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 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
127 parent
->AddChild(this);
129 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
130 int xscreen
= DefaultScreen( xdisplay
);
131 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
132 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
134 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
135 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
137 m_foregroundColour
= *wxBLACK
;
138 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
140 Window xparent
= (Window
) parent
->GetClientAreaWindow();
142 // Add window's own scrollbars to main window, not to client window
143 if (parent
->GetInsertIntoMain())
145 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
146 xparent
= (Window
) parent
->GetMainWindow();
149 // Size (not including the border) must be nonzero (or a Value error results)!
150 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
158 if (pos2
.x
== wxDefaultCoord
)
160 if (pos2
.y
== wxDefaultCoord
)
163 #if wxUSE_TWO_WINDOWS
164 bool need_two_windows
=
165 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
167 bool need_two_windows
= false;
171 long xattributes
= 0;
173 XSetWindowAttributes xattributes
;
174 long xattributes_mask
= 0;
176 xattributes_mask
|= CWBackPixel
;
177 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
179 xattributes_mask
|= CWBorderPixel
;
180 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
182 xattributes_mask
|= CWEventMask
;
185 if (need_two_windows
)
188 long backColor
, foreColor
;
189 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
190 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
192 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
193 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
194 XSelectInput( xdisplay
, xwindow
,
195 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
196 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
197 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
198 PropertyChangeMask
);
202 xattributes
.event_mask
=
203 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
205 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
206 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
210 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
212 m_mainWindow
= (WXWindow
) xwindow
;
213 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
215 XMapWindow( xdisplay
, xwindow
);
218 xattributes
.event_mask
=
219 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
220 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
221 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
222 PropertyChangeMask
| VisibilityChangeMask
;
224 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
226 xattributes_mask
|= CWBitGravity
;
227 xattributes
.bit_gravity
= StaticGravity
;
231 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
238 else if (HasFlag( wxSIMPLE_BORDER
))
251 // Make again sure the size is nonzero.
258 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
259 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
261 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
262 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
263 XSelectInput( xdisplay
, xwindow
,
264 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
265 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
266 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
267 PropertyChangeMask
);
270 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
271 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
274 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
276 m_clientWindow
= (WXWindow
) xwindow
;
277 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
279 XMapWindow( xdisplay
, xwindow
);
283 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
285 long backColor
, foreColor
;
286 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
287 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
289 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
290 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
291 XSelectInput( xdisplay
, xwindow
,
292 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
293 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
294 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
295 PropertyChangeMask
);
298 xattributes
.event_mask
=
299 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
300 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
301 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
302 PropertyChangeMask
| VisibilityChangeMask
;
304 if (!HasFlag( wxFULL_REPAINT_ON_RESIZE
))
306 xattributes_mask
|= CWBitGravity
;
307 xattributes
.bit_gravity
= NorthWestGravity
;
310 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
311 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
314 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
316 m_mainWindow
= (WXWindow
) xwindow
;
317 m_clientWindow
= m_mainWindow
;
318 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
320 XMapWindow( xdisplay
, xwindow
);
323 // Is a subwindow, so map immediately
326 // Without this, the cursor may not be restored properly (e.g. in splitter
328 SetCursor(*wxSTANDARD_CURSOR
);
329 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
331 // Don't call this, it can have nasty repercussions for composite controls,
333 // SetSize(pos.x, pos.y, size.x, size.y);
339 wxWindowX11::~wxWindowX11()
343 if (g_captureWindow
== this)
344 g_captureWindow
= NULL
;
346 m_isBeingDeleted
= true;
350 if (m_clientWindow
!= m_mainWindow
)
352 // Destroy the cleint window
353 Window xwindow
= (Window
) m_clientWindow
;
354 wxDeleteClientWindowFromTable( xwindow
);
355 XDestroyWindow( wxGlobalDisplay(), xwindow
);
356 m_clientWindow
= NULL
;
359 // Destroy the window
362 Window xwindow
= (Window
) m_mainWindow
;
363 wxDeleteWindowFromTable( xwindow
);
364 XDestroyWindow( wxGlobalDisplay(), xwindow
);
369 // ---------------------------------------------------------------------------
371 // ---------------------------------------------------------------------------
373 void wxWindowX11::SetFocus()
375 Window xwindow
= (Window
) m_clientWindow
;
377 wxCHECK_RET( xwindow
, wxT("invalid window") );
379 // Don't assert; we might be trying to set the focus for a panel
380 // with only static controls, so the panel returns false from AcceptsFocus.
381 // The app should be not be expected to deal with this.
386 if (GetName() == "scrollBar")
393 if (wxWindowIsVisible(xwindow
))
395 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
396 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
397 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
398 m_needsInputFocus
= false;
402 m_needsInputFocus
= true;
406 // Get the window with the focus
407 wxWindow
*wxWindowBase::DoFindFocus()
409 Window xfocus
= (Window
) 0;
412 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
415 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
418 win
= wxGetClientWindowFromTable( xfocus
);
427 // Enabling/disabling handled by event loop, and not sending events
429 bool wxWindowX11::Enable(bool enable
)
431 if ( !wxWindowBase::Enable(enable
) )
437 bool wxWindowX11::Show(bool show
)
439 wxWindowBase::Show(show
);
441 Window xwindow
= (Window
) m_mainWindow
;
442 Display
*xdisp
= wxGlobalDisplay();
445 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
446 XMapWindow(xdisp
, xwindow
);
450 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
451 XUnmapWindow(xdisp
, xwindow
);
457 // Raise the window to the top of the Z order
458 void wxWindowX11::Raise()
461 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
464 // Lower the window to the bottom of the Z order
465 void wxWindowX11::Lower()
468 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
471 void wxWindowX11::SetLabel(const wxString
& WXUNUSED(label
))
476 wxString
wxWindowX11::GetLabel() const
479 return wxEmptyString
;
482 void wxWindowX11::DoCaptureMouse()
484 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
486 wxFAIL_MSG(wxT("Trying to capture before mouse released."));
497 Window xwindow
= (Window
) m_clientWindow
;
499 wxCHECK_RET( xwindow
, wxT("invalid window") );
501 g_captureWindow
= (wxWindow
*) this;
505 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
507 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
511 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
514 if (res
!= GrabSuccess
)
517 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
519 if (res
== GrabNotViewable
)
520 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
522 g_captureWindow
= NULL
;
526 m_winCaptured
= true;
530 void wxWindowX11::DoReleaseMouse()
532 g_captureWindow
= NULL
;
534 if ( !m_winCaptured
)
537 Window xwindow
= (Window
) m_clientWindow
;
541 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
544 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
546 m_winCaptured
= false;
549 bool wxWindowX11::SetFont(const wxFont
& font
)
551 if ( !wxWindowBase::SetFont(font
) )
560 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
562 if ( !wxWindowBase::SetCursor(cursor
) )
568 Window xwindow
= (Window
) m_clientWindow
;
570 wxCHECK_MSG( xwindow
, false, wxT("invalid window") );
572 wxCursor cursorToUse
;
574 cursorToUse
= m_cursor
;
576 cursorToUse
= *wxSTANDARD_CURSOR
;
578 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
580 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
585 // Coordinates relative to the window
586 void wxWindowX11::WarpPointer (int x
, int y
)
588 Window xwindow
= (Window
) m_clientWindow
;
590 wxCHECK_RET( xwindow
, wxT("invalid window") );
592 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
595 // Does a physical scroll
596 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
598 // No scrolling requested.
599 if ((dx
== 0) && (dy
== 0)) return;
601 if (!m_updateRegion
.IsEmpty())
603 m_updateRegion
.Offset( dx
, dy
);
607 GetSize( &cw
, &ch
); // GetClientSize() ??
608 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
611 if (!m_clearRegion
.IsEmpty())
613 m_clearRegion
.Offset( dx
, dy
);
617 GetSize( &cw
, &ch
); // GetClientSize() ??
618 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
621 Window xwindow
= (Window
) GetClientAreaWindow();
623 wxCHECK_RET( xwindow
, wxT("invalid window") );
625 Display
*xdisplay
= wxGlobalDisplay();
627 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
628 XSetGraphicsExposures( xdisplay
, xgc
, True
);
646 GetClientSize( &cw
, &ch
);
649 #if wxUSE_TWO_WINDOWS
650 wxPoint
offset( 0,0 );
652 wxPoint offset
= GetClientAreaOrigin();
657 int w
= cw
- abs(dx
);
658 int h
= ch
- abs(dy
);
660 if ((h
< 0) || (w
< 0))
667 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
668 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
669 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
670 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
675 if (dx
< 0) s_x
+= -dx
;
676 if (dy
< 0) s_y
+= -dy
;
677 if (dx
> 0) d_x
= dx
+ offset
.x
;
678 if (dy
> 0) d_y
= dy
+ offset
.y
;
680 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
682 // 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 );
684 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
686 m_updateRegion
.Union( rect
);
687 m_clearRegion
.Union( rect
);
690 XFreeGC( xdisplay
, xgc
);
692 // Move Clients, but not the scrollbars
693 // FIXME: There may be a better method to move a lot of Windows within X11
694 wxScrollBar
*sbH
= ((wxWindow
*) this)->GetScrollbar( wxHORIZONTAL
);
695 wxScrollBar
*sbV
= ((wxWindow
*) this)->GetScrollbar( wxVERTICAL
);
696 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
699 // Only propagate to non-top-level windows
700 wxWindow
*win
= node
->GetData();
701 if ( win
->GetParent() && win
!= sbH
&& win
!= sbV
)
703 wxPoint pos
= win
->GetPosition();
704 // Add the delta to the old Position
707 win
->SetPosition(pos
);
709 node
= node
->GetNext();
713 // ---------------------------------------------------------------------------
715 // ---------------------------------------------------------------------------
717 #if wxUSE_DRAG_AND_DROP
719 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
726 // Old style file-manager drag&drop
727 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
732 // ----------------------------------------------------------------------------
734 // ----------------------------------------------------------------------------
738 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
743 #endif // wxUSE_TOOLTIPS
745 // ---------------------------------------------------------------------------
746 // moving and resizing
747 // ---------------------------------------------------------------------------
749 bool wxWindowX11::PreResize()
755 void wxWindowX11::DoGetSize(int *x
, int *y
) const
757 Window xwindow
= (Window
) m_mainWindow
;
759 wxCHECK_RET( xwindow
, wxT("invalid window") );
761 //XSync(wxGlobalDisplay(), False);
763 XWindowAttributes attr
;
764 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
769 *x
= attr
.width
/* + 2*m_borderSize */ ;
770 *y
= attr
.height
/* + 2*m_borderSize */ ;
774 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
776 Window window
= (Window
) m_mainWindow
;
779 //XSync(wxGlobalDisplay(), False);
780 XWindowAttributes attr
;
781 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
789 // We may be faking the client origin. So a window that's really at (0, 30)
790 // may appear (to wxWin apps) to be at (0, 0).
793 wxPoint
pt(GetParent()->GetClientAreaOrigin());
801 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
803 Display
*display
= wxGlobalDisplay();
804 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
805 Window thisWindow
= (Window
) m_clientWindow
;
810 XTranslateCoordinates(display
, rootWindow
, thisWindow
,
811 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
815 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
817 Display
*display
= wxGlobalDisplay();
818 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
819 Window thisWindow
= (Window
) m_clientWindow
;
824 XTranslateCoordinates(display
, thisWindow
, rootWindow
,
825 xx
, yy
, x
? x
: &xx
, y
? y
: &yy
,
830 // Get size *available for subwindows* i.e. excluding menu bar etc.
831 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
833 Window window
= (Window
) m_mainWindow
;
837 XWindowAttributes attr
;
838 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
849 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
851 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
853 Window xwindow
= (Window
) m_mainWindow
;
855 wxCHECK_RET( xwindow
, wxT("invalid window") );
857 XWindowAttributes attr
;
858 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
859 wxCHECK_RET( status
, wxT("invalid window attributes") );
863 int new_w
= attr
.width
;
864 int new_h
= attr
.height
;
866 if (x
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
869 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
872 if (y
!= wxDefaultCoord
|| (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
875 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
878 if (width
!= wxDefaultCoord
)
884 if (height
!= wxDefaultCoord
)
891 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
894 void wxWindowX11::DoSetClientSize(int width
, int height
)
896 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
898 Window xwindow
= (Window
) m_mainWindow
;
900 wxCHECK_RET( xwindow
, wxT("invalid window") );
902 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
904 if (m_mainWindow
!= m_clientWindow
)
906 xwindow
= (Window
) m_clientWindow
;
908 wxWindow
*window
= (wxWindow
*) this;
909 wxRenderer
*renderer
= window
->GetRenderer();
912 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
913 width
-= border
.x
+ border
.width
;
914 height
-= border
.y
+ border
.height
;
917 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
921 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
923 Window xwindow
= (Window
) m_mainWindow
;
925 wxCHECK_RET( xwindow
, wxT("invalid window") );
929 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
930 if (m_mainWindow
!= m_clientWindow
)
932 xwindow
= (Window
) m_clientWindow
;
934 wxWindow
*window
= (wxWindow
*) this;
935 wxRenderer
*renderer
= window
->GetRenderer();
938 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
941 width
-= border
.x
+ border
.width
;
942 height
-= border
.y
+ border
.height
;
950 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
951 if (sb
&& sb
->IsShown())
953 wxSize size
= sb
->GetSize();
956 sb
= window
->GetScrollbar( wxVERTICAL
);
957 if (sb
&& sb
->IsShown())
959 wxSize size
= sb
->GetSize();
963 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
968 XWindowChanges windowChanges
;
971 windowChanges
.width
= width
;
972 windowChanges
.height
= height
;
973 windowChanges
.stack_mode
= 0;
974 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
976 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
981 void wxWindowX11::DoSetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
989 XSizeHints sizeHints
;
992 if (minW
> -1 && minH
> -1)
994 sizeHints
.flags
|= PMinSize
;
995 sizeHints
.min_width
= minW
;
996 sizeHints
.min_height
= minH
;
998 if (maxW
> -1 && maxH
> -1)
1000 sizeHints
.flags
|= PMaxSize
;
1001 sizeHints
.max_width
= maxW
;
1002 sizeHints
.max_height
= maxH
;
1004 if (incW
> -1 && incH
> -1)
1006 sizeHints
.flags
|= PResizeInc
;
1007 sizeHints
.width_inc
= incW
;
1008 sizeHints
.height_inc
= incH
;
1011 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
1015 // ---------------------------------------------------------------------------
1017 // ---------------------------------------------------------------------------
1019 int wxWindowX11::GetCharHeight() const
1021 wxFont
font(GetFont());
1022 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1025 // There should be an easier way.
1026 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1027 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1028 pango_layout_set_text(layout
, "H", 1 );
1030 pango_layout_get_pixel_size(layout
, &w
, &h
);
1031 g_object_unref( G_OBJECT( layout
) );
1035 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1037 int direction
, ascent
, descent
;
1038 XCharStruct overall
;
1039 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1040 &descent
, &overall
);
1042 // return (overall.ascent + overall.descent);
1043 return (ascent
+ descent
);
1047 int wxWindowX11::GetCharWidth() const
1049 wxFont
font(GetFont());
1050 wxCHECK_MSG( font
.Ok(), 0, wxT("valid window font needed") );
1053 // There should be an easier way.
1054 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1055 pango_layout_set_font_description( layout
, font
.GetNativeFontInfo()->description
);
1056 pango_layout_set_text(layout
, "H", 1 );
1058 pango_layout_get_pixel_size(layout
, &w
, &h
);
1059 g_object_unref( G_OBJECT( layout
) );
1063 WXFontStructPtr pFontStruct
= font
.GetFontStruct(1.0, wxGlobalDisplay());
1065 int direction
, ascent
, descent
;
1066 XCharStruct overall
;
1067 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1068 &descent
, &overall
);
1070 return overall
.width
;
1074 void wxWindowX11::GetTextExtent(const wxString
& string
,
1076 int *descent
, int *externalLeading
,
1077 const wxFont
*theFont
) const
1079 wxFont fontToUse
= GetFont();
1080 if (theFont
) fontToUse
= *theFont
;
1082 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1092 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1094 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1095 pango_layout_set_font_description(layout
, desc
);
1097 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1098 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1100 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1103 PangoRectangle rect
;
1104 pango_layout_line_get_extents(line
, NULL
, &rect
);
1106 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1107 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1110 // Do something about metrics here
1113 if (externalLeading
) (*externalLeading
) = 0; // ??
1115 g_object_unref( G_OBJECT( layout
) );
1117 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1119 int direction
, ascent
, descent2
;
1120 XCharStruct overall
;
1121 int slen
= string
.length();
1123 XTextExtents((XFontStruct
*) pFontStruct
, (const char*) string
.c_str(), slen
,
1124 &direction
, &ascent
, &descent2
, &overall
);
1127 *x
= (overall
.width
);
1129 *y
= (ascent
+ descent2
);
1131 *descent
= descent2
;
1132 if (externalLeading
)
1133 *externalLeading
= 0;
1137 // ----------------------------------------------------------------------------
1139 // ----------------------------------------------------------------------------
1141 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1147 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1148 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1153 GetSize( &width
, &height
);
1155 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1156 m_clearRegion
.Clear();
1157 m_clearRegion
.Union( 0, 0, width
, height
);
1163 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1164 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1169 GetSize( &width
, &height
);
1171 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1172 m_updateRegion
.Clear();
1173 m_updateRegion
.Union( 0, 0, width
, height
);
1177 void wxWindowX11::Update()
1181 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1182 // Send nc paint events.
1183 SendNcPaintEvents();
1186 if (!m_updateRegion
.IsEmpty())
1188 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1189 // Actually send erase events.
1192 // Actually send paint events.
1197 void wxWindowX11::SendEraseEvents()
1199 if (m_clearRegion
.IsEmpty()) return;
1201 wxClientDC
dc( (wxWindow
*)this );
1202 dc
.SetClippingRegion( m_clearRegion
);
1204 wxEraseEvent
erase_event( GetId(), &dc
);
1205 erase_event
.SetEventObject( this );
1207 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1209 Display
*xdisplay
= wxGlobalDisplay();
1210 Window xwindow
= (Window
) GetClientAreaWindow();
1211 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1213 wxRegionIterator
upd( m_clearRegion
);
1216 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1217 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1222 m_clearRegion
.Clear();
1225 void wxWindowX11::SendPaintEvents()
1227 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1229 m_clipPaintRegion
= true;
1231 wxPaintEvent
paint_event( GetId() );
1232 paint_event
.SetEventObject( this );
1233 GetEventHandler()->ProcessEvent( paint_event
);
1235 m_updateRegion
.Clear();
1237 m_clipPaintRegion
= false;
1240 void wxWindowX11::SendNcPaintEvents()
1242 wxWindow
*window
= (wxWindow
*) this;
1244 // All this for drawing the small square between the scrollbars.
1249 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1250 if (sb
&& sb
->IsShown())
1252 height
= sb
->GetSize().y
;
1253 y
= sb
->GetPosition().y
;
1255 sb
= window
->GetScrollbar( wxVERTICAL
);
1256 if (sb
&& sb
->IsShown())
1258 width
= sb
->GetSize().x
;
1259 x
= sb
->GetPosition().x
;
1261 Display
*xdisplay
= wxGlobalDisplay();
1262 Window xwindow
= (Window
) GetMainWindow();
1263 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1264 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1265 colour
.CalcPixel( (WXColormap
) cm
);
1267 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1269 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1273 wxNcPaintEvent
nc_paint_event( GetId() );
1274 nc_paint_event
.SetEventObject( this );
1275 GetEventHandler()->ProcessEvent( nc_paint_event
);
1277 m_updateNcArea
= false;
1280 // ----------------------------------------------------------------------------
1282 // ----------------------------------------------------------------------------
1284 // Responds to colour changes: passes event on to children.
1285 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1287 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1290 // Only propagate to non-top-level windows
1291 wxWindow
*win
= node
->GetData();
1292 if ( win
->GetParent() )
1294 wxSysColourChangedEvent event2
;
1295 event
.SetEventObject(win
);
1296 win
->GetEventHandler()->ProcessEvent(event2
);
1299 node
= node
->GetNext();
1303 // See handler for InFocus case in app.cpp for details.
1304 wxWindow
* g_GettingFocus
= NULL
;
1306 void wxWindowX11::OnInternalIdle()
1308 // Update invalidated regions.
1311 // This calls the UI-update mechanism (querying windows for
1312 // menu/toolbar/control state information)
1313 if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this))
1314 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1316 // Set the input focus if couldn't do it before
1317 if (m_needsInputFocus
)
1321 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1322 printf(msg
.c_str());
1326 // If it couldn't set the focus now, there's
1327 // no point in trying again.
1328 m_needsInputFocus
= false;
1330 g_GettingFocus
= NULL
;
1333 // ----------------------------------------------------------------------------
1334 // function which maintain the global hash table mapping Widgets to wxWidgets
1335 // ----------------------------------------------------------------------------
1337 static bool DoAddWindowToTable(wxWindowHash
*hash
, Window w
, wxWindow
*win
)
1339 if ( !hash
->insert(wxWindowHash::value_type(w
, win
)).second
)
1341 wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
1342 (unsigned int)w
, win
->GetClassInfo()->GetClassName());
1346 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1347 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1352 static inline wxWindow
*DoGetWindowFromTable(wxWindowHash
*hash
, Window w
)
1354 wxWindowHash::iterator i
= hash
->find(w
);
1355 return i
== hash
->end() ? NULL
: i
->second
;
1358 static inline void DoDeleteWindowFromTable(wxWindowHash
*hash
, Window w
)
1360 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w
);
1365 // ----------------------------------------------------------------------------
1367 // ----------------------------------------------------------------------------
1369 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1371 return DoAddWindowToTable(wxWidgetHashTable
, w
, win
);
1374 wxWindow
*wxGetWindowFromTable(Window w
)
1376 return DoGetWindowFromTable(wxWidgetHashTable
, w
);
1379 void wxDeleteWindowFromTable(Window w
)
1381 DoDeleteWindowFromTable(wxWidgetHashTable
, w
);
1384 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1386 return DoAddWindowToTable(wxClientWidgetHashTable
, w
, win
);
1389 wxWindow
*wxGetClientWindowFromTable(Window w
)
1391 return DoGetWindowFromTable(wxClientWidgetHashTable
, w
);
1394 void wxDeleteClientWindowFromTable(Window w
)
1396 DoDeleteWindowFromTable(wxClientWidgetHashTable
, w
);
1399 // ----------------------------------------------------------------------------
1400 // X11-specific accessors
1401 // ----------------------------------------------------------------------------
1403 WXWindow
wxWindowX11::GetMainWindow() const
1405 return m_mainWindow
;
1408 WXWindow
wxWindowX11::GetClientAreaWindow() const
1410 return m_clientWindow
;
1413 // ----------------------------------------------------------------------------
1414 // TranslateXXXEvent() functions
1415 // ----------------------------------------------------------------------------
1417 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1419 switch (XEventGetType(xevent
))
1427 wxEventType eventType
= wxEVT_NULL
;
1429 if (XEventGetType(xevent
) == EnterNotify
)
1431 //if (local_event.xcrossing.mode!=NotifyNormal)
1432 // return ; // Ignore grab events
1433 eventType
= wxEVT_ENTER_WINDOW
;
1434 // canvas->GetEventHandler()->OnSetFocus();
1436 else if (XEventGetType(xevent
) == LeaveNotify
)
1438 //if (local_event.xcrossingr.mode!=NotifyNormal)
1439 // return ; // Ignore grab events
1440 eventType
= wxEVT_LEAVE_WINDOW
;
1441 // canvas->GetEventHandler()->OnKillFocus();
1443 else if (XEventGetType(xevent
) == MotionNotify
)
1445 eventType
= wxEVT_MOTION
;
1447 else if (XEventGetType(xevent
) == ButtonPress
)
1449 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1451 if (XButtonEventLChanged(xevent
))
1453 eventType
= wxEVT_LEFT_DOWN
;
1456 else if (XButtonEventMChanged(xevent
))
1458 eventType
= wxEVT_MIDDLE_DOWN
;
1461 else if (XButtonEventRChanged(xevent
))
1463 eventType
= wxEVT_RIGHT_DOWN
;
1466 else if ( xevent
->xbutton
.button
== Button4
||
1467 xevent
->xbutton
.button
== Button5
)
1469 // this is the same value as used under wxMSW
1470 static const int WHEEL_DELTA
= 120;
1472 eventType
= wxEVT_MOUSEWHEEL
;
1473 button
= xevent
->xbutton
.button
;
1475 wxevent
.m_linesPerAction
= 3;
1476 wxevent
.m_wheelDelta
= WHEEL_DELTA
;
1478 // Button 4 means mousewheel up, 5 means down
1479 wxevent
.m_wheelRotation
= button
== Button4
? WHEEL_DELTA
1483 // check for a double click
1484 // TODO: where can we get this value from?
1485 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1486 long dclickTime
= 200;
1487 long ts
= wxevent
.GetTimestamp();
1489 int buttonLast
= win
->GetLastClickedButton();
1490 long lastTS
= win
->GetLastClickTime();
1491 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1494 win
->SetLastClick(0, ts
);
1495 if ( eventType
== wxEVT_LEFT_DOWN
)
1496 eventType
= wxEVT_LEFT_DCLICK
;
1497 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1498 eventType
= wxEVT_MIDDLE_DCLICK
;
1499 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1500 eventType
= wxEVT_RIGHT_DCLICK
;
1504 // not fast enough or different button
1505 win
->SetLastClick(button
, ts
);
1508 else if (XEventGetType(xevent
) == ButtonRelease
)
1510 if (XButtonEventLChanged(xevent
))
1512 eventType
= wxEVT_LEFT_UP
;
1514 else if (XButtonEventMChanged(xevent
))
1516 eventType
= wxEVT_MIDDLE_UP
;
1518 else if (XButtonEventRChanged(xevent
))
1520 eventType
= wxEVT_RIGHT_UP
;
1529 wxevent
.SetEventType(eventType
);
1531 wxevent
.m_x
= XButtonEventGetX(xevent
);
1532 wxevent
.m_y
= XButtonEventGetY(xevent
);
1534 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1535 || (XButtonEventLIsDown(xevent
)
1536 && (eventType
!= wxEVT_LEFT_UP
)));
1537 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1538 || (XButtonEventMIsDown(xevent
)
1539 && (eventType
!= wxEVT_MIDDLE_UP
)));
1540 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1541 || (XButtonEventRIsDown (xevent
)
1542 && (eventType
!= wxEVT_RIGHT_UP
)));
1544 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1545 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1546 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1547 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1549 wxevent
.SetId(win
->GetId());
1550 wxevent
.SetEventObject(win
);
1558 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1560 switch (XEventGetType(xevent
))
1568 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1569 int id
= wxCharCodeXToWX (keySym
);
1570 // id may be WXK_xxx code - these are outside ASCII range, so we
1571 // can't just use toupper() on id.
1572 // Only change this if we want the raw key that was pressed,
1573 // and don't change it if we want an ASCII value.
1574 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1576 id
= id
+ 'A' - 'a';
1579 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1580 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1581 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1582 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1583 wxevent
.SetEventObject(win
);
1584 wxevent
.m_keyCode
= id
;
1585 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1587 wxevent
.m_x
= XKeyEventGetX(xevent
);
1588 wxevent
.m_y
= XKeyEventGetY(xevent
);
1598 // ----------------------------------------------------------------------------
1600 // ----------------------------------------------------------------------------
1602 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1604 wxWindowBase::SetBackgroundColour(col
);
1606 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1607 int xscreen
= DefaultScreen( xdisplay
);
1608 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1610 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1612 // We don't set the background colour as we paint
1613 // the background ourselves.
1614 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1619 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1621 if ( !wxWindowBase::SetForegroundColour(col
) )
1627 // ----------------------------------------------------------------------------
1629 // ----------------------------------------------------------------------------
1631 wxWindow
*wxGetActiveWindow()
1634 wxFAIL_MSG(wxT("Not implemented"));
1639 wxWindow
*wxWindowBase::GetCapture()
1641 return (wxWindow
*)g_captureWindow
;
1645 // Find the wxWindow at the current mouse position, returning the mouse
1647 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1649 return wxFindWindowAtPoint(wxGetMousePosition());
1652 void wxGetMouseState(int& rootX
, int& rootY
, unsigned& maskReturn
)
1659 Display
*display
= wxGlobalDisplay();
1660 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1661 Window rootReturn
, childReturn
;
1664 XQueryPointer (display
,
1668 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1672 // Get the current mouse position.
1673 wxPoint
wxGetMousePosition()
1678 wxGetMouseState(x
, y
, mask
);
1679 return wxPoint(x
, y
);
1682 wxMouseState
wxGetMouseState()
1688 wxGetMouseState(x
, y
, mask
);
1693 ms
.SetLeftDown(mask
& Button1Mask
);
1694 ms
.SetMiddleDown(mask
& Button2Mask
);
1695 ms
.SetRightDown(mask
& Button3Mask
);
1697 ms
.SetControlDown(mask
& ControlMask
);
1698 ms
.SetShiftDown(mask
& ShiftMask
);
1699 ms
.SetAltDown(mask
& Mod3Mask
);
1700 ms
.SetMetaDown(mask
& Mod1Mask
);
1706 // ----------------------------------------------------------------------------
1707 // wxNoOptimize: switch off size optimization
1708 // ----------------------------------------------------------------------------
1710 int wxNoOptimize::ms_count
= 0;
1713 // ----------------------------------------------------------------------------
1715 // ----------------------------------------------------------------------------
1717 class wxWinModule
: public wxModule
1722 // we must be cleaned up before the display is closed
1723 AddDependency(wxClassInfo::FindClass(_T("wxX11DisplayModule")));
1726 virtual bool OnInit();
1727 virtual void OnExit();
1730 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1733 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1735 bool wxWinModule::OnInit()
1737 Display
*xdisplay
= wxGlobalDisplay();
1738 int xscreen
= DefaultScreen( xdisplay
);
1739 Window xroot
= RootWindow( xdisplay
, xscreen
);
1740 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1741 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1746 void wxWinModule::OnExit()
1748 Display
*xdisplay
= wxGlobalDisplay();
1749 XFreeGC( xdisplay
, g_eraseGC
);