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 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
486 void wxWindow::SetFocus()
488 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
489 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
492 void wxWindow::Enable(bool enable
)
496 XtSetSensitive((Widget
) GetMainWidget(), enable
);
497 XmUpdateDisplay((Widget
) GetMainWidget());
501 void wxWindow::CaptureMouse()
507 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
509 m_winCaptured
= TRUE
;
512 void wxWindow::ReleaseMouse()
518 XtRemoveGrab((Widget
) GetMainWidget());
519 m_winCaptured
= FALSE
;
522 // Push/pop event handler (i.e. allow a chain of event handlers
524 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
526 handler
->SetNextHandler(GetEventHandler());
527 SetEventHandler(handler
);
530 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
532 if ( GetEventHandler() )
534 wxEvtHandler
*handlerA
= GetEventHandler();
535 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
536 handlerA
->SetNextHandler(NULL
);
537 SetEventHandler(handlerB
);
550 #if wxUSE_DRAG_AND_DROP
552 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
554 if ( m_pDropTarget
!= 0 ) {
555 delete m_pDropTarget
;
558 m_pDropTarget
= pDropTarget
;
559 if ( m_pDropTarget
!= 0 )
567 // Old style file-manager drag&drop
568 void wxWindow::DragAcceptFiles(bool accept
)
574 void wxWindow::GetSize(int *x
, int *y
) const
582 Widget widget
= (Widget
) GetTopWidget();
584 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
588 void wxWindow::GetPosition(int *x
, int *y
) const
592 CanvasGetPosition(x
, y
);
595 Widget widget
= (Widget
) GetTopWidget();
597 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
599 // We may be faking the client origin.
600 // So a window that's really at (0, 30) may appear
601 // (to wxWin apps) to be at (0, 0).
604 wxPoint
pt(GetParent()->GetClientAreaOrigin());
612 void wxWindow::ScreenToClient(int *x
, int *y
) const
614 Widget widget
= (Widget
) GetClientWidget();
615 Display
*display
= XtDisplay((Widget
) GetMainWidget());
616 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
617 Window thisWindow
= XtWindow(widget
);
622 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
625 void wxWindow::ClientToScreen(int *x
, int *y
) const
627 Widget widget
= (Widget
) GetClientWidget();
628 Display
*display
= XtDisplay(widget
);
629 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
630 Window thisWindow
= XtWindow(widget
);
635 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
638 void wxWindow::SetCursor(const wxCursor
& cursor
)
640 m_windowCursor
= cursor
;
641 if (m_windowCursor
.Ok())
643 WXDisplay
*dpy
= GetXDisplay();
644 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
646 Widget w
= (Widget
) GetMainWidget();
647 Window win
= XtWindow(w
);
648 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
653 // Get size *available for subwindows* i.e. excluding menu bar etc.
654 void wxWindow::GetClientSize(int *x
, int *y
) const
656 Widget widget
= (Widget
) GetClientWidget();
658 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
662 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
664 // A bit of optimization to help sort out the flickers.
665 int oldX
, oldY
, oldW
, oldH
;
666 GetSize(& oldW
, & oldH
);
667 GetPosition(& oldX
, & oldY
);
669 bool useOldPos
= FALSE
;
670 bool useOldSize
= FALSE
;
672 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
674 else if (x
== oldX
&& y
== oldY
)
677 if ((width
== -1) && (height
== -1))
679 else if (width
== oldW
&& height
== oldH
)
682 if (useOldPos
&& useOldSize
)
687 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
690 Widget widget
= (Widget
) GetTopWidget();
694 bool managed
= XtIsManaged( widget
);
696 XtUnmanageChild(widget
);
698 int xx
= x
; int yy
= y
;
699 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
703 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
704 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
705 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
706 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
711 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
713 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
717 XtManageChild(widget
);
719 // How about this bit. Maybe we don't need to generate size events
720 // all the time -- they'll be generated when the window is sized anyway.
722 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
723 sizeEvent.SetEventObject(this);
725 GetEventHandler()->ProcessEvent(sizeEvent);
729 void wxWindow::SetClientSize(int width
, int height
)
733 CanvasSetClientSize(width
, height
);
737 Widget widget
= (Widget
) GetTopWidget();
740 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
742 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
744 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
745 sizeEvent
.SetEventObject(this);
747 GetEventHandler()->ProcessEvent(sizeEvent
);
750 // For implementation purposes - sometimes decorations make the client area
752 wxPoint
wxWindow::GetClientAreaOrigin() const
754 return wxPoint(0, 0);
757 // Makes an adjustment to the window position (for example, a frame that has
758 // a toolbar that it manages itself).
759 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
761 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
763 wxPoint
pt(GetParent()->GetClientAreaOrigin());
764 x
+= pt
.x
; y
+= pt
.y
;
768 bool wxWindow::Show(bool show
)
772 if (m_borderWidget
|| m_scrolledWindow
)
775 XtMapWidget((Widget
) m_drawingArea
);
776 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
780 WXWidget topWidget
= GetTopWidget();
782 XtMapWidget((Widget
) GetTopWidget());
783 else if (GetMainWidget())
784 XtMapWidget((Widget
) GetMainWidget());
789 if (m_borderWidget
|| m_scrolledWindow
)
792 XtUnmapWidget((Widget
) m_drawingArea
);
793 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
798 XtUnmapWidget((Widget
) GetTopWidget());
799 else if (GetMainWidget())
800 XtUnmapWidget((Widget
) GetMainWidget());
805 Window xwin = (Window) GetXWindow();
806 Display *xdisp = (Display*) GetXDisplay();
808 XMapWindow(xdisp, xwin);
810 XUnmapWindow(xdisp, xwin);
818 bool wxWindow::IsShown() const
823 int wxWindow::GetCharHeight() const
825 if (!m_windowFont
.Ok())
828 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
830 int direction
, ascent
, descent
;
832 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
834 // return (overall.ascent + overall.descent);
835 return (ascent
+ descent
);
838 int wxWindow::GetCharWidth() const
840 if (!m_windowFont
.Ok())
843 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
845 int direction
, ascent
, descent
;
847 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
849 return overall
.width
;
852 /* Helper function for 16-bit fonts */
853 static int str16len(const char *s
)
857 while (s
[0] && s
[1]) {
865 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
866 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
868 wxFont
*fontToUse
= (wxFont
*)theFont
;
870 fontToUse
= (wxFont
*) & m_windowFont
;
872 if (!fontToUse
->Ok())
875 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
877 int direction
, ascent
, descent2
;
881 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
884 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
885 &ascent
, &descent2
, &overall
);
887 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
888 &ascent
, &descent2
, &overall
);
890 *x
= (overall
.width
);
891 *y
= (ascent
+ descent2
);
895 *externalLeading
= 0;
898 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
900 Display
*display
= XtDisplay((Widget
) GetMainWidget());
901 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
903 XExposeEvent dummyEvent
;
905 GetSize(&width
, &height
);
907 dummyEvent
.type
= Expose
;
908 dummyEvent
.display
= display
;
909 dummyEvent
.send_event
= True
;
910 dummyEvent
.window
= thisWindow
;
913 dummyEvent
.x
= rect
->x
;
914 dummyEvent
.y
= rect
->y
;
915 dummyEvent
.width
= rect
->width
;
916 dummyEvent
.height
= rect
->height
;
922 dummyEvent
.width
= width
;
923 dummyEvent
.height
= height
;
925 dummyEvent
.count
= 0;
930 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
931 dc
.SetBackground(backgroundBrush
);
935 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
938 // Responds to colour changes: passes event on to children.
939 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
941 wxNode
*node
= GetChildren()->First();
944 // Only propagate to non-top-level windows
945 wxWindow
*win
= (wxWindow
*)node
->Data();
946 if ( win
->GetParent() )
948 wxSysColourChangedEvent event2
;
949 event
.m_eventObject
= win
;
950 win
->GetEventHandler()->ProcessEvent(event2
);
957 // This can be called by the app (or wxWindows) to do default processing for the current
958 // event. Save message/event info in wxWindow so they can be used in this function.
959 long wxWindow::Default()
965 void wxWindow::InitDialog()
967 wxInitDialogEvent
event(GetId());
968 event
.SetEventObject( this );
969 GetEventHandler()->ProcessEvent(event
);
972 // Default init dialog behaviour is to transfer data to window
973 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
975 TransferDataToWindow();
978 // Caret manipulation
979 void wxWindow::CreateCaret(int w
, int h
)
983 m_caretEnabled
= TRUE
;
986 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
991 void wxWindow::ShowCaret(bool show
)
996 void wxWindow::DestroyCaret()
999 m_caretEnabled
= FALSE
;
1002 void wxWindow::SetCaretPos(int x
, int y
)
1007 void wxWindow::GetCaretPos(int *x
, int *y
) const
1012 wxWindow
*wxGetActiveWindow()
1018 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1025 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1028 wxFrame
*frame
= (wxFrame
*)this;
1029 Widget widget
= (Widget
) frame
->GetShellWidget();
1032 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1034 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1036 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1038 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1040 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1042 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1045 void wxWindow::Centre(int direction
)
1047 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1049 wxWindow
*father
= (wxWindow
*)GetParent();
1053 father
->GetClientSize(&panel_width
, &panel_height
);
1054 GetSize(&width
, &height
);
1055 GetPosition(&x
, &y
);
1060 if (direction
& wxHORIZONTAL
)
1061 new_x
= (int)((panel_width
- width
)/2);
1063 if (direction
& wxVERTICAL
)
1064 new_y
= (int)((panel_height
- height
)/2);
1066 SetSize(new_x
, new_y
, -1, -1);
1070 // Coordinates relative to the window
1071 void wxWindow::WarpPointer (int x
, int y
)
1073 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1076 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1082 int wxWindow::GetScrollPos(int orient
) const
1084 if (orient
== wxHORIZONTAL
)
1085 return m_scrollPosX
;
1087 return m_scrollPosY
;
1089 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1093 XtVaGetValues(scrollBar,
1094 XmNvalue, &pos, NULL);
1102 // This now returns the whole range, not just the number
1103 // of positions that we can scroll.
1104 int wxWindow::GetScrollRange(int orient
) const
1106 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1110 XtVaGetValues(scrollBar
,
1111 XmNmaximum
, &range
, NULL
);
1118 int wxWindow::GetScrollThumb(int orient
) const
1120 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1124 XtVaGetValues(scrollBar
,
1125 XmNsliderSize
, &thumb
, NULL
);
1132 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1134 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1137 XtVaSetValues (scrollBar
,
1141 if (orient
== wxHORIZONTAL
)
1148 // New function that will replace some of the above.
1149 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1150 int range
, bool WXUNUSED(refresh
))
1152 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1158 if (thumbVisible
== 0)
1161 XtVaSetValues(scrollBar
,
1165 XmNsliderSize
, thumbVisible
,
1168 if (orient
== wxHORIZONTAL
)
1174 // Does a physical scroll
1175 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
1177 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1181 // Use specified rectangle
1182 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1186 // Use whole client area
1188 GetClientSize(& w
, & h
);
1191 int x1
= (dx
>= 0) ? x
: x
- dx
;
1192 int y1
= (dy
>= 0) ? y
: y
- dy
;
1193 int w1
= w
- abs(dx
);
1194 int h1
= h
- abs(dy
);
1195 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1196 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1198 wxClientDC
dc(this);
1200 dc
.SetLogicalFunction (wxCOPY
);
1202 Widget widget
= (Widget
) GetMainWidget();
1203 Window window
= XtWindow(widget
);
1204 Display
* display
= XtDisplay(widget
);
1206 XCopyArea(display
, window
,
1207 window
, (GC
) dc
.GetGC(),
1212 dc
.SetAutoSetting(TRUE
);
1213 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1214 dc
.SetBrush(brush
); // ??
1216 // We'll add rectangles to the list of update rectangles
1217 // according to which bits we've exposed.
1222 wxRect
*rect
= new wxRect
;
1228 XFillRectangle(display
, window
,
1229 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1233 rect
->width
= rect
->width
;
1234 rect
->height
= rect
->height
;
1236 updateRects
.Append((wxObject
*) rect
);
1240 wxRect
*rect
= new wxRect
;
1242 rect
->x
= x
+ w
+ dx
;
1247 XFillRectangle(display
, window
,
1248 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1253 rect
->width
= rect
->width
;
1254 rect
->height
= rect
->height
;
1256 updateRects
.Append((wxObject
*) rect
);
1260 wxRect
*rect
= new wxRect
;
1267 XFillRectangle(display
, window
,
1268 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1272 rect
->width
= rect
->width
;
1273 rect
->height
= rect
->height
;
1275 updateRects
.Append((wxObject
*) rect
);
1279 wxRect
*rect
= new wxRect
;
1282 rect
->y
= y
+ h
+ dy
;
1286 XFillRectangle(display
, window
,
1287 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1291 rect
->width
= rect
->width
;
1292 rect
->height
= rect
->height
;
1294 updateRects
.Append((wxObject
*) rect
);
1296 dc
.SetBrush(wxNullBrush
);
1298 // Now send expose events
1300 wxNode
* node
= updateRects
.First();
1303 wxRect
* rect
= (wxRect
*) node
->Data();
1306 event
.type
= Expose
;
1307 event
.display
= display
;
1308 event
.send_event
= True
;
1309 event
.window
= window
;
1313 event
.width
= rect
->width
;
1314 event
.height
= rect
->height
;
1318 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1320 node
= node
->Next();
1325 void wxWindow::OnChar(wxKeyEvent
& event
)
1327 if ( event
.KeyCode() == WXK_TAB
) {
1328 // propagate the TABs to the parent - it's up to it to decide what
1330 if ( GetParent() ) {
1331 if ( GetParent()->ProcessEvent(event
) )
1337 void wxWindow::OnPaint(wxPaintEvent
& event
)
1342 bool wxWindow::IsEnabled() const
1344 // TODO. Is this right?
1345 // return XtGetSensitive((Widget) GetMainWidget());
1349 // Dialog support: override these and call
1350 // base class members to add functionality
1351 // that can't be done using validators.
1352 // NOTE: these functions assume that controls
1353 // are direct children of this window, not grandchildren
1354 // or other levels of descendant.
1356 // Transfer values to controls. If returns FALSE,
1357 // it's an application error (pops up a dialog)
1358 bool wxWindow::TransferDataToWindow()
1360 wxNode
*node
= GetChildren()->First();
1363 wxWindow
*child
= (wxWindow
*)node
->Data();
1364 if ( child
->GetValidator() &&
1365 !child
->GetValidator()->TransferToWindow() )
1367 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1371 node
= node
->Next();
1376 // Transfer values from controls. If returns FALSE,
1377 // validation failed: don't quit
1378 bool wxWindow::TransferDataFromWindow()
1380 wxNode
*node
= GetChildren()->First();
1383 wxWindow
*child
= (wxWindow
*)node
->Data();
1384 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1389 node
= node
->Next();
1394 bool wxWindow::Validate()
1396 wxNode
*node
= GetChildren()->First();
1399 wxWindow
*child
= (wxWindow
*)node
->Data();
1400 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1405 node
= node
->Next();
1410 // Get the window with the focus
1411 wxWindow
*wxWindow::FindFocus()
1417 void wxWindow::AddChild(wxWindow
*child
)
1419 GetChildren()->Append(child
);
1420 child
->m_windowParent
= this;
1423 void wxWindow::RemoveChild(wxWindow
*child
)
1426 GetChildren()->DeleteObject(child
);
1427 child
->m_windowParent
= NULL
;
1430 void wxWindow::DestroyChildren()
1434 wxNode
*node
= GetChildren()->First();
1437 wxNode
* next
= node
->Next();
1438 wxWindow
* child
= (wxWindow
*) node
->Data();
1442 GetChildren()->Clear();
1445 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1447 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1449 if ( GetChildren()->Member(child
) )
1457 void wxWindow::MakeModal(bool modal
)
1459 // Disable all other windows
1460 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1462 wxNode
*node
= wxTopLevelWindows
.First();
1465 wxWindow
*win
= (wxWindow
*)node
->Data();
1467 win
->Enable(!modal
);
1469 node
= node
->Next();
1474 // If nothing defined for this, try the parent.
1475 // E.g. we may be a button loaded from a resource, with no callback function
1477 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1479 if (GetEventHandler()->ProcessEvent(event
) )
1482 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1485 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1489 UnsetConstraints(m_constraints
);
1490 delete m_constraints
;
1495 // Make sure other windows know they're part of a 'meaningful relationship'
1496 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1497 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1498 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1499 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1500 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1501 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1502 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1503 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1504 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1505 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1506 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1507 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1508 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1509 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1510 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1511 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1515 // This removes any dangling pointers to this window
1516 // in other windows' constraintsInvolvedIn lists.
1517 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1521 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1522 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1523 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1524 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1525 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1526 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1527 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1528 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1529 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1530 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1531 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1532 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1533 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1534 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1535 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1536 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1540 // Back-pointer to other windows we're involved with, so if we delete
1541 // this window, we must delete any constraints we're involved with.
1542 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1544 if (!m_constraintsInvolvedIn
)
1545 m_constraintsInvolvedIn
= new wxList
;
1546 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1547 m_constraintsInvolvedIn
->Append(otherWin
);
1550 // REMOVE back-pointer to other windows we're involved with.
1551 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1553 if (m_constraintsInvolvedIn
)
1554 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1557 // Reset any constraints that mention this window
1558 void wxWindow::DeleteRelatedConstraints()
1560 if (m_constraintsInvolvedIn
)
1562 wxNode
*node
= m_constraintsInvolvedIn
->First();
1565 wxWindow
*win
= (wxWindow
*)node
->Data();
1566 wxNode
*next
= node
->Next();
1567 wxLayoutConstraints
*constr
= win
->GetConstraints();
1569 // Reset any constraints involving this window
1572 constr
->left
.ResetIfWin((wxWindow
*)this);
1573 constr
->top
.ResetIfWin((wxWindow
*)this);
1574 constr
->right
.ResetIfWin((wxWindow
*)this);
1575 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1576 constr
->width
.ResetIfWin((wxWindow
*)this);
1577 constr
->height
.ResetIfWin((wxWindow
*)this);
1578 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1579 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1584 delete m_constraintsInvolvedIn
;
1585 m_constraintsInvolvedIn
= NULL
;
1589 void wxWindow::SetSizer(wxSizer
*sizer
)
1591 m_windowSizer
= sizer
;
1593 sizer
->SetSizerParent((wxWindow
*)this);
1600 bool wxWindow::Layout()
1602 if (GetConstraints())
1605 GetClientSize(&w
, &h
);
1606 GetConstraints()->width
.SetValue(w
);
1607 GetConstraints()->height
.SetValue(h
);
1610 // If top level (one sizer), evaluate the sizer's constraints.
1614 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1615 GetSizer()->LayoutPhase1(&noChanges
);
1616 GetSizer()->LayoutPhase2(&noChanges
);
1617 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1622 // Otherwise, evaluate child constraints
1623 ResetConstraints(); // Mark all constraints as unevaluated
1624 DoPhase(1); // Just one phase need if no sizers involved
1626 SetConstraintSizes(); // Recursively set the real window sizes
1632 // Do a phase of evaluating constraints:
1633 // the default behaviour. wxSizers may do a similar
1634 // thing, but also impose their own 'constraints'
1635 // and order the evaluation differently.
1636 bool wxWindow::LayoutPhase1(int *noChanges
)
1638 wxLayoutConstraints
*constr
= GetConstraints();
1641 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1647 bool wxWindow::LayoutPhase2(int *noChanges
)
1657 // Do a phase of evaluating child constraints
1658 bool wxWindow::DoPhase(int phase
)
1660 int noIterations
= 0;
1661 int maxIterations
= 500;
1665 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1669 wxNode
*node
= GetChildren()->First();
1672 wxWindow
*child
= (wxWindow
*)node
->Data();
1673 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1675 wxLayoutConstraints
*constr
= child
->GetConstraints();
1678 if (succeeded
.Member(child
))
1683 int tempNoChanges
= 0;
1684 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1685 noChanges
+= tempNoChanges
;
1688 succeeded
.Append(child
);
1693 node
= node
->Next();
1700 void wxWindow::ResetConstraints()
1702 wxLayoutConstraints
*constr
= GetConstraints();
1705 constr
->left
.SetDone(FALSE
);
1706 constr
->top
.SetDone(FALSE
);
1707 constr
->right
.SetDone(FALSE
);
1708 constr
->bottom
.SetDone(FALSE
);
1709 constr
->width
.SetDone(FALSE
);
1710 constr
->height
.SetDone(FALSE
);
1711 constr
->centreX
.SetDone(FALSE
);
1712 constr
->centreY
.SetDone(FALSE
);
1714 wxNode
*node
= GetChildren()->First();
1717 wxWindow
*win
= (wxWindow
*)node
->Data();
1718 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1719 win
->ResetConstraints();
1720 node
= node
->Next();
1724 // Need to distinguish between setting the 'fake' size for
1725 // windows and sizers, and setting the real values.
1726 void wxWindow::SetConstraintSizes(bool recurse
)
1728 wxLayoutConstraints
*constr
= GetConstraints();
1729 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1730 constr
->width
.GetDone() && constr
->height
.GetDone())
1732 int x
= constr
->left
.GetValue();
1733 int y
= constr
->top
.GetValue();
1734 int w
= constr
->width
.GetValue();
1735 int h
= constr
->height
.GetValue();
1737 // If we don't want to resize this window, just move it...
1738 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1739 (constr
->height
.GetRelationship() != wxAsIs
))
1741 // Calls Layout() recursively. AAAGH. How can we stop that.
1742 // Simply take Layout() out of non-top level OnSizes.
1743 SizerSetSize(x
, y
, w
, h
);
1752 char *windowClass
= this->GetClassInfo()->GetClassName();
1755 if (GetName() == "")
1756 winName
= "unnamed";
1758 winName
= GetName();
1759 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1760 if (!constr
->left
.GetDone())
1761 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1762 if (!constr
->right
.GetDone())
1763 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1764 if (!constr
->width
.GetDone())
1765 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1766 if (!constr
->height
.GetDone())
1767 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1768 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1773 wxNode
*node
= GetChildren()->First();
1776 wxWindow
*win
= (wxWindow
*)node
->Data();
1777 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1778 win
->SetConstraintSizes();
1779 node
= node
->Next();
1784 // This assumes that all sizers are 'on' the same
1785 // window, i.e. the parent of this window.
1786 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1788 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1789 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1793 m_sizerParent
->GetPosition(&xp
, &yp
);
1794 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1799 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1803 TransformSizerToActual(&xx
, &yy
);
1804 SetSize(xx
, yy
, w
, h
);
1807 void wxWindow::SizerMove(int x
, int y
)
1811 TransformSizerToActual(&xx
, &yy
);
1815 // Only set the size/position of the constraint (if any)
1816 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1818 wxLayoutConstraints
*constr
= GetConstraints();
1823 constr
->left
.SetValue(x
);
1824 constr
->left
.SetDone(TRUE
);
1828 constr
->top
.SetValue(y
);
1829 constr
->top
.SetDone(TRUE
);
1833 constr
->width
.SetValue(w
);
1834 constr
->width
.SetDone(TRUE
);
1838 constr
->height
.SetValue(h
);
1839 constr
->height
.SetDone(TRUE
);
1844 void wxWindow::MoveConstraint(int x
, int y
)
1846 wxLayoutConstraints
*constr
= GetConstraints();
1851 constr
->left
.SetValue(x
);
1852 constr
->left
.SetDone(TRUE
);
1856 constr
->top
.SetValue(y
);
1857 constr
->top
.SetDone(TRUE
);
1862 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1864 wxLayoutConstraints
*constr
= GetConstraints();
1867 *w
= constr
->width
.GetValue();
1868 *h
= constr
->height
.GetValue();
1874 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1876 wxLayoutConstraints
*constr
= GetConstraints();
1879 *w
= constr
->width
.GetValue();
1880 *h
= constr
->height
.GetValue();
1883 GetClientSize(w
, h
);
1886 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1888 wxLayoutConstraints
*constr
= GetConstraints();
1891 *x
= constr
->left
.GetValue();
1892 *y
= constr
->top
.GetValue();
1898 bool wxWindow::Close(bool force
)
1900 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1901 event
.SetEventObject(this);
1902 event
.SetForce(force
);
1904 return GetEventHandler()->ProcessEvent(event
);
1907 wxObject
* wxWindow::GetChild(int number
) const
1909 // Return a pointer to the Nth object in the window
1912 wxNode
*node
= GetChildren()->First();
1915 node
= node
->Next() ;
1918 wxObject
*obj
= (wxObject
*)node
->Data();
1925 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1927 // Obsolete function
1930 void wxWindow::Clear()
1932 wxClientDC
dc(this);
1933 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1934 dc
.SetBackground(brush
);
1938 // Fits the panel around the items
1939 void wxWindow::Fit()
1943 wxNode
*node
= GetChildren()->First();
1946 wxWindow
*win
= (wxWindow
*)node
->Data();
1948 win
->GetPosition(&wx
, &wy
);
1949 win
->GetSize(&ww
, &wh
);
1950 if ( wx
+ ww
> maxX
)
1952 if ( wy
+ wh
> maxY
)
1955 node
= node
->Next();
1957 SetClientSize(maxX
+ 5, maxY
+ 5);
1960 void wxWindow::SetValidator(const wxValidator
& validator
)
1962 if ( m_windowValidator
)
1963 delete m_windowValidator
;
1964 m_windowValidator
= validator
.Clone();
1966 if ( m_windowValidator
)
1967 m_windowValidator
->SetWindow(this) ;
1970 void wxWindow::SetClientObject( wxClientData
*data
)
1972 if (m_clientObject
) delete m_clientObject
;
1973 m_clientObject
= data
;
1976 wxClientData
*wxWindow::GetClientObject()
1978 return m_clientObject
;
1981 void wxWindow::SetClientData( void *data
)
1983 m_clientData
= data
;
1986 void *wxWindow::GetClientData()
1988 return m_clientData
;
1991 // Find a window by id or name
1992 wxWindow
*wxWindow::FindWindow(long id
)
1997 wxNode
*node
= GetChildren()->First();
2000 wxWindow
*child
= (wxWindow
*)node
->Data();
2001 wxWindow
*found
= child
->FindWindow(id
);
2004 node
= node
->Next();
2009 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2011 if ( GetName() == name
)
2014 wxNode
*node
= GetChildren()->First();
2017 wxWindow
*child
= (wxWindow
*)node
->Data();
2018 wxWindow
*found
= child
->FindWindow(name
);
2021 node
= node
->Next();
2026 void wxWindow::OnIdle(wxIdleEvent
& event
)
2028 // This calls the UI-update mechanism (querying windows for
2029 // menu/toolbar/control state information)
2033 // Raise the window to the top of the Z order
2034 void wxWindow::Raise()
2036 Window window
= XtWindow((Widget
) GetTopWidget());
2037 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2040 // Lower the window to the bottom of the Z order
2041 void wxWindow::Lower()
2043 Window window
= XtWindow((Widget
) GetTopWidget());
2044 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2047 bool wxWindow::AcceptsFocus() const
2049 return IsShown() && IsEnabled();
2052 // Update region access
2053 wxRegion
& wxWindow::GetUpdateRegion() const
2055 return (wxRegion
&) m_updateRegion
;
2058 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2060 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2063 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2065 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2068 bool wxWindow::IsExposed(const wxRect
& rect
) const
2070 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2074 * Allocates control IDs
2077 int wxWindow::NewControlId()
2079 static int s_controlId
= 0;
2084 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2086 m_acceleratorTable
= accel
;
2089 // All widgets should have this as their resize proc.
2090 // OnSize sent to wxWindow via client data.
2091 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2093 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2097 if (win
->PreResize())
2100 win
->GetSize(&width
, &height
);
2101 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2102 sizeEvent
.SetEventObject(win
);
2103 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2107 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2109 wxWindow
*oldItem
= NULL
;
2110 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2111 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2114 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2117 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2122 wxWidgetHashTable
->Put ((long) w
, win
);
2126 wxWindow
*wxGetWindowFromTable(Widget w
)
2128 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2131 void wxDeleteWindowFromTable(Widget w
)
2133 wxWidgetHashTable
->Delete((long)w
);
2136 // Get the underlying X window and display
2137 WXWindow
wxWindow::GetXWindow() const
2139 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2142 WXDisplay
*wxWindow::GetXDisplay() const
2144 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2147 WXWidget
wxWindow::GetMainWidget() const
2150 return m_drawingArea
;
2152 return m_mainWidget
;
2155 WXWidget
wxWindow::GetClientWidget() const
2157 if (m_drawingArea
!= (WXWidget
) 0)
2158 return m_drawingArea
;
2160 return GetMainWidget();
2163 WXWidget
wxWindow::GetTopWidget() const
2165 return GetMainWidget();
2168 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2169 XmDrawingAreaCallbackStruct
* cbs
)
2171 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2174 XEvent
* event
= cbs
->event
;
2175 wxWindow
* win
= (wxWindow
*) clientData
;
2176 Display
* display
= (Display
*) win
->GetXDisplay();
2178 switch (event
->type
)
2182 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2183 event
->xexpose
.width
, event
->xexpose
.height
);
2185 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2186 cout << rect->width << ", " << rect->height << "\n\n";
2189 win
->m_updateRects
.Append((wxObject
*) rect
);
2191 if (event
-> xexpose
.count
== 0)
2193 wxPaintEvent
event(win
->GetId());
2194 event
.SetEventObject(win
);
2195 win
->GetEventHandler()->ProcessEvent(event
);
2197 win
->ClearUpdateRects();
2203 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2209 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2211 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2213 XmDrawingAreaCallbackStruct cbs
;
2216 //if (event->mode!=NotifyNormal)
2219 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2220 ((XCrossingEvent
&) ev
) = *event
;
2222 cbs
.reason
= XmCR_INPUT
;
2225 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2228 // Fix to make it work under Motif 1.0 (!)
2229 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2233 XmDrawingAreaCallbackStruct cbs
;
2236 //ev.xbutton = *event;
2237 ev
= *((XEvent
*) event
);
2238 cbs
.reason
= XmCR_INPUT
;
2241 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2245 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2247 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2253 if (cbs
->reason
!= XmCR_INPUT
)
2256 local_event
= *(cbs
->event
); // We must keep a copy!
2259 switch (local_event.xany.type)
2262 cout << "EnterNotify\n";
2265 cout << "LeaveNotify\n";
2268 cout << "ButtonPress\n";
2271 cout << "ButtonRelease\n";
2274 cout << "MotionNotify\n";
2277 cout << "Something else\n";
2282 switch (local_event
.xany
.type
)
2290 wxEventType eventType
= wxEVT_NULL
;
2292 if (local_event
.xany
.type
== EnterNotify
)
2294 //if (local_event.xcrossing.mode!=NotifyNormal)
2295 // return ; // Ignore grab events
2296 eventType
= wxEVT_ENTER_WINDOW
;
2297 // canvas->GetEventHandler()->OnSetFocus();
2299 else if (local_event
.xany
.type
== LeaveNotify
)
2301 //if (local_event.xcrossing.mode!=NotifyNormal)
2302 // return ; // Ignore grab events
2303 eventType
= wxEVT_LEAVE_WINDOW
;
2304 // canvas->GetEventHandler()->OnKillFocus();
2306 else if (local_event
.xany
.type
== MotionNotify
)
2308 eventType
= wxEVT_MOTION
;
2309 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2312 Display
*dpy
= XtDisplay (drawingArea
);
2314 XQueryPointer (dpy
, XtWindow (drawingArea
),
2316 &local_event
.xmotion
.x_root
,
2317 &local_event
.xmotion
.y_root
,
2318 &local_event
.xmotion
.x
,
2319 &local_event
.xmotion
.y
,
2320 &local_event
.xmotion
.state
);
2327 else if (local_event
.xany
.type
== ButtonPress
)
2329 if (local_event
.xbutton
.button
== Button1
)
2331 eventType
= wxEVT_LEFT_DOWN
;
2332 canvas
->m_button1Pressed
= TRUE
;
2334 else if (local_event
.xbutton
.button
== Button2
)
2336 eventType
= wxEVT_MIDDLE_DOWN
;
2337 canvas
->m_button2Pressed
= TRUE
;
2339 else if (local_event
.xbutton
.button
== Button3
)
2341 eventType
= wxEVT_RIGHT_DOWN
;
2342 canvas
->m_button3Pressed
= TRUE
;
2345 else if (local_event
.xany
.type
== ButtonRelease
)
2347 if (local_event
.xbutton
.button
== Button1
)
2349 eventType
= wxEVT_LEFT_UP
;
2350 canvas
->m_button1Pressed
= FALSE
;
2352 else if (local_event
.xbutton
.button
== Button2
)
2354 eventType
= wxEVT_MIDDLE_UP
;
2355 canvas
->m_button2Pressed
= FALSE
;
2357 else if (local_event
.xbutton
.button
== Button3
)
2359 eventType
= wxEVT_RIGHT_UP
;
2360 canvas
->m_button3Pressed
= FALSE
;
2364 wxMouseEvent
wxevent (eventType
);
2365 wxevent
.m_eventHandle
= (char *) &local_event
;
2367 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2368 || (event_left_is_down (&local_event
)
2369 && (eventType
!= wxEVT_LEFT_UP
)));
2370 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2371 || (event_middle_is_down (&local_event
)
2372 && (eventType
!= wxEVT_MIDDLE_UP
)));
2373 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2374 || (event_right_is_down (&local_event
)
2375 && (eventType
!= wxEVT_RIGHT_UP
)));
2377 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2378 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2379 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2380 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2381 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2383 // Now check if we need to translate this event into a double click
2384 if (TRUE
) // canvas->doubleClickAllowed)
2386 if (wxevent
.ButtonDown())
2388 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2390 // get button and time-stamp
2392 if (wxevent
.LeftDown()) button
= 1;
2393 else if (wxevent
.MiddleDown()) button
= 2;
2394 else if (wxevent
.RightDown()) button
= 3;
2395 long ts
= wxevent
.GetTimestamp();
2396 // check, if single or double click
2397 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2400 canvas
->m_lastButton
= 0;
2401 switch ( eventType
)
2403 case wxEVT_LEFT_DOWN
:
2404 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2406 case wxEVT_MIDDLE_DOWN
:
2407 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2409 case wxEVT_RIGHT_DOWN
:
2410 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2420 // not fast enough or different button
2421 canvas
->m_lastTS
= ts
;
2422 canvas
->m_lastButton
= button
;
2427 wxevent
.SetId(canvas
->GetId());
2428 wxevent
.SetEventObject(canvas
);
2429 wxevent
.m_x
= local_event
.xbutton
.x
;
2430 wxevent
.m_y
= local_event
.xbutton
.y
;
2431 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2433 if (eventType == wxEVT_ENTER_WINDOW ||
2434 eventType == wxEVT_LEAVE_WINDOW ||
2435 eventType == wxEVT_MOTION
2444 // XComposeStatus compose;
2445 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2446 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2447 int id
= wxCharCodeXToWX (keySym
);
2449 wxKeyEvent
event (wxEVT_CHAR
);
2451 if (local_event
.xkey
.state
& ShiftMask
)
2452 event
.m_shiftDown
= TRUE
;
2453 if (local_event
.xkey
.state
& ControlMask
)
2454 event
.m_controlDown
= TRUE
;
2455 if (local_event
.xkey
.state
& Mod3Mask
)
2456 event
.m_altDown
= TRUE
;
2457 if (local_event
.xkey
.state
& Mod1Mask
)
2458 event
.m_metaDown
= TRUE
;
2459 event
.SetEventObject(canvas
);
2460 event
.m_keyCode
= id
;
2461 event
.SetTimestamp(local_event
.xkey
.time
);
2465 // Implement wxFrame::OnCharHook by checking ancestor.
2466 wxWindow
*parent
= canvas
->GetParent();
2467 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2468 parent
= parent
->GetParent();
2472 event
.SetEventType(wxEVT_CHAR_HOOK
);
2473 if (parent
->GetEventHandler()->ProcessEvent(event
))
2475 event
.SetEventType(wxEVT_CHAR
);
2478 canvas
->GetEventHandler()->ProcessEvent (event
);
2484 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2486 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2487 event
.SetEventObject(canvas
);
2488 canvas
->GetEventHandler()->ProcessEvent(event
);
2494 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2496 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2497 event
.SetEventObject(canvas
);
2498 canvas
->GetEventHandler()->ProcessEvent(event
);
2507 void wxWindow::DoPaint()
2509 //TODO : make a temporary gc so we can do the XCopyArea below
2510 if (0) // m_backingPixmap)
2513 Widget drawingArea = (Widget) m_drawingArea;
2514 // int orig = GetDC()->GetLogicalFunction();
2515 // GetDC()->SetLogicalFunction (wxCOPY);
2517 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2518 // should be able to calculate them.
2519 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2520 m_pixmapOffsetX, m_pixmapOffsetY,
2521 m_pixmapWidth, m_pixmapHeight,
2524 // GetDC()->SetLogicalFunction (orig);
2529 wxPaintEvent
event(GetId());
2530 event
.SetEventObject(this);
2531 GetEventHandler()->ProcessEvent(event
);
2535 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2536 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2538 // A bit of optimization to help sort out the flickers.
2539 int oldX
, oldY
, oldW
, oldH
;
2540 GetSize(& oldW
, & oldH
);
2541 GetPosition(& oldX
, & oldY
);
2543 bool useOldPos
= FALSE
;
2544 bool useOldSize
= FALSE
;
2546 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2548 else if (x
== oldX
&& y
== oldY
)
2551 if ((w
== -1) && (h
== -1))
2553 else if (w
== oldW
&& h
== oldH
)
2556 if (useOldPos
&& useOldSize
)
2559 Widget drawingArea
= (Widget
) m_drawingArea
;
2560 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2563 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2564 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2566 int xx
= x
; int yy
= y
;
2567 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2571 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2573 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2577 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2579 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2591 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2592 short thick
, margin
;
2593 XtVaGetValues ((Widget
) m_borderWidget
,
2594 XmNshadowThickness
, &thick
,
2595 XmNmarginWidth
, &margin
,
2597 w
-= 2 * (thick
+ margin
);
2600 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2604 XtVaGetValues ((Widget
) m_scrolledWindow
,
2605 XmNspacing
, &spacing
,
2606 XmNverticalScrollBar
, &sbar
,
2610 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2614 w
-= (spacing
+ wsbar
);
2616 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2622 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2623 short thick
, margin
;
2624 XtVaGetValues ((Widget
) m_borderWidget
,
2625 XmNshadowThickness
, &thick
,
2626 XmNmarginHeight
, &margin
,
2628 h
-= 2 * (thick
+ margin
);
2631 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2635 XtVaGetValues ((Widget
) m_scrolledWindow
,
2636 XmNspacing
, &spacing
,
2637 XmNhorizontalScrollBar
, &sbar
,
2641 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2645 h
-= (spacing
+ wsbar
);
2647 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2652 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2653 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2657 GetClientSize (&ww, &hh);
2658 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2659 sizeEvent.SetEventObject(this);
2661 GetEventHandler()->ProcessEvent(sizeEvent);
2666 void wxWindow::CanvasSetClientSize (int w
, int h
)
2668 Widget drawingArea
= (Widget
) m_drawingArea
;
2670 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2673 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2675 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2676 /* TODO: is this necessary?
2677 allowRepainting = FALSE;
2679 XSync (XtDisplay (drawingArea), FALSE);
2681 while (XtAppPending (wxTheApp->appContext))
2683 XFlush (XtDisplay (drawingArea));
2684 XtAppNextEvent (wxTheApp->appContext, &event);
2685 XtDispatchEvent (&event);
2689 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2692 allowRepainting = TRUE;
2697 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2698 sizeEvent.SetEventObject(this);
2700 GetEventHandler()->ProcessEvent(sizeEvent);
2704 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2706 // Must return the same thing that was set via SetClientSize
2708 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2713 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2716 if ((Widget
) m_borderWidget
)
2717 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2718 else if ((Widget
) m_scrolledWindow
)
2719 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2721 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2727 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2730 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2732 // We may be faking the client origin.
2733 // So a window that's really at (0, 30) may appear
2734 // (to wxWin apps) to be at (0, 0).
2737 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2746 // Add to hash table, add event handler
2747 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2748 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2750 wxAddWindowToTable((Widget
) mainWidget
, this);
2751 if (CanAddEventHandler())
2753 XtAddEventHandler((Widget
) mainWidget
,
2754 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2756 wxPanelItemEventHandler
,
2763 XtOverrideTranslations ((Widget
) mainWidget
,
2764 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2765 XtFree ((char *) ptr
);
2768 // Some widgets have a parent form widget, e.g. wxRadioBox
2771 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2775 XtOverrideTranslations ((Widget
) formWidget
,
2776 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2777 XtFree ((char *) ptr
);
2784 SetSize (x
, y
, width
, height
);
2789 // Remove event handler, remove from hash table
2790 bool wxWindow::DetachWidget(WXWidget widget
)
2792 if (CanAddEventHandler())
2794 XtRemoveEventHandler((Widget
) widget
,
2795 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2797 wxPanelItemEventHandler
,
2801 wxDeleteWindowFromTable((Widget
) widget
);
2805 void wxPanelItemEventHandler (Widget wid
,
2806 XtPointer client_data
,
2808 Boolean
*continueToDispatch
)
2810 // Widget can be a label or the actual widget.
2812 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2815 wxMouseEvent
wxevent(0);
2816 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2818 window
->GetEventHandler()->ProcessEvent(wxevent
);
2821 // TODO: probably the key to allowing default behaviour
2823 // Say we set a m_doDefault flag to FALSE at the start of this
2824 // function. Then in e.g. wxWindow::OnMouseEvent we can
2825 // call Default() which sets this flag to TRUE, indicating
2826 // that default processing can happen. Thus, behaviour can appear
2827 // to be overridden just by adding an event handler and not calling
2828 // wxWindow::OnWhatever.
2829 // ALSO, maybe we can use this instead of the current way of handling
2830 // drawing area events, to simplify things.
2831 *continueToDispatch
= True
;
2834 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2835 XmScaleCallbackStruct
*cbs
)
2837 Widget scrolledWindow
= XtParent (scrollbar
);
2838 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2839 int orientation
= (int) clientData
;
2841 wxEventType eventType
= wxEVT_NULL
;
2842 switch (cbs
->reason
)
2844 case XmCR_INCREMENT
:
2846 eventType
= wxEVT_SCROLL_LINEDOWN
;
2849 case XmCR_DECREMENT
:
2851 eventType
= wxEVT_SCROLL_LINEUP
;
2856 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2859 case XmCR_VALUE_CHANGED
:
2861 // TODO: Should this be intercepted too, or will it cause
2862 // duplicate events?
2863 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2866 case XmCR_PAGE_INCREMENT
:
2868 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2871 case XmCR_PAGE_DECREMENT
:
2873 eventType
= wxEVT_SCROLL_PAGEUP
;
2878 eventType
= wxEVT_SCROLL_TOP
;
2881 case XmCR_TO_BOTTOM
:
2883 eventType
= wxEVT_SCROLL_BOTTOM
;
2888 // Should never get here
2889 wxFAIL_MSG("Unknown scroll event.");
2894 wxScrollEvent
event(eventType
, win
->GetId());
2895 event
.SetEventObject(win
);
2896 event
.SetPosition(cbs
->value
);
2897 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2899 win
->GetEventHandler()->ProcessEvent(event
);
2902 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2904 switch (xevent
->xany
.type
)
2912 wxEventType eventType
= wxEVT_NULL
;
2914 if (xevent
->xany
.type
== LeaveNotify
)
2916 win
->m_button1Pressed
= FALSE
;
2917 win
->m_button2Pressed
= FALSE
;
2918 win
->m_button3Pressed
= FALSE
;
2921 else if (xevent
->xany
.type
== MotionNotify
)
2923 eventType
= wxEVT_MOTION
;
2925 else if (xevent
->xany
.type
== ButtonPress
)
2927 if (xevent
->xbutton
.button
== Button1
)
2929 eventType
= wxEVT_LEFT_DOWN
;
2930 win
->m_button1Pressed
= TRUE
;
2932 else if (xevent
->xbutton
.button
== Button2
)
2934 eventType
= wxEVT_MIDDLE_DOWN
;
2935 win
->m_button2Pressed
= TRUE
;
2937 else if (xevent
->xbutton
.button
== Button3
)
2939 eventType
= wxEVT_RIGHT_DOWN
;
2940 win
->m_button3Pressed
= TRUE
;
2943 else if (xevent
->xany
.type
== ButtonRelease
)
2945 if (xevent
->xbutton
.button
== Button1
)
2947 eventType
= wxEVT_LEFT_UP
;
2948 win
->m_button1Pressed
= FALSE
;
2950 else if (xevent
->xbutton
.button
== Button2
)
2952 eventType
= wxEVT_MIDDLE_UP
;
2953 win
->m_button2Pressed
= FALSE
;
2955 else if (xevent
->xbutton
.button
== Button3
)
2957 eventType
= wxEVT_RIGHT_UP
;
2958 win
->m_button3Pressed
= FALSE
;
2964 wxevent
.m_eventHandle
= (char *)xevent
;
2965 wxevent
.SetEventType(eventType
);
2968 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2971 win
->GetPosition(&x2
, &y2
);
2973 // The button x/y must be translated to wxWindows
2974 // window space - the widget might be a label or button,
2978 if (widget
!= (Widget
)win
->GetMainWidget())
2984 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2985 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2987 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2988 || (event_left_is_down (xevent
)
2989 && (eventType
!= wxEVT_LEFT_UP
)));
2990 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2991 || (event_middle_is_down (xevent
)
2992 && (eventType
!= wxEVT_MIDDLE_UP
)));
2993 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2994 || (event_right_is_down (xevent
)
2995 && (eventType
!= wxEVT_RIGHT_UP
)));
2997 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2998 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3005 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3007 switch (xevent
->xany
.type
)
3014 // XComposeStatus compose;
3015 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3016 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3017 int id
= wxCharCodeXToWX (keySym
);
3019 if (xevent
->xkey
.state
& ShiftMask
)
3020 wxevent
.m_shiftDown
= TRUE
;
3021 if (xevent
->xkey
.state
& ControlMask
)
3022 wxevent
.m_controlDown
= TRUE
;
3023 if (xevent
->xkey
.state
& Mod3Mask
)
3024 wxevent
.m_altDown
= TRUE
;
3025 if (xevent
->xkey
.state
& Mod1Mask
)
3026 wxevent
.m_metaDown
= TRUE
;
3027 wxevent
.SetEventObject(win
);
3028 wxevent
.m_keyCode
= id
;
3029 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3031 wxevent
.m_x
= xevent
->xbutton
.x
;
3032 wxevent
.m_y
= xevent
->xbutton
.y
;
3046 #define YAllocColor XAllocColor
3047 XColor g_itemColors
[5];
3048 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3051 static XmColorProc colorProc
;
3053 result
= wxNO_COLORS
;
3057 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3058 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3059 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3060 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3061 if (colorProc
== (XmColorProc
) NULL
)
3063 // Get a ptr to the actual function
3064 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3065 // And set it back to motif.
3066 XmSetColorCalculation (colorProc
);
3068 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3069 &g_itemColors
[wxFORE_INDEX
],
3070 &g_itemColors
[wxSELE_INDEX
],
3071 &g_itemColors
[wxTOPS_INDEX
],
3072 &g_itemColors
[wxBOTS_INDEX
]);
3073 result
= wxBACK_COLORS
;
3077 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3078 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3079 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3080 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3081 if (result
== wxNO_COLORS
)
3082 result
= wxFORE_COLORS
;
3085 Display
*dpy
= display
;
3086 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3090 /* 5 Colours to allocate */
3091 for (int i
= 0; i
< 5; i
++)
3092 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3093 result
= wxNO_COLORS
;
3097 /* Only 1 colour to allocate */
3098 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3099 result
= wxNO_COLORS
;
3106 // Changes the foreground and background colours to be derived
3107 // from the current background colour.
3108 // To change the foreground colour, you must call SetForegroundColour
3110 void wxWindow::ChangeBackgroundColour()
3112 if (GetMainWidget())
3113 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3116 void wxWindow::ChangeForegroundColour()
3118 if (GetMainWidget())
3119 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3122 // Change a widget's foreground and background colours.
3124 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3126 // When should we specify the foreground, if it's calculated
3127 // by wxComputeColours?
3128 // Solution: say we start with the default (computed) foreground colour.
3129 // If we call SetForegroundColour explicitly for a control or window,
3130 // then the foreground is changed.
3131 // Therefore SetBackgroundColour computes the foreground colour, and
3132 // SetForegroundColour changes the foreground colour. The ordering is
3135 XtVaSetValues ((Widget
) widget
,
3136 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3140 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3142 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3145 XtVaSetValues ((Widget
) widget
,
3146 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3147 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3148 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3149 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3152 if (changeArmColour
)
3153 XtVaSetValues ((Widget
) widget
,
3154 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3158 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3160 m_backgroundColour
= col
;
3161 ChangeBackgroundColour();
3164 void wxWindow::SetForegroundColour(const wxColour
& col
)
3166 m_foregroundColour
= col
;
3167 ChangeForegroundColour();
3170 void wxWindow::ChangeFont(bool keepOriginalSize
)
3172 // Note that this causes the widget to be resized back
3173 // to its original size! We therefore have to set the size
3174 // back again. TODO: a better way in Motif?
3175 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3176 if (w
&& m_windowFont
.Ok())
3178 int width
, height
, width1
, height1
;
3179 GetSize(& width
, & height
);
3182 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3185 GetSize(& width1
, & height1
);
3186 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3188 SetSize(-1, -1, width
, height
);
3193 void wxWindow::SetFont(const wxFont
& font
)
3195 m_windowFont
= font
;
3199 void wxWindow::ClearUpdateRects()
3201 wxNode
* node
= m_updateRects
.First();
3204 wxRect
* rect
= (wxRect
*) node
->Data();
3206 node
= node
->Next();
3208 m_updateRects
.Clear();
3211 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3213 if (!m_acceleratorTable
.Ok())
3216 int count
= m_acceleratorTable
.GetCount();
3217 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3219 for (i
= 0; i
< count
; i
++)
3221 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3222 if (entry
->MatchesEvent(event
))
3224 // Bingo, we have a match. Now find a control
3225 // that matches the entry command id.
3227 // Need to go up to the top of the window hierarchy,
3228 // since it might be e.g. a menu item
3229 wxWindow
* parent
= this;
3230 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3231 parent
= parent
->GetParent();
3236 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3238 // Try for a menu command
3239 wxFrame
* frame
= (wxFrame
*) parent
;
3240 if (frame
->GetMenuBar())
3242 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3245 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3246 commandEvent
.SetEventObject(frame
);
3248 // If ProcessEvent returns TRUE (it was handled), then
3249 // the calling code will skip the event handling.
3250 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3255 // Find a child matching the command id
3256 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3262 // Now we process those kinds of windows that we can.
3263 // For now, only buttons.
3264 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3266 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3267 commandEvent
.SetEventObject(child
);
3268 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3275 // We didn't match the key event against an accelerator.