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
);
419 wxLogDebug("Ungrabbed pointer");
421 m_winCaptured
= FALSE
;
424 bool wxWindowX11::SetFont(const wxFont
& font
)
426 if ( !wxWindowBase::SetFont(font
) )
435 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
437 if ( !wxWindowBase::SetCursor(cursor
) )
443 Window xwindow
= (Window
) GetMainWindow();
445 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
447 wxCursor cursorToUse
;
449 cursorToUse
= m_cursor
;
451 cursorToUse
= *wxSTANDARD_CURSOR
;
453 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
455 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
460 // Coordinates relative to the window
461 void wxWindowX11::WarpPointer (int x
, int y
)
463 Window xwindow
= (Window
) GetMainWindow();
465 wxCHECK_RET( xwindow
, wxT("invalid window") );
467 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
470 // Does a physical scroll
471 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
473 // No scrolling requested.
474 if ((dx
== 0) && (dy
== 0)) return;
476 if (!m_updateRegion
.IsEmpty())
478 m_updateRegion
.Offset( dx
, dy
);
482 GetSize( &cw
, &ch
); // GetClientSize() ??
483 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
486 if (!m_clearRegion
.IsEmpty())
488 m_clearRegion
.Offset( dx
, dy
);
492 GetSize( &cw
, &ch
); // GetClientSize() ??
493 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
496 Window xwindow
= (Window
) GetMainWindow();
498 wxCHECK_RET( xwindow
, wxT("invalid window") );
500 Display
*xdisplay
= wxGlobalDisplay();
502 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
503 XSetGraphicsExposures( xdisplay
, xgc
, True
);
520 GetClientSize( &cw
, &ch
);
523 wxPoint offset
= GetClientAreaOrigin();
527 int w
= cw
- abs(dx
);
528 int h
= ch
- abs(dy
);
530 if ((h
< 0) || (w
< 0))
537 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
538 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
539 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
540 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
544 if (dx
< 0) s_x
+= -dx
;
545 if (dy
< 0) s_y
+= -dy
;
546 if (dx
> 0) d_x
= dx
;
547 if (dy
> 0) d_y
= dy
;
549 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
551 // 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 );
553 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
555 m_updateRegion
.Union( rect
);
556 m_clearRegion
.Union( rect
);
559 XFreeGC( xdisplay
, xgc
);
562 // ---------------------------------------------------------------------------
564 // ---------------------------------------------------------------------------
566 #if wxUSE_DRAG_AND_DROP
568 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
575 // Old style file-manager drag&drop
576 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
581 // ----------------------------------------------------------------------------
583 // ----------------------------------------------------------------------------
587 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
592 #endif // wxUSE_TOOLTIPS
594 // ---------------------------------------------------------------------------
595 // moving and resizing
596 // ---------------------------------------------------------------------------
598 bool wxWindowX11::PreResize()
604 void wxWindowX11::DoGetSize(int *x
, int *y
) const
606 Window xwindow
= (Window
) GetMainWindow();
608 wxCHECK_RET( xwindow
, wxT("invalid window") );
610 XSync(wxGlobalDisplay(), False
);
612 XWindowAttributes attr
;
613 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
618 *x
= attr
.width
/* + 2*m_borderSize */ ;
619 *y
= attr
.height
/* + 2*m_borderSize */ ;
623 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
625 Window window
= (Window
) m_mainWidget
;
628 XSync(wxGlobalDisplay(), False
);
629 XWindowAttributes attr
;
630 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
638 // We may be faking the client origin. So a window that's really at (0, 30)
639 // may appear (to wxWin apps) to be at (0, 0).
642 wxPoint
pt(GetParent()->GetClientAreaOrigin());
650 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
652 Display
*display
= wxGlobalDisplay();
653 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
654 Window thisWindow
= (Window
) m_mainWidget
;
659 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
662 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
664 Display
*display
= wxGlobalDisplay();
665 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
666 Window thisWindow
= (Window
) m_mainWidget
;
671 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
675 // Get size *available for subwindows* i.e. excluding menu bar etc.
676 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
678 Window window
= (Window
) m_mainWidget
;
682 XSync(wxGlobalDisplay(), False
); // Is this really a good idea?
683 XWindowAttributes attr
;
684 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
695 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
697 Window xwindow
= (Window
) GetMainWindow();
699 wxCHECK_RET( xwindow
, wxT("invalid window") );
701 XWindowAttributes attr
;
702 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
703 wxCHECK_RET( status
, wxT("invalid window attributes") );
707 int new_w
= attr
.width
;
708 int new_h
= attr
.height
;
711 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
714 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
717 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
720 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
736 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
739 void wxWindowX11::DoSetClientSize(int width
, int height
)
741 Window xwindow
= (Window
) GetMainWindow();
743 wxCHECK_RET( xwindow
, wxT("invalid window") );
745 XWindowAttributes attr
;
746 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
747 wxCHECK_RET( status
, wxT("invalid window attributes") );
751 int new_w
= attr
.width
;
752 int new_h
= attr
.height
;
760 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
763 // For implementation purposes - sometimes decorations make the client area
765 wxPoint
wxWindowX11::GetClientAreaOrigin() const
767 return wxPoint(0, 0);
770 // Makes an adjustment to the window position (for example, a frame that has
771 // a toolbar that it manages itself).
772 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
774 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
776 wxPoint
pt(GetParent()->GetClientAreaOrigin());
777 x
+= pt
.x
; y
+= pt
.y
;
781 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
788 XSizeHints sizeHints
;
791 if (minW
> -1 && minH
> -1)
793 sizeHints
.flags
|= PMinSize
;
794 sizeHints
.min_width
= minW
;
795 sizeHints
.min_height
= minH
;
797 if (maxW
> -1 && maxH
> -1)
799 sizeHints
.flags
|= PMaxSize
;
800 sizeHints
.max_width
= maxW
;
801 sizeHints
.max_height
= maxH
;
803 if (incW
> -1 && incH
> -1)
805 sizeHints
.flags
|= PResizeInc
;
806 sizeHints
.width_inc
= incW
;
807 sizeHints
.height_inc
= incH
;
810 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
813 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
815 Window xwindow
= (Window
) GetMainWindow();
817 wxCHECK_RET( xwindow
, wxT("invalid window") );
819 XWindowChanges windowChanges
;
822 windowChanges
.width
= width
;
823 windowChanges
.height
= height
;
824 windowChanges
.stack_mode
= 0;
825 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
827 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
830 // ---------------------------------------------------------------------------
832 // ---------------------------------------------------------------------------
834 int wxWindowX11::GetCharHeight() const
836 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
838 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
840 int direction
, ascent
, descent
;
842 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
845 // return (overall.ascent + overall.descent);
846 return (ascent
+ descent
);
849 int wxWindowX11::GetCharWidth() const
851 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
853 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
855 int direction
, ascent
, descent
;
857 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
860 return overall
.width
;
863 void wxWindowX11::GetTextExtent(const wxString
& string
,
865 int *descent
, int *externalLeading
,
866 const wxFont
*theFont
) const
868 wxFont fontToUse
= m_font
;
869 if (theFont
) fontToUse
= *theFont
;
871 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
873 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
875 int direction
, ascent
, descent2
;
877 int slen
= string
.Len();
881 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
882 &ascent
, &descent2
, &overall
);
885 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
886 &direction
, &ascent
, &descent2
, &overall
);
889 *x
= (overall
.width
);
891 *y
= (ascent
+ descent2
);
895 *externalLeading
= 0;
899 // ----------------------------------------------------------------------------
901 // ----------------------------------------------------------------------------
903 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
909 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
910 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
915 GetSize( &width
, &height
);
917 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
918 m_clearRegion
.Clear();
919 m_clearRegion
.Union( 0, 0, width
, height
);
925 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
926 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
931 GetSize( &width
, &height
);
933 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
934 m_updateRegion
.Clear();
935 m_updateRegion
.Union( 0, 0, width
, height
);
939 void wxWindowX11::Update()
941 if (!m_updateRegion
.IsEmpty())
943 // Actually send erase and paint events.
944 X11SendPaintEvents();
948 void wxWindowX11::Clear()
950 wxClientDC
dc((wxWindow
*) this);
951 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
952 dc
.SetBackground(brush
);
956 void wxWindowX11::X11SendPaintEvents()
958 m_clipPaintRegion
= TRUE
;
960 if (!m_clearRegion
.IsEmpty())
962 wxWindowDC
dc( (wxWindow
*)this );
963 dc
.SetClippingRegion( m_clearRegion
);
965 wxEraseEvent
erase_event( GetId(), &dc
);
966 erase_event
.SetEventObject( this );
968 if (!GetEventHandler()->ProcessEvent(erase_event
))
970 Window xwindow
= (Window
) GetMainWindow();
971 Display
*xdisplay
= wxGlobalDisplay();
972 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
973 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
974 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
975 wxRegionIterator
upd( m_clearRegion
);
978 XFillRectangle( xdisplay
, xwindow
, xgc
,
979 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
982 XFreeGC( xdisplay
, xgc
);
984 m_clearRegion
.Clear();
987 wxNcPaintEvent
nc_paint_event( GetId() );
988 nc_paint_event
.SetEventObject( this );
989 GetEventHandler()->ProcessEvent( nc_paint_event
);
991 wxPaintEvent
paint_event( GetId() );
992 paint_event
.SetEventObject( this );
993 GetEventHandler()->ProcessEvent( paint_event
);
995 m_updateRegion
.Clear();
997 m_clipPaintRegion
= FALSE
;
1000 // ----------------------------------------------------------------------------
1002 // ----------------------------------------------------------------------------
1004 // Responds to colour changes: passes event on to children.
1005 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1007 wxWindowList::Node
*node
= GetChildren().GetFirst();
1010 // Only propagate to non-top-level windows
1011 wxWindow
*win
= node
->GetData();
1012 if ( win
->GetParent() )
1014 wxSysColourChangedEvent event2
;
1015 event
.m_eventObject
= win
;
1016 win
->GetEventHandler()->ProcessEvent(event2
);
1019 node
= node
->GetNext();
1023 void wxWindowX11::OnInternalIdle()
1025 // Update invalidated regions.
1028 // This calls the UI-update mechanism (querying windows for
1029 // menu/toolbar/control state information)
1032 // Set the input focus if couldn't do it before
1033 if (m_needsInputFocus
)
1037 // ----------------------------------------------------------------------------
1038 // function which maintain the global hash table mapping Widgets to wxWindows
1039 // ----------------------------------------------------------------------------
1041 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1043 wxWindow
*oldItem
= NULL
;
1044 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1046 wxLogDebug("Widget table clash: new widget is %ld, %s",
1047 (long)w
, win
->GetClassInfo()->GetClassName());
1051 wxWidgetHashTable
->Put((long) w
, win
);
1053 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1054 w
, win
, win
->GetClassInfo()->GetClassName());
1059 wxWindow
*wxGetWindowFromTable(Window w
)
1061 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1064 void wxDeleteWindowFromTable(Window w
)
1066 wxWidgetHashTable
->Delete((long)w
);
1069 // ----------------------------------------------------------------------------
1070 // add/remove window from the table
1071 // ----------------------------------------------------------------------------
1073 // ----------------------------------------------------------------------------
1074 // X11-specific accessors
1075 // ----------------------------------------------------------------------------
1077 // Get the underlying X window
1078 WXWindow
wxWindowX11::GetXWindow() const
1080 return GetMainWindow();
1083 // Get the underlying X display
1084 WXDisplay
*wxWindowX11::GetXDisplay() const
1086 return wxGetDisplay();
1089 WXWindow
wxWindowX11::GetMainWindow() const
1091 return m_mainWidget
;
1094 // ----------------------------------------------------------------------------
1095 // TranslateXXXEvent() functions
1096 // ----------------------------------------------------------------------------
1098 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1100 switch (xevent
->xany
.type
)
1108 wxEventType eventType
= wxEVT_NULL
;
1110 if (xevent
->xany
.type
== EnterNotify
)
1112 //if (local_event.xcrossing.mode!=NotifyNormal)
1113 // return ; // Ignore grab events
1114 eventType
= wxEVT_ENTER_WINDOW
;
1115 // canvas->GetEventHandler()->OnSetFocus();
1117 else if (xevent
->xany
.type
== LeaveNotify
)
1119 //if (local_event.xcrossingr.mode!=NotifyNormal)
1120 // return ; // Ignore grab events
1121 eventType
= wxEVT_LEAVE_WINDOW
;
1122 // canvas->GetEventHandler()->OnKillFocus();
1124 else if (xevent
->xany
.type
== MotionNotify
)
1126 eventType
= wxEVT_MOTION
;
1128 else if (xevent
->xany
.type
== ButtonPress
)
1130 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1132 if (xevent
->xbutton
.button
== Button1
)
1134 eventType
= wxEVT_LEFT_DOWN
;
1137 else if (xevent
->xbutton
.button
== Button2
)
1139 eventType
= wxEVT_MIDDLE_DOWN
;
1142 else if (xevent
->xbutton
.button
== Button3
)
1144 eventType
= wxEVT_RIGHT_DOWN
;
1148 // check for a double click
1149 // TODO: where can we get this value from?
1150 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1151 long dclickTime
= 200;
1152 long ts
= wxevent
.GetTimestamp();
1154 int buttonLast
= win
->GetLastClickedButton();
1155 long lastTS
= win
->GetLastClickTime();
1156 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1159 win
->SetLastClick(0, ts
);
1160 if ( eventType
== wxEVT_LEFT_DOWN
)
1161 eventType
= wxEVT_LEFT_DCLICK
;
1162 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1163 eventType
= wxEVT_MIDDLE_DCLICK
;
1164 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1165 eventType
= wxEVT_RIGHT_DCLICK
;
1169 // not fast enough or different button
1170 win
->SetLastClick(button
, ts
);
1173 else if (xevent
->xany
.type
== ButtonRelease
)
1175 if (xevent
->xbutton
.button
== Button1
)
1177 eventType
= wxEVT_LEFT_UP
;
1179 else if (xevent
->xbutton
.button
== Button2
)
1181 eventType
= wxEVT_MIDDLE_UP
;
1183 else if (xevent
->xbutton
.button
== Button3
)
1185 eventType
= wxEVT_RIGHT_UP
;
1194 wxevent
.SetEventType(eventType
);
1196 wxevent
.m_x
= xevent
->xbutton
.x
;
1197 wxevent
.m_y
= xevent
->xbutton
.y
;
1199 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1200 || (event_left_is_down (xevent
)
1201 && (eventType
!= wxEVT_LEFT_UP
)));
1202 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1203 || (event_middle_is_down (xevent
)
1204 && (eventType
!= wxEVT_MIDDLE_UP
)));
1205 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1206 || (event_right_is_down (xevent
)
1207 && (eventType
!= wxEVT_RIGHT_UP
)));
1209 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1210 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1211 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1212 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1214 wxevent
.SetId(win
->GetId());
1215 wxevent
.SetEventObject(win
);
1223 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1225 switch (xevent
->xany
.type
)
1233 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1234 int id
= wxCharCodeXToWX (keySym
);
1236 if (xevent
->xkey
.state
& ShiftMask
)
1237 wxevent
.m_shiftDown
= TRUE
;
1238 if (xevent
->xkey
.state
& ControlMask
)
1239 wxevent
.m_controlDown
= TRUE
;
1240 if (xevent
->xkey
.state
& Mod3Mask
)
1241 wxevent
.m_altDown
= TRUE
;
1242 if (xevent
->xkey
.state
& Mod1Mask
)
1243 wxevent
.m_metaDown
= TRUE
;
1244 wxevent
.SetEventObject(win
);
1245 wxevent
.m_keyCode
= id
;
1246 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1248 wxevent
.m_x
= xevent
->xbutton
.x
;
1249 wxevent
.m_y
= xevent
->xbutton
.y
;
1263 // ----------------------------------------------------------------------------
1265 // ----------------------------------------------------------------------------
1267 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1269 wxWindowBase::SetBackgroundColour(col
);
1271 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1272 int xscreen
= DefaultScreen( xdisplay
);
1273 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1275 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1277 if (!GetMainWindow())
1281 XSetWindowAttributes attrib;
1282 attrib.background_pixel = colour.GetPixel();
1284 XChangeWindowAttributes(wxGlobalDisplay(),
1285 (Window) GetMainWindow(),
1293 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1295 if ( !wxWindowBase::SetForegroundColour(col
) )
1301 // ----------------------------------------------------------------------------
1303 // ----------------------------------------------------------------------------
1305 wxWindow
*wxGetActiveWindow()
1308 wxFAIL_MSG("Not implemented");
1313 wxWindow
*wxWindowBase::GetCapture()
1315 return (wxWindow
*)g_captureWindow
;
1319 // Find the wxWindow at the current mouse position, returning the mouse
1321 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1323 return wxFindWindowAtPoint(wxGetMousePosition());
1326 // Get the current mouse position.
1327 wxPoint
wxGetMousePosition()
1329 Display
*display
= wxGlobalDisplay();
1330 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1331 Window rootReturn
, childReturn
;
1332 int rootX
, rootY
, winX
, winY
;
1333 unsigned int maskReturn
;
1335 XQueryPointer (display
,
1339 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1340 return wxPoint(rootX
, rootY
);
1344 // ----------------------------------------------------------------------------
1345 // wxNoOptimize: switch off size optimization
1346 // ----------------------------------------------------------------------------
1348 int wxNoOptimize::ms_count
= 0;