map_win.cc
author hegyi
Fri, 17 Jun 2005 14:53:28 +0000
branchgui
changeset 23 d0e4ac77bafe
parent 6 603b85626bc0
child 28 fa28f1071bd6
permissions -rw-r--r--
Little beauty fault is corrected.
ladanyi@6
     1
#include <map_win.h>
ladanyi@6
     2
#include <set>
ladanyi@6
     3
hegyi@8
     4
bool MapWin::close_if_escape_is_pressed(GdkEventKey* e)
ladanyi@6
     5
{
hegyi@8
     6
  if(e->keyval==GDK_Escape)
hegyi@8
     7
  {
hegyi@8
     8
    hide();
hegyi@8
     9
  }
hegyi@8
    10
  return true;
hegyi@8
    11
}
ladanyi@6
    12
hegyi@8
    13
MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst),table(PROPERTY_NUM, 2, false)
hegyi@8
    14
{
hegyi@8
    15
  set_title(title);
hegyi@8
    16
  set_default_size(200, 50);
ladanyi@6
    17
hegyi@8
    18
  signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::close_if_escape_is_pressed));
ladanyi@6
    19
hegyi@8
    20
  combo_array=new Gtk::Combo [PROPERTY_NUM];
hegyi@8
    21
ladanyi@6
    22
  for(int i=0;i<PROPERTY_NUM;i++)
ladanyi@6
    23
  {
ladanyi@6
    24
ladanyi@6
    25
    std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
ladanyi@6
    26
    std::set<int> props;
ladanyi@6
    27
ladanyi@6
    28
    int actprop;
hegyi@8
    29
hegyi@8
    30
    //here we find out, which map is the default in MapStorage for this property, which are not
ladanyi@6
    31
    for(int j=0;j<ms.numOfEdgeMaps();j++)
ladanyi@6
    32
    {
hegyi@8
    33
      //this is the default value for this property
ladanyi@6
    34
      if(emsi->second==&(ms.default_edgemaps[i]))
ladanyi@6
    35
      {
ladanyi@6
    36
	actprop=j;
ladanyi@6
    37
      }
hegyi@8
    38
      //this is the other maps to show for this property
ladanyi@6
    39
      for(int k=0;k<PROPERTY_NUM;k++)
ladanyi@6
    40
      {
ladanyi@6
    41
	if(emsi->second==&(ms.default_edgemaps[k]))
ladanyi@6
    42
	{
ladanyi@6
    43
	  props.insert(j);
ladanyi@6
    44
	}
ladanyi@6
    45
      }
ladanyi@6
    46
      emsi++;
ladanyi@6
    47
    }
ladanyi@6
    48
hegyi@8
    49
    //combo_array[i].set_group(group);
ladanyi@6
    50
hegyi@8
    51
    //filling in combo box with choices
hegyi@8
    52
    std::list<Glib::ustring> listStrings;
hegyi@8
    53
hegyi@8
    54
    listStrings.push_back("Default");
ladanyi@6
    55
ladanyi@6
    56
    emsi=ms.beginOfEdgeMaps();
hegyi@8
    57
ladanyi@6
    58
    for(int j=0;j<ms.numOfEdgeMaps();j++)
ladanyi@6
    59
    {
ladanyi@6
    60
      if( ( props.find(j) )==( props.end() ) )
ladanyi@6
    61
      {
hegyi@8
    62
	listStrings.push_back(emsi->first);
ladanyi@6
    63
      }
ladanyi@6
    64
      emsi++;
ladanyi@6
    65
    }
hegyi@8
    66
hegyi@8
    67
    combo_array[i].set_popdown_strings(listStrings);
hegyi@8
    68
hegyi@8
    69
    //Restrict it to these choices only:
hegyi@8
    70
    combo_array[i].set_value_in_list();
hegyi@8
    71
hegyi@8
    72
    //binding signal to thew actual entry
hegyi@8
    73
    combo_array[i].get_entry()->signal_changed().connect
hegyi@8
    74
    (
hegyi@8
    75
     sigc::bind
hegyi@8
    76
     (
hegyi@8
    77
      sigc::mem_fun(*this, &MapWin::combo_changed),
hegyi@8
    78
      i
hegyi@8
    79
     )
hegyi@8
    80
    );
hegyi@8
    81
hegyi@8
    82
    //placing actual entry in the right place
hegyi@8
    83
hegyi@8
    84
    label=new Gtk::Label;
hegyi@8
    85
    label->set_text(property_strings[i]);
hegyi@8
    86
hegyi@8
    87
    //    labelpluscombo=new Gtk::HBox;
hegyi@8
    88
    //    labelpluscombo->pack_start(*label);
hegyi@8
    89
    //    labelpluscombo->pack_start(combo_array[i]);
hegyi@8
    90
        
hegyi@8
    91
    table.attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@8
    92
    table.attach(combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
hegyi@8
    93
hegyi@8
    94
    /*
hegyi@8
    95
    if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
hegyi@8
    96
    {
hegyi@8
    97
      vbox_r1.pack_start(*labelpluscombo);
hegyi@8
    98
    }
hegyi@8
    99
    else
hegyi@8
   100
    {
hegyi@8
   101
      vbox_r2.pack_start(*labelpluscombo);
hegyi@8
   102
    }
hegyi@8
   103
    actpos++;
hegyi@8
   104
    //*/
hegyi@8
   105
ladanyi@6
   106
  }
ladanyi@6
   107
hegyi@8
   108
  combos.pack_start(vbox_r1);
hegyi@8
   109
  combos.pack_start(vbox_r2);
hegyi@8
   110
hegyi@8
   111
  //add(combos);
hegyi@8
   112
  add(table);
ladanyi@6
   113
ladanyi@6
   114
  show_all_children();
ladanyi@6
   115
ladanyi@6
   116
}
ladanyi@6
   117
hegyi@8
   118
void MapWin::combo_changed(int prop)
ladanyi@6
   119
{
ladanyi@6
   120
ladanyi@6
   121
  //most nem kommentezem fel, mert ugyis valtozik
hegyi@8
   122
  Gtk::Entry* entry = combo_array[prop].get_entry();
ladanyi@6
   123
hegyi@8
   124
  if(entry)
ladanyi@6
   125
  {
hegyi@8
   126
    Glib::ustring mapname = entry->get_text();
hegyi@8
   127
    if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
hegyi@8
   128
    {
hegyi@8
   129
      if(mapname=="Default")
hegyi@8
   130
      {
hegyi@8
   131
	mapname=property_strings[prop];
hegyi@8
   132
      }
ladanyi@6
   133
hegyi@8
   134
      if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
hegyi@8
   135
      {
hegyi@8
   136
	switch(prop)
hegyi@8
   137
	{
hegyi@8
   138
          case WIDTH:
hegyi@8
   139
	    gdc.changeLineWidth(mapname);
hegyi@8
   140
	    break;
hegyi@8
   141
          case COLOR:
hegyi@8
   142
	    gdc.changeColor(mapname);
hegyi@8
   143
	    break;
hegyi@8
   144
          case TEXT:
hegyi@8
   145
	    gdc.changeText(mapname);
hegyi@8
   146
	    break;
hegyi@8
   147
          default:
hegyi@8
   148
	    std::cout<<"Error\n";
hegyi@8
   149
	}
hegyi@8
   150
      }
ladanyi@6
   151
    }
ladanyi@6
   152
  }
ladanyi@6
   153
};