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;
97 m_winCaptured
= FALSE
;
100 m_isBeingDeleted
= FALSE
;
106 // real construction (Init() must have been called before!)
107 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
111 const wxString
& name
)
113 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
115 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
117 parent
->AddChild(this);
119 int w
= size
.GetWidth();
120 int h
= size
.GetHeight();
128 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
129 int xscreen
= DefaultScreen( xdisplay
);
130 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
132 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
133 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
136 m_foregroundColour
= *wxBLACK
;
137 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
140 Window parentWindow
= (Window
) parent
->GetMainWindow();
142 Window window
= XCreateSimpleWindow(
143 xdisplay
, parentWindow
,
145 m_backgroundColour
.GetPixel(),
146 m_backgroundColour
.GetPixel() );
148 m_mainWidget
= (WXWindow
) window
;
150 // Select event types wanted
151 XSelectInput( wxGlobalDisplay(), window
,
152 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
153 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
154 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
157 wxAddWindowToTable(window
, (wxWindow
*) this);
159 // Is a subwindow, so map immediately
161 XMapWindow(wxGlobalDisplay(), window
);
163 // Without this, the cursor may not be restored properly (e.g. in splitter
165 SetCursor(*wxSTANDARD_CURSOR
);
166 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
167 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
173 wxWindowX11::~wxWindowX11()
175 if (g_captureWindow
== this)
176 g_captureWindow
= NULL
;
178 m_isBeingDeleted
= TRUE
;
180 // X11-specific actions first
181 Window main
= (Window
) m_mainWidget
;
184 // Removes event handlers
185 //DetachWidget(main);
189 m_parent
->RemoveChild( this );
193 // Destroy the window
196 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
197 wxDeleteWindowFromTable( main
);
198 XDestroyWindow( wxGlobalDisplay(), main
);
203 // ---------------------------------------------------------------------------
205 // ---------------------------------------------------------------------------
207 void wxWindowX11::SetFocus()
209 Window xwindow
= (Window
) GetMainWindow();
211 wxCHECK_RET( xwindow
, wxT("invalid window") );
213 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
216 // Get the window with the focus
217 wxWindow
*wxWindowBase::FindFocus()
219 Window xfocus
= (Window
) 0;
222 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
225 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
233 // Enabling/disabling handled by event loop, and not sending events
235 bool wxWindowX11::Enable(bool enable
)
237 if ( !wxWindowBase::Enable(enable
) )
243 bool wxWindowX11::Show(bool show
)
245 wxWindowBase::Show(show
);
247 Window xwin
= (Window
) GetXWindow();
248 Display
*xdisp
= (Display
*) GetXDisplay();
252 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
254 XMapWindow(xdisp
, xwin
);
260 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
262 XUnmapWindow(xdisp
, xwin
);
268 // Raise the window to the top of the Z order
269 void wxWindowX11::Raise()
272 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
275 // Lower the window to the bottom of the Z order
276 void wxWindowX11::Lower()
279 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
282 void wxWindowX11::DoCaptureMouse()
284 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
286 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
297 Window xwindow
= (Window
) GetMainWindow();
299 wxCHECK_RET( xwindow
, wxT("invalid window") );
301 g_captureWindow
= (wxWindow
*) this;
305 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
307 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
311 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
314 if (res
!= GrabSuccess
)
317 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
319 if (res
== GrabNotViewable
)
321 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
323 g_captureWindow
= NULL
;
327 wxLogDebug("Grabbed pointer");
330 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
331 (Window
) GetMainWindow(),
333 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
339 if (res
!= GrabSuccess
)
341 wxLogDebug("Failed to grab mouse buttons.");
342 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
348 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
349 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
355 if (res
!= GrabSuccess
)
357 wxLogDebug("Failed to grab keyboard.");
358 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
359 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
360 (Window
) GetMainWindow());
365 m_winCaptured
= TRUE
;
369 void wxWindowX11::DoReleaseMouse()
371 g_captureWindow
= NULL
;
373 if ( !m_winCaptured
)
376 Window xwindow
= (Window
) GetMainWindow();
380 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
382 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
383 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
386 wxLogDebug("Ungrabbed pointer");
388 m_winCaptured
= FALSE
;
391 bool wxWindowX11::SetFont(const wxFont
& font
)
393 if ( !wxWindowBase::SetFont(font
) )
402 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
404 if ( !wxWindowBase::SetCursor(cursor
) )
410 Window xwindow
= (Window
) GetMainWindow();
412 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
414 wxCursor cursorToUse
;
416 cursorToUse
= m_cursor
;
418 cursorToUse
= *wxSTANDARD_CURSOR
;
420 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
422 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
427 // Coordinates relative to the window
428 void wxWindowX11::WarpPointer (int x
, int y
)
430 Window xwindow
= (Window
) GetMainWindow();
432 wxCHECK_RET( xwindow
, wxT("invalid window") );
434 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
437 // Does a physical scroll
438 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
444 // Use specified rectangle
445 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
449 // Use whole client area
451 GetClientSize(& w
, & h
);
454 wxNode
*cnode
= m_children
.First();
457 wxWindow
*child
= (wxWindow
*) cnode
->Data();
460 child
->GetSize( &sx
, &sy
);
461 wxPoint
pos( child
->GetPosition() );
462 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
463 cnode
= cnode
->Next();
466 int x1
= (dx
>= 0) ? x
: x
- dx
;
467 int y1
= (dy
>= 0) ? y
: y
- dy
;
468 int w1
= w
- abs(dx
);
469 int h1
= h
- abs(dy
);
470 int x2
= (dx
>= 0) ? x
+ dx
: x
;
471 int y2
= (dy
>= 0) ? y
+ dy
: y
;
473 wxClientDC
dc((wxWindow
*) this);
475 dc
.SetLogicalFunction (wxCOPY
);
477 Window window
= (Window
) GetMainWindow();
478 Display
* display
= wxGlobalDisplay();
480 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
481 x1
, y1
, w1
, h1
, x2
, y2
);
483 dc
.SetAutoSetting(TRUE
);
484 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
485 dc
.SetBrush(brush
); // FIXME: needed?
487 // We'll add rectangles to the list of update rectangles according to which
488 // bits we've exposed.
493 wxRect
*rect
= new wxRect
;
499 XFillRectangle(display
, window
,
500 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
504 rect
->width
= rect
->width
;
505 rect
->height
= rect
->height
;
507 updateRects
.Append((wxObject
*) rect
);
511 wxRect
*rect
= new wxRect
;
513 rect
->x
= x
+ w
+ dx
;
518 XFillRectangle(display
, window
,
519 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
524 rect
->width
= rect
->width
;
525 rect
->height
= rect
->height
;
527 updateRects
.Append((wxObject
*) rect
);
531 wxRect
*rect
= new wxRect
;
538 XFillRectangle(display
, window
,
539 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
543 rect
->width
= rect
->width
;
544 rect
->height
= rect
->height
;
546 updateRects
.Append((wxObject
*) rect
);
550 wxRect
*rect
= new wxRect
;
553 rect
->y
= y
+ h
+ dy
;
557 XFillRectangle(display
, window
,
558 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
562 rect
->width
= rect
->width
;
563 rect
->height
= rect
->height
;
565 updateRects
.Append((wxObject
*) rect
);
567 dc
.SetBrush(wxNullBrush
);
569 // Now send expose events
571 wxNode
* node
= updateRects
.First();
574 wxRect
* rect
= (wxRect
*) node
->Data();
578 event
.display
= display
;
579 event
.send_event
= True
;
580 event
.window
= window
;
584 event
.width
= rect
->width
;
585 event
.height
= rect
->height
;
589 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
595 // Delete the update rects
596 node
= updateRects
.First();
599 wxRect
* rect
= (wxRect
*) node
->Data();
606 // ---------------------------------------------------------------------------
608 // ---------------------------------------------------------------------------
610 #if wxUSE_DRAG_AND_DROP
612 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
619 // Old style file-manager drag&drop
620 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
625 // ----------------------------------------------------------------------------
627 // ----------------------------------------------------------------------------
631 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
636 #endif // wxUSE_TOOLTIPS
638 // ---------------------------------------------------------------------------
639 // moving and resizing
640 // ---------------------------------------------------------------------------
642 bool wxWindowX11::PreResize()
648 void wxWindowX11::DoGetSize(int *x
, int *y
) const
650 Window xwindow
= (Window
) GetMainWindow();
652 wxCHECK_RET( xwindow
, wxT("invalid window") );
654 XWindowAttributes attr
;
655 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
660 *x
= attr
.width
/* + 2*m_borderSize */ ;
661 *y
= attr
.height
/* + 2*m_borderSize */ ;
665 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
667 Window window
= (Window
) m_mainWidget
;
670 XWindowAttributes attr
;
671 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
679 // We may be faking the client origin. So a window that's really at (0, 30)
680 // may appear (to wxWin apps) to be at (0, 0).
683 wxPoint
pt(GetParent()->GetClientAreaOrigin());
691 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
693 Display
*display
= wxGlobalDisplay();
694 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
695 Window thisWindow
= (Window
) m_mainWidget
;
700 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
703 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
705 Display
*display
= wxGlobalDisplay();
706 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
707 Window thisWindow
= (Window
) m_mainWidget
;
712 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
716 // Get size *available for subwindows* i.e. excluding menu bar etc.
717 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
719 Window window
= (Window
) m_mainWidget
;
723 XWindowAttributes attr
;
724 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
735 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
737 if (!GetMainWindow())
740 XWindowChanges windowChanges
;
743 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
746 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
750 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
753 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
757 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
759 windowChanges
.width
= width
/* - m_borderSize*2 */;
760 valueMask
|= CWWidth
;
762 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
764 windowChanges
.height
= height
/* -m_borderSize*2*/;
765 valueMask
|= CWHeight
;
768 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
769 valueMask
, & windowChanges
);
772 void wxWindowX11::DoSetClientSize(int width
, int height
)
774 if (!GetMainWindow())
777 XWindowChanges windowChanges
;
782 windowChanges
.width
= width
;
783 valueMask
|= CWWidth
;
787 windowChanges
.height
= height
;
788 valueMask
|= CWHeight
;
790 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
791 valueMask
, & windowChanges
);
794 // For implementation purposes - sometimes decorations make the client area
796 wxPoint
wxWindowX11::GetClientAreaOrigin() const
798 return wxPoint(0, 0);
801 // Makes an adjustment to the window position (for example, a frame that has
802 // a toolbar that it manages itself).
803 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
805 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
807 wxPoint
pt(GetParent()->GetClientAreaOrigin());
808 x
+= pt
.x
; y
+= pt
.y
;
812 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
819 XSizeHints sizeHints
;
822 if (minW
> -1 && minH
> -1)
824 sizeHints
.flags
|= PMinSize
;
825 sizeHints
.min_width
= minW
;
826 sizeHints
.min_height
= minH
;
828 if (maxW
> -1 && maxH
> -1)
830 sizeHints
.flags
|= PMaxSize
;
831 sizeHints
.max_width
= maxW
;
832 sizeHints
.max_height
= maxH
;
834 if (incW
> -1 && incH
> -1)
836 sizeHints
.flags
|= PResizeInc
;
837 sizeHints
.width_inc
= incW
;
838 sizeHints
.height_inc
= incH
;
841 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
844 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
846 DoSetSize(x
, y
, width
, height
);
849 // ---------------------------------------------------------------------------
851 // ---------------------------------------------------------------------------
853 int wxWindowX11::GetCharHeight() const
855 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
857 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
859 int direction
, ascent
, descent
;
861 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
864 // return (overall.ascent + overall.descent);
865 return (ascent
+ descent
);
868 int wxWindowX11::GetCharWidth() const
870 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
872 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
874 int direction
, ascent
, descent
;
876 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
879 return overall
.width
;
882 void wxWindowX11::GetTextExtent(const wxString
& string
,
884 int *descent
, int *externalLeading
,
885 const wxFont
*theFont
) const
887 wxFont fontToUse
= m_font
;
888 if (theFont
) fontToUse
= *theFont
;
890 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
892 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
894 int direction
, ascent
, descent2
;
896 int slen
= string
.Len();
900 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
901 &ascent
, &descent2
, &overall
);
904 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
905 &direction
, &ascent
, &descent2
, &overall
);
908 *x
= (overall
.width
);
910 *y
= (ascent
+ descent2
);
914 *externalLeading
= 0;
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
922 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
928 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
929 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
934 GetSize( &width
, &height
);
936 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
937 m_clearRegion
.Clear();
938 m_clearRegion
.Union( 0, 0, width
, height
);
944 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
945 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
950 GetSize( &width
, &height
);
952 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
953 m_updateRegion
.Clear();
954 m_updateRegion
.Union( 0, 0, width
, height
);
958 void wxWindowX11::Update()
960 if (!m_updateRegion
.IsEmpty())
962 X11SendPaintEvents();
966 void wxWindowX11::Clear()
968 wxClientDC
dc((wxWindow
*) this);
969 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
970 dc
.SetBackground(brush
);
974 void wxWindowX11::X11SendPaintEvents()
976 m_clipPaintRegion
= TRUE
;
978 // if (!m_clearRegion.IsEmpty())
980 wxWindowDC
dc( (wxWindow
*)this );
981 dc
.SetClippingRegion( m_clearRegion
);
983 wxEraseEvent
erase_event( GetId(), &dc
);
984 erase_event
.SetEventObject( this );
986 if (!GetEventHandler()->ProcessEvent(erase_event
))
988 wxRegionIterator
upd( m_clearRegion
);
991 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
992 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
996 m_clearRegion
.Clear();
999 wxNcPaintEvent
nc_paint_event( GetId() );
1000 nc_paint_event
.SetEventObject( this );
1001 GetEventHandler()->ProcessEvent( nc_paint_event
);
1003 wxPaintEvent
paint_event( GetId() );
1004 paint_event
.SetEventObject( this );
1005 GetEventHandler()->ProcessEvent( paint_event
);
1007 m_updateRegion
.Clear();
1009 m_clipPaintRegion
= FALSE
;
1012 // ----------------------------------------------------------------------------
1014 // ----------------------------------------------------------------------------
1016 // Responds to colour changes: passes event on to children.
1017 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1019 wxWindowList::Node
*node
= GetChildren().GetFirst();
1022 // Only propagate to non-top-level windows
1023 wxWindow
*win
= node
->GetData();
1024 if ( win
->GetParent() )
1026 wxSysColourChangedEvent event2
;
1027 event
.m_eventObject
= win
;
1028 win
->GetEventHandler()->ProcessEvent(event2
);
1031 node
= node
->GetNext();
1035 void wxWindowX11::OnInternalIdle()
1037 // Update invalidated regions.
1040 // This calls the UI-update mechanism (querying windows for
1041 // menu/toolbar/control state information)
1045 // ----------------------------------------------------------------------------
1046 // function which maintain the global hash table mapping Widgets to wxWindows
1047 // ----------------------------------------------------------------------------
1049 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1051 wxWindow
*oldItem
= NULL
;
1052 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1054 wxLogDebug("Widget table clash: new widget is %ld, %s",
1055 (long)w
, win
->GetClassInfo()->GetClassName());
1059 wxWidgetHashTable
->Put((long) w
, win
);
1061 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1062 w
, win
, win
->GetClassInfo()->GetClassName());
1067 wxWindow
*wxGetWindowFromTable(Window w
)
1069 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1072 void wxDeleteWindowFromTable(Window w
)
1074 wxWidgetHashTable
->Delete((long)w
);
1077 // ----------------------------------------------------------------------------
1078 // add/remove window from the table
1079 // ----------------------------------------------------------------------------
1081 // ----------------------------------------------------------------------------
1082 // X11-specific accessors
1083 // ----------------------------------------------------------------------------
1085 // Get the underlying X window
1086 WXWindow
wxWindowX11::GetXWindow() const
1088 return GetMainWindow();
1091 // Get the underlying X display
1092 WXDisplay
*wxWindowX11::GetXDisplay() const
1094 return wxGetDisplay();
1097 WXWindow
wxWindowX11::GetMainWindow() const
1099 return m_mainWidget
;
1102 // ----------------------------------------------------------------------------
1103 // TranslateXXXEvent() functions
1104 // ----------------------------------------------------------------------------
1106 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1108 switch (xevent
->xany
.type
)
1116 wxEventType eventType
= wxEVT_NULL
;
1118 if (xevent
->xany
.type
== EnterNotify
)
1120 //if (local_event.xcrossing.mode!=NotifyNormal)
1121 // return ; // Ignore grab events
1122 eventType
= wxEVT_ENTER_WINDOW
;
1123 // canvas->GetEventHandler()->OnSetFocus();
1125 else if (xevent
->xany
.type
== LeaveNotify
)
1127 //if (local_event.xcrossingr.mode!=NotifyNormal)
1128 // return ; // Ignore grab events
1129 eventType
= wxEVT_LEAVE_WINDOW
;
1130 // canvas->GetEventHandler()->OnKillFocus();
1132 else if (xevent
->xany
.type
== MotionNotify
)
1134 eventType
= wxEVT_MOTION
;
1136 else if (xevent
->xany
.type
== ButtonPress
)
1138 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1140 if (xevent
->xbutton
.button
== Button1
)
1142 eventType
= wxEVT_LEFT_DOWN
;
1145 else if (xevent
->xbutton
.button
== Button2
)
1147 eventType
= wxEVT_MIDDLE_DOWN
;
1150 else if (xevent
->xbutton
.button
== Button3
)
1152 eventType
= wxEVT_RIGHT_DOWN
;
1156 // check for a double click
1157 // TODO: where can we get this value from?
1158 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1159 long dclickTime
= 200;
1160 long ts
= wxevent
.GetTimestamp();
1162 int buttonLast
= win
->GetLastClickedButton();
1163 long lastTS
= win
->GetLastClickTime();
1164 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1167 win
->SetLastClick(0, ts
);
1168 if ( eventType
== wxEVT_LEFT_DOWN
)
1169 eventType
= wxEVT_LEFT_DCLICK
;
1170 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1171 eventType
= wxEVT_MIDDLE_DCLICK
;
1172 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1173 eventType
= wxEVT_RIGHT_DCLICK
;
1177 // not fast enough or different button
1178 win
->SetLastClick(button
, ts
);
1181 else if (xevent
->xany
.type
== ButtonRelease
)
1183 if (xevent
->xbutton
.button
== Button1
)
1185 eventType
= wxEVT_LEFT_UP
;
1187 else if (xevent
->xbutton
.button
== Button2
)
1189 eventType
= wxEVT_MIDDLE_UP
;
1191 else if (xevent
->xbutton
.button
== Button3
)
1193 eventType
= wxEVT_RIGHT_UP
;
1202 wxevent
.SetEventType(eventType
);
1204 wxevent
.m_x
= xevent
->xbutton
.x
;
1205 wxevent
.m_y
= xevent
->xbutton
.y
;
1207 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1208 || (event_left_is_down (xevent
)
1209 && (eventType
!= wxEVT_LEFT_UP
)));
1210 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1211 || (event_middle_is_down (xevent
)
1212 && (eventType
!= wxEVT_MIDDLE_UP
)));
1213 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1214 || (event_right_is_down (xevent
)
1215 && (eventType
!= wxEVT_RIGHT_UP
)));
1217 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1218 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1219 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1220 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1222 wxevent
.SetId(win
->GetId());
1223 wxevent
.SetEventObject(win
);
1231 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1233 switch (xevent
->xany
.type
)
1241 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1242 int id
= wxCharCodeXToWX (keySym
);
1244 if (xevent
->xkey
.state
& ShiftMask
)
1245 wxevent
.m_shiftDown
= TRUE
;
1246 if (xevent
->xkey
.state
& ControlMask
)
1247 wxevent
.m_controlDown
= TRUE
;
1248 if (xevent
->xkey
.state
& Mod3Mask
)
1249 wxevent
.m_altDown
= TRUE
;
1250 if (xevent
->xkey
.state
& Mod1Mask
)
1251 wxevent
.m_metaDown
= TRUE
;
1252 wxevent
.SetEventObject(win
);
1253 wxevent
.m_keyCode
= id
;
1254 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1256 wxevent
.m_x
= xevent
->xbutton
.x
;
1257 wxevent
.m_y
= xevent
->xbutton
.y
;
1271 // ----------------------------------------------------------------------------
1273 // ----------------------------------------------------------------------------
1275 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1277 wxWindowBase::SetBackgroundColour(col
);
1279 if (!GetMainWindow())
1282 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1283 int xscreen
= DefaultScreen( xdisplay
);
1284 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1286 wxColour
colour( col
);
1287 colour
.CalcPixel( (WXColormap
) cm
);
1289 XSetWindowAttributes attrib
;
1290 attrib
.background_pixel
= colour
.GetPixel();
1292 XChangeWindowAttributes(wxGlobalDisplay(),
1293 (Window
) GetMainWindow(),
1300 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1302 if ( !wxWindowBase::SetForegroundColour(col
) )
1308 // ----------------------------------------------------------------------------
1310 // ----------------------------------------------------------------------------
1312 wxWindow
*wxGetActiveWindow()
1315 wxFAIL_MSG("Not implemented");
1320 wxWindow
*wxWindowBase::GetCapture()
1322 return (wxWindow
*)g_captureWindow
;
1326 // Find the wxWindow at the current mouse position, returning the mouse
1328 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1330 return wxFindWindowAtPoint(wxGetMousePosition());
1333 // Get the current mouse position.
1334 wxPoint
wxGetMousePosition()
1336 Display
*display
= wxGlobalDisplay();
1337 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1338 Window rootReturn
, childReturn
;
1339 int rootX
, rootY
, winX
, winY
;
1340 unsigned int maskReturn
;
1342 XQueryPointer (display
,
1346 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1347 return wxPoint(rootX
, rootY
);
1351 // ----------------------------------------------------------------------------
1352 // wxNoOptimize: switch off size optimization
1353 // ----------------------------------------------------------------------------
1355 int wxNoOptimize::ms_count
= 0;