src/window.cpp
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
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
6268
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6267
diff changeset
     3
/** @file window.cpp windowing system, widgets and events */
4b5241e5dd10 (svn r8938) [cpp_gui] -Sync with trunk (r8772..r8900)
bjarni
parents: 6267
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
     6
#include <stdarg.h>
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1867
diff changeset
     7
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1112
diff changeset
     8
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     9
#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
    10
#include "map.h"
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2026
diff changeset
    11
#include "player.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#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
    14
#include "viewport.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 116
diff changeset
    15
#include "console.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    16
#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
    17
#include "table/sprites.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    18
#include "genworld.h"
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    19
#include "helpers.hpp"
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    20
#include "widget/window_events.hpp"
6289
be3d8bd9fb02 (svn r9010) [cpp_gui] -Add: Sticky button widget
KUDr
parents: 6283
diff changeset
    21
#include "widget/widget_types.h"
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    22
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
    23
/* delta between mouse cursor and upper left corner of dragged window */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    24
static Point _drag_delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    25
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    26
/*static*/ WindowList BaseWindow::s_list;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    27
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    28
//static BaseWindow _windows[25];
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    29
//BaseWindow *_z_windows[lengthof(_windows)];
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    30
//BaseWindow **_last_z_window; ///< always points to the next free space in the z-array
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    31
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    32
void WindowList::Add(BaseWindow *w)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    33
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    34
	/* we will add the new window before first vital window or at the end */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    35
	Iterator it = w->IsVital() ? m_list.end() : FindFirstVitalWindow();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    36
	/* it should be now at the proper position where new window should be added */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    37
	m_list.insert(it, w);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    38
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    39
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    40
void WindowList::Remove(BaseWindow *w)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    41
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    42
	Iterator it = Find(w);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    43
	if (it != m_list.end()) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    44
		assert(it != m_list.end());
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    45
		Item &item = (*it);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    46
		assert(item.w == w);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    47
//		w->Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    48
		m_list.erase(it);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    49
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    50
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    51
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    52
void WindowList::CloseAll()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    53
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    54
	BaseWindow *w_prev = NULL;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    55
	while (!m_list.empty()) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    56
		Iterator it = m_list.begin();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    57
		Item &item = (*it);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    58
		BaseWindow *w = item.w;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    59
		assert(w != w_prev);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    60
		w_prev = w;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    61
		w->Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
    62
	}
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    63
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    64
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    65
static bool MatchWindow(WindowList::Iterator it, BaseWindow *w)
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    66
{
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    67
	return (*it).w == w;
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    68
}
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    69
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    70
WindowList::Iterator WindowList::Find(BaseWindow *w)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    71
{
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    72
	Iterator it = EnumT(&MatchWindow, w);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    73
	if (it == m_list.end()) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
    74
		DEBUG(misc, 3, "BaseWindow (cls %d, number %d) is not open, probably removed by recursive calls",
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    75
			w->window_class, w->window_number);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    76
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    77
	return it;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    78
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    79
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    80
static bool MatchNonVitalWindow(WindowList::Iterator it)
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    81
{
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    82
	return !(*it).w->IsVital();
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    83
}
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    84
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    85
WindowList::Iterator WindowList::FindFirstVitalWindow()
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    86
{
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    87
	Iterator it = ReverseEnumT(&MatchNonVitalWindow);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    88
	/* we have stopped on last non-vital window. Move one step forward to locate first vital window. */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    89
	if (it != m_list.end()) ++it;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    90
	return it;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    91
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    92
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    93
static bool MatchClass(WindowList::Iterator it, WindowClass cls)
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    94
{
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    95
	return (*it).w->window_class == cls;
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    96
}
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
    97
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    98
WindowList::Iterator WindowList::FindByClass(WindowClass cls)
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
    99
{
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   100
	return EnumT(&MatchClass, cls);
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   101
}
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   102
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   103
static bool MatchClassAndId(WindowList::Iterator it, WindowClass cls, WindowNumber num)
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   104
{
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   105
	return (*it).w->window_class == cls && (*it).w->window_number == num;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   106
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   107
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   108
WindowList::Iterator WindowList::FindById(WindowClass cls, WindowNumber num)
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   109
{
6236
ec056d324811 (svn r8693) [cpp_gui] -Fix: g++ compilation errors 'non-local function A uses local type B' (template arguments must have external linkage while local type has no linkage)
KUDr
parents: 6235
diff changeset
   110
	return EnumT(&MatchClassAndId, cls, num);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   111
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   112
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   113
static bool MatchXY(WindowList::Iterator it, int x, int y)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   114
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   115
	BaseWindow *w = (*it).w;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   116
	return IS_INSIDE_1D(x, w->Left(), w->Width()) && IS_INSIDE_1D(y, w->Top(), w->Height());
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   117
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   118
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   119
/** Do a search for a window at specific coordinates. For this we start
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   120
* at the topmost window, obviously and work our way down to the bottom
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   121
* @return a pointer to the found window if any, NULL otherwise */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   122
WindowList::Iterator WindowList::FindFromPt(int x, int y)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   123
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   124
	return ReverseEnumT(&MatchXY, x, y);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   125
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   126
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   127
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   128
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   129
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   130
int16 BaseWindow::Left() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   131
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   132
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   133
	return m_wnd_pos.x;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   134
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   135
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   136
int16 BaseWindow::Top() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   137
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   138
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   139
	return m_wnd_pos.y;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   140
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   141
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   142
int16 BaseWindow::Right() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   143
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   144
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   145
	return m_wnd_pos.x + super::Right();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   146
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   147
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   148
int16 BaseWindow::Bottom() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   149
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   150
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   151
	return m_wnd_pos.y + super::Bottom();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   152
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   153
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   154
const Point16& BaseWindow::TopLeft() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   155
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   156
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   157
	return m_wnd_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   158
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   159
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   160
Point16 BaseWindow::BottomRight() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   161
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   162
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   163
	return m_wnd_pos + super::BottomRight();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   164
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   165
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   166
Rect16 BaseWindow::GetRect() const
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   167
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   168
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   169
	return super::GetRect() + m_wnd_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   170
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   171
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   172
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   173
void BaseWindow::SetLeft(int16 val)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   174
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   175
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   176
	m_wnd_pos.x = val;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   177
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   178
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   179
void BaseWindow::SetTop(int16 val)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   180
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   181
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   182
	m_wnd_pos.y = val;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   183
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   184
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   185
void BaseWindow::SetRight(int16 val)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   186
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   187
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   188
	assert(val >= m_wnd_pos.x);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   189
	super::SetRight(val - m_wnd_pos.x);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   190
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   191
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   192
void BaseWindow::SetBottom(int16 val)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   193
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   194
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   195
	assert(val >= m_wnd_pos.y);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   196
	super::SetBottom(val - m_wnd_pos.y);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   197
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   198
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   199
void BaseWindow::SetTopLeft(const Point16 &pt)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   200
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   201
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   202
	m_wnd_pos = pt;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   203
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   204
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   205
void BaseWindow::SetBottomRight(const Point16 &pt)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   206
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   207
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   208
	super::SetBottomRight(pt - m_wnd_pos);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   209
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   210
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   211
void BaseWindow::SetSize(const Point16 &pt)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   212
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   213
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   214
	super::SetSize(pt);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   215
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   216
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   217
void BaseWindow::SetRect(const Rect16 &rect)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   218
{
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   219
	assert(super::TopLeft() == Point16(0, 0));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   220
	m_wnd_pos = rect.top_left;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   221
	super::SetBottomRight(rect.Size());
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   222
}
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   223
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   224
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   225
/*virtual*/ bool BaseWindow::Create(WindowNumber num)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   226
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   227
	window_number = num;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   228
	flash_timeout = 3; // just opened windows have a white border
6273
d8a2c6844650 (svn r8981) [cpp_gui] -Add: simple CaptionBar Widget
KUDr
parents: 6272
diff changeset
   229
	caption_color = 0xFF;
6279
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   230
	wndproc = &BaseWindow::DefaultWndProc;
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   231
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   232
	/* add our new window into z-order list */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   233
	BaseWindow::s_list.Add(this);
6279
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   234
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   235
	/* Finalize the creation process */
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   236
	CallEventNP(WE_CREATE);
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   237
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   238
	/* window should have some widgets now */
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   239
	assert(widget != NULL || m_widgets.size() > 0);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   240
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   241
	SetDirty();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   242
	return true;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   243
}
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   244
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   245
/*virtual*/ bool BaseWindow::Create(const WindowDesc *desc, WindowNumber num)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   246
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   247
	window_class = desc->cls;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   248
	flash_timeout = 3; // just opened windows have a white border
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   249
	caption_color = 0xFF;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   250
	SetTopLeft(Point16(desc->left, desc->top));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   251
	SetSize(Point16(desc->width, desc->height));
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   252
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   253
	wndproc = desc->proc != NULL ? desc->proc : &BaseWindow::DefaultWndProc;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   254
	desc_flags = desc->flags;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   255
	AssignWidget(desc->widgets);
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   256
	resize.width = Width();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   257
	resize.height = Height();
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   258
	resize.step_width = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   259
	resize.step_height = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   260
	window_number = num;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   261
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   262
	/* add our new window into z-order list */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   263
	BaseWindow::s_list.Add(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   264
6279
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   265
	/* Finalize the creation process */
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   266
	CallEventNP(WE_CREATE);
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   267
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   268
	SetDirty();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   269
	return true;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   270
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   271
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   272
/*virtual*/ void BaseWindow::CreateNcWidgets()
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   273
{
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   274
	super::CreateNcWidgets();
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   275
	if ((m_feature_flags & gui::FF_NO_CAPTION_BAR) == gui::FF_NONE) {
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   276
		/* add caption bar */
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   277
		gui::FeatureFlags feature_flags = m_feature_flags & (gui::FF_NO_CLOSE_BOX | gui::FF_NO_STICKY_BOX);
6301
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   278
		feature_flags |= gui::FF_SAME_HEIGHT | gui::FF_MAX_WIDTH;
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   279
		gui::CaptionBar *capt_bar = new gui::CaptionBar(this, feature_flags);
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   280
		AddWidget(capt_bar, gui::Panel::TOP);
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   281
	}
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   282
	if ((m_feature_flags & gui::FF_NO_RESIZE_BOX) == gui::FF_NONE) {
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   283
		/* add resize box */
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   284
		gui::ResizeBox *resize_box = new gui::ResizeBox(this);
6301
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   285
		AddWidget(resize_box, gui::Panel::CENTER);
6283
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   286
	}
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   287
}
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   288
6279
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   289
/*virtual*/ void BaseWindow::CreateWidgets()
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   290
{
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   291
	/* only old windows are allowed to use this fake 'CreateWidgets()' method << new gui must have its own */
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   292
	assert(widget != NULL);
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   293
}
c75b2c7222ff (svn r8991) [cpp_gui] -Codechange: composite widgets (incl. windows) now must implement CreateWidgets() method which is called from the default OnCreate() implementation
KUDr
parents: 6273
diff changeset
   294
6301
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   295
/*virtual*/ void BaseWindow::OnCreate(gui::EvtCreate &ev)
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   296
{
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   297
	super::OnCreate(ev);
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   298
	QuerySizes();
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   299
	DoLayout();
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   300
}
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   301
6293
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   302
/*virtual*/ void BaseWindow::OnPaint(gui::EvtPaint &ev)
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   303
{
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   304
	ClipDrawContext ctx(0, 0, Width(), Height());
6295
a88d8c2cff6e (svn r9091) [cpp_gui] -Codechange: Widgets now use container's coordinate space instead of window's space
KUDr
parents: 6293
diff changeset
   305
	if (!ctx.IsEmpty()) super::OnPaint(ev);
6293
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   306
}
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   307
6301
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   308
/*virtual*/ void BaseWindow::OnResize(gui::EvtResize &ev)
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   309
{
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   310
	if (ev.m_change == Point16(0, 0)) return;
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   311
	super::OnResize(ev);
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   312
	QuerySizes();
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   313
	DoLayout();
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   314
}
e0251f797d59 (svn r9484) [cpp_gui] -Add: Auto layout/resize ability of widgets.
KUDr
parents: 6298
diff changeset
   315
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   316
/**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   317
* Open a new window. If there is no space for a new window, close an open
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   318
* window. Try to avoid stickied windows, but if there is no else, close one of
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   319
* those as well. Then make sure all created windows are below some always-on-top
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   320
* ones. Finally set all variables and call the WE_CREATE event
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   321
* @param x offset in pixels from the left of the screen
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   322
* @param y offset in pixels from the top of the screen
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   323
* @param width width in pixels of the window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   324
* @param height height in pixels of the window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   325
* @param *proc @see WindowProc function to call when any messages/updates happen to the window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   326
* @param cls @see WindowClass class of the window, used for identification and grouping
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   327
* @param *widget @see OldWidget pointer to the window layout and various elements
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   328
* @return @see BaseWindow pointer of the newly created window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   329
*/
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   330
/*static*/ BaseWindow* BaseWindow::Allocate(int x, int y, int width, int height, WindowProc *proc, WindowClass cls, const OldWidget *widget)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   331
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   332
	WindowDesc desc = {x, y, width, height, cls, WC_NONE, 0, widget, proc};
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   333
	return new BaseWindow(&desc, 0);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   334
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   335
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   336
/**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   337
* Open a new window.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   338
* @param *desc The pointer to the WindowDesc to be created
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   339
* @param window_number the window number of the new window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   340
* @return @see BaseWindow pointer of the newly created window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   341
*/
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   342
BaseWindow *BaseWindow::AllocateFront(const WindowDesc *desc, int window_number)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   343
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   344
	if (BaseWindow::BringToFrontById(desc->cls, window_number) != NULL) return NULL;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   345
	BaseWindow *w = Allocate(desc, window_number);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   346
	return w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   347
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   348
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   349
static Point GetAutoPlacePosition(int width, int height);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   350
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   351
/*static*/ BaseWindow* BaseWindow::Allocate(const WindowDesc *desc, int window_number)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   352
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   353
	Point pt;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   354
	BaseWindow *w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   355
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   356
	/* By default position a child window at an offset of 10/10 of its parent.
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   357
	 * However if it falls too extremely outside window positions, reposition
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   358
	 * it to an automatic place */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   359
	if (desc->parent_cls != WC_MAIN_WINDOW &&
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   360
		(w = BaseWindow::FindById(desc->parent_cls, window_number)) != NULL &&
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   361
		w->Left() < _screen.width - 20 && w->Left() > -60 && w->Top() < _screen.height - 20) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   362
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   363
			pt.x = w->Left() + 10;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   364
			if (pt.x > _screen.width + 10 - desc->width) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   365
				pt.x = (_screen.width + 10 - desc->width) - 20;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   366
			}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   367
			pt.y = w->Top() + 10;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   368
	} else {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   369
		switch (desc->left) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   370
			case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   371
				w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   372
				pt.x = (w->Left() + w->Width()) - desc->width;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   373
													}	break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   374
			case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   375
				pt.x = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0)->Left();
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   376
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   377
			case WDP_AUTO: /* Find a good automatic position for the window */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   378
				pt = GetAutoPlacePosition(desc->width, desc->height);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   379
				goto allocate_window;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   380
			case WDP_CENTER: /* Centre the window horizontally */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   381
				pt.x = (_screen.width - desc->width) / 2;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   382
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   383
			default:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   384
				pt.x = desc->left;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   385
				if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   386
		}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   387
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   388
		switch (desc->top) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   389
			case WDP_CENTER: /* Centre the window vertically */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   390
				pt.y = (_screen.height - desc->height) / 2;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   391
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   392
				/* WDP_AUTO sets the position at once and is controlled by desc->left.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   393
				* Both left and top must be set to WDP_AUTO */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   394
			case WDP_AUTO:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   395
				NOT_REACHED();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   396
				assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   397
				/* fallthrough */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   398
			default:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   399
				pt.y = desc->top;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   400
				if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   401
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   402
		}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   403
	}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   404
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   405
allocate_window:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   406
	WindowDesc d2 = *desc;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   407
	d2.left = pt.x;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   408
	d2.top  = pt.y;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   409
	w = new BaseWindow(&d2, window_number);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   410
	return w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   411
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   412
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   413
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   414
/* Open a new window.
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   415
* This function is called from AllocateWindow() or AllocateWindowDesc()
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   416
* See descriptions for those functions for usage
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   417
* See AllocateWindow() for description of arguments.
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   418
* Only addition here is window_number, which is the window_number being assigned to the new window
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   419
*/
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   420
//BaseWindow::BaseWindow(
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   421
//							 int x, int y, int w, int h,
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   422
//							 WindowProc *proc, WindowClass cls, const OldWidget *widget, int wnd_number)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   423
//{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   424
//	ZeroInit();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   425
//
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   426
//	window_class = cls;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   427
//	flash_timeout = 3; // just opened windows have a white border
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   428
//	caption_color = 0xFF;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   429
//	left = x;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   430
//	top = y;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   431
//	width = w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   432
//	height = h;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   433
//	wndproc = proc;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   434
//	this->AssignWidget(widget);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   435
//	resize.width = width;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   436
//	resize.height = height;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   437
//	resize.step_width = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   438
//	resize.step_height = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   439
//	window_number = wnd_number;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   440
//
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   441
//	/* add our new window into z-order list */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   442
//	BaseWindow::s_list.Add(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   443
//
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   444
//	SetDirty();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   445
//	CallEventNP(WE_CREATE);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   446
//}
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   447
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   448
/*virtual*/ BaseWindow* BaseWindow::GetWindow()
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   449
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   450
	return this;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   451
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   452
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   453
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   454
/** Find the BaseWindow whose parent pointer points to this window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   455
* @return return a BaseWindow pointer that is the child of w, or NULL otherwise */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   456
BaseWindow* BaseWindow::FindChild() const
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   457
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   458
	BaseWindow *v;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   459
	FOR_ALL_WINDOWS(v) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   460
		if (v->parent == this) return v;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   461
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   462
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   463
	return NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   464
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   465
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   466
void BaseWindow::SetDirty() const
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   467
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   468
	if (this == NULL) return;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   469
	SetDirtyBlocks(Left(), Top(), Left() + Width(), Top() + Height());
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   470
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   471
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   472
/*virtual*/ void BaseWindow::FinalRelease()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   473
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   474
	assert(m_is_closing); // should be closed already
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   475
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   476
	/* Delete any children a window might have in a head-recursive manner */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   477
	BaseWindow *v = FindChild();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   478
	if (v != NULL) v->Close();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   479
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   480
	if (_thd.place_mode != VHM_NONE &&
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   481
		_thd.window_class == window_class &&
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   482
		_thd.window_number == window_number) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   483
			ResetObjectToPlace();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   484
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   485
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   486
	if (viewport != NULL) DeleteWindowViewport(this);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   487
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   488
	SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   489
	free(widget);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   490
	widget = NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   491
	widget_count = 0;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   492
	parent = NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   493
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   494
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   495
/*virtual*/ void BaseWindow::Close()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   496
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   497
	super::Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   498
	CallEventNP(WE_DESTROY);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   499
	s_list.Remove(this);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   500
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   501
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   502
/*virtual*/ bool BaseWindow::IsVital()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   503
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   504
	WindowClass wc = window_class;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   505
	return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   506
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   507
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   508
/*static*/ BaseWindow* BaseWindow::Get(WindowList::Iterator it)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   509
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   510
	return (it != s_list.m_list.end()) ? (*it).w : NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   511
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   512
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   513
/** Do a search for a window at specific coordinates. For this we start
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   514
 * at the topmost window, obviously and work our way down to the bottom
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   515
 * @return a pointer to the found window if any, NULL otherwise */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   516
/*static*/ BaseWindow *BaseWindow::FindFromPt(int x, int y)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   517
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   518
	return Get(s_list.FindFromPt(x, y));
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   519
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   520
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   521
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   522
/*static*/ BaseWindow* BaseWindow::FindById(WindowClass cls, WindowNumber num)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   523
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   524
	return Get(s_list.FindById(cls, num));
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   525
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   526
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   527
/*static*/ void BaseWindow::SetDirtyById(WindowClass cls, WindowNumber num)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   528
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   529
	BaseWindow *w = FindById(cls, num);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   530
	if (w != NULL) w->SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   531
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   532
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   533
void CDECL BaseWindow::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   534
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   535
	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
   536
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   537
	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
   538
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   539
	while (widgets != WIDGET_LIST_END) {
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6245
diff changeset
   540
		SetWidgetDisabledState(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
   541
		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
   542
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   543
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   544
	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
   545
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   546
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   547
void CDECL BaseWindow::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...)
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   548
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   549
	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
   550
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   551
	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
   552
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   553
	while (widgets != WIDGET_LIST_END) {
6250
5135b200b376 (svn r8718) [cpp_gui] -Codechange: SetWindowWidgetHiddenState(), HideWindowWidget(), ShowWindowWidget() and IsWindowWidgetHidden() turned into Window methods
KUDr
parents: 6249
diff changeset
   554
		SetWidgetHiddenState(widgets, hidden_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
   555
		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
   556
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   557
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   558
	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
   559
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   560
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   561
void CDECL BaseWindow::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   562
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   563
	va_list wdg_list;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   564
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   565
	va_start(wdg_list, widgets);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   566
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   567
	while (widgets != WIDGET_LIST_END) {
6251
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   568
		SetWidgetLoweredState(widgets, lowered_stat);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   569
		widgets = va_arg(wdg_list, int);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   570
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   571
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   572
	va_end(wdg_list);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   573
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   574
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   575
void BaseWindow::RaiseButtons()
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   576
{
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
   577
	uint i;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   578
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   579
	for (i = 0; i < widget_count; i++) {
6251
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   580
		if (IsWidgetLowered(i)) {
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   581
			RaiseWidget(i);
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
   582
			this->InvalidateWidget(i);
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   583
		}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   584
	}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   585
}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   586
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   587
void BaseWindow::HandleButtonClick(byte widget)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
6251
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   589
	LowerWidget(widget);
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   590
	autorepeat_timeout = 5;
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   591
	InvalidateWidget(widget);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   592
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   593
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   594
/** On clicking on a window, make it the frontmost window of all. However
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   595
* there are certain windows that always need to be on-top; these include
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   596
* - Toolbar, Statusbar (always on)
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   597
* - New window, Chatbar (only if open)
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   598
* The window is marked dirty for a repaint if the window is actually moved
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   599
* @param w window that is put into the foreground
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   600
* @return pointer to the window, the same as the input pointer
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   601
*/
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   602
void BaseWindow::BringToFront()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   603
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   604
	WindowPtr wp = this;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   605
	WindowList::Iterator it = BaseWindow::s_list.Find(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   606
	BaseWindow::s_list.Remove(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   607
	BaseWindow::s_list.Add(this);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   608
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   609
	SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   610
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   611
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   612
/** Find a window and make it the top-window on the screen. The window
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   613
* gets a white border for a brief period of time to visualize its "activation"
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   614
* @param cls WindowClass of the window to activate
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   615
* @param num WindowNumber of the window to activate
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   616
* @return a pointer to the window thus activated */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   617
/*static*/ BaseWindow* BaseWindow::BringToFrontById(WindowClass cls, WindowNumber num)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   618
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   619
	BaseWindow *w = FindById(cls, num);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   620
	if (w != NULL) {
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   621
		w->flash_timeout = 3;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   622
		w->BringToFront();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   623
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   624
	return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   625
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   626
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   627
static bool _dragging_window;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   628
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   629
void BaseWindow::StartDrag()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   630
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   631
	flags4 |= WF_DRAGGING;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   632
	_dragging_window = true;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   633
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   634
	_drag_delta.x = Left() - _cursor.pos.x;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   635
	_drag_delta.y = Top()  - _cursor.pos.y;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   636
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   637
	BringToFront();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   638
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   639
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   640
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   641
bool BaseWindow::ContinueDrag()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   642
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   643
	const OldWidget *t = &widget[1]; // the title bar ... ugh
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   644
	const BaseWindow *v;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   645
	int x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   646
	int y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   647
	int nx;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   648
	int ny;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   649
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   650
	// Stop the dragging if the left mouse button was released
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   651
	if (!_left_button_down) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   652
		flags4 &= ~WF_DRAGGING;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   653
		_dragging_window = false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   654
		return false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   655
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   656
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   657
	SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   658
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   659
	x = _cursor.pos.x + _drag_delta.x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   660
	y = _cursor.pos.y + _drag_delta.y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   661
	nx = x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   662
	ny = y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   663
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   664
	if (_patches.window_snap_radius != 0) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   665
		BaseWindow *v;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   666
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   667
		int hsnap = _patches.window_snap_radius;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   668
		int vsnap = _patches.window_snap_radius;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   669
		int delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   670
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   671
		FOR_ALL_WINDOWS(v) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   672
			if (v == this) continue; // Don't snap at yourself
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   673
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   674
			if (y + Height() > v->Top() && y < v->Top() + v->Height()) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   675
				// Your left border <-> other right border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   676
				delta = abs(v->Left() + v->Width() - x);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   677
				if (delta <= hsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   678
					nx = v->Left() + v->Width();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   679
					hsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   680
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   681
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   682
				// Your right border <-> other left border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   683
				delta = abs(v->Left() - x - Width());
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   684
				if (delta <= hsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   685
					nx = v->Left() - Width();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   686
					hsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   687
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   688
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   689
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   690
			if (Top() + Height() >= v->Top() && Top() <= v->Top() + v->Height()) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   691
				// Your left border <-> other left border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   692
				delta = abs(v->Left() - x);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   693
				if (delta <= hsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   694
					nx = v->Left();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   695
					hsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   696
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   697
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   698
				// Your right border <-> other right border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   699
				delta = abs(v->Left() + v->Width() - x - Width());
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   700
				if (delta <= hsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   701
					nx = v->Left() + v->Width() - Width();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   702
					hsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   703
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   704
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   705
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   706
			if (x + Width() > v->Left() && x < v->Left() + v->Width()) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   707
				// Your top border <-> other bottom border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   708
				delta = abs(v->Top() + v->Height() - y);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   709
				if (delta <= vsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   710
					ny = v->Top() + v->Height();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   711
					vsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   712
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   713
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   714
				// Your bottom border <-> other top border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   715
				delta = abs(v->Top() - y - Height());
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   716
				if (delta <= vsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   717
					ny = v->Top() - Height();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   718
					vsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   719
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   720
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   721
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   722
			if (Left() + Width() >= v->Left() && Left() <= v->Left() + v->Width()) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   723
				// Your top border <-> other top border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   724
				delta = abs(v->Top() - y);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   725
				if (delta <= vsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   726
					ny = v->Top();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   727
					vsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   728
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   729
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   730
				// Your bottom border <-> other bottom border
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   731
				delta = abs(v->Top() + v->Height() - y - Height());
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   732
				if (delta <= vsnap) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   733
					ny = v->Top() + v->Height() - Height();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   734
					vsnap = delta;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   735
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   736
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   737
		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   738
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   739
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   740
	// Make sure the window doesn't leave the screen
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   741
	// 13 is the height of the title bar
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   742
	nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   743
	ny = clamp(ny, 0, _screen.height - 13);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   744
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   745
	// Make sure the title bar isn't hidden by behind the main tool bar
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   746
	v = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   747
	if (v != NULL) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   748
		int v_bottom = v->Top() + v->Height();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   749
		int v_right = v->Left() + v->Width();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   750
		if (ny + t->top >= v->Top() && ny + t->top < v_bottom) {
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   751
			if ((v->Left() < 13 && nx + t->left < v->Left()) ||
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   752
				(v_right > _screen.width - 13 && nx + t->right > v_right)) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   753
					ny = v_bottom;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   754
			} else {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   755
				if (nx + t->left > v->Left() - 13 &&
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   756
					nx + t->right < v_right + 13) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   757
						if (Top() >= v_bottom) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   758
							ny = v_bottom;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   759
						} else if (Left() < nx) {
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   760
							nx = v->Left() - 13 - t->left;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   761
						} else {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   762
							nx = v_right + 13 - t->right;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   763
						}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   764
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   765
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   766
		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   767
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   768
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   769
	if (viewport != NULL) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   770
		viewport->left += nx - Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   771
		viewport->top  += ny - Top();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   772
	}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   773
	SetTopLeft(Point16(nx, ny));
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   774
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   775
	SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   776
	return false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   777
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   778
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   779
void BaseWindow::StartSizing()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   780
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   781
	flags4 |= WF_SIZING;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   782
	_dragging_window = true;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   783
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   784
	_drag_delta.x = _cursor.pos.x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   785
	_drag_delta.y = _cursor.pos.y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   786
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   787
	BringToFront();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   788
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   789
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   790
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   791
bool BaseWindow::ContinueSizing()
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   792
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   793
	WindowEvent e;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   794
	int x, y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   795
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   796
	/* Stop the sizing if the left mouse button was released */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   797
	if (!_left_button_down) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   798
		flags4 &= ~WF_SIZING;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   799
		SetDirty();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   800
		_dragging_window = false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   801
		return false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   802
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   803
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   804
	x = _cursor.pos.x - _drag_delta.x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   805
	y = _cursor.pos.y - _drag_delta.y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   806
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   807
	/* X and Y has to go by step.. calculate it.
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   808
	* The cast to int is necessary else x/y are implicitly casted to
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   809
	* unsigned int, which won't work. */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   810
	if (resize.step_width > 1) x -= x % (int)resize.step_width;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   811
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   812
	if (resize.step_height > 1) y -= y % (int)resize.step_height;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   813
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   814
	/* Check if we don't go below the minimum set size */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   815
	if (Width() + x < (int)resize.width)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   816
		x = resize.width - Width();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   817
	if (Height() + y < (int)resize.height)
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   818
		y = resize.height - Height();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   819
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   820
	/* BaseWindow already on size */
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   821
	if (x == 0 && y == 0) return false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   822
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   823
	/* Now find the new cursor pos.. this is NOT _cursor, because
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   824
	we move in steps. */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   825
	_drag_delta.x += x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   826
	_drag_delta.y += y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   827
6240
8d4ea2d6befc (svn r8699) [cpp_gui] -Cleanup: removed the word Window from some Window method names as just being Winddow methods indicates that it's working on a window
bjarni
parents: 6239
diff changeset
   828
	/* Resize sets both pre- and after-size to dirty for redrawal */
8d4ea2d6befc (svn r8699) [cpp_gui] -Cleanup: removed the word Window from some Window method names as just being Winddow methods indicates that it's working on a window
bjarni
parents: 6239
diff changeset
   829
	this->Resize(x, y);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   830
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   831
	e.event = WE_RESIZE;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   832
	e.we.sizing.size.x = x + Width();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   833
	e.we.sizing.size.y = y + Height();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   834
	e.we.sizing.diff.x = x;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   835
	e.we.sizing.diff.y = y;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   836
	wndproc(this, &e);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   837
	return false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   838
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   839
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   840
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   841
/*static*/ bool BaseWindow::HandleWindowDragging(void)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   842
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   843
	// Get out immediately if no window is being dragged at all.
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   844
	if (!_dragging_window) return true;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   845
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   846
	// Otherwise find the window...
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   847
	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   848
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   849
		if (w->flags4 & WF_DRAGGING) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   850
			return w->ContinueDrag();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   851
		} else if (w->flags4 & WF_SIZING) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   852
			return w->ContinueSizing();
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   853
		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   854
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   855
	_dragging_window = false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   856
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   859
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   860
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   861
void BaseWindow::DispatchLeftClickEvent(int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   862
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
	WindowEvent e;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   864
	const OldWidget *wi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   866
	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
   867
	e.we.click.pt.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
	e.event = WE_CLICK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   870
	if (desc_flags & WDF_DEF_WIDGET) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   871
		e.we.click.widget = GetWidgetFromPos(x, y);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   872
		if (e.we.click.widget < 0) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   873
			OldWndProc(&e); // try to handle it by new window infrastructure
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   874
			return; // exit if clicked outside of widgets
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   875
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   876
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
   877
		/* don't allow any interaction if the button has been disabled */
6248
24583caadfee (svn r8716) [cpp_gui] -Codechange: IsWindowWidgetDisabled() turned into Window method
KUDr
parents: 6246
diff changeset
   878
		if (IsWidgetDisabled(e.we.click.widget)) return;
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 211
diff changeset
   879
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   880
		wi = &widget[e.we.click.widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   882
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   883
			/* special widget handling for buttons*/
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   884
			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
   885
				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
   886
				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
   887
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   888
					HandleButtonClick(e.we.click.widget);
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   889
					break;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   890
				default:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   891
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
			}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   893
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   894
			ScrollbarClickHandler(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
   895
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   897
		if (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
   898
			if (e.we.click.widget == 0) { /* 'X' */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   899
				Close();
984
a50e131688d2 (svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents: 983
diff changeset
   900
				return;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   901
			}
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   902
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   903
			if (e.we.click.widget == 1) { /* 'Title bar' */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   904
				StartDrag();
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
   905
				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
   906
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   908
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   909
		if (desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   910
			StartSizing();
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   911
			InvalidateWidget(e.we.click.widget);
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   912
			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
   913
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   914
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   915
		if (desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   916
			flags4 ^= WF_STICKY;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   917
			InvalidateWidget(e.we.click.widget);
1112
32f3e7a98095 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   918
			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
   919
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
	}
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
   921
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   922
	wndproc(this, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   925
void BaseWindow::DispatchRightClickEvent(int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   926
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	WindowEvent e;
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   928
	e.event = WE_RCLICK;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   929
	e.we.click.pt.x = x;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   930
	e.we.click.pt.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	/* default tooltips handler? */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   933
	if (desc_flags & WDF_STD_TOOLTIPS) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   934
		e.we.click.widget = GetWidgetFromPos(x, y);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   935
		if (e.we.click.widget < 0) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   936
			OldWndProc(&e); // try to handle it by new window infrastructure
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   937
			return; // exit if clicked outside of widgets
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   938
		}
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   939
		if (widget[e.we.click.widget].tooltips != 0) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   940
			GuiShowTooltips(widget[e.we.click.widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   945
	wndproc(this, &e);
0
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
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
   948
/** 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
   949
 * compatible scrollbars if the mouse is pointed over the bar or its contents
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   950
 * @param *w BaseWindow
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
   951
 * @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
   952
 * @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
   953
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   954
void BaseWindow::DispatchMouseWheelEvent(int widget_idx, int wheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   956
	const OldWidget *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
   957
	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
   958
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   959
	if (widget_idx < 0) return;
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
   960
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   961
	wi1 = &widget[widget_idx];
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   962
	wi2 = &widget[widget_idx + 1];
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   963
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
   964
	/* 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
   965
	 * 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
   966
	 * 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
   967
	 * not happening until someone rewrites the whole widget-code */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   968
	if ((sb = &vscroll,  wi1->type == WWT_SCROLLBAR)  || (sb = &vscroll2, wi1->type == WWT_SCROLL2BAR)  ||
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   969
			(sb = &vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &vscroll, wi2->type == WWT_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
   970
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
   971
		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
   972
			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
   973
			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
   974
				sb->pos = pos;
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   975
				SetDirty();
982
be834034b331 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   976
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   981
static void DrawOverlappedWindow(WindowList::Iterator wit, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   983
	BaseWindow *w = (*wit).w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   984
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   985
	for (WindowList::Iterator vit = wit; ++vit != BaseWindow::s_list.m_list.end(); ) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   986
		const BaseWindow *v = (*vit).w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   987
		int x;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   988
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   989
		if (right > v->Left() &&
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   990
				bottom > v->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   991
				left < v->Left() + v->Width() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   992
				top  < v->Top() + v->Height()) {
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   993
			if (left < (x = v->Left())) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   994
				DrawOverlappedWindow(wit, left, top, x, bottom);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   995
				DrawOverlappedWindow(wit, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
   999
			if (right > (x = v->Left() + v->Width())) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1000
				DrawOverlappedWindow(wit, left, top, x, bottom);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1001
				DrawOverlappedWindow(wit, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1002
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1003
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1005
			if (top < (x = v->Top())) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1006
				DrawOverlappedWindow(wit, left, top, right, x);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1007
				DrawOverlappedWindow(wit, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
				return;
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
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1011
			if (bottom > (x = v->Top() + v->Height())) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1012
				DrawOverlappedWindow(wit, left, top, right, x);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1013
				DrawOverlappedWindow(wit, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
			return;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
	{
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1022
		DrawPixelInfo *dp = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
		dp->width = right - left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
		dp->height = bottom - top;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1025
		dp->left = left - w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1026
		dp->top = top - w->Top();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
		dp->pitch = _screen.pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
		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
  1029
		dp->zoom = 0;
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1030
		w->CallEventNP(WE_PAINT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1034
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1035
{
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1036
	DrawPixelInfo bk;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1037
	_cur_dpi = &bk;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1038
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1039
	const BaseWindow *w = NULL;
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1040
	FOR_ALL_WINDOWS(w) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1041
		if (right > w->Left() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1042
			bottom > w->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1043
			left < w->Left() + w->Width() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1044
			top < w->Top() + w->Height()) {
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1045
				DrawOverlappedWindow(it, left, top, right, bottom);
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1046
		}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1047
	}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1048
}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1049
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1050
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1051
void BaseWindow::CallEventNP(int event)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
	WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1054
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	e.event = event;
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1056
	wndproc(this, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1059
void BaseWindow::OldWndProc(WindowEvent *e)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1060
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1061
	gui::EventBase *evt = NULL;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1062
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1063
	switch(e->event) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1064
		case WE_CREATE:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1065
			evt = new gui::EventT<gui::EVT_CREATE>();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1066
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1067
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1068
		case WE_DESTROY:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1069
			evt = new gui::EventT<gui::EVT_DESTROY>();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1070
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1071
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1072
		case WE_PAINT:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1073
			evt = new gui::EventT<gui::EVT_PAINT>();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1074
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1075
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1076
		case WE_KEYPRESS:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1077
			evt = new gui::EventT<gui::EVT_KEYPRESS>(e->we.keypress.cont, e->we.keypress.key, e->we.keypress.keycode);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1078
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1079
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1080
		case WE_CLICK:
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
  1081
			evt = new gui::EventT<gui::EVT_LBUTTON_DOWN>(e->we.click.pt);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1082
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1083
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1084
		case WE_RCLICK:
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
  1085
			evt = new gui::EventT<gui::EVT_RBUTTON_DOWN>(e->we.click.pt);
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1086
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1087
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1088
		default:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1089
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1090
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1091
	if (evt == NULL) return;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1092
	DispatchEvent(*evt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1093
	delete evt;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1094
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1095
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1096
/*static*/ void BaseWindow::DefaultWndProc(BaseWindow *w, WindowEvent *e)
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1097
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1098
	w->OldWndProc(e);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1099
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1100
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1101
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1102
/** Find the z-value of a window. A window must already be open
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1103
 * or the behavior is undefined but function should never fail
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1104
 * @return the window that matches it */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1105
//WindowList::Iterator FindWindowZPosition(const BaseWindow *w)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1106
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1107
//	BaseWindow *wz;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1108
//	FOR_ALL_WINDOWS(wz) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1109
//		if (wz == w) return it;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1110
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1111
//
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1112
//	DEBUG(misc, 3, "BaseWindow (cls %d, number %d) is not open, probably removed by recursive calls",
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1113
//		w->window_class, w->window_number);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1114
//	return BaseWindow::s_list.m_list.end();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1115
//}
5666
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
  1116
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1117
//BaseWindow *FindWindowById(WindowClass cls, WindowNumber number)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1118
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1119
//	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1120
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1121
//	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1122
//		if (w->window_class == cls && w->window_number == number) return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1123
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1124
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1125
//	return NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1126
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1130
	BaseWindow *w = BaseWindow::FindById(cls, number);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1131
	if (w != NULL) w->Close();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1132
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
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
  1134
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
  1135
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1136
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
  1137
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
  1138
	/* 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
  1139
	 * 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
  1140
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1141
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1142
	FOR_ALL_WINDOWS(w) {
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
  1143
		if (w->window_class == cls) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1144
			w->Close();
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
  1145
			goto restart_search;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1146
		}
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
  1147
	}
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
  1148
}
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
  1149
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1150
/** 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
  1151
 * 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
  1152
 * 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
  1153
 * @param id PlayerID player identifier */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1154
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
  1155
{
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
  1156
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
  1157
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
  1158
	/* 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
  1159
	 * 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
  1160
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1161
	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1162
	FOR_ALL_WINDOWS(w) {
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1163
		if (w->caption_color == id) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1164
			w->Close();
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
  1165
			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
  1166
		}
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
  1167
	}
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
  1168
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1169
	/* 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
  1170
	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
  1171
}
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
  1172
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1173
/** 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
  1174
 * 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
  1175
 * 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
  1176
 * @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
  1177
 * @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
  1178
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
  1179
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1180
	BaseWindow *w = NULL;
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
  1181
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1182
	FOR_ALL_WINDOWS(w) {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1183
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
  1184
		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
  1185
		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
  1186
		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
  1187
		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
  1188
		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
  1189
		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
  1190
		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
  1191
		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
  1192
		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
  1193
		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
  1194
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
  1195
		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
  1196
	}
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
  1197
}
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
  1198
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1199
/** 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
  1200
 * 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
  1201
 * - 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
  1202
 * - 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
  1203
 * - 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
  1204
 * @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
  1205
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1206
//static BaseWindow *FindDeletableWindow(void)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1207
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1208
//	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1209
//	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1210
//		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1211
//			return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1212
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1213
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1214
//	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1215
//		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1216
//			return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1217
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1218
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1219
//	return NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1220
//}
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
  1221
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1222
/** 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
  1223
 * restriction a bit by allowing to delete sticky windows. Keep important/vital
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1224
 * windows intact (Main window, Toolbar, Statusbar, News BaseWindow, Chatbar)
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1225
 * 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
  1226
 * @see FindDeletableWindow()
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1227
 * @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
  1228
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1229
//static BaseWindow *ForceFindDeletableWindow(void)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1230
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1231
//	BaseWindow* const *wz;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1232
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1233
//	for (wz = _z_windows;; wz++) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1234
//		BaseWindow *w = *wz;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1235
//		assert(wz < _last_z_window);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1236
//		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1237
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1238
//}
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
  1239
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1240
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1241
bool BaseWindow::IsOfPrototype(const OldWidget *widgets) const
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1242
{
6239
925a1bba771f (svn r8697) [cpp_gui] -Codechange: changed IsWindowOfPrototype() is a Window method
bjarni
parents: 6238
diff changeset
  1243
	return (original_widget == widgets);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1244
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1245
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1246
/** Copies 'widget' to 'w->widget' to allow for resizable windows
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1247
 * @param w Window on which to attach the widget array
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1248
 * @param widget pointer of widget array to fill the window with */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1249
void BaseWindow::AssignWidget(const OldWidget *widget_array)
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1250
{
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1251
	original_widget = widget_array;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1252
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1253
	if (widget_array != NULL) {
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1254
		uint index = 1;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1255
		const OldWidget *wi;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1256
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1257
		for (wi = widget_array; wi->type != WWT_LAST; wi++) index++;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1258
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1259
		widget = ReallocT(widget, index);
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1260
		memcpy(widget, widget_array, sizeof(*widget) * index);
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1261
		widget_count = index - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1262
	} else {
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1263
		widget = NULL;
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1264
		widget_count = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1265
	}
867
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1268
//static BaseWindow *FindFreeWindow(void)
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1269
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1270
//	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1271
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1272
//	for (w = _windows; w < endof(_windows); w++) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1273
//		BaseWindow* const *wz;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1274
//		bool window_in_use = false;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1275
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1276
//		FOR_ALL_WINDOWS(wz) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1277
//			if (*wz == w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1278
//				window_in_use = true;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1279
//				break;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1280
//			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1281
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1282
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1283
//		if (!window_in_use) return w;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1284
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1285
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1286
//	assert(_last_z_window == endof(_z_windows));
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1287
//	return NULL;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1288
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1291
struct SizeRect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
	int left,top,width,height;
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1293
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
static SizeRect _awap_r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
static bool IsGoodAutoPlace1(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
	int right,bottom;
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
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	right = _awap_r.width + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
	bottom = _awap_r.height + top;
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
	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
  1308
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1310
	/* Make sure it is not obscured by any window. */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1311
	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1312
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1313
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1315
		if (right > w->Left() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1316
				w->Left() + w->Width() > left &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1317
				bottom > w->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1318
				w->Top() + w->Height() > top) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1319
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1320
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1321
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
static bool IsGoodAutoPlace2(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
	int width,height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
	width = _awap_r.width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
	height = _awap_r.height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1335
	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
  1336
	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
  1337
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1338
	/* Make sure it is not obscured by any window. */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1339
	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1340
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1341
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1343
		if (left + width > w->Left() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1344
				w->Left() + w->Width() > left &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1345
				top + height > w->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1346
				w->Top() + w->Height() > top) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1347
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1348
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1349
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1352
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1354
static Point GetAutoPlacePosition(int width, int height)
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1355
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1356
	Point pt;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1357
	BaseWindow *w = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1358
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	_awap_r.width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
	_awap_r.height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
	if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1364
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1365
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1367
		if (IsGoodAutoPlace1(w->Left() + w->Width() + 2, w->Top())) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1368
		if (IsGoodAutoPlace1(w->Left() - width - 2, w->Top())) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1369
		if (IsGoodAutoPlace1(w->Left(), w->Top() + w->Height() + 2)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1370
		if (IsGoodAutoPlace1(w->Left(), w->Top() - height - 2)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1371
		if (IsGoodAutoPlace1(w->Left() + w->Width() + 2, w->Top() + w->Height() - height)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1372
		if (IsGoodAutoPlace1(w->Left() - width - 2, w->Top() + w->Height() - height)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1373
		if (IsGoodAutoPlace1(w->Left() + w->Width() - width, w->Top() + w->Height() + 2)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1374
		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
  1375
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1376
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1377
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1378
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1380
		if (IsGoodAutoPlace2(w->Left() + w->Width() + 2, w->Top())) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1381
		if (IsGoodAutoPlace2(w->Left() - width - 2, w->Top())) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1382
		if (IsGoodAutoPlace2(w->Left(), w->Top() + w->Height() + 2)) goto ok_pos;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1383
		if (IsGoodAutoPlace2(w->Left(), w->Top() - height - 2)) goto ok_pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
		int left=0,top=24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1388
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
restart:;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1390
		FOR_ALL_WINDOWS(w) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1391
			if (w->Left() == left && w->Top() == top) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1397
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1398
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1402
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
ok_pos:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
	pt.x = _awap_r.left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	pt.y = _awap_r.top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1409
///**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1410
// * Open a new window.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1411
// * @param *desc The pointer to the WindowDesc to be created
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1412
// * @return @see BaseWindow pointer of the newly created window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1413
// */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1414
//BaseWindow *AllocateWindowDesc(const WindowDesc *desc)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1415
//{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1416
//	return LocalAllocateWindowDesc(desc, 0);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1417
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1419
void InitWindowSystem()
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
  1420
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
  1421
	IConsoleClose();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1422
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1423
	//memset(&_windows, 0, sizeof(_windows));
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1424
	//_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
  1425
	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
  1426
	_no_scroll = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1429
void UnInitWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1430
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1431
	BaseWindow::s_list.CloseAll();
5893
16a86ac09d80 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5860
diff changeset
  1432
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1433
//	BaseWindow **wz;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1434
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1435
//restart_search:
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1436
//	/* Delete all windows, reset z-array.
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1437
//	 *When we find the window to delete, we need to restart the search
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1438
//	 * as deleting this window could cascade in deleting (many) others
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1439
//	 * anywhere in the z-array. We call DeleteWindow() so that it can properly
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1440
//	 * release own alloc'd memory, which otherwise could result in memleaks */
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1441
//	FOR_ALL_WINDOWS(wz) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1442
//		DeleteWindow(*wz);
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1443
//		goto restart_search;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1444
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1445
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1446
//	assert(_last_z_window == _z_windows);
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1447
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1448
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1449
void ResetWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1450
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1451
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1452
	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
  1453
	_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
  1454
	_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
  1455
	_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
  1456
	_thd.new_pos.y = 0;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1457
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1458
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1459
static void DecreaseWindowCounters()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
{
6272
43637acd46b5 (svn r8963) [cpp_gui] -Fix: g++ 3.4.2 warning: 'w' might be used uninitialized in this function (glx)
KUDr
parents: 6271
diff changeset
  1461
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1462
	REVERSED_FOR_ALL_WINDOWS(w) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1463
		/* Unclick scrollbar buttons if they are pressed. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1466
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
		}
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1468
		w->CallEventNP(WE_MOUSELOOP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1471
	REVERSED_FOR_ALL_WINDOWS(w) {
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
  1472
		if (w->autorepeat_timeout > 0 && (--w->autorepeat_timeout) == 0) {
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1473
			w->CallEventNP(WE_TIMEOUT);
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1474
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1479
BaseWindow *GetCallbackWnd()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1481
	return BaseWindow::FindById(_thd.window_class, _thd.window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1484
static void HandlePlacePresize()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1486
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1489
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1490
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1491
	w = GetCallbackWnd();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1492
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1494
	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
  1495
	if (e.we.place.pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
	}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1499
	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
  1500
	e.event = WE_PLACE_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1504
static bool HandleDragDrop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1506
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1509
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1511
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1512
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
	w = GetCallbackWnd();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
	ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1517
	if (w != NULL) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1518
		/* send an event in client coordinates. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
		e.event = WE_DRAGDROP;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1520
		e.we.dragdrop.pt.x = _cursor.pos.x - w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1521
		e.we.dragdrop.pt.y = _cursor.pos.y - w->Top();
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6240
diff changeset
  1522
		e.we.dragdrop.widget = w->GetWidgetFromPos(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
  1523
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1528
static bool HandlePopupMenu()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1530
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1533
	if (!_popup_menu_active) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1535
	w = BaseWindow::FindById(WC_TOOLBAR_MENU, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1539
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1540
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
		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
  1543
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
		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
  1547
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
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
  1550
	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
  1551
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1555
static bool HandleMouseOver()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1556
{
6271
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1557
	Point ptGlobal(_cursor.pos.x, _cursor.pos.y);
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1558
	/* try if the event is being captured */
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1559
	gui::EvtMouseOver evt_capture(ptGlobal);
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1560
	if (gui::EventCaptureStack::HandleEvent(evt_capture)) {
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1561
		return true;
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1562
	}
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1563
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1564
	static WindowClass  last_cls;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1565
	static WindowNumber last_num;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1566
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1567
	BaseWindow *w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1568
	WindowEvent e;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1569
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1570
	BaseWindow *last_w = BaseWindow::FindById(last_cls, last_num);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1571
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1572
	w = BaseWindow::FindFromPt(_cursor.pos.x, _cursor.pos.y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1573
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1574
	/* We changed window, put a MOUSEOVER event to the last window */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1575
	if (last_w != NULL && last_w != w) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1576
		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
  1577
		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
  1578
		e.we.mouseover.pt.y = -1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1579
		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
  1580
	}
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1581
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1582
	if (w == NULL) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1583
		last_cls = WC_NONE;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1584
		last_num = -1;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1585
		return false;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1586
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1587
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1588
	last_cls = w->window_class;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1589
	last_num = w->window_number;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1590
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1591
	if (w != NULL) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1592
		/* send an event in client coordinates. */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1593
		e.event = WE_MOUSEOVER;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1594
		e.we.mouseover.pt.x = _cursor.pos.x - w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1595
		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
  1596
		if (w->widget != NULL) {
6241
6a7a41b0cd32 (svn r8702) [cpp_gui] -Codechange: changed the 3 window functions in widget.cpp into Window methods
bjarni
parents: 6240
diff changeset
  1597
			e.we.mouseover.widget = w->GetWidgetFromPos(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
  1598
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1599
		w->wndproc(w, &e);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1600
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1601
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1602
	/* Mouseover never stops execution */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1603
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1604
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1605
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1606
/** 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
  1607
 * 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
  1608
 * ensuring proper redrawal.
6308
646711c5feaa (svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
KUDr
parents: 6307
diff changeset
  1609
 * @param x delta x-size of changed window (positive if larger, etc.)
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1610
 * @param y delta y-size of changed window */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1611
void BaseWindow::Resize(int x, int y)
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1612
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1613
	OldWidget *wi;
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1614
	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
  1615
	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
  1616
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1617
	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
  1618
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1619
	this->SetDirty();
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1620
	for (wi = widget; wi->type != WWT_LAST; wi++) {
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1621
		/* Isolate the resizing flags */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1622
		byte rsizeflag = GB(wi->m_display_flags, 0, 4);
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1623
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1624
		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
  1625
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1626
		/* 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
  1627
		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
  1628
			wi->left += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1629
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1630
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1631
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1632
		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
  1633
			wi->right += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1634
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1635
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1636
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1637
		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
  1638
			wi->top += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1639
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1640
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1641
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1642
		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
  1643
			wi->bottom += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1644
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1645
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1646
	}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1647
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1648
	/* We resized at least 1 widget, so let's resize the window totally */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1649
	if (resize_width)  SetWidth(Width() + x);
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1650
	if (resize_height) SetHeight(Height() + y);
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1651
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1652
	SetDirty();
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1653
}
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1654
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1655
static bool HandleScrollbarScrolling()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
	int pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1661
	/* Get out quickly if no item is being scrolled */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1662
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1664
	/* Find the scrolling window */
6272
43637acd46b5 (svn r8963) [cpp_gui] -Fix: g++ 3.4.2 warning: 'w' might be used uninitialized in this function (glx)
KUDr
parents: 6271
diff changeset
  1665
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1666
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
		if (w->flags4 & WF_SCROLL_MIDDLE) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1668
			/* Abort if no button is clicked any more. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1669
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
				w->flags4 &= ~WF_SCROLL_MIDDLE;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1671
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1673
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1678
			} else if (w->flags4 & WF_SCROLL2){
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1679
				sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1680
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1686
			/* Find the item we want to move to and make sure it's inside bounds. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
			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
  1688
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
				sb->pos = pos;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1690
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1693
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1694
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1695
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1696
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1697
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1698
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1700
static bool HandleViewportScroll()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1701
{
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
  1702
	WindowEvent e;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1703
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1704
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1705
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1706
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1707
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1708
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1709
	w = BaseWindow::FindFromPt(_cursor.pos.x, _cursor.pos.y);
4335
18bc63352a17 (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1710
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1711
	if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
		_cursor.fix_at = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1713
		_scrolling_viewport = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1714
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1715
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1716
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1717
	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
  1718
		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
  1719
		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
  1720
	} 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
  1721
		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
  1722
		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
  1723
	}
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1724
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1725
	if (scrollwheel_scrolling) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1726
		/* We are using scrollwheels for scrolling */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1727
		e.we.scroll.delta.x = _cursor.h_wheel;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1728
		e.we.scroll.delta.y = _cursor.v_wheel;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1729
		_cursor.v_wheel = 0;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1730
		_cursor.h_wheel = 0;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1731
	}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1732
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
  1733
	/* 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
  1734
	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
  1735
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1737
	_cursor.delta.x = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1738
	_cursor.delta.y = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1739
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1742
/** Check if a window can be made top-most window, and if so do
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1743
 * it. If a window does not obscure any other windows, it will not
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1744
 * be brought to the foreground. Also if the only obscuring windows
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1745
 * are so-called system-windows, the window will not be moved.
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1746
 * The function will return false when a child window of this window is a
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1747
 * modal-popup; function returns a false and child window gets a white border
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1748
 * @param w BaseWindow to bring on-top
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1749
 * @return false if the window has an active modal child, true otherwise */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1750
static bool MaybeBringWindowToFront(BaseWindow *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
{
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1752
	bool bring_to_front = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1754
	if (w->window_class == WC_MAIN_WINDOW ||
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1755
			w->IsVital() ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1756
			w->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1757
			w->window_class == WC_DROPDOWN_MENU) {
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1758
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1759
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1761
	WindowList::Iterator wit = BaseWindow::s_list.Find(w);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1762
	for (WindowList::Iterator it = wit; it != BaseWindow::s_list.m_list.end(); it++) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1763
		BaseWindow *u = (*it).w;
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1764
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1765
		/* A modal child will prevent the activation of the parent window */
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1766
		if (u->parent == w && (u->desc_flags & WDF_MODAL)) {
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
  1767
			u->flash_timeout = 3;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1768
			u->SetDirty();
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1769
			return false;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1770
		}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1771
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1772
		if (u->window_class == WC_MAIN_WINDOW ||
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1773
				u->IsVital() ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1774
				u->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1775
				u->window_class == WC_DROPDOWN_MENU) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1776
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1777
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1778
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1779
		/* BaseWindow sizes don't interfere, leave z-order alone */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1780
		if (w->Left() + w->Width() <= u->Left() ||
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1781
				u->Left() + u->Width() <= w->Left() ||
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1782
				w->Top()  + w->Height() <= u->Top() ||
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1783
				u->Top() + u->Height() <= w->Top()) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1784
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1785
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1786
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1787
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
	}
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1789
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1790
	if (bring_to_front) w->BringToFront();
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1791
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1792
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1793
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1794
/** Send a message from one window to another. The receiving window is found by
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1795
 * @param w BaseWindow pointer pointing to the other window
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1796
 * @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
  1797
 * @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
  1798
 * @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
  1799
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1800
static void SendWindowMessageW(BaseWindow *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
  1801
{
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1802
	WindowEvent e;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1803
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1804
	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
  1805
	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
  1806
	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
  1807
	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
  1808
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1809
	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
  1810
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1811
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1812
/** Send a message from one window to another. The receiving window is found by
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1813
 * @param wnd_class see WindowClass class AND
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1814
 * @param wnd_num see WindowNumber number, mostly 0
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1815
 * @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
  1816
 * @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
  1817
 * @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
  1818
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1819
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam)
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1820
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1821
	BaseWindow *w = BaseWindow::FindById(wnd_class, wnd_num);
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1822
	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
  1823
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1824
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1825
/** 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
  1826
 * to ALL windows of the windowclass specified in the first parameter
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1827
 * @param wnd_class see WindowClass class
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1828
 * @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
  1829
 * @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
  1830
 * @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
  1831
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1832
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam)
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1833
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1834
	BaseWindow *w = NULL;
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1835
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1836
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1837
		if (w->window_class == wnd_class) SendWindowMessageW(w, 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
  1838
	}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1839
}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1840
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1841
/** Handle keyboard input.
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1842
 * @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
  1843
 * 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
  1844
void HandleKeypress(uint32 key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1845
{
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1846
	WindowEvent e;
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1847
	/* 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
  1848
	 * 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
  1849
	 * 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
  1850
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1851
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1852
	/*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1853
	* 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
  1854
	* 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
  1855
	* 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
  1856
	* 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
  1857
	*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1858
	* 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
  1859
	* 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
  1860
	*/
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1861
	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
  1862
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1863
	/* 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
  1864
	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
  1865
	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
  1866
	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
  1867
	e.we.keypress.cont = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1868
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1869
	/* check if we have a query string window open before allowing hotkeys */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1870
	if (BaseWindow::FindById(WC_QUERY_STRING,       0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1871
			BaseWindow::FindById(WC_SEND_NETWORK_MSG,   0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1872
			BaseWindow::FindById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1873
			BaseWindow::FindById(WC_CONSOLE,            0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1874
			BaseWindow::FindById(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
  1875
		query_open = true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1876
	}
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
  1877
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1878
	/* Call the event, start with the uppermost window. */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1879
	BaseWindow *w;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1880
	REVERSED_FOR_ALL_WINDOWS(w) {
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1881
		/* if a query window is open, only call the event for certain window types */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1882
		if (query_open &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1883
				w->window_class != WC_QUERY_STRING &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1884
				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
  1885
				w->window_class != WC_GENERATE_LANDSCAPE &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1886
				w->window_class != WC_CONSOLE &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1887
				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
  1888
			continue;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1889
		}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1890
		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
  1891
		if (!e.we.keypress.cont) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
	}
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
  1893
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1894
	if (e.we.keypress.cont) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1895
		BaseWindow *w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1896
		/* 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
  1897
		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
  1898
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1901
extern void UpdateTileSelection();
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1902
extern bool VpHandlePlaceSizingDrag();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1904
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
  1905
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1906
static void HandleAutoscroll()
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1907
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1908
	BaseWindow *w;
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1909
	ViewPort *vp;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1910
	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
  1911
	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
  1912
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1913
	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
  1914
		/* 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
  1915
		_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
  1916
		/* 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
  1917
		return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1918
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1919
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1920
	if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1921
		w = BaseWindow::FindFromPt(x, y);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1922
		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
  1923
		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
  1924
		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
  1925
			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
  1926
			y -= vp->top;
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1927
			/* here allows scrolling in both x and y axis */
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1928
#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
  1929
			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
  1930
				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
  1931
			} 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
  1932
				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
  1933
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1934
			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
  1935
				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
  1936
			} 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
  1937
				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
  1938
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1939
#undef scrollspeed
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1940
		}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1941
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1942
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1943
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1944
void MouseLoop(int click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1945
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
	int x,y;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1947
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
	ViewPort *vp;
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1949
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1950
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
	UpdateTileSelection();
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1954
	if (!VpHandlePlaceSizingDrag())      return;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1955
	if (!HandleDragDrop())               return;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1956
	if (!HandlePopupMenu())              return;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1957
	if (!BaseWindow::HandleWindowDragging()) return;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1958
	if (!HandleScrollbarScrolling())     return;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1959
	if (!HandleViewportScroll())         return;
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1960
	if (!HandleMouseOver())              return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1961
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1962
	x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1963
	y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1965
	if (click == 0 && mousewheel == 0 && !scrollwheel_scrolling) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1966
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1967
	w = BaseWindow::FindFromPt(x, y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1968
	if (w == NULL) return;
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1969
	if (!MaybeBringWindowToFront(w)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
	vp = IsPtInWindowViewport(w, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1971
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
  1972
	/* 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
  1973
	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
  1974
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
  1975
	if (mousewheel != 0) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1976
		if (_patches.scrollwheel_scrolling == 0) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1977
			/* Scrollwheel is in zoom mode. Make the zoom event. */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1978
			WindowEvent e;
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1979
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1980
			/* Send WE_MOUSEWHEEL event to window */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1981
			e.event = WE_MOUSEWHEEL;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1982
			e.we.wheel.wheel = mousewheel;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1983
			w->wndproc(w, &e);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1984
		}
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
  1985
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1986
		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1987
		if (vp == NULL) w->DispatchMouseWheelEvent(w->GetWidgetFromPos(x - w->Left(), y - w->Top()), 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
  1988
	}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1989
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1990
	if (vp != NULL) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  1991
		if (scrollwheel_scrolling) click = 2; // we are using the scrollwheel in a viewport, so we emulate right mouse button
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1992
		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
  1993
			case 1:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1994
				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
  1995
				if (_thd.place_mode != 0 &&
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  1996
						/* query button and place sign button work in pause mode */
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1997
						_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
  1998
						_cursor.sprite != SPR_CURSOR_SIGN &&
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  1999
						_pause_game != 0 &&
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2000
						!_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
  2001
					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
  2002
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2003
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2004
				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
  2005
					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
  2006
				} 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
  2007
					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
  2008
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2009
				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
  2010
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2011
			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
  2012
				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
  2013
					_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
  2014
					_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
  2015
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  2016
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
	} else {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  2019
		switch (click) {
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2020
			case 1: w->DispatchLeftClickEvent(x - w->Left(), y - w->Top());  break;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2021
			default:
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2022
				if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2023
				/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2024
				* Simulate a right button click so we can get started. */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6301
diff changeset
  2025
				/* fallthough */
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2026
			case 2: w->DispatchRightClickEvent(x - w->Left(), y - w->Top()); break;
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  2027
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2029
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2031
void HandleMouseEvents()
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  2032
{
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
  2033
	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
  2034
	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
  2035
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2036
	/*
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2037
	 * 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
  2038
	 * 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
  2039
	 * 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
  2040
	 * NOT change the _current_player here.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2041
	 *
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2042
	 * 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
  2043
	 * 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
  2044
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2045
	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
  2046
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  2047
	/* Mouse event? */
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
  2048
	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
  2049
	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
  2050
		_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
  2051
		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
  2052
		_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
  2053
	} 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
  2054
		_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
  2055
		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
  2056
		_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
  2057
	}
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
  2058
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
  2059
	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
  2060
	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
  2061
		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
  2062
		_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
  2063
		_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
  2064
	}
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
  2065
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
  2066
	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
  2067
}
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
  2068
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2069
void InputLoop()
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2070
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2071
	HandleMouseEvents();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2072
	HandleAutoscroll();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2073
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2074
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2075
void UpdateWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
{
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2077
	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
  2078
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2080
	BaseWindow *w;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2081
	if (t >= 100) {
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2082
		REVERSED_FOR_ALL_WINDOWS(w) {
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2083
			w->CallEventNP(WE_4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
	}
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2087
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2089
	REVERSED_FOR_ALL_WINDOWS(w) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2090
		if (w->flash_timeout > 0 && (--w->flash_timeout) == 0) w->SetDirty();
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  2091
		w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2096
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2097
		if (w->viewport != NULL) UpdateViewportPosition(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  2099
	DrawTextMessage();
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  2100
	/* Redraw mouse cursor in case it was hidden */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2102
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2105
int BaseWindow::GetMenuItemIndex(int x, int y) const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
{
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2107
	if ((x -= Left()) >= 0 && x < Width() && (y -= Top() + 1) >= 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
		y /= 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  2110
		if (y < WP(this, const menu_d).item_count &&
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  2111
				!HASBIT(WP(this, const menu_d).disabled_items, y)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
			return y;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2113
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2114
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2116
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2118
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2120
	BaseWindow *w = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2122
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2123
		if (w->window_class == cls && w->window_number == number) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2124
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2126
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2127
void BaseWindow::InvalidateWidget(byte widget_index) const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2128
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2129
	const OldWidget *wi = &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
  2130
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
  2131
	/* Don't redraw the window if the widget is invisible or of no-type */
6250
5135b200b376 (svn r8718) [cpp_gui] -Codechange: SetWindowWidgetHiddenState(), HideWindowWidget(), ShowWindowWidget() and IsWindowWidgetHidden() turned into Window methods
KUDr
parents: 6249
diff changeset
  2132
	if (wi->type == WWT_EMPTY || IsWidgetHidden(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
  2133
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2134
	SetDirtyBlocks(Left() + wi->left, Top() + wi->top, Left() + wi->right + 1, Top() + wi->bottom + 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2135
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2136
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2137
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
  2138
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2139
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2140
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2141
		if (w->window_class == cls && w->window_number == number) {
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  2142
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2147
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2149
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2150
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2151
		if (w->window_class == cls) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2154
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2155
void BaseWindow::InvalidateData()
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
  2156
{
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2157
	this->CallEventNP(WE_INVALIDATE_DATA);
6244
4b42fb40e6d2 (svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents: 6243
diff changeset
  2158
	this->SetDirty();
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2159
}
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
  2160
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2161
void InvalidateWindowData(WindowClass cls, WindowNumber number)
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2162
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2163
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2164
	FOR_ALL_WINDOWS(w) {
6244
4b42fb40e6d2 (svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents: 6243
diff changeset
  2165
		if (w->window_class == cls && w->window_number == number) w->InvalidateData();
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
  2166
	}
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
  2167
}
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
  2168
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
  2169
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
  2170
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2171
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2172
	FOR_ALL_WINDOWS(w) {
6244
4b42fb40e6d2 (svn r8710) [cpp_gui] -Codechange: yet another two functions are turned into Window methods
bjarni
parents: 6243
diff changeset
  2173
		if (w->window_class == cls) w->InvalidateData();
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2174
	}
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2175
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2176
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2177
void CallWindowTickEvent()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2178
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2179
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2180
	REVERSED_FOR_ALL_WINDOWS(w) {
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2181
		w->CallEventNP(WE_TICK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2182
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2183
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2184
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2185
void BaseWindow::DeleteNonVitalWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2186
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2187
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
  2188
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
  2189
	/* 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
  2190
	 * 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
  2191
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2192
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2193
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2194
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
				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
  2199
				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
  2200
				(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
  2201
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2202
			w->Close();
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
  2203
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2207
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  2208
/** 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
  2209
 * '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
  2210
 * 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
  2211
 * 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
  2212
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2213
void BaseWindow::DeleteAllNonVitalWindows()
763
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2214
{
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
  2215
	/* 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
  2216
	DeleteNonVitalWindows();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2217
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
  2218
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
  2219
	/* 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
  2220
	 * 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
  2221
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2222
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2223
	FOR_ALL_WINDOWS(w) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2224
		if (w->flags4 & WF_STICKY) {
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2225
			w->Close();
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
  2226
			goto restart_search;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2227
		}
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
  2228
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2229
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2230
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
  2231
/** Delete all always on-top windows to get an empty screen */
6298
c30fe89622df (svn r9119) [cpp_gui] -Sync with trunk (r9003:9100)
bjarni
parents: 6295
diff changeset
  2232
void BaseWindow::HideVitalWindows()
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2233
{
6158
ca1471170695 (svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
rubidium
parents: 5893
diff changeset
  2234
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
983
1be852dcdd4c (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2235
	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
  2236
	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
  2237
}
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
  2238
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2239
int PositionMainToolbar(BaseWindow *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2240
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2241
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2242
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2243
	if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2244
		w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2245
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2246
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2247
	switch (_patches.toolbar_pos) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2248
		case 1:  w->SetLeft((_screen.width - w->Width()) / 2); break;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2249
		case 2:  w->SetLeft(_screen.width - w->Width()); break;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2250
		default: w->SetLeft(0);
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2251
	}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2252
	SetDirtyBlocks(0, 0, _screen.width, w->Height()); // invalidate the whole top part
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2253
	return w->Left();
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2254
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2255
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2258
	BaseWindow *w = NULL;
6235
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  2259
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2260
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2261
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2262
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2263
			ViewPort *vp = w->viewport;
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2264
			w->SetSize(Point(neww, newh));
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2265
			vp->width = neww;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2266
			vp->height = newh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2267
			vp->virtual_width = neww << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2268
			vp->virtual_height = newh << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2269
			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
  2270
		}
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
  2271
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2272
		/* 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
  2273
		 * in a 'backup'-desc that the window should always be centred. */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2274
		switch (w->window_class) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2275
			case WC_MAIN_TOOLBAR:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2276
				top = w->Top();
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2277
				left = PositionMainToolbar(w); // changes toolbar orientation
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2278
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2279
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2280
			case WC_SELECT_GAME:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2281
			case WC_GAME_OPTIONS:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2282
			case WC_NETWORK_WINDOW:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2283
				top = (newh - w->Height()) >> 1;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2284
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2285
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2286
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2287
			case WC_NEWS_WINDOW:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2288
				top = newh - w->Height();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2289
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2290
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2291
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2292
			case WC_STATUS_BAR:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2293
				top = newh - w->Height();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2294
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2295
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2296
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2297
			case WC_SEND_NETWORK_MSG:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2298
				top = (newh - 26); // 26 = height of status bar + height of chat bar
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2299
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2300
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2301
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2302
			case WC_CONSOLE:
5143
a78072872bff (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2303
				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
  2304
				continue;
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2305
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2306
			default:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2307
				left = w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2308
				if (left + (w->Width() >> 1) >= neww) left = neww - w->Width();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2309
				top = w->Top();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2310
				if (top + (w->Height() >> 1) >= newh) top = newh - w->Height();
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2311
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2312
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2313
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2314
		if (w->viewport != NULL) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2315
			w->viewport->left += left - w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2316
			w->viewport->top += top - w->Top();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2317
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2318
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2319
		w->SetTopLeft(Point(left, top));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2320
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2321
}