X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ccd4e1bc1ecec7e1db3b40a73601ad265aaec12f..7344108e8a129a3f9b4df5ab0f98a1713db03b89:/interface/wx/window.h?ds=sidebyside diff --git a/interface/wx/window.h b/interface/wx/window.h index 56be9b1845..d98fb8b0ab 100644 --- a/interface/wx/window.h +++ b/interface/wx/window.h @@ -3,7 +3,7 @@ // Purpose: interface of wxWindow // Author: wxWidgets team // RCS-ID: $Id$ -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -50,6 +50,28 @@ enum wxShowEffect wxSHOW_EFFECT_EXPAND }; + + +/** + Struct containing all the visual attributes of a control. +*/ +struct wxVisualAttributes +{ + /// The font used for control label/text inside it. + wxFont font; + + /// The foreground colour. + wxColour colFg; + + /** + The background colour. + + May be wxNullColour if the controls background colour is not solid. + */ + wxColour colBg; +}; + + /** Different window variants, on platforms like eg mac uses different rendering sizes. @@ -218,9 +240,13 @@ enum wxWindowVariant See wxKeyEvent. @event{EVT_KEY_UP(func)} Process a @c wxEVT_KEY_UP event (any key has been released). + See wxKeyEvent. @event{EVT_CHAR(func)} Process a @c wxEVT_CHAR event. See wxKeyEvent. + @event{EVT_CHAR_HOOK(func)} + Process a @c wxEVT_CHAR_HOOK event. + See wxKeyEvent. @event{EVT_MOUSE_CAPTURE_LOST(func)} Process a @c wxEVT_MOUSE_CAPTURE_LOST event. See wxMouseCaptureLostEvent. @event{EVT_MOUSE_CAPTURE_CHANGED(func)} @@ -235,8 +261,6 @@ enum wxWindowVariant Process scroll events. See wxScrollWinEvent. @event{EVT_SET_CURSOR(func)} Process a @c wxEVT_SET_CURSOR event. See wxSetCursorEvent. - @event{EVT_SHOW(func)} - Process a @c wxEVT_SHOW event. See wxShowEvent. @event{EVT_SIZE(func)} Process a @c wxEVT_SIZE event. See wxSizeEvent. @event{EVT_SYS_COLOUR_CHANGED(func)} @@ -297,6 +321,13 @@ public: virtual ~wxWindow(); + bool Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& name = wxPanelNameStr); + /** @name Focus functions @@ -462,11 +493,31 @@ public: @see GetNextSibling() */ wxWindow* GetPrevSibling() const; + /** - Reparents the window, i.e the window will be removed from its + Check if the specified window is a descendant of this one. + + Returns @true if the window is a descendant (i.e. a child or + grand-child or grand-grand-child or ...) of this one. + + Notice that a window can never be a descendant of another one if they + are in different top level windows, i.e. a child of a wxDialog is not + considered to be a descendant of dialogs parent wxFrame. + + @param win Any window, possible @NULL (@false is always returned then). + + @since 2.9.4 + */ + bool IsDescendant(wxWindowBase* win) const; + + /** + Reparents the window, i.e. the window will be removed from its current parent window (e.g. a non-standard toolbar in a wxFrame) and then re-inserted into another. + Notice that currently you need to explicitly call + wxNotebook::RemovePage() before reparenting a notebook page. + @param newParent New parent. */ @@ -686,7 +737,8 @@ public: /** @name Sizing functions - See also the protected functions DoGetBestSize() and SetInitialBestSize(). + See also the protected functions DoGetBestSize() and + DoGetBestClientSize(). */ //@{ @@ -767,13 +819,32 @@ public: wxPanel), the size returned by this function will be the same as the size the window would have had after calling Fit(). - Note that when you write your own widget you need to overload the - DoGetBestSize() function instead of this (non-virtual!) function. + Override virtual DoGetBestSize() or, better, because it's usually more + convenient, DoGetBestClientSize() when writing your own custom window + class to change the value returned by this public non-virtual method. @see CacheBestSize(), @ref overview_windowsizing */ wxSize GetBestSize() const; + /** + Returns the best height needed by this window if it had the given width. + + @see DoGetBestClientHeight() + + @since 2.9.4 + */ + int GetBestHeight(int width) const; + + /** + Returns the best width needed by this window if it had the given height. + + @see DoGetBestClientWidth() + + @since 2.9.4 + */ + int GetBestWidth(int height) const; + /** Returns the size of the window 'client area' in pixels. @@ -851,6 +922,11 @@ public: */ virtual wxSize GetMinSize() const; + int GetMinWidth() const; + int GetMinHeight() const; + int GetMaxWidth() const; + int GetMaxHeight() const; + /** Returns the size of the entire window in pixels, including title bar, border, scrollbars, etc. @@ -896,12 +972,31 @@ public: */ void GetVirtualSize(int* width, int* height) const; + /** + Return the largest of ClientSize and BestSize (as determined + by a sizer, interior children, or other means) + */ + virtual wxSize GetBestVirtualSize() const; + /** Returns the size of the left/right and top/bottom borders of this window in x and y components of the result respectively. */ virtual wxSize GetWindowBorderSize() const; + /** + wxSizer and friends use this to give a chance to a component to recalc + its min size once one of the final size components is known. Override + this function when that is useful (such as for wxStaticText which can + stretch over several lines). Parameter availableOtherDir + tells the item how much more space there is available in the opposite + direction (-1 if unknown). + */ + virtual bool + InformFirstDirection(int direction, + int size, + int availableOtherDir); + /** Resets the cached best size value so it will be recalculated the next time it is needed. @@ -971,12 +1066,17 @@ public: @see @ref overview_windowsizing */ - virtual void SetClientSize(int width, int height); + void SetClientSize(int width, int height); + + /** + @overload + */ + void SetClientSize(const wxSize& size); /** @overload */ - virtual void SetClientSize(const wxSize& size); + void SetClientSize(const wxRect& rect); /** This normally does not need to be called by user code. @@ -1114,17 +1214,17 @@ public: @see Move(), @ref overview_windowsizing */ - virtual void SetSize(const wxRect& rect); + void SetSize(const wxRect& rect); /** @overload */ - virtual void SetSize(const wxSize& size); + void SetSize(const wxSize& size); /** @overload */ - virtual void SetSize(int width, int height); + void SetSize(int width, int height); /** Use of this function for windows which are not toplevel windows @@ -1133,9 +1233,12 @@ public: @see wxTopLevelWindow::SetSizeHints, @ref overview_windowsizing */ - void SetSizeHints( const wxSize& minSize, - const wxSize& maxSize=wxDefaultSize, - const wxSize& incSize=wxDefaultSize); + virtual void SetSizeHints( const wxSize& minSize, + const wxSize& maxSize=wxDefaultSize, + const wxSize& incSize=wxDefaultSize); + virtual void SetSizeHints( int minW, int minH, + int maxW = -1, int maxH = -1, + int incW = -1, int incH = -1 ); /** Sets the virtual size of the window in pixels. @@ -1172,7 +1275,7 @@ public: @param direction Specifies the direction for the centring. May be wxHORIZONTAL, wxVERTICAL - or wxBOTH. It may also include wxCENTRE_ON_SCREEN flag + or wxBOTH. It may also include the wxCENTRE_ON_SCREEN flag if you want to centre the window on the entire screen and not on its parent window. @@ -1198,6 +1301,7 @@ public: @see wxTopLevelWindow::CentreOnScreen */ void CentreOnParent(int direction = wxBOTH); + /** This gets the position of the window in pixels, relative to the parent window for the child windows or relative to the display origin for the top level windows. @@ -1259,6 +1363,20 @@ public: */ wxRect GetScreenRect() const; + /** + Get the origin of the client area of the window relative to the + window top left corner (the client area may be shifted because of + the borders, scrollbars, other decorations...) + */ + virtual wxPoint GetClientAreaOrigin() const; + + /** + Get the client rectangle in window (i.e. client) coordinates + */ + wxRect GetClientRect() const; + + + /** Moves the window to the given position. @@ -1297,6 +1415,8 @@ public: */ void Move(const wxPoint& pt, int flags = wxSIZE_USE_EXISTING); + void SetPosition(const wxPoint& pt); + //@} @@ -1315,12 +1435,6 @@ public: A pointer to a integer value for the y coordinate. Pass the client coordinate in, and a screen coordinate will be passed out. - @beginWxPythonOnly - In place of a single overloaded method name, wxPython implements the following methods: - - ClientToScreen(point): Accepts and returns a wxPoint - - ClientToScreenXY(x, y): Returns a 2-tuple, (x, y) - @endWxPythonOnly - @beginWxPerlOnly In wxPerl this method returns a 2-element list instead of modifying its parameters. @@ -1354,12 +1468,12 @@ public: @see ConvertPixelsToDialog() */ - wxPoint ConvertDialogToPixels(const wxPoint& pt); + wxPoint ConvertDialogToPixels(const wxPoint& pt) const; /** @overload */ - wxSize ConvertDialogToPixels(const wxSize& sz); + wxSize ConvertDialogToPixels(const wxSize& sz) const; /** Converts a point or size from pixels to dialog units. @@ -1374,12 +1488,12 @@ public: @see ConvertDialogToPixels() */ - wxPoint ConvertPixelsToDialog(const wxPoint& pt); + wxPoint ConvertPixelsToDialog(const wxPoint& pt) const; /** @overload */ - wxSize ConvertPixelsToDialog(const wxSize& sz); + wxSize ConvertPixelsToDialog(const wxSize& sz) const; /** Converts from screen to client window coordinates. @@ -1408,8 +1522,14 @@ public: //@{ /** - Clears the window by filling it with the current background colour. Does not - cause an erase background event to be generated. + Clears the window by filling it with the current background colour. + + Does not cause an erase background event to be generated. + + Notice that this uses wxClientDC to draw on the window and the results + of doing it while also drawing on wxPaintDC for this window are + undefined. Hence this method shouldn't be used from EVT_PAINT handlers, + just use wxDC::Clear() on the wxPaintDC you already use there instead. */ virtual void ClearBackground(); @@ -1538,7 +1658,7 @@ public: @endWxPerlOnly */ void GetTextExtent(const wxString& string, - int* w, int* h, + int* w, int* h, int* descent = NULL, int* externalLeading = NULL, const wxFont* font = NULL) const; @@ -1557,6 +1677,11 @@ public: */ const wxRegion& GetUpdateRegion() const; + /** + Get the update rectangle bounding box in client coords + */ + wxRect GetUpdateClientRect() const; + /** Returns @true if this window background is transparent (as, for example, for wxStaticText) and should show the parent window background. @@ -1606,12 +1731,19 @@ public: /** Sets the background colour of the window. + + Notice that as with SetForegroundColour(), setting the background + colour of a native control may not affect the entire control and could + be not supported at all depending on the control and platform. + Please see InheritAttributes() for explanation of the difference between this method and SetOwnBackgroundColour(). @param colour The colour to be used as the background colour; pass wxNullColour to reset to the default colour. + Note that you may want to use wxSystemSettings::GetColour() to retrieve + a suitable colour to use rather than setting an hard-coded one. @remarks The background colour is usually painted by the default wxEraseEvent event handler function under Windows and @@ -1629,39 +1761,85 @@ public: @see GetBackgroundColour(), SetForegroundColour(), GetForegroundColour(), ClearBackground(), - Refresh(), wxEraseEvent + Refresh(), wxEraseEvent, wxSystemSettings */ virtual bool SetBackgroundColour(const wxColour& colour); /** Sets the background style of the window. - The default background style is wxBG_STYLE_ERASE which indicates that - the window background may be erased in EVT_ERASE_BACKGROUND handler. + The default background style is @c wxBG_STYLE_ERASE which indicates that + the window background may be erased in @c EVT_ERASE_BACKGROUND handler. This is a safe, compatibility default; however you may want to change it - to wxBG_STYLE_SYSTEM if you don't define any erase background event + to @c wxBG_STYLE_SYSTEM if you don't define any erase background event handlers at all, to avoid unnecessary generation of erase background events and always let system erase the background. And you should - change the background style to wxBG_STYLE_PAINT if you define an - EVT_PAINT handler which completely overwrites the window background as - in this case erasing it previously, either in EVT_ERASE_BACKGROUND + change the background style to @c wxBG_STYLE_PAINT if you define an + @c EVT_PAINT handler which completely overwrites the window background as + in this case erasing it previously, either in @c EVT_ERASE_BACKGROUND handler or in the system default handler, would result in flicker as the background pixels will be repainted twice every time the window is redrawn. Do ensure that the background is entirely erased by your - EVT_PAINT handler in this case however as otherwise garbage may be left + @c EVT_PAINT handler in this case however as otherwise garbage may be left on screen. Notice that in previous versions of wxWidgets a common way to work around the above mentioned flickering problem was to define an empty - EVT_ERASE_BACKGROUND handler. Setting background style to - wxBG_STYLE_PAINT is a simpler and more efficient solution to the same + @c EVT_ERASE_BACKGROUND handler. Setting background style to + @c wxBG_STYLE_PAINT is a simpler and more efficient solution to the same problem. + + Under wxGTK and wxOSX, you can use ::wxBG_STYLE_TRANSPARENT to obtain + full transparency of the window background. Note that wxGTK supports + this only since GTK 2.12 with a compositing manager enabled, call + IsTransparentBackgroundSupported() to check whether this is the case. + + Also, on order for @c SetBackgroundStyle(wxBG_STYLE_TRANSPARENT) to + work, it must be called before Create(). If you're using your own + wxWindow-derived class you should write your code in the following way: + @code + class MyWidget : public wxWindow + { + public: + MyWidget(wxWindow* parent, ...) + : wxWindow() // Use default ctor here! + { + // Do this first: + SetBackgroundStyle(wxBG_STYLE_TRANSPARENT); + + // And really create the window afterwards: + Create(parent, ...); + } + }; + @endcode + @see SetBackgroundColour(), GetForegroundColour(), - SetTransparent() + SetTransparent(), IsTransparentBackgroundSupported() */ virtual bool SetBackgroundStyle(wxBackgroundStyle style); + /** + Checks whether using transparent background might work. + + If this function returns @false, calling SetBackgroundStyle() with + ::wxBG_STYLE_TRANSPARENT is not going to work. If it returns @true, + setting transparent style should normally succeed. + + Notice that this function would typically be called on the parent of a + window you want to set transparent background style for as the window + for which this method is called must be fully created. + + @param reason + If not @NULL, a reason message is provided if transparency is not + supported. + + @return @true if background transparency is supported. + + @since 2.9.4 + */ + virtual bool IsTransparentBackgroundSupported(wxString *reason = NULL) const; + /** Sets the font for this window. This function should not be called for the parent window if you don't want its font to be inherited by its children, @@ -1687,6 +1865,13 @@ public: /** Sets the foreground colour of the window. + + The meaning of foreground colour varies according to the window class; + it may be the text colour or other colour, or it may not be used at + all. Additionally, not all native controls support changing their + foreground colour so this method may change their colour only partially + or even not at all. + Please see InheritAttributes() for explanation of the difference between this method and SetOwnForegroundColour(). @@ -1694,9 +1879,6 @@ public: The colour to be used as the foreground colour; pass wxNullColour to reset to the default colour. - @remarks The meaning of foreground colour varies according to the window class; - it may be the text colour or other colour, or it may not be used at all. - @return @true if the colour was really changed, @false if it was already set to this colour and nothing was done. @@ -1756,6 +1938,10 @@ public: */ virtual void SetThemeEnabled(bool enable); + /** + */ + virtual bool GetThemeEnabled() const; + /** Returns @true if the system supports transparent windows and calling SetTransparent() may succeed. If this function returns @false, transparent @@ -1825,6 +2011,19 @@ public: */ bool ProcessWindowEvent(wxEvent& event); + /** + Wrapper for wxEvtHandler::ProcessEventLocally(). + + This method is similar to ProcessWindowEvent() but can be used to + search for the event handler only in this window and any event handlers + pushed on top of it. Unlike ProcessWindowEvent() it won't propagate the + event upwards. But it will use the validator and event handlers + associated with this window, if any. + + @since 2.9.1 + */ + bool ProcessWindowEventLocally(wxEvent& event); + /** Removes and returns the top-most event handler on the event handler stack. @@ -1976,7 +2175,7 @@ public: /** Sets the style of the window. Please note that some styles cannot be changed - after the window creation and that Refresh() might need to be be called + after the window creation and that Refresh() might need to be called after changing the others for the change to take place immediately. See @ref overview_windowstyles "Window styles" for more information about flags. @@ -2054,13 +2253,13 @@ public: control. See also wxNavigationKeyEvent and HandleAsNavigationKey. */ - bool Navigate(int flags = IsForward); + bool Navigate(int flags = wxNavigationKeyEvent::IsForward); /** Performs a keyboard navigation action inside this window. See Navigate() for more information. */ - bool NavigateIn(int flags = IsForward); + bool NavigateIn(int flags = wxNavigationKeyEvent::IsForward); //@} @@ -2084,6 +2283,12 @@ public: /** Raises the window to the top of the window hierarchy (Z-order). + Notice that this function only requests the window manager to raise + this window to the top of Z-order. Depending on its configuration, the + window manager may raise the window, not do it at all or indicate that + a window requested to be raised in some other way, e.g. by flashing its + icon if it is minimized. + @remarks This function only works for wxTopLevelWindow-derived classes. @@ -2193,6 +2398,11 @@ public: for a top level window if you want to bring it to top, although this is not needed if Show() is called immediately after the frame creation. + Notice that the default state of newly created top level windows is hidden + (to allow you to create their contents without flicker) unlike for + all the other, not derived from wxTopLevelWindow, windows that + are by default created in the shown state. + @param show If @true displays the window. Otherwise, hides it. @@ -2289,7 +2499,7 @@ public: @see GetToolTip(), wxToolTip */ - void SetToolTip(const wxString& tip); + void SetToolTip(const wxString& tipString); /** @overload @@ -2330,6 +2540,10 @@ public: The parameter @a menu is the menu to show. The parameter @a pos (or the parameters @a x and @a y) is the position at which to show the menu in client coordinates. + It is recommended to not explicitly specify coordinates when + calling this method in response to mouse click, because some of + the ports (namely, wxGTK) can do a better job of positioning + the menu in that case. @return The selected menu item id or @c wxID_NONE if none selected or an @@ -2337,7 +2551,8 @@ public: @since 2.9.0 */ - int GetPopupMenuSelectionFromUser(wxMenu& menu, const wxPoint& pos); + int GetPopupMenuSelectionFromUser(wxMenu& menu, + const wxPoint& pos = wxDefaultPosition); /** @overload @@ -2664,7 +2879,7 @@ public: /** - @name Constraints, sizers and window layouting functions + @name Constraints, sizers and window layout functions */ //@{ @@ -2707,7 +2922,7 @@ public: This method calls SetSizer() and then wxSizer::SetSizeHints which sets the initial window size to the size needed to accommodate all sizer elements and sets the size hints which, if this window is a top level one, prevent the user from - resizing it to be less than this minimial size. + resizing it to be less than this minimal size. */ void SetSizerAndFit(wxSizer* sizer, bool deleteOld = true); @@ -2734,7 +2949,6 @@ public: */ void SetConstraints(wxLayoutConstraints* constraints); - /** Invokes the constraint-based layout algorithm or the sizer-based algorithm for this window. @@ -2764,6 +2978,8 @@ public: */ void SetAutoLayout(bool autoLayout); + bool GetAutoLayout() const; + //@} @@ -2863,6 +3079,22 @@ public: */ //@{ + wxHitTest HitTest(wxCoord x, wxCoord y) const; + wxHitTest HitTest(const wxPoint& pt) const; + + /** + Get the window border style from the given flags: this is different from + simply doing flags & wxBORDER_MASK because it uses GetDefaultBorder() to + translate wxBORDER_DEFAULT to something reasonable + */ + wxBorder GetBorder(long flags) const; + + /** + Get border for the flags of this window + */ + wxBorder GetBorder() const; + + /** Does the window-specific updating after processing the update event. This function is called by UpdateWindowUI() in order to check return @@ -2890,7 +3122,7 @@ public: /** Returns the platform-specific handle of the physical window. Cast it to an appropriate handle, such as @b HWND for Windows, - @b Widget for Motif, @b GtkWidget for GTK or @b WinHandle for PalmOS. + @b Widget for Motif or @b GtkWidget for GTK. @beginWxPerlOnly This method will return an integer in wxPerl. @@ -2947,6 +3179,11 @@ public: */ virtual bool IsDoubleBuffered() const; + /** + Turn on or off double buffering of the window if the system supports it. + */ + void SetDoubleBuffered(bool on); + /** Returns @true if the window is retained, @false otherwise. @@ -2969,17 +3206,7 @@ public: */ virtual bool IsTopLevel() const; - /** - Disables all other windows in the application so that - the user can only interact with this window. - - @param modal - If @true, this call disables all other windows in the application so that - the user can only interact with this window. If @false, the effect is - reversed. - */ - virtual void MakeModal(bool modal = true); - + /** This virtual function is normally only used internally, but sometimes an application may need it to implement functionality @@ -3132,6 +3359,8 @@ public: The search is recursive in both cases. @see FindWindow() + + @return Window with the given @a id or @NULL if not found. */ static wxWindow* FindWindowById(long id, const wxWindow* parent = 0); @@ -3145,6 +3374,8 @@ public: The search is recursive in both cases. @see FindWindow() + + @return Window with the given @a label or @NULL if not found. */ static wxWindow* FindWindowByLabel(const wxString& label, const wxWindow* parent = 0); @@ -3161,6 +3392,8 @@ public: FindWindowByLabel() is called. @see FindWindow() + + @return Window with the given @a name or @NULL if not found. */ static wxWindow* FindWindowByName(const wxString& name, const wxWindow* parent = 0); @@ -3211,9 +3444,25 @@ public: protected: /** - Gets the size which best suits the window: for a control, it would be - the minimal size which doesn't truncate the control, for a panel - the - same size as it would have after a call to Fit(). + Centres the window. + + @param direction + Specifies the direction for the centring. May be wxHORIZONTAL, + wxVERTICAL or wxBOTH. It may also include the wxCENTRE_ON_SCREEN + flag. + + @remarks This function is not meant to be called directly by user code, + but via Centre, Center, CentreOnParent, or CenterOnParent. + This function can be overridden to fine-tune centring behaviour. + */ + virtual void DoCentre(int direction); + + /** + Implementation of GetBestSize() that can be overridden. + + Notice that it is usually more convenient to override + DoGetBestClientSize() rather than this method itself as you need to + explicitly account for the window borders size if you do the latter. The default implementation of this function is designed for use in container windows, such as wxPanel, and works something like this: @@ -3231,11 +3480,65 @@ protected: */ virtual wxSize DoGetBestSize() const; + /** + Override this method to return the best size for a custom control. + + A typical implementation of this method should compute the minimal size + needed to fully display the control contents taking into account the + current font size. + + The default implementation simply returns ::wxDefaultSize and + GetBestSize() returns an arbitrary hardcoded size for the window, so + you must override it when implementing a custom window class. + + @see @ref overview_windowsizing + + @since 2.9.0 + */ + virtual wxSize DoGetBestClientSize() const; + + /** + Override this method to implement height-for-width best size + calculation. + + Return the height needed to fully display the control contents if its + width is fixed to the given value. Custom classes implementing + wrapping should override this method and return the height + corresponding to the number of lines needed to lay out the control + contents at this width. + + Currently this method is not used by wxWidgets yet, however it is + planned that it will be used by the new sizer classes implementing + height-for-width layout strategy in the future. + + Notice that implementing this method or even implementing both it and + DoGetBestClientWidth() doesn't replace overriding DoGetBestClientSize(), + i.e. you still need to implement the latter as well in order to provide + the best size when neither width nor height are constrained. + + By default returns ::wxDefaultCoord meaning that the vertical component + of DoGetBestClientSize() return value should be used. + + @since 2.9.4 + */ + virtual int DoGetBestClientHeight(int width) const; + + /** + Override this method to implement width-for-height best size + calculation. + + This method is exactly the same as DoGetBestClientHeight() except that + it determines the width assuming the height is fixed instead of vice + versa. + + @since 2.9.4 + */ + virtual int DoGetBestClientWidth(int height) const; /** Sets the initial window size if none is given (i.e. at least one of the components of the size passed to ctor/Create() is wxDefaultCoord). - @deprecated @todo provide deprecation description + @deprecated Use SetInitialSize() instead. */ virtual void SetInitialBestSize(const wxSize& size);