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_DYNAMIC_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
;
131 // TODO: How to create more interesting borders?
132 // Will presumably have to create multiple windows.
133 if (style
& wxSIMPLE_BORDER
)
136 } else if (style
& wxSUNKEN_BORDER
)
139 } else if (style
& wxRAISED_BORDER
)
145 int w
= size
.GetWidth();
146 int h
= size
.GetHeight();
154 int screen
= DefaultScreen(wxGlobalDisplay());
158 parentWindow
= (Window
) parent
->GetMainWindow();
160 parentWindow
= RootWindow(wxGlobalDisplay(), screen
);
162 Window window
= XCreateSimpleWindow(wxGlobalDisplay(), parentWindow
,
164 m_backgroundColour
.AllocColour(wxGlobalDisplay()),
165 m_foregroundColour
.AllocColour(wxGlobalDisplay()));
167 // Select event types wanted
168 XSelectInput(wxGlobalDisplay(), window
,
169 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
170 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
171 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
174 wxAddWindowToTable(window
, (wxWindow
*) this);
176 // If a subwindow, show.
177 // if (parent && !parent->IsKindOf(CLASSINFO(wxTopLevelWindowX11)) && parent->IsShown())
180 XMapWindow(wxGlobalDisplay(), window
);
183 // Without this, the cursor may not be restored properly (e.g. in splitter
185 SetCursor(*wxSTANDARD_CURSOR
);
186 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
187 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
193 wxWindowX11::~wxWindowX11()
195 if (g_captureWindow
== this)
196 g_captureWindow
= NULL
;
198 m_isBeingDeleted
= TRUE
;
200 // X11-specific actions first
201 Window main
= (Window
) m_mainWidget
;
204 // Removes event handlers
205 //DetachWidget(main);
209 m_parent
->RemoveChild( this );
213 // Destroy the window
216 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
217 wxDeleteWindowFromTable( main
);
218 XDestroyWindow( wxGlobalDisplay(), main
);
223 // ---------------------------------------------------------------------------
225 // ---------------------------------------------------------------------------
227 void wxWindowX11::SetFocus()
230 Window wMain
= (Window
) GetMainWidget();
233 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
236 wmhints
.flags
= InputHint
;
237 wmhints
.input
= True
;
238 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
)
243 // Get the window with the focus
244 wxWindow
*wxWindowBase::FindFocus()
246 Window wFocus
= (Window
) 0;
249 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
252 wxWindow
*win
= NULL
;
255 win
= wxGetWindowFromTable(wFocus
);
256 wFocus
= wxGetWindowParent(wFocus
);
257 } while (wFocus
&& !win
);
265 // Enabling/disabling handled by event loop, and not sending events
267 bool wxWindowX11::Enable(bool enable
)
269 if ( !wxWindowBase::Enable(enable
) )
275 bool wxWindowX11::Show(bool show
)
277 if ( !wxWindowBase::Show(show
) )
280 Window xwin
= (Window
) GetXWindow();
281 Display
*xdisp
= (Display
*) GetXDisplay();
284 XMapWindow(xdisp
, xwin
);
288 XUnmapWindow(xdisp
, xwin
);
294 // Raise the window to the top of the Z order
295 void wxWindowX11::Raise()
298 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
301 // Lower the window to the bottom of the Z order
302 void wxWindowX11::Lower()
305 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
308 void wxWindowX11::DoCaptureMouse()
310 g_captureWindow
= (wxWindow
*) this;
314 // TODO: should we also call XGrabButton, XGrabKeyboard?
317 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
319 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
323 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
326 if (res
== GrabSuccess
)
328 m_winCaptured
= TRUE
;
333 void wxWindowX11::DoReleaseMouse()
335 g_captureWindow
= NULL
;
336 if ( !m_winCaptured
)
339 Window wMain
= (Window
)GetMainWindow();
341 // TODO: should we also call XUngrabButton, XUngrabKeyboard?
343 XUngrabPointer(wxGlobalDisplay(), wMain
);
345 m_winCaptured
= FALSE
;
348 bool wxWindowX11::SetFont(const wxFont
& font
)
350 if ( !wxWindowBase::SetFont(font
) )
359 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
361 if ( !wxWindowBase::SetCursor(cursor
) )
367 wxCursor
* cursor2
= NULL
;
369 cursor2
= & m_cursor
;
371 cursor2
= wxSTANDARD_CURSOR
;
373 WXDisplay
*dpy
= GetXDisplay();
374 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
376 Window win
= (Window
) GetMainWindow();
377 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
382 // Coordinates relative to the window
383 void wxWindowX11::WarpPointer (int x
, int y
)
386 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
389 // ---------------------------------------------------------------------------
391 // ---------------------------------------------------------------------------
393 int wxWindowX11::GetScrollPos(int orient
) const
398 // This now returns the whole range, not just the number of positions that we
400 int wxWindowX11::GetScrollRange(int WXUNUSED(orient
)) const
405 int wxWindowX11::GetScrollThumb(int orient
) const
411 void wxWindowX11::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
416 // New function that will replace some of the above.
417 void wxWindowX11::SetScrollbar(int WXUNUSED(orient
), int WXUNUSED(pos
), int WXUNUSED(thumbVisible
),
418 int WXUNUSED(range
), bool WXUNUSED(refresh
))
423 // Does a physical scroll
424 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
429 // Use specified rectangle
430 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
434 // Use whole client area
436 GetClientSize(& w
, & h
);
439 wxNode
*cnode
= m_children
.First();
442 wxWindow
*child
= (wxWindow
*) cnode
->Data();
445 child
->GetSize( &sx
, &sy
);
446 wxPoint
pos( child
->GetPosition() );
447 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
448 cnode
= cnode
->Next();
451 int x1
= (dx
>= 0) ? x
: x
- dx
;
452 int y1
= (dy
>= 0) ? y
: y
- dy
;
453 int w1
= w
- abs(dx
);
454 int h1
= h
- abs(dy
);
455 int x2
= (dx
>= 0) ? x
+ dx
: x
;
456 int y2
= (dy
>= 0) ? y
+ dy
: y
;
458 wxClientDC
dc((wxWindow
*) this);
460 dc
.SetLogicalFunction (wxCOPY
);
462 Window window
= (Window
) GetMainWindow();
463 Display
* display
= wxGlobalDisplay();
465 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
466 x1
, y1
, w1
, h1
, x2
, y2
);
468 dc
.SetAutoSetting(TRUE
);
469 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
470 dc
.SetBrush(brush
); // FIXME: needed?
472 // We'll add rectangles to the list of update rectangles according to which
473 // bits we've exposed.
478 wxRect
*rect
= new wxRect
;
484 XFillRectangle(display
, window
,
485 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
489 rect
->width
= rect
->width
;
490 rect
->height
= rect
->height
;
492 updateRects
.Append((wxObject
*) rect
);
496 wxRect
*rect
= new wxRect
;
498 rect
->x
= x
+ w
+ dx
;
503 XFillRectangle(display
, window
,
504 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
509 rect
->width
= rect
->width
;
510 rect
->height
= rect
->height
;
512 updateRects
.Append((wxObject
*) rect
);
516 wxRect
*rect
= new wxRect
;
523 XFillRectangle(display
, window
,
524 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
528 rect
->width
= rect
->width
;
529 rect
->height
= rect
->height
;
531 updateRects
.Append((wxObject
*) rect
);
535 wxRect
*rect
= new wxRect
;
538 rect
->y
= y
+ h
+ dy
;
542 XFillRectangle(display
, window
,
543 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
547 rect
->width
= rect
->width
;
548 rect
->height
= rect
->height
;
550 updateRects
.Append((wxObject
*) rect
);
552 dc
.SetBrush(wxNullBrush
);
554 // Now send expose events
556 wxNode
* node
= updateRects
.First();
559 wxRect
* rect
= (wxRect
*) node
->Data();
563 event
.display
= display
;
564 event
.send_event
= True
;
565 event
.window
= window
;
569 event
.width
= rect
->width
;
570 event
.height
= rect
->height
;
574 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
580 // Delete the update rects
581 node
= updateRects
.First();
584 wxRect
* rect
= (wxRect
*) node
->Data();
591 // XmUpdateDisplay((Widget) GetMainWidget());
594 // ---------------------------------------------------------------------------
596 // ---------------------------------------------------------------------------
598 #if wxUSE_DRAG_AND_DROP
600 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
607 // Old style file-manager drag&drop
608 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
613 // ----------------------------------------------------------------------------
615 // ----------------------------------------------------------------------------
619 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
624 #endif // wxUSE_TOOLTIPS
626 // ---------------------------------------------------------------------------
627 // moving and resizing
628 // ---------------------------------------------------------------------------
630 bool wxWindowX11::PreResize()
636 void wxWindowX11::DoGetSize(int *x
, int *y
) const
638 Window window
= (Window
) m_mainWidget
;
641 XWindowAttributes attr
;
642 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
647 *x
= attr
.width
/* + 2*m_borderSize */ ;
648 *y
= attr
.height
/* + 2*m_borderSize */ ;
653 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
655 Window window
= (Window
) m_mainWidget
;
658 XWindowAttributes attr
;
659 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
667 // We may be faking the client origin. So a window that's really at (0, 30)
668 // may appear (to wxWin apps) to be at (0, 0).
671 wxPoint
pt(GetParent()->GetClientAreaOrigin());
679 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
681 Display
*display
= wxGlobalDisplay();
682 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
683 Window thisWindow
= (Window
) m_mainWidget
;
688 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
691 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
693 Display
*display
= wxGlobalDisplay();
694 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
695 Window thisWindow
= (Window
) m_mainWidget
;
700 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
704 // Get size *available for subwindows* i.e. excluding menu bar etc.
705 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
707 Window window
= (Window
) m_mainWidget
;
711 XWindowAttributes attr
;
712 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
723 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
725 if (!GetMainWindow())
728 XWindowChanges windowChanges
;
731 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
736 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
741 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
743 windowChanges
.width
= width
/* - m_borderSize*2 */;
744 valueMask
|= CWWidth
;
746 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
748 windowChanges
.height
= height
/* -m_borderSize*2*/;
749 valueMask
|= CWHeight
;
751 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
753 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
754 valueMask
, & windowChanges
);
757 void wxWindowX11::DoSetClientSize(int width
, int height
)
759 if (!GetMainWindow())
762 XWindowChanges windowChanges
;
767 windowChanges
.width
= width
;
768 valueMask
|= CWWidth
;
772 windowChanges
.height
= height
;
773 valueMask
|= CWHeight
;
775 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
776 valueMask
, & windowChanges
);
779 // For implementation purposes - sometimes decorations make the client area
781 wxPoint
wxWindowX11::GetClientAreaOrigin() const
783 return wxPoint(0, 0);
786 // Makes an adjustment to the window position (for example, a frame that has
787 // a toolbar that it manages itself).
788 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
790 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
792 wxPoint
pt(GetParent()->GetClientAreaOrigin());
793 x
+= pt
.x
; y
+= pt
.y
;
797 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
804 XSizeHints sizeHints
;
807 if (minW
> -1 && minH
> -1)
809 sizeHints
.flags
|= PMinSize
;
810 sizeHints
.min_width
= minW
;
811 sizeHints
.min_height
= minH
;
813 if (maxW
> -1 && maxH
> -1)
815 sizeHints
.flags
|= PMaxSize
;
816 sizeHints
.max_width
= maxW
;
817 sizeHints
.max_height
= maxH
;
819 if (incW
> -1 && incH
> -1)
821 sizeHints
.flags
|= PResizeInc
;
822 sizeHints
.width_inc
= incW
;
823 sizeHints
.height_inc
= incH
;
826 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
829 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
831 DoSetSize(x
, y
, width
, height
);
834 // ---------------------------------------------------------------------------
836 // ---------------------------------------------------------------------------
838 int wxWindowX11::GetCharHeight() const
840 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
842 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
844 int direction
, ascent
, descent
;
846 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
849 // return (overall.ascent + overall.descent);
850 return (ascent
+ descent
);
853 int wxWindowX11::GetCharWidth() 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
.width
;
867 void wxWindowX11::GetTextExtent(const wxString
& string
,
869 int *descent
, int *externalLeading
,
870 const wxFont
*theFont
) const
872 wxFont
*fontToUse
= (wxFont
*)theFont
;
874 fontToUse
= (wxFont
*) & m_font
;
876 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
878 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
880 int direction
, ascent
, descent2
;
882 int slen
= string
.Len();
886 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
887 &ascent
, &descent2
, &overall
);
890 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
891 &direction
, &ascent
, &descent2
, &overall
);
894 *x
= (overall
.width
);
896 *y
= (ascent
+ descent2
);
900 *externalLeading
= 0;
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
914 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
915 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
920 GetSize( &width
, &height
);
922 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
923 m_clearRegion
.Clear();
924 m_clearRegion
.Union( 0, 0, width
, height
);
930 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
931 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
936 GetSize( &width
, &height
);
938 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
939 m_updateRegion
.Clear();
940 m_updateRegion
.Union( 0, 0, width
, height
);
943 // Actually don't schedule yet..
947 void wxWindowX11::Update()
949 if (!m_updateRegion
.IsEmpty())
951 X11SendPaintEvents();
955 void wxWindowX11::Clear()
957 wxClientDC
dc((wxWindow
*) this);
958 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
959 dc
.SetBackground(brush
);
963 void wxWindowX11::X11SendPaintEvents()
965 m_clipPaintRegion
= TRUE
;
967 if (!m_clearRegion
.IsEmpty())
969 wxWindowDC
dc( (wxWindow
*)this );
970 dc
.SetClippingRegion( m_clearRegion
);
972 wxEraseEvent
erase_event( GetId(), &dc
);
973 erase_event
.SetEventObject( this );
975 if (!GetEventHandler()->ProcessEvent(erase_event
))
977 wxRegionIterator
upd( m_clearRegion
);
980 // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
984 m_clearRegion
.Clear();
987 wxNcPaintEvent
nc_paint_event( GetId() );
988 nc_paint_event
.SetEventObject( this );
989 GetEventHandler()->ProcessEvent( nc_paint_event
);
991 wxPaintEvent
paint_event( GetId() );
992 paint_event
.SetEventObject( this );
993 GetEventHandler()->ProcessEvent( paint_event
);
995 m_clipPaintRegion
= FALSE
;
998 // ----------------------------------------------------------------------------
1000 // ----------------------------------------------------------------------------
1002 // Responds to colour changes: passes event on to children.
1003 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1005 wxWindowList::Node
*node
= GetChildren().GetFirst();
1008 // Only propagate to non-top-level windows
1009 wxWindow
*win
= node
->GetData();
1010 if ( win
->GetParent() )
1012 wxSysColourChangedEvent event2
;
1013 event
.m_eventObject
= win
;
1014 win
->GetEventHandler()->ProcessEvent(event2
);
1017 node
= node
->GetNext();
1021 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1023 // This calls the UI-update mechanism (querying windows for
1024 // menu/toolbar/control state information)
1028 // ----------------------------------------------------------------------------
1029 // function which maintain the global hash table mapping Widgets to wxWindows
1030 // ----------------------------------------------------------------------------
1032 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1034 wxWindow
*oldItem
= NULL
;
1035 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1037 wxLogDebug("Widget table clash: new widget is %ld, %s",
1038 (long)w
, win
->GetClassInfo()->GetClassName());
1042 wxWidgetHashTable
->Put((long) w
, win
);
1044 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1045 w
, win
, win
->GetClassInfo()->GetClassName());
1050 wxWindow
*wxGetWindowFromTable(Window w
)
1052 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1055 void wxDeleteWindowFromTable(Window w
)
1057 wxWidgetHashTable
->Delete((long)w
);
1060 // ----------------------------------------------------------------------------
1061 // add/remove window from the table
1062 // ----------------------------------------------------------------------------
1064 // ----------------------------------------------------------------------------
1065 // X11-specific accessors
1066 // ----------------------------------------------------------------------------
1068 // Get the underlying X window
1069 WXWindow
wxWindowX11::GetXWindow() const
1071 return GetMainWindow();
1074 // Get the underlying X display
1075 WXDisplay
*wxWindowX11::GetXDisplay() const
1077 return wxGetDisplay();
1080 WXWindow
wxWindowX11::GetMainWindow() const
1082 return m_mainWidget
;
1085 // ----------------------------------------------------------------------------
1087 // ----------------------------------------------------------------------------
1089 // TODO: implement wxWindow scrollbar, presumably using wxScrollBar
1091 static void wxScrollBarCallback(Widget scrollbar
,
1092 XtPointer clientData
,
1093 XmScrollBarCallbackStruct
*cbs
)
1095 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
1096 int orientation
= (int) clientData
;
1098 wxEventType eventType
= wxEVT_NULL
;
1099 switch (cbs
->reason
)
1101 case XmCR_INCREMENT
:
1103 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
1106 case XmCR_DECREMENT
:
1108 eventType
= wxEVT_SCROLLWIN_LINEUP
;
1113 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
1116 case XmCR_VALUE_CHANGED
:
1118 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
1121 case XmCR_PAGE_INCREMENT
:
1123 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
1126 case XmCR_PAGE_DECREMENT
:
1128 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
1133 eventType
= wxEVT_SCROLLWIN_TOP
;
1136 case XmCR_TO_BOTTOM
:
1138 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
1143 // Should never get here
1144 wxFAIL_MSG("Unknown scroll event.");
1149 wxScrollWinEvent
event(eventType
,
1151 ((orientation
== XmHORIZONTAL
) ?
1152 wxHORIZONTAL
: wxVERTICAL
));
1153 event
.SetEventObject( win
);
1154 win
->GetEventHandler()->ProcessEvent(event
);
1158 // ----------------------------------------------------------------------------
1159 // TranslateXXXEvent() functions
1160 // ----------------------------------------------------------------------------
1162 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1164 switch (xevent
->xany
.type
)
1172 wxEventType eventType
= wxEVT_NULL
;
1174 if (xevent
->xany
.type
== EnterNotify
)
1176 //if (local_event.xcrossing.mode!=NotifyNormal)
1177 // return ; // Ignore grab events
1178 eventType
= wxEVT_ENTER_WINDOW
;
1179 // canvas->GetEventHandler()->OnSetFocus();
1181 else if (xevent
->xany
.type
== LeaveNotify
)
1183 //if (local_event.xcrossingr.mode!=NotifyNormal)
1184 // return ; // Ignore grab events
1185 eventType
= wxEVT_LEAVE_WINDOW
;
1186 // canvas->GetEventHandler()->OnKillFocus();
1188 else if (xevent
->xany
.type
== MotionNotify
)
1190 eventType
= wxEVT_MOTION
;
1192 else if (xevent
->xany
.type
== ButtonPress
)
1194 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1196 if (xevent
->xbutton
.button
== Button1
)
1198 eventType
= wxEVT_LEFT_DOWN
;
1201 else if (xevent
->xbutton
.button
== Button2
)
1203 eventType
= wxEVT_MIDDLE_DOWN
;
1206 else if (xevent
->xbutton
.button
== Button3
)
1208 eventType
= wxEVT_RIGHT_DOWN
;
1212 // check for a double click
1213 // TODO: where can we get this value from?
1214 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1215 long dclickTime
= 200;
1216 long ts
= wxevent
.GetTimestamp();
1218 int buttonLast
= win
->GetLastClickedButton();
1219 long lastTS
= win
->GetLastClickTime();
1220 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1223 win
->SetLastClick(0, ts
);
1224 if ( eventType
== wxEVT_LEFT_DOWN
)
1225 eventType
= wxEVT_LEFT_DCLICK
;
1226 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1227 eventType
= wxEVT_MIDDLE_DCLICK
;
1228 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1229 eventType
= wxEVT_RIGHT_DCLICK
;
1233 // not fast enough or different button
1234 win
->SetLastClick(button
, ts
);
1237 else if (xevent
->xany
.type
== ButtonRelease
)
1239 if (xevent
->xbutton
.button
== Button1
)
1241 eventType
= wxEVT_LEFT_UP
;
1243 else if (xevent
->xbutton
.button
== Button2
)
1245 eventType
= wxEVT_MIDDLE_UP
;
1247 else if (xevent
->xbutton
.button
== Button3
)
1249 eventType
= wxEVT_RIGHT_UP
;
1258 wxevent
.SetEventType(eventType
);
1260 wxevent
.m_x
= xevent
->xbutton
.x
;
1261 wxevent
.m_y
= xevent
->xbutton
.y
;
1263 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1264 || (event_left_is_down (xevent
)
1265 && (eventType
!= wxEVT_LEFT_UP
)));
1266 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1267 || (event_middle_is_down (xevent
)
1268 && (eventType
!= wxEVT_MIDDLE_UP
)));
1269 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1270 || (event_right_is_down (xevent
)
1271 && (eventType
!= wxEVT_RIGHT_UP
)));
1273 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1274 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1275 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1276 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1278 wxevent
.SetId(win
->GetId());
1279 wxevent
.SetEventObject(win
);
1287 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1289 switch (xevent
->xany
.type
)
1297 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1298 int id
= wxCharCodeXToWX (keySym
);
1300 if (xevent
->xkey
.state
& ShiftMask
)
1301 wxevent
.m_shiftDown
= TRUE
;
1302 if (xevent
->xkey
.state
& ControlMask
)
1303 wxevent
.m_controlDown
= TRUE
;
1304 if (xevent
->xkey
.state
& Mod3Mask
)
1305 wxevent
.m_altDown
= TRUE
;
1306 if (xevent
->xkey
.state
& Mod1Mask
)
1307 wxevent
.m_metaDown
= TRUE
;
1308 wxevent
.SetEventObject(win
);
1309 wxevent
.m_keyCode
= id
;
1310 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1312 wxevent
.m_x
= xevent
->xbutton
.x
;
1313 wxevent
.m_y
= xevent
->xbutton
.y
;
1327 // ----------------------------------------------------------------------------
1329 // ----------------------------------------------------------------------------
1333 #define YAllocColor XAllocColor
1334 XColor g_itemColors
[5];
1335 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1338 static XmColorProc colorProc
;
1340 result
= wxNO_COLORS
;
1344 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1345 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1346 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1347 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1348 if (colorProc
== (XmColorProc
) NULL
)
1350 // Get a ptr to the actual function
1351 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1352 // And set it back to motif.
1353 XmSetColorCalculation (colorProc
);
1355 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1356 &g_itemColors
[wxFORE_INDEX
],
1357 &g_itemColors
[wxSELE_INDEX
],
1358 &g_itemColors
[wxTOPS_INDEX
],
1359 &g_itemColors
[wxBOTS_INDEX
]);
1360 result
= wxBACK_COLORS
;
1364 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1365 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1366 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1367 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1368 if (result
== wxNO_COLORS
)
1369 result
= wxFORE_COLORS
;
1372 Display
*dpy
= display
;
1373 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1377 /* 5 Colours to allocate */
1378 for (int i
= 0; i
< 5; i
++)
1379 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1380 result
= wxNO_COLORS
;
1384 /* Only 1 colour to allocate */
1385 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1386 result
= wxNO_COLORS
;
1394 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1396 if ( !wxWindowBase::SetBackgroundColour(col
) )
1402 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1404 if ( !wxWindowBase::SetForegroundColour(col
) )
1410 // ----------------------------------------------------------------------------
1412 // ----------------------------------------------------------------------------
1414 wxWindow
*wxGetActiveWindow()
1417 wxFAIL_MSG("Not implemented");
1422 wxWindow
*wxWindowBase::GetCapture()
1424 return (wxWindow
*)g_captureWindow
;
1428 // Find the wxWindow at the current mouse position, returning the mouse
1430 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1432 return wxFindWindowAtPoint(wxGetMousePosition());
1435 // Get the current mouse position.
1436 wxPoint
wxGetMousePosition()
1438 Display
*display
= wxGlobalDisplay();
1439 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1440 Window rootReturn
, childReturn
;
1441 int rootX
, rootY
, winX
, winY
;
1442 unsigned int maskReturn
;
1444 XQueryPointer (display
,
1448 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1449 return wxPoint(rootX
, rootY
);
1453 // ----------------------------------------------------------------------------
1454 // wxNoOptimize: switch off size optimization
1455 // ----------------------------------------------------------------------------
1457 int wxNoOptimize::ms_count
= 0;