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();
145 XSetWindowAttributes xattributes
;
147 long xattributes_mask
=
149 CWBorderPixel
| CWBackPixel
;
151 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
152 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
154 xattributes
.event_mask
=
155 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
156 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
157 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
174 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
176 long backColor
, foreColor
;
177 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
178 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
180 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
181 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
182 XSelectInput( xdisplay
, xwindow
,
183 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
184 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
185 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
186 PropertyChangeMask
);
190 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
191 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
195 m_mainWidget
= (WXWindow
) xwindow
;
197 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
199 // Is a subwindow, so map immediately
201 XMapWindow( xdisplay
, xwindow
);
203 // Without this, the cursor may not be restored properly (e.g. in splitter
205 SetCursor(*wxSTANDARD_CURSOR
);
206 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
208 // Set background to None which will prevent X11 from clearing the
209 // background comletely.
210 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
212 // Don't call this, it can have nasty repercussions for composite controls,
214 // SetSize(pos.x, pos.y, size.x, size.y);
220 wxWindowX11::~wxWindowX11()
222 if (g_captureWindow
== this)
223 g_captureWindow
= NULL
;
225 m_isBeingDeleted
= TRUE
;
227 // X11-specific actions first
228 Window xwindow
= (Window
) m_mainWidget
;
231 m_parent
->RemoveChild( this );
235 // Destroy the window
238 XSelectInput( wxGlobalDisplay(), xwindow
, NoEventMask
);
239 wxDeleteWindowFromTable( xwindow
);
240 XDestroyWindow( wxGlobalDisplay(), xwindow
);
245 // ---------------------------------------------------------------------------
247 // ---------------------------------------------------------------------------
249 void wxWindowX11::SetFocus()
251 Window xwindow
= (Window
) GetMainWindow();
253 wxCHECK_RET( xwindow
, wxT("invalid window") );
255 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
258 if (GetName() == "scrollBar")
265 if (wxWindowIsVisible(xwindow
))
267 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
268 m_needsInputFocus
= FALSE
;
272 m_needsInputFocus
= TRUE
;
276 // Get the window with the focus
277 wxWindow
*wxWindowBase::FindFocus()
279 Window xfocus
= (Window
) 0;
282 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
285 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
293 wxWindow
*wxWindowX11::GetFocusWidget()
295 wxWindow
*win
= (wxWindow
*) this;
296 while (!win
->IsTopLevel())
298 win
= win
->GetParent();
300 return (wxWindow
*) NULL
;
306 // Enabling/disabling handled by event loop, and not sending events
308 bool wxWindowX11::Enable(bool enable
)
310 if ( !wxWindowBase::Enable(enable
) )
316 bool wxWindowX11::Show(bool show
)
318 wxWindowBase::Show(show
);
320 Window xwin
= (Window
) GetXWindow();
321 Display
*xdisp
= (Display
*) GetXDisplay();
324 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
325 XMapWindow(xdisp
, xwin
);
330 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
331 XUnmapWindow(xdisp
, xwin
);
337 // Raise the window to the top of the Z order
338 void wxWindowX11::Raise()
341 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
344 // Lower the window to the bottom of the Z order
345 void wxWindowX11::Lower()
348 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
351 void wxWindowX11::DoCaptureMouse()
353 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
355 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
366 Window xwindow
= (Window
) GetMainWindow();
368 wxCHECK_RET( xwindow
, wxT("invalid window") );
370 g_captureWindow
= (wxWindow
*) this;
374 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
376 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
380 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
383 if (res
!= GrabSuccess
)
386 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
388 if (res
== GrabNotViewable
)
390 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
392 g_captureWindow
= NULL
;
396 // wxLogDebug("Grabbed pointer in %s", GetName().c_str() );
399 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
400 (Window
) GetMainWindow(),
402 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
408 if (res
!= GrabSuccess
)
410 wxLogDebug("Failed to grab mouse buttons.");
411 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
417 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
418 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
424 if (res
!= GrabSuccess
)
426 wxLogDebug("Failed to grab keyboard.");
427 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
428 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
429 (Window
) GetMainWindow());
434 m_winCaptured
= TRUE
;
438 void wxWindowX11::DoReleaseMouse()
440 g_captureWindow
= NULL
;
442 if ( !m_winCaptured
)
445 Window xwindow
= (Window
) GetMainWindow();
449 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
451 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
452 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
456 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
458 m_winCaptured
= FALSE
;
461 bool wxWindowX11::SetFont(const wxFont
& font
)
463 if ( !wxWindowBase::SetFont(font
) )
472 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
474 if ( !wxWindowBase::SetCursor(cursor
) )
480 Window xwindow
= (Window
) GetMainWindow();
482 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
484 wxCursor cursorToUse
;
486 cursorToUse
= m_cursor
;
488 cursorToUse
= *wxSTANDARD_CURSOR
;
490 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
492 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
497 // Coordinates relative to the window
498 void wxWindowX11::WarpPointer (int x
, int y
)
500 Window xwindow
= (Window
) GetMainWindow();
502 wxCHECK_RET( xwindow
, wxT("invalid window") );
504 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
507 // Does a physical scroll
508 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
510 // No scrolling requested.
511 if ((dx
== 0) && (dy
== 0)) return;
513 if (!m_updateRegion
.IsEmpty())
515 m_updateRegion
.Offset( dx
, dy
);
519 GetSize( &cw
, &ch
); // GetClientSize() ??
520 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
523 if (!m_clearRegion
.IsEmpty())
525 m_clearRegion
.Offset( dx
, dy
);
529 GetSize( &cw
, &ch
); // GetClientSize() ??
530 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
533 Window xwindow
= (Window
) GetMainWindow();
535 wxCHECK_RET( xwindow
, wxT("invalid window") );
537 Display
*xdisplay
= wxGlobalDisplay();
539 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
540 XSetGraphicsExposures( xdisplay
, xgc
, True
);
558 GetClientSize( &cw
, &ch
);
561 wxPoint offset
= GetClientAreaOrigin();
565 int w
= cw
- abs(dx
);
566 int h
= ch
- abs(dy
);
568 if ((h
< 0) || (w
< 0))
575 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
576 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
577 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
578 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
583 if (dx
< 0) s_x
+= -dx
;
584 if (dy
< 0) s_y
+= -dy
;
585 if (dx
> 0) d_x
= dx
+ offset
.x
;
586 if (dy
> 0) d_y
= dy
+ offset
.y
;
588 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
590 // 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 );
592 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
594 m_updateRegion
.Union( rect
);
595 m_clearRegion
.Union( rect
);
598 XFreeGC( xdisplay
, xgc
);
601 // ---------------------------------------------------------------------------
603 // ---------------------------------------------------------------------------
605 #if wxUSE_DRAG_AND_DROP
607 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
614 // Old style file-manager drag&drop
615 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
620 // ----------------------------------------------------------------------------
622 // ----------------------------------------------------------------------------
626 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
631 #endif // wxUSE_TOOLTIPS
633 // ---------------------------------------------------------------------------
634 // moving and resizing
635 // ---------------------------------------------------------------------------
637 bool wxWindowX11::PreResize()
643 void wxWindowX11::DoGetSize(int *x
, int *y
) const
645 Window xwindow
= (Window
) GetMainWindow();
647 wxCHECK_RET( xwindow
, wxT("invalid window") );
649 //XSync(wxGlobalDisplay(), False);
651 XWindowAttributes attr
;
652 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
657 *x
= attr
.width
/* + 2*m_borderSize */ ;
658 *y
= attr
.height
/* + 2*m_borderSize */ ;
662 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
664 Window window
= (Window
) m_mainWidget
;
667 //XSync(wxGlobalDisplay(), False);
668 XWindowAttributes attr
;
669 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
677 // We may be faking the client origin. So a window that's really at (0, 30)
678 // may appear (to wxWin apps) to be at (0, 0).
681 wxPoint
pt(GetParent()->GetClientAreaOrigin());
689 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
691 Display
*display
= wxGlobalDisplay();
692 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
693 Window thisWindow
= (Window
) m_mainWidget
;
698 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
701 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
703 Display
*display
= wxGlobalDisplay();
704 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
705 Window thisWindow
= (Window
) m_mainWidget
;
710 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
714 // Get size *available for subwindows* i.e. excluding menu bar etc.
715 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
717 Window window
= (Window
) m_mainWidget
;
721 //XSync(wxGlobalDisplay(), False); // Is this really a good idea?
722 XWindowAttributes attr
;
723 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
734 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
736 Window xwindow
= (Window
) GetMainWindow();
738 wxCHECK_RET( xwindow
, wxT("invalid window") );
740 XWindowAttributes attr
;
741 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
742 wxCHECK_RET( status
, wxT("invalid window attributes") );
746 int new_w
= attr
.width
;
747 int new_h
= attr
.height
;
750 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
753 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
756 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
759 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
775 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
778 void wxWindowX11::DoSetClientSize(int width
, int height
)
780 Window xwindow
= (Window
) GetMainWindow();
782 wxCHECK_RET( xwindow
, wxT("invalid window") );
784 XWindowChanges windowChanges
;
785 windowChanges
.width
= width
;
786 windowChanges
.height
= height
;
787 windowChanges
.stack_mode
= 0;
788 int valueMask
= CWWidth
| CWHeight
;
790 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
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
);
811 // For implementation purposes - sometimes decorations make the client area
813 wxPoint
wxWindowX11::GetClientAreaOrigin() const
815 return wxPoint(0, 0);
818 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
826 XSizeHints sizeHints
;
829 if (minW
> -1 && minH
> -1)
831 sizeHints
.flags
|= PMinSize
;
832 sizeHints
.min_width
= minW
;
833 sizeHints
.min_height
= minH
;
835 if (maxW
> -1 && maxH
> -1)
837 sizeHints
.flags
|= PMaxSize
;
838 sizeHints
.max_width
= maxW
;
839 sizeHints
.max_height
= maxH
;
841 if (incW
> -1 && incH
> -1)
843 sizeHints
.flags
|= PResizeInc
;
844 sizeHints
.width_inc
= incW
;
845 sizeHints
.height_inc
= incH
;
848 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
852 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
854 Window xwindow
= (Window
) GetMainWindow();
856 wxCHECK_RET( xwindow
, wxT("invalid window") );
858 XWindowChanges windowChanges
;
861 windowChanges
.width
= width
;
862 windowChanges
.height
= height
;
863 windowChanges
.stack_mode
= 0;
864 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
866 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
869 // ---------------------------------------------------------------------------
871 // ---------------------------------------------------------------------------
873 int wxWindowX11::GetCharHeight() const
875 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
877 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
879 int direction
, ascent
, descent
;
881 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
884 // return (overall.ascent + overall.descent);
885 return (ascent
+ descent
);
888 int wxWindowX11::GetCharWidth() const
890 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
892 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
894 int direction
, ascent
, descent
;
896 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
899 return overall
.width
;
902 void wxWindowX11::GetTextExtent(const wxString
& string
,
904 int *descent
, int *externalLeading
,
905 const wxFont
*theFont
) const
907 wxFont fontToUse
= m_font
;
908 if (theFont
) fontToUse
= *theFont
;
910 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
912 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
914 int direction
, ascent
, descent2
;
916 int slen
= string
.Len();
920 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
921 &ascent
, &descent2
, &overall
);
924 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
925 &direction
, &ascent
, &descent2
, &overall
);
928 *x
= (overall
.width
);
930 *y
= (ascent
+ descent2
);
934 *externalLeading
= 0;
938 // ----------------------------------------------------------------------------
940 // ----------------------------------------------------------------------------
942 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
948 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
949 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
954 GetSize( &width
, &height
);
956 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
957 m_clearRegion
.Clear();
958 m_clearRegion
.Union( 0, 0, width
, height
);
964 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
965 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
970 GetSize( &width
, &height
);
972 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
973 m_updateRegion
.Clear();
974 m_updateRegion
.Union( 0, 0, width
, height
);
978 void wxWindowX11::Update()
980 if (!m_updateRegion
.IsEmpty())
982 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
983 // Actually send erase events.
986 // Actually send paint events.
991 void wxWindowX11::Clear()
993 wxClientDC
dc((wxWindow
*) this);
994 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
995 dc
.SetBackground(brush
);
999 void wxWindowX11::SendEraseEvents()
1001 if (!m_clearRegion
.IsEmpty())
1003 m_clipPaintRegion
= TRUE
;
1005 wxWindowDC
dc( (wxWindow
*)this );
1006 dc
.SetClippingRegion( m_clearRegion
);
1008 wxEraseEvent
erase_event( GetId(), &dc
);
1009 erase_event
.SetEventObject( this );
1011 if (!GetEventHandler()->ProcessEvent(erase_event
))
1013 Window xwindow
= (Window
) GetMainWindow();
1014 Display
*xdisplay
= wxGlobalDisplay();
1015 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1016 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1017 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1018 wxRegionIterator
upd( m_clearRegion
);
1021 XFillRectangle( xdisplay
, xwindow
, xgc
,
1022 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1025 XFreeGC( xdisplay
, xgc
);
1027 m_clearRegion
.Clear();
1029 m_clipPaintRegion
= FALSE
;
1034 void wxWindowX11::SendPaintEvents()
1036 m_clipPaintRegion
= TRUE
;
1038 wxNcPaintEvent
nc_paint_event( GetId() );
1039 nc_paint_event
.SetEventObject( this );
1040 GetEventHandler()->ProcessEvent( nc_paint_event
);
1042 wxPaintEvent
paint_event( GetId() );
1043 paint_event
.SetEventObject( this );
1044 GetEventHandler()->ProcessEvent( paint_event
);
1046 m_updateRegion
.Clear();
1047 m_clipPaintRegion
= FALSE
;
1050 // ----------------------------------------------------------------------------
1052 // ----------------------------------------------------------------------------
1054 // Responds to colour changes: passes event on to children.
1055 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1057 wxWindowList::Node
*node
= GetChildren().GetFirst();
1060 // Only propagate to non-top-level windows
1061 wxWindow
*win
= node
->GetData();
1062 if ( win
->GetParent() )
1064 wxSysColourChangedEvent event2
;
1065 event
.m_eventObject
= win
;
1066 win
->GetEventHandler()->ProcessEvent(event2
);
1069 node
= node
->GetNext();
1073 void wxWindowX11::OnInternalIdle()
1075 // Update invalidated regions.
1078 // This calls the UI-update mechanism (querying windows for
1079 // menu/toolbar/control state information)
1082 // Set the input focus if couldn't do it before
1083 if (m_needsInputFocus
)
1089 // ----------------------------------------------------------------------------
1090 // function which maintain the global hash table mapping Widgets to wxWindows
1091 // ----------------------------------------------------------------------------
1093 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1095 wxWindow
*oldItem
= NULL
;
1096 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1098 wxLogDebug("Widget table clash: new widget is %ld, %s",
1099 (long)w
, win
->GetClassInfo()->GetClassName());
1103 wxWidgetHashTable
->Put((long) w
, win
);
1105 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1106 w
, win
, win
->GetClassInfo()->GetClassName());
1111 wxWindow
*wxGetWindowFromTable(Window w
)
1113 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1116 void wxDeleteWindowFromTable(Window w
)
1118 wxWidgetHashTable
->Delete((long)w
);
1121 // ----------------------------------------------------------------------------
1122 // add/remove window from the table
1123 // ----------------------------------------------------------------------------
1125 // ----------------------------------------------------------------------------
1126 // X11-specific accessors
1127 // ----------------------------------------------------------------------------
1129 // Get the underlying X window
1130 WXWindow
wxWindowX11::GetXWindow() const
1132 return GetMainWindow();
1135 // Get the underlying X display
1136 WXDisplay
*wxWindowX11::GetXDisplay() const
1138 return wxGetDisplay();
1141 WXWindow
wxWindowX11::GetMainWindow() const
1143 return m_mainWidget
;
1146 // ----------------------------------------------------------------------------
1147 // TranslateXXXEvent() functions
1148 // ----------------------------------------------------------------------------
1150 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1152 switch (XEventGetType(xevent
))
1160 wxEventType eventType
= wxEVT_NULL
;
1162 if (XEventGetType(xevent
) == EnterNotify
)
1164 //if (local_event.xcrossing.mode!=NotifyNormal)
1165 // return ; // Ignore grab events
1166 eventType
= wxEVT_ENTER_WINDOW
;
1167 // canvas->GetEventHandler()->OnSetFocus();
1169 else if (XEventGetType(xevent
) == LeaveNotify
)
1171 //if (local_event.xcrossingr.mode!=NotifyNormal)
1172 // return ; // Ignore grab events
1173 eventType
= wxEVT_LEAVE_WINDOW
;
1174 // canvas->GetEventHandler()->OnKillFocus();
1176 else if (XEventGetType(xevent
) == MotionNotify
)
1178 eventType
= wxEVT_MOTION
;
1180 else if (XEventGetType(xevent
) == ButtonPress
)
1182 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1184 if (XButtonEventLChanged(xevent
))
1186 eventType
= wxEVT_LEFT_DOWN
;
1189 else if (XButtonEventMChanged(xevent
))
1191 eventType
= wxEVT_MIDDLE_DOWN
;
1194 else if (XButtonEventRChanged(xevent
))
1196 eventType
= wxEVT_RIGHT_DOWN
;
1200 // check for a double click
1201 // TODO: where can we get this value from?
1202 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1203 long dclickTime
= 200;
1204 long ts
= wxevent
.GetTimestamp();
1206 int buttonLast
= win
->GetLastClickedButton();
1207 long lastTS
= win
->GetLastClickTime();
1208 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1211 win
->SetLastClick(0, ts
);
1212 if ( eventType
== wxEVT_LEFT_DOWN
)
1213 eventType
= wxEVT_LEFT_DCLICK
;
1214 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1215 eventType
= wxEVT_MIDDLE_DCLICK
;
1216 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1217 eventType
= wxEVT_RIGHT_DCLICK
;
1221 // not fast enough or different button
1222 win
->SetLastClick(button
, ts
);
1225 else if (XEventGetType(xevent
) == ButtonRelease
)
1227 if (XButtonEventLChanged(xevent
))
1229 eventType
= wxEVT_LEFT_UP
;
1231 else if (XButtonEventMChanged(xevent
))
1233 eventType
= wxEVT_MIDDLE_UP
;
1235 else if (XButtonEventRChanged(xevent
))
1237 eventType
= wxEVT_RIGHT_UP
;
1246 wxevent
.SetEventType(eventType
);
1248 wxevent
.m_x
= XButtonEventGetX(xevent
);
1249 wxevent
.m_y
= XButtonEventGetY(xevent
);
1251 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1252 || (XButtonEventLIsDown(xevent
)
1253 && (eventType
!= wxEVT_LEFT_UP
)));
1254 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1255 || (XButtonEventMIsDown(xevent
)
1256 && (eventType
!= wxEVT_MIDDLE_UP
)));
1257 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1258 || (XButtonEventRIsDown (xevent
)
1259 && (eventType
!= wxEVT_RIGHT_UP
)));
1261 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1262 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1263 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1264 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1266 wxevent
.SetId(win
->GetId());
1267 wxevent
.SetEventObject(win
);
1275 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1277 switch (XEventGetType(xevent
))
1285 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1286 int id
= wxCharCodeXToWX (keySym
);
1288 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1289 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1290 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1291 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1292 wxevent
.SetEventObject(win
);
1293 wxevent
.m_keyCode
= id
;
1294 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1296 wxevent
.m_x
= XKeyEventGetX(xevent
);
1297 wxevent
.m_y
= XKeyEventGetY(xevent
);
1311 // ----------------------------------------------------------------------------
1313 // ----------------------------------------------------------------------------
1315 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1317 wxWindowBase::SetBackgroundColour(col
);
1319 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1320 int xscreen
= DefaultScreen( xdisplay
);
1321 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1323 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1325 if (!GetMainWindow())
1329 XSetWindowAttributes attrib;
1330 attrib.background_pixel = colour.GetPixel();
1332 XChangeWindowAttributes(wxGlobalDisplay(),
1333 (Window) GetMainWindow(),
1341 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1343 if ( !wxWindowBase::SetForegroundColour(col
) )
1349 // ----------------------------------------------------------------------------
1351 // ----------------------------------------------------------------------------
1353 wxWindow
*wxGetActiveWindow()
1356 wxFAIL_MSG("Not implemented");
1361 wxWindow
*wxWindowBase::GetCapture()
1363 return (wxWindow
*)g_captureWindow
;
1367 // Find the wxWindow at the current mouse position, returning the mouse
1369 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1371 return wxFindWindowAtPoint(wxGetMousePosition());
1374 // Get the current mouse position.
1375 wxPoint
wxGetMousePosition()
1379 return wxPoint(0, 0);
1381 Display
*display
= wxGlobalDisplay();
1382 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1383 Window rootReturn
, childReturn
;
1384 int rootX
, rootY
, winX
, winY
;
1385 unsigned int maskReturn
;
1387 XQueryPointer (display
,
1391 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1392 return wxPoint(rootX
, rootY
);
1397 // ----------------------------------------------------------------------------
1398 // wxNoOptimize: switch off size optimization
1399 // ----------------------------------------------------------------------------
1401 int wxNoOptimize::ms_count
= 0;