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 // ----------------------------------------------------------------------------
53 // global variables for this module
54 // ----------------------------------------------------------------------------
56 extern wxHashTable
*wxWidgetHashTable
;
57 static wxWindow
* g_captureWindow
= NULL
;
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
73 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 void wxWindowX11::Init()
91 // generic initializations first
95 m_mainWidget
= (WXWindow
) 0;
97 m_winCaptured
= FALSE
;
100 m_isBeingDeleted
= FALSE
;
106 // real construction (Init() must have been called before!)
107 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
111 const wxString
& name
)
113 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
115 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
117 parent
->AddChild(this);
119 int w
= size
.GetWidth();
120 int h
= size
.GetHeight();
128 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
129 int xscreen
= DefaultScreen( xdisplay
);
130 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
132 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
133 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
136 m_foregroundColour
= *wxBLACK
;
137 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
140 Window parentWindow
= (Window
) parent
->GetMainWindow();
142 Window window
= XCreateSimpleWindow(
143 xdisplay
, parentWindow
,
145 m_backgroundColour
.GetPixel(),
146 m_backgroundColour
.GetPixel() );
148 m_mainWidget
= (WXWindow
) window
;
150 // Select event types wanted
151 XSelectInput(wxGlobalDisplay(), window
,
152 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
153 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
154 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
157 wxAddWindowToTable(window
, (wxWindow
*) this);
159 // Is a subwindow, so map immediately
161 XMapWindow(wxGlobalDisplay(), window
);
163 // Without this, the cursor may not be restored properly (e.g. in splitter
165 SetCursor(*wxSTANDARD_CURSOR
);
166 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
167 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
173 wxWindowX11::~wxWindowX11()
175 if (g_captureWindow
== this)
176 g_captureWindow
= NULL
;
178 m_isBeingDeleted
= TRUE
;
180 // X11-specific actions first
181 Window main
= (Window
) m_mainWidget
;
184 // Removes event handlers
185 //DetachWidget(main);
189 m_parent
->RemoveChild( this );
193 // Destroy the window
196 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
197 wxDeleteWindowFromTable( main
);
198 XDestroyWindow( wxGlobalDisplay(), main
);
203 // ---------------------------------------------------------------------------
205 // ---------------------------------------------------------------------------
207 void wxWindowX11::SetFocus()
209 Window wMain
= (Window
) GetMainWindow();
212 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
215 wmhints
.flags
= InputHint
;
216 wmhints
.input
= True
;
217 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
221 // Get the window with the focus
222 wxWindow
*wxWindowBase::FindFocus()
224 Window wFocus
= (Window
) 0;
227 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
230 wxWindow
*win
= NULL
;
233 win
= wxGetWindowFromTable(wFocus
);
234 wFocus
= wxGetWindowParent(wFocus
);
235 } while (wFocus
&& !win
);
243 // Enabling/disabling handled by event loop, and not sending events
245 bool wxWindowX11::Enable(bool enable
)
247 if ( !wxWindowBase::Enable(enable
) )
253 bool wxWindowX11::Show(bool show
)
255 wxWindowBase::Show(show
);
257 Window xwin
= (Window
) GetXWindow();
258 Display
*xdisp
= (Display
*) GetXDisplay();
262 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
264 XMapWindow(xdisp
, xwin
);
270 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
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 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
296 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
307 g_captureWindow
= (wxWindow
*) this;
311 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
313 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
317 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
320 if (res
!= GrabSuccess
)
323 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
325 if (res
== GrabNotViewable
)
327 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
329 g_captureWindow
= NULL
;
332 wxLogDebug("Grabbed pointer");
335 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
336 (Window
) GetMainWindow(),
338 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
344 if (res
!= GrabSuccess
)
346 wxLogDebug("Failed to grab mouse buttons.");
347 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
353 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
355 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
363 if (res
!= GrabSuccess
)
365 wxLogDebug("Failed to grab keyboard.");
366 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
368 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
369 (Window
) GetMainWindow());
375 m_winCaptured
= TRUE
;
379 void wxWindowX11::DoReleaseMouse()
381 g_captureWindow
= NULL
;
382 if ( !m_winCaptured
)
385 Window wMain
= (Window
)GetMainWindow();
389 XUngrabPointer(wxGlobalDisplay(), wMain
);
391 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
393 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
396 wxLogDebug("Ungrabbed pointer");
398 m_winCaptured
= FALSE
;
401 bool wxWindowX11::SetFont(const wxFont
& font
)
403 if ( !wxWindowBase::SetFont(font
) )
412 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
414 if ( !wxWindowBase::SetCursor(cursor
) )
420 wxCursor
* cursor2
= NULL
;
422 cursor2
= & m_cursor
;
424 cursor2
= wxSTANDARD_CURSOR
;
426 WXCursor x_cursor
= cursor2
->GetCursor();
428 Window win
= (Window
) GetMainWindow();
429 XDefineCursor((Display
*) wxGlobalDisplay(), win
, (Cursor
) x_cursor
);
434 // Coordinates relative to the window
435 void wxWindowX11::WarpPointer (int x
, int y
)
438 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
441 // Does a physical scroll
442 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
448 // Use specified rectangle
449 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
453 // Use whole client area
455 GetClientSize(& w
, & h
);
458 wxNode
*cnode
= m_children
.First();
461 wxWindow
*child
= (wxWindow
*) cnode
->Data();
464 child
->GetSize( &sx
, &sy
);
465 wxPoint
pos( child
->GetPosition() );
466 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
467 cnode
= cnode
->Next();
470 int x1
= (dx
>= 0) ? x
: x
- dx
;
471 int y1
= (dy
>= 0) ? y
: y
- dy
;
472 int w1
= w
- abs(dx
);
473 int h1
= h
- abs(dy
);
474 int x2
= (dx
>= 0) ? x
+ dx
: x
;
475 int y2
= (dy
>= 0) ? y
+ dy
: y
;
477 wxClientDC
dc((wxWindow
*) this);
479 dc
.SetLogicalFunction (wxCOPY
);
481 Window window
= (Window
) GetMainWindow();
482 Display
* display
= wxGlobalDisplay();
484 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
485 x1
, y1
, w1
, h1
, x2
, y2
);
487 dc
.SetAutoSetting(TRUE
);
488 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
489 dc
.SetBrush(brush
); // FIXME: needed?
491 // We'll add rectangles to the list of update rectangles according to which
492 // bits we've exposed.
497 wxRect
*rect
= new wxRect
;
503 XFillRectangle(display
, window
,
504 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
508 rect
->width
= rect
->width
;
509 rect
->height
= rect
->height
;
511 updateRects
.Append((wxObject
*) rect
);
515 wxRect
*rect
= new wxRect
;
517 rect
->x
= x
+ w
+ dx
;
522 XFillRectangle(display
, window
,
523 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
528 rect
->width
= rect
->width
;
529 rect
->height
= rect
->height
;
531 updateRects
.Append((wxObject
*) rect
);
535 wxRect
*rect
= new wxRect
;
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
);
554 wxRect
*rect
= new wxRect
;
557 rect
->y
= y
+ h
+ dy
;
561 XFillRectangle(display
, window
,
562 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
566 rect
->width
= rect
->width
;
567 rect
->height
= rect
->height
;
569 updateRects
.Append((wxObject
*) rect
);
571 dc
.SetBrush(wxNullBrush
);
573 // Now send expose events
575 wxNode
* node
= updateRects
.First();
578 wxRect
* rect
= (wxRect
*) node
->Data();
582 event
.display
= display
;
583 event
.send_event
= True
;
584 event
.window
= window
;
588 event
.width
= rect
->width
;
589 event
.height
= rect
->height
;
593 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
599 // Delete the update rects
600 node
= updateRects
.First();
603 wxRect
* rect
= (wxRect
*) node
->Data();
610 // ---------------------------------------------------------------------------
612 // ---------------------------------------------------------------------------
614 #if wxUSE_DRAG_AND_DROP
616 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
623 // Old style file-manager drag&drop
624 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
629 // ----------------------------------------------------------------------------
631 // ----------------------------------------------------------------------------
635 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
640 #endif // wxUSE_TOOLTIPS
642 // ---------------------------------------------------------------------------
643 // moving and resizing
644 // ---------------------------------------------------------------------------
646 bool wxWindowX11::PreResize()
652 void wxWindowX11::DoGetSize(int *x
, int *y
) const
654 Window window
= (Window
) m_mainWidget
;
657 XWindowAttributes attr
;
658 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
663 *x
= attr
.width
/* + 2*m_borderSize */ ;
664 *y
= attr
.height
/* + 2*m_borderSize */ ;
669 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
671 Window window
= (Window
) m_mainWidget
;
674 XWindowAttributes attr
;
675 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
683 // We may be faking the client origin. So a window that's really at (0, 30)
684 // may appear (to wxWin apps) to be at (0, 0).
687 wxPoint
pt(GetParent()->GetClientAreaOrigin());
695 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
697 Display
*display
= wxGlobalDisplay();
698 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
699 Window thisWindow
= (Window
) m_mainWidget
;
704 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
707 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
709 Display
*display
= wxGlobalDisplay();
710 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
711 Window thisWindow
= (Window
) m_mainWidget
;
716 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
720 // Get size *available for subwindows* i.e. excluding menu bar etc.
721 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
723 Window window
= (Window
) m_mainWidget
;
727 XWindowAttributes attr
;
728 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
739 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
741 if (!GetMainWindow())
744 XWindowChanges windowChanges
;
747 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
750 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
754 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
757 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
761 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
763 windowChanges
.width
= width
/* - m_borderSize*2 */;
764 valueMask
|= CWWidth
;
766 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
768 windowChanges
.height
= height
/* -m_borderSize*2*/;
769 valueMask
|= CWHeight
;
772 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
773 valueMask
, & windowChanges
);
776 void wxWindowX11::DoSetClientSize(int width
, int height
)
778 if (!GetMainWindow())
781 XWindowChanges windowChanges
;
786 windowChanges
.width
= width
;
787 valueMask
|= CWWidth
;
791 windowChanges
.height
= height
;
792 valueMask
|= CWHeight
;
794 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
795 valueMask
, & windowChanges
);
798 // For implementation purposes - sometimes decorations make the client area
800 wxPoint
wxWindowX11::GetClientAreaOrigin() const
802 return wxPoint(0, 0);
805 // Makes an adjustment to the window position (for example, a frame that has
806 // a toolbar that it manages itself).
807 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
809 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
811 wxPoint
pt(GetParent()->GetClientAreaOrigin());
812 x
+= pt
.x
; y
+= pt
.y
;
816 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
823 XSizeHints sizeHints
;
826 if (minW
> -1 && minH
> -1)
828 sizeHints
.flags
|= PMinSize
;
829 sizeHints
.min_width
= minW
;
830 sizeHints
.min_height
= minH
;
832 if (maxW
> -1 && maxH
> -1)
834 sizeHints
.flags
|= PMaxSize
;
835 sizeHints
.max_width
= maxW
;
836 sizeHints
.max_height
= maxH
;
838 if (incW
> -1 && incH
> -1)
840 sizeHints
.flags
|= PResizeInc
;
841 sizeHints
.width_inc
= incW
;
842 sizeHints
.height_inc
= incH
;
845 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
848 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
850 DoSetSize(x
, y
, width
, height
);
853 // ---------------------------------------------------------------------------
855 // ---------------------------------------------------------------------------
857 int wxWindowX11::GetCharHeight() const
859 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
861 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
863 int direction
, ascent
, descent
;
865 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
868 // return (overall.ascent + overall.descent);
869 return (ascent
+ descent
);
872 int wxWindowX11::GetCharWidth() const
874 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
876 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
878 int direction
, ascent
, descent
;
880 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
883 return overall
.width
;
886 void wxWindowX11::GetTextExtent(const wxString
& string
,
888 int *descent
, int *externalLeading
,
889 const wxFont
*theFont
) const
891 wxFont fontToUse
= m_font
;
892 if (theFont
) fontToUse
= *theFont
;
894 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
896 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
898 int direction
, ascent
, descent2
;
900 int slen
= string
.Len();
904 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
905 &ascent
, &descent2
, &overall
);
908 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
909 &direction
, &ascent
, &descent2
, &overall
);
912 *x
= (overall
.width
);
914 *y
= (ascent
+ descent2
);
918 *externalLeading
= 0;
922 // ----------------------------------------------------------------------------
924 // ----------------------------------------------------------------------------
926 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
932 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
933 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
938 GetSize( &width
, &height
);
940 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
941 m_clearRegion
.Clear();
942 m_clearRegion
.Union( 0, 0, width
, height
);
948 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
949 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
954 GetSize( &width
, &height
);
956 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
957 m_updateRegion
.Clear();
958 m_updateRegion
.Union( 0, 0, width
, height
);
962 void wxWindowX11::Update()
964 if (!m_updateRegion
.IsEmpty())
966 X11SendPaintEvents();
970 void wxWindowX11::Clear()
972 wxClientDC
dc((wxWindow
*) this);
973 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
974 dc
.SetBackground(brush
);
978 void wxWindowX11::X11SendPaintEvents()
980 m_clipPaintRegion
= TRUE
;
982 // if (!m_clearRegion.IsEmpty())
984 wxWindowDC
dc( (wxWindow
*)this );
985 dc
.SetClippingRegion( m_clearRegion
);
987 wxEraseEvent
erase_event( GetId(), &dc
);
988 erase_event
.SetEventObject( this );
990 if (!GetEventHandler()->ProcessEvent(erase_event
))
992 wxRegionIterator
upd( m_clearRegion
);
995 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
996 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1000 m_clearRegion
.Clear();
1003 wxNcPaintEvent
nc_paint_event( GetId() );
1004 nc_paint_event
.SetEventObject( this );
1005 GetEventHandler()->ProcessEvent( nc_paint_event
);
1007 wxPaintEvent
paint_event( GetId() );
1008 paint_event
.SetEventObject( this );
1009 GetEventHandler()->ProcessEvent( paint_event
);
1011 m_updateRegion
.Clear();
1013 m_clipPaintRegion
= FALSE
;
1016 // ----------------------------------------------------------------------------
1018 // ----------------------------------------------------------------------------
1020 // Responds to colour changes: passes event on to children.
1021 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1023 wxWindowList::Node
*node
= GetChildren().GetFirst();
1026 // Only propagate to non-top-level windows
1027 wxWindow
*win
= node
->GetData();
1028 if ( win
->GetParent() )
1030 wxSysColourChangedEvent event2
;
1031 event
.m_eventObject
= win
;
1032 win
->GetEventHandler()->ProcessEvent(event2
);
1035 node
= node
->GetNext();
1039 void wxWindowX11::OnInternalIdle()
1041 // Update invalidated regions.
1044 // This calls the UI-update mechanism (querying windows for
1045 // menu/toolbar/control state information)
1049 // ----------------------------------------------------------------------------
1050 // function which maintain the global hash table mapping Widgets to wxWindows
1051 // ----------------------------------------------------------------------------
1053 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1055 wxWindow
*oldItem
= NULL
;
1056 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1058 wxLogDebug("Widget table clash: new widget is %ld, %s",
1059 (long)w
, win
->GetClassInfo()->GetClassName());
1063 wxWidgetHashTable
->Put((long) w
, win
);
1065 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1066 w
, win
, win
->GetClassInfo()->GetClassName());
1071 wxWindow
*wxGetWindowFromTable(Window w
)
1073 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1076 void wxDeleteWindowFromTable(Window w
)
1078 wxWidgetHashTable
->Delete((long)w
);
1081 // ----------------------------------------------------------------------------
1082 // add/remove window from the table
1083 // ----------------------------------------------------------------------------
1085 // ----------------------------------------------------------------------------
1086 // X11-specific accessors
1087 // ----------------------------------------------------------------------------
1089 // Get the underlying X window
1090 WXWindow
wxWindowX11::GetXWindow() const
1092 return GetMainWindow();
1095 // Get the underlying X display
1096 WXDisplay
*wxWindowX11::GetXDisplay() const
1098 return wxGetDisplay();
1101 WXWindow
wxWindowX11::GetMainWindow() const
1103 return m_mainWidget
;
1106 // ----------------------------------------------------------------------------
1107 // TranslateXXXEvent() functions
1108 // ----------------------------------------------------------------------------
1110 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1112 switch (xevent
->xany
.type
)
1120 wxEventType eventType
= wxEVT_NULL
;
1122 if (xevent
->xany
.type
== EnterNotify
)
1124 //if (local_event.xcrossing.mode!=NotifyNormal)
1125 // return ; // Ignore grab events
1126 eventType
= wxEVT_ENTER_WINDOW
;
1127 // canvas->GetEventHandler()->OnSetFocus();
1129 else if (xevent
->xany
.type
== LeaveNotify
)
1131 //if (local_event.xcrossingr.mode!=NotifyNormal)
1132 // return ; // Ignore grab events
1133 eventType
= wxEVT_LEAVE_WINDOW
;
1134 // canvas->GetEventHandler()->OnKillFocus();
1136 else if (xevent
->xany
.type
== MotionNotify
)
1138 eventType
= wxEVT_MOTION
;
1140 else if (xevent
->xany
.type
== ButtonPress
)
1142 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1144 if (xevent
->xbutton
.button
== Button1
)
1146 eventType
= wxEVT_LEFT_DOWN
;
1149 else if (xevent
->xbutton
.button
== Button2
)
1151 eventType
= wxEVT_MIDDLE_DOWN
;
1154 else if (xevent
->xbutton
.button
== Button3
)
1156 eventType
= wxEVT_RIGHT_DOWN
;
1160 // check for a double click
1161 // TODO: where can we get this value from?
1162 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1163 long dclickTime
= 200;
1164 long ts
= wxevent
.GetTimestamp();
1166 int buttonLast
= win
->GetLastClickedButton();
1167 long lastTS
= win
->GetLastClickTime();
1168 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1171 win
->SetLastClick(0, ts
);
1172 if ( eventType
== wxEVT_LEFT_DOWN
)
1173 eventType
= wxEVT_LEFT_DCLICK
;
1174 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1175 eventType
= wxEVT_MIDDLE_DCLICK
;
1176 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1177 eventType
= wxEVT_RIGHT_DCLICK
;
1181 // not fast enough or different button
1182 win
->SetLastClick(button
, ts
);
1185 else if (xevent
->xany
.type
== ButtonRelease
)
1187 if (xevent
->xbutton
.button
== Button1
)
1189 eventType
= wxEVT_LEFT_UP
;
1191 else if (xevent
->xbutton
.button
== Button2
)
1193 eventType
= wxEVT_MIDDLE_UP
;
1195 else if (xevent
->xbutton
.button
== Button3
)
1197 eventType
= wxEVT_RIGHT_UP
;
1206 wxevent
.SetEventType(eventType
);
1208 wxevent
.m_x
= xevent
->xbutton
.x
;
1209 wxevent
.m_y
= xevent
->xbutton
.y
;
1211 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1212 || (event_left_is_down (xevent
)
1213 && (eventType
!= wxEVT_LEFT_UP
)));
1214 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1215 || (event_middle_is_down (xevent
)
1216 && (eventType
!= wxEVT_MIDDLE_UP
)));
1217 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1218 || (event_right_is_down (xevent
)
1219 && (eventType
!= wxEVT_RIGHT_UP
)));
1221 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1222 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1223 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1224 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1226 wxevent
.SetId(win
->GetId());
1227 wxevent
.SetEventObject(win
);
1235 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1237 switch (xevent
->xany
.type
)
1245 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1246 int id
= wxCharCodeXToWX (keySym
);
1248 if (xevent
->xkey
.state
& ShiftMask
)
1249 wxevent
.m_shiftDown
= TRUE
;
1250 if (xevent
->xkey
.state
& ControlMask
)
1251 wxevent
.m_controlDown
= TRUE
;
1252 if (xevent
->xkey
.state
& Mod3Mask
)
1253 wxevent
.m_altDown
= TRUE
;
1254 if (xevent
->xkey
.state
& Mod1Mask
)
1255 wxevent
.m_metaDown
= TRUE
;
1256 wxevent
.SetEventObject(win
);
1257 wxevent
.m_keyCode
= id
;
1258 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1260 wxevent
.m_x
= xevent
->xbutton
.x
;
1261 wxevent
.m_y
= xevent
->xbutton
.y
;
1275 // ----------------------------------------------------------------------------
1277 // ----------------------------------------------------------------------------
1281 #define YAllocColor XAllocColor
1282 XColor g_itemColors
[5];
1283 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1286 static XmColorProc colorProc
;
1288 result
= wxNO_COLORS
;
1292 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1293 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1294 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1295 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1296 if (colorProc
== (XmColorProc
) NULL
)
1298 // Get a ptr to the actual function
1299 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1300 // And set it back to motif.
1301 XmSetColorCalculation (colorProc
);
1303 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1304 &g_itemColors
[wxFORE_INDEX
],
1305 &g_itemColors
[wxSELE_INDEX
],
1306 &g_itemColors
[wxTOPS_INDEX
],
1307 &g_itemColors
[wxBOTS_INDEX
]);
1308 result
= wxBACK_COLORS
;
1312 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1313 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1314 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1315 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1316 if (result
== wxNO_COLORS
)
1317 result
= wxFORE_COLORS
;
1320 Display
*dpy
= display
;
1321 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1325 /* 5 Colours to allocate */
1326 for (int i
= 0; i
< 5; i
++)
1327 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1328 result
= wxNO_COLORS
;
1332 /* Only 1 colour to allocate */
1333 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1334 result
= wxNO_COLORS
;
1342 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1344 wxWindowBase::SetBackgroundColour(col
);
1346 if (!GetMainWindow())
1349 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1350 int xscreen
= DefaultScreen( xdisplay
);
1351 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1353 wxColour
colour( col
);
1354 colour
.CalcPixel( (WXColormap
) cm
);
1356 XSetWindowAttributes attrib
;
1357 attrib
.background_pixel
= colour
.GetPixel();
1359 XChangeWindowAttributes(wxGlobalDisplay(),
1360 (Window
) GetMainWindow(),
1367 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1369 if ( !wxWindowBase::SetForegroundColour(col
) )
1375 // ----------------------------------------------------------------------------
1377 // ----------------------------------------------------------------------------
1379 wxWindow
*wxGetActiveWindow()
1382 wxFAIL_MSG("Not implemented");
1387 wxWindow
*wxWindowBase::GetCapture()
1389 return (wxWindow
*)g_captureWindow
;
1393 // Find the wxWindow at the current mouse position, returning the mouse
1395 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1397 return wxFindWindowAtPoint(wxGetMousePosition());
1400 // Get the current mouse position.
1401 wxPoint
wxGetMousePosition()
1403 Display
*display
= wxGlobalDisplay();
1404 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1405 Window rootReturn
, childReturn
;
1406 int rootX
, rootY
, winX
, winY
;
1407 unsigned int maskReturn
;
1409 XQueryPointer (display
,
1413 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1414 return wxPoint(rootX
, rootY
);
1418 // ----------------------------------------------------------------------------
1419 // wxNoOptimize: switch off size optimization
1420 // ----------------------------------------------------------------------------
1422 int wxNoOptimize::ms_count
= 0;