gui/mw-mapselector.cc
author hegyi
Thu, 05 Jan 2006 16:54:34 +0000
changeset 1879 01d41844ef46
parent 1837 8dd6160ff699
permissions -rw-r--r--
Kruskal algorithm can be run from GUI from now on.
     1 #include "map_win.h"
     2 
     3 MapWin::MapSelector::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), &MapWin::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, &MapWin::MapSelector::reset)
    42      );
    43 
    44   newbut=new Gtk::Button(Gtk::Stock::NEW);
    45 
    46   newbut->signal_pressed().connect
    47     (
    48      sigc::mem_fun(*this, &MapWin::MapSelector::new_but_pressed)
    49      );
    50 
    51   add(*label);
    52 
    53   add(cbt);
    54 
    55   add(*defbut);
    56   add(*newbut);
    57 }
    58 
    59 void MapWin::MapSelector::new_but_pressed()
    60 {
    61   set_new_map=true;
    62   signal_newmapwin.emit(itisedge);
    63 }
    64 
    65 void MapWin::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 
    81 void MapWin::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 
    98 void MapWin::MapSelector::reset()
    99 {
   100   default_state=true;
   101 
   102   cbt.set_active(0);
   103 
   104   signal_cbt.emit("");
   105 }
   106 
   107 
   108 Glib::ustring MapWin::MapSelector::get_active_text()
   109 {
   110   return cbt.get_active_text();
   111 }
   112 
   113 void MapWin::MapSelector::set_active_text(Glib::ustring text)
   114 {
   115   cbt.set_active_text(text);
   116 }
   117 
   118 void MapWin::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 
   128 sigc::signal<void, std::string> MapWin::MapSelector::signal_cbt_ch()
   129 {
   130   return signal_cbt;
   131 }
   132 
   133 sigc::signal<void, bool> MapWin::MapSelector::signal_newmapwin_needed()
   134 {
   135   return signal_newmapwin;
   136 }