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