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 msg
.Printf("SetFocus: %s\n", GetClassInfo()->GetClassName());
403 // Get the window with the focus
404 wxWindow
*wxWindowBase::FindFocus()
406 Window xfocus
= (Window
) 0;
409 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
412 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
415 win
= wxGetClientWindowFromTable( xfocus
);
424 // Enabling/disabling handled by event loop, and not sending events
426 bool wxWindowX11::Enable(bool enable
)
428 if ( !wxWindowBase::Enable(enable
) )
434 bool wxWindowX11::Show(bool show
)
436 wxWindowBase::Show(show
);
438 Window xwindow
= (Window
) m_mainWindow
;
439 Display
*xdisp
= wxGlobalDisplay();
442 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
443 XMapWindow(xdisp
, xwindow
);
447 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
448 XUnmapWindow(xdisp
, xwindow
);
454 // Raise the window to the top of the Z order
455 void wxWindowX11::Raise()
458 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
461 // Lower the window to the bottom of the Z order
462 void wxWindowX11::Lower()
465 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
468 void wxWindowX11::DoCaptureMouse()
470 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
472 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
483 Window xwindow
= (Window
) m_clientWindow
;
485 wxCHECK_RET( xwindow
, wxT("invalid window") );
487 g_captureWindow
= (wxWindow
*) this;
491 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
493 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
497 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
500 if (res
!= GrabSuccess
)
503 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
505 if (res
== GrabNotViewable
)
507 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
509 g_captureWindow
= NULL
;
513 m_winCaptured
= TRUE
;
517 void wxWindowX11::DoReleaseMouse()
519 g_captureWindow
= NULL
;
521 if ( !m_winCaptured
)
524 Window xwindow
= (Window
) m_clientWindow
;
528 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
531 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
533 m_winCaptured
= FALSE
;
536 bool wxWindowX11::SetFont(const wxFont
& font
)
538 if ( !wxWindowBase::SetFont(font
) )
547 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
549 if ( !wxWindowBase::SetCursor(cursor
) )
555 Window xwindow
= (Window
) m_clientWindow
;
557 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
559 wxCursor cursorToUse
;
561 cursorToUse
= m_cursor
;
563 cursorToUse
= *wxSTANDARD_CURSOR
;
565 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
567 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
572 // Coordinates relative to the window
573 void wxWindowX11::WarpPointer (int x
, int y
)
575 Window xwindow
= (Window
) m_clientWindow
;
577 wxCHECK_RET( xwindow
, wxT("invalid window") );
579 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
582 // Does a physical scroll
583 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
585 // No scrolling requested.
586 if ((dx
== 0) && (dy
== 0)) return;
588 if (!m_updateRegion
.IsEmpty())
590 m_updateRegion
.Offset( dx
, dy
);
594 GetSize( &cw
, &ch
); // GetClientSize() ??
595 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
598 if (!m_clearRegion
.IsEmpty())
600 m_clearRegion
.Offset( dx
, dy
);
604 GetSize( &cw
, &ch
); // GetClientSize() ??
605 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
608 Window xwindow
= (Window
) GetClientWindow();
610 wxCHECK_RET( xwindow
, wxT("invalid window") );
612 Display
*xdisplay
= wxGlobalDisplay();
614 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
615 XSetGraphicsExposures( xdisplay
, xgc
, True
);
633 GetClientSize( &cw
, &ch
);
636 #if wxUSE_TWO_WINDOWS
637 wxPoint
offset( 0,0 );
639 wxPoint offset
= GetClientAreaOrigin();
644 int w
= cw
- abs(dx
);
645 int h
= ch
- abs(dy
);
647 if ((h
< 0) || (w
< 0))
654 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
655 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
656 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
657 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
662 if (dx
< 0) s_x
+= -dx
;
663 if (dy
< 0) s_y
+= -dy
;
664 if (dx
> 0) d_x
= dx
+ offset
.x
;
665 if (dy
> 0) d_y
= dy
+ offset
.y
;
667 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
669 // 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 );
671 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
673 m_updateRegion
.Union( rect
);
674 m_clearRegion
.Union( rect
);
677 XFreeGC( xdisplay
, xgc
);
680 // ---------------------------------------------------------------------------
682 // ---------------------------------------------------------------------------
684 #if wxUSE_DRAG_AND_DROP
686 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
693 // Old style file-manager drag&drop
694 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
699 // ----------------------------------------------------------------------------
701 // ----------------------------------------------------------------------------
705 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
710 #endif // wxUSE_TOOLTIPS
712 // ---------------------------------------------------------------------------
713 // moving and resizing
714 // ---------------------------------------------------------------------------
716 bool wxWindowX11::PreResize()
722 void wxWindowX11::DoGetSize(int *x
, int *y
) const
724 Window xwindow
= (Window
) m_mainWindow
;
726 wxCHECK_RET( xwindow
, wxT("invalid window") );
728 //XSync(wxGlobalDisplay(), False);
730 XWindowAttributes attr
;
731 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
736 *x
= attr
.width
/* + 2*m_borderSize */ ;
737 *y
= attr
.height
/* + 2*m_borderSize */ ;
741 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
743 Window window
= (Window
) m_mainWindow
;
746 //XSync(wxGlobalDisplay(), False);
747 XWindowAttributes attr
;
748 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
756 // We may be faking the client origin. So a window that's really at (0, 30)
757 // may appear (to wxWin apps) to be at (0, 0).
760 wxPoint
pt(GetParent()->GetClientAreaOrigin());
768 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
770 Display
*display
= wxGlobalDisplay();
771 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
772 Window thisWindow
= (Window
) m_clientWindow
;
777 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
780 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
782 Display
*display
= wxGlobalDisplay();
783 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
784 Window thisWindow
= (Window
) m_clientWindow
;
789 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
793 // Get size *available for subwindows* i.e. excluding menu bar etc.
794 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
796 Window window
= (Window
) m_mainWindow
;
800 XWindowAttributes attr
;
801 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
812 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
814 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
816 Window xwindow
= (Window
) m_mainWindow
;
818 wxCHECK_RET( xwindow
, wxT("invalid window") );
820 XWindowAttributes attr
;
821 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
822 wxCHECK_RET( status
, wxT("invalid window attributes") );
826 int new_w
= attr
.width
;
827 int new_h
= attr
.height
;
829 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
832 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
835 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
838 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
854 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
857 void wxWindowX11::DoSetClientSize(int width
, int height
)
859 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
861 Window xwindow
= (Window
) m_mainWindow
;
863 wxCHECK_RET( xwindow
, wxT("invalid window") );
865 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
867 if (m_mainWindow
!= m_clientWindow
)
869 xwindow
= (Window
) m_clientWindow
;
871 wxWindow
*window
= (wxWindow
*) this;
872 wxRenderer
*renderer
= window
->GetRenderer();
875 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
876 width
-= border
.x
+ border
.width
;
877 height
-= border
.y
+ border
.height
;
880 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
884 // For implementation purposes - sometimes decorations make the client area
886 wxPoint
wxWindowX11::GetClientAreaOrigin() const
888 return wxPoint(0, 0);
891 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
893 Window xwindow
= (Window
) m_mainWindow
;
895 wxCHECK_RET( xwindow
, wxT("invalid window") );
899 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
900 if (m_mainWindow
!= m_clientWindow
)
902 xwindow
= (Window
) m_clientWindow
;
904 wxWindow
*window
= (wxWindow
*) this;
905 wxRenderer
*renderer
= window
->GetRenderer();
908 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
911 width
-= border
.x
+ border
.width
;
912 height
-= border
.y
+ border
.height
;
920 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
921 if (sb
&& sb
->IsShown())
923 wxSize size
= sb
->GetSize();
926 sb
= window
->GetScrollbar( wxVERTICAL
);
927 if (sb
&& sb
->IsShown())
929 wxSize size
= sb
->GetSize();
933 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
938 XWindowChanges windowChanges
;
941 windowChanges
.width
= width
;
942 windowChanges
.height
= height
;
943 windowChanges
.stack_mode
= 0;
944 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
946 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
951 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
959 XSizeHints sizeHints
;
962 if (minW
> -1 && minH
> -1)
964 sizeHints
.flags
|= PMinSize
;
965 sizeHints
.min_width
= minW
;
966 sizeHints
.min_height
= minH
;
968 if (maxW
> -1 && maxH
> -1)
970 sizeHints
.flags
|= PMaxSize
;
971 sizeHints
.max_width
= maxW
;
972 sizeHints
.max_height
= maxH
;
974 if (incW
> -1 && incH
> -1)
976 sizeHints
.flags
|= PResizeInc
;
977 sizeHints
.width_inc
= incW
;
978 sizeHints
.height_inc
= incH
;
981 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
985 // ---------------------------------------------------------------------------
987 // ---------------------------------------------------------------------------
989 int wxWindowX11::GetCharHeight() const
991 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
993 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
995 int direction
, ascent
, descent
;
997 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1000 // return (overall.ascent + overall.descent);
1001 return (ascent
+ descent
);
1004 int wxWindowX11::GetCharWidth() const
1006 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1008 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1010 int direction
, ascent
, descent
;
1011 XCharStruct overall
;
1012 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1013 &descent
, &overall
);
1015 return overall
.width
;
1018 void wxWindowX11::GetTextExtent(const wxString
& string
,
1020 int *descent
, int *externalLeading
,
1021 const wxFont
*theFont
) const
1023 wxFont fontToUse
= m_font
;
1024 if (theFont
) fontToUse
= *theFont
;
1026 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1028 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1030 int direction
, ascent
, descent2
;
1031 XCharStruct overall
;
1032 int slen
= string
.Len();
1036 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1037 &ascent
, &descent2
, &overall
);
1040 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1041 &direction
, &ascent
, &descent2
, &overall
);
1044 *x
= (overall
.width
);
1046 *y
= (ascent
+ descent2
);
1048 *descent
= descent2
;
1049 if (externalLeading
)
1050 *externalLeading
= 0;
1054 // ----------------------------------------------------------------------------
1056 // ----------------------------------------------------------------------------
1058 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1064 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1065 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1070 GetSize( &width
, &height
);
1072 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1073 m_clearRegion
.Clear();
1074 m_clearRegion
.Union( 0, 0, width
, height
);
1080 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1081 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1086 GetSize( &width
, &height
);
1088 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1089 m_updateRegion
.Clear();
1090 m_updateRegion
.Union( 0, 0, width
, height
);
1094 void wxWindowX11::Update()
1098 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1099 // Send nc paint events.
1100 SendNcPaintEvents();
1103 if (!m_updateRegion
.IsEmpty())
1105 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1106 // Actually send erase events.
1109 // Actually send paint events.
1114 void wxWindowX11::Clear()
1116 // wxClientDC dc((wxWindow*) this);
1117 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1118 // dc.SetBackground(brush);
1122 void wxWindowX11::SendEraseEvents()
1124 if (m_clearRegion
.IsEmpty()) return;
1126 wxClientDC
dc( (wxWindow
*)this );
1127 dc
.SetClippingRegion( m_clearRegion
);
1129 wxEraseEvent
erase_event( GetId(), &dc
);
1130 erase_event
.SetEventObject( this );
1132 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1134 Display
*xdisplay
= wxGlobalDisplay();
1135 Window xwindow
= (Window
) GetClientWindow();
1136 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1138 wxRegionIterator
upd( m_clearRegion
);
1141 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1142 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1147 m_clearRegion
.Clear();
1150 void wxWindowX11::SendPaintEvents()
1152 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1154 m_clipPaintRegion
= TRUE
;
1156 wxPaintEvent
paint_event( GetId() );
1157 paint_event
.SetEventObject( this );
1158 GetEventHandler()->ProcessEvent( paint_event
);
1160 m_updateRegion
.Clear();
1162 m_clipPaintRegion
= FALSE
;
1165 void wxWindowX11::SendNcPaintEvents()
1167 wxWindow
*window
= (wxWindow
*) this;
1169 // All this for drawing the small square between the scrollbars.
1174 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1175 if (sb
&& sb
->IsShown())
1177 height
= sb
->GetSize().y
;
1178 y
= sb
->GetPosition().y
;
1180 sb
= window
->GetScrollbar( wxVERTICAL
);
1181 if (sb
&& sb
->IsShown())
1183 width
= sb
->GetSize().x
;
1184 x
= sb
->GetPosition().x
;
1186 Display
*xdisplay
= wxGlobalDisplay();
1187 Window xwindow
= (Window
) GetMainWindow();
1188 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1189 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1190 colour
.CalcPixel( (WXColormap
) cm
);
1192 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1194 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1198 wxNcPaintEvent
nc_paint_event( GetId() );
1199 nc_paint_event
.SetEventObject( this );
1200 GetEventHandler()->ProcessEvent( nc_paint_event
);
1202 m_updateNcArea
= FALSE
;
1205 // ----------------------------------------------------------------------------
1207 // ----------------------------------------------------------------------------
1209 // Responds to colour changes: passes event on to children.
1210 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1212 wxWindowList::Node
*node
= GetChildren().GetFirst();
1215 // Only propagate to non-top-level windows
1216 wxWindow
*win
= node
->GetData();
1217 if ( win
->GetParent() )
1219 wxSysColourChangedEvent event2
;
1220 event
.m_eventObject
= win
;
1221 win
->GetEventHandler()->ProcessEvent(event2
);
1224 node
= node
->GetNext();
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
;
1252 // ----------------------------------------------------------------------------
1253 // function which maintain the global hash table mapping Widgets to wxWindows
1254 // ----------------------------------------------------------------------------
1256 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1258 wxWindow
*oldItem
= NULL
;
1259 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1261 wxLogDebug("Widget table clash: new widget is %ld, %s",
1262 (long)w
, win
->GetClassInfo()->GetClassName());
1266 wxWidgetHashTable
->Put((long) w
, win
);
1268 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1269 w
, win
, win
->GetClassInfo()->GetClassName());
1274 wxWindow
*wxGetWindowFromTable(Window w
)
1276 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1279 void wxDeleteWindowFromTable(Window w
)
1281 wxWidgetHashTable
->Delete((long)w
);
1284 // ----------------------------------------------------------------------------
1285 // function which maintain the global hash table mapping client widgets
1286 // ----------------------------------------------------------------------------
1288 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1290 wxWindow
*oldItem
= NULL
;
1291 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1293 wxLogDebug("Client window table clash: new window is %ld, %s",
1294 (long)w
, win
->GetClassInfo()->GetClassName());
1298 wxClientWidgetHashTable
->Put((long) w
, win
);
1300 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1301 w
, win
, win
->GetClassInfo()->GetClassName());
1306 wxWindow
*wxGetClientWindowFromTable(Window w
)
1308 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1311 void wxDeleteClientWindowFromTable(Window w
)
1313 wxClientWidgetHashTable
->Delete((long)w
);
1316 // ----------------------------------------------------------------------------
1317 // add/remove window from the table
1318 // ----------------------------------------------------------------------------
1320 // ----------------------------------------------------------------------------
1321 // X11-specific accessors
1322 // ----------------------------------------------------------------------------
1324 WXWindow
wxWindowX11::GetMainWindow() const
1326 return m_mainWindow
;
1329 WXWindow
wxWindowX11::GetClientWindow() const
1331 return m_clientWindow
;
1334 // ----------------------------------------------------------------------------
1335 // TranslateXXXEvent() functions
1336 // ----------------------------------------------------------------------------
1338 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1340 switch (XEventGetType(xevent
))
1348 wxEventType eventType
= wxEVT_NULL
;
1350 if (XEventGetType(xevent
) == EnterNotify
)
1352 //if (local_event.xcrossing.mode!=NotifyNormal)
1353 // return ; // Ignore grab events
1354 eventType
= wxEVT_ENTER_WINDOW
;
1355 // canvas->GetEventHandler()->OnSetFocus();
1357 else if (XEventGetType(xevent
) == LeaveNotify
)
1359 //if (local_event.xcrossingr.mode!=NotifyNormal)
1360 // return ; // Ignore grab events
1361 eventType
= wxEVT_LEAVE_WINDOW
;
1362 // canvas->GetEventHandler()->OnKillFocus();
1364 else if (XEventGetType(xevent
) == MotionNotify
)
1366 eventType
= wxEVT_MOTION
;
1368 else if (XEventGetType(xevent
) == ButtonPress
)
1370 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1372 if (XButtonEventLChanged(xevent
))
1374 eventType
= wxEVT_LEFT_DOWN
;
1377 else if (XButtonEventMChanged(xevent
))
1379 eventType
= wxEVT_MIDDLE_DOWN
;
1382 else if (XButtonEventRChanged(xevent
))
1384 eventType
= wxEVT_RIGHT_DOWN
;
1388 // check for a double click
1389 // TODO: where can we get this value from?
1390 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1391 long dclickTime
= 200;
1392 long ts
= wxevent
.GetTimestamp();
1394 int buttonLast
= win
->GetLastClickedButton();
1395 long lastTS
= win
->GetLastClickTime();
1396 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1399 win
->SetLastClick(0, ts
);
1400 if ( eventType
== wxEVT_LEFT_DOWN
)
1401 eventType
= wxEVT_LEFT_DCLICK
;
1402 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1403 eventType
= wxEVT_MIDDLE_DCLICK
;
1404 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1405 eventType
= wxEVT_RIGHT_DCLICK
;
1409 // not fast enough or different button
1410 win
->SetLastClick(button
, ts
);
1413 else if (XEventGetType(xevent
) == ButtonRelease
)
1415 if (XButtonEventLChanged(xevent
))
1417 eventType
= wxEVT_LEFT_UP
;
1419 else if (XButtonEventMChanged(xevent
))
1421 eventType
= wxEVT_MIDDLE_UP
;
1423 else if (XButtonEventRChanged(xevent
))
1425 eventType
= wxEVT_RIGHT_UP
;
1434 wxevent
.SetEventType(eventType
);
1436 wxevent
.m_x
= XButtonEventGetX(xevent
);
1437 wxevent
.m_y
= XButtonEventGetY(xevent
);
1439 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1440 || (XButtonEventLIsDown(xevent
)
1441 && (eventType
!= wxEVT_LEFT_UP
)));
1442 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1443 || (XButtonEventMIsDown(xevent
)
1444 && (eventType
!= wxEVT_MIDDLE_UP
)));
1445 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1446 || (XButtonEventRIsDown (xevent
)
1447 && (eventType
!= wxEVT_RIGHT_UP
)));
1449 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1450 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1451 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1452 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1454 wxevent
.SetId(win
->GetId());
1455 wxevent
.SetEventObject(win
);
1463 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1465 switch (XEventGetType(xevent
))
1473 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1474 int id
= wxCharCodeXToWX (keySym
);
1476 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1477 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1478 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1479 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1480 wxevent
.SetEventObject(win
);
1481 wxevent
.m_keyCode
= id
;
1482 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1484 wxevent
.m_x
= XKeyEventGetX(xevent
);
1485 wxevent
.m_y
= XKeyEventGetY(xevent
);
1499 // ----------------------------------------------------------------------------
1501 // ----------------------------------------------------------------------------
1503 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1505 wxWindowBase::SetBackgroundColour(col
);
1507 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1508 int xscreen
= DefaultScreen( xdisplay
);
1509 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1511 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1513 // We don't set the background colour as we paint
1514 // the background ourselves.
1515 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1520 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1522 if ( !wxWindowBase::SetForegroundColour(col
) )
1528 // ----------------------------------------------------------------------------
1530 // ----------------------------------------------------------------------------
1532 wxWindow
*wxGetActiveWindow()
1535 wxFAIL_MSG("Not implemented");
1540 wxWindow
*wxWindowBase::GetCapture()
1542 return (wxWindow
*)g_captureWindow
;
1546 // Find the wxWindow at the current mouse position, returning the mouse
1548 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1550 return wxFindWindowAtPoint(wxGetMousePosition());
1553 // Get the current mouse position.
1554 wxPoint
wxGetMousePosition()
1558 return wxPoint(0, 0);
1560 Display
*display
= wxGlobalDisplay();
1561 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1562 Window rootReturn
, childReturn
;
1563 int rootX
, rootY
, winX
, winY
;
1564 unsigned int maskReturn
;
1566 XQueryPointer (display
,
1570 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1571 return wxPoint(rootX
, rootY
);
1576 // ----------------------------------------------------------------------------
1577 // wxNoOptimize: switch off size optimization
1578 // ----------------------------------------------------------------------------
1580 int wxNoOptimize::ms_count
= 0;
1583 // ----------------------------------------------------------------------------
1585 // ----------------------------------------------------------------------------
1587 class wxWinModule
: public wxModule
1594 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1597 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1599 bool wxWinModule::OnInit()
1601 Display
*xdisplay
= wxGlobalDisplay();
1602 int xscreen
= DefaultScreen( xdisplay
);
1603 Window xroot
= RootWindow( xdisplay
, xscreen
);
1604 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1605 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1610 void wxWinModule::OnExit()
1612 Display
*xdisplay
= wxGlobalDisplay();
1613 XFreeGC( xdisplay
, g_eraseGC
);