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 // Note that this causes the widget to be resized back
1271 // to its original size! How can we stop that?
1273 Widget w = (Widget) GetLabelWidget(); // Usually the main widget
1274 if (w && m_windowFont.Ok())
1277 XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)),
1283 void wxWindow::OnChar(wxKeyEvent
& event
)
1285 if ( event
.KeyCode() == WXK_TAB
) {
1286 // propagate the TABs to the parent - it's up to it to decide what
1288 if ( GetParent() ) {
1289 if ( GetParent()->ProcessEvent(event
) )
1295 void wxWindow::OnPaint(wxPaintEvent
& event
)
1300 bool wxWindow::IsEnabled() const
1302 // TODO. Is this right?
1303 // return XtGetSensitive((Widget) GetMainWidget());
1307 // Dialog support: override these and call
1308 // base class members to add functionality
1309 // that can't be done using validators.
1310 // NOTE: these functions assume that controls
1311 // are direct children of this window, not grandchildren
1312 // or other levels of descendant.
1314 // Transfer values to controls. If returns FALSE,
1315 // it's an application error (pops up a dialog)
1316 bool wxWindow::TransferDataToWindow()
1318 wxNode
*node
= GetChildren()->First();
1321 wxWindow
*child
= (wxWindow
*)node
->Data();
1322 if ( child
->GetValidator() &&
1323 !child
->GetValidator()->TransferToWindow() )
1325 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1329 node
= node
->Next();
1334 // Transfer values from controls. If returns FALSE,
1335 // validation failed: don't quit
1336 bool wxWindow::TransferDataFromWindow()
1338 wxNode
*node
= GetChildren()->First();
1341 wxWindow
*child
= (wxWindow
*)node
->Data();
1342 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1347 node
= node
->Next();
1352 bool wxWindow::Validate()
1354 wxNode
*node
= GetChildren()->First();
1357 wxWindow
*child
= (wxWindow
*)node
->Data();
1358 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1363 node
= node
->Next();
1368 // Get the window with the focus
1369 wxWindow
*wxWindow::FindFocus()
1375 void wxWindow::AddChild(wxWindow
*child
)
1377 GetChildren()->Append(child
);
1378 child
->m_windowParent
= this;
1381 void wxWindow::RemoveChild(wxWindow
*child
)
1384 GetChildren()->DeleteObject(child
);
1385 child
->m_windowParent
= NULL
;
1388 void wxWindow::DestroyChildren()
1390 if (GetChildren()) {
1392 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1394 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1396 if ( GetChildren()->Member(child
) )
1403 void wxWindow::MakeModal(bool modal
)
1405 // Disable all other windows
1406 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1408 wxNode
*node
= wxTopLevelWindows
.First();
1411 wxWindow
*win
= (wxWindow
*)node
->Data();
1413 win
->Enable(!modal
);
1415 node
= node
->Next();
1420 // If nothing defined for this, try the parent.
1421 // E.g. we may be a button loaded from a resource, with no callback function
1423 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1425 if (GetEventHandler()->ProcessEvent(event
) )
1428 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1431 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1435 UnsetConstraints(m_constraints
);
1436 delete m_constraints
;
1441 // Make sure other windows know they're part of a 'meaningful relationship'
1442 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1443 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1444 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1445 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1446 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1447 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1448 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1449 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1450 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1451 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1452 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1453 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1454 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1455 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1456 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1457 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1461 // This removes any dangling pointers to this window
1462 // in other windows' constraintsInvolvedIn lists.
1463 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1467 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1468 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1469 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1470 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1471 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1472 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1473 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1474 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1475 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1476 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1477 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1478 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1479 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1480 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1481 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1482 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1486 // Back-pointer to other windows we're involved with, so if we delete
1487 // this window, we must delete any constraints we're involved with.
1488 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1490 if (!m_constraintsInvolvedIn
)
1491 m_constraintsInvolvedIn
= new wxList
;
1492 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1493 m_constraintsInvolvedIn
->Append(otherWin
);
1496 // REMOVE back-pointer to other windows we're involved with.
1497 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1499 if (m_constraintsInvolvedIn
)
1500 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1503 // Reset any constraints that mention this window
1504 void wxWindow::DeleteRelatedConstraints()
1506 if (m_constraintsInvolvedIn
)
1508 wxNode
*node
= m_constraintsInvolvedIn
->First();
1511 wxWindow
*win
= (wxWindow
*)node
->Data();
1512 wxNode
*next
= node
->Next();
1513 wxLayoutConstraints
*constr
= win
->GetConstraints();
1515 // Reset any constraints involving this window
1518 constr
->left
.ResetIfWin((wxWindow
*)this);
1519 constr
->top
.ResetIfWin((wxWindow
*)this);
1520 constr
->right
.ResetIfWin((wxWindow
*)this);
1521 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1522 constr
->width
.ResetIfWin((wxWindow
*)this);
1523 constr
->height
.ResetIfWin((wxWindow
*)this);
1524 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1525 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1530 delete m_constraintsInvolvedIn
;
1531 m_constraintsInvolvedIn
= NULL
;
1535 void wxWindow::SetSizer(wxSizer
*sizer
)
1537 m_windowSizer
= sizer
;
1539 sizer
->SetSizerParent((wxWindow
*)this);
1546 bool wxWindow::Layout()
1548 if (GetConstraints())
1551 GetClientSize(&w
, &h
);
1552 GetConstraints()->width
.SetValue(w
);
1553 GetConstraints()->height
.SetValue(h
);
1556 // If top level (one sizer), evaluate the sizer's constraints.
1560 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1561 GetSizer()->LayoutPhase1(&noChanges
);
1562 GetSizer()->LayoutPhase2(&noChanges
);
1563 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1568 // Otherwise, evaluate child constraints
1569 ResetConstraints(); // Mark all constraints as unevaluated
1570 DoPhase(1); // Just one phase need if no sizers involved
1572 SetConstraintSizes(); // Recursively set the real window sizes
1578 // Do a phase of evaluating constraints:
1579 // the default behaviour. wxSizers may do a similar
1580 // thing, but also impose their own 'constraints'
1581 // and order the evaluation differently.
1582 bool wxWindow::LayoutPhase1(int *noChanges
)
1584 wxLayoutConstraints
*constr
= GetConstraints();
1587 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1593 bool wxWindow::LayoutPhase2(int *noChanges
)
1603 // Do a phase of evaluating child constraints
1604 bool wxWindow::DoPhase(int phase
)
1606 int noIterations
= 0;
1607 int maxIterations
= 500;
1611 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1615 wxNode
*node
= GetChildren()->First();
1618 wxWindow
*child
= (wxWindow
*)node
->Data();
1619 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1621 wxLayoutConstraints
*constr
= child
->GetConstraints();
1624 if (succeeded
.Member(child
))
1629 int tempNoChanges
= 0;
1630 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1631 noChanges
+= tempNoChanges
;
1634 succeeded
.Append(child
);
1639 node
= node
->Next();
1646 void wxWindow::ResetConstraints()
1648 wxLayoutConstraints
*constr
= GetConstraints();
1651 constr
->left
.SetDone(FALSE
);
1652 constr
->top
.SetDone(FALSE
);
1653 constr
->right
.SetDone(FALSE
);
1654 constr
->bottom
.SetDone(FALSE
);
1655 constr
->width
.SetDone(FALSE
);
1656 constr
->height
.SetDone(FALSE
);
1657 constr
->centreX
.SetDone(FALSE
);
1658 constr
->centreY
.SetDone(FALSE
);
1660 wxNode
*node
= GetChildren()->First();
1663 wxWindow
*win
= (wxWindow
*)node
->Data();
1664 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1665 win
->ResetConstraints();
1666 node
= node
->Next();
1670 // Need to distinguish between setting the 'fake' size for
1671 // windows and sizers, and setting the real values.
1672 void wxWindow::SetConstraintSizes(bool recurse
)
1674 wxLayoutConstraints
*constr
= GetConstraints();
1675 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1676 constr
->width
.GetDone() && constr
->height
.GetDone())
1678 int x
= constr
->left
.GetValue();
1679 int y
= constr
->top
.GetValue();
1680 int w
= constr
->width
.GetValue();
1681 int h
= constr
->height
.GetValue();
1683 // If we don't want to resize this window, just move it...
1684 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1685 (constr
->height
.GetRelationship() != wxAsIs
))
1687 // Calls Layout() recursively. AAAGH. How can we stop that.
1688 // Simply take Layout() out of non-top level OnSizes.
1689 SizerSetSize(x
, y
, w
, h
);
1698 char *windowClass
= this->GetClassInfo()->GetClassName();
1701 if (GetName() == "")
1702 winName
= "unnamed";
1704 winName
= GetName();
1705 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1706 if (!constr
->left
.GetDone())
1707 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1708 if (!constr
->right
.GetDone())
1709 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1710 if (!constr
->width
.GetDone())
1711 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1712 if (!constr
->height
.GetDone())
1713 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1714 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1719 wxNode
*node
= GetChildren()->First();
1722 wxWindow
*win
= (wxWindow
*)node
->Data();
1723 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1724 win
->SetConstraintSizes();
1725 node
= node
->Next();
1730 // This assumes that all sizers are 'on' the same
1731 // window, i.e. the parent of this window.
1732 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1734 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1735 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1739 m_sizerParent
->GetPosition(&xp
, &yp
);
1740 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1745 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1749 TransformSizerToActual(&xx
, &yy
);
1750 SetSize(xx
, yy
, w
, h
);
1753 void wxWindow::SizerMove(int x
, int y
)
1757 TransformSizerToActual(&xx
, &yy
);
1761 // Only set the size/position of the constraint (if any)
1762 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1764 wxLayoutConstraints
*constr
= GetConstraints();
1769 constr
->left
.SetValue(x
);
1770 constr
->left
.SetDone(TRUE
);
1774 constr
->top
.SetValue(y
);
1775 constr
->top
.SetDone(TRUE
);
1779 constr
->width
.SetValue(w
);
1780 constr
->width
.SetDone(TRUE
);
1784 constr
->height
.SetValue(h
);
1785 constr
->height
.SetDone(TRUE
);
1790 void wxWindow::MoveConstraint(int x
, int y
)
1792 wxLayoutConstraints
*constr
= GetConstraints();
1797 constr
->left
.SetValue(x
);
1798 constr
->left
.SetDone(TRUE
);
1802 constr
->top
.SetValue(y
);
1803 constr
->top
.SetDone(TRUE
);
1808 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1810 wxLayoutConstraints
*constr
= GetConstraints();
1813 *w
= constr
->width
.GetValue();
1814 *h
= constr
->height
.GetValue();
1820 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1822 wxLayoutConstraints
*constr
= GetConstraints();
1825 *w
= constr
->width
.GetValue();
1826 *h
= constr
->height
.GetValue();
1829 GetClientSize(w
, h
);
1832 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1834 wxLayoutConstraints
*constr
= GetConstraints();
1837 *x
= constr
->left
.GetValue();
1838 *y
= constr
->top
.GetValue();
1844 bool wxWindow::Close(bool force
)
1846 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1847 event
.SetEventObject(this);
1848 event
.SetForce(force
);
1850 return GetEventHandler()->ProcessEvent(event
);
1853 wxObject
* wxWindow::GetChild(int number
) const
1855 // Return a pointer to the Nth object in the window
1858 wxNode
*node
= GetChildren()->First();
1861 node
= node
->Next() ;
1864 wxObject
*obj
= (wxObject
*)node
->Data();
1871 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1873 // Obsolete function
1876 void wxWindow::Clear()
1878 wxClientDC
dc(this);
1879 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1880 dc
.SetBackground(brush
);
1884 // Fits the panel around the items
1885 void wxWindow::Fit()
1889 wxNode
*node
= GetChildren()->First();
1892 wxWindow
*win
= (wxWindow
*)node
->Data();
1894 win
->GetPosition(&wx
, &wy
);
1895 win
->GetSize(&ww
, &wh
);
1896 if ( wx
+ ww
> maxX
)
1898 if ( wy
+ wh
> maxY
)
1901 node
= node
->Next();
1903 SetClientSize(maxX
+ 5, maxY
+ 5);
1906 void wxWindow::SetValidator(const wxValidator
& validator
)
1908 if ( m_windowValidator
)
1909 delete m_windowValidator
;
1910 m_windowValidator
= validator
.Clone();
1912 if ( m_windowValidator
)
1913 m_windowValidator
->SetWindow(this) ;
1916 // Find a window by id or name
1917 wxWindow
*wxWindow::FindWindow(long id
)
1922 wxNode
*node
= GetChildren()->First();
1925 wxWindow
*child
= (wxWindow
*)node
->Data();
1926 wxWindow
*found
= child
->FindWindow(id
);
1929 node
= node
->Next();
1934 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1936 if ( GetName() == name
)
1939 wxNode
*node
= GetChildren()->First();
1942 wxWindow
*child
= (wxWindow
*)node
->Data();
1943 wxWindow
*found
= child
->FindWindow(name
);
1946 node
= node
->Next();
1951 void wxWindow::OnIdle(wxIdleEvent
& event
)
1953 /* TODO: you may need to do something like this
1954 * if your GUI doesn't generate enter/leave events
1956 // Check if we need to send a LEAVE event
1957 if (m_mouseInWindow)
1960 ::GetCursorPos(&pt);
1961 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1963 // Generate a LEAVE event
1964 m_mouseInWindow = FALSE;
1965 MSWOnMouseLeave(pt.x, pt.y, 0);
1970 // This calls the UI-update mechanism (querying windows for
1971 // menu/toolbar/control state information)
1975 // Raise the window to the top of the Z order
1976 void wxWindow::Raise()
1978 Window window
= XtWindow((Widget
) GetTopWidget());
1979 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1982 // Lower the window to the bottom of the Z order
1983 void wxWindow::Lower()
1985 Window window
= XtWindow((Widget
) GetTopWidget());
1986 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1989 bool wxWindow::AcceptsFocus() const
1991 return IsShown() && IsEnabled();
1994 // Update region access
1995 wxRegion
wxWindow::GetUpdateRegion() const
1997 return m_updateRegion
;
2000 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2002 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2005 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2007 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2010 bool wxWindow::IsExposed(const wxRect
& rect
) const
2012 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2016 * Allocates control IDs
2019 int wxWindow::NewControlId()
2021 static int s_controlId
= 0;
2026 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2028 m_acceleratorTable
= accel
;
2031 // All widgets should have this as their resize proc.
2032 // OnSize sent to wxWindow via client data.
2033 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2035 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2039 if (win
->PreResize())
2042 win
->GetSize(&width
, &height
);
2043 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2044 sizeEvent
.SetEventObject(win
);
2045 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2049 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2051 wxWindow
*oldItem
= NULL
;
2053 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2055 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2058 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2061 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2066 wxWidgetHashTable
->Put ((long) w
, win
);
2070 wxWindow
*wxGetWindowFromTable(Widget w
)
2072 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2075 void wxDeleteWindowFromTable(Widget w
)
2077 wxWidgetHashTable
->Delete((long)w
);
2080 // Get the underlying X window and display
2081 WXWindow
wxWindow::GetXWindow() const
2083 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2086 WXDisplay
*wxWindow::GetXDisplay() const
2088 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2091 WXWidget
wxWindow::GetMainWidget() const
2094 return m_drawingArea
;
2096 return m_mainWidget
;
2099 WXWidget
wxWindow::GetClientWidget() const
2101 if (m_drawingArea
!= (WXWidget
) 0)
2102 return m_drawingArea
;
2104 return GetMainWidget();
2107 WXWidget
wxWindow::GetTopWidget() const
2109 return GetMainWidget();
2112 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2113 XmDrawingAreaCallbackStruct
* cbs
)
2115 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2118 XEvent
* event
= cbs
->event
;
2119 wxWindow
* canvas
= (wxWindow
*) clientData
;
2120 Display
* display
= (Display
*) canvas
->GetXDisplay();
2121 // GC gc = (GC) canvas->GetDC()->gc;
2123 switch (event
->type
)
2128 wxCanvasDC* canvasDC = canvas->GetDC();
2131 if (canvasDC->onpaint_reg)
2132 XDestroyRegion(canvasDC->onpaint_reg);
2133 canvasDC->onpaint_reg = XCreateRegion();
2138 int n
= canvas
->m_updateRects
.Number();
2139 XRectangle
* xrects
= new XRectangle
[n
];
2141 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
2143 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
2144 xrects
[i
].x
= rect
->x
;
2145 xrects
[i
].y
= rect
->y
;
2146 xrects
[i
].width
= rect
->width
;
2147 xrects
[i
].height
= rect
->height
;
2148 /* TODO (?) Actually ignore it I think.
2150 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
2151 canvasDC->onpaint_reg);
2154 /* TODO must clip the area being repainted. So we need a gc.
2155 * Alternatively, wxPaintDC must do the clipping
2156 * when it's created.
2157 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
2160 canvas
->DoPaint() ; // xrects, n);
2163 canvas
->m_updateRects
.Clear();
2168 XDestroyRegion(canvasDC->onpaint_reg);
2169 canvasDC->onpaint_reg = NULL;
2173 gc_val.clip_mask = None;
2174 XChangeGC(display, gc, GCClipMask, &gc_val);
2181 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2187 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2189 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2191 XmDrawingAreaCallbackStruct cbs
;
2194 //if (event->mode!=NotifyNormal)
2197 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2198 ((XCrossingEvent
&) ev
) = *event
;
2200 cbs
.reason
= XmCR_INPUT
;
2203 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2206 // Fix to make it work under Motif 1.0 (!)
2207 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2211 XmDrawingAreaCallbackStruct cbs
;
2214 //ev.xbutton = *event;
2215 ev
= *((XEvent
*) event
);
2216 cbs
.reason
= XmCR_INPUT
;
2219 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2223 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2225 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2231 if (cbs
->reason
!= XmCR_INPUT
)
2234 local_event
= *(cbs
->event
); // We must keep a copy!
2236 switch (local_event
.xany
.type
)
2244 wxEventType eventType
= wxEVT_NULL
;
2246 if (local_event
.xany
.type
== EnterNotify
)
2248 //if (local_event.xcrossing.mode!=NotifyNormal)
2249 // return ; // Ignore grab events
2250 eventType
= wxEVT_ENTER_WINDOW
;
2251 // canvas->GetEventHandler()->OnSetFocus();
2253 else if (local_event
.xany
.type
== LeaveNotify
)
2255 //if (local_event.xcrossing.mode!=NotifyNormal)
2256 // return ; // Ignore grab events
2257 eventType
= wxEVT_LEAVE_WINDOW
;
2258 // canvas->GetEventHandler()->OnKillFocus();
2260 else if (local_event
.xany
.type
== MotionNotify
)
2262 eventType
= wxEVT_MOTION
;
2263 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2266 Display
*dpy
= XtDisplay (drawingArea
);
2268 XQueryPointer (dpy
, XtWindow (drawingArea
),
2270 &local_event
.xmotion
.x_root
,
2271 &local_event
.xmotion
.y_root
,
2272 &local_event
.xmotion
.x
,
2273 &local_event
.xmotion
.y
,
2274 &local_event
.xmotion
.state
);
2281 else if (local_event
.xany
.type
== ButtonPress
)
2283 if (local_event
.xbutton
.button
== Button1
)
2285 eventType
= wxEVT_LEFT_DOWN
;
2286 canvas
->m_button1Pressed
= TRUE
;
2288 else if (local_event
.xbutton
.button
== Button2
)
2290 eventType
= wxEVT_MIDDLE_DOWN
;
2291 canvas
->m_button2Pressed
= TRUE
;
2293 else if (local_event
.xbutton
.button
== Button3
)
2295 eventType
= wxEVT_RIGHT_DOWN
;
2296 canvas
->m_button3Pressed
= TRUE
;
2299 else if (local_event
.xany
.type
== ButtonRelease
)
2301 if (local_event
.xbutton
.button
== Button1
)
2303 eventType
= wxEVT_LEFT_UP
;
2304 canvas
->m_button1Pressed
= FALSE
;
2306 else if (local_event
.xbutton
.button
== Button2
)
2308 eventType
= wxEVT_MIDDLE_UP
;
2309 canvas
->m_button2Pressed
= FALSE
;
2311 else if (local_event
.xbutton
.button
== Button3
)
2313 eventType
= wxEVT_RIGHT_UP
;
2314 canvas
->m_button3Pressed
= FALSE
;
2318 wxMouseEvent
wxevent (eventType
);
2319 wxevent
.m_eventHandle
= (char *) &local_event
;
2321 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2322 || (event_left_is_down (&local_event
)
2323 && (eventType
!= wxEVT_LEFT_UP
)));
2324 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2325 || (event_middle_is_down (&local_event
)
2326 && (eventType
!= wxEVT_MIDDLE_UP
)));
2327 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2328 || (event_right_is_down (&local_event
)
2329 && (eventType
!= wxEVT_RIGHT_UP
)));
2331 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2332 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2333 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2334 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2335 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2337 // Now check if we need to translate this event into a double click
2338 if (TRUE
) // canvas->doubleClickAllowed)
2340 if (wxevent
.ButtonDown())
2342 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2344 // get button and time-stamp
2346 if (wxevent
.LeftDown()) button
= 1;
2347 else if (wxevent
.MiddleDown()) button
= 2;
2348 else if (wxevent
.RightDown()) button
= 3;
2349 long ts
= wxevent
.GetTimestamp();
2350 // check, if single or double click
2351 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2354 canvas
->m_lastButton
= 0;
2355 switch ( eventType
)
2357 case wxEVT_LEFT_DOWN
:
2358 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2360 case wxEVT_MIDDLE_DOWN
:
2361 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2363 case wxEVT_RIGHT_DOWN
:
2364 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2374 // not fast enough or different button
2375 canvas
->m_lastTS
= ts
;
2376 canvas
->m_lastButton
= button
;
2381 wxevent
.SetId(canvas
->GetId());
2382 wxevent
.SetEventObject(canvas
);
2383 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2385 if (eventType == wxEVT_ENTER_WINDOW ||
2386 eventType == wxEVT_LEAVE_WINDOW ||
2387 eventType == wxEVT_MOTION
2396 // XComposeStatus compose;
2397 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2398 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2399 int id
= wxCharCodeXToWX (keySym
);
2401 wxKeyEvent
event (wxEVT_CHAR
);
2403 if (local_event
.xkey
.state
& ShiftMask
)
2404 event
.m_shiftDown
= TRUE
;
2405 if (local_event
.xkey
.state
& ControlMask
)
2406 event
.m_controlDown
= TRUE
;
2407 if (local_event
.xkey
.state
& Mod3Mask
)
2408 event
.m_altDown
= TRUE
;
2409 if (local_event
.xkey
.state
& Mod1Mask
)
2410 event
.m_metaDown
= TRUE
;
2411 event
.SetEventObject(canvas
);
2412 event
.m_keyCode
= id
;
2413 event
.SetTimestamp(local_event
.xkey
.time
);
2417 // Implement wxFrame::OnCharHook by checking ancestor.
2418 wxWindow
*parent
= canvas
->GetParent();
2419 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2420 parent
= parent
->GetParent();
2424 event
.SetEventType(wxEVT_CHAR_HOOK
);
2425 if (parent
->GetEventHandler()->ProcessEvent(event
))
2427 event
.SetEventType(wxEVT_CHAR
);
2430 canvas
->GetEventHandler()->ProcessEvent (event
);
2436 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2438 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2439 event
.SetEventObject(canvas
);
2440 canvas
->GetEventHandler()->ProcessEvent(event
);
2446 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2448 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2449 event
.SetEventObject(canvas
);
2450 canvas
->GetEventHandler()->ProcessEvent(event
);
2459 void wxWindow::DoPaint()
2461 //TODO : make a temporary gc so we can do the XCopyArea below
2462 if (0) // m_backingPixmap)
2465 Widget drawingArea = (Widget) m_drawingArea;
2466 // int orig = GetDC()->GetLogicalFunction();
2467 // GetDC()->SetLogicalFunction (wxCOPY);
2469 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2470 // should be able to calculate them.
2471 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2472 m_pixmapOffsetX, m_pixmapOffsetY,
2473 m_pixmapWidth, m_pixmapHeight,
2476 // GetDC()->SetLogicalFunction (orig);
2481 wxPaintEvent
event(GetId());
2482 event
.SetEventObject(this);
2483 GetEventHandler()->ProcessEvent(event
);
2487 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2488 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2490 Widget drawingArea
= (Widget
) m_drawingArea
;
2491 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2494 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2495 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2497 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2499 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2503 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2505 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2513 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2514 short thick
, margin
;
2515 XtVaGetValues ((Widget
) m_borderWidget
,
2516 XmNshadowThickness
, &thick
,
2517 XmNmarginWidth
, &margin
,
2519 w
-= 2 * (thick
+ margin
);
2522 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2526 XtVaGetValues ((Widget
) m_scrolledWindow
,
2527 XmNspacing
, &spacing
,
2528 XmNverticalScrollBar
, &sbar
,
2532 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2536 w
-= (spacing
+ wsbar
);
2538 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2544 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2545 short thick
, margin
;
2546 XtVaGetValues ((Widget
) m_borderWidget
,
2547 XmNshadowThickness
, &thick
,
2548 XmNmarginHeight
, &margin
,
2550 h
-= 2 * (thick
+ margin
);
2553 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2557 XtVaGetValues ((Widget
) m_scrolledWindow
,
2558 XmNspacing
, &spacing
,
2559 XmNhorizontalScrollBar
, &sbar
,
2563 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2567 h
-= (spacing
+ wsbar
);
2569 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2572 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2573 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2576 GetClientSize (&ww
, &hh
);
2577 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2578 sizeEvent
.SetEventObject(this);
2580 GetEventHandler()->ProcessEvent(sizeEvent
);
2583 void wxWindow::CanvasSetClientSize (int w
, int h
)
2585 Widget drawingArea
= (Widget
) m_drawingArea
;
2587 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2590 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2592 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2593 /* TODO: is this necessary?
2594 allowRepainting = FALSE;
2596 XSync (XtDisplay (drawingArea), FALSE);
2598 while (XtAppPending (wxTheApp->appContext))
2600 XFlush (XtDisplay (drawingArea));
2601 XtAppNextEvent (wxTheApp->appContext, &event);
2602 XtDispatchEvent (&event);
2606 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2609 allowRepainting = TRUE;
2613 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2614 sizeEvent
.SetEventObject(this);
2616 GetEventHandler()->ProcessEvent(sizeEvent
);
2619 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2621 // Must return the same thing that was set via SetClientSize
2623 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2628 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2631 if ((Widget
) m_borderWidget
)
2632 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2633 else if ((Widget
) m_scrolledWindow
)
2634 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2636 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2642 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2645 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2650 // Add to hash table, add event handler
2651 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2652 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2654 wxAddWindowToTable((Widget
) mainWidget
, this);
2655 if (CanAddEventHandler())
2657 XtAddEventHandler((Widget
) mainWidget
,
2658 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2660 wxPanelItemEventHandler
,
2667 XtOverrideTranslations ((Widget
) mainWidget
,
2668 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2669 XtFree ((char *) ptr
);
2672 // Some widgets have a parent form widget, e.g. wxRadioBox
2675 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2679 XtOverrideTranslations ((Widget
) formWidget
,
2680 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2681 XtFree ((char *) ptr
);
2688 SetSize (x
, y
, width
, height
);
2693 // Remove event handler, remove from hash table
2694 bool wxWindow::DetachWidget(WXWidget widget
)
2696 if (CanAddEventHandler())
2698 XtRemoveEventHandler((Widget
) widget
,
2699 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2701 wxPanelItemEventHandler
,
2705 wxDeleteWindowFromTable((Widget
) widget
);
2709 void wxPanelItemEventHandler (Widget wid
,
2710 XtPointer client_data
,
2712 Boolean
*continueToDispatch
)
2714 // Widget can be a label or the actual widget.
2716 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2719 wxMouseEvent
wxevent(0);
2720 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2722 window
->GetEventHandler()->ProcessEvent(wxevent
);
2725 // TODO: probably the key to allowing default behaviour
2727 // Say we set a m_doDefault flag to FALSE at the start of this
2728 // function. Then in e.g. wxWindow::OnMouseEvent we can
2729 // call Default() which sets this flag to TRUE, indicating
2730 // that default processing can happen. Thus, behaviour can appear
2731 // to be overridden just by adding an event handler and not calling
2732 // wxWindow::OnWhatever.
2733 // ALSO, maybe we can use this instead of the current way of handling
2734 // drawing area events, to simplify things.
2735 *continueToDispatch
= True
;
2738 void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2739 XmScaleCallbackStruct
*cbs
)
2741 Widget scrolledWindow
= XtParent (scrollbar
);
2742 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2743 int orientation
= (int) clientData
;
2745 wxEventType eventType
= wxEVT_NULL
;
2746 switch (cbs
->reason
)
2748 case XmCR_INCREMENT
:
2750 eventType
= wxEVT_SCROLL_LINEDOWN
;
2753 case XmCR_DECREMENT
:
2755 eventType
= wxEVT_SCROLL_LINEUP
;
2760 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2763 case XmCR_VALUE_CHANGED
:
2765 // TODO: Should this be intercepted too, or will it cause
2766 // duplicate events?
2767 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2770 case XmCR_PAGE_INCREMENT
:
2772 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2775 case XmCR_PAGE_DECREMENT
:
2777 eventType
= wxEVT_SCROLL_PAGEUP
;
2782 eventType
= wxEVT_SCROLL_TOP
;
2785 case XmCR_TO_BOTTOM
:
2787 eventType
= wxEVT_SCROLL_BOTTOM
;
2792 // Should never get here
2793 wxFAIL_MSG("Unknown scroll event.");
2798 wxScrollEvent
event(eventType
, win
->GetId());
2799 event
.SetEventObject(win
);
2800 event
.SetPosition(cbs
->value
);
2801 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2803 win
->GetEventHandler()->ProcessEvent(event
);
2806 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2808 switch (xevent
->xany
.type
)
2816 wxEventType eventType
= wxEVT_NULL
;
2818 if (xevent
->xany
.type
== LeaveNotify
)
2820 win
->m_button1Pressed
= FALSE
;
2821 win
->m_button2Pressed
= FALSE
;
2822 win
->m_button3Pressed
= FALSE
;
2825 else if (xevent
->xany
.type
== MotionNotify
)
2827 eventType
= wxEVT_MOTION
;
2829 else if (xevent
->xany
.type
== ButtonPress
)
2831 if (xevent
->xbutton
.button
== Button1
)
2833 eventType
= wxEVT_LEFT_DOWN
;
2834 win
->m_button1Pressed
= TRUE
;
2836 else if (xevent
->xbutton
.button
== Button2
)
2838 eventType
= wxEVT_MIDDLE_DOWN
;
2839 win
->m_button2Pressed
= TRUE
;
2841 else if (xevent
->xbutton
.button
== Button3
)
2843 eventType
= wxEVT_RIGHT_DOWN
;
2844 win
->m_button3Pressed
= TRUE
;
2847 else if (xevent
->xany
.type
== ButtonRelease
)
2849 if (xevent
->xbutton
.button
== Button1
)
2851 eventType
= wxEVT_LEFT_UP
;
2852 win
->m_button1Pressed
= FALSE
;
2854 else if (xevent
->xbutton
.button
== Button2
)
2856 eventType
= wxEVT_MIDDLE_UP
;
2857 win
->m_button2Pressed
= FALSE
;
2859 else if (xevent
->xbutton
.button
== Button3
)
2861 eventType
= wxEVT_RIGHT_UP
;
2862 win
->m_button3Pressed
= FALSE
;
2868 wxevent
.m_eventHandle
= (char *)xevent
;
2869 wxevent
.SetEventType(eventType
);
2872 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2875 win
->GetPosition(&x2
, &y2
);
2877 // The button x/y must be translated to wxWindows
2878 // window space - the widget might be a label or button,
2882 if (widget
!= (Widget
)win
->GetMainWidget())
2888 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2889 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2891 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2892 || (event_left_is_down (xevent
)
2893 && (eventType
!= wxEVT_LEFT_UP
)));
2894 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2895 || (event_middle_is_down (xevent
)
2896 && (eventType
!= wxEVT_MIDDLE_UP
)));
2897 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2898 || (event_right_is_down (xevent
)
2899 && (eventType
!= wxEVT_RIGHT_UP
)));
2901 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2902 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2909 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2911 switch (xevent
->xany
.type
)
2918 // XComposeStatus compose;
2919 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2920 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2921 int id
= wxCharCodeXToWX (keySym
);
2923 if (xevent
->xkey
.state
& ShiftMask
)
2924 wxevent
.m_shiftDown
= TRUE
;
2925 if (xevent
->xkey
.state
& ControlMask
)
2926 wxevent
.m_controlDown
= TRUE
;
2927 if (xevent
->xkey
.state
& Mod3Mask
)
2928 wxevent
.m_altDown
= TRUE
;
2929 if (xevent
->xkey
.state
& Mod1Mask
)
2930 wxevent
.m_metaDown
= TRUE
;
2931 wxevent
.SetEventObject(win
);
2932 wxevent
.m_keyCode
= id
;
2933 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2935 wxevent
.m_x
= xevent
->xbutton
.x
;
2936 wxevent
.m_y
= xevent
->xbutton
.y
;
2950 // TODO From wxWin 1.68. What does it do exactly?
2951 #define YAllocColor XAllocColor
2953 XColor itemColors
[5];
2954 int wxComputeColors (Display
*display
, wxColour
* back
, wxColour
* fore
)
2957 static XmColorProc colorProc
;
2959 result
= wxNO_COLORS
;
2963 itemColors
[0].red
= (((long) back
->Red ()) << 8);
2964 itemColors
[0].green
= (((long) back
->Green ()) << 8);
2965 itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2966 itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2967 if (colorProc
== (XmColorProc
) NULL
)
2969 // Get a ptr to the actual function
2970 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2971 // And set it back to motif.
2972 XmSetColorCalculation (colorProc
);
2974 (*colorProc
) (&itemColors
[wxBACK_INDEX
],
2975 &itemColors
[wxFORE_INDEX
],
2976 &itemColors
[wxSELE_INDEX
],
2977 &itemColors
[wxTOPS_INDEX
],
2978 &itemColors
[wxBOTS_INDEX
]);
2979 result
= wxBACK_COLORS
;
2983 itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2984 itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2985 itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2986 itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2987 if (result
== wxNO_COLORS
)
2988 result
= wxFORE_COLORS
;
2991 Display
*dpy
= display
;
2992 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2996 /* 5 Colours to allocate */
2997 for (int i
= 0; i
< 5; i
++)
2998 if (!YAllocColor (dpy
, cmap
, &itemColors
[i
]))
2999 result
= wxNO_COLORS
;
3003 /* Only 1 colour to allocate */
3004 if (!YAllocColor (dpy
, cmap
, &itemColors
[wxFORE_INDEX
]))
3005 result
= wxNO_COLORS
;
3012 void wxWindow::ChangeColour(WXWidget widget
)
3018 // TODO: how to determine whether we can change this item's colours?
3019 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
3021 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
3024 change
= wxComputeColors (XtDisplay((Widget
)widget
), panel
->GetBackgroundColour(),
3025 panel
->GetLabelColour());
3026 if (change
== wxBACK_COLORS
)
3027 XtVaSetValues ((Widget
) widget
,
3028 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
3029 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
3030 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
3031 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3033 else if (change
== wxFORE_COLORS
)
3034 XtVaSetValues (formWidget
,
3035 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3038 change
= wxComputeColors (XtDisplay((Widget
)formWidget
), GetBackgroundColour(), GetLabelColour());
3039 if (change
== wxBACK_COLORS
)
3040 XtVaSetValues (labelWidget
,
3041 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
3042 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
3043 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
3044 XmNarmColor
, itemColors
[wxSELE_INDEX
].pixel
,
3045 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3047 else if (change
== wxFORE_COLORS
)
3048 XtVaSetValues (labelWidget
,
3049 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
3054 void wxWindow::ChangeFont(WXWidget widget
)
3057 if (widget && GetFont() && GetFont()->Ok())
3059 XmFontList fontList = (XmFontList) GetFont()->GetFontList(1.0, GetXDisplay());
3061 XtVaSetValues ((Widget) widget,
3062 XmNfontList, fontList,