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