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
;
67 // ----------------------------------------------------------------------------
69 // ----------------------------------------------------------------------------
71 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
72 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
73 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
81 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
82 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
85 // ============================================================================
87 // ============================================================================
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 void wxWindowX11::Init()
99 // generic initializations first
103 m_mainWindow
= (WXWindow
) 0;
104 m_clientWindow
= (WXWindow
) 0;
105 m_insertIntoMain
= FALSE
;
106 m_updateNcArea
= FALSE
;
108 m_winCaptured
= FALSE
;
109 m_needsInputFocus
= FALSE
;
111 m_isBeingDeleted
= FALSE
;
116 // real construction (Init() must have been called before!)
117 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
121 const wxString
& name
)
123 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
125 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
127 parent
->AddChild(this);
129 int w
= size
.GetWidth();
130 int h
= size
.GetHeight();
138 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
139 int xscreen
= DefaultScreen( xdisplay
);
140 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
141 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
143 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
144 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
146 m_foregroundColour
= *wxBLACK
;
147 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
149 Window xparent
= (Window
) parent
->GetClientWindow();
151 // Add window's own scrollbars to main window, not to client window
152 if (parent
->GetInsertIntoMain())
154 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
155 xparent
= (Window
) parent
->GetMainWindow();
172 #if wxUSE_TWO_WINDOWS
173 bool need_two_windows
=
174 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
176 bool need_two_windows
= FALSE
;
179 XSetWindowAttributes xattributes
;
180 long xattributes_mask
= 0;
182 xattributes_mask
|= CWBackPixel
;
183 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
185 xattributes_mask
|= CWBorderPixel
;
186 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
188 xattributes_mask
|= CWEventMask
;
190 if (need_two_windows
)
192 xattributes
.event_mask
=
193 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
195 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
196 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
198 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
200 m_mainWindow
= (WXWindow
) xwindow
;
201 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
203 XMapWindow( xdisplay
, xwindow
);
205 xattributes
.event_mask
=
206 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
207 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
208 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
209 PropertyChangeMask
| VisibilityChangeMask
;
211 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
213 xattributes_mask
|= CWBitGravity
;
214 xattributes
.bit_gravity
= StaticGravity
;
217 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
224 if (HasFlag( wxSIMPLE_BORDER
))
236 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
237 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
239 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
241 m_clientWindow
= (WXWindow
) xwindow
;
242 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
244 XMapWindow( xdisplay
, xwindow
);
248 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
250 xattributes
.event_mask
=
251 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
252 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
253 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
254 PropertyChangeMask
| VisibilityChangeMask
;
256 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
258 xattributes_mask
|= CWBitGravity
;
259 xattributes
.bit_gravity
= NorthWestGravity
;
262 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
263 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
265 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
267 m_mainWindow
= (WXWindow
) xwindow
;
268 m_clientWindow
= m_mainWindow
;
269 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
271 XMapWindow( xdisplay
, xwindow
);
275 int extraFlags
= GR_EVENT_MASK_CLOSE_REQ
;
277 long backColor
, foreColor
;
278 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
279 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
281 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
282 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
283 XSelectInput( xdisplay
, xwindow
,
284 extraFlags
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
285 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
286 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
287 PropertyChangeMask
);
289 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
291 m_mainWindow
= (WXWindow
) xwindow
;
292 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
294 XMapWindow( xdisplay
, xwindow
);
297 // Is a subwindow, so map immediately
300 // Without this, the cursor may not be restored properly (e.g. in splitter
302 SetCursor(*wxSTANDARD_CURSOR
);
303 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
305 // Don't call this, it can have nasty repercussions for composite controls,
307 // SetSize(pos.x, pos.y, size.x, size.y);
313 wxWindowX11::~wxWindowX11()
315 if (g_captureWindow
== this)
316 g_captureWindow
= NULL
;
318 m_isBeingDeleted
= TRUE
;
321 m_parent
->RemoveChild( this );
325 if (m_clientWindow
!= m_mainWindow
)
327 // Destroy the cleint window
328 Window xwindow
= (Window
) m_clientWindow
;
329 wxDeleteClientWindowFromTable( xwindow
);
330 XDestroyWindow( wxGlobalDisplay(), xwindow
);
331 m_clientWindow
= NULL
;
334 // Destroy the window
335 Window xwindow
= (Window
) m_mainWindow
;
336 wxDeleteWindowFromTable( xwindow
);
337 XDestroyWindow( wxGlobalDisplay(), xwindow
);
341 // ---------------------------------------------------------------------------
343 // ---------------------------------------------------------------------------
345 void wxWindowX11::SetFocus()
347 Window xwindow
= (Window
) m_clientWindow
;
349 wxCHECK_RET( xwindow
, wxT("invalid window") );
351 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
354 if (GetName() == "scrollBar")
361 if (wxWindowIsVisible(xwindow
))
363 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToParent
, CurrentTime
);
364 m_needsInputFocus
= FALSE
;
368 m_needsInputFocus
= TRUE
;
372 // Get the window with the focus
373 wxWindow
*wxWindowBase::FindFocus()
375 Window xfocus
= (Window
) 0;
378 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
381 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
389 // Enabling/disabling handled by event loop, and not sending events
391 bool wxWindowX11::Enable(bool enable
)
393 if ( !wxWindowBase::Enable(enable
) )
399 bool wxWindowX11::Show(bool show
)
401 wxWindowBase::Show(show
);
403 Window xwindow
= (Window
) m_mainWindow
;
404 Display
*xdisp
= wxGlobalDisplay();
407 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
408 XMapWindow(xdisp
, xwindow
);
412 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
413 XUnmapWindow(xdisp
, xwindow
);
419 // Raise the window to the top of the Z order
420 void wxWindowX11::Raise()
423 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
426 // Lower the window to the bottom of the Z order
427 void wxWindowX11::Lower()
430 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
433 void wxWindowX11::DoCaptureMouse()
435 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
437 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
448 Window xwindow
= (Window
) m_clientWindow
;
450 wxCHECK_RET( xwindow
, wxT("invalid window") );
452 g_captureWindow
= (wxWindow
*) this;
456 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
458 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
462 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
465 if (res
!= GrabSuccess
)
468 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
470 if (res
== GrabNotViewable
)
472 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
474 g_captureWindow
= NULL
;
478 m_winCaptured
= TRUE
;
482 void wxWindowX11::DoReleaseMouse()
484 g_captureWindow
= NULL
;
486 if ( !m_winCaptured
)
489 Window xwindow
= (Window
) m_clientWindow
;
493 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
496 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
498 m_winCaptured
= FALSE
;
501 bool wxWindowX11::SetFont(const wxFont
& font
)
503 if ( !wxWindowBase::SetFont(font
) )
512 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
514 if ( !wxWindowBase::SetCursor(cursor
) )
520 Window xwindow
= (Window
) m_clientWindow
;
522 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
524 wxCursor cursorToUse
;
526 cursorToUse
= m_cursor
;
528 cursorToUse
= *wxSTANDARD_CURSOR
;
530 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
532 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
537 // Coordinates relative to the window
538 void wxWindowX11::WarpPointer (int x
, int y
)
540 Window xwindow
= (Window
) m_clientWindow
;
542 wxCHECK_RET( xwindow
, wxT("invalid window") );
544 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
547 // Does a physical scroll
548 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
550 // No scrolling requested.
551 if ((dx
== 0) && (dy
== 0)) return;
553 if (!m_updateRegion
.IsEmpty())
555 m_updateRegion
.Offset( dx
, dy
);
559 GetSize( &cw
, &ch
); // GetClientSize() ??
560 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
563 if (!m_clearRegion
.IsEmpty())
565 m_clearRegion
.Offset( dx
, dy
);
569 GetSize( &cw
, &ch
); // GetClientSize() ??
570 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
573 Window xwindow
= (Window
) GetClientWindow();
575 wxCHECK_RET( xwindow
, wxT("invalid window") );
577 Display
*xdisplay
= wxGlobalDisplay();
579 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
580 XSetGraphicsExposures( xdisplay
, xgc
, True
);
598 GetClientSize( &cw
, &ch
);
601 #if wxUSE_TWO_WINDOWS
602 wxPoint
offset( 0,0 );
604 wxPoint offset
= GetClientAreaOrigin();
609 int w
= cw
- abs(dx
);
610 int h
= ch
- abs(dy
);
612 if ((h
< 0) || (w
< 0))
619 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
620 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
621 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
622 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
627 if (dx
< 0) s_x
+= -dx
;
628 if (dy
< 0) s_y
+= -dy
;
629 if (dx
> 0) d_x
= dx
+ offset
.x
;
630 if (dy
> 0) d_y
= dy
+ offset
.y
;
632 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
634 // 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 );
636 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
638 m_updateRegion
.Union( rect
);
639 m_clearRegion
.Union( rect
);
642 XFreeGC( xdisplay
, xgc
);
645 // ---------------------------------------------------------------------------
647 // ---------------------------------------------------------------------------
649 #if wxUSE_DRAG_AND_DROP
651 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
658 // Old style file-manager drag&drop
659 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
664 // ----------------------------------------------------------------------------
666 // ----------------------------------------------------------------------------
670 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
675 #endif // wxUSE_TOOLTIPS
677 // ---------------------------------------------------------------------------
678 // moving and resizing
679 // ---------------------------------------------------------------------------
681 bool wxWindowX11::PreResize()
687 void wxWindowX11::DoGetSize(int *x
, int *y
) const
689 Window xwindow
= (Window
) m_mainWindow
;
691 wxCHECK_RET( xwindow
, wxT("invalid window") );
693 //XSync(wxGlobalDisplay(), False);
695 XWindowAttributes attr
;
696 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
701 *x
= attr
.width
/* + 2*m_borderSize */ ;
702 *y
= attr
.height
/* + 2*m_borderSize */ ;
706 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
708 Window window
= (Window
) m_mainWindow
;
711 //XSync(wxGlobalDisplay(), False);
712 XWindowAttributes attr
;
713 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
721 // We may be faking the client origin. So a window that's really at (0, 30)
722 // may appear (to wxWin apps) to be at (0, 0).
725 wxPoint
pt(GetParent()->GetClientAreaOrigin());
733 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
735 Display
*display
= wxGlobalDisplay();
736 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
737 Window thisWindow
= (Window
) m_clientWindow
;
742 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
745 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
747 Display
*display
= wxGlobalDisplay();
748 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
749 Window thisWindow
= (Window
) m_clientWindow
;
754 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
758 // Get size *available for subwindows* i.e. excluding menu bar etc.
759 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
761 Window window
= (Window
) m_mainWindow
;
765 XWindowAttributes attr
;
766 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
777 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
779 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
781 Window xwindow
= (Window
) m_mainWindow
;
783 wxCHECK_RET( xwindow
, wxT("invalid window") );
785 XWindowAttributes attr
;
786 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
787 wxCHECK_RET( status
, wxT("invalid window attributes") );
791 int new_w
= attr
.width
;
792 int new_h
= attr
.height
;
794 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
797 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
800 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
803 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
819 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
822 void wxWindowX11::DoSetClientSize(int width
, int height
)
824 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
826 Window xwindow
= (Window
) m_mainWindow
;
828 wxCHECK_RET( xwindow
, wxT("invalid window") );
830 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
832 if (m_mainWindow
!= m_clientWindow
)
834 xwindow
= (Window
) m_clientWindow
;
836 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
841 if (HasFlag( wxSIMPLE_BORDER
))
847 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
851 // For implementation purposes - sometimes decorations make the client area
853 wxPoint
wxWindowX11::GetClientAreaOrigin() const
855 return wxPoint(0, 0);
858 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
860 Window xwindow
= (Window
) m_mainWindow
;
862 wxCHECK_RET( xwindow
, wxT("invalid window") );
866 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
867 if (m_mainWindow
!= m_clientWindow
)
869 xwindow
= (Window
) m_clientWindow
;
871 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
878 if (HasFlag( wxSIMPLE_BORDER
))
890 wxWindow
*window
= (wxWindow
*) this;
891 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
892 if (sb
&& sb
->IsShown())
894 wxSize size
= sb
->GetSize();
897 sb
= window
->GetScrollbar( wxVERTICAL
);
898 if (sb
&& sb
->IsShown())
900 wxSize size
= sb
->GetSize();
904 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
909 XWindowChanges windowChanges
;
912 windowChanges
.width
= width
;
913 windowChanges
.height
= height
;
914 windowChanges
.stack_mode
= 0;
915 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
917 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
922 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
930 XSizeHints sizeHints
;
933 if (minW
> -1 && minH
> -1)
935 sizeHints
.flags
|= PMinSize
;
936 sizeHints
.min_width
= minW
;
937 sizeHints
.min_height
= minH
;
939 if (maxW
> -1 && maxH
> -1)
941 sizeHints
.flags
|= PMaxSize
;
942 sizeHints
.max_width
= maxW
;
943 sizeHints
.max_height
= maxH
;
945 if (incW
> -1 && incH
> -1)
947 sizeHints
.flags
|= PResizeInc
;
948 sizeHints
.width_inc
= incW
;
949 sizeHints
.height_inc
= incH
;
952 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
956 // ---------------------------------------------------------------------------
958 // ---------------------------------------------------------------------------
960 int wxWindowX11::GetCharHeight() 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.ascent + overall.descent);
972 return (ascent
+ descent
);
975 int wxWindowX11::GetCharWidth() const
977 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
979 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
981 int direction
, ascent
, descent
;
983 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
986 return overall
.width
;
989 void wxWindowX11::GetTextExtent(const wxString
& string
,
991 int *descent
, int *externalLeading
,
992 const wxFont
*theFont
) const
994 wxFont fontToUse
= m_font
;
995 if (theFont
) fontToUse
= *theFont
;
997 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
999 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1001 int direction
, ascent
, descent2
;
1002 XCharStruct overall
;
1003 int slen
= string
.Len();
1007 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1008 &ascent
, &descent2
, &overall
);
1011 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1012 &direction
, &ascent
, &descent2
, &overall
);
1015 *x
= (overall
.width
);
1017 *y
= (ascent
+ descent2
);
1019 *descent
= descent2
;
1020 if (externalLeading
)
1021 *externalLeading
= 0;
1025 // ----------------------------------------------------------------------------
1027 // ----------------------------------------------------------------------------
1029 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1035 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1036 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1041 GetSize( &width
, &height
);
1043 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1044 m_clearRegion
.Clear();
1045 m_clearRegion
.Union( 0, 0, width
, height
);
1051 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1052 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1057 GetSize( &width
, &height
);
1059 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1060 m_updateRegion
.Clear();
1061 m_updateRegion
.Union( 0, 0, width
, height
);
1065 void wxWindowX11::Update()
1069 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1070 // Send nc paint events.
1071 SendNcPaintEvents();
1074 if (!m_updateRegion
.IsEmpty())
1076 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1077 // Actually send erase events.
1080 // Actually send paint events.
1085 void wxWindowX11::Clear()
1087 // wxClientDC dc((wxWindow*) this);
1088 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1089 // dc.SetBackground(brush);
1093 void wxWindowX11::SendEraseEvents()
1095 if (m_clearRegion
.IsEmpty()) return;
1097 wxClientDC
dc( (wxWindow
*)this );
1098 dc
.SetClippingRegion( m_clearRegion
);
1100 wxEraseEvent
erase_event( GetId(), &dc
);
1101 erase_event
.SetEventObject( this );
1103 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1105 Display
*xdisplay
= wxGlobalDisplay();
1106 Window xwindow
= (Window
) GetClientWindow();
1107 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1109 wxRegionIterator
upd( m_clearRegion
);
1112 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1113 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1118 m_clearRegion
.Clear();
1121 void wxWindowX11::SendPaintEvents()
1123 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1125 m_clipPaintRegion
= TRUE
;
1127 wxPaintEvent
paint_event( GetId() );
1128 paint_event
.SetEventObject( this );
1129 GetEventHandler()->ProcessEvent( paint_event
);
1131 m_updateRegion
.Clear();
1133 m_clipPaintRegion
= FALSE
;
1136 void wxWindowX11::SendNcPaintEvents()
1138 wxNcPaintEvent
nc_paint_event( GetId() );
1139 nc_paint_event
.SetEventObject( this );
1140 GetEventHandler()->ProcessEvent( nc_paint_event
);
1142 m_updateNcArea
= FALSE
;
1145 // ----------------------------------------------------------------------------
1147 // ----------------------------------------------------------------------------
1149 // Responds to colour changes: passes event on to children.
1150 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1152 wxWindowList::Node
*node
= GetChildren().GetFirst();
1155 // Only propagate to non-top-level windows
1156 wxWindow
*win
= node
->GetData();
1157 if ( win
->GetParent() )
1159 wxSysColourChangedEvent event2
;
1160 event
.m_eventObject
= win
;
1161 win
->GetEventHandler()->ProcessEvent(event2
);
1164 node
= node
->GetNext();
1168 void wxWindowX11::OnInternalIdle()
1170 // Update invalidated regions.
1173 // This calls the UI-update mechanism (querying windows for
1174 // menu/toolbar/control state information)
1177 // Set the input focus if couldn't do it before
1178 if (m_needsInputFocus
)
1184 // ----------------------------------------------------------------------------
1185 // function which maintain the global hash table mapping Widgets to wxWindows
1186 // ----------------------------------------------------------------------------
1188 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1190 wxWindow
*oldItem
= NULL
;
1191 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1193 wxLogDebug("Widget table clash: new widget is %ld, %s",
1194 (long)w
, win
->GetClassInfo()->GetClassName());
1198 wxWidgetHashTable
->Put((long) w
, win
);
1200 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1201 w
, win
, win
->GetClassInfo()->GetClassName());
1206 wxWindow
*wxGetWindowFromTable(Window w
)
1208 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1211 void wxDeleteWindowFromTable(Window w
)
1213 wxWidgetHashTable
->Delete((long)w
);
1216 // ----------------------------------------------------------------------------
1217 // function which maintain the global hash table mapping client widgets
1218 // ----------------------------------------------------------------------------
1220 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1222 wxWindow
*oldItem
= NULL
;
1223 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1225 wxLogDebug("Client window table clash: new window is %ld, %s",
1226 (long)w
, win
->GetClassInfo()->GetClassName());
1230 wxClientWidgetHashTable
->Put((long) w
, win
);
1232 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1233 w
, win
, win
->GetClassInfo()->GetClassName());
1238 wxWindow
*wxGetClientWindowFromTable(Window w
)
1240 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1243 void wxDeleteClientWindowFromTable(Window w
)
1245 wxClientWidgetHashTable
->Delete((long)w
);
1248 // ----------------------------------------------------------------------------
1249 // add/remove window from the table
1250 // ----------------------------------------------------------------------------
1252 // ----------------------------------------------------------------------------
1253 // X11-specific accessors
1254 // ----------------------------------------------------------------------------
1256 WXWindow
wxWindowX11::GetMainWindow() const
1258 return m_mainWindow
;
1261 WXWindow
wxWindowX11::GetClientWindow() const
1263 return m_clientWindow
;
1266 // ----------------------------------------------------------------------------
1267 // TranslateXXXEvent() functions
1268 // ----------------------------------------------------------------------------
1270 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1272 switch (XEventGetType(xevent
))
1280 wxEventType eventType
= wxEVT_NULL
;
1282 if (XEventGetType(xevent
) == EnterNotify
)
1284 //if (local_event.xcrossing.mode!=NotifyNormal)
1285 // return ; // Ignore grab events
1286 eventType
= wxEVT_ENTER_WINDOW
;
1287 // canvas->GetEventHandler()->OnSetFocus();
1289 else if (XEventGetType(xevent
) == LeaveNotify
)
1291 //if (local_event.xcrossingr.mode!=NotifyNormal)
1292 // return ; // Ignore grab events
1293 eventType
= wxEVT_LEAVE_WINDOW
;
1294 // canvas->GetEventHandler()->OnKillFocus();
1296 else if (XEventGetType(xevent
) == MotionNotify
)
1298 eventType
= wxEVT_MOTION
;
1300 else if (XEventGetType(xevent
) == ButtonPress
)
1302 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1304 if (XButtonEventLChanged(xevent
))
1306 eventType
= wxEVT_LEFT_DOWN
;
1309 else if (XButtonEventMChanged(xevent
))
1311 eventType
= wxEVT_MIDDLE_DOWN
;
1314 else if (XButtonEventRChanged(xevent
))
1316 eventType
= wxEVT_RIGHT_DOWN
;
1320 // check for a double click
1321 // TODO: where can we get this value from?
1322 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1323 long dclickTime
= 200;
1324 long ts
= wxevent
.GetTimestamp();
1326 int buttonLast
= win
->GetLastClickedButton();
1327 long lastTS
= win
->GetLastClickTime();
1328 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1331 win
->SetLastClick(0, ts
);
1332 if ( eventType
== wxEVT_LEFT_DOWN
)
1333 eventType
= wxEVT_LEFT_DCLICK
;
1334 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1335 eventType
= wxEVT_MIDDLE_DCLICK
;
1336 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1337 eventType
= wxEVT_RIGHT_DCLICK
;
1341 // not fast enough or different button
1342 win
->SetLastClick(button
, ts
);
1345 else if (XEventGetType(xevent
) == ButtonRelease
)
1347 if (XButtonEventLChanged(xevent
))
1349 eventType
= wxEVT_LEFT_UP
;
1351 else if (XButtonEventMChanged(xevent
))
1353 eventType
= wxEVT_MIDDLE_UP
;
1355 else if (XButtonEventRChanged(xevent
))
1357 eventType
= wxEVT_RIGHT_UP
;
1366 wxevent
.SetEventType(eventType
);
1368 wxevent
.m_x
= XButtonEventGetX(xevent
);
1369 wxevent
.m_y
= XButtonEventGetY(xevent
);
1371 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1372 || (XButtonEventLIsDown(xevent
)
1373 && (eventType
!= wxEVT_LEFT_UP
)));
1374 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1375 || (XButtonEventMIsDown(xevent
)
1376 && (eventType
!= wxEVT_MIDDLE_UP
)));
1377 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1378 || (XButtonEventRIsDown (xevent
)
1379 && (eventType
!= wxEVT_RIGHT_UP
)));
1381 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1382 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1383 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1384 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1386 wxevent
.SetId(win
->GetId());
1387 wxevent
.SetEventObject(win
);
1395 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1397 switch (XEventGetType(xevent
))
1405 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1406 int id
= wxCharCodeXToWX (keySym
);
1408 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1409 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1410 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1411 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1412 wxevent
.SetEventObject(win
);
1413 wxevent
.m_keyCode
= id
;
1414 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1416 wxevent
.m_x
= XKeyEventGetX(xevent
);
1417 wxevent
.m_y
= XKeyEventGetY(xevent
);
1431 // ----------------------------------------------------------------------------
1433 // ----------------------------------------------------------------------------
1435 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1437 wxWindowBase::SetBackgroundColour(col
);
1439 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1440 int xscreen
= DefaultScreen( xdisplay
);
1441 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1443 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1445 // We don't set the background colour as we paint
1446 // the background ourselves.
1447 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1452 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1454 if ( !wxWindowBase::SetForegroundColour(col
) )
1460 // ----------------------------------------------------------------------------
1462 // ----------------------------------------------------------------------------
1464 wxWindow
*wxGetActiveWindow()
1467 wxFAIL_MSG("Not implemented");
1472 wxWindow
*wxWindowBase::GetCapture()
1474 return (wxWindow
*)g_captureWindow
;
1478 // Find the wxWindow at the current mouse position, returning the mouse
1480 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1482 return wxFindWindowAtPoint(wxGetMousePosition());
1485 // Get the current mouse position.
1486 wxPoint
wxGetMousePosition()
1490 return wxPoint(0, 0);
1492 Display
*display
= wxGlobalDisplay();
1493 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1494 Window rootReturn
, childReturn
;
1495 int rootX
, rootY
, winX
, winY
;
1496 unsigned int maskReturn
;
1498 XQueryPointer (display
,
1502 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1503 return wxPoint(rootX
, rootY
);
1508 // ----------------------------------------------------------------------------
1509 // wxNoOptimize: switch off size optimization
1510 // ----------------------------------------------------------------------------
1512 int wxNoOptimize::ms_count
= 0;
1515 // ----------------------------------------------------------------------------
1517 // ----------------------------------------------------------------------------
1519 class wxWinModule
: public wxModule
1526 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1529 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1531 bool wxWinModule::OnInit()
1533 Display
*xdisplay
= wxGlobalDisplay();
1534 int xscreen
= DefaultScreen( xdisplay
);
1535 Window xroot
= RootWindow( xdisplay
, xscreen
);
1536 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1537 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1542 void wxWinModule::OnExit()
1544 Display
*xdisplay
= wxGlobalDisplay();
1545 XFreeGC( xdisplay
, g_eraseGC
);