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/x11/private.h"
60 #include "X11/Xutil.h"
64 // ----------------------------------------------------------------------------
65 // global variables for this module
66 // ----------------------------------------------------------------------------
68 static wxWindow
* g_captureWindow
= NULL
;
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
76 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
77 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
85 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
86 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
89 // ============================================================================
91 // ============================================================================
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxWindowX11::Init()
104 m_mainWindow
= (WXWindow
) 0;
105 m_clientWindow
= (WXWindow
) 0;
106 m_insertIntoMain
= false;
107 m_updateNcArea
= false;
109 m_winCaptured
= false;
110 m_needsInputFocus
= false;
116 // real construction (Init() must have been called before!)
117 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
121 const wxString
& name
)
123 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
125 // Get default border
126 wxBorder border
= GetBorder(style
);
127 style
&= ~wxBORDER_MASK
;
130 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
132 parent
->AddChild(this);
134 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
135 int xscreen
= DefaultScreen( xdisplay
);
136 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
137 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
139 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
140 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
142 m_foregroundColour
= *wxBLACK
;
143 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
145 Window xparent
= (Window
) parent
->GetClientAreaWindow();
147 // Add window's own scrollbars to main window, not to client window
148 if (parent
->GetInsertIntoMain())
150 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
151 xparent
= (Window
) parent
->GetMainWindow();
154 // Size (not including the border) must be nonzero (or a Value error results)!
155 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
163 if (pos2
.x
== wxDefaultCoord
)
165 if (pos2
.y
== wxDefaultCoord
)
168 AdjustForParentClientOrigin(pos2
.x
, pos2
.y
);
170 #if wxUSE_TWO_WINDOWS
171 bool need_two_windows
=
172 ((( wxSUNKEN_BORDER
| wxBORDER_THEME
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
174 bool need_two_windows
= false;
178 long xattributes
= 0;
180 XSetWindowAttributes xattributes
;
181 long xattributes_mask
= 0;
183 xattributes_mask
|= CWBackPixel
;
184 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
186 xattributes_mask
|= CWBorderPixel
;
187 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
189 xattributes_mask
|= CWEventMask
;
192 if (need_two_windows
)
195 long backColor
, foreColor
;
196 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
197 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
199 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
200 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
201 XSelectInput( xdisplay
, xwindow
,
202 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
203 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
204 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
205 PropertyChangeMask
);
209 xattributes
.event_mask
=
210 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
212 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
213 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
217 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
219 m_mainWindow
= (WXWindow
) xwindow
;
220 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
222 XMapWindow( xdisplay
, xwindow
);
225 xattributes
.event_mask
=
226 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
227 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
228 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
229 PropertyChangeMask
| VisibilityChangeMask
;
231 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
233 xattributes_mask
|= CWBitGravity
;
234 xattributes
.bit_gravity
= StaticGravity
;
238 if (HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxRAISED_BORDER
) || HasFlag(wxBORDER_THEME
))
245 else if (HasFlag( wxSIMPLE_BORDER
))
258 // Make again sure the size is nonzero.
265 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
266 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
268 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
269 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
270 XSelectInput( xdisplay
, xwindow
,
271 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
272 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
273 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
274 PropertyChangeMask
);
277 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
278 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
281 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
283 m_clientWindow
= (WXWindow
) xwindow
;
284 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
286 XMapWindow( xdisplay
, xwindow
);
290 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
292 long backColor
, foreColor
;
293 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
294 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
296 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
297 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
298 XSelectInput( xdisplay
, xwindow
,
299 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
300 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
301 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
302 PropertyChangeMask
);
305 xattributes
.event_mask
=
306 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
307 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
308 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
309 PropertyChangeMask
| VisibilityChangeMask
;
311 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
313 xattributes_mask
|= CWBitGravity
;
314 xattributes
.bit_gravity
= NorthWestGravity
;
317 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
318 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
321 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
323 m_mainWindow
= (WXWindow
) xwindow
;
324 m_clientWindow
= m_mainWindow
;
325 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
327 XMapWindow( xdisplay
, xwindow
);
330 // Is a subwindow, so map immediately
333 // Without this, the cursor may not be restored properly (e.g. in splitter
335 SetCursor(*wxSTANDARD_CURSOR
);
336 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
338 // Don't call this, it can have nasty repercussions for composite controls,
340 // SetSize(pos.x, pos.y, size.x, size.y);
346 wxWindowX11::~wxWindowX11()
350 if (g_captureWindow
== this)
351 g_captureWindow
= NULL
;
353 m_isBeingDeleted
= true;
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 if (wxWindowIsVisible(xwindow
))
402 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
403 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
404 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
405 m_needsInputFocus
= false;
409 m_needsInputFocus
= true;
413 // Get the window with the focus
414 wxWindow
*wxWindowBase::DoFindFocus()
416 Window xfocus
= (Window
) 0;
419 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
422 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
425 win
= wxGetClientWindowFromTable( xfocus
);
434 // Enabling/disabling handled by event loop, and not sending events
436 bool wxWindowX11::Enable(bool enable
)
438 if ( !wxWindowBase::Enable(enable
) )
444 bool wxWindowX11::Show(bool show
)
446 wxWindowBase::Show(show
);
448 Window xwindow
= (Window
) m_mainWindow
;
449 Display
*xdisp
= wxGlobalDisplay();
452 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
453 XMapWindow(xdisp
, xwindow
);
457 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
458 XUnmapWindow(xdisp
, xwindow
);
464 // Raise the window to the top of the Z order
465 void wxWindowX11::Raise()
468 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
471 // Lower the window to the bottom of the Z order
472 void wxWindowX11::Lower()
475 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
478 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
483 wxString
wxWindowX11::GetLabel() const
486 return wxEmptyString
;
489 void wxWindowX11::DoCaptureMouse()
491 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
493 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
504 Window xwindow
= (Window
) m_clientWindow
;
506 wxCHECK_RET( xwindow
, wxT("invalid window") );
508 g_captureWindow
= (wxWindow
*) this;
512 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
514 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
518 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
521 if (res
!= GrabSuccess
)
524 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
526 if (res
== GrabNotViewable
)
527 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
529 g_captureWindow
= NULL
;
533 m_winCaptured
= true;
537 void wxWindowX11::DoReleaseMouse()
539 g_captureWindow
= NULL
;
541 if ( !m_winCaptured
)
544 Window xwindow
= (Window
) m_clientWindow
;
548 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
551 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
553 m_winCaptured
= false;
556 bool wxWindowX11::SetFont(const wxFont
& font
)
558 if ( !wxWindowBase::SetFont(font
) )
567 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
569 if ( !wxWindowBase::SetCursor(cursor
) )
575 Window xwindow
= (Window
) m_clientWindow
;
577 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
579 wxCursor cursorToUse
;
581 cursorToUse
= m_cursor
;
583 cursorToUse
= *wxSTANDARD_CURSOR
;
585 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
587 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
592 // Coordinates relative to the window
593 void wxWindowX11::WarpPointer (int x
, int y
)
595 Window xwindow
= (Window
) m_clientWindow
;
597 wxCHECK_RET( xwindow
, wxT("invalid window") );
599 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
602 // Does a physical scroll
603 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
605 // No scrolling requested.
606 if ((dx
== 0) && (dy
== 0)) return;
608 if (!m_updateRegion
.IsEmpty())
610 m_updateRegion
.Offset( dx
, dy
);
614 GetSize( &cw
, &ch
); // GetClientSize() ??
615 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
618 if (!m_clearRegion
.IsEmpty())
620 m_clearRegion
.Offset( dx
, dy
);
624 GetSize( &cw
, &ch
); // GetClientSize() ??
625 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
628 Window xwindow
= (Window
) GetClientAreaWindow();
630 wxCHECK_RET( xwindow
, wxT("invalid window") );
632 Display
*xdisplay
= wxGlobalDisplay();
634 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
635 XSetGraphicsExposures( xdisplay
, xgc
, True
);
653 GetClientSize( &cw
, &ch
);
656 #if wxUSE_TWO_WINDOWS
657 wxPoint
offset( 0,0 );
659 wxPoint offset
= GetClientAreaOrigin();
664 int w
= cw
- abs(dx
);
665 int h
= ch
- abs(dy
);
667 if ((h
< 0) || (w
< 0))
674 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
675 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
676 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
677 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
682 if (dx
< 0) s_x
+= -dx
;
683 if (dy
< 0) s_y
+= -dy
;
684 if (dx
> 0) d_x
+= dx
+ offset
.x
;
685 if (dy
> 0) d_y
+= dy
+ offset
.y
;
687 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
689 // 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 );
691 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
693 m_updateRegion
.Union( rect
);
694 m_clearRegion
.Union( rect
);
697 XFreeGC( xdisplay
, xgc
);
699 // Move Clients, but not the scrollbars
700 // FIXME: There may be a better method to move a lot of Windows within X11
701 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
702 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
703 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
706 // Only propagate to non-top-level windows
707 wxWindow
*win
= node
->GetData();
708 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
710 wxPoint pos
= win
->GetPosition();
711 // Add the delta to the old Position
714 win
->SetPosition(pos
);
716 node
= node
->GetNext();
720 // ---------------------------------------------------------------------------
722 // ---------------------------------------------------------------------------
724 #if wxUSE_DRAG_AND_DROP
726 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
733 // Old style file-manager drag&drop
734 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
739 // ----------------------------------------------------------------------------
741 // ----------------------------------------------------------------------------
745 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
750 #endif // wxUSE_TOOLTIPS
752 // ---------------------------------------------------------------------------
753 // moving and resizing
754 // ---------------------------------------------------------------------------
756 bool wxWindowX11::PreResize()
762 void wxWindowX11::DoGetSize(int *x
, int *y
) const
764 Window xwindow
= (Window
) m_mainWindow
;
766 wxCHECK_RET( xwindow
, wxT("invalid window") );
768 //XSync(wxGlobalDisplay(), False);
770 XWindowAttributes attr
;
771 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
776 *x
= attr
.width
/* + 2*m_borderSize */ ;
777 *y
= attr
.height
/* + 2*m_borderSize */ ;
781 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
783 Window window
= (Window
) m_mainWindow
;
786 //XSync(wxGlobalDisplay(), False);
787 XWindowAttributes attr
;
788 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
796 // We may be faking the client origin. So a window that's really at (0, 30)
797 // may appear (to wxWin apps) to be at (0, 0).
800 wxPoint
pt(GetParent()->GetClientAreaOrigin());
808 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
810 Display
*display
= wxGlobalDisplay();
811 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
812 Window thisWindow
= (Window
) m_clientWindow
;
817 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
818 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
822 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
824 Display
*display
= wxGlobalDisplay();
825 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
826 Window thisWindow
= (Window
) m_clientWindow
;
831 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
832 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
837 // Get size *available for subwindows* i.e. excluding menu bar etc.
838 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
840 Window window
= (Window
) m_mainWindow
;
844 XWindowAttributes attr
;
845 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
856 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
858 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
860 Window xwindow
= (Window
) m_mainWindow
;
862 wxCHECK_RET( xwindow
, wxT("invalid window") );
864 XWindowAttributes attr
;
865 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
866 wxCHECK_RET( status
, wxT("invalid window attributes") );
870 int new_w
= attr
.width
;
871 int new_h
= attr
.height
;
873 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
876 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
879 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
882 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
885 if (width
!= wxDefaultCoord
)
891 if (height
!= wxDefaultCoord
)
898 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
901 void wxWindowX11::DoSetClientSize(int width
, int height
)
903 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
905 Window xwindow
= (Window
) m_mainWindow
;
907 wxCHECK_RET( xwindow
, wxT("invalid window") );
909 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
911 if (m_mainWindow
!= m_clientWindow
)
913 xwindow
= (Window
) m_clientWindow
;
915 wxWindow
*window
= (wxWindow
*) this;
916 wxRenderer
*renderer
= window
->GetRenderer();
919 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
920 width
-= border
.x
+ border
.width
;
921 height
-= border
.y
+ border
.height
;
924 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
928 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
930 Window xwindow
= (Window
) m_mainWindow
;
932 wxCHECK_RET( xwindow
, wxT("invalid window") );
936 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
937 if (m_mainWindow
!= m_clientWindow
)
939 xwindow
= (Window
) m_clientWindow
;
941 wxWindow
*window
= (wxWindow
*) this;
942 wxRenderer
*renderer
= window
->GetRenderer();
945 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
948 width
-= border
.x
+ border
.width
;
949 height
-= border
.y
+ border
.height
;
957 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
958 if (sb
&& sb
->IsShown())
960 wxSize size
= sb
->GetSize();
963 sb
= window
->GetScrollbar( wxVERTICAL
);
964 if (sb
&& sb
->IsShown())
966 wxSize size
= sb
->GetSize();
970 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
975 XWindowChanges windowChanges
;
978 windowChanges
.width
= width
;
979 windowChanges
.height
= height
;
980 windowChanges
.stack_mode
= 0;
981 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
983 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
988 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
996 XSizeHints sizeHints
;
999 if (minW
> -1 && minH
> -1)
1001 sizeHints
.flags
|= PMinSize
;
1002 sizeHints
.min_width
= minW
;
1003 sizeHints
.min_height
= minH
;
1005 if (maxW
> -1 && maxH
> -1)
1007 sizeHints
.flags
|= PMaxSize
;
1008 sizeHints
.max_width
= maxW
;
1009 sizeHints
.max_height
= maxH
;
1011 if (incW
> -1 && incH
> -1)
1013 sizeHints
.flags
|= PResizeInc
;
1014 sizeHints
.width_inc
= incW
;
1015 sizeHints
.height_inc
= incH
;
1018 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1022 // ---------------------------------------------------------------------------
1024 // ---------------------------------------------------------------------------
1026 int wxWindowX11::GetCharHeight() const
1028 wxFont
font(GetFont());
1029 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1032 // There should be an easier way.
1033 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1034 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1035 pango_layout_set_text(layout
, "H", 1 );
1037 pango_layout_get_pixel_size(layout
, &w
, &h
);
1038 g_object_unref( G_OBJECT( layout
) );
1042 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1044 int direction
, ascent
, descent
;
1045 XCharStruct overall
;
1046 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1047 &descent
, &overall
);
1049 // return (overall.ascent + overall.descent);
1050 return (ascent
+ descent
);
1054 int wxWindowX11::GetCharWidth() const
1056 wxFont
font(GetFont());
1057 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1060 // There should be an easier way.
1061 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1062 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1063 pango_layout_set_text(layout
, "H", 1 );
1065 pango_layout_get_pixel_size(layout
, &w
, &h
);
1066 g_object_unref( G_OBJECT( layout
) );
1070 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1072 int direction
, ascent
, descent
;
1073 XCharStruct overall
;
1074 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1075 &descent
, &overall
);
1077 return overall
.width
;
1081 void wxWindowX11::GetTextExtent(const wxString
& string
,
1083 int *descent
, int *externalLeading
,
1084 const wxFont
*theFont
) const
1086 wxFont fontToUse
= GetFont();
1087 if (theFont
) fontToUse
= *theFont
;
1089 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1099 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1101 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1102 pango_layout_set_font_description(layout
, desc
);
1104 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1105 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1107 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1110 PangoRectangle rect
;
1111 pango_layout_line_get_extents(line
, NULL
, &rect
);
1113 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1114 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1117 // Do something about metrics here
1120 if (externalLeading
) (*externalLeading
) = 0; // ??
1122 g_object_unref( G_OBJECT( layout
) );
1124 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1126 int direction
, ascent
, descent2
;
1127 XCharStruct overall
;
1128 int slen
= string
.length();
1130 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1131 &direction
, &ascent
, &descent2
, &overall
);
1134 *x
= (overall
.width
);
1136 *y
= (ascent
+ descent2
);
1138 *descent
= descent2
;
1139 if (externalLeading
)
1140 *externalLeading
= 0;
1144 // ----------------------------------------------------------------------------
1146 // ----------------------------------------------------------------------------
1148 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1154 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1155 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1160 GetSize( &width
, &height
);
1162 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1163 m_clearRegion
.Clear();
1164 m_clearRegion
.Union( 0, 0, width
, height
);
1170 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1171 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1176 GetSize( &width
, &height
);
1178 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1179 m_updateRegion
.Clear();
1180 m_updateRegion
.Union( 0, 0, width
, height
);
1184 void wxWindowX11::Update()
1188 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1189 // Send nc paint events.
1190 SendNcPaintEvents();
1193 if (!m_updateRegion
.IsEmpty())
1195 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1196 // Actually send erase events.
1199 // Actually send paint events.
1204 void wxWindowX11::SendEraseEvents()
1206 if (m_clearRegion
.IsEmpty()) return;
1208 wxClientDC
dc( (wxWindow
*)this );
1209 dc
.SetDeviceClippingRegion( m_clearRegion
);
1211 wxEraseEvent
erase_event( GetId(), &dc
);
1212 erase_event
.SetEventObject( this );
1214 if (!HandleWindowEvent(erase_event
) )
1216 Display
*xdisplay
= wxGlobalDisplay();
1217 Window xwindow
= (Window
) GetClientAreaWindow();
1218 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1220 wxRegionIterator
upd( m_clearRegion
);
1223 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1224 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1229 m_clearRegion
.Clear();
1232 void wxWindowX11::SendPaintEvents()
1234 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1236 m_clipPaintRegion
= true;
1238 wxPaintEvent
paint_event( GetId() );
1239 paint_event
.SetEventObject( this );
1240 HandleWindowEvent( paint_event
);
1242 m_updateRegion
.Clear();
1244 m_clipPaintRegion
= false;
1247 void wxWindowX11::SendNcPaintEvents()
1249 wxWindow
*window
= (wxWindow
*) this;
1251 // All this for drawing the small square between the scrollbars.
1256 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1257 if (sb
&& sb
->IsShown())
1259 height
= sb
->GetSize().y
;
1260 y
= sb
->GetPosition().y
;
1262 sb
= window
->GetScrollbar( wxVERTICAL
);
1263 if (sb
&& sb
->IsShown())
1265 width
= sb
->GetSize().x
;
1266 x
= sb
->GetPosition().x
;
1268 Display
*xdisplay
= wxGlobalDisplay();
1269 Window xwindow
= (Window
) GetMainWindow();
1270 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1271 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1272 colour
.CalcPixel( (WXColormap
) cm
);
1274 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1276 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1280 wxNcPaintEvent
nc_paint_event( GetId() );
1281 nc_paint_event
.SetEventObject( this );
1282 HandleWindowEvent( nc_paint_event
);
1284 m_updateNcArea
= false;
1287 // ----------------------------------------------------------------------------
1289 // ----------------------------------------------------------------------------
1291 // Responds to colour changes: passes event on to children.
1292 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1294 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1297 // Only propagate to non-top-level windows
1298 wxWindow
*win
= node
->GetData();
1299 if ( win
->GetParent() )
1301 wxSysColourChangedEvent event2
;
1302 event
.SetEventObject(win
);
1303 win
->HandleWindowEvent(event2
);
1306 node
= node
->GetNext();
1310 // See handler for InFocus case in app.cpp for details.
1311 wxWindow
* g_GettingFocus
= NULL
;
1313 void wxWindowX11::OnInternalIdle()
1315 // Update invalidated regions.
1318 // This calls the UI-update mechanism (querying windows for
1319 // menu/toolbar/control state information)
1320 if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this) && IsShownOnScreen())
1321 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1323 // Set the input focus if couldn't do it before
1324 if (m_needsInputFocus
)
1328 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1329 printf(msg
.c_str());
1333 // If it couldn't set the focus now, there's
1334 // no point in trying again.
1335 m_needsInputFocus
= false;
1337 g_GettingFocus
= NULL
;
1340 // ----------------------------------------------------------------------------
1341 // function which maintain the global hash table mapping Widgets to wxWidgets
1342 // ----------------------------------------------------------------------------
1344 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1346 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1348 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1349 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1353 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1354 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1359 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1361 wxWindowHash::iterator i
= hash
->find(w
);
1362 return i
== hash
->end() ? NULL
: i
->second
;
1365 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1367 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1372 // ----------------------------------------------------------------------------
1374 // ----------------------------------------------------------------------------
1376 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1378 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1381 wxWindow
*wxGetWindowFromTable(Window w
)
1383 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1386 void wxDeleteWindowFromTable(Window w
)
1388 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1391 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1393 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1396 wxWindow
*wxGetClientWindowFromTable(Window w
)
1398 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1401 void wxDeleteClientWindowFromTable(Window w
)
1403 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1406 // ----------------------------------------------------------------------------
1407 // X11-specific accessors
1408 // ----------------------------------------------------------------------------
1410 WXWindow
wxWindowX11::GetMainWindow() const
1412 return m_mainWindow
;
1415 WXWindow
wxWindowX11::GetClientAreaWindow() const
1417 return m_clientWindow
;
1420 // ----------------------------------------------------------------------------
1421 // TranslateXXXEvent() functions
1422 // ----------------------------------------------------------------------------
1424 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
,
1426 Window
WXUNUSED(window
),
1429 switch (XEventGetType(xevent
))
1437 wxEventType eventType
= wxEVT_NULL
;
1439 if (XEventGetType(xevent
) == EnterNotify
)
1441 //if (local_event.xcrossing.mode!=NotifyNormal)
1442 // return ; // Ignore grab events
1443 eventType
= wxEVT_ENTER_WINDOW
;
1444 // canvas->GetEventHandler()->OnSetFocus();
1446 else if (XEventGetType(xevent
) == LeaveNotify
)
1448 //if (local_event.xcrossingr.mode!=NotifyNormal)
1449 // return ; // Ignore grab events
1450 eventType
= wxEVT_LEAVE_WINDOW
;
1451 // canvas->GetEventHandler()->OnKillFocus();
1453 else if (XEventGetType(xevent
) == MotionNotify
)
1455 eventType
= wxEVT_MOTION
;
1457 else if (XEventGetType(xevent
) == ButtonPress
)
1459 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1461 if (XButtonEventLChanged(xevent
))
1463 eventType
= wxEVT_LEFT_DOWN
;
1466 else if (XButtonEventMChanged(xevent
))
1468 eventType
= wxEVT_MIDDLE_DOWN
;
1471 else if (XButtonEventRChanged(xevent
))
1473 eventType
= wxEVT_RIGHT_DOWN
;
1476 else if ( xevent
->xbutton
.button
== Button4
||
1477 xevent
->xbutton
.button
== Button5
)
1479 // this is the same value as used under wxMSW
1480 static const int WHEEL_DELTA
= 120;
1482 eventType
= wxEVT_MOUSEWHEEL
;
1483 button
= xevent
->xbutton
.button
;
1485 wxevent
.m_linesPerAction
= 3;
1486 wxevent
.m_wheelDelta
= WHEEL_DELTA
;
1488 // Button 4 means mousewheel up, 5 means down
1489 wxevent
.m_wheelRotation
= button
== Button4
? WHEEL_DELTA
1493 // check for a double click
1494 // TODO: where can we get this value from?
1495 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1496 long dclickTime
= 200;
1497 long ts
= wxevent
.GetTimestamp();
1499 int buttonLast
= win
->GetLastClickedButton();
1500 long lastTS
= win
->GetLastClickTime();
1501 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1504 win
->SetLastClick(0, ts
);
1505 if ( eventType
== wxEVT_LEFT_DOWN
)
1506 eventType
= wxEVT_LEFT_DCLICK
;
1507 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1508 eventType
= wxEVT_MIDDLE_DCLICK
;
1509 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1510 eventType
= wxEVT_RIGHT_DCLICK
;
1514 // not fast enough or different button
1515 win
->SetLastClick(button
, ts
);
1518 else if (XEventGetType(xevent
) == ButtonRelease
)
1520 if (XButtonEventLChanged(xevent
))
1522 eventType
= wxEVT_LEFT_UP
;
1524 else if (XButtonEventMChanged(xevent
))
1526 eventType
= wxEVT_MIDDLE_UP
;
1528 else if (XButtonEventRChanged(xevent
))
1530 eventType
= wxEVT_RIGHT_UP
;
1539 wxevent
.SetEventType(eventType
);
1541 wxevent
.m_x
= XButtonEventGetX(xevent
);
1542 wxevent
.m_y
= XButtonEventGetY(xevent
);
1544 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1545 || (XButtonEventLIsDown(xevent
)
1546 && (eventType
!= wxEVT_LEFT_UP
)));
1547 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1548 || (XButtonEventMIsDown(xevent
)
1549 && (eventType
!= wxEVT_MIDDLE_UP
)));
1550 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1551 || (XButtonEventRIsDown (xevent
)
1552 && (eventType
!= wxEVT_RIGHT_UP
)));
1554 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1555 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1556 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1557 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1559 wxevent
.SetId(win
->GetId());
1560 wxevent
.SetEventObject(win
);
1568 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1570 switch (XEventGetType(xevent
))
1578 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1579 int id
= wxCharCodeXToWX (keySym
);
1580 // id may be WXK_xxx code - these are outside ASCII range, so we
1581 // can't just use toupper() on id.
1582 // Only change this if we want the raw key that was pressed,
1583 // and don't change it if we want an ASCII value.
1584 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1586 id
= id
+ 'A' - 'a';
1589 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1590 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1591 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1592 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1593 wxevent
.SetEventObject(win
);
1594 wxevent
.m_keyCode
= id
;
1595 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1597 wxevent
.m_x
= XKeyEventGetX(xevent
);
1598 wxevent
.m_y
= XKeyEventGetY(xevent
);
1608 // ----------------------------------------------------------------------------
1610 // ----------------------------------------------------------------------------
1612 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1614 wxWindowBase::SetBackgroundColour(col
);
1616 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1617 int xscreen
= DefaultScreen( xdisplay
);
1618 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1620 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1622 // We don't set the background colour as we paint
1623 // the background ourselves.
1624 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1629 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1631 if ( !wxWindowBase::SetForegroundColour(col
) )
1637 // ----------------------------------------------------------------------------
1639 // ----------------------------------------------------------------------------
1641 wxWindow
*wxGetActiveWindow()
1644 wxFAIL_MSG(wxT("Not implemented"));
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(_T("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
);