mapselector.cc
author hegyi
Fri, 06 Jan 2006 23:16:51 +0000
branchgui
changeset 115 9e5196647a5a
parent 112 3689cb170d3e
child 122 96bfa82264c3
permissions -rw-r--r--
Forgotten file committed.
     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=new Gtk::Button();
    30   defbut->set_label("Reset");
    31 
    32   defbut->signal_pressed().connect
    33     (
    34      sigc::mem_fun(*this, &MapSelector::reset)
    35      );
    36 
    37   newbut=new Gtk::Button(Gtk::Stock::NEW);
    38 
    39   newbut->signal_pressed().connect
    40     (
    41      sigc::mem_fun(*this, &MapSelector::new_but_pressed)
    42      );
    43 
    44   add(*label);
    45 
    46   add(cbt);
    47 
    48   add(*defbut);
    49   add(*newbut);
    50 }
    51 
    52 void MapSelector::new_but_pressed()
    53 {
    54   set_new_map=true;
    55   signal_newmapwin.emit(itisedge);
    56 }
    57 
    58 void MapSelector::update_list( std::vector< std::string > ml )
    59 {
    60   int prev_act=cbt.get_active_row_number();
    61   cbt.clear();
    62   std::vector< std::string >::iterator emsi=ml.begin();
    63   for(;emsi!=ml.end();emsi++)
    64     {
    65       cbt.append_text(*emsi);
    66     }
    67   if(def)
    68     {
    69       cbt.prepend_text("Default values");
    70     }
    71   if(prev_act!=-1)
    72     {
    73       cbt.set_active(prev_act);
    74     }
    75 }
    76 
    77 void MapSelector::comboChanged()
    78 {
    79   if(cbt.get_active_row_number()!=0)
    80     {
    81       default_state=false;
    82       Glib::ustring mapname = cbt.get_active_text();
    83       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
    84 	{
    85 	  signal_cbt.emit(mapname);
    86 	}
    87     }
    88   else if((!default_state)&&(cbt.get_active_row_number()==0))
    89     {
    90       reset();
    91     }
    92 }
    93 
    94 void MapSelector::reset()
    95 {
    96   default_state=true;
    97 
    98   cbt.set_active(0);
    99 
   100   signal_cbt.emit("");
   101 }
   102 
   103 
   104 Glib::ustring MapSelector::get_active_text()
   105 {
   106   return cbt.get_active_text();
   107 }
   108 
   109 void MapSelector::set_active_text(Glib::ustring text)
   110 {
   111   cbt.set_active_text(text);
   112 }
   113 
   114 void MapSelector::append_text(Glib::ustring text)
   115 {
   116   cbt.append_text(text);
   117   if(set_new_map)
   118     {
   119       set_active_text(text);
   120       set_new_map=false;
   121     }
   122 }
   123 
   124 sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
   125 {
   126   return signal_cbt;
   127 }
   128 
   129 sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
   130 {
   131   return signal_newmapwin;
   132 }