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
);
134 m_foregroundColour
= *wxBLACK
;
135 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
138 Window parentWindow
= (Window
) parent
->GetMainWindow();
152 Window window
= XCreateSimpleWindow(
153 xdisplay
, parentWindow
,
154 pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 0,
155 m_backgroundColour
.GetPixel(),
156 m_backgroundColour
.GetPixel() );
158 m_mainWidget
= (WXWindow
) window
;
160 // Select event types wanted
161 XSelectInput( wxGlobalDisplay(), window
,
162 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
163 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
164 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
167 wxAddWindowToTable(window
, (wxWindow
*) this);
169 // Is a subwindow, so map immediately
171 XMapWindow(wxGlobalDisplay(), window
);
173 // Without this, the cursor may not be restored properly (e.g. in splitter
175 SetCursor(*wxSTANDARD_CURSOR
);
176 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
178 // Don't call this, it can have nasty repercussions for composite controls,
180 // SetSize(pos.x, pos.y, size.x, size.y);
186 wxWindowX11::~wxWindowX11()
188 if (g_captureWindow
== this)
189 g_captureWindow
= NULL
;
191 m_isBeingDeleted
= TRUE
;
193 // X11-specific actions first
194 Window main
= (Window
) m_mainWidget
;
197 // Removes event handlers
198 //DetachWidget(main);
202 m_parent
->RemoveChild( this );
206 // Destroy the window
209 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
210 wxDeleteWindowFromTable( main
);
211 XDestroyWindow( wxGlobalDisplay(), main
);
216 // ---------------------------------------------------------------------------
218 // ---------------------------------------------------------------------------
220 void wxWindowX11::SetFocus()
222 Window xwindow
= (Window
) GetMainWindow();
224 wxCHECK_RET( xwindow
, wxT("invalid window") );
226 if (wxWindowIsVisible(xwindow
))
228 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
229 m_needsInputFocus
= FALSE
;
233 m_needsInputFocus
= TRUE
;
237 // Get the window with the focus
238 wxWindow
*wxWindowBase::FindFocus()
240 Window xfocus
= (Window
) 0;
243 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
246 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
254 // Enabling/disabling handled by event loop, and not sending events
256 bool wxWindowX11::Enable(bool enable
)
258 if ( !wxWindowBase::Enable(enable
) )
264 bool wxWindowX11::Show(bool show
)
266 wxWindowBase::Show(show
);
268 Window xwin
= (Window
) GetXWindow();
269 Display
*xdisp
= (Display
*) GetXDisplay();
273 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
275 XMapWindow(xdisp
, xwin
);
281 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
283 XUnmapWindow(xdisp
, xwin
);
289 // Raise the window to the top of the Z order
290 void wxWindowX11::Raise()
293 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
296 // Lower the window to the bottom of the Z order
297 void wxWindowX11::Lower()
300 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
303 void wxWindowX11::DoCaptureMouse()
305 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
307 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
318 Window xwindow
= (Window
) GetMainWindow();
320 wxCHECK_RET( xwindow
, wxT("invalid window") );
322 g_captureWindow
= (wxWindow
*) this;
326 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
328 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
332 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
335 if (res
!= GrabSuccess
)
338 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
340 if (res
== GrabNotViewable
)
342 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
344 g_captureWindow
= NULL
;
348 wxLogDebug("Grabbed pointer");
351 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
352 (Window
) GetMainWindow(),
354 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
360 if (res
!= GrabSuccess
)
362 wxLogDebug("Failed to grab mouse buttons.");
363 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
369 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
370 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
376 if (res
!= GrabSuccess
)
378 wxLogDebug("Failed to grab keyboard.");
379 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
380 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
381 (Window
) GetMainWindow());
386 m_winCaptured
= TRUE
;
390 void wxWindowX11::DoReleaseMouse()
392 g_captureWindow
= NULL
;
394 if ( !m_winCaptured
)
397 Window xwindow
= (Window
) GetMainWindow();
401 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
403 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
404 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
407 wxLogDebug("Ungrabbed pointer");
409 m_winCaptured
= FALSE
;
412 bool wxWindowX11::SetFont(const wxFont
& font
)
414 if ( !wxWindowBase::SetFont(font
) )
423 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
425 if ( !wxWindowBase::SetCursor(cursor
) )
431 Window xwindow
= (Window
) GetMainWindow();
433 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
435 wxCursor cursorToUse
;
437 cursorToUse
= m_cursor
;
439 cursorToUse
= *wxSTANDARD_CURSOR
;
441 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
443 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
448 // Coordinates relative to the window
449 void wxWindowX11::WarpPointer (int x
, int y
)
451 Window xwindow
= (Window
) GetMainWindow();
453 wxCHECK_RET( xwindow
, wxT("invalid window") );
455 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
458 // Does a physical scroll
459 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
465 // Use specified rectangle
466 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
470 // Use whole client area
472 GetClientSize(& w
, & h
);
475 wxNode
*cnode
= m_children
.First();
478 wxWindow
*child
= (wxWindow
*) cnode
->Data();
481 child
->GetSize( &sx
, &sy
);
482 wxPoint
pos( child
->GetPosition() );
483 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
484 cnode
= cnode
->Next();
487 int x1
= (dx
>= 0) ? x
: x
- dx
;
488 int y1
= (dy
>= 0) ? y
: y
- dy
;
489 int w1
= w
- abs(dx
);
490 int h1
= h
- abs(dy
);
491 int x2
= (dx
>= 0) ? x
+ dx
: x
;
492 int y2
= (dy
>= 0) ? y
+ dy
: y
;
494 wxClientDC
dc((wxWindow
*) this);
496 dc
.SetLogicalFunction (wxCOPY
);
498 Window window
= (Window
) GetMainWindow();
499 Display
* display
= wxGlobalDisplay();
501 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
502 x1
, y1
, w1
, h1
, x2
, y2
);
504 dc
.SetAutoSetting(TRUE
);
505 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
506 dc
.SetBrush(brush
); // FIXME: needed?
508 // We'll add rectangles to the list of update rectangles according to which
509 // bits we've exposed.
514 wxRect
*rect
= new wxRect
;
520 XFillRectangle(display
, window
,
521 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
525 rect
->width
= rect
->width
;
526 rect
->height
= rect
->height
;
528 updateRects
.Append((wxObject
*) rect
);
532 wxRect
*rect
= new wxRect
;
534 rect
->x
= x
+ w
+ dx
;
539 XFillRectangle(display
, window
,
540 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
545 rect
->width
= rect
->width
;
546 rect
->height
= rect
->height
;
548 updateRects
.Append((wxObject
*) rect
);
552 wxRect
*rect
= new wxRect
;
559 XFillRectangle(display
, window
,
560 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
564 rect
->width
= rect
->width
;
565 rect
->height
= rect
->height
;
567 updateRects
.Append((wxObject
*) rect
);
571 wxRect
*rect
= new wxRect
;
574 rect
->y
= y
+ h
+ dy
;
578 XFillRectangle(display
, window
,
579 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
583 rect
->width
= rect
->width
;
584 rect
->height
= rect
->height
;
586 updateRects
.Append((wxObject
*) rect
);
588 dc
.SetBrush(wxNullBrush
);
590 // Now send expose events
592 wxNode
* node
= updateRects
.First();
595 wxRect
* rect
= (wxRect
*) node
->Data();
599 event
.display
= display
;
600 event
.send_event
= True
;
601 event
.window
= window
;
605 event
.width
= rect
->width
;
606 event
.height
= rect
->height
;
610 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
616 // Delete the update rects
617 node
= updateRects
.First();
620 wxRect
* rect
= (wxRect
*) node
->Data();
627 // ---------------------------------------------------------------------------
629 // ---------------------------------------------------------------------------
631 #if wxUSE_DRAG_AND_DROP
633 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
640 // Old style file-manager drag&drop
641 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
646 // ----------------------------------------------------------------------------
648 // ----------------------------------------------------------------------------
652 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
657 #endif // wxUSE_TOOLTIPS
659 // ---------------------------------------------------------------------------
660 // moving and resizing
661 // ---------------------------------------------------------------------------
663 bool wxWindowX11::PreResize()
669 void wxWindowX11::DoGetSize(int *x
, int *y
) const
671 Window xwindow
= (Window
) GetMainWindow();
673 wxCHECK_RET( xwindow
, wxT("invalid window") );
675 XSync(wxGlobalDisplay(), False
);
676 XWindowAttributes attr
;
677 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
682 *x
= attr
.width
/* + 2*m_borderSize */ ;
683 *y
= attr
.height
/* + 2*m_borderSize */ ;
687 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
689 Window window
= (Window
) m_mainWidget
;
692 XSync(wxGlobalDisplay(), False
);
693 XWindowAttributes attr
;
694 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
702 // We may be faking the client origin. So a window that's really at (0, 30)
703 // may appear (to wxWin apps) to be at (0, 0).
706 wxPoint
pt(GetParent()->GetClientAreaOrigin());
714 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
716 Display
*display
= wxGlobalDisplay();
717 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
718 Window thisWindow
= (Window
) m_mainWidget
;
723 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
726 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
728 Display
*display
= wxGlobalDisplay();
729 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
730 Window thisWindow
= (Window
) m_mainWidget
;
735 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
739 // Get size *available for subwindows* i.e. excluding menu bar etc.
740 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
742 Window window
= (Window
) m_mainWidget
;
746 XSync(wxGlobalDisplay(), False
);
747 XWindowAttributes attr
;
748 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
759 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
761 if (!GetMainWindow())
764 XWindowChanges windowChanges
;
767 windowChanges
.width
= 0;
768 windowChanges
.height
= 0;
769 windowChanges
.stack_mode
= 0;
772 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
775 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
779 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
782 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
786 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
788 windowChanges
.width
= width
/* - m_borderSize*2 */;
789 if (windowChanges
.width
== 0)
790 windowChanges
.width
= 1;
791 valueMask
|= CWWidth
;
793 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
795 windowChanges
.height
= height
/* -m_borderSize*2*/;
796 if (windowChanges
.height
== 0)
797 windowChanges
.height
= 1;
798 valueMask
|= CWHeight
;
801 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
802 valueMask
, & windowChanges
);
803 XSync(wxGlobalDisplay(), False
);
806 void wxWindowX11::DoSetClientSize(int width
, int height
)
808 if (!GetMainWindow())
811 XWindowChanges windowChanges
;
816 windowChanges
.width
= width
;
817 valueMask
|= CWWidth
;
821 windowChanges
.height
= height
;
822 valueMask
|= CWHeight
;
824 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
825 valueMask
, & windowChanges
);
826 XSync(wxGlobalDisplay(), False
);
829 // For implementation purposes - sometimes decorations make the client area
831 wxPoint
wxWindowX11::GetClientAreaOrigin() const
833 return wxPoint(0, 0);
836 // Makes an adjustment to the window position (for example, a frame that has
837 // a toolbar that it manages itself).
838 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
840 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
842 wxPoint
pt(GetParent()->GetClientAreaOrigin());
843 x
+= pt
.x
; y
+= pt
.y
;
847 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
854 XSizeHints sizeHints
;
857 if (minW
> -1 && minH
> -1)
859 sizeHints
.flags
|= PMinSize
;
860 sizeHints
.min_width
= minW
;
861 sizeHints
.min_height
= minH
;
863 if (maxW
> -1 && maxH
> -1)
865 sizeHints
.flags
|= PMaxSize
;
866 sizeHints
.max_width
= maxW
;
867 sizeHints
.max_height
= maxH
;
869 if (incW
> -1 && incH
> -1)
871 sizeHints
.flags
|= PResizeInc
;
872 sizeHints
.width_inc
= incW
;
873 sizeHints
.height_inc
= incH
;
876 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
879 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
881 DoSetSize(x
, y
, width
, height
);
884 // ---------------------------------------------------------------------------
886 // ---------------------------------------------------------------------------
888 int wxWindowX11::GetCharHeight() 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.ascent + overall.descent);
900 return (ascent
+ descent
);
903 int wxWindowX11::GetCharWidth() const
905 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
907 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
909 int direction
, ascent
, descent
;
911 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
914 return overall
.width
;
917 void wxWindowX11::GetTextExtent(const wxString
& string
,
919 int *descent
, int *externalLeading
,
920 const wxFont
*theFont
) const
922 wxFont fontToUse
= m_font
;
923 if (theFont
) fontToUse
= *theFont
;
925 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
927 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
929 int direction
, ascent
, descent2
;
931 int slen
= string
.Len();
935 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
936 &ascent
, &descent2
, &overall
);
939 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
940 &direction
, &ascent
, &descent2
, &overall
);
943 *x
= (overall
.width
);
945 *y
= (ascent
+ descent2
);
949 *externalLeading
= 0;
953 // ----------------------------------------------------------------------------
955 // ----------------------------------------------------------------------------
957 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
963 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
964 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
969 GetSize( &width
, &height
);
971 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
972 m_clearRegion
.Clear();
973 m_clearRegion
.Union( 0, 0, width
, height
);
979 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
980 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
985 GetSize( &width
, &height
);
987 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
988 m_updateRegion
.Clear();
989 m_updateRegion
.Union( 0, 0, width
, height
);
993 void wxWindowX11::Update()
995 if (!m_updateRegion
.IsEmpty())
997 X11SendPaintEvents();
1001 void wxWindowX11::Clear()
1003 wxClientDC
dc((wxWindow
*) this);
1004 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1005 dc
.SetBackground(brush
);
1009 void wxWindowX11::X11SendPaintEvents()
1011 m_clipPaintRegion
= TRUE
;
1013 // if (!m_clearRegion.IsEmpty())
1015 wxWindowDC
dc( (wxWindow
*)this );
1016 dc
.SetClippingRegion( m_clearRegion
);
1018 wxEraseEvent
erase_event( GetId(), &dc
);
1019 erase_event
.SetEventObject( this );
1021 if (!GetEventHandler()->ProcessEvent(erase_event
))
1023 wxRegionIterator
upd( m_clearRegion
);
1026 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
1027 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1031 m_clearRegion
.Clear();
1034 wxNcPaintEvent
nc_paint_event( GetId() );
1035 nc_paint_event
.SetEventObject( this );
1036 GetEventHandler()->ProcessEvent( nc_paint_event
);
1038 wxPaintEvent
paint_event( GetId() );
1039 paint_event
.SetEventObject( this );
1040 GetEventHandler()->ProcessEvent( paint_event
);
1042 m_updateRegion
.Clear();
1044 m_clipPaintRegion
= FALSE
;
1047 // ----------------------------------------------------------------------------
1049 // ----------------------------------------------------------------------------
1051 // Responds to colour changes: passes event on to children.
1052 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1054 wxWindowList::Node
*node
= GetChildren().GetFirst();
1057 // Only propagate to non-top-level windows
1058 wxWindow
*win
= node
->GetData();
1059 if ( win
->GetParent() )
1061 wxSysColourChangedEvent event2
;
1062 event
.m_eventObject
= win
;
1063 win
->GetEventHandler()->ProcessEvent(event2
);
1066 node
= node
->GetNext();
1070 void wxWindowX11::OnInternalIdle()
1072 // Update invalidated regions.
1075 // This calls the UI-update mechanism (querying windows for
1076 // menu/toolbar/control state information)
1079 // Set the input focus if couldn't do it before
1080 if (m_needsInputFocus
)
1084 // ----------------------------------------------------------------------------
1085 // function which maintain the global hash table mapping Widgets to wxWindows
1086 // ----------------------------------------------------------------------------
1088 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1090 wxWindow
*oldItem
= NULL
;
1091 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1093 wxLogDebug("Widget table clash: new widget is %ld, %s",
1094 (long)w
, win
->GetClassInfo()->GetClassName());
1098 wxWidgetHashTable
->Put((long) w
, win
);
1100 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1101 w
, win
, win
->GetClassInfo()->GetClassName());
1106 wxWindow
*wxGetWindowFromTable(Window w
)
1108 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1111 void wxDeleteWindowFromTable(Window w
)
1113 wxWidgetHashTable
->Delete((long)w
);
1116 // ----------------------------------------------------------------------------
1117 // add/remove window from the table
1118 // ----------------------------------------------------------------------------
1120 // ----------------------------------------------------------------------------
1121 // X11-specific accessors
1122 // ----------------------------------------------------------------------------
1124 // Get the underlying X window
1125 WXWindow
wxWindowX11::GetXWindow() const
1127 return GetMainWindow();
1130 // Get the underlying X display
1131 WXDisplay
*wxWindowX11::GetXDisplay() const
1133 return wxGetDisplay();
1136 WXWindow
wxWindowX11::GetMainWindow() const
1138 return m_mainWidget
;
1141 // ----------------------------------------------------------------------------
1142 // TranslateXXXEvent() functions
1143 // ----------------------------------------------------------------------------
1145 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1147 switch (xevent
->xany
.type
)
1155 wxEventType eventType
= wxEVT_NULL
;
1157 if (xevent
->xany
.type
== EnterNotify
)
1159 //if (local_event.xcrossing.mode!=NotifyNormal)
1160 // return ; // Ignore grab events
1161 eventType
= wxEVT_ENTER_WINDOW
;
1162 // canvas->GetEventHandler()->OnSetFocus();
1164 else if (xevent
->xany
.type
== LeaveNotify
)
1166 //if (local_event.xcrossingr.mode!=NotifyNormal)
1167 // return ; // Ignore grab events
1168 eventType
= wxEVT_LEAVE_WINDOW
;
1169 // canvas->GetEventHandler()->OnKillFocus();
1171 else if (xevent
->xany
.type
== MotionNotify
)
1173 eventType
= wxEVT_MOTION
;
1175 else if (xevent
->xany
.type
== ButtonPress
)
1177 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1179 if (xevent
->xbutton
.button
== Button1
)
1181 eventType
= wxEVT_LEFT_DOWN
;
1184 else if (xevent
->xbutton
.button
== Button2
)
1186 eventType
= wxEVT_MIDDLE_DOWN
;
1189 else if (xevent
->xbutton
.button
== Button3
)
1191 eventType
= wxEVT_RIGHT_DOWN
;
1195 // check for a double click
1196 // TODO: where can we get this value from?
1197 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1198 long dclickTime
= 200;
1199 long ts
= wxevent
.GetTimestamp();
1201 int buttonLast
= win
->GetLastClickedButton();
1202 long lastTS
= win
->GetLastClickTime();
1203 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1206 win
->SetLastClick(0, ts
);
1207 if ( eventType
== wxEVT_LEFT_DOWN
)
1208 eventType
= wxEVT_LEFT_DCLICK
;
1209 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1210 eventType
= wxEVT_MIDDLE_DCLICK
;
1211 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1212 eventType
= wxEVT_RIGHT_DCLICK
;
1216 // not fast enough or different button
1217 win
->SetLastClick(button
, ts
);
1220 else if (xevent
->xany
.type
== ButtonRelease
)
1222 if (xevent
->xbutton
.button
== Button1
)
1224 eventType
= wxEVT_LEFT_UP
;
1226 else if (xevent
->xbutton
.button
== Button2
)
1228 eventType
= wxEVT_MIDDLE_UP
;
1230 else if (xevent
->xbutton
.button
== Button3
)
1232 eventType
= wxEVT_RIGHT_UP
;
1241 wxevent
.SetEventType(eventType
);
1243 wxevent
.m_x
= xevent
->xbutton
.x
;
1244 wxevent
.m_y
= xevent
->xbutton
.y
;
1246 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1247 || (event_left_is_down (xevent
)
1248 && (eventType
!= wxEVT_LEFT_UP
)));
1249 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1250 || (event_middle_is_down (xevent
)
1251 && (eventType
!= wxEVT_MIDDLE_UP
)));
1252 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1253 || (event_right_is_down (xevent
)
1254 && (eventType
!= wxEVT_RIGHT_UP
)));
1256 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1257 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1258 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1259 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1261 wxevent
.SetId(win
->GetId());
1262 wxevent
.SetEventObject(win
);
1270 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1272 switch (xevent
->xany
.type
)
1280 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1281 int id
= wxCharCodeXToWX (keySym
);
1283 if (xevent
->xkey
.state
& ShiftMask
)
1284 wxevent
.m_shiftDown
= TRUE
;
1285 if (xevent
->xkey
.state
& ControlMask
)
1286 wxevent
.m_controlDown
= TRUE
;
1287 if (xevent
->xkey
.state
& Mod3Mask
)
1288 wxevent
.m_altDown
= TRUE
;
1289 if (xevent
->xkey
.state
& Mod1Mask
)
1290 wxevent
.m_metaDown
= TRUE
;
1291 wxevent
.SetEventObject(win
);
1292 wxevent
.m_keyCode
= id
;
1293 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1295 wxevent
.m_x
= xevent
->xbutton
.x
;
1296 wxevent
.m_y
= xevent
->xbutton
.y
;
1310 // ----------------------------------------------------------------------------
1312 // ----------------------------------------------------------------------------
1314 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1316 wxWindowBase::SetBackgroundColour(col
);
1318 if (!GetMainWindow())
1321 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1322 int xscreen
= DefaultScreen( xdisplay
);
1323 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1325 wxColour
colour( col
);
1326 colour
.CalcPixel( (WXColormap
) cm
);
1328 XSetWindowAttributes attrib
;
1329 attrib
.background_pixel
= colour
.GetPixel();
1331 XChangeWindowAttributes(wxGlobalDisplay(),
1332 (Window
) GetMainWindow(),
1339 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1341 if ( !wxWindowBase::SetForegroundColour(col
) )
1347 // ----------------------------------------------------------------------------
1349 // ----------------------------------------------------------------------------
1351 wxWindow
*wxGetActiveWindow()
1354 wxFAIL_MSG("Not implemented");
1359 wxWindow
*wxWindowBase::GetCapture()
1361 return (wxWindow
*)g_captureWindow
;
1365 // Find the wxWindow at the current mouse position, returning the mouse
1367 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1369 return wxFindWindowAtPoint(wxGetMousePosition());
1372 // Get the current mouse position.
1373 wxPoint
wxGetMousePosition()
1375 Display
*display
= wxGlobalDisplay();
1376 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1377 Window rootReturn
, childReturn
;
1378 int rootX
, rootY
, winX
, winY
;
1379 unsigned int maskReturn
;
1381 XQueryPointer (display
,
1385 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1386 return wxPoint(rootX
, rootY
);
1390 // ----------------------------------------------------------------------------
1391 // wxNoOptimize: switch off size optimization
1392 // ----------------------------------------------------------------------------
1394 int wxNoOptimize::ms_count
= 0;