1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/menuitem.h"
34 #if wxUSE_DRAG_AND_DROP
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
46 #include "wx/motif/private.h"
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
52 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
54 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
55 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
56 XmScaleCallbackStruct
*cbs
);
57 void wxPanelItemEventHandler (Widget wid
,
58 XtPointer client_data
,
60 Boolean
*continueToDispatch
);
62 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
63 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
64 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
66 extern wxList wxPendingDelete
;
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
71 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
72 EVT_CHAR(wxWindow::OnChar
)
73 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
74 EVT_KEY_UP(wxWindow::OnKeyUp
)
75 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
76 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
77 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
78 EVT_IDLE(wxWindow::OnIdle
)
90 m_windowParent
= NULL
;
91 m_windowEventHandler
= this;
93 m_windowCursor
= *wxSTANDARD_CURSOR
;
94 m_children
= new wxList
;
96 m_constraintsInvolvedIn
= NULL
;
100 m_windowValidator
= NULL
;
101 m_defaultItem
= NULL
;
103 m_caretWidth
= 0; m_caretHeight
= 0;
104 m_caretEnabled
= FALSE
;
105 m_caretShown
= FALSE
;
106 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
107 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
108 m_foregroundColour
= *wxBLACK
;
110 #if wxUSE_DRAG_AND_DROP
111 m_pDropTarget
= NULL
;
113 m_clientObject
= (wxClientData
*) NULL
;
117 m_mainWidget
= (WXWidget
) 0;
118 m_button1Pressed
= FALSE
;
119 m_button2Pressed
= FALSE
;
120 m_button3Pressed
= FALSE
;
121 m_winCaptured
= FALSE
;
123 m_hScrollBar
= (WXWidget
) 0;
124 m_vScrollBar
= (WXWidget
) 0;
125 m_borderWidget
= (WXWidget
) 0;
126 m_scrolledWindow
= (WXWidget
) 0;
127 m_drawingArea
= (WXWidget
) 0;
130 m_backingPixmap
= (WXPixmap
) 0;
137 m_canAddEventHandler
= FALSE
;
143 wxWindow::~wxWindow()
148 DetachWidget(GetMainWidget()); // Removes event handlers
150 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
153 // Destroy children before destroying self
157 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
159 Widget w
= (Widget
) m_drawingArea
;
160 wxDeleteWindowFromTable(w
);
164 m_mainWidget
= (WXWidget
) 0;
166 // Only if we're _really_ a canvas (not a dialog box/panel)
167 if (m_scrolledWindow
)
169 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
174 XtUnmanageChild ((Widget
) m_hScrollBar
);
175 XtDestroyWidget ((Widget
) m_hScrollBar
);
179 XtUnmanageChild ((Widget
) m_vScrollBar
);
180 XtDestroyWidget ((Widget
) m_vScrollBar
);
182 if (m_scrolledWindow
)
184 XtUnmanageChild ((Widget
) m_scrolledWindow
);
185 XtDestroyWidget ((Widget
) m_scrolledWindow
);
190 XtDestroyWidget ((Widget
) m_borderWidget
);
191 m_borderWidget
= (WXWidget
) 0;
197 // Have to delete constraints/sizer FIRST otherwise
198 // sizers may try to look at deleted windows as they
199 // delete themselves.
200 #if wxUSE_CONSTRAINTS
201 DeleteRelatedConstraints();
204 // This removes any dangling pointers to this window
205 // in other windows' constraintsInvolvedIn lists.
206 UnsetConstraints(m_constraints
);
207 delete m_constraints
;
208 m_constraints
= NULL
;
212 delete m_windowSizer
;
213 m_windowSizer
= NULL
;
215 // If this is a child of a sizer, remove self from parent
217 m_sizerParent
->RemoveChild((wxWindow
*)this);
221 m_windowParent
->RemoveChild(this);
225 // Destroy the window
228 wxDeleteWindowFromTable((Widget
) GetMainWidget());
229 XtDestroyWidget((Widget
) GetMainWidget());
230 SetMainWidget((WXWidget
) NULL
);
236 // Just in case the window has been Closed, but
237 // we're then deleting immediately: don't leave
238 // dangling pointers.
239 wxPendingDelete
.DeleteObject(this);
241 if ( m_windowValidator
) delete m_windowValidator
;
242 if (m_clientObject
) delete m_clientObject
;
247 // Destroy the window (delayed, if a managed window)
248 bool wxWindow::Destroy()
255 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
259 const wxString
& name
)
264 m_windowParent
= NULL
;
265 m_windowEventHandler
= this;
267 m_windowCursor
= *wxSTANDARD_CURSOR
;
268 m_constraints
= NULL
;
269 m_constraintsInvolvedIn
= NULL
;
270 m_windowSizer
= NULL
;
271 m_sizerParent
= NULL
;
272 m_autoLayout
= FALSE
;
273 m_windowValidator
= NULL
;
274 #if wxUSE_DRAG_AND_DROP
275 m_pDropTarget
= NULL
;
277 m_caretWidth
= 0; m_caretHeight
= 0;
278 m_caretEnabled
= FALSE
;
279 m_caretShown
= FALSE
;
284 m_defaultItem
= NULL
;
285 m_windowParent
= NULL
;
286 m_clientObject
= (wxClientData
*) NULL
;
290 m_canAddEventHandler
= FALSE
;
291 m_mainWidget
= (WXWidget
) 0;
292 m_button1Pressed
= FALSE
;
293 m_button2Pressed
= FALSE
;
294 m_button3Pressed
= FALSE
;
295 m_winCaptured
= FALSE
;
297 m_hScrollBar
= (WXWidget
) 0;
298 m_vScrollBar
= (WXWidget
) 0;
299 m_borderWidget
= (WXWidget
) 0;
300 m_scrolledWindow
= (WXWidget
) 0;
301 m_drawingArea
= (WXWidget
) 0;
304 m_backingPixmap
= (WXPixmap
) 0;
315 if (parent
) parent
->AddChild(this);
322 m_windowId
= (int)NewControlId();
326 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
327 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
328 m_foregroundColour
= *wxBLACK
;
330 m_windowStyle
= style
;
333 m_windowId
= (int)NewControlId();
337 //// TODO: we should probably optimize by only creating a
338 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
339 //// But for now, let's simplify things by always creating the
340 //// drawing area, since otherwise the translations are different.
342 // New translations for getting mouse motion feedback
343 String translations
=
344 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
346 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
347 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
348 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
349 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
350 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
351 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
352 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
353 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
354 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
355 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
356 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
357 <Key>: DrawingAreaInput()";
359 XtActionsRec actions
[1];
360 actions
[0].string
= "wxCanvasMotionEvent";
361 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
362 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
364 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
365 if (style
& wxBORDER
)
366 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
367 xmFrameWidgetClass
, parentWidget
,
368 XmNshadowType
, XmSHADOW_IN
,
371 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
372 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
373 XmNresizePolicy
, XmRESIZE_NONE
,
375 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
376 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
380 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
381 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
382 XmNunitType
, XmPIXELS
,
383 // XmNresizePolicy, XmRESIZE_ANY,
384 XmNresizePolicy
, XmRESIZE_NONE
,
387 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
390 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
392 XtFree ((char *) ptr);
393 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
394 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
395 XtFree ((char *) ptr);
399 wxAddWindowToTable((Widget
) m_drawingArea
, this);
400 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
403 * This order is very important in Motif 1.2.1
407 XtRealizeWidget ((Widget
) m_scrolledWindow
);
408 XtRealizeWidget ((Widget
) m_drawingArea
);
409 XtManageChild ((Widget
) m_drawingArea
);
411 XtOverrideTranslations ((Widget
) m_drawingArea
,
412 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
413 XtFree ((char *) ptr
);
415 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
416 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
419 display = XtDisplay (scrolledWindow);
420 xwindow = XtWindow (drawingArea);
423 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
424 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
426 // Scrolled widget needs to have its colour changed or we get
427 // a little blue square where the scrollbars abutt
428 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
429 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
430 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
432 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) 0, (Widget
) 0, (Widget
) m_drawingArea
);
436 XtRealizeWidget ((Widget) m_hScrollBar);
438 XtRealizeWidget ((Widget) m_vScrollBar);
441 // Without this, the cursor may not be restored properly
442 // (e.g. in splitter sample).
443 SetCursor(*wxSTANDARD_CURSOR
);
444 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
445 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
451 void wxWindow::CreateScrollbar(int orientation
)
456 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
458 // Add scrollbars if required
459 if (orientation
== wxHORIZONTAL
)
461 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
462 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
463 XmNorientation
, XmHORIZONTAL
,
465 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
466 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
467 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
468 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
469 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
470 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
471 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
472 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
474 XtVaSetValues (hScrollBar
,
479 m_hScrollBar
= (WXWidget
) hScrollBar
;
481 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
482 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
484 XtRealizeWidget(hScrollBar
);
486 XtVaSetValues((Widget
) m_scrolledWindow
,
487 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
493 if (orientation
== wxVERTICAL
)
495 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
496 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
497 XmNorientation
, XmVERTICAL
,
499 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
500 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
501 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
502 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
503 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
504 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
505 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
506 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
508 XtVaSetValues (vScrollBar
,
513 m_vScrollBar
= (WXWidget
) vScrollBar
;
514 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
515 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
517 XtRealizeWidget(vScrollBar
);
519 XtVaSetValues((Widget
) m_scrolledWindow
,
520 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
526 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
528 void wxWindow::DestroyScrollbar(int orientation
)
533 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
534 // Add scrollbars if required
535 if (orientation
== wxHORIZONTAL
)
539 XtDestroyWidget((Widget
) m_hScrollBar
);
541 m_hScrollBar
= (WXWidget
) 0;
544 XtVaSetValues((Widget
) m_scrolledWindow
,
545 XmNhorizontalScrollBar
, (Widget
) 0,
550 if (orientation
== wxVERTICAL
)
554 XtDestroyWidget((Widget
) m_vScrollBar
);
556 m_vScrollBar
= (WXWidget
) 0;
559 XtVaSetValues((Widget
) m_scrolledWindow
,
560 XmNverticalScrollBar
, (Widget
) 0,
564 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
567 void wxWindow::SetFocus()
569 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
570 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
573 void wxWindow::Enable(bool enable
)
577 XtSetSensitive((Widget
) GetMainWidget(), enable
);
578 XmUpdateDisplay((Widget
) GetMainWidget());
582 void wxWindow::CaptureMouse()
588 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
590 m_winCaptured
= TRUE
;
593 void wxWindow::ReleaseMouse()
599 XtRemoveGrab((Widget
) GetMainWidget());
600 m_winCaptured
= FALSE
;
603 // Push/pop event handler (i.e. allow a chain of event handlers
605 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
607 handler
->SetNextHandler(GetEventHandler());
608 SetEventHandler(handler
);
611 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
613 if ( GetEventHandler() )
615 wxEvtHandler
*handlerA
= GetEventHandler();
616 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
617 handlerA
->SetNextHandler(NULL
);
618 SetEventHandler(handlerB
);
631 #if wxUSE_DRAG_AND_DROP
633 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
635 if ( m_pDropTarget
!= 0 ) {
636 delete m_pDropTarget
;
639 m_pDropTarget
= pDropTarget
;
640 if ( m_pDropTarget
!= 0 )
648 // Old style file-manager drag&drop
649 void wxWindow::DragAcceptFiles(bool accept
)
655 void wxWindow::GetSize(int *x
, int *y
) const
663 Widget widget
= (Widget
) GetTopWidget();
665 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
669 void wxWindow::GetPosition(int *x
, int *y
) const
673 CanvasGetPosition(x
, y
);
676 Widget widget
= (Widget
) GetTopWidget();
678 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
680 // We may be faking the client origin.
681 // So a window that's really at (0, 30) may appear
682 // (to wxWin apps) to be at (0, 0).
685 wxPoint
pt(GetParent()->GetClientAreaOrigin());
693 void wxWindow::ScreenToClient(int *x
, int *y
) const
695 Widget widget
= (Widget
) GetClientWidget();
696 Display
*display
= XtDisplay((Widget
) GetMainWidget());
697 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
698 Window thisWindow
= XtWindow(widget
);
703 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
706 void wxWindow::ClientToScreen(int *x
, int *y
) const
708 Widget widget
= (Widget
) GetClientWidget();
709 Display
*display
= XtDisplay(widget
);
710 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
711 Window thisWindow
= XtWindow(widget
);
716 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
719 void wxWindow::SetCursor(const wxCursor
& cursor
)
721 m_windowCursor
= cursor
;
722 if (m_windowCursor
.Ok())
724 WXDisplay
*dpy
= GetXDisplay();
725 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
727 Widget w
= (Widget
) GetMainWidget();
728 Window win
= XtWindow(w
);
729 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
734 // Get size *available for subwindows* i.e. excluding menu bar etc.
735 void wxWindow::GetClientSize(int *x
, int *y
) const
737 Widget widget
= (Widget
) GetClientWidget();
739 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
743 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
745 // A bit of optimization to help sort out the flickers.
746 int oldX
, oldY
, oldW
, oldH
;
747 GetSize(& oldW
, & oldH
);
748 GetPosition(& oldX
, & oldY
);
750 bool useOldPos
= FALSE
;
751 bool useOldSize
= FALSE
;
753 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
755 else if (x
== oldX
&& y
== oldY
)
758 if ((width
== -1) && (height
== -1))
760 else if (width
== oldW
&& height
== oldH
)
763 if (!wxNoOptimize::CanOptimize())
765 useOldSize
= FALSE
; useOldPos
= FALSE
;
768 if (useOldPos
&& useOldSize
)
773 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
776 Widget widget
= (Widget
) GetTopWidget();
780 bool managed
= XtIsManaged( widget
);
782 XtUnmanageChild(widget
);
784 int xx
= x
; int yy
= y
;
785 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
789 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
790 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
791 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
792 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
797 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
799 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
803 XtManageChild(widget
);
805 // How about this bit. Maybe we don't need to generate size events
806 // all the time -- they'll be generated when the window is sized anyway.
808 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
809 sizeEvent.SetEventObject(this);
811 GetEventHandler()->ProcessEvent(sizeEvent);
815 void wxWindow::SetClientSize(int width
, int height
)
819 CanvasSetClientSize(width
, height
);
823 Widget widget
= (Widget
) GetTopWidget();
826 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
828 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
830 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
831 sizeEvent
.SetEventObject(this);
833 GetEventHandler()->ProcessEvent(sizeEvent
);
836 // For implementation purposes - sometimes decorations make the client area
838 wxPoint
wxWindow::GetClientAreaOrigin() const
840 return wxPoint(0, 0);
843 // Makes an adjustment to the window position (for example, a frame that has
844 // a toolbar that it manages itself).
845 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
847 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
849 wxPoint
pt(GetParent()->GetClientAreaOrigin());
850 x
+= pt
.x
; y
+= pt
.y
;
854 bool wxWindow::Show(bool show
)
858 if (m_borderWidget
|| m_scrolledWindow
)
861 XtMapWidget((Widget
) m_drawingArea
);
862 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
866 WXWidget topWidget
= GetTopWidget();
868 XtMapWidget((Widget
) GetTopWidget());
869 else if (GetMainWidget())
870 XtMapWidget((Widget
) GetMainWidget());
875 if (m_borderWidget
|| m_scrolledWindow
)
878 XtUnmapWidget((Widget
) m_drawingArea
);
879 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
884 XtUnmapWidget((Widget
) GetTopWidget());
885 else if (GetMainWidget())
886 XtUnmapWidget((Widget
) GetMainWidget());
891 Window xwin = (Window) GetXWindow();
892 Display *xdisp = (Display*) GetXDisplay();
894 XMapWindow(xdisp, xwin);
896 XUnmapWindow(xdisp, xwin);
904 bool wxWindow::IsShown() const
909 int wxWindow::GetCharHeight() const
911 if (!m_windowFont
.Ok())
914 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
916 int direction
, ascent
, descent
;
918 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
920 // return (overall.ascent + overall.descent);
921 return (ascent
+ descent
);
924 int wxWindow::GetCharWidth() const
926 if (!m_windowFont
.Ok())
929 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
931 int direction
, ascent
, descent
;
933 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
935 return overall
.width
;
938 /* Helper function for 16-bit fonts */
939 static int str16len(const char *s
)
943 while (s
[0] && s
[1]) {
951 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
952 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
954 wxFont
*fontToUse
= (wxFont
*)theFont
;
956 fontToUse
= (wxFont
*) & m_windowFont
;
958 if (!fontToUse
->Ok())
961 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
963 int direction
, ascent
, descent2
;
967 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
970 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
971 &ascent
, &descent2
, &overall
);
973 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
974 &ascent
, &descent2
, &overall
);
976 *x
= (overall
.width
);
977 *y
= (ascent
+ descent2
);
981 *externalLeading
= 0;
984 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
986 Display
*display
= XtDisplay((Widget
) GetMainWidget());
987 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
989 XExposeEvent dummyEvent
;
991 GetSize(&width
, &height
);
993 dummyEvent
.type
= Expose
;
994 dummyEvent
.display
= display
;
995 dummyEvent
.send_event
= True
;
996 dummyEvent
.window
= thisWindow
;
999 dummyEvent
.x
= rect
->x
;
1000 dummyEvent
.y
= rect
->y
;
1001 dummyEvent
.width
= rect
->width
;
1002 dummyEvent
.height
= rect
->height
;
1008 dummyEvent
.width
= width
;
1009 dummyEvent
.height
= height
;
1011 dummyEvent
.count
= 0;
1015 wxClientDC
dc(this);
1016 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1017 dc
.SetBackground(backgroundBrush
);
1024 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1027 // Responds to colour changes: passes event on to children.
1028 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1030 wxNode
*node
= GetChildren().First();
1033 // Only propagate to non-top-level windows
1034 wxWindow
*win
= (wxWindow
*)node
->Data();
1035 if ( win
->GetParent() )
1037 wxSysColourChangedEvent event2
;
1038 event
.m_eventObject
= win
;
1039 win
->GetEventHandler()->ProcessEvent(event2
);
1042 node
= node
->Next();
1046 // This can be called by the app (or wxWindows) to do default processing for the current
1047 // event. Save message/event info in wxWindow so they can be used in this function.
1048 long wxWindow::Default()
1054 void wxWindow::InitDialog()
1056 wxInitDialogEvent
event(GetId());
1057 event
.SetEventObject( this );
1058 GetEventHandler()->ProcessEvent(event
);
1061 // Default init dialog behaviour is to transfer data to window
1062 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
1064 TransferDataToWindow();
1067 // Caret manipulation
1068 void wxWindow::CreateCaret(int w
, int h
)
1072 m_caretEnabled
= TRUE
;
1075 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1080 void wxWindow::ShowCaret(bool show
)
1085 void wxWindow::DestroyCaret()
1088 m_caretEnabled
= FALSE
;
1091 void wxWindow::SetCaretPos(int x
, int y
)
1096 void wxWindow::GetCaretPos(int *x
, int *y
) const
1101 wxWindow
*wxGetActiveWindow()
1107 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1114 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1117 wxFrame
*frame
= (wxFrame
*)this;
1118 Widget widget
= (Widget
) frame
->GetShellWidget();
1121 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1123 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1125 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1127 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1129 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1131 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1134 void wxWindow::Centre(int direction
)
1136 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1138 wxWindow
*father
= (wxWindow
*)GetParent();
1142 father
->GetClientSize(&panel_width
, &panel_height
);
1143 GetSize(&width
, &height
);
1144 GetPosition(&x
, &y
);
1149 if (direction
& wxHORIZONTAL
)
1150 new_x
= (int)((panel_width
- width
)/2);
1152 if (direction
& wxVERTICAL
)
1153 new_y
= (int)((panel_height
- height
)/2);
1155 SetSize(new_x
, new_y
, -1, -1);
1159 // Coordinates relative to the window
1160 void wxWindow::WarpPointer (int x
, int y
)
1162 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1165 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1171 int wxWindow::GetScrollPos(int orient
) const
1173 if (orient
== wxHORIZONTAL
)
1174 return m_scrollPosX
;
1176 return m_scrollPosY
;
1178 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1182 XtVaGetValues(scrollBar,
1183 XmNvalue, &pos, NULL);
1191 // This now returns the whole range, not just the number
1192 // of positions that we can scroll.
1193 int wxWindow::GetScrollRange(int orient
) const
1195 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1199 XtVaGetValues(scrollBar
,
1200 XmNmaximum
, &range
, NULL
);
1207 int wxWindow::GetScrollThumb(int orient
) const
1209 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1213 XtVaGetValues(scrollBar
,
1214 XmNsliderSize
, &thumb
, NULL
);
1221 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1223 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1226 XtVaSetValues (scrollBar
,
1230 if (orient
== wxHORIZONTAL
)
1237 // New function that will replace some of the above.
1238 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1239 int range
, bool WXUNUSED(refresh
))
1242 GetSize(& oldW
, & oldH
);
1246 if (thumbVisible
== 0)
1249 if (thumbVisible
> range
)
1250 thumbVisible
= range
;
1252 // Save the old state to see if it changed
1253 WXWidget oldScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1255 if (orient
== wxHORIZONTAL
)
1257 if (thumbVisible
== range
)
1260 DestroyScrollbar(wxHORIZONTAL
);
1265 CreateScrollbar(wxHORIZONTAL
);
1268 if (orient
== wxVERTICAL
)
1270 if (thumbVisible
== range
)
1273 DestroyScrollbar(wxVERTICAL
);
1278 CreateScrollbar(wxVERTICAL
);
1281 WXWidget newScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1283 if (oldScrollBar
!= newScrollBar
)
1285 // This is important! Without it, scrollbars misbehave
1287 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
1288 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
1289 XtRealizeWidget((Widget
) m_scrolledWindow
);
1290 XtManageChild((Widget
) m_scrolledWindow
);
1294 XtVaSetValues((Widget
) newScrollBar
,
1298 XmNsliderSize
, thumbVisible
,
1301 if (orient
== wxHORIZONTAL
)
1307 GetSize(& newW
, & newH
);
1309 // Adjusting scrollbars can resize the canvas accidentally
1310 if (newW
!= oldW
|| newH
!= oldH
)
1311 SetSize(-1, -1, oldW
, oldH
);
1314 // Does a physical scroll
1315 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1317 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1321 // Use specified rectangle
1322 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1326 // Use whole client area
1328 GetClientSize(& w
, & h
);
1331 int x1
= (dx
>= 0) ? x
: x
- dx
;
1332 int y1
= (dy
>= 0) ? y
: y
- dy
;
1333 int w1
= w
- abs(dx
);
1334 int h1
= h
- abs(dy
);
1335 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1336 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1338 wxClientDC
dc(this);
1340 dc
.SetLogicalFunction (wxCOPY
);
1342 Widget widget
= (Widget
) GetMainWidget();
1343 Window window
= XtWindow(widget
);
1344 Display
* display
= XtDisplay(widget
);
1346 XCopyArea(display
, window
,
1347 window
, (GC
) dc
.GetGC(),
1352 dc
.SetAutoSetting(TRUE
);
1353 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1354 dc
.SetBrush(brush
); // ??
1356 // We'll add rectangles to the list of update rectangles
1357 // according to which bits we've exposed.
1362 wxRect
*rect
= new wxRect
;
1368 XFillRectangle(display
, window
,
1369 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1373 rect
->width
= rect
->width
;
1374 rect
->height
= rect
->height
;
1376 updateRects
.Append((wxObject
*) rect
);
1380 wxRect
*rect
= new wxRect
;
1382 rect
->x
= x
+ w
+ dx
;
1387 XFillRectangle(display
, window
,
1388 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1393 rect
->width
= rect
->width
;
1394 rect
->height
= rect
->height
;
1396 updateRects
.Append((wxObject
*) rect
);
1400 wxRect
*rect
= new wxRect
;
1407 XFillRectangle(display
, window
,
1408 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1412 rect
->width
= rect
->width
;
1413 rect
->height
= rect
->height
;
1415 updateRects
.Append((wxObject
*) rect
);
1419 wxRect
*rect
= new wxRect
;
1422 rect
->y
= y
+ h
+ dy
;
1426 XFillRectangle(display
, window
,
1427 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1431 rect
->width
= rect
->width
;
1432 rect
->height
= rect
->height
;
1434 updateRects
.Append((wxObject
*) rect
);
1436 dc
.SetBrush(wxNullBrush
);
1438 // Now send expose events
1440 wxNode
* node
= updateRects
.First();
1443 wxRect
* rect
= (wxRect
*) node
->Data();
1446 event
.type
= Expose
;
1447 event
.display
= display
;
1448 event
.send_event
= True
;
1449 event
.window
= window
;
1453 event
.width
= rect
->width
;
1454 event
.height
= rect
->height
;
1458 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1460 node
= node
->Next();
1464 // Delete the update rects
1465 node
= updateRects
.First();
1468 wxRect
* rect
= (wxRect
*) node
->Data();
1470 node
= node
->Next();
1475 void wxWindow::OnChar(wxKeyEvent
& event
)
1478 if ( event.KeyCode() == WXK_TAB ) {
1479 // propagate the TABs to the parent - it's up to it to decide what
1481 if ( GetParent() ) {
1482 if ( GetParent()->ProcessEvent(event) )
1489 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1494 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1499 void wxWindow::OnPaint(wxPaintEvent
& event
)
1504 bool wxWindow::IsEnabled() const
1506 // TODO. Is this right?
1507 // return XtGetSensitive((Widget) GetMainWidget());
1511 // Dialog support: override these and call
1512 // base class members to add functionality
1513 // that can't be done using validators.
1514 // NOTE: these functions assume that controls
1515 // are direct children of this window, not grandchildren
1516 // or other levels of descendant.
1518 // Transfer values to controls. If returns FALSE,
1519 // it's an application error (pops up a dialog)
1520 bool wxWindow::TransferDataToWindow()
1522 wxNode
*node
= GetChildren().First();
1525 wxWindow
*child
= (wxWindow
*)node
->Data();
1526 if ( child
->GetValidator() &&
1527 !child
->GetValidator()->TransferToWindow() )
1529 wxLogError("Could not transfer data to window.");
1533 node
= node
->Next();
1538 // Transfer values from controls. If returns FALSE,
1539 // validation failed: don't quit
1540 bool wxWindow::TransferDataFromWindow()
1542 wxNode
*node
= GetChildren().First();
1545 wxWindow
*child
= (wxWindow
*)node
->Data();
1546 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1551 node
= node
->Next();
1556 bool wxWindow::Validate()
1558 wxNode
*node
= GetChildren().First();
1561 wxWindow
*child
= (wxWindow
*)node
->Data();
1562 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1567 node
= node
->Next();
1572 // Get the window with the focus
1573 wxWindow
*wxWindow::FindFocus()
1579 void wxWindow::AddChild(wxWindow
*child
)
1581 GetChildren().Append(child
);
1582 child
->m_windowParent
= this;
1585 void wxWindow::RemoveChild(wxWindow
*child
)
1587 GetChildren().DeleteObject(child
);
1588 child
->m_windowParent
= NULL
;
1591 // Reparents this window to have the new parent.
1592 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1594 // For now, we indicate that this isn't implemented.
1598 void wxWindow::DestroyChildren()
1600 wxNode
*node
= GetChildren().First();
1603 wxNode
* next
= node
->Next();
1604 wxWindow
* child
= (wxWindow
*) node
->Data();
1608 GetChildren().Clear();
1611 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1613 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1615 if ( GetChildren().Member(child
) )
1622 void wxWindow::MakeModal(bool modal
)
1624 // Disable all other windows
1625 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1627 wxNode
*node
= wxTopLevelWindows
.First();
1630 wxWindow
*win
= (wxWindow
*)node
->Data();
1632 win
->Enable(!modal
);
1634 node
= node
->Next();
1639 // If nothing defined for this, try the parent.
1640 // E.g. we may be a button loaded from a resource, with no callback function
1642 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1644 if (GetEventHandler()->ProcessEvent(event
) )
1647 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1650 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1654 UnsetConstraints(m_constraints
);
1655 delete m_constraints
;
1660 // Make sure other windows know they're part of a 'meaningful relationship'
1661 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1662 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1663 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1664 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1665 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1666 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1667 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1668 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1669 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1670 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1671 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1672 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1673 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1674 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1675 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1676 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1680 // This removes any dangling pointers to this window
1681 // in other windows' constraintsInvolvedIn lists.
1682 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1686 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1687 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1688 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1689 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1690 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1691 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1692 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1693 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1694 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1695 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1696 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1697 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1698 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1699 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1700 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1701 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1705 // Back-pointer to other windows we're involved with, so if we delete
1706 // this window, we must delete any constraints we're involved with.
1707 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1709 if (!m_constraintsInvolvedIn
)
1710 m_constraintsInvolvedIn
= new wxList
;
1711 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1712 m_constraintsInvolvedIn
->Append(otherWin
);
1715 // REMOVE back-pointer to other windows we're involved with.
1716 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1718 if (m_constraintsInvolvedIn
)
1719 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1722 // Reset any constraints that mention this window
1723 void wxWindow::DeleteRelatedConstraints()
1725 if (m_constraintsInvolvedIn
)
1727 wxNode
*node
= m_constraintsInvolvedIn
->First();
1730 wxWindow
*win
= (wxWindow
*)node
->Data();
1731 wxNode
*next
= node
->Next();
1732 wxLayoutConstraints
*constr
= win
->GetConstraints();
1734 // Reset any constraints involving this window
1737 constr
->left
.ResetIfWin((wxWindow
*)this);
1738 constr
->top
.ResetIfWin((wxWindow
*)this);
1739 constr
->right
.ResetIfWin((wxWindow
*)this);
1740 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1741 constr
->width
.ResetIfWin((wxWindow
*)this);
1742 constr
->height
.ResetIfWin((wxWindow
*)this);
1743 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1744 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1749 delete m_constraintsInvolvedIn
;
1750 m_constraintsInvolvedIn
= NULL
;
1754 void wxWindow::SetSizer(wxSizer
*sizer
)
1756 m_windowSizer
= sizer
;
1758 sizer
->SetSizerParent((wxWindow
*)this);
1765 bool wxWindow::Layout()
1767 if (GetConstraints())
1770 GetClientSize(&w
, &h
);
1771 GetConstraints()->width
.SetValue(w
);
1772 GetConstraints()->height
.SetValue(h
);
1775 // If top level (one sizer), evaluate the sizer's constraints.
1779 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1780 GetSizer()->LayoutPhase1(&noChanges
);
1781 GetSizer()->LayoutPhase2(&noChanges
);
1782 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1787 // Otherwise, evaluate child constraints
1788 ResetConstraints(); // Mark all constraints as unevaluated
1789 DoPhase(1); // Just one phase need if no sizers involved
1791 SetConstraintSizes(); // Recursively set the real window sizes
1797 // Do a phase of evaluating constraints:
1798 // the default behaviour. wxSizers may do a similar
1799 // thing, but also impose their own 'constraints'
1800 // and order the evaluation differently.
1801 bool wxWindow::LayoutPhase1(int *noChanges
)
1803 wxLayoutConstraints
*constr
= GetConstraints();
1806 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1812 bool wxWindow::LayoutPhase2(int *noChanges
)
1822 // Do a phase of evaluating child constraints
1823 bool wxWindow::DoPhase(int phase
)
1825 int noIterations
= 0;
1826 int maxIterations
= 500;
1830 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1834 wxNode
*node
= GetChildren().First();
1837 wxWindow
*child
= (wxWindow
*)node
->Data();
1838 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1840 wxLayoutConstraints
*constr
= child
->GetConstraints();
1843 if (succeeded
.Member(child
))
1848 int tempNoChanges
= 0;
1849 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1850 noChanges
+= tempNoChanges
;
1853 succeeded
.Append(child
);
1858 node
= node
->Next();
1865 void wxWindow::ResetConstraints()
1867 wxLayoutConstraints
*constr
= GetConstraints();
1870 constr
->left
.SetDone(FALSE
);
1871 constr
->top
.SetDone(FALSE
);
1872 constr
->right
.SetDone(FALSE
);
1873 constr
->bottom
.SetDone(FALSE
);
1874 constr
->width
.SetDone(FALSE
);
1875 constr
->height
.SetDone(FALSE
);
1876 constr
->centreX
.SetDone(FALSE
);
1877 constr
->centreY
.SetDone(FALSE
);
1879 wxNode
*node
= GetChildren().First();
1882 wxWindow
*win
= (wxWindow
*)node
->Data();
1883 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1884 win
->ResetConstraints();
1885 node
= node
->Next();
1889 // Need to distinguish between setting the 'fake' size for
1890 // windows and sizers, and setting the real values.
1891 void wxWindow::SetConstraintSizes(bool recurse
)
1893 wxLayoutConstraints
*constr
= GetConstraints();
1894 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1895 constr
->width
.GetDone() && constr
->height
.GetDone())
1897 int x
= constr
->left
.GetValue();
1898 int y
= constr
->top
.GetValue();
1899 int w
= constr
->width
.GetValue();
1900 int h
= constr
->height
.GetValue();
1902 // If we don't want to resize this window, just move it...
1903 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1904 (constr
->height
.GetRelationship() != wxAsIs
))
1906 // Calls Layout() recursively. AAAGH. How can we stop that.
1907 // Simply take Layout() out of non-top level OnSizes.
1908 SizerSetSize(x
, y
, w
, h
);
1917 char *windowClass
= this->GetClassInfo()->GetClassName();
1920 if (GetName() == "")
1921 winName
= "unnamed";
1923 winName
= GetName();
1924 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1925 if (!constr
->left
.GetDone())
1926 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1927 if (!constr
->right
.GetDone())
1928 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1929 if (!constr
->width
.GetDone())
1930 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1931 if (!constr
->height
.GetDone())
1932 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1933 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1938 wxNode
*node
= GetChildren().First();
1941 wxWindow
*win
= (wxWindow
*)node
->Data();
1942 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1943 win
->SetConstraintSizes();
1944 node
= node
->Next();
1949 // This assumes that all sizers are 'on' the same
1950 // window, i.e. the parent of this window.
1951 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1953 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1954 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1958 m_sizerParent
->GetPosition(&xp
, &yp
);
1959 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1964 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1968 TransformSizerToActual(&xx
, &yy
);
1969 SetSize(xx
, yy
, w
, h
);
1972 void wxWindow::SizerMove(int x
, int y
)
1976 TransformSizerToActual(&xx
, &yy
);
1980 // Only set the size/position of the constraint (if any)
1981 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1983 wxLayoutConstraints
*constr
= GetConstraints();
1988 constr
->left
.SetValue(x
);
1989 constr
->left
.SetDone(TRUE
);
1993 constr
->top
.SetValue(y
);
1994 constr
->top
.SetDone(TRUE
);
1998 constr
->width
.SetValue(w
);
1999 constr
->width
.SetDone(TRUE
);
2003 constr
->height
.SetValue(h
);
2004 constr
->height
.SetDone(TRUE
);
2009 void wxWindow::MoveConstraint(int x
, int y
)
2011 wxLayoutConstraints
*constr
= GetConstraints();
2016 constr
->left
.SetValue(x
);
2017 constr
->left
.SetDone(TRUE
);
2021 constr
->top
.SetValue(y
);
2022 constr
->top
.SetDone(TRUE
);
2027 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2029 wxLayoutConstraints
*constr
= GetConstraints();
2032 *w
= constr
->width
.GetValue();
2033 *h
= constr
->height
.GetValue();
2039 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2041 wxLayoutConstraints
*constr
= GetConstraints();
2044 *w
= constr
->width
.GetValue();
2045 *h
= constr
->height
.GetValue();
2048 GetClientSize(w
, h
);
2051 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2053 wxLayoutConstraints
*constr
= GetConstraints();
2056 *x
= constr
->left
.GetValue();
2057 *y
= constr
->top
.GetValue();
2063 bool wxWindow::Close(bool force
)
2065 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2066 event
.SetEventObject(this);
2067 event
.SetForce(force
);
2069 return GetEventHandler()->ProcessEvent(event
);
2072 wxObject
* wxWindow::GetChild(int number
) const
2074 // Return a pointer to the Nth object in the window
2075 wxNode
*node
= GetChildren().First();
2078 node
= node
->Next() ;
2081 wxObject
*obj
= (wxObject
*)node
->Data();
2088 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2090 // Obsolete function
2093 void wxWindow::Clear()
2095 wxClientDC
dc(this);
2096 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2097 dc
.SetBackground(brush
);
2101 // Fits the panel around the items
2102 void wxWindow::Fit()
2106 wxNode
*node
= GetChildren().First();
2109 wxWindow
*win
= (wxWindow
*)node
->Data();
2111 win
->GetPosition(&wx
, &wy
);
2112 win
->GetSize(&ww
, &wh
);
2113 if ( wx
+ ww
> maxX
)
2115 if ( wy
+ wh
> maxY
)
2118 node
= node
->Next();
2120 SetClientSize(maxX
+ 5, maxY
+ 5);
2123 void wxWindow::SetValidator(const wxValidator
& validator
)
2125 if ( m_windowValidator
)
2126 delete m_windowValidator
;
2127 m_windowValidator
= validator
.Clone();
2129 if ( m_windowValidator
)
2130 m_windowValidator
->SetWindow(this) ;
2133 void wxWindow::SetClientObject( wxClientData
*data
)
2135 if (m_clientObject
) delete m_clientObject
;
2136 m_clientObject
= data
;
2139 wxClientData
*wxWindow::GetClientObject()
2141 return m_clientObject
;
2144 void wxWindow::SetClientData( void *data
)
2146 m_clientData
= data
;
2149 void *wxWindow::GetClientData()
2151 return m_clientData
;
2154 // Find a window by id or name
2155 wxWindow
*wxWindow::FindWindow(long id
)
2160 wxNode
*node
= GetChildren().First();
2163 wxWindow
*child
= (wxWindow
*)node
->Data();
2164 wxWindow
*found
= child
->FindWindow(id
);
2167 node
= node
->Next();
2172 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2174 if ( GetName() == name
)
2177 wxNode
*node
= GetChildren().First();
2180 wxWindow
*child
= (wxWindow
*)node
->Data();
2181 wxWindow
*found
= child
->FindWindow(name
);
2184 node
= node
->Next();
2189 void wxWindow::OnIdle(wxIdleEvent
& event
)
2191 // This calls the UI-update mechanism (querying windows for
2192 // menu/toolbar/control state information)
2196 // Raise the window to the top of the Z order
2197 void wxWindow::Raise()
2199 Window window
= XtWindow((Widget
) GetTopWidget());
2200 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2203 // Lower the window to the bottom of the Z order
2204 void wxWindow::Lower()
2206 Window window
= XtWindow((Widget
) GetTopWidget());
2207 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2210 bool wxWindow::AcceptsFocus() const
2212 return IsShown() && IsEnabled();
2215 // Update region access
2216 wxRegion
& wxWindow::GetUpdateRegion() const
2218 return (wxRegion
&) m_updateRegion
;
2221 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2223 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2226 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2228 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2231 bool wxWindow::IsExposed(const wxRect
& rect
) const
2233 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2237 * Allocates control IDs
2240 int wxWindow::NewControlId()
2242 static int s_controlId
= 0;
2247 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2249 m_acceleratorTable
= accel
;
2252 // All widgets should have this as their resize proc.
2253 // OnSize sent to wxWindow via client data.
2254 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2256 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2260 if (win
->PreResize())
2263 win
->GetSize(&width
, &height
);
2264 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2265 sizeEvent
.SetEventObject(win
);
2266 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2270 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2272 wxWindow
*oldItem
= NULL
;
2273 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2274 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2276 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2280 wxWidgetHashTable
->Put ((long) w
, win
);
2284 wxWindow
*wxGetWindowFromTable(Widget w
)
2286 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2289 void wxDeleteWindowFromTable(Widget w
)
2291 wxWidgetHashTable
->Delete((long)w
);
2294 // Get the underlying X window and display
2295 WXWindow
wxWindow::GetXWindow() const
2297 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2300 WXDisplay
*wxWindow::GetXDisplay() const
2302 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2305 WXWidget
wxWindow::GetMainWidget() const
2308 return m_drawingArea
;
2310 return m_mainWidget
;
2313 WXWidget
wxWindow::GetClientWidget() const
2315 if (m_drawingArea
!= (WXWidget
) 0)
2316 return m_drawingArea
;
2318 return GetMainWidget();
2321 WXWidget
wxWindow::GetTopWidget() const
2323 return GetMainWidget();
2326 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2327 XmDrawingAreaCallbackStruct
* cbs
)
2329 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2332 XEvent
* event
= cbs
->event
;
2333 wxWindow
* win
= (wxWindow
*) clientData
;
2334 Display
* display
= (Display
*) win
->GetXDisplay();
2336 switch (event
->type
)
2340 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2341 event
->xexpose
.width
, event
->xexpose
.height
);
2343 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2344 cout << rect->width << ", " << rect->height << "\n\n";
2347 win
->m_updateRects
.Append((wxObject
*) rect
);
2349 if (event
-> xexpose
.count
== 0)
2351 wxPaintEvent
event(win
->GetId());
2352 event
.SetEventObject(win
);
2353 win
->GetEventHandler()->ProcessEvent(event
);
2355 win
->ClearUpdateRects();
2361 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2367 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2369 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2371 XmDrawingAreaCallbackStruct cbs
;
2374 //if (event->mode!=NotifyNormal)
2377 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2378 ((XCrossingEvent
&) ev
) = *event
;
2380 cbs
.reason
= XmCR_INPUT
;
2383 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2386 // Fix to make it work under Motif 1.0 (!)
2387 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2391 XmDrawingAreaCallbackStruct cbs
;
2394 //ev.xbutton = *event;
2395 ev
= *((XEvent
*) event
);
2396 cbs
.reason
= XmCR_INPUT
;
2399 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2403 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2405 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2411 if (cbs
->reason
!= XmCR_INPUT
)
2414 local_event
= *(cbs
->event
); // We must keep a copy!
2417 switch (local_event.xany.type)
2420 cout << "EnterNotify\n";
2423 cout << "LeaveNotify\n";
2426 cout << "ButtonPress\n";
2429 cout << "ButtonRelease\n";
2432 cout << "MotionNotify\n";
2435 cout << "Something else\n";
2440 switch (local_event
.xany
.type
)
2448 wxEventType eventType
= wxEVT_NULL
;
2450 if (local_event
.xany
.type
== EnterNotify
)
2452 //if (local_event.xcrossing.mode!=NotifyNormal)
2453 // return ; // Ignore grab events
2454 eventType
= wxEVT_ENTER_WINDOW
;
2455 // canvas->GetEventHandler()->OnSetFocus();
2457 else if (local_event
.xany
.type
== LeaveNotify
)
2459 //if (local_event.xcrossing.mode!=NotifyNormal)
2460 // return ; // Ignore grab events
2461 eventType
= wxEVT_LEAVE_WINDOW
;
2462 // canvas->GetEventHandler()->OnKillFocus();
2464 else if (local_event
.xany
.type
== MotionNotify
)
2466 eventType
= wxEVT_MOTION
;
2467 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2470 Display
*dpy
= XtDisplay (drawingArea
);
2472 XQueryPointer (dpy
, XtWindow (drawingArea
),
2474 &local_event
.xmotion
.x_root
,
2475 &local_event
.xmotion
.y_root
,
2476 &local_event
.xmotion
.x
,
2477 &local_event
.xmotion
.y
,
2478 &local_event
.xmotion
.state
);
2485 else if (local_event
.xany
.type
== ButtonPress
)
2487 if (local_event
.xbutton
.button
== Button1
)
2489 eventType
= wxEVT_LEFT_DOWN
;
2490 canvas
->m_button1Pressed
= TRUE
;
2492 else if (local_event
.xbutton
.button
== Button2
)
2494 eventType
= wxEVT_MIDDLE_DOWN
;
2495 canvas
->m_button2Pressed
= TRUE
;
2497 else if (local_event
.xbutton
.button
== Button3
)
2499 eventType
= wxEVT_RIGHT_DOWN
;
2500 canvas
->m_button3Pressed
= TRUE
;
2503 else if (local_event
.xany
.type
== ButtonRelease
)
2505 if (local_event
.xbutton
.button
== Button1
)
2507 eventType
= wxEVT_LEFT_UP
;
2508 canvas
->m_button1Pressed
= FALSE
;
2510 else if (local_event
.xbutton
.button
== Button2
)
2512 eventType
= wxEVT_MIDDLE_UP
;
2513 canvas
->m_button2Pressed
= FALSE
;
2515 else if (local_event
.xbutton
.button
== Button3
)
2517 eventType
= wxEVT_RIGHT_UP
;
2518 canvas
->m_button3Pressed
= FALSE
;
2522 wxMouseEvent
wxevent (eventType
);
2523 wxevent
.m_eventHandle
= (char *) &local_event
;
2525 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2526 || (event_left_is_down (&local_event
)
2527 && (eventType
!= wxEVT_LEFT_UP
)));
2528 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2529 || (event_middle_is_down (&local_event
)
2530 && (eventType
!= wxEVT_MIDDLE_UP
)));
2531 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2532 || (event_right_is_down (&local_event
)
2533 && (eventType
!= wxEVT_RIGHT_UP
)));
2535 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2536 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2537 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2538 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2539 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2541 // Now check if we need to translate this event into a double click
2542 if (TRUE
) // canvas->doubleClickAllowed)
2544 if (wxevent
.ButtonDown())
2546 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2548 // get button and time-stamp
2550 if (wxevent
.LeftDown()) button
= 1;
2551 else if (wxevent
.MiddleDown()) button
= 2;
2552 else if (wxevent
.RightDown()) button
= 3;
2553 long ts
= wxevent
.GetTimestamp();
2554 // check, if single or double click
2555 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2558 canvas
->m_lastButton
= 0;
2559 switch ( eventType
)
2561 case wxEVT_LEFT_DOWN
:
2562 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2564 case wxEVT_MIDDLE_DOWN
:
2565 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2567 case wxEVT_RIGHT_DOWN
:
2568 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2578 // not fast enough or different button
2579 canvas
->m_lastTS
= ts
;
2580 canvas
->m_lastButton
= button
;
2585 wxevent
.SetId(canvas
->GetId());
2586 wxevent
.SetEventObject(canvas
);
2587 wxevent
.m_x
= local_event
.xbutton
.x
;
2588 wxevent
.m_y
= local_event
.xbutton
.y
;
2589 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2591 if (eventType == wxEVT_ENTER_WINDOW ||
2592 eventType == wxEVT_LEAVE_WINDOW ||
2593 eventType == wxEVT_MOTION
2602 // XComposeStatus compose;
2603 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2604 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2605 int id
= wxCharCodeXToWX (keySym
);
2607 wxEventType eventType
= wxEVT_CHAR
;
2609 // TODO: Is this the correct criterion for wxEVT_KEY_DOWN down versus wxEVT_CHAR?
2610 if (id
> WXK_START
) // Non-ASCII values
2611 eventType
= wxEVT_KEY_DOWN
;
2613 wxKeyEvent
event (eventType
);
2615 if (local_event
.xkey
.state
& ShiftMask
)
2616 event
.m_shiftDown
= TRUE
;
2617 if (local_event
.xkey
.state
& ControlMask
)
2618 event
.m_controlDown
= TRUE
;
2619 if (local_event
.xkey
.state
& Mod3Mask
)
2620 event
.m_altDown
= TRUE
;
2621 if (local_event
.xkey
.state
& Mod1Mask
)
2622 event
.m_metaDown
= TRUE
;
2623 event
.SetEventObject(canvas
);
2624 event
.m_keyCode
= id
;
2625 event
.SetTimestamp(local_event
.xkey
.time
);
2629 // Implement wxFrame::OnCharHook by checking ancestor.
2630 wxWindow
*parent
= canvas
->GetParent();
2631 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2632 parent
= parent
->GetParent();
2636 event
.SetEventType(wxEVT_CHAR_HOOK
);
2637 if (parent
->GetEventHandler()->ProcessEvent(event
))
2639 event
.SetEventType(wxEVT_CHAR
);
2642 canvas
->GetEventHandler()->ProcessEvent (event
);
2649 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2650 int id
= wxCharCodeXToWX (keySym
);
2652 wxKeyEvent
event (wxEVT_KEY_UP
);
2654 if (local_event
.xkey
.state
& ShiftMask
)
2655 event
.m_shiftDown
= TRUE
;
2656 if (local_event
.xkey
.state
& ControlMask
)
2657 event
.m_controlDown
= TRUE
;
2658 if (local_event
.xkey
.state
& Mod3Mask
)
2659 event
.m_altDown
= TRUE
;
2660 if (local_event
.xkey
.state
& Mod1Mask
)
2661 event
.m_metaDown
= TRUE
;
2662 event
.SetEventObject(canvas
);
2663 event
.m_keyCode
= id
;
2664 event
.SetTimestamp(local_event
.xkey
.time
);
2668 canvas
->GetEventHandler()->ProcessEvent (event
);
2674 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2676 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2677 event
.SetEventObject(canvas
);
2678 canvas
->GetEventHandler()->ProcessEvent(event
);
2684 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2686 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2687 event
.SetEventObject(canvas
);
2688 canvas
->GetEventHandler()->ProcessEvent(event
);
2697 void wxWindow::DoPaint()
2699 //TODO : make a temporary gc so we can do the XCopyArea below
2700 if (0) // m_backingPixmap)
2703 Widget drawingArea = (Widget) m_drawingArea;
2704 // int orig = GetDC()->GetLogicalFunction();
2705 // GetDC()->SetLogicalFunction (wxCOPY);
2707 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2708 // should be able to calculate them.
2709 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2710 m_pixmapOffsetX, m_pixmapOffsetY,
2711 m_pixmapWidth, m_pixmapHeight,
2714 // GetDC()->SetLogicalFunction (orig);
2719 wxPaintEvent
event(GetId());
2720 event
.SetEventObject(this);
2721 GetEventHandler()->ProcessEvent(event
);
2725 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2726 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2728 // A bit of optimization to help sort out the flickers.
2729 int oldX
, oldY
, oldW
, oldH
;
2730 GetSize(& oldW
, & oldH
);
2731 GetPosition(& oldX
, & oldY
);
2733 bool useOldPos
= FALSE
;
2734 bool useOldSize
= FALSE
;
2736 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2738 else if (x
== oldX
&& y
== oldY
)
2741 if ((w
== -1) && (h
== -1))
2743 else if (w
== oldW
&& h
== oldH
)
2746 if (!wxNoOptimize::CanOptimize())
2748 useOldSize
= FALSE
; useOldPos
= FALSE
;
2751 if (useOldPos
&& useOldSize
)
2754 Widget drawingArea
= (Widget
) m_drawingArea
;
2755 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2758 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2759 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2761 int xx
= x
; int yy
= y
;
2762 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2766 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2768 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2772 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2774 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2786 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2787 short thick
, margin
;
2788 XtVaGetValues ((Widget
) m_borderWidget
,
2789 XmNshadowThickness
, &thick
,
2790 XmNmarginWidth
, &margin
,
2792 w
-= 2 * (thick
+ margin
);
2795 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2799 XtVaGetValues ((Widget
) m_scrolledWindow
,
2800 XmNspacing
, &spacing
,
2801 XmNverticalScrollBar
, &sbar
,
2805 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2809 w
-= (spacing
+ wsbar
);
2811 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2817 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2818 short thick
, margin
;
2819 XtVaGetValues ((Widget
) m_borderWidget
,
2820 XmNshadowThickness
, &thick
,
2821 XmNmarginHeight
, &margin
,
2823 h
-= 2 * (thick
+ margin
);
2826 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2830 XtVaGetValues ((Widget
) m_scrolledWindow
,
2831 XmNspacing
, &spacing
,
2832 XmNhorizontalScrollBar
, &sbar
,
2836 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2840 h
-= (spacing
+ wsbar
);
2842 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2848 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2849 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2853 GetClientSize (&ww, &hh);
2854 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2855 sizeEvent.SetEventObject(this);
2857 GetEventHandler()->ProcessEvent(sizeEvent);
2862 void wxWindow::CanvasSetClientSize (int w
, int h
)
2864 Widget drawingArea
= (Widget
) m_drawingArea
;
2866 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2869 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2871 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2872 /* TODO: is this necessary?
2873 allowRepainting = FALSE;
2875 XSync (XtDisplay (drawingArea), FALSE);
2877 while (XtAppPending (wxTheApp->appContext))
2879 XFlush (XtDisplay (drawingArea));
2880 XtAppNextEvent (wxTheApp->appContext, &event);
2881 XtDispatchEvent (&event);
2885 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2888 allowRepainting = TRUE;
2893 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2894 sizeEvent.SetEventObject(this);
2896 GetEventHandler()->ProcessEvent(sizeEvent);
2900 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2902 // Must return the same thing that was set via SetClientSize
2904 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2909 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2912 if ((Widget
) m_borderWidget
)
2913 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2914 else if ((Widget
) m_scrolledWindow
)
2915 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2917 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2923 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2926 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2928 // We may be faking the client origin.
2929 // So a window that's really at (0, 30) may appear
2930 // (to wxWin apps) to be at (0, 0).
2933 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2942 // Add to hash table, add event handler
2943 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2944 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2946 wxAddWindowToTable((Widget
) mainWidget
, this);
2947 if (CanAddEventHandler())
2949 XtAddEventHandler((Widget
) mainWidget
,
2950 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2952 wxPanelItemEventHandler
,
2959 XtOverrideTranslations ((Widget
) mainWidget
,
2960 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2961 XtFree ((char *) ptr
);
2964 // Some widgets have a parent form widget, e.g. wxRadioBox
2967 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2971 XtOverrideTranslations ((Widget
) formWidget
,
2972 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2973 XtFree ((char *) ptr
);
2980 SetSize (x
, y
, width
, height
);
2985 // Remove event handler, remove from hash table
2986 bool wxWindow::DetachWidget(WXWidget widget
)
2988 if (CanAddEventHandler())
2990 XtRemoveEventHandler((Widget
) widget
,
2991 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2993 wxPanelItemEventHandler
,
2997 wxDeleteWindowFromTable((Widget
) widget
);
3001 void wxPanelItemEventHandler (Widget wid
,
3002 XtPointer client_data
,
3004 Boolean
*continueToDispatch
)
3006 // Widget can be a label or the actual widget.
3008 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3011 wxMouseEvent
wxevent(0);
3012 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3014 window
->GetEventHandler()->ProcessEvent(wxevent
);
3017 // TODO: probably the key to allowing default behaviour
3019 // Say we set a m_doDefault flag to FALSE at the start of this
3020 // function. Then in e.g. wxWindow::OnMouseEvent we can
3021 // call Default() which sets this flag to TRUE, indicating
3022 // that default processing can happen. Thus, behaviour can appear
3023 // to be overridden just by adding an event handler and not calling
3024 // wxWindow::OnWhatever.
3025 // ALSO, maybe we can use this instead of the current way of handling
3026 // drawing area events, to simplify things.
3027 *continueToDispatch
= True
;
3030 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3031 XmScaleCallbackStruct
*cbs
)
3033 Widget scrolledWindow
= XtParent (scrollbar
);
3034 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3035 int orientation
= (int) clientData
;
3037 wxEventType eventType
= wxEVT_NULL
;
3038 switch (cbs
->reason
)
3040 case XmCR_INCREMENT
:
3042 eventType
= wxEVT_SCROLL_LINEDOWN
;
3045 case XmCR_DECREMENT
:
3047 eventType
= wxEVT_SCROLL_LINEUP
;
3052 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3055 case XmCR_VALUE_CHANGED
:
3057 // TODO: Should this be intercepted too, or will it cause
3058 // duplicate events?
3059 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3062 case XmCR_PAGE_INCREMENT
:
3064 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3067 case XmCR_PAGE_DECREMENT
:
3069 eventType
= wxEVT_SCROLL_PAGEUP
;
3074 eventType
= wxEVT_SCROLL_TOP
;
3077 case XmCR_TO_BOTTOM
:
3079 eventType
= wxEVT_SCROLL_BOTTOM
;
3084 // Should never get here
3085 wxFAIL_MSG("Unknown scroll event.");
3090 wxScrollEvent
event(eventType
, win
->GetId());
3091 event
.SetEventObject(win
);
3092 event
.SetPosition(cbs
->value
);
3093 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3095 win
->GetEventHandler()->ProcessEvent(event
);
3098 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3100 switch (xevent
->xany
.type
)
3108 wxEventType eventType
= wxEVT_NULL
;
3110 if (xevent
->xany
.type
== LeaveNotify
)
3112 win
->m_button1Pressed
= FALSE
;
3113 win
->m_button2Pressed
= FALSE
;
3114 win
->m_button3Pressed
= FALSE
;
3117 else if (xevent
->xany
.type
== MotionNotify
)
3119 eventType
= wxEVT_MOTION
;
3121 else if (xevent
->xany
.type
== ButtonPress
)
3123 if (xevent
->xbutton
.button
== Button1
)
3125 eventType
= wxEVT_LEFT_DOWN
;
3126 win
->m_button1Pressed
= TRUE
;
3128 else if (xevent
->xbutton
.button
== Button2
)
3130 eventType
= wxEVT_MIDDLE_DOWN
;
3131 win
->m_button2Pressed
= TRUE
;
3133 else if (xevent
->xbutton
.button
== Button3
)
3135 eventType
= wxEVT_RIGHT_DOWN
;
3136 win
->m_button3Pressed
= TRUE
;
3139 else if (xevent
->xany
.type
== ButtonRelease
)
3141 if (xevent
->xbutton
.button
== Button1
)
3143 eventType
= wxEVT_LEFT_UP
;
3144 win
->m_button1Pressed
= FALSE
;
3146 else if (xevent
->xbutton
.button
== Button2
)
3148 eventType
= wxEVT_MIDDLE_UP
;
3149 win
->m_button2Pressed
= FALSE
;
3151 else if (xevent
->xbutton
.button
== Button3
)
3153 eventType
= wxEVT_RIGHT_UP
;
3154 win
->m_button3Pressed
= FALSE
;
3160 wxevent
.m_eventHandle
= (char *)xevent
;
3161 wxevent
.SetEventType(eventType
);
3164 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3167 win
->GetPosition(&x2
, &y2
);
3169 // The button x/y must be translated to wxWindows
3170 // window space - the widget might be a label or button,
3174 if (widget
!= (Widget
)win
->GetMainWidget())
3180 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3181 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3183 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3184 || (event_left_is_down (xevent
)
3185 && (eventType
!= wxEVT_LEFT_UP
)));
3186 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3187 || (event_middle_is_down (xevent
)
3188 && (eventType
!= wxEVT_MIDDLE_UP
)));
3189 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3190 || (event_right_is_down (xevent
)
3191 && (eventType
!= wxEVT_RIGHT_UP
)));
3193 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3194 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3201 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3203 switch (xevent
->xany
.type
)
3210 // XComposeStatus compose;
3211 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3212 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3213 int id
= wxCharCodeXToWX (keySym
);
3215 if (xevent
->xkey
.state
& ShiftMask
)
3216 wxevent
.m_shiftDown
= TRUE
;
3217 if (xevent
->xkey
.state
& ControlMask
)
3218 wxevent
.m_controlDown
= TRUE
;
3219 if (xevent
->xkey
.state
& Mod3Mask
)
3220 wxevent
.m_altDown
= TRUE
;
3221 if (xevent
->xkey
.state
& Mod1Mask
)
3222 wxevent
.m_metaDown
= TRUE
;
3223 wxevent
.SetEventObject(win
);
3224 wxevent
.m_keyCode
= id
;
3225 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3227 wxevent
.m_x
= xevent
->xbutton
.x
;
3228 wxevent
.m_y
= xevent
->xbutton
.y
;
3242 #define YAllocColor XAllocColor
3243 XColor g_itemColors
[5];
3244 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3247 static XmColorProc colorProc
;
3249 result
= wxNO_COLORS
;
3253 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3254 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3255 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3256 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3257 if (colorProc
== (XmColorProc
) NULL
)
3259 // Get a ptr to the actual function
3260 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3261 // And set it back to motif.
3262 XmSetColorCalculation (colorProc
);
3264 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3265 &g_itemColors
[wxFORE_INDEX
],
3266 &g_itemColors
[wxSELE_INDEX
],
3267 &g_itemColors
[wxTOPS_INDEX
],
3268 &g_itemColors
[wxBOTS_INDEX
]);
3269 result
= wxBACK_COLORS
;
3273 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3274 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3275 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3276 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3277 if (result
== wxNO_COLORS
)
3278 result
= wxFORE_COLORS
;
3281 Display
*dpy
= display
;
3282 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3286 /* 5 Colours to allocate */
3287 for (int i
= 0; i
< 5; i
++)
3288 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3289 result
= wxNO_COLORS
;
3293 /* Only 1 colour to allocate */
3294 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3295 result
= wxNO_COLORS
;
3302 // Changes the foreground and background colours to be derived
3303 // from the current background colour.
3304 // To change the foreground colour, you must call SetForegroundColour
3306 void wxWindow::ChangeBackgroundColour()
3308 if (GetMainWidget())
3309 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3311 // This not necessary
3314 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3316 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3317 // Have to set the scrollbar colours back since
3318 // the scrolled window seemed to change them
3319 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3322 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3324 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3329 void wxWindow::ChangeForegroundColour()
3331 if (GetMainWidget())
3332 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3333 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3334 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3337 // Change a widget's foreground and background colours.
3339 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3341 // When should we specify the foreground, if it's calculated
3342 // by wxComputeColours?
3343 // Solution: say we start with the default (computed) foreground colour.
3344 // If we call SetForegroundColour explicitly for a control or window,
3345 // then the foreground is changed.
3346 // Therefore SetBackgroundColour computes the foreground colour, and
3347 // SetForegroundColour changes the foreground colour. The ordering is
3350 XtVaSetValues ((Widget
) widget
,
3351 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3355 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3357 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3360 XtVaSetValues ((Widget
) widget
,
3361 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3362 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3363 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3364 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3367 if (changeArmColour
)
3368 XtVaSetValues ((Widget
) widget
,
3369 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3373 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3375 m_backgroundColour
= col
;
3376 ChangeBackgroundColour();
3379 void wxWindow::SetForegroundColour(const wxColour
& col
)
3381 m_foregroundColour
= col
;
3382 ChangeForegroundColour();
3385 void wxWindow::ChangeFont(bool keepOriginalSize
)
3387 // Note that this causes the widget to be resized back
3388 // to its original size! We therefore have to set the size
3389 // back again. TODO: a better way in Motif?
3390 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3391 if (w
&& m_windowFont
.Ok())
3393 int width
, height
, width1
, height1
;
3394 GetSize(& width
, & height
);
3396 // lesstif 0.87 hangs here
3397 #ifndef LESSTIF_VERSION
3399 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3403 GetSize(& width1
, & height1
);
3404 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3406 SetSize(-1, -1, width
, height
);
3411 void wxWindow::SetFont(const wxFont
& font
)
3413 m_windowFont
= font
;
3417 void wxWindow::SetToolTip(const wxString
& tooltip
)
3422 void wxWindow::ClearUpdateRects()
3424 wxNode
* node
= m_updateRects
.First();
3427 wxRect
* rect
= (wxRect
*) node
->Data();
3429 node
= node
->Next();
3431 m_updateRects
.Clear();
3434 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3436 if (!m_acceleratorTable
.Ok())
3439 int count
= m_acceleratorTable
.GetCount();
3440 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3442 for (i
= 0; i
< count
; i
++)
3444 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3445 if (entry
->MatchesEvent(event
))
3447 // Bingo, we have a match. Now find a control
3448 // that matches the entry command id.
3450 // Need to go up to the top of the window hierarchy,
3451 // since it might be e.g. a menu item
3452 wxWindow
* parent
= this;
3453 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3454 parent
= parent
->GetParent();
3459 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3461 // Try for a menu command
3462 wxFrame
* frame
= (wxFrame
*) parent
;
3463 if (frame
->GetMenuBar())
3465 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3468 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3469 commandEvent
.SetEventObject(frame
);
3471 // If ProcessEvent returns TRUE (it was handled), then
3472 // the calling code will skip the event handling.
3473 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3478 // Find a child matching the command id
3479 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3485 // Now we process those kinds of windows that we can.
3486 // For now, only buttons.
3487 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3489 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3490 commandEvent
.SetEventObject(child
);
3491 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3498 // We didn't match the key event against an accelerator.
3503 * wxNoOptimize: switch off size optimization
3506 int wxNoOptimize::m_count
= 0;
3508 wxNoOptimize::wxNoOptimize()
3513 wxNoOptimize::~wxNoOptimize()
3518 bool wxNoOptimize::CanOptimize()
3520 return (m_count
== 0);