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
);
133 m_foregroundColour
= *wxBLACK
;
134 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
136 Window parentWindow
= (Window
) parent
->GetMainWindow();
150 Window xwindow
= XCreateSimpleWindow(
151 xdisplay
, parentWindow
,
152 pos2
.x
, pos2
.y
, size2
.x
, size2
.y
, 0,
153 m_backgroundColour
.GetPixel(),
154 m_backgroundColour
.GetPixel() );
156 m_mainWidget
= (WXWindow
) xwindow
;
158 // Select event types wanted
159 XSelectInput( xdisplay
, xwindow
,
160 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
161 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
162 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
165 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
167 // Is a subwindow, so map immediately
169 XMapWindow( xdisplay
, xwindow
);
171 // Without this, the cursor may not be restored properly (e.g. in splitter
173 SetCursor(*wxSTANDARD_CURSOR
);
174 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
176 // Set background to None which will prevent X11 from clearing the
177 // background comletely.
178 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
180 // Don't call this, it can have nasty repercussions for composite controls,
182 // SetSize(pos.x, pos.y, size.x, size.y);
188 wxWindowX11::~wxWindowX11()
190 if (g_captureWindow
== this)
191 g_captureWindow
= NULL
;
193 m_isBeingDeleted
= TRUE
;
195 // X11-specific actions first
196 Window main
= (Window
) m_mainWidget
;
199 // Removes event handlers
200 //DetachWidget(main);
204 m_parent
->RemoveChild( this );
208 // Destroy the window
211 XSelectInput( wxGlobalDisplay(), main
, NoEventMask
);
212 wxDeleteWindowFromTable( main
);
213 XDestroyWindow( wxGlobalDisplay(), main
);
218 // ---------------------------------------------------------------------------
220 // ---------------------------------------------------------------------------
222 void wxWindowX11::SetFocus()
224 Window xwindow
= (Window
) GetMainWindow();
226 wxCHECK_RET( xwindow
, wxT("invalid window") );
228 if (wxWindowIsVisible(xwindow
))
230 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
231 m_needsInputFocus
= FALSE
;
235 m_needsInputFocus
= TRUE
;
239 // Get the window with the focus
240 wxWindow
*wxWindowBase::FindFocus()
242 Window xfocus
= (Window
) 0;
245 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
248 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
;
271 // Enabling/disabling handled by event loop, and not sending events
273 bool wxWindowX11::Enable(bool enable
)
275 if ( !wxWindowBase::Enable(enable
) )
281 bool wxWindowX11::Show(bool show
)
283 wxWindowBase::Show(show
);
285 Window xwin
= (Window
) GetXWindow();
286 Display
*xdisp
= (Display
*) GetXDisplay();
290 msg
.Printf("Mapping window of type %s", GetClassInfo()->GetClassName());
292 XMapWindow(xdisp
, xwin
);
298 msg
.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName());
300 XUnmapWindow(xdisp
, xwin
);
306 // Raise the window to the top of the Z order
307 void wxWindowX11::Raise()
310 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
313 // Lower the window to the bottom of the Z order
314 void wxWindowX11::Lower()
317 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
320 void wxWindowX11::DoCaptureMouse()
322 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
324 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
335 Window xwindow
= (Window
) GetMainWindow();
337 wxCHECK_RET( xwindow
, wxT("invalid window") );
339 g_captureWindow
= (wxWindow
*) this;
343 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
345 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
349 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
352 if (res
!= GrabSuccess
)
355 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
357 if (res
== GrabNotViewable
)
359 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
361 g_captureWindow
= NULL
;
365 wxLogDebug("Grabbed pointer");
368 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
369 (Window
) GetMainWindow(),
371 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
377 if (res
!= GrabSuccess
)
379 wxLogDebug("Failed to grab mouse buttons.");
380 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
386 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
387 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
393 if (res
!= GrabSuccess
)
395 wxLogDebug("Failed to grab keyboard.");
396 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
397 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
398 (Window
) GetMainWindow());
403 m_winCaptured
= TRUE
;
407 void wxWindowX11::DoReleaseMouse()
409 g_captureWindow
= NULL
;
411 if ( !m_winCaptured
)
414 Window xwindow
= (Window
) GetMainWindow();
418 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
420 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
421 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
424 wxLogDebug("Ungrabbed pointer");
426 m_winCaptured
= FALSE
;
429 bool wxWindowX11::SetFont(const wxFont
& font
)
431 if ( !wxWindowBase::SetFont(font
) )
440 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
442 if ( !wxWindowBase::SetCursor(cursor
) )
448 Window xwindow
= (Window
) GetMainWindow();
450 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
452 wxCursor cursorToUse
;
454 cursorToUse
= m_cursor
;
456 cursorToUse
= *wxSTANDARD_CURSOR
;
458 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
460 XDefineCursor( (Display
*) wxGlobalDisplay(), xwindow
, xcursor
);
465 // Coordinates relative to the window
466 void wxWindowX11::WarpPointer (int x
, int y
)
468 Window xwindow
= (Window
) GetMainWindow();
470 wxCHECK_RET( xwindow
, wxT("invalid window") );
472 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
475 // Does a physical scroll
476 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
478 // No scrolling requested.
479 if ((dx
== 0) && (dy
== 0)) return;
481 if (!m_updateRegion
.IsEmpty())
483 m_updateRegion
.Offset( dx
, dy
);
487 GetSize( &cw
, &ch
); // GetClientSize() ??
488 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
491 if (!m_clearRegion
.IsEmpty())
493 m_clearRegion
.Offset( dx
, dy
);
497 GetSize( &cw
, &ch
); // GetClientSize() ??
498 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
501 Window xwindow
= (Window
) GetMainWindow();
503 wxCHECK_RET( xwindow
, wxT("invalid window") );
505 Display
*xdisplay
= wxGlobalDisplay();
507 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
508 XSetGraphicsExposures( xdisplay
, xgc
, True
);
525 GetClientSize( &cw
, &ch
);
528 wxPoint offset
= GetClientAreaOrigin();
532 int w
= cw
- abs(dx
);
533 int h
= ch
- abs(dy
);
535 if ((h
< 0) || (w
< 0))
542 if (dx
< 0) rect
.x
= cw
+dx
; else rect
.x
= s_x
;
543 if (dy
< 0) rect
.y
= ch
+dy
; else rect
.y
= s_y
;
544 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
545 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
549 if (dx
< 0) s_x
+= -dx
;
550 if (dy
< 0) s_y
+= -dy
;
551 if (dx
> 0) d_x
= dx
;
552 if (dy
> 0) d_y
= dy
;
554 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
556 // 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 );
558 // printf( "rect %d %d %d %d\n", rect.x, rect.y, rect.width, rect.height );
560 m_updateRegion
.Union( rect
);
561 m_clearRegion
.Union( rect
);
564 XFreeGC( xdisplay
, xgc
);
567 // ---------------------------------------------------------------------------
569 // ---------------------------------------------------------------------------
571 #if wxUSE_DRAG_AND_DROP
573 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
580 // Old style file-manager drag&drop
581 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
586 // ----------------------------------------------------------------------------
588 // ----------------------------------------------------------------------------
592 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
597 #endif // wxUSE_TOOLTIPS
599 // ---------------------------------------------------------------------------
600 // moving and resizing
601 // ---------------------------------------------------------------------------
603 bool wxWindowX11::PreResize()
609 void wxWindowX11::DoGetSize(int *x
, int *y
) const
611 Window xwindow
= (Window
) GetMainWindow();
613 wxCHECK_RET( xwindow
, wxT("invalid window") );
615 XSync(wxGlobalDisplay(), False
);
616 XWindowAttributes attr
;
617 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
622 *x
= attr
.width
/* + 2*m_borderSize */ ;
623 *y
= attr
.height
/* + 2*m_borderSize */ ;
627 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
629 Window window
= (Window
) m_mainWidget
;
632 XSync(wxGlobalDisplay(), False
);
633 XWindowAttributes attr
;
634 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
642 // We may be faking the client origin. So a window that's really at (0, 30)
643 // may appear (to wxWin apps) to be at (0, 0).
646 wxPoint
pt(GetParent()->GetClientAreaOrigin());
654 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
656 Display
*display
= wxGlobalDisplay();
657 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
658 Window thisWindow
= (Window
) m_mainWidget
;
663 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
666 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
668 Display
*display
= wxGlobalDisplay();
669 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
670 Window thisWindow
= (Window
) m_mainWidget
;
675 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
679 // Get size *available for subwindows* i.e. excluding menu bar etc.
680 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
682 Window window
= (Window
) m_mainWidget
;
686 XSync(wxGlobalDisplay(), False
); // Is this really a good idea?
687 XWindowAttributes attr
;
688 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
699 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
701 Window xwindow
= (Window
) GetMainWindow();
703 wxCHECK_RET( xwindow
, wxT("invalid window") );
705 XWindowAttributes attr
;
706 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
707 wxCHECK_RET( status
, wxT("invalid window attributes") );
711 int new_w
= attr
.width
;
712 int new_h
= attr
.height
;
715 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
718 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
721 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
724 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
740 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
743 void wxWindowX11::DoSetClientSize(int width
, int height
)
745 Window xwindow
= (Window
) GetMainWindow();
747 wxCHECK_RET( xwindow
, wxT("invalid window") );
749 XWindowAttributes attr
;
750 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
751 wxCHECK_RET( status
, wxT("invalid window attributes") );
755 int new_w
= attr
.width
;
756 int new_h
= attr
.height
;
764 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
767 // For implementation purposes - sometimes decorations make the client area
769 wxPoint
wxWindowX11::GetClientAreaOrigin() const
771 return wxPoint(0, 0);
774 // Makes an adjustment to the window position (for example, a frame that has
775 // a toolbar that it manages itself).
776 void wxWindowX11::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
778 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
780 wxPoint
pt(GetParent()->GetClientAreaOrigin());
781 x
+= pt
.x
; y
+= pt
.y
;
785 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
792 XSizeHints sizeHints
;
795 if (minW
> -1 && minH
> -1)
797 sizeHints
.flags
|= PMinSize
;
798 sizeHints
.min_width
= minW
;
799 sizeHints
.min_height
= minH
;
801 if (maxW
> -1 && maxH
> -1)
803 sizeHints
.flags
|= PMaxSize
;
804 sizeHints
.max_width
= maxW
;
805 sizeHints
.max_height
= maxH
;
807 if (incW
> -1 && incH
> -1)
809 sizeHints
.flags
|= PResizeInc
;
810 sizeHints
.width_inc
= incW
;
811 sizeHints
.height_inc
= incH
;
814 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
817 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
819 Window xwindow
= (Window
) GetMainWindow();
821 wxCHECK_RET( xwindow
, wxT("invalid window") );
823 XWindowChanges windowChanges
;
826 windowChanges
.width
= width
;
827 windowChanges
.height
= height
;
828 windowChanges
.stack_mode
= 0;
829 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
831 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
834 // ---------------------------------------------------------------------------
836 // ---------------------------------------------------------------------------
838 int wxWindowX11::GetCharHeight() const
840 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
842 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
844 int direction
, ascent
, descent
;
846 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
849 // return (overall.ascent + overall.descent);
850 return (ascent
+ descent
);
853 int wxWindowX11::GetCharWidth() const
855 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
857 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
859 int direction
, ascent
, descent
;
861 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
864 return overall
.width
;
867 void wxWindowX11::GetTextExtent(const wxString
& string
,
869 int *descent
, int *externalLeading
,
870 const wxFont
*theFont
) const
872 wxFont fontToUse
= m_font
;
873 if (theFont
) fontToUse
= *theFont
;
875 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
877 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
879 int direction
, ascent
, descent2
;
881 int slen
= string
.Len();
885 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
886 &ascent
, &descent2
, &overall
);
889 XTextExtents((XFontStruct
*) pFontStruct
, string
.c_str(), slen
,
890 &direction
, &ascent
, &descent2
, &overall
);
893 *x
= (overall
.width
);
895 *y
= (ascent
+ descent2
);
899 *externalLeading
= 0;
903 // ----------------------------------------------------------------------------
905 // ----------------------------------------------------------------------------
907 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
913 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
914 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
919 GetSize( &width
, &height
);
921 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
922 m_clearRegion
.Clear();
923 m_clearRegion
.Union( 0, 0, width
, height
);
929 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
930 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
935 GetSize( &width
, &height
);
937 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
938 m_updateRegion
.Clear();
939 m_updateRegion
.Union( 0, 0, width
, height
);
943 void wxWindowX11::Update()
945 if (!m_updateRegion
.IsEmpty())
947 // Actually send erase and paint events.
948 X11SendPaintEvents();
952 void wxWindowX11::Clear()
954 wxClientDC
dc((wxWindow
*) this);
955 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
956 dc
.SetBackground(brush
);
960 void wxWindowX11::X11SendPaintEvents()
962 m_clipPaintRegion
= TRUE
;
964 if (!m_clearRegion
.IsEmpty())
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();
991 wxNcPaintEvent
nc_paint_event( GetId() );
992 nc_paint_event
.SetEventObject( this );
993 GetEventHandler()->ProcessEvent( nc_paint_event
);
995 wxPaintEvent
paint_event( GetId() );
996 paint_event
.SetEventObject( this );
997 GetEventHandler()->ProcessEvent( paint_event
);
999 m_updateRegion
.Clear();
1001 m_clipPaintRegion
= FALSE
;
1004 // ----------------------------------------------------------------------------
1006 // ----------------------------------------------------------------------------
1008 // Responds to colour changes: passes event on to children.
1009 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1011 wxWindowList::Node
*node
= GetChildren().GetFirst();
1014 // Only propagate to non-top-level windows
1015 wxWindow
*win
= node
->GetData();
1016 if ( win
->GetParent() )
1018 wxSysColourChangedEvent event2
;
1019 event
.m_eventObject
= win
;
1020 win
->GetEventHandler()->ProcessEvent(event2
);
1023 node
= node
->GetNext();
1027 void wxWindowX11::OnInternalIdle()
1029 // Update invalidated regions.
1032 // This calls the UI-update mechanism (querying windows for
1033 // menu/toolbar/control state information)
1036 // Set the input focus if couldn't do it before
1037 if (m_needsInputFocus
)
1041 // ----------------------------------------------------------------------------
1042 // function which maintain the global hash table mapping Widgets to wxWindows
1043 // ----------------------------------------------------------------------------
1045 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1047 wxWindow
*oldItem
= NULL
;
1048 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1050 wxLogDebug("Widget table clash: new widget is %ld, %s",
1051 (long)w
, win
->GetClassInfo()->GetClassName());
1055 wxWidgetHashTable
->Put((long) w
, win
);
1057 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1058 w
, win
, win
->GetClassInfo()->GetClassName());
1063 wxWindow
*wxGetWindowFromTable(Window w
)
1065 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1068 void wxDeleteWindowFromTable(Window w
)
1070 wxWidgetHashTable
->Delete((long)w
);
1073 // ----------------------------------------------------------------------------
1074 // add/remove window from the table
1075 // ----------------------------------------------------------------------------
1077 // ----------------------------------------------------------------------------
1078 // X11-specific accessors
1079 // ----------------------------------------------------------------------------
1081 // Get the underlying X window
1082 WXWindow
wxWindowX11::GetXWindow() const
1084 return GetMainWindow();
1087 // Get the underlying X display
1088 WXDisplay
*wxWindowX11::GetXDisplay() const
1090 return wxGetDisplay();
1093 WXWindow
wxWindowX11::GetMainWindow() const
1095 return m_mainWidget
;
1098 // ----------------------------------------------------------------------------
1099 // TranslateXXXEvent() functions
1100 // ----------------------------------------------------------------------------
1102 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1104 switch (xevent
->xany
.type
)
1112 wxEventType eventType
= wxEVT_NULL
;
1114 if (xevent
->xany
.type
== EnterNotify
)
1116 //if (local_event.xcrossing.mode!=NotifyNormal)
1117 // return ; // Ignore grab events
1118 eventType
= wxEVT_ENTER_WINDOW
;
1119 // canvas->GetEventHandler()->OnSetFocus();
1121 else if (xevent
->xany
.type
== LeaveNotify
)
1123 //if (local_event.xcrossingr.mode!=NotifyNormal)
1124 // return ; // Ignore grab events
1125 eventType
= wxEVT_LEAVE_WINDOW
;
1126 // canvas->GetEventHandler()->OnKillFocus();
1128 else if (xevent
->xany
.type
== MotionNotify
)
1130 eventType
= wxEVT_MOTION
;
1132 else if (xevent
->xany
.type
== ButtonPress
)
1134 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
1136 if (xevent
->xbutton
.button
== Button1
)
1138 eventType
= wxEVT_LEFT_DOWN
;
1141 else if (xevent
->xbutton
.button
== Button2
)
1143 eventType
= wxEVT_MIDDLE_DOWN
;
1146 else if (xevent
->xbutton
.button
== Button3
)
1148 eventType
= wxEVT_RIGHT_DOWN
;
1152 // check for a double click
1153 // TODO: where can we get this value from?
1154 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1155 long dclickTime
= 200;
1156 long ts
= wxevent
.GetTimestamp();
1158 int buttonLast
= win
->GetLastClickedButton();
1159 long lastTS
= win
->GetLastClickTime();
1160 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1163 win
->SetLastClick(0, ts
);
1164 if ( eventType
== wxEVT_LEFT_DOWN
)
1165 eventType
= wxEVT_LEFT_DCLICK
;
1166 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1167 eventType
= wxEVT_MIDDLE_DCLICK
;
1168 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1169 eventType
= wxEVT_RIGHT_DCLICK
;
1173 // not fast enough or different button
1174 win
->SetLastClick(button
, ts
);
1177 else if (xevent
->xany
.type
== ButtonRelease
)
1179 if (xevent
->xbutton
.button
== Button1
)
1181 eventType
= wxEVT_LEFT_UP
;
1183 else if (xevent
->xbutton
.button
== Button2
)
1185 eventType
= wxEVT_MIDDLE_UP
;
1187 else if (xevent
->xbutton
.button
== Button3
)
1189 eventType
= wxEVT_RIGHT_UP
;
1198 wxevent
.SetEventType(eventType
);
1200 wxevent
.m_x
= xevent
->xbutton
.x
;
1201 wxevent
.m_y
= xevent
->xbutton
.y
;
1203 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1204 || (event_left_is_down (xevent
)
1205 && (eventType
!= wxEVT_LEFT_UP
)));
1206 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1207 || (event_middle_is_down (xevent
)
1208 && (eventType
!= wxEVT_MIDDLE_UP
)));
1209 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1210 || (event_right_is_down (xevent
)
1211 && (eventType
!= wxEVT_RIGHT_UP
)));
1213 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
1214 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
1215 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
1216 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
1218 wxevent
.SetId(win
->GetId());
1219 wxevent
.SetEventObject(win
);
1227 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1229 switch (xevent
->xany
.type
)
1237 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1238 int id
= wxCharCodeXToWX (keySym
);
1240 if (xevent
->xkey
.state
& ShiftMask
)
1241 wxevent
.m_shiftDown
= TRUE
;
1242 if (xevent
->xkey
.state
& ControlMask
)
1243 wxevent
.m_controlDown
= TRUE
;
1244 if (xevent
->xkey
.state
& Mod3Mask
)
1245 wxevent
.m_altDown
= TRUE
;
1246 if (xevent
->xkey
.state
& Mod1Mask
)
1247 wxevent
.m_metaDown
= TRUE
;
1248 wxevent
.SetEventObject(win
);
1249 wxevent
.m_keyCode
= id
;
1250 wxevent
.SetTimestamp(xevent
->xkey
.time
);
1252 wxevent
.m_x
= xevent
->xbutton
.x
;
1253 wxevent
.m_y
= xevent
->xbutton
.y
;
1267 // ----------------------------------------------------------------------------
1269 // ----------------------------------------------------------------------------
1271 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1273 wxWindowBase::SetBackgroundColour(col
);
1275 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1276 int xscreen
= DefaultScreen( xdisplay
);
1277 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1279 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1281 if (!GetMainWindow())
1285 XSetWindowAttributes attrib;
1286 attrib.background_pixel = colour.GetPixel();
1288 XChangeWindowAttributes(wxGlobalDisplay(),
1289 (Window) GetMainWindow(),
1297 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1299 if ( !wxWindowBase::SetForegroundColour(col
) )
1305 // ----------------------------------------------------------------------------
1307 // ----------------------------------------------------------------------------
1309 wxWindow
*wxGetActiveWindow()
1312 wxFAIL_MSG("Not implemented");
1317 wxWindow
*wxWindowBase::GetCapture()
1319 return (wxWindow
*)g_captureWindow
;
1323 // Find the wxWindow at the current mouse position, returning the mouse
1325 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1327 return wxFindWindowAtPoint(wxGetMousePosition());
1330 // Get the current mouse position.
1331 wxPoint
wxGetMousePosition()
1333 Display
*display
= wxGlobalDisplay();
1334 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1335 Window rootReturn
, childReturn
;
1336 int rootX
, rootY
, winX
, winY
;
1337 unsigned int maskReturn
;
1339 XQueryPointer (display
,
1343 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1344 return wxPoint(rootX
, rootY
);
1348 // ----------------------------------------------------------------------------
1349 // wxNoOptimize: switch off size optimization
1350 // ----------------------------------------------------------------------------
1352 int wxNoOptimize::ms_count
= 0;