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/scrolbar.h"
40 #include "wx/module.h"
41 #include "wx/menuitem.h"
43 #include "wx/univ/renderer.h"
45 #if wxUSE_DRAG_AND_DROP
49 #include "wx/x11/private.h"
50 #include "X11/Xutil.h"
53 // For wxGetLocalTime, used by XButtonEventGetTime
59 // ----------------------------------------------------------------------------
60 // global variables for this module
61 // ----------------------------------------------------------------------------
63 extern wxHashTable
*wxWidgetHashTable
;
64 extern wxHashTable
*wxClientWidgetHashTable
;
65 static wxWindow
* g_captureWindow
= NULL
;
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
73 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
74 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
82 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
83 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
86 // ============================================================================
88 // ============================================================================
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 void wxWindowX11::Init()
100 // generic initializations first
104 m_mainWindow
= (WXWindow
) 0;
105 m_clientWindow
= (WXWindow
) 0;
106 m_insertIntoMain
= FALSE
;
107 m_updateNcArea
= FALSE
;
109 m_winCaptured
= FALSE
;
110 m_needsInputFocus
= FALSE
;
112 m_isBeingDeleted
= FALSE
;
117 // real construction (Init() must have been called before!)
118 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
122 const wxString
& name
)
124 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
126 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
128 parent
->AddChild(this);
130 int w
= size
.GetWidth();
131 int h
= size
.GetHeight();
139 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
140 int xscreen
= DefaultScreen( xdisplay
);
141 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
142 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
144 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
145 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
147 m_foregroundColour
= *wxBLACK
;
148 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
150 Window xparent
= (Window
) parent
->GetClientWindow();
152 // Add window's own scrollbars to main window, not to client window
153 if (parent
->GetInsertIntoMain())
155 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
156 xparent
= (Window
) parent
->GetMainWindow();
171 #if wxUSE_TWO_WINDOWS
172 bool need_two_windows
=
173 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
175 bool need_two_windows
= FALSE
;
179 long xattributes
= 0;
181 XSetWindowAttributes xattributes
;
182 long xattributes_mask
= 0;
184 xattributes_mask
|= CWBackPixel
;
185 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
187 xattributes_mask
|= CWBorderPixel
;
188 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
190 xattributes_mask
|= CWEventMask
;
193 if (need_two_windows
)
196 long backColor
, foreColor
;
197 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
198 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
200 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
201 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
202 XSelectInput( xdisplay
, xwindow
,
203 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
204 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
205 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
206 PropertyChangeMask
);
210 xattributes
.event_mask
=
211 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
213 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
214 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
218 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
220 m_mainWindow
= (WXWindow
) xwindow
;
221 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
223 XMapWindow( xdisplay
, xwindow
);
226 xattributes
.event_mask
=
227 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
228 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
229 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
230 PropertyChangeMask
| VisibilityChangeMask
;
232 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
234 xattributes_mask
|= CWBitGravity
;
235 xattributes
.bit_gravity
= StaticGravity
;
239 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
246 if (HasFlag( wxSIMPLE_BORDER
))
258 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
259 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
261 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
262 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
263 XSelectInput( xdisplay
, xwindow
,
264 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
265 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
266 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
267 PropertyChangeMask
);
270 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
271 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
274 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
276 m_clientWindow
= (WXWindow
) xwindow
;
277 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
279 XMapWindow( xdisplay
, xwindow
);
283 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
285 long backColor
, foreColor
;
286 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
287 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
289 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
290 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
291 XSelectInput( xdisplay
, xwindow
,
292 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
293 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
294 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
295 PropertyChangeMask
);
298 xattributes
.event_mask
=
299 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
300 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
301 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
302 PropertyChangeMask
| VisibilityChangeMask
;
304 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
306 xattributes_mask
|= CWBitGravity
;
307 xattributes
.bit_gravity
= NorthWestGravity
;
310 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
311 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
314 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
316 m_mainWindow
= (WXWindow
) xwindow
;
317 m_clientWindow
= m_mainWindow
;
318 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
320 XMapWindow( xdisplay
, xwindow
);
323 // Is a subwindow, so map immediately
326 // Without this, the cursor may not be restored properly (e.g. in splitter
328 SetCursor(*wxSTANDARD_CURSOR
);
329 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
331 // Don't call this, it can have nasty repercussions for composite controls,
333 // SetSize(pos.x, pos.y, size.x, size.y);
339 wxWindowX11::~wxWindowX11()
341 if (g_captureWindow
== this)
342 g_captureWindow
= NULL
;
344 m_isBeingDeleted
= TRUE
;
347 m_parent
->RemoveChild( this );
351 if (m_clientWindow
!= m_mainWindow
)
353 // Destroy the cleint window
354 Window xwindow
= (Window
) m_clientWindow
;
355 wxDeleteClientWindowFromTable( xwindow
);
356 XDestroyWindow( wxGlobalDisplay(), xwindow
);
357 m_clientWindow
= NULL
;
360 // Destroy the window
361 Window xwindow
= (Window
) m_mainWindow
;
362 wxDeleteWindowFromTable( xwindow
);
363 XDestroyWindow( wxGlobalDisplay(), xwindow
);
367 // ---------------------------------------------------------------------------
369 // ---------------------------------------------------------------------------
371 void wxWindowX11::SetFocus()
373 Window xwindow
= (Window
) m_clientWindow
;
375 wxCHECK_RET( xwindow
, wxT("invalid window") );
377 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
380 if (GetName() == "scrollBar")
387 if (wxWindowIsVisible(xwindow
))
389 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
390 m_needsInputFocus
= FALSE
;
394 m_needsInputFocus
= TRUE
;
398 // Get the window with the focus
399 wxWindow
*wxWindowBase::FindFocus()
401 Window xfocus
= (Window
) 0;
404 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
407 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
410 win
= wxGetClientWindowFromTable( xfocus
);
419 // Enabling/disabling handled by event loop, and not sending events
421 bool wxWindowX11::Enable(bool enable
)
423 if ( !wxWindowBase::Enable(enable
) )
429 bool wxWindowX11::Show(bool show
)
431 wxWindowBase::Show(show
);
433 Window xwindow
= (Window
) m_mainWindow
;
434 Display
*xdisp
= wxGlobalDisplay();
437 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
438 XMapWindow(xdisp
, xwindow
);
442 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
443 XUnmapWindow(xdisp
, xwindow
);
449 // Raise the window to the top of the Z order
450 void wxWindowX11::Raise()
453 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
456 // Lower the window to the bottom of the Z order
457 void wxWindowX11::Lower()
460 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
463 void wxWindowX11::DoCaptureMouse()
465 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
467 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
478 Window xwindow
= (Window
) m_clientWindow
;
480 wxCHECK_RET( xwindow
, wxT("invalid window") );
482 g_captureWindow
= (wxWindow
*) this;
486 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
488 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
492 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
495 if (res
!= GrabSuccess
)
498 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
500 if (res
== GrabNotViewable
)
502 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
504 g_captureWindow
= NULL
;
508 m_winCaptured
= TRUE
;
512 void wxWindowX11::DoReleaseMouse()
514 g_captureWindow
= NULL
;
516 if ( !m_winCaptured
)
519 Window xwindow
= (Window
) m_clientWindow
;
523 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
526 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
528 m_winCaptured
= FALSE
;
531 bool wxWindowX11::SetFont(const wxFont
& font
)
533 if ( !wxWindowBase::SetFont(font
) )
542 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
544 if ( !wxWindowBase::SetCursor(cursor
) )
550 Window xwindow
= (Window
) m_clientWindow
;
552 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
554 wxCursor cursorToUse
;
556 cursorToUse
= m_cursor
;
558 cursorToUse
= *wxSTANDARD_CURSOR
;
560 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
562 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
567 // Coordinates relative to the window
568 void wxWindowX11::WarpPointer (int x
, int y
)
570 Window xwindow
= (Window
) m_clientWindow
;
572 wxCHECK_RET( xwindow
, wxT("invalid window") );
574 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
577 // Does a physical scroll
578 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
580 // No scrolling requested.
581 if ((dx
== 0) && (dy
== 0)) return;
583 if (!m_updateRegion
.IsEmpty())
585 m_updateRegion
.Offset( dx
, dy
);
589 GetSize( &cw
, &ch
); // GetClientSize() ??
590 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
593 if (!m_clearRegion
.IsEmpty())
595 m_clearRegion
.Offset( dx
, dy
);
599 GetSize( &cw
, &ch
); // GetClientSize() ??
600 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
603 Window xwindow
= (Window
) GetClientWindow();
605 wxCHECK_RET( xwindow
, wxT("invalid window") );
607 Display
*xdisplay
= wxGlobalDisplay();
609 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
610 XSetGraphicsExposures( xdisplay
, xgc
, True
);
628 GetClientSize( &cw
, &ch
);
631 #if wxUSE_TWO_WINDOWS
632 wxPoint
offset( 0,0 );
634 wxPoint offset
= GetClientAreaOrigin();
639 int w
= cw
- abs(dx
);
640 int h
= ch
- abs(dy
);
642 if ((h
< 0) || (w
< 0))
649 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
650 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
651 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
652 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
657 if (dx
< 0) s_x
+= -dx
;
658 if (dy
< 0) s_y
+= -dy
;
659 if (dx
> 0) d_x
= dx
+ offset
.x
;
660 if (dy
> 0) d_y
= dy
+ offset
.y
;
662 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
664 // 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 );
666 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
668 m_updateRegion
.Union( rect
);
669 m_clearRegion
.Union( rect
);
672 XFreeGC( xdisplay
, xgc
);
675 // ---------------------------------------------------------------------------
677 // ---------------------------------------------------------------------------
679 #if wxUSE_DRAG_AND_DROP
681 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
688 // Old style file-manager drag&drop
689 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
694 // ----------------------------------------------------------------------------
696 // ----------------------------------------------------------------------------
700 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
705 #endif // wxUSE_TOOLTIPS
707 // ---------------------------------------------------------------------------
708 // moving and resizing
709 // ---------------------------------------------------------------------------
711 bool wxWindowX11::PreResize()
717 void wxWindowX11::DoGetSize(int *x
, int *y
) const
719 Window xwindow
= (Window
) m_mainWindow
;
721 wxCHECK_RET( xwindow
, wxT("invalid window") );
723 //XSync(wxGlobalDisplay(), False);
725 XWindowAttributes attr
;
726 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
731 *x
= attr
.width
/* + 2*m_borderSize */ ;
732 *y
= attr
.height
/* + 2*m_borderSize */ ;
736 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
738 Window window
= (Window
) m_mainWindow
;
741 //XSync(wxGlobalDisplay(), False);
742 XWindowAttributes attr
;
743 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
751 // We may be faking the client origin. So a window that's really at (0, 30)
752 // may appear (to wxWin apps) to be at (0, 0).
755 wxPoint
pt(GetParent()->GetClientAreaOrigin());
763 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
765 Display
*display
= wxGlobalDisplay();
766 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
767 Window thisWindow
= (Window
) m_clientWindow
;
772 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
775 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
777 Display
*display
= wxGlobalDisplay();
778 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
779 Window thisWindow
= (Window
) m_clientWindow
;
784 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
788 // Get size *available for subwindows* i.e. excluding menu bar etc.
789 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
791 Window window
= (Window
) m_mainWindow
;
795 XWindowAttributes attr
;
796 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
807 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
809 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
811 Window xwindow
= (Window
) m_mainWindow
;
813 wxCHECK_RET( xwindow
, wxT("invalid window") );
815 XWindowAttributes attr
;
816 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
817 wxCHECK_RET( status
, wxT("invalid window attributes") );
821 int new_w
= attr
.width
;
822 int new_h
= attr
.height
;
824 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
827 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
830 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
833 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
849 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
852 void wxWindowX11::DoSetClientSize(int width
, int height
)
854 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
856 Window xwindow
= (Window
) m_mainWindow
;
858 wxCHECK_RET( xwindow
, wxT("invalid window") );
860 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
862 if (m_mainWindow
!= m_clientWindow
)
864 xwindow
= (Window
) m_clientWindow
;
866 wxWindow
*window
= (wxWindow
*) this;
867 wxRenderer
*renderer
= window
->GetRenderer();
870 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
871 width
-= border
.x
+ border
.width
;
872 height
-= border
.y
+ border
.height
;
875 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
879 // For implementation purposes - sometimes decorations make the client area
881 wxPoint
wxWindowX11::GetClientAreaOrigin() const
883 return wxPoint(0, 0);
886 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
888 Window xwindow
= (Window
) m_mainWindow
;
890 wxCHECK_RET( xwindow
, wxT("invalid window") );
894 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
895 if (m_mainWindow
!= m_clientWindow
)
897 xwindow
= (Window
) m_clientWindow
;
899 wxWindow
*window
= (wxWindow
*) this;
900 wxRenderer
*renderer
= window
->GetRenderer();
903 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
906 width
-= border
.x
+ border
.width
;
907 height
-= border
.y
+ border
.height
;
915 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
916 if (sb
&& sb
->IsShown())
918 wxSize size
= sb
->GetSize();
921 sb
= window
->GetScrollbar( wxVERTICAL
);
922 if (sb
&& sb
->IsShown())
924 wxSize size
= sb
->GetSize();
928 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
933 XWindowChanges windowChanges
;
936 windowChanges
.width
= width
;
937 windowChanges
.height
= height
;
938 windowChanges
.stack_mode
= 0;
939 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
941 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
946 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
954 XSizeHints sizeHints
;
957 if (minW
> -1 && minH
> -1)
959 sizeHints
.flags
|= PMinSize
;
960 sizeHints
.min_width
= minW
;
961 sizeHints
.min_height
= minH
;
963 if (maxW
> -1 && maxH
> -1)
965 sizeHints
.flags
|= PMaxSize
;
966 sizeHints
.max_width
= maxW
;
967 sizeHints
.max_height
= maxH
;
969 if (incW
> -1 && incH
> -1)
971 sizeHints
.flags
|= PResizeInc
;
972 sizeHints
.width_inc
= incW
;
973 sizeHints
.height_inc
= incH
;
976 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
980 // ---------------------------------------------------------------------------
982 // ---------------------------------------------------------------------------
984 int wxWindowX11::GetCharHeight() const
986 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
988 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
990 int direction
, ascent
, descent
;
992 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
995 // return (overall.ascent + overall.descent);
996 return (ascent
+ descent
);
999 int wxWindowX11::GetCharWidth() const
1001 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1003 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1005 int direction
, ascent
, descent
;
1006 XCharStruct overall
;
1007 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1008 &descent
, &overall
);
1010 return overall
.width
;
1013 void wxWindowX11::GetTextExtent(const wxString
& string
,
1015 int *descent
, int *externalLeading
,
1016 const wxFont
*theFont
) const
1018 wxFont fontToUse
= m_font
;
1019 if (theFont
) fontToUse
= *theFont
;
1021 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1023 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1025 int direction
, ascent
, descent2
;
1026 XCharStruct overall
;
1027 int slen
= string
.Len();
1031 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1032 &ascent
, &descent2
, &overall
);
1035 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1036 &direction
, &ascent
, &descent2
, &overall
);
1039 *x
= (overall
.width
);
1041 *y
= (ascent
+ descent2
);
1043 *descent
= descent2
;
1044 if (externalLeading
)
1045 *externalLeading
= 0;
1049 // ----------------------------------------------------------------------------
1051 // ----------------------------------------------------------------------------
1053 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1059 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1060 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1065 GetSize( &width
, &height
);
1067 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1068 m_clearRegion
.Clear();
1069 m_clearRegion
.Union( 0, 0, width
, height
);
1075 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1076 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1081 GetSize( &width
, &height
);
1083 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1084 m_updateRegion
.Clear();
1085 m_updateRegion
.Union( 0, 0, width
, height
);
1089 void wxWindowX11::Update()
1093 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1094 // Send nc paint events.
1095 SendNcPaintEvents();
1098 if (!m_updateRegion
.IsEmpty())
1100 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1101 // Actually send erase events.
1104 // Actually send paint events.
1109 void wxWindowX11::Clear()
1111 // wxClientDC dc((wxWindow*) this);
1112 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1113 // dc.SetBackground(brush);
1117 void wxWindowX11::SendEraseEvents()
1119 if (m_clearRegion
.IsEmpty()) return;
1121 wxClientDC
dc( (wxWindow
*)this );
1122 dc
.SetClippingRegion( m_clearRegion
);
1124 wxEraseEvent
erase_event( GetId(), &dc
);
1125 erase_event
.SetEventObject( this );
1127 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1129 Display
*xdisplay
= wxGlobalDisplay();
1130 Window xwindow
= (Window
) GetClientWindow();
1131 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1133 wxRegionIterator
upd( m_clearRegion
);
1136 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1137 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1142 m_clearRegion
.Clear();
1145 void wxWindowX11::SendPaintEvents()
1147 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1149 m_clipPaintRegion
= TRUE
;
1151 wxPaintEvent
paint_event( GetId() );
1152 paint_event
.SetEventObject( this );
1153 GetEventHandler()->ProcessEvent( paint_event
);
1155 m_updateRegion
.Clear();
1157 m_clipPaintRegion
= FALSE
;
1160 void wxWindowX11::SendNcPaintEvents()
1162 wxWindow
*window
= (wxWindow
*) this;
1164 // All this for drawing the small square between the scrollbars.
1169 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1170 if (sb
&& sb
->IsShown())
1172 height
= sb
->GetSize().y
;
1173 y
= sb
->GetPosition().y
;
1175 sb
= window
->GetScrollbar( wxVERTICAL
);
1176 if (sb
&& sb
->IsShown())
1178 width
= sb
->GetSize().x
;
1179 x
= sb
->GetPosition().x
;
1181 Display
*xdisplay
= wxGlobalDisplay();
1182 Window xwindow
= (Window
) GetMainWindow();
1183 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1184 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1185 colour
.CalcPixel( (WXColormap
) cm
);
1187 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1189 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1193 wxNcPaintEvent
nc_paint_event( GetId() );
1194 nc_paint_event
.SetEventObject( this );
1195 GetEventHandler()->ProcessEvent( nc_paint_event
);
1197 m_updateNcArea
= FALSE
;
1200 // ----------------------------------------------------------------------------
1202 // ----------------------------------------------------------------------------
1204 // Responds to colour changes: passes event on to children.
1205 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1207 wxWindowList::Node
*node
= GetChildren().GetFirst();
1210 // Only propagate to non-top-level windows
1211 wxWindow
*win
= node
->GetData();
1212 if ( win
->GetParent() )
1214 wxSysColourChangedEvent event2
;
1215 event
.m_eventObject
= win
;
1216 win
->GetEventHandler()->ProcessEvent(event2
);
1219 node
= node
->GetNext();
1223 void wxWindowX11::OnInternalIdle()
1225 // Update invalidated regions.
1228 // This calls the UI-update mechanism (querying windows for
1229 // menu/toolbar/control state information)
1232 // Set the input focus if couldn't do it before
1233 if (m_needsInputFocus
)
1239 // ----------------------------------------------------------------------------
1240 // function which maintain the global hash table mapping Widgets to wxWindows
1241 // ----------------------------------------------------------------------------
1243 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1245 wxWindow
*oldItem
= NULL
;
1246 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1248 wxLogDebug("Widget table clash: new widget is %ld, %s",
1249 (long)w
, win
->GetClassInfo()->GetClassName());
1253 wxWidgetHashTable
->Put((long) w
, win
);
1255 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1256 w
, win
, win
->GetClassInfo()->GetClassName());
1261 wxWindow
*wxGetWindowFromTable(Window w
)
1263 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1266 void wxDeleteWindowFromTable(Window w
)
1268 wxWidgetHashTable
->Delete((long)w
);
1271 // ----------------------------------------------------------------------------
1272 // function which maintain the global hash table mapping client widgets
1273 // ----------------------------------------------------------------------------
1275 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1277 wxWindow
*oldItem
= NULL
;
1278 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1280 wxLogDebug("Client window table clash: new window is %ld, %s",
1281 (long)w
, win
->GetClassInfo()->GetClassName());
1285 wxClientWidgetHashTable
->Put((long) w
, win
);
1287 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1288 w
, win
, win
->GetClassInfo()->GetClassName());
1293 wxWindow
*wxGetClientWindowFromTable(Window w
)
1295 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1298 void wxDeleteClientWindowFromTable(Window w
)
1300 wxClientWidgetHashTable
->Delete((long)w
);
1303 // ----------------------------------------------------------------------------
1304 // add/remove window from the table
1305 // ----------------------------------------------------------------------------
1307 // ----------------------------------------------------------------------------
1308 // X11-specific accessors
1309 // ----------------------------------------------------------------------------
1311 WXWindow
wxWindowX11::GetMainWindow() const
1313 return m_mainWindow
;
1316 WXWindow
wxWindowX11::GetClientWindow() const
1318 return m_clientWindow
;
1321 // ----------------------------------------------------------------------------
1322 // TranslateXXXEvent() functions
1323 // ----------------------------------------------------------------------------
1325 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1327 switch (XEventGetType(xevent
))
1335 wxEventType eventType
= wxEVT_NULL
;
1337 if (XEventGetType(xevent
) == EnterNotify
)
1339 //if (local_event.xcrossing.mode!=NotifyNormal)
1340 // return ; // Ignore grab events
1341 eventType
= wxEVT_ENTER_WINDOW
;
1342 // canvas->GetEventHandler()->OnSetFocus();
1344 else if (XEventGetType(xevent
) == LeaveNotify
)
1346 //if (local_event.xcrossingr.mode!=NotifyNormal)
1347 // return ; // Ignore grab events
1348 eventType
= wxEVT_LEAVE_WINDOW
;
1349 // canvas->GetEventHandler()->OnKillFocus();
1351 else if (XEventGetType(xevent
) == MotionNotify
)
1353 eventType
= wxEVT_MOTION
;
1355 else if (XEventGetType(xevent
) == ButtonPress
)
1357 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1359 if (XButtonEventLChanged(xevent
))
1361 eventType
= wxEVT_LEFT_DOWN
;
1364 else if (XButtonEventMChanged(xevent
))
1366 eventType
= wxEVT_MIDDLE_DOWN
;
1369 else if (XButtonEventRChanged(xevent
))
1371 eventType
= wxEVT_RIGHT_DOWN
;
1375 // check for a double click
1376 // TODO: where can we get this value from?
1377 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1378 long dclickTime
= 200;
1379 long ts
= wxevent
.GetTimestamp();
1381 int buttonLast
= win
->GetLastClickedButton();
1382 long lastTS
= win
->GetLastClickTime();
1383 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1386 win
->SetLastClick(0, ts
);
1387 if ( eventType
== wxEVT_LEFT_DOWN
)
1388 eventType
= wxEVT_LEFT_DCLICK
;
1389 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1390 eventType
= wxEVT_MIDDLE_DCLICK
;
1391 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1392 eventType
= wxEVT_RIGHT_DCLICK
;
1396 // not fast enough or different button
1397 win
->SetLastClick(button
, ts
);
1400 else if (XEventGetType(xevent
) == ButtonRelease
)
1402 if (XButtonEventLChanged(xevent
))
1404 eventType
= wxEVT_LEFT_UP
;
1406 else if (XButtonEventMChanged(xevent
))
1408 eventType
= wxEVT_MIDDLE_UP
;
1410 else if (XButtonEventRChanged(xevent
))
1412 eventType
= wxEVT_RIGHT_UP
;
1421 wxevent
.SetEventType(eventType
);
1423 wxevent
.m_x
= XButtonEventGetX(xevent
);
1424 wxevent
.m_y
= XButtonEventGetY(xevent
);
1426 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1427 || (XButtonEventLIsDown(xevent
)
1428 && (eventType
!= wxEVT_LEFT_UP
)));
1429 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1430 || (XButtonEventMIsDown(xevent
)
1431 && (eventType
!= wxEVT_MIDDLE_UP
)));
1432 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1433 || (XButtonEventRIsDown (xevent
)
1434 && (eventType
!= wxEVT_RIGHT_UP
)));
1436 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1437 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1438 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1439 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1441 wxevent
.SetId(win
->GetId());
1442 wxevent
.SetEventObject(win
);
1450 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1452 switch (XEventGetType(xevent
))
1460 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1461 int id
= wxCharCodeXToWX (keySym
);
1463 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1464 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1465 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1466 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1467 wxevent
.SetEventObject(win
);
1468 wxevent
.m_keyCode
= id
;
1469 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1471 wxevent
.m_x
= XKeyEventGetX(xevent
);
1472 wxevent
.m_y
= XKeyEventGetY(xevent
);
1486 // ----------------------------------------------------------------------------
1488 // ----------------------------------------------------------------------------
1490 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1492 wxWindowBase::SetBackgroundColour(col
);
1494 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1495 int xscreen
= DefaultScreen( xdisplay
);
1496 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1498 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1500 // We don't set the background colour as we paint
1501 // the background ourselves.
1502 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1507 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1509 if ( !wxWindowBase::SetForegroundColour(col
) )
1515 // ----------------------------------------------------------------------------
1517 // ----------------------------------------------------------------------------
1519 wxWindow
*wxGetActiveWindow()
1522 wxFAIL_MSG("Not implemented");
1527 wxWindow
*wxWindowBase::GetCapture()
1529 return (wxWindow
*)g_captureWindow
;
1533 // Find the wxWindow at the current mouse position, returning the mouse
1535 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1537 return wxFindWindowAtPoint(wxGetMousePosition());
1540 // Get the current mouse position.
1541 wxPoint
wxGetMousePosition()
1545 return wxPoint(0, 0);
1547 Display
*display
= wxGlobalDisplay();
1548 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1549 Window rootReturn
, childReturn
;
1550 int rootX
, rootY
, winX
, winY
;
1551 unsigned int maskReturn
;
1553 XQueryPointer (display
,
1557 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1558 return wxPoint(rootX
, rootY
);
1563 // ----------------------------------------------------------------------------
1564 // wxNoOptimize: switch off size optimization
1565 // ----------------------------------------------------------------------------
1567 int wxNoOptimize::ms_count
= 0;
1570 // ----------------------------------------------------------------------------
1572 // ----------------------------------------------------------------------------
1574 class wxWinModule
: public wxModule
1581 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1584 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1586 bool wxWinModule::OnInit()
1588 Display
*xdisplay
= wxGlobalDisplay();
1589 int xscreen
= DefaultScreen( xdisplay
);
1590 Window xroot
= RootWindow( xdisplay
, xscreen
);
1591 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1592 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1597 void wxWinModule::OnExit()
1599 Display
*xdisplay
= wxGlobalDisplay();
1600 XFreeGC( xdisplay
, g_eraseGC
);