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
);
384 win
= wxGetClientWindowFromTable( xfocus
);
393 // Enabling/disabling handled by event loop, and not sending events
395 bool wxWindowX11::Enable(bool enable
)
397 if ( !wxWindowBase::Enable(enable
) )
403 bool wxWindowX11::Show(bool show
)
405 wxWindowBase::Show(show
);
407 Window xwindow
= (Window
) m_mainWindow
;
408 Display
*xdisp
= wxGlobalDisplay();
411 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
412 XMapWindow(xdisp
, xwindow
);
416 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
417 XUnmapWindow(xdisp
, xwindow
);
423 // Raise the window to the top of the Z order
424 void wxWindowX11::Raise()
427 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
430 // Lower the window to the bottom of the Z order
431 void wxWindowX11::Lower()
434 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
437 void wxWindowX11::DoCaptureMouse()
439 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
441 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
452 Window xwindow
= (Window
) m_clientWindow
;
454 wxCHECK_RET( xwindow
, wxT("invalid window") );
456 g_captureWindow
= (wxWindow
*) this;
460 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
462 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
466 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
469 if (res
!= GrabSuccess
)
472 msg
.Printf("Failed to grab pointer for window %s", this->GetClassInfo()->GetClassName());
474 if (res
== GrabNotViewable
)
476 wxLogDebug("This is not a viewable window - perhaps not shown yet?");
478 g_captureWindow
= NULL
;
482 m_winCaptured
= TRUE
;
486 void wxWindowX11::DoReleaseMouse()
488 g_captureWindow
= NULL
;
490 if ( !m_winCaptured
)
493 Window xwindow
= (Window
) m_clientWindow
;
497 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
500 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
502 m_winCaptured
= FALSE
;
505 bool wxWindowX11::SetFont(const wxFont
& font
)
507 if ( !wxWindowBase::SetFont(font
) )
516 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
518 if ( !wxWindowBase::SetCursor(cursor
) )
524 Window xwindow
= (Window
) m_clientWindow
;
526 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
528 wxCursor cursorToUse
;
530 cursorToUse
= m_cursor
;
532 cursorToUse
= *wxSTANDARD_CURSOR
;
534 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
536 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
541 // Coordinates relative to the window
542 void wxWindowX11::WarpPointer (int x
, int y
)
544 Window xwindow
= (Window
) m_clientWindow
;
546 wxCHECK_RET( xwindow
, wxT("invalid window") );
548 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
551 // Does a physical scroll
552 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
554 // No scrolling requested.
555 if ((dx
== 0) && (dy
== 0)) return;
557 if (!m_updateRegion
.IsEmpty())
559 m_updateRegion
.Offset( dx
, dy
);
563 GetSize( &cw
, &ch
); // GetClientSize() ??
564 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
567 if (!m_clearRegion
.IsEmpty())
569 m_clearRegion
.Offset( dx
, dy
);
573 GetSize( &cw
, &ch
); // GetClientSize() ??
574 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
577 Window xwindow
= (Window
) GetClientWindow();
579 wxCHECK_RET( xwindow
, wxT("invalid window") );
581 Display
*xdisplay
= wxGlobalDisplay();
583 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
584 XSetGraphicsExposures( xdisplay
, xgc
, True
);
602 GetClientSize( &cw
, &ch
);
605 #if wxUSE_TWO_WINDOWS
606 wxPoint
offset( 0,0 );
608 wxPoint offset
= GetClientAreaOrigin();
613 int w
= cw
- abs(dx
);
614 int h
= ch
- abs(dy
);
616 if ((h
< 0) || (w
< 0))
623 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
624 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
625 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
626 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
631 if (dx
< 0) s_x
+= -dx
;
632 if (dy
< 0) s_y
+= -dy
;
633 if (dx
> 0) d_x
= dx
+ offset
.x
;
634 if (dy
> 0) d_y
= dy
+ offset
.y
;
636 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
638 // 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 );
640 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
642 m_updateRegion
.Union( rect
);
643 m_clearRegion
.Union( rect
);
646 XFreeGC( xdisplay
, xgc
);
649 // ---------------------------------------------------------------------------
651 // ---------------------------------------------------------------------------
653 #if wxUSE_DRAG_AND_DROP
655 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
662 // Old style file-manager drag&drop
663 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
668 // ----------------------------------------------------------------------------
670 // ----------------------------------------------------------------------------
674 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
679 #endif // wxUSE_TOOLTIPS
681 // ---------------------------------------------------------------------------
682 // moving and resizing
683 // ---------------------------------------------------------------------------
685 bool wxWindowX11::PreResize()
691 void wxWindowX11::DoGetSize(int *x
, int *y
) const
693 Window xwindow
= (Window
) m_mainWindow
;
695 wxCHECK_RET( xwindow
, wxT("invalid window") );
697 //XSync(wxGlobalDisplay(), False);
699 XWindowAttributes attr
;
700 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
705 *x
= attr
.width
/* + 2*m_borderSize */ ;
706 *y
= attr
.height
/* + 2*m_borderSize */ ;
710 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
712 Window window
= (Window
) m_mainWindow
;
715 //XSync(wxGlobalDisplay(), False);
716 XWindowAttributes attr
;
717 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
725 // We may be faking the client origin. So a window that's really at (0, 30)
726 // may appear (to wxWin apps) to be at (0, 0).
729 wxPoint
pt(GetParent()->GetClientAreaOrigin());
737 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
739 Display
*display
= wxGlobalDisplay();
740 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
741 Window thisWindow
= (Window
) m_clientWindow
;
746 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
749 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
751 Display
*display
= wxGlobalDisplay();
752 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
753 Window thisWindow
= (Window
) m_clientWindow
;
758 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
762 // Get size *available for subwindows* i.e. excluding menu bar etc.
763 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
765 Window window
= (Window
) m_mainWindow
;
769 XWindowAttributes attr
;
770 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
781 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
783 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
785 Window xwindow
= (Window
) m_mainWindow
;
787 wxCHECK_RET( xwindow
, wxT("invalid window") );
789 XWindowAttributes attr
;
790 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
791 wxCHECK_RET( status
, wxT("invalid window attributes") );
795 int new_w
= attr
.width
;
796 int new_h
= attr
.height
;
798 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
801 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
804 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
807 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
823 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
826 void wxWindowX11::DoSetClientSize(int width
, int height
)
828 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
830 Window xwindow
= (Window
) m_mainWindow
;
832 wxCHECK_RET( xwindow
, wxT("invalid window") );
834 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
836 if (m_mainWindow
!= m_clientWindow
)
838 xwindow
= (Window
) m_clientWindow
;
840 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
845 if (HasFlag( wxSIMPLE_BORDER
))
851 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
855 // For implementation purposes - sometimes decorations make the client area
857 wxPoint
wxWindowX11::GetClientAreaOrigin() const
859 return wxPoint(0, 0);
862 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
864 Window xwindow
= (Window
) m_mainWindow
;
866 wxCHECK_RET( xwindow
, wxT("invalid window") );
870 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
871 if (m_mainWindow
!= m_clientWindow
)
873 xwindow
= (Window
) m_clientWindow
;
875 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
882 if (HasFlag( wxSIMPLE_BORDER
))
894 wxWindow
*window
= (wxWindow
*) this;
895 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
896 if (sb
&& sb
->IsShown())
898 wxSize size
= sb
->GetSize();
901 sb
= window
->GetScrollbar( wxVERTICAL
);
902 if (sb
&& sb
->IsShown())
904 wxSize size
= sb
->GetSize();
908 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
913 XWindowChanges windowChanges
;
916 windowChanges
.width
= width
;
917 windowChanges
.height
= height
;
918 windowChanges
.stack_mode
= 0;
919 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
921 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
926 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
934 XSizeHints sizeHints
;
937 if (minW
> -1 && minH
> -1)
939 sizeHints
.flags
|= PMinSize
;
940 sizeHints
.min_width
= minW
;
941 sizeHints
.min_height
= minH
;
943 if (maxW
> -1 && maxH
> -1)
945 sizeHints
.flags
|= PMaxSize
;
946 sizeHints
.max_width
= maxW
;
947 sizeHints
.max_height
= maxH
;
949 if (incW
> -1 && incH
> -1)
951 sizeHints
.flags
|= PResizeInc
;
952 sizeHints
.width_inc
= incW
;
953 sizeHints
.height_inc
= incH
;
956 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
960 // ---------------------------------------------------------------------------
962 // ---------------------------------------------------------------------------
964 int wxWindowX11::GetCharHeight() const
966 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
968 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
970 int direction
, ascent
, descent
;
972 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
975 // return (overall.ascent + overall.descent);
976 return (ascent
+ descent
);
979 int wxWindowX11::GetCharWidth() const
981 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
983 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
985 int direction
, ascent
, descent
;
987 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
990 return overall
.width
;
993 void wxWindowX11::GetTextExtent(const wxString
& string
,
995 int *descent
, int *externalLeading
,
996 const wxFont
*theFont
) const
998 wxFont fontToUse
= m_font
;
999 if (theFont
) fontToUse
= *theFont
;
1001 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1003 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1005 int direction
, ascent
, descent2
;
1006 XCharStruct overall
;
1007 int slen
= string
.Len();
1011 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1012 &ascent
, &descent2
, &overall
);
1015 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1016 &direction
, &ascent
, &descent2
, &overall
);
1019 *x
= (overall
.width
);
1021 *y
= (ascent
+ descent2
);
1023 *descent
= descent2
;
1024 if (externalLeading
)
1025 *externalLeading
= 0;
1029 // ----------------------------------------------------------------------------
1031 // ----------------------------------------------------------------------------
1033 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1039 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1040 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1045 GetSize( &width
, &height
);
1047 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1048 m_clearRegion
.Clear();
1049 m_clearRegion
.Union( 0, 0, width
, height
);
1055 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1056 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1061 GetSize( &width
, &height
);
1063 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1064 m_updateRegion
.Clear();
1065 m_updateRegion
.Union( 0, 0, width
, height
);
1069 void wxWindowX11::Update()
1073 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1074 // Send nc paint events.
1075 SendNcPaintEvents();
1078 if (!m_updateRegion
.IsEmpty())
1080 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1081 // Actually send erase events.
1084 // Actually send paint events.
1089 void wxWindowX11::Clear()
1091 // wxClientDC dc((wxWindow*) this);
1092 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1093 // dc.SetBackground(brush);
1097 void wxWindowX11::SendEraseEvents()
1099 if (m_clearRegion
.IsEmpty()) return;
1101 wxClientDC
dc( (wxWindow
*)this );
1102 dc
.SetClippingRegion( m_clearRegion
);
1104 wxEraseEvent
erase_event( GetId(), &dc
);
1105 erase_event
.SetEventObject( this );
1107 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1109 Display
*xdisplay
= wxGlobalDisplay();
1110 Window xwindow
= (Window
) GetClientWindow();
1111 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1113 wxRegionIterator
upd( m_clearRegion
);
1116 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1117 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1122 m_clearRegion
.Clear();
1125 void wxWindowX11::SendPaintEvents()
1127 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1129 m_clipPaintRegion
= TRUE
;
1131 wxPaintEvent
paint_event( GetId() );
1132 paint_event
.SetEventObject( this );
1133 GetEventHandler()->ProcessEvent( paint_event
);
1135 m_updateRegion
.Clear();
1137 m_clipPaintRegion
= FALSE
;
1140 void wxWindowX11::SendNcPaintEvents()
1142 wxNcPaintEvent
nc_paint_event( GetId() );
1143 nc_paint_event
.SetEventObject( this );
1144 GetEventHandler()->ProcessEvent( nc_paint_event
);
1146 m_updateNcArea
= FALSE
;
1149 // ----------------------------------------------------------------------------
1151 // ----------------------------------------------------------------------------
1153 // Responds to colour changes: passes event on to children.
1154 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1156 wxWindowList::Node
*node
= GetChildren().GetFirst();
1159 // Only propagate to non-top-level windows
1160 wxWindow
*win
= node
->GetData();
1161 if ( win
->GetParent() )
1163 wxSysColourChangedEvent event2
;
1164 event
.m_eventObject
= win
;
1165 win
->GetEventHandler()->ProcessEvent(event2
);
1168 node
= node
->GetNext();
1172 void wxWindowX11::OnInternalIdle()
1174 // Update invalidated regions.
1177 // This calls the UI-update mechanism (querying windows for
1178 // menu/toolbar/control state information)
1181 // Set the input focus if couldn't do it before
1182 if (m_needsInputFocus
)
1188 // ----------------------------------------------------------------------------
1189 // function which maintain the global hash table mapping Widgets to wxWindows
1190 // ----------------------------------------------------------------------------
1192 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1194 wxWindow
*oldItem
= NULL
;
1195 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1197 wxLogDebug("Widget table clash: new widget is %ld, %s",
1198 (long)w
, win
->GetClassInfo()->GetClassName());
1202 wxWidgetHashTable
->Put((long) w
, win
);
1204 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1205 w
, win
, win
->GetClassInfo()->GetClassName());
1210 wxWindow
*wxGetWindowFromTable(Window w
)
1212 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1215 void wxDeleteWindowFromTable(Window w
)
1217 wxWidgetHashTable
->Delete((long)w
);
1220 // ----------------------------------------------------------------------------
1221 // function which maintain the global hash table mapping client widgets
1222 // ----------------------------------------------------------------------------
1224 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1226 wxWindow
*oldItem
= NULL
;
1227 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1229 wxLogDebug("Client window table clash: new window is %ld, %s",
1230 (long)w
, win
->GetClassInfo()->GetClassName());
1234 wxClientWidgetHashTable
->Put((long) w
, win
);
1236 wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
1237 w
, win
, win
->GetClassInfo()->GetClassName());
1242 wxWindow
*wxGetClientWindowFromTable(Window w
)
1244 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1247 void wxDeleteClientWindowFromTable(Window w
)
1249 wxClientWidgetHashTable
->Delete((long)w
);
1252 // ----------------------------------------------------------------------------
1253 // add/remove window from the table
1254 // ----------------------------------------------------------------------------
1256 // ----------------------------------------------------------------------------
1257 // X11-specific accessors
1258 // ----------------------------------------------------------------------------
1260 WXWindow
wxWindowX11::GetMainWindow() const
1262 return m_mainWindow
;
1265 WXWindow
wxWindowX11::GetClientWindow() const
1267 return m_clientWindow
;
1270 // ----------------------------------------------------------------------------
1271 // TranslateXXXEvent() functions
1272 // ----------------------------------------------------------------------------
1274 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1276 switch (XEventGetType(xevent
))
1284 wxEventType eventType
= wxEVT_NULL
;
1286 if (XEventGetType(xevent
) == EnterNotify
)
1288 //if (local_event.xcrossing.mode!=NotifyNormal)
1289 // return ; // Ignore grab events
1290 eventType
= wxEVT_ENTER_WINDOW
;
1291 // canvas->GetEventHandler()->OnSetFocus();
1293 else if (XEventGetType(xevent
) == LeaveNotify
)
1295 //if (local_event.xcrossingr.mode!=NotifyNormal)
1296 // return ; // Ignore grab events
1297 eventType
= wxEVT_LEAVE_WINDOW
;
1298 // canvas->GetEventHandler()->OnKillFocus();
1300 else if (XEventGetType(xevent
) == MotionNotify
)
1302 eventType
= wxEVT_MOTION
;
1304 else if (XEventGetType(xevent
) == ButtonPress
)
1306 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1308 if (XButtonEventLChanged(xevent
))
1310 eventType
= wxEVT_LEFT_DOWN
;
1313 else if (XButtonEventMChanged(xevent
))
1315 eventType
= wxEVT_MIDDLE_DOWN
;
1318 else if (XButtonEventRChanged(xevent
))
1320 eventType
= wxEVT_RIGHT_DOWN
;
1324 // check for a double click
1325 // TODO: where can we get this value from?
1326 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1327 long dclickTime
= 200;
1328 long ts
= wxevent
.GetTimestamp();
1330 int buttonLast
= win
->GetLastClickedButton();
1331 long lastTS
= win
->GetLastClickTime();
1332 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1335 win
->SetLastClick(0, ts
);
1336 if ( eventType
== wxEVT_LEFT_DOWN
)
1337 eventType
= wxEVT_LEFT_DCLICK
;
1338 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1339 eventType
= wxEVT_MIDDLE_DCLICK
;
1340 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1341 eventType
= wxEVT_RIGHT_DCLICK
;
1345 // not fast enough or different button
1346 win
->SetLastClick(button
, ts
);
1349 else if (XEventGetType(xevent
) == ButtonRelease
)
1351 if (XButtonEventLChanged(xevent
))
1353 eventType
= wxEVT_LEFT_UP
;
1355 else if (XButtonEventMChanged(xevent
))
1357 eventType
= wxEVT_MIDDLE_UP
;
1359 else if (XButtonEventRChanged(xevent
))
1361 eventType
= wxEVT_RIGHT_UP
;
1370 wxevent
.SetEventType(eventType
);
1372 wxevent
.m_x
= XButtonEventGetX(xevent
);
1373 wxevent
.m_y
= XButtonEventGetY(xevent
);
1375 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1376 || (XButtonEventLIsDown(xevent
)
1377 && (eventType
!= wxEVT_LEFT_UP
)));
1378 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1379 || (XButtonEventMIsDown(xevent
)
1380 && (eventType
!= wxEVT_MIDDLE_UP
)));
1381 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1382 || (XButtonEventRIsDown (xevent
)
1383 && (eventType
!= wxEVT_RIGHT_UP
)));
1385 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1386 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1387 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1388 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1390 wxevent
.SetId(win
->GetId());
1391 wxevent
.SetEventObject(win
);
1399 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
)
1401 switch (XEventGetType(xevent
))
1409 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1410 int id
= wxCharCodeXToWX (keySym
);
1412 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1413 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1414 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1415 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1416 wxevent
.SetEventObject(win
);
1417 wxevent
.m_keyCode
= id
;
1418 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1420 wxevent
.m_x
= XKeyEventGetX(xevent
);
1421 wxevent
.m_y
= XKeyEventGetY(xevent
);
1435 // ----------------------------------------------------------------------------
1437 // ----------------------------------------------------------------------------
1439 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1441 wxWindowBase::SetBackgroundColour(col
);
1443 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1444 int xscreen
= DefaultScreen( xdisplay
);
1445 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1447 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1449 // We don't set the background colour as we paint
1450 // the background ourselves.
1451 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1456 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1458 if ( !wxWindowBase::SetForegroundColour(col
) )
1464 // ----------------------------------------------------------------------------
1466 // ----------------------------------------------------------------------------
1468 wxWindow
*wxGetActiveWindow()
1471 wxFAIL_MSG("Not implemented");
1476 wxWindow
*wxWindowBase::GetCapture()
1478 return (wxWindow
*)g_captureWindow
;
1482 // Find the wxWindow at the current mouse position, returning the mouse
1484 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1486 return wxFindWindowAtPoint(wxGetMousePosition());
1489 // Get the current mouse position.
1490 wxPoint
wxGetMousePosition()
1494 return wxPoint(0, 0);
1496 Display
*display
= wxGlobalDisplay();
1497 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1498 Window rootReturn
, childReturn
;
1499 int rootX
, rootY
, winX
, winY
;
1500 unsigned int maskReturn
;
1502 XQueryPointer (display
,
1506 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1507 return wxPoint(rootX
, rootY
);
1512 // ----------------------------------------------------------------------------
1513 // wxNoOptimize: switch off size optimization
1514 // ----------------------------------------------------------------------------
1516 int wxNoOptimize::ms_count
= 0;
1519 // ----------------------------------------------------------------------------
1521 // ----------------------------------------------------------------------------
1523 class wxWinModule
: public wxModule
1530 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1533 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1535 bool wxWinModule::OnInit()
1537 Display
*xdisplay
= wxGlobalDisplay();
1538 int xscreen
= DefaultScreen( xdisplay
);
1539 Window xroot
= RootWindow( xdisplay
, xscreen
);
1540 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1541 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1546 void wxWinModule::OnExit()
1548 Display
*xdisplay
= wxGlobalDisplay();
1549 XFreeGC( xdisplay
, g_eraseGC
);