X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/47a8a4d5cc3e8fcb2efee4787cb9d244104beea5..6c0e710f008370d8c0039b3aa859b8eb65d6de12:/include/wx/msw/window.h diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index 8f846c2c9f..5b41235d9f 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -13,15 +13,23 @@ #ifndef _WX_WINDOW_H_ #define _WX_WINDOW_H_ -// --------------------------------------------------------------------------- -// constants -// --------------------------------------------------------------------------- +#include "wx/settings.h" // solely for wxSystemColour + +// if this is set to 1, we use deferred window sizing to reduce flicker when +// resizing complicated window hierarchies, but this can in theory result in +// different behaviour than the old code so we keep the possibility to use it +// by setting this to 0 (in the future this should be removed completely) +#ifdef __WXWINCE__ + #define wxUSE_DEFERRED_SIZING 0 +#else + #define wxUSE_DEFERRED_SIZING 1 +#endif // --------------------------------------------------------------------------- // wxWindow declaration for MSW // --------------------------------------------------------------------------- -class WXDLLEXPORT wxWindowMSW : public wxWindowBase +class WXDLLIMPEXP_CORE wxWindowMSW : public wxWindowBase { friend class wxSpinCtrl; friend class wxSlider; @@ -59,8 +67,17 @@ public: virtual void Raise(); virtual void Lower(); - virtual bool Show( bool show = true ); - virtual void DoEnable( bool enable ); + virtual bool Show(bool show = true); + virtual bool ShowWithEffect(wxShowEffect effect, + unsigned timeout = 0) + { + return MSWShowWithEffect(true, effect, timeout); + } + virtual bool HideWithEffect(wxShowEffect effect, + unsigned timeout = 0) + { + return MSWShowWithEffect(false, effect, timeout); + } virtual void SetFocus(); virtual void SetFocusFromKbd(); @@ -72,9 +89,6 @@ public: virtual void Refresh( bool eraseBackground = true, const wxRect *rect = (const wxRect *) NULL ); virtual void Update(); - virtual void Freeze(); - virtual void Thaw(); - virtual bool IsFrozen() const { return m_frozenness > 0; } virtual void SetWindowStyleFlag(long style); virtual void SetExtraStyle(long exStyle); @@ -83,12 +97,6 @@ public: virtual int GetCharHeight() const; virtual int GetCharWidth() const; - virtual void GetTextExtent(const wxString& string, - int *x, int *y, - int *descent = (int *) NULL, - int *externalLeading = (int *) NULL, - const wxFont *theFont = (const wxFont *) NULL) - const; virtual void SetScrollbar( int orient, int pos, int thumbVisible, int range, bool refresh = true ); @@ -97,7 +105,7 @@ public: virtual int GetScrollThumb( int orient ) const; virtual int GetScrollRange( int orient ) const; virtual void ScrollWindow( int dx, int dy, - const wxRect* rect = (wxRect *) NULL ); + const wxRect* rect = NULL ); virtual bool ScrollLines(int lines); virtual bool ScrollPages(int pages); @@ -148,6 +156,29 @@ public: // does this window have deferred position and/or size? bool IsSizeDeferred() const; + // these functions allow to register a global handler for the given Windows + // message: it will be called from MSWWindowProc() of any window which gets + // this event if it's not processed before (i.e. unlike a hook procedure it + // does not override the normal processing) + // + // notice that if you want to process a message for a given window only you + // should override its MSWWindowProc() instead + + // type of the handler: it is called with the message parameters (except + // that the window object is passed instead of window handle) and should + // return true if it handled the message or false if it should be passed to + // DefWindowProc() + typedef bool (*MSWMessageHandler)(wxWindowMSW *win, + WXUINT nMsg, + WXWPARAM wParam, + WXLPARAM lParam); + + // install a handler, shouldn't be called more than one for the same message + static bool MSWRegisterMessageHandler(int msg, MSWMessageHandler handler); + + // unregister a previously registered handler + static void MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler); + // implementation from now on // ========================== @@ -156,7 +187,6 @@ public: // -------------- void OnPaint(wxPaintEvent& event); - void OnEraseBackground(wxEraseEvent& event); #ifdef __WXWINCE__ void OnInitDialog(wxInitDialogEvent& event); #endif @@ -178,7 +208,7 @@ public: wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const; // MSW only: true if this control is part of the main control - virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; }; + virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; } #if wxUSE_TOOLTIPS // MSW only: true if this window or any of its children have a tooltip @@ -204,18 +234,12 @@ public: // created yet) void MSWUpdateStyle(long flagsOld, long exflagsOld); - // translate wxWidgets coords into Windows ones suitable to be passed to - // ::CreateWindow() - // - // returns true if non default coords are returned, false otherwise - bool MSWGetCreateWindowCoords(const wxPoint& pos, - const wxSize& size, - int& x, int& y, - int& w, int& h) const; - // get the HWND to be used as parent of this window with CreateWindow() virtual WXHWND MSWGetParent() const; + // get the Win32 window class name used by all wxWindow objects by default + static const wxChar *MSWGetRegisteredClassName(); + // creates the window of specified Windows class with given style, extended // style, title and geometry (default values // @@ -294,6 +318,8 @@ public: bool HandleSize(int x, int y, WXUINT flag); bool HandleSizing(wxRect& rect); bool HandleGetMinMaxInfo(void *mmInfo); + bool HandleEnterSizeMove(); + bool HandleExitSizeMove(); bool HandleShow(bool show, int status); bool HandleActivate(int flag, bool minimized, WXHWND activate); @@ -321,7 +347,7 @@ public: bool HandleMouseMove(int x, int y, WXUINT flags); bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam); - bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false); + bool HandleChar(WXWPARAM wParam, WXLPARAM lParam); bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam); bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam); #if wxUSE_ACCEL @@ -362,21 +388,50 @@ public: virtual void MSWDestroyWindow(); + // Functions dealing with painting the window background. The derived + // classes should normally only need to reimplement MSWGetBgBrush() if they + // need to use a non-solid brush for erasing their background. This + // function is called by MSWGetBgBrushForChild() which only exists for the + // weird wxToolBar case and MSWGetBgBrushForChild() itself is used by + // MSWGetBgBrush() to actually find the right brush to use. + + // The brush returned from here must remain valid at least until the next + // event loop iteration. Returning 0, as is done by default, indicates + // there is no custom background brush. + virtual WXHBRUSH MSWGetCustomBgBrush() { return 0; } + // this function should return the brush to paint the children controls // background or 0 if this window doesn't impose any particular background // on its children // + // the hDC parameter is the DC background will be drawn on, it can be used + // to call SetBrushOrgEx() on it if the returned brush is a bitmap one + // + // child parameter is never NULL, it can be this window itself or one of + // its (grand)children + // // the base class version returns a solid brush if we have a non default // background colour or 0 otherwise - virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, WXHWND hWnd); + virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child); // return the background brush to use for painting the given window by - // quering the parent windows via their MSWGetBgBrushForChild() recursively - // - // hWndToPaint is normally NULL meaning this window itself, but it can also - // be a child of this window which is used by the static box and could be - // potentially useful for other transparent controls - WXHBRUSH MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint = NULL); + // querying the parent windows via MSWGetBgBrushForChild() recursively + WXHBRUSH MSWGetBgBrush(WXHDC hDC); + + enum MSWThemeColour + { + ThemeColourText = 0, + ThemeColourBackground, + ThemeColourBorder + }; + + // returns a specific theme colour, or if that is not possible then + // wxSystemSettings::GetColour(fallback) + wxColour MSWGetThemeColour(const wchar_t *themeName, + int themePart, + int themeState, + MSWThemeColour themeColour, + wxSystemColour fallback) const; // gives the parent the possibility to draw its children background, e.g. // this is used by wxNotebook to do it using DrawThemeBackground() @@ -395,6 +450,36 @@ public: return true; } + // This should be overridden to return true for the controls which have + // themed background that should through their children. Currently only + // wxNotebook uses this. + virtual bool MSWHasInheritableBackground() const { return false; } + +#if !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__) + #define wxHAS_MSW_BACKGROUND_ERASE_HOOK +#endif + +#ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK + // allows the child to hook into its parent WM_ERASEBKGND processing: call + // MSWSetEraseBgHook() with a non-NULL window to make parent call + // MSWEraseBgHook() on this window (don't forget to reset it to NULL + // afterwards) + // + // this hack is used by wxToolBar, see comments there + void MSWSetEraseBgHook(wxWindow *child); + + // return true if WM_ERASEBKGND is currently hooked + bool MSWHasEraseBgHook() const; + + // called when the window on which MSWSetEraseBgHook() had been called + // receives WM_ERASEBKGND + virtual bool MSWEraseBgHook(WXHDC WXUNUSED(hDC)) { return false; } +#endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK + + // common part of Show/HideWithEffect() + bool MSWShowWithEffect(bool show, + wxShowEffect effect, + unsigned timeout); // Responds to colour changes: passes event on to children. void OnSysColourChanged(wxSysColourChangedEvent& event); @@ -408,6 +493,8 @@ public: // check if a native double-buffering applies for this window virtual bool IsDoubleBuffered() const; + void SetDoubleBuffered(bool on); + // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false void GenerateMouseLeave(); @@ -416,6 +503,17 @@ public: virtual void OnInternalIdle(); protected: + // 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; + + // choose the default border for this window + virtual wxBorder GetDefaultBorder() const; + + // Translate wxBORDER_THEME (and other border styles if necessary to the value + // that makes most sense for this Windows environment + virtual wxBorder TranslateBorder(wxBorder border) const; #if wxUSE_MENUS_NATIVE virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); @@ -436,6 +534,11 @@ protected: int m_yThumbSize; // implement the base class pure virtuals + virtual void DoGetTextExtent(const wxString& string, + int *x, int *y, + int *descent = NULL, + int *externalLeading = NULL, + const wxFont *font = NULL) const; virtual void DoClientToScreen( int *x, int *y ) const; virtual void DoScreenToClient( int *x, int *y ) const; virtual void DoGetPosition( int *x, int *y ) const; @@ -446,9 +549,16 @@ protected: int sizeFlags = wxSIZE_AUTO); virtual void DoSetClientSize(int width, int height); + virtual wxSize DoGetBorderSize() const; + virtual void DoCaptureMouse(); virtual void DoReleaseMouse(); + virtual void DoEnable(bool enable); + + virtual void DoFreeze(); + virtual void DoThaw(); + // this simply moves/resizes the given HWND which is supposed to be our // sibling (this is useful for controls which are composite at MSW level // and for which DoMoveWindow() is not enough) @@ -473,9 +583,29 @@ protected: const wxString& ttip); #endif // wxUSE_TOOLTIPS - // the helper functions used by HandleChar/KeyXXX methods - wxKeyEvent CreateKeyEvent(wxEventType evType, int id, - WXLPARAM lParam = 0, WXWPARAM wParam = 0) const; + // This is used by CreateKeyEvent() and also for wxEVT_CHAR[_HOOK] event + // creation. Notice that this method doesn't initialize wxKeyEvent + // m_keyCode and m_uniChar fields. + void InitAnyKeyEvent(wxKeyEvent& event, + WXWPARAM wParam, + WXLPARAM lParam) const; + + // Helper functions used by HandleKeyXXX() methods and some derived + // classes, wParam and lParam have the same meaning as in WM_KEY{DOWN,UP}. + // + // NB: evType here must be wxEVT_KEY_{DOWN,UP} as wParam here contains the + // virtual key code, not character! + wxKeyEvent CreateKeyEvent(wxEventType evType, + WXWPARAM wParam, + WXLPARAM lParam = 0) const; + + // Another helper for creating wxKeyEvent for wxEVT_CHAR and related types. + // + // The wParam and lParam here must come from WM_CHAR event parameters, i.e. + // wParam must be a character and not a virtual code. + wxKeyEvent CreateCharEvent(wxEventType evType, + WXWPARAM wParam, + WXLPARAM lParam) const; // default OnEraseBackground() implementation, return true if we did erase @@ -490,6 +620,15 @@ protected: // for state as the system will decide for us what needs to be set void MSWUpdateUIState(int action, int state = 0); + // translate wxWidgets coords into Windows ones suitable to be passed to + // ::CreateWindow(), called from MSWCreate() + virtual void MSWGetCreateWindowCoords(const wxPoint& pos, + const wxSize& size, + int& x, int& y, + int& w, int& h) const; + + bool MSWEnableHWND(WXHWND hWnd, bool enable); + private: // common part of all ctors void Init(); @@ -500,19 +639,24 @@ private: bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); - - // number of calls to Freeze() minus number of calls to Thaw() - unsigned int m_frozenness; +#if wxUSE_DEFERRED_SIZING +protected: + // this function is called after the window was resized to its new size + virtual void MSWEndDeferWindowPos() + { + m_pendingPosition = wxDefaultPosition; + m_pendingSize = wxDefaultSize; + } // current defer window position operation handle (may be NULL) WXHANDLE m_hDWP; -protected: // When deferred positioning is done these hold the pending changes, and // are used for the default values if another size/pos changes is done on // this window before the group of deferred changes is completed. wxPoint m_pendingPosition; wxSize m_pendingSize; +#endif // wxUSE_DEFERRED_SIZING private: #ifdef __POCKETPC__ @@ -520,22 +664,10 @@ private: #endif DECLARE_DYNAMIC_CLASS(wxWindowMSW) - DECLARE_NO_COPY_CLASS(wxWindowMSW) + wxDECLARE_NO_COPY_CLASS(wxWindowMSW); DECLARE_EVENT_TABLE() }; -// ---------------------------------------------------------------------------- -// inline functions -// ---------------------------------------------------------------------------- - -// --------------------------------------------------------------------------- -// global functions -// --------------------------------------------------------------------------- - -// kbd code translation -WXDLLEXPORT int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0); -WXDLLEXPORT WXWORD wxCharCodeWXToMSW(int id, bool *IsVirtual = NULL); - // window creation helper class: before creating a new HWND, instantiate an // object of this class on stack - this allows to process the messages sent to // the window even before CreateWindow() returns @@ -546,17 +678,4 @@ public: ~wxWindowCreationHook(); }; -// ---------------------------------------------------------------------------- -// global objects -// ---------------------------------------------------------------------------- - -// notice that this hash must be defined after wxWindow declaration as it -// needs to "see" its dtor and not just forward declaration -#include "wx/hash.h" - -// pseudo-template HWND <-> wxWindow hash table -WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable); - -extern wxWinHashTable *wxWinHandleHash; - #endif // _WX_WINDOW_H_