COIN-OR::LEMON - Graph Library

source: glemon-0.x/mapselector.cc @ 112:3689cb170d3e

gui
Last change on this file since 112:3689cb170d3e was 112:3689cb170d3e, checked in by Hegyi Péter, 19 years ago

MapSelector? has become a standalone class.

File size: 2.5 KB
Line 
1#include "mapselector.h"
2
3MapSelector::MapSelector(std::vector<std::string> ml, std::string act, int identifier, bool edge):id(identifier),itisedge(edge),set_new_map(false)
4{
5  update_list(ml);
6
7  if(act=="")
8    {
9      cbt.set_active(0);
10      default_state=true;
11    }
12  else
13    {
14      cbt.set_active_text((Glib::ustring)act);
15      default_state=false;
16    }
17
18  //binding signal to the actual entry
19  cbt.signal_changed().connect
20    (
21     sigc::mem_fun((*this), &MapSelector::comboChanged),
22     false
23     );
24 
25  if(itisedge)
26    {
27      label=new Gtk::Label(edge_property_strings[id]);
28    }
29  else
30    {
31      label=new Gtk::Label(node_property_strings[id]);
32    }
33
34  label->set_width_chars(longest_property_string_length);
35
36  defbut=new Gtk::Button();
37  defbut->set_label("Reset");
38
39  defbut->signal_pressed().connect
40    (
41     sigc::mem_fun(*this, &MapSelector::reset)
42     );
43
44  newbut=new Gtk::Button(Gtk::Stock::NEW);
45
46  newbut->signal_pressed().connect
47    (
48     sigc::mem_fun(*this, &MapSelector::new_but_pressed)
49     );
50
51  add(*label);
52
53  add(cbt);
54
55  add(*defbut);
56  add(*newbut);
57}
58
59void MapSelector::new_but_pressed()
60{
61  set_new_map=true;
62  signal_newmapwin.emit(itisedge);
63}
64
65void MapSelector::update_list( std::vector< std::string > ml )
66{
67  int prev_act=cbt.get_active_row_number();
68  cbt.clear();
69  std::vector< std::string >::iterator emsi=ml.begin();
70  for(;emsi!=ml.end();emsi++)
71    {
72      cbt.append_text(*emsi);
73    }
74  cbt.prepend_text("Default values");
75  if(prev_act!=-1)
76    {
77      cbt.set_active(prev_act);
78    }
79}
80
81void MapSelector::comboChanged()
82{
83  if(cbt.get_active_row_number()!=0)
84    {
85      default_state=false;
86      Glib::ustring mapname = cbt.get_active_text();
87      if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
88        {
89          signal_cbt.emit(mapname);
90        }
91    }
92  else if((!default_state)&&(cbt.get_active_row_number()==0))
93    {
94      reset();
95    }
96}
97
98void MapSelector::reset()
99{
100  default_state=true;
101
102  cbt.set_active(0);
103
104  signal_cbt.emit("");
105}
106
107
108Glib::ustring MapSelector::get_active_text()
109{
110  return cbt.get_active_text();
111}
112
113void MapSelector::set_active_text(Glib::ustring text)
114{
115  cbt.set_active_text(text);
116}
117
118void MapSelector::append_text(Glib::ustring text)
119{
120  cbt.append_text(text);
121  if(set_new_map)
122    {
123      set_active_text(text);
124      set_new_map=false;
125    }
126}
127
128sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
129{
130  return signal_cbt;
131}
132
133sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
134{
135  return signal_newmapwin;
136}
Note: See TracBrowser for help on using the repository browser.