annotate mde/gui/widget/ParentContent.d @ 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.
author Diggory Hardy <diggory.hardy@gmail.com>
date Sat, 08 Aug 2009 15:53:10 +0200
parents 0dd49f333189
children 3d58adc17d20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
1 /* LICENSE BLOCK
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
2 Part of mde: a Modular D game-oriented Engine
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
3 Copyright © 2007-2008 Diggory Hardy
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
4
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
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
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
6 of the GNU General Public License as published by the Free Software Foundation, either
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
7 version 2 of the License, or (at your option) any later version.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
8
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
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;
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
11 See the GNU General Public License for more details.
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
12
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
13 You should have received a copy of the GNU General Public License
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
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: 121
diff changeset
16 /******************************************************************************
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
17 * A pop-up widget, a switch (tab) widget, and a collapsible widget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
18 * (all parent widgets using content).
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
19 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
20 * Also a border widget (parent not using content).
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: 121
diff changeset
21 *****************************************************************************/
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
22 module mde.gui.widget.ParentContent;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
23
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: 121
diff changeset
24 import mde.gui.widget.AParentWidget;
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
25 import mde.gui.widget.layout;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
26 import mde.content.AStringContent;
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
27 import mde.gui.exception;
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
28
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
29 debug {
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
30 import tango.util.log.Log : Log, Logger;
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
31 private Logger logger;
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
32 static this () {
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
33 logger = Log.getLogger ("mde.gui.widget.ParentContent");
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
34 }
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
35 }
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
36
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: 121
diff changeset
37 /******************************************************************************
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
38 * Widget which pops up a ContentListWidget created with its content.
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
39 *
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
40 * Is a button displaying a content string, just like DisplayContentWidget.
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
41 *
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
42 * Popped up widget is a ContentListWidget created from the same creation data.
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: 121
diff changeset
43 *****************************************************************************/
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: 121
diff changeset
44 class PopupMenuWidget : APopupParentWidget
108
c9fc2d303178 Added capability for border-less pop-up widgets. Simple pop-up menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff changeset
45 {
121
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
46 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
47 content_ = cast(Content)c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
48 WDCMinCheck (data, 3,1, 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: 119
diff changeset
49 super (mgr, parent, id);
5b37d0400732 Widgets now receive and store their parent (IParentWidget). Infinite widget recursion checks. WidgetManager code redistributed.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 119
diff changeset
50
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
51 popup = new ContentListWidget (mgr, this, id, data, c);
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: 121
diff changeset
52 subWidgets = [popup];
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
53
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
54 cIndex = data.ints[2];
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
55 if (cIndex == 0)
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
56 content_.addCallback (&updateVal);
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
57 adapter = mgr.renderer.getAdapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
58 adapter.text = content_.toString (cIndex);
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
59 adapter.getDimensions (mw, mh);
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
60 w = mw;
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
61 h = mh;
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
62 }
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
63
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
64 override bool setup (uint n, uint flags) {
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
65 bool ret = super.setup (n, flags);
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
66 if (!(flags & 3)) return ret;
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
67 // else string or renderer (and possibly font) changed
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
68 adapter.text = content_.toString (cIndex);
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
69 wdim omw = mw, omh = mh;
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
70 adapter.getDimensions (mw, mh);
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
71 if (omw != mw || omh != mh) {
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
72 w = mw;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
73 h = mh;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
74 return true;
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
75 }
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
76 return ret;
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
77 }
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
78
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
79 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
80 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
81 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
82
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
83 override bool dropContent (IContent content) {
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
84 if (content_.set (content))
162
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
85 return true;
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
86 return parent.dropContent (content);
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
87 }
2476790223b8 First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 158
diff changeset
88
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
89 override void recursionCheck (widgetID wID, IContent c) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
90 if (wID is id && c is content_)
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
91 throw new WidgetRecursionException (wID);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
92 parent.recursionCheck (wID, c);
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
93 }
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
94
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
95 override int clickEvent (wdabs, wdabs, ubyte b, bool state) {
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
96 if (b == 1 && state == true) {
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
97 if (!pushed) {
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: 121
diff changeset
98 parentIPPW.addChildIPPW (this);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
99 parentIPPW.menuActive = mgr.positionPopup (this, popup);
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: 121
diff changeset
100 pushed = true;
133
9fd705793568 Fixed menu popup bug, improved recursion detection.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 131
diff changeset
101 } else if (!parentIPPW.parentMenuActive) { // if not a submenu
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: 121
diff changeset
102 parentIPPW.removeChildIPPW (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: 121
diff changeset
103 }
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
104 }
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
105 return 0;
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
106 }
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
107
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: 121
diff changeset
108 override void 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: 121
diff changeset
109 super.removedIPPW;
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
110 pushed = false;
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
111 }
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: 121
diff changeset
112
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: 121
diff changeset
113 override void underMouse (bool state) {
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: 121
diff changeset
114 if (state && !pushed && parentIPPW.menuActive) {
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: 121
diff changeset
115 parentIPPW.addChildIPPW (this);
152
c67d074a7111 Menu placement now takes into account left/right placement of parent menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 147
diff changeset
116 menuActive = mgr.positionPopup (this, popup, parentIPPW.parentMenuActive);
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: 121
diff changeset
117 pushed = true;
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: 121
diff changeset
118 }
117
aba2dd815a1f Some tweaks to popup events and widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 115
diff changeset
119 }
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
120
114
b16a534f5302 Changes for tango r4201. Added override keyword in a lot of places.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 113
diff changeset
121 override void draw () {
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
122 mgr.renderer.drawButton (x,y, w,h, pushed);
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
123 adapter.draw (x,y);
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
124 }
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
125
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
126 protected:
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
127 void updateVal (IContent) { // callback
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
128 adapter.text = content_.toString(cIndex);
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
129 wdim omw = mw, omh = mh;
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
130 adapter.getDimensions (mw, mh);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
131 if (omw != mw)
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
132 parent.minWChange (this, mw);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
133 if (omh != mh)
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
134 parent.minHChange (this, mh);
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
135 }
158
f132e599043f Re-enabled raising floating widgets, by clicking frame; disabled attempt at immediate language reloading for popup-button widgets.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 155
diff changeset
136
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
137 bool pushed = false;
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
138 IRenderer.TextAdapter adapter;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
139 Content content_;
138
3468e9bfded1 Popup widgets: are simpler to use and can show content fields like DisplayContentWidget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 137
diff changeset
140 int cIndex;
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
141 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
142
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
143 /** A "tab" widget: it doesn't display the tabs, but shows one of a number of
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
144 * widgets dependant on an EnumContent.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
145 *
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
146 * Sizability is set once. Min-size is updated when switching. */
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
147 class SwitchWidget : AParentWidget
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
148 {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
149 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
150 super (mgr, parent, id);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
151 content_ = cast(EnumContent) c;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
152 if (content_ is null || (subWidgets.length = content_.list.length) == 0)
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
153 throw new ContentException (this);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
154 WDCheck (data, 1, subWidgets.length);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
155
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
156 foreach (i,sc; content_.list)
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
157 subWidgets[i] = mgr.makeWidget (this, data.strings[i], sc);
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
158 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
159
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
160 content_.addCallback (&switchWidget);
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
161 }
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
162
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
163 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
164 return content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
165 }
172
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
166 override void setContent (IContent) {
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
167 logger.warn ("SwitchWidget: resetting content is not yet supported");
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
168 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
169
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
170 override bool setup (uint n, uint flags) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
171 bool r = super.setup (n, flags);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
172 if (r) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
173 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
174 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
175 w = currentW.width;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
176 h = currentW.height;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
177 static if (SIZABILITY & SIZABILITY_ENUM.START_TRUE)
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
178 isWS = isHS = true;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
179 foreach (i,sc; content_.list) {
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
180 static if (SIZABILITY == SIZABILITY_ENUM.ANY_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
181 isWS |= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
182 isHS |= subWidgets[i].isHSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
183 } else static if (SIZABILITY == SIZABILITY_ENUM.ALL_SUBWIDGETS) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
184 isWS &= subWidgets[i].isWSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
185 isHS &= subWidgets[i].isHSizable;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
186 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
187 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
188 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
189 return r;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
190 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
191
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
192 override void recursionCheck (widgetID wID, IContent c) {
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
193 if (wID is id && c is content_)
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
194 throw new WidgetRecursionException (wID);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
195 parent.recursionCheck (wID, c);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
196 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
197
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
198 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: 172
diff changeset
199 if (widget is currentW) {
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: 172
diff changeset
200 mw = 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: 172
diff changeset
201 parent.minWChange (this, 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: 172
diff changeset
202 } else { // changes won't be seen, but we must follow function spec
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: 172
diff changeset
203 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: 172
diff changeset
204 widget.setWidth (nmw, -1);
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: 172
diff changeset
205 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
206 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
207 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: 172
diff changeset
208 if (widget is currentW) {
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: 172
diff changeset
209 mh = 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: 172
diff changeset
210 parent.minHChange (this, 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: 172
diff changeset
211 } else {
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: 172
diff changeset
212 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: 172
diff changeset
213 widget.setHeight (nmh, -1);
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: 172
diff changeset
214 }
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
215 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
216
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
217 override bool isWSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
218 return isWS;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
219 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
220 override bool isHSizable () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
221 return isHS;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
222 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
223
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
224 override void setWidth (wdim nw, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
225 w = (nw >= mw ? nw : mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
226 currentW.setWidth (w, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
227 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
228 override void setHeight (wdim nh, int dir) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
229 h = (nh >= mh ? nh : mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
230 currentW.setHeight (h, dir);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
231 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
232
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
233 override void setPosition (wdim nx, wdim ny) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
234 x = nx;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
235 y = ny;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
236 currentW.setPosition (nx,ny);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
237 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
238
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
239 override IChildWidget getWidget (wdim cx, wdim cy) {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
240 return currentW.getWidget (cx, cy);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
241 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
242
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
243 override void draw () {
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
244 currentW.draw;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
245 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
246
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
247 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
248 // callback on content_
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
249 void switchWidget (IContent) {
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
250 currentW = subWidgets[content_()];
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
251 mw = currentW.minWidth;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
252 mh = currentW.minHeight;
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
253 parent.minWChange (this, mw);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
254 parent.minHChange (this, mh);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
255 // Parent may change size. If it doesn't, we must set child's size.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
256 // We can't tell if it did, so do it (call will be fast if size isn't
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
257 // changed anyway).
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
258 currentW.setWidth (w, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
259 currentW.setHeight (h, -1);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
260 currentW.setPosition (x,y);
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
261 }
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
262
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
263 IChildWidget currentW;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
264 EnumContent content_;
143
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
265
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
266 bool isWS, isHS; // no infrastructure for changing sizability, so need to fix it.
2ac3e0012788 Added a simple Slider widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 141
diff changeset
267 }
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
268
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
269 /** A collapsible widget: shows/hides a child dependant on an IBoolContent.
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
270 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
271 * Sizability is set once. Min-size is changed (but cannot force size to 0).
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
272 *
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
273 * Uses its content as a switch, which means content cannot be passed through.
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
274 * A builtin button would improve this. */
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
275 class CollapsibleWidget : AParentWidget
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
276 {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
277 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
278 super (mgr, parent, id);
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
279 content_ = cast(IBoolContent) c;
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
280 WDCCheck (data, 1, 1, content_);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
281
155
4e8819b65882 Changed collapsible widget in GUI.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 152
diff changeset
282 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
283
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: 172
diff changeset
284 content_.addCallback (&cbDisplay);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
285 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
286
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
287 override bool setup (uint n, uint flags) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
288 bool r = super.setup (n, flags);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
289 if (r) {
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: 172
diff changeset
290 display = content_();
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: 172
diff changeset
291 if (display) {
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
292 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
293 mh = subWidgets[0].minHeight;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
294 w = subWidgets[0].width;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
295 h = subWidgets[0].height;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
296 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
297 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
298 return r;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
299 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
300
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
301 override void recursionCheck (widgetID wID, IContent c) {
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
302 if (wID is id && c is content_)
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
303 throw new WidgetRecursionException (wID);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
304 parent.recursionCheck (wID, c);
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
305 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
306
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
307 override IContent content () {
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
308 return content_;
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
309 }
172
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
310 override void setContent (IContent c) {
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
311 auto cont = cast(IBoolContent) c;
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
312 if (!cont) {
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
313 logger.warn ("CollapsibleWidget: invalid content set: {}; ignoring", c);
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
314 return;
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
315 }
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
316 content_ = cont;
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: 172
diff changeset
317 cbDisplay (content_);
172
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
318 }
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
319
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
320 override void minWChange (IChildWidget widget, wdim nmw) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
321 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
322 mw = nmw;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
323 parent.minWChange (this, nmw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
324 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
325 override void minHChange (IChildWidget widget, wdim nmh) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
326 debug assert (widget is subWidgets[0]);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
327 mh = nmh;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
328 parent.minHChange (this, nmh);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
329 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
330
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
331 // Doesn't change:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
332 override bool isWSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
333 return subWidgets[0].isWSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
334 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
335 override bool isHSizable () {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
336 return subWidgets[0].isHSizable;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
337 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
338
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
339 override void setWidth (wdim nw, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
340 w = (nw >= mw ? nw : mw);
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: 172
diff changeset
341 subWidgets[0].setWidth (w, dir);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
342 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
343 override void setHeight (wdim nh, int dir) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
344 h = (nh >= mh ? nh : mh);
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: 172
diff changeset
345 subWidgets[0].setHeight (h, dir);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
346 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
347
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
348 override void setPosition (wdim nx, wdim ny) {
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
349 x = nx;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
350 y = ny;
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: 172
diff changeset
351 if (display) subWidgets[0].setPosition (nx,ny);
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
352 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
353
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
354 override IChildWidget getWidget (wdim cx, wdim cy) {
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: 172
diff changeset
355 if (display)
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
356 return subWidgets[0].getWidget (cx, cy);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
357 else return this;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
358 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
359
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
360 override void draw () {
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: 172
diff changeset
361 if (display) subWidgets[0].draw;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
362 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
363
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
364 protected:
146
783969f4665c Simple, inefficient context menus (displaying content description).
Diggory Hardy <diggory.hardy@gmail.com>
parents: 144
diff changeset
365 // callback on content_
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: 172
diff changeset
366 void cbDisplay (IContent) {
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: 172
diff changeset
367 if (display == content_()) return;
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: 172
diff changeset
368 display = content_();
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: 172
diff changeset
369 logger.trace ("{}.cbDisplay ({})", id, display);
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: 172
diff changeset
370 if (display) {
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
371 mw = subWidgets[0].minWidth;
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
372 mh = subWidgets[0].minHeight;
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: 172
diff changeset
373 } else {
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: 172
diff changeset
374 mw = mh = 0;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
375 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
376 parent.minWChange (this, mw);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
377 parent.minHChange (this, mh);
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: 172
diff changeset
378 if (!display) return;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
379 // set incase parent didn't:
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
380 subWidgets[0].setWidth (w, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
381 subWidgets[0].setHeight (h, -1);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
382 subWidgets[0].setPosition (x,y);
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
383 }
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
384
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: 172
diff changeset
385 bool display = false;
170
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 168
diff changeset
386 IBoolContent content_;
144
66c58e5b0062 Added a BoolContent-based collapsible widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 143
diff changeset
387 }
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
388
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
389 /** Puts a border around its child widget.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
390 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
391 * This doesn't allow dragging like widgets in a floating area.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
392 *
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
393 * data.ints[1] is interpreted as flags from IRenderer.Border.BTYPE.
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
394 * data.strings[0] is an ID for the child widget. */
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
395 class BorderWidget : AParentWidget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
396 {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
397 this (IWidgetManager mgr, IParentWidget parent, widgetID id, WidgetData data, IContent c) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
398 super (mgr, parent, id);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
399 WDCheck (data, 2, 1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
400
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
401 subWidgets = [mgr.makeWidget (this, data.strings[0], c)];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
402 borderType = cast(BTYPE) data.ints[1];
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
403 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
404
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
405 override bool setup (uint n, uint flags) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
406 if (!subWidgets[0].setup (n, flags) && !(flags & 1)) return false;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
407
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
408 border = mgr.renderer.getBorder (borderType, false, false);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
409 mw = subWidgets[0].minWidth + border.x1 + border.x2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
410 mh = subWidgets[0].minHeight + border.y1 + border.y2;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
411 if (w < mw || !subWidgets[0].isWSizable) w = mw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
412 if (h < mh || !subWidgets[0].isHSizable) h = mh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
413 return true;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
414 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
415
172
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
416 override void setContent (IContent c) {
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
417 subWidgets[0].setContent = c;
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
418 }
0dd49f333189 Implemented "void setContent (IContent)".
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
419
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
420 override void setWidth (wdim nw, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
421 debug assert (nw >= mw);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
422 w = nw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
423 subWidgets[0].setWidth (w - border.x1 - border.x2, -1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
424 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
425 override void setHeight (wdim nh, int) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
426 debug assert (nh >= mh);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
427 h = nh;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
428 subWidgets[0].setHeight (h - border.y1 - border.y2, -1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
429 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
430
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
431 override bool isWSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
432 return subWidgets[0].isWSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
433 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
434 override bool isHSizable () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
435 return subWidgets[0].isHSizable;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
436 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
437
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
438 override void setPosition (wdim nx, wdim ny) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
439 x = nx;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
440 y = ny;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
441 subWidgets[0].setPosition (x + border.x1, y + border.y1);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
442 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
443
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
444 override void minWChange (IChildWidget widget, wdim nmw) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
445 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
446 mw = nmw + border.x1 + border.x2;
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: 172
diff changeset
447 parent.minWChange (this, mw);
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
448 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
449 override void minHChange (IChildWidget widget, wdim nmh) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
450 debug assert (widget is subWidgets[0]);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
451 mh = nmh + border.y1 + border.y2;
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: 172
diff changeset
452 parent.minHChange (this, mh);
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
453 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
454
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
455 override void draw () {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
456 mgr.renderer.drawBorder (&border, x, y, w, h);
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
457 subWidgets[0].draw;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
458 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
459
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
460 override IChildWidget getWidget (wdim cx, wdim cy) {
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
461 debug assert (cx >= x && cx < x + w && cy >= y && cy < y + h, "getWidget: not on widget (code error)");
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
462
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
463 if (subWidgets[0].onSelf (cx, cy))
168
da8d3091fdaf More work on the context menu: now roughly usable like an ordinary context menu.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 165
diff changeset
464 return subWidgets[0].getWidget (cx, cy);
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
465 else
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
466 return this;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
467 }
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
468
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
469 protected:
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: 172
diff changeset
470 invariant {
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: 172
diff changeset
471 // this() calls makeWidget() which calls recursionCheck(); invariant is called at this point before this() finishes
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: 172
diff changeset
472 if (subWidgets.length) {
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: 172
diff changeset
473 assert (subWidgets.length == 1);
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: 172
diff changeset
474 assert (mw == subWidgets[0].minWidth + border.x1 + border.x2);
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: 172
diff changeset
475 assert (mh == subWidgets[0].minHeight + border.y1 + border.y2);
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: 172
diff changeset
476 }
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: 172
diff changeset
477 }
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: 172
diff changeset
478
147
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
479 alias IRenderer.Border.BTYPE BTYPE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
480 alias IRenderer.Border.RESIZE RESIZE;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
481 BTYPE borderType; // what type of border to put around the widget
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
482 IRenderer.Border border;
075705ad664a Added a border widget.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 146
diff changeset
483 }