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 // TODO: set a m_needInputFocus flag and do the
213 // the setting in OnIdle or Show, because we can't
214 // set the focus for an unmapped window.
215 // We need to figure out how to find out if the window
218 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
221 wmhints
.flags
= InputHint
;
222 wmhints
.input
= True
;
223 XSetWMHints(wxGlobalDisplay(), wMain
, &wmhints
);
228 // Get the window with the focus
229 wxWindow
*wxWindowBase::FindFocus()
231 Window wFocus
= (Window
) 0;
234 XGetInputFocus(wxGlobalDisplay(), & wFocus
, & revert
);
237 wxWindow
*win
= NULL
;
240 win
= wxGetWindowFromTable(wFocus
);
241 wFocus
= wxGetWindowParent(wFocus
);
242 } while (wFocus
&& !win
);
250 // Enabling/disabling handled by event loop, and not sending events
252 bool wxWindowX11::Enable(bool enable
)
254 if ( !wxWindowBase::Enable(enable
) )
260 bool wxWindowX11::Show(bool show
)
262 wxWindowBase::Show(show
);
264 Window xwin
= (Window
) GetXWindow();
265 Display
*xdisp
= (Display
*) GetXDisplay();
269 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
271 XMapWindow(xdisp
, xwin
);
277 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
279 XUnmapWindow(xdisp
, xwin
);
285 // Raise the window to the top of the Z order
286 void wxWindowX11::Raise()
289 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
292 // Lower the window to the bottom of the Z order
293 void wxWindowX11::Lower()
296 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
299 void wxWindowX11::DoCaptureMouse()
301 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
303 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
314 Window xwindow
= (Window
) GetMainWindow();
316 g_captureWindow
= (wxWindow
*) this;
320 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
322 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
326 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
329 if (res
!= GrabSuccess
)
332 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
334 if (res
== GrabNotViewable
)
336 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
338 g_captureWindow
= NULL
;
342 wxLogDebug("Grabbed pointer");
345 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
346 (Window
) GetMainWindow(),
348 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
354 if (res
!= GrabSuccess
)
356 wxLogDebug("Failed to grab mouse buttons.");
357 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
363 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
364 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
370 if (res
!= GrabSuccess
)
372 wxLogDebug("Failed to grab keyboard.");
373 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
374 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
375 (Window
) GetMainWindow());
380 m_winCaptured
= TRUE
;
384 void wxWindowX11::DoReleaseMouse()
386 g_captureWindow
= NULL
;
388 if ( !m_winCaptured
)
391 Window xwindow
= (Window
) GetMainWindow();
395 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
397 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
398 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
401 wxLogDebug("Ungrabbed pointer");
403 m_winCaptured
= FALSE
;
406 bool wxWindowX11::SetFont(const wxFont
& font
)
408 if ( !wxWindowBase::SetFont(font
) )
417 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
419 if ( !wxWindowBase::SetCursor(cursor
) )
425 wxCursor
* cursor2
= NULL
;
427 cursor2
= & m_cursor
;
429 cursor2
= wxSTANDARD_CURSOR
;
431 WXCursor x_cursor
= cursor2
->GetCursor();
433 Window win
= (Window
) GetMainWindow();
434 XDefineCursor((Display
*) wxGlobalDisplay(), win
, (Cursor
) x_cursor
);
439 // Coordinates relative to the window
440 void wxWindowX11::WarpPointer (int x
, int y
)
443 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
446 // Does a physical scroll
447 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
453 // Use specified rectangle
454 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
458 // Use whole client area
460 GetClientSize(& w
, & h
);
463 wxNode
*cnode
= m_children
.First();
466 wxWindow
*child
= (wxWindow
*) cnode
->Data();
469 child
->GetSize( &sx
, &sy
);
470 wxPoint
pos( child
->GetPosition() );
471 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
472 cnode
= cnode
->Next();
475 int x1
= (dx
>= 0) ? x
: x
- dx
;
476 int y1
= (dy
>= 0) ? y
: y
- dy
;
477 int w1
= w
- abs(dx
);
478 int h1
= h
- abs(dy
);
479 int x2
= (dx
>= 0) ? x
+ dx
: x
;
480 int y2
= (dy
>= 0) ? y
+ dy
: y
;
482 wxClientDC
dc((wxWindow
*) this);
484 dc
.SetLogicalFunction (wxCOPY
);
486 Window window
= (Window
) GetMainWindow();
487 Display
* display
= wxGlobalDisplay();
489 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
490 x1
, y1
, w1
, h1
, x2
, y2
);
492 dc
.SetAutoSetting(TRUE
);
493 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
494 dc
.SetBrush(brush
); // FIXME: needed?
496 // We'll add rectangles to the list of update rectangles according to which
497 // bits we've exposed.
502 wxRect
*rect
= new wxRect
;
508 XFillRectangle(display
, window
,
509 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
513 rect
->width
= rect
->width
;
514 rect
->height
= rect
->height
;
516 updateRects
.Append((wxObject
*) rect
);
520 wxRect
*rect
= new wxRect
;
522 rect
->x
= x
+ w
+ dx
;
527 XFillRectangle(display
, window
,
528 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
533 rect
->width
= rect
->width
;
534 rect
->height
= rect
->height
;
536 updateRects
.Append((wxObject
*) rect
);
540 wxRect
*rect
= new wxRect
;
547 XFillRectangle(display
, window
,
548 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
552 rect
->width
= rect
->width
;
553 rect
->height
= rect
->height
;
555 updateRects
.Append((wxObject
*) rect
);
559 wxRect
*rect
= new wxRect
;
562 rect
->y
= y
+ h
+ dy
;
566 XFillRectangle(display
, window
,
567 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
571 rect
->width
= rect
->width
;
572 rect
->height
= rect
->height
;
574 updateRects
.Append((wxObject
*) rect
);
576 dc
.SetBrush(wxNullBrush
);
578 // Now send expose events
580 wxNode
* node
= updateRects
.First();
583 wxRect
* rect
= (wxRect
*) node
->Data();
587 event
.display
= display
;
588 event
.send_event
= True
;
589 event
.window
= window
;
593 event
.width
= rect
->width
;
594 event
.height
= rect
->height
;
598 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
604 // Delete the update rects
605 node
= updateRects
.First();
608 wxRect
* rect
= (wxRect
*) node
->Data();
615 // ---------------------------------------------------------------------------
617 // ---------------------------------------------------------------------------
619 #if wxUSE_DRAG_AND_DROP
621 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
628 // Old style file-manager drag&drop
629 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
634 // ----------------------------------------------------------------------------
636 // ----------------------------------------------------------------------------
640 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
645 #endif // wxUSE_TOOLTIPS
647 // ---------------------------------------------------------------------------
648 // moving and resizing
649 // ---------------------------------------------------------------------------
651 bool wxWindowX11::PreResize()
657 void wxWindowX11::DoGetSize(int *x
, int *y
) const
659 Window window
= (Window
) m_mainWidget
;
662 XWindowAttributes attr
;
663 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
668 *x
= attr
.width
/* + 2*m_borderSize */ ;
669 *y
= attr
.height
/* + 2*m_borderSize */ ;
674 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
676 Window window
= (Window
) m_mainWidget
;
679 XWindowAttributes attr
;
680 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
688 // We may be faking the client origin. So a window that's really at (0, 30)
689 // may appear (to wxWin apps) to be at (0, 0).
692 wxPoint
pt(GetParent()->GetClientAreaOrigin());
700 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
702 Display
*display
= wxGlobalDisplay();
703 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
704 Window thisWindow
= (Window
) m_mainWidget
;
709 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
712 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
714 Display
*display
= wxGlobalDisplay();
715 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
716 Window thisWindow
= (Window
) m_mainWidget
;
721 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
725 // Get size *available for subwindows* i.e. excluding menu bar etc.
726 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
728 Window window
= (Window
) m_mainWidget
;
732 XWindowAttributes attr
;
733 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
744 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
746 if (!GetMainWindow())
749 XWindowChanges windowChanges
;
752 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
755 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
759 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
762 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
766 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
768 windowChanges
.width
= width
/* - m_borderSize*2 */;
769 valueMask
|= CWWidth
;
771 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
773 windowChanges
.height
= height
/* -m_borderSize*2*/;
774 valueMask
|= CWHeight
;
777 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
778 valueMask
, & windowChanges
);
781 void wxWindowX11::DoSetClientSize(int width
, int height
)
783 if (!GetMainWindow())
786 XWindowChanges windowChanges
;
791 windowChanges
.width
= width
;
792 valueMask
|= CWWidth
;
796 windowChanges
.height
= height
;
797 valueMask
|= CWHeight
;
799 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
800 valueMask
, & windowChanges
);
803 // For implementation purposes - sometimes decorations make the client area
805 wxPoint
wxWindowX11::GetClientAreaOrigin() const
807 return wxPoint(0, 0);
810 // Makes an adjustment to the window position (for example, a frame that has
811 // a toolbar that it manages itself).
812 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
814 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
816 wxPoint
pt(GetParent()->GetClientAreaOrigin());
817 x
+= pt
.x
; y
+= pt
.y
;
821 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
828 XSizeHints sizeHints
;
831 if (minW
> -1 && minH
> -1)
833 sizeHints
.flags
|= PMinSize
;
834 sizeHints
.min_width
= minW
;
835 sizeHints
.min_height
= minH
;
837 if (maxW
> -1 && maxH
> -1)
839 sizeHints
.flags
|= PMaxSize
;
840 sizeHints
.max_width
= maxW
;
841 sizeHints
.max_height
= maxH
;
843 if (incW
> -1 && incH
> -1)
845 sizeHints
.flags
|= PResizeInc
;
846 sizeHints
.width_inc
= incW
;
847 sizeHints
.height_inc
= incH
;
850 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
853 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
855 DoSetSize(x
, y
, width
, height
);
858 // ---------------------------------------------------------------------------
860 // ---------------------------------------------------------------------------
862 int wxWindowX11::GetCharHeight() const
864 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
866 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
868 int direction
, ascent
, descent
;
870 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
873 // return (overall.ascent + overall.descent);
874 return (ascent
+ descent
);
877 int wxWindowX11::GetCharWidth() const
879 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
881 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
883 int direction
, ascent
, descent
;
885 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
888 return overall
.width
;
891 void wxWindowX11::GetTextExtent(const wxString
& string
,
893 int *descent
, int *externalLeading
,
894 const wxFont
*theFont
) const
896 wxFont fontToUse
= m_font
;
897 if (theFont
) fontToUse
= *theFont
;
899 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
901 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
903 int direction
, ascent
, descent2
;
905 int slen
= string
.Len();
909 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
910 &ascent
, &descent2
, &overall
);
913 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
914 &direction
, &ascent
, &descent2
, &overall
);
917 *x
= (overall
.width
);
919 *y
= (ascent
+ descent2
);
923 *externalLeading
= 0;
927 // ----------------------------------------------------------------------------
929 // ----------------------------------------------------------------------------
931 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
937 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
938 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
943 GetSize( &width
, &height
);
945 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
946 m_clearRegion
.Clear();
947 m_clearRegion
.Union( 0, 0, width
, height
);
953 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
954 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
959 GetSize( &width
, &height
);
961 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
962 m_updateRegion
.Clear();
963 m_updateRegion
.Union( 0, 0, width
, height
);
967 void wxWindowX11::Update()
969 if (!m_updateRegion
.IsEmpty())
971 X11SendPaintEvents();
975 void wxWindowX11::Clear()
977 wxClientDC
dc((wxWindow
*) this);
978 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
979 dc
.SetBackground(brush
);
983 void wxWindowX11::X11SendPaintEvents()
985 m_clipPaintRegion
= TRUE
;
987 // if (!m_clearRegion.IsEmpty())
989 wxWindowDC
dc( (wxWindow
*)this );
990 dc
.SetClippingRegion( m_clearRegion
);
992 wxEraseEvent
erase_event( GetId(), &dc
);
993 erase_event
.SetEventObject( this );
995 if (!GetEventHandler()->ProcessEvent(erase_event
))
997 wxRegionIterator
upd( m_clearRegion
);
1000 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
1001 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1005 m_clearRegion
.Clear();
1008 wxNcPaintEvent
nc_paint_event( GetId() );
1009 nc_paint_event
.SetEventObject( this );
1010 GetEventHandler()->ProcessEvent( nc_paint_event
);
1012 wxPaintEvent
paint_event( GetId() );
1013 paint_event
.SetEventObject( this );
1014 GetEventHandler()->ProcessEvent( paint_event
);
1016 m_updateRegion
.Clear();
1018 m_clipPaintRegion
= FALSE
;
1021 // ----------------------------------------------------------------------------
1023 // ----------------------------------------------------------------------------
1025 // Responds to colour changes: passes event on to children.
1026 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1028 wxWindowList::Node
*node
= GetChildren().GetFirst();
1031 // Only propagate to non-top-level windows
1032 wxWindow
*win
= node
->GetData();
1033 if ( win
->GetParent() )
1035 wxSysColourChangedEvent event2
;
1036 event
.m_eventObject
= win
;
1037 win
->GetEventHandler()->ProcessEvent(event2
);
1040 node
= node
->GetNext();
1044 void wxWindowX11::OnInternalIdle()
1046 // Update invalidated regions.
1049 // This calls the UI-update mechanism (querying windows for
1050 // menu/toolbar/control state information)
1054 // ----------------------------------------------------------------------------
1055 // function which maintain the global hash table mapping Widgets to wxWindows
1056 // ----------------------------------------------------------------------------
1058 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1060 wxWindow
*oldItem
= NULL
;
1061 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1063 wxLogDebug("Widget table clash: new widget is %ld, %s",
1064 (long)w
, win
->GetClassInfo()->GetClassName());
1068 wxWidgetHashTable
->Put((long) w
, win
);
1070 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1071 w
, win
, win
->GetClassInfo()->GetClassName());
1076 wxWindow
*wxGetWindowFromTable(Window w
)
1078 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1081 void wxDeleteWindowFromTable(Window w
)
1083 wxWidgetHashTable
->Delete((long)w
);
1086 // ----------------------------------------------------------------------------
1087 // add/remove window from the table
1088 // ----------------------------------------------------------------------------
1090 // ----------------------------------------------------------------------------
1091 // X11-specific accessors
1092 // ----------------------------------------------------------------------------
1094 // Get the underlying X window
1095 WXWindow
wxWindowX11::GetXWindow() const
1097 return GetMainWindow();
1100 // Get the underlying X display
1101 WXDisplay
*wxWindowX11::GetXDisplay() const
1103 return wxGetDisplay();
1106 WXWindow
wxWindowX11::GetMainWindow() const
1108 return m_mainWidget
;
1111 // ----------------------------------------------------------------------------
1112 // TranslateXXXEvent() functions
1113 // ----------------------------------------------------------------------------
1115 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1117 switch (xevent
->xany
.type
)
1125 wxEventType eventType
= wxEVT_NULL
;
1127 if (xevent
->xany
.type
== EnterNotify
)
1129 //if (local_event.xcrossing.mode!=NotifyNormal)
1130 // return ; // Ignore grab events
1131 eventType
= wxEVT_ENTER_WINDOW
;
1132 // canvas->GetEventHandler()->OnSetFocus();
1134 else if (xevent
->xany
.type
== LeaveNotify
)
1136 //if (local_event.xcrossingr.mode!=NotifyNormal)
1137 // return ; // Ignore grab events
1138 eventType
= wxEVT_LEAVE_WINDOW
;
1139 // canvas->GetEventHandler()->OnKillFocus();
1141 else if (xevent
->xany
.type
== MotionNotify
)
1143 eventType
= wxEVT_MOTION
;
1145 else if (xevent
->xany
.type
== ButtonPress
)
1147 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1149 if (xevent
->xbutton
.button
== Button1
)
1151 eventType
= wxEVT_LEFT_DOWN
;
1154 else if (xevent
->xbutton
.button
== Button2
)
1156 eventType
= wxEVT_MIDDLE_DOWN
;
1159 else if (xevent
->xbutton
.button
== Button3
)
1161 eventType
= wxEVT_RIGHT_DOWN
;
1165 // check for a double click
1166 // TODO: where can we get this value from?
1167 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1168 long dclickTime
= 200;
1169 long ts
= wxevent
.GetTimestamp();
1171 int buttonLast
= win
->GetLastClickedButton();
1172 long lastTS
= win
->GetLastClickTime();
1173 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1176 win
->SetLastClick(0, ts
);
1177 if ( eventType
== wxEVT_LEFT_DOWN
)
1178 eventType
= wxEVT_LEFT_DCLICK
;
1179 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1180 eventType
= wxEVT_MIDDLE_DCLICK
;
1181 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1182 eventType
= wxEVT_RIGHT_DCLICK
;
1186 // not fast enough or different button
1187 win
->SetLastClick(button
, ts
);
1190 else if (xevent
->xany
.type
== ButtonRelease
)
1192 if (xevent
->xbutton
.button
== Button1
)
1194 eventType
= wxEVT_LEFT_UP
;
1196 else if (xevent
->xbutton
.button
== Button2
)
1198 eventType
= wxEVT_MIDDLE_UP
;
1200 else if (xevent
->xbutton
.button
== Button3
)
1202 eventType
= wxEVT_RIGHT_UP
;
1211 wxevent
.SetEventType(eventType
);
1213 wxevent
.m_x
= xevent
->xbutton
.x
;
1214 wxevent
.m_y
= xevent
->xbutton
.y
;
1216 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1217 || (event_left_is_down (xevent
)
1218 && (eventType
!= wxEVT_LEFT_UP
)));
1219 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1220 || (event_middle_is_down (xevent
)
1221 && (eventType
!= wxEVT_MIDDLE_UP
)));
1222 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1223 || (event_right_is_down (xevent
)
1224 && (eventType
!= wxEVT_RIGHT_UP
)));
1226 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1227 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1228 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1229 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1231 wxevent
.SetId(win
->GetId());
1232 wxevent
.SetEventObject(win
);
1240 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1242 switch (xevent
->xany
.type
)
1250 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1251 int id
= wxCharCodeXToWX (keySym
);
1253 if (xevent
->xkey
.state
& ShiftMask
)
1254 wxevent
.m_shiftDown
= TRUE
;
1255 if (xevent
->xkey
.state
& ControlMask
)
1256 wxevent
.m_controlDown
= TRUE
;
1257 if (xevent
->xkey
.state
& Mod3Mask
)
1258 wxevent
.m_altDown
= TRUE
;
1259 if (xevent
->xkey
.state
& Mod1Mask
)
1260 wxevent
.m_metaDown
= TRUE
;
1261 wxevent
.SetEventObject(win
);
1262 wxevent
.m_keyCode
= id
;
1263 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1265 wxevent
.m_x
= xevent
->xbutton
.x
;
1266 wxevent
.m_y
= xevent
->xbutton
.y
;
1280 // ----------------------------------------------------------------------------
1282 // ----------------------------------------------------------------------------
1286 #define YAllocColor XAllocColor
1287 XColor g_itemColors
[5];
1288 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1291 static XmColorProc colorProc
;
1293 result
= wxNO_COLORS
;
1297 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1298 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1299 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1300 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1301 if (colorProc
== (XmColorProc
) NULL
)
1303 // Get a ptr to the actual function
1304 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1305 // And set it back to motif.
1306 XmSetColorCalculation (colorProc
);
1308 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1309 &g_itemColors
[wxFORE_INDEX
],
1310 &g_itemColors
[wxSELE_INDEX
],
1311 &g_itemColors
[wxTOPS_INDEX
],
1312 &g_itemColors
[wxBOTS_INDEX
]);
1313 result
= wxBACK_COLORS
;
1317 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1318 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1319 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1320 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1321 if (result
== wxNO_COLORS
)
1322 result
= wxFORE_COLORS
;
1325 Display
*dpy
= display
;
1326 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1330 /* 5 Colours to allocate */
1331 for (int i
= 0; i
< 5; i
++)
1332 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1333 result
= wxNO_COLORS
;
1337 /* Only 1 colour to allocate */
1338 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1339 result
= wxNO_COLORS
;
1347 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1349 wxWindowBase::SetBackgroundColour(col
);
1351 if (!GetMainWindow())
1354 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1355 int xscreen
= DefaultScreen( xdisplay
);
1356 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1358 wxColour
colour( col
);
1359 colour
.CalcPixel( (WXColormap
) cm
);
1361 XSetWindowAttributes attrib
;
1362 attrib
.background_pixel
= colour
.GetPixel();
1364 XChangeWindowAttributes(wxGlobalDisplay(),
1365 (Window
) GetMainWindow(),
1372 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1374 if ( !wxWindowBase::SetForegroundColour(col
) )
1380 // ----------------------------------------------------------------------------
1382 // ----------------------------------------------------------------------------
1384 wxWindow
*wxGetActiveWindow()
1387 wxFAIL_MSG("Not implemented");
1392 wxWindow
*wxWindowBase::GetCapture()
1394 return (wxWindow
*)g_captureWindow
;
1398 // Find the wxWindow at the current mouse position, returning the mouse
1400 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1402 return wxFindWindowAtPoint(wxGetMousePosition());
1405 // Get the current mouse position.
1406 wxPoint
wxGetMousePosition()
1408 Display
*display
= wxGlobalDisplay();
1409 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1410 Window rootReturn
, childReturn
;
1411 int rootX
, rootY
, winX
, winY
;
1412 unsigned int maskReturn
;
1414 XQueryPointer (display
,
1418 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1419 return wxPoint(rootX
, rootY
);
1423 // ----------------------------------------------------------------------------
1424 // wxNoOptimize: switch off size optimization
1425 // ----------------------------------------------------------------------------
1427 int wxNoOptimize::ms_count
= 0;