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"
37 #include "wx/layout.h"
38 #include "wx/dialog.h"
39 #include "wx/listbox.h"
40 #include "wx/button.h"
41 #include "wx/settings.h"
42 #include "wx/msgdlg.h"
44 #include "wx/scrolwin.h"
45 #include "wx/module.h"
46 #include "wx/menuitem.h"
48 #include "wx/evtloop.h"
50 #if wxUSE_DRAG_AND_DROP
54 // DoSetSizeIntr and CanvasSetSizeIntr
56 // under Motif composite controls (such as wxCalendarCtrl or generic wxSpinCtrl
57 // don't work and/or segfault because
58 // 1) wxWindow::Create calls SetSize,
59 // which results in a call to DoSetSize much earlier than in the other ports
60 // 2) if wxWindow::Create is called (wxControl::Create calls it)
61 // then DoSetSize is never called, causing layout problems in composite
65 // 1) don't call SetSize, DoSetSize, DoMoveWindow, DoGetPosition,
66 // DoSetPosition directly or indirectly from wxWindow::Create
67 // 2) call DoMoveWindow from DoSetSize, allowing controls to override it,
68 // but make wxWindow::DoMoveWindow a no-op if it is called from
69 // an overridden DoMoveWindow (i.e. wxFoo::DoMoveWindow calls
70 // wxWindow::DoMoveWindow; this is to preserve the behaviour
74 #pragma message disable nosimpint
78 #include <Xm/DrawingA.h>
79 #include <Xm/ScrolledW.h>
80 #include <Xm/ScrollBar.h>
83 #include <Xm/RowColumn.h> // for XmMenuPosition
85 #pragma message enable nosimpint
88 #include "wx/motif/private.h"
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 static const int SCROLL_MARGIN
= 4;
98 // ----------------------------------------------------------------------------
99 // global variables for this module
100 // ----------------------------------------------------------------------------
102 extern wxHashTable
*wxWidgetHashTable
;
103 static wxWindow
* g_captureWindow
= NULL
;
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
111 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
112 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
113 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
114 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
115 XmScrollBarCallbackStruct
*cbs
);
116 static void wxPanelItemEventHandler(Widget wid
,
117 XtPointer client_data
,
119 Boolean
*continueToDispatch
);
124 // Helper function for 16-bit fonts
125 static int str16len(const char *s
)
129 while (s
[0] && s
[1]) {
139 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
143 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
144 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
145 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
153 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
154 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
155 EVT_IDLE(wxWindow::OnIdle
)
158 // ============================================================================
160 // ============================================================================
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
168 Widget w
= (Widget
)widget
;
176 bool wxWindow::MapOrUnmap(WXWidget widget
, bool domap
)
178 Widget w
= (Widget
)widget
;
187 // Rationale: a lot of common operations (including but not
188 // limited to moving, resizing and appending items to a listbox)
189 // unmamange the widget, do their work, then manage it again.
190 // This means that, for example adding an item to a listbox will show it,
191 // or that most controls are shown every time they are moved or resized!
192 XtSetMappedWhenManaged( w
, domap
);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 void wxWindow::Init()
203 // generic initializations first
207 m_needsRefresh
= TRUE
;
208 m_mainWidget
= (WXWidget
) 0;
212 m_button3Pressed
= FALSE
;
214 m_winCaptured
= FALSE
;
217 m_isBeingDeleted
= FALSE
;
223 m_drawingArea
= (WXWidget
) 0;
231 m_backingPixmap
= (WXPixmap
) 0;
240 m_canAddEventHandler
= FALSE
;
243 // real construction (Init() must have been called before!)
244 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
248 const wxString
& name
)
250 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
252 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
254 parent
->AddChild(this);
256 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
257 m_foregroundColour
= *wxBLACK
;
259 //// TODO: we should probably optimize by only creating a
260 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
261 //// But for now, let's simplify things by always creating the
262 //// drawing area, since otherwise the translations are different.
264 // New translations for getting mouse motion feedback
265 static const String translations
=
266 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
267 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
268 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
269 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
270 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
271 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
272 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
273 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
274 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
275 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
276 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
277 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
278 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
279 <Key>: DrawingAreaInput()";
281 XtActionsRec actions
[1];
282 actions
[0].string
= "wxCanvasMotionEvent";
283 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
284 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
286 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
288 if (style
& wxSIMPLE_BORDER
)
290 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
293 xmFrameWidgetClass
, parentWidget
,
294 XmNshadowType
, XmSHADOW_IN
,
295 XmNshadowThickness
, 1,
298 } else if (style
& wxSUNKEN_BORDER
)
300 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
303 xmFrameWidgetClass
, parentWidget
,
304 XmNshadowType
, XmSHADOW_IN
,
307 } else if (style
& wxRAISED_BORDER
)
309 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
312 xmFrameWidgetClass
, parentWidget
,
313 XmNshadowType
, XmSHADOW_OUT
,
318 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
321 xmScrolledWindowWidgetClass
,
322 m_borderWidget
? (Widget
) m_borderWidget
324 XmNresizePolicy
, XmRESIZE_NONE
,
326 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
327 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
331 XtTranslations ptr
= XtParseTranslationTable(translations
);
332 m_drawingArea
= (WXWidget
)XtVaCreateWidget
335 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
336 XmNunitType
, XmPIXELS
,
337 // XmNresizePolicy, XmRESIZE_ANY,
338 XmNresizePolicy
, XmRESIZE_NONE
,
341 XmNtranslations
, ptr
,
344 XtFree((char *) ptr
);
347 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
349 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
350 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
351 XtFree ((char *) ptr
);
355 wxAddWindowToTable((Widget
) m_drawingArea
, this);
356 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
358 // This order is very important in Motif 1.2.1
359 XtRealizeWidget ((Widget
) m_scrolledWindow
);
360 XtRealizeWidget ((Widget
) m_drawingArea
);
361 XtManageChild ((Widget
) m_drawingArea
);
363 ptr
= XtParseTranslationTable("<Configure>: resize()");
364 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
365 XtFree ((char *) ptr
);
367 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
368 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
372 display
= XtDisplay (scrolledWindow
);
373 xwindow
= XtWindow (drawingArea
);
377 (Widget
)m_drawingArea
,
378 PointerMotionHintMask
| EnterWindowMask
|
379 LeaveWindowMask
| FocusChangeMask
,
381 (XtEventHandler
) wxCanvasEnterLeave
,
385 // Scrolled widget needs to have its colour changed or we get a little blue
386 // square where the scrollbars abutt
387 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
388 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
389 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
391 XmScrolledWindowSetAreas(
392 (Widget
)m_scrolledWindow
,
393 (Widget
) 0, (Widget
) 0,
394 (Widget
) m_drawingArea
);
398 XtRealizeWidget ((Widget
) m_hScrollBar
);
400 XtRealizeWidget ((Widget
) m_vScrollBar
);
403 // Without this, the cursor may not be restored properly (e.g. in splitter
405 SetCursor(*wxSTANDARD_CURSOR
);
406 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
407 DoSetSizeIntr(pos
.x
, pos
.y
, size
.x
,size
.y
, wxSIZE_AUTO
, TRUE
);
412 wxWindow::~wxWindow()
414 if (g_captureWindow
== this)
415 g_captureWindow
= NULL
;
417 m_isBeingDeleted
= TRUE
;
419 // Motif-specific actions first
420 WXWidget wMain
= GetMainWidget();
423 // Removes event handlers
430 m_parent
->RemoveChild( this );
432 // If m_drawingArea, we're a fully-fledged window with drawing area,
433 // scrollbars etc. (what wxCanvas used to be)
436 // Destroy children before destroying self
440 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
442 Widget w
= (Widget
) m_drawingArea
;
443 wxDeleteWindowFromTable(w
);
448 m_drawingArea
= (WXWidget
) 0;
451 // Only if we're _really_ a canvas (not a dialog box/panel)
452 if (m_scrolledWindow
)
454 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
459 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
460 XtUnmanageChild((Widget
) m_hScrollBar
);
464 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
465 XtUnmanageChild((Widget
) m_vScrollBar
);
469 XtDestroyWidget((Widget
) m_hScrollBar
);
471 XtDestroyWidget((Widget
) m_vScrollBar
);
473 UnmanageAndDestroy(m_scrolledWindow
);
477 XtDestroyWidget ((Widget
) m_borderWidget
);
478 m_borderWidget
= (WXWidget
) 0;
481 else // Why wasn't this here before? JACS 8/3/2000
485 // Destroy the window
488 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
489 // Child widgets will get destroyed automatically when a frame
490 // or dialog is destroyed, but before that you may get some memory
491 // leaks and potential layout problems if you delete and then add
494 // GRG, Feb/2000: commented this out when adding support for
495 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
496 // that this call crashed wxMotif under OS/2, so it seems
497 // that leaving it out is the right thing to do.
498 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
499 XtDestroyWidget((Widget
) GetMainWidget());
500 SetMainWidget((WXWidget
) NULL
);
504 // ----------------------------------------------------------------------------
505 // scrollbar management
506 // ----------------------------------------------------------------------------
509 void wxWindow::CreateScrollbar(wxOrientation orientation
)
511 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
513 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
515 // Add scrollbars if required
516 if (orientation
== wxHORIZONTAL
)
518 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
519 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
520 XmNorientation
, XmHORIZONTAL
,
522 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
523 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
524 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
525 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
526 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
527 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
528 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
529 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
531 XtVaSetValues (hScrollBar
,
536 m_hScrollBar
= (WXWidget
) hScrollBar
;
538 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
539 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
541 XtRealizeWidget(hScrollBar
);
543 XtVaSetValues((Widget
) m_scrolledWindow
,
544 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
549 wxAddWindowToTable( hScrollBar
, this );
552 if (orientation
== wxVERTICAL
)
554 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
555 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
556 XmNorientation
, XmVERTICAL
,
558 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
559 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
560 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
561 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
562 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
563 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
564 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
565 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
567 XtVaSetValues (vScrollBar
,
572 m_vScrollBar
= (WXWidget
) vScrollBar
;
573 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
574 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
576 XtRealizeWidget(vScrollBar
);
578 XtVaSetValues((Widget
) m_scrolledWindow
,
579 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
584 wxAddWindowToTable( vScrollBar
, this );
587 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
590 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
592 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
594 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
595 // Add scrollbars if required
596 if (orientation
== wxHORIZONTAL
)
600 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
601 XtDestroyWidget((Widget
) m_hScrollBar
);
603 m_hScrollBar
= (WXWidget
) 0;
606 XtVaSetValues((Widget
) m_scrolledWindow
,
607 XmNhorizontalScrollBar
, (Widget
) 0,
612 if (orientation
== wxVERTICAL
)
616 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
617 XtDestroyWidget((Widget
) m_vScrollBar
);
619 m_vScrollBar
= (WXWidget
) 0;
622 XtVaSetValues((Widget
) m_scrolledWindow
,
623 XmNverticalScrollBar
, (Widget
) 0,
627 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
630 // ---------------------------------------------------------------------------
632 // ---------------------------------------------------------------------------
634 void wxWindow::SetFocus()
636 Widget wMain
= (Widget
) GetMainWidget();
637 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
638 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
641 // Get the window with the focus
642 wxWindow
*wxWindowBase::FindFocus()
645 // (1) Can there be multiple focussed widgets in an application?
646 // In which case we need to find the top-level window that's
648 // (2) The widget with the focus may not be in the widget table
649 // depending on which widgets I put in the table
650 wxWindow
*winFocus
= (wxWindow
*)NULL
;
651 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
653 node
= node
->GetNext() )
655 wxWindow
*win
= node
->GetData();
657 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
659 if (w
!= (Widget
) NULL
)
661 winFocus
= wxGetWindowFromTable(w
);
670 bool wxWindow::Enable(bool enable
)
672 if ( !wxWindowBase::Enable(enable
) )
675 Widget wMain
= (Widget
)GetMainWidget();
678 XtSetSensitive(wMain
, enable
);
679 XmUpdateDisplay(wMain
);
685 bool wxWindow::Show(bool show
)
687 if ( !wxWindowBase::Show(show
) )
690 if (m_borderWidget
|| m_scrolledWindow
)
692 MapOrUnmap(m_drawingArea
, show
);
693 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
697 if ( !MapOrUnmap(GetTopWidget(), show
) )
698 MapOrUnmap(GetMainWidget(), show
);
702 Window xwin
= (Window
) GetXWindow();
703 Display
*xdisp
= (Display
*) GetXDisplay();
705 XMapWindow(xdisp
, xwin
);
707 XUnmapWindow(xdisp
, xwin
);
713 // Raise the window to the top of the Z order
714 void wxWindow::Raise()
716 Widget wTop
= (Widget
) GetTopWidget();
717 Window window
= XtWindow(wTop
);
718 XRaiseWindow(XtDisplay(wTop
), window
);
721 // Lower the window to the bottom of the Z order
722 void wxWindow::Lower()
724 Widget wTop
= (Widget
) GetTopWidget();
725 Window window
= XtWindow(wTop
);
726 XLowerWindow(XtDisplay(wTop
), window
);
729 void wxWindow::SetTitle(const wxString
& title
)
731 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
734 wxString
wxWindow::GetTitle() const
737 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
739 return wxString(title
);
742 void wxWindow::DoCaptureMouse()
744 g_captureWindow
= this;
748 Widget wMain
= (Widget
)GetMainWidget();
750 XtAddGrab(wMain
, TRUE
, FALSE
);
752 m_winCaptured
= TRUE
;
755 void wxWindow::DoReleaseMouse()
757 g_captureWindow
= NULL
;
758 if ( !m_winCaptured
)
761 Widget wMain
= (Widget
)GetMainWidget();
765 m_winCaptured
= FALSE
;
768 bool wxWindow::SetFont(const wxFont
& font
)
770 if ( !wxWindowBase::SetFont(font
) )
781 bool wxWindow::SetCursor(const wxCursor
& cursor
)
783 if ( !wxWindowBase::SetCursor(cursor
) )
789 // wxASSERT_MSG( m_cursor.Ok(),
790 // wxT("cursor must be valid after call to the base version"));
791 wxCursor
* cursor2
= NULL
;
793 cursor2
= & m_cursor
;
795 cursor2
= wxSTANDARD_CURSOR
;
797 WXDisplay
*dpy
= GetXDisplay();
798 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
800 Widget w
= (Widget
) GetMainWidget();
801 Window win
= XtWindow(w
);
802 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
807 // Coordinates relative to the window
808 void wxWindow::WarpPointer (int x
, int y
)
810 Widget wClient
= (Widget
)GetClientWidget();
812 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
815 // ---------------------------------------------------------------------------
817 // ---------------------------------------------------------------------------
819 int wxWindow::GetScrollPos(int orient
) const
821 if (orient
== wxHORIZONTAL
)
827 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
831 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
839 // This now returns the whole range, not just the number of positions that we
841 int wxWindow::GetScrollRange(int orient
) const
843 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
844 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
848 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
852 int wxWindow::GetScrollThumb(int orient
) const
854 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
855 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
858 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
862 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
864 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
868 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
871 SetInternalScrollPos((wxOrientation
)orient
, pos
);
874 // New function that will replace some of the above.
875 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
876 int range
, bool WXUNUSED(refresh
))
879 GetSize(& oldW
, & oldH
);
883 if (thumbVisible
== 0)
886 if (thumbVisible
> range
)
887 thumbVisible
= range
;
889 // Save the old state to see if it changed
890 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
892 if (orient
== wxHORIZONTAL
)
894 if (thumbVisible
== range
)
897 DestroyScrollbar(wxHORIZONTAL
);
902 CreateScrollbar(wxHORIZONTAL
);
905 if (orient
== wxVERTICAL
)
907 if (thumbVisible
== range
)
910 DestroyScrollbar(wxVERTICAL
);
915 CreateScrollbar(wxVERTICAL
);
918 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
920 if (oldScrollBar
!= newScrollBar
)
922 // This is important! Without it, scrollbars misbehave badly.
923 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
924 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
925 XtRealizeWidget((Widget
) m_scrolledWindow
);
926 XtManageChild((Widget
) m_scrolledWindow
);
931 XtVaSetValues((Widget
) newScrollBar
,
935 XmNsliderSize
, thumbVisible
,
939 SetInternalScrollPos((wxOrientation
)orient
, pos
);
942 GetSize(& newW
, & newH
);
944 // Adjusting scrollbars can resize the canvas accidentally
945 if (newW
!= oldW
|| newH
!= oldH
)
946 SetSize(-1, -1, oldW
, oldH
);
949 // Does a physical scroll
950 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
955 // Use specified rectangle
956 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
960 // Use whole client area
962 GetClientSize(& w
, & h
);
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 int x1
= (dx
>= 0) ? x
: x
- dx
;
978 int y1
= (dy
>= 0) ? y
: y
- dy
;
979 int w1
= w
- abs(dx
);
980 int h1
= h
- abs(dy
);
981 int x2
= (dx
>= 0) ? x
+ dx
: x
;
982 int y2
= (dy
>= 0) ? y
+ dy
: y
;
986 dc
.SetLogicalFunction (wxCOPY
);
988 Widget widget
= (Widget
) GetMainWidget();
989 Window window
= XtWindow(widget
);
990 Display
* display
= XtDisplay(widget
);
992 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
993 x1
, y1
, w1
, h1
, x2
, y2
);
995 dc
.SetAutoSetting(TRUE
);
996 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
997 dc
.SetBrush(brush
); // FIXME: needed?
999 // We'll add rectangles to the list of update rectangles according to which
1000 // bits we've exposed.
1005 wxRect
*rect
= new wxRect
;
1011 XFillRectangle(display
, window
,
1012 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1016 rect
->width
= rect
->width
;
1017 rect
->height
= rect
->height
;
1019 updateRects
.Append((wxObject
*) rect
);
1023 wxRect
*rect
= new wxRect
;
1025 rect
->x
= x
+ w
+ dx
;
1030 XFillRectangle(display
, window
,
1031 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1036 rect
->width
= rect
->width
;
1037 rect
->height
= rect
->height
;
1039 updateRects
.Append((wxObject
*) rect
);
1043 wxRect
*rect
= new wxRect
;
1050 XFillRectangle(display
, window
,
1051 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1055 rect
->width
= rect
->width
;
1056 rect
->height
= rect
->height
;
1058 updateRects
.Append((wxObject
*) rect
);
1062 wxRect
*rect
= new wxRect
;
1065 rect
->y
= y
+ h
+ dy
;
1069 XFillRectangle(display
, window
,
1070 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1074 rect
->width
= rect
->width
;
1075 rect
->height
= rect
->height
;
1077 updateRects
.Append((wxObject
*) rect
);
1079 dc
.SetBrush(wxNullBrush
);
1081 // Now send expose events
1083 wxList::Node
* node
= updateRects
.GetFirst();
1086 wxRect
* rect
= (wxRect
*) node
->GetData();
1089 event
.type
= Expose
;
1090 event
.display
= display
;
1091 event
.send_event
= True
;
1092 event
.window
= window
;
1096 event
.width
= rect
->width
;
1097 event
.height
= rect
->height
;
1101 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1103 node
= node
->GetNext();
1107 // Delete the update rects
1108 node
= updateRects
.GetFirst();
1111 wxRect
* rect
= (wxRect
*) node
->GetData();
1113 node
= node
->GetNext();
1116 XmUpdateDisplay((Widget
) GetMainWidget());
1119 // ---------------------------------------------------------------------------
1121 // ---------------------------------------------------------------------------
1123 #if wxUSE_DRAG_AND_DROP
1125 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1132 // Old style file-manager drag&drop
1133 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1138 // ----------------------------------------------------------------------------
1140 // ----------------------------------------------------------------------------
1144 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1149 #endif // wxUSE_TOOLTIPS
1151 // ----------------------------------------------------------------------------
1153 // ----------------------------------------------------------------------------
1157 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1159 Widget widget
= (Widget
) GetMainWidget();
1161 /* The menuId field seems to be usused, so we'll use it to
1162 indicate whether a menu is popped up or not:
1163 0: Not currently created as a popup
1164 -1: Created as a popup, but not active
1168 if (menu
->GetParent() && (menu
->GetId() != -1))
1171 if (menu
->GetMainWidget())
1173 menu
->DestroyMenu(TRUE
);
1176 menu
->SetId(1); /* Mark as popped-up */
1177 menu
->CreateMenu(NULL
, widget
, menu
);
1178 menu
->SetInvokingWindow(this);
1182 // menu->SetParent(parent);
1183 // parent->children->Append(menu); // Store menu for later deletion
1185 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1193 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1195 wxCanvas *canvas = (wxCanvas *) this;
1196 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1197 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1201 Display
*display
= XtDisplay (widget
);
1202 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1203 Window thisWindow
= XtWindow (widget
);
1205 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1206 &rootX
, &rootY
, &childWindow
);
1208 XButtonPressedEvent event
;
1209 event
.type
= ButtonPress
;
1215 event
.x_root
= rootX
;
1216 event
.y_root
= rootY
;
1218 XmMenuPosition (menuWidget
, &event
);
1219 XtManageChild (menuWidget
);
1221 // The ID of a pop-up menu is 1 when active, and is set to 0 by the
1222 // idle-time destroy routine.
1223 // Waiting until this ID changes causes this function to block until
1224 // the menu has been dismissed and the widgets cleaned up.
1225 // In other words, once this routine returns, it is safe to delete
1227 // Ian Brown <ian.brown@printsoft.de>
1229 wxEventLoop evtLoop
;
1231 while (menu
->GetId() == 1)
1233 wxDoEventLoopIteration( evtLoop
);
1241 // ---------------------------------------------------------------------------
1242 // moving and resizing
1243 // ---------------------------------------------------------------------------
1245 bool wxWindow::PreResize()
1251 void wxWindow::DoGetSize(int *x
, int *y
) const
1255 CanvasGetSize(x
, y
);
1259 Widget widget
= (Widget
) GetTopWidget();
1261 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1262 if(x
) *x
= xx
; if(y
) *y
= yy
;
1265 void wxWindow::DoGetPosition(int *x
, int *y
) const
1269 CanvasGetPosition(x
, y
);
1272 Widget widget
= (Widget
) GetTopWidget();
1274 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1276 // We may be faking the client origin. So a window that's really at (0, 30)
1277 // may appear (to wxWin apps) to be at (0, 0).
1280 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1285 if(x
) *x
= xx
; if(y
) *y
= yy
;
1288 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1290 Widget widget
= (Widget
) GetClientWidget();
1291 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1292 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1293 Window thisWindow
= XtWindow(widget
);
1298 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1301 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1303 Widget widget
= (Widget
) GetClientWidget();
1304 Display
*display
= XtDisplay(widget
);
1305 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1306 Window thisWindow
= XtWindow(widget
);
1311 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1315 // Get size *available for subwindows* i.e. excluding menu bar etc.
1316 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1318 Widget widget
= (Widget
) GetClientWidget();
1320 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1321 if(x
) *x
= xx
; if(y
) *y
= yy
;
1324 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1326 DoSetSizeIntr(x
, y
, width
, height
, sizeFlags
, FALSE
);
1329 void wxWindow::DoSetSizeIntr(int x
, int y
, int width
, int height
,
1330 int sizeFlags
, bool fromCtor
)
1332 // A bit of optimization to help sort out the flickers.
1333 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
1336 GetSize(& oldW
, & oldH
);
1337 GetPosition(& oldX
, & oldY
);
1340 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1353 bool nothingChanged
= (x
== oldX
) && (y
== oldY
) &&
1354 (width
== oldW
) && (height
== oldH
);
1356 if (!wxNoOptimize::CanOptimize())
1358 nothingChanged
= FALSE
;
1361 if ( !nothingChanged
)
1365 CanvasSetSizeIntr(x
, y
, width
, height
, sizeFlags
, fromCtor
);
1366 if( !fromCtor
) DoMoveWindow(x
, y
, width
, height
);
1370 Widget widget
= (Widget
) GetTopWidget();
1374 bool managed
= XtIsManaged( widget
);
1376 XtUnmanageChild(widget
);
1380 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1382 DoMoveWindow(xx
, yy
, width
, height
);
1385 XtManageChild(widget
);
1389 void wxWindow::DoSetClientSize(int width
, int height
)
1393 CanvasSetClientSize(width
, height
);
1397 Widget widget
= (Widget
) GetTopWidget();
1400 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1402 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1404 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1405 sizeEvent
.SetEventObject(this);
1407 GetEventHandler()->ProcessEvent(sizeEvent
);
1410 // For implementation purposes - sometimes decorations make the client area
1412 wxPoint
wxWindow::GetClientAreaOrigin() const
1414 return wxPoint(0, 0);
1417 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1424 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1427 // TODO what about dialogs?
1431 Widget widget
= (Widget
) frame
->GetShellWidget();
1434 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1436 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1438 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1440 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1442 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1444 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1447 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1449 // see the top of the file, near DoSetSizeIntr
1458 XtVaSetValues((Widget
)GetTopWidget(),
1466 // ---------------------------------------------------------------------------
1468 // ---------------------------------------------------------------------------
1470 int wxWindow::GetCharHeight() const
1472 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1474 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1476 int direction
, ascent
, descent
;
1477 XCharStruct overall
;
1478 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1479 &descent
, &overall
);
1481 // return (overall.ascent + overall.descent);
1482 return (ascent
+ descent
);
1485 int wxWindow::GetCharWidth() const
1487 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1489 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1491 int direction
, ascent
, descent
;
1492 XCharStruct overall
;
1493 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1494 &descent
, &overall
);
1496 return overall
.width
;
1499 void wxWindow::GetTextExtent(const wxString
& string
,
1501 int *descent
, int *externalLeading
,
1502 const wxFont
*theFont
) const
1504 wxFont
*fontToUse
= (wxFont
*)theFont
;
1506 fontToUse
= (wxFont
*) & m_font
;
1508 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1510 WXFontStructPtr pFontStruct
= fontToUse
->GetFontStruct(1.0, GetXDisplay());
1512 int direction
, ascent
, descent2
;
1513 XCharStruct overall
;
1514 int slen
= string
.Len();
1518 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1519 &ascent
, &descent2
, &overall
);
1522 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1523 &direction
, &ascent
, &descent2
, &overall
);
1526 *x
= (overall
.width
);
1528 *y
= (ascent
+ descent2
);
1530 *descent
= descent2
;
1531 if (externalLeading
)
1532 *externalLeading
= 0;
1536 // ----------------------------------------------------------------------------
1538 // ----------------------------------------------------------------------------
1540 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1542 m_needsRefresh
= TRUE
;
1543 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1544 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1546 XExposeEvent dummyEvent
;
1548 GetSize(&width
, &height
);
1550 dummyEvent
.type
= Expose
;
1551 dummyEvent
.display
= display
;
1552 dummyEvent
.send_event
= True
;
1553 dummyEvent
.window
= thisWindow
;
1556 dummyEvent
.x
= rect
->x
;
1557 dummyEvent
.y
= rect
->y
;
1558 dummyEvent
.width
= rect
->width
;
1559 dummyEvent
.height
= rect
->height
;
1565 dummyEvent
.width
= width
;
1566 dummyEvent
.height
= height
;
1568 dummyEvent
.count
= 0;
1572 wxClientDC
dc(this);
1573 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1574 dc
.SetBackground(backgroundBrush
);
1581 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1584 void wxWindow::Clear()
1586 wxClientDC
dc(this);
1587 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1588 dc
.SetBackground(brush
);
1592 void wxWindow::ClearUpdateRects()
1594 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1597 wxRect
* rect
= node
->GetData();
1599 node
= node
->GetNext();
1602 m_updateRects
.Clear();
1605 void wxWindow::DoPaint()
1607 //TODO : make a temporary gc so we can do the XCopyArea below
1608 if (m_backingPixmap
&& !m_needsRefresh
)
1612 GC tempGC
= (GC
) dc
.GetBackingGC();
1614 Widget widget
= (Widget
) GetMainWidget();
1619 // We have to test whether it's a wxScrolledWindow (hack!) because
1620 // otherwise we don't know how many pixels have been scrolled. We might
1621 // solve this in the future by defining virtual wxWindow functions to get
1622 // the scroll position in pixels. Or, each kind of scrolled window has to
1623 // implement backing stores itself, using generic wxWindows code.
1624 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1625 if ( scrolledWindow
)
1628 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1634 // TODO: This could be optimized further by only copying the areas in the
1635 // current update region.
1637 // Only blit the part visible in the client area. The backing pixmap
1638 // always starts at 0, 0 but we may be looking at only a portion of it.
1639 wxSize clientArea
= GetClientSize();
1640 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1641 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1643 // Copy whichever is samller, the amount of pixmap we have to copy,
1644 // or the size of the client area.
1645 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1646 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1648 // Make sure we're not negative
1649 toBlitX
= wxMax(0, toBlitX
);
1650 toBlitY
= wxMax(0, toBlitY
);
1655 (Pixmap
) m_backingPixmap
,
1658 scrollPosX
, scrollPosY
, // Start at the scroll position
1659 toBlitX
, toBlitY
, // How much of the pixmap to copy
1665 // Set an erase event first
1666 wxEraseEvent
eraseEvent(GetId());
1667 eraseEvent
.SetEventObject(this);
1668 GetEventHandler()->ProcessEvent(eraseEvent
);
1670 wxPaintEvent
event(GetId());
1671 event
.SetEventObject(this);
1672 GetEventHandler()->ProcessEvent(event
);
1674 m_needsRefresh
= FALSE
;
1678 // ----------------------------------------------------------------------------
1680 // ----------------------------------------------------------------------------
1682 // Responds to colour changes: passes event on to children.
1683 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1685 wxWindowList::Node
*node
= GetChildren().GetFirst();
1688 // Only propagate to non-top-level windows
1689 wxWindow
*win
= node
->GetData();
1690 if ( win
->GetParent() )
1692 wxSysColourChangedEvent event2
;
1693 event
.m_eventObject
= win
;
1694 win
->GetEventHandler()->ProcessEvent(event2
);
1697 node
= node
->GetNext();
1701 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1703 // This calls the UI-update mechanism (querying windows for
1704 // menu/toolbar/control state information)
1708 // ----------------------------------------------------------------------------
1710 // ----------------------------------------------------------------------------
1712 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1715 if (!m_acceleratorTable
.Ok())
1718 int count
= m_acceleratorTable
.GetCount();
1719 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1721 for (i
= 0; i
< count
; i
++)
1723 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1724 if (entry
->MatchesEvent(event
))
1726 // Bingo, we have a match. Now find a control that matches the
1727 // entry command id.
1729 // Need to go up to the top of the window hierarchy, since it might
1730 // be e.g. a menu item
1731 wxWindow
* parent
= this;
1732 while ( parent
&& !parent
->IsTopLevel() )
1733 parent
= parent
->GetParent();
1738 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1742 // Try for a menu command
1743 if (frame
->GetMenuBar())
1745 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1748 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1749 commandEvent
.SetEventObject(frame
);
1751 // If ProcessEvent returns TRUE (it was handled), then
1752 // the calling code will skip the event handling.
1753 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1759 // Find a child matching the command id
1760 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1766 // Now we process those kinds of windows that we can.
1767 // For now, only buttons.
1768 if ( wxDynamicCast(child
, wxButton
) )
1770 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1771 commandEvent
.SetEventObject(child
);
1772 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1780 // We didn't match the key event against an accelerator.
1784 // ============================================================================
1785 // Motif-specific stuff from here on
1786 // ============================================================================
1788 // ----------------------------------------------------------------------------
1789 // function which maintain the global hash table mapping Widgets to wxWindows
1790 // ----------------------------------------------------------------------------
1792 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1794 wxWindow
*oldItem
= NULL
;
1795 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1797 wxLogDebug("Widget table clash: new widget is %ld, %s",
1798 (long)w
, win
->GetClassInfo()->GetClassName());
1802 wxWidgetHashTable
->Put((long) w
, win
);
1804 wxLogTrace("widget", "Widget 0x%p <-> window %p (%s)",
1805 (WXWidget
)w
, win
, win
->GetClassInfo()->GetClassName());
1810 wxWindow
*wxGetWindowFromTable(Widget w
)
1812 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1815 void wxDeleteWindowFromTable(Widget w
)
1817 wxWidgetHashTable
->Delete((long)w
);
1820 // ----------------------------------------------------------------------------
1821 // add/remove window from the table
1822 // ----------------------------------------------------------------------------
1824 // Add to hash table, add event handler
1825 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1826 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1828 wxAddWindowToTable((Widget
) mainWidget
, this);
1829 if (CanAddEventHandler())
1831 XtAddEventHandler((Widget
) mainWidget
,
1832 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1834 wxPanelItemEventHandler
,
1841 XtOverrideTranslations ((Widget
) mainWidget
,
1842 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1843 XtFree ((char *) ptr
);
1846 // Some widgets have a parent form widget, e.g. wxRadioBox
1849 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1853 XtOverrideTranslations ((Widget
) formWidget
,
1854 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1855 XtFree ((char *) ptr
);
1862 SetSize (x
, y
, width
, height
);
1867 // Remove event handler, remove from hash table
1868 bool wxWindow::DetachWidget(WXWidget widget
)
1870 if (CanAddEventHandler())
1872 XtRemoveEventHandler((Widget
) widget
,
1873 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1875 wxPanelItemEventHandler
,
1879 wxDeleteWindowFromTable((Widget
) widget
);
1883 // ----------------------------------------------------------------------------
1884 // Motif-specific accessors
1885 // ----------------------------------------------------------------------------
1887 // Get the underlying X window
1888 WXWindow
wxWindow::GetXWindow() const
1890 Widget wMain
= (Widget
)GetMainWidget();
1892 return (WXWindow
) XtWindow(wMain
);
1894 return (WXWindow
) 0;
1897 // Get the underlying X display
1898 WXDisplay
*wxWindow::GetXDisplay() const
1900 Widget wMain
= (Widget
)GetMainWidget();
1902 return (WXDisplay
*) XtDisplay(wMain
);
1904 return (WXDisplay
*) NULL
;
1907 WXWidget
wxWindow::GetMainWidget() const
1910 return m_drawingArea
;
1912 return m_mainWidget
;
1915 WXWidget
wxWindow::GetClientWidget() const
1917 if (m_drawingArea
!= (WXWidget
) 0)
1918 return m_drawingArea
;
1920 return GetMainWidget();
1923 WXWidget
wxWindow::GetTopWidget() const
1925 return GetMainWidget();
1928 WXWidget
wxWindow::GetLabelWidget() const
1930 return GetMainWidget();
1933 // ----------------------------------------------------------------------------
1935 // ----------------------------------------------------------------------------
1937 // All widgets should have this as their resize proc.
1938 // OnSize sent to wxWindow via client data.
1939 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1941 wxWindow
*win
= wxGetWindowFromTable(w
);
1945 if (win
->PreResize())
1948 win
->GetSize(&width
, &height
);
1949 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1950 sizeEvent
.SetEventObject(win
);
1951 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1955 static void wxCanvasRepaintProc(Widget drawingArea
,
1956 XtPointer clientData
,
1957 XmDrawingAreaCallbackStruct
* cbs
)
1959 if (!wxGetWindowFromTable(drawingArea
))
1962 XEvent
* event
= cbs
->event
;
1963 wxWindow
* win
= (wxWindow
*) clientData
;
1965 switch (event
->type
)
1969 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1970 event
->xexpose
.width
, event
->xexpose
.height
);
1972 if (event
-> xexpose
.count
== 0)
1975 win
->ClearUpdateRects();
1982 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1983 static void wxCanvasEnterLeave(Widget drawingArea
,
1984 XtPointer
WXUNUSED(clientData
),
1985 XCrossingEvent
* event
)
1987 XmDrawingAreaCallbackStruct cbs
;
1990 ((XCrossingEvent
&) ev
) = *event
;
1992 cbs
.reason
= XmCR_INPUT
;
1995 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1998 // Fix to make it work under Motif 1.0 (!)
1999 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
2001 #if XmVersion <= 1000
2002 XmDrawingAreaCallbackStruct cbs
;
2005 ev
= *((XEvent
*) event
);
2006 cbs
.reason
= XmCR_INPUT
;
2009 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2010 #endif // XmVersion <= 1000
2013 static void wxCanvasInputEvent(Widget drawingArea
,
2014 XtPointer
WXUNUSED(data
),
2015 XmDrawingAreaCallbackStruct
* cbs
)
2017 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
2023 if (cbs
->reason
!= XmCR_INPUT
)
2026 local_event
= *(cbs
->event
); // We must keep a copy!
2028 switch (local_event
.xany
.type
)
2036 // FIXME: most of this mouse event code is more or less
2037 // duplicated in wxTranslateMouseEvent
2039 wxEventType eventType
= wxEVT_NULL
;
2041 if (local_event
.xany
.type
== EnterNotify
)
2043 //if (local_event.xcrossing.mode!=NotifyNormal)
2044 // return ; // Ignore grab events
2045 eventType
= wxEVT_ENTER_WINDOW
;
2046 // canvas->GetEventHandler()->OnSetFocus();
2048 else if (local_event
.xany
.type
== LeaveNotify
)
2050 //if (local_event.xcrossingr.mode!=NotifyNormal)
2051 // return ; // Ignore grab events
2052 eventType
= wxEVT_LEAVE_WINDOW
;
2053 // canvas->GetEventHandler()->OnKillFocus();
2055 else if (local_event
.xany
.type
== MotionNotify
)
2057 eventType
= wxEVT_MOTION
;
2060 else if (local_event
.xany
.type
== ButtonPress
)
2062 if (local_event
.xbutton
.button
== Button1
)
2064 eventType
= wxEVT_LEFT_DOWN
;
2065 canvas
->SetButton1(TRUE
);
2067 else if (local_event
.xbutton
.button
== Button2
)
2069 eventType
= wxEVT_MIDDLE_DOWN
;
2070 canvas
->SetButton2(TRUE
);
2072 else if (local_event
.xbutton
.button
== Button3
)
2074 eventType
= wxEVT_RIGHT_DOWN
;
2075 canvas
->SetButton3(TRUE
);
2078 else if (local_event
.xany
.type
== ButtonRelease
)
2080 if (local_event
.xbutton
.button
== Button1
)
2082 eventType
= wxEVT_LEFT_UP
;
2083 canvas
->SetButton1(FALSE
);
2085 else if (local_event
.xbutton
.button
== Button2
)
2087 eventType
= wxEVT_MIDDLE_UP
;
2088 canvas
->SetButton2(FALSE
);
2090 else if (local_event
.xbutton
.button
== Button3
)
2092 eventType
= wxEVT_RIGHT_UP
;
2093 canvas
->SetButton3(FALSE
);
2097 wxMouseEvent
wxevent (eventType
);
2099 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2100 || (event_left_is_down (&local_event
)
2101 && (eventType
!= wxEVT_LEFT_UP
)));
2102 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2103 || (event_middle_is_down (&local_event
)
2104 && (eventType
!= wxEVT_MIDDLE_UP
)));
2105 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2106 || (event_right_is_down (&local_event
)
2107 && (eventType
!= wxEVT_RIGHT_UP
)));
2109 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2110 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2111 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2112 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2113 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2115 if ( eventType
== wxEVT_MOTION
)
2117 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2120 Display
*dpy
= XtDisplay (drawingArea
);
2122 XQueryPointer (dpy
, XtWindow (drawingArea
),
2124 &local_event
.xmotion
.x_root
,
2125 &local_event
.xmotion
.y_root
,
2126 &local_event
.xmotion
.x
,
2127 &local_event
.xmotion
.y
,
2128 &local_event
.xmotion
.state
);
2135 // Now check if we need to translate this event into a double click
2136 if (TRUE
) // canvas->doubleClickAllowed)
2138 if (wxevent
.ButtonDown())
2140 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2142 // get button and time-stamp
2144 if (wxevent
.LeftDown())
2146 else if (wxevent
.MiddleDown())
2148 else if (wxevent
.RightDown())
2150 long ts
= wxevent
.GetTimestamp();
2152 // check, if single or double click
2153 int buttonLast
= canvas
->GetLastClickedButton();
2154 long lastTS
= canvas
->GetLastClickTime();
2155 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2158 canvas
->SetLastClick(0, ts
);
2160 wxEventType typeDouble
;
2161 if ( eventType
== wxEVT_LEFT_DOWN
)
2162 typeDouble
= wxEVT_LEFT_DCLICK
;
2163 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2164 typeDouble
= wxEVT_MIDDLE_DCLICK
;
2165 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2166 typeDouble
= wxEVT_RIGHT_DCLICK
;
2168 typeDouble
= wxEVT_NULL
;
2170 if ( typeDouble
!= wxEVT_NULL
)
2172 wxevent
.SetEventType(typeDouble
);
2177 // not fast enough or different button
2178 canvas
->SetLastClick(button
, ts
);
2183 wxevent
.SetId(canvas
->GetId());
2184 wxevent
.SetEventObject(canvas
);
2185 wxevent
.m_x
= local_event
.xbutton
.x
;
2186 wxevent
.m_y
= local_event
.xbutton
.y
;
2187 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2189 if (eventType
== wxEVT_ENTER_WINDOW
||
2190 eventType
== wxEVT_LEAVE_WINDOW
||
2191 eventType
== wxEVT_MOTION
2199 wxKeyEvent
event (wxEVT_CHAR
);
2200 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2202 // Implement wxFrame::OnCharHook by checking ancestor.
2203 wxWindow
*parent
= canvas
->GetParent();
2204 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2205 parent
= parent
->GetParent();
2209 event
.SetEventType(wxEVT_CHAR_HOOK
);
2210 if (parent
->GetEventHandler()->ProcessEvent(event
))
2214 // For simplicity, OnKeyDown is the same as OnChar
2215 // TODO: filter modifier key presses from OnChar
2216 event
.SetEventType(wxEVT_KEY_DOWN
);
2218 // Only process OnChar if OnKeyDown didn't swallow it
2219 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2221 event
.SetEventType(wxEVT_CHAR
);
2222 canvas
->GetEventHandler()->ProcessEvent (event
);
2229 wxKeyEvent
event (wxEVT_KEY_UP
);
2230 if (wxTranslateKeyEvent (event
, canvas
, (Widget
) 0, &local_event
))
2232 canvas
->GetEventHandler()->ProcessEvent (event
);
2238 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2240 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2241 event
.SetEventObject(canvas
);
2242 canvas
->GetEventHandler()->ProcessEvent(event
);
2248 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2250 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2251 event
.SetEventObject(canvas
);
2252 canvas
->GetEventHandler()->ProcessEvent(event
);
2261 static void wxPanelItemEventHandler(Widget wid
,
2262 XtPointer
WXUNUSED(client_data
),
2264 Boolean
*continueToDispatch
)
2266 // Widget can be a label or the actual widget.
2268 wxWindow
*window
= wxGetWindowFromTable(wid
);
2271 wxMouseEvent
wxevent(0);
2272 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2274 window
->GetEventHandler()->ProcessEvent(wxevent
);
2278 // TODO: probably the key to allowing default behaviour to happen. Say we
2279 // set a m_doDefault flag to FALSE at the start of this function. Then in
2280 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2281 // TRUE, indicating that default processing can happen. Thus, behaviour can
2282 // appear to be overridden just by adding an event handler and not calling
2283 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2284 // way of handling drawing area events, to simplify things.
2285 *continueToDispatch
= True
;
2288 static void wxScrollBarCallback(Widget scrollbar
,
2289 XtPointer clientData
,
2290 XmScrollBarCallbackStruct
*cbs
)
2292 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2293 int orientation
= (int) clientData
;
2295 wxEventType eventType
= wxEVT_NULL
;
2296 switch (cbs
->reason
)
2298 case XmCR_INCREMENT
:
2300 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2303 case XmCR_DECREMENT
:
2305 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2310 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2313 case XmCR_VALUE_CHANGED
:
2315 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2318 case XmCR_PAGE_INCREMENT
:
2320 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2323 case XmCR_PAGE_DECREMENT
:
2325 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2330 eventType
= wxEVT_SCROLLWIN_TOP
;
2333 case XmCR_TO_BOTTOM
:
2335 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2340 // Should never get here
2341 wxFAIL_MSG("Unknown scroll event.");
2346 wxScrollWinEvent
event(eventType
,
2348 ((orientation
== XmHORIZONTAL
) ?
2349 wxHORIZONTAL
: wxVERTICAL
));
2350 event
.SetEventObject( win
);
2351 win
->GetEventHandler()->ProcessEvent(event
);
2354 // For repainting arbitrary windows
2355 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2360 wxWindow
* win
= wxGetWindowFromTable(w
);
2364 switch(event
-> type
)
2368 window
= (Window
) win
-> GetXWindow();
2369 display
= (Display
*) win
-> GetXDisplay();
2371 if (event
-> xexpose
.count
== 0)
2375 win
->ClearUpdateRects();
2379 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2380 event
->xexpose
.width
, event
->xexpose
.height
);
2388 // ----------------------------------------------------------------------------
2389 // CanvaseXXXSize() functions
2390 // ----------------------------------------------------------------------------
2392 void wxWindow::CanvasSetSize(int x
, int y
, int w
, int h
, int sizeFlags
)
2394 CanvasSetSizeIntr(x
, y
, w
, h
, sizeFlags
, FALSE
);
2397 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2398 void wxWindow::CanvasSetSizeIntr(int x
, int y
, int w
, int h
, int sizeFlags
,
2401 // A bit of optimization to help sort out the flickers.
2402 int oldX
= -1, oldY
= -1, oldW
= -1, oldH
= -1;
2403 // see the top of the file, near DoSetSizeIntr
2406 GetSize(& oldW
, & oldH
);
2407 GetPosition(& oldX
, & oldY
);
2410 bool useOldPos
= FALSE
;
2411 bool useOldSize
= FALSE
;
2413 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2415 else if (x
== oldX
&& y
== oldY
)
2418 if ((w
== -1) && (h
== -1))
2420 else if (w
== oldW
&& h
== oldH
)
2423 if (!wxNoOptimize::CanOptimize())
2425 useOldSize
= FALSE
; useOldPos
= FALSE
;
2428 if (useOldPos
&& useOldSize
)
2431 Widget drawingArea
= (Widget
) m_drawingArea
;
2432 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2435 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2436 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2438 int xx
= x
; int yy
= y
;
2439 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2443 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2445 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2449 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2451 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2463 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2464 short thick
, margin
;
2465 XtVaGetValues ((Widget
) m_borderWidget
,
2466 XmNshadowThickness
, &thick
,
2467 XmNmarginWidth
, &margin
,
2469 w
-= 2 * (thick
+ margin
);
2472 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2476 XtVaGetValues ((Widget
) m_scrolledWindow
,
2477 XmNspacing
, &spacing
,
2478 XmNverticalScrollBar
, &sbar
,
2482 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2486 w
-= (spacing
+ wsbar
);
2489 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2496 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2497 short thick
, margin
;
2498 XtVaGetValues ((Widget
) m_borderWidget
,
2499 XmNshadowThickness
, &thick
,
2500 XmNmarginHeight
, &margin
,
2502 h
-= 2 * (thick
+ margin
);
2505 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2509 XtVaGetValues ((Widget
) m_scrolledWindow
,
2510 XmNspacing
, &spacing
,
2511 XmNhorizontalScrollBar
, &sbar
,
2515 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2519 h
-= (spacing
+ wsbar
);
2522 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2528 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2529 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2533 GetClientSize (&ww
, &hh
);
2534 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2535 sizeEvent
.SetEventObject(this);
2537 GetEventHandler()->ProcessEvent(sizeEvent
);
2541 void wxWindow::CanvasSetClientSize (int w
, int h
)
2543 Widget drawingArea
= (Widget
) m_drawingArea
;
2545 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2548 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2550 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2553 // TODO: is this necessary?
2554 allowRepainting
= FALSE
;
2556 XSync (XtDisplay (drawingArea
), FALSE
);
2558 while (XtAppPending (wxTheApp
->appContext
))
2560 XFlush (XtDisplay (drawingArea
));
2561 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2562 XtDispatchEvent (&event
);
2566 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2569 allowRepainting
= TRUE
;
2572 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2573 sizeEvent
.SetEventObject(this);
2575 GetEventHandler()->ProcessEvent(sizeEvent
);
2579 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2581 // Must return the same thing that was set via SetClientSize
2583 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2588 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2591 if ((Widget
) m_borderWidget
)
2592 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2593 else if ((Widget
) m_scrolledWindow
)
2594 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2596 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2602 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2605 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2607 // We may be faking the client origin.
2608 // So a window that's really at (0, 30) may appear
2609 // (to wxWin apps) to be at (0, 0).
2612 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2621 // ----------------------------------------------------------------------------
2622 // TranslateXXXEvent() functions
2623 // ----------------------------------------------------------------------------
2625 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2627 switch (xevent
->xany
.type
)
2629 case EnterNotify
: // never received here - yes ? MB
2630 case LeaveNotify
: // never received here - yes ? MB
2635 wxEventType eventType
= wxEVT_NULL
;
2637 // FIXME: this is never true I think - MB
2639 if (xevent
->xany
.type
== LeaveNotify
)
2641 win
->SetButton1(FALSE
);
2642 win
->SetButton2(FALSE
);
2643 win
->SetButton3(FALSE
);
2646 else if (xevent
->xany
.type
== MotionNotify
)
2648 eventType
= wxEVT_MOTION
;
2650 else if (xevent
->xany
.type
== ButtonPress
)
2652 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2654 if (xevent
->xbutton
.button
== Button1
)
2656 eventType
= wxEVT_LEFT_DOWN
;
2657 win
->SetButton1(TRUE
);
2660 else if (xevent
->xbutton
.button
== Button2
)
2662 eventType
= wxEVT_MIDDLE_DOWN
;
2663 win
->SetButton2(TRUE
);
2666 else if (xevent
->xbutton
.button
== Button3
)
2668 eventType
= wxEVT_RIGHT_DOWN
;
2669 win
->SetButton3(TRUE
);
2673 // check for a double click
2675 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2676 long ts
= wxevent
.GetTimestamp();
2678 int buttonLast
= win
->GetLastClickedButton();
2679 long lastTS
= win
->GetLastClickTime();
2680 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2683 win
->SetLastClick(0, ts
);
2684 if ( eventType
== wxEVT_LEFT_DOWN
)
2685 eventType
= wxEVT_LEFT_DCLICK
;
2686 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2687 eventType
= wxEVT_MIDDLE_DCLICK
;
2688 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2689 eventType
= wxEVT_RIGHT_DCLICK
;
2693 // not fast enough or different button
2694 win
->SetLastClick(button
, ts
);
2697 else if (xevent
->xany
.type
== ButtonRelease
)
2699 if (xevent
->xbutton
.button
== Button1
)
2701 eventType
= wxEVT_LEFT_UP
;
2702 win
->SetButton1(FALSE
);
2704 else if (xevent
->xbutton
.button
== Button2
)
2706 eventType
= wxEVT_MIDDLE_UP
;
2707 win
->SetButton2(FALSE
);
2709 else if (xevent
->xbutton
.button
== Button3
)
2711 eventType
= wxEVT_RIGHT_UP
;
2712 win
->SetButton3(FALSE
);
2721 wxevent
.SetEventType(eventType
);
2724 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2727 win
->GetPosition(&x2
, &y2
);
2729 // The button x/y must be translated to wxWindows
2730 // window space - the widget might be a label or button,
2734 if (widget
!= (Widget
)win
->GetMainWidget())
2740 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2741 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2743 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2744 || (event_left_is_down (xevent
)
2745 && (eventType
!= wxEVT_LEFT_UP
)));
2746 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2747 || (event_middle_is_down (xevent
)
2748 && (eventType
!= wxEVT_MIDDLE_UP
)));
2749 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2750 || (event_right_is_down (xevent
)
2751 && (eventType
!= wxEVT_RIGHT_UP
)));
2753 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2754 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2755 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2756 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2758 wxevent
.SetId(win
->GetId());
2759 wxevent
.SetEventObject(win
);
2767 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2769 switch (xevent
->xany
.type
)
2778 XComposeStatus compose
;
2779 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2781 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2782 int id
= wxCharCodeXToWX (keySym
);
2783 // id may be WXK_xxx code - these are outside ASCII range, so we
2784 // can't just use toupper() on id
2785 if (id
>= 'a' && id
<= 'z')
2788 if (xevent
->xkey
.state
& ShiftMask
)
2789 wxevent
.m_shiftDown
= TRUE
;
2790 if (xevent
->xkey
.state
& ControlMask
)
2791 wxevent
.m_controlDown
= TRUE
;
2792 if (xevent
->xkey
.state
& Mod3Mask
)
2793 wxevent
.m_altDown
= TRUE
;
2794 if (xevent
->xkey
.state
& Mod1Mask
)
2795 wxevent
.m_metaDown
= TRUE
;
2796 wxevent
.SetEventObject(win
);
2797 wxevent
.m_keyCode
= id
;
2798 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2800 wxevent
.m_x
= xevent
->xbutton
.x
;
2801 wxevent
.m_y
= xevent
->xbutton
.y
;
2815 // ----------------------------------------------------------------------------
2817 // ----------------------------------------------------------------------------
2819 #define YAllocColor XAllocColor
2820 XColor g_itemColors
[5];
2821 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2824 static XmColorProc colorProc
;
2826 result
= wxNO_COLORS
;
2830 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2831 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2832 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2833 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2834 if (colorProc
== (XmColorProc
) NULL
)
2836 // Get a ptr to the actual function
2837 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2838 // And set it back to motif.
2839 XmSetColorCalculation (colorProc
);
2841 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2842 &g_itemColors
[wxFORE_INDEX
],
2843 &g_itemColors
[wxSELE_INDEX
],
2844 &g_itemColors
[wxTOPS_INDEX
],
2845 &g_itemColors
[wxBOTS_INDEX
]);
2846 result
= wxBACK_COLORS
;
2850 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2851 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2852 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2853 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2854 if (result
== wxNO_COLORS
)
2855 result
= wxFORE_COLORS
;
2858 Display
*dpy
= display
;
2859 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2863 /* 5 Colours to allocate */
2864 for (int i
= 0; i
< 5; i
++)
2865 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2866 result
= wxNO_COLORS
;
2870 /* Only 1 colour to allocate */
2871 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2872 result
= wxNO_COLORS
;
2879 // Changes the foreground and background colours to be derived from the current
2880 // background colour. To change the foreground colour, you must call
2881 // SetForegroundColour explicitly.
2882 void wxWindow::ChangeBackgroundColour()
2884 WXWidget mainWidget
= GetMainWidget();
2886 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2888 // This not necessary
2891 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2893 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2894 // Have to set the scrollbar colours back since
2895 // the scrolled window seemed to change them
2896 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
2899 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2901 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2906 void wxWindow::ChangeForegroundColour()
2908 WXWidget mainWidget
= GetMainWidget();
2910 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2911 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2912 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2915 // Change a widget's foreground and background colours.
2916 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2918 // When should we specify the foreground, if it's calculated
2919 // by wxComputeColours?
2920 // Solution: say we start with the default (computed) foreground colour.
2921 // If we call SetForegroundColour explicitly for a control or window,
2922 // then the foreground is changed.
2923 // Therefore SetBackgroundColour computes the foreground colour, and
2924 // SetForegroundColour changes the foreground colour. The ordering is
2927 Widget w
= (Widget
)widget
;
2930 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2935 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2937 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2940 XtVaSetValues ((Widget
) widget
,
2941 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2942 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2943 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2944 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2947 if (changeArmColour
)
2948 XtVaSetValues ((Widget
) widget
,
2949 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2953 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2955 if ( !wxWindowBase::SetBackgroundColour(col
) )
2958 ChangeBackgroundColour();
2963 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2965 if ( !wxWindowBase::SetForegroundColour(col
) )
2968 ChangeForegroundColour();
2973 void wxWindow::ChangeFont(bool keepOriginalSize
)
2975 // Note that this causes the widget to be resized back
2976 // to its original size! We therefore have to set the size
2977 // back again. TODO: a better way in Motif?
2978 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2979 if (w
&& m_font
.Ok())
2981 int width
, height
, width1
, height1
;
2982 GetSize(& width
, & height
);
2984 // lesstif 0.87 hangs here, but 0.93 does not
2985 #if !defined(LESSTIF_VERSION) \
2986 || (defined(LesstifVersion) && LesstifVersion >= 93)
2988 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2992 GetSize(& width1
, & height1
);
2993 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2995 SetSize(-1, -1, width
, height
);
3000 // ----------------------------------------------------------------------------
3002 // ----------------------------------------------------------------------------
3004 wxWindow
*wxGetActiveWindow()
3007 wxFAIL_MSG("Not implemented");
3012 wxWindow
*wxWindowBase::GetCapture()
3014 return (wxWindow
*)g_captureWindow
;
3018 // Find the wxWindow at the current mouse position, returning the mouse
3020 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
3022 return wxFindWindowAtPoint(wxGetMousePosition());
3025 // Get the current mouse position.
3026 wxPoint
wxGetMousePosition()
3028 Display
*display
= (Display
*) wxGetDisplay();
3029 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
3030 Window rootReturn
, childReturn
;
3031 int rootX
, rootY
, winX
, winY
;
3032 unsigned int maskReturn
;
3034 XQueryPointer (display
,
3038 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
3039 return wxPoint(rootX
, rootY
);
3043 // ----------------------------------------------------------------------------
3044 // wxNoOptimize: switch off size optimization
3045 // ----------------------------------------------------------------------------
3047 int wxNoOptimize::ms_count
= 0;