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 MAKE_CONST_WXSTRING(PanelNameStr);
23 //---------------------------------------------------------------------------
26 class wxWindow : public wxEvtHandler
29 %pythonAppend wxWindow "self._setOORInfo(self)"
30 %pythonAppend wxWindow() ""
32 wxWindow(wxWindow* parent, const wxWindowID id,
33 const wxPoint& pos = wxDefaultPosition,
34 const wxSize& size = wxDefaultSize,
36 const wxString& name = wxPyPanelNameStr);
37 %name(PreWindow)wxWindow();
39 bool Create(wxWindow* parent, const wxWindowID id,
40 const wxPoint& pos = wxDefaultPosition,
41 const wxSize& size = wxDefaultSize,
43 const wxString& name = wxPyPanelNameStr);
47 // deleting the window
48 // -------------------
50 // ask the window to close itself, return True if the event handler
51 // honoured our request
52 bool Close( bool force = False );
54 // delete window unconditionally (dangerous!), returns True if ok
55 virtual bool Destroy();
57 // delete all children of this window, returns True if ok
58 bool DestroyChildren();
60 // is the window being deleted?
61 bool IsBeingDeleted() const;
67 // the text which the window shows in the title if applicable
68 virtual void SetTitle( const wxString& WXUNUSED(title) );
69 virtual wxString GetTitle() const;
71 // the text which the window shows in its label if applicable
72 virtual void SetLabel(const wxString& label);
73 virtual wxString GetLabel() const;
75 // the window name is used for ressource setting in X, it is not the
76 // same as the window title/label
77 virtual void SetName( const wxString &name );
78 virtual wxString GetName() const;
80 // window id uniquely identifies the window among its siblings unless
81 // it is -1 which means "don't care"
82 void SetId( wxWindowID winid );
83 wxWindowID GetId() const;
85 // generate a control id for the controls which were not given one by
87 static int NewControlId();
89 // get the id of the control following the one with the given
91 static int NextControlId(int winid);
93 // get the id of the control preceding the one with the given
95 static int PrevControlId(int winid);
102 // set the window size
103 void SetSize( const wxSize& size );
105 // set the window size and position
106 %name(SetDimensions) void SetSize( int x, int y, int width, int height,
107 int sizeFlags = wxSIZE_AUTO );
109 // set the window size and position with a wxRect
110 %name(SetRect) void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO);
113 %name(SetSizeWH)void SetSize( int width, int height );
115 // set window position
116 void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING);
117 %pythoncode { SetPosition = Move }
119 // set window position
120 %name(MoveXY) void Move(int x, int y, int flags = wxSIZE_USE_EXISTING);
123 virtual void Raise();
124 virtual void Lower();
126 // client size is the size of the area available for subwindows
127 void SetClientSize( const wxSize& size );
128 %name(SetClientSizeWH) void SetClientSize( int width, int height );
129 %name(SetClientRect) void SetClientSize(const wxRect& rect);
132 DocStr(GetPosition, // sets the docstring for both
133 "Get the window's position.");
134 wxPoint GetPosition();
137 void, GetPosition(int *OUTPUT, int *OUTPUT),
138 "GetPositionTuple() -> (x,y)",
142 DocStr(GetSize, "Get the window size.");
143 wxSize GetSize() const;
145 void, GetSize( int *OUTPUT, int *OUTPUT ) const,
146 "GetSizeTuple() -> (width, height)",
150 // get the window position and size
151 wxRect GetRect() const;
153 DocStr(GetClientSize, "Get the window's client size.");
154 wxSize GetClientSize() const;
156 void, GetClientSize( int *OUTPUT, int *OUTPUT ) const,
157 "GetClientSizeTuple() -> (width, height)",
161 // get the origin of the client area of the window relative to the
162 // window top left corner (the client area may be shifted because of
163 // the borders, scrollbars, other decorations...)
164 virtual wxPoint GetClientAreaOrigin() const;
166 // get the client rectangle in window (i.e. client) coordinates
167 wxRect GetClientRect() const;
170 "Get the size best suited for the window (in fact, minimal acceptable size\n"
171 "using which it will still look \"nice\")");
172 wxSize GetBestSize() const;
174 void, GetBestSize(int *OUTPUT, int *OUTPUT) const,
175 "GetBestSizeTuple() -> (width, height)",
179 // There are times (and windows) where 'Best' size and 'Min' size
180 // are vastly out of sync. This should be remedied somehow, but in
181 // the meantime, this method will return the larger of BestSize
182 // (the window's smallest legible size), and any user specified
184 wxSize GetAdjustedBestSize() const;
187 // the generic center function - centers the window on parent by
188 // default or on screen if it doesn't have parent or
189 // wxCENTER_ON_SCREEN flag is given
190 void Center( int direction = wxBOTH );
191 %pythoncode { Centre = Center }
193 // center on screen (only works for top level windows)
194 void CenterOnScreen(int dir = wxBOTH);
195 %pythoncode { CentreOnScreen = CenterOnScreen }
197 // center with respect to the the parent window
198 void CenterOnParent(int dir = wxBOTH);
199 %pythoncode { CentreOnParent = CenterOnParent }
202 // set window size to wrap around its children
205 // set virtual size to satisfy children
206 virtual void FitInside();
208 // set min/max size of the window
209 virtual void SetSizeHints( int minW, int minH,
210 int maxW = -1, int maxH = -1,
211 int incW = -1, int incH = -1 );
213 virtual void SetVirtualSizeHints( int minW, int minH,
214 int maxW = -1, int maxH = -1 );
216 virtual int GetMinWidth() const;
217 virtual int GetMinHeight() const;
218 int GetMaxWidth() const;
219 int GetMaxHeight() const;
222 // Override this method to control the values given to Sizers etc.
223 virtual wxSize GetMaxSize() const;
226 DocStr(SetVirtualSize,
227 "Set the the virtual size of a window. For most windows this is just the\n"
228 "client area of the window, but for some like scrolled windows it is more or\n"
229 "less independent of the screen window size.");
230 void SetVirtualSize(const wxSize& size );
231 %name(SetVirtualSizeWH) void SetVirtualSize( int w, int h );
234 DocStr(GetVirtualSize,
235 "Get the the virtual size of the window. For most windows this is just\n"
236 "the client area of the window, but for some like scrolled windows it is\n"
237 "more or less independent of the screen window size.");
238 wxSize GetVirtualSize() const;
240 void, GetVirtualSize( int *OUTPUT, int *OUTPUT ) const,
241 "GetVirtualSizeTuple() -> (width, height)",
242 GetVirtualSizeTuple);
245 // TODO: using directors?
246 // // Override these methods for windows that have a virtual size
247 // // independent of their client size. eg. the virtual area of a
248 // // wxScrolledWindow. Default is to alias VirtualSize to ClientSize.
249 // virtual void DoSetVirtualSize( int x, int y );
250 // virtual wxSize DoGetVirtualSize() const; // { return m_virtualSize; }
253 // Return the largest of ClientSize and BestSize (as determined
254 // by a sizer, interior children, or other means)
255 virtual wxSize GetBestVirtualSize() const;
262 // returns True if window was shown/hidden, False if the nothing was
263 // done (window was already shown/hidden)
264 virtual bool Show( bool show = True );
267 // returns True if window was enabled/disabled, False if nothing done
268 virtual bool Enable( bool enable = True );
271 bool IsShown() const;
272 bool IsEnabled() const;
274 // get/set window style (setting style won't update the window and so
275 // is only useful for internal usage)
276 virtual void SetWindowStyleFlag( long style );
277 virtual long GetWindowStyleFlag() const;
279 // get/set window style (setting style won't update the window and so
280 // is only useful for internal usage)
281 void SetWindowStyle( long style );
282 long GetWindowStyle() const;
284 bool HasFlag(int flag) const;
285 virtual bool IsRetained() const;
287 // extra style: the less often used style bits which can't be set with
288 // SetWindowStyleFlag()
289 virtual void SetExtraStyle(long exStyle);
290 long GetExtraStyle() const;
292 // make the window modal (all other windows unresponsive)
293 virtual void MakeModal(bool modal = True);
295 virtual void SetThemeEnabled(bool enableTheme);
296 virtual bool GetThemeEnabled() const;
298 // controls by default inherit the colours of their parents, if a
299 // particular control class doesn't want to do it, it can override
300 // ShouldInheritColours() to return False
301 virtual bool ShouldInheritColours() const;
304 // focus and keyboard handling
305 // ---------------------------
307 // set focus to this window
308 virtual void SetFocus();
310 // set focus to this window as the result of a keyboard action
311 virtual void SetFocusFromKbd();
313 // return the window which currently has the focus or NULL
314 static wxWindow *FindFocus();
316 // can this window have focus?
317 virtual bool AcceptsFocus() const;
319 // can this window be given focus by keyboard navigation? if not, the
320 // only way to give it focus (provided it accepts it at all) is to
322 virtual bool AcceptsFocusFromKeyboard() const;
324 // get the default child of this parent, i.e. the one which is
325 // activated by pressing <Enter>
326 virtual wxWindow *GetDefaultItem() const;
328 // set this child as default, return the old default
329 virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child));
331 // set this child as temporary default
332 virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win));
336 // parent/children relations
337 // -------------------------
339 // get the list of children
340 //wxWindowList& GetChildren(); // TODO: Do a typemap or a wrapper for wxWindowList
342 PyObject* GetChildren() {
343 wxWindowList& list = self->GetChildren();
344 return wxPy_ConvertList(&list);
348 // get the parent or the parent of the parent
349 wxWindow *GetParent() const;
350 wxWindow *GetGrandParent() const;
352 // is this window a top level one?
353 virtual bool IsTopLevel() const;
355 // change the real parent of this window, return True if the parent
356 // was changed, False otherwise (error or newParent == oldParent)
357 virtual bool Reparent( wxWindow *newParent );
359 // implementation mostly
360 virtual void AddChild( wxWindow *child );
361 virtual void RemoveChild( wxWindow *child );
365 // looking for windows
366 // -------------------
368 // find window among the descendants of this one either by id or by
369 // name (return NULL if not found)
370 %name(FindWindowById) wxWindow *FindWindow( long winid );
371 %name(FindWindowByName) wxWindow *FindWindow( const wxString& name );
374 // event handler stuff
375 // -------------------
377 // get the current event handler
378 wxEvtHandler *GetEventHandler() const;
380 // replace the event handler (allows to completely subclass the
382 void SetEventHandler( wxEvtHandler *handler );
384 // push/pop event handler: allows to chain a custom event handler to
385 // alreasy existing ones
386 void PushEventHandler( wxEvtHandler *handler );
387 wxEvtHandler *PopEventHandler( bool deleteHandler = False );
389 // find the given handler in the event handler chain and remove (but
390 // not delete) it from the event handler chain, return True if it was
391 // found and False otherwise (this also results in an assert failure so
392 // this function should only be called when the handler is supposed to
394 bool RemoveEventHandler(wxEvtHandler *handler);
401 // a window may have an associated validator which is used to control
403 virtual void SetValidator( const wxValidator &validator );
404 virtual wxValidator *GetValidator();
410 virtual void SetAcceleratorTable( const wxAcceleratorTable& accel );
411 wxAcceleratorTable *GetAcceleratorTable();
416 // hot keys (system wide accelerators)
417 // -----------------------------------
419 // hot keys (system wide accelerators)
420 bool RegisterHotKey(int hotkeyId, int modifiers, int keycode) {
422 return self->RegisterHotKey(hotkeyId, modifiers, keycode);
428 bool UnregisterHotKey(int hotkeyId) {
430 return self->UnregisterHotKey(hotkeyId);
439 // "dialog units" translations
440 // ---------------------------
442 %name(ConvertDialogPointToPixels) wxPoint ConvertDialogToPixels(const wxPoint& pt);
443 %name(ConvertDialogSizeToPixels) wxSize ConvertDialogToPixels(const wxSize& sz);
445 %name(DLG_PNT) wxPoint ConvertDialogToPixels(const wxPoint& pt);
446 %name(DLG_SZE) wxSize ConvertDialogToPixels(const wxSize& sz);
448 %name(ConvertPixelPointToDialog) wxPoint ConvertPixelsToDialog(const wxPoint& pt);
449 %name(ConvertPixelSizeToDialog) wxSize ConvertPixelsToDialog(const wxSize& sz);
456 // move the mouse to the specified position
457 virtual void WarpPointer(int x, int y);
459 // start or end mouse capture, these functions maintain the stack of
460 // windows having captured the mouse and after calling ReleaseMouse()
461 // the mouse is not released but returns to the window which had had
462 // captured it previously (if any)
466 // get the window which currently captures the mouse or NULL
467 static wxWindow *GetCapture();
469 // does this window have the capture?
470 virtual bool HasCapture() const;
474 // painting the window
475 // -------------------
477 // mark the specified rectangle (or the whole window) as "dirty" so it
479 virtual void Refresh( bool eraseBackground = True,
480 const wxRect *rect = NULL );
482 // a less awkward wrapper for Refresh
483 void RefreshRect(const wxRect& rect);
485 // repaint all invalid areas of the window immediately
486 virtual void Update();
488 // clear the window background
489 virtual void ClearBackground();
491 // freeze the window: don't redraw it until it is thawed
492 virtual void Freeze();
494 // thaw the window: redraw it after it had been frozen
497 // adjust DC for drawing on this window
498 virtual void PrepareDC( wxDC & WXUNUSED(dc) );
500 // the update region of the window contains the areas which must be
501 // repainted by the program
502 wxRegion& GetUpdateRegion();
504 // get the update rectangle region bounding box in client coords
505 wxRect GetUpdateClientRect() const;
507 // these functions verify whether the given point/rectangle belongs to
508 // (or at least intersects with) the update region
509 bool IsExposed( int x, int y, int w=1, int h=1 ) const;
510 %name(IsExposedPoint) bool IsExposed( const wxPoint& pt ) const;
511 %name(isExposedRect) bool IsExposed( const wxRect& rect ) const;
515 // colours, fonts and cursors
516 // --------------------------
518 // set/retrieve the window colours (system defaults are used by
519 // default): Set functions return True if colour was changed
520 virtual bool SetBackgroundColour( const wxColour &colour );
521 virtual bool SetForegroundColour( const wxColour &colour );
523 wxColour GetBackgroundColour() const;
524 wxColour GetForegroundColour() const;
526 // set/retrieve the cursor for this window (SetCursor() returns True
527 // if the cursor was really changed)
528 virtual bool SetCursor( const wxCursor &cursor );
529 wxCursor& GetCursor();
531 // set/retrieve the font for the window (SetFont() returns True if the
532 // font really changed)
533 virtual bool SetFont( const wxFont &font );
536 // associate a caret with the window
537 void SetCaret(wxCaret *caret);
539 // get the current caret (may be NULL)
540 wxCaret *GetCaret() const;
542 // get the (average) character size for the current font
543 virtual int GetCharHeight() const;
544 virtual int GetCharWidth() const;
548 void, GetTextExtent(const wxString& string, int *OUTPUT, int *OUTPUT),
549 "GetTextExtent(String string) -> (width, height)",
550 "Get the width and height of the text using the current font.");
552 void, GetTextExtent(const wxString& string,
553 int *OUTPUT, int *OUTPUT, int *OUTPUT, int* OUTPUT,
554 const wxFont* font = NULL),
555 "GetFullTextExtent(String string, Font font=None) ->\n (width, height, descent, externalLeading)",
556 "Get the width, height, decent and leading of the text using the current or specified font.",
561 // client <-> screen coords
562 // ------------------------
564 %apply int * INOUT { int* x, int* y };
566 // translate to/from screen/client coordinates
567 %name(ClientToScreenXY) void ClientToScreen( int *x, int *y ) const;
568 %name(ScreenToClientXY) void ScreenToClient( int *x, int *y ) const;
570 wxPoint ClientToScreen(const wxPoint& pt) const;
571 wxPoint ScreenToClient(const wxPoint& pt) const;
573 // test where the given (in client coords) point lies
574 %name(HitTestXY) wxHitTest HitTest(wxCoord x, wxCoord y) const;
575 wxHitTest HitTest(const wxPoint& pt) const;
582 // get the window border style from the given flags: this is different from
583 // simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to
584 // translate wxBORDER_DEFAULT to something reasonable
585 %name(GetBorderFlags) wxBorder GetBorder(long flags) const;
587 // get border for the flags of this window
588 wxBorder GetBorder() const { return GetBorder(GetWindowStyleFlag()); }
590 // send wxUpdateUIEvents to this window, and children if recurse is True
591 virtual void UpdateWindowUI(long flags = wxUPDATE_UI_NONE);
593 // TODO: using directors?
594 // // do the window-specific processing after processing the update event
595 // virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ;
597 %name(PopupMenuXY) bool PopupMenu(wxMenu *menu, int x, int y);
598 bool PopupMenu(wxMenu *menu, const wxPoint& pos);
602 return wxPyGetWinHandle(self);
608 // A way to do the native draw first... Too bad it isn't in wxGTK too.
609 void OnPaint(wxPaintEvent& event);
617 // does the window have the scrollbar for this orientation?
618 bool HasScrollbar(int orient) const;
620 // configure the window scrollbars
621 virtual void SetScrollbar( int orient,
625 bool refresh = True );
626 virtual void SetScrollPos( int orient, int pos, bool refresh = True );
627 virtual int GetScrollPos( int orient ) const;
628 virtual int GetScrollThumb( int orient ) const;
629 virtual int GetScrollRange( int orient ) const;
631 // scroll window to the specified position
632 virtual void ScrollWindow( int dx, int dy,
633 const wxRect* rect = NULL );
635 // scrolls window by line/page: note that not all controls support this
637 // return True if the position changed, False otherwise
638 virtual bool ScrollLines(int WXUNUSED(lines));
639 virtual bool ScrollPages(int WXUNUSED(pages));
641 // convenient wrappers for ScrollLines/Pages
649 // context-sensitive help
650 // ----------------------
652 // associate this help text with this window
653 void SetHelpText(const wxString& text);
655 // associate this help text with all windows with the same id as this
657 void SetHelpTextForId(const wxString& text);
659 // get the help string associated with this window (may be empty)
660 wxString GetHelpText() const;
667 // the easiest way to set a tooltip for a window is to use this method
668 %name(SetToolTipString) void SetToolTip( const wxString &tip );
670 // attach a tooltip to the window
671 void SetToolTip( wxToolTip *tip );
673 // get the associated tooltip or NULL if none
674 wxToolTip* GetToolTip() const;
675 // LINK ERROR --> wxString GetToolTipText() const;
684 // set/retrieve the drop target associated with this window (may be
685 // NULL; it's owned by the window and will be deleted by it)
686 %apply SWIGTYPE *DISOWN { wxPyDropTarget *dropTarget };
687 virtual void SetDropTarget( wxPyDropTarget *dropTarget );
688 %clear wxPyDropTarget *dropTarget;
690 virtual wxPyDropTarget *GetDropTarget() const;
692 #ifdef __WXMSW__ // TODO: should I drop-kick this?
693 void DragAcceptFiles(bool accept);
698 // constraints and sizers
699 // ----------------------
701 // set the constraints for this window or retrieve them (may be NULL)
702 void SetConstraints( wxLayoutConstraints *constraints );
703 wxLayoutConstraints *GetConstraints() const;
705 // when using constraints or sizers, it makes sense to update
706 // children positions automatically whenever the window is resized
707 // - this is done if autoLayout is on
708 void SetAutoLayout( bool autoLayout );
709 bool GetAutoLayout() const;
711 // lay out the window and its children
712 virtual bool Layout();
715 void SetSizer(wxSizer *sizer, bool deleteOld = True );
716 void SetSizerAndFit( wxSizer *sizer, bool deleteOld = True );
718 wxSizer *GetSizer() const;
720 // Track if this window is a member of a sizer
721 void SetContainingSizer(wxSizer* sizer);
722 wxSizer *GetContainingSizer() const;
727 // ----------------------
728 #if wxUSE_ACCESSIBILITY
729 // Override to create a specific accessible object.
730 virtual wxAccessible* CreateAccessible();
732 // Sets the accessible object.
733 void SetAccessible(wxAccessible* accessible) ;
735 // Returns the accessible object.
736 wxAccessible* GetAccessible() { return m_accessible; };
738 // Returns the accessible object, creating if necessary.
739 wxAccessible* GetOrCreateAccessible() ;
745 def PostCreate(self, pre):
746 """Phase 3 of the 2-phase create <wink!>
747 Call this method after precreating the window with the 2-phase create method."""
749 self.thisown = pre.thisown
751 if hasattr(self, '_setOORInfo'):
752 self._setOORInfo(self)
753 if hasattr(self, '_setCallbackInfo'):
754 self._setCallbackInfo(self, self.__class__)
766 def DLG_PNT(win, point_or_x, y=None):
768 return win.ConvertDialogPointToPixels(point_or_x)
770 return win.ConvertDialogPointToPixels(wx.Point(point_or_x, y))
772 def DLG_SZE(win, size_width, height=None):
774 return win.ConvertDialogSizeToPixels(size_width)
776 return win.ConvertDialogSizeToPixels(wx.Size(size_width, height))
782 // Unfortunatly the names of these new static methods clash with the
783 // names wxPython has been using forever for the overloaded
784 // wxWindow::FindWindow, so instead of swigging them as statics create
785 // standalone functions for them.
788 // Find a window among any window in the application (all return NULL if not found)
790 wxWindow* wxFindWindowById( long id, const wxWindow *parent = NULL ) {
791 return wxWindow::FindWindowById(id, parent);
794 wxWindow* wxFindWindowByName( const wxString& name,
795 const wxWindow *parent = NULL ) {
796 return wxWindow::FindWindowByName(name, parent);
799 wxWindow* wxFindWindowByLabel( const wxString& label,
800 const wxWindow *parent = NULL ) {
801 return wxWindow::FindWindowByLabel(label, parent);
808 wxWindow* wxWindow_FromHWND(unsigned long hWnd) {
810 wxWindow* win = new wxWindow;
812 win->SubclassWin(hWnd);
815 wxPyRaiseNotImplemented();
821 //---------------------------------------------------------------------------
822 //---------------------------------------------------------------------------