mapselector.cc
changeset 3 2cc5ed6e6255
equal deleted inserted replaced
-1:000000000000 0:a19f287efa1e
       
     1 /* -*- C++ -*-
       
     2  *
       
     3  * This file is a part of LEMON, a generic C++ optimization library
       
     4  *
       
     5  * Copyright (C) 2003-2006
       
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       
     8  *
       
     9  * Permission to use, modify and distribute this software is granted
       
    10  * provided that this copyright notice appears in all copies. For
       
    11  * precise terms see the accompanying LICENSE file.
       
    12  *
       
    13  * This software is provided "AS IS" with no warranty of any kind,
       
    14  * express or implied, and with no claim as to its suitability for any
       
    15  * purpose.
       
    16  *
       
    17  */
       
    18 
       
    19 #include <mapselector.h>
       
    20 
       
    21 MapSelector::MapSelector(std::vector<std::string> n_ml,
       
    22     std::vector<std::string> s_ml, std::string act,
       
    23     std::string labeltext, bool arc, bool d, MapType type) :
       
    24   def(d),
       
    25   itisarc(arc),
       
    26   set_new_map(false),
       
    27   label(labeltext),
       
    28   map_type(type),
       
    29   newbut(Gtk::Stock::NEW)
       
    30 {
       
    31   update_list(n_ml, s_ml);
       
    32 
       
    33   if(act=="")
       
    34   {
       
    35     cbt.set_active(0);
       
    36     default_state=true;
       
    37   }
       
    38   else
       
    39   {
       
    40     cbt.set_active_text((Glib::ustring)act);
       
    41     default_state=false;
       
    42   }
       
    43 
       
    44   //binding signal to the actual entry
       
    45   cbt.signal_changed().connect
       
    46     (
       
    47      sigc::mem_fun((*this), &MapSelector::comboChanged),
       
    48      false
       
    49     );
       
    50 
       
    51   label.set_width_chars(longest_property_string_length);
       
    52 
       
    53   if(def)
       
    54   {
       
    55     defbut.set_label("Reset");
       
    56     defbut.signal_pressed().connect
       
    57       (
       
    58        sigc::mem_fun(*this, &MapSelector::reset)
       
    59       );
       
    60   }
       
    61 
       
    62 
       
    63   newbut.signal_pressed().connect
       
    64     (
       
    65      sigc::mem_fun(*this, &MapSelector::new_but_pressed)
       
    66     );
       
    67 
       
    68   add(label);
       
    69 
       
    70   add(cbt);
       
    71 
       
    72   if(def)
       
    73   {
       
    74     add(defbut);
       
    75   }
       
    76 
       
    77   add(newbut);
       
    78 }
       
    79 
       
    80 void MapSelector::new_but_pressed()
       
    81 {
       
    82   set_new_map=true;
       
    83   signal_newmapwin.emit(itisarc);
       
    84 }
       
    85 
       
    86 void MapSelector::update_list(std::vector<std::string> n_ml,
       
    87     std::vector<std::string> s_ml)
       
    88 {
       
    89   int prev_act=cbt.get_active_row_number();
       
    90   cbt.clear();
       
    91   cbt_content.clear();
       
    92 
       
    93   if (map_type & NUM)
       
    94   {
       
    95     std::vector< std::string >::iterator emsi=n_ml.begin();
       
    96     for(;emsi!=n_ml.end();emsi++)
       
    97     {
       
    98       cbt.append_text(*emsi);
       
    99       cbt_content.push_back(*emsi);
       
   100     }
       
   101   }
       
   102   if (map_type & STR)
       
   103   {
       
   104     std::vector< std::string >::iterator emsi=s_ml.begin();
       
   105     for(;emsi!=s_ml.end();emsi++)
       
   106     {
       
   107       cbt.append_text(*emsi);
       
   108       cbt_content.push_back(*emsi);
       
   109     }
       
   110   }
       
   111   if(def)
       
   112     {
       
   113       cbt.prepend_text("Default values");
       
   114       cbt_content.push_back("Default values");
       
   115     }
       
   116   if(prev_act!=-1)
       
   117     {
       
   118       cbt.set_active(prev_act);
       
   119     }
       
   120 }
       
   121 
       
   122 void MapSelector::comboChanged()
       
   123 {
       
   124   if(cbt.get_active_row_number()!=0 || !def)
       
   125     {
       
   126       default_state=false;
       
   127       Glib::ustring mapname = cbt.get_active_text();
       
   128       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
       
   129 	{
       
   130 	  signal_cbt.emit(mapname);
       
   131 	}
       
   132     }
       
   133   else if((!default_state)&&(cbt.get_active_row_number()==0))
       
   134     {
       
   135       reset();
       
   136     }
       
   137 }
       
   138 
       
   139 void MapSelector::reset()
       
   140 {
       
   141   default_state=true;
       
   142 
       
   143   cbt.set_active(0);
       
   144 
       
   145   signal_cbt.emit("");
       
   146 }
       
   147 
       
   148 
       
   149 Glib::ustring MapSelector::get_active_text()
       
   150 {
       
   151   return cbt.get_active_text();
       
   152 }
       
   153 
       
   154 void MapSelector::set_active_text(Glib::ustring text)
       
   155 {
       
   156   if(text.compare(""))
       
   157     {
       
   158       cbt.set_active_text(text);
       
   159     }
       
   160   else
       
   161     { 
       
   162       cbt.set_active_text("Default values");
       
   163     }
       
   164 }
       
   165 
       
   166 void MapSelector::append_text(Glib::ustring text, MapValue::Type type)
       
   167 {
       
   168   if (type & map_type)
       
   169   {
       
   170     cbt.append_text(text);
       
   171     cbt_content.push_back(text);
       
   172 
       
   173     if(set_new_map)
       
   174     {
       
   175       set_active_text(text);
       
   176       set_new_map=false;
       
   177     }
       
   178   }
       
   179 }
       
   180 
       
   181 sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
       
   182 {
       
   183   return signal_cbt;
       
   184 }
       
   185 
       
   186 sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
       
   187 {
       
   188   return signal_newmapwin;
       
   189 }