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"
44 #if wxUSE_DRAG_AND_DROP
48 #include "wx/x11/private.h"
49 #include "X11/Xutil.h"
52 // For wxGetLocalTime, used by XButtonEventGetTime
58 // ----------------------------------------------------------------------------
59 // global variables for this module
60 // ----------------------------------------------------------------------------
62 extern wxHashTable
*wxWidgetHashTable
;
63 extern wxHashTable
*wxClientWidgetHashTable
;
64 static wxWindow
* g_captureWindow
= NULL
;
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
71 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
72 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
80 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
81 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
84 // ============================================================================
86 // ============================================================================
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 void wxWindowX11::Init()
98 // generic initializations first
102 m_mainWindow
= (WXWindow
) 0;
103 m_clientWindow
= (WXWindow
) 0;
104 m_insertIntoMain
= FALSE
;
106 m_winCaptured
= FALSE
;
107 m_needsInputFocus
= FALSE
;
109 m_isBeingDeleted
= FALSE
;
114 // real construction (Init() must have been called before!)
115 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
119 const wxString
& name
)
121 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
123 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
125 parent
->AddChild(this);
127 int w
= size
.GetWidth();
128 int h
= size
.GetHeight();
136 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
137 int xscreen
= DefaultScreen( xdisplay
);
138 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
139 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
141 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
142 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
144 m_foregroundColour
= *wxBLACK
;
145 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
147 Window xparent
= (Window
) parent
->GetClientWindow();
149 // Add window's own scrollbars to main window, not to client window
150 if (parent
->GetInsertIntoMain())
152 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
153 xparent
= (Window
) parent
->GetMainWindow();
170 #if wxUSE_TWO_WINDOWS
171 bool need_two_windows
=
172 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
174 bool need_two_windows
= FALSE
;
177 XSetWindowAttributes xattributes
;
178 long xattributes_mask
= 0;
180 xattributes_mask
|= CWBackPixel
;
181 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
183 xattributes_mask
|= CWBorderPixel
;
184 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
186 xattributes_mask
|= CWEventMask
;
188 if (need_two_windows
)
190 xattributes
.event_mask
=
191 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
193 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
194 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
196 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
198 m_mainWindow
= (WXWindow
) xwindow
;
199 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
201 XMapWindow( xdisplay
, xwindow
);
203 xattributes
.event_mask
=
204 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
205 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
206 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
207 PropertyChangeMask
| VisibilityChangeMask
;
209 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
211 xattributes_mask
|= CWBitGravity
;
212 xattributes
.bit_gravity
= StaticGravity
;
215 xwindow
= XCreateWindow( xdisplay
, xwindow
, 0, 0, size2
.x
, size2
.y
,
216 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
218 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
220 m_clientWindow
= (WXWindow
) xwindow
;
221 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
223 XMapWindow( xdisplay
, xwindow
);
227 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
229 xattributes
.event_mask
=
230 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
231 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
232 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
233 PropertyChangeMask
| VisibilityChangeMask
;
235 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
237 xattributes_mask
|= CWBitGravity
;
238 xattributes
.bit_gravity
= StaticGravity
;
241 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
242 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
244 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
246 m_mainWindow
= (WXWindow
) xwindow
;
247 m_clientWindow
= m_mainWindow
;
248 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
250 XMapWindow( xdisplay
, xwindow
);
254 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
256 long backColor
, foreColor
;
257 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
258 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
260 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
261 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
262 XSelectInput( xdisplay
, xwindow
,
263 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
264 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
265 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
266 PropertyChangeMask
);
268 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
270 m_mainWindow
= (WXWindow
) xwindow
;
271 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
273 XMapWindow( xdisplay
, xwindow
);
276 // Is a subwindow, so map immediately
279 // Without this, the cursor may not be restored properly (e.g. in splitter
281 SetCursor(*wxSTANDARD_CURSOR
);
282 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
284 // Don't call this, it can have nasty repercussions for composite controls,
286 // SetSize(pos.x, pos.y, size.x, size.y);
292 wxWindowX11::~wxWindowX11()
294 if (g_captureWindow
== this)
295 g_captureWindow
= NULL
;
297 m_isBeingDeleted
= TRUE
;
300 m_parent
->RemoveChild( this );
304 if (m_clientWindow
!= m_mainWindow
)
306 // Destroy the cleint window
307 Window xwindow
= (Window
) m_clientWindow
;
308 wxDeleteClientWindowFromTable( xwindow
);
309 XDestroyWindow( wxGlobalDisplay(), xwindow
);
310 m_clientWindow
= NULL
;
313 // Destroy the window
314 Window xwindow
= (Window
) m_mainWindow
;
315 wxDeleteWindowFromTable( xwindow
);
316 XDestroyWindow( wxGlobalDisplay(), xwindow
);
320 // ---------------------------------------------------------------------------
322 // ---------------------------------------------------------------------------
324 void wxWindowX11::SetFocus()
326 Window xwindow
= (Window
) m_clientWindow
;
328 wxCHECK_RET( xwindow
, wxT("invalid window") );
330 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
333 if (GetName() == "scrollBar")
340 if (wxWindowIsVisible(xwindow
))
342 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
343 m_needsInputFocus
= FALSE
;
347 m_needsInputFocus
= TRUE
;
351 // Get the window with the focus
352 wxWindow
*wxWindowBase::FindFocus()
354 Window xfocus
= (Window
) 0;
357 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
360 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
368 // Enabling/disabling handled by event loop, and not sending events
370 bool wxWindowX11::Enable(bool enable
)
372 if ( !wxWindowBase::Enable(enable
) )
378 bool wxWindowX11::Show(bool show
)
380 wxWindowBase::Show(show
);
382 Window xwindow
= (Window
) m_mainWindow
;
383 Display
*xdisp
= wxGlobalDisplay();
386 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
387 XMapWindow(xdisp
, xwindow
);
391 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
392 XUnmapWindow(xdisp
, xwindow
);
398 // Raise the window to the top of the Z order
399 void wxWindowX11::Raise()
402 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
405 // Lower the window to the bottom of the Z order
406 void wxWindowX11::Lower()
409 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
412 void wxWindowX11::DoCaptureMouse()
414 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
416 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
427 Window xwindow
= (Window
) m_clientWindow
;
429 wxCHECK_RET( xwindow
, wxT("invalid window") );
431 g_captureWindow
= (wxWindow
*) this;
435 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
437 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
441 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
444 if (res
!= GrabSuccess
)
447 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
449 if (res
== GrabNotViewable
)
451 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
453 g_captureWindow
= NULL
;
457 m_winCaptured
= TRUE
;
461 void wxWindowX11::DoReleaseMouse()
463 g_captureWindow
= NULL
;
465 if ( !m_winCaptured
)
468 Window xwindow
= (Window
) m_clientWindow
;
472 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
475 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
477 m_winCaptured
= FALSE
;
480 bool wxWindowX11::SetFont(const wxFont
& font
)
482 if ( !wxWindowBase::SetFont(font
) )
491 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
493 if ( !wxWindowBase::SetCursor(cursor
) )
499 Window xwindow
= (Window
) m_clientWindow
;
501 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
503 wxCursor cursorToUse
;
505 cursorToUse
= m_cursor
;
507 cursorToUse
= *wxSTANDARD_CURSOR
;
509 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
511 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
516 // Coordinates relative to the window
517 void wxWindowX11::WarpPointer (int x
, int y
)
519 Window xwindow
= (Window
) m_clientWindow
;
521 wxCHECK_RET( xwindow
, wxT("invalid window") );
523 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
526 // Does a physical scroll
527 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
529 // No scrolling requested.
530 if ((dx
== 0) && (dy
== 0)) return;
532 if (!m_updateRegion
.IsEmpty())
534 m_updateRegion
.Offset( dx
, dy
);
538 GetSize( &cw
, &ch
); // GetClientSize() ??
539 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
542 if (!m_clearRegion
.IsEmpty())
544 m_clearRegion
.Offset( dx
, dy
);
548 GetSize( &cw
, &ch
); // GetClientSize() ??
549 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
552 Window xwindow
= (Window
) GetClientWindow();
554 wxCHECK_RET( xwindow
, wxT("invalid window") );
556 Display
*xdisplay
= wxGlobalDisplay();
558 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
559 XSetGraphicsExposures( xdisplay
, xgc
, True
);
577 GetClientSize( &cw
, &ch
);
580 #if wxUSE_TWO_WINDOWS
581 wxPoint
offset( 0,0 );
583 wxPoint offset
= GetClientAreaOrigin();
588 int w
= cw
- abs(dx
);
589 int h
= ch
- abs(dy
);
591 if ((h
< 0) || (w
< 0))
598 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
599 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
600 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
601 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
606 if (dx
< 0) s_x
+= -dx
;
607 if (dy
< 0) s_y
+= -dy
;
608 if (dx
> 0) d_x
= dx
+ offset
.x
;
609 if (dy
> 0) d_y
= dy
+ offset
.y
;
611 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
613 // 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 );
615 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
617 m_updateRegion
.Union( rect
);
618 m_clearRegion
.Union( rect
);
621 XFreeGC( xdisplay
, xgc
);
624 // ---------------------------------------------------------------------------
626 // ---------------------------------------------------------------------------
628 #if wxUSE_DRAG_AND_DROP
630 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
637 // Old style file-manager drag&drop
638 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
643 // ----------------------------------------------------------------------------
645 // ----------------------------------------------------------------------------
649 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
654 #endif // wxUSE_TOOLTIPS
656 // ---------------------------------------------------------------------------
657 // moving and resizing
658 // ---------------------------------------------------------------------------
660 bool wxWindowX11::PreResize()
666 void wxWindowX11::DoGetSize(int *x
, int *y
) const
668 Window xwindow
= (Window
) m_mainWindow
;
670 wxCHECK_RET( xwindow
, wxT("invalid window") );
672 //XSync(wxGlobalDisplay(), False);
674 XWindowAttributes attr
;
675 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
680 *x
= attr
.width
/* + 2*m_borderSize */ ;
681 *y
= attr
.height
/* + 2*m_borderSize */ ;
685 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
687 Window window
= (Window
) m_mainWindow
;
690 //XSync(wxGlobalDisplay(), False);
691 XWindowAttributes attr
;
692 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
700 // We may be faking the client origin. So a window that's really at (0, 30)
701 // may appear (to wxWin apps) to be at (0, 0).
704 wxPoint
pt(GetParent()->GetClientAreaOrigin());
712 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
714 Display
*display
= wxGlobalDisplay();
715 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
716 Window thisWindow
= (Window
) m_clientWindow
;
721 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
724 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
726 Display
*display
= wxGlobalDisplay();
727 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
728 Window thisWindow
= (Window
) m_clientWindow
;
733 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
737 // Get size *available for subwindows* i.e. excluding menu bar etc.
738 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
740 Window window
= (Window
) m_mainWindow
;
744 XWindowAttributes attr
;
745 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
756 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
758 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
760 Window xwindow
= (Window
) m_mainWindow
;
762 wxCHECK_RET( xwindow
, wxT("invalid window") );
764 XWindowAttributes attr
;
765 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
766 wxCHECK_RET( status
, wxT("invalid window attributes") );
770 int new_w
= attr
.width
;
771 int new_h
= attr
.height
;
773 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
776 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
779 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
782 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
798 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
801 wxSizeEvent
event(wxSize(new_w
, new_h
), GetId());
802 event
.SetEventObject(this);
803 GetEventHandler()->ProcessEvent(event
);
807 void wxWindowX11::DoSetClientSize(int width
, int height
)
809 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
811 Window xwindow
= (Window
) m_mainWindow
;
813 wxCHECK_RET( xwindow
, wxT("invalid window") );
815 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
817 if (m_mainWindow
!= m_clientWindow
)
819 xwindow
= (Window
) m_clientWindow
;
821 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
826 if (HasFlag( wxSIMPLE_BORDER
))
832 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
836 // For implementation purposes - sometimes decorations make the client area
838 wxPoint
wxWindowX11::GetClientAreaOrigin() const
840 return wxPoint(0, 0);
843 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
845 Window xwindow
= (Window
) m_mainWindow
;
847 wxCHECK_RET( xwindow
, wxT("invalid window") );
851 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
852 if (m_mainWindow
!= m_clientWindow
)
854 xwindow
= (Window
) m_clientWindow
;
856 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
863 if (HasFlag( wxSIMPLE_BORDER
))
875 wxWindow
*window
= (wxWindow
*) this;
876 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
877 if (sb
&& sb
->IsShown())
879 wxSize size
= sb
->GetSize();
882 sb
= window
->GetScrollbar( wxVERTICAL
);
883 if (sb
&& sb
->IsShown())
885 wxSize size
= sb
->GetSize();
889 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
894 XWindowChanges windowChanges
;
897 windowChanges
.width
= width
;
898 windowChanges
.height
= height
;
899 windowChanges
.stack_mode
= 0;
900 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
902 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
907 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
915 XSizeHints sizeHints
;
918 if (minW
> -1 && minH
> -1)
920 sizeHints
.flags
|= PMinSize
;
921 sizeHints
.min_width
= minW
;
922 sizeHints
.min_height
= minH
;
924 if (maxW
> -1 && maxH
> -1)
926 sizeHints
.flags
|= PMaxSize
;
927 sizeHints
.max_width
= maxW
;
928 sizeHints
.max_height
= maxH
;
930 if (incW
> -1 && incH
> -1)
932 sizeHints
.flags
|= PResizeInc
;
933 sizeHints
.width_inc
= incW
;
934 sizeHints
.height_inc
= incH
;
937 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
941 // ---------------------------------------------------------------------------
943 // ---------------------------------------------------------------------------
945 int wxWindowX11::GetCharHeight() const
947 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
949 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
951 int direction
, ascent
, descent
;
953 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
956 // return (overall.ascent + overall.descent);
957 return (ascent
+ descent
);
960 int wxWindowX11::GetCharWidth() const
962 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
964 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
966 int direction
, ascent
, descent
;
968 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
971 return overall
.width
;
974 void wxWindowX11::GetTextExtent(const wxString
& string
,
976 int *descent
, int *externalLeading
,
977 const wxFont
*theFont
) const
979 wxFont fontToUse
= m_font
;
980 if (theFont
) fontToUse
= *theFont
;
982 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
984 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
986 int direction
, ascent
, descent2
;
988 int slen
= string
.Len();
992 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
993 &ascent
, &descent2
, &overall
);
996 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
997 &direction
, &ascent
, &descent2
, &overall
);
1000 *x
= (overall
.width
);
1002 *y
= (ascent
+ descent2
);
1004 *descent
= descent2
;
1005 if (externalLeading
)
1006 *externalLeading
= 0;
1010 // ----------------------------------------------------------------------------
1012 // ----------------------------------------------------------------------------
1014 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1020 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1021 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1026 GetSize( &width
, &height
);
1028 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1029 m_clearRegion
.Clear();
1030 m_clearRegion
.Union( 0, 0, width
, height
);
1036 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1037 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1042 GetSize( &width
, &height
);
1044 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1045 m_updateRegion
.Clear();
1046 m_updateRegion
.Union( 0, 0, width
, height
);
1050 void wxWindowX11::Update()
1054 // Send nc paint events.
1055 SendNcPaintEvents();
1058 if (!m_updateRegion
.IsEmpty())
1060 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1061 // Actually send erase events.
1064 // Actually send paint events.
1069 void wxWindowX11::Clear()
1071 // wxClientDC dc((wxWindow*) this);
1072 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1073 // dc.SetBackground(brush);
1077 void wxWindowX11::SendEraseEvents()
1079 if (m_clearRegion
.IsEmpty()) return;
1081 wxClientDC
dc( (wxWindow
*)this );
1082 dc
.SetClippingRegion( m_clearRegion
);
1084 wxEraseEvent
erase_event( GetId(), &dc
);
1085 erase_event
.SetEventObject( this );
1087 if (!GetEventHandler()->ProcessEvent(erase_event
))
1089 Window xwindow
= (Window
) m_clientWindow
;
1090 Display
*xdisplay
= wxGlobalDisplay();
1091 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1092 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1093 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1094 wxRegionIterator
upd( m_clearRegion
);
1097 XFillRectangle( xdisplay
, xwindow
, xgc
,
1098 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1101 XFreeGC( xdisplay
, xgc
);
1104 m_clearRegion
.Clear();
1107 void wxWindowX11::SendPaintEvents()
1109 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1111 m_clipPaintRegion
= TRUE
;
1113 wxPaintEvent
paint_event( GetId() );
1114 paint_event
.SetEventObject( this );
1115 GetEventHandler()->ProcessEvent( paint_event
);
1117 m_updateRegion
.Clear();
1119 m_clipPaintRegion
= FALSE
;
1122 void wxWindowX11::SendNcPaintEvents()
1124 wxNcPaintEvent
nc_paint_event( GetId() );
1125 nc_paint_event
.SetEventObject( this );
1126 GetEventHandler()->ProcessEvent( nc_paint_event
);
1129 // ----------------------------------------------------------------------------
1131 // ----------------------------------------------------------------------------
1133 // Responds to colour changes: passes event on to children.
1134 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1136 wxWindowList::Node
*node
= GetChildren().GetFirst();
1139 // Only propagate to non-top-level windows
1140 wxWindow
*win
= node
->GetData();
1141 if ( win
->GetParent() )
1143 wxSysColourChangedEvent event2
;
1144 event
.m_eventObject
= win
;
1145 win
->GetEventHandler()->ProcessEvent(event2
);
1148 node
= node
->GetNext();
1152 void wxWindowX11::OnInternalIdle()
1154 // Update invalidated regions.
1157 // This calls the UI-update mechanism (querying windows for
1158 // menu/toolbar/control state information)
1161 // Set the input focus if couldn't do it before
1162 if (m_needsInputFocus
)
1168 // ----------------------------------------------------------------------------
1169 // function which maintain the global hash table mapping Widgets to wxWindows
1170 // ----------------------------------------------------------------------------
1172 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1174 wxWindow
*oldItem
= NULL
;
1175 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1177 wxLogDebug("Widget table clash: new widget is %ld, %s",
1178 (long)w
, win
->GetClassInfo()->GetClassName());
1182 wxWidgetHashTable
->Put((long) w
, win
);
1184 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1185 w
, win
, win
->GetClassInfo()->GetClassName());
1190 wxWindow
*wxGetWindowFromTable(Window w
)
1192 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1195 void wxDeleteWindowFromTable(Window w
)
1197 wxWidgetHashTable
->Delete((long)w
);
1200 // ----------------------------------------------------------------------------
1201 // function which maintain the global hash table mapping client widgets
1202 // ----------------------------------------------------------------------------
1204 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1206 wxWindow
*oldItem
= NULL
;
1207 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1209 wxLogDebug("Client window table clash: new window is %ld, %s",
1210 (long)w
, win
->GetClassInfo()->GetClassName());
1214 wxClientWidgetHashTable
->Put((long) w
, win
);
1216 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1217 w
, win
, win
->GetClassInfo()->GetClassName());
1222 wxWindow
*wxGetClientWindowFromTable(Window w
)
1224 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1227 void wxDeleteClientWindowFromTable(Window w
)
1229 wxClientWidgetHashTable
->Delete((long)w
);
1232 // ----------------------------------------------------------------------------
1233 // add/remove window from the table
1234 // ----------------------------------------------------------------------------
1236 // ----------------------------------------------------------------------------
1237 // X11-specific accessors
1238 // ----------------------------------------------------------------------------
1240 WXWindow
wxWindowX11::GetMainWindow() const
1242 return m_mainWindow
;
1245 WXWindow
wxWindowX11::GetClientWindow() const
1247 return m_clientWindow
;
1250 // ----------------------------------------------------------------------------
1251 // TranslateXXXEvent() functions
1252 // ----------------------------------------------------------------------------
1254 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1256 switch (XEventGetType(xevent
))
1264 wxEventType eventType
= wxEVT_NULL
;
1266 if (XEventGetType(xevent
) == EnterNotify
)
1268 //if (local_event.xcrossing.mode!=NotifyNormal)
1269 // return ; // Ignore grab events
1270 eventType
= wxEVT_ENTER_WINDOW
;
1271 // canvas->GetEventHandler()->OnSetFocus();
1273 else if (XEventGetType(xevent
) == LeaveNotify
)
1275 //if (local_event.xcrossingr.mode!=NotifyNormal)
1276 // return ; // Ignore grab events
1277 eventType
= wxEVT_LEAVE_WINDOW
;
1278 // canvas->GetEventHandler()->OnKillFocus();
1280 else if (XEventGetType(xevent
) == MotionNotify
)
1282 eventType
= wxEVT_MOTION
;
1284 else if (XEventGetType(xevent
) == ButtonPress
)
1286 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1288 if (XButtonEventLChanged(xevent
))
1290 eventType
= wxEVT_LEFT_DOWN
;
1293 else if (XButtonEventMChanged(xevent
))
1295 eventType
= wxEVT_MIDDLE_DOWN
;
1298 else if (XButtonEventRChanged(xevent
))
1300 eventType
= wxEVT_RIGHT_DOWN
;
1304 // check for a double click
1305 // TODO: where can we get this value from?
1306 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1307 long dclickTime
= 200;
1308 long ts
= wxevent
.GetTimestamp();
1310 int buttonLast
= win
->GetLastClickedButton();
1311 long lastTS
= win
->GetLastClickTime();
1312 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1315 win
->SetLastClick(0, ts
);
1316 if ( eventType
== wxEVT_LEFT_DOWN
)
1317 eventType
= wxEVT_LEFT_DCLICK
;
1318 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1319 eventType
= wxEVT_MIDDLE_DCLICK
;
1320 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1321 eventType
= wxEVT_RIGHT_DCLICK
;
1325 // not fast enough or different button
1326 win
->SetLastClick(button
, ts
);
1329 else if (XEventGetType(xevent
) == ButtonRelease
)
1331 if (XButtonEventLChanged(xevent
))
1333 eventType
= wxEVT_LEFT_UP
;
1335 else if (XButtonEventMChanged(xevent
))
1337 eventType
= wxEVT_MIDDLE_UP
;
1339 else if (XButtonEventRChanged(xevent
))
1341 eventType
= wxEVT_RIGHT_UP
;
1350 wxevent
.SetEventType(eventType
);
1352 wxevent
.m_x
= XButtonEventGetX(xevent
);
1353 wxevent
.m_y
= XButtonEventGetY(xevent
);
1355 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1356 || (XButtonEventLIsDown(xevent
)
1357 && (eventType
!= wxEVT_LEFT_UP
)));
1358 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1359 || (XButtonEventMIsDown(xevent
)
1360 && (eventType
!= wxEVT_MIDDLE_UP
)));
1361 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1362 || (XButtonEventRIsDown (xevent
)
1363 && (eventType
!= wxEVT_RIGHT_UP
)));
1365 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1366 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1367 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1368 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1370 wxevent
.SetId(win
->GetId());
1371 wxevent
.SetEventObject(win
);
1379 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1381 switch (XEventGetType(xevent
))
1389 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1390 int id
= wxCharCodeXToWX (keySym
);
1392 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1393 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1394 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1395 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1396 wxevent
.SetEventObject(win
);
1397 wxevent
.m_keyCode
= id
;
1398 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1400 wxevent
.m_x
= XKeyEventGetX(xevent
);
1401 wxevent
.m_y
= XKeyEventGetY(xevent
);
1415 // ----------------------------------------------------------------------------
1417 // ----------------------------------------------------------------------------
1419 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1421 wxWindowBase::SetBackgroundColour(col
);
1423 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1424 int xscreen
= DefaultScreen( xdisplay
);
1425 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1427 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1429 if (!GetMainWindow())
1433 XSetWindowAttributes attrib;
1434 attrib.background_pixel = colour.GetPixel();
1436 XChangeWindowAttributes(wxGlobalDisplay(),
1437 (Window) GetMainWindow(),
1445 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1447 if ( !wxWindowBase::SetForegroundColour(col
) )
1453 // ----------------------------------------------------------------------------
1455 // ----------------------------------------------------------------------------
1457 wxWindow
*wxGetActiveWindow()
1460 wxFAIL_MSG("Not implemented");
1465 wxWindow
*wxWindowBase::GetCapture()
1467 return (wxWindow
*)g_captureWindow
;
1471 // Find the wxWindow at the current mouse position, returning the mouse
1473 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1475 return wxFindWindowAtPoint(wxGetMousePosition());
1478 // Get the current mouse position.
1479 wxPoint
wxGetMousePosition()
1483 return wxPoint(0, 0);
1485 Display
*display
= wxGlobalDisplay();
1486 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1487 Window rootReturn
, childReturn
;
1488 int rootX
, rootY
, winX
, winY
;
1489 unsigned int maskReturn
;
1491 XQueryPointer (display
,
1495 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1496 return wxPoint(rootX
, rootY
);
1501 // ----------------------------------------------------------------------------
1502 // wxNoOptimize: switch off size optimization
1503 // ----------------------------------------------------------------------------
1505 int wxNoOptimize::ms_count
= 0;