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"
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_foregroundColour
= *wxBLACK
;
104 m_defaultForegroundColour
= *wxBLACK
;
105 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
107 #if USE_DRAG_AND_DROP
108 m_pDropTarget
= NULL
;
112 m_mainWidget
= (WXWidget
) 0;
113 m_button1Pressed
= FALSE
;
114 m_button2Pressed
= FALSE
;
115 m_button3Pressed
= FALSE
;
116 m_winCaptured
= FALSE
;
118 m_hScrollBar
= (WXWidget
) 0;
119 m_vScrollBar
= (WXWidget
) 0;
120 m_borderWidget
= (WXWidget
) 0;
121 m_scrolledWindow
= (WXWidget
) 0;
122 m_drawingArea
= (WXWidget
) 0;
125 m_hScrollingEnabled
= FALSE
;
126 m_vScrollingEnabled
= FALSE
;
127 m_backingPixmap
= (WXPixmap
) 0;
134 m_canAddEventHandler
= FALSE
;
135 m_paintRegion
= (WXRegion
) 0;
139 wxWindow::~wxWindow()
144 XDestroyRegion ((Region
) m_paintRegion
);
145 m_paintRegion
= (WXRegion
) 0;
148 DetachWidget(GetMainWidget()); // Removes event handlers
150 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
153 // Destroy children before destroying self
157 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
159 Widget w
= (Widget
) m_drawingArea
;
160 wxDeleteWindowFromTable(w
);
164 m_mainWidget
= (WXWidget
) 0;
166 // Only if we're _really_ a canvas (not a dialog box/panel)
167 if (m_scrolledWindow
)
169 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
174 XtUnmanageChild ((Widget
) m_hScrollBar
);
175 XtDestroyWidget ((Widget
) m_hScrollBar
);
179 XtUnmanageChild ((Widget
) m_vScrollBar
);
180 XtDestroyWidget ((Widget
) m_vScrollBar
);
182 if (m_scrolledWindow
)
184 XtUnmanageChild ((Widget
) m_scrolledWindow
);
185 XtDestroyWidget ((Widget
) m_scrolledWindow
);
190 XtDestroyWidget ((Widget
) m_borderWidget
);
191 m_borderWidget
= (WXWidget
) 0;
197 // Have to delete constraints/sizer FIRST otherwise
198 // sizers may try to look at deleted windows as they
199 // delete themselves.
201 DeleteRelatedConstraints();
204 // This removes any dangling pointers to this window
205 // in other windows' constraintsInvolvedIn lists.
206 UnsetConstraints(m_constraints
);
207 delete m_constraints
;
208 m_constraints
= NULL
;
212 delete m_windowSizer
;
213 m_windowSizer
= NULL
;
215 // If this is a child of a sizer, remove self from parent
217 m_sizerParent
->RemoveChild((wxWindow
*)this);
221 m_windowParent
->RemoveChild(this);
225 // Destroy the window
228 wxDeleteWindowFromTable((Widget
) GetMainWidget());
229 XtDestroyWidget((Widget
) GetMainWidget());
230 SetMainWidget((WXWidget
) NULL
);
236 // Just in case the window has been Closed, but
237 // we're then deleting immediately: don't leave
238 // dangling pointers.
239 wxPendingDelete
.DeleteObject(this);
241 if ( m_windowValidator
)
242 delete m_windowValidator
;
245 // Destroy the window (delayed, if a managed window)
246 bool wxWindow::Destroy()
253 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
257 const wxString
& name
)
262 m_windowParent
= NULL
;
263 m_windowEventHandler
= this;
265 m_windowCursor
= *wxSTANDARD_CURSOR
;
266 m_constraints
= NULL
;
267 m_constraintsInvolvedIn
= NULL
;
268 m_windowSizer
= NULL
;
269 m_sizerParent
= NULL
;
270 m_autoLayout
= FALSE
;
271 m_windowValidator
= NULL
;
272 #if USE_DRAG_AND_DROP
273 m_pDropTarget
= NULL
;
275 m_caretWidth
= 0; m_caretHeight
= 0;
276 m_caretEnabled
= FALSE
;
277 m_caretShown
= FALSE
;
282 m_defaultItem
= NULL
;
283 m_windowParent
= NULL
;
286 m_canAddEventHandler
= FALSE
;
287 m_mainWidget
= (WXWidget
) 0;
288 m_button1Pressed
= FALSE
;
289 m_button2Pressed
= FALSE
;
290 m_button3Pressed
= FALSE
;
291 m_winCaptured
= FALSE
;
293 m_hScrollBar
= (WXWidget
) 0;
294 m_vScrollBar
= (WXWidget
) 0;
295 m_borderWidget
= (WXWidget
) 0;
296 m_scrolledWindow
= (WXWidget
) 0;
297 m_drawingArea
= (WXWidget
) 0;
300 m_hScrollingEnabled
= FALSE
;
301 m_vScrollingEnabled
= FALSE
;
302 m_backingPixmap
= (WXPixmap
) 0;
307 m_paintRegion
= (WXRegion
) 0;
312 if (parent
) parent
->AddChild(this);
319 m_windowId
= (int)NewControlId();
323 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
324 m_foregroundColour
= *wxBLACK
;
325 m_defaultForegroundColour
= *wxBLACK
;
326 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
328 m_windowStyle
= style
;
331 m_windowId
= (int)NewControlId();
335 //// TODO: we should probably optimize by only creating a
336 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
337 //// But for now, let's simplify things by always creating the
338 //// drawing area, since otherwise the translations are different.
340 // New translations for getting mouse motion feedback
341 String translations
=
342 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
343 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
344 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
345 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
346 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
347 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
348 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
349 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
350 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
351 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
352 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
353 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
354 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
355 <Key>: DrawingAreaInput()";
357 XtActionsRec actions
[1];
358 actions
[0].string
= "wxCanvasMotionEvent";
359 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
360 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
362 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
363 if (style
& wxBORDER
)
364 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
365 xmFrameWidgetClass
, parentWidget
,
366 XmNshadowType
, XmSHADOW_IN
,
369 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
370 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
372 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
376 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
377 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
378 XmNunitType
, XmPIXELS
,
379 // XmNresizePolicy, XmRESIZE_ANY,
380 XmNresizePolicy
, XmRESIZE_NONE
,
383 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
386 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
388 XtFree ((char *) ptr);
389 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
390 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
391 XtFree ((char *) ptr);
395 wxAddWindowToTable((Widget
) m_drawingArea
, this);
396 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
399 * This order is very important in Motif 1.2.1
403 XtRealizeWidget ((Widget
) m_scrolledWindow
);
404 XtRealizeWidget ((Widget
) m_drawingArea
);
405 XtManageChild ((Widget
) m_drawingArea
);
407 XtOverrideTranslations ((Widget
) m_drawingArea
,
408 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
409 XtFree ((char *) ptr
);
411 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
412 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
415 display = XtDisplay (scrolledWindow);
416 xwindow = XtWindow (drawingArea);
419 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
420 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
422 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
427 void wxWindow::SetFocus()
429 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
430 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
433 void wxWindow::Enable(bool enable
)
437 XtSetSensitive((Widget
) GetMainWidget(), enable
);
438 XmUpdateDisplay((Widget
) GetMainWidget());
442 void wxWindow::CaptureMouse()
448 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
450 m_winCaptured
= TRUE
;
453 void wxWindow::ReleaseMouse()
459 XtRemoveGrab((Widget
) GetMainWidget());
460 m_winCaptured
= FALSE
;
463 // Push/pop event handler (i.e. allow a chain of event handlers
465 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
467 handler
->SetNextHandler(GetEventHandler());
468 SetEventHandler(handler
);
471 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
473 if ( GetEventHandler() )
475 wxEvtHandler
*handlerA
= GetEventHandler();
476 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
477 handlerA
->SetNextHandler(NULL
);
478 SetEventHandler(handlerB
);
491 #if USE_DRAG_AND_DROP
493 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
495 if ( m_pDropTarget
!= 0 ) {
496 delete m_pDropTarget
;
499 m_pDropTarget
= pDropTarget
;
500 if ( m_pDropTarget
!= 0 )
508 // Old style file-manager drag&drop
509 void wxWindow::DragAcceptFiles(bool accept
)
515 void wxWindow::GetSize(int *x
, int *y
) const
523 Widget widget
= (Widget
) GetTopWidget();
525 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
529 void wxWindow::GetPosition(int *x
, int *y
) const
533 CanvasGetPosition(x
, y
);
536 Widget widget
= (Widget
) GetTopWidget();
538 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
542 void wxWindow::ScreenToClient(int *x
, int *y
) const
547 void wxWindow::ClientToScreen(int *x
, int *y
) const
549 Widget widget
= (Widget
) GetClientWidget();
550 Display
*display
= XtDisplay(widget
);
551 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
553 if (this->IsKindOf(CLASSINFO(wxFrame
)))
555 wxFrame
*fr
= (wxFrame
*)this;
557 // thisWindow = XtWindow(fr->m_clientArea);
560 thisWindow
= XtWindow((Widget
)widget
);
565 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
568 void wxWindow::SetCursor(const wxCursor
& cursor
)
570 m_windowCursor
= cursor
;
571 if (m_windowCursor
.Ok())
573 /* TODO when wxCursor implemented
574 WXDisplay *dpy = GetXDisplay();
575 Cursor x_cursor = cursor.GetXCursor(dpy);
577 Widget w = (Widget) GetMainWidget();
578 Window win = XtWindow(w);
579 XDefineCursor((Display*) dpy, win, x_cursor);
585 // Get size *available for subwindows* i.e. excluding menu bar etc.
586 void wxWindow::GetClientSize(int *x
, int *y
) const
588 Widget widget
= (Widget
) GetTopWidget();
590 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
594 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
598 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
601 Widget widget
= (Widget
) GetTopWidget();
605 bool managed
= XtIsManaged( widget
);
607 XtUnmanageChild(widget
);
609 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
610 XtVaSetValues(widget
, XmNx
, x
, NULL
);
611 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
612 XtVaSetValues(widget
, XmNy
, y
, NULL
);
614 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
616 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
619 XtManageChild(widget
);
621 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
622 sizeEvent
.SetEventObject(this);
624 GetEventHandler()->ProcessEvent(sizeEvent
);
627 void wxWindow::SetClientSize(int width
, int height
)
631 CanvasSetClientSize(width
, height
);
635 Widget widget
= (Widget
) GetTopWidget();
638 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
640 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
642 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
643 sizeEvent
.SetEventObject(this);
645 GetEventHandler()->ProcessEvent(sizeEvent
);
648 // For implementation purposes - sometimes decorations make the client area
650 wxPoint
wxWindow::GetClientAreaOrigin() const
652 return wxPoint(0, 0);
655 // Makes an adjustment to the window position (for example, a frame that has
656 // a toolbar that it manages itself).
657 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
659 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
661 wxPoint
pt(GetParent()->GetClientAreaOrigin());
662 x
+= pt
.x
; y
+= pt
.y
;
666 bool wxWindow::Show(bool show
)
670 if (m_borderWidget
|| m_scrolledWindow
)
672 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
676 XtMapWidget((Widget
) GetTopWidget());
681 if (m_borderWidget
|| m_scrolledWindow
)
683 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
687 XtUnmapWidget((Widget
) GetTopWidget());
692 Window xwin = (Window) GetXWindow();
693 Display *xdisp = (Display*) GetXDisplay();
695 XMapWindow(xdisp, xwin);
697 XUnmapWindow(xdisp, xwin);
705 bool wxWindow::IsShown() const
710 int wxWindow::GetCharHeight() const
716 int wxWindow::GetCharWidth() const
722 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
723 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
725 wxFont
*fontToUse
= (wxFont
*)theFont
;
727 fontToUse
= (wxFont
*) & m_windowFont
;
732 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
734 Display
*display
= XtDisplay((Widget
) GetMainWidget());
735 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
737 XExposeEvent dummyEvent
;
739 GetSize(&width
, &height
);
741 dummyEvent
.type
= Expose
;
742 dummyEvent
.display
= display
;
743 dummyEvent
.send_event
= True
;
744 dummyEvent
.window
= thisWindow
;
747 dummyEvent
.x
= rect
->x
;
748 dummyEvent
.y
= rect
->y
;
749 dummyEvent
.width
= rect
->width
;
750 dummyEvent
.height
= rect
->height
;
756 dummyEvent
.width
= width
;
757 dummyEvent
.height
= height
;
759 dummyEvent
.count
= 0;
764 wxBrush
backgroundBrush(GetBackgroundColour(), wxSOLID
);
765 dc
.SetBackground(backgroundBrush
);
769 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
772 // Responds to colour changes: passes event on to children.
773 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
775 wxNode
*node
= GetChildren()->First();
778 // Only propagate to non-top-level windows
779 wxWindow
*win
= (wxWindow
*)node
->Data();
780 if ( win
->GetParent() )
782 wxSysColourChangedEvent event2
;
783 event
.m_eventObject
= win
;
784 win
->GetEventHandler()->ProcessEvent(event2
);
791 // This can be called by the app (or wxWindows) to do default processing for the current
792 // event. Save message/event info in wxWindow so they can be used in this function.
793 long wxWindow::Default()
799 void wxWindow::InitDialog()
801 wxInitDialogEvent
event(GetId());
802 event
.SetEventObject( this );
803 GetEventHandler()->ProcessEvent(event
);
806 // Default init dialog behaviour is to transfer data to window
807 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
809 TransferDataToWindow();
812 // Caret manipulation
813 void wxWindow::CreateCaret(int w
, int h
)
817 m_caretEnabled
= TRUE
;
820 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
825 void wxWindow::ShowCaret(bool show
)
830 void wxWindow::DestroyCaret()
833 m_caretEnabled
= FALSE
;
836 void wxWindow::SetCaretPos(int x
, int y
)
841 void wxWindow::GetCaretPos(int *x
, int *y
) const
846 wxWindow
*wxGetActiveWindow()
852 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
859 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
862 wxFrame
*frame
= (wxFrame
*)this;
864 /* Uncomment when wxFrame implemented
866 XtVaSetValues((Widget) frame->m_frameShell, XmNminWidth, minW, NULL);
868 XtVaSetValues((Widget) frame->m_frameShell, XmNminHeight, minH, NULL);
870 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxWidth, maxW, NULL);
872 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxHeight, maxH, NULL);
874 XtVaSetValues((Widget) frame->m_frameShell, XmNwidthInc, incW, NULL);
876 XtVaSetValues((Widget) frame->m_frameShell, XmNheightInc, incH, NULL);
880 void wxWindow::Centre(int direction
)
882 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
884 wxWindow
*father
= (wxWindow
*)GetParent();
888 father
->GetClientSize(&panel_width
, &panel_height
);
889 GetSize(&width
, &height
);
895 if (direction
& wxHORIZONTAL
)
896 new_x
= (int)((panel_width
- width
)/2);
898 if (direction
& wxVERTICAL
)
899 new_y
= (int)((panel_height
- height
)/2);
901 SetSize(new_x
, new_y
, -1, -1);
905 // Coordinates relative to the window
906 void wxWindow::WarpPointer (int x
, int y
)
908 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
911 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
917 int wxWindow::GetScrollPos(int orient
) const
923 // This now returns the whole range, not just the number
924 // of positions that we can scroll.
925 int wxWindow::GetScrollRange(int orient
) const
931 int wxWindow::GetScrollThumb(int orient
) const
937 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
943 // New function that will replace some of the above.
944 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
945 int range
, bool refresh
)
950 // Does a physical scroll
951 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
957 void wxWindow::SetFont(const wxFont
& font
)
961 if (!m_windowFont
.Ok())
966 void wxWindow::OnChar(wxKeyEvent
& event
)
968 if ( event
.KeyCode() == WXK_TAB
) {
969 // propagate the TABs to the parent - it's up to it to decide what
972 if ( GetParent()->ProcessEvent(event
) )
978 void wxWindow::OnPaint(wxPaintEvent
& event
)
983 bool wxWindow::IsEnabled() const
989 // Dialog support: override these and call
990 // base class members to add functionality
991 // that can't be done using validators.
992 // NOTE: these functions assume that controls
993 // are direct children of this window, not grandchildren
994 // or other levels of descendant.
996 // Transfer values to controls. If returns FALSE,
997 // it's an application error (pops up a dialog)
998 bool wxWindow::TransferDataToWindow()
1000 wxNode
*node
= GetChildren()->First();
1003 wxWindow
*child
= (wxWindow
*)node
->Data();
1004 if ( child
->GetValidator() &&
1005 !child
->GetValidator()->TransferToWindow() )
1007 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1011 node
= node
->Next();
1016 // Transfer values from controls. If returns FALSE,
1017 // validation failed: don't quit
1018 bool wxWindow::TransferDataFromWindow()
1020 wxNode
*node
= GetChildren()->First();
1023 wxWindow
*child
= (wxWindow
*)node
->Data();
1024 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1029 node
= node
->Next();
1034 bool wxWindow::Validate()
1036 wxNode
*node
= GetChildren()->First();
1039 wxWindow
*child
= (wxWindow
*)node
->Data();
1040 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1045 node
= node
->Next();
1050 // Get the window with the focus
1051 wxWindow
*wxWindow::FindFocus()
1057 void wxWindow::AddChild(wxWindow
*child
)
1059 GetChildren()->Append(child
);
1060 child
->m_windowParent
= this;
1063 void wxWindow::RemoveChild(wxWindow
*child
)
1066 GetChildren()->DeleteObject(child
);
1067 child
->m_windowParent
= NULL
;
1070 void wxWindow::DestroyChildren()
1072 if (GetChildren()) {
1074 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1076 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1078 if ( GetChildren()->Member(child
) )
1085 void wxWindow::MakeModal(bool modal
)
1087 // Disable all other windows
1088 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1090 wxNode
*node
= wxTopLevelWindows
.First();
1093 wxWindow
*win
= (wxWindow
*)node
->Data();
1095 win
->Enable(!modal
);
1097 node
= node
->Next();
1102 // If nothing defined for this, try the parent.
1103 // E.g. we may be a button loaded from a resource, with no callback function
1105 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1107 if (GetEventHandler()->ProcessEvent(event
) )
1110 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1113 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1117 UnsetConstraints(m_constraints
);
1118 delete m_constraints
;
1123 // Make sure other windows know they're part of a 'meaningful relationship'
1124 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1125 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1126 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1127 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1128 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1129 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1130 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1131 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1132 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1133 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1134 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1135 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1136 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1137 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1138 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1139 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1143 // This removes any dangling pointers to this window
1144 // in other windows' constraintsInvolvedIn lists.
1145 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1149 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1150 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1151 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1152 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1153 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1154 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1155 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1156 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1157 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1158 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1159 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1160 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1161 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1162 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1163 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1164 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1168 // Back-pointer to other windows we're involved with, so if we delete
1169 // this window, we must delete any constraints we're involved with.
1170 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1172 if (!m_constraintsInvolvedIn
)
1173 m_constraintsInvolvedIn
= new wxList
;
1174 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1175 m_constraintsInvolvedIn
->Append(otherWin
);
1178 // REMOVE back-pointer to other windows we're involved with.
1179 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1181 if (m_constraintsInvolvedIn
)
1182 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1185 // Reset any constraints that mention this window
1186 void wxWindow::DeleteRelatedConstraints()
1188 if (m_constraintsInvolvedIn
)
1190 wxNode
*node
= m_constraintsInvolvedIn
->First();
1193 wxWindow
*win
= (wxWindow
*)node
->Data();
1194 wxNode
*next
= node
->Next();
1195 wxLayoutConstraints
*constr
= win
->GetConstraints();
1197 // Reset any constraints involving this window
1200 constr
->left
.ResetIfWin((wxWindow
*)this);
1201 constr
->top
.ResetIfWin((wxWindow
*)this);
1202 constr
->right
.ResetIfWin((wxWindow
*)this);
1203 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1204 constr
->width
.ResetIfWin((wxWindow
*)this);
1205 constr
->height
.ResetIfWin((wxWindow
*)this);
1206 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1207 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1212 delete m_constraintsInvolvedIn
;
1213 m_constraintsInvolvedIn
= NULL
;
1217 void wxWindow::SetSizer(wxSizer
*sizer
)
1219 m_windowSizer
= sizer
;
1221 sizer
->SetSizerParent((wxWindow
*)this);
1228 bool wxWindow::Layout()
1230 if (GetConstraints())
1233 GetClientSize(&w
, &h
);
1234 GetConstraints()->width
.SetValue(w
);
1235 GetConstraints()->height
.SetValue(h
);
1238 // If top level (one sizer), evaluate the sizer's constraints.
1242 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1243 GetSizer()->LayoutPhase1(&noChanges
);
1244 GetSizer()->LayoutPhase2(&noChanges
);
1245 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1250 // Otherwise, evaluate child constraints
1251 ResetConstraints(); // Mark all constraints as unevaluated
1252 DoPhase(1); // Just one phase need if no sizers involved
1254 SetConstraintSizes(); // Recursively set the real window sizes
1260 // Do a phase of evaluating constraints:
1261 // the default behaviour. wxSizers may do a similar
1262 // thing, but also impose their own 'constraints'
1263 // and order the evaluation differently.
1264 bool wxWindow::LayoutPhase1(int *noChanges
)
1266 wxLayoutConstraints
*constr
= GetConstraints();
1269 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1275 bool wxWindow::LayoutPhase2(int *noChanges
)
1285 // Do a phase of evaluating child constraints
1286 bool wxWindow::DoPhase(int phase
)
1288 int noIterations
= 0;
1289 int maxIterations
= 500;
1293 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1297 wxNode
*node
= GetChildren()->First();
1300 wxWindow
*child
= (wxWindow
*)node
->Data();
1301 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1303 wxLayoutConstraints
*constr
= child
->GetConstraints();
1306 if (succeeded
.Member(child
))
1311 int tempNoChanges
= 0;
1312 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1313 noChanges
+= tempNoChanges
;
1316 succeeded
.Append(child
);
1321 node
= node
->Next();
1328 void wxWindow::ResetConstraints()
1330 wxLayoutConstraints
*constr
= GetConstraints();
1333 constr
->left
.SetDone(FALSE
);
1334 constr
->top
.SetDone(FALSE
);
1335 constr
->right
.SetDone(FALSE
);
1336 constr
->bottom
.SetDone(FALSE
);
1337 constr
->width
.SetDone(FALSE
);
1338 constr
->height
.SetDone(FALSE
);
1339 constr
->centreX
.SetDone(FALSE
);
1340 constr
->centreY
.SetDone(FALSE
);
1342 wxNode
*node
= GetChildren()->First();
1345 wxWindow
*win
= (wxWindow
*)node
->Data();
1346 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1347 win
->ResetConstraints();
1348 node
= node
->Next();
1352 // Need to distinguish between setting the 'fake' size for
1353 // windows and sizers, and setting the real values.
1354 void wxWindow::SetConstraintSizes(bool recurse
)
1356 wxLayoutConstraints
*constr
= GetConstraints();
1357 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1358 constr
->width
.GetDone() && constr
->height
.GetDone())
1360 int x
= constr
->left
.GetValue();
1361 int y
= constr
->top
.GetValue();
1362 int w
= constr
->width
.GetValue();
1363 int h
= constr
->height
.GetValue();
1365 // If we don't want to resize this window, just move it...
1366 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1367 (constr
->height
.GetRelationship() != wxAsIs
))
1369 // Calls Layout() recursively. AAAGH. How can we stop that.
1370 // Simply take Layout() out of non-top level OnSizes.
1371 SizerSetSize(x
, y
, w
, h
);
1380 char *windowClass
= this->GetClassInfo()->GetClassName();
1383 if (GetName() == "")
1384 winName
= "unnamed";
1386 winName
= GetName();
1387 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1388 if (!constr
->left
.GetDone())
1389 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1390 if (!constr
->right
.GetDone())
1391 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1392 if (!constr
->width
.GetDone())
1393 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1394 if (!constr
->height
.GetDone())
1395 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1396 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1401 wxNode
*node
= GetChildren()->First();
1404 wxWindow
*win
= (wxWindow
*)node
->Data();
1405 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1406 win
->SetConstraintSizes();
1407 node
= node
->Next();
1412 // This assumes that all sizers are 'on' the same
1413 // window, i.e. the parent of this window.
1414 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1416 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1417 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1421 m_sizerParent
->GetPosition(&xp
, &yp
);
1422 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1427 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1431 TransformSizerToActual(&xx
, &yy
);
1432 SetSize(xx
, yy
, w
, h
);
1435 void wxWindow::SizerMove(int x
, int y
)
1439 TransformSizerToActual(&xx
, &yy
);
1443 // Only set the size/position of the constraint (if any)
1444 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1446 wxLayoutConstraints
*constr
= GetConstraints();
1451 constr
->left
.SetValue(x
);
1452 constr
->left
.SetDone(TRUE
);
1456 constr
->top
.SetValue(y
);
1457 constr
->top
.SetDone(TRUE
);
1461 constr
->width
.SetValue(w
);
1462 constr
->width
.SetDone(TRUE
);
1466 constr
->height
.SetValue(h
);
1467 constr
->height
.SetDone(TRUE
);
1472 void wxWindow::MoveConstraint(int x
, int y
)
1474 wxLayoutConstraints
*constr
= GetConstraints();
1479 constr
->left
.SetValue(x
);
1480 constr
->left
.SetDone(TRUE
);
1484 constr
->top
.SetValue(y
);
1485 constr
->top
.SetDone(TRUE
);
1490 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1492 wxLayoutConstraints
*constr
= GetConstraints();
1495 *w
= constr
->width
.GetValue();
1496 *h
= constr
->height
.GetValue();
1502 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1504 wxLayoutConstraints
*constr
= GetConstraints();
1507 *w
= constr
->width
.GetValue();
1508 *h
= constr
->height
.GetValue();
1511 GetClientSize(w
, h
);
1514 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1516 wxLayoutConstraints
*constr
= GetConstraints();
1519 *x
= constr
->left
.GetValue();
1520 *y
= constr
->top
.GetValue();
1526 bool wxWindow::Close(bool force
)
1528 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1529 event
.SetEventObject(this);
1530 event
.SetForce(force
);
1532 return GetEventHandler()->ProcessEvent(event
);
1535 wxObject
* wxWindow::GetChild(int number
) const
1537 // Return a pointer to the Nth object in the window
1540 wxNode
*node
= GetChildren()->First();
1543 node
= node
->Next() ;
1546 wxObject
*obj
= (wxObject
*)node
->Data();
1553 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1555 // Obsolete function
1558 void wxWindow::Clear()
1560 wxClientDC
dc(this);
1561 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1562 dc
.SetBackground(brush
);
1566 // Fits the panel around the items
1567 void wxWindow::Fit()
1571 wxNode
*node
= GetChildren()->First();
1574 wxWindow
*win
= (wxWindow
*)node
->Data();
1576 win
->GetPosition(&wx
, &wy
);
1577 win
->GetSize(&ww
, &wh
);
1578 if ( wx
+ ww
> maxX
)
1580 if ( wy
+ wh
> maxY
)
1583 node
= node
->Next();
1585 SetClientSize(maxX
+ 5, maxY
+ 5);
1588 void wxWindow::SetValidator(const wxValidator
& validator
)
1590 if ( m_windowValidator
)
1591 delete m_windowValidator
;
1592 m_windowValidator
= validator
.Clone();
1594 if ( m_windowValidator
)
1595 m_windowValidator
->SetWindow(this) ;
1598 // Find a window by id or name
1599 wxWindow
*wxWindow::FindWindow(long id
)
1604 wxNode
*node
= GetChildren()->First();
1607 wxWindow
*child
= (wxWindow
*)node
->Data();
1608 wxWindow
*found
= child
->FindWindow(id
);
1611 node
= node
->Next();
1616 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1618 if ( GetName() == name
)
1621 wxNode
*node
= GetChildren()->First();
1624 wxWindow
*child
= (wxWindow
*)node
->Data();
1625 wxWindow
*found
= child
->FindWindow(name
);
1628 node
= node
->Next();
1633 void wxWindow::OnIdle(wxIdleEvent
& event
)
1635 /* TODO: you may need to do something like this
1636 * if your GUI doesn't generate enter/leave events
1638 // Check if we need to send a LEAVE event
1639 if (m_mouseInWindow)
1642 ::GetCursorPos(&pt);
1643 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1645 // Generate a LEAVE event
1646 m_mouseInWindow = FALSE;
1647 MSWOnMouseLeave(pt.x, pt.y, 0);
1652 // This calls the UI-update mechanism (querying windows for
1653 // menu/toolbar/control state information)
1657 // Raise the window to the top of the Z order
1658 void wxWindow::Raise()
1660 Window window
= XtWindow((Widget
) GetTopWidget());
1661 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1664 // Lower the window to the bottom of the Z order
1665 void wxWindow::Lower()
1667 Window window
= XtWindow((Widget
) GetTopWidget());
1668 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1671 bool wxWindow::AcceptsFocus() const
1673 return IsShown() && IsEnabled();
1676 // Update region access
1677 wxRegion
wxWindow::GetUpdateRegion() const
1679 return m_updateRegion
;
1682 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1684 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1687 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1689 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1692 bool wxWindow::IsExposed(const wxRect
& rect
) const
1694 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1698 * Allocates control IDs
1701 int wxWindow::NewControlId()
1703 static int s_controlId
= 0;
1708 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1710 m_acceleratorTable
= accel
;
1713 // All widgets should have this as their resize proc.
1714 // OnSize sent to wxWindow via client data.
1715 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1717 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
1721 if (win
->PreResize())
1724 win
->GetSize(&width
, &height
);
1725 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1726 sizeEvent
.SetEventObject(win
);
1727 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1731 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1733 wxWindow
*oldItem
= NULL
;
1735 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
1737 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1740 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
1743 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
1748 wxWidgetHashTable
->Put ((long) w
, win
);
1752 wxWindow
*wxGetWindowFromTable(Widget w
)
1754 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
1757 void wxDeleteWindowFromTable(Widget w
)
1759 wxWidgetHashTable
->Delete((long)w
);
1762 // Get the underlying X window and display
1763 WXWindow
wxWindow::GetXWindow() const
1765 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
1768 WXDisplay
*wxWindow::GetXDisplay() const
1770 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
1773 WXWidget
wxWindow::GetMainWidget() const
1776 return m_drawingArea
;
1778 return m_mainWidget
;
1781 WXWidget
wxWindow::GetClientWidget() const
1783 if (m_drawingArea
!= (WXWidget
) 0)
1784 return m_drawingArea
;
1786 return GetMainWidget();
1789 WXWidget
wxWindow::GetTopWidget() const
1791 return GetMainWidget();
1794 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
1795 XmDrawingAreaCallbackStruct
* cbs
)
1797 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
1800 XEvent
* event
= cbs
->event
;
1801 wxWindow
* canvas
= (wxWindow
*) clientData
;
1802 Display
* display
= (Display
*) canvas
->GetXDisplay();
1803 // GC gc = (GC) canvas->GetDC()->gc;
1805 switch (event
->type
)
1810 wxCanvasDC* canvasDC = canvas->GetDC();
1813 if (canvasDC->onpaint_reg)
1814 XDestroyRegion(canvasDC->onpaint_reg);
1815 canvasDC->onpaint_reg = XCreateRegion();
1820 int n
= canvas
->m_updateRects
.Number();
1821 XRectangle
* xrects
= new XRectangle
[n
];
1823 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
1825 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
1826 xrects
[i
].x
= rect
->x
;
1827 xrects
[i
].y
= rect
->y
;
1828 xrects
[i
].width
= rect
->width
;
1829 xrects
[i
].height
= rect
->height
;
1830 /* TODO (?) Actually ignore it I think.
1832 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
1833 canvasDC->onpaint_reg);
1836 /* TODO must clip the area being repainted. So we need a gc.
1837 * Alternatively, wxPaintDC must do the clipping
1838 * when it's created.
1839 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
1842 canvas
->DoPaint() ; // xrects, n);
1845 canvas
->m_updateRects
.Clear();
1850 XDestroyRegion(canvasDC->onpaint_reg);
1851 canvasDC->onpaint_reg = NULL;
1855 gc_val.clip_mask = None;
1856 XChangeGC(display, gc, GCClipMask, &gc_val);
1863 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
1869 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1871 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
1873 XmDrawingAreaCallbackStruct cbs
;
1876 //if (event->mode!=NotifyNormal)
1879 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
1880 ((XCrossingEvent
&) ev
) = *event
;
1882 cbs
.reason
= XmCR_INPUT
;
1885 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1888 // Fix to make it work under Motif 1.0 (!)
1889 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1893 XmDrawingAreaCallbackStruct cbs
;
1896 //ev.xbutton = *event;
1897 ev
= *((XEvent
*) event
);
1898 cbs
.reason
= XmCR_INPUT
;
1901 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1905 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
1907 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
1913 if (cbs
->reason
!= XmCR_INPUT
)
1916 local_event
= *(cbs
->event
); // We must keep a copy!
1918 switch (local_event
.xany
.type
)
1926 wxEventType eventType
= wxEVT_NULL
;
1928 if (local_event
.xany
.type
== EnterNotify
)
1930 //if (local_event.xcrossing.mode!=NotifyNormal)
1931 // return ; // Ignore grab events
1932 eventType
= wxEVT_ENTER_WINDOW
;
1933 // canvas->GetEventHandler()->OnSetFocus();
1935 else if (local_event
.xany
.type
== LeaveNotify
)
1937 //if (local_event.xcrossing.mode!=NotifyNormal)
1938 // return ; // Ignore grab events
1939 eventType
= wxEVT_LEAVE_WINDOW
;
1940 // canvas->GetEventHandler()->OnKillFocus();
1942 else if (local_event
.xany
.type
== MotionNotify
)
1944 eventType
= wxEVT_MOTION
;
1945 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1948 Display
*dpy
= XtDisplay (drawingArea
);
1950 XQueryPointer (dpy
, XtWindow (drawingArea
),
1952 &local_event
.xmotion
.x_root
,
1953 &local_event
.xmotion
.y_root
,
1954 &local_event
.xmotion
.x
,
1955 &local_event
.xmotion
.y
,
1956 &local_event
.xmotion
.state
);
1963 else if (local_event
.xany
.type
== ButtonPress
)
1965 if (local_event
.xbutton
.button
== Button1
)
1967 eventType
= wxEVT_LEFT_DOWN
;
1968 canvas
->m_button1Pressed
= TRUE
;
1970 else if (local_event
.xbutton
.button
== Button2
)
1972 eventType
= wxEVT_MIDDLE_DOWN
;
1973 canvas
->m_button2Pressed
= TRUE
;
1975 else if (local_event
.xbutton
.button
== Button3
)
1977 eventType
= wxEVT_RIGHT_DOWN
;
1978 canvas
->m_button3Pressed
= TRUE
;
1981 else if (local_event
.xany
.type
== ButtonRelease
)
1983 if (local_event
.xbutton
.button
== Button1
)
1985 eventType
= wxEVT_LEFT_UP
;
1986 canvas
->m_button1Pressed
= FALSE
;
1988 else if (local_event
.xbutton
.button
== Button2
)
1990 eventType
= wxEVT_MIDDLE_UP
;
1991 canvas
->m_button2Pressed
= FALSE
;
1993 else if (local_event
.xbutton
.button
== Button3
)
1995 eventType
= wxEVT_RIGHT_UP
;
1996 canvas
->m_button3Pressed
= FALSE
;
2000 wxMouseEvent
wxevent (eventType
);
2001 wxevent
.m_eventHandle
= (char *) &local_event
;
2003 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2004 || (event_left_is_down (&local_event
)
2005 && (eventType
!= wxEVT_LEFT_UP
)));
2006 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2007 || (event_middle_is_down (&local_event
)
2008 && (eventType
!= wxEVT_MIDDLE_UP
)));
2009 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2010 || (event_right_is_down (&local_event
)
2011 && (eventType
!= wxEVT_RIGHT_UP
)));
2013 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2014 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2015 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2016 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2017 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2019 // Now check if we need to translate this event into a double click
2020 if (TRUE
) // canvas->doubleClickAllowed)
2022 if (wxevent
.ButtonDown())
2024 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2026 // get button and time-stamp
2028 if (wxevent
.LeftDown()) button
= 1;
2029 else if (wxevent
.MiddleDown()) button
= 2;
2030 else if (wxevent
.RightDown()) button
= 3;
2031 long ts
= wxevent
.GetTimestamp();
2032 // check, if single or double click
2033 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2036 canvas
->m_lastButton
= 0;
2037 switch ( eventType
)
2039 case wxEVT_LEFT_DOWN
:
2040 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2042 case wxEVT_MIDDLE_DOWN
:
2043 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2045 case wxEVT_RIGHT_DOWN
:
2046 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2056 // not fast enough or different button
2057 canvas
->m_lastTS
= ts
;
2058 canvas
->m_lastButton
= button
;
2063 wxevent
.SetId(canvas
->GetId());
2064 wxevent
.SetEventObject(canvas
);
2065 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2067 if (eventType == wxEVT_ENTER_WINDOW ||
2068 eventType == wxEVT_LEAVE_WINDOW ||
2069 eventType == wxEVT_MOTION
2078 // XComposeStatus compose;
2079 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2080 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2081 int id
= wxCharCodeXToWX (keySym
);
2083 wxKeyEvent
event (wxEVT_CHAR
);
2085 if (local_event
.xkey
.state
& ShiftMask
)
2086 event
.m_shiftDown
= TRUE
;
2087 if (local_event
.xkey
.state
& ControlMask
)
2088 event
.m_controlDown
= TRUE
;
2089 if (local_event
.xkey
.state
& Mod3Mask
)
2090 event
.m_altDown
= TRUE
;
2091 if (local_event
.xkey
.state
& Mod1Mask
)
2092 event
.m_metaDown
= TRUE
;
2093 event
.SetEventObject(canvas
);
2094 event
.m_keyCode
= id
;
2095 event
.SetTimestamp(local_event
.xkey
.time
);
2099 // Implement wxFrame::OnCharHook by checking ancestor.
2100 wxWindow
*parent
= canvas
->GetParent();
2101 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2102 parent
= parent
->GetParent();
2106 event
.SetEventType(wxEVT_CHAR_HOOK
);
2107 if (parent
->GetEventHandler()->ProcessEvent(event
))
2109 event
.SetEventType(wxEVT_CHAR
);
2112 canvas
->GetEventHandler()->ProcessEvent (event
);
2118 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2120 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2121 event
.SetEventObject(canvas
);
2122 canvas
->GetEventHandler()->ProcessEvent(event
);
2128 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2130 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2131 event
.SetEventObject(canvas
);
2132 canvas
->GetEventHandler()->ProcessEvent(event
);
2141 void wxWindow::DoPaint()
2143 //TODO : make a temporary gc so we can do the XCopyArea below
2144 if (0) // m_backingPixmap)
2147 Widget drawingArea = (Widget) m_drawingArea;
2148 // int orig = GetDC()->GetLogicalFunction();
2149 // GetDC()->SetLogicalFunction (wxCOPY);
2151 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2152 // should be able to calculate them.
2153 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2154 m_pixmapOffsetX, m_pixmapOffsetY,
2155 m_pixmapWidth, m_pixmapHeight,
2158 // GetDC()->SetLogicalFunction (orig);
2163 wxPaintEvent
event(GetId());
2164 event
.SetEventObject(this);
2165 GetEventHandler()->ProcessEvent(event
);
2169 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2170 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2172 Widget drawingArea
= (Widget
) m_drawingArea
;
2173 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2176 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2177 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2179 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2181 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2185 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2187 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2195 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2196 short thick
, margin
;
2197 XtVaGetValues ((Widget
) m_borderWidget
,
2198 XmNshadowThickness
, &thick
,
2199 XmNmarginWidth
, &margin
,
2201 w
-= 2 * (thick
+ margin
);
2204 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2208 XtVaGetValues ((Widget
) m_scrolledWindow
,
2209 XmNspacing
, &spacing
,
2210 XmNverticalScrollBar
, &sbar
,
2214 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2218 w
-= (spacing
+ wsbar
);
2220 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2226 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2227 short thick
, margin
;
2228 XtVaGetValues ((Widget
) m_borderWidget
,
2229 XmNshadowThickness
, &thick
,
2230 XmNmarginHeight
, &margin
,
2232 h
-= 2 * (thick
+ margin
);
2235 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2239 XtVaGetValues ((Widget
) m_scrolledWindow
,
2240 XmNspacing
, &spacing
,
2241 XmNhorizontalScrollBar
, &sbar
,
2245 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2249 h
-= (spacing
+ wsbar
);
2251 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2254 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2255 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2258 GetClientSize (&ww
, &hh
);
2259 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2260 sizeEvent
.SetEventObject(this);
2262 GetEventHandler()->ProcessEvent(sizeEvent
);
2265 void wxWindow::CanvasSetClientSize (int w
, int h
)
2267 Widget drawingArea
= (Widget
) m_drawingArea
;
2269 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2272 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2274 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2275 /* TODO: is this necessary?
2276 allowRepainting = FALSE;
2278 XSync (XtDisplay (drawingArea), FALSE);
2280 while (XtAppPending (wxTheApp->appContext))
2282 XFlush (XtDisplay (drawingArea));
2283 XtAppNextEvent (wxTheApp->appContext, &event);
2284 XtDispatchEvent (&event);
2288 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2291 allowRepainting = TRUE;
2295 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2296 sizeEvent
.SetEventObject(this);
2298 GetEventHandler()->ProcessEvent(sizeEvent
);
2301 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2303 // Must return the same thing that was set via SetClientSize
2305 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2310 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2313 if ((Widget
) m_borderWidget
)
2314 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2315 else if ((Widget
) m_scrolledWindow
)
2316 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2318 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2324 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2327 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2332 // Add to hash table, add event handler
2333 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2334 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2336 wxAddWindowToTable((Widget
) mainWidget
, this);
2337 if (CanAddEventHandler())
2339 XtAddEventHandler((Widget
) mainWidget
,
2340 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2342 wxPanelItemEventHandler
,
2349 XtOverrideTranslations ((Widget
) mainWidget
,
2350 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2351 XtFree ((char *) ptr
);
2354 // Some widgets have a parent form widget, e.g. wxRadioBox
2357 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2361 XtOverrideTranslations ((Widget
) formWidget
,
2362 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2363 XtFree ((char *) ptr
);
2370 SetSize (x
, y
, width
, height
);
2375 // Remove event handler, remove from hash table
2376 bool wxWindow::DetachWidget(WXWidget widget
)
2378 if (CanAddEventHandler())
2380 XtRemoveEventHandler((Widget
) widget
,
2381 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2383 wxPanelItemEventHandler
,
2387 wxDeleteWindowFromTable((Widget
) widget
);
2391 void wxPanelItemEventHandler (Widget wid
,
2392 XtPointer client_data
,
2394 Boolean
*continueToDispatch
)
2396 // Widget can be a label or the actual widget.
2398 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2401 wxMouseEvent
wxevent(0);
2402 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2404 window
->GetEventHandler()->ProcessEvent(wxevent
);
2407 // TODO: probably the key to allowing default behaviour
2409 // Say we set a m_doDefault flag to FALSE at the start of this
2410 // function. Then in e.g. wxWindow::OnMouseEvent we can
2411 // call Default() which sets this flag to TRUE, indicating
2412 // that default processing can happen. Thus, behaviour can appear
2413 // to be overridden just by adding an event handler and not calling
2414 // wxWindow::OnWhatever.
2415 // ALSO, maybe we can use this instead of the current way of handling
2416 // drawing area events, to simplify things.
2417 *continueToDispatch
= True
;
2420 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2422 switch (xevent
->xany
.type
)
2430 wxEventType eventType
= wxEVT_NULL
;
2432 if (xevent
->xany
.type
== LeaveNotify
)
2434 win
->m_button1Pressed
= FALSE
;
2435 win
->m_button2Pressed
= FALSE
;
2436 win
->m_button3Pressed
= FALSE
;
2439 else if (xevent
->xany
.type
== MotionNotify
)
2441 eventType
= wxEVT_MOTION
;
2443 else if (xevent
->xany
.type
== ButtonPress
)
2445 if (xevent
->xbutton
.button
== Button1
)
2447 eventType
= wxEVT_LEFT_DOWN
;
2448 win
->m_button1Pressed
= TRUE
;
2450 else if (xevent
->xbutton
.button
== Button2
)
2452 eventType
= wxEVT_MIDDLE_DOWN
;
2453 win
->m_button2Pressed
= TRUE
;
2455 else if (xevent
->xbutton
.button
== Button3
)
2457 eventType
= wxEVT_RIGHT_DOWN
;
2458 win
->m_button3Pressed
= TRUE
;
2461 else if (xevent
->xany
.type
== ButtonRelease
)
2463 if (xevent
->xbutton
.button
== Button1
)
2465 eventType
= wxEVT_LEFT_UP
;
2466 win
->m_button1Pressed
= FALSE
;
2468 else if (xevent
->xbutton
.button
== Button2
)
2470 eventType
= wxEVT_MIDDLE_UP
;
2471 win
->m_button2Pressed
= FALSE
;
2473 else if (xevent
->xbutton
.button
== Button3
)
2475 eventType
= wxEVT_RIGHT_UP
;
2476 win
->m_button3Pressed
= FALSE
;
2482 wxevent
.m_eventHandle
= (char *)xevent
;
2483 wxevent
.SetEventType(eventType
);
2486 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2489 win
->GetPosition(&x2
, &y2
);
2491 // The button x/y must be translated to wxWindows
2492 // window space - the widget might be a label or button,
2496 if (widget
!= (Widget
)win
->GetMainWidget())
2502 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2503 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2505 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2506 || (event_left_is_down (xevent
)
2507 && (eventType
!= wxEVT_LEFT_UP
)));
2508 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2509 || (event_middle_is_down (xevent
)
2510 && (eventType
!= wxEVT_MIDDLE_UP
)));
2511 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2512 || (event_right_is_down (xevent
)
2513 && (eventType
!= wxEVT_RIGHT_UP
)));
2515 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2516 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2523 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2525 switch (xevent
->xany
.type
)
2532 // XComposeStatus compose;
2533 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2534 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2535 int id
= wxCharCodeXToWX (keySym
);
2537 if (xevent
->xkey
.state
& ShiftMask
)
2538 wxevent
.m_shiftDown
= TRUE
;
2539 if (xevent
->xkey
.state
& ControlMask
)
2540 wxevent
.m_controlDown
= TRUE
;
2541 if (xevent
->xkey
.state
& Mod3Mask
)
2542 wxevent
.m_altDown
= TRUE
;
2543 if (xevent
->xkey
.state
& Mod1Mask
)
2544 wxevent
.m_metaDown
= TRUE
;
2545 wxevent
.SetEventObject(win
);
2546 wxevent
.m_keyCode
= id
;
2547 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2549 wxevent
.m_x
= xevent
->xbutton
.x
;
2550 wxevent
.m_y
= xevent
->xbutton
.y
;
2564 // TODO From wxWin 1.68. What does it do exactly?
2565 #define YAllocColor XAllocColor
2567 XColor itemColors
[5];
2568 int wxComputeColors (Display
*display
, wxColour
* back
, wxColour
* fore
)
2571 static XmColorProc colorProc
;
2573 result
= wxNO_COLORS
;
2577 itemColors
[0].red
= (((long) back
->Red ()) << 8);
2578 itemColors
[0].green
= (((long) back
->Green ()) << 8);
2579 itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2580 itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2581 if (colorProc
== (XmColorProc
) NULL
)
2583 // Get a ptr to the actual function
2584 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2585 // And set it back to motif.
2586 XmSetColorCalculation (colorProc
);
2588 (*colorProc
) (&itemColors
[wxBACK_INDEX
],
2589 &itemColors
[wxFORE_INDEX
],
2590 &itemColors
[wxSELE_INDEX
],
2591 &itemColors
[wxTOPS_INDEX
],
2592 &itemColors
[wxBOTS_INDEX
]);
2593 result
= wxBACK_COLORS
;
2597 itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2598 itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2599 itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2600 itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2601 if (result
== wxNO_COLORS
)
2602 result
= wxFORE_COLORS
;
2605 Display
*dpy
= display
;
2606 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2610 /* 5 Colours to allocate */
2611 for (int i
= 0; i
< 5; i
++)
2612 if (!YAllocColor (dpy
, cmap
, &itemColors
[i
]))
2613 result
= wxNO_COLORS
;
2617 /* Only 1 colour to allocate */
2618 if (!YAllocColor (dpy
, cmap
, &itemColors
[wxFORE_INDEX
]))
2619 result
= wxNO_COLORS
;
2626 void wxWindow::ChangeColour(WXWidget widget
)
2632 // TODO: how to determine whether we can change this item's colours?
2633 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
2635 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
2638 change
= wxComputeColors (XtDisplay((Widget
)widget
), panel
->GetBackgroundColour(),
2639 panel
->GetLabelColour());
2640 if (change
== wxBACK_COLORS
)
2641 XtVaSetValues ((Widget
) widget
,
2642 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2643 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2644 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2645 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2647 else if (change
== wxFORE_COLORS
)
2648 XtVaSetValues (formWidget
,
2649 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2652 change
= wxComputeColors (XtDisplay((Widget
)formWidget
), GetBackgroundColour(), GetLabelColour());
2653 if (change
== wxBACK_COLORS
)
2654 XtVaSetValues (labelWidget
,
2655 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2656 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2657 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2658 XmNarmColor
, itemColors
[wxSELE_INDEX
].pixel
,
2659 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2661 else if (change
== wxFORE_COLORS
)
2662 XtVaSetValues (labelWidget
,
2663 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2668 void wxWindow::ChangeFont(WXWidget widget
)
2671 if (widget && GetFont() && GetFont()->IsOk())
2672 XtVaSetValues ((Widget) widget,
2673 XmNfontList, GetFont()->GetInternalFont (),