summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1f37e9d)
raw | patch | inline | side by side (parent: 1f37e9d)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 16 Jul 2008 21:38:16 +0000 (21:38 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Wed, 16 Jul 2008 21:38:16 +0000 (21:38 +0000) |
src/ui/dialog/filter-effects-dialog.cpp | patch | blob | history | |
src/ui/widget/combo-enums.h | patch | blob | history | |
src/util/enums.h | patch | blob | history |
index 1ded9e255f7064e487a7503381e1906ac63c0776..2cec40860dda09e9312b7f152401fec99a7503e4 100644 (file)
_vertical_layout = Pango::Layout::create(context);
int maxfont = 0;
- for(int i = 0; i < FPInputConverter.end; ++i) {
+ for(unsigned int i = 0; i < FPInputConverter._length; ++i) {
_vertical_layout->set_text(_(FPInputConverter.get_label((FilterPrimitiveInput)i).c_str()));
int fontw, fonth;
_vertical_layout->get_pixel_size(fontw, fonth);
int vis_x, vis_y;
tree_to_widget_coords(vis.get_x(), vis.get_y(), vis_x, vis_y);
- text_start_x = rct.get_x() + rct.get_width() - _connection_cell.get_text_width() * (FPInputConverter.end + 1) + 1;
- for(int i = 0; i < FPInputConverter.end; ++i) {
+ text_start_x = rct.get_x() + rct.get_width() - _connection_cell.get_text_width() * (FPInputConverter._length + 1) + 1;
+ for(unsigned int i = 0; i < FPInputConverter._length; ++i) {
_vertical_layout->set_text(_(FPInputConverter.get_label((FilterPrimitiveInput)i).c_str()));
const int x = text_start_x + _connection_cell.get_text_width() * (i + 1);
get_bin_window()->draw_rectangle(get_style()->get_bg_gc(Gtk::STATE_NORMAL), true, x, vis_y, _connection_cell.get_text_width(), vis.get_height());
@@ -1898,13 +1898,13 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton*
Gdk::Rectangle rct;
get_cell_area(path, *col, rct);
const int twidth = _connection_cell.get_text_width();
- const int sources_x = rct.get_width() - twidth * FPInputConverter.end;
+ const int sources_x = rct.get_width() - twidth * FPInputConverter._length;
if(cx > sources_x) {
int src = (cx - sources_x) / twidth;
if(src < 0)
src = 0;
- else if(src >= FPInputConverter.end)
- src = FPInputConverter.end - 1;
+ else if(src >= FPInputConverter._length)
+ src = FPInputConverter._length - 1;
result = FPInputConverter.get_key((FilterPrimitiveInput)src);
in_val = result.c_str();
}
index cab93f55783c47c7a3a9acea2745e4d449877107..11640f3ca3b971ae750b33aa88ca536f7def759b 100644 (file)
pack_start(_columns.label);
// Initialize list
- for(int i = 0; i < _converter.end; ++i) {
+ for(int i = 0; i < _converter._length; ++i) {
Gtk::TreeModel::Row row = *_model->append();
const Util::EnumData<E>* data = &_converter.data(i);
row[_columns.data] = data;
pack_start(_columns.label);
// Initialize list
- for(int i = 0; i < _converter.end; ++i) {
+ for(unsigned int i = 0; i < _converter._length; ++i) {
Gtk::TreeModel::Row row = *_model->append();
const Util::EnumData<E>* data = &_converter.data(i);
row[_columns.data] = data;
setProgrammatically = true;
const gchar* val = attribute_value(o);
if(val)
- set_active(_converter.get_id_from_key(val));
+ set_active_by_id(_converter.get_id_from_key(val));
else
set_active(get_default()->as_uint());
}
diff --git a/src/util/enums.h b/src/util/enums.h
index 69514b202922f516bb930307c0c934f31085d485..cbb1cb9a1ba6e57c217db0397990027a39c51f77 100644 (file)
--- a/src/util/enums.h
+++ b/src/util/enums.h
* Instead, one must use N_(...) and do the translation every time the string is retreived.
*
* Note that get_id_from_key and get_id_from_label return 0 if it cannot find an entry for that key string
+ * Note that get_label and get_key return an empty string when the requested id is not in the list.
*/
namespace Inkscape {
namespace Util {
-template<typename E> class EnumData
+template<typename E>
+struct EnumData
{
-public:
E id;
const Glib::ustring label;
const Glib::ustring key;
};
+const Glib::ustring empty_string("");
+
template<typename E> class EnumDataConverter
{
public:
typedef EnumData<E> Data;
- EnumDataConverter(const EnumData<E>* cd, const int endval)
- : end(endval), _data(cd)
+ EnumDataConverter(const EnumData<E>* cd, const unsigned int length)
+ : _length(length), _data(cd)
{}
E get_id_from_label(const Glib::ustring& label) const
{
- for(int i = 0; i < end; ++i) {
+ for(unsigned int i = 0; i < _length; ++i) {
if(_data[i].label == label)
- return (E)i;
+ return _data[i].id;
}
return (E)0;
E get_id_from_key(const Glib::ustring& key) const
{
- for(int i = 0; i < end; ++i) {
+ for(unsigned int i = 0; i < _length; ++i) {
if(_data[i].key == key)
- return (E)i;
+ return _data[i].id;
}
return (E)0;
bool is_valid_key(const Glib::ustring& key) const
{
- for(int i = 0; i < end; ++i) {
+ for(unsigned int i = 0; i < _length; ++i) {
if(_data[i].key == key)
return true;
}
return false;
}
- bool is_valid_id(const E e) const
+ bool is_valid_id(const E id) const
{
- return ( (int)e < end );
+ for(unsigned int i = 0; i < _length; ++i) {
+ if(_data[i].id == id)
+ return true;
+ }
+ return false;
}
- const Glib::ustring& get_label(const E e) const
+ const Glib::ustring& get_label(const E id) const
{
- return _data[e].label;
+ for(unsigned int i = 0; i < _length; ++i) {
+ if(_data[i].id == id)
+ return _data[i].label;
+ }
+
+ return empty_string;
}
- const Glib::ustring& get_key(const E e) const
+ const Glib::ustring& get_key(const E id) const
{
- return _data[e].key;
+ for(unsigned int i = 0; i < _length; ++i) {
+ if(_data[i].id == id)
+ return _data[i].key;
+ }
+
+ return empty_string;
}
- const EnumData<E>& data(const int i) const
+ const EnumData<E>& data(const unsigned int i) const
{
return _data[i];
}
- const int end;
+ const unsigned int _length;
private:
const EnumData<E>* _data;
};