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 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
;
113 m_mainWidget
= (WXWidget
) 0;
114 m_button1Pressed
= FALSE
;
115 m_button2Pressed
= FALSE
;
116 m_button3Pressed
= FALSE
;
117 m_winCaptured
= FALSE
;
119 m_hScrollBar
= (WXWidget
) 0;
120 m_vScrollBar
= (WXWidget
) 0;
121 m_borderWidget
= (WXWidget
) 0;
122 m_scrolledWindow
= (WXWidget
) 0;
123 m_drawingArea
= (WXWidget
) 0;
126 m_backingPixmap
= (WXPixmap
) 0;
133 m_canAddEventHandler
= FALSE
;
136 m_paintRegion
= (WXRegion
) 0;
140 wxWindow::~wxWindow()
145 XDestroyRegion ((Region
) m_paintRegion
);
146 m_paintRegion
= (WXRegion
) 0;
149 DetachWidget(GetMainWidget()); // Removes event handlers
151 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
154 // Destroy children before destroying self
158 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
160 Widget w
= (Widget
) m_drawingArea
;
161 wxDeleteWindowFromTable(w
);
165 m_mainWidget
= (WXWidget
) 0;
167 // Only if we're _really_ a canvas (not a dialog box/panel)
168 if (m_scrolledWindow
)
170 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
175 XtUnmanageChild ((Widget
) m_hScrollBar
);
176 XtDestroyWidget ((Widget
) m_hScrollBar
);
180 XtUnmanageChild ((Widget
) m_vScrollBar
);
181 XtDestroyWidget ((Widget
) m_vScrollBar
);
183 if (m_scrolledWindow
)
185 XtUnmanageChild ((Widget
) m_scrolledWindow
);
186 XtDestroyWidget ((Widget
) m_scrolledWindow
);
191 XtDestroyWidget ((Widget
) m_borderWidget
);
192 m_borderWidget
= (WXWidget
) 0;
198 // Have to delete constraints/sizer FIRST otherwise
199 // sizers may try to look at deleted windows as they
200 // delete themselves.
201 #if wxUSE_CONSTRAINTS
202 DeleteRelatedConstraints();
205 // This removes any dangling pointers to this window
206 // in other windows' constraintsInvolvedIn lists.
207 UnsetConstraints(m_constraints
);
208 delete m_constraints
;
209 m_constraints
= NULL
;
213 delete m_windowSizer
;
214 m_windowSizer
= NULL
;
216 // If this is a child of a sizer, remove self from parent
218 m_sizerParent
->RemoveChild((wxWindow
*)this);
222 m_windowParent
->RemoveChild(this);
226 // Destroy the window
229 wxDeleteWindowFromTable((Widget
) GetMainWidget());
230 XtDestroyWidget((Widget
) GetMainWidget());
231 SetMainWidget((WXWidget
) NULL
);
237 // Just in case the window has been Closed, but
238 // we're then deleting immediately: don't leave
239 // dangling pointers.
240 wxPendingDelete
.DeleteObject(this);
242 if ( m_windowValidator
)
243 delete m_windowValidator
;
246 // Destroy the window (delayed, if a managed window)
247 bool wxWindow::Destroy()
254 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
258 const wxString
& name
)
263 m_windowParent
= NULL
;
264 m_windowEventHandler
= this;
266 m_windowCursor
= *wxSTANDARD_CURSOR
;
267 m_constraints
= NULL
;
268 m_constraintsInvolvedIn
= NULL
;
269 m_windowSizer
= NULL
;
270 m_sizerParent
= NULL
;
271 m_autoLayout
= FALSE
;
272 m_windowValidator
= NULL
;
273 #if wxUSE_DRAG_AND_DROP
274 m_pDropTarget
= NULL
;
276 m_caretWidth
= 0; m_caretHeight
= 0;
277 m_caretEnabled
= FALSE
;
278 m_caretShown
= FALSE
;
283 m_defaultItem
= NULL
;
284 m_windowParent
= NULL
;
287 m_canAddEventHandler
= FALSE
;
288 m_mainWidget
= (WXWidget
) 0;
289 m_button1Pressed
= FALSE
;
290 m_button2Pressed
= FALSE
;
291 m_button3Pressed
= FALSE
;
292 m_winCaptured
= FALSE
;
294 m_hScrollBar
= (WXWidget
) 0;
295 m_vScrollBar
= (WXWidget
) 0;
296 m_borderWidget
= (WXWidget
) 0;
297 m_scrolledWindow
= (WXWidget
) 0;
298 m_drawingArea
= (WXWidget
) 0;
301 m_backingPixmap
= (WXPixmap
) 0;
308 m_paintRegion
= (WXRegion
) 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 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
483 void wxWindow::SetFocus()
485 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
486 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
489 void wxWindow::Enable(bool enable
)
493 XtSetSensitive((Widget
) GetMainWidget(), enable
);
494 XmUpdateDisplay((Widget
) GetMainWidget());
498 void wxWindow::CaptureMouse()
504 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
506 m_winCaptured
= TRUE
;
509 void wxWindow::ReleaseMouse()
515 XtRemoveGrab((Widget
) GetMainWidget());
516 m_winCaptured
= FALSE
;
519 // Push/pop event handler (i.e. allow a chain of event handlers
521 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
523 handler
->SetNextHandler(GetEventHandler());
524 SetEventHandler(handler
);
527 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
529 if ( GetEventHandler() )
531 wxEvtHandler
*handlerA
= GetEventHandler();
532 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
533 handlerA
->SetNextHandler(NULL
);
534 SetEventHandler(handlerB
);
547 #if wxUSE_DRAG_AND_DROP
549 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
551 if ( m_pDropTarget
!= 0 ) {
552 delete m_pDropTarget
;
555 m_pDropTarget
= pDropTarget
;
556 if ( m_pDropTarget
!= 0 )
564 // Old style file-manager drag&drop
565 void wxWindow::DragAcceptFiles(bool accept
)
571 void wxWindow::GetSize(int *x
, int *y
) const
579 Widget widget
= (Widget
) GetTopWidget();
581 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
585 void wxWindow::GetPosition(int *x
, int *y
) const
589 CanvasGetPosition(x
, y
);
592 Widget widget
= (Widget
) GetTopWidget();
594 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
598 void wxWindow::ScreenToClient(int *x
, int *y
) const
600 Widget widget
= (Widget
) GetClientWidget();
601 Display
*display
= XtDisplay((Widget
) GetMainWidget());
602 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
603 Window thisWindow
= XtWindow(widget
);
608 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
611 void wxWindow::ClientToScreen(int *x
, int *y
) const
613 Widget widget
= (Widget
) GetClientWidget();
614 Display
*display
= XtDisplay(widget
);
615 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
616 Window thisWindow
= XtWindow(widget
);
621 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
624 void wxWindow::SetCursor(const wxCursor
& cursor
)
626 m_windowCursor
= cursor
;
627 if (m_windowCursor
.Ok())
629 WXDisplay
*dpy
= GetXDisplay();
630 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
632 Widget w
= (Widget
) GetMainWidget();
633 Window win
= XtWindow(w
);
634 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
639 // Get size *available for subwindows* i.e. excluding menu bar etc.
640 void wxWindow::GetClientSize(int *x
, int *y
) const
642 Widget widget
= (Widget
) GetClientWidget();
644 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
648 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
652 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
655 Widget widget
= (Widget
) GetTopWidget();
659 bool managed
= XtIsManaged( widget
);
661 XtUnmanageChild(widget
);
663 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
664 XtVaSetValues(widget
, XmNx
, x
, NULL
);
665 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
666 XtVaSetValues(widget
, XmNy
, y
, NULL
);
668 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
670 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
673 XtManageChild(widget
);
675 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
676 sizeEvent
.SetEventObject(this);
678 GetEventHandler()->ProcessEvent(sizeEvent
);
681 void wxWindow::SetClientSize(int width
, int height
)
685 CanvasSetClientSize(width
, height
);
689 Widget widget
= (Widget
) GetTopWidget();
692 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
694 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
696 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
697 sizeEvent
.SetEventObject(this);
699 GetEventHandler()->ProcessEvent(sizeEvent
);
702 // For implementation purposes - sometimes decorations make the client area
704 wxPoint
wxWindow::GetClientAreaOrigin() const
706 return wxPoint(0, 0);
709 // Makes an adjustment to the window position (for example, a frame that has
710 // a toolbar that it manages itself).
711 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
713 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
715 wxPoint
pt(GetParent()->GetClientAreaOrigin());
716 x
+= pt
.x
; y
+= pt
.y
;
720 bool wxWindow::Show(bool show
)
724 if (m_borderWidget
|| m_scrolledWindow
)
726 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
730 XtMapWidget((Widget
) GetTopWidget());
735 if (m_borderWidget
|| m_scrolledWindow
)
737 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
741 XtUnmapWidget((Widget
) GetTopWidget());
746 Window xwin = (Window) GetXWindow();
747 Display *xdisp = (Display*) GetXDisplay();
749 XMapWindow(xdisp, xwin);
751 XUnmapWindow(xdisp, xwin);
759 bool wxWindow::IsShown() const
764 int wxWindow::GetCharHeight() const
766 if (!m_windowFont
.Ok())
769 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
771 int direction
, ascent
, descent
;
773 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
775 // return (overall.ascent + overall.descent);
776 return (ascent
+ descent
);
779 int wxWindow::GetCharWidth() const
781 if (!m_windowFont
.Ok())
784 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
786 int direction
, ascent
, descent
;
788 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
790 return overall
.width
;
793 /* Helper function for 16-bit fonts */
794 static int str16len(const char *s
)
798 while (s
[0] && s
[1]) {
806 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
807 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
809 wxFont
*fontToUse
= (wxFont
*)theFont
;
811 fontToUse
= (wxFont
*) & m_windowFont
;
813 if (!fontToUse
->Ok())
816 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
818 int direction
, ascent
, descent2
;
822 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
825 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
826 &ascent
, &descent2
, &overall
);
828 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
829 &ascent
, &descent2
, &overall
);
831 *x
= (overall
.width
);
832 *y
= (ascent
+ descent2
);
836 *externalLeading
= 0;
839 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
841 Display
*display
= XtDisplay((Widget
) GetMainWidget());
842 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
844 XExposeEvent dummyEvent
;
846 GetSize(&width
, &height
);
848 dummyEvent
.type
= Expose
;
849 dummyEvent
.display
= display
;
850 dummyEvent
.send_event
= True
;
851 dummyEvent
.window
= thisWindow
;
854 dummyEvent
.x
= rect
->x
;
855 dummyEvent
.y
= rect
->y
;
856 dummyEvent
.width
= rect
->width
;
857 dummyEvent
.height
= rect
->height
;
863 dummyEvent
.width
= width
;
864 dummyEvent
.height
= height
;
866 dummyEvent
.count
= 0;
871 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
872 dc
.SetBackground(backgroundBrush
);
876 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
879 // Responds to colour changes: passes event on to children.
880 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
882 wxNode
*node
= GetChildren()->First();
885 // Only propagate to non-top-level windows
886 wxWindow
*win
= (wxWindow
*)node
->Data();
887 if ( win
->GetParent() )
889 wxSysColourChangedEvent event2
;
890 event
.m_eventObject
= win
;
891 win
->GetEventHandler()->ProcessEvent(event2
);
898 // This can be called by the app (or wxWindows) to do default processing for the current
899 // event. Save message/event info in wxWindow so they can be used in this function.
900 long wxWindow::Default()
906 void wxWindow::InitDialog()
908 wxInitDialogEvent
event(GetId());
909 event
.SetEventObject( this );
910 GetEventHandler()->ProcessEvent(event
);
913 // Default init dialog behaviour is to transfer data to window
914 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
916 TransferDataToWindow();
919 // Caret manipulation
920 void wxWindow::CreateCaret(int w
, int h
)
924 m_caretEnabled
= TRUE
;
927 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
932 void wxWindow::ShowCaret(bool show
)
937 void wxWindow::DestroyCaret()
940 m_caretEnabled
= FALSE
;
943 void wxWindow::SetCaretPos(int x
, int y
)
948 void wxWindow::GetCaretPos(int *x
, int *y
) const
953 wxWindow
*wxGetActiveWindow()
959 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
966 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
969 wxFrame
*frame
= (wxFrame
*)this;
970 Widget widget
= (Widget
) frame
->GetShellWidget();
973 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
975 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
977 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
979 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
981 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
983 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
986 void wxWindow::Centre(int direction
)
988 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
990 wxWindow
*father
= (wxWindow
*)GetParent();
994 father
->GetClientSize(&panel_width
, &panel_height
);
995 GetSize(&width
, &height
);
1001 if (direction
& wxHORIZONTAL
)
1002 new_x
= (int)((panel_width
- width
)/2);
1004 if (direction
& wxVERTICAL
)
1005 new_y
= (int)((panel_height
- height
)/2);
1007 SetSize(new_x
, new_y
, -1, -1);
1011 // Coordinates relative to the window
1012 void wxWindow::WarpPointer (int x
, int y
)
1014 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1017 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1023 int wxWindow::GetScrollPos(int orient
) const
1025 if (orient
== wxHORIZONTAL
)
1026 return m_scrollPosX
;
1028 return m_scrollPosY
;
1030 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1034 XtVaGetValues(scrollBar,
1035 XmNvalue, &pos, NULL);
1043 // This now returns the whole range, not just the number
1044 // of positions that we can scroll.
1045 int wxWindow::GetScrollRange(int orient
) const
1047 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1051 XtVaGetValues(scrollBar
,
1052 XmNmaximum
, &range
, NULL
);
1059 int wxWindow::GetScrollThumb(int orient
) const
1061 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1065 XtVaGetValues(scrollBar
,
1066 XmNsliderSize
, &thumb
, NULL
);
1073 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1075 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1078 XtVaSetValues (scrollBar
,
1082 if (orient
== wxHORIZONTAL
)
1089 // New function that will replace some of the above.
1090 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1091 int range
, bool WXUNUSED(refresh
))
1093 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1099 if (thumbVisible
== 0)
1102 XtVaSetValues(scrollBar
,
1106 XmNsliderSize
, thumbVisible
,
1109 if (orient
== wxHORIZONTAL
)
1115 // Does a physical scroll
1116 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
1118 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1122 // Use specified rectangle
1123 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1127 // Use whole client area
1129 GetClientSize(& w
, & h
);
1132 int x1
= (dx
>= 0) ? x
: x
- dx
;
1133 int y1
= (dy
>= 0) ? y
: y
- dy
;
1134 int w1
= w
- abs(dx
);
1135 int h1
= h
- abs(dy
);
1136 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1137 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1139 wxClientDC
dc(this);
1141 dc
.SetLogicalFunction (wxCOPY
);
1143 Widget widget
= (Widget
) GetMainWidget();
1144 Window window
= XtWindow(widget
);
1145 Display
* display
= XtDisplay(widget
);
1147 XCopyArea(display
, window
,
1148 window
, (GC
) dc
.GetGC(),
1153 dc
.SetAutoSetting(TRUE
);
1154 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1155 dc
.SetBrush(brush
); // ??
1157 // We'll add rectangles to the list of update rectangles
1158 // according to which bits we've exposed.
1163 wxRect
*rect
= new wxRect
;
1169 XFillRectangle(display
, window
,
1170 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1174 rect
->width
= rect
->width
;
1175 rect
->height
= rect
->height
;
1177 updateRects
.Append((wxObject
*) rect
);
1181 wxRect
*rect
= new wxRect
;
1183 rect
->x
= x
+ w
+ dx
;
1188 XFillRectangle(display
, window
,
1189 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1194 rect
->width
= rect
->width
;
1195 rect
->height
= rect
->height
;
1197 updateRects
.Append((wxObject
*) rect
);
1201 wxRect
*rect
= new wxRect
;
1208 XFillRectangle(display
, window
,
1209 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1213 rect
->width
= rect
->width
;
1214 rect
->height
= rect
->height
;
1216 updateRects
.Append((wxObject
*) rect
);
1220 wxRect
*rect
= new wxRect
;
1223 rect
->y
= y
+ h
+ dy
;
1227 XFillRectangle(display
, window
,
1228 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1232 rect
->width
= rect
->width
;
1233 rect
->height
= rect
->height
;
1235 updateRects
.Append((wxObject
*) rect
);
1237 dc
.SetBrush(wxNullBrush
);
1239 // Now send expose events
1241 wxNode
* node
= updateRects
.First();
1244 wxRect
* rect
= (wxRect
*) node
->Data();
1247 event
.type
= Expose
;
1248 event
.display
= display
;
1249 event
.send_event
= True
;
1250 event
.window
= window
;
1254 event
.width
= rect
->width
;
1255 event
.height
= rect
->height
;
1259 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1261 node
= node
->Next();
1266 void wxWindow::SetFont(const wxFont
& font
)
1268 m_windowFont
= font
;
1270 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
1271 if (w
&& m_windowFont
.Ok())
1274 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
1279 void wxWindow::OnChar(wxKeyEvent
& event
)
1281 if ( event
.KeyCode() == WXK_TAB
) {
1282 // propagate the TABs to the parent - it's up to it to decide what
1284 if ( GetParent() ) {
1285 if ( GetParent()->ProcessEvent(event
) )
1291 void wxWindow::OnPaint(wxPaintEvent
& event
)
1296 bool wxWindow::IsEnabled() const
1298 // TODO. Is this right?
1299 // return XtGetSensitive((Widget) GetMainWidget());
1303 // Dialog support: override these and call
1304 // base class members to add functionality
1305 // that can't be done using validators.
1306 // NOTE: these functions assume that controls
1307 // are direct children of this window, not grandchildren
1308 // or other levels of descendant.
1310 // Transfer values to controls. If returns FALSE,
1311 // it's an application error (pops up a dialog)
1312 bool wxWindow::TransferDataToWindow()
1314 wxNode
*node
= GetChildren()->First();
1317 wxWindow
*child
= (wxWindow
*)node
->Data();
1318 if ( child
->GetValidator() &&
1319 !child
->GetValidator()->TransferToWindow() )
1321 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1325 node
= node
->Next();
1330 // Transfer values from controls. If returns FALSE,
1331 // validation failed: don't quit
1332 bool wxWindow::TransferDataFromWindow()
1334 wxNode
*node
= GetChildren()->First();
1337 wxWindow
*child
= (wxWindow
*)node
->Data();
1338 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1343 node
= node
->Next();
1348 bool wxWindow::Validate()
1350 wxNode
*node
= GetChildren()->First();
1353 wxWindow
*child
= (wxWindow
*)node
->Data();
1354 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1359 node
= node
->Next();
1364 // Get the window with the focus
1365 wxWindow
*wxWindow::FindFocus()
1371 void wxWindow::AddChild(wxWindow
*child
)
1373 GetChildren()->Append(child
);
1374 child
->m_windowParent
= this;
1377 void wxWindow::RemoveChild(wxWindow
*child
)
1380 GetChildren()->DeleteObject(child
);
1381 child
->m_windowParent
= NULL
;
1384 void wxWindow::DestroyChildren()
1386 if (GetChildren()) {
1388 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1390 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1392 if ( GetChildren()->Member(child
) )
1399 void wxWindow::MakeModal(bool modal
)
1401 // Disable all other windows
1402 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1404 wxNode
*node
= wxTopLevelWindows
.First();
1407 wxWindow
*win
= (wxWindow
*)node
->Data();
1409 win
->Enable(!modal
);
1411 node
= node
->Next();
1416 // If nothing defined for this, try the parent.
1417 // E.g. we may be a button loaded from a resource, with no callback function
1419 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1421 if (GetEventHandler()->ProcessEvent(event
) )
1424 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1427 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1431 UnsetConstraints(m_constraints
);
1432 delete m_constraints
;
1437 // Make sure other windows know they're part of a 'meaningful relationship'
1438 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1439 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1440 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1441 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1442 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1443 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1444 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1445 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1446 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1447 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1448 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1449 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1450 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1451 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1452 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1453 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1457 // This removes any dangling pointers to this window
1458 // in other windows' constraintsInvolvedIn lists.
1459 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1463 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1464 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1465 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1466 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1467 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1468 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1469 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1470 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1471 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1472 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1473 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1474 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1475 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1476 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1477 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1478 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1482 // Back-pointer to other windows we're involved with, so if we delete
1483 // this window, we must delete any constraints we're involved with.
1484 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1486 if (!m_constraintsInvolvedIn
)
1487 m_constraintsInvolvedIn
= new wxList
;
1488 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1489 m_constraintsInvolvedIn
->Append(otherWin
);
1492 // REMOVE back-pointer to other windows we're involved with.
1493 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1495 if (m_constraintsInvolvedIn
)
1496 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1499 // Reset any constraints that mention this window
1500 void wxWindow::DeleteRelatedConstraints()
1502 if (m_constraintsInvolvedIn
)
1504 wxNode
*node
= m_constraintsInvolvedIn
->First();
1507 wxWindow
*win
= (wxWindow
*)node
->Data();
1508 wxNode
*next
= node
->Next();
1509 wxLayoutConstraints
*constr
= win
->GetConstraints();
1511 // Reset any constraints involving this window
1514 constr
->left
.ResetIfWin((wxWindow
*)this);
1515 constr
->top
.ResetIfWin((wxWindow
*)this);
1516 constr
->right
.ResetIfWin((wxWindow
*)this);
1517 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1518 constr
->width
.ResetIfWin((wxWindow
*)this);
1519 constr
->height
.ResetIfWin((wxWindow
*)this);
1520 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1521 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1526 delete m_constraintsInvolvedIn
;
1527 m_constraintsInvolvedIn
= NULL
;
1531 void wxWindow::SetSizer(wxSizer
*sizer
)
1533 m_windowSizer
= sizer
;
1535 sizer
->SetSizerParent((wxWindow
*)this);
1542 bool wxWindow::Layout()
1544 if (GetConstraints())
1547 GetClientSize(&w
, &h
);
1548 GetConstraints()->width
.SetValue(w
);
1549 GetConstraints()->height
.SetValue(h
);
1552 // If top level (one sizer), evaluate the sizer's constraints.
1556 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1557 GetSizer()->LayoutPhase1(&noChanges
);
1558 GetSizer()->LayoutPhase2(&noChanges
);
1559 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1564 // Otherwise, evaluate child constraints
1565 ResetConstraints(); // Mark all constraints as unevaluated
1566 DoPhase(1); // Just one phase need if no sizers involved
1568 SetConstraintSizes(); // Recursively set the real window sizes
1574 // Do a phase of evaluating constraints:
1575 // the default behaviour. wxSizers may do a similar
1576 // thing, but also impose their own 'constraints'
1577 // and order the evaluation differently.
1578 bool wxWindow::LayoutPhase1(int *noChanges
)
1580 wxLayoutConstraints
*constr
= GetConstraints();
1583 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1589 bool wxWindow::LayoutPhase2(int *noChanges
)
1599 // Do a phase of evaluating child constraints
1600 bool wxWindow::DoPhase(int phase
)
1602 int noIterations
= 0;
1603 int maxIterations
= 500;
1607 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1611 wxNode
*node
= GetChildren()->First();
1614 wxWindow
*child
= (wxWindow
*)node
->Data();
1615 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1617 wxLayoutConstraints
*constr
= child
->GetConstraints();
1620 if (succeeded
.Member(child
))
1625 int tempNoChanges
= 0;
1626 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1627 noChanges
+= tempNoChanges
;
1630 succeeded
.Append(child
);
1635 node
= node
->Next();
1642 void wxWindow::ResetConstraints()
1644 wxLayoutConstraints
*constr
= GetConstraints();
1647 constr
->left
.SetDone(FALSE
);
1648 constr
->top
.SetDone(FALSE
);
1649 constr
->right
.SetDone(FALSE
);
1650 constr
->bottom
.SetDone(FALSE
);
1651 constr
->width
.SetDone(FALSE
);
1652 constr
->height
.SetDone(FALSE
);
1653 constr
->centreX
.SetDone(FALSE
);
1654 constr
->centreY
.SetDone(FALSE
);
1656 wxNode
*node
= GetChildren()->First();
1659 wxWindow
*win
= (wxWindow
*)node
->Data();
1660 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1661 win
->ResetConstraints();
1662 node
= node
->Next();
1666 // Need to distinguish between setting the 'fake' size for
1667 // windows and sizers, and setting the real values.
1668 void wxWindow::SetConstraintSizes(bool recurse
)
1670 wxLayoutConstraints
*constr
= GetConstraints();
1671 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1672 constr
->width
.GetDone() && constr
->height
.GetDone())
1674 int x
= constr
->left
.GetValue();
1675 int y
= constr
->top
.GetValue();
1676 int w
= constr
->width
.GetValue();
1677 int h
= constr
->height
.GetValue();
1679 // If we don't want to resize this window, just move it...
1680 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1681 (constr
->height
.GetRelationship() != wxAsIs
))
1683 // Calls Layout() recursively. AAAGH. How can we stop that.
1684 // Simply take Layout() out of non-top level OnSizes.
1685 SizerSetSize(x
, y
, w
, h
);
1694 char *windowClass
= this->GetClassInfo()->GetClassName();
1697 if (GetName() == "")
1698 winName
= "unnamed";
1700 winName
= GetName();
1701 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1702 if (!constr
->left
.GetDone())
1703 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1704 if (!constr
->right
.GetDone())
1705 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1706 if (!constr
->width
.GetDone())
1707 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1708 if (!constr
->height
.GetDone())
1709 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1710 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1715 wxNode
*node
= GetChildren()->First();
1718 wxWindow
*win
= (wxWindow
*)node
->Data();
1719 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1720 win
->SetConstraintSizes();
1721 node
= node
->Next();
1726 // This assumes that all sizers are 'on' the same
1727 // window, i.e. the parent of this window.
1728 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1730 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1731 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1735 m_sizerParent
->GetPosition(&xp
, &yp
);
1736 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1741 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1745 TransformSizerToActual(&xx
, &yy
);
1746 SetSize(xx
, yy
, w
, h
);
1749 void wxWindow::SizerMove(int x
, int y
)
1753 TransformSizerToActual(&xx
, &yy
);
1757 // Only set the size/position of the constraint (if any)
1758 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1760 wxLayoutConstraints
*constr
= GetConstraints();
1765 constr
->left
.SetValue(x
);
1766 constr
->left
.SetDone(TRUE
);
1770 constr
->top
.SetValue(y
);
1771 constr
->top
.SetDone(TRUE
);
1775 constr
->width
.SetValue(w
);
1776 constr
->width
.SetDone(TRUE
);
1780 constr
->height
.SetValue(h
);
1781 constr
->height
.SetDone(TRUE
);
1786 void wxWindow::MoveConstraint(int x
, int y
)
1788 wxLayoutConstraints
*constr
= GetConstraints();
1793 constr
->left
.SetValue(x
);
1794 constr
->left
.SetDone(TRUE
);
1798 constr
->top
.SetValue(y
);
1799 constr
->top
.SetDone(TRUE
);
1804 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1806 wxLayoutConstraints
*constr
= GetConstraints();
1809 *w
= constr
->width
.GetValue();
1810 *h
= constr
->height
.GetValue();
1816 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1818 wxLayoutConstraints
*constr
= GetConstraints();
1821 *w
= constr
->width
.GetValue();
1822 *h
= constr
->height
.GetValue();
1825 GetClientSize(w
, h
);
1828 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1830 wxLayoutConstraints
*constr
= GetConstraints();
1833 *x
= constr
->left
.GetValue();
1834 *y
= constr
->top
.GetValue();
1840 bool wxWindow::Close(bool force
)
1842 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1843 event
.SetEventObject(this);
1844 event
.SetForce(force
);
1846 return GetEventHandler()->ProcessEvent(event
);
1849 wxObject
* wxWindow::GetChild(int number
) const
1851 // Return a pointer to the Nth object in the window
1854 wxNode
*node
= GetChildren()->First();
1857 node
= node
->Next() ;
1860 wxObject
*obj
= (wxObject
*)node
->Data();
1867 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1869 // Obsolete function
1872 void wxWindow::Clear()
1874 wxClientDC
dc(this);
1875 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1876 dc
.SetBackground(brush
);
1880 // Fits the panel around the items
1881 void wxWindow::Fit()
1885 wxNode
*node
= GetChildren()->First();
1888 wxWindow
*win
= (wxWindow
*)node
->Data();
1890 win
->GetPosition(&wx
, &wy
);
1891 win
->GetSize(&ww
, &wh
);
1892 if ( wx
+ ww
> maxX
)
1894 if ( wy
+ wh
> maxY
)
1897 node
= node
->Next();
1899 SetClientSize(maxX
+ 5, maxY
+ 5);
1902 void wxWindow::SetValidator(const wxValidator
& validator
)
1904 if ( m_windowValidator
)
1905 delete m_windowValidator
;
1906 m_windowValidator
= validator
.Clone();
1908 if ( m_windowValidator
)
1909 m_windowValidator
->SetWindow(this) ;
1912 // Find a window by id or name
1913 wxWindow
*wxWindow::FindWindow(long id
)
1918 wxNode
*node
= GetChildren()->First();
1921 wxWindow
*child
= (wxWindow
*)node
->Data();
1922 wxWindow
*found
= child
->FindWindow(id
);
1925 node
= node
->Next();
1930 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1932 if ( GetName() == name
)
1935 wxNode
*node
= GetChildren()->First();
1938 wxWindow
*child
= (wxWindow
*)node
->Data();
1939 wxWindow
*found
= child
->FindWindow(name
);
1942 node
= node
->Next();
1947 void wxWindow::OnIdle(wxIdleEvent
& event
)
1949 /* TODO: you may need to do something like this
1950 * if your GUI doesn't generate enter/leave events
1952 // Check if we need to send a LEAVE event
1953 if (m_mouseInWindow)
1956 ::GetCursorPos(&pt);
1957 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1959 // Generate a LEAVE event
1960 m_mouseInWindow = FALSE;
1961 MSWOnMouseLeave(pt.x, pt.y, 0);
1966 // This calls the UI-update mechanism (querying windows for
1967 // menu/toolbar/control state information)
1971 // Raise the window to the top of the Z order
1972 void wxWindow::Raise()
1974 Window window
= XtWindow((Widget
) GetTopWidget());
1975 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1978 // Lower the window to the bottom of the Z order
1979 void wxWindow::Lower()
1981 Window window
= XtWindow((Widget
) GetTopWidget());
1982 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1985 bool wxWindow::AcceptsFocus() const
1987 return IsShown() && IsEnabled();
1990 // Update region access
1991 wxRegion
wxWindow::GetUpdateRegion() const
1993 return m_updateRegion
;
1996 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1998 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2001 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2003 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2006 bool wxWindow::IsExposed(const wxRect
& rect
) const
2008 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2012 * Allocates control IDs
2015 int wxWindow::NewControlId()
2017 static int s_controlId
= 0;
2022 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2024 m_acceleratorTable
= accel
;
2027 // All widgets should have this as their resize proc.
2028 // OnSize sent to wxWindow via client data.
2029 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2031 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2035 if (win
->PreResize())
2038 win
->GetSize(&width
, &height
);
2039 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2040 sizeEvent
.SetEventObject(win
);
2041 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2045 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2047 wxWindow
*oldItem
= NULL
;
2049 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2051 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2054 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2057 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2062 wxWidgetHashTable
->Put ((long) w
, win
);
2066 wxWindow
*wxGetWindowFromTable(Widget w
)
2068 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2071 void wxDeleteWindowFromTable(Widget w
)
2073 wxWidgetHashTable
->Delete((long)w
);
2076 // Get the underlying X window and display
2077 WXWindow
wxWindow::GetXWindow() const
2079 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2082 WXDisplay
*wxWindow::GetXDisplay() const
2084 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2087 WXWidget
wxWindow::GetMainWidget() const
2090 return m_drawingArea
;
2092 return m_mainWidget
;
2095 WXWidget
wxWindow::GetClientWidget() const
2097 if (m_drawingArea
!= (WXWidget
) 0)
2098 return m_drawingArea
;
2100 return GetMainWidget();
2103 WXWidget
wxWindow::GetTopWidget() const
2105 return GetMainWidget();
2108 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2109 XmDrawingAreaCallbackStruct
* cbs
)
2111 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2114 XEvent
* event
= cbs
->event
;
2115 wxWindow
* canvas
= (wxWindow
*) clientData
;
2116 Display
* display
= (Display
*) canvas
->GetXDisplay();
2117 // GC gc = (GC) canvas->GetDC()->gc;
2119 switch (event
->type
)
2124 wxCanvasDC* canvasDC = canvas->GetDC();
2127 if (canvasDC->onpaint_reg)
2128 XDestroyRegion(canvasDC->onpaint_reg);
2129 canvasDC->onpaint_reg = XCreateRegion();
2134 int n
= canvas
->m_updateRects
.Number();
2135 XRectangle
* xrects
= new XRectangle
[n
];
2137 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
2139 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
2140 xrects
[i
].x
= rect
->x
;
2141 xrects
[i
].y
= rect
->y
;
2142 xrects
[i
].width
= rect
->width
;
2143 xrects
[i
].height
= rect
->height
;
2144 /* TODO (?) Actually ignore it I think.
2146 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
2147 canvasDC->onpaint_reg);
2150 /* TODO must clip the area being repainted. So we need a gc.
2151 * Alternatively, wxPaintDC must do the clipping
2152 * when it's created.
2153 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
2156 canvas
->DoPaint() ; // xrects, n);
2159 canvas
->m_updateRects
.Clear();
2164 XDestroyRegion(canvasDC->onpaint_reg);
2165 canvasDC->onpaint_reg = NULL;
2169 gc_val.clip_mask = None;
2170 XChangeGC(display, gc, GCClipMask, &gc_val);
2177 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2183 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2185 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2187 XmDrawingAreaCallbackStruct cbs
;
2190 //if (event->mode!=NotifyNormal)
2193 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2194 ((XCrossingEvent
&) ev
) = *event
;
2196 cbs
.reason
= XmCR_INPUT
;
2199 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2202 // Fix to make it work under Motif 1.0 (!)
2203 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2207 XmDrawingAreaCallbackStruct cbs
;
2210 //ev.xbutton = *event;
2211 ev
= *((XEvent
*) event
);
2212 cbs
.reason
= XmCR_INPUT
;
2215 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2219 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2221 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2227 if (cbs
->reason
!= XmCR_INPUT
)
2230 local_event
= *(cbs
->event
); // We must keep a copy!
2232 switch (local_event
.xany
.type
)
2240 wxEventType eventType
= wxEVT_NULL
;
2242 if (local_event
.xany
.type
== EnterNotify
)
2244 //if (local_event.xcrossing.mode!=NotifyNormal)
2245 // return ; // Ignore grab events
2246 eventType
= wxEVT_ENTER_WINDOW
;
2247 // canvas->GetEventHandler()->OnSetFocus();
2249 else if (local_event
.xany
.type
== LeaveNotify
)
2251 //if (local_event.xcrossing.mode!=NotifyNormal)
2252 // return ; // Ignore grab events
2253 eventType
= wxEVT_LEAVE_WINDOW
;
2254 // canvas->GetEventHandler()->OnKillFocus();
2256 else if (local_event
.xany
.type
== MotionNotify
)
2258 eventType
= wxEVT_MOTION
;
2259 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2262 Display
*dpy
= XtDisplay (drawingArea
);
2264 XQueryPointer (dpy
, XtWindow (drawingArea
),
2266 &local_event
.xmotion
.x_root
,
2267 &local_event
.xmotion
.y_root
,
2268 &local_event
.xmotion
.x
,
2269 &local_event
.xmotion
.y
,
2270 &local_event
.xmotion
.state
);
2277 else if (local_event
.xany
.type
== ButtonPress
)
2279 if (local_event
.xbutton
.button
== Button1
)
2281 eventType
= wxEVT_LEFT_DOWN
;
2282 canvas
->m_button1Pressed
= TRUE
;
2284 else if (local_event
.xbutton
.button
== Button2
)
2286 eventType
= wxEVT_MIDDLE_DOWN
;
2287 canvas
->m_button2Pressed
= TRUE
;
2289 else if (local_event
.xbutton
.button
== Button3
)
2291 eventType
= wxEVT_RIGHT_DOWN
;
2292 canvas
->m_button3Pressed
= TRUE
;
2295 else if (local_event
.xany
.type
== ButtonRelease
)
2297 if (local_event
.xbutton
.button
== Button1
)
2299 eventType
= wxEVT_LEFT_UP
;
2300 canvas
->m_button1Pressed
= FALSE
;
2302 else if (local_event
.xbutton
.button
== Button2
)
2304 eventType
= wxEVT_MIDDLE_UP
;
2305 canvas
->m_button2Pressed
= FALSE
;
2307 else if (local_event
.xbutton
.button
== Button3
)
2309 eventType
= wxEVT_RIGHT_UP
;
2310 canvas
->m_button3Pressed
= FALSE
;
2314 wxMouseEvent
wxevent (eventType
);
2315 wxevent
.m_eventHandle
= (char *) &local_event
;
2317 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2318 || (event_left_is_down (&local_event
)
2319 && (eventType
!= wxEVT_LEFT_UP
)));
2320 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2321 || (event_middle_is_down (&local_event
)
2322 && (eventType
!= wxEVT_MIDDLE_UP
)));
2323 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2324 || (event_right_is_down (&local_event
)
2325 && (eventType
!= wxEVT_RIGHT_UP
)));
2327 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2328 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2329 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2330 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2331 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2333 // Now check if we need to translate this event into a double click
2334 if (TRUE
) // canvas->doubleClickAllowed)
2336 if (wxevent
.ButtonDown())
2338 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2340 // get button and time-stamp
2342 if (wxevent
.LeftDown()) button
= 1;
2343 else if (wxevent
.MiddleDown()) button
= 2;
2344 else if (wxevent
.RightDown()) button
= 3;
2345 long ts
= wxevent
.GetTimestamp();
2346 // check, if single or double click
2347 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2350 canvas
->m_lastButton
= 0;
2351 switch ( eventType
)
2353 case wxEVT_LEFT_DOWN
:
2354 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2356 case wxEVT_MIDDLE_DOWN
:
2357 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2359 case wxEVT_RIGHT_DOWN
:
2360 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2370 // not fast enough or different button
2371 canvas
->m_lastTS
= ts
;
2372 canvas
->m_lastButton
= button
;
2377 wxevent
.SetId(canvas
->GetId());
2378 wxevent
.SetEventObject(canvas
);
2379 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2381 if (eventType == wxEVT_ENTER_WINDOW ||
2382 eventType == wxEVT_LEAVE_WINDOW ||
2383 eventType == wxEVT_MOTION
2392 // XComposeStatus compose;
2393 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2394 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2395 int id
= wxCharCodeXToWX (keySym
);
2397 wxKeyEvent
event (wxEVT_CHAR
);
2399 if (local_event
.xkey
.state
& ShiftMask
)
2400 event
.m_shiftDown
= TRUE
;
2401 if (local_event
.xkey
.state
& ControlMask
)
2402 event
.m_controlDown
= TRUE
;
2403 if (local_event
.xkey
.state
& Mod3Mask
)
2404 event
.m_altDown
= TRUE
;
2405 if (local_event
.xkey
.state
& Mod1Mask
)
2406 event
.m_metaDown
= TRUE
;
2407 event
.SetEventObject(canvas
);
2408 event
.m_keyCode
= id
;
2409 event
.SetTimestamp(local_event
.xkey
.time
);
2413 // Implement wxFrame::OnCharHook by checking ancestor.
2414 wxWindow
*parent
= canvas
->GetParent();
2415 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2416 parent
= parent
->GetParent();
2420 event
.SetEventType(wxEVT_CHAR_HOOK
);
2421 if (parent
->GetEventHandler()->ProcessEvent(event
))
2423 event
.SetEventType(wxEVT_CHAR
);
2426 canvas
->GetEventHandler()->ProcessEvent (event
);
2432 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2434 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2435 event
.SetEventObject(canvas
);
2436 canvas
->GetEventHandler()->ProcessEvent(event
);
2442 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2444 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2445 event
.SetEventObject(canvas
);
2446 canvas
->GetEventHandler()->ProcessEvent(event
);
2455 void wxWindow::DoPaint()
2457 //TODO : make a temporary gc so we can do the XCopyArea below
2458 if (0) // m_backingPixmap)
2461 Widget drawingArea = (Widget) m_drawingArea;
2462 // int orig = GetDC()->GetLogicalFunction();
2463 // GetDC()->SetLogicalFunction (wxCOPY);
2465 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2466 // should be able to calculate them.
2467 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2468 m_pixmapOffsetX, m_pixmapOffsetY,
2469 m_pixmapWidth, m_pixmapHeight,
2472 // GetDC()->SetLogicalFunction (orig);
2477 wxPaintEvent
event(GetId());
2478 event
.SetEventObject(this);
2479 GetEventHandler()->ProcessEvent(event
);
2483 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2484 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2486 Widget drawingArea
= (Widget
) m_drawingArea
;
2487 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2490 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2491 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2493 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2495 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2499 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2501 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2509 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2510 short thick
, margin
;
2511 XtVaGetValues ((Widget
) m_borderWidget
,
2512 XmNshadowThickness
, &thick
,
2513 XmNmarginWidth
, &margin
,
2515 w
-= 2 * (thick
+ margin
);
2518 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2522 XtVaGetValues ((Widget
) m_scrolledWindow
,
2523 XmNspacing
, &spacing
,
2524 XmNverticalScrollBar
, &sbar
,
2528 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2532 w
-= (spacing
+ wsbar
);
2534 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2540 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2541 short thick
, margin
;
2542 XtVaGetValues ((Widget
) m_borderWidget
,
2543 XmNshadowThickness
, &thick
,
2544 XmNmarginHeight
, &margin
,
2546 h
-= 2 * (thick
+ margin
);
2549 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2553 XtVaGetValues ((Widget
) m_scrolledWindow
,
2554 XmNspacing
, &spacing
,
2555 XmNhorizontalScrollBar
, &sbar
,
2559 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2563 h
-= (spacing
+ wsbar
);
2565 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2568 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2569 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2572 GetClientSize (&ww
, &hh
);
2573 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2574 sizeEvent
.SetEventObject(this);
2576 GetEventHandler()->ProcessEvent(sizeEvent
);
2579 void wxWindow::CanvasSetClientSize (int w
, int h
)
2581 Widget drawingArea
= (Widget
) m_drawingArea
;
2583 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2586 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2588 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2589 /* TODO: is this necessary?
2590 allowRepainting = FALSE;
2592 XSync (XtDisplay (drawingArea), FALSE);
2594 while (XtAppPending (wxTheApp->appContext))
2596 XFlush (XtDisplay (drawingArea));
2597 XtAppNextEvent (wxTheApp->appContext, &event);
2598 XtDispatchEvent (&event);
2602 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2605 allowRepainting = TRUE;
2609 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2610 sizeEvent
.SetEventObject(this);
2612 GetEventHandler()->ProcessEvent(sizeEvent
);
2615 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2617 // Must return the same thing that was set via SetClientSize
2619 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2624 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2627 if ((Widget
) m_borderWidget
)
2628 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2629 else if ((Widget
) m_scrolledWindow
)
2630 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2632 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2638 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2641 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2646 // Add to hash table, add event handler
2647 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2648 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2650 wxAddWindowToTable((Widget
) mainWidget
, this);
2651 if (CanAddEventHandler())
2653 XtAddEventHandler((Widget
) mainWidget
,
2654 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2656 wxPanelItemEventHandler
,
2663 XtOverrideTranslations ((Widget
) mainWidget
,
2664 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2665 XtFree ((char *) ptr
);
2668 // Some widgets have a parent form widget, e.g. wxRadioBox
2671 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2675 XtOverrideTranslations ((Widget
) formWidget
,
2676 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2677 XtFree ((char *) ptr
);
2684 SetSize (x
, y
, width
, height
);
2689 // Remove event handler, remove from hash table
2690 bool wxWindow::DetachWidget(WXWidget widget
)
2692 if (CanAddEventHandler())
2694 XtRemoveEventHandler((Widget
) widget
,
2695 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2697 wxPanelItemEventHandler
,
2701 wxDeleteWindowFromTable((Widget
) widget
);
2705 void wxPanelItemEventHandler (Widget wid
,
2706 XtPointer client_data
,
2708 Boolean
*continueToDispatch
)
2710 // Widget can be a label or the actual widget.
2712 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2715 wxMouseEvent
wxevent(0);
2716 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2718 window
->GetEventHandler()->ProcessEvent(wxevent
);
2721 // TODO: probably the key to allowing default behaviour
2723 // Say we set a m_doDefault flag to FALSE at the start of this
2724 // function. Then in e.g. wxWindow::OnMouseEvent we can
2725 // call Default() which sets this flag to TRUE, indicating
2726 // that default processing can happen. Thus, behaviour can appear
2727 // to be overridden just by adding an event handler and not calling
2728 // wxWindow::OnWhatever.
2729 // ALSO, maybe we can use this instead of the current way of handling
2730 // drawing area events, to simplify things.
2731 *continueToDispatch
= True
;
2734 void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2735 XmScaleCallbackStruct
*cbs
)
2737 Widget scrolledWindow
= XtParent (scrollbar
);
2738 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2739 int orientation
= (int) clientData
;
2741 wxEventType eventType
= wxEVT_NULL
;
2742 switch (cbs
->reason
)
2744 case XmCR_INCREMENT
:
2746 eventType
= wxEVT_SCROLL_LINEDOWN
;
2749 case XmCR_DECREMENT
:
2751 eventType
= wxEVT_SCROLL_LINEUP
;
2756 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2759 case XmCR_VALUE_CHANGED
:
2761 // TODO: Should this be intercepted too, or will it cause
2762 // duplicate events?
2763 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2766 case XmCR_PAGE_INCREMENT
:
2768 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2771 case XmCR_PAGE_DECREMENT
:
2773 eventType
= wxEVT_SCROLL_PAGEUP
;
2778 eventType
= wxEVT_SCROLL_TOP
;
2781 case XmCR_TO_BOTTOM
:
2783 eventType
= wxEVT_SCROLL_BOTTOM
;
2788 // Should never get here
2789 wxFAIL_MSG("Unknown scroll event.");
2794 wxScrollEvent
event(eventType
, win
->GetId());
2795 event
.SetEventObject(win
);
2796 event
.SetPosition(cbs
->value
);
2797 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2799 win
->GetEventHandler()->ProcessEvent(event
);
2802 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2804 switch (xevent
->xany
.type
)
2812 wxEventType eventType
= wxEVT_NULL
;
2814 if (xevent
->xany
.type
== LeaveNotify
)
2816 win
->m_button1Pressed
= FALSE
;
2817 win
->m_button2Pressed
= FALSE
;
2818 win
->m_button3Pressed
= FALSE
;
2821 else if (xevent
->xany
.type
== MotionNotify
)
2823 eventType
= wxEVT_MOTION
;
2825 else if (xevent
->xany
.type
== ButtonPress
)
2827 if (xevent
->xbutton
.button
== Button1
)
2829 eventType
= wxEVT_LEFT_DOWN
;
2830 win
->m_button1Pressed
= TRUE
;
2832 else if (xevent
->xbutton
.button
== Button2
)
2834 eventType
= wxEVT_MIDDLE_DOWN
;
2835 win
->m_button2Pressed
= TRUE
;
2837 else if (xevent
->xbutton
.button
== Button3
)
2839 eventType
= wxEVT_RIGHT_DOWN
;
2840 win
->m_button3Pressed
= TRUE
;
2843 else if (xevent
->xany
.type
== ButtonRelease
)
2845 if (xevent
->xbutton
.button
== Button1
)
2847 eventType
= wxEVT_LEFT_UP
;
2848 win
->m_button1Pressed
= FALSE
;
2850 else if (xevent
->xbutton
.button
== Button2
)
2852 eventType
= wxEVT_MIDDLE_UP
;
2853 win
->m_button2Pressed
= FALSE
;
2855 else if (xevent
->xbutton
.button
== Button3
)
2857 eventType
= wxEVT_RIGHT_UP
;
2858 win
->m_button3Pressed
= FALSE
;
2864 wxevent
.m_eventHandle
= (char *)xevent
;
2865 wxevent
.SetEventType(eventType
);
2868 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2871 win
->GetPosition(&x2
, &y2
);
2873 // The button x/y must be translated to wxWindows
2874 // window space - the widget might be a label or button,
2878 if (widget
!= (Widget
)win
->GetMainWidget())
2884 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2885 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2887 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2888 || (event_left_is_down (xevent
)
2889 && (eventType
!= wxEVT_LEFT_UP
)));
2890 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2891 || (event_middle_is_down (xevent
)
2892 && (eventType
!= wxEVT_MIDDLE_UP
)));
2893 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2894 || (event_right_is_down (xevent
)
2895 && (eventType
!= wxEVT_RIGHT_UP
)));
2897 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2898 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2905 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2907 switch (xevent
->xany
.type
)
2914 // XComposeStatus compose;
2915 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2916 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2917 int id
= wxCharCodeXToWX (keySym
);
2919 if (xevent
->xkey
.state
& ShiftMask
)
2920 wxevent
.m_shiftDown
= TRUE
;
2921 if (xevent
->xkey
.state
& ControlMask
)
2922 wxevent
.m_controlDown
= TRUE
;
2923 if (xevent
->xkey
.state
& Mod3Mask
)
2924 wxevent
.m_altDown
= TRUE
;
2925 if (xevent
->xkey
.state
& Mod1Mask
)
2926 wxevent
.m_metaDown
= TRUE
;
2927 wxevent
.SetEventObject(win
);
2928 wxevent
.m_keyCode
= id
;
2929 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2931 wxevent
.m_x
= xevent
->xbutton
.x
;
2932 wxevent
.m_y
= xevent
->xbutton
.y
;
2946 // TODO From wxWin 1.68. What does it do exactly?
2947 #define YAllocColor XAllocColor
2949 XColor itemColors
[5];
2950 int wxComputeColors (Display
*display
, wxColour
* back
, wxColour
* fore
)
2953 static XmColorProc colorProc
;
2955 result
= wxNO_COLORS
;
2959 itemColors
[0].red
= (((long) back
->Red ()) << 8);
2960 itemColors
[0].green
= (((long) back
->Green ()) << 8);
2961 itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2962 itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2963 if (colorProc
== (XmColorProc
) NULL
)
2965 // Get a ptr to the actual function
2966 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2967 // And set it back to motif.
2968 XmSetColorCalculation (colorProc
);
2970 (*colorProc
) (&itemColors
[wxBACK_INDEX
],
2971 &itemColors
[wxFORE_INDEX
],
2972 &itemColors
[wxSELE_INDEX
],
2973 &itemColors
[wxTOPS_INDEX
],
2974 &itemColors
[wxBOTS_INDEX
]);
2975 result
= wxBACK_COLORS
;
2979 itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2980 itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2981 itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2982 itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2983 if (result
== wxNO_COLORS
)
2984 result
= wxFORE_COLORS
;
2987 Display
*dpy
= display
;
2988 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2992 /* 5 Colours to allocate */
2993 for (int i
= 0; i
< 5; i
++)
2994 if (!YAllocColor (dpy
, cmap
, &itemColors
[i
]))
2995 result
= wxNO_COLORS
;
2999 /* Only 1 colour to allocate */
3000 if (!YAllocColor (dpy
, cmap
, &itemColors
[wxFORE_INDEX
]))
3001 result
= wxNO_COLORS
;
3008 void wxWindow::ChangeColour(WXWidget widget
)
3014 // TODO: how to determine whether we can change this item's colours?
3015 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
3017 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
3020 change
= wxComputeColors (XtDisplay((Widget
)widget
), panel
->GetBackgroundColour(),
3021 panel
->GetLabelColour());
3022 if (change
== wxBACK_COLORS
)
3023 XtVaSetValues ((Widget
) widget
,
3024 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
3025 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
3026 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
3027 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3029 else if (change
== wxFORE_COLORS
)
3030 XtVaSetValues (formWidget
,
3031 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3034 change
= wxComputeColors (XtDisplay((Widget
)formWidget
), GetBackgroundColour(), GetLabelColour());
3035 if (change
== wxBACK_COLORS
)
3036 XtVaSetValues (labelWidget
,
3037 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
3038 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
3039 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
3040 XmNarmColor
, itemColors
[wxSELE_INDEX
].pixel
,
3041 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3043 else if (change
== wxFORE_COLORS
)
3044 XtVaSetValues (labelWidget
,
3045 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3050 void wxWindow::ChangeFont(WXWidget widget
)
3052 if (widget
&& GetFont() && GetFont()->Ok())
3054 XmFontList fontList
= (XmFontList
) GetFont()->GetFontList(1.0, GetXDisplay());
3056 XtVaSetValues ((Widget
) widget
,
3057 XmNfontList
, fontList
,