Changeset 12

Show
Ignore:
Timestamp:
12/04/06 00:55:01 (2 years ago)
Author:
lindquist
Message:

Updated samples to new indentation style.
Fixed a use of auto that should now be scope in the widgets sample.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/minwin/samples/idle.d

    r5 r12  
    1313import std.utf; 
    1414 
    15 extern (C)  
     15extern (C) 
    1616int MinWinMain(Application* app) { 
    17   Window win = new Window("Idle processing"); 
    18   char[] text  = "Idle processing..."; 
    19   char[] cur = ""; 
    20   win.quitOnDestroy = true; 
    21   win.paintDelegate ~= delegate void(Component source, GContext gc) { 
    22     auto Font font = new Font("",14,FontWeight.Bold); 
    23     Font oldfont = gc.setFont(font); 
    24     gc.drawText(100,100,text); 
    25     gc.setFont(oldfont); 
    26   }; 
    27   win.keyDelegate ~= delegate void(Component source, KeyEvent* event) { 
    28     if (event.id == KeyPressedEvent) { 
    29       char[4] buf; 
    30       cur = toUTF8(buf,event.keyCode).dup; 
    31    
    32   }; 
    33   app.idleTime = 1000; // every second 
    34   app.idleDelegate ~= delegate void() { 
    35     text = cur ~ " " ~ toString(rand()); 
    36     win.repaint(); 
    37   }; 
    38   win.visible = true; 
    39   return app.enterEventLoop(); 
     17    Window win = new Window("Idle processing"); 
     18    char[] text    = "Idle processing..."; 
     19    char[] cur = ""; 
     20    win.quitOnDestroy = true; 
     21    win.paintDelegate ~= delegate void(Component source, GContext gc) { 
     22        auto Font font = new Font("",14,FontWeight.Bold); 
     23        Font oldfont = gc.setFont(font); 
     24        gc.drawText(100,100,text); 
     25        gc.setFont(oldfont); 
     26    }; 
     27    win.keyDelegate ~= delegate void(Component source, KeyEvent* event) { 
     28        if (event.id == KeyPressedEvent) { 
     29            char[4] buf; 
     30            cur = toUTF8(buf,event.keyCode).dup; 
     31       
     32    }; 
     33    app.idleTime = 1000; // every second 
     34    app.idleDelegate ~= delegate void() { 
     35        text = cur ~ " " ~ toString(rand()); 
     36        win.repaint(); 
     37    }; 
     38    win.visible = true; 
     39    return app.enterEventLoop(); 
    4040} 
  • trunk/minwin/samples/layout.d

    r5 r12  
    1212import std.string; 
    1313 
    14 extern (C)  
     14extern (C) 
    1515int MinWinMain(Application* app) { 
    1616 
    17   Window win = new Window("Layout Sample"); 
    18   char[] text = "Click the Random number button"; 
    19   win.quitOnDestroy = true; 
     17    Window win = new Window("Layout Sample"); 
     18    char[] text = "Click the Random number button"; 
     19    win.quitOnDestroy = true; 
    2020 
    21   // set table layout 
    22   static double[3] yy = [.3, .2, .5]; 
    23   static double[2] xx = [.5,.5]; 
    24   win.layoutMgr = new TableLayout(xx,yy); 
     21    // set table layout 
     22    static double[3] yy = [.3, .2, .5]; 
     23    static double[2] xx = [.5,.5]; 
     24    win.layoutMgr = new TableLayout(xx,yy); 
    2525 
    26   // define some buttons to put in the table 
    27   Button b1 = new Button(win,"Random number"); 
    28   Button b2 = new Button(win,"hide groups"); 
    29   Button b3 = new Button(win,"hide layout"); 
     26    // define some buttons to put in the table 
     27    Button b1 = new Button(win,"Random number"); 
     28    Button b2 = new Button(win,"hide groups"); 
     29    Button b3 = new Button(win,"hide layout"); 
    3030 
    31   // define a group to put in the table 
    32   Group g = new Group(win); 
    33   FlowLayout flow = new FlowLayout(); 
    34   flow.sideStretch = true; 
    35   g.layoutMgr = flow; 
    36   Button sub1 = new Button(g,"click random"); 
    37   Button sub2 = new Button(g,"sub2"); 
     31    // define a group to put in the table 
     32    Group g = new Group(win); 
     33    FlowLayout flow = new FlowLayout(); 
     34    flow.sideStretch = true; 
     35    g.layoutMgr = flow; 
     36    Button sub1 = new Button(g,"click random"); 
     37    Button sub2 = new Button(g,"sub2"); 
    3838 
    39   // make a sub-group of g 
    40   Group g2 = new Group(g); 
    41   flow = new FlowLayout(Dir.Horizontal); 
    42   flow.flowReverse = 1; 
    43   g2.layoutMgr = flow; 
    44   Button sub3 = new Button(g2,"sub3"); 
    45   Button sub4 = new Button(g2,"sub4"); 
    46   Button sub5 = new Button(g2,"sub5"); 
     39    // make a sub-group of g 
     40    Group g2 = new Group(g); 
     41    flow = new FlowLayout(Dir.Horizontal); 
     42    flow.flowReverse = 1; 
     43    g2.layoutMgr = flow; 
     44    Button sub3 = new Button(g2,"sub3"); 
     45    Button sub4 = new Button(g2,"sub4"); 
     46    Button sub5 = new Button(g2,"sub5"); 
    4747 
    48   Button b4 = new Button(win,"b3"); 
     48    Button b4 = new Button(win,"b3"); 
    4949 
    50   // define actions 
    51   b1.actionDelegate ~= delegate void(Component source) { 
    52     sub1.text = toString(rand()); 
    53   }; 
    54   b2.actionDelegate ~= delegate void(Component source) { 
    55     g.visible = !g.visible; 
    56   };   
    57   b3.actionDelegate ~= delegate void(Component source) { 
    58     // remove from layout computations 
    59     g.parentOwnsLayout = !g.parentOwnsLayout; 
    60   };   
     50    // define actions 
     51    b1.actionDelegate ~= delegate void(Component source) { 
     52        sub1.text = toString(rand()); 
     53    }; 
     54    b2.actionDelegate ~= delegate void(Component source) { 
     55        g.visible = !g.visible; 
     56    }; 
     57    b3.actionDelegate ~= delegate void(Component source) { 
     58        // remove from layout computations 
     59        g.parentOwnsLayout = !g.parentOwnsLayout; 
     60    }; 
    6161 
    62   win.pack(); 
    63   win.visible = true; 
     62    win.pack(); 
     63    win.visible = true; 
    6464 
    65   Window win2 = new Window("Border Layout Sample"); 
    66   win2.quitOnDestroy = true; 
    67   BorderLayout bl = new BorderLayout(); 
    68   Button w2b1 = new Button(win2,"north"); 
    69   bl.location[Loc.North] = w2b1; 
    70   Button w2b2 = new Button(win2,"south"); 
    71   bl.location[Loc.South] = w2b2; 
    72   Button w2b3 = new Button(win2,"east"); 
    73   bl.location[Loc.East] = w2b3; 
    74   Button w2b4 = new Button(win2,"west"); 
    75   bl.location[Loc.West] = w2b4; 
    76   Button w2b5 = new Button(win2,"center"); 
    77   bl.location[Loc.Center] = w2b5; 
    78   win2.layoutMgr = bl; 
    79    
    80   win2.pack(); 
    81   win2.visible = true; 
    82    
    83   return app.enterEventLoop(); 
     65    Window win2 = new Window("Border Layout Sample"); 
     66    win2.quitOnDestroy = true; 
     67    BorderLayout bl = new BorderLayout(); 
     68    Button w2b1 = new Button(win2,"north"); 
     69    bl.location[Loc.North] = w2b1; 
     70    Button w2b2 = new Button(win2,"south"); 
     71    bl.location[Loc.South] = w2b2; 
     72    Button w2b3 = new Button(win2,"east"); 
     73    bl.location[Loc.East] = w2b3; 
     74    Button w2b4 = new Button(win2,"west"); 
     75    bl.location[Loc.West] = w2b4; 
     76    Button w2b5 = new Button(win2,"center"); 
     77    bl.location[Loc.Center] = w2b5; 
     78    win2.layoutMgr = bl; 
     79 
     80    win2.pack(); 
     81    win2.visible = true; 
     82 
     83    return app.enterEventLoop(); 
    8484} 
  • trunk/minwin/samples/menus.d

    r5 r12  
    1111import std.string; 
    1212 
    13 extern (C)  
     13extern (C) 
    1414int MinWinMain(Application* app) { 
    15   Window win = new Window("Menu Sample"); 
    16   win.quitOnDestroy = true; 
    17   win.layoutMgr = new FlowLayout; 
    18   MenuBar mb = new MenuBar(win); 
    19   Menu file = new Menu(mb,"File"); 
    20   file.add("Open...",100); 
    21   file.addSeparator(); 
    22   file.add("Save...",234); 
    23   Menu edit = new Menu(mb,"Edit"); 
    24   edit.add("Hello",400); 
    25   edit.add("World",500); 
    26   char[] text = "select menu"; 
    27   win.commandDelegate ~= delegate void(Component source, int cmd) { 
    28     text = toString(cmd); 
    29     win.repaint(); 
    30     if (cmd == 100) { 
    31       // show open file dialog 
    32       FileDialogData data; 
    33       data.title = "Open File"; 
    34       if (openFileDialog(win,data)) { 
    35    text = "you selected " ~ data.result; 
    36      
    37     } else if (cmd == 234) { 
    38       // show save file dialog 
    39       FileFilter[2] filt; 
    40       filt[0].description = "Foo bar files"; 
    41       filt[0].extensions ~= "*.foo"; 
    42       filt[1].description = "All files"; 
    43       filt[1].extensions ~= "*"; 
    44       FileDialogData data; 
    45       data.title = "Save File"; 
    46       data.filter = filt; 
    47       if (saveFileDialog(win,data)) { 
    48    text = "you saved " ~ data.result; 
    49      
    50    
    51   }; 
    52   win.paintDelegate ~= delegate void(Component source, GContext gc) { 
    53     auto Font font = new Font("",12); 
    54     Font oldfont = gc.setFont(font); 
    55     gc.drawText(100,100,text); 
    56     gc.setFont(oldfont); 
    57   }; 
     15    Window win = new Window("Menu Sample"); 
     16    win.quitOnDestroy = true; 
     17    win.layoutMgr = new FlowLayout; 
     18    MenuBar mb = new MenuBar(win); 
     19    Menu file = new Menu(mb,"File"); 
     20    file.add("Open...",100); 
     21    file.addSeparator(); 
     22    file.add("Save...",234); 
     23    Menu edit = new Menu(mb,"Edit"); 
     24    edit.add("Hello",400); 
     25    edit.add("World",500); 
     26    char[] text = "select menu"; 
     27    win.commandDelegate ~= delegate void(Component source, int cmd) { 
     28        text = toString(cmd); 
     29        win.repaint(); 
     30        if (cmd == 100) { 
     31            // show open file dialog 
     32            FileDialogData data; 
     33            data.title = "Open File"; 
     34            if (openFileDialog(win,data)) { 
     35                text = "you selected " ~ data.result; 
     36           
     37        } else if (cmd == 234) { 
     38            // show save file dialog 
     39            FileFilter[2] filt; 
     40            filt[0].description = "Foo bar files"; 
     41            filt[0].extensions ~= "*.foo"; 
     42            filt[1].description = "All files"; 
     43            filt[1].extensions ~= "*"; 
     44            FileDialogData data; 
     45            data.title = "Save File"; 
     46            data.filter = filt; 
     47            if (saveFileDialog(win,data)) { 
     48                text = "you saved " ~ data.result; 
     49           
     50       
     51    }; 
     52    win.paintDelegate ~= delegate void(Component source, GContext gc) { 
     53        auto Font font = new Font("",12); 
     54        Font oldfont = gc.setFont(font); 
     55        gc.drawText(100,100,text); 
     56        gc.setFont(oldfont); 
     57    }; 
    5858 
    59   win.visible = true; 
    60   return app.enterEventLoop(); 
     59    win.visible = true; 
     60    return app.enterEventLoop(); 
    6161} 
  • trunk/minwin/samples/painting.d

    r5 r12  
    1010import minwin.all; 
    1111 
    12 extern (C)  
     12extern (C) 
    1313int MinWinMain(Application* app) { 
    14   Window win = new Window("Painting Sample"); 
    15   win.quitOnDestroy = true; 
     14    Window win = new Window("Painting Sample"); 
     15    win.quitOnDestroy = true; 
    1616 
    17   Image im = win.getCompatibleImage(100,150); 
    18   GContext gc = im.getGContext(); 
     17    Image im = win.getCompatibleImage(100,150); 
     18    GContext gc = im.getGContext(); 
    1919 
    20   auto Pen p2 = new Pen(RGB(0,0,0)); 
    21   Pen oldPen = gc.setPen(p2); 
    22   Rect r = LTWH(0,0,100,150); 
    23   auto Brush b2 = new Brush(RGB(255,255,255)); 
    24   Brush oldBrush = gc.setBrush(b2); 
    25   gc.fillRect(r); 
    26   gc.drawRect(r); 
    27   gc.setBrush(oldBrush); 
     20    auto Pen p2 = new Pen(RGB(0,0,0)); 
     21    Pen oldPen = gc.setPen(p2); 
     22    Rect r = LTWH(0,0,100,150); 
     23    auto Brush b2 = new Brush(RGB(255,255,255)); 
     24    Brush oldBrush = gc.setBrush(b2); 
     25    gc.fillRect(r); 
     26    gc.drawRect(r); 
     27    gc.setBrush(oldBrush); 
    2828 
    29   PenData pd; 
    30   pd.width = 4; 
    31   pd.style = PenStyle.Solid; 
    32   pd.color = RGB(100,0,120); 
    33   auto Pen p = new Pen(&pd); 
    34   gc.setPen(p); 
    35   gc.drawLine(0,0,100,150); 
    36   gc.drawLine(100,0,0,150); 
    37   gc.drawLine(50,0,50,150); 
    38   gc.setPen(oldPen); 
    39   gc.dispose(); 
    40  
    41   win.paintDelegate ~= delegate void(Component source, GContext pc) { 
    42  
    43     auto Font font = new Font("", 20, FontWeight.Bold); 
    44     Font oldfont = pc.setFont(font); 
    45     pc.drawText(100,100,"testing"); 
    46     pc.setFont(oldfont); 
    47  
    48     pc.drawLine(10,10,20,20); 
    49     pc.drawLine(30,10,35,50); 
    50  
    51     static Point[3] pts = [{{40,10}}, {{45,50}}, {{50,30}}]; 
    52     pc.drawPolyline(pts); 
    53  
    54     static Point[4] pts2 = [{{70,10}},{{75,50}},{{80,30}},{{90,10}}]; 
    55     pc.drawPolygon(pts2); 
    56  
    57     static Point[4] pts3 = [{{100,10}},{{105,50}},{{110,30}},{{120,10}}]; 
    58     pc.fillPolygon(pts3); 
    59  
    60     // try different line styles and colors 
    6129    PenData pd; 
    6230    pd.width = 4; 
    63     pd.color = RGB(100,200,0); 
    64     pd.style = PenStyle.Dash; 
    65     auto Pen p1 = new Pen(&pd); 
    66     Pen oldPen = pc.setPen(p1); 
    67     pc.drawLine(10,100,20,200); 
     31    pd.style = PenStyle.Solid; 
     32    pd.color = RGB(100,0,120); 
     33    auto Pen p = new Pen(&pd); 
     34    gc.setPen(p); 
     35    gc.drawLine(0,0,100,150); 
     36    gc.drawLine(100,0,0,150); 
     37    gc.drawLine(50,0,50,150); 
     38    gc.setPen(oldPen); 
     39    gc.dispose(); 
    6840 
    69     pd.color = RGB(0,200,200); 
    70     auto Pen p2 = new Pen(&pd); 
    71     pc.setPen(p2); 
    72     pc.drawLine(50,100,50,200); 
     41    win.paintDelegate ~= delegate void(Component source, GContext pc) { 
    7342 
    74     pc.setPen(oldPen); 
     43        auto Font font = new Font("", 20, FontWeight.Bold); 
     44        Font oldfont = pc.setFont(font); 
     45        pc.drawText(100,100,"testing"); 
     46        pc.setFont(oldfont); 
    7547 
    76     pc.drawImage(im,180,30); 
    77   }
     48        pc.drawLine(10,10,20,20); 
     49        pc.drawLine(30,10,35,50)
    7850 
    79   win.visible = true; 
    80   return app.enterEventLoop(); 
     51        static Point[3] pts = [{{40,10}}, {{45,50}}, {{50,30}}]; 
     52        pc.drawPolyline(pts); 
     53 
     54        static Point[4] pts2 = [{{70,10}},{{75,50}},{{80,30}},{{90,10}}]; 
     55        pc.drawPolygon(pts2); 
     56 
     57        static Point[4] pts3 = [{{100,10}},{{105,50}},{{110,30}},{{120,10}}]; 
     58        pc.fillPolygon(pts3); 
     59 
     60        // try different line styles and colors 
     61        PenData pd; 
     62        pd.width = 4; 
     63        pd.color = RGB(100,200,0); 
     64        pd.style = PenStyle.Dash; 
     65        auto Pen p1 = new Pen(&pd); 
     66        Pen oldPen = pc.setPen(p1); 
     67        pc.drawLine(10,100,20,200); 
     68 
     69        pd.color = RGB(0,200,200); 
     70        auto Pen p2 = new Pen(&pd); 
     71        pc.setPen(p2); 
     72        pc.drawLine(50,100,50,200); 
     73 
     74        pc.setPen(oldPen); 
     75 
     76        pc.drawImage(im,180,30); 
     77    }; 
     78 
     79    win.visible = true; 
     80    return app.enterEventLoop(); 
    8181} 
  • trunk/minwin/samples/sample.d

    r5 r12  
    1111import std.string; 
    1212version (Windows) { 
    13   import minwin.mswindows; 
     13    import minwin.mswindows; 
    1414} 
    1515 
    16 extern (C)  
     16extern (C) 
    1717int MinWinMain(Application* app) { 
    18   Window win = new Window("MinWin Sample"); 
    19   char[] text  = "D Does Windows, Motif and GTK"; 
    20   win.quitOnDestroy = true; 
    21   win.paintDelegate ~= delegate void(Component source, GContext gc) { 
    22     FontData fd; 
    23     fd.size = 18; 
    24     fd.weight = FontWeight.Bold; 
    25     auto Font font = new Font(fd); 
    26     Font oldfont = gc.setFont(font); 
    27     gc.drawText(100,100,text); 
    28     gc.setFont(oldfont); 
    29     //    Image im = win.loadCompatibleImage(44); 
    30     //    gc.drawImage(im,200,200); 
    31   }; 
     18    Window win = new Window("MinWin Sample"); 
     19    char[] text    = "D Does Windows, Motif and GTK"; 
     20    win.quitOnDestroy = true; 
     21    win.paintDelegate ~= delegate void(Component source, GContext gc) { 
     22        FontData fd; 
     23        fd.size = 18; 
     24        fd.weight = FontWeight.Bold; 
     25        auto Font font = new Font(fd); 
     26        Font oldfont = gc.setFont(font); 
     27        gc.drawText(100,100,text); 
     28        gc.setFont(oldfont); 
     29        //        Image im = win.loadCompatibleImage(44); 
     30        //        gc.drawImage(im,200,200); 
     31    }; 
    3232 
    33   win.mouseDelegate ~= delegate void(Component source, MouseEvent* event) { 
    34     Point pt = event.point; 
    35     text = pt.toString ~ " " ~  toString(cast(int)event.id) ~" " ~ toString(event.modifiers); 
    36     win.repaint(); 
    37   }; 
     33    win.mouseDelegate ~= delegate void(Component source, MouseEvent* event) { 
     34        Point pt = event.point; 
     35        text = pt.toString ~ " " ~ toString(cast(int)event.id) ~ " " ~ toString(event.modifiers); 
     36        win.repaint(); 
     37    }; 
    3838 
    39   Button b = new Button(win,"Click me"); 
    40   Button b2 = new Button(win,"Don't click me"); 
     39    Button b = new Button(win,"Click me"); 
     40    Button b2 = new Button(win,"Don't click me"); 
    4141 
    42   // like winsamp.d place buttons by hand 
    43   Point s = b.preferredSize; 
    44   Rect r = LTWH(20,50,s.x,s.y); 
    45   b.setBounds(r); 
    46   s = b2.preferredSize; 
    47   r.LTWH(100,50,s.x,s.y); 
    48   b2.setBounds(r); 
     42    // like winsamp.d place buttons by hand 
     43    Point s = b.preferredSize; 
     44    Rect r = LTWH(20,50,s.x,s.y); 
     45    b.setBounds(r); 
     46    s = b2.preferredSize; 
     47    r.LTWH(100,50,s.x,s.y); 
     48    b2.setBounds(r); 
    4949 
    50   // define actions to perform on button clicks 
    51   b.actionDelegate ~= delegate void(Component source) { 
    52     informationDialog(win, "Hello, world!", "Greeting"); 
    53   }; 
    54   b2.actionDelegate ~= delegate void(Component source) { 
    55     warningDialog(win, "You've been warned...", "Prepare to GP fault"); 
    56     *(cast(int*) null) = 666;   
    57   };   
     50    // define actions to perform on button clicks 
     51    b.actionDelegate ~= delegate void(Component source) { 
     52        informationDialog(win, "Hello, world!", "Greeting"); 
     53    }; 
     54    b2.actionDelegate ~= delegate void(Component source) { 
     55        warningDialog(win, "You've been warned...", "Prepare to GP fault"); 
     56        *(cast(int*) null) = 666; 
     57    }; 
    5858 
    59   // show window 
    60   version (Windows) { 
    61     ShowWindow(win.peer,gApp.nCmdShow); 
    62   } else { 
    63     win.visible = true; 
    64  
     59    // show window 
     60    version (Windows) { 
     61        ShowWindow(win.peer,gApp.nCmdShow); 
     62    } else { 
     63        win.visible = true; 
     64   
    6565 
    66   return app.enterEventLoop(); 
     66    return app.enterEventLoop(); 
    6767} 
  • trunk/minwin/samples/sdialog.d

    r5 r12  
    1111 
    1212class MyDialog : Dialog { 
    13   int result; 
    14   this(MyWindow win, char[] str) { 
    15     super(win,str); 
    16     layoutMgr = new FlowLayout; 
    17     Button clicked; 
    18     Button ok = new Button(this,"OK"); 
    19     Button cancel = new Button(this,"Cancel"); 
    20     CheckBox bb = new CheckBox(this,"this is a big check"); 
    21     CheckBox bb2 = new CheckBox(this,"this check"); 
    22     ok.actionDelegate ~= &okCallback; 
    23     cancel.actionDelegate ~= &cancelCallback; 
    24     pack(); 
    25  
    26   void okCallback(Component c) { 
    27     MyWindow win = cast(MyWindow)owner; 
    28     win.title = "you hit ok"; 
    29     result = 100; 
    30     visible = false; 
    31   }     
    32   void cancelCallback(Component c) { 
    33     MyWindow win = cast(MyWindow)owner; 
    34     win.title = "you hit cancel"; 
    35     result = 101; 
    36     visible = false; 
    37   }     
     13    int result; 
     14    this(MyWindow win, char[] str) { 
     15        super(win,str); 
     16        layoutMgr = new FlowLayout; 
     17        Button clicked; 
     18        Button ok = new Button(this,"OK"); 
     19        Button cancel = new Button(this,"Cancel"); 
     20        CheckBox bb = new CheckBox(this,"this is a big check"); 
     21        CheckBox bb2 = new CheckBox(this,"this check"); 
     22        ok.actionDelegate ~= &okCallback; 
     23        cancel.actionDelegate ~= &cancelCallback; 
     24        pack(); 
     25   
     26    void okCallback(Component c) { 
     27        MyWindow win = cast(MyWindow)owner; 
     28        win.title = "you hit ok"; 
     29        result = 100; 
     30        visible = false; 
     31    } 
     32    void cancelCallback(Component c) { 
     33        MyWindow win = cast(MyWindow)owner; 
     34        win.title = "you hit cancel"; 
     35        result = 101; 
     36        visible = false; 
     37    } 
    3838} 
    3939 
    4040class MyWindow : Window { 
    41   this(char[] str) { 
    42     super(str); 
    43     layoutMgr = new FlowLayout; 
    44     Button but = new Button(this,"click me"); 
    45     but.actionDelegate ~= &doDialogCallback; 
    46   } 
    47   void doDialogCallback(Component c){doDialog();} 
    48   void doDialog() { 
    49     MyDialog dlg = new MyDialog(this,"hello"); 
    50     dlg.visible = true; 
    51     if (dlg.result == 0) { 
    52       title = "you destroyed the dialog"; 
     41    this(char[] str) { 
     42        super(str); 
     43        layoutMgr = new FlowLayout; 
     44        Button but = new Button(this,"click me"); 
     45        but.actionDelegate ~= &doDialogCallback; 
    5346    } 
    54   } 
     47    void doDialogCallback(Component c){doDialog();} 
     48    void doDialog() { 
     49        MyDialog dlg = new MyDialog(this,"hello"); 
     50        dlg.visible = true; 
     51        if (dlg.result == 0) { 
     52            title = "you destroyed the dialog"; 
     53        } 
     54    } 
    5555} 
    5656 
    57 extern (C)  
     57extern (C) 
    5858int MinWinMain(Application* app) { 
    59   MyWindow win = new MyWindow("window"); 
    60   win.quitOnDestroy = true; 
    61   win.visible = true; 
    62   return app.enterEventLoop(); 
     59    MyWindow win = new MyWindow("window"); 
     60    win.quitOnDestroy = true; 
     61    win.visible = true; 
     62    return app.enterEventLoop(); 
    6363} 
  • trunk/minwin/samples/sdialog2.d

    r7 r12  
    1616extern (C) 
    1717int MinWinMain(Application* app) { 
    18   Window win = new Window("window"); 
    19   win.quitOnDestroy = true; 
    20   win.layoutMgr = new FlowLayout; 
    21   Button but = new Button(win,"click me"); 
    22   but.actionDelegate ~= delegate void (Component c) { 
    23     Window w = cast(Window)c.parent; 
    24     Dialog dlg = new Dialog(w,"hit ok or cancel"); 
    25     dlg.layoutMgr = new FlowLayout; 
    26     Button ok = new Button(dlg,"OK"); 
    27     ok.cmd = OK; 
    28     Button cancel = new Button(dlg,"Cancel"); 
    29     cancel.cmd = CANCEL; 
    30     dlg.commandDelegate ~= delegate void(Component c, int cmd) { 
    31       Dialog dlg = cast(Dialog)c; 
    32       switch (cmd) { 
    33     case OK: 
    34     dlg.owner.title = "you hit ok"; 
    35     break; 
    36     case CANCEL: 
    37     dlg.owner.title = "you hit cancel"; 
    38     break; 
    39     default: assert(0); 
    40       } 
    41       // indicate a button was clicked 
    42       int* data = new int; 
    43       *data = cmd; 
    44       dlg.userdata[KEY] = data; 
    45       // end the dialog modality 
    46       dlg.visible = false; 
     18    Window win = new Window("window"); 
     19    win.quitOnDestroy = true; 
     20    win.layoutMgr = new FlowLayout; 
     21    Button but = new Button(win,"click me"); 
     22    but.actionDelegate ~= delegate void (Component c) { 
     23        Window w = cast(Window)c.parent; 
     24        Dialog dlg = new Dialog(w,"hit ok or cancel"); 
     25        dlg.layoutMgr = new FlowLayout; 
     26        Button ok = new Button(dlg,"OK"); 
     27        ok.cmd = OK; 
     28        Button cancel = new Button(dlg,"Cancel"); 
     29        cancel.cmd = CANCEL; 
     30        dlg.commandDelegate ~= delegate void(Component c, int cmd) { 
     31            Dialog dlg = cast(Dialog)c; 
     32            switch (cmd) { 
     33                case OK: 
     34                    dlg.owner.title = "you hit ok"; 
     35                    break; 
     36                case CANCEL: 
     37                    dlg.owner.title = "you hit cancel"; 
     38                    break; 
     39                default: assert(0); 
     40            } 
     41            // indicate a button was clicked 
     42            int* data = new int; 
     43            *data = cmd; 
     44            dlg.userdata[KEY] = data; 
     45            // end the dialog modality 
     46            dlg.visible = false; 
     47        }; 
     48        dlg.pack(); 
     49        dlg.visible = true; 
     50        if ((KEY in dlg.userdata) is null) { 
     51            w.title = "you destroyed the dialog"; 
     52        } 
    4753    }; 
    48     dlg.pack(); 
    49     dlg.visible = true; 
    50     if ((KEY in dlg.userdata) is null) { 
    51       w.title = "you destroyed the dialog"; 
    52     } 
    53   }; 
    54   win.visible = true; 
    55   return app.enterEventLoop(); 
     54    win.visible = true; 
     55    return app.enterEventLoop(); 
    5656} 
  • trunk/minwin/samples/topgroup.d

    r5 r12  
    1010import minwin.all; 
    1111 
    12 extern (C)  
     12extern (C) 
    1313int MinWinMain(Application* app) { 
    1414 
    15   Window win = new Window("Close window 2"); 
    16   win.cancelCloseDelegate ~= delegate bool(Component c) { 
    17     // we could pop up a confirm dialog but let's just say 
    18     // you can't destroy this window 
    19     return true;  
    20   }; 
     15    Window win = new Window("Close window 2"); 
     16    win.cancelCloseDelegate ~= delegate bool(Component c) { 
     17        // we could pop up a confirm dialog but let's just say 
     18        // you can't destroy this window 
     19        return true; 
     20    }; 
    2121 
    22   Window win2 = new Window("Testing 2"); 
    23   win2.quitOnDestroy = true; 
     22    Window win2 = new Window("Testing 2"); 
     23    win2.quitOnDestroy = true; 
    2424 
    25   Group g = new Group(null); 
    26   g ~= win; 
    27   g ~= win2; 
     25    Group g = new Group(null); 
     26    g ~= win; 
     27    g ~= win2; 
    2828 
    29   static double[2] x = [.5,.5]; 
    30   static double[1] y = [1]; 
    31   g.layoutMgr = new TableLayout(x,y); 
     29    static double[2] x = [.5,.5]; 
     30    static double[1] y = [1]; 
     31    g.layoutMgr = new TableLayout(x,y); 
    3232 
    33   Rect r; 
    34   r.LTWH(100,100,600,300); 
    35   g.setBounds(r); 
    36   g.layout(false); 
     33    Rect r; 
     34    r.LTWH(100,100,600,300); 
     35    g.setBounds(r); 
     36    g.layout(false); 
    3737 
    38   g.visible = true; 
     38    g.visible = true; 
    3939 
    40   return app.enterEventLoop(); 
     40    return app.enterEventLoop(); 
    4141} 
  • trunk/minwin/samples/widgets.d

    r5 r12  
    1212import std.utf; 
    1313 
    14 extern (C)  
     14extern (C) 
    1515int MinWinMain(Application* app) { 
    16   Window win = new Window("Widgets"); 
    17   win.quitOnDestroy = true; 
    18   win.backgroundColor = systemBackgroundColor(); 
    19   win.layoutMgr = new FlowLayout; 
     16    Window win = new Window("Widgets"); 
     17    win.quitOnDestroy = true; 
     18    win.backgroundColor = systemBackgroundColor(); 
     19    win.layoutMgr = new FlowLayout; 
    2020 
    21   CheckBox b3 = new CheckBox(win,"check 1"); 
    22   CheckBox b4 = new CheckBox(win,"check 2"); 
    23   ToggleButton b5 = new ToggleButton(win,"toggle 1"); 
     21    CheckBox b3 = new CheckBox(win,"check 1"); 
     22    CheckBox b4 = new CheckBox(win,"check 2"); 
     23    ToggleButton b5 = new ToggleButton(win,"toggle 1"); 
    2424 
    25   ToggleGroup g = new ToggleGroup; 
    26   GroupBox box = new GroupBox(win,"Group"); 
    27   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); 
     25    ToggleGroup g = new ToggleGroup; 
     26    GroupBox box = new GroupBox(win,"Group"); 
     27    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); 
    3333 
    34   Label lab = new Label(win,"This is a label"); 
    35   Text t1 = new Text(win,"single line"); 
    36   t1.userPreferredWidth = 60; 
    37   MultiLineText t2 = new MultiLineText(win,"multi line text area"); 
    38   t2.userPreferredSize(60,60); 
     34    Label lab = new Label(win,"This is a label"); 
     35    Text t1 = new Text(win,"single line"); 
     36    t1.userPreferredWidth = 60; 
     37    MultiLineText t2 = new MultiLineText(win,"multi line text area"); 
     38    t2.userPreferredSize(60,60); 
    3939 
    40   char[][] strs; 
    41   strs ~= "hello"; 
    42   strs ~= "world"; 
    43   strs ~= "bye"; 
    44   ComboBox combo = new ComboBox(win,strs); 
    45   combo.selection = 0; 
     40    char[][] strs; 
     41    strs ~= "hello"; 
     42    strs ~= "world"; 
     43    strs ~= "bye"; 
     44    ComboBox combo = new ComboBox(win,strs); 
     45    combo.selection = 0; 
    4646 
    47   ListBox list = new ListBox(win,strs); 
    48   list.selection = 0; 
    49   list.userPreferredHeight = 60; 
     47    ListBox list = new ListBox(win,strs); 
     48    list.selection = 0; 
     49    list.userPreferredHeight = 60; 
    5050 
    51   Canvas p = new Canvas(win); 
    52   p.keyDelegate ~= delegate void(Component source, KeyEvent* event) { 
    53     if (event.id == KeyPressedEvent) { 
    54       char[4] buf; 
    55       win.title = "you hit the " ~ toUTF8(buf,event.keyChar) ~ " key"; 
    56    
    57   }; 
    58   p.paintDelegate ~= delegate void(Component source, GContext gc) { 
    59     assert(source !is null); 
    60     auto Brush b = new Brush(RGB(250,20,20)); 
    61     Brush oldBrush = gc.setBrush(b); 
    62     Rect r = LTWH(0,0,source.width(),source.height()); 
    63     gc.fillRect(r); 
    64     gc.setBrush(oldBrush); 
    65   }; 
    66   p.userPreferredSize(20,20); 
     51    Canvas p = new Canvas(win); 
     52    p.keyDelegate ~= delegate void(Component source, KeyEvent* event) { 
     53        if (event.id == KeyPressedEvent) { 
     54            char[4] buf; 
     55            win.title = "you hit the " ~ toUTF8(buf,event.keyChar) ~ " key"; 
     56       
     57    }; 
     58    p.paintDelegate ~= delegate void(Component source, GContext gc) { 
     59        assert(source !is null); 
     60        scope Brush b = new Brush(RGB(250,20,20)); 
     61        Brush oldBrush = gc.setBrush(b); 
     62        Rect r = LTWH(0,0,source.width(),source.height()); 
     63        gc.fillRect(r); 
     64        gc.setBrush(oldBrush); 
     65    }; 
     66    p.userPreferredSize(20,20); 
    6767 
    68   ScrollBar sb = new ScrollBar(win,Horizontal); 
     68    ScrollBar sb = new ScrollBar(win,Horizontal); 
    6969 
    70   ScrollPane sp = new ScrollPane(win); 
    71   MultiLineText t3 = new MultiLineText(sp,"This is a big text block that needs some scrolling maybe if we are lucky"); 
    72   t3.userPreferredSize(221,334); // make a large scrollable area 
    73   sp.userPreferredSize(100,100); 
     70    ScrollPane sp = new ScrollPane(win); 
     71    MultiLineText t3 = new MultiLineText(sp,"This is a big text block that needs some scrolling maybe if we are lucky"); 
     72    t3.userPreferredSize(221,334); // make a large scrollable area 
     73    sp.userPreferredSize(100,100); 
    7474 
    75   win.pack(); 
    76   win.visible = true; 
     75    win.pack(); 
     76    win.visible = true; 
    7777 
    78   p.requestFocus(); // on GTK must be made visible first 
    79   return app.enterEventLoop(); 
     78    p.requestFocus(); // on GTK must be made visible first 
     79    return app.enterEventLoop(); 
    8080}