gui/mapselector.cc
author deba
Wed, 01 Mar 2006 10:17:25 +0000
changeset 1990 15fb7a4ea6be
parent 1884 9c061834b33b
permissions -rw-r--r--
Some classes assumed that the GraphMaps should be inherited
from an ObserverBase. These classes parents replaced with
DefaultMap which cause that the graph maps should not be
inherited from the ObserverBase.
     1 #include "mapselector.h"
     2 
     3 MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),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   label=new Gtk::Label(labeltext);
    26 
    27   label->set_width_chars(longest_property_string_length);
    28 
    29   defbut=NULL;
    30   if(def)
    31     {
    32       defbut=new Gtk::Button();
    33       defbut->set_label("Reset");
    34       
    35       defbut->signal_pressed().connect
    36 	(
    37 	 sigc::mem_fun(*this, &MapSelector::reset)
    38 	 );
    39     }
    40 
    41   newbut=new Gtk::Button(Gtk::Stock::NEW);
    42 
    43   newbut->signal_pressed().connect
    44     (
    45      sigc::mem_fun(*this, &MapSelector::new_but_pressed)
    46      );
    47 
    48   add(*label);
    49 
    50   add(cbt);
    51 
    52   if(def)
    53     {
    54       add(*defbut);
    55     }
    56 
    57   add(*newbut);
    58 }
    59 
    60 void MapSelector::new_but_pressed()
    61 {
    62   set_new_map=true;
    63   signal_newmapwin.emit(itisedge);
    64 }
    65 
    66 void MapSelector::update_list( std::vector< std::string > ml )
    67 {
    68   int prev_act=cbt.get_active_row_number();
    69   cbt.clear();
    70   std::vector< std::string >::iterator emsi=ml.begin();
    71   for(;emsi!=ml.end();emsi++)
    72     {
    73       cbt.append_text(*emsi);
    74     }
    75   if(def)
    76     {
    77       cbt.prepend_text("Default values");
    78     }
    79   if(prev_act!=-1)
    80     {
    81       cbt.set_active(prev_act);
    82     }
    83 }
    84 
    85 void MapSelector::comboChanged()
    86 {
    87   if(cbt.get_active_row_number()!=0 || !def)
    88     {
    89       default_state=false;
    90       Glib::ustring mapname = cbt.get_active_text();
    91       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
    92 	{
    93 	  signal_cbt.emit(mapname);
    94 	}
    95     }
    96   else if((!default_state)&&(cbt.get_active_row_number()==0))
    97     {
    98       reset();
    99     }
   100 }
   101 
   102 void MapSelector::reset()
   103 {
   104   default_state=true;
   105 
   106   cbt.set_active(0);
   107 
   108   signal_cbt.emit("");
   109 }
   110 
   111 
   112 Glib::ustring MapSelector::get_active_text()
   113 {
   114   return cbt.get_active_text();
   115 }
   116 
   117 void MapSelector::set_active_text(Glib::ustring text)
   118 {
   119   cbt.set_active_text(text);
   120 }
   121 
   122 void MapSelector::append_text(Glib::ustring text)
   123 {
   124   cbt.append_text(text);
   125   if(set_new_map)
   126     {
   127       set_active_text(text);
   128       set_new_map=false;
   129     }
   130 }
   131 
   132 sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
   133 {
   134   return signal_cbt;
   135 }
   136 
   137 sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
   138 {
   139   return signal_newmapwin;
   140 }