1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
27 #include "wx/dcclient.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"
38 #include "wx/scrolwin.h"
39 #include "wx/module.h"
40 #include "wx/menuitem.h"
43 #if wxUSE_DRAG_AND_DROP
47 #include "wx/x11/private.h"
48 #include "X11/Xutil.h"
52 // ----------------------------------------------------------------------------
53 // global variables for this module
54 // ----------------------------------------------------------------------------
56 extern wxHashTable
*wxWidgetHashTable
;
57 static wxWindow
* g_captureWindow
= NULL
;
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
73 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 void wxWindowX11::Init()
91 // generic initializations first
95 m_mainWidget
= (WXWindow
) 0;
96 m_winCaptured
= FALSE
;
97 m_needsInputFocus
= FALSE
;
99 m_isBeingDeleted
= FALSE
;
104 // real construction (Init() must have been called before!)
105 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
109 const wxString
& name
)
111 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
113 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
115 parent
->AddChild(this);
117 int w
= size
.GetWidth();
118 int h
= size
.GetHeight();
126 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
127 int xscreen
= DefaultScreen( xdisplay
);
128 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
130 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
131 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
133 m_foregroundColour
= *wxBLACK
;
134 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
136 Window parentWindow
= (Window
) parent
->GetMainWindow();
150 Window xwindow
= XCreateSimpleWindow(
151 xdisplay
, parentWindow
,
152 pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 0,
153 m_backgroundColour
.GetPixel(),
154 m_backgroundColour
.GetPixel() );
156 m_mainWidget
= (WXWindow
) xwindow
;
158 // Select event types wanted
159 XSelectInput( xdisplay
, xwindow
,
160 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
161 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
162 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
165 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
167 // Is a subwindow, so map immediately
169 XMapWindow( xdisplay
, xwindow
);
171 // Without this, the cursor may not be restored properly (e.g. in splitter
173 SetCursor(*wxSTANDARD_CURSOR
);
174 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
176 // Set background to None which will prevent X11 from clearing the
177 // background comletely.
178 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
180 // Don't call this, it can have nasty repercussions for composite controls,
182 // SetSize(pos.x, pos.y, size.x, size.y);
188 wxWindowX11::~wxWindowX11()
190 if (g_captureWindow
== this)
191 g_captureWindow
= NULL
;
193 m_isBeingDeleted
= TRUE
;
195 // X11-specific actions first
196 Window main
= (Window
) m_mainWidget
;
199 // Removes event handlers
200 //DetachWidget(main);
204 m_parent
->RemoveChild( this );
208 // Destroy the window
211 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
212 wxDeleteWindowFromTable( main
);
213 XDestroyWindow( wxGlobalDisplay(), main
);
218 // ---------------------------------------------------------------------------
220 // ---------------------------------------------------------------------------
222 void wxWindowX11::SetFocus()
224 Window xwindow
= (Window
) GetMainWindow();
226 wxCHECK_RET( xwindow
, wxT("invalid window") );
228 if (wxWindowIsVisible(xwindow
))
230 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
231 m_needsInputFocus
= FALSE
;
235 m_needsInputFocus
= TRUE
;
239 // Get the window with the focus
240 wxWindow
*wxWindowBase::FindFocus()
242 Window xfocus
= (Window
) 0;
245 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
248 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
256 // Enabling/disabling handled by event loop, and not sending events
258 bool wxWindowX11::Enable(bool enable
)
260 if ( !wxWindowBase::Enable(enable
) )
266 bool wxWindowX11::Show(bool show
)
268 wxWindowBase::Show(show
);
270 Window xwin
= (Window
) GetXWindow();
271 Display
*xdisp
= (Display
*) GetXDisplay();
275 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
277 XMapWindow(xdisp
, xwin
);
283 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
285 XUnmapWindow(xdisp
, xwin
);
291 // Raise the window to the top of the Z order
292 void wxWindowX11::Raise()
295 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
298 // Lower the window to the bottom of the Z order
299 void wxWindowX11::Lower()
302 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
305 void wxWindowX11::DoCaptureMouse()
307 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
309 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
320 Window xwindow
= (Window
) GetMainWindow();
322 wxCHECK_RET( xwindow
, wxT("invalid window") );
324 g_captureWindow
= (wxWindow
*) this;
328 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
330 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
334 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
337 if (res
!= GrabSuccess
)
340 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
342 if (res
== GrabNotViewable
)
344 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
346 g_captureWindow
= NULL
;
350 wxLogDebug("Grabbed pointer");
353 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
354 (Window
) GetMainWindow(),
356 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
362 if (res
!= GrabSuccess
)
364 wxLogDebug("Failed to grab mouse buttons.");
365 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
371 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
372 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
378 if (res
!= GrabSuccess
)
380 wxLogDebug("Failed to grab keyboard.");
381 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
382 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
383 (Window
) GetMainWindow());
388 m_winCaptured
= TRUE
;
392 void wxWindowX11::DoReleaseMouse()
394 g_captureWindow
= NULL
;
396 if ( !m_winCaptured
)
399 Window xwindow
= (Window
) GetMainWindow();
403 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
405 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
406 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
409 wxLogDebug("Ungrabbed pointer");
411 m_winCaptured
= FALSE
;
414 bool wxWindowX11::SetFont(const wxFont
& font
)
416 if ( !wxWindowBase::SetFont(font
) )
425 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
427 if ( !wxWindowBase::SetCursor(cursor
) )
433 Window xwindow
= (Window
) GetMainWindow();
435 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
437 wxCursor cursorToUse
;
439 cursorToUse
= m_cursor
;
441 cursorToUse
= *wxSTANDARD_CURSOR
;
443 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
445 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
450 // Coordinates relative to the window
451 void wxWindowX11::WarpPointer (int x
, int y
)
453 Window xwindow
= (Window
) GetMainWindow();
455 wxCHECK_RET( xwindow
, wxT("invalid window") );
457 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
460 // Does a physical scroll
461 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
463 Window xwindow
= (Window
) GetMainWindow();
465 wxCHECK_RET( xwindow
, wxT("invalid window") );
467 Display
*xdisplay
= wxGlobalDisplay();
469 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
470 XSetGraphicsExposures( xdisplay
, xgc
, True
);
487 GetClientSize( &cw
, &ch
);
490 wxPoint offset
= GetClientAreaOrigin();
494 int w
= cw
- abs(dx
);
495 int h
= ch
- abs(dy
);
497 if ((h
< 0) || (w
< 0))
504 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
505 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
506 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
507 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
511 if (dx
< 0) s_x
+= -dx
;
512 if (dy
< 0) s_y
+= -dy
;
513 if (dx
> 0) d_x
= dx
;
514 if (dy
> 0) d_y
= dy
;
516 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
518 // printf( "s_x %d s_y %d w %d h %d d_x %d d_y %d\n", s_x, s_y, w, h, d_x, d_y );
520 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
522 m_updateRegion
.Union( rect
);
523 m_clearRegion
.Union( rect
);
526 XFreeGC( xdisplay
, xgc
);
529 // ---------------------------------------------------------------------------
531 // ---------------------------------------------------------------------------
533 #if wxUSE_DRAG_AND_DROP
535 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
542 // Old style file-manager drag&drop
543 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
548 // ----------------------------------------------------------------------------
550 // ----------------------------------------------------------------------------
554 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
559 #endif // wxUSE_TOOLTIPS
561 // ---------------------------------------------------------------------------
562 // moving and resizing
563 // ---------------------------------------------------------------------------
565 bool wxWindowX11::PreResize()
571 void wxWindowX11::DoGetSize(int *x
, int *y
) const
573 Window xwindow
= (Window
) GetMainWindow();
575 wxCHECK_RET( xwindow
, wxT("invalid window") );
577 XSync(wxGlobalDisplay(), False
);
578 XWindowAttributes attr
;
579 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
584 *x
= attr
.width
/* + 2*m_borderSize */ ;
585 *y
= attr
.height
/* + 2*m_borderSize */ ;
589 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
591 Window window
= (Window
) m_mainWidget
;
594 XSync(wxGlobalDisplay(), False
);
595 XWindowAttributes attr
;
596 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
604 // We may be faking the client origin. So a window that's really at (0, 30)
605 // may appear (to wxWin apps) to be at (0, 0).
608 wxPoint
pt(GetParent()->GetClientAreaOrigin());
616 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
618 Display
*display
= wxGlobalDisplay();
619 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
620 Window thisWindow
= (Window
) m_mainWidget
;
625 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
628 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
630 Display
*display
= wxGlobalDisplay();
631 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
632 Window thisWindow
= (Window
) m_mainWidget
;
637 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
641 // Get size *available for subwindows* i.e. excluding menu bar etc.
642 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
644 Window window
= (Window
) m_mainWidget
;
648 XSync(wxGlobalDisplay(), False
);
649 XWindowAttributes attr
;
650 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
661 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
663 if (!GetMainWindow())
666 XWindowChanges windowChanges
;
669 windowChanges
.width
= 0;
670 windowChanges
.height
= 0;
671 windowChanges
.stack_mode
= 0;
674 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
677 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
681 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
684 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
688 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
690 windowChanges
.width
= width
/* - m_borderSize*2 */;
691 if (windowChanges
.width
== 0)
692 windowChanges
.width
= 1;
693 valueMask
|= CWWidth
;
695 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
697 windowChanges
.height
= height
/* -m_borderSize*2*/;
698 if (windowChanges
.height
== 0)
699 windowChanges
.height
= 1;
700 valueMask
|= CWHeight
;
703 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
704 valueMask
, & windowChanges
);
705 XSync(wxGlobalDisplay(), False
);
708 void wxWindowX11::DoSetClientSize(int width
, int height
)
710 if (!GetMainWindow())
713 XWindowChanges windowChanges
;
718 windowChanges
.width
= width
;
719 valueMask
|= CWWidth
;
723 windowChanges
.height
= height
;
724 valueMask
|= CWHeight
;
726 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
727 valueMask
, & windowChanges
);
728 XSync(wxGlobalDisplay(), False
);
731 // For implementation purposes - sometimes decorations make the client area
733 wxPoint
wxWindowX11::GetClientAreaOrigin() const
735 return wxPoint(0, 0);
738 // Makes an adjustment to the window position (for example, a frame that has
739 // a toolbar that it manages itself).
740 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
742 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
744 wxPoint
pt(GetParent()->GetClientAreaOrigin());
745 x
+= pt
.x
; y
+= pt
.y
;
749 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
756 XSizeHints sizeHints
;
759 if (minW
> -1 && minH
> -1)
761 sizeHints
.flags
|= PMinSize
;
762 sizeHints
.min_width
= minW
;
763 sizeHints
.min_height
= minH
;
765 if (maxW
> -1 && maxH
> -1)
767 sizeHints
.flags
|= PMaxSize
;
768 sizeHints
.max_width
= maxW
;
769 sizeHints
.max_height
= maxH
;
771 if (incW
> -1 && incH
> -1)
773 sizeHints
.flags
|= PResizeInc
;
774 sizeHints
.width_inc
= incW
;
775 sizeHints
.height_inc
= incH
;
778 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
781 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
783 DoSetSize(x
, y
, width
, height
);
786 // ---------------------------------------------------------------------------
788 // ---------------------------------------------------------------------------
790 int wxWindowX11::GetCharHeight() const
792 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
794 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
796 int direction
, ascent
, descent
;
798 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
801 // return (overall.ascent + overall.descent);
802 return (ascent
+ descent
);
805 int wxWindowX11::GetCharWidth() const
807 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
809 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
811 int direction
, ascent
, descent
;
813 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
816 return overall
.width
;
819 void wxWindowX11::GetTextExtent(const wxString
& string
,
821 int *descent
, int *externalLeading
,
822 const wxFont
*theFont
) const
824 wxFont fontToUse
= m_font
;
825 if (theFont
) fontToUse
= *theFont
;
827 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
829 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
831 int direction
, ascent
, descent2
;
833 int slen
= string
.Len();
837 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
838 &ascent
, &descent2
, &overall
);
841 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
842 &direction
, &ascent
, &descent2
, &overall
);
845 *x
= (overall
.width
);
847 *y
= (ascent
+ descent2
);
851 *externalLeading
= 0;
855 // ----------------------------------------------------------------------------
857 // ----------------------------------------------------------------------------
859 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
865 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
866 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
871 GetSize( &width
, &height
);
873 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
874 m_clearRegion
.Clear();
875 m_clearRegion
.Union( 0, 0, width
, height
);
881 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
882 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
887 GetSize( &width
, &height
);
889 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
890 m_updateRegion
.Clear();
891 m_updateRegion
.Union( 0, 0, width
, height
);
895 void wxWindowX11::Update()
897 if (!m_updateRegion
.IsEmpty())
899 // Actually send erase and paint events.
900 X11SendPaintEvents();
904 void wxWindowX11::Clear()
906 wxClientDC
dc((wxWindow
*) this);
907 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
908 dc
.SetBackground(brush
);
912 void wxWindowX11::X11SendPaintEvents()
914 m_clipPaintRegion
= TRUE
;
916 if (!m_clearRegion
.IsEmpty())
918 wxWindowDC
dc( (wxWindow
*)this );
919 dc
.SetClippingRegion( m_clearRegion
);
921 wxEraseEvent
erase_event( GetId(), &dc
);
922 erase_event
.SetEventObject( this );
924 if (!GetEventHandler()->ProcessEvent(erase_event
))
926 printf( "Hallo!\n" );
927 Window xwindow
= (Window
) GetMainWindow();
928 Display
*xdisplay
= wxGlobalDisplay();
929 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
930 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
931 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
932 wxRegionIterator
upd( m_clearRegion
);
935 XFillRectangle( xdisplay
, xwindow
, xgc
,
936 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
940 m_clearRegion
.Clear();
943 wxNcPaintEvent
nc_paint_event( GetId() );
944 nc_paint_event
.SetEventObject( this );
945 GetEventHandler()->ProcessEvent( nc_paint_event
);
947 wxPaintEvent
paint_event( GetId() );
948 paint_event
.SetEventObject( this );
949 GetEventHandler()->ProcessEvent( paint_event
);
951 m_updateRegion
.Clear();
953 m_clipPaintRegion
= FALSE
;
956 // ----------------------------------------------------------------------------
958 // ----------------------------------------------------------------------------
960 // Responds to colour changes: passes event on to children.
961 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
963 wxWindowList::Node
*node
= GetChildren().GetFirst();
966 // Only propagate to non-top-level windows
967 wxWindow
*win
= node
->GetData();
968 if ( win
->GetParent() )
970 wxSysColourChangedEvent event2
;
971 event
.m_eventObject
= win
;
972 win
->GetEventHandler()->ProcessEvent(event2
);
975 node
= node
->GetNext();
979 void wxWindowX11::OnInternalIdle()
981 // Update invalidated regions.
984 // This calls the UI-update mechanism (querying windows for
985 // menu/toolbar/control state information)
988 // Set the input focus if couldn't do it before
989 if (m_needsInputFocus
)
993 // ----------------------------------------------------------------------------
994 // function which maintain the global hash table mapping Widgets to wxWindows
995 // ----------------------------------------------------------------------------
997 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
999 wxWindow
*oldItem
= NULL
;
1000 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1002 wxLogDebug("Widget table clash: new widget is %ld, %s",
1003 (long)w
, win
->GetClassInfo()->GetClassName());
1007 wxWidgetHashTable
->Put((long) w
, win
);
1009 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1010 w
, win
, win
->GetClassInfo()->GetClassName());
1015 wxWindow
*wxGetWindowFromTable(Window w
)
1017 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1020 void wxDeleteWindowFromTable(Window w
)
1022 wxWidgetHashTable
->Delete((long)w
);
1025 // ----------------------------------------------------------------------------
1026 // add/remove window from the table
1027 // ----------------------------------------------------------------------------
1029 // ----------------------------------------------------------------------------
1030 // X11-specific accessors
1031 // ----------------------------------------------------------------------------
1033 // Get the underlying X window
1034 WXWindow
wxWindowX11::GetXWindow() const
1036 return GetMainWindow();
1039 // Get the underlying X display
1040 WXDisplay
*wxWindowX11::GetXDisplay() const
1042 return wxGetDisplay();
1045 WXWindow
wxWindowX11::GetMainWindow() const
1047 return m_mainWidget
;
1050 // ----------------------------------------------------------------------------
1051 // TranslateXXXEvent() functions
1052 // ----------------------------------------------------------------------------
1054 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1056 switch (xevent
->xany
.type
)
1064 wxEventType eventType
= wxEVT_NULL
;
1066 if (xevent
->xany
.type
== EnterNotify
)
1068 //if (local_event.xcrossing.mode!=NotifyNormal)
1069 // return ; // Ignore grab events
1070 eventType
= wxEVT_ENTER_WINDOW
;
1071 // canvas->GetEventHandler()->OnSetFocus();
1073 else if (xevent
->xany
.type
== LeaveNotify
)
1075 //if (local_event.xcrossingr.mode!=NotifyNormal)
1076 // return ; // Ignore grab events
1077 eventType
= wxEVT_LEAVE_WINDOW
;
1078 // canvas->GetEventHandler()->OnKillFocus();
1080 else if (xevent
->xany
.type
== MotionNotify
)
1082 eventType
= wxEVT_MOTION
;
1084 else if (xevent
->xany
.type
== ButtonPress
)
1086 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1088 if (xevent
->xbutton
.button
== Button1
)
1090 eventType
= wxEVT_LEFT_DOWN
;
1093 else if (xevent
->xbutton
.button
== Button2
)
1095 eventType
= wxEVT_MIDDLE_DOWN
;
1098 else if (xevent
->xbutton
.button
== Button3
)
1100 eventType
= wxEVT_RIGHT_DOWN
;
1104 // check for a double click
1105 // TODO: where can we get this value from?
1106 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1107 long dclickTime
= 200;
1108 long ts
= wxevent
.GetTimestamp();
1110 int buttonLast
= win
->GetLastClickedButton();
1111 long lastTS
= win
->GetLastClickTime();
1112 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1115 win
->SetLastClick(0, ts
);
1116 if ( eventType
== wxEVT_LEFT_DOWN
)
1117 eventType
= wxEVT_LEFT_DCLICK
;
1118 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1119 eventType
= wxEVT_MIDDLE_DCLICK
;
1120 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1121 eventType
= wxEVT_RIGHT_DCLICK
;
1125 // not fast enough or different button
1126 win
->SetLastClick(button
, ts
);
1129 else if (xevent
->xany
.type
== ButtonRelease
)
1131 if (xevent
->xbutton
.button
== Button1
)
1133 eventType
= wxEVT_LEFT_UP
;
1135 else if (xevent
->xbutton
.button
== Button2
)
1137 eventType
= wxEVT_MIDDLE_UP
;
1139 else if (xevent
->xbutton
.button
== Button3
)
1141 eventType
= wxEVT_RIGHT_UP
;
1150 wxevent
.SetEventType(eventType
);
1152 wxevent
.m_x
= xevent
->xbutton
.x
;
1153 wxevent
.m_y
= xevent
->xbutton
.y
;
1155 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1156 || (event_left_is_down (xevent
)
1157 && (eventType
!= wxEVT_LEFT_UP
)));
1158 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1159 || (event_middle_is_down (xevent
)
1160 && (eventType
!= wxEVT_MIDDLE_UP
)));
1161 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1162 || (event_right_is_down (xevent
)
1163 && (eventType
!= wxEVT_RIGHT_UP
)));
1165 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1166 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1167 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1168 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1170 wxevent
.SetId(win
->GetId());
1171 wxevent
.SetEventObject(win
);
1179 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1181 switch (xevent
->xany
.type
)
1189 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1190 int id
= wxCharCodeXToWX (keySym
);
1192 if (xevent
->xkey
.state
& ShiftMask
)
1193 wxevent
.m_shiftDown
= TRUE
;
1194 if (xevent
->xkey
.state
& ControlMask
)
1195 wxevent
.m_controlDown
= TRUE
;
1196 if (xevent
->xkey
.state
& Mod3Mask
)
1197 wxevent
.m_altDown
= TRUE
;
1198 if (xevent
->xkey
.state
& Mod1Mask
)
1199 wxevent
.m_metaDown
= TRUE
;
1200 wxevent
.SetEventObject(win
);
1201 wxevent
.m_keyCode
= id
;
1202 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1204 wxevent
.m_x
= xevent
->xbutton
.x
;
1205 wxevent
.m_y
= xevent
->xbutton
.y
;
1219 // ----------------------------------------------------------------------------
1221 // ----------------------------------------------------------------------------
1223 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1225 wxWindowBase::SetBackgroundColour(col
);
1227 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1228 int xscreen
= DefaultScreen( xdisplay
);
1229 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1231 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1233 if (!GetMainWindow())
1237 XSetWindowAttributes attrib;
1238 attrib.background_pixel = colour.GetPixel();
1240 XChangeWindowAttributes(wxGlobalDisplay(),
1241 (Window) GetMainWindow(),
1249 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1251 if ( !wxWindowBase::SetForegroundColour(col
) )
1257 // ----------------------------------------------------------------------------
1259 // ----------------------------------------------------------------------------
1261 wxWindow
*wxGetActiveWindow()
1264 wxFAIL_MSG("Not implemented");
1269 wxWindow
*wxWindowBase::GetCapture()
1271 return (wxWindow
*)g_captureWindow
;
1275 // Find the wxWindow at the current mouse position, returning the mouse
1277 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1279 return wxFindWindowAtPoint(wxGetMousePosition());
1282 // Get the current mouse position.
1283 wxPoint
wxGetMousePosition()
1285 Display
*display
= wxGlobalDisplay();
1286 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1287 Window rootReturn
, childReturn
;
1288 int rootX
, rootY
, winX
, winY
;
1289 unsigned int maskReturn
;
1291 XQueryPointer (display
,
1295 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1296 return wxPoint(rootX
, rootY
);
1300 // ----------------------------------------------------------------------------
1301 // wxNoOptimize: switch off size optimization
1302 // ----------------------------------------------------------------------------
1304 int wxNoOptimize::ms_count
= 0;