1 module formoshlep.window;
2 
3 import dlangui;
4 
5 class FormoshlepWindow : Window
6 {
7     private dstring caption;
8 
9     this(dstring caption)
10     {
11         this.caption = caption;
12         windowOrContentResizeMode = WindowOrContentResizeMode.shrinkWidgets;
13         super();
14 
15         //~ BT.open(caption.to!string);
16 
17         // set background color:
18         {
19             //~ BT.bkcolor(backgroundColor);
20             //~ BT.clear();
21             //~ BT.refresh();
22         }
23     }
24 
25     ~this()
26     {
27         close();
28     }
29 
30     import vibe.http.server: HTTPServerResponse;
31 
32     package void genHttpServerResponse(ref HTTPServerResponse res)
33     {
34         res.writeBody(toHtml.toString(false), "text/html; charset=UTF-8");
35     }
36 
37     import dhtags.tags.tag: HtmlFragment, HtmlString;
38 
39     private HtmlFragment toHtml()
40     {
41         import dhtags;
42         import std.conv: to;
43 
44         assert(mainWidget !is null);
45 
46         return
47             html
48             (
49                 head
50                 (
51                     tags.title
52                     (
53                         windowCaption().to!string
54                     )
55                 ),
56 
57                 body_
58                 (
59                     tags.form(enctype="multipart/form-data", action=".", method="post")
60                     (
61                         mainWidgetToHtml.toString(false)
62                     )
63                 )
64             );
65     }
66 
67     private HtmlFragment mainWidgetToHtml()
68     {
69         import formoshlep.widget;
70 
71         return mainWidget.toHtml;
72     }
73 
74     override:
75 
76     void close()
77     {
78         assert(false, __FUNCTION__~" isn't implemented");
79     }
80 
81     /// Displays window at the first time
82     void show() {}
83 
84     dstring windowCaption() const @property
85     {
86         return caption;
87     }
88 
89     void windowCaption(dstring caption) @property
90     {
91         this.caption = caption;
92     }
93 
94     void windowIcon(DrawBufRef icon) @property
95     {
96         assert(false, __FUNCTION__~" isn't implemented");
97     }
98 
99     void invalidate() {}
100 }