]> git.saurik.com Git - wxWidgets.git/blame - src/x11/window.cpp
Made sure events for defunct windows are no longer handled.
[wxWidgets.git] / src / x11 / window.cpp
CommitLineData
83df96d6
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: windows.cpp
3// Purpose: wxWindow
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "window.h"
22#endif
23
83df96d6
JS
24#include "wx/setup.h"
25#include "wx/menu.h"
26#include "wx/dc.h"
27#include "wx/dcclient.h"
28#include "wx/utils.h"
29#include "wx/app.h"
30#include "wx/panel.h"
31#include "wx/layout.h"
32#include "wx/dialog.h"
33#include "wx/listbox.h"
34#include "wx/button.h"
35#include "wx/settings.h"
36#include "wx/msgdlg.h"
37#include "wx/frame.h"
38#include "wx/scrolwin.h"
39#include "wx/module.h"
40#include "wx/menuitem.h"
41#include "wx/log.h"
42
43#if wxUSE_DRAG_AND_DROP
44 #include "wx/dnd.h"
45#endif
46
bc797f4c 47#include "wx/x11/private.h"
7266b672 48#include "X11/Xutil.h"
83df96d6
JS
49
50#include <string.h>
51
52// ----------------------------------------------------------------------------
53// constants
54// ----------------------------------------------------------------------------
55
56static const int SCROLL_MARGIN = 4;
57
58// ----------------------------------------------------------------------------
59// global variables for this module
60// ----------------------------------------------------------------------------
61
62extern wxHashTable *wxWidgetHashTable;
63static wxWindow* g_captureWindow = NULL;
64
83df96d6
JS
65// ----------------------------------------------------------------------------
66// macros
67// ----------------------------------------------------------------------------
68
69#define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
70#define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
71#define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
72
73// ----------------------------------------------------------------------------
74// event tables
75// ----------------------------------------------------------------------------
76
8354aa92 77IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase)
83df96d6 78
bc797f4c
JS
79BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase)
80 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged)
81 EVT_IDLE(wxWindowX11::OnIdle)
82END_EVENT_TABLE()
83df96d6
JS
83
84// ============================================================================
85// implementation
86// ============================================================================
87
88// ----------------------------------------------------------------------------
89// helper functions
90// ----------------------------------------------------------------------------
91
83df96d6
JS
92// ----------------------------------------------------------------------------
93// constructors
94// ----------------------------------------------------------------------------
95
bc797f4c 96void wxWindowX11::Init()
83df96d6
JS
97{
98 // generic initializations first
99 InitBase();
100
7266b672 101 // X11-specific
7266b672 102 m_mainWidget = (WXWindow) 0;
83df96d6 103
83df96d6
JS
104 m_winCaptured = FALSE;
105
106 m_isShown = TRUE;
107 m_isBeingDeleted = FALSE;
108
83df96d6
JS
109 m_lastTS = 0;
110 m_lastButton = 0;
83df96d6
JS
111}
112
113// real construction (Init() must have been called before!)
bc797f4c 114bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
83df96d6
JS
115 const wxPoint& pos,
116 const wxSize& size,
117 long style,
118 const wxString& name)
119{
120 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
121
122 CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
123
b513212d
JS
124 if (parent)
125 parent->AddChild(this);
83df96d6
JS
126
127 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
128 m_foregroundColour = *wxBLACK;
129
b513212d
JS
130 int w = size.GetWidth();
131 int h = size.GetHeight();
132 int x = size.GetX();
133 int y = size.GetY();
178572bb
RR
134 if (w == -1) w = 20;
135 if (h == -1) h = 20;
b513212d
JS
136 if (x == -1) x = 0;
137 if (y == -1) y = 0;
83df96d6 138
b513212d
JS
139 int screen = DefaultScreen(wxGlobalDisplay());
140
141 Window parentWindow;
142 if (parent)
d02cb44e 143 parentWindow = (Window) parent->GetMainWindow();
b513212d
JS
144 else
145 parentWindow = RootWindow(wxGlobalDisplay(), screen);
146
178572bb 147 Window window = XCreateSimpleWindow(wxGlobalDisplay(), parentWindow,
d02cb44e 148 x, y, w, h, 0,
b513212d 149 m_backgroundColour.AllocColour(wxGlobalDisplay()),
ea596687
JS
150 m_foregroundColour.AllocColour(wxGlobalDisplay()));
151 m_mainWidget = (WXWindow) window;
b513212d
JS
152
153 // Select event types wanted
154 XSelectInput(wxGlobalDisplay(), window,
155 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
156 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
157 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
158 PropertyChangeMask);
159
b513212d
JS
160 wxAddWindowToTable(window, (wxWindow*) this);
161
b28d3abf
JS
162 // Is a subwindow, so map immediately
163 m_isShown = TRUE;
164 XMapWindow(wxGlobalDisplay(), window);
83df96d6
JS
165
166 // Without this, the cursor may not be restored properly (e.g. in splitter
167 // sample).
168 SetCursor(*wxSTANDARD_CURSOR);
169 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
170 SetSize(pos.x, pos.y, size.x, size.y);
171
172 return TRUE;
173}
174
175// Destructor
7266b672 176wxWindowX11::~wxWindowX11()
83df96d6
JS
177{
178 if (g_captureWindow == this)
179 g_captureWindow = NULL;
180
181 m_isBeingDeleted = TRUE;
182
7266b672 183 // X11-specific actions first
d02cb44e
RR
184 Window main = (Window) m_mainWidget;
185 if ( main )
83df96d6
JS
186 {
187 // Removes event handlers
d02cb44e 188 //DetachWidget(main);
83df96d6
JS
189 }
190
d02cb44e 191 if (m_parent)
83df96d6
JS
192 m_parent->RemoveChild( this );
193
d02cb44e 194 DestroyChildren();
83df96d6
JS
195
196 // Destroy the window
d02cb44e 197 if (main)
83df96d6 198 {
d02cb44e
RR
199 XSelectInput( wxGlobalDisplay(), main, NoEventMask);
200 wxDeleteWindowFromTable( main );
201 XDestroyWindow( wxGlobalDisplay(), main );
202 m_mainWidget = NULL;
83df96d6 203 }
83df96d6
JS
204}
205
206// ---------------------------------------------------------------------------
207// basic operations
208// ---------------------------------------------------------------------------
209
bc797f4c 210void wxWindowX11::SetFocus()
83df96d6 211{
b28d3abf 212 Window wMain = (Window) GetMainWindow();
b513212d
JS
213 if (wMain)
214 {
215 XSetInputFocus(wxGlobalDisplay(), wMain, RevertToParent, CurrentTime);
216
217 XWMHints wmhints;
218 wmhints.flags = InputHint;
219 wmhints.input = True;
6a44bffd 220 XSetWMHints(wxGlobalDisplay(), wMain, &wmhints);
b513212d 221 }
83df96d6
JS
222}
223
224// Get the window with the focus
225wxWindow *wxWindowBase::FindFocus()
226{
b513212d
JS
227 Window wFocus = (Window) 0;
228 int revert = 0;
bc797f4c 229
b513212d
JS
230 XGetInputFocus(wxGlobalDisplay(), & wFocus, & revert);
231 if (wFocus)
83df96d6 232 {
b513212d
JS
233 wxWindow *win = NULL;
234 do
83df96d6 235 {
b513212d
JS
236 win = wxGetWindowFromTable(wFocus);
237 wFocus = wxGetWindowParent(wFocus);
238 } while (wFocus && !win);
239
240 return win;
83df96d6
JS
241 }
242
b513212d 243 return NULL;
83df96d6
JS
244}
245
b513212d
JS
246// Enabling/disabling handled by event loop, and not sending events
247// if disabled.
bc797f4c 248bool wxWindowX11::Enable(bool enable)
83df96d6
JS
249{
250 if ( !wxWindowBase::Enable(enable) )
251 return FALSE;
b513212d 252
83df96d6
JS
253 return TRUE;
254}
255
bc797f4c 256bool wxWindowX11::Show(bool show)
83df96d6
JS
257{
258 if ( !wxWindowBase::Show(show) )
259 return FALSE;
260
83df96d6
JS
261 Window xwin = (Window) GetXWindow();
262 Display *xdisp = (Display*) GetXDisplay();
263 if (show)
b513212d 264 {
83df96d6 265 XMapWindow(xdisp, xwin);
b513212d 266 }
83df96d6 267 else
b513212d 268 {
83df96d6 269 XUnmapWindow(xdisp, xwin);
b513212d 270 }
83df96d6
JS
271
272 return TRUE;
273}
274
275// Raise the window to the top of the Z order
bc797f4c 276void wxWindowX11::Raise()
83df96d6 277{
d02cb44e
RR
278 if (m_mainWidget)
279 XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWidget );
83df96d6
JS
280}
281
282// Lower the window to the bottom of the Z order
bc797f4c 283void wxWindowX11::Lower()
83df96d6 284{
d02cb44e
RR
285 if (m_mainWidget)
286 XLowerWindow( wxGlobalDisplay(), (Window) m_mainWidget );
83df96d6
JS
287}
288
bc797f4c 289void wxWindowX11::DoCaptureMouse()
83df96d6 290{
7266b672 291 g_captureWindow = (wxWindow*) this;
83df96d6
JS
292 if ( m_winCaptured )
293 return;
294
b513212d
JS
295 if (GetMainWindow())
296 {
297 int res = XGrabPointer(wxGlobalDisplay(), (Window) GetMainWindow(),
298 FALSE,
299 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
300 GrabModeAsync,
301 GrabModeAsync,
302 None,
303 None, /* cursor */ // TODO: This may need to be set to the cursor of this window
304 CurrentTime);
305
b28d3abf 306 if (res != GrabSuccess)
b513212d 307 {
b28d3abf
JS
308 wxLogDebug("Failed to grab pointer.");
309 return;
b513212d 310 }
b28d3abf
JS
311
312 res = XGrabButton(wxGlobalDisplay(), AnyButton, AnyModifier,
313 (Window) GetMainWindow(),
314 FALSE,
315 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask,
316 GrabModeAsync,
317 GrabModeAsync,
318 None,
319 None);
320
321 if (res != GrabSuccess)
322 {
323 wxLogDebug("Failed to grab mouse buttons.");
324 XUngrabPointer(wxGlobalDisplay(), CurrentTime);
325 return;
326 }
327
328 res = XGrabKeyboard(wxGlobalDisplay(), (Window) GetMainWindow(),
1b0b798d
RR
329#if 0
330 ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask,
331#else
b28d3abf 332 FALSE,
1b0b798d 333#endif
b28d3abf
JS
334 GrabModeAsync,
335 GrabModeAsync,
336 CurrentTime);
337
338 if (res != GrabSuccess)
339 {
340 wxLogDebug("Failed to grab keyboard.");
341 XUngrabPointer(wxGlobalDisplay(), CurrentTime);
342 XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier,
343 (Window) GetMainWindow());
344 return;
345 }
346
347 m_winCaptured = TRUE;
b513212d 348 }
83df96d6
JS
349}
350
bc797f4c 351void wxWindowX11::DoReleaseMouse()
83df96d6
JS
352{
353 g_captureWindow = NULL;
354 if ( !m_winCaptured )
355 return;
356
178572bb 357 Window wMain = (Window)GetMainWindow();
b513212d 358
83df96d6 359 if ( wMain )
b28d3abf 360 {
b513212d 361 XUngrabPointer(wxGlobalDisplay(), wMain);
b28d3abf
JS
362 XUngrabButton(wxGlobalDisplay(), AnyButton, AnyModifier,
363 wMain);
364 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime);
365 }
83df96d6
JS
366
367 m_winCaptured = FALSE;
368}
369
bc797f4c 370bool wxWindowX11::SetFont(const wxFont& font)
83df96d6
JS
371{
372 if ( !wxWindowBase::SetFont(font) )
373 {
374 // nothing to do
375 return FALSE;
376 }
377
83df96d6
JS
378 return TRUE;
379}
380
bc797f4c 381bool wxWindowX11::SetCursor(const wxCursor& cursor)
83df96d6
JS
382{
383 if ( !wxWindowBase::SetCursor(cursor) )
384 {
385 // no change
386 return FALSE;
387 }
388
83df96d6
JS
389 wxCursor* cursor2 = NULL;
390 if (m_cursor.Ok())
391 cursor2 = & m_cursor;
392 else
393 cursor2 = wxSTANDARD_CURSOR;
394
395 WXDisplay *dpy = GetXDisplay();
396 WXCursor x_cursor = cursor2->GetXCursor(dpy);
397
bc797f4c 398 Window win = (Window) GetMainWindow();
83df96d6
JS
399 XDefineCursor((Display*) dpy, win, (Cursor) x_cursor);
400
401 return TRUE;
402}
403
404// Coordinates relative to the window
bc797f4c 405void wxWindowX11::WarpPointer (int x, int y)
83df96d6 406{
d02cb44e
RR
407 if (m_mainWidget)
408 XWarpPointer( wxGlobalDisplay(), None, (Window) m_mainWidget, 0, 0, 0, 0, x, y);
83df96d6
JS
409}
410
83df96d6 411// Does a physical scroll
bc797f4c 412void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
83df96d6
JS
413{
414 int x, y, w, h;
415 if (rect)
416 {
417 // Use specified rectangle
418 x = rect->x; y = rect->y; w = rect->width; h = rect->height;
419 }
420 else
421 {
422 // Use whole client area
423 x = 0; y = 0;
424 GetClientSize(& w, & h);
425 }
bc797f4c 426
83df96d6
JS
427 wxNode *cnode = m_children.First();
428 while (cnode)
429 {
430 wxWindow *child = (wxWindow*) cnode->Data();
bc797f4c
JS
431 int sx = 0;
432 int sy = 0;
433 child->GetSize( &sx, &sy );
83df96d6 434 wxPoint pos( child->GetPosition() );
bc797f4c
JS
435 child->SetSize( pos.x + dx, pos.y + dy, sx, sy, wxSIZE_ALLOW_MINUS_ONE );
436 cnode = cnode->Next();
83df96d6 437 }
bc797f4c 438
83df96d6
JS
439 int x1 = (dx >= 0) ? x : x - dx;
440 int y1 = (dy >= 0) ? y : y - dy;
441 int w1 = w - abs(dx);
442 int h1 = h - abs(dy);
443 int x2 = (dx >= 0) ? x + dx : x;
444 int y2 = (dy >= 0) ? y + dy : y;
bc797f4c 445
7266b672 446 wxClientDC dc((wxWindow*) this);
bc797f4c 447
83df96d6 448 dc.SetLogicalFunction (wxCOPY);
bc797f4c
JS
449
450 Window window = (Window) GetMainWindow();
b513212d 451 Display* display = wxGlobalDisplay();
bc797f4c 452
83df96d6 453 XCopyArea(display, window, window, (GC) dc.GetGC(),
bc797f4c
JS
454 x1, y1, w1, h1, x2, y2);
455
83df96d6
JS
456 dc.SetAutoSetting(TRUE);
457 wxBrush brush(GetBackgroundColour(), wxSOLID);
458 dc.SetBrush(brush); // FIXME: needed?
bc797f4c 459
83df96d6
JS
460 // We'll add rectangles to the list of update rectangles according to which
461 // bits we've exposed.
462 wxList updateRects;
bc797f4c 463
83df96d6
JS
464 if (dx > 0)
465 {
466 wxRect *rect = new wxRect;
467 rect->x = x;
468 rect->y = y;
469 rect->width = dx;
470 rect->height = h;
bc797f4c 471
83df96d6
JS
472 XFillRectangle(display, window,
473 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
bc797f4c 474
83df96d6
JS
475 rect->x = rect->x;
476 rect->y = rect->y;
477 rect->width = rect->width;
478 rect->height = rect->height;
bc797f4c 479
83df96d6
JS
480 updateRects.Append((wxObject*) rect);
481 }
482 else if (dx < 0)
483 {
484 wxRect *rect = new wxRect;
bc797f4c 485
83df96d6
JS
486 rect->x = x + w + dx;
487 rect->y = y;
488 rect->width = -dx;
489 rect->height = h;
bc797f4c 490
83df96d6
JS
491 XFillRectangle(display, window,
492 (GC) dc.GetGC(), rect->x, rect->y, rect->width,
493 rect->height);
bc797f4c 494
83df96d6
JS
495 rect->x = rect->x;
496 rect->y = rect->y;
497 rect->width = rect->width;
498 rect->height = rect->height;
bc797f4c 499
83df96d6
JS
500 updateRects.Append((wxObject*) rect);
501 }
502 if (dy > 0)
503 {
504 wxRect *rect = new wxRect;
bc797f4c 505
83df96d6
JS
506 rect->x = x;
507 rect->y = y;
508 rect->width = w;
509 rect->height = dy;
bc797f4c 510
83df96d6
JS
511 XFillRectangle(display, window,
512 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
bc797f4c 513
83df96d6
JS
514 rect->x = rect->x;
515 rect->y = rect->y;
516 rect->width = rect->width;
517 rect->height = rect->height;
bc797f4c 518
83df96d6
JS
519 updateRects.Append((wxObject*) rect);
520 }
521 else if (dy < 0)
522 {
523 wxRect *rect = new wxRect;
bc797f4c 524
83df96d6
JS
525 rect->x = x;
526 rect->y = y + h + dy;
527 rect->width = w;
528 rect->height = -dy;
bc797f4c 529
83df96d6
JS
530 XFillRectangle(display, window,
531 (GC) dc.GetGC(), rect->x, rect->y, rect->width, rect->height);
bc797f4c 532
83df96d6
JS
533 rect->x = rect->x;
534 rect->y = rect->y;
535 rect->width = rect->width;
536 rect->height = rect->height;
bc797f4c 537
83df96d6
JS
538 updateRects.Append((wxObject*) rect);
539 }
540 dc.SetBrush(wxNullBrush);
bc797f4c 541
83df96d6 542 // Now send expose events
bc797f4c 543
83df96d6
JS
544 wxNode* node = updateRects.First();
545 while (node)
546 {
547 wxRect* rect = (wxRect*) node->Data();
548 XExposeEvent event;
bc797f4c 549
83df96d6
JS
550 event.type = Expose;
551 event.display = display;
552 event.send_event = True;
553 event.window = window;
bc797f4c 554
83df96d6
JS
555 event.x = rect->x;
556 event.y = rect->y;
557 event.width = rect->width;
558 event.height = rect->height;
bc797f4c 559
83df96d6 560 event.count = 0;
bc797f4c 561
83df96d6 562 XSendEvent(display, window, False, ExposureMask, (XEvent *)&event);
bc797f4c 563
83df96d6 564 node = node->Next();
bc797f4c 565
83df96d6 566 }
bc797f4c 567
83df96d6
JS
568 // Delete the update rects
569 node = updateRects.First();
570 while (node)
571 {
572 wxRect* rect = (wxRect*) node->Data();
573 delete rect;
574 node = node->Next();
575 }
bc797f4c
JS
576
577 // TODO
83df96d6 578
bc797f4c 579 // XmUpdateDisplay((Widget) GetMainWidget());
83df96d6
JS
580}
581
582// ---------------------------------------------------------------------------
583// drag and drop
584// ---------------------------------------------------------------------------
585
586#if wxUSE_DRAG_AND_DROP
587
bc797f4c 588void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
83df96d6
JS
589{
590 // TODO
591}
592
593#endif
594
595// Old style file-manager drag&drop
bc797f4c 596void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept))
83df96d6
JS
597{
598 // TODO
599}
600
601// ----------------------------------------------------------------------------
602// tooltips
603// ----------------------------------------------------------------------------
604
605#if wxUSE_TOOLTIPS
606
bc797f4c 607void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
83df96d6
JS
608{
609 // TODO
610}
611
612#endif // wxUSE_TOOLTIPS
613
83df96d6
JS
614// ---------------------------------------------------------------------------
615// moving and resizing
616// ---------------------------------------------------------------------------
617
bc797f4c 618bool wxWindowX11::PreResize()
83df96d6
JS
619{
620 return TRUE;
621}
622
623// Get total size
bc797f4c 624void wxWindowX11::DoGetSize(int *x, int *y) const
83df96d6 625{
d02cb44e 626 Window window = (Window) m_mainWidget;
b513212d 627 if (window)
83df96d6 628 {
b513212d
JS
629 XWindowAttributes attr;
630 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
631 wxASSERT(status);
632
633 if (status)
634 {
d02cb44e
RR
635 *x = attr.width /* + 2*m_borderSize */ ;
636 *y = attr.height /* + 2*m_borderSize */ ;
b513212d 637 }
83df96d6 638 }
83df96d6
JS
639}
640
bc797f4c 641void wxWindowX11::DoGetPosition(int *x, int *y) const
83df96d6 642{
d02cb44e 643 Window window = (Window) m_mainWidget;
b513212d 644 if (window)
83df96d6 645 {
b513212d
JS
646 XWindowAttributes attr;
647 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
648 wxASSERT(status);
649
650 if (status)
651 {
652 *x = attr.x;
653 *y = attr.y;
654
655 // We may be faking the client origin. So a window that's really at (0, 30)
656 // may appear (to wxWin apps) to be at (0, 0).
657 if (GetParent())
658 {
659 wxPoint pt(GetParent()->GetClientAreaOrigin());
660 *x -= pt.x;
661 *y -= pt.y;
662 }
663 }
83df96d6 664 }
83df96d6
JS
665}
666
bc797f4c 667void wxWindowX11::DoScreenToClient(int *x, int *y) const
83df96d6 668{
b513212d 669 Display *display = wxGlobalDisplay();
bc797f4c 670 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
d02cb44e 671 Window thisWindow = (Window) m_mainWidget;
83df96d6
JS
672
673 Window childWindow;
674 int xx = *x;
675 int yy = *y;
676 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
677}
678
bc797f4c 679void wxWindowX11::DoClientToScreen(int *x, int *y) const
83df96d6 680{
b513212d 681 Display *display = wxGlobalDisplay();
bc797f4c 682 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
d02cb44e 683 Window thisWindow = (Window) m_mainWidget;
83df96d6
JS
684
685 Window childWindow;
686 int xx = *x;
687 int yy = *y;
688 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
689}
690
691
692// Get size *available for subwindows* i.e. excluding menu bar etc.
bc797f4c 693void wxWindowX11::DoGetClientSize(int *x, int *y) const
83df96d6 694{
d02cb44e 695 Window window = (Window) m_mainWidget;
b513212d
JS
696
697 if (window)
698 {
699 XWindowAttributes attr;
700 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
701 wxASSERT(status);
702
703 if (status)
704 {
705 *x = attr.width ;
706 *y = attr.height ;
707 }
708 }
83df96d6
JS
709}
710
bc797f4c 711void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
83df96d6 712{
b513212d
JS
713 if (!GetMainWindow())
714 return;
83df96d6 715
b513212d
JS
716 XWindowChanges windowChanges;
717 int valueMask = 0;
718
719 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 720 {
b513212d
JS
721 windowChanges.x = x;
722 valueMask |= CWX;
83df96d6 723 }
b513212d 724 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 725 {
b513212d
JS
726 windowChanges.y = y;
727 valueMask |= CWY;
83df96d6 728 }
b513212d 729 if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
83df96d6 730 {
d02cb44e 731 windowChanges.width = width /* - m_borderSize*2 */;
b513212d 732 valueMask |= CWWidth;
83df96d6 733 }
b513212d
JS
734 if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
735 {
d02cb44e 736 windowChanges.height = height /* -m_borderSize*2*/;
b513212d
JS
737 valueMask |= CWHeight;
738 }
178572bb 739 AdjustForParentClientOrigin( x, y, sizeFlags);
b513212d
JS
740
741 XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(),
742 valueMask, & windowChanges);
83df96d6
JS
743}
744
bc797f4c 745void wxWindowX11::DoSetClientSize(int width, int height)
83df96d6 746{
b513212d 747 if (!GetMainWindow())
83df96d6 748 return;
83df96d6 749
b513212d
JS
750 XWindowChanges windowChanges;
751 int valueMask = 0;
83df96d6 752
b513212d
JS
753 if (width != -1)
754 {
755 windowChanges.width = width ;
756 valueMask |= CWWidth;
757 }
758 if (height != -1)
759 {
760 windowChanges.height = height ;
761 valueMask |= CWHeight;
762 }
763 XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(),
764 valueMask, & windowChanges);
83df96d6
JS
765}
766
767// For implementation purposes - sometimes decorations make the client area
768// smaller
bc797f4c 769wxPoint wxWindowX11::GetClientAreaOrigin() const
83df96d6
JS
770{
771 return wxPoint(0, 0);
772}
773
774// Makes an adjustment to the window position (for example, a frame that has
775// a toolbar that it manages itself).
bc797f4c 776void wxWindowX11::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
83df96d6
JS
777{
778 if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
779 {
780 wxPoint pt(GetParent()->GetClientAreaOrigin());
781 x += pt.x; y += pt.y;
782 }
783}
784
bc797f4c 785void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
83df96d6
JS
786{
787 m_minWidth = minW;
788 m_minHeight = minH;
789 m_maxWidth = maxW;
790 m_maxHeight = maxH;
791
b513212d
JS
792 XSizeHints sizeHints;
793 sizeHints.flags = 0;
794
795 if (minW > -1 && minH > -1)
83df96d6 796 {
b513212d
JS
797 sizeHints.flags |= PMinSize;
798 sizeHints.min_width = minW;
799 sizeHints.min_height = minH;
800 }
801 if (maxW > -1 && maxH > -1)
802 {
803 sizeHints.flags |= PMaxSize;
804 sizeHints.max_width = maxW;
805 sizeHints.max_height = maxH;
806 }
807 if (incW > -1 && incH > -1)
808 {
809 sizeHints.flags |= PResizeInc;
810 sizeHints.width_inc = incW;
811 sizeHints.height_inc = incH;
83df96d6
JS
812 }
813
178572bb 814 XSetWMNormalHints(wxGlobalDisplay(), (Window) GetMainWindow(), & sizeHints);
83df96d6
JS
815}
816
bc797f4c 817void wxWindowX11::DoMoveWindow(int x, int y, int width, int height)
83df96d6 818{
b513212d 819 DoSetSize(x, y, width, height);
83df96d6
JS
820}
821
822// ---------------------------------------------------------------------------
823// text metrics
824// ---------------------------------------------------------------------------
825
bc797f4c 826int wxWindowX11::GetCharHeight() const
83df96d6
JS
827{
828 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
829
830 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
831
832 int direction, ascent, descent;
833 XCharStruct overall;
834 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
835 &descent, &overall);
836
837 // return (overall.ascent + overall.descent);
838 return (ascent + descent);
839}
840
bc797f4c 841int wxWindowX11::GetCharWidth() const
83df96d6
JS
842{
843 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
844
845 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
846
847 int direction, ascent, descent;
848 XCharStruct overall;
849 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
850 &descent, &overall);
851
852 return overall.width;
853}
854
bc797f4c 855void wxWindowX11::GetTextExtent(const wxString& string,
83df96d6
JS
856 int *x, int *y,
857 int *descent, int *externalLeading,
858 const wxFont *theFont) const
859{
860 wxFont *fontToUse = (wxFont *)theFont;
861 if (!fontToUse)
862 fontToUse = (wxFont *) & m_font;
863
864 wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
865
866 WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
867
868 int direction, ascent, descent2;
869 XCharStruct overall;
870 int slen = string.Len();
871
872#if 0
873 if (use16)
874 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
875 &ascent, &descent2, &overall);
876#endif
877
878 XTextExtents((XFontStruct*) pFontStruct, string, slen,
879 &direction, &ascent, &descent2, &overall);
880
881 if ( x )
882 *x = (overall.width);
883 if ( y )
884 *y = (ascent + descent2);
885 if (descent)
886 *descent = descent2;
887 if (externalLeading)
888 *externalLeading = 0;
889
890}
891
892// ----------------------------------------------------------------------------
893// painting
894// ----------------------------------------------------------------------------
895
bc797f4c 896void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect)
83df96d6 897{
d02cb44e
RR
898 if (eraseBack)
899 {
900 if (rect)
901 {
902 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
903 m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
904 }
905 else
906 {
907 int height,width;
908 GetSize( &width, &height );
909
910 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
911 m_clearRegion.Clear();
912 m_clearRegion.Union( 0, 0, width, height );
913 }
914 }
83df96d6 915
83df96d6
JS
916 if (rect)
917 {
d02cb44e
RR
918 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
919 m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
83df96d6
JS
920 }
921 else
922 {
d02cb44e
RR
923 int height,width;
924 GetSize( &width, &height );
925
926 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
927 m_updateRegion.Clear();
928 m_updateRegion.Union( 0, 0, width, height );
83df96d6 929 }
d02cb44e
RR
930
931 // Actually don't schedule yet..
932 Update();
933}
83df96d6 934
d02cb44e
RR
935void wxWindowX11::Update()
936{
937 if (!m_updateRegion.IsEmpty())
83df96d6 938 {
d02cb44e 939 X11SendPaintEvents();
83df96d6 940 }
83df96d6
JS
941}
942
bc797f4c 943void wxWindowX11::Clear()
83df96d6 944{
7266b672 945 wxClientDC dc((wxWindow*) this);
83df96d6
JS
946 wxBrush brush(GetBackgroundColour(), wxSOLID);
947 dc.SetBackground(brush);
948 dc.Clear();
949}
950
1934d291 951void wxWindowX11::X11SendPaintEvents()
83df96d6 952{
1934d291
RR
953 m_clipPaintRegion = TRUE;
954
955 if (!m_clearRegion.IsEmpty())
83df96d6 956 {
1934d291
RR
957 wxWindowDC dc( (wxWindow*)this );
958 dc.SetClippingRegion( m_clearRegion );
959
960 wxEraseEvent erase_event( GetId(), &dc );
961 erase_event.SetEventObject( this );
962
963 if (!GetEventHandler()->ProcessEvent(erase_event))
964 {
965 wxRegionIterator upd( m_clearRegion );
966 while (upd)
967 {
968 // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
969 upd ++;
970 }
971 }
972 m_clearRegion.Clear();
83df96d6
JS
973 }
974
1934d291
RR
975 wxNcPaintEvent nc_paint_event( GetId() );
976 nc_paint_event.SetEventObject( this );
977 GetEventHandler()->ProcessEvent( nc_paint_event );
83df96d6 978
1934d291
RR
979 wxPaintEvent paint_event( GetId() );
980 paint_event.SetEventObject( this );
981 GetEventHandler()->ProcessEvent( paint_event );
982
983 m_clipPaintRegion = FALSE;
83df96d6
JS
984}
985
986// ----------------------------------------------------------------------------
987// event handlers
988// ----------------------------------------------------------------------------
989
990// Responds to colour changes: passes event on to children.
bc797f4c 991void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
83df96d6
JS
992{
993 wxWindowList::Node *node = GetChildren().GetFirst();
994 while ( node )
995 {
996 // Only propagate to non-top-level windows
997 wxWindow *win = node->GetData();
998 if ( win->GetParent() )
999 {
1000 wxSysColourChangedEvent event2;
1001 event.m_eventObject = win;
1002 win->GetEventHandler()->ProcessEvent(event2);
1003 }
1004
1005 node = node->GetNext();
1006 }
1007}
1008
bc797f4c 1009void wxWindowX11::OnIdle(wxIdleEvent& WXUNUSED(event))
83df96d6
JS
1010{
1011 // This calls the UI-update mechanism (querying windows for
1012 // menu/toolbar/control state information)
1013 UpdateWindowUI();
1014}
1015
83df96d6
JS
1016// ----------------------------------------------------------------------------
1017// function which maintain the global hash table mapping Widgets to wxWindows
1018// ----------------------------------------------------------------------------
1019
bc797f4c 1020bool wxAddWindowToTable(Window w, wxWindow *win)
83df96d6
JS
1021{
1022 wxWindow *oldItem = NULL;
1023 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
1024 {
1025 wxLogDebug("Widget table clash: new widget is %ld, %s",
1026 (long)w, win->GetClassInfo()->GetClassName());
1027 return FALSE;
1028 }
1029
1030 wxWidgetHashTable->Put((long) w, win);
1031
bc797f4c 1032 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
83df96d6
JS
1033 w, win, win->GetClassInfo()->GetClassName());
1034
1035 return TRUE;
1036}
1037
bc797f4c 1038wxWindow *wxGetWindowFromTable(Window w)
83df96d6
JS
1039{
1040 return (wxWindow *)wxWidgetHashTable->Get((long) w);
1041}
1042
bc797f4c 1043void wxDeleteWindowFromTable(Window w)
83df96d6
JS
1044{
1045 wxWidgetHashTable->Delete((long)w);
1046}
1047
1048// ----------------------------------------------------------------------------
1049// add/remove window from the table
1050// ----------------------------------------------------------------------------
1051
83df96d6 1052// ----------------------------------------------------------------------------
bc797f4c 1053// X11-specific accessors
83df96d6
JS
1054// ----------------------------------------------------------------------------
1055
1056// Get the underlying X window
bc797f4c 1057WXWindow wxWindowX11::GetXWindow() const
83df96d6 1058{
bc797f4c 1059 return GetMainWindow();
83df96d6
JS
1060}
1061
1062// Get the underlying X display
bc797f4c 1063WXDisplay *wxWindowX11::GetXDisplay() const
83df96d6 1064{
bc797f4c 1065 return wxGetDisplay();
83df96d6
JS
1066}
1067
bc797f4c 1068WXWindow wxWindowX11::GetMainWindow() const
83df96d6 1069{
d02cb44e 1070 return m_mainWidget;
83df96d6
JS
1071}
1072
83df96d6
JS
1073// ----------------------------------------------------------------------------
1074// TranslateXXXEvent() functions
1075// ----------------------------------------------------------------------------
1076
1b0fb34b 1077bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent)
83df96d6
JS
1078{
1079 switch (xevent->xany.type)
1080 {
1b0fb34b
JS
1081 case EnterNotify:
1082 case LeaveNotify:
83df96d6
JS
1083 case ButtonPress:
1084 case ButtonRelease:
1085 case MotionNotify:
1086 {
1087 wxEventType eventType = wxEVT_NULL;
1088
1b0fb34b 1089 if (xevent->xany.type == EnterNotify)
83df96d6 1090 {
1b0fb34b
JS
1091 //if (local_event.xcrossing.mode!=NotifyNormal)
1092 // return ; // Ignore grab events
1093 eventType = wxEVT_ENTER_WINDOW;
1094 // canvas->GetEventHandler()->OnSetFocus();
1095 }
1096 else if (xevent->xany.type == LeaveNotify)
1097 {
1098 //if (local_event.xcrossingr.mode!=NotifyNormal)
1099 // return ; // Ignore grab events
1100 eventType = wxEVT_LEAVE_WINDOW;
1101 // canvas->GetEventHandler()->OnKillFocus();
83df96d6
JS
1102 }
1103 else if (xevent->xany.type == MotionNotify)
1104 {
1105 eventType = wxEVT_MOTION;
1106 }
1107 else if (xevent->xany.type == ButtonPress)
1108 {
1109 wxevent.SetTimestamp(xevent->xbutton.time);
1110 int button = 0;
1111 if (xevent->xbutton.button == Button1)
1112 {
1113 eventType = wxEVT_LEFT_DOWN;
83df96d6
JS
1114 button = 1;
1115 }
1116 else if (xevent->xbutton.button == Button2)
1117 {
1118 eventType = wxEVT_MIDDLE_DOWN;
83df96d6
JS
1119 button = 2;
1120 }
1121 else if (xevent->xbutton.button == Button3)
1122 {
1123 eventType = wxEVT_RIGHT_DOWN;
83df96d6
JS
1124 button = 3;
1125 }
1126
1127 // check for a double click
1b0fb34b 1128 // TODO: where can we get this value from?
b513212d 1129 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
7266b672 1130 long dclickTime = 200;
83df96d6
JS
1131 long ts = wxevent.GetTimestamp();
1132
1133 int buttonLast = win->GetLastClickedButton();
1134 long lastTS = win->GetLastClickTime();
1135 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
1136 {
1137 // I have a dclick
1138 win->SetLastClick(0, ts);
1139 if ( eventType == wxEVT_LEFT_DOWN )
1140 eventType = wxEVT_LEFT_DCLICK;
1141 else if ( eventType == wxEVT_MIDDLE_DOWN )
1142 eventType = wxEVT_MIDDLE_DCLICK;
1143 else if ( eventType == wxEVT_RIGHT_DOWN )
1144 eventType = wxEVT_RIGHT_DCLICK;
1145 }
1146 else
1147 {
1148 // not fast enough or different button
1149 win->SetLastClick(button, ts);
1150 }
1151 }
1152 else if (xevent->xany.type == ButtonRelease)
1153 {
1154 if (xevent->xbutton.button == Button1)
1155 {
1156 eventType = wxEVT_LEFT_UP;
83df96d6
JS
1157 }
1158 else if (xevent->xbutton.button == Button2)
1159 {
1160 eventType = wxEVT_MIDDLE_UP;
83df96d6
JS
1161 }
1162 else if (xevent->xbutton.button == Button3)
1163 {
1164 eventType = wxEVT_RIGHT_UP;
83df96d6
JS
1165 }
1166 else return FALSE;
1167 }
1168 else
1169 {
1170 return FALSE;
1171 }
1172
1173 wxevent.SetEventType(eventType);
1174
1b0fb34b
JS
1175 wxevent.m_x = xevent->xbutton.x;
1176 wxevent.m_y = xevent->xbutton.y;
83df96d6
JS
1177
1178 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
1179 || (event_left_is_down (xevent)
1180 && (eventType != wxEVT_LEFT_UP)));
1181 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
1182 || (event_middle_is_down (xevent)
1183 && (eventType != wxEVT_MIDDLE_UP)));
1184 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
1185 || (event_right_is_down (xevent)
1186 && (eventType != wxEVT_RIGHT_UP)));
1187
1188 wxevent.m_shiftDown = xevent->xbutton.state & ShiftMask;
1189 wxevent.m_controlDown = xevent->xbutton.state & ControlMask;
1190 wxevent.m_altDown = xevent->xbutton.state & Mod3Mask;
1191 wxevent.m_metaDown = xevent->xbutton.state & Mod1Mask;
1192
1193 wxevent.SetId(win->GetId());
1194 wxevent.SetEventObject(win);
1195
1196 return TRUE;
1197 }
1198 }
1199 return FALSE;
1200}
1201
7eaac9f5 1202bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent)
83df96d6
JS
1203{
1204 switch (xevent->xany.type)
1205 {
1206 case KeyPress:
1207 case KeyRelease:
1208 {
1209 char buf[20];
1210
1211 KeySym keySym;
83df96d6
JS
1212 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
1213 int id = wxCharCodeXToWX (keySym);
1214
1215 if (xevent->xkey.state & ShiftMask)
1216 wxevent.m_shiftDown = TRUE;
1217 if (xevent->xkey.state & ControlMask)
1218 wxevent.m_controlDown = TRUE;
1219 if (xevent->xkey.state & Mod3Mask)
1220 wxevent.m_altDown = TRUE;
1221 if (xevent->xkey.state & Mod1Mask)
1222 wxevent.m_metaDown = TRUE;
1223 wxevent.SetEventObject(win);
1224 wxevent.m_keyCode = id;
1225 wxevent.SetTimestamp(xevent->xkey.time);
1226
1227 wxevent.m_x = xevent->xbutton.x;
1228 wxevent.m_y = xevent->xbutton.y;
1229
1230 if (id > -1)
1231 return TRUE;
1232 else
1233 return FALSE;
1234 break;
1235 }
1236 default:
1237 break;
1238 }
1239 return FALSE;
1240}
1241
1242// ----------------------------------------------------------------------------
1243// Colour stuff
1244// ----------------------------------------------------------------------------
1245
bc797f4c
JS
1246#if 0
1247
83df96d6
JS
1248#define YAllocColor XAllocColor
1249XColor g_itemColors[5];
1250int wxComputeColours (Display *display, wxColour * back, wxColour * fore)
1251{
1252 int result;
1253 static XmColorProc colorProc;
1254
1255 result = wxNO_COLORS;
1256
1257 if (back)
1258 {
1259 g_itemColors[0].red = (((long) back->Red ()) << 8);
1260 g_itemColors[0].green = (((long) back->Green ()) << 8);
1261 g_itemColors[0].blue = (((long) back->Blue ()) << 8);
1262 g_itemColors[0].flags = DoRed | DoGreen | DoBlue;
1263 if (colorProc == (XmColorProc) NULL)
1264 {
1265 // Get a ptr to the actual function
1266 colorProc = XmSetColorCalculation ((XmColorProc) NULL);
1267 // And set it back to motif.
1268 XmSetColorCalculation (colorProc);
1269 }
1270 (*colorProc) (&g_itemColors[wxBACK_INDEX],
1271 &g_itemColors[wxFORE_INDEX],
1272 &g_itemColors[wxSELE_INDEX],
1273 &g_itemColors[wxTOPS_INDEX],
1274 &g_itemColors[wxBOTS_INDEX]);
1275 result = wxBACK_COLORS;
1276 }
1277 if (fore)
1278 {
1279 g_itemColors[wxFORE_INDEX].red = (((long) fore->Red ()) << 8);
1280 g_itemColors[wxFORE_INDEX].green = (((long) fore->Green ()) << 8);
1281 g_itemColors[wxFORE_INDEX].blue = (((long) fore->Blue ()) << 8);
1282 g_itemColors[wxFORE_INDEX].flags = DoRed | DoGreen | DoBlue;
1283 if (result == wxNO_COLORS)
1284 result = wxFORE_COLORS;
1285 }
1286
1287 Display *dpy = display;
1288 Colormap cmap = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dpy);
1289
1290 if (back)
1291 {
1292 /* 5 Colours to allocate */
1293 for (int i = 0; i < 5; i++)
1294 if (!YAllocColor (dpy, cmap, &g_itemColors[i]))
1295 result = wxNO_COLORS;
1296 }
1297 else if (fore)
1298 {
1299 /* Only 1 colour to allocate */
1300 if (!YAllocColor (dpy, cmap, &g_itemColors[wxFORE_INDEX]))
1301 result = wxNO_COLORS;
1302 }
1303
1304 return (result);
1305
1306}
bc797f4c 1307#endif
83df96d6 1308
bc797f4c 1309bool wxWindowX11::SetBackgroundColour(const wxColour& col)
83df96d6
JS
1310{
1311 if ( !wxWindowBase::SetBackgroundColour(col) )
1312 return FALSE;
1313
b28d3abf
JS
1314 if (!GetMainWindow())
1315 return FALSE;
1316
1b0b798d 1317 wxColour colour( col );
b28d3abf 1318 XSetWindowAttributes attrib;
1b0b798d 1319 attrib.background_pixel = colour.AllocColour(wxGlobalDisplay());
b28d3abf
JS
1320
1321 XChangeWindowAttributes(wxGlobalDisplay(),
1322 (Window) GetMainWindow(),
1323 CWBackPixel,
1324 & attrib);
1325
83df96d6
JS
1326 return TRUE;
1327}
1328
bc797f4c 1329bool wxWindowX11::SetForegroundColour(const wxColour& col)
83df96d6
JS
1330{
1331 if ( !wxWindowBase::SetForegroundColour(col) )
1332 return FALSE;
1333
83df96d6
JS
1334 return TRUE;
1335}
1336
83df96d6
JS
1337// ----------------------------------------------------------------------------
1338// global functions
1339// ----------------------------------------------------------------------------
1340
1341wxWindow *wxGetActiveWindow()
1342{
1343 // TODO
1344 wxFAIL_MSG("Not implemented");
1345 return NULL;
1346}
1347
1348/* static */
1349wxWindow *wxWindowBase::GetCapture()
1350{
1351 return (wxWindow *)g_captureWindow;
1352}
1353
1354
1355// Find the wxWindow at the current mouse position, returning the mouse
1356// position.
1357wxWindow* wxFindWindowAtPointer(wxPoint& pt)
1358{
1359 return wxFindWindowAtPoint(wxGetMousePosition());
1360}
1361
1362// Get the current mouse position.
1363wxPoint wxGetMousePosition()
1364{
b513212d 1365 Display *display = wxGlobalDisplay();
83df96d6
JS
1366 Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
1367 Window rootReturn, childReturn;
1368 int rootX, rootY, winX, winY;
1369 unsigned int maskReturn;
1370
1371 XQueryPointer (display,
1372 rootWindow,
1373 &rootReturn,
1374 &childReturn,
1375 &rootX, &rootY, &winX, &winY, &maskReturn);
1376 return wxPoint(rootX, rootY);
1377}
1378
1379
1380// ----------------------------------------------------------------------------
1381// wxNoOptimize: switch off size optimization
1382// ----------------------------------------------------------------------------
1383
1384int wxNoOptimize::ms_count = 0;
1385