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"
51 // For wxGetLocalTime, used by XButtonEventGetTime
57 // ----------------------------------------------------------------------------
58 // global variables for this module
59 // ----------------------------------------------------------------------------
61 extern wxHashTable
*wxWidgetHashTable
;
62 static wxWindow
* g_captureWindow
= NULL
;
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
69 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
70 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
78 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
79 EVT_SYS_COLOUR_CHANGED(wxWindowX11
::OnSysColourChanged
)
82 // ============================================================================
84 // ============================================================================
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 void wxWindowX11
::Init()
96 // generic initializations first
100 m_mainWidget
= (WXWindow
) 0;
101 m_winCaptured
= FALSE
;
102 m_needsInputFocus
= FALSE
;
104 m_isBeingDeleted
= FALSE
;
109 // real construction (Init() must have been called before!)
110 bool wxWindowX11
::Create(wxWindow
*parent
, wxWindowID id
,
114 const wxString
& name
)
116 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
118 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
120 parent
->AddChild(this);
122 int w
= size
.GetWidth();
123 int h
= size
.GetHeight();
131 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
132 int xscreen
= DefaultScreen( xdisplay
);
133 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
134 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
136 m_backgroundColour
= wxSystemSettings
::GetColour(wxSYS_COLOUR_3DFACE
);
137 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
139 m_foregroundColour
= *wxBLACK
;
140 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
142 Window xparent
= (Window
) parent
->GetMainWindow();
157 XSetWindowAttributes xattributes
;
159 long xattributes_mask
=
160 CWBorderPixel
| CWBackPixel
;
162 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
163 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
165 xattributes_mask
|= CWEventMask
;
166 xattributes
.event_mask
=
167 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
168 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
169 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
170 PropertyChangeMask
| VisibilityChangeMask
;
172 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
174 xattributes_mask
|= CWBitGravity
;
175 xattributes
.bit_gravity
= StaticGravity
;
178 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
179 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
182 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
184 long backColor
, foreColor
;
185 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
186 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
188 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
189 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
190 XSelectInput( xdisplay
, xwindow
,
191 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
192 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
193 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
194 PropertyChangeMask
);
197 m_mainWidget
= (WXWindow
) xwindow
;
199 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
201 // Is a subwindow, so map immediately
203 XMapWindow( xdisplay
, xwindow
);
205 // Without this, the cursor may not be restored properly (e.g. in splitter
207 SetCursor(*wxSTANDARD_CURSOR
);
208 SetFont(wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
));
210 // Set background to None which will prevent X11 from clearing the
211 // background comletely.
212 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
214 // Don't call this, it can have nasty repercussions for composite controls,
216 // SetSize(pos.x, pos.y, size.x, size.y);
222 wxWindowX11
::~wxWindowX11()
224 if (g_captureWindow
== this)
225 g_captureWindow
= NULL
;
227 m_isBeingDeleted
= TRUE
;
229 // X11-specific actions first
230 Window xwindow
= (Window
) m_mainWidget
;
233 m_parent
->RemoveChild( this );
237 // Destroy the window
240 XSelectInput( wxGlobalDisplay(), xwindow
, NoEventMask
);
241 wxDeleteWindowFromTable( xwindow
);
242 XDestroyWindow( wxGlobalDisplay(), xwindow
);
247 // ---------------------------------------------------------------------------
249 // ---------------------------------------------------------------------------
251 void wxWindowX11
::SetFocus()
253 Window xwindow
= (Window
) GetMainWindow();
255 wxCHECK_RET( xwindow
, wxT("invalid window") );
257 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
260 if (GetName() == "scrollBar")
267 if (wxWindowIsVisible(xwindow
))
269 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
270 m_needsInputFocus
= FALSE
;
274 m_needsInputFocus
= TRUE
;
278 // Get the window with the focus
279 wxWindow
*wxWindowBase
::FindFocus()
281 Window xfocus
= (Window
) 0;
284 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
287 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
295 wxWindow
*wxWindowX11
::GetFocusWidget()
297 wxWindow
*win
= (wxWindow
*) this;
298 while (!win
->IsTopLevel())
300 win
= win
->GetParent();
302 return (wxWindow
*) NULL
;
308 // Enabling/disabling handled by event loop, and not sending events
310 bool wxWindowX11
::Enable(bool enable
)
312 if ( !wxWindowBase
::Enable(enable
) )
318 bool wxWindowX11
::Show(bool show
)
320 wxWindowBase
::Show(show
);
322 Window xwin
= (Window
) GetXWindow();
323 Display
*xdisp
= (Display
*) GetXDisplay();
326 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
327 XMapWindow(xdisp
, xwin
);
332 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
333 XUnmapWindow(xdisp
, xwin
);
339 // Raise the window to the top of the Z order
340 void wxWindowX11
::Raise()
343 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
346 // Lower the window to the bottom of the Z order
347 void wxWindowX11
::Lower()
350 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWidget
);
353 void wxWindowX11
::DoCaptureMouse()
355 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
357 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
368 Window xwindow
= (Window
) GetMainWindow();
370 wxCHECK_RET( xwindow
, wxT("invalid window") );
372 g_captureWindow
= (wxWindow
*) this;
376 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
378 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
382 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
385 if (res
!= GrabSuccess
)
388 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
390 if (res
== GrabNotViewable
)
392 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
394 g_captureWindow
= NULL
;
398 // wxLogDebug("Grabbed pointer in %s", GetName().c_str() );
401 res
= XGrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
402 (Window
) GetMainWindow(),
404 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
,
410 if (res
!= GrabSuccess
)
412 wxLogDebug("Failed to grab mouse buttons.");
413 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
419 res
= XGrabKeyboard(wxGlobalDisplay(), (Window
) GetMainWindow(),
420 ShiftMask
| LockMask
| ControlMask
| Mod1Mask
| Mod2Mask
| Mod3Mask
| Mod4Mask
| Mod5Mask
,
426 if (res
!= GrabSuccess
)
428 wxLogDebug("Failed to grab keyboard.");
429 XUngrabPointer(wxGlobalDisplay(), CurrentTime
);
430 XUngrabButton(wxGlobalDisplay(), AnyButton
, AnyModifier
,
431 (Window
) GetMainWindow());
436 m_winCaptured
= TRUE
;
440 void wxWindowX11
::DoReleaseMouse()
442 g_captureWindow
= NULL
;
444 if ( !m_winCaptured
)
447 Window xwindow
= (Window
) GetMainWindow();
451 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
453 XUngrabButton( wxGlobalDisplay(), AnyButton
, AnyModifier
, xwindow
);
454 XUngrabKeyboard( wxGlobalDisplay(), CurrentTime
);
458 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
460 m_winCaptured
= FALSE
;
463 bool wxWindowX11
::SetFont(const wxFont
& font
)
465 if ( !wxWindowBase
::SetFont(font
) )
474 bool wxWindowX11
::SetCursor(const wxCursor
& cursor
)
476 if ( !wxWindowBase
::SetCursor(cursor
) )
482 Window xwindow
= (Window
) GetMainWindow();
484 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
486 wxCursor cursorToUse
;
488 cursorToUse
= m_cursor
;
490 cursorToUse
= *wxSTANDARD_CURSOR
;
492 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
494 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
499 // Coordinates relative to the window
500 void wxWindowX11
::WarpPointer (int x
, int y
)
502 Window xwindow
= (Window
) GetMainWindow();
504 wxCHECK_RET( xwindow
, wxT("invalid window") );
506 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
509 // Does a physical scroll
510 void wxWindowX11
::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
512 // No scrolling requested.
513 if ((dx
== 0) && (dy
== 0)) return;
515 if (!m_updateRegion
.IsEmpty())
517 m_updateRegion
.Offset( dx
, dy
);
521 GetSize( &cw
, &ch
); // GetClientSize() ??
522 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
525 if (!m_clearRegion
.IsEmpty())
527 m_clearRegion
.Offset( dx
, dy
);
531 GetSize( &cw
, &ch
); // GetClientSize() ??
532 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
535 Window xwindow
= (Window
) GetMainWindow();
537 wxCHECK_RET( xwindow
, wxT("invalid window") );
539 Display
*xdisplay
= wxGlobalDisplay();
541 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
542 XSetGraphicsExposures( xdisplay
, xgc
, True
);
560 GetClientSize( &cw
, &ch
);
563 wxPoint offset
= GetClientAreaOrigin();
567 int w
= cw
- abs(dx
);
568 int h
= ch
- abs(dy
);
570 if ((h
< 0) || (w
< 0))
577 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
578 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
579 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
580 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
585 if (dx
< 0) s_x
+= -dx
;
586 if (dy
< 0) s_y
+= -dy
;
587 if (dx
> 0) d_x
= dx
+ offset
.x
;
588 if (dy
> 0) d_y
= dy
+ offset
.y
;
590 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
592 // wxLogDebug( "Copy: s_x %d s_y %d w %d h %d d_x %d d_y %d", s_x, s_y, w, h, d_x, d_y );
594 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
596 m_updateRegion
.Union( rect
);
597 m_clearRegion
.Union( rect
);
600 XFreeGC( xdisplay
, xgc
);
603 // ---------------------------------------------------------------------------
605 // ---------------------------------------------------------------------------
607 #if wxUSE_DRAG_AND_DROP
609 void wxWindowX11
::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
616 // Old style file-manager drag&drop
617 void wxWindowX11
::DragAcceptFiles(bool WXUNUSED(accept
))
622 // ----------------------------------------------------------------------------
624 // ----------------------------------------------------------------------------
628 void wxWindowX11
::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
633 #endif // wxUSE_TOOLTIPS
635 // ---------------------------------------------------------------------------
636 // moving and resizing
637 // ---------------------------------------------------------------------------
639 bool wxWindowX11
::PreResize()
645 void wxWindowX11
::DoGetSize(int *x
, int *y
) const
647 Window xwindow
= (Window
) GetMainWindow();
649 wxCHECK_RET( xwindow
, wxT("invalid window") );
651 //XSync(wxGlobalDisplay(), False);
653 XWindowAttributes attr
;
654 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
659 *x
= attr
.width
/* + 2*m_borderSize */ ;
660 *y
= attr
.height
/* + 2*m_borderSize */ ;
664 void wxWindowX11
::DoGetPosition(int *x
, int *y
) const
666 Window window
= (Window
) m_mainWidget
;
669 //XSync(wxGlobalDisplay(), False);
670 XWindowAttributes attr
;
671 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
679 // We may be faking the client origin. So a window that's really at (0, 30)
680 // may appear (to wxWin apps) to be at (0, 0).
683 wxPoint
pt(GetParent()->GetClientAreaOrigin());
691 void wxWindowX11
::DoScreenToClient(int *x
, int *y
) const
693 Display
*display
= wxGlobalDisplay();
694 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
695 Window thisWindow
= (Window
) m_mainWidget
;
700 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
703 void wxWindowX11
::DoClientToScreen(int *x
, int *y
) const
705 Display
*display
= wxGlobalDisplay();
706 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
707 Window thisWindow
= (Window
) m_mainWidget
;
712 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
716 // Get size *available for subwindows* i.e. excluding menu bar etc.
717 void wxWindowX11
::DoGetClientSize(int *x
, int *y
) const
719 Window window
= (Window
) m_mainWidget
;
723 //XSync(wxGlobalDisplay(), False); // Is this really a good idea?
724 XWindowAttributes attr
;
725 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
736 void wxWindowX11
::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
738 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
740 Window xwindow
= (Window
) GetMainWindow();
742 wxCHECK_RET( xwindow
, wxT("invalid window") );
744 XWindowAttributes attr
;
745 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
746 wxCHECK_RET( status
, wxT("invalid window attributes") );
750 int new_w
= attr
.width
;
751 int new_h
= attr
.height
;
754 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
757 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
760 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
763 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
779 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
782 wxSizeEvent
event(wxSize(new_w
, new_h
), GetId());
783 event
.SetEventObject(this);
784 GetEventHandler()->ProcessEvent(event
);
788 void wxWindowX11
::DoSetClientSize(int width
, int height
)
790 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
792 Window xwindow
= (Window
) GetMainWindow();
794 wxCHECK_RET( xwindow
, wxT("invalid window") );
798 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
801 wxSizeEvent
event(wxSize(width
, height
), GetId());
802 event
.SetEventObject(this);
803 GetEventHandler()->ProcessEvent(event
);
808 XWindowAttributes attr
;
809 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
810 wxCHECK_RET( status
, wxT("invalid window attributes") );
814 int new_w
= attr
.width
;
815 int new_h
= attr
.height
;
823 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
828 // For implementation purposes - sometimes decorations make the client area
830 wxPoint wxWindowX11
::GetClientAreaOrigin() const
832 return wxPoint(0, 0);
835 void wxWindowX11
::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
843 XSizeHints sizeHints
;
846 if (minW
> -1 && minH
> -1)
848 sizeHints
.flags
|= PMinSize
;
849 sizeHints
.min_width
= minW
;
850 sizeHints
.min_height
= minH
;
852 if (maxW
> -1 && maxH
> -1)
854 sizeHints
.flags
|= PMaxSize
;
855 sizeHints
.max_width
= maxW
;
856 sizeHints
.max_height
= maxH
;
858 if (incW
> -1 && incH
> -1)
860 sizeHints
.flags
|= PResizeInc
;
861 sizeHints
.width_inc
= incW
;
862 sizeHints
.height_inc
= incH
;
865 XSetWMNormalHints(wxGlobalDisplay(), (Window
) GetMainWindow(), & sizeHints
);
869 void wxWindowX11
::DoMoveWindow(int x
, int y
, int width
, int height
)
871 Window xwindow
= (Window
) GetMainWindow();
873 wxCHECK_RET( xwindow
, wxT("invalid window") );
877 XWindowAttributes attr
;
878 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
879 wxCHECK_RET( status
, wxT("invalid window attributes") );
881 if (attr
.width
== width
&& attr
.height
== height
)
883 XMoveWindow( wxGlobalDisplay(), xwindow
, x
, y
);
887 if (attr
.x
== x
&& attr
.y
== y
)
889 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
893 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
897 XWindowChanges windowChanges
;
900 windowChanges
.width
= width
;
901 windowChanges
.height
= height
;
902 windowChanges
.stack_mode
= 0;
903 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
905 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
910 // ---------------------------------------------------------------------------
912 // ---------------------------------------------------------------------------
914 int wxWindowX11
::GetCharHeight() const
916 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
918 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
920 int direction
, ascent
, descent
;
922 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
925 // return (overall.ascent + overall.descent);
926 return (ascent
+ descent
);
929 int wxWindowX11
::GetCharWidth() const
931 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
933 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
935 int direction
, ascent
, descent
;
937 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
940 return overall
.width
;
943 void wxWindowX11
::GetTextExtent(const wxString
& string
,
945 int *descent
, int *externalLeading
,
946 const wxFont
*theFont
) const
948 wxFont fontToUse
= m_font
;
949 if (theFont
) fontToUse
= *theFont
;
951 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
953 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, GetXDisplay());
955 int direction
, ascent
, descent2
;
957 int slen
= string
.Len();
961 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
962 &ascent
, &descent2
, &overall
);
965 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
966 &direction
, &ascent
, &descent2
, &overall
);
969 *x
= (overall
.width
);
971 *y
= (ascent
+ descent2
);
975 *externalLeading
= 0;
979 // ----------------------------------------------------------------------------
981 // ----------------------------------------------------------------------------
983 void wxWindowX11
::Refresh(bool eraseBack
, const wxRect
*rect
)
989 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
990 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
995 GetSize( &width
, &height
);
997 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
998 m_clearRegion
.Clear();
999 m_clearRegion
.Union( 0, 0, width
, height
);
1005 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1006 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1011 GetSize( &width
, &height
);
1013 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1014 m_updateRegion
.Clear();
1015 m_updateRegion
.Union( 0, 0, width
, height
);
1019 void wxWindowX11
::Update()
1021 if (!m_updateRegion
.IsEmpty())
1023 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1024 // Actually send erase events.
1027 // Actually send paint events.
1032 void wxWindowX11
::Clear()
1034 wxClientDC
dc((wxWindow
*) this);
1035 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1036 dc
.SetBackground(brush
);
1040 void wxWindowX11
::SendEraseEvents()
1042 if (m_clearRegion
.IsEmpty()) return;
1044 wxWindowDC
dc( (wxWindow
*)this );
1045 dc
.SetClippingRegion( m_clearRegion
);
1047 wxEraseEvent
erase_event( GetId(), &dc
);
1048 erase_event
.SetEventObject( this );
1050 if (!GetEventHandler()->ProcessEvent(erase_event
))
1052 Window xwindow
= (Window
) GetMainWindow();
1053 Display
*xdisplay
= wxGlobalDisplay();
1054 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1055 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1056 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1057 wxRegionIterator
upd( m_clearRegion
);
1060 XFillRectangle( xdisplay
, xwindow
, xgc
,
1061 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1064 XFreeGC( xdisplay
, xgc
);
1067 m_clearRegion
.Clear();
1070 void wxWindowX11
::SendPaintEvents()
1072 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1074 m_clipPaintRegion
= TRUE
;
1076 wxNcPaintEvent
nc_paint_event( GetId() );
1077 nc_paint_event
.SetEventObject( this );
1078 GetEventHandler()->ProcessEvent( nc_paint_event
);
1080 wxPaintEvent
paint_event( GetId() );
1081 paint_event
.SetEventObject( this );
1082 GetEventHandler()->ProcessEvent( paint_event
);
1084 m_updateRegion
.Clear();
1086 m_clipPaintRegion
= FALSE
;
1089 // ----------------------------------------------------------------------------
1091 // ----------------------------------------------------------------------------
1093 // Responds to colour changes: passes event on to children.
1094 void wxWindowX11
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1096 wxWindowList
::Node
*node
= GetChildren().GetFirst();
1099 // Only propagate to non-top-level windows
1100 wxWindow
*win
= node
->GetData();
1101 if ( win
->GetParent() )
1103 wxSysColourChangedEvent event2
;
1104 event
.m_eventObject
= win
;
1105 win
->GetEventHandler()->ProcessEvent(event2
);
1108 node
= node
->GetNext();
1112 void wxWindowX11
::OnInternalIdle()
1114 // Update invalidated regions.
1117 // This calls the UI-update mechanism (querying windows for
1118 // menu/toolbar/control state information)
1121 // Set the input focus if couldn't do it before
1122 if (m_needsInputFocus
)
1128 // ----------------------------------------------------------------------------
1129 // function which maintain the global hash table mapping Widgets to wxWindows
1130 // ----------------------------------------------------------------------------
1132 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1134 wxWindow
*oldItem
= NULL
;
1135 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1137 wxLogDebug("Widget table clash: new widget is %ld, %s",
1138 (long)w
, win
->GetClassInfo()->GetClassName());
1142 wxWidgetHashTable
->Put((long) w
, win
);
1144 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1145 w
, win
, win
->GetClassInfo()->GetClassName());
1150 wxWindow
*wxGetWindowFromTable(Window w
)
1152 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1155 void wxDeleteWindowFromTable(Window w
)
1157 wxWidgetHashTable
->Delete((long)w
);
1160 // ----------------------------------------------------------------------------
1161 // add/remove window from the table
1162 // ----------------------------------------------------------------------------
1164 // ----------------------------------------------------------------------------
1165 // X11-specific accessors
1166 // ----------------------------------------------------------------------------
1168 // Get the underlying X window
1169 WXWindow wxWindowX11
::GetXWindow() const
1171 return GetMainWindow();
1174 // Get the underlying X display
1175 WXDisplay
*wxWindowX11
::GetXDisplay() const
1177 return wxGetDisplay();
1180 WXWindow wxWindowX11
::GetMainWindow() const
1182 return m_mainWidget
;
1185 // ----------------------------------------------------------------------------
1186 // TranslateXXXEvent() functions
1187 // ----------------------------------------------------------------------------
1189 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1191 switch (XEventGetType(xevent
))
1199 wxEventType eventType
= wxEVT_NULL
;
1201 if (XEventGetType(xevent
) == EnterNotify
)
1203 //if (local_event.xcrossing.mode!=NotifyNormal)
1204 // return ; // Ignore grab events
1205 eventType
= wxEVT_ENTER_WINDOW
;
1206 // canvas->GetEventHandler()->OnSetFocus();
1208 else if (XEventGetType(xevent
) == LeaveNotify
)
1210 //if (local_event.xcrossingr.mode!=NotifyNormal)
1211 // return ; // Ignore grab events
1212 eventType
= wxEVT_LEAVE_WINDOW
;
1213 // canvas->GetEventHandler()->OnKillFocus();
1215 else if (XEventGetType(xevent
) == MotionNotify
)
1217 eventType
= wxEVT_MOTION
;
1219 else if (XEventGetType(xevent
) == ButtonPress
)
1221 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1223 if (XButtonEventLChanged(xevent
))
1225 eventType
= wxEVT_LEFT_DOWN
;
1228 else if (XButtonEventMChanged(xevent
))
1230 eventType
= wxEVT_MIDDLE_DOWN
;
1233 else if (XButtonEventRChanged(xevent
))
1235 eventType
= wxEVT_RIGHT_DOWN
;
1239 // check for a double click
1240 // TODO: where can we get this value from?
1241 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1242 long dclickTime
= 200;
1243 long ts
= wxevent
.GetTimestamp();
1245 int buttonLast
= win
->GetLastClickedButton();
1246 long lastTS
= win
->GetLastClickTime();
1247 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1250 win
->SetLastClick(0, ts
);
1251 if ( eventType
== wxEVT_LEFT_DOWN
)
1252 eventType
= wxEVT_LEFT_DCLICK
;
1253 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1254 eventType
= wxEVT_MIDDLE_DCLICK
;
1255 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1256 eventType
= wxEVT_RIGHT_DCLICK
;
1260 // not fast enough or different button
1261 win
->SetLastClick(button
, ts
);
1264 else if (XEventGetType(xevent
) == ButtonRelease
)
1266 if (XButtonEventLChanged(xevent
))
1268 eventType
= wxEVT_LEFT_UP
;
1270 else if (XButtonEventMChanged(xevent
))
1272 eventType
= wxEVT_MIDDLE_UP
;
1274 else if (XButtonEventRChanged(xevent
))
1276 eventType
= wxEVT_RIGHT_UP
;
1285 wxevent
.SetEventType(eventType
);
1287 wxevent
.m_x
= XButtonEventGetX(xevent
);
1288 wxevent
.m_y
= XButtonEventGetY(xevent
);
1290 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1291 || (XButtonEventLIsDown(xevent
)
1292 && (eventType
!= wxEVT_LEFT_UP
)));
1293 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1294 || (XButtonEventMIsDown(xevent
)
1295 && (eventType
!= wxEVT_MIDDLE_UP
)));
1296 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1297 || (XButtonEventRIsDown (xevent
)
1298 && (eventType
!= wxEVT_RIGHT_UP
)));
1300 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1301 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1302 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1303 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1305 wxevent
.SetId(win
->GetId());
1306 wxevent
.SetEventObject(win
);
1314 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1316 switch (XEventGetType(xevent
))
1324 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1325 int id
= wxCharCodeXToWX (keySym
);
1327 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1328 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1329 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1330 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1331 wxevent
.SetEventObject(win
);
1332 wxevent
.m_keyCode
= id
;
1333 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1335 wxevent
.m_x
= XKeyEventGetX(xevent
);
1336 wxevent
.m_y
= XKeyEventGetY(xevent
);
1350 // ----------------------------------------------------------------------------
1352 // ----------------------------------------------------------------------------
1354 bool wxWindowX11
::SetBackgroundColour(const wxColour
& col
)
1356 wxWindowBase
::SetBackgroundColour(col
);
1358 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1359 int xscreen
= DefaultScreen( xdisplay
);
1360 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1362 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1364 if (!GetMainWindow())
1368 XSetWindowAttributes attrib;
1369 attrib.background_pixel = colour.GetPixel();
1371 XChangeWindowAttributes(wxGlobalDisplay(),
1372 (Window) GetMainWindow(),
1380 bool wxWindowX11
::SetForegroundColour(const wxColour
& col
)
1382 if ( !wxWindowBase
::SetForegroundColour(col
) )
1388 // ----------------------------------------------------------------------------
1390 // ----------------------------------------------------------------------------
1392 wxWindow
*wxGetActiveWindow()
1395 wxFAIL_MSG("Not implemented");
1400 wxWindow
*wxWindowBase
::GetCapture()
1402 return (wxWindow
*)g_captureWindow
;
1406 // Find the wxWindow at the current mouse position, returning the mouse
1408 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1410 return wxFindWindowAtPoint(wxGetMousePosition());
1413 // Get the current mouse position.
1414 wxPoint
wxGetMousePosition()
1418 return wxPoint(0, 0);
1420 Display
*display
= wxGlobalDisplay();
1421 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1422 Window rootReturn
, childReturn
;
1423 int rootX
, rootY
, winX
, winY
;
1424 unsigned int maskReturn
;
1426 XQueryPointer (display
,
1430 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1431 return wxPoint(rootX
, rootY
);
1436 // ----------------------------------------------------------------------------
1437 // wxNoOptimize: switch off size optimization
1438 // ----------------------------------------------------------------------------
1440 int wxNoOptimize
::ms_count
= 0;