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;
96 m_winCaptured
= FALSE
;
97 m_needsInputFocus
= FALSE
;
99 m_isBeingDeleted
= FALSE
;
104 // real construction (Init() must have been called before!)
105 bool wxWindowX11
::Create(wxWindow
*parent
, wxWindowID id
,
109 const wxString
& name
)
111 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
113 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
115 parent
->AddChild(this);
117 int w
= size
.GetWidth();
118 int h
= size
.GetHeight();
126 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
127 int xscreen
= DefaultScreen( xdisplay
);
128 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
130 m_backgroundColour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
131 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
134 m_foregroundColour
= *wxBLACK
;
135 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
138 Window parentWindow
= (Window
) parent
->GetMainWindow();
140 Window window
= XCreateSimpleWindow(
141 xdisplay
, parentWindow
,
143 m_backgroundColour
.GetPixel(),
144 m_backgroundColour
.GetPixel() );
146 m_mainWidget
= (WXWindow
) window
;
148 // Select event types wanted
149 XSelectInput( wxGlobalDisplay(), window
,
150 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
151 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
152 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
155 wxAddWindowToTable(window
, (wxWindow
*) this);
157 // Is a subwindow, so map immediately
159 XMapWindow(wxGlobalDisplay(), window
);
161 // Without this, the cursor may not be restored properly (e.g. in splitter
163 SetCursor(*wxSTANDARD_CURSOR
);
164 SetFont(wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
));
165 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
171 wxWindowX11
::~wxWindowX11()
173 if (g_captureWindow
== this)
174 g_captureWindow
= NULL
;
176 m_isBeingDeleted
= TRUE
;
178 // X11-specific actions first
179 Window main
= (Window
) m_mainWidget
;
182 // Removes event handlers
183 //DetachWidget(main);
187 m_parent
->RemoveChild( this );
191 // Destroy the window
194 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
195 wxDeleteWindowFromTable( main
);
196 XDestroyWindow( wxGlobalDisplay(), main
);
201 // ---------------------------------------------------------------------------
203 // ---------------------------------------------------------------------------
205 void wxWindowX11
::SetFocus()
207 Window xwindow
= (Window
) GetMainWindow();
209 wxCHECK_RET( xwindow
, wxT("invalid window") );
211 if (wxWindowIsVisible(xwindow
))
213 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
214 m_needsInputFocus
= FALSE
;
218 m_needsInputFocus
= TRUE
;
222 // Get the window with the focus
223 wxWindow
*wxWindowBase
::FindFocus()
225 Window xfocus
= (Window
) 0;
228 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
231 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
239 // Enabling/disabling handled by event loop, and not sending events
241 bool wxWindowX11
::Enable(bool enable
)
243 if ( !wxWindowBase
::Enable(enable
) )
249 bool wxWindowX11
::Show(bool show
)
251 wxWindowBase
::Show(show
);
253 Window xwin
= (Window
) GetXWindow();
254 Display
*xdisp
= (Display
*) GetXDisplay();
258 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
260 XMapWindow(xdisp
, xwin
);
266 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
268 XUnmapWindow(xdisp
, xwin
);
274 // Raise the window to the top of the Z order
275 void wxWindowX11
::Raise()
278 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
281 // Lower the window to the bottom of the Z order
282 void wxWindowX11
::Lower()
285 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
288 void wxWindowX11
::DoCaptureMouse()
290 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
292 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
303 Window xwindow
= (Window
) GetMainWindow();
305 wxCHECK_RET( xwindow
, wxT("invalid window") );
307 g_captureWindow
= (wxWindow
*) this;
311 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
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
;
333 wxLogDebug("Grabbed pointer");
336 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
337 (Window
) GetMainWindow(),
339 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
345 if (res
!= GrabSuccess
)
347 wxLogDebug("Failed to grab mouse buttons.");
348 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
354 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
355 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
361 if (res
!= GrabSuccess
)
363 wxLogDebug("Failed to grab keyboard.");
364 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
365 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
366 (Window
) GetMainWindow());
371 m_winCaptured
= TRUE
;
375 void wxWindowX11
::DoReleaseMouse()
377 g_captureWindow
= NULL
;
379 if ( !m_winCaptured
)
382 Window xwindow
= (Window
) GetMainWindow();
386 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
388 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
389 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
392 wxLogDebug("Ungrabbed pointer");
394 m_winCaptured
= FALSE
;
397 bool wxWindowX11
::SetFont(const wxFont
& font
)
399 if ( !wxWindowBase
::SetFont(font
) )
408 bool wxWindowX11
::SetCursor(const wxCursor
& cursor
)
410 if ( !wxWindowBase
::SetCursor(cursor
) )
416 Window xwindow
= (Window
) GetMainWindow();
418 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
420 wxCursor cursorToUse
;
422 cursorToUse
= m_cursor
;
424 cursorToUse
= *wxSTANDARD_CURSOR
;
426 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
428 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
433 // Coordinates relative to the window
434 void wxWindowX11
::WarpPointer (int x
, int y
)
436 Window xwindow
= (Window
) GetMainWindow();
438 wxCHECK_RET( xwindow
, wxT("invalid window") );
440 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
443 // Does a physical scroll
444 void wxWindowX11
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
450 // Use specified rectangle
451 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
455 // Use whole client area
457 GetClientSize(& w
, & h
);
460 wxNode
*cnode
= m_children
.First();
463 wxWindow
*child
= (wxWindow
*) cnode
->Data();
466 child
->GetSize( &sx
, &sy
);
467 wxPoint
pos( child
->GetPosition() );
468 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
469 cnode
= cnode
->Next();
472 int x1
= (dx
>= 0) ? x
: x
- dx
;
473 int y1
= (dy
>= 0) ? y
: y
- dy
;
474 int w1
= w
- abs(dx
);
475 int h1
= h
- abs(dy
);
476 int x2
= (dx
>= 0) ? x
+ dx
: x
;
477 int y2
= (dy
>= 0) ? y
+ dy
: y
;
479 wxClientDC
dc((wxWindow
*) this);
481 dc
.SetLogicalFunction (wxCOPY
);
483 Window window
= (Window
) GetMainWindow();
484 Display
* display
= wxGlobalDisplay();
486 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
487 x1
, y1
, w1
, h1
, x2
, y2
);
489 dc
.SetAutoSetting(TRUE
);
490 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
491 dc
.SetBrush(brush
); // FIXME: needed?
493 // We'll add rectangles to the list of update rectangles according to which
494 // bits we've exposed.
499 wxRect
*rect
= new wxRect
;
505 XFillRectangle(display
, window
,
506 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
510 rect
->width
= rect
->width
;
511 rect
->height
= rect
->height
;
513 updateRects
.Append((wxObject
*) rect
);
517 wxRect
*rect
= new wxRect
;
519 rect
->x
= x
+ w
+ dx
;
524 XFillRectangle(display
, window
,
525 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
530 rect
->width
= rect
->width
;
531 rect
->height
= rect
->height
;
533 updateRects
.Append((wxObject
*) rect
);
537 wxRect
*rect
= new wxRect
;
544 XFillRectangle(display
, window
,
545 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
549 rect
->width
= rect
->width
;
550 rect
->height
= rect
->height
;
552 updateRects
.Append((wxObject
*) rect
);
556 wxRect
*rect
= new wxRect
;
559 rect
->y
= y
+ h
+ dy
;
563 XFillRectangle(display
, window
,
564 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
568 rect
->width
= rect
->width
;
569 rect
->height
= rect
->height
;
571 updateRects
.Append((wxObject
*) rect
);
573 dc
.SetBrush(wxNullBrush
);
575 // Now send expose events
577 wxNode
* node
= updateRects
.First();
580 wxRect
* rect
= (wxRect
*) node
->Data();
584 event
.display
= display
;
585 event
.send_event
= True
;
586 event
.window
= window
;
590 event
.width
= rect
->width
;
591 event
.height
= rect
->height
;
595 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
601 // Delete the update rects
602 node
= updateRects
.First();
605 wxRect
* rect
= (wxRect
*) node
->Data();
612 // ---------------------------------------------------------------------------
614 // ---------------------------------------------------------------------------
616 #if wxUSE_DRAG_AND_DROP
618 void wxWindowX11
::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
625 // Old style file-manager drag&drop
626 void wxWindowX11
::DragAcceptFiles(bool WXUNUSED(accept
))
631 // ----------------------------------------------------------------------------
633 // ----------------------------------------------------------------------------
637 void wxWindowX11
::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
642 #endif // wxUSE_TOOLTIPS
644 // ---------------------------------------------------------------------------
645 // moving and resizing
646 // ---------------------------------------------------------------------------
648 bool wxWindowX11
::PreResize()
654 void wxWindowX11
::DoGetSize(int *x
, int *y
) const
656 Window xwindow
= (Window
) GetMainWindow();
658 wxCHECK_RET( xwindow
, wxT("invalid window") );
660 XSync(wxGlobalDisplay(), False
);
661 XWindowAttributes attr
;
662 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
667 *x
= attr
.width
/* + 2*m_borderSize */ ;
668 *y
= attr
.height
/* + 2*m_borderSize */ ;
672 void wxWindowX11
::DoGetPosition(int *x
, int *y
) const
674 Window window
= (Window
) m_mainWidget
;
677 XSync(wxGlobalDisplay(), False
);
678 XWindowAttributes attr
;
679 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
687 // We may be faking the client origin. So a window that's really at (0, 30)
688 // may appear (to wxWin apps) to be at (0, 0).
691 wxPoint
pt(GetParent()->GetClientAreaOrigin());
699 void wxWindowX11
::DoScreenToClient(int *x
, int *y
) const
701 Display
*display
= wxGlobalDisplay();
702 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
703 Window thisWindow
= (Window
) m_mainWidget
;
708 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
711 void wxWindowX11
::DoClientToScreen(int *x
, int *y
) const
713 Display
*display
= wxGlobalDisplay();
714 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
715 Window thisWindow
= (Window
) m_mainWidget
;
720 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
724 // Get size *available for subwindows* i.e. excluding menu bar etc.
725 void wxWindowX11
::DoGetClientSize(int *x
, int *y
) const
727 Window window
= (Window
) m_mainWidget
;
731 XSync(wxGlobalDisplay(), False
);
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
);
779 XSync(wxGlobalDisplay(), False
);
782 void wxWindowX11
::DoSetClientSize(int width
, int height
)
784 if (!GetMainWindow())
787 XWindowChanges windowChanges
;
792 windowChanges
.width
= width
;
793 valueMask
|= CWWidth
;
797 windowChanges
.height
= height
;
798 valueMask
|= CWHeight
;
800 XConfigureWindow(wxGlobalDisplay(), (Window
) GetMainWindow(),
801 valueMask
, & windowChanges
);
802 XSync(wxGlobalDisplay(), False
);
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
= m_font
;
899 if (theFont
) fontToUse
= *theFont
;
901 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
903 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
905 int direction
, ascent
, descent2
;
907 int slen
= string
.Len();
911 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
912 &ascent
, &descent2
, &overall
);
915 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
916 &direction
, &ascent
, &descent2
, &overall
);
919 *x
= (overall
.width
);
921 *y
= (ascent
+ descent2
);
925 *externalLeading
= 0;
929 // ----------------------------------------------------------------------------
931 // ----------------------------------------------------------------------------
933 void wxWindowX11
::Refresh(bool eraseBack
, const wxRect
*rect
)
939 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
940 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
945 GetSize( &width
, &height
);
947 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
948 m_clearRegion
.Clear();
949 m_clearRegion
.Union( 0, 0, width
, height
);
955 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
956 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
961 GetSize( &width
, &height
);
963 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
964 m_updateRegion
.Clear();
965 m_updateRegion
.Union( 0, 0, width
, height
);
969 void wxWindowX11
::Update()
971 if (!m_updateRegion
.IsEmpty())
973 X11SendPaintEvents();
977 void wxWindowX11
::Clear()
979 wxClientDC
dc((wxWindow
*) this);
980 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
981 dc
.SetBackground(brush
);
985 void wxWindowX11
::X11SendPaintEvents()
987 m_clipPaintRegion
= TRUE
;
989 // if (!m_clearRegion.IsEmpty())
991 wxWindowDC
dc( (wxWindow
*)this );
992 dc
.SetClippingRegion( m_clearRegion
);
994 wxEraseEvent
erase_event( GetId(), &dc
);
995 erase_event
.SetEventObject( this );
997 if (!GetEventHandler()->ProcessEvent(erase_event
))
999 wxRegionIterator
upd( m_clearRegion
);
1002 XClearArea( wxGlobalDisplay(), (Window
) m_mainWidget
,
1003 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight(), False
);
1007 m_clearRegion
.Clear();
1010 wxNcPaintEvent
nc_paint_event( GetId() );
1011 nc_paint_event
.SetEventObject( this );
1012 GetEventHandler()->ProcessEvent( nc_paint_event
);
1014 wxPaintEvent
paint_event( GetId() );
1015 paint_event
.SetEventObject( this );
1016 GetEventHandler()->ProcessEvent( paint_event
);
1018 m_updateRegion
.Clear();
1020 m_clipPaintRegion
= FALSE
;
1023 // ----------------------------------------------------------------------------
1025 // ----------------------------------------------------------------------------
1027 // Responds to colour changes: passes event on to children.
1028 void wxWindowX11
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1030 wxWindowList
::Node
*node
= GetChildren().GetFirst();
1033 // Only propagate to non-top-level windows
1034 wxWindow
*win
= node
->GetData();
1035 if ( win
->GetParent() )
1037 wxSysColourChangedEvent event2
;
1038 event
.m_eventObject
= win
;
1039 win
->GetEventHandler()->ProcessEvent(event2
);
1042 node
= node
->GetNext();
1046 void wxWindowX11
::OnInternalIdle()
1048 // Update invalidated regions.
1051 // This calls the UI-update mechanism (querying windows for
1052 // menu/toolbar/control state information)
1055 // Set the input focus if couldn't do it before
1056 if (m_needsInputFocus
)
1060 // ----------------------------------------------------------------------------
1061 // function which maintain the global hash table mapping Widgets to wxWindows
1062 // ----------------------------------------------------------------------------
1064 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1066 wxWindow
*oldItem
= NULL
;
1067 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1069 wxLogDebug("Widget table clash: new widget is %ld, %s",
1070 (long)w
, win
->GetClassInfo()->GetClassName());
1074 wxWidgetHashTable
->Put((long) w
, win
);
1076 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1077 w
, win
, win
->GetClassInfo()->GetClassName());
1082 wxWindow
*wxGetWindowFromTable(Window w
)
1084 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1087 void wxDeleteWindowFromTable(Window w
)
1089 wxWidgetHashTable
->Delete((long)w
);
1092 // ----------------------------------------------------------------------------
1093 // add/remove window from the table
1094 // ----------------------------------------------------------------------------
1096 // ----------------------------------------------------------------------------
1097 // X11-specific accessors
1098 // ----------------------------------------------------------------------------
1100 // Get the underlying X window
1101 WXWindow wxWindowX11
::GetXWindow() const
1103 return GetMainWindow();
1106 // Get the underlying X display
1107 WXDisplay
*wxWindowX11
::GetXDisplay() const
1109 return wxGetDisplay();
1112 WXWindow wxWindowX11
::GetMainWindow() const
1114 return m_mainWidget
;
1117 // ----------------------------------------------------------------------------
1118 // TranslateXXXEvent() functions
1119 // ----------------------------------------------------------------------------
1121 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1123 switch (xevent
->xany
.type
)
1131 wxEventType eventType
= wxEVT_NULL
;
1133 if (xevent
->xany
.type
== EnterNotify
)
1135 //if (local_event.xcrossing.mode!=NotifyNormal)
1136 // return ; // Ignore grab events
1137 eventType
= wxEVT_ENTER_WINDOW
;
1138 // canvas->GetEventHandler()->OnSetFocus();
1140 else if (xevent
->xany
.type
== LeaveNotify
)
1142 //if (local_event.xcrossingr.mode!=NotifyNormal)
1143 // return ; // Ignore grab events
1144 eventType
= wxEVT_LEAVE_WINDOW
;
1145 // canvas->GetEventHandler()->OnKillFocus();
1147 else if (xevent
->xany
.type
== MotionNotify
)
1149 eventType
= wxEVT_MOTION
;
1151 else if (xevent
->xany
.type
== ButtonPress
)
1153 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1155 if (xevent
->xbutton
.button
== Button1
)
1157 eventType
= wxEVT_LEFT_DOWN
;
1160 else if (xevent
->xbutton
.button
== Button2
)
1162 eventType
= wxEVT_MIDDLE_DOWN
;
1165 else if (xevent
->xbutton
.button
== Button3
)
1167 eventType
= wxEVT_RIGHT_DOWN
;
1171 // check for a double click
1172 // TODO: where can we get this value from?
1173 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1174 long dclickTime
= 200;
1175 long ts
= wxevent
.GetTimestamp();
1177 int buttonLast
= win
->GetLastClickedButton();
1178 long lastTS
= win
->GetLastClickTime();
1179 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1182 win
->SetLastClick(0, ts
);
1183 if ( eventType
== wxEVT_LEFT_DOWN
)
1184 eventType
= wxEVT_LEFT_DCLICK
;
1185 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1186 eventType
= wxEVT_MIDDLE_DCLICK
;
1187 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1188 eventType
= wxEVT_RIGHT_DCLICK
;
1192 // not fast enough or different button
1193 win
->SetLastClick(button
, ts
);
1196 else if (xevent
->xany
.type
== ButtonRelease
)
1198 if (xevent
->xbutton
.button
== Button1
)
1200 eventType
= wxEVT_LEFT_UP
;
1202 else if (xevent
->xbutton
.button
== Button2
)
1204 eventType
= wxEVT_MIDDLE_UP
;
1206 else if (xevent
->xbutton
.button
== Button3
)
1208 eventType
= wxEVT_RIGHT_UP
;
1217 wxevent
.SetEventType(eventType
);
1219 wxevent
.m_x
= xevent
->xbutton
.x
;
1220 wxevent
.m_y
= xevent
->xbutton
.y
;
1222 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1223 || (event_left_is_down (xevent
)
1224 && (eventType
!= wxEVT_LEFT_UP
)));
1225 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1226 || (event_middle_is_down (xevent
)
1227 && (eventType
!= wxEVT_MIDDLE_UP
)));
1228 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1229 || (event_right_is_down (xevent
)
1230 && (eventType
!= wxEVT_RIGHT_UP
)));
1232 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1233 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1234 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1235 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1237 wxevent
.SetId(win
->GetId());
1238 wxevent
.SetEventObject(win
);
1246 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1248 switch (xevent
->xany
.type
)
1256 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1257 int id
= wxCharCodeXToWX (keySym
);
1259 if (xevent
->xkey
.state
& ShiftMask
)
1260 wxevent
.m_shiftDown
= TRUE
;
1261 if (xevent
->xkey
.state
& ControlMask
)
1262 wxevent
.m_controlDown
= TRUE
;
1263 if (xevent
->xkey
.state
& Mod3Mask
)
1264 wxevent
.m_altDown
= TRUE
;
1265 if (xevent
->xkey
.state
& Mod1Mask
)
1266 wxevent
.m_metaDown
= TRUE
;
1267 wxevent
.SetEventObject(win
);
1268 wxevent
.m_keyCode
= id
;
1269 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1271 wxevent
.m_x
= xevent
->xbutton
.x
;
1272 wxevent
.m_y
= xevent
->xbutton
.y
;
1286 // ----------------------------------------------------------------------------
1288 // ----------------------------------------------------------------------------
1290 bool wxWindowX11
::SetBackgroundColour(const wxColour
& col
)
1292 wxWindowBase
::SetBackgroundColour(col
);
1294 if (!GetMainWindow())
1297 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1298 int xscreen
= DefaultScreen( xdisplay
);
1299 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1301 wxColour
colour( col
);
1302 colour
.CalcPixel( (WXColormap
) cm
);
1304 XSetWindowAttributes attrib
;
1305 attrib
.background_pixel
= colour
.GetPixel();
1307 XChangeWindowAttributes(wxGlobalDisplay(),
1308 (Window
) GetMainWindow(),
1315 bool wxWindowX11
::SetForegroundColour(const wxColour
& col
)
1317 if ( !wxWindowBase
::SetForegroundColour(col
) )
1323 // ----------------------------------------------------------------------------
1325 // ----------------------------------------------------------------------------
1327 wxWindow
*wxGetActiveWindow()
1330 wxFAIL_MSG("Not implemented");
1335 wxWindow
*wxWindowBase
::GetCapture()
1337 return (wxWindow
*)g_captureWindow
;
1341 // Find the wxWindow at the current mouse position, returning the mouse
1343 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1345 return wxFindWindowAtPoint(wxGetMousePosition());
1348 // Get the current mouse position.
1349 wxPoint
wxGetMousePosition()
1351 Display
*display
= wxGlobalDisplay();
1352 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1353 Window rootReturn
, childReturn
;
1354 int rootX
, rootY
, winX
, winY
;
1355 unsigned int maskReturn
;
1357 XQueryPointer (display
,
1361 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1362 return wxPoint(rootX
, rootY
);
1366 // ----------------------------------------------------------------------------
1367 // wxNoOptimize: switch off size optimization
1368 // ----------------------------------------------------------------------------
1370 int wxNoOptimize
::ms_count
= 0;