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
,
371 XmNresizePolicy
, XmRESIZE_NONE
,
373 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
374 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
378 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
379 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
380 XmNunitType
, XmPIXELS
,
381 // XmNresizePolicy, XmRESIZE_ANY,
382 XmNresizePolicy
, XmRESIZE_NONE
,
385 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
388 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
390 XtFree ((char *) ptr);
391 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
392 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
393 XtFree ((char *) ptr);
397 wxAddWindowToTable((Widget
) m_drawingArea
, this);
398 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
401 * This order is very important in Motif 1.2.1
405 XtRealizeWidget ((Widget
) m_scrolledWindow
);
406 XtRealizeWidget ((Widget
) m_drawingArea
);
407 XtManageChild ((Widget
) m_drawingArea
);
409 XtOverrideTranslations ((Widget
) m_drawingArea
,
410 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
411 XtFree ((char *) ptr
);
413 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
414 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
417 display = XtDisplay (scrolledWindow);
418 xwindow = XtWindow (drawingArea);
421 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
422 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
424 // Scrolled widget needs to have its colour changed or we get
425 // a little blue square where the scrollbars abutt
426 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
427 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
428 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
430 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) 0, (Widget
) 0, (Widget
) m_drawingArea
);
434 XtRealizeWidget ((Widget) m_hScrollBar);
436 XtRealizeWidget ((Widget) m_vScrollBar);
439 // Without this, the cursor may not be restored properly
440 // (e.g. in splitter sample).
441 SetCursor(*wxSTANDARD_CURSOR
);
442 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
443 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
449 void wxWindow::CreateScrollbar(int orientation
)
454 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
456 // Add scrollbars if required
457 if (orientation
== wxHORIZONTAL
)
459 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
460 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
461 XmNorientation
, XmHORIZONTAL
,
463 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
464 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
465 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
466 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
467 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
468 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
469 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
470 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
472 XtVaSetValues (hScrollBar
,
477 m_hScrollBar
= (WXWidget
) hScrollBar
;
479 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
480 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
482 XtRealizeWidget(hScrollBar
);
484 XtVaSetValues((Widget
) m_scrolledWindow
,
485 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
491 if (orientation
== wxVERTICAL
)
493 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
494 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
495 XmNorientation
, XmVERTICAL
,
497 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
498 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
499 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
500 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
501 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
502 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
503 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
504 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
506 XtVaSetValues (vScrollBar
,
511 m_vScrollBar
= (WXWidget
) vScrollBar
;
512 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
513 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
515 XtRealizeWidget(vScrollBar
);
517 XtVaSetValues((Widget
) m_scrolledWindow
,
518 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
524 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
526 void wxWindow::DestroyScrollbar(int orientation
)
531 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
532 // Add scrollbars if required
533 if (orientation
== wxHORIZONTAL
)
537 XtDestroyWidget((Widget
) m_hScrollBar
);
539 m_hScrollBar
= (WXWidget
) 0;
542 XtVaSetValues((Widget
) m_scrolledWindow
,
543 XmNhorizontalScrollBar
, (Widget
) 0,
548 if (orientation
== wxVERTICAL
)
552 XtDestroyWidget((Widget
) m_vScrollBar
);
554 m_vScrollBar
= (WXWidget
) 0;
557 XtVaSetValues((Widget
) m_scrolledWindow
,
558 XmNverticalScrollBar
, (Widget
) 0,
562 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
565 void wxWindow::SetFocus()
567 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
568 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
571 void wxWindow::Enable(bool enable
)
575 XtSetSensitive((Widget
) GetMainWidget(), enable
);
576 XmUpdateDisplay((Widget
) GetMainWidget());
580 void wxWindow::CaptureMouse()
586 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
588 m_winCaptured
= TRUE
;
591 void wxWindow::ReleaseMouse()
597 XtRemoveGrab((Widget
) GetMainWidget());
598 m_winCaptured
= FALSE
;
601 // Push/pop event handler (i.e. allow a chain of event handlers
603 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
605 handler
->SetNextHandler(GetEventHandler());
606 SetEventHandler(handler
);
609 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
611 if ( GetEventHandler() )
613 wxEvtHandler
*handlerA
= GetEventHandler();
614 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
615 handlerA
->SetNextHandler(NULL
);
616 SetEventHandler(handlerB
);
629 #if wxUSE_DRAG_AND_DROP
631 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
633 if ( m_pDropTarget
!= 0 ) {
634 delete m_pDropTarget
;
637 m_pDropTarget
= pDropTarget
;
638 if ( m_pDropTarget
!= 0 )
646 // Old style file-manager drag&drop
647 void wxWindow::DragAcceptFiles(bool accept
)
653 void wxWindow::GetSize(int *x
, int *y
) const
661 Widget widget
= (Widget
) GetTopWidget();
663 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
667 void wxWindow::GetPosition(int *x
, int *y
) const
671 CanvasGetPosition(x
, y
);
674 Widget widget
= (Widget
) GetTopWidget();
676 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
678 // We may be faking the client origin.
679 // So a window that's really at (0, 30) may appear
680 // (to wxWin apps) to be at (0, 0).
683 wxPoint
pt(GetParent()->GetClientAreaOrigin());
691 void wxWindow::ScreenToClient(int *x
, int *y
) const
693 Widget widget
= (Widget
) GetClientWidget();
694 Display
*display
= XtDisplay((Widget
) GetMainWidget());
695 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
696 Window thisWindow
= XtWindow(widget
);
701 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
704 void wxWindow::ClientToScreen(int *x
, int *y
) const
706 Widget widget
= (Widget
) GetClientWidget();
707 Display
*display
= XtDisplay(widget
);
708 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
709 Window thisWindow
= XtWindow(widget
);
714 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
717 void wxWindow::SetCursor(const wxCursor
& cursor
)
719 m_windowCursor
= cursor
;
720 if (m_windowCursor
.Ok())
722 WXDisplay
*dpy
= GetXDisplay();
723 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
725 Widget w
= (Widget
) GetMainWidget();
726 Window win
= XtWindow(w
);
727 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
732 // Get size *available for subwindows* i.e. excluding menu bar etc.
733 void wxWindow::GetClientSize(int *x
, int *y
) const
735 Widget widget
= (Widget
) GetClientWidget();
737 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
741 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
743 // A bit of optimization to help sort out the flickers.
744 int oldX
, oldY
, oldW
, oldH
;
745 GetSize(& oldW
, & oldH
);
746 GetPosition(& oldX
, & oldY
);
748 bool useOldPos
= FALSE
;
749 bool useOldSize
= FALSE
;
751 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
753 else if (x
== oldX
&& y
== oldY
)
756 if ((width
== -1) && (height
== -1))
758 else if (width
== oldW
&& height
== oldH
)
761 if (!wxNoOptimize::CanOptimize())
763 useOldSize
= FALSE
; useOldPos
= FALSE
;
766 if (useOldPos
&& useOldSize
)
771 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
774 Widget widget
= (Widget
) GetTopWidget();
778 bool managed
= XtIsManaged( widget
);
780 XtUnmanageChild(widget
);
782 int xx
= x
; int yy
= y
;
783 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
787 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
788 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
789 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
790 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
795 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
797 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
801 XtManageChild(widget
);
803 // How about this bit. Maybe we don't need to generate size events
804 // all the time -- they'll be generated when the window is sized anyway.
806 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
807 sizeEvent.SetEventObject(this);
809 GetEventHandler()->ProcessEvent(sizeEvent);
813 void wxWindow::SetClientSize(int width
, int height
)
817 CanvasSetClientSize(width
, height
);
821 Widget widget
= (Widget
) GetTopWidget();
824 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
826 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
828 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
829 sizeEvent
.SetEventObject(this);
831 GetEventHandler()->ProcessEvent(sizeEvent
);
834 // For implementation purposes - sometimes decorations make the client area
836 wxPoint
wxWindow::GetClientAreaOrigin() const
838 return wxPoint(0, 0);
841 // Makes an adjustment to the window position (for example, a frame that has
842 // a toolbar that it manages itself).
843 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
845 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
847 wxPoint
pt(GetParent()->GetClientAreaOrigin());
848 x
+= pt
.x
; y
+= pt
.y
;
852 bool wxWindow::Show(bool show
)
856 if (m_borderWidget
|| m_scrolledWindow
)
859 XtMapWidget((Widget
) m_drawingArea
);
860 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
864 WXWidget topWidget
= GetTopWidget();
866 XtMapWidget((Widget
) GetTopWidget());
867 else if (GetMainWidget())
868 XtMapWidget((Widget
) GetMainWidget());
873 if (m_borderWidget
|| m_scrolledWindow
)
876 XtUnmapWidget((Widget
) m_drawingArea
);
877 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
882 XtUnmapWidget((Widget
) GetTopWidget());
883 else if (GetMainWidget())
884 XtUnmapWidget((Widget
) GetMainWidget());
889 Window xwin = (Window) GetXWindow();
890 Display *xdisp = (Display*) GetXDisplay();
892 XMapWindow(xdisp, xwin);
894 XUnmapWindow(xdisp, xwin);
902 bool wxWindow::IsShown() const
907 int wxWindow::GetCharHeight() const
909 if (!m_windowFont
.Ok())
912 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
914 int direction
, ascent
, descent
;
916 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
918 // return (overall.ascent + overall.descent);
919 return (ascent
+ descent
);
922 int wxWindow::GetCharWidth() const
924 if (!m_windowFont
.Ok())
927 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
929 int direction
, ascent
, descent
;
931 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
933 return overall
.width
;
936 /* Helper function for 16-bit fonts */
937 static int str16len(const char *s
)
941 while (s
[0] && s
[1]) {
949 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
950 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
952 wxFont
*fontToUse
= (wxFont
*)theFont
;
954 fontToUse
= (wxFont
*) & m_windowFont
;
956 if (!fontToUse
->Ok())
959 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
961 int direction
, ascent
, descent2
;
965 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
968 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
969 &ascent
, &descent2
, &overall
);
971 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
972 &ascent
, &descent2
, &overall
);
974 *x
= (overall
.width
);
975 *y
= (ascent
+ descent2
);
979 *externalLeading
= 0;
982 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
984 Display
*display
= XtDisplay((Widget
) GetMainWidget());
985 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
987 XExposeEvent dummyEvent
;
989 GetSize(&width
, &height
);
991 dummyEvent
.type
= Expose
;
992 dummyEvent
.display
= display
;
993 dummyEvent
.send_event
= True
;
994 dummyEvent
.window
= thisWindow
;
997 dummyEvent
.x
= rect
->x
;
998 dummyEvent
.y
= rect
->y
;
999 dummyEvent
.width
= rect
->width
;
1000 dummyEvent
.height
= rect
->height
;
1006 dummyEvent
.width
= width
;
1007 dummyEvent
.height
= height
;
1009 dummyEvent
.count
= 0;
1013 wxClientDC
dc(this);
1014 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1015 dc
.SetBackground(backgroundBrush
);
1022 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1025 // Responds to colour changes: passes event on to children.
1026 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1028 wxNode
*node
= GetChildren().First();
1031 // Only propagate to non-top-level windows
1032 wxWindow
*win
= (wxWindow
*)node
->Data();
1033 if ( win
->GetParent() )
1035 wxSysColourChangedEvent event2
;
1036 event
.m_eventObject
= win
;
1037 win
->GetEventHandler()->ProcessEvent(event2
);
1040 node
= node
->Next();
1044 // This can be called by the app (or wxWindows) to do default processing for the current
1045 // event. Save message/event info in wxWindow so they can be used in this function.
1046 long wxWindow::Default()
1052 void wxWindow::InitDialog()
1054 wxInitDialogEvent
event(GetId());
1055 event
.SetEventObject( this );
1056 GetEventHandler()->ProcessEvent(event
);
1059 // Default init dialog behaviour is to transfer data to window
1060 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
1062 TransferDataToWindow();
1065 // Caret manipulation
1066 void wxWindow::CreateCaret(int w
, int h
)
1070 m_caretEnabled
= TRUE
;
1073 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1078 void wxWindow::ShowCaret(bool show
)
1083 void wxWindow::DestroyCaret()
1086 m_caretEnabled
= FALSE
;
1089 void wxWindow::SetCaretPos(int x
, int y
)
1094 void wxWindow::GetCaretPos(int *x
, int *y
) const
1099 wxWindow
*wxGetActiveWindow()
1105 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1112 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1115 wxFrame
*frame
= (wxFrame
*)this;
1116 Widget widget
= (Widget
) frame
->GetShellWidget();
1119 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1121 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1123 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1125 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1127 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1129 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1132 void wxWindow::Centre(int direction
)
1134 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1136 wxWindow
*father
= (wxWindow
*)GetParent();
1140 father
->GetClientSize(&panel_width
, &panel_height
);
1141 GetSize(&width
, &height
);
1142 GetPosition(&x
, &y
);
1147 if (direction
& wxHORIZONTAL
)
1148 new_x
= (int)((panel_width
- width
)/2);
1150 if (direction
& wxVERTICAL
)
1151 new_y
= (int)((panel_height
- height
)/2);
1153 SetSize(new_x
, new_y
, -1, -1);
1157 // Coordinates relative to the window
1158 void wxWindow::WarpPointer (int x
, int y
)
1160 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1163 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1169 int wxWindow::GetScrollPos(int orient
) const
1171 if (orient
== wxHORIZONTAL
)
1172 return m_scrollPosX
;
1174 return m_scrollPosY
;
1176 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1180 XtVaGetValues(scrollBar,
1181 XmNvalue, &pos, NULL);
1189 // This now returns the whole range, not just the number
1190 // of positions that we can scroll.
1191 int wxWindow::GetScrollRange(int orient
) const
1193 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1197 XtVaGetValues(scrollBar
,
1198 XmNmaximum
, &range
, NULL
);
1205 int wxWindow::GetScrollThumb(int orient
) const
1207 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1211 XtVaGetValues(scrollBar
,
1212 XmNsliderSize
, &thumb
, NULL
);
1219 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1221 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1224 XtVaSetValues (scrollBar
,
1228 if (orient
== wxHORIZONTAL
)
1235 // New function that will replace some of the above.
1236 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1237 int range
, bool WXUNUSED(refresh
))
1240 GetSize(& oldW
, & oldH
);
1244 if (thumbVisible
== 0)
1247 if (thumbVisible
> range
)
1248 thumbVisible
= range
;
1250 // Save the old state to see if it changed
1251 WXWidget oldScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1253 if (orient
== wxHORIZONTAL
)
1255 if (thumbVisible
== range
)
1258 DestroyScrollbar(wxHORIZONTAL
);
1263 CreateScrollbar(wxHORIZONTAL
);
1266 if (orient
== wxVERTICAL
)
1268 if (thumbVisible
== range
)
1271 DestroyScrollbar(wxVERTICAL
);
1276 CreateScrollbar(wxVERTICAL
);
1279 WXWidget newScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1281 if (oldScrollBar
!= newScrollBar
)
1283 // This is important! Without it, scrollbars misbehave
1285 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
1286 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
1287 XtRealizeWidget((Widget
) m_scrolledWindow
);
1288 XtManageChild((Widget
) m_scrolledWindow
);
1292 XtVaSetValues((Widget
) newScrollBar
,
1296 XmNsliderSize
, thumbVisible
,
1299 if (orient
== wxHORIZONTAL
)
1305 GetSize(& newW
, & newH
);
1307 // Adjusting scrollbars can resize the canvas accidentally
1308 if (newW
!= oldW
|| newH
!= oldH
)
1309 SetSize(-1, -1, oldW
, oldH
);
1312 // Does a physical scroll
1313 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1315 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1319 // Use specified rectangle
1320 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1324 // Use whole client area
1326 GetClientSize(& w
, & h
);
1329 int x1
= (dx
>= 0) ? x
: x
- dx
;
1330 int y1
= (dy
>= 0) ? y
: y
- dy
;
1331 int w1
= w
- abs(dx
);
1332 int h1
= h
- abs(dy
);
1333 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1334 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1336 wxClientDC
dc(this);
1338 dc
.SetLogicalFunction (wxCOPY
);
1340 Widget widget
= (Widget
) GetMainWidget();
1341 Window window
= XtWindow(widget
);
1342 Display
* display
= XtDisplay(widget
);
1344 XCopyArea(display
, window
,
1345 window
, (GC
) dc
.GetGC(),
1350 dc
.SetAutoSetting(TRUE
);
1351 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1352 dc
.SetBrush(brush
); // ??
1354 // We'll add rectangles to the list of update rectangles
1355 // according to which bits we've exposed.
1360 wxRect
*rect
= new wxRect
;
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
);
1378 wxRect
*rect
= new wxRect
;
1380 rect
->x
= x
+ w
+ dx
;
1385 XFillRectangle(display
, window
,
1386 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1391 rect
->width
= rect
->width
;
1392 rect
->height
= rect
->height
;
1394 updateRects
.Append((wxObject
*) rect
);
1398 wxRect
*rect
= new wxRect
;
1405 XFillRectangle(display
, window
,
1406 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1410 rect
->width
= rect
->width
;
1411 rect
->height
= rect
->height
;
1413 updateRects
.Append((wxObject
*) rect
);
1417 wxRect
*rect
= new wxRect
;
1420 rect
->y
= y
+ h
+ dy
;
1424 XFillRectangle(display
, window
,
1425 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1429 rect
->width
= rect
->width
;
1430 rect
->height
= rect
->height
;
1432 updateRects
.Append((wxObject
*) rect
);
1434 dc
.SetBrush(wxNullBrush
);
1436 // Now send expose events
1438 wxNode
* node
= updateRects
.First();
1441 wxRect
* rect
= (wxRect
*) node
->Data();
1444 event
.type
= Expose
;
1445 event
.display
= display
;
1446 event
.send_event
= True
;
1447 event
.window
= window
;
1451 event
.width
= rect
->width
;
1452 event
.height
= rect
->height
;
1456 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1458 node
= node
->Next();
1462 // Delete the update rects
1463 node
= updateRects
.First();
1466 wxRect
* rect
= (wxRect
*) node
->Data();
1468 node
= node
->Next();
1473 void wxWindow::OnChar(wxKeyEvent
& event
)
1475 if ( event
.KeyCode() == WXK_TAB
) {
1476 // propagate the TABs to the parent - it's up to it to decide what
1478 if ( GetParent() ) {
1479 if ( GetParent()->ProcessEvent(event
) )
1485 void wxWindow::OnPaint(wxPaintEvent
& event
)
1490 bool wxWindow::IsEnabled() const
1492 // TODO. Is this right?
1493 // return XtGetSensitive((Widget) GetMainWidget());
1497 // Dialog support: override these and call
1498 // base class members to add functionality
1499 // that can't be done using validators.
1500 // NOTE: these functions assume that controls
1501 // are direct children of this window, not grandchildren
1502 // or other levels of descendant.
1504 // Transfer values to controls. If returns FALSE,
1505 // it's an application error (pops up a dialog)
1506 bool wxWindow::TransferDataToWindow()
1508 wxNode
*node
= GetChildren().First();
1511 wxWindow
*child
= (wxWindow
*)node
->Data();
1512 if ( child
->GetValidator() &&
1513 !child
->GetValidator()->TransferToWindow() )
1515 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1519 node
= node
->Next();
1524 // Transfer values from controls. If returns FALSE,
1525 // validation failed: don't quit
1526 bool wxWindow::TransferDataFromWindow()
1528 wxNode
*node
= GetChildren().First();
1531 wxWindow
*child
= (wxWindow
*)node
->Data();
1532 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1537 node
= node
->Next();
1542 bool wxWindow::Validate()
1544 wxNode
*node
= GetChildren().First();
1547 wxWindow
*child
= (wxWindow
*)node
->Data();
1548 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1553 node
= node
->Next();
1558 // Get the window with the focus
1559 wxWindow
*wxWindow::FindFocus()
1565 void wxWindow::AddChild(wxWindow
*child
)
1567 GetChildren().Append(child
);
1568 child
->m_windowParent
= this;
1571 void wxWindow::RemoveChild(wxWindow
*child
)
1573 GetChildren().DeleteObject(child
);
1574 child
->m_windowParent
= NULL
;
1577 // Reparents this window to have the new parent.
1578 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1580 // For now, we indicate that this isn't implemented.
1584 void wxWindow::DestroyChildren()
1586 wxNode
*node
= GetChildren().First();
1589 wxNode
* next
= node
->Next();
1590 wxWindow
* child
= (wxWindow
*) node
->Data();
1594 GetChildren().Clear();
1597 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1599 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1601 if ( GetChildren().Member(child
) )
1608 void wxWindow::MakeModal(bool modal
)
1610 // Disable all other windows
1611 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1613 wxNode
*node
= wxTopLevelWindows
.First();
1616 wxWindow
*win
= (wxWindow
*)node
->Data();
1618 win
->Enable(!modal
);
1620 node
= node
->Next();
1625 // If nothing defined for this, try the parent.
1626 // E.g. we may be a button loaded from a resource, with no callback function
1628 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1630 if (GetEventHandler()->ProcessEvent(event
) )
1633 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1636 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1640 UnsetConstraints(m_constraints
);
1641 delete m_constraints
;
1646 // Make sure other windows know they're part of a 'meaningful relationship'
1647 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1648 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1649 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1650 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1651 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1652 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1653 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1654 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1655 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1656 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1657 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1658 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1659 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1660 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1661 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1662 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1666 // This removes any dangling pointers to this window
1667 // in other windows' constraintsInvolvedIn lists.
1668 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1672 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1673 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1674 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1675 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1676 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1677 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1678 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1679 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1680 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1681 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1682 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1683 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1684 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1685 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1686 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1687 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1691 // Back-pointer to other windows we're involved with, so if we delete
1692 // this window, we must delete any constraints we're involved with.
1693 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1695 if (!m_constraintsInvolvedIn
)
1696 m_constraintsInvolvedIn
= new wxList
;
1697 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1698 m_constraintsInvolvedIn
->Append(otherWin
);
1701 // REMOVE back-pointer to other windows we're involved with.
1702 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1704 if (m_constraintsInvolvedIn
)
1705 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1708 // Reset any constraints that mention this window
1709 void wxWindow::DeleteRelatedConstraints()
1711 if (m_constraintsInvolvedIn
)
1713 wxNode
*node
= m_constraintsInvolvedIn
->First();
1716 wxWindow
*win
= (wxWindow
*)node
->Data();
1717 wxNode
*next
= node
->Next();
1718 wxLayoutConstraints
*constr
= win
->GetConstraints();
1720 // Reset any constraints involving this window
1723 constr
->left
.ResetIfWin((wxWindow
*)this);
1724 constr
->top
.ResetIfWin((wxWindow
*)this);
1725 constr
->right
.ResetIfWin((wxWindow
*)this);
1726 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1727 constr
->width
.ResetIfWin((wxWindow
*)this);
1728 constr
->height
.ResetIfWin((wxWindow
*)this);
1729 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1730 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1735 delete m_constraintsInvolvedIn
;
1736 m_constraintsInvolvedIn
= NULL
;
1740 void wxWindow::SetSizer(wxSizer
*sizer
)
1742 m_windowSizer
= sizer
;
1744 sizer
->SetSizerParent((wxWindow
*)this);
1751 bool wxWindow::Layout()
1753 if (GetConstraints())
1756 GetClientSize(&w
, &h
);
1757 GetConstraints()->width
.SetValue(w
);
1758 GetConstraints()->height
.SetValue(h
);
1761 // If top level (one sizer), evaluate the sizer's constraints.
1765 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1766 GetSizer()->LayoutPhase1(&noChanges
);
1767 GetSizer()->LayoutPhase2(&noChanges
);
1768 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1773 // Otherwise, evaluate child constraints
1774 ResetConstraints(); // Mark all constraints as unevaluated
1775 DoPhase(1); // Just one phase need if no sizers involved
1777 SetConstraintSizes(); // Recursively set the real window sizes
1783 // Do a phase of evaluating constraints:
1784 // the default behaviour. wxSizers may do a similar
1785 // thing, but also impose their own 'constraints'
1786 // and order the evaluation differently.
1787 bool wxWindow::LayoutPhase1(int *noChanges
)
1789 wxLayoutConstraints
*constr
= GetConstraints();
1792 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1798 bool wxWindow::LayoutPhase2(int *noChanges
)
1808 // Do a phase of evaluating child constraints
1809 bool wxWindow::DoPhase(int phase
)
1811 int noIterations
= 0;
1812 int maxIterations
= 500;
1816 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1820 wxNode
*node
= GetChildren().First();
1823 wxWindow
*child
= (wxWindow
*)node
->Data();
1824 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1826 wxLayoutConstraints
*constr
= child
->GetConstraints();
1829 if (succeeded
.Member(child
))
1834 int tempNoChanges
= 0;
1835 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1836 noChanges
+= tempNoChanges
;
1839 succeeded
.Append(child
);
1844 node
= node
->Next();
1851 void wxWindow::ResetConstraints()
1853 wxLayoutConstraints
*constr
= GetConstraints();
1856 constr
->left
.SetDone(FALSE
);
1857 constr
->top
.SetDone(FALSE
);
1858 constr
->right
.SetDone(FALSE
);
1859 constr
->bottom
.SetDone(FALSE
);
1860 constr
->width
.SetDone(FALSE
);
1861 constr
->height
.SetDone(FALSE
);
1862 constr
->centreX
.SetDone(FALSE
);
1863 constr
->centreY
.SetDone(FALSE
);
1865 wxNode
*node
= GetChildren().First();
1868 wxWindow
*win
= (wxWindow
*)node
->Data();
1869 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1870 win
->ResetConstraints();
1871 node
= node
->Next();
1875 // Need to distinguish between setting the 'fake' size for
1876 // windows and sizers, and setting the real values.
1877 void wxWindow::SetConstraintSizes(bool recurse
)
1879 wxLayoutConstraints
*constr
= GetConstraints();
1880 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1881 constr
->width
.GetDone() && constr
->height
.GetDone())
1883 int x
= constr
->left
.GetValue();
1884 int y
= constr
->top
.GetValue();
1885 int w
= constr
->width
.GetValue();
1886 int h
= constr
->height
.GetValue();
1888 // If we don't want to resize this window, just move it...
1889 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1890 (constr
->height
.GetRelationship() != wxAsIs
))
1892 // Calls Layout() recursively. AAAGH. How can we stop that.
1893 // Simply take Layout() out of non-top level OnSizes.
1894 SizerSetSize(x
, y
, w
, h
);
1903 char *windowClass
= this->GetClassInfo()->GetClassName();
1906 if (GetName() == "")
1907 winName
= "unnamed";
1909 winName
= GetName();
1910 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1911 if (!constr
->left
.GetDone())
1912 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1913 if (!constr
->right
.GetDone())
1914 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1915 if (!constr
->width
.GetDone())
1916 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1917 if (!constr
->height
.GetDone())
1918 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1919 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1924 wxNode
*node
= GetChildren().First();
1927 wxWindow
*win
= (wxWindow
*)node
->Data();
1928 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1929 win
->SetConstraintSizes();
1930 node
= node
->Next();
1935 // This assumes that all sizers are 'on' the same
1936 // window, i.e. the parent of this window.
1937 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1939 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1940 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1944 m_sizerParent
->GetPosition(&xp
, &yp
);
1945 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1950 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1954 TransformSizerToActual(&xx
, &yy
);
1955 SetSize(xx
, yy
, w
, h
);
1958 void wxWindow::SizerMove(int x
, int y
)
1962 TransformSizerToActual(&xx
, &yy
);
1966 // Only set the size/position of the constraint (if any)
1967 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1969 wxLayoutConstraints
*constr
= GetConstraints();
1974 constr
->left
.SetValue(x
);
1975 constr
->left
.SetDone(TRUE
);
1979 constr
->top
.SetValue(y
);
1980 constr
->top
.SetDone(TRUE
);
1984 constr
->width
.SetValue(w
);
1985 constr
->width
.SetDone(TRUE
);
1989 constr
->height
.SetValue(h
);
1990 constr
->height
.SetDone(TRUE
);
1995 void wxWindow::MoveConstraint(int x
, int y
)
1997 wxLayoutConstraints
*constr
= GetConstraints();
2002 constr
->left
.SetValue(x
);
2003 constr
->left
.SetDone(TRUE
);
2007 constr
->top
.SetValue(y
);
2008 constr
->top
.SetDone(TRUE
);
2013 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2015 wxLayoutConstraints
*constr
= GetConstraints();
2018 *w
= constr
->width
.GetValue();
2019 *h
= constr
->height
.GetValue();
2025 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2027 wxLayoutConstraints
*constr
= GetConstraints();
2030 *w
= constr
->width
.GetValue();
2031 *h
= constr
->height
.GetValue();
2034 GetClientSize(w
, h
);
2037 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2039 wxLayoutConstraints
*constr
= GetConstraints();
2042 *x
= constr
->left
.GetValue();
2043 *y
= constr
->top
.GetValue();
2049 bool wxWindow::Close(bool force
)
2051 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2052 event
.SetEventObject(this);
2053 event
.SetForce(force
);
2055 return GetEventHandler()->ProcessEvent(event
);
2058 wxObject
* wxWindow::GetChild(int number
) const
2060 // Return a pointer to the Nth object in the window
2061 wxNode
*node
= GetChildren().First();
2064 node
= node
->Next() ;
2067 wxObject
*obj
= (wxObject
*)node
->Data();
2074 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2076 // Obsolete function
2079 void wxWindow::Clear()
2081 wxClientDC
dc(this);
2082 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2083 dc
.SetBackground(brush
);
2087 // Fits the panel around the items
2088 void wxWindow::Fit()
2092 wxNode
*node
= GetChildren().First();
2095 wxWindow
*win
= (wxWindow
*)node
->Data();
2097 win
->GetPosition(&wx
, &wy
);
2098 win
->GetSize(&ww
, &wh
);
2099 if ( wx
+ ww
> maxX
)
2101 if ( wy
+ wh
> maxY
)
2104 node
= node
->Next();
2106 SetClientSize(maxX
+ 5, maxY
+ 5);
2109 void wxWindow::SetValidator(const wxValidator
& validator
)
2111 if ( m_windowValidator
)
2112 delete m_windowValidator
;
2113 m_windowValidator
= validator
.Clone();
2115 if ( m_windowValidator
)
2116 m_windowValidator
->SetWindow(this) ;
2119 void wxWindow::SetClientObject( wxClientData
*data
)
2121 if (m_clientObject
) delete m_clientObject
;
2122 m_clientObject
= data
;
2125 wxClientData
*wxWindow::GetClientObject()
2127 return m_clientObject
;
2130 void wxWindow::SetClientData( void *data
)
2132 m_clientData
= data
;
2135 void *wxWindow::GetClientData()
2137 return m_clientData
;
2140 // Find a window by id or name
2141 wxWindow
*wxWindow::FindWindow(long id
)
2146 wxNode
*node
= GetChildren().First();
2149 wxWindow
*child
= (wxWindow
*)node
->Data();
2150 wxWindow
*found
= child
->FindWindow(id
);
2153 node
= node
->Next();
2158 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2160 if ( GetName() == name
)
2163 wxNode
*node
= GetChildren().First();
2166 wxWindow
*child
= (wxWindow
*)node
->Data();
2167 wxWindow
*found
= child
->FindWindow(name
);
2170 node
= node
->Next();
2175 void wxWindow::OnIdle(wxIdleEvent
& event
)
2177 // This calls the UI-update mechanism (querying windows for
2178 // menu/toolbar/control state information)
2182 // Raise the window to the top of the Z order
2183 void wxWindow::Raise()
2185 Window window
= XtWindow((Widget
) GetTopWidget());
2186 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2189 // Lower the window to the bottom of the Z order
2190 void wxWindow::Lower()
2192 Window window
= XtWindow((Widget
) GetTopWidget());
2193 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2196 bool wxWindow::AcceptsFocus() const
2198 return IsShown() && IsEnabled();
2201 // Update region access
2202 wxRegion
& wxWindow::GetUpdateRegion() const
2204 return (wxRegion
&) m_updateRegion
;
2207 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2209 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2212 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2214 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2217 bool wxWindow::IsExposed(const wxRect
& rect
) const
2219 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2223 * Allocates control IDs
2226 int wxWindow::NewControlId()
2228 static int s_controlId
= 0;
2233 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2235 m_acceleratorTable
= accel
;
2238 // All widgets should have this as their resize proc.
2239 // OnSize sent to wxWindow via client data.
2240 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2242 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2246 if (win
->PreResize())
2249 win
->GetSize(&width
, &height
);
2250 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2251 sizeEvent
.SetEventObject(win
);
2252 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2256 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2258 wxWindow
*oldItem
= NULL
;
2259 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2260 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2263 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2266 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2271 wxWidgetHashTable
->Put ((long) w
, win
);
2275 wxWindow
*wxGetWindowFromTable(Widget w
)
2277 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2280 void wxDeleteWindowFromTable(Widget w
)
2282 wxWidgetHashTable
->Delete((long)w
);
2285 // Get the underlying X window and display
2286 WXWindow
wxWindow::GetXWindow() const
2288 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2291 WXDisplay
*wxWindow::GetXDisplay() const
2293 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2296 WXWidget
wxWindow::GetMainWidget() const
2299 return m_drawingArea
;
2301 return m_mainWidget
;
2304 WXWidget
wxWindow::GetClientWidget() const
2306 if (m_drawingArea
!= (WXWidget
) 0)
2307 return m_drawingArea
;
2309 return GetMainWidget();
2312 WXWidget
wxWindow::GetTopWidget() const
2314 return GetMainWidget();
2317 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2318 XmDrawingAreaCallbackStruct
* cbs
)
2320 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2323 XEvent
* event
= cbs
->event
;
2324 wxWindow
* win
= (wxWindow
*) clientData
;
2325 Display
* display
= (Display
*) win
->GetXDisplay();
2327 switch (event
->type
)
2331 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2332 event
->xexpose
.width
, event
->xexpose
.height
);
2334 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2335 cout << rect->width << ", " << rect->height << "\n\n";
2338 win
->m_updateRects
.Append((wxObject
*) rect
);
2340 if (event
-> xexpose
.count
== 0)
2342 wxPaintEvent
event(win
->GetId());
2343 event
.SetEventObject(win
);
2344 win
->GetEventHandler()->ProcessEvent(event
);
2346 win
->ClearUpdateRects();
2352 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2358 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2360 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2362 XmDrawingAreaCallbackStruct cbs
;
2365 //if (event->mode!=NotifyNormal)
2368 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2369 ((XCrossingEvent
&) ev
) = *event
;
2371 cbs
.reason
= XmCR_INPUT
;
2374 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2377 // Fix to make it work under Motif 1.0 (!)
2378 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2382 XmDrawingAreaCallbackStruct cbs
;
2385 //ev.xbutton = *event;
2386 ev
= *((XEvent
*) event
);
2387 cbs
.reason
= XmCR_INPUT
;
2390 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2394 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2396 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2402 if (cbs
->reason
!= XmCR_INPUT
)
2405 local_event
= *(cbs
->event
); // We must keep a copy!
2408 switch (local_event.xany.type)
2411 cout << "EnterNotify\n";
2414 cout << "LeaveNotify\n";
2417 cout << "ButtonPress\n";
2420 cout << "ButtonRelease\n";
2423 cout << "MotionNotify\n";
2426 cout << "Something else\n";
2431 switch (local_event
.xany
.type
)
2439 wxEventType eventType
= wxEVT_NULL
;
2441 if (local_event
.xany
.type
== EnterNotify
)
2443 //if (local_event.xcrossing.mode!=NotifyNormal)
2444 // return ; // Ignore grab events
2445 eventType
= wxEVT_ENTER_WINDOW
;
2446 // canvas->GetEventHandler()->OnSetFocus();
2448 else if (local_event
.xany
.type
== LeaveNotify
)
2450 //if (local_event.xcrossing.mode!=NotifyNormal)
2451 // return ; // Ignore grab events
2452 eventType
= wxEVT_LEAVE_WINDOW
;
2453 // canvas->GetEventHandler()->OnKillFocus();
2455 else if (local_event
.xany
.type
== MotionNotify
)
2457 eventType
= wxEVT_MOTION
;
2458 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2461 Display
*dpy
= XtDisplay (drawingArea
);
2463 XQueryPointer (dpy
, XtWindow (drawingArea
),
2465 &local_event
.xmotion
.x_root
,
2466 &local_event
.xmotion
.y_root
,
2467 &local_event
.xmotion
.x
,
2468 &local_event
.xmotion
.y
,
2469 &local_event
.xmotion
.state
);
2476 else if (local_event
.xany
.type
== ButtonPress
)
2478 if (local_event
.xbutton
.button
== Button1
)
2480 eventType
= wxEVT_LEFT_DOWN
;
2481 canvas
->m_button1Pressed
= TRUE
;
2483 else if (local_event
.xbutton
.button
== Button2
)
2485 eventType
= wxEVT_MIDDLE_DOWN
;
2486 canvas
->m_button2Pressed
= TRUE
;
2488 else if (local_event
.xbutton
.button
== Button3
)
2490 eventType
= wxEVT_RIGHT_DOWN
;
2491 canvas
->m_button3Pressed
= TRUE
;
2494 else if (local_event
.xany
.type
== ButtonRelease
)
2496 if (local_event
.xbutton
.button
== Button1
)
2498 eventType
= wxEVT_LEFT_UP
;
2499 canvas
->m_button1Pressed
= FALSE
;
2501 else if (local_event
.xbutton
.button
== Button2
)
2503 eventType
= wxEVT_MIDDLE_UP
;
2504 canvas
->m_button2Pressed
= FALSE
;
2506 else if (local_event
.xbutton
.button
== Button3
)
2508 eventType
= wxEVT_RIGHT_UP
;
2509 canvas
->m_button3Pressed
= FALSE
;
2513 wxMouseEvent
wxevent (eventType
);
2514 wxevent
.m_eventHandle
= (char *) &local_event
;
2516 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2517 || (event_left_is_down (&local_event
)
2518 && (eventType
!= wxEVT_LEFT_UP
)));
2519 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2520 || (event_middle_is_down (&local_event
)
2521 && (eventType
!= wxEVT_MIDDLE_UP
)));
2522 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2523 || (event_right_is_down (&local_event
)
2524 && (eventType
!= wxEVT_RIGHT_UP
)));
2526 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2527 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2528 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2529 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2530 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2532 // Now check if we need to translate this event into a double click
2533 if (TRUE
) // canvas->doubleClickAllowed)
2535 if (wxevent
.ButtonDown())
2537 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2539 // get button and time-stamp
2541 if (wxevent
.LeftDown()) button
= 1;
2542 else if (wxevent
.MiddleDown()) button
= 2;
2543 else if (wxevent
.RightDown()) button
= 3;
2544 long ts
= wxevent
.GetTimestamp();
2545 // check, if single or double click
2546 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2549 canvas
->m_lastButton
= 0;
2550 switch ( eventType
)
2552 case wxEVT_LEFT_DOWN
:
2553 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2555 case wxEVT_MIDDLE_DOWN
:
2556 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2558 case wxEVT_RIGHT_DOWN
:
2559 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2569 // not fast enough or different button
2570 canvas
->m_lastTS
= ts
;
2571 canvas
->m_lastButton
= button
;
2576 wxevent
.SetId(canvas
->GetId());
2577 wxevent
.SetEventObject(canvas
);
2578 wxevent
.m_x
= local_event
.xbutton
.x
;
2579 wxevent
.m_y
= local_event
.xbutton
.y
;
2580 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2582 if (eventType == wxEVT_ENTER_WINDOW ||
2583 eventType == wxEVT_LEAVE_WINDOW ||
2584 eventType == wxEVT_MOTION
2593 // XComposeStatus compose;
2594 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2595 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2596 int id
= wxCharCodeXToWX (keySym
);
2598 wxKeyEvent
event (wxEVT_CHAR
);
2600 if (local_event
.xkey
.state
& ShiftMask
)
2601 event
.m_shiftDown
= TRUE
;
2602 if (local_event
.xkey
.state
& ControlMask
)
2603 event
.m_controlDown
= TRUE
;
2604 if (local_event
.xkey
.state
& Mod3Mask
)
2605 event
.m_altDown
= TRUE
;
2606 if (local_event
.xkey
.state
& Mod1Mask
)
2607 event
.m_metaDown
= TRUE
;
2608 event
.SetEventObject(canvas
);
2609 event
.m_keyCode
= id
;
2610 event
.SetTimestamp(local_event
.xkey
.time
);
2614 // Implement wxFrame::OnCharHook by checking ancestor.
2615 wxWindow
*parent
= canvas
->GetParent();
2616 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2617 parent
= parent
->GetParent();
2621 event
.SetEventType(wxEVT_CHAR_HOOK
);
2622 if (parent
->GetEventHandler()->ProcessEvent(event
))
2624 event
.SetEventType(wxEVT_CHAR
);
2627 canvas
->GetEventHandler()->ProcessEvent (event
);
2633 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2635 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2636 event
.SetEventObject(canvas
);
2637 canvas
->GetEventHandler()->ProcessEvent(event
);
2643 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2645 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2646 event
.SetEventObject(canvas
);
2647 canvas
->GetEventHandler()->ProcessEvent(event
);
2656 void wxWindow::DoPaint()
2658 //TODO : make a temporary gc so we can do the XCopyArea below
2659 if (0) // m_backingPixmap)
2662 Widget drawingArea = (Widget) m_drawingArea;
2663 // int orig = GetDC()->GetLogicalFunction();
2664 // GetDC()->SetLogicalFunction (wxCOPY);
2666 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2667 // should be able to calculate them.
2668 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2669 m_pixmapOffsetX, m_pixmapOffsetY,
2670 m_pixmapWidth, m_pixmapHeight,
2673 // GetDC()->SetLogicalFunction (orig);
2678 wxPaintEvent
event(GetId());
2679 event
.SetEventObject(this);
2680 GetEventHandler()->ProcessEvent(event
);
2684 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2685 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2687 // A bit of optimization to help sort out the flickers.
2688 int oldX
, oldY
, oldW
, oldH
;
2689 GetSize(& oldW
, & oldH
);
2690 GetPosition(& oldX
, & oldY
);
2692 bool useOldPos
= FALSE
;
2693 bool useOldSize
= FALSE
;
2695 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2697 else if (x
== oldX
&& y
== oldY
)
2700 if ((w
== -1) && (h
== -1))
2702 else if (w
== oldW
&& h
== oldH
)
2705 if (!wxNoOptimize::CanOptimize())
2707 useOldSize
= FALSE
; useOldPos
= FALSE
;
2710 if (useOldPos
&& useOldSize
)
2713 Widget drawingArea
= (Widget
) m_drawingArea
;
2714 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2717 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2718 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2720 int xx
= x
; int yy
= y
;
2721 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2725 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2727 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2731 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2733 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2745 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2746 short thick
, margin
;
2747 XtVaGetValues ((Widget
) m_borderWidget
,
2748 XmNshadowThickness
, &thick
,
2749 XmNmarginWidth
, &margin
,
2751 w
-= 2 * (thick
+ margin
);
2754 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2758 XtVaGetValues ((Widget
) m_scrolledWindow
,
2759 XmNspacing
, &spacing
,
2760 XmNverticalScrollBar
, &sbar
,
2764 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2768 w
-= (spacing
+ wsbar
);
2770 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2776 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2777 short thick
, margin
;
2778 XtVaGetValues ((Widget
) m_borderWidget
,
2779 XmNshadowThickness
, &thick
,
2780 XmNmarginHeight
, &margin
,
2782 h
-= 2 * (thick
+ margin
);
2785 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2789 XtVaGetValues ((Widget
) m_scrolledWindow
,
2790 XmNspacing
, &spacing
,
2791 XmNhorizontalScrollBar
, &sbar
,
2795 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2799 h
-= (spacing
+ wsbar
);
2801 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2807 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2808 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2812 GetClientSize (&ww, &hh);
2813 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2814 sizeEvent.SetEventObject(this);
2816 GetEventHandler()->ProcessEvent(sizeEvent);
2821 void wxWindow::CanvasSetClientSize (int w
, int h
)
2823 Widget drawingArea
= (Widget
) m_drawingArea
;
2825 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2828 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2830 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2831 /* TODO: is this necessary?
2832 allowRepainting = FALSE;
2834 XSync (XtDisplay (drawingArea), FALSE);
2836 while (XtAppPending (wxTheApp->appContext))
2838 XFlush (XtDisplay (drawingArea));
2839 XtAppNextEvent (wxTheApp->appContext, &event);
2840 XtDispatchEvent (&event);
2844 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2847 allowRepainting = TRUE;
2852 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2853 sizeEvent.SetEventObject(this);
2855 GetEventHandler()->ProcessEvent(sizeEvent);
2859 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2861 // Must return the same thing that was set via SetClientSize
2863 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2868 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2871 if ((Widget
) m_borderWidget
)
2872 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2873 else if ((Widget
) m_scrolledWindow
)
2874 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2876 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2882 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2885 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2887 // We may be faking the client origin.
2888 // So a window that's really at (0, 30) may appear
2889 // (to wxWin apps) to be at (0, 0).
2892 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2901 // Add to hash table, add event handler
2902 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2903 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2905 wxAddWindowToTable((Widget
) mainWidget
, this);
2906 if (CanAddEventHandler())
2908 XtAddEventHandler((Widget
) mainWidget
,
2909 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2911 wxPanelItemEventHandler
,
2918 XtOverrideTranslations ((Widget
) mainWidget
,
2919 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2920 XtFree ((char *) ptr
);
2923 // Some widgets have a parent form widget, e.g. wxRadioBox
2926 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2930 XtOverrideTranslations ((Widget
) formWidget
,
2931 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2932 XtFree ((char *) ptr
);
2939 SetSize (x
, y
, width
, height
);
2944 // Remove event handler, remove from hash table
2945 bool wxWindow::DetachWidget(WXWidget widget
)
2947 if (CanAddEventHandler())
2949 XtRemoveEventHandler((Widget
) widget
,
2950 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2952 wxPanelItemEventHandler
,
2956 wxDeleteWindowFromTable((Widget
) widget
);
2960 void wxPanelItemEventHandler (Widget wid
,
2961 XtPointer client_data
,
2963 Boolean
*continueToDispatch
)
2965 // Widget can be a label or the actual widget.
2967 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2970 wxMouseEvent
wxevent(0);
2971 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2973 window
->GetEventHandler()->ProcessEvent(wxevent
);
2976 // TODO: probably the key to allowing default behaviour
2978 // Say we set a m_doDefault flag to FALSE at the start of this
2979 // function. Then in e.g. wxWindow::OnMouseEvent we can
2980 // call Default() which sets this flag to TRUE, indicating
2981 // that default processing can happen. Thus, behaviour can appear
2982 // to be overridden just by adding an event handler and not calling
2983 // wxWindow::OnWhatever.
2984 // ALSO, maybe we can use this instead of the current way of handling
2985 // drawing area events, to simplify things.
2986 *continueToDispatch
= True
;
2989 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2990 XmScaleCallbackStruct
*cbs
)
2992 Widget scrolledWindow
= XtParent (scrollbar
);
2993 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2994 int orientation
= (int) clientData
;
2996 wxEventType eventType
= wxEVT_NULL
;
2997 switch (cbs
->reason
)
2999 case XmCR_INCREMENT
:
3001 eventType
= wxEVT_SCROLL_LINEDOWN
;
3004 case XmCR_DECREMENT
:
3006 eventType
= wxEVT_SCROLL_LINEUP
;
3011 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3014 case XmCR_VALUE_CHANGED
:
3016 // TODO: Should this be intercepted too, or will it cause
3017 // duplicate events?
3018 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3021 case XmCR_PAGE_INCREMENT
:
3023 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3026 case XmCR_PAGE_DECREMENT
:
3028 eventType
= wxEVT_SCROLL_PAGEUP
;
3033 eventType
= wxEVT_SCROLL_TOP
;
3036 case XmCR_TO_BOTTOM
:
3038 eventType
= wxEVT_SCROLL_BOTTOM
;
3043 // Should never get here
3044 wxFAIL_MSG("Unknown scroll event.");
3049 wxScrollEvent
event(eventType
, win
->GetId());
3050 event
.SetEventObject(win
);
3051 event
.SetPosition(cbs
->value
);
3052 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3054 win
->GetEventHandler()->ProcessEvent(event
);
3057 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3059 switch (xevent
->xany
.type
)
3067 wxEventType eventType
= wxEVT_NULL
;
3069 if (xevent
->xany
.type
== LeaveNotify
)
3071 win
->m_button1Pressed
= FALSE
;
3072 win
->m_button2Pressed
= FALSE
;
3073 win
->m_button3Pressed
= FALSE
;
3076 else if (xevent
->xany
.type
== MotionNotify
)
3078 eventType
= wxEVT_MOTION
;
3080 else if (xevent
->xany
.type
== ButtonPress
)
3082 if (xevent
->xbutton
.button
== Button1
)
3084 eventType
= wxEVT_LEFT_DOWN
;
3085 win
->m_button1Pressed
= TRUE
;
3087 else if (xevent
->xbutton
.button
== Button2
)
3089 eventType
= wxEVT_MIDDLE_DOWN
;
3090 win
->m_button2Pressed
= TRUE
;
3092 else if (xevent
->xbutton
.button
== Button3
)
3094 eventType
= wxEVT_RIGHT_DOWN
;
3095 win
->m_button3Pressed
= TRUE
;
3098 else if (xevent
->xany
.type
== ButtonRelease
)
3100 if (xevent
->xbutton
.button
== Button1
)
3102 eventType
= wxEVT_LEFT_UP
;
3103 win
->m_button1Pressed
= FALSE
;
3105 else if (xevent
->xbutton
.button
== Button2
)
3107 eventType
= wxEVT_MIDDLE_UP
;
3108 win
->m_button2Pressed
= FALSE
;
3110 else if (xevent
->xbutton
.button
== Button3
)
3112 eventType
= wxEVT_RIGHT_UP
;
3113 win
->m_button3Pressed
= FALSE
;
3119 wxevent
.m_eventHandle
= (char *)xevent
;
3120 wxevent
.SetEventType(eventType
);
3123 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3126 win
->GetPosition(&x2
, &y2
);
3128 // The button x/y must be translated to wxWindows
3129 // window space - the widget might be a label or button,
3133 if (widget
!= (Widget
)win
->GetMainWidget())
3139 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3140 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3142 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3143 || (event_left_is_down (xevent
)
3144 && (eventType
!= wxEVT_LEFT_UP
)));
3145 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3146 || (event_middle_is_down (xevent
)
3147 && (eventType
!= wxEVT_MIDDLE_UP
)));
3148 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3149 || (event_right_is_down (xevent
)
3150 && (eventType
!= wxEVT_RIGHT_UP
)));
3152 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3153 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3160 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3162 switch (xevent
->xany
.type
)
3169 // XComposeStatus compose;
3170 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3171 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3172 int id
= wxCharCodeXToWX (keySym
);
3174 if (xevent
->xkey
.state
& ShiftMask
)
3175 wxevent
.m_shiftDown
= TRUE
;
3176 if (xevent
->xkey
.state
& ControlMask
)
3177 wxevent
.m_controlDown
= TRUE
;
3178 if (xevent
->xkey
.state
& Mod3Mask
)
3179 wxevent
.m_altDown
= TRUE
;
3180 if (xevent
->xkey
.state
& Mod1Mask
)
3181 wxevent
.m_metaDown
= TRUE
;
3182 wxevent
.SetEventObject(win
);
3183 wxevent
.m_keyCode
= id
;
3184 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3186 wxevent
.m_x
= xevent
->xbutton
.x
;
3187 wxevent
.m_y
= xevent
->xbutton
.y
;
3201 #define YAllocColor XAllocColor
3202 XColor g_itemColors
[5];
3203 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3206 static XmColorProc colorProc
;
3208 result
= wxNO_COLORS
;
3212 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3213 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3214 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3215 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3216 if (colorProc
== (XmColorProc
) NULL
)
3218 // Get a ptr to the actual function
3219 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3220 // And set it back to motif.
3221 XmSetColorCalculation (colorProc
);
3223 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3224 &g_itemColors
[wxFORE_INDEX
],
3225 &g_itemColors
[wxSELE_INDEX
],
3226 &g_itemColors
[wxTOPS_INDEX
],
3227 &g_itemColors
[wxBOTS_INDEX
]);
3228 result
= wxBACK_COLORS
;
3232 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3233 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3234 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3235 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3236 if (result
== wxNO_COLORS
)
3237 result
= wxFORE_COLORS
;
3240 Display
*dpy
= display
;
3241 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3245 /* 5 Colours to allocate */
3246 for (int i
= 0; i
< 5; i
++)
3247 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3248 result
= wxNO_COLORS
;
3252 /* Only 1 colour to allocate */
3253 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3254 result
= wxNO_COLORS
;
3261 // Changes the foreground and background colours to be derived
3262 // from the current background colour.
3263 // To change the foreground colour, you must call SetForegroundColour
3265 void wxWindow::ChangeBackgroundColour()
3267 if (GetMainWidget())
3268 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3269 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3270 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3273 void wxWindow::ChangeForegroundColour()
3275 if (GetMainWidget())
3276 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3277 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3278 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3281 // Change a widget's foreground and background colours.
3283 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3285 // When should we specify the foreground, if it's calculated
3286 // by wxComputeColours?
3287 // Solution: say we start with the default (computed) foreground colour.
3288 // If we call SetForegroundColour explicitly for a control or window,
3289 // then the foreground is changed.
3290 // Therefore SetBackgroundColour computes the foreground colour, and
3291 // SetForegroundColour changes the foreground colour. The ordering is
3294 XtVaSetValues ((Widget
) widget
,
3295 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3299 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3301 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3304 XtVaSetValues ((Widget
) widget
,
3305 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3306 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3307 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3308 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3311 if (changeArmColour
)
3312 XtVaSetValues ((Widget
) widget
,
3313 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3317 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3319 m_backgroundColour
= col
;
3320 ChangeBackgroundColour();
3323 void wxWindow::SetForegroundColour(const wxColour
& col
)
3325 m_foregroundColour
= col
;
3326 ChangeForegroundColour();
3329 void wxWindow::ChangeFont(bool keepOriginalSize
)
3331 // Note that this causes the widget to be resized back
3332 // to its original size! We therefore have to set the size
3333 // back again. TODO: a better way in Motif?
3334 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3335 if (w
&& m_windowFont
.Ok())
3337 int width
, height
, width1
, height1
;
3338 GetSize(& width
, & height
);
3340 // lesstif 0.87 hangs here
3341 #ifndef LESSTIF_VERSION
3343 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3347 GetSize(& width1
, & height1
);
3348 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3350 SetSize(-1, -1, width
, height
);
3355 void wxWindow::SetFont(const wxFont
& font
)
3357 m_windowFont
= font
;
3361 void wxWindow::ClearUpdateRects()
3363 wxNode
* node
= m_updateRects
.First();
3366 wxRect
* rect
= (wxRect
*) node
->Data();
3368 node
= node
->Next();
3370 m_updateRects
.Clear();
3373 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3375 if (!m_acceleratorTable
.Ok())
3378 int count
= m_acceleratorTable
.GetCount();
3379 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3381 for (i
= 0; i
< count
; i
++)
3383 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3384 if (entry
->MatchesEvent(event
))
3386 // Bingo, we have a match. Now find a control
3387 // that matches the entry command id.
3389 // Need to go up to the top of the window hierarchy,
3390 // since it might be e.g. a menu item
3391 wxWindow
* parent
= this;
3392 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3393 parent
= parent
->GetParent();
3398 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3400 // Try for a menu command
3401 wxFrame
* frame
= (wxFrame
*) parent
;
3402 if (frame
->GetMenuBar())
3404 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3407 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3408 commandEvent
.SetEventObject(frame
);
3410 // If ProcessEvent returns TRUE (it was handled), then
3411 // the calling code will skip the event handling.
3412 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3417 // Find a child matching the command id
3418 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3424 // Now we process those kinds of windows that we can.
3425 // For now, only buttons.
3426 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3428 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3429 commandEvent
.SetEventObject(child
);
3430 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3437 // We didn't match the key event against an accelerator.
3442 * wxNoOptimize: switch off size optimization
3445 int wxNoOptimize::m_count
= 0;
3447 wxNoOptimize::wxNoOptimize()
3452 wxNoOptimize::~wxNoOptimize()
3457 bool wxNoOptimize::CanOptimize()
3459 return (m_count
== 0);