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
);
142 m_foregroundColour
= *wxBLACK
;
143 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
146 Window parentWindow
= (Window
) parent
->GetMainWindow();
148 Window window
= XCreateSimpleWindow(
149 xdisplay
, parentWindow
,
151 m_backgroundColour
.GetPixel(),
152 m_foregroundColour
.GetPixel() );
154 m_mainWidget
= (WXWindow
) window
;
156 // Select event types wanted
157 XSelectInput(wxGlobalDisplay(), window
,
158 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
159 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
160 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
163 wxAddWindowToTable(window
, (wxWindow
*) this);
165 // Is a subwindow, so map immediately
167 XMapWindow(wxGlobalDisplay(), window
);
169 // Without this, the cursor may not be restored properly (e.g. in splitter
171 SetCursor(*wxSTANDARD_CURSOR
);
172 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
173 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
179 wxWindowX11::~wxWindowX11()
181 if (g_captureWindow
== this)
182 g_captureWindow
= NULL
;
184 m_isBeingDeleted
= TRUE
;
186 // X11-specific actions first
187 Window main
= (Window
) m_mainWidget
;
190 // Removes event handlers
191 //DetachWidget(main);
195 m_parent
->RemoveChild( this );
199 // Destroy the window
202 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
203 wxDeleteWindowFromTable( main
);
204 XDestroyWindow( wxGlobalDisplay(), main
);
209 // ---------------------------------------------------------------------------
211 // ---------------------------------------------------------------------------
213 void wxWindowX11::SetFocus()
215 Window wMain
= (Window
) GetMainWindow();
218 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
221 wmhints
.flags
= InputHint
;
222 wmhints
.input
= True
;
223 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
227 // Get the window with the focus
228 wxWindow
*wxWindowBase::FindFocus()
230 Window wFocus
= (Window
) 0;
233 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
236 wxWindow
*win
= NULL
;
239 win
= wxGetWindowFromTable(wFocus
);
240 wFocus
= wxGetWindowParent(wFocus
);
241 } while (wFocus
&& !win
);
249 // Enabling/disabling handled by event loop, and not sending events
251 bool wxWindowX11::Enable(bool enable
)
253 if ( !wxWindowBase::Enable(enable
) )
259 bool wxWindowX11::Show(bool show
)
261 if ( !wxWindowBase::Show(show
) )
264 Window xwin
= (Window
) GetXWindow();
265 Display
*xdisp
= (Display
*) GetXDisplay();
268 XMapWindow(xdisp
, xwin
);
272 XUnmapWindow(xdisp
, xwin
);
278 // Raise the window to the top of the Z order
279 void wxWindowX11::Raise()
282 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
285 // Lower the window to the bottom of the Z order
286 void wxWindowX11::Lower()
289 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
292 void wxWindowX11::DoCaptureMouse()
294 g_captureWindow
= (wxWindow
*) this;
300 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
302 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
306 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
309 if (res
!= GrabSuccess
)
311 wxLogDebug("Failed to grab pointer.");
315 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
316 (Window
) GetMainWindow(),
318 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
324 if (res
!= GrabSuccess
)
326 wxLogDebug("Failed to grab mouse buttons.");
327 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
331 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
333 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
341 if (res
!= GrabSuccess
)
343 wxLogDebug("Failed to grab keyboard.");
344 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
345 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
346 (Window
) GetMainWindow());
350 m_winCaptured
= TRUE
;
354 void wxWindowX11::DoReleaseMouse()
356 g_captureWindow
= NULL
;
357 if ( !m_winCaptured
)
360 Window wMain
= (Window
)GetMainWindow();
364 XUngrabPointer(wxGlobalDisplay(), wMain
);
365 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
367 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
370 m_winCaptured
= FALSE
;
373 bool wxWindowX11::SetFont(const wxFont
& font
)
375 if ( !wxWindowBase::SetFont(font
) )
384 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
386 if ( !wxWindowBase::SetCursor(cursor
) )
392 wxCursor
* cursor2
= NULL
;
394 cursor2
= & m_cursor
;
396 cursor2
= wxSTANDARD_CURSOR
;
398 WXDisplay
*dpy
= GetXDisplay();
399 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
401 Window win
= (Window
) GetMainWindow();
402 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
407 // Coordinates relative to the window
408 void wxWindowX11::WarpPointer (int x
, int y
)
411 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
414 // Does a physical scroll
415 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
421 // Use specified rectangle
422 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
426 // Use whole client area
428 GetClientSize(& w
, & h
);
431 wxNode
*cnode
= m_children
.First();
434 wxWindow
*child
= (wxWindow
*) cnode
->Data();
437 child
->GetSize( &sx
, &sy
);
438 wxPoint
pos( child
->GetPosition() );
439 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
440 cnode
= cnode
->Next();
443 int x1
= (dx
>= 0) ? x
: x
- dx
;
444 int y1
= (dy
>= 0) ? y
: y
- dy
;
445 int w1
= w
- abs(dx
);
446 int h1
= h
- abs(dy
);
447 int x2
= (dx
>= 0) ? x
+ dx
: x
;
448 int y2
= (dy
>= 0) ? y
+ dy
: y
;
450 wxClientDC
dc((wxWindow
*) this);
452 dc
.SetLogicalFunction (wxCOPY
);
454 Window window
= (Window
) GetMainWindow();
455 Display
* display
= wxGlobalDisplay();
457 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
458 x1
, y1
, w1
, h1
, x2
, y2
);
460 dc
.SetAutoSetting(TRUE
);
461 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
462 dc
.SetBrush(brush
); // FIXME: needed?
464 // We'll add rectangles to the list of update rectangles according to which
465 // bits we've exposed.
470 wxRect
*rect
= new wxRect
;
476 XFillRectangle(display
, window
,
477 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
481 rect
->width
= rect
->width
;
482 rect
->height
= rect
->height
;
484 updateRects
.Append((wxObject
*) rect
);
488 wxRect
*rect
= new wxRect
;
490 rect
->x
= x
+ w
+ dx
;
495 XFillRectangle(display
, window
,
496 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
501 rect
->width
= rect
->width
;
502 rect
->height
= rect
->height
;
504 updateRects
.Append((wxObject
*) rect
);
508 wxRect
*rect
= new wxRect
;
515 XFillRectangle(display
, window
,
516 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
520 rect
->width
= rect
->width
;
521 rect
->height
= rect
->height
;
523 updateRects
.Append((wxObject
*) rect
);
527 wxRect
*rect
= new wxRect
;
530 rect
->y
= y
+ h
+ dy
;
534 XFillRectangle(display
, window
,
535 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
539 rect
->width
= rect
->width
;
540 rect
->height
= rect
->height
;
542 updateRects
.Append((wxObject
*) rect
);
544 dc
.SetBrush(wxNullBrush
);
546 // Now send expose events
548 wxNode
* node
= updateRects
.First();
551 wxRect
* rect
= (wxRect
*) node
->Data();
555 event
.display
= display
;
556 event
.send_event
= True
;
557 event
.window
= window
;
561 event
.width
= rect
->width
;
562 event
.height
= rect
->height
;
566 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
572 // Delete the update rects
573 node
= updateRects
.First();
576 wxRect
* rect
= (wxRect
*) node
->Data();
583 // ---------------------------------------------------------------------------
585 // ---------------------------------------------------------------------------
587 #if wxUSE_DRAG_AND_DROP
589 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
596 // Old style file-manager drag&drop
597 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
602 // ----------------------------------------------------------------------------
604 // ----------------------------------------------------------------------------
608 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
613 #endif // wxUSE_TOOLTIPS
615 // ---------------------------------------------------------------------------
616 // moving and resizing
617 // ---------------------------------------------------------------------------
619 bool wxWindowX11::PreResize()
625 void wxWindowX11::DoGetSize(int *x
, int *y
) const
627 Window window
= (Window
) m_mainWidget
;
630 XWindowAttributes attr
;
631 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
636 *x
= attr
.width
/* + 2*m_borderSize */ ;
637 *y
= attr
.height
/* + 2*m_borderSize */ ;
642 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
644 Window window
= (Window
) m_mainWidget
;
647 XWindowAttributes attr
;
648 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
656 // We may be faking the client origin. So a window that's really at (0, 30)
657 // may appear (to wxWin apps) to be at (0, 0).
660 wxPoint
pt(GetParent()->GetClientAreaOrigin());
668 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
670 Display
*display
= wxGlobalDisplay();
671 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
672 Window thisWindow
= (Window
) m_mainWidget
;
677 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
680 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
682 Display
*display
= wxGlobalDisplay();
683 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
684 Window thisWindow
= (Window
) m_mainWidget
;
689 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
693 // Get size *available for subwindows* i.e. excluding menu bar etc.
694 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
696 Window window
= (Window
) m_mainWidget
;
700 XWindowAttributes attr
;
701 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
712 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
714 if (!GetMainWindow())
717 XWindowChanges windowChanges
;
720 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
725 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
730 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
732 windowChanges
.width
= width
/* - m_borderSize*2 */;
733 valueMask
|= CWWidth
;
735 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
737 windowChanges
.height
= height
/* -m_borderSize*2*/;
738 valueMask
|= CWHeight
;
740 AdjustForParentClientOrigin( x
, y
, sizeFlags
);
742 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
743 valueMask
, & windowChanges
);
746 void wxWindowX11::DoSetClientSize(int width
, int height
)
748 if (!GetMainWindow())
751 XWindowChanges windowChanges
;
756 windowChanges
.width
= width
;
757 valueMask
|= CWWidth
;
761 windowChanges
.height
= height
;
762 valueMask
|= CWHeight
;
764 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
765 valueMask
, & windowChanges
);
768 // For implementation purposes - sometimes decorations make the client area
770 wxPoint
wxWindowX11::GetClientAreaOrigin() const
772 return wxPoint(0, 0);
775 // Makes an adjustment to the window position (for example, a frame that has
776 // a toolbar that it manages itself).
777 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
779 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
781 wxPoint
pt(GetParent()->GetClientAreaOrigin());
782 x
+= pt
.x
; y
+= pt
.y
;
786 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
793 XSizeHints sizeHints
;
796 if (minW
> -1 && minH
> -1)
798 sizeHints
.flags
|= PMinSize
;
799 sizeHints
.min_width
= minW
;
800 sizeHints
.min_height
= minH
;
802 if (maxW
> -1 && maxH
> -1)
804 sizeHints
.flags
|= PMaxSize
;
805 sizeHints
.max_width
= maxW
;
806 sizeHints
.max_height
= maxH
;
808 if (incW
> -1 && incH
> -1)
810 sizeHints
.flags
|= PResizeInc
;
811 sizeHints
.width_inc
= incW
;
812 sizeHints
.height_inc
= incH
;
815 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
818 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
820 DoSetSize(x
, y
, width
, height
);
823 // ---------------------------------------------------------------------------
825 // ---------------------------------------------------------------------------
827 int wxWindowX11::GetCharHeight() const
829 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
831 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
833 int direction
, ascent
, descent
;
835 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
838 // return (overall.ascent + overall.descent);
839 return (ascent
+ descent
);
842 int wxWindowX11::GetCharWidth() const
844 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
846 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
848 int direction
, ascent
, descent
;
850 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
853 return overall
.width
;
856 void wxWindowX11::GetTextExtent(const wxString
& string
,
858 int *descent
, int *externalLeading
,
859 const wxFont
*theFont
) const
861 wxFont
*fontToUse
= (wxFont
*)theFont
;
863 fontToUse
= (wxFont
*) & m_font
;
865 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
867 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
869 int direction
, ascent
, descent2
;
871 int slen
= string
.Len();
875 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
876 &ascent
, &descent2
, &overall
);
879 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
880 &direction
, &ascent
, &descent2
, &overall
);
883 *x
= (overall
.width
);
885 *y
= (ascent
+ descent2
);
889 *externalLeading
= 0;
893 // ----------------------------------------------------------------------------
895 // ----------------------------------------------------------------------------
897 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
903 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
904 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
909 GetSize( &width
, &height
);
911 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
912 m_clearRegion
.Clear();
913 m_clearRegion
.Union( 0, 0, width
, height
);
919 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
920 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
925 GetSize( &width
, &height
);
927 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
928 m_updateRegion
.Clear();
929 m_updateRegion
.Union( 0, 0, width
, height
);
932 // Actually don't schedule yet..
936 void wxWindowX11::Update()
938 if (!m_updateRegion
.IsEmpty())
940 X11SendPaintEvents();
944 void wxWindowX11::Clear()
946 wxClientDC
dc((wxWindow
*) this);
947 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
948 dc
.SetBackground(brush
);
952 void wxWindowX11::X11SendPaintEvents()
954 m_clipPaintRegion
= TRUE
;
956 if (!m_clearRegion
.IsEmpty())
958 wxWindowDC
dc( (wxWindow
*)this );
959 dc
.SetClippingRegion( m_clearRegion
);
961 wxEraseEvent
erase_event( GetId(), &dc
);
962 erase_event
.SetEventObject( this );
964 if (!GetEventHandler()->ProcessEvent(erase_event
))
966 wxRegionIterator
upd( m_clearRegion
);
969 // XClearArea( ... , upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
973 m_clearRegion
.Clear();
976 // wxNcPaintEvent nc_paint_event( GetId() );
977 // nc_paint_event.SetEventObject( this );
978 // GetEventHandler()->ProcessEvent( nc_paint_event );
980 wxPaintEvent
paint_event( GetId() );
981 paint_event
.SetEventObject( this );
982 GetEventHandler()->ProcessEvent( paint_event
);
984 m_clipPaintRegion
= FALSE
;
987 // ----------------------------------------------------------------------------
989 // ----------------------------------------------------------------------------
991 // Responds to colour changes: passes event on to children.
992 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
994 wxWindowList::Node
*node
= GetChildren().GetFirst();
997 // Only propagate to non-top-level windows
998 wxWindow
*win
= node
->GetData();
999 if ( win
->GetParent() )
1001 wxSysColourChangedEvent event2
;
1002 event
.m_eventObject
= win
;
1003 win
->GetEventHandler()->ProcessEvent(event2
);
1006 node
= node
->GetNext();
1010 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1012 // This calls the UI-update mechanism (querying windows for
1013 // menu/toolbar/control state information)
1017 // ----------------------------------------------------------------------------
1018 // function which maintain the global hash table mapping Widgets to wxWindows
1019 // ----------------------------------------------------------------------------
1021 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1023 wxWindow
*oldItem
= NULL
;
1024 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1026 wxLogDebug("Widget table clash: new widget is %ld, %s",
1027 (long)w
, win
->GetClassInfo()->GetClassName());
1031 wxWidgetHashTable
->Put((long) w
, win
);
1033 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1034 w
, win
, win
->GetClassInfo()->GetClassName());
1039 wxWindow
*wxGetWindowFromTable(Window w
)
1041 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1044 void wxDeleteWindowFromTable(Window w
)
1046 wxWidgetHashTable
->Delete((long)w
);
1049 // ----------------------------------------------------------------------------
1050 // add/remove window from the table
1051 // ----------------------------------------------------------------------------
1053 // ----------------------------------------------------------------------------
1054 // X11-specific accessors
1055 // ----------------------------------------------------------------------------
1057 // Get the underlying X window
1058 WXWindow
wxWindowX11::GetXWindow() const
1060 return GetMainWindow();
1063 // Get the underlying X display
1064 WXDisplay
*wxWindowX11::GetXDisplay() const
1066 return wxGetDisplay();
1069 WXWindow
wxWindowX11::GetMainWindow() const
1071 return m_mainWidget
;
1074 // ----------------------------------------------------------------------------
1075 // TranslateXXXEvent() functions
1076 // ----------------------------------------------------------------------------
1078 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1080 switch (xevent
->xany
.type
)
1088 wxEventType eventType
= wxEVT_NULL
;
1090 if (xevent
->xany
.type
== EnterNotify
)
1092 //if (local_event.xcrossing.mode!=NotifyNormal)
1093 // return ; // Ignore grab events
1094 eventType
= wxEVT_ENTER_WINDOW
;
1095 // canvas->GetEventHandler()->OnSetFocus();
1097 else if (xevent
->xany
.type
== LeaveNotify
)
1099 //if (local_event.xcrossingr.mode!=NotifyNormal)
1100 // return ; // Ignore grab events
1101 eventType
= wxEVT_LEAVE_WINDOW
;
1102 // canvas->GetEventHandler()->OnKillFocus();
1104 else if (xevent
->xany
.type
== MotionNotify
)
1106 eventType
= wxEVT_MOTION
;
1108 else if (xevent
->xany
.type
== ButtonPress
)
1110 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1112 if (xevent
->xbutton
.button
== Button1
)
1114 eventType
= wxEVT_LEFT_DOWN
;
1117 else if (xevent
->xbutton
.button
== Button2
)
1119 eventType
= wxEVT_MIDDLE_DOWN
;
1122 else if (xevent
->xbutton
.button
== Button3
)
1124 eventType
= wxEVT_RIGHT_DOWN
;
1128 // check for a double click
1129 // TODO: where can we get this value from?
1130 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1131 long dclickTime
= 200;
1132 long ts
= wxevent
.GetTimestamp();
1134 int buttonLast
= win
->GetLastClickedButton();
1135 long lastTS
= win
->GetLastClickTime();
1136 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1139 win
->SetLastClick(0, ts
);
1140 if ( eventType
== wxEVT_LEFT_DOWN
)
1141 eventType
= wxEVT_LEFT_DCLICK
;
1142 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1143 eventType
= wxEVT_MIDDLE_DCLICK
;
1144 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1145 eventType
= wxEVT_RIGHT_DCLICK
;
1149 // not fast enough or different button
1150 win
->SetLastClick(button
, ts
);
1153 else if (xevent
->xany
.type
== ButtonRelease
)
1155 if (xevent
->xbutton
.button
== Button1
)
1157 eventType
= wxEVT_LEFT_UP
;
1159 else if (xevent
->xbutton
.button
== Button2
)
1161 eventType
= wxEVT_MIDDLE_UP
;
1163 else if (xevent
->xbutton
.button
== Button3
)
1165 eventType
= wxEVT_RIGHT_UP
;
1174 wxevent
.SetEventType(eventType
);
1176 wxevent
.m_x
= xevent
->xbutton
.x
;
1177 wxevent
.m_y
= xevent
->xbutton
.y
;
1179 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1180 || (event_left_is_down (xevent
)
1181 && (eventType
!= wxEVT_LEFT_UP
)));
1182 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1183 || (event_middle_is_down (xevent
)
1184 && (eventType
!= wxEVT_MIDDLE_UP
)));
1185 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1186 || (event_right_is_down (xevent
)
1187 && (eventType
!= wxEVT_RIGHT_UP
)));
1189 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1190 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1191 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1192 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1194 wxevent
.SetId(win
->GetId());
1195 wxevent
.SetEventObject(win
);
1203 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1205 switch (xevent
->xany
.type
)
1213 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1214 int id
= wxCharCodeXToWX (keySym
);
1216 if (xevent
->xkey
.state
& ShiftMask
)
1217 wxevent
.m_shiftDown
= TRUE
;
1218 if (xevent
->xkey
.state
& ControlMask
)
1219 wxevent
.m_controlDown
= TRUE
;
1220 if (xevent
->xkey
.state
& Mod3Mask
)
1221 wxevent
.m_altDown
= TRUE
;
1222 if (xevent
->xkey
.state
& Mod1Mask
)
1223 wxevent
.m_metaDown
= TRUE
;
1224 wxevent
.SetEventObject(win
);
1225 wxevent
.m_keyCode
= id
;
1226 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1228 wxevent
.m_x
= xevent
->xbutton
.x
;
1229 wxevent
.m_y
= xevent
->xbutton
.y
;
1243 // ----------------------------------------------------------------------------
1245 // ----------------------------------------------------------------------------
1249 #define YAllocColor XAllocColor
1250 XColor g_itemColors
[5];
1251 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1254 static XmColorProc colorProc
;
1256 result
= wxNO_COLORS
;
1260 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1261 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1262 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1263 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1264 if (colorProc
== (XmColorProc
) NULL
)
1266 // Get a ptr to the actual function
1267 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1268 // And set it back to motif.
1269 XmSetColorCalculation (colorProc
);
1271 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1272 &g_itemColors
[wxFORE_INDEX
],
1273 &g_itemColors
[wxSELE_INDEX
],
1274 &g_itemColors
[wxTOPS_INDEX
],
1275 &g_itemColors
[wxBOTS_INDEX
]);
1276 result
= wxBACK_COLORS
;
1280 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1281 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1282 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1283 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1284 if (result
== wxNO_COLORS
)
1285 result
= wxFORE_COLORS
;
1288 Display
*dpy
= display
;
1289 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1293 /* 5 Colours to allocate */
1294 for (int i
= 0; i
< 5; i
++)
1295 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1296 result
= wxNO_COLORS
;
1300 /* Only 1 colour to allocate */
1301 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1302 result
= wxNO_COLORS
;
1310 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1312 if ( !wxWindowBase::SetBackgroundColour(col
) )
1315 if (!GetMainWindow())
1318 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1319 int xscreen
= DefaultScreen( xdisplay
);
1320 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1322 wxColour
colour( col
);
1323 colour
.CalcPixel( (WXColormap
) cm
);
1325 XSetWindowAttributes attrib
;
1326 attrib
.background_pixel
= colour
.GetPixel();
1328 XChangeWindowAttributes(wxGlobalDisplay(),
1329 (Window
) GetMainWindow(),
1336 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1338 if ( !wxWindowBase::SetForegroundColour(col
) )
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1348 wxWindow
*wxGetActiveWindow()
1351 wxFAIL_MSG("Not implemented");
1356 wxWindow
*wxWindowBase::GetCapture()
1358 return (wxWindow
*)g_captureWindow
;
1362 // Find the wxWindow at the current mouse position, returning the mouse
1364 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1366 return wxFindWindowAtPoint(wxGetMousePosition());
1369 // Get the current mouse position.
1370 wxPoint
wxGetMousePosition()
1372 Display
*display
= wxGlobalDisplay();
1373 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1374 Window rootReturn
, childReturn
;
1375 int rootX
, rootY
, winX
, winY
;
1376 unsigned int maskReturn
;
1378 XQueryPointer (display
,
1382 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1383 return wxPoint(rootX
, rootY
);
1387 // ----------------------------------------------------------------------------
1388 // wxNoOptimize: switch off size optimization
1389 // ----------------------------------------------------------------------------
1391 int wxNoOptimize::ms_count
= 0;