1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "window.h"
19 #include "wx/dcclient.h"
23 #include "wx/layout.h"
24 #include "wx/dialog.h"
25 #include "wx/listbox.h"
26 #include "wx/button.h"
27 #include "wx/settings.h"
28 #include "wx/msgdlg.h"
31 #include "wx/menuitem.h"
34 #if wxUSE_DRAG_AND_DROP
40 #include <Xm/DrawingA.h>
41 #include <Xm/ScrolledW.h>
42 #include <Xm/ScrollBar.h>
46 #include "wx/motif/private.h"
50 #define SCROLL_MARGIN 4
51 void wxCanvasRepaintProc (Widget
, XtPointer
, XmDrawingAreaCallbackStruct
* cbs
);
52 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
);
53 void wxCanvasMotionEvent (Widget
, XButtonEvent
* event
);
54 void wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
);
55 void wxPanelItemEventHandler (Widget wid
,
56 XtPointer client_data
,
58 Boolean
*continueToDispatch
);
60 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
61 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
62 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
64 extern wxList wxPendingDelete
;
66 #if !USE_SHARED_LIBRARY
67 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
69 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
70 EVT_CHAR(wxWindow::OnChar
)
71 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
72 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
73 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
74 EVT_IDLE(wxWindow::OnIdle
)
86 m_windowParent
= NULL
;
87 m_windowEventHandler
= this;
89 m_windowCursor
= *wxSTANDARD_CURSOR
;
90 m_children
= new wxList
;
92 m_constraintsInvolvedIn
= NULL
;
96 m_windowValidator
= NULL
;
99 m_caretWidth
= 0; m_caretHeight
= 0;
100 m_caretEnabled
= FALSE
;
101 m_caretShown
= FALSE
;
102 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
103 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
104 m_foregroundColour
= *wxBLACK
;
106 #if wxUSE_DRAG_AND_DROP
107 m_pDropTarget
= NULL
;
111 m_mainWidget
= (WXWidget
) 0;
112 m_button1Pressed
= FALSE
;
113 m_button2Pressed
= FALSE
;
114 m_button3Pressed
= FALSE
;
115 m_winCaptured
= FALSE
;
117 m_hScrollBar
= (WXWidget
) 0;
118 m_vScrollBar
= (WXWidget
) 0;
119 m_borderWidget
= (WXWidget
) 0;
120 m_scrolledWindow
= (WXWidget
) 0;
121 m_drawingArea
= (WXWidget
) 0;
124 m_hScrollingEnabled
= FALSE
;
125 m_vScrollingEnabled
= FALSE
;
126 m_backingPixmap
= (WXPixmap
) 0;
133 m_canAddEventHandler
= FALSE
;
134 m_paintRegion
= (WXRegion
) 0;
138 wxWindow::~wxWindow()
143 XDestroyRegion ((Region
) m_paintRegion
);
144 m_paintRegion
= (WXRegion
) 0;
147 DetachWidget(GetMainWidget()); // Removes event handlers
149 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
152 // Destroy children before destroying self
156 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
158 Widget w
= (Widget
) m_drawingArea
;
159 wxDeleteWindowFromTable(w
);
163 m_mainWidget
= (WXWidget
) 0;
165 // Only if we're _really_ a canvas (not a dialog box/panel)
166 if (m_scrolledWindow
)
168 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
173 XtUnmanageChild ((Widget
) m_hScrollBar
);
174 XtDestroyWidget ((Widget
) m_hScrollBar
);
178 XtUnmanageChild ((Widget
) m_vScrollBar
);
179 XtDestroyWidget ((Widget
) m_vScrollBar
);
181 if (m_scrolledWindow
)
183 XtUnmanageChild ((Widget
) m_scrolledWindow
);
184 XtDestroyWidget ((Widget
) m_scrolledWindow
);
189 XtDestroyWidget ((Widget
) m_borderWidget
);
190 m_borderWidget
= (WXWidget
) 0;
196 // Have to delete constraints/sizer FIRST otherwise
197 // sizers may try to look at deleted windows as they
198 // delete themselves.
199 #if wxUSE_CONSTRAINTS
200 DeleteRelatedConstraints();
203 // This removes any dangling pointers to this window
204 // in other windows' constraintsInvolvedIn lists.
205 UnsetConstraints(m_constraints
);
206 delete m_constraints
;
207 m_constraints
= NULL
;
211 delete m_windowSizer
;
212 m_windowSizer
= NULL
;
214 // If this is a child of a sizer, remove self from parent
216 m_sizerParent
->RemoveChild((wxWindow
*)this);
220 m_windowParent
->RemoveChild(this);
224 // Destroy the window
227 wxDeleteWindowFromTable((Widget
) GetMainWidget());
228 XtDestroyWidget((Widget
) GetMainWidget());
229 SetMainWidget((WXWidget
) NULL
);
235 // Just in case the window has been Closed, but
236 // we're then deleting immediately: don't leave
237 // dangling pointers.
238 wxPendingDelete
.DeleteObject(this);
240 if ( m_windowValidator
)
241 delete m_windowValidator
;
244 // Destroy the window (delayed, if a managed window)
245 bool wxWindow::Destroy()
252 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
256 const wxString
& name
)
261 m_windowParent
= NULL
;
262 m_windowEventHandler
= this;
264 m_windowCursor
= *wxSTANDARD_CURSOR
;
265 m_constraints
= NULL
;
266 m_constraintsInvolvedIn
= NULL
;
267 m_windowSizer
= NULL
;
268 m_sizerParent
= NULL
;
269 m_autoLayout
= FALSE
;
270 m_windowValidator
= NULL
;
271 #if wxUSE_DRAG_AND_DROP
272 m_pDropTarget
= NULL
;
274 m_caretWidth
= 0; m_caretHeight
= 0;
275 m_caretEnabled
= FALSE
;
276 m_caretShown
= FALSE
;
281 m_defaultItem
= NULL
;
282 m_windowParent
= NULL
;
285 m_canAddEventHandler
= FALSE
;
286 m_mainWidget
= (WXWidget
) 0;
287 m_button1Pressed
= FALSE
;
288 m_button2Pressed
= FALSE
;
289 m_button3Pressed
= FALSE
;
290 m_winCaptured
= FALSE
;
292 m_hScrollBar
= (WXWidget
) 0;
293 m_vScrollBar
= (WXWidget
) 0;
294 m_borderWidget
= (WXWidget
) 0;
295 m_scrolledWindow
= (WXWidget
) 0;
296 m_drawingArea
= (WXWidget
) 0;
299 m_hScrollingEnabled
= FALSE
;
300 m_vScrollingEnabled
= FALSE
;
301 m_backingPixmap
= (WXPixmap
) 0;
306 m_paintRegion
= (WXRegion
) 0;
311 if (parent
) parent
->AddChild(this);
318 m_windowId
= (int)NewControlId();
322 // m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) ; ;
323 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
324 m_foregroundColour
= *wxBLACK
;
325 m_defaultForegroundColour
= *wxBLACK
;
327 m_windowStyle
= style
;
330 m_windowId
= (int)NewControlId();
334 //// TODO: we should probably optimize by only creating a
335 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
336 //// But for now, let's simplify things by always creating the
337 //// drawing area, since otherwise the translations are different.
339 // New translations for getting mouse motion feedback
340 String translations
=
341 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
342 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
343 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
344 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
346 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
347 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
348 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
349 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
350 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
351 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
352 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
353 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
354 <Key>: DrawingAreaInput()";
356 XtActionsRec actions
[1];
357 actions
[0].string
= "wxCanvasMotionEvent";
358 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
359 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
361 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
362 if (style
& wxBORDER
)
363 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
364 xmFrameWidgetClass
, parentWidget
,
365 XmNshadowType
, XmSHADOW_IN
,
368 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
369 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
371 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
375 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
376 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
377 XmNunitType
, XmPIXELS
,
378 // XmNresizePolicy, XmRESIZE_ANY,
379 XmNresizePolicy
, XmRESIZE_NONE
,
382 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
385 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
387 XtFree ((char *) ptr);
388 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
389 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
390 XtFree ((char *) ptr);
394 wxAddWindowToTable((Widget
) m_drawingArea
, this);
395 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
398 * This order is very important in Motif 1.2.1
402 XtRealizeWidget ((Widget
) m_scrolledWindow
);
403 XtRealizeWidget ((Widget
) m_drawingArea
);
404 XtManageChild ((Widget
) m_drawingArea
);
406 XtOverrideTranslations ((Widget
) m_drawingArea
,
407 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
408 XtFree ((char *) ptr
);
410 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
411 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
414 display = XtDisplay (scrolledWindow);
415 xwindow = XtWindow (drawingArea);
418 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
419 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
421 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
426 void wxWindow::SetFocus()
428 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
429 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
432 void wxWindow::Enable(bool enable
)
436 XtSetSensitive((Widget
) GetMainWidget(), enable
);
437 XmUpdateDisplay((Widget
) GetMainWidget());
441 void wxWindow::CaptureMouse()
447 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
449 m_winCaptured
= TRUE
;
452 void wxWindow::ReleaseMouse()
458 XtRemoveGrab((Widget
) GetMainWidget());
459 m_winCaptured
= FALSE
;
462 // Push/pop event handler (i.e. allow a chain of event handlers
464 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
466 handler
->SetNextHandler(GetEventHandler());
467 SetEventHandler(handler
);
470 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
472 if ( GetEventHandler() )
474 wxEvtHandler
*handlerA
= GetEventHandler();
475 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
476 handlerA
->SetNextHandler(NULL
);
477 SetEventHandler(handlerB
);
490 #if wxUSE_DRAG_AND_DROP
492 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
494 if ( m_pDropTarget
!= 0 ) {
495 delete m_pDropTarget
;
498 m_pDropTarget
= pDropTarget
;
499 if ( m_pDropTarget
!= 0 )
507 // Old style file-manager drag&drop
508 void wxWindow::DragAcceptFiles(bool accept
)
514 void wxWindow::GetSize(int *x
, int *y
) const
522 Widget widget
= (Widget
) GetTopWidget();
524 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
528 void wxWindow::GetPosition(int *x
, int *y
) const
532 CanvasGetPosition(x
, y
);
535 Widget widget
= (Widget
) GetTopWidget();
537 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
541 void wxWindow::ScreenToClient(int *x
, int *y
) const
546 void wxWindow::ClientToScreen(int *x
, int *y
) const
548 Widget widget
= (Widget
) GetClientWidget();
549 Display
*display
= XtDisplay(widget
);
550 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
552 if (this->IsKindOf(CLASSINFO(wxFrame
)))
554 wxFrame
*fr
= (wxFrame
*)this;
556 // thisWindow = XtWindow(fr->m_clientArea);
559 thisWindow
= XtWindow((Widget
)widget
);
564 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
567 void wxWindow::SetCursor(const wxCursor
& cursor
)
569 m_windowCursor
= cursor
;
570 if (m_windowCursor
.Ok())
572 /* TODO when wxCursor implemented
573 WXDisplay *dpy = GetXDisplay();
574 Cursor x_cursor = cursor.GetXCursor(dpy);
576 Widget w = (Widget) GetMainWidget();
577 Window win = XtWindow(w);
578 XDefineCursor((Display*) dpy, win, x_cursor);
584 // Get size *available for subwindows* i.e. excluding menu bar etc.
585 void wxWindow::GetClientSize(int *x
, int *y
) const
587 Widget widget
= (Widget
) GetTopWidget();
589 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
593 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
597 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
600 Widget widget
= (Widget
) GetTopWidget();
604 bool managed
= XtIsManaged( widget
);
606 XtUnmanageChild(widget
);
608 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
609 XtVaSetValues(widget
, XmNx
, x
, NULL
);
610 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
611 XtVaSetValues(widget
, XmNy
, y
, NULL
);
613 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
615 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
618 XtManageChild(widget
);
620 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
621 sizeEvent
.SetEventObject(this);
623 GetEventHandler()->ProcessEvent(sizeEvent
);
626 void wxWindow::SetClientSize(int width
, int height
)
630 CanvasSetClientSize(width
, height
);
634 Widget widget
= (Widget
) GetTopWidget();
637 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
639 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
641 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
642 sizeEvent
.SetEventObject(this);
644 GetEventHandler()->ProcessEvent(sizeEvent
);
647 // For implementation purposes - sometimes decorations make the client area
649 wxPoint
wxWindow::GetClientAreaOrigin() const
651 return wxPoint(0, 0);
654 // Makes an adjustment to the window position (for example, a frame that has
655 // a toolbar that it manages itself).
656 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
658 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
660 wxPoint
pt(GetParent()->GetClientAreaOrigin());
661 x
+= pt
.x
; y
+= pt
.y
;
665 bool wxWindow::Show(bool show
)
669 if (m_borderWidget
|| m_scrolledWindow
)
671 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
675 XtMapWidget((Widget
) GetTopWidget());
680 if (m_borderWidget
|| m_scrolledWindow
)
682 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
686 XtUnmapWidget((Widget
) GetTopWidget());
691 Window xwin = (Window) GetXWindow();
692 Display *xdisp = (Display*) GetXDisplay();
694 XMapWindow(xdisp, xwin);
696 XUnmapWindow(xdisp, xwin);
704 bool wxWindow::IsShown() const
709 int wxWindow::GetCharHeight() const
715 int wxWindow::GetCharWidth() const
721 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
722 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
724 wxFont
*fontToUse
= (wxFont
*)theFont
;
726 fontToUse
= (wxFont
*) & m_windowFont
;
731 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
733 Display
*display
= XtDisplay((Widget
) GetMainWidget());
734 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
736 XExposeEvent dummyEvent
;
738 GetSize(&width
, &height
);
740 dummyEvent
.type
= Expose
;
741 dummyEvent
.display
= display
;
742 dummyEvent
.send_event
= True
;
743 dummyEvent
.window
= thisWindow
;
746 dummyEvent
.x
= rect
->x
;
747 dummyEvent
.y
= rect
->y
;
748 dummyEvent
.width
= rect
->width
;
749 dummyEvent
.height
= rect
->height
;
755 dummyEvent
.width
= width
;
756 dummyEvent
.height
= height
;
758 dummyEvent
.count
= 0;
763 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
764 dc
.SetBackground(backgroundBrush
);
768 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
771 // Responds to colour changes: passes event on to children.
772 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
774 wxNode
*node
= GetChildren()->First();
777 // Only propagate to non-top-level windows
778 wxWindow
*win
= (wxWindow
*)node
->Data();
779 if ( win
->GetParent() )
781 wxSysColourChangedEvent event2
;
782 event
.m_eventObject
= win
;
783 win
->GetEventHandler()->ProcessEvent(event2
);
790 // This can be called by the app (or wxWindows) to do default processing for the current
791 // event. Save message/event info in wxWindow so they can be used in this function.
792 long wxWindow::Default()
798 void wxWindow::InitDialog()
800 wxInitDialogEvent
event(GetId());
801 event
.SetEventObject( this );
802 GetEventHandler()->ProcessEvent(event
);
805 // Default init dialog behaviour is to transfer data to window
806 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
808 TransferDataToWindow();
811 // Caret manipulation
812 void wxWindow::CreateCaret(int w
, int h
)
816 m_caretEnabled
= TRUE
;
819 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
824 void wxWindow::ShowCaret(bool show
)
829 void wxWindow::DestroyCaret()
832 m_caretEnabled
= FALSE
;
835 void wxWindow::SetCaretPos(int x
, int y
)
840 void wxWindow::GetCaretPos(int *x
, int *y
) const
845 wxWindow
*wxGetActiveWindow()
851 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
858 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
861 wxFrame
*frame
= (wxFrame
*)this;
863 /* Uncomment when wxFrame implemented
865 XtVaSetValues((Widget) frame->m_frameShell, XmNminWidth, minW, NULL);
867 XtVaSetValues((Widget) frame->m_frameShell, XmNminHeight, minH, NULL);
869 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxWidth, maxW, NULL);
871 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxHeight, maxH, NULL);
873 XtVaSetValues((Widget) frame->m_frameShell, XmNwidthInc, incW, NULL);
875 XtVaSetValues((Widget) frame->m_frameShell, XmNheightInc, incH, NULL);
879 void wxWindow::Centre(int direction
)
881 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
883 wxWindow
*father
= (wxWindow
*)GetParent();
887 father
->GetClientSize(&panel_width
, &panel_height
);
888 GetSize(&width
, &height
);
894 if (direction
& wxHORIZONTAL
)
895 new_x
= (int)((panel_width
- width
)/2);
897 if (direction
& wxVERTICAL
)
898 new_y
= (int)((panel_height
- height
)/2);
900 SetSize(new_x
, new_y
, -1, -1);
904 // Coordinates relative to the window
905 void wxWindow::WarpPointer (int x
, int y
)
907 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
910 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
916 int wxWindow::GetScrollPos(int orient
) const
922 // This now returns the whole range, not just the number
923 // of positions that we can scroll.
924 int wxWindow::GetScrollRange(int orient
) const
930 int wxWindow::GetScrollThumb(int orient
) const
936 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
942 // New function that will replace some of the above.
943 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
944 int range
, bool refresh
)
949 // Does a physical scroll
950 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
956 void wxWindow::SetFont(const wxFont
& font
)
960 Widget w
= (Widget
) GetMainWidget();
961 if (w
&& m_windowFont
.Ok())
964 XmNfontList
, (XmFontList
) m_windowFont
.GetFontList(1.0, XtDisplay(w
)),
969 void wxWindow::OnChar(wxKeyEvent
& event
)
971 if ( event
.KeyCode() == WXK_TAB
) {
972 // propagate the TABs to the parent - it's up to it to decide what
975 if ( GetParent()->ProcessEvent(event
) )
981 void wxWindow::OnPaint(wxPaintEvent
& event
)
986 bool wxWindow::IsEnabled() const
992 // Dialog support: override these and call
993 // base class members to add functionality
994 // that can't be done using validators.
995 // NOTE: these functions assume that controls
996 // are direct children of this window, not grandchildren
997 // or other levels of descendant.
999 // Transfer values to controls. If returns FALSE,
1000 // it's an application error (pops up a dialog)
1001 bool wxWindow::TransferDataToWindow()
1003 wxNode
*node
= GetChildren()->First();
1006 wxWindow
*child
= (wxWindow
*)node
->Data();
1007 if ( child
->GetValidator() &&
1008 !child
->GetValidator()->TransferToWindow() )
1010 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1014 node
= node
->Next();
1019 // Transfer values from controls. If returns FALSE,
1020 // validation failed: don't quit
1021 bool wxWindow::TransferDataFromWindow()
1023 wxNode
*node
= GetChildren()->First();
1026 wxWindow
*child
= (wxWindow
*)node
->Data();
1027 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1032 node
= node
->Next();
1037 bool wxWindow::Validate()
1039 wxNode
*node
= GetChildren()->First();
1042 wxWindow
*child
= (wxWindow
*)node
->Data();
1043 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1048 node
= node
->Next();
1053 // Get the window with the focus
1054 wxWindow
*wxWindow::FindFocus()
1060 void wxWindow::AddChild(wxWindow
*child
)
1062 GetChildren()->Append(child
);
1063 child
->m_windowParent
= this;
1066 void wxWindow::RemoveChild(wxWindow
*child
)
1069 GetChildren()->DeleteObject(child
);
1070 child
->m_windowParent
= NULL
;
1073 void wxWindow::DestroyChildren()
1075 if (GetChildren()) {
1077 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1079 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1081 if ( GetChildren()->Member(child
) )
1088 void wxWindow::MakeModal(bool modal
)
1090 // Disable all other windows
1091 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1093 wxNode
*node
= wxTopLevelWindows
.First();
1096 wxWindow
*win
= (wxWindow
*)node
->Data();
1098 win
->Enable(!modal
);
1100 node
= node
->Next();
1105 // If nothing defined for this, try the parent.
1106 // E.g. we may be a button loaded from a resource, with no callback function
1108 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1110 if (GetEventHandler()->ProcessEvent(event
) )
1113 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1116 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1120 UnsetConstraints(m_constraints
);
1121 delete m_constraints
;
1126 // Make sure other windows know they're part of a 'meaningful relationship'
1127 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1128 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1129 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1130 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1131 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1132 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1133 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1134 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1135 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1136 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1137 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1138 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1139 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1140 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1141 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1142 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1146 // This removes any dangling pointers to this window
1147 // in other windows' constraintsInvolvedIn lists.
1148 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1152 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1153 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1154 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1155 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1156 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1157 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1158 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1159 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1160 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1161 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1162 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1163 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1164 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1165 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1166 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1167 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1171 // Back-pointer to other windows we're involved with, so if we delete
1172 // this window, we must delete any constraints we're involved with.
1173 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1175 if (!m_constraintsInvolvedIn
)
1176 m_constraintsInvolvedIn
= new wxList
;
1177 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1178 m_constraintsInvolvedIn
->Append(otherWin
);
1181 // REMOVE back-pointer to other windows we're involved with.
1182 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1184 if (m_constraintsInvolvedIn
)
1185 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1188 // Reset any constraints that mention this window
1189 void wxWindow::DeleteRelatedConstraints()
1191 if (m_constraintsInvolvedIn
)
1193 wxNode
*node
= m_constraintsInvolvedIn
->First();
1196 wxWindow
*win
= (wxWindow
*)node
->Data();
1197 wxNode
*next
= node
->Next();
1198 wxLayoutConstraints
*constr
= win
->GetConstraints();
1200 // Reset any constraints involving this window
1203 constr
->left
.ResetIfWin((wxWindow
*)this);
1204 constr
->top
.ResetIfWin((wxWindow
*)this);
1205 constr
->right
.ResetIfWin((wxWindow
*)this);
1206 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1207 constr
->width
.ResetIfWin((wxWindow
*)this);
1208 constr
->height
.ResetIfWin((wxWindow
*)this);
1209 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1210 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1215 delete m_constraintsInvolvedIn
;
1216 m_constraintsInvolvedIn
= NULL
;
1220 void wxWindow::SetSizer(wxSizer
*sizer
)
1222 m_windowSizer
= sizer
;
1224 sizer
->SetSizerParent((wxWindow
*)this);
1231 bool wxWindow::Layout()
1233 if (GetConstraints())
1236 GetClientSize(&w
, &h
);
1237 GetConstraints()->width
.SetValue(w
);
1238 GetConstraints()->height
.SetValue(h
);
1241 // If top level (one sizer), evaluate the sizer's constraints.
1245 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1246 GetSizer()->LayoutPhase1(&noChanges
);
1247 GetSizer()->LayoutPhase2(&noChanges
);
1248 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1253 // Otherwise, evaluate child constraints
1254 ResetConstraints(); // Mark all constraints as unevaluated
1255 DoPhase(1); // Just one phase need if no sizers involved
1257 SetConstraintSizes(); // Recursively set the real window sizes
1263 // Do a phase of evaluating constraints:
1264 // the default behaviour. wxSizers may do a similar
1265 // thing, but also impose their own 'constraints'
1266 // and order the evaluation differently.
1267 bool wxWindow::LayoutPhase1(int *noChanges
)
1269 wxLayoutConstraints
*constr
= GetConstraints();
1272 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1278 bool wxWindow::LayoutPhase2(int *noChanges
)
1288 // Do a phase of evaluating child constraints
1289 bool wxWindow::DoPhase(int phase
)
1291 int noIterations
= 0;
1292 int maxIterations
= 500;
1296 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1300 wxNode
*node
= GetChildren()->First();
1303 wxWindow
*child
= (wxWindow
*)node
->Data();
1304 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1306 wxLayoutConstraints
*constr
= child
->GetConstraints();
1309 if (succeeded
.Member(child
))
1314 int tempNoChanges
= 0;
1315 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1316 noChanges
+= tempNoChanges
;
1319 succeeded
.Append(child
);
1324 node
= node
->Next();
1331 void wxWindow::ResetConstraints()
1333 wxLayoutConstraints
*constr
= GetConstraints();
1336 constr
->left
.SetDone(FALSE
);
1337 constr
->top
.SetDone(FALSE
);
1338 constr
->right
.SetDone(FALSE
);
1339 constr
->bottom
.SetDone(FALSE
);
1340 constr
->width
.SetDone(FALSE
);
1341 constr
->height
.SetDone(FALSE
);
1342 constr
->centreX
.SetDone(FALSE
);
1343 constr
->centreY
.SetDone(FALSE
);
1345 wxNode
*node
= GetChildren()->First();
1348 wxWindow
*win
= (wxWindow
*)node
->Data();
1349 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1350 win
->ResetConstraints();
1351 node
= node
->Next();
1355 // Need to distinguish between setting the 'fake' size for
1356 // windows and sizers, and setting the real values.
1357 void wxWindow::SetConstraintSizes(bool recurse
)
1359 wxLayoutConstraints
*constr
= GetConstraints();
1360 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1361 constr
->width
.GetDone() && constr
->height
.GetDone())
1363 int x
= constr
->left
.GetValue();
1364 int y
= constr
->top
.GetValue();
1365 int w
= constr
->width
.GetValue();
1366 int h
= constr
->height
.GetValue();
1368 // If we don't want to resize this window, just move it...
1369 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1370 (constr
->height
.GetRelationship() != wxAsIs
))
1372 // Calls Layout() recursively. AAAGH. How can we stop that.
1373 // Simply take Layout() out of non-top level OnSizes.
1374 SizerSetSize(x
, y
, w
, h
);
1383 char *windowClass
= this->GetClassInfo()->GetClassName();
1386 if (GetName() == "")
1387 winName
= "unnamed";
1389 winName
= GetName();
1390 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1391 if (!constr
->left
.GetDone())
1392 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1393 if (!constr
->right
.GetDone())
1394 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1395 if (!constr
->width
.GetDone())
1396 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1397 if (!constr
->height
.GetDone())
1398 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1399 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1404 wxNode
*node
= GetChildren()->First();
1407 wxWindow
*win
= (wxWindow
*)node
->Data();
1408 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1409 win
->SetConstraintSizes();
1410 node
= node
->Next();
1415 // This assumes that all sizers are 'on' the same
1416 // window, i.e. the parent of this window.
1417 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1419 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1420 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1424 m_sizerParent
->GetPosition(&xp
, &yp
);
1425 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1430 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1434 TransformSizerToActual(&xx
, &yy
);
1435 SetSize(xx
, yy
, w
, h
);
1438 void wxWindow::SizerMove(int x
, int y
)
1442 TransformSizerToActual(&xx
, &yy
);
1446 // Only set the size/position of the constraint (if any)
1447 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1449 wxLayoutConstraints
*constr
= GetConstraints();
1454 constr
->left
.SetValue(x
);
1455 constr
->left
.SetDone(TRUE
);
1459 constr
->top
.SetValue(y
);
1460 constr
->top
.SetDone(TRUE
);
1464 constr
->width
.SetValue(w
);
1465 constr
->width
.SetDone(TRUE
);
1469 constr
->height
.SetValue(h
);
1470 constr
->height
.SetDone(TRUE
);
1475 void wxWindow::MoveConstraint(int x
, int y
)
1477 wxLayoutConstraints
*constr
= GetConstraints();
1482 constr
->left
.SetValue(x
);
1483 constr
->left
.SetDone(TRUE
);
1487 constr
->top
.SetValue(y
);
1488 constr
->top
.SetDone(TRUE
);
1493 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1495 wxLayoutConstraints
*constr
= GetConstraints();
1498 *w
= constr
->width
.GetValue();
1499 *h
= constr
->height
.GetValue();
1505 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1507 wxLayoutConstraints
*constr
= GetConstraints();
1510 *w
= constr
->width
.GetValue();
1511 *h
= constr
->height
.GetValue();
1514 GetClientSize(w
, h
);
1517 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1519 wxLayoutConstraints
*constr
= GetConstraints();
1522 *x
= constr
->left
.GetValue();
1523 *y
= constr
->top
.GetValue();
1529 bool wxWindow::Close(bool force
)
1531 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1532 event
.SetEventObject(this);
1533 event
.SetForce(force
);
1535 return GetEventHandler()->ProcessEvent(event
);
1538 wxObject
* wxWindow::GetChild(int number
) const
1540 // Return a pointer to the Nth object in the window
1543 wxNode
*node
= GetChildren()->First();
1546 node
= node
->Next() ;
1549 wxObject
*obj
= (wxObject
*)node
->Data();
1556 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1558 // Obsolete function
1561 void wxWindow::Clear()
1563 wxClientDC
dc(this);
1564 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1565 dc
.SetBackground(brush
);
1569 // Fits the panel around the items
1570 void wxWindow::Fit()
1574 wxNode
*node
= GetChildren()->First();
1577 wxWindow
*win
= (wxWindow
*)node
->Data();
1579 win
->GetPosition(&wx
, &wy
);
1580 win
->GetSize(&ww
, &wh
);
1581 if ( wx
+ ww
> maxX
)
1583 if ( wy
+ wh
> maxY
)
1586 node
= node
->Next();
1588 SetClientSize(maxX
+ 5, maxY
+ 5);
1591 void wxWindow::SetValidator(const wxValidator
& validator
)
1593 if ( m_windowValidator
)
1594 delete m_windowValidator
;
1595 m_windowValidator
= validator
.Clone();
1597 if ( m_windowValidator
)
1598 m_windowValidator
->SetWindow(this) ;
1601 // Find a window by id or name
1602 wxWindow
*wxWindow::FindWindow(long id
)
1607 wxNode
*node
= GetChildren()->First();
1610 wxWindow
*child
= (wxWindow
*)node
->Data();
1611 wxWindow
*found
= child
->FindWindow(id
);
1614 node
= node
->Next();
1619 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1621 if ( GetName() == name
)
1624 wxNode
*node
= GetChildren()->First();
1627 wxWindow
*child
= (wxWindow
*)node
->Data();
1628 wxWindow
*found
= child
->FindWindow(name
);
1631 node
= node
->Next();
1636 void wxWindow::OnIdle(wxIdleEvent
& event
)
1638 /* TODO: you may need to do something like this
1639 * if your GUI doesn't generate enter/leave events
1641 // Check if we need to send a LEAVE event
1642 if (m_mouseInWindow)
1645 ::GetCursorPos(&pt);
1646 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1648 // Generate a LEAVE event
1649 m_mouseInWindow = FALSE;
1650 MSWOnMouseLeave(pt.x, pt.y, 0);
1655 // This calls the UI-update mechanism (querying windows for
1656 // menu/toolbar/control state information)
1660 // Raise the window to the top of the Z order
1661 void wxWindow::Raise()
1663 Window window
= XtWindow((Widget
) GetTopWidget());
1664 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1667 // Lower the window to the bottom of the Z order
1668 void wxWindow::Lower()
1670 Window window
= XtWindow((Widget
) GetTopWidget());
1671 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1674 bool wxWindow::AcceptsFocus() const
1676 return IsShown() && IsEnabled();
1679 // Update region access
1680 wxRegion
wxWindow::GetUpdateRegion() const
1682 return m_updateRegion
;
1685 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1687 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1690 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1692 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1695 bool wxWindow::IsExposed(const wxRect
& rect
) const
1697 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1701 * Allocates control IDs
1704 int wxWindow::NewControlId()
1706 static int s_controlId
= 0;
1711 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1713 m_acceleratorTable
= accel
;
1716 // All widgets should have this as their resize proc.
1717 // OnSize sent to wxWindow via client data.
1718 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1720 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
1724 if (win
->PreResize())
1727 win
->GetSize(&width
, &height
);
1728 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1729 sizeEvent
.SetEventObject(win
);
1730 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1734 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1736 wxWindow
*oldItem
= NULL
;
1738 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
1740 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1743 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
1746 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
1751 wxWidgetHashTable
->Put ((long) w
, win
);
1755 wxWindow
*wxGetWindowFromTable(Widget w
)
1757 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
1760 void wxDeleteWindowFromTable(Widget w
)
1762 wxWidgetHashTable
->Delete((long)w
);
1765 // Get the underlying X window and display
1766 WXWindow
wxWindow::GetXWindow() const
1768 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
1771 WXDisplay
*wxWindow::GetXDisplay() const
1773 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
1776 WXWidget
wxWindow::GetMainWidget() const
1779 return m_drawingArea
;
1781 return m_mainWidget
;
1784 WXWidget
wxWindow::GetClientWidget() const
1786 if (m_drawingArea
!= (WXWidget
) 0)
1787 return m_drawingArea
;
1789 return GetMainWidget();
1792 WXWidget
wxWindow::GetTopWidget() const
1794 return GetMainWidget();
1797 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
1798 XmDrawingAreaCallbackStruct
* cbs
)
1800 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
1803 XEvent
* event
= cbs
->event
;
1804 wxWindow
* canvas
= (wxWindow
*) clientData
;
1805 Display
* display
= (Display
*) canvas
->GetXDisplay();
1806 // GC gc = (GC) canvas->GetDC()->gc;
1808 switch (event
->type
)
1813 wxCanvasDC* canvasDC = canvas->GetDC();
1816 if (canvasDC->onpaint_reg)
1817 XDestroyRegion(canvasDC->onpaint_reg);
1818 canvasDC->onpaint_reg = XCreateRegion();
1823 int n
= canvas
->m_updateRects
.Number();
1824 XRectangle
* xrects
= new XRectangle
[n
];
1826 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
1828 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
1829 xrects
[i
].x
= rect
->x
;
1830 xrects
[i
].y
= rect
->y
;
1831 xrects
[i
].width
= rect
->width
;
1832 xrects
[i
].height
= rect
->height
;
1833 /* TODO (?) Actually ignore it I think.
1835 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
1836 canvasDC->onpaint_reg);
1839 /* TODO must clip the area being repainted. So we need a gc.
1840 * Alternatively, wxPaintDC must do the clipping
1841 * when it's created.
1842 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
1845 canvas
->DoPaint() ; // xrects, n);
1848 canvas
->m_updateRects
.Clear();
1853 XDestroyRegion(canvasDC->onpaint_reg);
1854 canvasDC->onpaint_reg = NULL;
1858 gc_val.clip_mask = None;
1859 XChangeGC(display, gc, GCClipMask, &gc_val);
1866 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
1872 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1874 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
1876 XmDrawingAreaCallbackStruct cbs
;
1879 //if (event->mode!=NotifyNormal)
1882 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
1883 ((XCrossingEvent
&) ev
) = *event
;
1885 cbs
.reason
= XmCR_INPUT
;
1888 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1891 // Fix to make it work under Motif 1.0 (!)
1892 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1896 XmDrawingAreaCallbackStruct cbs
;
1899 //ev.xbutton = *event;
1900 ev
= *((XEvent
*) event
);
1901 cbs
.reason
= XmCR_INPUT
;
1904 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1908 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
1910 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
1916 if (cbs
->reason
!= XmCR_INPUT
)
1919 local_event
= *(cbs
->event
); // We must keep a copy!
1921 switch (local_event
.xany
.type
)
1929 wxEventType eventType
= wxEVT_NULL
;
1931 if (local_event
.xany
.type
== EnterNotify
)
1933 //if (local_event.xcrossing.mode!=NotifyNormal)
1934 // return ; // Ignore grab events
1935 eventType
= wxEVT_ENTER_WINDOW
;
1936 // canvas->GetEventHandler()->OnSetFocus();
1938 else if (local_event
.xany
.type
== LeaveNotify
)
1940 //if (local_event.xcrossing.mode!=NotifyNormal)
1941 // return ; // Ignore grab events
1942 eventType
= wxEVT_LEAVE_WINDOW
;
1943 // canvas->GetEventHandler()->OnKillFocus();
1945 else if (local_event
.xany
.type
== MotionNotify
)
1947 eventType
= wxEVT_MOTION
;
1948 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1951 Display
*dpy
= XtDisplay (drawingArea
);
1953 XQueryPointer (dpy
, XtWindow (drawingArea
),
1955 &local_event
.xmotion
.x_root
,
1956 &local_event
.xmotion
.y_root
,
1957 &local_event
.xmotion
.x
,
1958 &local_event
.xmotion
.y
,
1959 &local_event
.xmotion
.state
);
1966 else if (local_event
.xany
.type
== ButtonPress
)
1968 if (local_event
.xbutton
.button
== Button1
)
1970 eventType
= wxEVT_LEFT_DOWN
;
1971 canvas
->m_button1Pressed
= TRUE
;
1973 else if (local_event
.xbutton
.button
== Button2
)
1975 eventType
= wxEVT_MIDDLE_DOWN
;
1976 canvas
->m_button2Pressed
= TRUE
;
1978 else if (local_event
.xbutton
.button
== Button3
)
1980 eventType
= wxEVT_RIGHT_DOWN
;
1981 canvas
->m_button3Pressed
= TRUE
;
1984 else if (local_event
.xany
.type
== ButtonRelease
)
1986 if (local_event
.xbutton
.button
== Button1
)
1988 eventType
= wxEVT_LEFT_UP
;
1989 canvas
->m_button1Pressed
= FALSE
;
1991 else if (local_event
.xbutton
.button
== Button2
)
1993 eventType
= wxEVT_MIDDLE_UP
;
1994 canvas
->m_button2Pressed
= FALSE
;
1996 else if (local_event
.xbutton
.button
== Button3
)
1998 eventType
= wxEVT_RIGHT_UP
;
1999 canvas
->m_button3Pressed
= FALSE
;
2003 wxMouseEvent
wxevent (eventType
);
2004 wxevent
.m_eventHandle
= (char *) &local_event
;
2006 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2007 || (event_left_is_down (&local_event
)
2008 && (eventType
!= wxEVT_LEFT_UP
)));
2009 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2010 || (event_middle_is_down (&local_event
)
2011 && (eventType
!= wxEVT_MIDDLE_UP
)));
2012 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2013 || (event_right_is_down (&local_event
)
2014 && (eventType
!= wxEVT_RIGHT_UP
)));
2016 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2017 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2018 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2019 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2020 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2022 // Now check if we need to translate this event into a double click
2023 if (TRUE
) // canvas->doubleClickAllowed)
2025 if (wxevent
.ButtonDown())
2027 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2029 // get button and time-stamp
2031 if (wxevent
.LeftDown()) button
= 1;
2032 else if (wxevent
.MiddleDown()) button
= 2;
2033 else if (wxevent
.RightDown()) button
= 3;
2034 long ts
= wxevent
.GetTimestamp();
2035 // check, if single or double click
2036 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2039 canvas
->m_lastButton
= 0;
2040 switch ( eventType
)
2042 case wxEVT_LEFT_DOWN
:
2043 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2045 case wxEVT_MIDDLE_DOWN
:
2046 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2048 case wxEVT_RIGHT_DOWN
:
2049 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2059 // not fast enough or different button
2060 canvas
->m_lastTS
= ts
;
2061 canvas
->m_lastButton
= button
;
2066 wxevent
.SetId(canvas
->GetId());
2067 wxevent
.SetEventObject(canvas
);
2068 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2070 if (eventType == wxEVT_ENTER_WINDOW ||
2071 eventType == wxEVT_LEAVE_WINDOW ||
2072 eventType == wxEVT_MOTION
2081 // XComposeStatus compose;
2082 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2083 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2084 int id
= wxCharCodeXToWX (keySym
);
2086 wxKeyEvent
event (wxEVT_CHAR
);
2088 if (local_event
.xkey
.state
& ShiftMask
)
2089 event
.m_shiftDown
= TRUE
;
2090 if (local_event
.xkey
.state
& ControlMask
)
2091 event
.m_controlDown
= TRUE
;
2092 if (local_event
.xkey
.state
& Mod3Mask
)
2093 event
.m_altDown
= TRUE
;
2094 if (local_event
.xkey
.state
& Mod1Mask
)
2095 event
.m_metaDown
= TRUE
;
2096 event
.SetEventObject(canvas
);
2097 event
.m_keyCode
= id
;
2098 event
.SetTimestamp(local_event
.xkey
.time
);
2102 // Implement wxFrame::OnCharHook by checking ancestor.
2103 wxWindow
*parent
= canvas
->GetParent();
2104 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2105 parent
= parent
->GetParent();
2109 event
.SetEventType(wxEVT_CHAR_HOOK
);
2110 if (parent
->GetEventHandler()->ProcessEvent(event
))
2112 event
.SetEventType(wxEVT_CHAR
);
2115 canvas
->GetEventHandler()->ProcessEvent (event
);
2121 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2123 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2124 event
.SetEventObject(canvas
);
2125 canvas
->GetEventHandler()->ProcessEvent(event
);
2131 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2133 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2134 event
.SetEventObject(canvas
);
2135 canvas
->GetEventHandler()->ProcessEvent(event
);
2144 void wxWindow::DoPaint()
2146 //TODO : make a temporary gc so we can do the XCopyArea below
2147 if (0) // m_backingPixmap)
2150 Widget drawingArea = (Widget) m_drawingArea;
2151 // int orig = GetDC()->GetLogicalFunction();
2152 // GetDC()->SetLogicalFunction (wxCOPY);
2154 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2155 // should be able to calculate them.
2156 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2157 m_pixmapOffsetX, m_pixmapOffsetY,
2158 m_pixmapWidth, m_pixmapHeight,
2161 // GetDC()->SetLogicalFunction (orig);
2166 wxPaintEvent
event(GetId());
2167 event
.SetEventObject(this);
2168 GetEventHandler()->ProcessEvent(event
);
2172 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2173 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2175 Widget drawingArea
= (Widget
) m_drawingArea
;
2176 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2179 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2180 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2182 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2184 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2188 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2190 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2198 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2199 short thick
, margin
;
2200 XtVaGetValues ((Widget
) m_borderWidget
,
2201 XmNshadowThickness
, &thick
,
2202 XmNmarginWidth
, &margin
,
2204 w
-= 2 * (thick
+ margin
);
2207 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2211 XtVaGetValues ((Widget
) m_scrolledWindow
,
2212 XmNspacing
, &spacing
,
2213 XmNverticalScrollBar
, &sbar
,
2217 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2221 w
-= (spacing
+ wsbar
);
2223 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2229 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2230 short thick
, margin
;
2231 XtVaGetValues ((Widget
) m_borderWidget
,
2232 XmNshadowThickness
, &thick
,
2233 XmNmarginHeight
, &margin
,
2235 h
-= 2 * (thick
+ margin
);
2238 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2242 XtVaGetValues ((Widget
) m_scrolledWindow
,
2243 XmNspacing
, &spacing
,
2244 XmNhorizontalScrollBar
, &sbar
,
2248 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2252 h
-= (spacing
+ wsbar
);
2254 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2257 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2258 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2261 GetClientSize (&ww
, &hh
);
2262 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2263 sizeEvent
.SetEventObject(this);
2265 GetEventHandler()->ProcessEvent(sizeEvent
);
2268 void wxWindow::CanvasSetClientSize (int w
, int h
)
2270 Widget drawingArea
= (Widget
) m_drawingArea
;
2272 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2275 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2277 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2278 /* TODO: is this necessary?
2279 allowRepainting = FALSE;
2281 XSync (XtDisplay (drawingArea), FALSE);
2283 while (XtAppPending (wxTheApp->appContext))
2285 XFlush (XtDisplay (drawingArea));
2286 XtAppNextEvent (wxTheApp->appContext, &event);
2287 XtDispatchEvent (&event);
2291 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2294 allowRepainting = TRUE;
2298 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2299 sizeEvent
.SetEventObject(this);
2301 GetEventHandler()->ProcessEvent(sizeEvent
);
2304 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2306 // Must return the same thing that was set via SetClientSize
2308 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2313 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2316 if ((Widget
) m_borderWidget
)
2317 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2318 else if ((Widget
) m_scrolledWindow
)
2319 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2321 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2327 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2330 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2335 // Add to hash table, add event handler
2336 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2337 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2339 wxAddWindowToTable((Widget
) mainWidget
, this);
2340 if (CanAddEventHandler())
2342 XtAddEventHandler((Widget
) mainWidget
,
2343 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2345 wxPanelItemEventHandler
,
2352 XtOverrideTranslations ((Widget
) mainWidget
,
2353 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2354 XtFree ((char *) ptr
);
2357 // Some widgets have a parent form widget, e.g. wxRadioBox
2360 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2364 XtOverrideTranslations ((Widget
) formWidget
,
2365 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2366 XtFree ((char *) ptr
);
2373 SetSize (x
, y
, width
, height
);
2378 // Remove event handler, remove from hash table
2379 bool wxWindow::DetachWidget(WXWidget widget
)
2381 if (CanAddEventHandler())
2383 XtRemoveEventHandler((Widget
) widget
,
2384 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2386 wxPanelItemEventHandler
,
2390 wxDeleteWindowFromTable((Widget
) widget
);
2394 void wxPanelItemEventHandler (Widget wid
,
2395 XtPointer client_data
,
2397 Boolean
*continueToDispatch
)
2399 // Widget can be a label or the actual widget.
2401 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2404 wxMouseEvent
wxevent(0);
2405 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2407 window
->GetEventHandler()->ProcessEvent(wxevent
);
2410 // TODO: probably the key to allowing default behaviour
2412 // Say we set a m_doDefault flag to FALSE at the start of this
2413 // function. Then in e.g. wxWindow::OnMouseEvent we can
2414 // call Default() which sets this flag to TRUE, indicating
2415 // that default processing can happen. Thus, behaviour can appear
2416 // to be overridden just by adding an event handler and not calling
2417 // wxWindow::OnWhatever.
2418 // ALSO, maybe we can use this instead of the current way of handling
2419 // drawing area events, to simplify things.
2420 *continueToDispatch
= True
;
2423 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2425 switch (xevent
->xany
.type
)
2433 wxEventType eventType
= wxEVT_NULL
;
2435 if (xevent
->xany
.type
== LeaveNotify
)
2437 win
->m_button1Pressed
= FALSE
;
2438 win
->m_button2Pressed
= FALSE
;
2439 win
->m_button3Pressed
= FALSE
;
2442 else if (xevent
->xany
.type
== MotionNotify
)
2444 eventType
= wxEVT_MOTION
;
2446 else if (xevent
->xany
.type
== ButtonPress
)
2448 if (xevent
->xbutton
.button
== Button1
)
2450 eventType
= wxEVT_LEFT_DOWN
;
2451 win
->m_button1Pressed
= TRUE
;
2453 else if (xevent
->xbutton
.button
== Button2
)
2455 eventType
= wxEVT_MIDDLE_DOWN
;
2456 win
->m_button2Pressed
= TRUE
;
2458 else if (xevent
->xbutton
.button
== Button3
)
2460 eventType
= wxEVT_RIGHT_DOWN
;
2461 win
->m_button3Pressed
= TRUE
;
2464 else if (xevent
->xany
.type
== ButtonRelease
)
2466 if (xevent
->xbutton
.button
== Button1
)
2468 eventType
= wxEVT_LEFT_UP
;
2469 win
->m_button1Pressed
= FALSE
;
2471 else if (xevent
->xbutton
.button
== Button2
)
2473 eventType
= wxEVT_MIDDLE_UP
;
2474 win
->m_button2Pressed
= FALSE
;
2476 else if (xevent
->xbutton
.button
== Button3
)
2478 eventType
= wxEVT_RIGHT_UP
;
2479 win
->m_button3Pressed
= FALSE
;
2485 wxevent
.m_eventHandle
= (char *)xevent
;
2486 wxevent
.SetEventType(eventType
);
2489 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2492 win
->GetPosition(&x2
, &y2
);
2494 // The button x/y must be translated to wxWindows
2495 // window space - the widget might be a label or button,
2499 if (widget
!= (Widget
)win
->GetMainWidget())
2505 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2506 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2508 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2509 || (event_left_is_down (xevent
)
2510 && (eventType
!= wxEVT_LEFT_UP
)));
2511 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2512 || (event_middle_is_down (xevent
)
2513 && (eventType
!= wxEVT_MIDDLE_UP
)));
2514 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2515 || (event_right_is_down (xevent
)
2516 && (eventType
!= wxEVT_RIGHT_UP
)));
2518 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2519 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2526 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2528 switch (xevent
->xany
.type
)
2535 // XComposeStatus compose;
2536 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2537 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2538 int id
= wxCharCodeXToWX (keySym
);
2540 if (xevent
->xkey
.state
& ShiftMask
)
2541 wxevent
.m_shiftDown
= TRUE
;
2542 if (xevent
->xkey
.state
& ControlMask
)
2543 wxevent
.m_controlDown
= TRUE
;
2544 if (xevent
->xkey
.state
& Mod3Mask
)
2545 wxevent
.m_altDown
= TRUE
;
2546 if (xevent
->xkey
.state
& Mod1Mask
)
2547 wxevent
.m_metaDown
= TRUE
;
2548 wxevent
.SetEventObject(win
);
2549 wxevent
.m_keyCode
= id
;
2550 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2552 wxevent
.m_x
= xevent
->xbutton
.x
;
2553 wxevent
.m_y
= xevent
->xbutton
.y
;
2567 // TODO From wxWin 1.68. What does it do exactly?
2568 #define YAllocColor XAllocColor
2570 XColor itemColors
[5];
2571 int wxComputeColors (Display
*display
, wxColour
* back
, wxColour
* fore
)
2574 static XmColorProc colorProc
;
2576 result
= wxNO_COLORS
;
2580 itemColors
[0].red
= (((long) back
->Red ()) << 8);
2581 itemColors
[0].green
= (((long) back
->Green ()) << 8);
2582 itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2583 itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2584 if (colorProc
== (XmColorProc
) NULL
)
2586 // Get a ptr to the actual function
2587 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2588 // And set it back to motif.
2589 XmSetColorCalculation (colorProc
);
2591 (*colorProc
) (&itemColors
[wxBACK_INDEX
],
2592 &itemColors
[wxFORE_INDEX
],
2593 &itemColors
[wxSELE_INDEX
],
2594 &itemColors
[wxTOPS_INDEX
],
2595 &itemColors
[wxBOTS_INDEX
]);
2596 result
= wxBACK_COLORS
;
2600 itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2601 itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2602 itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2603 itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2604 if (result
== wxNO_COLORS
)
2605 result
= wxFORE_COLORS
;
2608 Display
*dpy
= display
;
2609 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2613 /* 5 Colours to allocate */
2614 for (int i
= 0; i
< 5; i
++)
2615 if (!YAllocColor (dpy
, cmap
, &itemColors
[i
]))
2616 result
= wxNO_COLORS
;
2620 /* Only 1 colour to allocate */
2621 if (!YAllocColor (dpy
, cmap
, &itemColors
[wxFORE_INDEX
]))
2622 result
= wxNO_COLORS
;
2629 void wxWindow::ChangeColour(WXWidget widget
)
2635 // TODO: how to determine whether we can change this item's colours?
2636 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
2638 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
2641 change
= wxComputeColors (XtDisplay((Widget
)widget
), panel
->GetBackgroundColour(),
2642 panel
->GetLabelColour());
2643 if (change
== wxBACK_COLORS
)
2644 XtVaSetValues ((Widget
) widget
,
2645 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2646 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2647 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2648 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2650 else if (change
== wxFORE_COLORS
)
2651 XtVaSetValues (formWidget
,
2652 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2655 change
= wxComputeColors (XtDisplay((Widget
)formWidget
), GetBackgroundColour(), GetLabelColour());
2656 if (change
== wxBACK_COLORS
)
2657 XtVaSetValues (labelWidget
,
2658 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2659 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2660 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2661 XmNarmColor
, itemColors
[wxSELE_INDEX
].pixel
,
2662 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2664 else if (change
== wxFORE_COLORS
)
2665 XtVaSetValues (labelWidget
,
2666 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2671 void wxWindow::ChangeFont(WXWidget widget
)
2674 if (widget && GetFont() && GetFont()->IsOk())
2675 XtVaSetValues ((Widget) widget,
2676 XmNfontList, GetFont()->GetInternalFont (),