1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
27 #include "wx/dcclient.h"
31 #include "wx/layout.h"
32 #include "wx/dialog.h"
33 #include "wx/listbox.h"
34 #include "wx/button.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
38 #include "wx/scrolwin.h"
39 #include "wx/scrolbar.h"
40 #include "wx/module.h"
41 #include "wx/menuitem.h"
43 #include "wx/fontutil.h"
44 #include "wx/univ/renderer.h"
47 #if wxUSE_DRAG_AND_DROP
51 #include "wx/x11/private.h"
52 #include "X11/Xutil.h"
55 // For wxGetLocalTime, used by XButtonEventGetTime
61 // ----------------------------------------------------------------------------
62 // global variables for this module
63 // ----------------------------------------------------------------------------
65 extern wxHashTable
*wxWidgetHashTable
;
66 extern wxHashTable
*wxClientWidgetHashTable
;
67 static wxWindow
* g_captureWindow
= NULL
;
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
75 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
76 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 IMPLEMENT_ABSTRACT_CLASS(wxWindowX11
, wxWindowBase
)
84 BEGIN_EVENT_TABLE(wxWindowX11
, wxWindowBase
)
85 EVT_SYS_COLOUR_CHANGED(wxWindowX11::OnSysColourChanged
)
88 // ============================================================================
90 // ============================================================================
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 void wxWindowX11::Init()
102 // generic initializations first
106 m_mainWindow
= (WXWindow
) 0;
107 m_clientWindow
= (WXWindow
) 0;
108 m_insertIntoMain
= FALSE
;
109 m_updateNcArea
= FALSE
;
111 m_winCaptured
= FALSE
;
112 m_needsInputFocus
= FALSE
;
114 m_isBeingDeleted
= FALSE
;
119 // real construction (Init() must have been called before!)
120 bool wxWindowX11::Create(wxWindow
*parent
, wxWindowID id
,
124 const wxString
& name
)
126 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
128 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
130 parent
->AddChild(this);
132 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
133 int xscreen
= DefaultScreen( xdisplay
);
134 Visual
*xvisual
= DefaultVisual( xdisplay
, xscreen
);
135 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
137 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
138 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
140 m_foregroundColour
= *wxBLACK
;
141 m_foregroundColour
.CalcPixel( (WXColormap
) cm
);
143 Window xparent
= (Window
) parent
->GetClientAreaWindow();
145 // Add window's own scrollbars to main window, not to client window
146 if (parent
->GetInsertIntoMain())
148 // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
149 xparent
= (Window
) parent
->GetMainWindow();
152 // Size (not including the border) must be nonzero (or a Value error results)!
153 // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
166 #if wxUSE_TWO_WINDOWS
167 bool need_two_windows
=
168 ((( wxSUNKEN_BORDER
| wxRAISED_BORDER
| wxSIMPLE_BORDER
| wxHSCROLL
| wxVSCROLL
) & m_windowStyle
) != 0);
170 bool need_two_windows
= FALSE
;
174 long xattributes
= 0;
176 XSetWindowAttributes xattributes
;
177 long xattributes_mask
= 0;
179 xattributes_mask
|= CWBackPixel
;
180 xattributes
.background_pixel
= m_backgroundColour
.GetPixel();
182 xattributes_mask
|= CWBorderPixel
;
183 xattributes
.border_pixel
= BlackPixel( xdisplay
, xscreen
);
185 xattributes_mask
|= CWEventMask
;
188 if (need_two_windows
)
191 long backColor
, foreColor
;
192 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
193 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
195 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
196 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
197 XSelectInput( xdisplay
, xwindow
,
198 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
199 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
200 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
201 PropertyChangeMask
);
205 xattributes
.event_mask
=
206 ExposureMask
| StructureNotifyMask
| ColormapChangeMask
;
208 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
209 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
213 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
215 m_mainWindow
= (WXWindow
) xwindow
;
216 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
218 XMapWindow( xdisplay
, xwindow
);
221 xattributes
.event_mask
=
222 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
223 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
224 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
225 PropertyChangeMask
| VisibilityChangeMask
;
227 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
229 xattributes_mask
|= CWBitGravity
;
230 xattributes
.bit_gravity
= StaticGravity
;
234 if (HasFlag( wxSUNKEN_BORDER
) || HasFlag( wxRAISED_BORDER
))
241 else if (HasFlag( wxSIMPLE_BORDER
))
254 // Make again sure the size is nonzero.
261 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
262 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
264 xwindow
= XCreateWindowWithColor( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
265 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
266 XSelectInput( xdisplay
, xwindow
,
267 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
268 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
269 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
270 PropertyChangeMask
);
273 xwindow
= XCreateWindow( xdisplay
, xwindow
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
274 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
277 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
279 m_clientWindow
= (WXWindow
) xwindow
;
280 wxAddClientWindowToTable( xwindow
, (wxWindow
*) this );
282 XMapWindow( xdisplay
, xwindow
);
286 // wxLogDebug( "No two windows needed %s", GetName().c_str() );
288 long backColor
, foreColor
;
289 backColor
= GR_RGB(m_backgroundColour
.Red(), m_backgroundColour
.Green(), m_backgroundColour
.Blue());
290 foreColor
= GR_RGB(m_foregroundColour
.Red(), m_foregroundColour
.Green(), m_foregroundColour
.Blue());
292 Window xwindow
= XCreateWindowWithColor( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
293 0, 0, InputOutput
, xvisual
, backColor
, foreColor
);
294 XSelectInput( xdisplay
, xwindow
,
295 GR_EVENT_MASK_CLOSE_REQ
| ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
296 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
297 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
298 PropertyChangeMask
);
301 xattributes
.event_mask
=
302 ExposureMask
| KeyPressMask
| KeyReleaseMask
| ButtonPressMask
| ButtonReleaseMask
|
303 ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
|
304 KeymapStateMask
| FocusChangeMask
| ColormapChangeMask
| StructureNotifyMask
|
305 PropertyChangeMask
| VisibilityChangeMask
;
307 if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE
))
309 xattributes_mask
|= CWBitGravity
;
310 xattributes
.bit_gravity
= NorthWestGravity
;
313 Window xwindow
= XCreateWindow( xdisplay
, xparent
, pos2
.x
, pos2
.y
, size2
.x
, size2
.y
,
314 0, DefaultDepth(xdisplay
,xscreen
), InputOutput
, xvisual
, xattributes_mask
, &xattributes
);
317 XSetWindowBackgroundPixmap( xdisplay
, xwindow
, None
);
319 m_mainWindow
= (WXWindow
) xwindow
;
320 m_clientWindow
= m_mainWindow
;
321 wxAddWindowToTable( xwindow
, (wxWindow
*) this );
323 XMapWindow( xdisplay
, xwindow
);
326 // Is a subwindow, so map immediately
329 // Without this, the cursor may not be restored properly (e.g. in splitter
331 SetCursor(*wxSTANDARD_CURSOR
);
332 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
334 // Don't call this, it can have nasty repercussions for composite controls,
336 // SetSize(pos.x, pos.y, size.x, size.y);
342 wxWindowX11::~wxWindowX11()
346 if (g_captureWindow
== this)
347 g_captureWindow
= NULL
;
349 m_isBeingDeleted
= TRUE
;
352 m_parent
->RemoveChild( this );
356 if (m_clientWindow
!= m_mainWindow
)
358 // Destroy the cleint window
359 Window xwindow
= (Window
) m_clientWindow
;
360 wxDeleteClientWindowFromTable( xwindow
);
361 XDestroyWindow( wxGlobalDisplay(), xwindow
);
362 m_clientWindow
= NULL
;
365 // Destroy the window
366 Window xwindow
= (Window
) m_mainWindow
;
367 wxDeleteWindowFromTable( xwindow
);
368 XDestroyWindow( wxGlobalDisplay(), xwindow
);
372 // ---------------------------------------------------------------------------
374 // ---------------------------------------------------------------------------
376 void wxWindowX11::SetFocus()
378 Window xwindow
= (Window
) m_clientWindow
;
380 wxCHECK_RET( xwindow
, wxT("invalid window") );
382 wxCHECK_RET( AcceptsFocus(), wxT("set focus on window that doesn't accept the focus") );
385 if (GetName() == "scrollBar")
392 if (wxWindowIsVisible(xwindow
))
394 wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
395 // XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
396 XSetInputFocus( wxGlobalDisplay(), xwindow
, RevertToNone
, CurrentTime
);
397 m_needsInputFocus
= FALSE
;
401 m_needsInputFocus
= TRUE
;
405 // Get the window with the focus
406 wxWindow
*wxWindowBase::FindFocus()
408 Window xfocus
= (Window
) 0;
411 XGetInputFocus( wxGlobalDisplay(), &xfocus
, &revert
);
414 wxWindow
*win
= wxGetWindowFromTable( xfocus
);
417 win
= wxGetClientWindowFromTable( xfocus
);
426 // Enabling/disabling handled by event loop, and not sending events
428 bool wxWindowX11::Enable(bool enable
)
430 if ( !wxWindowBase::Enable(enable
) )
436 bool wxWindowX11::Show(bool show
)
438 wxWindowBase::Show(show
);
440 Window xwindow
= (Window
) m_mainWindow
;
441 Display
*xdisp
= wxGlobalDisplay();
444 // wxLogDebug( "Mapping window of type %s", GetName().c_str() );
445 XMapWindow(xdisp
, xwindow
);
449 // wxLogDebug( "Unmapping window of type %s", GetName().c_str() );
450 XUnmapWindow(xdisp
, xwindow
);
456 // Raise the window to the top of the Z order
457 void wxWindowX11::Raise()
460 XRaiseWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
463 // Lower the window to the bottom of the Z order
464 void wxWindowX11::Lower()
467 XLowerWindow( wxGlobalDisplay(), (Window
) m_mainWindow
);
470 void wxWindowX11::DoCaptureMouse()
472 if ((g_captureWindow
!= NULL
) && (g_captureWindow
!= this))
474 wxASSERT_MSG(FALSE
, "Trying to capture before mouse released.");
485 Window xwindow
= (Window
) m_clientWindow
;
487 wxCHECK_RET( xwindow
, wxT("invalid window") );
489 g_captureWindow
= (wxWindow
*) this;
493 int res
= XGrabPointer(wxGlobalDisplay(), xwindow
,
495 ButtonPressMask
| ButtonReleaseMask
| ButtonMotionMask
| EnterWindowMask
| LeaveWindowMask
| PointerMotionMask
,
499 None
, /* cursor */ // TODO: This may need to be set to the cursor of this window
502 if (res
!= GrabSuccess
)
505 msg
.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
507 if (res
== GrabNotViewable
)
508 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
510 g_captureWindow
= NULL
;
514 m_winCaptured
= TRUE
;
518 void wxWindowX11::DoReleaseMouse()
520 g_captureWindow
= NULL
;
522 if ( !m_winCaptured
)
525 Window xwindow
= (Window
) m_clientWindow
;
529 XUngrabPointer( wxGlobalDisplay(), CurrentTime
);
532 // wxLogDebug( "Ungrabbed pointer in %s", GetName().c_str() );
534 m_winCaptured
= FALSE
;
537 bool wxWindowX11::SetFont(const wxFont
& font
)
539 if ( !wxWindowBase::SetFont(font
) )
548 bool wxWindowX11::SetCursor(const wxCursor
& cursor
)
550 if ( !wxWindowBase::SetCursor(cursor
) )
556 Window xwindow
= (Window
) m_clientWindow
;
558 wxCHECK_MSG( xwindow
, FALSE
, wxT("invalid window") );
560 wxCursor cursorToUse
;
562 cursorToUse
= m_cursor
;
564 cursorToUse
= *wxSTANDARD_CURSOR
;
566 Cursor xcursor
= (Cursor
) cursorToUse
.GetCursor();
568 XDefineCursor( wxGlobalDisplay(), xwindow
, xcursor
);
573 // Coordinates relative to the window
574 void wxWindowX11::WarpPointer (int x
, int y
)
576 Window xwindow
= (Window
) m_clientWindow
;
578 wxCHECK_RET( xwindow
, wxT("invalid window") );
580 XWarpPointer( wxGlobalDisplay(), None
, xwindow
, 0, 0, 0, 0, x
, y
);
583 // Does a physical scroll
584 void wxWindowX11::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
586 // No scrolling requested.
587 if ((dx
== 0) && (dy
== 0)) return;
589 if (!m_updateRegion
.IsEmpty())
591 m_updateRegion
.Offset( dx
, dy
);
595 GetSize( &cw
, &ch
); // GetClientSize() ??
596 m_updateRegion
.Intersect( 0, 0, cw
, ch
);
599 if (!m_clearRegion
.IsEmpty())
601 m_clearRegion
.Offset( dx
, dy
);
605 GetSize( &cw
, &ch
); // GetClientSize() ??
606 m_clearRegion
.Intersect( 0, 0, cw
, ch
);
609 Window xwindow
= (Window
) GetClientAreaWindow();
611 wxCHECK_RET( xwindow
, wxT("invalid window") );
613 Display
*xdisplay
= wxGlobalDisplay();
615 GC xgc
= XCreateGC( xdisplay
, xwindow
, 0, NULL
);
616 XSetGraphicsExposures( xdisplay
, xgc
, True
);
634 GetClientSize( &cw
, &ch
);
637 #if wxUSE_TWO_WINDOWS
638 wxPoint
offset( 0,0 );
640 wxPoint offset
= GetClientAreaOrigin();
645 int w
= cw
- abs(dx
);
646 int h
= ch
- abs(dy
);
648 if ((h
< 0) || (w
< 0))
655 if (dx
< 0) rect
.x
= cw
+dx
+ offset
.x
; else rect
.x
= s_x
;
656 if (dy
< 0) rect
.y
= ch
+dy
+ offset
.y
; else rect
.y
= s_y
;
657 if (dy
!= 0) rect
.width
= cw
; else rect
.width
= abs(dx
);
658 if (dx
!= 0) rect
.height
= ch
; else rect
.height
= abs(dy
);
663 if (dx
< 0) s_x
+= -dx
;
664 if (dy
< 0) s_y
+= -dy
;
665 if (dx
> 0) d_x
= dx
+ offset
.x
;
666 if (dy
> 0) d_y
= dy
+ offset
.y
;
668 XCopyArea( xdisplay
, xwindow
, xwindow
, xgc
, s_x
, s_y
, w
, h
, d_x
, d_y
);
670 // 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 );
672 // wxLogDebug( "Update: %d %d %d %d", rect.x, rect.y, rect.width, rect.height );
674 m_updateRegion
.Union( rect
);
675 m_clearRegion
.Union( rect
);
678 XFreeGC( xdisplay
, xgc
);
681 // ---------------------------------------------------------------------------
683 // ---------------------------------------------------------------------------
685 #if wxUSE_DRAG_AND_DROP
687 void wxWindowX11::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
694 // Old style file-manager drag&drop
695 void wxWindowX11::DragAcceptFiles(bool WXUNUSED(accept
))
700 // ----------------------------------------------------------------------------
702 // ----------------------------------------------------------------------------
706 void wxWindowX11::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
711 #endif // wxUSE_TOOLTIPS
713 // ---------------------------------------------------------------------------
714 // moving and resizing
715 // ---------------------------------------------------------------------------
717 bool wxWindowX11::PreResize()
723 void wxWindowX11::DoGetSize(int *x
, int *y
) const
725 Window xwindow
= (Window
) m_mainWindow
;
727 wxCHECK_RET( xwindow
, wxT("invalid window") );
729 //XSync(wxGlobalDisplay(), False);
731 XWindowAttributes attr
;
732 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
737 *x
= attr
.width
/* + 2*m_borderSize */ ;
738 *y
= attr
.height
/* + 2*m_borderSize */ ;
742 void wxWindowX11::DoGetPosition(int *x
, int *y
) const
744 Window window
= (Window
) m_mainWindow
;
747 //XSync(wxGlobalDisplay(), False);
748 XWindowAttributes attr
;
749 Status status
= XGetWindowAttributes(wxGlobalDisplay(), window
, & attr
);
757 // We may be faking the client origin. So a window that's really at (0, 30)
758 // may appear (to wxWin apps) to be at (0, 0).
761 wxPoint
pt(GetParent()->GetClientAreaOrigin());
769 void wxWindowX11::DoScreenToClient(int *x
, int *y
) const
771 Display
*display
= wxGlobalDisplay();
772 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
773 Window thisWindow
= (Window
) m_clientWindow
;
778 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
781 void wxWindowX11::DoClientToScreen(int *x
, int *y
) const
783 Display
*display
= wxGlobalDisplay();
784 Window rootWindow
= RootWindowOfScreen(DefaultScreenOfDisplay(display
));
785 Window thisWindow
= (Window
) m_clientWindow
;
790 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
794 // Get size *available for subwindows* i.e. excluding menu bar etc.
795 void wxWindowX11::DoGetClientSize(int *x
, int *y
) const
797 Window window
= (Window
) m_mainWindow
;
801 XWindowAttributes attr
;
802 Status status
= XGetWindowAttributes( wxGlobalDisplay(), window
, &attr
);
813 void wxWindowX11::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
815 // wxLogDebug("DoSetSize: %s (%ld) %d, %d %dx%d", GetClassInfo()->GetClassName(), GetId(), x, y, width, height);
817 Window xwindow
= (Window
) m_mainWindow
;
819 wxCHECK_RET( xwindow
, wxT("invalid window") );
821 XWindowAttributes attr
;
822 Status status
= XGetWindowAttributes( wxGlobalDisplay(), xwindow
, &attr
);
823 wxCHECK_RET( status
, wxT("invalid window attributes") );
827 int new_w
= attr
.width
;
828 int new_h
= attr
.height
;
830 if (x
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
833 AdjustForParentClientOrigin( x
, yy
, sizeFlags
);
836 if (y
!= -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
839 AdjustForParentClientOrigin( xx
, y
, sizeFlags
);
855 DoMoveWindow( new_x
, new_y
, new_w
, new_h
);
858 void wxWindowX11::DoSetClientSize(int width
, int height
)
860 // wxLogDebug("DoSetClientSize: %s (%ld) %dx%d", GetClassInfo()->GetClassName(), GetId(), width, height);
862 Window xwindow
= (Window
) m_mainWindow
;
864 wxCHECK_RET( xwindow
, wxT("invalid window") );
866 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
868 if (m_mainWindow
!= m_clientWindow
)
870 xwindow
= (Window
) m_clientWindow
;
872 wxWindow
*window
= (wxWindow
*) this;
873 wxRenderer
*renderer
= window
->GetRenderer();
876 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
877 width
-= border
.x
+ border
.width
;
878 height
-= border
.y
+ border
.height
;
881 XResizeWindow( wxGlobalDisplay(), xwindow
, width
, height
);
885 // For implementation purposes - sometimes decorations make the client area
887 wxPoint
wxWindowX11::GetClientAreaOrigin() const
889 return wxPoint(0, 0);
892 void wxWindowX11::DoMoveWindow(int x
, int y
, int width
, int height
)
894 Window xwindow
= (Window
) m_mainWindow
;
896 wxCHECK_RET( xwindow
, wxT("invalid window") );
900 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, width
, height
);
901 if (m_mainWindow
!= m_clientWindow
)
903 xwindow
= (Window
) m_clientWindow
;
905 wxWindow
*window
= (wxWindow
*) this;
906 wxRenderer
*renderer
= window
->GetRenderer();
909 wxRect border
= renderer
->GetBorderDimensions( (wxBorder
)(m_windowStyle
& wxBORDER_MASK
) );
912 width
-= border
.x
+ border
.width
;
913 height
-= border
.y
+ border
.height
;
921 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
922 if (sb
&& sb
->IsShown())
924 wxSize size
= sb
->GetSize();
927 sb
= window
->GetScrollbar( wxVERTICAL
);
928 if (sb
&& sb
->IsShown())
930 wxSize size
= sb
->GetSize();
934 XMoveResizeWindow( wxGlobalDisplay(), xwindow
, x
, y
, wxMax(1, width
), wxMax(1, height
) );
939 XWindowChanges windowChanges
;
942 windowChanges
.width
= width
;
943 windowChanges
.height
= height
;
944 windowChanges
.stack_mode
= 0;
945 int valueMask
= CWX
| CWY
| CWWidth
| CWHeight
;
947 XConfigureWindow( wxGlobalDisplay(), xwindow
, valueMask
, &windowChanges
);
952 void wxWindowX11::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
960 XSizeHints sizeHints
;
963 if (minW
> -1 && minH
> -1)
965 sizeHints
.flags
|= PMinSize
;
966 sizeHints
.min_width
= minW
;
967 sizeHints
.min_height
= minH
;
969 if (maxW
> -1 && maxH
> -1)
971 sizeHints
.flags
|= PMaxSize
;
972 sizeHints
.max_width
= maxW
;
973 sizeHints
.max_height
= maxH
;
975 if (incW
> -1 && incH
> -1)
977 sizeHints
.flags
|= PResizeInc
;
978 sizeHints
.width_inc
= incW
;
979 sizeHints
.height_inc
= incH
;
982 XSetWMNormalHints(wxGlobalDisplay(), (Window
) m_mainWindow
, &sizeHints
);
986 // ---------------------------------------------------------------------------
988 // ---------------------------------------------------------------------------
990 int wxWindowX11::GetCharHeight() const
992 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
995 // There should be an easier way.
996 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
997 pango_layout_set_font_description( layout
, GetFont().GetNativeFontInfo()->description
);
998 pango_layout_set_text(layout
, "H", 1 );
1000 pango_layout_get_pixel_size(layout
, &w
, &h
);
1001 g_object_unref( G_OBJECT( layout
) );
1005 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1007 int direction
, ascent
, descent
;
1008 XCharStruct overall
;
1009 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1010 &descent
, &overall
);
1012 // return (overall.ascent + overall.descent);
1013 return (ascent
+ descent
);
1017 int wxWindowX11::GetCharWidth() const
1019 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1022 // There should be an easier way.
1023 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1024 pango_layout_set_font_description( layout
, GetFont().GetNativeFontInfo()->description
);
1025 pango_layout_set_text(layout
, "H", 1 );
1027 pango_layout_get_pixel_size(layout
, &w
, &h
);
1028 g_object_unref( G_OBJECT( layout
) );
1032 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, wxGlobalDisplay());
1034 int direction
, ascent
, descent
;
1035 XCharStruct overall
;
1036 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1037 &descent
, &overall
);
1039 return overall
.width
;
1043 void wxWindowX11::GetTextExtent(const wxString
& string
,
1045 int *descent
, int *externalLeading
,
1046 const wxFont
*theFont
) const
1048 wxFont fontToUse
= m_font
;
1049 if (theFont
) fontToUse
= *theFont
;
1051 wxCHECK_RET( fontToUse
.Ok(), wxT("invalid font") );
1053 if (string
.IsEmpty())
1061 PangoLayout
*layout
= pango_layout_new( wxTheApp
->GetPangoContext() );
1063 PangoFontDescription
*desc
= fontToUse
.GetNativeFontInfo()->description
;
1064 pango_layout_set_font_description(layout
, desc
);
1066 const wxCharBuffer data
= wxConvUTF8
.cWC2MB( string
);
1067 pango_layout_set_text(layout
, (const char*) data
, strlen( (const char*) data
));
1069 PangoLayoutLine
*line
= (PangoLayoutLine
*)pango_layout_get_lines(layout
)->data
;
1072 PangoRectangle rect
;
1073 pango_layout_line_get_extents(line
, NULL
, &rect
);
1075 if (x
) (*x
) = (wxCoord
) (rect
.width
/ PANGO_SCALE
);
1076 if (y
) (*y
) = (wxCoord
) (rect
.height
/ PANGO_SCALE
);
1079 // Do something about metrics here
1082 if (externalLeading
) (*externalLeading
) = 0; // ??
1084 g_object_unref( G_OBJECT( layout
) );
1086 WXFontStructPtr pFontStruct
= fontToUse
.GetFontStruct(1.0, wxGlobalDisplay());
1088 int direction
, ascent
, descent2
;
1089 XCharStruct overall
;
1090 int slen
= string
.Len();
1092 XTextExtents((XFontStruct
*) pFontStruct
, (char*) string
.c_str(), slen
,
1093 &direction
, &ascent
, &descent2
, &overall
);
1096 *x
= (overall
.width
);
1098 *y
= (ascent
+ descent2
);
1100 *descent
= descent2
;
1101 if (externalLeading
)
1102 *externalLeading
= 0;
1106 // ----------------------------------------------------------------------------
1108 // ----------------------------------------------------------------------------
1110 void wxWindowX11::Refresh(bool eraseBack
, const wxRect
*rect
)
1116 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1117 m_clearRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1122 GetSize( &width
, &height
);
1124 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1125 m_clearRegion
.Clear();
1126 m_clearRegion
.Union( 0, 0, width
, height
);
1132 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1133 m_updateRegion
.Union( rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1138 GetSize( &width
, &height
);
1140 // Schedule for later Updating in ::Update() or ::OnInternalIdle().
1141 m_updateRegion
.Clear();
1142 m_updateRegion
.Union( 0, 0, width
, height
);
1146 void wxWindowX11::Update()
1150 // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
1151 // Send nc paint events.
1152 SendNcPaintEvents();
1155 if (!m_updateRegion
.IsEmpty())
1157 // wxLogDebug("wxWindowX11::Update: %s", GetClassInfo()->GetClassName());
1158 // Actually send erase events.
1161 // Actually send paint events.
1166 void wxWindowX11::Clear()
1168 // wxClientDC dc((wxWindow*) this);
1169 // wxBrush brush(GetBackgroundColour(), wxSOLID);
1170 // dc.SetBackground(brush);
1174 void wxWindowX11::SendEraseEvents()
1176 if (m_clearRegion
.IsEmpty()) return;
1178 wxClientDC
dc( (wxWindow
*)this );
1179 dc
.SetClippingRegion( m_clearRegion
);
1181 wxEraseEvent
erase_event( GetId(), &dc
);
1182 erase_event
.SetEventObject( this );
1184 if (!GetEventHandler()->ProcessEvent(erase_event
) )
1186 Display
*xdisplay
= wxGlobalDisplay();
1187 Window xwindow
= (Window
) GetClientAreaWindow();
1188 XSetForeground( xdisplay
, g_eraseGC
, m_backgroundColour
.GetPixel() );
1190 wxRegionIterator
upd( m_clearRegion
);
1193 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
,
1194 upd
.GetX(), upd
.GetY(), upd
.GetWidth(), upd
.GetHeight() );
1199 m_clearRegion
.Clear();
1202 void wxWindowX11::SendPaintEvents()
1204 // wxLogDebug("SendPaintEvents: %s (%ld)", GetClassInfo()->GetClassName(), GetId());
1206 m_clipPaintRegion
= TRUE
;
1208 wxPaintEvent
paint_event( GetId() );
1209 paint_event
.SetEventObject( this );
1210 GetEventHandler()->ProcessEvent( paint_event
);
1212 m_updateRegion
.Clear();
1214 m_clipPaintRegion
= FALSE
;
1217 void wxWindowX11::SendNcPaintEvents()
1219 wxWindow
*window
= (wxWindow
*) this;
1221 // All this for drawing the small square between the scrollbars.
1226 wxScrollBar
*sb
= window
->GetScrollbar( wxHORIZONTAL
);
1227 if (sb
&& sb
->IsShown())
1229 height
= sb
->GetSize().y
;
1230 y
= sb
->GetPosition().y
;
1232 sb
= window
->GetScrollbar( wxVERTICAL
);
1233 if (sb
&& sb
->IsShown())
1235 width
= sb
->GetSize().x
;
1236 x
= sb
->GetPosition().x
;
1238 Display
*xdisplay
= wxGlobalDisplay();
1239 Window xwindow
= (Window
) GetMainWindow();
1240 Colormap cm
= (Colormap
) wxTheApp
->GetMainColormap( wxGetDisplay() );
1241 wxColour colour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1242 colour
.CalcPixel( (WXColormap
) cm
);
1244 XSetForeground( xdisplay
, g_eraseGC
, colour
.GetPixel() );
1246 XFillRectangle( xdisplay
, xwindow
, g_eraseGC
, x
, y
, width
, height
);
1250 wxNcPaintEvent
nc_paint_event( GetId() );
1251 nc_paint_event
.SetEventObject( this );
1252 GetEventHandler()->ProcessEvent( nc_paint_event
);
1254 m_updateNcArea
= FALSE
;
1257 // ----------------------------------------------------------------------------
1259 // ----------------------------------------------------------------------------
1261 // Responds to colour changes: passes event on to children.
1262 void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1264 wxWindowList::Node
*node
= GetChildren().GetFirst();
1267 // Only propagate to non-top-level windows
1268 wxWindow
*win
= node
->GetData();
1269 if ( win
->GetParent() )
1271 wxSysColourChangedEvent event2
;
1272 event
.m_eventObject
= win
;
1273 win
->GetEventHandler()->ProcessEvent(event2
);
1276 node
= node
->GetNext();
1280 // See handler for InFocus case in app.cpp for details.
1281 wxWindow
* g_GettingFocus
= NULL
;
1283 void wxWindowX11::OnInternalIdle()
1285 // Update invalidated regions.
1288 // This calls the UI-update mechanism (querying windows for
1289 // menu/toolbar/control state information)
1290 if (wxUpdateUIEvent::CanUpdate((wxWindow
*) this))
1291 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);
1293 // Set the input focus if couldn't do it before
1294 if (m_needsInputFocus
)
1298 msg
.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
1299 printf(msg
.c_str());
1303 // If it couldn't set the focus now, there's
1304 // no point in trying again.
1305 m_needsInputFocus
= FALSE
;
1307 g_GettingFocus
= NULL
;
1310 // ----------------------------------------------------------------------------
1311 // function which maintain the global hash table mapping Widgets to wxWindows
1312 // ----------------------------------------------------------------------------
1314 bool wxAddWindowToTable(Window w
, wxWindow
*win
)
1316 wxWindow
*oldItem
= NULL
;
1317 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1319 wxLogDebug( wxT("Widget table clash: new widget is %ld, %s"),
1320 (long)w
, win
->GetClassInfo()->GetClassName());
1324 wxWidgetHashTable
->Put((long) w
, win
);
1326 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1327 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1332 wxWindow
*wxGetWindowFromTable(Window w
)
1334 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1337 void wxDeleteWindowFromTable(Window w
)
1339 wxWidgetHashTable
->Delete((long)w
);
1342 // ----------------------------------------------------------------------------
1343 // function which maintain the global hash table mapping client widgets
1344 // ----------------------------------------------------------------------------
1346 bool wxAddClientWindowToTable(Window w
, wxWindow
*win
)
1348 wxWindow
*oldItem
= NULL
;
1349 if ((oldItem
= (wxWindow
*)wxClientWidgetHashTable
->Get ((long) w
)))
1351 wxLogDebug( wxT("Client window table clash: new window is %ld, %s"),
1352 (long)w
, win
->GetClassInfo()->GetClassName());
1356 wxClientWidgetHashTable
->Put((long) w
, win
);
1358 wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
1359 (unsigned int) w
, win
, win
->GetClassInfo()->GetClassName());
1364 wxWindow
*wxGetClientWindowFromTable(Window w
)
1366 return (wxWindow
*)wxClientWidgetHashTable
->Get((long) w
);
1369 void wxDeleteClientWindowFromTable(Window w
)
1371 wxClientWidgetHashTable
->Delete((long)w
);
1374 // ----------------------------------------------------------------------------
1375 // add/remove window from the table
1376 // ----------------------------------------------------------------------------
1378 // ----------------------------------------------------------------------------
1379 // X11-specific accessors
1380 // ----------------------------------------------------------------------------
1382 WXWindow
wxWindowX11::GetMainWindow() const
1384 return m_mainWindow
;
1387 WXWindow
wxWindowX11::GetClientAreaWindow() const
1389 return m_clientWindow
;
1392 // ----------------------------------------------------------------------------
1393 // TranslateXXXEvent() functions
1394 // ----------------------------------------------------------------------------
1396 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Window window
, XEvent
*xevent
)
1398 switch (XEventGetType(xevent
))
1406 wxEventType eventType
= wxEVT_NULL
;
1408 if (XEventGetType(xevent
) == EnterNotify
)
1410 //if (local_event.xcrossing.mode!=NotifyNormal)
1411 // return ; // Ignore grab events
1412 eventType
= wxEVT_ENTER_WINDOW
;
1413 // canvas->GetEventHandler()->OnSetFocus();
1415 else if (XEventGetType(xevent
) == LeaveNotify
)
1417 //if (local_event.xcrossingr.mode!=NotifyNormal)
1418 // return ; // Ignore grab events
1419 eventType
= wxEVT_LEAVE_WINDOW
;
1420 // canvas->GetEventHandler()->OnKillFocus();
1422 else if (XEventGetType(xevent
) == MotionNotify
)
1424 eventType
= wxEVT_MOTION
;
1426 else if (XEventGetType(xevent
) == ButtonPress
)
1428 wxevent
.SetTimestamp(XButtonEventGetTime(xevent
));
1430 if (XButtonEventLChanged(xevent
))
1432 eventType
= wxEVT_LEFT_DOWN
;
1435 else if (XButtonEventMChanged(xevent
))
1437 eventType
= wxEVT_MIDDLE_DOWN
;
1440 else if (XButtonEventRChanged(xevent
))
1442 eventType
= wxEVT_RIGHT_DOWN
;
1446 // check for a double click
1447 // TODO: where can we get this value from?
1448 //long dclickTime = XtGetMultiClickTime(wxGlobalDisplay());
1449 long dclickTime
= 200;
1450 long ts
= wxevent
.GetTimestamp();
1452 int buttonLast
= win
->GetLastClickedButton();
1453 long lastTS
= win
->GetLastClickTime();
1454 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
1457 win
->SetLastClick(0, ts
);
1458 if ( eventType
== wxEVT_LEFT_DOWN
)
1459 eventType
= wxEVT_LEFT_DCLICK
;
1460 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
1461 eventType
= wxEVT_MIDDLE_DCLICK
;
1462 else if ( eventType
== wxEVT_RIGHT_DOWN
)
1463 eventType
= wxEVT_RIGHT_DCLICK
;
1467 // not fast enough or different button
1468 win
->SetLastClick(button
, ts
);
1471 else if (XEventGetType(xevent
) == ButtonRelease
)
1473 if (XButtonEventLChanged(xevent
))
1475 eventType
= wxEVT_LEFT_UP
;
1477 else if (XButtonEventMChanged(xevent
))
1479 eventType
= wxEVT_MIDDLE_UP
;
1481 else if (XButtonEventRChanged(xevent
))
1483 eventType
= wxEVT_RIGHT_UP
;
1492 wxevent
.SetEventType(eventType
);
1494 wxevent
.m_x
= XButtonEventGetX(xevent
);
1495 wxevent
.m_y
= XButtonEventGetY(xevent
);
1497 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1498 || (XButtonEventLIsDown(xevent
)
1499 && (eventType
!= wxEVT_LEFT_UP
)));
1500 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1501 || (XButtonEventMIsDown(xevent
)
1502 && (eventType
!= wxEVT_MIDDLE_UP
)));
1503 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1504 || (XButtonEventRIsDown (xevent
)
1505 && (eventType
!= wxEVT_RIGHT_UP
)));
1507 wxevent
.m_shiftDown
= XButtonEventShiftIsDown(xevent
);
1508 wxevent
.m_controlDown
= XButtonEventCtrlIsDown(xevent
);
1509 wxevent
.m_altDown
= XButtonEventAltIsDown(xevent
);
1510 wxevent
.m_metaDown
= XButtonEventMetaIsDown(xevent
);
1512 wxevent
.SetId(win
->GetId());
1513 wxevent
.SetEventObject(win
);
1521 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Window
WXUNUSED(win
), XEvent
*xevent
, bool isAscii
)
1523 switch (XEventGetType(xevent
))
1531 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
1532 int id
= wxCharCodeXToWX (keySym
);
1533 // id may be WXK_xxx code - these are outside ASCII range, so we
1534 // can't just use toupper() on id.
1535 // Only change this if we want the raw key that was pressed,
1536 // and don't change it if we want an ASCII value.
1537 if (!isAscii
&& (id
>= 'a' && id
<= 'z'))
1539 id
= id
+ 'A' - 'a';
1542 wxevent
.m_shiftDown
= XKeyEventShiftIsDown(xevent
);
1543 wxevent
.m_controlDown
= XKeyEventCtrlIsDown(xevent
);
1544 wxevent
.m_altDown
= XKeyEventAltIsDown(xevent
);
1545 wxevent
.m_metaDown
= XKeyEventMetaIsDown(xevent
);
1546 wxevent
.SetEventObject(win
);
1547 wxevent
.m_keyCode
= id
;
1548 wxevent
.SetTimestamp(XKeyEventGetTime(xevent
));
1550 wxevent
.m_x
= XKeyEventGetX(xevent
);
1551 wxevent
.m_y
= XKeyEventGetY(xevent
);
1561 // ----------------------------------------------------------------------------
1563 // ----------------------------------------------------------------------------
1565 bool wxWindowX11::SetBackgroundColour(const wxColour
& col
)
1567 wxWindowBase::SetBackgroundColour(col
);
1569 Display
*xdisplay
= (Display
*) wxGlobalDisplay();
1570 int xscreen
= DefaultScreen( xdisplay
);
1571 Colormap cm
= DefaultColormap( xdisplay
, xscreen
);
1573 m_backgroundColour
.CalcPixel( (WXColormap
) cm
);
1575 // We don't set the background colour as we paint
1576 // the background ourselves.
1577 // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
1582 bool wxWindowX11::SetForegroundColour(const wxColour
& col
)
1584 if ( !wxWindowBase::SetForegroundColour(col
) )
1590 // ----------------------------------------------------------------------------
1592 // ----------------------------------------------------------------------------
1594 wxWindow
*wxGetActiveWindow()
1597 wxFAIL_MSG("Not implemented");
1602 wxWindow
*wxWindowBase::GetCapture()
1604 return (wxWindow
*)g_captureWindow
;
1608 // Find the wxWindow at the current mouse position, returning the mouse
1610 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1612 return wxFindWindowAtPoint(wxGetMousePosition());
1615 // Get the current mouse position.
1616 wxPoint
wxGetMousePosition()
1620 return wxPoint(0, 0);
1622 Display
*display
= wxGlobalDisplay();
1623 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
1624 Window rootReturn
, childReturn
;
1625 int rootX
, rootY
, winX
, winY
;
1626 unsigned int maskReturn
;
1628 XQueryPointer (display
,
1632 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
1633 return wxPoint(rootX
, rootY
);
1638 // ----------------------------------------------------------------------------
1639 // wxNoOptimize: switch off size optimization
1640 // ----------------------------------------------------------------------------
1642 int wxNoOptimize::ms_count
= 0;
1645 // ----------------------------------------------------------------------------
1647 // ----------------------------------------------------------------------------
1649 class wxWinModule
: public wxModule
1656 DECLARE_DYNAMIC_CLASS(wxWinModule
)
1659 IMPLEMENT_DYNAMIC_CLASS(wxWinModule
, wxModule
)
1661 bool wxWinModule::OnInit()
1663 Display
*xdisplay
= wxGlobalDisplay();
1664 int xscreen
= DefaultScreen( xdisplay
);
1665 Window xroot
= RootWindow( xdisplay
, xscreen
);
1666 g_eraseGC
= XCreateGC( xdisplay
, xroot
, 0, NULL
);
1667 XSetFillStyle( xdisplay
, g_eraseGC
, FillSolid
);
1672 void wxWinModule::OnExit()
1674 Display
*xdisplay
= wxGlobalDisplay();
1675 XFreeGC( xdisplay
, g_eraseGC
);