root/trunk/examples/behavior/behavior.d

Revision 17, 2.1 kB (checked in by bobef, 4 years ago)

Updated to HTMLayout 3.2.2.8 and added a new example (see change log for more details)

Line 
1 import flowerd.dfl;
2 import dfl.all;
3 import flowerd.config;
4 import htmlayout.behaviors.translatable;
5 import tango.io.Buffer;
6
7 class BaseForm : HLayoutForm
8 {
9     void init()
10     {
11         setOption(HTMLAYOUT_FONT_SMOOTHING,3);
12         trans=cast(HBehaviorTranslatable)HBehavior.find("translatable");
13         trans.load(new Buffer(getResource("language.kfg")),"bg");
14     }
15
16     static Config resources;
17     static char[] getResource(char[] res)
18     {
19         if(resources is null)
20         {
21             resources=new Config;
22             resources.load("behavior.res");
23            
24         }
25         return resources.getv(res);
26     }
27
28     void showError(char[] id)
29     {
30         msgBox(trans(id),trans(id~".title"),MsgBoxButtons.OK, MsgBoxIcon.ERROR);
31     }
32
33     bool askQuestion(char[] id,MsgBoxButtons buttons=MsgBoxButtons.YES_NO)
34     {
35         auto r=msgBox(trans(id),trans(id~".title"), buttons, MsgBoxIcon.QUESTION);
36         if(r==DialogResult.YES || r==DialogResult.OK) return true;
37         else return false;
38     }
39
40     HBehaviorTranslatable trans;
41 }
42
43 class MyForm : BaseForm
44 {
45     this()
46     {
47         htmlayout.capi.loadHTMLayout();
48         super();
49         init();
50     }
51
52     void init()
53     {
54         form.visible=false;
55         form.text="Behavior test";
56         //form.icon=(new Resources(Application.getInstance())).getIcon(2);
57
58         super.init();
59
60         HLayoutBase.handleEvent(&onLoadData);
61
62         loadHTML("res:///index.htm",getResource("index.htm"));
63
64         form.pack;
65         form.formBorderStyle=FormBorderStyle.FIXED_TOOLWINDOW;
66         form.centerToParent();
67
68         with(rootElement)
69         {
70             getId("button1").handleStatic(&onButton1);
71             getId("button2").handleStatic(&onButton2);
72         }
73     }
74
75     bool onButton1(HMouse p)
76     {
77         if(p.cmd==MOUSE_DOWN)
78         {
79             trans.language="bg";
80             return true;
81         }
82         return false;
83     }
84
85     bool onButton2(HMouse p)
86     {
87         if(p.cmd==MOUSE_DOWN)
88         {
89             trans.language="en";
90             return true;
91         }
92         return false;
93     }
94
95     bool onLoadData(HLoadData data)
96     {
97         const RES="res:///";
98         auto uri=data.uri;
99         if(uri.length>RES.length && uri[0..RES.length]==RES)
100         {
101             auto res=getResource(uri[RES.length..$]);
102             if(res.length) dataReady(uri,res);
103             return true;
104         }
105         return false;
106     }
107 }
108
109 void main()
110 {
111     Application.run(cast(Form)new MyForm);
112 }
Note: See TracBrowser for help on using the browser.