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 #if WXWIN_COMPATIBILITY
2068 event
.SetForce(force
);
2070 event
.SetCanVeto(!force
);
2072 return GetEventHandler()->ProcessEvent(event
);
2075 wxObject
* wxWindow::GetChild(int number
) const
2077 // Return a pointer to the Nth object in the window
2078 wxNode
*node
= GetChildren().First();
2081 node
= node
->Next() ;
2084 wxObject
*obj
= (wxObject
*)node
->Data();
2091 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2093 // Obsolete function
2096 void wxWindow::Clear()
2098 wxClientDC
dc(this);
2099 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2100 dc
.SetBackground(brush
);
2104 // Fits the panel around the items
2105 void wxWindow::Fit()
2109 wxNode
*node
= GetChildren().First();
2112 wxWindow
*win
= (wxWindow
*)node
->Data();
2114 win
->GetPosition(&wx
, &wy
);
2115 win
->GetSize(&ww
, &wh
);
2116 if ( wx
+ ww
> maxX
)
2118 if ( wy
+ wh
> maxY
)
2121 node
= node
->Next();
2123 SetClientSize(maxX
+ 5, maxY
+ 5);
2126 void wxWindow::SetValidator(const wxValidator
& validator
)
2128 if ( m_windowValidator
)
2129 delete m_windowValidator
;
2130 m_windowValidator
= validator
.Clone();
2132 if ( m_windowValidator
)
2133 m_windowValidator
->SetWindow(this) ;
2136 void wxWindow::SetClientObject( wxClientData
*data
)
2138 if (m_clientObject
) delete m_clientObject
;
2139 m_clientObject
= data
;
2142 wxClientData
*wxWindow::GetClientObject()
2144 return m_clientObject
;
2147 void wxWindow::SetClientData( void *data
)
2149 m_clientData
= data
;
2152 void *wxWindow::GetClientData()
2154 return m_clientData
;
2157 // Find a window by id or name
2158 wxWindow
*wxWindow::FindWindow(long id
)
2163 wxNode
*node
= GetChildren().First();
2166 wxWindow
*child
= (wxWindow
*)node
->Data();
2167 wxWindow
*found
= child
->FindWindow(id
);
2170 node
= node
->Next();
2175 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2177 if ( GetName() == name
)
2180 wxNode
*node
= GetChildren().First();
2183 wxWindow
*child
= (wxWindow
*)node
->Data();
2184 wxWindow
*found
= child
->FindWindow(name
);
2187 node
= node
->Next();
2192 void wxWindow::OnIdle(wxIdleEvent
& event
)
2194 // This calls the UI-update mechanism (querying windows for
2195 // menu/toolbar/control state information)
2199 // Raise the window to the top of the Z order
2200 void wxWindow::Raise()
2202 Window window
= XtWindow((Widget
) GetTopWidget());
2203 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2206 // Lower the window to the bottom of the Z order
2207 void wxWindow::Lower()
2209 Window window
= XtWindow((Widget
) GetTopWidget());
2210 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2213 bool wxWindow::AcceptsFocus() const
2215 return IsShown() && IsEnabled();
2218 // Update region access
2219 wxRegion
& wxWindow::GetUpdateRegion() const
2221 return (wxRegion
&) m_updateRegion
;
2224 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2226 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2229 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2231 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2234 bool wxWindow::IsExposed(const wxRect
& rect
) const
2236 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2240 * Allocates control IDs
2243 int wxWindow::NewControlId()
2245 static int s_controlId
= 0;
2250 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2252 m_acceleratorTable
= accel
;
2255 // All widgets should have this as their resize proc.
2256 // OnSize sent to wxWindow via client data.
2257 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2259 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2263 if (win
->PreResize())
2266 win
->GetSize(&width
, &height
);
2267 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2268 sizeEvent
.SetEventObject(win
);
2269 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2273 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2275 wxWindow
*oldItem
= NULL
;
2276 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2277 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2279 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2283 wxWidgetHashTable
->Put ((long) w
, win
);
2287 wxWindow
*wxGetWindowFromTable(Widget w
)
2289 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2292 void wxDeleteWindowFromTable(Widget w
)
2294 wxWidgetHashTable
->Delete((long)w
);
2297 // Get the underlying X window and display
2298 WXWindow
wxWindow::GetXWindow() const
2300 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2303 WXDisplay
*wxWindow::GetXDisplay() const
2305 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2308 WXWidget
wxWindow::GetMainWidget() const
2311 return m_drawingArea
;
2313 return m_mainWidget
;
2316 WXWidget
wxWindow::GetClientWidget() const
2318 if (m_drawingArea
!= (WXWidget
) 0)
2319 return m_drawingArea
;
2321 return GetMainWidget();
2324 WXWidget
wxWindow::GetTopWidget() const
2326 return GetMainWidget();
2329 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2330 XmDrawingAreaCallbackStruct
* cbs
)
2332 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2335 XEvent
* event
= cbs
->event
;
2336 wxWindow
* win
= (wxWindow
*) clientData
;
2337 Display
* display
= (Display
*) win
->GetXDisplay();
2339 switch (event
->type
)
2343 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2344 event
->xexpose
.width
, event
->xexpose
.height
);
2346 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2347 cout << rect->width << ", " << rect->height << "\n\n";
2350 win
->m_updateRects
.Append((wxObject
*) rect
);
2352 if (event
-> xexpose
.count
== 0)
2354 wxPaintEvent
event(win
->GetId());
2355 event
.SetEventObject(win
);
2356 win
->GetEventHandler()->ProcessEvent(event
);
2358 win
->ClearUpdateRects();
2364 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2370 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2372 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2374 XmDrawingAreaCallbackStruct cbs
;
2377 //if (event->mode!=NotifyNormal)
2380 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2381 ((XCrossingEvent
&) ev
) = *event
;
2383 cbs
.reason
= XmCR_INPUT
;
2386 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2389 // Fix to make it work under Motif 1.0 (!)
2390 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2394 XmDrawingAreaCallbackStruct cbs
;
2397 //ev.xbutton = *event;
2398 ev
= *((XEvent
*) event
);
2399 cbs
.reason
= XmCR_INPUT
;
2402 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2406 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2408 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2414 if (cbs
->reason
!= XmCR_INPUT
)
2417 local_event
= *(cbs
->event
); // We must keep a copy!
2420 switch (local_event.xany.type)
2423 cout << "EnterNotify\n";
2426 cout << "LeaveNotify\n";
2429 cout << "ButtonPress\n";
2432 cout << "ButtonRelease\n";
2435 cout << "MotionNotify\n";
2438 cout << "Something else\n";
2443 switch (local_event
.xany
.type
)
2451 wxEventType eventType
= wxEVT_NULL
;
2453 if (local_event
.xany
.type
== EnterNotify
)
2455 //if (local_event.xcrossing.mode!=NotifyNormal)
2456 // return ; // Ignore grab events
2457 eventType
= wxEVT_ENTER_WINDOW
;
2458 // canvas->GetEventHandler()->OnSetFocus();
2460 else if (local_event
.xany
.type
== LeaveNotify
)
2462 //if (local_event.xcrossing.mode!=NotifyNormal)
2463 // return ; // Ignore grab events
2464 eventType
= wxEVT_LEAVE_WINDOW
;
2465 // canvas->GetEventHandler()->OnKillFocus();
2467 else if (local_event
.xany
.type
== MotionNotify
)
2469 eventType
= wxEVT_MOTION
;
2470 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2473 Display
*dpy
= XtDisplay (drawingArea
);
2475 XQueryPointer (dpy
, XtWindow (drawingArea
),
2477 &local_event
.xmotion
.x_root
,
2478 &local_event
.xmotion
.y_root
,
2479 &local_event
.xmotion
.x
,
2480 &local_event
.xmotion
.y
,
2481 &local_event
.xmotion
.state
);
2488 else if (local_event
.xany
.type
== ButtonPress
)
2490 if (local_event
.xbutton
.button
== Button1
)
2492 eventType
= wxEVT_LEFT_DOWN
;
2493 canvas
->m_button1Pressed
= TRUE
;
2495 else if (local_event
.xbutton
.button
== Button2
)
2497 eventType
= wxEVT_MIDDLE_DOWN
;
2498 canvas
->m_button2Pressed
= TRUE
;
2500 else if (local_event
.xbutton
.button
== Button3
)
2502 eventType
= wxEVT_RIGHT_DOWN
;
2503 canvas
->m_button3Pressed
= TRUE
;
2506 else if (local_event
.xany
.type
== ButtonRelease
)
2508 if (local_event
.xbutton
.button
== Button1
)
2510 eventType
= wxEVT_LEFT_UP
;
2511 canvas
->m_button1Pressed
= FALSE
;
2513 else if (local_event
.xbutton
.button
== Button2
)
2515 eventType
= wxEVT_MIDDLE_UP
;
2516 canvas
->m_button2Pressed
= FALSE
;
2518 else if (local_event
.xbutton
.button
== Button3
)
2520 eventType
= wxEVT_RIGHT_UP
;
2521 canvas
->m_button3Pressed
= FALSE
;
2525 wxMouseEvent
wxevent (eventType
);
2526 wxevent
.m_eventHandle
= (char *) &local_event
;
2528 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2529 || (event_left_is_down (&local_event
)
2530 && (eventType
!= wxEVT_LEFT_UP
)));
2531 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2532 || (event_middle_is_down (&local_event
)
2533 && (eventType
!= wxEVT_MIDDLE_UP
)));
2534 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2535 || (event_right_is_down (&local_event
)
2536 && (eventType
!= wxEVT_RIGHT_UP
)));
2538 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2539 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2540 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2541 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2542 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2544 // Now check if we need to translate this event into a double click
2545 if (TRUE
) // canvas->doubleClickAllowed)
2547 if (wxevent
.ButtonDown())
2549 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2551 // get button and time-stamp
2553 if (wxevent
.LeftDown()) button
= 1;
2554 else if (wxevent
.MiddleDown()) button
= 2;
2555 else if (wxevent
.RightDown()) button
= 3;
2556 long ts
= wxevent
.GetTimestamp();
2557 // check, if single or double click
2558 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2561 canvas
->m_lastButton
= 0;
2562 switch ( eventType
)
2564 case wxEVT_LEFT_DOWN
:
2565 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2567 case wxEVT_MIDDLE_DOWN
:
2568 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2570 case wxEVT_RIGHT_DOWN
:
2571 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2581 // not fast enough or different button
2582 canvas
->m_lastTS
= ts
;
2583 canvas
->m_lastButton
= button
;
2588 wxevent
.SetId(canvas
->GetId());
2589 wxevent
.SetEventObject(canvas
);
2590 wxevent
.m_x
= local_event
.xbutton
.x
;
2591 wxevent
.m_y
= local_event
.xbutton
.y
;
2592 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2594 if (eventType == wxEVT_ENTER_WINDOW ||
2595 eventType == wxEVT_LEAVE_WINDOW ||
2596 eventType == wxEVT_MOTION
2605 // XComposeStatus compose;
2606 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2607 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2608 int id
= wxCharCodeXToWX (keySym
);
2610 wxEventType eventType
= wxEVT_CHAR
;
2612 // TODO: Is this the correct criterion for wxEVT_KEY_DOWN down versus wxEVT_CHAR?
2613 if (id
> WXK_START
) // Non-ASCII values
2614 eventType
= wxEVT_KEY_DOWN
;
2616 wxKeyEvent
event (eventType
);
2618 if (local_event
.xkey
.state
& ShiftMask
)
2619 event
.m_shiftDown
= TRUE
;
2620 if (local_event
.xkey
.state
& ControlMask
)
2621 event
.m_controlDown
= TRUE
;
2622 if (local_event
.xkey
.state
& Mod3Mask
)
2623 event
.m_altDown
= TRUE
;
2624 if (local_event
.xkey
.state
& Mod1Mask
)
2625 event
.m_metaDown
= TRUE
;
2626 event
.SetEventObject(canvas
);
2627 event
.m_keyCode
= id
;
2628 event
.SetTimestamp(local_event
.xkey
.time
);
2632 // Implement wxFrame::OnCharHook by checking ancestor.
2633 wxWindow
*parent
= canvas
->GetParent();
2634 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2635 parent
= parent
->GetParent();
2639 event
.SetEventType(wxEVT_CHAR_HOOK
);
2640 if (parent
->GetEventHandler()->ProcessEvent(event
))
2642 event
.SetEventType(wxEVT_CHAR
);
2645 canvas
->GetEventHandler()->ProcessEvent (event
);
2652 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2653 int id
= wxCharCodeXToWX (keySym
);
2655 wxKeyEvent
event (wxEVT_KEY_UP
);
2657 if (local_event
.xkey
.state
& ShiftMask
)
2658 event
.m_shiftDown
= TRUE
;
2659 if (local_event
.xkey
.state
& ControlMask
)
2660 event
.m_controlDown
= TRUE
;
2661 if (local_event
.xkey
.state
& Mod3Mask
)
2662 event
.m_altDown
= TRUE
;
2663 if (local_event
.xkey
.state
& Mod1Mask
)
2664 event
.m_metaDown
= TRUE
;
2665 event
.SetEventObject(canvas
);
2666 event
.m_keyCode
= id
;
2667 event
.SetTimestamp(local_event
.xkey
.time
);
2671 canvas
->GetEventHandler()->ProcessEvent (event
);
2677 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2679 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2680 event
.SetEventObject(canvas
);
2681 canvas
->GetEventHandler()->ProcessEvent(event
);
2687 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2689 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2690 event
.SetEventObject(canvas
);
2691 canvas
->GetEventHandler()->ProcessEvent(event
);
2700 void wxWindow::DoPaint()
2702 //TODO : make a temporary gc so we can do the XCopyArea below
2703 if (0) // m_backingPixmap)
2706 Widget drawingArea = (Widget) m_drawingArea;
2707 // int orig = GetDC()->GetLogicalFunction();
2708 // GetDC()->SetLogicalFunction (wxCOPY);
2710 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2711 // should be able to calculate them.
2712 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2713 m_pixmapOffsetX, m_pixmapOffsetY,
2714 m_pixmapWidth, m_pixmapHeight,
2717 // GetDC()->SetLogicalFunction (orig);
2722 wxPaintEvent
event(GetId());
2723 event
.SetEventObject(this);
2724 GetEventHandler()->ProcessEvent(event
);
2728 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2729 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2731 // A bit of optimization to help sort out the flickers.
2732 int oldX
, oldY
, oldW
, oldH
;
2733 GetSize(& oldW
, & oldH
);
2734 GetPosition(& oldX
, & oldY
);
2736 bool useOldPos
= FALSE
;
2737 bool useOldSize
= FALSE
;
2739 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2741 else if (x
== oldX
&& y
== oldY
)
2744 if ((w
== -1) && (h
== -1))
2746 else if (w
== oldW
&& h
== oldH
)
2749 if (!wxNoOptimize::CanOptimize())
2751 useOldSize
= FALSE
; useOldPos
= FALSE
;
2754 if (useOldPos
&& useOldSize
)
2757 Widget drawingArea
= (Widget
) m_drawingArea
;
2758 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2761 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2762 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2764 int xx
= x
; int yy
= y
;
2765 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2769 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2771 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2775 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2777 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2789 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2790 short thick
, margin
;
2791 XtVaGetValues ((Widget
) m_borderWidget
,
2792 XmNshadowThickness
, &thick
,
2793 XmNmarginWidth
, &margin
,
2795 w
-= 2 * (thick
+ margin
);
2798 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2802 XtVaGetValues ((Widget
) m_scrolledWindow
,
2803 XmNspacing
, &spacing
,
2804 XmNverticalScrollBar
, &sbar
,
2808 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2812 w
-= (spacing
+ wsbar
);
2814 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2820 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2821 short thick
, margin
;
2822 XtVaGetValues ((Widget
) m_borderWidget
,
2823 XmNshadowThickness
, &thick
,
2824 XmNmarginHeight
, &margin
,
2826 h
-= 2 * (thick
+ margin
);
2829 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2833 XtVaGetValues ((Widget
) m_scrolledWindow
,
2834 XmNspacing
, &spacing
,
2835 XmNhorizontalScrollBar
, &sbar
,
2839 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2843 h
-= (spacing
+ wsbar
);
2845 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2851 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2852 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2856 GetClientSize (&ww, &hh);
2857 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2858 sizeEvent.SetEventObject(this);
2860 GetEventHandler()->ProcessEvent(sizeEvent);
2865 void wxWindow::CanvasSetClientSize (int w
, int h
)
2867 Widget drawingArea
= (Widget
) m_drawingArea
;
2869 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2872 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2874 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2875 /* TODO: is this necessary?
2876 allowRepainting = FALSE;
2878 XSync (XtDisplay (drawingArea), FALSE);
2880 while (XtAppPending (wxTheApp->appContext))
2882 XFlush (XtDisplay (drawingArea));
2883 XtAppNextEvent (wxTheApp->appContext, &event);
2884 XtDispatchEvent (&event);
2888 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2891 allowRepainting = TRUE;
2896 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2897 sizeEvent.SetEventObject(this);
2899 GetEventHandler()->ProcessEvent(sizeEvent);
2903 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2905 // Must return the same thing that was set via SetClientSize
2907 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2912 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2915 if ((Widget
) m_borderWidget
)
2916 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2917 else if ((Widget
) m_scrolledWindow
)
2918 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2920 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2926 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2929 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2931 // We may be faking the client origin.
2932 // So a window that's really at (0, 30) may appear
2933 // (to wxWin apps) to be at (0, 0).
2936 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2945 // Add to hash table, add event handler
2946 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2947 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2949 wxAddWindowToTable((Widget
) mainWidget
, this);
2950 if (CanAddEventHandler())
2952 XtAddEventHandler((Widget
) mainWidget
,
2953 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2955 wxPanelItemEventHandler
,
2962 XtOverrideTranslations ((Widget
) mainWidget
,
2963 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2964 XtFree ((char *) ptr
);
2967 // Some widgets have a parent form widget, e.g. wxRadioBox
2970 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2974 XtOverrideTranslations ((Widget
) formWidget
,
2975 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2976 XtFree ((char *) ptr
);
2983 SetSize (x
, y
, width
, height
);
2988 // Remove event handler, remove from hash table
2989 bool wxWindow::DetachWidget(WXWidget widget
)
2991 if (CanAddEventHandler())
2993 XtRemoveEventHandler((Widget
) widget
,
2994 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2996 wxPanelItemEventHandler
,
3000 wxDeleteWindowFromTable((Widget
) widget
);
3004 void wxPanelItemEventHandler (Widget wid
,
3005 XtPointer client_data
,
3007 Boolean
*continueToDispatch
)
3009 // Widget can be a label or the actual widget.
3011 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3014 wxMouseEvent
wxevent(0);
3015 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3017 window
->GetEventHandler()->ProcessEvent(wxevent
);
3020 // TODO: probably the key to allowing default behaviour
3022 // Say we set a m_doDefault flag to FALSE at the start of this
3023 // function. Then in e.g. wxWindow::OnMouseEvent we can
3024 // call Default() which sets this flag to TRUE, indicating
3025 // that default processing can happen. Thus, behaviour can appear
3026 // to be overridden just by adding an event handler and not calling
3027 // wxWindow::OnWhatever.
3028 // ALSO, maybe we can use this instead of the current way of handling
3029 // drawing area events, to simplify things.
3030 *continueToDispatch
= True
;
3033 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3034 XmScaleCallbackStruct
*cbs
)
3036 Widget scrolledWindow
= XtParent (scrollbar
);
3037 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3038 int orientation
= (int) clientData
;
3040 wxEventType eventType
= wxEVT_NULL
;
3041 switch (cbs
->reason
)
3043 case XmCR_INCREMENT
:
3045 eventType
= wxEVT_SCROLL_LINEDOWN
;
3048 case XmCR_DECREMENT
:
3050 eventType
= wxEVT_SCROLL_LINEUP
;
3055 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3058 case XmCR_VALUE_CHANGED
:
3060 // TODO: Should this be intercepted too, or will it cause
3061 // duplicate events?
3062 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3065 case XmCR_PAGE_INCREMENT
:
3067 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3070 case XmCR_PAGE_DECREMENT
:
3072 eventType
= wxEVT_SCROLL_PAGEUP
;
3077 eventType
= wxEVT_SCROLL_TOP
;
3080 case XmCR_TO_BOTTOM
:
3082 eventType
= wxEVT_SCROLL_BOTTOM
;
3087 // Should never get here
3088 wxFAIL_MSG("Unknown scroll event.");
3093 wxScrollEvent
event(eventType
, win
->GetId());
3094 event
.SetEventObject(win
);
3095 event
.SetPosition(cbs
->value
);
3096 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3098 win
->GetEventHandler()->ProcessEvent(event
);
3101 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3103 switch (xevent
->xany
.type
)
3111 wxEventType eventType
= wxEVT_NULL
;
3113 if (xevent
->xany
.type
== LeaveNotify
)
3115 win
->m_button1Pressed
= FALSE
;
3116 win
->m_button2Pressed
= FALSE
;
3117 win
->m_button3Pressed
= FALSE
;
3120 else if (xevent
->xany
.type
== MotionNotify
)
3122 eventType
= wxEVT_MOTION
;
3124 else if (xevent
->xany
.type
== ButtonPress
)
3126 if (xevent
->xbutton
.button
== Button1
)
3128 eventType
= wxEVT_LEFT_DOWN
;
3129 win
->m_button1Pressed
= TRUE
;
3131 else if (xevent
->xbutton
.button
== Button2
)
3133 eventType
= wxEVT_MIDDLE_DOWN
;
3134 win
->m_button2Pressed
= TRUE
;
3136 else if (xevent
->xbutton
.button
== Button3
)
3138 eventType
= wxEVT_RIGHT_DOWN
;
3139 win
->m_button3Pressed
= TRUE
;
3142 else if (xevent
->xany
.type
== ButtonRelease
)
3144 if (xevent
->xbutton
.button
== Button1
)
3146 eventType
= wxEVT_LEFT_UP
;
3147 win
->m_button1Pressed
= FALSE
;
3149 else if (xevent
->xbutton
.button
== Button2
)
3151 eventType
= wxEVT_MIDDLE_UP
;
3152 win
->m_button2Pressed
= FALSE
;
3154 else if (xevent
->xbutton
.button
== Button3
)
3156 eventType
= wxEVT_RIGHT_UP
;
3157 win
->m_button3Pressed
= FALSE
;
3163 wxevent
.m_eventHandle
= (char *)xevent
;
3164 wxevent
.SetEventType(eventType
);
3167 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3170 win
->GetPosition(&x2
, &y2
);
3172 // The button x/y must be translated to wxWindows
3173 // window space - the widget might be a label or button,
3177 if (widget
!= (Widget
)win
->GetMainWidget())
3183 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3184 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3186 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3187 || (event_left_is_down (xevent
)
3188 && (eventType
!= wxEVT_LEFT_UP
)));
3189 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3190 || (event_middle_is_down (xevent
)
3191 && (eventType
!= wxEVT_MIDDLE_UP
)));
3192 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3193 || (event_right_is_down (xevent
)
3194 && (eventType
!= wxEVT_RIGHT_UP
)));
3196 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3197 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3204 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3206 switch (xevent
->xany
.type
)
3213 // XComposeStatus compose;
3214 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3215 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3216 int id
= wxCharCodeXToWX (keySym
);
3218 if (xevent
->xkey
.state
& ShiftMask
)
3219 wxevent
.m_shiftDown
= TRUE
;
3220 if (xevent
->xkey
.state
& ControlMask
)
3221 wxevent
.m_controlDown
= TRUE
;
3222 if (xevent
->xkey
.state
& Mod3Mask
)
3223 wxevent
.m_altDown
= TRUE
;
3224 if (xevent
->xkey
.state
& Mod1Mask
)
3225 wxevent
.m_metaDown
= TRUE
;
3226 wxevent
.SetEventObject(win
);
3227 wxevent
.m_keyCode
= id
;
3228 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3230 wxevent
.m_x
= xevent
->xbutton
.x
;
3231 wxevent
.m_y
= xevent
->xbutton
.y
;
3245 #define YAllocColor XAllocColor
3246 XColor g_itemColors
[5];
3247 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3250 static XmColorProc colorProc
;
3252 result
= wxNO_COLORS
;
3256 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3257 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3258 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3259 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3260 if (colorProc
== (XmColorProc
) NULL
)
3262 // Get a ptr to the actual function
3263 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3264 // And set it back to motif.
3265 XmSetColorCalculation (colorProc
);
3267 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3268 &g_itemColors
[wxFORE_INDEX
],
3269 &g_itemColors
[wxSELE_INDEX
],
3270 &g_itemColors
[wxTOPS_INDEX
],
3271 &g_itemColors
[wxBOTS_INDEX
]);
3272 result
= wxBACK_COLORS
;
3276 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3277 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3278 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3279 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3280 if (result
== wxNO_COLORS
)
3281 result
= wxFORE_COLORS
;
3284 Display
*dpy
= display
;
3285 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3289 /* 5 Colours to allocate */
3290 for (int i
= 0; i
< 5; i
++)
3291 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3292 result
= wxNO_COLORS
;
3296 /* Only 1 colour to allocate */
3297 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3298 result
= wxNO_COLORS
;
3305 // Changes the foreground and background colours to be derived
3306 // from the current background colour.
3307 // To change the foreground colour, you must call SetForegroundColour
3309 void wxWindow::ChangeBackgroundColour()
3311 if (GetMainWidget())
3312 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3314 // This not necessary
3317 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3319 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3320 // Have to set the scrollbar colours back since
3321 // the scrolled window seemed to change them
3322 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3325 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3327 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3332 void wxWindow::ChangeForegroundColour()
3334 if (GetMainWidget())
3335 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3336 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3337 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3340 // Change a widget's foreground and background colours.
3342 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3344 // When should we specify the foreground, if it's calculated
3345 // by wxComputeColours?
3346 // Solution: say we start with the default (computed) foreground colour.
3347 // If we call SetForegroundColour explicitly for a control or window,
3348 // then the foreground is changed.
3349 // Therefore SetBackgroundColour computes the foreground colour, and
3350 // SetForegroundColour changes the foreground colour. The ordering is
3353 XtVaSetValues ((Widget
) widget
,
3354 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3358 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3360 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3363 XtVaSetValues ((Widget
) widget
,
3364 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3365 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3366 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3367 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3370 if (changeArmColour
)
3371 XtVaSetValues ((Widget
) widget
,
3372 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3376 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3378 m_backgroundColour
= col
;
3379 ChangeBackgroundColour();
3382 void wxWindow::SetForegroundColour(const wxColour
& col
)
3384 m_foregroundColour
= col
;
3385 ChangeForegroundColour();
3388 void wxWindow::ChangeFont(bool keepOriginalSize
)
3390 // Note that this causes the widget to be resized back
3391 // to its original size! We therefore have to set the size
3392 // back again. TODO: a better way in Motif?
3393 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3394 if (w
&& m_windowFont
.Ok())
3396 int width
, height
, width1
, height1
;
3397 GetSize(& width
, & height
);
3399 // lesstif 0.87 hangs here
3400 #ifndef LESSTIF_VERSION
3402 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3406 GetSize(& width1
, & height1
);
3407 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3409 SetSize(-1, -1, width
, height
);
3414 void wxWindow::SetFont(const wxFont
& font
)
3416 m_windowFont
= font
;
3420 void wxWindow::SetToolTip(const wxString
& tooltip
)
3425 void wxWindow::ClearUpdateRects()
3427 wxNode
* node
= m_updateRects
.First();
3430 wxRect
* rect
= (wxRect
*) node
->Data();
3432 node
= node
->Next();
3434 m_updateRects
.Clear();
3437 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3439 if (!m_acceleratorTable
.Ok())
3442 int count
= m_acceleratorTable
.GetCount();
3443 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3445 for (i
= 0; i
< count
; i
++)
3447 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3448 if (entry
->MatchesEvent(event
))
3450 // Bingo, we have a match. Now find a control
3451 // that matches the entry command id.
3453 // Need to go up to the top of the window hierarchy,
3454 // since it might be e.g. a menu item
3455 wxWindow
* parent
= this;
3456 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3457 parent
= parent
->GetParent();
3462 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3464 // Try for a menu command
3465 wxFrame
* frame
= (wxFrame
*) parent
;
3466 if (frame
->GetMenuBar())
3468 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3471 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3472 commandEvent
.SetEventObject(frame
);
3474 // If ProcessEvent returns TRUE (it was handled), then
3475 // the calling code will skip the event handling.
3476 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3481 // Find a child matching the command id
3482 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3488 // Now we process those kinds of windows that we can.
3489 // For now, only buttons.
3490 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3492 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3493 commandEvent
.SetEventObject(child
);
3494 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3501 // We didn't match the key event against an accelerator.
3506 * wxNoOptimize: switch off size optimization
3509 int wxNoOptimize::m_count
= 0;
3511 wxNoOptimize::wxNoOptimize()
3516 wxNoOptimize::~wxNoOptimize()
3521 bool wxNoOptimize::CanOptimize()
3523 return (m_count
== 0);