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();
173 #if wxUSE_TWO_WINDOWS
174 bool need_two_windows
=
175 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
177 bool need_two_windows
= FALSE
;
180 XSetWindowAttributes xattributes
;
181 long xattributes_mask
= 0;
183 xattributes_mask
|= CWBackPixel
;
184 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
186 xattributes_mask
|= CWBorderPixel
;
187 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
189 xattributes_mask
|= CWEventMask
;
191 if (need_two_windows
)
193 xattributes
.event_mask
=
194 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
196 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
197 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
199 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
201 m_mainWindow
= (WXWindow
) xwindow
;
202 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
204 XMapWindow( xdisplay
, xwindow
);
206 xattributes
.event_mask
=
207 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
208 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
209 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
210 PropertyChangeMask
| VisibilityChangeMask
;
212 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
214 xattributes_mask
|= CWBitGravity
;
215 xattributes
.bit_gravity
= StaticGravity
;
218 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
225 if (HasFlag( wxSIMPLE_BORDER
))
237 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
238 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
240 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
242 m_clientWindow
= (WXWindow
) xwindow
;
243 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
245 XMapWindow( xdisplay
, xwindow
);
249 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
251 xattributes
.event_mask
=
252 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
253 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
254 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
255 PropertyChangeMask
| VisibilityChangeMask
;
257 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
259 xattributes_mask
|= CWBitGravity
;
260 xattributes
.bit_gravity
= NorthWestGravity
;
263 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
264 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
266 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
268 m_mainWindow
= (WXWindow
) xwindow
;
269 m_clientWindow
= m_mainWindow
;
270 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
272 XMapWindow( xdisplay
, xwindow
);
276 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
278 long backColor
, foreColor
;
279 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
280 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
282 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
283 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
284 XSelectInput( xdisplay
, xwindow
,
285 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
286 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
287 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
288 PropertyChangeMask
);
290 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
292 m_mainWindow
= (WXWindow
) xwindow
;
293 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
295 XMapWindow( xdisplay
, xwindow
);
298 // Is a subwindow, so map immediately
301 // Without this, the cursor may not be restored properly (e.g. in splitter
303 SetCursor(*wxSTANDARD_CURSOR
);
304 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
306 // Don't call this, it can have nasty repercussions for composite controls,
308 // SetSize(pos.x, pos.y, size.x, size.y);
314 wxWindowX11::~wxWindowX11()
316 if (g_captureWindow
== this)
317 g_captureWindow
= NULL
;
319 m_isBeingDeleted
= TRUE
;
322 m_parent
->RemoveChild( this );
326 if (m_clientWindow
!= m_mainWindow
)
328 // Destroy the cleint window
329 Window xwindow
= (Window
) m_clientWindow
;
330 wxDeleteClientWindowFromTable( xwindow
);
331 XDestroyWindow( wxGlobalDisplay(), xwindow
);
332 m_clientWindow
= NULL
;
335 // Destroy the window
336 Window xwindow
= (Window
) m_mainWindow
;
337 wxDeleteWindowFromTable( xwindow
);
338 XDestroyWindow( wxGlobalDisplay(), xwindow
);
342 // ---------------------------------------------------------------------------
344 // ---------------------------------------------------------------------------
346 void wxWindowX11::SetFocus()
348 Window xwindow
= (Window
) m_clientWindow
;
350 wxCHECK_RET( xwindow
, wxT("invalid window") );
352 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
355 if (GetName() == "scrollBar")
362 if (wxWindowIsVisible(xwindow
))
364 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
365 m_needsInputFocus
= FALSE
;
369 m_needsInputFocus
= TRUE
;
373 // Get the window with the focus
374 wxWindow
*wxWindowBase::FindFocus()
376 Window xfocus
= (Window
) 0;
379 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
382 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
385 win
= wxGetClientWindowFromTable( xfocus
);
394 // Enabling/disabling handled by event loop, and not sending events
396 bool wxWindowX11::Enable(bool enable
)
398 if ( !wxWindowBase::Enable(enable
) )
404 bool wxWindowX11::Show(bool show
)
406 wxWindowBase::Show(show
);
408 Window xwindow
= (Window
) m_mainWindow
;
409 Display
*xdisp
= wxGlobalDisplay();
412 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
413 XMapWindow(xdisp
, xwindow
);
417 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
418 XUnmapWindow(xdisp
, xwindow
);
424 // Raise the window to the top of the Z order
425 void wxWindowX11::Raise()
428 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
431 // Lower the window to the bottom of the Z order
432 void wxWindowX11::Lower()
435 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
438 void wxWindowX11::DoCaptureMouse()
440 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
442 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
453 Window xwindow
= (Window
) m_clientWindow
;
455 wxCHECK_RET( xwindow
, wxT("invalid window") );
457 g_captureWindow
= (wxWindow
*) this;
461 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
463 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
467 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
470 if (res
!= GrabSuccess
)
473 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
475 if (res
== GrabNotViewable
)
477 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
479 g_captureWindow
= NULL
;
483 m_winCaptured
= TRUE
;
487 void wxWindowX11::DoReleaseMouse()
489 g_captureWindow
= NULL
;
491 if ( !m_winCaptured
)
494 Window xwindow
= (Window
) m_clientWindow
;
498 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
501 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
503 m_winCaptured
= FALSE
;
506 bool wxWindowX11::SetFont(const wxFont
& font
)
508 if ( !wxWindowBase::SetFont(font
) )
517 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
519 if ( !wxWindowBase::SetCursor(cursor
) )
525 Window xwindow
= (Window
) m_clientWindow
;
527 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
529 wxCursor cursorToUse
;
531 cursorToUse
= m_cursor
;
533 cursorToUse
= *wxSTANDARD_CURSOR
;
535 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
537 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
542 // Coordinates relative to the window
543 void wxWindowX11::WarpPointer (int x
, int y
)
545 Window xwindow
= (Window
) m_clientWindow
;
547 wxCHECK_RET( xwindow
, wxT("invalid window") );
549 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
552 // Does a physical scroll
553 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
555 // No scrolling requested.
556 if ((dx
== 0) && (dy
== 0)) return;
558 if (!m_updateRegion
.IsEmpty())
560 m_updateRegion
.Offset( dx
, dy
);
564 GetSize( &cw
, &ch
); // GetClientSize() ??
565 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
568 if (!m_clearRegion
.IsEmpty())
570 m_clearRegion
.Offset( dx
, dy
);
574 GetSize( &cw
, &ch
); // GetClientSize() ??
575 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
578 Window xwindow
= (Window
) GetClientWindow();
580 wxCHECK_RET( xwindow
, wxT("invalid window") );
582 Display
*xdisplay
= wxGlobalDisplay();
584 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
585 XSetGraphicsExposures( xdisplay
, xgc
, True
);
603 GetClientSize( &cw
, &ch
);
606 #if wxUSE_TWO_WINDOWS
607 wxPoint
offset( 0,0 );
609 wxPoint offset
= GetClientAreaOrigin();
614 int w
= cw
- abs(dx
);
615 int h
= ch
- abs(dy
);
617 if ((h
< 0) || (w
< 0))
624 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
625 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
626 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
627 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
632 if (dx
< 0) s_x
+= -dx
;
633 if (dy
< 0) s_y
+= -dy
;
634 if (dx
> 0) d_x
= dx
+ offset
.x
;
635 if (dy
> 0) d_y
= dy
+ offset
.y
;
637 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
639 // 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 );
641 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
643 m_updateRegion
.Union( rect
);
644 m_clearRegion
.Union( rect
);
647 XFreeGC( xdisplay
, xgc
);
650 // ---------------------------------------------------------------------------
652 // ---------------------------------------------------------------------------
654 #if wxUSE_DRAG_AND_DROP
656 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
663 // Old style file-manager drag&drop
664 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
669 // ----------------------------------------------------------------------------
671 // ----------------------------------------------------------------------------
675 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
680 #endif // wxUSE_TOOLTIPS
682 // ---------------------------------------------------------------------------
683 // moving and resizing
684 // ---------------------------------------------------------------------------
686 bool wxWindowX11::PreResize()
692 void wxWindowX11::DoGetSize(int *x
, int *y
) const
694 Window xwindow
= (Window
) m_mainWindow
;
696 wxCHECK_RET( xwindow
, wxT("invalid window") );
698 //XSync(wxGlobalDisplay(), False);
700 XWindowAttributes attr
;
701 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
706 *x
= attr
.width
/* + 2*m_borderSize */ ;
707 *y
= attr
.height
/* + 2*m_borderSize */ ;
711 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
713 Window window
= (Window
) m_mainWindow
;
716 //XSync(wxGlobalDisplay(), False);
717 XWindowAttributes attr
;
718 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
726 // We may be faking the client origin. So a window that's really at (0, 30)
727 // may appear (to wxWin apps) to be at (0, 0).
730 wxPoint
pt(GetParent()->GetClientAreaOrigin());
738 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
740 Display
*display
= wxGlobalDisplay();
741 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
742 Window thisWindow
= (Window
) m_clientWindow
;
747 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
750 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
752 Display
*display
= wxGlobalDisplay();
753 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
754 Window thisWindow
= (Window
) m_clientWindow
;
759 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
763 // Get size *available for subwindows* i.e. excluding menu bar etc.
764 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
766 Window window
= (Window
) m_mainWindow
;
770 XWindowAttributes attr
;
771 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
782 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
784 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
786 Window xwindow
= (Window
) m_mainWindow
;
788 wxCHECK_RET( xwindow
, wxT("invalid window") );
790 XWindowAttributes attr
;
791 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
792 wxCHECK_RET( status
, wxT("invalid window attributes") );
796 int new_w
= attr
.width
;
797 int new_h
= attr
.height
;
799 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
802 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
805 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
808 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
824 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
827 void wxWindowX11::DoSetClientSize(int width
, int height
)
829 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
831 Window xwindow
= (Window
) m_mainWindow
;
833 wxCHECK_RET( xwindow
, wxT("invalid window") );
835 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
837 if (m_mainWindow
!= m_clientWindow
)
839 xwindow
= (Window
) m_clientWindow
;
841 wxWindow
*window
= (wxWindow
*) this;
842 wxRenderer
*renderer
= window
->GetRenderer();
845 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
846 width
-= border
.x
+ border
.width
;
847 height
-= border
.y
+ border
.height
;
850 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
854 // For implementation purposes - sometimes decorations make the client area
856 wxPoint
wxWindowX11::GetClientAreaOrigin() const
858 return wxPoint(0, 0);
861 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
863 Window xwindow
= (Window
) m_mainWindow
;
865 wxCHECK_RET( xwindow
, wxT("invalid window") );
869 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
870 if (m_mainWindow
!= m_clientWindow
)
872 xwindow
= (Window
) m_clientWindow
;
874 wxWindow
*window
= (wxWindow
*) this;
875 wxRenderer
*renderer
= window
->GetRenderer();
878 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
881 width
-= border
.x
+ border
.width
;
882 height
-= border
.y
+ border
.height
;
890 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
891 if (sb
&& sb
->IsShown())
893 wxSize size
= sb
->GetSize();
896 sb
= window
->GetScrollbar( wxVERTICAL
);
897 if (sb
&& sb
->IsShown())
899 wxSize size
= sb
->GetSize();
903 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
908 XWindowChanges windowChanges
;
911 windowChanges
.width
= width
;
912 windowChanges
.height
= height
;
913 windowChanges
.stack_mode
= 0;
914 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
916 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
921 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
929 XSizeHints sizeHints
;
932 if (minW
> -1 && minH
> -1)
934 sizeHints
.flags
|= PMinSize
;
935 sizeHints
.min_width
= minW
;
936 sizeHints
.min_height
= minH
;
938 if (maxW
> -1 && maxH
> -1)
940 sizeHints
.flags
|= PMaxSize
;
941 sizeHints
.max_width
= maxW
;
942 sizeHints
.max_height
= maxH
;
944 if (incW
> -1 && incH
> -1)
946 sizeHints
.flags
|= PResizeInc
;
947 sizeHints
.width_inc
= incW
;
948 sizeHints
.height_inc
= incH
;
951 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
955 // ---------------------------------------------------------------------------
957 // ---------------------------------------------------------------------------
959 int wxWindowX11::GetCharHeight() const
961 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
963 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
965 int direction
, ascent
, descent
;
967 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
970 // return (overall.ascent + overall.descent);
971 return (ascent
+ descent
);
974 int wxWindowX11::GetCharWidth() const
976 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
978 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
980 int direction
, ascent
, descent
;
982 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
985 return overall
.width
;
988 void wxWindowX11::GetTextExtent(const wxString
& string
,
990 int *descent
, int *externalLeading
,
991 const wxFont
*theFont
) const
993 wxFont fontToUse
= m_font
;
994 if (theFont
) fontToUse
= *theFont
;
996 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
998 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1000 int direction
, ascent
, descent2
;
1001 XCharStruct overall
;
1002 int slen
= string
.Len();
1006 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1007 &ascent
, &descent2
, &overall
);
1010 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1011 &direction
, &ascent
, &descent2
, &overall
);
1014 *x
= (overall
.width
);
1016 *y
= (ascent
+ descent2
);
1018 *descent
= descent2
;
1019 if (externalLeading
)
1020 *externalLeading
= 0;
1024 // ----------------------------------------------------------------------------
1026 // ----------------------------------------------------------------------------
1028 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1034 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1035 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1040 GetSize( &width
, &height
);
1042 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1043 m_clearRegion
.Clear();
1044 m_clearRegion
.Union( 0, 0, width
, height
);
1050 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1051 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1056 GetSize( &width
, &height
);
1058 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1059 m_updateRegion
.Clear();
1060 m_updateRegion
.Union( 0, 0, width
, height
);
1064 void wxWindowX11::Update()
1068 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1069 // Send nc paint events.
1070 SendNcPaintEvents();
1073 if (!m_updateRegion
.IsEmpty())
1075 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1076 // Actually send erase events.
1079 // Actually send paint events.
1084 void wxWindowX11::Clear()
1086 // wxClientDC dc((wxWindow*) this);
1087 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1088 // dc.SetBackground(brush);
1092 void wxWindowX11::SendEraseEvents()
1094 if (m_clearRegion
.IsEmpty()) return;
1096 wxClientDC
dc( (wxWindow
*)this );
1097 dc
.SetClippingRegion( m_clearRegion
);
1099 wxEraseEvent
erase_event( GetId(), &dc
);
1100 erase_event
.SetEventObject( this );
1102 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1104 Display
*xdisplay
= wxGlobalDisplay();
1105 Window xwindow
= (Window
) GetClientWindow();
1106 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1108 wxRegionIterator
upd( m_clearRegion
);
1111 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1112 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1117 m_clearRegion
.Clear();
1120 void wxWindowX11::SendPaintEvents()
1122 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1124 m_clipPaintRegion
= TRUE
;
1126 wxPaintEvent
paint_event( GetId() );
1127 paint_event
.SetEventObject( this );
1128 GetEventHandler()->ProcessEvent( paint_event
);
1130 m_updateRegion
.Clear();
1132 m_clipPaintRegion
= FALSE
;
1135 void wxWindowX11::SendNcPaintEvents()
1137 wxWindow
*window
= (wxWindow
*) this;
1139 // All this for drawing the small square between the scrollbars.
1144 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1145 if (sb
&& sb
->IsShown())
1147 height
= sb
->GetSize().y
;
1148 y
= sb
->GetPosition().y
;
1150 sb
= window
->GetScrollbar( wxVERTICAL
);
1151 if (sb
&& sb
->IsShown())
1153 width
= sb
->GetSize().x
;
1154 x
= sb
->GetPosition().x
;
1156 Display
*xdisplay
= wxGlobalDisplay();
1157 Window xwindow
= (Window
) GetMainWindow();
1158 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1159 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1160 colour
.CalcPixel( (WXColormap
) cm
);
1162 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1164 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1168 wxNcPaintEvent
nc_paint_event( GetId() );
1169 nc_paint_event
.SetEventObject( this );
1170 GetEventHandler()->ProcessEvent( nc_paint_event
);
1172 m_updateNcArea
= FALSE
;
1175 // ----------------------------------------------------------------------------
1177 // ----------------------------------------------------------------------------
1179 // Responds to colour changes: passes event on to children.
1180 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1182 wxWindowList::Node
*node
= GetChildren().GetFirst();
1185 // Only propagate to non-top-level windows
1186 wxWindow
*win
= node
->GetData();
1187 if ( win
->GetParent() )
1189 wxSysColourChangedEvent event2
;
1190 event
.m_eventObject
= win
;
1191 win
->GetEventHandler()->ProcessEvent(event2
);
1194 node
= node
->GetNext();
1198 void wxWindowX11::OnInternalIdle()
1200 // Update invalidated regions.
1203 // This calls the UI-update mechanism (querying windows for
1204 // menu/toolbar/control state information)
1207 // Set the input focus if couldn't do it before
1208 if (m_needsInputFocus
)
1214 // ----------------------------------------------------------------------------
1215 // function which maintain the global hash table mapping Widgets to wxWindows
1216 // ----------------------------------------------------------------------------
1218 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1220 wxWindow
*oldItem
= NULL
;
1221 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1223 wxLogDebug("Widget table clash: new widget is %ld, %s",
1224 (long)w
, win
->GetClassInfo()->GetClassName());
1228 wxWidgetHashTable
->Put((long) w
, win
);
1230 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1231 w
, win
, win
->GetClassInfo()->GetClassName());
1236 wxWindow
*wxGetWindowFromTable(Window w
)
1238 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1241 void wxDeleteWindowFromTable(Window w
)
1243 wxWidgetHashTable
->Delete((long)w
);
1246 // ----------------------------------------------------------------------------
1247 // function which maintain the global hash table mapping client widgets
1248 // ----------------------------------------------------------------------------
1250 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1252 wxWindow
*oldItem
= NULL
;
1253 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1255 wxLogDebug("Client window table clash: new window is %ld, %s",
1256 (long)w
, win
->GetClassInfo()->GetClassName());
1260 wxClientWidgetHashTable
->Put((long) w
, win
);
1262 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1263 w
, win
, win
->GetClassInfo()->GetClassName());
1268 wxWindow
*wxGetClientWindowFromTable(Window w
)
1270 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1273 void wxDeleteClientWindowFromTable(Window w
)
1275 wxClientWidgetHashTable
->Delete((long)w
);
1278 // ----------------------------------------------------------------------------
1279 // add/remove window from the table
1280 // ----------------------------------------------------------------------------
1282 // ----------------------------------------------------------------------------
1283 // X11-specific accessors
1284 // ----------------------------------------------------------------------------
1286 WXWindow
wxWindowX11::GetMainWindow() const
1288 return m_mainWindow
;
1291 WXWindow
wxWindowX11::GetClientWindow() const
1293 return m_clientWindow
;
1296 // ----------------------------------------------------------------------------
1297 // TranslateXXXEvent() functions
1298 // ----------------------------------------------------------------------------
1300 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1302 switch (XEventGetType(xevent
))
1310 wxEventType eventType
= wxEVT_NULL
;
1312 if (XEventGetType(xevent
) == EnterNotify
)
1314 //if (local_event.xcrossing.mode!=NotifyNormal)
1315 // return ; // Ignore grab events
1316 eventType
= wxEVT_ENTER_WINDOW
;
1317 // canvas->GetEventHandler()->OnSetFocus();
1319 else if (XEventGetType(xevent
) == LeaveNotify
)
1321 //if (local_event.xcrossingr.mode!=NotifyNormal)
1322 // return ; // Ignore grab events
1323 eventType
= wxEVT_LEAVE_WINDOW
;
1324 // canvas->GetEventHandler()->OnKillFocus();
1326 else if (XEventGetType(xevent
) == MotionNotify
)
1328 eventType
= wxEVT_MOTION
;
1330 else if (XEventGetType(xevent
) == ButtonPress
)
1332 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1334 if (XButtonEventLChanged(xevent
))
1336 eventType
= wxEVT_LEFT_DOWN
;
1339 else if (XButtonEventMChanged(xevent
))
1341 eventType
= wxEVT_MIDDLE_DOWN
;
1344 else if (XButtonEventRChanged(xevent
))
1346 eventType
= wxEVT_RIGHT_DOWN
;
1350 // check for a double click
1351 // TODO: where can we get this value from?
1352 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1353 long dclickTime
= 200;
1354 long ts
= wxevent
.GetTimestamp();
1356 int buttonLast
= win
->GetLastClickedButton();
1357 long lastTS
= win
->GetLastClickTime();
1358 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1361 win
->SetLastClick(0, ts
);
1362 if ( eventType
== wxEVT_LEFT_DOWN
)
1363 eventType
= wxEVT_LEFT_DCLICK
;
1364 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1365 eventType
= wxEVT_MIDDLE_DCLICK
;
1366 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1367 eventType
= wxEVT_RIGHT_DCLICK
;
1371 // not fast enough or different button
1372 win
->SetLastClick(button
, ts
);
1375 else if (XEventGetType(xevent
) == ButtonRelease
)
1377 if (XButtonEventLChanged(xevent
))
1379 eventType
= wxEVT_LEFT_UP
;
1381 else if (XButtonEventMChanged(xevent
))
1383 eventType
= wxEVT_MIDDLE_UP
;
1385 else if (XButtonEventRChanged(xevent
))
1387 eventType
= wxEVT_RIGHT_UP
;
1396 wxevent
.SetEventType(eventType
);
1398 wxevent
.m_x
= XButtonEventGetX(xevent
);
1399 wxevent
.m_y
= XButtonEventGetY(xevent
);
1401 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1402 || (XButtonEventLIsDown(xevent
)
1403 && (eventType
!= wxEVT_LEFT_UP
)));
1404 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1405 || (XButtonEventMIsDown(xevent
)
1406 && (eventType
!= wxEVT_MIDDLE_UP
)));
1407 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1408 || (XButtonEventRIsDown (xevent
)
1409 && (eventType
!= wxEVT_RIGHT_UP
)));
1411 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1412 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1413 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1414 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1416 wxevent
.SetId(win
->GetId());
1417 wxevent
.SetEventObject(win
);
1425 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1427 switch (XEventGetType(xevent
))
1435 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1436 int id
= wxCharCodeXToWX (keySym
);
1438 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1439 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1440 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1441 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1442 wxevent
.SetEventObject(win
);
1443 wxevent
.m_keyCode
= id
;
1444 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1446 wxevent
.m_x
= XKeyEventGetX(xevent
);
1447 wxevent
.m_y
= XKeyEventGetY(xevent
);
1461 // ----------------------------------------------------------------------------
1463 // ----------------------------------------------------------------------------
1465 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1467 wxWindowBase::SetBackgroundColour(col
);
1469 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1470 int xscreen
= DefaultScreen( xdisplay
);
1471 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1473 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1475 // We don't set the background colour as we paint
1476 // the background ourselves.
1477 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1482 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1484 if ( !wxWindowBase::SetForegroundColour(col
) )
1490 // ----------------------------------------------------------------------------
1492 // ----------------------------------------------------------------------------
1494 wxWindow
*wxGetActiveWindow()
1497 wxFAIL_MSG("Not implemented");
1502 wxWindow
*wxWindowBase::GetCapture()
1504 return (wxWindow
*)g_captureWindow
;
1508 // Find the wxWindow at the current mouse position, returning the mouse
1510 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1512 return wxFindWindowAtPoint(wxGetMousePosition());
1515 // Get the current mouse position.
1516 wxPoint
wxGetMousePosition()
1520 return wxPoint(0, 0);
1522 Display
*display
= wxGlobalDisplay();
1523 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1524 Window rootReturn
, childReturn
;
1525 int rootX
, rootY
, winX
, winY
;
1526 unsigned int maskReturn
;
1528 XQueryPointer (display
,
1532 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1533 return wxPoint(rootX
, rootY
);
1538 // ----------------------------------------------------------------------------
1539 // wxNoOptimize: switch off size optimization
1540 // ----------------------------------------------------------------------------
1542 int wxNoOptimize::ms_count
= 0;
1545 // ----------------------------------------------------------------------------
1547 // ----------------------------------------------------------------------------
1549 class wxWinModule
: public wxModule
1556 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1559 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1561 bool wxWinModule::OnInit()
1563 Display
*xdisplay
= wxGlobalDisplay();
1564 int xscreen
= DefaultScreen( xdisplay
);
1565 Window xroot
= RootWindow( xdisplay
, xscreen
);
1566 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1567 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1572 void wxWinModule::OnExit()
1574 Display
*xdisplay
= wxGlobalDisplay();
1575 XFreeGC( xdisplay
, g_eraseGC
);