1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/menuitem.h"
34 #if wxUSE_DRAG_AND_DROP
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
46 #include "wx/motif/private.h"
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
52 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
54 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
55 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
56 XmScaleCallbackStruct
*cbs
);
57 void wxPanelItemEventHandler (Widget wid
,
58 XtPointer client_data
,
60 Boolean
*continueToDispatch
);
62 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
63 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
64 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
66 extern wxList wxPendingDelete
;
68 #if !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
71 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
72 EVT_CHAR(wxWindow::OnChar
)
73 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
74 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
75 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
76 EVT_IDLE(wxWindow::OnIdle
)
88 m_windowParent
= NULL
;
89 m_windowEventHandler
= this;
91 m_windowCursor
= *wxSTANDARD_CURSOR
;
92 m_children
= new wxList
;
94 m_constraintsInvolvedIn
= NULL
;
98 m_windowValidator
= NULL
;
101 m_caretWidth
= 0; m_caretHeight
= 0;
102 m_caretEnabled
= FALSE
;
103 m_caretShown
= FALSE
;
104 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
105 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
106 m_foregroundColour
= *wxBLACK
;
108 #if wxUSE_DRAG_AND_DROP
109 m_pDropTarget
= NULL
;
111 m_clientObject
= (wxClientData
*) NULL
;
115 m_mainWidget
= (WXWidget
) 0;
116 m_button1Pressed
= FALSE
;
117 m_button2Pressed
= FALSE
;
118 m_button3Pressed
= FALSE
;
119 m_winCaptured
= FALSE
;
121 m_hScrollBar
= (WXWidget
) 0;
122 m_vScrollBar
= (WXWidget
) 0;
123 m_borderWidget
= (WXWidget
) 0;
124 m_scrolledWindow
= (WXWidget
) 0;
125 m_drawingArea
= (WXWidget
) 0;
128 m_backingPixmap
= (WXPixmap
) 0;
135 m_canAddEventHandler
= FALSE
;
141 wxWindow::~wxWindow()
146 DetachWidget(GetMainWidget()); // Removes event handlers
148 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
151 // Destroy children before destroying self
155 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
157 Widget w
= (Widget
) m_drawingArea
;
158 wxDeleteWindowFromTable(w
);
162 m_mainWidget
= (WXWidget
) 0;
164 // Only if we're _really_ a canvas (not a dialog box/panel)
165 if (m_scrolledWindow
)
167 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
172 XtUnmanageChild ((Widget
) m_hScrollBar
);
173 XtDestroyWidget ((Widget
) m_hScrollBar
);
177 XtUnmanageChild ((Widget
) m_vScrollBar
);
178 XtDestroyWidget ((Widget
) m_vScrollBar
);
180 if (m_scrolledWindow
)
182 XtUnmanageChild ((Widget
) m_scrolledWindow
);
183 XtDestroyWidget ((Widget
) m_scrolledWindow
);
188 XtDestroyWidget ((Widget
) m_borderWidget
);
189 m_borderWidget
= (WXWidget
) 0;
195 // Have to delete constraints/sizer FIRST otherwise
196 // sizers may try to look at deleted windows as they
197 // delete themselves.
198 #if wxUSE_CONSTRAINTS
199 DeleteRelatedConstraints();
202 // This removes any dangling pointers to this window
203 // in other windows' constraintsInvolvedIn lists.
204 UnsetConstraints(m_constraints
);
205 delete m_constraints
;
206 m_constraints
= NULL
;
210 delete m_windowSizer
;
211 m_windowSizer
= NULL
;
213 // If this is a child of a sizer, remove self from parent
215 m_sizerParent
->RemoveChild((wxWindow
*)this);
219 m_windowParent
->RemoveChild(this);
223 // Destroy the window
226 wxDeleteWindowFromTable((Widget
) GetMainWidget());
227 XtDestroyWidget((Widget
) GetMainWidget());
228 SetMainWidget((WXWidget
) NULL
);
234 // Just in case the window has been Closed, but
235 // we're then deleting immediately: don't leave
236 // dangling pointers.
237 wxPendingDelete
.DeleteObject(this);
239 if ( m_windowValidator
) delete m_windowValidator
;
240 if (m_clientObject
) delete m_clientObject
;
245 // Destroy the window (delayed, if a managed window)
246 bool wxWindow::Destroy()
253 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
257 const wxString
& name
)
262 m_windowParent
= NULL
;
263 m_windowEventHandler
= this;
265 m_windowCursor
= *wxSTANDARD_CURSOR
;
266 m_constraints
= NULL
;
267 m_constraintsInvolvedIn
= NULL
;
268 m_windowSizer
= NULL
;
269 m_sizerParent
= NULL
;
270 m_autoLayout
= FALSE
;
271 m_windowValidator
= NULL
;
272 #if wxUSE_DRAG_AND_DROP
273 m_pDropTarget
= NULL
;
275 m_caretWidth
= 0; m_caretHeight
= 0;
276 m_caretEnabled
= FALSE
;
277 m_caretShown
= FALSE
;
282 m_defaultItem
= NULL
;
283 m_windowParent
= NULL
;
284 m_clientObject
= (wxClientData
*) NULL
;
288 m_canAddEventHandler
= FALSE
;
289 m_mainWidget
= (WXWidget
) 0;
290 m_button1Pressed
= FALSE
;
291 m_button2Pressed
= FALSE
;
292 m_button3Pressed
= FALSE
;
293 m_winCaptured
= FALSE
;
295 m_hScrollBar
= (WXWidget
) 0;
296 m_vScrollBar
= (WXWidget
) 0;
297 m_borderWidget
= (WXWidget
) 0;
298 m_scrolledWindow
= (WXWidget
) 0;
299 m_drawingArea
= (WXWidget
) 0;
302 m_backingPixmap
= (WXPixmap
) 0;
313 if (parent
) parent
->AddChild(this);
320 m_windowId
= (int)NewControlId();
324 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
325 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
326 m_foregroundColour
= *wxBLACK
;
328 m_windowStyle
= style
;
331 m_windowId
= (int)NewControlId();
335 //// TODO: we should probably optimize by only creating a
336 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
337 //// But for now, let's simplify things by always creating the
338 //// drawing area, since otherwise the translations are different.
340 // New translations for getting mouse motion feedback
341 String translations
=
342 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
343 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
344 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
346 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
347 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
348 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
349 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
350 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
351 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
352 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
353 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
354 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
355 <Key>: DrawingAreaInput()";
357 XtActionsRec actions
[1];
358 actions
[0].string
= "wxCanvasMotionEvent";
359 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
360 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
362 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
363 if (style
& wxBORDER
)
364 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
365 xmFrameWidgetClass
, parentWidget
,
366 XmNshadowType
, XmSHADOW_IN
,
369 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
370 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
372 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
376 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
377 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
378 XmNunitType
, XmPIXELS
,
379 // XmNresizePolicy, XmRESIZE_ANY,
380 XmNresizePolicy
, XmRESIZE_NONE
,
383 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
386 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
388 XtFree ((char *) ptr);
389 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
390 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
391 XtFree ((char *) ptr);
395 wxAddWindowToTable((Widget
) m_drawingArea
, this);
396 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
399 * This order is very important in Motif 1.2.1
403 XtRealizeWidget ((Widget
) m_scrolledWindow
);
404 XtRealizeWidget ((Widget
) m_drawingArea
);
405 XtManageChild ((Widget
) m_drawingArea
);
407 XtOverrideTranslations ((Widget
) m_drawingArea
,
408 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
409 XtFree ((char *) ptr
);
411 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
412 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
415 display = XtDisplay (scrolledWindow);
416 xwindow = XtWindow (drawingArea);
419 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
420 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
422 // Add scrollbars if required
423 if (m_windowStyle
& wxHSCROLL
)
425 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
426 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
427 XmNorientation
, XmHORIZONTAL
,
429 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
430 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
431 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
432 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
433 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
434 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
435 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
436 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
438 XtVaSetValues (hScrollBar
,
443 m_hScrollBar
= (WXWidget
) hScrollBar
;
446 if (m_windowStyle
& wxVSCROLL
)
448 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
449 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
450 XmNorientation
, XmVERTICAL
,
452 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
453 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
454 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
455 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
456 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
457 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
458 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
459 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
461 XtVaSetValues (vScrollBar
,
466 m_vScrollBar
= (WXWidget
) vScrollBar
;
470 if (m_hScrollBar
|| m_vScrollBar
)
471 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
474 XtRealizeWidget ((Widget
) m_hScrollBar
);
476 XtRealizeWidget ((Widget
) m_vScrollBar
);
478 // Without this, the cursor may not be restored properly
479 // (e.g. in splitter sample).
480 SetCursor(*wxSTANDARD_CURSOR
);
481 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
486 void wxWindow::SetFocus()
488 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
489 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
492 void wxWindow::Enable(bool enable
)
496 XtSetSensitive((Widget
) GetMainWidget(), enable
);
497 XmUpdateDisplay((Widget
) GetMainWidget());
501 void wxWindow::CaptureMouse()
507 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
509 m_winCaptured
= TRUE
;
512 void wxWindow::ReleaseMouse()
518 XtRemoveGrab((Widget
) GetMainWidget());
519 m_winCaptured
= FALSE
;
522 // Push/pop event handler (i.e. allow a chain of event handlers
524 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
526 handler
->SetNextHandler(GetEventHandler());
527 SetEventHandler(handler
);
530 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
532 if ( GetEventHandler() )
534 wxEvtHandler
*handlerA
= GetEventHandler();
535 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
536 handlerA
->SetNextHandler(NULL
);
537 SetEventHandler(handlerB
);
550 #if wxUSE_DRAG_AND_DROP
552 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
554 if ( m_pDropTarget
!= 0 ) {
555 delete m_pDropTarget
;
558 m_pDropTarget
= pDropTarget
;
559 if ( m_pDropTarget
!= 0 )
567 // Old style file-manager drag&drop
568 void wxWindow::DragAcceptFiles(bool accept
)
574 void wxWindow::GetSize(int *x
, int *y
) const
582 Widget widget
= (Widget
) GetTopWidget();
584 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
588 void wxWindow::GetPosition(int *x
, int *y
) const
592 CanvasGetPosition(x
, y
);
595 Widget widget
= (Widget
) GetTopWidget();
597 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
599 // We may be faking the client origin.
600 // So a window that's really at (0, 30) may appear
601 // (to wxWin apps) to be at (0, 0).
604 wxPoint
pt(GetParent()->GetClientAreaOrigin());
612 void wxWindow::ScreenToClient(int *x
, int *y
) const
614 Widget widget
= (Widget
) GetClientWidget();
615 Display
*display
= XtDisplay((Widget
) GetMainWidget());
616 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
617 Window thisWindow
= XtWindow(widget
);
622 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
625 void wxWindow::ClientToScreen(int *x
, int *y
) const
627 Widget widget
= (Widget
) GetClientWidget();
628 Display
*display
= XtDisplay(widget
);
629 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
630 Window thisWindow
= XtWindow(widget
);
635 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
638 void wxWindow::SetCursor(const wxCursor
& cursor
)
640 m_windowCursor
= cursor
;
641 if (m_windowCursor
.Ok())
643 WXDisplay
*dpy
= GetXDisplay();
644 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
646 Widget w
= (Widget
) GetMainWidget();
647 Window win
= XtWindow(w
);
648 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
653 // Get size *available for subwindows* i.e. excluding menu bar etc.
654 void wxWindow::GetClientSize(int *x
, int *y
) const
656 Widget widget
= (Widget
) GetClientWidget();
658 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
662 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
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
)
744 XtMapWidget((Widget
) m_drawingArea
);
745 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
749 XtMapWidget((Widget
) GetTopWidget());
754 if (m_borderWidget
|| m_scrolledWindow
)
757 XtUnmapWidget((Widget
) m_drawingArea
);
758 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
762 XtUnmapWidget((Widget
) GetTopWidget());
767 Window xwin = (Window) GetXWindow();
768 Display *xdisp = (Display*) GetXDisplay();
770 XMapWindow(xdisp, xwin);
772 XUnmapWindow(xdisp, xwin);
780 bool wxWindow::IsShown() const
785 int wxWindow::GetCharHeight() const
787 if (!m_windowFont
.Ok())
790 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
792 int direction
, ascent
, descent
;
794 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
796 // return (overall.ascent + overall.descent);
797 return (ascent
+ descent
);
800 int wxWindow::GetCharWidth() const
802 if (!m_windowFont
.Ok())
805 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
807 int direction
, ascent
, descent
;
809 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
811 return overall
.width
;
814 /* Helper function for 16-bit fonts */
815 static int str16len(const char *s
)
819 while (s
[0] && s
[1]) {
827 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
828 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
830 wxFont
*fontToUse
= (wxFont
*)theFont
;
832 fontToUse
= (wxFont
*) & m_windowFont
;
834 if (!fontToUse
->Ok())
837 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
839 int direction
, ascent
, descent2
;
843 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
846 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
847 &ascent
, &descent2
, &overall
);
849 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
850 &ascent
, &descent2
, &overall
);
852 *x
= (overall
.width
);
853 *y
= (ascent
+ descent2
);
857 *externalLeading
= 0;
860 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
862 Display
*display
= XtDisplay((Widget
) GetMainWidget());
863 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
865 XExposeEvent dummyEvent
;
867 GetSize(&width
, &height
);
869 dummyEvent
.type
= Expose
;
870 dummyEvent
.display
= display
;
871 dummyEvent
.send_event
= True
;
872 dummyEvent
.window
= thisWindow
;
875 dummyEvent
.x
= rect
->x
;
876 dummyEvent
.y
= rect
->y
;
877 dummyEvent
.width
= rect
->width
;
878 dummyEvent
.height
= rect
->height
;
884 dummyEvent
.width
= width
;
885 dummyEvent
.height
= height
;
887 dummyEvent
.count
= 0;
892 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
893 dc
.SetBackground(backgroundBrush
);
897 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
900 // Responds to colour changes: passes event on to children.
901 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
903 wxNode
*node
= GetChildren()->First();
906 // Only propagate to non-top-level windows
907 wxWindow
*win
= (wxWindow
*)node
->Data();
908 if ( win
->GetParent() )
910 wxSysColourChangedEvent event2
;
911 event
.m_eventObject
= win
;
912 win
->GetEventHandler()->ProcessEvent(event2
);
919 // This can be called by the app (or wxWindows) to do default processing for the current
920 // event. Save message/event info in wxWindow so they can be used in this function.
921 long wxWindow::Default()
927 void wxWindow::InitDialog()
929 wxInitDialogEvent
event(GetId());
930 event
.SetEventObject( this );
931 GetEventHandler()->ProcessEvent(event
);
934 // Default init dialog behaviour is to transfer data to window
935 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
937 TransferDataToWindow();
940 // Caret manipulation
941 void wxWindow::CreateCaret(int w
, int h
)
945 m_caretEnabled
= TRUE
;
948 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
953 void wxWindow::ShowCaret(bool show
)
958 void wxWindow::DestroyCaret()
961 m_caretEnabled
= FALSE
;
964 void wxWindow::SetCaretPos(int x
, int y
)
969 void wxWindow::GetCaretPos(int *x
, int *y
) const
974 wxWindow
*wxGetActiveWindow()
980 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
987 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
990 wxFrame
*frame
= (wxFrame
*)this;
991 Widget widget
= (Widget
) frame
->GetShellWidget();
994 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
996 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
998 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1000 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1002 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1004 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1007 void wxWindow::Centre(int direction
)
1009 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1011 wxWindow
*father
= (wxWindow
*)GetParent();
1015 father
->GetClientSize(&panel_width
, &panel_height
);
1016 GetSize(&width
, &height
);
1017 GetPosition(&x
, &y
);
1022 if (direction
& wxHORIZONTAL
)
1023 new_x
= (int)((panel_width
- width
)/2);
1025 if (direction
& wxVERTICAL
)
1026 new_y
= (int)((panel_height
- height
)/2);
1028 SetSize(new_x
, new_y
, -1, -1);
1032 // Coordinates relative to the window
1033 void wxWindow::WarpPointer (int x
, int y
)
1035 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1038 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1044 int wxWindow::GetScrollPos(int orient
) const
1046 if (orient
== wxHORIZONTAL
)
1047 return m_scrollPosX
;
1049 return m_scrollPosY
;
1051 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1055 XtVaGetValues(scrollBar,
1056 XmNvalue, &pos, NULL);
1064 // This now returns the whole range, not just the number
1065 // of positions that we can scroll.
1066 int wxWindow::GetScrollRange(int orient
) const
1068 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1072 XtVaGetValues(scrollBar
,
1073 XmNmaximum
, &range
, NULL
);
1080 int wxWindow::GetScrollThumb(int orient
) const
1082 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1086 XtVaGetValues(scrollBar
,
1087 XmNsliderSize
, &thumb
, NULL
);
1094 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1096 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1099 XtVaSetValues (scrollBar
,
1103 if (orient
== wxHORIZONTAL
)
1110 // New function that will replace some of the above.
1111 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1112 int range
, bool WXUNUSED(refresh
))
1114 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1120 if (thumbVisible
== 0)
1123 XtVaSetValues(scrollBar
,
1127 XmNsliderSize
, thumbVisible
,
1130 if (orient
== wxHORIZONTAL
)
1136 // Does a physical scroll
1137 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
1139 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1143 // Use specified rectangle
1144 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1148 // Use whole client area
1150 GetClientSize(& w
, & h
);
1153 int x1
= (dx
>= 0) ? x
: x
- dx
;
1154 int y1
= (dy
>= 0) ? y
: y
- dy
;
1155 int w1
= w
- abs(dx
);
1156 int h1
= h
- abs(dy
);
1157 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1158 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1160 wxClientDC
dc(this);
1162 dc
.SetLogicalFunction (wxCOPY
);
1164 Widget widget
= (Widget
) GetMainWidget();
1165 Window window
= XtWindow(widget
);
1166 Display
* display
= XtDisplay(widget
);
1168 XCopyArea(display
, window
,
1169 window
, (GC
) dc
.GetGC(),
1174 dc
.SetAutoSetting(TRUE
);
1175 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1176 dc
.SetBrush(brush
); // ??
1178 // We'll add rectangles to the list of update rectangles
1179 // according to which bits we've exposed.
1184 wxRect
*rect
= new wxRect
;
1190 XFillRectangle(display
, window
,
1191 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1195 rect
->width
= rect
->width
;
1196 rect
->height
= rect
->height
;
1198 updateRects
.Append((wxObject
*) rect
);
1202 wxRect
*rect
= new wxRect
;
1204 rect
->x
= x
+ w
+ dx
;
1209 XFillRectangle(display
, window
,
1210 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1215 rect
->width
= rect
->width
;
1216 rect
->height
= rect
->height
;
1218 updateRects
.Append((wxObject
*) rect
);
1222 wxRect
*rect
= new wxRect
;
1229 XFillRectangle(display
, window
,
1230 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1234 rect
->width
= rect
->width
;
1235 rect
->height
= rect
->height
;
1237 updateRects
.Append((wxObject
*) rect
);
1241 wxRect
*rect
= new wxRect
;
1244 rect
->y
= y
+ h
+ dy
;
1248 XFillRectangle(display
, window
,
1249 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1253 rect
->width
= rect
->width
;
1254 rect
->height
= rect
->height
;
1256 updateRects
.Append((wxObject
*) rect
);
1258 dc
.SetBrush(wxNullBrush
);
1260 // Now send expose events
1262 wxNode
* node
= updateRects
.First();
1265 wxRect
* rect
= (wxRect
*) node
->Data();
1268 event
.type
= Expose
;
1269 event
.display
= display
;
1270 event
.send_event
= True
;
1271 event
.window
= window
;
1275 event
.width
= rect
->width
;
1276 event
.height
= rect
->height
;
1280 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1282 node
= node
->Next();
1287 void wxWindow::OnChar(wxKeyEvent
& event
)
1289 if ( event
.KeyCode() == WXK_TAB
) {
1290 // propagate the TABs to the parent - it's up to it to decide what
1292 if ( GetParent() ) {
1293 if ( GetParent()->ProcessEvent(event
) )
1299 void wxWindow::OnPaint(wxPaintEvent
& event
)
1304 bool wxWindow::IsEnabled() const
1306 // TODO. Is this right?
1307 // return XtGetSensitive((Widget) GetMainWidget());
1311 // Dialog support: override these and call
1312 // base class members to add functionality
1313 // that can't be done using validators.
1314 // NOTE: these functions assume that controls
1315 // are direct children of this window, not grandchildren
1316 // or other levels of descendant.
1318 // Transfer values to controls. If returns FALSE,
1319 // it's an application error (pops up a dialog)
1320 bool wxWindow::TransferDataToWindow()
1322 wxNode
*node
= GetChildren()->First();
1325 wxWindow
*child
= (wxWindow
*)node
->Data();
1326 if ( child
->GetValidator() &&
1327 !child
->GetValidator()->TransferToWindow() )
1329 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1333 node
= node
->Next();
1338 // Transfer values from controls. If returns FALSE,
1339 // validation failed: don't quit
1340 bool wxWindow::TransferDataFromWindow()
1342 wxNode
*node
= GetChildren()->First();
1345 wxWindow
*child
= (wxWindow
*)node
->Data();
1346 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1351 node
= node
->Next();
1356 bool wxWindow::Validate()
1358 wxNode
*node
= GetChildren()->First();
1361 wxWindow
*child
= (wxWindow
*)node
->Data();
1362 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1367 node
= node
->Next();
1372 // Get the window with the focus
1373 wxWindow
*wxWindow::FindFocus()
1379 void wxWindow::AddChild(wxWindow
*child
)
1381 GetChildren()->Append(child
);
1382 child
->m_windowParent
= this;
1385 void wxWindow::RemoveChild(wxWindow
*child
)
1388 GetChildren()->DeleteObject(child
);
1389 child
->m_windowParent
= NULL
;
1392 void wxWindow::DestroyChildren()
1396 wxNode
*node
= GetChildren()->First();
1399 wxNode
* next
= node
->Next();
1400 wxWindow
* child
= (wxWindow
*) node
->Data();
1404 GetChildren()->Clear();
1407 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1409 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1411 if ( GetChildren()->Member(child
) )
1419 void wxWindow::MakeModal(bool modal
)
1421 // Disable all other windows
1422 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1424 wxNode
*node
= wxTopLevelWindows
.First();
1427 wxWindow
*win
= (wxWindow
*)node
->Data();
1429 win
->Enable(!modal
);
1431 node
= node
->Next();
1436 // If nothing defined for this, try the parent.
1437 // E.g. we may be a button loaded from a resource, with no callback function
1439 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1441 if (GetEventHandler()->ProcessEvent(event
) )
1444 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1447 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1451 UnsetConstraints(m_constraints
);
1452 delete m_constraints
;
1457 // Make sure other windows know they're part of a 'meaningful relationship'
1458 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1459 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1460 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1461 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1462 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1463 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1464 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1465 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1466 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1467 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1468 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1469 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1470 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1471 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1472 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1473 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1477 // This removes any dangling pointers to this window
1478 // in other windows' constraintsInvolvedIn lists.
1479 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1483 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1484 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1485 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1486 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1487 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1488 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1489 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1490 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1491 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1492 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1493 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1494 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1495 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1496 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1497 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1498 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1502 // Back-pointer to other windows we're involved with, so if we delete
1503 // this window, we must delete any constraints we're involved with.
1504 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1506 if (!m_constraintsInvolvedIn
)
1507 m_constraintsInvolvedIn
= new wxList
;
1508 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1509 m_constraintsInvolvedIn
->Append(otherWin
);
1512 // REMOVE back-pointer to other windows we're involved with.
1513 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1515 if (m_constraintsInvolvedIn
)
1516 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1519 // Reset any constraints that mention this window
1520 void wxWindow::DeleteRelatedConstraints()
1522 if (m_constraintsInvolvedIn
)
1524 wxNode
*node
= m_constraintsInvolvedIn
->First();
1527 wxWindow
*win
= (wxWindow
*)node
->Data();
1528 wxNode
*next
= node
->Next();
1529 wxLayoutConstraints
*constr
= win
->GetConstraints();
1531 // Reset any constraints involving this window
1534 constr
->left
.ResetIfWin((wxWindow
*)this);
1535 constr
->top
.ResetIfWin((wxWindow
*)this);
1536 constr
->right
.ResetIfWin((wxWindow
*)this);
1537 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1538 constr
->width
.ResetIfWin((wxWindow
*)this);
1539 constr
->height
.ResetIfWin((wxWindow
*)this);
1540 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1541 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1546 delete m_constraintsInvolvedIn
;
1547 m_constraintsInvolvedIn
= NULL
;
1551 void wxWindow::SetSizer(wxSizer
*sizer
)
1553 m_windowSizer
= sizer
;
1555 sizer
->SetSizerParent((wxWindow
*)this);
1562 bool wxWindow::Layout()
1564 if (GetConstraints())
1567 GetClientSize(&w
, &h
);
1568 GetConstraints()->width
.SetValue(w
);
1569 GetConstraints()->height
.SetValue(h
);
1572 // If top level (one sizer), evaluate the sizer's constraints.
1576 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1577 GetSizer()->LayoutPhase1(&noChanges
);
1578 GetSizer()->LayoutPhase2(&noChanges
);
1579 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1584 // Otherwise, evaluate child constraints
1585 ResetConstraints(); // Mark all constraints as unevaluated
1586 DoPhase(1); // Just one phase need if no sizers involved
1588 SetConstraintSizes(); // Recursively set the real window sizes
1594 // Do a phase of evaluating constraints:
1595 // the default behaviour. wxSizers may do a similar
1596 // thing, but also impose their own 'constraints'
1597 // and order the evaluation differently.
1598 bool wxWindow::LayoutPhase1(int *noChanges
)
1600 wxLayoutConstraints
*constr
= GetConstraints();
1603 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1609 bool wxWindow::LayoutPhase2(int *noChanges
)
1619 // Do a phase of evaluating child constraints
1620 bool wxWindow::DoPhase(int phase
)
1622 int noIterations
= 0;
1623 int maxIterations
= 500;
1627 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1631 wxNode
*node
= GetChildren()->First();
1634 wxWindow
*child
= (wxWindow
*)node
->Data();
1635 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1637 wxLayoutConstraints
*constr
= child
->GetConstraints();
1640 if (succeeded
.Member(child
))
1645 int tempNoChanges
= 0;
1646 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1647 noChanges
+= tempNoChanges
;
1650 succeeded
.Append(child
);
1655 node
= node
->Next();
1662 void wxWindow::ResetConstraints()
1664 wxLayoutConstraints
*constr
= GetConstraints();
1667 constr
->left
.SetDone(FALSE
);
1668 constr
->top
.SetDone(FALSE
);
1669 constr
->right
.SetDone(FALSE
);
1670 constr
->bottom
.SetDone(FALSE
);
1671 constr
->width
.SetDone(FALSE
);
1672 constr
->height
.SetDone(FALSE
);
1673 constr
->centreX
.SetDone(FALSE
);
1674 constr
->centreY
.SetDone(FALSE
);
1676 wxNode
*node
= GetChildren()->First();
1679 wxWindow
*win
= (wxWindow
*)node
->Data();
1680 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1681 win
->ResetConstraints();
1682 node
= node
->Next();
1686 // Need to distinguish between setting the 'fake' size for
1687 // windows and sizers, and setting the real values.
1688 void wxWindow::SetConstraintSizes(bool recurse
)
1690 wxLayoutConstraints
*constr
= GetConstraints();
1691 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1692 constr
->width
.GetDone() && constr
->height
.GetDone())
1694 int x
= constr
->left
.GetValue();
1695 int y
= constr
->top
.GetValue();
1696 int w
= constr
->width
.GetValue();
1697 int h
= constr
->height
.GetValue();
1699 // If we don't want to resize this window, just move it...
1700 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1701 (constr
->height
.GetRelationship() != wxAsIs
))
1703 // Calls Layout() recursively. AAAGH. How can we stop that.
1704 // Simply take Layout() out of non-top level OnSizes.
1705 SizerSetSize(x
, y
, w
, h
);
1714 char *windowClass
= this->GetClassInfo()->GetClassName();
1717 if (GetName() == "")
1718 winName
= "unnamed";
1720 winName
= GetName();
1721 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1722 if (!constr
->left
.GetDone())
1723 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1724 if (!constr
->right
.GetDone())
1725 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1726 if (!constr
->width
.GetDone())
1727 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1728 if (!constr
->height
.GetDone())
1729 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1730 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1735 wxNode
*node
= GetChildren()->First();
1738 wxWindow
*win
= (wxWindow
*)node
->Data();
1739 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1740 win
->SetConstraintSizes();
1741 node
= node
->Next();
1746 // This assumes that all sizers are 'on' the same
1747 // window, i.e. the parent of this window.
1748 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1750 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1751 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1755 m_sizerParent
->GetPosition(&xp
, &yp
);
1756 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1761 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1765 TransformSizerToActual(&xx
, &yy
);
1766 SetSize(xx
, yy
, w
, h
);
1769 void wxWindow::SizerMove(int x
, int y
)
1773 TransformSizerToActual(&xx
, &yy
);
1777 // Only set the size/position of the constraint (if any)
1778 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1780 wxLayoutConstraints
*constr
= GetConstraints();
1785 constr
->left
.SetValue(x
);
1786 constr
->left
.SetDone(TRUE
);
1790 constr
->top
.SetValue(y
);
1791 constr
->top
.SetDone(TRUE
);
1795 constr
->width
.SetValue(w
);
1796 constr
->width
.SetDone(TRUE
);
1800 constr
->height
.SetValue(h
);
1801 constr
->height
.SetDone(TRUE
);
1806 void wxWindow::MoveConstraint(int x
, int y
)
1808 wxLayoutConstraints
*constr
= GetConstraints();
1813 constr
->left
.SetValue(x
);
1814 constr
->left
.SetDone(TRUE
);
1818 constr
->top
.SetValue(y
);
1819 constr
->top
.SetDone(TRUE
);
1824 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1826 wxLayoutConstraints
*constr
= GetConstraints();
1829 *w
= constr
->width
.GetValue();
1830 *h
= constr
->height
.GetValue();
1836 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1838 wxLayoutConstraints
*constr
= GetConstraints();
1841 *w
= constr
->width
.GetValue();
1842 *h
= constr
->height
.GetValue();
1845 GetClientSize(w
, h
);
1848 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1850 wxLayoutConstraints
*constr
= GetConstraints();
1853 *x
= constr
->left
.GetValue();
1854 *y
= constr
->top
.GetValue();
1860 bool wxWindow::Close(bool force
)
1862 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1863 event
.SetEventObject(this);
1864 event
.SetForce(force
);
1866 return GetEventHandler()->ProcessEvent(event
);
1869 wxObject
* wxWindow::GetChild(int number
) const
1871 // Return a pointer to the Nth object in the window
1874 wxNode
*node
= GetChildren()->First();
1877 node
= node
->Next() ;
1880 wxObject
*obj
= (wxObject
*)node
->Data();
1887 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1889 // Obsolete function
1892 void wxWindow::Clear()
1894 wxClientDC
dc(this);
1895 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1896 dc
.SetBackground(brush
);
1900 // Fits the panel around the items
1901 void wxWindow::Fit()
1905 wxNode
*node
= GetChildren()->First();
1908 wxWindow
*win
= (wxWindow
*)node
->Data();
1910 win
->GetPosition(&wx
, &wy
);
1911 win
->GetSize(&ww
, &wh
);
1912 if ( wx
+ ww
> maxX
)
1914 if ( wy
+ wh
> maxY
)
1917 node
= node
->Next();
1919 SetClientSize(maxX
+ 5, maxY
+ 5);
1922 void wxWindow::SetValidator(const wxValidator
& validator
)
1924 if ( m_windowValidator
)
1925 delete m_windowValidator
;
1926 m_windowValidator
= validator
.Clone();
1928 if ( m_windowValidator
)
1929 m_windowValidator
->SetWindow(this) ;
1932 void wxWindow::SetClientObject( wxClientData
*data
)
1934 if (m_clientObject
) delete m_clientObject
;
1935 m_clientObject
= data
;
1938 wxClientData
*wxWindow::GetClientObject()
1940 return m_clientObject
;
1943 void wxWindow::SetClientData( void *data
)
1945 m_clientData
= data
;
1948 void *wxWindow::GetClientData()
1950 return m_clientData
;
1953 // Find a window by id or name
1954 wxWindow
*wxWindow::FindWindow(long id
)
1959 wxNode
*node
= GetChildren()->First();
1962 wxWindow
*child
= (wxWindow
*)node
->Data();
1963 wxWindow
*found
= child
->FindWindow(id
);
1966 node
= node
->Next();
1971 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1973 if ( GetName() == name
)
1976 wxNode
*node
= GetChildren()->First();
1979 wxWindow
*child
= (wxWindow
*)node
->Data();
1980 wxWindow
*found
= child
->FindWindow(name
);
1983 node
= node
->Next();
1988 void wxWindow::OnIdle(wxIdleEvent
& event
)
1990 // This calls the UI-update mechanism (querying windows for
1991 // menu/toolbar/control state information)
1995 // Raise the window to the top of the Z order
1996 void wxWindow::Raise()
1998 Window window
= XtWindow((Widget
) GetTopWidget());
1999 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2002 // Lower the window to the bottom of the Z order
2003 void wxWindow::Lower()
2005 Window window
= XtWindow((Widget
) GetTopWidget());
2006 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2009 bool wxWindow::AcceptsFocus() const
2011 return IsShown() && IsEnabled();
2014 // Update region access
2015 wxRegion
& wxWindow::GetUpdateRegion() const
2017 return (wxRegion
&) m_updateRegion
;
2020 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2022 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2025 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2027 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2030 bool wxWindow::IsExposed(const wxRect
& rect
) const
2032 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2036 * Allocates control IDs
2039 int wxWindow::NewControlId()
2041 static int s_controlId
= 0;
2046 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2048 m_acceleratorTable
= accel
;
2051 // All widgets should have this as their resize proc.
2052 // OnSize sent to wxWindow via client data.
2053 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2055 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2059 if (win
->PreResize())
2062 win
->GetSize(&width
, &height
);
2063 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2064 sizeEvent
.SetEventObject(win
);
2065 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2069 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2071 wxWindow
*oldItem
= NULL
;
2072 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2073 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2076 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2079 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2084 wxWidgetHashTable
->Put ((long) w
, win
);
2088 wxWindow
*wxGetWindowFromTable(Widget w
)
2090 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2093 void wxDeleteWindowFromTable(Widget w
)
2095 wxWidgetHashTable
->Delete((long)w
);
2098 // Get the underlying X window and display
2099 WXWindow
wxWindow::GetXWindow() const
2101 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2104 WXDisplay
*wxWindow::GetXDisplay() const
2106 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2109 WXWidget
wxWindow::GetMainWidget() const
2112 return m_drawingArea
;
2114 return m_mainWidget
;
2117 WXWidget
wxWindow::GetClientWidget() const
2119 if (m_drawingArea
!= (WXWidget
) 0)
2120 return m_drawingArea
;
2122 return GetMainWidget();
2125 WXWidget
wxWindow::GetTopWidget() const
2127 return GetMainWidget();
2130 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2131 XmDrawingAreaCallbackStruct
* cbs
)
2133 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2136 XEvent
* event
= cbs
->event
;
2137 wxWindow
* win
= (wxWindow
*) clientData
;
2138 Display
* display
= (Display
*) win
->GetXDisplay();
2140 switch (event
->type
)
2144 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2145 event
->xexpose
.width
, event
->xexpose
.height
);
2147 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2148 cout << rect->width << ", " << rect->height << "\n\n";
2151 win
->m_updateRects
.Append((wxObject
*) rect
);
2153 if (event
-> xexpose
.count
== 0)
2155 wxPaintEvent
event(win
->GetId());
2156 event
.SetEventObject(win
);
2157 win
->GetEventHandler()->ProcessEvent(event
);
2159 win
->ClearUpdateRects();
2165 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2171 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2173 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2175 XmDrawingAreaCallbackStruct cbs
;
2178 //if (event->mode!=NotifyNormal)
2181 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2182 ((XCrossingEvent
&) ev
) = *event
;
2184 cbs
.reason
= XmCR_INPUT
;
2187 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2190 // Fix to make it work under Motif 1.0 (!)
2191 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2195 XmDrawingAreaCallbackStruct cbs
;
2198 //ev.xbutton = *event;
2199 ev
= *((XEvent
*) event
);
2200 cbs
.reason
= XmCR_INPUT
;
2203 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2207 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2209 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2215 if (cbs
->reason
!= XmCR_INPUT
)
2218 local_event
= *(cbs
->event
); // We must keep a copy!
2221 switch (local_event.xany.type)
2224 cout << "EnterNotify\n";
2227 cout << "LeaveNotify\n";
2230 cout << "ButtonPress\n";
2233 cout << "ButtonRelease\n";
2236 cout << "MotionNotify\n";
2239 cout << "Something else\n";
2244 switch (local_event
.xany
.type
)
2252 wxEventType eventType
= wxEVT_NULL
;
2254 if (local_event
.xany
.type
== EnterNotify
)
2256 //if (local_event.xcrossing.mode!=NotifyNormal)
2257 // return ; // Ignore grab events
2258 eventType
= wxEVT_ENTER_WINDOW
;
2259 // canvas->GetEventHandler()->OnSetFocus();
2261 else if (local_event
.xany
.type
== LeaveNotify
)
2263 //if (local_event.xcrossing.mode!=NotifyNormal)
2264 // return ; // Ignore grab events
2265 eventType
= wxEVT_LEAVE_WINDOW
;
2266 // canvas->GetEventHandler()->OnKillFocus();
2268 else if (local_event
.xany
.type
== MotionNotify
)
2270 eventType
= wxEVT_MOTION
;
2271 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2274 Display
*dpy
= XtDisplay (drawingArea
);
2276 XQueryPointer (dpy
, XtWindow (drawingArea
),
2278 &local_event
.xmotion
.x_root
,
2279 &local_event
.xmotion
.y_root
,
2280 &local_event
.xmotion
.x
,
2281 &local_event
.xmotion
.y
,
2282 &local_event
.xmotion
.state
);
2289 else if (local_event
.xany
.type
== ButtonPress
)
2291 if (local_event
.xbutton
.button
== Button1
)
2293 eventType
= wxEVT_LEFT_DOWN
;
2294 canvas
->m_button1Pressed
= TRUE
;
2296 else if (local_event
.xbutton
.button
== Button2
)
2298 eventType
= wxEVT_MIDDLE_DOWN
;
2299 canvas
->m_button2Pressed
= TRUE
;
2301 else if (local_event
.xbutton
.button
== Button3
)
2303 eventType
= wxEVT_RIGHT_DOWN
;
2304 canvas
->m_button3Pressed
= TRUE
;
2307 else if (local_event
.xany
.type
== ButtonRelease
)
2309 if (local_event
.xbutton
.button
== Button1
)
2311 eventType
= wxEVT_LEFT_UP
;
2312 canvas
->m_button1Pressed
= FALSE
;
2314 else if (local_event
.xbutton
.button
== Button2
)
2316 eventType
= wxEVT_MIDDLE_UP
;
2317 canvas
->m_button2Pressed
= FALSE
;
2319 else if (local_event
.xbutton
.button
== Button3
)
2321 eventType
= wxEVT_RIGHT_UP
;
2322 canvas
->m_button3Pressed
= FALSE
;
2326 wxMouseEvent
wxevent (eventType
);
2327 wxevent
.m_eventHandle
= (char *) &local_event
;
2329 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2330 || (event_left_is_down (&local_event
)
2331 && (eventType
!= wxEVT_LEFT_UP
)));
2332 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2333 || (event_middle_is_down (&local_event
)
2334 && (eventType
!= wxEVT_MIDDLE_UP
)));
2335 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2336 || (event_right_is_down (&local_event
)
2337 && (eventType
!= wxEVT_RIGHT_UP
)));
2339 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2340 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2341 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2342 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2343 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2345 // Now check if we need to translate this event into a double click
2346 if (TRUE
) // canvas->doubleClickAllowed)
2348 if (wxevent
.ButtonDown())
2350 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2352 // get button and time-stamp
2354 if (wxevent
.LeftDown()) button
= 1;
2355 else if (wxevent
.MiddleDown()) button
= 2;
2356 else if (wxevent
.RightDown()) button
= 3;
2357 long ts
= wxevent
.GetTimestamp();
2358 // check, if single or double click
2359 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2362 canvas
->m_lastButton
= 0;
2363 switch ( eventType
)
2365 case wxEVT_LEFT_DOWN
:
2366 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2368 case wxEVT_MIDDLE_DOWN
:
2369 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2371 case wxEVT_RIGHT_DOWN
:
2372 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2382 // not fast enough or different button
2383 canvas
->m_lastTS
= ts
;
2384 canvas
->m_lastButton
= button
;
2389 wxevent
.SetId(canvas
->GetId());
2390 wxevent
.SetEventObject(canvas
);
2391 wxevent
.m_x
= local_event
.xbutton
.x
;
2392 wxevent
.m_y
= local_event
.xbutton
.y
;
2393 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2395 if (eventType == wxEVT_ENTER_WINDOW ||
2396 eventType == wxEVT_LEAVE_WINDOW ||
2397 eventType == wxEVT_MOTION
2406 // XComposeStatus compose;
2407 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2408 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2409 int id
= wxCharCodeXToWX (keySym
);
2411 wxKeyEvent
event (wxEVT_CHAR
);
2413 if (local_event
.xkey
.state
& ShiftMask
)
2414 event
.m_shiftDown
= TRUE
;
2415 if (local_event
.xkey
.state
& ControlMask
)
2416 event
.m_controlDown
= TRUE
;
2417 if (local_event
.xkey
.state
& Mod3Mask
)
2418 event
.m_altDown
= TRUE
;
2419 if (local_event
.xkey
.state
& Mod1Mask
)
2420 event
.m_metaDown
= TRUE
;
2421 event
.SetEventObject(canvas
);
2422 event
.m_keyCode
= id
;
2423 event
.SetTimestamp(local_event
.xkey
.time
);
2427 // Implement wxFrame::OnCharHook by checking ancestor.
2428 wxWindow
*parent
= canvas
->GetParent();
2429 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2430 parent
= parent
->GetParent();
2434 event
.SetEventType(wxEVT_CHAR_HOOK
);
2435 if (parent
->GetEventHandler()->ProcessEvent(event
))
2437 event
.SetEventType(wxEVT_CHAR
);
2440 canvas
->GetEventHandler()->ProcessEvent (event
);
2446 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2448 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2449 event
.SetEventObject(canvas
);
2450 canvas
->GetEventHandler()->ProcessEvent(event
);
2456 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2458 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2459 event
.SetEventObject(canvas
);
2460 canvas
->GetEventHandler()->ProcessEvent(event
);
2469 void wxWindow::DoPaint()
2471 //TODO : make a temporary gc so we can do the XCopyArea below
2472 if (0) // m_backingPixmap)
2475 Widget drawingArea = (Widget) m_drawingArea;
2476 // int orig = GetDC()->GetLogicalFunction();
2477 // GetDC()->SetLogicalFunction (wxCOPY);
2479 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2480 // should be able to calculate them.
2481 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2482 m_pixmapOffsetX, m_pixmapOffsetY,
2483 m_pixmapWidth, m_pixmapHeight,
2486 // GetDC()->SetLogicalFunction (orig);
2491 wxPaintEvent
event(GetId());
2492 event
.SetEventObject(this);
2493 GetEventHandler()->ProcessEvent(event
);
2497 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2498 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2500 Widget drawingArea
= (Widget
) m_drawingArea
;
2501 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2504 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2505 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2507 int xx
= x
; int yy
= y
;
2508 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2510 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2512 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2516 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2518 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2526 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2527 short thick
, margin
;
2528 XtVaGetValues ((Widget
) m_borderWidget
,
2529 XmNshadowThickness
, &thick
,
2530 XmNmarginWidth
, &margin
,
2532 w
-= 2 * (thick
+ margin
);
2535 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2539 XtVaGetValues ((Widget
) m_scrolledWindow
,
2540 XmNspacing
, &spacing
,
2541 XmNverticalScrollBar
, &sbar
,
2545 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2549 w
-= (spacing
+ wsbar
);
2551 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2557 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2558 short thick
, margin
;
2559 XtVaGetValues ((Widget
) m_borderWidget
,
2560 XmNshadowThickness
, &thick
,
2561 XmNmarginHeight
, &margin
,
2563 h
-= 2 * (thick
+ margin
);
2566 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2570 XtVaGetValues ((Widget
) m_scrolledWindow
,
2571 XmNspacing
, &spacing
,
2572 XmNhorizontalScrollBar
, &sbar
,
2576 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2580 h
-= (spacing
+ wsbar
);
2582 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2585 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2586 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2589 GetClientSize (&ww
, &hh
);
2590 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2591 sizeEvent
.SetEventObject(this);
2593 GetEventHandler()->ProcessEvent(sizeEvent
);
2596 void wxWindow::CanvasSetClientSize (int w
, int h
)
2598 Widget drawingArea
= (Widget
) m_drawingArea
;
2600 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2603 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2605 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2606 /* TODO: is this necessary?
2607 allowRepainting = FALSE;
2609 XSync (XtDisplay (drawingArea), FALSE);
2611 while (XtAppPending (wxTheApp->appContext))
2613 XFlush (XtDisplay (drawingArea));
2614 XtAppNextEvent (wxTheApp->appContext, &event);
2615 XtDispatchEvent (&event);
2619 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2622 allowRepainting = TRUE;
2626 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2627 sizeEvent
.SetEventObject(this);
2629 GetEventHandler()->ProcessEvent(sizeEvent
);
2632 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2634 // Must return the same thing that was set via SetClientSize
2636 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2641 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2644 if ((Widget
) m_borderWidget
)
2645 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2646 else if ((Widget
) m_scrolledWindow
)
2647 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2649 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2655 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2658 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2660 // We may be faking the client origin.
2661 // So a window that's really at (0, 30) may appear
2662 // (to wxWin apps) to be at (0, 0).
2665 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2674 // Add to hash table, add event handler
2675 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2676 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2678 wxAddWindowToTable((Widget
) mainWidget
, this);
2679 if (CanAddEventHandler())
2681 XtAddEventHandler((Widget
) mainWidget
,
2682 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2684 wxPanelItemEventHandler
,
2691 XtOverrideTranslations ((Widget
) mainWidget
,
2692 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2693 XtFree ((char *) ptr
);
2696 // Some widgets have a parent form widget, e.g. wxRadioBox
2699 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2703 XtOverrideTranslations ((Widget
) formWidget
,
2704 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2705 XtFree ((char *) ptr
);
2712 SetSize (x
, y
, width
, height
);
2717 // Remove event handler, remove from hash table
2718 bool wxWindow::DetachWidget(WXWidget widget
)
2720 if (CanAddEventHandler())
2722 XtRemoveEventHandler((Widget
) widget
,
2723 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2725 wxPanelItemEventHandler
,
2729 wxDeleteWindowFromTable((Widget
) widget
);
2733 void wxPanelItemEventHandler (Widget wid
,
2734 XtPointer client_data
,
2736 Boolean
*continueToDispatch
)
2738 // Widget can be a label or the actual widget.
2740 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2743 wxMouseEvent
wxevent(0);
2744 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2746 window
->GetEventHandler()->ProcessEvent(wxevent
);
2749 // TODO: probably the key to allowing default behaviour
2751 // Say we set a m_doDefault flag to FALSE at the start of this
2752 // function. Then in e.g. wxWindow::OnMouseEvent we can
2753 // call Default() which sets this flag to TRUE, indicating
2754 // that default processing can happen. Thus, behaviour can appear
2755 // to be overridden just by adding an event handler and not calling
2756 // wxWindow::OnWhatever.
2757 // ALSO, maybe we can use this instead of the current way of handling
2758 // drawing area events, to simplify things.
2759 *continueToDispatch
= True
;
2762 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2763 XmScaleCallbackStruct
*cbs
)
2765 Widget scrolledWindow
= XtParent (scrollbar
);
2766 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2767 int orientation
= (int) clientData
;
2769 wxEventType eventType
= wxEVT_NULL
;
2770 switch (cbs
->reason
)
2772 case XmCR_INCREMENT
:
2774 eventType
= wxEVT_SCROLL_LINEDOWN
;
2777 case XmCR_DECREMENT
:
2779 eventType
= wxEVT_SCROLL_LINEUP
;
2784 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2787 case XmCR_VALUE_CHANGED
:
2789 // TODO: Should this be intercepted too, or will it cause
2790 // duplicate events?
2791 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2794 case XmCR_PAGE_INCREMENT
:
2796 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2799 case XmCR_PAGE_DECREMENT
:
2801 eventType
= wxEVT_SCROLL_PAGEUP
;
2806 eventType
= wxEVT_SCROLL_TOP
;
2809 case XmCR_TO_BOTTOM
:
2811 eventType
= wxEVT_SCROLL_BOTTOM
;
2816 // Should never get here
2817 wxFAIL_MSG("Unknown scroll event.");
2822 wxScrollEvent
event(eventType
, win
->GetId());
2823 event
.SetEventObject(win
);
2824 event
.SetPosition(cbs
->value
);
2825 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2827 win
->GetEventHandler()->ProcessEvent(event
);
2830 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2832 switch (xevent
->xany
.type
)
2840 wxEventType eventType
= wxEVT_NULL
;
2842 if (xevent
->xany
.type
== LeaveNotify
)
2844 win
->m_button1Pressed
= FALSE
;
2845 win
->m_button2Pressed
= FALSE
;
2846 win
->m_button3Pressed
= FALSE
;
2849 else if (xevent
->xany
.type
== MotionNotify
)
2851 eventType
= wxEVT_MOTION
;
2853 else if (xevent
->xany
.type
== ButtonPress
)
2855 if (xevent
->xbutton
.button
== Button1
)
2857 eventType
= wxEVT_LEFT_DOWN
;
2858 win
->m_button1Pressed
= TRUE
;
2860 else if (xevent
->xbutton
.button
== Button2
)
2862 eventType
= wxEVT_MIDDLE_DOWN
;
2863 win
->m_button2Pressed
= TRUE
;
2865 else if (xevent
->xbutton
.button
== Button3
)
2867 eventType
= wxEVT_RIGHT_DOWN
;
2868 win
->m_button3Pressed
= TRUE
;
2871 else if (xevent
->xany
.type
== ButtonRelease
)
2873 if (xevent
->xbutton
.button
== Button1
)
2875 eventType
= wxEVT_LEFT_UP
;
2876 win
->m_button1Pressed
= FALSE
;
2878 else if (xevent
->xbutton
.button
== Button2
)
2880 eventType
= wxEVT_MIDDLE_UP
;
2881 win
->m_button2Pressed
= FALSE
;
2883 else if (xevent
->xbutton
.button
== Button3
)
2885 eventType
= wxEVT_RIGHT_UP
;
2886 win
->m_button3Pressed
= FALSE
;
2892 wxevent
.m_eventHandle
= (char *)xevent
;
2893 wxevent
.SetEventType(eventType
);
2896 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2899 win
->GetPosition(&x2
, &y2
);
2901 // The button x/y must be translated to wxWindows
2902 // window space - the widget might be a label or button,
2906 if (widget
!= (Widget
)win
->GetMainWidget())
2912 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2913 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2915 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2916 || (event_left_is_down (xevent
)
2917 && (eventType
!= wxEVT_LEFT_UP
)));
2918 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2919 || (event_middle_is_down (xevent
)
2920 && (eventType
!= wxEVT_MIDDLE_UP
)));
2921 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2922 || (event_right_is_down (xevent
)
2923 && (eventType
!= wxEVT_RIGHT_UP
)));
2925 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2926 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2933 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2935 switch (xevent
->xany
.type
)
2942 // XComposeStatus compose;
2943 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2944 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2945 int id
= wxCharCodeXToWX (keySym
);
2947 if (xevent
->xkey
.state
& ShiftMask
)
2948 wxevent
.m_shiftDown
= TRUE
;
2949 if (xevent
->xkey
.state
& ControlMask
)
2950 wxevent
.m_controlDown
= TRUE
;
2951 if (xevent
->xkey
.state
& Mod3Mask
)
2952 wxevent
.m_altDown
= TRUE
;
2953 if (xevent
->xkey
.state
& Mod1Mask
)
2954 wxevent
.m_metaDown
= TRUE
;
2955 wxevent
.SetEventObject(win
);
2956 wxevent
.m_keyCode
= id
;
2957 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2959 wxevent
.m_x
= xevent
->xbutton
.x
;
2960 wxevent
.m_y
= xevent
->xbutton
.y
;
2974 #define YAllocColor XAllocColor
2975 XColor g_itemColors
[5];
2976 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2979 static XmColorProc colorProc
;
2981 result
= wxNO_COLORS
;
2985 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
2986 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
2987 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2988 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2989 if (colorProc
== (XmColorProc
) NULL
)
2991 // Get a ptr to the actual function
2992 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2993 // And set it back to motif.
2994 XmSetColorCalculation (colorProc
);
2996 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
2997 &g_itemColors
[wxFORE_INDEX
],
2998 &g_itemColors
[wxSELE_INDEX
],
2999 &g_itemColors
[wxTOPS_INDEX
],
3000 &g_itemColors
[wxBOTS_INDEX
]);
3001 result
= wxBACK_COLORS
;
3005 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3006 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3007 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3008 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3009 if (result
== wxNO_COLORS
)
3010 result
= wxFORE_COLORS
;
3013 Display
*dpy
= display
;
3014 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3018 /* 5 Colours to allocate */
3019 for (int i
= 0; i
< 5; i
++)
3020 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3021 result
= wxNO_COLORS
;
3025 /* Only 1 colour to allocate */
3026 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3027 result
= wxNO_COLORS
;
3034 // Changes the foreground and background colours to be derived
3035 // from the current background colour.
3036 // To change the foreground colour, you must call SetForegroundColour
3038 void wxWindow::ChangeBackgroundColour()
3040 if (GetMainWidget())
3041 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3044 void wxWindow::ChangeForegroundColour()
3046 if (GetMainWidget())
3047 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3050 // Change a widget's foreground and background colours.
3052 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3054 // When should we specify the foreground, if it's calculated
3055 // by wxComputeColours?
3056 // Solution: say we start with the default (computed) foreground colour.
3057 // If we call SetForegroundColour explicitly for a control or window,
3058 // then the foreground is changed.
3059 // Therefore SetBackgroundColour computes the foreground colour, and
3060 // SetForegroundColour changes the foreground colour. The ordering is
3063 XtVaSetValues ((Widget
) widget
,
3064 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3068 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3070 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3073 XtVaSetValues ((Widget
) widget
,
3074 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3075 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3076 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3077 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3080 if (changeArmColour
)
3081 XtVaSetValues ((Widget
) widget
,
3082 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3086 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3088 m_backgroundColour
= col
;
3089 ChangeBackgroundColour();
3092 void wxWindow::SetForegroundColour(const wxColour
& col
)
3094 m_foregroundColour
= col
;
3095 ChangeForegroundColour();
3098 void wxWindow::ChangeFont(bool keepOriginalSize
)
3100 // Note that this causes the widget to be resized back
3101 // to its original size! We therefore have to set the size
3102 // back again. TODO: a better way in Motif?
3103 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3104 if (w
&& m_windowFont
.Ok())
3106 int width
, height
, width1
, height1
;
3107 GetSize(& width
, & height
);
3110 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3113 GetSize(& width1
, & height1
);
3114 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3116 SetSize(-1, -1, width
, height
);
3121 void wxWindow::SetFont(const wxFont
& font
)
3123 m_windowFont
= font
;
3127 void wxWindow::ClearUpdateRects()
3129 wxNode
* node
= m_updateRects
.First();
3132 wxRect
* rect
= (wxRect
*) node
->Data();
3134 node
= node
->Next();
3136 m_updateRects
.Clear();
3139 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3141 if (!m_acceleratorTable
.Ok())
3144 int count
= m_acceleratorTable
.GetCount();
3145 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3147 for (i
= 0; i
< count
; i
++)
3149 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3150 if (entry
->MatchesEvent(event
))
3152 // Bingo, we have a match. Now find a control
3153 // that matches the entry command id.
3155 // Need to go up to the top of the window hierarchy,
3156 // since it might be e.g. a menu item
3157 wxWindow
* parent
= this;
3158 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3159 parent
= parent
->GetParent();
3164 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3166 // Try for a menu command
3167 wxFrame
* frame
= (wxFrame
*) parent
;
3168 if (frame
->GetMenuBar())
3170 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3173 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3174 commandEvent
.SetEventObject(frame
);
3176 // If ProcessEvent returns TRUE (it was handled), then
3177 // the calling code will skip the event handling.
3178 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3183 // Find a child matching the command id
3184 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3190 // Now we process those kinds of windows that we can.
3191 // For now, only buttons.
3192 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3194 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3195 commandEvent
.SetEventObject(child
);
3196 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3203 // We didn't match the key event against an accelerator.