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
->GetClientAreaWindow();
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 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
390 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
391 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
392 m_needsInputFocus
= FALSE
;
396 m_needsInputFocus
= TRUE
;
400 // Get the window with the focus
401 wxWindow
*wxWindowBase::FindFocus()
403 Window xfocus
= (Window
) 0;
406 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
409 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
412 win
= wxGetClientWindowFromTable( xfocus
);
421 // Enabling/disabling handled by event loop, and not sending events
423 bool wxWindowX11::Enable(bool enable
)
425 if ( !wxWindowBase::Enable(enable
) )
431 bool wxWindowX11::Show(bool show
)
433 wxWindowBase::Show(show
);
435 Window xwindow
= (Window
) m_mainWindow
;
436 Display
*xdisp
= wxGlobalDisplay();
439 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
440 XMapWindow(xdisp
, xwindow
);
444 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
445 XUnmapWindow(xdisp
, xwindow
);
451 // Raise the window to the top of the Z order
452 void wxWindowX11::Raise()
455 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
458 // Lower the window to the bottom of the Z order
459 void wxWindowX11::Lower()
462 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
465 void wxWindowX11::DoCaptureMouse()
467 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
469 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
480 Window xwindow
= (Window
) m_clientWindow
;
482 wxCHECK_RET( xwindow
, wxT("invalid window") );
484 g_captureWindow
= (wxWindow
*) this;
488 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
490 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
494 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
497 if (res
!= GrabSuccess
)
500 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
502 if (res
== GrabNotViewable
)
504 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
506 g_captureWindow
= NULL
;
510 m_winCaptured
= TRUE
;
514 void wxWindowX11::DoReleaseMouse()
516 g_captureWindow
= NULL
;
518 if ( !m_winCaptured
)
521 Window xwindow
= (Window
) m_clientWindow
;
525 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
528 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
530 m_winCaptured
= FALSE
;
533 bool wxWindowX11::SetFont(const wxFont
& font
)
535 if ( !wxWindowBase::SetFont(font
) )
544 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
546 if ( !wxWindowBase::SetCursor(cursor
) )
552 Window xwindow
= (Window
) m_clientWindow
;
554 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
556 wxCursor cursorToUse
;
558 cursorToUse
= m_cursor
;
560 cursorToUse
= *wxSTANDARD_CURSOR
;
562 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
564 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
569 // Coordinates relative to the window
570 void wxWindowX11::WarpPointer (int x
, int y
)
572 Window xwindow
= (Window
) m_clientWindow
;
574 wxCHECK_RET( xwindow
, wxT("invalid window") );
576 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
579 // Does a physical scroll
580 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
582 // No scrolling requested.
583 if ((dx
== 0) && (dy
== 0)) return;
585 if (!m_updateRegion
.IsEmpty())
587 m_updateRegion
.Offset( dx
, dy
);
591 GetSize( &cw
, &ch
); // GetClientSize() ??
592 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
595 if (!m_clearRegion
.IsEmpty())
597 m_clearRegion
.Offset( dx
, dy
);
601 GetSize( &cw
, &ch
); // GetClientSize() ??
602 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
605 Window xwindow
= (Window
) GetClientAreaWindow();
607 wxCHECK_RET( xwindow
, wxT("invalid window") );
609 Display
*xdisplay
= wxGlobalDisplay();
611 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
612 XSetGraphicsExposures( xdisplay
, xgc
, True
);
630 GetClientSize( &cw
, &ch
);
633 #if wxUSE_TWO_WINDOWS
634 wxPoint
offset( 0,0 );
636 wxPoint offset
= GetClientAreaOrigin();
641 int w
= cw
- abs(dx
);
642 int h
= ch
- abs(dy
);
644 if ((h
< 0) || (w
< 0))
651 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
652 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
653 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
654 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
659 if (dx
< 0) s_x
+= -dx
;
660 if (dy
< 0) s_y
+= -dy
;
661 if (dx
> 0) d_x
= dx
+ offset
.x
;
662 if (dy
> 0) d_y
= dy
+ offset
.y
;
664 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
666 // 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 );
668 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
670 m_updateRegion
.Union( rect
);
671 m_clearRegion
.Union( rect
);
674 XFreeGC( xdisplay
, xgc
);
677 // ---------------------------------------------------------------------------
679 // ---------------------------------------------------------------------------
681 #if wxUSE_DRAG_AND_DROP
683 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
690 // Old style file-manager drag&drop
691 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
696 // ----------------------------------------------------------------------------
698 // ----------------------------------------------------------------------------
702 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
707 #endif // wxUSE_TOOLTIPS
709 // ---------------------------------------------------------------------------
710 // moving and resizing
711 // ---------------------------------------------------------------------------
713 bool wxWindowX11::PreResize()
719 void wxWindowX11::DoGetSize(int *x
, int *y
) const
721 Window xwindow
= (Window
) m_mainWindow
;
723 wxCHECK_RET( xwindow
, wxT("invalid window") );
725 //XSync(wxGlobalDisplay(), False);
727 XWindowAttributes attr
;
728 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
733 *x
= attr
.width
/* + 2*m_borderSize */ ;
734 *y
= attr
.height
/* + 2*m_borderSize */ ;
738 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
740 Window window
= (Window
) m_mainWindow
;
743 //XSync(wxGlobalDisplay(), False);
744 XWindowAttributes attr
;
745 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
753 // We may be faking the client origin. So a window that's really at (0, 30)
754 // may appear (to wxWin apps) to be at (0, 0).
757 wxPoint
pt(GetParent()->GetClientAreaOrigin());
765 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
767 Display
*display
= wxGlobalDisplay();
768 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
769 Window thisWindow
= (Window
) m_clientWindow
;
774 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
777 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
779 Display
*display
= wxGlobalDisplay();
780 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
781 Window thisWindow
= (Window
) m_clientWindow
;
786 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
790 // Get size *available for subwindows* i.e. excluding menu bar etc.
791 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
793 Window window
= (Window
) m_mainWindow
;
797 XWindowAttributes attr
;
798 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
809 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
811 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
813 Window xwindow
= (Window
) m_mainWindow
;
815 wxCHECK_RET( xwindow
, wxT("invalid window") );
817 XWindowAttributes attr
;
818 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
819 wxCHECK_RET( status
, wxT("invalid window attributes") );
823 int new_w
= attr
.width
;
824 int new_h
= attr
.height
;
826 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
829 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
832 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
835 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
851 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
854 void wxWindowX11::DoSetClientSize(int width
, int height
)
856 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
858 Window xwindow
= (Window
) m_mainWindow
;
860 wxCHECK_RET( xwindow
, wxT("invalid window") );
862 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
864 if (m_mainWindow
!= m_clientWindow
)
866 xwindow
= (Window
) m_clientWindow
;
868 wxWindow
*window
= (wxWindow
*) this;
869 wxRenderer
*renderer
= window
->GetRenderer();
872 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
873 width
-= border
.x
+ border
.width
;
874 height
-= border
.y
+ border
.height
;
877 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
881 // For implementation purposes - sometimes decorations make the client area
883 wxPoint
wxWindowX11::GetClientAreaOrigin() const
885 return wxPoint(0, 0);
888 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
890 Window xwindow
= (Window
) m_mainWindow
;
892 wxCHECK_RET( xwindow
, wxT("invalid window") );
896 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
897 if (m_mainWindow
!= m_clientWindow
)
899 xwindow
= (Window
) m_clientWindow
;
901 wxWindow
*window
= (wxWindow
*) this;
902 wxRenderer
*renderer
= window
->GetRenderer();
905 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
908 width
-= border
.x
+ border
.width
;
909 height
-= border
.y
+ border
.height
;
917 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
918 if (sb
&& sb
->IsShown())
920 wxSize size
= sb
->GetSize();
923 sb
= window
->GetScrollbar( wxVERTICAL
);
924 if (sb
&& sb
->IsShown())
926 wxSize size
= sb
->GetSize();
930 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
935 XWindowChanges windowChanges
;
938 windowChanges
.width
= width
;
939 windowChanges
.height
= height
;
940 windowChanges
.stack_mode
= 0;
941 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
943 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
948 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
956 XSizeHints sizeHints
;
959 if (minW
> -1 && minH
> -1)
961 sizeHints
.flags
|= PMinSize
;
962 sizeHints
.min_width
= minW
;
963 sizeHints
.min_height
= minH
;
965 if (maxW
> -1 && maxH
> -1)
967 sizeHints
.flags
|= PMaxSize
;
968 sizeHints
.max_width
= maxW
;
969 sizeHints
.max_height
= maxH
;
971 if (incW
> -1 && incH
> -1)
973 sizeHints
.flags
|= PResizeInc
;
974 sizeHints
.width_inc
= incW
;
975 sizeHints
.height_inc
= incH
;
978 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
982 // ---------------------------------------------------------------------------
984 // ---------------------------------------------------------------------------
986 int wxWindowX11::GetCharHeight() const
988 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
990 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
992 int direction
, ascent
, descent
;
994 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
997 // return (overall.ascent + overall.descent);
998 return (ascent
+ descent
);
1001 int wxWindowX11::GetCharWidth() const
1003 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1005 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1007 int direction
, ascent
, descent
;
1008 XCharStruct overall
;
1009 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1010 &descent
, &overall
);
1012 return overall
.width
;
1015 void wxWindowX11::GetTextExtent(const wxString
& string
,
1017 int *descent
, int *externalLeading
,
1018 const wxFont
*theFont
) const
1020 wxFont fontToUse
= m_font
;
1021 if (theFont
) fontToUse
= *theFont
;
1023 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1025 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1027 int direction
, ascent
, descent2
;
1028 XCharStruct overall
;
1029 int slen
= string
.Len();
1033 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1034 &ascent
, &descent2
, &overall
);
1037 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1038 &direction
, &ascent
, &descent2
, &overall
);
1041 *x
= (overall
.width
);
1043 *y
= (ascent
+ descent2
);
1045 *descent
= descent2
;
1046 if (externalLeading
)
1047 *externalLeading
= 0;
1051 // ----------------------------------------------------------------------------
1053 // ----------------------------------------------------------------------------
1055 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1061 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1062 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1067 GetSize( &width
, &height
);
1069 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1070 m_clearRegion
.Clear();
1071 m_clearRegion
.Union( 0, 0, width
, height
);
1077 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1078 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1083 GetSize( &width
, &height
);
1085 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1086 m_updateRegion
.Clear();
1087 m_updateRegion
.Union( 0, 0, width
, height
);
1091 void wxWindowX11::Update()
1095 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1096 // Send nc paint events.
1097 SendNcPaintEvents();
1100 if (!m_updateRegion
.IsEmpty())
1102 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1103 // Actually send erase events.
1106 // Actually send paint events.
1111 void wxWindowX11::Clear()
1113 // wxClientDC dc((wxWindow*) this);
1114 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1115 // dc.SetBackground(brush);
1119 void wxWindowX11::SendEraseEvents()
1121 if (m_clearRegion
.IsEmpty()) return;
1123 wxClientDC
dc( (wxWindow
*)this );
1124 dc
.SetClippingRegion( m_clearRegion
);
1126 wxEraseEvent
erase_event( GetId(), &dc
);
1127 erase_event
.SetEventObject( this );
1129 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1131 Display
*xdisplay
= wxGlobalDisplay();
1132 Window xwindow
= (Window
) GetClientAreaWindow();
1133 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1135 wxRegionIterator
upd( m_clearRegion
);
1138 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1139 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1144 m_clearRegion
.Clear();
1147 void wxWindowX11::SendPaintEvents()
1149 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1151 m_clipPaintRegion
= TRUE
;
1153 wxPaintEvent
paint_event( GetId() );
1154 paint_event
.SetEventObject( this );
1155 GetEventHandler()->ProcessEvent( paint_event
);
1157 m_updateRegion
.Clear();
1159 m_clipPaintRegion
= FALSE
;
1162 void wxWindowX11::SendNcPaintEvents()
1164 wxWindow
*window
= (wxWindow
*) this;
1166 // All this for drawing the small square between the scrollbars.
1171 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1172 if (sb
&& sb
->IsShown())
1174 height
= sb
->GetSize().y
;
1175 y
= sb
->GetPosition().y
;
1177 sb
= window
->GetScrollbar( wxVERTICAL
);
1178 if (sb
&& sb
->IsShown())
1180 width
= sb
->GetSize().x
;
1181 x
= sb
->GetPosition().x
;
1183 Display
*xdisplay
= wxGlobalDisplay();
1184 Window xwindow
= (Window
) GetMainWindow();
1185 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1186 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1187 colour
.CalcPixel( (WXColormap
) cm
);
1189 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1191 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1195 wxNcPaintEvent
nc_paint_event( GetId() );
1196 nc_paint_event
.SetEventObject( this );
1197 GetEventHandler()->ProcessEvent( nc_paint_event
);
1199 m_updateNcArea
= FALSE
;
1202 // ----------------------------------------------------------------------------
1204 // ----------------------------------------------------------------------------
1206 // Responds to colour changes: passes event on to children.
1207 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1209 wxWindowList::Node
*node
= GetChildren().GetFirst();
1212 // Only propagate to non-top-level windows
1213 wxWindow
*win
= node
->GetData();
1214 if ( win
->GetParent() )
1216 wxSysColourChangedEvent event2
;
1217 event
.m_eventObject
= win
;
1218 win
->GetEventHandler()->ProcessEvent(event2
);
1221 node
= node
->GetNext();
1225 // See handler for InFocus case in app.cpp for details.
1226 wxWindow
* g_GettingFocus
= NULL
;
1228 void wxWindowX11::OnInternalIdle()
1230 // Update invalidated regions.
1233 // This calls the UI-update mechanism (querying windows for
1234 // menu/toolbar/control state information)
1237 // Set the input focus if couldn't do it before
1238 if (m_needsInputFocus
)
1242 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1243 printf(msg
.c_str());
1246 // If it couldn't set the focus now, there's
1247 // no point in trying again.
1248 m_needsInputFocus
= FALSE
;
1250 g_GettingFocus
= NULL
;
1253 // ----------------------------------------------------------------------------
1254 // function which maintain the global hash table mapping Widgets to wxWindows
1255 // ----------------------------------------------------------------------------
1257 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1259 wxWindow
*oldItem
= NULL
;
1260 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1262 wxLogDebug("Widget table clash: new widget is %ld, %s",
1263 (long)w
, win
->GetClassInfo()->GetClassName());
1267 wxWidgetHashTable
->Put((long) w
, win
);
1269 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1270 w
, win
, win
->GetClassInfo()->GetClassName());
1275 wxWindow
*wxGetWindowFromTable(Window w
)
1277 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1280 void wxDeleteWindowFromTable(Window w
)
1282 wxWidgetHashTable
->Delete((long)w
);
1285 // ----------------------------------------------------------------------------
1286 // function which maintain the global hash table mapping client widgets
1287 // ----------------------------------------------------------------------------
1289 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1291 wxWindow
*oldItem
= NULL
;
1292 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1294 wxLogDebug("Client window table clash: new window is %ld, %s",
1295 (long)w
, win
->GetClassInfo()->GetClassName());
1299 wxClientWidgetHashTable
->Put((long) w
, win
);
1301 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1302 w
, win
, win
->GetClassInfo()->GetClassName());
1307 wxWindow
*wxGetClientWindowFromTable(Window w
)
1309 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1312 void wxDeleteClientWindowFromTable(Window w
)
1314 wxClientWidgetHashTable
->Delete((long)w
);
1317 // ----------------------------------------------------------------------------
1318 // add/remove window from the table
1319 // ----------------------------------------------------------------------------
1321 // ----------------------------------------------------------------------------
1322 // X11-specific accessors
1323 // ----------------------------------------------------------------------------
1325 WXWindow
wxWindowX11::GetMainWindow() const
1327 return m_mainWindow
;
1330 WXWindow
wxWindowX11::GetClientAreaWindow() const
1332 return m_clientWindow
;
1335 // ----------------------------------------------------------------------------
1336 // TranslateXXXEvent() functions
1337 // ----------------------------------------------------------------------------
1339 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1341 switch (XEventGetType(xevent
))
1349 wxEventType eventType
= wxEVT_NULL
;
1351 if (XEventGetType(xevent
) == EnterNotify
)
1353 //if (local_event.xcrossing.mode!=NotifyNormal)
1354 // return ; // Ignore grab events
1355 eventType
= wxEVT_ENTER_WINDOW
;
1356 // canvas->GetEventHandler()->OnSetFocus();
1358 else if (XEventGetType(xevent
) == LeaveNotify
)
1360 //if (local_event.xcrossingr.mode!=NotifyNormal)
1361 // return ; // Ignore grab events
1362 eventType
= wxEVT_LEAVE_WINDOW
;
1363 // canvas->GetEventHandler()->OnKillFocus();
1365 else if (XEventGetType(xevent
) == MotionNotify
)
1367 eventType
= wxEVT_MOTION
;
1369 else if (XEventGetType(xevent
) == ButtonPress
)
1371 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1373 if (XButtonEventLChanged(xevent
))
1375 eventType
= wxEVT_LEFT_DOWN
;
1378 else if (XButtonEventMChanged(xevent
))
1380 eventType
= wxEVT_MIDDLE_DOWN
;
1383 else if (XButtonEventRChanged(xevent
))
1385 eventType
= wxEVT_RIGHT_DOWN
;
1389 // check for a double click
1390 // TODO: where can we get this value from?
1391 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1392 long dclickTime
= 200;
1393 long ts
= wxevent
.GetTimestamp();
1395 int buttonLast
= win
->GetLastClickedButton();
1396 long lastTS
= win
->GetLastClickTime();
1397 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1400 win
->SetLastClick(0, ts
);
1401 if ( eventType
== wxEVT_LEFT_DOWN
)
1402 eventType
= wxEVT_LEFT_DCLICK
;
1403 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1404 eventType
= wxEVT_MIDDLE_DCLICK
;
1405 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1406 eventType
= wxEVT_RIGHT_DCLICK
;
1410 // not fast enough or different button
1411 win
->SetLastClick(button
, ts
);
1414 else if (XEventGetType(xevent
) == ButtonRelease
)
1416 if (XButtonEventLChanged(xevent
))
1418 eventType
= wxEVT_LEFT_UP
;
1420 else if (XButtonEventMChanged(xevent
))
1422 eventType
= wxEVT_MIDDLE_UP
;
1424 else if (XButtonEventRChanged(xevent
))
1426 eventType
= wxEVT_RIGHT_UP
;
1435 wxevent
.SetEventType(eventType
);
1437 wxevent
.m_x
= XButtonEventGetX(xevent
);
1438 wxevent
.m_y
= XButtonEventGetY(xevent
);
1440 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1441 || (XButtonEventLIsDown(xevent
)
1442 && (eventType
!= wxEVT_LEFT_UP
)));
1443 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1444 || (XButtonEventMIsDown(xevent
)
1445 && (eventType
!= wxEVT_MIDDLE_UP
)));
1446 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1447 || (XButtonEventRIsDown (xevent
)
1448 && (eventType
!= wxEVT_RIGHT_UP
)));
1450 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1451 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1452 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1453 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1455 wxevent
.SetId(win
->GetId());
1456 wxevent
.SetEventObject(win
);
1464 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1466 switch (XEventGetType(xevent
))
1474 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1475 int id
= wxCharCodeXToWX (keySym
);
1477 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1478 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1479 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1480 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1481 wxevent
.SetEventObject(win
);
1482 wxevent
.m_keyCode
= id
;
1483 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1485 wxevent
.m_x
= XKeyEventGetX(xevent
);
1486 wxevent
.m_y
= XKeyEventGetY(xevent
);
1500 // ----------------------------------------------------------------------------
1502 // ----------------------------------------------------------------------------
1504 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1506 wxWindowBase::SetBackgroundColour(col
);
1508 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1509 int xscreen
= DefaultScreen( xdisplay
);
1510 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1512 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1514 // We don't set the background colour as we paint
1515 // the background ourselves.
1516 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1521 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1523 if ( !wxWindowBase::SetForegroundColour(col
) )
1529 // ----------------------------------------------------------------------------
1531 // ----------------------------------------------------------------------------
1533 wxWindow
*wxGetActiveWindow()
1536 wxFAIL_MSG("Not implemented");
1541 wxWindow
*wxWindowBase::GetCapture()
1543 return (wxWindow
*)g_captureWindow
;
1547 // Find the wxWindow at the current mouse position, returning the mouse
1549 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1551 return wxFindWindowAtPoint(wxGetMousePosition());
1554 // Get the current mouse position.
1555 wxPoint
wxGetMousePosition()
1559 return wxPoint(0, 0);
1561 Display
*display
= wxGlobalDisplay();
1562 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1563 Window rootReturn
, childReturn
;
1564 int rootX
, rootY
, winX
, winY
;
1565 unsigned int maskReturn
;
1567 XQueryPointer (display
,
1571 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1572 return wxPoint(rootX
, rootY
);
1577 // ----------------------------------------------------------------------------
1578 // wxNoOptimize: switch off size optimization
1579 // ----------------------------------------------------------------------------
1581 int wxNoOptimize::ms_count
= 0;
1584 // ----------------------------------------------------------------------------
1586 // ----------------------------------------------------------------------------
1588 class wxWinModule
: public wxModule
1595 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1598 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1600 bool wxWinModule::OnInit()
1602 Display
*xdisplay
= wxGlobalDisplay();
1603 int xscreen
= DefaultScreen( xdisplay
);
1604 Window xroot
= RootWindow( xdisplay
, xscreen
);
1605 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1606 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1611 void wxWinModule::OnExit()
1613 Display
*xdisplay
= wxGlobalDisplay();
1614 XFreeGC( xdisplay
, g_eraseGC
);