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()
1591 void wxWindow::AddChild(wxWindow
*child
)
1593 GetChildren().Append(child
);
1594 child
->m_windowParent
= this;
1597 void wxWindow::RemoveChild(wxWindow
*child
)
1599 GetChildren().DeleteObject(child
);
1600 child
->m_windowParent
= NULL
;
1603 // Reparents this window to have the new parent.
1604 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1606 // For now, we indicate that this isn't implemented.
1610 void wxWindow::DestroyChildren()
1612 wxNode
*node
= GetChildren().First();
1615 wxNode
* next
= node
->Next();
1616 wxWindow
* child
= (wxWindow
*) node
->Data();
1620 GetChildren().Clear();
1623 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1625 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1627 if ( GetChildren().Member(child
) )
1634 void wxWindow::MakeModal(bool modal
)
1636 // Disable all other windows
1637 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1639 wxNode
*node
= wxTopLevelWindows
.First();
1642 wxWindow
*win
= (wxWindow
*)node
->Data();
1644 win
->Enable(!modal
);
1646 node
= node
->Next();
1651 // If nothing defined for this, try the parent.
1652 // E.g. we may be a button loaded from a resource, with no callback function
1654 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1656 if (GetEventHandler()->ProcessEvent(event
) )
1659 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1662 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1666 UnsetConstraints(m_constraints
);
1667 delete m_constraints
;
1672 // Make sure other windows know they're part of a 'meaningful relationship'
1673 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1674 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1675 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1676 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1677 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1678 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1679 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1680 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1681 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1682 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1683 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1684 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1685 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1686 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1687 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1688 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1692 // This removes any dangling pointers to this window
1693 // in other windows' constraintsInvolvedIn lists.
1694 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1698 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1699 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1700 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1701 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1702 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1703 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1704 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1705 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1706 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1707 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1708 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1709 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1710 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1711 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1712 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1713 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1717 // Back-pointer to other windows we're involved with, so if we delete
1718 // this window, we must delete any constraints we're involved with.
1719 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1721 if (!m_constraintsInvolvedIn
)
1722 m_constraintsInvolvedIn
= new wxList
;
1723 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1724 m_constraintsInvolvedIn
->Append(otherWin
);
1727 // REMOVE back-pointer to other windows we're involved with.
1728 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1730 if (m_constraintsInvolvedIn
)
1731 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1734 // Reset any constraints that mention this window
1735 void wxWindow::DeleteRelatedConstraints()
1737 if (m_constraintsInvolvedIn
)
1739 wxNode
*node
= m_constraintsInvolvedIn
->First();
1742 wxWindow
*win
= (wxWindow
*)node
->Data();
1743 wxNode
*next
= node
->Next();
1744 wxLayoutConstraints
*constr
= win
->GetConstraints();
1746 // Reset any constraints involving this window
1749 constr
->left
.ResetIfWin((wxWindow
*)this);
1750 constr
->top
.ResetIfWin((wxWindow
*)this);
1751 constr
->right
.ResetIfWin((wxWindow
*)this);
1752 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1753 constr
->width
.ResetIfWin((wxWindow
*)this);
1754 constr
->height
.ResetIfWin((wxWindow
*)this);
1755 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1756 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1761 delete m_constraintsInvolvedIn
;
1762 m_constraintsInvolvedIn
= NULL
;
1766 void wxWindow::SetSizer(wxSizer
*sizer
)
1768 m_windowSizer
= sizer
;
1770 sizer
->SetSizerParent((wxWindow
*)this);
1777 bool wxWindow::Layout()
1779 if (GetConstraints())
1782 GetClientSize(&w
, &h
);
1783 GetConstraints()->width
.SetValue(w
);
1784 GetConstraints()->height
.SetValue(h
);
1787 // If top level (one sizer), evaluate the sizer's constraints.
1791 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1792 GetSizer()->LayoutPhase1(&noChanges
);
1793 GetSizer()->LayoutPhase2(&noChanges
);
1794 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1799 // Otherwise, evaluate child constraints
1800 ResetConstraints(); // Mark all constraints as unevaluated
1801 DoPhase(1); // Just one phase need if no sizers involved
1803 SetConstraintSizes(); // Recursively set the real window sizes
1809 // Do a phase of evaluating constraints:
1810 // the default behaviour. wxSizers may do a similar
1811 // thing, but also impose their own 'constraints'
1812 // and order the evaluation differently.
1813 bool wxWindow::LayoutPhase1(int *noChanges
)
1815 wxLayoutConstraints
*constr
= GetConstraints();
1818 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1824 bool wxWindow::LayoutPhase2(int *noChanges
)
1834 // Do a phase of evaluating child constraints
1835 bool wxWindow::DoPhase(int phase
)
1837 int noIterations
= 0;
1838 int maxIterations
= 500;
1842 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1846 wxNode
*node
= GetChildren().First();
1849 wxWindow
*child
= (wxWindow
*)node
->Data();
1850 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1852 wxLayoutConstraints
*constr
= child
->GetConstraints();
1855 if (succeeded
.Member(child
))
1860 int tempNoChanges
= 0;
1861 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1862 noChanges
+= tempNoChanges
;
1865 succeeded
.Append(child
);
1870 node
= node
->Next();
1877 void wxWindow::ResetConstraints()
1879 wxLayoutConstraints
*constr
= GetConstraints();
1882 constr
->left
.SetDone(FALSE
);
1883 constr
->top
.SetDone(FALSE
);
1884 constr
->right
.SetDone(FALSE
);
1885 constr
->bottom
.SetDone(FALSE
);
1886 constr
->width
.SetDone(FALSE
);
1887 constr
->height
.SetDone(FALSE
);
1888 constr
->centreX
.SetDone(FALSE
);
1889 constr
->centreY
.SetDone(FALSE
);
1891 wxNode
*node
= GetChildren().First();
1894 wxWindow
*win
= (wxWindow
*)node
->Data();
1895 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1896 win
->ResetConstraints();
1897 node
= node
->Next();
1901 // Need to distinguish between setting the 'fake' size for
1902 // windows and sizers, and setting the real values.
1903 void wxWindow::SetConstraintSizes(bool recurse
)
1905 wxLayoutConstraints
*constr
= GetConstraints();
1906 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1907 constr
->width
.GetDone() && constr
->height
.GetDone())
1909 int x
= constr
->left
.GetValue();
1910 int y
= constr
->top
.GetValue();
1911 int w
= constr
->width
.GetValue();
1912 int h
= constr
->height
.GetValue();
1914 // If we don't want to resize this window, just move it...
1915 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1916 (constr
->height
.GetRelationship() != wxAsIs
))
1918 // Calls Layout() recursively. AAAGH. How can we stop that.
1919 // Simply take Layout() out of non-top level OnSizes.
1920 SizerSetSize(x
, y
, w
, h
);
1929 char *windowClass
= this->GetClassInfo()->GetClassName();
1932 if (GetName() == "")
1933 winName
= "unnamed";
1935 winName
= GetName();
1936 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1937 if (!constr
->left
.GetDone())
1938 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1939 if (!constr
->right
.GetDone())
1940 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1941 if (!constr
->width
.GetDone())
1942 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1943 if (!constr
->height
.GetDone())
1944 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1945 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1950 wxNode
*node
= GetChildren().First();
1953 wxWindow
*win
= (wxWindow
*)node
->Data();
1954 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1955 win
->SetConstraintSizes();
1956 node
= node
->Next();
1961 // This assumes that all sizers are 'on' the same
1962 // window, i.e. the parent of this window.
1963 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1965 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1966 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1970 m_sizerParent
->GetPosition(&xp
, &yp
);
1971 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1976 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1980 TransformSizerToActual(&xx
, &yy
);
1981 SetSize(xx
, yy
, w
, h
);
1984 void wxWindow::SizerMove(int x
, int y
)
1988 TransformSizerToActual(&xx
, &yy
);
1992 // Only set the size/position of the constraint (if any)
1993 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1995 wxLayoutConstraints
*constr
= GetConstraints();
2000 constr
->left
.SetValue(x
);
2001 constr
->left
.SetDone(TRUE
);
2005 constr
->top
.SetValue(y
);
2006 constr
->top
.SetDone(TRUE
);
2010 constr
->width
.SetValue(w
);
2011 constr
->width
.SetDone(TRUE
);
2015 constr
->height
.SetValue(h
);
2016 constr
->height
.SetDone(TRUE
);
2021 void wxWindow::MoveConstraint(int x
, int y
)
2023 wxLayoutConstraints
*constr
= GetConstraints();
2028 constr
->left
.SetValue(x
);
2029 constr
->left
.SetDone(TRUE
);
2033 constr
->top
.SetValue(y
);
2034 constr
->top
.SetDone(TRUE
);
2039 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2041 wxLayoutConstraints
*constr
= GetConstraints();
2044 *w
= constr
->width
.GetValue();
2045 *h
= constr
->height
.GetValue();
2051 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2053 wxLayoutConstraints
*constr
= GetConstraints();
2056 *w
= constr
->width
.GetValue();
2057 *h
= constr
->height
.GetValue();
2060 GetClientSize(w
, h
);
2063 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2065 wxLayoutConstraints
*constr
= GetConstraints();
2068 *x
= constr
->left
.GetValue();
2069 *y
= constr
->top
.GetValue();
2075 bool wxWindow::Close(bool force
)
2077 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2078 event
.SetEventObject(this);
2079 #if WXWIN_COMPATIBILITY
2080 event
.SetForce(force
);
2082 event
.SetCanVeto(!force
);
2084 return GetEventHandler()->ProcessEvent(event
);
2087 wxObject
* wxWindow::GetChild(int number
) const
2089 // Return a pointer to the Nth object in the window
2090 wxNode
*node
= GetChildren().First();
2093 node
= node
->Next() ;
2096 wxObject
*obj
= (wxObject
*)node
->Data();
2103 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2105 // Obsolete function
2108 void wxWindow::Clear()
2110 wxClientDC
dc(this);
2111 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2112 dc
.SetBackground(brush
);
2116 // Fits the panel around the items
2117 void wxWindow::Fit()
2121 wxNode
*node
= GetChildren().First();
2124 wxWindow
*win
= (wxWindow
*)node
->Data();
2126 win
->GetPosition(&wx
, &wy
);
2127 win
->GetSize(&ww
, &wh
);
2128 if ( wx
+ ww
> maxX
)
2130 if ( wy
+ wh
> maxY
)
2133 node
= node
->Next();
2135 SetClientSize(maxX
+ 5, maxY
+ 5);
2138 void wxWindow::SetValidator(const wxValidator
& validator
)
2140 if ( m_windowValidator
)
2141 delete m_windowValidator
;
2142 m_windowValidator
= validator
.Clone();
2144 if ( m_windowValidator
)
2145 m_windowValidator
->SetWindow(this) ;
2148 void wxWindow::SetClientObject( wxClientData
*data
)
2150 if (m_clientObject
) delete m_clientObject
;
2151 m_clientObject
= data
;
2154 wxClientData
*wxWindow::GetClientObject()
2156 return m_clientObject
;
2159 void wxWindow::SetClientData( void *data
)
2161 m_clientData
= data
;
2164 void *wxWindow::GetClientData()
2166 return m_clientData
;
2169 // Find a window by id or name
2170 wxWindow
*wxWindow::FindWindow(long id
)
2175 wxNode
*node
= GetChildren().First();
2178 wxWindow
*child
= (wxWindow
*)node
->Data();
2179 wxWindow
*found
= child
->FindWindow(id
);
2182 node
= node
->Next();
2187 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2189 if ( GetName() == name
)
2192 wxNode
*node
= GetChildren().First();
2195 wxWindow
*child
= (wxWindow
*)node
->Data();
2196 wxWindow
*found
= child
->FindWindow(name
);
2199 node
= node
->Next();
2204 void wxWindow::OnIdle(wxIdleEvent
& event
)
2206 // This calls the UI-update mechanism (querying windows for
2207 // menu/toolbar/control state information)
2211 // Raise the window to the top of the Z order
2212 void wxWindow::Raise()
2214 Window window
= XtWindow((Widget
) GetTopWidget());
2215 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2218 // Lower the window to the bottom of the Z order
2219 void wxWindow::Lower()
2221 Window window
= XtWindow((Widget
) GetTopWidget());
2222 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2225 bool wxWindow::AcceptsFocus() const
2227 return IsShown() && IsEnabled();
2230 // Update region access
2231 wxRegion
& wxWindow::GetUpdateRegion() const
2233 return (wxRegion
&) m_updateRegion
;
2236 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2238 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2241 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2243 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2246 bool wxWindow::IsExposed(const wxRect
& rect
) const
2248 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2252 * Allocates control IDs
2255 int wxWindow::NewControlId()
2257 static int s_controlId
= 0;
2262 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2264 m_acceleratorTable
= accel
;
2267 // All widgets should have this as their resize proc.
2268 // OnSize sent to wxWindow via client data.
2269 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2271 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2275 if (win
->PreResize())
2278 win
->GetSize(&width
, &height
);
2279 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2280 sizeEvent
.SetEventObject(win
);
2281 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2285 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2287 wxWindow
*oldItem
= NULL
;
2288 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2289 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2291 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2295 wxWidgetHashTable
->Put ((long) w
, win
);
2299 wxWindow
*wxGetWindowFromTable(Widget w
)
2301 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2304 void wxDeleteWindowFromTable(Widget w
)
2306 wxWidgetHashTable
->Delete((long)w
);
2309 // Get the underlying X window and display
2310 WXWindow
wxWindow::GetXWindow() const
2312 if (GetMainWidget())
2313 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2315 return (WXWindow
) 0;
2318 WXDisplay
*wxWindow::GetXDisplay() const
2320 if (GetMainWidget())
2321 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2323 return (WXDisplay
*) NULL
;
2326 WXWidget
wxWindow::GetMainWidget() const
2329 return m_drawingArea
;
2331 return m_mainWidget
;
2334 WXWidget
wxWindow::GetClientWidget() const
2336 if (m_drawingArea
!= (WXWidget
) 0)
2337 return m_drawingArea
;
2339 return GetMainWidget();
2342 WXWidget
wxWindow::GetTopWidget() const
2344 return GetMainWidget();
2347 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2348 XmDrawingAreaCallbackStruct
* cbs
)
2350 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2353 XEvent
* event
= cbs
->event
;
2354 wxWindow
* win
= (wxWindow
*) clientData
;
2355 Display
* display
= (Display
*) win
->GetXDisplay();
2357 switch (event
->type
)
2361 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2362 event
->xexpose
.width
, event
->xexpose
.height
);
2364 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2365 cout << rect->width << ", " << rect->height << "\n\n";
2368 win
->m_updateRects
.Append((wxObject
*) rect
);
2370 if (event
-> xexpose
.count
== 0)
2373 wxPaintEvent event(win->GetId());
2374 event.SetEventObject(win);
2375 win->GetEventHandler()->ProcessEvent(event);
2379 win
->ClearUpdateRects();
2385 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2391 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2393 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2395 XmDrawingAreaCallbackStruct cbs
;
2398 //if (event->mode!=NotifyNormal)
2401 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2402 ((XCrossingEvent
&) ev
) = *event
;
2404 cbs
.reason
= XmCR_INPUT
;
2407 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2410 // Fix to make it work under Motif 1.0 (!)
2411 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2415 XmDrawingAreaCallbackStruct cbs
;
2418 //ev.xbutton = *event;
2419 ev
= *((XEvent
*) event
);
2420 cbs
.reason
= XmCR_INPUT
;
2423 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2427 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2429 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2435 if (cbs
->reason
!= XmCR_INPUT
)
2438 local_event
= *(cbs
->event
); // We must keep a copy!
2441 switch (local_event.xany.type)
2444 cout << "EnterNotify\n";
2447 cout << "LeaveNotify\n";
2450 cout << "ButtonPress\n";
2453 cout << "ButtonRelease\n";
2456 cout << "MotionNotify\n";
2459 cout << "Something else\n";
2464 switch (local_event
.xany
.type
)
2472 wxEventType eventType
= wxEVT_NULL
;
2474 if (local_event
.xany
.type
== EnterNotify
)
2476 //if (local_event.xcrossing.mode!=NotifyNormal)
2477 // return ; // Ignore grab events
2478 eventType
= wxEVT_ENTER_WINDOW
;
2479 // canvas->GetEventHandler()->OnSetFocus();
2481 else if (local_event
.xany
.type
== LeaveNotify
)
2483 //if (local_event.xcrossing.mode!=NotifyNormal)
2484 // return ; // Ignore grab events
2485 eventType
= wxEVT_LEAVE_WINDOW
;
2486 // canvas->GetEventHandler()->OnKillFocus();
2488 else if (local_event
.xany
.type
== MotionNotify
)
2490 eventType
= wxEVT_MOTION
;
2491 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2494 Display
*dpy
= XtDisplay (drawingArea
);
2496 XQueryPointer (dpy
, XtWindow (drawingArea
),
2498 &local_event
.xmotion
.x_root
,
2499 &local_event
.xmotion
.y_root
,
2500 &local_event
.xmotion
.x
,
2501 &local_event
.xmotion
.y
,
2502 &local_event
.xmotion
.state
);
2509 else if (local_event
.xany
.type
== ButtonPress
)
2511 if (local_event
.xbutton
.button
== Button1
)
2513 eventType
= wxEVT_LEFT_DOWN
;
2514 canvas
->m_button1Pressed
= TRUE
;
2516 else if (local_event
.xbutton
.button
== Button2
)
2518 eventType
= wxEVT_MIDDLE_DOWN
;
2519 canvas
->m_button2Pressed
= TRUE
;
2521 else if (local_event
.xbutton
.button
== Button3
)
2523 eventType
= wxEVT_RIGHT_DOWN
;
2524 canvas
->m_button3Pressed
= TRUE
;
2527 else if (local_event
.xany
.type
== ButtonRelease
)
2529 if (local_event
.xbutton
.button
== Button1
)
2531 eventType
= wxEVT_LEFT_UP
;
2532 canvas
->m_button1Pressed
= FALSE
;
2534 else if (local_event
.xbutton
.button
== Button2
)
2536 eventType
= wxEVT_MIDDLE_UP
;
2537 canvas
->m_button2Pressed
= FALSE
;
2539 else if (local_event
.xbutton
.button
== Button3
)
2541 eventType
= wxEVT_RIGHT_UP
;
2542 canvas
->m_button3Pressed
= FALSE
;
2546 wxMouseEvent
wxevent (eventType
);
2547 wxevent
.m_eventHandle
= (char *) &local_event
;
2549 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2550 || (event_left_is_down (&local_event
)
2551 && (eventType
!= wxEVT_LEFT_UP
)));
2552 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2553 || (event_middle_is_down (&local_event
)
2554 && (eventType
!= wxEVT_MIDDLE_UP
)));
2555 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2556 || (event_right_is_down (&local_event
)
2557 && (eventType
!= wxEVT_RIGHT_UP
)));
2559 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2560 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2561 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2562 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2563 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2565 // Now check if we need to translate this event into a double click
2566 if (TRUE
) // canvas->doubleClickAllowed)
2568 if (wxevent
.ButtonDown())
2570 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2572 // get button and time-stamp
2574 if (wxevent
.LeftDown()) button
= 1;
2575 else if (wxevent
.MiddleDown()) button
= 2;
2576 else if (wxevent
.RightDown()) button
= 3;
2577 long ts
= wxevent
.GetTimestamp();
2578 // check, if single or double click
2579 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2582 canvas
->m_lastButton
= 0;
2583 switch ( eventType
)
2585 case wxEVT_LEFT_DOWN
:
2586 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2588 case wxEVT_MIDDLE_DOWN
:
2589 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2591 case wxEVT_RIGHT_DOWN
:
2592 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2602 // not fast enough or different button
2603 canvas
->m_lastTS
= ts
;
2604 canvas
->m_lastButton
= button
;
2609 wxevent
.SetId(canvas
->GetId());
2610 wxevent
.SetEventObject(canvas
);
2611 wxevent
.m_x
= local_event
.xbutton
.x
;
2612 wxevent
.m_y
= local_event
.xbutton
.y
;
2613 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2615 if (eventType == wxEVT_ENTER_WINDOW ||
2616 eventType == wxEVT_LEAVE_WINDOW ||
2617 eventType == wxEVT_MOTION
2626 // XComposeStatus compose;
2627 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2628 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2629 int id
= wxCharCodeXToWX (keySym
);
2631 wxEventType eventType
= wxEVT_CHAR
;
2633 wxKeyEvent
event (eventType
);
2635 if (local_event
.xkey
.state
& ShiftMask
)
2636 event
.m_shiftDown
= TRUE
;
2637 if (local_event
.xkey
.state
& ControlMask
)
2638 event
.m_controlDown
= TRUE
;
2639 if (local_event
.xkey
.state
& Mod3Mask
)
2640 event
.m_altDown
= TRUE
;
2641 if (local_event
.xkey
.state
& Mod1Mask
)
2642 event
.m_metaDown
= TRUE
;
2643 event
.SetEventObject(canvas
);
2644 event
.m_keyCode
= id
;
2645 event
.SetTimestamp(local_event
.xkey
.time
);
2649 // Implement wxFrame::OnCharHook by checking ancestor.
2650 wxWindow
*parent
= canvas
->GetParent();
2651 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2652 parent
= parent
->GetParent();
2656 event
.SetEventType(wxEVT_CHAR_HOOK
);
2657 if (parent
->GetEventHandler()->ProcessEvent(event
))
2661 // For simplicity, OnKeyDown is the same as OnChar
2662 // TODO: filter modifier key presses from OnChar
2663 event
.SetEventType(wxEVT_KEY_DOWN
);
2665 // Only process OnChar if OnKeyDown didn't swallow it
2666 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2668 event
.SetEventType(wxEVT_CHAR
);
2669 canvas
->GetEventHandler()->ProcessEvent (event
);
2677 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2678 int id
= wxCharCodeXToWX (keySym
);
2680 wxKeyEvent
event (wxEVT_KEY_UP
);
2682 if (local_event
.xkey
.state
& ShiftMask
)
2683 event
.m_shiftDown
= TRUE
;
2684 if (local_event
.xkey
.state
& ControlMask
)
2685 event
.m_controlDown
= TRUE
;
2686 if (local_event
.xkey
.state
& Mod3Mask
)
2687 event
.m_altDown
= TRUE
;
2688 if (local_event
.xkey
.state
& Mod1Mask
)
2689 event
.m_metaDown
= TRUE
;
2690 event
.SetEventObject(canvas
);
2691 event
.m_keyCode
= id
;
2692 event
.SetTimestamp(local_event
.xkey
.time
);
2696 canvas
->GetEventHandler()->ProcessEvent (event
);
2702 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2704 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2705 event
.SetEventObject(canvas
);
2706 canvas
->GetEventHandler()->ProcessEvent(event
);
2712 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2714 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2715 event
.SetEventObject(canvas
);
2716 canvas
->GetEventHandler()->ProcessEvent(event
);
2725 void wxWindow::DoPaint()
2727 //TODO : make a temporary gc so we can do the XCopyArea below
2728 if (m_backingPixmap
&& !m_needsRefresh
)
2732 GC tempGC
= (GC
) dc
.GetBackingGC();
2734 Widget widget
= (Widget
) GetMainWidget();
2739 // We have to test whether it's a wxScrolledWindow (hack!)
2740 // because otherwise we don't know how many pixels have been
2741 // scrolled. We might solve this in the future by defining
2742 // virtual wxWindow functions to get the scroll position in pixels.
2743 // Or, each kind of scrolled window has to implement backing
2744 // stores itself, using generic wxWindows code.
2745 if (this->IsKindOf(CLASSINFO(wxScrolledWindow
)))
2747 wxScrolledWindow
* scrolledWindow
= (wxScrolledWindow
*) this;
2749 scrolledWindow
->CalcScrolledPosition(0, 0, & x
, & y
);
2755 // TODO: This could be optimized further by only copying the
2756 // areas in the current update region.
2758 // Only blit the part visible in the client area. The backing pixmap
2759 // always starts at 0, 0 but we may be looking at only a portion of it.
2760 wxSize clientArea
= GetClientSize();
2761 int toBlitX
= m_pixmapWidth
- scrollPosX
;
2762 int toBlitY
= m_pixmapHeight
- scrollPosY
;
2764 // Copy whichever is samller, the amount of pixmap we have to copy,
2765 // or the size of the client area.
2766 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
2767 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
2769 // Make sure we're not negative
2770 toBlitX
= wxMax(0, toBlitX
);
2771 toBlitY
= wxMax(0, toBlitY
);
2773 XCopyArea (XtDisplay (widget
), (Pixmap
) m_backingPixmap
, XtWindow (widget
), tempGC
,
2774 scrollPosX
, scrollPosY
, // Start at the scroll position
2775 toBlitX
, toBlitY
, // How much of the pixmap to copy
2776 0, 0); // Destination
2780 // Set an erase event first
2781 wxEraseEvent
eraseEvent(GetId());
2782 eraseEvent
.SetEventObject(this);
2783 GetEventHandler()->ProcessEvent(eraseEvent
);
2785 wxPaintEvent
event(GetId());
2786 event
.SetEventObject(this);
2787 GetEventHandler()->ProcessEvent(event
);
2789 m_needsRefresh
= FALSE
;
2793 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2794 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2796 // A bit of optimization to help sort out the flickers.
2797 int oldX
, oldY
, oldW
, oldH
;
2798 GetSize(& oldW
, & oldH
);
2799 GetPosition(& oldX
, & oldY
);
2801 bool useOldPos
= FALSE
;
2802 bool useOldSize
= FALSE
;
2804 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2806 else if (x
== oldX
&& y
== oldY
)
2809 if ((w
== -1) && (h
== -1))
2811 else if (w
== oldW
&& h
== oldH
)
2814 if (!wxNoOptimize::CanOptimize())
2816 useOldSize
= FALSE
; useOldPos
= FALSE
;
2819 if (useOldPos
&& useOldSize
)
2822 Widget drawingArea
= (Widget
) m_drawingArea
;
2823 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2826 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2827 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2829 int xx
= x
; int yy
= y
;
2830 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2834 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2836 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2840 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2842 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2854 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2855 short thick
, margin
;
2856 XtVaGetValues ((Widget
) m_borderWidget
,
2857 XmNshadowThickness
, &thick
,
2858 XmNmarginWidth
, &margin
,
2860 w
-= 2 * (thick
+ margin
);
2863 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2867 XtVaGetValues ((Widget
) m_scrolledWindow
,
2868 XmNspacing
, &spacing
,
2869 XmNverticalScrollBar
, &sbar
,
2873 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2877 w
-= (spacing
+ wsbar
);
2879 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2885 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2886 short thick
, margin
;
2887 XtVaGetValues ((Widget
) m_borderWidget
,
2888 XmNshadowThickness
, &thick
,
2889 XmNmarginHeight
, &margin
,
2891 h
-= 2 * (thick
+ margin
);
2894 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2898 XtVaGetValues ((Widget
) m_scrolledWindow
,
2899 XmNspacing
, &spacing
,
2900 XmNhorizontalScrollBar
, &sbar
,
2904 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2908 h
-= (spacing
+ wsbar
);
2910 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2916 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2917 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2921 GetClientSize (&ww, &hh);
2922 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2923 sizeEvent.SetEventObject(this);
2925 GetEventHandler()->ProcessEvent(sizeEvent);
2930 void wxWindow::CanvasSetClientSize (int w
, int h
)
2932 Widget drawingArea
= (Widget
) m_drawingArea
;
2934 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2937 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2939 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2940 /* TODO: is this necessary?
2941 allowRepainting = FALSE;
2943 XSync (XtDisplay (drawingArea), FALSE);
2945 while (XtAppPending (wxTheApp->appContext))
2947 XFlush (XtDisplay (drawingArea));
2948 XtAppNextEvent (wxTheApp->appContext, &event);
2949 XtDispatchEvent (&event);
2953 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2956 allowRepainting = TRUE;
2961 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2962 sizeEvent.SetEventObject(this);
2964 GetEventHandler()->ProcessEvent(sizeEvent);
2968 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2970 // Must return the same thing that was set via SetClientSize
2972 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2977 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2980 if ((Widget
) m_borderWidget
)
2981 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2982 else if ((Widget
) m_scrolledWindow
)
2983 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2985 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2991 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2994 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2996 // We may be faking the client origin.
2997 // So a window that's really at (0, 30) may appear
2998 // (to wxWin apps) to be at (0, 0).
3001 wxPoint
pt(GetParent()->GetClientAreaOrigin());
3010 // Add to hash table, add event handler
3011 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
3012 WXWidget formWidget
, int x
, int y
, int width
, int height
)
3014 wxAddWindowToTable((Widget
) mainWidget
, this);
3015 if (CanAddEventHandler())
3017 XtAddEventHandler((Widget
) mainWidget
,
3018 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3020 wxPanelItemEventHandler
,
3027 XtOverrideTranslations ((Widget
) mainWidget
,
3028 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3029 XtFree ((char *) ptr
);
3032 // Some widgets have a parent form widget, e.g. wxRadioBox
3035 if (!wxAddWindowToTable((Widget
) formWidget
, this))
3039 XtOverrideTranslations ((Widget
) formWidget
,
3040 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3041 XtFree ((char *) ptr
);
3048 SetSize (x
, y
, width
, height
);
3053 // Remove event handler, remove from hash table
3054 bool wxWindow::DetachWidget(WXWidget widget
)
3056 if (CanAddEventHandler())
3058 XtRemoveEventHandler((Widget
) widget
,
3059 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3061 wxPanelItemEventHandler
,
3065 wxDeleteWindowFromTable((Widget
) widget
);
3069 void wxPanelItemEventHandler (Widget wid
,
3070 XtPointer client_data
,
3072 Boolean
*continueToDispatch
)
3074 // Widget can be a label or the actual widget.
3076 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3079 wxMouseEvent
wxevent(0);
3080 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3082 window
->GetEventHandler()->ProcessEvent(wxevent
);
3085 // TODO: probably the key to allowing default behaviour
3087 // Say we set a m_doDefault flag to FALSE at the start of this
3088 // function. Then in e.g. wxWindow::OnMouseEvent we can
3089 // call Default() which sets this flag to TRUE, indicating
3090 // that default processing can happen. Thus, behaviour can appear
3091 // to be overridden just by adding an event handler and not calling
3092 // wxWindow::OnWhatever.
3093 // ALSO, maybe we can use this instead of the current way of handling
3094 // drawing area events, to simplify things.
3095 *continueToDispatch
= True
;
3098 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3099 XmScaleCallbackStruct
*cbs
)
3101 Widget scrolledWindow
= XtParent (scrollbar
);
3102 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3103 int orientation
= (int) clientData
;
3105 wxEventType eventType
= wxEVT_NULL
;
3106 switch (cbs
->reason
)
3108 case XmCR_INCREMENT
:
3110 eventType
= wxEVT_SCROLL_LINEDOWN
;
3113 case XmCR_DECREMENT
:
3115 eventType
= wxEVT_SCROLL_LINEUP
;
3120 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3123 case XmCR_VALUE_CHANGED
:
3125 // TODO: Should this be intercepted too, or will it cause
3126 // duplicate events?
3127 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3130 case XmCR_PAGE_INCREMENT
:
3132 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3135 case XmCR_PAGE_DECREMENT
:
3137 eventType
= wxEVT_SCROLL_PAGEUP
;
3142 eventType
= wxEVT_SCROLL_TOP
;
3145 case XmCR_TO_BOTTOM
:
3147 eventType
= wxEVT_SCROLL_BOTTOM
;
3152 // Should never get here
3153 wxFAIL_MSG("Unknown scroll event.");
3158 wxScrollEvent
event(eventType
, win
->GetId());
3159 event
.SetEventObject(win
);
3160 event
.SetPosition(cbs
->value
);
3161 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3163 win
->GetEventHandler()->ProcessEvent(event
);
3166 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3168 switch (xevent
->xany
.type
)
3176 wxEventType eventType
= wxEVT_NULL
;
3178 if (xevent
->xany
.type
== LeaveNotify
)
3180 win
->m_button1Pressed
= FALSE
;
3181 win
->m_button2Pressed
= FALSE
;
3182 win
->m_button3Pressed
= FALSE
;
3185 else if (xevent
->xany
.type
== MotionNotify
)
3187 eventType
= wxEVT_MOTION
;
3189 else if (xevent
->xany
.type
== ButtonPress
)
3191 if (xevent
->xbutton
.button
== Button1
)
3193 eventType
= wxEVT_LEFT_DOWN
;
3194 win
->m_button1Pressed
= TRUE
;
3196 else if (xevent
->xbutton
.button
== Button2
)
3198 eventType
= wxEVT_MIDDLE_DOWN
;
3199 win
->m_button2Pressed
= TRUE
;
3201 else if (xevent
->xbutton
.button
== Button3
)
3203 eventType
= wxEVT_RIGHT_DOWN
;
3204 win
->m_button3Pressed
= TRUE
;
3207 else if (xevent
->xany
.type
== ButtonRelease
)
3209 if (xevent
->xbutton
.button
== Button1
)
3211 eventType
= wxEVT_LEFT_UP
;
3212 win
->m_button1Pressed
= FALSE
;
3214 else if (xevent
->xbutton
.button
== Button2
)
3216 eventType
= wxEVT_MIDDLE_UP
;
3217 win
->m_button2Pressed
= FALSE
;
3219 else if (xevent
->xbutton
.button
== Button3
)
3221 eventType
= wxEVT_RIGHT_UP
;
3222 win
->m_button3Pressed
= FALSE
;
3228 wxevent
.m_eventHandle
= (char *)xevent
;
3229 wxevent
.SetEventType(eventType
);
3232 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3235 win
->GetPosition(&x2
, &y2
);
3237 // The button x/y must be translated to wxWindows
3238 // window space - the widget might be a label or button,
3242 if (widget
!= (Widget
)win
->GetMainWidget())
3248 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3249 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3251 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3252 || (event_left_is_down (xevent
)
3253 && (eventType
!= wxEVT_LEFT_UP
)));
3254 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3255 || (event_middle_is_down (xevent
)
3256 && (eventType
!= wxEVT_MIDDLE_UP
)));
3257 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3258 || (event_right_is_down (xevent
)
3259 && (eventType
!= wxEVT_RIGHT_UP
)));
3261 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3262 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3269 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3271 switch (xevent
->xany
.type
)
3278 // XComposeStatus compose;
3279 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3280 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3281 int id
= wxCharCodeXToWX (keySym
);
3283 if (xevent
->xkey
.state
& ShiftMask
)
3284 wxevent
.m_shiftDown
= TRUE
;
3285 if (xevent
->xkey
.state
& ControlMask
)
3286 wxevent
.m_controlDown
= TRUE
;
3287 if (xevent
->xkey
.state
& Mod3Mask
)
3288 wxevent
.m_altDown
= TRUE
;
3289 if (xevent
->xkey
.state
& Mod1Mask
)
3290 wxevent
.m_metaDown
= TRUE
;
3291 wxevent
.SetEventObject(win
);
3292 wxevent
.m_keyCode
= id
;
3293 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3295 wxevent
.m_x
= xevent
->xbutton
.x
;
3296 wxevent
.m_y
= xevent
->xbutton
.y
;
3310 #define YAllocColor XAllocColor
3311 XColor g_itemColors
[5];
3312 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3315 static XmColorProc colorProc
;
3317 result
= wxNO_COLORS
;
3321 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3322 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3323 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3324 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3325 if (colorProc
== (XmColorProc
) NULL
)
3327 // Get a ptr to the actual function
3328 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3329 // And set it back to motif.
3330 XmSetColorCalculation (colorProc
);
3332 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3333 &g_itemColors
[wxFORE_INDEX
],
3334 &g_itemColors
[wxSELE_INDEX
],
3335 &g_itemColors
[wxTOPS_INDEX
],
3336 &g_itemColors
[wxBOTS_INDEX
]);
3337 result
= wxBACK_COLORS
;
3341 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3342 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3343 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3344 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3345 if (result
== wxNO_COLORS
)
3346 result
= wxFORE_COLORS
;
3349 Display
*dpy
= display
;
3350 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3354 /* 5 Colours to allocate */
3355 for (int i
= 0; i
< 5; i
++)
3356 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3357 result
= wxNO_COLORS
;
3361 /* Only 1 colour to allocate */
3362 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3363 result
= wxNO_COLORS
;
3370 // Changes the foreground and background colours to be derived
3371 // from the current background colour.
3372 // To change the foreground colour, you must call SetForegroundColour
3374 void wxWindow::ChangeBackgroundColour()
3376 if (GetMainWidget())
3377 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3379 // This not necessary
3382 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3384 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3385 // Have to set the scrollbar colours back since
3386 // the scrolled window seemed to change them
3387 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3390 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3392 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3397 void wxWindow::ChangeForegroundColour()
3399 if (GetMainWidget())
3400 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3401 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3402 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3405 // Change a widget's foreground and background colours.
3407 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3409 // When should we specify the foreground, if it's calculated
3410 // by wxComputeColours?
3411 // Solution: say we start with the default (computed) foreground colour.
3412 // If we call SetForegroundColour explicitly for a control or window,
3413 // then the foreground is changed.
3414 // Therefore SetBackgroundColour computes the foreground colour, and
3415 // SetForegroundColour changes the foreground colour. The ordering is
3418 XtVaSetValues ((Widget
) widget
,
3419 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3423 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3425 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3428 XtVaSetValues ((Widget
) widget
,
3429 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3430 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3431 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3432 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3435 if (changeArmColour
)
3436 XtVaSetValues ((Widget
) widget
,
3437 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3441 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3443 m_backgroundColour
= col
;
3444 ChangeBackgroundColour();
3447 void wxWindow::SetForegroundColour(const wxColour
& col
)
3449 m_foregroundColour
= col
;
3450 ChangeForegroundColour();
3453 void wxWindow::ChangeFont(bool keepOriginalSize
)
3455 // Note that this causes the widget to be resized back
3456 // to its original size! We therefore have to set the size
3457 // back again. TODO: a better way in Motif?
3458 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3459 if (w
&& m_windowFont
.Ok())
3461 int width
, height
, width1
, height1
;
3462 GetSize(& width
, & height
);
3464 // lesstif 0.87 hangs here
3465 #ifndef LESSTIF_VERSION
3467 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3471 GetSize(& width1
, & height1
);
3472 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3474 SetSize(-1, -1, width
, height
);
3479 void wxWindow::SetFont(const wxFont
& font
)
3481 m_windowFont
= font
;
3485 void wxWindow::SetToolTip(const wxString
& tooltip
)
3490 void wxWindow::ClearUpdateRects()
3492 wxNode
* node
= m_updateRects
.First();
3495 wxRect
* rect
= (wxRect
*) node
->Data();
3497 node
= node
->Next();
3499 m_updateRects
.Clear();
3502 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3504 if (!m_acceleratorTable
.Ok())
3507 int count
= m_acceleratorTable
.GetCount();
3508 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3510 for (i
= 0; i
< count
; i
++)
3512 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3513 if (entry
->MatchesEvent(event
))
3515 // Bingo, we have a match. Now find a control
3516 // that matches the entry command id.
3518 // Need to go up to the top of the window hierarchy,
3519 // since it might be e.g. a menu item
3520 wxWindow
* parent
= this;
3521 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3522 parent
= parent
->GetParent();
3527 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3529 // Try for a menu command
3530 wxFrame
* frame
= (wxFrame
*) parent
;
3531 if (frame
->GetMenuBar())
3533 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3536 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3537 commandEvent
.SetEventObject(frame
);
3539 // If ProcessEvent returns TRUE (it was handled), then
3540 // the calling code will skip the event handling.
3541 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3546 // Find a child matching the command id
3547 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3553 // Now we process those kinds of windows that we can.
3554 // For now, only buttons.
3555 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3557 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3558 commandEvent
.SetEventObject(child
);
3559 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3566 // We didn't match the key event against an accelerator.
3571 * wxNoOptimize: switch off size optimization
3574 int wxNoOptimize::m_count
= 0;
3576 wxNoOptimize::wxNoOptimize()
3581 wxNoOptimize::~wxNoOptimize()
3586 bool wxNoOptimize::CanOptimize()
3588 return (m_count
== 0);
3591 // For repainting arbitrary windows
3592 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
3597 wxWindow
* win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
3601 switch(event
-> type
)
3605 window
= (Window
) win
-> GetXWindow();
3606 display
= (Display
*) win
-> GetXDisplay();
3608 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
3609 event
->xexpose
.width
, event
->xexpose
.height
);
3610 win
->m_updateRects
.Append((wxObject
*) rect
);
3612 if (event
-> xexpose
.count
== 0)
3616 win
->ClearUpdateRects();
3622 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";