Mercurial > hg > openttd
changeset 9178:708347596d9a draft
(svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sun, 11 May 2008 11:41:18 +0000 |
parents | 94a08f9e1061 |
children | 3b7b689031d6 |
files | src/autoreplace_gui.cpp src/industry_gui.cpp src/misc_gui.cpp src/network/network_gui.cpp src/window.cpp src/window_gui.h |
diffstat | 6 files changed, 34 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -301,6 +301,8 @@ this->caption_color = _local_player; this->sel_group = id_g; this->vscroll2.cap = this->vscroll.cap; // these two are always the same + + this->FindWindowPlacementAndResize(desc); } virtual void OnPaint()
--- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -163,6 +163,8 @@ this->selected_index = 0; this->selected_type = this->index[0]; this->callback_timer = DAY_TICKS; + + this->FindWindowPlacementAndResize(&_build_industry_desc); } virtual void OnPaint()
--- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -184,6 +184,8 @@ DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _m[tile].m6); DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7); #undef LANDINFOD_LEVEL + + this->FindWindowPlacementAndResize(&_land_info_desc); } }; @@ -1125,6 +1127,8 @@ this->widget[QUERY_WIDGET_CAPTION].data = caption; this->message = message; this->proc = callback; + + this->FindWindowPlacementAndResize(desc); } ~QueryWindow()
--- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1038,6 +1038,8 @@ { strcpy(_edit_str_net_buf, ""); this->vscroll.cap = 10; + + this->FindWindowPlacementAndResize(desc); } virtual void OnPaint()
--- a/src/window.cpp +++ b/src/window.cpp @@ -887,15 +887,13 @@ * @param y offset in pixels from the top of the screen * @param min_width minimum width in pixels of the window * @param min_height minimum height in pixels of the window - * @param def_width default width in pixels of the window - * @param def_height default height in pixels of the window * @param *proc see WindowProc function to call when any messages/updates happen to the window * @param cls see WindowClass class of the window, used for identification and grouping * @param *widget see Widget pointer to the window layout and various elements * @param window_number number being assigned to the new window * @param data the data to be given during the WE_CREATE message * @return Window pointer of the newly created window */ -void Window::Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height, +void Window::Initialize(int x, int y, int min_width, int min_height, WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data) { /* We have run out of windows, close one and use that as the place for our new one */ @@ -947,7 +945,15 @@ e.event = WE_CREATE; e.we.create.data = data; this->HandleWindowEvent(&e); +} +/** + * Find a nice spot for this window and resize it towards the default size. + * @param def_width default width in pixels of the window + * @param def_height default height in pixels of the window + */ +void Window::FindWindowPlacementAndResize(int def_width, int def_height) +{ /* Try to make windows smaller when our window is too small. * w->(width|height) is normally the same as min_(width|height), * but this way the GUIs can be made a little more dynamic; @@ -987,7 +993,7 @@ if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width); const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); - ny = max(ny, (wt == NULL || this == wt || y == 0) ? 0 : wt->height); + ny = max(ny, (wt == NULL || this == wt || this->top == 0) ? 0 : wt->height); nx = max(nx, 0); if (this->viewport != NULL) { @@ -1000,6 +1006,11 @@ this->SetDirty(); } +void Window::FindWindowPlacementAndResize(const WindowDesc *desc) +{ + this->FindWindowPlacementAndResize(desc->default_width, desc->default_height); +} + /** * Open a new window. If there is no space for a new window, close an open * window. Try to avoid stickied windows, but if there is no else, close one of @@ -1016,7 +1027,9 @@ */ Window::Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data) { - this->Initialize(x, y, width, height, width, height, proc, cls, widget, 0, data); + this->Initialize(x, y, width, height, proc, cls, widget, 0, data); + + if (proc != NULL) this->FindWindowPlacementAndResize(width, height); } @@ -1209,8 +1222,10 @@ Window::Window(const WindowDesc *desc, void *data, WindowNumber window_number) { Point pt = LocalGetWindowPlacement(desc, window_number); - this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data); + this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->proc, desc->cls, desc->widgets, window_number, data); this->desc_flags = desc->flags; + + if (desc->proc != NULL) this->FindWindowPlacementAndResize(desc->default_width, desc->default_height); } /** Do a search for a window at specific coordinates. For this we start
--- a/src/window_gui.h +++ b/src/window_gui.h @@ -279,8 +279,10 @@ void HandleWindowEvent(WindowEvent *e); protected: - void Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height, + void Initialize(int x, int y, int min_width, int min_height, WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data); + void FindWindowPlacementAndResize(int def_width, int def_height); + void FindWindowPlacementAndResize(const WindowDesc *desc); public: Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data = NULL);