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
;
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
;
138 m_paintRegion
= (WXRegion
) 0;
142 wxWindow::~wxWindow()
147 XDestroyRegion ((Region
) m_paintRegion
);
148 m_paintRegion
= (WXRegion
) 0;
151 DetachWidget(GetMainWidget()); // Removes event handlers
153 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
156 // Destroy children before destroying self
160 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
162 Widget w
= (Widget
) m_drawingArea
;
163 wxDeleteWindowFromTable(w
);
167 m_mainWidget
= (WXWidget
) 0;
169 // Only if we're _really_ a canvas (not a dialog box/panel)
170 if (m_scrolledWindow
)
172 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
177 XtUnmanageChild ((Widget
) m_hScrollBar
);
178 XtDestroyWidget ((Widget
) m_hScrollBar
);
182 XtUnmanageChild ((Widget
) m_vScrollBar
);
183 XtDestroyWidget ((Widget
) m_vScrollBar
);
185 if (m_scrolledWindow
)
187 XtUnmanageChild ((Widget
) m_scrolledWindow
);
188 XtDestroyWidget ((Widget
) m_scrolledWindow
);
193 XtDestroyWidget ((Widget
) m_borderWidget
);
194 m_borderWidget
= (WXWidget
) 0;
200 // Have to delete constraints/sizer FIRST otherwise
201 // sizers may try to look at deleted windows as they
202 // delete themselves.
203 #if wxUSE_CONSTRAINTS
204 DeleteRelatedConstraints();
207 // This removes any dangling pointers to this window
208 // in other windows' constraintsInvolvedIn lists.
209 UnsetConstraints(m_constraints
);
210 delete m_constraints
;
211 m_constraints
= NULL
;
215 delete m_windowSizer
;
216 m_windowSizer
= NULL
;
218 // If this is a child of a sizer, remove self from parent
220 m_sizerParent
->RemoveChild((wxWindow
*)this);
224 m_windowParent
->RemoveChild(this);
228 // Destroy the window
231 wxDeleteWindowFromTable((Widget
) GetMainWidget());
232 XtDestroyWidget((Widget
) GetMainWidget());
233 SetMainWidget((WXWidget
) NULL
);
239 // Just in case the window has been Closed, but
240 // we're then deleting immediately: don't leave
241 // dangling pointers.
242 wxPendingDelete
.DeleteObject(this);
244 if ( m_windowValidator
) delete m_windowValidator
;
245 if (m_clientObject
) delete m_clientObject
;
248 // Destroy the window (delayed, if a managed window)
249 bool wxWindow::Destroy()
256 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
260 const wxString
& name
)
265 m_windowParent
= NULL
;
266 m_windowEventHandler
= this;
268 m_windowCursor
= *wxSTANDARD_CURSOR
;
269 m_constraints
= NULL
;
270 m_constraintsInvolvedIn
= NULL
;
271 m_windowSizer
= NULL
;
272 m_sizerParent
= NULL
;
273 m_autoLayout
= FALSE
;
274 m_windowValidator
= NULL
;
275 #if wxUSE_DRAG_AND_DROP
276 m_pDropTarget
= NULL
;
278 m_caretWidth
= 0; m_caretHeight
= 0;
279 m_caretEnabled
= FALSE
;
280 m_caretShown
= FALSE
;
285 m_defaultItem
= NULL
;
286 m_windowParent
= NULL
;
287 m_clientObject
= (wxClientData
*) NULL
;
291 m_canAddEventHandler
= FALSE
;
292 m_mainWidget
= (WXWidget
) 0;
293 m_button1Pressed
= FALSE
;
294 m_button2Pressed
= FALSE
;
295 m_button3Pressed
= FALSE
;
296 m_winCaptured
= FALSE
;
298 m_hScrollBar
= (WXWidget
) 0;
299 m_vScrollBar
= (WXWidget
) 0;
300 m_borderWidget
= (WXWidget
) 0;
301 m_scrolledWindow
= (WXWidget
) 0;
302 m_drawingArea
= (WXWidget
) 0;
305 m_backingPixmap
= (WXPixmap
) 0;
312 m_paintRegion
= (WXRegion
) 0;
317 if (parent
) parent
->AddChild(this);
324 m_windowId
= (int)NewControlId();
328 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
329 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
330 m_foregroundColour
= *wxBLACK
;
332 m_windowStyle
= style
;
335 m_windowId
= (int)NewControlId();
339 //// TODO: we should probably optimize by only creating a
340 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
341 //// But for now, let's simplify things by always creating the
342 //// drawing area, since otherwise the translations are different.
344 // New translations for getting mouse motion feedback
345 String translations
=
346 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
347 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
348 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
349 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
350 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
351 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
352 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
353 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
354 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
355 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
356 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
357 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
358 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
359 <Key>: DrawingAreaInput()";
361 XtActionsRec actions
[1];
362 actions
[0].string
= "wxCanvasMotionEvent";
363 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
364 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
366 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
367 if (style
& wxBORDER
)
368 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
369 xmFrameWidgetClass
, parentWidget
,
370 XmNshadowType
, XmSHADOW_IN
,
373 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
374 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
376 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
380 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
381 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
382 XmNunitType
, XmPIXELS
,
383 // XmNresizePolicy, XmRESIZE_ANY,
384 XmNresizePolicy
, XmRESIZE_NONE
,
387 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
390 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
392 XtFree ((char *) ptr);
393 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
394 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
395 XtFree ((char *) ptr);
399 wxAddWindowToTable((Widget
) m_drawingArea
, this);
400 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
403 * This order is very important in Motif 1.2.1
407 XtRealizeWidget ((Widget
) m_scrolledWindow
);
408 XtRealizeWidget ((Widget
) m_drawingArea
);
409 XtManageChild ((Widget
) m_drawingArea
);
411 XtOverrideTranslations ((Widget
) m_drawingArea
,
412 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
413 XtFree ((char *) ptr
);
415 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
416 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
419 display = XtDisplay (scrolledWindow);
420 xwindow = XtWindow (drawingArea);
423 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
424 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
426 // Add scrollbars if required
427 if (m_windowStyle
& wxHSCROLL
)
429 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
430 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
431 XmNorientation
, XmHORIZONTAL
,
433 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
434 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
435 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
436 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
437 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
438 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
439 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
440 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
442 XtVaSetValues (hScrollBar
,
447 m_hScrollBar
= (WXWidget
) hScrollBar
;
450 if (m_windowStyle
& wxVSCROLL
)
452 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
453 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
454 XmNorientation
, XmVERTICAL
,
456 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
457 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
458 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
459 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
460 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
461 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
462 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
463 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
465 XtVaSetValues (vScrollBar
,
470 m_vScrollBar
= (WXWidget
) vScrollBar
;
474 if (m_hScrollBar
|| m_vScrollBar
)
475 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
478 XtRealizeWidget ((Widget
) m_hScrollBar
);
480 XtRealizeWidget ((Widget
) m_vScrollBar
);
482 // Without this, the cursor may not be restored properly
483 // (e.g. in splitter sample).
484 SetCursor(*wxSTANDARD_CURSOR
);
485 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
490 void wxWindow::SetFocus()
492 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
493 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
496 void wxWindow::Enable(bool enable
)
500 XtSetSensitive((Widget
) GetMainWidget(), enable
);
501 XmUpdateDisplay((Widget
) GetMainWidget());
505 void wxWindow::CaptureMouse()
511 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
513 m_winCaptured
= TRUE
;
516 void wxWindow::ReleaseMouse()
522 XtRemoveGrab((Widget
) GetMainWidget());
523 m_winCaptured
= FALSE
;
526 // Push/pop event handler (i.e. allow a chain of event handlers
528 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
530 handler
->SetNextHandler(GetEventHandler());
531 SetEventHandler(handler
);
534 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
536 if ( GetEventHandler() )
538 wxEvtHandler
*handlerA
= GetEventHandler();
539 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
540 handlerA
->SetNextHandler(NULL
);
541 SetEventHandler(handlerB
);
554 #if wxUSE_DRAG_AND_DROP
556 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
558 if ( m_pDropTarget
!= 0 ) {
559 delete m_pDropTarget
;
562 m_pDropTarget
= pDropTarget
;
563 if ( m_pDropTarget
!= 0 )
571 // Old style file-manager drag&drop
572 void wxWindow::DragAcceptFiles(bool accept
)
578 void wxWindow::GetSize(int *x
, int *y
) const
586 Widget widget
= (Widget
) GetTopWidget();
588 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
592 void wxWindow::GetPosition(int *x
, int *y
) const
596 CanvasGetPosition(x
, y
);
599 Widget widget
= (Widget
) GetTopWidget();
601 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
603 // We may be faking the client origin.
604 // So a window that's really at (0, 30) may appear
605 // (to wxWin apps) to be at (0, 0).
608 wxPoint
pt(GetParent()->GetClientAreaOrigin());
616 void wxWindow::ScreenToClient(int *x
, int *y
) const
618 Widget widget
= (Widget
) GetClientWidget();
619 Display
*display
= XtDisplay((Widget
) GetMainWidget());
620 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
621 Window thisWindow
= XtWindow(widget
);
626 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
629 void wxWindow::ClientToScreen(int *x
, int *y
) const
631 Widget widget
= (Widget
) GetClientWidget();
632 Display
*display
= XtDisplay(widget
);
633 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
634 Window thisWindow
= XtWindow(widget
);
639 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
642 void wxWindow::SetCursor(const wxCursor
& cursor
)
644 m_windowCursor
= cursor
;
645 if (m_windowCursor
.Ok())
647 WXDisplay
*dpy
= GetXDisplay();
648 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
650 Widget w
= (Widget
) GetMainWidget();
651 Window win
= XtWindow(w
);
652 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
657 // Get size *available for subwindows* i.e. excluding menu bar etc.
658 void wxWindow::GetClientSize(int *x
, int *y
) const
660 Widget widget
= (Widget
) GetClientWidget();
662 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
666 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
670 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
673 Widget widget
= (Widget
) GetTopWidget();
677 bool managed
= XtIsManaged( widget
);
679 XtUnmanageChild(widget
);
681 int xx
= x
; int yy
= y
;
682 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
684 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
685 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
686 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
687 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
689 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
691 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
694 XtManageChild(widget
);
696 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
697 sizeEvent
.SetEventObject(this);
699 GetEventHandler()->ProcessEvent(sizeEvent
);
702 void wxWindow::SetClientSize(int width
, int height
)
706 CanvasSetClientSize(width
, height
);
710 Widget widget
= (Widget
) GetTopWidget();
713 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
715 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
717 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
718 sizeEvent
.SetEventObject(this);
720 GetEventHandler()->ProcessEvent(sizeEvent
);
723 // For implementation purposes - sometimes decorations make the client area
725 wxPoint
wxWindow::GetClientAreaOrigin() const
727 return wxPoint(0, 0);
730 // Makes an adjustment to the window position (for example, a frame that has
731 // a toolbar that it manages itself).
732 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
734 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
736 wxPoint
pt(GetParent()->GetClientAreaOrigin());
737 x
+= pt
.x
; y
+= pt
.y
;
741 bool wxWindow::Show(bool show
)
745 if (m_borderWidget
|| m_scrolledWindow
)
748 XtMapWidget((Widget
) m_drawingArea
);
749 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
753 XtMapWidget((Widget
) GetTopWidget());
758 if (m_borderWidget
|| m_scrolledWindow
)
761 XtUnmapWidget((Widget
) m_drawingArea
);
762 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
766 XtUnmapWidget((Widget
) GetTopWidget());
771 Window xwin = (Window) GetXWindow();
772 Display *xdisp = (Display*) GetXDisplay();
774 XMapWindow(xdisp, xwin);
776 XUnmapWindow(xdisp, xwin);
784 bool wxWindow::IsShown() const
789 int wxWindow::GetCharHeight() const
791 if (!m_windowFont
.Ok())
794 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
796 int direction
, ascent
, descent
;
798 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
800 // return (overall.ascent + overall.descent);
801 return (ascent
+ descent
);
804 int wxWindow::GetCharWidth() const
806 if (!m_windowFont
.Ok())
809 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
811 int direction
, ascent
, descent
;
813 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
815 return overall
.width
;
818 /* Helper function for 16-bit fonts */
819 static int str16len(const char *s
)
823 while (s
[0] && s
[1]) {
831 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
832 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
834 wxFont
*fontToUse
= (wxFont
*)theFont
;
836 fontToUse
= (wxFont
*) & m_windowFont
;
838 if (!fontToUse
->Ok())
841 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
843 int direction
, ascent
, descent2
;
847 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
850 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
851 &ascent
, &descent2
, &overall
);
853 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
854 &ascent
, &descent2
, &overall
);
856 *x
= (overall
.width
);
857 *y
= (ascent
+ descent2
);
861 *externalLeading
= 0;
864 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
866 Display
*display
= XtDisplay((Widget
) GetMainWidget());
867 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
869 XExposeEvent dummyEvent
;
871 GetSize(&width
, &height
);
873 dummyEvent
.type
= Expose
;
874 dummyEvent
.display
= display
;
875 dummyEvent
.send_event
= True
;
876 dummyEvent
.window
= thisWindow
;
879 dummyEvent
.x
= rect
->x
;
880 dummyEvent
.y
= rect
->y
;
881 dummyEvent
.width
= rect
->width
;
882 dummyEvent
.height
= rect
->height
;
888 dummyEvent
.width
= width
;
889 dummyEvent
.height
= height
;
891 dummyEvent
.count
= 0;
896 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
897 dc
.SetBackground(backgroundBrush
);
901 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
904 // Responds to colour changes: passes event on to children.
905 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
907 wxNode
*node
= GetChildren()->First();
910 // Only propagate to non-top-level windows
911 wxWindow
*win
= (wxWindow
*)node
->Data();
912 if ( win
->GetParent() )
914 wxSysColourChangedEvent event2
;
915 event
.m_eventObject
= win
;
916 win
->GetEventHandler()->ProcessEvent(event2
);
923 // This can be called by the app (or wxWindows) to do default processing for the current
924 // event. Save message/event info in wxWindow so they can be used in this function.
925 long wxWindow::Default()
931 void wxWindow::InitDialog()
933 wxInitDialogEvent
event(GetId());
934 event
.SetEventObject( this );
935 GetEventHandler()->ProcessEvent(event
);
938 // Default init dialog behaviour is to transfer data to window
939 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
941 TransferDataToWindow();
944 // Caret manipulation
945 void wxWindow::CreateCaret(int w
, int h
)
949 m_caretEnabled
= TRUE
;
952 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
957 void wxWindow::ShowCaret(bool show
)
962 void wxWindow::DestroyCaret()
965 m_caretEnabled
= FALSE
;
968 void wxWindow::SetCaretPos(int x
, int y
)
973 void wxWindow::GetCaretPos(int *x
, int *y
) const
978 wxWindow
*wxGetActiveWindow()
984 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
991 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
994 wxFrame
*frame
= (wxFrame
*)this;
995 Widget widget
= (Widget
) frame
->GetShellWidget();
998 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1000 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1002 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1004 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1006 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1008 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1011 void wxWindow::Centre(int direction
)
1013 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1015 wxWindow
*father
= (wxWindow
*)GetParent();
1019 father
->GetClientSize(&panel_width
, &panel_height
);
1020 GetSize(&width
, &height
);
1021 GetPosition(&x
, &y
);
1026 if (direction
& wxHORIZONTAL
)
1027 new_x
= (int)((panel_width
- width
)/2);
1029 if (direction
& wxVERTICAL
)
1030 new_y
= (int)((panel_height
- height
)/2);
1032 SetSize(new_x
, new_y
, -1, -1);
1036 // Coordinates relative to the window
1037 void wxWindow::WarpPointer (int x
, int y
)
1039 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1042 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1048 int wxWindow::GetScrollPos(int orient
) const
1050 if (orient
== wxHORIZONTAL
)
1051 return m_scrollPosX
;
1053 return m_scrollPosY
;
1055 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1059 XtVaGetValues(scrollBar,
1060 XmNvalue, &pos, NULL);
1068 // This now returns the whole range, not just the number
1069 // of positions that we can scroll.
1070 int wxWindow::GetScrollRange(int orient
) const
1072 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1076 XtVaGetValues(scrollBar
,
1077 XmNmaximum
, &range
, NULL
);
1084 int wxWindow::GetScrollThumb(int orient
) const
1086 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1090 XtVaGetValues(scrollBar
,
1091 XmNsliderSize
, &thumb
, NULL
);
1098 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1100 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1103 XtVaSetValues (scrollBar
,
1107 if (orient
== wxHORIZONTAL
)
1114 // New function that will replace some of the above.
1115 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1116 int range
, bool WXUNUSED(refresh
))
1118 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1124 if (thumbVisible
== 0)
1127 XtVaSetValues(scrollBar
,
1131 XmNsliderSize
, thumbVisible
,
1134 if (orient
== wxHORIZONTAL
)
1140 // Does a physical scroll
1141 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
1143 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1147 // Use specified rectangle
1148 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1152 // Use whole client area
1154 GetClientSize(& w
, & h
);
1157 int x1
= (dx
>= 0) ? x
: x
- dx
;
1158 int y1
= (dy
>= 0) ? y
: y
- dy
;
1159 int w1
= w
- abs(dx
);
1160 int h1
= h
- abs(dy
);
1161 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1162 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1164 wxClientDC
dc(this);
1166 dc
.SetLogicalFunction (wxCOPY
);
1168 Widget widget
= (Widget
) GetMainWidget();
1169 Window window
= XtWindow(widget
);
1170 Display
* display
= XtDisplay(widget
);
1172 XCopyArea(display
, window
,
1173 window
, (GC
) dc
.GetGC(),
1178 dc
.SetAutoSetting(TRUE
);
1179 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1180 dc
.SetBrush(brush
); // ??
1182 // We'll add rectangles to the list of update rectangles
1183 // according to which bits we've exposed.
1188 wxRect
*rect
= new wxRect
;
1194 XFillRectangle(display
, window
,
1195 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1199 rect
->width
= rect
->width
;
1200 rect
->height
= rect
->height
;
1202 updateRects
.Append((wxObject
*) rect
);
1206 wxRect
*rect
= new wxRect
;
1208 rect
->x
= x
+ w
+ dx
;
1213 XFillRectangle(display
, window
,
1214 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1219 rect
->width
= rect
->width
;
1220 rect
->height
= rect
->height
;
1222 updateRects
.Append((wxObject
*) rect
);
1226 wxRect
*rect
= new wxRect
;
1233 XFillRectangle(display
, window
,
1234 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1238 rect
->width
= rect
->width
;
1239 rect
->height
= rect
->height
;
1241 updateRects
.Append((wxObject
*) rect
);
1245 wxRect
*rect
= new wxRect
;
1248 rect
->y
= y
+ h
+ dy
;
1252 XFillRectangle(display
, window
,
1253 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1257 rect
->width
= rect
->width
;
1258 rect
->height
= rect
->height
;
1260 updateRects
.Append((wxObject
*) rect
);
1262 dc
.SetBrush(wxNullBrush
);
1264 // Now send expose events
1266 wxNode
* node
= updateRects
.First();
1269 wxRect
* rect
= (wxRect
*) node
->Data();
1272 event
.type
= Expose
;
1273 event
.display
= display
;
1274 event
.send_event
= True
;
1275 event
.window
= window
;
1279 event
.width
= rect
->width
;
1280 event
.height
= rect
->height
;
1284 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1286 node
= node
->Next();
1291 void wxWindow::OnChar(wxKeyEvent
& event
)
1293 if ( event
.KeyCode() == WXK_TAB
) {
1294 // propagate the TABs to the parent - it's up to it to decide what
1296 if ( GetParent() ) {
1297 if ( GetParent()->ProcessEvent(event
) )
1303 void wxWindow::OnPaint(wxPaintEvent
& event
)
1308 bool wxWindow::IsEnabled() const
1310 // TODO. Is this right?
1311 // return XtGetSensitive((Widget) GetMainWidget());
1315 // Dialog support: override these and call
1316 // base class members to add functionality
1317 // that can't be done using validators.
1318 // NOTE: these functions assume that controls
1319 // are direct children of this window, not grandchildren
1320 // or other levels of descendant.
1322 // Transfer values to controls. If returns FALSE,
1323 // it's an application error (pops up a dialog)
1324 bool wxWindow::TransferDataToWindow()
1326 wxNode
*node
= GetChildren()->First();
1329 wxWindow
*child
= (wxWindow
*)node
->Data();
1330 if ( child
->GetValidator() &&
1331 !child
->GetValidator()->TransferToWindow() )
1333 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1337 node
= node
->Next();
1342 // Transfer values from controls. If returns FALSE,
1343 // validation failed: don't quit
1344 bool wxWindow::TransferDataFromWindow()
1346 wxNode
*node
= GetChildren()->First();
1349 wxWindow
*child
= (wxWindow
*)node
->Data();
1350 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1355 node
= node
->Next();
1360 bool wxWindow::Validate()
1362 wxNode
*node
= GetChildren()->First();
1365 wxWindow
*child
= (wxWindow
*)node
->Data();
1366 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1371 node
= node
->Next();
1376 // Get the window with the focus
1377 wxWindow
*wxWindow::FindFocus()
1383 void wxWindow::AddChild(wxWindow
*child
)
1385 GetChildren()->Append(child
);
1386 child
->m_windowParent
= this;
1389 void wxWindow::RemoveChild(wxWindow
*child
)
1392 GetChildren()->DeleteObject(child
);
1393 child
->m_windowParent
= NULL
;
1396 void wxWindow::DestroyChildren()
1400 wxNode
*node
= GetChildren()->First();
1403 wxNode
* next
= node
->Next();
1404 wxWindow
* child
= (wxWindow
*) node
->Data();
1408 GetChildren()->Clear();
1411 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1413 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1415 if ( GetChildren()->Member(child
) )
1423 void wxWindow::MakeModal(bool modal
)
1425 // Disable all other windows
1426 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1428 wxNode
*node
= wxTopLevelWindows
.First();
1431 wxWindow
*win
= (wxWindow
*)node
->Data();
1433 win
->Enable(!modal
);
1435 node
= node
->Next();
1440 // If nothing defined for this, try the parent.
1441 // E.g. we may be a button loaded from a resource, with no callback function
1443 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1445 if (GetEventHandler()->ProcessEvent(event
) )
1448 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1451 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1455 UnsetConstraints(m_constraints
);
1456 delete m_constraints
;
1461 // Make sure other windows know they're part of a 'meaningful relationship'
1462 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1463 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1464 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1465 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1466 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1467 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1468 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1469 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1470 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1471 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1472 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1473 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1474 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1475 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1476 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1477 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1481 // This removes any dangling pointers to this window
1482 // in other windows' constraintsInvolvedIn lists.
1483 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1487 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1488 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1489 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1490 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1491 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1492 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1493 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1494 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1495 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1496 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1497 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1498 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1499 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1500 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1501 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1502 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1506 // Back-pointer to other windows we're involved with, so if we delete
1507 // this window, we must delete any constraints we're involved with.
1508 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1510 if (!m_constraintsInvolvedIn
)
1511 m_constraintsInvolvedIn
= new wxList
;
1512 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1513 m_constraintsInvolvedIn
->Append(otherWin
);
1516 // REMOVE back-pointer to other windows we're involved with.
1517 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1519 if (m_constraintsInvolvedIn
)
1520 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1523 // Reset any constraints that mention this window
1524 void wxWindow::DeleteRelatedConstraints()
1526 if (m_constraintsInvolvedIn
)
1528 wxNode
*node
= m_constraintsInvolvedIn
->First();
1531 wxWindow
*win
= (wxWindow
*)node
->Data();
1532 wxNode
*next
= node
->Next();
1533 wxLayoutConstraints
*constr
= win
->GetConstraints();
1535 // Reset any constraints involving this window
1538 constr
->left
.ResetIfWin((wxWindow
*)this);
1539 constr
->top
.ResetIfWin((wxWindow
*)this);
1540 constr
->right
.ResetIfWin((wxWindow
*)this);
1541 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1542 constr
->width
.ResetIfWin((wxWindow
*)this);
1543 constr
->height
.ResetIfWin((wxWindow
*)this);
1544 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1545 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1550 delete m_constraintsInvolvedIn
;
1551 m_constraintsInvolvedIn
= NULL
;
1555 void wxWindow::SetSizer(wxSizer
*sizer
)
1557 m_windowSizer
= sizer
;
1559 sizer
->SetSizerParent((wxWindow
*)this);
1566 bool wxWindow::Layout()
1568 if (GetConstraints())
1571 GetClientSize(&w
, &h
);
1572 GetConstraints()->width
.SetValue(w
);
1573 GetConstraints()->height
.SetValue(h
);
1576 // If top level (one sizer), evaluate the sizer's constraints.
1580 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1581 GetSizer()->LayoutPhase1(&noChanges
);
1582 GetSizer()->LayoutPhase2(&noChanges
);
1583 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1588 // Otherwise, evaluate child constraints
1589 ResetConstraints(); // Mark all constraints as unevaluated
1590 DoPhase(1); // Just one phase need if no sizers involved
1592 SetConstraintSizes(); // Recursively set the real window sizes
1598 // Do a phase of evaluating constraints:
1599 // the default behaviour. wxSizers may do a similar
1600 // thing, but also impose their own 'constraints'
1601 // and order the evaluation differently.
1602 bool wxWindow::LayoutPhase1(int *noChanges
)
1604 wxLayoutConstraints
*constr
= GetConstraints();
1607 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1613 bool wxWindow::LayoutPhase2(int *noChanges
)
1623 // Do a phase of evaluating child constraints
1624 bool wxWindow::DoPhase(int phase
)
1626 int noIterations
= 0;
1627 int maxIterations
= 500;
1631 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1635 wxNode
*node
= GetChildren()->First();
1638 wxWindow
*child
= (wxWindow
*)node
->Data();
1639 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1641 wxLayoutConstraints
*constr
= child
->GetConstraints();
1644 if (succeeded
.Member(child
))
1649 int tempNoChanges
= 0;
1650 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1651 noChanges
+= tempNoChanges
;
1654 succeeded
.Append(child
);
1659 node
= node
->Next();
1666 void wxWindow::ResetConstraints()
1668 wxLayoutConstraints
*constr
= GetConstraints();
1671 constr
->left
.SetDone(FALSE
);
1672 constr
->top
.SetDone(FALSE
);
1673 constr
->right
.SetDone(FALSE
);
1674 constr
->bottom
.SetDone(FALSE
);
1675 constr
->width
.SetDone(FALSE
);
1676 constr
->height
.SetDone(FALSE
);
1677 constr
->centreX
.SetDone(FALSE
);
1678 constr
->centreY
.SetDone(FALSE
);
1680 wxNode
*node
= GetChildren()->First();
1683 wxWindow
*win
= (wxWindow
*)node
->Data();
1684 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1685 win
->ResetConstraints();
1686 node
= node
->Next();
1690 // Need to distinguish between setting the 'fake' size for
1691 // windows and sizers, and setting the real values.
1692 void wxWindow::SetConstraintSizes(bool recurse
)
1694 wxLayoutConstraints
*constr
= GetConstraints();
1695 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1696 constr
->width
.GetDone() && constr
->height
.GetDone())
1698 int x
= constr
->left
.GetValue();
1699 int y
= constr
->top
.GetValue();
1700 int w
= constr
->width
.GetValue();
1701 int h
= constr
->height
.GetValue();
1703 // If we don't want to resize this window, just move it...
1704 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1705 (constr
->height
.GetRelationship() != wxAsIs
))
1707 // Calls Layout() recursively. AAAGH. How can we stop that.
1708 // Simply take Layout() out of non-top level OnSizes.
1709 SizerSetSize(x
, y
, w
, h
);
1718 char *windowClass
= this->GetClassInfo()->GetClassName();
1721 if (GetName() == "")
1722 winName
= "unnamed";
1724 winName
= GetName();
1725 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1726 if (!constr
->left
.GetDone())
1727 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1728 if (!constr
->right
.GetDone())
1729 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1730 if (!constr
->width
.GetDone())
1731 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1732 if (!constr
->height
.GetDone())
1733 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1734 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1739 wxNode
*node
= GetChildren()->First();
1742 wxWindow
*win
= (wxWindow
*)node
->Data();
1743 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1744 win
->SetConstraintSizes();
1745 node
= node
->Next();
1750 // This assumes that all sizers are 'on' the same
1751 // window, i.e. the parent of this window.
1752 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1754 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1755 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1759 m_sizerParent
->GetPosition(&xp
, &yp
);
1760 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1765 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1769 TransformSizerToActual(&xx
, &yy
);
1770 SetSize(xx
, yy
, w
, h
);
1773 void wxWindow::SizerMove(int x
, int y
)
1777 TransformSizerToActual(&xx
, &yy
);
1781 // Only set the size/position of the constraint (if any)
1782 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1784 wxLayoutConstraints
*constr
= GetConstraints();
1789 constr
->left
.SetValue(x
);
1790 constr
->left
.SetDone(TRUE
);
1794 constr
->top
.SetValue(y
);
1795 constr
->top
.SetDone(TRUE
);
1799 constr
->width
.SetValue(w
);
1800 constr
->width
.SetDone(TRUE
);
1804 constr
->height
.SetValue(h
);
1805 constr
->height
.SetDone(TRUE
);
1810 void wxWindow::MoveConstraint(int x
, int y
)
1812 wxLayoutConstraints
*constr
= GetConstraints();
1817 constr
->left
.SetValue(x
);
1818 constr
->left
.SetDone(TRUE
);
1822 constr
->top
.SetValue(y
);
1823 constr
->top
.SetDone(TRUE
);
1828 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1830 wxLayoutConstraints
*constr
= GetConstraints();
1833 *w
= constr
->width
.GetValue();
1834 *h
= constr
->height
.GetValue();
1840 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1842 wxLayoutConstraints
*constr
= GetConstraints();
1845 *w
= constr
->width
.GetValue();
1846 *h
= constr
->height
.GetValue();
1849 GetClientSize(w
, h
);
1852 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1854 wxLayoutConstraints
*constr
= GetConstraints();
1857 *x
= constr
->left
.GetValue();
1858 *y
= constr
->top
.GetValue();
1864 bool wxWindow::Close(bool force
)
1866 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1867 event
.SetEventObject(this);
1868 event
.SetForce(force
);
1870 return GetEventHandler()->ProcessEvent(event
);
1873 wxObject
* wxWindow::GetChild(int number
) const
1875 // Return a pointer to the Nth object in the window
1878 wxNode
*node
= GetChildren()->First();
1881 node
= node
->Next() ;
1884 wxObject
*obj
= (wxObject
*)node
->Data();
1891 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1893 // Obsolete function
1896 void wxWindow::Clear()
1898 wxClientDC
dc(this);
1899 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1900 dc
.SetBackground(brush
);
1904 // Fits the panel around the items
1905 void wxWindow::Fit()
1909 wxNode
*node
= GetChildren()->First();
1912 wxWindow
*win
= (wxWindow
*)node
->Data();
1914 win
->GetPosition(&wx
, &wy
);
1915 win
->GetSize(&ww
, &wh
);
1916 if ( wx
+ ww
> maxX
)
1918 if ( wy
+ wh
> maxY
)
1921 node
= node
->Next();
1923 SetClientSize(maxX
+ 5, maxY
+ 5);
1926 void wxWindow::SetValidator(const wxValidator
& validator
)
1928 if ( m_windowValidator
)
1929 delete m_windowValidator
;
1930 m_windowValidator
= validator
.Clone();
1932 if ( m_windowValidator
)
1933 m_windowValidator
->SetWindow(this) ;
1936 void wxWindow::SetClientObject( wxClientData
*data
)
1938 if (m_clientObject
) delete m_clientObject
;
1939 m_clientObject
= data
;
1942 wxClientData
*wxWindow::GetClientObject()
1944 return m_clientObject
;
1947 void wxWindow::SetClientData( void *data
)
1949 m_clientData
= data
;
1952 void *wxWindow::GetClientData()
1954 return m_clientData
;
1957 // Find a window by id or name
1958 wxWindow
*wxWindow::FindWindow(long id
)
1963 wxNode
*node
= GetChildren()->First();
1966 wxWindow
*child
= (wxWindow
*)node
->Data();
1967 wxWindow
*found
= child
->FindWindow(id
);
1970 node
= node
->Next();
1975 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1977 if ( GetName() == name
)
1980 wxNode
*node
= GetChildren()->First();
1983 wxWindow
*child
= (wxWindow
*)node
->Data();
1984 wxWindow
*found
= child
->FindWindow(name
);
1987 node
= node
->Next();
1992 void wxWindow::OnIdle(wxIdleEvent
& event
)
1994 // This calls the UI-update mechanism (querying windows for
1995 // menu/toolbar/control state information)
1999 // Raise the window to the top of the Z order
2000 void wxWindow::Raise()
2002 Window window
= XtWindow((Widget
) GetTopWidget());
2003 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2006 // Lower the window to the bottom of the Z order
2007 void wxWindow::Lower()
2009 Window window
= XtWindow((Widget
) GetTopWidget());
2010 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2013 bool wxWindow::AcceptsFocus() const
2015 return IsShown() && IsEnabled();
2018 // Update region access
2019 wxRegion
wxWindow::GetUpdateRegion() const
2021 return m_updateRegion
;
2024 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2026 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2029 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2031 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2034 bool wxWindow::IsExposed(const wxRect
& rect
) const
2036 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2040 * Allocates control IDs
2043 int wxWindow::NewControlId()
2045 static int s_controlId
= 0;
2050 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2052 m_acceleratorTable
= accel
;
2055 // All widgets should have this as their resize proc.
2056 // OnSize sent to wxWindow via client data.
2057 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2059 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2063 if (win
->PreResize())
2066 win
->GetSize(&width
, &height
);
2067 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2068 sizeEvent
.SetEventObject(win
);
2069 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2073 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2075 wxWindow
*oldItem
= NULL
;
2077 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2079 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2082 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2085 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
2090 wxWidgetHashTable
->Put ((long) w
, win
);
2094 wxWindow
*wxGetWindowFromTable(Widget w
)
2096 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2099 void wxDeleteWindowFromTable(Widget w
)
2101 wxWidgetHashTable
->Delete((long)w
);
2104 // Get the underlying X window and display
2105 WXWindow
wxWindow::GetXWindow() const
2107 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2110 WXDisplay
*wxWindow::GetXDisplay() const
2112 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2115 WXWidget
wxWindow::GetMainWidget() const
2118 return m_drawingArea
;
2120 return m_mainWidget
;
2123 WXWidget
wxWindow::GetClientWidget() const
2125 if (m_drawingArea
!= (WXWidget
) 0)
2126 return m_drawingArea
;
2128 return GetMainWidget();
2131 WXWidget
wxWindow::GetTopWidget() const
2133 return GetMainWidget();
2136 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2137 XmDrawingAreaCallbackStruct
* cbs
)
2139 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2142 XEvent
* event
= cbs
->event
;
2143 wxWindow
* canvas
= (wxWindow
*) clientData
;
2144 Display
* display
= (Display
*) canvas
->GetXDisplay();
2145 // GC gc = (GC) canvas->GetDC()->gc;
2147 switch (event
->type
)
2152 wxCanvasDC* canvasDC = canvas->GetDC();
2155 if (canvasDC->onpaint_reg)
2156 XDestroyRegion(canvasDC->onpaint_reg);
2157 canvasDC->onpaint_reg = XCreateRegion();
2162 int n
= canvas
->m_updateRects
.Number();
2163 XRectangle
* xrects
= new XRectangle
[n
];
2165 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
2167 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
2168 xrects
[i
].x
= rect
->x
;
2169 xrects
[i
].y
= rect
->y
;
2170 xrects
[i
].width
= rect
->width
;
2171 xrects
[i
].height
= rect
->height
;
2172 /* TODO (?) Actually ignore it I think.
2174 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
2175 canvasDC->onpaint_reg);
2178 /* TODO must clip the area being repainted. So we need a gc.
2179 * Alternatively, wxPaintDC must do the clipping
2180 * when it's created.
2181 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
2184 canvas
->DoPaint() ; // xrects, n);
2187 canvas
->m_updateRects
.Clear();
2192 XDestroyRegion(canvasDC->onpaint_reg);
2193 canvasDC->onpaint_reg = NULL;
2197 gc_val.clip_mask = None;
2198 XChangeGC(display, gc, GCClipMask, &gc_val);
2205 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2211 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2213 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2215 XmDrawingAreaCallbackStruct cbs
;
2218 //if (event->mode!=NotifyNormal)
2221 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2222 ((XCrossingEvent
&) ev
) = *event
;
2224 cbs
.reason
= XmCR_INPUT
;
2227 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2230 // Fix to make it work under Motif 1.0 (!)
2231 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2235 XmDrawingAreaCallbackStruct cbs
;
2238 //ev.xbutton = *event;
2239 ev
= *((XEvent
*) event
);
2240 cbs
.reason
= XmCR_INPUT
;
2243 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2247 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2249 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2255 if (cbs
->reason
!= XmCR_INPUT
)
2258 local_event
= *(cbs
->event
); // We must keep a copy!
2260 switch (local_event
.xany
.type
)
2268 wxEventType eventType
= wxEVT_NULL
;
2270 if (local_event
.xany
.type
== EnterNotify
)
2272 //if (local_event.xcrossing.mode!=NotifyNormal)
2273 // return ; // Ignore grab events
2274 eventType
= wxEVT_ENTER_WINDOW
;
2275 // canvas->GetEventHandler()->OnSetFocus();
2277 else if (local_event
.xany
.type
== LeaveNotify
)
2279 //if (local_event.xcrossing.mode!=NotifyNormal)
2280 // return ; // Ignore grab events
2281 eventType
= wxEVT_LEAVE_WINDOW
;
2282 // canvas->GetEventHandler()->OnKillFocus();
2284 else if (local_event
.xany
.type
== MotionNotify
)
2286 eventType
= wxEVT_MOTION
;
2287 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2290 Display
*dpy
= XtDisplay (drawingArea
);
2292 XQueryPointer (dpy
, XtWindow (drawingArea
),
2294 &local_event
.xmotion
.x_root
,
2295 &local_event
.xmotion
.y_root
,
2296 &local_event
.xmotion
.x
,
2297 &local_event
.xmotion
.y
,
2298 &local_event
.xmotion
.state
);
2305 else if (local_event
.xany
.type
== ButtonPress
)
2307 if (local_event
.xbutton
.button
== Button1
)
2309 eventType
= wxEVT_LEFT_DOWN
;
2310 canvas
->m_button1Pressed
= TRUE
;
2312 else if (local_event
.xbutton
.button
== Button2
)
2314 eventType
= wxEVT_MIDDLE_DOWN
;
2315 canvas
->m_button2Pressed
= TRUE
;
2317 else if (local_event
.xbutton
.button
== Button3
)
2319 eventType
= wxEVT_RIGHT_DOWN
;
2320 canvas
->m_button3Pressed
= TRUE
;
2323 else if (local_event
.xany
.type
== ButtonRelease
)
2325 if (local_event
.xbutton
.button
== Button1
)
2327 eventType
= wxEVT_LEFT_UP
;
2328 canvas
->m_button1Pressed
= FALSE
;
2330 else if (local_event
.xbutton
.button
== Button2
)
2332 eventType
= wxEVT_MIDDLE_UP
;
2333 canvas
->m_button2Pressed
= FALSE
;
2335 else if (local_event
.xbutton
.button
== Button3
)
2337 eventType
= wxEVT_RIGHT_UP
;
2338 canvas
->m_button3Pressed
= FALSE
;
2342 wxMouseEvent
wxevent (eventType
);
2343 wxevent
.m_eventHandle
= (char *) &local_event
;
2345 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2346 || (event_left_is_down (&local_event
)
2347 && (eventType
!= wxEVT_LEFT_UP
)));
2348 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2349 || (event_middle_is_down (&local_event
)
2350 && (eventType
!= wxEVT_MIDDLE_UP
)));
2351 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2352 || (event_right_is_down (&local_event
)
2353 && (eventType
!= wxEVT_RIGHT_UP
)));
2355 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2356 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2357 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2358 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2359 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2361 // Now check if we need to translate this event into a double click
2362 if (TRUE
) // canvas->doubleClickAllowed)
2364 if (wxevent
.ButtonDown())
2366 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2368 // get button and time-stamp
2370 if (wxevent
.LeftDown()) button
= 1;
2371 else if (wxevent
.MiddleDown()) button
= 2;
2372 else if (wxevent
.RightDown()) button
= 3;
2373 long ts
= wxevent
.GetTimestamp();
2374 // check, if single or double click
2375 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2378 canvas
->m_lastButton
= 0;
2379 switch ( eventType
)
2381 case wxEVT_LEFT_DOWN
:
2382 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2384 case wxEVT_MIDDLE_DOWN
:
2385 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2387 case wxEVT_RIGHT_DOWN
:
2388 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2398 // not fast enough or different button
2399 canvas
->m_lastTS
= ts
;
2400 canvas
->m_lastButton
= button
;
2405 wxevent
.SetId(canvas
->GetId());
2406 wxevent
.SetEventObject(canvas
);
2407 wxevent
.m_x
= local_event
.xbutton
.x
;
2408 wxevent
.m_y
= local_event
.xbutton
.y
;
2409 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2411 if (eventType == wxEVT_ENTER_WINDOW ||
2412 eventType == wxEVT_LEAVE_WINDOW ||
2413 eventType == wxEVT_MOTION
2422 // XComposeStatus compose;
2423 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2424 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2425 int id
= wxCharCodeXToWX (keySym
);
2427 wxKeyEvent
event (wxEVT_CHAR
);
2429 if (local_event
.xkey
.state
& ShiftMask
)
2430 event
.m_shiftDown
= TRUE
;
2431 if (local_event
.xkey
.state
& ControlMask
)
2432 event
.m_controlDown
= TRUE
;
2433 if (local_event
.xkey
.state
& Mod3Mask
)
2434 event
.m_altDown
= TRUE
;
2435 if (local_event
.xkey
.state
& Mod1Mask
)
2436 event
.m_metaDown
= TRUE
;
2437 event
.SetEventObject(canvas
);
2438 event
.m_keyCode
= id
;
2439 event
.SetTimestamp(local_event
.xkey
.time
);
2443 // Implement wxFrame::OnCharHook by checking ancestor.
2444 wxWindow
*parent
= canvas
->GetParent();
2445 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2446 parent
= parent
->GetParent();
2450 event
.SetEventType(wxEVT_CHAR_HOOK
);
2451 if (parent
->GetEventHandler()->ProcessEvent(event
))
2453 event
.SetEventType(wxEVT_CHAR
);
2456 canvas
->GetEventHandler()->ProcessEvent (event
);
2462 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2464 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2465 event
.SetEventObject(canvas
);
2466 canvas
->GetEventHandler()->ProcessEvent(event
);
2472 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2474 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2475 event
.SetEventObject(canvas
);
2476 canvas
->GetEventHandler()->ProcessEvent(event
);
2485 void wxWindow::DoPaint()
2487 //TODO : make a temporary gc so we can do the XCopyArea below
2488 if (0) // m_backingPixmap)
2491 Widget drawingArea = (Widget) m_drawingArea;
2492 // int orig = GetDC()->GetLogicalFunction();
2493 // GetDC()->SetLogicalFunction (wxCOPY);
2495 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2496 // should be able to calculate them.
2497 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2498 m_pixmapOffsetX, m_pixmapOffsetY,
2499 m_pixmapWidth, m_pixmapHeight,
2502 // GetDC()->SetLogicalFunction (orig);
2507 wxPaintEvent
event(GetId());
2508 event
.SetEventObject(this);
2509 GetEventHandler()->ProcessEvent(event
);
2513 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2514 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2516 Widget drawingArea
= (Widget
) m_drawingArea
;
2517 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2520 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2521 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2523 int xx
= x
; int yy
= y
;
2524 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2526 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2528 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2532 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2534 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2542 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2543 short thick
, margin
;
2544 XtVaGetValues ((Widget
) m_borderWidget
,
2545 XmNshadowThickness
, &thick
,
2546 XmNmarginWidth
, &margin
,
2548 w
-= 2 * (thick
+ margin
);
2551 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2555 XtVaGetValues ((Widget
) m_scrolledWindow
,
2556 XmNspacing
, &spacing
,
2557 XmNverticalScrollBar
, &sbar
,
2561 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2565 w
-= (spacing
+ wsbar
);
2567 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2573 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2574 short thick
, margin
;
2575 XtVaGetValues ((Widget
) m_borderWidget
,
2576 XmNshadowThickness
, &thick
,
2577 XmNmarginHeight
, &margin
,
2579 h
-= 2 * (thick
+ margin
);
2582 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2586 XtVaGetValues ((Widget
) m_scrolledWindow
,
2587 XmNspacing
, &spacing
,
2588 XmNhorizontalScrollBar
, &sbar
,
2592 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2596 h
-= (spacing
+ wsbar
);
2598 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2601 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2602 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2605 GetClientSize (&ww
, &hh
);
2606 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2607 sizeEvent
.SetEventObject(this);
2609 GetEventHandler()->ProcessEvent(sizeEvent
);
2612 void wxWindow::CanvasSetClientSize (int w
, int h
)
2614 Widget drawingArea
= (Widget
) m_drawingArea
;
2616 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2619 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2621 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2622 /* TODO: is this necessary?
2623 allowRepainting = FALSE;
2625 XSync (XtDisplay (drawingArea), FALSE);
2627 while (XtAppPending (wxTheApp->appContext))
2629 XFlush (XtDisplay (drawingArea));
2630 XtAppNextEvent (wxTheApp->appContext, &event);
2631 XtDispatchEvent (&event);
2635 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2638 allowRepainting = TRUE;
2642 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2643 sizeEvent
.SetEventObject(this);
2645 GetEventHandler()->ProcessEvent(sizeEvent
);
2648 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2650 // Must return the same thing that was set via SetClientSize
2652 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2657 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2660 if ((Widget
) m_borderWidget
)
2661 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2662 else if ((Widget
) m_scrolledWindow
)
2663 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2665 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2671 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2674 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2676 // We may be faking the client origin.
2677 // So a window that's really at (0, 30) may appear
2678 // (to wxWin apps) to be at (0, 0).
2681 wxPoint
pt(GetParent()->GetClientAreaOrigin());
2690 // Add to hash table, add event handler
2691 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2692 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2694 wxAddWindowToTable((Widget
) mainWidget
, this);
2695 if (CanAddEventHandler())
2697 XtAddEventHandler((Widget
) mainWidget
,
2698 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2700 wxPanelItemEventHandler
,
2707 XtOverrideTranslations ((Widget
) mainWidget
,
2708 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2709 XtFree ((char *) ptr
);
2712 // Some widgets have a parent form widget, e.g. wxRadioBox
2715 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2719 XtOverrideTranslations ((Widget
) formWidget
,
2720 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2721 XtFree ((char *) ptr
);
2728 SetSize (x
, y
, width
, height
);
2733 // Remove event handler, remove from hash table
2734 bool wxWindow::DetachWidget(WXWidget widget
)
2736 if (CanAddEventHandler())
2738 XtRemoveEventHandler((Widget
) widget
,
2739 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2741 wxPanelItemEventHandler
,
2745 wxDeleteWindowFromTable((Widget
) widget
);
2749 void wxPanelItemEventHandler (Widget wid
,
2750 XtPointer client_data
,
2752 Boolean
*continueToDispatch
)
2754 // Widget can be a label or the actual widget.
2756 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2759 wxMouseEvent
wxevent(0);
2760 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2762 window
->GetEventHandler()->ProcessEvent(wxevent
);
2765 // TODO: probably the key to allowing default behaviour
2767 // Say we set a m_doDefault flag to FALSE at the start of this
2768 // function. Then in e.g. wxWindow::OnMouseEvent we can
2769 // call Default() which sets this flag to TRUE, indicating
2770 // that default processing can happen. Thus, behaviour can appear
2771 // to be overridden just by adding an event handler and not calling
2772 // wxWindow::OnWhatever.
2773 // ALSO, maybe we can use this instead of the current way of handling
2774 // drawing area events, to simplify things.
2775 *continueToDispatch
= True
;
2778 void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
2779 XmScaleCallbackStruct
*cbs
)
2781 Widget scrolledWindow
= XtParent (scrollbar
);
2782 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
2783 int orientation
= (int) clientData
;
2785 wxEventType eventType
= wxEVT_NULL
;
2786 switch (cbs
->reason
)
2788 case XmCR_INCREMENT
:
2790 eventType
= wxEVT_SCROLL_LINEDOWN
;
2793 case XmCR_DECREMENT
:
2795 eventType
= wxEVT_SCROLL_LINEUP
;
2800 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2803 case XmCR_VALUE_CHANGED
:
2805 // TODO: Should this be intercepted too, or will it cause
2806 // duplicate events?
2807 eventType
= wxEVT_SCROLL_THUMBTRACK
;
2810 case XmCR_PAGE_INCREMENT
:
2812 eventType
= wxEVT_SCROLL_PAGEDOWN
;
2815 case XmCR_PAGE_DECREMENT
:
2817 eventType
= wxEVT_SCROLL_PAGEUP
;
2822 eventType
= wxEVT_SCROLL_TOP
;
2825 case XmCR_TO_BOTTOM
:
2827 eventType
= wxEVT_SCROLL_BOTTOM
;
2832 // Should never get here
2833 wxFAIL_MSG("Unknown scroll event.");
2838 wxScrollEvent
event(eventType
, win
->GetId());
2839 event
.SetEventObject(win
);
2840 event
.SetPosition(cbs
->value
);
2841 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
2843 win
->GetEventHandler()->ProcessEvent(event
);
2846 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2848 switch (xevent
->xany
.type
)
2856 wxEventType eventType
= wxEVT_NULL
;
2858 if (xevent
->xany
.type
== LeaveNotify
)
2860 win
->m_button1Pressed
= FALSE
;
2861 win
->m_button2Pressed
= FALSE
;
2862 win
->m_button3Pressed
= FALSE
;
2865 else if (xevent
->xany
.type
== MotionNotify
)
2867 eventType
= wxEVT_MOTION
;
2869 else if (xevent
->xany
.type
== ButtonPress
)
2871 if (xevent
->xbutton
.button
== Button1
)
2873 eventType
= wxEVT_LEFT_DOWN
;
2874 win
->m_button1Pressed
= TRUE
;
2876 else if (xevent
->xbutton
.button
== Button2
)
2878 eventType
= wxEVT_MIDDLE_DOWN
;
2879 win
->m_button2Pressed
= TRUE
;
2881 else if (xevent
->xbutton
.button
== Button3
)
2883 eventType
= wxEVT_RIGHT_DOWN
;
2884 win
->m_button3Pressed
= TRUE
;
2887 else if (xevent
->xany
.type
== ButtonRelease
)
2889 if (xevent
->xbutton
.button
== Button1
)
2891 eventType
= wxEVT_LEFT_UP
;
2892 win
->m_button1Pressed
= FALSE
;
2894 else if (xevent
->xbutton
.button
== Button2
)
2896 eventType
= wxEVT_MIDDLE_UP
;
2897 win
->m_button2Pressed
= FALSE
;
2899 else if (xevent
->xbutton
.button
== Button3
)
2901 eventType
= wxEVT_RIGHT_UP
;
2902 win
->m_button3Pressed
= FALSE
;
2908 wxevent
.m_eventHandle
= (char *)xevent
;
2909 wxevent
.SetEventType(eventType
);
2912 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2915 win
->GetPosition(&x2
, &y2
);
2917 // The button x/y must be translated to wxWindows
2918 // window space - the widget might be a label or button,
2922 if (widget
!= (Widget
)win
->GetMainWidget())
2928 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2929 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2931 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2932 || (event_left_is_down (xevent
)
2933 && (eventType
!= wxEVT_LEFT_UP
)));
2934 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2935 || (event_middle_is_down (xevent
)
2936 && (eventType
!= wxEVT_MIDDLE_UP
)));
2937 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2938 || (event_right_is_down (xevent
)
2939 && (eventType
!= wxEVT_RIGHT_UP
)));
2941 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2942 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2949 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2951 switch (xevent
->xany
.type
)
2958 // XComposeStatus compose;
2959 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2960 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2961 int id
= wxCharCodeXToWX (keySym
);
2963 if (xevent
->xkey
.state
& ShiftMask
)
2964 wxevent
.m_shiftDown
= TRUE
;
2965 if (xevent
->xkey
.state
& ControlMask
)
2966 wxevent
.m_controlDown
= TRUE
;
2967 if (xevent
->xkey
.state
& Mod3Mask
)
2968 wxevent
.m_altDown
= TRUE
;
2969 if (xevent
->xkey
.state
& Mod1Mask
)
2970 wxevent
.m_metaDown
= TRUE
;
2971 wxevent
.SetEventObject(win
);
2972 wxevent
.m_keyCode
= id
;
2973 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2975 wxevent
.m_x
= xevent
->xbutton
.x
;
2976 wxevent
.m_y
= xevent
->xbutton
.y
;
2990 #define YAllocColor XAllocColor
2991 XColor g_itemColors
[5];
2992 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
2995 static XmColorProc colorProc
;
2997 result
= wxNO_COLORS
;
3001 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3002 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3003 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3004 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3005 if (colorProc
== (XmColorProc
) NULL
)
3007 // Get a ptr to the actual function
3008 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3009 // And set it back to motif.
3010 XmSetColorCalculation (colorProc
);
3012 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3013 &g_itemColors
[wxFORE_INDEX
],
3014 &g_itemColors
[wxSELE_INDEX
],
3015 &g_itemColors
[wxTOPS_INDEX
],
3016 &g_itemColors
[wxBOTS_INDEX
]);
3017 result
= wxBACK_COLORS
;
3021 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3022 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3023 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3024 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3025 if (result
== wxNO_COLORS
)
3026 result
= wxFORE_COLORS
;
3029 Display
*dpy
= display
;
3030 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3034 /* 5 Colours to allocate */
3035 for (int i
= 0; i
< 5; i
++)
3036 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3037 result
= wxNO_COLORS
;
3041 /* Only 1 colour to allocate */
3042 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3043 result
= wxNO_COLORS
;
3050 // Changes the foreground and background colours to be derived
3051 // from the current background colour.
3052 // To change the foreground colour, you must call SetForegroundColour
3054 void wxWindow::ChangeBackgroundColour()
3056 if (GetMainWidget())
3057 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3060 void wxWindow::ChangeForegroundColour()
3062 if (GetMainWidget())
3063 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3066 // Change a widget's foreground and background colours.
3068 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3070 // When should we specify the foreground, if it's calculated
3071 // by wxComputeColours?
3072 // Solution: say we start with the default (computed) foreground colour.
3073 // If we call SetForegroundColour explicitly for a control or window,
3074 // then the foreground is changed.
3075 // Therefore SetBackgroundColour computes the foreground colour, and
3076 // SetForegroundColour changes the foreground colour. The ordering is
3079 XtVaSetValues ((Widget
) widget
,
3080 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3084 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3086 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3089 XtVaSetValues ((Widget
) widget
,
3090 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3091 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3092 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3093 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3096 if (changeArmColour
)
3097 XtVaSetValues ((Widget
) widget
,
3098 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3102 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3104 m_backgroundColour
= col
;
3105 ChangeBackgroundColour();
3108 void wxWindow::SetForegroundColour(const wxColour
& col
)
3110 m_foregroundColour
= col
;
3111 ChangeForegroundColour();
3114 void wxWindow::ChangeFont(bool keepOriginalSize
)
3116 // Note that this causes the widget to be resized back
3117 // to its original size! We therefore have to set the size
3118 // back again. TODO: a better way in Motif?
3119 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3120 if (w
&& m_windowFont
.Ok())
3122 int width
, height
, width1
, height1
;
3123 GetSize(& width
, & height
);
3126 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3129 GetSize(& width1
, & height1
);
3130 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3132 SetSize(-1, -1, width
, height
);
3137 void wxWindow::SetFont(const wxFont
& font
)
3139 m_windowFont
= font
;