| 1 |
#include "WidgetPlace.hh" |
#include "WidgetPlace.hh" |
| 2 |
#include <gtk--/menuitem.h> |
#include <gtk--/menuitem.h> |
| 3 |
#include <gtk--/menu.h> |
#include <gtk--/menu.h> |
| 4 |
|
#include <gtk--/menushell.h> |
| 5 |
|
#include <sigc++/object.h> |
| 6 |
|
#include <iostream> |
| 7 |
|
|
| 8 |
#define VALUES_SEPARATOR "," |
#define VALUES_SEPARATOR "," |
| 9 |
|
#define DEFAULT_MENU_HISTORY 0 |
| 10 |
|
|
| 11 |
|
WidgetPlace::WidgetEntryPlace::WidgetEntryPlace(void) : |
| 12 |
|
Gtk::MenuItem(), |
| 13 |
|
_entry(0) |
| 14 |
|
{ |
| 15 |
|
_entry = manage(new Gtk::Entry()); |
| 16 |
|
add(*_entry); |
| 17 |
|
return; |
| 18 |
|
} |
| 19 |
|
|
| 20 |
|
void WidgetPlace::WidgetEntryPlace::set_text(std::string const &value) |
| 21 |
|
{ |
| 22 |
|
_entry->set_text(value); |
| 23 |
|
return; |
| 24 |
|
} |
| 25 |
|
|
| 26 |
|
Gtk::Entry * WidgetPlace::WidgetEntryPlace::getEntryWidget(void) |
| 27 |
|
{ |
| 28 |
|
return _entry; |
| 29 |
|
} |
| 30 |
|
|
| 31 |
|
WidgetPlace::WidgetPlace(void) : |
| 32 |
|
_value(), |
| 33 |
|
_entry_place(0) |
| 34 |
|
{ |
| 35 |
|
set_text(""); |
| 36 |
|
return; |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
int WidgetPlace::on_Place_clicked(GdkEventFocus * e) |
| 40 |
|
{ |
| 41 |
|
std::string new_value = _entry_place->getEntryWidget()->get_text(); |
| 42 |
|
if (new_value != _value) |
| 43 |
|
{ |
| 44 |
|
set_text(new_value); |
| 45 |
|
} |
| 46 |
|
return 0; |
| 47 |
|
} |
| 48 |
|
|
| 49 |
void WidgetPlace::set_text(std::string const &values) |
void WidgetPlace::set_text(std::string const &values) |
| 50 |
{ |
{ |
| 51 |
// set_usize(-1, 25); |
_value = values; |
| 52 |
|
if (get_menu() != 0) |
| 53 |
|
{ |
| 54 |
|
clear(); |
| 55 |
|
} |
| 56 |
|
set_usize(-1, 25); |
| 57 |
set_flags(GTK_CAN_FOCUS); |
set_flags(GTK_CAN_FOCUS); |
| 58 |
Gtk::MenuItem * mi = 0; |
Gtk::MenuItem * mi = 0; |
| 59 |
int cpt = 0; |
int cpt = 0; |
| 60 |
int cpt2 = 0; |
int cpt2 = 0; |
| 61 |
std::string tmp; |
std::string tmp; |
| 62 |
Gtk::Menu *m(manage(new Gtk::Menu())); |
|
| 63 |
|
Gtk::Menu * m = get_menu(); |
| 64 |
|
if (m == 0) |
| 65 |
|
{ |
| 66 |
|
m = manage(new Gtk::Menu()); |
| 67 |
|
set_menu(*m); |
| 68 |
|
} |
| 69 |
|
if (_entry_place == 0) |
| 70 |
|
{ |
| 71 |
|
_entry_place = manage(new WidgetEntryPlace()); |
| 72 |
|
_entry_place->getEntryWidget()->focus_out_event.connect(SigC::slot(this, &WidgetPlace::on_Place_clicked)); |
| 73 |
|
m->append(*_entry_place); |
| 74 |
|
} |
| 75 |
|
_entry_place->set_text(values); |
| 76 |
|
Gtk::Menu_Helpers::MenuList::const_iterator iter_entry = m->items().end(); |
| 77 |
|
if (iter_entry != m->items().begin()) |
| 78 |
|
{ |
| 79 |
|
iter_entry--; |
| 80 |
|
} |
| 81 |
|
|
| 82 |
while (cpt2 < values.length()) |
while (cpt2 < values.length()) |
| 83 |
{ |
{ |
| 84 |
cpt2 = values.find(VALUES_SEPARATOR, cpt); |
cpt2 = values.find(VALUES_SEPARATOR, cpt); |
| 85 |
tmp.assign(values, cpt, cpt2 - cpt); |
tmp.assign(values, cpt, cpt2 - cpt); |
| 86 |
mi = manage(new Gtk::MenuItem(tmp)); |
mi = manage(new Gtk::MenuItem(tmp)); |
| 87 |
m->append(*mi); |
m->items().insert(iter_entry,*mi); |
| 88 |
cpt = cpt2 + 1; |
cpt = cpt2 + 1; |
| 89 |
} |
} |
| 90 |
set_menu(*m); |
set_history(DEFAULT_MENU_HISTORY); |
| 91 |
show_all(); |
show_all(); |
| 92 |
return; |
return; |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
void WidgetPlace::clear(void) |
void WidgetPlace::clear(void) |
| 96 |
{ |
{ |
| 97 |
remove_menu(); |
Gtk::Menu * m = get_menu(); |
| 98 |
|
if (get_menu() != 0) |
| 99 |
|
{ |
| 100 |
|
Gtk::Menu_Helpers::MenuList::const_iterator iter_entry = m->items().end(); |
| 101 |
|
if (iter_entry != m->items().begin()) |
| 102 |
|
{ |
| 103 |
|
iter_entry--; |
| 104 |
|
m->items().erase(m->items().begin(), iter_entry); |
| 105 |
|
} |
| 106 |
|
} |
| 107 |
return; |
return; |
| 108 |
} |
} |
| 109 |
|
|
| 110 |
|
Gtk::Entry * WidgetPlace::getEntryWidget(void) |
| 111 |
|
{ |
| 112 |
|
|
| 113 |
|
if (_entry_place != 0) |
| 114 |
|
{ |
| 115 |
|
return _entry_place->getEntryWidget(); |
| 116 |
|
} |
| 117 |
|
else |
| 118 |
|
{ |
| 119 |
|
return 0; |
| 120 |
|
} |
| 121 |
|
} |