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
);
143 m_foregroundColour
= *wxBLACK
;
144 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
147 Window parentWindow
= (Window
) parent
->GetMainWindow();
149 Window window
= XCreateSimpleWindow(
150 xdisplay
, parentWindow
,
152 m_backgroundColour
.GetPixel(),
153 m_backgroundColour
.GetPixel() );
155 m_mainWidget
= (WXWindow
) window
;
157 // Select event types wanted
158 XSelectInput(wxGlobalDisplay(), window
,
159 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
160 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
161 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
164 wxAddWindowToTable(window
, (wxWindow
*) this);
166 // Is a subwindow, so map immediately
168 XMapWindow(wxGlobalDisplay(), window
);
170 // Without this, the cursor may not be restored properly (e.g. in splitter
172 SetCursor(*wxSTANDARD_CURSOR
);
173 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
174 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
180 wxWindowX11::~wxWindowX11()
182 if (g_captureWindow
== this)
183 g_captureWindow
= NULL
;
185 m_isBeingDeleted
= TRUE
;
187 // X11-specific actions first
188 Window main
= (Window
) m_mainWidget
;
191 // Removes event handlers
192 //DetachWidget(main);
196 m_parent
->RemoveChild( this );
200 // Destroy the window
203 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
204 wxDeleteWindowFromTable( main
);
205 XDestroyWindow( wxGlobalDisplay(), main
);
210 // ---------------------------------------------------------------------------
212 // ---------------------------------------------------------------------------
214 void wxWindowX11::SetFocus()
216 Window wMain
= (Window
) GetMainWindow();
219 XSetInputFocus(wxGlobalDisplay(), wMain
, RevertToParent
, CurrentTime
);
222 wmhints
.flags
= InputHint
;
223 wmhints
.input
= True
;
224 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 g_captureWindow
= (wxWindow
*) this;
318 int res
= XGrabPointer(wxGlobalDisplay(), (Window
) GetMainWindow(),
320 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
324 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
327 if (res
!= GrabSuccess
)
330 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
332 if (res
== GrabNotViewable
)
334 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
336 g_captureWindow
= NULL
;
339 wxLogDebug("Grabbed pointer");
342 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
343 (Window
) GetMainWindow(),
345 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
351 if (res
!= GrabSuccess
)
353 wxLogDebug("Failed to grab mouse buttons.");
354 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
360 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
362 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
370 if (res
!= GrabSuccess
)
372 wxLogDebug("Failed to grab keyboard.");
373 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
375 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
376 (Window
) GetMainWindow());
382 m_winCaptured
= TRUE
;
386 void wxWindowX11::DoReleaseMouse()
388 g_captureWindow
= NULL
;
389 if ( !m_winCaptured
)
392 Window wMain
= (Window
)GetMainWindow();
396 XUngrabPointer(wxGlobalDisplay(), wMain
);
398 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
400 XUngrabKeyboard(wxGlobalDisplay(), CurrentTime
);
403 wxLogDebug("Ungrabbed pointer");
405 m_winCaptured
= FALSE
;
408 bool wxWindowX11::SetFont(const wxFont
& font
)
410 if ( !wxWindowBase::SetFont(font
) )
419 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
421 if ( !wxWindowBase::SetCursor(cursor
) )
427 wxCursor
* cursor2
= NULL
;
429 cursor2
= & m_cursor
;
431 cursor2
= wxSTANDARD_CURSOR
;
433 WXCursor x_cursor
= cursor2
->GetCursor();
435 Window win
= (Window
) GetMainWindow();
436 XDefineCursor((Display
*) wxGlobalDisplay(), win
, (Cursor
) x_cursor
);
441 // Coordinates relative to the window
442 void wxWindowX11::WarpPointer (int x
, int y
)
445 XWarpPointer( wxGlobalDisplay(), None
, (Window
) m_mainWidget
, 0, 0, 0, 0, x
, y
);
448 // Does a physical scroll
449 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
455 // Use specified rectangle
456 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
460 // Use whole client area
462 GetClientSize(& w
, & h
);
465 wxNode
*cnode
= m_children
.First();
468 wxWindow
*child
= (wxWindow
*) cnode
->Data();
471 child
->GetSize( &sx
, &sy
);
472 wxPoint
pos( child
->GetPosition() );
473 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
474 cnode
= cnode
->Next();
477 int x1
= (dx
>= 0) ? x
: x
- dx
;
478 int y1
= (dy
>= 0) ? y
: y
- dy
;
479 int w1
= w
- abs(dx
);
480 int h1
= h
- abs(dy
);
481 int x2
= (dx
>= 0) ? x
+ dx
: x
;
482 int y2
= (dy
>= 0) ? y
+ dy
: y
;
484 wxClientDC
dc((wxWindow
*) this);
486 dc
.SetLogicalFunction (wxCOPY
);
488 Window window
= (Window
) GetMainWindow();
489 Display
* display
= wxGlobalDisplay();
491 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
492 x1
, y1
, w1
, h1
, x2
, y2
);
494 dc
.SetAutoSetting(TRUE
);
495 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
496 dc
.SetBrush(brush
); // FIXME: needed?
498 // We'll add rectangles to the list of update rectangles according to which
499 // bits we've exposed.
504 wxRect
*rect
= new wxRect
;
510 XFillRectangle(display
, window
,
511 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
515 rect
->width
= rect
->width
;
516 rect
->height
= rect
->height
;
518 updateRects
.Append((wxObject
*) rect
);
522 wxRect
*rect
= new wxRect
;
524 rect
->x
= x
+ w
+ dx
;
529 XFillRectangle(display
, window
,
530 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
535 rect
->width
= rect
->width
;
536 rect
->height
= rect
->height
;
538 updateRects
.Append((wxObject
*) rect
);
542 wxRect
*rect
= new wxRect
;
549 XFillRectangle(display
, window
,
550 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
554 rect
->width
= rect
->width
;
555 rect
->height
= rect
->height
;
557 updateRects
.Append((wxObject
*) rect
);
561 wxRect
*rect
= new wxRect
;
564 rect
->y
= y
+ h
+ dy
;
568 XFillRectangle(display
, window
,
569 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
573 rect
->width
= rect
->width
;
574 rect
->height
= rect
->height
;
576 updateRects
.Append((wxObject
*) rect
);
578 dc
.SetBrush(wxNullBrush
);
580 // Now send expose events
582 wxNode
* node
= updateRects
.First();
585 wxRect
* rect
= (wxRect
*) node
->Data();
589 event
.display
= display
;
590 event
.send_event
= True
;
591 event
.window
= window
;
595 event
.width
= rect
->width
;
596 event
.height
= rect
->height
;
600 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
606 // Delete the update rects
607 node
= updateRects
.First();
610 wxRect
* rect
= (wxRect
*) node
->Data();
617 // ---------------------------------------------------------------------------
619 // ---------------------------------------------------------------------------
621 #if wxUSE_DRAG_AND_DROP
623 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
630 // Old style file-manager drag&drop
631 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
636 // ----------------------------------------------------------------------------
638 // ----------------------------------------------------------------------------
642 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
647 #endif // wxUSE_TOOLTIPS
649 // ---------------------------------------------------------------------------
650 // moving and resizing
651 // ---------------------------------------------------------------------------
653 bool wxWindowX11::PreResize()
659 void wxWindowX11::DoGetSize(int *x
, int *y
) const
661 Window window
= (Window
) m_mainWidget
;
664 XWindowAttributes attr
;
665 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
670 *x
= attr
.width
/* + 2*m_borderSize */ ;
671 *y
= attr
.height
/* + 2*m_borderSize */ ;
676 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
678 Window window
= (Window
) m_mainWidget
;
681 XWindowAttributes attr
;
682 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
690 // We may be faking the client origin. So a window that's really at (0, 30)
691 // may appear (to wxWin apps) to be at (0, 0).
694 wxPoint
pt(GetParent()->GetClientAreaOrigin());
702 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
704 Display
*display
= wxGlobalDisplay();
705 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
706 Window thisWindow
= (Window
) m_mainWidget
;
711 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
714 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
716 Display
*display
= wxGlobalDisplay();
717 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
718 Window thisWindow
= (Window
) m_mainWidget
;
723 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
727 // Get size *available for subwindows* i.e. excluding menu bar etc.
728 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
730 Window window
= (Window
) m_mainWidget
;
734 XWindowAttributes attr
;
735 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
746 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
748 if (!GetMainWindow())
751 XWindowChanges windowChanges
;
754 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
757 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
761 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
764 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
768 if (width
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
770 windowChanges
.width
= width
/* - m_borderSize*2 */;
771 valueMask
|= CWWidth
;
773 if (height
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
775 windowChanges
.height
= height
/* -m_borderSize*2*/;
776 valueMask
|= CWHeight
;
779 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
780 valueMask
, & windowChanges
);
783 void wxWindowX11::DoSetClientSize(int width
, int height
)
785 if (!GetMainWindow())
788 XWindowChanges windowChanges
;
793 windowChanges
.width
= width
;
794 valueMask
|= CWWidth
;
798 windowChanges
.height
= height
;
799 valueMask
|= CWHeight
;
801 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
802 valueMask
, & windowChanges
);
805 // For implementation purposes - sometimes decorations make the client area
807 wxPoint
wxWindowX11::GetClientAreaOrigin() const
809 return wxPoint(0, 0);
812 // Makes an adjustment to the window position (for example, a frame that has
813 // a toolbar that it manages itself).
814 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
816 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
818 wxPoint
pt(GetParent()->GetClientAreaOrigin());
819 x
+= pt
.x
; y
+= pt
.y
;
823 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
830 XSizeHints sizeHints
;
833 if (minW
> -1 && minH
> -1)
835 sizeHints
.flags
|= PMinSize
;
836 sizeHints
.min_width
= minW
;
837 sizeHints
.min_height
= minH
;
839 if (maxW
> -1 && maxH
> -1)
841 sizeHints
.flags
|= PMaxSize
;
842 sizeHints
.max_width
= maxW
;
843 sizeHints
.max_height
= maxH
;
845 if (incW
> -1 && incH
> -1)
847 sizeHints
.flags
|= PResizeInc
;
848 sizeHints
.width_inc
= incW
;
849 sizeHints
.height_inc
= incH
;
852 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
855 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
857 DoSetSize(x
, y
, width
, height
);
860 // ---------------------------------------------------------------------------
862 // ---------------------------------------------------------------------------
864 int wxWindowX11::GetCharHeight() const
866 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
868 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
870 int direction
, ascent
, descent
;
872 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
875 // return (overall.ascent + overall.descent);
876 return (ascent
+ descent
);
879 int wxWindowX11::GetCharWidth() const
881 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
883 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
885 int direction
, ascent
, descent
;
887 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
890 return overall
.width
;
893 void wxWindowX11::GetTextExtent(const wxString
& string
,
895 int *descent
, int *externalLeading
,
896 const wxFont
*theFont
) const
898 wxFont
*fontToUse
= (wxFont
*)theFont
;
900 fontToUse
= (wxFont
*) & m_font
;
902 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
904 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
906 int direction
, ascent
, descent2
;
908 int slen
= string
.Len();
912 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
913 &ascent
, &descent2
, &overall
);
916 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
917 &direction
, &ascent
, &descent2
, &overall
);
920 *x
= (overall
.width
);
922 *y
= (ascent
+ descent2
);
926 *externalLeading
= 0;
930 // ----------------------------------------------------------------------------
932 // ----------------------------------------------------------------------------
934 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
940 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
941 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
946 GetSize( &width
, &height
);
948 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
949 m_clearRegion
.Clear();
950 m_clearRegion
.Union( 0, 0, width
, height
);
956 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
957 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
962 GetSize( &width
, &height
);
964 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
965 m_updateRegion
.Clear();
966 m_updateRegion
.Union( 0, 0, width
, height
);
969 // Actually don't schedule yet..
973 void wxWindowX11::Update()
975 if (!m_updateRegion
.IsEmpty())
977 X11SendPaintEvents();
981 void wxWindowX11::Clear()
983 wxClientDC
dc((wxWindow
*) this);
984 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
985 dc
.SetBackground(brush
);
989 void wxWindowX11::X11SendPaintEvents()
991 m_clipPaintRegion
= TRUE
;
993 // if (!m_clearRegion.IsEmpty())
995 wxWindowDC
dc( (wxWindow
*)this );
996 dc
.SetClippingRegion( m_clearRegion
);
998 wxEraseEvent
erase_event( GetId(), &dc
);
999 erase_event
.SetEventObject( this );
1001 if (!GetEventHandler()->ProcessEvent(erase_event
))
1003 wxRegionIterator
upd( m_clearRegion
);
1006 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
1007 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1011 m_clearRegion
.Clear();
1014 wxNcPaintEvent
nc_paint_event( GetId() );
1015 nc_paint_event
.SetEventObject( this );
1016 GetEventHandler()->ProcessEvent( nc_paint_event
);
1018 wxPaintEvent
paint_event( GetId() );
1019 paint_event
.SetEventObject( this );
1020 GetEventHandler()->ProcessEvent( paint_event
);
1022 m_clipPaintRegion
= FALSE
;
1025 // ----------------------------------------------------------------------------
1027 // ----------------------------------------------------------------------------
1029 // Responds to colour changes: passes event on to children.
1030 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1032 wxWindowList::Node
*node
= GetChildren().GetFirst();
1035 // Only propagate to non-top-level windows
1036 wxWindow
*win
= node
->GetData();
1037 if ( win
->GetParent() )
1039 wxSysColourChangedEvent event2
;
1040 event
.m_eventObject
= win
;
1041 win
->GetEventHandler()->ProcessEvent(event2
);
1044 node
= node
->GetNext();
1048 void wxWindowX11::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1050 // This calls the UI-update mechanism (querying windows for
1051 // menu/toolbar/control state information)
1055 // ----------------------------------------------------------------------------
1056 // function which maintain the global hash table mapping Widgets to wxWindows
1057 // ----------------------------------------------------------------------------
1059 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1061 wxWindow
*oldItem
= NULL
;
1062 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1064 wxLogDebug("Widget table clash: new widget is %ld, %s",
1065 (long)w
, win
->GetClassInfo()->GetClassName());
1069 wxWidgetHashTable
->Put((long) w
, win
);
1071 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1072 w
, win
, win
->GetClassInfo()->GetClassName());
1077 wxWindow
*wxGetWindowFromTable(Window w
)
1079 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1082 void wxDeleteWindowFromTable(Window w
)
1084 wxWidgetHashTable
->Delete((long)w
);
1087 // ----------------------------------------------------------------------------
1088 // add/remove window from the table
1089 // ----------------------------------------------------------------------------
1091 // ----------------------------------------------------------------------------
1092 // X11-specific accessors
1093 // ----------------------------------------------------------------------------
1095 // Get the underlying X window
1096 WXWindow
wxWindowX11::GetXWindow() const
1098 return GetMainWindow();
1101 // Get the underlying X display
1102 WXDisplay
*wxWindowX11::GetXDisplay() const
1104 return wxGetDisplay();
1107 WXWindow
wxWindowX11::GetMainWindow() const
1109 return m_mainWidget
;
1112 // ----------------------------------------------------------------------------
1113 // TranslateXXXEvent() functions
1114 // ----------------------------------------------------------------------------
1116 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1118 switch (xevent
->xany
.type
)
1126 wxEventType eventType
= wxEVT_NULL
;
1128 if (xevent
->xany
.type
== EnterNotify
)
1130 //if (local_event.xcrossing.mode!=NotifyNormal)
1131 // return ; // Ignore grab events
1132 eventType
= wxEVT_ENTER_WINDOW
;
1133 // canvas->GetEventHandler()->OnSetFocus();
1135 else if (xevent
->xany
.type
== LeaveNotify
)
1137 //if (local_event.xcrossingr.mode!=NotifyNormal)
1138 // return ; // Ignore grab events
1139 eventType
= wxEVT_LEAVE_WINDOW
;
1140 // canvas->GetEventHandler()->OnKillFocus();
1142 else if (xevent
->xany
.type
== MotionNotify
)
1144 eventType
= wxEVT_MOTION
;
1146 else if (xevent
->xany
.type
== ButtonPress
)
1148 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1150 if (xevent
->xbutton
.button
== Button1
)
1152 eventType
= wxEVT_LEFT_DOWN
;
1155 else if (xevent
->xbutton
.button
== Button2
)
1157 eventType
= wxEVT_MIDDLE_DOWN
;
1160 else if (xevent
->xbutton
.button
== Button3
)
1162 eventType
= wxEVT_RIGHT_DOWN
;
1166 // check for a double click
1167 // TODO: where can we get this value from?
1168 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1169 long dclickTime
= 200;
1170 long ts
= wxevent
.GetTimestamp();
1172 int buttonLast
= win
->GetLastClickedButton();
1173 long lastTS
= win
->GetLastClickTime();
1174 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1177 win
->SetLastClick(0, ts
);
1178 if ( eventType
== wxEVT_LEFT_DOWN
)
1179 eventType
= wxEVT_LEFT_DCLICK
;
1180 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1181 eventType
= wxEVT_MIDDLE_DCLICK
;
1182 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1183 eventType
= wxEVT_RIGHT_DCLICK
;
1187 // not fast enough or different button
1188 win
->SetLastClick(button
, ts
);
1191 else if (xevent
->xany
.type
== ButtonRelease
)
1193 if (xevent
->xbutton
.button
== Button1
)
1195 eventType
= wxEVT_LEFT_UP
;
1197 else if (xevent
->xbutton
.button
== Button2
)
1199 eventType
= wxEVT_MIDDLE_UP
;
1201 else if (xevent
->xbutton
.button
== Button3
)
1203 eventType
= wxEVT_RIGHT_UP
;
1212 wxevent
.SetEventType(eventType
);
1214 wxevent
.m_x
= xevent
->xbutton
.x
;
1215 wxevent
.m_y
= xevent
->xbutton
.y
;
1217 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1218 || (event_left_is_down (xevent
)
1219 && (eventType
!= wxEVT_LEFT_UP
)));
1220 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1221 || (event_middle_is_down (xevent
)
1222 && (eventType
!= wxEVT_MIDDLE_UP
)));
1223 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1224 || (event_right_is_down (xevent
)
1225 && (eventType
!= wxEVT_RIGHT_UP
)));
1227 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1228 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1229 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1230 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1232 wxevent
.SetId(win
->GetId());
1233 wxevent
.SetEventObject(win
);
1241 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1243 switch (xevent
->xany
.type
)
1251 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1252 int id
= wxCharCodeXToWX (keySym
);
1254 if (xevent
->xkey
.state
& ShiftMask
)
1255 wxevent
.m_shiftDown
= TRUE
;
1256 if (xevent
->xkey
.state
& ControlMask
)
1257 wxevent
.m_controlDown
= TRUE
;
1258 if (xevent
->xkey
.state
& Mod3Mask
)
1259 wxevent
.m_altDown
= TRUE
;
1260 if (xevent
->xkey
.state
& Mod1Mask
)
1261 wxevent
.m_metaDown
= TRUE
;
1262 wxevent
.SetEventObject(win
);
1263 wxevent
.m_keyCode
= id
;
1264 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1266 wxevent
.m_x
= xevent
->xbutton
.x
;
1267 wxevent
.m_y
= xevent
->xbutton
.y
;
1281 // ----------------------------------------------------------------------------
1283 // ----------------------------------------------------------------------------
1287 #define YAllocColor XAllocColor
1288 XColor g_itemColors
[5];
1289 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
1292 static XmColorProc colorProc
;
1294 result
= wxNO_COLORS
;
1298 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
1299 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
1300 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
1301 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
1302 if (colorProc
== (XmColorProc
) NULL
)
1304 // Get a ptr to the actual function
1305 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
1306 // And set it back to motif.
1307 XmSetColorCalculation (colorProc
);
1309 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
1310 &g_itemColors
[wxFORE_INDEX
],
1311 &g_itemColors
[wxSELE_INDEX
],
1312 &g_itemColors
[wxTOPS_INDEX
],
1313 &g_itemColors
[wxBOTS_INDEX
]);
1314 result
= wxBACK_COLORS
;
1318 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
1319 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
1320 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
1321 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
1322 if (result
== wxNO_COLORS
)
1323 result
= wxFORE_COLORS
;
1326 Display
*dpy
= display
;
1327 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
1331 /* 5 Colours to allocate */
1332 for (int i
= 0; i
< 5; i
++)
1333 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
1334 result
= wxNO_COLORS
;
1338 /* Only 1 colour to allocate */
1339 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
1340 result
= wxNO_COLORS
;
1348 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1350 wxWindowBase::SetBackgroundColour(col
);
1352 if (!GetMainWindow())
1355 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1356 int xscreen
= DefaultScreen( xdisplay
);
1357 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1359 wxColour
colour( col
);
1360 colour
.CalcPixel( (WXColormap
) cm
);
1362 XSetWindowAttributes attrib
;
1363 attrib
.background_pixel
= colour
.GetPixel();
1365 XChangeWindowAttributes(wxGlobalDisplay(),
1366 (Window
) GetMainWindow(),
1373 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1375 if ( !wxWindowBase::SetForegroundColour(col
) )
1381 // ----------------------------------------------------------------------------
1383 // ----------------------------------------------------------------------------
1385 wxWindow
*wxGetActiveWindow()
1388 wxFAIL_MSG("Not implemented");
1393 wxWindow
*wxWindowBase::GetCapture()
1395 return (wxWindow
*)g_captureWindow
;
1399 // Find the wxWindow at the current mouse position, returning the mouse
1401 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1403 return wxFindWindowAtPoint(wxGetMousePosition());
1406 // Get the current mouse position.
1407 wxPoint
wxGetMousePosition()
1409 Display
*display
= wxGlobalDisplay();
1410 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1411 Window rootReturn
, childReturn
;
1412 int rootX
, rootY
, winX
, winY
;
1413 unsigned int maskReturn
;
1415 XQueryPointer (display
,
1419 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1420 return wxPoint(rootX
, rootY
);
1424 // ----------------------------------------------------------------------------
1425 // wxNoOptimize: switch off size optimization
1426 // ----------------------------------------------------------------------------
1428 int wxNoOptimize::ms_count
= 0;