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 // Without this, the cursor may not be restored properly
479 // (e.g. in splitter sample).
480 SetCursor(*wxSTANDARD_CURSOR
);
481 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
486 void wxWindow::SetFocus()
488 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
489 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
492 void wxWindow::Enable(bool enable
)
496 XtSetSensitive((Widget
) GetMainWidget(), enable
);
497 XmUpdateDisplay((Widget
) GetMainWidget());
501 void wxWindow::CaptureMouse()
507 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
509 m_winCaptured
= TRUE
;
512 void wxWindow::ReleaseMouse()
518 XtRemoveGrab((Widget
) GetMainWidget());
519 m_winCaptured
= FALSE
;
522 // Push/pop event handler (i.e. allow a chain of event handlers
524 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
526 handler
->SetNextHandler(GetEventHandler());
527 SetEventHandler(handler
);
530 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
532 if ( GetEventHandler() )
534 wxEvtHandler
*handlerA
= GetEventHandler();
535 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
536 handlerA
->SetNextHandler(NULL
);
537 SetEventHandler(handlerB
);
550 #if wxUSE_DRAG_AND_DROP
552 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
554 if ( m_pDropTarget
!= 0 ) {
555 delete m_pDropTarget
;
558 m_pDropTarget
= pDropTarget
;
559 if ( m_pDropTarget
!= 0 )
567 // Old style file-manager drag&drop
568 void wxWindow::DragAcceptFiles(bool accept
)
574 void wxWindow::GetSize(int *x
, int *y
) const
582 Widget widget
= (Widget
) GetTopWidget();
584 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
588 void wxWindow::GetPosition(int *x
, int *y
) const
592 CanvasGetPosition(x
, y
);
595 Widget widget
= (Widget
) GetTopWidget();
597 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
599 // We may be faking the client origin.
600 // So a window that's really at (0, 30) may appear
601 // (to wxWin apps) to be at (0, 0).
604 wxPoint
pt(GetParent()->GetClientAreaOrigin());
612 void wxWindow::ScreenToClient(int *x
, int *y
) const
614 Widget widget
= (Widget
) GetClientWidget();
615 Display
*display
= XtDisplay((Widget
) GetMainWidget());
616 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
617 Window thisWindow
= XtWindow(widget
);
622 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
625 void wxWindow::ClientToScreen(int *x
, int *y
) const
627 Widget widget
= (Widget
) GetClientWidget();
628 Display
*display
= XtDisplay(widget
);
629 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
630 Window thisWindow
= XtWindow(widget
);
635 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
638 void wxWindow::SetCursor(const wxCursor
& cursor
)
640 m_windowCursor
= cursor
;
641 if (m_windowCursor
.Ok())
643 WXDisplay
*dpy
= GetXDisplay();
644 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
646 Widget w
= (Widget
) GetMainWidget();
647 Window win
= XtWindow(w
);
648 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
653 // Get size *available for subwindows* i.e. excluding menu bar etc.
654 void wxWindow::GetClientSize(int *x
, int *y
) const
656 Widget widget
= (Widget
) GetClientWidget();
658 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
662 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
666 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
669 Widget widget
= (Widget
) GetTopWidget();
673 bool managed
= XtIsManaged( widget
);
675 XtUnmanageChild(widget
);
677 int xx
= x
; int yy
= y
;
678 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
680 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
681 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
682 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
683 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
685 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
687 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
690 XtManageChild(widget
);
692 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
693 sizeEvent
.SetEventObject(this);
695 GetEventHandler()->ProcessEvent(sizeEvent
);
698 void wxWindow::SetClientSize(int width
, int height
)
702 CanvasSetClientSize(width
, height
);
706 Widget widget
= (Widget
) GetTopWidget();
709 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
711 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
713 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
714 sizeEvent
.SetEventObject(this);
716 GetEventHandler()->ProcessEvent(sizeEvent
);
719 // For implementation purposes - sometimes decorations make the client area
721 wxPoint
wxWindow::GetClientAreaOrigin() const
723 return wxPoint(0, 0);
726 // Makes an adjustment to the window position (for example, a frame that has
727 // a toolbar that it manages itself).
728 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
730 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
732 wxPoint
pt(GetParent()->GetClientAreaOrigin());
733 x
+= pt
.x
; y
+= pt
.y
;
737 bool wxWindow::Show(bool show
)
741 if (m_borderWidget
|| m_scrolledWindow
)
743 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
747 XtMapWidget((Widget
) GetTopWidget());
752 if (m_borderWidget
|| m_scrolledWindow
)
754 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
758 XtUnmapWidget((Widget
) GetTopWidget());
763 Window xwin = (Window) GetXWindow();
764 Display *xdisp = (Display*) GetXDisplay();
766 XMapWindow(xdisp, xwin);
768 XUnmapWindow(xdisp, xwin);
776 bool wxWindow::IsShown() const
781 int wxWindow::GetCharHeight() const
783 if (!m_windowFont
.Ok())
786 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
788 int direction
, ascent
, descent
;
790 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
792 // return (overall.ascent + overall.descent);
793 return (ascent
+ descent
);
796 int wxWindow::GetCharWidth() const
798 if (!m_windowFont
.Ok())
801 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
803 int direction
, ascent
, descent
;
805 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
807 return overall
.width
;
810 /* Helper function for 16-bit fonts */
811 static int str16len(const char *s
)
815 while (s
[0] && s
[1]) {
823 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
824 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
826 wxFont
*fontToUse
= (wxFont
*)theFont
;
828 fontToUse
= (wxFont
*) & m_windowFont
;
830 if (!fontToUse
->Ok())
833 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
835 int direction
, ascent
, descent2
;
839 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
842 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
843 &ascent
, &descent2
, &overall
);
845 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
846 &ascent
, &descent2
, &overall
);
848 *x
= (overall
.width
);
849 *y
= (ascent
+ descent2
);
853 *externalLeading
= 0;
856 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
858 Display
*display
= XtDisplay((Widget
) GetMainWidget());
859 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
861 XExposeEvent dummyEvent
;
863 GetSize(&width
, &height
);
865 dummyEvent
.type
= Expose
;
866 dummyEvent
.display
= display
;
867 dummyEvent
.send_event
= True
;
868 dummyEvent
.window
= thisWindow
;
871 dummyEvent
.x
= rect
->x
;
872 dummyEvent
.y
= rect
->y
;
873 dummyEvent
.width
= rect
->width
;
874 dummyEvent
.height
= rect
->height
;
880 dummyEvent
.width
= width
;
881 dummyEvent
.height
= height
;
883 dummyEvent
.count
= 0;
888 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
889 dc
.SetBackground(backgroundBrush
);
893 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
896 // Responds to colour changes: passes event on to children.
897 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
899 wxNode
*node
= GetChildren()->First();
902 // Only propagate to non-top-level windows
903 wxWindow
*win
= (wxWindow
*)node
->Data();
904 if ( win
->GetParent() )
906 wxSysColourChangedEvent event2
;
907 event
.m_eventObject
= win
;
908 win
->GetEventHandler()->ProcessEvent(event2
);
915 // This can be called by the app (or wxWindows) to do default processing for the current
916 // event. Save message/event info in wxWindow so they can be used in this function.
917 long wxWindow::Default()
923 void wxWindow::InitDialog()
925 wxInitDialogEvent
event(GetId());
926 event
.SetEventObject( this );
927 GetEventHandler()->ProcessEvent(event
);
930 // Default init dialog behaviour is to transfer data to window
931 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
933 TransferDataToWindow();
936 // Caret manipulation
937 void wxWindow::CreateCaret(int w
, int h
)
941 m_caretEnabled
= TRUE
;
944 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
949 void wxWindow::ShowCaret(bool show
)
954 void wxWindow::DestroyCaret()
957 m_caretEnabled
= FALSE
;
960 void wxWindow::SetCaretPos(int x
, int y
)
965 void wxWindow::GetCaretPos(int *x
, int *y
) const
970 wxWindow
*wxGetActiveWindow()
976 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
983 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
986 wxFrame
*frame
= (wxFrame
*)this;
987 Widget widget
= (Widget
) frame
->GetShellWidget();
990 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
992 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
994 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
996 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
998 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1000 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1003 void wxWindow::Centre(int direction
)
1005 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1007 wxWindow
*father
= (wxWindow
*)GetParent();
1011 father
->GetClientSize(&panel_width
, &panel_height
);
1012 GetSize(&width
, &height
);
1013 GetPosition(&x
, &y
);
1018 if (direction
& wxHORIZONTAL
)
1019 new_x
= (int)((panel_width
- width
)/2);
1021 if (direction
& wxVERTICAL
)
1022 new_y
= (int)((panel_height
- height
)/2);
1024 SetSize(new_x
, new_y
, -1, -1);
1028 // Coordinates relative to the window
1029 void wxWindow::WarpPointer (int x
, int y
)
1031 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1034 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1040 int wxWindow::GetScrollPos(int orient
) const
1042 if (orient
== wxHORIZONTAL
)
1043 return m_scrollPosX
;
1045 return m_scrollPosY
;
1047 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1051 XtVaGetValues(scrollBar,
1052 XmNvalue, &pos, NULL);
1060 // This now returns the whole range, not just the number
1061 // of positions that we can scroll.
1062 int wxWindow::GetScrollRange(int orient
) const
1064 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1068 XtVaGetValues(scrollBar
,
1069 XmNmaximum
, &range
, NULL
);
1076 int wxWindow::GetScrollThumb(int orient
) const
1078 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1082 XtVaGetValues(scrollBar
,
1083 XmNsliderSize
, &thumb
, NULL
);
1090 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1092 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1095 XtVaSetValues (scrollBar
,
1099 if (orient
== wxHORIZONTAL
)
1106 // New function that will replace some of the above.
1107 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1108 int range
, bool WXUNUSED(refresh
))
1110 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1116 if (thumbVisible
== 0)
1119 XtVaSetValues(scrollBar
,
1123 XmNsliderSize
, thumbVisible
,
1126 if (orient
== wxHORIZONTAL
)
1132 // Does a physical scroll
1133 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
1135 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1139 // Use specified rectangle
1140 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1144 // Use whole client area
1146 GetClientSize(& w
, & h
);
1149 int x1
= (dx
>= 0) ? x
: x
- dx
;
1150 int y1
= (dy
>= 0) ? y
: y
- dy
;
1151 int w1
= w
- abs(dx
);
1152 int h1
= h
- abs(dy
);
1153 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1154 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1156 wxClientDC
dc(this);
1158 dc
.SetLogicalFunction (wxCOPY
);
1160 Widget widget
= (Widget
) GetMainWidget();
1161 Window window
= XtWindow(widget
);
1162 Display
* display
= XtDisplay(widget
);
1164 XCopyArea(display
, window
,
1165 window
, (GC
) dc
.GetGC(),
1170 dc
.SetAutoSetting(TRUE
);
1171 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1172 dc
.SetBrush(brush
); // ??
1174 // We'll add rectangles to the list of update rectangles
1175 // according to which bits we've exposed.
1180 wxRect
*rect
= new wxRect
;
1186 XFillRectangle(display
, window
,
1187 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1191 rect
->width
= rect
->width
;
1192 rect
->height
= rect
->height
;
1194 updateRects
.Append((wxObject
*) rect
);
1198 wxRect
*rect
= new wxRect
;
1200 rect
->x
= x
+ w
+ dx
;
1205 XFillRectangle(display
, window
,
1206 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1211 rect
->width
= rect
->width
;
1212 rect
->height
= rect
->height
;
1214 updateRects
.Append((wxObject
*) rect
);
1218 wxRect
*rect
= new wxRect
;
1225 XFillRectangle(display
, window
,
1226 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1230 rect
->width
= rect
->width
;
1231 rect
->height
= rect
->height
;
1233 updateRects
.Append((wxObject
*) rect
);
1237 wxRect
*rect
= new wxRect
;
1240 rect
->y
= y
+ h
+ dy
;
1244 XFillRectangle(display
, window
,
1245 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1249 rect
->width
= rect
->width
;
1250 rect
->height
= rect
->height
;
1252 updateRects
.Append((wxObject
*) rect
);
1254 dc
.SetBrush(wxNullBrush
);
1256 // Now send expose events
1258 wxNode
* node
= updateRects
.First();
1261 wxRect
* rect
= (wxRect
*) node
->Data();
1264 event
.type
= Expose
;
1265 event
.display
= display
;
1266 event
.send_event
= True
;
1267 event
.window
= window
;
1271 event
.width
= rect
->width
;
1272 event
.height
= rect
->height
;
1276 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1278 node
= node
->Next();
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 // This calls the UI-update mechanism (querying windows for
1954 // menu/toolbar/control state information)
1958 // Raise the window to the top of the Z order
1959 void wxWindow::Raise()
1961 Window window
= XtWindow((Widget
) GetTopWidget());
1962 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1965 // Lower the window to the bottom of the Z order
1966 void wxWindow::Lower()
1968 Window window
= XtWindow((Widget
) GetTopWidget());
1969 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1972 bool wxWindow::AcceptsFocus() const
1974 return IsShown() && IsEnabled();
1977 // Update region access
1978 wxRegion
wxWindow::GetUpdateRegion() const
1980 return m_updateRegion
;
1983 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1985 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1988 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1990 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1993 bool wxWindow::IsExposed(const wxRect
& rect
) const
1995 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1999 * Allocates control IDs
2002 int wxWindow::NewControlId()
2004 static int s_controlId
= 0;
2009 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2011 m_acceleratorTable
= accel
;
2014 // All widgets should have this as their resize proc.
2015 // OnSize sent to wxWindow via client data.
2016 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2018 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2022 if (win
->PreResize())
2025 win
->GetSize(&width
, &height
);
2026 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2027 sizeEvent
.SetEventObject(win
);
2028 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2032 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2034 wxWindow
*oldItem
= NULL
;
2036 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2038 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2041 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2044 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2049 wxWidgetHashTable
->Put ((long) w
, win
);
2053 wxWindow
*wxGetWindowFromTable(Widget w
)
2055 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2058 void wxDeleteWindowFromTable(Widget w
)
2060 wxWidgetHashTable
->Delete((long)w
);
2063 // Get the underlying X window and display
2064 WXWindow
wxWindow::GetXWindow() const
2066 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2069 WXDisplay
*wxWindow::GetXDisplay() const
2071 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2074 WXWidget
wxWindow::GetMainWidget() const
2077 return m_drawingArea
;
2079 return m_mainWidget
;
2082 WXWidget
wxWindow::GetClientWidget() const
2084 if (m_drawingArea
!= (WXWidget
) 0)
2085 return m_drawingArea
;
2087 return GetMainWidget();
2090 WXWidget
wxWindow::GetTopWidget() const
2092 return GetMainWidget();
2095 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2096 XmDrawingAreaCallbackStruct
* cbs
)
2098 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2101 XEvent
* event
= cbs
->event
;
2102 wxWindow
* canvas
= (wxWindow
*) clientData
;
2103 Display
* display
= (Display
*) canvas
->GetXDisplay();
2104 // GC gc = (GC) canvas->GetDC()->gc;
2106 switch (event
->type
)
2111 wxCanvasDC* canvasDC = canvas->GetDC();
2114 if (canvasDC->onpaint_reg)
2115 XDestroyRegion(canvasDC->onpaint_reg);
2116 canvasDC->onpaint_reg = XCreateRegion();
2121 int n
= canvas
->m_updateRects
.Number();
2122 XRectangle
* xrects
= new XRectangle
[n
];
2124 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
2126 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
2127 xrects
[i
].x
= rect
->x
;
2128 xrects
[i
].y
= rect
->y
;
2129 xrects
[i
].width
= rect
->width
;
2130 xrects
[i
].height
= rect
->height
;
2131 /* TODO (?) Actually ignore it I think.
2133 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
2134 canvasDC->onpaint_reg);
2137 /* TODO must clip the area being repainted. So we need a gc.
2138 * Alternatively, wxPaintDC must do the clipping
2139 * when it's created.
2140 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
2143 canvas
->DoPaint() ; // xrects, n);
2146 canvas
->m_updateRects
.Clear();
2151 XDestroyRegion(canvasDC->onpaint_reg);
2152 canvasDC->onpaint_reg = NULL;
2156 gc_val.clip_mask = None;
2157 XChangeGC(display, gc, GCClipMask, &gc_val);
2164 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2170 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2172 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2174 XmDrawingAreaCallbackStruct cbs
;
2177 //if (event->mode!=NotifyNormal)
2180 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2181 ((XCrossingEvent
&) ev
) = *event
;
2183 cbs
.reason
= XmCR_INPUT
;
2186 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2189 // Fix to make it work under Motif 1.0 (!)
2190 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2194 XmDrawingAreaCallbackStruct cbs
;
2197 //ev.xbutton = *event;
2198 ev
= *((XEvent
*) event
);
2199 cbs
.reason
= XmCR_INPUT
;
2202 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2206 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2208 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2214 if (cbs
->reason
!= XmCR_INPUT
)
2217 local_event
= *(cbs
->event
); // We must keep a copy!
2219 switch (local_event
.xany
.type
)
2227 wxEventType eventType
= wxEVT_NULL
;
2229 if (local_event
.xany
.type
== EnterNotify
)
2231 //if (local_event.xcrossing.mode!=NotifyNormal)
2232 // return ; // Ignore grab events
2233 eventType
= wxEVT_ENTER_WINDOW
;
2234 // canvas->GetEventHandler()->OnSetFocus();
2236 else if (local_event
.xany
.type
== LeaveNotify
)
2238 //if (local_event.xcrossing.mode!=NotifyNormal)
2239 // return ; // Ignore grab events
2240 eventType
= wxEVT_LEAVE_WINDOW
;
2241 // canvas->GetEventHandler()->OnKillFocus();
2243 else if (local_event
.xany
.type
== MotionNotify
)
2245 eventType
= wxEVT_MOTION
;
2246 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2249 Display
*dpy
= XtDisplay (drawingArea
);
2251 XQueryPointer (dpy
, XtWindow (drawingArea
),
2253 &local_event
.xmotion
.x_root
,
2254 &local_event
.xmotion
.y_root
,
2255 &local_event
.xmotion
.x
,
2256 &local_event
.xmotion
.y
,
2257 &local_event
.xmotion
.state
);
2264 else if (local_event
.xany
.type
== ButtonPress
)
2266 if (local_event
.xbutton
.button
== Button1
)
2268 eventType
= wxEVT_LEFT_DOWN
;
2269 canvas
->m_button1Pressed
= TRUE
;
2271 else if (local_event
.xbutton
.button
== Button2
)
2273 eventType
= wxEVT_MIDDLE_DOWN
;
2274 canvas
->m_button2Pressed
= TRUE
;
2276 else if (local_event
.xbutton
.button
== Button3
)
2278 eventType
= wxEVT_RIGHT_DOWN
;
2279 canvas
->m_button3Pressed
= TRUE
;
2282 else if (local_event
.xany
.type
== ButtonRelease
)
2284 if (local_event
.xbutton
.button
== Button1
)
2286 eventType
= wxEVT_LEFT_UP
;
2287 canvas
->m_button1Pressed
= FALSE
;
2289 else if (local_event
.xbutton
.button
== Button2
)
2291 eventType
= wxEVT_MIDDLE_UP
;
2292 canvas
->m_button2Pressed
= FALSE
;
2294 else if (local_event
.xbutton
.button
== Button3
)
2296 eventType
= wxEVT_RIGHT_UP
;
2297 canvas
->m_button3Pressed
= FALSE
;
2301 wxMouseEvent
wxevent (eventType
);
2302 wxevent
.m_eventHandle
= (char *) &local_event
;
2304 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2305 || (event_left_is_down (&local_event
)
2306 && (eventType
!= wxEVT_LEFT_UP
)));
2307 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2308 || (event_middle_is_down (&local_event
)
2309 && (eventType
!= wxEVT_MIDDLE_UP
)));
2310 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2311 || (event_right_is_down (&local_event
)
2312 && (eventType
!= wxEVT_RIGHT_UP
)));
2314 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2315 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2316 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2317 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2318 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2320 // Now check if we need to translate this event into a double click
2321 if (TRUE
) // canvas->doubleClickAllowed)
2323 if (wxevent
.ButtonDown())
2325 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2327 // get button and time-stamp
2329 if (wxevent
.LeftDown()) button
= 1;
2330 else if (wxevent
.MiddleDown()) button
= 2;
2331 else if (wxevent
.RightDown()) button
= 3;
2332 long ts
= wxevent
.GetTimestamp();
2333 // check, if single or double click
2334 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2337 canvas
->m_lastButton
= 0;
2338 switch ( eventType
)
2340 case wxEVT_LEFT_DOWN
:
2341 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2343 case wxEVT_MIDDLE_DOWN
:
2344 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2346 case wxEVT_RIGHT_DOWN
:
2347 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2357 // not fast enough or different button
2358 canvas
->m_lastTS
= ts
;
2359 canvas
->m_lastButton
= button
;
2364 wxevent
.SetId(canvas
->GetId());
2365 wxevent
.SetEventObject(canvas
);
2366 wxevent
.m_x
= local_event
.xbutton
.x
;
2367 wxevent
.m_y
= local_event
.xbutton
.y
;
2368 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2370 if (eventType == wxEVT_ENTER_WINDOW ||
2371 eventType == wxEVT_LEAVE_WINDOW ||
2372 eventType == wxEVT_MOTION
2381 // XComposeStatus compose;
2382 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2383 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2384 int id
= wxCharCodeXToWX (keySym
);
2386 wxKeyEvent
event (wxEVT_CHAR
);
2388 if (local_event
.xkey
.state
& ShiftMask
)
2389 event
.m_shiftDown
= TRUE
;
2390 if (local_event
.xkey
.state
& ControlMask
)
2391 event
.m_controlDown
= TRUE
;
2392 if (local_event
.xkey
.state
& Mod3Mask
)
2393 event
.m_altDown
= TRUE
;
2394 if (local_event
.xkey
.state
& Mod1Mask
)
2395 event
.m_metaDown
= TRUE
;
2396 event
.SetEventObject(canvas
);
2397 event
.m_keyCode
= id
;
2398 event
.SetTimestamp(local_event
.xkey
.time
);
2402 // Implement wxFrame::OnCharHook by checking ancestor.
2403 wxWindow
*parent
= canvas
->GetParent();
2404 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2405 parent
= parent
->GetParent();
2409 event
.SetEventType(wxEVT_CHAR_HOOK
);
2410 if (parent
->GetEventHandler()->ProcessEvent(event
))
2412 event
.SetEventType(wxEVT_CHAR
);
2415 canvas
->GetEventHandler()->ProcessEvent (event
);
2421 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2423 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2424 event
.SetEventObject(canvas
);
2425 canvas
->GetEventHandler()->ProcessEvent(event
);
2431 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2433 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2434 event
.SetEventObject(canvas
);
2435 canvas
->GetEventHandler()->ProcessEvent(event
);
2444 void wxWindow::DoPaint()
2446 //TODO : make a temporary gc so we can do the XCopyArea below
2447 if (0) // m_backingPixmap)
2450 Widget drawingArea = (Widget) m_drawingArea;
2451 // int orig = GetDC()->GetLogicalFunction();
2452 // GetDC()->SetLogicalFunction (wxCOPY);
2454 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2455 // should be able to calculate them.
2456 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2457 m_pixmapOffsetX, m_pixmapOffsetY,
2458 m_pixmapWidth, m_pixmapHeight,
2461 // GetDC()->SetLogicalFunction (orig);
2466 wxPaintEvent
event(GetId());
2467 event
.SetEventObject(this);
2468 GetEventHandler()->ProcessEvent(event
);
2472 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2473 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2475 Widget drawingArea
= (Widget
) m_drawingArea
;
2476 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2479 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2480 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2482 int xx
= x
; int yy
= y
;
2483 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2485 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2487 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2491 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2493 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2501 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2502 short thick
, margin
;
2503 XtVaGetValues ((Widget
) m_borderWidget
,
2504 XmNshadowThickness
, &thick
,
2505 XmNmarginWidth
, &margin
,
2507 w
-= 2 * (thick
+ margin
);
2510 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2514 XtVaGetValues ((Widget
) m_scrolledWindow
,
2515 XmNspacing
, &spacing
,
2516 XmNverticalScrollBar
, &sbar
,
2520 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2524 w
-= (spacing
+ wsbar
);
2526 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2532 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2533 short thick
, margin
;
2534 XtVaGetValues ((Widget
) m_borderWidget
,
2535 XmNshadowThickness
, &thick
,
2536 XmNmarginHeight
, &margin
,
2538 h
-= 2 * (thick
+ margin
);
2541 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2545 XtVaGetValues ((Widget
) m_scrolledWindow
,
2546 XmNspacing
, &spacing
,
2547 XmNhorizontalScrollBar
, &sbar
,
2551 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2555 h
-= (spacing
+ wsbar
);
2557 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2560 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2561 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2564 GetClientSize (&ww
, &hh
);
2565 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2566 sizeEvent
.SetEventObject(this);
2568 GetEventHandler()->ProcessEvent(sizeEvent
);
2571 void wxWindow::CanvasSetClientSize (int w
, int h
)
2573 Widget drawingArea
= (Widget
) m_drawingArea
;
2575 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2578 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2580 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2581 /* TODO: is this necessary?
2582 allowRepainting = FALSE;
2584 XSync (XtDisplay (drawingArea), FALSE);
2586 while (XtAppPending (wxTheApp->appContext))
2588 XFlush (XtDisplay (drawingArea));
2589 XtAppNextEvent (wxTheApp->appContext, &event);
2590 XtDispatchEvent (&event);
2594 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2597 allowRepainting = TRUE;
2601 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2602 sizeEvent
.SetEventObject(this);
2604 GetEventHandler()->ProcessEvent(sizeEvent
);
2607 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2609 // Must return the same thing that was set via SetClientSize
2611 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2616 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2619 if ((Widget
) m_borderWidget
)
2620 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2621 else if ((Widget
) m_scrolledWindow
)
2622 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2624 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2630 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2633 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2635 // We may be faking the client origin.
2636 // So a window that's really at (0, 30) may appear
2637 // (to wxWin apps) to be at (0, 0).
2640 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2649 // Add to hash table, add event handler
2650 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2651 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2653 wxAddWindowToTable((Widget
) mainWidget
, this);
2654 if (CanAddEventHandler())
2656 XtAddEventHandler((Widget
) mainWidget
,
2657 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2659 wxPanelItemEventHandler
,
2666 XtOverrideTranslations ((Widget
) mainWidget
,
2667 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2668 XtFree ((char *) ptr
);
2671 // Some widgets have a parent form widget, e.g. wxRadioBox
2674 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2678 XtOverrideTranslations ((Widget
) formWidget
,
2679 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2680 XtFree ((char *) ptr
);
2687 SetSize (x
, y
, width
, height
);
2692 // Remove event handler, remove from hash table
2693 bool wxWindow::DetachWidget(WXWidget widget
)
2695 if (CanAddEventHandler())
2697 XtRemoveEventHandler((Widget
) widget
,
2698 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2700 wxPanelItemEventHandler
,
2704 wxDeleteWindowFromTable((Widget
) widget
);
2708 void wxPanelItemEventHandler (Widget wid
,
2709 XtPointer client_data
,
2711 Boolean
*continueToDispatch
)
2713 // Widget can be a label or the actual widget.
2715 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2718 wxMouseEvent
wxevent(0);
2719 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2721 window
->GetEventHandler()->ProcessEvent(wxevent
);
2724 // TODO: probably the key to allowing default behaviour
2726 // Say we set a m_doDefault flag to FALSE at the start of this
2727 // function. Then in e.g. wxWindow::OnMouseEvent we can
2728 // call Default() which sets this flag to TRUE, indicating
2729 // that default processing can happen. Thus, behaviour can appear
2730 // to be overridden just by adding an event handler and not calling
2731 // wxWindow::OnWhatever.
2732 // ALSO, maybe we can use this instead of the current way of handling
2733 // drawing area events, to simplify things.
2734 *continueToDispatch
= True
;
2737 void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2738 XmScaleCallbackStruct
*cbs
)
2740 Widget scrolledWindow
= XtParent (scrollbar
);
2741 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2742 int orientation
= (int) clientData
;
2744 wxEventType eventType
= wxEVT_NULL
;
2745 switch (cbs
->reason
)
2747 case XmCR_INCREMENT
:
2749 eventType
= wxEVT_SCROLL_LINEDOWN
;
2752 case XmCR_DECREMENT
:
2754 eventType
= wxEVT_SCROLL_LINEUP
;
2759 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2762 case XmCR_VALUE_CHANGED
:
2764 // TODO: Should this be intercepted too, or will it cause
2765 // duplicate events?
2766 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2769 case XmCR_PAGE_INCREMENT
:
2771 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2774 case XmCR_PAGE_DECREMENT
:
2776 eventType
= wxEVT_SCROLL_PAGEUP
;
2781 eventType
= wxEVT_SCROLL_TOP
;
2784 case XmCR_TO_BOTTOM
:
2786 eventType
= wxEVT_SCROLL_BOTTOM
;
2791 // Should never get here
2792 wxFAIL_MSG("Unknown scroll event.");
2797 wxScrollEvent
event(eventType
, win
->GetId());
2798 event
.SetEventObject(win
);
2799 event
.SetPosition(cbs
->value
);
2800 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2802 win
->GetEventHandler()->ProcessEvent(event
);
2805 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2807 switch (xevent
->xany
.type
)
2815 wxEventType eventType
= wxEVT_NULL
;
2817 if (xevent
->xany
.type
== LeaveNotify
)
2819 win
->m_button1Pressed
= FALSE
;
2820 win
->m_button2Pressed
= FALSE
;
2821 win
->m_button3Pressed
= FALSE
;
2824 else if (xevent
->xany
.type
== MotionNotify
)
2826 eventType
= wxEVT_MOTION
;
2828 else if (xevent
->xany
.type
== ButtonPress
)
2830 if (xevent
->xbutton
.button
== Button1
)
2832 eventType
= wxEVT_LEFT_DOWN
;
2833 win
->m_button1Pressed
= TRUE
;
2835 else if (xevent
->xbutton
.button
== Button2
)
2837 eventType
= wxEVT_MIDDLE_DOWN
;
2838 win
->m_button2Pressed
= TRUE
;
2840 else if (xevent
->xbutton
.button
== Button3
)
2842 eventType
= wxEVT_RIGHT_DOWN
;
2843 win
->m_button3Pressed
= TRUE
;
2846 else if (xevent
->xany
.type
== ButtonRelease
)
2848 if (xevent
->xbutton
.button
== Button1
)
2850 eventType
= wxEVT_LEFT_UP
;
2851 win
->m_button1Pressed
= FALSE
;
2853 else if (xevent
->xbutton
.button
== Button2
)
2855 eventType
= wxEVT_MIDDLE_UP
;
2856 win
->m_button2Pressed
= FALSE
;
2858 else if (xevent
->xbutton
.button
== Button3
)
2860 eventType
= wxEVT_RIGHT_UP
;
2861 win
->m_button3Pressed
= FALSE
;
2867 wxevent
.m_eventHandle
= (char *)xevent
;
2868 wxevent
.SetEventType(eventType
);
2871 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2874 win
->GetPosition(&x2
, &y2
);
2876 // The button x/y must be translated to wxWindows
2877 // window space - the widget might be a label or button,
2881 if (widget
!= (Widget
)win
->GetMainWidget())
2887 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2888 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2890 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2891 || (event_left_is_down (xevent
)
2892 && (eventType
!= wxEVT_LEFT_UP
)));
2893 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2894 || (event_middle_is_down (xevent
)
2895 && (eventType
!= wxEVT_MIDDLE_UP
)));
2896 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2897 || (event_right_is_down (xevent
)
2898 && (eventType
!= wxEVT_RIGHT_UP
)));
2900 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2901 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2908 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2910 switch (xevent
->xany
.type
)
2917 // XComposeStatus compose;
2918 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2919 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2920 int id
= wxCharCodeXToWX (keySym
);
2922 if (xevent
->xkey
.state
& ShiftMask
)
2923 wxevent
.m_shiftDown
= TRUE
;
2924 if (xevent
->xkey
.state
& ControlMask
)
2925 wxevent
.m_controlDown
= TRUE
;
2926 if (xevent
->xkey
.state
& Mod3Mask
)
2927 wxevent
.m_altDown
= TRUE
;
2928 if (xevent
->xkey
.state
& Mod1Mask
)
2929 wxevent
.m_metaDown
= TRUE
;
2930 wxevent
.SetEventObject(win
);
2931 wxevent
.m_keyCode
= id
;
2932 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2934 wxevent
.m_x
= xevent
->xbutton
.x
;
2935 wxevent
.m_y
= xevent
->xbutton
.y
;
2949 #define YAllocColor XAllocColor
2950 XColor g_itemColors
[5];
2951 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2954 static XmColorProc colorProc
;
2956 result
= wxNO_COLORS
;
2960 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2961 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2962 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2963 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2964 if (colorProc
== (XmColorProc
) NULL
)
2966 // Get a ptr to the actual function
2967 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2968 // And set it back to motif.
2969 XmSetColorCalculation (colorProc
);
2971 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2972 &g_itemColors
[wxFORE_INDEX
],
2973 &g_itemColors
[wxSELE_INDEX
],
2974 &g_itemColors
[wxTOPS_INDEX
],
2975 &g_itemColors
[wxBOTS_INDEX
]);
2976 result
= wxBACK_COLORS
;
2980 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2981 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2982 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2983 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2984 if (result
== wxNO_COLORS
)
2985 result
= wxFORE_COLORS
;
2988 Display
*dpy
= display
;
2989 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2993 /* 5 Colours to allocate */
2994 for (int i
= 0; i
< 5; i
++)
2995 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
2996 result
= wxNO_COLORS
;
3000 /* Only 1 colour to allocate */
3001 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3002 result
= wxNO_COLORS
;
3009 // Changes the foreground and background colours to be derived
3010 // from the current background colour.
3011 // To change the foreground colour, you must call SetForegroundColour
3013 void wxWindow::ChangeBackgroundColour()
3015 if (GetMainWidget())
3016 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3019 void wxWindow::ChangeForegroundColour()
3021 if (GetMainWidget())
3022 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3025 // Change a widget's foreground and background colours.
3027 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3029 // When should we specify the foreground, if it's calculated
3030 // by wxComputeColours?
3031 // Solution: say we start with the default (computed) foreground colour.
3032 // If we call SetForegroundColour explicitly for a control or window,
3033 // then the foreground is changed.
3034 // Therefore SetBackgroundColour computes the foreground colour, and
3035 // SetForegroundColour changes the foreground colour. The ordering is
3038 XtVaSetValues ((Widget
) widget
,
3039 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3043 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3045 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3048 XtVaSetValues ((Widget
) widget
,
3049 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3050 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3051 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3052 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3055 if (changeArmColour
)
3056 XtVaSetValues ((Widget
) widget
,
3057 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3061 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3063 m_backgroundColour
= col
;
3064 ChangeBackgroundColour();
3067 void wxWindow::SetForegroundColour(const wxColour
& col
)
3069 m_foregroundColour
= col
;
3070 ChangeForegroundColour();
3073 void wxWindow::ChangeFont(bool keepOriginalSize
)
3075 // Note that this causes the widget to be resized back
3076 // to its original size! We therefore have to set the size
3077 // back again. TODO: a better way in Motif?
3078 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3079 if (w
&& m_windowFont
.Ok())
3081 int width
, height
, width1
, height1
;
3082 GetSize(& width
, & height
);
3085 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3088 GetSize(& width1
, & height1
);
3089 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3091 SetSize(-1, -1, width
, height
);
3096 void wxWindow::SetFont(const wxFont
& font
)
3098 m_windowFont
= font
;