1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface for wxWindow
7 // Created: 24-June-1997
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
24 class wxWindow : public wxEvtHandler
27 %addtofunc wxWindow "self._setOORInfo(self)"
28 %addtofunc wxWindow() ""
30 wxWindow(wxWindow* parent, const wxWindowID id,
31 const wxPoint& pos = wxDefaultPosition,
32 const wxSize& size = wxDefaultSize,
34 const wxString& name = wxPyPanelNameStr);
35 %name(PreWindow)wxWindow();
37 bool Create(wxWindow* parent, const wxWindowID id,
38 const wxPoint& pos = wxDefaultPosition,
39 const wxSize& size = wxDefaultSize,
41 const wxString& name = wxPyPanelNameStr);
45 // deleting the window
46 // -------------------
48 // ask the window to close itself, return TRUE if the event handler
49 // honoured our request
50 bool Close( bool force = FALSE );
52 // delete window unconditionally (dangerous!), returns TRUE if ok
53 virtual bool Destroy();
55 // delete all children of this window, returns TRUE if ok
56 bool DestroyChildren();
58 // is the window being deleted?
59 bool IsBeingDeleted() const;
65 // the text which the window shows in the title if applicable
66 virtual void SetTitle( const wxString& WXUNUSED(title) );
67 virtual wxString GetTitle() const;
69 // the text which the window shows in its label if applicable
70 virtual void SetLabel(const wxString& label);
71 virtual wxString GetLabel() const;
73 // the window name is used for ressource setting in X, it is not the
74 // same as the window title/label
75 virtual void SetName( const wxString &name );
76 virtual wxString GetName() const;
78 // window id uniquely identifies the window among its siblings unless
79 // it is -1 which means "don't care"
80 void SetId( wxWindowID winid );
81 wxWindowID GetId() const;
83 // generate a control id for the controls which were not given one by
85 static int NewControlId();
87 // get the id of the control following the one with the given
89 static int NextControlId(int winid);
91 // get the id of the control preceding the one with the given
93 static int PrevControlId(int winid);
100 // set the window size
101 void SetSize( const wxSize& size );
103 // set the window size and position
104 %name(SetDimensions) void SetSize( int x, int y, int width, int height,
105 int sizeFlags = wxSIZE_AUTO );
107 // set the window size and position with a wxRect
108 %name(SetRect) void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO);
111 %name(SetSizeWH)void SetSize( int width, int height );
113 // set window position
114 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING);
115 %pythoncode { SetPosition = Move }
117 // set window position
118 %name(MoveXY) void Move(int x, int y, int flags = wxSIZE_USE_EXISTING);
121 virtual void Raise();
122 virtual void Lower();
124 // client size is the size of the area available for subwindows
125 void SetClientSize( const wxSize& size );
126 %name(SetClientSizeWH) void SetClientSize( int width, int height );
127 %name(SetClientRect) void SetClientSize(const wxRect& rect);
130 // get the window position
131 wxPoint GetPosition() const;
132 %name(GetPositionTuple) void GetPosition( int *OUTPUT, int *OUTPUT ) const;
135 // get the window size
136 wxSize GetSize() const;
137 %name(GetSizeTuple) void GetSize( int *OUTPUT, int *OUTPUT ) const;
139 // get the window position and size
140 wxRect GetRect() const;
142 // get the window's client size
143 wxSize GetClientSize() const;
144 %name(GetClientSizeTuple) void GetClientSize( int *OUTPUT, int *OUTPUT ) const;
147 // get the origin of the client area of the window relative to the
148 // window top left corner (the client area may be shifted because of
149 // the borders, scrollbars, other decorations...)
150 virtual wxPoint GetClientAreaOrigin() const;
152 // get the client rectangle in window (i.e. client) coordinates
153 wxRect GetClientRect() const;
155 // get the size best suited for the window (in fact, minimal
156 // acceptable size using which it will still look "nice")
157 wxSize GetBestSize() const;
158 %name(GetBestSizeTuple) void GetBestSize(int *OUTPUT, int *OUTPUT) const;
160 // There are times (and windows) where 'Best' size and 'Min' size
161 // are vastly out of sync. This should be remedied somehow, but in
162 // the meantime, this method will return the larger of BestSize
163 // (the window's smallest legible size), and any user specified
165 wxSize GetAdjustedBestSize() const;
168 // the generic center function - centers the window on parent by
169 // default or on screen if it doesn't have parent or
170 // wxCENTER_ON_SCREEN flag is given
171 void Center( int direction = wxBOTH );
172 %pythoncode { Centre = Center }
174 // center on screen (only works for top level windows)
175 void CenterOnScreen(int dir = wxBOTH);
176 %pythoncode { CentreOnScreen = CenterOnScreen }
178 // center with respect to the the parent window
179 void CenterOnParent(int dir = wxBOTH);
180 %pythoncode { CentreOnParent = CenterOnParent }
183 // set window size to wrap around its children
186 // set virtual size to satisfy children
187 virtual void FitInside();
189 // set min/max size of the window
190 virtual void SetSizeHints( int minW, int minH,
191 int maxW = -1, int maxH = -1,
192 int incW = -1, int incH = -1 );
194 virtual void SetVirtualSizeHints( int minW, int minH,
195 int maxW = -1, int maxH = -1 );
197 virtual int GetMinWidth() const;
198 virtual int GetMinHeight() const;
199 int GetMaxWidth() const;
200 int GetMaxHeight() const;
203 // Override this method to control the values given to Sizers etc.
204 virtual wxSize GetMaxSize() const;
206 // Methods for accessing the virtual size of a window. For most
207 // windows this is just the client area of the window, but for
208 // some like scrolled windows it is more or less independent of
209 // the screen window size. You may override the DoXXXVirtual
210 // methods below for classes where that is is the case.
211 void SetVirtualSize( const wxSize &size );
212 %name(SetVirtualSizeWH) void SetVirtualSize( int w, int h );
214 wxSize GetVirtualSize() const;
215 %name(GetVirtualSizeTuple)void GetVirtualSize( int *OUTPUT, int *OUTPUT ) const;
218 // TODO: using directors?
219 // // Override these methods for windows that have a virtual size
220 // // independent of their client size. eg. the virtual area of a
221 // // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
222 // virtual void DoSetVirtualSize( int x, int y );
223 // virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; }
226 // Return the largest of ClientSize and BestSize (as determined
227 // by a sizer, interior children, or other means)
228 virtual wxSize GetBestVirtualSize() const;
235 // returns TRUE if window was shown/hidden, FALSE if the nothing was
236 // done (window was already shown/hidden)
237 virtual bool Show( bool show = TRUE );
240 // returns TRUE if window was enabled/disabled, FALSE if nothing done
241 virtual bool Enable( bool enable = TRUE );
244 bool IsShown() const;
245 bool IsEnabled() const;
247 // get/set window style (setting style won't update the window and so
248 // is only useful for internal usage)
249 virtual void SetWindowStyleFlag( long style );
250 virtual long GetWindowStyleFlag() const;
252 // get/set window style (setting style won't update the window and so
253 // is only useful for internal usage)
254 void SetWindowStyle( long style );
255 long GetWindowStyle() const;
257 bool HasFlag(int flag) const;
258 virtual bool IsRetained() const;
260 // extra style: the less often used style bits which can't be set with
261 // SetWindowStyleFlag()
262 virtual void SetExtraStyle(long exStyle);
263 long GetExtraStyle() const;
265 // make the window modal (all other windows unresponsive)
266 virtual void MakeModal(bool modal = TRUE);
268 virtual void SetThemeEnabled(bool enableTheme);
269 virtual bool GetThemeEnabled() const;
271 // controls by default inherit the colours of their parents, if a
272 // particular control class doesn't want to do it, it can override
273 // ShouldInheritColours() to return false
274 virtual bool ShouldInheritColours() const;
277 // focus and keyboard handling
278 // ---------------------------
280 // set focus to this window
281 virtual void SetFocus();
283 // set focus to this window as the result of a keyboard action
284 virtual void SetFocusFromKbd();
286 // return the window which currently has the focus or NULL
287 static wxWindow *FindFocus();
289 // can this window have focus?
290 virtual bool AcceptsFocus() const;
292 // can this window be given focus by keyboard navigation? if not, the
293 // only way to give it focus (provided it accepts it at all) is to
295 virtual bool AcceptsFocusFromKeyboard() const;
297 // get the default child of this parent, i.e. the one which is
298 // activated by pressing <Enter>
299 virtual wxWindow *GetDefaultItem() const;
301 // set this child as default, return the old default
302 virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child));
304 // set this child as temporary default
305 virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win));
309 // parent/children relations
310 // -------------------------
312 // get the list of children
313 //wxWindowList& GetChildren(); // TODO: Do a typemap or a wrapper for wxWindowList
315 PyObject* GetChildren() {
316 wxWindowList& list = self->GetChildren();
317 return wxPy_ConvertList(&list);
321 // get the parent or the parent of the parent
322 wxWindow *GetParent() const;
323 wxWindow *GetGrandParent() const;
325 // is this window a top level one?
326 virtual bool IsTopLevel() const;
328 // change the real parent of this window, return TRUE if the parent
329 // was changed, FALSE otherwise (error or newParent == oldParent)
330 virtual bool Reparent( wxWindow *newParent );
332 // implementation mostly
333 virtual void AddChild( wxWindow *child );
334 virtual void RemoveChild( wxWindow *child );
338 // looking for windows
339 // -------------------
341 // find window among the descendants of this one either by id or by
342 // name (return NULL if not found)
343 %name(FindWindowById) wxWindow *FindWindow( long winid );
344 %name(FindWindowByName) wxWindow *FindWindow( const wxString& name );
347 // event handler stuff
348 // -------------------
350 // get the current event handler
351 wxEvtHandler *GetEventHandler() const;
353 // replace the event handler (allows to completely subclass the
355 void SetEventHandler( wxEvtHandler *handler );
357 // push/pop event handler: allows to chain a custom event handler to
358 // alreasy existing ones
359 void PushEventHandler( wxEvtHandler *handler );
360 wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE );
362 // find the given handler in the event handler chain and remove (but
363 // not delete) it from the event handler chain, return TRUE if it was
364 // found and FALSE otherwise (this also results in an assert failure so
365 // this function should only be called when the handler is supposed to
367 bool RemoveEventHandler(wxEvtHandler *handler);
374 // a window may have an associated validator which is used to control
376 virtual void SetValidator( const wxValidator &validator );
377 virtual wxValidator *GetValidator();
383 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
384 wxAcceleratorTable *GetAcceleratorTable();
389 // hot keys (system wide accelerators)
390 // -----------------------------------
392 // hot keys (system wide accelerators)
393 bool RegisterHotKey(int hotkeyId, int modifiers, int keycode) {
395 return self->RegisterHotKey(hotkeyId, modifiers, keycode);
401 bool UnregisterHotKey(int hotkeyId) {
403 return self->UnregisterHotKey(hotkeyId);
412 // "dialog units" translations
413 // ---------------------------
415 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
416 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
418 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
419 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
421 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
422 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
429 // move the mouse to the specified position
430 virtual void WarpPointer(int x, int y);
432 // start or end mouse capture, these functions maintain the stack of
433 // windows having captured the mouse and after calling ReleaseMouse()
434 // the mouse is not released but returns to the window which had had
435 // captured it previously (if any)
439 // get the window which currently captures the mouse or NULL
440 static wxWindow *GetCapture();
442 // does this window have the capture?
443 virtual bool HasCapture() const;
447 // painting the window
448 // -------------------
450 // mark the specified rectangle (or the whole window) as "dirty" so it
452 virtual void Refresh( bool eraseBackground = TRUE,
453 const wxRect *rect = NULL );
455 // a less awkward wrapper for Refresh
456 void RefreshRect(const wxRect& rect);
458 // repaint all invalid areas of the window immediately
459 virtual void Update();
461 // clear the window background
462 virtual void ClearBackground();
464 // freeze the window: don't redraw it until it is thawed
465 virtual void Freeze();
467 // thaw the window: redraw it after it had been frozen
470 // adjust DC for drawing on this window
471 virtual void PrepareDC( wxDC & WXUNUSED(dc) );
473 // the update region of the window contains the areas which must be
474 // repainted by the program
475 wxRegion& GetUpdateRegion();
477 // get the update rectangle region bounding box in client coords
478 wxRect GetUpdateClientRect() const;
480 // these functions verify whether the given point/rectangle belongs to
481 // (or at least intersects with) the update region
482 bool IsExposed( int x, int y, int w=1, int h=1 ) const;
483 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt ) const;
484 %name(isExposedRect) bool IsExposed( const wxRect& rect ) const;
488 // colours, fonts and cursors
489 // --------------------------
491 // set/retrieve the window colours (system defaults are used by
492 // default): Set functions return TRUE if colour was changed
493 virtual bool SetBackgroundColour( const wxColour &colour );
494 virtual bool SetForegroundColour( const wxColour &colour );
496 wxColour GetBackgroundColour() const;
497 wxColour GetForegroundColour() const;
499 // set/retrieve the cursor for this window (SetCursor() returns TRUE
500 // if the cursor was really changed)
501 virtual bool SetCursor( const wxCursor &cursor );
502 wxCursor& GetCursor();
504 // set/retrieve the font for the window (SetFont() returns TRUE if the
505 // font really changed)
506 virtual bool SetFont( const wxFont &font );
509 // associate a caret with the window
510 void SetCaret(wxCaret *caret);
512 // get the current caret (may be NULL)
513 wxCaret *GetCaret() const;
515 // get the (average) character size for the current font
516 virtual int GetCharHeight() const;
517 virtual int GetCharWidth() const;
519 // get the width/height/... of the text using current or specified
521 virtual void GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT); // x, y
522 %name(GetFullTextExtent) virtual void GetTextExtent(const wxString& string,
523 int *OUTPUT, int *OUTPUT, // x, y
524 int *OUTPUT, int* OUTPUT, // descent, externalLeading
525 const wxFont* font = NULL);
528 // client <-> screen coords
529 // ------------------------
531 %apply int * INOUT { int* x, int* y };
533 // translate to/from screen/client coordinates
534 %name(ClientToScreenXY) void ClientToScreen( int *x, int *y ) const;
535 %name(ScreenToClientXY) void ScreenToClient( int *x, int *y ) const;
537 wxPoint ClientToScreen(const wxPoint& pt) const;
538 wxPoint ScreenToClient(const wxPoint& pt) const;
540 // test where the given (in client coords) point lies
541 %name(HitTestXY) wxHitTest HitTest(wxCoord x, wxCoord y) const;
542 wxHitTest HitTest(const wxPoint& pt) const;
549 // get the window border style from the given flags: this is different from
550 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
551 // translate wxBORDER_DEFAULT to something reasonable
552 %name(GetBorderFlags) wxBorder GetBorder(long flags) const;
554 // get border for the flags of this window
555 wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
557 // send wxUpdateUIEvents to this window, and children if recurse is TRUE
558 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
560 // TODO: using directors?
561 // // do the window-specific processing after processing the update event
562 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
564 %name(PopupMenuXY) bool PopupMenu(wxMenu *menu, int x, int y);
565 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
569 return wxPyGetWinHandle(self);
575 // A way to do the native draw first... Too bad it isn't in wxGTK too.
576 void OnPaint(wxPaintEvent& event);
584 // does the window have the scrollbar for this orientation?
585 bool HasScrollbar(int orient) const;
587 // configure the window scrollbars
588 virtual void SetScrollbar( int orient,
592 bool refresh = TRUE );
593 virtual void SetScrollPos( int orient, int pos, bool refresh = TRUE );
594 virtual int GetScrollPos( int orient ) const;
595 virtual int GetScrollThumb( int orient ) const;
596 virtual int GetScrollRange( int orient ) const;
598 // scroll window to the specified position
599 virtual void ScrollWindow( int dx, int dy,
600 const wxRect* rect = NULL );
602 // scrolls window by line/page: note that not all controls support this
604 // return TRUE if the position changed, FALSE otherwise
605 virtual bool ScrollLines(int WXUNUSED(lines));
606 virtual bool ScrollPages(int WXUNUSED(pages));
608 // convenient wrappers for ScrollLines/Pages
616 // context-sensitive help
617 // ----------------------
619 // associate this help text with this window
620 void SetHelpText(const wxString& text);
622 // associate this help text with all windows with the same id as this
624 void SetHelpTextForId(const wxString& text);
626 // get the help string associated with this window (may be empty)
627 wxString GetHelpText() const;
634 // the easiest way to set a tooltip for a window is to use this method
635 %name(SetToolTipString) void SetToolTip( const wxString &tip );
637 // attach a tooltip to the window
638 void SetToolTip( wxToolTip *tip );
640 // get the associated tooltip or NULL if none
641 wxToolTip* GetToolTip() const;
642 // LINK ERROR --> wxString GetToolTipText() const;
649 // set/retrieve the drop target associated with this window (may be
650 // NULL; it's owned by the window and will be deleted by it)
651 %addtofunc SetDropTarget "args[1].thisown = 0"
652 virtual void SetDropTarget( wxDropTarget *dropTarget );
653 virtual wxDropTarget *GetDropTarget() const;
655 #ifdef __WXMSW__ // TODO: should I drop-kick this?
656 void DragAcceptFiles(bool accept);
660 // constraints and sizers
661 // ----------------------
663 // set the constraints for this window or retrieve them (may be NULL)
664 void SetConstraints( wxLayoutConstraints *constraints );
665 wxLayoutConstraints *GetConstraints() const;
667 // when using constraints or sizers, it makes sense to update
668 // children positions automatically whenever the window is resized
669 // - this is done if autoLayout is on
670 void SetAutoLayout( bool autoLayout );
671 bool GetAutoLayout() const;
673 // lay out the window and its children
674 virtual bool Layout();
677 void SetSizer(wxSizer *sizer, bool deleteOld = TRUE );
678 void SetSizerAndFit( wxSizer *sizer, bool deleteOld = TRUE );
680 wxSizer *GetSizer() const;
682 // Track if this window is a member of a sizer
683 void SetContainingSizer(wxSizer* sizer);
684 wxSizer *GetContainingSizer() const;
689 // ----------------------
690 #if wxUSE_ACCESSIBILITY
691 // Override to create a specific accessible object.
692 virtual wxAccessible* CreateAccessible();
694 // Sets the accessible object.
695 void SetAccessible(wxAccessible* accessible) ;
697 // Returns the accessible object.
698 wxAccessible* GetAccessible() { return m_accessible; };
700 // Returns the accessible object, creating if necessary.
701 wxAccessible* GetOrCreateAccessible() ;
707 def PostCreate(self, pre):
708 """Phase 3 of the 2-phase create <wink!>
709 Call this method after precreating the window with the 2-phase create method."""
711 self.thisown = pre.thisown
713 if hasattr(self, '_setOORInfo'):
714 self._setOORInfo(self)
715 if hasattr(self, '_setCallbackInfo'):
716 self._setCallbackInfo(self, self.__class__)
728 def DLG_PNT(win, point_or_x, y=None):
730 return win.ConvertDialogPointToPixels(point_or_x)
732 return win.ConvertDialogPointToPixels(wxPoint(point_or_x, y))
734 def DLG_SZE(win, size_width, height=None):
736 return win.ConvertDialogSizeToPixels(size_width)
738 return win.ConvertDialogSizeToPixels(wxSize(size_width, height))
744 // Unfortunatly the names of these new static methods clash with the
745 // names wxPython has been using forever for the overloaded
746 // wxWindow::FindWindow, so instead of swigging them as statics create
747 // standalone functions for them.
750 // Find a window among any window in the application (all return NULL if not found)
752 wxWindow* wxFindWindowById( long id, const wxWindow *parent = NULL ) {
753 return wxWindow::FindWindowById(id, parent);
756 wxWindow* wxFindWindowByName( const wxString& name,
757 const wxWindow *parent = NULL ) {
758 return wxWindow::FindWindowByName(name, parent);
761 wxWindow* wxFindWindowByLabel( const wxString& label,
762 const wxWindow *parent = NULL ) {
763 return wxWindow::FindWindowByLabel(label, parent);
770 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
772 wxWindow* win = new wxWindow;
774 win->SubclassWin(hWnd);
777 PyErr_SetNone(PyExc_NotImplementedError);
783 //---------------------------------------------------------------------------
784 //---------------------------------------------------------------------------