Some more fiddling with two-window approach and
[wxWidgets.git] / src / x11 / window.cpp
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
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/scrolbar.h"
40 #include "wx/module.h"
41 #include "wx/menuitem.h"
42 #include "wx/log.h"
43
44 #if wxUSE_DRAG_AND_DROP
45 #include "wx/dnd.h"
46 #endif
47
48 #include "wx/x11/private.h"
49 #include "X11/Xutil.h"
50
51 #if wxUSE_NANOX
52 // For wxGetLocalTime, used by XButtonEventGetTime
53 #include "wx/timer.h"
54 #endif
55
56 #include <string.h>
57
58 // ----------------------------------------------------------------------------
59 // global variables for this module
60 // ----------------------------------------------------------------------------
61
62 extern wxHashTable *wxWidgetHashTable;
63 extern wxHashTable *wxClientWidgetHashTable;
64 static wxWindow* g_captureWindow = NULL;
65
66 // ----------------------------------------------------------------------------
67 // macros
68 // ----------------------------------------------------------------------------
69
70 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
71 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
72 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
73
74 // ----------------------------------------------------------------------------
75 // event tables
76 // ----------------------------------------------------------------------------
77
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11, wxWindowBase)
79
80 BEGIN_EVENT_TABLE(wxWindowX11, wxWindowBase)
81 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged)
82 END_EVENT_TABLE()
83
84 // ============================================================================
85 // implementation
86 // ============================================================================
87
88 // ----------------------------------------------------------------------------
89 // helper functions
90 // ----------------------------------------------------------------------------
91
92 // ----------------------------------------------------------------------------
93 // constructors
94 // ----------------------------------------------------------------------------
95
96 void wxWindowX11::Init()
97 {
98 // generic initializations first
99 InitBase();
100
101 // X11-specific
102 m_mainWindow = (WXWindow) 0;
103 m_clientWindow = (WXWindow) 0;
104 m_insertIntoMain = FALSE;
105 m_updateNcArea = FALSE;
106
107 m_winCaptured = FALSE;
108 m_needsInputFocus = FALSE;
109 m_isShown = TRUE;
110 m_isBeingDeleted = FALSE;
111 m_lastTS = 0;
112 m_lastButton = 0;
113 }
114
115 // real construction (Init() must have been called before!)
116 bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
117 const wxPoint& pos,
118 const wxSize& size,
119 long style,
120 const wxString& name)
121 {
122 wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
123
124 CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
125
126 parent->AddChild(this);
127
128 int w = size.GetWidth();
129 int h = size.GetHeight();
130 int x = size.GetX();
131 int y = size.GetY();
132 if (w == -1) w = 20;
133 if (h == -1) h = 20;
134 if (x == -1) x = 0;
135 if (y == -1) y = 0;
136
137 Display *xdisplay = (Display*) wxGlobalDisplay();
138 int xscreen = DefaultScreen( xdisplay );
139 Visual *xvisual = DefaultVisual( xdisplay, xscreen );
140 Colormap cm = DefaultColormap( xdisplay, xscreen );
141
142 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
143 m_backgroundColour.CalcPixel( (WXColormap) cm );
144
145 m_foregroundColour = *wxBLACK;
146 m_foregroundColour.CalcPixel( (WXColormap) cm );
147
148 Window xparent = (Window) parent->GetClientWindow();
149
150 // Add window's own scrollbars to main window, not to client window
151 if (parent->GetInsertIntoMain())
152 {
153 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
154 xparent = (Window) parent->GetMainWindow();
155 }
156
157 wxSize size2(size);
158 if (size2.x == -1)
159 size2.x = 20;
160 if (size2.y == -1)
161 size2.y = 20;
162
163 wxPoint pos2(pos);
164 if (pos2.x == -1)
165 pos2.x = 0;
166 if (pos2.y == -1)
167 pos2.y = 0;
168
169 #if !wxUSE_NANOX
170
171 #if wxUSE_TWO_WINDOWS
172 bool need_two_windows =
173 ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
174 #else
175 bool need_two_windows = FALSE;
176 #endif
177
178 XSetWindowAttributes xattributes;
179 long xattributes_mask = 0;
180
181 xattributes_mask |= CWBackPixel;
182 xattributes.background_pixel = m_backgroundColour.GetPixel();
183
184 xattributes_mask |= CWBorderPixel;
185 xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
186
187 xattributes_mask |= CWEventMask;
188
189 if (need_two_windows)
190 {
191 xattributes.event_mask =
192 ExposureMask | StructureNotifyMask | ColormapChangeMask;
193
194 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
195 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
196
197 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
198
199 m_mainWindow = (WXWindow) xwindow;
200 wxAddWindowToTable( xwindow, (wxWindow*) this );
201
202 XMapWindow( xdisplay, xwindow );
203
204 xattributes.event_mask =
205 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
206 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
207 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
208 PropertyChangeMask | VisibilityChangeMask ;
209
210 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
211 {
212 xattributes_mask |= CWBitGravity;
213 xattributes.bit_gravity = StaticGravity;
214 }
215
216 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
217 {
218 pos2.x = 2;
219 pos2.y = 2;
220 size2.x -= 4;
221 size2.y -= 4;
222 } else
223 if (HasFlag( wxSIMPLE_BORDER ))
224 {
225 pos2.x = 1;
226 pos2.y = 1;
227 size2.x -= 2;
228 size2.y -= 2;
229 } else
230 {
231 pos2.x = 0;
232 pos2.y = 0;
233 }
234
235 xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y,
236 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
237
238 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
239
240 m_clientWindow = (WXWindow) xwindow;
241 wxAddClientWindowToTable( xwindow, (wxWindow*) this );
242
243 XMapWindow( xdisplay, xwindow );
244 }
245 else
246 {
247 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
248
249 xattributes.event_mask =
250 ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
251 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
252 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
253 PropertyChangeMask | VisibilityChangeMask ;
254
255 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
256 {
257 xattributes_mask |= CWBitGravity;
258 xattributes.bit_gravity = NorthWestGravity;
259 }
260
261 Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
262 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
263
264 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
265
266 m_mainWindow = (WXWindow) xwindow;
267 m_clientWindow = m_mainWindow;
268 wxAddWindowToTable( xwindow, (wxWindow*) this );
269
270 XMapWindow( xdisplay, xwindow );
271 }
272 #else
273
274 int extraFlags = GR_EVENT_MASK_CLOSE_REQ;
275
276 long backColor, foreColor;
277 backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
278 foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
279
280 Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y,
281 0, 0, InputOutput, xvisual, backColor, foreColor);
282 XSelectInput( xdisplay, xwindow,
283 extraFlags | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
284 ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
285 KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
286 PropertyChangeMask );
287
288 XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
289
290 m_mainWindow = (WXWindow) xwindow;
291 wxAddWindowToTable( xwindow, (wxWindow*) this );
292
293 XMapWindow( xdisplay, xwindow );
294 #endif
295
296 // Is a subwindow, so map immediately
297 m_isShown = TRUE;
298
299 // Without this, the cursor may not be restored properly (e.g. in splitter
300 // sample).
301 SetCursor(*wxSTANDARD_CURSOR);
302 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
303
304 // Don't call this, it can have nasty repercussions for composite controls,
305 // for example
306 // SetSize(pos.x, pos.y, size.x, size.y);
307
308 return TRUE;
309 }
310
311 // Destructor
312 wxWindowX11::~wxWindowX11()
313 {
314 if (g_captureWindow == this)
315 g_captureWindow = NULL;
316
317 m_isBeingDeleted = TRUE;
318
319 if (m_parent)
320 m_parent->RemoveChild( this );
321
322 DestroyChildren();
323
324 if (m_clientWindow != m_mainWindow)
325 {
326 // Destroy the cleint window
327 Window xwindow = (Window) m_clientWindow;
328 wxDeleteClientWindowFromTable( xwindow );
329 XDestroyWindow( wxGlobalDisplay(), xwindow );
330 m_clientWindow = NULL;
331 }
332
333 // Destroy the window
334 Window xwindow = (Window) m_mainWindow;
335 wxDeleteWindowFromTable( xwindow );
336 XDestroyWindow( wxGlobalDisplay(), xwindow );
337 m_mainWindow = NULL;
338 }
339
340 // ---------------------------------------------------------------------------
341 // basic operations
342 // ---------------------------------------------------------------------------
343
344 void wxWindowX11::SetFocus()
345 {
346 Window xwindow = (Window) m_clientWindow;
347
348 wxCHECK_RET( xwindow, wxT("invalid window") );
349
350 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
351
352 #if 0
353 if (GetName() == "scrollBar")
354 {
355 char *crash = NULL;
356 *crash = 0;
357 }
358 #endif
359
360 if (wxWindowIsVisible(xwindow))
361 {
362 XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
363 m_needsInputFocus = FALSE;
364 }
365 else
366 {
367 m_needsInputFocus = TRUE;
368 }
369 }
370
371 // Get the window with the focus
372 wxWindow *wxWindowBase::FindFocus()
373 {
374 Window xfocus = (Window) 0;
375 int revert = 0;
376
377 XGetInputFocus( wxGlobalDisplay(), &xfocus, &revert);
378 if (xfocus)
379 {
380 wxWindow *win = wxGetWindowFromTable( xfocus );
381
382 return win;
383 }
384
385 return NULL;
386 }
387
388 // Enabling/disabling handled by event loop, and not sending events
389 // if disabled.
390 bool wxWindowX11::Enable(bool enable)
391 {
392 if ( !wxWindowBase::Enable(enable) )
393 return FALSE;
394
395 return TRUE;
396 }
397
398 bool wxWindowX11::Show(bool show)
399 {
400 wxWindowBase::Show(show);
401
402 Window xwindow = (Window) m_mainWindow;
403 Display *xdisp = wxGlobalDisplay();
404 if (show)
405 {
406 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
407 XMapWindow(xdisp, xwindow);
408 }
409 else
410 {
411 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
412 XUnmapWindow(xdisp, xwindow);
413 }
414
415 return TRUE;
416 }
417
418 // Raise the window to the top of the Z order
419 void wxWindowX11::Raise()
420 {
421 if (m_mainWindow)
422 XRaiseWindow( wxGlobalDisplay(), (Window) m_mainWindow );
423 }
424
425 // Lower the window to the bottom of the Z order
426 void wxWindowX11::Lower()
427 {
428 if (m_mainWindow)
429 XLowerWindow( wxGlobalDisplay(), (Window) m_mainWindow );
430 }
431
432 void wxWindowX11::DoCaptureMouse()
433 {
434 if ((g_captureWindow != NULL) && (g_captureWindow != this))
435 {
436 wxASSERT_MSG(FALSE, "Trying to capture before mouse released.");
437
438 // Core dump now
439 int *tmp = NULL;
440 (*tmp) = 1;
441 return;
442 }
443
444 if (m_winCaptured)
445 return;
446
447 Window xwindow = (Window) m_clientWindow;
448
449 wxCHECK_RET( xwindow, wxT("invalid window") );
450
451 g_captureWindow = (wxWindow*) this;
452
453 if (xwindow)
454 {
455 int res = XGrabPointer(wxGlobalDisplay(), xwindow,
456 FALSE,
457 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
458 GrabModeAsync,
459 GrabModeAsync,
460 None,
461 None, /* cursor */ // TODO: This may need to be set to the cursor of this window
462 CurrentTime );
463
464 if (res != GrabSuccess)
465 {
466 wxString msg;
467 msg.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
468 wxLogDebug(msg);
469 if (res == GrabNotViewable)
470 {
471 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
472 }
473 g_captureWindow = NULL;
474 return;
475 }
476
477 m_winCaptured = TRUE;
478 }
479 }
480
481 void wxWindowX11::DoReleaseMouse()
482 {
483 g_captureWindow = NULL;
484
485 if ( !m_winCaptured )
486 return;
487
488 Window xwindow = (Window) m_clientWindow;
489
490 if (xwindow)
491 {
492 XUngrabPointer( wxGlobalDisplay(), CurrentTime );
493 }
494
495 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
496
497 m_winCaptured = FALSE;
498 }
499
500 bool wxWindowX11::SetFont(const wxFont& font)
501 {
502 if ( !wxWindowBase::SetFont(font) )
503 {
504 // nothing to do
505 return FALSE;
506 }
507
508 return TRUE;
509 }
510
511 bool wxWindowX11::SetCursor(const wxCursor& cursor)
512 {
513 if ( !wxWindowBase::SetCursor(cursor) )
514 {
515 // no change
516 return FALSE;
517 }
518
519 Window xwindow = (Window) m_clientWindow;
520
521 wxCHECK_MSG( xwindow, FALSE, wxT("invalid window") );
522
523 wxCursor cursorToUse;
524 if (m_cursor.Ok())
525 cursorToUse = m_cursor;
526 else
527 cursorToUse = *wxSTANDARD_CURSOR;
528
529 Cursor xcursor = (Cursor) cursorToUse.GetCursor();
530
531 XDefineCursor( wxGlobalDisplay(), xwindow, xcursor );
532
533 return TRUE;
534 }
535
536 // Coordinates relative to the window
537 void wxWindowX11::WarpPointer (int x, int y)
538 {
539 Window xwindow = (Window) m_clientWindow;
540
541 wxCHECK_RET( xwindow, wxT("invalid window") );
542
543 XWarpPointer( wxGlobalDisplay(), None, xwindow, 0, 0, 0, 0, x, y);
544 }
545
546 // Does a physical scroll
547 void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
548 {
549 // No scrolling requested.
550 if ((dx == 0) && (dy == 0)) return;
551
552 if (!m_updateRegion.IsEmpty())
553 {
554 m_updateRegion.Offset( dx, dy );
555
556 int cw = 0;
557 int ch = 0;
558 GetSize( &cw, &ch ); // GetClientSize() ??
559 m_updateRegion.Intersect( 0, 0, cw, ch );
560 }
561
562 if (!m_clearRegion.IsEmpty())
563 {
564 m_clearRegion.Offset( dx, dy );
565
566 int cw = 0;
567 int ch = 0;
568 GetSize( &cw, &ch ); // GetClientSize() ??
569 m_clearRegion.Intersect( 0, 0, cw, ch );
570 }
571
572 Window xwindow = (Window) GetClientWindow();
573
574 wxCHECK_RET( xwindow, wxT("invalid window") );
575
576 Display *xdisplay = wxGlobalDisplay();
577
578 GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL );
579 XSetGraphicsExposures( xdisplay, xgc, True );
580
581 int s_x = 0;
582 int s_y = 0;
583 int cw;
584 int ch;
585 if (rect)
586 {
587 s_x = rect->x;
588 s_y = rect->y;
589
590 cw = rect->width;
591 ch = rect->height;
592 }
593 else
594 {
595 s_x = 0;
596 s_y = 0;
597 GetClientSize( &cw, &ch );
598 }
599
600 #if wxUSE_TWO_WINDOWS
601 wxPoint offset( 0,0 );
602 #else
603 wxPoint offset = GetClientAreaOrigin();
604 s_x += offset.x;
605 s_y += offset.y;
606 #endif
607
608 int w = cw - abs(dx);
609 int h = ch - abs(dy);
610
611 if ((h < 0) || (w < 0))
612 {
613 Refresh();
614 }
615 else
616 {
617 wxRect rect;
618 if (dx < 0) rect.x = cw+dx + offset.x; else rect.x = s_x;
619 if (dy < 0) rect.y = ch+dy + offset.y; else rect.y = s_y;
620 if (dy != 0) rect.width = cw; else rect.width = abs(dx);
621 if (dx != 0) rect.height = ch; else rect.height = abs(dy);
622
623 int d_x = s_x;
624 int d_y = s_y;
625
626 if (dx < 0) s_x += -dx;
627 if (dy < 0) s_y += -dy;
628 if (dx > 0) d_x = dx + offset.x;
629 if (dy > 0) d_y = dy + offset.y;
630
631 XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y );
632
633 // 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 );
634
635 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
636
637 m_updateRegion.Union( rect );
638 m_clearRegion.Union( rect );
639 }
640
641 XFreeGC( xdisplay, xgc );
642 }
643
644 // ---------------------------------------------------------------------------
645 // drag and drop
646 // ---------------------------------------------------------------------------
647
648 #if wxUSE_DRAG_AND_DROP
649
650 void wxWindowX11::SetDropTarget(wxDropTarget * WXUNUSED(pDropTarget))
651 {
652 // TODO
653 }
654
655 #endif
656
657 // Old style file-manager drag&drop
658 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept))
659 {
660 // TODO
661 }
662
663 // ----------------------------------------------------------------------------
664 // tooltips
665 // ----------------------------------------------------------------------------
666
667 #if wxUSE_TOOLTIPS
668
669 void wxWindowX11::DoSetToolTip(wxToolTip * WXUNUSED(tooltip))
670 {
671 // TODO
672 }
673
674 #endif // wxUSE_TOOLTIPS
675
676 // ---------------------------------------------------------------------------
677 // moving and resizing
678 // ---------------------------------------------------------------------------
679
680 bool wxWindowX11::PreResize()
681 {
682 return TRUE;
683 }
684
685 // Get total size
686 void wxWindowX11::DoGetSize(int *x, int *y) const
687 {
688 Window xwindow = (Window) m_mainWindow;
689
690 wxCHECK_RET( xwindow, wxT("invalid window") );
691
692 //XSync(wxGlobalDisplay(), False);
693
694 XWindowAttributes attr;
695 Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr );
696 wxASSERT(status);
697
698 if (status)
699 {
700 *x = attr.width /* + 2*m_borderSize */ ;
701 *y = attr.height /* + 2*m_borderSize */ ;
702 }
703 }
704
705 void wxWindowX11::DoGetPosition(int *x, int *y) const
706 {
707 Window window = (Window) m_mainWindow;
708 if (window)
709 {
710 //XSync(wxGlobalDisplay(), False);
711 XWindowAttributes attr;
712 Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr);
713 wxASSERT(status);
714
715 if (status)
716 {
717 *x = attr.x;
718 *y = attr.y;
719
720 // We may be faking the client origin. So a window that's really at (0, 30)
721 // may appear (to wxWin apps) to be at (0, 0).
722 if (GetParent())
723 {
724 wxPoint pt(GetParent()->GetClientAreaOrigin());
725 *x -= pt.x;
726 *y -= pt.y;
727 }
728 }
729 }
730 }
731
732 void wxWindowX11::DoScreenToClient(int *x, int *y) const
733 {
734 Display *display = wxGlobalDisplay();
735 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
736 Window thisWindow = (Window) m_clientWindow;
737
738 Window childWindow;
739 int xx = *x;
740 int yy = *y;
741 XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
742 }
743
744 void wxWindowX11::DoClientToScreen(int *x, int *y) const
745 {
746 Display *display = wxGlobalDisplay();
747 Window rootWindow = RootWindowOfScreen(DefaultScreenOfDisplay(display));
748 Window thisWindow = (Window) m_clientWindow;
749
750 Window childWindow;
751 int xx = *x;
752 int yy = *y;
753 XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
754 }
755
756
757 // Get size *available for subwindows* i.e. excluding menu bar etc.
758 void wxWindowX11::DoGetClientSize(int *x, int *y) const
759 {
760 Window window = (Window) m_mainWindow;
761
762 if (window)
763 {
764 XWindowAttributes attr;
765 Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr );
766 wxASSERT(status);
767
768 if (status)
769 {
770 *x = attr.width ;
771 *y = attr.height ;
772 }
773 }
774 }
775
776 void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
777 {
778 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
779
780 Window xwindow = (Window) m_mainWindow;
781
782 wxCHECK_RET( xwindow, wxT("invalid window") );
783
784 XWindowAttributes attr;
785 Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr );
786 wxCHECK_RET( status, wxT("invalid window attributes") );
787
788 int new_x = attr.x;
789 int new_y = attr.y;
790 int new_w = attr.width;
791 int new_h = attr.height;
792
793 if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
794 {
795 int yy = 0;
796 AdjustForParentClientOrigin( x, yy, sizeFlags);
797 new_x = x;
798 }
799 if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
800 {
801 int xx = 0;
802 AdjustForParentClientOrigin( xx, y, sizeFlags);
803 new_y = y;
804 }
805 if (width != -1)
806 {
807 new_w = width;
808 if (new_w <= 0)
809 new_w = 20;
810 }
811 if (height != -1)
812 {
813 new_h = height;
814 if (new_h <= 0)
815 new_h = 20;
816 }
817
818 DoMoveWindow( new_x, new_y, new_w, new_h );
819
820 #if 0
821 wxSizeEvent event(wxSize(new_w, new_h), GetId());
822 event.SetEventObject(this);
823 GetEventHandler()->ProcessEvent(event);
824 #endif
825 }
826
827 void wxWindowX11::DoSetClientSize(int width, int height)
828 {
829 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
830
831 Window xwindow = (Window) m_mainWindow;
832
833 wxCHECK_RET( xwindow, wxT("invalid window") );
834
835 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
836
837 if (m_mainWindow != m_clientWindow)
838 {
839 xwindow = (Window) m_clientWindow;
840
841 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
842 {
843 width -= 4;
844 height -= 4;
845 } else
846 if (HasFlag( wxSIMPLE_BORDER ))
847 {
848 width -= 2;
849 height -= 2;
850 }
851
852 XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
853 }
854 }
855
856 // For implementation purposes - sometimes decorations make the client area
857 // smaller
858 wxPoint wxWindowX11::GetClientAreaOrigin() const
859 {
860 return wxPoint(0, 0);
861 }
862
863 void wxWindowX11::DoMoveWindow(int x, int y, int width, int height)
864 {
865 Window xwindow = (Window) m_mainWindow;
866
867 wxCHECK_RET( xwindow, wxT("invalid window") );
868
869 #if !wxUSE_NANOX
870
871 XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height );
872 if (m_mainWindow != m_clientWindow)
873 {
874 xwindow = (Window) m_clientWindow;
875
876 if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
877 {
878 x = 2;
879 y = 2;
880 width -= 4;
881 height -= 4;
882 } else
883 if (HasFlag( wxSIMPLE_BORDER ))
884 {
885 x = 1;
886 y = 1;
887 width -= 2;
888 height -= 2;
889 } else
890 {
891 x = 0;
892 y = 0;
893 }
894
895 wxWindow *window = (wxWindow*) this;
896 wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL );
897 if (sb && sb->IsShown())
898 {
899 wxSize size = sb->GetSize();
900 height -= size.y;
901 }
902 sb = window->GetScrollbar( wxVERTICAL );
903 if (sb && sb->IsShown())
904 {
905 wxSize size = sb->GetSize();
906 width -= size.x;
907 }
908
909 XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height );
910 }
911
912 #else
913
914 XWindowChanges windowChanges;
915 windowChanges.x = x;
916 windowChanges.y = y;
917 windowChanges.width = width;
918 windowChanges.height = height;
919 windowChanges.stack_mode = 0;
920 int valueMask = CWX | CWY | CWWidth | CWHeight;
921
922 XConfigureWindow( wxGlobalDisplay(), xwindow, valueMask, &windowChanges );
923
924 #endif
925 }
926
927 void wxWindowX11::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
928 {
929 m_minWidth = minW;
930 m_minHeight = minH;
931 m_maxWidth = maxW;
932 m_maxHeight = maxH;
933
934 #if !wxUSE_NANOX
935 XSizeHints sizeHints;
936 sizeHints.flags = 0;
937
938 if (minW > -1 && minH > -1)
939 {
940 sizeHints.flags |= PMinSize;
941 sizeHints.min_width = minW;
942 sizeHints.min_height = minH;
943 }
944 if (maxW > -1 && maxH > -1)
945 {
946 sizeHints.flags |= PMaxSize;
947 sizeHints.max_width = maxW;
948 sizeHints.max_height = maxH;
949 }
950 if (incW > -1 && incH > -1)
951 {
952 sizeHints.flags |= PResizeInc;
953 sizeHints.width_inc = incW;
954 sizeHints.height_inc = incH;
955 }
956
957 XSetWMNormalHints(wxGlobalDisplay(), (Window) m_mainWindow, &sizeHints );
958 #endif
959 }
960
961 // ---------------------------------------------------------------------------
962 // text metrics
963 // ---------------------------------------------------------------------------
964
965 int wxWindowX11::GetCharHeight() const
966 {
967 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
968
969 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay());
970
971 int direction, ascent, descent;
972 XCharStruct overall;
973 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
974 &descent, &overall);
975
976 // return (overall.ascent + overall.descent);
977 return (ascent + descent);
978 }
979
980 int wxWindowX11::GetCharWidth() const
981 {
982 wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
983
984 WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, wxGlobalDisplay());
985
986 int direction, ascent, descent;
987 XCharStruct overall;
988 XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
989 &descent, &overall);
990
991 return overall.width;
992 }
993
994 void wxWindowX11::GetTextExtent(const wxString& string,
995 int *x, int *y,
996 int *descent, int *externalLeading,
997 const wxFont *theFont) const
998 {
999 wxFont fontToUse = m_font;
1000 if (theFont) fontToUse = *theFont;
1001
1002 wxCHECK_RET( fontToUse.Ok(), wxT("invalid font") );
1003
1004 WXFontStructPtr pFontStruct = fontToUse.GetFontStruct(1.0, wxGlobalDisplay());
1005
1006 int direction, ascent, descent2;
1007 XCharStruct overall;
1008 int slen = string.Len();
1009
1010 #if 0
1011 if (use16)
1012 XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
1013 &ascent, &descent2, &overall);
1014 #endif
1015
1016 XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen,
1017 &direction, &ascent, &descent2, &overall);
1018
1019 if ( x )
1020 *x = (overall.width);
1021 if ( y )
1022 *y = (ascent + descent2);
1023 if (descent)
1024 *descent = descent2;
1025 if (externalLeading)
1026 *externalLeading = 0;
1027
1028 }
1029
1030 // ----------------------------------------------------------------------------
1031 // painting
1032 // ----------------------------------------------------------------------------
1033
1034 void wxWindowX11::Refresh(bool eraseBack, const wxRect *rect)
1035 {
1036 if (eraseBack)
1037 {
1038 if (rect)
1039 {
1040 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1041 m_clearRegion.Union( rect->x, rect->y, rect->width, rect->height );
1042 }
1043 else
1044 {
1045 int height,width;
1046 GetSize( &width, &height );
1047
1048 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1049 m_clearRegion.Clear();
1050 m_clearRegion.Union( 0, 0, width, height );
1051 }
1052 }
1053
1054 if (rect)
1055 {
1056 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1057 m_updateRegion.Union( rect->x, rect->y, rect->width, rect->height );
1058 }
1059 else
1060 {
1061 int height,width;
1062 GetSize( &width, &height );
1063
1064 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1065 m_updateRegion.Clear();
1066 m_updateRegion.Union( 0, 0, width, height );
1067 }
1068 }
1069
1070 void wxWindowX11::Update()
1071 {
1072 if (m_updateNcArea)
1073 {
1074 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1075 // Send nc paint events.
1076 SendNcPaintEvents();
1077 }
1078
1079 if (!m_updateRegion.IsEmpty())
1080 {
1081 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1082 // Actually send erase events.
1083 SendEraseEvents();
1084
1085 // Actually send paint events.
1086 SendPaintEvents();
1087 }
1088 }
1089
1090 void wxWindowX11::Clear()
1091 {
1092 // wxClientDC dc((wxWindow*) this);
1093 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1094 // dc.SetBackground(brush);
1095 // dc.Clear();
1096 }
1097
1098 void wxWindowX11::SendEraseEvents()
1099 {
1100 if (m_clearRegion.IsEmpty()) return;
1101
1102 wxClientDC dc( (wxWindow*)this );
1103 dc.SetClippingRegion( m_clearRegion );
1104
1105 wxEraseEvent erase_event( GetId(), &dc );
1106 erase_event.SetEventObject( this );
1107
1108 if (!GetEventHandler()->ProcessEvent(erase_event))
1109 {
1110 Window xwindow = (Window) m_clientWindow;
1111 Display *xdisplay = wxGlobalDisplay();
1112 GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL );
1113 XSetFillStyle( xdisplay, xgc, FillSolid );
1114 XSetForeground( xdisplay, xgc, m_backgroundColour.GetPixel() );
1115 wxRegionIterator upd( m_clearRegion );
1116 while (upd)
1117 {
1118 XFillRectangle( xdisplay, xwindow, xgc,
1119 upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
1120 upd ++;
1121 }
1122 XFreeGC( xdisplay, xgc );
1123 }
1124
1125 m_clearRegion.Clear();
1126 }
1127
1128 void wxWindowX11::SendPaintEvents()
1129 {
1130 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1131
1132 m_clipPaintRegion = TRUE;
1133
1134 wxPaintEvent paint_event( GetId() );
1135 paint_event.SetEventObject( this );
1136 GetEventHandler()->ProcessEvent( paint_event );
1137
1138 m_updateRegion.Clear();
1139
1140 m_clipPaintRegion = FALSE;
1141 }
1142
1143 void wxWindowX11::SendNcPaintEvents()
1144 {
1145 wxNcPaintEvent nc_paint_event( GetId() );
1146 nc_paint_event.SetEventObject( this );
1147 GetEventHandler()->ProcessEvent( nc_paint_event );
1148
1149 m_updateNcArea = FALSE;
1150 }
1151
1152 // ----------------------------------------------------------------------------
1153 // event handlers
1154 // ----------------------------------------------------------------------------
1155
1156 // Responds to colour changes: passes event on to children.
1157 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
1158 {
1159 wxWindowList::Node *node = GetChildren().GetFirst();
1160 while ( node )
1161 {
1162 // Only propagate to non-top-level windows
1163 wxWindow *win = node->GetData();
1164 if ( win->GetParent() )
1165 {
1166 wxSysColourChangedEvent event2;
1167 event.m_eventObject = win;
1168 win->GetEventHandler()->ProcessEvent(event2);
1169 }
1170
1171 node = node->GetNext();
1172 }
1173 }
1174
1175 void wxWindowX11::OnInternalIdle()
1176 {
1177 // Update invalidated regions.
1178 Update();
1179
1180 // This calls the UI-update mechanism (querying windows for
1181 // menu/toolbar/control state information)
1182 UpdateWindowUI();
1183
1184 // Set the input focus if couldn't do it before
1185 if (m_needsInputFocus)
1186 {
1187 SetFocus();
1188 }
1189 }
1190
1191 // ----------------------------------------------------------------------------
1192 // function which maintain the global hash table mapping Widgets to wxWindows
1193 // ----------------------------------------------------------------------------
1194
1195 bool wxAddWindowToTable(Window w, wxWindow *win)
1196 {
1197 wxWindow *oldItem = NULL;
1198 if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
1199 {
1200 wxLogDebug("Widget table clash: new widget is %ld, %s",
1201 (long)w, win->GetClassInfo()->GetClassName());
1202 return FALSE;
1203 }
1204
1205 wxWidgetHashTable->Put((long) w, win);
1206
1207 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1208 w, win, win->GetClassInfo()->GetClassName());
1209
1210 return TRUE;
1211 }
1212
1213 wxWindow *wxGetWindowFromTable(Window w)
1214 {
1215 return (wxWindow *)wxWidgetHashTable->Get((long) w);
1216 }
1217
1218 void wxDeleteWindowFromTable(Window w)
1219 {
1220 wxWidgetHashTable->Delete((long)w);
1221 }
1222
1223 // ----------------------------------------------------------------------------
1224 // function which maintain the global hash table mapping client widgets
1225 // ----------------------------------------------------------------------------
1226
1227 bool wxAddClientWindowToTable(Window w, wxWindow *win)
1228 {
1229 wxWindow *oldItem = NULL;
1230 if ((oldItem = (wxWindow *)wxClientWidgetHashTable->Get ((long) w)))
1231 {
1232 wxLogDebug("Client window table clash: new window is %ld, %s",
1233 (long)w, win->GetClassInfo()->GetClassName());
1234 return FALSE;
1235 }
1236
1237 wxClientWidgetHashTable->Put((long) w, win);
1238
1239 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1240 w, win, win->GetClassInfo()->GetClassName());
1241
1242 return TRUE;
1243 }
1244
1245 wxWindow *wxGetClientWindowFromTable(Window w)
1246 {
1247 return (wxWindow *)wxClientWidgetHashTable->Get((long) w);
1248 }
1249
1250 void wxDeleteClientWindowFromTable(Window w)
1251 {
1252 wxClientWidgetHashTable->Delete((long)w);
1253 }
1254
1255 // ----------------------------------------------------------------------------
1256 // add/remove window from the table
1257 // ----------------------------------------------------------------------------
1258
1259 // ----------------------------------------------------------------------------
1260 // X11-specific accessors
1261 // ----------------------------------------------------------------------------
1262
1263 WXWindow wxWindowX11::GetMainWindow() const
1264 {
1265 return m_mainWindow;
1266 }
1267
1268 WXWindow wxWindowX11::GetClientWindow() const
1269 {
1270 return m_clientWindow;
1271 }
1272
1273 // ----------------------------------------------------------------------------
1274 // TranslateXXXEvent() functions
1275 // ----------------------------------------------------------------------------
1276
1277 bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent)
1278 {
1279 switch (XEventGetType(xevent))
1280 {
1281 case EnterNotify:
1282 case LeaveNotify:
1283 case ButtonPress:
1284 case ButtonRelease:
1285 case MotionNotify:
1286 {
1287 wxEventType eventType = wxEVT_NULL;
1288
1289 if (XEventGetType(xevent) == EnterNotify)
1290 {
1291 //if (local_event.xcrossing.mode!=NotifyNormal)
1292 // return ; // Ignore grab events
1293 eventType = wxEVT_ENTER_WINDOW;
1294 // canvas->GetEventHandler()->OnSetFocus();
1295 }
1296 else if (XEventGetType(xevent) == LeaveNotify)
1297 {
1298 //if (local_event.xcrossingr.mode!=NotifyNormal)
1299 // return ; // Ignore grab events
1300 eventType = wxEVT_LEAVE_WINDOW;
1301 // canvas->GetEventHandler()->OnKillFocus();
1302 }
1303 else if (XEventGetType(xevent) == MotionNotify)
1304 {
1305 eventType = wxEVT_MOTION;
1306 }
1307 else if (XEventGetType(xevent) == ButtonPress)
1308 {
1309 wxevent.SetTimestamp(XButtonEventGetTime(xevent));
1310 int button = 0;
1311 if (XButtonEventLChanged(xevent))
1312 {
1313 eventType = wxEVT_LEFT_DOWN;
1314 button = 1;
1315 }
1316 else if (XButtonEventMChanged(xevent))
1317 {
1318 eventType = wxEVT_MIDDLE_DOWN;
1319 button = 2;
1320 }
1321 else if (XButtonEventRChanged(xevent))
1322 {
1323 eventType = wxEVT_RIGHT_DOWN;
1324 button = 3;
1325 }
1326
1327 // check for a double click
1328 // TODO: where can we get this value from?
1329 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1330 long dclickTime = 200;
1331 long ts = wxevent.GetTimestamp();
1332
1333 int buttonLast = win->GetLastClickedButton();
1334 long lastTS = win->GetLastClickTime();
1335 if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
1336 {
1337 // I have a dclick
1338 win->SetLastClick(0, ts);
1339 if ( eventType == wxEVT_LEFT_DOWN )
1340 eventType = wxEVT_LEFT_DCLICK;
1341 else if ( eventType == wxEVT_MIDDLE_DOWN )
1342 eventType = wxEVT_MIDDLE_DCLICK;
1343 else if ( eventType == wxEVT_RIGHT_DOWN )
1344 eventType = wxEVT_RIGHT_DCLICK;
1345 }
1346 else
1347 {
1348 // not fast enough or different button
1349 win->SetLastClick(button, ts);
1350 }
1351 }
1352 else if (XEventGetType(xevent) == ButtonRelease)
1353 {
1354 if (XButtonEventLChanged(xevent))
1355 {
1356 eventType = wxEVT_LEFT_UP;
1357 }
1358 else if (XButtonEventMChanged(xevent))
1359 {
1360 eventType = wxEVT_MIDDLE_UP;
1361 }
1362 else if (XButtonEventRChanged(xevent))
1363 {
1364 eventType = wxEVT_RIGHT_UP;
1365 }
1366 else return FALSE;
1367 }
1368 else
1369 {
1370 return FALSE;
1371 }
1372
1373 wxevent.SetEventType(eventType);
1374
1375 wxevent.m_x = XButtonEventGetX(xevent);
1376 wxevent.m_y = XButtonEventGetY(xevent);
1377
1378 wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
1379 || (XButtonEventLIsDown(xevent)
1380 && (eventType != wxEVT_LEFT_UP)));
1381 wxevent.m_middleDown = ((eventType == wxEVT_MIDDLE_DOWN)
1382 || (XButtonEventMIsDown(xevent)
1383 && (eventType != wxEVT_MIDDLE_UP)));
1384 wxevent.m_rightDown = ((eventType == wxEVT_RIGHT_DOWN)
1385 || (XButtonEventRIsDown (xevent)
1386 && (eventType != wxEVT_RIGHT_UP)));
1387
1388 wxevent.m_shiftDown = XButtonEventShiftIsDown(xevent);
1389 wxevent.m_controlDown = XButtonEventCtrlIsDown(xevent);
1390 wxevent.m_altDown = XButtonEventAltIsDown(xevent);
1391 wxevent.m_metaDown = XButtonEventMetaIsDown(xevent);
1392
1393 wxevent.SetId(win->GetId());
1394 wxevent.SetEventObject(win);
1395
1396 return TRUE;
1397 }
1398 }
1399 return FALSE;
1400 }
1401
1402 bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Window WXUNUSED(win), XEvent *xevent)
1403 {
1404 switch (XEventGetType(xevent))
1405 {
1406 case KeyPress:
1407 case KeyRelease:
1408 {
1409 char buf[20];
1410
1411 KeySym keySym;
1412 (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, NULL);
1413 int id = wxCharCodeXToWX (keySym);
1414
1415 wxevent.m_shiftDown = XKeyEventShiftIsDown(xevent);
1416 wxevent.m_controlDown = XKeyEventCtrlIsDown(xevent);
1417 wxevent.m_altDown = XKeyEventAltIsDown(xevent);
1418 wxevent.m_metaDown = XKeyEventMetaIsDown(xevent);
1419 wxevent.SetEventObject(win);
1420 wxevent.m_keyCode = id;
1421 wxevent.SetTimestamp(XKeyEventGetTime(xevent));
1422
1423 wxevent.m_x = XKeyEventGetX(xevent);
1424 wxevent.m_y = XKeyEventGetY(xevent);
1425
1426 if (id > -1)
1427 return TRUE;
1428 else
1429 return FALSE;
1430 break;
1431 }
1432 default:
1433 break;
1434 }
1435 return FALSE;
1436 }
1437
1438 // ----------------------------------------------------------------------------
1439 // Colour stuff
1440 // ----------------------------------------------------------------------------
1441
1442 bool wxWindowX11::SetBackgroundColour(const wxColour& col)
1443 {
1444 wxWindowBase::SetBackgroundColour(col);
1445
1446 Display *xdisplay = (Display*) wxGlobalDisplay();
1447 int xscreen = DefaultScreen( xdisplay );
1448 Colormap cm = DefaultColormap( xdisplay, xscreen );
1449
1450 m_backgroundColour.CalcPixel( (WXColormap) cm );
1451
1452 if (!GetMainWindow())
1453 return FALSE;
1454
1455 /*
1456 XSetWindowAttributes attrib;
1457 attrib.background_pixel = colour.GetPixel();
1458
1459 XChangeWindowAttributes(wxGlobalDisplay(),
1460 (Window) GetMainWindow(),
1461 CWBackPixel,
1462 & attrib);
1463 */
1464
1465 return TRUE;
1466 }
1467
1468 bool wxWindowX11::SetForegroundColour(const wxColour& col)
1469 {
1470 if ( !wxWindowBase::SetForegroundColour(col) )
1471 return FALSE;
1472
1473 return TRUE;
1474 }
1475
1476 // ----------------------------------------------------------------------------
1477 // global functions
1478 // ----------------------------------------------------------------------------
1479
1480 wxWindow *wxGetActiveWindow()
1481 {
1482 // TODO
1483 wxFAIL_MSG("Not implemented");
1484 return NULL;
1485 }
1486
1487 /* static */
1488 wxWindow *wxWindowBase::GetCapture()
1489 {
1490 return (wxWindow *)g_captureWindow;
1491 }
1492
1493
1494 // Find the wxWindow at the current mouse position, returning the mouse
1495 // position.
1496 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
1497 {
1498 return wxFindWindowAtPoint(wxGetMousePosition());
1499 }
1500
1501 // Get the current mouse position.
1502 wxPoint wxGetMousePosition()
1503 {
1504 #if wxUSE_NANOX
1505 /* TODO */
1506 return wxPoint(0, 0);
1507 #else
1508 Display *display = wxGlobalDisplay();
1509 Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
1510 Window rootReturn, childReturn;
1511 int rootX, rootY, winX, winY;
1512 unsigned int maskReturn;
1513
1514 XQueryPointer (display,
1515 rootWindow,
1516 &rootReturn,
1517 &childReturn,
1518 &rootX, &rootY, &winX, &winY, &maskReturn);
1519 return wxPoint(rootX, rootY);
1520 #endif
1521 }
1522
1523
1524 // ----------------------------------------------------------------------------
1525 // wxNoOptimize: switch off size optimization
1526 // ----------------------------------------------------------------------------
1527
1528 int wxNoOptimize::ms_count = 0;
1529