1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
27 #include "wx/dcclient.h"
31 #include "wx/layout.h"
32 #include "wx/dialog.h"
33 #include "wx/listbox.h"
34 #include "wx/button.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
38 #include "wx/scrolwin.h"
39 #include "wx/module.h"
40 #include "wx/menuitem.h"
43 #if wxUSE_DRAG_AND_DROP
49 #include <Xm/DrawingA.h>
50 #include <Xm/ScrolledW.h>
51 #include <Xm/ScrollBar.h>
54 #include <Xm/RowColumn.h> // for XmMenuPosition
56 #include "wx/motif/private.h"
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 static const int SCROLL_MARGIN
= 4;
66 // ----------------------------------------------------------------------------
67 // global variables for this module
68 // ----------------------------------------------------------------------------
70 extern wxHashTable
*wxWidgetHashTable
;
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
77 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
78 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
79 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
80 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
81 XmScrollBarCallbackStruct
*cbs
);
82 static void wxPanelItemEventHandler(Widget wid
,
83 XtPointer client_data
,
85 Boolean
*continueToDispatch
);
90 // Helper function for 16-bit fonts
91 static int str16len(const char *s
)
95 while (s
[0] && s
[1]) {
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
110 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
111 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 #if !USE_SHARED_LIBRARY
118 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
120 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
121 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
122 EVT_IDLE(wxWindow::OnIdle
)
124 #endif // USE_SHARED_LIBRARY
126 // ============================================================================
128 // ============================================================================
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
136 Widget w
= (Widget
)widget
;
144 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
146 Widget w
= (Widget
)widget
;
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 void wxWindow::Init()
164 // generic initializations first
168 m_needsRefresh
= TRUE
;
169 m_mainWidget
= (WXWidget
) 0;
173 m_button3Pressed
= FALSE
;
175 m_winCaptured
= FALSE
;
178 m_isBeingDeleted
= FALSE
;
184 m_drawingArea
= (WXWidget
) 0;
192 m_backingPixmap
= (WXPixmap
) 0;
201 m_canAddEventHandler
= FALSE
;
204 // real construction (Init() must have been called before!)
205 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
209 const wxString
& name
)
211 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
213 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
215 parent
->AddChild(this);
217 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
218 m_foregroundColour
= *wxBLACK
;
220 //// TODO: we should probably optimize by only creating a
221 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
222 //// But for now, let's simplify things by always creating the
223 //// drawing area, since otherwise the translations are different.
225 // New translations for getting mouse motion feedback
226 static const String translations
=
227 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
228 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
229 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
230 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
231 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
232 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
233 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
234 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
235 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
236 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
237 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
238 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
239 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
240 <Key>: DrawingAreaInput()";
242 XtActionsRec actions
[1];
243 actions
[0].string
= "wxCanvasMotionEvent";
244 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
245 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
247 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
248 if (style
& wxBORDER
)
250 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
253 xmFrameWidgetClass
, parentWidget
,
254 XmNshadowType
, XmSHADOW_IN
,
259 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
262 xmScrolledWindowWidgetClass
,
263 m_borderWidget
? (Widget
) m_borderWidget
265 XmNresizePolicy
, XmRESIZE_NONE
,
267 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
268 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
272 XtTranslations ptr
= XtParseTranslationTable(translations
);
273 m_drawingArea
= (WXWidget
)XtVaCreateWidget
276 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
277 XmNunitType
, XmPIXELS
,
278 // XmNresizePolicy, XmRESIZE_ANY,
279 XmNresizePolicy
, XmRESIZE_NONE
,
282 XmNtranslations
, ptr
,
285 XtFree((char *) ptr
);
288 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
290 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
291 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
292 XtFree ((char *) ptr
);
296 wxAddWindowToTable((Widget
) m_drawingArea
, this);
297 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
299 // This order is very important in Motif 1.2.1
300 XtRealizeWidget ((Widget
) m_scrolledWindow
);
301 XtRealizeWidget ((Widget
) m_drawingArea
);
302 XtManageChild ((Widget
) m_drawingArea
);
304 ptr
= XtParseTranslationTable("<Configure>: resize()");
305 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
306 XtFree ((char *) ptr
);
308 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
309 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
313 display
= XtDisplay (scrolledWindow
);
314 xwindow
= XtWindow (drawingArea
);
318 (Widget
)m_drawingArea
,
319 PointerMotionHintMask
| EnterWindowMask
|
320 LeaveWindowMask
| FocusChangeMask
,
322 (XtEventHandler
) wxCanvasEnterLeave
,
326 // Scrolled widget needs to have its colour changed or we get a little blue
327 // square where the scrollbars abutt
328 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
329 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
330 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
332 XmScrolledWindowSetAreas(
333 (Widget
)m_scrolledWindow
,
334 (Widget
) 0, (Widget
) 0,
335 (Widget
) m_drawingArea
);
339 XtRealizeWidget ((Widget
) m_hScrollBar
);
341 XtRealizeWidget ((Widget
) m_vScrollBar
);
344 // Without this, the cursor may not be restored properly (e.g. in splitter
346 SetCursor(*wxSTANDARD_CURSOR
);
347 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
348 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
354 wxWindow::~wxWindow()
356 m_isBeingDeleted
= TRUE
;
358 // Motif-specific actions first
359 WXWidget wMain
= GetMainWidget();
362 // Removes event handlers
369 m_parent
->RemoveChild( this );
371 // If m_drawingArea, we're a fully-fledged window with drawing area,
372 // scrollbars etc. (what wxCanvas used to be)
375 // Destroy children before destroying self
379 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
381 Widget w
= (Widget
) m_drawingArea
;
382 wxDeleteWindowFromTable(w
);
389 m_mainWidget
= (WXWidget
) 0;
391 // Only if we're _really_ a canvas (not a dialog box/panel)
392 if (m_scrolledWindow
)
394 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
399 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
403 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
406 UnmanageAndDestroy(m_hScrollBar
);
407 UnmanageAndDestroy(m_vScrollBar
);
408 UnmanageAndDestroy(m_scrolledWindow
);
412 XtDestroyWidget ((Widget
) m_borderWidget
);
413 m_borderWidget
= (WXWidget
) 0;
417 // Destroy the window
420 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
421 // Child widgets will get destroyed automatically when a frame
422 // or dialog is destroyed, but before that you may get some memory
423 // leaks and potential layout problems if you delete and then add
425 XtDestroyWidget((Widget
) GetMainWidget());
426 SetMainWidget((WXWidget
) NULL
);
430 // ----------------------------------------------------------------------------
431 // scrollbar management
432 // ----------------------------------------------------------------------------
435 void wxWindow::CreateScrollbar(wxOrientation orientation
)
437 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
439 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
441 // Add scrollbars if required
442 if (orientation
== wxHORIZONTAL
)
444 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
445 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
446 XmNorientation
, XmHORIZONTAL
,
448 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
449 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
450 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
451 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
452 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
453 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
454 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
455 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
457 XtVaSetValues (hScrollBar
,
462 m_hScrollBar
= (WXWidget
) hScrollBar
;
464 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
465 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
467 XtRealizeWidget(hScrollBar
);
469 XtVaSetValues((Widget
) m_scrolledWindow
,
470 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
475 wxAddWindowToTable( hScrollBar
, this );
478 if (orientation
== wxVERTICAL
)
480 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
481 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
482 XmNorientation
, XmVERTICAL
,
484 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
485 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
486 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
487 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
488 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
489 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
490 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
491 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
493 XtVaSetValues (vScrollBar
,
498 m_vScrollBar
= (WXWidget
) vScrollBar
;
499 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
500 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
502 XtRealizeWidget(vScrollBar
);
504 XtVaSetValues((Widget
) m_scrolledWindow
,
505 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
510 wxAddWindowToTable( vScrollBar
, this );
513 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
516 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
518 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
520 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
521 // Add scrollbars if required
522 if (orientation
== wxHORIZONTAL
)
526 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
527 XtDestroyWidget((Widget
) m_hScrollBar
);
529 m_hScrollBar
= (WXWidget
) 0;
532 XtVaSetValues((Widget
) m_scrolledWindow
,
533 XmNhorizontalScrollBar
, (Widget
) 0,
538 if (orientation
== wxVERTICAL
)
542 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
543 XtDestroyWidget((Widget
) m_vScrollBar
);
545 m_vScrollBar
= (WXWidget
) 0;
548 XtVaSetValues((Widget
) m_scrolledWindow
,
549 XmNverticalScrollBar
, (Widget
) 0,
553 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
556 // ---------------------------------------------------------------------------
558 // ---------------------------------------------------------------------------
560 void wxWindow::SetFocus()
562 Widget wMain
= (Widget
) GetMainWidget();
563 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
564 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
567 // Get the window with the focus
568 wxWindow
*wxWindowBase::FindFocus()
571 // (1) Can there be multiple focussed widgets in an application?
572 // In which case we need to find the top-level window that's
574 // (2) The widget with the focus may not be in the widget table
575 // depending on which widgets I put in the table
576 wxWindow
*winFocus
= (wxWindow
*)NULL
;
577 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
579 node
= node
->GetNext() )
581 wxWindow
*win
= node
->GetData();
583 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
585 if (w
!= (Widget
) NULL
)
587 winFocus
= wxGetWindowFromTable(w
);
596 bool wxWindow::Enable(bool enable
)
598 if ( !wxWindowBase::Enable(enable
) )
601 Widget wMain
= (Widget
)GetMainWidget();
604 XtSetSensitive(wMain
, enable
);
605 XmUpdateDisplay(wMain
);
611 bool wxWindow::Show(bool show
)
613 if ( !wxWindowBase::Show(show
) )
616 if (m_borderWidget
|| m_scrolledWindow
)
618 MapOrUnmap(m_drawingArea
, show
);
619 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
623 if ( !MapOrUnmap(GetTopWidget(), show
) )
624 MapOrUnmap(GetMainWidget(), show
);
628 Window xwin
= (Window
) GetXWindow();
629 Display
*xdisp
= (Display
*) GetXDisplay();
631 XMapWindow(xdisp
, xwin
);
633 XUnmapWindow(xdisp
, xwin
);
639 // Raise the window to the top of the Z order
640 void wxWindow::Raise()
642 Widget wTop
= (Widget
) GetTopWidget();
643 Window window
= XtWindow(wTop
);
644 XRaiseWindow(XtDisplay(wTop
), window
);
647 // Lower the window to the bottom of the Z order
648 void wxWindow::Lower()
650 Widget wTop
= (Widget
) GetTopWidget();
651 Window window
= XtWindow(wTop
);
652 XLowerWindow(XtDisplay(wTop
), window
);
655 void wxWindow::SetTitle(const wxString
& title
)
657 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
660 wxString
wxWindow::GetTitle() const
663 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
665 return wxString(title
);
668 void wxWindow::CaptureMouse()
673 Widget wMain
= (Widget
)GetMainWidget();
675 XtAddGrab(wMain
, TRUE
, FALSE
);
677 m_winCaptured
= TRUE
;
680 void wxWindow::ReleaseMouse()
682 if ( !m_winCaptured
)
685 Widget wMain
= (Widget
)GetMainWidget();
689 m_winCaptured
= FALSE
;
692 bool wxWindow::SetFont(const wxFont
& font
)
694 if ( !wxWindowBase::SetFont(font
) )
705 bool wxWindow::SetCursor(const wxCursor
& cursor
)
707 if ( !wxWindowBase::SetCursor(cursor
) )
713 wxASSERT_MSG( m_cursor
.Ok(),
714 wxT("cursor must be valid after call to the base version"));
716 WXDisplay
*dpy
= GetXDisplay();
717 WXCursor x_cursor
= m_cursor
.GetXCursor(dpy
);
719 Widget w
= (Widget
) GetMainWidget();
720 Window win
= XtWindow(w
);
721 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
726 // Coordinates relative to the window
727 void wxWindow::WarpPointer (int x
, int y
)
729 Widget wClient
= (Widget
)GetClientWidget();
731 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
734 // ---------------------------------------------------------------------------
736 // ---------------------------------------------------------------------------
738 int wxWindow::GetScrollPos(int orient
) const
740 if (orient
== wxHORIZONTAL
)
746 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
750 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
758 // This now returns the whole range, not just the number of positions that we
760 int wxWindow::GetScrollRange(int orient
) const
762 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
763 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
766 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
770 int wxWindow::GetScrollThumb(int orient
) const
772 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
773 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
776 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
780 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
782 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
786 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
789 SetInternalScrollPos((wxOrientation
)orient
, pos
);
792 // New function that will replace some of the above.
793 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
794 int range
, bool WXUNUSED(refresh
))
797 GetSize(& oldW
, & oldH
);
801 if (thumbVisible
== 0)
804 if (thumbVisible
> range
)
805 thumbVisible
= range
;
807 // Save the old state to see if it changed
808 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
810 if (orient
== wxHORIZONTAL
)
812 if (thumbVisible
== range
)
815 DestroyScrollbar(wxHORIZONTAL
);
820 CreateScrollbar(wxHORIZONTAL
);
823 if (orient
== wxVERTICAL
)
825 if (thumbVisible
== range
)
828 DestroyScrollbar(wxVERTICAL
);
833 CreateScrollbar(wxVERTICAL
);
836 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
838 if (oldScrollBar
!= newScrollBar
)
840 // This is important! Without it, scrollbars misbehave badly.
841 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
842 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
843 XtRealizeWidget((Widget
) m_scrolledWindow
);
844 XtManageChild((Widget
) m_scrolledWindow
);
849 XtVaSetValues((Widget
) newScrollBar
,
853 XmNsliderSize
, thumbVisible
,
857 SetInternalScrollPos((wxOrientation
)orient
, pos
);
860 GetSize(& newW
, & newH
);
862 // Adjusting scrollbars can resize the canvas accidentally
863 if (newW
!= oldW
|| newH
!= oldH
)
864 SetSize(-1, -1, oldW
, oldH
);
867 // Does a physical scroll
868 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
873 // Use specified rectangle
874 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
878 // Use whole client area
880 GetClientSize(& w
, & h
);
883 int x1
= (dx
>= 0) ? x
: x
- dx
;
884 int y1
= (dy
>= 0) ? y
: y
- dy
;
885 int w1
= w
- abs(dx
);
886 int h1
= h
- abs(dy
);
887 int x2
= (dx
>= 0) ? x
+ dx
: x
;
888 int y2
= (dy
>= 0) ? y
+ dy
: y
;
892 dc
.SetLogicalFunction (wxCOPY
);
894 Widget widget
= (Widget
) GetMainWidget();
895 Window window
= XtWindow(widget
);
896 Display
* display
= XtDisplay(widget
);
898 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
899 x1
, y1
, w1
, h1
, x2
, y2
);
901 dc
.SetAutoSetting(TRUE
);
902 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
903 dc
.SetBrush(brush
); // FIXME: needed?
905 // We'll add rectangles to the list of update rectangles according to which
906 // bits we've exposed.
911 wxRect
*rect
= new wxRect
;
917 XFillRectangle(display
, window
,
918 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
922 rect
->width
= rect
->width
;
923 rect
->height
= rect
->height
;
925 updateRects
.Append((wxObject
*) rect
);
929 wxRect
*rect
= new wxRect
;
931 rect
->x
= x
+ w
+ dx
;
936 XFillRectangle(display
, window
,
937 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
942 rect
->width
= rect
->width
;
943 rect
->height
= rect
->height
;
945 updateRects
.Append((wxObject
*) rect
);
949 wxRect
*rect
= new wxRect
;
956 XFillRectangle(display
, window
,
957 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
961 rect
->width
= rect
->width
;
962 rect
->height
= rect
->height
;
964 updateRects
.Append((wxObject
*) rect
);
968 wxRect
*rect
= new wxRect
;
971 rect
->y
= y
+ h
+ dy
;
975 XFillRectangle(display
, window
,
976 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
980 rect
->width
= rect
->width
;
981 rect
->height
= rect
->height
;
983 updateRects
.Append((wxObject
*) rect
);
985 dc
.SetBrush(wxNullBrush
);
987 // Now send expose events
989 wxNode
* node
= updateRects
.First();
992 wxRect
* rect
= (wxRect
*) node
->Data();
996 event
.display
= display
;
997 event
.send_event
= True
;
998 event
.window
= window
;
1002 event
.width
= rect
->width
;
1003 event
.height
= rect
->height
;
1007 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1009 node
= node
->Next();
1013 // Delete the update rects
1014 node
= updateRects
.First();
1017 wxRect
* rect
= (wxRect
*) node
->Data();
1019 node
= node
->Next();
1022 XmUpdateDisplay((Widget
) GetMainWidget());
1025 // ---------------------------------------------------------------------------
1027 // ---------------------------------------------------------------------------
1029 #if wxUSE_DRAG_AND_DROP
1031 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1038 // Old style file-manager drag&drop
1039 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1044 // ----------------------------------------------------------------------------
1046 // ----------------------------------------------------------------------------
1050 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1055 #endif // wxUSE_TOOLTIPS
1057 // ----------------------------------------------------------------------------
1059 // ----------------------------------------------------------------------------
1061 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1063 Widget widget
= (Widget
) GetMainWidget();
1065 /* The menuId field seems to be usused, so we'll use it to
1066 indicate whether a menu is popped up or not:
1067 0: Not currently created as a popup
1068 -1: Created as a popup, but not active
1072 if (menu
->GetParent() && (menu
->GetId() != -1))
1075 if (menu
->GetMainWidget()) {
1076 menu
->DestroyMenu(TRUE
);
1079 menu
->SetId(1); /* Mark as popped-up */
1080 menu
->CreateMenu(NULL
, widget
, menu
);
1081 menu
->SetInvokingWindow(this);
1085 // menu->SetParent(parent);
1086 // parent->children->Append(menu); // Store menu for later deletion
1088 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1096 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1098 wxCanvas *canvas = (wxCanvas *) this;
1099 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1100 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1104 Display
*display
= XtDisplay (widget
);
1105 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1106 Window thisWindow
= XtWindow (widget
);
1108 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1109 &rootX
, &rootY
, &childWindow
);
1111 XButtonPressedEvent event
;
1112 event
.type
= ButtonPress
;
1118 event
.x_root
= rootX
;
1119 event
.y_root
= rootY
;
1121 XmMenuPosition (menuWidget
, &event
);
1122 XtManageChild (menuWidget
);
1127 // ---------------------------------------------------------------------------
1128 // moving and resizing
1129 // ---------------------------------------------------------------------------
1131 bool wxWindow::PreResize()
1137 void wxWindow::DoGetSize(int *x
, int *y
) const
1141 CanvasGetSize(x
, y
);
1145 Widget widget
= (Widget
) GetTopWidget();
1147 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1151 void wxWindow::DoGetPosition(int *x
, int *y
) const
1155 CanvasGetPosition(x
, y
);
1158 Widget widget
= (Widget
) GetTopWidget();
1160 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1162 // We may be faking the client origin. So a window that's really at (0, 30)
1163 // may appear (to wxWin apps) to be at (0, 0).
1166 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1174 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1176 Widget widget
= (Widget
) GetClientWidget();
1177 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1178 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1179 Window thisWindow
= XtWindow(widget
);
1184 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1187 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1189 Widget widget
= (Widget
) GetClientWidget();
1190 Display
*display
= XtDisplay(widget
);
1191 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1192 Window thisWindow
= XtWindow(widget
);
1197 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1201 // Get size *available for subwindows* i.e. excluding menu bar etc.
1202 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1204 Widget widget
= (Widget
) GetClientWidget();
1206 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1210 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1212 // A bit of optimization to help sort out the flickers.
1213 int oldX
, oldY
, oldW
, oldH
;
1214 GetSize(& oldW
, & oldH
);
1215 GetPosition(& oldX
, & oldY
);
1217 bool useOldPos
= FALSE
;
1218 bool useOldSize
= FALSE
;
1220 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
1222 else if (x
== oldX
&& y
== oldY
)
1225 if ((width
== -1) && (height
== -1))
1227 else if (width
== oldW
&& height
== oldH
)
1230 if (!wxNoOptimize::CanOptimize())
1232 useOldSize
= FALSE
; useOldPos
= FALSE
;
1235 if (useOldPos
&& useOldSize
)
1240 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1243 Widget widget
= (Widget
) GetTopWidget();
1247 bool managed
= XtIsManaged( widget
);
1249 XtUnmanageChild(widget
);
1251 int xx
= x
; int yy
= y
;
1252 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1256 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1257 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
1258 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1259 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
1264 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1266 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1270 XtManageChild(widget
);
1272 // How about this bit. Maybe we don't need to generate size events
1273 // all the time -- they'll be generated when the window is sized anyway.
1275 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1276 sizeEvent
.SetEventObject(this);
1278 GetEventHandler()->ProcessEvent(sizeEvent
);
1282 void wxWindow::DoSetClientSize(int width
, int height
)
1286 CanvasSetClientSize(width
, height
);
1290 Widget widget
= (Widget
) GetTopWidget();
1293 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1295 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1297 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1298 sizeEvent
.SetEventObject(this);
1300 GetEventHandler()->ProcessEvent(sizeEvent
);
1303 // For implementation purposes - sometimes decorations make the client area
1305 wxPoint
wxWindow::GetClientAreaOrigin() const
1307 return wxPoint(0, 0);
1310 // Makes an adjustment to the window position (for example, a frame that has
1311 // a toolbar that it manages itself).
1312 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1314 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1316 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1317 x
+= pt
.x
; y
+= pt
.y
;
1321 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1328 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1331 // TODO what about dialogs?
1335 Widget widget
= (Widget
) frame
->GetShellWidget();
1338 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1340 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1342 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1344 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1346 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1348 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1351 // ---------------------------------------------------------------------------
1353 // ---------------------------------------------------------------------------
1355 int wxWindow::GetCharHeight() const
1357 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1359 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1361 int direction
, ascent
, descent
;
1362 XCharStruct overall
;
1363 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1364 &descent
, &overall
);
1366 // return (overall.ascent + overall.descent);
1367 return (ascent
+ descent
);
1370 int wxWindow::GetCharWidth() const
1372 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1374 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1376 int direction
, ascent
, descent
;
1377 XCharStruct overall
;
1378 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1379 &descent
, &overall
);
1381 return overall
.width
;
1384 void wxWindow::GetTextExtent(const wxString
& string
,
1386 int *descent
, int *externalLeading
,
1387 const wxFont
*theFont
) const
1389 wxFont
*fontToUse
= (wxFont
*)theFont
;
1391 fontToUse
= (wxFont
*) & m_font
;
1393 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1395 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1397 int direction
, ascent
, descent2
;
1398 XCharStruct overall
;
1399 int slen
= string
.Len();
1403 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1404 &ascent
, &descent2
, &overall
);
1407 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1408 &direction
, &ascent
, &descent2
, &overall
);
1411 *x
= (overall
.width
);
1413 *y
= (ascent
+ descent2
);
1415 *descent
= descent2
;
1416 if (externalLeading
)
1417 *externalLeading
= 0;
1421 // ----------------------------------------------------------------------------
1423 // ----------------------------------------------------------------------------
1425 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1427 m_needsRefresh
= TRUE
;
1428 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1429 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1431 XExposeEvent dummyEvent
;
1433 GetSize(&width
, &height
);
1435 dummyEvent
.type
= Expose
;
1436 dummyEvent
.display
= display
;
1437 dummyEvent
.send_event
= True
;
1438 dummyEvent
.window
= thisWindow
;
1441 dummyEvent
.x
= rect
->x
;
1442 dummyEvent
.y
= rect
->y
;
1443 dummyEvent
.width
= rect
->width
;
1444 dummyEvent
.height
= rect
->height
;
1450 dummyEvent
.width
= width
;
1451 dummyEvent
.height
= height
;
1453 dummyEvent
.count
= 0;
1457 wxClientDC
dc(this);
1458 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1459 dc
.SetBackground(backgroundBrush
);
1466 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1469 void wxWindow::Clear()
1471 wxClientDC
dc(this);
1472 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1473 dc
.SetBackground(brush
);
1477 void wxWindow::ClearUpdateRects()
1479 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1482 wxRect
* rect
= node
->GetData();
1484 node
= node
->GetNext();
1487 m_updateRects
.Clear();
1490 void wxWindow::DoPaint()
1492 //TODO : make a temporary gc so we can do the XCopyArea below
1493 if (m_backingPixmap
&& !m_needsRefresh
)
1497 GC tempGC
= (GC
) dc
.GetBackingGC();
1499 Widget widget
= (Widget
) GetMainWidget();
1504 // We have to test whether it's a wxScrolledWindow (hack!) because
1505 // otherwise we don't know how many pixels have been scrolled. We might
1506 // solve this in the future by defining virtual wxWindow functions to get
1507 // the scroll position in pixels. Or, each kind of scrolled window has to
1508 // implement backing stores itself, using generic wxWindows code.
1509 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1510 if ( scrolledWindow
)
1513 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1519 // TODO: This could be optimized further by only copying the areas in the
1520 // current update region.
1522 // Only blit the part visible in the client area. The backing pixmap
1523 // always starts at 0, 0 but we may be looking at only a portion of it.
1524 wxSize clientArea
= GetClientSize();
1525 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1526 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1528 // Copy whichever is samller, the amount of pixmap we have to copy,
1529 // or the size of the client area.
1530 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1531 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1533 // Make sure we're not negative
1534 toBlitX
= wxMax(0, toBlitX
);
1535 toBlitY
= wxMax(0, toBlitY
);
1540 (Pixmap
) m_backingPixmap
,
1543 scrollPosX
, scrollPosY
, // Start at the scroll position
1544 toBlitX
, toBlitY
, // How much of the pixmap to copy
1550 // Set an erase event first
1551 wxEraseEvent
eraseEvent(GetId());
1552 eraseEvent
.SetEventObject(this);
1553 GetEventHandler()->ProcessEvent(eraseEvent
);
1555 wxPaintEvent
event(GetId());
1556 event
.SetEventObject(this);
1557 GetEventHandler()->ProcessEvent(event
);
1559 m_needsRefresh
= FALSE
;
1563 // ----------------------------------------------------------------------------
1565 // ----------------------------------------------------------------------------
1567 // Responds to colour changes: passes event on to children.
1568 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1570 wxWindowList::Node
*node
= GetChildren().GetFirst();
1573 // Only propagate to non-top-level windows
1574 wxWindow
*win
= node
->GetData();
1575 if ( win
->GetParent() )
1577 wxSysColourChangedEvent event2
;
1578 event
.m_eventObject
= win
;
1579 win
->GetEventHandler()->ProcessEvent(event2
);
1582 node
= node
->GetNext();
1586 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1588 // This calls the UI-update mechanism (querying windows for
1589 // menu/toolbar/control state information)
1593 // ----------------------------------------------------------------------------
1595 // ----------------------------------------------------------------------------
1597 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1599 if (!m_acceleratorTable
.Ok())
1602 int count
= m_acceleratorTable
.GetCount();
1603 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1605 for (i
= 0; i
< count
; i
++)
1607 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1608 if (entry
->MatchesEvent(event
))
1610 // Bingo, we have a match. Now find a control that matches the entry
1613 // Need to go up to the top of the window hierarchy, since it might
1614 // be e.g. a menu item
1615 wxWindow
* parent
= this;
1616 while ( parent
&& !parent
->IsTopLevel() )
1617 parent
= parent
->GetParent();
1622 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1625 // Try for a menu command
1626 if (frame
->GetMenuBar())
1628 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
1631 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1632 commandEvent
.SetEventObject(frame
);
1634 // If ProcessEvent returns TRUE (it was handled), then
1635 // the calling code will skip the event handling.
1636 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1641 // Find a child matching the command id
1642 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1648 // Now we process those kinds of windows that we can.
1649 // For now, only buttons.
1650 if ( wxDynamicCast(child
, wxButton
) )
1652 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1653 commandEvent
.SetEventObject(child
);
1654 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1661 // We didn't match the key event against an accelerator.
1665 // ============================================================================
1666 // Motif-specific stuff from here on
1667 // ============================================================================
1669 // ----------------------------------------------------------------------------
1670 // function which maintain the global hash table mapping Widgets to wxWindows
1671 // ----------------------------------------------------------------------------
1673 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1675 wxWindow
*oldItem
= NULL
;
1676 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1678 wxLogDebug("Widget table clash: new widget is %ld, %s",
1679 (long)w
, win
->GetClassInfo()->GetClassName());
1683 wxWidgetHashTable
->Put((long) w
, win
);
1685 wxLogDebug("Widget 0x%08x <-> window %p (%s)",
1686 w
, win
, win
->GetClassInfo()->GetClassName());
1691 wxWindow
*wxGetWindowFromTable(Widget w
)
1693 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1696 void wxDeleteWindowFromTable(Widget w
)
1698 wxWidgetHashTable
->Delete((long)w
);
1701 // ----------------------------------------------------------------------------
1702 // add/remove window from the table
1703 // ----------------------------------------------------------------------------
1705 // Add to hash table, add event handler
1706 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1707 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1709 wxAddWindowToTable((Widget
) mainWidget
, this);
1710 if (CanAddEventHandler())
1712 XtAddEventHandler((Widget
) mainWidget
,
1713 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1715 wxPanelItemEventHandler
,
1722 XtOverrideTranslations ((Widget
) mainWidget
,
1723 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1724 XtFree ((char *) ptr
);
1727 // Some widgets have a parent form widget, e.g. wxRadioBox
1730 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1734 XtOverrideTranslations ((Widget
) formWidget
,
1735 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1736 XtFree ((char *) ptr
);
1743 SetSize (x
, y
, width
, height
);
1748 // Remove event handler, remove from hash table
1749 bool wxWindow::DetachWidget(WXWidget widget
)
1751 if (CanAddEventHandler())
1753 XtRemoveEventHandler((Widget
) widget
,
1754 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1756 wxPanelItemEventHandler
,
1760 wxDeleteWindowFromTable((Widget
) widget
);
1764 // ----------------------------------------------------------------------------
1765 // Motif-specific accessors
1766 // ----------------------------------------------------------------------------
1768 // Get the underlying X window
1769 WXWindow
wxWindow::GetXWindow() const
1771 Widget wMain
= (Widget
)GetMainWidget();
1773 return (WXWindow
) XtWindow(wMain
);
1775 return (WXWindow
) 0;
1778 // Get the underlying X display
1779 WXDisplay
*wxWindow::GetXDisplay() const
1781 Widget wMain
= (Widget
)GetMainWidget();
1783 return (WXDisplay
*) XtDisplay(wMain
);
1785 return (WXDisplay
*) NULL
;
1788 WXWidget
wxWindow::GetMainWidget() const
1791 return m_drawingArea
;
1793 return m_mainWidget
;
1796 WXWidget
wxWindow::GetClientWidget() const
1798 if (m_drawingArea
!= (WXWidget
) 0)
1799 return m_drawingArea
;
1801 return GetMainWidget();
1804 WXWidget
wxWindow::GetTopWidget() const
1806 return GetMainWidget();
1809 WXWidget
wxWindow::GetLabelWidget() const
1811 return GetMainWidget();
1814 // ----------------------------------------------------------------------------
1816 // ----------------------------------------------------------------------------
1818 // All widgets should have this as their resize proc.
1819 // OnSize sent to wxWindow via client data.
1820 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1822 wxWindow
*win
= wxGetWindowFromTable(w
);
1826 if (win
->PreResize())
1829 win
->GetSize(&width
, &height
);
1830 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1831 sizeEvent
.SetEventObject(win
);
1832 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1836 static void wxCanvasRepaintProc(Widget drawingArea
,
1837 XtPointer clientData
,
1838 XmDrawingAreaCallbackStruct
* cbs
)
1840 if (!wxGetWindowFromTable(drawingArea
))
1843 XEvent
* event
= cbs
->event
;
1844 wxWindow
* win
= (wxWindow
*) clientData
;
1846 switch (event
->type
)
1850 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1851 event
->xexpose
.width
, event
->xexpose
.height
);
1853 if (event
-> xexpose
.count
== 0)
1856 win
->ClearUpdateRects();
1863 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1864 static void wxCanvasEnterLeave(Widget drawingArea
,
1865 XtPointer
WXUNUSED(clientData
),
1866 XCrossingEvent
* event
)
1868 XmDrawingAreaCallbackStruct cbs
;
1871 ((XCrossingEvent
&) ev
) = *event
;
1873 cbs
.reason
= XmCR_INPUT
;
1876 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1879 // Fix to make it work under Motif 1.0 (!)
1880 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1882 #if XmVersion <= 1000
1883 XmDrawingAreaCallbackStruct cbs
;
1886 ev
= *((XEvent
*) event
);
1887 cbs
.reason
= XmCR_INPUT
;
1890 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1891 #endif // XmVersion <= 1000
1894 static void wxCanvasInputEvent(Widget drawingArea
,
1895 XtPointer
WXUNUSED(data
),
1896 XmDrawingAreaCallbackStruct
* cbs
)
1898 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1904 if (cbs
->reason
!= XmCR_INPUT
)
1907 local_event
= *(cbs
->event
); // We must keep a copy!
1909 switch (local_event
.xany
.type
)
1917 // FIXME: most of this mouse event code is more or less
1918 // duplicated in wxTranslateMouseEvent
1920 wxEventType eventType
= wxEVT_NULL
;
1922 if (local_event
.xany
.type
== EnterNotify
)
1924 //if (local_event.xcrossing.mode!=NotifyNormal)
1925 // return ; // Ignore grab events
1926 eventType
= wxEVT_ENTER_WINDOW
;
1927 // canvas->GetEventHandler()->OnSetFocus();
1929 else if (local_event
.xany
.type
== LeaveNotify
)
1931 //if (local_event.xcrossingr.mode!=NotifyNormal)
1932 // return ; // Ignore grab events
1933 eventType
= wxEVT_LEAVE_WINDOW
;
1934 // canvas->GetEventHandler()->OnKillFocus();
1936 else if (local_event
.xany
.type
== MotionNotify
)
1938 eventType
= wxEVT_MOTION
;
1939 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1942 Display
*dpy
= XtDisplay (drawingArea
);
1944 XQueryPointer (dpy
, XtWindow (drawingArea
),
1946 &local_event
.xmotion
.x_root
,
1947 &local_event
.xmotion
.y_root
,
1948 &local_event
.xmotion
.x
,
1949 &local_event
.xmotion
.y
,
1950 &local_event
.xmotion
.state
);
1957 else if (local_event
.xany
.type
== ButtonPress
)
1959 if (local_event
.xbutton
.button
== Button1
)
1961 eventType
= wxEVT_LEFT_DOWN
;
1962 canvas
->SetButton1(TRUE
);
1964 else if (local_event
.xbutton
.button
== Button2
)
1966 eventType
= wxEVT_MIDDLE_DOWN
;
1967 canvas
->SetButton2(TRUE
);
1969 else if (local_event
.xbutton
.button
== Button3
)
1971 eventType
= wxEVT_RIGHT_DOWN
;
1972 canvas
->SetButton3(TRUE
);
1975 else if (local_event
.xany
.type
== ButtonRelease
)
1977 if (local_event
.xbutton
.button
== Button1
)
1979 eventType
= wxEVT_LEFT_UP
;
1980 canvas
->SetButton1(FALSE
);
1982 else if (local_event
.xbutton
.button
== Button2
)
1984 eventType
= wxEVT_MIDDLE_UP
;
1985 canvas
->SetButton2(FALSE
);
1987 else if (local_event
.xbutton
.button
== Button3
)
1989 eventType
= wxEVT_RIGHT_UP
;
1990 canvas
->SetButton3(FALSE
);
1994 wxMouseEvent
wxevent (eventType
);
1996 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1997 || (event_left_is_down (&local_event
)
1998 && (eventType
!= wxEVT_LEFT_UP
)));
1999 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2000 || (event_middle_is_down (&local_event
)
2001 && (eventType
!= wxEVT_MIDDLE_UP
)));
2002 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2003 || (event_right_is_down (&local_event
)
2004 && (eventType
!= wxEVT_RIGHT_UP
)));
2006 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2007 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2008 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2009 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2010 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2012 // Now check if we need to translate this event into a double click
2013 if (TRUE
) // canvas->doubleClickAllowed)
2015 if (wxevent
.ButtonDown())
2017 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2019 // get button and time-stamp
2021 if (wxevent
.LeftDown())
2023 else if (wxevent
.MiddleDown())
2025 else if (wxevent
.RightDown())
2027 long ts
= wxevent
.GetTimestamp();
2029 // check, if single or double click
2030 int buttonLast
= canvas
->GetLastClickedButton();
2031 long lastTS
= canvas
->GetLastClickTime();
2032 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2035 canvas
->SetLastClick(0, ts
);
2036 switch ( eventType
)
2038 case wxEVT_LEFT_DOWN
:
2039 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2041 case wxEVT_MIDDLE_DOWN
:
2042 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2044 case wxEVT_RIGHT_DOWN
:
2045 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2055 // not fast enough or different button
2056 canvas
->SetLastClick(button
, ts
);
2061 wxevent
.SetId(canvas
->GetId());
2062 wxevent
.SetEventObject(canvas
);
2063 wxevent
.m_x
= local_event
.xbutton
.x
;
2064 wxevent
.m_y
= local_event
.xbutton
.y
;
2065 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2067 if (eventType
== wxEVT_ENTER_WINDOW
||
2068 eventType
== wxEVT_LEAVE_WINDOW
||
2069 eventType
== wxEVT_MOTION
2079 XComposeStatus compose
;
2080 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2083 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2084 int id
= wxCharCodeXToWX (keySym
);
2086 wxEventType eventType
= wxEVT_CHAR
;
2088 wxKeyEvent
event (eventType
);
2090 if (local_event
.xkey
.state
& ShiftMask
)
2091 event
.m_shiftDown
= TRUE
;
2092 if (local_event
.xkey
.state
& ControlMask
)
2093 event
.m_controlDown
= TRUE
;
2094 if (local_event
.xkey
.state
& Mod3Mask
)
2095 event
.m_altDown
= TRUE
;
2096 if (local_event
.xkey
.state
& Mod1Mask
)
2097 event
.m_metaDown
= TRUE
;
2098 event
.SetEventObject(canvas
);
2099 event
.m_keyCode
= id
;
2100 event
.SetTimestamp(local_event
.xkey
.time
);
2104 // Implement wxFrame::OnCharHook by checking ancestor.
2105 wxWindow
*parent
= canvas
->GetParent();
2106 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2107 parent
= parent
->GetParent();
2111 event
.SetEventType(wxEVT_CHAR_HOOK
);
2112 if (parent
->GetEventHandler()->ProcessEvent(event
))
2116 // For simplicity, OnKeyDown is the same as OnChar
2117 // TODO: filter modifier key presses from OnChar
2118 event
.SetEventType(wxEVT_KEY_DOWN
);
2120 // Only process OnChar if OnKeyDown didn't swallow it
2121 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2123 event
.SetEventType(wxEVT_CHAR
);
2124 canvas
->GetEventHandler()->ProcessEvent (event
);
2132 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2133 int id
= wxCharCodeXToWX (keySym
);
2135 wxKeyEvent
event (wxEVT_KEY_UP
);
2137 if (local_event
.xkey
.state
& ShiftMask
)
2138 event
.m_shiftDown
= TRUE
;
2139 if (local_event
.xkey
.state
& ControlMask
)
2140 event
.m_controlDown
= TRUE
;
2141 if (local_event
.xkey
.state
& Mod3Mask
)
2142 event
.m_altDown
= TRUE
;
2143 if (local_event
.xkey
.state
& Mod1Mask
)
2144 event
.m_metaDown
= TRUE
;
2145 event
.SetEventObject(canvas
);
2146 event
.m_keyCode
= id
;
2147 event
.SetTimestamp(local_event
.xkey
.time
);
2151 canvas
->GetEventHandler()->ProcessEvent (event
);
2157 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2159 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2160 event
.SetEventObject(canvas
);
2161 canvas
->GetEventHandler()->ProcessEvent(event
);
2167 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2169 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2170 event
.SetEventObject(canvas
);
2171 canvas
->GetEventHandler()->ProcessEvent(event
);
2180 static void wxPanelItemEventHandler(Widget wid
,
2181 XtPointer
WXUNUSED(client_data
),
2183 Boolean
*continueToDispatch
)
2185 // Widget can be a label or the actual widget.
2187 wxWindow
*window
= wxGetWindowFromTable(wid
);
2190 wxMouseEvent
wxevent(0);
2191 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2193 window
->GetEventHandler()->ProcessEvent(wxevent
);
2197 // TODO: probably the key to allowing default behaviour to happen. Say we
2198 // set a m_doDefault flag to FALSE at the start of this function. Then in
2199 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2200 // TRUE, indicating that default processing can happen. Thus, behaviour can
2201 // appear to be overridden just by adding an event handler and not calling
2202 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2203 // way of handling drawing area events, to simplify things.
2204 *continueToDispatch
= True
;
2207 static void wxScrollBarCallback(Widget scrollbar
,
2208 XtPointer clientData
,
2209 XmScrollBarCallbackStruct
*cbs
)
2211 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2212 int orientation
= (int) clientData
;
2214 wxEventType eventType
= wxEVT_NULL
;
2215 switch (cbs
->reason
)
2217 case XmCR_INCREMENT
:
2219 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2222 case XmCR_DECREMENT
:
2224 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2229 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2232 case XmCR_VALUE_CHANGED
:
2234 // TODO: Should this be intercepted too, or will it cause
2235 // duplicate events?
2236 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2239 case XmCR_PAGE_INCREMENT
:
2241 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2244 case XmCR_PAGE_DECREMENT
:
2246 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2251 eventType
= wxEVT_SCROLLWIN_TOP
;
2254 case XmCR_TO_BOTTOM
:
2256 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2261 // Should never get here
2262 wxFAIL_MSG("Unknown scroll event.");
2267 wxScrollWinEvent
event(eventType
,
2269 ((orientation
== XmHORIZONTAL
) ?
2270 wxHORIZONTAL
: wxVERTICAL
));
2271 event
.SetEventObject( win
);
2272 win
->GetEventHandler()->ProcessEvent(event
);
2275 // For repainting arbitrary windows
2276 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2281 wxWindow
* win
= wxGetWindowFromTable(w
);
2285 switch(event
-> type
)
2289 window
= (Window
) win
-> GetXWindow();
2290 display
= (Display
*) win
-> GetXDisplay();
2292 if (event
-> xexpose
.count
== 0)
2296 win
->ClearUpdateRects();
2300 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2301 event
->xexpose
.width
, event
->xexpose
.height
);
2309 // ----------------------------------------------------------------------------
2310 // CanvaseXXXSize() functions
2311 // ----------------------------------------------------------------------------
2313 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2314 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2316 // A bit of optimization to help sort out the flickers.
2317 int oldX
, oldY
, oldW
, oldH
;
2318 GetSize(& oldW
, & oldH
);
2319 GetPosition(& oldX
, & oldY
);
2321 bool useOldPos
= FALSE
;
2322 bool useOldSize
= FALSE
;
2324 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2326 else if (x
== oldX
&& y
== oldY
)
2329 if ((w
== -1) && (h
== -1))
2331 else if (w
== oldW
&& h
== oldH
)
2334 if (!wxNoOptimize::CanOptimize())
2336 useOldSize
= FALSE
; useOldPos
= FALSE
;
2339 if (useOldPos
&& useOldSize
)
2342 Widget drawingArea
= (Widget
) m_drawingArea
;
2343 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2346 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2347 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2349 int xx
= x
; int yy
= y
;
2350 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2354 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2356 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2360 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2362 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2374 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2375 short thick
, margin
;
2376 XtVaGetValues ((Widget
) m_borderWidget
,
2377 XmNshadowThickness
, &thick
,
2378 XmNmarginWidth
, &margin
,
2380 w
-= 2 * (thick
+ margin
);
2383 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2387 XtVaGetValues ((Widget
) m_scrolledWindow
,
2388 XmNspacing
, &spacing
,
2389 XmNverticalScrollBar
, &sbar
,
2393 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2397 w
-= (spacing
+ wsbar
);
2400 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2407 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2408 short thick
, margin
;
2409 XtVaGetValues ((Widget
) m_borderWidget
,
2410 XmNshadowThickness
, &thick
,
2411 XmNmarginHeight
, &margin
,
2413 h
-= 2 * (thick
+ margin
);
2416 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2420 XtVaGetValues ((Widget
) m_scrolledWindow
,
2421 XmNspacing
, &spacing
,
2422 XmNhorizontalScrollBar
, &sbar
,
2426 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2430 h
-= (spacing
+ wsbar
);
2433 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2439 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2440 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2444 GetClientSize (&ww
, &hh
);
2445 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2446 sizeEvent
.SetEventObject(this);
2448 GetEventHandler()->ProcessEvent(sizeEvent
);
2452 void wxWindow::CanvasSetClientSize (int w
, int h
)
2454 Widget drawingArea
= (Widget
) m_drawingArea
;
2456 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2459 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2461 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2464 // TODO: is this necessary?
2465 allowRepainting
= FALSE
;
2467 XSync (XtDisplay (drawingArea
), FALSE
);
2469 while (XtAppPending (wxTheApp
->appContext
))
2471 XFlush (XtDisplay (drawingArea
));
2472 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2473 XtDispatchEvent (&event
);
2477 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2480 allowRepainting
= TRUE
;
2483 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2484 sizeEvent
.SetEventObject(this);
2486 GetEventHandler()->ProcessEvent(sizeEvent
);
2490 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2492 // Must return the same thing that was set via SetClientSize
2494 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2499 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2502 if ((Widget
) m_borderWidget
)
2503 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2504 else if ((Widget
) m_scrolledWindow
)
2505 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2507 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2513 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2516 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2518 // We may be faking the client origin.
2519 // So a window that's really at (0, 30) may appear
2520 // (to wxWin apps) to be at (0, 0).
2523 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2532 // ----------------------------------------------------------------------------
2533 // TranslateXXXEvent() functions
2534 // ----------------------------------------------------------------------------
2536 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2538 switch (xevent
->xany
.type
)
2540 case EnterNotify
: // never received here - yes ? MB
2541 case LeaveNotify
: // never received here - yes ? MB
2546 wxEventType eventType
= wxEVT_NULL
;
2548 // FIXME: this is never true I think - MB
2550 if (xevent
->xany
.type
== LeaveNotify
)
2552 win
->SetButton1(FALSE
);
2553 win
->SetButton2(FALSE
);
2554 win
->SetButton3(FALSE
);
2557 else if (xevent
->xany
.type
== MotionNotify
)
2559 eventType
= wxEVT_MOTION
;
2561 else if (xevent
->xany
.type
== ButtonPress
)
2563 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2565 if (xevent
->xbutton
.button
== Button1
)
2567 eventType
= wxEVT_LEFT_DOWN
;
2568 win
->SetButton1(TRUE
);
2571 else if (xevent
->xbutton
.button
== Button2
)
2573 eventType
= wxEVT_MIDDLE_DOWN
;
2574 win
->SetButton2(TRUE
);
2577 else if (xevent
->xbutton
.button
== Button3
)
2579 eventType
= wxEVT_RIGHT_DOWN
;
2580 win
->SetButton3(TRUE
);
2584 // check for a double click
2586 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2587 long ts
= wxevent
.GetTimestamp();
2589 int buttonLast
= win
->GetLastClickedButton();
2590 long lastTS
= win
->GetLastClickTime();
2591 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2594 win
->SetLastClick(0, ts
);
2595 switch ( eventType
)
2597 case wxEVT_LEFT_DOWN
:
2598 eventType
= wxEVT_LEFT_DCLICK
;
2600 case wxEVT_MIDDLE_DOWN
:
2601 eventType
= wxEVT_MIDDLE_DCLICK
;
2603 case wxEVT_RIGHT_DOWN
:
2604 eventType
= wxEVT_RIGHT_DCLICK
;
2614 // not fast enough or different button
2615 win
->SetLastClick(button
, ts
);
2618 else if (xevent
->xany
.type
== ButtonRelease
)
2620 if (xevent
->xbutton
.button
== Button1
)
2622 eventType
= wxEVT_LEFT_UP
;
2623 win
->SetButton1(FALSE
);
2625 else if (xevent
->xbutton
.button
== Button2
)
2627 eventType
= wxEVT_MIDDLE_UP
;
2628 win
->SetButton2(FALSE
);
2630 else if (xevent
->xbutton
.button
== Button3
)
2632 eventType
= wxEVT_RIGHT_UP
;
2633 win
->SetButton3(FALSE
);
2642 wxevent
.SetEventType(eventType
);
2645 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2648 win
->GetPosition(&x2
, &y2
);
2650 // The button x/y must be translated to wxWindows
2651 // window space - the widget might be a label or button,
2655 if (widget
!= (Widget
)win
->GetMainWidget())
2661 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2662 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2664 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2665 || (event_left_is_down (xevent
)
2666 && (eventType
!= wxEVT_LEFT_UP
)));
2667 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2668 || (event_middle_is_down (xevent
)
2669 && (eventType
!= wxEVT_MIDDLE_UP
)));
2670 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2671 || (event_right_is_down (xevent
)
2672 && (eventType
!= wxEVT_RIGHT_UP
)));
2674 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2675 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2676 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2677 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2679 wxevent
.SetId(win
->GetId());
2680 wxevent
.SetEventObject(win
);
2688 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2690 switch (xevent
->xany
.type
)
2699 XComposeStatus compose
;
2700 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2702 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2703 int id
= wxCharCodeXToWX (keySym
);
2705 if (xevent
->xkey
.state
& ShiftMask
)
2706 wxevent
.m_shiftDown
= TRUE
;
2707 if (xevent
->xkey
.state
& ControlMask
)
2708 wxevent
.m_controlDown
= TRUE
;
2709 if (xevent
->xkey
.state
& Mod3Mask
)
2710 wxevent
.m_altDown
= TRUE
;
2711 if (xevent
->xkey
.state
& Mod1Mask
)
2712 wxevent
.m_metaDown
= TRUE
;
2713 wxevent
.SetEventObject(win
);
2714 wxevent
.m_keyCode
= id
;
2715 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2717 wxevent
.m_x
= xevent
->xbutton
.x
;
2718 wxevent
.m_y
= xevent
->xbutton
.y
;
2732 // ----------------------------------------------------------------------------
2734 // ----------------------------------------------------------------------------
2736 #define YAllocColor XAllocColor
2737 XColor g_itemColors
[5];
2738 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2741 static XmColorProc colorProc
;
2743 result
= wxNO_COLORS
;
2747 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2748 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2749 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2750 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2751 if (colorProc
== (XmColorProc
) NULL
)
2753 // Get a ptr to the actual function
2754 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2755 // And set it back to motif.
2756 XmSetColorCalculation (colorProc
);
2758 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2759 &g_itemColors
[wxFORE_INDEX
],
2760 &g_itemColors
[wxSELE_INDEX
],
2761 &g_itemColors
[wxTOPS_INDEX
],
2762 &g_itemColors
[wxBOTS_INDEX
]);
2763 result
= wxBACK_COLORS
;
2767 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2768 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2769 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2770 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2771 if (result
== wxNO_COLORS
)
2772 result
= wxFORE_COLORS
;
2775 Display
*dpy
= display
;
2776 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2780 /* 5 Colours to allocate */
2781 for (int i
= 0; i
< 5; i
++)
2782 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2783 result
= wxNO_COLORS
;
2787 /* Only 1 colour to allocate */
2788 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2789 result
= wxNO_COLORS
;
2796 // Changes the foreground and background colours to be derived from the current
2797 // background colour. To change the foreground colour, you must call
2798 // SetForegroundColour explicitly.
2799 void wxWindow::ChangeBackgroundColour()
2801 WXWidget mainWidget
= GetMainWidget();
2803 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2805 // This not necessary
2808 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2810 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2811 // Have to set the scrollbar colours back since
2812 // the scrolled window seemed to change them
2813 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2816 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2818 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2823 void wxWindow::ChangeForegroundColour()
2825 WXWidget mainWidget
= GetMainWidget();
2827 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2828 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2829 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2832 // Change a widget's foreground and background colours.
2833 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2835 // When should we specify the foreground, if it's calculated
2836 // by wxComputeColours?
2837 // Solution: say we start with the default (computed) foreground colour.
2838 // If we call SetForegroundColour explicitly for a control or window,
2839 // then the foreground is changed.
2840 // Therefore SetBackgroundColour computes the foreground colour, and
2841 // SetForegroundColour changes the foreground colour. The ordering is
2844 Widget w
= (Widget
)widget
;
2847 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2852 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2854 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2857 XtVaSetValues ((Widget
) widget
,
2858 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2859 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2860 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2861 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2864 if (changeArmColour
)
2865 XtVaSetValues ((Widget
) widget
,
2866 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2870 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2872 if ( !wxWindowBase::SetBackgroundColour(col
) )
2875 ChangeBackgroundColour();
2880 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2882 if ( !wxWindowBase::SetForegroundColour(col
) )
2885 ChangeForegroundColour();
2890 void wxWindow::ChangeFont(bool keepOriginalSize
)
2892 // Note that this causes the widget to be resized back
2893 // to its original size! We therefore have to set the size
2894 // back again. TODO: a better way in Motif?
2895 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2896 if (w
&& m_font
.Ok())
2898 int width
, height
, width1
, height1
;
2899 GetSize(& width
, & height
);
2901 // lesstif 0.87 hangs here
2902 #ifndef LESSTIF_VERSION
2904 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2908 GetSize(& width1
, & height1
);
2909 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2911 SetSize(-1, -1, width
, height
);
2916 // ----------------------------------------------------------------------------
2918 // ----------------------------------------------------------------------------
2920 wxWindow
*wxGetActiveWindow()
2926 // ----------------------------------------------------------------------------
2927 // wxNoOptimize: switch off size optimization
2928 // ----------------------------------------------------------------------------
2930 int wxNoOptimize::ms_count
= 0;