]> git.saurik.com Git - wxWidgets.git/blame - src/x11/window.cpp
fixes #10358
[wxWidgets.git] / src / x11 / window.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
9eddec69 2// Name: src/x11/window.cpp
83df96d6
JS
3// Purpose: wxWindow
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
521bf4ff
WS
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#if defined(__BORLANDC__)
32d4c30a
WS
16 #pragma hdrstop
17#endif
18
83df96d6
JS
19// ============================================================================
20// declarations
21// ============================================================================
22
23// ----------------------------------------------------------------------------
24// headers
25// ----------------------------------------------------------------------------
26
e4db172a
WS
27#include "wx/window.h"
28
29#ifndef WX_PRECOMP
30 #include "wx/hash.h"
31 #include "wx/log.h"
670f9935 32 #include "wx/app.h"
de6185e2 33 #include "wx/utils.h"
8e609c82 34 #include "wx/panel.h"
76b49cf4 35 #include "wx/frame.h"
da80ae71 36 #include "wx/dc.h"
ed4b0fdc 37 #include "wx/dcclient.h"
f1e01716 38 #include "wx/button.h"
3b3dc801 39 #include "wx/menu.h"
fdf565fe 40 #include "wx/dialog.h"
c0badb70 41 #include "wx/timer.h"
9eddec69 42 #include "wx/settings.h"
246c5004 43 #include "wx/msgdlg.h"
851dee09 44 #include "wx/scrolbar.h"
2a673eb1 45 #include "wx/listbox.h"
1ab440bc 46 #include "wx/scrolwin.h"
ed2fbeb8 47 #include "wx/layout.h"
25466131 48 #include "wx/menuitem.h"
02761f6c 49 #include "wx/module.h"
e4db172a
WS
50#endif
51
2b5f62a0 52#include "wx/fontutil.h"
a17a79ba 53#include "wx/univ/renderer.h"
83df96d6
JS
54
55#if wxUSE_DRAG_AND_DROP
56 #include "wx/dnd.h"
57#endif
58
bc797f4c 59#include "wx/x11/private.h"
7266b672 60#include "X11/Xutil.h"
83df96d6
JS
61
62#include <string.h>
63
83df96d6
JS
64// ----------------------------------------------------------------------------
65// global variables for this module
66// ----------------------------------------------------------------------------
67
83df96d6 68static wxWindow* g_captureWindow = NULL;
c2c0dabf 69static GC g_eraseGC;
83df96d6 70
83df96d6
JS
71// ----------------------------------------------------------------------------
72// macros
73// ----------------------------------------------------------------------------
74
75#define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
76#define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
77#define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
78
79// ----------------------------------------------------------------------------
80// event tables
81// ----------------------------------------------------------------------------
82
8354aa92 83IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase)
83df96d6 84
bc797f4c
JS
85BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase)
86 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged)
bc797f4c 87END_EVENT_TABLE()
83df96d6
JS
88
89// ============================================================================
90// implementation
91// ============================================================================
92
93// ----------------------------------------------------------------------------
94// helper functions
95// ----------------------------------------------------------------------------
96
83df96d6
JS
97// ----------------------------------------------------------------------------
98// constructors
99// ----------------------------------------------------------------------------
100
bc797f4c 101void wxWindowX11::Init()
83df96d6 102{
7266b672 103 // X11-specific
ab6b6b15
RR
104 m_mainWindow = (WXWindow) 0;
105 m_clientWindow = (WXWindow) 0;
ffd84c94
WS
106 m_insertIntoMain = false;
107 m_updateNcArea = false;
7de59551 108
ffd84c94
WS
109 m_winCaptured = false;
110 m_needsInputFocus = false;
111 m_isShown = true;
83df96d6
JS
112 m_lastTS = 0;
113 m_lastButton = 0;
83df96d6
JS
114}
115
116// real construction (Init() must have been called before!)
bc797f4c 117bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
ffd84c94
WS
118 const wxPoint& pos,
119 const wxSize& size,
120 long style,
121 const wxString& name)
83df96d6 122{
ffd84c94 123 wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
83df96d6 124
cce69fec
JS
125 // Get default border
126 wxBorder border = GetBorder(style);
127 style &= ~wxBORDER_MASK;
128 style |= border;
129
83df96d6
JS
130 CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
131
3cd0b8c5 132 parent->AddChild(this);
83df96d6 133
3cd0b8c5
RR
134 Display *xdisplay = (Display*) wxGlobalDisplay();
135 int xscreen = DefaultScreen( xdisplay );
7e4501ee 136 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
3cd0b8c5 137 Colormap cm = DefaultColormap( xdisplay, xscreen );
b513212d 138
3cd0b8c5 139 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
7de59551
RD
140 m_backgroundColour.CalcPixel( (WXColormap) cm );
141
3cd0b8c5 142 m_foregroundColour = *wxBLACK;
7de59551 143 m_foregroundColour.CalcPixel( (WXColormap) cm );
3cd0b8c5 144
f41bc3e3 145 Window xparent = (Window) parent->GetClientAreaWindow();
7de59551 146
ab6b6b15
RR
147 // Add window's own scrollbars to main window, not to client window
148 if (parent->GetInsertIntoMain())
149 {
150 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
151 xparent = (Window) parent->GetMainWindow();
152 }
7de59551 153
1cfb7d2c
RR
154 // Size (not including the border) must be nonzero (or a Value error results)!
155 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
2f12683e 156 wxSize size2(size);
1cfb7d2c 157 if (size2.x <= 0)
2b5f62a0 158 size2.x = 20;
1cfb7d2c 159 if (size2.y <= 0)
2b5f62a0 160 size2.y = 20;
b513212d 161
2f12683e 162 wxPoint pos2(pos);
ffd84c94 163 if (pos2.x == wxDefaultCoord)
2b5f62a0 164 pos2.x = 0;
ffd84c94 165 if (pos2.y == wxDefaultCoord)
2b5f62a0 166 pos2.y = 0;
7de59551 167
43c05cf8
VZ
168 AdjustForParentClientOrigin(pos2.x, pos2.y);
169
ab6b6b15 170#if wxUSE_TWO_WINDOWS
2b5f62a0 171 bool need_two_windows =
cce69fec 172 ((( wxSUNKEN_BORDER | wxBORDER_THEME | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
ab6b6b15 173#else
ffd84c94 174 bool need_two_windows = false;
ab6b6b15
RR
175#endif
176
8601b2e1
JS
177#if wxUSE_NANOX
178 long xattributes = 0;
179#else
7e4501ee 180 XSetWindowAttributes xattributes;
ab6b6b15 181 long xattributes_mask = 0;
7de59551 182
ab6b6b15 183 xattributes_mask |= CWBackPixel;
7e4501ee 184 xattributes.background_pixel = m_backgroundColour.GetPixel();
7de59551 185
ab6b6b15 186 xattributes_mask |= CWBorderPixel;
7e4501ee 187 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
7de59551 188
2f12683e 189 xattributes_mask |= CWEventMask;
8601b2e1 190#endif
7de59551 191
ab6b6b15 192 if (need_two_windows)
2f12683e 193 {
8601b2e1
JS
194#if wxUSE_NANOX
195 long backColor, foreColor;
196 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
197 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
7de59551
RD
198
199 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
8601b2e1
JS
200 0, 0, InputOutput, xvisual, backColor, foreColor);
201 XSelectInput( xdisplay, xwindow,
202 GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
203 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
204 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
205 PropertyChangeMask );
7de59551 206
8601b2e1
JS
207#else
208 // Normal X11
7de59551 209 xattributes.event_mask =
ab6b6b15
RR
210 ExposureMask | StructureNotifyMask | ColormapChangeMask;
211
7de59551 212 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
ab6b6b15 213 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1
JS
214
215#endif
7de59551 216
ab6b6b15 217 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7de59551 218
ab6b6b15
RR
219 m_mainWindow = (WXWindow) xwindow;
220 wxAddWindowToTable( xwindow, (wxWindow*) this );
7de59551 221
ab6b6b15 222 XMapWindow( xdisplay, xwindow );
8601b2e1 223
7de59551
RD
224#if !wxUSE_NANOX
225 xattributes.event_mask =
ab6b6b15
RR
226 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
227 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
228 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
229 PropertyChangeMask | VisibilityChangeMask ;
230
e441e1f4 231 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE ))
ab6b6b15
RR
232 {
233 xattributes_mask |= CWBitGravity;
234 xattributes.bit_gravity = StaticGravity;
235 }
8601b2e1 236#endif
7de59551 237
cce69fec 238 if (HasFlag(wxSUNKEN_BORDER) || HasFlag(wxRAISED_BORDER) || HasFlag(wxBORDER_THEME))
065722d7
RR
239 {
240 pos2.x = 2;
241 pos2.y = 2;
242 size2.x -= 4;
243 size2.y -= 4;
7de59551 244 }
1cfb7d2c 245 else if (HasFlag( wxSIMPLE_BORDER ))
065722d7
RR
246 {
247 pos2.x = 1;
248 pos2.y = 1;
249 size2.x -= 2;
250 size2.y -= 2;
7de59551 251 }
1cfb7d2c 252 else
065722d7
RR
253 {
254 pos2.x = 0;
255 pos2.y = 0;
256 }
1cfb7d2c
RR
257
258 // Make again sure the size is nonzero.
259 if (size2.x <= 0)
260 size2.x = 1;
261 if (size2.y <= 0)
262 size2.y = 1;
263
7de59551 264#if wxUSE_NANOX
8601b2e1
JS
265 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
266 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
7de59551
RD
267
268 xwindow = XCreateWindowWithColor( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
8601b2e1
JS
269 0, 0, InputOutput, xvisual, backColor, foreColor);
270 XSelectInput( xdisplay, xwindow,
271 GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
272 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
273 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
274 PropertyChangeMask );
7de59551 275
8601b2e1 276#else
7de59551 277 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
ab6b6b15 278 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1 279#endif
7de59551 280
ab6b6b15 281 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7de59551 282
ab6b6b15
RR
283 m_clientWindow = (WXWindow) xwindow;
284 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
7de59551 285
ab6b6b15 286 XMapWindow( xdisplay, xwindow );
2f12683e 287 }
ab6b6b15
RR
288 else
289 {
290 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
8601b2e1
JS
291#if wxUSE_NANOX
292 long backColor, foreColor;
293 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
294 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
7de59551
RD
295
296 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
8601b2e1
JS
297 0, 0, InputOutput, xvisual, backColor, foreColor);
298 XSelectInput( xdisplay, xwindow,
299 GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
300 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
301 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
302 PropertyChangeMask );
7de59551 303
8601b2e1 304#else
7de59551 305 xattributes.event_mask =
ab6b6b15
RR
306 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
307 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
308 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
309 PropertyChangeMask | VisibilityChangeMask ;
2f12683e 310
e441e1f4 311 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE ))
ab6b6b15
RR
312 {
313 xattributes_mask |= CWBitGravity;
065722d7 314 xattributes.bit_gravity = NorthWestGravity;
ab6b6b15 315 }
7de59551
RD
316
317 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
ab6b6b15 318 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
8601b2e1 319#endif
7de59551 320
ab6b6b15 321 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
7de59551 322
ab6b6b15
RR
323 m_mainWindow = (WXWindow) xwindow;
324 m_clientWindow = m_mainWindow;
325 wxAddWindowToTable( xwindow, (wxWindow*) this );
7de59551 326
ab6b6b15
RR
327 XMapWindow( xdisplay, xwindow );
328 }
b513212d 329
b28d3abf 330 // Is a subwindow, so map immediately
ffd84c94 331 m_isShown = true;
83df96d6
JS
332
333 // Without this, the cursor may not be restored properly (e.g. in splitter
334 // sample).
335 SetCursor(*wxSTANDARD_CURSOR);
336 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
15c69343
JS
337
338 // Don't call this, it can have nasty repercussions for composite controls,
339 // for example
340 // SetSize(pos.x, pos.y, size.x, size.y);
83df96d6 341
ffd84c94 342 return true;
83df96d6
JS
343}
344
345// Destructor
7266b672 346wxWindowX11::~wxWindowX11()
83df96d6 347{
7de59551
RD
348 SendDestroyEvent();
349
83df96d6 350 if (g_captureWindow == this)
2b5f62a0 351 g_captureWindow = NULL;
7de59551 352
ffd84c94 353 m_isBeingDeleted = true;
7de59551 354
d02cb44e 355 DestroyChildren();
83df96d6 356
ab6b6b15 357 if (m_clientWindow != m_mainWindow)
83df96d6 358 {
ab6b6b15
RR
359 // Destroy the cleint window
360 Window xwindow = (Window) m_clientWindow;
361 wxDeleteClientWindowFromTable( xwindow );
7e4501ee 362 XDestroyWindow( wxGlobalDisplay(), xwindow );
ab6b6b15 363 m_clientWindow = NULL;
83df96d6 364 }
7de59551 365
ab6b6b15 366 // Destroy the window
3aba082d
VZ
367 if ( m_mainWindow )
368 {
369 Window xwindow = (Window) m_mainWindow;
370 wxDeleteWindowFromTable( xwindow );
371 XDestroyWindow( wxGlobalDisplay(), xwindow );
372 m_mainWindow = NULL;
373 }
83df96d6
JS
374}
375
376// ---------------------------------------------------------------------------
377// basic operations
378// ---------------------------------------------------------------------------
379
bc797f4c 380void wxWindowX11::SetFocus()
83df96d6 381{
ab6b6b15 382 Window xwindow = (Window) m_clientWindow;
7de59551 383
86fd8bda 384 wxCHECK_RET( xwindow, wxT("invalid window") );
7de59551 385
10e0e1be
JS
386 // Don't assert; we might be trying to set the focus for a panel
387 // with only static controls, so the panel returns false from AcceptsFocus.
388 // The app should be not be expected to deal with this.
389 if (!AcceptsFocus())
390 return;
7de59551 391
9b8270da
RR
392#if 0
393 if (GetName() == "scrollBar")
394 {
395 char *crash = NULL;
396 *crash = 0;
397 }
398#endif
7de59551 399
3a0b23eb
JS
400 if (wxWindowIsVisible(xwindow))
401 {
58ec2255
JS
402 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
403 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
404 XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToNone, CurrentTime );
ffd84c94 405 m_needsInputFocus = false;
3a0b23eb
JS
406 }
407 else
408 {
ffd84c94 409 m_needsInputFocus = true;
3a0b23eb 410 }
83df96d6
JS
411}
412
413// Get the window with the focus
0fe02759 414wxWindow *wxWindowBase::DoFindFocus()
83df96d6 415{
86fd8bda 416 Window xfocus = (Window) 0;
b513212d 417 int revert = 0;
bc797f4c 418
86fd8bda
RR
419 XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert);
420 if (xfocus)
83df96d6 421 {
86fd8bda 422 wxWindow *win = wxGetWindowFromTable( xfocus );
288efe84
JS
423 if (!win)
424 {
425 win = wxGetClientWindowFromTable( xfocus );
426 }
b513212d
JS
427
428 return win;
83df96d6
JS
429 }
430
b513212d 431 return NULL;
83df96d6
JS
432}
433
b513212d
JS
434// Enabling/disabling handled by event loop, and not sending events
435// if disabled.
bc797f4c 436bool wxWindowX11::Enable(bool enable)
83df96d6
JS
437{
438 if ( !wxWindowBase::Enable(enable) )
ffd84c94 439 return false;
7de59551 440
ffd84c94 441 return true;
83df96d6
JS
442}
443
bc797f4c 444bool wxWindowX11::Show(bool show)
83df96d6 445{
7edcafa4 446 wxWindowBase::Show(show);
83df96d6 447
ab6b6b15
RR
448 Window xwindow = (Window) m_mainWindow;
449 Display *xdisp = wxGlobalDisplay();
83df96d6 450 if (show)
b513212d 451 {
7e4501ee 452 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
ab6b6b15 453 XMapWindow(xdisp, xwindow);
b513212d 454 }
83df96d6 455 else
b513212d 456 {
7e4501ee 457 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
ab6b6b15 458 XUnmapWindow(xdisp, xwindow);
b513212d 459 }
83df96d6 460
ffd84c94 461 return true;
83df96d6
JS
462}
463
464// Raise the window to the top of the Z order
bc797f4c 465void wxWindowX11::Raise()
83df96d6 466{
ab6b6b15
RR
467 if (m_mainWindow)
468 XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow );
83df96d6
JS
469}
470
471// Lower the window to the bottom of the Z order
bc797f4c 472void wxWindowX11::Lower()
83df96d6 473{
ab6b6b15
RR
474 if (m_mainWindow)
475 XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow );
83df96d6
JS
476}
477
ffd84c94
WS
478void wxWindowX11::SetLabel(const wxString& WXUNUSED(label))
479{
480 // TODO
481}
482
483wxString wxWindowX11::GetLabel() const
484{
485 // TODO
486 return wxEmptyString;
487}
488
bc797f4c 489void wxWindowX11::DoCaptureMouse()
83df96d6 490{
7edcafa4
JS
491 if ((g_captureWindow != NULL) && (g_captureWindow != this))
492 {
4362c705 493 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
7edcafa4 494
346d4fcd
RR
495 // Core dump now
496 int *tmp = NULL;
497 (*tmp) = 1;
498 return;
7edcafa4 499 }
7de59551 500
346d4fcd 501 if (m_winCaptured)
83df96d6
JS
502 return;
503
ab6b6b15 504 Window xwindow = (Window) m_clientWindow;
346d4fcd 505
86fd8bda 506 wxCHECK_RET( xwindow, wxT("invalid window") );
7de59551 507
7edcafa4
JS
508 g_captureWindow = (wxWindow*) this;
509
346d4fcd 510 if (xwindow)
b513212d 511 {
346d4fcd 512 int res = XGrabPointer(wxGlobalDisplay(), xwindow,
b513212d
JS
513 FALSE,
514 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
515 GrabModeAsync,
2b5f62a0 516 GrabModeAsync,
b513212d
JS
517 None,
518 None, /* cursor */ // TODO: This may need to be set to the cursor of this window
346d4fcd 519 CurrentTime );
b513212d 520
b28d3abf 521 if (res != GrabSuccess)
b513212d 522 {
346d4fcd 523 wxString msg;
2b5f62a0 524 msg.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
346d4fcd
RR
525 wxLogDebug(msg);
526 if (res == GrabNotViewable)
2b5f62a0 527 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
7de59551 528
346d4fcd 529 g_captureWindow = NULL;
b28d3abf 530 return;
b513212d 531 }
346d4fcd 532
ffd84c94 533 m_winCaptured = true;
b513212d 534 }
83df96d6
JS
535}
536
bc797f4c 537void wxWindowX11::DoReleaseMouse()
83df96d6
JS
538{
539 g_captureWindow = NULL;
7de59551 540
83df96d6
JS
541 if ( !m_winCaptured )
542 return;
543
ab6b6b15 544 Window xwindow = (Window) m_clientWindow;
b513212d 545
346d4fcd 546 if (xwindow)
b28d3abf 547 {
346d4fcd 548 XUngrabPointer( wxGlobalDisplay(), CurrentTime );
b28d3abf 549 }
7de59551 550
9691c806 551 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
83df96d6 552
ffd84c94 553 m_winCaptured = false;
83df96d6
JS
554}
555
bc797f4c 556bool wxWindowX11::SetFont(const wxFont& font)
83df96d6
JS
557{
558 if ( !wxWindowBase::SetFont(font) )
559 {
560 // nothing to do
ffd84c94 561 return false;
83df96d6
JS
562 }
563
ffd84c94 564 return true;
83df96d6
JS
565}
566
bc797f4c 567bool wxWindowX11::SetCursor(const wxCursor& cursor)
83df96d6
JS
568{
569 if ( !wxWindowBase::SetCursor(cursor) )
570 {
571 // no change
ffd84c94 572 return false;
83df96d6
JS
573 }
574
ab6b6b15 575 Window xwindow = (Window) m_clientWindow;
86fd8bda 576
ffd84c94 577 wxCHECK_MSG( xwindow, false, wxT("invalid window") );
7de59551 578
86fd8bda 579 wxCursor cursorToUse;
83df96d6 580 if (m_cursor.Ok())
86fd8bda 581 cursorToUse = m_cursor;
83df96d6 582 else
86fd8bda 583 cursorToUse = *wxSTANDARD_CURSOR;
83df96d6 584
86fd8bda 585 Cursor xcursor = (Cursor) cursorToUse.GetCursor();
83df96d6 586
e88be8c9 587 XDefineCursor( wxGlobalDisplay(), xwindow, xcursor );
83df96d6 588
ffd84c94 589 return true;
83df96d6
JS
590}
591
592// Coordinates relative to the window
bc797f4c 593void wxWindowX11::WarpPointer (int x, int y)
83df96d6 594{
ab6b6b15 595 Window xwindow = (Window) m_clientWindow;
86fd8bda
RR
596
597 wxCHECK_RET( xwindow, wxT("invalid window") );
7de59551 598
86fd8bda 599 XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y);
83df96d6
JS
600}
601
83df96d6 602// Does a physical scroll
bc797f4c 603void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
83df96d6 604{
fc9be1cf
RR
605 // No scrolling requested.
606 if ((dx == 0) && (dy == 0)) return;
7de59551 607
fc9be1cf
RR
608 if (!m_updateRegion.IsEmpty())
609 {
610 m_updateRegion.Offset( dx, dy );
7de59551 611
fc9be1cf
RR
612 int cw = 0;
613 int ch = 0;
614 GetSize( &cw, &ch ); // GetClientSize() ??
615 m_updateRegion.Intersect( 0, 0, cw, ch );
616 }
7de59551 617
fc9be1cf
RR
618 if (!m_clearRegion.IsEmpty())
619 {
620 m_clearRegion.Offset( dx, dy );
7de59551 621
fc9be1cf
RR
622 int cw = 0;
623 int ch = 0;
624 GetSize( &cw, &ch ); // GetClientSize() ??
625 m_clearRegion.Intersect( 0, 0, cw, ch );
626 }
7de59551 627
f41bc3e3 628 Window xwindow = (Window) GetClientAreaWindow();
7e085304
RR
629
630 wxCHECK_RET( xwindow, wxT("invalid window") );
631
632 Display *xdisplay = wxGlobalDisplay();
633
634 GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL );
635 XSetGraphicsExposures( xdisplay, xgc, True );
636
e88be8c9
RR
637 int s_x = 0;
638 int s_y = 0;
4125131b
RR
639 int cw;
640 int ch;
641 if (rect)
642 {
643 s_x = rect->x;
644 s_y = rect->y;
7de59551 645
4125131b
RR
646 cw = rect->width;
647 ch = rect->height;
648 }
649 else
650 {
651 s_x = 0;
652 s_y = 0;
653 GetClientSize( &cw, &ch );
654 }
7de59551 655
ab6b6b15
RR
656#if wxUSE_TWO_WINDOWS
657 wxPoint offset( 0,0 );
658#else
4125131b
RR
659 wxPoint offset = GetClientAreaOrigin();
660 s_x += offset.x;
661 s_y += offset.y;
ab6b6b15 662#endif
7de59551 663
7e085304
RR
664 int w = cw - abs(dx);
665 int h = ch - abs(dy);
7de59551 666
7e085304 667 if ((h < 0) || (w < 0))
83df96d6 668 {
7e085304 669 Refresh();
83df96d6
JS
670 }
671 else
672 {
4125131b 673 wxRect rect;
f809133f
RR
674 if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x;
675 if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y;
4125131b
RR
676 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
677 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
7de59551 678
4125131b
RR
679 int d_x = s_x;
680 int d_y = s_y;
7de59551 681
4125131b
RR
682 if (dx < 0) s_x += -dx;
683 if (dy < 0) s_y += -dy;
ca86035f
VZ
684 if (dx > 0) d_x += dx + offset.x;
685 if (dy > 0) d_y += dy + offset.y;
7e085304
RR
686
687 XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y );
7de59551 688
e88be8c9 689 // wxLogDebug( "Copy: s_x %d s_y %d w %d h %d d_x %d d_y %d", s_x, s_y, w, h, d_x, d_y );
7e085304 690
e88be8c9 691 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
7e085304
RR
692
693 m_updateRegion.Union( rect );
694 m_clearRegion.Union( rect );
83df96d6 695 }
7de59551 696
7e085304 697 XFreeGC( xdisplay, xgc );
271f05f7
JS
698
699 // Move Clients, but not the scrollbars
700 // FIXME: There may be a better method to move a lot of Windows within X11
701 wxScrollBar *sbH = ((wxWindow *) this)->GetScrollbar( wxHORIZONTAL );
702 wxScrollBar *sbV = ((wxWindow *) this)->GetScrollbar( wxVERTICAL );
703 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
704 while ( node )
705 {
706 // Only propagate to non-top-level windows
707 wxWindow *win = node->GetData();
708 if ( win->GetParent() && win != sbH && win != sbV )
709 {
710 wxPoint pos = win->GetPosition();
711 // Add the delta to the old Position
712 pos.x += dx;
713 pos.y += dy;
714 win->SetPosition(pos);
715 }
716 node = node->GetNext();
717 }
83df96d6
JS
718}
719
720// ---------------------------------------------------------------------------
721// drag and drop
722// ---------------------------------------------------------------------------
723
724#if wxUSE_DRAG_AND_DROP
725
bc797f4c 726void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
83df96d6
JS
727{
728 // TODO
729}
730
731#endif
732
733// Old style file-manager drag&drop
bc797f4c 734void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept))
83df96d6
JS
735{
736 // TODO
737}
738
739// ----------------------------------------------------------------------------
740// tooltips
741// ----------------------------------------------------------------------------
742
743#if wxUSE_TOOLTIPS
744
bc797f4c 745void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
83df96d6
JS
746{
747 // TODO
748}
749
750#endif // wxUSE_TOOLTIPS
751
83df96d6
JS
752// ---------------------------------------------------------------------------
753// moving and resizing
754// ---------------------------------------------------------------------------
755
bc797f4c 756bool wxWindowX11::PreResize()
83df96d6 757{
ffd84c94 758 return true;
83df96d6
JS
759}
760
761// Get total size
bc797f4c 762void wxWindowX11::DoGetSize(int *x, int *y) const
83df96d6 763{
ab6b6b15 764 Window xwindow = (Window) m_mainWindow;
86fd8bda
RR
765
766 wxCHECK_RET( xwindow, wxT("invalid window") );
7de59551 767
59db9cfa 768 //XSync(wxGlobalDisplay(), False);
e941874b 769
86fd8bda
RR
770 XWindowAttributes attr;
771 Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr );
772 wxASSERT(status);
7de59551 773
86fd8bda
RR
774 if (status)
775 {
776 *x = attr.width /* + 2*m_borderSize */ ;
777 *y = attr.height /* + 2*m_borderSize */ ;
83df96d6 778 }
83df96d6
JS
779}
780
bc797f4c 781void wxWindowX11::DoGetPosition(int *x, int *y) const
83df96d6 782{
ab6b6b15 783 Window window = (Window) m_mainWindow;
b513212d 784 if (window)
83df96d6 785 {
59db9cfa 786 //XSync(wxGlobalDisplay(), False);
b513212d
JS
787 XWindowAttributes attr;
788 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
789 wxASSERT(status);
7de59551 790
b513212d
JS
791 if (status)
792 {
793 *x = attr.x;
794 *y = attr.y;
7de59551 795
b513212d
JS
796 // We may be faking the client origin. So a window that's really at (0, 30)
797 // may appear (to wxWin apps) to be at (0, 0).
798 if (GetParent())
799 {
800 wxPoint pt(GetParent()->GetClientAreaOrigin());
801 *x -= pt.x;
802 *y -= pt.y;
803 }
804 }
83df96d6 805 }
83df96d6
JS
806}
807
bc797f4c 808void wxWindowX11::DoScreenToClient(int *x, int *y) const
83df96d6 809{
b513212d 810 Display *display = wxGlobalDisplay();
bc797f4c 811 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
ab6b6b15 812 Window thisWindow = (Window) m_clientWindow;
83df96d6
JS
813
814 Window childWindow;
c5c01214
VZ
815 int xx = x ? *x : 0;
816 int yy = y ? *y : 0;
817 XTranslateCoordinates(display, rootWindow, thisWindow,
818 xx, yy, x ? x : &xx, y ? y : &yy,
819 &childWindow);
83df96d6
JS
820}
821
bc797f4c 822void wxWindowX11::DoClientToScreen(int *x, int *y) const
83df96d6 823{
b513212d 824 Display *display = wxGlobalDisplay();
bc797f4c 825 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
ab6b6b15 826 Window thisWindow = (Window) m_clientWindow;
83df96d6 827
9d529fa0 828 Window childWindow;
c5c01214
VZ
829 int xx = x ? *x : 0;
830 int yy = y ? *y : 0;
831 XTranslateCoordinates(display, thisWindow, rootWindow,
832 xx, yy, x ? x : &xx, y ? y : &yy,
833 &childWindow);
83df96d6
JS
834}
835
836
837// Get size *available for subwindows* i.e. excluding menu bar etc.
bc797f4c 838void wxWindowX11::DoGetClientSize(int *x, int *y) const
83df96d6 839{
ab6b6b15 840 Window window = (Window) m_mainWindow;
b513212d
JS
841
842 if (window)
843 {
844 XWindowAttributes attr;
3cd0b8c5 845 Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr );
b513212d 846 wxASSERT(status);
7de59551 847
b513212d
JS
848 if (status)
849 {
850 *x = attr.width ;
851 *y = attr.height ;
852 }
853 }
83df96d6
JS
854}
855
bc797f4c 856void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
83df96d6 857{
df0e1b64 858 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
7de59551 859
ab6b6b15 860 Window xwindow = (Window) m_mainWindow;
83df96d6 861
27398643
RR
862 wxCHECK_RET( xwindow, wxT("invalid window") );
863
864 XWindowAttributes attr;
865 Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr );
866 wxCHECK_RET( status, wxT("invalid window attributes") );
7de59551 867
27398643
RR
868 int new_x = attr.x;
869 int new_y = attr.y;
870 int new_w = attr.width;
871 int new_h = attr.height;
7de59551 872
ffd84c94 873 if (x != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 874 {
27398643 875 int yy = 0;
e5053ade 876 AdjustForParentClientOrigin( x, yy, sizeFlags);
27398643 877 new_x = x;
83df96d6 878 }
ffd84c94 879 if (y != wxDefaultCoord || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 880 {
27398643 881 int xx = 0;
e5053ade 882 AdjustForParentClientOrigin( xx, y, sizeFlags);
27398643 883 new_y = y;
83df96d6 884 }
ffd84c94 885 if (width != wxDefaultCoord)
83df96d6 886 {
27398643
RR
887 new_w = width;
888 if (new_w <= 0)
889 new_w = 20;
83df96d6 890 }
ffd84c94 891 if (height != wxDefaultCoord)
b513212d 892 {
27398643
RR
893 new_h = height;
894 if (new_h <= 0)
895 new_h = 20;
b513212d 896 }
7de59551 897
27398643 898 DoMoveWindow( new_x, new_y, new_w, new_h );
83df96d6
JS
899}
900
bc797f4c 901void wxWindowX11::DoSetClientSize(int width, int height)
83df96d6 902{
df0e1b64 903 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
7de59551 904
ab6b6b15 905 Window xwindow = (Window) m_mainWindow;
83df96d6 906
27398643 907 wxCHECK_RET( xwindow, wxT("invalid window") );
83df96d6 908
2f12683e 909 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
7de59551 910
ab6b6b15
RR
911 if (m_mainWindow != m_clientWindow)
912 {
913 xwindow = (Window) m_clientWindow;
7de59551 914
a17a79ba
RR
915 wxWindow *window = (wxWindow*) this;
916 wxRenderer *renderer = window->GetRenderer();
917 if (renderer)
ab6b6b15 918 {
a17a79ba
RR
919 wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) );
920 width -= border.x + border.width;
921 height -= border.y + border.height;
ab6b6b15 922 }
7de59551 923
ab6b6b15
RR
924 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
925 }
83df96d6
JS
926}
927
ab6b6b15
RR
928void wxWindowX11::DoMoveWindow(int x, int y, int width, int height)
929{
930 Window xwindow = (Window) m_mainWindow;
931
932 wxCHECK_RET( xwindow, wxT("invalid window") );
933
934#if !wxUSE_NANOX
935
936 XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height );
937 if (m_mainWindow != m_clientWindow)
938 {
939 xwindow = (Window) m_clientWindow;
7de59551 940
a17a79ba
RR
941 wxWindow *window = (wxWindow*) this;
942 wxRenderer *renderer = window->GetRenderer();
943 if (renderer)
ab6b6b15 944 {
a17a79ba
RR
945 wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) );
946 x = border.x;
947 y = border.y;
948 width -= border.x + border.width;
949 height -= border.y + border.height;
950 }
951 else
ab6b6b15
RR
952 {
953 x = 0;
954 y = 0;
955 }
7de59551 956
ab6b6b15
RR
957 wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL );
958 if (sb && sb->IsShown())
959 {
960 wxSize size = sb->GetSize();
961 height -= size.y;
962 }
963 sb = window->GetScrollbar( wxVERTICAL );
964 if (sb && sb->IsShown())
965 {
966 wxSize size = sb->GetSize();
967 width -= size.x;
968 }
7de59551 969
288efe84 970 XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, wxMax(1, width), wxMax(1, height) );
ab6b6b15 971 }
7de59551
RD
972
973#else
ab6b6b15
RR
974
975 XWindowChanges windowChanges;
976 windowChanges.x = x;
977 windowChanges.y = y;
978 windowChanges.width = width;
979 windowChanges.height = height;
980 windowChanges.stack_mode = 0;
981 int valueMask = CWX | CWY | CWWidth | CWHeight;
982
983 XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges );
7de59551 984
ab6b6b15
RR
985#endif
986}
987
024f89f9 988void wxWindowX11::DoSetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
83df96d6
JS
989{
990 m_minWidth = minW;
991 m_minHeight = minH;
992 m_maxWidth = maxW;
993 m_maxHeight = maxH;
994
461e93f9 995#if !wxUSE_NANOX
b513212d
JS
996 XSizeHints sizeHints;
997 sizeHints.flags = 0;
7de59551 998
b513212d 999 if (minW > -1 && minH > -1)
83df96d6 1000 {
b513212d
JS
1001 sizeHints.flags |= PMinSize;
1002 sizeHints.min_width = minW;
1003 sizeHints.min_height = minH;
1004 }
1005 if (maxW > -1 && maxH > -1)
1006 {
1007 sizeHints.flags |= PMaxSize;
1008 sizeHints.max_width = maxW;
1009 sizeHints.max_height = maxH;
1010 }
1011 if (incW > -1 && incH > -1)
1012 {
1013 sizeHints.flags |= PResizeInc;
1014 sizeHints.width_inc = incW;
1015 sizeHints.height_inc = incH;
83df96d6
JS
1016 }
1017
ab6b6b15 1018 XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints );
2f12683e 1019#endif
83df96d6
JS
1020}
1021
1022// ---------------------------------------------------------------------------
1023// text metrics
1024// ---------------------------------------------------------------------------
1025
bc797f4c 1026int wxWindowX11::GetCharHeight() const
83df96d6 1027{
4837b89e
JS
1028 wxFont font(GetFont());
1029 wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") );
83df96d6 1030
2b5f62a0
VZ
1031#if wxUSE_UNICODE
1032 // There should be an easier way.
1033 PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() );
4837b89e 1034 pango_layout_set_font_description( layout, font.GetNativeFontInfo()->description );
2b5f62a0
VZ
1035 pango_layout_set_text(layout, "H", 1 );
1036 int w,h;
1037 pango_layout_get_pixel_size(layout, &w, &h);
1038 g_object_unref( G_OBJECT( layout ) );
7de59551 1039
2b5f62a0
VZ
1040 return h;
1041#else
4837b89e 1042 WXFontStructPtr pFontStruct = font.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
1043
1044 int direction, ascent, descent;
1045 XCharStruct overall;
1046 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1047 &descent, &overall);
1048
1049 // return (overall.ascent + overall.descent);
1050 return (ascent + descent);
2b5f62a0 1051#endif
83df96d6
JS
1052}
1053
bc797f4c 1054int wxWindowX11::GetCharWidth() const
83df96d6 1055{
4837b89e
JS
1056 wxFont font(GetFont());
1057 wxCHECK_MSG( font.Ok(), 0, wxT("valid window font needed") );
83df96d6 1058
2b5f62a0
VZ
1059#if wxUSE_UNICODE
1060 // There should be an easier way.
1061 PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() );
4837b89e 1062 pango_layout_set_font_description( layout, font.GetNativeFontInfo()->description );
2b5f62a0
VZ
1063 pango_layout_set_text(layout, "H", 1 );
1064 int w,h;
1065 pango_layout_get_pixel_size(layout, &w, &h);
1066 g_object_unref( G_OBJECT( layout ) );
7de59551 1067
2b5f62a0
VZ
1068 return w;
1069#else
4837b89e 1070 WXFontStructPtr pFontStruct = font.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
1071
1072 int direction, ascent, descent;
1073 XCharStruct overall;
1074 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
1075 &descent, &overall);
1076
1077 return overall.width;
2b5f62a0 1078#endif
83df96d6
JS
1079}
1080
bc797f4c 1081void wxWindowX11::GetTextExtent(const wxString& string,
ffd84c94
WS
1082 int *x, int *y,
1083 int *descent, int *externalLeading,
1084 const wxFont *theFont) const
83df96d6 1085{
4837b89e 1086 wxFont fontToUse = GetFont();
0d1dff01 1087 if (theFont) fontToUse = *theFont;
83df96d6 1088
0d1dff01
RR
1089 wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
1090
ffd84c94 1091 if (string.empty())
2b5f62a0
VZ
1092 {
1093 if (x) (*x) = 0;
1094 if (y) (*y) = 0;
1095 return;
1096 }
1097
1098#if wxUSE_UNICODE
1099 PangoLayout *layout = pango_layout_new( wxTheApp->GetPangoContext() );
7de59551 1100
2b5f62a0
VZ
1101 PangoFontDescription *desc = fontToUse.GetNativeFontInfo()->description;
1102 pango_layout_set_font_description(layout, desc);
7de59551 1103
2b5f62a0
VZ
1104 const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
1105 pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
7de59551 1106
2b5f62a0
VZ
1107 PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
1108
7de59551 1109
2b5f62a0
VZ
1110 PangoRectangle rect;
1111 pango_layout_line_get_extents(line, NULL, &rect);
7de59551 1112
2b5f62a0
VZ
1113 if (x) (*x) = (wxCoord) (rect.width / PANGO_SCALE);
1114 if (y) (*y) = (wxCoord) (rect.height / PANGO_SCALE);
1115 if (descent)
1116 {
1117 // Do something about metrics here
1118 (*descent) = 0;
1119 }
1120 if (externalLeading) (*externalLeading) = 0; // ??
1121
1122 g_object_unref( G_OBJECT( layout ) );
1123#else
ab6b6b15 1124 WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay());
83df96d6
JS
1125
1126 int direction, ascent, descent2;
1127 XCharStruct overall;
851dee09 1128 int slen = string.length();
83df96d6 1129
3ad2d972 1130 XTextExtents((XFontStruct*) pFontStruct, (const char*) string.c_str(), slen,
83df96d6
JS
1131 &direction, &ascent, &descent2, &overall);
1132
1133 if ( x )
1134 *x = (overall.width);
1135 if ( y )
1136 *y = (ascent + descent2);
1137 if (descent)
1138 *descent = descent2;
1139 if (externalLeading)
1140 *externalLeading = 0;
2b5f62a0 1141#endif
83df96d6
JS
1142}
1143
1144// ----------------------------------------------------------------------------
1145// painting
1146// ----------------------------------------------------------------------------
1147
bc797f4c 1148void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect)
83df96d6 1149{
d02cb44e
RR
1150 if (eraseBack)
1151 {
1152 if (rect)
1153 {
1154 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1155 m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
1156 }
1157 else
1158 {
1159 int height,width;
1160 GetSize( &width, &height );
7de59551 1161
d02cb44e
RR
1162 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1163 m_clearRegion.Clear();
1164 m_clearRegion.Union( 0, 0, width, height );
1165 }
1166 }
83df96d6 1167
83df96d6
JS
1168 if (rect)
1169 {
d02cb44e
RR
1170 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1171 m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
83df96d6
JS
1172 }
1173 else
1174 {
0d1dff01
RR
1175 int height,width;
1176 GetSize( &width, &height );
7de59551 1177
d02cb44e
RR
1178 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1179 m_updateRegion.Clear();
1180 m_updateRegion.Union( 0, 0, width, height );
83df96d6 1181 }
d02cb44e 1182}
83df96d6 1183
d02cb44e
RR
1184void wxWindowX11::Update()
1185{
ab6b6b15
RR
1186 if (m_updateNcArea)
1187 {
065722d7 1188 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
ab6b6b15
RR
1189 // Send nc paint events.
1190 SendNcPaintEvents();
1191 }
7de59551 1192
d02cb44e 1193 if (!m_updateRegion.IsEmpty())
83df96d6 1194 {
ab6b6b15 1195 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
887dd52f
RR
1196 // Actually send erase events.
1197 SendEraseEvents();
7de59551 1198
887dd52f
RR
1199 // Actually send paint events.
1200 SendPaintEvents();
83df96d6 1201 }
83df96d6
JS
1202}
1203
887dd52f 1204void wxWindowX11::SendEraseEvents()
83df96d6 1205{
2f12683e 1206 if (m_clearRegion.IsEmpty()) return;
7de59551 1207
ab6b6b15 1208 wxClientDC dc( (wxWindow*)this );
f84fb4ad 1209 dc.SetDeviceClippingRegion( m_clearRegion );
7de59551 1210
2f12683e
RR
1211 wxEraseEvent erase_event( GetId(), &dc );
1212 erase_event.SetEventObject( this );
0b5c0e1a 1213
937013e0 1214 if (!HandleWindowEvent(erase_event) )
2f12683e 1215 {
2f12683e 1216 Display *xdisplay = wxGlobalDisplay();
f41bc3e3 1217 Window xwindow = (Window) GetClientAreaWindow();
c2c0dabf 1218 XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() );
7de59551 1219
2f12683e
RR
1220 wxRegionIterator upd( m_clearRegion );
1221 while (upd)
1934d291 1222 {
c2c0dabf 1223 XFillRectangle( xdisplay, xwindow, g_eraseGC,
2f12683e
RR
1224 upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
1225 upd ++;
1934d291 1226 }
83df96d6 1227 }
7de59551 1228
2f12683e 1229 m_clearRegion.Clear();
887dd52f
RR
1230}
1231
887dd52f
RR
1232void wxWindowX11::SendPaintEvents()
1233{
df0e1b64
JS
1234 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1235
ffd84c94 1236 m_clipPaintRegion = true;
7de59551 1237
1934d291
RR
1238 wxPaintEvent paint_event( GetId() );
1239 paint_event.SetEventObject( this );
937013e0 1240 HandleWindowEvent( paint_event );
7de59551 1241
0b5c0e1a 1242 m_updateRegion.Clear();
7de59551 1243
ffd84c94 1244 m_clipPaintRegion = false;
83df96d6
JS
1245}
1246
ab6b6b15
RR
1247void wxWindowX11::SendNcPaintEvents()
1248{
a17a79ba
RR
1249 wxWindow *window = (wxWindow*) this;
1250
1251 // All this for drawing the small square between the scrollbars.
1252 int width = 0;
1253 int height = 0;
1254 int x = 0;
1255 int y = 0;
1256 wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL );
1257 if (sb && sb->IsShown())
1258 {
1259 height = sb->GetSize().y;
1260 y = sb->GetPosition().y;
7de59551 1261
a17a79ba
RR
1262 sb = window->GetScrollbar( wxVERTICAL );
1263 if (sb && sb->IsShown())
1264 {
1265 width = sb->GetSize().x;
1266 x = sb->GetPosition().x;
1267
1268 Display *xdisplay = wxGlobalDisplay();
1269 Window xwindow = (Window) GetMainWindow();
1270 Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() );
1271 wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
1272 colour.CalcPixel( (WXColormap) cm );
7de59551 1273
a17a79ba 1274 XSetForeground( xdisplay, g_eraseGC, colour.GetPixel() );
7de59551 1275
a17a79ba
RR
1276 XFillRectangle( xdisplay, xwindow, g_eraseGC, x, y, width, height );
1277 }
1278 }
7de59551 1279
ab6b6b15
RR
1280 wxNcPaintEvent nc_paint_event( GetId() );
1281 nc_paint_event.SetEventObject( this );
937013e0 1282 HandleWindowEvent( nc_paint_event );
7de59551 1283
ffd84c94 1284 m_updateNcArea = false;
ab6b6b15
RR
1285}
1286
83df96d6
JS
1287// ----------------------------------------------------------------------------
1288// event handlers
1289// ----------------------------------------------------------------------------
1290
1291// Responds to colour changes: passes event on to children.
bc797f4c 1292void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
83df96d6 1293{
ac32ba44 1294 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
83df96d6
JS
1295 while ( node )
1296 {
1297 // Only propagate to non-top-level windows
1298 wxWindow *win = node->GetData();
1299 if ( win->GetParent() )
1300 {
1301 wxSysColourChangedEvent event2;
687706f5 1302 event.SetEventObject(win);
937013e0 1303 win->HandleWindowEvent(event2);
83df96d6
JS
1304 }
1305
1306 node = node->GetNext();
1307 }
1308}
1309
58ec2255
JS
1310// See handler for InFocus case in app.cpp for details.
1311wxWindow* g_GettingFocus = NULL;
1312
0d1dff01 1313void wxWindowX11::OnInternalIdle()
83df96d6 1314{
0d1dff01
RR
1315 // Update invalidated regions.
1316 Update();
7de59551 1317
83df96d6
JS
1318 // This calls the UI-update mechanism (querying windows for
1319 // menu/toolbar/control state information)
df707c27 1320 if (wxUpdateUIEvent::CanUpdate((wxWindow*) this) && IsShownOnScreen())
e39af974 1321 UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
3a0b23eb
JS
1322
1323 // Set the input focus if couldn't do it before
1324 if (m_needsInputFocus)
ff6b424a 1325 {
4cae9a20
JS
1326#if 0
1327 wxString msg;
1328 msg.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1329 printf(msg.c_str());
2b5f62a0
VZ
1330#endif
1331 SetFocus();
7de59551 1332
4cae9a20
JS
1333 // If it couldn't set the focus now, there's
1334 // no point in trying again.
ffd84c94 1335 m_needsInputFocus = false;
ff6b424a 1336 }
58ec2255 1337 g_GettingFocus = NULL;
83df96d6
JS
1338}
1339
83df96d6 1340// ----------------------------------------------------------------------------
77ffb593 1341// function which maintain the global hash table mapping Widgets to wxWidgets
83df96d6
JS
1342// ----------------------------------------------------------------------------
1343
b8033a5d 1344static bool DoAddWindowToTable(wxWindowHash *hash, Window w, wxWindow *win)
83df96d6 1345{
b8033a5d 1346 if ( !hash->insert(wxWindowHash::value_type(w, win)).second )
83df96d6 1347 {
b8033a5d
VZ
1348 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1349 (unsigned int)w, win->GetClassInfo()->GetClassName());
ffd84c94 1350 return false;
83df96d6
JS
1351 }
1352
2b5f62a0
VZ
1353 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1354 (unsigned int) w, win, win->GetClassInfo()->GetClassName());
83df96d6 1355
ffd84c94 1356 return true;
83df96d6
JS
1357}
1358
b8033a5d 1359static inline wxWindow *DoGetWindowFromTable(wxWindowHash *hash, Window w)
83df96d6 1360{
b8033a5d
VZ
1361 wxWindowHash::iterator i = hash->find(w);
1362 return i == hash->end() ? NULL : i->second;
83df96d6
JS
1363}
1364
b8033a5d 1365static inline void DoDeleteWindowFromTable(wxWindowHash *hash, Window w)
83df96d6 1366{
b8033a5d
VZ
1367 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w);
1368
1369 hash->erase(w);
83df96d6
JS
1370}
1371
1372// ----------------------------------------------------------------------------
b8033a5d 1373// public wrappers
83df96d6
JS
1374// ----------------------------------------------------------------------------
1375
b8033a5d 1376bool wxAddWindowToTable(Window w, wxWindow *win)
ab6b6b15 1377{
b8033a5d
VZ
1378 return DoAddWindowToTable(wxWidgetHashTable, w, win);
1379}
ab6b6b15 1380
b8033a5d
VZ
1381wxWindow *wxGetWindowFromTable(Window w)
1382{
1383 return DoGetWindowFromTable(wxWidgetHashTable, w);
1384}
ab6b6b15 1385
b8033a5d
VZ
1386void wxDeleteWindowFromTable(Window w)
1387{
1388 DoDeleteWindowFromTable(wxWidgetHashTable, w);
1389}
83df96d6 1390
b8033a5d
VZ
1391bool wxAddClientWindowToTable(Window w, wxWindow *win)
1392{
1393 return DoAddWindowToTable(wxClientWidgetHashTable, w, win);
ab6b6b15
RR
1394}
1395
1396wxWindow *wxGetClientWindowFromTable(Window w)
83df96d6 1397{
b8033a5d 1398 return DoGetWindowFromTable(wxClientWidgetHashTable, w);
83df96d6
JS
1399}
1400
ab6b6b15 1401void wxDeleteClientWindowFromTable(Window w)
83df96d6 1402{
b8033a5d 1403 DoDeleteWindowFromTable(wxClientWidgetHashTable, w);
83df96d6
JS
1404}
1405
ab6b6b15
RR
1406// ----------------------------------------------------------------------------
1407// X11-specific accessors
1408// ----------------------------------------------------------------------------
1409
bc797f4c 1410WXWindow wxWindowX11::GetMainWindow() const
83df96d6 1411{
ab6b6b15
RR
1412 return m_mainWindow;
1413}
1414
f41bc3e3 1415WXWindow wxWindowX11::GetClientAreaWindow() const
ab6b6b15
RR
1416{
1417 return m_clientWindow;
83df96d6
JS
1418}
1419
83df96d6
JS
1420// ----------------------------------------------------------------------------
1421// TranslateXXXEvent() functions
1422// ----------------------------------------------------------------------------
1423
89954433
VZ
1424bool wxTranslateMouseEvent(wxMouseEvent& wxevent,
1425 wxWindow *win,
1426 Window WXUNUSED(window),
1427 XEvent *xevent)
83df96d6 1428{
461e93f9 1429 switch (XEventGetType(xevent))
83df96d6 1430 {
1b0fb34b
JS
1431 case EnterNotify:
1432 case LeaveNotify:
83df96d6
JS
1433 case ButtonPress:
1434 case ButtonRelease:
1435 case MotionNotify:
1436 {
1437 wxEventType eventType = wxEVT_NULL;
1438
461e93f9 1439 if (XEventGetType(xevent) == EnterNotify)
83df96d6 1440 {
1b0fb34b
JS
1441 //if (local_event.xcrossing.mode!=NotifyNormal)
1442 // return ; // Ignore grab events
1443 eventType = wxEVT_ENTER_WINDOW;
1444 // canvas->GetEventHandler()->OnSetFocus();
1445 }
461e93f9 1446 else if (XEventGetType(xevent) == LeaveNotify)
1b0fb34b
JS
1447 {
1448 //if (local_event.xcrossingr.mode!=NotifyNormal)
1449 // return ; // Ignore grab events
1450 eventType = wxEVT_LEAVE_WINDOW;
1451 // canvas->GetEventHandler()->OnKillFocus();
83df96d6 1452 }
461e93f9 1453 else if (XEventGetType(xevent) == MotionNotify)
83df96d6
JS
1454 {
1455 eventType = wxEVT_MOTION;
1456 }
461e93f9 1457 else if (XEventGetType(xevent) == ButtonPress)
83df96d6 1458 {
461e93f9 1459 wxevent.SetTimestamp(XButtonEventGetTime(xevent));
83df96d6 1460 int button = 0;
461e93f9 1461 if (XButtonEventLChanged(xevent))
83df96d6
JS
1462 {
1463 eventType = wxEVT_LEFT_DOWN;
83df96d6
JS
1464 button = 1;
1465 }
461e93f9 1466 else if (XButtonEventMChanged(xevent))
83df96d6
JS
1467 {
1468 eventType = wxEVT_MIDDLE_DOWN;
83df96d6
JS
1469 button = 2;
1470 }
461e93f9 1471 else if (XButtonEventRChanged(xevent))
83df96d6
JS
1472 {
1473 eventType = wxEVT_RIGHT_DOWN;
83df96d6
JS
1474 button = 3;
1475 }
2cdb6fdb
VZ
1476 else if ( xevent->xbutton.button == Button4 ||
1477 xevent->xbutton.button == Button5 )
1478 {
1479 // this is the same value as used under wxMSW
1480 static const int WHEEL_DELTA = 120;
1481
1482 eventType = wxEVT_MOUSEWHEEL;
1483 button = xevent->xbutton.button;
1484
1485 wxevent.m_linesPerAction = 3;
1486 wxevent.m_wheelDelta = WHEEL_DELTA;
1487
1488 // Button 4 means mousewheel up, 5 means down
1489 wxevent.m_wheelRotation = button == Button4 ? WHEEL_DELTA
1490 : -WHEEL_DELTA;
1491 }
83df96d6
JS
1492
1493 // check for a double click
1b0fb34b 1494 // TODO: where can we get this value from?
b513212d 1495 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
7266b672 1496 long dclickTime = 200;
83df96d6
JS
1497 long ts = wxevent.GetTimestamp();
1498
1499 int buttonLast = win->GetLastClickedButton();
1500 long lastTS = win->GetLastClickTime();
1501 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
1502 {
1503 // I have a dclick
1504 win->SetLastClick(0, ts);
1505 if ( eventType == wxEVT_LEFT_DOWN )
1506 eventType = wxEVT_LEFT_DCLICK;
1507 else if ( eventType == wxEVT_MIDDLE_DOWN )
1508 eventType = wxEVT_MIDDLE_DCLICK;
1509 else if ( eventType == wxEVT_RIGHT_DOWN )
1510 eventType = wxEVT_RIGHT_DCLICK;
1511 }
1512 else
1513 {
1514 // not fast enough or different button
1515 win->SetLastClick(button, ts);
1516 }
1517 }
461e93f9 1518 else if (XEventGetType(xevent) == ButtonRelease)
83df96d6 1519 {
461e93f9 1520 if (XButtonEventLChanged(xevent))
83df96d6
JS
1521 {
1522 eventType = wxEVT_LEFT_UP;
83df96d6 1523 }
461e93f9 1524 else if (XButtonEventMChanged(xevent))
83df96d6
JS
1525 {
1526 eventType = wxEVT_MIDDLE_UP;
83df96d6 1527 }
461e93f9 1528 else if (XButtonEventRChanged(xevent))
83df96d6
JS
1529 {
1530 eventType = wxEVT_RIGHT_UP;
83df96d6 1531 }
ffd84c94 1532 else return false;
83df96d6
JS
1533 }
1534 else
1535 {
ffd84c94 1536 return false;
83df96d6
JS
1537 }
1538
1539 wxevent.SetEventType(eventType);
1540
461e93f9
JS
1541 wxevent.m_x = XButtonEventGetX(xevent);
1542 wxevent.m_y = XButtonEventGetY(xevent);
83df96d6
JS
1543
1544 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
461e93f9 1545 || (XButtonEventLIsDown(xevent)
83df96d6
JS
1546 && (eventType != wxEVT_LEFT_UP)));
1547 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
461e93f9 1548 || (XButtonEventMIsDown(xevent)
83df96d6
JS
1549 && (eventType != wxEVT_MIDDLE_UP)));
1550 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
461e93f9 1551 || (XButtonEventRIsDown (xevent)
83df96d6
JS
1552 && (eventType != wxEVT_RIGHT_UP)));
1553
461e93f9
JS
1554 wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent);
1555 wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent);
1556 wxevent.m_altDown = XButtonEventAltIsDown(xevent);
1557 wxevent.m_metaDown = XButtonEventMetaIsDown(xevent);
83df96d6
JS
1558
1559 wxevent.SetId(win->GetId());
1560 wxevent.SetEventObject(win);
1561
ffd84c94 1562 return true;
83df96d6
JS
1563 }
1564 }
ffd84c94 1565 return false;
83df96d6
JS
1566}
1567
2b5f62a0 1568bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent, bool isAscii)
83df96d6 1569{
461e93f9 1570 switch (XEventGetType(xevent))
83df96d6
JS
1571 {
1572 case KeyPress:
1573 case KeyRelease:
1574 {
1575 char buf[20];
1576
1577 KeySym keySym;
83df96d6
JS
1578 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
1579 int id = wxCharCodeXToWX (keySym);
2b5f62a0
VZ
1580 // id may be WXK_xxx code - these are outside ASCII range, so we
1581 // can't just use toupper() on id.
1582 // Only change this if we want the raw key that was pressed,
1583 // and don't change it if we want an ASCII value.
1584 if (!isAscii && (id >= 'a' && id <= 'z'))
1585 {
1586 id = id + 'A' - 'a';
1587 }
83df96d6 1588
461e93f9
JS
1589 wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent);
1590 wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent);
1591 wxevent.m_altDown = XKeyEventAltIsDown(xevent);
1592 wxevent.m_metaDown = XKeyEventMetaIsDown(xevent);
83df96d6 1593 wxevent.SetEventObject(win);
2b5f62a0 1594 wxevent.m_keyCode = id;
461e93f9 1595 wxevent.SetTimestamp(XKeyEventGetTime(xevent));
83df96d6 1596
461e93f9
JS
1597 wxevent.m_x = XKeyEventGetX(xevent);
1598 wxevent.m_y = XKeyEventGetY(xevent);
83df96d6 1599
2b5f62a0 1600 return id > -1;
83df96d6
JS
1601 }
1602 default:
1603 break;
1604 }
ffd84c94 1605 return false;
83df96d6
JS
1606}
1607
1608// ----------------------------------------------------------------------------
1609// Colour stuff
1610// ----------------------------------------------------------------------------
1611
bc797f4c 1612bool wxWindowX11::SetBackgroundColour(const wxColour& col)
83df96d6 1613{
56cb684a 1614 wxWindowBase::SetBackgroundColour(col);
83df96d6 1615
3cd0b8c5
RR
1616 Display *xdisplay = (Display*) wxGlobalDisplay();
1617 int xscreen = DefaultScreen( xdisplay );
1618 Colormap cm = DefaultColormap( xdisplay, xscreen );
1619
ba696cfa 1620 m_backgroundColour.CalcPixel( (WXColormap) cm );
7de59551 1621
c2c0dabf
RR
1622 // We don't set the background colour as we paint
1623 // the background ourselves.
1624 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
7de59551 1625
ffd84c94 1626 return true;
83df96d6
JS
1627}
1628
bc797f4c 1629bool wxWindowX11::SetForegroundColour(const wxColour& col)
83df96d6
JS
1630{
1631 if ( !wxWindowBase::SetForegroundColour(col) )
ffd84c94 1632 return false;
83df96d6 1633
ffd84c94 1634 return true;
83df96d6
JS
1635}
1636
83df96d6
JS
1637// ----------------------------------------------------------------------------
1638// global functions
1639// ----------------------------------------------------------------------------
1640
1641wxWindow *wxGetActiveWindow()
1642{
1643 // TODO
54385bdb 1644 wxFAIL_MSG(wxT("Not implemented"));
83df96d6
JS
1645 return NULL;
1646}
1647
1648/* static */
1649wxWindow *wxWindowBase::GetCapture()
1650{
1651 return (wxWindow *)g_captureWindow;
1652}
1653
1654
1655// Find the wxWindow at the current mouse position, returning the mouse
1656// position.
1657wxWindow* wxFindWindowAtPointer(wxPoint& pt)
1658{
89954433
VZ
1659 pt = wxGetMousePosition();
1660 return wxFindWindowAtPoint(pt);
83df96d6
JS
1661}
1662
0cbc5287 1663void wxGetMouseState(int& rootX, int& rootY, unsigned& maskReturn)
83df96d6 1664{
461e93f9
JS
1665#if wxUSE_NANOX
1666 /* TODO */
0cbc5287
MW
1667 rootX = rootY = 0;
1668 maskReturn = 0;
461e93f9 1669#else
b513212d 1670 Display *display = wxGlobalDisplay();
83df96d6
JS
1671 Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
1672 Window rootReturn, childReturn;
0cbc5287 1673 int winX, winY;
83df96d6
JS
1674
1675 XQueryPointer (display,
2b5f62a0
VZ
1676 rootWindow,
1677 &rootReturn,
83df96d6
JS
1678 &childReturn,
1679 &rootX, &rootY, &winX, &winY, &maskReturn);
461e93f9 1680#endif
83df96d6
JS
1681}
1682
0cbc5287
MW
1683// Get the current mouse position.
1684wxPoint wxGetMousePosition()
1685{
1686 int x, y;
1687 unsigned mask;
1688
1689 wxGetMouseState(x, y, mask);
1690 return wxPoint(x, y);
1691}
1692
1693wxMouseState wxGetMouseState()
1694{
1695 wxMouseState ms;
1696 int x, y;
1697 unsigned mask;
1698
1699 wxGetMouseState(x, y, mask);
1700
1701 ms.SetX(x);
1702 ms.SetY(y);
1703
1704 ms.SetLeftDown(mask & Button1Mask);
1705 ms.SetMiddleDown(mask & Button2Mask);
1706 ms.SetRightDown(mask & Button3Mask);
1707
1708 ms.SetControlDown(mask & ControlMask);
1709 ms.SetShiftDown(mask & ShiftMask);
af1a6227
MW
1710 ms.SetAltDown(mask & Mod3Mask);
1711 ms.SetMetaDown(mask & Mod1Mask);
0cbc5287
MW
1712
1713 return ms;
1714}
1715
83df96d6
JS
1716
1717// ----------------------------------------------------------------------------
1718// wxNoOptimize: switch off size optimization
1719// ----------------------------------------------------------------------------
1720
1721int wxNoOptimize::ms_count = 0;
1722
c2c0dabf
RR
1723
1724// ----------------------------------------------------------------------------
1725// wxDCModule
1726// ----------------------------------------------------------------------------
1727
1728class wxWinModule : public wxModule
1729{
1730public:
b886fae6
VZ
1731 wxWinModule()
1732 {
1733 // we must be cleaned up before the display is closed
1734 AddDependency(wxClassInfo::FindClass(_T("wxX11DisplayModule")));
1735 }
1736
1737 virtual bool OnInit();
1738 virtual void OnExit();
c2c0dabf
RR
1739
1740private:
1741 DECLARE_DYNAMIC_CLASS(wxWinModule)
1742};
1743
1744IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule)
1745
1746bool wxWinModule::OnInit()
1747{
1748 Display *xdisplay = wxGlobalDisplay();
1749 int xscreen = DefaultScreen( xdisplay );
1750 Window xroot = RootWindow( xdisplay, xscreen );
1751 g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL );
1752 XSetFillStyle( xdisplay, g_eraseGC, FillSolid );
7de59551 1753
ffd84c94 1754 return true;
c2c0dabf
RR
1755}
1756
1757void wxWinModule::OnExit()
1758{
1759 Display *xdisplay = wxGlobalDisplay();
1760 XFreeGC( xdisplay, g_eraseGC );
1761}