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
;
175 // if the widget is not unmanaged, it still intercepts
176 // mouse events, even if it is not mapped (and hence invisible)
188 // Rationale: a lot of common operations (including but not
189 // limited to moving, resizing and appending items to a listbox)
190 // unmamange the widget, do their work, then manage it again.
191 // This means that, for example adding an item to a listbox will show it,
192 // or that most controls are shown every time they are moved or resized!
193 XtSetMappedWhenManaged( w
, domap
);
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 void wxWindow::Init()
204 // generic initializations first
208 m_needsRefresh
= TRUE
;
209 m_mainWidget
= (WXWidget
) 0;
211 m_winCaptured
= FALSE
;
214 m_isBeingDeleted
= FALSE
;
220 m_drawingArea
= (WXWidget
) 0;
225 m_backingPixmap
= (WXPixmap
) 0;
236 // real construction (Init() must have been called before!)
237 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
241 const wxString
& name
)
243 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
245 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
247 parent
->AddChild(this);
249 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
250 m_foregroundColour
= *wxBLACK
;
252 //// TODO: we should probably optimize by only creating a
253 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
254 //// But for now, let's simplify things by always creating the
255 //// drawing area, since otherwise the translations are different.
257 // New translations for getting mouse motion feedback
258 static const String translations
=
259 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
260 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
261 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
262 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
263 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
264 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
265 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
266 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
267 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
268 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
269 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
270 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
271 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
272 <Key>: DrawingAreaInput()";
274 XtActionsRec actions
[1];
275 actions
[0].string
= "wxCanvasMotionEvent";
276 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
277 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
279 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
281 if (style
& wxSIMPLE_BORDER
)
283 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
286 xmFrameWidgetClass
, parentWidget
,
287 XmNshadowType
, XmSHADOW_IN
,
288 XmNshadowThickness
, 1,
291 } else if (style
& wxSUNKEN_BORDER
)
293 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
296 xmFrameWidgetClass
, parentWidget
,
297 XmNshadowType
, XmSHADOW_IN
,
300 } else if (style
& wxRAISED_BORDER
)
302 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
305 xmFrameWidgetClass
, parentWidget
,
306 XmNshadowType
, XmSHADOW_OUT
,
311 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
314 xmScrolledWindowWidgetClass
,
315 m_borderWidget
? (Widget
) m_borderWidget
317 XmNresizePolicy
, XmRESIZE_NONE
,
319 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
320 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
324 XtTranslations ptr
= XtParseTranslationTable(translations
);
325 m_drawingArea
= (WXWidget
)XtVaCreateWidget
328 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
329 XmNunitType
, XmPIXELS
,
330 // XmNresizePolicy, XmRESIZE_ANY,
331 XmNresizePolicy
, XmRESIZE_NONE
,
334 XmNtranslations
, ptr
,
337 XtFree((char *) ptr
);
340 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
342 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
343 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
344 XtFree ((char *) ptr
);
348 wxAddWindowToTable((Widget
) m_drawingArea
, this);
349 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
351 // This order is very important in Motif 1.2.1
352 XtRealizeWidget ((Widget
) m_scrolledWindow
);
353 XtRealizeWidget ((Widget
) m_drawingArea
);
354 XtManageChild ((Widget
) m_drawingArea
);
356 ptr
= XtParseTranslationTable("<Configure>: resize()");
357 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
358 XtFree ((char *) ptr
);
360 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
361 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
365 display
= XtDisplay (scrolledWindow
);
366 xwindow
= XtWindow (drawingArea
);
370 (Widget
)m_drawingArea
,
371 PointerMotionHintMask
| EnterWindowMask
|
372 LeaveWindowMask
| FocusChangeMask
,
374 (XtEventHandler
) wxCanvasEnterLeave
,
378 // Scrolled widget needs to have its colour changed or we get a little blue
379 // square where the scrollbars abutt
380 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
381 wxDoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
382 wxDoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
384 XmScrolledWindowSetAreas(
385 (Widget
)m_scrolledWindow
,
386 (Widget
) 0, (Widget
) 0,
387 (Widget
) m_drawingArea
);
391 XtRealizeWidget ((Widget
) m_hScrollBar
);
393 XtRealizeWidget ((Widget
) m_vScrollBar
);
396 // Without this, the cursor may not be restored properly (e.g. in splitter
398 SetCursor(*wxSTANDARD_CURSOR
);
399 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
400 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, TRUE
);
405 wxWindow::~wxWindow()
407 if (g_captureWindow
== this)
408 g_captureWindow
= NULL
;
410 m_isBeingDeleted
= TRUE
;
412 // Motif-specific actions first
413 WXWidget wMain
= GetMainWidget();
416 // Removes event handlers
423 m_parent
->RemoveChild( this );
425 // If m_drawingArea, we're a fully-fledged window with drawing area,
426 // scrollbars etc. (what wxCanvas used to be)
429 // Destroy children before destroying self
433 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
435 Widget w
= (Widget
) m_drawingArea
;
436 wxDeleteWindowFromTable(w
);
441 m_drawingArea
= (WXWidget
) 0;
444 // Only if we're _really_ a canvas (not a dialog box/panel)
445 if (m_scrolledWindow
)
447 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
452 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
453 XtUnmanageChild((Widget
) m_hScrollBar
);
457 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
458 XtUnmanageChild((Widget
) m_vScrollBar
);
462 XtDestroyWidget((Widget
) m_hScrollBar
);
464 XtDestroyWidget((Widget
) m_vScrollBar
);
466 UnmanageAndDestroy(m_scrolledWindow
);
470 XtDestroyWidget ((Widget
) m_borderWidget
);
471 m_borderWidget
= (WXWidget
) 0;
474 else // Why wasn't this here before? JACS 8/3/2000
478 // Destroy the window
481 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
482 // Child widgets will get destroyed automatically when a frame
483 // or dialog is destroyed, but before that you may get some memory
484 // leaks and potential layout problems if you delete and then add
487 // GRG, Feb/2000: commented this out when adding support for
488 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
489 // that this call crashed wxMotif under OS/2, so it seems
490 // that leaving it out is the right thing to do.
491 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
492 XtDestroyWidget((Widget
) GetMainWidget());
493 SetMainWidget((WXWidget
) NULL
);
497 // ----------------------------------------------------------------------------
498 // scrollbar management
499 // ----------------------------------------------------------------------------
502 void wxWindow::CreateScrollbar(wxOrientation orientation
)
504 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
506 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
508 // Add scrollbars if required
509 if (orientation
== wxHORIZONTAL
)
511 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
512 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
513 XmNorientation
, XmHORIZONTAL
,
515 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
516 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
517 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
518 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
519 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
520 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
521 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
522 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
524 XtVaSetValues (hScrollBar
,
529 m_hScrollBar
= (WXWidget
) hScrollBar
;
531 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
532 wxDoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
534 XtRealizeWidget(hScrollBar
);
536 XtVaSetValues((Widget
) m_scrolledWindow
,
537 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
540 wxAddWindowToTable( hScrollBar
, this );
543 if (orientation
== wxVERTICAL
)
545 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
546 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
547 XmNorientation
, XmVERTICAL
,
549 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
550 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
551 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
552 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
553 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
554 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
555 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
556 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
558 XtVaSetValues (vScrollBar
,
563 m_vScrollBar
= (WXWidget
) vScrollBar
;
564 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
565 wxDoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
567 XtRealizeWidget(vScrollBar
);
569 XtVaSetValues((Widget
) m_scrolledWindow
,
570 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
573 wxAddWindowToTable( vScrollBar
, this );
576 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
579 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
581 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
583 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
584 // Add scrollbars if required
585 if (orientation
== wxHORIZONTAL
)
589 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
590 XtDestroyWidget((Widget
) m_hScrollBar
);
592 m_hScrollBar
= (WXWidget
) 0;
594 XtVaSetValues((Widget
) m_scrolledWindow
,
595 XmNhorizontalScrollBar
, (Widget
) 0,
600 if (orientation
== wxVERTICAL
)
604 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
605 XtDestroyWidget((Widget
) m_vScrollBar
);
607 m_vScrollBar
= (WXWidget
) 0;
609 XtVaSetValues((Widget
) m_scrolledWindow
,
610 XmNverticalScrollBar
, (Widget
) 0,
614 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
617 // ---------------------------------------------------------------------------
619 // ---------------------------------------------------------------------------
621 void wxWindow::SetFocus()
623 Widget wMain
= (Widget
) GetMainWidget();
624 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
625 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
628 // Get the window with the focus
629 wxWindow
*wxWindowBase::FindFocus()
632 // (1) Can there be multiple focussed widgets in an application?
633 // In which case we need to find the top-level window that's
635 // (2) The widget with the focus may not be in the widget table
636 // depending on which widgets I put in the table
637 wxWindow
*winFocus
= (wxWindow
*)NULL
;
638 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
640 node
= node
->GetNext() )
642 wxWindow
*win
= node
->GetData();
644 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
646 if (w
!= (Widget
) NULL
)
648 winFocus
= wxGetWindowFromTable(w
);
657 bool wxWindow::Enable(bool enable
)
659 if ( !wxWindowBase::Enable(enable
) )
662 Widget wMain
= (Widget
)GetMainWidget();
665 XtSetSensitive(wMain
, enable
);
666 XmUpdateDisplay(wMain
);
672 bool wxWindow::Show(bool show
)
674 if ( !wxWindowBase::Show(show
) )
677 if (m_borderWidget
|| m_scrolledWindow
)
679 MapOrUnmap(m_drawingArea
, show
);
680 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
684 if ( !MapOrUnmap(GetTopWidget(), show
) )
685 MapOrUnmap(GetMainWidget(), show
);
691 // Raise the window to the top of the Z order
692 void wxWindow::Raise()
694 Widget wTop
= (Widget
) GetTopWidget();
695 Window window
= XtWindow(wTop
);
696 XRaiseWindow(XtDisplay(wTop
), window
);
699 // Lower the window to the bottom of the Z order
700 void wxWindow::Lower()
702 Widget wTop
= (Widget
) GetTopWidget();
703 Window window
= XtWindow(wTop
);
704 XLowerWindow(XtDisplay(wTop
), window
);
707 void wxWindow::SetTitle(const wxString
& title
)
709 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
712 wxString
wxWindow::GetTitle() const
715 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
717 return wxString(title
);
720 void wxWindow::DoCaptureMouse()
722 g_captureWindow
= this;
726 Widget wMain
= (Widget
)GetMainWidget();
728 XtAddGrab(wMain
, TRUE
, FALSE
);
730 m_winCaptured
= TRUE
;
733 void wxWindow::DoReleaseMouse()
735 g_captureWindow
= NULL
;
736 if ( !m_winCaptured
)
739 Widget wMain
= (Widget
)GetMainWidget();
743 m_winCaptured
= FALSE
;
746 bool wxWindow::SetFont(const wxFont
& font
)
748 if ( !wxWindowBase::SetFont(font
) )
759 bool wxWindow::SetCursor(const wxCursor
& cursor
)
761 if ( !wxWindowBase::SetCursor(cursor
) )
767 // wxASSERT_MSG( m_cursor.Ok(),
768 // wxT("cursor must be valid after call to the base version"));
769 wxCursor
* cursor2
= NULL
;
771 cursor2
= & m_cursor
;
773 cursor2
= wxSTANDARD_CURSOR
;
775 WXDisplay
*dpy
= GetXDisplay();
776 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
778 Widget w
= (Widget
) GetMainWidget();
779 Window win
= XtWindow(w
);
780 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
785 // Coordinates relative to the window
786 void wxWindow::WarpPointer (int x
, int y
)
788 Widget wClient
= (Widget
)GetClientWidget();
790 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
793 // ---------------------------------------------------------------------------
795 // ---------------------------------------------------------------------------
797 int wxWindow::GetScrollPos(int orient
) const
799 if (orient
== wxHORIZONTAL
)
805 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
809 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
817 // This now returns the whole range, not just the number of positions that we
819 int wxWindow::GetScrollRange(int orient
) const
821 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
822 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
826 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
830 int wxWindow::GetScrollThumb(int orient
) const
832 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
833 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
836 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
840 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
842 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
846 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
849 SetInternalScrollPos((wxOrientation
)orient
, pos
);
852 // New function that will replace some of the above.
853 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
854 int range
, bool WXUNUSED(refresh
))
857 GetSize(& oldW
, & oldH
);
861 if (thumbVisible
== 0)
864 if (thumbVisible
> range
)
865 thumbVisible
= range
;
867 // Save the old state to see if it changed
868 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
870 if (orient
== wxHORIZONTAL
)
872 if (thumbVisible
== range
)
875 DestroyScrollbar(wxHORIZONTAL
);
880 CreateScrollbar(wxHORIZONTAL
);
883 if (orient
== wxVERTICAL
)
885 if (thumbVisible
== range
)
888 DestroyScrollbar(wxVERTICAL
);
893 CreateScrollbar(wxVERTICAL
);
896 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
898 if (oldScrollBar
!= newScrollBar
)
900 // This is important! Without it, scrollbars misbehave badly.
901 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
902 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
903 XtRealizeWidget((Widget
) m_scrolledWindow
);
904 XtManageChild((Widget
) m_scrolledWindow
);
909 XtVaSetValues((Widget
) newScrollBar
,
913 XmNsliderSize
, thumbVisible
,
917 SetInternalScrollPos((wxOrientation
)orient
, pos
);
920 GetSize(& newW
, & newH
);
922 // Adjusting scrollbars can resize the canvas accidentally
923 if (newW
!= oldW
|| newH
!= oldH
)
924 SetSize(-1, -1, oldW
, oldH
);
927 // Does a physical scroll
928 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
933 // Use specified rectangle
934 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
938 // Use whole client area
940 GetClientSize(& w
, & h
);
943 int x1
= (dx
>= 0) ? x
: x
- dx
;
944 int y1
= (dy
>= 0) ? y
: y
- dy
;
945 int w1
= w
- abs(dx
);
946 int h1
= h
- abs(dy
);
947 int x2
= (dx
>= 0) ? x
+ dx
: x
;
948 int y2
= (dy
>= 0) ? y
+ dy
: y
;
952 dc
.SetLogicalFunction (wxCOPY
);
954 Widget widget
= (Widget
) GetMainWidget();
955 Window window
= XtWindow(widget
);
956 Display
* display
= XtDisplay(widget
);
958 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
959 x1
, y1
, w1
, h1
, x2
, y2
);
961 dc
.SetAutoSetting(TRUE
);
962 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
963 dc
.SetBrush(brush
); // FIXME: needed?
965 wxWindowList::Node
*cnode
= m_children
.GetFirst();
968 wxWindow
*child
= cnode
->GetData();
971 child
->GetSize( &sx
, &sy
);
972 wxPoint
pos( child
->GetPosition() );
973 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
974 cnode
= cnode
->GetNext();
977 // We'll add rectangles to the list of update rectangles according to which
978 // bits we've exposed.
983 wxRect
*rect
= new wxRect
;
989 XFillRectangle(display
, window
,
990 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
994 rect
->width
= rect
->width
;
995 rect
->height
= rect
->height
;
997 updateRects
.Append((wxObject
*) rect
);
1001 wxRect
*rect
= new wxRect
;
1003 rect
->x
= x
+ w
+ dx
;
1008 XFillRectangle(display
, window
,
1009 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1014 rect
->width
= rect
->width
;
1015 rect
->height
= rect
->height
;
1017 updateRects
.Append((wxObject
*) rect
);
1021 wxRect
*rect
= new wxRect
;
1028 XFillRectangle(display
, window
,
1029 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1033 rect
->width
= rect
->width
;
1034 rect
->height
= rect
->height
;
1036 updateRects
.Append((wxObject
*) rect
);
1040 wxRect
*rect
= new wxRect
;
1043 rect
->y
= y
+ h
+ dy
;
1047 XFillRectangle(display
, window
,
1048 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1052 rect
->width
= rect
->width
;
1053 rect
->height
= rect
->height
;
1055 updateRects
.Append((wxObject
*) rect
);
1057 dc
.SetBrush(wxNullBrush
);
1059 // Now send expose events
1061 wxList::Node
* node
= updateRects
.GetFirst();
1064 wxRect
* rect
= (wxRect
*) node
->GetData();
1067 event
.type
= Expose
;
1068 event
.display
= display
;
1069 event
.send_event
= True
;
1070 event
.window
= window
;
1074 event
.width
= rect
->width
;
1075 event
.height
= rect
->height
;
1079 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1081 node
= node
->GetNext();
1085 // Delete the update rects
1086 node
= updateRects
.GetFirst();
1089 wxRect
* rect
= (wxRect
*) node
->GetData();
1091 node
= node
->GetNext();
1094 XmUpdateDisplay((Widget
) GetMainWidget());
1097 // ---------------------------------------------------------------------------
1099 // ---------------------------------------------------------------------------
1101 #if wxUSE_DRAG_AND_DROP
1103 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1110 // Old style file-manager drag&drop
1111 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1116 // ----------------------------------------------------------------------------
1118 // ----------------------------------------------------------------------------
1122 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1127 #endif // wxUSE_TOOLTIPS
1129 // ----------------------------------------------------------------------------
1131 // ----------------------------------------------------------------------------
1135 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1137 Widget widget
= (Widget
) GetMainWidget();
1139 /* The menuId field seems to be usused, so we'll use it to
1140 indicate whether a menu is popped up or not:
1141 0: Not currently created as a popup
1142 -1: Created as a popup, but not active
1146 if (menu
->GetParent() && (menu
->GetId() != -1))
1149 if (menu
->GetMainWidget())
1151 menu
->DestroyMenu(TRUE
);
1154 menu
->SetId(1); /* Mark as popped-up */
1155 menu
->CreateMenu(NULL
, widget
, menu
);
1156 menu
->SetInvokingWindow(this);
1160 // menu->SetParent(parent);
1161 // parent->children->Append(menu); // Store menu for later deletion
1163 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1171 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1173 wxCanvas *canvas = (wxCanvas *) this;
1174 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1175 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1179 Display
*display
= XtDisplay (widget
);
1180 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1181 Window thisWindow
= XtWindow (widget
);
1183 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1184 &rootX
, &rootY
, &childWindow
);
1186 XButtonPressedEvent event
;
1187 event
.type
= ButtonPress
;
1193 event
.x_root
= rootX
;
1194 event
.y_root
= rootY
;
1196 XmMenuPosition (menuWidget
, &event
);
1197 XtManageChild (menuWidget
);
1199 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1200 // idle-time destroy routine.
1201 // Waiting until this ID changes causes this function to block until
1202 // the menu has been dismissed and the widgets cleaned up.
1203 // In other words, once this routine returns, it is safe to delete
1205 // Ian Brown <ian.brown@printsoft.de>
1207 wxEventLoop evtLoop
;
1209 while (menu
->GetId() == 1)
1211 wxDoEventLoopIteration( evtLoop
);
1219 // ---------------------------------------------------------------------------
1220 // moving and resizing
1221 // ---------------------------------------------------------------------------
1223 bool wxWindow::PreResize()
1229 void wxWindow::DoGetSize(int *x
, int *y
) const
1231 Widget widget
= (Widget
)( !m_drawingArea
? GetTopWidget() :
1232 ( m_borderWidget
? m_borderWidget
:
1233 m_scrolledWindow
? m_scrolledWindow
:
1237 XtVaGetValues( widget
,
1245 void wxWindow::DoGetPosition(int *x
, int *y
) const
1247 Widget widget
= (Widget
)
1249 ( m_borderWidget
? m_borderWidget
: m_scrolledWindow
) :
1253 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1255 // We may be faking the client origin. So a window that's really at (0, 30)
1256 // may appear (to wxWin apps) to be at (0, 0).
1259 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1268 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1270 Widget widget
= (Widget
) GetClientWidget();
1271 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1272 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1273 Window thisWindow
= XtWindow(widget
);
1278 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1281 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1283 Widget widget
= (Widget
) GetClientWidget();
1284 Display
*display
= XtDisplay(widget
);
1285 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1286 Window thisWindow
= XtWindow(widget
);
1291 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1295 // Get size *available for subwindows* i.e. excluding menu bar etc.
1296 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1298 Widget widget
= (Widget
) GetClientWidget();
1300 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1301 if(x
) *x
= xx
; if(y
) *y
= yy
;
1304 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1306 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, FALSE
);
1309 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1310 int sizeFlags
, bool fromCtor
)
1312 // A bit of optimization to help sort out the flickers.
1313 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1316 GetSize(& oldW
, & oldH
);
1317 GetPosition(& oldX
, & oldY
);
1320 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1328 wxSize
size(-1, -1);
1331 if ( ( sizeFlags
& wxSIZE_AUTO_WIDTH
) && !fromCtor
)
1333 size
= DoGetBestSize();
1344 if( ( sizeFlags
& wxSIZE_AUTO_HEIGHT
) && !fromCtor
)
1346 if( size
.x
== -1 ) size
= DoGetBestSize();
1355 if ( x
!= oldX
|| y
!= oldY
|| width
!= oldW
|| height
!= oldH
1356 || !wxNoOptimize::CanOptimize() )
1362 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1365 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1369 flags
|= wxMOVE_WIDTH
;
1372 flags
|= wxMOVE_HEIGHT
;
1374 int xx
= x
; int yy
= y
;
1375 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1377 DoMoveWindow( xx
, yy
, width
, height
);
1379 DoMoveWindowIntr( xx
, yy
, width
, height
, flags
);
1384 Widget widget
= (Widget
) GetTopWidget();
1388 bool managed
= XtIsManaged( widget
);
1390 XtUnmanageChild(widget
);
1394 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1396 DoMoveWindow(xx
, yy
, width
, height
);
1399 XtManageChild(widget
);
1403 void wxWindow::DoSetClientSize(int width
, int height
)
1407 Widget drawingArea
= (Widget
) m_drawingArea
;
1409 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1412 XtVaSetValues(drawingArea
, XmNwidth
, width
, NULL
);
1414 XtVaSetValues(drawingArea
, XmNheight
, height
, NULL
);
1416 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1420 Widget widget
= (Widget
) GetTopWidget();
1423 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1425 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1428 // For implementation purposes - sometimes decorations make the client area
1430 wxPoint
wxWindow::GetClientAreaOrigin() const
1432 return wxPoint(0, 0);
1435 void wxWindow::DoMoveWindowIntr(int xx
, int yy
, int w
, int h
,
1440 Widget drawingArea
= (Widget
) m_drawingArea
;
1441 Widget borderOrScrolled
= m_borderWidget
?
1442 (Widget
) m_borderWidget
:
1443 (Widget
) m_scrolledWindow
;
1445 bool managed
= XtIsManaged(borderOrScrolled
);
1447 XtUnmanageChild (borderOrScrolled
);
1448 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
1450 if (flags
& wxMOVE_X
)
1451 XtVaSetValues (borderOrScrolled
,
1454 if (flags
& wxMOVE_Y
)
1455 XtVaSetValues (borderOrScrolled
,
1459 if (flags
& wxMOVE_WIDTH
)
1463 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
1464 short thick
, margin
;
1465 XtVaGetValues ((Widget
) m_borderWidget
,
1466 XmNshadowThickness
, &thick
,
1467 XmNmarginWidth
, &margin
,
1469 w
-= 2 * (thick
+ margin
);
1472 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
1475 if (flags
& wxMOVE_HEIGHT
)
1479 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
1480 short thick
, margin
;
1481 XtVaGetValues ((Widget
) m_borderWidget
,
1482 XmNshadowThickness
, &thick
,
1483 XmNmarginHeight
, &margin
,
1485 h
-= 2 * (thick
+ margin
);
1488 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
1492 XtManageChild (borderOrScrolled
);
1493 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
1500 XtVaSetValues((Widget
)GetTopWidget(),
1509 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1511 DoMoveWindowIntr (x
, y
, width
, height
,
1512 wxMOVE_X
|wxMOVE_Y
|wxMOVE_WIDTH
|wxMOVE_HEIGHT
);
1515 // ---------------------------------------------------------------------------
1517 // ---------------------------------------------------------------------------
1519 int wxWindow::GetCharHeight() const
1521 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1523 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1525 int direction
, ascent
, descent
;
1526 XCharStruct overall
;
1527 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1528 &descent
, &overall
);
1530 // return (overall.ascent + overall.descent);
1531 return (ascent
+ descent
);
1534 int wxWindow::GetCharWidth() const
1536 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1538 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1540 int direction
, ascent
, descent
;
1541 XCharStruct overall
;
1542 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1543 &descent
, &overall
);
1545 return overall
.width
;
1548 void wxWindow::GetTextExtent(const wxString
& string
,
1550 int *descent
, int *externalLeading
,
1551 const wxFont
*theFont
) const
1553 wxFont
*fontToUse
= (wxFont
*)theFont
;
1555 fontToUse
= (wxFont
*) & m_font
;
1557 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1559 WXFontStructPtr pFontStruct
= fontToUse
->GetFontStruct(1.0, GetXDisplay());
1561 int direction
, ascent
, descent2
;
1562 XCharStruct overall
;
1563 int slen
= string
.Len();
1567 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1568 &ascent
, &descent2
, &overall
);
1571 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1572 &direction
, &ascent
, &descent2
, &overall
);
1575 *x
= (overall
.width
);
1577 *y
= (ascent
+ descent2
);
1579 *descent
= descent2
;
1580 if (externalLeading
)
1581 *externalLeading
= 0;
1585 // ----------------------------------------------------------------------------
1587 // ----------------------------------------------------------------------------
1589 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1591 m_needsRefresh
= TRUE
;
1592 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1593 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1595 XExposeEvent dummyEvent
;
1597 GetSize(&width
, &height
);
1599 dummyEvent
.type
= Expose
;
1600 dummyEvent
.display
= display
;
1601 dummyEvent
.send_event
= True
;
1602 dummyEvent
.window
= thisWindow
;
1605 dummyEvent
.x
= rect
->x
;
1606 dummyEvent
.y
= rect
->y
;
1607 dummyEvent
.width
= rect
->width
;
1608 dummyEvent
.height
= rect
->height
;
1614 dummyEvent
.width
= width
;
1615 dummyEvent
.height
= height
;
1617 dummyEvent
.count
= 0;
1621 wxClientDC
dc(this);
1622 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1623 dc
.SetBackground(backgroundBrush
);
1630 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1633 void wxWindow::Clear()
1635 wxClientDC
dc(this);
1636 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1637 dc
.SetBackground(brush
);
1641 void wxWindow::ClearUpdateRects()
1643 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1646 wxRect
* rect
= node
->GetData();
1648 node
= node
->GetNext();
1651 m_updateRects
.Clear();
1654 void wxWindow::DoPaint()
1656 //TODO : make a temporary gc so we can do the XCopyArea below
1657 if (m_backingPixmap
&& !m_needsRefresh
)
1661 GC tempGC
= (GC
) dc
.GetBackingGC();
1663 Widget widget
= (Widget
) GetMainWidget();
1668 // We have to test whether it's a wxScrolledWindow (hack!) because
1669 // otherwise we don't know how many pixels have been scrolled. We might
1670 // solve this in the future by defining virtual wxWindow functions to get
1671 // the scroll position in pixels. Or, each kind of scrolled window has to
1672 // implement backing stores itself, using generic wxWindows code.
1673 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1674 if ( scrolledWindow
)
1677 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1683 // TODO: This could be optimized further by only copying the areas in the
1684 // current update region.
1686 // Only blit the part visible in the client area. The backing pixmap
1687 // always starts at 0, 0 but we may be looking at only a portion of it.
1688 wxSize clientArea
= GetClientSize();
1689 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1690 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1692 // Copy whichever is samller, the amount of pixmap we have to copy,
1693 // or the size of the client area.
1694 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1695 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1697 // Make sure we're not negative
1698 toBlitX
= wxMax(0, toBlitX
);
1699 toBlitY
= wxMax(0, toBlitY
);
1704 (Pixmap
) m_backingPixmap
,
1707 scrollPosX
, scrollPosY
, // Start at the scroll position
1708 toBlitX
, toBlitY
, // How much of the pixmap to copy
1714 wxWindowDC
dc(this);
1715 // Set an erase event first
1716 wxEraseEvent
eraseEvent(GetId(), &dc
);
1717 eraseEvent
.SetEventObject(this);
1718 GetEventHandler()->ProcessEvent(eraseEvent
);
1720 wxPaintEvent
event(GetId());
1721 event
.SetEventObject(this);
1722 GetEventHandler()->ProcessEvent(event
);
1724 m_needsRefresh
= FALSE
;
1728 // ----------------------------------------------------------------------------
1730 // ----------------------------------------------------------------------------
1732 // Responds to colour changes: passes event on to children.
1733 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1735 wxWindowList::Node
*node
= GetChildren().GetFirst();
1738 // Only propagate to non-top-level windows
1739 wxWindow
*win
= node
->GetData();
1740 if ( win
->GetParent() )
1742 wxSysColourChangedEvent event2
;
1743 event
.m_eventObject
= win
;
1744 win
->GetEventHandler()->ProcessEvent(event2
);
1747 node
= node
->GetNext();
1751 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1753 // This calls the UI-update mechanism (querying windows for
1754 // menu/toolbar/control state information)
1758 // ----------------------------------------------------------------------------
1760 // ----------------------------------------------------------------------------
1762 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1765 if (!m_acceleratorTable
.Ok())
1768 int count
= m_acceleratorTable
.GetCount();
1769 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1771 for (i
= 0; i
< count
; i
++)
1773 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1774 if (entry
->MatchesEvent(event
))
1776 // Bingo, we have a match. Now find a control that matches the
1777 // entry command id.
1779 // Need to go up to the top of the window hierarchy, since it might
1780 // be e.g. a menu item
1781 wxWindow
* parent
= this;
1782 while ( parent
&& !parent
->IsTopLevel() )
1783 parent
= parent
->GetParent();
1788 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1792 // Try for a menu command
1793 if (frame
->GetMenuBar())
1795 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1798 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1799 commandEvent
.SetEventObject(frame
);
1801 // If ProcessEvent returns TRUE (it was handled), then
1802 // the calling code will skip the event handling.
1803 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1809 // Find a child matching the command id
1810 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1816 // Now we process those kinds of windows that we can.
1817 // For now, only buttons.
1818 if ( wxDynamicCast(child
, wxButton
) )
1820 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1821 commandEvent
.SetEventObject(child
);
1822 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1830 // We didn't match the key event against an accelerator.
1834 // ============================================================================
1835 // Motif-specific stuff from here on
1836 // ============================================================================
1838 // ----------------------------------------------------------------------------
1839 // function which maintain the global hash table mapping Widgets to wxWindows
1840 // ----------------------------------------------------------------------------
1842 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1844 wxWindow
*oldItem
= NULL
;
1845 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1847 wxLogDebug("Widget table clash: new widget is %ld, %s",
1848 (long)w
, win
->GetClassInfo()->GetClassName());
1852 wxWidgetHashTable
->Put((long) w
, win
);
1854 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1855 (WXWidget
)w
, win
, win
->GetClassInfo()->GetClassName());
1860 wxWindow
*wxGetWindowFromTable(Widget w
)
1862 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1865 void wxDeleteWindowFromTable(Widget w
)
1867 wxLogTrace("widget", "Widget 0x%p", (WXWidget
)w
);
1869 wxWidgetHashTable
->Delete((long)w
);
1872 // ----------------------------------------------------------------------------
1873 // add/remove window from the table
1874 // ----------------------------------------------------------------------------
1876 // Add to hash table, add event handler
1877 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1878 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1880 wxAddWindowToTable((Widget
) mainWidget
, this);
1881 XtAddEventHandler( (Widget
) mainWidget
,
1882 ButtonPressMask
| ButtonReleaseMask
1883 | PointerMotionMask
,
1885 wxPanelItemEventHandler
,
1891 XtOverrideTranslations ((Widget
) mainWidget
,
1892 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1893 XtFree ((char *) ptr
);
1896 // Some widgets have a parent form widget, e.g. wxRadioBox
1899 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1903 XtOverrideTranslations ((Widget
) formWidget
,
1904 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1905 XtFree ((char *) ptr
);
1912 SetSize (x
, y
, width
, height
);
1917 // Remove event handler, remove from hash table
1918 bool wxWindow::DetachWidget(WXWidget widget
)
1920 XtRemoveEventHandler( (Widget
) widget
,
1921 ButtonPressMask
| ButtonReleaseMask
1922 | PointerMotionMask
,
1924 wxPanelItemEventHandler
,
1927 wxDeleteWindowFromTable((Widget
) widget
);
1931 // ----------------------------------------------------------------------------
1932 // Motif-specific accessors
1933 // ----------------------------------------------------------------------------
1935 // Get the underlying X window
1936 WXWindow
wxWindow::GetXWindow() const
1938 Widget wMain
= (Widget
)GetMainWidget();
1940 return (WXWindow
) XtWindow(wMain
);
1942 return (WXWindow
) 0;
1945 // Get the underlying X display
1946 WXDisplay
*wxWindow::GetXDisplay() const
1948 Widget wMain
= (Widget
)GetMainWidget();
1950 return (WXDisplay
*) XtDisplay(wMain
);
1952 return (WXDisplay
*) NULL
;
1955 WXWidget
wxWindow::GetMainWidget() const
1958 return m_drawingArea
;
1960 return m_mainWidget
;
1963 WXWidget
wxWindow::GetClientWidget() const
1965 if (m_drawingArea
!= (WXWidget
) 0)
1966 return m_drawingArea
;
1968 return GetMainWidget();
1971 WXWidget
wxWindow::GetTopWidget() const
1973 return GetMainWidget();
1976 WXWidget
wxWindow::GetLabelWidget() const
1978 return GetMainWidget();
1981 // ----------------------------------------------------------------------------
1983 // ----------------------------------------------------------------------------
1985 // All widgets should have this as their resize proc.
1986 // OnSize sent to wxWindow via client data.
1987 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
),
1988 String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1990 wxWindow
*win
= wxGetWindowFromTable(w
);
1994 if (win
->PreResize())
1997 win
->GetSize(&width
, &height
);
1998 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1999 sizeEvent
.SetEventObject(win
);
2000 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2004 static void wxCanvasRepaintProc(Widget drawingArea
,
2005 XtPointer clientData
,
2006 XmDrawingAreaCallbackStruct
* cbs
)
2008 if (!wxGetWindowFromTable(drawingArea
))
2011 XEvent
* event
= cbs
->event
;
2012 wxWindow
* win
= (wxWindow
*) clientData
;
2014 switch (event
->type
)
2018 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2019 event
->xexpose
.width
, event
->xexpose
.height
);
2021 if (event
-> xexpose
.count
== 0)
2024 win
->ClearUpdateRects();
2031 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2032 static void wxCanvasEnterLeave(Widget drawingArea
,
2033 XtPointer
WXUNUSED(clientData
),
2034 XCrossingEvent
* event
)
2036 XmDrawingAreaCallbackStruct cbs
;
2039 ((XCrossingEvent
&) ev
) = *event
;
2041 cbs
.reason
= XmCR_INPUT
;
2044 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
2047 // Fix to make it work under Motif 1.0 (!)
2048 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
),
2049 XButtonEvent
*WXUNUSED(event
))
2051 #if XmVersion <= 1000
2052 XmDrawingAreaCallbackStruct cbs
;
2055 ev
= *((XEvent
*) event
);
2056 cbs
.reason
= XmCR_INPUT
;
2059 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2060 #endif // XmVersion <= 1000
2063 static void wxCanvasInputEvent(Widget drawingArea
,
2064 XtPointer
WXUNUSED(data
),
2065 XmDrawingAreaCallbackStruct
* cbs
)
2067 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
2073 if (cbs
->reason
!= XmCR_INPUT
)
2076 local_event
= *(cbs
->event
); // We must keep a copy!
2078 switch (local_event
.xany
.type
)
2086 wxMouseEvent wxevent
;
2087 if(wxTranslateMouseEvent(wxevent
, canvas
, drawingArea
, &local_event
))
2089 canvas
->GetEventHandler()->ProcessEvent(wxevent
);
2095 wxKeyEvent
event (wxEVT_CHAR
);
2096 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2098 // Implement wxFrame::OnCharHook by checking ancestor.
2099 wxWindow
*parent
= canvas
;
2100 while (parent
&& !parent
->IsTopLevel())
2101 parent
= parent
->GetParent();
2105 event
.SetEventType(wxEVT_CHAR_HOOK
);
2106 if (parent
->GetEventHandler()->ProcessEvent(event
))
2110 // For simplicity, OnKeyDown is the same as OnChar
2111 // TODO: filter modifier key presses from OnChar
2112 event
.SetEventType(wxEVT_KEY_DOWN
);
2114 // Only process OnChar if OnKeyDown didn't swallow it
2115 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2117 event
.SetEventType(wxEVT_CHAR
);
2118 canvas
->GetEventHandler()->ProcessEvent (event
);
2125 wxKeyEvent
event (wxEVT_KEY_UP
);
2126 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2128 canvas
->GetEventHandler()->ProcessEvent (event
);
2134 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2136 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2137 event
.SetEventObject(canvas
);
2138 canvas
->GetEventHandler()->ProcessEvent(event
);
2144 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2146 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2147 event
.SetEventObject(canvas
);
2148 canvas
->GetEventHandler()->ProcessEvent(event
);
2157 static void wxPanelItemEventHandler(Widget wid
,
2158 XtPointer
WXUNUSED(client_data
),
2160 Boolean
*continueToDispatch
)
2162 // Widget can be a label or the actual widget.
2164 wxWindow
*window
= wxGetWindowFromTable(wid
);
2167 wxMouseEvent
wxevent(0);
2168 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2170 window
->GetEventHandler()->ProcessEvent(wxevent
);
2174 // TODO: probably the key to allowing default behaviour to happen. Say we
2175 // set a m_doDefault flag to FALSE at the start of this function. Then in
2176 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2177 // TRUE, indicating that default processing can happen. Thus, behaviour can
2178 // appear to be overridden just by adding an event handler and not calling
2179 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2180 // way of handling drawing area events, to simplify things.
2181 *continueToDispatch
= True
;
2184 static void wxScrollBarCallback(Widget scrollbar
,
2185 XtPointer clientData
,
2186 XmScrollBarCallbackStruct
*cbs
)
2188 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2189 int orientation
= (int) clientData
;
2191 wxEventType eventType
= wxEVT_NULL
;
2192 switch (cbs
->reason
)
2194 case XmCR_INCREMENT
:
2196 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2199 case XmCR_DECREMENT
:
2201 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2206 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2209 case XmCR_VALUE_CHANGED
:
2211 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2214 case XmCR_PAGE_INCREMENT
:
2216 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2219 case XmCR_PAGE_DECREMENT
:
2221 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2226 eventType
= wxEVT_SCROLLWIN_TOP
;
2229 case XmCR_TO_BOTTOM
:
2231 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2236 // Should never get here
2237 wxFAIL_MSG("Unknown scroll event.");
2242 wxScrollWinEvent
event(eventType
,
2244 ((orientation
== XmHORIZONTAL
) ?
2245 wxHORIZONTAL
: wxVERTICAL
));
2246 event
.SetEventObject( win
);
2247 win
->GetEventHandler()->ProcessEvent(event
);
2250 // For repainting arbitrary windows
2251 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2256 wxWindow
* win
= wxGetWindowFromTable(w
);
2260 switch(event
-> type
)
2264 window
= (Window
) win
-> GetXWindow();
2265 display
= (Display
*) win
-> GetXDisplay();
2267 if (event
-> xexpose
.count
== 0)
2271 win
->ClearUpdateRects();
2275 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2276 event
->xexpose
.width
, event
->xexpose
.height
);
2284 // ----------------------------------------------------------------------------
2285 // TranslateXXXEvent() functions
2286 // ----------------------------------------------------------------------------
2288 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
,
2289 Widget widget
, XEvent
*xevent
)
2291 switch (xevent
->xany
.type
)
2296 fprintf(stderr
, "Widget 0x%p <-> window %p (%s), %s\n",
2297 (WXWidget
)widget
, win
, win
->GetClassInfo()->GetClassName(),
2298 (xevent
->xany
.type
== EnterNotify
? "ENTER" : "LEAVE"));
2304 wxEventType eventType
= wxEVT_NULL
;
2306 if (xevent
->xany
.type
== LeaveNotify
)
2308 eventType
= wxEVT_LEAVE_WINDOW
;
2310 if (xevent
->xany
.type
== EnterNotify
)
2312 eventType
= wxEVT_ENTER_WINDOW
;
2314 else if (xevent
->xany
.type
== MotionNotify
)
2316 eventType
= wxEVT_MOTION
;
2318 else if (xevent
->xany
.type
== ButtonPress
)
2320 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2322 if (xevent
->xbutton
.button
== Button1
)
2324 eventType
= wxEVT_LEFT_DOWN
;
2327 else if (xevent
->xbutton
.button
== Button2
)
2329 eventType
= wxEVT_MIDDLE_DOWN
;
2332 else if (xevent
->xbutton
.button
== Button3
)
2334 eventType
= wxEVT_RIGHT_DOWN
;
2338 // check for a double click
2340 long dclickTime
= XtGetMultiClickTime(xevent
->xany
.display
);
2341 long ts
= wxevent
.GetTimestamp();
2343 int buttonLast
= win
->GetLastClickedButton();
2344 long lastTS
= win
->GetLastClickTime();
2345 if ( buttonLast
&& buttonLast
== button
&&
2346 (ts
- lastTS
) < dclickTime
)
2349 win
->SetLastClick(0, ts
);
2350 if ( eventType
== wxEVT_LEFT_DOWN
)
2351 eventType
= wxEVT_LEFT_DCLICK
;
2352 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2353 eventType
= wxEVT_MIDDLE_DCLICK
;
2354 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2355 eventType
= wxEVT_RIGHT_DCLICK
;
2359 // not fast enough or different button
2360 win
->SetLastClick(button
, ts
);
2363 else if (xevent
->xany
.type
== ButtonRelease
)
2365 if (xevent
->xbutton
.button
== Button1
)
2367 eventType
= wxEVT_LEFT_UP
;
2369 else if (xevent
->xbutton
.button
== Button2
)
2371 eventType
= wxEVT_MIDDLE_UP
;
2373 else if (xevent
->xbutton
.button
== Button3
)
2375 eventType
= wxEVT_RIGHT_UP
;
2385 wxevent
.SetEventType(eventType
);
2388 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2391 win
->GetPosition(&x2
, &y2
);
2393 // The button x/y must be translated to wxWindows
2394 // window space - the widget might be a label or button,
2398 if (widget
!= (Widget
)win
->GetMainWidget())
2404 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2405 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2407 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2408 || (event_left_is_down (xevent
)
2409 && (eventType
!= wxEVT_LEFT_UP
)));
2410 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2411 || (event_middle_is_down (xevent
)
2412 && (eventType
!= wxEVT_MIDDLE_UP
)));
2413 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2414 || (event_right_is_down (xevent
)
2415 && (eventType
!= wxEVT_RIGHT_UP
)));
2417 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2418 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2419 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2420 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2422 wxevent
.SetId(win
->GetId());
2423 wxevent
.SetEventObject(win
);
2431 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
,
2432 Widget
WXUNUSED(widget
), XEvent
*xevent
)
2434 switch (xevent
->xany
.type
)
2442 (void) XLookupString((XKeyEvent
*)xevent
, buf
, 20, &keySym
, NULL
);
2443 int id
= wxCharCodeXToWX (keySym
);
2444 // id may be WXK_xxx code - these are outside ASCII range, so we
2445 // can't just use toupper() on id
2446 if (id
>= 'a' && id
<= 'z')
2449 if (xevent
->xkey
.state
& ShiftMask
)
2450 wxevent
.m_shiftDown
= TRUE
;
2451 if (xevent
->xkey
.state
& ControlMask
)
2452 wxevent
.m_controlDown
= TRUE
;
2453 if (xevent
->xkey
.state
& Mod3Mask
)
2454 wxevent
.m_altDown
= TRUE
;
2455 if (xevent
->xkey
.state
& Mod1Mask
)
2456 wxevent
.m_metaDown
= TRUE
;
2457 wxevent
.SetEventObject(win
);
2458 wxevent
.m_keyCode
= id
;
2459 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2461 wxevent
.m_x
= xevent
->xbutton
.x
;
2462 wxevent
.m_y
= xevent
->xbutton
.y
;
2476 // ----------------------------------------------------------------------------
2478 // ----------------------------------------------------------------------------
2480 #define YAllocColor XAllocColor
2481 XColor g_itemColors
[5];
2482 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2485 static XmColorProc colorProc
;
2487 result
= wxNO_COLORS
;
2491 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2492 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2493 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2494 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2495 if (colorProc
== (XmColorProc
) NULL
)
2497 // Get a ptr to the actual function
2498 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2499 // And set it back to motif.
2500 XmSetColorCalculation (colorProc
);
2502 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2503 &g_itemColors
[wxFORE_INDEX
],
2504 &g_itemColors
[wxSELE_INDEX
],
2505 &g_itemColors
[wxTOPS_INDEX
],
2506 &g_itemColors
[wxBOTS_INDEX
]);
2507 result
= wxBACK_COLORS
;
2511 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2512 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2513 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2514 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2515 if (result
== wxNO_COLORS
)
2516 result
= wxFORE_COLORS
;
2519 Display
*dpy
= display
;
2520 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2524 /* 5 Colours to allocate */
2525 for (int i
= 0; i
< 5; i
++)
2526 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2527 result
= wxNO_COLORS
;
2531 /* Only 1 colour to allocate */
2532 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2533 result
= wxNO_COLORS
;
2539 // Changes the foreground and background colours to be derived from the current
2540 // background colour. To change the foreground colour, you must call
2541 // SetForegroundColour explicitly.
2542 void wxWindow::ChangeBackgroundColour()
2544 WXWidget mainWidget
= GetMainWidget();
2546 wxDoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2549 void wxWindow::ChangeForegroundColour()
2551 WXWidget mainWidget
= GetMainWidget();
2553 wxDoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2554 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2555 wxDoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2558 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2560 if ( !wxWindowBase::SetBackgroundColour(col
) )
2563 ChangeBackgroundColour();
2568 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2570 if ( !wxWindowBase::SetForegroundColour(col
) )
2573 ChangeForegroundColour();
2578 void wxWindow::ChangeFont(bool keepOriginalSize
)
2580 // Note that this causes the widget to be resized back
2581 // to its original size! We therefore have to set the size
2582 // back again. TODO: a better way in Motif?
2583 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2584 if (w
&& m_font
.Ok())
2586 int width
, height
, width1
, height1
;
2587 GetSize(& width
, & height
);
2589 wxDoChangeFont( GetLabelWidget(), m_font
);
2591 GetSize(& width1
, & height1
);
2592 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2594 SetSize(-1, -1, width
, height
);
2599 // ----------------------------------------------------------------------------
2601 // ----------------------------------------------------------------------------
2603 wxWindow
*wxGetActiveWindow()
2606 wxFAIL_MSG("Not implemented");
2611 wxWindow
*wxWindowBase::GetCapture()
2613 return (wxWindow
*)g_captureWindow
;
2617 // Find the wxWindow at the current mouse position, returning the mouse
2619 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2621 return wxFindWindowAtPoint(wxGetMousePosition());
2624 // Get the current mouse position.
2625 wxPoint
wxGetMousePosition()
2627 Display
*display
= wxGlobalDisplay();
2628 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2629 Window rootReturn
, childReturn
;
2630 int rootX
, rootY
, winX
, winY
;
2631 unsigned int maskReturn
;
2633 XQueryPointer (display
,
2637 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
2638 return wxPoint(rootX
, rootY
);
2642 // ----------------------------------------------------------------------------
2643 // wxNoOptimize: switch off size optimization
2644 // ----------------------------------------------------------------------------
2646 int wxNoOptimize::ms_count
= 0;