1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/window.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #if defined(__BORLANDC__)
19 // ============================================================================
21 // ============================================================================
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 #include "wx/window.h"
37 #include "wx/dcclient.h"
38 #include "wx/button.h"
40 #include "wx/dialog.h"
42 #include "wx/settings.h"
43 #include "wx/msgdlg.h"
44 #include "wx/scrolbar.h"
45 #include "wx/listbox.h"
46 #include "wx/scrolwin.h"
47 #include "wx/layout.h"
48 #include "wx/menuitem.h"
49 #include "wx/module.h"
50 #include "wx/unix/utilsx11.h"
53 #include "wx/fontutil.h"
54 #include "wx/univ/renderer.h"
56 #if wxUSE_DRAG_AND_DROP
60 #include "wx/x11/private.h"
61 #include "X11/Xutil.h"
65 // ----------------------------------------------------------------------------
66 // global variables for this module
67 // ----------------------------------------------------------------------------
69 static wxWindow
* g_captureWindow
= NULL
;
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
77 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
78 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
86 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
87 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
90 // ============================================================================
92 // ============================================================================
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 void wxWindowX11::Init()
105 m_mainWindow
= (WXWindow
) 0;
106 m_clientWindow
= (WXWindow
) 0;
107 m_insertIntoMain
= false;
108 m_updateNcArea
= false;
110 m_winCaptured
= false;
111 m_needsInputFocus
= false;
117 // real construction (Init() must have been called before!)
118 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
122 const wxString
& name
)
124 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
126 // Get default border
127 wxBorder border
= GetBorder(style
);
128 style
&= ~wxBORDER_MASK
;
131 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
133 parent
->AddChild(this);
135 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
136 int xscreen
= DefaultScreen( xdisplay
);
137 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
138 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
140 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
141 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
143 m_foregroundColour
= *wxBLACK
;
144 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
146 Window xparent
= (Window
) parent
->GetClientAreaWindow();
148 // Add window's own scrollbars to main window, not to client window
149 if (parent
->GetInsertIntoMain())
151 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
152 xparent
= (Window
) parent
->X11GetMainWindow();
155 // Size (not including the border) must be nonzero (or a Value error results)!
156 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
164 if (pos2
.x
== wxDefaultCoord
)
166 if (pos2
.y
== wxDefaultCoord
)
169 AdjustForParentClientOrigin(pos2
.x
, pos2
.y
);
171 #if wxUSE_TWO_WINDOWS
172 bool need_two_windows
=
173 ((( wxSUNKEN_BORDER
| wxBORDER_THEME
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
175 bool need_two_windows
= false;
179 long xattributes
= 0;
181 XSetWindowAttributes xattributes
;
182 long xattributes_mask
= 0;
184 xattributes_mask
|= CWBackPixel
;
185 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
187 xattributes_mask
|= CWBorderPixel
;
188 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
190 xattributes_mask
|= CWEventMask
;
193 if (need_two_windows
)
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());
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
);
210 xattributes
.event_mask
=
211 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
213 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
214 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
218 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
220 m_mainWindow
= (WXWindow
) xwindow
;
221 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
223 XMapWindow( xdisplay
, xwindow
);
226 xattributes
.event_mask
=
227 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
228 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
229 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
230 PropertyChangeMask
| VisibilityChangeMask
;
232 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
234 xattributes_mask
|= CWBitGravity
;
235 xattributes
.bit_gravity
= StaticGravity
;
239 if (HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxRAISED_BORDER
) || HasFlag(wxBORDER_THEME
))
246 else if (HasFlag( wxSIMPLE_BORDER
))
259 // Make again sure the size is nonzero.
266 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
267 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
269 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
270 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
271 XSelectInput( xdisplay
, xwindow
,
272 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
273 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
274 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
275 PropertyChangeMask
);
278 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
279 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
282 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
284 m_clientWindow
= (WXWindow
) xwindow
;
285 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
287 XMapWindow( xdisplay
, xwindow
);
291 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
293 long backColor
, foreColor
;
294 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
295 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
297 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
298 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
299 XSelectInput( xdisplay
, xwindow
,
300 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
301 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
302 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
303 PropertyChangeMask
);
306 xattributes
.event_mask
=
307 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
308 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
309 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
310 PropertyChangeMask
| VisibilityChangeMask
;
312 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
314 xattributes_mask
|= CWBitGravity
;
315 xattributes
.bit_gravity
= NorthWestGravity
;
318 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
319 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
322 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
324 m_mainWindow
= (WXWindow
) xwindow
;
325 m_clientWindow
= m_mainWindow
;
326 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
328 XMapWindow( xdisplay
, xwindow
);
331 // Is a subwindow, so map immediately
334 // Without this, the cursor may not be restored properly (e.g. in splitter
336 SetCursor(*wxSTANDARD_CURSOR
);
337 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
339 // Don't call this, it can have nasty repercussions for composite controls,
341 // SetSize(pos.x, pos.y, size.x, size.y);
347 wxWindowX11::~wxWindowX11()
351 if (g_captureWindow
== this)
352 g_captureWindow
= NULL
;
356 if (m_clientWindow
!= m_mainWindow
)
358 // Destroy the cleint window
359 Window xwindow
= (Window
) m_clientWindow
;
360 wxDeleteClientWindowFromTable( xwindow
);
361 XDestroyWindow( wxGlobalDisplay(), xwindow
);
362 m_clientWindow
= NULL
;
365 // Destroy the window
368 Window xwindow
= (Window
) m_mainWindow
;
369 wxDeleteWindowFromTable( xwindow
);
370 XDestroyWindow( wxGlobalDisplay(), xwindow
);
375 // ---------------------------------------------------------------------------
377 // ---------------------------------------------------------------------------
379 void wxWindowX11::SetFocus()
381 Window xwindow
= (Window
) m_clientWindow
;
383 wxCHECK_RET( xwindow
, wxT("invalid window") );
385 // Don't assert; we might be trying to set the focus for a panel
386 // with only static controls, so the panel returns false from AcceptsFocus.
387 // The app should be not be expected to deal with this.
392 if (GetName() == "scrollBar")
399 if (wxWindowIsVisible(xwindow
))
401 wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
402 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
403 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
404 m_needsInputFocus
= false;
408 m_needsInputFocus
= true;
412 // Get the window with the focus
413 wxWindow
*wxWindowBase::DoFindFocus()
415 Window xfocus
= (Window
) 0;
418 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
421 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
424 win
= wxGetClientWindowFromTable( xfocus
);
433 // Enabling/disabling handled by event loop, and not sending events
435 bool wxWindowX11::Enable(bool enable
)
437 if ( !wxWindowBase::Enable(enable
) )
443 bool wxWindowX11::Show(bool show
)
445 wxWindowBase::Show(show
);
447 Window xwindow
= (Window
) m_mainWindow
;
448 Display
*xdisp
= wxGlobalDisplay();
451 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
452 XMapWindow(xdisp
, xwindow
);
456 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
457 XUnmapWindow(xdisp
, xwindow
);
463 // Raise the window to the top of the Z order
464 void wxWindowX11::Raise()
467 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
470 // Lower the window to the bottom of the Z order
471 void wxWindowX11::Lower()
474 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
477 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
482 wxString
wxWindowX11::GetLabel() const
485 return wxEmptyString
;
488 void wxWindowX11::DoCaptureMouse()
490 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
492 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
503 Window xwindow
= (Window
) m_clientWindow
;
505 wxCHECK_RET( xwindow
, wxT("invalid window") );
507 g_captureWindow
= (wxWindow
*) this;
511 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
513 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
517 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
520 if (res
!= GrabSuccess
)
523 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
525 if (res
== GrabNotViewable
)
527 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
530 g_captureWindow
= NULL
;
534 m_winCaptured
= true;
538 void wxWindowX11::DoReleaseMouse()
540 g_captureWindow
= NULL
;
542 if ( !m_winCaptured
)
545 Window xwindow
= (Window
) m_clientWindow
;
549 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
552 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
554 m_winCaptured
= false;
557 bool wxWindowX11::SetFont(const wxFont
& font
)
559 if ( !wxWindowBase::SetFont(font
) )
568 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
570 if ( !wxWindowBase::SetCursor(cursor
) )
576 Window xwindow
= (Window
) m_clientWindow
;
578 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
580 wxCursor cursorToUse
;
582 cursorToUse
= m_cursor
;
584 cursorToUse
= *wxSTANDARD_CURSOR
;
586 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
588 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
593 // Coordinates relative to the window
594 void wxWindowX11::WarpPointer (int x
, int y
)
596 Window xwindow
= (Window
) m_clientWindow
;
598 wxCHECK_RET( xwindow
, wxT("invalid window") );
600 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
603 // Does a physical scroll
604 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
606 // No scrolling requested.
607 if ((dx
== 0) && (dy
== 0)) return;
609 if (!m_updateRegion
.IsEmpty())
611 m_updateRegion
.Offset( dx
, dy
);
615 GetSize( &cw
, &ch
); // GetClientSize() ??
616 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
619 if (!m_clearRegion
.IsEmpty())
621 m_clearRegion
.Offset( dx
, dy
);
625 GetSize( &cw
, &ch
); // GetClientSize() ??
626 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
629 Window xwindow
= (Window
) GetClientAreaWindow();
631 wxCHECK_RET( xwindow
, wxT("invalid window") );
633 Display
*xdisplay
= wxGlobalDisplay();
635 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
636 XSetGraphicsExposures( xdisplay
, xgc
, True
);
654 GetClientSize( &cw
, &ch
);
657 #if wxUSE_TWO_WINDOWS
658 wxPoint
offset( 0,0 );
660 wxPoint offset
= GetClientAreaOrigin();
665 int w
= cw
- abs(dx
);
666 int h
= ch
- abs(dy
);
668 if ((h
< 0) || (w
< 0))
675 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
676 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
677 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
678 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
683 if (dx
< 0) s_x
+= -dx
;
684 if (dy
< 0) s_y
+= -dy
;
685 if (dx
> 0) d_x
+= dx
+ offset
.x
;
686 if (dy
> 0) d_y
+= dy
+ offset
.y
;
688 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
690 // 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 );
692 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
694 m_updateRegion
.Union( rect
);
695 m_clearRegion
.Union( rect
);
698 XFreeGC( xdisplay
, xgc
);
700 // Move Clients, but not the scrollbars
701 // FIXME: There may be a better method to move a lot of Windows within X11
702 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
703 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
704 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
707 // Only propagate to non-top-level windows
708 wxWindow
*win
= node
->GetData();
709 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
711 wxPoint pos
= win
->GetPosition();
712 // Add the delta to the old Position
715 win
->SetPosition(pos
);
717 node
= node
->GetNext();
721 // ---------------------------------------------------------------------------
723 // ---------------------------------------------------------------------------
725 #if wxUSE_DRAG_AND_DROP
727 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
734 // Old style file-manager drag&drop
735 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
740 // ----------------------------------------------------------------------------
742 // ----------------------------------------------------------------------------
746 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
751 #endif // wxUSE_TOOLTIPS
753 // ---------------------------------------------------------------------------
754 // moving and resizing
755 // ---------------------------------------------------------------------------
757 bool wxWindowX11::PreResize()
763 void wxWindowX11::DoGetSize(int *x
, int *y
) const
765 Window xwindow
= (Window
) m_mainWindow
;
767 wxCHECK_RET( xwindow
, wxT("invalid window") );
769 //XSync(wxGlobalDisplay(), False);
771 XWindowAttributes attr
;
772 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
777 *x
= attr
.width
/* + 2*m_borderSize */ ;
778 *y
= attr
.height
/* + 2*m_borderSize */ ;
782 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
784 Window window
= (Window
) m_mainWindow
;
787 //XSync(wxGlobalDisplay(), False);
788 XWindowAttributes attr
;
789 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
797 // We may be faking the client origin. So a window that's really at (0, 30)
798 // may appear (to wxWin apps) to be at (0, 0).
801 wxPoint
pt(GetParent()->GetClientAreaOrigin());
809 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
811 Display
*display
= wxGlobalDisplay();
812 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
813 Window thisWindow
= (Window
) m_clientWindow
;
818 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
819 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
823 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
825 Display
*display
= wxGlobalDisplay();
826 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
827 Window thisWindow
= (Window
) m_clientWindow
;
832 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
833 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
838 // Get size *available for subwindows* i.e. excluding menu bar etc.
839 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
841 Window window
= (Window
) m_mainWindow
;
845 XWindowAttributes attr
;
846 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
857 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
859 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
861 Window xwindow
= (Window
) m_mainWindow
;
863 wxCHECK_RET( xwindow
, wxT("invalid window") );
865 XWindowAttributes attr
;
866 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
867 wxCHECK_RET( status
, wxT("invalid window attributes") );
871 int new_w
= attr
.width
;
872 int new_h
= attr
.height
;
874 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
877 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
880 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
883 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
886 if (width
!= wxDefaultCoord
)
892 if (height
!= wxDefaultCoord
)
899 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
902 void wxWindowX11::DoSetClientSize(int width
, int height
)
904 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
906 Window xwindow
= (Window
) m_mainWindow
;
908 wxCHECK_RET( xwindow
, wxT("invalid window") );
910 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
912 if (m_mainWindow
!= m_clientWindow
)
914 xwindow
= (Window
) m_clientWindow
;
916 wxWindow
*window
= (wxWindow
*) this;
917 wxRenderer
*renderer
= window
->GetRenderer();
920 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
921 width
-= border
.x
+ border
.width
;
922 height
-= border
.y
+ border
.height
;
925 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
929 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
931 Window xwindow
= (Window
) m_mainWindow
;
933 wxCHECK_RET( xwindow
, wxT("invalid window") );
937 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
938 if (m_mainWindow
!= m_clientWindow
)
940 xwindow
= (Window
) m_clientWindow
;
942 wxWindow
*window
= (wxWindow
*) this;
943 wxRenderer
*renderer
= window
->GetRenderer();
946 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
949 width
-= border
.x
+ border
.width
;
950 height
-= border
.y
+ border
.height
;
958 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
959 if (sb
&& sb
->IsShown())
961 wxSize size
= sb
->GetSize();
964 sb
= window
->GetScrollbar( wxVERTICAL
);
965 if (sb
&& sb
->IsShown())
967 wxSize size
= sb
->GetSize();
971 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
976 XWindowChanges windowChanges
;
979 windowChanges
.width
= width
;
980 windowChanges
.height
= height
;
981 windowChanges
.stack_mode
= 0;
982 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
984 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
989 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
997 XSizeHints sizeHints
;
1000 if (minW
> -1 && minH
> -1)
1002 sizeHints
.flags
|= PMinSize
;
1003 sizeHints
.min_width
= minW
;
1004 sizeHints
.min_height
= minH
;
1006 if (maxW
> -1 && maxH
> -1)
1008 sizeHints
.flags
|= PMaxSize
;
1009 sizeHints
.max_width
= maxW
;
1010 sizeHints
.max_height
= maxH
;
1012 if (incW
> -1 && incH
> -1)
1014 sizeHints
.flags
|= PResizeInc
;
1015 sizeHints
.width_inc
= incW
;
1016 sizeHints
.height_inc
= incH
;
1019 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1023 // ---------------------------------------------------------------------------
1025 // ---------------------------------------------------------------------------
1027 int wxWindowX11::GetCharHeight() const
1029 wxFont
font(GetFont());
1030 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1033 // There should be an easier way.
1034 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1035 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1036 pango_layout_set_text(layout
, "H", 1 );
1038 pango_layout_get_pixel_size(layout
, &w
, &h
);
1039 g_object_unref( G_OBJECT( layout
) );
1043 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1045 int direction
, ascent
, descent
;
1046 XCharStruct overall
;
1047 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1048 &descent
, &overall
);
1050 // return (overall.ascent + overall.descent);
1051 return (ascent
+ descent
);
1055 int wxWindowX11::GetCharWidth() const
1057 wxFont
font(GetFont());
1058 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1061 // There should be an easier way.
1062 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1063 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1064 pango_layout_set_text(layout
, "H", 1 );
1066 pango_layout_get_pixel_size(layout
, &w
, &h
);
1067 g_object_unref( G_OBJECT( layout
) );
1071 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1073 int direction
, ascent
, descent
;
1074 XCharStruct overall
;
1075 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1076 &descent
, &overall
);
1078 return overall
.width
;
1082 void wxWindowX11::DoGetTextExtent(const wxString
& string
,
1085 int *externalLeading
,
1086 const wxFont
*theFont
) const
1088 wxFont fontToUse
= GetFont();
1089 if (theFont
) fontToUse
= *theFont
;
1091 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1101 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1103 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1104 pango_layout_set_font_description(layout
, desc
);
1106 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1107 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1109 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1112 PangoRectangle rect
;
1113 pango_layout_line_get_extents(line
, NULL
, &rect
);
1115 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1116 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1119 // Do something about metrics here
1122 if (externalLeading
) (*externalLeading
) = 0; // ??
1124 g_object_unref( G_OBJECT( layout
) );
1126 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1128 int direction
, ascent
, descent2
;
1129 XCharStruct overall
;
1130 int slen
= string
.length();
1132 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1133 &direction
, &ascent
, &descent2
, &overall
);
1136 *x
= (overall
.width
);
1138 *y
= (ascent
+ descent2
);
1140 *descent
= descent2
;
1141 if (externalLeading
)
1142 *externalLeading
= 0;
1146 // ----------------------------------------------------------------------------
1148 // ----------------------------------------------------------------------------
1150 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1156 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1157 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1162 GetSize( &width
, &height
);
1164 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1165 m_clearRegion
.Clear();
1166 m_clearRegion
.Union( 0, 0, width
, height
);
1172 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1173 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1178 GetSize( &width
, &height
);
1180 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1181 m_updateRegion
.Clear();
1182 m_updateRegion
.Union( 0, 0, width
, height
);
1186 void wxWindowX11::Update()
1190 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1191 // Send nc paint events.
1192 SendNcPaintEvents();
1195 if (!m_updateRegion
.IsEmpty())
1197 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1198 // Actually send erase events.
1201 // Actually send paint events.
1206 void wxWindowX11::SendEraseEvents()
1208 if (m_clearRegion
.IsEmpty()) return;
1210 wxClientDC
dc( (wxWindow
*)this );
1211 dc
.SetDeviceClippingRegion( m_clearRegion
);
1213 wxEraseEvent
erase_event( GetId(), &dc
);
1214 erase_event
.SetEventObject( this );
1216 if (!HandleWindowEvent(erase_event
) )
1218 Display
*xdisplay
= wxGlobalDisplay();
1219 Window xwindow
= (Window
) GetClientAreaWindow();
1220 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1222 wxRegionIterator
upd( m_clearRegion
);
1225 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1226 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1231 m_clearRegion
.Clear();
1234 void wxWindowX11::SendPaintEvents()
1236 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1238 m_clipPaintRegion
= true;
1240 wxPaintEvent
paint_event( GetId() );
1241 paint_event
.SetEventObject( this );
1242 HandleWindowEvent( paint_event
);
1244 m_updateRegion
.Clear();
1246 m_clipPaintRegion
= false;
1249 void wxWindowX11::SendNcPaintEvents()
1251 wxWindow
*window
= (wxWindow
*) this;
1253 // All this for drawing the small square between the scrollbars.
1258 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1259 if (sb
&& sb
->IsShown())
1261 height
= sb
->GetSize().y
;
1262 y
= sb
->GetPosition().y
;
1264 sb
= window
->GetScrollbar( wxVERTICAL
);
1265 if (sb
&& sb
->IsShown())
1267 width
= sb
->GetSize().x
;
1268 x
= sb
->GetPosition().x
;
1270 Display
*xdisplay
= wxGlobalDisplay();
1271 Window xwindow
= (Window
) X11GetMainWindow();
1272 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1273 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1274 colour
.CalcPixel( (WXColormap
) cm
);
1276 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1278 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1282 wxNcPaintEvent
nc_paint_event( GetId() );
1283 nc_paint_event
.SetEventObject( this );
1284 HandleWindowEvent( nc_paint_event
);
1286 m_updateNcArea
= false;
1289 // ----------------------------------------------------------------------------
1291 // ----------------------------------------------------------------------------
1293 // Responds to colour changes: passes event on to children.
1294 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1296 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1299 // Only propagate to non-top-level windows
1300 wxWindow
*win
= node
->GetData();
1301 if ( win
->GetParent() )
1303 wxSysColourChangedEvent event2
;
1304 event
.SetEventObject(win
);
1305 win
->HandleWindowEvent(event2
);
1308 node
= node
->GetNext();
1312 // See handler for InFocus case in app.cpp for details.
1313 wxWindow
* g_GettingFocus
= NULL
;
1315 void wxWindowX11::OnInternalIdle()
1317 // Update invalidated regions.
1320 // This calls the UI-update mechanism (querying windows for
1321 // menu/toolbar/control state information)
1322 if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this) && IsShownOnScreen())
1323 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1325 // Set the input focus if couldn't do it before
1326 if (m_needsInputFocus
)
1330 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1331 printf(msg
.c_str());
1335 // If it couldn't set the focus now, there's
1336 // no point in trying again.
1337 m_needsInputFocus
= false;
1339 g_GettingFocus
= NULL
;
1342 // ----------------------------------------------------------------------------
1343 // function which maintain the global hash table mapping Widgets to wxWidgets
1344 // ----------------------------------------------------------------------------
1346 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1348 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1350 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1351 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1355 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1356 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1361 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1363 wxWindowHash::iterator i
= hash
->find(w
);
1364 return i
== hash
->end() ? NULL
: i
->second
;
1367 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1369 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1374 // ----------------------------------------------------------------------------
1376 // ----------------------------------------------------------------------------
1378 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1380 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1383 wxWindow
*wxGetWindowFromTable(Window w
)
1385 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1388 void wxDeleteWindowFromTable(Window w
)
1390 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1393 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1395 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1398 wxWindow
*wxGetClientWindowFromTable(Window w
)
1400 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1403 void wxDeleteClientWindowFromTable(Window w
)
1405 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1408 // ----------------------------------------------------------------------------
1409 // X11-specific accessors
1410 // ----------------------------------------------------------------------------
1412 WXWindow
wxWindowX11::X11GetMainWindow() const
1414 return m_mainWindow
;
1417 WXWindow
wxWindowX11::GetClientAreaWindow() const
1419 return m_clientWindow
;
1422 // ----------------------------------------------------------------------------
1423 // TranslateXXXEvent() functions
1424 // ----------------------------------------------------------------------------
1426 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
,
1428 Window
WXUNUSED(window
),
1431 switch (XEventGetType(xevent
))
1439 wxEventType eventType
= wxEVT_NULL
;
1441 if (XEventGetType(xevent
) == EnterNotify
)
1443 //if (local_event.xcrossing.mode!=NotifyNormal)
1444 // return ; // Ignore grab events
1445 eventType
= wxEVT_ENTER_WINDOW
;
1446 // canvas->GetEventHandler()->OnSetFocus();
1448 else if (XEventGetType(xevent
) == LeaveNotify
)
1450 //if (local_event.xcrossingr.mode!=NotifyNormal)
1451 // return ; // Ignore grab events
1452 eventType
= wxEVT_LEAVE_WINDOW
;
1453 // canvas->GetEventHandler()->OnKillFocus();
1455 else if (XEventGetType(xevent
) == MotionNotify
)
1457 eventType
= wxEVT_MOTION
;
1459 else if (XEventGetType(xevent
) == ButtonPress
)
1461 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1463 if (XButtonEventLChanged(xevent
))
1465 eventType
= wxEVT_LEFT_DOWN
;
1468 else if (XButtonEventMChanged(xevent
))
1470 eventType
= wxEVT_MIDDLE_DOWN
;
1473 else if (XButtonEventRChanged(xevent
))
1475 eventType
= wxEVT_RIGHT_DOWN
;
1478 else if ( xevent
->xbutton
.button
== Button4
||
1479 xevent
->xbutton
.button
== Button5
)
1481 // this is the same value as used under wxMSW
1482 static const int WHEEL_DELTA
= 120;
1484 eventType
= wxEVT_MOUSEWHEEL
;
1485 button
= xevent
->xbutton
.button
;
1487 wxevent
.m_linesPerAction
= 3;
1488 wxevent
.m_wheelDelta
= WHEEL_DELTA
;
1490 // Button 4 means mousewheel up, 5 means down
1491 wxevent
.m_wheelRotation
= button
== Button4
? WHEEL_DELTA
1495 // check for a double click
1496 // TODO: where can we get this value from?
1497 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1498 long dclickTime
= 200;
1499 long ts
= wxevent
.GetTimestamp();
1501 int buttonLast
= win
->GetLastClickedButton();
1502 long lastTS
= win
->GetLastClickTime();
1503 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1506 win
->SetLastClick(0, ts
);
1507 if ( eventType
== wxEVT_LEFT_DOWN
)
1508 eventType
= wxEVT_LEFT_DCLICK
;
1509 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1510 eventType
= wxEVT_MIDDLE_DCLICK
;
1511 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1512 eventType
= wxEVT_RIGHT_DCLICK
;
1516 // not fast enough or different button
1517 win
->SetLastClick(button
, ts
);
1520 else if (XEventGetType(xevent
) == ButtonRelease
)
1522 if (XButtonEventLChanged(xevent
))
1524 eventType
= wxEVT_LEFT_UP
;
1526 else if (XButtonEventMChanged(xevent
))
1528 eventType
= wxEVT_MIDDLE_UP
;
1530 else if (XButtonEventRChanged(xevent
))
1532 eventType
= wxEVT_RIGHT_UP
;
1541 wxevent
.SetEventType(eventType
);
1543 wxevent
.m_x
= XButtonEventGetX(xevent
);
1544 wxevent
.m_y
= XButtonEventGetY(xevent
);
1546 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1547 || (XButtonEventLIsDown(xevent
)
1548 && (eventType
!= wxEVT_LEFT_UP
)));
1549 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1550 || (XButtonEventMIsDown(xevent
)
1551 && (eventType
!= wxEVT_MIDDLE_UP
)));
1552 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1553 || (XButtonEventRIsDown (xevent
)
1554 && (eventType
!= wxEVT_RIGHT_UP
)));
1556 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1557 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1558 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1559 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1561 wxevent
.SetId(win
->GetId());
1562 wxevent
.SetEventObject(win
);
1570 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1572 switch (XEventGetType(xevent
))
1580 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1581 int id
= wxCharCodeXToWX (keySym
);
1582 // id may be WXK_xxx code - these are outside ASCII range, so we
1583 // can't just use toupper() on id.
1584 // Only change this if we want the raw key that was pressed,
1585 // and don't change it if we want an ASCII value.
1586 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1588 id
= id
+ 'A' - 'a';
1591 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1592 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1593 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1594 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1595 wxevent
.SetEventObject(win
);
1596 wxevent
.m_keyCode
= id
;
1597 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1599 wxevent
.m_x
= XKeyEventGetX(xevent
);
1600 wxevent
.m_y
= XKeyEventGetY(xevent
);
1610 // ----------------------------------------------------------------------------
1612 // ----------------------------------------------------------------------------
1614 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1616 wxWindowBase::SetBackgroundColour(col
);
1618 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1619 int xscreen
= DefaultScreen( xdisplay
);
1620 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1622 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1624 // We don't set the background colour as we paint
1625 // the background ourselves.
1626 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1631 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1633 if ( !wxWindowBase::SetForegroundColour(col
) )
1639 // ----------------------------------------------------------------------------
1641 // ----------------------------------------------------------------------------
1643 wxWindow
*wxGetActiveWindow()
1645 return wxGetTopLevelParent(wxWindow::FindFocus());
1649 wxWindow
*wxWindowBase::GetCapture()
1651 return (wxWindow
*)g_captureWindow
;
1655 // Find the wxWindow at the current mouse position, returning the mouse
1657 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1659 pt
= wxGetMousePosition();
1660 return wxFindWindowAtPoint(pt
);
1663 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
1670 Display
*display
= wxGlobalDisplay();
1671 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1672 Window rootReturn
, childReturn
;
1675 XQueryPointer (display
,
1679 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1683 // Get the current mouse position.
1684 wxPoint
wxGetMousePosition()
1689 wxGetMouseState(x
, y
, mask
);
1690 return wxPoint(x
, y
);
1693 wxMouseState
wxGetMouseState()
1699 wxGetMouseState(x
, y
, mask
);
1704 ms
.SetLeftDown(mask
& Button1Mask
);
1705 ms
.SetMiddleDown(mask
& Button2Mask
);
1706 ms
.SetRightDown(mask
& Button3Mask
);
1708 ms
.SetControlDown(mask
& ControlMask
);
1709 ms
.SetShiftDown(mask
& ShiftMask
);
1710 ms
.SetAltDown(mask
& Mod3Mask
);
1711 ms
.SetMetaDown(mask
& Mod1Mask
);
1717 // ----------------------------------------------------------------------------
1718 // wxNoOptimize: switch off size optimization
1719 // ----------------------------------------------------------------------------
1721 int wxNoOptimize::ms_count
= 0;
1724 // ----------------------------------------------------------------------------
1726 // ----------------------------------------------------------------------------
1728 class wxWinModule
: public wxModule
1733 // we must be cleaned up before the display is closed
1734 AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule")));
1737 virtual bool OnInit();
1738 virtual void OnExit();
1741 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1744 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1746 bool wxWinModule::OnInit()
1748 Display
*xdisplay
= wxGlobalDisplay();
1749 int xscreen
= DefaultScreen( xdisplay
);
1750 Window xroot
= RootWindow( xdisplay
, xscreen
);
1751 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1752 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1757 void wxWinModule::OnExit()
1759 Display
*xdisplay
= wxGlobalDisplay();
1760 XFreeGC( xdisplay
, g_eraseGC
);