1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/menuitem.h"
34 #if wxUSE_DRAG_AND_DROP
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
46 #include "wx/motif/private.h"
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
52 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
54 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
55 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
56 XmScaleCallbackStruct
*cbs
);
57 void wxPanelItemEventHandler (Widget wid
,
58 XtPointer client_data
,
60 Boolean
*continueToDispatch
);
62 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
63 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
64 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
66 extern wxList wxPendingDelete
;
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
71 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
72 EVT_CHAR(wxWindow::OnChar
)
73 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
74 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
75 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
76 EVT_IDLE(wxWindow::OnIdle
)
88 m_windowParent
= NULL
;
89 m_windowEventHandler
= this;
91 m_windowCursor
= *wxSTANDARD_CURSOR
;
92 m_children
= new wxList
;
94 m_constraintsInvolvedIn
= NULL
;
98 m_windowValidator
= NULL
;
101 m_caretWidth
= 0; m_caretHeight
= 0;
102 m_caretEnabled
= FALSE
;
103 m_caretShown
= FALSE
;
104 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
105 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
106 m_foregroundColour
= *wxBLACK
;
108 #if wxUSE_DRAG_AND_DROP
109 m_pDropTarget
= NULL
;
111 m_clientObject
= (wxClientData
*) NULL
;
115 m_mainWidget
= (WXWidget
) 0;
116 m_button1Pressed
= FALSE
;
117 m_button2Pressed
= FALSE
;
118 m_button3Pressed
= FALSE
;
119 m_winCaptured
= FALSE
;
121 m_hScrollBar
= (WXWidget
) 0;
122 m_vScrollBar
= (WXWidget
) 0;
123 m_borderWidget
= (WXWidget
) 0;
124 m_scrolledWindow
= (WXWidget
) 0;
125 m_drawingArea
= (WXWidget
) 0;
128 m_backingPixmap
= (WXPixmap
) 0;
135 m_canAddEventHandler
= FALSE
;
141 wxWindow::~wxWindow()
146 DetachWidget(GetMainWidget()); // Removes event handlers
148 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
151 // Destroy children before destroying self
155 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
157 Widget w
= (Widget
) m_drawingArea
;
158 wxDeleteWindowFromTable(w
);
162 m_mainWidget
= (WXWidget
) 0;
164 // Only if we're _really_ a canvas (not a dialog box/panel)
165 if (m_scrolledWindow
)
167 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
172 XtUnmanageChild ((Widget
) m_hScrollBar
);
173 XtDestroyWidget ((Widget
) m_hScrollBar
);
177 XtUnmanageChild ((Widget
) m_vScrollBar
);
178 XtDestroyWidget ((Widget
) m_vScrollBar
);
180 if (m_scrolledWindow
)
182 XtUnmanageChild ((Widget
) m_scrolledWindow
);
183 XtDestroyWidget ((Widget
) m_scrolledWindow
);
188 XtDestroyWidget ((Widget
) m_borderWidget
);
189 m_borderWidget
= (WXWidget
) 0;
195 // Have to delete constraints/sizer FIRST otherwise
196 // sizers may try to look at deleted windows as they
197 // delete themselves.
198 #if wxUSE_CONSTRAINTS
199 DeleteRelatedConstraints();
202 // This removes any dangling pointers to this window
203 // in other windows' constraintsInvolvedIn lists.
204 UnsetConstraints(m_constraints
);
205 delete m_constraints
;
206 m_constraints
= NULL
;
210 delete m_windowSizer
;
211 m_windowSizer
= NULL
;
213 // If this is a child of a sizer, remove self from parent
215 m_sizerParent
->RemoveChild((wxWindow
*)this);
219 m_windowParent
->RemoveChild(this);
223 // Destroy the window
226 wxDeleteWindowFromTable((Widget
) GetMainWidget());
227 XtDestroyWidget((Widget
) GetMainWidget());
228 SetMainWidget((WXWidget
) NULL
);
234 // Just in case the window has been Closed, but
235 // we're then deleting immediately: don't leave
236 // dangling pointers.
237 wxPendingDelete
.DeleteObject(this);
239 if ( m_windowValidator
) delete m_windowValidator
;
240 if (m_clientObject
) delete m_clientObject
;
245 // Destroy the window (delayed, if a managed window)
246 bool wxWindow::Destroy()
253 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
257 const wxString
& name
)
262 m_windowParent
= NULL
;
263 m_windowEventHandler
= this;
265 m_windowCursor
= *wxSTANDARD_CURSOR
;
266 m_constraints
= NULL
;
267 m_constraintsInvolvedIn
= NULL
;
268 m_windowSizer
= NULL
;
269 m_sizerParent
= NULL
;
270 m_autoLayout
= FALSE
;
271 m_windowValidator
= NULL
;
272 #if wxUSE_DRAG_AND_DROP
273 m_pDropTarget
= NULL
;
275 m_caretWidth
= 0; m_caretHeight
= 0;
276 m_caretEnabled
= FALSE
;
277 m_caretShown
= FALSE
;
282 m_defaultItem
= NULL
;
283 m_windowParent
= NULL
;
284 m_clientObject
= (wxClientData
*) NULL
;
288 m_canAddEventHandler
= FALSE
;
289 m_mainWidget
= (WXWidget
) 0;
290 m_button1Pressed
= FALSE
;
291 m_button2Pressed
= FALSE
;
292 m_button3Pressed
= FALSE
;
293 m_winCaptured
= FALSE
;
295 m_hScrollBar
= (WXWidget
) 0;
296 m_vScrollBar
= (WXWidget
) 0;
297 m_borderWidget
= (WXWidget
) 0;
298 m_scrolledWindow
= (WXWidget
) 0;
299 m_drawingArea
= (WXWidget
) 0;
302 m_backingPixmap
= (WXPixmap
) 0;
313 if (parent
) parent
->AddChild(this);
320 m_windowId
= (int)NewControlId();
324 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
325 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
326 m_foregroundColour
= *wxBLACK
;
328 m_windowStyle
= style
;
331 m_windowId
= (int)NewControlId();
335 //// TODO: we should probably optimize by only creating a
336 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
337 //// But for now, let's simplify things by always creating the
338 //// drawing area, since otherwise the translations are different.
340 // New translations for getting mouse motion feedback
341 String translations
=
342 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
343 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
344 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
346 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
347 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
348 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
349 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
350 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
351 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
352 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
353 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
354 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
355 <Key>: DrawingAreaInput()";
357 XtActionsRec actions
[1];
358 actions
[0].string
= "wxCanvasMotionEvent";
359 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
360 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
362 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
363 if (style
& wxBORDER
)
364 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
365 xmFrameWidgetClass
, parentWidget
,
366 XmNshadowType
, XmSHADOW_IN
,
369 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
370 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
372 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
376 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
377 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
378 XmNunitType
, XmPIXELS
,
379 // XmNresizePolicy, XmRESIZE_ANY,
380 XmNresizePolicy
, XmRESIZE_NONE
,
383 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
386 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
388 XtFree ((char *) ptr);
389 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
390 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
391 XtFree ((char *) ptr);
395 wxAddWindowToTable((Widget
) m_drawingArea
, this);
396 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
399 * This order is very important in Motif 1.2.1
403 XtRealizeWidget ((Widget
) m_scrolledWindow
);
404 XtRealizeWidget ((Widget
) m_drawingArea
);
405 XtManageChild ((Widget
) m_drawingArea
);
407 XtOverrideTranslations ((Widget
) m_drawingArea
,
408 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
409 XtFree ((char *) ptr
);
411 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
412 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
415 display = XtDisplay (scrolledWindow);
416 xwindow = XtWindow (drawingArea);
419 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
420 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
422 // Add scrollbars if required
423 if (m_windowStyle
& wxHSCROLL
)
425 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
426 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
427 XmNorientation
, XmHORIZONTAL
,
429 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
430 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
431 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
432 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
433 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
434 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
435 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
436 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
438 XtVaSetValues (hScrollBar
,
443 m_hScrollBar
= (WXWidget
) hScrollBar
;
446 if (m_windowStyle
& wxVSCROLL
)
448 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
449 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
450 XmNorientation
, XmVERTICAL
,
452 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
453 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
454 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
455 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
456 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
457 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
458 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
459 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
461 XtVaSetValues (vScrollBar
,
466 m_vScrollBar
= (WXWidget
) vScrollBar
;
470 if (m_hScrollBar
|| m_vScrollBar
)
471 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
474 XtRealizeWidget ((Widget
) m_hScrollBar
);
476 XtRealizeWidget ((Widget
) m_vScrollBar
);
478 // Without this, the cursor may not be restored properly
479 // (e.g. in splitter sample).
480 SetCursor(*wxSTANDARD_CURSOR
);
481 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
482 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
487 void wxWindow::SetFocus()
489 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
490 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
493 void wxWindow::Enable(bool enable
)
497 XtSetSensitive((Widget
) GetMainWidget(), enable
);
498 XmUpdateDisplay((Widget
) GetMainWidget());
502 void wxWindow::CaptureMouse()
508 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
510 m_winCaptured
= TRUE
;
513 void wxWindow::ReleaseMouse()
519 XtRemoveGrab((Widget
) GetMainWidget());
520 m_winCaptured
= FALSE
;
523 // Push/pop event handler (i.e. allow a chain of event handlers
525 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
527 handler
->SetNextHandler(GetEventHandler());
528 SetEventHandler(handler
);
531 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
533 if ( GetEventHandler() )
535 wxEvtHandler
*handlerA
= GetEventHandler();
536 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
537 handlerA
->SetNextHandler(NULL
);
538 SetEventHandler(handlerB
);
551 #if wxUSE_DRAG_AND_DROP
553 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
555 if ( m_pDropTarget
!= 0 ) {
556 delete m_pDropTarget
;
559 m_pDropTarget
= pDropTarget
;
560 if ( m_pDropTarget
!= 0 )
568 // Old style file-manager drag&drop
569 void wxWindow::DragAcceptFiles(bool accept
)
575 void wxWindow::GetSize(int *x
, int *y
) const
583 Widget widget
= (Widget
) GetTopWidget();
585 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
589 void wxWindow::GetPosition(int *x
, int *y
) const
593 CanvasGetPosition(x
, y
);
596 Widget widget
= (Widget
) GetTopWidget();
598 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
600 // We may be faking the client origin.
601 // So a window that's really at (0, 30) may appear
602 // (to wxWin apps) to be at (0, 0).
605 wxPoint
pt(GetParent()->GetClientAreaOrigin());
613 void wxWindow::ScreenToClient(int *x
, int *y
) const
615 Widget widget
= (Widget
) GetClientWidget();
616 Display
*display
= XtDisplay((Widget
) GetMainWidget());
617 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
618 Window thisWindow
= XtWindow(widget
);
623 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
626 void wxWindow::ClientToScreen(int *x
, int *y
) const
628 Widget widget
= (Widget
) GetClientWidget();
629 Display
*display
= XtDisplay(widget
);
630 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
631 Window thisWindow
= XtWindow(widget
);
636 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
639 void wxWindow::SetCursor(const wxCursor
& cursor
)
641 m_windowCursor
= cursor
;
642 if (m_windowCursor
.Ok())
644 WXDisplay
*dpy
= GetXDisplay();
645 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
647 Widget w
= (Widget
) GetMainWidget();
648 Window win
= XtWindow(w
);
649 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
654 // Get size *available for subwindows* i.e. excluding menu bar etc.
655 void wxWindow::GetClientSize(int *x
, int *y
) const
657 Widget widget
= (Widget
) GetClientWidget();
659 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
663 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
665 // A bit of optimization to help sort out the flickers.
666 int oldX
, oldY
, oldW
, oldH
;
667 GetSize(& oldW
, & oldH
);
668 GetPosition(& oldX
, & oldY
);
670 bool useOldPos
= FALSE
;
671 bool useOldSize
= FALSE
;
673 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
675 else if (x
== oldX
&& y
== oldY
)
678 if ((width
== -1) && (height
== -1))
680 else if (width
== oldW
&& height
== oldH
)
683 if (useOldPos
&& useOldSize
)
688 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
691 Widget widget
= (Widget
) GetTopWidget();
695 bool managed
= XtIsManaged( widget
);
697 XtUnmanageChild(widget
);
699 int xx
= x
; int yy
= y
;
700 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
704 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
705 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
706 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
707 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
712 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
714 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
718 XtManageChild(widget
);
720 // How about this bit. Maybe we don't need to generate size events
721 // all the time -- they'll be generated when the window is sized anyway.
723 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
724 sizeEvent.SetEventObject(this);
726 GetEventHandler()->ProcessEvent(sizeEvent);
730 void wxWindow::SetClientSize(int width
, int height
)
734 CanvasSetClientSize(width
, height
);
738 Widget widget
= (Widget
) GetTopWidget();
741 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
743 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
745 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
746 sizeEvent
.SetEventObject(this);
748 GetEventHandler()->ProcessEvent(sizeEvent
);
751 // For implementation purposes - sometimes decorations make the client area
753 wxPoint
wxWindow::GetClientAreaOrigin() const
755 return wxPoint(0, 0);
758 // Makes an adjustment to the window position (for example, a frame that has
759 // a toolbar that it manages itself).
760 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
762 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
764 wxPoint
pt(GetParent()->GetClientAreaOrigin());
765 x
+= pt
.x
; y
+= pt
.y
;
769 bool wxWindow::Show(bool show
)
773 if (m_borderWidget
|| m_scrolledWindow
)
776 XtMapWidget((Widget
) m_drawingArea
);
777 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
781 WXWidget topWidget
= GetTopWidget();
783 XtMapWidget((Widget
) GetTopWidget());
784 else if (GetMainWidget())
785 XtMapWidget((Widget
) GetMainWidget());
790 if (m_borderWidget
|| m_scrolledWindow
)
793 XtUnmapWidget((Widget
) m_drawingArea
);
794 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
799 XtUnmapWidget((Widget
) GetTopWidget());
800 else if (GetMainWidget())
801 XtUnmapWidget((Widget
) GetMainWidget());
806 Window xwin = (Window) GetXWindow();
807 Display *xdisp = (Display*) GetXDisplay();
809 XMapWindow(xdisp, xwin);
811 XUnmapWindow(xdisp, xwin);
819 bool wxWindow::IsShown() const
824 int wxWindow::GetCharHeight() const
826 if (!m_windowFont
.Ok())
829 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
831 int direction
, ascent
, descent
;
833 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
835 // return (overall.ascent + overall.descent);
836 return (ascent
+ descent
);
839 int wxWindow::GetCharWidth() const
841 if (!m_windowFont
.Ok())
844 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
846 int direction
, ascent
, descent
;
848 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
850 return overall
.width
;
853 /* Helper function for 16-bit fonts */
854 static int str16len(const char *s
)
858 while (s
[0] && s
[1]) {
866 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
867 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
869 wxFont
*fontToUse
= (wxFont
*)theFont
;
871 fontToUse
= (wxFont
*) & m_windowFont
;
873 if (!fontToUse
->Ok())
876 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
878 int direction
, ascent
, descent2
;
882 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
885 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
886 &ascent
, &descent2
, &overall
);
888 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
889 &ascent
, &descent2
, &overall
);
891 *x
= (overall
.width
);
892 *y
= (ascent
+ descent2
);
896 *externalLeading
= 0;
899 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
901 Display
*display
= XtDisplay((Widget
) GetMainWidget());
902 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
904 XExposeEvent dummyEvent
;
906 GetSize(&width
, &height
);
908 dummyEvent
.type
= Expose
;
909 dummyEvent
.display
= display
;
910 dummyEvent
.send_event
= True
;
911 dummyEvent
.window
= thisWindow
;
914 dummyEvent
.x
= rect
->x
;
915 dummyEvent
.y
= rect
->y
;
916 dummyEvent
.width
= rect
->width
;
917 dummyEvent
.height
= rect
->height
;
923 dummyEvent
.width
= width
;
924 dummyEvent
.height
= height
;
926 dummyEvent
.count
= 0;
931 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
932 dc
.SetBackground(backgroundBrush
);
939 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
942 // Responds to colour changes: passes event on to children.
943 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
945 wxNode
*node
= GetChildren().First();
948 // Only propagate to non-top-level windows
949 wxWindow
*win
= (wxWindow
*)node
->Data();
950 if ( win
->GetParent() )
952 wxSysColourChangedEvent event2
;
953 event
.m_eventObject
= win
;
954 win
->GetEventHandler()->ProcessEvent(event2
);
961 // This can be called by the app (or wxWindows) to do default processing for the current
962 // event. Save message/event info in wxWindow so they can be used in this function.
963 long wxWindow::Default()
969 void wxWindow::InitDialog()
971 wxInitDialogEvent
event(GetId());
972 event
.SetEventObject( this );
973 GetEventHandler()->ProcessEvent(event
);
976 // Default init dialog behaviour is to transfer data to window
977 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
979 TransferDataToWindow();
982 // Caret manipulation
983 void wxWindow::CreateCaret(int w
, int h
)
987 m_caretEnabled
= TRUE
;
990 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
995 void wxWindow::ShowCaret(bool show
)
1000 void wxWindow::DestroyCaret()
1003 m_caretEnabled
= FALSE
;
1006 void wxWindow::SetCaretPos(int x
, int y
)
1011 void wxWindow::GetCaretPos(int *x
, int *y
) const
1016 wxWindow
*wxGetActiveWindow()
1022 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1029 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1032 wxFrame
*frame
= (wxFrame
*)this;
1033 Widget widget
= (Widget
) frame
->GetShellWidget();
1036 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1038 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1040 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1042 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1044 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1046 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1049 void wxWindow::Centre(int direction
)
1051 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1053 wxWindow
*father
= (wxWindow
*)GetParent();
1057 father
->GetClientSize(&panel_width
, &panel_height
);
1058 GetSize(&width
, &height
);
1059 GetPosition(&x
, &y
);
1064 if (direction
& wxHORIZONTAL
)
1065 new_x
= (int)((panel_width
- width
)/2);
1067 if (direction
& wxVERTICAL
)
1068 new_y
= (int)((panel_height
- height
)/2);
1070 SetSize(new_x
, new_y
, -1, -1);
1074 // Coordinates relative to the window
1075 void wxWindow::WarpPointer (int x
, int y
)
1077 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1080 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1086 int wxWindow::GetScrollPos(int orient
) const
1088 if (orient
== wxHORIZONTAL
)
1089 return m_scrollPosX
;
1091 return m_scrollPosY
;
1093 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1097 XtVaGetValues(scrollBar,
1098 XmNvalue, &pos, NULL);
1106 // This now returns the whole range, not just the number
1107 // of positions that we can scroll.
1108 int wxWindow::GetScrollRange(int orient
) const
1110 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1114 XtVaGetValues(scrollBar
,
1115 XmNmaximum
, &range
, NULL
);
1122 int wxWindow::GetScrollThumb(int orient
) const
1124 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1128 XtVaGetValues(scrollBar
,
1129 XmNsliderSize
, &thumb
, NULL
);
1136 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1138 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1141 XtVaSetValues (scrollBar
,
1145 if (orient
== wxHORIZONTAL
)
1152 // New function that will replace some of the above.
1153 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1154 int range
, bool WXUNUSED(refresh
))
1156 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1162 if (thumbVisible
== 0)
1165 XtVaSetValues(scrollBar
,
1169 XmNsliderSize
, thumbVisible
,
1172 if (orient
== wxHORIZONTAL
)
1178 // Does a physical scroll
1179 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1181 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1185 // Use specified rectangle
1186 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1190 // Use whole client area
1192 GetClientSize(& w
, & h
);
1195 int x1
= (dx
>= 0) ? x
: x
- dx
;
1196 int y1
= (dy
>= 0) ? y
: y
- dy
;
1197 int w1
= w
- abs(dx
);
1198 int h1
= h
- abs(dy
);
1199 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1200 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1202 wxClientDC
dc(this);
1204 dc
.SetLogicalFunction (wxCOPY
);
1206 Widget widget
= (Widget
) GetMainWidget();
1207 Window window
= XtWindow(widget
);
1208 Display
* display
= XtDisplay(widget
);
1210 XCopyArea(display
, window
,
1211 window
, (GC
) dc
.GetGC(),
1216 dc
.SetAutoSetting(TRUE
);
1217 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1218 dc
.SetBrush(brush
); // ??
1220 // We'll add rectangles to the list of update rectangles
1221 // according to which bits we've exposed.
1226 wxRect
*rect
= new wxRect
;
1232 XFillRectangle(display
, window
,
1233 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1237 rect
->width
= rect
->width
;
1238 rect
->height
= rect
->height
;
1240 updateRects
.Append((wxObject
*) rect
);
1244 wxRect
*rect
= new wxRect
;
1246 rect
->x
= x
+ w
+ dx
;
1251 XFillRectangle(display
, window
,
1252 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1257 rect
->width
= rect
->width
;
1258 rect
->height
= rect
->height
;
1260 updateRects
.Append((wxObject
*) rect
);
1264 wxRect
*rect
= new wxRect
;
1271 XFillRectangle(display
, window
,
1272 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1276 rect
->width
= rect
->width
;
1277 rect
->height
= rect
->height
;
1279 updateRects
.Append((wxObject
*) rect
);
1283 wxRect
*rect
= new wxRect
;
1286 rect
->y
= y
+ h
+ dy
;
1290 XFillRectangle(display
, window
,
1291 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1295 rect
->width
= rect
->width
;
1296 rect
->height
= rect
->height
;
1298 updateRects
.Append((wxObject
*) rect
);
1300 dc
.SetBrush(wxNullBrush
);
1302 // Now send expose events
1304 wxNode
* node
= updateRects
.First();
1307 wxRect
* rect
= (wxRect
*) node
->Data();
1310 event
.type
= Expose
;
1311 event
.display
= display
;
1312 event
.send_event
= True
;
1313 event
.window
= window
;
1317 event
.width
= rect
->width
;
1318 event
.height
= rect
->height
;
1322 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1324 node
= node
->Next();
1328 // Delete the update rects
1329 node
= updateRects
.First();
1332 wxRect
* rect
= (wxRect
*) node
->Data();
1334 node
= node
->Next();
1339 void wxWindow::OnChar(wxKeyEvent
& event
)
1341 if ( event
.KeyCode() == WXK_TAB
) {
1342 // propagate the TABs to the parent - it's up to it to decide what
1344 if ( GetParent() ) {
1345 if ( GetParent()->ProcessEvent(event
) )
1351 void wxWindow::OnPaint(wxPaintEvent
& event
)
1356 bool wxWindow::IsEnabled() const
1358 // TODO. Is this right?
1359 // return XtGetSensitive((Widget) GetMainWidget());
1363 // Dialog support: override these and call
1364 // base class members to add functionality
1365 // that can't be done using validators.
1366 // NOTE: these functions assume that controls
1367 // are direct children of this window, not grandchildren
1368 // or other levels of descendant.
1370 // Transfer values to controls. If returns FALSE,
1371 // it's an application error (pops up a dialog)
1372 bool wxWindow::TransferDataToWindow()
1374 wxNode
*node
= GetChildren().First();
1377 wxWindow
*child
= (wxWindow
*)node
->Data();
1378 if ( child
->GetValidator() &&
1379 !child
->GetValidator()->TransferToWindow() )
1381 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1385 node
= node
->Next();
1390 // Transfer values from controls. If returns FALSE,
1391 // validation failed: don't quit
1392 bool wxWindow::TransferDataFromWindow()
1394 wxNode
*node
= GetChildren().First();
1397 wxWindow
*child
= (wxWindow
*)node
->Data();
1398 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1403 node
= node
->Next();
1408 bool wxWindow::Validate()
1410 wxNode
*node
= GetChildren().First();
1413 wxWindow
*child
= (wxWindow
*)node
->Data();
1414 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1419 node
= node
->Next();
1424 // Get the window with the focus
1425 wxWindow
*wxWindow::FindFocus()
1431 void wxWindow::AddChild(wxWindow
*child
)
1433 GetChildren().Append(child
);
1434 child
->m_windowParent
= this;
1437 void wxWindow::RemoveChild(wxWindow
*child
)
1439 GetChildren().DeleteObject(child
);
1440 child
->m_windowParent
= NULL
;
1443 // Reparents this window to have the new parent.
1444 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1446 // For now, we indicate that this isn't implemented.
1450 void wxWindow::DestroyChildren()
1452 wxNode
*node
= GetChildren().First();
1455 wxNode
* next
= node
->Next();
1456 wxWindow
* child
= (wxWindow
*) node
->Data();
1460 GetChildren().Clear();
1463 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1465 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1467 if ( GetChildren().Member(child
) )
1474 void wxWindow::MakeModal(bool modal
)
1476 // Disable all other windows
1477 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1479 wxNode
*node
= wxTopLevelWindows
.First();
1482 wxWindow
*win
= (wxWindow
*)node
->Data();
1484 win
->Enable(!modal
);
1486 node
= node
->Next();
1491 // If nothing defined for this, try the parent.
1492 // E.g. we may be a button loaded from a resource, with no callback function
1494 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1496 if (GetEventHandler()->ProcessEvent(event
) )
1499 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1502 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1506 UnsetConstraints(m_constraints
);
1507 delete m_constraints
;
1512 // Make sure other windows know they're part of a 'meaningful relationship'
1513 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1514 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1515 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1516 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1517 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1518 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1519 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1520 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1521 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1522 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1523 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1524 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1525 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1526 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1527 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1528 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1532 // This removes any dangling pointers to this window
1533 // in other windows' constraintsInvolvedIn lists.
1534 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1538 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1539 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1540 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1541 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1542 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1543 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1544 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1545 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1546 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1547 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1548 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1549 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1550 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1551 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1552 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1553 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1557 // Back-pointer to other windows we're involved with, so if we delete
1558 // this window, we must delete any constraints we're involved with.
1559 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1561 if (!m_constraintsInvolvedIn
)
1562 m_constraintsInvolvedIn
= new wxList
;
1563 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1564 m_constraintsInvolvedIn
->Append(otherWin
);
1567 // REMOVE back-pointer to other windows we're involved with.
1568 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1570 if (m_constraintsInvolvedIn
)
1571 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1574 // Reset any constraints that mention this window
1575 void wxWindow::DeleteRelatedConstraints()
1577 if (m_constraintsInvolvedIn
)
1579 wxNode
*node
= m_constraintsInvolvedIn
->First();
1582 wxWindow
*win
= (wxWindow
*)node
->Data();
1583 wxNode
*next
= node
->Next();
1584 wxLayoutConstraints
*constr
= win
->GetConstraints();
1586 // Reset any constraints involving this window
1589 constr
->left
.ResetIfWin((wxWindow
*)this);
1590 constr
->top
.ResetIfWin((wxWindow
*)this);
1591 constr
->right
.ResetIfWin((wxWindow
*)this);
1592 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1593 constr
->width
.ResetIfWin((wxWindow
*)this);
1594 constr
->height
.ResetIfWin((wxWindow
*)this);
1595 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1596 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1601 delete m_constraintsInvolvedIn
;
1602 m_constraintsInvolvedIn
= NULL
;
1606 void wxWindow::SetSizer(wxSizer
*sizer
)
1608 m_windowSizer
= sizer
;
1610 sizer
->SetSizerParent((wxWindow
*)this);
1617 bool wxWindow::Layout()
1619 if (GetConstraints())
1622 GetClientSize(&w
, &h
);
1623 GetConstraints()->width
.SetValue(w
);
1624 GetConstraints()->height
.SetValue(h
);
1627 // If top level (one sizer), evaluate the sizer's constraints.
1631 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1632 GetSizer()->LayoutPhase1(&noChanges
);
1633 GetSizer()->LayoutPhase2(&noChanges
);
1634 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1639 // Otherwise, evaluate child constraints
1640 ResetConstraints(); // Mark all constraints as unevaluated
1641 DoPhase(1); // Just one phase need if no sizers involved
1643 SetConstraintSizes(); // Recursively set the real window sizes
1649 // Do a phase of evaluating constraints:
1650 // the default behaviour. wxSizers may do a similar
1651 // thing, but also impose their own 'constraints'
1652 // and order the evaluation differently.
1653 bool wxWindow::LayoutPhase1(int *noChanges
)
1655 wxLayoutConstraints
*constr
= GetConstraints();
1658 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1664 bool wxWindow::LayoutPhase2(int *noChanges
)
1674 // Do a phase of evaluating child constraints
1675 bool wxWindow::DoPhase(int phase
)
1677 int noIterations
= 0;
1678 int maxIterations
= 500;
1682 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1686 wxNode
*node
= GetChildren().First();
1689 wxWindow
*child
= (wxWindow
*)node
->Data();
1690 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1692 wxLayoutConstraints
*constr
= child
->GetConstraints();
1695 if (succeeded
.Member(child
))
1700 int tempNoChanges
= 0;
1701 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1702 noChanges
+= tempNoChanges
;
1705 succeeded
.Append(child
);
1710 node
= node
->Next();
1717 void wxWindow::ResetConstraints()
1719 wxLayoutConstraints
*constr
= GetConstraints();
1722 constr
->left
.SetDone(FALSE
);
1723 constr
->top
.SetDone(FALSE
);
1724 constr
->right
.SetDone(FALSE
);
1725 constr
->bottom
.SetDone(FALSE
);
1726 constr
->width
.SetDone(FALSE
);
1727 constr
->height
.SetDone(FALSE
);
1728 constr
->centreX
.SetDone(FALSE
);
1729 constr
->centreY
.SetDone(FALSE
);
1731 wxNode
*node
= GetChildren().First();
1734 wxWindow
*win
= (wxWindow
*)node
->Data();
1735 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1736 win
->ResetConstraints();
1737 node
= node
->Next();
1741 // Need to distinguish between setting the 'fake' size for
1742 // windows and sizers, and setting the real values.
1743 void wxWindow::SetConstraintSizes(bool recurse
)
1745 wxLayoutConstraints
*constr
= GetConstraints();
1746 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1747 constr
->width
.GetDone() && constr
->height
.GetDone())
1749 int x
= constr
->left
.GetValue();
1750 int y
= constr
->top
.GetValue();
1751 int w
= constr
->width
.GetValue();
1752 int h
= constr
->height
.GetValue();
1754 // If we don't want to resize this window, just move it...
1755 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1756 (constr
->height
.GetRelationship() != wxAsIs
))
1758 // Calls Layout() recursively. AAAGH. How can we stop that.
1759 // Simply take Layout() out of non-top level OnSizes.
1760 SizerSetSize(x
, y
, w
, h
);
1769 char *windowClass
= this->GetClassInfo()->GetClassName();
1772 if (GetName() == "")
1773 winName
= "unnamed";
1775 winName
= GetName();
1776 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1777 if (!constr
->left
.GetDone())
1778 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1779 if (!constr
->right
.GetDone())
1780 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1781 if (!constr
->width
.GetDone())
1782 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1783 if (!constr
->height
.GetDone())
1784 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1785 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1790 wxNode
*node
= GetChildren().First();
1793 wxWindow
*win
= (wxWindow
*)node
->Data();
1794 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1795 win
->SetConstraintSizes();
1796 node
= node
->Next();
1801 // This assumes that all sizers are 'on' the same
1802 // window, i.e. the parent of this window.
1803 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1805 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1806 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1810 m_sizerParent
->GetPosition(&xp
, &yp
);
1811 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1816 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1820 TransformSizerToActual(&xx
, &yy
);
1821 SetSize(xx
, yy
, w
, h
);
1824 void wxWindow::SizerMove(int x
, int y
)
1828 TransformSizerToActual(&xx
, &yy
);
1832 // Only set the size/position of the constraint (if any)
1833 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1835 wxLayoutConstraints
*constr
= GetConstraints();
1840 constr
->left
.SetValue(x
);
1841 constr
->left
.SetDone(TRUE
);
1845 constr
->top
.SetValue(y
);
1846 constr
->top
.SetDone(TRUE
);
1850 constr
->width
.SetValue(w
);
1851 constr
->width
.SetDone(TRUE
);
1855 constr
->height
.SetValue(h
);
1856 constr
->height
.SetDone(TRUE
);
1861 void wxWindow::MoveConstraint(int x
, int y
)
1863 wxLayoutConstraints
*constr
= GetConstraints();
1868 constr
->left
.SetValue(x
);
1869 constr
->left
.SetDone(TRUE
);
1873 constr
->top
.SetValue(y
);
1874 constr
->top
.SetDone(TRUE
);
1879 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1881 wxLayoutConstraints
*constr
= GetConstraints();
1884 *w
= constr
->width
.GetValue();
1885 *h
= constr
->height
.GetValue();
1891 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1893 wxLayoutConstraints
*constr
= GetConstraints();
1896 *w
= constr
->width
.GetValue();
1897 *h
= constr
->height
.GetValue();
1900 GetClientSize(w
, h
);
1903 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1905 wxLayoutConstraints
*constr
= GetConstraints();
1908 *x
= constr
->left
.GetValue();
1909 *y
= constr
->top
.GetValue();
1915 bool wxWindow::Close(bool force
)
1917 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1918 event
.SetEventObject(this);
1919 event
.SetForce(force
);
1921 return GetEventHandler()->ProcessEvent(event
);
1924 wxObject
* wxWindow::GetChild(int number
) const
1926 // Return a pointer to the Nth object in the window
1927 wxNode
*node
= GetChildren().First();
1930 node
= node
->Next() ;
1933 wxObject
*obj
= (wxObject
*)node
->Data();
1940 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1942 // Obsolete function
1945 void wxWindow::Clear()
1947 wxClientDC
dc(this);
1948 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1949 dc
.SetBackground(brush
);
1953 // Fits the panel around the items
1954 void wxWindow::Fit()
1958 wxNode
*node
= GetChildren().First();
1961 wxWindow
*win
= (wxWindow
*)node
->Data();
1963 win
->GetPosition(&wx
, &wy
);
1964 win
->GetSize(&ww
, &wh
);
1965 if ( wx
+ ww
> maxX
)
1967 if ( wy
+ wh
> maxY
)
1970 node
= node
->Next();
1972 SetClientSize(maxX
+ 5, maxY
+ 5);
1975 void wxWindow::SetValidator(const wxValidator
& validator
)
1977 if ( m_windowValidator
)
1978 delete m_windowValidator
;
1979 m_windowValidator
= validator
.Clone();
1981 if ( m_windowValidator
)
1982 m_windowValidator
->SetWindow(this) ;
1985 void wxWindow::SetClientObject( wxClientData
*data
)
1987 if (m_clientObject
) delete m_clientObject
;
1988 m_clientObject
= data
;
1991 wxClientData
*wxWindow::GetClientObject()
1993 return m_clientObject
;
1996 void wxWindow::SetClientData( void *data
)
1998 m_clientData
= data
;
2001 void *wxWindow::GetClientData()
2003 return m_clientData
;
2006 // Find a window by id or name
2007 wxWindow
*wxWindow::FindWindow(long id
)
2012 wxNode
*node
= GetChildren().First();
2015 wxWindow
*child
= (wxWindow
*)node
->Data();
2016 wxWindow
*found
= child
->FindWindow(id
);
2019 node
= node
->Next();
2024 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2026 if ( GetName() == name
)
2029 wxNode
*node
= GetChildren().First();
2032 wxWindow
*child
= (wxWindow
*)node
->Data();
2033 wxWindow
*found
= child
->FindWindow(name
);
2036 node
= node
->Next();
2041 void wxWindow::OnIdle(wxIdleEvent
& event
)
2043 // This calls the UI-update mechanism (querying windows for
2044 // menu/toolbar/control state information)
2048 // Raise the window to the top of the Z order
2049 void wxWindow::Raise()
2051 Window window
= XtWindow((Widget
) GetTopWidget());
2052 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2055 // Lower the window to the bottom of the Z order
2056 void wxWindow::Lower()
2058 Window window
= XtWindow((Widget
) GetTopWidget());
2059 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2062 bool wxWindow::AcceptsFocus() const
2064 return IsShown() && IsEnabled();
2067 // Update region access
2068 wxRegion
& wxWindow::GetUpdateRegion() const
2070 return (wxRegion
&) m_updateRegion
;
2073 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2075 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2078 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2080 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2083 bool wxWindow::IsExposed(const wxRect
& rect
) const
2085 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2089 * Allocates control IDs
2092 int wxWindow::NewControlId()
2094 static int s_controlId
= 0;
2099 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2101 m_acceleratorTable
= accel
;
2104 // All widgets should have this as their resize proc.
2105 // OnSize sent to wxWindow via client data.
2106 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2108 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2112 if (win
->PreResize())
2115 win
->GetSize(&width
, &height
);
2116 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2117 sizeEvent
.SetEventObject(win
);
2118 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2122 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2124 wxWindow
*oldItem
= NULL
;
2125 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2126 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2129 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2132 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2137 wxWidgetHashTable
->Put ((long) w
, win
);
2141 wxWindow
*wxGetWindowFromTable(Widget w
)
2143 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2146 void wxDeleteWindowFromTable(Widget w
)
2148 wxWidgetHashTable
->Delete((long)w
);
2151 // Get the underlying X window and display
2152 WXWindow
wxWindow::GetXWindow() const
2154 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2157 WXDisplay
*wxWindow::GetXDisplay() const
2159 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2162 WXWidget
wxWindow::GetMainWidget() const
2165 return m_drawingArea
;
2167 return m_mainWidget
;
2170 WXWidget
wxWindow::GetClientWidget() const
2172 if (m_drawingArea
!= (WXWidget
) 0)
2173 return m_drawingArea
;
2175 return GetMainWidget();
2178 WXWidget
wxWindow::GetTopWidget() const
2180 return GetMainWidget();
2183 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2184 XmDrawingAreaCallbackStruct
* cbs
)
2186 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2189 XEvent
* event
= cbs
->event
;
2190 wxWindow
* win
= (wxWindow
*) clientData
;
2191 Display
* display
= (Display
*) win
->GetXDisplay();
2193 switch (event
->type
)
2197 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2198 event
->xexpose
.width
, event
->xexpose
.height
);
2200 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2201 cout << rect->width << ", " << rect->height << "\n\n";
2204 win
->m_updateRects
.Append((wxObject
*) rect
);
2206 if (event
-> xexpose
.count
== 0)
2208 wxPaintEvent
event(win
->GetId());
2209 event
.SetEventObject(win
);
2210 win
->GetEventHandler()->ProcessEvent(event
);
2212 win
->ClearUpdateRects();
2218 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2224 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2226 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2228 XmDrawingAreaCallbackStruct cbs
;
2231 //if (event->mode!=NotifyNormal)
2234 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2235 ((XCrossingEvent
&) ev
) = *event
;
2237 cbs
.reason
= XmCR_INPUT
;
2240 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2243 // Fix to make it work under Motif 1.0 (!)
2244 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2248 XmDrawingAreaCallbackStruct cbs
;
2251 //ev.xbutton = *event;
2252 ev
= *((XEvent
*) event
);
2253 cbs
.reason
= XmCR_INPUT
;
2256 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2260 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2262 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2268 if (cbs
->reason
!= XmCR_INPUT
)
2271 local_event
= *(cbs
->event
); // We must keep a copy!
2274 switch (local_event.xany.type)
2277 cout << "EnterNotify\n";
2280 cout << "LeaveNotify\n";
2283 cout << "ButtonPress\n";
2286 cout << "ButtonRelease\n";
2289 cout << "MotionNotify\n";
2292 cout << "Something else\n";
2297 switch (local_event
.xany
.type
)
2305 wxEventType eventType
= wxEVT_NULL
;
2307 if (local_event
.xany
.type
== EnterNotify
)
2309 //if (local_event.xcrossing.mode!=NotifyNormal)
2310 // return ; // Ignore grab events
2311 eventType
= wxEVT_ENTER_WINDOW
;
2312 // canvas->GetEventHandler()->OnSetFocus();
2314 else if (local_event
.xany
.type
== LeaveNotify
)
2316 //if (local_event.xcrossing.mode!=NotifyNormal)
2317 // return ; // Ignore grab events
2318 eventType
= wxEVT_LEAVE_WINDOW
;
2319 // canvas->GetEventHandler()->OnKillFocus();
2321 else if (local_event
.xany
.type
== MotionNotify
)
2323 eventType
= wxEVT_MOTION
;
2324 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2327 Display
*dpy
= XtDisplay (drawingArea
);
2329 XQueryPointer (dpy
, XtWindow (drawingArea
),
2331 &local_event
.xmotion
.x_root
,
2332 &local_event
.xmotion
.y_root
,
2333 &local_event
.xmotion
.x
,
2334 &local_event
.xmotion
.y
,
2335 &local_event
.xmotion
.state
);
2342 else if (local_event
.xany
.type
== ButtonPress
)
2344 if (local_event
.xbutton
.button
== Button1
)
2346 eventType
= wxEVT_LEFT_DOWN
;
2347 canvas
->m_button1Pressed
= TRUE
;
2349 else if (local_event
.xbutton
.button
== Button2
)
2351 eventType
= wxEVT_MIDDLE_DOWN
;
2352 canvas
->m_button2Pressed
= TRUE
;
2354 else if (local_event
.xbutton
.button
== Button3
)
2356 eventType
= wxEVT_RIGHT_DOWN
;
2357 canvas
->m_button3Pressed
= TRUE
;
2360 else if (local_event
.xany
.type
== ButtonRelease
)
2362 if (local_event
.xbutton
.button
== Button1
)
2364 eventType
= wxEVT_LEFT_UP
;
2365 canvas
->m_button1Pressed
= FALSE
;
2367 else if (local_event
.xbutton
.button
== Button2
)
2369 eventType
= wxEVT_MIDDLE_UP
;
2370 canvas
->m_button2Pressed
= FALSE
;
2372 else if (local_event
.xbutton
.button
== Button3
)
2374 eventType
= wxEVT_RIGHT_UP
;
2375 canvas
->m_button3Pressed
= FALSE
;
2379 wxMouseEvent
wxevent (eventType
);
2380 wxevent
.m_eventHandle
= (char *) &local_event
;
2382 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2383 || (event_left_is_down (&local_event
)
2384 && (eventType
!= wxEVT_LEFT_UP
)));
2385 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2386 || (event_middle_is_down (&local_event
)
2387 && (eventType
!= wxEVT_MIDDLE_UP
)));
2388 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2389 || (event_right_is_down (&local_event
)
2390 && (eventType
!= wxEVT_RIGHT_UP
)));
2392 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2393 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2394 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2395 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2396 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2398 // Now check if we need to translate this event into a double click
2399 if (TRUE
) // canvas->doubleClickAllowed)
2401 if (wxevent
.ButtonDown())
2403 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2405 // get button and time-stamp
2407 if (wxevent
.LeftDown()) button
= 1;
2408 else if (wxevent
.MiddleDown()) button
= 2;
2409 else if (wxevent
.RightDown()) button
= 3;
2410 long ts
= wxevent
.GetTimestamp();
2411 // check, if single or double click
2412 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2415 canvas
->m_lastButton
= 0;
2416 switch ( eventType
)
2418 case wxEVT_LEFT_DOWN
:
2419 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2421 case wxEVT_MIDDLE_DOWN
:
2422 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2424 case wxEVT_RIGHT_DOWN
:
2425 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2435 // not fast enough or different button
2436 canvas
->m_lastTS
= ts
;
2437 canvas
->m_lastButton
= button
;
2442 wxevent
.SetId(canvas
->GetId());
2443 wxevent
.SetEventObject(canvas
);
2444 wxevent
.m_x
= local_event
.xbutton
.x
;
2445 wxevent
.m_y
= local_event
.xbutton
.y
;
2446 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2448 if (eventType == wxEVT_ENTER_WINDOW ||
2449 eventType == wxEVT_LEAVE_WINDOW ||
2450 eventType == wxEVT_MOTION
2459 // XComposeStatus compose;
2460 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2461 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2462 int id
= wxCharCodeXToWX (keySym
);
2464 wxKeyEvent
event (wxEVT_CHAR
);
2466 if (local_event
.xkey
.state
& ShiftMask
)
2467 event
.m_shiftDown
= TRUE
;
2468 if (local_event
.xkey
.state
& ControlMask
)
2469 event
.m_controlDown
= TRUE
;
2470 if (local_event
.xkey
.state
& Mod3Mask
)
2471 event
.m_altDown
= TRUE
;
2472 if (local_event
.xkey
.state
& Mod1Mask
)
2473 event
.m_metaDown
= TRUE
;
2474 event
.SetEventObject(canvas
);
2475 event
.m_keyCode
= id
;
2476 event
.SetTimestamp(local_event
.xkey
.time
);
2480 // Implement wxFrame::OnCharHook by checking ancestor.
2481 wxWindow
*parent
= canvas
->GetParent();
2482 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2483 parent
= parent
->GetParent();
2487 event
.SetEventType(wxEVT_CHAR_HOOK
);
2488 if (parent
->GetEventHandler()->ProcessEvent(event
))
2490 event
.SetEventType(wxEVT_CHAR
);
2493 canvas
->GetEventHandler()->ProcessEvent (event
);
2499 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2501 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2502 event
.SetEventObject(canvas
);
2503 canvas
->GetEventHandler()->ProcessEvent(event
);
2509 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2511 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2512 event
.SetEventObject(canvas
);
2513 canvas
->GetEventHandler()->ProcessEvent(event
);
2522 void wxWindow::DoPaint()
2524 //TODO : make a temporary gc so we can do the XCopyArea below
2525 if (0) // m_backingPixmap)
2528 Widget drawingArea = (Widget) m_drawingArea;
2529 // int orig = GetDC()->GetLogicalFunction();
2530 // GetDC()->SetLogicalFunction (wxCOPY);
2532 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2533 // should be able to calculate them.
2534 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2535 m_pixmapOffsetX, m_pixmapOffsetY,
2536 m_pixmapWidth, m_pixmapHeight,
2539 // GetDC()->SetLogicalFunction (orig);
2544 wxPaintEvent
event(GetId());
2545 event
.SetEventObject(this);
2546 GetEventHandler()->ProcessEvent(event
);
2550 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2551 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2553 // A bit of optimization to help sort out the flickers.
2554 int oldX
, oldY
, oldW
, oldH
;
2555 GetSize(& oldW
, & oldH
);
2556 GetPosition(& oldX
, & oldY
);
2558 bool useOldPos
= FALSE
;
2559 bool useOldSize
= FALSE
;
2561 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2563 else if (x
== oldX
&& y
== oldY
)
2566 if ((w
== -1) && (h
== -1))
2568 else if (w
== oldW
&& h
== oldH
)
2571 if (useOldPos
&& useOldSize
)
2574 Widget drawingArea
= (Widget
) m_drawingArea
;
2575 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2578 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2579 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2581 int xx
= x
; int yy
= y
;
2582 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2586 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2588 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2592 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2594 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2606 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2607 short thick
, margin
;
2608 XtVaGetValues ((Widget
) m_borderWidget
,
2609 XmNshadowThickness
, &thick
,
2610 XmNmarginWidth
, &margin
,
2612 w
-= 2 * (thick
+ margin
);
2615 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2619 XtVaGetValues ((Widget
) m_scrolledWindow
,
2620 XmNspacing
, &spacing
,
2621 XmNverticalScrollBar
, &sbar
,
2625 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2629 w
-= (spacing
+ wsbar
);
2631 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2637 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2638 short thick
, margin
;
2639 XtVaGetValues ((Widget
) m_borderWidget
,
2640 XmNshadowThickness
, &thick
,
2641 XmNmarginHeight
, &margin
,
2643 h
-= 2 * (thick
+ margin
);
2646 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2650 XtVaGetValues ((Widget
) m_scrolledWindow
,
2651 XmNspacing
, &spacing
,
2652 XmNhorizontalScrollBar
, &sbar
,
2656 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2660 h
-= (spacing
+ wsbar
);
2662 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2667 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2668 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2672 GetClientSize (&ww, &hh);
2673 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2674 sizeEvent.SetEventObject(this);
2676 GetEventHandler()->ProcessEvent(sizeEvent);
2681 void wxWindow::CanvasSetClientSize (int w
, int h
)
2683 Widget drawingArea
= (Widget
) m_drawingArea
;
2685 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2688 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2690 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2691 /* TODO: is this necessary?
2692 allowRepainting = FALSE;
2694 XSync (XtDisplay (drawingArea), FALSE);
2696 while (XtAppPending (wxTheApp->appContext))
2698 XFlush (XtDisplay (drawingArea));
2699 XtAppNextEvent (wxTheApp->appContext, &event);
2700 XtDispatchEvent (&event);
2704 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2707 allowRepainting = TRUE;
2712 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2713 sizeEvent.SetEventObject(this);
2715 GetEventHandler()->ProcessEvent(sizeEvent);
2719 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2721 // Must return the same thing that was set via SetClientSize
2723 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2728 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2731 if ((Widget
) m_borderWidget
)
2732 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2733 else if ((Widget
) m_scrolledWindow
)
2734 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2736 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2742 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2745 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2747 // We may be faking the client origin.
2748 // So a window that's really at (0, 30) may appear
2749 // (to wxWin apps) to be at (0, 0).
2752 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2761 // Add to hash table, add event handler
2762 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2763 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2765 wxAddWindowToTable((Widget
) mainWidget
, this);
2766 if (CanAddEventHandler())
2768 XtAddEventHandler((Widget
) mainWidget
,
2769 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2771 wxPanelItemEventHandler
,
2778 XtOverrideTranslations ((Widget
) mainWidget
,
2779 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2780 XtFree ((char *) ptr
);
2783 // Some widgets have a parent form widget, e.g. wxRadioBox
2786 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2790 XtOverrideTranslations ((Widget
) formWidget
,
2791 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2792 XtFree ((char *) ptr
);
2799 SetSize (x
, y
, width
, height
);
2804 // Remove event handler, remove from hash table
2805 bool wxWindow::DetachWidget(WXWidget widget
)
2807 if (CanAddEventHandler())
2809 XtRemoveEventHandler((Widget
) widget
,
2810 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2812 wxPanelItemEventHandler
,
2816 wxDeleteWindowFromTable((Widget
) widget
);
2820 void wxPanelItemEventHandler (Widget wid
,
2821 XtPointer client_data
,
2823 Boolean
*continueToDispatch
)
2825 // Widget can be a label or the actual widget.
2827 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2830 wxMouseEvent
wxevent(0);
2831 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2833 window
->GetEventHandler()->ProcessEvent(wxevent
);
2836 // TODO: probably the key to allowing default behaviour
2838 // Say we set a m_doDefault flag to FALSE at the start of this
2839 // function. Then in e.g. wxWindow::OnMouseEvent we can
2840 // call Default() which sets this flag to TRUE, indicating
2841 // that default processing can happen. Thus, behaviour can appear
2842 // to be overridden just by adding an event handler and not calling
2843 // wxWindow::OnWhatever.
2844 // ALSO, maybe we can use this instead of the current way of handling
2845 // drawing area events, to simplify things.
2846 *continueToDispatch
= True
;
2849 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2850 XmScaleCallbackStruct
*cbs
)
2852 Widget scrolledWindow
= XtParent (scrollbar
);
2853 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2854 int orientation
= (int) clientData
;
2856 wxEventType eventType
= wxEVT_NULL
;
2857 switch (cbs
->reason
)
2859 case XmCR_INCREMENT
:
2861 eventType
= wxEVT_SCROLL_LINEDOWN
;
2864 case XmCR_DECREMENT
:
2866 eventType
= wxEVT_SCROLL_LINEUP
;
2871 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2874 case XmCR_VALUE_CHANGED
:
2876 // TODO: Should this be intercepted too, or will it cause
2877 // duplicate events?
2878 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2881 case XmCR_PAGE_INCREMENT
:
2883 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2886 case XmCR_PAGE_DECREMENT
:
2888 eventType
= wxEVT_SCROLL_PAGEUP
;
2893 eventType
= wxEVT_SCROLL_TOP
;
2896 case XmCR_TO_BOTTOM
:
2898 eventType
= wxEVT_SCROLL_BOTTOM
;
2903 // Should never get here
2904 wxFAIL_MSG("Unknown scroll event.");
2909 wxScrollEvent
event(eventType
, win
->GetId());
2910 event
.SetEventObject(win
);
2911 event
.SetPosition(cbs
->value
);
2912 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2914 win
->GetEventHandler()->ProcessEvent(event
);
2917 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2919 switch (xevent
->xany
.type
)
2927 wxEventType eventType
= wxEVT_NULL
;
2929 if (xevent
->xany
.type
== LeaveNotify
)
2931 win
->m_button1Pressed
= FALSE
;
2932 win
->m_button2Pressed
= FALSE
;
2933 win
->m_button3Pressed
= FALSE
;
2936 else if (xevent
->xany
.type
== MotionNotify
)
2938 eventType
= wxEVT_MOTION
;
2940 else if (xevent
->xany
.type
== ButtonPress
)
2942 if (xevent
->xbutton
.button
== Button1
)
2944 eventType
= wxEVT_LEFT_DOWN
;
2945 win
->m_button1Pressed
= TRUE
;
2947 else if (xevent
->xbutton
.button
== Button2
)
2949 eventType
= wxEVT_MIDDLE_DOWN
;
2950 win
->m_button2Pressed
= TRUE
;
2952 else if (xevent
->xbutton
.button
== Button3
)
2954 eventType
= wxEVT_RIGHT_DOWN
;
2955 win
->m_button3Pressed
= TRUE
;
2958 else if (xevent
->xany
.type
== ButtonRelease
)
2960 if (xevent
->xbutton
.button
== Button1
)
2962 eventType
= wxEVT_LEFT_UP
;
2963 win
->m_button1Pressed
= FALSE
;
2965 else if (xevent
->xbutton
.button
== Button2
)
2967 eventType
= wxEVT_MIDDLE_UP
;
2968 win
->m_button2Pressed
= FALSE
;
2970 else if (xevent
->xbutton
.button
== Button3
)
2972 eventType
= wxEVT_RIGHT_UP
;
2973 win
->m_button3Pressed
= FALSE
;
2979 wxevent
.m_eventHandle
= (char *)xevent
;
2980 wxevent
.SetEventType(eventType
);
2983 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2986 win
->GetPosition(&x2
, &y2
);
2988 // The button x/y must be translated to wxWindows
2989 // window space - the widget might be a label or button,
2993 if (widget
!= (Widget
)win
->GetMainWidget())
2999 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3000 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3002 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3003 || (event_left_is_down (xevent
)
3004 && (eventType
!= wxEVT_LEFT_UP
)));
3005 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3006 || (event_middle_is_down (xevent
)
3007 && (eventType
!= wxEVT_MIDDLE_UP
)));
3008 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3009 || (event_right_is_down (xevent
)
3010 && (eventType
!= wxEVT_RIGHT_UP
)));
3012 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3013 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3020 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3022 switch (xevent
->xany
.type
)
3029 // XComposeStatus compose;
3030 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3031 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3032 int id
= wxCharCodeXToWX (keySym
);
3034 if (xevent
->xkey
.state
& ShiftMask
)
3035 wxevent
.m_shiftDown
= TRUE
;
3036 if (xevent
->xkey
.state
& ControlMask
)
3037 wxevent
.m_controlDown
= TRUE
;
3038 if (xevent
->xkey
.state
& Mod3Mask
)
3039 wxevent
.m_altDown
= TRUE
;
3040 if (xevent
->xkey
.state
& Mod1Mask
)
3041 wxevent
.m_metaDown
= TRUE
;
3042 wxevent
.SetEventObject(win
);
3043 wxevent
.m_keyCode
= id
;
3044 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3046 wxevent
.m_x
= xevent
->xbutton
.x
;
3047 wxevent
.m_y
= xevent
->xbutton
.y
;
3061 #define YAllocColor XAllocColor
3062 XColor g_itemColors
[5];
3063 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3066 static XmColorProc colorProc
;
3068 result
= wxNO_COLORS
;
3072 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3073 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3074 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3075 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3076 if (colorProc
== (XmColorProc
) NULL
)
3078 // Get a ptr to the actual function
3079 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3080 // And set it back to motif.
3081 XmSetColorCalculation (colorProc
);
3083 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3084 &g_itemColors
[wxFORE_INDEX
],
3085 &g_itemColors
[wxSELE_INDEX
],
3086 &g_itemColors
[wxTOPS_INDEX
],
3087 &g_itemColors
[wxBOTS_INDEX
]);
3088 result
= wxBACK_COLORS
;
3092 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3093 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3094 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3095 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3096 if (result
== wxNO_COLORS
)
3097 result
= wxFORE_COLORS
;
3100 Display
*dpy
= display
;
3101 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3105 /* 5 Colours to allocate */
3106 for (int i
= 0; i
< 5; i
++)
3107 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3108 result
= wxNO_COLORS
;
3112 /* Only 1 colour to allocate */
3113 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3114 result
= wxNO_COLORS
;
3121 // Changes the foreground and background colours to be derived
3122 // from the current background colour.
3123 // To change the foreground colour, you must call SetForegroundColour
3125 void wxWindow::ChangeBackgroundColour()
3127 if (GetMainWidget())
3128 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3131 void wxWindow::ChangeForegroundColour()
3133 if (GetMainWidget())
3134 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3137 // Change a widget's foreground and background colours.
3139 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3141 // When should we specify the foreground, if it's calculated
3142 // by wxComputeColours?
3143 // Solution: say we start with the default (computed) foreground colour.
3144 // If we call SetForegroundColour explicitly for a control or window,
3145 // then the foreground is changed.
3146 // Therefore SetBackgroundColour computes the foreground colour, and
3147 // SetForegroundColour changes the foreground colour. The ordering is
3150 XtVaSetValues ((Widget
) widget
,
3151 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3155 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3157 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3160 XtVaSetValues ((Widget
) widget
,
3161 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3162 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3163 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3164 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3167 if (changeArmColour
)
3168 XtVaSetValues ((Widget
) widget
,
3169 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3173 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3175 m_backgroundColour
= col
;
3176 ChangeBackgroundColour();
3179 void wxWindow::SetForegroundColour(const wxColour
& col
)
3181 m_foregroundColour
= col
;
3182 ChangeForegroundColour();
3185 void wxWindow::ChangeFont(bool keepOriginalSize
)
3187 // Note that this causes the widget to be resized back
3188 // to its original size! We therefore have to set the size
3189 // back again. TODO: a better way in Motif?
3190 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3191 if (w
&& m_windowFont
.Ok())
3193 int width
, height
, width1
, height1
;
3194 GetSize(& width
, & height
);
3196 // lesstif 0.87 hangs here
3197 #ifndef LESSTIF_VERSION
3199 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3203 GetSize(& width1
, & height1
);
3204 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3206 SetSize(-1, -1, width
, height
);
3211 void wxWindow::SetFont(const wxFont
& font
)
3213 m_windowFont
= font
;
3217 void wxWindow::ClearUpdateRects()
3219 wxNode
* node
= m_updateRects
.First();
3222 wxRect
* rect
= (wxRect
*) node
->Data();
3224 node
= node
->Next();
3226 m_updateRects
.Clear();
3229 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3231 if (!m_acceleratorTable
.Ok())
3234 int count
= m_acceleratorTable
.GetCount();
3235 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3237 for (i
= 0; i
< count
; i
++)
3239 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3240 if (entry
->MatchesEvent(event
))
3242 // Bingo, we have a match. Now find a control
3243 // that matches the entry command id.
3245 // Need to go up to the top of the window hierarchy,
3246 // since it might be e.g. a menu item
3247 wxWindow
* parent
= this;
3248 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3249 parent
= parent
->GetParent();
3254 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3256 // Try for a menu command
3257 wxFrame
* frame
= (wxFrame
*) parent
;
3258 if (frame
->GetMenuBar())
3260 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3263 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3264 commandEvent
.SetEventObject(frame
);
3266 // If ProcessEvent returns TRUE (it was handled), then
3267 // the calling code will skip the event handling.
3268 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3273 // Find a child matching the command id
3274 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3280 // Now we process those kinds of windows that we can.
3281 // For now, only buttons.
3282 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3284 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3285 commandEvent
.SetEventObject(child
);
3286 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3293 // We didn't match the key event against an accelerator.