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