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( wxGlobalDisplay(), (Window
) m_mainWidget
,
970 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
974 m_clearRegion
.Clear();
977 wxNcPaintEvent
nc_paint_event( GetId() );
978 nc_paint_event
.SetEventObject( this );
979 GetEventHandler()->ProcessEvent( nc_paint_event
);
981 wxPaintEvent
paint_event( GetId() );
982 paint_event
.SetEventObject( this );
983 GetEventHandler()->ProcessEvent( paint_event
);
985 m_clipPaintRegion
= FALSE
;
988 // ----------------------------------------------------------------------------
990 // ----------------------------------------------------------------------------
992 // Responds to colour changes: passes event on to children.
993 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
995 wxWindowList::Node
*node
= GetChildren().GetFirst();
998 // Only propagate to non-top-level windows
999 wxWindow
*win
= node
->GetData();
1000 if ( win
->GetParent() )
1002 wxSysColourChangedEvent event2
;
1003 event
.m_eventObject
= win
;
1004 win
->GetEventHandler()->ProcessEvent(event2
);
1007 node
= node
->GetNext();
1011 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1013 // This calls the UI-update mechanism (querying windows for
1014 // menu/toolbar/control state information)
1018 // ----------------------------------------------------------------------------
1019 // function which maintain the global hash table mapping Widgets to wxWindows
1020 // ----------------------------------------------------------------------------
1022 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1024 wxWindow
*oldItem
= NULL
;
1025 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1027 wxLogDebug("Widget table clash: new widget is %ld, %s",
1028 (long)w
, win
->GetClassInfo()->GetClassName());
1032 wxWidgetHashTable
->Put((long) w
, win
);
1034 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1035 w
, win
, win
->GetClassInfo()->GetClassName());
1040 wxWindow
*wxGetWindowFromTable(Window w
)
1042 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1045 void wxDeleteWindowFromTable(Window w
)
1047 wxWidgetHashTable
->Delete((long)w
);
1050 // ----------------------------------------------------------------------------
1051 // add/remove window from the table
1052 // ----------------------------------------------------------------------------
1054 // ----------------------------------------------------------------------------
1055 // X11-specific accessors
1056 // ----------------------------------------------------------------------------
1058 // Get the underlying X window
1059 WXWindow
wxWindowX11::GetXWindow() const
1061 return GetMainWindow();
1064 // Get the underlying X display
1065 WXDisplay
*wxWindowX11::GetXDisplay() const
1067 return wxGetDisplay();
1070 WXWindow
wxWindowX11::GetMainWindow() const
1072 return m_mainWidget
;
1075 // ----------------------------------------------------------------------------
1076 // TranslateXXXEvent() functions
1077 // ----------------------------------------------------------------------------
1079 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1081 switch (xevent
->xany
.type
)
1089 wxEventType eventType
= wxEVT_NULL
;
1091 if (xevent
->xany
.type
== EnterNotify
)
1093 //if (local_event.xcrossing.mode!=NotifyNormal)
1094 // return ; // Ignore grab events
1095 eventType
= wxEVT_ENTER_WINDOW
;
1096 // canvas->GetEventHandler()->OnSetFocus();
1098 else if (xevent
->xany
.type
== LeaveNotify
)
1100 //if (local_event.xcrossingr.mode!=NotifyNormal)
1101 // return ; // Ignore grab events
1102 eventType
= wxEVT_LEAVE_WINDOW
;
1103 // canvas->GetEventHandler()->OnKillFocus();
1105 else if (xevent
->xany
.type
== MotionNotify
)
1107 eventType
= wxEVT_MOTION
;
1109 else if (xevent
->xany
.type
== ButtonPress
)
1111 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1113 if (xevent
->xbutton
.button
== Button1
)
1115 eventType
= wxEVT_LEFT_DOWN
;
1118 else if (xevent
->xbutton
.button
== Button2
)
1120 eventType
= wxEVT_MIDDLE_DOWN
;
1123 else if (xevent
->xbutton
.button
== Button3
)
1125 eventType
= wxEVT_RIGHT_DOWN
;
1129 // check for a double click
1130 // TODO: where can we get this value from?
1131 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1132 long dclickTime
= 200;
1133 long ts
= wxevent
.GetTimestamp();
1135 int buttonLast
= win
->GetLastClickedButton();
1136 long lastTS
= win
->GetLastClickTime();
1137 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1140 win
->SetLastClick(0, ts
);
1141 if ( eventType
== wxEVT_LEFT_DOWN
)
1142 eventType
= wxEVT_LEFT_DCLICK
;
1143 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1144 eventType
= wxEVT_MIDDLE_DCLICK
;
1145 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1146 eventType
= wxEVT_RIGHT_DCLICK
;
1150 // not fast enough or different button
1151 win
->SetLastClick(button
, ts
);
1154 else if (xevent
->xany
.type
== ButtonRelease
)
1156 if (xevent
->xbutton
.button
== Button1
)
1158 eventType
= wxEVT_LEFT_UP
;
1160 else if (xevent
->xbutton
.button
== Button2
)
1162 eventType
= wxEVT_MIDDLE_UP
;
1164 else if (xevent
->xbutton
.button
== Button3
)
1166 eventType
= wxEVT_RIGHT_UP
;
1175 wxevent
.SetEventType(eventType
);
1177 wxevent
.m_x
= xevent
->xbutton
.x
;
1178 wxevent
.m_y
= xevent
->xbutton
.y
;
1180 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1181 || (event_left_is_down (xevent
)
1182 && (eventType
!= wxEVT_LEFT_UP
)));
1183 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1184 || (event_middle_is_down (xevent
)
1185 && (eventType
!= wxEVT_MIDDLE_UP
)));
1186 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1187 || (event_right_is_down (xevent
)
1188 && (eventType
!= wxEVT_RIGHT_UP
)));
1190 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1191 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1192 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1193 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1195 wxevent
.SetId(win
->GetId());
1196 wxevent
.SetEventObject(win
);
1204 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1206 switch (xevent
->xany
.type
)
1214 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1215 int id
= wxCharCodeXToWX (keySym
);
1217 if (xevent
->xkey
.state
& ShiftMask
)
1218 wxevent
.m_shiftDown
= TRUE
;
1219 if (xevent
->xkey
.state
& ControlMask
)
1220 wxevent
.m_controlDown
= TRUE
;
1221 if (xevent
->xkey
.state
& Mod3Mask
)
1222 wxevent
.m_altDown
= TRUE
;
1223 if (xevent
->xkey
.state
& Mod1Mask
)
1224 wxevent
.m_metaDown
= TRUE
;
1225 wxevent
.SetEventObject(win
);
1226 wxevent
.m_keyCode
= id
;
1227 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1229 wxevent
.m_x
= xevent
->xbutton
.x
;
1230 wxevent
.m_y
= xevent
->xbutton
.y
;
1244 // ----------------------------------------------------------------------------
1246 // ----------------------------------------------------------------------------
1250 #define YAllocColor XAllocColor
1251 XColor g_itemColors
[5];
1252 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1255 static XmColorProc colorProc
;
1257 result
= wxNO_COLORS
;
1261 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1262 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1263 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1264 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1265 if (colorProc
== (XmColorProc
) NULL
)
1267 // Get a ptr to the actual function
1268 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1269 // And set it back to motif.
1270 XmSetColorCalculation (colorProc
);
1272 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1273 &g_itemColors
[wxFORE_INDEX
],
1274 &g_itemColors
[wxSELE_INDEX
],
1275 &g_itemColors
[wxTOPS_INDEX
],
1276 &g_itemColors
[wxBOTS_INDEX
]);
1277 result
= wxBACK_COLORS
;
1281 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1282 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1283 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1284 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1285 if (result
== wxNO_COLORS
)
1286 result
= wxFORE_COLORS
;
1289 Display
*dpy
= display
;
1290 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1294 /* 5 Colours to allocate */
1295 for (int i
= 0; i
< 5; i
++)
1296 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1297 result
= wxNO_COLORS
;
1301 /* Only 1 colour to allocate */
1302 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1303 result
= wxNO_COLORS
;
1311 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1313 if ( !wxWindowBase::SetBackgroundColour(col
) )
1316 if (!GetMainWindow())
1319 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1320 int xscreen
= DefaultScreen( xdisplay
);
1321 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1323 wxColour
colour( col
);
1324 colour
.CalcPixel( (WXColormap
) cm
);
1326 XSetWindowAttributes attrib
;
1327 attrib
.background_pixel
= colour
.GetPixel();
1329 XChangeWindowAttributes(wxGlobalDisplay(),
1330 (Window
) GetMainWindow(),
1337 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1339 if ( !wxWindowBase::SetForegroundColour(col
) )
1345 // ----------------------------------------------------------------------------
1347 // ----------------------------------------------------------------------------
1349 wxWindow
*wxGetActiveWindow()
1352 wxFAIL_MSG("Not implemented");
1357 wxWindow
*wxWindowBase::GetCapture()
1359 return (wxWindow
*)g_captureWindow
;
1363 // Find the wxWindow at the current mouse position, returning the mouse
1365 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1367 return wxFindWindowAtPoint(wxGetMousePosition());
1370 // Get the current mouse position.
1371 wxPoint
wxGetMousePosition()
1373 Display
*display
= wxGlobalDisplay();
1374 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1375 Window rootReturn
, childReturn
;
1376 int rootX
, rootY
, winX
, winY
;
1377 unsigned int maskReturn
;
1379 XQueryPointer (display
,
1383 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1384 return wxPoint(rootX
, rootY
);
1388 // ----------------------------------------------------------------------------
1389 // wxNoOptimize: switch off size optimization
1390 // ----------------------------------------------------------------------------
1392 int wxNoOptimize::ms_count
= 0;