1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/mapselector.cc Mon Jul 07 08:10:39 2008 -0500
1.3 @@ -0,0 +1,189 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include <mapselector.h>
1.23 +
1.24 +MapSelector::MapSelector(std::vector<std::string> n_ml,
1.25 + std::vector<std::string> s_ml, std::string act,
1.26 + std::string labeltext, bool arc, bool d, MapType type) :
1.27 + def(d),
1.28 + itisarc(arc),
1.29 + set_new_map(false),
1.30 + label(labeltext),
1.31 + map_type(type),
1.32 + newbut(Gtk::Stock::NEW)
1.33 +{
1.34 + update_list(n_ml, s_ml);
1.35 +
1.36 + if(act=="")
1.37 + {
1.38 + cbt.set_active(0);
1.39 + default_state=true;
1.40 + }
1.41 + else
1.42 + {
1.43 + cbt.set_active_text((Glib::ustring)act);
1.44 + default_state=false;
1.45 + }
1.46 +
1.47 + //binding signal to the actual entry
1.48 + cbt.signal_changed().connect
1.49 + (
1.50 + sigc::mem_fun((*this), &MapSelector::comboChanged),
1.51 + false
1.52 + );
1.53 +
1.54 + label.set_width_chars(longest_property_string_length);
1.55 +
1.56 + if(def)
1.57 + {
1.58 + defbut.set_label("Reset");
1.59 + defbut.signal_pressed().connect
1.60 + (
1.61 + sigc::mem_fun(*this, &MapSelector::reset)
1.62 + );
1.63 + }
1.64 +
1.65 +
1.66 + newbut.signal_pressed().connect
1.67 + (
1.68 + sigc::mem_fun(*this, &MapSelector::new_but_pressed)
1.69 + );
1.70 +
1.71 + add(label);
1.72 +
1.73 + add(cbt);
1.74 +
1.75 + if(def)
1.76 + {
1.77 + add(defbut);
1.78 + }
1.79 +
1.80 + add(newbut);
1.81 +}
1.82 +
1.83 +void MapSelector::new_but_pressed()
1.84 +{
1.85 + set_new_map=true;
1.86 + signal_newmapwin.emit(itisarc);
1.87 +}
1.88 +
1.89 +void MapSelector::update_list(std::vector<std::string> n_ml,
1.90 + std::vector<std::string> s_ml)
1.91 +{
1.92 + int prev_act=cbt.get_active_row_number();
1.93 + cbt.clear();
1.94 + cbt_content.clear();
1.95 +
1.96 + if (map_type & NUM)
1.97 + {
1.98 + std::vector< std::string >::iterator emsi=n_ml.begin();
1.99 + for(;emsi!=n_ml.end();emsi++)
1.100 + {
1.101 + cbt.append_text(*emsi);
1.102 + cbt_content.push_back(*emsi);
1.103 + }
1.104 + }
1.105 + if (map_type & STR)
1.106 + {
1.107 + std::vector< std::string >::iterator emsi=s_ml.begin();
1.108 + for(;emsi!=s_ml.end();emsi++)
1.109 + {
1.110 + cbt.append_text(*emsi);
1.111 + cbt_content.push_back(*emsi);
1.112 + }
1.113 + }
1.114 + if(def)
1.115 + {
1.116 + cbt.prepend_text("Default values");
1.117 + cbt_content.push_back("Default values");
1.118 + }
1.119 + if(prev_act!=-1)
1.120 + {
1.121 + cbt.set_active(prev_act);
1.122 + }
1.123 +}
1.124 +
1.125 +void MapSelector::comboChanged()
1.126 +{
1.127 + if(cbt.get_active_row_number()!=0 || !def)
1.128 + {
1.129 + default_state=false;
1.130 + Glib::ustring mapname = cbt.get_active_text();
1.131 + if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
1.132 + {
1.133 + signal_cbt.emit(mapname);
1.134 + }
1.135 + }
1.136 + else if((!default_state)&&(cbt.get_active_row_number()==0))
1.137 + {
1.138 + reset();
1.139 + }
1.140 +}
1.141 +
1.142 +void MapSelector::reset()
1.143 +{
1.144 + default_state=true;
1.145 +
1.146 + cbt.set_active(0);
1.147 +
1.148 + signal_cbt.emit("");
1.149 +}
1.150 +
1.151 +
1.152 +Glib::ustring MapSelector::get_active_text()
1.153 +{
1.154 + return cbt.get_active_text();
1.155 +}
1.156 +
1.157 +void MapSelector::set_active_text(Glib::ustring text)
1.158 +{
1.159 + if(text.compare(""))
1.160 + {
1.161 + cbt.set_active_text(text);
1.162 + }
1.163 + else
1.164 + {
1.165 + cbt.set_active_text("Default values");
1.166 + }
1.167 +}
1.168 +
1.169 +void MapSelector::append_text(Glib::ustring text, MapValue::Type type)
1.170 +{
1.171 + if (type & map_type)
1.172 + {
1.173 + cbt.append_text(text);
1.174 + cbt_content.push_back(text);
1.175 +
1.176 + if(set_new_map)
1.177 + {
1.178 + set_active_text(text);
1.179 + set_new_map=false;
1.180 + }
1.181 + }
1.182 +}
1.183 +
1.184 +sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
1.185 +{
1.186 + return signal_cbt;
1.187 +}
1.188 +
1.189 +sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
1.190 +{
1.191 + return signal_newmapwin;
1.192 +}