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
;
138 wxWindow::~wxWindow()
143 DetachWidget(GetMainWidget()); // Removes event handlers
145 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
148 // Destroy children before destroying self
152 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
154 Widget w
= (Widget
) m_drawingArea
;
155 wxDeleteWindowFromTable(w
);
159 m_mainWidget
= (WXWidget
) 0;
161 // Only if we're _really_ a canvas (not a dialog box/panel)
162 if (m_scrolledWindow
)
164 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
169 XtUnmanageChild ((Widget
) m_hScrollBar
);
170 XtDestroyWidget ((Widget
) m_hScrollBar
);
174 XtUnmanageChild ((Widget
) m_vScrollBar
);
175 XtDestroyWidget ((Widget
) m_vScrollBar
);
177 if (m_scrolledWindow
)
179 XtUnmanageChild ((Widget
) m_scrolledWindow
);
180 XtDestroyWidget ((Widget
) m_scrolledWindow
);
185 XtDestroyWidget ((Widget
) m_borderWidget
);
186 m_borderWidget
= (WXWidget
) 0;
192 // Have to delete constraints/sizer FIRST otherwise
193 // sizers may try to look at deleted windows as they
194 // delete themselves.
196 DeleteRelatedConstraints();
199 // This removes any dangling pointers to this window
200 // in other windows' constraintsInvolvedIn lists.
201 UnsetConstraints(m_constraints
);
202 delete m_constraints
;
203 m_constraints
= NULL
;
207 delete m_windowSizer
;
208 m_windowSizer
= NULL
;
210 // If this is a child of a sizer, remove self from parent
212 m_sizerParent
->RemoveChild((wxWindow
*)this);
216 m_windowParent
->RemoveChild(this);
220 // Destroy the window
223 wxDeleteWindowFromTable((Widget
) GetMainWidget());
224 XtDestroyWidget((Widget
) GetMainWidget());
225 SetMainWidget((WXWidget
) NULL
);
231 // Just in case the window has been Closed, but
232 // we're then deleting immediately: don't leave
233 // dangling pointers.
234 wxPendingDelete
.DeleteObject(this);
236 if ( m_windowValidator
)
237 delete m_windowValidator
;
240 // Destroy the window (delayed, if a managed window)
241 bool wxWindow::Destroy()
248 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
252 const wxString
& name
)
257 m_windowParent
= NULL
;
258 m_windowEventHandler
= this;
260 m_windowCursor
= *wxSTANDARD_CURSOR
;
261 m_constraints
= NULL
;
262 m_constraintsInvolvedIn
= NULL
;
263 m_windowSizer
= NULL
;
264 m_sizerParent
= NULL
;
265 m_autoLayout
= FALSE
;
266 m_windowValidator
= NULL
;
267 #if USE_DRAG_AND_DROP
268 m_pDropTarget
= NULL
;
270 m_caretWidth
= 0; m_caretHeight
= 0;
271 m_caretEnabled
= FALSE
;
272 m_caretShown
= FALSE
;
277 m_defaultItem
= NULL
;
278 m_windowParent
= NULL
;
281 m_canAddEventHandler
= FALSE
;
282 m_mainWidget
= (WXWidget
) 0;
283 m_button1Pressed
= FALSE
;
284 m_button2Pressed
= FALSE
;
285 m_button3Pressed
= FALSE
;
286 m_winCaptured
= FALSE
;
288 m_hScrollBar
= (WXWidget
) 0;
289 m_vScrollBar
= (WXWidget
) 0;
290 m_borderWidget
= (WXWidget
) 0;
291 m_scrolledWindow
= (WXWidget
) 0;
292 m_drawingArea
= (WXWidget
) 0;
295 m_hScrollingEnabled
= FALSE
;
296 m_vScrollingEnabled
= FALSE
;
297 m_backingPixmap
= (WXPixmap
) 0;
306 if (parent
) parent
->AddChild(this);
313 m_windowId
= (int)NewControlId();
317 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
318 m_foregroundColour
= *wxBLACK
;
319 m_defaultForegroundColour
= *wxBLACK
;
320 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
322 m_windowStyle
= style
;
325 m_windowId
= (int)NewControlId();
329 //// TODO: we should probably optimize by only creating a
330 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
331 //// But for now, let's simplify things by always creating the
332 //// drawing area, since otherwise the translations are different.
334 // New translations for getting mouse motion feedback
335 String translations
=
336 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
337 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
338 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
339 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
340 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
341 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
342 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
343 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
344 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
345 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
346 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
347 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
348 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
349 <Key>: DrawingAreaInput()";
351 XtActionsRec actions
[1];
352 actions
[0].string
= "wxCanvasMotionEvent";
353 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
354 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
356 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
357 if (style
& wxBORDER
)
358 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
359 xmFrameWidgetClass
, parentWidget
,
360 XmNshadowType
, XmSHADOW_IN
,
363 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
364 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
366 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
370 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
371 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
372 XmNunitType
, XmPIXELS
,
373 // XmNresizePolicy, XmRESIZE_ANY,
374 XmNresizePolicy
, XmRESIZE_NONE
,
377 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
380 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
382 XtFree ((char *) ptr);
383 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
384 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
385 XtFree ((char *) ptr);
389 wxAddWindowToTable((Widget
) m_drawingArea
, this);
390 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
393 * This order is very important in Motif 1.2.1
397 XtRealizeWidget ((Widget
) m_scrolledWindow
);
398 XtRealizeWidget ((Widget
) m_drawingArea
);
399 XtManageChild ((Widget
) m_drawingArea
);
401 XtOverrideTranslations ((Widget
) m_drawingArea
,
402 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
403 XtFree ((char *) ptr
);
405 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
406 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
409 display = XtDisplay (scrolledWindow);
410 xwindow = XtWindow (drawingArea);
413 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
414 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
419 void wxWindow::SetFocus()
421 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
422 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
425 void wxWindow::Enable(bool enable
)
429 XtSetSensitive((Widget
) GetMainWidget(), enable
);
430 XmUpdateDisplay((Widget
) GetMainWidget());
434 void wxWindow::CaptureMouse()
440 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
442 m_winCaptured
= TRUE
;
445 void wxWindow::ReleaseMouse()
451 XtRemoveGrab((Widget
) GetMainWidget());
452 m_winCaptured
= FALSE
;
455 // Push/pop event handler (i.e. allow a chain of event handlers
457 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
459 handler
->SetNextHandler(GetEventHandler());
460 SetEventHandler(handler
);
463 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
465 if ( GetEventHandler() )
467 wxEvtHandler
*handlerA
= GetEventHandler();
468 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
469 handlerA
->SetNextHandler(NULL
);
470 SetEventHandler(handlerB
);
483 #if USE_DRAG_AND_DROP
485 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
487 if ( m_pDropTarget
!= 0 ) {
488 delete m_pDropTarget
;
491 m_pDropTarget
= pDropTarget
;
492 if ( m_pDropTarget
!= 0 )
500 // Old style file-manager drag&drop
501 void wxWindow::DragAcceptFiles(bool accept
)
507 void wxWindow::GetSize(int *x
, int *y
) const
515 Widget widget
= (Widget
) GetTopWidget();
517 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
521 void wxWindow::GetPosition(int *x
, int *y
) const
525 CanvasGetPosition(x
, y
);
528 Widget widget
= (Widget
) GetTopWidget();
530 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
534 void wxWindow::ScreenToClient(int *x
, int *y
) const
539 void wxWindow::ClientToScreen(int *x
, int *y
) const
541 Widget widget
= (Widget
) GetClientWidget();
542 Display
*display
= XtDisplay(widget
);
543 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
545 if (this->IsKindOf(CLASSINFO(wxFrame
)))
547 wxFrame
*fr
= (wxFrame
*)this;
549 // thisWindow = XtWindow(fr->m_clientArea);
552 thisWindow
= XtWindow((Widget
)widget
);
557 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
560 void wxWindow::SetCursor(const wxCursor
& cursor
)
562 m_windowCursor
= cursor
;
563 if (m_windowCursor
.Ok())
565 /* TODO when wxCursor implemented
566 WXDisplay *dpy = GetXDisplay();
567 Cursor x_cursor = cursor.GetXCursor(dpy);
569 Widget w = (Widget) GetMainWidget();
570 Window win = XtWindow(w);
571 XDefineCursor((Display*) dpy, win, x_cursor);
577 // Get size *available for subwindows* i.e. excluding menu bar etc.
578 void wxWindow::GetClientSize(int *x
, int *y
) const
580 Widget widget
= (Widget
) GetTopWidget();
582 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
586 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
590 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
593 Widget widget
= (Widget
) GetTopWidget();
597 bool managed
= XtIsManaged( widget
);
599 XtUnmanageChild(widget
);
601 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
602 XtVaSetValues(widget
, XmNx
, x
, NULL
);
603 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
604 XtVaSetValues(widget
, XmNy
, y
, NULL
);
606 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
608 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
611 XtManageChild(widget
);
613 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
614 sizeEvent
.SetEventObject(this);
616 GetEventHandler()->ProcessEvent(sizeEvent
);
619 void wxWindow::SetClientSize(int width
, int height
)
623 CanvasSetClientSize(width
, height
);
627 Widget widget
= (Widget
) GetTopWidget();
630 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
632 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
634 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
635 sizeEvent
.SetEventObject(this);
637 GetEventHandler()->ProcessEvent(sizeEvent
);
640 // For implementation purposes - sometimes decorations make the client area
642 wxPoint
wxWindow::GetClientAreaOrigin() const
644 return wxPoint(0, 0);
647 // Makes an adjustment to the window position (for example, a frame that has
648 // a toolbar that it manages itself).
649 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
651 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
653 wxPoint
pt(GetParent()->GetClientAreaOrigin());
654 x
+= pt
.x
; y
+= pt
.y
;
658 bool wxWindow::Show(bool show
)
662 if (m_borderWidget
|| m_scrolledWindow
)
664 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
668 XtMapWidget((Widget
) GetTopWidget());
673 if (m_borderWidget
|| m_scrolledWindow
)
675 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
679 XtUnmapWidget((Widget
) GetTopWidget());
684 Window xwin = (Window) GetXWindow();
685 Display *xdisp = (Display*) GetXDisplay();
687 XMapWindow(xdisp, xwin);
689 XUnmapWindow(xdisp, xwin);
697 bool wxWindow::IsShown() const
702 int wxWindow::GetCharHeight() const
708 int wxWindow::GetCharWidth() const
714 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
715 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
717 wxFont
*fontToUse
= (wxFont
*)theFont
;
719 fontToUse
= (wxFont
*) & m_windowFont
;
724 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
726 Display
*display
= XtDisplay((Widget
) GetMainWidget());
727 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
729 XExposeEvent dummyEvent
;
731 GetSize(&width
, &height
);
733 dummyEvent
.type
= Expose
;
734 dummyEvent
.display
= display
;
735 dummyEvent
.send_event
= True
;
736 dummyEvent
.window
= thisWindow
;
739 dummyEvent
.x
= rect
->x
;
740 dummyEvent
.y
= rect
->y
;
741 dummyEvent
.width
= rect
->width
;
742 dummyEvent
.height
= rect
->height
;
748 dummyEvent
.width
= width
;
749 dummyEvent
.height
= height
;
751 dummyEvent
.count
= 0;
759 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
762 // Responds to colour changes: passes event on to children.
763 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
765 wxNode
*node
= GetChildren()->First();
768 // Only propagate to non-top-level windows
769 wxWindow
*win
= (wxWindow
*)node
->Data();
770 if ( win
->GetParent() )
772 wxSysColourChangedEvent event2
;
773 event
.m_eventObject
= win
;
774 win
->GetEventHandler()->ProcessEvent(event2
);
781 // This can be called by the app (or wxWindows) to do default processing for the current
782 // event. Save message/event info in wxWindow so they can be used in this function.
783 long wxWindow::Default()
789 void wxWindow::InitDialog()
791 wxInitDialogEvent
event(GetId());
792 event
.SetEventObject( this );
793 GetEventHandler()->ProcessEvent(event
);
796 // Default init dialog behaviour is to transfer data to window
797 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
799 TransferDataToWindow();
802 // Caret manipulation
803 void wxWindow::CreateCaret(int w
, int h
)
807 m_caretEnabled
= TRUE
;
810 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
815 void wxWindow::ShowCaret(bool show
)
820 void wxWindow::DestroyCaret()
823 m_caretEnabled
= FALSE
;
826 void wxWindow::SetCaretPos(int x
, int y
)
831 void wxWindow::GetCaretPos(int *x
, int *y
) const
836 wxWindow
*wxGetActiveWindow()
842 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
849 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
852 wxFrame
*frame
= (wxFrame
*)this;
854 /* Uncomment when wxFrame implemented
856 XtVaSetValues((Widget) frame->m_frameShell, XmNminWidth, minW, NULL);
858 XtVaSetValues((Widget) frame->m_frameShell, XmNminHeight, minH, NULL);
860 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxWidth, maxW, NULL);
862 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxHeight, maxH, NULL);
864 XtVaSetValues((Widget) frame->m_frameShell, XmNwidthInc, incW, NULL);
866 XtVaSetValues((Widget) frame->m_frameShell, XmNheightInc, incH, NULL);
870 void wxWindow::Centre(int direction
)
872 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
874 wxWindow
*father
= (wxWindow
*)GetParent();
878 father
->GetClientSize(&panel_width
, &panel_height
);
879 GetSize(&width
, &height
);
885 if (direction
& wxHORIZONTAL
)
886 new_x
= (int)((panel_width
- width
)/2);
888 if (direction
& wxVERTICAL
)
889 new_y
= (int)((panel_height
- height
)/2);
891 SetSize(new_x
, new_y
, -1, -1);
895 // Coordinates relative to the window
896 void wxWindow::WarpPointer (int x
, int y
)
898 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
901 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
907 int wxWindow::GetScrollPos(int orient
) const
913 // This now returns the whole range, not just the number
914 // of positions that we can scroll.
915 int wxWindow::GetScrollRange(int orient
) const
921 int wxWindow::GetScrollThumb(int orient
) const
927 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
933 // New function that will replace some of the above.
934 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
935 int range
, bool refresh
)
940 // Does a physical scroll
941 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
947 void wxWindow::SetFont(const wxFont
& font
)
951 if (!m_windowFont
.Ok())
956 void wxWindow::OnChar(wxKeyEvent
& event
)
958 if ( event
.KeyCode() == WXK_TAB
) {
959 // propagate the TABs to the parent - it's up to it to decide what
962 if ( GetParent()->ProcessEvent(event
) )
968 void wxWindow::OnPaint(wxPaintEvent
& event
)
973 bool wxWindow::IsEnabled() const
979 // Dialog support: override these and call
980 // base class members to add functionality
981 // that can't be done using validators.
982 // NOTE: these functions assume that controls
983 // are direct children of this window, not grandchildren
984 // or other levels of descendant.
986 // Transfer values to controls. If returns FALSE,
987 // it's an application error (pops up a dialog)
988 bool wxWindow::TransferDataToWindow()
990 wxNode
*node
= GetChildren()->First();
993 wxWindow
*child
= (wxWindow
*)node
->Data();
994 if ( child
->GetValidator() &&
995 !child
->GetValidator()->TransferToWindow() )
997 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
1001 node
= node
->Next();
1006 // Transfer values from controls. If returns FALSE,
1007 // validation failed: don't quit
1008 bool wxWindow::TransferDataFromWindow()
1010 wxNode
*node
= GetChildren()->First();
1013 wxWindow
*child
= (wxWindow
*)node
->Data();
1014 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1019 node
= node
->Next();
1024 bool wxWindow::Validate()
1026 wxNode
*node
= GetChildren()->First();
1029 wxWindow
*child
= (wxWindow
*)node
->Data();
1030 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1035 node
= node
->Next();
1040 // Get the window with the focus
1041 wxWindow
*wxWindow::FindFocus()
1047 void wxWindow::AddChild(wxWindow
*child
)
1049 GetChildren()->Append(child
);
1050 child
->m_windowParent
= this;
1053 void wxWindow::RemoveChild(wxWindow
*child
)
1056 GetChildren()->DeleteObject(child
);
1057 child
->m_windowParent
= NULL
;
1060 void wxWindow::DestroyChildren()
1062 if (GetChildren()) {
1064 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1066 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1068 if ( GetChildren()->Member(child
) )
1075 void wxWindow::MakeModal(bool modal
)
1077 // Disable all other windows
1078 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1080 wxNode
*node
= wxTopLevelWindows
.First();
1083 wxWindow
*win
= (wxWindow
*)node
->Data();
1085 win
->Enable(!modal
);
1087 node
= node
->Next();
1092 // If nothing defined for this, try the parent.
1093 // E.g. we may be a button loaded from a resource, with no callback function
1095 void wxWindow::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
1097 if (GetEventHandler()->ProcessEvent(event
) )
1100 m_windowParent
->GetEventHandler()->OnCommand(win
, event
);
1103 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1107 UnsetConstraints(m_constraints
);
1108 delete m_constraints
;
1113 // Make sure other windows know they're part of a 'meaningful relationship'
1114 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1115 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1116 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1117 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1118 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1119 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1120 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1121 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1122 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1123 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1124 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1125 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1126 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1127 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1128 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1129 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1133 // This removes any dangling pointers to this window
1134 // in other windows' constraintsInvolvedIn lists.
1135 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1139 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1140 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1141 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1142 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1143 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1144 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1145 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1146 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1147 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1148 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1149 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1150 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1151 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1152 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1153 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1154 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1158 // Back-pointer to other windows we're involved with, so if we delete
1159 // this window, we must delete any constraints we're involved with.
1160 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1162 if (!m_constraintsInvolvedIn
)
1163 m_constraintsInvolvedIn
= new wxList
;
1164 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1165 m_constraintsInvolvedIn
->Append(otherWin
);
1168 // REMOVE back-pointer to other windows we're involved with.
1169 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1171 if (m_constraintsInvolvedIn
)
1172 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1175 // Reset any constraints that mention this window
1176 void wxWindow::DeleteRelatedConstraints()
1178 if (m_constraintsInvolvedIn
)
1180 wxNode
*node
= m_constraintsInvolvedIn
->First();
1183 wxWindow
*win
= (wxWindow
*)node
->Data();
1184 wxNode
*next
= node
->Next();
1185 wxLayoutConstraints
*constr
= win
->GetConstraints();
1187 // Reset any constraints involving this window
1190 constr
->left
.ResetIfWin((wxWindow
*)this);
1191 constr
->top
.ResetIfWin((wxWindow
*)this);
1192 constr
->right
.ResetIfWin((wxWindow
*)this);
1193 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1194 constr
->width
.ResetIfWin((wxWindow
*)this);
1195 constr
->height
.ResetIfWin((wxWindow
*)this);
1196 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1197 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1202 delete m_constraintsInvolvedIn
;
1203 m_constraintsInvolvedIn
= NULL
;
1207 void wxWindow::SetSizer(wxSizer
*sizer
)
1209 m_windowSizer
= sizer
;
1211 sizer
->SetSizerParent((wxWindow
*)this);
1218 bool wxWindow::Layout()
1220 if (GetConstraints())
1223 GetClientSize(&w
, &h
);
1224 GetConstraints()->width
.SetValue(w
);
1225 GetConstraints()->height
.SetValue(h
);
1228 // If top level (one sizer), evaluate the sizer's constraints.
1232 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1233 GetSizer()->LayoutPhase1(&noChanges
);
1234 GetSizer()->LayoutPhase2(&noChanges
);
1235 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1240 // Otherwise, evaluate child constraints
1241 ResetConstraints(); // Mark all constraints as unevaluated
1242 DoPhase(1); // Just one phase need if no sizers involved
1244 SetConstraintSizes(); // Recursively set the real window sizes
1250 // Do a phase of evaluating constraints:
1251 // the default behaviour. wxSizers may do a similar
1252 // thing, but also impose their own 'constraints'
1253 // and order the evaluation differently.
1254 bool wxWindow::LayoutPhase1(int *noChanges
)
1256 wxLayoutConstraints
*constr
= GetConstraints();
1259 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1265 bool wxWindow::LayoutPhase2(int *noChanges
)
1275 // Do a phase of evaluating child constraints
1276 bool wxWindow::DoPhase(int phase
)
1278 int noIterations
= 0;
1279 int maxIterations
= 500;
1283 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1287 wxNode
*node
= GetChildren()->First();
1290 wxWindow
*child
= (wxWindow
*)node
->Data();
1291 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1293 wxLayoutConstraints
*constr
= child
->GetConstraints();
1296 if (succeeded
.Member(child
))
1301 int tempNoChanges
= 0;
1302 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1303 noChanges
+= tempNoChanges
;
1306 succeeded
.Append(child
);
1311 node
= node
->Next();
1318 void wxWindow::ResetConstraints()
1320 wxLayoutConstraints
*constr
= GetConstraints();
1323 constr
->left
.SetDone(FALSE
);
1324 constr
->top
.SetDone(FALSE
);
1325 constr
->right
.SetDone(FALSE
);
1326 constr
->bottom
.SetDone(FALSE
);
1327 constr
->width
.SetDone(FALSE
);
1328 constr
->height
.SetDone(FALSE
);
1329 constr
->centreX
.SetDone(FALSE
);
1330 constr
->centreY
.SetDone(FALSE
);
1332 wxNode
*node
= GetChildren()->First();
1335 wxWindow
*win
= (wxWindow
*)node
->Data();
1336 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1337 win
->ResetConstraints();
1338 node
= node
->Next();
1342 // Need to distinguish between setting the 'fake' size for
1343 // windows and sizers, and setting the real values.
1344 void wxWindow::SetConstraintSizes(bool recurse
)
1346 wxLayoutConstraints
*constr
= GetConstraints();
1347 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1348 constr
->width
.GetDone() && constr
->height
.GetDone())
1350 int x
= constr
->left
.GetValue();
1351 int y
= constr
->top
.GetValue();
1352 int w
= constr
->width
.GetValue();
1353 int h
= constr
->height
.GetValue();
1355 // If we don't want to resize this window, just move it...
1356 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1357 (constr
->height
.GetRelationship() != wxAsIs
))
1359 // Calls Layout() recursively. AAAGH. How can we stop that.
1360 // Simply take Layout() out of non-top level OnSizes.
1361 SizerSetSize(x
, y
, w
, h
);
1370 char *windowClass
= this->GetClassInfo()->GetClassName();
1373 if (GetName() == "")
1374 winName
= "unnamed";
1376 winName
= GetName();
1377 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1378 if (!constr
->left
.GetDone())
1379 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1380 if (!constr
->right
.GetDone())
1381 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1382 if (!constr
->width
.GetDone())
1383 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1384 if (!constr
->height
.GetDone())
1385 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1386 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1391 wxNode
*node
= GetChildren()->First();
1394 wxWindow
*win
= (wxWindow
*)node
->Data();
1395 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1396 win
->SetConstraintSizes();
1397 node
= node
->Next();
1402 // This assumes that all sizers are 'on' the same
1403 // window, i.e. the parent of this window.
1404 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1406 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1407 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1411 m_sizerParent
->GetPosition(&xp
, &yp
);
1412 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1417 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1421 TransformSizerToActual(&xx
, &yy
);
1422 SetSize(xx
, yy
, w
, h
);
1425 void wxWindow::SizerMove(int x
, int y
)
1429 TransformSizerToActual(&xx
, &yy
);
1433 // Only set the size/position of the constraint (if any)
1434 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1436 wxLayoutConstraints
*constr
= GetConstraints();
1441 constr
->left
.SetValue(x
);
1442 constr
->left
.SetDone(TRUE
);
1446 constr
->top
.SetValue(y
);
1447 constr
->top
.SetDone(TRUE
);
1451 constr
->width
.SetValue(w
);
1452 constr
->width
.SetDone(TRUE
);
1456 constr
->height
.SetValue(h
);
1457 constr
->height
.SetDone(TRUE
);
1462 void wxWindow::MoveConstraint(int x
, int y
)
1464 wxLayoutConstraints
*constr
= GetConstraints();
1469 constr
->left
.SetValue(x
);
1470 constr
->left
.SetDone(TRUE
);
1474 constr
->top
.SetValue(y
);
1475 constr
->top
.SetDone(TRUE
);
1480 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1482 wxLayoutConstraints
*constr
= GetConstraints();
1485 *w
= constr
->width
.GetValue();
1486 *h
= constr
->height
.GetValue();
1492 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1494 wxLayoutConstraints
*constr
= GetConstraints();
1497 *w
= constr
->width
.GetValue();
1498 *h
= constr
->height
.GetValue();
1501 GetClientSize(w
, h
);
1504 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1506 wxLayoutConstraints
*constr
= GetConstraints();
1509 *x
= constr
->left
.GetValue();
1510 *y
= constr
->top
.GetValue();
1516 bool wxWindow::Close(bool force
)
1518 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1519 event
.SetEventObject(this);
1520 event
.SetForce(force
);
1522 return GetEventHandler()->ProcessEvent(event
);
1525 wxObject
* wxWindow::GetChild(int number
) const
1527 // Return a pointer to the Nth object in the window
1530 wxNode
*node
= GetChildren()->First();
1533 node
= node
->Next() ;
1536 wxObject
*obj
= (wxObject
*)node
->Data();
1543 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1545 // Obsolete function
1548 void wxWindow::Clear()
1550 wxClientDC
dc(this);
1551 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1552 dc
.SetBackground(brush
);
1556 // Fits the panel around the items
1557 void wxWindow::Fit()
1561 wxNode
*node
= GetChildren()->First();
1564 wxWindow
*win
= (wxWindow
*)node
->Data();
1566 win
->GetPosition(&wx
, &wy
);
1567 win
->GetSize(&ww
, &wh
);
1568 if ( wx
+ ww
> maxX
)
1570 if ( wy
+ wh
> maxY
)
1573 node
= node
->Next();
1575 SetClientSize(maxX
+ 5, maxY
+ 5);
1578 void wxWindow::SetValidator(const wxValidator
& validator
)
1580 if ( m_windowValidator
)
1581 delete m_windowValidator
;
1582 m_windowValidator
= validator
.Clone();
1584 if ( m_windowValidator
)
1585 m_windowValidator
->SetWindow(this) ;
1588 // Find a window by id or name
1589 wxWindow
*wxWindow::FindWindow(long id
)
1594 wxNode
*node
= GetChildren()->First();
1597 wxWindow
*child
= (wxWindow
*)node
->Data();
1598 wxWindow
*found
= child
->FindWindow(id
);
1601 node
= node
->Next();
1606 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1608 if ( GetName() == name
)
1611 wxNode
*node
= GetChildren()->First();
1614 wxWindow
*child
= (wxWindow
*)node
->Data();
1615 wxWindow
*found
= child
->FindWindow(name
);
1618 node
= node
->Next();
1623 void wxWindow::OnIdle(wxIdleEvent
& event
)
1625 /* TODO: you may need to do something like this
1626 * if your GUI doesn't generate enter/leave events
1628 // Check if we need to send a LEAVE event
1629 if (m_mouseInWindow)
1632 ::GetCursorPos(&pt);
1633 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1635 // Generate a LEAVE event
1636 m_mouseInWindow = FALSE;
1637 MSWOnMouseLeave(pt.x, pt.y, 0);
1642 // This calls the UI-update mechanism (querying windows for
1643 // menu/toolbar/control state information)
1647 // Raise the window to the top of the Z order
1648 void wxWindow::Raise()
1650 Window window
= XtWindow((Widget
) GetTopWidget());
1651 XRaiseWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1654 // Lower the window to the bottom of the Z order
1655 void wxWindow::Lower()
1657 Window window
= XtWindow((Widget
) GetTopWidget());
1658 XLowerWindow(XtDisplay((Widget
) GetTopWidget()), window
);
1661 bool wxWindow::AcceptsFocus() const
1663 return IsShown() && IsEnabled();
1666 // Update region access
1667 wxRegion
wxWindow::GetUpdateRegion() const
1669 return m_updateRegion
;
1672 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1674 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1677 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1679 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1682 bool wxWindow::IsExposed(const wxRect
& rect
) const
1684 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1688 * Allocates control IDs
1691 int wxWindow::NewControlId()
1693 static int s_controlId
= 0;
1698 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1700 m_acceleratorTable
= accel
;
1703 // All widgets should have this as their resize proc.
1704 // OnSize sent to wxWindow via client data.
1705 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1707 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
1711 if (win
->PreResize())
1714 win
->GetSize(&width
, &height
);
1715 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1716 sizeEvent
.SetEventObject(win
);
1717 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1721 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1723 wxWindow
*oldItem
= NULL
;
1725 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
1727 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1730 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
1733 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
1738 wxWidgetHashTable
->Put ((long) w
, win
);
1742 wxWindow
*wxGetWindowFromTable(Widget w
)
1744 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
1747 void wxDeleteWindowFromTable(Widget w
)
1749 wxWidgetHashTable
->Delete((long)w
);
1752 // Get the underlying X window and display
1753 WXWindow
wxWindow::GetXWindow() const
1755 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
1758 WXDisplay
*wxWindow::GetXDisplay() const
1760 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
1763 WXWidget
wxWindow::GetMainWidget() const
1766 return m_drawingArea
;
1768 return m_mainWidget
;
1771 WXWidget
wxWindow::GetClientWidget() const
1773 if (m_drawingArea
!= (WXWidget
) 0)
1774 return m_drawingArea
;
1776 return GetMainWidget();
1779 WXWidget
wxWindow::GetTopWidget() const
1781 return GetMainWidget();
1784 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
1785 XmDrawingAreaCallbackStruct
* cbs
)
1787 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
1790 XEvent
* event
= cbs
->event
;
1791 wxWindow
* canvas
= (wxWindow
*) clientData
;
1792 Display
* display
= (Display
*) canvas
->GetXDisplay();
1793 // GC gc = (GC) canvas->GetDC()->gc;
1795 switch (event
->type
)
1800 wxCanvasDC* canvasDC = canvas->GetDC();
1803 if (canvasDC->onpaint_reg)
1804 XDestroyRegion(canvasDC->onpaint_reg);
1805 canvasDC->onpaint_reg = XCreateRegion();
1810 int n
= canvas
->m_updateRects
.Number();
1811 XRectangle
* xrects
= new XRectangle
[n
];
1813 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
1815 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
1816 xrects
[i
].x
= rect
->x
;
1817 xrects
[i
].y
= rect
->y
;
1818 xrects
[i
].width
= rect
->width
;
1819 xrects
[i
].height
= rect
->height
;
1820 /* TODO (?) Actually ignore it I think.
1822 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
1823 canvasDC->onpaint_reg);
1826 /* TODO must clip the area being repainted. So we need a gc.
1827 * Alternatively, wxPaintDC must do the clipping
1828 * when it's created.
1829 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
1832 canvas
->DoPaint() ; // xrects, n);
1835 canvas
->m_updateRects
.Clear();
1840 XDestroyRegion(canvasDC->onpaint_reg);
1841 canvasDC->onpaint_reg = NULL;
1845 gc_val.clip_mask = None;
1846 XChangeGC(display, gc, GCClipMask, &gc_val);
1853 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
1859 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1861 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
1863 XmDrawingAreaCallbackStruct cbs
;
1866 //if (event->mode!=NotifyNormal)
1869 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
1870 ((XCrossingEvent
&) ev
) = *event
;
1872 cbs
.reason
= XmCR_INPUT
;
1875 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1878 // Fix to make it work under Motif 1.0 (!)
1879 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1883 XmDrawingAreaCallbackStruct cbs
;
1886 //ev.xbutton = *event;
1887 ev
= *((XEvent
*) event
);
1888 cbs
.reason
= XmCR_INPUT
;
1891 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1895 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
1897 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
1903 if (cbs
->reason
!= XmCR_INPUT
)
1906 local_event
= *(cbs
->event
); // We must keep a copy!
1908 switch (local_event
.xany
.type
)
1916 wxEventType eventType
= wxEVT_NULL
;
1918 if (local_event
.xany
.type
== EnterNotify
)
1920 //if (local_event.xcrossing.mode!=NotifyNormal)
1921 // return ; // Ignore grab events
1922 eventType
= wxEVT_ENTER_WINDOW
;
1923 // canvas->GetEventHandler()->OnSetFocus();
1925 else if (local_event
.xany
.type
== LeaveNotify
)
1927 //if (local_event.xcrossing.mode!=NotifyNormal)
1928 // return ; // Ignore grab events
1929 eventType
= wxEVT_LEAVE_WINDOW
;
1930 // canvas->GetEventHandler()->OnKillFocus();
1932 else if (local_event
.xany
.type
== MotionNotify
)
1934 eventType
= wxEVT_MOTION
;
1935 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1938 Display
*dpy
= XtDisplay (drawingArea
);
1940 XQueryPointer (dpy
, XtWindow (drawingArea
),
1942 &local_event
.xmotion
.x_root
,
1943 &local_event
.xmotion
.y_root
,
1944 &local_event
.xmotion
.x
,
1945 &local_event
.xmotion
.y
,
1946 &local_event
.xmotion
.state
);
1953 else if (local_event
.xany
.type
== ButtonPress
)
1955 if (local_event
.xbutton
.button
== Button1
)
1957 eventType
= wxEVT_LEFT_DOWN
;
1958 canvas
->m_button1Pressed
= TRUE
;
1960 else if (local_event
.xbutton
.button
== Button2
)
1962 eventType
= wxEVT_MIDDLE_DOWN
;
1963 canvas
->m_button2Pressed
= TRUE
;
1965 else if (local_event
.xbutton
.button
== Button3
)
1967 eventType
= wxEVT_RIGHT_DOWN
;
1968 canvas
->m_button3Pressed
= TRUE
;
1971 else if (local_event
.xany
.type
== ButtonRelease
)
1973 if (local_event
.xbutton
.button
== Button1
)
1975 eventType
= wxEVT_LEFT_UP
;
1976 canvas
->m_button1Pressed
= FALSE
;
1978 else if (local_event
.xbutton
.button
== Button2
)
1980 eventType
= wxEVT_MIDDLE_UP
;
1981 canvas
->m_button2Pressed
= FALSE
;
1983 else if (local_event
.xbutton
.button
== Button3
)
1985 eventType
= wxEVT_RIGHT_UP
;
1986 canvas
->m_button3Pressed
= FALSE
;
1990 wxMouseEvent
wxevent (eventType
);
1991 wxevent
.m_eventHandle
= (char *) &local_event
;
1993 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1994 || (event_left_is_down (&local_event
)
1995 && (eventType
!= wxEVT_LEFT_UP
)));
1996 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1997 || (event_middle_is_down (&local_event
)
1998 && (eventType
!= wxEVT_MIDDLE_UP
)));
1999 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2000 || (event_right_is_down (&local_event
)
2001 && (eventType
!= wxEVT_RIGHT_UP
)));
2003 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
2004 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
2005 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
2006 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
2007 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
2009 // Now check if we need to translate this event into a double click
2010 if (TRUE
) // canvas->doubleClickAllowed)
2012 if (wxevent
.ButtonDown())
2014 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
2016 // get button and time-stamp
2018 if (wxevent
.LeftDown()) button
= 1;
2019 else if (wxevent
.MiddleDown()) button
= 2;
2020 else if (wxevent
.RightDown()) button
= 3;
2021 long ts
= wxevent
.GetTimestamp();
2022 // check, if single or double click
2023 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
2026 canvas
->m_lastButton
= 0;
2027 switch ( eventType
)
2029 case wxEVT_LEFT_DOWN
:
2030 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2032 case wxEVT_MIDDLE_DOWN
:
2033 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2035 case wxEVT_RIGHT_DOWN
:
2036 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2046 // not fast enough or different button
2047 canvas
->m_lastTS
= ts
;
2048 canvas
->m_lastButton
= button
;
2053 wxevent
.SetId(canvas
->GetId());
2054 wxevent
.SetEventObject(canvas
);
2055 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2057 if (eventType == wxEVT_ENTER_WINDOW ||
2058 eventType == wxEVT_LEAVE_WINDOW ||
2059 eventType == wxEVT_MOTION
2068 // XComposeStatus compose;
2069 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2070 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2071 int id
= wxCharCodeXToWX (keySym
);
2073 wxKeyEvent
event (wxEVT_CHAR
);
2075 if (local_event
.xkey
.state
& ShiftMask
)
2076 event
.m_shiftDown
= TRUE
;
2077 if (local_event
.xkey
.state
& ControlMask
)
2078 event
.m_controlDown
= TRUE
;
2079 if (local_event
.xkey
.state
& Mod3Mask
)
2080 event
.m_altDown
= TRUE
;
2081 if (local_event
.xkey
.state
& Mod1Mask
)
2082 event
.m_metaDown
= TRUE
;
2083 event
.SetEventObject(canvas
);
2084 event
.m_keyCode
= id
;
2085 event
.SetTimestamp(local_event
.xkey
.time
);
2089 // Implement wxFrame::OnCharHook by checking ancestor.
2090 wxWindow
*parent
= canvas
->GetParent();
2091 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2092 parent
= parent
->GetParent();
2096 event
.SetEventType(wxEVT_CHAR_HOOK
);
2097 if (parent
->GetEventHandler()->ProcessEvent(event
))
2099 event
.SetEventType(wxEVT_CHAR
);
2102 canvas
->GetEventHandler()->ProcessEvent (event
);
2108 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2110 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2111 event
.SetEventObject(canvas
);
2112 canvas
->GetEventHandler()->ProcessEvent(event
);
2118 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2120 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2121 event
.SetEventObject(canvas
);
2122 canvas
->GetEventHandler()->ProcessEvent(event
);
2131 void wxWindow::DoPaint()
2133 //TODO : make a temporary gc so we can do the XCopyArea below
2134 if (0) // m_backingPixmap)
2137 Widget drawingArea = (Widget) m_drawingArea;
2138 // int orig = GetDC()->GetLogicalFunction();
2139 // GetDC()->SetLogicalFunction (wxCOPY);
2141 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2142 // should be able to calculate them.
2143 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2144 m_pixmapOffsetX, m_pixmapOffsetY,
2145 m_pixmapWidth, m_pixmapHeight,
2148 // GetDC()->SetLogicalFunction (orig);
2153 wxPaintEvent
event(GetId());
2154 event
.SetEventObject(this);
2155 GetEventHandler()->ProcessEvent(event
);
2159 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2160 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2162 Widget drawingArea
= (Widget
) m_drawingArea
;
2163 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2166 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2167 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2169 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2171 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2175 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2177 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2185 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2186 short thick
, margin
;
2187 XtVaGetValues ((Widget
) m_borderWidget
,
2188 XmNshadowThickness
, &thick
,
2189 XmNmarginWidth
, &margin
,
2191 w
-= 2 * (thick
+ margin
);
2194 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2198 XtVaGetValues ((Widget
) m_scrolledWindow
,
2199 XmNspacing
, &spacing
,
2200 XmNverticalScrollBar
, &sbar
,
2204 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2208 w
-= (spacing
+ wsbar
);
2210 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2216 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2217 short thick
, margin
;
2218 XtVaGetValues ((Widget
) m_borderWidget
,
2219 XmNshadowThickness
, &thick
,
2220 XmNmarginHeight
, &margin
,
2222 h
-= 2 * (thick
+ margin
);
2225 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2229 XtVaGetValues ((Widget
) m_scrolledWindow
,
2230 XmNspacing
, &spacing
,
2231 XmNhorizontalScrollBar
, &sbar
,
2235 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2239 h
-= (spacing
+ wsbar
);
2241 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2244 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2245 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2248 GetClientSize (&ww
, &hh
);
2249 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2250 sizeEvent
.SetEventObject(this);
2252 GetEventHandler()->ProcessEvent(sizeEvent
);
2255 void wxWindow::CanvasSetClientSize (int w
, int h
)
2257 Widget drawingArea
= (Widget
) m_drawingArea
;
2259 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2262 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2264 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2265 /* TODO: is this necessary?
2266 allowRepainting = FALSE;
2268 XSync (XtDisplay (drawingArea), FALSE);
2270 while (XtAppPending (wxTheApp->appContext))
2272 XFlush (XtDisplay (drawingArea));
2273 XtAppNextEvent (wxTheApp->appContext, &event);
2274 XtDispatchEvent (&event);
2278 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2281 allowRepainting = TRUE;
2285 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2286 sizeEvent
.SetEventObject(this);
2288 GetEventHandler()->ProcessEvent(sizeEvent
);
2291 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2293 // Must return the same thing that was set via SetClientSize
2295 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2300 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2303 if ((Widget
) m_borderWidget
)
2304 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2305 else if ((Widget
) m_scrolledWindow
)
2306 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2308 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2314 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2317 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
2322 // Add to hash table, add event handler
2323 bool wxWindow::AttachWidget (wxWindow
* parent
, WXWidget mainWidget
,
2324 WXWidget formWidget
, int x
, int y
, int width
, int height
)
2326 wxAddWindowToTable((Widget
) mainWidget
, this);
2327 if (CanAddEventHandler())
2329 XtAddEventHandler((Widget
) mainWidget
,
2330 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2332 wxPanelItemEventHandler
,
2339 XtOverrideTranslations ((Widget
) mainWidget
,
2340 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2341 XtFree ((char *) ptr
);
2344 // Some widgets have a parent form widget, e.g. wxRadioBox
2347 if (!wxAddWindowToTable((Widget
) formWidget
, this))
2351 XtOverrideTranslations ((Widget
) formWidget
,
2352 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
2353 XtFree ((char *) ptr
);
2360 SetSize (x
, y
, width
, height
);
2365 // Remove event handler, remove from hash table
2366 bool wxWindow::DetachWidget(WXWidget widget
)
2368 if (CanAddEventHandler())
2370 XtRemoveEventHandler((Widget
) widget
,
2371 ButtonPressMask
| ButtonReleaseMask
| PointerMotionMask
, // | KeyPressMask,
2373 wxPanelItemEventHandler
,
2377 wxDeleteWindowFromTable((Widget
) widget
);
2381 void wxPanelItemEventHandler (Widget wid
,
2382 XtPointer client_data
,
2384 Boolean
*continueToDispatch
)
2386 // Widget can be a label or the actual widget.
2388 wxWindow
*window
= (wxWindow
*)wxWidgetHashTable
->Get((long)wid
);
2391 wxMouseEvent
wxevent(0);
2392 if (wxTranslateMouseEvent(wxevent
, window
, wid
, event
))
2394 window
->GetEventHandler()->ProcessEvent(wxevent
);
2397 // TODO: probably the key to allowing default behaviour
2399 // Say we set a m_doDefault flag to FALSE at the start of this
2400 // function. Then in e.g. wxWindow::OnMouseEvent we can
2401 // call Default() which sets this flag to TRUE, indicating
2402 // that default processing can happen. Thus, behaviour can appear
2403 // to be overridden just by adding an event handler and not calling
2404 // wxWindow::OnWhatever.
2405 // ALSO, maybe we can use this instead of the current way of handling
2406 // drawing area events, to simplify things.
2407 *continueToDispatch
= True
;
2410 bool wxTranslateMouseEvent(wxMouseEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2412 switch (xevent
->xany
.type
)
2420 wxEventType eventType
= wxEVT_NULL
;
2422 if (xevent
->xany
.type
== LeaveNotify
)
2424 win
->m_button1Pressed
= FALSE
;
2425 win
->m_button2Pressed
= FALSE
;
2426 win
->m_button3Pressed
= FALSE
;
2429 else if (xevent
->xany
.type
== MotionNotify
)
2431 eventType
= wxEVT_MOTION
;
2433 else if (xevent
->xany
.type
== ButtonPress
)
2435 if (xevent
->xbutton
.button
== Button1
)
2437 eventType
= wxEVT_LEFT_DOWN
;
2438 win
->m_button1Pressed
= TRUE
;
2440 else if (xevent
->xbutton
.button
== Button2
)
2442 eventType
= wxEVT_MIDDLE_DOWN
;
2443 win
->m_button2Pressed
= TRUE
;
2445 else if (xevent
->xbutton
.button
== Button3
)
2447 eventType
= wxEVT_RIGHT_DOWN
;
2448 win
->m_button3Pressed
= TRUE
;
2451 else if (xevent
->xany
.type
== ButtonRelease
)
2453 if (xevent
->xbutton
.button
== Button1
)
2455 eventType
= wxEVT_LEFT_UP
;
2456 win
->m_button1Pressed
= FALSE
;
2458 else if (xevent
->xbutton
.button
== Button2
)
2460 eventType
= wxEVT_MIDDLE_UP
;
2461 win
->m_button2Pressed
= FALSE
;
2463 else if (xevent
->xbutton
.button
== Button3
)
2465 eventType
= wxEVT_RIGHT_UP
;
2466 win
->m_button3Pressed
= FALSE
;
2472 wxevent
.m_eventHandle
= (char *)xevent
;
2473 wxevent
.SetEventType(eventType
);
2476 XtVaGetValues(widget
, XmNx
, &x1
, XmNy
, &y1
, NULL
);
2479 win
->GetPosition(&x2
, &y2
);
2481 // The button x/y must be translated to wxWindows
2482 // window space - the widget might be a label or button,
2486 if (widget
!= (Widget
)win
->GetMainWidget())
2492 wxevent
.m_x
= xevent
->xbutton
.x
+ dx
;
2493 wxevent
.m_y
= xevent
->xbutton
.y
+ dy
;
2495 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
2496 || (event_left_is_down (xevent
)
2497 && (eventType
!= wxEVT_LEFT_UP
)));
2498 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
2499 || (event_middle_is_down (xevent
)
2500 && (eventType
!= wxEVT_MIDDLE_UP
)));
2501 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
2502 || (event_right_is_down (xevent
)
2503 && (eventType
!= wxEVT_RIGHT_UP
)));
2505 wxevent
.m_shiftDown
= xevent
->xbutton
.state
& ShiftMask
;
2506 wxevent
.m_controlDown
= xevent
->xbutton
.state
& ControlMask
;
2513 bool wxTranslateKeyEvent(wxKeyEvent
& wxevent
, wxWindow
*win
, Widget widget
, XEvent
*xevent
)
2515 switch (xevent
->xany
.type
)
2522 // XComposeStatus compose;
2523 // (void) XLookupString ((XKeyEvent *) xevent, buf, 20, &keySym, &compose);
2524 (void) XLookupString ((XKeyEvent
*) xevent
, buf
, 20, &keySym
, NULL
);
2525 int id
= wxCharCodeXToWX (keySym
);
2527 if (xevent
->xkey
.state
& ShiftMask
)
2528 wxevent
.m_shiftDown
= TRUE
;
2529 if (xevent
->xkey
.state
& ControlMask
)
2530 wxevent
.m_controlDown
= TRUE
;
2531 if (xevent
->xkey
.state
& Mod3Mask
)
2532 wxevent
.m_altDown
= TRUE
;
2533 if (xevent
->xkey
.state
& Mod1Mask
)
2534 wxevent
.m_metaDown
= TRUE
;
2535 wxevent
.SetEventObject(win
);
2536 wxevent
.m_keyCode
= id
;
2537 wxevent
.SetTimestamp(xevent
->xkey
.time
);
2539 wxevent
.m_x
= xevent
->xbutton
.x
;
2540 wxevent
.m_y
= xevent
->xbutton
.y
;
2554 // TODO From wxWin 1.68. What does it do exactly?
2555 #define YAllocColor XAllocColor
2557 XColor itemColors
[5];
2558 int wxComputeColors (Display
*display
, wxColour
* back
, wxColour
* fore
)
2561 static XmColorProc colorProc
;
2563 result
= wxNO_COLORS
;
2567 itemColors
[0].red
= (((long) back
->Red ()) << 8);
2568 itemColors
[0].green
= (((long) back
->Green ()) << 8);
2569 itemColors
[0].blue
= (((long) back
->Blue ()) << 8);
2570 itemColors
[0].flags
= DoRed
| DoGreen
| DoBlue
;
2571 if (colorProc
== (XmColorProc
) NULL
)
2573 // Get a ptr to the actual function
2574 colorProc
= XmSetColorCalculation ((XmColorProc
) NULL
);
2575 // And set it back to motif.
2576 XmSetColorCalculation (colorProc
);
2578 (*colorProc
) (&itemColors
[wxBACK_INDEX
],
2579 &itemColors
[wxFORE_INDEX
],
2580 &itemColors
[wxSELE_INDEX
],
2581 &itemColors
[wxTOPS_INDEX
],
2582 &itemColors
[wxBOTS_INDEX
]);
2583 result
= wxBACK_COLORS
;
2587 itemColors
[wxFORE_INDEX
].red
= (((long) fore
->Red ()) << 8);
2588 itemColors
[wxFORE_INDEX
].green
= (((long) fore
->Green ()) << 8);
2589 itemColors
[wxFORE_INDEX
].blue
= (((long) fore
->Blue ()) << 8);
2590 itemColors
[wxFORE_INDEX
].flags
= DoRed
| DoGreen
| DoBlue
;
2591 if (result
== wxNO_COLORS
)
2592 result
= wxFORE_COLORS
;
2595 Display
*dpy
= display
;
2596 Colormap cmap
= (Colormap
) wxTheApp
->GetMainColormap((WXDisplay
*) dpy
);
2600 /* 5 Colours to allocate */
2601 for (int i
= 0; i
< 5; i
++)
2602 if (!YAllocColor (dpy
, cmap
, &itemColors
[i
]))
2603 result
= wxNO_COLORS
;
2607 /* Only 1 colour to allocate */
2608 if (!YAllocColor (dpy
, cmap
, &itemColors
[wxFORE_INDEX
]))
2609 result
= wxNO_COLORS
;
2616 void wxWindow::ChangeColour(WXWidget widget
)
2622 // TODO: how to determine whether we can change this item's colours?
2623 // We used to have wxUSER_COLOURS. Now perhaps we assume we always
2625 // if (!(parent->GetWindowStyleFlag() & wxUSER_COLOURS))
2628 change
= wxComputeColors (XtDisplay((Widget
)widget
), panel
->GetBackgroundColour(),
2629 panel
->GetLabelColour());
2630 if (change
== wxBACK_COLORS
)
2631 XtVaSetValues ((Widget
) widget
,
2632 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2633 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2634 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2635 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2637 else if (change
== wxFORE_COLORS
)
2638 XtVaSetValues (formWidget
,
2639 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2642 change
= wxComputeColors (XtDisplay((Widget
)formWidget
), GetBackgroundColour(), GetLabelColour());
2643 if (change
== wxBACK_COLORS
)
2644 XtVaSetValues (labelWidget
,
2645 XmNbackground
, itemColors
[wxBACK_INDEX
].pixel
,
2646 XmNtopShadowColor
, itemColors
[wxTOPS_INDEX
].pixel
,
2647 XmNbottomShadowColor
, itemColors
[wxBOTS_INDEX
].pixel
,
2648 XmNarmColor
, itemColors
[wxSELE_INDEX
].pixel
,
2649 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2651 else if (change
== wxFORE_COLORS
)
2652 XtVaSetValues (labelWidget
,
2653 XmNforeground
, itemColors
[wxFORE_INDEX
].pixel
,
2658 void wxWindow::ChangeFont(WXWidget widget
)
2661 if (widget && GetFont() && GetFont()->IsOk())
2662 XtVaSetValues ((Widget) widget,
2663 XmNfontList, GetFont()->GetInternalFont (),