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