]> git.tdb.fi Git - r2c2.git/blob - source/designer/zoneproperties.cpp
6ea4f2a330fc1a4b115a597933b01ede9813968d
[r2c2.git] / source / designer / zoneproperties.cpp
1 #include <msp/gltk/button.h>
2 #include <msp/gltk/column.h>
3 #include <msp/gltk/label.h>
4 #include <msp/gltk/row.h>
5 #include "zoneproperties.h"
6
7 using namespace std;
8 using namespace Msp;
9 using namespace R2C2;
10
11 ZoneProperties::ZoneProperties(Zone &z):
12         zone(z)
13 {
14         set_layout(new GLtk::Layout);
15         GLtk::Column col(*layout);
16
17         GLtk::Label *lbl1, *lbl2;
18
19         add(*(lbl1 = new GLtk::Label("Zone properties")));
20         lbl1->set_style("title");
21
22         {
23                 GLtk::Row row(*layout);
24                 add(*(lbl1 = new GLtk::Label("Group")));
25                 add(*(ent_group = new GLtk::Entry(zone.get_group())));
26                 ent_group->set_edit_size(30, 1);
27         }
28
29         {
30                 GLtk::Row row(*layout);
31                 add(*(lbl2 = new GLtk::Label("Qualifier")));
32                 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
33
34                 add(*(drp_qualifier = new GLtk::Dropdown));
35                 GLtk::ListDataStore<string> &data = dynamic_cast<GLtk::ListDataStore<string> &>(drp_qualifier->get_data());
36                 const char *qualifiers[] = { "track", "platform", "siding", 0 };
37                 for(unsigned i=0; qualifiers[i]; ++i)
38                 {
39                         data.append(qualifiers[i]);
40                         if(zone.get_qualifier()==qualifiers[i])
41                                 drp_qualifier->set_selected_index(i);
42                 }
43         }
44
45         {
46                 GLtk::Row row(*layout);
47                 add(*(lbl1 = new GLtk::Label("Number")));
48                 layout->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
49                 add(*(ent_number = new GLtk::Entry(lexical_cast<string>(zone.get_number()))));
50                 ent_number->set_edit_size(4, 1);
51         }
52
53         GLtk::Button *btn;
54
55         {
56                 GLtk::Row row(*layout);
57                 row.split();
58                 add_button(*(btn = new GLtk::Button("Cncl")), 0);
59                 btn->set_style("red");
60
61                 add_button(*(btn = new GLtk::Button("OK")), 1);
62                 btn->set_style("green");
63         }
64 }
65
66 void ZoneProperties::on_response(int code)
67 {
68         if(code==1)
69         {
70                 string qualifier;
71                 int sel = drp_qualifier->get_selected_index();
72                 if(sel>=0)
73                         qualifier = drp_qualifier->get_data().get_string(sel);
74                 unsigned number = lexical_cast<unsigned>(ent_number->get_text());
75                 zone.set_name(ent_group->get_text(), qualifier, number);
76         }
77 }