Changeset 51

Show
Ignore:
Timestamp:
05/15/07 21:11:23 (2 years ago)
Author:
lindquist
Message:

Changed ToggleGroup? to RadioGroup?. It is now restricted to radio buttons
only, but this is all GTK can handle properly.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/bughunt/minwin/button.d

    r49 r51  
    4747    void selected(bool x); 
    4848} 
     49 
    4950version (MinWin32) { 
    50     version = SimpleToggleGroup
    51 
    52 version (SimpleToggleGroup) { 
    53     private import minwin.dialog; 
    54     // manages selected state between several ToggleButtons 
    55     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 ...) { 
    5859            buttons ~= btns; 
    5960            foreach(b; btns) { 
     
    6364        void select(Component c) { 
    6465            version (LOG) log.writefln("selecting component ", c); 
    65             foreach(AbstractToggleButton b; buttons) { 
     66            foreach(b; buttons) { 
    6667                b.selected = (b is c); 
    6768            } 
    6869        } 
    6970        void select(int index) { 
    70             foreach(int n, AbstractToggleButton b; buttons) { 
    71                 b.selected = n == index
     71            foreach(int n, b; buttons) { 
     72                b.selected = (n == index)
    7273            } 
    7374        } 
    7475        int selected() { 
    75             foreach(int n, AbstractToggleButton b; 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); 
    7778                if (b && b.selected) 
    7879                    return n; 
    7980            } 
    80             version(LOG)log.printf(" no button selected??\n"); 
     81            version(LOG)log.printf(" no radio button selected??\n"); 
    8182            return 0; 
    8283        } 
    8384    } 
    84 } 
    85  
    86 version (MinWin32) { 
    87     private import minwin.mswindows; 
    88  
    89     enum : int { ButtonClickedCommand = BN_CLICKED } 
    9085 
    9186    template PreferredSizeImpl() { 
     
    243238 
    244239    // 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; 
    248244            buttons ~= btns; 
    249245            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); 
    261251                } 
    262252            } 
     
    264254        void select(Component c) { 
    265255            version (LOG) log.writefln("selecting component ", c); 
    266             foreach(HeavyAbstractToggleButton b; buttons) { 
     256            foreach(b; buttons) { 
    267257                b.selected = (b is c); 
    268258            } 
    269259        } 
    270260        void select(int index) { 
    271             foreach(int n, HeavyAbstractToggleButton b; buttons) { 
     261            foreach(int n, b; buttons) { 
    272262                b.selected = n == index; 
    273263            } 
    274264        } 
    275265        int selected() { 
    276             foreach(int n, HeavyAbstractToggleButton b; buttons) { 
     266            foreach(int n, b; buttons) { 
    277267                if (b.selected) 
    278268                    return n; 
     
    362352                cast(GCallback)&mw_buttonclick_callback, 
    363353                cast(gpointer)b, 
    364                 null,cast(GConnectFlags)0); 
     354                null,GConnectFlags.G_CONNECT_AFTER);//cast(GConnectFlags)0); 
    365355        setWindowChildPeer(b,peer,OWNS_PEER); 
    366356        parent.addChild(b); 
  • branches/bughunt/samples/widgets.d

    r49 r51  
    1414extern (C) 
    1515int MinWinMain(Application* app) { 
    16     auto win = new Window("Widgets"); 
     16    Window win = new Window("Widgets"); 
    1717    win.quitOnDestroy = true; 
    1818    win.backgroundColor = systemBackgroundColor(); 
    1919    win.layoutMgr = new FlowLayout; 
    2020 
    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; 
    2621    GroupBox box = new GroupBox(win,"Group"); 
    2722    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); 
    3331 
    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"); 
    3638    t1.userPreferredWidth = 60; 
    3739 
    38     auto t2 = new MultiLineText(win,"multi line\ntext area"); 
     40    MultiLineText t2 = new MultiLineText(win,"multi line\ntext area"); 
    3941    t2.userPreferredSize(120,120); 
    4042 
    4143    char[][] strs = ["hello","world","The","D","Programming","Language","is","great"]; 
    42     auto combo = new ComboBox(win,strs); 
     44    ComboBox combo = new ComboBox(win,strs); 
    4345    combo.selection = 0; 
    4446 
    45     auto list = new ListBox(win,strs); 
     47    ListBox list = new ListBox(win,strs); 
    4648    list.selection = 0; 
    4749    list.userPreferredSize(100,100); 
    4850 
    49     auto p = new Canvas(win); 
     51    Canvas p = new Canvas(win); 
    5052    p.keyDelegate ~= (Component source, KeyEvent* event) { 
    5153        if (event.id == KeyPressedEvent) { 
     
    7375    p.userPreferredSize(30,30); 
    7476 
    75     auto sbh = new ScrollBar(win,Horizontal); 
    76     auto sbv = new ScrollBar(win,Vertical); 
     77    ScrollBar sbh = new ScrollBar(win,Horizontal); 
     78    ScrollBar sbv = new ScrollBar(win,Vertical); 
    7779 
    78     auto sp = new ScrollPane(win); 
    79     auto 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 :)"; 
    80     auto t3 = 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); 
    8183    //t3.userPreferredSize(100,75); // make a large scrollable area 
    8284    sp.userPreferredSize(150,75);