src/window.cpp
author rubidium
Sat, 10 May 2008 12:30:27 +0000
changeset 10485 331014dcd0d3
parent 10482 260c05e63bf4
child 10486 247d43dfa6f1
permissions -rw-r--r--
(svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10400
diff changeset
     3
/** @file window.cpp Windowing system, widgets and events */
6443
b8f06d8eb7be (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6158
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
     6
#include <stdarg.h>
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1867
diff changeset
     7
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1112
diff changeset
     8
#include "debug.h"
8750
fdd6054e7bae (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8720
diff changeset
     9
#include "player_func.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8673
diff changeset
    10
#include "gfx_func.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 116
diff changeset
    11
#include "console.h"
8720
4e60c30e2006 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8673
diff changeset
    12
#include "viewport_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    13
#include "variables.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    14
#include "genworld.h"
7433
8e410e7ec0d7 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 7374
diff changeset
    15
#include "blitter/factory.hpp"
8602
9e75e594a068 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8564
diff changeset
    16
#include "window_gui.h"
8619
c2434269c3eb (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8617
diff changeset
    17
#include "zoom_func.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8619
diff changeset
    18
#include "core/alloc_func.hpp"
8635
3bbb6f87fced (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8627
diff changeset
    19
#include "map_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    20
#include "vehicle_base.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8764
diff changeset
    21
#include "settings_type.h"
10225
8becb17444a7 (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 10217
diff changeset
    22
#include "cheat_func.h"
10435
0e2b98df9707 (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 10434
diff changeset
    23
#include "window_func.h"
10445
2dd7d9d0a957 (svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents: 10442
diff changeset
    24
#include "tilehighlight_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    26
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    27
10163
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
    28
static Point _drag_delta; ///< delta between mouse cursor and upper left corner of dragged window
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
    29
static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    30
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
    31
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
    32
 * List of windows opened at the screen.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
    33
 * Uppermost window is at  _z_windows[_last_z_window - 1],
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
    34
 * bottom window is at _z_windows[0]
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
    35
 */
10164
3ff9e65f3d49 (svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium
parents: 10163
diff changeset
    36
Window *_z_windows[MAX_NUMBER_OF_WINDOWS];
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
    37
Window **_last_z_window; ///< always points to the next free space in the z-array
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    38
8764
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    39
Point _cursorpos_drag_start;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    40
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    41
int _scrollbar_start_pos;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    42
int _scrollbar_size;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    43
byte _scroller_click_timeout;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    44
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    45
bool _scrolling_scrollbar;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    46
bool _scrolling_viewport;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    47
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    48
byte _special_mouse_mode;
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    49
65746a5248ec (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8760
diff changeset
    50
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    51
/**
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    52
 * Call the window event handler for handling event \a e
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    53
 * @param e Window event to handle
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    54
 */
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    55
void Window::HandleWindowEvent(WindowEvent *e)
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    56
{
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    57
	if (wndproc != NULL) wndproc(this, e);
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    58
}
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
    59
8489
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    60
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    61
{
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    62
	va_list wdg_list;
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    63
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    64
	va_start(wdg_list, widgets);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    65
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    66
	while (widgets != WIDGET_LIST_END) {
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    67
		SetWidgetDisabledState(widgets, disab_stat);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    68
		widgets = va_arg(wdg_list, int);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    69
	}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    70
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    71
	va_end(wdg_list);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    72
}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    73
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    74
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...)
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    75
{
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    76
	va_list wdg_list;
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    77
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    78
	va_start(wdg_list, widgets);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    79
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    80
	while (widgets != WIDGET_LIST_END) {
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    81
		SetWidgetHiddenState(widgets, hidden_stat);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    82
		widgets = va_arg(wdg_list, int);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    83
	}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    84
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    85
	va_end(wdg_list);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    86
}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    87
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    88
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    89
{
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    90
	va_list wdg_list;
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    91
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    92
	va_start(wdg_list, widgets);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    93
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    94
	while (widgets != WIDGET_LIST_END) {
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    95
		SetWidgetLoweredState(widgets, lowered_stat);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    96
		widgets = va_arg(wdg_list, int);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    97
	}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    98
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
    99
	va_end(wdg_list);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   100
}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   101
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   102
void Window::RaiseButtons()
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   103
{
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   104
	for (uint i = 0; i < this->widget_count; i++) {
8528
04b4ef9abd9b (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8527
diff changeset
   105
		if (this->IsWidgetLowered(i)) {
04b4ef9abd9b (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8527
diff changeset
   106
			this->RaiseWidget(i);
04b4ef9abd9b (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8527
diff changeset
   107
			this->InvalidateWidget(i);
8489
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   108
		}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   109
	}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   110
}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   111
8522
a1c44311e09e (svn r11586) -Fix: make another widget 'accessor' function const when it should be const.
glx
parents: 8519
diff changeset
   112
void Window::InvalidateWidget(byte widget_index) const
8489
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   113
{
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   114
	const Widget *wi = &this->widget[widget_index];
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   115
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   116
	/* Don't redraw the window if the widget is invisible or of no-type */
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   117
	if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   118
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   119
	SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1);
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   120
}
1e2a5fdb152f (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 8450
diff changeset
   121
8531
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   122
void Window::HandleButtonClick(byte widget)
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   123
{
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   124
	this->LowerWidget(widget);
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   125
	this->flags4 |= 5 << WF_TIMEOUT_SHL;
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   126
	this->InvalidateWidget(widget);
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   127
}
e87a51f162e2 (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8529
diff changeset
   128
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   129
static void StartWindowDrag(Window *w);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   130
static void StartWindowSizing(Window *w);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   131
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   132
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   133
 * Dispatch left mouse-button (possibly double) click in window.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   134
 * @param w Window to dispatch event in
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   135
 * @param x X coordinate of the click
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   136
 * @param y Y coordinate of the click
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   137
 * @param double_click Was it a double click?
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   138
 */
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
   139
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   140
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	WindowEvent e;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   142
	e.we.click.pt.x = x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   143
	e.we.click.pt.y = y;
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
   144
	e.event = double_click ? WE_DOUBLE_CLICK : WE_CLICK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	if (w->desc_flags & WDF_DEF_WIDGET) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   147
		e.we.click.widget = GetWidgetFromPos(w, x, y);
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
   148
		if (e.we.click.widget < 0) return; // exit if clicked outside of widgets
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   149
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5235
diff changeset
   150
		/* don't allow any interaction if the button has been disabled */
8493
3ab458f7cff4 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 8489
diff changeset
   151
		if (w->IsWidgetDisabled(e.we.click.widget)) return;
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 211
diff changeset
   152
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   153
		const Widget *wi = &w->widget[e.we.click.widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   155
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   156
			/* special widget handling for buttons*/
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   157
			switch (wi->type) {
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   158
				case WWT_PANEL   | WWB_PUSHBUTTON: /* WWT_PUSHBTN */
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   159
				case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   160
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
8532
3099f32f9bfd (svn r11596) -Codechange: Use the Window member HandleButtonClick and remove its now useless counterpart function
belugas
parents: 8531
diff changeset
   161
					w->HandleButtonClick(e.we.click.widget);
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   162
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
			}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   164
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   165
			ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		if (w->desc_flags & WDF_STD_BTN) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   169
			if (e.we.click.widget == 0) { /* 'X' */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   170
				delete w;
984
a50e131688d2 (svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents: 983
diff changeset
   171
				return;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   172
			}
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   173
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   174
			if (e.we.click.widget == 1) { /* 'Title bar' */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   175
				StartWindowDrag(w);
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   176
				return;
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   177
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   179
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   180
		if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   181
			StartWindowSizing(w);
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8522
diff changeset
   182
			w->InvalidateWidget(e.we.click.widget);
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   183
			return;
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   184
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   185
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   186
		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   187
			w->flags4 ^= WF_STICKY;
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8522
diff changeset
   188
			w->InvalidateWidget(e.we.click.widget);
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   189
			return;
682
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
   190
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	}
1038
cf60aaf4c4ba (svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents: 1033
diff changeset
   192
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
   193
	w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   196
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   197
 * Dispatch right mouse-button click in window.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   198
 * @param w Window to dispatch event in
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   199
 * @param x X coordinate of the click
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   200
 * @param y Y coordinate of the click
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   201
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   202
static void DispatchRightClickEvent(Window *w, int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   203
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	/* default tooltips handler? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	if (w->desc_flags & WDF_STD_TOOLTIPS) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   208
		e.we.click.widget = GetWidgetFromPos(w, x, y);
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   209
		if (e.we.click.widget < 0) return; // exit if clicked outside of widgets
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   211
		if (w->widget[e.we.click.widget].tooltips != 0) {
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   212
			GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
	e.event = WE_RCLICK;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   218
	e.we.click.pt.x = x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   219
	e.we.click.pt.y = y;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
   220
	w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   223
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   224
 * Dispatch the mousewheel-action to the window.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   225
 * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   226
 * @param w Window
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   227
 * @param widget the widget where the scrollwheel was used
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   228
 * @param wheel scroll up or down
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   229
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   230
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
{
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   232
	if (widget < 0) return;
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   233
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   234
	const Widget *wi1 = &w->widget[widget];
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   235
	const Widget *wi2 = &w->widget[widget + 1];
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   236
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   237
	/* The listbox can only scroll if scrolling was done on the scrollbar itself,
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   238
	 * or on the listbox (and the next item is (must be) the scrollbar)
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   239
	 * XXX - should be rewritten as a widget-dependent scroller but that's
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   240
	 * not happening until someone rewrites the whole widget-code */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   241
	Scrollbar *sb;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   242
	if ((sb = &w->vscroll,  wi1->type == WWT_SCROLLBAR)  || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR)  ||
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   243
			(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   244
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   245
		if (sb->count > sb->cap) {
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8414
diff changeset
   246
			int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   247
			if (pos != sb->pos) {
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   248
				sb->pos = pos;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
   249
				w->SetDirty();
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   250
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   255
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   256
 * Generate repaint events for the visible part of window *wz within the rectangle.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   257
 *
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   258
 * The function goes recursively upwards in the window stack, and splits the rectangle
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   259
 * into multiple pieces at the window edges, so obscured parts are not redrawn.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   260
 *
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   261
 * @param wz Pointer into window stack, pointing at the window that needs to be repainted
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   262
 * @param left Left edge of the rectangle that should be repainted
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   263
 * @param top Top edge of the rectangle that should be repainted
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   264
 * @param right Right edge of the rectangle that should be repainted
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   265
 * @param bottom Bottom edge of the rectangle that should be repainted
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   266
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   267
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
{
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
   269
	Window* const *vz = wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   271
	while (++vz != _last_z_window) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   272
		const Window *v = *vz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   273
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		if (right > v->left &&
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
   275
				bottom > v->top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
				left < v->left + v->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
				top < v->top + v->height) {
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   278
			/* v and rectangle intersect with eeach other */
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   279
			int x;
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   280
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   281
			if (left < (x = v->left)) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   282
				DrawOverlappedWindow(wz, left, top, x, bottom);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   283
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   287
			if (right > (x = v->left + v->width)) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   288
				DrawOverlappedWindow(wz, left, top, x, bottom);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   289
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   293
			if (top < (x = v->top)) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   294
				DrawOverlappedWindow(wz, left, top, right, x);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   295
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6977
diff changeset
   299
			if (bottom > (x = v->top + v->height)) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   300
				DrawOverlappedWindow(wz, left, top, right, x);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   301
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
   309
	/* Setup blitter, and dispatch a repaint event to window *wz */
10161
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   310
	DrawPixelInfo *dp = _cur_dpi;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   311
	dp->width = right - left;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   312
	dp->height = bottom - top;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   313
	dp->left = left - (*wz)->left;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   314
	dp->top = top - (*wz)->top;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   315
	dp->pitch = _screen.pitch;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   316
	dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   317
	dp->zoom = ZOOM_LVL_NORMAL;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   318
	CallWindowEventNP(*wz, WE_PAINT);
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   319
}
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   320
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   321
/**
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   322
 * From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   323
 * These windows should be re-painted.
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   324
 * @param left Left edge of the rectangle that should be repainted
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   325
 * @param top Top edge of the rectangle that should be repainted
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   326
 * @param right Right edge of the rectangle that should be repainted
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   327
 * @param bottom Bottom edge of the rectangle that should be repainted
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   328
 */
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   329
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   330
{
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   331
	Window* const *wz;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   332
	DrawPixelInfo bk;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   333
	_cur_dpi = &bk;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   334
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   335
	FOR_ALL_WINDOWS(wz) {
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   336
		const Window *w = *wz;
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   337
		if (right > w->left &&
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   338
				bottom > w->top &&
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   339
				left < w->left + w->width &&
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   340
				top < w->top + w->height) {
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
   341
			/* Window w intersects with the rectangle => needs repaint */
10161
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   342
			DrawOverlappedWindow(wz, left, top, right, bottom);
4331e1c4c987 (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 10083
diff changeset
   343
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   347
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   348
 * Dispatch an event to a possibly non-existing window.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   349
 * If the window pointer w is \c NULL, the event is not dispatched
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   350
 * @param w Window to dispatch the event to, may be \c NULL
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   351
 * @param event Event to dispatch
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   352
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
void CallWindowEventNP(Window *w, int event)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
   356
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
	e.event = event;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
   358
	w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   361
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   362
 * Mark entire window as dirty (in need of re-paint)
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   363
 * @param w Window to redraw
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   364
 * @ingroup dirty
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   365
 */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   366
void Window::SetDirty() const
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   367
{
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   368
	SetDirtyBlocks(this->left, this->top, this->left + this->width, this->top + this->height);
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   369
}
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   370
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   371
/**
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   372
 * Mark entire window as dirty (in need of re-paint)
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   373
 * @param w Window to redraw
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   374
 * @ingroup dirty
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   375
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   376
void SetWindowDirty(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
{
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   378
	if (w != NULL) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
5666
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   381
/** Find the Window whose parent pointer points to this window
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   382
 * @param w parent Window to find child of
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   383
 * @return a Window pointer that is the child of w, or NULL otherwise */
5666
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   384
static Window *FindChildWindow(const Window *w)
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   385
{
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   386
	Window* const *wz;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   387
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   388
	FOR_ALL_WINDOWS(wz) {
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   389
		Window *v = *wz;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   390
		if (v->parent == w) return v;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   391
	}
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   392
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   393
	return NULL;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   394
}
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   395
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   396
/** Find the z-value of a window. A window must already be open
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   397
 * or the behaviour is undefined but function should never fail
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   398
 * @param w window to query Z Position
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   399
 * @return Pointer into the window-list at the position of \a w
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   400
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   401
Window **FindWindowZPosition(const Window *w)
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   402
{
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   403
	Window **wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   404
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   405
	FOR_ALL_WINDOWS(wz) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   406
		if (*wz == w) return wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   407
	}
5680
b0bae92a1620 (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5667
diff changeset
   408
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   409
	DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls",
5680
b0bae92a1620 (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5667
diff changeset
   410
		w->window_class, w->window_number);
b0bae92a1620 (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5667
diff changeset
   411
	return NULL;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   412
}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   413
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   414
/**
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
   415
 * Remove window and all its child windows from the window stack.
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   416
 */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   417
Window::~Window()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   419
	if (_thd.place_mode != VHM_NONE &&
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   420
			_thd.window_class == this->window_class &&
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   421
			_thd.window_number == this->window_number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
10400
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   425
	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   426
	if (_mouseover_last_w == this) _mouseover_last_w = NULL;
10400
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   427
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   428
	/* Find the window in the z-array, and effectively remove it
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   429
	 * by moving all windows after it one to the left. This must be
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   430
	 * done before removing the child so we cannot cause recursion
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   431
	 * between the deletion of the parent and the child. */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   432
	Window **wz = FindWindowZPosition(this);
10400
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   433
	if (wz == NULL) return;
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   434
	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   435
	_last_z_window--;
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   436
fe5ae75ca8ac (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 10399
diff changeset
   437
	/* Delete any children a window might have in a head-recursive manner */
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   438
	delete FindChildWindow(this);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   440
	CallWindowEventNP(this, WE_DESTROY);
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   441
	if (this->viewport != NULL) DeleteWindowViewport(this);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   442
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   443
	this->SetDirty();
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   444
	free(this->widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   447
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   448
 * Find a window by its class and window number
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   449
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   450
 * @param number Number of the window within the window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   451
 * @return Pointer to the found window, or \c NULL if not available
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   452
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
Window *FindWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   455
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   457
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   458
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   459
		if (w->window_class == cls && w->window_number == number) return w;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   460
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   465
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   466
 * Delete a window by its class and window number (if it is open).
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   467
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   468
 * @param number Number of the window within the window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   469
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
{
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   472
	delete FindWindowById(cls, number);
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   473
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   475
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   476
 * Delete all windows of a given class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   477
 * @param cls Window class of windows to delete
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   478
 */
999
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   479
void DeleteWindowByClass(WindowClass cls)
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   480
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   481
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   482
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   483
restart_search:
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   484
	/* When we find the window to delete, we need to restart the search
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   485
	 * as deleting this window could cascade in deleting (many) others
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   486
	 * anywhere in the z-array */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   487
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   488
		Window *w = *wz;
999
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   489
		if (w->window_class == cls) {
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   490
			delete w;
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   491
			goto restart_search;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   492
		}
999
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   493
	}
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   494
}
8b2a34061963 (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   495
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   496
/** Delete all windows of a player. We identify windows of a player
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   497
 * by looking at the caption colour. If it is equal to the player ID
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   498
 * then we say the window belongs to the player and should be deleted
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   499
 * @param id PlayerID player identifier */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   500
void DeletePlayerWindows(PlayerID id)
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   501
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   502
	Window* const *wz;
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   503
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   504
restart_search:
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   505
	/* When we find the window to delete, we need to restart the search
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   506
	 * as deleting this window could cascade in deleting (many) others
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   507
	 * anywhere in the z-array */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   508
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   509
		Window *w = *wz;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   510
		if (w->caption_color == id) {
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   511
			delete w;
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   512
			goto restart_search;
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   513
		}
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   514
	}
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   515
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   516
	/* Also delete the player specific windows, that don't have a player-colour */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   517
	DeleteWindowById(WC_BUY_COMPANY, id);
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   518
}
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   519
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   520
/** Change the owner of all the windows one player can take over from another
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   521
 * player in the case of a company merger. Do not change ownership of windows
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   522
 * that need to be deleted once takeover is complete
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   523
 * @param old_player PlayerID of original owner of the window
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   524
 * @param new_player PlayerID of the new owner of the window */
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   525
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   526
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   527
	Window* const *wz;
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   528
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   529
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   530
		Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   531
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   532
		if (w->caption_color != old_player) continue;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   533
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   534
		switch (w->window_class) {
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   535
			case WC_PLAYER_COLOR:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   536
			case WC_FINANCES:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   537
			case WC_STATION_LIST:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   538
			case WC_TRAINS_LIST:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   539
			case WC_ROADVEH_LIST:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   540
			case WC_SHIPS_LIST:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   541
			case WC_AIRCRAFT_LIST:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   542
			case WC_BUY_COMPANY:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   543
			case WC_COMPANY:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   544
				continue;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   545
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   546
			default:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   547
				w->caption_color = new_player;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   548
				break;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   549
		}
5077
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   550
	}
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   551
}
587701a06b6a (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   552
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   553
static void BringWindowToFront(const Window *w);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   554
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   555
/** Find a window and make it the top-window on the screen. The window
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   556
 * gets a white border for a brief period of time to visualize its "activation"
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   557
 * @param cls WindowClass of the window to activate
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   558
 * @param number WindowNumber of the window to activate
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   559
 * @return a pointer to the window thus activated */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
	Window *w = FindWindowById(cls, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   564
	if (w != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
		w->flags4 |= WF_WHITE_BORDER_MASK;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   566
		BringWindowToFront(w);
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
   567
		w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   573
static inline bool IsVitalWindow(const Window *w)
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   574
{
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   575
	switch (w->window_class) {
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   576
		case WC_MAIN_TOOLBAR:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   577
		case WC_STATUS_BAR:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   578
		case WC_NEWS_WINDOW:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   579
		case WC_SEND_NETWORK_MSG:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   580
			return true;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   581
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   582
		default:
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   583
			return false;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   584
	}
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   585
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   586
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   587
/** On clicking on a window, make it the frontmost window of all. However
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   588
 * there are certain windows that always need to be on-top; these include
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   589
 * - Toolbar, Statusbar (always on)
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   590
 * - New window, Chatbar (only if open)
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   591
 * The window is marked dirty for a repaint if the window is actually moved
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   592
 * @param w window that is put into the foreground
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   593
 * @return pointer to the window, the same as the input pointer
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   594
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   595
static void BringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   597
	Window **wz = FindWindowZPosition(w);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   598
	Window **vz = _last_z_window;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   600
	/* Bring the window just below the vital windows */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	do {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   602
		if (--vz < _z_windows) return;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   603
	} while (IsVitalWindow(*vz));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   605
	if (wz == vz) return; // window is already in the right position
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   606
	assert(wz < vz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   608
	Window *tempz = *wz;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   609
	memmove(wz, wz + 1, (byte*)vz - (byte*)wz);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   610
	*vz = tempz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
   612
	w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   615
/** We have run out of windows, so find a suitable candidate for replacement.
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   616
 * Keep all important windows intact. These are
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   617
 * - Main window (gamefield), Toolbar, Statusbar (always on)
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   618
 * - News window, Chatbar (when on)
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   619
 * - Any sticked windows since we wanted to keep these
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   620
 * @return w pointer to the window that is going to be deleted
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   621
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   622
static Window *FindDeletableWindow()
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   623
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   624
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   625
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   626
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   627
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   628
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   629
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   630
		}
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   631
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   632
	return NULL;
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   633
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   634
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   635
/** A window must be freed, and all are marked as important windows. Ease the
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   636
 * restriction a bit by allowing to delete sticky windows. Keep important/vital
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   637
 * windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar)
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   638
 * Start finding an appropiate candidate from the lowest z-values (bottom)
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   639
 * @see FindDeletableWindow()
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   640
 * @return w Pointer to the window that is being deleted
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   641
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   642
static Window *ForceFindDeletableWindow()
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   643
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   644
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   645
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
   646
	FOR_ALL_WINDOWS(wz) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   647
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   648
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   649
	}
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
   650
	NOT_REACHED();
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   651
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   652
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   653
bool IsWindowOfPrototype(const Window *w, const Widget *widget)
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   654
{
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   655
	return (w->original_widget == widget);
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   656
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   657
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   658
/** Copies 'widget' to 'w->widget' to allow for resizable windows
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   659
 * @param w Window on which to attach the widget array
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   660
 * @param widget pointer of widget array to fill the window with */
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   661
void AssignWidgetToWindow(Window *w, const Widget *widget)
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   662
{
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   663
	w->original_widget = widget;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   664
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   665
	if (widget != NULL) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   666
		uint index = 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   667
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   668
		for (const Widget *wi = widget; wi->type != WWT_LAST; wi++) index++;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   669
5860
7fdc9b423ba1 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5838
diff changeset
   670
		w->widget = ReallocT(w->widget, index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   671
		memcpy(w->widget, widget, sizeof(*w->widget) * index);
5232
0ba6acdc527f (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   672
		w->widget_count = index - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   673
	} else {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   674
		w->widget = NULL;
5232
0ba6acdc527f (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   675
		w->widget_count = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   676
	}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   677
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   678
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   679
/**
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   680
 * Initializes a new Window.
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   681
 * This function is called the constructors.
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   682
 * See descriptions for those functions for usage
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   683
 * Only addition here is window_number, which is the window_number being assigned to the new window
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   684
 * @param x offset in pixels from the left of the screen
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   685
 * @param y offset in pixels from the top of the screen
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   686
 * @param min_width minimum width in pixels of the window
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   687
 * @param min_height minimum height in pixels of the window
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   688
 * @param def_width default width in pixels of the window
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   689
 * @param def_height default height in pixels of the window
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   690
 * @param *proc see WindowProc function to call when any messages/updates happen to the window
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   691
 * @param cls see WindowClass class of the window, used for identification and grouping
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   692
 * @param *widget see Widget pointer to the window layout and various elements
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   693
 * @param window_number number being assigned to the new window
7863
cc5dcf5c8ed4 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7860
diff changeset
   694
 * @param data the data to be given during the WE_CREATE message
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   695
 * @return Window pointer of the newly created window */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   696
void Window::Initialize(int x, int y, int min_width, int min_height, int def_width, int def_height,
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   697
				WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   699
	/* We have run out of windows, close one and use that as the place for our new one */
10164
3ff9e65f3d49 (svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium
parents: 10163
diff changeset
   700
	if (_last_z_window == endof(_z_windows)) {
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   701
		Window *w = FindDeletableWindow();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   702
		if (w == NULL) w = ForceFindDeletableWindow();
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
   703
		delete w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
   706
	/* Set up window properties */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   707
	this->window_class = cls;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   708
	this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   709
	this->caption_color = 0xFF;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   710
	this->left = x;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   711
	this->top = y;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   712
	this->width = min_width;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   713
	this->height = min_height;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   714
	this->wndproc = proc;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   715
	AssignWidgetToWindow(this, widget);
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   716
	this->resize.width = min_width;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   717
	this->resize.height = min_height;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   718
	this->resize.step_width = 1;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   719
	this->resize.step_height = 1;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   720
	this->window_number = window_number;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   721
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   722
	/* Hacky way of specifying always-on-top windows. These windows are
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   723
		* always above other windows because they are moved below them.
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   724
		* status-bar is above news-window because it has been created earlier.
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   725
		* Also, as the chat-window is excluded from this, it will always be
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   726
		* the last window, thus always on top.
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   727
		* XXX - Yes, ugly, probably needs something like w->always_on_top flag
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   728
		* to implement correctly, but even then you need some kind of distinction
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   729
		* between on-top of chat/news and status windows, because these conflict */
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   730
	Window **wz = _last_z_window;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   731
	if (wz != _z_windows && this->window_class != WC_SEND_NETWORK_MSG && this->window_class != WC_HIGHSCORE && this->window_class != WC_ENDSCREEN) {
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   732
		if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   733
		if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   734
		if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   735
		if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   736
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   737
		assert(wz >= _z_windows);
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   738
		if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   739
	}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   740
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   741
	*wz = this;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   742
	_last_z_window++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
7863
cc5dcf5c8ed4 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7860
diff changeset
   744
	WindowEvent e;
cc5dcf5c8ed4 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7860
diff changeset
   745
	e.event = WE_CREATE;
cc5dcf5c8ed4 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7860
diff changeset
   746
	e.we.create.data = data;
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   747
	this->HandleWindowEvent(&e);
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   748
7849
eafce07e8f96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7840
diff changeset
   749
	/* Try to make windows smaller when our window is too small.
eafce07e8f96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7840
diff changeset
   750
	 * w->(width|height) is normally the same as min_(width|height),
eafce07e8f96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7840
diff changeset
   751
	 * but this way the GUIs can be made a little more dynamic;
eafce07e8f96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7840
diff changeset
   752
	 * one can use the same spec for multiple windows and those
eafce07e8f96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7840
diff changeset
   753
	 * can then determine the real minimum size of the window. */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   754
	if (this->width != def_width || this->height != def_height) {
7840
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   755
		/* Think about the overlapping toolbars when determining the minimum window size */
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   756
		int free_height = _screen.height;
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   757
		const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   758
		if (wt != NULL) free_height -= wt->height;
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   759
		wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   760
		if (wt != NULL) free_height -= wt->height;
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   761
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   762
		int enlarge_x = max(min(def_width  - this->width,  _screen.width - this->width),  0);
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   763
		int enlarge_y = max(min(def_height - this->height, free_height   - this->height), 0);
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   764
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   765
		/* X and Y has to go by step.. calculate it.
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   766
		 * The cast to int is necessary else x/y are implicitly casted to
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   767
		 * unsigned int, which won't work. */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   768
		if (this->resize.step_width  > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   769
		if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   770
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   771
		ResizeWindow(this, enlarge_x, enlarge_y);
7838
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   772
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   773
		WindowEvent e;
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   774
		e.event = WE_RESIZE;
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   775
		e.we.sizing.size.x = this->width;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   776
		e.we.sizing.size.y = this->height;
7838
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   777
		e.we.sizing.diff.x = enlarge_x;
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   778
		e.we.sizing.diff.y = enlarge_y;
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   779
		this->HandleWindowEvent(&e);
7840
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   780
	}
7838
539b4d33ce87 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7837
diff changeset
   781
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   782
	int nx = this->left;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   783
	int ny = this->top;
7960
af0f10d86051 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7950
diff changeset
   784
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   785
	if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
7860
b2a4bed111b6 (svn r10727) -Codechange: when a window would fall outside of the screen (on the right) when opening it, move it to the left so it stays inside the screen.
rubidium
parents: 7859
diff changeset
   786
7840
0878bbe3d39a (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7838
diff changeset
   787
	const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   788
	ny = max(ny, (wt == NULL || this == wt || y == 0) ? 0 : wt->height);
7960
af0f10d86051 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7950
diff changeset
   789
	nx = max(nx, 0);
af0f10d86051 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7950
diff changeset
   790
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   791
	if (this->viewport != NULL) {
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   792
		this->viewport->left += nx - this->left;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   793
		this->viewport->top  += ny - this->top;
7960
af0f10d86051 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7950
diff changeset
   794
	}
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   795
	this->left = nx;
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   796
	this->top = ny;
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   797
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   798
	this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   801
/**
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   802
 * Open a new window. If there is no space for a new window, close an open
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   803
 * window. Try to avoid stickied windows, but if there is no else, close one of
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   804
 * those as well. Then make sure all created windows are below some always-on-top
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   805
 * ones. Finally set all variables and call the WE_CREATE event
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   806
 * @param x offset in pixels from the left of the screen
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   807
 * @param y offset in pixels from the top of the screen
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   808
 * @param width width in pixels of the window
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   809
 * @param height height in pixels of the window
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   810
 * @param *proc see WindowProc function to call when any messages/updates happen to the window
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   811
 * @param cls see WindowClass class of the window, used for identification and grouping
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
   812
 * @param *widget see Widget pointer to the window layout and various elements
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   813
 * @return Window pointer of the newly created window
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
   814
 */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   815
Window::Window(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   816
{
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
   817
	this->Initialize(x, y, width, height, width, height, proc, cls, widget, 0, data);
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   818
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   821
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   823
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   825
	int right  = width + left;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   826
	int bottom = height + top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
   828
	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
   830
	/* Make sure it is not obscured by any window. */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   831
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   832
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   833
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   835
		if (right > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   836
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
				bottom > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   838
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   839
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   840
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   841
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   843
	pos.x = left;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   844
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   848
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   850
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   852
	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   853
	if (top < 22 || top > _screen.height - (height>>2)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
   855
	/* Make sure it is not obscured by any window. */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   856
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   857
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   858
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   860
		if (left + width > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   861
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
				top + height > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   863
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   864
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   865
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   866
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   868
	pos.x = left;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   869
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   873
static Point GetAutoPlacePosition(int width, int height)
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   874
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   875
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   878
	if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   880
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   881
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   882
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   884
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   885
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   886
		if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   887
		if (IsGoodAutoPlace1(w->left, w->top - height - 2,    width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   888
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   889
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top + w->height - height, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   890
		if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   891
		if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2,    width, height, pt)) return pt;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   892
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   893
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   894
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   895
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   896
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   898
		if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   899
		if (IsGoodAutoPlace2(w->left - width - 2,    w->top, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   900
		if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt;
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   901
		if (IsGoodAutoPlace2(w->left, w->top - height - 2,    width, height, pt)) return pt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	{
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   905
		int left = 0, top = 24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   906
7028
bca7019b2210 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6988
diff changeset
   907
restart:
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   908
		FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   909
			const Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   910
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
			if (w->left == left && w->top == top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   917
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   924
/**
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   925
 * Compute the position of the top-left corner of a new window that is opened.
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   926
 *
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   927
 * By default position a child window at an offset of 10/10 of its parent.
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   928
 * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports)
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   929
 * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   930
 * its parent. So it's exactly under the parent toolbar and no buttons will be covered.
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   931
 * However if it falls too extremely outside window positions, reposition
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   932
 * it to an automatic place.
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   933
 *
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   934
 * @param *desc         The pointer to the WindowDesc to be created
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   935
 * @param window_number the window number of the new window
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   936
 *
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   937
 * @return Coordinate of the top-left corner of the new window
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   938
 */
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   939
static Point LocalGetWindowPlacement(const WindowDesc *desc, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   944
	if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   945
			(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   946
			w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   947
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   948
		pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   949
		if (pt.x > _screen.width + 10 - desc->default_width) {
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   950
			pt.x = (_screen.width + 10 - desc->default_width) - 20;
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   951
		}
8217
ce7255c36b9e (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7960
diff changeset
   952
		pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	} else {
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   954
		switch (desc->left) {
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   955
			case WDP_ALIGN_TBR: // Align the right side with the top toolbar
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   956
				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   957
				pt.x = (w->left + w->width) - desc->default_width;
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   958
				break;
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   959
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   960
			case WDP_ALIGN_TBL: // Align the left side with the top toolbar
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   961
				pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   962
				break;
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   963
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   964
			case WDP_AUTO: // Find a good automatic position for the window
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   965
				return GetAutoPlacePosition(desc->default_width, desc->default_height);
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   966
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   967
			case WDP_CENTER: // Centre the window horizontally
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   968
				pt.x = (_screen.width - desc->default_width) / 2;
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   969
				break;
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   970
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   971
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   972
				pt.x = desc->left;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   973
				if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   974
		}
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   975
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   976
		switch (desc->top) {
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   977
			case WDP_CENTER: // Centre the window vertically
7837
65d7362153a6 (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7797
diff changeset
   978
				pt.y = (_screen.height - desc->default_height) / 2;
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   979
				break;
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   980
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   981
			/* WDP_AUTO sets the position at once and is controlled by desc->left.
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   982
			 * Both left and top must be set to WDP_AUTO */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   983
			case WDP_AUTO:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   984
				NOT_REACHED();
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   985
				assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO);
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   986
				/* fallthrough */
10396
6bf03c5e4d3f (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 10395
diff changeset
   987
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   988
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   989
				pt.y = desc->top;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   990
				if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   991
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   995
	return pt;
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   996
}
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   997
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   998
/**
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
   999
 * Set the positions of a new window from a WindowDesc and open it.
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1000
 *
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1001
 * @param *desc         The pointer to the WindowDesc to be created
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1002
 * @param window_number the window number of the new window
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1003
 * @param data          arbitrary data that is send with the WE_CREATE message
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1004
 *
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1005
 * @return Window pointer of the newly created window
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1006
 */
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
  1007
Window::Window(const WindowDesc *desc, void *data, WindowNumber window_number)
10395
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1008
{
9c8a408b649c (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 10258
diff changeset
  1009
	Point pt = LocalGetWindowPlacement(desc, window_number);
10461
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
  1010
	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);
48556aee54da (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 10457
diff changeset
  1011
	this->desc_flags = desc->flags;
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1012
}
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1013
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1014
/** Do a search for a window at specific coordinates. For this we start
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1015
 * at the topmost window, obviously and work our way down to the bottom
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
  1016
 * @param x position x to query
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
  1017
 * @param y position y to query
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1018
 * @return a pointer to the found window if any, NULL otherwise */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
Window *FindWindowFromPt(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
{
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1021
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1022
		Window *w = *--wz;
8450
dce58137301f (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 8424
diff changeset
  1023
		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1024
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1025
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
10162
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1031
/**
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1032
 * (re)initialize the windowing system
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1033
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1034
void InitWindowSystem()
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
  1035
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
  1036
	IConsoleClose();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1037
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1038
	_last_z_window = _z_windows;
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1039
	_mouseover_last_w = NULL;
1397
b04402b901cd (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1299
diff changeset
  1040
	_no_scroll = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
10162
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1043
/**
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1044
 * Close down the windowing system
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1045
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1046
void UnInitWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1047
{
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1048
	while (_last_z_window != _z_windows) delete _z_windows[0];
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1049
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1050
10162
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1051
/**
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1052
 * Reset the windowing system, by means of shutting it down followed by re-initialization
d0d33ae1c7bc (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 10161
diff changeset
  1053
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1054
void ResetWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1055
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1056
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1057
	InitWindowSystem();
1744
1677a99b0daf (svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents: 1737
diff changeset
  1058
	_thd.pos.x = 0;
1677a99b0daf (svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents: 1737
diff changeset
  1059
	_thd.pos.y = 0;
2877
c307d8f60e48 (svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents: 2817
diff changeset
  1060
	_thd.new_pos.x = 0;
c307d8f60e48 (svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents: 2817
diff changeset
  1061
	_thd.new_pos.y = 0;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1062
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1063
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1064
static void DecreaseWindowCounters()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1066
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1068
	for (wz = _last_z_window; wz != _z_windows;) {
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1069
		Window *w = *--wz;
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1070
		/* Unclick scrollbar buttons if they are pressed. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1073
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
		CallWindowEventNP(w, WE_MOUSELOOP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1078
	for (wz = _last_z_window; wz != _z_windows;) {
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1079
		Window *w = *--wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1080
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1081
		if (w->flags4 & WF_TIMEOUT_MASK && !(--w->flags4 & WF_TIMEOUT_MASK)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
			CallWindowEventNP(w, WE_TIMEOUT);
8528
04b4ef9abd9b (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8527
diff changeset
  1083
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1088
Window *GetCallbackWnd()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	return FindWindowById(_thd.window_class, _thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1093
static void HandlePlacePresize()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1095
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1097
	Window *w = GetCallbackWnd();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1098
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1100
	WindowEvent e;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1101
	e.we.place.pt = GetTileBelowCursor();
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1102
	if (e.we.place.pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
	}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1106
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	e.event = WE_PLACE_PRESIZE;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1108
	w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1111
static bool HandleDragDrop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1113
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1114
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1115
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1116
	Window *w = GetCallbackWnd();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1118
	if (w != NULL) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1119
		/* send an event in client coordinates. */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1120
		WindowEvent e;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1121
		e.event = WE_DRAGDROP;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1122
		e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1123
		e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1124
		e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1125
		w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	}
9081
4c47047836f3 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8766
diff changeset
  1127
4c47047836f3 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8766
diff changeset
  1128
	ResetObjectToPlace();
4c47047836f3 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8766
diff changeset
  1129
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1133
static bool HandleMouseOver()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1134
{
10163
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1135
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1136
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1137
	/* We changed window, put a MOUSEOVER event to the last window */
10163
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1138
	if (_mouseover_last_w != NULL && _mouseover_last_w != w) {
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1139
		/* Reset mouse-over coordinates of previous window */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1140
		WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1141
		e.event = WE_MOUSEOVER;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1142
		e.we.mouseover.pt.x = -1;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1143
		e.we.mouseover.pt.y = -1;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1144
		_mouseover_last_w->HandleWindowEvent(&e);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1145
	}
10163
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1146
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1147
	/* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
d18ad4693602 (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 10162
diff changeset
  1148
	_mouseover_last_w = w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1149
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1150
	if (w != NULL) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1151
		/* send an event in client coordinates. */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1152
		WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1153
		e.event = WE_MOUSEOVER;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1154
		e.we.mouseover.pt.x = _cursor.pos.x - w->left;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1155
		e.we.mouseover.pt.y = _cursor.pos.y - w->top;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1156
		if (w->widget != NULL) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1157
			e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1158
		}
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1159
		w->HandleWindowEvent(&e);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1160
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1161
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1162
	/* Mouseover never stops execution */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1163
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1164
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1165
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1166
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1167
 * Resize the window.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1168
 * Update all the widgets of a window based on their resize flags
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1169
 * Both the areas of the old window and the new sized window are set dirty
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1170
 * ensuring proper redrawal.
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1171
 * @param w Window to resize
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6939
diff changeset
  1172
 * @param x delta x-size of changed window (positive if larger, etc.)
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1173
 * @param y delta y-size of changed window
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1174
 */
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1175
void ResizeWindow(Window *w, int x, int y)
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1176
{
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1177
	bool resize_height = false;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1178
	bool resize_width = false;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1179
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1180
	if (x == 0 && y == 0) return;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1181
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1182
	w->SetDirty();
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1183
	for (Widget *wi = w->widget; wi->type != WWT_LAST; wi++) {
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1184
		/* Isolate the resizing flags */
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1185
		byte rsizeflag = GB(wi->display_flags, 0, 4);
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1186
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1187
		if (rsizeflag == RESIZE_NONE) continue;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1188
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1189
		/* Resize the widget based on its resize-flag */
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1190
		if (rsizeflag & RESIZE_LEFT) {
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1191
			wi->left += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1192
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1193
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1194
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1195
		if (rsizeflag & RESIZE_RIGHT) {
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1196
			wi->right += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1197
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1198
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1199
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1200
		if (rsizeflag & RESIZE_TOP) {
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1201
			wi->top += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1202
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1203
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1204
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1205
		if (rsizeflag & RESIZE_BOTTOM) {
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1206
			wi->bottom += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1207
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1208
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1209
	}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1210
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1211
	/* We resized at least 1 widget, so let's resize the window totally */
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1212
	if (resize_width)  w->width  += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1213
	if (resize_height) w->height += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1214
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1215
	w->SetDirty();
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1216
}
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1217
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1218
static bool _dragging_window;
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1219
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1220
static bool HandleWindowDragging()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1222
	Window* const *wz;
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1223
	/* Get out immediately if no window is being dragged at all. */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1224
	if (!_dragging_window) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1226
	/* Otherwise find the window... */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1227
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1228
		Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1229
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1230
		if (w->flags4 & WF_DRAGGING) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1231
			const Widget *t = &w->widget[1]; // the title bar ... ugh
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1232
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1233
			/* Stop the dragging if the left mouse button was released */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
			if (!_left_button_down) {
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1235
				w->flags4 &= ~WF_DRAGGING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1239
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1241
			int x = _cursor.pos.x + _drag_delta.x;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1242
			int y = _cursor.pos.y + _drag_delta.y;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1243
			int nx = x;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1244
			int ny = y;
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1245
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1246
			if (_patches.window_snap_radius != 0) {
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1247
				Window* const *vz;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1248
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1249
				int hsnap = _patches.window_snap_radius;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1250
				int vsnap = _patches.window_snap_radius;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1251
				int delta;
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1252
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1253
				FOR_ALL_WINDOWS(vz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1254
					const Window *v = *vz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1255
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1256
					if (v == w) continue; // Don't snap at yourself
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1257
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1258
					if (y + w->height > v->top && y < v->top + v->height) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1259
						/* Your left border <-> other right border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1260
						delta = abs(v->left + v->width - x);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1261
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1262
							nx = v->left + v->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1263
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1264
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1265
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1266
						/* Your right border <-> other left border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1267
						delta = abs(v->left - x - w->width);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1268
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1269
							nx = v->left - w->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1270
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1271
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1272
					}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1273
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1274
					if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1275
						/* Your left border <-> other left border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1276
						delta = abs(v->left - x);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1277
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1278
							nx = v->left;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1279
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1280
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1281
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1282
						/* Your right border <-> other right border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1283
						delta = abs(v->left + v->width - x - w->width);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1284
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1285
							nx = v->left + v->width - w->width;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1286
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1287
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1288
					}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1289
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1290
					if (x + w->width > v->left && x < v->left + v->width) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1291
						/* Your top border <-> other bottom border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1292
						delta = abs(v->top + v->height - y);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1293
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1294
							ny = v->top + v->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1295
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1296
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1297
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1298
						/* Your bottom border <-> other top border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1299
						delta = abs(v->top - y - w->height);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1300
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1301
							ny = v->top - w->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1302
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1303
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1304
					}
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1305
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1306
					if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1307
						/* Your top border <-> other top border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1308
						delta = abs(v->top - y);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1309
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1310
							ny = v->top;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1311
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1312
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1313
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1314
						/* Your bottom border <-> other bottom border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1315
						delta = abs(v->top + v->height - y - w->height);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1316
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1317
							ny = v->top + v->height - w->height;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1318
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1319
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1320
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
			}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1323
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1324
			/* Make sure the window doesn't leave the screen
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1325
			 * 13 is the height of the title bar */
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8414
diff changeset
  1326
			nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8414
diff changeset
  1327
			ny = Clamp(ny, 0, _screen.height - 13);
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1328
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1329
			/* Make sure the title bar isn't hidden by behind the main tool bar */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1330
			Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1331
			if (v != NULL) {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1332
				int v_bottom = v->top + v->height;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1333
				int v_right = v->left + v->width;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1334
				if (ny + t->top >= v->top && ny + t->top < v_bottom) {
371
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1335
					if ((v->left < 13 && nx + t->left < v->left) ||
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1336
							(v_right > _screen.width - 13 && nx + t->right > v_right)) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1337
						ny = v_bottom;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1338
					} else {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1339
						if (nx + t->left > v->left - 13 &&
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1340
								nx + t->right < v_right + 13) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1341
							if (w->top >= v_bottom) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1342
								ny = v_bottom;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1343
							} else if (w->left < nx) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1344
								nx = v->left - 13 - t->left;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1345
							} else {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1346
								nx = v_right + 13 - t->right;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1347
							}
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1348
						}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1349
					}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1350
				}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1351
			}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1352
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1353
			if (w->viewport != NULL) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1354
				w->viewport->left += nx - w->left;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1355
				w->viewport->top  += ny - w->top;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1356
			}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1357
			w->left = nx;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1358
			w->top  = ny;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1359
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1360
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
			return false;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1362
		} else if (w->flags4 & WF_SIZING) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1363
			WindowEvent e;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1364
			int x, y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1365
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1366
			/* Stop the sizing if the left mouse button was released */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1367
			if (!_left_button_down) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1368
				w->flags4 &= ~WF_SIZING;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1369
				w->SetDirty();
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1370
				break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1371
			}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1372
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1373
			x = _cursor.pos.x - _drag_delta.x;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1374
			y = _cursor.pos.y - _drag_delta.y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1375
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1376
			/* X and Y has to go by step.. calculate it.
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1377
			 * The cast to int is necessary else x/y are implicitly casted to
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1378
			 * unsigned int, which won't work. */
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1379
			if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1380
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1381
			if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1382
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1383
			/* Check if we don't go below the minimum set size */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1384
			if ((int)w->width + x < (int)w->resize.width)
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1385
				x = w->resize.width - w->width;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1386
			if ((int)w->height + y < (int)w->resize.height)
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1387
				y = w->resize.height - w->height;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1388
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1389
			/* Window already on size */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1390
			if (x == 0 && y == 0) return false;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1391
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1392
			/* Now find the new cursor pos.. this is NOT _cursor, because
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1393
			    we move in steps. */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1394
			_drag_delta.x += x;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1395
			_drag_delta.y += y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1396
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1397
			/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1398
			ResizeWindow(w, x, y);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1399
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1400
			e.event = WE_RESIZE;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1401
			e.we.sizing.size.x = x + w->width;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1402
			e.we.sizing.size.y = y + w->height;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1403
			e.we.sizing.diff.x = x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1404
			e.we.sizing.diff.y = y;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1405
			w->HandleWindowEvent(&e);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1406
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
	_dragging_window = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1414
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1415
 * Start window dragging
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1416
 * @param w Window to start dragging
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1417
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1418
static void StartWindowDrag(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
	w->flags4 |= WF_DRAGGING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1422
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1423
	_drag_delta.x = w->left - _cursor.pos.x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1424
	_drag_delta.y = w->top  - _cursor.pos.y;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1425
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1426
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1430
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1431
 * Start resizing a window
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1432
 * @param w Window to start resizing
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1433
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1434
static void StartWindowSizing(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
	w->flags4 |= WF_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1438
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1439
	_drag_delta.x = _cursor.pos.x;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1440
	_drag_delta.y = _cursor.pos.y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1441
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1442
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1447
static bool HandleScrollbarScrolling()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1449
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1451
	/* Get out quickly if no item is being scrolled */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1452
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1454
	/* Find the scrolling window */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1455
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1456
		Window *w = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1457
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
		if (w->flags4 & WF_SCROLL_MIDDLE) {
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1459
			/* Abort if no button is clicked any more. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
				w->flags4 &= ~WF_SCROLL_MIDDLE;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1462
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1464
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1466
			int i;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1467
			Scrollbar *sb;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1468
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1472
			} else if (w->flags4 & WF_SCROLL2){
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1473
				sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1474
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1480
			/* Find the item we want to move to and make sure it's inside bounds. */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1481
			int pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
				sb->pos = pos;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1484
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1487
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1489
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1492
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1494
static bool HandleViewportScroll()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
{
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1496
	WindowEvent e;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1498
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1499
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1500
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1502
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
4335
18bc63352a17 (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1503
8351
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1504
	if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) {
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1505
		_cursor.fix_at = false;
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1506
		_scrolling_viewport = false;
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1507
		return true;
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1508
	}
5e100e34b417 (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 8255
diff changeset
  1509
8255
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1510
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) {
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1511
		/* If the main window is following a vehicle, then first let go of it! */
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1512
		const Vehicle *veh = GetVehicle(WP(w, vp_d).follow_vehicle);
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1513
		ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1514
		return true;
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1515
	}
ba58769915ac (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 8217
diff changeset
  1516
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1517
	if (_patches.reverse_scroll) {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1518
		e.we.scroll.delta.x = -_cursor.delta.x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1519
		e.we.scroll.delta.y = -_cursor.delta.y;
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1520
	} else {
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1521
		e.we.scroll.delta.x = _cursor.delta.x;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1522
		e.we.scroll.delta.y = _cursor.delta.y;
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1523
	}
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1524
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1525
	if (scrollwheel_scrolling) {
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1526
		/* We are using scrollwheels for scrolling */
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1527
		e.we.scroll.delta.x = _cursor.h_wheel;
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1528
		e.we.scroll.delta.y = _cursor.v_wheel;
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1529
		_cursor.v_wheel = 0;
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1530
		_cursor.h_wheel = 0;
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1531
	}
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1532
4335
18bc63352a17 (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1533
	/* Create a scroll-event and send it to the window */
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1534
	e.event = WE_SCROLL;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1535
	w->HandleWindowEvent(&e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1537
	_cursor.delta.x = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1538
	_cursor.delta.y = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1539
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1542
/** Check if a window can be made top-most window, and if so do
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1543
 * it. If a window does not obscure any other windows, it will not
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1544
 * be brought to the foreground. Also if the only obscuring windows
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1545
 * are so-called system-windows, the window will not be moved.
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1546
 * The function will return false when a child window of this window is a
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1547
 * modal-popup; function returns a false and child window gets a white border
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1548
 * @param w Window to bring on-top
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1549
 * @return false if the window has an active modal child, true otherwise */
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1550
static bool MaybeBringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
{
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1552
	bool bring_to_front = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1554
	if (w->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1555
			IsVitalWindow(w) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1556
			w->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1557
			w->window_class == WC_DROPDOWN_MENU) {
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1558
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1559
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1561
	Window * const *wz = FindWindowZPosition(w);
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1562
	for (Window * const *uz = wz; ++uz != _last_z_window;) {
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1563
		Window *u = *uz;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1564
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1565
		/* A modal child will prevent the activation of the parent window */
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1566
		if (u->parent == w && (u->desc_flags & WDF_MODAL)) {
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1567
			u->flags4 |= WF_WHITE_BORDER_MASK;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1568
			u->SetDirty();
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1569
			return false;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1570
		}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1571
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1572
		if (u->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1573
				IsVitalWindow(u) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1574
				u->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1575
				u->window_class == WC_DROPDOWN_MENU) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1576
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1577
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1579
		/* Window sizes don't interfere, leave z-order alone */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
		if (w->left + w->width <= u->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
				u->left + u->width <= w->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
				w->top  + w->height <= u->top ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1583
				u->top + u->height <= w->top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1584
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1585
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1586
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1587
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
	}
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1589
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1590
	if (bring_to_front) BringWindowToFront(w);
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1591
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1594
/** Handle keyboard input.
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1595
 * @param key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1596
 */
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1597
void HandleKeypress(uint32 key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1598
{
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1599
	WindowEvent e;
8515
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1600
	/* Stores if a window with a textfield for typing is open
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1601
	 * If this is the case, keypress events are only passed to windows with text fields and
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1602
	 * to thein this main toolbar. */
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1603
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1604
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1605
	/*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1606
	* During the generation of the world, there might be
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1607
	* another thread that is currently building for example
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1608
	* a road. To not interfere with those tasks, we should
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1609
	* NOT change the _current_player here.
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1610
	*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1611
	* This is not necessary either, as the only events that
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1612
	* can be handled are the 'close application' events
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1613
	*/
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1614
	if (!IsGeneratingWorld()) _current_player = _local_player;
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1615
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1616
	/* Setup event */
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1617
	e.event = WE_KEYPRESS;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5090
diff changeset
  1618
	e.we.keypress.key     = GB(key,  0, 16);
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1619
	e.we.keypress.keycode = GB(key, 16, 16);
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1620
	e.we.keypress.cont = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
8673
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1622
	/*
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1623
	 * The Unicode standard defines an area called the private use area. Code points in this
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1624
	 * area are reserved for private use and thus not portable between systems. For instance,
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1625
	 * Apple defines code points for the arrow keys in this area, but these are only printable
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1626
	 * on a system running OS X. We don't want these keys to show up in text fields and such,
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1627
	 * and thus we have to clear the unicode character when we encounter such a key.
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1628
	 */
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1629
	if (e.we.keypress.key >= 0xE000 && e.we.keypress.key <= 0xF8FF) e.we.keypress.key = 0;
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1630
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1631
	/*
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1632
	 * If both key and keycode is zero, we don't bother to process the event.
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1633
	 */
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1634
	if (e.we.keypress.key == 0 && e.we.keypress.keycode == 0) return;
85d63e5a028e (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8640
diff changeset
  1635
8515
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1636
	/* check if we have a query string window open before allowing hotkeys */
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1637
	if (FindWindowById(WC_QUERY_STRING,            0) != NULL ||
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1638
			FindWindowById(WC_SEND_NETWORK_MSG,        0) != NULL ||
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1639
			FindWindowById(WC_GENERATE_LANDSCAPE,      0) != NULL ||
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1640
			FindWindowById(WC_CONSOLE,                 0) != NULL ||
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1641
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1642
			FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) {
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1643
		query_open = true;
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1644
	}
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1645
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1646
	/* Call the event, start with the uppermost window. */
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1647
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1648
		Window *w = *--wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1649
8515
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1650
		/* if a query window is open, only call the event for certain window types */
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1651
		if (query_open &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1652
				w->window_class != WC_QUERY_STRING &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1653
				w->window_class != WC_SEND_NETWORK_MSG &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1654
				w->window_class != WC_GENERATE_LANDSCAPE &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1655
				w->window_class != WC_CONSOLE &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1656
				w->window_class != WC_SAVELOAD &&
d0401d967e99 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8514
diff changeset
  1657
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
651
32b229802ed2 (svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents: 649
diff changeset
  1658
			continue;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1659
		}
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1660
		w->HandleWindowEvent(&e);
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1661
		if (!e.we.keypress.cont) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
	}
1637
5a51ba5fb8b7 (svn r2141) - Fix: Keys now hopefully only activate the right windows. If console/querybox/chatbox is open, all input goes there, if closed to game itself.
Darkvater
parents: 1570
diff changeset
  1663
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1664
	if (e.we.keypress.cont) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1665
		Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1666
		/* When there is no toolbar w is null, check for that */
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1667
		if (w != NULL) w->HandleWindowEvent(&e);
1642
593a9b750b91 (svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents: 1637
diff changeset
  1668
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1671
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1672
 * State of CONTROL key has changed
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1673
 */
9082
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1674
void HandleCtrlChanged()
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1675
{
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1676
	WindowEvent e;
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1677
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1678
	e.event = WE_CTRL_CHANGED;
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1679
	e.we.ctrl.cont = true;
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1680
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1681
	/* Call the event, start with the uppermost window. */
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1682
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1683
		Window *w = *--wz;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1684
		w->HandleWindowEvent(&e);
9082
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1685
		if (!e.we.ctrl.cont) break;
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1686
	}
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1687
}
8217cb013e23 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 9081
diff changeset
  1688
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1689
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1690
 * Local counter that is incremented each time an mouse input event is detected.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1691
 * The counter is used to stop auto-scrolling.
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1692
 * @see HandleAutoscroll()
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1693
 * @see HandleMouseEvents()
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1694
 */
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1695
static int _input_events_this_tick = 0;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1696
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1697
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1698
 * If needed and switched on, perform auto scrolling (automatically
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1699
 * moving window contents when mouse is near edge of the window).
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1700
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1701
static void HandleAutoscroll()
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1702
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1703
	if (_input_events_this_tick != 0) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1704
		/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1705
		_input_events_this_tick = 0;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1706
		/* there were some inputs this tick, don't scroll ??? */
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1707
		return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1708
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1709
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1710
	if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1711
		int x = _cursor.pos.x;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1712
		int y = _cursor.pos.y;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1713
		Window *w = FindWindowFromPt(x, y);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1714
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1715
		ViewPort *vp = IsPtInWindowViewport(w, x, y);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1716
		if (vp != NULL) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1717
			x -= vp->left;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1718
			y -= vp->top;
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1719
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1720
			/* here allows scrolling in both x and y axis */
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1721
#define scrollspeed 3
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1722
			if (x - 15 < 0) {
7797
3f3c109e2109 (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7686
diff changeset
  1723
				WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1724
			} else if (15 - (vp->width - x) > 0) {
7797
3f3c109e2109 (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7686
diff changeset
  1725
				WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1726
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1727
			if (y - 15 < 0) {
7797
3f3c109e2109 (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7686
diff changeset
  1728
				WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1729
			} else if (15 - (vp->height - y) > 0) {
7797
3f3c109e2109 (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7686
diff changeset
  1730
				WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1731
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1732
#undef scrollspeed
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1733
		}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1734
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1735
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1736
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1737
enum MouseClick {
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1738
	MC_NONE = 0,
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1739
	MC_LEFT,
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1740
	MC_RIGHT,
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1741
	MC_DOUBLE_LEFT,
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1742
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7505
diff changeset
  1743
	MAX_OFFSET_DOUBLE_CLICK = 5,     ///< How much the mouse is allowed to move to call it a double click
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7505
diff changeset
  1744
	TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1745
};
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1746
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1747
extern void UpdateTileSelection();
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1748
extern bool VpHandlePlaceSizingDrag();
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  1749
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1750
void MouseLoop(MouseClick click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
	UpdateTileSelection();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1755
	if (!VpHandlePlaceSizingDrag())  return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1756
	if (!HandleDragDrop())           return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1757
	if (!HandleWindowDragging())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1758
	if (!HandleScrollbarScrolling()) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1759
	if (!HandleViewportScroll())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1760
	if (!HandleMouseOver())          return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1761
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1762
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1763
	if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1765
	int x = _cursor.pos.x;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1766
	int y = _cursor.pos.y;
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1767
	Window *w = FindWindowFromPt(x, y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1768
	if (w == NULL) return;
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1769
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1770
	if (!MaybeBringWindowToFront(w)) return;
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1771
	ViewPort *vp = IsPtInWindowViewport(w, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1773
	/* Don't allow any action in a viewport if either in menu of in generating world */
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1774
	if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1775
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1776
	if (mousewheel != 0) {
6622
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1777
		if (_patches.scrollwheel_scrolling == 0) {
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1778
			/* Scrollwheel is in zoom mode. Make the zoom event. */
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1779
			WindowEvent e;
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1780
6622
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1781
			/* Send WE_MOUSEWHEEL event to window */
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1782
			e.event = WE_MOUSEWHEEL;
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1783
			e.we.wheel.wheel = mousewheel;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  1784
			w->HandleWindowEvent(&e);
6622
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1785
		}
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1786
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1787
		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1788
		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1789
	}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1790
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1791
	if (vp != NULL) {
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1792
		if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1793
		switch (click) {
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1794
			case MC_DOUBLE_LEFT:
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1795
			case MC_LEFT:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1796
				DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
8414
8c2ecc2dc12c (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents: 8351
diff changeset
  1797
				if (_thd.place_mode != VHM_NONE &&
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1798
						/* query button and place sign button work in pause mode */
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1799
						_cursor.sprite != SPR_CURSOR_QUERY &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1800
						_cursor.sprite != SPR_CURSOR_SIGN &&
6557
8381016f71f3 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6443
diff changeset
  1801
						_pause_game != 0 &&
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1802
						!_cheats.build_in_pause.value) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1803
					return;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1804
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1805
8414
8c2ecc2dc12c (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents: 8351
diff changeset
  1806
				if (_thd.place_mode == VHM_NONE) {
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1807
					HandleViewportClicked(vp, x, y);
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1808
				} else {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1809
					PlaceObject();
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1810
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1811
				break;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1812
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1813
			case MC_RIGHT:
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1814
				if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1815
					_scrolling_viewport = true;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1816
					_cursor.fix_at = true;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1817
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1818
				break;
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1819
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1820
			default:
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1821
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	} else {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1824
		switch (click) {
10457
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1825
			case MC_DOUBLE_LEFT:
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1826
				DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1827
				if (_mouseover_last_w == NULL) break; // The window got removed.
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1828
				/* fallthough, and also give a single-click for backwards compatibility */
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1829
			case MC_LEFT:
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1830
				DispatchLeftClickEvent(w, x - w->left, y - w->top, false);
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1831
				break;
ea18877d8eba (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 10445
diff changeset
  1832
6616
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1833
			default:
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1834
				if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break;
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1835
				/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1836
				* Simulate a right button click so we can get started. */
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1837
				/* fallthough */
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1838
			case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1839
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1842
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1843
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1844
 * Handle a mouse event from the video driver
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1845
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1846
void HandleMouseEvents()
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1847
{
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1848
	static int double_click_time = 0;
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1849
	static int double_click_x = 0;
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1850
	static int double_click_y = 0;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1851
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1852
	/*
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1853
	 * During the generation of the world, there might be
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1854
	 * another thread that is currently building for example
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1855
	 * a road. To not interfere with those tasks, we should
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1856
	 * NOT change the _current_player here.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1857
	 *
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1858
	 * This is not necessary either, as the only events that
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1859
	 * can be handled are the 'close application' events
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1860
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1861
	if (!IsGeneratingWorld()) _current_player = _local_player;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1862
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1863
	/* Mouse event? */
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1864
	MouseClick click = MC_NONE;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1865
	if (_left_button_down && !_left_button_clicked) {
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1866
		click = MC_LEFT;
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7505
diff changeset
  1867
		if (double_click_time != 0 && _realtime_tick - double_click_time   < TIME_BETWEEN_DOUBLE_CLICK &&
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1868
			  double_click_x != 0    && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK  &&
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1869
			  double_click_y != 0    && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) {
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1870
			click = MC_DOUBLE_LEFT;
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1871
		}
7514
98a024616010 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7505
diff changeset
  1872
		double_click_time = _realtime_tick;
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1873
		double_click_x = _cursor.pos.x;
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1874
		double_click_y = _cursor.pos.y;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1875
		_left_button_clicked = true;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1876
		_input_events_this_tick++;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1877
	} else if (_right_button_clicked) {
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1878
		_right_button_clicked = false;
7505
94a7391e0377 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 7433
diff changeset
  1879
		click = MC_RIGHT;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1880
		_input_events_this_tick++;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1881
	}
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1882
10442
2dfe39b56bbb (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 10435
diff changeset
  1883
	int mousewheel = 0;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1884
	if (_cursor.wheel) {
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1885
		mousewheel = _cursor.wheel;
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1886
		_cursor.wheel = 0;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1887
		_input_events_this_tick++;
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1888
	}
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1889
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1890
	MouseLoop(click, mousewheel);
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1891
}
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1892
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1893
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1894
 * Regular call from the global game loop
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1895
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1896
void InputLoop()
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1897
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1898
	HandleMouseEvents();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1899
	HandleAutoscroll();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1900
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1901
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1902
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1903
 * Update the continuously changing contents of the windows, such as the viewports
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1904
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1905
void UpdateWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1906
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1907
	Window* const *wz;
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1908
	static int we4_timer = 0;
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1909
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1911
	if (t >= 100) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1912
		for (wz = _last_z_window; wz != _z_windows;) {
10481
0c7aed4edabe (svn r13024) -Codechange: do not use WE_MOUSELOOP when WE_TICK suffices, rename WE_4 to something more descriptive and correct some (completely incorrect) comments.
rubidium
parents: 10463
diff changeset
  1913
			CallWindowEventNP(*--wz, WE_100_TICKS);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
	}
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1917
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1919
	for (wz = _last_z_window; wz != _z_windows;) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1920
		Window *w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
			w->flags4 -= WF_WHITE_BORDER_ONE;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1923
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1924
			if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1930
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1931
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	}
7950
3d3ed007127a (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7863
diff changeset
  1933
	DrawChatMessage();
6928
44797333bcbf (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6622
diff changeset
  1934
	/* Redraw mouse cursor in case it was hidden */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1936
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1938
/**
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  1939
 * Mark window as dirty (in need of repainting)
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  1940
 * @param cls Window class
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  1941
 * @param number Window number in that class
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1942
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1943
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
{
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1945
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1947
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1948
		const Window *w = *wz;
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1949
		if (w->window_class == cls && w->window_number == number) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  1953
/**
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1954
 * Mark a particular widget in a particular window as dirty (in need of repainting)
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1955
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1956
 * @param number Window number in that class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1957
 * @param widget_index Index number of the widget that needs repainting
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1958
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1959
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
{
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1961
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1963
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1964
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1965
		if (w->window_class == cls && w->window_number == number) {
8524
baf4ab1ba18d (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8522
diff changeset
  1966
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1967
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  1971
/**
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1972
 * Mark all windows of a particular class as dirty (in need of repainting)
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1973
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1974
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1975
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
{
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1977
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1978
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1979
	FOR_ALL_WINDOWS(wz) {
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1980
		if ((*wz)->window_class == cls) (*wz)->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1984
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1985
 * Mark window data as invalid (in need of re-computing)
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1986
 * @param w Window with invalid data
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1987
 */
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1988
void InvalidateThisWindowData(Window *w, int data)
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1989
{
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1990
	WindowEvent e;
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1991
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1992
	e.event = WE_INVALIDATE_DATA;
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1993
	e.we.invalidate.data = data;
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1994
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  1995
	w->HandleWindowEvent(&e);
10434
d6accd017341 (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 10433
diff changeset
  1996
	w->SetDirty();
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1997
}
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1998
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  1999
/**
10255
5600b575e6e7 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 10225
diff changeset
  2000
 * Mark window data of the window of a given class and specific window number as invalid (in need of re-computing)
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2001
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2002
 * @param number Window number within the class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2003
 */
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  2004
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data)
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2005
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2006
	Window* const *wz;
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2007
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2008
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2009
		Window *w = *wz;
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  2010
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w, data);
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2011
	}
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2012
}
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2013
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2014
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2015
 * Mark window data of all windows of a given class as invalid (in need of re-computing)
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2016
 * @param cls Window class
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2017
 */
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  2018
void InvalidateWindowClassesData(WindowClass cls, int data)
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2019
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2020
	Window* const *wz;
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2021
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2022
	FOR_ALL_WINDOWS(wz) {
10485
331014dcd0d3 (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 10482
diff changeset
  2023
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz, data);
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2024
	}
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2025
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2026
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2027
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2028
 * Dispatch WE_TICK event over all windows
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2029
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2030
void CallWindowTickEvent()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
{
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2032
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2033
		CallWindowEventNP(*--wz, WE_TICK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
10258
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2037
/**
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2038
 * Try to delete a non-vital window.
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2039
 * Non-vital windows are windows other than the game selection, main toolbar,
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2040
 * status bar, toolbar menu, and tooltip windows. Stickied windows are also
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2041
 * considered vital.
2aa4a5f35186 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 10255
diff changeset
  2042
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2043
void DeleteNonVitalWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2044
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2045
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2046
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2047
restart_search:
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2048
	/* When we find the window to delete, we need to restart the search
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2049
	 * as deleting this window could cascade in deleting (many) others
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2050
	 * anywhere in the z-array */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2051
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2052
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2056
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2057
				w->window_class != WC_TOOLBAR_MENU &&
682
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
  2058
				w->window_class != WC_TOOLTIPS &&
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
  2059
				(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2060
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
  2061
			delete w;
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2062
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
  2067
/** It is possible that a stickied window gets to a position where the
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2068
 * 'close' button is outside the gaming area. You cannot close it then; except
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2069
 * with this function. It closes all windows calling the standard function,
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2070
 * then, does a little hacked loop of closing all stickied windows. Note
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2071
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2072
void DeleteAllNonVitalWindows()
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2073
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2074
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2075
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2076
	/* Delete every window except for stickied ones, then sticky ones as well */
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2077
	DeleteNonVitalWindows();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2078
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2079
restart_search:
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2080
	/* When we find the window to delete, we need to restart the search
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2081
	 * as deleting this window could cascade in deleting (many) others
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2082
	 * anywhere in the z-array */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2083
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2084
		if ((*wz)->flags4 & WF_STICKY) {
10433
cca9f7948fe5 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 10429
diff changeset
  2085
			delete *wz;
5121
9fedd27b3ec3 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2086
			goto restart_search;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2087
		}
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2088
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2089
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2090
6939
50b3cf596ce2 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6928
diff changeset
  2091
/** Delete all always on-top windows to get an empty screen */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2092
void HideVitalWindows()
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2093
{
6158
ca1471170695 (svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
rubidium
parents: 5893
diff changeset
  2094
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2095
	DeleteWindowById(WC_MAIN_TOOLBAR, 0);
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2096
	DeleteWindowById(WC_STATUS_BAR, 0);
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2097
}
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2098
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2099
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2100
 * (Re)position main toolbar window at the screen
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2101
 * @param w Window structure of the main toolbar window, may also be \c NULL
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2102
 * @return X coordinate of left edge of the repositioned toolbar window
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2103
 */
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2104
int PositionMainToolbar(Window *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2105
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2106
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2107
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2108
	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2109
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2110
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2111
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2112
	switch (_patches.toolbar_pos) {
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  2113
		case 1:  w->left = (_screen.width - w->width) / 2; break;
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2114
		case 2:  w->left = _screen.width - w->width; break;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2115
		default: w->left = 0;
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2116
	}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2117
	SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2118
	return w->left;
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2119
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2120
10083
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2121
/**
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2122
 * Relocate all windows to fit the new size of the game application screen
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2123
 * @param neww New width of the game application screen
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2124
 * @param newh New height of the game appliction screen
9fb63cf5cc90 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 9194
diff changeset
  2125
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2128
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2129
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2130
	FOR_ALL_WINDOWS(wz) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2131
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2133
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2134
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
			ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
			vp->width = w->width = neww;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
			vp->height = w->height = newh;
7122
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
  2138
			vp->virtual_width = ScaleByZoom(neww, vp->zoom);
0607a15aedc0 (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 7120
diff changeset
  2139
			vp->virtual_height = ScaleByZoom(newh, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
			continue; // don't modify top,left
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
  2141
		}
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
  2142
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2143
		/* XXX - this probably needs something more sane. For example specying
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2144
		 * in a 'backup'-desc that the window should always be centred. */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2145
		switch (w->window_class) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2146
			case WC_MAIN_TOOLBAR:
7858
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2147
				if (neww - w->width != 0) {
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2148
					ResizeWindow(w, min(neww, 640) - w->width, 0);
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2149
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2150
					WindowEvent e;
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2151
					e.event = WE_RESIZE;
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2152
					e.we.sizing.size.x = w->width;
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2153
					e.we.sizing.size.y = w->height;
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2154
					e.we.sizing.diff.x = neww - w->width;
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2155
					e.we.sizing.diff.y = 0;
10399
79a272c88359 (svn r12941) -Codechange: don't access wndproc directly. Patch by Alberth.
rubidium
parents: 10396
diff changeset
  2156
					w->HandleWindowEvent(&e);
7858
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2157
				}
eece91cb3472 (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7850
diff changeset
  2158
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2159
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2160
				left = PositionMainToolbar(w); // changes toolbar orientation
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2161
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2162
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2163
			case WC_SELECT_GAME:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2164
			case WC_GAME_OPTIONS:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2165
			case WC_NETWORK_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2166
				top = (newh - w->height) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2167
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2168
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2169
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2170
			case WC_NEWS_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2171
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2172
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2173
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2174
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2175
			case WC_STATUS_BAR:
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8414
diff changeset
  2176
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2177
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2178
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2179
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2180
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2181
			case WC_SEND_NETWORK_MSG:
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8414
diff changeset
  2182
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2183
				top = (newh - 26); // 26 = height of status bar + height of chat bar
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2184
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2185
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2186
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2187
			case WC_CONSOLE:
5143
a78072872bff (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2188
				IConsoleResize(w);
5137
a1f26c30fecd (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  2189
				continue;
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2190
9194
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2191
			default: {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2192
				left = w->left;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2193
				if (left + (w->width >> 1) >= neww) left = neww - w->width;
8519
7a9d047a184e (svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents: 8515
diff changeset
  2194
				if (left < 0) left = 0;
7a9d047a184e (svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents: 8515
diff changeset
  2195
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2196
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2197
				if (top + (w->height >> 1) >= newh) top = newh - w->height;
9194
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2198
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2199
				const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2200
				if (wt != NULL) {
10183
bb64c0c1947c (svn r12714) -Fix [FS#1904]: do not move windows below the toolbar on resizes unless they would go behind the toolbar.
rubidium
parents: 10164
diff changeset
  2201
					if (top < wt->height && wt->left < (w->left + w->width) && (wt->left + wt->width) > w->left) top = wt->height;
9194
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2202
					if (top >= newh) top = newh - 1;
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2203
				} else {
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2204
					if (top < 0) top = 0;
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2205
				}
685d482d1e6c (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 9082
diff changeset
  2206
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2209
		if (w->viewport != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
			w->viewport->left += left - w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
			w->viewport->top += top - w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2212
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2214
		w->left = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2215
		w->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
}