1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
25 #define XtDisplay XTDISPLAY
26 #define XtWindow XTWINDOW
27 #define XtScreen XTSCREEN
33 #include "wx/dcclient.h"
36 #include "wx/layout.h"
37 #include "wx/button.h"
38 #include "wx/settings.h"
40 #include "wx/scrolwin.h"
41 #include "wx/module.h"
42 #include "wx/menuitem.h"
44 #include "wx/evtloop.h"
47 #if wxUSE_DRAG_AND_DROP
51 // DoSetSizeIntr and DoMoveWindowIntr
53 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
54 // did nott work and/or segfaulted because
55 // 1) wxWindow::Create calls SetSize,
56 // which results in a call to DoSetSize much earlier than in the other ports
57 // 2) if wxWindow::Create is called (wxControl::Create calls it)
58 // then DoSetSize is never called, causing layout problems in composite
62 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
63 // DoSetPosition directly or indirectly from wxWindow::Create
64 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it
67 #pragma message disable nosimpint
71 #include <Xm/DrawingA.h>
72 #include <Xm/ScrolledW.h>
73 #include <Xm/ScrollBar.h>
76 #include <Xm/RowColumn.h> // for XmMenuPosition
78 #pragma message enable nosimpint
81 #include "wx/motif/private.h"
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 static const int SCROLL_MARGIN
= 4;
91 // ----------------------------------------------------------------------------
92 // global variables for this module
93 // ----------------------------------------------------------------------------
95 extern wxHashTable
*wxWidgetHashTable
;
96 static wxWindow
* g_captureWindow
= NULL
;
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
104 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
105 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
106 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
107 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
108 XmScrollBarCallbackStruct
*cbs
);
109 static void wxPanelItemEventHandler(Widget wid
,
110 XtPointer client_data
,
112 Boolean
*continueToDispatch
);
117 // Helper function for 16-bit fonts
118 static int str16len(const char *s
)
122 while (s
[0] && s
[1]) {
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
137 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
138 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
146 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
147 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
148 EVT_IDLE(wxWindow::OnIdle
)
151 // ============================================================================
153 // ============================================================================
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
161 Widget w
= (Widget
)widget
;
169 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
171 Widget w
= (Widget
)widget
;
180 // Rationale: a lot of common operations (including but not
181 // limited to moving, resizing and appending items to a listbox)
182 // unmamange the widget, do their work, then manage it again.
183 // This means that, for example adding an item to a listbox will show it,
184 // or that most controls are shown every time they are moved or resized!
185 XtSetMappedWhenManaged( w
, domap
);
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
194 void wxWindow::Init()
196 // generic initializations first
200 m_needsRefresh
= TRUE
;
201 m_mainWidget
= (WXWidget
) 0;
203 m_winCaptured
= FALSE
;
206 m_isBeingDeleted
= FALSE
;
212 m_drawingArea
= (WXWidget
) 0;
217 m_backingPixmap
= (WXPixmap
) 0;
228 // real construction (Init() must have been called before!)
229 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
233 const wxString
& name
)
235 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
237 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
239 parent
->AddChild(this);
241 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
242 m_foregroundColour
= *wxBLACK
;
244 //// TODO: we should probably optimize by only creating a
245 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
246 //// But for now, let's simplify things by always creating the
247 //// drawing area, since otherwise the translations are different.
249 // New translations for getting mouse motion feedback
250 static const String translations
=
251 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
252 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
253 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
254 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
255 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
256 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
257 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
258 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
259 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
260 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
261 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
262 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
263 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
264 <Key>: DrawingAreaInput()";
266 XtActionsRec actions
[1];
267 actions
[0].string
= "wxCanvasMotionEvent";
268 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
269 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
271 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
273 if (style
& wxSIMPLE_BORDER
)
275 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
278 xmFrameWidgetClass
, parentWidget
,
279 XmNshadowType
, XmSHADOW_IN
,
280 XmNshadowThickness
, 1,
283 } else if (style
& wxSUNKEN_BORDER
)
285 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
288 xmFrameWidgetClass
, parentWidget
,
289 XmNshadowType
, XmSHADOW_IN
,
292 } else if (style
& wxRAISED_BORDER
)
294 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
297 xmFrameWidgetClass
, parentWidget
,
298 XmNshadowType
, XmSHADOW_OUT
,
303 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
306 xmScrolledWindowWidgetClass
,
307 m_borderWidget
? (Widget
) m_borderWidget
309 XmNresizePolicy
, XmRESIZE_NONE
,
311 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
312 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
316 XtTranslations ptr
= XtParseTranslationTable(translations
);
317 m_drawingArea
= (WXWidget
)XtVaCreateWidget
320 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
321 XmNunitType
, XmPIXELS
,
322 // XmNresizePolicy, XmRESIZE_ANY,
323 XmNresizePolicy
, XmRESIZE_NONE
,
326 XmNtranslations
, ptr
,
329 XtFree((char *) ptr
);
332 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
334 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
335 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
336 XtFree ((char *) ptr
);
340 wxAddWindowToTable((Widget
) m_drawingArea
, this);
341 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
343 // This order is very important in Motif 1.2.1
344 XtRealizeWidget ((Widget
) m_scrolledWindow
);
345 XtRealizeWidget ((Widget
) m_drawingArea
);
346 XtManageChild ((Widget
) m_drawingArea
);
348 ptr
= XtParseTranslationTable("<Configure>: resize()");
349 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
350 XtFree ((char *) ptr
);
352 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
353 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
357 display
= XtDisplay (scrolledWindow
);
358 xwindow
= XtWindow (drawingArea
);
362 (Widget
)m_drawingArea
,
363 PointerMotionHintMask
| EnterWindowMask
|
364 LeaveWindowMask
| FocusChangeMask
,
366 (XtEventHandler
) wxCanvasEnterLeave
,
370 // Scrolled widget needs to have its colour changed or we get a little blue
371 // square where the scrollbars abutt
372 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
373 wxDoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
374 wxDoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
376 XmScrolledWindowSetAreas(
377 (Widget
)m_scrolledWindow
,
378 (Widget
) 0, (Widget
) 0,
379 (Widget
) m_drawingArea
);
383 XtRealizeWidget ((Widget
) m_hScrollBar
);
385 XtRealizeWidget ((Widget
) m_vScrollBar
);
388 // Without this, the cursor may not be restored properly (e.g. in splitter
390 SetCursor(*wxSTANDARD_CURSOR
);
391 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
392 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, TRUE
);
397 wxWindow::~wxWindow()
399 if (g_captureWindow
== this)
400 g_captureWindow
= NULL
;
402 m_isBeingDeleted
= TRUE
;
404 // Motif-specific actions first
405 WXWidget wMain
= GetMainWidget();
408 // Removes event handlers
415 m_parent
->RemoveChild( this );
417 // If m_drawingArea, we're a fully-fledged window with drawing area,
418 // scrollbars etc. (what wxCanvas used to be)
421 // Destroy children before destroying self
425 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
427 Widget w
= (Widget
) m_drawingArea
;
428 wxDeleteWindowFromTable(w
);
433 m_drawingArea
= (WXWidget
) 0;
436 // Only if we're _really_ a canvas (not a dialog box/panel)
437 if (m_scrolledWindow
)
439 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
444 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
445 XtUnmanageChild((Widget
) m_hScrollBar
);
449 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
450 XtUnmanageChild((Widget
) m_vScrollBar
);
454 XtDestroyWidget((Widget
) m_hScrollBar
);
456 XtDestroyWidget((Widget
) m_vScrollBar
);
458 UnmanageAndDestroy(m_scrolledWindow
);
462 XtDestroyWidget ((Widget
) m_borderWidget
);
463 m_borderWidget
= (WXWidget
) 0;
466 else // Why wasn't this here before? JACS 8/3/2000
470 // Destroy the window
473 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
474 // Child widgets will get destroyed automatically when a frame
475 // or dialog is destroyed, but before that you may get some memory
476 // leaks and potential layout problems if you delete and then add
479 // GRG, Feb/2000: commented this out when adding support for
480 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
481 // that this call crashed wxMotif under OS/2, so it seems
482 // that leaving it out is the right thing to do.
483 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
484 XtDestroyWidget((Widget
) GetMainWidget());
485 SetMainWidget((WXWidget
) NULL
);
489 // ----------------------------------------------------------------------------
490 // scrollbar management
491 // ----------------------------------------------------------------------------
494 void wxWindow::CreateScrollbar(wxOrientation orientation
)
496 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
498 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
500 // Add scrollbars if required
501 if (orientation
== wxHORIZONTAL
)
503 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
504 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
505 XmNorientation
, XmHORIZONTAL
,
507 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
508 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
509 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
510 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
511 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
512 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
513 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
514 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
516 XtVaSetValues (hScrollBar
,
521 m_hScrollBar
= (WXWidget
) hScrollBar
;
523 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
524 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
526 XtRealizeWidget(hScrollBar
);
528 XtVaSetValues((Widget
) m_scrolledWindow
,
529 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
532 wxAddWindowToTable( hScrollBar
, this );
535 if (orientation
== wxVERTICAL
)
537 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
538 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
539 XmNorientation
, XmVERTICAL
,
541 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
542 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
543 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
544 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
545 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
546 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
547 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
548 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
550 XtVaSetValues (vScrollBar
,
555 m_vScrollBar
= (WXWidget
) vScrollBar
;
556 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
557 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
559 XtRealizeWidget(vScrollBar
);
561 XtVaSetValues((Widget
) m_scrolledWindow
,
562 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
565 wxAddWindowToTable( vScrollBar
, this );
568 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
571 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
573 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
575 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
576 // Add scrollbars if required
577 if (orientation
== wxHORIZONTAL
)
581 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
582 XtDestroyWidget((Widget
) m_hScrollBar
);
584 m_hScrollBar
= (WXWidget
) 0;
586 XtVaSetValues((Widget
) m_scrolledWindow
,
587 XmNhorizontalScrollBar
, (Widget
) 0,
592 if (orientation
== wxVERTICAL
)
596 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
597 XtDestroyWidget((Widget
) m_vScrollBar
);
599 m_vScrollBar
= (WXWidget
) 0;
601 XtVaSetValues((Widget
) m_scrolledWindow
,
602 XmNverticalScrollBar
, (Widget
) 0,
606 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
609 // ---------------------------------------------------------------------------
611 // ---------------------------------------------------------------------------
613 void wxWindow::SetFocus()
615 Widget wMain
= (Widget
) GetMainWidget();
616 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
617 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
620 // Get the window with the focus
621 wxWindow
*wxWindowBase::FindFocus()
624 // (1) Can there be multiple focussed widgets in an application?
625 // In which case we need to find the top-level window that's
627 // (2) The widget with the focus may not be in the widget table
628 // depending on which widgets I put in the table
629 wxWindow
*winFocus
= (wxWindow
*)NULL
;
630 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
632 node
= node
->GetNext() )
634 wxWindow
*win
= node
->GetData();
636 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
638 if (w
!= (Widget
) NULL
)
640 winFocus
= wxGetWindowFromTable(w
);
649 bool wxWindow::Enable(bool enable
)
651 if ( !wxWindowBase::Enable(enable
) )
654 Widget wMain
= (Widget
)GetMainWidget();
657 XtSetSensitive(wMain
, enable
);
658 XmUpdateDisplay(wMain
);
664 bool wxWindow::Show(bool show
)
666 if ( !wxWindowBase::Show(show
) )
669 if (m_borderWidget
|| m_scrolledWindow
)
671 MapOrUnmap(m_drawingArea
, show
);
672 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
676 if ( !MapOrUnmap(GetTopWidget(), show
) )
677 MapOrUnmap(GetMainWidget(), show
);
683 // Raise the window to the top of the Z order
684 void wxWindow::Raise()
686 Widget wTop
= (Widget
) GetTopWidget();
687 Window window
= XtWindow(wTop
);
688 XRaiseWindow(XtDisplay(wTop
), window
);
691 // Lower the window to the bottom of the Z order
692 void wxWindow::Lower()
694 Widget wTop
= (Widget
) GetTopWidget();
695 Window window
= XtWindow(wTop
);
696 XLowerWindow(XtDisplay(wTop
), window
);
699 void wxWindow::SetTitle(const wxString
& title
)
701 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
704 wxString
wxWindow::GetTitle() const
707 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
709 return wxString(title
);
712 void wxWindow::DoCaptureMouse()
714 g_captureWindow
= this;
718 Widget wMain
= (Widget
)GetMainWidget();
720 XtAddGrab(wMain
, TRUE
, FALSE
);
722 m_winCaptured
= TRUE
;
725 void wxWindow::DoReleaseMouse()
727 g_captureWindow
= NULL
;
728 if ( !m_winCaptured
)
731 Widget wMain
= (Widget
)GetMainWidget();
735 m_winCaptured
= FALSE
;
738 bool wxWindow::SetFont(const wxFont
& font
)
740 if ( !wxWindowBase::SetFont(font
) )
751 bool wxWindow::SetCursor(const wxCursor
& cursor
)
753 if ( !wxWindowBase::SetCursor(cursor
) )
759 // wxASSERT_MSG( m_cursor.Ok(),
760 // wxT("cursor must be valid after call to the base version"));
761 wxCursor
* cursor2
= NULL
;
763 cursor2
= & m_cursor
;
765 cursor2
= wxSTANDARD_CURSOR
;
767 WXDisplay
*dpy
= GetXDisplay();
768 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
770 Widget w
= (Widget
) GetMainWidget();
771 Window win
= XtWindow(w
);
772 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
777 // Coordinates relative to the window
778 void wxWindow::WarpPointer (int x
, int y
)
780 Widget wClient
= (Widget
)GetClientWidget();
782 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
785 // ---------------------------------------------------------------------------
787 // ---------------------------------------------------------------------------
789 int wxWindow::GetScrollPos(int orient
) const
791 if (orient
== wxHORIZONTAL
)
797 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
801 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
809 // This now returns the whole range, not just the number of positions that we
811 int wxWindow::GetScrollRange(int orient
) const
813 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
814 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
818 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
822 int wxWindow::GetScrollThumb(int orient
) const
824 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
825 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
828 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
832 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
834 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
838 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
841 SetInternalScrollPos((wxOrientation
)orient
, pos
);
844 // New function that will replace some of the above.
845 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
846 int range
, bool WXUNUSED(refresh
))
849 GetSize(& oldW
, & oldH
);
853 if (thumbVisible
== 0)
856 if (thumbVisible
> range
)
857 thumbVisible
= range
;
859 // Save the old state to see if it changed
860 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
862 if (orient
== wxHORIZONTAL
)
864 if (thumbVisible
== range
)
867 DestroyScrollbar(wxHORIZONTAL
);
872 CreateScrollbar(wxHORIZONTAL
);
875 if (orient
== wxVERTICAL
)
877 if (thumbVisible
== range
)
880 DestroyScrollbar(wxVERTICAL
);
885 CreateScrollbar(wxVERTICAL
);
888 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
890 if (oldScrollBar
!= newScrollBar
)
892 // This is important! Without it, scrollbars misbehave badly.
893 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
894 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
895 XtRealizeWidget((Widget
) m_scrolledWindow
);
896 XtManageChild((Widget
) m_scrolledWindow
);
901 XtVaSetValues((Widget
) newScrollBar
,
905 XmNsliderSize
, thumbVisible
,
909 SetInternalScrollPos((wxOrientation
)orient
, pos
);
912 GetSize(& newW
, & newH
);
914 // Adjusting scrollbars can resize the canvas accidentally
915 if (newW
!= oldW
|| newH
!= oldH
)
916 SetSize(-1, -1, oldW
, oldH
);
919 // Does a physical scroll
920 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
925 // Use specified rectangle
926 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
930 // Use whole client area
932 GetClientSize(& w
, & h
);
935 int x1
= (dx
>= 0) ? x
: x
- dx
;
936 int y1
= (dy
>= 0) ? y
: y
- dy
;
937 int w1
= w
- abs(dx
);
938 int h1
= h
- abs(dy
);
939 int x2
= (dx
>= 0) ? x
+ dx
: x
;
940 int y2
= (dy
>= 0) ? y
+ dy
: y
;
944 dc
.SetLogicalFunction (wxCOPY
);
946 Widget widget
= (Widget
) GetMainWidget();
947 Window window
= XtWindow(widget
);
948 Display
* display
= XtDisplay(widget
);
950 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
951 x1
, y1
, w1
, h1
, x2
, y2
);
953 dc
.SetAutoSetting(TRUE
);
954 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
955 dc
.SetBrush(brush
); // FIXME: needed?
957 wxWindowList::Node
*cnode
= m_children
.GetFirst();
960 wxWindow
*child
= cnode
->GetData();
963 child
->GetSize( &sx
, &sy
);
964 wxPoint
pos( child
->GetPosition() );
965 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
966 cnode
= cnode
->GetNext();
969 // We'll add rectangles to the list of update rectangles according to which
970 // bits we've exposed.
975 wxRect
*rect
= new wxRect
;
981 XFillRectangle(display
, window
,
982 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
986 rect
->width
= rect
->width
;
987 rect
->height
= rect
->height
;
989 updateRects
.Append((wxObject
*) rect
);
993 wxRect
*rect
= new wxRect
;
995 rect
->x
= x
+ w
+ dx
;
1000 XFillRectangle(display
, window
,
1001 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1006 rect
->width
= rect
->width
;
1007 rect
->height
= rect
->height
;
1009 updateRects
.Append((wxObject
*) rect
);
1013 wxRect
*rect
= new wxRect
;
1020 XFillRectangle(display
, window
,
1021 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1025 rect
->width
= rect
->width
;
1026 rect
->height
= rect
->height
;
1028 updateRects
.Append((wxObject
*) rect
);
1032 wxRect
*rect
= new wxRect
;
1035 rect
->y
= y
+ h
+ dy
;
1039 XFillRectangle(display
, window
,
1040 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1044 rect
->width
= rect
->width
;
1045 rect
->height
= rect
->height
;
1047 updateRects
.Append((wxObject
*) rect
);
1049 dc
.SetBrush(wxNullBrush
);
1051 // Now send expose events
1053 wxList::Node
* node
= updateRects
.GetFirst();
1056 wxRect
* rect
= (wxRect
*) node
->GetData();
1059 event
.type
= Expose
;
1060 event
.display
= display
;
1061 event
.send_event
= True
;
1062 event
.window
= window
;
1066 event
.width
= rect
->width
;
1067 event
.height
= rect
->height
;
1071 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1073 node
= node
->GetNext();
1077 // Delete the update rects
1078 node
= updateRects
.GetFirst();
1081 wxRect
* rect
= (wxRect
*) node
->GetData();
1083 node
= node
->GetNext();
1086 XmUpdateDisplay((Widget
) GetMainWidget());
1089 // ---------------------------------------------------------------------------
1091 // ---------------------------------------------------------------------------
1093 #if wxUSE_DRAG_AND_DROP
1095 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1102 // Old style file-manager drag&drop
1103 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1108 // ----------------------------------------------------------------------------
1110 // ----------------------------------------------------------------------------
1114 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1119 #endif // wxUSE_TOOLTIPS
1121 // ----------------------------------------------------------------------------
1123 // ----------------------------------------------------------------------------
1127 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1129 Widget widget
= (Widget
) GetMainWidget();
1131 /* The menuId field seems to be usused, so we'll use it to
1132 indicate whether a menu is popped up or not:
1133 0: Not currently created as a popup
1134 -1: Created as a popup, but not active
1138 if (menu
->GetParent() && (menu
->GetId() != -1))
1141 if (menu
->GetMainWidget())
1143 menu
->DestroyMenu(TRUE
);
1146 menu
->SetId(1); /* Mark as popped-up */
1147 menu
->CreateMenu(NULL
, widget
, menu
);
1148 menu
->SetInvokingWindow(this);
1152 // menu->SetParent(parent);
1153 // parent->children->Append(menu); // Store menu for later deletion
1155 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1163 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1165 wxCanvas *canvas = (wxCanvas *) this;
1166 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1167 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1171 Display
*display
= XtDisplay (widget
);
1172 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1173 Window thisWindow
= XtWindow (widget
);
1175 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1176 &rootX
, &rootY
, &childWindow
);
1178 XButtonPressedEvent event
;
1179 event
.type
= ButtonPress
;
1185 event
.x_root
= rootX
;
1186 event
.y_root
= rootY
;
1188 XmMenuPosition (menuWidget
, &event
);
1189 XtManageChild (menuWidget
);
1191 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1192 // idle-time destroy routine.
1193 // Waiting until this ID changes causes this function to block until
1194 // the menu has been dismissed and the widgets cleaned up.
1195 // In other words, once this routine returns, it is safe to delete
1197 // Ian Brown <ian.brown@printsoft.de>
1199 wxEventLoop evtLoop
;
1201 while (menu
->GetId() == 1)
1203 wxDoEventLoopIteration( evtLoop
);
1211 // ---------------------------------------------------------------------------
1212 // moving and resizing
1213 // ---------------------------------------------------------------------------
1215 bool wxWindow::PreResize()
1221 void wxWindow::DoGetSize(int *x
, int *y
) const
1223 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1224 ( m_borderWidget
? m_borderWidget
:
1225 m_scrolledWindow
? m_scrolledWindow
:
1229 XtVaGetValues( widget
,
1237 void wxWindow::DoGetPosition(int *x
, int *y
) const
1239 Widget widget
= (Widget
)
1241 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1245 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1247 // We may be faking the client origin. So a window that's really at (0, 30)
1248 // may appear (to wxWin apps) to be at (0, 0).
1251 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1260 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1262 Widget widget
= (Widget
) GetClientWidget();
1263 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1264 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1265 Window thisWindow
= XtWindow(widget
);
1270 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1273 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1275 Widget widget
= (Widget
) GetClientWidget();
1276 Display
*display
= XtDisplay(widget
);
1277 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1278 Window thisWindow
= XtWindow(widget
);
1283 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1287 // Get size *available for subwindows* i.e. excluding menu bar etc.
1288 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1290 Widget widget
= (Widget
) GetClientWidget();
1292 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1293 if(x
) *x
= xx
; if(y
) *y
= yy
;
1296 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1298 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, FALSE
);
1301 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1302 int sizeFlags
, bool fromCtor
)
1304 // A bit of optimization to help sort out the flickers.
1305 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1308 GetSize(& oldW
, & oldH
);
1309 GetPosition(& oldX
, & oldY
);
1312 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1320 wxSize
size(-1, -1);
1323 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1325 size
= DoGetBestSize();
1336 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1338 if( size
.x
== -1 ) size
= DoGetBestSize();
1347 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1348 || !wxNoOptimize::CanOptimize() )
1354 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1357 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1361 flags
|= wxMOVE_WIDTH
;
1364 flags
|= wxMOVE_HEIGHT
;
1366 int xx
= x
; int yy
= y
;
1367 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1369 DoMoveWindow( xx
, yy
, width
, height
);
1371 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1376 Widget widget
= (Widget
) GetTopWidget();
1380 bool managed
= XtIsManaged( widget
);
1382 XtUnmanageChild(widget
);
1386 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1388 DoMoveWindow(xx
, yy
, width
, height
);
1391 XtManageChild(widget
);
1395 void wxWindow::DoSetClientSize(int width
, int height
)
1399 Widget drawingArea
= (Widget
) m_drawingArea
;
1401 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1404 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1406 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1408 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1412 Widget widget
= (Widget
) GetTopWidget();
1415 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1417 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1420 // For implementation purposes - sometimes decorations make the client area
1422 wxPoint
wxWindow::GetClientAreaOrigin() const
1424 return wxPoint(0, 0);
1427 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1432 Widget drawingArea
= (Widget
) m_drawingArea
;
1433 Widget borderOrScrolled
= m_borderWidget
?
1434 (Widget
) m_borderWidget
:
1435 (Widget
) m_scrolledWindow
;
1437 bool managed
= XtIsManaged(borderOrScrolled
);
1439 XtUnmanageChild (borderOrScrolled
);
1440 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1442 if (flags
& wxMOVE_X
)
1443 XtVaSetValues (borderOrScrolled
,
1446 if (flags
& wxMOVE_Y
)
1447 XtVaSetValues (borderOrScrolled
,
1451 if (flags
& wxMOVE_WIDTH
)
1455 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1456 short thick
, margin
;
1457 XtVaGetValues ((Widget
) m_borderWidget
,
1458 XmNshadowThickness
, &thick
,
1459 XmNmarginWidth
, &margin
,
1461 w
-= 2 * (thick
+ margin
);
1464 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1467 if (flags
& wxMOVE_HEIGHT
)
1471 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1472 short thick
, margin
;
1473 XtVaGetValues ((Widget
) m_borderWidget
,
1474 XmNshadowThickness
, &thick
,
1475 XmNmarginHeight
, &margin
,
1477 h
-= 2 * (thick
+ margin
);
1480 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1484 XtManageChild (borderOrScrolled
);
1485 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1492 XtVaSetValues((Widget
)GetTopWidget(),
1501 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1503 DoMoveWindowIntr (x
, y
, width
, height
,
1504 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1507 // ---------------------------------------------------------------------------
1509 // ---------------------------------------------------------------------------
1511 int wxWindow::GetCharHeight() const
1513 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1515 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1517 int direction
, ascent
, descent
;
1518 XCharStruct overall
;
1519 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1520 &descent
, &overall
);
1522 // return (overall.ascent + overall.descent);
1523 return (ascent
+ descent
);
1526 int wxWindow::GetCharWidth() const
1528 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1530 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1532 int direction
, ascent
, descent
;
1533 XCharStruct overall
;
1534 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1535 &descent
, &overall
);
1537 return overall
.width
;
1540 void wxWindow::GetTextExtent(const wxString
& string
,
1542 int *descent
, int *externalLeading
,
1543 const wxFont
*theFont
) const
1545 wxFont
*fontToUse
= (wxFont
*)theFont
;
1547 fontToUse
= (wxFont
*) & m_font
;
1549 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1551 WXFontStructPtr pFontStruct
= fontToUse
->GetFontStruct(1.0, GetXDisplay());
1553 int direction
, ascent
, descent2
;
1554 XCharStruct overall
;
1555 int slen
= string
.Len();
1559 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1560 &ascent
, &descent2
, &overall
);
1563 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1564 &direction
, &ascent
, &descent2
, &overall
);
1567 *x
= (overall
.width
);
1569 *y
= (ascent
+ descent2
);
1571 *descent
= descent2
;
1572 if (externalLeading
)
1573 *externalLeading
= 0;
1577 // ----------------------------------------------------------------------------
1579 // ----------------------------------------------------------------------------
1581 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1583 m_needsRefresh
= TRUE
;
1584 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1585 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1587 XExposeEvent dummyEvent
;
1589 GetSize(&width
, &height
);
1591 dummyEvent
.type
= Expose
;
1592 dummyEvent
.display
= display
;
1593 dummyEvent
.send_event
= True
;
1594 dummyEvent
.window
= thisWindow
;
1597 dummyEvent
.x
= rect
->x
;
1598 dummyEvent
.y
= rect
->y
;
1599 dummyEvent
.width
= rect
->width
;
1600 dummyEvent
.height
= rect
->height
;
1606 dummyEvent
.width
= width
;
1607 dummyEvent
.height
= height
;
1609 dummyEvent
.count
= 0;
1613 wxClientDC
dc(this);
1614 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1615 dc
.SetBackground(backgroundBrush
);
1622 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1625 void wxWindow::Clear()
1627 wxClientDC
dc(this);
1628 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1629 dc
.SetBackground(brush
);
1633 void wxWindow::ClearUpdateRects()
1635 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1638 wxRect
* rect
= node
->GetData();
1640 node
= node
->GetNext();
1643 m_updateRects
.Clear();
1646 void wxWindow::DoPaint()
1648 //TODO : make a temporary gc so we can do the XCopyArea below
1649 if (m_backingPixmap
&& !m_needsRefresh
)
1653 GC tempGC
= (GC
) dc
.GetBackingGC();
1655 Widget widget
= (Widget
) GetMainWidget();
1660 // We have to test whether it's a wxScrolledWindow (hack!) because
1661 // otherwise we don't know how many pixels have been scrolled. We might
1662 // solve this in the future by defining virtual wxWindow functions to get
1663 // the scroll position in pixels. Or, each kind of scrolled window has to
1664 // implement backing stores itself, using generic wxWindows code.
1665 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1666 if ( scrolledWindow
)
1669 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1675 // TODO: This could be optimized further by only copying the areas in the
1676 // current update region.
1678 // Only blit the part visible in the client area. The backing pixmap
1679 // always starts at 0, 0 but we may be looking at only a portion of it.
1680 wxSize clientArea
= GetClientSize();
1681 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1682 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1684 // Copy whichever is samller, the amount of pixmap we have to copy,
1685 // or the size of the client area.
1686 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1687 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1689 // Make sure we're not negative
1690 toBlitX
= wxMax(0, toBlitX
);
1691 toBlitY
= wxMax(0, toBlitY
);
1696 (Pixmap
) m_backingPixmap
,
1699 scrollPosX
, scrollPosY
, // Start at the scroll position
1700 toBlitX
, toBlitY
, // How much of the pixmap to copy
1706 wxWindowDC
dc(this);
1707 // Set an erase event first
1708 wxEraseEvent
eraseEvent(GetId(), &dc
);
1709 eraseEvent
.SetEventObject(this);
1710 GetEventHandler()->ProcessEvent(eraseEvent
);
1712 wxPaintEvent
event(GetId());
1713 event
.SetEventObject(this);
1714 GetEventHandler()->ProcessEvent(event
);
1716 m_needsRefresh
= FALSE
;
1720 // ----------------------------------------------------------------------------
1722 // ----------------------------------------------------------------------------
1724 // Responds to colour changes: passes event on to children.
1725 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1727 wxWindowList::Node
*node
= GetChildren().GetFirst();
1730 // Only propagate to non-top-level windows
1731 wxWindow
*win
= node
->GetData();
1732 if ( win
->GetParent() )
1734 wxSysColourChangedEvent event2
;
1735 event
.m_eventObject
= win
;
1736 win
->GetEventHandler()->ProcessEvent(event2
);
1739 node
= node
->GetNext();
1743 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1745 // This calls the UI-update mechanism (querying windows for
1746 // menu/toolbar/control state information)
1750 // ----------------------------------------------------------------------------
1752 // ----------------------------------------------------------------------------
1754 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1757 if (!m_acceleratorTable
.Ok())
1760 int count
= m_acceleratorTable
.GetCount();
1761 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1763 for (i
= 0; i
< count
; i
++)
1765 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1766 if (entry
->MatchesEvent(event
))
1768 // Bingo, we have a match. Now find a control that matches the
1769 // entry command id.
1771 // Need to go up to the top of the window hierarchy, since it might
1772 // be e.g. a menu item
1773 wxWindow
* parent
= this;
1774 while ( parent
&& !parent
->IsTopLevel() )
1775 parent
= parent
->GetParent();
1780 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1784 // Try for a menu command
1785 if (frame
->GetMenuBar())
1787 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1790 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1791 commandEvent
.SetEventObject(frame
);
1793 // If ProcessEvent returns TRUE (it was handled), then
1794 // the calling code will skip the event handling.
1795 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1801 // Find a child matching the command id
1802 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1808 // Now we process those kinds of windows that we can.
1809 // For now, only buttons.
1810 if ( wxDynamicCast(child
, wxButton
) )
1812 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1813 commandEvent
.SetEventObject(child
);
1814 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1822 // We didn't match the key event against an accelerator.
1826 // ============================================================================
1827 // Motif-specific stuff from here on
1828 // ============================================================================
1830 // ----------------------------------------------------------------------------
1831 // function which maintain the global hash table mapping Widgets to wxWindows
1832 // ----------------------------------------------------------------------------
1834 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1836 wxWindow
*oldItem
= NULL
;
1837 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1839 wxLogDebug("Widget table clash: new widget is %ld, %s",
1840 (long)w
, win
->GetClassInfo()->GetClassName());
1844 wxWidgetHashTable
->Put((long) w
, win
);
1846 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1847 (WXWidget
)w
, win
, win
->GetClassInfo()->GetClassName());
1852 wxWindow
*wxGetWindowFromTable(Widget w
)
1854 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1857 void wxDeleteWindowFromTable(Widget w
)
1859 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1861 wxWidgetHashTable
->Delete((long)w
);
1864 // ----------------------------------------------------------------------------
1865 // add/remove window from the table
1866 // ----------------------------------------------------------------------------
1868 // Add to hash table, add event handler
1869 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1870 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1872 wxAddWindowToTable((Widget
) mainWidget
, this);
1873 XtAddEventHandler( (Widget
) mainWidget
,
1874 ButtonPressMask
| ButtonReleaseMask
1875 | PointerMotionMask
,
1877 wxPanelItemEventHandler
,
1883 XtOverrideTranslations ((Widget
) mainWidget
,
1884 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1885 XtFree ((char *) ptr
);
1888 // Some widgets have a parent form widget, e.g. wxRadioBox
1891 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1895 XtOverrideTranslations ((Widget
) formWidget
,
1896 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1897 XtFree ((char *) ptr
);
1904 SetSize (x
, y
, width
, height
);
1909 // Remove event handler, remove from hash table
1910 bool wxWindow::DetachWidget(WXWidget widget
)
1912 XtRemoveEventHandler( (Widget
) widget
,
1913 ButtonPressMask
| ButtonReleaseMask
1914 | PointerMotionMask
,
1916 wxPanelItemEventHandler
,
1919 wxDeleteWindowFromTable((Widget
) widget
);
1923 // ----------------------------------------------------------------------------
1924 // Motif-specific accessors
1925 // ----------------------------------------------------------------------------
1927 // Get the underlying X window
1928 WXWindow
wxWindow::GetXWindow() const
1930 Widget wMain
= (Widget
)GetMainWidget();
1932 return (WXWindow
) XtWindow(wMain
);
1934 return (WXWindow
) 0;
1937 // Get the underlying X display
1938 WXDisplay
*wxWindow::GetXDisplay() const
1940 Widget wMain
= (Widget
)GetMainWidget();
1942 return (WXDisplay
*) XtDisplay(wMain
);
1944 return (WXDisplay
*) NULL
;
1947 WXWidget
wxWindow::GetMainWidget() const
1950 return m_drawingArea
;
1952 return m_mainWidget
;
1955 WXWidget
wxWindow::GetClientWidget() const
1957 if (m_drawingArea
!= (WXWidget
) 0)
1958 return m_drawingArea
;
1960 return GetMainWidget();
1963 WXWidget
wxWindow::GetTopWidget() const
1965 return GetMainWidget();
1968 WXWidget
wxWindow::GetLabelWidget() const
1970 return GetMainWidget();
1973 // ----------------------------------------------------------------------------
1975 // ----------------------------------------------------------------------------
1977 // All widgets should have this as their resize proc.
1978 // OnSize sent to wxWindow via client data.
1979 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1980 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1982 wxWindow
*win
= wxGetWindowFromTable(w
);
1986 if (win
->PreResize())
1989 win
->GetSize(&width
, &height
);
1990 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1991 sizeEvent
.SetEventObject(win
);
1992 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1996 static void wxCanvasRepaintProc(Widget drawingArea
,
1997 XtPointer clientData
,
1998 XmDrawingAreaCallbackStruct
* cbs
)
2000 if (!wxGetWindowFromTable(drawingArea
))
2003 XEvent
* event
= cbs
->event
;
2004 wxWindow
* win
= (wxWindow
*) clientData
;
2006 switch (event
->type
)
2010 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2011 event
->xexpose
.width
, event
->xexpose
.height
);
2013 if (event
-> xexpose
.count
== 0)
2016 win
->ClearUpdateRects();
2023 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2024 static void wxCanvasEnterLeave(Widget drawingArea
,
2025 XtPointer
WXUNUSED(clientData
),
2026 XCrossingEvent
* event
)
2028 XmDrawingAreaCallbackStruct cbs
;
2031 ((XCrossingEvent
&) ev
) = *event
;
2033 cbs
.reason
= XmCR_INPUT
;
2036 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
2039 // Fix to make it work under Motif 1.0 (!)
2040 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
2041 XButtonEvent
*WXUNUSED(event
))
2043 #if XmVersion <= 1000
2044 XmDrawingAreaCallbackStruct cbs
;
2047 ev
= *((XEvent
*) event
);
2048 cbs
.reason
= XmCR_INPUT
;
2051 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2052 #endif // XmVersion <= 1000
2055 static void wxCanvasInputEvent(Widget drawingArea
,
2056 XtPointer
WXUNUSED(data
),
2057 XmDrawingAreaCallbackStruct
* cbs
)
2059 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
2065 if (cbs
->reason
!= XmCR_INPUT
)
2068 local_event
= *(cbs
->event
); // We must keep a copy!
2070 switch (local_event
.xany
.type
)
2078 wxMouseEvent wxevent
;
2079 if(wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, &local_event
))
2081 canvas
->GetEventHandler()->ProcessEvent(wxevent
);
2087 wxKeyEvent
event (wxEVT_CHAR
);
2088 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2090 // Implement wxFrame::OnCharHook by checking ancestor.
2091 wxWindow
*parent
= canvas
;
2092 while (parent
&& !parent
->IsTopLevel())
2093 parent
= parent
->GetParent();
2097 event
.SetEventType(wxEVT_CHAR_HOOK
);
2098 if (parent
->GetEventHandler()->ProcessEvent(event
))
2102 // For simplicity, OnKeyDown is the same as OnChar
2103 // TODO: filter modifier key presses from OnChar
2104 event
.SetEventType(wxEVT_KEY_DOWN
);
2106 // Only process OnChar if OnKeyDown didn't swallow it
2107 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2109 event
.SetEventType(wxEVT_CHAR
);
2110 canvas
->GetEventHandler()->ProcessEvent (event
);
2117 wxKeyEvent
event (wxEVT_KEY_UP
);
2118 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2120 canvas
->GetEventHandler()->ProcessEvent (event
);
2126 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2128 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2129 event
.SetEventObject(canvas
);
2130 canvas
->GetEventHandler()->ProcessEvent(event
);
2136 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2138 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2139 event
.SetEventObject(canvas
);
2140 canvas
->GetEventHandler()->ProcessEvent(event
);
2149 static void wxPanelItemEventHandler(Widget wid
,
2150 XtPointer
WXUNUSED(client_data
),
2152 Boolean
*continueToDispatch
)
2154 // Widget can be a label or the actual widget.
2156 wxWindow
*window
= wxGetWindowFromTable(wid
);
2159 wxMouseEvent
wxevent(0);
2160 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2162 window
->GetEventHandler()->ProcessEvent(wxevent
);
2166 // TODO: probably the key to allowing default behaviour to happen. Say we
2167 // set a m_doDefault flag to FALSE at the start of this function. Then in
2168 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2169 // TRUE, indicating that default processing can happen. Thus, behaviour can
2170 // appear to be overridden just by adding an event handler and not calling
2171 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2172 // way of handling drawing area events, to simplify things.
2173 *continueToDispatch
= True
;
2176 static void wxScrollBarCallback(Widget scrollbar
,
2177 XtPointer clientData
,
2178 XmScrollBarCallbackStruct
*cbs
)
2180 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2181 int orientation
= (int) clientData
;
2183 wxEventType eventType
= wxEVT_NULL
;
2184 switch (cbs
->reason
)
2186 case XmCR_INCREMENT
:
2188 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2191 case XmCR_DECREMENT
:
2193 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2198 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2201 case XmCR_VALUE_CHANGED
:
2203 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2206 case XmCR_PAGE_INCREMENT
:
2208 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2211 case XmCR_PAGE_DECREMENT
:
2213 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2218 eventType
= wxEVT_SCROLLWIN_TOP
;
2221 case XmCR_TO_BOTTOM
:
2223 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2228 // Should never get here
2229 wxFAIL_MSG("Unknown scroll event.");
2234 wxScrollWinEvent
event(eventType
,
2236 ((orientation
== XmHORIZONTAL
) ?
2237 wxHORIZONTAL
: wxVERTICAL
));
2238 event
.SetEventObject( win
);
2239 win
->GetEventHandler()->ProcessEvent(event
);
2242 // For repainting arbitrary windows
2243 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2248 wxWindow
* win
= wxGetWindowFromTable(w
);
2252 switch(event
-> type
)
2256 window
= (Window
) win
-> GetXWindow();
2257 display
= (Display
*) win
-> GetXDisplay();
2259 if (event
-> xexpose
.count
== 0)
2263 win
->ClearUpdateRects();
2267 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2268 event
->xexpose
.width
, event
->xexpose
.height
);
2276 // ----------------------------------------------------------------------------
2277 // TranslateXXXEvent() functions
2278 // ----------------------------------------------------------------------------
2280 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2281 Widget widget
, XEvent
*xevent
)
2283 switch (xevent
->xany
.type
)
2288 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2289 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2290 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2296 wxEventType eventType
= wxEVT_NULL
;
2298 if (xevent
->xany
.type
== LeaveNotify
)
2300 eventType
= wxEVT_LEAVE_WINDOW
;
2302 if (xevent
->xany
.type
== EnterNotify
)
2304 eventType
= wxEVT_ENTER_WINDOW
;
2306 else if (xevent
->xany
.type
== MotionNotify
)
2308 eventType
= wxEVT_MOTION
;
2310 else if (xevent
->xany
.type
== ButtonPress
)
2312 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2314 if (xevent
->xbutton
.button
== Button1
)
2316 eventType
= wxEVT_LEFT_DOWN
;
2319 else if (xevent
->xbutton
.button
== Button2
)
2321 eventType
= wxEVT_MIDDLE_DOWN
;
2324 else if (xevent
->xbutton
.button
== Button3
)
2326 eventType
= wxEVT_RIGHT_DOWN
;
2330 // check for a double click
2332 long dclickTime
= XtGetMultiClickTime(wxGlobalDisplay());
2333 long ts
= wxevent
.GetTimestamp();
2335 int buttonLast
= win
->GetLastClickedButton();
2336 long lastTS
= win
->GetLastClickTime();
2337 if ( buttonLast
&& buttonLast
== button
&&
2338 (ts
- lastTS
) < dclickTime
)
2341 win
->SetLastClick(0, ts
);
2342 if ( eventType
== wxEVT_LEFT_DOWN
)
2343 eventType
= wxEVT_LEFT_DCLICK
;
2344 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2345 eventType
= wxEVT_MIDDLE_DCLICK
;
2346 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2347 eventType
= wxEVT_RIGHT_DCLICK
;
2351 // not fast enough or different button
2352 win
->SetLastClick(button
, ts
);
2355 else if (xevent
->xany
.type
== ButtonRelease
)
2357 if (xevent
->xbutton
.button
== Button1
)
2359 eventType
= wxEVT_LEFT_UP
;
2361 else if (xevent
->xbutton
.button
== Button2
)
2363 eventType
= wxEVT_MIDDLE_UP
;
2365 else if (xevent
->xbutton
.button
== Button3
)
2367 eventType
= wxEVT_RIGHT_UP
;
2377 wxevent
.SetEventType(eventType
);
2380 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2383 win
->GetPosition(&x2
, &y2
);
2385 // The button x/y must be translated to wxWindows
2386 // window space - the widget might be a label or button,
2390 if (widget
!= (Widget
)win
->GetMainWidget())
2396 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2397 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2399 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2400 || (event_left_is_down (xevent
)
2401 && (eventType
!= wxEVT_LEFT_UP
)));
2402 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2403 || (event_middle_is_down (xevent
)
2404 && (eventType
!= wxEVT_MIDDLE_UP
)));
2405 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2406 || (event_right_is_down (xevent
)
2407 && (eventType
!= wxEVT_RIGHT_UP
)));
2409 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2410 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2411 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2412 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2414 wxevent
.SetId(win
->GetId());
2415 wxevent
.SetEventObject(win
);
2423 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2424 Widget
WXUNUSED(widget
), XEvent
*xevent
)
2426 switch (xevent
->xany
.type
)
2434 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2435 int id
= wxCharCodeXToWX (keySym
);
2436 // id may be WXK_xxx code - these are outside ASCII range, so we
2437 // can't just use toupper() on id
2438 if (id
>= 'a' && id
<= 'z')
2441 if (xevent
->xkey
.state
& ShiftMask
)
2442 wxevent
.m_shiftDown
= TRUE
;
2443 if (xevent
->xkey
.state
& ControlMask
)
2444 wxevent
.m_controlDown
= TRUE
;
2445 if (xevent
->xkey
.state
& Mod3Mask
)
2446 wxevent
.m_altDown
= TRUE
;
2447 if (xevent
->xkey
.state
& Mod1Mask
)
2448 wxevent
.m_metaDown
= TRUE
;
2449 wxevent
.SetEventObject(win
);
2450 wxevent
.m_keyCode
= id
;
2451 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2453 wxevent
.m_x
= xevent
->xbutton
.x
;
2454 wxevent
.m_y
= xevent
->xbutton
.y
;
2468 // ----------------------------------------------------------------------------
2470 // ----------------------------------------------------------------------------
2472 #define YAllocColor XAllocColor
2473 XColor g_itemColors
[5];
2474 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2477 static XmColorProc colorProc
;
2479 result
= wxNO_COLORS
;
2483 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2484 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2485 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2486 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2487 if (colorProc
== (XmColorProc
) NULL
)
2489 // Get a ptr to the actual function
2490 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2491 // And set it back to motif.
2492 XmSetColorCalculation (colorProc
);
2494 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2495 &g_itemColors
[wxFORE_INDEX
],
2496 &g_itemColors
[wxSELE_INDEX
],
2497 &g_itemColors
[wxTOPS_INDEX
],
2498 &g_itemColors
[wxBOTS_INDEX
]);
2499 result
= wxBACK_COLORS
;
2503 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2504 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2505 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2506 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2507 if (result
== wxNO_COLORS
)
2508 result
= wxFORE_COLORS
;
2511 Display
*dpy
= display
;
2512 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2516 /* 5 Colours to allocate */
2517 for (int i
= 0; i
< 5; i
++)
2518 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2519 result
= wxNO_COLORS
;
2523 /* Only 1 colour to allocate */
2524 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2525 result
= wxNO_COLORS
;
2531 // Changes the foreground and background colours to be derived from the current
2532 // background colour. To change the foreground colour, you must call
2533 // SetForegroundColour explicitly.
2534 void wxWindow::ChangeBackgroundColour()
2536 WXWidget mainWidget
= GetMainWidget();
2538 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2541 void wxWindow::ChangeForegroundColour()
2543 WXWidget mainWidget
= GetMainWidget();
2545 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2546 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2547 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2550 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2552 if ( !wxWindowBase::SetBackgroundColour(col
) )
2555 ChangeBackgroundColour();
2560 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2562 if ( !wxWindowBase::SetForegroundColour(col
) )
2565 ChangeForegroundColour();
2570 void wxWindow::ChangeFont(bool keepOriginalSize
)
2572 // Note that this causes the widget to be resized back
2573 // to its original size! We therefore have to set the size
2574 // back again. TODO: a better way in Motif?
2575 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2576 if (w
&& m_font
.Ok())
2578 int width
, height
, width1
, height1
;
2579 GetSize(& width
, & height
);
2581 wxDoChangeFont( GetLabelWidget(), m_font
);
2583 GetSize(& width1
, & height1
);
2584 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2586 SetSize(-1, -1, width
, height
);
2591 // ----------------------------------------------------------------------------
2593 // ----------------------------------------------------------------------------
2595 wxWindow
*wxGetActiveWindow()
2598 wxFAIL_MSG("Not implemented");
2603 wxWindow
*wxWindowBase::GetCapture()
2605 return (wxWindow
*)g_captureWindow
;
2609 // Find the wxWindow at the current mouse position, returning the mouse
2611 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2613 return wxFindWindowAtPoint(wxGetMousePosition());
2616 // Get the current mouse position.
2617 wxPoint
wxGetMousePosition()
2619 Display
*display
= (Display
*) wxGetDisplay();
2620 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2621 Window rootReturn
, childReturn
;
2622 int rootX
, rootY
, winX
, winY
;
2623 unsigned int maskReturn
;
2625 XQueryPointer (display
,
2629 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2630 return wxPoint(rootX
, rootY
);
2634 // ----------------------------------------------------------------------------
2635 // wxNoOptimize: switch off size optimization
2636 // ----------------------------------------------------------------------------
2638 int wxNoOptimize::ms_count
= 0;