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"
30 #include "wx/scrolwin.h"
32 #include "wx/menuitem.h"
35 #if wxUSE_DRAG_AND_DROP
41 #include <Xm/DrawingA.h>
42 #include <Xm/ScrolledW.h>
43 #include <Xm/ScrollBar.h>
47 #include "wx/motif/private.h"
51 #define SCROLL_MARGIN 4
52 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
54 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
55 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
56 static void wxScrollBarCallback(Widget widget
, XtPointer clientData
,
57 XmScaleCallbackStruct
*cbs
);
58 void wxPanelItemEventHandler (Widget wid
,
59 XtPointer client_data
,
61 Boolean
*continueToDispatch
);
63 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
64 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
65 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
67 extern wxList wxPendingDelete
;
69 #if !USE_SHARED_LIBRARY
70 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
72 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
73 EVT_CHAR(wxWindow::OnChar
)
74 EVT_KEY_DOWN(wxWindow::OnKeyDown
)
75 EVT_KEY_UP(wxWindow::OnKeyUp
)
76 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
77 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
78 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
79 EVT_IDLE(wxWindow::OnIdle
)
89 m_isWindow
= TRUE
; // An optimization
92 m_windowParent
= NULL
;
93 m_windowEventHandler
= this;
95 m_windowCursor
= *wxSTANDARD_CURSOR
;
96 m_children
= new wxList
;
98 m_constraintsInvolvedIn
= NULL
;
100 m_sizerParent
= NULL
;
101 m_autoLayout
= FALSE
;
102 m_windowValidator
= NULL
;
103 m_defaultItem
= NULL
;
105 m_caretWidth
= 0; m_caretHeight
= 0;
106 m_caretEnabled
= FALSE
;
107 m_caretShown
= FALSE
;
108 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
109 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
110 m_foregroundColour
= *wxBLACK
;
112 #if wxUSE_DRAG_AND_DROP
113 m_pDropTarget
= NULL
;
115 m_clientObject
= (wxClientData
*) NULL
;
119 m_needsRefresh
= TRUE
;
120 m_mainWidget
= (WXWidget
) 0;
121 m_button1Pressed
= FALSE
;
122 m_button2Pressed
= FALSE
;
123 m_button3Pressed
= FALSE
;
124 m_winCaptured
= FALSE
;
126 m_hScrollBar
= (WXWidget
) 0;
127 m_vScrollBar
= (WXWidget
) 0;
128 m_borderWidget
= (WXWidget
) 0;
129 m_scrolledWindow
= (WXWidget
) 0;
130 m_drawingArea
= (WXWidget
) 0;
133 m_backingPixmap
= (WXPixmap
) 0;
140 m_canAddEventHandler
= FALSE
;
146 wxWindow::~wxWindow()
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 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
232 // Child widgets will get destroyed automatically when a frame
233 // or dialog is destroyed, but before that you may get some memory
234 // leaks and potential layout problems if you delete and then add
236 XtDestroyWidget((Widget
) GetMainWidget());
237 SetMainWidget((WXWidget
) NULL
);
243 // Just in case the window has been Closed, but
244 // we're then deleting immediately: don't leave
245 // dangling pointers.
246 wxPendingDelete
.DeleteObject(this);
248 if ( m_windowValidator
) delete m_windowValidator
;
249 if (m_clientObject
) delete m_clientObject
;
254 // Destroy the window (delayed, if a managed window)
255 bool wxWindow::Destroy()
262 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
266 const wxString
& name
)
269 m_isWindow
= TRUE
; // An optimization
272 m_windowParent
= NULL
;
273 m_windowEventHandler
= this;
275 m_windowCursor
= *wxSTANDARD_CURSOR
;
276 m_constraints
= NULL
;
277 m_constraintsInvolvedIn
= NULL
;
278 m_windowSizer
= NULL
;
279 m_sizerParent
= NULL
;
280 m_autoLayout
= FALSE
;
281 m_windowValidator
= NULL
;
282 #if wxUSE_DRAG_AND_DROP
283 m_pDropTarget
= NULL
;
285 m_caretWidth
= 0; m_caretHeight
= 0;
286 m_caretEnabled
= FALSE
;
287 m_caretShown
= FALSE
;
292 m_defaultItem
= NULL
;
293 m_windowParent
= NULL
;
294 m_clientObject
= (wxClientData
*) NULL
;
298 m_needsRefresh
= TRUE
;
299 m_canAddEventHandler
= FALSE
;
300 m_mainWidget
= (WXWidget
) 0;
301 m_button1Pressed
= FALSE
;
302 m_button2Pressed
= FALSE
;
303 m_button3Pressed
= FALSE
;
304 m_winCaptured
= FALSE
;
306 m_hScrollBar
= (WXWidget
) 0;
307 m_vScrollBar
= (WXWidget
) 0;
308 m_borderWidget
= (WXWidget
) 0;
309 m_scrolledWindow
= (WXWidget
) 0;
310 m_drawingArea
= (WXWidget
) 0;
313 m_backingPixmap
= (WXPixmap
) 0;
324 if (parent
) parent
->AddChild(this);
331 m_windowId
= (int)NewControlId();
335 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
336 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
337 m_foregroundColour
= *wxBLACK
;
339 m_windowStyle
= style
;
342 m_windowId
= (int)NewControlId();
346 //// TODO: we should probably optimize by only creating a
347 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
348 //// But for now, let's simplify things by always creating the
349 //// drawing area, since otherwise the translations are different.
351 // New translations for getting mouse motion feedback
352 String translations
=
353 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
354 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
355 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
356 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
357 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
358 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
359 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
360 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
361 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
362 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
363 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
364 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
365 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
366 <Key>: DrawingAreaInput()";
368 XtActionsRec actions
[1];
369 actions
[0].string
= "wxCanvasMotionEvent";
370 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
371 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
373 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
374 if (style
& wxBORDER
)
375 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
376 xmFrameWidgetClass
, parentWidget
,
377 XmNshadowType
, XmSHADOW_IN
,
380 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
381 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
382 XmNresizePolicy
, XmRESIZE_NONE
,
384 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
385 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
389 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
390 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
391 XmNunitType
, XmPIXELS
,
392 // XmNresizePolicy, XmRESIZE_ANY,
393 XmNresizePolicy
, XmRESIZE_NONE
,
396 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
399 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
401 XtFree ((char *) ptr);
402 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
403 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
404 XtFree ((char *) ptr);
408 wxAddWindowToTable((Widget
) m_drawingArea
, this);
409 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
412 * This order is very important in Motif 1.2.1
416 XtRealizeWidget ((Widget
) m_scrolledWindow
);
417 XtRealizeWidget ((Widget
) m_drawingArea
);
418 XtManageChild ((Widget
) m_drawingArea
);
420 XtOverrideTranslations ((Widget
) m_drawingArea
,
421 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
422 XtFree ((char *) ptr
);
424 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
425 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
428 display = XtDisplay (scrolledWindow);
429 xwindow = XtWindow (drawingArea);
432 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
433 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
435 // Scrolled widget needs to have its colour changed or we get
436 // a little blue square where the scrollbars abutt
437 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
438 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
439 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
441 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) 0, (Widget
) 0, (Widget
) m_drawingArea
);
445 XtRealizeWidget ((Widget) m_hScrollBar);
447 XtRealizeWidget ((Widget) m_vScrollBar);
450 // Without this, the cursor may not be restored properly
451 // (e.g. in splitter sample).
452 SetCursor(*wxSTANDARD_CURSOR
);
453 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
454 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
460 void wxWindow::CreateScrollbar(int orientation
)
465 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
467 // Add scrollbars if required
468 if (orientation
== wxHORIZONTAL
)
470 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
471 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
472 XmNorientation
, XmHORIZONTAL
,
474 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
475 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
476 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
477 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
478 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
479 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
480 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
481 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
483 XtVaSetValues (hScrollBar
,
488 m_hScrollBar
= (WXWidget
) hScrollBar
;
490 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
491 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
493 XtRealizeWidget(hScrollBar
);
495 XtVaSetValues((Widget
) m_scrolledWindow
,
496 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
502 if (orientation
== wxVERTICAL
)
504 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
505 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
506 XmNorientation
, XmVERTICAL
,
508 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
509 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
510 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
511 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
512 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
513 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
514 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
515 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
517 XtVaSetValues (vScrollBar
,
522 m_vScrollBar
= (WXWidget
) vScrollBar
;
523 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
524 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
526 XtRealizeWidget(vScrollBar
);
528 XtVaSetValues((Widget
) m_scrolledWindow
,
529 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
535 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
537 void wxWindow::DestroyScrollbar(int orientation
)
542 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
543 // Add scrollbars if required
544 if (orientation
== wxHORIZONTAL
)
548 XtDestroyWidget((Widget
) m_hScrollBar
);
550 m_hScrollBar
= (WXWidget
) 0;
553 XtVaSetValues((Widget
) m_scrolledWindow
,
554 XmNhorizontalScrollBar
, (Widget
) 0,
559 if (orientation
== wxVERTICAL
)
563 XtDestroyWidget((Widget
) m_vScrollBar
);
565 m_vScrollBar
= (WXWidget
) 0;
568 XtVaSetValues((Widget
) m_scrolledWindow
,
569 XmNverticalScrollBar
, (Widget
) 0,
573 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
576 void wxWindow::SetFocus()
578 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
579 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
582 void wxWindow::Enable(bool enable
)
586 XtSetSensitive((Widget
) GetMainWidget(), enable
);
587 XmUpdateDisplay((Widget
) GetMainWidget());
591 void wxWindow::CaptureMouse()
597 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
599 m_winCaptured
= TRUE
;
602 void wxWindow::ReleaseMouse()
608 XtRemoveGrab((Widget
) GetMainWidget());
609 m_winCaptured
= FALSE
;
612 // Push/pop event handler (i.e. allow a chain of event handlers
614 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
616 handler
->SetNextHandler(GetEventHandler());
617 SetEventHandler(handler
);
620 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
622 if ( GetEventHandler() )
624 wxEvtHandler
*handlerA
= GetEventHandler();
625 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
626 handlerA
->SetNextHandler(NULL
);
627 SetEventHandler(handlerB
);
640 #if wxUSE_DRAG_AND_DROP
642 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
644 if ( m_pDropTarget
!= 0 ) {
645 delete m_pDropTarget
;
648 m_pDropTarget
= pDropTarget
;
649 if ( m_pDropTarget
!= 0 )
657 // Old style file-manager drag&drop
658 void wxWindow::DragAcceptFiles(bool accept
)
664 void wxWindow::GetSize(int *x
, int *y
) const
672 Widget widget
= (Widget
) GetTopWidget();
674 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
678 void wxWindow::GetPosition(int *x
, int *y
) const
682 CanvasGetPosition(x
, y
);
685 Widget widget
= (Widget
) GetTopWidget();
687 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
689 // We may be faking the client origin.
690 // So a window that's really at (0, 30) may appear
691 // (to wxWin apps) to be at (0, 0).
694 wxPoint
pt(GetParent()->GetClientAreaOrigin());
702 void wxWindow::ScreenToClient(int *x
, int *y
) const
704 Widget widget
= (Widget
) GetClientWidget();
705 Display
*display
= XtDisplay((Widget
) GetMainWidget());
706 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
707 Window thisWindow
= XtWindow(widget
);
712 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
715 void wxWindow::ClientToScreen(int *x
, int *y
) const
717 Widget widget
= (Widget
) GetClientWidget();
718 Display
*display
= XtDisplay(widget
);
719 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
720 Window thisWindow
= XtWindow(widget
);
725 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
728 void wxWindow::SetCursor(const wxCursor
& cursor
)
730 m_windowCursor
= cursor
;
731 if (m_windowCursor
.Ok())
733 WXDisplay
*dpy
= GetXDisplay();
734 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
736 Widget w
= (Widget
) GetMainWidget();
737 Window win
= XtWindow(w
);
738 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
743 // Get size *available for subwindows* i.e. excluding menu bar etc.
744 void wxWindow::GetClientSize(int *x
, int *y
) const
746 Widget widget
= (Widget
) GetClientWidget();
748 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
752 void wxWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
754 // A bit of optimization to help sort out the flickers.
755 int oldX
, oldY
, oldW
, oldH
;
756 GetSize(& oldW
, & oldH
);
757 GetPosition(& oldX
, & oldY
);
759 bool useOldPos
= FALSE
;
760 bool useOldSize
= FALSE
;
762 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
764 else if (x
== oldX
&& y
== oldY
)
767 if ((width
== -1) && (height
== -1))
769 else if (width
== oldW
&& height
== oldH
)
772 if (!wxNoOptimize::CanOptimize())
774 useOldSize
= FALSE
; useOldPos
= FALSE
;
777 if (useOldPos
&& useOldSize
)
782 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
785 Widget widget
= (Widget
) GetTopWidget();
789 bool managed
= XtIsManaged( widget
);
791 XtUnmanageChild(widget
);
793 int xx
= x
; int yy
= y
;
794 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
798 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
799 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
800 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
801 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
806 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
808 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
812 XtManageChild(widget
);
814 // How about this bit. Maybe we don't need to generate size events
815 // all the time -- they'll be generated when the window is sized anyway.
817 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
818 sizeEvent.SetEventObject(this);
820 GetEventHandler()->ProcessEvent(sizeEvent);
824 void wxWindow::DoSetClientSize(int width
, int height
)
828 CanvasSetClientSize(width
, height
);
832 Widget widget
= (Widget
) GetTopWidget();
835 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
837 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
839 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
840 sizeEvent
.SetEventObject(this);
842 GetEventHandler()->ProcessEvent(sizeEvent
);
845 // For implementation purposes - sometimes decorations make the client area
847 wxPoint
wxWindow::GetClientAreaOrigin() const
849 return wxPoint(0, 0);
852 // Makes an adjustment to the window position (for example, a frame that has
853 // a toolbar that it manages itself).
854 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
856 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
858 wxPoint
pt(GetParent()->GetClientAreaOrigin());
859 x
+= pt
.x
; y
+= pt
.y
;
863 bool wxWindow::Show(bool show
)
867 if (m_borderWidget
|| m_scrolledWindow
)
870 XtMapWidget((Widget
) m_drawingArea
);
871 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
875 WXWidget topWidget
= GetTopWidget();
877 XtMapWidget((Widget
) GetTopWidget());
878 else if (GetMainWidget())
879 XtMapWidget((Widget
) GetMainWidget());
884 if (m_borderWidget
|| m_scrolledWindow
)
887 XtUnmapWidget((Widget
) m_drawingArea
);
888 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
893 XtUnmapWidget((Widget
) GetTopWidget());
894 else if (GetMainWidget())
895 XtUnmapWidget((Widget
) GetMainWidget());
900 Window xwin = (Window) GetXWindow();
901 Display *xdisp = (Display*) GetXDisplay();
903 XMapWindow(xdisp, xwin);
905 XUnmapWindow(xdisp, xwin);
913 bool wxWindow::IsShown() const
918 int wxWindow::GetCharHeight() const
920 if (!m_windowFont
.Ok())
923 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
925 int direction
, ascent
, descent
;
927 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
929 // return (overall.ascent + overall.descent);
930 return (ascent
+ descent
);
933 int wxWindow::GetCharWidth() const
935 if (!m_windowFont
.Ok())
938 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
940 int direction
, ascent
, descent
;
942 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
944 return overall
.width
;
947 /* Helper function for 16-bit fonts */
948 static int str16len(const char *s
)
952 while (s
[0] && s
[1]) {
960 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
961 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
963 wxFont
*fontToUse
= (wxFont
*)theFont
;
965 fontToUse
= (wxFont
*) & m_windowFont
;
967 if (!fontToUse
->Ok())
970 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
972 int direction
, ascent
, descent2
;
976 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
979 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
980 &ascent
, &descent2
, &overall
);
982 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
983 &ascent
, &descent2
, &overall
);
985 *x
= (overall
.width
);
986 *y
= (ascent
+ descent2
);
990 *externalLeading
= 0;
993 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
995 m_needsRefresh
= TRUE
;
996 Display
*display
= XtDisplay((Widget
) GetMainWidget());
997 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
999 XExposeEvent dummyEvent
;
1001 GetSize(&width
, &height
);
1003 dummyEvent
.type
= Expose
;
1004 dummyEvent
.display
= display
;
1005 dummyEvent
.send_event
= True
;
1006 dummyEvent
.window
= thisWindow
;
1009 dummyEvent
.x
= rect
->x
;
1010 dummyEvent
.y
= rect
->y
;
1011 dummyEvent
.width
= rect
->width
;
1012 dummyEvent
.height
= rect
->height
;
1018 dummyEvent
.width
= width
;
1019 dummyEvent
.height
= height
;
1021 dummyEvent
.count
= 0;
1025 wxClientDC
dc(this);
1026 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1027 dc
.SetBackground(backgroundBrush
);
1034 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1037 // Responds to colour changes: passes event on to children.
1038 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1040 wxNode
*node
= GetChildren().First();
1043 // Only propagate to non-top-level windows
1044 wxWindow
*win
= (wxWindow
*)node
->Data();
1045 if ( win
->GetParent() )
1047 wxSysColourChangedEvent event2
;
1048 event
.m_eventObject
= win
;
1049 win
->GetEventHandler()->ProcessEvent(event2
);
1052 node
= node
->Next();
1056 // This can be called by the app (or wxWindows) to do default processing for the current
1057 // event. Save message/event info in wxWindow so they can be used in this function.
1058 long wxWindow::Default()
1064 void wxWindow::InitDialog()
1066 wxInitDialogEvent
event(GetId());
1067 event
.SetEventObject( this );
1068 GetEventHandler()->ProcessEvent(event
);
1071 // Default init dialog behaviour is to transfer data to window
1072 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
1074 TransferDataToWindow();
1077 // Caret manipulation
1078 void wxWindow::CreateCaret(int w
, int h
)
1082 m_caretEnabled
= TRUE
;
1085 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1090 void wxWindow::ShowCaret(bool show
)
1095 void wxWindow::DestroyCaret()
1098 m_caretEnabled
= FALSE
;
1101 void wxWindow::SetCaretPos(int x
, int y
)
1106 void wxWindow::GetCaretPos(int *x
, int *y
) const
1111 wxWindow
*wxGetActiveWindow()
1117 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1124 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1127 wxFrame
*frame
= (wxFrame
*)this;
1128 Widget widget
= (Widget
) frame
->GetShellWidget();
1131 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1133 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1135 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1137 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1139 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1141 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1144 void wxWindow::Centre(int direction
)
1146 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1148 wxWindow
*father
= (wxWindow
*)GetParent();
1152 father
->GetClientSize(&panel_width
, &panel_height
);
1153 GetSize(&width
, &height
);
1154 GetPosition(&x
, &y
);
1159 if (direction
& wxHORIZONTAL
)
1160 new_x
= (int)((panel_width
- width
)/2);
1162 if (direction
& wxVERTICAL
)
1163 new_y
= (int)((panel_height
- height
)/2);
1165 SetSize(new_x
, new_y
, -1, -1);
1169 // Coordinates relative to the window
1170 void wxWindow::WarpPointer (int x
, int y
)
1172 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1175 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1181 int wxWindow::GetScrollPos(int orient
) const
1183 if (orient
== wxHORIZONTAL
)
1184 return m_scrollPosX
;
1186 return m_scrollPosY
;
1188 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1192 XtVaGetValues(scrollBar,
1193 XmNvalue, &pos, NULL);
1201 // This now returns the whole range, not just the number
1202 // of positions that we can scroll.
1203 int wxWindow::GetScrollRange(int orient
) const
1205 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1209 XtVaGetValues(scrollBar
,
1210 XmNmaximum
, &range
, NULL
);
1217 int wxWindow::GetScrollThumb(int orient
) const
1219 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1223 XtVaGetValues(scrollBar
,
1224 XmNsliderSize
, &thumb
, NULL
);
1231 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1233 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1236 XtVaSetValues (scrollBar
,
1240 if (orient
== wxHORIZONTAL
)
1247 // New function that will replace some of the above.
1248 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1249 int range
, bool WXUNUSED(refresh
))
1252 GetSize(& oldW
, & oldH
);
1256 if (thumbVisible
== 0)
1259 if (thumbVisible
> range
)
1260 thumbVisible
= range
;
1262 // Save the old state to see if it changed
1263 WXWidget oldScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1265 if (orient
== wxHORIZONTAL
)
1267 if (thumbVisible
== range
)
1270 DestroyScrollbar(wxHORIZONTAL
);
1275 CreateScrollbar(wxHORIZONTAL
);
1278 if (orient
== wxVERTICAL
)
1280 if (thumbVisible
== range
)
1283 DestroyScrollbar(wxVERTICAL
);
1288 CreateScrollbar(wxVERTICAL
);
1291 WXWidget newScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1293 if (oldScrollBar
!= newScrollBar
)
1295 // This is important! Without it, scrollbars misbehave
1297 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
1298 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
1299 XtRealizeWidget((Widget
) m_scrolledWindow
);
1300 XtManageChild((Widget
) m_scrolledWindow
);
1304 XtVaSetValues((Widget
) newScrollBar
,
1308 XmNsliderSize
, thumbVisible
,
1311 if (orient
== wxHORIZONTAL
)
1317 GetSize(& newW
, & newH
);
1319 // Adjusting scrollbars can resize the canvas accidentally
1320 if (newW
!= oldW
|| newH
!= oldH
)
1321 SetSize(-1, -1, oldW
, oldH
);
1324 // Does a physical scroll
1325 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1327 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1331 // Use specified rectangle
1332 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1336 // Use whole client area
1338 GetClientSize(& w
, & h
);
1341 int x1
= (dx
>= 0) ? x
: x
- dx
;
1342 int y1
= (dy
>= 0) ? y
: y
- dy
;
1343 int w1
= w
- abs(dx
);
1344 int h1
= h
- abs(dy
);
1345 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1346 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1348 wxClientDC
dc(this);
1350 dc
.SetLogicalFunction (wxCOPY
);
1352 Widget widget
= (Widget
) GetMainWidget();
1353 Window window
= XtWindow(widget
);
1354 Display
* display
= XtDisplay(widget
);
1356 XCopyArea(display
, window
,
1357 window
, (GC
) dc
.GetGC(),
1362 dc
.SetAutoSetting(TRUE
);
1363 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1364 dc
.SetBrush(brush
); // ??
1366 // We'll add rectangles to the list of update rectangles
1367 // according to which bits we've exposed.
1372 wxRect
*rect
= new wxRect
;
1378 XFillRectangle(display
, window
,
1379 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1383 rect
->width
= rect
->width
;
1384 rect
->height
= rect
->height
;
1386 updateRects
.Append((wxObject
*) rect
);
1390 wxRect
*rect
= new wxRect
;
1392 rect
->x
= x
+ w
+ dx
;
1397 XFillRectangle(display
, window
,
1398 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1403 rect
->width
= rect
->width
;
1404 rect
->height
= rect
->height
;
1406 updateRects
.Append((wxObject
*) rect
);
1410 wxRect
*rect
= new wxRect
;
1417 XFillRectangle(display
, window
,
1418 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1422 rect
->width
= rect
->width
;
1423 rect
->height
= rect
->height
;
1425 updateRects
.Append((wxObject
*) rect
);
1429 wxRect
*rect
= new wxRect
;
1432 rect
->y
= y
+ h
+ dy
;
1436 XFillRectangle(display
, window
,
1437 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1441 rect
->width
= rect
->width
;
1442 rect
->height
= rect
->height
;
1444 updateRects
.Append((wxObject
*) rect
);
1446 dc
.SetBrush(wxNullBrush
);
1448 // Now send expose events
1450 wxNode
* node
= updateRects
.First();
1453 wxRect
* rect
= (wxRect
*) node
->Data();
1456 event
.type
= Expose
;
1457 event
.display
= display
;
1458 event
.send_event
= True
;
1459 event
.window
= window
;
1463 event
.width
= rect
->width
;
1464 event
.height
= rect
->height
;
1468 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1470 node
= node
->Next();
1474 // Delete the update rects
1475 node
= updateRects
.First();
1478 wxRect
* rect
= (wxRect
*) node
->Data();
1480 node
= node
->Next();
1483 XmUpdateDisplay((Widget
) GetMainWidget());
1486 void wxWindow::OnChar(wxKeyEvent
& event
)
1490 if ( event.KeyCode() == WXK_TAB ) {
1491 // propagate the TABs to the parent - it's up to it to decide what
1493 if ( GetParent() ) {
1494 if ( GetParent()->ProcessEvent(event) )
1501 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1506 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1511 void wxWindow::OnPaint(wxPaintEvent
& event
)
1516 bool wxWindow::IsEnabled() const
1518 // TODO. Is this right?
1519 // return XtGetSensitive((Widget) GetMainWidget());
1523 // Dialog support: override these and call
1524 // base class members to add functionality
1525 // that can't be done using validators.
1526 // NOTE: these functions assume that controls
1527 // are direct children of this window, not grandchildren
1528 // or other levels of descendant.
1530 // Transfer values to controls. If returns FALSE,
1531 // it's an application error (pops up a dialog)
1532 bool wxWindow::TransferDataToWindow()
1534 wxNode
*node
= GetChildren().First();
1537 wxWindow
*child
= (wxWindow
*)node
->Data();
1538 if ( child
->GetValidator() &&
1539 !child
->GetValidator()->TransferToWindow() )
1541 wxLogError("Could not transfer data to window.");
1545 node
= node
->Next();
1550 // Transfer values from controls. If returns FALSE,
1551 // validation failed: don't quit
1552 bool wxWindow::TransferDataFromWindow()
1554 wxNode
*node
= GetChildren().First();
1557 wxWindow
*child
= (wxWindow
*)node
->Data();
1558 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1563 node
= node
->Next();
1568 bool wxWindow::Validate()
1570 wxNode
*node
= GetChildren().First();
1573 wxWindow
*child
= (wxWindow
*)node
->Data();
1574 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1579 node
= node
->Next();
1584 // Get the window with the focus
1585 wxWindow
*wxWindow::FindFocus()
1588 // (1) Can there be multiple focussed widgets in an application?
1589 // In which case we need to find the top-level window that's
1590 // currently active.
1591 // (2) The widget with the focus may not be in the widget table
1592 // depending on which widgets I put in the table
1594 wxNode
*node
= wxTopLevelWindows
.First();
1597 wxWindow
*win
= (wxWindow
*)node
->Data();
1599 Widget w
= XmGetFocusWidget ((Widget
) win
->GetTopWidget()) ;
1601 if (w
!= (Widget
) NULL
)
1603 wxWindow
* focusWin
= wxGetWindowFromTable(w
);
1608 node
= node
->Next();
1610 return (wxWindow
*) NULL
;
1613 void wxWindow::AddChild(wxWindow
*child
)
1615 GetChildren().Append(child
);
1616 child
->m_windowParent
= this;
1619 void wxWindow::RemoveChild(wxWindow
*child
)
1621 GetChildren().DeleteObject(child
);
1622 child
->m_windowParent
= NULL
;
1625 // Reparents this window to have the new parent.
1626 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1628 // For now, we indicate that this isn't implemented.
1632 void wxWindow::DestroyChildren()
1634 wxNode
*node
= GetChildren().First();
1637 wxNode
* next
= node
->Next();
1638 wxWindow
* child
= (wxWindow
*) node
->Data();
1642 GetChildren().Clear();
1645 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1647 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1649 if ( GetChildren().Member(child
) )
1656 void wxWindow::MakeModal(bool modal
)
1658 // Disable all other windows
1659 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1661 wxNode
*node
= wxTopLevelWindows
.First();
1664 wxWindow
*win
= (wxWindow
*)node
->Data();
1666 win
->Enable(!modal
);
1668 node
= node
->Next();
1673 // If nothing defined for this, try the parent.
1674 // E.g. we may be a button loaded from a resource, with no callback function
1676 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1678 if (GetEventHandler()->ProcessEvent(event
) )
1681 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1684 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1688 UnsetConstraints(m_constraints
);
1689 delete m_constraints
;
1694 // Make sure other windows know they're part of a 'meaningful relationship'
1695 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1696 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1697 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1698 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1699 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1700 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1701 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1702 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1703 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1704 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1705 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1706 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1707 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1708 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1709 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1710 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1714 // This removes any dangling pointers to this window
1715 // in other windows' constraintsInvolvedIn lists.
1716 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1720 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1721 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1722 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1723 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1724 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1725 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1726 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1727 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1728 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1729 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1730 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1731 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1732 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1733 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1734 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1735 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1739 // Back-pointer to other windows we're involved with, so if we delete
1740 // this window, we must delete any constraints we're involved with.
1741 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1743 if (!m_constraintsInvolvedIn
)
1744 m_constraintsInvolvedIn
= new wxList
;
1745 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1746 m_constraintsInvolvedIn
->Append(otherWin
);
1749 // REMOVE back-pointer to other windows we're involved with.
1750 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1752 if (m_constraintsInvolvedIn
)
1753 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1756 // Reset any constraints that mention this window
1757 void wxWindow::DeleteRelatedConstraints()
1759 if (m_constraintsInvolvedIn
)
1761 wxNode
*node
= m_constraintsInvolvedIn
->First();
1764 wxWindow
*win
= (wxWindow
*)node
->Data();
1765 wxNode
*next
= node
->Next();
1766 wxLayoutConstraints
*constr
= win
->GetConstraints();
1768 // Reset any constraints involving this window
1771 constr
->left
.ResetIfWin((wxWindow
*)this);
1772 constr
->top
.ResetIfWin((wxWindow
*)this);
1773 constr
->right
.ResetIfWin((wxWindow
*)this);
1774 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1775 constr
->width
.ResetIfWin((wxWindow
*)this);
1776 constr
->height
.ResetIfWin((wxWindow
*)this);
1777 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1778 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1783 delete m_constraintsInvolvedIn
;
1784 m_constraintsInvolvedIn
= NULL
;
1788 void wxWindow::SetSizer(wxSizer
*sizer
)
1790 m_windowSizer
= sizer
;
1792 sizer
->SetSizerParent((wxWindow
*)this);
1799 bool wxWindow::Layout()
1801 if (GetConstraints())
1804 GetClientSize(&w
, &h
);
1805 GetConstraints()->width
.SetValue(w
);
1806 GetConstraints()->height
.SetValue(h
);
1809 // If top level (one sizer), evaluate the sizer's constraints.
1813 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1814 GetSizer()->LayoutPhase1(&noChanges
);
1815 GetSizer()->LayoutPhase2(&noChanges
);
1816 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1821 // Otherwise, evaluate child constraints
1822 ResetConstraints(); // Mark all constraints as unevaluated
1823 DoPhase(1); // Just one phase need if no sizers involved
1825 SetConstraintSizes(); // Recursively set the real window sizes
1831 // Do a phase of evaluating constraints:
1832 // the default behaviour. wxSizers may do a similar
1833 // thing, but also impose their own 'constraints'
1834 // and order the evaluation differently.
1835 bool wxWindow::LayoutPhase1(int *noChanges
)
1837 wxLayoutConstraints
*constr
= GetConstraints();
1840 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1846 bool wxWindow::LayoutPhase2(int *noChanges
)
1856 // Do a phase of evaluating child constraints
1857 bool wxWindow::DoPhase(int phase
)
1859 int noIterations
= 0;
1860 int maxIterations
= 500;
1864 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1868 wxNode
*node
= GetChildren().First();
1871 wxWindow
*child
= (wxWindow
*)node
->Data();
1872 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1874 wxLayoutConstraints
*constr
= child
->GetConstraints();
1877 if (succeeded
.Member(child
))
1882 int tempNoChanges
= 0;
1883 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1884 noChanges
+= tempNoChanges
;
1887 succeeded
.Append(child
);
1892 node
= node
->Next();
1899 void wxWindow::ResetConstraints()
1901 wxLayoutConstraints
*constr
= GetConstraints();
1904 constr
->left
.SetDone(FALSE
);
1905 constr
->top
.SetDone(FALSE
);
1906 constr
->right
.SetDone(FALSE
);
1907 constr
->bottom
.SetDone(FALSE
);
1908 constr
->width
.SetDone(FALSE
);
1909 constr
->height
.SetDone(FALSE
);
1910 constr
->centreX
.SetDone(FALSE
);
1911 constr
->centreY
.SetDone(FALSE
);
1913 wxNode
*node
= GetChildren().First();
1916 wxWindow
*win
= (wxWindow
*)node
->Data();
1917 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1918 win
->ResetConstraints();
1919 node
= node
->Next();
1923 // Need to distinguish between setting the 'fake' size for
1924 // windows and sizers, and setting the real values.
1925 void wxWindow::SetConstraintSizes(bool recurse
)
1927 wxLayoutConstraints
*constr
= GetConstraints();
1928 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1929 constr
->width
.GetDone() && constr
->height
.GetDone())
1931 int x
= constr
->left
.GetValue();
1932 int y
= constr
->top
.GetValue();
1933 int w
= constr
->width
.GetValue();
1934 int h
= constr
->height
.GetValue();
1936 // If we don't want to resize this window, just move it...
1937 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1938 (constr
->height
.GetRelationship() != wxAsIs
))
1940 // Calls Layout() recursively. AAAGH. How can we stop that.
1941 // Simply take Layout() out of non-top level OnSizes.
1942 SizerSetSize(x
, y
, w
, h
);
1951 char *windowClass
= this->GetClassInfo()->GetClassName();
1954 if (GetName() == "")
1955 winName
= "unnamed";
1957 winName
= GetName();
1958 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1959 if (!constr
->left
.GetDone())
1960 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1961 if (!constr
->right
.GetDone())
1962 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1963 if (!constr
->width
.GetDone())
1964 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1965 if (!constr
->height
.GetDone())
1966 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1967 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1972 wxNode
*node
= GetChildren().First();
1975 wxWindow
*win
= (wxWindow
*)node
->Data();
1976 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1977 win
->SetConstraintSizes();
1978 node
= node
->Next();
1983 // This assumes that all sizers are 'on' the same
1984 // window, i.e. the parent of this window.
1985 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1987 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1988 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1992 m_sizerParent
->GetPosition(&xp
, &yp
);
1993 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1998 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
2002 TransformSizerToActual(&xx
, &yy
);
2003 SetSize(xx
, yy
, w
, h
);
2006 void wxWindow::SizerMove(int x
, int y
)
2010 TransformSizerToActual(&xx
, &yy
);
2014 // Only set the size/position of the constraint (if any)
2015 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
2017 wxLayoutConstraints
*constr
= GetConstraints();
2022 constr
->left
.SetValue(x
);
2023 constr
->left
.SetDone(TRUE
);
2027 constr
->top
.SetValue(y
);
2028 constr
->top
.SetDone(TRUE
);
2032 constr
->width
.SetValue(w
);
2033 constr
->width
.SetDone(TRUE
);
2037 constr
->height
.SetValue(h
);
2038 constr
->height
.SetDone(TRUE
);
2043 void wxWindow::MoveConstraint(int x
, int y
)
2045 wxLayoutConstraints
*constr
= GetConstraints();
2050 constr
->left
.SetValue(x
);
2051 constr
->left
.SetDone(TRUE
);
2055 constr
->top
.SetValue(y
);
2056 constr
->top
.SetDone(TRUE
);
2061 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2063 wxLayoutConstraints
*constr
= GetConstraints();
2066 *w
= constr
->width
.GetValue();
2067 *h
= constr
->height
.GetValue();
2073 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2075 wxLayoutConstraints
*constr
= GetConstraints();
2078 *w
= constr
->width
.GetValue();
2079 *h
= constr
->height
.GetValue();
2082 GetClientSize(w
, h
);
2085 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2087 wxLayoutConstraints
*constr
= GetConstraints();
2090 *x
= constr
->left
.GetValue();
2091 *y
= constr
->top
.GetValue();
2097 bool wxWindow::Close(bool force
)
2099 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2100 event
.SetEventObject(this);
2101 #if WXWIN_COMPATIBILITY
2102 event
.SetForce(force
);
2104 event
.SetCanVeto(!force
);
2106 return GetEventHandler()->ProcessEvent(event
);
2109 wxObject
* wxWindow::GetChild(int number
) const
2111 // Return a pointer to the Nth object in the window
2112 wxNode
*node
= GetChildren().First();
2115 node
= node
->Next() ;
2118 wxObject
*obj
= (wxObject
*)node
->Data();
2125 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2127 // Obsolete function
2130 void wxWindow::Clear()
2132 wxClientDC
dc(this);
2133 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2134 dc
.SetBackground(brush
);
2138 // Fits the panel around the items
2139 void wxWindow::Fit()
2143 wxNode
*node
= GetChildren().First();
2146 wxWindow
*win
= (wxWindow
*)node
->Data();
2148 win
->GetPosition(&wx
, &wy
);
2149 win
->GetSize(&ww
, &wh
);
2150 if ( wx
+ ww
> maxX
)
2152 if ( wy
+ wh
> maxY
)
2155 node
= node
->Next();
2157 SetClientSize(maxX
+ 5, maxY
+ 5);
2160 void wxWindow::SetValidator(const wxValidator
& validator
)
2162 if ( m_windowValidator
)
2163 delete m_windowValidator
;
2164 m_windowValidator
= (wxValidator
*) validator
.Clone();
2166 if ( m_windowValidator
)
2167 m_windowValidator
->SetWindow(this) ;
2170 void wxWindow::SetClientObject( wxClientData
*data
)
2172 if (m_clientObject
) delete m_clientObject
;
2173 m_clientObject
= data
;
2176 wxClientData
*wxWindow::GetClientObject()
2178 return m_clientObject
;
2181 void wxWindow::SetClientData( void *data
)
2183 m_clientData
= data
;
2186 void *wxWindow::GetClientData()
2188 return m_clientData
;
2191 // Find a window by id or name
2192 wxWindow
*wxWindow::FindWindow(long id
)
2197 wxNode
*node
= GetChildren().First();
2200 wxWindow
*child
= (wxWindow
*)node
->Data();
2201 wxWindow
*found
= child
->FindWindow(id
);
2204 node
= node
->Next();
2209 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2211 if ( GetName() == name
)
2214 wxNode
*node
= GetChildren().First();
2217 wxWindow
*child
= (wxWindow
*)node
->Data();
2218 wxWindow
*found
= child
->FindWindow(name
);
2221 node
= node
->Next();
2226 void wxWindow::OnIdle(wxIdleEvent
& event
)
2228 // This calls the UI-update mechanism (querying windows for
2229 // menu/toolbar/control state information)
2233 // Raise the window to the top of the Z order
2234 void wxWindow::Raise()
2236 Window window
= XtWindow((Widget
) GetTopWidget());
2237 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2240 // Lower the window to the bottom of the Z order
2241 void wxWindow::Lower()
2243 Window window
= XtWindow((Widget
) GetTopWidget());
2244 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2247 bool wxWindow::AcceptsFocus() const
2249 return IsShown() && IsEnabled();
2252 // Update region access
2253 wxRegion
& wxWindow::GetUpdateRegion() const
2255 return (wxRegion
&) m_updateRegion
;
2258 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2260 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2263 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2265 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2268 bool wxWindow::IsExposed(const wxRect
& rect
) const
2270 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2274 * Allocates control IDs
2277 int wxWindow::NewControlId()
2279 static int s_controlId
= 0;
2284 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2286 m_acceleratorTable
= accel
;
2289 // All widgets should have this as their resize proc.
2290 // OnSize sent to wxWindow via client data.
2291 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2293 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2297 if (win
->PreResize())
2300 win
->GetSize(&width
, &height
);
2301 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2302 sizeEvent
.SetEventObject(win
);
2303 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2307 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2309 wxWindow
*oldItem
= NULL
;
2310 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2311 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2313 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2317 wxWidgetHashTable
->Put ((long) w
, win
);
2321 wxWindow
*wxGetWindowFromTable(Widget w
)
2323 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2326 void wxDeleteWindowFromTable(Widget w
)
2328 wxWidgetHashTable
->Delete((long)w
);
2331 // Get the underlying X window and display
2332 WXWindow
wxWindow::GetXWindow() const
2334 if (GetMainWidget())
2335 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2337 return (WXWindow
) 0;
2340 WXDisplay
*wxWindow::GetXDisplay() const
2342 if (GetMainWidget())
2343 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2345 return (WXDisplay
*) NULL
;
2348 WXWidget
wxWindow::GetMainWidget() const
2351 return m_drawingArea
;
2353 return m_mainWidget
;
2356 WXWidget
wxWindow::GetClientWidget() const
2358 if (m_drawingArea
!= (WXWidget
) 0)
2359 return m_drawingArea
;
2361 return GetMainWidget();
2364 WXWidget
wxWindow::GetTopWidget() const
2366 return GetMainWidget();
2369 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2370 XmDrawingAreaCallbackStruct
* cbs
)
2372 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2375 XEvent
* event
= cbs
->event
;
2376 wxWindow
* win
= (wxWindow
*) clientData
;
2377 Display
* display
= (Display
*) win
->GetXDisplay();
2379 switch (event
->type
)
2383 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2384 event
->xexpose
.width
, event
->xexpose
.height
);
2386 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2387 cout << rect->width << ", " << rect->height << "\n\n";
2390 win
->m_updateRects
.Append((wxObject
*) rect
);
2392 if (event
-> xexpose
.count
== 0)
2395 wxPaintEvent event(win->GetId());
2396 event.SetEventObject(win);
2397 win->GetEventHandler()->ProcessEvent(event);
2401 win
->ClearUpdateRects();
2407 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2413 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2415 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2417 XmDrawingAreaCallbackStruct cbs
;
2420 //if (event->mode!=NotifyNormal)
2423 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2424 ((XCrossingEvent
&) ev
) = *event
;
2426 cbs
.reason
= XmCR_INPUT
;
2429 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2432 // Fix to make it work under Motif 1.0 (!)
2433 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2437 XmDrawingAreaCallbackStruct cbs
;
2440 //ev.xbutton = *event;
2441 ev
= *((XEvent
*) event
);
2442 cbs
.reason
= XmCR_INPUT
;
2445 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2449 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2451 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2457 if (cbs
->reason
!= XmCR_INPUT
)
2460 local_event
= *(cbs
->event
); // We must keep a copy!
2463 switch (local_event.xany.type)
2466 cout << "EnterNotify\n";
2469 cout << "LeaveNotify\n";
2472 cout << "ButtonPress\n";
2475 cout << "ButtonRelease\n";
2478 cout << "MotionNotify\n";
2481 cout << "Something else\n";
2486 switch (local_event
.xany
.type
)
2494 wxEventType eventType
= wxEVT_NULL
;
2496 if (local_event
.xany
.type
== EnterNotify
)
2498 //if (local_event.xcrossing.mode!=NotifyNormal)
2499 // return ; // Ignore grab events
2500 eventType
= wxEVT_ENTER_WINDOW
;
2501 // canvas->GetEventHandler()->OnSetFocus();
2503 else if (local_event
.xany
.type
== LeaveNotify
)
2505 //if (local_event.xcrossing.mode!=NotifyNormal)
2506 // return ; // Ignore grab events
2507 eventType
= wxEVT_LEAVE_WINDOW
;
2508 // canvas->GetEventHandler()->OnKillFocus();
2510 else if (local_event
.xany
.type
== MotionNotify
)
2512 eventType
= wxEVT_MOTION
;
2513 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2516 Display
*dpy
= XtDisplay (drawingArea
);
2518 XQueryPointer (dpy
, XtWindow (drawingArea
),
2520 &local_event
.xmotion
.x_root
,
2521 &local_event
.xmotion
.y_root
,
2522 &local_event
.xmotion
.x
,
2523 &local_event
.xmotion
.y
,
2524 &local_event
.xmotion
.state
);
2531 else if (local_event
.xany
.type
== ButtonPress
)
2533 if (local_event
.xbutton
.button
== Button1
)
2535 eventType
= wxEVT_LEFT_DOWN
;
2536 canvas
->m_button1Pressed
= TRUE
;
2538 else if (local_event
.xbutton
.button
== Button2
)
2540 eventType
= wxEVT_MIDDLE_DOWN
;
2541 canvas
->m_button2Pressed
= TRUE
;
2543 else if (local_event
.xbutton
.button
== Button3
)
2545 eventType
= wxEVT_RIGHT_DOWN
;
2546 canvas
->m_button3Pressed
= TRUE
;
2549 else if (local_event
.xany
.type
== ButtonRelease
)
2551 if (local_event
.xbutton
.button
== Button1
)
2553 eventType
= wxEVT_LEFT_UP
;
2554 canvas
->m_button1Pressed
= FALSE
;
2556 else if (local_event
.xbutton
.button
== Button2
)
2558 eventType
= wxEVT_MIDDLE_UP
;
2559 canvas
->m_button2Pressed
= FALSE
;
2561 else if (local_event
.xbutton
.button
== Button3
)
2563 eventType
= wxEVT_RIGHT_UP
;
2564 canvas
->m_button3Pressed
= FALSE
;
2568 wxMouseEvent
wxevent (eventType
);
2569 wxevent
.m_eventHandle
= (char *) &local_event
;
2571 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2572 || (event_left_is_down (&local_event
)
2573 && (eventType
!= wxEVT_LEFT_UP
)));
2574 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2575 || (event_middle_is_down (&local_event
)
2576 && (eventType
!= wxEVT_MIDDLE_UP
)));
2577 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2578 || (event_right_is_down (&local_event
)
2579 && (eventType
!= wxEVT_RIGHT_UP
)));
2581 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2582 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2583 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2584 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2585 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2587 // Now check if we need to translate this event into a double click
2588 if (TRUE
) // canvas->doubleClickAllowed)
2590 if (wxevent
.ButtonDown())
2592 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2594 // get button and time-stamp
2596 if (wxevent
.LeftDown()) button
= 1;
2597 else if (wxevent
.MiddleDown()) button
= 2;
2598 else if (wxevent
.RightDown()) button
= 3;
2599 long ts
= wxevent
.GetTimestamp();
2600 // check, if single or double click
2601 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2604 canvas
->m_lastButton
= 0;
2605 switch ( eventType
)
2607 case wxEVT_LEFT_DOWN
:
2608 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2610 case wxEVT_MIDDLE_DOWN
:
2611 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2613 case wxEVT_RIGHT_DOWN
:
2614 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2624 // not fast enough or different button
2625 canvas
->m_lastTS
= ts
;
2626 canvas
->m_lastButton
= button
;
2631 wxevent
.SetId(canvas
->GetId());
2632 wxevent
.SetEventObject(canvas
);
2633 wxevent
.m_x
= local_event
.xbutton
.x
;
2634 wxevent
.m_y
= local_event
.xbutton
.y
;
2635 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2637 if (eventType == wxEVT_ENTER_WINDOW ||
2638 eventType == wxEVT_LEAVE_WINDOW ||
2639 eventType == wxEVT_MOTION
2648 // XComposeStatus compose;
2649 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2650 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2651 int id
= wxCharCodeXToWX (keySym
);
2653 wxEventType eventType
= wxEVT_CHAR
;
2655 wxKeyEvent
event (eventType
);
2657 if (local_event
.xkey
.state
& ShiftMask
)
2658 event
.m_shiftDown
= TRUE
;
2659 if (local_event
.xkey
.state
& ControlMask
)
2660 event
.m_controlDown
= TRUE
;
2661 if (local_event
.xkey
.state
& Mod3Mask
)
2662 event
.m_altDown
= TRUE
;
2663 if (local_event
.xkey
.state
& Mod1Mask
)
2664 event
.m_metaDown
= TRUE
;
2665 event
.SetEventObject(canvas
);
2666 event
.m_keyCode
= id
;
2667 event
.SetTimestamp(local_event
.xkey
.time
);
2671 // Implement wxFrame::OnCharHook by checking ancestor.
2672 wxWindow
*parent
= canvas
->GetParent();
2673 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2674 parent
= parent
->GetParent();
2678 event
.SetEventType(wxEVT_CHAR_HOOK
);
2679 if (parent
->GetEventHandler()->ProcessEvent(event
))
2683 // For simplicity, OnKeyDown is the same as OnChar
2684 // TODO: filter modifier key presses from OnChar
2685 event
.SetEventType(wxEVT_KEY_DOWN
);
2687 // Only process OnChar if OnKeyDown didn't swallow it
2688 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2690 event
.SetEventType(wxEVT_CHAR
);
2691 canvas
->GetEventHandler()->ProcessEvent (event
);
2699 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2700 int id
= wxCharCodeXToWX (keySym
);
2702 wxKeyEvent
event (wxEVT_KEY_UP
);
2704 if (local_event
.xkey
.state
& ShiftMask
)
2705 event
.m_shiftDown
= TRUE
;
2706 if (local_event
.xkey
.state
& ControlMask
)
2707 event
.m_controlDown
= TRUE
;
2708 if (local_event
.xkey
.state
& Mod3Mask
)
2709 event
.m_altDown
= TRUE
;
2710 if (local_event
.xkey
.state
& Mod1Mask
)
2711 event
.m_metaDown
= TRUE
;
2712 event
.SetEventObject(canvas
);
2713 event
.m_keyCode
= id
;
2714 event
.SetTimestamp(local_event
.xkey
.time
);
2718 canvas
->GetEventHandler()->ProcessEvent (event
);
2724 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2726 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2727 event
.SetEventObject(canvas
);
2728 canvas
->GetEventHandler()->ProcessEvent(event
);
2734 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2736 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2737 event
.SetEventObject(canvas
);
2738 canvas
->GetEventHandler()->ProcessEvent(event
);
2747 void wxWindow::DoPaint()
2749 //TODO : make a temporary gc so we can do the XCopyArea below
2750 if (m_backingPixmap
&& !m_needsRefresh
)
2754 GC tempGC
= (GC
) dc
.GetBackingGC();
2756 Widget widget
= (Widget
) GetMainWidget();
2761 // We have to test whether it's a wxScrolledWindow (hack!)
2762 // because otherwise we don't know how many pixels have been
2763 // scrolled. We might solve this in the future by defining
2764 // virtual wxWindow functions to get the scroll position in pixels.
2765 // Or, each kind of scrolled window has to implement backing
2766 // stores itself, using generic wxWindows code.
2767 if (this->IsKindOf(CLASSINFO(wxScrolledWindow
)))
2769 wxScrolledWindow
* scrolledWindow
= (wxScrolledWindow
*) this;
2771 scrolledWindow
->CalcScrolledPosition(0, 0, & x
, & y
);
2777 // TODO: This could be optimized further by only copying the
2778 // areas in the current update region.
2780 // Only blit the part visible in the client area. The backing pixmap
2781 // always starts at 0, 0 but we may be looking at only a portion of it.
2782 wxSize clientArea
= GetClientSize();
2783 int toBlitX
= m_pixmapWidth
- scrollPosX
;
2784 int toBlitY
= m_pixmapHeight
- scrollPosY
;
2786 // Copy whichever is samller, the amount of pixmap we have to copy,
2787 // or the size of the client area.
2788 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
2789 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
2791 // Make sure we're not negative
2792 toBlitX
= wxMax(0, toBlitX
);
2793 toBlitY
= wxMax(0, toBlitY
);
2795 XCopyArea (XtDisplay (widget
), (Pixmap
) m_backingPixmap
, XtWindow (widget
), tempGC
,
2796 scrollPosX
, scrollPosY
, // Start at the scroll position
2797 toBlitX
, toBlitY
, // How much of the pixmap to copy
2798 0, 0); // Destination
2802 // Set an erase event first
2803 wxEraseEvent
eraseEvent(GetId());
2804 eraseEvent
.SetEventObject(this);
2805 GetEventHandler()->ProcessEvent(eraseEvent
);
2807 wxPaintEvent
event(GetId());
2808 event
.SetEventObject(this);
2809 GetEventHandler()->ProcessEvent(event
);
2811 m_needsRefresh
= FALSE
;
2815 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2816 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2818 // A bit of optimization to help sort out the flickers.
2819 int oldX
, oldY
, oldW
, oldH
;
2820 GetSize(& oldW
, & oldH
);
2821 GetPosition(& oldX
, & oldY
);
2823 bool useOldPos
= FALSE
;
2824 bool useOldSize
= FALSE
;
2826 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2828 else if (x
== oldX
&& y
== oldY
)
2831 if ((w
== -1) && (h
== -1))
2833 else if (w
== oldW
&& h
== oldH
)
2836 if (!wxNoOptimize::CanOptimize())
2838 useOldSize
= FALSE
; useOldPos
= FALSE
;
2841 if (useOldPos
&& useOldSize
)
2844 Widget drawingArea
= (Widget
) m_drawingArea
;
2845 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2848 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2849 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2851 int xx
= x
; int yy
= y
;
2852 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2856 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2858 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2862 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2864 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2876 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2877 short thick
, margin
;
2878 XtVaGetValues ((Widget
) m_borderWidget
,
2879 XmNshadowThickness
, &thick
,
2880 XmNmarginWidth
, &margin
,
2882 w
-= 2 * (thick
+ margin
);
2885 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2889 XtVaGetValues ((Widget
) m_scrolledWindow
,
2890 XmNspacing
, &spacing
,
2891 XmNverticalScrollBar
, &sbar
,
2895 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2899 w
-= (spacing
+ wsbar
);
2901 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2907 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2908 short thick
, margin
;
2909 XtVaGetValues ((Widget
) m_borderWidget
,
2910 XmNshadowThickness
, &thick
,
2911 XmNmarginHeight
, &margin
,
2913 h
-= 2 * (thick
+ margin
);
2916 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2920 XtVaGetValues ((Widget
) m_scrolledWindow
,
2921 XmNspacing
, &spacing
,
2922 XmNhorizontalScrollBar
, &sbar
,
2926 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2930 h
-= (spacing
+ wsbar
);
2932 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2938 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2939 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2943 GetClientSize (&ww, &hh);
2944 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2945 sizeEvent.SetEventObject(this);
2947 GetEventHandler()->ProcessEvent(sizeEvent);
2952 void wxWindow::CanvasSetClientSize (int w
, int h
)
2954 Widget drawingArea
= (Widget
) m_drawingArea
;
2956 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2959 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2961 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2962 /* TODO: is this necessary?
2963 allowRepainting = FALSE;
2965 XSync (XtDisplay (drawingArea), FALSE);
2967 while (XtAppPending (wxTheApp->appContext))
2969 XFlush (XtDisplay (drawingArea));
2970 XtAppNextEvent (wxTheApp->appContext, &event);
2971 XtDispatchEvent (&event);
2975 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2978 allowRepainting = TRUE;
2983 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2984 sizeEvent.SetEventObject(this);
2986 GetEventHandler()->ProcessEvent(sizeEvent);
2990 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2992 // Must return the same thing that was set via SetClientSize
2994 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2999 void wxWindow::CanvasGetSize (int *w
, int *h
) const
3002 if ((Widget
) m_borderWidget
)
3003 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
3004 else if ((Widget
) m_scrolledWindow
)
3005 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
3007 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
3013 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
3016 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
3018 // We may be faking the client origin.
3019 // So a window that's really at (0, 30) may appear
3020 // (to wxWin apps) to be at (0, 0).
3023 wxPoint
pt(GetParent()->GetClientAreaOrigin());
3032 // Add to hash table, add event handler
3033 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
3034 WXWidget formWidget
, int x
, int y
, int width
, int height
)
3036 wxAddWindowToTable((Widget
) mainWidget
, this);
3037 if (CanAddEventHandler())
3039 XtAddEventHandler((Widget
) mainWidget
,
3040 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3042 wxPanelItemEventHandler
,
3049 XtOverrideTranslations ((Widget
) mainWidget
,
3050 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3051 XtFree ((char *) ptr
);
3054 // Some widgets have a parent form widget, e.g. wxRadioBox
3057 if (!wxAddWindowToTable((Widget
) formWidget
, this))
3061 XtOverrideTranslations ((Widget
) formWidget
,
3062 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3063 XtFree ((char *) ptr
);
3070 SetSize (x
, y
, width
, height
);
3075 // Remove event handler, remove from hash table
3076 bool wxWindow::DetachWidget(WXWidget widget
)
3078 if (CanAddEventHandler())
3080 XtRemoveEventHandler((Widget
) widget
,
3081 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3083 wxPanelItemEventHandler
,
3087 wxDeleteWindowFromTable((Widget
) widget
);
3091 void wxPanelItemEventHandler (Widget wid
,
3092 XtPointer client_data
,
3094 Boolean
*continueToDispatch
)
3096 // Widget can be a label or the actual widget.
3098 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3101 wxMouseEvent
wxevent(0);
3102 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3104 window
->GetEventHandler()->ProcessEvent(wxevent
);
3107 // TODO: probably the key to allowing default behaviour
3109 // Say we set a m_doDefault flag to FALSE at the start of this
3110 // function. Then in e.g. wxWindow::OnMouseEvent we can
3111 // call Default() which sets this flag to TRUE, indicating
3112 // that default processing can happen. Thus, behaviour can appear
3113 // to be overridden just by adding an event handler and not calling
3114 // wxWindow::OnWhatever.
3115 // ALSO, maybe we can use this instead of the current way of handling
3116 // drawing area events, to simplify things.
3117 *continueToDispatch
= True
;
3120 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3121 XmScaleCallbackStruct
*cbs
)
3123 Widget scrolledWindow
= XtParent (scrollbar
);
3124 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3125 int orientation
= (int) clientData
;
3127 wxEventType eventType
= wxEVT_NULL
;
3128 switch (cbs
->reason
)
3130 case XmCR_INCREMENT
:
3132 eventType
= wxEVT_SCROLL_LINEDOWN
;
3135 case XmCR_DECREMENT
:
3137 eventType
= wxEVT_SCROLL_LINEUP
;
3142 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3145 case XmCR_VALUE_CHANGED
:
3147 // TODO: Should this be intercepted too, or will it cause
3148 // duplicate events?
3149 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3152 case XmCR_PAGE_INCREMENT
:
3154 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3157 case XmCR_PAGE_DECREMENT
:
3159 eventType
= wxEVT_SCROLL_PAGEUP
;
3164 eventType
= wxEVT_SCROLL_TOP
;
3167 case XmCR_TO_BOTTOM
:
3169 eventType
= wxEVT_SCROLL_BOTTOM
;
3174 // Should never get here
3175 wxFAIL_MSG("Unknown scroll event.");
3180 wxScrollEvent
event(eventType
, win
->GetId());
3181 event
.SetEventObject(win
);
3182 event
.SetPosition(cbs
->value
);
3183 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3185 win
->GetEventHandler()->ProcessEvent(event
);
3188 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3190 switch (xevent
->xany
.type
)
3198 wxEventType eventType
= wxEVT_NULL
;
3200 if (xevent
->xany
.type
== LeaveNotify
)
3202 win
->m_button1Pressed
= FALSE
;
3203 win
->m_button2Pressed
= FALSE
;
3204 win
->m_button3Pressed
= FALSE
;
3207 else if (xevent
->xany
.type
== MotionNotify
)
3209 eventType
= wxEVT_MOTION
;
3211 else if (xevent
->xany
.type
== ButtonPress
)
3213 if (xevent
->xbutton
.button
== Button1
)
3215 eventType
= wxEVT_LEFT_DOWN
;
3216 win
->m_button1Pressed
= TRUE
;
3218 else if (xevent
->xbutton
.button
== Button2
)
3220 eventType
= wxEVT_MIDDLE_DOWN
;
3221 win
->m_button2Pressed
= TRUE
;
3223 else if (xevent
->xbutton
.button
== Button3
)
3225 eventType
= wxEVT_RIGHT_DOWN
;
3226 win
->m_button3Pressed
= TRUE
;
3229 else if (xevent
->xany
.type
== ButtonRelease
)
3231 if (xevent
->xbutton
.button
== Button1
)
3233 eventType
= wxEVT_LEFT_UP
;
3234 win
->m_button1Pressed
= FALSE
;
3236 else if (xevent
->xbutton
.button
== Button2
)
3238 eventType
= wxEVT_MIDDLE_UP
;
3239 win
->m_button2Pressed
= FALSE
;
3241 else if (xevent
->xbutton
.button
== Button3
)
3243 eventType
= wxEVT_RIGHT_UP
;
3244 win
->m_button3Pressed
= FALSE
;
3250 wxevent
.m_eventHandle
= (char *)xevent
;
3251 wxevent
.SetEventType(eventType
);
3254 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3257 win
->GetPosition(&x2
, &y2
);
3259 // The button x/y must be translated to wxWindows
3260 // window space - the widget might be a label or button,
3264 if (widget
!= (Widget
)win
->GetMainWidget())
3270 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3271 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3273 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3274 || (event_left_is_down (xevent
)
3275 && (eventType
!= wxEVT_LEFT_UP
)));
3276 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3277 || (event_middle_is_down (xevent
)
3278 && (eventType
!= wxEVT_MIDDLE_UP
)));
3279 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3280 || (event_right_is_down (xevent
)
3281 && (eventType
!= wxEVT_RIGHT_UP
)));
3283 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3284 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3291 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3293 switch (xevent
->xany
.type
)
3300 // XComposeStatus compose;
3301 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3302 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3303 int id
= wxCharCodeXToWX (keySym
);
3305 if (xevent
->xkey
.state
& ShiftMask
)
3306 wxevent
.m_shiftDown
= TRUE
;
3307 if (xevent
->xkey
.state
& ControlMask
)
3308 wxevent
.m_controlDown
= TRUE
;
3309 if (xevent
->xkey
.state
& Mod3Mask
)
3310 wxevent
.m_altDown
= TRUE
;
3311 if (xevent
->xkey
.state
& Mod1Mask
)
3312 wxevent
.m_metaDown
= TRUE
;
3313 wxevent
.SetEventObject(win
);
3314 wxevent
.m_keyCode
= id
;
3315 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3317 wxevent
.m_x
= xevent
->xbutton
.x
;
3318 wxevent
.m_y
= xevent
->xbutton
.y
;
3332 #define YAllocColor XAllocColor
3333 XColor g_itemColors
[5];
3334 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3337 static XmColorProc colorProc
;
3339 result
= wxNO_COLORS
;
3343 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3344 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3345 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3346 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3347 if (colorProc
== (XmColorProc
) NULL
)
3349 // Get a ptr to the actual function
3350 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3351 // And set it back to motif.
3352 XmSetColorCalculation (colorProc
);
3354 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3355 &g_itemColors
[wxFORE_INDEX
],
3356 &g_itemColors
[wxSELE_INDEX
],
3357 &g_itemColors
[wxTOPS_INDEX
],
3358 &g_itemColors
[wxBOTS_INDEX
]);
3359 result
= wxBACK_COLORS
;
3363 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3364 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3365 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3366 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3367 if (result
== wxNO_COLORS
)
3368 result
= wxFORE_COLORS
;
3371 Display
*dpy
= display
;
3372 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3376 /* 5 Colours to allocate */
3377 for (int i
= 0; i
< 5; i
++)
3378 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3379 result
= wxNO_COLORS
;
3383 /* Only 1 colour to allocate */
3384 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3385 result
= wxNO_COLORS
;
3392 // Changes the foreground and background colours to be derived
3393 // from the current background colour.
3394 // To change the foreground colour, you must call SetForegroundColour
3396 void wxWindow::ChangeBackgroundColour()
3398 if (GetMainWidget())
3399 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3401 // This not necessary
3404 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3406 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3407 // Have to set the scrollbar colours back since
3408 // the scrolled window seemed to change them
3409 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3412 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3414 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3419 void wxWindow::ChangeForegroundColour()
3421 if (GetMainWidget())
3422 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3423 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3424 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3427 // Change a widget's foreground and background colours.
3429 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3431 // When should we specify the foreground, if it's calculated
3432 // by wxComputeColours?
3433 // Solution: say we start with the default (computed) foreground colour.
3434 // If we call SetForegroundColour explicitly for a control or window,
3435 // then the foreground is changed.
3436 // Therefore SetBackgroundColour computes the foreground colour, and
3437 // SetForegroundColour changes the foreground colour. The ordering is
3440 XtVaSetValues ((Widget
) widget
,
3441 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3445 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3447 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3450 XtVaSetValues ((Widget
) widget
,
3451 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3452 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3453 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3454 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3457 if (changeArmColour
)
3458 XtVaSetValues ((Widget
) widget
,
3459 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3463 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3465 m_backgroundColour
= col
;
3466 ChangeBackgroundColour();
3469 void wxWindow::SetForegroundColour(const wxColour
& col
)
3471 m_foregroundColour
= col
;
3472 ChangeForegroundColour();
3475 void wxWindow::ChangeFont(bool keepOriginalSize
)
3477 // Note that this causes the widget to be resized back
3478 // to its original size! We therefore have to set the size
3479 // back again. TODO: a better way in Motif?
3480 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3481 if (w
&& m_windowFont
.Ok())
3483 int width
, height
, width1
, height1
;
3484 GetSize(& width
, & height
);
3486 // lesstif 0.87 hangs here
3487 #ifndef LESSTIF_VERSION
3489 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3493 GetSize(& width1
, & height1
);
3494 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3496 SetSize(-1, -1, width
, height
);
3501 void wxWindow::SetFont(const wxFont
& font
)
3503 m_windowFont
= font
;
3507 void wxWindow::SetToolTip(const wxString
& tooltip
)
3512 void wxWindow::ClearUpdateRects()
3514 wxNode
* node
= m_updateRects
.First();
3517 wxRect
* rect
= (wxRect
*) node
->Data();
3519 node
= node
->Next();
3521 m_updateRects
.Clear();
3524 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3526 if (!m_acceleratorTable
.Ok())
3529 int count
= m_acceleratorTable
.GetCount();
3530 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3532 for (i
= 0; i
< count
; i
++)
3534 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3535 if (entry
->MatchesEvent(event
))
3537 // Bingo, we have a match. Now find a control
3538 // that matches the entry command id.
3540 // Need to go up to the top of the window hierarchy,
3541 // since it might be e.g. a menu item
3542 wxWindow
* parent
= this;
3543 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3544 parent
= parent
->GetParent();
3549 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3551 // Try for a menu command
3552 wxFrame
* frame
= (wxFrame
*) parent
;
3553 if (frame
->GetMenuBar())
3555 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3558 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3559 commandEvent
.SetEventObject(frame
);
3561 // If ProcessEvent returns TRUE (it was handled), then
3562 // the calling code will skip the event handling.
3563 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3568 // Find a child matching the command id
3569 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3575 // Now we process those kinds of windows that we can.
3576 // For now, only buttons.
3577 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3579 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3580 commandEvent
.SetEventObject(child
);
3581 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3588 // We didn't match the key event against an accelerator.
3593 * wxNoOptimize: switch off size optimization
3596 int wxNoOptimize::m_count
= 0;
3598 wxNoOptimize::wxNoOptimize()
3603 wxNoOptimize::~wxNoOptimize()
3608 bool wxNoOptimize::CanOptimize()
3610 return (m_count
== 0);
3613 // For repainting arbitrary windows
3614 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
3619 wxWindow
* win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
3623 switch(event
-> type
)
3627 window
= (Window
) win
-> GetXWindow();
3628 display
= (Display
*) win
-> GetXDisplay();
3630 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
3631 event
->xexpose
.width
, event
->xexpose
.height
);
3632 win
->m_updateRects
.Append((wxObject
*) rect
);
3634 if (event
-> xexpose
.count
== 0)
3638 win
->ClearUpdateRects();
3644 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";