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 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
129 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
131 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
132 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
134 m_foregroundColour
= *wxBLACK
;
135 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
137 Window xparent
= (Window
) parent
->GetMainWindow();
139 XSetWindowAttributes xattributes
;
141 long xattributes_mask
=
143 CWBorderPixel
| CWBackPixel
;
145 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
146 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
148 xattributes
.event_mask
=
149 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
150 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
151 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
166 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
167 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
169 m_mainWidget
= (WXWindow
) xwindow
;
171 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
173 // Is a subwindow, so map immediately
175 XMapWindow( xdisplay
, xwindow
);
177 // Without this, the cursor may not be restored properly (e.g. in splitter
179 SetCursor(*wxSTANDARD_CURSOR
);
180 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
182 // Set background to None which will prevent X11 from clearing the
183 // background comletely.
184 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
186 // Don't call this, it can have nasty repercussions for composite controls,
188 // SetSize(pos.x, pos.y, size.x, size.y);
194 wxWindowX11::~wxWindowX11()
196 if (g_captureWindow
== this)
197 g_captureWindow
= NULL
;
199 m_isBeingDeleted
= TRUE
;
201 // X11-specific actions first
202 Window xwindow
= (Window
) m_mainWidget
;
205 m_parent
->RemoveChild( this );
209 // Destroy the window
212 XSelectInput( wxGlobalDisplay(), xwindow
, NoEventMask
);
213 wxDeleteWindowFromTable( xwindow
);
214 XDestroyWindow( wxGlobalDisplay(), xwindow
);
219 // ---------------------------------------------------------------------------
221 // ---------------------------------------------------------------------------
223 void wxWindowX11::SetFocus()
225 Window xwindow
= (Window
) GetMainWindow();
227 wxCHECK_RET( xwindow
, wxT("invalid window") );
229 if (wxWindowIsVisible(xwindow
))
231 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
232 m_needsInputFocus
= FALSE
;
236 m_needsInputFocus
= TRUE
;
240 // Get the window with the focus
241 wxWindow
*wxWindowBase::FindFocus()
243 Window xfocus
= (Window
) 0;
246 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
249 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
257 wxWindow
*wxWindowX11::GetFocusWidget()
259 wxWindow
*win
= (wxWindow
*) this;
260 while (!win
->IsTopLevel())
262 win
= win
->GetParent();
264 return (wxWindow
*) NULL
;
270 // Enabling/disabling handled by event loop, and not sending events
272 bool wxWindowX11::Enable(bool enable
)
274 if ( !wxWindowBase::Enable(enable
) )
280 bool wxWindowX11::Show(bool show
)
282 wxWindowBase::Show(show
);
284 Window xwin
= (Window
) GetXWindow();
285 Display
*xdisp
= (Display
*) GetXDisplay();
288 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
289 XMapWindow(xdisp
, xwin
);
294 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
295 XUnmapWindow(xdisp
, xwin
);
301 // Raise the window to the top of the Z order
302 void wxWindowX11::Raise()
305 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
308 // Lower the window to the bottom of the Z order
309 void wxWindowX11::Lower()
312 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
315 void wxWindowX11::DoCaptureMouse()
317 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
319 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
330 Window xwindow
= (Window
) GetMainWindow();
332 wxCHECK_RET( xwindow
, wxT("invalid window") );
334 g_captureWindow
= (wxWindow
*) this;
338 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
340 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
344 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
347 if (res
!= GrabSuccess
)
350 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
352 if (res
== GrabNotViewable
)
354 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
356 g_captureWindow
= NULL
;
360 /// wxLogDebug("Grabbed pointer");
363 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
364 (Window
) GetMainWindow(),
366 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
372 if (res
!= GrabSuccess
)
374 wxLogDebug("Failed to grab mouse buttons.");
375 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
381 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
382 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
388 if (res
!= GrabSuccess
)
390 wxLogDebug("Failed to grab keyboard.");
391 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
392 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
393 (Window
) GetMainWindow());
398 m_winCaptured
= TRUE
;
402 void wxWindowX11::DoReleaseMouse()
404 g_captureWindow
= NULL
;
406 if ( !m_winCaptured
)
409 Window xwindow
= (Window
) GetMainWindow();
413 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
415 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
416 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
420 // wxLogDebug("Ungrabbed pointer");
422 m_winCaptured
= FALSE
;
425 bool wxWindowX11::SetFont(const wxFont
& font
)
427 if ( !wxWindowBase::SetFont(font
) )
436 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
438 if ( !wxWindowBase::SetCursor(cursor
) )
444 Window xwindow
= (Window
) GetMainWindow();
446 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
448 wxCursor cursorToUse
;
450 cursorToUse
= m_cursor
;
452 cursorToUse
= *wxSTANDARD_CURSOR
;
454 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
456 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
461 // Coordinates relative to the window
462 void wxWindowX11::WarpPointer (int x
, int y
)
464 Window xwindow
= (Window
) GetMainWindow();
466 wxCHECK_RET( xwindow
, wxT("invalid window") );
468 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
471 // Does a physical scroll
472 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
474 // No scrolling requested.
475 if ((dx
== 0) && (dy
== 0)) return;
477 if (!m_updateRegion
.IsEmpty())
479 m_updateRegion
.Offset( dx
, dy
);
483 GetSize( &cw
, &ch
); // GetClientSize() ??
484 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
487 if (!m_clearRegion
.IsEmpty())
489 m_clearRegion
.Offset( dx
, dy
);
493 GetSize( &cw
, &ch
); // GetClientSize() ??
494 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
497 Window xwindow
= (Window
) GetMainWindow();
499 wxCHECK_RET( xwindow
, wxT("invalid window") );
501 Display
*xdisplay
= wxGlobalDisplay();
503 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
504 XSetGraphicsExposures( xdisplay
, xgc
, True
);
521 GetClientSize( &cw
, &ch
);
524 wxPoint offset
= GetClientAreaOrigin();
528 int w
= cw
- abs(dx
);
529 int h
= ch
- abs(dy
);
531 if ((h
< 0) || (w
< 0))
538 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
539 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
540 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
541 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
545 if (dx
< 0) s_x
+= -dx
;
546 if (dy
< 0) s_y
+= -dy
;
547 if (dx
> 0) d_x
= dx
;
548 if (dy
> 0) d_y
= dy
;
550 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
552 // printf( "s_x %d s_y %d w %d h %d d_x %d d_y %d\n", s_x, s_y, w, h, d_x, d_y );
554 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
556 m_updateRegion
.Union( rect
);
557 m_clearRegion
.Union( rect
);
560 XFreeGC( xdisplay
, xgc
);
563 // ---------------------------------------------------------------------------
565 // ---------------------------------------------------------------------------
567 #if wxUSE_DRAG_AND_DROP
569 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
576 // Old style file-manager drag&drop
577 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
582 // ----------------------------------------------------------------------------
584 // ----------------------------------------------------------------------------
588 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
593 #endif // wxUSE_TOOLTIPS
595 // ---------------------------------------------------------------------------
596 // moving and resizing
597 // ---------------------------------------------------------------------------
599 bool wxWindowX11::PreResize()
605 void wxWindowX11::DoGetSize(int *x
, int *y
) const
607 Window xwindow
= (Window
) GetMainWindow();
609 wxCHECK_RET( xwindow
, wxT("invalid window") );
611 XSync(wxGlobalDisplay(), False
);
613 XWindowAttributes attr
;
614 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
619 *x
= attr
.width
/* + 2*m_borderSize */ ;
620 *y
= attr
.height
/* + 2*m_borderSize */ ;
624 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
626 Window window
= (Window
) m_mainWidget
;
629 XSync(wxGlobalDisplay(), False
);
630 XWindowAttributes attr
;
631 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
639 // We may be faking the client origin. So a window that's really at (0, 30)
640 // may appear (to wxWin apps) to be at (0, 0).
643 wxPoint
pt(GetParent()->GetClientAreaOrigin());
651 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
653 Display
*display
= wxGlobalDisplay();
654 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
655 Window thisWindow
= (Window
) m_mainWidget
;
660 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
663 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
665 Display
*display
= wxGlobalDisplay();
666 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
667 Window thisWindow
= (Window
) m_mainWidget
;
672 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
676 // Get size *available for subwindows* i.e. excluding menu bar etc.
677 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
679 Window window
= (Window
) m_mainWidget
;
683 XSync(wxGlobalDisplay(), False
); // Is this really a good idea?
684 XWindowAttributes attr
;
685 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
696 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
698 Window xwindow
= (Window
) GetMainWindow();
700 wxCHECK_RET( xwindow
, wxT("invalid window") );
702 XWindowAttributes attr
;
703 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
704 wxCHECK_RET( status
, wxT("invalid window attributes") );
708 int new_w
= attr
.width
;
709 int new_h
= attr
.height
;
712 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
715 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
718 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
721 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
737 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
740 void wxWindowX11::DoSetClientSize(int width
, int height
)
742 Window xwindow
= (Window
) GetMainWindow();
744 wxCHECK_RET( xwindow
, wxT("invalid window") );
746 XWindowAttributes attr
;
747 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
748 wxCHECK_RET( status
, wxT("invalid window attributes") );
752 int new_w
= attr
.width
;
753 int new_h
= attr
.height
;
761 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
764 // For implementation purposes - sometimes decorations make the client area
766 wxPoint
wxWindowX11::GetClientAreaOrigin() const
768 return wxPoint(0, 0);
771 // Makes an adjustment to the window position (for example, a frame that has
772 // a toolbar that it manages itself).
773 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
775 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
777 wxPoint
pt(GetParent()->GetClientAreaOrigin());
778 x
+= pt
.x
; y
+= pt
.y
;
782 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
789 XSizeHints sizeHints
;
792 if (minW
> -1 && minH
> -1)
794 sizeHints
.flags
|= PMinSize
;
795 sizeHints
.min_width
= minW
;
796 sizeHints
.min_height
= minH
;
798 if (maxW
> -1 && maxH
> -1)
800 sizeHints
.flags
|= PMaxSize
;
801 sizeHints
.max_width
= maxW
;
802 sizeHints
.max_height
= maxH
;
804 if (incW
> -1 && incH
> -1)
806 sizeHints
.flags
|= PResizeInc
;
807 sizeHints
.width_inc
= incW
;
808 sizeHints
.height_inc
= incH
;
811 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
814 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
816 Window xwindow
= (Window
) GetMainWindow();
818 wxCHECK_RET( xwindow
, wxT("invalid window") );
820 XWindowChanges windowChanges
;
823 windowChanges
.width
= width
;
824 windowChanges
.height
= height
;
825 windowChanges
.stack_mode
= 0;
826 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
828 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
831 // ---------------------------------------------------------------------------
833 // ---------------------------------------------------------------------------
835 int wxWindowX11::GetCharHeight() const
837 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
839 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
841 int direction
, ascent
, descent
;
843 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
846 // return (overall.ascent + overall.descent);
847 return (ascent
+ descent
);
850 int wxWindowX11::GetCharWidth() const
852 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
854 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
856 int direction
, ascent
, descent
;
858 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
861 return overall
.width
;
864 void wxWindowX11::GetTextExtent(const wxString
& string
,
866 int *descent
, int *externalLeading
,
867 const wxFont
*theFont
) const
869 wxFont fontToUse
= m_font
;
870 if (theFont
) fontToUse
= *theFont
;
872 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
874 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
876 int direction
, ascent
, descent2
;
878 int slen
= string
.Len();
882 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
883 &ascent
, &descent2
, &overall
);
886 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
887 &direction
, &ascent
, &descent2
, &overall
);
890 *x
= (overall
.width
);
892 *y
= (ascent
+ descent2
);
896 *externalLeading
= 0;
900 // ----------------------------------------------------------------------------
902 // ----------------------------------------------------------------------------
904 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
910 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
911 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
916 GetSize( &width
, &height
);
918 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
919 m_clearRegion
.Clear();
920 m_clearRegion
.Union( 0, 0, width
, height
);
926 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
927 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
932 GetSize( &width
, &height
);
934 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
935 m_updateRegion
.Clear();
936 m_updateRegion
.Union( 0, 0, width
, height
);
940 void wxWindowX11::Update()
942 if (!m_updateRegion
.IsEmpty())
944 // Actually send erase events.
947 // Actually send paint events.
952 void wxWindowX11::Clear()
954 wxClientDC
dc((wxWindow
*) this);
955 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
956 dc
.SetBackground(brush
);
960 void wxWindowX11::SendEraseEvents()
962 if (!m_clearRegion
.IsEmpty())
964 m_clipPaintRegion
= TRUE
;
966 wxWindowDC
dc( (wxWindow
*)this );
967 dc
.SetClippingRegion( m_clearRegion
);
969 wxEraseEvent
erase_event( GetId(), &dc
);
970 erase_event
.SetEventObject( this );
972 if (!GetEventHandler()->ProcessEvent(erase_event
))
974 Window xwindow
= (Window
) GetMainWindow();
975 Display
*xdisplay
= wxGlobalDisplay();
976 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
977 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
978 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
979 wxRegionIterator
upd( m_clearRegion
);
982 XFillRectangle( xdisplay
, xwindow
, xgc
,
983 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
986 XFreeGC( xdisplay
, xgc
);
988 m_clearRegion
.Clear();
990 m_clipPaintRegion
= FALSE
;
995 void wxWindowX11::SendPaintEvents()
997 m_clipPaintRegion
= TRUE
;
999 wxNcPaintEvent
nc_paint_event( GetId() );
1000 nc_paint_event
.SetEventObject( this );
1001 GetEventHandler()->ProcessEvent( nc_paint_event
);
1003 wxPaintEvent
paint_event( GetId() );
1004 paint_event
.SetEventObject( this );
1005 GetEventHandler()->ProcessEvent( paint_event
);
1007 m_updateRegion
.Clear();
1009 m_clipPaintRegion
= FALSE
;
1012 // ----------------------------------------------------------------------------
1014 // ----------------------------------------------------------------------------
1016 // Responds to colour changes: passes event on to children.
1017 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1019 wxWindowList::Node
*node
= GetChildren().GetFirst();
1022 // Only propagate to non-top-level windows
1023 wxWindow
*win
= node
->GetData();
1024 if ( win
->GetParent() )
1026 wxSysColourChangedEvent event2
;
1027 event
.m_eventObject
= win
;
1028 win
->GetEventHandler()->ProcessEvent(event2
);
1031 node
= node
->GetNext();
1035 void wxWindowX11::OnInternalIdle()
1037 // Update invalidated regions.
1040 // This calls the UI-update mechanism (querying windows for
1041 // menu/toolbar/control state information)
1044 // Set the input focus if couldn't do it before
1045 if (m_needsInputFocus
)
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 // ----------------------------------------------------------------------------
1279 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1281 wxWindowBase::SetBackgroundColour(col
);
1283 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1284 int xscreen
= DefaultScreen( xdisplay
);
1285 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1287 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1289 if (!GetMainWindow())
1293 XSetWindowAttributes attrib;
1294 attrib.background_pixel = colour.GetPixel();
1296 XChangeWindowAttributes(wxGlobalDisplay(),
1297 (Window) GetMainWindow(),
1305 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1307 if ( !wxWindowBase::SetForegroundColour(col
) )
1313 // ----------------------------------------------------------------------------
1315 // ----------------------------------------------------------------------------
1317 wxWindow
*wxGetActiveWindow()
1320 wxFAIL_MSG("Not implemented");
1325 wxWindow
*wxWindowBase::GetCapture()
1327 return (wxWindow
*)g_captureWindow
;
1331 // Find the wxWindow at the current mouse position, returning the mouse
1333 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1335 return wxFindWindowAtPoint(wxGetMousePosition());
1338 // Get the current mouse position.
1339 wxPoint
wxGetMousePosition()
1341 Display
*display
= wxGlobalDisplay();
1342 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1343 Window rootReturn
, childReturn
;
1344 int rootX
, rootY
, winX
, winY
;
1345 unsigned int maskReturn
;
1347 XQueryPointer (display
,
1351 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1352 return wxPoint(rootX
, rootY
);
1356 // ----------------------------------------------------------------------------
1357 // wxNoOptimize: switch off size optimization
1358 // ----------------------------------------------------------------------------
1360 int wxNoOptimize::ms_count
= 0;