1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
27 #include "wx/dcclient.h"
31 #include "wx/layout.h"
32 #include "wx/dialog.h"
33 #include "wx/listbox.h"
34 #include "wx/button.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
38 #include "wx/scrolwin.h"
39 #include "wx/module.h"
40 #include "wx/menuitem.h"
43 #if wxUSE_DRAG_AND_DROP
47 #include "wx/x11/private.h"
48 #include "X11/Xutil.h"
51 // For wxGetLocalTime, used by XButtonEventGetTime
57 // ----------------------------------------------------------------------------
58 // global variables for this module
59 // ----------------------------------------------------------------------------
61 extern wxHashTable
*wxWidgetHashTable
;
62 static wxWindow
* g_captureWindow
= NULL
;
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
69 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
70 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
78 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
79 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
82 // ============================================================================
84 // ============================================================================
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 void wxWindowX11::Init()
96 // generic initializations first
100 m_mainWidget
= (WXWindow
) 0;
101 m_winCaptured
= FALSE
;
102 m_needsInputFocus
= FALSE
;
104 m_isBeingDeleted
= FALSE
;
109 // real construction (Init() must have been called before!)
110 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
114 const wxString
& name
)
116 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
118 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
120 parent
->AddChild(this);
122 int w
= size
.GetWidth();
123 int h
= size
.GetHeight();
131 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
132 int xscreen
= DefaultScreen( xdisplay
);
133 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
134 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
136 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
137 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
139 m_foregroundColour
= *wxBLACK
;
140 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
142 Window xparent
= (Window
) parent
->GetMainWindow();
157 XSetWindowAttributes xattributes
;
159 long xattributes_mask
=
160 CWBorderPixel
| CWBackPixel
;
162 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
163 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
165 xattributes_mask
|= CWEventMask
;
166 xattributes
.event_mask
=
167 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
168 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
169 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
170 PropertyChangeMask
| VisibilityChangeMask
;
172 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
174 xattributes_mask
|= CWBitGravity
;
175 xattributes
.bit_gravity
= StaticGravity
;
178 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
179 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
182 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
184 long backColor
, foreColor
;
185 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
186 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
188 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
189 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
190 XSelectInput( xdisplay
, xwindow
,
191 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
192 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
193 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
194 PropertyChangeMask
);
197 m_mainWidget
= (WXWindow
) xwindow
;
199 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
201 // Is a subwindow, so map immediately
203 XMapWindow( xdisplay
, xwindow
);
205 // Without this, the cursor may not be restored properly (e.g. in splitter
207 SetCursor(*wxSTANDARD_CURSOR
);
208 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
210 // Set background to None which will prevent X11 from clearing the
211 // background comletely.
212 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
214 // Don't call this, it can have nasty repercussions for composite controls,
216 // SetSize(pos.x, pos.y, size.x, size.y);
222 wxWindowX11::~wxWindowX11()
224 if (g_captureWindow
== this)
225 g_captureWindow
= NULL
;
227 m_isBeingDeleted
= TRUE
;
229 // X11-specific actions first
230 Window xwindow
= (Window
) m_mainWidget
;
233 m_parent
->RemoveChild( this );
237 // Destroy the window
240 XSelectInput( wxGlobalDisplay(), xwindow
, NoEventMask
);
241 wxDeleteWindowFromTable( xwindow
);
242 XDestroyWindow( wxGlobalDisplay(), xwindow
);
247 // ---------------------------------------------------------------------------
249 // ---------------------------------------------------------------------------
251 void wxWindowX11::SetFocus()
253 Window xwindow
= (Window
) GetMainWindow();
255 wxCHECK_RET( xwindow
, wxT("invalid window") );
257 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
260 if (GetName() == "scrollBar")
267 if (wxWindowIsVisible(xwindow
))
269 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
270 m_needsInputFocus
= FALSE
;
274 m_needsInputFocus
= TRUE
;
278 // Get the window with the focus
279 wxWindow
*wxWindowBase::FindFocus()
281 Window xfocus
= (Window
) 0;
284 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
287 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
295 wxWindow
*wxWindowX11::GetFocusWidget()
297 wxWindow
*win
= (wxWindow
*) this;
298 while (!win
->IsTopLevel())
300 win
= win
->GetParent();
302 return (wxWindow
*) NULL
;
308 // Enabling/disabling handled by event loop, and not sending events
310 bool wxWindowX11::Enable(bool enable
)
312 if ( !wxWindowBase::Enable(enable
) )
318 bool wxWindowX11::Show(bool show
)
320 wxWindowBase::Show(show
);
322 Window xwin
= (Window
) GetXWindow();
323 Display
*xdisp
= (Display
*) GetXDisplay();
326 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
327 XMapWindow(xdisp
, xwin
);
332 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
333 XUnmapWindow(xdisp
, xwin
);
339 // Raise the window to the top of the Z order
340 void wxWindowX11::Raise()
343 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
346 // Lower the window to the bottom of the Z order
347 void wxWindowX11::Lower()
350 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
353 void wxWindowX11::DoCaptureMouse()
355 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
357 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
368 Window xwindow
= (Window
) GetMainWindow();
370 wxCHECK_RET( xwindow
, wxT("invalid window") );
372 g_captureWindow
= (wxWindow
*) this;
376 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
378 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
382 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
385 if (res
!= GrabSuccess
)
388 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
390 if (res
== GrabNotViewable
)
392 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
394 g_captureWindow
= NULL
;
398 // wxLogDebug("Grabbed pointer in %s", GetName().c_str() );
401 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
402 (Window
) GetMainWindow(),
404 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
410 if (res
!= GrabSuccess
)
412 wxLogDebug("Failed to grab mouse buttons.");
413 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
419 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
420 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
426 if (res
!= GrabSuccess
)
428 wxLogDebug("Failed to grab keyboard.");
429 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
430 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
431 (Window
) GetMainWindow());
436 m_winCaptured
= TRUE
;
440 void wxWindowX11::DoReleaseMouse()
442 g_captureWindow
= NULL
;
444 if ( !m_winCaptured
)
447 Window xwindow
= (Window
) GetMainWindow();
451 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
453 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
454 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
458 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
460 m_winCaptured
= FALSE
;
463 bool wxWindowX11::SetFont(const wxFont
& font
)
465 if ( !wxWindowBase::SetFont(font
) )
474 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
476 if ( !wxWindowBase::SetCursor(cursor
) )
482 Window xwindow
= (Window
) GetMainWindow();
484 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
486 wxCursor cursorToUse
;
488 cursorToUse
= m_cursor
;
490 cursorToUse
= *wxSTANDARD_CURSOR
;
492 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
494 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
499 // Coordinates relative to the window
500 void wxWindowX11::WarpPointer (int x
, int y
)
502 Window xwindow
= (Window
) GetMainWindow();
504 wxCHECK_RET( xwindow
, wxT("invalid window") );
506 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
509 // Does a physical scroll
510 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
512 // No scrolling requested.
513 if ((dx
== 0) && (dy
== 0)) return;
515 if (!m_updateRegion
.IsEmpty())
517 m_updateRegion
.Offset( dx
, dy
);
521 GetSize( &cw
, &ch
); // GetClientSize() ??
522 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
525 if (!m_clearRegion
.IsEmpty())
527 m_clearRegion
.Offset( dx
, dy
);
531 GetSize( &cw
, &ch
); // GetClientSize() ??
532 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
535 Window xwindow
= (Window
) GetMainWindow();
537 wxCHECK_RET( xwindow
, wxT("invalid window") );
539 Display
*xdisplay
= wxGlobalDisplay();
541 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
542 XSetGraphicsExposures( xdisplay
, xgc
, True
);
560 GetClientSize( &cw
, &ch
);
563 wxPoint offset
= GetClientAreaOrigin();
567 int w
= cw
- abs(dx
);
568 int h
= ch
- abs(dy
);
570 if ((h
< 0) || (w
< 0))
577 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
578 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
579 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
580 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
585 if (dx
< 0) s_x
+= -dx
;
586 if (dy
< 0) s_y
+= -dy
;
587 if (dx
> 0) d_x
= dx
+ offset
.x
;
588 if (dy
> 0) d_y
= dy
+ offset
.y
;
590 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
592 // 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 );
594 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
596 m_updateRegion
.Union( rect
);
597 m_clearRegion
.Union( rect
);
600 XFreeGC( xdisplay
, xgc
);
603 // ---------------------------------------------------------------------------
605 // ---------------------------------------------------------------------------
607 #if wxUSE_DRAG_AND_DROP
609 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
616 // Old style file-manager drag&drop
617 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
628 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
633 #endif // wxUSE_TOOLTIPS
635 // ---------------------------------------------------------------------------
636 // moving and resizing
637 // ---------------------------------------------------------------------------
639 bool wxWindowX11::PreResize()
645 void wxWindowX11::DoGetSize(int *x
, int *y
) const
647 Window xwindow
= (Window
) GetMainWindow();
649 wxCHECK_RET( xwindow
, wxT("invalid window") );
651 //XSync(wxGlobalDisplay(), False);
653 XWindowAttributes attr
;
654 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
659 *x
= attr
.width
/* + 2*m_borderSize */ ;
660 *y
= attr
.height
/* + 2*m_borderSize */ ;
664 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
666 Window window
= (Window
) m_mainWidget
;
669 //XSync(wxGlobalDisplay(), False);
670 XWindowAttributes attr
;
671 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
679 // We may be faking the client origin. So a window that's really at (0, 30)
680 // may appear (to wxWin apps) to be at (0, 0).
683 wxPoint
pt(GetParent()->GetClientAreaOrigin());
691 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
693 Display
*display
= wxGlobalDisplay();
694 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
695 Window thisWindow
= (Window
) m_mainWidget
;
700 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
703 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
705 Display
*display
= wxGlobalDisplay();
706 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
707 Window thisWindow
= (Window
) m_mainWidget
;
712 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
716 // Get size *available for subwindows* i.e. excluding menu bar etc.
717 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
719 Window window
= (Window
) m_mainWidget
;
723 //XSync(wxGlobalDisplay(), False); // Is this really a good idea?
724 XWindowAttributes attr
;
725 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
736 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
738 Window xwindow
= (Window
) GetMainWindow();
740 wxCHECK_RET( xwindow
, wxT("invalid window") );
742 XWindowAttributes attr
;
743 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
744 wxCHECK_RET( status
, wxT("invalid window attributes") );
748 int new_w
= attr
.width
;
749 int new_h
= attr
.height
;
752 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
755 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
758 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
761 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
777 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
780 void wxWindowX11::DoSetClientSize(int width
, int height
)
782 Window xwindow
= (Window
) GetMainWindow();
784 wxCHECK_RET( xwindow
, wxT("invalid window") );
788 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
792 XWindowAttributes attr
;
793 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
794 wxCHECK_RET( status
, wxT("invalid window attributes") );
798 int new_w
= attr
.width
;
799 int new_h
= attr
.height
;
807 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
812 // For implementation purposes - sometimes decorations make the client area
814 wxPoint
wxWindowX11::GetClientAreaOrigin() const
816 return wxPoint(0, 0);
819 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
827 XSizeHints sizeHints
;
830 if (minW
> -1 && minH
> -1)
832 sizeHints
.flags
|= PMinSize
;
833 sizeHints
.min_width
= minW
;
834 sizeHints
.min_height
= minH
;
836 if (maxW
> -1 && maxH
> -1)
838 sizeHints
.flags
|= PMaxSize
;
839 sizeHints
.max_width
= maxW
;
840 sizeHints
.max_height
= maxH
;
842 if (incW
> -1 && incH
> -1)
844 sizeHints
.flags
|= PResizeInc
;
845 sizeHints
.width_inc
= incW
;
846 sizeHints
.height_inc
= incH
;
849 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
853 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
855 Window xwindow
= (Window
) GetMainWindow();
857 wxCHECK_RET( xwindow
, wxT("invalid window") );
861 XWindowAttributes attr
;
862 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
863 wxCHECK_RET( status
, wxT("invalid window attributes") );
865 if (attr
.width
== width
&& attr
.height
== height
)
867 XMoveWindow( wxGlobalDisplay(), xwindow
, x
, y
);
871 if (attr
.x
== x
&& attr
.y
== y
)
873 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
877 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
881 XWindowChanges windowChanges
;
884 windowChanges
.width
= width
;
885 windowChanges
.height
= height
;
886 windowChanges
.stack_mode
= 0;
887 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
889 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
894 // ---------------------------------------------------------------------------
896 // ---------------------------------------------------------------------------
898 int wxWindowX11::GetCharHeight() const
900 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
902 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
904 int direction
, ascent
, descent
;
906 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
909 // return (overall.ascent + overall.descent);
910 return (ascent
+ descent
);
913 int wxWindowX11::GetCharWidth() const
915 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
917 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
919 int direction
, ascent
, descent
;
921 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
924 return overall
.width
;
927 void wxWindowX11::GetTextExtent(const wxString
& string
,
929 int *descent
, int *externalLeading
,
930 const wxFont
*theFont
) const
932 wxFont fontToUse
= m_font
;
933 if (theFont
) fontToUse
= *theFont
;
935 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
937 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
939 int direction
, ascent
, descent2
;
941 int slen
= string
.Len();
945 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
946 &ascent
, &descent2
, &overall
);
949 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
950 &direction
, &ascent
, &descent2
, &overall
);
953 *x
= (overall
.width
);
955 *y
= (ascent
+ descent2
);
959 *externalLeading
= 0;
963 // ----------------------------------------------------------------------------
965 // ----------------------------------------------------------------------------
967 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
973 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
974 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
979 GetSize( &width
, &height
);
981 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
982 m_clearRegion
.Clear();
983 m_clearRegion
.Union( 0, 0, width
, height
);
989 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
990 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
995 GetSize( &width
, &height
);
997 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
998 m_updateRegion
.Clear();
999 m_updateRegion
.Union( 0, 0, width
, height
);
1003 void wxWindowX11::Update()
1005 if (!m_updateRegion
.IsEmpty())
1007 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1008 // Actually send erase events.
1011 // Actually send paint events.
1016 void wxWindowX11::Clear()
1018 wxClientDC
dc((wxWindow
*) this);
1019 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1020 dc
.SetBackground(brush
);
1024 void wxWindowX11::SendEraseEvents()
1026 if (m_clearRegion
.IsEmpty()) return;
1028 wxWindowDC
dc( (wxWindow
*)this );
1029 dc
.SetClippingRegion( m_clearRegion
);
1031 wxEraseEvent
erase_event( GetId(), &dc
);
1032 erase_event
.SetEventObject( this );
1034 if (!GetEventHandler()->ProcessEvent(erase_event
))
1036 Window xwindow
= (Window
) GetMainWindow();
1037 Display
*xdisplay
= wxGlobalDisplay();
1038 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1039 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1040 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1041 wxRegionIterator
upd( m_clearRegion
);
1044 XFillRectangle( xdisplay
, xwindow
, xgc
,
1045 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1048 XFreeGC( xdisplay
, xgc
);
1051 m_clearRegion
.Clear();
1054 void wxWindowX11::SendPaintEvents()
1056 m_clipPaintRegion
= TRUE
;
1058 wxNcPaintEvent
nc_paint_event( GetId() );
1059 nc_paint_event
.SetEventObject( this );
1060 GetEventHandler()->ProcessEvent( nc_paint_event
);
1062 wxPaintEvent
paint_event( GetId() );
1063 paint_event
.SetEventObject( this );
1064 GetEventHandler()->ProcessEvent( paint_event
);
1066 m_updateRegion
.Clear();
1068 m_clipPaintRegion
= FALSE
;
1071 // ----------------------------------------------------------------------------
1073 // ----------------------------------------------------------------------------
1075 // Responds to colour changes: passes event on to children.
1076 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1078 wxWindowList::Node
*node
= GetChildren().GetFirst();
1081 // Only propagate to non-top-level windows
1082 wxWindow
*win
= node
->GetData();
1083 if ( win
->GetParent() )
1085 wxSysColourChangedEvent event2
;
1086 event
.m_eventObject
= win
;
1087 win
->GetEventHandler()->ProcessEvent(event2
);
1090 node
= node
->GetNext();
1094 void wxWindowX11::OnInternalIdle()
1096 // Update invalidated regions.
1099 // This calls the UI-update mechanism (querying windows for
1100 // menu/toolbar/control state information)
1103 // Set the input focus if couldn't do it before
1104 if (m_needsInputFocus
)
1110 // ----------------------------------------------------------------------------
1111 // function which maintain the global hash table mapping Widgets to wxWindows
1112 // ----------------------------------------------------------------------------
1114 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1116 wxWindow
*oldItem
= NULL
;
1117 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1119 wxLogDebug("Widget table clash: new widget is %ld, %s",
1120 (long)w
, win
->GetClassInfo()->GetClassName());
1124 wxWidgetHashTable
->Put((long) w
, win
);
1126 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1127 w
, win
, win
->GetClassInfo()->GetClassName());
1132 wxWindow
*wxGetWindowFromTable(Window w
)
1134 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1137 void wxDeleteWindowFromTable(Window w
)
1139 wxWidgetHashTable
->Delete((long)w
);
1142 // ----------------------------------------------------------------------------
1143 // add/remove window from the table
1144 // ----------------------------------------------------------------------------
1146 // ----------------------------------------------------------------------------
1147 // X11-specific accessors
1148 // ----------------------------------------------------------------------------
1150 // Get the underlying X window
1151 WXWindow
wxWindowX11::GetXWindow() const
1153 return GetMainWindow();
1156 // Get the underlying X display
1157 WXDisplay
*wxWindowX11::GetXDisplay() const
1159 return wxGetDisplay();
1162 WXWindow
wxWindowX11::GetMainWindow() const
1164 return m_mainWidget
;
1167 // ----------------------------------------------------------------------------
1168 // TranslateXXXEvent() functions
1169 // ----------------------------------------------------------------------------
1171 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1173 switch (XEventGetType(xevent
))
1181 wxEventType eventType
= wxEVT_NULL
;
1183 if (XEventGetType(xevent
) == EnterNotify
)
1185 //if (local_event.xcrossing.mode!=NotifyNormal)
1186 // return ; // Ignore grab events
1187 eventType
= wxEVT_ENTER_WINDOW
;
1188 // canvas->GetEventHandler()->OnSetFocus();
1190 else if (XEventGetType(xevent
) == LeaveNotify
)
1192 //if (local_event.xcrossingr.mode!=NotifyNormal)
1193 // return ; // Ignore grab events
1194 eventType
= wxEVT_LEAVE_WINDOW
;
1195 // canvas->GetEventHandler()->OnKillFocus();
1197 else if (XEventGetType(xevent
) == MotionNotify
)
1199 eventType
= wxEVT_MOTION
;
1201 else if (XEventGetType(xevent
) == ButtonPress
)
1203 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1205 if (XButtonEventLChanged(xevent
))
1207 eventType
= wxEVT_LEFT_DOWN
;
1210 else if (XButtonEventMChanged(xevent
))
1212 eventType
= wxEVT_MIDDLE_DOWN
;
1215 else if (XButtonEventRChanged(xevent
))
1217 eventType
= wxEVT_RIGHT_DOWN
;
1221 // check for a double click
1222 // TODO: where can we get this value from?
1223 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1224 long dclickTime
= 200;
1225 long ts
= wxevent
.GetTimestamp();
1227 int buttonLast
= win
->GetLastClickedButton();
1228 long lastTS
= win
->GetLastClickTime();
1229 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1232 win
->SetLastClick(0, ts
);
1233 if ( eventType
== wxEVT_LEFT_DOWN
)
1234 eventType
= wxEVT_LEFT_DCLICK
;
1235 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1236 eventType
= wxEVT_MIDDLE_DCLICK
;
1237 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1238 eventType
= wxEVT_RIGHT_DCLICK
;
1242 // not fast enough or different button
1243 win
->SetLastClick(button
, ts
);
1246 else if (XEventGetType(xevent
) == ButtonRelease
)
1248 if (XButtonEventLChanged(xevent
))
1250 eventType
= wxEVT_LEFT_UP
;
1252 else if (XButtonEventMChanged(xevent
))
1254 eventType
= wxEVT_MIDDLE_UP
;
1256 else if (XButtonEventRChanged(xevent
))
1258 eventType
= wxEVT_RIGHT_UP
;
1267 wxevent
.SetEventType(eventType
);
1269 wxevent
.m_x
= XButtonEventGetX(xevent
);
1270 wxevent
.m_y
= XButtonEventGetY(xevent
);
1272 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1273 || (XButtonEventLIsDown(xevent
)
1274 && (eventType
!= wxEVT_LEFT_UP
)));
1275 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1276 || (XButtonEventMIsDown(xevent
)
1277 && (eventType
!= wxEVT_MIDDLE_UP
)));
1278 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1279 || (XButtonEventRIsDown (xevent
)
1280 && (eventType
!= wxEVT_RIGHT_UP
)));
1282 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1283 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1284 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1285 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1287 wxevent
.SetId(win
->GetId());
1288 wxevent
.SetEventObject(win
);
1296 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1298 switch (XEventGetType(xevent
))
1306 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1307 int id
= wxCharCodeXToWX (keySym
);
1309 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1310 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1311 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1312 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1313 wxevent
.SetEventObject(win
);
1314 wxevent
.m_keyCode
= id
;
1315 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1317 wxevent
.m_x
= XKeyEventGetX(xevent
);
1318 wxevent
.m_y
= XKeyEventGetY(xevent
);
1332 // ----------------------------------------------------------------------------
1334 // ----------------------------------------------------------------------------
1336 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1338 wxWindowBase::SetBackgroundColour(col
);
1340 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1341 int xscreen
= DefaultScreen( xdisplay
);
1342 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1344 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1346 if (!GetMainWindow())
1350 XSetWindowAttributes attrib;
1351 attrib.background_pixel = colour.GetPixel();
1353 XChangeWindowAttributes(wxGlobalDisplay(),
1354 (Window) GetMainWindow(),
1362 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1364 if ( !wxWindowBase::SetForegroundColour(col
) )
1370 // ----------------------------------------------------------------------------
1372 // ----------------------------------------------------------------------------
1374 wxWindow
*wxGetActiveWindow()
1377 wxFAIL_MSG("Not implemented");
1382 wxWindow
*wxWindowBase::GetCapture()
1384 return (wxWindow
*)g_captureWindow
;
1388 // Find the wxWindow at the current mouse position, returning the mouse
1390 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1392 return wxFindWindowAtPoint(wxGetMousePosition());
1395 // Get the current mouse position.
1396 wxPoint
wxGetMousePosition()
1400 return wxPoint(0, 0);
1402 Display
*display
= wxGlobalDisplay();
1403 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1404 Window rootReturn
, childReturn
;
1405 int rootX
, rootY
, winX
, winY
;
1406 unsigned int maskReturn
;
1408 XQueryPointer (display
,
1412 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1413 return wxPoint(rootX
, rootY
);
1418 // ----------------------------------------------------------------------------
1419 // wxNoOptimize: switch off size optimization
1420 // ----------------------------------------------------------------------------
1422 int wxNoOptimize::ms_count
= 0;