src/window.cpp
author KUDr
Sat, 10 Mar 2007 04:52:01 +0000
branchcpp_gui
changeset 6294 6c74bf9cc5a4
parent 6293 59b7305f9a8b
child 6295 a88d8c2cff6e
permissions -rw-r--r--
(svn r9090) [cpp_gui] -Add: min/step/max sizes added to the widget (still not set/used)
-Codechange: order of some includes changed (solved min/max macro conflict with stl)
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
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    23
// delta between mouse cursor and upper left corner of dragged window
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    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);
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   278
		gui::CaptionBar *capt_bar = new gui::CaptionBar(this, -100, feature_flags, m_color);
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   279
		capt_bar->SetAnchors(PIN_LEFT | PIN_TOP | PIN_RIGHT);
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   280
		AddWidget(capt_bar);
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);
7072ee68c676 (svn r8997) [cpp_gui] -Codechange: common window features are now controlled by FeatureFlags enum.
KUDr
parents: 6282
diff changeset
   285
		AddWidget(resize_box);
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
6293
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   295
/*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
   296
{
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   297
	ClipDrawContext ctx(0, 0, Width(), Height());
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   298
	super::OnPaint(ev);
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   299
}
59b7305f9a8b (svn r9087) [cpp_gui] -Codechange: Window is now clipping its widgets in OnPaint()
KUDr
parents: 6289
diff changeset
   300
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   301
/**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   302
* 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
   303
* 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
   304
* 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
   305
* 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
   306
* @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
   307
* @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
   308
* @param width width in pixels of the window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   309
* @param height height in pixels of the window
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   310
* @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
   311
* @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
   312
* @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
   313
* @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
   314
*/
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   315
/*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
   316
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   317
	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
   318
	return new BaseWindow(&desc, 0);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   319
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   320
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   321
/**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   322
* Open a new window.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   323
* @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
   324
* @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
   325
* @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
   326
*/
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   327
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
   328
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   329
	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
   330
	BaseWindow *w = Allocate(desc, window_number);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   331
	return w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   332
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   333
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   334
static Point GetAutoPlacePosition(int width, int height);
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
/*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
   337
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   338
	Point pt;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   339
	BaseWindow *w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   340
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   341
	/* By default position a child window at an offset of 10/10 of its parent.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   342
	* However if it falls too extremely outside window positions, reposition
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   343
	* it to an automatic place */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   344
	if (desc->parent_cls != WC_MAIN_WINDOW &&
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   345
		(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
   346
		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
   347
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   348
			pt.x = w->Left() + 10;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   349
			if (pt.x > _screen.width + 10 - desc->width) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   350
				pt.x = (_screen.width + 10 - desc->width) - 20;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   351
			}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   352
			pt.y = w->Top() + 10;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   353
	} else {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   354
		switch (desc->left) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   355
			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
   356
				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
   357
				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
   358
													}	break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   359
			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
   360
				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
   361
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   362
			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
   363
				pt = GetAutoPlacePosition(desc->width, desc->height);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   364
				goto allocate_window;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   365
			case WDP_CENTER: /* Centre the window horizontally */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   366
				pt.x = (_screen.width - desc->width) / 2;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   367
				break;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   368
			default:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   369
				pt.x = desc->left;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   370
				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
   371
		}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   372
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   373
		switch (desc->top) {
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   374
			case WDP_CENTER: /* Centre the window vertically */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   375
				pt.y = (_screen.height - desc->height) / 2;
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
				/* 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
   378
				* 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
   379
			case WDP_AUTO:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   380
				NOT_REACHED();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   381
				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
   382
				/* fallthrough */
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.y = desc->top;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   385
				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
   386
				break;
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
	}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   389
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   390
allocate_window:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   391
	WindowDesc d2 = *desc;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   392
	d2.left = pt.x;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   393
	d2.top  = pt.y;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   394
	w = new BaseWindow(&d2, window_number);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   395
	return w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   396
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   397
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   398
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
   399
/* 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
   400
* 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
   401
* 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
   402
* 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
   403
* 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
   404
*/
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   405
//BaseWindow::BaseWindow(
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   406
//							 int x, int y, int w, int h,
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   407
//							 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
   408
//{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   409
//	ZeroInit();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   410
//
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   411
//	window_class = cls;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   412
//	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
   413
//	caption_color = 0xFF;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   414
//	left = x;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   415
//	top = y;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   416
//	width = w;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   417
//	height = h;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   418
//	wndproc = proc;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   419
//	this->AssignWidget(widget);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   420
//	resize.width = width;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   421
//	resize.height = height;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   422
//	resize.step_width = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   423
//	resize.step_height = 1;
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   424
//	window_number = wnd_number;
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
//	/* add our new window into z-order list */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   427
//	BaseWindow::s_list.Add(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   428
//
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   429
//	SetDirty();
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   430
//	CallEventNP(WE_CREATE);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   431
//}
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
   432
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   433
/*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
   434
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   435
	return this;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   436
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   437
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   438
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   439
/** 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
   440
* @parent w BaseWindow to find child of
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   441
* @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
   442
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
   443
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   444
	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
   445
	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
   446
		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
   447
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   448
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   449
	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
   450
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   451
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   452
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
   453
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   454
	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
   455
	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
   456
}
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
/*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
   459
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   460
	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
   461
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
   462
	/* 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
   463
	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
   464
	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
   465
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   466
	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
   467
		_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
   468
		_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
   469
			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
   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
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   472
	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
   473
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   474
	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
   475
	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
   476
	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
   477
	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
   478
	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
   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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   481
/*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
   482
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   483
	super::Close();
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   484
	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
   485
	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
   486
}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   488
/*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
   489
{
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
	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
   491
	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
   492
}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   494
/*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
   495
{
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
	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
   497
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   498
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   499
/** 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
   500
 * 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
   501
 * @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
   502
/*static*/ BaseWindow *BaseWindow::FindFromPt(int x, int y)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   503
{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   504
	return Get(s_list.FindFromPt(x, y));
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   505
}
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   506
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   507
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   508
/*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
   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 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
   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
/*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
   514
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   515
	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
   516
	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
   517
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   518
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   519
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
   520
{
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   521
	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
   522
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   523
	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
   524
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   525
	while (widgets != WIDGET_LIST_END) {
6246
2a4c2c4d66f0 (svn r8713) [cpp_gui] -Codechange: SetWindowWidgetDisabledState turned into Window method
KUDr
parents: 6245
diff changeset
   526
		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
   527
		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
   528
	}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   529
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   530
	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
   531
}
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
   532
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   533
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
   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) {
6250
5135b200b376 (svn r8718) [cpp_gui] -Codechange: SetWindowWidgetHiddenState(), HideWindowWidget(), ShowWindowWidget() and IsWindowWidgetHidden() turned into Window methods
KUDr
parents: 6249
diff changeset
   540
		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
   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::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
   548
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   549
	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
   550
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   551
	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
   552
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   553
	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
   554
		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
   555
		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
   556
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   557
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   558
	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
   559
}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   560
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   561
void BaseWindow::RaiseButtons()
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   562
{
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
   563
	uint i;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   564
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
   565
	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
   566
		if (IsWidgetLowered(i)) {
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   567
			RaiseWidget(i);
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
   568
			this->InvalidateWidget(i);
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   569
		}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   570
	}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   571
}
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   572
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   573
void BaseWindow::HandleButtonClick(byte widget)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
{
6251
cd413fa2e252 (svn r8720) [cpp_gui] -Codechange: SetWindowWidgetLoweredState(), ToggleWidgetLoweredState(), LowerWindowWidget(), RaiseWindowWidget() and IsWindowWidgetLowered() turned into Window methods
KUDr
parents: 6250
diff changeset
   575
	LowerWidget(widget);
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   576
	autorepeat_timeout = 5;
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   577
	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
   578
}
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
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   580
/** 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
   581
* 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
   582
* - 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
   583
* - 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
   584
* 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
   585
* @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
   586
* @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
   587
*/
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   588
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
   589
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   590
	WindowPtr wp = this;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   591
	WindowList::Iterator it = BaseWindow::s_list.Find(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   592
	BaseWindow::s_list.Remove(this);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   593
	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
   594
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
	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
   596
}
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
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
/** Find a window and make it the top-window on the screen. The 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
   599
* gets a white border for a brief period of time to visualize its
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
* "activation"
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
* @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
   602
/*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
   603
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   604
	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
   605
	if (w != NULL) {
6242
17609af8a1d1 (svn r8704) [cpp_gui] -Codechange: flash_timeout and autorepeat_timeout extracted from Window::flags4
KUDr
parents: 6241
diff changeset
   606
		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
   607
		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
   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
	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
   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
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
   613
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   614
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
   615
{
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
	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
   617
	_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
   618
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   619
	_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
   620
	_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
   621
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
	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
	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
   624
}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   626
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
   627
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   628
	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
   629
	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
   630
	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
   631
	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
   632
	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
   633
	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
   634
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   635
	// 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
   636
	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
   637
		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
   638
		_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
   639
		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
   640
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   641
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
	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
   643
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   644
	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
   645
	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
   646
	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
   647
	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
   648
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
	if (_patches.window_snap_radius != 0) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   650
		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
   651
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
		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
   653
		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
   654
		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
   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
		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
   657
			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
   658
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   659
			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
   660
				// 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
   661
				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
   662
				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
   663
					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
   664
					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
   665
				}
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
				// 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
   668
				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
   669
				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
   670
					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
   671
					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
   672
				}
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
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   674
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   675
			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
   676
				// 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
   677
				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
   678
				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
   679
					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
   680
					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
   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
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   683
				// 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
   684
				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
   685
				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
   686
					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
   687
					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
   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
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   690
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   691
			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
   692
				// 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
   693
				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
   694
				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
   695
					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
   696
					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
   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
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   699
				// 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
   700
				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
   701
				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
   702
					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
   703
					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
   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
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   706
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   707
			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
   708
				// 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
   709
				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
   710
				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
   711
					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
   712
					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
   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
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   715
				// 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
   716
				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
   717
				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
   718
					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
   719
					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
   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
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   722
		}
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
	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   724
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
	// 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
   726
	// 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
   727
	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
   728
	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
   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
	// 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
   731
	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
   732
	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
   733
		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
   734
		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
   735
		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
   736
			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
   737
				(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
   738
					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
   739
			} else {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   740
				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
   741
					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
   742
						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
   743
							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
   744
						} 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
   745
							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
   746
						} 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
   747
							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
   748
						}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   749
				}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   750
			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   751
		}
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
	}
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
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
	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
   755
		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
   756
		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
   757
	}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   758
	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
   759
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   760
	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
   761
	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
   762
}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   764
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
   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
	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
   767
	_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
   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
	_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
   770
	_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
   771
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
	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
   773
	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
   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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   776
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
   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
	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
   779
	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
   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
	/* 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
   782
	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
   783
		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
   784
		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
   785
		_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
   786
		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
   787
	}
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
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
	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
   790
	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
   791
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
	/* 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
   793
	* 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
   794
	* 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
   795
	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
   796
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 (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
   798
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
	/* 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
   800
	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
   801
		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
   802
	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
   803
		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
   804
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   805
	/* 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
   806
	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
   807
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
	/* 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
   809
	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
   810
	_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
   811
	_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
   812
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
   813
	/* 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
   814
	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
   815
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   816
	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
   817
	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
   818
	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
   819
	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
   820
	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
   821
	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
   822
	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
   823
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
}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   826
/*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
   827
{
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
   828
	// 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
   829
	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
   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
	// Otherwise find the window...
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   832
	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
   833
	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
   834
		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
   835
			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
   836
		} 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
   837
			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
   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
	_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
   841
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   844
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   845
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   846
void BaseWindow::DispatchLeftClickEvent(int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   847
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
	WindowEvent e;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   849
	const OldWidget *wi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   851
	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
   852
	e.we.click.pt.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
	e.event = WE_CLICK;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   855
	if (desc_flags & WDF_DEF_WIDGET) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   856
		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
   857
		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
   858
			OldWndProc(&e); // try to handle it by new window infrastructure
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   859
			return; /* exit if clicked outside of widgets */
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   860
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   861
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
   862
		/* 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
   863
		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
   864
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   865
		wi = &widget[e.we.click.widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   867
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   868
			/* special widget handling for buttons*/
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   869
			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
   870
				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
   871
				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
   872
				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
   873
					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
   874
					break;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   875
				default:
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   876
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
			}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   878
		} 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
   879
			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
   880
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   882
		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
   883
			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
   884
				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
   885
				return;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   886
			}
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   887
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   888
			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
   889
				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
   890
				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
   891
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   893
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   894
		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
   895
			StartSizing();
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   896
			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
   897
			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
   898
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   899
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   900
		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
   901
			flags4 ^= WF_STICKY;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   902
			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
   903
			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
   904
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	}
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
   906
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   907
	wndproc(this, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   910
void BaseWindow::DispatchRightClickEvent(int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   911
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	WindowEvent e;
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
   913
	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
   914
	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
   915
	e.we.click.pt.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
	/* default tooltips handler? */
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   918
	if (desc_flags & WDF_STD_TOOLTIPS) {
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   919
		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
   920
		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
   921
			OldWndProc(&e); // try to handle it by new window infrastructure
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
			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
   923
		}
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   924
		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
   925
			GuiShowTooltips(widget[e.we.click.widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   930
	wndproc(this, &e);
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
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
   933
/** 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
   934
 * 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
   935
 * @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
   936
 * @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
   937
 * @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
   938
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   939
void BaseWindow::DispatchMouseWheelEvent(int widget_idx, int wheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   941
	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
   942
	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
   943
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   944
	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
   945
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   946
	wi1 = &widget[widget_idx];
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   947
	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
   948
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
   949
	/* 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
   950
	 * 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
   951
	 * 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
   952
	 * 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
   953
	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
   954
			(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
   955
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
   956
		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
   957
			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
   958
			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
   959
				sb->pos = pos;
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
   960
				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
   961
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   965
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
   966
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
   967
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   968
	BaseWindow *w = (*wit).w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
   970
	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
   971
		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
   972
		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
   973
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   974
		if (right  > v->Left() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   975
				bottom > v->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   976
				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
   977
				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
   978
			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
   979
				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
   980
				DrawOverlappedWindow(wit, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   982
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   983
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   984
			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
   985
				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
   986
				DrawOverlappedWindow(wit, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   990
			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
   991
				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
   992
				DrawOverlappedWindow(wit, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
   996
			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
   997
				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
   998
				DrawOverlappedWindow(wit, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   999
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1000
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1001
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1005
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1006
	{
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1007
		DrawPixelInfo *dp = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
		dp->width = right - left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
		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
  1010
		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
  1011
		dp->top = top - w->Top();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
		dp->pitch = _screen.pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
		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
  1014
		dp->zoom = 0;
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1015
		w->CallEventNP(WE_PAINT);
0
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1019
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
  1020
{
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1021
	DrawPixelInfo bk;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1022
	_cur_dpi = &bk;
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1023
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1024
	const BaseWindow *w = NULL;
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1025
	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
  1026
		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
  1027
			bottom > w->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1028
			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
  1029
			top < w->Top() + w->Height()) {
6243
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1030
				DrawOverlappedWindow(it, left, top, right, bottom);
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1031
		}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1032
	}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1033
}
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1034
8f231ee779cb (svn r8706) [cpp_gui] -Codechange: few more functions turned into Window methods
KUDr
parents: 6242
diff changeset
  1035
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1036
void BaseWindow::CallEventNP(int event)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	WindowEvent e;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1039
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	e.event = event;
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1041
	wndproc(this, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1044
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
  1045
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1046
	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
  1047
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1048
	switch(e->event) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1049
		case WE_CREATE:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1050
			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
  1051
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1052
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1053
		case WE_DESTROY:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1054
			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
  1055
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1056
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1057
		case WE_PAINT:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1058
			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
  1059
			break;
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
		case WE_KEYPRESS:
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1062
			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
  1063
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1064
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1065
		case WE_CLICK:
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
  1066
			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
  1067
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1068
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1069
		case WE_RCLICK:
6282
c5b92f2d924f (svn r8996) [cpp_gui] -Add: CloseBox added into CaptionBar
KUDr
parents: 6279
diff changeset
  1070
			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
  1071
			break;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1072
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1073
		default:
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
	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
  1077
	DispatchEvent(*evt);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1078
	delete evt;
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
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1081
/*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
  1082
{
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1083
	w->OldWndProc(e);
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1084
}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1085
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1086
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1087
/** Find the z-value of a window. A window must already be open
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1088
 * or the behaviour is undefined but function should never fail */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1089
//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
  1090
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1091
//	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
  1092
//	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
  1093
//		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
  1094
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1095
//
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1096
//	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
  1097
//		w->window_class, w->window_number);
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1098
//	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
  1099
//}
5666
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
  1100
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1101
//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
  1102
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1103
//	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
  1104
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1105
//	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
  1106
//		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
  1107
//	}
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
//
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
//	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
  1110
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1114
	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
  1115
	if (w != NULL) w->Close();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1116
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
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
  1118
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
  1119
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1120
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
  1121
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
  1122
	/* 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
  1123
	 * 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
  1124
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1125
	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
  1126
	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
  1127
		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
  1128
			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
  1129
			goto restart_search;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1130
		}
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
  1131
	}
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
  1132
}
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
  1133
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1134
/** 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
  1135
 * 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
  1136
 * 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
  1137
 * @param id PlayerID player identifier */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1138
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
  1139
{
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
  1140
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
  1141
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
  1142
	/* 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
  1143
	 * 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
  1144
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1145
	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
  1146
	FOR_ALL_WINDOWS(w) {
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1147
		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
  1148
			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
  1149
			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
  1150
		}
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
  1151
	}
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
  1152
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1153
	/* 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
  1154
	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
  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
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1157
/** 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
  1158
 * 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
  1159
 * 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
  1160
 * @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
  1161
 * @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
  1162
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
  1163
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1164
	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
  1165
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
  1166
	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
  1167
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
  1168
		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
  1169
		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
  1170
		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
  1171
		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
  1172
		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
  1173
		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
  1174
		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
  1175
		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
  1176
		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
  1177
		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
  1178
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
  1179
		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
  1180
	}
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
}
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
  1182
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1183
/** 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
  1184
 * 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
  1185
 * - 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
  1186
 * - 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
  1187
 * - 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
  1188
 * @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
  1189
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1190
//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
  1191
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1192
//	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
  1193
//	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
  1194
//		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
  1195
//			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
  1196
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1197
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1198
//	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
  1199
//		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
  1200
//			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
  1201
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1202
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1203
//	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
  1204
//}
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
  1205
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1206
/** 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
  1207
 * 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
  1208
 * 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
  1209
 * 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
  1210
 * @see FindDeletableWindow()
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1211
 * @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
  1212
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1213
//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
  1214
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1215
//	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
  1216
//
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
//	for (wz = _z_windows;; wz++) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1218
//		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
  1219
//		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
  1220
//		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
  1221
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1222
//}
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
  1223
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1224
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
  1225
{
6239
925a1bba771f (svn r8697) [cpp_gui] -Codechange: changed IsWindowOfPrototype() is a Window method
bjarni
parents: 6238
diff changeset
  1226
	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
  1227
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1228
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1229
/* Copies 'widget' to 'w->widget' to allow for resizable windows */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1230
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
  1231
{
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1232
	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
  1233
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1234
	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
  1235
		uint index = 1;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1236
		const OldWidget *wi;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1237
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1238
		for (wi = widget_array; wi->type != WWT_LAST; wi++) index++;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1239
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1240
		widget = ReallocT(widget, index);
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1241
		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
  1242
		widget_count = index - 1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1243
	} else {
6237
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1244
		widget = NULL;
bce32e54c993 (svn r8695) [cpp_gui] -Codechange: changed AssignWidgetToWindow() and InvalidateWidget() into Window methods
bjarni
parents: 6236
diff changeset
  1245
		widget_count = 0;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1246
	}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1247
}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1248
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1249
//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
  1250
//{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1251
//	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
  1252
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1253
//	for (w = _windows; w < endof(_windows); w++) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1254
//		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
  1255
//		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
  1256
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1257
//		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
  1258
//			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
  1259
//				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
  1260
//				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
  1261
//			}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1262
//		}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1263
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1264
//		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
  1265
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1266
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1267
//	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
  1268
//	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
  1269
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
typedef struct SizeRect {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	int left,top,width,height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
} SizeRect;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
static SizeRect _awap_r;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
static bool IsGoodAutoPlace1(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	int right,bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	right = _awap_r.width + left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	bottom = _awap_r.height + top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
	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
  1289
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1291
	// 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
  1292
	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
  1293
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1294
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1296
		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
  1297
				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
  1298
				bottom > w->Top() &&
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1299
				w->Top() + w->Height() > top) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1300
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1301
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1302
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
}
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
static bool IsGoodAutoPlace2(int left, int top)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1309
	int width,height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	_awap_r.left= left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
	_awap_r.top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
	width = _awap_r.width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
	height = _awap_r.height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1315
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1316
	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
  1317
	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
  1318
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1319
	// 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
  1320
	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
  1321
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1322
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1324
		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
  1325
				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
  1326
				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
  1327
				w->Top() + w->Height() > top) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1328
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1329
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1330
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1332
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1333
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1334
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1335
static Point GetAutoPlacePosition(int width, int height)
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1336
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1337
	Point pt;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1338
	BaseWindow *w = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
	_awap_r.width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
	_awap_r.height = height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
	if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
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
  1345
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1346
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1348
		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
  1349
		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
  1350
		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
  1351
		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
  1352
		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
  1353
		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
  1354
		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
  1355
		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
  1356
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1357
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
  1358
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1359
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1361
		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
  1362
		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
  1363
		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
  1364
		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
  1365
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		int left=0,top=24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1369
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
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
  1371
		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
  1372
			if (w->Left() == left && w->Top() == top) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1374
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1378
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1383
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
ok_pos:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
	pt.x = _awap_r.left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
	pt.y = _awap_r.top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1390
///**
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1391
// * Open a new window.
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1392
// * @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
  1393
// * @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
  1394
// */
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1395
//BaseWindow *AllocateWindowDesc(const WindowDesc *desc)
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1396
//{
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1397
//	return LocalAllocateWindowDesc(desc, 0);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1398
//}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1400
void InitWindowSystem(void)
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
  1401
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
  1402
	IConsoleClose();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1403
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
  1404
	//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
  1405
	//_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
  1406
	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
  1407
	_no_scroll = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1410
void UnInitWindowSystem(void)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1411
{
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1412
	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
  1413
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1414
//	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
  1415
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1416
//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
  1417
//	/* 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
  1418
//	 *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
  1419
//	 * 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
  1420
//	 * 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
  1421
//	 * 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
  1422
//	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
  1423
//		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
  1424
//		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
  1425
//	}
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1426
//
5077e6ed3788 (svn r8683) [cpp_gui] -Codechange: first steps towards OO GUI (together with Bjarni) without changes in the logic
KUDr
parents: 6158
diff changeset
  1427
//	assert(_last_z_window == _z_windows);
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1428
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1429
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1430
void ResetWindowSystem(void)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1431
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1432
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1433
	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
  1434
	_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
  1435
	_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
  1436
	_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
  1437
	_thd.new_pos.y = 0;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1438
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1439
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1440
static void DecreaseWindowCounters(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
{
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
  1442
	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
  1443
	REVERSED_FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
		// Unclick scrollbar buttons if they are pressed.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
			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
  1447
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
		}
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  1449
		w->CallEventNP(WE_MOUSELOOP);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
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
  1452
	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
  1453
		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
  1454
			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
  1455
			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
  1456
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1460
BaseWindow *GetCallbackWnd(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1462
	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
  1463
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1465
static void HandlePlacePresize(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1467
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1470
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1472
	w = GetCallbackWnd();
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1473
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1475
	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
  1476
	if (e.we.place.pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
	}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1480
	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
  1481
	e.event = WE_PLACE_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1483
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1485
static bool HandleDragDrop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1487
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1488
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1490
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1492
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1493
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	w = GetCallbackWnd();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1496
	ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1497
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1498
	if (w != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
		// send an event in client coordinates.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
		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
  1501
		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
  1502
		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
  1503
		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
  1504
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1509
static bool HandlePopupMenu(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1511
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1514
	if (!_popup_menu_active) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1516
	w = BaseWindow::FindById(WC_TOOLBAR_MENU, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
		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
  1524
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
		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
  1528
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
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
  1531
	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
  1532
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
  1536
static bool HandleMouseOver(void)
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1537
{
6271
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1538
	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
  1539
	/* 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
  1540
	gui::EvtMouseOver evt_capture(ptGlobal);
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1541
	if (gui::EventCaptureStack::HandleEvent(evt_capture)) {
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1542
		return true;
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1543
	}
0ad100a98853 (svn r8958) [cpp_gui] -Add: Widget can now capture specified gui events
KUDr
parents: 6268
diff changeset
  1544
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
  1545
	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
  1546
	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
  1547
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1548
	BaseWindow *w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1549
	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
  1550
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1551
	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
  1552
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1553
	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
  1554
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1555
	// We changed window, put a MOUSEOVER event to the last window
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1556
	if (last_w != NULL && last_w != w) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1557
		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
  1558
		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
  1559
		e.we.mouseover.pt.y = -1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1560
		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
  1561
	}
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
  1562
6264
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1563
	if (w == NULL) {
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1564
		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
  1565
		last_num = -1;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1566
		return false;
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1567
	}
9fc3b5467396 (svn r8931) [cpp_gui] -Add: first OO widget type (TextButton) added only with basic functionality
KUDr
parents: 6263
diff changeset
  1568
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
	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
  1570
	last_num = w->window_number;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1571
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1572
	if (w != NULL) {
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1573
		// send an event in client coordinates.
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1574
		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
  1575
		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
  1576
		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
  1577
		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
  1578
			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
  1579
		}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1580
		w->wndproc(w, &e);
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1581
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1582
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1583
	// Mouseover never stops execution
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1584
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1585
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1586
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1587
/** 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
  1588
 * 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
  1589
 * ensuring proper redrawal.
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1590
 * @param x delta x-size of changed window (positive if larger, etc.(
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1591
 * @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
  1592
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
  1593
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1594
	OldWidget *wi;
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1595
	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
  1596
	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
  1597
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1598
	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
  1599
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1600
	this->SetDirty();
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1601
	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
  1602
		/* Isolate the resizing flags */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1603
		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
  1604
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1605
		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
  1606
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1607
		/* 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
  1608
		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
  1609
			wi->left += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1610
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1611
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1612
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1613
		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
  1614
			wi->right += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1615
			resize_width = true;
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
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1618
		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
  1619
			wi->top += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1620
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1621
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1622
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1623
		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
  1624
			wi->bottom += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1625
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1626
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1627
	}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1628
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1629
	/* 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
  1630
	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
  1631
	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
  1632
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  1633
	SetDirty();
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1634
}
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1635
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1636
static bool HandleScrollbarScrolling(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
	int pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
	// Get out quickly if no item is being scrolled
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1643
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
	// 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
  1646
	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
  1647
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
		if (w->flags4 & WF_SCROLL_MIDDLE) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1649
			// Abort if no button is clicked any more.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1651
				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
  1652
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1653
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1654
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1655
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1659
			} else if (w->flags4 & WF_SCROLL2){
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1660
				sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1661
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1663
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1664
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1665
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1666
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1667
			// Find the item we want to move to and make sure it's inside bounds.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1668
			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
  1669
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1670
				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
  1671
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1674
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1676
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1681
static bool HandleViewportScroll(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
{
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
  1683
	WindowEvent e;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1684
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1686
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1688
	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
  1689
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
  1690
	if (!_right_button_down || w == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
		_cursor.fix_at = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
		_scrolling_viewport = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1693
		return true;
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
2680
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1696
	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
  1697
		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
  1698
		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
  1699
	} 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
  1700
		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
  1701
		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
  1702
	}
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1703
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
  1704
	/* 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
  1705
	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
  1706
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1708
	_cursor.delta.x = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1709
	_cursor.delta.y = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1710
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1712
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1713
/** 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
  1714
 * 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
  1715
 * 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
  1716
 * 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
  1717
 * 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
  1718
 * 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
  1719
 * @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
  1720
 * @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
  1721
static bool MaybeBringWindowToFront(BaseWindow *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
{
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1723
	bool bring_to_front = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1725
	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
  1726
			w->IsVital() ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1727
			w->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1728
			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
  1729
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1730
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1732
	WindowList::Iterator wit = BaseWindow::s_list.Find(w);
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1733
	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
  1734
		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
  1735
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1736
		/* 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
  1737
		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
  1738
			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
  1739
			u->SetDirty();
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1740
			return false;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1741
		}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1742
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1743
		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
  1744
				u->IsVital() ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1745
				u->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1746
				u->window_class == WC_DROPDOWN_MENU) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1747
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1748
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1750
		/* 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
  1751
		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
  1752
				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
  1753
				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
  1754
				u->Top() + u->Height() <= w->Top()) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1755
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1756
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1757
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1758
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
	}
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1760
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
  1761
	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
  1762
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1765
/** Send a message from one window to another. The receiving window is found by
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1766
 * @param w @see 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
  1767
 * @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
  1768
 * @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
  1769
 * @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
  1770
 */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1771
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
  1772
{
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1773
	WindowEvent e;
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1774
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1775
	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
  1776
	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
  1777
	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
  1778
	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
  1779
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1780
	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
  1781
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1782
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1783
/** Send a message from one window to another. The receiving window is found by
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1784
 * @param wnd_class @see WindowClass class AND
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1785
 * @param wnd_num @see WindowNumber number, mostly 0
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1786
 * @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
  1787
 * @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
  1788
 * @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
  1789
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1790
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
  1791
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1792
	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
  1793
	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
  1794
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1795
5043
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1796
/** 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
  1797
 * to ALL windows of the windowclass specified in the first parameter
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1798
 * @param wnd_class @see WindowClass class
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1799
 * @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
  1800
 * @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
  1801
 * @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
  1802
 */
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
  1803
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
  1804
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1805
	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
  1806
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
  1807
	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
  1808
		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
  1809
	}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1810
}
d567abc96b5d (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1811
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1812
/** Handle keyboard input.
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1813
 * @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
  1814
 * 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
  1815
void HandleKeypress(uint32 key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
{
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1817
	WindowEvent e;
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1818
	/* 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
  1819
	 * 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
  1820
	 * 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
  1821
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1822
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1823
	/*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1824
	* 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
  1825
	* 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
  1826
	* 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
  1827
	* 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
  1828
	*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1829
	* 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
  1830
	* 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
  1831
	*/
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1832
	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
  1833
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1834
	// 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
  1835
	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
  1836
	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
  1837
	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
  1838
	e.we.keypress.cont = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
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
  1840
	// 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
  1841
	if (BaseWindow::FindById(WC_QUERY_STRING,       0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1842
			BaseWindow::FindById(WC_SEND_NETWORK_MSG,   0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1843
			BaseWindow::FindById(WC_GENERATE_LANDSCAPE, 0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1844
			BaseWindow::FindById(WC_CONSOLE,            0) != NULL ||
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1845
			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
  1846
		query_open = true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1847
	}
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
  1848
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
	// 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
  1850
	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
  1851
	REVERSED_FOR_ALL_WINDOWS(w) {
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
  1852
		// if a query window is open, only call the event for certain window types
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1853
		if (query_open &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1854
				w->window_class != WC_QUERY_STRING &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1855
				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
  1856
				w->window_class != WC_GENERATE_LANDSCAPE &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1857
				w->window_class != WC_CONSOLE &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1858
				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
  1859
			continue;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1860
		}
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1861
		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
  1862
		if (!e.we.keypress.cont) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
	}
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
  1864
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1865
	if (e.we.keypress.cont) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1866
		BaseWindow *w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
1642
593a9b750b91 (svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents: 1637
diff changeset
  1867
		// 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
  1868
		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
  1869
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1870
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1872
extern void UpdateTileSelection(void);
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  1873
extern bool VpHandlePlaceSizingDrag(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1875
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
  1876
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1877
static void HandleAutoscroll(void)
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1878
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1879
	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
  1880
	ViewPort *vp;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1881
	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
  1882
	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
  1883
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1884
	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
  1885
		/* 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
  1886
		_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
  1887
		/* 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
  1888
		return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1889
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1890
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1891
	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
  1892
		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
  1893
		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
  1894
		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
  1895
		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
  1896
			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
  1897
			y -= vp->top;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1898
			//here allows scrolling in both x and y axis
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1899
#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
  1900
			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
  1901
				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
  1902
			} 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
  1903
				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
  1904
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1905
			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
  1906
				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
  1907
			} 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
  1908
				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
  1909
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1910
#undef scrollspeed
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1911
		}
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
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1914
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1915
void MouseLoop(int click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
	int x,y;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1918
	BaseWindow *w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
	ViewPort *vp;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1920
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1921
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1923
	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
  1924
	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
  1925
	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
  1926
	if (!HandlePopupMenu())              return;
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1927
	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
  1928
	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
  1929
	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
  1930
	if (!HandleMouseOver())              return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1931
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
	y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1935
	if (click == 0 && mousewheel == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  1937
	w = BaseWindow::FindFromPt(x, y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1938
	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
  1939
	if (!MaybeBringWindowToFront(w)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
	vp = IsPtInWindowViewport(w, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
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
  1942
	/* 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
  1943
	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
  1944
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
  1945
	if (mousewheel != 0) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1946
		WindowEvent e;
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1947
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1948
		/* Send WE_MOUSEWHEEL event to window */
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1949
		e.event = WE_MOUSEWHEEL;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1950
		e.we.wheel.wheel = mousewheel;
4337
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1951
		w->wndproc(w, &e);
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1952
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1953
		/* 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
  1954
		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
  1955
	}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1956
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1957
	if (vp != NULL) {
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1958
		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
  1959
			case 1:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1960
				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
  1961
				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
  1962
						// query button and place sign button work in pause mode
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1963
						_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
  1964
						_cursor.sprite != SPR_CURSOR_SIGN &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1965
						_pause != 0 &&
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1966
						!_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
  1967
					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
  1968
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1969
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1970
				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
  1971
					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
  1972
				} 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
  1973
					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
  1974
				}
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
				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
  1976
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1977
			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
  1978
				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
  1979
					_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
  1980
					_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
  1981
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1982
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1984
	} else {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1985
		switch (click) {
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1986
			case 1: w->DispatchLeftClickEvent (x - w->Left(), y - w->Top()); break;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  1987
			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
  1988
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1992
void HandleMouseEvents(void)
1570
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1993
{
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
  1994
	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
  1995
	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
  1996
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1997
	/*
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1998
	 * 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
  1999
	 * 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
  2000
	 * 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
  2001
	 * NOT change the _current_player here.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2002
	 *
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2003
	 * 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
  2004
	 * 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
  2005
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  2006
	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
  2007
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
  2008
	// Mouse event?
c470380facb9 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  2009
	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
  2010
	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
  2011
		_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
  2012
		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
  2013
		_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
  2014
	} 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
  2015
		_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
  2016
		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
  2017
		_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
  2018
	}
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
  2019
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
  2020
	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
  2021
	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
  2022
		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
  2023
		_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
  2024
		_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
  2025
	}
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
  2026
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
  2027
	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
  2028
}
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
  2029
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2030
void InputLoop(void)
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2031
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2032
	HandleMouseEvents();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2033
	HandleAutoscroll();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2034
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  2035
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  2036
void UpdateWindows(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
{
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2038
	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
  2039
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2041
	BaseWindow *w;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2042
	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
  2043
		REVERSED_FOR_ALL_WINDOWS(w) {
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2044
			w->CallEventNP(WE_4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2045
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2046
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
	}
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2048
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2049
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
  2050
	REVERSED_FOR_ALL_WINDOWS(w) {
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2051
		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
  2052
		w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2053
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2054
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2055
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2056
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
  2057
	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
  2058
		if (w->viewport != NULL) UpdateViewportPosition(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
	}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  2060
	DrawTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
	// Redraw mouse cursor in case it was hidden
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2063
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2066
int BaseWindow::GetMenuItemIndex(int x, int y) const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
{
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2068
	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
  2069
		y /= 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2070
6238
1ff56ccccbb5 (svn r8696) [cpp_gui] -Codechange: changed GetMenuItemIndex() and ResizeWindow() into Window methods
bjarni
parents: 6237
diff changeset
  2071
		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
  2072
				!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
  2073
			return y;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2074
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2078
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2079
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2081
	BaseWindow *w = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2082
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
  2083
	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
  2084
		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
  2085
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2088
void BaseWindow::InvalidateWidget(byte widget_index) const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2090
	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
  2091
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
  2092
	/* 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
  2093
	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
  2094
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2095
	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
  2096
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2098
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
  2099
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2100
	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
  2101
	FOR_ALL_WINDOWS(w) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2102
		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
  2103
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2108
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2110
	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
  2111
	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
  2112
		if (w->window_class == cls) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
	}
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2116
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
  2117
{
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2118
	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
  2119
	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
  2120
}
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
  2121
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2122
void InvalidateWindowData(WindowClass cls, WindowNumber number)
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2123
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2124
	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
  2125
	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
  2126
		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
  2127
	}
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
  2128
}
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
  2129
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
  2130
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
  2131
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2132
	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
  2133
	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
  2134
		if (w->window_class == cls) w->InvalidateData();
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2135
	}
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2136
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2137
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1038
diff changeset
  2138
void CallWindowTickEvent(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2139
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2140
	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
  2141
	REVERSED_FOR_ALL_WINDOWS(w) {
6245
6fa82c6ee8ca (svn r8711) [cpp_gui] -Codechange: even more funktion->method conversions
bjarni
parents: 6244
diff changeset
  2142
		w->CallEventNP(WE_TICK);
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
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2146
void BaseWindow::DeleteNonVitalWindows(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2148
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
  2149
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
  2150
	/* 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
  2151
	 * 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
  2152
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2153
	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
  2154
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2156
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2157
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
				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
  2160
				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
  2161
				(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
  2162
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
  2163
			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
  2164
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2166
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  2169
/* 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
  2170
 * '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
  2171
 * 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
  2172
 * 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
  2173
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2174
void BaseWindow::DeleteAllNonVitalWindows(void)
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
  2175
{
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
  2176
	/* 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
  2177
	DeleteNonVitalWindows();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2178
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
  2179
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
  2180
	/* 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
  2181
	 * 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
  2182
	 * anywhere in the z-array */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2183
	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
  2184
	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
  2185
		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
  2186
			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
  2187
			goto restart_search;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2188
		}
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
  2189
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2190
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2191
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
  2192
/* Delete all always on-top windows to get an empty screen */
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2193
void BaseWindow::HideVitalWindows(void)
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
  2194
{
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
  2195
	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
  2196
	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
  2197
	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
  2198
}
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
  2199
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2200
int PositionMainToolbar(BaseWindow *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2201
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2202
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2203
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2204
	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
  2205
		w = BaseWindow::FindById(WC_MAIN_TOOLBAR, 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2206
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2207
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2208
	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
  2209
		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
  2210
		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
  2211
		default: w->SetLeft(0);
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2212
	}
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2213
	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
  2214
	return w->Left();
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2215
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2216
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2218
{
6258
a2f86b8fd99b (svn r8801) [cpp_gui] -Codechange: few changes towards OO GUI:
KUDr
parents: 6256
diff changeset
  2219
	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
  2220
	FOR_ALL_WINDOWS(w) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2221
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2222
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2224
			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
  2225
			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
  2226
			vp->width = neww;
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2227
			vp->height = newh;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
			vp->virtual_width = neww << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2229
			vp->virtual_height = newh << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2230
			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
  2231
		}
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
  2232
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2233
		/* 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
  2234
		 * in a 'backup'-desc that the window should always be centred. */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2235
		switch (w->window_class) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2236
			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
  2237
				top = w->Top();
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2238
				left = PositionMainToolbar(w); // changes toolbar orientation
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2239
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2240
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2241
			case WC_SELECT_GAME:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2242
			case WC_GAME_OPTIONS:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2243
			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
  2244
				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
  2245
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2246
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2247
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2248
			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
  2249
				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
  2250
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2251
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2252
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2253
			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
  2254
				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
  2255
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2256
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2257
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2258
			case WC_SEND_NETWORK_MSG:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2259
				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
  2260
				left = (neww - w->Width()) >> 1;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2261
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2262
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2263
			case WC_CONSOLE:
5143
a78072872bff (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2264
				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
  2265
				continue;
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2266
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2267
			default:
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2268
				left = w->Left();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2269
				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
  2270
				top = w->Top();
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2271
				if (top + (w->Height() >> 1) >= newh) top = newh - w->Height();
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2272
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2273
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2274
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2275
		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
  2276
			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
  2277
			w->viewport->top += top - w->Top();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2278
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2279
6263
19dab6a68886 (svn r8913) [cpp_gui] -Codechange: use BaseWindow accessors instead of accessing window size/position directly
KUDr
parents: 6261
diff changeset
  2280
		w->SetTopLeft(Point(left, top));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2281
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2282
}