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 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 static const int SCROLL_MARGIN
= 4;
58 // ----------------------------------------------------------------------------
59 // global variables for this module
60 // ----------------------------------------------------------------------------
62 extern wxHashTable
*wxWidgetHashTable
;
63 static wxWindow
* g_captureWindow
= NULL
;
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
70 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
71 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
79 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
80 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
81 EVT_IDLE(wxWindowX11::OnIdle
)
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 void wxWindowX11::Init()
98 // generic initializations first
102 m_mainWidget
= (WXWindow
) 0;
104 m_winCaptured
= FALSE
;
107 m_isBeingDeleted
= FALSE
;
113 // real construction (Init() must have been called before!)
114 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
118 const wxString
& name
)
120 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
122 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
124 parent
->AddChild(this);
126 int w
= size
.GetWidth();
127 int h
= size
.GetHeight();
135 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
136 int xscreen
= DefaultScreen( xdisplay
);
137 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
139 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
140 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
143 m_foregroundColour
= *wxBLACK
;
144 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
147 Window parentWindow
= (Window
) parent
->GetMainWindow();
149 Window window
= XCreateSimpleWindow(
150 xdisplay
, parentWindow
,
152 m_backgroundColour
.GetPixel(),
153 m_backgroundColour
.GetPixel() );
155 m_mainWidget
= (WXWindow
) window
;
157 // Select event types wanted
158 XSelectInput(wxGlobalDisplay(), window
,
159 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
160 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
161 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
164 wxAddWindowToTable(window
, (wxWindow
*) this);
166 // Is a subwindow, so map immediately
168 XMapWindow(wxGlobalDisplay(), window
);
170 // Without this, the cursor may not be restored properly (e.g. in splitter
172 SetCursor(*wxSTANDARD_CURSOR
);
173 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
174 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
180 wxWindowX11::~wxWindowX11()
182 if (g_captureWindow
== this)
183 g_captureWindow
= NULL
;
185 m_isBeingDeleted
= TRUE
;
187 // X11-specific actions first
188 Window main
= (Window
) m_mainWidget
;
191 // Removes event handlers
192 //DetachWidget(main);
196 m_parent
->RemoveChild( this );
200 // Destroy the window
203 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
204 wxDeleteWindowFromTable( main
);
205 XDestroyWindow( wxGlobalDisplay(), main
);
210 // ---------------------------------------------------------------------------
212 // ---------------------------------------------------------------------------
214 void wxWindowX11::SetFocus()
216 Window wMain
= (Window
) GetMainWindow();
219 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
222 wmhints
.flags
= InputHint
;
223 wmhints
.input
= True
;
224 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
228 // Get the window with the focus
229 wxWindow
*wxWindowBase::FindFocus()
231 Window wFocus
= (Window
) 0;
234 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
237 wxWindow
*win
= NULL
;
240 win
= wxGetWindowFromTable(wFocus
);
241 wFocus
= wxGetWindowParent(wFocus
);
242 } while (wFocus
&& !win
);
250 // Enabling/disabling handled by event loop, and not sending events
252 bool wxWindowX11::Enable(bool enable
)
254 if ( !wxWindowBase::Enable(enable
) )
260 bool wxWindowX11::Show(bool show
)
262 if ( !wxWindowBase::Show(show
) )
265 Window xwin
= (Window
) GetXWindow();
266 Display
*xdisp
= (Display
*) GetXDisplay();
269 XMapWindow(xdisp
, xwin
);
273 XUnmapWindow(xdisp
, xwin
);
279 // Raise the window to the top of the Z order
280 void wxWindowX11::Raise()
283 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
286 // Lower the window to the bottom of the Z order
287 void wxWindowX11::Lower()
290 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
293 void wxWindowX11::DoCaptureMouse()
295 g_captureWindow
= (wxWindow
*) this;
301 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
303 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
307 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
310 if (res
!= GrabSuccess
)
312 wxLogDebug("Failed to grab pointer.");
316 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
317 (Window
) GetMainWindow(),
319 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
325 if (res
!= GrabSuccess
)
327 wxLogDebug("Failed to grab mouse buttons.");
328 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
332 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
334 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
342 if (res
!= GrabSuccess
)
344 wxLogDebug("Failed to grab keyboard.");
345 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
346 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
347 (Window
) GetMainWindow());
351 m_winCaptured
= TRUE
;
355 void wxWindowX11::DoReleaseMouse()
357 g_captureWindow
= NULL
;
358 if ( !m_winCaptured
)
361 Window wMain
= (Window
)GetMainWindow();
365 XUngrabPointer(wxGlobalDisplay(), wMain
);
366 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
368 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
371 m_winCaptured
= FALSE
;
374 bool wxWindowX11::SetFont(const wxFont
& font
)
376 if ( !wxWindowBase::SetFont(font
) )
385 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
387 if ( !wxWindowBase::SetCursor(cursor
) )
393 wxCursor
* cursor2
= NULL
;
395 cursor2
= & m_cursor
;
397 cursor2
= wxSTANDARD_CURSOR
;
399 WXDisplay
*dpy
= GetXDisplay();
400 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
402 Window win
= (Window
) GetMainWindow();
403 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
408 // Coordinates relative to the window
409 void wxWindowX11::WarpPointer (int x
, int y
)
412 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
415 // Does a physical scroll
416 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
422 // Use specified rectangle
423 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
427 // Use whole client area
429 GetClientSize(& w
, & h
);
432 wxNode
*cnode
= m_children
.First();
435 wxWindow
*child
= (wxWindow
*) cnode
->Data();
438 child
->GetSize( &sx
, &sy
);
439 wxPoint
pos( child
->GetPosition() );
440 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
441 cnode
= cnode
->Next();
444 int x1
= (dx
>= 0) ? x
: x
- dx
;
445 int y1
= (dy
>= 0) ? y
: y
- dy
;
446 int w1
= w
- abs(dx
);
447 int h1
= h
- abs(dy
);
448 int x2
= (dx
>= 0) ? x
+ dx
: x
;
449 int y2
= (dy
>= 0) ? y
+ dy
: y
;
451 wxClientDC
dc((wxWindow
*) this);
453 dc
.SetLogicalFunction (wxCOPY
);
455 Window window
= (Window
) GetMainWindow();
456 Display
* display
= wxGlobalDisplay();
458 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
459 x1
, y1
, w1
, h1
, x2
, y2
);
461 dc
.SetAutoSetting(TRUE
);
462 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
463 dc
.SetBrush(brush
); // FIXME: needed?
465 // We'll add rectangles to the list of update rectangles according to which
466 // bits we've exposed.
471 wxRect
*rect
= new wxRect
;
477 XFillRectangle(display
, window
,
478 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
482 rect
->width
= rect
->width
;
483 rect
->height
= rect
->height
;
485 updateRects
.Append((wxObject
*) rect
);
489 wxRect
*rect
= new wxRect
;
491 rect
->x
= x
+ w
+ dx
;
496 XFillRectangle(display
, window
,
497 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
502 rect
->width
= rect
->width
;
503 rect
->height
= rect
->height
;
505 updateRects
.Append((wxObject
*) rect
);
509 wxRect
*rect
= new wxRect
;
516 XFillRectangle(display
, window
,
517 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
521 rect
->width
= rect
->width
;
522 rect
->height
= rect
->height
;
524 updateRects
.Append((wxObject
*) rect
);
528 wxRect
*rect
= new wxRect
;
531 rect
->y
= y
+ h
+ dy
;
535 XFillRectangle(display
, window
,
536 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
540 rect
->width
= rect
->width
;
541 rect
->height
= rect
->height
;
543 updateRects
.Append((wxObject
*) rect
);
545 dc
.SetBrush(wxNullBrush
);
547 // Now send expose events
549 wxNode
* node
= updateRects
.First();
552 wxRect
* rect
= (wxRect
*) node
->Data();
556 event
.display
= display
;
557 event
.send_event
= True
;
558 event
.window
= window
;
562 event
.width
= rect
->width
;
563 event
.height
= rect
->height
;
567 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
573 // Delete the update rects
574 node
= updateRects
.First();
577 wxRect
* rect
= (wxRect
*) node
->Data();
584 // ---------------------------------------------------------------------------
586 // ---------------------------------------------------------------------------
588 #if wxUSE_DRAG_AND_DROP
590 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
597 // Old style file-manager drag&drop
598 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
603 // ----------------------------------------------------------------------------
605 // ----------------------------------------------------------------------------
609 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
614 #endif // wxUSE_TOOLTIPS
616 // ---------------------------------------------------------------------------
617 // moving and resizing
618 // ---------------------------------------------------------------------------
620 bool wxWindowX11::PreResize()
626 void wxWindowX11::DoGetSize(int *x
, int *y
) const
628 Window window
= (Window
) m_mainWidget
;
631 XWindowAttributes attr
;
632 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
637 *x
= attr
.width
/* + 2*m_borderSize */ ;
638 *y
= attr
.height
/* + 2*m_borderSize */ ;
643 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
645 Window window
= (Window
) m_mainWidget
;
648 XWindowAttributes attr
;
649 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
657 // We may be faking the client origin. So a window that's really at (0, 30)
658 // may appear (to wxWin apps) to be at (0, 0).
661 wxPoint
pt(GetParent()->GetClientAreaOrigin());
669 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
671 Display
*display
= wxGlobalDisplay();
672 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
673 Window thisWindow
= (Window
) m_mainWidget
;
678 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
681 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
683 Display
*display
= wxGlobalDisplay();
684 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
685 Window thisWindow
= (Window
) m_mainWidget
;
690 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
694 // Get size *available for subwindows* i.e. excluding menu bar etc.
695 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
697 Window window
= (Window
) m_mainWidget
;
701 XWindowAttributes attr
;
702 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
713 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
715 if (!GetMainWindow())
718 XWindowChanges windowChanges
;
721 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
724 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
728 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
731 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
735 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
737 windowChanges
.width
= width
/* - m_borderSize*2 */;
738 valueMask
|= CWWidth
;
740 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
742 windowChanges
.height
= height
/* -m_borderSize*2*/;
743 valueMask
|= CWHeight
;
746 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
747 valueMask
, & windowChanges
);
750 void wxWindowX11::DoSetClientSize(int width
, int height
)
752 if (!GetMainWindow())
755 XWindowChanges windowChanges
;
760 windowChanges
.width
= width
;
761 valueMask
|= CWWidth
;
765 windowChanges
.height
= height
;
766 valueMask
|= CWHeight
;
768 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
769 valueMask
, & windowChanges
);
772 // For implementation purposes - sometimes decorations make the client area
774 wxPoint
wxWindowX11::GetClientAreaOrigin() const
776 return wxPoint(0, 0);
779 // Makes an adjustment to the window position (for example, a frame that has
780 // a toolbar that it manages itself).
781 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
783 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
785 wxPoint
pt(GetParent()->GetClientAreaOrigin());
786 x
+= pt
.x
; y
+= pt
.y
;
790 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
797 XSizeHints sizeHints
;
800 if (minW
> -1 && minH
> -1)
802 sizeHints
.flags
|= PMinSize
;
803 sizeHints
.min_width
= minW
;
804 sizeHints
.min_height
= minH
;
806 if (maxW
> -1 && maxH
> -1)
808 sizeHints
.flags
|= PMaxSize
;
809 sizeHints
.max_width
= maxW
;
810 sizeHints
.max_height
= maxH
;
812 if (incW
> -1 && incH
> -1)
814 sizeHints
.flags
|= PResizeInc
;
815 sizeHints
.width_inc
= incW
;
816 sizeHints
.height_inc
= incH
;
819 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
822 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
824 DoSetSize(x
, y
, width
, height
);
827 // ---------------------------------------------------------------------------
829 // ---------------------------------------------------------------------------
831 int wxWindowX11::GetCharHeight() const
833 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
835 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
837 int direction
, ascent
, descent
;
839 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
842 // return (overall.ascent + overall.descent);
843 return (ascent
+ descent
);
846 int wxWindowX11::GetCharWidth() const
848 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
850 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
852 int direction
, ascent
, descent
;
854 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
857 return overall
.width
;
860 void wxWindowX11::GetTextExtent(const wxString
& string
,
862 int *descent
, int *externalLeading
,
863 const wxFont
*theFont
) const
865 wxFont
*fontToUse
= (wxFont
*)theFont
;
867 fontToUse
= (wxFont
*) & m_font
;
869 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
871 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
873 int direction
, ascent
, descent2
;
875 int slen
= string
.Len();
879 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
880 &ascent
, &descent2
, &overall
);
883 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
884 &direction
, &ascent
, &descent2
, &overall
);
887 *x
= (overall
.width
);
889 *y
= (ascent
+ descent2
);
893 *externalLeading
= 0;
897 // ----------------------------------------------------------------------------
899 // ----------------------------------------------------------------------------
901 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
907 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
908 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
913 GetSize( &width
, &height
);
915 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
916 m_clearRegion
.Clear();
917 m_clearRegion
.Union( 0, 0, width
, height
);
923 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
924 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
929 GetSize( &width
, &height
);
931 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
932 m_updateRegion
.Clear();
933 m_updateRegion
.Union( 0, 0, width
, height
);
936 // Actually don't schedule yet..
940 void wxWindowX11::Update()
942 if (!m_updateRegion
.IsEmpty())
944 X11SendPaintEvents();
948 void wxWindowX11::Clear()
950 wxClientDC
dc((wxWindow
*) this);
951 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
952 dc
.SetBackground(brush
);
956 void wxWindowX11::X11SendPaintEvents()
958 m_clipPaintRegion
= TRUE
;
960 // if (!m_clearRegion.IsEmpty())
962 wxWindowDC
dc( (wxWindow
*)this );
963 dc
.SetClippingRegion( m_clearRegion
);
965 wxEraseEvent
erase_event( GetId(), &dc
);
966 erase_event
.SetEventObject( this );
968 if (!GetEventHandler()->ProcessEvent(erase_event
))
970 wxRegionIterator
upd( m_clearRegion
);
973 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
974 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
978 m_clearRegion
.Clear();
981 wxNcPaintEvent
nc_paint_event( GetId() );
982 nc_paint_event
.SetEventObject( this );
983 GetEventHandler()->ProcessEvent( nc_paint_event
);
985 wxPaintEvent
paint_event( GetId() );
986 paint_event
.SetEventObject( this );
987 GetEventHandler()->ProcessEvent( paint_event
);
989 m_clipPaintRegion
= FALSE
;
992 // ----------------------------------------------------------------------------
994 // ----------------------------------------------------------------------------
996 // Responds to colour changes: passes event on to children.
997 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
999 wxWindowList::Node
*node
= GetChildren().GetFirst();
1002 // Only propagate to non-top-level windows
1003 wxWindow
*win
= node
->GetData();
1004 if ( win
->GetParent() )
1006 wxSysColourChangedEvent event2
;
1007 event
.m_eventObject
= win
;
1008 win
->GetEventHandler()->ProcessEvent(event2
);
1011 node
= node
->GetNext();
1015 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1017 // This calls the UI-update mechanism (querying windows for
1018 // menu/toolbar/control state information)
1022 // ----------------------------------------------------------------------------
1023 // function which maintain the global hash table mapping Widgets to wxWindows
1024 // ----------------------------------------------------------------------------
1026 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1028 wxWindow
*oldItem
= NULL
;
1029 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1031 wxLogDebug("Widget table clash: new widget is %ld, %s",
1032 (long)w
, win
->GetClassInfo()->GetClassName());
1036 wxWidgetHashTable
->Put((long) w
, win
);
1038 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1039 w
, win
, win
->GetClassInfo()->GetClassName());
1044 wxWindow
*wxGetWindowFromTable(Window w
)
1046 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1049 void wxDeleteWindowFromTable(Window w
)
1051 wxWidgetHashTable
->Delete((long)w
);
1054 // ----------------------------------------------------------------------------
1055 // add/remove window from the table
1056 // ----------------------------------------------------------------------------
1058 // ----------------------------------------------------------------------------
1059 // X11-specific accessors
1060 // ----------------------------------------------------------------------------
1062 // Get the underlying X window
1063 WXWindow
wxWindowX11::GetXWindow() const
1065 return GetMainWindow();
1068 // Get the underlying X display
1069 WXDisplay
*wxWindowX11::GetXDisplay() const
1071 return wxGetDisplay();
1074 WXWindow
wxWindowX11::GetMainWindow() const
1076 return m_mainWidget
;
1079 // ----------------------------------------------------------------------------
1080 // TranslateXXXEvent() functions
1081 // ----------------------------------------------------------------------------
1083 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1085 switch (xevent
->xany
.type
)
1093 wxEventType eventType
= wxEVT_NULL
;
1095 if (xevent
->xany
.type
== EnterNotify
)
1097 //if (local_event.xcrossing.mode!=NotifyNormal)
1098 // return ; // Ignore grab events
1099 eventType
= wxEVT_ENTER_WINDOW
;
1100 // canvas->GetEventHandler()->OnSetFocus();
1102 else if (xevent
->xany
.type
== LeaveNotify
)
1104 //if (local_event.xcrossingr.mode!=NotifyNormal)
1105 // return ; // Ignore grab events
1106 eventType
= wxEVT_LEAVE_WINDOW
;
1107 // canvas->GetEventHandler()->OnKillFocus();
1109 else if (xevent
->xany
.type
== MotionNotify
)
1111 eventType
= wxEVT_MOTION
;
1113 else if (xevent
->xany
.type
== ButtonPress
)
1115 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1117 if (xevent
->xbutton
.button
== Button1
)
1119 eventType
= wxEVT_LEFT_DOWN
;
1122 else if (xevent
->xbutton
.button
== Button2
)
1124 eventType
= wxEVT_MIDDLE_DOWN
;
1127 else if (xevent
->xbutton
.button
== Button3
)
1129 eventType
= wxEVT_RIGHT_DOWN
;
1133 // check for a double click
1134 // TODO: where can we get this value from?
1135 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1136 long dclickTime
= 200;
1137 long ts
= wxevent
.GetTimestamp();
1139 int buttonLast
= win
->GetLastClickedButton();
1140 long lastTS
= win
->GetLastClickTime();
1141 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1144 win
->SetLastClick(0, ts
);
1145 if ( eventType
== wxEVT_LEFT_DOWN
)
1146 eventType
= wxEVT_LEFT_DCLICK
;
1147 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1148 eventType
= wxEVT_MIDDLE_DCLICK
;
1149 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1150 eventType
= wxEVT_RIGHT_DCLICK
;
1154 // not fast enough or different button
1155 win
->SetLastClick(button
, ts
);
1158 else if (xevent
->xany
.type
== ButtonRelease
)
1160 if (xevent
->xbutton
.button
== Button1
)
1162 eventType
= wxEVT_LEFT_UP
;
1164 else if (xevent
->xbutton
.button
== Button2
)
1166 eventType
= wxEVT_MIDDLE_UP
;
1168 else if (xevent
->xbutton
.button
== Button3
)
1170 eventType
= wxEVT_RIGHT_UP
;
1179 wxevent
.SetEventType(eventType
);
1181 wxevent
.m_x
= xevent
->xbutton
.x
;
1182 wxevent
.m_y
= xevent
->xbutton
.y
;
1184 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1185 || (event_left_is_down (xevent
)
1186 && (eventType
!= wxEVT_LEFT_UP
)));
1187 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1188 || (event_middle_is_down (xevent
)
1189 && (eventType
!= wxEVT_MIDDLE_UP
)));
1190 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1191 || (event_right_is_down (xevent
)
1192 && (eventType
!= wxEVT_RIGHT_UP
)));
1194 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1195 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1196 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1197 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1199 wxevent
.SetId(win
->GetId());
1200 wxevent
.SetEventObject(win
);
1208 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1210 switch (xevent
->xany
.type
)
1218 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1219 int id
= wxCharCodeXToWX (keySym
);
1221 if (xevent
->xkey
.state
& ShiftMask
)
1222 wxevent
.m_shiftDown
= TRUE
;
1223 if (xevent
->xkey
.state
& ControlMask
)
1224 wxevent
.m_controlDown
= TRUE
;
1225 if (xevent
->xkey
.state
& Mod3Mask
)
1226 wxevent
.m_altDown
= TRUE
;
1227 if (xevent
->xkey
.state
& Mod1Mask
)
1228 wxevent
.m_metaDown
= TRUE
;
1229 wxevent
.SetEventObject(win
);
1230 wxevent
.m_keyCode
= id
;
1231 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1233 wxevent
.m_x
= xevent
->xbutton
.x
;
1234 wxevent
.m_y
= xevent
->xbutton
.y
;
1248 // ----------------------------------------------------------------------------
1250 // ----------------------------------------------------------------------------
1254 #define YAllocColor XAllocColor
1255 XColor g_itemColors
[5];
1256 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1259 static XmColorProc colorProc
;
1261 result
= wxNO_COLORS
;
1265 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1266 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1267 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1268 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1269 if (colorProc
== (XmColorProc
) NULL
)
1271 // Get a ptr to the actual function
1272 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1273 // And set it back to motif.
1274 XmSetColorCalculation (colorProc
);
1276 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1277 &g_itemColors
[wxFORE_INDEX
],
1278 &g_itemColors
[wxSELE_INDEX
],
1279 &g_itemColors
[wxTOPS_INDEX
],
1280 &g_itemColors
[wxBOTS_INDEX
]);
1281 result
= wxBACK_COLORS
;
1285 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1286 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1287 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1288 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1289 if (result
== wxNO_COLORS
)
1290 result
= wxFORE_COLORS
;
1293 Display
*dpy
= display
;
1294 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1298 /* 5 Colours to allocate */
1299 for (int i
= 0; i
< 5; i
++)
1300 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1301 result
= wxNO_COLORS
;
1305 /* Only 1 colour to allocate */
1306 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1307 result
= wxNO_COLORS
;
1315 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1317 wxWindowBase::SetBackgroundColour(col
);
1319 if (!GetMainWindow())
1322 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1323 int xscreen
= DefaultScreen( xdisplay
);
1324 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1326 wxColour
colour( col
);
1327 colour
.CalcPixel( (WXColormap
) cm
);
1329 XSetWindowAttributes attrib
;
1330 attrib
.background_pixel
= colour
.GetPixel();
1332 XChangeWindowAttributes(wxGlobalDisplay(),
1333 (Window
) GetMainWindow(),
1340 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1342 if ( !wxWindowBase::SetForegroundColour(col
) )
1348 // ----------------------------------------------------------------------------
1350 // ----------------------------------------------------------------------------
1352 wxWindow
*wxGetActiveWindow()
1355 wxFAIL_MSG("Not implemented");
1360 wxWindow
*wxWindowBase::GetCapture()
1362 return (wxWindow
*)g_captureWindow
;
1366 // Find the wxWindow at the current mouse position, returning the mouse
1368 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1370 return wxFindWindowAtPoint(wxGetMousePosition());
1373 // Get the current mouse position.
1374 wxPoint
wxGetMousePosition()
1376 Display
*display
= wxGlobalDisplay();
1377 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1378 Window rootReturn
, childReturn
;
1379 int rootX
, rootY
, winX
, winY
;
1380 unsigned int maskReturn
;
1382 XQueryPointer (display
,
1386 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1387 return wxPoint(rootX
, rootY
);
1391 // ----------------------------------------------------------------------------
1392 // wxNoOptimize: switch off size optimization
1393 // ----------------------------------------------------------------------------
1395 int wxNoOptimize::ms_count
= 0;