Changeset 51
- Timestamp:
- 05/15/07 21:11:23 (2 years ago)
- Files:
-
- branches/bughunt/minwin/button.d (modified) (5 diffs)
- branches/bughunt/samples/widgets.d (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/bughunt/minwin/button.d
r49 r51 47 47 void selected(bool x); 48 48 } 49 49 50 version (MinWin32) { 50 version = SimpleToggleGroup;51 } 52 version (SimpleToggleGroup) { 53 private import minwin.dialog; 54 // manages selected state between several ToggleButtons55 class ToggleGroup {56 AbstractToggleButton[] buttons;57 void addButton( AbstractToggleButton[] btns ...) {51 private import minwin.mswindows; 52 53 enum : int { ButtonClickedCommand = BN_CLICKED } 54 55 // manages selected state between several RadioButtons 56 class RadioGroup { 57 RadioButton[] buttons; 58 void addButton(RadioButton[] btns ...) { 58 59 buttons ~= btns; 59 60 foreach(b; btns) { … … 63 64 void select(Component c) { 64 65 version (LOG) log.writefln("selecting component ", c); 65 foreach( AbstractToggleButtonb; buttons) {66 foreach(b; buttons) { 66 67 b.selected = (b is c); 67 68 } 68 69 } 69 70 void select(int index) { 70 foreach(int n, AbstractToggleButtonb; buttons) {71 b.selected = n == index;71 foreach(int n, b; buttons) { 72 b.selected = (n == index); 72 73 } 73 74 } 74 75 int selected() { 75 foreach(int n, AbstractToggleButtonb; buttons) {76 version(LOG)log.printf("testing button %d %x\n",n,b);76 foreach(int n, b; buttons) { 77 version(LOG)log.printf("testing radio button %d %x\n",n,b); 77 78 if (b && b.selected) 78 79 return n; 79 80 } 80 version(LOG)log.printf(" no button selected??\n");81 version(LOG)log.printf(" no radio button selected??\n"); 81 82 return 0; 82 83 } 83 84 } 84 }85 86 version (MinWin32) {87 private import minwin.mswindows;88 89 enum : int { ButtonClickedCommand = BN_CLICKED }90 85 91 86 template PreferredSizeImpl() { … … 243 238 244 239 // manages selected state between several ToggleButtons 245 class ToggleGroup { 246 HeavyAbstractToggleButton[] buttons; 247 void addButton(HeavyAbstractToggleButton[] btns ...) { 240 class RadioGroup { 241 RadioButton[] buttons; 242 void addButton(RadioButton[] btns ...) { 243 size_t olen = buttons.length; 248 244 buttons ~= btns; 249 245 foreach(b; btns) { 250 RadioButton rb = cast(RadioButton)b; 251 if (rb is null) { 252 b.actionDelegate ~= &select; 253 } else { 254 // set the RadioButton group to its sibling, if any 255 if (buttons.length != 0) { 256 GtkRadioButton* rbpeer1 = cast(GtkRadioButton*)buttons[0].peer; 257 GtkRadioButton* rbpeer = cast(GtkRadioButton*)rb.peer; 258 GSList* group = gtk_radio_button_get_group(rbpeer1); 259 gtk_radio_button_set_group(rbpeer,group); 260 } 246 if (olen++ != 0) { 247 GtkRadioButton* rbpeer1 = cast(GtkRadioButton*)buttons[0].peer; 248 GtkRadioButton* rbpeer = cast(GtkRadioButton*)b.peer; 249 GSList* group = gtk_radio_button_get_group(rbpeer1); 250 gtk_radio_button_set_group(rbpeer,group); 261 251 } 262 252 } … … 264 254 void select(Component c) { 265 255 version (LOG) log.writefln("selecting component ", c); 266 foreach( HeavyAbstractToggleButtonb; buttons) {256 foreach(b; buttons) { 267 257 b.selected = (b is c); 268 258 } 269 259 } 270 260 void select(int index) { 271 foreach(int n, HeavyAbstractToggleButtonb; buttons) {261 foreach(int n, b; buttons) { 272 262 b.selected = n == index; 273 263 } 274 264 } 275 265 int selected() { 276 foreach(int n, HeavyAbstractToggleButtonb; buttons) {266 foreach(int n, b; buttons) { 277 267 if (b.selected) 278 268 return n; … … 362 352 cast(GCallback)&mw_buttonclick_callback, 363 353 cast(gpointer)b, 364 null, cast(GConnectFlags)0);354 null,GConnectFlags.G_CONNECT_AFTER);//cast(GConnectFlags)0); 365 355 setWindowChildPeer(b,peer,OWNS_PEER); 366 356 parent.addChild(b); branches/bughunt/samples/widgets.d
r49 r51 14 14 extern (C) 15 15 int MinWinMain(Application* app) { 16 autowin = new Window("Widgets");16 Window win = new Window("Widgets"); 17 17 win.quitOnDestroy = true; 18 18 win.backgroundColor = systemBackgroundColor(); 19 19 win.layoutMgr = new FlowLayout; 20 20 21 auto b3 = new CheckBox(win,"check 1");22 auto b4 = new CheckBox(win,"check 2");23 //ToggleButton b5 = new ToggleButton(win,"toggle 1");24 25 /*ToggleGroup g = new ToggleGroup;26 21 GroupBox box = new GroupBox(win,"Group"); 27 22 box.layoutMgr = new FlowLayout; 28 RadioButton b1 = new RadioButton(box,"click me"); 29 RadioButton b2 = new RadioButton(box,"no, click me"); 30 g.addButton(b1); 31 g.addButton(b2); 32 g.select(0);*/ 23 RadioGroup g = new RadioGroup; 24 RadioButton r1 = new RadioButton(box,"click me"); 25 RadioButton r2 = new RadioButton(box,"no, click me"); 26 RadioButton r3 = new RadioButton(box,"or me ;)"); 27 g.addButton(r1); 28 g.addButton(r2); 29 g.addButton(r3); 30 g.select(0); 33 31 34 auto lab = new Label(win,"This is a label"); 35 auto t1 = new Text(win,"single line"); 32 CheckBox b1 = new CheckBox(win,"check 1"); 33 CheckBox b2 = new CheckBox(win,"check 2"); 34 ToggleButton b3 = new ToggleButton(win,"toggle 1"); 35 36 Label lab = new Label(win,"This is a label"); 37 Text t1 = new Text(win,"single line"); 36 38 t1.userPreferredWidth = 60; 37 39 38 autot2 = new MultiLineText(win,"multi line\ntext area");40 MultiLineText t2 = new MultiLineText(win,"multi line\ntext area"); 39 41 t2.userPreferredSize(120,120); 40 42 41 43 char[][] strs = ["hello","world","The","D","Programming","Language","is","great"]; 42 autocombo = new ComboBox(win,strs);44 ComboBox combo = new ComboBox(win,strs); 43 45 combo.selection = 0; 44 46 45 autolist = new ListBox(win,strs);47 ListBox list = new ListBox(win,strs); 46 48 list.selection = 0; 47 49 list.userPreferredSize(100,100); 48 50 49 autop = new Canvas(win);51 Canvas p = new Canvas(win); 50 52 p.keyDelegate ~= (Component source, KeyEvent* event) { 51 53 if (event.id == KeyPressedEvent) { … … 73 75 p.userPreferredSize(30,30); 74 76 75 autosbh = new ScrollBar(win,Horizontal);76 autosbv = new ScrollBar(win,Vertical);77 ScrollBar sbh = new ScrollBar(win,Horizontal); 78 ScrollBar sbv = new ScrollBar(win,Vertical); 77 79 78 autosp = new ScrollPane(win);79 automltxt = "This is a big text block that needs some scrolling maybe if we are lucky.\nLet's not depend on luck, but rather make it long enough...\nAnd span a few lines so it will scroll\nPlease...\n\n\nBye :)";80 autot3 = new Label(sp,mltxt);80 ScrollPane sp = new ScrollPane(win); 81 char[] mltxt = "This is a big text block that needs some scrolling maybe if we are lucky.\nLet's not depend on luck, but rather make it long enough...\nAnd span a few lines so it will scroll\nPlease...\n\n\nBye :)"; 82 Label t3 = new Label(sp,mltxt); 81 83 //t3.userPreferredSize(100,75); // make a large scrollable area 82 84 sp.userPreferredSize(150,75);
