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