gui/mw-mapselector.cc
author hegyi
Wed, 30 Nov 2005 13:24:23 +0000
changeset 1838 b61682f0ee96
parent 1837 8dd6160ff699
permissions -rw-r--r--
MapWin is created and disposed from now instead of being show and hide.
hegyi@1819
     1
#include "map_win.h"
hegyi@1731
     2
hegyi@1838
     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@1731
     4
{
hegyi@1837
     5
  update_list(ml);
hegyi@1731
     6
hegyi@1838
     7
  if(act=="")
hegyi@1838
     8
    {
hegyi@1838
     9
      cbt.set_active(0);
hegyi@1838
    10
      default_state=true;
hegyi@1838
    11
    }
hegyi@1838
    12
  else
hegyi@1838
    13
    {
hegyi@1838
    14
      cbt.set_active_text((Glib::ustring)act);
hegyi@1838
    15
      default_state=false;
hegyi@1838
    16
    }
hegyi@1731
    17
hegyi@1731
    18
  //binding signal to the actual entry
hegyi@1731
    19
  cbt.signal_changed().connect
hegyi@1731
    20
    (
hegyi@1819
    21
     sigc::mem_fun((*this), &MapWin::MapSelector::comboChanged),
hegyi@1731
    22
     false
hegyi@1731
    23
     );
hegyi@1731
    24
  
hegyi@1731
    25
  if(itisedge)
hegyi@1731
    26
    {
hegyi@1731
    27
      label=new Gtk::Label(edge_property_strings[id]);
hegyi@1731
    28
    }
hegyi@1731
    29
  else
hegyi@1731
    30
    {
hegyi@1731
    31
      label=new Gtk::Label(node_property_strings[id]);
hegyi@1731
    32
    }
hegyi@1731
    33
hegyi@1731
    34
  label->set_width_chars(longest_property_string_length);
hegyi@1731
    35
hegyi@1731
    36
  defbut=new Gtk::Button();
hegyi@1731
    37
  defbut->set_label("Reset");
hegyi@1731
    38
hegyi@1731
    39
  defbut->signal_pressed().connect
hegyi@1731
    40
    (
hegyi@1819
    41
     sigc::mem_fun(*this, &MapWin::MapSelector::reset)
hegyi@1731
    42
     );
hegyi@1731
    43
hegyi@1731
    44
  newbut=new Gtk::Button(Gtk::Stock::NEW);
hegyi@1731
    45
hegyi@1733
    46
  newbut->signal_pressed().connect
hegyi@1733
    47
    (
hegyi@1819
    48
     sigc::mem_fun(*this, &MapWin::MapSelector::new_but_pressed)
hegyi@1733
    49
     );
hegyi@1733
    50
hegyi@1731
    51
  add(*label);
hegyi@1731
    52
hegyi@1731
    53
  add(cbt);
hegyi@1731
    54
hegyi@1731
    55
  add(*defbut);
hegyi@1731
    56
  add(*newbut);
hegyi@1731
    57
}
hegyi@1731
    58
hegyi@1819
    59
void MapWin::MapSelector::new_but_pressed()
hegyi@1737
    60
{
hegyi@1737
    61
  set_new_map=true;
hegyi@1837
    62
  signal_newmapwin.emit(itisedge);
hegyi@1737
    63
}
hegyi@1737
    64
hegyi@1837
    65
void MapWin::MapSelector::update_list( std::vector< std::string > ml )
hegyi@1731
    66
{
hegyi@1838
    67
  int prev_act=cbt.get_active_row_number();
hegyi@1731
    68
  cbt.clear();
hegyi@1837
    69
  std::vector< std::string >::iterator emsi=ml.begin();
hegyi@1837
    70
  for(;emsi!=ml.end();emsi++)
hegyi@1731
    71
    {
hegyi@1837
    72
      cbt.append_text(*emsi);
hegyi@1731
    73
    }
hegyi@1731
    74
  cbt.prepend_text("Default values");
hegyi@1838
    75
  if(prev_act!=-1)
hegyi@1838
    76
    {
hegyi@1838
    77
      cbt.set_active(prev_act);
hegyi@1838
    78
    }
hegyi@1731
    79
}
hegyi@1731
    80
hegyi@1819
    81
void MapWin::MapSelector::comboChanged()
hegyi@1731
    82
{
hegyi@1731
    83
  if(cbt.get_active_row_number()!=0)
hegyi@1731
    84
    {
hegyi@1731
    85
      default_state=false;
hegyi@1731
    86
      Glib::ustring mapname = cbt.get_active_text();
hegyi@1731
    87
      if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@1731
    88
	{
hegyi@1837
    89
	  signal_cbt.emit(mapname);
hegyi@1731
    90
	}
hegyi@1731
    91
    }
hegyi@1731
    92
  else if((!default_state)&&(cbt.get_active_row_number()==0))
hegyi@1731
    93
    {
hegyi@1731
    94
      reset();
hegyi@1731
    95
    }
hegyi@1731
    96
}
hegyi@1731
    97
hegyi@1819
    98
void MapWin::MapSelector::reset()
hegyi@1731
    99
{
hegyi@1731
   100
  default_state=true;
hegyi@1838
   101
hegyi@1731
   102
  cbt.set_active(0);
hegyi@1731
   103
hegyi@1837
   104
  signal_cbt.emit("");
hegyi@1731
   105
}
hegyi@1731
   106
hegyi@1731
   107
hegyi@1819
   108
Glib::ustring MapWin::MapSelector::get_active_text()
hegyi@1731
   109
{
hegyi@1731
   110
  return cbt.get_active_text();
hegyi@1731
   111
}
hegyi@1731
   112
hegyi@1819
   113
void MapWin::MapSelector::set_active_text(Glib::ustring text)
hegyi@1731
   114
{
hegyi@1731
   115
  cbt.set_active_text(text);
hegyi@1731
   116
}
hegyi@1731
   117
hegyi@1819
   118
void MapWin::MapSelector::append_text(Glib::ustring text)
hegyi@1731
   119
{
hegyi@1731
   120
  cbt.append_text(text);
hegyi@1737
   121
  if(set_new_map)
hegyi@1737
   122
    {
hegyi@1737
   123
      set_active_text(text);
hegyi@1737
   124
      set_new_map=false;
hegyi@1737
   125
    }
hegyi@1731
   126
}
hegyi@1837
   127
hegyi@1837
   128
sigc::signal<void, std::string> MapWin::MapSelector::signal_cbt_ch()
hegyi@1837
   129
{
hegyi@1837
   130
  return signal_cbt;
hegyi@1837
   131
}
hegyi@1837
   132
hegyi@1837
   133
sigc::signal<void, bool> MapWin::MapSelector::signal_newmapwin_needed()
hegyi@1837
   134
{
hegyi@1837
   135
  return signal_newmapwin;
hegyi@1837
   136
}