annotate mde/gui/widget/WidgetManager.d @ 175:1cbde9807293

Compile/link-time fixes for ldc & non-debug builds. Moved WidgetManager to widget/ Reverted IChildWidget to an interface, not an abstract class. Introduced a work-around for a compiler problem. May not cover all cases.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 11 Sep 2009 20:56:53 +0200
parents mde/gui/WidgetManager.d@a1ba9157510e
children af40e9679436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify it under the terms
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
15
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
16 /******************************************************************************
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
17 * The widget manager; root of the widget tree.
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
18 *
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
19 * Rendering is handled separately by an IRenderer.
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
20 *****************************************************************************/
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
21 module mde.gui.widget.WidgetManager;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
22
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
23 import mde.gui.WidgetDataSet;
34
6b4116e6355c Work on the Gui: some of the framework for drag & drop. Also made Window an IWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 32
diff changeset
24 import mde.gui.widget.Ifaces;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
25 import mde.gui.renderer.createRenderer;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
26
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
27 import imde = mde.imde;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
28 import mde.content.Content;
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
29 import mde.content.ServiceContent;
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
30 debug import mde.content.miscContent; // Debug menu
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
31 debug import mde.content.Debug;
128
41582439a42b Added support for dynamic EnumContent loading and saving, with translation loading.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 126
diff changeset
32
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
33 // Widgets to create:
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
34 import mde.gui.widget.layout;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
35 import mde.gui.widget.miscWidgets;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
36 import mde.gui.widget.TextWidget;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
37 import mde.gui.widget.contentFunctions;
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
38 import mde.gui.widget.miscContent;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
39 import mde.gui.widget.Floating;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
40 import mde.gui.widget.ParentContent;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
41 import mde.gui.widget.AParentWidget;
36
57d000574d75 Enabled drawing on demand, and made the polling interval configurable.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 35
diff changeset
42
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
43 public import tango.core.sync.Mutex;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
44 import tango.util.log.Log : Log, Logger;
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
45 import tango.io.Console; // to print exception stack-trace
113
9824bee909fd Popup menu; works for simple menus except that clicking an item doesn't close it.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 112
diff changeset
46 import tango.util.container.SortedMap;
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
47
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
48 private Logger logger;
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
49 static this () {
75
25cb7420dc91 A massive overhaul/rewrite for the gui's data management and setup code. Currently much that was working is broken.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 74
diff changeset
50 logger = Log.getLogger ("mde.gui.WidgetManager");
32
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
51 }
316b0230a849 Lots more work on the GUI. Also renamed lots of files.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
52
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
53 /******************************************************************************
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
54 * Methods in this class are only intended for use within the gui package,
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
55 * either by widgets (the IXXXWidget methods implementing from an interface in
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
56 * widgets.Ifaces.d) or by a derived class (back-end methods doing widget
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
57 * work). None of these methods are intended to be thread-safe when called
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
58 * concurrently on the same WidgetManager instance, but they should be thread-
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
59 * safe for calling on separate instances.
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
60 *****************************************************************************/
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
61 abstract class AWidgetManager : IWidgetManager
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
62 {
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
63 //BEGIN Public methods, for use outside the widget package
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
64 /** Construct a new widget manager.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
65 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
66 * Params:
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
67 * name = The file name of the config for this GUI (to identify multiple GUIs). */
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
68 this (char[] name) {
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
69 auto p = "MiscOptions.l10n" in Content.allContent;
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
70 assert (p, "MiscOptions.l10n not created!");
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
71 p.addCallback (&reloadStrings);
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
72
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
73 serviceContent = ServiceContentList.createItems (name);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
74 assert (cast (IServiceContent) Content.get ("menus.services."~name));
167
620d4ea30228 Context menus: added a clipboard (functions accessible from main menu rather than context menu).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 166
diff changeset
75
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
76 debug { // add a debug-mode menu
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
77 auto lWS = new EventContent ("menus.debug."~name~".logWidgetSize");
129
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
78 lWS.addCallback (&logWidgetSize);
ad91de8867a0 Added a widget size printing debug function. Fixed a bug in SwitchWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 128
diff changeset
79 }
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
80 }
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
81
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
82 /** A change callback on MiscOptions.l10n content to update widgets.
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
83 *
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
84 * Relies on another callback reloading translations to content first! */
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
85 final void reloadStrings (IContent) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
86 synchronized(mutex) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
87 if (childRoot is null) return;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
88 childRoot.setup (++setupN, 2);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
89 childRoot.setWidth (w, -1);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
90 childRoot.setHeight (h, -1);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
91 childRoot.setPosition (0,0);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
92 childContext.setup (setupN, 2);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
93 //TODO: possibly childDragged?
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
94 requestRedraw;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
95 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
96 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
97
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
98 debug public void logWidgetSize (IContent) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
99 logger.trace ("size: {,4},{,4}; minimal: {,4},{,4} - WidgetManager", w,h, mw,mh);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
100 logger.trace ("childRoot:");
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
101 childRoot.logWidgetSize;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
102 logger.trace ("childContext:");
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
103 childContext.logWidgetSize;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
104 if (childDragged !is null) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
105 logger.trace ("childDragged:");
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
106 childDragged.logWidgetSize;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
107 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
108 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
109
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
110
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
111 //BEGIN Public IWidget methods
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
112 override bool saveChanges () {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
113 bool ret = childRoot.saveChanges;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
114 ret |= childContext.saveChanges;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
115 if (childDragged !is null)
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
116 ret |= childDragged.saveChanges;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
117 return ret;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
118 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
119
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
120 /** Draw all widgets */
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
121 override void draw () {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
122 if (childRoot)
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
123 childRoot.draw;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
124 drawPopup;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
125 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
126 //END Public IWidget methods
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
127 //END Public methods, for use outside the widget package
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
128
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
129 //BEGIN IWidget methods for widgets
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
130 public override bool dropContent (IContent content) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
131 return false;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
132 }
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
133 //END IWidget methods for widgets
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
134
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
135 //BEGIN IParentWidget methods
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
136 // If call reaches the widget manager there isn't any recursion.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
137 //NOTE: should be override
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
138 final void recursionCheck (widgetID, IContent) {}
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
139
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
140 override void minWChange (IChildWidget widget, wdim nmw) {
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
141 if (widget !is childRoot) { // Probably because widget is a popup widget
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
142 // This may get called from a CTOR, hence we can't check widget is one of childContext, etc.
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
143 if (widget.width < nmw)
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
144 widget.setWidth (nmw, -1);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
145 return;
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
146 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
147 mw = nmw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
148 if (w < nmw) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
149 childRoot.setWidth (nmw, -1);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
150 w = nmw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
151 }
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
152 childRoot.setPosition (0,0);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
153 requestRedraw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
154 }
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
155 override void minHChange (IChildWidget widget, wdim nmh) {
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
156 if (widget !is childRoot) {
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
157 if (widget.height < nmh)
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
158 widget.setHeight (nmh, -1);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
159 return;
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
160 }
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
161 mh = nmh;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
162 if (h < nmh) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
163 childRoot.setHeight (nmh, -1);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
164 h = nmh;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
165 }
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
166 childRoot.setPosition (0,0);
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
167 requestRedraw;
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
168 }
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
169 //END IParentWidget methods
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
170
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
171 //BEGIN IPopupParentWidget methods
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
172 override IPopupParentWidget getParentIPPW () {
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
173 return this;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
174 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
175
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
176 override void addChildIPPW (IPopupParentWidget ippw) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
177 requestRedraw;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
178 if (ippw is childContext) { // special handling - a separate IPPW
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
179 contextActive = true;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
180 return;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
181 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
182 if (childIPPW)
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
183 childIPPW.removedIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
184 childIPPW = ippw;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
185 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
186 override bool removeChildIPPW (IPopupParentWidget ippw) {
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
187 if (ippw is childContext && contextActive) {
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
188 childContext.removedIPPW;
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
189 contextActive = false;
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
190 return true;
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
191 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
192 if (childIPPW !is ippw) return false;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
193 childIPPW.removedIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
194 childIPPW = null;
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
195 mAIPPW = MenuPosition.INACTIVE;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
196 requestRedraw;
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
197 return true;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
198 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
199
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
200 override void menuActive (MenuPosition mA) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
201 mAIPPW = mA;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
202 if (childIPPW)
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
203 childIPPW.menuActive = mA;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
204 if (contextActive)
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
205 childContext.menuActive = mA;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
206 }
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
207 override MenuPosition menuActive () {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
208 return mAIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
209 }
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
210 override MenuPosition parentMenuActive () {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
211 return MenuPosition.INACTIVE;
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
212 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
213
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
214 // Note: also triggered by non-popup widgets
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
215 override void menuDone () {}
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
216
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
217 override IChildWidget getPopupWidget (wdabs cx, wdabs cy, bool closePopup) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
218 IChildWidget ret;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
219 // Don't bother with childDragged; it has no interaction
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
220 if (contextActive) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
221 ret = childContext.getPopupWidget (cx, cy, closePopup);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
222 if (ret) return ret;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
223 if (closePopup) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
224 childContext.removedIPPW;
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
225 contextActive = false;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
226 requestRedraw;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
227 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
228 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
229 if (childIPPW) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
230 ret = childIPPW.getPopupWidget (cx, cy, closePopup);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
231 if (ret) return ret;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
232 if (closePopup) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
233 removeChildIPPW (childIPPW);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
234 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
235 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
236 return null;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
237 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
238
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
239 override void drawPopup () {
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
240 if (childIPPW)
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
241 childIPPW.drawPopup;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
242 if (contextActive)
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
243 childContext.drawPopup();
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
244 if (childDragged)
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
245 childDragged.draw();
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
246 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
247
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
248 debug override bool isChild (IPopupParentWidget ippw) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
249 if (contextActive && ippw is childContext)
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
250 return true;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
251 return ippw is childIPPW;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
252 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
253
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
254 override void removedIPPW () {} // irrelevant
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
255 //END IPopupParentWidget methods
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
256
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
257 //BEGIN IWidgetManager methods
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
258 override IChildWidget makeWidget (IParentWidget parent, widgetID id, IContent content = null)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
259 {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
260 debug assert (parent, "makeWidget: parent is null (code error)");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
261 debug scope (failure)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
262 logger.warn ("Creating widget \""~id~"\" failed.");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
263
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
264 WidgetData data = curData[id];
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
265 if (data.ints.length < 1) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
266 logger.error ("No int data; creating a debug widget");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
267 data.ints = [WIDGET_TYPE.Debug];
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
268 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
269 int type = data.ints[0]; // type is first element of data
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
270
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
271 try {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
272 // Statically programmed binary search on type, returning a new widget or calling a
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
273 // function:
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
274 //pragma (msg, binarySearch ("type", WIDGETS));
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
275 mixin (binarySearch ("type", WIDGETS));
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
276 // Not returned a new widget:
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
277 logger.error ("Bad widget type: {}; creating a debug widget instead",type);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
278 } catch (Exception e) {
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
279 logger.error ("Error creating widget; creating a debug widget instead. Exception printed to stderr.");
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
280 //TODO: find a standard way to output exceptions, and implement everywhere:
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
281 e.writeOut(delegate void(char[]s){ Cerr(s); });
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
282 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
283
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
284 return new DebugWidget (this, parent, id, data, content);
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
285 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
286
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
287 override WidgetData widgetData (widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
288 return curData[id];
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
289 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
290 override void widgetData (widgetID id, WidgetData d) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
291 changes[id] = d; // also updates WidgetDataSet in data.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
292 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
293
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
294 override wdims dimData (widgetID id) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
295 return curData.dims (id);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
296 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
297 override void dimData (widgetID id, wdims d) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
298 changes.setDims(id, d); // also updates WidgetDataSet in data.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
299 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
300
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
301 IRenderer renderer () {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
302 assert (rend !is null, "WidgetManager.renderer: rend is null");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
303 return rend;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
304 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
305
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
306 MenuPosition positionPopup (IChildWidget parent, IChildWidget popup, MenuPosition position = MenuPosition.INACTIVE) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
307 debug assert (parent && popup, "positionPopup: null widget");
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 169
diff changeset
308 debug if (Debug.logPopupPositioning())
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 169
diff changeset
309 logger.trace ("Placing popup {} in relation to parent {}; input position: {}", popup, parent, position);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
310 wdim w = popup.width,
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
311 h = popup.height,
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
312 x, y;
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
313 if (position & MenuPosition.ACTIVE) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
314 y = parent.yPos; // height flush with top
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
315 if (y+h > this.h) y += parent.height - h; // or bottom
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
316 if (position & MenuPosition.LEFT) { // previously left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
317 x = parent.xPos - w; // on left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
318 if (x < 0) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
319 x = parent.xPos + parent.width; // on right
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
320 position = MenuPosition.RIGHT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
321 }
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
322 } else { // previously right or above/below
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
323 x = parent.xPos + parent.width; // on right
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
324 position = MenuPosition.RIGHT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
325 if (x+w > this.w) {
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
326 x = parent.xPos - w; // or left
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
327 position = MenuPosition.LEFT;
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
328 }
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
329 }
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
330 } else {
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
331 wdim pw = parent.width;
165
bb2f1a76346d Fixed a few bugs; most notably changing the translation reloads the text on PopupMenuWidgets now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 163
diff changeset
332 if (popup.minWidth <= pw)
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
333 popup.setWidth (pw, -1); // neatness
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
334 x = parent.xPos; // align on left edge
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
335 if (x+w > this.w) x += pw - w; // align on right edge
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
336 y = parent.yPos + parent.height; // place below
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
337 if (y+h > this.h) y = parent.yPos - h; // or above
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
338 position = MenuPosition.ACTIVE;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
339 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
340 if (x < 0) x = 0; // may be placed partially off-screen
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
341 if (y < 0) y = 0;
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
342 popup.setPosition (x, y);
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 169
diff changeset
343 debug if (Debug.logPopupPositioning())
173
a1ba9157510e Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 171
diff changeset
344 logger.trace ("Placed popup {} of size ({},{}) at ({},{}); output position: {}", popup, w,h, x,y, position);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
345 return position;
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
346 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
347
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
348 void requestRedraw () {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
349 imde.mainSchedule.request(imde.SCHEDULE.DRAW);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
350 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
351 //END IWidgetManager methods
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
352
110
6acd96f8685f Translation reloading as far as AContent name/desc supported. Limited & crude support for updating gui.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 108
diff changeset
353 protected:
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
354 // These methods are called by derived classes to do the widget-management work
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
355 //BEGIN WidgetManagement methods
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
356 /** Second stage of widget loading.
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
357 *
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
358 * Widget data should be loaded before this is called. */
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
359 final void createWidgets () {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
360 // The renderer needs to be created on the first load, but not after this.
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
361 if (rend is null)
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
362 rend = createRenderer (rendName);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
363
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
364 debug (mdeWidgets) logger.trace ("Creating root widget...");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
365 childRoot = makeWidget (this, "root");
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
366 underMouse = childRoot; // don't leave null due to a check
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
367 debug (mdeWidgets) logger.trace ("Setting up root widget...");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
368 childRoot.setup (0, 3);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
369
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
370 mw = childRoot.minWidth;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
371 mh = childRoot.minHeight;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
372 matchMinimalSize ();
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
373
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
374 debug (mdeWidgets) logger.trace ("Setting size and position of root widget...");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
375 childRoot.setWidth (w, -1);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
376 childRoot.setHeight (h, -1);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
377 childRoot.setPosition (0,0);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
378 debug (mdeWidgets) logger.trace ("Done creating root widget.");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
379
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
380 childContext = new PopupHandlerWidget (this, this, "contextHandler", "context", serviceContent);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
381 childContext.setup (0,3);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
382 debug (mdeWidgets) logger.trace ("Created context handler widget.");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
383
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
384 underMouse = childRoot; // must be something
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
385 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
386
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
387 final void wmSizeEvent (int nw, int nh) {
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
388 w = cast(wdim) nw;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
389 h = cast(wdim) nh;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
390 matchMinimalSize;
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
391
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
392 if (!childRoot) return; // if not created yet.
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
393 childRoot.setWidth (w, -1);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
394 childRoot.setHeight (h, -1);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
395 childRoot.setPosition (0,0);
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
396 debug logWidgetSize (null);
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
397 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
398
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
399 /** For mouse click events.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
400 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
401 * Sends the event on to the relevant windows and all click callbacks. */
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
402 final void wmMouseClick (wdabs cx, wdabs cy, ubyte b, bool state) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
403 if (childRoot is null) return;
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
404
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
405 // Update underMouse to get the widget clicked on
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
406 updateUnderMouse (cx, cy, state);
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
407
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
408 // end of a drag?
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
409 if (dragStart !is null && b == dragButton && state == false) {
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
410 IChildWidget dS = dragStart;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
411 dragStart = null;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
412 childDragged = null;
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
413 requestRedraw;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
414 if (dS.dragRelease (cx, cy, underMouse))
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
415 return;
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
416 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
417
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
418 // Disable keyboard input if on another widget:
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
419 if (keyFocus && keyFocus !is underMouse) {
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
420 keyFocus.keyFocusLost;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
421 keyFocus = null;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
422 setLetterCallback (null);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
423 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
424
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
425 // Finally, post the actual event:
169
bc1cf73dc835 Context menu refinements: right button click-drag-release use and closing via buttons.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
426 if (b == 3 && state) { // right click - open context menu
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
427 Content contextContent = cast(Content) underMouse.content;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
428 if (contextContent !is null) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
429 serviceContent.setContent (contextContent);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
430 childContext.openMenu (underMouse, contextContent);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
431 }
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
432 } else { // post other button presses to clickEvent
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
433 int ret = underMouse.clickEvent (cast(wdabs)cx,cast(wdabs)cy,b,state);
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
434 if (ret & 1) { // keyboard input requested
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
435 keyFocus = underMouse;
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
436 setLetterCallback (&underMouse.keyEvent);
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
437 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
438 if (ret & 2 && dragStart is null) { // drag events requested
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
439 dragStart = underMouse;
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
440 dragButton = b; // currently we allow any button to be used for a drag, but.. ?
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
441 if (ret & 4) {
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
442 IContent c = underMouse.content();
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
443 if (c) { // NOTE: creates a new widget, not optimal
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
444 childDragged = new DisplayContentWidget (this, this, "dragContentDisplay", WidgetData ([0], []), c);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
445 childDragged.setup (0, 3);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
446 dragX = underMouse.xPos - cx;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
447 dragY = underMouse.yPos - cy;
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
448 childDragged.setPosition (cx + dragX, cy + dragY);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
449 }
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
450 }
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
451 }
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
452 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
453 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
454
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
455 /** For mouse motion events.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
456 *
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
457 * Lock on mutex before calling. Pass new mouse coordinates. */
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
458 final void wmMouseMotion (wdabs cx, wdabs cy) {
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
459 updateUnderMouse (cx, cy, false);
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
460
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
461 if (dragStart !is null) {
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
462 dragStart.dragMotion (cx, cy, underMouse);
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
463 if (childDragged !is null) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
464 childDragged.setPosition (cx + dragX, cy + dragY);
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
465 requestRedraw;
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
466 }
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
467 }
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
468 }
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
469
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
470 // for internal use
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
471 private final void updateUnderMouse (wdabs cx, wdabs cy, bool closePopup) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
472 auto oUM = underMouse;
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
473 underMouse = getPopupWidget (cx, cy, closePopup);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
474 if (underMouse is null) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
475 debug assert (childRoot.onSelf (cx, cy), "WidgetManager: childRoot doesn't cover whole area");
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
476 underMouse = childRoot.getWidget (cx, cy);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
477 }
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
478 debug assert (oUM && underMouse, "no widget under mouse: error");
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
479 if (underMouse !is oUM) {
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
480 oUM.underMouse (false);
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
481 underMouse.underMouse (true);
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
482 debug if (Debug.logUnderMouse())
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 167
diff changeset
483 logger.trace ("Widget under mouse: {}", underMouse);
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
484 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
485 }
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
486
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
487 /** If possible, the screen-interaction derived class should override to
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
488 * make sure the window is at least (mw,mh) in size. In any case, this
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
489 * method MUST make sure w >= mw and h >= mh even if the window isn't this
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
490 * big.
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
491 *
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
492 * A resize may not be required when this is called, however. */
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
493 void matchMinimalSize () {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
494 if (w < mw) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
495 logger.warn ("Min width for gui, {}, not met: {}", mw, w);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
496 w = mw;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
497 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
498 if (h < mh) {
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
499 logger.warn ("Min height for gui, {}, not met: {}", mh, h);
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
500 h = mh;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
501 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
502 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
503
159
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
504 /// This should be overloaded to set a callback receiving keyboard input.
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
505 abstract void setLetterCallback(void delegate(ushort, char[]));
b06b04c75e86 Finished last commit, rearranged code for the WidgetManager class.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
506 //END WidgetManagement methods
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
507
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
508 //BEGIN makeWidget metacode
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
509 private static {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
510 /// Widget types. Items match widget names without the "Widget" suffix.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
511 enum WIDGET_TYPE : int {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
512 FUNCTION = 0x2000, // Function called instead of widget created (no "Widget" appended to fct name)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
513 TAKES_CONTENT = 0x4000, // Flag indicates widget's this should be passed an IContent reference.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
514
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
515 // Use widget names rather than usual capitals convention
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
516 Unnamed = 0x0, // Only for use by widgets not created with createWidget
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
517
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
518 // blank: 0x1
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
519 FixedBlank = 0x1,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
520 SizableBlank = 0x2,
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
521 Debug = TAKES_CONTENT | 0xF,
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
522
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
523 // popup widgets: 0x10
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
524 PopupMenu = TAKES_CONTENT | 0x11,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
525
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
526 // labels: 0x20
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
527 TextLabel = 0x21,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
528
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
529 // content functions: 0x30
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
530 editContent = FUNCTION | TAKES_CONTENT | 0x30,
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
531 addContent = FUNCTION | 0x31,
132
264028f4115a Cleaned up mde.imde and a couple of widget functions.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
532 popupListContent = FUNCTION | TAKES_CONTENT | 0x33,
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
533
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
534 // content widgets: 0x40
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
535 DisplayContent = TAKES_CONTENT | 0x40,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
536 BoolContent = TAKES_CONTENT | 0x41,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
537 AStringContent = TAKES_CONTENT | 0x42,
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
538 ButtonContent = TAKES_CONTENT | 0x43,
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
539 SliderContent = TAKES_CONTENT | 0x44,
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
540
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
541 GridLayout = TAKES_CONTENT | 0x100,
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
542 ContentList = TAKES_CONTENT | 0x110,
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
543
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
544 FloatingArea = TAKES_CONTENT | 0x200,
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
545 Border = TAKES_CONTENT | 0x204,
125
3e648bc53bde Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
546 Switch = TAKES_CONTENT | 0x210,
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
547 Collapsible = TAKES_CONTENT | 0x214,
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
548 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
549
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
550 // Only used for binarySearch algorithm generation; must be ordered by numerical values.
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
551 const char[][] WIDGETS = [
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
552 "FixedBlank",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
553 "SizableBlank",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
554 "TextLabel",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
555 "addContent",
137
9f035cd139c6 BIG commit. Major change: old Options class is gone, all content values are loaded and saved automatically. All options updated to reflect this, some changed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 134
diff changeset
556 "Debug",
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
557 "PopupMenu",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
558 "DisplayContent",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
559 "BoolContent",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
560 "AStringContent",
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
561 "ButtonContent",
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 138
diff changeset
562 "SliderContent",
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
563 "GridLayout",
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
564 "ContentList",
123
d3b2cefd46c9 minSizeChange() allows run-time changes to widgets' minimal size (except for shrinking in a GridLayoutWidget).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 121
diff changeset
565 "FloatingArea",
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
566 "Border",
125
3e648bc53bde Added a simple switch/tab widget (depends on existing EnumContent).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 123
diff changeset
567 "Switch",
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
568 "Collapsible",
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
569 "editContent",
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
570 "popupListContent"];
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
571
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
572 /* Generates a binary search algorithm for makeWidget. */
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
573 char[] binarySearch (char[] var, char[][] consts) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
574 if (consts.length > 3) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
575 return `if (`~var~` <= WIDGET_TYPE.`~consts[$/2 - 1]~`) {` ~
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
576 binarySearch (var, consts[0 .. $/2]) ~
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
577 `} else {` ~
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
578 binarySearch (var, consts[$/2 .. $]) ~
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
579 `}`;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
580 } else {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
581 char[] ret;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
582 foreach (c; consts) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
583 ret ~= `if (` ~ var ~ ` == WIDGET_TYPE.` ~ c ~ `) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
584 debug (mdeWidgets) logger.trace ("Creating new `~c~`.");
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 132
diff changeset
585 parent.recursionCheck (id, content);
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
586 static if (WIDGET_TYPE.`~c~` & WIDGET_TYPE.FUNCTION)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
587 return `~c~` (this, parent, id, data, content);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
588 else static if (WIDGET_TYPE.`~c~` & WIDGET_TYPE.TAKES_CONTENT)
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
589 return new `~c~`Widget (this, parent, id, data, content);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
590 else
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
591 return new `~c~`Widget (this, parent, id, data);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
592 } else `;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
593 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
594 ret = ret[0..$-6]; // remove last else
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
595 return ret;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
596 }
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
597 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
598
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
599 debug { // check items in WIDGETS are listed in order
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
600 char[] WIDGETS_check () {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
601 char[] ret;
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
602 for (int i = WIDGETS.length-2; i > 0; --i) {
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
603 ret ~= "WIDGET_TYPE."~WIDGETS[i] ~" >= WIDGET_TYPE."~ WIDGETS[i+1];
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
604 if (i>1) ret ~= " || ";
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
605 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
606 return ret;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
607 }
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
608 mixin ("static if ("~WIDGETS_check~")
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
609 static assert (false, \"WIDGETS is not in order!\");");
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
610 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
611 }
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
612 //END makeWidget metacode
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
613
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
614 protected:
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
615 // Main child widget:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
616 IChildWidget childRoot; // Root of the main GUI widget tree
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
617
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
618 // Dimensions and child set-up data (fit to childRoot):
126
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
619 wdim w,h; // current widget size; should be at least (mw,mh) even if not displayable
c9843fbaac88 Dynamic minimal size changing improved; works over layouts sharing alignment.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 125
diff changeset
620 wdim mw,mh; // minimal area required by widgets
111
1655693702fc Resolved ticket #4, allowing widgets to reload strings and recalculate sizes mid-run.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 110
diff changeset
621 uint setupN; // n to pass to IChildWidget.setup
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
622
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
623 // IPopupParentWidget stuff for childRoot:
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
624 MenuPosition mAIPPW; // IPPW variable
131
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
625 IPopupParentWidget childIPPW; // child IPPW, if any active
9cff74f68b84 Major revisions to popup handling. Buttons can close menus now, plus some smaller impovements. Removed Widget module.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 129
diff changeset
626
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
627 IChildWidget keyFocus; // widget receiving keyboard input
175
1cbde9807293 Compile/link-time fixes for ldc & non-debug builds.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
628 IChildWidget underMouse; // widget under the mouse pointer; should never be null when childRoot is non-null
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
629
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
630
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
631 // Context menu:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
632 // Essentially, we consider childContext a full child IPPW, but handle it separately from
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
633 // childIPPW. Instead of providing another ref. for this IPPW, shortcut by using this reference
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
634 // and the boolean contextActive:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
635 scope PopupHandlerWidget childContext; // context menu popup (handler)
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
636 bool contextActive = false; // If true, consider childContext a child IPPW
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
637 scope IServiceContent serviceContent; // context menu content tree
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
638
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
639
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
640 // Drag-and-drop data:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
641 //NOTE: could be wrapped with a PopupHandlerWidget, but can't set position then?
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
642 scope IChildWidget childDragged; // displays dragged content; no interaction
160
ccd01fde535e Replaced WidgetManager's click and motion callbacks with a drag event system.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 159
diff changeset
643 IChildWidget dragStart; // if non-null, this widget should receive motion and click-release events
163
24d77c52243f Provided sensible conversions for setting the value of one AStringContent from another, along with unittest.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 162
diff changeset
644 int dragButton; // index of button in use for drag
166
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
645 wdrel dragX, dragY; // coordinates of dragged content relative to mouse
55667d048c31 Made content displayable while being dragged.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
646
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
647
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
648 // Renderer:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
649 char[] rendName; // Name of renderer; for saving and creating renderers
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
650 scope IRenderer rend;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
651
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
652
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
653 // Data loaded/to save:
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
654 WidgetDataSet curData; // Current data
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
655 WidgetDataChanges changes; // Changes for the current design.
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 117
diff changeset
656
99
5de5810e3516 Implemented an editable TextContent widget; it's now possible to edit text options using the GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 97
diff changeset
657 Mutex mutex; // lock on methods for use outside the package.
80
ea58f277f487 Gui reorganization and changes; partial implementation of floating widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 76
diff changeset
658 }