1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/menuitem.h"
34 #if wxUSE_DRAG_AND_DROP
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
46 #include "wx/motif/private.h"
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
52 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
54 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
55 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
56 XmScaleCallbackStruct
*cbs
);
57 void wxPanelItemEventHandler (Widget wid
,
58 XtPointer client_data
,
60 Boolean
*continueToDispatch
);
62 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
63 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
64 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
66 extern wxList wxPendingDelete
;
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
71 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
72 EVT_CHAR(wxWindow::OnChar
)
73 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
74 EVT_KEY_UP(wxWindow::OnKeyUp
)
75 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
76 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
77 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
78 EVT_IDLE(wxWindow::OnIdle
)
90 m_windowParent
= NULL
;
91 m_windowEventHandler
= this;
93 m_windowCursor
= *wxSTANDARD_CURSOR
;
94 m_children
= new wxList
;
96 m_constraintsInvolvedIn
= NULL
;
100 m_windowValidator
= NULL
;
101 m_defaultItem
= NULL
;
103 m_caretWidth
= 0; m_caretHeight
= 0;
104 m_caretEnabled
= FALSE
;
105 m_caretShown
= FALSE
;
106 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
107 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
108 m_foregroundColour
= *wxBLACK
;
110 #if wxUSE_DRAG_AND_DROP
111 m_pDropTarget
= NULL
;
113 m_clientObject
= (wxClientData
*) NULL
;
117 m_mainWidget
= (WXWidget
) 0;
118 m_button1Pressed
= FALSE
;
119 m_button2Pressed
= FALSE
;
120 m_button3Pressed
= FALSE
;
121 m_winCaptured
= FALSE
;
123 m_hScrollBar
= (WXWidget
) 0;
124 m_vScrollBar
= (WXWidget
) 0;
125 m_borderWidget
= (WXWidget
) 0;
126 m_scrolledWindow
= (WXWidget
) 0;
127 m_drawingArea
= (WXWidget
) 0;
130 m_backingPixmap
= (WXPixmap
) 0;
137 m_canAddEventHandler
= FALSE
;
143 wxWindow::~wxWindow()
145 // Remove potential dangling pointer
146 if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel
)))
148 wxPanel
* panel
= (wxPanel
*) GetParent();
149 if (panel
->GetLastFocus() == this)
150 panel
->SetLastFocus((wxWindow
*) NULL
);
156 DetachWidget(GetMainWidget()); // Removes event handlers
158 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
161 // Destroy children before destroying self
165 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
167 Widget w
= (Widget
) m_drawingArea
;
168 wxDeleteWindowFromTable(w
);
172 m_mainWidget
= (WXWidget
) 0;
174 // Only if we're _really_ a canvas (not a dialog box/panel)
175 if (m_scrolledWindow
)
177 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
182 XtUnmanageChild ((Widget
) m_hScrollBar
);
183 XtDestroyWidget ((Widget
) m_hScrollBar
);
187 XtUnmanageChild ((Widget
) m_vScrollBar
);
188 XtDestroyWidget ((Widget
) m_vScrollBar
);
190 if (m_scrolledWindow
)
192 XtUnmanageChild ((Widget
) m_scrolledWindow
);
193 XtDestroyWidget ((Widget
) m_scrolledWindow
);
198 XtDestroyWidget ((Widget
) m_borderWidget
);
199 m_borderWidget
= (WXWidget
) 0;
205 // Have to delete constraints/sizer FIRST otherwise
206 // sizers may try to look at deleted windows as they
207 // delete themselves.
208 #if wxUSE_CONSTRAINTS
209 DeleteRelatedConstraints();
212 // This removes any dangling pointers to this window
213 // in other windows' constraintsInvolvedIn lists.
214 UnsetConstraints(m_constraints
);
215 delete m_constraints
;
216 m_constraints
= NULL
;
220 delete m_windowSizer
;
221 m_windowSizer
= NULL
;
223 // If this is a child of a sizer, remove self from parent
225 m_sizerParent
->RemoveChild((wxWindow
*)this);
229 m_windowParent
->RemoveChild(this);
233 // Destroy the window
236 wxDeleteWindowFromTable((Widget
) GetMainWidget());
237 XtDestroyWidget((Widget
) GetMainWidget());
238 SetMainWidget((WXWidget
) NULL
);
244 // Just in case the window has been Closed, but
245 // we're then deleting immediately: don't leave
246 // dangling pointers.
247 wxPendingDelete
.DeleteObject(this);
249 if ( m_windowValidator
) delete m_windowValidator
;
250 if (m_clientObject
) delete m_clientObject
;
255 // Destroy the window (delayed, if a managed window)
256 bool wxWindow::Destroy()
263 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
267 const wxString
& name
)
272 m_windowParent
= NULL
;
273 m_windowEventHandler
= this;
275 m_windowCursor
= *wxSTANDARD_CURSOR
;
276 m_constraints
= NULL
;
277 m_constraintsInvolvedIn
= NULL
;
278 m_windowSizer
= NULL
;
279 m_sizerParent
= NULL
;
280 m_autoLayout
= FALSE
;
281 m_windowValidator
= NULL
;
282 #if wxUSE_DRAG_AND_DROP
283 m_pDropTarget
= NULL
;
285 m_caretWidth
= 0; m_caretHeight
= 0;
286 m_caretEnabled
= FALSE
;
287 m_caretShown
= FALSE
;
292 m_defaultItem
= NULL
;
293 m_windowParent
= NULL
;
294 m_clientObject
= (wxClientData
*) NULL
;
298 m_canAddEventHandler
= FALSE
;
299 m_mainWidget
= (WXWidget
) 0;
300 m_button1Pressed
= FALSE
;
301 m_button2Pressed
= FALSE
;
302 m_button3Pressed
= FALSE
;
303 m_winCaptured
= FALSE
;
305 m_hScrollBar
= (WXWidget
) 0;
306 m_vScrollBar
= (WXWidget
) 0;
307 m_borderWidget
= (WXWidget
) 0;
308 m_scrolledWindow
= (WXWidget
) 0;
309 m_drawingArea
= (WXWidget
) 0;
312 m_backingPixmap
= (WXPixmap
) 0;
323 if (parent
) parent
->AddChild(this);
330 m_windowId
= (int)NewControlId();
334 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
335 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
336 m_foregroundColour
= *wxBLACK
;
338 m_windowStyle
= style
;
341 m_windowId
= (int)NewControlId();
345 //// TODO: we should probably optimize by only creating a
346 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
347 //// But for now, let's simplify things by always creating the
348 //// drawing area, since otherwise the translations are different.
350 // New translations for getting mouse motion feedback
351 String translations
=
352 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
353 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
354 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
355 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
356 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
357 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
358 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
359 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
360 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
361 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
362 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
363 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
364 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
365 <Key>: DrawingAreaInput()";
367 XtActionsRec actions
[1];
368 actions
[0].string
= "wxCanvasMotionEvent";
369 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
370 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
372 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
373 if (style
& wxBORDER
)
374 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
375 xmFrameWidgetClass
, parentWidget
,
376 XmNshadowType
, XmSHADOW_IN
,
379 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
380 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
381 XmNresizePolicy
, XmRESIZE_NONE
,
383 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
384 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
388 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
389 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
390 XmNunitType
, XmPIXELS
,
391 // XmNresizePolicy, XmRESIZE_ANY,
392 XmNresizePolicy
, XmRESIZE_NONE
,
395 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
398 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
400 XtFree ((char *) ptr);
401 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
402 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
403 XtFree ((char *) ptr);
407 wxAddWindowToTable((Widget
) m_drawingArea
, this);
408 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
411 * This order is very important in Motif 1.2.1
415 XtRealizeWidget ((Widget
) m_scrolledWindow
);
416 XtRealizeWidget ((Widget
) m_drawingArea
);
417 XtManageChild ((Widget
) m_drawingArea
);
419 XtOverrideTranslations ((Widget
) m_drawingArea
,
420 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
421 XtFree ((char *) ptr
);
423 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
424 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
427 display = XtDisplay (scrolledWindow);
428 xwindow = XtWindow (drawingArea);
431 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
432 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
434 // Scrolled widget needs to have its colour changed or we get
435 // a little blue square where the scrollbars abutt
436 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
437 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
438 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
440 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) 0, (Widget
) 0, (Widget
) m_drawingArea
);
444 XtRealizeWidget ((Widget) m_hScrollBar);
446 XtRealizeWidget ((Widget) m_vScrollBar);
449 // Without this, the cursor may not be restored properly
450 // (e.g. in splitter sample).
451 SetCursor(*wxSTANDARD_CURSOR
);
452 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
453 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
459 void wxWindow::CreateScrollbar(int orientation
)
464 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
466 // Add scrollbars if required
467 if (orientation
== wxHORIZONTAL
)
469 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
470 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
471 XmNorientation
, XmHORIZONTAL
,
473 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
474 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
475 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
476 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
477 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
478 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
479 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
480 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
482 XtVaSetValues (hScrollBar
,
487 m_hScrollBar
= (WXWidget
) hScrollBar
;
489 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
490 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
492 XtRealizeWidget(hScrollBar
);
494 XtVaSetValues((Widget
) m_scrolledWindow
,
495 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
501 if (orientation
== wxVERTICAL
)
503 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
504 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
505 XmNorientation
, XmVERTICAL
,
507 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
508 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
509 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
510 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
511 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
512 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
513 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
514 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
516 XtVaSetValues (vScrollBar
,
521 m_vScrollBar
= (WXWidget
) vScrollBar
;
522 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
523 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
525 XtRealizeWidget(vScrollBar
);
527 XtVaSetValues((Widget
) m_scrolledWindow
,
528 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
534 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
536 void wxWindow::DestroyScrollbar(int orientation
)
541 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
542 // Add scrollbars if required
543 if (orientation
== wxHORIZONTAL
)
547 XtDestroyWidget((Widget
) m_hScrollBar
);
549 m_hScrollBar
= (WXWidget
) 0;
552 XtVaSetValues((Widget
) m_scrolledWindow
,
553 XmNhorizontalScrollBar
, (Widget
) 0,
558 if (orientation
== wxVERTICAL
)
562 XtDestroyWidget((Widget
) m_vScrollBar
);
564 m_vScrollBar
= (WXWidget
) 0;
567 XtVaSetValues((Widget
) m_scrolledWindow
,
568 XmNverticalScrollBar
, (Widget
) 0,
572 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
575 void wxWindow::SetFocus()
577 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
578 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
581 void wxWindow::Enable(bool enable
)
585 XtSetSensitive((Widget
) GetMainWidget(), enable
);
586 XmUpdateDisplay((Widget
) GetMainWidget());
590 void wxWindow::CaptureMouse()
596 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
598 m_winCaptured
= TRUE
;
601 void wxWindow::ReleaseMouse()
607 XtRemoveGrab((Widget
) GetMainWidget());
608 m_winCaptured
= FALSE
;
611 // Push/pop event handler (i.e. allow a chain of event handlers
613 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
615 handler
->SetNextHandler(GetEventHandler());
616 SetEventHandler(handler
);
619 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
621 if ( GetEventHandler() )
623 wxEvtHandler
*handlerA
= GetEventHandler();
624 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
625 handlerA
->SetNextHandler(NULL
);
626 SetEventHandler(handlerB
);
639 #if wxUSE_DRAG_AND_DROP
641 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
643 if ( m_pDropTarget
!= 0 ) {
644 delete m_pDropTarget
;
647 m_pDropTarget
= pDropTarget
;
648 if ( m_pDropTarget
!= 0 )
656 // Old style file-manager drag&drop
657 void wxWindow::DragAcceptFiles(bool accept
)
663 void wxWindow::GetSize(int *x
, int *y
) const
671 Widget widget
= (Widget
) GetTopWidget();
673 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
677 void wxWindow::GetPosition(int *x
, int *y
) const
681 CanvasGetPosition(x
, y
);
684 Widget widget
= (Widget
) GetTopWidget();
686 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
688 // We may be faking the client origin.
689 // So a window that's really at (0, 30) may appear
690 // (to wxWin apps) to be at (0, 0).
693 wxPoint
pt(GetParent()->GetClientAreaOrigin());
701 void wxWindow::ScreenToClient(int *x
, int *y
) const
703 Widget widget
= (Widget
) GetClientWidget();
704 Display
*display
= XtDisplay((Widget
) GetMainWidget());
705 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
706 Window thisWindow
= XtWindow(widget
);
711 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
714 void wxWindow::ClientToScreen(int *x
, int *y
) const
716 Widget widget
= (Widget
) GetClientWidget();
717 Display
*display
= XtDisplay(widget
);
718 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
719 Window thisWindow
= XtWindow(widget
);
724 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
727 void wxWindow::SetCursor(const wxCursor
& cursor
)
729 m_windowCursor
= cursor
;
730 if (m_windowCursor
.Ok())
732 WXDisplay
*dpy
= GetXDisplay();
733 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
735 Widget w
= (Widget
) GetMainWidget();
736 Window win
= XtWindow(w
);
737 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
742 // Get size *available for subwindows* i.e. excluding menu bar etc.
743 void wxWindow::GetClientSize(int *x
, int *y
) const
745 Widget widget
= (Widget
) GetClientWidget();
747 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
751 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
753 // A bit of optimization to help sort out the flickers.
754 int oldX
, oldY
, oldW
, oldH
;
755 GetSize(& oldW
, & oldH
);
756 GetPosition(& oldX
, & oldY
);
758 bool useOldPos
= FALSE
;
759 bool useOldSize
= FALSE
;
761 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
763 else if (x
== oldX
&& y
== oldY
)
766 if ((width
== -1) && (height
== -1))
768 else if (width
== oldW
&& height
== oldH
)
771 if (!wxNoOptimize::CanOptimize())
773 useOldSize
= FALSE
; useOldPos
= FALSE
;
776 if (useOldPos
&& useOldSize
)
781 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
784 Widget widget
= (Widget
) GetTopWidget();
788 bool managed
= XtIsManaged( widget
);
790 XtUnmanageChild(widget
);
792 int xx
= x
; int yy
= y
;
793 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
797 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
798 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
799 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
800 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
805 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
807 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
811 XtManageChild(widget
);
813 // How about this bit. Maybe we don't need to generate size events
814 // all the time -- they'll be generated when the window is sized anyway.
816 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
817 sizeEvent.SetEventObject(this);
819 GetEventHandler()->ProcessEvent(sizeEvent);
823 void wxWindow::SetClientSize(int width
, int height
)
827 CanvasSetClientSize(width
, height
);
831 Widget widget
= (Widget
) GetTopWidget();
834 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
836 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
838 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
839 sizeEvent
.SetEventObject(this);
841 GetEventHandler()->ProcessEvent(sizeEvent
);
844 // For implementation purposes - sometimes decorations make the client area
846 wxPoint
wxWindow::GetClientAreaOrigin() const
848 return wxPoint(0, 0);
851 // Makes an adjustment to the window position (for example, a frame that has
852 // a toolbar that it manages itself).
853 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
855 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
857 wxPoint
pt(GetParent()->GetClientAreaOrigin());
858 x
+= pt
.x
; y
+= pt
.y
;
862 bool wxWindow::Show(bool show
)
866 if (m_borderWidget
|| m_scrolledWindow
)
869 XtMapWidget((Widget
) m_drawingArea
);
870 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
874 WXWidget topWidget
= GetTopWidget();
876 XtMapWidget((Widget
) GetTopWidget());
877 else if (GetMainWidget())
878 XtMapWidget((Widget
) GetMainWidget());
883 if (m_borderWidget
|| m_scrolledWindow
)
886 XtUnmapWidget((Widget
) m_drawingArea
);
887 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
892 XtUnmapWidget((Widget
) GetTopWidget());
893 else if (GetMainWidget())
894 XtUnmapWidget((Widget
) GetMainWidget());
899 Window xwin = (Window) GetXWindow();
900 Display *xdisp = (Display*) GetXDisplay();
902 XMapWindow(xdisp, xwin);
904 XUnmapWindow(xdisp, xwin);
912 bool wxWindow::IsShown() const
917 int wxWindow::GetCharHeight() const
919 if (!m_windowFont
.Ok())
922 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
924 int direction
, ascent
, descent
;
926 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
928 // return (overall.ascent + overall.descent);
929 return (ascent
+ descent
);
932 int wxWindow::GetCharWidth() const
934 if (!m_windowFont
.Ok())
937 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
939 int direction
, ascent
, descent
;
941 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
943 return overall
.width
;
946 /* Helper function for 16-bit fonts */
947 static int str16len(const char *s
)
951 while (s
[0] && s
[1]) {
959 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
960 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
962 wxFont
*fontToUse
= (wxFont
*)theFont
;
964 fontToUse
= (wxFont
*) & m_windowFont
;
966 if (!fontToUse
->Ok())
969 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
971 int direction
, ascent
, descent2
;
975 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
978 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
979 &ascent
, &descent2
, &overall
);
981 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
982 &ascent
, &descent2
, &overall
);
984 *x
= (overall
.width
);
985 *y
= (ascent
+ descent2
);
989 *externalLeading
= 0;
992 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
994 Display
*display
= XtDisplay((Widget
) GetMainWidget());
995 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
997 XExposeEvent dummyEvent
;
999 GetSize(&width
, &height
);
1001 dummyEvent
.type
= Expose
;
1002 dummyEvent
.display
= display
;
1003 dummyEvent
.send_event
= True
;
1004 dummyEvent
.window
= thisWindow
;
1007 dummyEvent
.x
= rect
->x
;
1008 dummyEvent
.y
= rect
->y
;
1009 dummyEvent
.width
= rect
->width
;
1010 dummyEvent
.height
= rect
->height
;
1016 dummyEvent
.width
= width
;
1017 dummyEvent
.height
= height
;
1019 dummyEvent
.count
= 0;
1023 wxClientDC
dc(this);
1024 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1025 dc
.SetBackground(backgroundBrush
);
1032 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1035 // Responds to colour changes: passes event on to children.
1036 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1038 wxNode
*node
= GetChildren().First();
1041 // Only propagate to non-top-level windows
1042 wxWindow
*win
= (wxWindow
*)node
->Data();
1043 if ( win
->GetParent() )
1045 wxSysColourChangedEvent event2
;
1046 event
.m_eventObject
= win
;
1047 win
->GetEventHandler()->ProcessEvent(event2
);
1050 node
= node
->Next();
1054 // This can be called by the app (or wxWindows) to do default processing for the current
1055 // event. Save message/event info in wxWindow so they can be used in this function.
1056 long wxWindow::Default()
1062 void wxWindow::InitDialog()
1064 wxInitDialogEvent
event(GetId());
1065 event
.SetEventObject( this );
1066 GetEventHandler()->ProcessEvent(event
);
1069 // Default init dialog behaviour is to transfer data to window
1070 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
1072 TransferDataToWindow();
1075 // Caret manipulation
1076 void wxWindow::CreateCaret(int w
, int h
)
1080 m_caretEnabled
= TRUE
;
1083 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1088 void wxWindow::ShowCaret(bool show
)
1093 void wxWindow::DestroyCaret()
1096 m_caretEnabled
= FALSE
;
1099 void wxWindow::SetCaretPos(int x
, int y
)
1104 void wxWindow::GetCaretPos(int *x
, int *y
) const
1109 wxWindow
*wxGetActiveWindow()
1115 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1122 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1125 wxFrame
*frame
= (wxFrame
*)this;
1126 Widget widget
= (Widget
) frame
->GetShellWidget();
1129 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1131 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1133 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1135 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1137 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1139 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1142 void wxWindow::Centre(int direction
)
1144 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1146 wxWindow
*father
= (wxWindow
*)GetParent();
1150 father
->GetClientSize(&panel_width
, &panel_height
);
1151 GetSize(&width
, &height
);
1152 GetPosition(&x
, &y
);
1157 if (direction
& wxHORIZONTAL
)
1158 new_x
= (int)((panel_width
- width
)/2);
1160 if (direction
& wxVERTICAL
)
1161 new_y
= (int)((panel_height
- height
)/2);
1163 SetSize(new_x
, new_y
, -1, -1);
1167 // Coordinates relative to the window
1168 void wxWindow::WarpPointer (int x
, int y
)
1170 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1173 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1179 int wxWindow::GetScrollPos(int orient
) const
1181 if (orient
== wxHORIZONTAL
)
1182 return m_scrollPosX
;
1184 return m_scrollPosY
;
1186 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1190 XtVaGetValues(scrollBar,
1191 XmNvalue, &pos, NULL);
1199 // This now returns the whole range, not just the number
1200 // of positions that we can scroll.
1201 int wxWindow::GetScrollRange(int orient
) const
1203 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1207 XtVaGetValues(scrollBar
,
1208 XmNmaximum
, &range
, NULL
);
1215 int wxWindow::GetScrollThumb(int orient
) const
1217 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1221 XtVaGetValues(scrollBar
,
1222 XmNsliderSize
, &thumb
, NULL
);
1229 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1231 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1234 XtVaSetValues (scrollBar
,
1238 if (orient
== wxHORIZONTAL
)
1245 // New function that will replace some of the above.
1246 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1247 int range
, bool WXUNUSED(refresh
))
1250 GetSize(& oldW
, & oldH
);
1254 if (thumbVisible
== 0)
1257 if (thumbVisible
> range
)
1258 thumbVisible
= range
;
1260 // Save the old state to see if it changed
1261 WXWidget oldScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1263 if (orient
== wxHORIZONTAL
)
1265 if (thumbVisible
== range
)
1268 DestroyScrollbar(wxHORIZONTAL
);
1273 CreateScrollbar(wxHORIZONTAL
);
1276 if (orient
== wxVERTICAL
)
1278 if (thumbVisible
== range
)
1281 DestroyScrollbar(wxVERTICAL
);
1286 CreateScrollbar(wxVERTICAL
);
1289 WXWidget newScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1291 if (oldScrollBar
!= newScrollBar
)
1293 // This is important! Without it, scrollbars misbehave
1295 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
1296 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
1297 XtRealizeWidget((Widget
) m_scrolledWindow
);
1298 XtManageChild((Widget
) m_scrolledWindow
);
1302 XtVaSetValues((Widget
) newScrollBar
,
1306 XmNsliderSize
, thumbVisible
,
1309 if (orient
== wxHORIZONTAL
)
1315 GetSize(& newW
, & newH
);
1317 // Adjusting scrollbars can resize the canvas accidentally
1318 if (newW
!= oldW
|| newH
!= oldH
)
1319 SetSize(-1, -1, oldW
, oldH
);
1322 // Does a physical scroll
1323 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1325 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1329 // Use specified rectangle
1330 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1334 // Use whole client area
1336 GetClientSize(& w
, & h
);
1339 int x1
= (dx
>= 0) ? x
: x
- dx
;
1340 int y1
= (dy
>= 0) ? y
: y
- dy
;
1341 int w1
= w
- abs(dx
);
1342 int h1
= h
- abs(dy
);
1343 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1344 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1346 wxClientDC
dc(this);
1348 dc
.SetLogicalFunction (wxCOPY
);
1350 Widget widget
= (Widget
) GetMainWidget();
1351 Window window
= XtWindow(widget
);
1352 Display
* display
= XtDisplay(widget
);
1354 XCopyArea(display
, window
,
1355 window
, (GC
) dc
.GetGC(),
1360 dc
.SetAutoSetting(TRUE
);
1361 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1362 dc
.SetBrush(brush
); // ??
1364 // We'll add rectangles to the list of update rectangles
1365 // according to which bits we've exposed.
1370 wxRect
*rect
= new wxRect
;
1376 XFillRectangle(display
, window
,
1377 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1381 rect
->width
= rect
->width
;
1382 rect
->height
= rect
->height
;
1384 updateRects
.Append((wxObject
*) rect
);
1388 wxRect
*rect
= new wxRect
;
1390 rect
->x
= x
+ w
+ dx
;
1395 XFillRectangle(display
, window
,
1396 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1401 rect
->width
= rect
->width
;
1402 rect
->height
= rect
->height
;
1404 updateRects
.Append((wxObject
*) rect
);
1408 wxRect
*rect
= new wxRect
;
1415 XFillRectangle(display
, window
,
1416 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1420 rect
->width
= rect
->width
;
1421 rect
->height
= rect
->height
;
1423 updateRects
.Append((wxObject
*) rect
);
1427 wxRect
*rect
= new wxRect
;
1430 rect
->y
= y
+ h
+ dy
;
1434 XFillRectangle(display
, window
,
1435 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1439 rect
->width
= rect
->width
;
1440 rect
->height
= rect
->height
;
1442 updateRects
.Append((wxObject
*) rect
);
1444 dc
.SetBrush(wxNullBrush
);
1446 // Now send expose events
1448 wxNode
* node
= updateRects
.First();
1451 wxRect
* rect
= (wxRect
*) node
->Data();
1454 event
.type
= Expose
;
1455 event
.display
= display
;
1456 event
.send_event
= True
;
1457 event
.window
= window
;
1461 event
.width
= rect
->width
;
1462 event
.height
= rect
->height
;
1466 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1468 node
= node
->Next();
1472 // Delete the update rects
1473 node
= updateRects
.First();
1476 wxRect
* rect
= (wxRect
*) node
->Data();
1478 node
= node
->Next();
1483 void wxWindow::OnChar(wxKeyEvent
& event
)
1486 if ( event.KeyCode() == WXK_TAB ) {
1487 // propagate the TABs to the parent - it's up to it to decide what
1489 if ( GetParent() ) {
1490 if ( GetParent()->ProcessEvent(event) )
1497 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1502 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1507 void wxWindow::OnPaint(wxPaintEvent
& event
)
1512 bool wxWindow::IsEnabled() const
1514 // TODO. Is this right?
1515 // return XtGetSensitive((Widget) GetMainWidget());
1519 // Dialog support: override these and call
1520 // base class members to add functionality
1521 // that can't be done using validators.
1522 // NOTE: these functions assume that controls
1523 // are direct children of this window, not grandchildren
1524 // or other levels of descendant.
1526 // Transfer values to controls. If returns FALSE,
1527 // it's an application error (pops up a dialog)
1528 bool wxWindow::TransferDataToWindow()
1530 wxNode
*node
= GetChildren().First();
1533 wxWindow
*child
= (wxWindow
*)node
->Data();
1534 if ( child
->GetValidator() &&
1535 !child
->GetValidator()->TransferToWindow() )
1537 wxLogError("Could not transfer data to window.");
1541 node
= node
->Next();
1546 // Transfer values from controls. If returns FALSE,
1547 // validation failed: don't quit
1548 bool wxWindow::TransferDataFromWindow()
1550 wxNode
*node
= GetChildren().First();
1553 wxWindow
*child
= (wxWindow
*)node
->Data();
1554 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1559 node
= node
->Next();
1564 bool wxWindow::Validate()
1566 wxNode
*node
= GetChildren().First();
1569 wxWindow
*child
= (wxWindow
*)node
->Data();
1570 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1575 node
= node
->Next();
1580 // Get the window with the focus
1581 wxWindow
*wxWindow::FindFocus()
1587 void wxWindow::AddChild(wxWindow
*child
)
1589 GetChildren().Append(child
);
1590 child
->m_windowParent
= this;
1593 void wxWindow::RemoveChild(wxWindow
*child
)
1595 GetChildren().DeleteObject(child
);
1596 child
->m_windowParent
= NULL
;
1599 // Reparents this window to have the new parent.
1600 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1602 // For now, we indicate that this isn't implemented.
1606 void wxWindow::DestroyChildren()
1608 wxNode
*node
= GetChildren().First();
1611 wxNode
* next
= node
->Next();
1612 wxWindow
* child
= (wxWindow
*) node
->Data();
1616 GetChildren().Clear();
1619 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1621 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1623 if ( GetChildren().Member(child
) )
1630 void wxWindow::MakeModal(bool modal
)
1632 // Disable all other windows
1633 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1635 wxNode
*node
= wxTopLevelWindows
.First();
1638 wxWindow
*win
= (wxWindow
*)node
->Data();
1640 win
->Enable(!modal
);
1642 node
= node
->Next();
1647 // If nothing defined for this, try the parent.
1648 // E.g. we may be a button loaded from a resource, with no callback function
1650 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1652 if (GetEventHandler()->ProcessEvent(event
) )
1655 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1658 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1662 UnsetConstraints(m_constraints
);
1663 delete m_constraints
;
1668 // Make sure other windows know they're part of a 'meaningful relationship'
1669 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1670 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1671 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1672 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1673 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1674 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1675 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1676 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1677 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1678 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1679 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1680 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1681 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1682 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1683 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1684 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1688 // This removes any dangling pointers to this window
1689 // in other windows' constraintsInvolvedIn lists.
1690 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1694 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1695 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1696 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1697 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1698 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1699 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1700 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1701 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1702 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1703 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1704 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1705 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1706 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1707 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1708 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1709 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1713 // Back-pointer to other windows we're involved with, so if we delete
1714 // this window, we must delete any constraints we're involved with.
1715 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1717 if (!m_constraintsInvolvedIn
)
1718 m_constraintsInvolvedIn
= new wxList
;
1719 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1720 m_constraintsInvolvedIn
->Append(otherWin
);
1723 // REMOVE back-pointer to other windows we're involved with.
1724 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1726 if (m_constraintsInvolvedIn
)
1727 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1730 // Reset any constraints that mention this window
1731 void wxWindow::DeleteRelatedConstraints()
1733 if (m_constraintsInvolvedIn
)
1735 wxNode
*node
= m_constraintsInvolvedIn
->First();
1738 wxWindow
*win
= (wxWindow
*)node
->Data();
1739 wxNode
*next
= node
->Next();
1740 wxLayoutConstraints
*constr
= win
->GetConstraints();
1742 // Reset any constraints involving this window
1745 constr
->left
.ResetIfWin((wxWindow
*)this);
1746 constr
->top
.ResetIfWin((wxWindow
*)this);
1747 constr
->right
.ResetIfWin((wxWindow
*)this);
1748 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1749 constr
->width
.ResetIfWin((wxWindow
*)this);
1750 constr
->height
.ResetIfWin((wxWindow
*)this);
1751 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1752 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1757 delete m_constraintsInvolvedIn
;
1758 m_constraintsInvolvedIn
= NULL
;
1762 void wxWindow::SetSizer(wxSizer
*sizer
)
1764 m_windowSizer
= sizer
;
1766 sizer
->SetSizerParent((wxWindow
*)this);
1773 bool wxWindow::Layout()
1775 if (GetConstraints())
1778 GetClientSize(&w
, &h
);
1779 GetConstraints()->width
.SetValue(w
);
1780 GetConstraints()->height
.SetValue(h
);
1783 // If top level (one sizer), evaluate the sizer's constraints.
1787 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1788 GetSizer()->LayoutPhase1(&noChanges
);
1789 GetSizer()->LayoutPhase2(&noChanges
);
1790 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1795 // Otherwise, evaluate child constraints
1796 ResetConstraints(); // Mark all constraints as unevaluated
1797 DoPhase(1); // Just one phase need if no sizers involved
1799 SetConstraintSizes(); // Recursively set the real window sizes
1805 // Do a phase of evaluating constraints:
1806 // the default behaviour. wxSizers may do a similar
1807 // thing, but also impose their own 'constraints'
1808 // and order the evaluation differently.
1809 bool wxWindow::LayoutPhase1(int *noChanges
)
1811 wxLayoutConstraints
*constr
= GetConstraints();
1814 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1820 bool wxWindow::LayoutPhase2(int *noChanges
)
1830 // Do a phase of evaluating child constraints
1831 bool wxWindow::DoPhase(int phase
)
1833 int noIterations
= 0;
1834 int maxIterations
= 500;
1838 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1842 wxNode
*node
= GetChildren().First();
1845 wxWindow
*child
= (wxWindow
*)node
->Data();
1846 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1848 wxLayoutConstraints
*constr
= child
->GetConstraints();
1851 if (succeeded
.Member(child
))
1856 int tempNoChanges
= 0;
1857 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1858 noChanges
+= tempNoChanges
;
1861 succeeded
.Append(child
);
1866 node
= node
->Next();
1873 void wxWindow::ResetConstraints()
1875 wxLayoutConstraints
*constr
= GetConstraints();
1878 constr
->left
.SetDone(FALSE
);
1879 constr
->top
.SetDone(FALSE
);
1880 constr
->right
.SetDone(FALSE
);
1881 constr
->bottom
.SetDone(FALSE
);
1882 constr
->width
.SetDone(FALSE
);
1883 constr
->height
.SetDone(FALSE
);
1884 constr
->centreX
.SetDone(FALSE
);
1885 constr
->centreY
.SetDone(FALSE
);
1887 wxNode
*node
= GetChildren().First();
1890 wxWindow
*win
= (wxWindow
*)node
->Data();
1891 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1892 win
->ResetConstraints();
1893 node
= node
->Next();
1897 // Need to distinguish between setting the 'fake' size for
1898 // windows and sizers, and setting the real values.
1899 void wxWindow::SetConstraintSizes(bool recurse
)
1901 wxLayoutConstraints
*constr
= GetConstraints();
1902 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1903 constr
->width
.GetDone() && constr
->height
.GetDone())
1905 int x
= constr
->left
.GetValue();
1906 int y
= constr
->top
.GetValue();
1907 int w
= constr
->width
.GetValue();
1908 int h
= constr
->height
.GetValue();
1910 // If we don't want to resize this window, just move it...
1911 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1912 (constr
->height
.GetRelationship() != wxAsIs
))
1914 // Calls Layout() recursively. AAAGH. How can we stop that.
1915 // Simply take Layout() out of non-top level OnSizes.
1916 SizerSetSize(x
, y
, w
, h
);
1925 char *windowClass
= this->GetClassInfo()->GetClassName();
1928 if (GetName() == "")
1929 winName
= "unnamed";
1931 winName
= GetName();
1932 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1933 if (!constr
->left
.GetDone())
1934 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1935 if (!constr
->right
.GetDone())
1936 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1937 if (!constr
->width
.GetDone())
1938 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1939 if (!constr
->height
.GetDone())
1940 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1941 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1946 wxNode
*node
= GetChildren().First();
1949 wxWindow
*win
= (wxWindow
*)node
->Data();
1950 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1951 win
->SetConstraintSizes();
1952 node
= node
->Next();
1957 // This assumes that all sizers are 'on' the same
1958 // window, i.e. the parent of this window.
1959 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1961 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1962 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1966 m_sizerParent
->GetPosition(&xp
, &yp
);
1967 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1972 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1976 TransformSizerToActual(&xx
, &yy
);
1977 SetSize(xx
, yy
, w
, h
);
1980 void wxWindow::SizerMove(int x
, int y
)
1984 TransformSizerToActual(&xx
, &yy
);
1988 // Only set the size/position of the constraint (if any)
1989 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1991 wxLayoutConstraints
*constr
= GetConstraints();
1996 constr
->left
.SetValue(x
);
1997 constr
->left
.SetDone(TRUE
);
2001 constr
->top
.SetValue(y
);
2002 constr
->top
.SetDone(TRUE
);
2006 constr
->width
.SetValue(w
);
2007 constr
->width
.SetDone(TRUE
);
2011 constr
->height
.SetValue(h
);
2012 constr
->height
.SetDone(TRUE
);
2017 void wxWindow::MoveConstraint(int x
, int y
)
2019 wxLayoutConstraints
*constr
= GetConstraints();
2024 constr
->left
.SetValue(x
);
2025 constr
->left
.SetDone(TRUE
);
2029 constr
->top
.SetValue(y
);
2030 constr
->top
.SetDone(TRUE
);
2035 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2037 wxLayoutConstraints
*constr
= GetConstraints();
2040 *w
= constr
->width
.GetValue();
2041 *h
= constr
->height
.GetValue();
2047 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2049 wxLayoutConstraints
*constr
= GetConstraints();
2052 *w
= constr
->width
.GetValue();
2053 *h
= constr
->height
.GetValue();
2056 GetClientSize(w
, h
);
2059 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2061 wxLayoutConstraints
*constr
= GetConstraints();
2064 *x
= constr
->left
.GetValue();
2065 *y
= constr
->top
.GetValue();
2071 bool wxWindow::Close(bool force
)
2073 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2074 event
.SetEventObject(this);
2075 #if WXWIN_COMPATIBILITY
2076 event
.SetForce(force
);
2078 event
.SetCanVeto(!force
);
2080 return GetEventHandler()->ProcessEvent(event
);
2083 wxObject
* wxWindow::GetChild(int number
) const
2085 // Return a pointer to the Nth object in the window
2086 wxNode
*node
= GetChildren().First();
2089 node
= node
->Next() ;
2092 wxObject
*obj
= (wxObject
*)node
->Data();
2099 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2101 // Obsolete function
2104 void wxWindow::Clear()
2106 wxClientDC
dc(this);
2107 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2108 dc
.SetBackground(brush
);
2112 // Fits the panel around the items
2113 void wxWindow::Fit()
2117 wxNode
*node
= GetChildren().First();
2120 wxWindow
*win
= (wxWindow
*)node
->Data();
2122 win
->GetPosition(&wx
, &wy
);
2123 win
->GetSize(&ww
, &wh
);
2124 if ( wx
+ ww
> maxX
)
2126 if ( wy
+ wh
> maxY
)
2129 node
= node
->Next();
2131 SetClientSize(maxX
+ 5, maxY
+ 5);
2134 void wxWindow::SetValidator(const wxValidator
& validator
)
2136 if ( m_windowValidator
)
2137 delete m_windowValidator
;
2138 m_windowValidator
= validator
.Clone();
2140 if ( m_windowValidator
)
2141 m_windowValidator
->SetWindow(this) ;
2144 void wxWindow::SetClientObject( wxClientData
*data
)
2146 if (m_clientObject
) delete m_clientObject
;
2147 m_clientObject
= data
;
2150 wxClientData
*wxWindow::GetClientObject()
2152 return m_clientObject
;
2155 void wxWindow::SetClientData( void *data
)
2157 m_clientData
= data
;
2160 void *wxWindow::GetClientData()
2162 return m_clientData
;
2165 // Find a window by id or name
2166 wxWindow
*wxWindow::FindWindow(long id
)
2171 wxNode
*node
= GetChildren().First();
2174 wxWindow
*child
= (wxWindow
*)node
->Data();
2175 wxWindow
*found
= child
->FindWindow(id
);
2178 node
= node
->Next();
2183 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2185 if ( GetName() == name
)
2188 wxNode
*node
= GetChildren().First();
2191 wxWindow
*child
= (wxWindow
*)node
->Data();
2192 wxWindow
*found
= child
->FindWindow(name
);
2195 node
= node
->Next();
2200 void wxWindow::OnIdle(wxIdleEvent
& event
)
2202 // This calls the UI-update mechanism (querying windows for
2203 // menu/toolbar/control state information)
2207 // Raise the window to the top of the Z order
2208 void wxWindow::Raise()
2210 Window window
= XtWindow((Widget
) GetTopWidget());
2211 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2214 // Lower the window to the bottom of the Z order
2215 void wxWindow::Lower()
2217 Window window
= XtWindow((Widget
) GetTopWidget());
2218 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2221 bool wxWindow::AcceptsFocus() const
2223 return IsShown() && IsEnabled();
2226 // Update region access
2227 wxRegion
& wxWindow::GetUpdateRegion() const
2229 return (wxRegion
&) m_updateRegion
;
2232 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2234 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2237 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2239 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2242 bool wxWindow::IsExposed(const wxRect
& rect
) const
2244 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2248 * Allocates control IDs
2251 int wxWindow::NewControlId()
2253 static int s_controlId
= 0;
2258 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2260 m_acceleratorTable
= accel
;
2263 // All widgets should have this as their resize proc.
2264 // OnSize sent to wxWindow via client data.
2265 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2267 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2271 if (win
->PreResize())
2274 win
->GetSize(&width
, &height
);
2275 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2276 sizeEvent
.SetEventObject(win
);
2277 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2281 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2283 wxWindow
*oldItem
= NULL
;
2284 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2285 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2287 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2291 wxWidgetHashTable
->Put ((long) w
, win
);
2295 wxWindow
*wxGetWindowFromTable(Widget w
)
2297 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2300 void wxDeleteWindowFromTable(Widget w
)
2302 wxWidgetHashTable
->Delete((long)w
);
2305 // Get the underlying X window and display
2306 WXWindow
wxWindow::GetXWindow() const
2308 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2311 WXDisplay
*wxWindow::GetXDisplay() const
2313 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2316 WXWidget
wxWindow::GetMainWidget() const
2319 return m_drawingArea
;
2321 return m_mainWidget
;
2324 WXWidget
wxWindow::GetClientWidget() const
2326 if (m_drawingArea
!= (WXWidget
) 0)
2327 return m_drawingArea
;
2329 return GetMainWidget();
2332 WXWidget
wxWindow::GetTopWidget() const
2334 return GetMainWidget();
2337 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2338 XmDrawingAreaCallbackStruct
* cbs
)
2340 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2343 XEvent
* event
= cbs
->event
;
2344 wxWindow
* win
= (wxWindow
*) clientData
;
2345 Display
* display
= (Display
*) win
->GetXDisplay();
2347 switch (event
->type
)
2351 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2352 event
->xexpose
.width
, event
->xexpose
.height
);
2354 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2355 cout << rect->width << ", " << rect->height << "\n\n";
2358 win
->m_updateRects
.Append((wxObject
*) rect
);
2360 if (event
-> xexpose
.count
== 0)
2362 wxPaintEvent
event(win
->GetId());
2363 event
.SetEventObject(win
);
2364 win
->GetEventHandler()->ProcessEvent(event
);
2366 win
->ClearUpdateRects();
2372 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2378 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2380 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2382 XmDrawingAreaCallbackStruct cbs
;
2385 //if (event->mode!=NotifyNormal)
2388 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2389 ((XCrossingEvent
&) ev
) = *event
;
2391 cbs
.reason
= XmCR_INPUT
;
2394 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2397 // Fix to make it work under Motif 1.0 (!)
2398 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2402 XmDrawingAreaCallbackStruct cbs
;
2405 //ev.xbutton = *event;
2406 ev
= *((XEvent
*) event
);
2407 cbs
.reason
= XmCR_INPUT
;
2410 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2414 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2416 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2422 if (cbs
->reason
!= XmCR_INPUT
)
2425 local_event
= *(cbs
->event
); // We must keep a copy!
2428 switch (local_event.xany.type)
2431 cout << "EnterNotify\n";
2434 cout << "LeaveNotify\n";
2437 cout << "ButtonPress\n";
2440 cout << "ButtonRelease\n";
2443 cout << "MotionNotify\n";
2446 cout << "Something else\n";
2451 switch (local_event
.xany
.type
)
2459 wxEventType eventType
= wxEVT_NULL
;
2461 if (local_event
.xany
.type
== EnterNotify
)
2463 //if (local_event.xcrossing.mode!=NotifyNormal)
2464 // return ; // Ignore grab events
2465 eventType
= wxEVT_ENTER_WINDOW
;
2466 // canvas->GetEventHandler()->OnSetFocus();
2468 else if (local_event
.xany
.type
== LeaveNotify
)
2470 //if (local_event.xcrossing.mode!=NotifyNormal)
2471 // return ; // Ignore grab events
2472 eventType
= wxEVT_LEAVE_WINDOW
;
2473 // canvas->GetEventHandler()->OnKillFocus();
2475 else if (local_event
.xany
.type
== MotionNotify
)
2477 eventType
= wxEVT_MOTION
;
2478 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2481 Display
*dpy
= XtDisplay (drawingArea
);
2483 XQueryPointer (dpy
, XtWindow (drawingArea
),
2485 &local_event
.xmotion
.x_root
,
2486 &local_event
.xmotion
.y_root
,
2487 &local_event
.xmotion
.x
,
2488 &local_event
.xmotion
.y
,
2489 &local_event
.xmotion
.state
);
2496 else if (local_event
.xany
.type
== ButtonPress
)
2498 if (local_event
.xbutton
.button
== Button1
)
2500 eventType
= wxEVT_LEFT_DOWN
;
2501 canvas
->m_button1Pressed
= TRUE
;
2503 else if (local_event
.xbutton
.button
== Button2
)
2505 eventType
= wxEVT_MIDDLE_DOWN
;
2506 canvas
->m_button2Pressed
= TRUE
;
2508 else if (local_event
.xbutton
.button
== Button3
)
2510 eventType
= wxEVT_RIGHT_DOWN
;
2511 canvas
->m_button3Pressed
= TRUE
;
2514 else if (local_event
.xany
.type
== ButtonRelease
)
2516 if (local_event
.xbutton
.button
== Button1
)
2518 eventType
= wxEVT_LEFT_UP
;
2519 canvas
->m_button1Pressed
= FALSE
;
2521 else if (local_event
.xbutton
.button
== Button2
)
2523 eventType
= wxEVT_MIDDLE_UP
;
2524 canvas
->m_button2Pressed
= FALSE
;
2526 else if (local_event
.xbutton
.button
== Button3
)
2528 eventType
= wxEVT_RIGHT_UP
;
2529 canvas
->m_button3Pressed
= FALSE
;
2533 wxMouseEvent
wxevent (eventType
);
2534 wxevent
.m_eventHandle
= (char *) &local_event
;
2536 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2537 || (event_left_is_down (&local_event
)
2538 && (eventType
!= wxEVT_LEFT_UP
)));
2539 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2540 || (event_middle_is_down (&local_event
)
2541 && (eventType
!= wxEVT_MIDDLE_UP
)));
2542 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2543 || (event_right_is_down (&local_event
)
2544 && (eventType
!= wxEVT_RIGHT_UP
)));
2546 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2547 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2548 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2549 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2550 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2552 // Now check if we need to translate this event into a double click
2553 if (TRUE
) // canvas->doubleClickAllowed)
2555 if (wxevent
.ButtonDown())
2557 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2559 // get button and time-stamp
2561 if (wxevent
.LeftDown()) button
= 1;
2562 else if (wxevent
.MiddleDown()) button
= 2;
2563 else if (wxevent
.RightDown()) button
= 3;
2564 long ts
= wxevent
.GetTimestamp();
2565 // check, if single or double click
2566 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2569 canvas
->m_lastButton
= 0;
2570 switch ( eventType
)
2572 case wxEVT_LEFT_DOWN
:
2573 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2575 case wxEVT_MIDDLE_DOWN
:
2576 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2578 case wxEVT_RIGHT_DOWN
:
2579 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2589 // not fast enough or different button
2590 canvas
->m_lastTS
= ts
;
2591 canvas
->m_lastButton
= button
;
2596 wxevent
.SetId(canvas
->GetId());
2597 wxevent
.SetEventObject(canvas
);
2598 wxevent
.m_x
= local_event
.xbutton
.x
;
2599 wxevent
.m_y
= local_event
.xbutton
.y
;
2600 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2602 if (eventType == wxEVT_ENTER_WINDOW ||
2603 eventType == wxEVT_LEAVE_WINDOW ||
2604 eventType == wxEVT_MOTION
2613 // XComposeStatus compose;
2614 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2615 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2616 int id
= wxCharCodeXToWX (keySym
);
2618 wxEventType eventType
= wxEVT_CHAR
;
2620 // TODO: Is this the correct criterion for wxEVT_KEY_DOWN down versus wxEVT_CHAR?
2621 if (id
> WXK_START
) // Non-ASCII values
2622 eventType
= wxEVT_KEY_DOWN
;
2624 wxKeyEvent
event (eventType
);
2626 if (local_event
.xkey
.state
& ShiftMask
)
2627 event
.m_shiftDown
= TRUE
;
2628 if (local_event
.xkey
.state
& ControlMask
)
2629 event
.m_controlDown
= TRUE
;
2630 if (local_event
.xkey
.state
& Mod3Mask
)
2631 event
.m_altDown
= TRUE
;
2632 if (local_event
.xkey
.state
& Mod1Mask
)
2633 event
.m_metaDown
= TRUE
;
2634 event
.SetEventObject(canvas
);
2635 event
.m_keyCode
= id
;
2636 event
.SetTimestamp(local_event
.xkey
.time
);
2640 // Implement wxFrame::OnCharHook by checking ancestor.
2641 wxWindow
*parent
= canvas
->GetParent();
2642 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2643 parent
= parent
->GetParent();
2647 event
.SetEventType(wxEVT_CHAR_HOOK
);
2648 if (parent
->GetEventHandler()->ProcessEvent(event
))
2650 event
.SetEventType(wxEVT_CHAR
);
2653 canvas
->GetEventHandler()->ProcessEvent (event
);
2660 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2661 int id
= wxCharCodeXToWX (keySym
);
2663 wxKeyEvent
event (wxEVT_KEY_UP
);
2665 if (local_event
.xkey
.state
& ShiftMask
)
2666 event
.m_shiftDown
= TRUE
;
2667 if (local_event
.xkey
.state
& ControlMask
)
2668 event
.m_controlDown
= TRUE
;
2669 if (local_event
.xkey
.state
& Mod3Mask
)
2670 event
.m_altDown
= TRUE
;
2671 if (local_event
.xkey
.state
& Mod1Mask
)
2672 event
.m_metaDown
= TRUE
;
2673 event
.SetEventObject(canvas
);
2674 event
.m_keyCode
= id
;
2675 event
.SetTimestamp(local_event
.xkey
.time
);
2679 canvas
->GetEventHandler()->ProcessEvent (event
);
2685 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2687 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2688 event
.SetEventObject(canvas
);
2689 canvas
->GetEventHandler()->ProcessEvent(event
);
2695 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2697 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2698 event
.SetEventObject(canvas
);
2699 canvas
->GetEventHandler()->ProcessEvent(event
);
2708 void wxWindow::DoPaint()
2710 //TODO : make a temporary gc so we can do the XCopyArea below
2711 if (0) // m_backingPixmap)
2714 Widget drawingArea = (Widget) m_drawingArea;
2715 // int orig = GetDC()->GetLogicalFunction();
2716 // GetDC()->SetLogicalFunction (wxCOPY);
2718 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2719 // should be able to calculate them.
2720 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2721 m_pixmapOffsetX, m_pixmapOffsetY,
2722 m_pixmapWidth, m_pixmapHeight,
2725 // GetDC()->SetLogicalFunction (orig);
2730 wxPaintEvent
event(GetId());
2731 event
.SetEventObject(this);
2732 GetEventHandler()->ProcessEvent(event
);
2736 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2737 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2739 // A bit of optimization to help sort out the flickers.
2740 int oldX
, oldY
, oldW
, oldH
;
2741 GetSize(& oldW
, & oldH
);
2742 GetPosition(& oldX
, & oldY
);
2744 bool useOldPos
= FALSE
;
2745 bool useOldSize
= FALSE
;
2747 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2749 else if (x
== oldX
&& y
== oldY
)
2752 if ((w
== -1) && (h
== -1))
2754 else if (w
== oldW
&& h
== oldH
)
2757 if (!wxNoOptimize::CanOptimize())
2759 useOldSize
= FALSE
; useOldPos
= FALSE
;
2762 if (useOldPos
&& useOldSize
)
2765 Widget drawingArea
= (Widget
) m_drawingArea
;
2766 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2769 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2770 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2772 int xx
= x
; int yy
= y
;
2773 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2777 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2779 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2783 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2785 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2797 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2798 short thick
, margin
;
2799 XtVaGetValues ((Widget
) m_borderWidget
,
2800 XmNshadowThickness
, &thick
,
2801 XmNmarginWidth
, &margin
,
2803 w
-= 2 * (thick
+ margin
);
2806 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2810 XtVaGetValues ((Widget
) m_scrolledWindow
,
2811 XmNspacing
, &spacing
,
2812 XmNverticalScrollBar
, &sbar
,
2816 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2820 w
-= (spacing
+ wsbar
);
2822 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2828 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2829 short thick
, margin
;
2830 XtVaGetValues ((Widget
) m_borderWidget
,
2831 XmNshadowThickness
, &thick
,
2832 XmNmarginHeight
, &margin
,
2834 h
-= 2 * (thick
+ margin
);
2837 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2841 XtVaGetValues ((Widget
) m_scrolledWindow
,
2842 XmNspacing
, &spacing
,
2843 XmNhorizontalScrollBar
, &sbar
,
2847 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2851 h
-= (spacing
+ wsbar
);
2853 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2859 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2860 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2864 GetClientSize (&ww, &hh);
2865 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2866 sizeEvent.SetEventObject(this);
2868 GetEventHandler()->ProcessEvent(sizeEvent);
2873 void wxWindow::CanvasSetClientSize (int w
, int h
)
2875 Widget drawingArea
= (Widget
) m_drawingArea
;
2877 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2880 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2882 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2883 /* TODO: is this necessary?
2884 allowRepainting = FALSE;
2886 XSync (XtDisplay (drawingArea), FALSE);
2888 while (XtAppPending (wxTheApp->appContext))
2890 XFlush (XtDisplay (drawingArea));
2891 XtAppNextEvent (wxTheApp->appContext, &event);
2892 XtDispatchEvent (&event);
2896 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2899 allowRepainting = TRUE;
2904 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2905 sizeEvent.SetEventObject(this);
2907 GetEventHandler()->ProcessEvent(sizeEvent);
2911 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2913 // Must return the same thing that was set via SetClientSize
2915 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2920 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2923 if ((Widget
) m_borderWidget
)
2924 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2925 else if ((Widget
) m_scrolledWindow
)
2926 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2928 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2934 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2937 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2939 // We may be faking the client origin.
2940 // So a window that's really at (0, 30) may appear
2941 // (to wxWin apps) to be at (0, 0).
2944 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2953 // Add to hash table, add event handler
2954 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2955 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2957 wxAddWindowToTable((Widget
) mainWidget
, this);
2958 if (CanAddEventHandler())
2960 XtAddEventHandler((Widget
) mainWidget
,
2961 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2963 wxPanelItemEventHandler
,
2970 XtOverrideTranslations ((Widget
) mainWidget
,
2971 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2972 XtFree ((char *) ptr
);
2975 // Some widgets have a parent form widget, e.g. wxRadioBox
2978 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2982 XtOverrideTranslations ((Widget
) formWidget
,
2983 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2984 XtFree ((char *) ptr
);
2991 SetSize (x
, y
, width
, height
);
2996 // Remove event handler, remove from hash table
2997 bool wxWindow::DetachWidget(WXWidget widget
)
2999 if (CanAddEventHandler())
3001 XtRemoveEventHandler((Widget
) widget
,
3002 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3004 wxPanelItemEventHandler
,
3008 wxDeleteWindowFromTable((Widget
) widget
);
3012 void wxPanelItemEventHandler (Widget wid
,
3013 XtPointer client_data
,
3015 Boolean
*continueToDispatch
)
3017 // Widget can be a label or the actual widget.
3019 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3022 wxMouseEvent
wxevent(0);
3023 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3025 window
->GetEventHandler()->ProcessEvent(wxevent
);
3028 // TODO: probably the key to allowing default behaviour
3030 // Say we set a m_doDefault flag to FALSE at the start of this
3031 // function. Then in e.g. wxWindow::OnMouseEvent we can
3032 // call Default() which sets this flag to TRUE, indicating
3033 // that default processing can happen. Thus, behaviour can appear
3034 // to be overridden just by adding an event handler and not calling
3035 // wxWindow::OnWhatever.
3036 // ALSO, maybe we can use this instead of the current way of handling
3037 // drawing area events, to simplify things.
3038 *continueToDispatch
= True
;
3041 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3042 XmScaleCallbackStruct
*cbs
)
3044 Widget scrolledWindow
= XtParent (scrollbar
);
3045 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3046 int orientation
= (int) clientData
;
3048 wxEventType eventType
= wxEVT_NULL
;
3049 switch (cbs
->reason
)
3051 case XmCR_INCREMENT
:
3053 eventType
= wxEVT_SCROLL_LINEDOWN
;
3056 case XmCR_DECREMENT
:
3058 eventType
= wxEVT_SCROLL_LINEUP
;
3063 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3066 case XmCR_VALUE_CHANGED
:
3068 // TODO: Should this be intercepted too, or will it cause
3069 // duplicate events?
3070 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3073 case XmCR_PAGE_INCREMENT
:
3075 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3078 case XmCR_PAGE_DECREMENT
:
3080 eventType
= wxEVT_SCROLL_PAGEUP
;
3085 eventType
= wxEVT_SCROLL_TOP
;
3088 case XmCR_TO_BOTTOM
:
3090 eventType
= wxEVT_SCROLL_BOTTOM
;
3095 // Should never get here
3096 wxFAIL_MSG("Unknown scroll event.");
3101 wxScrollEvent
event(eventType
, win
->GetId());
3102 event
.SetEventObject(win
);
3103 event
.SetPosition(cbs
->value
);
3104 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3106 win
->GetEventHandler()->ProcessEvent(event
);
3109 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3111 switch (xevent
->xany
.type
)
3119 wxEventType eventType
= wxEVT_NULL
;
3121 if (xevent
->xany
.type
== LeaveNotify
)
3123 win
->m_button1Pressed
= FALSE
;
3124 win
->m_button2Pressed
= FALSE
;
3125 win
->m_button3Pressed
= FALSE
;
3128 else if (xevent
->xany
.type
== MotionNotify
)
3130 eventType
= wxEVT_MOTION
;
3132 else if (xevent
->xany
.type
== ButtonPress
)
3134 if (xevent
->xbutton
.button
== Button1
)
3136 eventType
= wxEVT_LEFT_DOWN
;
3137 win
->m_button1Pressed
= TRUE
;
3139 else if (xevent
->xbutton
.button
== Button2
)
3141 eventType
= wxEVT_MIDDLE_DOWN
;
3142 win
->m_button2Pressed
= TRUE
;
3144 else if (xevent
->xbutton
.button
== Button3
)
3146 eventType
= wxEVT_RIGHT_DOWN
;
3147 win
->m_button3Pressed
= TRUE
;
3150 else if (xevent
->xany
.type
== ButtonRelease
)
3152 if (xevent
->xbutton
.button
== Button1
)
3154 eventType
= wxEVT_LEFT_UP
;
3155 win
->m_button1Pressed
= FALSE
;
3157 else if (xevent
->xbutton
.button
== Button2
)
3159 eventType
= wxEVT_MIDDLE_UP
;
3160 win
->m_button2Pressed
= FALSE
;
3162 else if (xevent
->xbutton
.button
== Button3
)
3164 eventType
= wxEVT_RIGHT_UP
;
3165 win
->m_button3Pressed
= FALSE
;
3171 wxevent
.m_eventHandle
= (char *)xevent
;
3172 wxevent
.SetEventType(eventType
);
3175 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3178 win
->GetPosition(&x2
, &y2
);
3180 // The button x/y must be translated to wxWindows
3181 // window space - the widget might be a label or button,
3185 if (widget
!= (Widget
)win
->GetMainWidget())
3191 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3192 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3194 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3195 || (event_left_is_down (xevent
)
3196 && (eventType
!= wxEVT_LEFT_UP
)));
3197 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3198 || (event_middle_is_down (xevent
)
3199 && (eventType
!= wxEVT_MIDDLE_UP
)));
3200 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3201 || (event_right_is_down (xevent
)
3202 && (eventType
!= wxEVT_RIGHT_UP
)));
3204 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3205 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3212 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3214 switch (xevent
->xany
.type
)
3221 // XComposeStatus compose;
3222 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3223 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3224 int id
= wxCharCodeXToWX (keySym
);
3226 if (xevent
->xkey
.state
& ShiftMask
)
3227 wxevent
.m_shiftDown
= TRUE
;
3228 if (xevent
->xkey
.state
& ControlMask
)
3229 wxevent
.m_controlDown
= TRUE
;
3230 if (xevent
->xkey
.state
& Mod3Mask
)
3231 wxevent
.m_altDown
= TRUE
;
3232 if (xevent
->xkey
.state
& Mod1Mask
)
3233 wxevent
.m_metaDown
= TRUE
;
3234 wxevent
.SetEventObject(win
);
3235 wxevent
.m_keyCode
= id
;
3236 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3238 wxevent
.m_x
= xevent
->xbutton
.x
;
3239 wxevent
.m_y
= xevent
->xbutton
.y
;
3253 #define YAllocColor XAllocColor
3254 XColor g_itemColors
[5];
3255 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3258 static XmColorProc colorProc
;
3260 result
= wxNO_COLORS
;
3264 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3265 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3266 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3267 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3268 if (colorProc
== (XmColorProc
) NULL
)
3270 // Get a ptr to the actual function
3271 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3272 // And set it back to motif.
3273 XmSetColorCalculation (colorProc
);
3275 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3276 &g_itemColors
[wxFORE_INDEX
],
3277 &g_itemColors
[wxSELE_INDEX
],
3278 &g_itemColors
[wxTOPS_INDEX
],
3279 &g_itemColors
[wxBOTS_INDEX
]);
3280 result
= wxBACK_COLORS
;
3284 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3285 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3286 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3287 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3288 if (result
== wxNO_COLORS
)
3289 result
= wxFORE_COLORS
;
3292 Display
*dpy
= display
;
3293 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3297 /* 5 Colours to allocate */
3298 for (int i
= 0; i
< 5; i
++)
3299 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3300 result
= wxNO_COLORS
;
3304 /* Only 1 colour to allocate */
3305 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3306 result
= wxNO_COLORS
;
3313 // Changes the foreground and background colours to be derived
3314 // from the current background colour.
3315 // To change the foreground colour, you must call SetForegroundColour
3317 void wxWindow::ChangeBackgroundColour()
3319 if (GetMainWidget())
3320 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3322 // This not necessary
3325 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3327 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3328 // Have to set the scrollbar colours back since
3329 // the scrolled window seemed to change them
3330 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3333 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3335 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3340 void wxWindow::ChangeForegroundColour()
3342 if (GetMainWidget())
3343 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3344 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3345 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3348 // Change a widget's foreground and background colours.
3350 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3352 // When should we specify the foreground, if it's calculated
3353 // by wxComputeColours?
3354 // Solution: say we start with the default (computed) foreground colour.
3355 // If we call SetForegroundColour explicitly for a control or window,
3356 // then the foreground is changed.
3357 // Therefore SetBackgroundColour computes the foreground colour, and
3358 // SetForegroundColour changes the foreground colour. The ordering is
3361 XtVaSetValues ((Widget
) widget
,
3362 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3366 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3368 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3371 XtVaSetValues ((Widget
) widget
,
3372 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3373 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3374 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3375 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3378 if (changeArmColour
)
3379 XtVaSetValues ((Widget
) widget
,
3380 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3384 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3386 m_backgroundColour
= col
;
3387 ChangeBackgroundColour();
3390 void wxWindow::SetForegroundColour(const wxColour
& col
)
3392 m_foregroundColour
= col
;
3393 ChangeForegroundColour();
3396 void wxWindow::ChangeFont(bool keepOriginalSize
)
3398 // Note that this causes the widget to be resized back
3399 // to its original size! We therefore have to set the size
3400 // back again. TODO: a better way in Motif?
3401 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3402 if (w
&& m_windowFont
.Ok())
3404 int width
, height
, width1
, height1
;
3405 GetSize(& width
, & height
);
3407 // lesstif 0.87 hangs here
3408 #ifndef LESSTIF_VERSION
3410 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3414 GetSize(& width1
, & height1
);
3415 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3417 SetSize(-1, -1, width
, height
);
3422 void wxWindow::SetFont(const wxFont
& font
)
3424 m_windowFont
= font
;
3428 void wxWindow::SetToolTip(const wxString
& tooltip
)
3433 void wxWindow::ClearUpdateRects()
3435 wxNode
* node
= m_updateRects
.First();
3438 wxRect
* rect
= (wxRect
*) node
->Data();
3440 node
= node
->Next();
3442 m_updateRects
.Clear();
3445 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3447 if (!m_acceleratorTable
.Ok())
3450 int count
= m_acceleratorTable
.GetCount();
3451 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3453 for (i
= 0; i
< count
; i
++)
3455 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3456 if (entry
->MatchesEvent(event
))
3458 // Bingo, we have a match. Now find a control
3459 // that matches the entry command id.
3461 // Need to go up to the top of the window hierarchy,
3462 // since it might be e.g. a menu item
3463 wxWindow
* parent
= this;
3464 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3465 parent
= parent
->GetParent();
3470 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3472 // Try for a menu command
3473 wxFrame
* frame
= (wxFrame
*) parent
;
3474 if (frame
->GetMenuBar())
3476 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3479 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3480 commandEvent
.SetEventObject(frame
);
3482 // If ProcessEvent returns TRUE (it was handled), then
3483 // the calling code will skip the event handling.
3484 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3489 // Find a child matching the command id
3490 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3496 // Now we process those kinds of windows that we can.
3497 // For now, only buttons.
3498 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3500 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3501 commandEvent
.SetEventObject(child
);
3502 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3509 // We didn't match the key event against an accelerator.
3514 * wxNoOptimize: switch off size optimization
3517 int wxNoOptimize::m_count
= 0;
3519 wxNoOptimize::wxNoOptimize()
3524 wxNoOptimize::~wxNoOptimize()
3529 bool wxNoOptimize::CanOptimize()
3531 return (m_count
== 0);