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