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
;
355 if (m_clientWindow
!= m_mainWindow
)
357 // Destroy the cleint window
358 Window xwindow
= (Window
) m_clientWindow
;
359 wxDeleteClientWindowFromTable( xwindow
);
360 XDestroyWindow( wxGlobalDisplay(), xwindow
);
361 m_clientWindow
= NULL
;
364 // Destroy the window
367 Window xwindow
= (Window
) m_mainWindow
;
368 wxDeleteWindowFromTable( xwindow
);
369 XDestroyWindow( wxGlobalDisplay(), xwindow
);
374 // ---------------------------------------------------------------------------
376 // ---------------------------------------------------------------------------
378 void wxWindowX11::SetFocus()
380 Window xwindow
= (Window
) m_clientWindow
;
382 wxCHECK_RET( xwindow
, wxT("invalid window") );
384 // Don't assert; we might be trying to set the focus for a panel
385 // with only static controls, so the panel returns false from AcceptsFocus.
386 // The app should be not be expected to deal with this.
391 if (GetName() == "scrollBar")
398 if (wxWindowIsVisible(xwindow
))
400 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
401 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
402 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
403 m_needsInputFocus
= false;
407 m_needsInputFocus
= true;
411 // Get the window with the focus
412 wxWindow
*wxWindowBase::DoFindFocus()
414 Window xfocus
= (Window
) 0;
417 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
420 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
423 win
= wxGetClientWindowFromTable( xfocus
);
432 // Enabling/disabling handled by event loop, and not sending events
434 bool wxWindowX11::Enable(bool enable
)
436 if ( !wxWindowBase::Enable(enable
) )
442 bool wxWindowX11::Show(bool show
)
444 wxWindowBase::Show(show
);
446 Window xwindow
= (Window
) m_mainWindow
;
447 Display
*xdisp
= wxGlobalDisplay();
450 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
451 XMapWindow(xdisp
, xwindow
);
455 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
456 XUnmapWindow(xdisp
, xwindow
);
462 // Raise the window to the top of the Z order
463 void wxWindowX11::Raise()
466 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
469 // Lower the window to the bottom of the Z order
470 void wxWindowX11::Lower()
473 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
476 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
481 wxString
wxWindowX11::GetLabel() const
484 return wxEmptyString
;
487 void wxWindowX11::DoCaptureMouse()
489 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
491 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
502 Window xwindow
= (Window
) m_clientWindow
;
504 wxCHECK_RET( xwindow
, wxT("invalid window") );
506 g_captureWindow
= (wxWindow
*) this;
510 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
512 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
516 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
519 if (res
!= GrabSuccess
)
522 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
524 if (res
== GrabNotViewable
)
525 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
527 g_captureWindow
= NULL
;
531 m_winCaptured
= true;
535 void wxWindowX11::DoReleaseMouse()
537 g_captureWindow
= NULL
;
539 if ( !m_winCaptured
)
542 Window xwindow
= (Window
) m_clientWindow
;
546 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
549 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
551 m_winCaptured
= false;
554 bool wxWindowX11::SetFont(const wxFont
& font
)
556 if ( !wxWindowBase::SetFont(font
) )
565 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
567 if ( !wxWindowBase::SetCursor(cursor
) )
573 Window xwindow
= (Window
) m_clientWindow
;
575 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
577 wxCursor cursorToUse
;
579 cursorToUse
= m_cursor
;
581 cursorToUse
= *wxSTANDARD_CURSOR
;
583 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
585 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
590 // Coordinates relative to the window
591 void wxWindowX11::WarpPointer (int x
, int y
)
593 Window xwindow
= (Window
) m_clientWindow
;
595 wxCHECK_RET( xwindow
, wxT("invalid window") );
597 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
600 // Does a physical scroll
601 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
603 // No scrolling requested.
604 if ((dx
== 0) && (dy
== 0)) return;
606 if (!m_updateRegion
.IsEmpty())
608 m_updateRegion
.Offset( dx
, dy
);
612 GetSize( &cw
, &ch
); // GetClientSize() ??
613 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
616 if (!m_clearRegion
.IsEmpty())
618 m_clearRegion
.Offset( dx
, dy
);
622 GetSize( &cw
, &ch
); // GetClientSize() ??
623 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
626 Window xwindow
= (Window
) GetClientAreaWindow();
628 wxCHECK_RET( xwindow
, wxT("invalid window") );
630 Display
*xdisplay
= wxGlobalDisplay();
632 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
633 XSetGraphicsExposures( xdisplay
, xgc
, True
);
651 GetClientSize( &cw
, &ch
);
654 #if wxUSE_TWO_WINDOWS
655 wxPoint
offset( 0,0 );
657 wxPoint offset
= GetClientAreaOrigin();
662 int w
= cw
- abs(dx
);
663 int h
= ch
- abs(dy
);
665 if ((h
< 0) || (w
< 0))
672 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
673 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
674 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
675 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
680 if (dx
< 0) s_x
+= -dx
;
681 if (dy
< 0) s_y
+= -dy
;
682 if (dx
> 0) d_x
+= dx
+ offset
.x
;
683 if (dy
> 0) d_y
+= dy
+ offset
.y
;
685 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
687 // 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 );
689 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
691 m_updateRegion
.Union( rect
);
692 m_clearRegion
.Union( rect
);
695 XFreeGC( xdisplay
, xgc
);
697 // Move Clients, but not the scrollbars
698 // FIXME: There may be a better method to move a lot of Windows within X11
699 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
700 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
701 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
704 // Only propagate to non-top-level windows
705 wxWindow
*win
= node
->GetData();
706 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
708 wxPoint pos
= win
->GetPosition();
709 // Add the delta to the old Position
712 win
->SetPosition(pos
);
714 node
= node
->GetNext();
718 // ---------------------------------------------------------------------------
720 // ---------------------------------------------------------------------------
722 #if wxUSE_DRAG_AND_DROP
724 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
731 // Old style file-manager drag&drop
732 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
737 // ----------------------------------------------------------------------------
739 // ----------------------------------------------------------------------------
743 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
748 #endif // wxUSE_TOOLTIPS
750 // ---------------------------------------------------------------------------
751 // moving and resizing
752 // ---------------------------------------------------------------------------
754 bool wxWindowX11::PreResize()
760 void wxWindowX11::DoGetSize(int *x
, int *y
) const
762 Window xwindow
= (Window
) m_mainWindow
;
764 wxCHECK_RET( xwindow
, wxT("invalid window") );
766 //XSync(wxGlobalDisplay(), False);
768 XWindowAttributes attr
;
769 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
774 *x
= attr
.width
/* + 2*m_borderSize */ ;
775 *y
= attr
.height
/* + 2*m_borderSize */ ;
779 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
781 Window window
= (Window
) m_mainWindow
;
784 //XSync(wxGlobalDisplay(), False);
785 XWindowAttributes attr
;
786 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
794 // We may be faking the client origin. So a window that's really at (0, 30)
795 // may appear (to wxWin apps) to be at (0, 0).
798 wxPoint
pt(GetParent()->GetClientAreaOrigin());
806 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
808 Display
*display
= wxGlobalDisplay();
809 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
810 Window thisWindow
= (Window
) m_clientWindow
;
815 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
816 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
820 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
822 Display
*display
= wxGlobalDisplay();
823 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
824 Window thisWindow
= (Window
) m_clientWindow
;
829 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
830 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
835 // Get size *available for subwindows* i.e. excluding menu bar etc.
836 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
838 Window window
= (Window
) m_mainWindow
;
842 XWindowAttributes attr
;
843 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
854 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
856 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
858 Window xwindow
= (Window
) m_mainWindow
;
860 wxCHECK_RET( xwindow
, wxT("invalid window") );
862 XWindowAttributes attr
;
863 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
864 wxCHECK_RET( status
, wxT("invalid window attributes") );
868 int new_w
= attr
.width
;
869 int new_h
= attr
.height
;
871 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
874 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
877 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
880 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
883 if (width
!= wxDefaultCoord
)
889 if (height
!= wxDefaultCoord
)
896 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
899 void wxWindowX11::DoSetClientSize(int width
, int height
)
901 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
903 Window xwindow
= (Window
) m_mainWindow
;
905 wxCHECK_RET( xwindow
, wxT("invalid window") );
907 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
909 if (m_mainWindow
!= m_clientWindow
)
911 xwindow
= (Window
) m_clientWindow
;
913 wxWindow
*window
= (wxWindow
*) this;
914 wxRenderer
*renderer
= window
->GetRenderer();
917 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
918 width
-= border
.x
+ border
.width
;
919 height
-= border
.y
+ border
.height
;
922 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
926 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
928 Window xwindow
= (Window
) m_mainWindow
;
930 wxCHECK_RET( xwindow
, wxT("invalid window") );
934 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
935 if (m_mainWindow
!= m_clientWindow
)
937 xwindow
= (Window
) m_clientWindow
;
939 wxWindow
*window
= (wxWindow
*) this;
940 wxRenderer
*renderer
= window
->GetRenderer();
943 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
946 width
-= border
.x
+ border
.width
;
947 height
-= border
.y
+ border
.height
;
955 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
956 if (sb
&& sb
->IsShown())
958 wxSize size
= sb
->GetSize();
961 sb
= window
->GetScrollbar( wxVERTICAL
);
962 if (sb
&& sb
->IsShown())
964 wxSize size
= sb
->GetSize();
968 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
973 XWindowChanges windowChanges
;
976 windowChanges
.width
= width
;
977 windowChanges
.height
= height
;
978 windowChanges
.stack_mode
= 0;
979 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
981 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
986 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
994 XSizeHints sizeHints
;
997 if (minW
> -1 && minH
> -1)
999 sizeHints
.flags
|= PMinSize
;
1000 sizeHints
.min_width
= minW
;
1001 sizeHints
.min_height
= minH
;
1003 if (maxW
> -1 && maxH
> -1)
1005 sizeHints
.flags
|= PMaxSize
;
1006 sizeHints
.max_width
= maxW
;
1007 sizeHints
.max_height
= maxH
;
1009 if (incW
> -1 && incH
> -1)
1011 sizeHints
.flags
|= PResizeInc
;
1012 sizeHints
.width_inc
= incW
;
1013 sizeHints
.height_inc
= incH
;
1016 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1020 // ---------------------------------------------------------------------------
1022 // ---------------------------------------------------------------------------
1024 int wxWindowX11::GetCharHeight() const
1026 wxFont
font(GetFont());
1027 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1030 // There should be an easier way.
1031 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1032 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1033 pango_layout_set_text(layout
, "H", 1 );
1035 pango_layout_get_pixel_size(layout
, &w
, &h
);
1036 g_object_unref( G_OBJECT( layout
) );
1040 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1042 int direction
, ascent
, descent
;
1043 XCharStruct overall
;
1044 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1045 &descent
, &overall
);
1047 // return (overall.ascent + overall.descent);
1048 return (ascent
+ descent
);
1052 int wxWindowX11::GetCharWidth() const
1054 wxFont
font(GetFont());
1055 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1058 // There should be an easier way.
1059 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1060 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1061 pango_layout_set_text(layout
, "H", 1 );
1063 pango_layout_get_pixel_size(layout
, &w
, &h
);
1064 g_object_unref( G_OBJECT( layout
) );
1068 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1070 int direction
, ascent
, descent
;
1071 XCharStruct overall
;
1072 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1073 &descent
, &overall
);
1075 return overall
.width
;
1079 void wxWindowX11::GetTextExtent(const wxString
& string
,
1081 int *descent
, int *externalLeading
,
1082 const wxFont
*theFont
) const
1084 wxFont fontToUse
= GetFont();
1085 if (theFont
) fontToUse
= *theFont
;
1087 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1097 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1099 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1100 pango_layout_set_font_description(layout
, desc
);
1102 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1103 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1105 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1108 PangoRectangle rect
;
1109 pango_layout_line_get_extents(line
, NULL
, &rect
);
1111 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1112 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1115 // Do something about metrics here
1118 if (externalLeading
) (*externalLeading
) = 0; // ??
1120 g_object_unref( G_OBJECT( layout
) );
1122 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1124 int direction
, ascent
, descent2
;
1125 XCharStruct overall
;
1126 int slen
= string
.length();
1128 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1129 &direction
, &ascent
, &descent2
, &overall
);
1132 *x
= (overall
.width
);
1134 *y
= (ascent
+ descent2
);
1136 *descent
= descent2
;
1137 if (externalLeading
)
1138 *externalLeading
= 0;
1142 // ----------------------------------------------------------------------------
1144 // ----------------------------------------------------------------------------
1146 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1152 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1153 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1158 GetSize( &width
, &height
);
1160 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1161 m_clearRegion
.Clear();
1162 m_clearRegion
.Union( 0, 0, width
, height
);
1168 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1169 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1174 GetSize( &width
, &height
);
1176 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1177 m_updateRegion
.Clear();
1178 m_updateRegion
.Union( 0, 0, width
, height
);
1182 void wxWindowX11::Update()
1186 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1187 // Send nc paint events.
1188 SendNcPaintEvents();
1191 if (!m_updateRegion
.IsEmpty())
1193 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1194 // Actually send erase events.
1197 // Actually send paint events.
1202 void wxWindowX11::SendEraseEvents()
1204 if (m_clearRegion
.IsEmpty()) return;
1206 wxClientDC
dc( (wxWindow
*)this );
1207 dc
.SetDeviceClippingRegion( m_clearRegion
);
1209 wxEraseEvent
erase_event( GetId(), &dc
);
1210 erase_event
.SetEventObject( this );
1212 if (!HandleWindowEvent(erase_event
) )
1214 Display
*xdisplay
= wxGlobalDisplay();
1215 Window xwindow
= (Window
) GetClientAreaWindow();
1216 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1218 wxRegionIterator
upd( m_clearRegion
);
1221 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1222 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1227 m_clearRegion
.Clear();
1230 void wxWindowX11::SendPaintEvents()
1232 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1234 m_clipPaintRegion
= true;
1236 wxPaintEvent
paint_event( GetId() );
1237 paint_event
.SetEventObject( this );
1238 HandleWindowEvent( paint_event
);
1240 m_updateRegion
.Clear();
1242 m_clipPaintRegion
= false;
1245 void wxWindowX11::SendNcPaintEvents()
1247 wxWindow
*window
= (wxWindow
*) this;
1249 // All this for drawing the small square between the scrollbars.
1254 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1255 if (sb
&& sb
->IsShown())
1257 height
= sb
->GetSize().y
;
1258 y
= sb
->GetPosition().y
;
1260 sb
= window
->GetScrollbar( wxVERTICAL
);
1261 if (sb
&& sb
->IsShown())
1263 width
= sb
->GetSize().x
;
1264 x
= sb
->GetPosition().x
;
1266 Display
*xdisplay
= wxGlobalDisplay();
1267 Window xwindow
= (Window
) GetMainWindow();
1268 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1269 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1270 colour
.CalcPixel( (WXColormap
) cm
);
1272 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1274 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1278 wxNcPaintEvent
nc_paint_event( GetId() );
1279 nc_paint_event
.SetEventObject( this );
1280 HandleWindowEvent( nc_paint_event
);
1282 m_updateNcArea
= false;
1285 // ----------------------------------------------------------------------------
1287 // ----------------------------------------------------------------------------
1289 // Responds to colour changes: passes event on to children.
1290 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1292 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1295 // Only propagate to non-top-level windows
1296 wxWindow
*win
= node
->GetData();
1297 if ( win
->GetParent() )
1299 wxSysColourChangedEvent event2
;
1300 event
.SetEventObject(win
);
1301 win
->HandleWindowEvent(event2
);
1304 node
= node
->GetNext();
1308 // See handler for InFocus case in app.cpp for details.
1309 wxWindow
* g_GettingFocus
= NULL
;
1311 void wxWindowX11::OnInternalIdle()
1313 // Update invalidated regions.
1316 // This calls the UI-update mechanism (querying windows for
1317 // menu/toolbar/control state information)
1318 if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this) && IsShownOnScreen())
1319 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1321 // Set the input focus if couldn't do it before
1322 if (m_needsInputFocus
)
1326 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1327 printf(msg
.c_str());
1331 // If it couldn't set the focus now, there's
1332 // no point in trying again.
1333 m_needsInputFocus
= false;
1335 g_GettingFocus
= NULL
;
1338 // ----------------------------------------------------------------------------
1339 // function which maintain the global hash table mapping Widgets to wxWidgets
1340 // ----------------------------------------------------------------------------
1342 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1344 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1346 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1347 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1351 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1352 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1357 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1359 wxWindowHash::iterator i
= hash
->find(w
);
1360 return i
== hash
->end() ? NULL
: i
->second
;
1363 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1365 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1370 // ----------------------------------------------------------------------------
1372 // ----------------------------------------------------------------------------
1374 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1376 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1379 wxWindow
*wxGetWindowFromTable(Window w
)
1381 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1384 void wxDeleteWindowFromTable(Window w
)
1386 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1389 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1391 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1394 wxWindow
*wxGetClientWindowFromTable(Window w
)
1396 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1399 void wxDeleteClientWindowFromTable(Window w
)
1401 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1404 // ----------------------------------------------------------------------------
1405 // X11-specific accessors
1406 // ----------------------------------------------------------------------------
1408 WXWindow
wxWindowX11::GetMainWindow() const
1410 return m_mainWindow
;
1413 WXWindow
wxWindowX11::GetClientAreaWindow() const
1415 return m_clientWindow
;
1418 // ----------------------------------------------------------------------------
1419 // TranslateXXXEvent() functions
1420 // ----------------------------------------------------------------------------
1422 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
,
1424 Window
WXUNUSED(window
),
1427 switch (XEventGetType(xevent
))
1435 wxEventType eventType
= wxEVT_NULL
;
1437 if (XEventGetType(xevent
) == EnterNotify
)
1439 //if (local_event.xcrossing.mode!=NotifyNormal)
1440 // return ; // Ignore grab events
1441 eventType
= wxEVT_ENTER_WINDOW
;
1442 // canvas->GetEventHandler()->OnSetFocus();
1444 else if (XEventGetType(xevent
) == LeaveNotify
)
1446 //if (local_event.xcrossingr.mode!=NotifyNormal)
1447 // return ; // Ignore grab events
1448 eventType
= wxEVT_LEAVE_WINDOW
;
1449 // canvas->GetEventHandler()->OnKillFocus();
1451 else if (XEventGetType(xevent
) == MotionNotify
)
1453 eventType
= wxEVT_MOTION
;
1455 else if (XEventGetType(xevent
) == ButtonPress
)
1457 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1459 if (XButtonEventLChanged(xevent
))
1461 eventType
= wxEVT_LEFT_DOWN
;
1464 else if (XButtonEventMChanged(xevent
))
1466 eventType
= wxEVT_MIDDLE_DOWN
;
1469 else if (XButtonEventRChanged(xevent
))
1471 eventType
= wxEVT_RIGHT_DOWN
;
1474 else if ( xevent
->xbutton
.button
== Button4
||
1475 xevent
->xbutton
.button
== Button5
)
1477 // this is the same value as used under wxMSW
1478 static const int WHEEL_DELTA
= 120;
1480 eventType
= wxEVT_MOUSEWHEEL
;
1481 button
= xevent
->xbutton
.button
;
1483 wxevent
.m_linesPerAction
= 3;
1484 wxevent
.m_wheelDelta
= WHEEL_DELTA
;
1486 // Button 4 means mousewheel up, 5 means down
1487 wxevent
.m_wheelRotation
= button
== Button4
? WHEEL_DELTA
1491 // check for a double click
1492 // TODO: where can we get this value from?
1493 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1494 long dclickTime
= 200;
1495 long ts
= wxevent
.GetTimestamp();
1497 int buttonLast
= win
->GetLastClickedButton();
1498 long lastTS
= win
->GetLastClickTime();
1499 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1502 win
->SetLastClick(0, ts
);
1503 if ( eventType
== wxEVT_LEFT_DOWN
)
1504 eventType
= wxEVT_LEFT_DCLICK
;
1505 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1506 eventType
= wxEVT_MIDDLE_DCLICK
;
1507 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1508 eventType
= wxEVT_RIGHT_DCLICK
;
1512 // not fast enough or different button
1513 win
->SetLastClick(button
, ts
);
1516 else if (XEventGetType(xevent
) == ButtonRelease
)
1518 if (XButtonEventLChanged(xevent
))
1520 eventType
= wxEVT_LEFT_UP
;
1522 else if (XButtonEventMChanged(xevent
))
1524 eventType
= wxEVT_MIDDLE_UP
;
1526 else if (XButtonEventRChanged(xevent
))
1528 eventType
= wxEVT_RIGHT_UP
;
1537 wxevent
.SetEventType(eventType
);
1539 wxevent
.m_x
= XButtonEventGetX(xevent
);
1540 wxevent
.m_y
= XButtonEventGetY(xevent
);
1542 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1543 || (XButtonEventLIsDown(xevent
)
1544 && (eventType
!= wxEVT_LEFT_UP
)));
1545 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1546 || (XButtonEventMIsDown(xevent
)
1547 && (eventType
!= wxEVT_MIDDLE_UP
)));
1548 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1549 || (XButtonEventRIsDown (xevent
)
1550 && (eventType
!= wxEVT_RIGHT_UP
)));
1552 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1553 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1554 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1555 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1557 wxevent
.SetId(win
->GetId());
1558 wxevent
.SetEventObject(win
);
1566 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1568 switch (XEventGetType(xevent
))
1576 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1577 int id
= wxCharCodeXToWX (keySym
);
1578 // id may be WXK_xxx code - these are outside ASCII range, so we
1579 // can't just use toupper() on id.
1580 // Only change this if we want the raw key that was pressed,
1581 // and don't change it if we want an ASCII value.
1582 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1584 id
= id
+ 'A' - 'a';
1587 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1588 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1589 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1590 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1591 wxevent
.SetEventObject(win
);
1592 wxevent
.m_keyCode
= id
;
1593 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1595 wxevent
.m_x
= XKeyEventGetX(xevent
);
1596 wxevent
.m_y
= XKeyEventGetY(xevent
);
1606 // ----------------------------------------------------------------------------
1608 // ----------------------------------------------------------------------------
1610 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1612 wxWindowBase::SetBackgroundColour(col
);
1614 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1615 int xscreen
= DefaultScreen( xdisplay
);
1616 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1618 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1620 // We don't set the background colour as we paint
1621 // the background ourselves.
1622 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1627 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1629 if ( !wxWindowBase::SetForegroundColour(col
) )
1635 // ----------------------------------------------------------------------------
1637 // ----------------------------------------------------------------------------
1639 wxWindow
*wxGetActiveWindow()
1642 wxFAIL_MSG(wxT("Not implemented"));
1647 wxWindow
*wxWindowBase::GetCapture()
1649 return (wxWindow
*)g_captureWindow
;
1653 // Find the wxWindow at the current mouse position, returning the mouse
1655 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1657 pt
= wxGetMousePosition();
1658 return wxFindWindowAtPoint(pt
);
1661 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
1668 Display
*display
= wxGlobalDisplay();
1669 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1670 Window rootReturn
, childReturn
;
1673 XQueryPointer (display
,
1677 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1681 // Get the current mouse position.
1682 wxPoint
wxGetMousePosition()
1687 wxGetMouseState(x
, y
, mask
);
1688 return wxPoint(x
, y
);
1691 wxMouseState
wxGetMouseState()
1697 wxGetMouseState(x
, y
, mask
);
1702 ms
.SetLeftDown(mask
& Button1Mask
);
1703 ms
.SetMiddleDown(mask
& Button2Mask
);
1704 ms
.SetRightDown(mask
& Button3Mask
);
1706 ms
.SetControlDown(mask
& ControlMask
);
1707 ms
.SetShiftDown(mask
& ShiftMask
);
1708 ms
.SetAltDown(mask
& Mod3Mask
);
1709 ms
.SetMetaDown(mask
& Mod1Mask
);
1715 // ----------------------------------------------------------------------------
1716 // wxNoOptimize: switch off size optimization
1717 // ----------------------------------------------------------------------------
1719 int wxNoOptimize::ms_count
= 0;
1722 // ----------------------------------------------------------------------------
1724 // ----------------------------------------------------------------------------
1726 class wxWinModule
: public wxModule
1731 // we must be cleaned up before the display is closed
1732 AddDependency(wxClassInfo::FindClass(_T("wxX11DisplayModule")));
1735 virtual bool OnInit();
1736 virtual void OnExit();
1739 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1742 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1744 bool wxWinModule::OnInit()
1746 Display
*xdisplay
= wxGlobalDisplay();
1747 int xscreen
= DefaultScreen( xdisplay
);
1748 Window xroot
= RootWindow( xdisplay
, xscreen
);
1749 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1750 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1755 void wxWinModule::OnExit()
1757 Display
*xdisplay
= wxGlobalDisplay();
1758 XFreeGC( xdisplay
, g_eraseGC
);