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
;
105 m_updateNcArea
= FALSE
;
107 m_winCaptured
= FALSE
;
108 m_needsInputFocus
= FALSE
;
110 m_isBeingDeleted
= FALSE
;
115 // real construction (Init() must have been called before!)
116 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
120 const wxString
& name
)
122 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
124 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
126 parent
->AddChild(this);
128 int w
= size
.GetWidth();
129 int h
= size
.GetHeight();
137 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
138 int xscreen
= DefaultScreen( xdisplay
);
139 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
140 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
142 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
143 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
145 m_foregroundColour
= *wxBLACK
;
146 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
148 Window xparent
= (Window
) parent
->GetClientWindow();
150 // Add window's own scrollbars to main window, not to client window
151 if (parent
->GetInsertIntoMain())
153 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
154 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
;
178 XSetWindowAttributes xattributes
;
179 long xattributes_mask
= 0;
181 xattributes_mask
|= CWBackPixel
;
182 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
184 xattributes_mask
|= CWBorderPixel
;
185 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
187 xattributes_mask
|= CWEventMask
;
189 if (need_two_windows
)
191 xattributes
.event_mask
=
192 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
194 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
195 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
197 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
199 m_mainWindow
= (WXWindow
) xwindow
;
200 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
202 XMapWindow( xdisplay
, xwindow
);
204 xattributes
.event_mask
=
205 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
206 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
207 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
208 PropertyChangeMask
| VisibilityChangeMask
;
210 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
212 xattributes_mask
|= CWBitGravity
;
213 xattributes
.bit_gravity
= StaticGravity
;
216 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
223 if (HasFlag( wxSIMPLE_BORDER
))
235 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
236 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
238 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
240 m_clientWindow
= (WXWindow
) xwindow
;
241 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
243 XMapWindow( xdisplay
, xwindow
);
247 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
249 xattributes
.event_mask
=
250 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
251 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
252 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
253 PropertyChangeMask
| VisibilityChangeMask
;
255 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
257 xattributes_mask
|= CWBitGravity
;
258 xattributes
.bit_gravity
= NorthWestGravity
;
261 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
262 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
264 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
266 m_mainWindow
= (WXWindow
) xwindow
;
267 m_clientWindow
= m_mainWindow
;
268 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
270 XMapWindow( xdisplay
, xwindow
);
274 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
276 long backColor
, foreColor
;
277 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
278 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
280 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
281 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
282 XSelectInput( xdisplay
, xwindow
,
283 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
284 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
285 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
286 PropertyChangeMask
);
288 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
290 m_mainWindow
= (WXWindow
) xwindow
;
291 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
293 XMapWindow( xdisplay
, xwindow
);
296 // Is a subwindow, so map immediately
299 // Without this, the cursor may not be restored properly (e.g. in splitter
301 SetCursor(*wxSTANDARD_CURSOR
);
302 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
304 // Don't call this, it can have nasty repercussions for composite controls,
306 // SetSize(pos.x, pos.y, size.x, size.y);
312 wxWindowX11::~wxWindowX11()
314 if (g_captureWindow
== this)
315 g_captureWindow
= NULL
;
317 m_isBeingDeleted
= TRUE
;
320 m_parent
->RemoveChild( this );
324 if (m_clientWindow
!= m_mainWindow
)
326 // Destroy the cleint window
327 Window xwindow
= (Window
) m_clientWindow
;
328 wxDeleteClientWindowFromTable( xwindow
);
329 XDestroyWindow( wxGlobalDisplay(), xwindow
);
330 m_clientWindow
= NULL
;
333 // Destroy the window
334 Window xwindow
= (Window
) m_mainWindow
;
335 wxDeleteWindowFromTable( xwindow
);
336 XDestroyWindow( wxGlobalDisplay(), xwindow
);
340 // ---------------------------------------------------------------------------
342 // ---------------------------------------------------------------------------
344 void wxWindowX11::SetFocus()
346 Window xwindow
= (Window
) m_clientWindow
;
348 wxCHECK_RET( xwindow
, wxT("invalid window") );
350 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
353 if (GetName() == "scrollBar")
360 if (wxWindowIsVisible(xwindow
))
362 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
363 m_needsInputFocus
= FALSE
;
367 m_needsInputFocus
= TRUE
;
371 // Get the window with the focus
372 wxWindow
*wxWindowBase::FindFocus()
374 Window xfocus
= (Window
) 0;
377 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
380 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
388 // Enabling/disabling handled by event loop, and not sending events
390 bool wxWindowX11::Enable(bool enable
)
392 if ( !wxWindowBase::Enable(enable
) )
398 bool wxWindowX11::Show(bool show
)
400 wxWindowBase::Show(show
);
402 Window xwindow
= (Window
) m_mainWindow
;
403 Display
*xdisp
= wxGlobalDisplay();
406 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
407 XMapWindow(xdisp
, xwindow
);
411 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
412 XUnmapWindow(xdisp
, xwindow
);
418 // Raise the window to the top of the Z order
419 void wxWindowX11::Raise()
422 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
425 // Lower the window to the bottom of the Z order
426 void wxWindowX11::Lower()
429 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
432 void wxWindowX11::DoCaptureMouse()
434 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
436 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
447 Window xwindow
= (Window
) m_clientWindow
;
449 wxCHECK_RET( xwindow
, wxT("invalid window") );
451 g_captureWindow
= (wxWindow
*) this;
455 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
457 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
461 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
464 if (res
!= GrabSuccess
)
467 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
469 if (res
== GrabNotViewable
)
471 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
473 g_captureWindow
= NULL
;
477 m_winCaptured
= TRUE
;
481 void wxWindowX11::DoReleaseMouse()
483 g_captureWindow
= NULL
;
485 if ( !m_winCaptured
)
488 Window xwindow
= (Window
) m_clientWindow
;
492 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
495 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
497 m_winCaptured
= FALSE
;
500 bool wxWindowX11::SetFont(const wxFont
& font
)
502 if ( !wxWindowBase::SetFont(font
) )
511 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
513 if ( !wxWindowBase::SetCursor(cursor
) )
519 Window xwindow
= (Window
) m_clientWindow
;
521 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
523 wxCursor cursorToUse
;
525 cursorToUse
= m_cursor
;
527 cursorToUse
= *wxSTANDARD_CURSOR
;
529 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
531 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
536 // Coordinates relative to the window
537 void wxWindowX11::WarpPointer (int x
, int y
)
539 Window xwindow
= (Window
) m_clientWindow
;
541 wxCHECK_RET( xwindow
, wxT("invalid window") );
543 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
546 // Does a physical scroll
547 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
549 // No scrolling requested.
550 if ((dx
== 0) && (dy
== 0)) return;
552 if (!m_updateRegion
.IsEmpty())
554 m_updateRegion
.Offset( dx
, dy
);
558 GetSize( &cw
, &ch
); // GetClientSize() ??
559 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
562 if (!m_clearRegion
.IsEmpty())
564 m_clearRegion
.Offset( dx
, dy
);
568 GetSize( &cw
, &ch
); // GetClientSize() ??
569 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
572 Window xwindow
= (Window
) GetClientWindow();
574 wxCHECK_RET( xwindow
, wxT("invalid window") );
576 Display
*xdisplay
= wxGlobalDisplay();
578 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
579 XSetGraphicsExposures( xdisplay
, xgc
, True
);
597 GetClientSize( &cw
, &ch
);
600 #if wxUSE_TWO_WINDOWS
601 wxPoint
offset( 0,0 );
603 wxPoint offset
= GetClientAreaOrigin();
608 int w
= cw
- abs(dx
);
609 int h
= ch
- abs(dy
);
611 if ((h
< 0) || (w
< 0))
618 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
619 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
620 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
621 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
626 if (dx
< 0) s_x
+= -dx
;
627 if (dy
< 0) s_y
+= -dy
;
628 if (dx
> 0) d_x
= dx
+ offset
.x
;
629 if (dy
> 0) d_y
= dy
+ offset
.y
;
631 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
633 // 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 );
635 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
637 m_updateRegion
.Union( rect
);
638 m_clearRegion
.Union( rect
);
641 XFreeGC( xdisplay
, xgc
);
644 // ---------------------------------------------------------------------------
646 // ---------------------------------------------------------------------------
648 #if wxUSE_DRAG_AND_DROP
650 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
657 // Old style file-manager drag&drop
658 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
663 // ----------------------------------------------------------------------------
665 // ----------------------------------------------------------------------------
669 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
674 #endif // wxUSE_TOOLTIPS
676 // ---------------------------------------------------------------------------
677 // moving and resizing
678 // ---------------------------------------------------------------------------
680 bool wxWindowX11::PreResize()
686 void wxWindowX11::DoGetSize(int *x
, int *y
) const
688 Window xwindow
= (Window
) m_mainWindow
;
690 wxCHECK_RET( xwindow
, wxT("invalid window") );
692 //XSync(wxGlobalDisplay(), False);
694 XWindowAttributes attr
;
695 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
700 *x
= attr
.width
/* + 2*m_borderSize */ ;
701 *y
= attr
.height
/* + 2*m_borderSize */ ;
705 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
707 Window window
= (Window
) m_mainWindow
;
710 //XSync(wxGlobalDisplay(), False);
711 XWindowAttributes attr
;
712 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
720 // We may be faking the client origin. So a window that's really at (0, 30)
721 // may appear (to wxWin apps) to be at (0, 0).
724 wxPoint
pt(GetParent()->GetClientAreaOrigin());
732 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
734 Display
*display
= wxGlobalDisplay();
735 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
736 Window thisWindow
= (Window
) m_clientWindow
;
741 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
744 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
746 Display
*display
= wxGlobalDisplay();
747 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
748 Window thisWindow
= (Window
) m_clientWindow
;
753 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
757 // Get size *available for subwindows* i.e. excluding menu bar etc.
758 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
760 Window window
= (Window
) m_mainWindow
;
764 XWindowAttributes attr
;
765 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
776 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
778 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
780 Window xwindow
= (Window
) m_mainWindow
;
782 wxCHECK_RET( xwindow
, wxT("invalid window") );
784 XWindowAttributes attr
;
785 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
786 wxCHECK_RET( status
, wxT("invalid window attributes") );
790 int new_w
= attr
.width
;
791 int new_h
= attr
.height
;
793 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
796 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
799 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
802 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
818 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
821 wxSizeEvent
event(wxSize(new_w
, new_h
), GetId());
822 event
.SetEventObject(this);
823 GetEventHandler()->ProcessEvent(event
);
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 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
846 if (HasFlag( wxSIMPLE_BORDER
))
852 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
856 // For implementation purposes - sometimes decorations make the client area
858 wxPoint
wxWindowX11::GetClientAreaOrigin() const
860 return wxPoint(0, 0);
863 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
865 Window xwindow
= (Window
) m_mainWindow
;
867 wxCHECK_RET( xwindow
, wxT("invalid window") );
871 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
872 if (m_mainWindow
!= m_clientWindow
)
874 xwindow
= (Window
) m_clientWindow
;
876 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
883 if (HasFlag( wxSIMPLE_BORDER
))
895 wxWindow
*window
= (wxWindow
*) this;
896 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
897 if (sb
&& sb
->IsShown())
899 wxSize size
= sb
->GetSize();
902 sb
= window
->GetScrollbar( wxVERTICAL
);
903 if (sb
&& sb
->IsShown())
905 wxSize size
= sb
->GetSize();
909 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
914 XWindowChanges windowChanges
;
917 windowChanges
.width
= width
;
918 windowChanges
.height
= height
;
919 windowChanges
.stack_mode
= 0;
920 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
922 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
927 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
935 XSizeHints sizeHints
;
938 if (minW
> -1 && minH
> -1)
940 sizeHints
.flags
|= PMinSize
;
941 sizeHints
.min_width
= minW
;
942 sizeHints
.min_height
= minH
;
944 if (maxW
> -1 && maxH
> -1)
946 sizeHints
.flags
|= PMaxSize
;
947 sizeHints
.max_width
= maxW
;
948 sizeHints
.max_height
= maxH
;
950 if (incW
> -1 && incH
> -1)
952 sizeHints
.flags
|= PResizeInc
;
953 sizeHints
.width_inc
= incW
;
954 sizeHints
.height_inc
= incH
;
957 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
961 // ---------------------------------------------------------------------------
963 // ---------------------------------------------------------------------------
965 int wxWindowX11::GetCharHeight() const
967 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
969 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
971 int direction
, ascent
, descent
;
973 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
976 // return (overall.ascent + overall.descent);
977 return (ascent
+ descent
);
980 int wxWindowX11::GetCharWidth() const
982 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
984 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
986 int direction
, ascent
, descent
;
988 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
991 return overall
.width
;
994 void wxWindowX11::GetTextExtent(const wxString
& string
,
996 int *descent
, int *externalLeading
,
997 const wxFont
*theFont
) const
999 wxFont fontToUse
= m_font
;
1000 if (theFont
) fontToUse
= *theFont
;
1002 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1004 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1006 int direction
, ascent
, descent2
;
1007 XCharStruct overall
;
1008 int slen
= string
.Len();
1012 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1013 &ascent
, &descent2
, &overall
);
1016 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1017 &direction
, &ascent
, &descent2
, &overall
);
1020 *x
= (overall
.width
);
1022 *y
= (ascent
+ descent2
);
1024 *descent
= descent2
;
1025 if (externalLeading
)
1026 *externalLeading
= 0;
1030 // ----------------------------------------------------------------------------
1032 // ----------------------------------------------------------------------------
1034 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1040 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1041 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1046 GetSize( &width
, &height
);
1048 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1049 m_clearRegion
.Clear();
1050 m_clearRegion
.Union( 0, 0, width
, height
);
1056 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1057 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1062 GetSize( &width
, &height
);
1064 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1065 m_updateRegion
.Clear();
1066 m_updateRegion
.Union( 0, 0, width
, height
);
1070 void wxWindowX11::Update()
1074 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1075 // Send nc paint events.
1076 SendNcPaintEvents();
1079 if (!m_updateRegion
.IsEmpty())
1081 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1082 // Actually send erase events.
1085 // Actually send paint events.
1090 void wxWindowX11::Clear()
1092 // wxClientDC dc((wxWindow*) this);
1093 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1094 // dc.SetBackground(brush);
1098 void wxWindowX11::SendEraseEvents()
1100 if (m_clearRegion
.IsEmpty()) return;
1102 wxClientDC
dc( (wxWindow
*)this );
1103 dc
.SetClippingRegion( m_clearRegion
);
1105 wxEraseEvent
erase_event( GetId(), &dc
);
1106 erase_event
.SetEventObject( this );
1108 if (!GetEventHandler()->ProcessEvent(erase_event
))
1110 Window xwindow
= (Window
) m_clientWindow
;
1111 Display
*xdisplay
= wxGlobalDisplay();
1112 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
1113 XSetFillStyle( xdisplay
, xgc
, FillSolid
);
1114 XSetForeground( xdisplay
, xgc
, m_backgroundColour
.GetPixel() );
1115 wxRegionIterator
upd( m_clearRegion
);
1118 XFillRectangle( xdisplay
, xwindow
, xgc
,
1119 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1122 XFreeGC( xdisplay
, xgc
);
1125 m_clearRegion
.Clear();
1128 void wxWindowX11::SendPaintEvents()
1130 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1132 m_clipPaintRegion
= TRUE
;
1134 wxPaintEvent
paint_event( GetId() );
1135 paint_event
.SetEventObject( this );
1136 GetEventHandler()->ProcessEvent( paint_event
);
1138 m_updateRegion
.Clear();
1140 m_clipPaintRegion
= FALSE
;
1143 void wxWindowX11::SendNcPaintEvents()
1145 wxNcPaintEvent
nc_paint_event( GetId() );
1146 nc_paint_event
.SetEventObject( this );
1147 GetEventHandler()->ProcessEvent( nc_paint_event
);
1149 m_updateNcArea
= FALSE
;
1152 // ----------------------------------------------------------------------------
1154 // ----------------------------------------------------------------------------
1156 // Responds to colour changes: passes event on to children.
1157 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1159 wxWindowList::Node
*node
= GetChildren().GetFirst();
1162 // Only propagate to non-top-level windows
1163 wxWindow
*win
= node
->GetData();
1164 if ( win
->GetParent() )
1166 wxSysColourChangedEvent event2
;
1167 event
.m_eventObject
= win
;
1168 win
->GetEventHandler()->ProcessEvent(event2
);
1171 node
= node
->GetNext();
1175 void wxWindowX11::OnInternalIdle()
1177 // Update invalidated regions.
1180 // This calls the UI-update mechanism (querying windows for
1181 // menu/toolbar/control state information)
1184 // Set the input focus if couldn't do it before
1185 if (m_needsInputFocus
)
1191 // ----------------------------------------------------------------------------
1192 // function which maintain the global hash table mapping Widgets to wxWindows
1193 // ----------------------------------------------------------------------------
1195 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1197 wxWindow
*oldItem
= NULL
;
1198 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1200 wxLogDebug("Widget table clash: new widget is %ld, %s",
1201 (long)w
, win
->GetClassInfo()->GetClassName());
1205 wxWidgetHashTable
->Put((long) w
, win
);
1207 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1208 w
, win
, win
->GetClassInfo()->GetClassName());
1213 wxWindow
*wxGetWindowFromTable(Window w
)
1215 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1218 void wxDeleteWindowFromTable(Window w
)
1220 wxWidgetHashTable
->Delete((long)w
);
1223 // ----------------------------------------------------------------------------
1224 // function which maintain the global hash table mapping client widgets
1225 // ----------------------------------------------------------------------------
1227 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1229 wxWindow
*oldItem
= NULL
;
1230 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1232 wxLogDebug("Client window table clash: new window is %ld, %s",
1233 (long)w
, win
->GetClassInfo()->GetClassName());
1237 wxClientWidgetHashTable
->Put((long) w
, win
);
1239 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1240 w
, win
, win
->GetClassInfo()->GetClassName());
1245 wxWindow
*wxGetClientWindowFromTable(Window w
)
1247 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1250 void wxDeleteClientWindowFromTable(Window w
)
1252 wxClientWidgetHashTable
->Delete((long)w
);
1255 // ----------------------------------------------------------------------------
1256 // add/remove window from the table
1257 // ----------------------------------------------------------------------------
1259 // ----------------------------------------------------------------------------
1260 // X11-specific accessors
1261 // ----------------------------------------------------------------------------
1263 WXWindow
wxWindowX11::GetMainWindow() const
1265 return m_mainWindow
;
1268 WXWindow
wxWindowX11::GetClientWindow() const
1270 return m_clientWindow
;
1273 // ----------------------------------------------------------------------------
1274 // TranslateXXXEvent() functions
1275 // ----------------------------------------------------------------------------
1277 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1279 switch (XEventGetType(xevent
))
1287 wxEventType eventType
= wxEVT_NULL
;
1289 if (XEventGetType(xevent
) == EnterNotify
)
1291 //if (local_event.xcrossing.mode!=NotifyNormal)
1292 // return ; // Ignore grab events
1293 eventType
= wxEVT_ENTER_WINDOW
;
1294 // canvas->GetEventHandler()->OnSetFocus();
1296 else if (XEventGetType(xevent
) == LeaveNotify
)
1298 //if (local_event.xcrossingr.mode!=NotifyNormal)
1299 // return ; // Ignore grab events
1300 eventType
= wxEVT_LEAVE_WINDOW
;
1301 // canvas->GetEventHandler()->OnKillFocus();
1303 else if (XEventGetType(xevent
) == MotionNotify
)
1305 eventType
= wxEVT_MOTION
;
1307 else if (XEventGetType(xevent
) == ButtonPress
)
1309 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1311 if (XButtonEventLChanged(xevent
))
1313 eventType
= wxEVT_LEFT_DOWN
;
1316 else if (XButtonEventMChanged(xevent
))
1318 eventType
= wxEVT_MIDDLE_DOWN
;
1321 else if (XButtonEventRChanged(xevent
))
1323 eventType
= wxEVT_RIGHT_DOWN
;
1327 // check for a double click
1328 // TODO: where can we get this value from?
1329 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1330 long dclickTime
= 200;
1331 long ts
= wxevent
.GetTimestamp();
1333 int buttonLast
= win
->GetLastClickedButton();
1334 long lastTS
= win
->GetLastClickTime();
1335 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1338 win
->SetLastClick(0, ts
);
1339 if ( eventType
== wxEVT_LEFT_DOWN
)
1340 eventType
= wxEVT_LEFT_DCLICK
;
1341 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1342 eventType
= wxEVT_MIDDLE_DCLICK
;
1343 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1344 eventType
= wxEVT_RIGHT_DCLICK
;
1348 // not fast enough or different button
1349 win
->SetLastClick(button
, ts
);
1352 else if (XEventGetType(xevent
) == ButtonRelease
)
1354 if (XButtonEventLChanged(xevent
))
1356 eventType
= wxEVT_LEFT_UP
;
1358 else if (XButtonEventMChanged(xevent
))
1360 eventType
= wxEVT_MIDDLE_UP
;
1362 else if (XButtonEventRChanged(xevent
))
1364 eventType
= wxEVT_RIGHT_UP
;
1373 wxevent
.SetEventType(eventType
);
1375 wxevent
.m_x
= XButtonEventGetX(xevent
);
1376 wxevent
.m_y
= XButtonEventGetY(xevent
);
1378 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1379 || (XButtonEventLIsDown(xevent
)
1380 && (eventType
!= wxEVT_LEFT_UP
)));
1381 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1382 || (XButtonEventMIsDown(xevent
)
1383 && (eventType
!= wxEVT_MIDDLE_UP
)));
1384 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1385 || (XButtonEventRIsDown (xevent
)
1386 && (eventType
!= wxEVT_RIGHT_UP
)));
1388 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1389 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1390 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1391 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1393 wxevent
.SetId(win
->GetId());
1394 wxevent
.SetEventObject(win
);
1402 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1404 switch (XEventGetType(xevent
))
1412 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1413 int id
= wxCharCodeXToWX (keySym
);
1415 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1416 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1417 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1418 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1419 wxevent
.SetEventObject(win
);
1420 wxevent
.m_keyCode
= id
;
1421 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1423 wxevent
.m_x
= XKeyEventGetX(xevent
);
1424 wxevent
.m_y
= XKeyEventGetY(xevent
);
1438 // ----------------------------------------------------------------------------
1440 // ----------------------------------------------------------------------------
1442 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1444 wxWindowBase::SetBackgroundColour(col
);
1446 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1447 int xscreen
= DefaultScreen( xdisplay
);
1448 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1450 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1452 if (!GetMainWindow())
1456 XSetWindowAttributes attrib;
1457 attrib.background_pixel = colour.GetPixel();
1459 XChangeWindowAttributes(wxGlobalDisplay(),
1460 (Window) GetMainWindow(),
1468 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1470 if ( !wxWindowBase::SetForegroundColour(col
) )
1476 // ----------------------------------------------------------------------------
1478 // ----------------------------------------------------------------------------
1480 wxWindow
*wxGetActiveWindow()
1483 wxFAIL_MSG("Not implemented");
1488 wxWindow
*wxWindowBase::GetCapture()
1490 return (wxWindow
*)g_captureWindow
;
1494 // Find the wxWindow at the current mouse position, returning the mouse
1496 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1498 return wxFindWindowAtPoint(wxGetMousePosition());
1501 // Get the current mouse position.
1502 wxPoint
wxGetMousePosition()
1506 return wxPoint(0, 0);
1508 Display
*display
= wxGlobalDisplay();
1509 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1510 Window rootReturn
, childReturn
;
1511 int rootX
, rootY
, winX
, winY
;
1512 unsigned int maskReturn
;
1514 XQueryPointer (display
,
1518 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1519 return wxPoint(rootX
, rootY
);
1524 // ----------------------------------------------------------------------------
1525 // wxNoOptimize: switch off size optimization
1526 // ----------------------------------------------------------------------------
1528 int wxNoOptimize::ms_count
= 0;