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
)
91 m_windowParent
= NULL
;
92 m_windowEventHandler
= this;
94 m_windowCursor
= *wxSTANDARD_CURSOR
;
95 m_children
= new wxList
;
97 m_constraintsInvolvedIn
= NULL
;
100 m_autoLayout
= FALSE
;
101 m_windowValidator
= NULL
;
102 m_defaultItem
= NULL
;
104 m_caretWidth
= 0; m_caretHeight
= 0;
105 m_caretEnabled
= FALSE
;
106 m_caretShown
= FALSE
;
107 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
108 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
109 m_foregroundColour
= *wxBLACK
;
111 #if wxUSE_DRAG_AND_DROP
112 m_pDropTarget
= NULL
;
114 m_clientObject
= (wxClientData
*) NULL
;
118 m_needsRefresh
= TRUE
;
119 m_mainWidget
= (WXWidget
) 0;
120 m_button1Pressed
= FALSE
;
121 m_button2Pressed
= FALSE
;
122 m_button3Pressed
= FALSE
;
123 m_winCaptured
= FALSE
;
125 m_hScrollBar
= (WXWidget
) 0;
126 m_vScrollBar
= (WXWidget
) 0;
127 m_borderWidget
= (WXWidget
) 0;
128 m_scrolledWindow
= (WXWidget
) 0;
129 m_drawingArea
= (WXWidget
) 0;
132 m_backingPixmap
= (WXPixmap
) 0;
139 m_canAddEventHandler
= FALSE
;
145 wxWindow::~wxWindow()
150 DetachWidget(GetMainWidget()); // Removes event handlers
152 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
155 // Destroy children before destroying self
159 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
161 Widget w
= (Widget
) m_drawingArea
;
162 wxDeleteWindowFromTable(w
);
166 m_mainWidget
= (WXWidget
) 0;
168 // Only if we're _really_ a canvas (not a dialog box/panel)
169 if (m_scrolledWindow
)
171 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
176 XtUnmanageChild ((Widget
) m_hScrollBar
);
177 XtDestroyWidget ((Widget
) m_hScrollBar
);
181 XtUnmanageChild ((Widget
) m_vScrollBar
);
182 XtDestroyWidget ((Widget
) m_vScrollBar
);
184 if (m_scrolledWindow
)
186 XtUnmanageChild ((Widget
) m_scrolledWindow
);
187 XtDestroyWidget ((Widget
) m_scrolledWindow
);
192 XtDestroyWidget ((Widget
) m_borderWidget
);
193 m_borderWidget
= (WXWidget
) 0;
199 // Have to delete constraints/sizer FIRST otherwise
200 // sizers may try to look at deleted windows as they
201 // delete themselves.
202 #if wxUSE_CONSTRAINTS
203 DeleteRelatedConstraints();
206 // This removes any dangling pointers to this window
207 // in other windows' constraintsInvolvedIn lists.
208 UnsetConstraints(m_constraints
);
209 delete m_constraints
;
210 m_constraints
= NULL
;
214 delete m_windowSizer
;
215 m_windowSizer
= NULL
;
217 // If this is a child of a sizer, remove self from parent
219 m_sizerParent
->RemoveChild((wxWindow
*)this);
223 m_windowParent
->RemoveChild(this);
227 // Destroy the window
230 // If this line (XtDestroyWidget) causes a crash, you may comment it out.
231 // Child widgets will get destroyed automatically when a frame
232 // or dialog is destroyed, but before that you may get some memory
233 // leaks and potential layout problems if you delete and then add
235 XtDestroyWidget((Widget
) GetMainWidget());
236 SetMainWidget((WXWidget
) NULL
);
242 // Just in case the window has been Closed, but
243 // we're then deleting immediately: don't leave
244 // dangling pointers.
245 wxPendingDelete
.DeleteObject(this);
247 if ( m_windowValidator
) delete m_windowValidator
;
248 if (m_clientObject
) delete m_clientObject
;
253 // Destroy the window (delayed, if a managed window)
254 bool wxWindow::Destroy()
261 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
265 const wxString
& name
)
270 m_windowParent
= NULL
;
271 m_windowEventHandler
= this;
273 m_windowCursor
= *wxSTANDARD_CURSOR
;
274 m_constraints
= NULL
;
275 m_constraintsInvolvedIn
= NULL
;
276 m_windowSizer
= NULL
;
277 m_sizerParent
= NULL
;
278 m_autoLayout
= FALSE
;
279 m_windowValidator
= NULL
;
280 #if wxUSE_DRAG_AND_DROP
281 m_pDropTarget
= NULL
;
283 m_caretWidth
= 0; m_caretHeight
= 0;
284 m_caretEnabled
= FALSE
;
285 m_caretShown
= FALSE
;
290 m_defaultItem
= NULL
;
291 m_windowParent
= NULL
;
292 m_clientObject
= (wxClientData
*) NULL
;
296 m_needsRefresh
= TRUE
;
297 m_canAddEventHandler
= FALSE
;
298 m_mainWidget
= (WXWidget
) 0;
299 m_button1Pressed
= FALSE
;
300 m_button2Pressed
= FALSE
;
301 m_button3Pressed
= FALSE
;
302 m_winCaptured
= FALSE
;
304 m_hScrollBar
= (WXWidget
) 0;
305 m_vScrollBar
= (WXWidget
) 0;
306 m_borderWidget
= (WXWidget
) 0;
307 m_scrolledWindow
= (WXWidget
) 0;
308 m_drawingArea
= (WXWidget
) 0;
311 m_backingPixmap
= (WXPixmap
) 0;
322 if (parent
) parent
->AddChild(this);
329 m_windowId
= (int)NewControlId();
333 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
334 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
335 m_foregroundColour
= *wxBLACK
;
337 m_windowStyle
= style
;
340 m_windowId
= (int)NewControlId();
344 //// TODO: we should probably optimize by only creating a
345 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
346 //// But for now, let's simplify things by always creating the
347 //// drawing area, since otherwise the translations are different.
349 // New translations for getting mouse motion feedback
350 String translations
=
351 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
352 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
353 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
354 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
355 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
356 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
357 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
358 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
359 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
360 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
361 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
362 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
363 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
364 <Key>: DrawingAreaInput()";
366 XtActionsRec actions
[1];
367 actions
[0].string
= "wxCanvasMotionEvent";
368 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
369 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
371 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
372 if (style
& wxBORDER
)
373 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
374 xmFrameWidgetClass
, parentWidget
,
375 XmNshadowType
, XmSHADOW_IN
,
378 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
379 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
380 XmNresizePolicy
, XmRESIZE_NONE
,
382 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
383 // XmNscrollBarDisplayPolicy, XmAS_NEEDED,
387 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
388 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
389 XmNunitType
, XmPIXELS
,
390 // XmNresizePolicy, XmRESIZE_ANY,
391 XmNresizePolicy
, XmRESIZE_NONE
,
394 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
397 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
399 XtFree ((char *) ptr);
400 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
401 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
402 XtFree ((char *) ptr);
406 wxAddWindowToTable((Widget
) m_drawingArea
, this);
407 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
410 * This order is very important in Motif 1.2.1
414 XtRealizeWidget ((Widget
) m_scrolledWindow
);
415 XtRealizeWidget ((Widget
) m_drawingArea
);
416 XtManageChild ((Widget
) m_drawingArea
);
418 XtOverrideTranslations ((Widget
) m_drawingArea
,
419 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
420 XtFree ((char *) ptr
);
422 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
423 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
426 display = XtDisplay (scrolledWindow);
427 xwindow = XtWindow (drawingArea);
430 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
431 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
433 // Scrolled widget needs to have its colour changed or we get
434 // a little blue square where the scrollbars abutt
435 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
436 DoChangeBackgroundColour(m_scrolledWindow
, backgroundColour
, TRUE
);
437 DoChangeBackgroundColour(m_drawingArea
, backgroundColour
, TRUE
);
439 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) 0, (Widget
) 0, (Widget
) m_drawingArea
);
443 XtRealizeWidget ((Widget) m_hScrollBar);
445 XtRealizeWidget ((Widget) m_vScrollBar);
448 // Without this, the cursor may not be restored properly
449 // (e.g. in splitter sample).
450 SetCursor(*wxSTANDARD_CURSOR
);
451 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
452 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
458 void wxWindow::CreateScrollbar(int orientation
)
463 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
465 // Add scrollbars if required
466 if (orientation
== wxHORIZONTAL
)
468 Widget hScrollBar
= XtVaCreateManagedWidget ("hsb",
469 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
470 XmNorientation
, XmHORIZONTAL
,
472 // XtAddCallback (hScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmHORIZONTAL);
473 XtAddCallback (hScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
474 XtAddCallback (hScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
475 XtAddCallback (hScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
476 XtAddCallback (hScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
477 XtAddCallback (hScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
478 XtAddCallback (hScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
479 XtAddCallback (hScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmHORIZONTAL
);
481 XtVaSetValues (hScrollBar
,
486 m_hScrollBar
= (WXWidget
) hScrollBar
;
488 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
489 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
, TRUE
);
491 XtRealizeWidget(hScrollBar
);
493 XtVaSetValues((Widget
) m_scrolledWindow
,
494 XmNhorizontalScrollBar
, (Widget
) m_hScrollBar
,
500 if (orientation
== wxVERTICAL
)
502 Widget vScrollBar
= XtVaCreateManagedWidget ("vsb",
503 xmScrollBarWidgetClass
, (Widget
) m_scrolledWindow
,
504 XmNorientation
, XmVERTICAL
,
506 // XtAddCallback (vScrollBar, XmNvalueChangedCallback, (XtCallbackProc) wxScrollBarCallback, (XtPointer) XmVERTICAL);
507 XtAddCallback (vScrollBar
, XmNdragCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
508 XtAddCallback (vScrollBar
, XmNincrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
509 XtAddCallback (vScrollBar
, XmNdecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
510 XtAddCallback (vScrollBar
, XmNpageIncrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
511 XtAddCallback (vScrollBar
, XmNpageDecrementCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
512 XtAddCallback (vScrollBar
, XmNtoTopCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
513 XtAddCallback (vScrollBar
, XmNtoBottomCallback
, (XtCallbackProc
) wxScrollBarCallback
, (XtPointer
) XmVERTICAL
);
515 XtVaSetValues (vScrollBar
,
520 m_vScrollBar
= (WXWidget
) vScrollBar
;
521 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
522 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
, TRUE
);
524 XtRealizeWidget(vScrollBar
);
526 XtVaSetValues((Widget
) m_scrolledWindow
,
527 XmNverticalScrollBar
, (Widget
) m_vScrollBar
,
533 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
535 void wxWindow::DestroyScrollbar(int orientation
)
540 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
541 // Add scrollbars if required
542 if (orientation
== wxHORIZONTAL
)
546 XtDestroyWidget((Widget
) m_hScrollBar
);
548 m_hScrollBar
= (WXWidget
) 0;
551 XtVaSetValues((Widget
) m_scrolledWindow
,
552 XmNhorizontalScrollBar
, (Widget
) 0,
557 if (orientation
== wxVERTICAL
)
561 XtDestroyWidget((Widget
) m_vScrollBar
);
563 m_vScrollBar
= (WXWidget
) 0;
566 XtVaSetValues((Widget
) m_scrolledWindow
,
567 XmNverticalScrollBar
, (Widget
) 0,
571 XtVaSetValues((Widget
) m_scrolledWindow
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
574 void wxWindow::SetFocus()
576 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
577 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
580 void wxWindow::Enable(bool enable
)
584 XtSetSensitive((Widget
) GetMainWidget(), enable
);
585 XmUpdateDisplay((Widget
) GetMainWidget());
589 void wxWindow::CaptureMouse()
595 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
597 m_winCaptured
= TRUE
;
600 void wxWindow::ReleaseMouse()
606 XtRemoveGrab((Widget
) GetMainWidget());
607 m_winCaptured
= FALSE
;
610 // Push/pop event handler (i.e. allow a chain of event handlers
612 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
614 handler
->SetNextHandler(GetEventHandler());
615 SetEventHandler(handler
);
618 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
620 if ( GetEventHandler() )
622 wxEvtHandler
*handlerA
= GetEventHandler();
623 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
624 handlerA
->SetNextHandler(NULL
);
625 SetEventHandler(handlerB
);
638 #if wxUSE_DRAG_AND_DROP
640 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
642 if ( m_pDropTarget
!= 0 ) {
643 delete m_pDropTarget
;
646 m_pDropTarget
= pDropTarget
;
647 if ( m_pDropTarget
!= 0 )
655 // Old style file-manager drag&drop
656 void wxWindow::DragAcceptFiles(bool accept
)
662 void wxWindow::GetSize(int *x
, int *y
) const
670 Widget widget
= (Widget
) GetTopWidget();
672 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
676 void wxWindow::GetPosition(int *x
, int *y
) const
680 CanvasGetPosition(x
, y
);
683 Widget widget
= (Widget
) GetTopWidget();
685 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
687 // We may be faking the client origin.
688 // So a window that's really at (0, 30) may appear
689 // (to wxWin apps) to be at (0, 0).
692 wxPoint
pt(GetParent()->GetClientAreaOrigin());
700 void wxWindow::ScreenToClient(int *x
, int *y
) const
702 Widget widget
= (Widget
) GetClientWidget();
703 Display
*display
= XtDisplay((Widget
) GetMainWidget());
704 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
705 Window thisWindow
= XtWindow(widget
);
710 XTranslateCoordinates(display
, rootWindow
, thisWindow
, xx
, yy
, x
, y
, &childWindow
);
713 void wxWindow::ClientToScreen(int *x
, int *y
) const
715 Widget widget
= (Widget
) GetClientWidget();
716 Display
*display
= XtDisplay(widget
);
717 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
718 Window thisWindow
= XtWindow(widget
);
723 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
726 void wxWindow::SetCursor(const wxCursor
& cursor
)
728 m_windowCursor
= cursor
;
729 if (m_windowCursor
.Ok())
731 WXDisplay
*dpy
= GetXDisplay();
732 WXCursor x_cursor
= ((wxCursor
&)cursor
).GetXCursor(dpy
);
734 Widget w
= (Widget
) GetMainWidget();
735 Window win
= XtWindow(w
);
736 XDefineCursor((Display
*) dpy
, win
, (Cursor
) x_cursor
);
741 // Get size *available for subwindows* i.e. excluding menu bar etc.
742 void wxWindow::GetClientSize(int *x
, int *y
) const
744 Widget widget
= (Widget
) GetClientWidget();
746 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
750 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
752 // A bit of optimization to help sort out the flickers.
753 int oldX
, oldY
, oldW
, oldH
;
754 GetSize(& oldW
, & oldH
);
755 GetPosition(& oldX
, & oldY
);
757 bool useOldPos
= FALSE
;
758 bool useOldSize
= FALSE
;
760 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
762 else if (x
== oldX
&& y
== oldY
)
765 if ((width
== -1) && (height
== -1))
767 else if (width
== oldW
&& height
== oldH
)
770 if (!wxNoOptimize::CanOptimize())
772 useOldSize
= FALSE
; useOldPos
= FALSE
;
775 if (useOldPos
&& useOldSize
)
780 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
783 Widget widget
= (Widget
) GetTopWidget();
787 bool managed
= XtIsManaged( widget
);
789 XtUnmanageChild(widget
);
791 int xx
= x
; int yy
= y
;
792 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
796 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
797 XtVaSetValues(widget
, XmNx
, xx
, NULL
);
798 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
799 XtVaSetValues(widget
, XmNy
, yy
, NULL
);
804 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
806 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
810 XtManageChild(widget
);
812 // How about this bit. Maybe we don't need to generate size events
813 // all the time -- they'll be generated when the window is sized anyway.
815 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
816 sizeEvent.SetEventObject(this);
818 GetEventHandler()->ProcessEvent(sizeEvent);
822 void wxWindow::SetClientSize(int width
, int height
)
826 CanvasSetClientSize(width
, height
);
830 Widget widget
= (Widget
) GetTopWidget();
833 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
835 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
837 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
838 sizeEvent
.SetEventObject(this);
840 GetEventHandler()->ProcessEvent(sizeEvent
);
843 // For implementation purposes - sometimes decorations make the client area
845 wxPoint
wxWindow::GetClientAreaOrigin() const
847 return wxPoint(0, 0);
850 // Makes an adjustment to the window position (for example, a frame that has
851 // a toolbar that it manages itself).
852 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
854 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
856 wxPoint
pt(GetParent()->GetClientAreaOrigin());
857 x
+= pt
.x
; y
+= pt
.y
;
861 bool wxWindow::Show(bool show
)
865 if (m_borderWidget
|| m_scrolledWindow
)
868 XtMapWidget((Widget
) m_drawingArea
);
869 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
873 WXWidget topWidget
= GetTopWidget();
875 XtMapWidget((Widget
) GetTopWidget());
876 else if (GetMainWidget())
877 XtMapWidget((Widget
) GetMainWidget());
882 if (m_borderWidget
|| m_scrolledWindow
)
885 XtUnmapWidget((Widget
) m_drawingArea
);
886 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
891 XtUnmapWidget((Widget
) GetTopWidget());
892 else if (GetMainWidget())
893 XtUnmapWidget((Widget
) GetMainWidget());
898 Window xwin = (Window) GetXWindow();
899 Display *xdisp = (Display*) GetXDisplay();
901 XMapWindow(xdisp, xwin);
903 XUnmapWindow(xdisp, xwin);
911 bool wxWindow::IsShown() const
916 int wxWindow::GetCharHeight() const
918 if (!m_windowFont
.Ok())
921 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
923 int direction
, ascent
, descent
;
925 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
927 // return (overall.ascent + overall.descent);
928 return (ascent
+ descent
);
931 int wxWindow::GetCharWidth() const
933 if (!m_windowFont
.Ok())
936 WXFontStructPtr pFontStruct
= m_windowFont
.GetFontStruct(1.0, GetXDisplay());
938 int direction
, ascent
, descent
;
940 XTextExtents ((XFontStruct
*) pFontStruct
, "x", 1, &direction
, &ascent
,
942 return overall
.width
;
945 /* Helper function for 16-bit fonts */
946 static int str16len(const char *s
)
950 while (s
[0] && s
[1]) {
958 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
959 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool use16
) const
961 wxFont
*fontToUse
= (wxFont
*)theFont
;
963 fontToUse
= (wxFont
*) & m_windowFont
;
965 if (!fontToUse
->Ok())
968 WXFontStructPtr pFontStruct
= theFont
->GetFontStruct(1.0, GetXDisplay());
970 int direction
, ascent
, descent2
;
974 if (use16
) slen
= str16len(string
); else slen
= strlen(string
);
977 XTextExtents16((XFontStruct
*) pFontStruct
, (XChar2b
*) (char*) (const char*) string
, slen
, &direction
,
978 &ascent
, &descent2
, &overall
);
980 XTextExtents((XFontStruct
*) pFontStruct
, (char*) (const char*) string
, slen
, &direction
,
981 &ascent
, &descent2
, &overall
);
983 *x
= (overall
.width
);
984 *y
= (ascent
+ descent2
);
988 *externalLeading
= 0;
991 void wxWindow::Refresh(bool eraseBack
, const wxRect
*rect
)
993 m_needsRefresh
= TRUE
;
994 Display
*display
= XtDisplay((Widget
) GetMainWidget());
995 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
997 XExposeEvent dummyEvent
;
999 GetSize(&width
, &height
);
1001 dummyEvent
.type
= Expose
;
1002 dummyEvent
.display
= display
;
1003 dummyEvent
.send_event
= True
;
1004 dummyEvent
.window
= thisWindow
;
1007 dummyEvent
.x
= rect
->x
;
1008 dummyEvent
.y
= rect
->y
;
1009 dummyEvent
.width
= rect
->width
;
1010 dummyEvent
.height
= rect
->height
;
1016 dummyEvent
.width
= width
;
1017 dummyEvent
.height
= height
;
1019 dummyEvent
.count
= 0;
1023 wxClientDC
dc(this);
1024 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
1025 dc
.SetBackground(backgroundBrush
);
1032 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
1035 // Responds to colour changes: passes event on to children.
1036 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1038 wxNode
*node
= GetChildren().First();
1041 // Only propagate to non-top-level windows
1042 wxWindow
*win
= (wxWindow
*)node
->Data();
1043 if ( win
->GetParent() )
1045 wxSysColourChangedEvent event2
;
1046 event
.m_eventObject
= win
;
1047 win
->GetEventHandler()->ProcessEvent(event2
);
1050 node
= node
->Next();
1054 // This can be called by the app (or wxWindows) to do default processing for the current
1055 // event. Save message/event info in wxWindow so they can be used in this function.
1056 long wxWindow::Default()
1062 void wxWindow::InitDialog()
1064 wxInitDialogEvent
event(GetId());
1065 event
.SetEventObject( this );
1066 GetEventHandler()->ProcessEvent(event
);
1069 // Default init dialog behaviour is to transfer data to window
1070 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
1072 TransferDataToWindow();
1075 // Caret manipulation
1076 void wxWindow::CreateCaret(int w
, int h
)
1080 m_caretEnabled
= TRUE
;
1083 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1088 void wxWindow::ShowCaret(bool show
)
1093 void wxWindow::DestroyCaret()
1096 m_caretEnabled
= FALSE
;
1099 void wxWindow::SetCaretPos(int x
, int y
)
1104 void wxWindow::GetCaretPos(int *x
, int *y
) const
1109 wxWindow
*wxGetActiveWindow()
1115 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
1122 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
1125 wxFrame
*frame
= (wxFrame
*)this;
1126 Widget widget
= (Widget
) frame
->GetShellWidget();
1129 XtVaSetValues(widget
, XmNminWidth
, minW
, NULL
);
1131 XtVaSetValues(widget
, XmNminHeight
, minH
, NULL
);
1133 XtVaSetValues(widget
, XmNmaxWidth
, maxW
, NULL
);
1135 XtVaSetValues(widget
, XmNmaxHeight
, maxH
, NULL
);
1137 XtVaSetValues(widget
, XmNwidthInc
, incW
, NULL
);
1139 XtVaSetValues(widget
, XmNheightInc
, incH
, NULL
);
1142 void wxWindow::Centre(int direction
)
1144 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
1146 wxWindow
*father
= (wxWindow
*)GetParent();
1150 father
->GetClientSize(&panel_width
, &panel_height
);
1151 GetSize(&width
, &height
);
1152 GetPosition(&x
, &y
);
1157 if (direction
& wxHORIZONTAL
)
1158 new_x
= (int)((panel_width
- width
)/2);
1160 if (direction
& wxVERTICAL
)
1161 new_y
= (int)((panel_height
- height
)/2);
1163 SetSize(new_x
, new_y
, -1, -1);
1167 // Coordinates relative to the window
1168 void wxWindow::WarpPointer (int x
, int y
)
1170 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
1173 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
1179 int wxWindow::GetScrollPos(int orient
) const
1181 if (orient
== wxHORIZONTAL
)
1182 return m_scrollPosX
;
1184 return m_scrollPosY
;
1186 Widget scrollBar = (Widget) ((orient == wxHORIZONTAL) ? m_hScrollBar : m_vScrollBar);
1190 XtVaGetValues(scrollBar,
1191 XmNvalue, &pos, NULL);
1199 // This now returns the whole range, not just the number
1200 // of positions that we can scroll.
1201 int wxWindow::GetScrollRange(int orient
) const
1203 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1207 XtVaGetValues(scrollBar
,
1208 XmNmaximum
, &range
, NULL
);
1215 int wxWindow::GetScrollThumb(int orient
) const
1217 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1221 XtVaGetValues(scrollBar
,
1222 XmNsliderSize
, &thumb
, NULL
);
1229 void wxWindow::SetScrollPos(int orient
, int pos
, bool WXUNUSED(refresh
))
1231 Widget scrollBar
= (Widget
) ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1234 XtVaSetValues (scrollBar
,
1238 if (orient
== wxHORIZONTAL
)
1245 // New function that will replace some of the above.
1246 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
1247 int range
, bool WXUNUSED(refresh
))
1250 GetSize(& oldW
, & oldH
);
1254 if (thumbVisible
== 0)
1257 if (thumbVisible
> range
)
1258 thumbVisible
= range
;
1260 // Save the old state to see if it changed
1261 WXWidget oldScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1263 if (orient
== wxHORIZONTAL
)
1265 if (thumbVisible
== range
)
1268 DestroyScrollbar(wxHORIZONTAL
);
1273 CreateScrollbar(wxHORIZONTAL
);
1276 if (orient
== wxVERTICAL
)
1278 if (thumbVisible
== range
)
1281 DestroyScrollbar(wxVERTICAL
);
1286 CreateScrollbar(wxVERTICAL
);
1289 WXWidget newScrollBar
= ((orient
== wxHORIZONTAL
) ? m_hScrollBar
: m_vScrollBar
);
1291 if (oldScrollBar
!= newScrollBar
)
1293 // This is important! Without it, scrollbars misbehave
1295 XtUnrealizeWidget((Widget
) m_scrolledWindow
);
1296 XmScrolledWindowSetAreas ((Widget
) m_scrolledWindow
, (Widget
) m_hScrollBar
, (Widget
) m_vScrollBar
, (Widget
) m_drawingArea
);
1297 XtRealizeWidget((Widget
) m_scrolledWindow
);
1298 XtManageChild((Widget
) m_scrolledWindow
);
1302 XtVaSetValues((Widget
) newScrollBar
,
1306 XmNsliderSize
, thumbVisible
,
1309 if (orient
== wxHORIZONTAL
)
1315 GetSize(& newW
, & newH
);
1317 // Adjusting scrollbars can resize the canvas accidentally
1318 if (newW
!= oldW
|| newH
!= oldH
)
1319 SetSize(-1, -1, oldW
, oldH
);
1322 // Does a physical scroll
1323 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRect
*rect
)
1325 // cerr << "Scrolling. delta = " << dx << ", " << dy << endl;
1329 // Use specified rectangle
1330 x
= rect
->x
; y
= rect
->y
; w
= rect
->width
; h
= rect
->height
;
1334 // Use whole client area
1336 GetClientSize(& w
, & h
);
1339 int x1
= (dx
>= 0) ? x
: x
- dx
;
1340 int y1
= (dy
>= 0) ? y
: y
- dy
;
1341 int w1
= w
- abs(dx
);
1342 int h1
= h
- abs(dy
);
1343 int x2
= (dx
>= 0) ? x
+ dx
: x
;
1344 int y2
= (dy
>= 0) ? y
+ dy
: y
;
1346 wxClientDC
dc(this);
1348 dc
.SetLogicalFunction (wxCOPY
);
1350 Widget widget
= (Widget
) GetMainWidget();
1351 Window window
= XtWindow(widget
);
1352 Display
* display
= XtDisplay(widget
);
1354 XCopyArea(display
, window
,
1355 window
, (GC
) dc
.GetGC(),
1360 dc
.SetAutoSetting(TRUE
);
1361 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1362 dc
.SetBrush(brush
); // ??
1364 // We'll add rectangles to the list of update rectangles
1365 // according to which bits we've exposed.
1370 wxRect
*rect
= new wxRect
;
1376 XFillRectangle(display
, window
,
1377 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1381 rect
->width
= rect
->width
;
1382 rect
->height
= rect
->height
;
1384 updateRects
.Append((wxObject
*) rect
);
1388 wxRect
*rect
= new wxRect
;
1390 rect
->x
= x
+ w
+ dx
;
1395 XFillRectangle(display
, window
,
1396 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
,
1401 rect
->width
= rect
->width
;
1402 rect
->height
= rect
->height
;
1404 updateRects
.Append((wxObject
*) rect
);
1408 wxRect
*rect
= new wxRect
;
1415 XFillRectangle(display
, window
,
1416 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1420 rect
->width
= rect
->width
;
1421 rect
->height
= rect
->height
;
1423 updateRects
.Append((wxObject
*) rect
);
1427 wxRect
*rect
= new wxRect
;
1430 rect
->y
= y
+ h
+ dy
;
1434 XFillRectangle(display
, window
,
1435 (GC
) dc
.GetGC(), rect
->x
, rect
->y
, rect
->width
, rect
->height
);
1439 rect
->width
= rect
->width
;
1440 rect
->height
= rect
->height
;
1442 updateRects
.Append((wxObject
*) rect
);
1444 dc
.SetBrush(wxNullBrush
);
1446 // Now send expose events
1448 wxNode
* node
= updateRects
.First();
1451 wxRect
* rect
= (wxRect
*) node
->Data();
1454 event
.type
= Expose
;
1455 event
.display
= display
;
1456 event
.send_event
= True
;
1457 event
.window
= window
;
1461 event
.width
= rect
->width
;
1462 event
.height
= rect
->height
;
1466 XSendEvent(display
, window
, False
, ExposureMask
, (XEvent
*)&event
);
1468 node
= node
->Next();
1472 // Delete the update rects
1473 node
= updateRects
.First();
1476 wxRect
* rect
= (wxRect
*) node
->Data();
1478 node
= node
->Next();
1481 XmUpdateDisplay((Widget
) GetMainWidget());
1484 void wxWindow::OnChar(wxKeyEvent
& event
)
1488 if ( event.KeyCode() == WXK_TAB ) {
1489 // propagate the TABs to the parent - it's up to it to decide what
1491 if ( GetParent() ) {
1492 if ( GetParent()->ProcessEvent(event) )
1499 void wxWindow::OnKeyDown(wxKeyEvent
& event
)
1504 void wxWindow::OnKeyUp(wxKeyEvent
& event
)
1509 void wxWindow::OnPaint(wxPaintEvent
& event
)
1514 bool wxWindow::IsEnabled() const
1516 // TODO. Is this right?
1517 // return XtGetSensitive((Widget) GetMainWidget());
1521 // Dialog support: override these and call
1522 // base class members to add functionality
1523 // that can't be done using validators.
1524 // NOTE: these functions assume that controls
1525 // are direct children of this window, not grandchildren
1526 // or other levels of descendant.
1528 // Transfer values to controls. If returns FALSE,
1529 // it's an application error (pops up a dialog)
1530 bool wxWindow::TransferDataToWindow()
1532 wxNode
*node
= GetChildren().First();
1535 wxWindow
*child
= (wxWindow
*)node
->Data();
1536 if ( child
->GetValidator() &&
1537 !child
->GetValidator()->TransferToWindow() )
1539 wxLogError("Could not transfer data to window.");
1543 node
= node
->Next();
1548 // Transfer values from controls. If returns FALSE,
1549 // validation failed: don't quit
1550 bool wxWindow::TransferDataFromWindow()
1552 wxNode
*node
= GetChildren().First();
1555 wxWindow
*child
= (wxWindow
*)node
->Data();
1556 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1561 node
= node
->Next();
1566 bool wxWindow::Validate()
1568 wxNode
*node
= GetChildren().First();
1571 wxWindow
*child
= (wxWindow
*)node
->Data();
1572 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1577 node
= node
->Next();
1582 // Get the window with the focus
1583 wxWindow
*wxWindow::FindFocus()
1589 void wxWindow::AddChild(wxWindow
*child
)
1591 GetChildren().Append(child
);
1592 child
->m_windowParent
= this;
1595 void wxWindow::RemoveChild(wxWindow
*child
)
1597 GetChildren().DeleteObject(child
);
1598 child
->m_windowParent
= NULL
;
1601 // Reparents this window to have the new parent.
1602 bool wxWindow::Reparent(wxWindow
* WXUNUSED(parent
))
1604 // For now, we indicate that this isn't implemented.
1608 void wxWindow::DestroyChildren()
1610 wxNode
*node
= GetChildren().First();
1613 wxNode
* next
= node
->Next();
1614 wxWindow
* child
= (wxWindow
*) node
->Data();
1618 GetChildren().Clear();
1621 while ((node
= GetChildren().First()) != (wxNode
*)NULL
) {
1623 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1625 if ( GetChildren().Member(child
) )
1632 void wxWindow::MakeModal(bool modal
)
1634 // Disable all other windows
1635 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1637 wxNode
*node
= wxTopLevelWindows
.First();
1640 wxWindow
*win
= (wxWindow
*)node
->Data();
1642 win
->Enable(!modal
);
1644 node
= node
->Next();
1649 // If nothing defined for this, try the parent.
1650 // E.g. we may be a button loaded from a resource, with no callback function
1652 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1654 if (GetEventHandler()->ProcessEvent(event
) )
1657 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1660 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1664 UnsetConstraints(m_constraints
);
1665 delete m_constraints
;
1670 // Make sure other windows know they're part of a 'meaningful relationship'
1671 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1672 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1673 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1674 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1675 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1676 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1677 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1678 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1679 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1680 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1681 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1682 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1683 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1684 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1685 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1686 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1690 // This removes any dangling pointers to this window
1691 // in other windows' constraintsInvolvedIn lists.
1692 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1696 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1697 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1698 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1699 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1700 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1701 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1702 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1703 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1704 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1705 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1706 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1707 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1708 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1709 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1710 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1711 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1715 // Back-pointer to other windows we're involved with, so if we delete
1716 // this window, we must delete any constraints we're involved with.
1717 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1719 if (!m_constraintsInvolvedIn
)
1720 m_constraintsInvolvedIn
= new wxList
;
1721 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1722 m_constraintsInvolvedIn
->Append(otherWin
);
1725 // REMOVE back-pointer to other windows we're involved with.
1726 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1728 if (m_constraintsInvolvedIn
)
1729 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1732 // Reset any constraints that mention this window
1733 void wxWindow::DeleteRelatedConstraints()
1735 if (m_constraintsInvolvedIn
)
1737 wxNode
*node
= m_constraintsInvolvedIn
->First();
1740 wxWindow
*win
= (wxWindow
*)node
->Data();
1741 wxNode
*next
= node
->Next();
1742 wxLayoutConstraints
*constr
= win
->GetConstraints();
1744 // Reset any constraints involving this window
1747 constr
->left
.ResetIfWin((wxWindow
*)this);
1748 constr
->top
.ResetIfWin((wxWindow
*)this);
1749 constr
->right
.ResetIfWin((wxWindow
*)this);
1750 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1751 constr
->width
.ResetIfWin((wxWindow
*)this);
1752 constr
->height
.ResetIfWin((wxWindow
*)this);
1753 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1754 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1759 delete m_constraintsInvolvedIn
;
1760 m_constraintsInvolvedIn
= NULL
;
1764 void wxWindow::SetSizer(wxSizer
*sizer
)
1766 m_windowSizer
= sizer
;
1768 sizer
->SetSizerParent((wxWindow
*)this);
1775 bool wxWindow::Layout()
1777 if (GetConstraints())
1780 GetClientSize(&w
, &h
);
1781 GetConstraints()->width
.SetValue(w
);
1782 GetConstraints()->height
.SetValue(h
);
1785 // If top level (one sizer), evaluate the sizer's constraints.
1789 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1790 GetSizer()->LayoutPhase1(&noChanges
);
1791 GetSizer()->LayoutPhase2(&noChanges
);
1792 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1797 // Otherwise, evaluate child constraints
1798 ResetConstraints(); // Mark all constraints as unevaluated
1799 DoPhase(1); // Just one phase need if no sizers involved
1801 SetConstraintSizes(); // Recursively set the real window sizes
1807 // Do a phase of evaluating constraints:
1808 // the default behaviour. wxSizers may do a similar
1809 // thing, but also impose their own 'constraints'
1810 // and order the evaluation differently.
1811 bool wxWindow::LayoutPhase1(int *noChanges
)
1813 wxLayoutConstraints
*constr
= GetConstraints();
1816 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1822 bool wxWindow::LayoutPhase2(int *noChanges
)
1832 // Do a phase of evaluating child constraints
1833 bool wxWindow::DoPhase(int phase
)
1835 int noIterations
= 0;
1836 int maxIterations
= 500;
1840 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1844 wxNode
*node
= GetChildren().First();
1847 wxWindow
*child
= (wxWindow
*)node
->Data();
1848 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1850 wxLayoutConstraints
*constr
= child
->GetConstraints();
1853 if (succeeded
.Member(child
))
1858 int tempNoChanges
= 0;
1859 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1860 noChanges
+= tempNoChanges
;
1863 succeeded
.Append(child
);
1868 node
= node
->Next();
1875 void wxWindow::ResetConstraints()
1877 wxLayoutConstraints
*constr
= GetConstraints();
1880 constr
->left
.SetDone(FALSE
);
1881 constr
->top
.SetDone(FALSE
);
1882 constr
->right
.SetDone(FALSE
);
1883 constr
->bottom
.SetDone(FALSE
);
1884 constr
->width
.SetDone(FALSE
);
1885 constr
->height
.SetDone(FALSE
);
1886 constr
->centreX
.SetDone(FALSE
);
1887 constr
->centreY
.SetDone(FALSE
);
1889 wxNode
*node
= GetChildren().First();
1892 wxWindow
*win
= (wxWindow
*)node
->Data();
1893 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1894 win
->ResetConstraints();
1895 node
= node
->Next();
1899 // Need to distinguish between setting the 'fake' size for
1900 // windows and sizers, and setting the real values.
1901 void wxWindow::SetConstraintSizes(bool recurse
)
1903 wxLayoutConstraints
*constr
= GetConstraints();
1904 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1905 constr
->width
.GetDone() && constr
->height
.GetDone())
1907 int x
= constr
->left
.GetValue();
1908 int y
= constr
->top
.GetValue();
1909 int w
= constr
->width
.GetValue();
1910 int h
= constr
->height
.GetValue();
1912 // If we don't want to resize this window, just move it...
1913 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1914 (constr
->height
.GetRelationship() != wxAsIs
))
1916 // Calls Layout() recursively. AAAGH. How can we stop that.
1917 // Simply take Layout() out of non-top level OnSizes.
1918 SizerSetSize(x
, y
, w
, h
);
1927 char *windowClass
= this->GetClassInfo()->GetClassName();
1930 if (GetName() == "")
1931 winName
= "unnamed";
1933 winName
= GetName();
1934 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1935 if (!constr
->left
.GetDone())
1936 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1937 if (!constr
->right
.GetDone())
1938 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1939 if (!constr
->width
.GetDone())
1940 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1941 if (!constr
->height
.GetDone())
1942 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1943 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1948 wxNode
*node
= GetChildren().First();
1951 wxWindow
*win
= (wxWindow
*)node
->Data();
1952 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1953 win
->SetConstraintSizes();
1954 node
= node
->Next();
1959 // This assumes that all sizers are 'on' the same
1960 // window, i.e. the parent of this window.
1961 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1963 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1964 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1968 m_sizerParent
->GetPosition(&xp
, &yp
);
1969 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1974 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1978 TransformSizerToActual(&xx
, &yy
);
1979 SetSize(xx
, yy
, w
, h
);
1982 void wxWindow::SizerMove(int x
, int y
)
1986 TransformSizerToActual(&xx
, &yy
);
1990 // Only set the size/position of the constraint (if any)
1991 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1993 wxLayoutConstraints
*constr
= GetConstraints();
1998 constr
->left
.SetValue(x
);
1999 constr
->left
.SetDone(TRUE
);
2003 constr
->top
.SetValue(y
);
2004 constr
->top
.SetDone(TRUE
);
2008 constr
->width
.SetValue(w
);
2009 constr
->width
.SetDone(TRUE
);
2013 constr
->height
.SetValue(h
);
2014 constr
->height
.SetDone(TRUE
);
2019 void wxWindow::MoveConstraint(int x
, int y
)
2021 wxLayoutConstraints
*constr
= GetConstraints();
2026 constr
->left
.SetValue(x
);
2027 constr
->left
.SetDone(TRUE
);
2031 constr
->top
.SetValue(y
);
2032 constr
->top
.SetDone(TRUE
);
2037 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
2039 wxLayoutConstraints
*constr
= GetConstraints();
2042 *w
= constr
->width
.GetValue();
2043 *h
= constr
->height
.GetValue();
2049 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
2051 wxLayoutConstraints
*constr
= GetConstraints();
2054 *w
= constr
->width
.GetValue();
2055 *h
= constr
->height
.GetValue();
2058 GetClientSize(w
, h
);
2061 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
2063 wxLayoutConstraints
*constr
= GetConstraints();
2066 *x
= constr
->left
.GetValue();
2067 *y
= constr
->top
.GetValue();
2073 bool wxWindow::Close(bool force
)
2075 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
2076 event
.SetEventObject(this);
2077 #if WXWIN_COMPATIBILITY
2078 event
.SetForce(force
);
2080 event
.SetCanVeto(!force
);
2082 return GetEventHandler()->ProcessEvent(event
);
2085 wxObject
* wxWindow::GetChild(int number
) const
2087 // Return a pointer to the Nth object in the window
2088 wxNode
*node
= GetChildren().First();
2091 node
= node
->Next() ;
2094 wxObject
*obj
= (wxObject
*)node
->Data();
2101 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
2103 // Obsolete function
2106 void wxWindow::Clear()
2108 wxClientDC
dc(this);
2109 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
2110 dc
.SetBackground(brush
);
2114 // Fits the panel around the items
2115 void wxWindow::Fit()
2119 wxNode
*node
= GetChildren().First();
2122 wxWindow
*win
= (wxWindow
*)node
->Data();
2124 win
->GetPosition(&wx
, &wy
);
2125 win
->GetSize(&ww
, &wh
);
2126 if ( wx
+ ww
> maxX
)
2128 if ( wy
+ wh
> maxY
)
2131 node
= node
->Next();
2133 SetClientSize(maxX
+ 5, maxY
+ 5);
2136 void wxWindow::SetValidator(const wxValidator
& validator
)
2138 if ( m_windowValidator
)
2139 delete m_windowValidator
;
2140 m_windowValidator
= validator
.Clone();
2142 if ( m_windowValidator
)
2143 m_windowValidator
->SetWindow(this) ;
2146 void wxWindow::SetClientObject( wxClientData
*data
)
2148 if (m_clientObject
) delete m_clientObject
;
2149 m_clientObject
= data
;
2152 wxClientData
*wxWindow::GetClientObject()
2154 return m_clientObject
;
2157 void wxWindow::SetClientData( void *data
)
2159 m_clientData
= data
;
2162 void *wxWindow::GetClientData()
2164 return m_clientData
;
2167 // Find a window by id or name
2168 wxWindow
*wxWindow::FindWindow(long id
)
2173 wxNode
*node
= GetChildren().First();
2176 wxWindow
*child
= (wxWindow
*)node
->Data();
2177 wxWindow
*found
= child
->FindWindow(id
);
2180 node
= node
->Next();
2185 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
2187 if ( GetName() == name
)
2190 wxNode
*node
= GetChildren().First();
2193 wxWindow
*child
= (wxWindow
*)node
->Data();
2194 wxWindow
*found
= child
->FindWindow(name
);
2197 node
= node
->Next();
2202 void wxWindow::OnIdle(wxIdleEvent
& event
)
2204 // This calls the UI-update mechanism (querying windows for
2205 // menu/toolbar/control state information)
2209 // Raise the window to the top of the Z order
2210 void wxWindow::Raise()
2212 Window window
= XtWindow((Widget
) GetTopWidget());
2213 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2216 // Lower the window to the bottom of the Z order
2217 void wxWindow::Lower()
2219 Window window
= XtWindow((Widget
) GetTopWidget());
2220 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
2223 bool wxWindow::AcceptsFocus() const
2225 return IsShown() && IsEnabled();
2228 // Update region access
2229 wxRegion
& wxWindow::GetUpdateRegion() const
2231 return (wxRegion
&) m_updateRegion
;
2234 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
2236 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
2239 bool wxWindow::IsExposed(const wxPoint
& pt
) const
2241 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
2244 bool wxWindow::IsExposed(const wxRect
& rect
) const
2246 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
2250 * Allocates control IDs
2253 int wxWindow::NewControlId()
2255 static int s_controlId
= 0;
2260 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
2262 m_acceleratorTable
= accel
;
2265 // All widgets should have this as their resize proc.
2266 // OnSize sent to wxWindow via client data.
2267 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
2269 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
2273 if (win
->PreResize())
2276 win
->GetSize(&width
, &height
);
2277 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
2278 sizeEvent
.SetEventObject(win
);
2279 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
2283 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
2285 wxWindow
*oldItem
= NULL
;
2286 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
2287 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
2289 wxLogError("Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
2293 wxWidgetHashTable
->Put ((long) w
, win
);
2297 wxWindow
*wxGetWindowFromTable(Widget w
)
2299 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
2302 void wxDeleteWindowFromTable(Widget w
)
2304 wxWidgetHashTable
->Delete((long)w
);
2307 // Get the underlying X window and display
2308 WXWindow
wxWindow::GetXWindow() const
2310 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
2313 WXDisplay
*wxWindow::GetXDisplay() const
2315 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
2318 WXWidget
wxWindow::GetMainWidget() const
2321 return m_drawingArea
;
2323 return m_mainWidget
;
2326 WXWidget
wxWindow::GetClientWidget() const
2328 if (m_drawingArea
!= (WXWidget
) 0)
2329 return m_drawingArea
;
2331 return GetMainWidget();
2334 WXWidget
wxWindow::GetTopWidget() const
2336 return GetMainWidget();
2339 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
2340 XmDrawingAreaCallbackStruct
* cbs
)
2342 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
2345 XEvent
* event
= cbs
->event
;
2346 wxWindow
* win
= (wxWindow
*) clientData
;
2347 Display
* display
= (Display
*) win
->GetXDisplay();
2349 switch (event
->type
)
2353 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
2354 event
->xexpose
.width
, event
->xexpose
.height
);
2356 cout << "Expose proc. wxRect: " << rect->x << ", " << rect->y << ", ";
2357 cout << rect->width << ", " << rect->height << "\n\n";
2360 win
->m_updateRects
.Append((wxObject
*) rect
);
2362 if (event
-> xexpose
.count
== 0)
2365 wxPaintEvent event(win->GetId());
2366 event.SetEventObject(win);
2367 win->GetEventHandler()->ProcessEvent(event);
2371 win
->ClearUpdateRects();
2377 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
2383 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
2385 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
2387 XmDrawingAreaCallbackStruct cbs
;
2390 //if (event->mode!=NotifyNormal)
2393 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
2394 ((XCrossingEvent
&) ev
) = *event
;
2396 cbs
.reason
= XmCR_INPUT
;
2399 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2402 // Fix to make it work under Motif 1.0 (!)
2403 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
2407 XmDrawingAreaCallbackStruct cbs
;
2410 //ev.xbutton = *event;
2411 ev
= *((XEvent
*) event
);
2412 cbs
.reason
= XmCR_INPUT
;
2415 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
2419 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
2421 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
2427 if (cbs
->reason
!= XmCR_INPUT
)
2430 local_event
= *(cbs
->event
); // We must keep a copy!
2433 switch (local_event.xany.type)
2436 cout << "EnterNotify\n";
2439 cout << "LeaveNotify\n";
2442 cout << "ButtonPress\n";
2445 cout << "ButtonRelease\n";
2448 cout << "MotionNotify\n";
2451 cout << "Something else\n";
2456 switch (local_event
.xany
.type
)
2464 wxEventType eventType
= wxEVT_NULL
;
2466 if (local_event
.xany
.type
== EnterNotify
)
2468 //if (local_event.xcrossing.mode!=NotifyNormal)
2469 // return ; // Ignore grab events
2470 eventType
= wxEVT_ENTER_WINDOW
;
2471 // canvas->GetEventHandler()->OnSetFocus();
2473 else if (local_event
.xany
.type
== LeaveNotify
)
2475 //if (local_event.xcrossing.mode!=NotifyNormal)
2476 // return ; // Ignore grab events
2477 eventType
= wxEVT_LEAVE_WINDOW
;
2478 // canvas->GetEventHandler()->OnKillFocus();
2480 else if (local_event
.xany
.type
== MotionNotify
)
2482 eventType
= wxEVT_MOTION
;
2483 if (local_event
.xmotion
.is_hint
== NotifyHint
)
2486 Display
*dpy
= XtDisplay (drawingArea
);
2488 XQueryPointer (dpy
, XtWindow (drawingArea
),
2490 &local_event
.xmotion
.x_root
,
2491 &local_event
.xmotion
.y_root
,
2492 &local_event
.xmotion
.x
,
2493 &local_event
.xmotion
.y
,
2494 &local_event
.xmotion
.state
);
2501 else if (local_event
.xany
.type
== ButtonPress
)
2503 if (local_event
.xbutton
.button
== Button1
)
2505 eventType
= wxEVT_LEFT_DOWN
;
2506 canvas
->m_button1Pressed
= TRUE
;
2508 else if (local_event
.xbutton
.button
== Button2
)
2510 eventType
= wxEVT_MIDDLE_DOWN
;
2511 canvas
->m_button2Pressed
= TRUE
;
2513 else if (local_event
.xbutton
.button
== Button3
)
2515 eventType
= wxEVT_RIGHT_DOWN
;
2516 canvas
->m_button3Pressed
= TRUE
;
2519 else if (local_event
.xany
.type
== ButtonRelease
)
2521 if (local_event
.xbutton
.button
== Button1
)
2523 eventType
= wxEVT_LEFT_UP
;
2524 canvas
->m_button1Pressed
= FALSE
;
2526 else if (local_event
.xbutton
.button
== Button2
)
2528 eventType
= wxEVT_MIDDLE_UP
;
2529 canvas
->m_button2Pressed
= FALSE
;
2531 else if (local_event
.xbutton
.button
== Button3
)
2533 eventType
= wxEVT_RIGHT_UP
;
2534 canvas
->m_button3Pressed
= FALSE
;
2538 wxMouseEvent
wxevent (eventType
);
2539 wxevent
.m_eventHandle
= (char *) &local_event
;
2541 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2542 || (event_left_is_down (&local_event
)
2543 && (eventType
!= wxEVT_LEFT_UP
)));
2544 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2545 || (event_middle_is_down (&local_event
)
2546 && (eventType
!= wxEVT_MIDDLE_UP
)));
2547 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2548 || (event_right_is_down (&local_event
)
2549 && (eventType
!= wxEVT_RIGHT_UP
)));
2551 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2552 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2553 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2554 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2555 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2557 // Now check if we need to translate this event into a double click
2558 if (TRUE
) // canvas->doubleClickAllowed)
2560 if (wxevent
.ButtonDown())
2562 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2564 // get button and time-stamp
2566 if (wxevent
.LeftDown()) button
= 1;
2567 else if (wxevent
.MiddleDown()) button
= 2;
2568 else if (wxevent
.RightDown()) button
= 3;
2569 long ts
= wxevent
.GetTimestamp();
2570 // check, if single or double click
2571 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2574 canvas
->m_lastButton
= 0;
2575 switch ( eventType
)
2577 case wxEVT_LEFT_DOWN
:
2578 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2580 case wxEVT_MIDDLE_DOWN
:
2581 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2583 case wxEVT_RIGHT_DOWN
:
2584 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2594 // not fast enough or different button
2595 canvas
->m_lastTS
= ts
;
2596 canvas
->m_lastButton
= button
;
2601 wxevent
.SetId(canvas
->GetId());
2602 wxevent
.SetEventObject(canvas
);
2603 wxevent
.m_x
= local_event
.xbutton
.x
;
2604 wxevent
.m_y
= local_event
.xbutton
.y
;
2605 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2607 if (eventType == wxEVT_ENTER_WINDOW ||
2608 eventType == wxEVT_LEAVE_WINDOW ||
2609 eventType == wxEVT_MOTION
2618 // XComposeStatus compose;
2619 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2620 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2621 int id
= wxCharCodeXToWX (keySym
);
2623 wxEventType eventType
= wxEVT_CHAR
;
2625 wxKeyEvent
event (eventType
);
2627 if (local_event
.xkey
.state
& ShiftMask
)
2628 event
.m_shiftDown
= TRUE
;
2629 if (local_event
.xkey
.state
& ControlMask
)
2630 event
.m_controlDown
= TRUE
;
2631 if (local_event
.xkey
.state
& Mod3Mask
)
2632 event
.m_altDown
= TRUE
;
2633 if (local_event
.xkey
.state
& Mod1Mask
)
2634 event
.m_metaDown
= TRUE
;
2635 event
.SetEventObject(canvas
);
2636 event
.m_keyCode
= id
;
2637 event
.SetTimestamp(local_event
.xkey
.time
);
2641 // Implement wxFrame::OnCharHook by checking ancestor.
2642 wxWindow
*parent
= canvas
->GetParent();
2643 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2644 parent
= parent
->GetParent();
2648 event
.SetEventType(wxEVT_CHAR_HOOK
);
2649 if (parent
->GetEventHandler()->ProcessEvent(event
))
2653 // For simplicity, OnKeyDown is the same as OnChar
2654 // TODO: filter modifier key presses from OnChar
2655 event
.SetEventType(wxEVT_KEY_DOWN
);
2657 // Only process OnChar if OnKeyDown didn't swallow it
2658 if (!canvas
->GetEventHandler()->ProcessEvent (event
))
2660 event
.SetEventType(wxEVT_CHAR
);
2661 canvas
->GetEventHandler()->ProcessEvent (event
);
2669 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2670 int id
= wxCharCodeXToWX (keySym
);
2672 wxKeyEvent
event (wxEVT_KEY_UP
);
2674 if (local_event
.xkey
.state
& ShiftMask
)
2675 event
.m_shiftDown
= TRUE
;
2676 if (local_event
.xkey
.state
& ControlMask
)
2677 event
.m_controlDown
= TRUE
;
2678 if (local_event
.xkey
.state
& Mod3Mask
)
2679 event
.m_altDown
= TRUE
;
2680 if (local_event
.xkey
.state
& Mod1Mask
)
2681 event
.m_metaDown
= TRUE
;
2682 event
.SetEventObject(canvas
);
2683 event
.m_keyCode
= id
;
2684 event
.SetTimestamp(local_event
.xkey
.time
);
2688 canvas
->GetEventHandler()->ProcessEvent (event
);
2694 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2696 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2697 event
.SetEventObject(canvas
);
2698 canvas
->GetEventHandler()->ProcessEvent(event
);
2704 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2706 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2707 event
.SetEventObject(canvas
);
2708 canvas
->GetEventHandler()->ProcessEvent(event
);
2717 void wxWindow::DoPaint()
2719 //TODO : make a temporary gc so we can do the XCopyArea below
2720 if (m_backingPixmap
&& !m_needsRefresh
)
2724 GC tempGC
= (GC
) dc
.GetBackingGC();
2726 Widget widget
= (Widget
) GetMainWidget();
2731 // We have to test whether it's a wxScrolledWindow (hack!)
2732 // because otherwise we don't know how many pixels have been
2733 // scrolled. We might solve this in the future by defining
2734 // virtual wxWindow functions to get the scroll position in pixels.
2735 // Or, each kind of scrolled window has to implement backing
2736 // stores itself, using generic wxWindows code.
2737 if (this->IsKindOf(CLASSINFO(wxScrolledWindow
)))
2739 wxScrolledWindow
* scrolledWindow
= (wxScrolledWindow
*) this;
2741 scrolledWindow
->CalcScrolledPosition(0, 0, & x
, & y
);
2747 // TODO: This could be optimized further by only copying the
2748 // areas in the current update region.
2750 // Only blit the part visible in the client area. The backing pixmap
2751 // always starts at 0, 0 but we may be looking at only a portion of it.
2752 wxSize clientArea
= GetClientSize();
2753 int toBlitX
= m_pixmapWidth
- scrollPosX
;
2754 int toBlitY
= m_pixmapHeight
- scrollPosY
;
2756 // Copy whichever is samller, the amount of pixmap we have to copy,
2757 // or the size of the client area.
2758 toBlitX
= wxMin(toBlitX
, clientArea
.x
);
2759 toBlitY
= wxMin(toBlitY
, clientArea
.y
);
2761 // Make sure we're not negative
2762 toBlitX
= wxMax(0, toBlitX
);
2763 toBlitY
= wxMax(0, toBlitY
);
2765 XCopyArea (XtDisplay (widget
), (Pixmap
) m_backingPixmap
, XtWindow (widget
), tempGC
,
2766 scrollPosX
, scrollPosY
, // Start at the scroll position
2767 toBlitX
, toBlitY
, // How much of the pixmap to copy
2768 0, 0); // Destination
2772 // Set an erase event first
2773 wxEraseEvent
eraseEvent(GetId());
2774 eraseEvent
.SetEventObject(this);
2775 GetEventHandler()->ProcessEvent(eraseEvent
);
2777 wxPaintEvent
event(GetId());
2778 event
.SetEventObject(this);
2779 GetEventHandler()->ProcessEvent(event
);
2781 m_needsRefresh
= FALSE
;
2785 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2786 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2788 // A bit of optimization to help sort out the flickers.
2789 int oldX
, oldY
, oldW
, oldH
;
2790 GetSize(& oldW
, & oldH
);
2791 GetPosition(& oldX
, & oldY
);
2793 bool useOldPos
= FALSE
;
2794 bool useOldSize
= FALSE
;
2796 if ((x
== -1) && (x
== -1) && ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0))
2798 else if (x
== oldX
&& y
== oldY
)
2801 if ((w
== -1) && (h
== -1))
2803 else if (w
== oldW
&& h
== oldH
)
2806 if (!wxNoOptimize::CanOptimize())
2808 useOldSize
= FALSE
; useOldPos
= FALSE
;
2811 if (useOldPos
&& useOldSize
)
2814 Widget drawingArea
= (Widget
) m_drawingArea
;
2815 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2818 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2819 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2821 int xx
= x
; int yy
= y
;
2822 AdjustForParentClientOrigin(xx
, yy
, sizeFlags
);
2826 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2828 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2832 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2834 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2846 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2847 short thick
, margin
;
2848 XtVaGetValues ((Widget
) m_borderWidget
,
2849 XmNshadowThickness
, &thick
,
2850 XmNmarginWidth
, &margin
,
2852 w
-= 2 * (thick
+ margin
);
2855 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2859 XtVaGetValues ((Widget
) m_scrolledWindow
,
2860 XmNspacing
, &spacing
,
2861 XmNverticalScrollBar
, &sbar
,
2865 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2869 w
-= (spacing
+ wsbar
);
2871 // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
2877 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2878 short thick
, margin
;
2879 XtVaGetValues ((Widget
) m_borderWidget
,
2880 XmNshadowThickness
, &thick
,
2881 XmNmarginHeight
, &margin
,
2883 h
-= 2 * (thick
+ margin
);
2886 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2890 XtVaGetValues ((Widget
) m_scrolledWindow
,
2891 XmNspacing
, &spacing
,
2892 XmNhorizontalScrollBar
, &sbar
,
2896 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2900 h
-= (spacing
+ wsbar
);
2902 // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
2908 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2909 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2913 GetClientSize (&ww, &hh);
2914 wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
2915 sizeEvent.SetEventObject(this);
2917 GetEventHandler()->ProcessEvent(sizeEvent);
2922 void wxWindow::CanvasSetClientSize (int w
, int h
)
2924 Widget drawingArea
= (Widget
) m_drawingArea
;
2926 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2929 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2931 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2932 /* TODO: is this necessary?
2933 allowRepainting = FALSE;
2935 XSync (XtDisplay (drawingArea), FALSE);
2937 while (XtAppPending (wxTheApp->appContext))
2939 XFlush (XtDisplay (drawingArea));
2940 XtAppNextEvent (wxTheApp->appContext, &event);
2941 XtDispatchEvent (&event);
2945 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2948 allowRepainting = TRUE;
2953 wxSizeEvent sizeEvent(wxSize(w, h), GetId());
2954 sizeEvent.SetEventObject(this);
2956 GetEventHandler()->ProcessEvent(sizeEvent);
2960 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2962 // Must return the same thing that was set via SetClientSize
2964 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2969 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2972 if ((Widget
) m_borderWidget
)
2973 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2974 else if ((Widget
) m_scrolledWindow
)
2975 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2977 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2983 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2986 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2988 // We may be faking the client origin.
2989 // So a window that's really at (0, 30) may appear
2990 // (to wxWin apps) to be at (0, 0).
2993 wxPoint
pt(GetParent()->GetClientAreaOrigin());
3002 // Add to hash table, add event handler
3003 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
3004 WXWidget formWidget
, int x
, int y
, int width
, int height
)
3006 wxAddWindowToTable((Widget
) mainWidget
, this);
3007 if (CanAddEventHandler())
3009 XtAddEventHandler((Widget
) mainWidget
,
3010 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3012 wxPanelItemEventHandler
,
3019 XtOverrideTranslations ((Widget
) mainWidget
,
3020 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3021 XtFree ((char *) ptr
);
3024 // Some widgets have a parent form widget, e.g. wxRadioBox
3027 if (!wxAddWindowToTable((Widget
) formWidget
, this))
3031 XtOverrideTranslations ((Widget
) formWidget
,
3032 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
3033 XtFree ((char *) ptr
);
3040 SetSize (x
, y
, width
, height
);
3045 // Remove event handler, remove from hash table
3046 bool wxWindow::DetachWidget(WXWidget widget
)
3048 if (CanAddEventHandler())
3050 XtRemoveEventHandler((Widget
) widget
,
3051 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
3053 wxPanelItemEventHandler
,
3057 wxDeleteWindowFromTable((Widget
) widget
);
3061 void wxPanelItemEventHandler (Widget wid
,
3062 XtPointer client_data
,
3064 Boolean
*continueToDispatch
)
3066 // Widget can be a label or the actual widget.
3068 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
3071 wxMouseEvent
wxevent(0);
3072 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
3074 window
->GetEventHandler()->ProcessEvent(wxevent
);
3077 // TODO: probably the key to allowing default behaviour
3079 // Say we set a m_doDefault flag to FALSE at the start of this
3080 // function. Then in e.g. wxWindow::OnMouseEvent we can
3081 // call Default() which sets this flag to TRUE, indicating
3082 // that default processing can happen. Thus, behaviour can appear
3083 // to be overridden just by adding an event handler and not calling
3084 // wxWindow::OnWhatever.
3085 // ALSO, maybe we can use this instead of the current way of handling
3086 // drawing area events, to simplify things.
3087 *continueToDispatch
= True
;
3090 static void wxScrollBarCallback(Widget scrollbar
, XtPointer clientData
,
3091 XmScaleCallbackStruct
*cbs
)
3093 Widget scrolledWindow
= XtParent (scrollbar
);
3094 wxWindow
*win
= (wxWindow
*) wxWidgetHashTable
->Get ((long) scrolledWindow
);
3095 int orientation
= (int) clientData
;
3097 wxEventType eventType
= wxEVT_NULL
;
3098 switch (cbs
->reason
)
3100 case XmCR_INCREMENT
:
3102 eventType
= wxEVT_SCROLL_LINEDOWN
;
3105 case XmCR_DECREMENT
:
3107 eventType
= wxEVT_SCROLL_LINEUP
;
3112 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3115 case XmCR_VALUE_CHANGED
:
3117 // TODO: Should this be intercepted too, or will it cause
3118 // duplicate events?
3119 eventType
= wxEVT_SCROLL_THUMBTRACK
;
3122 case XmCR_PAGE_INCREMENT
:
3124 eventType
= wxEVT_SCROLL_PAGEDOWN
;
3127 case XmCR_PAGE_DECREMENT
:
3129 eventType
= wxEVT_SCROLL_PAGEUP
;
3134 eventType
= wxEVT_SCROLL_TOP
;
3137 case XmCR_TO_BOTTOM
:
3139 eventType
= wxEVT_SCROLL_BOTTOM
;
3144 // Should never get here
3145 wxFAIL_MSG("Unknown scroll event.");
3150 wxScrollEvent
event(eventType
, win
->GetId());
3151 event
.SetEventObject(win
);
3152 event
.SetPosition(cbs
->value
);
3153 event
.SetOrientation( (orientation
== XmHORIZONTAL
) ? wxHORIZONTAL
: wxVERTICAL
);
3155 win
->GetEventHandler()->ProcessEvent(event
);
3158 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3160 switch (xevent
->xany
.type
)
3168 wxEventType eventType
= wxEVT_NULL
;
3170 if (xevent
->xany
.type
== LeaveNotify
)
3172 win
->m_button1Pressed
= FALSE
;
3173 win
->m_button2Pressed
= FALSE
;
3174 win
->m_button3Pressed
= FALSE
;
3177 else if (xevent
->xany
.type
== MotionNotify
)
3179 eventType
= wxEVT_MOTION
;
3181 else if (xevent
->xany
.type
== ButtonPress
)
3183 if (xevent
->xbutton
.button
== Button1
)
3185 eventType
= wxEVT_LEFT_DOWN
;
3186 win
->m_button1Pressed
= TRUE
;
3188 else if (xevent
->xbutton
.button
== Button2
)
3190 eventType
= wxEVT_MIDDLE_DOWN
;
3191 win
->m_button2Pressed
= TRUE
;
3193 else if (xevent
->xbutton
.button
== Button3
)
3195 eventType
= wxEVT_RIGHT_DOWN
;
3196 win
->m_button3Pressed
= TRUE
;
3199 else if (xevent
->xany
.type
== ButtonRelease
)
3201 if (xevent
->xbutton
.button
== Button1
)
3203 eventType
= wxEVT_LEFT_UP
;
3204 win
->m_button1Pressed
= FALSE
;
3206 else if (xevent
->xbutton
.button
== Button2
)
3208 eventType
= wxEVT_MIDDLE_UP
;
3209 win
->m_button2Pressed
= FALSE
;
3211 else if (xevent
->xbutton
.button
== Button3
)
3213 eventType
= wxEVT_RIGHT_UP
;
3214 win
->m_button3Pressed
= FALSE
;
3220 wxevent
.m_eventHandle
= (char *)xevent
;
3221 wxevent
.SetEventType(eventType
);
3224 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
3227 win
->GetPosition(&x2
, &y2
);
3229 // The button x/y must be translated to wxWindows
3230 // window space - the widget might be a label or button,
3234 if (widget
!= (Widget
)win
->GetMainWidget())
3240 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
3241 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
3243 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
3244 || (event_left_is_down (xevent
)
3245 && (eventType
!= wxEVT_LEFT_UP
)));
3246 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
3247 || (event_middle_is_down (xevent
)
3248 && (eventType
!= wxEVT_MIDDLE_UP
)));
3249 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
3250 || (event_right_is_down (xevent
)
3251 && (eventType
!= wxEVT_RIGHT_UP
)));
3253 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
3254 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
3261 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
3263 switch (xevent
->xany
.type
)
3270 // XComposeStatus compose;
3271 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
3272 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
3273 int id
= wxCharCodeXToWX (keySym
);
3275 if (xevent
->xkey
.state
& ShiftMask
)
3276 wxevent
.m_shiftDown
= TRUE
;
3277 if (xevent
->xkey
.state
& ControlMask
)
3278 wxevent
.m_controlDown
= TRUE
;
3279 if (xevent
->xkey
.state
& Mod3Mask
)
3280 wxevent
.m_altDown
= TRUE
;
3281 if (xevent
->xkey
.state
& Mod1Mask
)
3282 wxevent
.m_metaDown
= TRUE
;
3283 wxevent
.SetEventObject(win
);
3284 wxevent
.m_keyCode
= id
;
3285 wxevent
.SetTimestamp(xevent
->xkey
.time
);
3287 wxevent
.m_x
= xevent
->xbutton
.x
;
3288 wxevent
.m_y
= xevent
->xbutton
.y
;
3302 #define YAllocColor XAllocColor
3303 XColor g_itemColors
[5];
3304 int wxComputeColours (Display
*display
, wxColour
* back
, wxColour
* fore
)
3307 static XmColorProc colorProc
;
3309 result
= wxNO_COLORS
;
3313 g_itemColors
[0].red
= (((long) back
->Red ()) << 8);
3314 g_itemColors
[0].green
= (((long) back
->Green ()) << 8);
3315 g_itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
3316 g_itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
3317 if (colorProc
== (XmColorProc
) NULL
)
3319 // Get a ptr to the actual function
3320 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
3321 // And set it back to motif.
3322 XmSetColorCalculation (colorProc
);
3324 (*colorProc
) (&g_itemColors
[wxBACK_INDEX
],
3325 &g_itemColors
[wxFORE_INDEX
],
3326 &g_itemColors
[wxSELE_INDEX
],
3327 &g_itemColors
[wxTOPS_INDEX
],
3328 &g_itemColors
[wxBOTS_INDEX
]);
3329 result
= wxBACK_COLORS
;
3333 g_itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
3334 g_itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
3335 g_itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
3336 g_itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
3337 if (result
== wxNO_COLORS
)
3338 result
= wxFORE_COLORS
;
3341 Display
*dpy
= display
;
3342 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
3346 /* 5 Colours to allocate */
3347 for (int i
= 0; i
< 5; i
++)
3348 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[i
]))
3349 result
= wxNO_COLORS
;
3353 /* Only 1 colour to allocate */
3354 if (!YAllocColor (dpy
, cmap
, &g_itemColors
[wxFORE_INDEX
]))
3355 result
= wxNO_COLORS
;
3362 // Changes the foreground and background colours to be derived
3363 // from the current background colour.
3364 // To change the foreground colour, you must call SetForegroundColour
3366 void wxWindow::ChangeBackgroundColour()
3368 if (GetMainWidget())
3369 DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour
);
3371 // This not necessary
3374 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3376 DoChangeBackgroundColour(m_scrolledWindow
, m_backgroundColour
);
3377 // Have to set the scrollbar colours back since
3378 // the scrolled window seemed to change them
3379 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
3382 DoChangeBackgroundColour(m_hScrollBar
, backgroundColour
);
3384 DoChangeBackgroundColour(m_vScrollBar
, backgroundColour
);
3389 void wxWindow::ChangeForegroundColour()
3391 if (GetMainWidget())
3392 DoChangeForegroundColour(GetMainWidget(), m_foregroundColour
);
3393 if (m_scrolledWindow
&& (GetMainWidget() != m_scrolledWindow
))
3394 DoChangeForegroundColour(m_scrolledWindow
, m_foregroundColour
);
3397 // Change a widget's foreground and background colours.
3399 void wxWindow::DoChangeForegroundColour(WXWidget widget
, wxColour
& foregroundColour
)
3401 // When should we specify the foreground, if it's calculated
3402 // by wxComputeColours?
3403 // Solution: say we start with the default (computed) foreground colour.
3404 // If we call SetForegroundColour explicitly for a control or window,
3405 // then the foreground is changed.
3406 // Therefore SetBackgroundColour computes the foreground colour, and
3407 // SetForegroundColour changes the foreground colour. The ordering is
3410 XtVaSetValues ((Widget
) widget
,
3411 XmNforeground
, foregroundColour
.AllocColour(XtDisplay((Widget
) widget
)),
3415 void wxWindow::DoChangeBackgroundColour(WXWidget widget
, wxColour
& backgroundColour
, bool changeArmColour
)
3417 wxComputeColours (XtDisplay((Widget
) widget
), & backgroundColour
,
3420 XtVaSetValues ((Widget
) widget
,
3421 XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
,
3422 XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
,
3423 XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
,
3424 XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
,
3427 if (changeArmColour
)
3428 XtVaSetValues ((Widget
) widget
,
3429 XmNarmColor
, g_itemColors
[wxSELE_INDEX
].pixel
,
3433 void wxWindow::SetBackgroundColour(const wxColour
& col
)
3435 m_backgroundColour
= col
;
3436 ChangeBackgroundColour();
3439 void wxWindow::SetForegroundColour(const wxColour
& col
)
3441 m_foregroundColour
= col
;
3442 ChangeForegroundColour();
3445 void wxWindow::ChangeFont(bool keepOriginalSize
)
3447 // Note that this causes the widget to be resized back
3448 // to its original size! We therefore have to set the size
3449 // back again. TODO: a better way in Motif?
3450 Widget w
= (Widget
) GetLabelWidget(); // Usually the main widget
3451 if (w
&& m_windowFont
.Ok())
3453 int width
, height
, width1
, height1
;
3454 GetSize(& width
, & height
);
3456 // lesstif 0.87 hangs here
3457 #ifndef LESSTIF_VERSION
3459 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
3463 GetSize(& width1
, & height1
);
3464 if (keepOriginalSize
&& (width
!= width1
|| height
!= height1
))
3466 SetSize(-1, -1, width
, height
);
3471 void wxWindow::SetFont(const wxFont
& font
)
3473 m_windowFont
= font
;
3477 void wxWindow::SetToolTip(const wxString
& tooltip
)
3482 void wxWindow::ClearUpdateRects()
3484 wxNode
* node
= m_updateRects
.First();
3487 wxRect
* rect
= (wxRect
*) node
->Data();
3489 node
= node
->Next();
3491 m_updateRects
.Clear();
3494 bool wxWindow::ProcessAccelerator(wxKeyEvent
& event
)
3496 if (!m_acceleratorTable
.Ok())
3499 int count
= m_acceleratorTable
.GetCount();
3500 wxAcceleratorEntry
* entries
= m_acceleratorTable
.GetEntries();
3502 for (i
= 0; i
< count
; i
++)
3504 wxAcceleratorEntry
* entry
= & (entries
[i
]);
3505 if (entry
->MatchesEvent(event
))
3507 // Bingo, we have a match. Now find a control
3508 // that matches the entry command id.
3510 // Need to go up to the top of the window hierarchy,
3511 // since it might be e.g. a menu item
3512 wxWindow
* parent
= this;
3513 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)) && !parent
->IsKindOf(CLASSINFO(wxDialog
)))
3514 parent
= parent
->GetParent();
3519 if (parent
->IsKindOf(CLASSINFO(wxFrame
)))
3521 // Try for a menu command
3522 wxFrame
* frame
= (wxFrame
*) parent
;
3523 if (frame
->GetMenuBar())
3525 wxMenuItem
* item
= frame
->GetMenuBar()->FindItemForId(entry
->GetCommand());
3528 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, entry
->GetCommand());
3529 commandEvent
.SetEventObject(frame
);
3531 // If ProcessEvent returns TRUE (it was handled), then
3532 // the calling code will skip the event handling.
3533 return frame
->GetEventHandler()->ProcessEvent(commandEvent
);
3538 // Find a child matching the command id
3539 wxWindow
* child
= parent
->FindWindow(entry
->GetCommand());
3545 // Now we process those kinds of windows that we can.
3546 // For now, only buttons.
3547 if (child
->IsKindOf(CLASSINFO(wxButton
)))
3549 wxCommandEvent
commandEvent (wxEVT_COMMAND_BUTTON_CLICKED
, child
->GetId());
3550 commandEvent
.SetEventObject(child
);
3551 return child
->GetEventHandler()->ProcessEvent(commandEvent
);
3558 // We didn't match the key event against an accelerator.
3563 * wxNoOptimize: switch off size optimization
3566 int wxNoOptimize::m_count
= 0;
3568 wxNoOptimize::wxNoOptimize()
3573 wxNoOptimize::~wxNoOptimize()
3578 bool wxNoOptimize::CanOptimize()
3580 return (m_count
== 0);
3583 // For repainting arbitrary windows
3584 void wxUniversalRepaintProc(Widget w
, XtPointer
WXUNUSED(c_data
), XEvent
*event
, char *)
3589 wxWindow
* win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
3593 switch(event
-> type
)
3597 window
= (Window
) win
-> GetXWindow();
3598 display
= (Display
*) win
-> GetXDisplay();
3600 wxRect
* rect
= new wxRect(event
->xexpose
.x
, event
->xexpose
.y
,
3601 event
->xexpose
.width
, event
->xexpose
.height
);
3602 win
->m_updateRects
.Append((wxObject
*) rect
);
3604 if (event
-> xexpose
.count
== 0)
3608 win
->ClearUpdateRects();
3614 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";