mw-mapselector.cc
author hegyi
Thu, 05 Jan 2006 12:30:09 +0000
branchgui
changeset 108 bf355fd6563e
parent 94 adfdc2f70548
permissions -rw-r--r--
Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
hegyi@89
     1
#include "map_win.h"
hegyi@81
     2
hegyi@95
     3
MapWin::MapSelector::MapSelector(std::vector<std::string> ml, std::string act, int identifier, bool edge):id(identifier),itisedge(edge),set_new_map(false)
hegyi@81
     4
{
hegyi@94
     5
  update_list(ml);
hegyi@81
     6
hegyi@95
     7
  if(act=="")
hegyi@95
     8
    {
hegyi@95
     9
      cbt.set_active(0);
hegyi@95
    10
      default_state=true;
hegyi@95
    11
    }
hegyi@95
    12
  else
hegyi@95
    13
    {
hegyi@95
    14
      cbt.set_active_text((Glib::ustring)act);
hegyi@95
    15
      default_state=false;
hegyi@95
    16
    }
hegyi@81
    17
hegyi@81
    18
  //binding signal to the actual entry
hegyi@81
    19
  cbt.signal_changed().connect
hegyi@81
    20
    (
hegyi@89
    21
     sigc::mem_fun((*this), &MapWin::MapSelector::comboChanged),
hegyi@81
    22
     false
hegyi@81
    23
     );
hegyi@81
    24
  
hegyi@81
    25
  if(itisedge)
hegyi@81
    26
    {
hegyi@81
    27
      label=new Gtk::Label(edge_property_strings[id]);
hegyi@81
    28
    }
hegyi@81
    29
  else
hegyi@81
    30
    {
hegyi@81
    31
      label=new Gtk::Label(node_property_strings[id]);
hegyi@81
    32
    }
hegyi@81
    33
hegyi@81
    34
  label->set_width_chars(longest_property_string_length);
hegyi@81
    35
hegyi@81
    36
  defbut=new Gtk::Button();
hegyi@81
    37
  defbut->set_label("Reset");
hegyi@81
    38
hegyi@81
    39
  defbut->signal_pressed().connect
hegyi@81
    40
    (
hegyi@89
    41
     sigc::mem_fun(*this, &MapWin::MapSelector::reset)
hegyi@81
    42
     );
hegyi@81
    43
hegyi@81
    44
  newbut=new Gtk::Button(Gtk::Stock::NEW);
hegyi@81
    45
hegyi@82
    46
  newbut->signal_pressed().connect
hegyi@82
    47
    (
hegyi@89
    48
     sigc::mem_fun(*this, &MapWin::MapSelector::new_but_pressed)
hegyi@82
    49
     );
hegyi@82
    50
hegyi@81
    51
  add(*label);
hegyi@81
    52
hegyi@81
    53
  add(cbt);
hegyi@81
    54
hegyi@81
    55
  add(*defbut);
hegyi@81
    56
  add(*newbut);
hegyi@81
    57
}
hegyi@81
    58
hegyi@89
    59
void MapWin::MapSelector::new_but_pressed()
hegyi@85
    60
{
hegyi@85
    61
  set_new_map=true;
hegyi@94
    62
  signal_newmapwin.emit(itisedge);
hegyi@85
    63
}
hegyi@85
    64
hegyi@94
    65
void MapWin::MapSelector::update_list( std::vector< std::string > ml )
hegyi@81
    66
{
hegyi@95
    67
  int prev_act=cbt.get_active_row_number();
hegyi@81
    68
  cbt.clear();
hegyi@94
    69
  std::vector< std::string >::iterator emsi=ml.begin();
hegyi@94
    70
  for(;emsi!=ml.end();emsi++)
hegyi@81
    71
    {
hegyi@94
    72
      cbt.append_text(*emsi);
hegyi@81
    73
    }
hegyi@81
    74
  cbt.prepend_text("Default values");
hegyi@95
    75
  if(prev_act!=-1)
hegyi@95
    76
    {
hegyi@95
    77
      cbt.set_active(prev_act);
hegyi@95
    78
    }
hegyi@81
    79
}
hegyi@81
    80
hegyi@89
    81
void MapWin::MapSelector::comboChanged()
hegyi@81
    82
{
hegyi@81
    83
  if(cbt.get_active_row_number()!=0)
hegyi@81
    84
    {
hegyi@81
    85
      default_state=false;
hegyi@81
    86
      Glib::ustring mapname = cbt.get_active_text();
hegyi@81
    87
      if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@81
    88
	{
hegyi@94
    89
	  signal_cbt.emit(mapname);
hegyi@81
    90
	}
hegyi@81
    91
    }
hegyi@81
    92
  else if((!default_state)&&(cbt.get_active_row_number()==0))
hegyi@81
    93
    {
hegyi@81
    94
      reset();
hegyi@81
    95
    }
hegyi@81
    96
}
hegyi@81
    97
hegyi@89
    98
void MapWin::MapSelector::reset()
hegyi@81
    99
{
hegyi@81
   100
  default_state=true;
hegyi@95
   101
hegyi@81
   102
  cbt.set_active(0);
hegyi@81
   103
hegyi@94
   104
  signal_cbt.emit("");
hegyi@81
   105
}
hegyi@81
   106
hegyi@81
   107
hegyi@89
   108
Glib::ustring MapWin::MapSelector::get_active_text()
hegyi@81
   109
{
hegyi@81
   110
  return cbt.get_active_text();
hegyi@81
   111
}
hegyi@81
   112
hegyi@89
   113
void MapWin::MapSelector::set_active_text(Glib::ustring text)
hegyi@81
   114
{
hegyi@81
   115
  cbt.set_active_text(text);
hegyi@81
   116
}
hegyi@81
   117
hegyi@89
   118
void MapWin::MapSelector::append_text(Glib::ustring text)
hegyi@81
   119
{
hegyi@81
   120
  cbt.append_text(text);
hegyi@85
   121
  if(set_new_map)
hegyi@85
   122
    {
hegyi@85
   123
      set_active_text(text);
hegyi@85
   124
      set_new_map=false;
hegyi@85
   125
    }
hegyi@81
   126
}
hegyi@94
   127
hegyi@94
   128
sigc::signal<void, std::string> MapWin::MapSelector::signal_cbt_ch()
hegyi@94
   129
{
hegyi@94
   130
  return signal_cbt;
hegyi@94
   131
}
hegyi@94
   132
hegyi@94
   133
sigc::signal<void, bool> MapWin::MapSelector::signal_newmapwin_needed()
hegyi@94
   134
{
hegyi@94
   135
  return signal_newmapwin;
hegyi@94
   136
}