]> git.tdb.fi Git - libs/gltk.git/blob - examples/widgetdemo/dropdowndemo.cpp
Only pass key and navigation events to enabled widgets
[libs/gltk.git] / examples / widgetdemo / dropdowndemo.cpp
1 #include <msp/gltk/dropdown.h>
2 #include <msp/strings/format.h>
3 #include "dropdowndemo.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 DropdownDemo::DropdownDemo()
9 {
10         set_layout(new GLtk::Layout);
11
12         GLtk::Dropdown *drp = new GLtk::Dropdown(categories);
13         drp->signal_item_selected.connect(sigc::mem_fun(this, &DropdownDemo::category_selected));
14         add(*drp);
15
16         categories.append("Arabic numerals");
17         categories.append("Roman numerals");
18         categories.append("Lowercase letters");
19         categories.append("Uppercase letters");
20
21         GLtk::Widget *prev = drp;
22         drp = new GLtk::Dropdown(values);
23         add(*drp);
24
25         layout->add_constraint(*drp, GLtk::Layout::BELOW, *prev);
26         layout->add_constraint(*drp, GLtk::Layout::ALIGN_LEFT, *prev);
27         layout->add_constraint(*drp, GLtk::Layout::ALIGN_RIGHT, *prev);
28 }
29
30 void DropdownDemo::category_selected(unsigned i)
31 {
32         values.clear();
33         if(i==0)
34         {
35                 for(unsigned j=0; j<=26; ++j)
36                         values.append(format("%d", j));
37         }
38         else if(i==1)
39         {
40                 for(unsigned j=1; j<=26; ++j)
41                 {
42                         string r = string(j/10, 'X');
43                         if(j%10==9)
44                                 r += "IX";
45                         else if(j%10>=4)
46                         {
47                                 if(j%10==4)
48                                         r += 'I';
49                                 r += 'V';
50                         }
51
52                         if(j%5<=3)
53                                 r += string(j%5, 'I');
54
55                         values.append(r);
56                 }
57         }
58         else if(i==2)
59         {
60                 for(unsigned j=0; j<26; ++j)
61                         values.append(string(1, 'a'+j));
62         }
63         else if(i==3)
64         {
65                 for(unsigned j=0; j<26; ++j)
66                         values.append(string(1, 'A'+j));
67         }
68 }