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
);
413 m_mainWidget
= (WXWidget
) 0;
415 // Only if we're _really_ a canvas (not a dialog box/panel)
416 if (m_scrolledWindow
)
418 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
423 wxDeleteWindowFromTable((Widget
) m_hScrollBar
);
427 wxDeleteWindowFromTable((Widget
) m_vScrollBar
);
430 UnmanageAndDestroy(m_hScrollBar
);
431 UnmanageAndDestroy(m_vScrollBar
);
432 UnmanageAndDestroy(m_scrolledWindow
);
436 XtDestroyWidget ((Widget
) m_borderWidget
);
437 m_borderWidget
= (WXWidget
) 0;
441 // Destroy the window
444 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
445 // Child widgets will get destroyed automatically when a frame
446 // or dialog is destroyed, but before that you may get some memory
447 // leaks and potential layout problems if you delete and then add
449 XtDestroyWidget((Widget
) GetMainWidget());
450 SetMainWidget((WXWidget
) NULL
);
454 // ----------------------------------------------------------------------------
455 // scrollbar management
456 // ----------------------------------------------------------------------------
459 void wxWindow::CreateScrollbar(wxOrientation orientation
)
461 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
463 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
465 // Add scrollbars if required
466 if (orientation
== wxHORIZONTAL
)
468 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
469 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
470 XmNorientation
, XmHORIZONTAL
,
472 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
473 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
474 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
475 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
476 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
477 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
478 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
479 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
481 XtVaSetValues (hScrollBar
,
486 m_hScrollBar
= (WXWidget
) hScrollBar
;
488 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
489 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
491 XtRealizeWidget(hScrollBar
);
493 XtVaSetValues((Widget
) m_scrolledWindow
,
494 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
499 wxAddWindowToTable( hScrollBar
, this );
502 if (orientation
== wxVERTICAL
)
504 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
505 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
506 XmNorientation
, XmVERTICAL
,
508 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
509 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
510 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
511 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
512 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
513 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
514 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
515 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
517 XtVaSetValues (vScrollBar
,
522 m_vScrollBar
= (WXWidget
) vScrollBar
;
523 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
524 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
526 XtRealizeWidget(vScrollBar
);
528 XtVaSetValues((Widget
) m_scrolledWindow
,
529 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
534 wxAddWindowToTable( vScrollBar
, this );
537 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
540 void wxWindow::DestroyScrollbar(wxOrientation orientation
)
542 wxCHECK_RET( m_drawingArea
, "this window can't have scrollbars" );
544 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
545 // Add scrollbars if required
546 if (orientation
== wxHORIZONTAL
)
550 wxDeleteWindowFromTable((Widget
)m_hScrollBar
);
551 XtDestroyWidget((Widget
) m_hScrollBar
);
553 m_hScrollBar
= (WXWidget
) 0;
556 XtVaSetValues((Widget
) m_scrolledWindow
,
557 XmNhorizontalScrollBar
, (Widget
) 0,
562 if (orientation
== wxVERTICAL
)
566 wxDeleteWindowFromTable((Widget
)m_vScrollBar
);
567 XtDestroyWidget((Widget
) m_vScrollBar
);
569 m_vScrollBar
= (WXWidget
) 0;
572 XtVaSetValues((Widget
) m_scrolledWindow
,
573 XmNverticalScrollBar
, (Widget
) 0,
577 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
580 // ---------------------------------------------------------------------------
582 // ---------------------------------------------------------------------------
584 void wxWindow::SetFocus()
586 Widget wMain
= (Widget
) GetMainWidget();
587 XmProcessTraversal(wMain
, XmTRAVERSE_CURRENT
);
588 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
591 // Get the window with the focus
592 wxWindow
*wxWindowBase::FindFocus()
595 // (1) Can there be multiple focussed widgets in an application?
596 // In which case we need to find the top-level window that's
598 // (2) The widget with the focus may not be in the widget table
599 // depending on which widgets I put in the table
600 wxWindow
*winFocus
= (wxWindow
*)NULL
;
601 for ( wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
603 node
= node
->GetNext() )
605 wxWindow
*win
= node
->GetData();
607 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget());
609 if (w
!= (Widget
) NULL
)
611 winFocus
= wxGetWindowFromTable(w
);
620 bool wxWindow::Enable(bool enable
)
622 if ( !wxWindowBase::Enable(enable
) )
625 Widget wMain
= (Widget
)GetMainWidget();
628 XtSetSensitive(wMain
, enable
);
629 XmUpdateDisplay(wMain
);
635 bool wxWindow::Show(bool show
)
637 if ( !wxWindowBase::Show(show
) )
640 if (m_borderWidget
|| m_scrolledWindow
)
642 MapOrUnmap(m_drawingArea
, show
);
643 MapOrUnmap(m_borderWidget
? m_borderWidget
: m_scrolledWindow
, show
);
647 if ( !MapOrUnmap(GetTopWidget(), show
) )
648 MapOrUnmap(GetMainWidget(), show
);
652 Window xwin
= (Window
) GetXWindow();
653 Display
*xdisp
= (Display
*) GetXDisplay();
655 XMapWindow(xdisp
, xwin
);
657 XUnmapWindow(xdisp
, xwin
);
663 // Raise the window to the top of the Z order
664 void wxWindow::Raise()
666 Widget wTop
= (Widget
) GetTopWidget();
667 Window window
= XtWindow(wTop
);
668 XRaiseWindow(XtDisplay(wTop
), window
);
671 // Lower the window to the bottom of the Z order
672 void wxWindow::Lower()
674 Widget wTop
= (Widget
) GetTopWidget();
675 Window window
= XtWindow(wTop
);
676 XLowerWindow(XtDisplay(wTop
), window
);
679 void wxWindow::SetTitle(const wxString
& title
)
681 XtVaSetValues((Widget
)GetMainWidget(), XmNtitle
, title
.c_str(), NULL
);
684 wxString
wxWindow::GetTitle() const
687 XtVaGetValues((Widget
)GetMainWidget(), XmNtitle
, &title
, NULL
);
689 return wxString(title
);
692 void wxWindow::CaptureMouse()
697 Widget wMain
= (Widget
)GetMainWidget();
699 XtAddGrab(wMain
, TRUE
, FALSE
);
701 m_winCaptured
= TRUE
;
704 void wxWindow::ReleaseMouse()
706 if ( !m_winCaptured
)
709 Widget wMain
= (Widget
)GetMainWidget();
713 m_winCaptured
= FALSE
;
716 bool wxWindow::SetFont(const wxFont
& font
)
718 if ( !wxWindowBase::SetFont(font
) )
729 bool wxWindow::SetCursor(const wxCursor
& cursor
)
731 if ( !wxWindowBase::SetCursor(cursor
) )
737 wxASSERT_MSG( m_cursor
.Ok(),
738 wxT("cursor must be valid after call to the base version"));
740 WXDisplay
*dpy
= GetXDisplay();
741 WXCursor x_cursor
= m_cursor
.GetXCursor(dpy
);
743 Widget w
= (Widget
) GetMainWidget();
744 Window win
= XtWindow(w
);
745 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
750 // Coordinates relative to the window
751 void wxWindow::WarpPointer (int x
, int y
)
753 Widget wClient
= (Widget
)GetClientWidget();
755 XWarpPointer(XtDisplay(wClient
), None
, XtWindow(wClient
), 0, 0, 0, 0, x
, y
);
758 // ---------------------------------------------------------------------------
760 // ---------------------------------------------------------------------------
762 int wxWindow::GetScrollPos(int orient
) const
764 if (orient
== wxHORIZONTAL
)
770 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
774 XtVaGetValues(scrollBar
, XmNvalue
, &pos
, NULL
);
782 // This now returns the whole range, not just the number of positions that we
784 int wxWindow::GetScrollRange(int orient
) const
786 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
787 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
790 XtVaGetValues(scrollBar
, XmNmaximum
, &range
, NULL
);
794 int wxWindow::GetScrollThumb(int orient
) const
796 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
797 wxCHECK_MSG( scrollBar
, 0, "no such scrollbar" );
800 XtVaGetValues(scrollBar
, XmNsliderSize
, &thumb
, NULL
);
804 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
806 Widget scrollBar
= (Widget
)GetScrollbar((wxOrientation
)orient
);
810 XtVaSetValues (scrollBar
, XmNvalue
, pos
, NULL
);
813 SetInternalScrollPos((wxOrientation
)orient
, pos
);
816 // New function that will replace some of the above.
817 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
818 int range
, bool WXUNUSED(refresh
))
821 GetSize(& oldW
, & oldH
);
825 if (thumbVisible
== 0)
828 if (thumbVisible
> range
)
829 thumbVisible
= range
;
831 // Save the old state to see if it changed
832 WXWidget oldScrollBar
= GetScrollbar((wxOrientation
)orient
);
834 if (orient
== wxHORIZONTAL
)
836 if (thumbVisible
== range
)
839 DestroyScrollbar(wxHORIZONTAL
);
844 CreateScrollbar(wxHORIZONTAL
);
847 if (orient
== wxVERTICAL
)
849 if (thumbVisible
== range
)
852 DestroyScrollbar(wxVERTICAL
);
857 CreateScrollbar(wxVERTICAL
);
860 WXWidget newScrollBar
= GetScrollbar((wxOrientation
)orient
);
862 if (oldScrollBar
!= newScrollBar
)
864 // This is important! Without it, scrollbars misbehave badly.
865 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
866 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
867 XtRealizeWidget((Widget
) m_scrolledWindow
);
868 XtManageChild((Widget
) m_scrolledWindow
);
873 XtVaSetValues((Widget
) newScrollBar
,
877 XmNsliderSize
, thumbVisible
,
881 SetInternalScrollPos((wxOrientation
)orient
, pos
);
884 GetSize(& newW
, & newH
);
886 // Adjusting scrollbars can resize the canvas accidentally
887 if (newW
!= oldW
|| newH
!= oldH
)
888 SetSize(-1, -1, oldW
, oldH
);
891 // Does a physical scroll
892 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
897 // Use specified rectangle
898 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
902 // Use whole client area
904 GetClientSize(& w
, & h
);
907 wxNode
*cnode
= m_children
.First();
910 wxWindow
*child
= (wxWindow
*) cnode
->Data();
913 child
->GetSize( &sx
, &sy
);
914 wxPoint
pos( child
->GetPosition() );
915 child
->SetSize( pos
.x
+ dx
, pos
.y
+ dy
, sx
, sy
, wxSIZE_ALLOW_MINUS_ONE
);
916 cnode
= cnode
->Next();
919 int x1
= (dx
>= 0) ? x
: x
- dx
;
920 int y1
= (dy
>= 0) ? y
: y
- dy
;
921 int w1
= w
- abs(dx
);
922 int h1
= h
- abs(dy
);
923 int x2
= (dx
>= 0) ? x
+ dx
: x
;
924 int y2
= (dy
>= 0) ? y
+ dy
: y
;
928 dc
.SetLogicalFunction (wxCOPY
);
930 Widget widget
= (Widget
) GetMainWidget();
931 Window window
= XtWindow(widget
);
932 Display
* display
= XtDisplay(widget
);
934 XCopyArea(display
, window
, window
, (GC
) dc
.GetGC(),
935 x1
, y1
, w1
, h1
, x2
, y2
);
937 dc
.SetAutoSetting(TRUE
);
938 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
939 dc
.SetBrush(brush
); // FIXME: needed?
941 // We'll add rectangles to the list of update rectangles according to which
942 // bits we've exposed.
947 wxRect
*rect
= new wxRect
;
953 XFillRectangle(display
, window
,
954 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
958 rect
->width
= rect
->width
;
959 rect
->height
= rect
->height
;
961 updateRects
.Append((wxObject
*) rect
);
965 wxRect
*rect
= new wxRect
;
967 rect
->x
= x
+ w
+ dx
;
972 XFillRectangle(display
, window
,
973 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
978 rect
->width
= rect
->width
;
979 rect
->height
= rect
->height
;
981 updateRects
.Append((wxObject
*) rect
);
985 wxRect
*rect
= new wxRect
;
992 XFillRectangle(display
, window
,
993 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
997 rect
->width
= rect
->width
;
998 rect
->height
= rect
->height
;
1000 updateRects
.Append((wxObject
*) rect
);
1004 wxRect
*rect
= new wxRect
;
1007 rect
->y
= y
+ h
+ dy
;
1011 XFillRectangle(display
, window
,
1012 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1016 rect
->width
= rect
->width
;
1017 rect
->height
= rect
->height
;
1019 updateRects
.Append((wxObject
*) rect
);
1021 dc
.SetBrush(wxNullBrush
);
1023 // Now send expose events
1025 wxNode
* node
= updateRects
.First();
1028 wxRect
* rect
= (wxRect
*) node
->Data();
1031 event
.type
= Expose
;
1032 event
.display
= display
;
1033 event
.send_event
= True
;
1034 event
.window
= window
;
1038 event
.width
= rect
->width
;
1039 event
.height
= rect
->height
;
1043 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1045 node
= node
->Next();
1049 // Delete the update rects
1050 node
= updateRects
.First();
1053 wxRect
* rect
= (wxRect
*) node
->Data();
1055 node
= node
->Next();
1058 XmUpdateDisplay((Widget
) GetMainWidget());
1061 // ---------------------------------------------------------------------------
1063 // ---------------------------------------------------------------------------
1065 #if wxUSE_DRAG_AND_DROP
1067 void wxWindow::SetDropTarget(wxDropTarget
* WXUNUSED(pDropTarget
))
1074 // Old style file-manager drag&drop
1075 void wxWindow::DragAcceptFiles(bool WXUNUSED(accept
))
1080 // ----------------------------------------------------------------------------
1082 // ----------------------------------------------------------------------------
1086 void wxWindow::DoSetToolTip(wxToolTip
* WXUNUSED(tooltip
))
1091 #endif // wxUSE_TOOLTIPS
1093 // ----------------------------------------------------------------------------
1095 // ----------------------------------------------------------------------------
1097 bool wxWindow::DoPopupMenu(wxMenu
*menu
, int x
, int y
)
1099 Widget widget
= (Widget
) GetMainWidget();
1101 /* The menuId field seems to be usused, so we'll use it to
1102 indicate whether a menu is popped up or not:
1103 0: Not currently created as a popup
1104 -1: Created as a popup, but not active
1108 if (menu
->GetParent() && (menu
->GetId() != -1))
1111 if (menu
->GetMainWidget()) {
1112 menu
->DestroyMenu(TRUE
);
1115 menu
->SetId(1); /* Mark as popped-up */
1116 menu
->CreateMenu(NULL
, widget
, menu
);
1117 menu
->SetInvokingWindow(this);
1121 // menu->SetParent(parent);
1122 // parent->children->Append(menu); // Store menu for later deletion
1124 Widget menuWidget
= (Widget
) menu
->GetMainWidget();
1132 if (this->IsKindOf(CLASSINFO(wxCanvas)))
1134 wxCanvas *canvas = (wxCanvas *) this;
1135 deviceX = canvas->GetDC ()->LogicalToDeviceX (x);
1136 deviceY = canvas->GetDC ()->LogicalToDeviceY (y);
1140 Display
*display
= XtDisplay (widget
);
1141 Window rootWindow
= RootWindowOfScreen (XtScreen((Widget
)widget
));
1142 Window thisWindow
= XtWindow (widget
);
1144 XTranslateCoordinates (display
, thisWindow
, rootWindow
, (int) deviceX
, (int) deviceY
,
1145 &rootX
, &rootY
, &childWindow
);
1147 XButtonPressedEvent event
;
1148 event
.type
= ButtonPress
;
1154 event
.x_root
= rootX
;
1155 event
.y_root
= rootY
;
1157 XmMenuPosition (menuWidget
, &event
);
1158 XtManageChild (menuWidget
);
1163 // ---------------------------------------------------------------------------
1164 // moving and resizing
1165 // ---------------------------------------------------------------------------
1167 bool wxWindow::PreResize()
1173 void wxWindow::DoGetSize(int *x
, int *y
) const
1177 CanvasGetSize(x
, y
);
1181 Widget widget
= (Widget
) GetTopWidget();
1183 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1187 void wxWindow::DoGetPosition(int *x
, int *y
) const
1191 CanvasGetPosition(x
, y
);
1194 Widget widget
= (Widget
) GetTopWidget();
1196 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
1198 // We may be faking the client origin. So a window that's really at (0, 30)
1199 // may appear (to wxWin apps) to be at (0, 0).
1202 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1210 void wxWindow::DoScreenToClient(int *x
, int *y
) const
1212 Widget widget
= (Widget
) GetClientWidget();
1213 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1214 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1215 Window thisWindow
= XtWindow(widget
);
1220 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
1223 void wxWindow::DoClientToScreen(int *x
, int *y
) const
1225 Widget widget
= (Widget
) GetClientWidget();
1226 Display
*display
= XtDisplay(widget
);
1227 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
1228 Window thisWindow
= XtWindow(widget
);
1233 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
1237 // Get size *available for subwindows* i.e. excluding menu bar etc.
1238 void wxWindow::DoGetClientSize(int *x
, int *y
) const
1240 Widget widget
= (Widget
) GetClientWidget();
1242 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
1246 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1248 // A bit of optimization to help sort out the flickers.
1249 int oldX
, oldY
, oldW
, oldH
;
1250 GetSize(& oldW
, & oldH
);
1251 GetPosition(& oldX
, & oldY
);
1253 bool useOldPos
= FALSE
;
1254 bool useOldSize
= FALSE
;
1256 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
1258 else if (x
== oldX
&& y
== oldY
)
1261 if ((width
== -1) && (height
== -1))
1263 else if (width
== oldW
&& height
== oldH
)
1266 if (!wxNoOptimize::CanOptimize())
1268 useOldSize
= FALSE
; useOldPos
= FALSE
;
1271 if (useOldPos
&& useOldSize
)
1276 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
1279 Widget widget
= (Widget
) GetTopWidget();
1283 bool managed
= XtIsManaged( widget
);
1285 XtUnmanageChild(widget
);
1287 int xx
= x
; int yy
= y
;
1288 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
1292 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1293 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
1294 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
1295 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
1300 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1302 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1306 XtManageChild(widget
);
1308 // How about this bit. Maybe we don't need to generate size events
1309 // all the time -- they'll be generated when the window is sized anyway.
1311 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1312 sizeEvent
.SetEventObject(this);
1314 GetEventHandler()->ProcessEvent(sizeEvent
);
1318 void wxWindow::DoSetClientSize(int width
, int height
)
1322 CanvasSetClientSize(width
, height
);
1326 Widget widget
= (Widget
) GetTopWidget();
1329 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
1331 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
1333 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
1334 sizeEvent
.SetEventObject(this);
1336 GetEventHandler()->ProcessEvent(sizeEvent
);
1339 // For implementation purposes - sometimes decorations make the client area
1341 wxPoint
wxWindow::GetClientAreaOrigin() const
1343 return wxPoint(0, 0);
1346 // Makes an adjustment to the window position (for example, a frame that has
1347 // a toolbar that it manages itself).
1348 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
1350 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
1352 wxPoint
pt(GetParent()->GetClientAreaOrigin());
1353 x
+= pt
.x
; y
+= pt
.y
;
1357 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1364 wxFrame
*frame
= wxDynamicCast(this, wxFrame
);
1367 // TODO what about dialogs?
1371 Widget widget
= (Widget
) frame
->GetShellWidget();
1374 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1376 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1378 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1380 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1382 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1384 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1387 // ---------------------------------------------------------------------------
1389 // ---------------------------------------------------------------------------
1391 int wxWindow::GetCharHeight() const
1393 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1395 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1397 int direction
, ascent
, descent
;
1398 XCharStruct overall
;
1399 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1400 &descent
, &overall
);
1402 // return (overall.ascent + overall.descent);
1403 return (ascent
+ descent
);
1406 int wxWindow::GetCharWidth() const
1408 wxCHECK_MSG( m_font
.Ok(), 0, "valid window font needed" );
1410 WXFontStructPtr pFontStruct
= m_font
.GetFontStruct(1.0, GetXDisplay());
1412 int direction
, ascent
, descent
;
1413 XCharStruct overall
;
1414 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
1415 &descent
, &overall
);
1417 return overall
.width
;
1420 void wxWindow::GetTextExtent(const wxString
& string
,
1422 int *descent
, int *externalLeading
,
1423 const wxFont
*theFont
) const
1425 wxFont
*fontToUse
= (wxFont
*)theFont
;
1427 fontToUse
= (wxFont
*) & m_font
;
1429 wxCHECK_RET( fontToUse
->Ok(), "valid window font needed" );
1431 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
1433 int direction
, ascent
, descent2
;
1434 XCharStruct overall
;
1435 int slen
= string
.Len();
1439 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
1440 &ascent
, &descent2
, &overall
);
1443 XTextExtents((XFontStruct
*) pFontStruct
, string
, slen
,
1444 &direction
, &ascent
, &descent2
, &overall
);
1447 *x
= (overall
.width
);
1449 *y
= (ascent
+ descent2
);
1451 *descent
= descent2
;
1452 if (externalLeading
)
1453 *externalLeading
= 0;
1457 // ----------------------------------------------------------------------------
1459 // ----------------------------------------------------------------------------
1461 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
1463 m_needsRefresh
= TRUE
;
1464 Display
*display
= XtDisplay((Widget
) GetMainWidget());
1465 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
1467 XExposeEvent dummyEvent
;
1469 GetSize(&width
, &height
);
1471 dummyEvent
.type
= Expose
;
1472 dummyEvent
.display
= display
;
1473 dummyEvent
.send_event
= True
;
1474 dummyEvent
.window
= thisWindow
;
1477 dummyEvent
.x
= rect
->x
;
1478 dummyEvent
.y
= rect
->y
;
1479 dummyEvent
.width
= rect
->width
;
1480 dummyEvent
.height
= rect
->height
;
1486 dummyEvent
.width
= width
;
1487 dummyEvent
.height
= height
;
1489 dummyEvent
.count
= 0;
1493 wxClientDC
dc(this);
1494 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1495 dc
.SetBackground(backgroundBrush
);
1502 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1505 void wxWindow::Clear()
1507 wxClientDC
dc(this);
1508 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1509 dc
.SetBackground(brush
);
1513 void wxWindow::ClearUpdateRects()
1515 wxRectList::Node
* node
= m_updateRects
.GetFirst();
1518 wxRect
* rect
= node
->GetData();
1520 node
= node
->GetNext();
1523 m_updateRects
.Clear();
1526 void wxWindow::DoPaint()
1528 //TODO : make a temporary gc so we can do the XCopyArea below
1529 if (m_backingPixmap
&& !m_needsRefresh
)
1533 GC tempGC
= (GC
) dc
.GetBackingGC();
1535 Widget widget
= (Widget
) GetMainWidget();
1540 // We have to test whether it's a wxScrolledWindow (hack!) because
1541 // otherwise we don't know how many pixels have been scrolled. We might
1542 // solve this in the future by defining virtual wxWindow functions to get
1543 // the scroll position in pixels. Or, each kind of scrolled window has to
1544 // implement backing stores itself, using generic wxWindows code.
1545 wxScrolledWindow
* scrolledWindow
= wxDynamicCast(this, wxScrolledWindow
);
1546 if ( scrolledWindow
)
1549 scrolledWindow
->CalcScrolledPosition(0, 0, &x
, &y
);
1555 // TODO: This could be optimized further by only copying the areas in the
1556 // current update region.
1558 // Only blit the part visible in the client area. The backing pixmap
1559 // always starts at 0, 0 but we may be looking at only a portion of it.
1560 wxSize clientArea
= GetClientSize();
1561 int toBlitX
= m_pixmapWidth
- scrollPosX
;
1562 int toBlitY
= m_pixmapHeight
- scrollPosY
;
1564 // Copy whichever is samller, the amount of pixmap we have to copy,
1565 // or the size of the client area.
1566 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
1567 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
1569 // Make sure we're not negative
1570 toBlitX
= wxMax(0, toBlitX
);
1571 toBlitY
= wxMax(0, toBlitY
);
1576 (Pixmap
) m_backingPixmap
,
1579 scrollPosX
, scrollPosY
, // Start at the scroll position
1580 toBlitX
, toBlitY
, // How much of the pixmap to copy
1586 // Set an erase event first
1587 wxEraseEvent
eraseEvent(GetId());
1588 eraseEvent
.SetEventObject(this);
1589 GetEventHandler()->ProcessEvent(eraseEvent
);
1591 wxPaintEvent
event(GetId());
1592 event
.SetEventObject(this);
1593 GetEventHandler()->ProcessEvent(event
);
1595 m_needsRefresh
= FALSE
;
1599 // ----------------------------------------------------------------------------
1601 // ----------------------------------------------------------------------------
1603 // Responds to colour changes: passes event on to children.
1604 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1606 wxWindowList::Node
*node
= GetChildren().GetFirst();
1609 // Only propagate to non-top-level windows
1610 wxWindow
*win
= node
->GetData();
1611 if ( win
->GetParent() )
1613 wxSysColourChangedEvent event2
;
1614 event
.m_eventObject
= win
;
1615 win
->GetEventHandler()->ProcessEvent(event2
);
1618 node
= node
->GetNext();
1622 void wxWindow::OnIdle(wxIdleEvent
& WXUNUSED(event
))
1624 // This calls the UI-update mechanism (querying windows for
1625 // menu/toolbar/control state information)
1629 // ----------------------------------------------------------------------------
1631 // ----------------------------------------------------------------------------
1633 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
1635 if (!m_acceleratorTable
.Ok())
1638 int count
= m_acceleratorTable
.GetCount();
1639 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
1641 for (i
= 0; i
< count
; i
++)
1643 wxAcceleratorEntry
* entry
= & (entries
[i
]);
1644 if (entry
->MatchesEvent(event
))
1646 // Bingo, we have a match. Now find a control that matches the entry
1649 // Need to go up to the top of the window hierarchy, since it might
1650 // be e.g. a menu item
1651 wxWindow
* parent
= this;
1652 while ( parent
&& !parent
->IsTopLevel() )
1653 parent
= parent
->GetParent();
1658 wxFrame
* frame
= wxDynamicCast(parent
, wxFrame
);
1661 // Try for a menu command
1662 if (frame
->GetMenuBar())
1664 wxMenuItem
* item
= frame
->GetMenuBar()->FindItem(entry
->GetCommand());
1667 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
1668 commandEvent
.SetEventObject(frame
);
1670 // If ProcessEvent returns TRUE (it was handled), then
1671 // the calling code will skip the event handling.
1672 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
1677 // Find a child matching the command id
1678 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
1684 // Now we process those kinds of windows that we can.
1685 // For now, only buttons.
1686 if ( wxDynamicCast(child
, wxButton
) )
1688 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
1689 commandEvent
.SetEventObject(child
);
1690 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
1697 // We didn't match the key event against an accelerator.
1701 // ============================================================================
1702 // Motif-specific stuff from here on
1703 // ============================================================================
1705 // ----------------------------------------------------------------------------
1706 // function which maintain the global hash table mapping Widgets to wxWindows
1707 // ----------------------------------------------------------------------------
1709 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1711 wxWindow
*oldItem
= NULL
;
1712 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1714 wxLogDebug("Widget table clash: new widget is %ld, %s",
1715 (long)w
, win
->GetClassInfo()->GetClassName());
1719 wxWidgetHashTable
->Put((long) w
, win
);
1721 wxLogDebug("Widget 0x%08x <-> window %p (%s)",
1722 w
, win
, win
->GetClassInfo()->GetClassName());
1727 wxWindow
*wxGetWindowFromTable(Widget w
)
1729 return (wxWindow
*)wxWidgetHashTable
->Get((long) w
);
1732 void wxDeleteWindowFromTable(Widget w
)
1734 wxWidgetHashTable
->Delete((long)w
);
1737 // ----------------------------------------------------------------------------
1738 // add/remove window from the table
1739 // ----------------------------------------------------------------------------
1741 // Add to hash table, add event handler
1742 bool wxWindow::AttachWidget (wxWindow
* WXUNUSED(parent
), WXWidget mainWidget
,
1743 WXWidget formWidget
, int x
, int y
, int width
, int height
)
1745 wxAddWindowToTable((Widget
) mainWidget
, this);
1746 if (CanAddEventHandler())
1748 XtAddEventHandler((Widget
) mainWidget
,
1749 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1751 wxPanelItemEventHandler
,
1758 XtOverrideTranslations ((Widget
) mainWidget
,
1759 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1760 XtFree ((char *) ptr
);
1763 // Some widgets have a parent form widget, e.g. wxRadioBox
1766 if (!wxAddWindowToTable((Widget
) formWidget
, this))
1770 XtOverrideTranslations ((Widget
) formWidget
,
1771 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
1772 XtFree ((char *) ptr
);
1779 SetSize (x
, y
, width
, height
);
1784 // Remove event handler, remove from hash table
1785 bool wxWindow::DetachWidget(WXWidget widget
)
1787 if (CanAddEventHandler())
1789 XtRemoveEventHandler((Widget
) widget
,
1790 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
1792 wxPanelItemEventHandler
,
1796 wxDeleteWindowFromTable((Widget
) widget
);
1800 // ----------------------------------------------------------------------------
1801 // Motif-specific accessors
1802 // ----------------------------------------------------------------------------
1804 // Get the underlying X window
1805 WXWindow
wxWindow::GetXWindow() const
1807 Widget wMain
= (Widget
)GetMainWidget();
1809 return (WXWindow
) XtWindow(wMain
);
1811 return (WXWindow
) 0;
1814 // Get the underlying X display
1815 WXDisplay
*wxWindow::GetXDisplay() const
1817 Widget wMain
= (Widget
)GetMainWidget();
1819 return (WXDisplay
*) XtDisplay(wMain
);
1821 return (WXDisplay
*) NULL
;
1824 WXWidget
wxWindow::GetMainWidget() const
1827 return m_drawingArea
;
1829 return m_mainWidget
;
1832 WXWidget
wxWindow::GetClientWidget() const
1834 if (m_drawingArea
!= (WXWidget
) 0)
1835 return m_drawingArea
;
1837 return GetMainWidget();
1840 WXWidget
wxWindow::GetTopWidget() const
1842 return GetMainWidget();
1845 WXWidget
wxWindow::GetLabelWidget() const
1847 return GetMainWidget();
1850 // ----------------------------------------------------------------------------
1852 // ----------------------------------------------------------------------------
1854 // All widgets should have this as their resize proc.
1855 // OnSize sent to wxWindow via client data.
1856 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*WXUNUSED(event
), String
WXUNUSED(args
)[], int *WXUNUSED(num_args
))
1858 wxWindow
*win
= wxGetWindowFromTable(w
);
1862 if (win
->PreResize())
1865 win
->GetSize(&width
, &height
);
1866 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1867 sizeEvent
.SetEventObject(win
);
1868 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1872 static void wxCanvasRepaintProc(Widget drawingArea
,
1873 XtPointer clientData
,
1874 XmDrawingAreaCallbackStruct
* cbs
)
1876 if (!wxGetWindowFromTable(drawingArea
))
1879 XEvent
* event
= cbs
->event
;
1880 wxWindow
* win
= (wxWindow
*) clientData
;
1882 switch (event
->type
)
1886 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
1887 event
->xexpose
.width
, event
->xexpose
.height
);
1889 if (event
-> xexpose
.count
== 0)
1892 win
->ClearUpdateRects();
1899 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1900 static void wxCanvasEnterLeave(Widget drawingArea
,
1901 XtPointer
WXUNUSED(clientData
),
1902 XCrossingEvent
* event
)
1904 XmDrawingAreaCallbackStruct cbs
;
1907 ((XCrossingEvent
&) ev
) = *event
;
1909 cbs
.reason
= XmCR_INPUT
;
1912 wxCanvasInputEvent(drawingArea
, (XtPointer
) NULL
, &cbs
);
1915 // Fix to make it work under Motif 1.0 (!)
1916 static void wxCanvasMotionEvent (Widget
WXUNUSED(drawingArea
), XButtonEvent
* WXUNUSED(event
))
1918 #if XmVersion <= 1000
1919 XmDrawingAreaCallbackStruct cbs
;
1922 ev
= *((XEvent
*) event
);
1923 cbs
.reason
= XmCR_INPUT
;
1926 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1927 #endif // XmVersion <= 1000
1930 static void wxCanvasInputEvent(Widget drawingArea
,
1931 XtPointer
WXUNUSED(data
),
1932 XmDrawingAreaCallbackStruct
* cbs
)
1934 wxWindow
*canvas
= wxGetWindowFromTable(drawingArea
);
1940 if (cbs
->reason
!= XmCR_INPUT
)
1943 local_event
= *(cbs
->event
); // We must keep a copy!
1945 switch (local_event
.xany
.type
)
1953 // FIXME: most of this mouse event code is more or less
1954 // duplicated in wxTranslateMouseEvent
1956 wxEventType eventType
= wxEVT_NULL
;
1958 if (local_event
.xany
.type
== EnterNotify
)
1960 //if (local_event.xcrossing.mode!=NotifyNormal)
1961 // return ; // Ignore grab events
1962 eventType
= wxEVT_ENTER_WINDOW
;
1963 // canvas->GetEventHandler()->OnSetFocus();
1965 else if (local_event
.xany
.type
== LeaveNotify
)
1967 //if (local_event.xcrossingr.mode!=NotifyNormal)
1968 // return ; // Ignore grab events
1969 eventType
= wxEVT_LEAVE_WINDOW
;
1970 // canvas->GetEventHandler()->OnKillFocus();
1972 else if (local_event
.xany
.type
== MotionNotify
)
1974 eventType
= wxEVT_MOTION
;
1977 else if (local_event
.xany
.type
== ButtonPress
)
1979 if (local_event
.xbutton
.button
== Button1
)
1981 eventType
= wxEVT_LEFT_DOWN
;
1982 canvas
->SetButton1(TRUE
);
1984 else if (local_event
.xbutton
.button
== Button2
)
1986 eventType
= wxEVT_MIDDLE_DOWN
;
1987 canvas
->SetButton2(TRUE
);
1989 else if (local_event
.xbutton
.button
== Button3
)
1991 eventType
= wxEVT_RIGHT_DOWN
;
1992 canvas
->SetButton3(TRUE
);
1995 else if (local_event
.xany
.type
== ButtonRelease
)
1997 if (local_event
.xbutton
.button
== Button1
)
1999 eventType
= wxEVT_LEFT_UP
;
2000 canvas
->SetButton1(FALSE
);
2002 else if (local_event
.xbutton
.button
== Button2
)
2004 eventType
= wxEVT_MIDDLE_UP
;
2005 canvas
->SetButton2(FALSE
);
2007 else if (local_event
.xbutton
.button
== Button3
)
2009 eventType
= wxEVT_RIGHT_UP
;
2010 canvas
->SetButton3(FALSE
);
2014 wxMouseEvent
wxevent (eventType
);
2016 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2017 || (event_left_is_down (&local_event
)
2018 && (eventType
!= wxEVT_LEFT_UP
)));
2019 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2020 || (event_middle_is_down (&local_event
)
2021 && (eventType
!= wxEVT_MIDDLE_UP
)));
2022 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2023 || (event_right_is_down (&local_event
)
2024 && (eventType
!= wxEVT_RIGHT_UP
)));
2026 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2027 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2028 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2029 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2030 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2032 if ( eventType
== wxEVT_MOTION
)
2034 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2037 Display
*dpy
= XtDisplay (drawingArea
);
2039 XQueryPointer (dpy
, XtWindow (drawingArea
),
2041 &local_event
.xmotion
.x_root
,
2042 &local_event
.xmotion
.y_root
,
2043 &local_event
.xmotion
.x
,
2044 &local_event
.xmotion
.y
,
2045 &local_event
.xmotion
.state
);
2052 // Now check if we need to translate this event into a double click
2053 if (TRUE
) // canvas->doubleClickAllowed)
2055 if (wxevent
.ButtonDown())
2057 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2059 // get button and time-stamp
2061 if (wxevent
.LeftDown())
2063 else if (wxevent
.MiddleDown())
2065 else if (wxevent
.RightDown())
2067 long ts
= wxevent
.GetTimestamp();
2069 // check, if single or double click
2070 int buttonLast
= canvas
->GetLastClickedButton();
2071 long lastTS
= canvas
->GetLastClickTime();
2072 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2075 canvas
->SetLastClick(0, ts
);
2076 switch ( eventType
)
2078 case wxEVT_LEFT_DOWN
:
2079 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2081 case wxEVT_MIDDLE_DOWN
:
2082 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2084 case wxEVT_RIGHT_DOWN
:
2085 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2095 // not fast enough or different button
2096 canvas
->SetLastClick(button
, ts
);
2101 wxevent
.SetId(canvas
->GetId());
2102 wxevent
.SetEventObject(canvas
);
2103 wxevent
.m_x
= local_event
.xbutton
.x
;
2104 wxevent
.m_y
= local_event
.xbutton
.y
;
2105 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2107 if (eventType
== wxEVT_ENTER_WINDOW
||
2108 eventType
== wxEVT_LEAVE_WINDOW
||
2109 eventType
== wxEVT_MOTION
2119 XComposeStatus compose
;
2120 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, &compose
);
2123 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2124 int id
= wxCharCodeXToWX (keySym
);
2126 wxEventType eventType
= wxEVT_CHAR
;
2128 wxKeyEvent
event (eventType
);
2130 if (local_event
.xkey
.state
& ShiftMask
)
2131 event
.m_shiftDown
= TRUE
;
2132 if (local_event
.xkey
.state
& ControlMask
)
2133 event
.m_controlDown
= TRUE
;
2134 if (local_event
.xkey
.state
& Mod3Mask
)
2135 event
.m_altDown
= TRUE
;
2136 if (local_event
.xkey
.state
& Mod1Mask
)
2137 event
.m_metaDown
= TRUE
;
2138 event
.SetEventObject(canvas
);
2139 event
.m_keyCode
= id
;
2140 event
.SetTimestamp(local_event
.xkey
.time
);
2144 // Implement wxFrame::OnCharHook by checking ancestor.
2145 wxWindow
*parent
= canvas
->GetParent();
2146 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2147 parent
= parent
->GetParent();
2151 event
.SetEventType(wxEVT_CHAR_HOOK
);
2152 if (parent
->GetEventHandler()->ProcessEvent(event
))
2156 // For simplicity, OnKeyDown is the same as OnChar
2157 // TODO: filter modifier key presses from OnChar
2158 event
.SetEventType(wxEVT_KEY_DOWN
);
2160 // Only process OnChar if OnKeyDown didn't swallow it
2161 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2163 event
.SetEventType(wxEVT_CHAR
);
2164 canvas
->GetEventHandler()->ProcessEvent (event
);
2172 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2173 int id
= wxCharCodeXToWX (keySym
);
2175 wxKeyEvent
event (wxEVT_KEY_UP
);
2177 if (local_event
.xkey
.state
& ShiftMask
)
2178 event
.m_shiftDown
= TRUE
;
2179 if (local_event
.xkey
.state
& ControlMask
)
2180 event
.m_controlDown
= TRUE
;
2181 if (local_event
.xkey
.state
& Mod3Mask
)
2182 event
.m_altDown
= TRUE
;
2183 if (local_event
.xkey
.state
& Mod1Mask
)
2184 event
.m_metaDown
= TRUE
;
2185 event
.SetEventObject(canvas
);
2186 event
.m_keyCode
= id
;
2187 event
.SetTimestamp(local_event
.xkey
.time
);
2191 canvas
->GetEventHandler()->ProcessEvent (event
);
2197 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2199 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2200 event
.SetEventObject(canvas
);
2201 canvas
->GetEventHandler()->ProcessEvent(event
);
2207 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2209 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2210 event
.SetEventObject(canvas
);
2211 canvas
->GetEventHandler()->ProcessEvent(event
);
2220 static void wxPanelItemEventHandler(Widget wid
,
2221 XtPointer
WXUNUSED(client_data
),
2223 Boolean
*continueToDispatch
)
2225 // Widget can be a label or the actual widget.
2227 wxWindow
*window
= wxGetWindowFromTable(wid
);
2230 wxMouseEvent
wxevent(0);
2231 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2233 window
->GetEventHandler()->ProcessEvent(wxevent
);
2237 // TODO: probably the key to allowing default behaviour to happen. Say we
2238 // set a m_doDefault flag to FALSE at the start of this function. Then in
2239 // e.g. wxWindow::OnMouseEvent we can call Default() which sets this flag to
2240 // TRUE, indicating that default processing can happen. Thus, behaviour can
2241 // appear to be overridden just by adding an event handler and not calling
2242 // wxWindow::OnWhatever. ALSO, maybe we can use this instead of the current
2243 // way of handling drawing area events, to simplify things.
2244 *continueToDispatch
= True
;
2247 static void wxScrollBarCallback(Widget scrollbar
,
2248 XtPointer clientData
,
2249 XmScrollBarCallbackStruct
*cbs
)
2251 wxWindow
*win
= wxGetWindowFromTable(scrollbar
);
2252 int orientation
= (int) clientData
;
2254 wxEventType eventType
= wxEVT_NULL
;
2255 switch (cbs
->reason
)
2257 case XmCR_INCREMENT
:
2259 eventType
= wxEVT_SCROLLWIN_LINEDOWN
;
2262 case XmCR_DECREMENT
:
2264 eventType
= wxEVT_SCROLLWIN_LINEUP
;
2269 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2272 case XmCR_VALUE_CHANGED
:
2274 // TODO: Should this be intercepted too, or will it cause
2275 // duplicate events?
2276 eventType
= wxEVT_SCROLLWIN_THUMBTRACK
;
2279 case XmCR_PAGE_INCREMENT
:
2281 eventType
= wxEVT_SCROLLWIN_PAGEDOWN
;
2284 case XmCR_PAGE_DECREMENT
:
2286 eventType
= wxEVT_SCROLLWIN_PAGEUP
;
2291 eventType
= wxEVT_SCROLLWIN_TOP
;
2294 case XmCR_TO_BOTTOM
:
2296 eventType
= wxEVT_SCROLLWIN_BOTTOM
;
2301 // Should never get here
2302 wxFAIL_MSG("Unknown scroll event.");
2307 wxScrollWinEvent
event(eventType
,
2309 ((orientation
== XmHORIZONTAL
) ?
2310 wxHORIZONTAL
: wxVERTICAL
));
2311 event
.SetEventObject( win
);
2312 win
->GetEventHandler()->ProcessEvent(event
);
2315 // For repainting arbitrary windows
2316 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
2321 wxWindow
* win
= wxGetWindowFromTable(w
);
2325 switch(event
-> type
)
2329 window
= (Window
) win
-> GetXWindow();
2330 display
= (Display
*) win
-> GetXDisplay();
2332 if (event
-> xexpose
.count
== 0)
2336 win
->ClearUpdateRects();
2340 win
->AddUpdateRect(event
->xexpose
.x
, event
->xexpose
.y
,
2341 event
->xexpose
.width
, event
->xexpose
.height
);
2349 // ----------------------------------------------------------------------------
2350 // CanvaseXXXSize() functions
2351 // ----------------------------------------------------------------------------
2353 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2354 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2356 // A bit of optimization to help sort out the flickers.
2357 int oldX
, oldY
, oldW
, oldH
;
2358 GetSize(& oldW
, & oldH
);
2359 GetPosition(& oldX
, & oldY
);
2361 bool useOldPos
= FALSE
;
2362 bool useOldSize
= FALSE
;
2364 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2366 else if (x
== oldX
&& y
== oldY
)
2369 if ((w
== -1) && (h
== -1))
2371 else if (w
== oldW
&& h
== oldH
)
2374 if (!wxNoOptimize::CanOptimize())
2376 useOldSize
= FALSE
; useOldPos
= FALSE
;
2379 if (useOldPos
&& useOldSize
)
2382 Widget drawingArea
= (Widget
) m_drawingArea
;
2383 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2386 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2387 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2389 int xx
= x
; int yy
= y
;
2390 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2394 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2396 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2400 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2402 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2414 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2415 short thick
, margin
;
2416 XtVaGetValues ((Widget
) m_borderWidget
,
2417 XmNshadowThickness
, &thick
,
2418 XmNmarginWidth
, &margin
,
2420 w
-= 2 * (thick
+ margin
);
2423 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2427 XtVaGetValues ((Widget
) m_scrolledWindow
,
2428 XmNspacing
, &spacing
,
2429 XmNverticalScrollBar
, &sbar
,
2433 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2437 w
-= (spacing
+ wsbar
);
2440 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2447 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2448 short thick
, margin
;
2449 XtVaGetValues ((Widget
) m_borderWidget
,
2450 XmNshadowThickness
, &thick
,
2451 XmNmarginHeight
, &margin
,
2453 h
-= 2 * (thick
+ margin
);
2456 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2460 XtVaGetValues ((Widget
) m_scrolledWindow
,
2461 XmNspacing
, &spacing
,
2462 XmNhorizontalScrollBar
, &sbar
,
2466 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2470 h
-= (spacing
+ wsbar
);
2473 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2479 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2480 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2484 GetClientSize (&ww
, &hh
);
2485 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2486 sizeEvent
.SetEventObject(this);
2488 GetEventHandler()->ProcessEvent(sizeEvent
);
2492 void wxWindow::CanvasSetClientSize (int w
, int h
)
2494 Widget drawingArea
= (Widget
) m_drawingArea
;
2496 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2499 XtVaSetValues(drawingArea
, XmNwidth
, w
, NULL
);
2501 XtVaSetValues(drawingArea
, XmNheight
, h
, NULL
);
2504 // TODO: is this necessary?
2505 allowRepainting
= FALSE
;
2507 XSync (XtDisplay (drawingArea
), FALSE
);
2509 while (XtAppPending (wxTheApp
->appContext
))
2511 XFlush (XtDisplay (drawingArea
));
2512 XtAppNextEvent (wxTheApp
->appContext
, &event
);
2513 XtDispatchEvent (&event
);
2517 XtVaSetValues(drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2520 allowRepainting
= TRUE
;
2523 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2524 sizeEvent
.SetEventObject(this);
2526 GetEventHandler()->ProcessEvent(sizeEvent
);
2530 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2532 // Must return the same thing that was set via SetClientSize
2534 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2539 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2542 if ((Widget
) m_borderWidget
)
2543 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2544 else if ((Widget
) m_scrolledWindow
)
2545 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2547 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2553 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2556 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2558 // We may be faking the client origin.
2559 // So a window that's really at (0, 30) may appear
2560 // (to wxWin apps) to be at (0, 0).
2563 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2572 // ----------------------------------------------------------------------------
2573 // TranslateXXXEvent() functions
2574 // ----------------------------------------------------------------------------
2576 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2578 switch (xevent
->xany
.type
)
2580 case EnterNotify
: // never received here - yes ? MB
2581 case LeaveNotify
: // never received here - yes ? MB
2586 wxEventType eventType
= wxEVT_NULL
;
2588 // FIXME: this is never true I think - MB
2590 if (xevent
->xany
.type
== LeaveNotify
)
2592 win
->SetButton1(FALSE
);
2593 win
->SetButton2(FALSE
);
2594 win
->SetButton3(FALSE
);
2597 else if (xevent
->xany
.type
== MotionNotify
)
2599 eventType
= wxEVT_MOTION
;
2601 else if (xevent
->xany
.type
== ButtonPress
)
2603 wxevent
.SetTimestamp(xevent
->xbutton
.time
);
2605 if (xevent
->xbutton
.button
== Button1
)
2607 eventType
= wxEVT_LEFT_DOWN
;
2608 win
->SetButton1(TRUE
);
2611 else if (xevent
->xbutton
.button
== Button2
)
2613 eventType
= wxEVT_MIDDLE_DOWN
;
2614 win
->SetButton2(TRUE
);
2617 else if (xevent
->xbutton
.button
== Button3
)
2619 eventType
= wxEVT_RIGHT_DOWN
;
2620 win
->SetButton3(TRUE
);
2624 // check for a double click
2626 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay());
2627 long ts
= wxevent
.GetTimestamp();
2629 int buttonLast
= win
->GetLastClickedButton();
2630 long lastTS
= win
->GetLastClickTime();
2631 if ( buttonLast
&& buttonLast
== button
&& (ts
- lastTS
) < dclickTime
)
2634 win
->SetLastClick(0, ts
);
2635 switch ( eventType
)
2637 case wxEVT_LEFT_DOWN
:
2638 eventType
= wxEVT_LEFT_DCLICK
;
2640 case wxEVT_MIDDLE_DOWN
:
2641 eventType
= wxEVT_MIDDLE_DCLICK
;
2643 case wxEVT_RIGHT_DOWN
:
2644 eventType
= wxEVT_RIGHT_DCLICK
;
2654 // not fast enough or different button
2655 win
->SetLastClick(button
, ts
);
2658 else if (xevent
->xany
.type
== ButtonRelease
)
2660 if (xevent
->xbutton
.button
== Button1
)
2662 eventType
= wxEVT_LEFT_UP
;
2663 win
->SetButton1(FALSE
);
2665 else if (xevent
->xbutton
.button
== Button2
)
2667 eventType
= wxEVT_MIDDLE_UP
;
2668 win
->SetButton2(FALSE
);
2670 else if (xevent
->xbutton
.button
== Button3
)
2672 eventType
= wxEVT_RIGHT_UP
;
2673 win
->SetButton3(FALSE
);
2682 wxevent
.SetEventType(eventType
);
2685 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2688 win
->GetPosition(&x2
, &y2
);
2690 // The button x/y must be translated to wxWindows
2691 // window space - the widget might be a label or button,
2695 if (widget
!= (Widget
)win
->GetMainWidget())
2701 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2702 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2704 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2705 || (event_left_is_down (xevent
)
2706 && (eventType
!= wxEVT_LEFT_UP
)));
2707 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2708 || (event_middle_is_down (xevent
)
2709 && (eventType
!= wxEVT_MIDDLE_UP
)));
2710 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2711 || (event_right_is_down (xevent
)
2712 && (eventType
!= wxEVT_RIGHT_UP
)));
2714 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2715 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2716 wxevent
.m_altDown
= xevent
->xbutton
.state
& Mod3Mask
;
2717 wxevent
.m_metaDown
= xevent
->xbutton
.state
& Mod1Mask
;
2719 wxevent
.SetId(win
->GetId());
2720 wxevent
.SetEventObject(win
);
2728 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget
WXUNUSED(widget
), XEvent
*xevent
)
2730 switch (xevent
->xany
.type
)
2739 XComposeStatus compose
;
2740 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, &compose
);
2742 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2743 int id
= wxCharCodeXToWX (keySym
);
2745 if (xevent
->xkey
.state
& ShiftMask
)
2746 wxevent
.m_shiftDown
= TRUE
;
2747 if (xevent
->xkey
.state
& ControlMask
)
2748 wxevent
.m_controlDown
= TRUE
;
2749 if (xevent
->xkey
.state
& Mod3Mask
)
2750 wxevent
.m_altDown
= TRUE
;
2751 if (xevent
->xkey
.state
& Mod1Mask
)
2752 wxevent
.m_metaDown
= TRUE
;
2753 wxevent
.SetEventObject(win
);
2754 wxevent
.m_keyCode
= id
;
2755 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2757 wxevent
.m_x
= xevent
->xbutton
.x
;
2758 wxevent
.m_y
= xevent
->xbutton
.y
;
2772 // ----------------------------------------------------------------------------
2774 // ----------------------------------------------------------------------------
2776 #define YAllocColor XAllocColor
2777 XColor g_itemColors
[5];
2778 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2781 static XmColorProc colorProc
;
2783 result
= wxNO_COLORS
;
2787 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2788 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2789 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2790 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2791 if (colorProc
== (XmColorProc
) NULL
)
2793 // Get a ptr to the actual function
2794 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2795 // And set it back to motif.
2796 XmSetColorCalculation (colorProc
);
2798 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2799 &g_itemColors
[wxFORE_INDEX
],
2800 &g_itemColors
[wxSELE_INDEX
],
2801 &g_itemColors
[wxTOPS_INDEX
],
2802 &g_itemColors
[wxBOTS_INDEX
]);
2803 result
= wxBACK_COLORS
;
2807 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2808 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2809 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2810 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2811 if (result
== wxNO_COLORS
)
2812 result
= wxFORE_COLORS
;
2815 Display
*dpy
= display
;
2816 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2820 /* 5 Colours to allocate */
2821 for (int i
= 0; i
< 5; i
++)
2822 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2823 result
= wxNO_COLORS
;
2827 /* Only 1 colour to allocate */
2828 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
2829 result
= wxNO_COLORS
;
2836 // Changes the foreground and background colours to be derived from the current
2837 // background colour. To change the foreground colour, you must call
2838 // SetForegroundColour explicitly.
2839 void wxWindow::ChangeBackgroundColour()
2841 WXWidget mainWidget
= GetMainWidget();
2843 DoChangeBackgroundColour(mainWidget
, m_backgroundColour
);
2845 // This not necessary
2848 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
2850 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
2851 // Have to set the scrollbar colours back since
2852 // the scrolled window seemed to change them
2853 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
2856 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
2858 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
2863 void wxWindow::ChangeForegroundColour()
2865 WXWidget mainWidget
= GetMainWidget();
2867 DoChangeForegroundColour(mainWidget
, m_foregroundColour
);
2868 if ( m_scrolledWindow
&& mainWidget
!= m_scrolledWindow
)
2869 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
2872 // Change a widget's foreground and background colours.
2873 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
2875 // When should we specify the foreground, if it's calculated
2876 // by wxComputeColours?
2877 // Solution: say we start with the default (computed) foreground colour.
2878 // If we call SetForegroundColour explicitly for a control or window,
2879 // then the foreground is changed.
2880 // Therefore SetBackgroundColour computes the foreground colour, and
2881 // SetForegroundColour changes the foreground colour. The ordering is
2884 Widget w
= (Widget
)widget
;
2887 XmNforeground
, foregroundColour
.AllocColour(XtDisplay(w
)),
2892 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
2894 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
2897 XtVaSetValues ((Widget
) widget
,
2898 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
2899 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
2900 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
2901 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
2904 if (changeArmColour
)
2905 XtVaSetValues ((Widget
) widget
,
2906 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
2910 bool wxWindow::SetBackgroundColour(const wxColour
& col
)
2912 if ( !wxWindowBase::SetBackgroundColour(col
) )
2915 ChangeBackgroundColour();
2920 bool wxWindow::SetForegroundColour(const wxColour
& col
)
2922 if ( !wxWindowBase::SetForegroundColour(col
) )
2925 ChangeForegroundColour();
2930 void wxWindow::ChangeFont(bool keepOriginalSize
)
2932 // Note that this causes the widget to be resized back
2933 // to its original size! We therefore have to set the size
2934 // back again. TODO: a better way in Motif?
2935 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
2936 if (w
&& m_font
.Ok())
2938 int width
, height
, width1
, height1
;
2939 GetSize(& width
, & height
);
2941 // lesstif 0.87 hangs here
2942 #ifndef LESSTIF_VERSION
2944 XmNfontList
, (XmFontList
) m_font
.GetFontList(1.0, XtDisplay(w
)),
2948 GetSize(& width1
, & height1
);
2949 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
2951 SetSize(-1, -1, width
, height
);
2956 // ----------------------------------------------------------------------------
2958 // ----------------------------------------------------------------------------
2960 wxWindow
*wxGetActiveWindow()
2966 // ----------------------------------------------------------------------------
2967 // wxNoOptimize: switch off size optimization
2968 // ----------------------------------------------------------------------------
2970 int wxNoOptimize::ms_count
= 0;