summaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-12-29 17:07:41 +0000
committerDarkvater <Darkvater@openttd.org>2006-12-29 17:07:41 +0000
commit684ec92c19dd9d749d3c60c3ed5e0078a2e08299 (patch)
tree0c805e369dd82e534d576e98a38f47226c8124c8 /window.c
parentd42ee81f7996f5d62d843e004338903cb9d05cc7 (diff)
downloadopenttd-684ec92c19dd9d749d3c60c3ed5e0078a2e08299.tar.xz
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
is a window whose parent pointer is non-null. Deleting the parent cascades deleting the children as well; children first.
Diffstat (limited to 'window.c')
-rw-r--r--window.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/window.c b/window.c
index 1b7431219..14aef6bb7 100644
--- a/window.c
+++ b/window.c
@@ -287,6 +287,21 @@ void SetWindowDirty(const Window *w)
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
}
+/** Find the Window whose parent pointer points to this window
+ * @parent w Window to find child of
+ * @return return a Window pointer that is the child of w, or NULL otherwise */
+static Window *FindChildWindow(const Window *w)
+{
+ Window* const *wz;
+
+ FOR_ALL_WINDOWS(wz) {
+ Window *v = *wz;
+ if (v->parent == w) return v;
+ }
+
+ return NULL;
+}
+
/** Find the z-value of a window. A window must already be open
* or the behaviour is undefined but function should never fail */
Window **FindWindowZPosition(const Window *w)
@@ -301,9 +316,14 @@ Window **FindWindowZPosition(const Window *w)
void DeleteWindow(Window *w)
{
+ Window *v;
Window **wz;
if (w == NULL) return;
+ /* Delete any children a window might have in a head-recursive manner */
+ v = FindChildWindow(w);
+ if (v != NULL) DeleteWindow(v);
+
if (_thd.place_mode != VHM_NONE &&
_thd.window_class == w->window_class &&
_thd.window_number == w->window_number) {
@@ -317,6 +337,7 @@ void DeleteWindow(Window *w)
free(w->widget);
w->widget = NULL;
w->widget_count = 0;
+ w->parent = NULL;
/* Find the window in the z-array, and effectively remove it
* by moving all windows after it one to the left */