window.c
author KUDr
Mon, 01 Jan 2007 18:26:10 +0000
branchcustombridgeheads
changeset 5624 7901de192beb
parent 5623 ef2a8a524a95
permissions -rw-r--r--
(svn r7724) [cbh] - Codechange: cbh tile edge detection changed (using one if instead of switch) when entering the bridge wormhole
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#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
     4
#include <stdarg.h>
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1867
diff changeset
     5
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1112
diff changeset
     6
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     7
#include "functions.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 651
diff changeset
     8
#include "map.h"
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2026
diff changeset
     9
#include "player.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "gfx.h"
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
    12
#include "viewport.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 116
diff changeset
    13
#include "console.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    14
#include "variables.h"
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2436
diff changeset
    15
#include "table/sprites.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    16
#include "genworld.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    18
// delta between mouse cursor and upper left corner of dragged window
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    19
static Point _drag_delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    20
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    21
static Window _windows[25];
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    22
Window *_z_windows[lengthof(_windows)];
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
    23
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
    24
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    25
void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...)
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    26
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    27
	va_list wdg_list;
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    28
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    29
	va_start(wdg_list, widgets);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    30
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    31
	while (widgets != WIDGET_LIST_END) {
4757
a25d9f2067f7 (svn r6671) -Fix r6670: typo :P
glx
parents: 4756
diff changeset
    32
		SetWindowWidgetDisabledState(w, widgets, disab_stat);
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    33
		widgets = va_arg(wdg_list, int);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    34
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    35
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    36
	va_end(wdg_list);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    37
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    38
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    39
void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...)
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    40
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    41
	va_list wdg_list;
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    42
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    43
	va_start(wdg_list, widgets);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    44
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    45
	while (widgets != WIDGET_LIST_END) {
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    46
		SetWindowWidgetHiddenState(w, widgets, hidden_stat);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    47
		widgets = va_arg(wdg_list, int);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    48
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    49
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    50
	va_end(wdg_list);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    51
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    52
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    53
void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...)
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    54
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    55
	va_list wdg_list;
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    56
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    57
	va_start(wdg_list, widgets);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    58
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    59
	while (widgets != WIDGET_LIST_END) {
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    60
		SetWindowWidgetLoweredState(w, widgets, lowered_stat);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    61
		widgets = va_arg(wdg_list, int);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    62
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    63
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    64
	va_end(wdg_list);
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    65
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    66
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    67
void RaiseWindowButtons(Window *w)
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    68
{
5235
3c309f43f0a6 (svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents: 5232
diff changeset
    69
	uint i;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    70
5235
3c309f43f0a6 (svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents: 5232
diff changeset
    71
	for (i = 0; i < w->widget_count; i++) {
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    72
		if (IsWindowWidgetLowered(w, i)) {
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    73
			RaiseWindowWidget(w, i);
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    74
			InvalidateWidget(w, i);
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    75
		}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    76
	}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    77
}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    78
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
void HandleButtonClick(Window *w, byte widget)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
{
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    81
	LowerWindowWidget(w, widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	w->flags4 |= 5 << WF_TIMEOUT_SHL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
	InvalidateWidget(w, widget);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
    86
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    87
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
    88
static void StartWindowSizing(Window *w);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
    89
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
    90
static void DispatchLeftClickEvent(Window *w, int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
    91
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
	const Widget *wi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
    95
	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
    96
	e.we.click.pt.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	e.event = WE_CLICK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	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
   100
		e.we.click.widget = GetWidgetFromPos(w, x, y);
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   101
		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
   102
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
   103
		/* don't allow any interaction if the button has been disabled */
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
   104
		if (IsWindowWidgetDisabled(w, 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
   105
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
   106
		wi = &w->widget[e.we.click.widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   108
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   109
			/* special widget handling for buttons*/
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   110
			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
   111
				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
   112
				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
   113
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   114
					HandleButtonClick(w, e.we.click.widget);
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   115
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
			}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   117
		} 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
   118
			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
   119
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		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
   122
			if (e.we.click.widget == 0) { /* 'X' */
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   123
				DeleteWindow(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
   124
				return;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   125
			}
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   126
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   127
			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
   128
				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
   129
				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
   130
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   132
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
   133
		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
   134
			StartWindowSizing(w);
5272
e27514065ed8 (svn r7414) -Fix: Immediately invalidate the resize widget when clicked, instead of when started to drag
Darkvater
parents: 5268
diff changeset
   135
			InvalidateWidget(w, 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
   136
			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
   137
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   138
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   139
		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
   140
			w->flags4 ^= WF_STICKY;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   141
			InvalidateWidget(w, 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
   142
			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
   143
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	}
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
   145
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
   146
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   149
static void DispatchRightClickEvent(Window *w, int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   150
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	/* default tooltips handler? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	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
   155
		e.we.click.widget = GetWidgetFromPos(w, x, y);
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   156
		if (e.we.click.widget < 0)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
			return; /* exit if clicked outside of widgets */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   159
		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
   160
			GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	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
   166
	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
   167
	e.we.click.pt.y = y;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   168
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
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
   171
/** Dispatch the mousewheel-action to the window which will scroll any
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
   172
 * compatible scrollbars if the mouse is pointed over the bar or its contents
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
   173
 * @param *w Window
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
   174
 * @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
   175
 * @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
   176
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   177
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
   178
{
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
   179
	const Widget *wi1, *wi2;
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
   180
	Scrollbar *sb;
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
   181
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
   182
	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
   183
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
   184
	wi1 = &w->widget[widget];
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
   185
	wi2 = &w->widget[widget + 1];
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
   186
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
   187
	/* 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
   188
	 * 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
   189
	 * 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
   190
	 * not happening until someone rewrites the whole widget-code */
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   191
	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
   192
			(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
   193
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
   194
		if (sb->count > sb->cap) {
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
   195
			int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap);
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
   196
			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
   197
				sb->pos = 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
   198
				SetWindowDirty(w);
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
   199
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   204
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   205
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   208
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	DrawPixelInfo bk;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	_cur_dpi = &bk;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   212
	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
   213
		const Window *w = *wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   214
		if (right > w->left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
				bottom > w->top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
				left < w->left + w->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
				top < w->top + w->height) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   218
			DrawOverlappedWindow(wz, left, top, right, bottom);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   219
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	}
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
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   223
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
   224
{
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
   225
	Window* const *vz = wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	int x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   228
	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
   229
		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
   230
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
		if (right > v->left &&
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
   232
				bottom > v->top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
				left < v->left + v->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
				top < v->top + v->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
			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
   236
				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
   237
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
			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
   242
				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
   243
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
			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
   248
				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
   249
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
				return;
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
			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
   254
				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
   255
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	{
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   264
		DrawPixelInfo *dp = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
		dp->width = right - left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
		dp->height = bottom - top;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   267
		dp->left = left - (*wz)->left;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   268
		dp->top = top - (*wz)->top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
		dp->pitch = _screen.pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
		dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		dp->zoom = 0;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   272
		CallWindowEventNP(*wz, WE_PAINT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
void CallWindowEventNP(Window *w, int event)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
   279
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	e.event = event;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   284
void SetWindowDirty(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
{
2549
f1d3b383d557 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   286
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   290
/** Find the Window whose parent pointer points to this window
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   291
 * @parent w Window to find child of
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   292
 * @return return a Window pointer that is the child of w, or NULL otherwise */
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   293
static Window *FindChildWindow(const Window *w)
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   294
{
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   295
	Window* const *wz;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   296
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   297
	FOR_ALL_WINDOWS(wz) {
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   298
		Window *v = *wz;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   299
		if (v->parent == w) return v;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   300
	}
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   301
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   302
	return NULL;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   303
}
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   304
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   305
/** Find the z-value of a window. A window must already be open
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   306
 * or the behaviour is undefined but function should never fail */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   307
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
   308
{
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   309
	Window **wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   310
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   311
	for (wz = _z_windows; wz != _last_z_window; wz++) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   312
		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
   313
	}
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   314
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   315
	DEBUG(misc, 3, "Window (class %d, number %d) is not open, probably removed by recursive calls",
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   316
		w->window_class, w->window_number);
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   317
	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
   318
}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   319
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   320
void DeleteWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
{
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   322
	Window *v;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   323
	Window **wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   324
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   326
	/* Delete any children a window might have in a head-recursive manner */
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   327
	v = FindChildWindow(w);
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   328
	if (v != NULL) DeleteWindow(v);
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   329
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   330
	if (_thd.place_mode != VHM_NONE &&
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   331
			_thd.window_class == w->window_class &&
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   332
			_thd.window_number == w->window_number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	CallWindowEventNP(w, WE_DESTROY);
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5121
diff changeset
   337
	if (w->viewport != NULL) DeleteWindowViewport(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
	SetWindowDirty(w);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   340
	free(w->widget);
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   341
	w->widget = NULL;
5232
0ba6acdc527f (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   342
	w->widget_count = 0;
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   343
	w->parent = NULL;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   344
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   345
	/* Find the window in the z-array, and effectively remove it
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   346
	 * by moving all windows after it one to the left */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   347
	wz = FindWindowZPosition(w);
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   348
	if (wz == NULL) return;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   349
	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   350
	_last_z_window--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
Window *FindWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   355
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   357
	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
   358
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   359
		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
   360
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	DeleteWindow(FindWindowById(cls, number));
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   368
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
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
   370
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
   371
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   372
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   373
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
   374
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
   375
	/* 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
   376
	 * 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
   377
	 * 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
   378
	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
   379
		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
   380
		if (w->window_class == 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
   381
			DeleteWindow(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
   382
			goto restart_search;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   383
		}
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
   384
	}
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
   385
}
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
   386
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   387
/** 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
   388
 * 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
   389
 * 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
   390
 * @param id PlayerID player identifier */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   391
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
   392
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   393
	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
   394
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
   395
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
   396
	/* 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
   397
	 * 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
   398
	 * 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
   399
	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
   400
		Window *w = *wz;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   401
		if (w->caption_color == 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
   402
			DeleteWindow(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
   403
			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
   404
		}
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
   405
	}
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
   406
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   407
	/* 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
   408
	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
   409
}
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
   410
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   411
/** 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
   412
 * 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
   413
 * 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
   414
 * @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
   415
 * @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
   416
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
   417
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   418
	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
   419
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   420
	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
   421
		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
   422
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
   423
		if (w->caption_color != old_player)      continue;
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
   424
		if (w->window_class == WC_PLAYER_COLOR)  continue;
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
   425
		if (w->window_class == WC_FINANCES)      continue;
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
   426
		if (w->window_class == WC_STATION_LIST)  continue;
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
   427
		if (w->window_class == WC_TRAINS_LIST)   continue;
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
   428
		if (w->window_class == WC_ROADVEH_LIST)  continue;
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
   429
		if (w->window_class == WC_SHIPS_LIST)    continue;
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
   430
		if (w->window_class == WC_AIRCRAFT_LIST) continue;
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
   431
		if (w->window_class == WC_BUY_COMPANY)   continue;
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
   432
		if (w->window_class == WC_COMPANY)       continue;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   433
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
   434
		w->caption_color = 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
   435
	}
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
   436
}
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
   437
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   438
static void BringWindowToFront(const Window *w);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   439
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   440
/** Find a window and make it the top-window on the screen. The window
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   441
 * gets a white border for a brief period of time to visualize its
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   442
 * "activation"
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   443
 * @return a pointer to the window thus activated */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
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
	Window *w = FindWindowById(cls, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	if (w != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
		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
   450
		BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   457
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
   458
{
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   459
	WindowClass wc = w->window_class;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   460
	return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG);
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   461
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   462
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   463
/** 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
   464
 * 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
   465
 * - 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
   466
 * - 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
   467
 * 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
   468
 * @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
   469
 * @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
   470
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   471
static void BringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   473
	Window *tempz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   474
	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
   475
	Window **vz = _last_z_window;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   477
	/* Bring the window just below the vital windows */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	do {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   479
		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
   480
	} while (IsVitalWindow(*vz));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   482
	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
   483
	assert(wz < vz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   485
	tempz = *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   486
	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
   487
	*vz = tempz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   489
	SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   492
/** 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
   493
 * 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
   494
 * - 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
   495
 * - 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
   496
 * - 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
   497
 * @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
   498
 */
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
   499
static Window *FindDeletableWindow(void)
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   500
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   501
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   502
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   503
	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
   504
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   505
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   506
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   507
		}
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
   508
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   509
	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
   510
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   511
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   512
/** 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
   513
 * 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
   514
 * 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
   515
 * 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
   516
 * @see FindDeletableWindow()
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   517
 * @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
   518
 */
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
   519
static Window *ForceFindDeletableWindow(void)
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   520
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   521
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   522
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   523
	for (wz = _z_windows;; wz++) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   524
		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
   525
		assert(wz < _last_z_window);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   526
		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
   527
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   528
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   529
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   530
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
   531
{
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   532
	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
   533
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   534
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   535
/* Copies 'widget' to 'w->widget' to allow for resizable windows */
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   536
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
   537
{
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   538
	w->original_widget = widget;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   539
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   540
	if (widget != NULL) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   541
		uint index = 1;
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   542
		const Widget *wi;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   543
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   544
		for (wi = widget; wi->type != WWT_LAST; wi++) index++;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   545
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   546
		w->widget = realloc(w->widget, sizeof(*w->widget) * index);
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   547
		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
   548
		w->widget_count = index - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   549
	} else {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   550
		w->widget = NULL;
5232
0ba6acdc527f (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   551
		w->widget_count = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   552
	}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   553
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
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
static Window *FindFreeWindow(void)
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   556
{
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   557
	Window *w;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   558
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   559
	for (w = _windows; w < endof(_windows); w++) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   560
		Window* const *wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   561
		bool window_in_use = false;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   562
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   563
		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
   564
			if (*wz == w) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   565
				window_in_use = true;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   566
				break;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   567
			}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   568
		}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   569
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   570
		if (!window_in_use) return w;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   571
	}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   572
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   573
	assert(_last_z_window == endof(_z_windows));
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   574
	return NULL;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   575
}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   576
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   577
/* Open a new window.
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   578
 * This function is called from AllocateWindow() or AllocateWindowDesc()
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   579
 * 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
   580
 * See AllocateWindow() for description of arguments.
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   581
 * Only addition here is window_number, which is the window_number being assigned to the new window
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   582
 */
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   583
static Window *LocalAllocateWindow(
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   584
							int x, int y, int width, int height,
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   585
							WindowProc *proc, WindowClass cls, const Widget *widget, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   587
	Window *w = FindFreeWindow();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   589
	/* We have run out of windows, close one and use that as the place for our new one */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   590
	if (w == NULL) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   591
		w = FindDeletableWindow();
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   592
		if (w == NULL) w = ForceFindDeletableWindow();
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   593
		DeleteWindow(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   596
	// Set up window properties
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   597
	memset(w, 0, sizeof(*w));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	w->window_class = cls;
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   599
	w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
	w->caption_color = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	w->left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
	w->top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	w->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
	w->height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	w->wndproc = proc;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   606
	AssignWidgetToWindow(w, widget);
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   607
	w->resize.width = width;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   608
	w->resize.height = height;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   609
	w->resize.step_width = 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   610
	w->resize.step_height = 1;
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   611
	w->window_number = window_number;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   613
	{
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   614
		Window **wz = _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
   615
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   616
		/* Hacky way of specifying always-on-top windows. These windows are
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   617
		 * always above other windows because they are moved below them.
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   618
		 * status-bar is above news-window because it has been created earlier.
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   619
		 * Also, as the chat-window is excluded from this, it will always be
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   620
		 * the last window, thus always on top.
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   621
		 * XXX - Yes, ugly, probably needs something like w->always_on_top flag
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   622
		 * to implement correctly, but even then you need some kind of distinction
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   623
		 * between on-top of chat/news and status windows, because these conflict */
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   624
		if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   625
			if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   626
			if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   627
			if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   628
			if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   629
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   630
			assert(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
   631
			if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   632
		}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   633
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   634
		*wz = w;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   635
		_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
   636
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   637
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
	SetWindowDirty(w);
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 86
diff changeset
   639
	CallWindowEventNP(w, WE_CREATE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   644
/**
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   645
 * 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
   646
 * 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
   647
 * 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
   648
 * 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
   649
 * @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
   650
 * @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
   651
 * @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
   652
 * @param height height 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
   653
 * @param *proc @see WindowProc function to call when any messages/updates happen to 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
   654
 * @param cls @see WindowClass class of the window, used for identification and grouping
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   655
 * @param *widget @see Widget pointer to the window layout and various elements
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   656
 * @return @see Window pointer of the newly created window
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   657
 */
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   658
Window *AllocateWindow(
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   659
							int x, int y, int width, int height,
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   660
							WindowProc *proc, WindowClass cls, const Widget *widget)
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   661
{
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   662
	return LocalAllocateWindow(x, y, width, height, proc, cls, widget, 0);
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   663
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
typedef struct SizeRect {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	int left,top,width,height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
} SizeRect;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
static SizeRect _awap_r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
static bool IsGoodAutoPlace1(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	int right,bottom;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   675
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	right = _awap_r.width + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	bottom = _awap_r.height + top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   685
	// 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
   686
	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
   687
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   688
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   690
		if (right > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   691
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
				bottom > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   693
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   694
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   695
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   696
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
static bool IsGoodAutoPlace2(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	int width,height;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   704
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	width = _awap_r.width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	height = _awap_r.height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   711
	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
   712
	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
   713
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   714
	// 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
   715
	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
   716
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   717
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   719
		if (left + width > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   720
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
				top + height > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   722
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   723
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   724
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   725
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   730
static Point GetAutoPlacePosition(int width, int height)
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   731
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   732
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
	_awap_r.width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	_awap_r.height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
	if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
	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
   741
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   742
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
		if (IsGoodAutoPlace1(w->left-   width-2,w->top)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
		if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
		if (IsGoodAutoPlace1(w->left,w->top-   height-2)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
		if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
		if (IsGoodAutoPlace1(w->left-   width-2,w->top+w->height-height)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
		if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		if (IsGoodAutoPlace1(w->left+w->width-width,w->top-   height-2)) goto ok_pos;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   752
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   753
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   754
	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
   755
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   756
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
		if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		if (IsGoodAutoPlace2(w->left-   width-2,w->top)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
		if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
		if (IsGoodAutoPlace2(w->left,w->top-   height-2)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
		int left=0,top=24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   766
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
restart:;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   768
		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
   769
			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
   770
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
			if (w->left == left && w->top == top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   777
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   782
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
ok_pos:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
	pt.x = _awap_r.left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
	pt.y = _awap_r.top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   789
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   794
	/* By default position a child window at an offset of 10/10 of its parent.
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   795
	 * However if it falls too extremely outside window positions, reposition
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   796
	 * it to an automatic place */
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   797
	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
   798
			(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
   799
			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
   800
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
		pt.x = w->left + 10;
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   802
		if (pt.x > _screen.width + 10 - desc->width) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
			pt.x = (_screen.width + 10 - desc->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
   804
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
		pt.y = w->top + 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	} else {
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   807
		switch (desc->left) {
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   808
			case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   809
				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   810
				pt.x = (w->left + w->width) - desc->width;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   811
			}	break;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   812
			case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   813
				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
   814
				break;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   815
			case WDP_AUTO: /* Find a good automatic position for the window */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   816
				pt = GetAutoPlacePosition(desc->width, desc->height);
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   817
				goto allocate_window;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   818
			case WDP_CENTER: /* Centre the window horizontally */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   819
				pt.x = (_screen.width - desc->width) / 2;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   820
				break;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   821
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   822
				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
   823
				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
   824
		}
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   825
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   826
		switch (desc->top) {
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   827
			case WDP_CENTER: /* Centre the window vertically */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   828
				pt.y = (_screen.height - desc->height) / 2;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   829
				break;
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   830
			/* 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
   831
			 * 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
   832
			case WDP_AUTO:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   833
				NOT_REACHED();
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   834
				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
   835
				/* fallthrough */
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   836
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   837
				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
   838
				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
   839
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   843
allocate_window:
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   844
	w = LocalAllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	w->desc_flags = desc->flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   849
/**
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   850
 * Open a new window.
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   851
 * @param *desc The pointer to the WindowDesc to be created
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   852
 * @return @see Window pointer of the newly created window
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   853
 */
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   854
Window *AllocateWindowDesc(const WindowDesc *desc)
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   855
{
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   856
	return LocalAllocateWindowDesc(desc, 0);
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   857
}
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   858
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   859
/**
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   860
 * Open a new window.
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   861
 * @param *desc The pointer to the WindowDesc to be created
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   862
 * @param window_number the window number of the new window
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   863
 * @return @see Window pointer of the newly created window
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   864
 */
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   865
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number)
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   866
{
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   867
	Window *w;
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   868
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   869
	if (BringWindowToFrontById(desc->cls, window_number)) return NULL;
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   870
	w = LocalAllocateWindowDesc(desc, window_number);
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   871
	return w;
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   872
}
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   873
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   874
/** 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
   875
 * at the topmost window, obviously and work our way down to the bottom
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   876
 * @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
   877
Window *FindWindowFromPt(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   879
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   881
	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
   882
		Window *w = *--wz;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   883
		if (IS_INSIDE_1D(x, w->left, w->width) && IS_INSIDE_1D(y, w->top, w->height)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   884
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   885
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   891
void InitWindowSystem(void)
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
   892
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   893
	IConsoleClose();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   894
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	memset(&_windows, 0, sizeof(_windows));
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   896
	_last_z_window = _z_windows;
5122
a68d16b055fa (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5121
diff changeset
   897
	InitViewports();
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
   898
	_no_scroll = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   901
void UnInitWindowSystem(void)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   902
{
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   903
	Window **wz;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   904
	/* Delete all malloced widgets, and reset 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
   905
	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
   906
		free((*wz)->widget);
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   907
		(*wz)->widget = NULL;
5232
0ba6acdc527f (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   908
		(*wz)->widget_count = 0;
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   909
		*wz = NULL;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   910
	}
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
   911
	_last_z_window = _z_windows;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   912
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   913
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   914
void ResetWindowSystem(void)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   915
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   916
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   917
	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
   918
	_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
   919
	_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
   920
	_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
   921
	_thd.new_pos.y = 0;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   922
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   923
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   924
static void DecreaseWindowCounters(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
	Window *w;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   927
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   929
	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
   930
		w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
		// Unclick scrollbar buttons if they are pressed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
		CallWindowEventNP(w, WE_MOUSELOOP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   939
	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
   940
		w = *--wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   941
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
		if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
			CallWindowEventNP(w, WE_TIMEOUT);
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   944
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) RaiseWindowButtons(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   949
Window *GetCallbackWnd(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
	return FindWindowById(_thd.window_class, _thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   954
static void HandlePlacePresize(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   959
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   961
	w = GetCallbackWnd();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   962
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   964
	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
   965
	if (e.we.place.pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
	}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   969
	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
   970
	e.event = WE_PLACE_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   972
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   974
static bool HandleDragDrop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   979
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   981
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   982
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
	w = GetCallbackWnd();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   985
	ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   987
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
		// send an event in client coordinates.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
		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
   990
		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
   991
		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
   992
		e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
   998
static bool HandlePopupMenu(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1003
	if (!_popup_menu_active) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
	w = FindWindowById(WC_TOOLBAR_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
		e.event = WE_POPUPMENU_OVER;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1013
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
		e.event = WE_POPUPMENU_SELECT;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1017
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
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
  1020
	w->wndproc(w, &e);
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
  1021
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1025
static bool HandleMouseOver(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1026
{
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1027
	Window *w;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1028
	WindowEvent e;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1029
	static Window *last_w = NULL;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1030
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1031
	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1032
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1033
	// We changed window, put a MOUSEOVER event to the last window
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1034
	if (last_w != NULL && last_w != w) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1035
		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
  1036
		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
  1037
		e.we.mouseover.pt.y = -1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1038
		if (last_w->wndproc) last_w->wndproc(last_w, &e);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1039
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1040
	last_w = w;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1041
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1042
	if (w != NULL) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1043
		// send an event in client coordinates.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1044
		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
  1045
		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
  1046
		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
  1047
		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
  1048
			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
  1049
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1050
		w->wndproc(w, &e);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1051
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1052
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1053
	// Mouseover never stops execution
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1054
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1055
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1056
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1057
/** Update all the widgets of a window based on their resize flags
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1058
 * 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
  1059
 * ensuring proper redrawal.
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1060
 * @param w Window to resize
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1061
 * @param x delta x-size of changed window (positive if larger, etc.(
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1062
 * @param y delta y-size of changed window */
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1063
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
  1064
{
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1065
	Widget *wi;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1066
	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
  1067
	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
  1068
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1069
	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
  1070
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1071
	SetWindowDirty(w);
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1072
	for (wi = w->widget; wi->type != WWT_LAST; wi++) {
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1073
		/* 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
  1074
		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
  1075
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1076
		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
  1077
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1078
		/* 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
  1079
		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
  1080
			wi->left += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1081
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1082
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1083
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1084
		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
  1085
			wi->right += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1086
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1087
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1088
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1089
		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
  1090
			wi->top += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1091
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1092
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1093
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1094
		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
  1095
			wi->bottom += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1096
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1097
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1098
	}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1099
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1100
	/* 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
  1101
	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
  1102
	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
  1103
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1104
	SetWindowDirty(w);
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1105
}
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1106
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1107
static bool _dragging_window;
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1108
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1109
static bool HandleWindowDragging(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1111
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	// Get out immediately if no window is being dragged at all.
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1113
	if (!_dragging_window) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	// 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
  1116
	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
  1117
		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
  1118
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1119
		if (w->flags4 & WF_DRAGGING) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1120
			const Widget *t = &w->widget[1]; // the title bar ... ugh
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1121
			const Window *v;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1122
			int x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1123
			int y;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1124
			int nx;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1125
			int ny;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1126
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
			// Stop the dragging if the left mouse button was released
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
			if (!_left_button_down) {
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1129
				w->flags4 &= ~WF_DRAGGING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
				break;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1135
			x = _cursor.pos.x + _drag_delta.x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1136
			y = _cursor.pos.y + _drag_delta.y;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1137
			nx = x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1138
			ny = y;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1139
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1140
			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
  1141
				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
  1142
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1143
				int hsnap = _patches.window_snap_radius;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1144
				int vsnap = _patches.window_snap_radius;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1145
				int delta;
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1146
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1147
				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
  1148
					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
  1149
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1150
					if (v == w) continue; // Don't snap at yourself
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1151
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1152
					if (y + w->height > v->top && y < v->top + v->height) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1153
						// Your left border <-> other right border
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1154
						delta = abs(v->left + v->width - x);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1155
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1156
							nx = v->left + v->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1157
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1158
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1159
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1160
						// Your right border <-> other left border
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1161
						delta = abs(v->left - x - w->width);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1162
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1163
							nx = v->left - w->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1164
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1165
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1166
					}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1167
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1168
					if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1169
						// Your left border <-> other left border
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1170
						delta = abs(v->left - x);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1171
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1172
							nx = v->left;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1173
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1174
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1175
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1176
						// Your right border <-> other right border
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1177
						delta = abs(v->left + v->width - x - w->width);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1178
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1179
							nx = v->left + v->width - w->width;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1180
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1181
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1182
					}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1183
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1184
					if (x + w->width > v->left && x < v->left + v->width) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1185
						// Your top border <-> other bottom border
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1186
						delta = abs(v->top + v->height - y);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1187
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1188
							ny = v->top + v->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1189
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1190
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1191
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1192
						// Your bottom border <-> other top border
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1193
						delta = abs(v->top - y - w->height);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1194
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1195
							ny = v->top - w->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1196
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1197
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1198
					}
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1199
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1200
					if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1201
						// Your top border <-> other top border
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1202
						delta = abs(v->top - y);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1203
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1204
							ny = v->top;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1205
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1206
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1207
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1208
						// Your bottom border <-> other bottom border
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1209
						delta = abs(v->top + v->height - y - w->height);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1210
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1211
							ny = v->top + v->height - w->height;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1212
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1213
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1214
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
			}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1217
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1218
			// Make sure the window doesn't leave the screen
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1219
			// 13 is the height of the title bar
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1220
			nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1221
			ny = clamp(ny, 0, _screen.height - 13);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1222
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1223
			// Make sure the title bar isn't hidden by behind the main tool bar
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1224
			v = FindWindowById(WC_MAIN_TOOLBAR, 0);
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1225
			if (v != NULL) {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1226
				int v_bottom = v->top + v->height;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1227
				int v_right = v->left + v->width;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1228
				if (ny + t->top >= v->top && ny + t->top < v_bottom) {
371
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1229
					if ((v->left < 13 && nx + t->left < v->left) ||
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1230
							(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
  1231
						ny = v_bottom;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1232
					} else {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1233
						if (nx + t->left > v->left - 13 &&
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1234
								nx + t->right < v_right + 13) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1235
							if (w->top >= v_bottom) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1236
								ny = v_bottom;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1237
							} else if (w->left < nx) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1238
								nx = v->left - 13 - t->left;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1239
							} else {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1240
								nx = v_right + 13 - t->right;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1241
							}
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1242
						}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1243
					}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1244
				}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1245
			}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1246
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1247
			if (w->viewport != NULL) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1248
				w->viewport->left += nx - w->left;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1249
				w->viewport->top  += ny - w->top;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1250
			}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1251
			w->left = nx;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1252
			w->top  = ny;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1253
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
			return false;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1256
		} 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
  1257
			WindowEvent e;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1258
			int x, y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1259
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1260
			/* 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
  1261
			if (!_left_button_down) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1262
				w->flags4 &= ~WF_SIZING;
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1648
diff changeset
  1263
				SetWindowDirty(w);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1264
				break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1265
			}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1266
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1267
			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
  1268
			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
  1269
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1270
			/* 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
  1271
			 * 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
  1272
			 * unsigned int, which won't work. */
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1273
			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
  1274
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1275
			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
  1276
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1277
			/* 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
  1278
			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
  1279
				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
  1280
			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
  1281
				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
  1282
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1283
			/* Window already on size */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1284
			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
  1285
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1286
			/* 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
  1287
			    we move in steps. */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1288
			_drag_delta.x += x;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1289
			_drag_delta.y += y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1290
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1291
			/* 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
  1292
			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
  1293
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1294
			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
  1295
			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
  1296
			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
  1297
			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
  1298
			e.we.sizing.diff.y = y;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1299
			w->wndproc(w, &e);
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1300
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	_dragging_window = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1308
static void StartWindowDrag(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
	w->flags4 |= WF_DRAGGING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1312
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1313
	_drag_delta.x = w->left - _cursor.pos.x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1314
	_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
  1315
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1316
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1320
static void StartWindowSizing(Window *w)
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
	w->flags4 |= WF_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1324
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1325
	_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
  1326
	_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
  1327
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1328
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1333
static bool HandleScrollbarScrolling(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1335
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
	int pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	// Get out quickly if no item is being scrolled
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1341
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
	// 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
  1344
	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
  1345
		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
  1346
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
		if (w->flags4 & WF_SCROLL_MIDDLE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
			// Abort if no button is clicked any more.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
				w->flags4 &= ~WF_SCROLL_MIDDLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1353
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1357
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1358
			} else if (w->flags4 & WF_SCROLL2){
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1359
				sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1360
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
			// Find the item we want to move to and make sure it's inside bounds.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
			pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
				sb->pos = pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1373
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1375
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1380
static bool HandleViewportScroll(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
{
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
  1382
	WindowEvent e;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1385
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
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
  1387
	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
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
  1388
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
  1389
	if (!_right_button_down || w == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
		_cursor.fix_at = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
		_scrolling_viewport = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1394
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1395
	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
  1396
		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
  1397
		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
  1398
	} 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
  1399
		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
  1400
		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
  1401
	}
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1402
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
  1403
	/* 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
  1404
	e.event = WE_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
  1405
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1407
	_cursor.delta.x = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1408
	_cursor.delta.y = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1409
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1412
/** Check if a window can be made top-most window, and if so do
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1413
 * it. If a window does not obscure any other windows, it will not
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1414
 * be brought to the foreground. Also if the only obscuring windows
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1415
 * are so-called system-windows, the window will not be moved.
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1416
 * The function will return false when a child window of this window is a
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1417
 * modal-popup; function returns a false and child window gets a white border
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1418
 * @param w Window to bring on-top
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1419
 * @return false if the window has an active modal child, true otherwise */
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1420
static bool MaybeBringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
{
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1422
	bool bring_to_front = false;
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
  1423
	Window* const *wz;
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
  1424
	Window* const *uz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1426
	if (w->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1427
			IsVitalWindow(w) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1428
			w->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1429
			w->window_class == WC_DROPDOWN_MENU) {
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1430
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1431
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1433
	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
  1434
	for (uz = wz; ++uz != _last_z_window;) {
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1435
		Window *u = *uz;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1436
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1437
		/* A modal child will prevent the activation of the parent window */
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1438
		if (u->parent == w && (u->desc_flags & WDF_MODAL)) {
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1439
			u->flags4 |= WF_WHITE_BORDER_MASK;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1440
			SetWindowDirty(u);
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1441
			return false;
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1442
		}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1443
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1444
		if (u->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1445
				IsVitalWindow(u) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1446
				u->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1447
				u->window_class == WC_DROPDOWN_MENU) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1448
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1449
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1451
		/* 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
  1452
		if (w->left + w->width <= u->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
				u->left + u->width <= w->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
				w->top  + w->height <= u->top ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1455
				u->top + u->height <= w->top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1456
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1457
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1458
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1459
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	}
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1461
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1462
	if (bring_to_front) BringWindowToFront(w);
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1463
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1466
/** Send a message from one window to another. The receiving window is found by
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1467
 * @param w @see Window pointer pointing to the other window
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1468
 * @param msg Specifies the message to be sent
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1469
 * @param wparam Specifies additional message-specific information
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1470
 * @param lparam Specifies additional message-specific information
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1471
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1472
static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1473
{
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1474
	WindowEvent e;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1475
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1476
	e.event             = WE_MESSAGE;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1477
	e.we.message.msg    = msg;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1478
	e.we.message.wparam = wparam;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1479
	e.we.message.lparam = lparam;
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1480
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1481
	w->wndproc(w, &e);
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1482
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1483
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1484
/** Send a message from one window to another. The receiving window is found by
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1485
 * @param wnd_class @see WindowClass class AND
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1486
 * @param wnd_num @see WindowNumber number, mostly 0
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1487
 * @param msg Specifies the message to be sent
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1488
 * @param wparam Specifies additional message-specific information
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1489
 * @param lparam Specifies additional message-specific information
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1490
 */
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1491
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, uint msg, uint wparam, uint lparam)
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1492
{
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1493
	Window *w = FindWindowById(wnd_class, wnd_num);
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1494
	if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam);
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1495
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1496
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1497
/** Send a message from one window to another. The message will be sent
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1498
 * to ALL windows of the windowclass specified in the first parameter
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1499
 * @param wnd_class @see WindowClass class
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1500
 * @param msg Specifies the message to be sent
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1501
 * @param wparam Specifies additional message-specific information
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1502
 * @param lparam Specifies additional message-specific information
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1503
 */
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1504
void SendWindowMessageClass(WindowClass wnd_class, uint msg, uint wparam, uint lparam)
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1505
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1506
	Window* const *wz;
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1507
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1508
	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
  1509
		if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam);
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1510
	}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1511
}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1512
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1513
/** Handle keyboard input.
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1514
 * @param key Lower 8 bits contain the ASCII character, the higher
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1515
 * 16 bits the keycode */
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1516
void HandleKeypress(uint32 key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1518
	Window* const *wz;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1519
	WindowEvent e;
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1520
	/* Stores if a window with a textfield for typing is open
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1521
	 * If this is the case, keypress events are only passed to windows with text fields and
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1522
	 * to thein this main toolbar. */
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
  1523
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1524
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1525
	/*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1526
	* 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
  1527
	* 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
  1528
	* 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
  1529
	* 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
  1530
	*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1531
	* 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
  1532
	* 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
  1533
	*/
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1534
	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
  1535
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	// 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
  1537
	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
  1538
	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
  1539
	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
  1540
	e.we.keypress.cont = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
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
  1542
	// check if we have a query string window open before allowing hotkeys
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1543
	if (FindWindowById(WC_QUERY_STRING,       0) != NULL ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1544
			FindWindowById(WC_SEND_NETWORK_MSG,   0) != NULL ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1545
			FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1546
			FindWindowById(WC_CONSOLE,            0) != NULL ||
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1547
			FindWindowById(WC_SAVELOAD,           0) != NULL) {
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
  1548
		query_open = true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1549
	}
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
  1550
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
	// Call the event, start with the uppermost window.
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1552
	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
  1553
		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
  1554
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
  1555
		// if a query window is open, only call the event for certain window types
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1556
		if (query_open &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1557
				w->window_class != WC_QUERY_STRING &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1558
				w->window_class != WC_SEND_NETWORK_MSG &&
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1559
				w->window_class != WC_GENERATE_LANDSCAPE &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1560
				w->window_class != WC_CONSOLE &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1561
				w->window_class != WC_SAVELOAD) {
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
  1562
			continue;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1563
		}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1564
		w->wndproc(w, &e);
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1565
		if (!e.we.keypress.cont) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
	}
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
  1567
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1568
	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
  1569
		Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
1642
593a9b750b91 (svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents: 1637
diff changeset
  1570
		// When there is no toolbar w is null, check for that
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1571
		if (w != NULL) w->wndproc(w, &e);
1642
593a9b750b91 (svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents: 1637
diff changeset
  1572
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1574
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1575
extern void UpdateTileSelection(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1576
extern bool VpHandlePlaceSizingDrag(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1578
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
  1579
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1580
static void HandleAutoscroll(void)
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1581
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1582
	Window *w;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1583
	ViewPort *vp;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1584
	int x = _cursor.pos.x;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1585
	int y = _cursor.pos.y;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1586
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1587
	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
  1588
		/* 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
  1589
		_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
  1590
		/* 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
  1591
		return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1592
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1593
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1594
	if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1595
		w = FindWindowFromPt(x, y);
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1596
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1597
		vp = IsPtInWindowViewport(w, x, y);
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1598
		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
  1599
			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
  1600
			y -= vp->top;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1601
			//here allows scrolling in both x and y axis
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1602
#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
  1603
			if (x - 15 < 0) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1604
				WP(w, vp_d).scrollpos_x += (x - 15) * scrollspeed << vp->zoom;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1605
			} else if (15 - (vp->width - x) > 0) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1606
				WP(w, vp_d).scrollpos_x += (15 - (vp->width - x)) * scrollspeed << vp->zoom;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1607
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1608
			if (y - 15 < 0) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1609
				WP(w, vp_d).scrollpos_y += (y - 15) * scrollspeed << vp->zoom;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1610
			} else if (15 - (vp->height - y) > 0) {
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1611
				WP(w,vp_d).scrollpos_y += (15 - (vp->height - y)) * scrollspeed << vp->zoom;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1612
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1613
#undef scrollspeed
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1614
		}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1615
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1616
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1617
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1618
void MouseLoop(int click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	ViewPort *vp;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1623
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
	UpdateTileSelection();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1627
	if (!VpHandlePlaceSizingDrag())  return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1628
	if (!HandleDragDrop())           return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1629
	if (!HandlePopupMenu())          return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1630
	if (!HandleWindowDragging())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1631
	if (!HandleScrollbarScrolling()) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1632
	if (!HandleViewportScroll())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1633
	if (!HandleMouseOver())          return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1634
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
	x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1638
	if (click == 0 && mousewheel == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	w = FindWindowFromPt(x, y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1641
	if (w == NULL) return;
5623
ef2a8a524a95 (svn r7721) [cbh] - Sync with 7607:7720 from trunk
celestar
parents: 5568
diff changeset
  1642
	if (!MaybeBringWindowToFront(w)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1643
	vp = IsPtInWindowViewport(w, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
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
  1645
	/* 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
  1646
	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
  1647
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
  1648
	if (mousewheel != 0) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1649
		WindowEvent e;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1650
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1651
		/* Send WE_MOUSEWHEEL event to window */
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1652
		e.event = WE_MOUSEWHEEL;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1653
		e.we.wheel.wheel = mousewheel;
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
  1654
		w->wndproc(w, &e);
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1655
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1656
		/* 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
  1657
		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
  1658
	}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1659
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1660
	if (vp != NULL) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1661
		switch (click) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1662
			case 1:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1663
				DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
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
  1664
				if (_thd.place_mode != 0 &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1665
						// query button and place sign button work in pause mode
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1666
						_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
  1667
						_cursor.sprite != SPR_CURSOR_SIGN &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1668
						_pause != 0 &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1669
						!_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
  1670
					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
  1671
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1672
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1673
				if (_thd.place_mode == 0) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1674
					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
  1675
				} 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
  1676
					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
  1677
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1678
				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
  1679
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1680
			case 2:
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1681
				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
  1682
					_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
  1683
					_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
  1684
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1685
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
	} else {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1688
		switch (click) {
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1689
			case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top);  break;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1690
			case 2: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1691
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
void HandleMouseEvents(void)
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
  1696
{
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
  1697
	int click;
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
  1698
	int 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
  1699
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1700
	/*
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1701
	 * 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
  1702
	 * 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
  1703
	 * 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
  1704
	 * NOT change the _current_player here.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1705
	 *
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1706
	 * 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
  1707
	 * 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
  1708
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1709
	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
  1710
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
  1711
	// Mouse event?
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
  1712
	click = 0;
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
  1713
	if (_left_button_down && !_left_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
  1714
		_left_button_clicked = true;
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
  1715
		click = 1;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1716
		_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
  1717
	} 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
  1718
		_right_button_clicked = false;
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
  1719
		click = 2;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1720
		_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
  1721
	}
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
  1722
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
  1723
	mousewheel = 0;
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
  1724
	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
  1725
		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
  1726
		_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
  1727
		_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
  1728
	}
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
  1729
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
  1730
	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
  1731
}
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
  1732
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1733
void InputLoop(void)
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
	HandleMouseEvents();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1736
	HandleAutoscroll();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1737
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1738
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1739
void UpdateWindows(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1741
	Window* const *wz;
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1742
	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
  1743
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1745
	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
  1746
		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
  1747
			CallWindowEventNP(*--wz, WE_4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1750
	}
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1751
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1753
	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
  1754
		Window *w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
			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
  1757
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1758
			if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1764
	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
  1765
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1767
	DrawTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
	// Redraw mouse cursor in case it was hidden
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1769
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1770
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1772
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2216
diff changeset
  1773
int GetMenuItemIndex(const Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
	if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
		y /= 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1777
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1778
		if (y < WP(w, const menu_d).item_count &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1779
				!HASBIT(WP(w, const menu_d).disabled_items, y)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1780
			return y;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1781
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1782
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1783
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1784
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1785
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1786
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
{
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
  1788
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1789
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1790
	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
  1791
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1792
		if (w->window_class == cls && w->window_number == number) SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1794
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1795
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1796
void InvalidateWidget(const Window *w, byte widget_index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1797
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1798
	const Widget *wi = &w->widget[widget_index];
1867
8de1958719fe (svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents: 1744
diff changeset
  1799
8de1958719fe (svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents: 1744
diff changeset
  1800
	/* Don't redraw the window if the widget is invisible or of no-type */
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
  1801
	if (wi->type == WWT_EMPTY || IsWindowWidgetHidden(w, widget_index)) return;
1867
8de1958719fe (svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents: 1744
diff changeset
  1802
8de1958719fe (svn r2373) - CodeChange: don't redraw the window upon a user-based dirty request if the requested widget is invisible or otherwise not visible (type WWT_EMPTY)
Darkvater
parents: 1744
diff changeset
  1803
	SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1806
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
  1807
{
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
  1808
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1810
	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
  1811
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1812
		if (w->window_class == cls && w->window_number == number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
			InvalidateWidget(w, widget_index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1818
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
{
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
  1820
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1821
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1822
	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
  1823
		if ((*wz)->window_class == cls) SetWindowDirty(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
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
  1827
void InvalidateThisWindowData(Window *w)
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
  1828
{
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
  1829
	CallWindowEventNP(w, WE_INVALIDATE_DATA);
5198
2547d72f2db4 (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5143
diff changeset
  1830
	SetWindowDirty(w);
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
  1831
}
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
  1832
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1833
void InvalidateWindowData(WindowClass cls, WindowNumber number)
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1834
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1835
	Window* const *wz;
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1836
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1837
	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
  1838
		Window *w = *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
  1839
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w);
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
  1840
	}
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
  1841
}
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
  1842
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
  1843
void InvalidateWindowClassesData(WindowClass cls)
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
  1844
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1845
	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
  1846
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1847
	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
  1848
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz);
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1849
	}
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1850
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1851
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1852
void CallWindowTickEvent(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1854
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1855
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1856
	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
  1857
		CallWindowEventNP(*--wz, WE_TICK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1860
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1861
void DeleteNonVitalWindows(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1863
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1864
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
  1865
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
  1866
	/* 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
  1867
	 * 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
  1868
	 * 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
  1869
	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
  1870
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1873
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
				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
  1876
				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
  1877
				(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
  1878
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1879
			DeleteWindow(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
  1880
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1881
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1883
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1884
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1885
/* 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
  1886
 * '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
  1887
 * 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
  1888
 * 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
  1889
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  1890
void DeleteAllNonVitalWindows(void)
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  1891
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1892
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1893
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
  1894
	/* 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
  1895
	DeleteNonVitalWindows();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1896
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
  1897
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
  1898
	/* 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
  1899
	 * 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
  1900
	 * 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
  1901
	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
  1902
		if ((*wz)->flags4 & WF_STICKY) {
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1903
			DeleteWindow(*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
  1904
			goto restart_search;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1905
		}
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
  1906
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  1907
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  1908
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
  1909
/* Delete all always on-top windows to get an empty screen */
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
  1910
void HideVitalWindows(void)
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
  1911
{
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
  1912
	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
  1913
	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
  1914
}
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
  1915
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1916
int PositionMainToolbar(Window *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1917
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1918
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1919
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1920
	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
  1921
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1922
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1923
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1924
	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
  1925
		case 1:  w->left = (_screen.width - w->width) / 2; break;
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  1926
		case 2:  w->left = _screen.width - w->width; break;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  1927
		default: w->left = 0;
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1928
	}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1929
	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
  1930
	return w->left;
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1931
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  1932
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1935
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1937
	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
  1938
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1940
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1942
			ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1943
			vp->width = w->width = neww;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1944
			vp->height = w->height = newh;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
			vp->virtual_width = neww << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
			vp->virtual_height = newh << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
			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
  1948
		}
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
  1949
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  1950
		/* 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
  1951
		 * in a 'backup'-desc that the window should always be centred. */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1952
		switch (w->window_class) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1953
			case WC_MAIN_TOOLBAR:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1954
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1955
				left = PositionMainToolbar(w); // changes toolbar orientation
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1956
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1957
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1958
			case WC_SELECT_GAME:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1959
			case WC_GAME_OPTIONS:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1960
			case WC_NETWORK_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1961
				top = (newh - w->height) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1962
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1963
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1964
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1965
			case WC_NEWS_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1966
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1967
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1968
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1969
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1970
			case WC_STATUS_BAR:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1971
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1972
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1973
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1974
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1975
			case WC_SEND_NETWORK_MSG:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1976
				top = (newh - 26); // 26 = height of status bar + height of chat bar
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1977
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1978
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1979
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  1980
			case WC_CONSOLE:
5143
a78072872bff (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  1981
				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
  1982
				continue;
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  1983
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1984
			default:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1985
				left = w->left;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1986
				if (left + (w->width >> 1) >= neww) left = neww - w->width;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1987
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1988
				if (top + (w->height >> 1) >= newh) top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1989
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1992
		if (w->viewport != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
			w->viewport->left += left - w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
			w->viewport->top += top - w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1996
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1997
		w->left = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
		w->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1999
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
}