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"
52 // ----------------------------------------------------------------------------
53 // global variables for this module
54 // ----------------------------------------------------------------------------
56 extern wxHashTable
*wxWidgetHashTable
;
57 static wxWindow
* g_captureWindow
= NULL
;
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
73 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowX11
::OnSysColourChanged
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 void wxWindowX11
::Init()
91 // generic initializations first
95 m_mainWidget
= (WXWindow
) 0;
96 m_winCaptured
= FALSE
;
97 m_needsInputFocus
= FALSE
;
99 m_isBeingDeleted
= FALSE
;
104 // real construction (Init() must have been called before!)
105 bool wxWindowX11
::Create(wxWindow
*parent
, wxWindowID id
,
109 const wxString
& name
)
111 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
113 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
115 parent
->AddChild(this);
117 int w
= size
.GetWidth();
118 int h
= size
.GetHeight();
126 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
127 int xscreen
= DefaultScreen( xdisplay
);
128 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
130 m_backgroundColour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
131 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
133 m_foregroundColour
= *wxBLACK
;
134 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
136 Window parentWindow
= (Window
) parent
->GetMainWindow();
150 Window xwindow
= XCreateSimpleWindow(
151 xdisplay
, parentWindow
,
152 pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 0,
153 m_backgroundColour
.GetPixel(),
154 m_backgroundColour
.GetPixel() );
156 m_mainWidget
= (WXWindow
) xwindow
;
158 // Select event types wanted
159 XSelectInput( xdisplay
, xwindow
,
160 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
161 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
162 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
165 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
167 // Is a subwindow, so map immediately
169 XMapWindow( xdisplay
, xwindow
);
171 // Without this, the cursor may not be restored properly (e.g. in splitter
173 SetCursor(*wxSTANDARD_CURSOR
);
174 SetFont(wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
));
176 // Set background to None which will prevent X11 from clearing the
177 // background comletely.
178 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
180 // Don't call this, it can have nasty repercussions for composite controls,
182 // SetSize(pos.x, pos.y, size.x, size.y);
188 wxWindowX11
::~wxWindowX11()
190 if (g_captureWindow
== this)
191 g_captureWindow
= NULL
;
193 m_isBeingDeleted
= TRUE
;
195 // X11-specific actions first
196 Window main
= (Window
) m_mainWidget
;
199 // Removes event handlers
200 //DetachWidget(main);
204 m_parent
->RemoveChild( this );
208 // Destroy the window
211 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
212 wxDeleteWindowFromTable( main
);
213 XDestroyWindow( wxGlobalDisplay(), main
);
218 // ---------------------------------------------------------------------------
220 // ---------------------------------------------------------------------------
222 void wxWindowX11
::SetFocus()
224 Window xwindow
= (Window
) GetMainWindow();
226 wxCHECK_RET( xwindow
, wxT("invalid window") );
228 if (wxWindowIsVisible(xwindow
))
230 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
231 m_needsInputFocus
= FALSE
;
235 m_needsInputFocus
= TRUE
;
239 // Get the window with the focus
240 wxWindow
*wxWindowBase
::FindFocus()
242 Window xfocus
= (Window
) 0;
245 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
248 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
257 wxWindow
*wxWindowX11
::GetFocusWidget()
259 wxWindow
*win
= (wxWindow
*) this;
260 while (!win
->IsTopLevel())
262 win
= win
->GetParent();
264 return (wxWindow
*) NULL
;
271 // Enabling/disabling handled by event loop, and not sending events
273 bool wxWindowX11
::Enable(bool enable
)
275 if ( !wxWindowBase
::Enable(enable
) )
281 bool wxWindowX11
::Show(bool show
)
283 wxWindowBase
::Show(show
);
285 Window xwin
= (Window
) GetXWindow();
286 Display
*xdisp
= (Display
*) GetXDisplay();
290 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
292 XMapWindow(xdisp
, xwin
);
298 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
300 XUnmapWindow(xdisp
, xwin
);
306 // Raise the window to the top of the Z order
307 void wxWindowX11
::Raise()
310 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
313 // Lower the window to the bottom of the Z order
314 void wxWindowX11
::Lower()
317 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
320 void wxWindowX11
::DoCaptureMouse()
322 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
324 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
335 Window xwindow
= (Window
) GetMainWindow();
337 wxCHECK_RET( xwindow
, wxT("invalid window") );
339 g_captureWindow
= (wxWindow
*) this;
343 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
345 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
349 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
352 if (res
!= GrabSuccess
)
355 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
357 if (res
== GrabNotViewable
)
359 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
361 g_captureWindow
= NULL
;
365 wxLogDebug("Grabbed pointer");
368 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
369 (Window
) GetMainWindow(),
371 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
377 if (res
!= GrabSuccess
)
379 wxLogDebug("Failed to grab mouse buttons.");
380 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
386 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
387 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
393 if (res
!= GrabSuccess
)
395 wxLogDebug("Failed to grab keyboard.");
396 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
397 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
398 (Window
) GetMainWindow());
403 m_winCaptured
= TRUE
;
407 void wxWindowX11
::DoReleaseMouse()
409 g_captureWindow
= NULL
;
411 if ( !m_winCaptured
)
414 Window xwindow
= (Window
) GetMainWindow();
418 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
420 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
421 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
424 wxLogDebug("Ungrabbed pointer");
426 m_winCaptured
= FALSE
;
429 bool wxWindowX11
::SetFont(const wxFont
& font
)
431 if ( !wxWindowBase
::SetFont(font
) )
440 bool wxWindowX11
::SetCursor(const wxCursor
& cursor
)
442 if ( !wxWindowBase
::SetCursor(cursor
) )
448 Window xwindow
= (Window
) GetMainWindow();
450 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
452 wxCursor cursorToUse
;
454 cursorToUse
= m_cursor
;
456 cursorToUse
= *wxSTANDARD_CURSOR
;
458 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
460 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
465 // Coordinates relative to the window
466 void wxWindowX11
::WarpPointer (int x
, int y
)
468 Window xwindow
= (Window
) GetMainWindow();
470 wxCHECK_RET( xwindow
, wxT("invalid window") );
472 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
475 // Does a physical scroll
476 void wxWindowX11
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
478 // No scrolling requested.
479 if ((dx
== 0) && (dy
== 0)) return;
481 if (!m_updateRegion
.IsEmpty())
483 m_updateRegion
.Offset( dx
, dy
);
487 GetSize( &cw
, &ch
); // GetClientSize() ??
488 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
491 if (!m_clearRegion
.IsEmpty())
493 m_clearRegion
.Offset( dx
, dy
);
497 GetSize( &cw
, &ch
); // GetClientSize() ??
498 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
501 Window xwindow
= (Window
) GetMainWindow();
503 wxCHECK_RET( xwindow
, wxT("invalid window") );
505 Display
*xdisplay
= wxGlobalDisplay();
507 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
508 XSetGraphicsExposures( xdisplay
, xgc
, True
);
525 GetClientSize( &cw
, &ch
);
528 wxPoint offset
= GetClientAreaOrigin();
532 int w
= cw
- abs(dx
);
533 int h
= ch
- abs(dy
);
535 if ((h
< 0) || (w
< 0))
542 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
543 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
544 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
545 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
549 if (dx
< 0) s_x
+= -dx
;
550 if (dy
< 0) s_y
+= -dy
;
551 if (dx
> 0) d_x
= dx
;
552 if (dy
> 0) d_y
= dy
;
554 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
556 // 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 );
558 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
560 m_updateRegion
.Union( rect
);
561 m_clearRegion
.Union( rect
);
564 XFreeGC( xdisplay
, xgc
);
567 // ---------------------------------------------------------------------------
569 // ---------------------------------------------------------------------------
571 #if wxUSE_DRAG_AND_DROP
573 void wxWindowX11
::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
580 // Old style file-manager drag&drop
581 void wxWindowX11
::DragAcceptFiles(bool WXUNUSED(accept
))
586 // ----------------------------------------------------------------------------
588 // ----------------------------------------------------------------------------
592 void wxWindowX11
::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
597 #endif // wxUSE_TOOLTIPS
599 // ---------------------------------------------------------------------------
600 // moving and resizing
601 // ---------------------------------------------------------------------------
603 bool wxWindowX11
::PreResize()
609 void wxWindowX11
::DoGetSize(int *x
, int *y
) const
611 Window xwindow
= (Window
) GetMainWindow();
613 wxCHECK_RET( xwindow
, wxT("invalid window") );
615 XSync(wxGlobalDisplay(), False
);
617 XWindowAttributes attr
;
618 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
623 *x
= attr
.width
/* + 2*m_borderSize */ ;
624 *y
= attr
.height
/* + 2*m_borderSize */ ;
628 void wxWindowX11
::DoGetPosition(int *x
, int *y
) const
630 Window window
= (Window
) m_mainWidget
;
633 XSync(wxGlobalDisplay(), False
);
634 XWindowAttributes attr
;
635 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
643 // We may be faking the client origin. So a window that's really at (0, 30)
644 // may appear (to wxWin apps) to be at (0, 0).
647 wxPoint
pt(GetParent()->GetClientAreaOrigin());
655 void wxWindowX11
::DoScreenToClient(int *x
, int *y
) const
657 Display
*display
= wxGlobalDisplay();
658 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
659 Window thisWindow
= (Window
) m_mainWidget
;
664 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
667 void wxWindowX11
::DoClientToScreen(int *x
, int *y
) const
669 Display
*display
= wxGlobalDisplay();
670 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
671 Window thisWindow
= (Window
) m_mainWidget
;
676 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
680 // Get size *available for subwindows* i.e. excluding menu bar etc.
681 void wxWindowX11
::DoGetClientSize(int *x
, int *y
) const
683 Window window
= (Window
) m_mainWidget
;
687 XSync(wxGlobalDisplay(), False
); // Is this really a good idea?
688 XWindowAttributes attr
;
689 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
700 void wxWindowX11
::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
702 Window xwindow
= (Window
) GetMainWindow();
704 wxCHECK_RET( xwindow
, wxT("invalid window") );
706 XWindowAttributes attr
;
707 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
708 wxCHECK_RET( status
, wxT("invalid window attributes") );
712 int new_w
= attr
.width
;
713 int new_h
= attr
.height
;
716 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
719 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
722 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
725 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
741 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
744 void wxWindowX11
::DoSetClientSize(int width
, int height
)
746 Window xwindow
= (Window
) GetMainWindow();
748 wxCHECK_RET( xwindow
, wxT("invalid window") );
750 XWindowAttributes attr
;
751 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
752 wxCHECK_RET( status
, wxT("invalid window attributes") );
756 int new_w
= attr
.width
;
757 int new_h
= attr
.height
;
765 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
768 // For implementation purposes - sometimes decorations make the client area
770 wxPoint wxWindowX11
::GetClientAreaOrigin() const
772 return wxPoint(0, 0);
775 // Makes an adjustment to the window position (for example, a frame that has
776 // a toolbar that it manages itself).
777 void wxWindowX11
::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
779 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
781 wxPoint
pt(GetParent()->GetClientAreaOrigin());
782 x
+= pt
.x
; y
+= pt
.y
;
786 void wxWindowX11
::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
793 XSizeHints sizeHints
;
796 if (minW
> -1 && minH
> -1)
798 sizeHints
.flags
|= PMinSize
;
799 sizeHints
.min_width
= minW
;
800 sizeHints
.min_height
= minH
;
802 if (maxW
> -1 && maxH
> -1)
804 sizeHints
.flags
|= PMaxSize
;
805 sizeHints
.max_width
= maxW
;
806 sizeHints
.max_height
= maxH
;
808 if (incW
> -1 && incH
> -1)
810 sizeHints
.flags
|= PResizeInc
;
811 sizeHints
.width_inc
= incW
;
812 sizeHints
.height_inc
= incH
;
815 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
818 void wxWindowX11
::DoMoveWindow(int x
, int y
, int width
, int height
)
820 Window xwindow
= (Window
) GetMainWindow();
822 wxCHECK_RET( xwindow
, wxT("invalid window") );
824 XWindowChanges windowChanges
;
827 windowChanges
.width
= width
;
828 windowChanges
.height
= height
;
829 windowChanges
.stack_mode
= 0;
830 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
832 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
835 // ---------------------------------------------------------------------------
837 // ---------------------------------------------------------------------------
839 int wxWindowX11
::GetCharHeight() const
841 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
843 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
845 int direction
, ascent
, descent
;
847 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
850 // return (overall.ascent + overall.descent);
851 return (ascent
+ descent
);
854 int wxWindowX11
::GetCharWidth() const
856 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
858 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
860 int direction
, ascent
, descent
;
862 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
865 return overall
.width
;
868 void wxWindowX11
::GetTextExtent(const wxString
& string
,
870 int *descent
, int *externalLeading
,
871 const wxFont
*theFont
) const
873 wxFont fontToUse
= m_font
;
874 if (theFont
) fontToUse
= *theFont
;
876 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
878 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
880 int direction
, ascent
, descent2
;
882 int slen
= string
.Len();
886 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
887 &ascent
, &descent2
, &overall
);
890 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
891 &direction
, &ascent
, &descent2
, &overall
);
894 *x
= (overall
.width
);
896 *y
= (ascent
+ descent2
);
900 *externalLeading
= 0;
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 void wxWindowX11
::Refresh(bool eraseBack
, const wxRect
*rect
)
914 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
915 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
920 GetSize( &width
, &height
);
922 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
923 m_clearRegion
.Clear();
924 m_clearRegion
.Union( 0, 0, width
, height
);
930 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
931 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
936 GetSize( &width
, &height
);
938 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
939 m_updateRegion
.Clear();
940 m_updateRegion
.Union( 0, 0, width
, height
);
944 void wxWindowX11
::Update()
946 if (!m_updateRegion
.IsEmpty())
948 // Actually send erase and paint events.
949 X11SendPaintEvents();
953 void wxWindowX11
::Clear()
955 wxClientDC
dc((wxWindow
*) this);
956 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
957 dc
.SetBackground(brush
);
961 void wxWindowX11
::X11SendPaintEvents()
963 m_clipPaintRegion
= TRUE
;
965 if (!m_clearRegion
.IsEmpty())
967 wxWindowDC
dc( (wxWindow
*)this );
968 dc
.SetClippingRegion( m_clearRegion
);
970 wxEraseEvent
erase_event( GetId(), &dc
);
971 erase_event
.SetEventObject( this );
973 if (!GetEventHandler()->ProcessEvent(erase_event
))
975 Window xwindow
= (Window
) GetMainWindow();
976 Display
*xdisplay
= wxGlobalDisplay();
977 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
978 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
979 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
980 wxRegionIterator
upd( m_clearRegion
);
983 XFillRectangle( xdisplay
, xwindow
, xgc
,
984 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
987 XFreeGC( xdisplay
, xgc
);
989 m_clearRegion
.Clear();
992 wxNcPaintEvent
nc_paint_event( GetId() );
993 nc_paint_event
.SetEventObject( this );
994 GetEventHandler()->ProcessEvent( nc_paint_event
);
996 wxPaintEvent
paint_event( GetId() );
997 paint_event
.SetEventObject( this );
998 GetEventHandler()->ProcessEvent( paint_event
);
1000 m_updateRegion
.Clear();
1002 m_clipPaintRegion
= FALSE
;
1005 // ----------------------------------------------------------------------------
1007 // ----------------------------------------------------------------------------
1009 // Responds to colour changes: passes event on to children.
1010 void wxWindowX11
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1012 wxWindowList
::Node
*node
= GetChildren().GetFirst();
1015 // Only propagate to non-top-level windows
1016 wxWindow
*win
= node
->GetData();
1017 if ( win
->GetParent() )
1019 wxSysColourChangedEvent event2
;
1020 event
.m_eventObject
= win
;
1021 win
->GetEventHandler()->ProcessEvent(event2
);
1024 node
= node
->GetNext();
1028 void wxWindowX11
::OnInternalIdle()
1030 // Update invalidated regions.
1033 // This calls the UI-update mechanism (querying windows for
1034 // menu/toolbar/control state information)
1037 // Set the input focus if couldn't do it before
1038 if (m_needsInputFocus
)
1042 // ----------------------------------------------------------------------------
1043 // function which maintain the global hash table mapping Widgets to wxWindows
1044 // ----------------------------------------------------------------------------
1046 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1048 wxWindow
*oldItem
= NULL
;
1049 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1051 wxLogDebug("Widget table clash: new widget is %ld, %s",
1052 (long)w
, win
->GetClassInfo()->GetClassName());
1056 wxWidgetHashTable
->Put((long) w
, win
);
1058 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1059 w
, win
, win
->GetClassInfo()->GetClassName());
1064 wxWindow
*wxGetWindowFromTable(Window w
)
1066 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1069 void wxDeleteWindowFromTable(Window w
)
1071 wxWidgetHashTable
->Delete((long)w
);
1074 // ----------------------------------------------------------------------------
1075 // add/remove window from the table
1076 // ----------------------------------------------------------------------------
1078 // ----------------------------------------------------------------------------
1079 // X11-specific accessors
1080 // ----------------------------------------------------------------------------
1082 // Get the underlying X window
1083 WXWindow wxWindowX11
::GetXWindow() const
1085 return GetMainWindow();
1088 // Get the underlying X display
1089 WXDisplay
*wxWindowX11
::GetXDisplay() const
1091 return wxGetDisplay();
1094 WXWindow wxWindowX11
::GetMainWindow() const
1096 return m_mainWidget
;
1099 // ----------------------------------------------------------------------------
1100 // TranslateXXXEvent() functions
1101 // ----------------------------------------------------------------------------
1103 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1105 switch (xevent
->xany
.type
)
1113 wxEventType eventType
= wxEVT_NULL
;
1115 if (xevent
->xany
.type
== EnterNotify
)
1117 //if (local_event.xcrossing.mode!=NotifyNormal)
1118 // return ; // Ignore grab events
1119 eventType
= wxEVT_ENTER_WINDOW
;
1120 // canvas->GetEventHandler()->OnSetFocus();
1122 else if (xevent
->xany
.type
== LeaveNotify
)
1124 //if (local_event.xcrossingr.mode!=NotifyNormal)
1125 // return ; // Ignore grab events
1126 eventType
= wxEVT_LEAVE_WINDOW
;
1127 // canvas->GetEventHandler()->OnKillFocus();
1129 else if (xevent
->xany
.type
== MotionNotify
)
1131 eventType
= wxEVT_MOTION
;
1133 else if (xevent
->xany
.type
== ButtonPress
)
1135 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1137 if (xevent
->xbutton
.button
== Button1
)
1139 eventType
= wxEVT_LEFT_DOWN
;
1142 else if (xevent
->xbutton
.button
== Button2
)
1144 eventType
= wxEVT_MIDDLE_DOWN
;
1147 else if (xevent
->xbutton
.button
== Button3
)
1149 eventType
= wxEVT_RIGHT_DOWN
;
1153 // check for a double click
1154 // TODO: where can we get this value from?
1155 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1156 long dclickTime
= 200;
1157 long ts
= wxevent
.GetTimestamp();
1159 int buttonLast
= win
->GetLastClickedButton();
1160 long lastTS
= win
->GetLastClickTime();
1161 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1164 win
->SetLastClick(0, ts
);
1165 if ( eventType
== wxEVT_LEFT_DOWN
)
1166 eventType
= wxEVT_LEFT_DCLICK
;
1167 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1168 eventType
= wxEVT_MIDDLE_DCLICK
;
1169 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1170 eventType
= wxEVT_RIGHT_DCLICK
;
1174 // not fast enough or different button
1175 win
->SetLastClick(button
, ts
);
1178 else if (xevent
->xany
.type
== ButtonRelease
)
1180 if (xevent
->xbutton
.button
== Button1
)
1182 eventType
= wxEVT_LEFT_UP
;
1184 else if (xevent
->xbutton
.button
== Button2
)
1186 eventType
= wxEVT_MIDDLE_UP
;
1188 else if (xevent
->xbutton
.button
== Button3
)
1190 eventType
= wxEVT_RIGHT_UP
;
1199 wxevent
.SetEventType(eventType
);
1201 wxevent
.m_x
= xevent
->xbutton
.x
;
1202 wxevent
.m_y
= xevent
->xbutton
.y
;
1204 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1205 || (event_left_is_down (xevent
)
1206 && (eventType
!= wxEVT_LEFT_UP
)));
1207 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1208 || (event_middle_is_down (xevent
)
1209 && (eventType
!= wxEVT_MIDDLE_UP
)));
1210 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1211 || (event_right_is_down (xevent
)
1212 && (eventType
!= wxEVT_RIGHT_UP
)));
1214 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1215 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1216 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1217 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1219 wxevent
.SetId(win
->GetId());
1220 wxevent
.SetEventObject(win
);
1228 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1230 switch (xevent
->xany
.type
)
1238 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1239 int id
= wxCharCodeXToWX (keySym
);
1241 if (xevent
->xkey
.state
& ShiftMask
)
1242 wxevent
.m_shiftDown
= TRUE
;
1243 if (xevent
->xkey
.state
& ControlMask
)
1244 wxevent
.m_controlDown
= TRUE
;
1245 if (xevent
->xkey
.state
& Mod3Mask
)
1246 wxevent
.m_altDown
= TRUE
;
1247 if (xevent
->xkey
.state
& Mod1Mask
)
1248 wxevent
.m_metaDown
= TRUE
;
1249 wxevent
.SetEventObject(win
);
1250 wxevent
.m_keyCode
= id
;
1251 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1253 wxevent
.m_x
= xevent
->xbutton
.x
;
1254 wxevent
.m_y
= xevent
->xbutton
.y
;
1268 // ----------------------------------------------------------------------------
1270 // ----------------------------------------------------------------------------
1272 bool wxWindowX11
::SetBackgroundColour(const wxColour
& col
)
1274 wxWindowBase
::SetBackgroundColour(col
);
1276 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1277 int xscreen
= DefaultScreen( xdisplay
);
1278 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1280 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1282 if (!GetMainWindow())
1286 XSetWindowAttributes attrib;
1287 attrib.background_pixel = colour.GetPixel();
1289 XChangeWindowAttributes(wxGlobalDisplay(),
1290 (Window) GetMainWindow(),
1298 bool wxWindowX11
::SetForegroundColour(const wxColour
& col
)
1300 if ( !wxWindowBase
::SetForegroundColour(col
) )
1306 // ----------------------------------------------------------------------------
1308 // ----------------------------------------------------------------------------
1310 wxWindow
*wxGetActiveWindow()
1313 wxFAIL_MSG("Not implemented");
1318 wxWindow
*wxWindowBase
::GetCapture()
1320 return (wxWindow
*)g_captureWindow
;
1324 // Find the wxWindow at the current mouse position, returning the mouse
1326 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1328 return wxFindWindowAtPoint(wxGetMousePosition());
1331 // Get the current mouse position.
1332 wxPoint
wxGetMousePosition()
1334 Display
*display
= wxGlobalDisplay();
1335 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1336 Window rootReturn
, childReturn
;
1337 int rootX
, rootY
, winX
, winY
;
1338 unsigned int maskReturn
;
1340 XQueryPointer (display
,
1344 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1345 return wxPoint(rootX
, rootY
);
1349 // ----------------------------------------------------------------------------
1350 // wxNoOptimize: switch off size optimization
1351 // ----------------------------------------------------------------------------
1353 int wxNoOptimize
::ms_count
= 0;