X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftable.cpp;h=936be5cc61b032bb4c94ca7622a54e138fd5dbbd;hb=c1faa54a3218b53757b8b55de0ff8aa64412253b;hp=7f334a0e6825041fb24df917a06be91bc3a2e405;hpb=f34c8d617cbe8ae426e7a1e280dfa0aaf5d11a6d;p=libs%2Fgltk.git diff --git a/source/table.cpp b/source/table.cpp index 7f334a0..936be5c 100644 --- a/source/table.cpp +++ b/source/table.cpp @@ -1,10 +1,4 @@ -/* $Id$ - -This file is part of libmspgltk -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - +#include #include #include #include "part.h" @@ -16,19 +10,18 @@ using namespace std; namespace Msp { namespace GLtk { -Table::Table(const Resources &r): - Widget(r), +Table::Table(): rows(1), columns(1), data(1), col_w(1) { - update_style(); + focusable = false; } void Table::set_rows(unsigned r) { - rows=r; + rows = r; data.resize(rows*columns); } @@ -39,7 +32,7 @@ void Table::set_columns(unsigned c) for(unsigned j=0; j=columns) - throw InvalidParameterValue("Column index out of bounds"); - col_w[c]=w; + throw invalid_argument("Table::set_column_width"); + col_w[c] = w; } void Table::set_cell_text(unsigned r, unsigned c, const string &t) { if(r>=rows || c>=columns) - throw InvalidParameterValue("Cell coordinates out of bounds"); + throw out_of_range("Table::set_cell_text"); - data[r*columns+c]=t; + data[r*columns+c] = t; } void Table::render_special(const Part &part) const { if(part.get_name()=="cells") { - const GL::Font *const font=style->get_font(); - const float font_size=font->get_default_size(); + const GL::Font *const font = style->get_font(); + const float font_size = font->get_default_size(); - unsigned free_width=geom.w; + unsigned free_width = geom.w; for(unsigned i=0; i(font->get_string_width(text)*font_size); - rgeom.h=static_cast((font->get_ascent()-font->get_descent())*font_size); + rgeom.x = cgeom.x; + rgeom.y = cgeom.y; + rgeom.w = static_cast(font->get_string_width(text)*font_size); + rgeom.h = static_cast((font->get_ascent()-font->get_descent())*font_size); part.get_alignment().apply(rgeom, cgeom, part.get_margin()); @@ -99,10 +92,10 @@ void Table::render_special(const Part &part) const font->draw_string(text); GL::pop_matrix(); - cgeom.x+=cgeom.w; + cgeom.x += cgeom.w; } - cgeom.y-=cgeom.h; + cgeom.y -= cgeom.h; } } } @@ -123,22 +116,22 @@ Table::Loader::Loader(Table &t): void Table::Loader::cell_text(unsigned r, unsigned c, const string &t) { - static_cast(wdg).set_cell_text(r, c, t); + static_cast
(obj).set_cell_text(r, c, t); } void Table::Loader::column_width(unsigned c, unsigned w) { - static_cast
(wdg).set_column_width(c, w); + static_cast
(obj).set_column_width(c, w); } void Table::Loader::columns(unsigned c) { - static_cast
(wdg).set_columns(c); + static_cast
(obj).set_columns(c); } void Table::Loader::rows(unsigned r) { - static_cast
(wdg).set_rows(r); + static_cast
(obj).set_rows(r); } } // namespace GLtk