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"
52 #include "wx/fontutil.h"
53 #include "wx/univ/renderer.h"
55 #if wxUSE_DRAG_AND_DROP
59 #include "wx/unix/utilsx11.h"
61 #include "wx/x11/private.h"
62 #include "X11/Xutil.h"
66 // ----------------------------------------------------------------------------
67 // global variables for this module
68 // ----------------------------------------------------------------------------
70 static wxWindow
* g_captureWindow
= NULL
;
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
78 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
79 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
87 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
88 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
91 // ============================================================================
93 // ============================================================================
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 void wxWindowX11::Init()
106 m_mainWindow
= (WXWindow
) 0;
107 m_clientWindow
= (WXWindow
) 0;
108 m_insertIntoMain
= false;
109 m_updateNcArea
= false;
111 m_winCaptured
= false;
112 m_needsInputFocus
= false;
118 // real construction (Init() must have been called before!)
119 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
123 const wxString
& name
)
125 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
127 // Get default border
128 wxBorder border
= GetBorder(style
);
129 style
&= ~wxBORDER_MASK
;
132 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
134 parent
->AddChild(this);
136 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
137 int xscreen
= DefaultScreen( xdisplay
);
138 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
139 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
141 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
142 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
144 m_foregroundColour
= *wxBLACK
;
145 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
147 Window xparent
= (Window
) parent
->GetClientAreaWindow();
149 // Add window's own scrollbars to main window, not to client window
150 if (parent
->GetInsertIntoMain())
152 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
153 xparent
= (Window
) parent
->X11GetMainWindow();
156 // Size (not including the border) must be nonzero (or a Value error results)!
157 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
165 if (pos2
.x
== wxDefaultCoord
)
167 if (pos2
.y
== wxDefaultCoord
)
170 AdjustForParentClientOrigin(pos2
.x
, pos2
.y
);
172 #if wxUSE_TWO_WINDOWS
173 bool need_two_windows
=
174 ((( wxSUNKEN_BORDER
| wxBORDER_THEME
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
176 bool need_two_windows
= false;
180 long xattributes
= 0;
182 XSetWindowAttributes xattributes
;
183 long xattributes_mask
= 0;
185 xattributes_mask
|= CWBackPixel
;
186 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
188 xattributes_mask
|= CWBorderPixel
;
189 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
191 xattributes_mask
|= CWEventMask
;
194 if (need_two_windows
)
197 long backColor
, foreColor
;
198 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
199 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
201 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
202 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
203 XSelectInput( xdisplay
, xwindow
,
204 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
205 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
206 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
207 PropertyChangeMask
);
211 xattributes
.event_mask
=
212 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
214 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
215 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
219 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
221 m_mainWindow
= (WXWindow
) xwindow
;
222 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
224 XMapWindow( xdisplay
, xwindow
);
227 xattributes
.event_mask
=
228 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
229 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
230 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
231 PropertyChangeMask
| VisibilityChangeMask
;
233 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
235 xattributes_mask
|= CWBitGravity
;
236 xattributes
.bit_gravity
= StaticGravity
;
240 if (HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxRAISED_BORDER
) || HasFlag(wxBORDER_THEME
))
247 else if (HasFlag( wxSIMPLE_BORDER
))
260 // Make again sure the size is nonzero.
267 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
268 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
270 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
271 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
272 XSelectInput( xdisplay
, xwindow
,
273 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
274 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
275 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
276 PropertyChangeMask
);
279 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
280 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
283 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
285 m_clientWindow
= (WXWindow
) xwindow
;
286 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
288 XMapWindow( xdisplay
, xwindow
);
292 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
294 long backColor
, foreColor
;
295 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
296 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
298 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
299 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
300 XSelectInput( xdisplay
, xwindow
,
301 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
302 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
303 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
304 PropertyChangeMask
);
307 xattributes
.event_mask
=
308 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
309 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
310 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
311 PropertyChangeMask
| VisibilityChangeMask
;
313 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
315 xattributes_mask
|= CWBitGravity
;
316 xattributes
.bit_gravity
= NorthWestGravity
;
319 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
320 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
323 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
325 m_mainWindow
= (WXWindow
) xwindow
;
326 m_clientWindow
= m_mainWindow
;
327 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
329 XMapWindow( xdisplay
, xwindow
);
332 // Is a subwindow, so map immediately
335 // Without this, the cursor may not be restored properly (e.g. in splitter
337 SetCursor(*wxSTANDARD_CURSOR
);
338 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
340 // Don't call this, it can have nasty repercussions for composite controls,
342 // SetSize(pos.x, pos.y, size.x, size.y);
348 wxWindowX11::~wxWindowX11()
352 if (g_captureWindow
== this)
353 g_captureWindow
= NULL
;
357 if (m_clientWindow
!= m_mainWindow
)
359 // Destroy the cleint window
360 Window xwindow
= (Window
) m_clientWindow
;
361 wxDeleteClientWindowFromTable( xwindow
);
362 XDestroyWindow( wxGlobalDisplay(), xwindow
);
363 m_clientWindow
= NULL
;
366 // Destroy the window
369 Window xwindow
= (Window
) m_mainWindow
;
370 wxDeleteWindowFromTable( xwindow
);
371 XDestroyWindow( wxGlobalDisplay(), xwindow
);
376 // ---------------------------------------------------------------------------
378 // ---------------------------------------------------------------------------
380 void wxWindowX11::SetFocus()
382 Window xwindow
= (Window
) m_clientWindow
;
384 wxCHECK_RET( xwindow
, wxT("invalid window") );
386 // Don't assert; we might be trying to set the focus for a panel
387 // with only static controls, so the panel returns false from AcceptsFocus.
388 // The app should be not be expected to deal with this.
393 if (GetName() == "scrollBar")
400 XWindowAttributes wa
;
401 XGetWindowAttributes(wxGlobalDisplay(), xwindow
, &wa
);
403 if (wa
.map_state
== IsViewable
)
405 wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
406 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
407 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
408 m_needsInputFocus
= false;
412 m_needsInputFocus
= true;
416 // Get the window with the focus
417 wxWindow
*wxWindowBase::DoFindFocus()
419 Window xfocus
= (Window
) 0;
422 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
425 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
428 win
= wxGetClientWindowFromTable( xfocus
);
437 // Enabling/disabling handled by event loop, and not sending events
439 bool wxWindowX11::Enable(bool enable
)
441 if ( !wxWindowBase::Enable(enable
) )
447 bool wxWindowX11::Show(bool show
)
449 wxWindowBase::Show(show
);
451 Window xwindow
= (Window
) m_mainWindow
;
452 Display
*xdisp
= wxGlobalDisplay();
455 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
456 XMapWindow(xdisp
, xwindow
);
460 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
461 XUnmapWindow(xdisp
, xwindow
);
467 // Raise the window to the top of the Z order
468 void wxWindowX11::Raise()
471 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
474 // Lower the window to the bottom of the Z order
475 void wxWindowX11::Lower()
478 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
481 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
486 wxString
wxWindowX11::GetLabel() const
489 return wxEmptyString
;
492 void wxWindowX11::DoCaptureMouse()
494 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
496 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
507 Window xwindow
= (Window
) m_clientWindow
;
509 wxCHECK_RET( xwindow
, wxT("invalid window") );
511 g_captureWindow
= (wxWindow
*) this;
515 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
517 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
521 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
524 if (res
!= GrabSuccess
)
527 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
529 if (res
== GrabNotViewable
)
531 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
534 g_captureWindow
= NULL
;
538 m_winCaptured
= true;
542 void wxWindowX11::DoReleaseMouse()
544 g_captureWindow
= NULL
;
546 if ( !m_winCaptured
)
549 Window xwindow
= (Window
) m_clientWindow
;
553 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
556 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
558 m_winCaptured
= false;
561 bool wxWindowX11::SetFont(const wxFont
& font
)
563 if ( !wxWindowBase::SetFont(font
) )
572 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
574 if ( !wxWindowBase::SetCursor(cursor
) )
580 Window xwindow
= (Window
) m_clientWindow
;
582 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
584 wxCursor cursorToUse
;
586 cursorToUse
= m_cursor
;
588 cursorToUse
= *wxSTANDARD_CURSOR
;
590 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
592 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
597 // Coordinates relative to the window
598 void wxWindowX11::WarpPointer (int x
, int y
)
600 Window xwindow
= (Window
) m_clientWindow
;
602 wxCHECK_RET( xwindow
, wxT("invalid window") );
604 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
607 // Does a physical scroll
608 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
610 // No scrolling requested.
611 if ((dx
== 0) && (dy
== 0)) return;
613 if (!m_updateRegion
.IsEmpty())
615 m_updateRegion
.Offset( dx
, dy
);
619 GetSize( &cw
, &ch
); // GetClientSize() ??
620 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
623 if (!m_clearRegion
.IsEmpty())
625 m_clearRegion
.Offset( dx
, dy
);
629 GetSize( &cw
, &ch
); // GetClientSize() ??
630 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
633 Window xwindow
= (Window
) GetClientAreaWindow();
635 wxCHECK_RET( xwindow
, wxT("invalid window") );
637 Display
*xdisplay
= wxGlobalDisplay();
639 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
640 XSetGraphicsExposures( xdisplay
, xgc
, True
);
658 GetClientSize( &cw
, &ch
);
661 #if wxUSE_TWO_WINDOWS
662 wxPoint
offset( 0,0 );
664 wxPoint offset
= GetClientAreaOrigin();
669 int w
= cw
- abs(dx
);
670 int h
= ch
- abs(dy
);
672 if ((h
< 0) || (w
< 0))
679 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
680 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
681 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
682 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
687 if (dx
< 0) s_x
+= -dx
;
688 if (dy
< 0) s_y
+= -dy
;
689 if (dx
> 0) d_x
+= dx
+ offset
.x
;
690 if (dy
> 0) d_y
+= dy
+ offset
.y
;
692 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
694 // 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 );
696 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
698 m_updateRegion
.Union( rect
);
699 m_clearRegion
.Union( rect
);
702 XFreeGC( xdisplay
, xgc
);
704 // Move Clients, but not the scrollbars
705 // FIXME: There may be a better method to move a lot of Windows within X11
706 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
707 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
708 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
711 // Only propagate to non-top-level windows
712 wxWindow
*win
= node
->GetData();
713 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
715 wxPoint pos
= win
->GetPosition();
716 // Add the delta to the old Position
719 win
->SetPosition(pos
);
721 node
= node
->GetNext();
725 // ---------------------------------------------------------------------------
727 // ---------------------------------------------------------------------------
729 #if wxUSE_DRAG_AND_DROP
731 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
738 // Old style file-manager drag&drop
739 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
744 // ----------------------------------------------------------------------------
746 // ----------------------------------------------------------------------------
750 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
755 #endif // wxUSE_TOOLTIPS
757 // ---------------------------------------------------------------------------
758 // moving and resizing
759 // ---------------------------------------------------------------------------
761 bool wxWindowX11::PreResize()
767 void wxWindowX11::DoGetSize(int *x
, int *y
) const
769 Window xwindow
= (Window
) m_mainWindow
;
771 wxCHECK_RET( xwindow
, wxT("invalid window") );
773 //XSync(wxGlobalDisplay(), False);
775 XWindowAttributes attr
;
776 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
781 *x
= attr
.width
/* + 2*m_borderSize */ ;
782 *y
= attr
.height
/* + 2*m_borderSize */ ;
786 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
788 Window window
= (Window
) m_mainWindow
;
791 //XSync(wxGlobalDisplay(), False);
792 XWindowAttributes attr
;
793 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
801 // We may be faking the client origin. So a window that's really at (0, 30)
802 // may appear (to wxWin apps) to be at (0, 0).
805 wxPoint
pt(GetParent()->GetClientAreaOrigin());
813 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
815 Display
*display
= wxGlobalDisplay();
816 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
817 Window thisWindow
= (Window
) m_clientWindow
;
822 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
823 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
827 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
829 Display
*display
= wxGlobalDisplay();
830 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
831 Window thisWindow
= (Window
) m_clientWindow
;
836 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
837 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
842 // Get size *available for subwindows* i.e. excluding menu bar etc.
843 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
845 Window window
= (Window
) m_mainWindow
;
849 XWindowAttributes attr
;
850 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
861 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
863 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
865 Window xwindow
= (Window
) m_mainWindow
;
867 wxCHECK_RET( xwindow
, wxT("invalid window") );
869 XWindowAttributes attr
;
870 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
871 wxCHECK_RET( status
, wxT("invalid window attributes") );
875 int new_w
= attr
.width
;
876 int new_h
= attr
.height
;
878 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
881 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
884 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
887 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
890 if (width
!= wxDefaultCoord
)
896 if (height
!= wxDefaultCoord
)
903 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
906 void wxWindowX11::DoSetClientSize(int width
, int height
)
908 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
910 Window xwindow
= (Window
) m_mainWindow
;
912 wxCHECK_RET( xwindow
, wxT("invalid window") );
914 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
916 if (m_mainWindow
!= m_clientWindow
)
918 xwindow
= (Window
) m_clientWindow
;
920 wxWindow
*window
= (wxWindow
*) this;
921 wxRenderer
*renderer
= window
->GetRenderer();
924 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
925 width
-= border
.x
+ border
.width
;
926 height
-= border
.y
+ border
.height
;
929 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
933 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
935 Window xwindow
= (Window
) m_mainWindow
;
937 wxCHECK_RET( xwindow
, wxT("invalid window") );
941 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
942 if (m_mainWindow
!= m_clientWindow
)
944 xwindow
= (Window
) m_clientWindow
;
946 wxWindow
*window
= (wxWindow
*) this;
947 wxRenderer
*renderer
= window
->GetRenderer();
950 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
953 width
-= border
.x
+ border
.width
;
954 height
-= border
.y
+ border
.height
;
962 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
963 if (sb
&& sb
->IsShown())
965 wxSize size
= sb
->GetSize();
968 sb
= window
->GetScrollbar( wxVERTICAL
);
969 if (sb
&& sb
->IsShown())
971 wxSize size
= sb
->GetSize();
975 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
980 XWindowChanges windowChanges
;
983 windowChanges
.width
= width
;
984 windowChanges
.height
= height
;
985 windowChanges
.stack_mode
= 0;
986 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
988 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
993 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1001 XSizeHints sizeHints
;
1002 sizeHints
.flags
= 0;
1004 if (minW
> -1 && minH
> -1)
1006 sizeHints
.flags
|= PMinSize
;
1007 sizeHints
.min_width
= minW
;
1008 sizeHints
.min_height
= minH
;
1010 if (maxW
> -1 && maxH
> -1)
1012 sizeHints
.flags
|= PMaxSize
;
1013 sizeHints
.max_width
= maxW
;
1014 sizeHints
.max_height
= maxH
;
1016 if (incW
> -1 && incH
> -1)
1018 sizeHints
.flags
|= PResizeInc
;
1019 sizeHints
.width_inc
= incW
;
1020 sizeHints
.height_inc
= incH
;
1023 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1027 // ---------------------------------------------------------------------------
1029 // ---------------------------------------------------------------------------
1031 int wxWindowX11::GetCharHeight() const
1033 wxFont
font(GetFont());
1034 wxCHECK_MSG( font
.IsOk(), 0, wxT("valid window font needed") );
1037 // There should be an easier way.
1038 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1039 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1040 pango_layout_set_text(layout
, "H", 1 );
1042 pango_layout_get_pixel_size(layout
, &w
, &h
);
1043 g_object_unref( G_OBJECT( layout
) );
1047 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1049 int direction
, ascent
, descent
;
1050 XCharStruct overall
;
1051 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1052 &descent
, &overall
);
1054 // return (overall.ascent + overall.descent);
1055 return (ascent
+ descent
);
1059 int wxWindowX11::GetCharWidth() const
1061 wxFont
font(GetFont());
1062 wxCHECK_MSG( font
.IsOk(), 0, wxT("valid window font needed") );
1065 // There should be an easier way.
1066 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1067 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1068 pango_layout_set_text(layout
, "H", 1 );
1070 pango_layout_get_pixel_size(layout
, &w
, &h
);
1071 g_object_unref( G_OBJECT( layout
) );
1075 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1077 int direction
, ascent
, descent
;
1078 XCharStruct overall
;
1079 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1080 &descent
, &overall
);
1082 return overall
.width
;
1086 void wxWindowX11::DoGetTextExtent(const wxString
& string
,
1089 int *externalLeading
,
1090 const wxFont
*theFont
) const
1092 wxFont fontToUse
= GetFont();
1093 if (theFont
) fontToUse
= *theFont
;
1095 wxCHECK_RET( fontToUse
.IsOk(), wxT("invalid font") );
1105 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1107 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1108 pango_layout_set_font_description(layout
, desc
);
1110 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
.wc_str() );
1111 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1113 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1116 PangoRectangle rect
;
1117 pango_layout_line_get_extents(line
, NULL
, &rect
);
1119 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1120 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1123 // Do something about metrics here
1126 if (externalLeading
) (*externalLeading
) = 0; // ??
1128 g_object_unref( G_OBJECT( layout
) );
1130 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1132 int direction
, ascent
, descent2
;
1133 XCharStruct overall
;
1134 int slen
= string
.length();
1136 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1137 &direction
, &ascent
, &descent2
, &overall
);
1140 *x
= (overall
.width
);
1142 *y
= (ascent
+ descent2
);
1144 *descent
= descent2
;
1145 if (externalLeading
)
1146 *externalLeading
= 0;
1150 // ----------------------------------------------------------------------------
1152 // ----------------------------------------------------------------------------
1154 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1160 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1161 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1166 GetSize( &width
, &height
);
1168 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1169 m_clearRegion
.Clear();
1170 m_clearRegion
.Union( 0, 0, width
, height
);
1176 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1177 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1182 GetSize( &width
, &height
);
1184 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1185 m_updateRegion
.Clear();
1186 m_updateRegion
.Union( 0, 0, width
, height
);
1190 void wxWindowX11::Update()
1194 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1195 // Send nc paint events.
1196 SendNcPaintEvents();
1199 if (!m_updateRegion
.IsEmpty())
1201 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1202 // Actually send erase events.
1205 // Actually send paint events.
1210 void wxWindowX11::SendEraseEvents()
1212 if (m_clearRegion
.IsEmpty()) return;
1214 wxClientDC
dc( (wxWindow
*)this );
1215 dc
.SetDeviceClippingRegion( m_clearRegion
);
1217 wxEraseEvent
erase_event( GetId(), &dc
);
1218 erase_event
.SetEventObject( this );
1220 if (!HandleWindowEvent(erase_event
) )
1222 Display
*xdisplay
= wxGlobalDisplay();
1223 Window xwindow
= (Window
) GetClientAreaWindow();
1224 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1226 wxRegionIterator
upd( m_clearRegion
);
1229 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1230 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1235 m_clearRegion
.Clear();
1238 void wxWindowX11::SendPaintEvents()
1240 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1242 m_clipPaintRegion
= true;
1244 wxPaintEvent
paint_event( GetId() );
1245 paint_event
.SetEventObject( this );
1246 HandleWindowEvent( paint_event
);
1248 m_updateRegion
.Clear();
1250 m_clipPaintRegion
= false;
1253 void wxWindowX11::SendNcPaintEvents()
1255 wxWindow
*window
= (wxWindow
*) this;
1257 // All this for drawing the small square between the scrollbars.
1262 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1263 if (sb
&& sb
->IsShown())
1265 height
= sb
->GetSize().y
;
1266 y
= sb
->GetPosition().y
;
1268 sb
= window
->GetScrollbar( wxVERTICAL
);
1269 if (sb
&& sb
->IsShown())
1271 width
= sb
->GetSize().x
;
1272 x
= sb
->GetPosition().x
;
1274 Display
*xdisplay
= wxGlobalDisplay();
1275 Window xwindow
= (Window
) X11GetMainWindow();
1276 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1277 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1278 colour
.CalcPixel( (WXColormap
) cm
);
1280 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1282 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1286 wxNcPaintEvent
nc_paint_event( GetId() );
1287 nc_paint_event
.SetEventObject( this );
1288 HandleWindowEvent( nc_paint_event
);
1290 m_updateNcArea
= false;
1293 // ----------------------------------------------------------------------------
1295 // ----------------------------------------------------------------------------
1297 // Responds to colour changes: passes event on to children.
1298 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1300 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1303 // Only propagate to non-top-level windows
1304 wxWindow
*win
= node
->GetData();
1305 if ( win
->GetParent() )
1307 wxSysColourChangedEvent event2
;
1308 event
.SetEventObject(win
);
1309 win
->HandleWindowEvent(event2
);
1312 node
= node
->GetNext();
1316 // See handler for InFocus case in app.cpp for details.
1317 wxWindow
* g_GettingFocus
= NULL
;
1319 void wxWindowX11::OnInternalIdle()
1321 // Update invalidated regions.
1324 wxWindowBase::OnInternalIdle();
1326 // Set the input focus if couldn't do it before
1327 if (m_needsInputFocus
)
1331 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1332 printf(msg
.c_str());
1336 // If it couldn't set the focus now, there's
1337 // no point in trying again.
1338 m_needsInputFocus
= false;
1340 g_GettingFocus
= NULL
;
1343 // ----------------------------------------------------------------------------
1344 // function which maintain the global hash table mapping Widgets to wxWidgets
1345 // ----------------------------------------------------------------------------
1347 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1349 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1351 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1352 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1356 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1357 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1362 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1364 wxWindowHash::iterator i
= hash
->find(w
);
1365 return i
== hash
->end() ? NULL
: i
->second
;
1368 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1370 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1375 // ----------------------------------------------------------------------------
1377 // ----------------------------------------------------------------------------
1379 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1381 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1384 wxWindow
*wxGetWindowFromTable(Window w
)
1386 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1389 void wxDeleteWindowFromTable(Window w
)
1391 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1394 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1396 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1399 wxWindow
*wxGetClientWindowFromTable(Window w
)
1401 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1404 void wxDeleteClientWindowFromTable(Window w
)
1406 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1409 // ----------------------------------------------------------------------------
1410 // X11-specific accessors
1411 // ----------------------------------------------------------------------------
1413 WXWindow
wxWindowX11::X11GetMainWindow() const
1415 return m_mainWindow
;
1418 WXWindow
wxWindowX11::GetClientAreaWindow() const
1420 return m_clientWindow
;
1423 // ----------------------------------------------------------------------------
1424 // TranslateXXXEvent() functions
1425 // ----------------------------------------------------------------------------
1427 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
,
1429 Window
WXUNUSED(window
),
1432 switch (XEventGetType(xevent
))
1440 wxEventType eventType
= wxEVT_NULL
;
1442 if (XEventGetType(xevent
) == EnterNotify
)
1444 //if (local_event.xcrossing.mode!=NotifyNormal)
1445 // return ; // Ignore grab events
1446 eventType
= wxEVT_ENTER_WINDOW
;
1447 // canvas->GetEventHandler()->OnSetFocus();
1449 else if (XEventGetType(xevent
) == LeaveNotify
)
1451 //if (local_event.xcrossingr.mode!=NotifyNormal)
1452 // return ; // Ignore grab events
1453 eventType
= wxEVT_LEAVE_WINDOW
;
1454 // canvas->GetEventHandler()->OnKillFocus();
1456 else if (XEventGetType(xevent
) == MotionNotify
)
1458 eventType
= wxEVT_MOTION
;
1460 else if (XEventGetType(xevent
) == ButtonPress
)
1462 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1464 if (XButtonEventLChanged(xevent
))
1466 eventType
= wxEVT_LEFT_DOWN
;
1469 else if (XButtonEventMChanged(xevent
))
1471 eventType
= wxEVT_MIDDLE_DOWN
;
1474 else if (XButtonEventRChanged(xevent
))
1476 eventType
= wxEVT_RIGHT_DOWN
;
1479 else if ( xevent
->xbutton
.button
== Button4
||
1480 xevent
->xbutton
.button
== Button5
)
1482 // this is the same value as used under wxMSW
1483 static const int WHEEL_DELTA
= 120;
1485 eventType
= wxEVT_MOUSEWHEEL
;
1486 button
= xevent
->xbutton
.button
;
1488 wxevent
.m_linesPerAction
= 3;
1489 wxevent
.m_wheelDelta
= WHEEL_DELTA
;
1491 // Button 4 means mousewheel up, 5 means down
1492 wxevent
.m_wheelRotation
= button
== Button4
? WHEEL_DELTA
1496 // check for a double click
1497 // TODO: where can we get this value from?
1498 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1499 long dclickTime
= 200;
1500 long ts
= wxevent
.GetTimestamp();
1502 int buttonLast
= win
->GetLastClickedButton();
1503 long lastTS
= win
->GetLastClickTime();
1504 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1507 win
->SetLastClick(0, ts
);
1508 if ( eventType
== wxEVT_LEFT_DOWN
)
1509 eventType
= wxEVT_LEFT_DCLICK
;
1510 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1511 eventType
= wxEVT_MIDDLE_DCLICK
;
1512 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1513 eventType
= wxEVT_RIGHT_DCLICK
;
1517 // not fast enough or different button
1518 win
->SetLastClick(button
, ts
);
1521 else if (XEventGetType(xevent
) == ButtonRelease
)
1523 if (XButtonEventLChanged(xevent
))
1525 eventType
= wxEVT_LEFT_UP
;
1527 else if (XButtonEventMChanged(xevent
))
1529 eventType
= wxEVT_MIDDLE_UP
;
1531 else if (XButtonEventRChanged(xevent
))
1533 eventType
= wxEVT_RIGHT_UP
;
1542 wxevent
.SetEventType(eventType
);
1544 wxevent
.m_x
= XButtonEventGetX(xevent
);
1545 wxevent
.m_y
= XButtonEventGetY(xevent
);
1547 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1548 || (XButtonEventLIsDown(xevent
)
1549 && (eventType
!= wxEVT_LEFT_UP
)));
1550 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1551 || (XButtonEventMIsDown(xevent
)
1552 && (eventType
!= wxEVT_MIDDLE_UP
)));
1553 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1554 || (XButtonEventRIsDown (xevent
)
1555 && (eventType
!= wxEVT_RIGHT_UP
)));
1557 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1558 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1559 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1560 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1562 wxevent
.SetId(win
->GetId());
1563 wxevent
.SetEventObject(win
);
1571 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1573 switch (XEventGetType(xevent
))
1581 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1582 int id
= wxCharCodeXToWX (keySym
);
1583 // id may be WXK_xxx code - these are outside ASCII range, so we
1584 // can't just use toupper() on id.
1585 // Only change this if we want the raw key that was pressed,
1586 // and don't change it if we want an ASCII value.
1587 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1589 id
= id
+ 'A' - 'a';
1592 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1593 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1594 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1595 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1596 wxevent
.SetEventObject(win
);
1597 wxevent
.m_keyCode
= id
;
1598 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1600 wxevent
.m_x
= XKeyEventGetX(xevent
);
1601 wxevent
.m_y
= XKeyEventGetY(xevent
);
1611 // ----------------------------------------------------------------------------
1613 // ----------------------------------------------------------------------------
1615 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1617 wxWindowBase::SetBackgroundColour(col
);
1619 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1620 int xscreen
= DefaultScreen( xdisplay
);
1621 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1623 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1625 // We don't set the background colour as we paint
1626 // the background ourselves.
1627 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1632 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1634 if ( !wxWindowBase::SetForegroundColour(col
) )
1640 // ----------------------------------------------------------------------------
1642 // ----------------------------------------------------------------------------
1644 wxWindow
*wxGetActiveWindow()
1646 return wxGetTopLevelParent(wxWindow::FindFocus());
1650 wxWindow
*wxWindowBase::GetCapture()
1652 return (wxWindow
*)g_captureWindow
;
1656 // Find the wxWindow at the current mouse position, returning the mouse
1658 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1660 pt
= wxGetMousePosition();
1661 return wxFindWindowAtPoint(pt
);
1664 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
1671 Display
*display
= wxGlobalDisplay();
1672 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1673 Window rootReturn
, childReturn
;
1676 XQueryPointer (display
,
1680 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1684 // Get the current mouse position.
1685 wxPoint
wxGetMousePosition()
1690 wxGetMouseState(x
, y
, mask
);
1691 return wxPoint(x
, y
);
1694 wxMouseState
wxGetMouseState()
1700 wxGetMouseState(x
, y
, mask
);
1705 ms
.SetLeftDown(mask
& Button1Mask
);
1706 ms
.SetMiddleDown(mask
& Button2Mask
);
1707 ms
.SetRightDown(mask
& Button3Mask
);
1709 ms
.SetControlDown(mask
& ControlMask
);
1710 ms
.SetShiftDown(mask
& ShiftMask
);
1711 ms
.SetAltDown(mask
& Mod3Mask
);
1712 ms
.SetMetaDown(mask
& Mod1Mask
);
1718 // ----------------------------------------------------------------------------
1719 // wxNoOptimize: switch off size optimization
1720 // ----------------------------------------------------------------------------
1722 int wxNoOptimize::ms_count
= 0;
1725 // ----------------------------------------------------------------------------
1727 // ----------------------------------------------------------------------------
1729 class wxWinModule
: public wxModule
1734 // we must be cleaned up before the display is closed
1735 AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule")));
1738 virtual bool OnInit();
1739 virtual void OnExit();
1742 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1745 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1747 bool wxWinModule::OnInit()
1749 Display
*xdisplay
= wxGlobalDisplay();
1752 // This module may be linked into a console program when using
1753 // monolithic library and in this case it's perfectly normal not to
1754 // have a display, so just return without doing anything and avoid
1759 int xscreen
= DefaultScreen( xdisplay
);
1760 Window xroot
= RootWindow( xdisplay
, xscreen
);
1761 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1762 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1767 void wxWinModule::OnExit()
1769 Display
*xdisplay
= wxGlobalDisplay();
1770 XFreeGC( xdisplay
, g_eraseGC
);