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
);
125 parent
->AddChild(this);
127 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
128 m_foregroundColour
= *wxBLACK
;
130 int w
= size
.GetWidth();
131 int h
= size
.GetHeight();
139 int screen
= DefaultScreen(wxGlobalDisplay());
143 parentWindow
= (Window
) parent
->GetMainWindow();
145 parentWindow
= RootWindow(wxGlobalDisplay(), screen
);
147 Window window
= XCreateSimpleWindow(wxGlobalDisplay(), parentWindow
,
149 m_backgroundColour
.AllocColour(wxGlobalDisplay()),
150 m_foregroundColour
.AllocColour(wxGlobalDisplay()));
152 // Select event types wanted
153 XSelectInput(wxGlobalDisplay(), window
,
154 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
155 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
156 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
159 wxAddWindowToTable(window
, (wxWindow
*) this);
161 // Is a subwindow, so map immediately
163 XMapWindow(wxGlobalDisplay(), window
);
165 // Without this, the cursor may not be restored properly (e.g. in splitter
167 SetCursor(*wxSTANDARD_CURSOR
);
168 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
169 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
175 wxWindowX11::~wxWindowX11()
177 if (g_captureWindow
== this)
178 g_captureWindow
= NULL
;
180 m_isBeingDeleted
= TRUE
;
182 // X11-specific actions first
183 Window main
= (Window
) m_mainWidget
;
186 // Removes event handlers
187 //DetachWidget(main);
191 m_parent
->RemoveChild( this );
195 // Destroy the window
198 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
199 wxDeleteWindowFromTable( main
);
200 XDestroyWindow( wxGlobalDisplay(), main
);
205 // ---------------------------------------------------------------------------
207 // ---------------------------------------------------------------------------
209 void wxWindowX11::SetFocus()
211 Window wMain
= (Window
) GetMainWindow();
214 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
217 wmhints
.flags
= InputHint
;
218 wmhints
.input
= True
;
219 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
223 // Get the window with the focus
224 wxWindow
*wxWindowBase::FindFocus()
226 Window wFocus
= (Window
) 0;
229 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
232 wxWindow
*win
= NULL
;
235 win
= wxGetWindowFromTable(wFocus
);
236 wFocus
= wxGetWindowParent(wFocus
);
237 } while (wFocus
&& !win
);
245 // Enabling/disabling handled by event loop, and not sending events
247 bool wxWindowX11::Enable(bool enable
)
249 if ( !wxWindowBase::Enable(enable
) )
255 bool wxWindowX11::Show(bool show
)
257 if ( !wxWindowBase::Show(show
) )
260 Window xwin
= (Window
) GetXWindow();
261 Display
*xdisp
= (Display
*) GetXDisplay();
264 XMapWindow(xdisp
, xwin
);
268 XUnmapWindow(xdisp
, xwin
);
274 // Raise the window to the top of the Z order
275 void wxWindowX11::Raise()
278 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
281 // Lower the window to the bottom of the Z order
282 void wxWindowX11::Lower()
285 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
288 void wxWindowX11::DoCaptureMouse()
290 g_captureWindow
= (wxWindow
*) this;
296 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
298 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
302 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
305 if (res
!= GrabSuccess
)
307 wxLogDebug("Failed to grab pointer.");
311 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
312 (Window
) GetMainWindow(),
314 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
320 if (res
!= GrabSuccess
)
322 wxLogDebug("Failed to grab mouse buttons.");
323 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
327 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
333 if (res
!= GrabSuccess
)
335 wxLogDebug("Failed to grab keyboard.");
336 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
337 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
338 (Window
) GetMainWindow());
342 m_winCaptured
= TRUE
;
346 void wxWindowX11::DoReleaseMouse()
348 g_captureWindow
= NULL
;
349 if ( !m_winCaptured
)
352 Window wMain
= (Window
)GetMainWindow();
356 XUngrabPointer(wxGlobalDisplay(), wMain
);
357 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
359 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
362 m_winCaptured
= FALSE
;
365 bool wxWindowX11::SetFont(const wxFont
& font
)
367 if ( !wxWindowBase::SetFont(font
) )
376 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
378 if ( !wxWindowBase::SetCursor(cursor
) )
384 wxCursor
* cursor2
= NULL
;
386 cursor2
= & m_cursor
;
388 cursor2
= wxSTANDARD_CURSOR
;
390 WXDisplay
*dpy
= GetXDisplay();
391 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
393 Window win
= (Window
) GetMainWindow();
394 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
399 // Coordinates relative to the window
400 void wxWindowX11::WarpPointer (int x
, int y
)
403 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
406 // Does a physical scroll
407 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
412 // Use specified rectangle
413 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
417 // Use whole client area
419 GetClientSize(& w
, & h
);
422 wxNode
*cnode
= m_children
.First();
425 wxWindow
*child
= (wxWindow
*) cnode
->Data();
428 child
->GetSize( &sx
, &sy
);
429 wxPoint
pos( child
->GetPosition() );
430 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
431 cnode
= cnode
->Next();
434 int x1
= (dx
>= 0) ? x
: x
- dx
;
435 int y1
= (dy
>= 0) ? y
: y
- dy
;
436 int w1
= w
- abs(dx
);
437 int h1
= h
- abs(dy
);
438 int x2
= (dx
>= 0) ? x
+ dx
: x
;
439 int y2
= (dy
>= 0) ? y
+ dy
: y
;
441 wxClientDC
dc((wxWindow
*) this);
443 dc
.SetLogicalFunction (wxCOPY
);
445 Window window
= (Window
) GetMainWindow();
446 Display
* display
= wxGlobalDisplay();
448 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
449 x1
, y1
, w1
, h1
, x2
, y2
);
451 dc
.SetAutoSetting(TRUE
);
452 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
453 dc
.SetBrush(brush
); // FIXME: needed?
455 // We'll add rectangles to the list of update rectangles according to which
456 // bits we've exposed.
461 wxRect
*rect
= new wxRect
;
467 XFillRectangle(display
, window
,
468 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
472 rect
->width
= rect
->width
;
473 rect
->height
= rect
->height
;
475 updateRects
.Append((wxObject
*) rect
);
479 wxRect
*rect
= new wxRect
;
481 rect
->x
= x
+ w
+ dx
;
486 XFillRectangle(display
, window
,
487 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
492 rect
->width
= rect
->width
;
493 rect
->height
= rect
->height
;
495 updateRects
.Append((wxObject
*) rect
);
499 wxRect
*rect
= new wxRect
;
506 XFillRectangle(display
, window
,
507 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
511 rect
->width
= rect
->width
;
512 rect
->height
= rect
->height
;
514 updateRects
.Append((wxObject
*) rect
);
518 wxRect
*rect
= new wxRect
;
521 rect
->y
= y
+ h
+ dy
;
525 XFillRectangle(display
, window
,
526 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
530 rect
->width
= rect
->width
;
531 rect
->height
= rect
->height
;
533 updateRects
.Append((wxObject
*) rect
);
535 dc
.SetBrush(wxNullBrush
);
537 // Now send expose events
539 wxNode
* node
= updateRects
.First();
542 wxRect
* rect
= (wxRect
*) node
->Data();
546 event
.display
= display
;
547 event
.send_event
= True
;
548 event
.window
= window
;
552 event
.width
= rect
->width
;
553 event
.height
= rect
->height
;
557 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
563 // Delete the update rects
564 node
= updateRects
.First();
567 wxRect
* rect
= (wxRect
*) node
->Data();
574 // XmUpdateDisplay((Widget) GetMainWidget());
577 // ---------------------------------------------------------------------------
579 // ---------------------------------------------------------------------------
581 #if wxUSE_DRAG_AND_DROP
583 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
590 // Old style file-manager drag&drop
591 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
596 // ----------------------------------------------------------------------------
598 // ----------------------------------------------------------------------------
602 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
607 #endif // wxUSE_TOOLTIPS
609 // ---------------------------------------------------------------------------
610 // moving and resizing
611 // ---------------------------------------------------------------------------
613 bool wxWindowX11::PreResize()
619 void wxWindowX11::DoGetSize(int *x
, int *y
) const
621 Window window
= (Window
) m_mainWidget
;
624 XWindowAttributes attr
;
625 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
630 *x
= attr
.width
/* + 2*m_borderSize */ ;
631 *y
= attr
.height
/* + 2*m_borderSize */ ;
636 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
638 Window window
= (Window
) m_mainWidget
;
641 XWindowAttributes attr
;
642 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
650 // We may be faking the client origin. So a window that's really at (0, 30)
651 // may appear (to wxWin apps) to be at (0, 0).
654 wxPoint
pt(GetParent()->GetClientAreaOrigin());
662 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
664 Display
*display
= wxGlobalDisplay();
665 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
666 Window thisWindow
= (Window
) m_mainWidget
;
671 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
674 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
676 Display
*display
= wxGlobalDisplay();
677 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
678 Window thisWindow
= (Window
) m_mainWidget
;
683 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
687 // Get size *available for subwindows* i.e. excluding menu bar etc.
688 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
690 Window window
= (Window
) m_mainWidget
;
694 XWindowAttributes attr
;
695 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
706 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
708 if (!GetMainWindow())
711 XWindowChanges windowChanges
;
714 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
719 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
724 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
726 windowChanges
.width
= width
/* - m_borderSize*2 */;
727 valueMask
|= CWWidth
;
729 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
731 windowChanges
.height
= height
/* -m_borderSize*2*/;
732 valueMask
|= CWHeight
;
734 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
736 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
737 valueMask
, & windowChanges
);
740 void wxWindowX11::DoSetClientSize(int width
, int height
)
742 if (!GetMainWindow())
745 XWindowChanges windowChanges
;
750 windowChanges
.width
= width
;
751 valueMask
|= CWWidth
;
755 windowChanges
.height
= height
;
756 valueMask
|= CWHeight
;
758 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
759 valueMask
, & windowChanges
);
762 // For implementation purposes - sometimes decorations make the client area
764 wxPoint
wxWindowX11::GetClientAreaOrigin() const
766 return wxPoint(0, 0);
769 // Makes an adjustment to the window position (for example, a frame that has
770 // a toolbar that it manages itself).
771 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
773 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
775 wxPoint
pt(GetParent()->GetClientAreaOrigin());
776 x
+= pt
.x
; y
+= pt
.y
;
780 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
787 XSizeHints sizeHints
;
790 if (minW
> -1 && minH
> -1)
792 sizeHints
.flags
|= PMinSize
;
793 sizeHints
.min_width
= minW
;
794 sizeHints
.min_height
= minH
;
796 if (maxW
> -1 && maxH
> -1)
798 sizeHints
.flags
|= PMaxSize
;
799 sizeHints
.max_width
= maxW
;
800 sizeHints
.max_height
= maxH
;
802 if (incW
> -1 && incH
> -1)
804 sizeHints
.flags
|= PResizeInc
;
805 sizeHints
.width_inc
= incW
;
806 sizeHints
.height_inc
= incH
;
809 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
812 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
814 DoSetSize(x
, y
, width
, height
);
817 // ---------------------------------------------------------------------------
819 // ---------------------------------------------------------------------------
821 int wxWindowX11::GetCharHeight() const
823 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
825 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
827 int direction
, ascent
, descent
;
829 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
832 // return (overall.ascent + overall.descent);
833 return (ascent
+ descent
);
836 int wxWindowX11::GetCharWidth() const
838 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
840 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
842 int direction
, ascent
, descent
;
844 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
847 return overall
.width
;
850 void wxWindowX11::GetTextExtent(const wxString
& string
,
852 int *descent
, int *externalLeading
,
853 const wxFont
*theFont
) const
855 wxFont
*fontToUse
= (wxFont
*)theFont
;
857 fontToUse
= (wxFont
*) & m_font
;
859 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
861 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
863 int direction
, ascent
, descent2
;
865 int slen
= string
.Len();
869 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
870 &ascent
, &descent2
, &overall
);
873 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
874 &direction
, &ascent
, &descent2
, &overall
);
877 *x
= (overall
.width
);
879 *y
= (ascent
+ descent2
);
883 *externalLeading
= 0;
887 // ----------------------------------------------------------------------------
889 // ----------------------------------------------------------------------------
891 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
897 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
898 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
903 GetSize( &width
, &height
);
905 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
906 m_clearRegion
.Clear();
907 m_clearRegion
.Union( 0, 0, width
, height
);
913 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
914 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
919 GetSize( &width
, &height
);
921 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
922 m_updateRegion
.Clear();
923 m_updateRegion
.Union( 0, 0, width
, height
);
926 // Actually don't schedule yet..
930 void wxWindowX11::Update()
932 if (!m_updateRegion
.IsEmpty())
934 X11SendPaintEvents();
938 void wxWindowX11::Clear()
940 wxClientDC
dc((wxWindow
*) this);
941 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
942 dc
.SetBackground(brush
);
946 void wxWindowX11::X11SendPaintEvents()
948 m_clipPaintRegion
= TRUE
;
950 if (!m_clearRegion
.IsEmpty())
952 wxWindowDC
dc( (wxWindow
*)this );
953 dc
.SetClippingRegion( m_clearRegion
);
955 wxEraseEvent
erase_event( GetId(), &dc
);
956 erase_event
.SetEventObject( this );
958 if (!GetEventHandler()->ProcessEvent(erase_event
))
960 wxRegionIterator
upd( m_clearRegion
);
963 // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
967 m_clearRegion
.Clear();
970 wxNcPaintEvent
nc_paint_event( GetId() );
971 nc_paint_event
.SetEventObject( this );
972 GetEventHandler()->ProcessEvent( nc_paint_event
);
974 wxPaintEvent
paint_event( GetId() );
975 paint_event
.SetEventObject( this );
976 GetEventHandler()->ProcessEvent( paint_event
);
978 m_clipPaintRegion
= FALSE
;
981 // ----------------------------------------------------------------------------
983 // ----------------------------------------------------------------------------
985 // Responds to colour changes: passes event on to children.
986 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
988 wxWindowList::Node
*node
= GetChildren().GetFirst();
991 // Only propagate to non-top-level windows
992 wxWindow
*win
= node
->GetData();
993 if ( win
->GetParent() )
995 wxSysColourChangedEvent event2
;
996 event
.m_eventObject
= win
;
997 win
->GetEventHandler()->ProcessEvent(event2
);
1000 node
= node
->GetNext();
1004 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1006 // This calls the UI-update mechanism (querying windows for
1007 // menu/toolbar/control state information)
1011 // ----------------------------------------------------------------------------
1012 // function which maintain the global hash table mapping Widgets to wxWindows
1013 // ----------------------------------------------------------------------------
1015 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1017 wxWindow
*oldItem
= NULL
;
1018 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1020 wxLogDebug("Widget table clash: new widget is %ld, %s",
1021 (long)w
, win
->GetClassInfo()->GetClassName());
1025 wxWidgetHashTable
->Put((long) w
, win
);
1027 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1028 w
, win
, win
->GetClassInfo()->GetClassName());
1033 wxWindow
*wxGetWindowFromTable(Window w
)
1035 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1038 void wxDeleteWindowFromTable(Window w
)
1040 wxWidgetHashTable
->Delete((long)w
);
1043 // ----------------------------------------------------------------------------
1044 // add/remove window from the table
1045 // ----------------------------------------------------------------------------
1047 // ----------------------------------------------------------------------------
1048 // X11-specific accessors
1049 // ----------------------------------------------------------------------------
1051 // Get the underlying X window
1052 WXWindow
wxWindowX11::GetXWindow() const
1054 return GetMainWindow();
1057 // Get the underlying X display
1058 WXDisplay
*wxWindowX11::GetXDisplay() const
1060 return wxGetDisplay();
1063 WXWindow
wxWindowX11::GetMainWindow() const
1065 return m_mainWidget
;
1068 // ----------------------------------------------------------------------------
1069 // TranslateXXXEvent() functions
1070 // ----------------------------------------------------------------------------
1072 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1074 switch (xevent
->xany
.type
)
1082 wxEventType eventType
= wxEVT_NULL
;
1084 if (xevent
->xany
.type
== EnterNotify
)
1086 //if (local_event.xcrossing.mode!=NotifyNormal)
1087 // return ; // Ignore grab events
1088 eventType
= wxEVT_ENTER_WINDOW
;
1089 // canvas->GetEventHandler()->OnSetFocus();
1091 else if (xevent
->xany
.type
== LeaveNotify
)
1093 //if (local_event.xcrossingr.mode!=NotifyNormal)
1094 // return ; // Ignore grab events
1095 eventType
= wxEVT_LEAVE_WINDOW
;
1096 // canvas->GetEventHandler()->OnKillFocus();
1098 else if (xevent
->xany
.type
== MotionNotify
)
1100 eventType
= wxEVT_MOTION
;
1102 else if (xevent
->xany
.type
== ButtonPress
)
1104 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1106 if (xevent
->xbutton
.button
== Button1
)
1108 eventType
= wxEVT_LEFT_DOWN
;
1111 else if (xevent
->xbutton
.button
== Button2
)
1113 eventType
= wxEVT_MIDDLE_DOWN
;
1116 else if (xevent
->xbutton
.button
== Button3
)
1118 eventType
= wxEVT_RIGHT_DOWN
;
1122 // check for a double click
1123 // TODO: where can we get this value from?
1124 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1125 long dclickTime
= 200;
1126 long ts
= wxevent
.GetTimestamp();
1128 int buttonLast
= win
->GetLastClickedButton();
1129 long lastTS
= win
->GetLastClickTime();
1130 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1133 win
->SetLastClick(0, ts
);
1134 if ( eventType
== wxEVT_LEFT_DOWN
)
1135 eventType
= wxEVT_LEFT_DCLICK
;
1136 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1137 eventType
= wxEVT_MIDDLE_DCLICK
;
1138 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1139 eventType
= wxEVT_RIGHT_DCLICK
;
1143 // not fast enough or different button
1144 win
->SetLastClick(button
, ts
);
1147 else if (xevent
->xany
.type
== ButtonRelease
)
1149 if (xevent
->xbutton
.button
== Button1
)
1151 eventType
= wxEVT_LEFT_UP
;
1153 else if (xevent
->xbutton
.button
== Button2
)
1155 eventType
= wxEVT_MIDDLE_UP
;
1157 else if (xevent
->xbutton
.button
== Button3
)
1159 eventType
= wxEVT_RIGHT_UP
;
1168 wxevent
.SetEventType(eventType
);
1170 wxevent
.m_x
= xevent
->xbutton
.x
;
1171 wxevent
.m_y
= xevent
->xbutton
.y
;
1173 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1174 || (event_left_is_down (xevent
)
1175 && (eventType
!= wxEVT_LEFT_UP
)));
1176 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1177 || (event_middle_is_down (xevent
)
1178 && (eventType
!= wxEVT_MIDDLE_UP
)));
1179 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1180 || (event_right_is_down (xevent
)
1181 && (eventType
!= wxEVT_RIGHT_UP
)));
1183 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1184 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1185 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1186 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1188 wxevent
.SetId(win
->GetId());
1189 wxevent
.SetEventObject(win
);
1197 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1199 switch (xevent
->xany
.type
)
1207 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1208 int id
= wxCharCodeXToWX (keySym
);
1210 if (xevent
->xkey
.state
& ShiftMask
)
1211 wxevent
.m_shiftDown
= TRUE
;
1212 if (xevent
->xkey
.state
& ControlMask
)
1213 wxevent
.m_controlDown
= TRUE
;
1214 if (xevent
->xkey
.state
& Mod3Mask
)
1215 wxevent
.m_altDown
= TRUE
;
1216 if (xevent
->xkey
.state
& Mod1Mask
)
1217 wxevent
.m_metaDown
= TRUE
;
1218 wxevent
.SetEventObject(win
);
1219 wxevent
.m_keyCode
= id
;
1220 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1222 wxevent
.m_x
= xevent
->xbutton
.x
;
1223 wxevent
.m_y
= xevent
->xbutton
.y
;
1237 // ----------------------------------------------------------------------------
1239 // ----------------------------------------------------------------------------
1243 #define YAllocColor XAllocColor
1244 XColor g_itemColors
[5];
1245 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1248 static XmColorProc colorProc
;
1250 result
= wxNO_COLORS
;
1254 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1255 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1256 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1257 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1258 if (colorProc
== (XmColorProc
) NULL
)
1260 // Get a ptr to the actual function
1261 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1262 // And set it back to motif.
1263 XmSetColorCalculation (colorProc
);
1265 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1266 &g_itemColors
[wxFORE_INDEX
],
1267 &g_itemColors
[wxSELE_INDEX
],
1268 &g_itemColors
[wxTOPS_INDEX
],
1269 &g_itemColors
[wxBOTS_INDEX
]);
1270 result
= wxBACK_COLORS
;
1274 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1275 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1276 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1277 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1278 if (result
== wxNO_COLORS
)
1279 result
= wxFORE_COLORS
;
1282 Display
*dpy
= display
;
1283 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1287 /* 5 Colours to allocate */
1288 for (int i
= 0; i
< 5; i
++)
1289 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1290 result
= wxNO_COLORS
;
1294 /* Only 1 colour to allocate */
1295 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1296 result
= wxNO_COLORS
;
1304 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1306 if ( !wxWindowBase::SetBackgroundColour(col
) )
1309 if (!GetMainWindow())
1312 XSetWindowAttributes attrib
;
1313 attrib
.background_pixel
= ((wxColour
&)col
).AllocColour(wxGlobalDisplay());
1315 XChangeWindowAttributes(wxGlobalDisplay(),
1316 (Window
) GetMainWindow(),
1323 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1325 if ( !wxWindowBase::SetForegroundColour(col
) )
1331 // ----------------------------------------------------------------------------
1333 // ----------------------------------------------------------------------------
1335 wxWindow
*wxGetActiveWindow()
1338 wxFAIL_MSG("Not implemented");
1343 wxWindow
*wxWindowBase::GetCapture()
1345 return (wxWindow
*)g_captureWindow
;
1349 // Find the wxWindow at the current mouse position, returning the mouse
1351 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1353 return wxFindWindowAtPoint(wxGetMousePosition());
1356 // Get the current mouse position.
1357 wxPoint
wxGetMousePosition()
1359 Display
*display
= wxGlobalDisplay();
1360 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1361 Window rootReturn
, childReturn
;
1362 int rootX
, rootY
, winX
, winY
;
1363 unsigned int maskReturn
;
1365 XQueryPointer (display
,
1369 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1370 return wxPoint(rootX
, rootY
);
1374 // ----------------------------------------------------------------------------
1375 // wxNoOptimize: switch off size optimization
1376 // ----------------------------------------------------------------------------
1378 int wxNoOptimize::ms_count
= 0;