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
);
56 #define event_left_is_down(x) ((x)->xbutton.state & Button1Mask)
57 #define event_middle_is_down(x) ((x)->xbutton.state & Button2Mask)
58 #define event_right_is_down(x) ((x)->xbutton.state & Button3Mask)
60 extern wxList wxPendingDelete
;
62 #if !USE_SHARED_LIBRARY
63 IMPLEMENT_DYNAMIC_CLASS(wxWindow
, wxEvtHandler
)
65 BEGIN_EVENT_TABLE(wxWindow
, wxEvtHandler
)
66 EVT_CHAR(wxWindow::OnChar
)
67 EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground
)
68 EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged
)
69 EVT_INIT_DIALOG(wxWindow::OnInitDialog
)
70 EVT_IDLE(wxWindow::OnIdle
)
82 m_windowParent
= NULL
;
83 m_windowEventHandler
= this;
85 m_windowCursor
= *wxSTANDARD_CURSOR
;
86 m_children
= new wxList
;
88 m_constraintsInvolvedIn
= NULL
;
92 m_windowValidator
= NULL
;
95 m_caretWidth
= 0; m_caretHeight
= 0;
96 m_caretEnabled
= FALSE
;
98 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
99 m_foregroundColour
= *wxBLACK
;
100 m_defaultForegroundColour
= *wxBLACK
;
101 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
103 #if USE_DRAG_AND_DROP
104 m_pDropTarget
= NULL
;
108 m_mainWidget
= (WXWidget
) 0;
109 m_button1Pressed
= FALSE
;
110 m_button2Pressed
= FALSE
;
111 m_button3Pressed
= FALSE
;
112 m_winCaptured
= FALSE
;
114 m_hScrollBar
= (WXWidget
) 0;
115 m_vScrollBar
= (WXWidget
) 0;
116 m_borderWidget
= (WXWidget
) 0;
117 m_scrolledWindow
= (WXWidget
) 0;
118 m_drawingArea
= (WXWidget
) 0;
121 m_hScrollingEnabled
= FALSE
;
122 m_vScrollingEnabled
= FALSE
;
123 m_backingPixmap
= (WXPixmap
) 0;
133 wxWindow::~wxWindow()
137 // If m_drawingArea, we're a fully-fledged window with drawing area, scrollbars etc. (what wxCanvas used to be)
140 // Destroy children before destroying self
144 XFreePixmap (XtDisplay ((Widget
) GetMainWidget()), (Pixmap
) m_backingPixmap
);
146 Widget w
= (Widget
) m_drawingArea
;
147 wxDeleteWindowFromTable(w
);
151 m_mainWidget
= (WXWidget
) 0;
153 // Only if we're _really_ a canvas (not a dialog box/panel)
154 if (m_scrolledWindow
)
156 wxDeleteWindowFromTable((Widget
) m_scrolledWindow
);
161 XtUnmanageChild ((Widget
) m_hScrollBar
);
162 XtDestroyWidget ((Widget
) m_hScrollBar
);
166 XtUnmanageChild ((Widget
) m_vScrollBar
);
167 XtDestroyWidget ((Widget
) m_vScrollBar
);
169 if (m_scrolledWindow
)
171 XtUnmanageChild ((Widget
) m_scrolledWindow
);
172 XtDestroyWidget ((Widget
) m_scrolledWindow
);
177 XtDestroyWidget ((Widget
) m_borderWidget
);
178 m_borderWidget
= (WXWidget
) 0;
185 // Have to delete constraints/sizer FIRST otherwise
186 // sizers may try to look at deleted windows as they
187 // delete themselves.
189 DeleteRelatedConstraints();
192 // This removes any dangling pointers to this window
193 // in other windows' constraintsInvolvedIn lists.
194 UnsetConstraints(m_constraints
);
195 delete m_constraints
;
196 m_constraints
= NULL
;
200 delete m_windowSizer
;
201 m_windowSizer
= NULL
;
203 // If this is a child of a sizer, remove self from parent
205 m_sizerParent
->RemoveChild((wxWindow
*)this);
209 m_windowParent
->RemoveChild(this);
213 // Destroy the window
216 wxDeleteWindowFromTable((Widget
) GetMainWidget());
217 XtDestroyWidget((Widget
) GetMainWidget());
218 SetMainWidget((WXWidget
) NULL
);
224 // Just in case the window has been Closed, but
225 // we're then deleting immediately: don't leave
226 // dangling pointers.
227 wxPendingDelete
.DeleteObject(this);
229 if ( m_windowValidator
)
230 delete m_windowValidator
;
233 // Destroy the window (delayed, if a managed window)
234 bool wxWindow::Destroy()
241 bool wxWindow::Create(wxWindow
*parent
, wxWindowID id
,
245 const wxString
& name
)
250 m_windowParent
= NULL
;
251 m_windowEventHandler
= this;
253 m_windowCursor
= *wxSTANDARD_CURSOR
;
254 m_constraints
= NULL
;
255 m_constraintsInvolvedIn
= NULL
;
256 m_windowSizer
= NULL
;
257 m_sizerParent
= NULL
;
258 m_autoLayout
= FALSE
;
259 m_windowValidator
= NULL
;
260 #if USE_DRAG_AND_DROP
261 m_pDropTarget
= NULL
;
263 m_caretWidth
= 0; m_caretHeight
= 0;
264 m_caretEnabled
= FALSE
;
265 m_caretShown
= FALSE
;
270 m_defaultItem
= NULL
;
271 m_windowParent
= NULL
;
274 m_mainWidget
= (WXWidget
) 0;
275 m_button1Pressed
= FALSE
;
276 m_button2Pressed
= FALSE
;
277 m_button3Pressed
= FALSE
;
278 m_winCaptured
= FALSE
;
280 m_hScrollBar
= (WXWidget
) 0;
281 m_vScrollBar
= (WXWidget
) 0;
282 m_borderWidget
= (WXWidget
) 0;
283 m_scrolledWindow
= (WXWidget
) 0;
284 m_drawingArea
= (WXWidget
) 0;
287 m_hScrollingEnabled
= FALSE
;
288 m_vScrollingEnabled
= FALSE
;
289 m_backingPixmap
= (WXPixmap
) 0;
298 if (parent
) parent
->AddChild(this);
305 m_windowId
= (int)NewControlId();
309 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) ; ;
310 m_foregroundColour
= *wxBLACK
;
311 m_defaultForegroundColour
= *wxBLACK
;
312 m_defaultBackgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
) ;
314 m_windowStyle
= style
;
317 m_windowId
= (int)NewControlId();
321 //// TODO: we should probably optimize by only creating a
322 //// a drawing area if we have one or more scrollbars (wxVSCROLL/wxHSCROLL).
323 //// But for now, let's simplify things by always creating the
324 //// drawing area, since otherwise the translations are different.
326 // New translations for getting mouse motion feedback
327 String translations
=
328 "<Btn1Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
329 <Btn2Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
330 <Btn3Motion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
331 <BtnMotion>: wxCanvasMotionEvent() DrawingAreaInput() ManagerGadgetButtonMotion()\n\
332 <Btn1Down>: DrawingAreaInput() ManagerGadgetArm()\n\
333 <Btn2Down>: DrawingAreaInput() ManagerGadgetArm()\n\
334 <Btn3Down>: DrawingAreaInput() ManagerGadgetArm()\n\
335 <Btn1Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
336 <Btn2Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
337 <Btn3Up>: DrawingAreaInput() ManagerGadgetActivate()\n\
338 <Motion>: wxCanvasMotionEvent() DrawingAreaInput()\n\
339 <EnterWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
340 <LeaveWindow>: wxCanvasMotionEvent() DrawingAreaInput()\n\
341 <Key>: DrawingAreaInput()";
343 XtActionsRec actions
[1];
344 actions
[0].string
= "wxCanvasMotionEvent";
345 actions
[0].proc
= (XtActionProc
) wxCanvasMotionEvent
;
346 XtAppAddActions ((XtAppContext
) wxTheApp
->GetAppContext(), actions
, 1);
348 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
349 if (style
& wxBORDER
)
350 m_borderWidget
= (WXWidget
) XtVaCreateManagedWidget ("canvasBorder",
351 xmFrameWidgetClass
, parentWidget
,
352 XmNshadowType
, XmSHADOW_IN
,
355 m_scrolledWindow
= (WXWidget
) XtVaCreateManagedWidget ("scrolledWindow",
356 xmScrolledWindowWidgetClass
, m_borderWidget
? (Widget
) m_borderWidget
: parentWidget
,
358 XmNscrollingPolicy
, XmAPPLICATION_DEFINED
,
362 m_drawingArea
= (WXWidget
) XtVaCreateWidget ((char*) (const char*) name
,
363 xmDrawingAreaWidgetClass
, (Widget
) m_scrolledWindow
,
364 XmNunitType
, XmPIXELS
,
365 // XmNresizePolicy, XmRESIZE_ANY,
366 XmNresizePolicy
, XmRESIZE_NONE
,
369 XmNtranslations
, ptr
= XtParseTranslationTable (translations
),
372 if (GetWindowStyleFlag() & wxOVERRIDE_KEY_TRANSLATIONS)
374 XtFree ((char *) ptr);
375 ptr = XtParseTranslationTable ("<Key>: DrawingAreaInput()");
376 XtOverrideTranslations ((Widget) m_drawingArea, ptr);
377 XtFree ((char *) ptr);
381 wxAddWindowToTable((Widget
) m_drawingArea
, this);
382 wxAddWindowToTable((Widget
) m_scrolledWindow
, this);
385 * This order is very important in Motif 1.2.1
389 XtRealizeWidget ((Widget
) m_scrolledWindow
);
390 XtRealizeWidget ((Widget
) m_drawingArea
);
391 XtManageChild ((Widget
) m_drawingArea
);
393 XtOverrideTranslations ((Widget
) m_drawingArea
,
394 ptr
= XtParseTranslationTable ("<Configure>: resize()"));
395 XtFree ((char *) ptr
);
397 XtAddCallback ((Widget
) m_drawingArea
, XmNexposeCallback
, (XtCallbackProc
) wxCanvasRepaintProc
, (XtPointer
) this);
398 XtAddCallback ((Widget
) m_drawingArea
, XmNinputCallback
, (XtCallbackProc
) wxCanvasInputEvent
, (XtPointer
) this);
401 display = XtDisplay (scrolledWindow);
402 xwindow = XtWindow (drawingArea);
405 XtAddEventHandler ((Widget
) m_drawingArea
, PointerMotionHintMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
,
406 False
, (XtEventHandler
) wxCanvasEnterLeave
, (XtPointer
) this);
411 void wxWindow::SetFocus()
413 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
414 XmProcessTraversal((Widget
) GetMainWidget(), XmTRAVERSE_CURRENT
);
417 void wxWindow::Enable(bool enable
)
421 XtSetSensitive((Widget
) GetMainWidget(), enable
);
422 XmUpdateDisplay((Widget
) GetMainWidget());
426 void wxWindow::CaptureMouse()
432 XtAddGrab((Widget
) GetMainWidget(), TRUE
, FALSE
);
434 m_winCaptured
= TRUE
;
437 void wxWindow::ReleaseMouse()
443 XtRemoveGrab((Widget
) GetMainWidget());
444 m_winCaptured
= FALSE
;
447 // Push/pop event handler (i.e. allow a chain of event handlers
449 void wxWindow::PushEventHandler(wxEvtHandler
*handler
)
451 handler
->SetNextHandler(GetEventHandler());
452 SetEventHandler(handler
);
455 wxEvtHandler
*wxWindow::PopEventHandler(bool deleteHandler
)
457 if ( GetEventHandler() )
459 wxEvtHandler
*handlerA
= GetEventHandler();
460 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
461 handlerA
->SetNextHandler(NULL
);
462 SetEventHandler(handlerB
);
475 #if USE_DRAG_AND_DROP
477 void wxWindow::SetDropTarget(wxDropTarget
*pDropTarget
)
479 if ( m_pDropTarget
!= 0 ) {
480 delete m_pDropTarget
;
483 m_pDropTarget
= pDropTarget
;
484 if ( m_pDropTarget
!= 0 )
492 // Old style file-manager drag&drop
493 void wxWindow::DragAcceptFiles(bool accept
)
499 void wxWindow::GetSize(int *x
, int *y
) const
507 Widget widget
= (Widget
) GetMainWidget();
509 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
513 void wxWindow::GetPosition(int *x
, int *y
) const
517 CanvasGetPosition(x
, y
);
520 Widget widget
= (Widget
) GetMainWidget();
522 XtVaGetValues(widget
, XmNx
, &xx
, XmNy
, &yy
, NULL
);
526 void wxWindow::ScreenToClient(int *x
, int *y
) const
531 void wxWindow::ClientToScreen(int *x
, int *y
) const
533 Widget widget
= (Widget
) GetMainWidget();
534 Display
*display
= XtDisplay(widget
);
535 Window rootWindow
= RootWindowOfScreen(XtScreen(widget
));
537 if (this->IsKindOf(CLASSINFO(wxFrame
)))
539 wxFrame
*fr
= (wxFrame
*)this;
541 // thisWindow = XtWindow(fr->m_clientArea);
544 thisWindow
= XtWindow((Widget
)widget
);
549 XTranslateCoordinates(display
, thisWindow
, rootWindow
, xx
, yy
, x
, y
, &childWindow
);
552 void wxWindow::SetCursor(const wxCursor
& cursor
)
554 m_windowCursor
= cursor
;
555 if (m_windowCursor
.Ok())
557 /* TODO when wxCursor implemented
558 WXDisplay *dpy = GetXDisplay();
559 Cursor x_cursor = cursor.GetXCursor(dpy);
561 Widget w = (Widget) GetMainWidget();
562 Window win = XtWindow(w);
563 XDefineCursor((Display*) dpy, win, x_cursor);
569 // Get size *available for subwindows* i.e. excluding menu bar etc.
570 void wxWindow::GetClientSize(int *x
, int *y
) const
572 Widget widget
= (Widget
) GetMainWidget();
574 XtVaGetValues(widget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
578 void wxWindow::SetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
582 CanvasSetSize(x
, y
, width
, height
, sizeFlags
);
585 Widget widget
= (Widget
) GetMainWidget();
587 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
588 XtVaSetValues(widget
, XmNx
, x
, NULL
);
589 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
590 XtVaSetValues(widget
, XmNy
, y
, NULL
);
592 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
594 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
596 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
597 sizeEvent
.SetEventObject(this);
599 GetEventHandler()->ProcessEvent(sizeEvent
);
602 void wxWindow::SetClientSize(int width
, int height
)
606 CanvasSetClientSize(width
, height
);
610 Widget widget
= (Widget
) GetMainWidget();
613 XtVaSetValues(widget
, XmNwidth
, width
, NULL
);
615 XtVaSetValues(widget
, XmNheight
, height
, NULL
);
617 wxSizeEvent
sizeEvent(wxSize(width
, height
), GetId());
618 sizeEvent
.SetEventObject(this);
620 GetEventHandler()->ProcessEvent(sizeEvent
);
623 // For implementation purposes - sometimes decorations make the client area
625 wxPoint
wxWindow::GetClientAreaOrigin() const
627 return wxPoint(0, 0);
630 // Makes an adjustment to the window position (for example, a frame that has
631 // a toolbar that it manages itself).
632 void wxWindow::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
)
634 if (((sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) == 0) && GetParent())
636 wxPoint
pt(GetParent()->GetClientAreaOrigin());
637 x
+= pt
.x
; y
+= pt
.y
;
641 bool wxWindow::Show(bool show
)
645 if (m_borderWidget
|| m_scrolledWindow
)
647 XtMapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
651 XtMapWidget((Widget
) GetMainWidget());
656 if (m_borderWidget
|| m_scrolledWindow
)
658 XtUnmapWidget(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
662 XtUnmapWidget((Widget
) GetMainWidget());
667 Window xwin = (Window) GetXWindow();
668 Display *xdisp = (Display*) GetXDisplay();
670 XMapWindow(xdisp, xwin);
672 XUnmapWindow(xdisp, xwin);
680 bool wxWindow::IsShown() const
685 int wxWindow::GetCharHeight() const
691 int wxWindow::GetCharWidth() const
697 void wxWindow::GetTextExtent(const wxString
& string
, int *x
, int *y
,
698 int *descent
, int *externalLeading
, const wxFont
*theFont
, bool) const
700 wxFont
*fontToUse
= (wxFont
*)theFont
;
702 fontToUse
= (wxFont
*) & m_windowFont
;
707 void wxWindow::Refresh(bool eraseBack
, const wxRectangle
*rect
)
709 Display
*display
= XtDisplay((Widget
) GetMainWidget());
710 Window thisWindow
= XtWindow((Widget
) GetMainWidget());
712 XExposeEvent dummyEvent
;
714 GetSize(&width
, &height
);
716 dummyEvent
.type
= Expose
;
717 dummyEvent
.display
= display
;
718 dummyEvent
.send_event
= True
;
719 dummyEvent
.window
= thisWindow
;
722 dummyEvent
.x
= rect
->x
;
723 dummyEvent
.y
= rect
->y
;
724 dummyEvent
.width
= rect
->width
;
725 dummyEvent
.height
= rect
->height
;
731 dummyEvent
.width
= width
;
732 dummyEvent
.height
= height
;
734 dummyEvent
.count
= 0;
742 XSendEvent(display
, thisWindow
, False
, ExposureMask
, (XEvent
*)&dummyEvent
);
745 // Responds to colour changes: passes event on to children.
746 void wxWindow::OnSysColourChanged(wxSysColourChangedEvent
& event
)
748 wxNode
*node
= GetChildren()->First();
751 // Only propagate to non-top-level windows
752 wxWindow
*win
= (wxWindow
*)node
->Data();
753 if ( win
->GetParent() )
755 wxSysColourChangedEvent event2
;
756 event
.m_eventObject
= win
;
757 win
->GetEventHandler()->ProcessEvent(event2
);
764 // This can be called by the app (or wxWindows) to do default processing for the current
765 // event. Save message/event info in wxWindow so they can be used in this function.
766 long wxWindow::Default()
772 void wxWindow::InitDialog()
774 wxInitDialogEvent
event(GetId());
775 event
.SetEventObject( this );
776 GetEventHandler()->ProcessEvent(event
);
779 // Default init dialog behaviour is to transfer data to window
780 void wxWindow::OnInitDialog(wxInitDialogEvent
& event
)
782 TransferDataToWindow();
785 // Caret manipulation
786 void wxWindow::CreateCaret(int w
, int h
)
790 m_caretEnabled
= TRUE
;
793 void wxWindow::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
798 void wxWindow::ShowCaret(bool show
)
803 void wxWindow::DestroyCaret()
806 m_caretEnabled
= FALSE
;
809 void wxWindow::SetCaretPos(int x
, int y
)
814 void wxWindow::GetCaretPos(int *x
, int *y
) const
819 wxWindow
*wxGetActiveWindow()
825 void wxWindow::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int incW
, int incH
)
832 if (!this->IsKindOf(CLASSINFO(wxFrame
)))
835 wxFrame
*frame
= (wxFrame
*)this;
837 /* Uncomment when wxFrame implemented
839 XtVaSetValues((Widget) frame->m_frameShell, XmNminWidth, minW, NULL);
841 XtVaSetValues((Widget) frame->m_frameShell, XmNminHeight, minH, NULL);
843 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxWidth, maxW, NULL);
845 XtVaSetValues((Widget) frame->m_frameShell, XmNmaxHeight, maxH, NULL);
847 XtVaSetValues((Widget) frame->m_frameShell, XmNwidthInc, incW, NULL);
849 XtVaSetValues((Widget) frame->m_frameShell, XmNheightInc, incH, NULL);
853 void wxWindow::Centre(int direction
)
855 int x
, y
, width
, height
, panel_width
, panel_height
, new_x
, new_y
;
857 wxWindow
*father
= (wxWindow
*)GetParent();
861 father
->GetClientSize(&panel_width
, &panel_height
);
862 GetSize(&width
, &height
);
868 if (direction
& wxHORIZONTAL
)
869 new_x
= (int)((panel_width
- width
)/2);
871 if (direction
& wxVERTICAL
)
872 new_y
= (int)((panel_height
- height
)/2);
874 SetSize(new_x
, new_y
, -1, -1);
878 // Coordinates relative to the window
879 void wxWindow::WarpPointer (int x
, int y
)
881 XWarpPointer (XtDisplay((Widget
) GetClientWidget()), None
, XtWindow((Widget
) GetClientWidget()), 0, 0, 0, 0, x
, y
);
884 void wxWindow::OnEraseBackground(wxEraseEvent
& event
)
890 int wxWindow::GetScrollPos(int orient
) const
896 // This now returns the whole range, not just the number
897 // of positions that we can scroll.
898 int wxWindow::GetScrollRange(int orient
) const
904 int wxWindow::GetScrollThumb(int orient
) const
910 void wxWindow::SetScrollPos(int orient
, int pos
, bool refresh
)
916 // New function that will replace some of the above.
917 void wxWindow::SetScrollbar(int orient
, int pos
, int thumbVisible
,
918 int range
, bool refresh
)
923 // Does a physical scroll
924 void wxWindow::ScrollWindow(int dx
, int dy
, const wxRectangle
*rect
)
930 void wxWindow::SetFont(const wxFont
& font
)
934 if (!m_windowFont
.Ok())
939 void wxWindow::OnChar(wxKeyEvent
& event
)
941 if ( event
.KeyCode() == WXK_TAB
) {
942 // propagate the TABs to the parent - it's up to it to decide what
945 if ( GetParent()->ProcessEvent(event
) )
951 void wxWindow::OnPaint(wxPaintEvent
& event
)
956 bool wxWindow::IsEnabled() const
962 // Dialog support: override these and call
963 // base class members to add functionality
964 // that can't be done using validators.
965 // NOTE: these functions assume that controls
966 // are direct children of this window, not grandchildren
967 // or other levels of descendant.
969 // Transfer values to controls. If returns FALSE,
970 // it's an application error (pops up a dialog)
971 bool wxWindow::TransferDataToWindow()
973 wxNode
*node
= GetChildren()->First();
976 wxWindow
*child
= (wxWindow
*)node
->Data();
977 if ( child
->GetValidator() &&
978 !child
->GetValidator()->TransferToWindow() )
980 wxMessageBox("Application Error", "Could not transfer data to window", wxOK
|wxICON_EXCLAMATION
);
989 // Transfer values from controls. If returns FALSE,
990 // validation failed: don't quit
991 bool wxWindow::TransferDataFromWindow()
993 wxNode
*node
= GetChildren()->First();
996 wxWindow
*child
= (wxWindow
*)node
->Data();
997 if ( child
->GetValidator() && !child
->GetValidator()->TransferFromWindow() )
1002 node
= node
->Next();
1007 bool wxWindow::Validate()
1009 wxNode
*node
= GetChildren()->First();
1012 wxWindow
*child
= (wxWindow
*)node
->Data();
1013 if ( child
->GetValidator() && /* child->GetValidator()->Ok() && */ !child
->GetValidator()->Validate(this) )
1018 node
= node
->Next();
1023 // Get the window with the focus
1024 wxWindow
*wxWindow::FindFocus()
1030 void wxWindow::AddChild(wxWindow
*child
)
1032 GetChildren()->Append(child
);
1033 child
->m_windowParent
= this;
1036 void wxWindow::RemoveChild(wxWindow
*child
)
1039 GetChildren()->DeleteObject(child
);
1040 child
->m_windowParent
= NULL
;
1043 void wxWindow::DestroyChildren()
1045 if (GetChildren()) {
1047 while ((node
= GetChildren()->First()) != (wxNode
*)NULL
) {
1049 if ((child
= (wxWindow
*)node
->Data()) != (wxWindow
*)NULL
) {
1051 if ( GetChildren()->Member(child
) )
1058 void wxWindow::MakeModal(bool modal
)
1060 // Disable all other windows
1061 if (this->IsKindOf(CLASSINFO(wxDialog
)) || this->IsKindOf(CLASSINFO(wxFrame
)))
1063 wxNode
*node
= wxTopLevelWindows
.First();
1066 wxWindow
*win
= (wxWindow
*)node
->Data();
1068 win
->Enable(!modal
);
1070 node
= node
->Next();
1075 void wxWindow::SetConstraints(wxLayoutConstraints
*c
)
1079 UnsetConstraints(m_constraints
);
1080 delete m_constraints
;
1085 // Make sure other windows know they're part of a 'meaningful relationship'
1086 if (m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this))
1087 m_constraints
->left
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1088 if (m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this))
1089 m_constraints
->top
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1090 if (m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this))
1091 m_constraints
->right
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1092 if (m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this))
1093 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1094 if (m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this))
1095 m_constraints
->width
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1096 if (m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this))
1097 m_constraints
->height
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1098 if (m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this))
1099 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1100 if (m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this))
1101 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference((wxWindow
*)this);
1105 // This removes any dangling pointers to this window
1106 // in other windows' constraintsInvolvedIn lists.
1107 void wxWindow::UnsetConstraints(wxLayoutConstraints
*c
)
1111 if (c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1112 c
->left
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1113 if (c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this))
1114 c
->top
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1115 if (c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this))
1116 c
->right
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1117 if (c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this))
1118 c
->bottom
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1119 if (c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this))
1120 c
->width
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1121 if (c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this))
1122 c
->height
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1123 if (c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this))
1124 c
->centreX
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1125 if (c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this))
1126 c
->centreY
.GetOtherWindow()->RemoveConstraintReference((wxWindow
*)this);
1130 // Back-pointer to other windows we're involved with, so if we delete
1131 // this window, we must delete any constraints we're involved with.
1132 void wxWindow::AddConstraintReference(wxWindow
*otherWin
)
1134 if (!m_constraintsInvolvedIn
)
1135 m_constraintsInvolvedIn
= new wxList
;
1136 if (!m_constraintsInvolvedIn
->Member(otherWin
))
1137 m_constraintsInvolvedIn
->Append(otherWin
);
1140 // REMOVE back-pointer to other windows we're involved with.
1141 void wxWindow::RemoveConstraintReference(wxWindow
*otherWin
)
1143 if (m_constraintsInvolvedIn
)
1144 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1147 // Reset any constraints that mention this window
1148 void wxWindow::DeleteRelatedConstraints()
1150 if (m_constraintsInvolvedIn
)
1152 wxNode
*node
= m_constraintsInvolvedIn
->First();
1155 wxWindow
*win
= (wxWindow
*)node
->Data();
1156 wxNode
*next
= node
->Next();
1157 wxLayoutConstraints
*constr
= win
->GetConstraints();
1159 // Reset any constraints involving this window
1162 constr
->left
.ResetIfWin((wxWindow
*)this);
1163 constr
->top
.ResetIfWin((wxWindow
*)this);
1164 constr
->right
.ResetIfWin((wxWindow
*)this);
1165 constr
->bottom
.ResetIfWin((wxWindow
*)this);
1166 constr
->width
.ResetIfWin((wxWindow
*)this);
1167 constr
->height
.ResetIfWin((wxWindow
*)this);
1168 constr
->centreX
.ResetIfWin((wxWindow
*)this);
1169 constr
->centreY
.ResetIfWin((wxWindow
*)this);
1174 delete m_constraintsInvolvedIn
;
1175 m_constraintsInvolvedIn
= NULL
;
1179 void wxWindow::SetSizer(wxSizer
*sizer
)
1181 m_windowSizer
= sizer
;
1183 sizer
->SetSizerParent((wxWindow
*)this);
1190 bool wxWindow::Layout()
1192 if (GetConstraints())
1195 GetClientSize(&w
, &h
);
1196 GetConstraints()->width
.SetValue(w
);
1197 GetConstraints()->height
.SetValue(h
);
1200 // If top level (one sizer), evaluate the sizer's constraints.
1204 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
1205 GetSizer()->LayoutPhase1(&noChanges
);
1206 GetSizer()->LayoutPhase2(&noChanges
);
1207 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
1212 // Otherwise, evaluate child constraints
1213 ResetConstraints(); // Mark all constraints as unevaluated
1214 DoPhase(1); // Just one phase need if no sizers involved
1216 SetConstraintSizes(); // Recursively set the real window sizes
1222 // Do a phase of evaluating constraints:
1223 // the default behaviour. wxSizers may do a similar
1224 // thing, but also impose their own 'constraints'
1225 // and order the evaluation differently.
1226 bool wxWindow::LayoutPhase1(int *noChanges
)
1228 wxLayoutConstraints
*constr
= GetConstraints();
1231 return constr
->SatisfyConstraints((wxWindow
*)this, noChanges
);
1237 bool wxWindow::LayoutPhase2(int *noChanges
)
1247 // Do a phase of evaluating child constraints
1248 bool wxWindow::DoPhase(int phase
)
1250 int noIterations
= 0;
1251 int maxIterations
= 500;
1255 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1259 wxNode
*node
= GetChildren()->First();
1262 wxWindow
*child
= (wxWindow
*)node
->Data();
1263 if (!child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)))
1265 wxLayoutConstraints
*constr
= child
->GetConstraints();
1268 if (succeeded
.Member(child
))
1273 int tempNoChanges
= 0;
1274 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1275 noChanges
+= tempNoChanges
;
1278 succeeded
.Append(child
);
1283 node
= node
->Next();
1290 void wxWindow::ResetConstraints()
1292 wxLayoutConstraints
*constr
= GetConstraints();
1295 constr
->left
.SetDone(FALSE
);
1296 constr
->top
.SetDone(FALSE
);
1297 constr
->right
.SetDone(FALSE
);
1298 constr
->bottom
.SetDone(FALSE
);
1299 constr
->width
.SetDone(FALSE
);
1300 constr
->height
.SetDone(FALSE
);
1301 constr
->centreX
.SetDone(FALSE
);
1302 constr
->centreY
.SetDone(FALSE
);
1304 wxNode
*node
= GetChildren()->First();
1307 wxWindow
*win
= (wxWindow
*)node
->Data();
1308 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1309 win
->ResetConstraints();
1310 node
= node
->Next();
1314 // Need to distinguish between setting the 'fake' size for
1315 // windows and sizers, and setting the real values.
1316 void wxWindow::SetConstraintSizes(bool recurse
)
1318 wxLayoutConstraints
*constr
= GetConstraints();
1319 if (constr
&& constr
->left
.GetDone() && constr
->right
.GetDone() &&
1320 constr
->width
.GetDone() && constr
->height
.GetDone())
1322 int x
= constr
->left
.GetValue();
1323 int y
= constr
->top
.GetValue();
1324 int w
= constr
->width
.GetValue();
1325 int h
= constr
->height
.GetValue();
1327 // If we don't want to resize this window, just move it...
1328 if ((constr
->width
.GetRelationship() != wxAsIs
) ||
1329 (constr
->height
.GetRelationship() != wxAsIs
))
1331 // Calls Layout() recursively. AAAGH. How can we stop that.
1332 // Simply take Layout() out of non-top level OnSizes.
1333 SizerSetSize(x
, y
, w
, h
);
1342 char *windowClass
= this->GetClassInfo()->GetClassName();
1345 if (GetName() == "")
1346 winName
= "unnamed";
1348 winName
= GetName();
1349 wxDebugMsg("Constraint(s) not satisfied for window of type %s, name %s:\n", (const char *)windowClass
, (const char *)winName
);
1350 if (!constr
->left
.GetDone())
1351 wxDebugMsg(" unsatisfied 'left' constraint.\n");
1352 if (!constr
->right
.GetDone())
1353 wxDebugMsg(" unsatisfied 'right' constraint.\n");
1354 if (!constr
->width
.GetDone())
1355 wxDebugMsg(" unsatisfied 'width' constraint.\n");
1356 if (!constr
->height
.GetDone())
1357 wxDebugMsg(" unsatisfied 'height' constraint.\n");
1358 wxDebugMsg("Please check constraints: try adding AsIs() constraints.\n");
1363 wxNode
*node
= GetChildren()->First();
1366 wxWindow
*win
= (wxWindow
*)node
->Data();
1367 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)))
1368 win
->SetConstraintSizes();
1369 node
= node
->Next();
1374 // This assumes that all sizers are 'on' the same
1375 // window, i.e. the parent of this window.
1376 void wxWindow::TransformSizerToActual(int *x
, int *y
) const
1378 if (!m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
)) ||
1379 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1383 m_sizerParent
->GetPosition(&xp
, &yp
);
1384 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1389 void wxWindow::SizerSetSize(int x
, int y
, int w
, int h
)
1393 TransformSizerToActual(&xx
, &yy
);
1394 SetSize(xx
, yy
, w
, h
);
1397 void wxWindow::SizerMove(int x
, int y
)
1401 TransformSizerToActual(&xx
, &yy
);
1405 // Only set the size/position of the constraint (if any)
1406 void wxWindow::SetSizeConstraint(int x
, int y
, int w
, int h
)
1408 wxLayoutConstraints
*constr
= GetConstraints();
1413 constr
->left
.SetValue(x
);
1414 constr
->left
.SetDone(TRUE
);
1418 constr
->top
.SetValue(y
);
1419 constr
->top
.SetDone(TRUE
);
1423 constr
->width
.SetValue(w
);
1424 constr
->width
.SetDone(TRUE
);
1428 constr
->height
.SetValue(h
);
1429 constr
->height
.SetDone(TRUE
);
1434 void wxWindow::MoveConstraint(int x
, int y
)
1436 wxLayoutConstraints
*constr
= GetConstraints();
1441 constr
->left
.SetValue(x
);
1442 constr
->left
.SetDone(TRUE
);
1446 constr
->top
.SetValue(y
);
1447 constr
->top
.SetDone(TRUE
);
1452 void wxWindow::GetSizeConstraint(int *w
, int *h
) const
1454 wxLayoutConstraints
*constr
= GetConstraints();
1457 *w
= constr
->width
.GetValue();
1458 *h
= constr
->height
.GetValue();
1464 void wxWindow::GetClientSizeConstraint(int *w
, int *h
) const
1466 wxLayoutConstraints
*constr
= GetConstraints();
1469 *w
= constr
->width
.GetValue();
1470 *h
= constr
->height
.GetValue();
1473 GetClientSize(w
, h
);
1476 void wxWindow::GetPositionConstraint(int *x
, int *y
) const
1478 wxLayoutConstraints
*constr
= GetConstraints();
1481 *x
= constr
->left
.GetValue();
1482 *y
= constr
->top
.GetValue();
1488 bool wxWindow::Close(bool force
)
1490 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
1491 event
.SetEventObject(this);
1492 event
.SetForce(force
);
1494 return GetEventHandler()->ProcessEvent(event
);
1497 wxObject
* wxWindow::GetChild(int number
) const
1499 // Return a pointer to the Nth object in the window
1502 wxNode
*node
= GetChildren()->First();
1505 node
= node
->Next() ;
1508 wxObject
*obj
= (wxObject
*)node
->Data();
1515 void wxWindow::OnDefaultAction(wxControl
*initiatingItem
)
1517 // Obsolete function
1520 void wxWindow::Clear()
1522 wxClientDC
dc(this);
1523 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1524 dc
.SetBackground(brush
);
1528 // Fits the panel around the items
1529 void wxWindow::Fit()
1533 wxNode
*node
= GetChildren()->First();
1536 wxWindow
*win
= (wxWindow
*)node
->Data();
1538 win
->GetPosition(&wx
, &wy
);
1539 win
->GetSize(&ww
, &wh
);
1540 if ( wx
+ ww
> maxX
)
1542 if ( wy
+ wh
> maxY
)
1545 node
= node
->Next();
1547 SetClientSize(maxX
+ 5, maxY
+ 5);
1550 void wxWindow::SetValidator(const wxValidator
& validator
)
1552 if ( m_windowValidator
)
1553 delete m_windowValidator
;
1554 m_windowValidator
= validator
.Clone();
1556 if ( m_windowValidator
)
1557 m_windowValidator
->SetWindow(this) ;
1560 // Find a window by id or name
1561 wxWindow
*wxWindow::FindWindow(long id
)
1566 wxNode
*node
= GetChildren()->First();
1569 wxWindow
*child
= (wxWindow
*)node
->Data();
1570 wxWindow
*found
= child
->FindWindow(id
);
1573 node
= node
->Next();
1578 wxWindow
*wxWindow::FindWindow(const wxString
& name
)
1580 if ( GetName() == name
)
1583 wxNode
*node
= GetChildren()->First();
1586 wxWindow
*child
= (wxWindow
*)node
->Data();
1587 wxWindow
*found
= child
->FindWindow(name
);
1590 node
= node
->Next();
1595 void wxWindow::OnIdle(wxIdleEvent
& event
)
1597 /* TODO: you may need to do something like this
1598 * if your GUI doesn't generate enter/leave events
1600 // Check if we need to send a LEAVE event
1601 if (m_mouseInWindow)
1604 ::GetCursorPos(&pt);
1605 if (::WindowFromPoint(pt) != (HWND) GetHWND())
1607 // Generate a LEAVE event
1608 m_mouseInWindow = FALSE;
1609 MSWOnMouseLeave(pt.x, pt.y, 0);
1614 // This calls the UI-update mechanism (querying windows for
1615 // menu/toolbar/control state information)
1619 // Raise the window to the top of the Z order
1620 void wxWindow::Raise()
1622 Window window
= XtWindow((Widget
) GetMainWidget());
1623 XRaiseWindow(XtDisplay((Widget
) GetMainWidget()), window
);
1626 // Lower the window to the bottom of the Z order
1627 void wxWindow::Lower()
1629 Window window
= XtWindow((Widget
) GetMainWidget());
1630 XLowerWindow(XtDisplay((Widget
) GetMainWidget()), window
);
1633 bool wxWindow::AcceptsFocus() const
1635 return IsShown() && IsEnabled();
1638 // Update region access
1639 wxRegion
wxWindow::GetUpdateRegion() const
1641 return m_updateRegion
;
1644 bool wxWindow::IsExposed(int x
, int y
, int w
, int h
) const
1646 return (m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
);
1649 bool wxWindow::IsExposed(const wxPoint
& pt
) const
1651 return (m_updateRegion
.Contains(pt
) != wxOutRegion
);
1654 bool wxWindow::IsExposed(const wxRect
& rect
) const
1656 return (m_updateRegion
.Contains(rect
) != wxOutRegion
);
1660 * Allocates control IDs
1663 int wxWindow::NewControlId()
1665 static int s_controlId
= 0;
1670 void wxWindow::SetAcceleratorTable(const wxAcceleratorTable
& accel
)
1672 m_acceleratorTable
= accel
;
1675 // All widgets should have this as their resize proc.
1676 // OnSize sent to wxWindow via client data.
1677 void wxWidgetResizeProc(Widget w
, XConfigureEvent
*event
, String args
[], int *num_args
)
1679 wxWindow
*win
= (wxWindow
*)wxWidgetHashTable
->Get((long)w
);
1683 if (win
->PreResize())
1686 win
->GetSize(&width
, &height
);
1687 wxSizeEvent
sizeEvent(wxSize(width
, height
), win
->GetId());
1688 sizeEvent
.SetEventObject(win
);
1689 win
->GetEventHandler()->ProcessEvent(sizeEvent
);
1693 bool wxAddWindowToTable(Widget w
, wxWindow
*win
)
1695 wxWindow
*oldItem
= NULL
;
1697 // printf("Adding widget %ld, name = %s\n", w, win->GetClassInfo()->GetClassName());
1699 if ((oldItem
= (wxWindow
*)wxWidgetHashTable
->Get ((long) w
)))
1702 sprintf(buf
, "Widget table clash: new widget is %ld, %s", (long)w
, win
->GetClassInfo()->GetClassName());
1705 sprintf(buf
, "Old widget was %s", oldItem
->GetClassInfo()->GetClassName());
1710 wxWidgetHashTable
->Put ((long) w
, win
);
1714 wxWindow
*wxGetWindowFromTable(Widget w
)
1716 return (wxWindow
*)wxWidgetHashTable
->Get ((long) w
);
1719 void wxDeleteWindowFromTable(Widget w
)
1722 // printf("Deleting widget %ld\n", w);
1724 // wxWindow *win = (wxWindow *)wxWidgetHashTable->Get ((long) w);
1726 wxWidgetHashTable
->Delete((long)w
);
1729 // Get the underlying X window and display
1730 WXWindow
wxWindow::GetXWindow() const
1732 return (WXWindow
) XtWindow((Widget
) GetMainWidget());
1735 WXDisplay
*wxWindow::GetXDisplay() const
1737 return (WXDisplay
*) XtDisplay((Widget
) GetMainWidget());
1740 WXWidget
wxWindow::GetMainWidget() const
1743 return m_drawingArea
;
1745 return m_mainWidget
;
1748 WXWidget
wxWindow::GetClientWidget() const
1750 if (m_drawingArea
!= (WXWidget
) 0)
1751 return m_drawingArea
;
1753 return m_mainWidget
;
1756 void wxCanvasRepaintProc (Widget drawingArea
, XtPointer clientData
,
1757 XmDrawingAreaCallbackStruct
* cbs
)
1759 if (!wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
))
1762 XEvent
* event
= cbs
->event
;
1763 wxWindow
* canvas
= (wxWindow
*) clientData
;
1764 Display
* display
= (Display
*) canvas
->GetXDisplay();
1765 // GC gc = (GC) canvas->GetDC()->gc;
1767 switch (event
->type
)
1772 wxCanvasDC* canvasDC = canvas->GetDC();
1775 if (canvasDC->onpaint_reg)
1776 XDestroyRegion(canvasDC->onpaint_reg);
1777 canvasDC->onpaint_reg = XCreateRegion();
1782 int n
= canvas
->m_updateRects
.Number();
1783 XRectangle
* xrects
= new XRectangle
[n
];
1785 for (i
= 0; i
< canvas
->m_updateRects
.Number(); i
++)
1787 wxRect
* rect
= (wxRect
*) canvas
->m_updateRects
.Nth(i
)->Data();
1788 xrects
[i
].x
= rect
->x
;
1789 xrects
[i
].y
= rect
->y
;
1790 xrects
[i
].width
= rect
->width
;
1791 xrects
[i
].height
= rect
->height
;
1792 /* TODO (?) Actually ignore it I think.
1794 XUnionRectWithRegion(&(xrects[i]), canvasDC->onpaint_reg,
1795 canvasDC->onpaint_reg);
1798 /* TODO must clip the area being repainted. So we need a gc.
1799 * Alternatively, wxPaintDC must do the clipping
1800 * when it's created.
1801 XSetClipRectangles(display, gc, 0, 0, xrects, n, Unsorted);
1804 canvas
->DoPaint() ; // xrects, n);
1807 canvas
->m_updateRects
.Clear();
1812 XDestroyRegion(canvasDC->onpaint_reg);
1813 canvasDC->onpaint_reg = NULL;
1817 gc_val.clip_mask = None;
1818 XChangeGC(display, gc, GCClipMask, &gc_val);
1825 cout
<< "\n\nNew Event ! is = " << event
-> type
<< "\n";
1831 // Unable to deal with Enter/Leave without a separate EventHandler (Motif 1.1.4)
1833 wxCanvasEnterLeave (Widget drawingArea
, XtPointer clientData
, XCrossingEvent
* event
)
1835 XmDrawingAreaCallbackStruct cbs
;
1838 //if (event->mode!=NotifyNormal)
1841 // ev = *((XEvent *) event); // Causes Purify error (copying too many bytes)
1842 ((XCrossingEvent
&) ev
) = *event
;
1844 cbs
.reason
= XmCR_INPUT
;
1847 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1850 // Fix to make it work under Motif 1.0 (!)
1851 void wxCanvasMotionEvent (Widget drawingArea
, XButtonEvent
* event
)
1855 XmDrawingAreaCallbackStruct cbs
;
1858 //ev.xbutton = *event;
1859 ev
= *((XEvent
*) event
);
1860 cbs
.reason
= XmCR_INPUT
;
1863 wxCanvasInputEvent (drawingArea
, (XtPointer
) NULL
, &cbs
);
1867 void wxCanvasInputEvent (Widget drawingArea
, XtPointer data
, XmDrawingAreaCallbackStruct
* cbs
)
1869 wxWindow
*canvas
= (wxWindow
*) wxWidgetHashTable
->Get ((long) (Widget
) drawingArea
);
1875 if (cbs
->reason
!= XmCR_INPUT
)
1878 local_event
= *(cbs
->event
); // We must keep a copy!
1880 switch (local_event
.xany
.type
)
1888 wxEventType eventType
= wxEVT_NULL
;
1890 if (local_event
.xany
.type
== EnterNotify
)
1892 //if (local_event.xcrossing.mode!=NotifyNormal)
1893 // return ; // Ignore grab events
1894 eventType
= wxEVT_ENTER_WINDOW
;
1895 // canvas->GetEventHandler()->OnSetFocus();
1897 else if (local_event
.xany
.type
== LeaveNotify
)
1899 //if (local_event.xcrossing.mode!=NotifyNormal)
1900 // return ; // Ignore grab events
1901 eventType
= wxEVT_LEAVE_WINDOW
;
1902 // canvas->GetEventHandler()->OnKillFocus();
1904 else if (local_event
.xany
.type
== MotionNotify
)
1906 eventType
= wxEVT_MOTION
;
1907 if (local_event
.xmotion
.is_hint
== NotifyHint
)
1910 Display
*dpy
= XtDisplay (drawingArea
);
1912 XQueryPointer (dpy
, XtWindow (drawingArea
),
1914 &local_event
.xmotion
.x_root
,
1915 &local_event
.xmotion
.y_root
,
1916 &local_event
.xmotion
.x
,
1917 &local_event
.xmotion
.y
,
1918 &local_event
.xmotion
.state
);
1925 else if (local_event
.xany
.type
== ButtonPress
)
1927 if (local_event
.xbutton
.button
== Button1
)
1929 eventType
= wxEVT_LEFT_DOWN
;
1930 canvas
->m_button1Pressed
= TRUE
;
1932 else if (local_event
.xbutton
.button
== Button2
)
1934 eventType
= wxEVT_MIDDLE_DOWN
;
1935 canvas
->m_button2Pressed
= TRUE
;
1937 else if (local_event
.xbutton
.button
== Button3
)
1939 eventType
= wxEVT_RIGHT_DOWN
;
1940 canvas
->m_button3Pressed
= TRUE
;
1943 else if (local_event
.xany
.type
== ButtonRelease
)
1945 if (local_event
.xbutton
.button
== Button1
)
1947 eventType
= wxEVT_LEFT_UP
;
1948 canvas
->m_button1Pressed
= FALSE
;
1950 else if (local_event
.xbutton
.button
== Button2
)
1952 eventType
= wxEVT_MIDDLE_UP
;
1953 canvas
->m_button2Pressed
= FALSE
;
1955 else if (local_event
.xbutton
.button
== Button3
)
1957 eventType
= wxEVT_RIGHT_UP
;
1958 canvas
->m_button3Pressed
= FALSE
;
1962 wxMouseEvent
wxevent (eventType
);
1963 wxevent
.m_eventHandle
= (char *) &local_event
;
1965 wxevent
.m_leftDown
= ((eventType
== wxEVT_LEFT_DOWN
)
1966 || (event_left_is_down (&local_event
)
1967 && (eventType
!= wxEVT_LEFT_UP
)));
1968 wxevent
.m_middleDown
= ((eventType
== wxEVT_MIDDLE_DOWN
)
1969 || (event_middle_is_down (&local_event
)
1970 && (eventType
!= wxEVT_MIDDLE_UP
)));
1971 wxevent
.m_rightDown
= ((eventType
== wxEVT_RIGHT_DOWN
)
1972 || (event_right_is_down (&local_event
)
1973 && (eventType
!= wxEVT_RIGHT_UP
)));
1975 wxevent
.m_shiftDown
= local_event
.xbutton
.state
& ShiftMask
;
1976 wxevent
.m_controlDown
= local_event
.xbutton
.state
& ControlMask
;
1977 wxevent
.m_altDown
= local_event
.xbutton
.state
& Mod3Mask
;
1978 wxevent
.m_metaDown
= local_event
.xbutton
.state
& Mod1Mask
;
1979 wxevent
.SetTimestamp(local_event
.xbutton
.time
);
1981 // Now check if we need to translate this event into a double click
1982 if (TRUE
) // canvas->doubleClickAllowed)
1984 if (wxevent
.ButtonDown())
1986 long dclickTime
= XtGetMultiClickTime((Display
*) wxGetDisplay()) ;
1988 // get button and time-stamp
1990 if (wxevent
.LeftDown()) button
= 1;
1991 else if (wxevent
.MiddleDown()) button
= 2;
1992 else if (wxevent
.RightDown()) button
= 3;
1993 long ts
= wxevent
.GetTimestamp();
1994 // check, if single or double click
1995 if (canvas
->m_lastButton
&& canvas
->m_lastButton
==button
&& (ts
- canvas
->m_lastTS
) < dclickTime
)
1998 canvas
->m_lastButton
= 0;
1999 switch ( eventType
)
2001 case wxEVT_LEFT_DOWN
:
2002 wxevent
.SetEventType(wxEVT_LEFT_DCLICK
);
2004 case wxEVT_MIDDLE_DOWN
:
2005 wxevent
.SetEventType(wxEVT_MIDDLE_DCLICK
);
2007 case wxEVT_RIGHT_DOWN
:
2008 wxevent
.SetEventType(wxEVT_RIGHT_DCLICK
);
2018 // not fast enough or different button
2019 canvas
->m_lastTS
= ts
;
2020 canvas
->m_lastButton
= button
;
2025 wxevent
.SetId(canvas
->GetId());
2026 wxevent
.SetEventObject(canvas
);
2027 canvas
->GetEventHandler()->ProcessEvent (wxevent
);
2029 if (eventType == wxEVT_ENTER_WINDOW ||
2030 eventType == wxEVT_LEAVE_WINDOW ||
2031 eventType == wxEVT_MOTION
2040 // XComposeStatus compose;
2041 // (void) XLookupString ((XKeyEvent *) & local_event, wxBuffer, 20, &keySym, &compose);
2042 (void) XLookupString ((XKeyEvent
*) & local_event
, wxBuffer
, 20, &keySym
, NULL
);
2043 int id
= wxCharCodeXToWX (keySym
);
2045 wxKeyEvent
event (wxEVT_CHAR
);
2047 if (local_event
.xkey
.state
& ShiftMask
)
2048 event
.m_shiftDown
= TRUE
;
2049 if (local_event
.xkey
.state
& ControlMask
)
2050 event
.m_controlDown
= TRUE
;
2051 if (local_event
.xkey
.state
& Mod3Mask
)
2052 event
.m_altDown
= TRUE
;
2053 if (local_event
.xkey
.state
& Mod1Mask
)
2054 event
.m_metaDown
= TRUE
;
2055 event
.SetEventObject(canvas
);
2056 event
.m_keyCode
= id
;
2057 event
.SetTimestamp(local_event
.xkey
.time
);
2061 // Implement wxFrame::OnCharHook by checking ancestor.
2062 wxWindow
*parent
= canvas
->GetParent();
2063 while (parent
&& !parent
->IsKindOf(CLASSINFO(wxFrame
)))
2064 parent
= parent
->GetParent();
2068 event
.SetEventType(wxEVT_CHAR_HOOK
);
2069 if (parent
->GetEventHandler()->ProcessEvent(event
))
2071 event
.SetEventType(wxEVT_CHAR
);
2074 canvas
->GetEventHandler()->ProcessEvent (event
);
2080 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2082 wxFocusEvent
event(wxEVT_SET_FOCUS
, canvas
->GetId());
2083 event
.SetEventObject(canvas
);
2084 canvas
->GetEventHandler()->ProcessEvent(event
);
2090 if (local_event
.xfocus
.detail
!= NotifyPointer
)
2092 wxFocusEvent
event(wxEVT_KILL_FOCUS
, canvas
->GetId());
2093 event
.SetEventObject(canvas
);
2094 canvas
->GetEventHandler()->ProcessEvent(event
);
2103 void wxWindow::DoPaint()
2105 //TODO : make a temporary gc so we can do the XCopyArea below
2106 if (0) // m_backingPixmap)
2109 Widget drawingArea = (Widget) m_drawingArea;
2110 // int orig = GetDC()->GetLogicalFunction();
2111 // GetDC()->SetLogicalFunction (wxCOPY);
2113 // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
2114 // should be able to calculate them.
2115 XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
2116 m_pixmapOffsetX, m_pixmapOffsetY,
2117 m_pixmapWidth, m_pixmapHeight,
2120 // GetDC()->SetLogicalFunction (orig);
2125 wxPaintEvent
event(GetId());
2126 event
.SetEventObject(this);
2127 GetEventHandler()->ProcessEvent(event
);
2131 // SetSize, but as per old wxCanvas (with drawing widget etc.)
2132 void wxWindow::CanvasSetSize (int x
, int y
, int w
, int h
, int sizeFlags
)
2134 Widget drawingArea
= (Widget
) m_drawingArea
;
2135 bool managed
= XtIsManaged(m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2138 XtUnmanageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2139 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2141 if (x
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2143 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2147 if (y
> -1 || (sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
2149 XtVaSetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
,
2157 XtVaSetValues ((Widget
) m_borderWidget
, XmNwidth
, w
, NULL
);
2158 short thick
, margin
;
2159 XtVaGetValues ((Widget
) m_borderWidget
,
2160 XmNshadowThickness
, &thick
,
2161 XmNmarginWidth
, &margin
,
2163 w
-= 2 * (thick
+ margin
);
2166 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNwidth
, w
, NULL
);
2170 XtVaGetValues ((Widget
) m_scrolledWindow
,
2171 XmNspacing
, &spacing
,
2172 XmNverticalScrollBar
, &sbar
,
2176 XtVaGetValues (sbar
, XmNwidth
, &wsbar
, NULL
);
2180 w
-= (spacing
+ wsbar
);
2182 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2188 XtVaSetValues ((Widget
) m_borderWidget
, XmNheight
, h
, NULL
);
2189 short thick
, margin
;
2190 XtVaGetValues ((Widget
) m_borderWidget
,
2191 XmNshadowThickness
, &thick
,
2192 XmNmarginHeight
, &margin
,
2194 h
-= 2 * (thick
+ margin
);
2197 XtVaSetValues ((Widget
) m_scrolledWindow
, XmNheight
, h
, NULL
);
2201 XtVaGetValues ((Widget
) m_scrolledWindow
,
2202 XmNspacing
, &spacing
,
2203 XmNhorizontalScrollBar
, &sbar
,
2207 XtVaGetValues (sbar
, XmNheight
, &wsbar
, NULL
);
2211 h
-= (spacing
+ wsbar
);
2213 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2216 XtManageChild (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
);
2217 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2220 GetClientSize (&ww
, &hh
);
2221 wxSizeEvent
sizeEvent(wxSize(ww
, hh
), GetId());
2222 sizeEvent
.SetEventObject(this);
2224 GetEventHandler()->ProcessEvent(sizeEvent
);
2227 void wxWindow::CanvasSetClientSize (int w
, int h
)
2229 Widget drawingArea
= (Widget
) m_drawingArea
;
2231 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_ANY
, NULL
);
2234 XtVaSetValues ((Widget
) m_drawingArea
, XmNwidth
, w
, NULL
);
2236 XtVaSetValues ((Widget
) m_drawingArea
, XmNheight
, h
, NULL
);
2237 /* TODO: is this necessary?
2238 allowRepainting = FALSE;
2240 XSync (XtDisplay (drawingArea), FALSE);
2242 while (XtAppPending (wxTheApp->appContext))
2244 XFlush (XtDisplay (drawingArea));
2245 XtAppNextEvent (wxTheApp->appContext, &event);
2246 XtDispatchEvent (&event);
2250 XtVaSetValues((Widget
) m_drawingArea
, XmNresizePolicy
, XmRESIZE_NONE
, NULL
);
2253 allowRepainting = TRUE;
2257 wxSizeEvent
sizeEvent(wxSize(w
, h
), GetId());
2258 sizeEvent
.SetEventObject(this);
2260 GetEventHandler()->ProcessEvent(sizeEvent
);
2263 void wxWindow::CanvasGetClientSize (int *w
, int *h
) const
2265 // Must return the same thing that was set via SetClientSize
2267 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2272 void wxWindow::CanvasGetSize (int *w
, int *h
) const
2275 if ((Widget
) m_borderWidget
)
2276 XtVaGetValues ((Widget
) m_borderWidget
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2277 else if ((Widget
) m_scrolledWindow
)
2278 XtVaGetValues ((Widget
) m_scrolledWindow
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2280 XtVaGetValues ((Widget
) m_drawingArea
, XmNwidth
, &xx
, XmNheight
, &yy
, NULL
);
2286 void wxWindow::CanvasGetPosition (int *x
, int *y
) const
2289 XtVaGetValues (m_borderWidget
? (Widget
) m_borderWidget
: (Widget
) m_scrolledWindow
, XmNx
, &xx
, XmNy
, &yy
, NULL
);