1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/window.cpp
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // for compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
14 #if defined(__BORLANDC__)
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 #include "wx/window.h"
36 #include "wx/dcclient.h"
37 #include "wx/button.h"
39 #include "wx/dialog.h"
41 #include "wx/settings.h"
42 #include "wx/msgdlg.h"
43 #include "wx/scrolbar.h"
44 #include "wx/listbox.h"
45 #include "wx/scrolwin.h"
46 #include "wx/layout.h"
47 #include "wx/menuitem.h"
48 #include "wx/module.h"
51 #include "wx/fontutil.h"
52 #include "wx/univ/renderer.h"
54 #if wxUSE_DRAG_AND_DROP
58 #include "wx/unix/utilsx11.h"
60 #include "wx/x11/private.h"
61 #include "X11/Xutil.h"
65 // ----------------------------------------------------------------------------
66 // global variables for this module
67 // ----------------------------------------------------------------------------
69 static wxWindow
* g_captureWindow
= NULL
;
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
77 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
78 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
86 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
87 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
90 // ============================================================================
92 // ============================================================================
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 void wxWindowX11::Init()
105 m_mainWindow
= (WXWindow
) 0;
106 m_clientWindow
= (WXWindow
) 0;
107 m_insertIntoMain
= false;
108 m_updateNcArea
= false;
110 m_winCaptured
= false;
111 m_needsInputFocus
= false;
117 // real construction (Init() must have been called before!)
118 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
122 const wxString
& name
)
124 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
126 // Get default border
127 wxBorder border
= GetBorder(style
);
128 style
&= ~wxBORDER_MASK
;
131 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
133 parent
->AddChild(this);
135 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
136 int xscreen
= DefaultScreen( xdisplay
);
137 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
138 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
140 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
141 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
143 m_foregroundColour
= *wxBLACK
;
144 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
146 Window xparent
= (Window
) parent
->GetClientAreaWindow();
148 // Add window's own scrollbars to main window, not to client window
149 if (parent
->GetInsertIntoMain())
151 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
152 xparent
= (Window
) parent
->X11GetMainWindow();
155 // Size (not including the border) must be nonzero (or a Value error results)!
156 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
164 if (pos2
.x
== wxDefaultCoord
)
166 if (pos2
.y
== wxDefaultCoord
)
169 AdjustForParentClientOrigin(pos2
.x
, pos2
.y
);
171 #if wxUSE_TWO_WINDOWS
172 bool need_two_windows
=
173 ((( wxSUNKEN_BORDER
| wxBORDER_THEME
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
175 bool need_two_windows
= false;
179 long xattributes
= 0;
181 XSetWindowAttributes xattributes
;
182 long xattributes_mask
= 0;
184 xattributes_mask
|= CWBackPixel
;
185 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
187 xattributes_mask
|= CWBorderPixel
;
188 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
190 xattributes_mask
|= CWEventMask
;
193 if (need_two_windows
)
196 long backColor
, foreColor
;
197 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
198 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
200 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
201 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
202 XSelectInput( xdisplay
, xwindow
,
203 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
204 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
205 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
206 PropertyChangeMask
);
210 xattributes
.event_mask
=
211 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
213 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
214 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
218 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
220 m_mainWindow
= (WXWindow
) xwindow
;
221 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
223 XMapWindow( xdisplay
, xwindow
);
226 xattributes
.event_mask
=
227 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
228 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
229 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
230 PropertyChangeMask
| VisibilityChangeMask
;
232 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
234 xattributes_mask
|= CWBitGravity
;
235 xattributes
.bit_gravity
= StaticGravity
;
239 if (HasFlag(wxSUNKEN_BORDER
) || HasFlag(wxRAISED_BORDER
) || HasFlag(wxBORDER_THEME
))
246 else if (HasFlag( wxSIMPLE_BORDER
))
259 // Make again sure the size is nonzero.
266 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
267 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
269 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
270 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
271 XSelectInput( xdisplay
, xwindow
,
272 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
273 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
274 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
275 PropertyChangeMask
);
278 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
279 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
282 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
284 m_clientWindow
= (WXWindow
) xwindow
;
285 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
287 XMapWindow( xdisplay
, xwindow
);
291 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
293 long backColor
, foreColor
;
294 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
295 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
297 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
298 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
299 XSelectInput( xdisplay
, xwindow
,
300 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
301 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
302 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
303 PropertyChangeMask
);
306 xattributes
.event_mask
=
307 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
308 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
309 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
310 PropertyChangeMask
| VisibilityChangeMask
;
312 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
314 xattributes_mask
|= CWBitGravity
;
315 xattributes
.bit_gravity
= NorthWestGravity
;
318 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
319 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
322 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
324 m_mainWindow
= (WXWindow
) xwindow
;
325 m_clientWindow
= m_mainWindow
;
326 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
328 XMapWindow( xdisplay
, xwindow
);
331 // Is a subwindow, so map immediately
334 // Without this, the cursor may not be restored properly (e.g. in splitter
336 SetCursor(*wxSTANDARD_CURSOR
);
337 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
339 // Don't call this, it can have nasty repercussions for composite controls,
341 // SetSize(pos.x, pos.y, size.x, size.y);
347 wxWindowX11::~wxWindowX11()
351 if (g_captureWindow
== this)
352 g_captureWindow
= NULL
;
356 if (m_clientWindow
!= m_mainWindow
)
358 // Destroy the cleint window
359 Window xwindow
= (Window
) m_clientWindow
;
360 wxDeleteClientWindowFromTable( xwindow
);
361 XDestroyWindow( wxGlobalDisplay(), xwindow
);
362 m_clientWindow
= NULL
;
365 // Destroy the window
368 Window xwindow
= (Window
) m_mainWindow
;
369 wxDeleteWindowFromTable( xwindow
);
370 XDestroyWindow( wxGlobalDisplay(), xwindow
);
375 // ---------------------------------------------------------------------------
377 // ---------------------------------------------------------------------------
379 void wxWindowX11::SetFocus()
381 Window xwindow
= (Window
) m_clientWindow
;
383 wxCHECK_RET( xwindow
, wxT("invalid window") );
385 // Don't assert; we might be trying to set the focus for a panel
386 // with only static controls, so the panel returns false from AcceptsFocus.
387 // The app should be not be expected to deal with this.
392 if (GetName() == "scrollBar")
399 XWindowAttributes wa
;
400 XGetWindowAttributes(wxGlobalDisplay(), xwindow
, &wa
);
402 if (wa
.map_state
== IsViewable
)
404 wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
405 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
406 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
407 m_needsInputFocus
= false;
411 m_needsInputFocus
= true;
415 // Get the window with the focus
416 wxWindow
*wxWindowBase::DoFindFocus()
418 Window xfocus
= (Window
) 0;
421 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
424 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
427 win
= wxGetClientWindowFromTable( xfocus
);
436 // Enabling/disabling handled by event loop, and not sending events
438 bool wxWindowX11::Enable(bool enable
)
440 if ( !wxWindowBase::Enable(enable
) )
446 bool wxWindowX11::Show(bool show
)
448 wxWindowBase::Show(show
);
450 Window xwindow
= (Window
) m_mainWindow
;
451 Display
*xdisp
= wxGlobalDisplay();
454 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
455 XMapWindow(xdisp
, xwindow
);
459 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
460 XUnmapWindow(xdisp
, xwindow
);
466 // Raise the window to the top of the Z order
467 void wxWindowX11::Raise()
470 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
473 // Lower the window to the bottom of the Z order
474 void wxWindowX11::Lower()
477 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
480 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
485 wxString
wxWindowX11::GetLabel() const
488 return wxEmptyString
;
491 void wxWindowX11::DoCaptureMouse()
493 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
495 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
506 Window xwindow
= (Window
) m_clientWindow
;
508 wxCHECK_RET( xwindow
, wxT("invalid window") );
510 g_captureWindow
= (wxWindow
*) this;
514 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
516 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
520 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
523 if (res
!= GrabSuccess
)
526 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
528 if (res
== GrabNotViewable
)
530 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
533 g_captureWindow
= NULL
;
537 m_winCaptured
= true;
541 void wxWindowX11::DoReleaseMouse()
543 g_captureWindow
= NULL
;
545 if ( !m_winCaptured
)
548 Window xwindow
= (Window
) m_clientWindow
;
552 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
555 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
557 m_winCaptured
= false;
560 bool wxWindowX11::SetFont(const wxFont
& font
)
562 if ( !wxWindowBase::SetFont(font
) )
571 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
573 if ( !wxWindowBase::SetCursor(cursor
) )
579 Window xwindow
= (Window
) m_clientWindow
;
581 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
583 wxCursor cursorToUse
;
585 cursorToUse
= m_cursor
;
587 cursorToUse
= *wxSTANDARD_CURSOR
;
589 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
591 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
596 // Coordinates relative to the window
597 void wxWindowX11::WarpPointer (int x
, int y
)
599 Window xwindow
= (Window
) m_clientWindow
;
601 wxCHECK_RET( xwindow
, wxT("invalid window") );
603 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
606 // Does a physical scroll
607 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
609 // No scrolling requested.
610 if ((dx
== 0) && (dy
== 0)) return;
612 if (!m_updateRegion
.IsEmpty())
614 m_updateRegion
.Offset( dx
, dy
);
618 GetSize( &cw
, &ch
); // GetClientSize() ??
619 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
622 if (!m_clearRegion
.IsEmpty())
624 m_clearRegion
.Offset( dx
, dy
);
628 GetSize( &cw
, &ch
); // GetClientSize() ??
629 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
632 Window xwindow
= (Window
) GetClientAreaWindow();
634 wxCHECK_RET( xwindow
, wxT("invalid window") );
636 Display
*xdisplay
= wxGlobalDisplay();
638 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
639 XSetGraphicsExposures( xdisplay
, xgc
, True
);
657 GetClientSize( &cw
, &ch
);
660 #if wxUSE_TWO_WINDOWS
661 wxPoint
offset( 0,0 );
663 wxPoint offset
= GetClientAreaOrigin();
668 int w
= cw
- abs(dx
);
669 int h
= ch
- abs(dy
);
671 if ((h
< 0) || (w
< 0))
678 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
679 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
680 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
681 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
686 if (dx
< 0) s_x
+= -dx
;
687 if (dy
< 0) s_y
+= -dy
;
688 if (dx
> 0) d_x
+= dx
+ offset
.x
;
689 if (dy
> 0) d_y
+= dy
+ offset
.y
;
691 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
693 // 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 );
695 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
697 m_updateRegion
.Union( rect
);
698 m_clearRegion
.Union( rect
);
701 XFreeGC( xdisplay
, xgc
);
703 // Move Clients, but not the scrollbars
704 // FIXME: There may be a better method to move a lot of Windows within X11
705 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
706 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
707 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
710 // Only propagate to non-top-level windows
711 wxWindow
*win
= node
->GetData();
712 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
714 wxPoint pos
= win
->GetPosition();
715 // Add the delta to the old Position
718 win
->SetPosition(pos
);
720 node
= node
->GetNext();
724 // ---------------------------------------------------------------------------
726 // ---------------------------------------------------------------------------
728 #if wxUSE_DRAG_AND_DROP
730 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
737 // Old style file-manager drag&drop
738 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
749 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
754 #endif // wxUSE_TOOLTIPS
756 // ---------------------------------------------------------------------------
757 // moving and resizing
758 // ---------------------------------------------------------------------------
760 bool wxWindowX11::PreResize()
766 void wxWindowX11::DoGetSize(int *x
, int *y
) const
768 Window xwindow
= (Window
) m_mainWindow
;
770 wxCHECK_RET( xwindow
, wxT("invalid window") );
772 //XSync(wxGlobalDisplay(), False);
774 XWindowAttributes attr
;
775 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
780 *x
= attr
.width
/* + 2*m_borderSize */ ;
781 *y
= attr
.height
/* + 2*m_borderSize */ ;
785 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
787 Window window
= (Window
) m_mainWindow
;
790 //XSync(wxGlobalDisplay(), False);
791 XWindowAttributes attr
;
792 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
800 // We may be faking the client origin. So a window that's really at (0, 30)
801 // may appear (to wxWin apps) to be at (0, 0).
804 wxPoint
pt(GetParent()->GetClientAreaOrigin());
812 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
814 Display
*display
= wxGlobalDisplay();
815 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
816 Window thisWindow
= (Window
) m_clientWindow
;
821 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
822 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
826 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
828 Display
*display
= wxGlobalDisplay();
829 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
830 Window thisWindow
= (Window
) m_clientWindow
;
835 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
836 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
841 // Get size *available for subwindows* i.e. excluding menu bar etc.
842 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
844 Window window
= (Window
) m_mainWindow
;
848 XWindowAttributes attr
;
849 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
860 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
862 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
864 Window xwindow
= (Window
) m_mainWindow
;
866 wxCHECK_RET( xwindow
, wxT("invalid window") );
868 XWindowAttributes attr
;
869 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
870 wxCHECK_RET( status
, wxT("invalid window attributes") );
874 int new_w
= attr
.width
;
875 int new_h
= attr
.height
;
877 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
880 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
883 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
886 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
889 if (width
!= wxDefaultCoord
)
895 if (height
!= wxDefaultCoord
)
902 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
905 void wxWindowX11::DoSetClientSize(int width
, int height
)
907 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
909 Window xwindow
= (Window
) m_mainWindow
;
911 wxCHECK_RET( xwindow
, wxT("invalid window") );
913 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
915 if (m_mainWindow
!= m_clientWindow
)
917 xwindow
= (Window
) m_clientWindow
;
919 wxWindow
*window
= (wxWindow
*) this;
920 wxRenderer
*renderer
= window
->GetRenderer();
923 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
924 width
-= border
.x
+ border
.width
;
925 height
-= border
.y
+ border
.height
;
928 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
932 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
934 Window xwindow
= (Window
) m_mainWindow
;
936 wxCHECK_RET( xwindow
, wxT("invalid window") );
940 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
941 if (m_mainWindow
!= m_clientWindow
)
943 xwindow
= (Window
) m_clientWindow
;
945 wxWindow
*window
= (wxWindow
*) this;
946 wxRenderer
*renderer
= window
->GetRenderer();
949 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
952 width
-= border
.x
+ border
.width
;
953 height
-= border
.y
+ border
.height
;
961 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
962 if (sb
&& sb
->IsShown())
964 wxSize size
= sb
->GetSize();
967 sb
= window
->GetScrollbar( wxVERTICAL
);
968 if (sb
&& sb
->IsShown())
970 wxSize size
= sb
->GetSize();
974 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
979 XWindowChanges windowChanges
;
982 windowChanges
.width
= width
;
983 windowChanges
.height
= height
;
984 windowChanges
.stack_mode
= 0;
985 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
987 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
992 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1000 XSizeHints sizeHints
;
1001 sizeHints
.flags
= 0;
1003 if (minW
> -1 && minH
> -1)
1005 sizeHints
.flags
|= PMinSize
;
1006 sizeHints
.min_width
= minW
;
1007 sizeHints
.min_height
= minH
;
1009 if (maxW
> -1 && maxH
> -1)
1011 sizeHints
.flags
|= PMaxSize
;
1012 sizeHints
.max_width
= maxW
;
1013 sizeHints
.max_height
= maxH
;
1015 if (incW
> -1 && incH
> -1)
1017 sizeHints
.flags
|= PResizeInc
;
1018 sizeHints
.width_inc
= incW
;
1019 sizeHints
.height_inc
= incH
;
1022 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1026 // ---------------------------------------------------------------------------
1028 // ---------------------------------------------------------------------------
1030 int wxWindowX11::GetCharHeight() const
1032 wxFont
font(GetFont());
1033 wxCHECK_MSG( font
.IsOk(), 0, wxT("valid window font needed") );
1036 // There should be an easier way.
1037 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1038 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1039 pango_layout_set_text(layout
, "H", 1 );
1041 pango_layout_get_pixel_size(layout
, &w
, &h
);
1042 g_object_unref( G_OBJECT( layout
) );
1046 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1048 int direction
, ascent
, descent
;
1049 XCharStruct overall
;
1050 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1051 &descent
, &overall
);
1053 // return (overall.ascent + overall.descent);
1054 return (ascent
+ descent
);
1058 int wxWindowX11::GetCharWidth() const
1060 wxFont
font(GetFont());
1061 wxCHECK_MSG( font
.IsOk(), 0, wxT("valid window font needed") );
1064 // There should be an easier way.
1065 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1066 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1067 pango_layout_set_text(layout
, "H", 1 );
1069 pango_layout_get_pixel_size(layout
, &w
, &h
);
1070 g_object_unref( G_OBJECT( layout
) );
1074 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1076 int direction
, ascent
, descent
;
1077 XCharStruct overall
;
1078 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1079 &descent
, &overall
);
1081 return overall
.width
;
1085 void wxWindowX11::DoGetTextExtent(const wxString
& string
,
1088 int *externalLeading
,
1089 const wxFont
*theFont
) const
1091 wxFont fontToUse
= GetFont();
1092 if (theFont
) fontToUse
= *theFont
;
1094 wxCHECK_RET( fontToUse
.IsOk(), wxT("invalid font") );
1104 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1106 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1107 pango_layout_set_font_description(layout
, desc
);
1109 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
.wc_str() );
1110 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1112 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1115 PangoRectangle rect
;
1116 pango_layout_line_get_extents(line
, NULL
, &rect
);
1118 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1119 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1122 // Do something about metrics here
1125 if (externalLeading
) (*externalLeading
) = 0; // ??
1127 g_object_unref( G_OBJECT( layout
) );
1129 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1131 int direction
, ascent
, descent2
;
1132 XCharStruct overall
;
1133 int slen
= string
.length();
1135 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1136 &direction
, &ascent
, &descent2
, &overall
);
1139 *x
= (overall
.width
);
1141 *y
= (ascent
+ descent2
);
1143 *descent
= descent2
;
1144 if (externalLeading
)
1145 *externalLeading
= 0;
1149 // ----------------------------------------------------------------------------
1151 // ----------------------------------------------------------------------------
1153 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1159 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1160 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1165 GetSize( &width
, &height
);
1167 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1168 m_clearRegion
.Clear();
1169 m_clearRegion
.Union( 0, 0, width
, height
);
1175 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1176 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1181 GetSize( &width
, &height
);
1183 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1184 m_updateRegion
.Clear();
1185 m_updateRegion
.Union( 0, 0, width
, height
);
1189 void wxWindowX11::Update()
1193 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1194 // Send nc paint events.
1195 SendNcPaintEvents();
1198 if (!m_updateRegion
.IsEmpty())
1200 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1201 // Actually send erase events.
1204 // Actually send paint events.
1209 void wxWindowX11::SendEraseEvents()
1211 if (m_clearRegion
.IsEmpty()) return;
1213 wxClientDC
dc( (wxWindow
*)this );
1214 dc
.SetDeviceClippingRegion( m_clearRegion
);
1216 wxEraseEvent
erase_event( GetId(), &dc
);
1217 erase_event
.SetEventObject( this );
1219 if (!HandleWindowEvent(erase_event
) )
1221 Display
*xdisplay
= wxGlobalDisplay();
1222 Window xwindow
= (Window
) GetClientAreaWindow();
1223 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1225 wxRegionIterator
upd( m_clearRegion
);
1228 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1229 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1234 m_clearRegion
.Clear();
1237 void wxWindowX11::SendPaintEvents()
1239 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1241 m_clipPaintRegion
= true;
1243 wxPaintEvent
paint_event( GetId() );
1244 paint_event
.SetEventObject( this );
1245 HandleWindowEvent( paint_event
);
1247 m_updateRegion
.Clear();
1249 m_clipPaintRegion
= false;
1252 void wxWindowX11::SendNcPaintEvents()
1254 wxWindow
*window
= (wxWindow
*) this;
1256 // All this for drawing the small square between the scrollbars.
1261 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1262 if (sb
&& sb
->IsShown())
1264 height
= sb
->GetSize().y
;
1265 y
= sb
->GetPosition().y
;
1267 sb
= window
->GetScrollbar( wxVERTICAL
);
1268 if (sb
&& sb
->IsShown())
1270 width
= sb
->GetSize().x
;
1271 x
= sb
->GetPosition().x
;
1273 Display
*xdisplay
= wxGlobalDisplay();
1274 Window xwindow
= (Window
) X11GetMainWindow();
1275 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1276 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1277 colour
.CalcPixel( (WXColormap
) cm
);
1279 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1281 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1285 wxNcPaintEvent
nc_paint_event( GetId() );
1286 nc_paint_event
.SetEventObject( this );
1287 HandleWindowEvent( nc_paint_event
);
1289 m_updateNcArea
= false;
1292 // ----------------------------------------------------------------------------
1294 // ----------------------------------------------------------------------------
1296 // Responds to colour changes: passes event on to children.
1297 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1299 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1302 // Only propagate to non-top-level windows
1303 wxWindow
*win
= node
->GetData();
1304 if ( win
->GetParent() )
1306 wxSysColourChangedEvent event2
;
1307 event
.SetEventObject(win
);
1308 win
->HandleWindowEvent(event2
);
1311 node
= node
->GetNext();
1315 // See handler for InFocus case in app.cpp for details.
1316 wxWindow
* g_GettingFocus
= NULL
;
1318 void wxWindowX11::OnInternalIdle()
1320 // Update invalidated regions.
1323 wxWindowBase::OnInternalIdle();
1325 // Set the input focus if couldn't do it before
1326 if (m_needsInputFocus
)
1330 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1331 printf(msg
.c_str());
1335 // If it couldn't set the focus now, there's
1336 // no point in trying again.
1337 m_needsInputFocus
= false;
1339 g_GettingFocus
= NULL
;
1342 // ----------------------------------------------------------------------------
1343 // function which maintain the global hash table mapping Widgets to wxWidgets
1344 // ----------------------------------------------------------------------------
1346 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1348 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1350 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1351 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1355 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1356 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1361 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1363 wxWindowHash::iterator i
= hash
->find(w
);
1364 return i
== hash
->end() ? NULL
: i
->second
;
1367 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1369 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1374 // ----------------------------------------------------------------------------
1376 // ----------------------------------------------------------------------------
1378 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1380 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1383 wxWindow
*wxGetWindowFromTable(Window w
)
1385 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1388 void wxDeleteWindowFromTable(Window w
)
1390 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1393 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1395 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1398 wxWindow
*wxGetClientWindowFromTable(Window w
)
1400 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1403 void wxDeleteClientWindowFromTable(Window w
)
1405 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1408 // ----------------------------------------------------------------------------
1409 // X11-specific accessors
1410 // ----------------------------------------------------------------------------
1412 WXWindow
wxWindowX11::X11GetMainWindow() const
1414 return m_mainWindow
;
1417 WXWindow
wxWindowX11::GetClientAreaWindow() const
1419 return m_clientWindow
;
1422 // ----------------------------------------------------------------------------
1423 // TranslateXXXEvent() functions
1424 // ----------------------------------------------------------------------------
1426 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
,
1428 Window
WXUNUSED(window
),
1431 switch (XEventGetType(xevent
))
1439 wxEventType eventType
= wxEVT_NULL
;
1441 if (XEventGetType(xevent
) == EnterNotify
)
1443 //if (local_event.xcrossing.mode!=NotifyNormal)
1444 // return ; // Ignore grab events
1445 eventType
= wxEVT_ENTER_WINDOW
;
1446 // canvas->GetEventHandler()->OnSetFocus();
1448 else if (XEventGetType(xevent
) == LeaveNotify
)
1450 //if (local_event.xcrossingr.mode!=NotifyNormal)
1451 // return ; // Ignore grab events
1452 eventType
= wxEVT_LEAVE_WINDOW
;
1453 // canvas->GetEventHandler()->OnKillFocus();
1455 else if (XEventGetType(xevent
) == MotionNotify
)
1457 eventType
= wxEVT_MOTION
;
1459 else if (XEventGetType(xevent
) == ButtonPress
)
1461 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1463 if (XButtonEventLChanged(xevent
))
1465 eventType
= wxEVT_LEFT_DOWN
;
1468 else if (XButtonEventMChanged(xevent
))
1470 eventType
= wxEVT_MIDDLE_DOWN
;
1473 else if (XButtonEventRChanged(xevent
))
1475 eventType
= wxEVT_RIGHT_DOWN
;
1478 else if ( xevent
->xbutton
.button
== Button4
||
1479 xevent
->xbutton
.button
== Button5
)
1481 // this is the same value as used under wxMSW
1482 static const int WHEEL_DELTA
= 120;
1484 eventType
= wxEVT_MOUSEWHEEL
;
1485 button
= xevent
->xbutton
.button
;
1487 wxevent
.m_linesPerAction
= 3;
1488 wxevent
.m_columnsPerAction
= 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
);