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 if (wxWindowIsVisible(xwindow
))
257 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
258 m_needsInputFocus
= FALSE
;
262 m_needsInputFocus
= TRUE
;
266 // Get the window with the focus
267 wxWindow
*wxWindowBase::FindFocus()
269 Window xfocus
= (Window
) 0;
272 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
275 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
283 wxWindow
*wxWindowX11::GetFocusWidget()
285 wxWindow
*win
= (wxWindow
*) this;
286 while (!win
->IsTopLevel())
288 win
= win
->GetParent();
290 return (wxWindow
*) NULL
;
296 // Enabling/disabling handled by event loop, and not sending events
298 bool wxWindowX11::Enable(bool enable
)
300 if ( !wxWindowBase::Enable(enable
) )
306 bool wxWindowX11::Show(bool show
)
308 wxWindowBase::Show(show
);
310 Window xwin
= (Window
) GetXWindow();
311 Display
*xdisp
= (Display
*) GetXDisplay();
314 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
315 XMapWindow(xdisp
, xwin
);
320 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
321 XUnmapWindow(xdisp
, xwin
);
327 // Raise the window to the top of the Z order
328 void wxWindowX11::Raise()
331 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
334 // Lower the window to the bottom of the Z order
335 void wxWindowX11::Lower()
338 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
341 void wxWindowX11::DoCaptureMouse()
343 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
345 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
356 Window xwindow
= (Window
) GetMainWindow();
358 wxCHECK_RET( xwindow
, wxT("invalid window") );
360 g_captureWindow
= (wxWindow
*) this;
364 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
366 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
370 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
373 if (res
!= GrabSuccess
)
376 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
378 if (res
== GrabNotViewable
)
380 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
382 g_captureWindow
= NULL
;
386 // wxLogDebug("Grabbed pointer in %s", GetName().c_str() );
389 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
390 (Window
) GetMainWindow(),
392 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
398 if (res
!= GrabSuccess
)
400 wxLogDebug("Failed to grab mouse buttons.");
401 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
407 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
408 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
414 if (res
!= GrabSuccess
)
416 wxLogDebug("Failed to grab keyboard.");
417 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
418 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
419 (Window
) GetMainWindow());
424 m_winCaptured
= TRUE
;
428 void wxWindowX11::DoReleaseMouse()
430 g_captureWindow
= NULL
;
432 if ( !m_winCaptured
)
435 Window xwindow
= (Window
) GetMainWindow();
439 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
441 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
442 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
446 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
448 m_winCaptured
= FALSE
;
451 bool wxWindowX11::SetFont(const wxFont
& font
)
453 if ( !wxWindowBase::SetFont(font
) )
462 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
464 if ( !wxWindowBase::SetCursor(cursor
) )
470 Window xwindow
= (Window
) GetMainWindow();
472 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
474 wxCursor cursorToUse
;
476 cursorToUse
= m_cursor
;
478 cursorToUse
= *wxSTANDARD_CURSOR
;
480 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
482 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
487 // Coordinates relative to the window
488 void wxWindowX11::WarpPointer (int x
, int y
)
490 Window xwindow
= (Window
) GetMainWindow();
492 wxCHECK_RET( xwindow
, wxT("invalid window") );
494 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
497 // Does a physical scroll
498 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
500 // No scrolling requested.
501 if ((dx
== 0) && (dy
== 0)) return;
503 if (!m_updateRegion
.IsEmpty())
505 m_updateRegion
.Offset( dx
, dy
);
509 GetSize( &cw
, &ch
); // GetClientSize() ??
510 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
513 if (!m_clearRegion
.IsEmpty())
515 m_clearRegion
.Offset( dx
, dy
);
519 GetSize( &cw
, &ch
); // GetClientSize() ??
520 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
523 Window xwindow
= (Window
) GetMainWindow();
525 wxCHECK_RET( xwindow
, wxT("invalid window") );
527 Display
*xdisplay
= wxGlobalDisplay();
529 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
530 XSetGraphicsExposures( xdisplay
, xgc
, True
);
547 GetClientSize( &cw
, &ch
);
550 wxPoint offset
= GetClientAreaOrigin();
554 int w
= cw
- abs(dx
);
555 int h
= ch
- abs(dy
);
557 if ((h
< 0) || (w
< 0))
564 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
565 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
566 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
567 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
571 if (dx
< 0) s_x
+= -dx
;
572 if (dy
< 0) s_y
+= -dy
;
573 if (dx
> 0) d_x
= dx
;
574 if (dy
> 0) d_y
= dy
;
576 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
578 // printf( "s_x %d s_y %d w %d h %d d_x %d d_y %d\n", s_x, s_y, w, h, d_x, d_y );
580 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
582 m_updateRegion
.Union( rect
);
583 m_clearRegion
.Union( rect
);
586 XFreeGC( xdisplay
, xgc
);
589 // ---------------------------------------------------------------------------
591 // ---------------------------------------------------------------------------
593 #if wxUSE_DRAG_AND_DROP
595 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
602 // Old style file-manager drag&drop
603 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
608 // ----------------------------------------------------------------------------
610 // ----------------------------------------------------------------------------
614 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
619 #endif // wxUSE_TOOLTIPS
621 // ---------------------------------------------------------------------------
622 // moving and resizing
623 // ---------------------------------------------------------------------------
625 bool wxWindowX11::PreResize()
631 void wxWindowX11::DoGetSize(int *x
, int *y
) const
633 Window xwindow
= (Window
) GetMainWindow();
635 wxCHECK_RET( xwindow
, wxT("invalid window") );
637 XSync(wxGlobalDisplay(), False
);
639 XWindowAttributes attr
;
640 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
645 *x
= attr
.width
/* + 2*m_borderSize */ ;
646 *y
= attr
.height
/* + 2*m_borderSize */ ;
650 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
652 Window window
= (Window
) m_mainWidget
;
655 XSync(wxGlobalDisplay(), False
);
656 XWindowAttributes attr
;
657 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
665 // We may be faking the client origin. So a window that's really at (0, 30)
666 // may appear (to wxWin apps) to be at (0, 0).
669 wxPoint
pt(GetParent()->GetClientAreaOrigin());
677 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
679 Display
*display
= wxGlobalDisplay();
680 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
681 Window thisWindow
= (Window
) m_mainWidget
;
686 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
689 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
691 Display
*display
= wxGlobalDisplay();
692 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
693 Window thisWindow
= (Window
) m_mainWidget
;
698 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
702 // Get size *available for subwindows* i.e. excluding menu bar etc.
703 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
705 Window window
= (Window
) m_mainWidget
;
709 XSync(wxGlobalDisplay(), False
); // Is this really a good idea?
710 XWindowAttributes attr
;
711 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
722 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
724 Window xwindow
= (Window
) GetMainWindow();
726 wxCHECK_RET( xwindow
, wxT("invalid window") );
728 XWindowAttributes attr
;
729 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
730 wxCHECK_RET( status
, wxT("invalid window attributes") );
734 int new_w
= attr
.width
;
735 int new_h
= attr
.height
;
738 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
741 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
744 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
747 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
763 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
766 void wxWindowX11::DoSetClientSize(int width
, int height
)
768 Window xwindow
= (Window
) GetMainWindow();
770 wxCHECK_RET( xwindow
, wxT("invalid window") );
772 XWindowAttributes attr
;
773 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
774 wxCHECK_RET( status
, wxT("invalid window attributes") );
778 int new_w
= attr
.width
;
779 int new_h
= attr
.height
;
787 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
790 // For implementation purposes - sometimes decorations make the client area
792 wxPoint
wxWindowX11::GetClientAreaOrigin() const
794 return wxPoint(0, 0);
797 // Makes an adjustment to the window position (for example, a frame that has
798 // a toolbar that it manages itself).
799 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
801 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
803 wxPoint
pt(GetParent()->GetClientAreaOrigin());
804 x
+= pt
.x
; y
+= pt
.y
;
808 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
816 XSizeHints sizeHints
;
819 if (minW
> -1 && minH
> -1)
821 sizeHints
.flags
|= PMinSize
;
822 sizeHints
.min_width
= minW
;
823 sizeHints
.min_height
= minH
;
825 if (maxW
> -1 && maxH
> -1)
827 sizeHints
.flags
|= PMaxSize
;
828 sizeHints
.max_width
= maxW
;
829 sizeHints
.max_height
= maxH
;
831 if (incW
> -1 && incH
> -1)
833 sizeHints
.flags
|= PResizeInc
;
834 sizeHints
.width_inc
= incW
;
835 sizeHints
.height_inc
= incH
;
838 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
842 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
844 Window xwindow
= (Window
) GetMainWindow();
846 wxCHECK_RET( xwindow
, wxT("invalid window") );
848 XWindowChanges windowChanges
;
851 windowChanges
.width
= width
;
852 windowChanges
.height
= height
;
853 windowChanges
.stack_mode
= 0;
854 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
856 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
859 // ---------------------------------------------------------------------------
861 // ---------------------------------------------------------------------------
863 int wxWindowX11::GetCharHeight() const
865 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
867 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
869 int direction
, ascent
, descent
;
871 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
874 // return (overall.ascent + overall.descent);
875 return (ascent
+ descent
);
878 int wxWindowX11::GetCharWidth() const
880 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
882 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
884 int direction
, ascent
, descent
;
886 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
889 return overall
.width
;
892 void wxWindowX11::GetTextExtent(const wxString
& string
,
894 int *descent
, int *externalLeading
,
895 const wxFont
*theFont
) const
897 wxFont fontToUse
= m_font
;
898 if (theFont
) fontToUse
= *theFont
;
900 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
902 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
904 int direction
, ascent
, descent2
;
906 int slen
= string
.Len();
910 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
911 &ascent
, &descent2
, &overall
);
914 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
915 &direction
, &ascent
, &descent2
, &overall
);
918 *x
= (overall
.width
);
920 *y
= (ascent
+ descent2
);
924 *externalLeading
= 0;
928 // ----------------------------------------------------------------------------
930 // ----------------------------------------------------------------------------
932 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
938 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
939 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
944 GetSize( &width
, &height
);
946 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
947 m_clearRegion
.Clear();
948 m_clearRegion
.Union( 0, 0, width
, height
);
954 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
955 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
960 GetSize( &width
, &height
);
962 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
963 m_updateRegion
.Clear();
964 m_updateRegion
.Union( 0, 0, width
, height
);
968 void wxWindowX11::Update()
970 if (!m_updateRegion
.IsEmpty())
972 // Actually send erase events.
975 // Actually send paint events.
980 void wxWindowX11::Clear()
982 wxClientDC
dc((wxWindow
*) this);
983 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
984 dc
.SetBackground(brush
);
988 void wxWindowX11::SendEraseEvents()
990 if (!m_clearRegion
.IsEmpty())
992 m_clipPaintRegion
= TRUE
;
994 wxWindowDC
dc( (wxWindow
*)this );
995 dc
.SetClippingRegion( m_clearRegion
);
997 wxEraseEvent
erase_event( GetId(), &dc
);
998 erase_event
.SetEventObject( this );
1000 if (!GetEventHandler()->ProcessEvent(erase_event
))
1002 Window xwindow
= (Window
) GetMainWindow();
1003 Display
*xdisplay
= wxGlobalDisplay();
1004 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1005 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1006 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1007 wxRegionIterator
upd( m_clearRegion
);
1010 XFillRectangle( xdisplay
, xwindow
, xgc
,
1011 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1014 XFreeGC( xdisplay
, xgc
);
1016 m_clearRegion
.Clear();
1018 m_clipPaintRegion
= FALSE
;
1023 void wxWindowX11::SendPaintEvents()
1025 m_clipPaintRegion
= TRUE
;
1027 wxNcPaintEvent
nc_paint_event( GetId() );
1028 nc_paint_event
.SetEventObject( this );
1029 GetEventHandler()->ProcessEvent( nc_paint_event
);
1031 wxPaintEvent
paint_event( GetId() );
1032 paint_event
.SetEventObject( this );
1033 GetEventHandler()->ProcessEvent( paint_event
);
1035 m_updateRegion
.Clear();
1037 m_clipPaintRegion
= FALSE
;
1040 // ----------------------------------------------------------------------------
1042 // ----------------------------------------------------------------------------
1044 // Responds to colour changes: passes event on to children.
1045 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1047 wxWindowList::Node
*node
= GetChildren().GetFirst();
1050 // Only propagate to non-top-level windows
1051 wxWindow
*win
= node
->GetData();
1052 if ( win
->GetParent() )
1054 wxSysColourChangedEvent event2
;
1055 event
.m_eventObject
= win
;
1056 win
->GetEventHandler()->ProcessEvent(event2
);
1059 node
= node
->GetNext();
1063 void wxWindowX11::OnInternalIdle()
1065 // Update invalidated regions.
1068 // This calls the UI-update mechanism (querying windows for
1069 // menu/toolbar/control state information)
1072 // Set the input focus if couldn't do it before
1073 if (m_needsInputFocus
)
1077 // ----------------------------------------------------------------------------
1078 // function which maintain the global hash table mapping Widgets to wxWindows
1079 // ----------------------------------------------------------------------------
1081 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1083 wxWindow
*oldItem
= NULL
;
1084 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1086 wxLogDebug("Widget table clash: new widget is %ld, %s",
1087 (long)w
, win
->GetClassInfo()->GetClassName());
1091 wxWidgetHashTable
->Put((long) w
, win
);
1093 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1094 w
, win
, win
->GetClassInfo()->GetClassName());
1099 wxWindow
*wxGetWindowFromTable(Window w
)
1101 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1104 void wxDeleteWindowFromTable(Window w
)
1106 wxWidgetHashTable
->Delete((long)w
);
1109 // ----------------------------------------------------------------------------
1110 // add/remove window from the table
1111 // ----------------------------------------------------------------------------
1113 // ----------------------------------------------------------------------------
1114 // X11-specific accessors
1115 // ----------------------------------------------------------------------------
1117 // Get the underlying X window
1118 WXWindow
wxWindowX11::GetXWindow() const
1120 return GetMainWindow();
1123 // Get the underlying X display
1124 WXDisplay
*wxWindowX11::GetXDisplay() const
1126 return wxGetDisplay();
1129 WXWindow
wxWindowX11::GetMainWindow() const
1131 return m_mainWidget
;
1134 // ----------------------------------------------------------------------------
1135 // TranslateXXXEvent() functions
1136 // ----------------------------------------------------------------------------
1138 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1140 switch (XEventGetType(xevent
))
1148 wxEventType eventType
= wxEVT_NULL
;
1150 if (XEventGetType(xevent
) == EnterNotify
)
1152 //if (local_event.xcrossing.mode!=NotifyNormal)
1153 // return ; // Ignore grab events
1154 eventType
= wxEVT_ENTER_WINDOW
;
1155 // canvas->GetEventHandler()->OnSetFocus();
1157 else if (XEventGetType(xevent
) == LeaveNotify
)
1159 //if (local_event.xcrossingr.mode!=NotifyNormal)
1160 // return ; // Ignore grab events
1161 eventType
= wxEVT_LEAVE_WINDOW
;
1162 // canvas->GetEventHandler()->OnKillFocus();
1164 else if (XEventGetType(xevent
) == MotionNotify
)
1166 eventType
= wxEVT_MOTION
;
1168 else if (XEventGetType(xevent
) == ButtonPress
)
1170 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1172 if (XButtonEventLChanged(xevent
))
1174 eventType
= wxEVT_LEFT_DOWN
;
1177 else if (XButtonEventMChanged(xevent
))
1179 eventType
= wxEVT_MIDDLE_DOWN
;
1182 else if (XButtonEventRChanged(xevent
))
1184 eventType
= wxEVT_RIGHT_DOWN
;
1188 // check for a double click
1189 // TODO: where can we get this value from?
1190 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1191 long dclickTime
= 200;
1192 long ts
= wxevent
.GetTimestamp();
1194 int buttonLast
= win
->GetLastClickedButton();
1195 long lastTS
= win
->GetLastClickTime();
1196 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1199 win
->SetLastClick(0, ts
);
1200 if ( eventType
== wxEVT_LEFT_DOWN
)
1201 eventType
= wxEVT_LEFT_DCLICK
;
1202 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1203 eventType
= wxEVT_MIDDLE_DCLICK
;
1204 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1205 eventType
= wxEVT_RIGHT_DCLICK
;
1209 // not fast enough or different button
1210 win
->SetLastClick(button
, ts
);
1213 else if (XEventGetType(xevent
) == ButtonRelease
)
1215 if (XButtonEventLChanged(xevent
))
1217 eventType
= wxEVT_LEFT_UP
;
1219 else if (XButtonEventMChanged(xevent
))
1221 eventType
= wxEVT_MIDDLE_UP
;
1223 else if (XButtonEventRChanged(xevent
))
1225 eventType
= wxEVT_RIGHT_UP
;
1234 wxevent
.SetEventType(eventType
);
1236 wxevent
.m_x
= XButtonEventGetX(xevent
);
1237 wxevent
.m_y
= XButtonEventGetY(xevent
);
1239 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1240 || (XButtonEventLIsDown(xevent
)
1241 && (eventType
!= wxEVT_LEFT_UP
)));
1242 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1243 || (XButtonEventMIsDown(xevent
)
1244 && (eventType
!= wxEVT_MIDDLE_UP
)));
1245 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1246 || (XButtonEventRIsDown (xevent
)
1247 && (eventType
!= wxEVT_RIGHT_UP
)));
1249 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1250 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1251 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1252 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1254 wxevent
.SetId(win
->GetId());
1255 wxevent
.SetEventObject(win
);
1263 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1265 switch (XEventGetType(xevent
))
1273 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1274 int id
= wxCharCodeXToWX (keySym
);
1276 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1277 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1278 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1279 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1280 wxevent
.SetEventObject(win
);
1281 wxevent
.m_keyCode
= id
;
1282 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1284 wxevent
.m_x
= XKeyEventGetX(xevent
);
1285 wxevent
.m_y
= XKeyEventGetY(xevent
);
1299 // ----------------------------------------------------------------------------
1301 // ----------------------------------------------------------------------------
1303 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1305 wxWindowBase::SetBackgroundColour(col
);
1307 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1308 int xscreen
= DefaultScreen( xdisplay
);
1309 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1311 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1313 if (!GetMainWindow())
1317 XSetWindowAttributes attrib;
1318 attrib.background_pixel = colour.GetPixel();
1320 XChangeWindowAttributes(wxGlobalDisplay(),
1321 (Window) GetMainWindow(),
1329 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1331 if ( !wxWindowBase::SetForegroundColour(col
) )
1337 // ----------------------------------------------------------------------------
1339 // ----------------------------------------------------------------------------
1341 wxWindow
*wxGetActiveWindow()
1344 wxFAIL_MSG("Not implemented");
1349 wxWindow
*wxWindowBase::GetCapture()
1351 return (wxWindow
*)g_captureWindow
;
1355 // Find the wxWindow at the current mouse position, returning the mouse
1357 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1359 return wxFindWindowAtPoint(wxGetMousePosition());
1362 // Get the current mouse position.
1363 wxPoint
wxGetMousePosition()
1367 return wxPoint(0, 0);
1369 Display
*display
= wxGlobalDisplay();
1370 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1371 Window rootReturn
, childReturn
;
1372 int rootX
, rootY
, winX
, winY
;
1373 unsigned int maskReturn
;
1375 XQueryPointer (display
,
1379 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1380 return wxPoint(rootX
, rootY
);
1385 // ----------------------------------------------------------------------------
1386 // wxNoOptimize: switch off size optimization
1387 // ----------------------------------------------------------------------------
1389 int wxNoOptimize::ms_count
= 0;