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
48 #pragma message disable nosimpint
52 #include <Xm/DrawingA.h>
53 #include <Xm/ScrolledW.h>
54 #include <Xm/ScrollBar.h>
57 #include <Xm/RowColumn.h> // for XmMenuPosition
59 #pragma message enable nosimpint
62 #include "wx/motif/private.h"
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 static const int SCROLL_MARGIN
= 4;
72 // ----------------------------------------------------------------------------
73 // global variables for this module
74 // ----------------------------------------------------------------------------
76 extern wxHashTable
*wxWidgetHashTable
;
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
83 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
84 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
85 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
86 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
87 XmScrollBarCallbackStruct
*cbs
);
88 static void wxPanelItemEventHandler(Widget wid
,
89 XtPointer client_data
,
91 Boolean
*continueToDispatch
);
96 // Helper function for 16-bit fonts
97 static int str16len(const char *s
)
101 while (s
[0] && s
[1]) {
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
116 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
117 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
125 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
126 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
127 EVT_IDLE(wxWindow::OnIdle
)
130 // ============================================================================
132 // ============================================================================
134 // ----------------------------------------------------------------------------
136 // ----------------------------------------------------------------------------
138 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
140 Widget w
= (Widget
)widget
;
148 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
150 Widget w
= (Widget
)widget
;
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void wxWindow::Init()
168 // generic initializations first
172 m_needsRefresh
= TRUE
;
173 m_mainWidget
= (WXWidget
) 0;
177 m_button3Pressed
= FALSE
;
179 m_winCaptured
= FALSE
;
182 m_isBeingDeleted
= FALSE
;
188 m_drawingArea
= (WXWidget
) 0;
196 m_backingPixmap
= (WXPixmap
) 0;
205 m_canAddEventHandler
= FALSE
;
208 // real construction (Init() must have been called before!)
209 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
213 const wxString
& name
)
215 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
217 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
219 parent
->AddChild(this);
221 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
222 m_foregroundColour
= *wxBLACK
;
224 //// TODO: we should probably optimize by only creating a
225 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
226 //// But for now, let's simplify things by always creating the
227 //// drawing area, since otherwise the translations are different.
229 // New translations for getting mouse motion feedback
230 static const String translations
=
231 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
232 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
233 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
234 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
235 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
236 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
237 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
238 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
239 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
240 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
241 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
242 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
243 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
244 <Key>: DrawingAreaInput()";
246 XtActionsRec actions
[1];
247 actions
[0].string
= "wxCanvasMotionEvent";
248 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
249 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
251 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
253 if (style
& wxSIMPLE_BORDER
)
255 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
258 xmFrameWidgetClass
, parentWidget
,
259 XmNshadowType
, XmSHADOW_IN
,
260 XmNshadowThickness
, 1,
263 } else if (style
& wxSUNKEN_BORDER
)
265 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
268 xmFrameWidgetClass
, parentWidget
,
269 XmNshadowType
, XmSHADOW_IN
,
272 } else if (style
& wxRAISED_BORDER
)
274 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
277 xmFrameWidgetClass
, parentWidget
,
278 XmNshadowType
, XmSHADOW_OUT
,
283 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
286 xmScrolledWindowWidgetClass
,
287 m_borderWidget
? (Widget
) m_borderWidget
289 XmNresizePolicy
, XmRESIZE_NONE
,
291 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
292 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
296 XtTranslations ptr
= XtParseTranslationTable(translations
);
297 m_drawingArea
= (WXWidget
)XtVaCreateWidget
300 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
301 XmNunitType
, XmPIXELS
,
302 // XmNresizePolicy, XmRESIZE_ANY,
303 XmNresizePolicy
, XmRESIZE_NONE
,
306 XmNtranslations
, ptr
,
309 XtFree((char *) ptr
);
312 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
314 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
315 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
316 XtFree ((char *) ptr
);
320 wxAddWindowToTable((Widget
) m_drawingArea
, this);
321 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
323 // This order is very important in Motif 1.2.1
324 XtRealizeWidget ((Widget
) m_scrolledWindow
);
325 XtRealizeWidget ((Widget
) m_drawingArea
);
326 XtManageChild ((Widget
) m_drawingArea
);
328 ptr
= XtParseTranslationTable("<Configure>: resize()");
329 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
330 XtFree ((char *) ptr
);
332 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
333 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
337 display
= XtDisplay (scrolledWindow
);
338 xwindow
= XtWindow (drawingArea
);
342 (Widget
)m_drawingArea
,
343 PointerMotionHintMask
| EnterWindowMask
|
344 LeaveWindowMask
| FocusChangeMask
,
346 (XtEventHandler
) wxCanvasEnterLeave
,
350 // Scrolled widget needs to have its colour changed or we get a little blue
351 // square where the scrollbars abutt
352 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
353 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
354 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
356 XmScrolledWindowSetAreas(
357 (Widget
)m_scrolledWindow
,
358 (Widget
) 0, (Widget
) 0,
359 (Widget
) m_drawingArea
);
363 XtRealizeWidget ((Widget
) m_hScrollBar
);
365 XtRealizeWidget ((Widget
) m_vScrollBar
);
368 // Without this, the cursor may not be restored properly (e.g. in splitter
370 SetCursor(*wxSTANDARD_CURSOR
);
371 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
372 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
378 wxWindow::~wxWindow()
380 m_isBeingDeleted
= TRUE
;
382 // Motif-specific actions first
383 WXWidget wMain
= GetMainWidget();
386 // Removes event handlers
393 m_parent
->RemoveChild( this );
395 // If m_drawingArea, we're a fully-fledged window with drawing area,
396 // scrollbars etc. (what wxCanvas used to be)
399 // Destroy children before destroying self
403 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
405 Widget w
= (Widget
) m_drawingArea
;
406 wxDeleteWindowFromTable(w
);
411 m_drawingArea
= (WXWidget
) 0;
414 // Only if we're _really_ a canvas (not a dialog box/panel)
415 if (m_scrolledWindow
)
417 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
422 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
423 XtUnmanageChild((Widget
) m_hScrollBar
);
427 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
428 XtUnmanageChild((Widget
) m_vScrollBar
);
432 XtDestroyWidget((Widget
) m_hScrollBar
);
434 XtDestroyWidget((Widget
) m_vScrollBar
);
436 UnmanageAndDestroy(m_scrolledWindow
);
440 XtDestroyWidget ((Widget
) m_borderWidget
);
441 m_borderWidget
= (WXWidget
) 0;
445 // Destroy the window
448 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
449 // Child widgets will get destroyed automatically when a frame
450 // or dialog is destroyed, but before that you may get some memory
451 // leaks and potential layout problems if you delete and then add
454 // GRG, Feb/2000: commented this out when adding support for
455 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
456 // that this call crashed wxMotif under OS/2, so it seems
457 // that leaving it out is the right thing to do.
458 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
459 XtDestroyWidget((Widget
) GetMainWidget());
460 SetMainWidget((WXWidget
) NULL
);
464 // ----------------------------------------------------------------------------
465 // scrollbar management
466 // ----------------------------------------------------------------------------
469 void wxWindow::CreateScrollbar(wxOrientation orientation
)
471 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
473 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
475 // Add scrollbars if required
476 if (orientation
== wxHORIZONTAL
)
478 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
479 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
480 XmNorientation
, XmHORIZONTAL
,
482 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
483 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
484 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
485 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
486 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
487 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
488 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
489 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
491 XtVaSetValues (hScrollBar
,
496 m_hScrollBar
= (WXWidget
) hScrollBar
;
498 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
499 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
501 XtRealizeWidget(hScrollBar
);
503 XtVaSetValues((Widget
) m_scrolledWindow
,
504 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
509 wxAddWindowToTable( hScrollBar
, this );
512 if (orientation
== wxVERTICAL
)
514 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
515 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
516 XmNorientation
, XmVERTICAL
,
518 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
519 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
520 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
521 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
522 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
523 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
524 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
525 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
527 XtVaSetValues (vScrollBar
,
532 m_vScrollBar
= (WXWidget
) vScrollBar
;
533 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
534 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
536 XtRealizeWidget(vScrollBar
);
538 XtVaSetValues((Widget
) m_scrolledWindow
,
539 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
544 wxAddWindowToTable( vScrollBar
, this );
547 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
550 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
552 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
554 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
555 // Add scrollbars if required
556 if (orientation
== wxHORIZONTAL
)
560 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
561 XtDestroyWidget((Widget
) m_hScrollBar
);
563 m_hScrollBar
= (WXWidget
) 0;
566 XtVaSetValues((Widget
) m_scrolledWindow
,
567 XmNhorizontalScrollBar
, (Widget
) 0,
572 if (orientation
== wxVERTICAL
)
576 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
577 XtDestroyWidget((Widget
) m_vScrollBar
);
579 m_vScrollBar
= (WXWidget
) 0;
582 XtVaSetValues((Widget
) m_scrolledWindow
,
583 XmNverticalScrollBar
, (Widget
) 0,
587 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
590 // ---------------------------------------------------------------------------
592 // ---------------------------------------------------------------------------
594 void wxWindow::SetFocus()
596 Widget wMain
= (Widget
) GetMainWidget();
597 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
598 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
601 // Get the window with the focus
602 wxWindow
*wxWindowBase::FindFocus()
605 // (1) Can there be multiple focussed widgets in an application?
606 // In which case we need to find the top-level window that's
608 // (2) The widget with the focus may not be in the widget table
609 // depending on which widgets I put in the table
610 wxWindow
*winFocus
= (wxWindow
*)NULL
;
611 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
613 node
= node
->GetNext() )
615 wxWindow
*win
= node
->GetData();
617 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
619 if (w
!= (Widget
) NULL
)
621 winFocus
= wxGetWindowFromTable(w
);
630 bool wxWindow::Enable(bool enable
)
632 if ( !wxWindowBase::Enable(enable
) )
635 Widget wMain
= (Widget
)GetMainWidget();
638 XtSetSensitive(wMain
, enable
);
639 XmUpdateDisplay(wMain
);
645 bool wxWindow::Show(bool show
)
647 if ( !wxWindowBase::Show(show
) )
650 if (m_borderWidget
|| m_scrolledWindow
)
652 MapOrUnmap(m_drawingArea
, show
);
653 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
657 if ( !MapOrUnmap(GetTopWidget(), show
) )
658 MapOrUnmap(GetMainWidget(), show
);
662 Window xwin
= (Window
) GetXWindow();
663 Display
*xdisp
= (Display
*) GetXDisplay();
665 XMapWindow(xdisp
, xwin
);
667 XUnmapWindow(xdisp
, xwin
);
673 // Raise the window to the top of the Z order
674 void wxWindow::Raise()
676 Widget wTop
= (Widget
) GetTopWidget();
677 Window window
= XtWindow(wTop
);
678 XRaiseWindow(XtDisplay(wTop
), window
);
681 // Lower the window to the bottom of the Z order
682 void wxWindow::Lower()
684 Widget wTop
= (Widget
) GetTopWidget();
685 Window window
= XtWindow(wTop
);
686 XLowerWindow(XtDisplay(wTop
), window
);
689 void wxWindow::SetTitle(const wxString
& title
)
691 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
694 wxString
wxWindow::GetTitle() const
697 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
699 return wxString(title
);
702 void wxWindow::CaptureMouse()
707 Widget wMain
= (Widget
)GetMainWidget();
709 XtAddGrab(wMain
, TRUE
, FALSE
);
711 m_winCaptured
= TRUE
;
714 void wxWindow::ReleaseMouse()
716 if ( !m_winCaptured
)
719 Widget wMain
= (Widget
)GetMainWidget();
723 m_winCaptured
= FALSE
;
726 bool wxWindow::SetFont(const wxFont
& font
)
728 if ( !wxWindowBase::SetFont(font
) )
739 bool wxWindow::SetCursor(const wxCursor
& cursor
)
741 if ( !wxWindowBase::SetCursor(cursor
) )
747 wxASSERT_MSG( m_cursor
.Ok(),
748 wxT("cursor must be valid after call to the base version"));
750 WXDisplay
*dpy
= GetXDisplay();
751 WXCursor x_cursor
= m_cursor
.GetXCursor(dpy
);
753 Widget w
= (Widget
) GetMainWidget();
754 Window win
= XtWindow(w
);
755 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
760 // Coordinates relative to the window
761 void wxWindow::WarpPointer (int x
, int y
)
763 Widget wClient
= (Widget
)GetClientWidget();
765 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
768 // ---------------------------------------------------------------------------
770 // ---------------------------------------------------------------------------
772 int wxWindow::GetScrollPos(int orient
) const
774 if (orient
== wxHORIZONTAL
)
780 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
784 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
792 // This now returns the whole range, not just the number of positions that we
794 int wxWindow::GetScrollRange(int orient
) const
796 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
797 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
800 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
804 int wxWindow::GetScrollThumb(int orient
) const
806 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
807 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
810 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
814 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
816 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
820 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
823 SetInternalScrollPos((wxOrientation
)orient
, pos
);
826 // New function that will replace some of the above.
827 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
828 int range
, bool WXUNUSED(refresh
))
831 GetSize(& oldW
, & oldH
);
835 if (thumbVisible
== 0)
838 if (thumbVisible
> range
)
839 thumbVisible
= range
;
841 // Save the old state to see if it changed
842 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
844 if (orient
== wxHORIZONTAL
)
846 if (thumbVisible
== range
)
849 DestroyScrollbar(wxHORIZONTAL
);
854 CreateScrollbar(wxHORIZONTAL
);
857 if (orient
== wxVERTICAL
)
859 if (thumbVisible
== range
)
862 DestroyScrollbar(wxVERTICAL
);
867 CreateScrollbar(wxVERTICAL
);
870 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
872 if (oldScrollBar
!= newScrollBar
)
874 // This is important! Without it, scrollbars misbehave badly.
875 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
876 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
877 XtRealizeWidget((Widget
) m_scrolledWindow
);
878 XtManageChild((Widget
) m_scrolledWindow
);
883 XtVaSetValues((Widget
) newScrollBar
,
887 XmNsliderSize
, thumbVisible
,
891 SetInternalScrollPos((wxOrientation
)orient
, pos
);
894 GetSize(& newW
, & newH
);
896 // Adjusting scrollbars can resize the canvas accidentally
897 if (newW
!= oldW
|| newH
!= oldH
)
898 SetSize(-1, -1, oldW
, oldH
);
901 // Does a physical scroll
902 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
907 // Use specified rectangle
908 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
912 // Use whole client area
914 GetClientSize(& w
, & h
);
917 wxNode
*cnode
= m_children
.First();
920 wxWindow
*child
= (wxWindow
*) cnode
->Data();
923 child
->GetSize( &sx
, &sy
);
924 wxPoint
pos( child
->GetPosition() );
925 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
926 cnode
= cnode
->Next();
929 int x1
= (dx
>= 0) ? x
: x
- dx
;
930 int y1
= (dy
>= 0) ? y
: y
- dy
;
931 int w1
= w
- abs(dx
);
932 int h1
= h
- abs(dy
);
933 int x2
= (dx
>= 0) ? x
+ dx
: x
;
934 int y2
= (dy
>= 0) ? y
+ dy
: y
;
938 dc
.SetLogicalFunction (wxCOPY
);
940 Widget widget
= (Widget
) GetMainWidget();
941 Window window
= XtWindow(widget
);
942 Display
* display
= XtDisplay(widget
);
944 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
945 x1
, y1
, w1
, h1
, x2
, y2
);
947 dc
.SetAutoSetting(TRUE
);
948 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
949 dc
.SetBrush(brush
); // FIXME: needed?
951 // We'll add rectangles to the list of update rectangles according to which
952 // bits we've exposed.
957 wxRect
*rect
= new wxRect
;
963 XFillRectangle(display
, window
,
964 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
968 rect
->width
= rect
->width
;
969 rect
->height
= rect
->height
;
971 updateRects
.Append((wxObject
*) rect
);
975 wxRect
*rect
= new wxRect
;
977 rect
->x
= x
+ w
+ dx
;
982 XFillRectangle(display
, window
,
983 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
988 rect
->width
= rect
->width
;
989 rect
->height
= rect
->height
;
991 updateRects
.Append((wxObject
*) rect
);
995 wxRect
*rect
= new wxRect
;
1002 XFillRectangle(display
, window
,
1003 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1007 rect
->width
= rect
->width
;
1008 rect
->height
= rect
->height
;
1010 updateRects
.Append((wxObject
*) rect
);
1014 wxRect
*rect
= new wxRect
;
1017 rect
->y
= y
+ h
+ dy
;
1021 XFillRectangle(display
, window
,
1022 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1026 rect
->width
= rect
->width
;
1027 rect
->height
= rect
->height
;
1029 updateRects
.Append((wxObject
*) rect
);
1031 dc
.SetBrush(wxNullBrush
);
1033 // Now send expose events
1035 wxNode
* node
= updateRects
.First();
1038 wxRect
* rect
= (wxRect
*) node
->Data();
1041 event
.type
= Expose
;
1042 event
.display
= display
;
1043 event
.send_event
= True
;
1044 event
.window
= window
;
1048 event
.width
= rect
->width
;
1049 event
.height
= rect
->height
;
1053 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1055 node
= node
->Next();
1059 // Delete the update rects
1060 node
= updateRects
.First();
1063 wxRect
* rect
= (wxRect
*) node
->Data();
1065 node
= node
->Next();
1068 XmUpdateDisplay((Widget
) GetMainWidget());
1071 // ---------------------------------------------------------------------------
1073 // ---------------------------------------------------------------------------
1075 #if wxUSE_DRAG_AND_DROP
1077 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1084 // Old style file-manager drag&drop
1085 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1090 // ----------------------------------------------------------------------------
1092 // ----------------------------------------------------------------------------
1096 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1101 #endif // wxUSE_TOOLTIPS
1103 // ----------------------------------------------------------------------------
1105 // ----------------------------------------------------------------------------
1107 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1109 Widget widget
= (Widget
) GetMainWidget();
1111 /* The menuId field seems to be usused, so we'll use it to
1112 indicate whether a menu is popped up or not:
1113 0: Not currently created as a popup
1114 -1: Created as a popup, but not active
1118 if (menu
->GetParent() && (menu
->GetId() != -1))
1121 if (menu
->GetMainWidget()) {
1122 menu
->DestroyMenu(TRUE
);
1125 menu
->SetId(1); /* Mark as popped-up */
1126 menu
->CreateMenu(NULL
, widget
, menu
);
1127 menu
->SetInvokingWindow(this);
1131 // menu->SetParent(parent);
1132 // parent->children->Append(menu); // Store menu for later deletion
1134 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1142 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1144 wxCanvas *canvas = (wxCanvas *) this;
1145 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1146 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1150 Display
*display
= XtDisplay (widget
);
1151 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1152 Window thisWindow
= XtWindow (widget
);
1154 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1155 &rootX
, &rootY
, &childWindow
);
1157 XButtonPressedEvent event
;
1158 event
.type
= ButtonPress
;
1164 event
.x_root
= rootX
;
1165 event
.y_root
= rootY
;
1167 XmMenuPosition (menuWidget
, &event
);
1168 XtManageChild (menuWidget
);
1173 // ---------------------------------------------------------------------------
1174 // moving and resizing
1175 // ---------------------------------------------------------------------------
1177 bool wxWindow::PreResize()
1183 void wxWindow::DoGetSize(int *x
, int *y
) const
1187 CanvasGetSize(x
, y
);
1191 Widget widget
= (Widget
) GetTopWidget();
1193 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1197 void wxWindow::DoGetPosition(int *x
, int *y
) const
1201 CanvasGetPosition(x
, y
);
1204 Widget widget
= (Widget
) GetTopWidget();
1206 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1208 // We may be faking the client origin. So a window that's really at (0, 30)
1209 // may appear (to wxWin apps) to be at (0, 0).
1212 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1220 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1222 Widget widget
= (Widget
) GetClientWidget();
1223 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1224 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1225 Window thisWindow
= XtWindow(widget
);
1230 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1233 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1235 Widget widget
= (Widget
) GetClientWidget();
1236 Display
*display
= XtDisplay(widget
);
1237 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1238 Window thisWindow
= XtWindow(widget
);
1243 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1247 // Get size *available for subwindows* i.e. excluding menu bar etc.
1248 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1250 Widget widget
= (Widget
) GetClientWidget();
1252 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1256 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1258 // A bit of optimization to help sort out the flickers.
1259 int oldX
, oldY
, oldW
, oldH
;
1260 GetSize(& oldW
, & oldH
);
1261 GetPosition(& oldX
, & oldY
);
1263 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1276 bool nothingChanged
= (x
== oldX
) && (y
== oldY
) &&
1277 (width
== oldW
) && (height
== oldH
);
1279 if (!wxNoOptimize::CanOptimize())
1281 nothingChanged
= FALSE
;
1284 if ( !nothingChanged
)
1288 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1292 Widget widget
= (Widget
) GetTopWidget();
1296 bool managed
= XtIsManaged( widget
);
1298 XtUnmanageChild(widget
);
1302 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1304 DoMoveWindow(xx
, yy
, width
, height
);
1307 XtManageChild(widget
);
1309 // How about this bit. Maybe we don't need to generate size events
1310 // all the time -- they'll be generated when the window is sized anyway.
1312 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1313 sizeEvent
.SetEventObject(this);
1315 GetEventHandler()->ProcessEvent(sizeEvent
);
1320 void wxWindow::DoSetClientSize(int width
, int height
)
1324 CanvasSetClientSize(width
, height
);
1328 Widget widget
= (Widget
) GetTopWidget();
1331 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1333 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1335 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1336 sizeEvent
.SetEventObject(this);
1338 GetEventHandler()->ProcessEvent(sizeEvent
);
1341 // For implementation purposes - sometimes decorations make the client area
1343 wxPoint
wxWindow::GetClientAreaOrigin() const
1345 return wxPoint(0, 0);
1348 // Makes an adjustment to the window position (for example, a frame that has
1349 // a toolbar that it manages itself).
1350 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1352 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1354 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1355 x
+= pt
.x
; y
+= pt
.y
;
1359 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1366 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1369 // TODO what about dialogs?
1373 Widget widget
= (Widget
) frame
->GetShellWidget();
1376 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1378 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1380 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1382 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1384 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1386 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1389 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1391 XtVaSetValues((Widget
)GetTopWidget(),
1399 // ---------------------------------------------------------------------------
1401 // ---------------------------------------------------------------------------
1403 int wxWindow::GetCharHeight() const
1405 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1407 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1409 int direction
, ascent
, descent
;
1410 XCharStruct overall
;
1411 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1412 &descent
, &overall
);
1414 // return (overall.ascent + overall.descent);
1415 return (ascent
+ descent
);
1418 int wxWindow::GetCharWidth() const
1420 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1422 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1424 int direction
, ascent
, descent
;
1425 XCharStruct overall
;
1426 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1427 &descent
, &overall
);
1429 return overall
.width
;
1432 void wxWindow::GetTextExtent(const wxString
& string
,
1434 int *descent
, int *externalLeading
,
1435 const wxFont
*theFont
) const
1437 wxFont
*fontToUse
= (wxFont
*)theFont
;
1439 fontToUse
= (wxFont
*) & m_font
;
1441 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1443 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1445 int direction
, ascent
, descent2
;
1446 XCharStruct overall
;
1447 int slen
= string
.Len();
1451 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1452 &ascent
, &descent2
, &overall
);
1455 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1456 &direction
, &ascent
, &descent2
, &overall
);
1459 *x
= (overall
.width
);
1461 *y
= (ascent
+ descent2
);
1463 *descent
= descent2
;
1464 if (externalLeading
)
1465 *externalLeading
= 0;
1469 // ----------------------------------------------------------------------------
1471 // ----------------------------------------------------------------------------
1473 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1475 m_needsRefresh
= TRUE
;
1476 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1477 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1479 XExposeEvent dummyEvent
;
1481 GetSize(&width
, &height
);
1483 dummyEvent
.type
= Expose
;
1484 dummyEvent
.display
= display
;
1485 dummyEvent
.send_event
= True
;
1486 dummyEvent
.window
= thisWindow
;
1489 dummyEvent
.x
= rect
->x
;
1490 dummyEvent
.y
= rect
->y
;
1491 dummyEvent
.width
= rect
->width
;
1492 dummyEvent
.height
= rect
->height
;
1498 dummyEvent
.width
= width
;
1499 dummyEvent
.height
= height
;
1501 dummyEvent
.count
= 0;
1505 wxClientDC
dc(this);
1506 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1507 dc
.SetBackground(backgroundBrush
);
1514 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1517 void wxWindow::Clear()
1519 wxClientDC
dc(this);
1520 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1521 dc
.SetBackground(brush
);
1525 void wxWindow::ClearUpdateRects()
1527 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1530 wxRect
* rect
= node
->GetData();
1532 node
= node
->GetNext();
1535 m_updateRects
.Clear();
1538 void wxWindow::DoPaint()
1540 //TODO : make a temporary gc so we can do the XCopyArea below
1541 if (m_backingPixmap
&& !m_needsRefresh
)
1545 GC tempGC
= (GC
) dc
.GetBackingGC();
1547 Widget widget
= (Widget
) GetMainWidget();
1552 // We have to test whether it's a wxScrolledWindow (hack!) because
1553 // otherwise we don't know how many pixels have been scrolled. We might
1554 // solve this in the future by defining virtual wxWindow functions to get
1555 // the scroll position in pixels. Or, each kind of scrolled window has to
1556 // implement backing stores itself, using generic wxWindows code.
1557 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1558 if ( scrolledWindow
)
1561 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1567 // TODO: This could be optimized further by only copying the areas in the
1568 // current update region.
1570 // Only blit the part visible in the client area. The backing pixmap
1571 // always starts at 0, 0 but we may be looking at only a portion of it.
1572 wxSize clientArea
= GetClientSize();
1573 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1574 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1576 // Copy whichever is samller, the amount of pixmap we have to copy,
1577 // or the size of the client area.
1578 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1579 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1581 // Make sure we're not negative
1582 toBlitX
= wxMax(0, toBlitX
);
1583 toBlitY
= wxMax(0, toBlitY
);
1588 (Pixmap
) m_backingPixmap
,
1591 scrollPosX
, scrollPosY
, // Start at the scroll position
1592 toBlitX
, toBlitY
, // How much of the pixmap to copy
1598 // Set an erase event first
1599 wxEraseEvent
eraseEvent(GetId());
1600 eraseEvent
.SetEventObject(this);
1601 GetEventHandler()->ProcessEvent(eraseEvent
);
1603 wxPaintEvent
event(GetId());
1604 event
.SetEventObject(this);
1605 GetEventHandler()->ProcessEvent(event
);
1607 m_needsRefresh
= FALSE
;
1611 // ----------------------------------------------------------------------------
1613 // ----------------------------------------------------------------------------
1615 // Responds to colour changes: passes event on to children.
1616 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1618 wxWindowList::Node
*node
= GetChildren().GetFirst();
1621 // Only propagate to non-top-level windows
1622 wxWindow
*win
= node
->GetData();
1623 if ( win
->GetParent() )
1625 wxSysColourChangedEvent event2
;
1626 event
.m_eventObject
= win
;
1627 win
->GetEventHandler()->ProcessEvent(event2
);
1630 node
= node
->GetNext();
1634 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1636 // This calls the UI-update mechanism (querying windows for
1637 // menu/toolbar/control state information)
1641 // ----------------------------------------------------------------------------
1643 // ----------------------------------------------------------------------------
1645 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1647 if (!m_acceleratorTable
.Ok())
1650 int count
= m_acceleratorTable
.GetCount();
1651 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1653 for (i
= 0; i
< count
; i
++)
1655 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1656 if (entry
->MatchesEvent(event
))
1658 // Bingo, we have a match. Now find a control that matches the entry
1661 // Need to go up to the top of the window hierarchy, since it might
1662 // be e.g. a menu item
1663 wxWindow
* parent
= this;
1664 while ( parent
&& !parent
->IsTopLevel() )
1665 parent
= parent
->GetParent();
1670 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1673 // Try for a menu command
1674 if (frame
->GetMenuBar())
1676 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1679 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1680 commandEvent
.SetEventObject(frame
);
1682 // If ProcessEvent returns TRUE (it was handled), then
1683 // the calling code will skip the event handling.
1684 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1689 // Find a child matching the command id
1690 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1696 // Now we process those kinds of windows that we can.
1697 // For now, only buttons.
1698 if ( wxDynamicCast(child
, wxButton
) )
1700 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1701 commandEvent
.SetEventObject(child
);
1702 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1709 // We didn't match the key event against an accelerator.
1713 // ============================================================================
1714 // Motif-specific stuff from here on
1715 // ============================================================================
1717 // ----------------------------------------------------------------------------
1718 // function which maintain the global hash table mapping Widgets to wxWindows
1719 // ----------------------------------------------------------------------------
1721 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1723 wxWindow
*oldItem
= NULL
;
1724 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1726 wxLogDebug("Widget table clash: new widget is %ld, %s",
1727 (long)w
, win
->GetClassInfo()->GetClassName());
1731 wxWidgetHashTable
->Put((long) w
, win
);
1733 wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)",
1734 w
, win
, win
->GetClassInfo()->GetClassName());
1739 wxWindow
*wxGetWindowFromTable(Widget w
)
1741 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1744 void wxDeleteWindowFromTable(Widget w
)
1746 wxWidgetHashTable
->Delete((long)w
);
1749 // ----------------------------------------------------------------------------
1750 // add/remove window from the table
1751 // ----------------------------------------------------------------------------
1753 // Add to hash table, add event handler
1754 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1755 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1757 wxAddWindowToTable((Widget
) mainWidget
, this);
1758 if (CanAddEventHandler())
1760 XtAddEventHandler((Widget
) mainWidget
,
1761 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1763 wxPanelItemEventHandler
,
1770 XtOverrideTranslations ((Widget
) mainWidget
,
1771 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1772 XtFree ((char *) ptr
);
1775 // Some widgets have a parent form widget, e.g. wxRadioBox
1778 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1782 XtOverrideTranslations ((Widget
) formWidget
,
1783 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1784 XtFree ((char *) ptr
);
1791 SetSize (x
, y
, width
, height
);
1796 // Remove event handler, remove from hash table
1797 bool wxWindow::DetachWidget(WXWidget widget
)
1799 if (CanAddEventHandler())
1801 XtRemoveEventHandler((Widget
) widget
,
1802 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1804 wxPanelItemEventHandler
,
1808 wxDeleteWindowFromTable((Widget
) widget
);
1812 // ----------------------------------------------------------------------------
1813 // Motif-specific accessors
1814 // ----------------------------------------------------------------------------
1816 // Get the underlying X window
1817 WXWindow
wxWindow::GetXWindow() const
1819 Widget wMain
= (Widget
)GetMainWidget();
1821 return (WXWindow
) XtWindow(wMain
);
1823 return (WXWindow
) 0;
1826 // Get the underlying X display
1827 WXDisplay
*wxWindow::GetXDisplay() const
1829 Widget wMain
= (Widget
)GetMainWidget();
1831 return (WXDisplay
*) XtDisplay(wMain
);
1833 return (WXDisplay
*) NULL
;
1836 WXWidget
wxWindow::GetMainWidget() const
1839 return m_drawingArea
;
1841 return m_mainWidget
;
1844 WXWidget
wxWindow::GetClientWidget() const
1846 if (m_drawingArea
!= (WXWidget
) 0)
1847 return m_drawingArea
;
1849 return GetMainWidget();
1852 WXWidget
wxWindow::GetTopWidget() const
1854 return GetMainWidget();
1857 WXWidget
wxWindow::GetLabelWidget() const
1859 return GetMainWidget();
1862 // ----------------------------------------------------------------------------
1864 // ----------------------------------------------------------------------------
1866 // All widgets should have this as their resize proc.
1867 // OnSize sent to wxWindow via client data.
1868 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1870 wxWindow
*win
= wxGetWindowFromTable(w
);
1874 if (win
->PreResize())
1877 win
->GetSize(&width
, &height
);
1878 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1879 sizeEvent
.SetEventObject(win
);
1880 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1884 static void wxCanvasRepaintProc(Widget drawingArea
,
1885 XtPointer clientData
,
1886 XmDrawingAreaCallbackStruct
* cbs
)
1888 if (!wxGetWindowFromTable(drawingArea
))
1891 XEvent
* event
= cbs
->event
;
1892 wxWindow
* win
= (wxWindow
*) clientData
;
1894 switch (event
->type
)
1898 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1899 event
->xexpose
.width
, event
->xexpose
.height
);
1901 if (event
-> xexpose
.count
== 0)
1904 win
->ClearUpdateRects();
1911 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1912 static void wxCanvasEnterLeave(Widget drawingArea
,
1913 XtPointer
WXUNUSED(clientData
),
1914 XCrossingEvent
* event
)
1916 XmDrawingAreaCallbackStruct cbs
;
1919 ((XCrossingEvent
&) ev
) = *event
;
1921 cbs
.reason
= XmCR_INPUT
;
1924 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1927 // Fix to make it work under Motif 1.0 (!)
1928 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1930 #if XmVersion <= 1000
1931 XmDrawingAreaCallbackStruct cbs
;
1934 ev
= *((XEvent
*) event
);
1935 cbs
.reason
= XmCR_INPUT
;
1938 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1939 #endif // XmVersion <= 1000
1942 static void wxCanvasInputEvent(Widget drawingArea
,
1943 XtPointer
WXUNUSED(data
),
1944 XmDrawingAreaCallbackStruct
* cbs
)
1946 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1952 if (cbs
->reason
!= XmCR_INPUT
)
1955 local_event
= *(cbs
->event
); // We must keep a copy!
1957 switch (local_event
.xany
.type
)
1965 // FIXME: most of this mouse event code is more or less
1966 // duplicated in wxTranslateMouseEvent
1968 wxEventType eventType
= wxEVT_NULL
;
1970 if (local_event
.xany
.type
== EnterNotify
)
1972 //if (local_event.xcrossing.mode!=NotifyNormal)
1973 // return ; // Ignore grab events
1974 eventType
= wxEVT_ENTER_WINDOW
;
1975 // canvas->GetEventHandler()->OnSetFocus();
1977 else if (local_event
.xany
.type
== LeaveNotify
)
1979 //if (local_event.xcrossingr.mode!=NotifyNormal)
1980 // return ; // Ignore grab events
1981 eventType
= wxEVT_LEAVE_WINDOW
;
1982 // canvas->GetEventHandler()->OnKillFocus();
1984 else if (local_event
.xany
.type
== MotionNotify
)
1986 eventType
= wxEVT_MOTION
;
1989 else if (local_event
.xany
.type
== ButtonPress
)
1991 if (local_event
.xbutton
.button
== Button1
)
1993 eventType
= wxEVT_LEFT_DOWN
;
1994 canvas
->SetButton1(TRUE
);
1996 else if (local_event
.xbutton
.button
== Button2
)
1998 eventType
= wxEVT_MIDDLE_DOWN
;
1999 canvas
->SetButton2(TRUE
);
2001 else if (local_event
.xbutton
.button
== Button3
)
2003 eventType
= wxEVT_RIGHT_DOWN
;
2004 canvas
->SetButton3(TRUE
);
2007 else if (local_event
.xany
.type
== ButtonRelease
)
2009 if (local_event
.xbutton
.button
== Button1
)
2011 eventType
= wxEVT_LEFT_UP
;
2012 canvas
->SetButton1(FALSE
);
2014 else if (local_event
.xbutton
.button
== Button2
)
2016 eventType
= wxEVT_MIDDLE_UP
;
2017 canvas
->SetButton2(FALSE
);
2019 else if (local_event
.xbutton
.button
== Button3
)
2021 eventType
= wxEVT_RIGHT_UP
;
2022 canvas
->SetButton3(FALSE
);
2026 wxMouseEvent
wxevent (eventType
);
2028 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2029 || (event_left_is_down (&local_event
)
2030 && (eventType
!= wxEVT_LEFT_UP
)));
2031 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2032 || (event_middle_is_down (&local_event
)
2033 && (eventType
!= wxEVT_MIDDLE_UP
)));
2034 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2035 || (event_right_is_down (&local_event
)
2036 && (eventType
!= wxEVT_RIGHT_UP
)));
2038 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2039 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2040 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2041 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2042 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2044 if ( eventType
== wxEVT_MOTION
)
2046 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2049 Display
*dpy
= XtDisplay (drawingArea
);
2051 XQueryPointer (dpy
, XtWindow (drawingArea
),
2053 &local_event
.xmotion
.x_root
,
2054 &local_event
.xmotion
.y_root
,
2055 &local_event
.xmotion
.x
,
2056 &local_event
.xmotion
.y
,
2057 &local_event
.xmotion
.state
);
2064 // Now check if we need to translate this event into a double click
2065 if (TRUE
) // canvas->doubleClickAllowed)
2067 if (wxevent
.ButtonDown())
2069 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2071 // get button and time-stamp
2073 if (wxevent
.LeftDown())
2075 else if (wxevent
.MiddleDown())
2077 else if (wxevent
.RightDown())
2079 long ts
= wxevent
.GetTimestamp();
2081 // check, if single or double click
2082 int buttonLast
= canvas
->GetLastClickedButton();
2083 long lastTS
= canvas
->GetLastClickTime();
2084 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2087 canvas
->SetLastClick(0, ts
);
2088 switch ( eventType
)
2090 case wxEVT_LEFT_DOWN
:
2091 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2093 case wxEVT_MIDDLE_DOWN
:
2094 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2096 case wxEVT_RIGHT_DOWN
:
2097 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2107 // not fast enough or different button
2108 canvas
->SetLastClick(button
, ts
);
2113 wxevent
.SetId(canvas
->GetId());
2114 wxevent
.SetEventObject(canvas
);
2115 wxevent
.m_x
= local_event
.xbutton
.x
;
2116 wxevent
.m_y
= local_event
.xbutton
.y
;
2117 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2119 if (eventType
== wxEVT_ENTER_WINDOW
||
2120 eventType
== wxEVT_LEAVE_WINDOW
||
2121 eventType
== wxEVT_MOTION
2131 XComposeStatus compose
;
2132 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2135 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2136 int id
= wxCharCodeXToWX (keySym
);
2138 wxEventType eventType
= wxEVT_CHAR
;
2140 wxKeyEvent
event (eventType
);
2142 if (local_event
.xkey
.state
& ShiftMask
)
2143 event
.m_shiftDown
= TRUE
;
2144 if (local_event
.xkey
.state
& ControlMask
)
2145 event
.m_controlDown
= TRUE
;
2146 if (local_event
.xkey
.state
& Mod3Mask
)
2147 event
.m_altDown
= TRUE
;
2148 if (local_event
.xkey
.state
& Mod1Mask
)
2149 event
.m_metaDown
= TRUE
;
2150 event
.SetEventObject(canvas
);
2151 event
.m_keyCode
= id
;
2152 event
.SetTimestamp(local_event
.xkey
.time
);
2156 // Implement wxFrame::OnCharHook by checking ancestor.
2157 wxWindow
*parent
= canvas
->GetParent();
2158 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2159 parent
= parent
->GetParent();
2163 event
.SetEventType(wxEVT_CHAR_HOOK
);
2164 if (parent
->GetEventHandler()->ProcessEvent(event
))
2168 // For simplicity, OnKeyDown is the same as OnChar
2169 // TODO: filter modifier key presses from OnChar
2170 event
.SetEventType(wxEVT_KEY_DOWN
);
2172 // Only process OnChar if OnKeyDown didn't swallow it
2173 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2175 event
.SetEventType(wxEVT_CHAR
);
2176 canvas
->GetEventHandler()->ProcessEvent (event
);
2184 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2185 int id
= wxCharCodeXToWX (keySym
);
2187 wxKeyEvent
event (wxEVT_KEY_UP
);
2189 if (local_event
.xkey
.state
& ShiftMask
)
2190 event
.m_shiftDown
= TRUE
;
2191 if (local_event
.xkey
.state
& ControlMask
)
2192 event
.m_controlDown
= TRUE
;
2193 if (local_event
.xkey
.state
& Mod3Mask
)
2194 event
.m_altDown
= TRUE
;
2195 if (local_event
.xkey
.state
& Mod1Mask
)
2196 event
.m_metaDown
= TRUE
;
2197 event
.SetEventObject(canvas
);
2198 event
.m_keyCode
= id
;
2199 event
.SetTimestamp(local_event
.xkey
.time
);
2203 canvas
->GetEventHandler()->ProcessEvent (event
);
2209 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2211 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2212 event
.SetEventObject(canvas
);
2213 canvas
->GetEventHandler()->ProcessEvent(event
);
2219 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2221 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2222 event
.SetEventObject(canvas
);
2223 canvas
->GetEventHandler()->ProcessEvent(event
);
2232 static void wxPanelItemEventHandler(Widget wid
,
2233 XtPointer
WXUNUSED(client_data
),
2235 Boolean
*continueToDispatch
)
2237 // Widget can be a label or the actual widget.
2239 wxWindow
*window
= wxGetWindowFromTable(wid
);
2242 wxMouseEvent
wxevent(0);
2243 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2245 window
->GetEventHandler()->ProcessEvent(wxevent
);
2249 // TODO: probably the key to allowing default behaviour to happen. Say we
2250 // set a m_doDefault flag to FALSE at the start of this function. Then in
2251 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2252 // TRUE, indicating that default processing can happen. Thus, behaviour can
2253 // appear to be overridden just by adding an event handler and not calling
2254 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2255 // way of handling drawing area events, to simplify things.
2256 *continueToDispatch
= True
;
2259 static void wxScrollBarCallback(Widget scrollbar
,
2260 XtPointer clientData
,
2261 XmScrollBarCallbackStruct
*cbs
)
2263 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2264 int orientation
= (int) clientData
;
2266 wxEventType eventType
= wxEVT_NULL
;
2267 switch (cbs
->reason
)
2269 case XmCR_INCREMENT
:
2271 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2274 case XmCR_DECREMENT
:
2276 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2281 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2284 case XmCR_VALUE_CHANGED
:
2286 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2289 case XmCR_PAGE_INCREMENT
:
2291 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2294 case XmCR_PAGE_DECREMENT
:
2296 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2301 eventType
= wxEVT_SCROLLWIN_TOP
;
2304 case XmCR_TO_BOTTOM
:
2306 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2311 // Should never get here
2312 wxFAIL_MSG("Unknown scroll event.");
2317 wxScrollWinEvent
event(eventType
,
2319 ((orientation
== XmHORIZONTAL
) ?
2320 wxHORIZONTAL
: wxVERTICAL
));
2321 event
.SetEventObject( win
);
2322 win
->GetEventHandler()->ProcessEvent(event
);
2325 // For repainting arbitrary windows
2326 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2331 wxWindow
* win
= wxGetWindowFromTable(w
);
2335 switch(event
-> type
)
2339 window
= (Window
) win
-> GetXWindow();
2340 display
= (Display
*) win
-> GetXDisplay();
2342 if (event
-> xexpose
.count
== 0)
2346 win
->ClearUpdateRects();
2350 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2351 event
->xexpose
.width
, event
->xexpose
.height
);
2359 // ----------------------------------------------------------------------------
2360 // CanvaseXXXSize() functions
2361 // ----------------------------------------------------------------------------
2363 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2364 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2366 // A bit of optimization to help sort out the flickers.
2367 int oldX
, oldY
, oldW
, oldH
;
2368 GetSize(& oldW
, & oldH
);
2369 GetPosition(& oldX
, & oldY
);
2371 bool useOldPos
= FALSE
;
2372 bool useOldSize
= FALSE
;
2374 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2376 else if (x
== oldX
&& y
== oldY
)
2379 if ((w
== -1) && (h
== -1))
2381 else if (w
== oldW
&& h
== oldH
)
2384 if (!wxNoOptimize::CanOptimize())
2386 useOldSize
= FALSE
; useOldPos
= FALSE
;
2389 if (useOldPos
&& useOldSize
)
2392 Widget drawingArea
= (Widget
) m_drawingArea
;
2393 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2396 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2397 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2399 int xx
= x
; int yy
= y
;
2400 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2404 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2406 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2410 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2412 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2424 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2425 short thick
, margin
;
2426 XtVaGetValues ((Widget
) m_borderWidget
,
2427 XmNshadowThickness
, &thick
,
2428 XmNmarginWidth
, &margin
,
2430 w
-= 2 * (thick
+ margin
);
2433 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2437 XtVaGetValues ((Widget
) m_scrolledWindow
,
2438 XmNspacing
, &spacing
,
2439 XmNverticalScrollBar
, &sbar
,
2443 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2447 w
-= (spacing
+ wsbar
);
2450 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2457 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2458 short thick
, margin
;
2459 XtVaGetValues ((Widget
) m_borderWidget
,
2460 XmNshadowThickness
, &thick
,
2461 XmNmarginHeight
, &margin
,
2463 h
-= 2 * (thick
+ margin
);
2466 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2470 XtVaGetValues ((Widget
) m_scrolledWindow
,
2471 XmNspacing
, &spacing
,
2472 XmNhorizontalScrollBar
, &sbar
,
2476 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2480 h
-= (spacing
+ wsbar
);
2483 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2489 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2490 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2494 GetClientSize (&ww
, &hh
);
2495 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2496 sizeEvent
.SetEventObject(this);
2498 GetEventHandler()->ProcessEvent(sizeEvent
);
2502 void wxWindow::CanvasSetClientSize (int w
, int h
)
2504 Widget drawingArea
= (Widget
) m_drawingArea
;
2506 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2509 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2511 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2514 // TODO: is this necessary?
2515 allowRepainting
= FALSE
;
2517 XSync (XtDisplay (drawingArea
), FALSE
);
2519 while (XtAppPending (wxTheApp
->appContext
))
2521 XFlush (XtDisplay (drawingArea
));
2522 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2523 XtDispatchEvent (&event
);
2527 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2530 allowRepainting
= TRUE
;
2533 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2534 sizeEvent
.SetEventObject(this);
2536 GetEventHandler()->ProcessEvent(sizeEvent
);
2540 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2542 // Must return the same thing that was set via SetClientSize
2544 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2549 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2552 if ((Widget
) m_borderWidget
)
2553 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2554 else if ((Widget
) m_scrolledWindow
)
2555 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2557 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2563 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2566 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2568 // We may be faking the client origin.
2569 // So a window that's really at (0, 30) may appear
2570 // (to wxWin apps) to be at (0, 0).
2573 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2582 // ----------------------------------------------------------------------------
2583 // TranslateXXXEvent() functions
2584 // ----------------------------------------------------------------------------
2586 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2588 switch (xevent
->xany
.type
)
2590 case EnterNotify
: // never received here - yes ? MB
2591 case LeaveNotify
: // never received here - yes ? MB
2596 wxEventType eventType
= wxEVT_NULL
;
2598 // FIXME: this is never true I think - MB
2600 if (xevent
->xany
.type
== LeaveNotify
)
2602 win
->SetButton1(FALSE
);
2603 win
->SetButton2(FALSE
);
2604 win
->SetButton3(FALSE
);
2607 else if (xevent
->xany
.type
== MotionNotify
)
2609 eventType
= wxEVT_MOTION
;
2611 else if (xevent
->xany
.type
== ButtonPress
)
2613 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2615 if (xevent
->xbutton
.button
== Button1
)
2617 eventType
= wxEVT_LEFT_DOWN
;
2618 win
->SetButton1(TRUE
);
2621 else if (xevent
->xbutton
.button
== Button2
)
2623 eventType
= wxEVT_MIDDLE_DOWN
;
2624 win
->SetButton2(TRUE
);
2627 else if (xevent
->xbutton
.button
== Button3
)
2629 eventType
= wxEVT_RIGHT_DOWN
;
2630 win
->SetButton3(TRUE
);
2634 // check for a double click
2636 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2637 long ts
= wxevent
.GetTimestamp();
2639 int buttonLast
= win
->GetLastClickedButton();
2640 long lastTS
= win
->GetLastClickTime();
2641 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2644 win
->SetLastClick(0, ts
);
2645 switch ( eventType
)
2647 case wxEVT_LEFT_DOWN
:
2648 eventType
= wxEVT_LEFT_DCLICK
;
2650 case wxEVT_MIDDLE_DOWN
:
2651 eventType
= wxEVT_MIDDLE_DCLICK
;
2653 case wxEVT_RIGHT_DOWN
:
2654 eventType
= wxEVT_RIGHT_DCLICK
;
2664 // not fast enough or different button
2665 win
->SetLastClick(button
, ts
);
2668 else if (xevent
->xany
.type
== ButtonRelease
)
2670 if (xevent
->xbutton
.button
== Button1
)
2672 eventType
= wxEVT_LEFT_UP
;
2673 win
->SetButton1(FALSE
);
2675 else if (xevent
->xbutton
.button
== Button2
)
2677 eventType
= wxEVT_MIDDLE_UP
;
2678 win
->SetButton2(FALSE
);
2680 else if (xevent
->xbutton
.button
== Button3
)
2682 eventType
= wxEVT_RIGHT_UP
;
2683 win
->SetButton3(FALSE
);
2692 wxevent
.SetEventType(eventType
);
2695 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2698 win
->GetPosition(&x2
, &y2
);
2700 // The button x/y must be translated to wxWindows
2701 // window space - the widget might be a label or button,
2705 if (widget
!= (Widget
)win
->GetMainWidget())
2711 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2712 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2714 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2715 || (event_left_is_down (xevent
)
2716 && (eventType
!= wxEVT_LEFT_UP
)));
2717 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2718 || (event_middle_is_down (xevent
)
2719 && (eventType
!= wxEVT_MIDDLE_UP
)));
2720 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2721 || (event_right_is_down (xevent
)
2722 && (eventType
!= wxEVT_RIGHT_UP
)));
2724 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2725 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2726 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2727 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2729 wxevent
.SetId(win
->GetId());
2730 wxevent
.SetEventObject(win
);
2738 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2740 switch (xevent
->xany
.type
)
2749 XComposeStatus compose
;
2750 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2752 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2753 int id
= wxCharCodeXToWX (keySym
);
2755 if (xevent
->xkey
.state
& ShiftMask
)
2756 wxevent
.m_shiftDown
= TRUE
;
2757 if (xevent
->xkey
.state
& ControlMask
)
2758 wxevent
.m_controlDown
= TRUE
;
2759 if (xevent
->xkey
.state
& Mod3Mask
)
2760 wxevent
.m_altDown
= TRUE
;
2761 if (xevent
->xkey
.state
& Mod1Mask
)
2762 wxevent
.m_metaDown
= TRUE
;
2763 wxevent
.SetEventObject(win
);
2764 wxevent
.m_keyCode
= id
;
2765 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2767 wxevent
.m_x
= xevent
->xbutton
.x
;
2768 wxevent
.m_y
= xevent
->xbutton
.y
;
2782 // ----------------------------------------------------------------------------
2784 // ----------------------------------------------------------------------------
2786 #define YAllocColor XAllocColor
2787 XColor g_itemColors
[5];
2788 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2791 static XmColorProc colorProc
;
2793 result
= wxNO_COLORS
;
2797 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2798 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2799 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2800 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2801 if (colorProc
== (XmColorProc
) NULL
)
2803 // Get a ptr to the actual function
2804 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2805 // And set it back to motif.
2806 XmSetColorCalculation (colorProc
);
2808 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2809 &g_itemColors
[wxFORE_INDEX
],
2810 &g_itemColors
[wxSELE_INDEX
],
2811 &g_itemColors
[wxTOPS_INDEX
],
2812 &g_itemColors
[wxBOTS_INDEX
]);
2813 result
= wxBACK_COLORS
;
2817 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2818 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2819 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2820 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2821 if (result
== wxNO_COLORS
)
2822 result
= wxFORE_COLORS
;
2825 Display
*dpy
= display
;
2826 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2830 /* 5 Colours to allocate */
2831 for (int i
= 0; i
< 5; i
++)
2832 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2833 result
= wxNO_COLORS
;
2837 /* Only 1 colour to allocate */
2838 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2839 result
= wxNO_COLORS
;
2846 // Changes the foreground and background colours to be derived from the current
2847 // background colour. To change the foreground colour, you must call
2848 // SetForegroundColour explicitly.
2849 void wxWindow::ChangeBackgroundColour()
2851 WXWidget mainWidget
= GetMainWidget();
2853 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2855 // This not necessary
2858 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2860 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2861 // Have to set the scrollbar colours back since
2862 // the scrolled window seemed to change them
2863 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2866 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2868 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2873 void wxWindow::ChangeForegroundColour()
2875 WXWidget mainWidget
= GetMainWidget();
2877 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2878 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2879 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2882 // Change a widget's foreground and background colours.
2883 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2885 // When should we specify the foreground, if it's calculated
2886 // by wxComputeColours?
2887 // Solution: say we start with the default (computed) foreground colour.
2888 // If we call SetForegroundColour explicitly for a control or window,
2889 // then the foreground is changed.
2890 // Therefore SetBackgroundColour computes the foreground colour, and
2891 // SetForegroundColour changes the foreground colour. The ordering is
2894 Widget w
= (Widget
)widget
;
2897 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2902 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2904 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2907 XtVaSetValues ((Widget
) widget
,
2908 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2909 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2910 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2911 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2914 if (changeArmColour
)
2915 XtVaSetValues ((Widget
) widget
,
2916 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2920 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2922 if ( !wxWindowBase::SetBackgroundColour(col
) )
2925 ChangeBackgroundColour();
2930 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2932 if ( !wxWindowBase::SetForegroundColour(col
) )
2935 ChangeForegroundColour();
2940 void wxWindow::ChangeFont(bool keepOriginalSize
)
2942 // Note that this causes the widget to be resized back
2943 // to its original size! We therefore have to set the size
2944 // back again. TODO: a better way in Motif?
2945 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2946 if (w
&& m_font
.Ok())
2948 int width
, height
, width1
, height1
;
2949 GetSize(& width
, & height
);
2951 // lesstif 0.87 hangs here
2952 #ifndef LESSTIF_VERSION
2954 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2958 GetSize(& width1
, & height1
);
2959 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2961 SetSize(-1, -1, width
, height
);
2966 // ----------------------------------------------------------------------------
2968 // ----------------------------------------------------------------------------
2970 wxWindow
*wxGetActiveWindow()
2976 // ----------------------------------------------------------------------------
2977 // wxNoOptimize: switch off size optimization
2978 // ----------------------------------------------------------------------------
2980 int wxNoOptimize::ms_count
= 0;