X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/edc09871744140f16b2ef6b7abaa2289d7deb260..f9d6e4e454ac06b3303c71081b289152c8867ec1:/include/wx/window.h diff --git a/include/wx/window.h b/include/wx/window.h index a9a881c8a8..d953c23b7e 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -66,22 +66,20 @@ // forward declarations // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxCaret; -class WXDLLEXPORT wxControl; -class WXDLLEXPORT wxCursor; -class WXDLLEXPORT wxDC; -class WXDLLEXPORT wxDropTarget; -class WXDLLEXPORT wxItemResource; -class WXDLLEXPORT wxLayoutConstraints; -class WXDLLEXPORT wxResourceTable; -class WXDLLEXPORT wxSizer; -class WXDLLEXPORT wxToolTip; -class WXDLLEXPORT wxWindowBase; -class WXDLLEXPORT wxWindow; -class WXDLLEXPORT wxScrollHelper; +class WXDLLIMPEXP_FWD_CORE wxCaret; +class WXDLLIMPEXP_FWD_CORE wxControl; +class WXDLLIMPEXP_FWD_CORE wxCursor; +class WXDLLIMPEXP_FWD_CORE wxDC; +class WXDLLIMPEXP_FWD_CORE wxDropTarget; +class WXDLLIMPEXP_FWD_CORE wxLayoutConstraints; +class WXDLLIMPEXP_FWD_CORE wxSizer; +class WXDLLIMPEXP_FWD_CORE wxToolTip; +class WXDLLIMPEXP_FWD_CORE wxWindowBase; +class WXDLLIMPEXP_FWD_CORE wxWindow; +class WXDLLIMPEXP_FWD_CORE wxScrollHelper; #if wxUSE_ACCESSIBILITY -class WXDLLEXPORT wxAccessible; +class WXDLLIMPEXP_FWD_CORE wxAccessible; #endif // ---------------------------------------------------------------------------- @@ -89,7 +87,7 @@ class WXDLLEXPORT wxAccessible; // ---------------------------------------------------------------------------- // struct containing all the visual attributes of a control -struct WXDLLEXPORT wxVisualAttributes +struct WXDLLIMPEXP_CORE wxVisualAttributes { // the font used for control label/text inside it wxFont font; @@ -117,17 +115,27 @@ enum wxWindowVariant #define wxWINDOW_DEFAULT_VARIANT wxT("window-default-variant") #endif +// valid values for Show/HideWithEffect() +enum wxShowEffect +{ + wxSHOW_EFFECT_ROLL, + wxSHOW_EFFECT_SLIDE, + wxSHOW_EFFECT_BLEND, + wxSHOW_EFFECT_EXPAND, + wxSHOW_EFFECT_MAX +}; + // ---------------------------------------------------------------------------- // (pseudo)template list classes // ---------------------------------------------------------------------------- -WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLEXPORT); +WX_DECLARE_LIST_3(wxWindow, wxWindowBase, wxWindowList, wxWindowListNode, class WXDLLIMPEXP_CORE); // ---------------------------------------------------------------------------- // global variables // ---------------------------------------------------------------------------- -extern WXDLLEXPORT_DATA(wxWindowList) wxTopLevelWindows; +extern WXDLLIMPEXP_DATA_CORE(wxWindowList) wxTopLevelWindows; extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete; // ---------------------------------------------------------------------------- @@ -141,7 +149,7 @@ extern WXDLLIMPEXP_DATA_CORE(wxList) wxPendingDelete; // temporarily switches event handlers). // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxWindowBase : public wxEvtHandler +class WXDLLIMPEXP_CORE wxWindowBase : public wxEvtHandler { public: // creating the window @@ -201,11 +209,6 @@ public: wxWindowVariant GetWindowVariant() const { return m_windowVariant; } - // window id uniquely identifies the window among its siblings unless - // it is wxID_ANY which means "don't care" - void SetId( wxWindowID winid ) { m_windowId = winid; } - wxWindowID GetId() const { return m_windowId; } - // get or change the layout direction (LTR or RTL) for this window, // wxLayout_Default is returned if layout direction is not supported virtual wxLayoutDirection GetLayoutDirection() const @@ -219,15 +222,28 @@ public: wxCoord width, wxCoord widthTotal) const; - // generate a control id for the controls which were not given one by - // user - static int NewControlId() { return --ms_lastControlId; } - // get the id of the control following the one with the given - // (autogenerated) id - static int NextControlId(int winid) { return winid - 1; } - // get the id of the control preceding the one with the given - // (autogenerated) id - static int PrevControlId(int winid) { return winid + 1; } + + // window id uniquely identifies the window among its siblings unless + // it is wxID_ANY which means "don't care" + void SetId( wxWindowID winid ) { m_windowId = winid; } + wxWindowID GetId() const { return m_windowId; } + + // generate a unique id (or count of them consecutively), returns a + // valid id in the auto-id range or wxID_NONE if failed. If using + // autoid management, it will mark the id as reserved until it is + // used (by assigning it to a wxWindowIDRef) or unreserved. + static wxWindowID NewControlId(int count = 1) + { + return wxIdManager::ReserveId(count); + } + + // If an ID generated from NewControlId is not assigned to a wxWindowIDRef, + // it must be unreserved + static void UnreserveControlId(wxWindowID id, int count = 1) + { + wxIdManager::UnreserveId(id, count); + } + // moving/resizing // --------------- @@ -339,6 +355,10 @@ public: return wxRect(GetClientAreaOrigin(), GetClientSize()); } + // client<->window size conversion + virtual wxSize ClientToWindowSize(const wxSize& size) const; + virtual wxSize WindowToClientSize(const wxSize& size) const; + // get the size best suited for the window (in fact, minimal // acceptable size using which it will still look "nice" in // most situations) @@ -413,20 +433,14 @@ public: const wxSize& incSize=wxDefaultSize) { DoSetSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y, incSize.x, incSize.y); } - virtual void DoSetSizeHints( int minW, int minH, - int maxW, int maxH, - int incW, int incH ); - - // Methods for setting virtual size hints - // FIXME: What are virtual size hints? - virtual void SetVirtualSizeHints( int minW, int minH, - int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ); - void SetVirtualSizeHints( const wxSize& minSize, - const wxSize& maxSize=wxDefaultSize) - { - SetVirtualSizeHints(minSize.x, minSize.y, maxSize.x, maxSize.y); - } +#if WXWIN_COMPATIBILITY_2_8 + // these are useless and do nothing since wxWidgets 2.9 + wxDEPRECATED( virtual void SetVirtualSizeHints( int minW, int minH, + int maxW = wxDefaultCoord, int maxH = wxDefaultCoord ) ); + wxDEPRECATED( void SetVirtualSizeHints( const wxSize& minSize, + const wxSize& maxSize=wxDefaultSize) ); +#endif // WXWIN_COMPATIBILITY_2_8 // Call these to override what GetBestSize() returns. This @@ -435,12 +449,24 @@ public: virtual void SetMinSize(const wxSize& minSize) { m_minWidth = minSize.x; m_minHeight = minSize.y; } virtual void SetMaxSize(const wxSize& maxSize) { m_maxWidth = maxSize.x; m_maxHeight = maxSize.y; } + // Like Set*Size, but for client, not window, size + virtual void SetMinClientSize(const wxSize& size) + { SetMinSize(ClientToWindowSize(size)); } + virtual void SetMaxClientSize(const wxSize& size) + { SetMaxSize(ClientToWindowSize(size)); } + // Override these methods to impose restrictions on min/max size. // The easier way is to call SetMinSize() and SetMaxSize() which // will have the same effect. Doing both is non-sense. virtual wxSize GetMinSize() const { return wxSize(m_minWidth, m_minHeight); } virtual wxSize GetMaxSize() const { return wxSize(m_maxWidth, m_maxHeight); } + // Like Get*Size, but for client, not window, size + virtual wxSize GetMinClientSize() const + { return WindowToClientSize(GetMinSize()); } + virtual wxSize GetMaxClientSize() const + { return WindowToClientSize(GetMaxSize()); } + // Get the min and max values one by one int GetMinWidth() const { return GetMinSize().x; } int GetMinHeight() const { return GetMinSize().y; } @@ -490,6 +516,14 @@ public: // 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 WXUNUSED(direction), int WXUNUSED(size), int WXUNUSED(availableOtherDir) ) + { return false; } // window state // ------------ @@ -499,6 +533,35 @@ public: virtual bool Show( bool show = true ); bool Hide() { return Show(false); } + // show or hide the window with a special effect, not implemented on + // most platforms (where it is the same as Show()/Hide() respectively) + // + // timeout specifies how long the animation should take, in ms, the + // default value of 0 means to use the default (system-dependent) value + // + // direction is only used with wxSHOW_EFFECT_ROLL and SLIDE values + virtual bool ShowWithEffect(wxShowEffect effect, + unsigned timeout = 0, + wxDirection dir = wxBOTTOM) + { + wxUnusedVar(effect); + wxUnusedVar(timeout); + wxUnusedVar(dir); + + return Show(); + } + + virtual bool HideWithEffect(wxShowEffect effect, + unsigned timeout = 0, + wxDirection dir = wxBOTTOM) + { + wxUnusedVar(effect); + wxUnusedVar(timeout); + wxUnusedVar(dir); + + return Hide(); + } + // returns true if window was enabled/disabled, false if nothing done virtual bool Enable( bool enable = true ); bool Disable() { return Enable(false); } @@ -573,6 +636,11 @@ public: static wxWindow *DoFindFocus() /* = 0: implement in derived classes */; + // return true if the window has focus (handles composite windows + // correctly - returns true if GetMainWindowOfCompositeControl() + // has focus) + virtual bool HasFocus() const; + // can this window have focus in principle? // // the difference between AcceptsFocus[FromKeyboard]() and CanAcceptFocus @@ -624,12 +692,17 @@ public: bool Navigate(int flags = wxNavigationKeyEvent::IsForward) { return m_parent && ((wxWindowBase *)m_parent)->DoNavigateIn(flags); } + // this function will generate the appropriate call to Navigate() if the + // key event is one normally used for keyboard navigation and return true + // in this case + bool HandleAsNavigationKey(const wxKeyEvent& event); + // move this window just before/after the specified one in tab order // (the other window must be our sibling!) void MoveBeforeInTabOrder(wxWindow *win) - { DoMoveInTabOrder(win, MoveBefore); } + { DoMoveInTabOrder(win, OrderBefore); } void MoveAfterInTabOrder(wxWindow *win) - { DoMoveInTabOrder(win, MoveAfter); } + { DoMoveInTabOrder(win, OrderAfter); } // parent/children relations @@ -642,6 +715,11 @@ public: // needed just for extended runtime const wxWindowList& GetWindowChildren() const { return GetChildren() ; } + // get the window before/after this one in the parents children list, + // returns NULL if this is the first/last window + wxWindow *GetPrevSibling() const { return DoGetSibling(OrderBefore); } + wxWindow *GetNextSibling() const { return DoGetSibling(OrderAfter); } + // get the parent or the parent of the parent wxWindow *GetParent() const { return m_parent; } inline wxWindow *GetGrandParent() const; @@ -701,6 +779,13 @@ public: // be there) bool RemoveEventHandler(wxEvtHandler *handler); + // Process an event by calling GetEventHandler()->ProcessEvent() and + // handling any exceptions thrown by event handlers. It's mostly useful + // when processing wx events when called from C code (e.g. in GTK+ + // callback) when the exception wouldn't correctly propagate to + // wxEventLoop. + bool HandleWindowEvent(wxEvent& event) const; + // validators // ---------- @@ -803,13 +888,13 @@ public: virtual void ClearBackground(); // freeze the window: don't redraw it until it is thawed - virtual void Freeze() { } + void Freeze(); // thaw the window: redraw it after it had been frozen - virtual void Thaw() { } + void Thaw(); // return true if window had been frozen and not unthawed yet - virtual bool IsFrozen() const { return false; } + bool IsFrozen() const { return m_freezeCount != 0; } // adjust DC for drawing on this window virtual void PrepareDC( wxDC & WXUNUSED(dc) ) { } @@ -988,10 +1073,18 @@ public: virtual void DoUpdateWindowUI(wxUpdateUIEvent& event) ; #if wxUSE_MENUS + // show popup menu at the given position, generate events for the items + // selected in it bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition) - { return DoPopupMenu(menu, pos.x, pos.y); } - bool PopupMenu(wxMenu *menu, int x, int y) - { return DoPopupMenu(menu, x, y); } + { return PopupMenu(menu, pos.x, pos.y); } + bool PopupMenu(wxMenu *menu, int x, int y); + + // simply return the id of the selected item or wxID_NONE without + // generating any events + int GetPopupMenuSelectionFromUser(wxMenu& menu, const wxPoint& pos) + { return DoGetPopupMenuSelectionFromUser(menu, pos.x, pos.y); } + int GetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y) + { return DoGetPopupMenuSelectionFromUser(menu, x, y); } #endif // wxUSE_MENUS // override this method to return true for controls having multiple pages @@ -1035,6 +1128,20 @@ public: bool PageUp() { return ScrollPages(-1); } bool PageDown() { return ScrollPages(1); } + // call this to always show one or both scrollbars, even if the window + // is big enough to not require them + virtual void AlwaysShowScrollbars(bool WXUNUSED(horz) = true, + bool WXUNUSED(vert) = true) + { + } + + // return true if AlwaysShowScrollbars() had been called before for the + // corresponding orientation + virtual bool IsScrollbarAlwaysShown(int WXUNUSED(orient)) const + { + return false; + } + // context-sensitive help // ---------------------- @@ -1043,9 +1150,13 @@ public: #if wxUSE_HELP // associate this help text with this window void SetHelpText(const wxString& text); - // associate this help text with all windows with the same id as this - // one - void SetHelpTextForId(const wxString& text); + +#if WXWIN_COMPATIBILITY_2_8 + // Associate this help text with all windows with the same id as this one. + // Don't use this, do wxHelpProvider::Get()->AddHelp(id, text); + wxDEPRECATED( void SetHelpTextForId(const wxString& text) ); +#endif // WXWIN_COMPATIBILITY_2_8 + // get the help string associated with the given position in this window // // notice that pt may be invalid if event origin is keyboard or unknown @@ -1221,23 +1332,30 @@ public: // area (normal windows can't, but e.g. menubar or statusbar can): virtual bool CanBeOutsideClientArea() const { return false; } + // returns true if the platform should explicitly apply a theme border. Currently + // used only by Windows + virtual bool CanApplyThemeBorder() const { return true; } + protected: // event handling specific to wxWindow virtual bool TryValidator(wxEvent& event); virtual bool TryParent(wxEvent& event); - // common part of MoveBefore/AfterInTabOrder() - enum MoveKind + enum WindowOrder { - MoveBefore, // insert before the given window - MoveAfter // insert after the given window + OrderBefore, // insert before the given window + OrderAfter // insert after the given window }; - virtual void DoMoveInTabOrder(wxWindow *win, MoveKind move); + + // common part of GetPrev/NextSibling() + wxWindow *DoGetSibling(WindowOrder order) const; + + // common part of MoveBefore/AfterInTabOrder() + virtual void DoMoveInTabOrder(wxWindow *win, WindowOrder move); // implementation of Navigate() and NavigateIn() virtual bool DoNavigateIn(int flags); - #if wxUSE_CONSTRAINTS // satisfy the constraints for the windows but don't set the window sizes void SatisfyConstraints(); @@ -1266,7 +1384,7 @@ protected: // the window id - a number which uniquely identifies a window among // its siblings unless it is wxID_ANY - wxWindowID m_windowId; + wxWindowIDRef m_windowId; // the parent window of this window (or NULL) and the list of the children // of this window @@ -1370,17 +1488,17 @@ protected: wxScrollHelper *m_scrollHelper; - int m_minVirtualWidth; // VirtualSizeHints - int m_minVirtualHeight; - int m_maxVirtualWidth; - int m_maxVirtualHeight; - wxWindowVariant m_windowVariant ; // override this to change the default (i.e. used when no style is // specified) border for the window class virtual wxBorder GetDefaultBorder() const; + // this allows you to implement standard control borders without + // repeating the code in different classes that are not derived from + // wxControl + virtual wxBorder GetDefaultBorderForControl() const { return wxBORDER_THEME; } + // Get the default size for the new window if no explicit size given. TLWs // have their own default size so this is just for non top-level windows. static int WidthDefault(int w) { return w == wxDefaultCoord ? 20 : w; } @@ -1429,14 +1547,6 @@ protected: // same size as it would have after a call to Fit() virtual wxSize DoGetBestSize() const; - // called from DoGetBestSize() to convert best virtual size (returned by - // the window sizer) to the best size for the window itself; this is - // overridden at wxScrolledWindow level to clump down virtual size to real - virtual wxSize GetWindowSizeForVirtualSize(const wxSize& size) const - { - return size; - } - // this is the virtual function to be overriden in any derived class which // wants to change how SetSize() or Move() works - it is called by all // versions of these functions in the base class @@ -1447,6 +1557,10 @@ protected: // same as DoSetSize() for the client size virtual void DoSetClientSize(int width, int height) = 0; + virtual void DoSetSizeHints( int minW, int minH, + int maxW, int maxH, + int incW, int incH ); + // move the window to the specified location and resize it: this is called // from both DoSetSize() and DoSetClientSize() and would usually just // reposition this window except for composite controls which will want to @@ -1479,6 +1593,12 @@ protected: // implements the window variants virtual void DoSetWindowVariant( wxWindowVariant variant ) ; + + // really freeze/thaw the window (should have port-specific implementation) + virtual void DoFreeze() { } + virtual void DoThaw() { } + + // Must be called when mouse capture is lost to send // wxMouseCaptureLostEvent to windows on capture stack. static void NotifyCaptureLost(); @@ -1489,17 +1609,29 @@ private: // enabled/disabled void NotifyWindowOnEnableChange(bool enabled); +#if wxUSE_MENUS + // temporary event handler used by GetPopupMenuSelectionFromUser() + void InternalOnPopupMenu(wxCommandEvent& event); - // contains the last id generated by NewControlId - static int ms_lastControlId; + // implementation of the public GetPopupMenuSelectionFromUser() method + int DoGetPopupMenuSelectionFromUser(wxMenu& menu, int x, int y); +#endif // wxUSE_MENUS // the stack of windows which have captured the mouse - static struct WXDLLEXPORT wxWindowNext *ms_winCaptureNext; + static struct WXDLLIMPEXP_FWD_CORE wxWindowNext *ms_winCaptureNext; + // the window that currently has mouse capture static wxWindow *ms_winCaptureCurrent; + // indicates if execution is inside CaptureMouse/ReleaseMouse static bool ms_winCaptureChanging; + + // number of Freeze() calls minus the number of Thaw() calls: we're frozen + // (i.e. not being updated) if it is positive + unsigned int m_freezeCount; + + DECLARE_ABSTRACT_CLASS(wxWindowBase) DECLARE_NO_COPY_CLASS(wxWindowBase) DECLARE_EVENT_TABLE() @@ -1626,21 +1758,21 @@ inline wxWindow *wxWindowBase::GetGrandParent() const // Find the wxWindow at the current mouse position, also returning the mouse // position. -extern WXDLLEXPORT wxWindow* wxFindWindowAtPointer(wxPoint& pt); +extern WXDLLIMPEXP_CORE wxWindow* wxFindWindowAtPointer(wxPoint& pt); // Get the current mouse position. -extern WXDLLEXPORT wxPoint wxGetMousePosition(); +extern WXDLLIMPEXP_CORE wxPoint wxGetMousePosition(); // get the currently active window of this application or NULL -extern WXDLLEXPORT wxWindow *wxGetActiveWindow(); +extern WXDLLIMPEXP_CORE wxWindow *wxGetActiveWindow(); // get the (first) top level parent window -WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win); +WXDLLIMPEXP_CORE wxWindow* wxGetTopLevelParent(wxWindow *win); #if WXWIN_COMPATIBILITY_2_6 // deprecated (doesn't start with 'wx' prefix), use wxWindow::NewControlId() - wxDEPRECATED( int NewControlId() ); - inline int NewControlId() { return wxWindowBase::NewControlId(); } + wxDEPRECATED( wxWindowID NewControlId() ); + inline wxWindowID NewControlId() { return wxWindowBase::NewControlId(); } #endif // WXWIN_COMPATIBILITY_2_6 #if wxUSE_ACCESSIBILITY @@ -1648,7 +1780,7 @@ WXDLLEXPORT wxWindow* wxGetTopLevelParent(wxWindow *win); // accessible object for windows // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxWindowAccessible: public wxAccessible +class WXDLLIMPEXP_CORE wxWindowAccessible: public wxAccessible { public: wxWindowAccessible(wxWindow* win): wxAccessible(win) { if (win) win->SetAccessible(this); }