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