1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "window.h"
25 #define XtDisplay XTDISPLAY
26 #define XtWindow XTWINDOW
27 #define XtScreen XTSCREEN
33 #include "wx/dcclient.h"
37 #include "wx/layout.h"
38 #include "wx/dialog.h"
39 #include "wx/listbox.h"
40 #include "wx/button.h"
41 #include "wx/settings.h"
42 #include "wx/msgdlg.h"
44 #include "wx/scrolwin.h"
45 #include "wx/module.h"
46 #include "wx/menuitem.h"
49 #if wxUSE_DRAG_AND_DROP
54 #pragma message disable nosimpint
58 #include <Xm/DrawingA.h>
59 #include <Xm/ScrolledW.h>
60 #include <Xm/ScrollBar.h>
63 #include <Xm/RowColumn.h> // for XmMenuPosition
65 #pragma message enable nosimpint
68 #include "wx/motif/private.h"
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 static const int SCROLL_MARGIN
= 4;
78 // ----------------------------------------------------------------------------
79 // global variables for this module
80 // ----------------------------------------------------------------------------
82 extern wxHashTable
*wxWidgetHashTable
;
83 static wxWindow
* g_captureWindow
= NULL
;
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 static void wxCanvasRepaintProc(Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
91 static void wxCanvasInputEvent(Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
92 static void wxCanvasMotionEvent(Widget
, XButtonEvent
* event
);
93 static void wxCanvasEnterLeave(Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
94 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
95 XmScrollBarCallbackStruct
*cbs
);
96 static void wxPanelItemEventHandler(Widget wid
,
97 XtPointer client_data
,
99 Boolean
*continueToDispatch
);
104 // Helper function for 16-bit fonts
105 static int str16len(const char *s
)
109 while (s
[0] && s
[1]) {
119 // ----------------------------------------------------------------------------
121 // ----------------------------------------------------------------------------
123 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
124 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
125 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
127 // ----------------------------------------------------------------------------
129 // ----------------------------------------------------------------------------
131 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxWindowBase
)
133 BEGIN_EVENT_TABLE(wxWindow
, wxWindowBase
)
134 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
135 EVT_IDLE(wxWindow::OnIdle
)
138 // ============================================================================
140 // ============================================================================
142 // ----------------------------------------------------------------------------
144 // ----------------------------------------------------------------------------
146 void wxWindow::UnmanageAndDestroy(WXWidget widget
)
148 Widget w
= (Widget
)widget
;
156 bool wxWindow::MapOrUnmap(WXWidget widget
, bool map
)
158 Widget w
= (Widget
)widget
;
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 void wxWindow::Init()
176 // generic initializations first
180 m_needsRefresh
= TRUE
;
181 m_mainWidget
= (WXWidget
) 0;
185 m_button3Pressed
= FALSE
;
187 m_winCaptured
= FALSE
;
190 m_isBeingDeleted
= FALSE
;
196 m_drawingArea
= (WXWidget
) 0;
204 m_backingPixmap
= (WXPixmap
) 0;
213 m_canAddEventHandler
= FALSE
;
216 // real construction (Init() must have been called before!)
217 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
221 const wxString
& name
)
223 wxCHECK_MSG( parent
, FALSE
, "can't create wxWindow without parent" );
225 CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
);
227 parent
->AddChild(this);
229 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
230 m_foregroundColour
= *wxBLACK
;
232 //// TODO: we should probably optimize by only creating a
233 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
234 //// But for now, let's simplify things by always creating the
235 //// drawing area, since otherwise the translations are different.
237 // New translations for getting mouse motion feedback
238 static const String translations
=
239 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
240 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
241 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
242 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
243 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
244 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
245 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
246 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
247 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
248 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
249 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
250 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
251 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
252 <Key>: DrawingAreaInput()";
254 XtActionsRec actions
[1];
255 actions
[0].string
= "wxCanvasMotionEvent";
256 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
257 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
259 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
261 if (style
& wxSIMPLE_BORDER
)
263 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
266 xmFrameWidgetClass
, parentWidget
,
267 XmNshadowType
, XmSHADOW_IN
,
268 XmNshadowThickness
, 1,
271 } else if (style
& wxSUNKEN_BORDER
)
273 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
276 xmFrameWidgetClass
, parentWidget
,
277 XmNshadowType
, XmSHADOW_IN
,
280 } else if (style
& wxRAISED_BORDER
)
282 m_borderWidget
= (WXWidget
)XtVaCreateManagedWidget
285 xmFrameWidgetClass
, parentWidget
,
286 XmNshadowType
, XmSHADOW_OUT
,
291 m_scrolledWindow
= (WXWidget
)XtVaCreateManagedWidget
294 xmScrolledWindowWidgetClass
,
295 m_borderWidget
? (Widget
) m_borderWidget
297 XmNresizePolicy
, XmRESIZE_NONE
,
299 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
300 //XmNscrollBarDisplayPolicy, XmAS_NEEDED,
304 XtTranslations ptr
= XtParseTranslationTable(translations
);
305 m_drawingArea
= (WXWidget
)XtVaCreateWidget
308 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
309 XmNunitType
, XmPIXELS
,
310 // XmNresizePolicy, XmRESIZE_ANY,
311 XmNresizePolicy
, XmRESIZE_NONE
,
314 XmNtranslations
, ptr
,
317 XtFree((char *) ptr
);
320 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS
)
322 ptr
= XtParseTranslationTable ("<Key>: DrawingAreaInput()");
323 XtOverrideTranslations ((Widget
) m_drawingArea
, ptr
);
324 XtFree ((char *) ptr
);
328 wxAddWindowToTable((Widget
) m_drawingArea
, this);
329 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
331 // This order is very important in Motif 1.2.1
332 XtRealizeWidget ((Widget
) m_scrolledWindow
);
333 XtRealizeWidget ((Widget
) m_drawingArea
);
334 XtManageChild ((Widget
) m_drawingArea
);
336 ptr
= XtParseTranslationTable("<Configure>: resize()");
337 XtOverrideTranslations((Widget
) m_drawingArea
, ptr
);
338 XtFree ((char *) ptr
);
340 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
341 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
345 display
= XtDisplay (scrolledWindow
);
346 xwindow
= XtWindow (drawingArea
);
350 (Widget
)m_drawingArea
,
351 PointerMotionHintMask
| EnterWindowMask
|
352 LeaveWindowMask
| FocusChangeMask
,
354 (XtEventHandler
) wxCanvasEnterLeave
,
358 // Scrolled widget needs to have its colour changed or we get a little blue
359 // square where the scrollbars abutt
360 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
361 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
362 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
364 XmScrolledWindowSetAreas(
365 (Widget
)m_scrolledWindow
,
366 (Widget
) 0, (Widget
) 0,
367 (Widget
) m_drawingArea
);
371 XtRealizeWidget ((Widget
) m_hScrollBar
);
373 XtRealizeWidget ((Widget
) m_vScrollBar
);
376 // Without this, the cursor may not be restored properly (e.g. in splitter
378 SetCursor(*wxSTANDARD_CURSOR
);
379 SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
380 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
386 wxWindow::~wxWindow()
388 if (g_captureWindow
== this)
389 g_captureWindow
= NULL
;
391 m_isBeingDeleted
= TRUE
;
393 // Motif-specific actions first
394 WXWidget wMain
= GetMainWidget();
397 // Removes event handlers
404 m_parent
->RemoveChild( this );
406 // If m_drawingArea, we're a fully-fledged window with drawing area,
407 // scrollbars etc. (what wxCanvas used to be)
410 // Destroy children before destroying self
414 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
416 Widget w
= (Widget
) m_drawingArea
;
417 wxDeleteWindowFromTable(w
);
422 m_drawingArea
= (WXWidget
) 0;
425 // Only if we're _really_ a canvas (not a dialog box/panel)
426 if (m_scrolledWindow
)
428 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
433 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
434 XtUnmanageChild((Widget
) m_hScrollBar
);
438 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
439 XtUnmanageChild((Widget
) m_vScrollBar
);
443 XtDestroyWidget((Widget
) m_hScrollBar
);
445 XtDestroyWidget((Widget
) m_vScrollBar
);
447 UnmanageAndDestroy(m_scrolledWindow
);
451 XtDestroyWidget ((Widget
) m_borderWidget
);
452 m_borderWidget
= (WXWidget
) 0;
455 else // Why wasn't this here before? JACS 8/3/2000
459 // Destroy the window
462 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
463 // Child widgets will get destroyed automatically when a frame
464 // or dialog is destroyed, but before that you may get some memory
465 // leaks and potential layout problems if you delete and then add
468 // GRG, Feb/2000: commented this out when adding support for
469 // wxSCROLL[WIN]_THUMBRELEASE events. Also it was reported
470 // that this call crashed wxMotif under OS/2, so it seems
471 // that leaving it out is the right thing to do.
472 // SN, Feb/2000: newgrid/griddemo shows why it is needed :-(
473 XtDestroyWidget((Widget
) GetMainWidget());
474 SetMainWidget((WXWidget
) NULL
);
478 // ----------------------------------------------------------------------------
479 // scrollbar management
480 // ----------------------------------------------------------------------------
483 void wxWindow::CreateScrollbar(wxOrientation orientation
)
485 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
487 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
489 // Add scrollbars if required
490 if (orientation
== wxHORIZONTAL
)
492 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
493 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
494 XmNorientation
, XmHORIZONTAL
,
496 XtAddCallback (hScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
497 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
498 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
499 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
500 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
501 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
502 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
503 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
505 XtVaSetValues (hScrollBar
,
510 m_hScrollBar
= (WXWidget
) hScrollBar
;
512 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
513 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
515 XtRealizeWidget(hScrollBar
);
517 XtVaSetValues((Widget
) m_scrolledWindow
,
518 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
523 wxAddWindowToTable( hScrollBar
, this );
526 if (orientation
== wxVERTICAL
)
528 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
529 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
530 XmNorientation
, XmVERTICAL
,
532 XtAddCallback (vScrollBar
, XmNvalueChangedCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
533 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
534 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
535 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
536 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
537 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
538 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
539 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
541 XtVaSetValues (vScrollBar
,
546 m_vScrollBar
= (WXWidget
) vScrollBar
;
547 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
548 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
550 XtRealizeWidget(vScrollBar
);
552 XtVaSetValues((Widget
) m_scrolledWindow
,
553 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
558 wxAddWindowToTable( vScrollBar
, this );
561 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
564 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
566 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
568 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
569 // Add scrollbars if required
570 if (orientation
== wxHORIZONTAL
)
574 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
575 XtDestroyWidget((Widget
) m_hScrollBar
);
577 m_hScrollBar
= (WXWidget
) 0;
580 XtVaSetValues((Widget
) m_scrolledWindow
,
581 XmNhorizontalScrollBar
, (Widget
) 0,
586 if (orientation
== wxVERTICAL
)
590 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
591 XtDestroyWidget((Widget
) m_vScrollBar
);
593 m_vScrollBar
= (WXWidget
) 0;
596 XtVaSetValues((Widget
) m_scrolledWindow
,
597 XmNverticalScrollBar
, (Widget
) 0,
601 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
604 // ---------------------------------------------------------------------------
606 // ---------------------------------------------------------------------------
608 void wxWindow::SetFocus()
610 Widget wMain
= (Widget
) GetMainWidget();
611 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
612 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
615 // Get the window with the focus
616 wxWindow
*wxWindowBase::FindFocus()
619 // (1) Can there be multiple focussed widgets in an application?
620 // In which case we need to find the top-level window that's
622 // (2) The widget with the focus may not be in the widget table
623 // depending on which widgets I put in the table
624 wxWindow
*winFocus
= (wxWindow
*)NULL
;
625 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
627 node
= node
->GetNext() )
629 wxWindow
*win
= node
->GetData();
631 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
633 if (w
!= (Widget
) NULL
)
635 winFocus
= wxGetWindowFromTable(w
);
644 bool wxWindow::Enable(bool enable
)
646 if ( !wxWindowBase::Enable(enable
) )
649 Widget wMain
= (Widget
)GetMainWidget();
652 XtSetSensitive(wMain
, enable
);
653 XmUpdateDisplay(wMain
);
659 bool wxWindow::Show(bool show
)
661 if ( !wxWindowBase::Show(show
) )
664 if (m_borderWidget
|| m_scrolledWindow
)
666 MapOrUnmap(m_drawingArea
, show
);
667 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
671 if ( !MapOrUnmap(GetTopWidget(), show
) )
672 MapOrUnmap(GetMainWidget(), show
);
676 Window xwin
= (Window
) GetXWindow();
677 Display
*xdisp
= (Display
*) GetXDisplay();
679 XMapWindow(xdisp
, xwin
);
681 XUnmapWindow(xdisp
, xwin
);
687 // Raise the window to the top of the Z order
688 void wxWindow::Raise()
690 Widget wTop
= (Widget
) GetTopWidget();
691 Window window
= XtWindow(wTop
);
692 XRaiseWindow(XtDisplay(wTop
), window
);
695 // Lower the window to the bottom of the Z order
696 void wxWindow::Lower()
698 Widget wTop
= (Widget
) GetTopWidget();
699 Window window
= XtWindow(wTop
);
700 XLowerWindow(XtDisplay(wTop
), window
);
703 void wxWindow::SetTitle(const wxString
& title
)
705 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
708 wxString
wxWindow::GetTitle() const
711 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
713 return wxString(title
);
716 void wxWindow::DoCaptureMouse()
718 g_captureWindow
= this;
722 Widget wMain
= (Widget
)GetMainWidget();
724 XtAddGrab(wMain
, TRUE
, FALSE
);
726 m_winCaptured
= TRUE
;
729 void wxWindow::DoReleaseMouse()
731 g_captureWindow
= NULL
;
732 if ( !m_winCaptured
)
735 Widget wMain
= (Widget
)GetMainWidget();
739 m_winCaptured
= FALSE
;
742 bool wxWindow::SetFont(const wxFont
& font
)
744 if ( !wxWindowBase::SetFont(font
) )
755 bool wxWindow::SetCursor(const wxCursor
& cursor
)
757 if ( !wxWindowBase::SetCursor(cursor
) )
763 // wxASSERT_MSG( m_cursor.Ok(),
764 // wxT("cursor must be valid after call to the base version"));
765 wxCursor
* cursor2
= NULL
;
767 cursor2
= & m_cursor
;
769 cursor2
= wxSTANDARD_CURSOR
;
771 WXDisplay
*dpy
= GetXDisplay();
772 WXCursor x_cursor
= cursor2
->GetXCursor(dpy
);
774 Widget w
= (Widget
) GetMainWidget();
775 Window win
= XtWindow(w
);
776 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
781 // Coordinates relative to the window
782 void wxWindow::WarpPointer (int x
, int y
)
784 Widget wClient
= (Widget
)GetClientWidget();
786 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
789 // ---------------------------------------------------------------------------
791 // ---------------------------------------------------------------------------
793 int wxWindow::GetScrollPos(int orient
) const
795 if (orient
== wxHORIZONTAL
)
801 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
805 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
813 // This now returns the whole range, not just the number of positions that we
815 int wxWindow::GetScrollRange(int orient
) const
817 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
818 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
821 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
825 int wxWindow::GetScrollThumb(int orient
) const
827 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
828 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
831 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
835 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
837 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
841 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
844 SetInternalScrollPos((wxOrientation
)orient
, pos
);
847 // New function that will replace some of the above.
848 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
849 int range
, bool WXUNUSED(refresh
))
852 GetSize(& oldW
, & oldH
);
856 if (thumbVisible
== 0)
859 if (thumbVisible
> range
)
860 thumbVisible
= range
;
862 // Save the old state to see if it changed
863 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
865 if (orient
== wxHORIZONTAL
)
867 if (thumbVisible
== range
)
870 DestroyScrollbar(wxHORIZONTAL
);
875 CreateScrollbar(wxHORIZONTAL
);
878 if (orient
== wxVERTICAL
)
880 if (thumbVisible
== range
)
883 DestroyScrollbar(wxVERTICAL
);
888 CreateScrollbar(wxVERTICAL
);
891 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
893 if (oldScrollBar
!= newScrollBar
)
895 // This is important! Without it, scrollbars misbehave badly.
896 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
897 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
898 XtRealizeWidget((Widget
) m_scrolledWindow
);
899 XtManageChild((Widget
) m_scrolledWindow
);
904 XtVaSetValues((Widget
) newScrollBar
,
908 XmNsliderSize
, thumbVisible
,
912 SetInternalScrollPos((wxOrientation
)orient
, pos
);
915 GetSize(& newW
, & newH
);
917 // Adjusting scrollbars can resize the canvas accidentally
918 if (newW
!= oldW
|| newH
!= oldH
)
919 SetSize(-1, -1, oldW
, oldH
);
922 // Does a physical scroll
923 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
928 // Use specified rectangle
929 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
933 // Use whole client area
935 GetClientSize(& w
, & h
);
938 wxNode
*cnode
= m_children
.First();
941 wxWindow
*child
= (wxWindow
*) cnode
->Data();
944 child
->GetSize( &sx
, &sy
);
945 wxPoint
pos( child
->GetPosition() );
946 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
947 cnode
= cnode
->Next();
950 int x1
= (dx
>= 0) ? x
: x
- dx
;
951 int y1
= (dy
>= 0) ? y
: y
- dy
;
952 int w1
= w
- abs(dx
);
953 int h1
= h
- abs(dy
);
954 int x2
= (dx
>= 0) ? x
+ dx
: x
;
955 int y2
= (dy
>= 0) ? y
+ dy
: y
;
959 dc
.SetLogicalFunction (wxCOPY
);
961 Widget widget
= (Widget
) GetMainWidget();
962 Window window
= XtWindow(widget
);
963 Display
* display
= XtDisplay(widget
);
965 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
966 x1
, y1
, w1
, h1
, x2
, y2
);
968 dc
.SetAutoSetting(TRUE
);
969 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
970 dc
.SetBrush(brush
); // FIXME: needed?
972 // We'll add rectangles to the list of update rectangles according to which
973 // bits we've exposed.
978 wxRect
*rect
= new wxRect
;
984 XFillRectangle(display
, window
,
985 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
989 rect
->width
= rect
->width
;
990 rect
->height
= rect
->height
;
992 updateRects
.Append((wxObject
*) rect
);
996 wxRect
*rect
= new wxRect
;
998 rect
->x
= x
+ w
+ dx
;
1003 XFillRectangle(display
, window
,
1004 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1009 rect
->width
= rect
->width
;
1010 rect
->height
= rect
->height
;
1012 updateRects
.Append((wxObject
*) rect
);
1016 wxRect
*rect
= new wxRect
;
1023 XFillRectangle(display
, window
,
1024 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1028 rect
->width
= rect
->width
;
1029 rect
->height
= rect
->height
;
1031 updateRects
.Append((wxObject
*) rect
);
1035 wxRect
*rect
= new wxRect
;
1038 rect
->y
= y
+ h
+ dy
;
1042 XFillRectangle(display
, window
,
1043 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1047 rect
->width
= rect
->width
;
1048 rect
->height
= rect
->height
;
1050 updateRects
.Append((wxObject
*) rect
);
1052 dc
.SetBrush(wxNullBrush
);
1054 // Now send expose events
1056 wxNode
* node
= updateRects
.First();
1059 wxRect
* rect
= (wxRect
*) node
->Data();
1062 event
.type
= Expose
;
1063 event
.display
= display
;
1064 event
.send_event
= True
;
1065 event
.window
= window
;
1069 event
.width
= rect
->width
;
1070 event
.height
= rect
->height
;
1074 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1076 node
= node
->Next();
1080 // Delete the update rects
1081 node
= updateRects
.First();
1084 wxRect
* rect
= (wxRect
*) node
->Data();
1086 node
= node
->Next();
1089 XmUpdateDisplay((Widget
) GetMainWidget());
1092 // ---------------------------------------------------------------------------
1094 // ---------------------------------------------------------------------------
1096 #if wxUSE_DRAG_AND_DROP
1098 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1105 // Old style file-manager drag&drop
1106 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1111 // ----------------------------------------------------------------------------
1113 // ----------------------------------------------------------------------------
1117 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1122 #endif // wxUSE_TOOLTIPS
1124 // ----------------------------------------------------------------------------
1126 // ----------------------------------------------------------------------------
1128 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1130 Widget widget
= (Widget
) GetMainWidget();
1132 /* The menuId field seems to be usused, so we'll use it to
1133 indicate whether a menu is popped up or not:
1134 0: Not currently created as a popup
1135 -1: Created as a popup, but not active
1139 if (menu
->GetParent() && (menu
->GetId() != -1))
1142 if (menu
->GetMainWidget()) {
1143 menu
->DestroyMenu(TRUE
);
1146 menu
->SetId(1); /* Mark as popped-up */
1147 menu
->CreateMenu(NULL
, widget
, menu
);
1148 menu
->SetInvokingWindow(this);
1152 // menu->SetParent(parent);
1153 // parent->children->Append(menu); // Store menu for later deletion
1155 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1163 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1165 wxCanvas *canvas = (wxCanvas *) this;
1166 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1167 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1171 Display
*display
= XtDisplay (widget
);
1172 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1173 Window thisWindow
= XtWindow (widget
);
1175 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1176 &rootX
, &rootY
, &childWindow
);
1178 XButtonPressedEvent event
;
1179 event
.type
= ButtonPress
;
1185 event
.x_root
= rootX
;
1186 event
.y_root
= rootY
;
1188 XmMenuPosition (menuWidget
, &event
);
1189 XtManageChild (menuWidget
);
1194 // ---------------------------------------------------------------------------
1195 // moving and resizing
1196 // ---------------------------------------------------------------------------
1198 bool wxWindow::PreResize()
1204 void wxWindow::DoGetSize(int *x
, int *y
) const
1208 CanvasGetSize(x
, y
);
1212 Widget widget
= (Widget
) GetTopWidget();
1214 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1215 if(x
) *x
= xx
; if(y
) *y
= yy
;
1218 void wxWindow::DoGetPosition(int *x
, int *y
) const
1222 CanvasGetPosition(x
, y
);
1225 Widget widget
= (Widget
) GetTopWidget();
1227 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1229 // We may be faking the client origin. So a window that's really at (0, 30)
1230 // may appear (to wxWin apps) to be at (0, 0).
1233 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1238 if(x
) *x
= xx
; if(y
) *y
= yy
;
1241 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1243 Widget widget
= (Widget
) GetClientWidget();
1244 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1245 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1246 Window thisWindow
= XtWindow(widget
);
1251 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1254 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1256 Widget widget
= (Widget
) GetClientWidget();
1257 Display
*display
= XtDisplay(widget
);
1258 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1259 Window thisWindow
= XtWindow(widget
);
1264 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1268 // Get size *available for subwindows* i.e. excluding menu bar etc.
1269 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1271 Widget widget
= (Widget
) GetClientWidget();
1273 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1274 if(x
) *x
= xx
; if(y
) *y
= yy
;
1277 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1279 // A bit of optimization to help sort out the flickers.
1280 int oldX
, oldY
, oldW
, oldH
;
1281 GetSize(& oldW
, & oldH
);
1282 GetPosition(& oldX
, & oldY
);
1284 if ( !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1297 bool nothingChanged
= (x
== oldX
) && (y
== oldY
) &&
1298 (width
== oldW
) && (height
== oldH
);
1300 if (!wxNoOptimize::CanOptimize())
1302 nothingChanged
= FALSE
;
1305 if ( !nothingChanged
)
1309 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1313 Widget widget
= (Widget
) GetTopWidget();
1317 bool managed
= XtIsManaged( widget
);
1319 XtUnmanageChild(widget
);
1323 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1325 DoMoveWindow(xx
, yy
, width
, height
);
1328 XtManageChild(widget
);
1330 // How about this bit. Maybe we don't need to generate size events
1331 // all the time -- they'll be generated when the window is sized anyway.
1333 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1334 sizeEvent
.SetEventObject(this);
1336 GetEventHandler()->ProcessEvent(sizeEvent
);
1341 void wxWindow::DoSetClientSize(int width
, int height
)
1345 CanvasSetClientSize(width
, height
);
1349 Widget widget
= (Widget
) GetTopWidget();
1352 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1354 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1356 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1357 sizeEvent
.SetEventObject(this);
1359 GetEventHandler()->ProcessEvent(sizeEvent
);
1362 // For implementation purposes - sometimes decorations make the client area
1364 wxPoint
wxWindow::GetClientAreaOrigin() const
1366 return wxPoint(0, 0);
1369 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1376 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1379 // TODO what about dialogs?
1383 Widget widget
= (Widget
) frame
->GetShellWidget();
1386 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1388 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1390 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1392 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1394 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1396 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1399 void wxWindow::DoMoveWindow(int x
, int y
, int width
, int height
)
1401 XtVaSetValues((Widget
)GetTopWidget(),
1409 // ---------------------------------------------------------------------------
1411 // ---------------------------------------------------------------------------
1413 int wxWindow::GetCharHeight() const
1415 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1417 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1419 int direction
, ascent
, descent
;
1420 XCharStruct overall
;
1421 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1422 &descent
, &overall
);
1424 // return (overall.ascent + overall.descent);
1425 return (ascent
+ descent
);
1428 int wxWindow::GetCharWidth() const
1430 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1432 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1434 int direction
, ascent
, descent
;
1435 XCharStruct overall
;
1436 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1437 &descent
, &overall
);
1439 return overall
.width
;
1442 void wxWindow::GetTextExtent(const wxString
& string
,
1444 int *descent
, int *externalLeading
,
1445 const wxFont
*theFont
) const
1447 wxFont
*fontToUse
= (wxFont
*)theFont
;
1449 fontToUse
= (wxFont
*) & m_font
;
1451 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1453 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1455 int direction
, ascent
, descent2
;
1456 XCharStruct overall
;
1457 int slen
= string
.Len();
1461 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1462 &ascent
, &descent2
, &overall
);
1465 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1466 &direction
, &ascent
, &descent2
, &overall
);
1469 *x
= (overall
.width
);
1471 *y
= (ascent
+ descent2
);
1473 *descent
= descent2
;
1474 if (externalLeading
)
1475 *externalLeading
= 0;
1479 // ----------------------------------------------------------------------------
1481 // ----------------------------------------------------------------------------
1483 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1485 m_needsRefresh
= TRUE
;
1486 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1487 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1489 XExposeEvent dummyEvent
;
1491 GetSize(&width
, &height
);
1493 dummyEvent
.type
= Expose
;
1494 dummyEvent
.display
= display
;
1495 dummyEvent
.send_event
= True
;
1496 dummyEvent
.window
= thisWindow
;
1499 dummyEvent
.x
= rect
->x
;
1500 dummyEvent
.y
= rect
->y
;
1501 dummyEvent
.width
= rect
->width
;
1502 dummyEvent
.height
= rect
->height
;
1508 dummyEvent
.width
= width
;
1509 dummyEvent
.height
= height
;
1511 dummyEvent
.count
= 0;
1515 wxClientDC
dc(this);
1516 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1517 dc
.SetBackground(backgroundBrush
);
1524 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1527 void wxWindow::Clear()
1529 wxClientDC
dc(this);
1530 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1531 dc
.SetBackground(brush
);
1535 void wxWindow::ClearUpdateRects()
1537 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1540 wxRect
* rect
= node
->GetData();
1542 node
= node
->GetNext();
1545 m_updateRects
.Clear();
1548 void wxWindow::DoPaint()
1550 //TODO : make a temporary gc so we can do the XCopyArea below
1551 if (m_backingPixmap
&& !m_needsRefresh
)
1555 GC tempGC
= (GC
) dc
.GetBackingGC();
1557 Widget widget
= (Widget
) GetMainWidget();
1562 // We have to test whether it's a wxScrolledWindow (hack!) because
1563 // otherwise we don't know how many pixels have been scrolled. We might
1564 // solve this in the future by defining virtual wxWindow functions to get
1565 // the scroll position in pixels. Or, each kind of scrolled window has to
1566 // implement backing stores itself, using generic wxWindows code.
1567 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1568 if ( scrolledWindow
)
1571 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1577 // TODO: This could be optimized further by only copying the areas in the
1578 // current update region.
1580 // Only blit the part visible in the client area. The backing pixmap
1581 // always starts at 0, 0 but we may be looking at only a portion of it.
1582 wxSize clientArea
= GetClientSize();
1583 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1584 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1586 // Copy whichever is samller, the amount of pixmap we have to copy,
1587 // or the size of the client area.
1588 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1589 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1591 // Make sure we're not negative
1592 toBlitX
= wxMax(0, toBlitX
);
1593 toBlitY
= wxMax(0, toBlitY
);
1598 (Pixmap
) m_backingPixmap
,
1601 scrollPosX
, scrollPosY
, // Start at the scroll position
1602 toBlitX
, toBlitY
, // How much of the pixmap to copy
1608 // Set an erase event first
1609 wxEraseEvent
eraseEvent(GetId());
1610 eraseEvent
.SetEventObject(this);
1611 GetEventHandler()->ProcessEvent(eraseEvent
);
1613 wxPaintEvent
event(GetId());
1614 event
.SetEventObject(this);
1615 GetEventHandler()->ProcessEvent(event
);
1617 m_needsRefresh
= FALSE
;
1621 // ----------------------------------------------------------------------------
1623 // ----------------------------------------------------------------------------
1625 // Responds to colour changes: passes event on to children.
1626 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1628 wxWindowList::Node
*node
= GetChildren().GetFirst();
1631 // Only propagate to non-top-level windows
1632 wxWindow
*win
= node
->GetData();
1633 if ( win
->GetParent() )
1635 wxSysColourChangedEvent event2
;
1636 event
.m_eventObject
= win
;
1637 win
->GetEventHandler()->ProcessEvent(event2
);
1640 node
= node
->GetNext();
1644 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1646 // This calls the UI-update mechanism (querying windows for
1647 // menu/toolbar/control state information)
1651 // ----------------------------------------------------------------------------
1653 // ----------------------------------------------------------------------------
1655 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1657 if (!m_acceleratorTable
.Ok())
1660 int count
= m_acceleratorTable
.GetCount();
1661 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1663 for (i
= 0; i
< count
; i
++)
1665 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1666 if (entry
->MatchesEvent(event
))
1668 // Bingo, we have a match. Now find a control that matches the
1669 // entry command id.
1671 // Need to go up to the top of the window hierarchy, since it might
1672 // be e.g. a menu item
1673 wxWindow
* parent
= this;
1674 while ( parent
&& !parent
->IsTopLevel() )
1675 parent
= parent
->GetParent();
1680 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1683 // Try for a menu command
1684 if (frame
->GetMenuBar())
1686 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1689 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1690 commandEvent
.SetEventObject(frame
);
1692 // If ProcessEvent returns TRUE (it was handled), then
1693 // the calling code will skip the event handling.
1694 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1699 // Find a child matching the command id
1700 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1706 // Now we process those kinds of windows that we can.
1707 // For now, only buttons.
1708 if ( wxDynamicCast(child
, wxButton
) )
1710 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1711 commandEvent
.SetEventObject(child
);
1712 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1719 // We didn't match the key event against an accelerator.
1723 // ============================================================================
1724 // Motif-specific stuff from here on
1725 // ============================================================================
1727 // ----------------------------------------------------------------------------
1728 // function which maintain the global hash table mapping Widgets to wxWindows
1729 // ----------------------------------------------------------------------------
1731 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1733 wxWindow
*oldItem
= NULL
;
1734 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1736 wxLogDebug("Widget table clash: new widget is %ld, %s",
1737 (long)w
, win
->GetClassInfo()->GetClassName());
1741 wxWidgetHashTable
->Put((long) w
, win
);
1743 wxLogTrace("widget", "Widget 0x%08x <-> window %p (%s)",
1744 w
, win
, win
->GetClassInfo()->GetClassName());
1749 wxWindow
*wxGetWindowFromTable(Widget w
)
1751 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1754 void wxDeleteWindowFromTable(Widget w
)
1756 wxWidgetHashTable
->Delete((long)w
);
1759 // ----------------------------------------------------------------------------
1760 // add/remove window from the table
1761 // ----------------------------------------------------------------------------
1763 // Add to hash table, add event handler
1764 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1765 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1767 wxAddWindowToTable((Widget
) mainWidget
, this);
1768 if (CanAddEventHandler())
1770 XtAddEventHandler((Widget
) mainWidget
,
1771 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1773 wxPanelItemEventHandler
,
1780 XtOverrideTranslations ((Widget
) mainWidget
,
1781 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1782 XtFree ((char *) ptr
);
1785 // Some widgets have a parent form widget, e.g. wxRadioBox
1788 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1792 XtOverrideTranslations ((Widget
) formWidget
,
1793 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1794 XtFree ((char *) ptr
);
1801 SetSize (x
, y
, width
, height
);
1806 // Remove event handler, remove from hash table
1807 bool wxWindow::DetachWidget(WXWidget widget
)
1809 if (CanAddEventHandler())
1811 XtRemoveEventHandler((Widget
) widget
,
1812 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1814 wxPanelItemEventHandler
,
1818 wxDeleteWindowFromTable((Widget
) widget
);
1822 // ----------------------------------------------------------------------------
1823 // Motif-specific accessors
1824 // ----------------------------------------------------------------------------
1826 // Get the underlying X window
1827 WXWindow
wxWindow::GetXWindow() const
1829 Widget wMain
= (Widget
)GetMainWidget();
1831 return (WXWindow
) XtWindow(wMain
);
1833 return (WXWindow
) 0;
1836 // Get the underlying X display
1837 WXDisplay
*wxWindow::GetXDisplay() const
1839 Widget wMain
= (Widget
)GetMainWidget();
1841 return (WXDisplay
*) XtDisplay(wMain
);
1843 return (WXDisplay
*) NULL
;
1846 WXWidget
wxWindow::GetMainWidget() const
1849 return m_drawingArea
;
1851 return m_mainWidget
;
1854 WXWidget
wxWindow::GetClientWidget() const
1856 if (m_drawingArea
!= (WXWidget
) 0)
1857 return m_drawingArea
;
1859 return GetMainWidget();
1862 WXWidget
wxWindow::GetTopWidget() const
1864 return GetMainWidget();
1867 WXWidget
wxWindow::GetLabelWidget() const
1869 return GetMainWidget();
1872 // ----------------------------------------------------------------------------
1874 // ----------------------------------------------------------------------------
1876 // All widgets should have this as their resize proc.
1877 // OnSize sent to wxWindow via client data.
1878 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1880 wxWindow
*win
= wxGetWindowFromTable(w
);
1884 if (win
->PreResize())
1887 win
->GetSize(&width
, &height
);
1888 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1889 sizeEvent
.SetEventObject(win
);
1890 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1894 static void wxCanvasRepaintProc(Widget drawingArea
,
1895 XtPointer clientData
,
1896 XmDrawingAreaCallbackStruct
* cbs
)
1898 if (!wxGetWindowFromTable(drawingArea
))
1901 XEvent
* event
= cbs
->event
;
1902 wxWindow
* win
= (wxWindow
*) clientData
;
1904 switch (event
->type
)
1908 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1909 event
->xexpose
.width
, event
->xexpose
.height
);
1911 if (event
-> xexpose
.count
== 0)
1914 win
->ClearUpdateRects();
1921 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1922 static void wxCanvasEnterLeave(Widget drawingArea
,
1923 XtPointer
WXUNUSED(clientData
),
1924 XCrossingEvent
* event
)
1926 XmDrawingAreaCallbackStruct cbs
;
1929 ((XCrossingEvent
&) ev
) = *event
;
1931 cbs
.reason
= XmCR_INPUT
;
1934 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1937 // Fix to make it work under Motif 1.0 (!)
1938 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1940 #if XmVersion <= 1000
1941 XmDrawingAreaCallbackStruct cbs
;
1944 ev
= *((XEvent
*) event
);
1945 cbs
.reason
= XmCR_INPUT
;
1948 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1949 #endif // XmVersion <= 1000
1952 static void wxCanvasInputEvent(Widget drawingArea
,
1953 XtPointer
WXUNUSED(data
),
1954 XmDrawingAreaCallbackStruct
* cbs
)
1956 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1962 if (cbs
->reason
!= XmCR_INPUT
)
1965 local_event
= *(cbs
->event
); // We must keep a copy!
1967 switch (local_event
.xany
.type
)
1975 // FIXME: most of this mouse event code is more or less
1976 // duplicated in wxTranslateMouseEvent
1978 wxEventType eventType
= wxEVT_NULL
;
1980 if (local_event
.xany
.type
== EnterNotify
)
1982 //if (local_event.xcrossing.mode!=NotifyNormal)
1983 // return ; // Ignore grab events
1984 eventType
= wxEVT_ENTER_WINDOW
;
1985 // canvas->GetEventHandler()->OnSetFocus();
1987 else if (local_event
.xany
.type
== LeaveNotify
)
1989 //if (local_event.xcrossingr.mode!=NotifyNormal)
1990 // return ; // Ignore grab events
1991 eventType
= wxEVT_LEAVE_WINDOW
;
1992 // canvas->GetEventHandler()->OnKillFocus();
1994 else if (local_event
.xany
.type
== MotionNotify
)
1996 eventType
= wxEVT_MOTION
;
1999 else if (local_event
.xany
.type
== ButtonPress
)
2001 if (local_event
.xbutton
.button
== Button1
)
2003 eventType
= wxEVT_LEFT_DOWN
;
2004 canvas
->SetButton1(TRUE
);
2006 else if (local_event
.xbutton
.button
== Button2
)
2008 eventType
= wxEVT_MIDDLE_DOWN
;
2009 canvas
->SetButton2(TRUE
);
2011 else if (local_event
.xbutton
.button
== Button3
)
2013 eventType
= wxEVT_RIGHT_DOWN
;
2014 canvas
->SetButton3(TRUE
);
2017 else if (local_event
.xany
.type
== ButtonRelease
)
2019 if (local_event
.xbutton
.button
== Button1
)
2021 eventType
= wxEVT_LEFT_UP
;
2022 canvas
->SetButton1(FALSE
);
2024 else if (local_event
.xbutton
.button
== Button2
)
2026 eventType
= wxEVT_MIDDLE_UP
;
2027 canvas
->SetButton2(FALSE
);
2029 else if (local_event
.xbutton
.button
== Button3
)
2031 eventType
= wxEVT_RIGHT_UP
;
2032 canvas
->SetButton3(FALSE
);
2036 wxMouseEvent
wxevent (eventType
);
2038 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2039 || (event_left_is_down (&local_event
)
2040 && (eventType
!= wxEVT_LEFT_UP
)));
2041 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2042 || (event_middle_is_down (&local_event
)
2043 && (eventType
!= wxEVT_MIDDLE_UP
)));
2044 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2045 || (event_right_is_down (&local_event
)
2046 && (eventType
!= wxEVT_RIGHT_UP
)));
2048 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2049 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2050 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2051 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2052 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2054 if ( eventType
== wxEVT_MOTION
)
2056 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2059 Display
*dpy
= XtDisplay (drawingArea
);
2061 XQueryPointer (dpy
, XtWindow (drawingArea
),
2063 &local_event
.xmotion
.x_root
,
2064 &local_event
.xmotion
.y_root
,
2065 &local_event
.xmotion
.x
,
2066 &local_event
.xmotion
.y
,
2067 &local_event
.xmotion
.state
);
2074 // Now check if we need to translate this event into a double click
2075 if (TRUE
) // canvas->doubleClickAllowed)
2077 if (wxevent
.ButtonDown())
2079 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2081 // get button and time-stamp
2083 if (wxevent
.LeftDown())
2085 else if (wxevent
.MiddleDown())
2087 else if (wxevent
.RightDown())
2089 long ts
= wxevent
.GetTimestamp();
2091 // check, if single or double click
2092 int buttonLast
= canvas
->GetLastClickedButton();
2093 long lastTS
= canvas
->GetLastClickTime();
2094 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2097 canvas
->SetLastClick(0, ts
);
2099 wxEventType typeDouble
;
2100 if ( eventType
== wxEVT_LEFT_DOWN
)
2101 typeDouble
= wxEVT_LEFT_DCLICK
;
2102 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2103 typeDouble
= wxEVT_MIDDLE_DCLICK
;
2104 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2105 typeDouble
= wxEVT_RIGHT_DCLICK
;
2107 typeDouble
= wxEVT_NULL
;
2109 if ( typeDouble
!= wxEVT_NULL
)
2111 wxevent
.SetEventType(typeDouble
);
2116 // not fast enough or different button
2117 canvas
->SetLastClick(button
, ts
);
2122 wxevent
.SetId(canvas
->GetId());
2123 wxevent
.SetEventObject(canvas
);
2124 wxevent
.m_x
= local_event
.xbutton
.x
;
2125 wxevent
.m_y
= local_event
.xbutton
.y
;
2126 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2128 if (eventType
== wxEVT_ENTER_WINDOW
||
2129 eventType
== wxEVT_LEAVE_WINDOW
||
2130 eventType
== wxEVT_MOTION
2139 static char buf
[100];
2141 XComposeStatus compose
;
2142 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, &compose
);
2145 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, NULL
);
2146 int id
= wxCharCodeXToWX (keySym
);
2148 wxEventType eventType
= wxEVT_CHAR
;
2150 wxKeyEvent
event (eventType
);
2152 if (local_event
.xkey
.state
& ShiftMask
)
2153 event
.m_shiftDown
= TRUE
;
2154 if (local_event
.xkey
.state
& ControlMask
)
2155 event
.m_controlDown
= TRUE
;
2156 if (local_event
.xkey
.state
& Mod3Mask
)
2157 event
.m_altDown
= TRUE
;
2158 if (local_event
.xkey
.state
& Mod1Mask
)
2159 event
.m_metaDown
= TRUE
;
2160 event
.SetEventObject(canvas
);
2161 event
.m_keyCode
= id
;
2162 event
.SetTimestamp(local_event
.xkey
.time
);
2166 // Implement wxFrame::OnCharHook by checking ancestor.
2167 wxWindow
*parent
= canvas
->GetParent();
2168 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2169 parent
= parent
->GetParent();
2173 event
.SetEventType(wxEVT_CHAR_HOOK
);
2174 if (parent
->GetEventHandler()->ProcessEvent(event
))
2178 // For simplicity, OnKeyDown is the same as OnChar
2179 // TODO: filter modifier key presses from OnChar
2180 event
.SetEventType(wxEVT_KEY_DOWN
);
2182 // Only process OnChar if OnKeyDown didn't swallow it
2183 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2185 event
.SetEventType(wxEVT_CHAR
);
2186 canvas
->GetEventHandler()->ProcessEvent (event
);
2193 static char buf
[100];
2195 (void) XLookupString ((XKeyEvent
*) & local_event
, buf
, 20, &keySym
, NULL
);
2196 int id
= wxCharCodeXToWX (keySym
);
2198 wxKeyEvent
event (wxEVT_KEY_UP
);
2200 if (local_event
.xkey
.state
& ShiftMask
)
2201 event
.m_shiftDown
= TRUE
;
2202 if (local_event
.xkey
.state
& ControlMask
)
2203 event
.m_controlDown
= TRUE
;
2204 if (local_event
.xkey
.state
& Mod3Mask
)
2205 event
.m_altDown
= TRUE
;
2206 if (local_event
.xkey
.state
& Mod1Mask
)
2207 event
.m_metaDown
= TRUE
;
2208 event
.SetEventObject(canvas
);
2209 event
.m_keyCode
= id
;
2210 event
.SetTimestamp(local_event
.xkey
.time
);
2214 canvas
->GetEventHandler()->ProcessEvent (event
);
2220 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2222 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2223 event
.SetEventObject(canvas
);
2224 canvas
->GetEventHandler()->ProcessEvent(event
);
2230 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2232 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2233 event
.SetEventObject(canvas
);
2234 canvas
->GetEventHandler()->ProcessEvent(event
);
2243 static void wxPanelItemEventHandler(Widget wid
,
2244 XtPointer
WXUNUSED(client_data
),
2246 Boolean
*continueToDispatch
)
2248 // Widget can be a label or the actual widget.
2250 wxWindow
*window
= wxGetWindowFromTable(wid
);
2253 wxMouseEvent
wxevent(0);
2254 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2256 window
->GetEventHandler()->ProcessEvent(wxevent
);
2260 // TODO: probably the key to allowing default behaviour to happen. Say we
2261 // set a m_doDefault flag to FALSE at the start of this function. Then in
2262 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2263 // TRUE, indicating that default processing can happen. Thus, behaviour can
2264 // appear to be overridden just by adding an event handler and not calling
2265 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2266 // way of handling drawing area events, to simplify things.
2267 *continueToDispatch
= True
;
2270 static void wxScrollBarCallback(Widget scrollbar
,
2271 XtPointer clientData
,
2272 XmScrollBarCallbackStruct
*cbs
)
2274 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2275 int orientation
= (int) clientData
;
2277 wxEventType eventType
= wxEVT_NULL
;
2278 switch (cbs
->reason
)
2280 case XmCR_INCREMENT
:
2282 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2285 case XmCR_DECREMENT
:
2287 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2292 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2295 case XmCR_VALUE_CHANGED
:
2297 eventType
= wxEVT_SCROLLWIN_THUMBRELEASE
;
2300 case XmCR_PAGE_INCREMENT
:
2302 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2305 case XmCR_PAGE_DECREMENT
:
2307 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2312 eventType
= wxEVT_SCROLLWIN_TOP
;
2315 case XmCR_TO_BOTTOM
:
2317 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2322 // Should never get here
2323 wxFAIL_MSG("Unknown scroll event.");
2328 wxScrollWinEvent
event(eventType
,
2330 ((orientation
== XmHORIZONTAL
) ?
2331 wxHORIZONTAL
: wxVERTICAL
));
2332 event
.SetEventObject( win
);
2333 win
->GetEventHandler()->ProcessEvent(event
);
2336 // For repainting arbitrary windows
2337 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2342 wxWindow
* win
= wxGetWindowFromTable(w
);
2346 switch(event
-> type
)
2350 window
= (Window
) win
-> GetXWindow();
2351 display
= (Display
*) win
-> GetXDisplay();
2353 if (event
-> xexpose
.count
== 0)
2357 win
->ClearUpdateRects();
2361 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2362 event
->xexpose
.width
, event
->xexpose
.height
);
2370 // ----------------------------------------------------------------------------
2371 // CanvaseXXXSize() functions
2372 // ----------------------------------------------------------------------------
2374 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2375 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2377 // A bit of optimization to help sort out the flickers.
2378 int oldX
, oldY
, oldW
, oldH
;
2379 GetSize(& oldW
, & oldH
);
2380 GetPosition(& oldX
, & oldY
);
2382 bool useOldPos
= FALSE
;
2383 bool useOldSize
= FALSE
;
2385 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2387 else if (x
== oldX
&& y
== oldY
)
2390 if ((w
== -1) && (h
== -1))
2392 else if (w
== oldW
&& h
== oldH
)
2395 if (!wxNoOptimize::CanOptimize())
2397 useOldSize
= FALSE
; useOldPos
= FALSE
;
2400 if (useOldPos
&& useOldSize
)
2403 Widget drawingArea
= (Widget
) m_drawingArea
;
2404 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2407 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2408 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2410 int xx
= x
; int yy
= y
;
2411 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2415 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2417 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2421 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2423 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2435 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2436 short thick
, margin
;
2437 XtVaGetValues ((Widget
) m_borderWidget
,
2438 XmNshadowThickness
, &thick
,
2439 XmNmarginWidth
, &margin
,
2441 w
-= 2 * (thick
+ margin
);
2444 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2448 XtVaGetValues ((Widget
) m_scrolledWindow
,
2449 XmNspacing
, &spacing
,
2450 XmNverticalScrollBar
, &sbar
,
2454 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2458 w
-= (spacing
+ wsbar
);
2461 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2468 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2469 short thick
, margin
;
2470 XtVaGetValues ((Widget
) m_borderWidget
,
2471 XmNshadowThickness
, &thick
,
2472 XmNmarginHeight
, &margin
,
2474 h
-= 2 * (thick
+ margin
);
2477 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2481 XtVaGetValues ((Widget
) m_scrolledWindow
,
2482 XmNspacing
, &spacing
,
2483 XmNhorizontalScrollBar
, &sbar
,
2487 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2491 h
-= (spacing
+ wsbar
);
2494 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2500 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2501 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2505 GetClientSize (&ww
, &hh
);
2506 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2507 sizeEvent
.SetEventObject(this);
2509 GetEventHandler()->ProcessEvent(sizeEvent
);
2513 void wxWindow::CanvasSetClientSize (int w
, int h
)
2515 Widget drawingArea
= (Widget
) m_drawingArea
;
2517 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2520 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2522 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2525 // TODO: is this necessary?
2526 allowRepainting
= FALSE
;
2528 XSync (XtDisplay (drawingArea
), FALSE
);
2530 while (XtAppPending (wxTheApp
->appContext
))
2532 XFlush (XtDisplay (drawingArea
));
2533 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2534 XtDispatchEvent (&event
);
2538 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2541 allowRepainting
= TRUE
;
2544 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2545 sizeEvent
.SetEventObject(this);
2547 GetEventHandler()->ProcessEvent(sizeEvent
);
2551 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2553 // Must return the same thing that was set via SetClientSize
2555 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2560 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2563 if ((Widget
) m_borderWidget
)
2564 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2565 else if ((Widget
) m_scrolledWindow
)
2566 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2568 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2574 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2577 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2579 // We may be faking the client origin.
2580 // So a window that's really at (0, 30) may appear
2581 // (to wxWin apps) to be at (0, 0).
2584 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2593 // ----------------------------------------------------------------------------
2594 // TranslateXXXEvent() functions
2595 // ----------------------------------------------------------------------------
2597 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2599 switch (xevent
->xany
.type
)
2601 case EnterNotify
: // never received here - yes ? MB
2602 case LeaveNotify
: // never received here - yes ? MB
2607 wxEventType eventType
= wxEVT_NULL
;
2609 // FIXME: this is never true I think - MB
2611 if (xevent
->xany
.type
== LeaveNotify
)
2613 win
->SetButton1(FALSE
);
2614 win
->SetButton2(FALSE
);
2615 win
->SetButton3(FALSE
);
2618 else if (xevent
->xany
.type
== MotionNotify
)
2620 eventType
= wxEVT_MOTION
;
2622 else if (xevent
->xany
.type
== ButtonPress
)
2624 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2626 if (xevent
->xbutton
.button
== Button1
)
2628 eventType
= wxEVT_LEFT_DOWN
;
2629 win
->SetButton1(TRUE
);
2632 else if (xevent
->xbutton
.button
== Button2
)
2634 eventType
= wxEVT_MIDDLE_DOWN
;
2635 win
->SetButton2(TRUE
);
2638 else if (xevent
->xbutton
.button
== Button3
)
2640 eventType
= wxEVT_RIGHT_DOWN
;
2641 win
->SetButton3(TRUE
);
2645 // check for a double click
2647 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2648 long ts
= wxevent
.GetTimestamp();
2650 int buttonLast
= win
->GetLastClickedButton();
2651 long lastTS
= win
->GetLastClickTime();
2652 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2655 win
->SetLastClick(0, ts
);
2656 if ( eventType
== wxEVT_LEFT_DOWN
)
2657 eventType
= wxEVT_LEFT_DCLICK
;
2658 else if ( eventType
== wxEVT_MIDDLE_DOWN
)
2659 eventType
= wxEVT_MIDDLE_DCLICK
;
2660 else if ( eventType
== wxEVT_RIGHT_DOWN
)
2661 eventType
= wxEVT_RIGHT_DCLICK
;
2665 // not fast enough or different button
2666 win
->SetLastClick(button
, ts
);
2669 else if (xevent
->xany
.type
== ButtonRelease
)
2671 if (xevent
->xbutton
.button
== Button1
)
2673 eventType
= wxEVT_LEFT_UP
;
2674 win
->SetButton1(FALSE
);
2676 else if (xevent
->xbutton
.button
== Button2
)
2678 eventType
= wxEVT_MIDDLE_UP
;
2679 win
->SetButton2(FALSE
);
2681 else if (xevent
->xbutton
.button
== Button3
)
2683 eventType
= wxEVT_RIGHT_UP
;
2684 win
->SetButton3(FALSE
);
2693 wxevent
.SetEventType(eventType
);
2696 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2699 win
->GetPosition(&x2
, &y2
);
2701 // The button x/y must be translated to wxWindows
2702 // window space - the widget might be a label or button,
2706 if (widget
!= (Widget
)win
->GetMainWidget())
2712 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2713 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2715 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2716 || (event_left_is_down (xevent
)
2717 && (eventType
!= wxEVT_LEFT_UP
)));
2718 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2719 || (event_middle_is_down (xevent
)
2720 && (eventType
!= wxEVT_MIDDLE_UP
)));
2721 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2722 || (event_right_is_down (xevent
)
2723 && (eventType
!= wxEVT_RIGHT_UP
)));
2725 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2726 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2727 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2728 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2730 wxevent
.SetId(win
->GetId());
2731 wxevent
.SetEventObject(win
);
2739 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2741 switch (xevent
->xany
.type
)
2750 XComposeStatus compose
;
2751 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2753 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2754 int id
= wxCharCodeXToWX (keySym
);
2756 if (xevent
->xkey
.state
& ShiftMask
)
2757 wxevent
.m_shiftDown
= TRUE
;
2758 if (xevent
->xkey
.state
& ControlMask
)
2759 wxevent
.m_controlDown
= TRUE
;
2760 if (xevent
->xkey
.state
& Mod3Mask
)
2761 wxevent
.m_altDown
= TRUE
;
2762 if (xevent
->xkey
.state
& Mod1Mask
)
2763 wxevent
.m_metaDown
= TRUE
;
2764 wxevent
.SetEventObject(win
);
2765 wxevent
.m_keyCode
= id
;
2766 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2768 wxevent
.m_x
= xevent
->xbutton
.x
;
2769 wxevent
.m_y
= xevent
->xbutton
.y
;
2783 // ----------------------------------------------------------------------------
2785 // ----------------------------------------------------------------------------
2787 #define YAllocColor XAllocColor
2788 XColor g_itemColors
[5];
2789 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2792 static XmColorProc colorProc
;
2794 result
= wxNO_COLORS
;
2798 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2799 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2800 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2801 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2802 if (colorProc
== (XmColorProc
) NULL
)
2804 // Get a ptr to the actual function
2805 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2806 // And set it back to motif.
2807 XmSetColorCalculation (colorProc
);
2809 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2810 &g_itemColors
[wxFORE_INDEX
],
2811 &g_itemColors
[wxSELE_INDEX
],
2812 &g_itemColors
[wxTOPS_INDEX
],
2813 &g_itemColors
[wxBOTS_INDEX
]);
2814 result
= wxBACK_COLORS
;
2818 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2819 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2820 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2821 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2822 if (result
== wxNO_COLORS
)
2823 result
= wxFORE_COLORS
;
2826 Display
*dpy
= display
;
2827 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2831 /* 5 Colours to allocate */
2832 for (int i
= 0; i
< 5; i
++)
2833 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2834 result
= wxNO_COLORS
;
2838 /* Only 1 colour to allocate */
2839 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2840 result
= wxNO_COLORS
;
2847 // Changes the foreground and background colours to be derived from the current
2848 // background colour. To change the foreground colour, you must call
2849 // SetForegroundColour explicitly.
2850 void wxWindow::ChangeBackgroundColour()
2852 WXWidget mainWidget
= GetMainWidget();
2854 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2856 // This not necessary
2859 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2861 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2862 // Have to set the scrollbar colours back since
2863 // the scrolled window seemed to change them
2864 wxColour backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
2867 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2869 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2874 void wxWindow::ChangeForegroundColour()
2876 WXWidget mainWidget
= GetMainWidget();
2878 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2879 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2880 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2883 // Change a widget's foreground and background colours.
2884 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2886 // When should we specify the foreground, if it's calculated
2887 // by wxComputeColours?
2888 // Solution: say we start with the default (computed) foreground colour.
2889 // If we call SetForegroundColour explicitly for a control or window,
2890 // then the foreground is changed.
2891 // Therefore SetBackgroundColour computes the foreground colour, and
2892 // SetForegroundColour changes the foreground colour. The ordering is
2895 Widget w
= (Widget
)widget
;
2898 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2903 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2905 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2908 XtVaSetValues ((Widget
) widget
,
2909 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2910 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2911 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2912 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2915 if (changeArmColour
)
2916 XtVaSetValues ((Widget
) widget
,
2917 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2921 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2923 if ( !wxWindowBase::SetBackgroundColour(col
) )
2926 ChangeBackgroundColour();
2931 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2933 if ( !wxWindowBase::SetForegroundColour(col
) )
2936 ChangeForegroundColour();
2941 void wxWindow::ChangeFont(bool keepOriginalSize
)
2943 // Note that this causes the widget to be resized back
2944 // to its original size! We therefore have to set the size
2945 // back again. TODO: a better way in Motif?
2946 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2947 if (w
&& m_font
.Ok())
2949 int width
, height
, width1
, height1
;
2950 GetSize(& width
, & height
);
2952 // lesstif 0.87 hangs here
2953 #ifndef LESSTIF_VERSION
2955 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2959 GetSize(& width1
, & height1
);
2960 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2962 SetSize(-1, -1, width
, height
);
2967 // ----------------------------------------------------------------------------
2969 // ----------------------------------------------------------------------------
2971 wxWindow
*wxGetActiveWindow()
2974 wxFAIL_MSG("Not implemented");
2979 wxWindow
*wxWindowBase::GetCapture()
2981 return (wxWindow
*)g_captureWindow
;
2985 // Find the wxWindow at the current mouse position, returning the mouse
2987 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
2989 return wxFindWindowAtPoint(wxGetMousePosition());
2992 // Get the current mouse position.
2993 wxPoint
wxGetMousePosition()
2995 Display
*display
= (Display
*) wxGetDisplay();
2996 Window rootWindow
= RootWindowOfScreen (DefaultScreenOfDisplay(display
));
2997 Window rootReturn
, childReturn
;
2998 int rootX
, rootY
, winX
, winY
;
2999 unsigned int maskReturn
;
3001 XQueryPointer (display
,
3005 &rootX
, &rootY
, &winX
, &winY
, &maskReturn
);
3006 return wxPoint(rootX
, rootY
);
3010 // ----------------------------------------------------------------------------
3011 // wxNoOptimize: switch off size optimization
3012 // ----------------------------------------------------------------------------
3014 int wxNoOptimize::ms_count
= 0;