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