comparison mde/gui/WMScreen.d @ 171:7f7b2011b759

Partially complete commit: code runs but context menus don't work. Moved WMScreen.createRootWidget to WidgetManager.createWidgets. Put childContext under a popupHandler widget. TODO: implement IChildWidget.setContent(Content) (see AParentWidget.d:237).
author Diggory Hardy <diggory.hardy@gmail.com>
date Sun, 26 Jul 2009 11:04:17 +0200
parents b06b04c75e86
children a1ba9157510e
comparison
equal deleted inserted replaced
170:e45226d3deae 171:7f7b2011b759
22 module mde.gui.WMScreen; 22 module mde.gui.WMScreen;
23 23
24 import mde.gui.WidgetManager; 24 import mde.gui.WidgetManager;
25 import mde.gui.WidgetLoader; 25 import mde.gui.WidgetLoader;
26 import mde.gui.widget.Ifaces; 26 import mde.gui.widget.Ifaces;
27 import mde.gui.renderer.createRenderer;
28 27
29 import mde.setup.Screen; 28 import mde.setup.Screen;
30 import mde.input.Input; 29 import mde.input.Input;
31 30
32 import tango.util.log.Log : Log, Logger; 31 import tango.util.log.Log : Log, Logger;
66 // Events we want to know about: 65 // Events we want to know about:
67 input = Input.singleton; 66 input = Input.singleton;
68 input.addMouseClickCallback(&clickEvent) 67 input.addMouseClickCallback(&clickEvent)
69 .addMouseMotionCallback(&motionEvent); 68 .addMouseMotionCallback(&motionEvent);
70 } 69 }
70 ~this () {
71 // Make sure the keyboard is not locked in text-entry mode.
72 input.setLetterCallback (null);
73 }
71 74
72 /** Draw the gui. */ 75 /** Draw the gui. */
73 void draw() { 76 void draw() {
74 synchronized(mutex) { 77 synchronized(mutex) {
75 debug (mdeDrawEvents) 78 debug (mdeDrawEvents)
98 } catch (Exception e) { 101 } catch (Exception e) {
99 logger.error ("motionEvent: exception processing event: {}", e.msg); 102 logger.error ("motionEvent: exception processing event: {}", e.msg);
100 } 103 }
101 } 104 }
102 105
103 106 /** Notification of externally-caused screen resize.
107 *
108 * Should be called before createWidgets to prevent widgets being squashed
109 * to min-dims on loading (losing saved dimensions of columns, etc). */
104 void sizeEvent (int nw, int nh) { // IDrawable function 110 void sizeEvent (int nw, int nh) { // IDrawable function
105 mutex.lock; 111 mutex.lock;
106 scope(exit) mutex.unlock; 112 scope(exit) mutex.unlock;
107 113
108 w = cast(wdim) nw; 114 w = cast(wdim) nw;
109 h = cast(wdim) nh; 115 h = cast(wdim) nh;
116 matchMinimalSize;
110 117
111 if (w < mw) { 118 if (!childRoot) return; // if not created yet.
112 logger.warn ("Min width for gui, {}, not met: {}", mw, w); 119 childRoot.setWidth (w, -1);
113 w = mw; 120 childRoot.setHeight (h, -1);
114 } 121 childRoot.setPosition (0,0);
115 if (h < mh) {
116 logger.warn ("Min height for gui, {}, not met: {}", mh, h);
117 h = mh;
118 }
119
120 if (!child) return; // if not created yet.
121 child.setWidth (w, -1);
122 child.setHeight (h, -1);
123 child.setPosition (0,0);
124 } 122 }
125 123
126 protected: 124 protected:
127 final override void setLetterCallback(void delegate(ushort, char[]) dlg) { 125 final override void setLetterCallback(void delegate(ushort, char[]) dlg) {
128 input.setLetterCallback (dlg); 126 input.setLetterCallback (dlg);
129 }
130
131 /* Second stage of widget loading.
132 * Note: sizeEvent should be called with window size before this. */
133 final override void createRootWidget () {
134 // The renderer needs to be created on the first load, but not after this.
135 if (rend is null)
136 rend = createRenderer (rendName);
137
138 debug (mdeWidgets) logger.trace ("Creating root widget...");
139 child = makeWidget (this, "root");
140 debug (mdeWidgets) logger.trace ("Setting up root widget...");
141 child.setup (0, 3);
142
143 mw = child.minWidth;
144 mh = child.minHeight;
145 if (w < mw) {
146 logger.warn ("Min width for gui, {}, not met: {}", mw, w);
147 w = mw;
148 }
149 if (h < mh) {
150 logger.warn ("Min height for gui, {}, not met: {}", mh, h);
151 h = mh;
152 }
153
154 debug (mdeWidgets) logger.trace ("Setting size and position of root widget...");
155 child.setWidth (w, -1);
156 child.setHeight (h, -1);
157 child.setPosition (0,0);
158 debug (mdeWidgets) logger.trace ("Done creating root widget.");
159 } 127 }
160 128
161 final override void preSave () { 129 final override void preSave () {
162 if (keyFocus) { 130 if (keyFocus) {
163 keyFocus.keyFocusLost; 131 keyFocus.keyFocusLost;