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 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
131 int xscreen
= DefaultScreen( xdisplay
);
132 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
133 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
135 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
136 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
138 m_foregroundColour
= *wxBLACK
;
139 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
141 Window xparent
= (Window
) parent
->GetClientAreaWindow();
143 // Add window's own scrollbars to main window, not to client window
144 if (parent
->GetInsertIntoMain())
146 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
147 xparent
= (Window
) parent
->GetMainWindow();
150 // Size (not including the border) must be nonzero (or a Value error results)!
151 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
164 #if wxUSE_TWO_WINDOWS
165 bool need_two_windows
=
166 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
168 bool need_two_windows
= FALSE
;
172 long xattributes
= 0;
174 XSetWindowAttributes xattributes
;
175 long xattributes_mask
= 0;
177 xattributes_mask
|= CWBackPixel
;
178 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
180 xattributes_mask
|= CWBorderPixel
;
181 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
183 xattributes_mask
|= CWEventMask
;
186 if (need_two_windows
)
189 long backColor
, foreColor
;
190 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
191 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
193 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
194 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
195 XSelectInput( xdisplay
, xwindow
,
196 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
197 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
198 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
199 PropertyChangeMask
);
203 xattributes
.event_mask
=
204 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
206 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
207 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
211 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
213 m_mainWindow
= (WXWindow
) xwindow
;
214 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
216 XMapWindow( xdisplay
, xwindow
);
219 xattributes
.event_mask
=
220 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
221 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
222 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
223 PropertyChangeMask
| VisibilityChangeMask
;
225 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
227 xattributes_mask
|= CWBitGravity
;
228 xattributes
.bit_gravity
= StaticGravity
;
232 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
239 else if (HasFlag( wxSIMPLE_BORDER
))
252 // Make again sure the size is nonzero.
259 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
260 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
262 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
263 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
264 XSelectInput( xdisplay
, xwindow
,
265 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
266 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
267 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
268 PropertyChangeMask
);
271 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
272 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
275 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
277 m_clientWindow
= (WXWindow
) xwindow
;
278 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
280 XMapWindow( xdisplay
, xwindow
);
284 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
286 long backColor
, foreColor
;
287 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
288 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
290 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
291 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
292 XSelectInput( xdisplay
, xwindow
,
293 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
294 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
295 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
296 PropertyChangeMask
);
299 xattributes
.event_mask
=
300 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
301 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
302 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
303 PropertyChangeMask
| VisibilityChangeMask
;
305 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
307 xattributes_mask
|= CWBitGravity
;
308 xattributes
.bit_gravity
= NorthWestGravity
;
311 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
312 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
315 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
317 m_mainWindow
= (WXWindow
) xwindow
;
318 m_clientWindow
= m_mainWindow
;
319 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
321 XMapWindow( xdisplay
, xwindow
);
324 // Is a subwindow, so map immediately
327 // Without this, the cursor may not be restored properly (e.g. in splitter
329 SetCursor(*wxSTANDARD_CURSOR
);
330 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
332 // Don't call this, it can have nasty repercussions for composite controls,
334 // SetSize(pos.x, pos.y, size.x, size.y);
340 wxWindowX11::~wxWindowX11()
342 if (g_captureWindow
== this)
343 g_captureWindow
= NULL
;
345 m_isBeingDeleted
= TRUE
;
348 m_parent
->RemoveChild( this );
352 if (m_clientWindow
!= m_mainWindow
)
354 // Destroy the cleint window
355 Window xwindow
= (Window
) m_clientWindow
;
356 wxDeleteClientWindowFromTable( xwindow
);
357 XDestroyWindow( wxGlobalDisplay(), xwindow
);
358 m_clientWindow
= NULL
;
361 // Destroy the window
362 Window xwindow
= (Window
) m_mainWindow
;
363 wxDeleteWindowFromTable( xwindow
);
364 XDestroyWindow( wxGlobalDisplay(), xwindow
);
368 // ---------------------------------------------------------------------------
370 // ---------------------------------------------------------------------------
372 void wxWindowX11::SetFocus()
374 Window xwindow
= (Window
) m_clientWindow
;
376 wxCHECK_RET( xwindow
, wxT("invalid window") );
378 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
381 if (GetName() == "scrollBar")
388 if (wxWindowIsVisible(xwindow
))
390 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
391 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
392 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
393 m_needsInputFocus
= FALSE
;
397 m_needsInputFocus
= TRUE
;
401 // Get the window with the focus
402 wxWindow
*wxWindowBase::FindFocus()
404 Window xfocus
= (Window
) 0;
407 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
410 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
413 win
= wxGetClientWindowFromTable( xfocus
);
422 // Enabling/disabling handled by event loop, and not sending events
424 bool wxWindowX11::Enable(bool enable
)
426 if ( !wxWindowBase::Enable(enable
) )
432 bool wxWindowX11::Show(bool show
)
434 wxWindowBase::Show(show
);
436 Window xwindow
= (Window
) m_mainWindow
;
437 Display
*xdisp
= wxGlobalDisplay();
440 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
441 XMapWindow(xdisp
, xwindow
);
445 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
446 XUnmapWindow(xdisp
, xwindow
);
452 // Raise the window to the top of the Z order
453 void wxWindowX11::Raise()
456 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
459 // Lower the window to the bottom of the Z order
460 void wxWindowX11::Lower()
463 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
466 void wxWindowX11::DoCaptureMouse()
468 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
470 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
481 Window xwindow
= (Window
) m_clientWindow
;
483 wxCHECK_RET( xwindow
, wxT("invalid window") );
485 g_captureWindow
= (wxWindow
*) this;
489 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
491 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
495 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
498 if (res
!= GrabSuccess
)
501 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
503 if (res
== GrabNotViewable
)
505 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
507 g_captureWindow
= NULL
;
511 m_winCaptured
= TRUE
;
515 void wxWindowX11::DoReleaseMouse()
517 g_captureWindow
= NULL
;
519 if ( !m_winCaptured
)
522 Window xwindow
= (Window
) m_clientWindow
;
526 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
529 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
531 m_winCaptured
= FALSE
;
534 bool wxWindowX11::SetFont(const wxFont
& font
)
536 if ( !wxWindowBase::SetFont(font
) )
545 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
547 if ( !wxWindowBase::SetCursor(cursor
) )
553 Window xwindow
= (Window
) m_clientWindow
;
555 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
557 wxCursor cursorToUse
;
559 cursorToUse
= m_cursor
;
561 cursorToUse
= *wxSTANDARD_CURSOR
;
563 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
565 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
570 // Coordinates relative to the window
571 void wxWindowX11::WarpPointer (int x
, int y
)
573 Window xwindow
= (Window
) m_clientWindow
;
575 wxCHECK_RET( xwindow
, wxT("invalid window") );
577 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
580 // Does a physical scroll
581 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
583 // No scrolling requested.
584 if ((dx
== 0) && (dy
== 0)) return;
586 if (!m_updateRegion
.IsEmpty())
588 m_updateRegion
.Offset( dx
, dy
);
592 GetSize( &cw
, &ch
); // GetClientSize() ??
593 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
596 if (!m_clearRegion
.IsEmpty())
598 m_clearRegion
.Offset( dx
, dy
);
602 GetSize( &cw
, &ch
); // GetClientSize() ??
603 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
606 Window xwindow
= (Window
) GetClientAreaWindow();
608 wxCHECK_RET( xwindow
, wxT("invalid window") );
610 Display
*xdisplay
= wxGlobalDisplay();
612 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
613 XSetGraphicsExposures( xdisplay
, xgc
, True
);
631 GetClientSize( &cw
, &ch
);
634 #if wxUSE_TWO_WINDOWS
635 wxPoint
offset( 0,0 );
637 wxPoint offset
= GetClientAreaOrigin();
642 int w
= cw
- abs(dx
);
643 int h
= ch
- abs(dy
);
645 if ((h
< 0) || (w
< 0))
652 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
653 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
654 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
655 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
660 if (dx
< 0) s_x
+= -dx
;
661 if (dy
< 0) s_y
+= -dy
;
662 if (dx
> 0) d_x
= dx
+ offset
.x
;
663 if (dy
> 0) d_y
= dy
+ offset
.y
;
665 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
667 // 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 );
669 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
671 m_updateRegion
.Union( rect
);
672 m_clearRegion
.Union( rect
);
675 XFreeGC( xdisplay
, xgc
);
678 // ---------------------------------------------------------------------------
680 // ---------------------------------------------------------------------------
682 #if wxUSE_DRAG_AND_DROP
684 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
691 // Old style file-manager drag&drop
692 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
697 // ----------------------------------------------------------------------------
699 // ----------------------------------------------------------------------------
703 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
708 #endif // wxUSE_TOOLTIPS
710 // ---------------------------------------------------------------------------
711 // moving and resizing
712 // ---------------------------------------------------------------------------
714 bool wxWindowX11::PreResize()
720 void wxWindowX11::DoGetSize(int *x
, int *y
) const
722 Window xwindow
= (Window
) m_mainWindow
;
724 wxCHECK_RET( xwindow
, wxT("invalid window") );
726 //XSync(wxGlobalDisplay(), False);
728 XWindowAttributes attr
;
729 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
734 *x
= attr
.width
/* + 2*m_borderSize */ ;
735 *y
= attr
.height
/* + 2*m_borderSize */ ;
739 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
741 Window window
= (Window
) m_mainWindow
;
744 //XSync(wxGlobalDisplay(), False);
745 XWindowAttributes attr
;
746 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
754 // We may be faking the client origin. So a window that's really at (0, 30)
755 // may appear (to wxWin apps) to be at (0, 0).
758 wxPoint
pt(GetParent()->GetClientAreaOrigin());
766 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
768 Display
*display
= wxGlobalDisplay();
769 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
770 Window thisWindow
= (Window
) m_clientWindow
;
775 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
778 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
780 Display
*display
= wxGlobalDisplay();
781 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
782 Window thisWindow
= (Window
) m_clientWindow
;
787 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
791 // Get size *available for subwindows* i.e. excluding menu bar etc.
792 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
794 Window window
= (Window
) m_mainWindow
;
798 XWindowAttributes attr
;
799 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
810 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
812 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
814 Window xwindow
= (Window
) m_mainWindow
;
816 wxCHECK_RET( xwindow
, wxT("invalid window") );
818 XWindowAttributes attr
;
819 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
820 wxCHECK_RET( status
, wxT("invalid window attributes") );
824 int new_w
= attr
.width
;
825 int new_h
= attr
.height
;
827 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
830 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
833 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
836 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
852 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
855 void wxWindowX11::DoSetClientSize(int width
, int height
)
857 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
859 Window xwindow
= (Window
) m_mainWindow
;
861 wxCHECK_RET( xwindow
, wxT("invalid window") );
863 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
865 if (m_mainWindow
!= m_clientWindow
)
867 xwindow
= (Window
) m_clientWindow
;
869 wxWindow
*window
= (wxWindow
*) this;
870 wxRenderer
*renderer
= window
->GetRenderer();
873 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
874 width
-= border
.x
+ border
.width
;
875 height
-= border
.y
+ border
.height
;
878 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
882 // For implementation purposes - sometimes decorations make the client area
884 wxPoint
wxWindowX11::GetClientAreaOrigin() const
886 return wxPoint(0, 0);
889 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
891 Window xwindow
= (Window
) m_mainWindow
;
893 wxCHECK_RET( xwindow
, wxT("invalid window") );
897 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
898 if (m_mainWindow
!= m_clientWindow
)
900 xwindow
= (Window
) m_clientWindow
;
902 wxWindow
*window
= (wxWindow
*) this;
903 wxRenderer
*renderer
= window
->GetRenderer();
906 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
909 width
-= border
.x
+ border
.width
;
910 height
-= border
.y
+ border
.height
;
918 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
919 if (sb
&& sb
->IsShown())
921 wxSize size
= sb
->GetSize();
924 sb
= window
->GetScrollbar( wxVERTICAL
);
925 if (sb
&& sb
->IsShown())
927 wxSize size
= sb
->GetSize();
931 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
936 XWindowChanges windowChanges
;
939 windowChanges
.width
= width
;
940 windowChanges
.height
= height
;
941 windowChanges
.stack_mode
= 0;
942 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
944 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
949 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
957 XSizeHints sizeHints
;
960 if (minW
> -1 && minH
> -1)
962 sizeHints
.flags
|= PMinSize
;
963 sizeHints
.min_width
= minW
;
964 sizeHints
.min_height
= minH
;
966 if (maxW
> -1 && maxH
> -1)
968 sizeHints
.flags
|= PMaxSize
;
969 sizeHints
.max_width
= maxW
;
970 sizeHints
.max_height
= maxH
;
972 if (incW
> -1 && incH
> -1)
974 sizeHints
.flags
|= PResizeInc
;
975 sizeHints
.width_inc
= incW
;
976 sizeHints
.height_inc
= incH
;
979 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
983 // ---------------------------------------------------------------------------
985 // ---------------------------------------------------------------------------
987 int wxWindowX11::GetCharHeight() const
989 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
991 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
993 int direction
, ascent
, descent
;
995 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
998 // return (overall.ascent + overall.descent);
999 return (ascent
+ descent
);
1002 int wxWindowX11::GetCharWidth() const
1004 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1006 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1008 int direction
, ascent
, descent
;
1009 XCharStruct overall
;
1010 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1011 &descent
, &overall
);
1013 return overall
.width
;
1016 void wxWindowX11::GetTextExtent(const wxString
& string
,
1018 int *descent
, int *externalLeading
,
1019 const wxFont
*theFont
) const
1021 wxFont fontToUse
= m_font
;
1022 if (theFont
) fontToUse
= *theFont
;
1024 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1026 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1028 int direction
, ascent
, descent2
;
1029 XCharStruct overall
;
1030 int slen
= string
.Len();
1034 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1035 &ascent
, &descent2
, &overall
);
1038 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1039 &direction
, &ascent
, &descent2
, &overall
);
1042 *x
= (overall
.width
);
1044 *y
= (ascent
+ descent2
);
1046 *descent
= descent2
;
1047 if (externalLeading
)
1048 *externalLeading
= 0;
1052 // ----------------------------------------------------------------------------
1054 // ----------------------------------------------------------------------------
1056 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1062 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1063 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1068 GetSize( &width
, &height
);
1070 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1071 m_clearRegion
.Clear();
1072 m_clearRegion
.Union( 0, 0, width
, height
);
1078 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1079 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1084 GetSize( &width
, &height
);
1086 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1087 m_updateRegion
.Clear();
1088 m_updateRegion
.Union( 0, 0, width
, height
);
1092 void wxWindowX11::Update()
1096 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1097 // Send nc paint events.
1098 SendNcPaintEvents();
1101 if (!m_updateRegion
.IsEmpty())
1103 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1104 // Actually send erase events.
1107 // Actually send paint events.
1112 void wxWindowX11::Clear()
1114 // wxClientDC dc((wxWindow*) this);
1115 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1116 // dc.SetBackground(brush);
1120 void wxWindowX11::SendEraseEvents()
1122 if (m_clearRegion
.IsEmpty()) return;
1124 wxClientDC
dc( (wxWindow
*)this );
1125 dc
.SetClippingRegion( m_clearRegion
);
1127 wxEraseEvent
erase_event( GetId(), &dc
);
1128 erase_event
.SetEventObject( this );
1130 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1132 Display
*xdisplay
= wxGlobalDisplay();
1133 Window xwindow
= (Window
) GetClientAreaWindow();
1134 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1136 wxRegionIterator
upd( m_clearRegion
);
1139 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1140 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1145 m_clearRegion
.Clear();
1148 void wxWindowX11::SendPaintEvents()
1150 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1152 m_clipPaintRegion
= TRUE
;
1154 wxPaintEvent
paint_event( GetId() );
1155 paint_event
.SetEventObject( this );
1156 GetEventHandler()->ProcessEvent( paint_event
);
1158 m_updateRegion
.Clear();
1160 m_clipPaintRegion
= FALSE
;
1163 void wxWindowX11::SendNcPaintEvents()
1165 wxWindow
*window
= (wxWindow
*) this;
1167 // All this for drawing the small square between the scrollbars.
1172 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1173 if (sb
&& sb
->IsShown())
1175 height
= sb
->GetSize().y
;
1176 y
= sb
->GetPosition().y
;
1178 sb
= window
->GetScrollbar( wxVERTICAL
);
1179 if (sb
&& sb
->IsShown())
1181 width
= sb
->GetSize().x
;
1182 x
= sb
->GetPosition().x
;
1184 Display
*xdisplay
= wxGlobalDisplay();
1185 Window xwindow
= (Window
) GetMainWindow();
1186 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1187 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1188 colour
.CalcPixel( (WXColormap
) cm
);
1190 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1192 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1196 wxNcPaintEvent
nc_paint_event( GetId() );
1197 nc_paint_event
.SetEventObject( this );
1198 GetEventHandler()->ProcessEvent( nc_paint_event
);
1200 m_updateNcArea
= FALSE
;
1203 // ----------------------------------------------------------------------------
1205 // ----------------------------------------------------------------------------
1207 // Responds to colour changes: passes event on to children.
1208 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1210 wxWindowList::Node
*node
= GetChildren().GetFirst();
1213 // Only propagate to non-top-level windows
1214 wxWindow
*win
= node
->GetData();
1215 if ( win
->GetParent() )
1217 wxSysColourChangedEvent event2
;
1218 event
.m_eventObject
= win
;
1219 win
->GetEventHandler()->ProcessEvent(event2
);
1222 node
= node
->GetNext();
1226 // See handler for InFocus case in app.cpp for details.
1227 wxWindow
* g_GettingFocus
= NULL
;
1229 void wxWindowX11::OnInternalIdle()
1231 // Update invalidated regions.
1234 // This calls the UI-update mechanism (querying windows for
1235 // menu/toolbar/control state information)
1238 // Set the input focus if couldn't do it before
1239 if (m_needsInputFocus
)
1243 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1244 printf(msg
.c_str());
1247 // If it couldn't set the focus now, there's
1248 // no point in trying again.
1249 m_needsInputFocus
= FALSE
;
1251 g_GettingFocus
= NULL
;
1254 // ----------------------------------------------------------------------------
1255 // function which maintain the global hash table mapping Widgets to wxWindows
1256 // ----------------------------------------------------------------------------
1258 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1260 wxWindow
*oldItem
= NULL
;
1261 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1263 wxLogDebug("Widget table clash: new widget is %ld, %s",
1264 (long)w
, win
->GetClassInfo()->GetClassName());
1268 wxWidgetHashTable
->Put((long) w
, win
);
1270 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1271 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1276 wxWindow
*wxGetWindowFromTable(Window w
)
1278 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1281 void wxDeleteWindowFromTable(Window w
)
1283 wxWidgetHashTable
->Delete((long)w
);
1286 // ----------------------------------------------------------------------------
1287 // function which maintain the global hash table mapping client widgets
1288 // ----------------------------------------------------------------------------
1290 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1292 wxWindow
*oldItem
= NULL
;
1293 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1295 wxLogDebug("Client window table clash: new window is %ld, %s",
1296 (long)w
, win
->GetClassInfo()->GetClassName());
1300 wxClientWidgetHashTable
->Put((long) w
, win
);
1302 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1303 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1308 wxWindow
*wxGetClientWindowFromTable(Window w
)
1310 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1313 void wxDeleteClientWindowFromTable(Window w
)
1315 wxClientWidgetHashTable
->Delete((long)w
);
1318 // ----------------------------------------------------------------------------
1319 // add/remove window from the table
1320 // ----------------------------------------------------------------------------
1322 // ----------------------------------------------------------------------------
1323 // X11-specific accessors
1324 // ----------------------------------------------------------------------------
1326 WXWindow
wxWindowX11::GetMainWindow() const
1328 return m_mainWindow
;
1331 WXWindow
wxWindowX11::GetClientAreaWindow() const
1333 return m_clientWindow
;
1336 // ----------------------------------------------------------------------------
1337 // TranslateXXXEvent() functions
1338 // ----------------------------------------------------------------------------
1340 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1342 switch (XEventGetType(xevent
))
1350 wxEventType eventType
= wxEVT_NULL
;
1352 if (XEventGetType(xevent
) == EnterNotify
)
1354 //if (local_event.xcrossing.mode!=NotifyNormal)
1355 // return ; // Ignore grab events
1356 eventType
= wxEVT_ENTER_WINDOW
;
1357 // canvas->GetEventHandler()->OnSetFocus();
1359 else if (XEventGetType(xevent
) == LeaveNotify
)
1361 //if (local_event.xcrossingr.mode!=NotifyNormal)
1362 // return ; // Ignore grab events
1363 eventType
= wxEVT_LEAVE_WINDOW
;
1364 // canvas->GetEventHandler()->OnKillFocus();
1366 else if (XEventGetType(xevent
) == MotionNotify
)
1368 eventType
= wxEVT_MOTION
;
1370 else if (XEventGetType(xevent
) == ButtonPress
)
1372 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1374 if (XButtonEventLChanged(xevent
))
1376 eventType
= wxEVT_LEFT_DOWN
;
1379 else if (XButtonEventMChanged(xevent
))
1381 eventType
= wxEVT_MIDDLE_DOWN
;
1384 else if (XButtonEventRChanged(xevent
))
1386 eventType
= wxEVT_RIGHT_DOWN
;
1390 // check for a double click
1391 // TODO: where can we get this value from?
1392 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1393 long dclickTime
= 200;
1394 long ts
= wxevent
.GetTimestamp();
1396 int buttonLast
= win
->GetLastClickedButton();
1397 long lastTS
= win
->GetLastClickTime();
1398 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1401 win
->SetLastClick(0, ts
);
1402 if ( eventType
== wxEVT_LEFT_DOWN
)
1403 eventType
= wxEVT_LEFT_DCLICK
;
1404 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1405 eventType
= wxEVT_MIDDLE_DCLICK
;
1406 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1407 eventType
= wxEVT_RIGHT_DCLICK
;
1411 // not fast enough or different button
1412 win
->SetLastClick(button
, ts
);
1415 else if (XEventGetType(xevent
) == ButtonRelease
)
1417 if (XButtonEventLChanged(xevent
))
1419 eventType
= wxEVT_LEFT_UP
;
1421 else if (XButtonEventMChanged(xevent
))
1423 eventType
= wxEVT_MIDDLE_UP
;
1425 else if (XButtonEventRChanged(xevent
))
1427 eventType
= wxEVT_RIGHT_UP
;
1436 wxevent
.SetEventType(eventType
);
1438 wxevent
.m_x
= XButtonEventGetX(xevent
);
1439 wxevent
.m_y
= XButtonEventGetY(xevent
);
1441 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1442 || (XButtonEventLIsDown(xevent
)
1443 && (eventType
!= wxEVT_LEFT_UP
)));
1444 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1445 || (XButtonEventMIsDown(xevent
)
1446 && (eventType
!= wxEVT_MIDDLE_UP
)));
1447 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1448 || (XButtonEventRIsDown (xevent
)
1449 && (eventType
!= wxEVT_RIGHT_UP
)));
1451 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1452 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1453 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1454 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1456 wxevent
.SetId(win
->GetId());
1457 wxevent
.SetEventObject(win
);
1465 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1467 switch (XEventGetType(xevent
))
1475 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1476 int id
= wxCharCodeXToWX (keySym
);
1478 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1479 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1480 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1481 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1482 wxevent
.SetEventObject(win
);
1483 wxevent
.m_keyCode
= toupper(id
);
1484 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1486 wxevent
.m_x
= XKeyEventGetX(xevent
);
1487 wxevent
.m_y
= XKeyEventGetY(xevent
);
1501 // ----------------------------------------------------------------------------
1503 // ----------------------------------------------------------------------------
1505 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1507 wxWindowBase::SetBackgroundColour(col
);
1509 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1510 int xscreen
= DefaultScreen( xdisplay
);
1511 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1513 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1515 // We don't set the background colour as we paint
1516 // the background ourselves.
1517 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1522 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1524 if ( !wxWindowBase::SetForegroundColour(col
) )
1530 // ----------------------------------------------------------------------------
1532 // ----------------------------------------------------------------------------
1534 wxWindow
*wxGetActiveWindow()
1537 wxFAIL_MSG("Not implemented");
1542 wxWindow
*wxWindowBase::GetCapture()
1544 return (wxWindow
*)g_captureWindow
;
1548 // Find the wxWindow at the current mouse position, returning the mouse
1550 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1552 return wxFindWindowAtPoint(wxGetMousePosition());
1555 // Get the current mouse position.
1556 wxPoint
wxGetMousePosition()
1560 return wxPoint(0, 0);
1562 Display
*display
= wxGlobalDisplay();
1563 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1564 Window rootReturn
, childReturn
;
1565 int rootX
, rootY
, winX
, winY
;
1566 unsigned int maskReturn
;
1568 XQueryPointer (display
,
1572 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1573 return wxPoint(rootX
, rootY
);
1578 // ----------------------------------------------------------------------------
1579 // wxNoOptimize: switch off size optimization
1580 // ----------------------------------------------------------------------------
1582 int wxNoOptimize::ms_count
= 0;
1585 // ----------------------------------------------------------------------------
1587 // ----------------------------------------------------------------------------
1589 class wxWinModule
: public wxModule
1596 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1599 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1601 bool wxWinModule::OnInit()
1603 Display
*xdisplay
= wxGlobalDisplay();
1604 int xscreen
= DefaultScreen( xdisplay
);
1605 Window xroot
= RootWindow( xdisplay
, xscreen
);
1606 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1607 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1612 void wxWinModule::OnExit()
1614 Display
*xdisplay
= wxGlobalDisplay();
1615 XFreeGC( xdisplay
, g_eraseGC
);