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_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
74 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
75 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
76 EVT_IDLE(wxWindow::OnIdle
)
88 m_windowParent
= NULL
;
89 m_windowEventHandler
= this;
91 m_windowCursor
= *wxSTANDARD_CURSOR
;
92 m_children
= new wxList
;
94 m_constraintsInvolvedIn
= NULL
;
98 m_windowValidator
= NULL
;
101 m_caretWidth
= 0; m_caretHeight
= 0;
102 m_caretEnabled
= FALSE
;
103 m_caretShown
= FALSE
;
104 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
105 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
106 m_foregroundColour
= *wxBLACK
;
108 #if wxUSE_DRAG_AND_DROP
109 m_pDropTarget
= NULL
;
111 m_clientObject
= (wxClientData
*) NULL
;
115 m_mainWidget
= (WXWidget
) 0;
116 m_button1Pressed
= FALSE
;
117 m_button2Pressed
= FALSE
;
118 m_button3Pressed
= FALSE
;
119 m_winCaptured
= FALSE
;
121 m_hScrollBar
= (WXWidget
) 0;
122 m_vScrollBar
= (WXWidget
) 0;
123 m_borderWidget
= (WXWidget
) 0;
124 m_scrolledWindow
= (WXWidget
) 0;
125 m_drawingArea
= (WXWidget
) 0;
128 m_backingPixmap
= (WXPixmap
) 0;
135 m_canAddEventHandler
= FALSE
;
141 wxWindow::~wxWindow()
146 DetachWidget(GetMainWidget()); // Removes event handlers
148 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
151 // Destroy children before destroying self
155 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
157 Widget w
= (Widget
) m_drawingArea
;
158 wxDeleteWindowFromTable(w
);
162 m_mainWidget
= (WXWidget
) 0;
164 // Only if we're _really_ a canvas (not a dialog box/panel)
165 if (m_scrolledWindow
)
167 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
172 XtUnmanageChild ((Widget
) m_hScrollBar
);
173 XtDestroyWidget ((Widget
) m_hScrollBar
);
177 XtUnmanageChild ((Widget
) m_vScrollBar
);
178 XtDestroyWidget ((Widget
) m_vScrollBar
);
180 if (m_scrolledWindow
)
182 XtUnmanageChild ((Widget
) m_scrolledWindow
);
183 XtDestroyWidget ((Widget
) m_scrolledWindow
);
188 XtDestroyWidget ((Widget
) m_borderWidget
);
189 m_borderWidget
= (WXWidget
) 0;
195 // Have to delete constraints/sizer FIRST otherwise
196 // sizers may try to look at deleted windows as they
197 // delete themselves.
198 #if wxUSE_CONSTRAINTS
199 DeleteRelatedConstraints();
202 // This removes any dangling pointers to this window
203 // in other windows' constraintsInvolvedIn lists.
204 UnsetConstraints(m_constraints
);
205 delete m_constraints
;
206 m_constraints
= NULL
;
210 delete m_windowSizer
;
211 m_windowSizer
= NULL
;
213 // If this is a child of a sizer, remove self from parent
215 m_sizerParent
->RemoveChild((wxWindow
*)this);
219 m_windowParent
->RemoveChild(this);
223 // Destroy the window
226 wxDeleteWindowFromTable((Widget
) GetMainWidget());
227 XtDestroyWidget((Widget
) GetMainWidget());
228 SetMainWidget((WXWidget
) NULL
);
234 // Just in case the window has been Closed, but
235 // we're then deleting immediately: don't leave
236 // dangling pointers.
237 wxPendingDelete
.DeleteObject(this);
239 if ( m_windowValidator
) delete m_windowValidator
;
240 if (m_clientObject
) delete m_clientObject
;
245 // Destroy the window (delayed, if a managed window)
246 bool wxWindow::Destroy()
253 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
257 const wxString
& name
)
262 m_windowParent
= NULL
;
263 m_windowEventHandler
= this;
265 m_windowCursor
= *wxSTANDARD_CURSOR
;
266 m_constraints
= NULL
;
267 m_constraintsInvolvedIn
= NULL
;
268 m_windowSizer
= NULL
;
269 m_sizerParent
= NULL
;
270 m_autoLayout
= FALSE
;
271 m_windowValidator
= NULL
;
272 #if wxUSE_DRAG_AND_DROP
273 m_pDropTarget
= NULL
;
275 m_caretWidth
= 0; m_caretHeight
= 0;
276 m_caretEnabled
= FALSE
;
277 m_caretShown
= FALSE
;
282 m_defaultItem
= NULL
;
283 m_windowParent
= NULL
;
284 m_clientObject
= (wxClientData
*) NULL
;
288 m_canAddEventHandler
= FALSE
;
289 m_mainWidget
= (WXWidget
) 0;
290 m_button1Pressed
= FALSE
;
291 m_button2Pressed
= FALSE
;
292 m_button3Pressed
= FALSE
;
293 m_winCaptured
= FALSE
;
295 m_hScrollBar
= (WXWidget
) 0;
296 m_vScrollBar
= (WXWidget
) 0;
297 m_borderWidget
= (WXWidget
) 0;
298 m_scrolledWindow
= (WXWidget
) 0;
299 m_drawingArea
= (WXWidget
) 0;
302 m_backingPixmap
= (WXPixmap
) 0;
313 if (parent
) parent
->AddChild(this);
320 m_windowId
= (int)NewControlId();
324 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
325 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
326 m_foregroundColour
= *wxBLACK
;
328 m_windowStyle
= style
;
331 m_windowId
= (int)NewControlId();
335 //// TODO: we should probably optimize by only creating a
336 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
337 //// But for now, let's simplify things by always creating the
338 //// drawing area, since otherwise the translations are different.
340 // New translations for getting mouse motion feedback
341 String translations
=
342 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
343 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
344 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
346 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
347 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
348 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
349 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
350 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
351 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
352 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
353 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
354 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
355 <Key>: DrawingAreaInput()";
357 XtActionsRec actions
[1];
358 actions
[0].string
= "wxCanvasMotionEvent";
359 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
360 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
362 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
363 if (style
& wxBORDER
)
364 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
365 xmFrameWidgetClass
, parentWidget
,
366 XmNshadowType
, XmSHADOW_IN
,
369 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
370 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
372 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
373 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
377 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
378 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
379 XmNunitType
, XmPIXELS
,
380 // XmNresizePolicy, XmRESIZE_ANY,
381 XmNresizePolicy
, XmRESIZE_NONE
,
384 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
387 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
389 XtFree ((char *) ptr);
390 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
391 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
392 XtFree ((char *) ptr);
396 wxAddWindowToTable((Widget
) m_drawingArea
, this);
397 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
400 * This order is very important in Motif 1.2.1
404 XtRealizeWidget ((Widget
) m_scrolledWindow
);
405 XtRealizeWidget ((Widget
) m_drawingArea
);
406 XtManageChild ((Widget
) m_drawingArea
);
408 XtOverrideTranslations ((Widget
) m_drawingArea
,
409 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
410 XtFree ((char *) ptr
);
412 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
413 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
416 display = XtDisplay (scrolledWindow);
417 xwindow = XtWindow (drawingArea);
420 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
421 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
423 // Add scrollbars if required
424 if (m_windowStyle
& wxHSCROLL
)
426 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
427 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
428 XmNorientation
, XmHORIZONTAL
,
430 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
431 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
432 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
433 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
434 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
435 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
436 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
437 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
439 XtVaSetValues (hScrollBar
,
444 m_hScrollBar
= (WXWidget
) hScrollBar
;
446 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
447 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
451 if (m_windowStyle
& wxVSCROLL
)
453 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
454 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
455 XmNorientation
, XmVERTICAL
,
457 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
458 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
459 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
460 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
461 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
462 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
463 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
464 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
466 XtVaSetValues (vScrollBar
,
471 m_vScrollBar
= (WXWidget
) vScrollBar
;
472 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
473 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
478 // Scrolled widget needs to have its colour changed or we get
479 // a little blue square where the scrollbars abutt
480 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
481 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
483 if (m_hScrollBar
|| m_vScrollBar
)
484 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
487 XtRealizeWidget ((Widget
) m_hScrollBar
);
489 XtRealizeWidget ((Widget
) m_vScrollBar
);
491 // Without this, the cursor may not be restored properly
492 // (e.g. in splitter sample).
493 SetCursor(*wxSTANDARD_CURSOR
);
494 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
495 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
500 void wxWindow::SetFocus()
502 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
503 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
506 void wxWindow::Enable(bool enable
)
510 XtSetSensitive((Widget
) GetMainWidget(), enable
);
511 XmUpdateDisplay((Widget
) GetMainWidget());
515 void wxWindow::CaptureMouse()
521 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
523 m_winCaptured
= TRUE
;
526 void wxWindow::ReleaseMouse()
532 XtRemoveGrab((Widget
) GetMainWidget());
533 m_winCaptured
= FALSE
;
536 // Push/pop event handler (i.e. allow a chain of event handlers
538 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
540 handler
->SetNextHandler(GetEventHandler());
541 SetEventHandler(handler
);
544 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
546 if ( GetEventHandler() )
548 wxEvtHandler
*handlerA
= GetEventHandler();
549 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
550 handlerA
->SetNextHandler(NULL
);
551 SetEventHandler(handlerB
);
564 #if wxUSE_DRAG_AND_DROP
566 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
568 if ( m_pDropTarget
!= 0 ) {
569 delete m_pDropTarget
;
572 m_pDropTarget
= pDropTarget
;
573 if ( m_pDropTarget
!= 0 )
581 // Old style file-manager drag&drop
582 void wxWindow::DragAcceptFiles(bool accept
)
588 void wxWindow::GetSize(int *x
, int *y
) const
596 Widget widget
= (Widget
) GetTopWidget();
598 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
602 void wxWindow::GetPosition(int *x
, int *y
) const
606 CanvasGetPosition(x
, y
);
609 Widget widget
= (Widget
) GetTopWidget();
611 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
613 // We may be faking the client origin.
614 // So a window that's really at (0, 30) may appear
615 // (to wxWin apps) to be at (0, 0).
618 wxPoint
pt(GetParent()->GetClientAreaOrigin());
626 void wxWindow::ScreenToClient(int *x
, int *y
) const
628 Widget widget
= (Widget
) GetClientWidget();
629 Display
*display
= XtDisplay((Widget
) GetMainWidget());
630 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
631 Window thisWindow
= XtWindow(widget
);
636 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
639 void wxWindow::ClientToScreen(int *x
, int *y
) const
641 Widget widget
= (Widget
) GetClientWidget();
642 Display
*display
= XtDisplay(widget
);
643 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
644 Window thisWindow
= XtWindow(widget
);
649 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
652 void wxWindow::SetCursor(const wxCursor
& cursor
)
654 m_windowCursor
= cursor
;
655 if (m_windowCursor
.Ok())
657 WXDisplay
*dpy
= GetXDisplay();
658 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
660 Widget w
= (Widget
) GetMainWidget();
661 Window win
= XtWindow(w
);
662 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
667 // Get size *available for subwindows* i.e. excluding menu bar etc.
668 void wxWindow::GetClientSize(int *x
, int *y
) const
670 Widget widget
= (Widget
) GetClientWidget();
672 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
676 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
678 // A bit of optimization to help sort out the flickers.
679 int oldX
, oldY
, oldW
, oldH
;
680 GetSize(& oldW
, & oldH
);
681 GetPosition(& oldX
, & oldY
);
683 bool useOldPos
= FALSE
;
684 bool useOldSize
= FALSE
;
686 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
688 else if (x
== oldX
&& y
== oldY
)
691 if ((width
== -1) && (height
== -1))
693 else if (width
== oldW
&& height
== oldH
)
696 if (useOldPos
&& useOldSize
)
701 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
704 Widget widget
= (Widget
) GetTopWidget();
708 bool managed
= XtIsManaged( widget
);
710 XtUnmanageChild(widget
);
712 int xx
= x
; int yy
= y
;
713 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
717 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
718 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
719 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
720 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
725 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
727 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
731 XtManageChild(widget
);
733 // How about this bit. Maybe we don't need to generate size events
734 // all the time -- they'll be generated when the window is sized anyway.
736 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
737 sizeEvent.SetEventObject(this);
739 GetEventHandler()->ProcessEvent(sizeEvent);
743 void wxWindow::SetClientSize(int width
, int height
)
747 CanvasSetClientSize(width
, height
);
751 Widget widget
= (Widget
) GetTopWidget();
754 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
756 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
758 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
759 sizeEvent
.SetEventObject(this);
761 GetEventHandler()->ProcessEvent(sizeEvent
);
764 // For implementation purposes - sometimes decorations make the client area
766 wxPoint
wxWindow::GetClientAreaOrigin() const
768 return wxPoint(0, 0);
771 // Makes an adjustment to the window position (for example, a frame that has
772 // a toolbar that it manages itself).
773 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
775 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
777 wxPoint
pt(GetParent()->GetClientAreaOrigin());
778 x
+= pt
.x
; y
+= pt
.y
;
782 bool wxWindow::Show(bool show
)
786 if (m_borderWidget
|| m_scrolledWindow
)
789 XtMapWidget((Widget
) m_drawingArea
);
790 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
794 WXWidget topWidget
= GetTopWidget();
796 XtMapWidget((Widget
) GetTopWidget());
797 else if (GetMainWidget())
798 XtMapWidget((Widget
) GetMainWidget());
803 if (m_borderWidget
|| m_scrolledWindow
)
806 XtUnmapWidget((Widget
) m_drawingArea
);
807 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
812 XtUnmapWidget((Widget
) GetTopWidget());
813 else if (GetMainWidget())
814 XtUnmapWidget((Widget
) GetMainWidget());
819 Window xwin = (Window) GetXWindow();
820 Display *xdisp = (Display*) GetXDisplay();
822 XMapWindow(xdisp, xwin);
824 XUnmapWindow(xdisp, xwin);
832 bool wxWindow::IsShown() const
837 int wxWindow::GetCharHeight() const
839 if (!m_windowFont
.Ok())
842 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
844 int direction
, ascent
, descent
;
846 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
848 // return (overall.ascent + overall.descent);
849 return (ascent
+ descent
);
852 int wxWindow::GetCharWidth() const
854 if (!m_windowFont
.Ok())
857 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
859 int direction
, ascent
, descent
;
861 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
863 return overall
.width
;
866 /* Helper function for 16-bit fonts */
867 static int str16len(const char *s
)
871 while (s
[0] && s
[1]) {
879 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
880 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
882 wxFont
*fontToUse
= (wxFont
*)theFont
;
884 fontToUse
= (wxFont
*) & m_windowFont
;
886 if (!fontToUse
->Ok())
889 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
891 int direction
, ascent
, descent2
;
895 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
898 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
899 &ascent
, &descent2
, &overall
);
901 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
902 &ascent
, &descent2
, &overall
);
904 *x
= (overall
.width
);
905 *y
= (ascent
+ descent2
);
909 *externalLeading
= 0;
912 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
914 Display
*display
= XtDisplay((Widget
) GetMainWidget());
915 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
917 XExposeEvent dummyEvent
;
919 GetSize(&width
, &height
);
921 dummyEvent
.type
= Expose
;
922 dummyEvent
.display
= display
;
923 dummyEvent
.send_event
= True
;
924 dummyEvent
.window
= thisWindow
;
927 dummyEvent
.x
= rect
->x
;
928 dummyEvent
.y
= rect
->y
;
929 dummyEvent
.width
= rect
->width
;
930 dummyEvent
.height
= rect
->height
;
936 dummyEvent
.width
= width
;
937 dummyEvent
.height
= height
;
939 dummyEvent
.count
= 0;
944 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
945 dc
.SetBackground(backgroundBrush
);
952 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
955 // Responds to colour changes: passes event on to children.
956 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
958 wxNode
*node
= GetChildren().First();
961 // Only propagate to non-top-level windows
962 wxWindow
*win
= (wxWindow
*)node
->Data();
963 if ( win
->GetParent() )
965 wxSysColourChangedEvent event2
;
966 event
.m_eventObject
= win
;
967 win
->GetEventHandler()->ProcessEvent(event2
);
974 // This can be called by the app (or wxWindows) to do default processing for the current
975 // event. Save message/event info in wxWindow so they can be used in this function.
976 long wxWindow::Default()
982 void wxWindow::InitDialog()
984 wxInitDialogEvent
event(GetId());
985 event
.SetEventObject( this );
986 GetEventHandler()->ProcessEvent(event
);
989 // Default init dialog behaviour is to transfer data to window
990 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
992 TransferDataToWindow();
995 // Caret manipulation
996 void wxWindow::CreateCaret(int w
, int h
)
1000 m_caretEnabled
= TRUE
;
1003 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1008 void wxWindow::ShowCaret(bool show
)
1013 void wxWindow::DestroyCaret()
1016 m_caretEnabled
= FALSE
;
1019 void wxWindow::SetCaretPos(int x
, int y
)
1024 void wxWindow::GetCaretPos(int *x
, int *y
) const
1029 wxWindow
*wxGetActiveWindow()
1035 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1042 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1045 wxFrame
*frame
= (wxFrame
*)this;
1046 Widget widget
= (Widget
) frame
->GetShellWidget();
1049 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1051 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1053 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1055 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1057 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1059 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1062 void wxWindow::Centre(int direction
)
1064 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1066 wxWindow
*father
= (wxWindow
*)GetParent();
1070 father
->GetClientSize(&panel_width
, &panel_height
);
1071 GetSize(&width
, &height
);
1072 GetPosition(&x
, &y
);
1077 if (direction
& wxHORIZONTAL
)
1078 new_x
= (int)((panel_width
- width
)/2);
1080 if (direction
& wxVERTICAL
)
1081 new_y
= (int)((panel_height
- height
)/2);
1083 SetSize(new_x
, new_y
, -1, -1);
1087 // Coordinates relative to the window
1088 void wxWindow::WarpPointer (int x
, int y
)
1090 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1093 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1099 int wxWindow::GetScrollPos(int orient
) const
1101 if (orient
== wxHORIZONTAL
)
1102 return m_scrollPosX
;
1104 return m_scrollPosY
;
1106 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1110 XtVaGetValues(scrollBar,
1111 XmNvalue, &pos, NULL);
1119 // This now returns the whole range, not just the number
1120 // of positions that we can scroll.
1121 int wxWindow::GetScrollRange(int orient
) const
1123 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1127 XtVaGetValues(scrollBar
,
1128 XmNmaximum
, &range
, NULL
);
1135 int wxWindow::GetScrollThumb(int orient
) const
1137 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1141 XtVaGetValues(scrollBar
,
1142 XmNsliderSize
, &thumb
, NULL
);
1149 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1151 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1154 XtVaSetValues (scrollBar
,
1158 if (orient
== wxHORIZONTAL
)
1165 // New function that will replace some of the above.
1166 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1167 int range
, bool WXUNUSED(refresh
))
1169 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1175 if (thumbVisible
== 0)
1178 if (thumbVisible
> range
)
1179 thumbVisible
= range
;
1181 XtVaSetValues(scrollBar
,
1185 XmNsliderSize
, thumbVisible
,
1188 if (orient
== wxHORIZONTAL
)
1193 // See notes below. If the scrollbars didn't leave a ghost presence,
1194 // this would be OK.
1196 if (range
== thumbVisible
)
1198 XtUnmanageChild(scrollBar
);
1199 if (orient
== wxHORIZONTAL
)
1200 XtVaSetValues((Widget
) m_scrolledWindow
,
1201 XmNhorizontalScrollBar
, (Widget
) 0,
1204 XtVaSetValues((Widget
) m_scrolledWindow
,
1205 XmNverticalScrollBar
, (Widget
) 0,
1210 XtManageChild(scrollBar
);
1211 if (orient
== wxHORIZONTAL
)
1212 XtVaSetValues((Widget
) m_scrolledWindow
,
1213 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
1216 XtVaSetValues((Widget
) m_scrolledWindow
,
1217 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
1221 // Either both scrollbars are on, or they are off,
1222 // otherwise you get a gap where one scrollbar
1223 // isn't shown. TODO: try to eliminate this problem.
1224 if ((GetScrollThumb(wxHORIZONTAL
) >= GetScrollRange(wxHORIZONTAL
)) &&
1225 (GetScrollThumb(wxVERTICAL
) >= GetScrollRange(wxVERTICAL
)))
1228 XtUnmanageChild((Widget
) m_hScrollBar
);
1230 XtUnmanageChild((Widget
) m_vScrollBar
);
1231 XtVaSetValues((Widget
) m_scrolledWindow
,
1232 XmNhorizontalScrollBar
, (Widget
) 0,
1233 XmNverticalScrollBar
, (Widget
) 0,
1235 // XmScrolledWindowSetAreas((Widget) m_scrolledWindow,
1236 // (Widget) 0, (Widget) 0, (Widget) m_drawingArea);
1241 XtManageChild((Widget
) m_hScrollBar
);
1243 XtManageChild((Widget
) m_vScrollBar
);
1244 XtVaSetValues((Widget
) m_scrolledWindow
,
1245 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
1246 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
1248 // XmScrolledWindowSetAreas((Widget) m_scrolledWindow,
1249 // (Widget) m_hScrollBar, (Widget) m_vScrollBar, (Widget) m_drawingArea);
1254 // Does a physical scroll
1255 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1257 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1261 // Use specified rectangle
1262 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1266 // Use whole client area
1268 GetClientSize(& w
, & h
);
1271 int x1
= (dx
>= 0) ? x
: x
- dx
;
1272 int y1
= (dy
>= 0) ? y
: y
- dy
;
1273 int w1
= w
- abs(dx
);
1274 int h1
= h
- abs(dy
);
1275 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1276 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1278 wxClientDC
dc(this);
1280 dc
.SetLogicalFunction (wxCOPY
);
1282 Widget widget
= (Widget
) GetMainWidget();
1283 Window window
= XtWindow(widget
);
1284 Display
* display
= XtDisplay(widget
);
1286 XCopyArea(display
, window
,
1287 window
, (GC
) dc
.GetGC(),
1292 dc
.SetAutoSetting(TRUE
);
1293 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1294 dc
.SetBrush(brush
); // ??
1296 // We'll add rectangles to the list of update rectangles
1297 // according to which bits we've exposed.
1302 wxRect
*rect
= new wxRect
;
1308 XFillRectangle(display
, window
,
1309 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1313 rect
->width
= rect
->width
;
1314 rect
->height
= rect
->height
;
1316 updateRects
.Append((wxObject
*) rect
);
1320 wxRect
*rect
= new wxRect
;
1322 rect
->x
= x
+ w
+ dx
;
1327 XFillRectangle(display
, window
,
1328 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1333 rect
->width
= rect
->width
;
1334 rect
->height
= rect
->height
;
1336 updateRects
.Append((wxObject
*) rect
);
1340 wxRect
*rect
= new wxRect
;
1347 XFillRectangle(display
, window
,
1348 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1352 rect
->width
= rect
->width
;
1353 rect
->height
= rect
->height
;
1355 updateRects
.Append((wxObject
*) rect
);
1359 wxRect
*rect
= new wxRect
;
1362 rect
->y
= y
+ h
+ dy
;
1366 XFillRectangle(display
, window
,
1367 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1371 rect
->width
= rect
->width
;
1372 rect
->height
= rect
->height
;
1374 updateRects
.Append((wxObject
*) rect
);
1376 dc
.SetBrush(wxNullBrush
);
1378 // Now send expose events
1380 wxNode
* node
= updateRects
.First();
1383 wxRect
* rect
= (wxRect
*) node
->Data();
1386 event
.type
= Expose
;
1387 event
.display
= display
;
1388 event
.send_event
= True
;
1389 event
.window
= window
;
1393 event
.width
= rect
->width
;
1394 event
.height
= rect
->height
;
1398 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1400 node
= node
->Next();
1404 // Delete the update rects
1405 node
= updateRects
.First();
1408 wxRect
* rect
= (wxRect
*) node
->Data();
1410 node
= node
->Next();
1415 void wxWindow::OnChar(wxKeyEvent
& event
)
1417 if ( event
.KeyCode() == WXK_TAB
) {
1418 // propagate the TABs to the parent - it's up to it to decide what
1420 if ( GetParent() ) {
1421 if ( GetParent()->ProcessEvent(event
) )
1427 void wxWindow::OnPaint(wxPaintEvent
& event
)
1432 bool wxWindow::IsEnabled() const
1434 // TODO. Is this right?
1435 // return XtGetSensitive((Widget) GetMainWidget());
1439 // Dialog support: override these and call
1440 // base class members to add functionality
1441 // that can't be done using validators.
1442 // NOTE: these functions assume that controls
1443 // are direct children of this window, not grandchildren
1444 // or other levels of descendant.
1446 // Transfer values to controls. If returns FALSE,
1447 // it's an application error (pops up a dialog)
1448 bool wxWindow::TransferDataToWindow()
1450 wxNode
*node
= GetChildren().First();
1453 wxWindow
*child
= (wxWindow
*)node
->Data();
1454 if ( child
->GetValidator() &&
1455 !child
->GetValidator()->TransferToWindow() )
1457 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1461 node
= node
->Next();
1466 // Transfer values from controls. If returns FALSE,
1467 // validation failed: don't quit
1468 bool wxWindow::TransferDataFromWindow()
1470 wxNode
*node
= GetChildren().First();
1473 wxWindow
*child
= (wxWindow
*)node
->Data();
1474 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1479 node
= node
->Next();
1484 bool wxWindow::Validate()
1486 wxNode
*node
= GetChildren().First();
1489 wxWindow
*child
= (wxWindow
*)node
->Data();
1490 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1495 node
= node
->Next();
1500 // Get the window with the focus
1501 wxWindow
*wxWindow::FindFocus()
1507 void wxWindow::AddChild(wxWindow
*child
)
1509 GetChildren().Append(child
);
1510 child
->m_windowParent
= this;
1513 void wxWindow::RemoveChild(wxWindow
*child
)
1515 GetChildren().DeleteObject(child
);
1516 child
->m_windowParent
= NULL
;
1519 // Reparents this window to have the new parent.
1520 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1522 // For now, we indicate that this isn't implemented.
1526 void wxWindow::DestroyChildren()
1528 wxNode
*node
= GetChildren().First();
1531 wxNode
* next
= node
->Next();
1532 wxWindow
* child
= (wxWindow
*) node
->Data();
1536 GetChildren().Clear();
1539 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1541 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1543 if ( GetChildren().Member(child
) )
1550 void wxWindow::MakeModal(bool modal
)
1552 // Disable all other windows
1553 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1555 wxNode
*node
= wxTopLevelWindows
.First();
1558 wxWindow
*win
= (wxWindow
*)node
->Data();
1560 win
->Enable(!modal
);
1562 node
= node
->Next();
1567 // If nothing defined for this, try the parent.
1568 // E.g. we may be a button loaded from a resource, with no callback function
1570 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1572 if (GetEventHandler()->ProcessEvent(event
) )
1575 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1578 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1582 UnsetConstraints(m_constraints
);
1583 delete m_constraints
;
1588 // Make sure other windows know they're part of a 'meaningful relationship'
1589 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1590 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1591 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1592 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1593 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1594 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1595 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1596 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1597 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1598 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1599 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1600 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1601 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1602 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1603 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1604 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1608 // This removes any dangling pointers to this window
1609 // in other windows' constraintsInvolvedIn lists.
1610 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1614 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1615 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1616 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1617 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1618 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1619 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1620 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1621 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1622 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1623 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1624 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1625 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1626 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1627 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1628 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1629 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1633 // Back-pointer to other windows we're involved with, so if we delete
1634 // this window, we must delete any constraints we're involved with.
1635 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1637 if (!m_constraintsInvolvedIn
)
1638 m_constraintsInvolvedIn
= new wxList
;
1639 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1640 m_constraintsInvolvedIn
->Append(otherWin
);
1643 // REMOVE back-pointer to other windows we're involved with.
1644 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1646 if (m_constraintsInvolvedIn
)
1647 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1650 // Reset any constraints that mention this window
1651 void wxWindow::DeleteRelatedConstraints()
1653 if (m_constraintsInvolvedIn
)
1655 wxNode
*node
= m_constraintsInvolvedIn
->First();
1658 wxWindow
*win
= (wxWindow
*)node
->Data();
1659 wxNode
*next
= node
->Next();
1660 wxLayoutConstraints
*constr
= win
->GetConstraints();
1662 // Reset any constraints involving this window
1665 constr
->left
.ResetIfWin((wxWindow
*)this);
1666 constr
->top
.ResetIfWin((wxWindow
*)this);
1667 constr
->right
.ResetIfWin((wxWindow
*)this);
1668 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1669 constr
->width
.ResetIfWin((wxWindow
*)this);
1670 constr
->height
.ResetIfWin((wxWindow
*)this);
1671 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1672 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1677 delete m_constraintsInvolvedIn
;
1678 m_constraintsInvolvedIn
= NULL
;
1682 void wxWindow::SetSizer(wxSizer
*sizer
)
1684 m_windowSizer
= sizer
;
1686 sizer
->SetSizerParent((wxWindow
*)this);
1693 bool wxWindow::Layout()
1695 if (GetConstraints())
1698 GetClientSize(&w
, &h
);
1699 GetConstraints()->width
.SetValue(w
);
1700 GetConstraints()->height
.SetValue(h
);
1703 // If top level (one sizer), evaluate the sizer's constraints.
1707 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1708 GetSizer()->LayoutPhase1(&noChanges
);
1709 GetSizer()->LayoutPhase2(&noChanges
);
1710 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1715 // Otherwise, evaluate child constraints
1716 ResetConstraints(); // Mark all constraints as unevaluated
1717 DoPhase(1); // Just one phase need if no sizers involved
1719 SetConstraintSizes(); // Recursively set the real window sizes
1725 // Do a phase of evaluating constraints:
1726 // the default behaviour. wxSizers may do a similar
1727 // thing, but also impose their own 'constraints'
1728 // and order the evaluation differently.
1729 bool wxWindow::LayoutPhase1(int *noChanges
)
1731 wxLayoutConstraints
*constr
= GetConstraints();
1734 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1740 bool wxWindow::LayoutPhase2(int *noChanges
)
1750 // Do a phase of evaluating child constraints
1751 bool wxWindow::DoPhase(int phase
)
1753 int noIterations
= 0;
1754 int maxIterations
= 500;
1758 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1762 wxNode
*node
= GetChildren().First();
1765 wxWindow
*child
= (wxWindow
*)node
->Data();
1766 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1768 wxLayoutConstraints
*constr
= child
->GetConstraints();
1771 if (succeeded
.Member(child
))
1776 int tempNoChanges
= 0;
1777 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1778 noChanges
+= tempNoChanges
;
1781 succeeded
.Append(child
);
1786 node
= node
->Next();
1793 void wxWindow::ResetConstraints()
1795 wxLayoutConstraints
*constr
= GetConstraints();
1798 constr
->left
.SetDone(FALSE
);
1799 constr
->top
.SetDone(FALSE
);
1800 constr
->right
.SetDone(FALSE
);
1801 constr
->bottom
.SetDone(FALSE
);
1802 constr
->width
.SetDone(FALSE
);
1803 constr
->height
.SetDone(FALSE
);
1804 constr
->centreX
.SetDone(FALSE
);
1805 constr
->centreY
.SetDone(FALSE
);
1807 wxNode
*node
= GetChildren().First();
1810 wxWindow
*win
= (wxWindow
*)node
->Data();
1811 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1812 win
->ResetConstraints();
1813 node
= node
->Next();
1817 // Need to distinguish between setting the 'fake' size for
1818 // windows and sizers, and setting the real values.
1819 void wxWindow::SetConstraintSizes(bool recurse
)
1821 wxLayoutConstraints
*constr
= GetConstraints();
1822 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1823 constr
->width
.GetDone() && constr
->height
.GetDone())
1825 int x
= constr
->left
.GetValue();
1826 int y
= constr
->top
.GetValue();
1827 int w
= constr
->width
.GetValue();
1828 int h
= constr
->height
.GetValue();
1830 // If we don't want to resize this window, just move it...
1831 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1832 (constr
->height
.GetRelationship() != wxAsIs
))
1834 // Calls Layout() recursively. AAAGH. How can we stop that.
1835 // Simply take Layout() out of non-top level OnSizes.
1836 SizerSetSize(x
, y
, w
, h
);
1845 char *windowClass
= this->GetClassInfo()->GetClassName();
1848 if (GetName() == "")
1849 winName
= "unnamed";
1851 winName
= GetName();
1852 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1853 if (!constr
->left
.GetDone())
1854 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1855 if (!constr
->right
.GetDone())
1856 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1857 if (!constr
->width
.GetDone())
1858 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1859 if (!constr
->height
.GetDone())
1860 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1861 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1866 wxNode
*node
= GetChildren().First();
1869 wxWindow
*win
= (wxWindow
*)node
->Data();
1870 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1871 win
->SetConstraintSizes();
1872 node
= node
->Next();
1877 // This assumes that all sizers are 'on' the same
1878 // window, i.e. the parent of this window.
1879 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1881 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1882 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1886 m_sizerParent
->GetPosition(&xp
, &yp
);
1887 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1892 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1896 TransformSizerToActual(&xx
, &yy
);
1897 SetSize(xx
, yy
, w
, h
);
1900 void wxWindow::SizerMove(int x
, int y
)
1904 TransformSizerToActual(&xx
, &yy
);
1908 // Only set the size/position of the constraint (if any)
1909 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1911 wxLayoutConstraints
*constr
= GetConstraints();
1916 constr
->left
.SetValue(x
);
1917 constr
->left
.SetDone(TRUE
);
1921 constr
->top
.SetValue(y
);
1922 constr
->top
.SetDone(TRUE
);
1926 constr
->width
.SetValue(w
);
1927 constr
->width
.SetDone(TRUE
);
1931 constr
->height
.SetValue(h
);
1932 constr
->height
.SetDone(TRUE
);
1937 void wxWindow::MoveConstraint(int x
, int y
)
1939 wxLayoutConstraints
*constr
= GetConstraints();
1944 constr
->left
.SetValue(x
);
1945 constr
->left
.SetDone(TRUE
);
1949 constr
->top
.SetValue(y
);
1950 constr
->top
.SetDone(TRUE
);
1955 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1957 wxLayoutConstraints
*constr
= GetConstraints();
1960 *w
= constr
->width
.GetValue();
1961 *h
= constr
->height
.GetValue();
1967 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1969 wxLayoutConstraints
*constr
= GetConstraints();
1972 *w
= constr
->width
.GetValue();
1973 *h
= constr
->height
.GetValue();
1976 GetClientSize(w
, h
);
1979 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1981 wxLayoutConstraints
*constr
= GetConstraints();
1984 *x
= constr
->left
.GetValue();
1985 *y
= constr
->top
.GetValue();
1991 bool wxWindow::Close(bool force
)
1993 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1994 event
.SetEventObject(this);
1995 event
.SetForce(force
);
1997 return GetEventHandler()->ProcessEvent(event
);
2000 wxObject
* wxWindow::GetChild(int number
) const
2002 // Return a pointer to the Nth object in the window
2003 wxNode
*node
= GetChildren().First();
2006 node
= node
->Next() ;
2009 wxObject
*obj
= (wxObject
*)node
->Data();
2016 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2018 // Obsolete function
2021 void wxWindow::Clear()
2023 wxClientDC
dc(this);
2024 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2025 dc
.SetBackground(brush
);
2029 // Fits the panel around the items
2030 void wxWindow::Fit()
2034 wxNode
*node
= GetChildren().First();
2037 wxWindow
*win
= (wxWindow
*)node
->Data();
2039 win
->GetPosition(&wx
, &wy
);
2040 win
->GetSize(&ww
, &wh
);
2041 if ( wx
+ ww
> maxX
)
2043 if ( wy
+ wh
> maxY
)
2046 node
= node
->Next();
2048 SetClientSize(maxX
+ 5, maxY
+ 5);
2051 void wxWindow::SetValidator(const wxValidator
& validator
)
2053 if ( m_windowValidator
)
2054 delete m_windowValidator
;
2055 m_windowValidator
= validator
.Clone();
2057 if ( m_windowValidator
)
2058 m_windowValidator
->SetWindow(this) ;
2061 void wxWindow::SetClientObject( wxClientData
*data
)
2063 if (m_clientObject
) delete m_clientObject
;
2064 m_clientObject
= data
;
2067 wxClientData
*wxWindow::GetClientObject()
2069 return m_clientObject
;
2072 void wxWindow::SetClientData( void *data
)
2074 m_clientData
= data
;
2077 void *wxWindow::GetClientData()
2079 return m_clientData
;
2082 // Find a window by id or name
2083 wxWindow
*wxWindow::FindWindow(long id
)
2088 wxNode
*node
= GetChildren().First();
2091 wxWindow
*child
= (wxWindow
*)node
->Data();
2092 wxWindow
*found
= child
->FindWindow(id
);
2095 node
= node
->Next();
2100 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2102 if ( GetName() == name
)
2105 wxNode
*node
= GetChildren().First();
2108 wxWindow
*child
= (wxWindow
*)node
->Data();
2109 wxWindow
*found
= child
->FindWindow(name
);
2112 node
= node
->Next();
2117 void wxWindow::OnIdle(wxIdleEvent
& event
)
2119 // This calls the UI-update mechanism (querying windows for
2120 // menu/toolbar/control state information)
2124 // Raise the window to the top of the Z order
2125 void wxWindow::Raise()
2127 Window window
= XtWindow((Widget
) GetTopWidget());
2128 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2131 // Lower the window to the bottom of the Z order
2132 void wxWindow::Lower()
2134 Window window
= XtWindow((Widget
) GetTopWidget());
2135 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2138 bool wxWindow::AcceptsFocus() const
2140 return IsShown() && IsEnabled();
2143 // Update region access
2144 wxRegion
& wxWindow::GetUpdateRegion() const
2146 return (wxRegion
&) m_updateRegion
;
2149 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2151 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2154 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2156 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2159 bool wxWindow::IsExposed(const wxRect
& rect
) const
2161 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2165 * Allocates control IDs
2168 int wxWindow::NewControlId()
2170 static int s_controlId
= 0;
2175 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2177 m_acceleratorTable
= accel
;
2180 // All widgets should have this as their resize proc.
2181 // OnSize sent to wxWindow via client data.
2182 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2184 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2188 if (win
->PreResize())
2191 win
->GetSize(&width
, &height
);
2192 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2193 sizeEvent
.SetEventObject(win
);
2194 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2198 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2200 wxWindow
*oldItem
= NULL
;
2201 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2202 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2205 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2208 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2213 wxWidgetHashTable
->Put ((long) w
, win
);
2217 wxWindow
*wxGetWindowFromTable(Widget w
)
2219 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2222 void wxDeleteWindowFromTable(Widget w
)
2224 wxWidgetHashTable
->Delete((long)w
);
2227 // Get the underlying X window and display
2228 WXWindow
wxWindow::GetXWindow() const
2230 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2233 WXDisplay
*wxWindow::GetXDisplay() const
2235 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2238 WXWidget
wxWindow::GetMainWidget() const
2241 return m_drawingArea
;
2243 return m_mainWidget
;
2246 WXWidget
wxWindow::GetClientWidget() const
2248 if (m_drawingArea
!= (WXWidget
) 0)
2249 return m_drawingArea
;
2251 return GetMainWidget();
2254 WXWidget
wxWindow::GetTopWidget() const
2256 return GetMainWidget();
2259 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2260 XmDrawingAreaCallbackStruct
* cbs
)
2262 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2265 XEvent
* event
= cbs
->event
;
2266 wxWindow
* win
= (wxWindow
*) clientData
;
2267 Display
* display
= (Display
*) win
->GetXDisplay();
2269 switch (event
->type
)
2273 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2274 event
->xexpose
.width
, event
->xexpose
.height
);
2276 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2277 cout << rect->width << ", " << rect->height << "\n\n";
2280 win
->m_updateRects
.Append((wxObject
*) rect
);
2282 if (event
-> xexpose
.count
== 0)
2284 wxPaintEvent
event(win
->GetId());
2285 event
.SetEventObject(win
);
2286 win
->GetEventHandler()->ProcessEvent(event
);
2288 win
->ClearUpdateRects();
2294 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2300 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2302 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2304 XmDrawingAreaCallbackStruct cbs
;
2307 //if (event->mode!=NotifyNormal)
2310 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2311 ((XCrossingEvent
&) ev
) = *event
;
2313 cbs
.reason
= XmCR_INPUT
;
2316 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2319 // Fix to make it work under Motif 1.0 (!)
2320 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2324 XmDrawingAreaCallbackStruct cbs
;
2327 //ev.xbutton = *event;
2328 ev
= *((XEvent
*) event
);
2329 cbs
.reason
= XmCR_INPUT
;
2332 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2336 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2338 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2344 if (cbs
->reason
!= XmCR_INPUT
)
2347 local_event
= *(cbs
->event
); // We must keep a copy!
2350 switch (local_event.xany.type)
2353 cout << "EnterNotify\n";
2356 cout << "LeaveNotify\n";
2359 cout << "ButtonPress\n";
2362 cout << "ButtonRelease\n";
2365 cout << "MotionNotify\n";
2368 cout << "Something else\n";
2373 switch (local_event
.xany
.type
)
2381 wxEventType eventType
= wxEVT_NULL
;
2383 if (local_event
.xany
.type
== EnterNotify
)
2385 //if (local_event.xcrossing.mode!=NotifyNormal)
2386 // return ; // Ignore grab events
2387 eventType
= wxEVT_ENTER_WINDOW
;
2388 // canvas->GetEventHandler()->OnSetFocus();
2390 else if (local_event
.xany
.type
== LeaveNotify
)
2392 //if (local_event.xcrossing.mode!=NotifyNormal)
2393 // return ; // Ignore grab events
2394 eventType
= wxEVT_LEAVE_WINDOW
;
2395 // canvas->GetEventHandler()->OnKillFocus();
2397 else if (local_event
.xany
.type
== MotionNotify
)
2399 eventType
= wxEVT_MOTION
;
2400 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2403 Display
*dpy
= XtDisplay (drawingArea
);
2405 XQueryPointer (dpy
, XtWindow (drawingArea
),
2407 &local_event
.xmotion
.x_root
,
2408 &local_event
.xmotion
.y_root
,
2409 &local_event
.xmotion
.x
,
2410 &local_event
.xmotion
.y
,
2411 &local_event
.xmotion
.state
);
2418 else if (local_event
.xany
.type
== ButtonPress
)
2420 if (local_event
.xbutton
.button
== Button1
)
2422 eventType
= wxEVT_LEFT_DOWN
;
2423 canvas
->m_button1Pressed
= TRUE
;
2425 else if (local_event
.xbutton
.button
== Button2
)
2427 eventType
= wxEVT_MIDDLE_DOWN
;
2428 canvas
->m_button2Pressed
= TRUE
;
2430 else if (local_event
.xbutton
.button
== Button3
)
2432 eventType
= wxEVT_RIGHT_DOWN
;
2433 canvas
->m_button3Pressed
= TRUE
;
2436 else if (local_event
.xany
.type
== ButtonRelease
)
2438 if (local_event
.xbutton
.button
== Button1
)
2440 eventType
= wxEVT_LEFT_UP
;
2441 canvas
->m_button1Pressed
= FALSE
;
2443 else if (local_event
.xbutton
.button
== Button2
)
2445 eventType
= wxEVT_MIDDLE_UP
;
2446 canvas
->m_button2Pressed
= FALSE
;
2448 else if (local_event
.xbutton
.button
== Button3
)
2450 eventType
= wxEVT_RIGHT_UP
;
2451 canvas
->m_button3Pressed
= FALSE
;
2455 wxMouseEvent
wxevent (eventType
);
2456 wxevent
.m_eventHandle
= (char *) &local_event
;
2458 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2459 || (event_left_is_down (&local_event
)
2460 && (eventType
!= wxEVT_LEFT_UP
)));
2461 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2462 || (event_middle_is_down (&local_event
)
2463 && (eventType
!= wxEVT_MIDDLE_UP
)));
2464 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2465 || (event_right_is_down (&local_event
)
2466 && (eventType
!= wxEVT_RIGHT_UP
)));
2468 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2469 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2470 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2471 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2472 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2474 // Now check if we need to translate this event into a double click
2475 if (TRUE
) // canvas->doubleClickAllowed)
2477 if (wxevent
.ButtonDown())
2479 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2481 // get button and time-stamp
2483 if (wxevent
.LeftDown()) button
= 1;
2484 else if (wxevent
.MiddleDown()) button
= 2;
2485 else if (wxevent
.RightDown()) button
= 3;
2486 long ts
= wxevent
.GetTimestamp();
2487 // check, if single or double click
2488 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2491 canvas
->m_lastButton
= 0;
2492 switch ( eventType
)
2494 case wxEVT_LEFT_DOWN
:
2495 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2497 case wxEVT_MIDDLE_DOWN
:
2498 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2500 case wxEVT_RIGHT_DOWN
:
2501 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2511 // not fast enough or different button
2512 canvas
->m_lastTS
= ts
;
2513 canvas
->m_lastButton
= button
;
2518 wxevent
.SetId(canvas
->GetId());
2519 wxevent
.SetEventObject(canvas
);
2520 wxevent
.m_x
= local_event
.xbutton
.x
;
2521 wxevent
.m_y
= local_event
.xbutton
.y
;
2522 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2524 if (eventType == wxEVT_ENTER_WINDOW ||
2525 eventType == wxEVT_LEAVE_WINDOW ||
2526 eventType == wxEVT_MOTION
2535 // XComposeStatus compose;
2536 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2537 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2538 int id
= wxCharCodeXToWX (keySym
);
2540 wxKeyEvent
event (wxEVT_CHAR
);
2542 if (local_event
.xkey
.state
& ShiftMask
)
2543 event
.m_shiftDown
= TRUE
;
2544 if (local_event
.xkey
.state
& ControlMask
)
2545 event
.m_controlDown
= TRUE
;
2546 if (local_event
.xkey
.state
& Mod3Mask
)
2547 event
.m_altDown
= TRUE
;
2548 if (local_event
.xkey
.state
& Mod1Mask
)
2549 event
.m_metaDown
= TRUE
;
2550 event
.SetEventObject(canvas
);
2551 event
.m_keyCode
= id
;
2552 event
.SetTimestamp(local_event
.xkey
.time
);
2556 // Implement wxFrame::OnCharHook by checking ancestor.
2557 wxWindow
*parent
= canvas
->GetParent();
2558 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2559 parent
= parent
->GetParent();
2563 event
.SetEventType(wxEVT_CHAR_HOOK
);
2564 if (parent
->GetEventHandler()->ProcessEvent(event
))
2566 event
.SetEventType(wxEVT_CHAR
);
2569 canvas
->GetEventHandler()->ProcessEvent (event
);
2575 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2577 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2578 event
.SetEventObject(canvas
);
2579 canvas
->GetEventHandler()->ProcessEvent(event
);
2585 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2587 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2588 event
.SetEventObject(canvas
);
2589 canvas
->GetEventHandler()->ProcessEvent(event
);
2598 void wxWindow::DoPaint()
2600 //TODO : make a temporary gc so we can do the XCopyArea below
2601 if (0) // m_backingPixmap)
2604 Widget drawingArea = (Widget) m_drawingArea;
2605 // int orig = GetDC()->GetLogicalFunction();
2606 // GetDC()->SetLogicalFunction (wxCOPY);
2608 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2609 // should be able to calculate them.
2610 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2611 m_pixmapOffsetX, m_pixmapOffsetY,
2612 m_pixmapWidth, m_pixmapHeight,
2615 // GetDC()->SetLogicalFunction (orig);
2620 wxPaintEvent
event(GetId());
2621 event
.SetEventObject(this);
2622 GetEventHandler()->ProcessEvent(event
);
2626 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2627 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2629 // A bit of optimization to help sort out the flickers.
2630 int oldX
, oldY
, oldW
, oldH
;
2631 GetSize(& oldW
, & oldH
);
2632 GetPosition(& oldX
, & oldY
);
2634 bool useOldPos
= FALSE
;
2635 bool useOldSize
= FALSE
;
2637 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2639 else if (x
== oldX
&& y
== oldY
)
2642 if ((w
== -1) && (h
== -1))
2644 else if (w
== oldW
&& h
== oldH
)
2647 if (useOldPos
&& useOldSize
)
2650 Widget drawingArea
= (Widget
) m_drawingArea
;
2651 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2654 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2655 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2657 int xx
= x
; int yy
= y
;
2658 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2662 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2664 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2668 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2670 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2682 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2683 short thick
, margin
;
2684 XtVaGetValues ((Widget
) m_borderWidget
,
2685 XmNshadowThickness
, &thick
,
2686 XmNmarginWidth
, &margin
,
2688 w
-= 2 * (thick
+ margin
);
2691 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2695 XtVaGetValues ((Widget
) m_scrolledWindow
,
2696 XmNspacing
, &spacing
,
2697 XmNverticalScrollBar
, &sbar
,
2701 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2705 w
-= (spacing
+ wsbar
);
2707 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2713 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2714 short thick
, margin
;
2715 XtVaGetValues ((Widget
) m_borderWidget
,
2716 XmNshadowThickness
, &thick
,
2717 XmNmarginHeight
, &margin
,
2719 h
-= 2 * (thick
+ margin
);
2722 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2726 XtVaGetValues ((Widget
) m_scrolledWindow
,
2727 XmNspacing
, &spacing
,
2728 XmNhorizontalScrollBar
, &sbar
,
2732 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2736 h
-= (spacing
+ wsbar
);
2738 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2743 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2744 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2748 GetClientSize (&ww, &hh);
2749 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2750 sizeEvent.SetEventObject(this);
2752 GetEventHandler()->ProcessEvent(sizeEvent);
2757 void wxWindow::CanvasSetClientSize (int w
, int h
)
2759 Widget drawingArea
= (Widget
) m_drawingArea
;
2761 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2764 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2766 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2767 /* TODO: is this necessary?
2768 allowRepainting = FALSE;
2770 XSync (XtDisplay (drawingArea), FALSE);
2772 while (XtAppPending (wxTheApp->appContext))
2774 XFlush (XtDisplay (drawingArea));
2775 XtAppNextEvent (wxTheApp->appContext, &event);
2776 XtDispatchEvent (&event);
2780 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2783 allowRepainting = TRUE;
2788 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2789 sizeEvent.SetEventObject(this);
2791 GetEventHandler()->ProcessEvent(sizeEvent);
2795 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2797 // Must return the same thing that was set via SetClientSize
2799 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2804 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2807 if ((Widget
) m_borderWidget
)
2808 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2809 else if ((Widget
) m_scrolledWindow
)
2810 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2812 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2818 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2821 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2823 // We may be faking the client origin.
2824 // So a window that's really at (0, 30) may appear
2825 // (to wxWin apps) to be at (0, 0).
2828 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2837 // Add to hash table, add event handler
2838 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2839 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2841 wxAddWindowToTable((Widget
) mainWidget
, this);
2842 if (CanAddEventHandler())
2844 XtAddEventHandler((Widget
) mainWidget
,
2845 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2847 wxPanelItemEventHandler
,
2854 XtOverrideTranslations ((Widget
) mainWidget
,
2855 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2856 XtFree ((char *) ptr
);
2859 // Some widgets have a parent form widget, e.g. wxRadioBox
2862 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2866 XtOverrideTranslations ((Widget
) formWidget
,
2867 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2868 XtFree ((char *) ptr
);
2875 SetSize (x
, y
, width
, height
);
2880 // Remove event handler, remove from hash table
2881 bool wxWindow::DetachWidget(WXWidget widget
)
2883 if (CanAddEventHandler())
2885 XtRemoveEventHandler((Widget
) widget
,
2886 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2888 wxPanelItemEventHandler
,
2892 wxDeleteWindowFromTable((Widget
) widget
);
2896 void wxPanelItemEventHandler (Widget wid
,
2897 XtPointer client_data
,
2899 Boolean
*continueToDispatch
)
2901 // Widget can be a label or the actual widget.
2903 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2906 wxMouseEvent
wxevent(0);
2907 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2909 window
->GetEventHandler()->ProcessEvent(wxevent
);
2912 // TODO: probably the key to allowing default behaviour
2914 // Say we set a m_doDefault flag to FALSE at the start of this
2915 // function. Then in e.g. wxWindow::OnMouseEvent we can
2916 // call Default() which sets this flag to TRUE, indicating
2917 // that default processing can happen. Thus, behaviour can appear
2918 // to be overridden just by adding an event handler and not calling
2919 // wxWindow::OnWhatever.
2920 // ALSO, maybe we can use this instead of the current way of handling
2921 // drawing area events, to simplify things.
2922 *continueToDispatch
= True
;
2925 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2926 XmScaleCallbackStruct
*cbs
)
2928 Widget scrolledWindow
= XtParent (scrollbar
);
2929 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2930 int orientation
= (int) clientData
;
2932 wxEventType eventType
= wxEVT_NULL
;
2933 switch (cbs
->reason
)
2935 case XmCR_INCREMENT
:
2937 eventType
= wxEVT_SCROLL_LINEDOWN
;
2940 case XmCR_DECREMENT
:
2942 eventType
= wxEVT_SCROLL_LINEUP
;
2947 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2950 case XmCR_VALUE_CHANGED
:
2952 // TODO: Should this be intercepted too, or will it cause
2953 // duplicate events?
2954 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2957 case XmCR_PAGE_INCREMENT
:
2959 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2962 case XmCR_PAGE_DECREMENT
:
2964 eventType
= wxEVT_SCROLL_PAGEUP
;
2969 eventType
= wxEVT_SCROLL_TOP
;
2972 case XmCR_TO_BOTTOM
:
2974 eventType
= wxEVT_SCROLL_BOTTOM
;
2979 // Should never get here
2980 wxFAIL_MSG("Unknown scroll event.");
2985 wxScrollEvent
event(eventType
, win
->GetId());
2986 event
.SetEventObject(win
);
2987 event
.SetPosition(cbs
->value
);
2988 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2990 win
->GetEventHandler()->ProcessEvent(event
);
2993 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2995 switch (xevent
->xany
.type
)
3003 wxEventType eventType
= wxEVT_NULL
;
3005 if (xevent
->xany
.type
== LeaveNotify
)
3007 win
->m_button1Pressed
= FALSE
;
3008 win
->m_button2Pressed
= FALSE
;
3009 win
->m_button3Pressed
= FALSE
;
3012 else if (xevent
->xany
.type
== MotionNotify
)
3014 eventType
= wxEVT_MOTION
;
3016 else if (xevent
->xany
.type
== ButtonPress
)
3018 if (xevent
->xbutton
.button
== Button1
)
3020 eventType
= wxEVT_LEFT_DOWN
;
3021 win
->m_button1Pressed
= TRUE
;
3023 else if (xevent
->xbutton
.button
== Button2
)
3025 eventType
= wxEVT_MIDDLE_DOWN
;
3026 win
->m_button2Pressed
= TRUE
;
3028 else if (xevent
->xbutton
.button
== Button3
)
3030 eventType
= wxEVT_RIGHT_DOWN
;
3031 win
->m_button3Pressed
= TRUE
;
3034 else if (xevent
->xany
.type
== ButtonRelease
)
3036 if (xevent
->xbutton
.button
== Button1
)
3038 eventType
= wxEVT_LEFT_UP
;
3039 win
->m_button1Pressed
= FALSE
;
3041 else if (xevent
->xbutton
.button
== Button2
)
3043 eventType
= wxEVT_MIDDLE_UP
;
3044 win
->m_button2Pressed
= FALSE
;
3046 else if (xevent
->xbutton
.button
== Button3
)
3048 eventType
= wxEVT_RIGHT_UP
;
3049 win
->m_button3Pressed
= FALSE
;
3055 wxevent
.m_eventHandle
= (char *)xevent
;
3056 wxevent
.SetEventType(eventType
);
3059 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3062 win
->GetPosition(&x2
, &y2
);
3064 // The button x/y must be translated to wxWindows
3065 // window space - the widget might be a label or button,
3069 if (widget
!= (Widget
)win
->GetMainWidget())
3075 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3076 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3078 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3079 || (event_left_is_down (xevent
)
3080 && (eventType
!= wxEVT_LEFT_UP
)));
3081 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3082 || (event_middle_is_down (xevent
)
3083 && (eventType
!= wxEVT_MIDDLE_UP
)));
3084 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3085 || (event_right_is_down (xevent
)
3086 && (eventType
!= wxEVT_RIGHT_UP
)));
3088 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3089 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3096 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3098 switch (xevent
->xany
.type
)
3105 // XComposeStatus compose;
3106 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3107 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3108 int id
= wxCharCodeXToWX (keySym
);
3110 if (xevent
->xkey
.state
& ShiftMask
)
3111 wxevent
.m_shiftDown
= TRUE
;
3112 if (xevent
->xkey
.state
& ControlMask
)
3113 wxevent
.m_controlDown
= TRUE
;
3114 if (xevent
->xkey
.state
& Mod3Mask
)
3115 wxevent
.m_altDown
= TRUE
;
3116 if (xevent
->xkey
.state
& Mod1Mask
)
3117 wxevent
.m_metaDown
= TRUE
;
3118 wxevent
.SetEventObject(win
);
3119 wxevent
.m_keyCode
= id
;
3120 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3122 wxevent
.m_x
= xevent
->xbutton
.x
;
3123 wxevent
.m_y
= xevent
->xbutton
.y
;
3137 #define YAllocColor XAllocColor
3138 XColor g_itemColors
[5];
3139 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3142 static XmColorProc colorProc
;
3144 result
= wxNO_COLORS
;
3148 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3149 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3150 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3151 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3152 if (colorProc
== (XmColorProc
) NULL
)
3154 // Get a ptr to the actual function
3155 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3156 // And set it back to motif.
3157 XmSetColorCalculation (colorProc
);
3159 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3160 &g_itemColors
[wxFORE_INDEX
],
3161 &g_itemColors
[wxSELE_INDEX
],
3162 &g_itemColors
[wxTOPS_INDEX
],
3163 &g_itemColors
[wxBOTS_INDEX
]);
3164 result
= wxBACK_COLORS
;
3168 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3169 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3170 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3171 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3172 if (result
== wxNO_COLORS
)
3173 result
= wxFORE_COLORS
;
3176 Display
*dpy
= display
;
3177 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3181 /* 5 Colours to allocate */
3182 for (int i
= 0; i
< 5; i
++)
3183 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3184 result
= wxNO_COLORS
;
3188 /* Only 1 colour to allocate */
3189 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3190 result
= wxNO_COLORS
;
3197 // Changes the foreground and background colours to be derived
3198 // from the current background colour.
3199 // To change the foreground colour, you must call SetForegroundColour
3201 void wxWindow::ChangeBackgroundColour()
3203 if (GetMainWidget())
3204 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3207 void wxWindow::ChangeForegroundColour()
3209 if (GetMainWidget())
3210 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3213 // Change a widget's foreground and background colours.
3215 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3217 // When should we specify the foreground, if it's calculated
3218 // by wxComputeColours?
3219 // Solution: say we start with the default (computed) foreground colour.
3220 // If we call SetForegroundColour explicitly for a control or window,
3221 // then the foreground is changed.
3222 // Therefore SetBackgroundColour computes the foreground colour, and
3223 // SetForegroundColour changes the foreground colour. The ordering is
3226 XtVaSetValues ((Widget
) widget
,
3227 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3231 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3233 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3236 XtVaSetValues ((Widget
) widget
,
3237 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3238 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3239 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3240 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3243 if (changeArmColour
)
3244 XtVaSetValues ((Widget
) widget
,
3245 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3249 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3251 m_backgroundColour
= col
;
3252 ChangeBackgroundColour();
3255 void wxWindow::SetForegroundColour(const wxColour
& col
)
3257 m_foregroundColour
= col
;
3258 ChangeForegroundColour();
3261 void wxWindow::ChangeFont(bool keepOriginalSize
)
3263 // Note that this causes the widget to be resized back
3264 // to its original size! We therefore have to set the size
3265 // back again. TODO: a better way in Motif?
3266 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3267 if (w
&& m_windowFont
.Ok())
3269 int width
, height
, width1
, height1
;
3270 GetSize(& width
, & height
);
3272 // lesstif 0.87 hangs here
3273 #ifndef LESSTIF_VERSION
3275 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3279 GetSize(& width1
, & height1
);
3280 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3282 SetSize(-1, -1, width
, height
);
3287 void wxWindow::SetFont(const wxFont
& font
)
3289 m_windowFont
= font
;
3293 void wxWindow::ClearUpdateRects()
3295 wxNode
* node
= m_updateRects
.First();
3298 wxRect
* rect
= (wxRect
*) node
->Data();
3300 node
= node
->Next();
3302 m_updateRects
.Clear();
3305 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3307 if (!m_acceleratorTable
.Ok())
3310 int count
= m_acceleratorTable
.GetCount();
3311 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3313 for (i
= 0; i
< count
; i
++)
3315 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3316 if (entry
->MatchesEvent(event
))
3318 // Bingo, we have a match. Now find a control
3319 // that matches the entry command id.
3321 // Need to go up to the top of the window hierarchy,
3322 // since it might be e.g. a menu item
3323 wxWindow
* parent
= this;
3324 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3325 parent
= parent
->GetParent();
3330 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3332 // Try for a menu command
3333 wxFrame
* frame
= (wxFrame
*) parent
;
3334 if (frame
->GetMenuBar())
3336 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3339 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3340 commandEvent
.SetEventObject(frame
);
3342 // If ProcessEvent returns TRUE (it was handled), then
3343 // the calling code will skip the event handling.
3344 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3349 // Find a child matching the command id
3350 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3356 // Now we process those kinds of windows that we can.
3357 // For now, only buttons.
3358 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3360 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3361 commandEvent
.SetEventObject(child
);
3362 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3369 // We didn't match the key event against an accelerator.