/** * @file XTPPreviewCtrl.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPPREVIEWCTRL_H__) # define __XTPPREVIEWCTRL_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPPreviewHostWindow; class CXTPPreviewNavigatorWindow; /** * @brief * Implements the preview control that can display visual preview data provided * by the best matching preview provider registered to the control. */ class _XTP_EXT_CLASS CXTPPreviewCtrl : public CWnd { /** @cond */ DECLARE_DYNAMIC(CXTPPreviewCtrl) /** @endcond */ public: /** * @brief * Handles control construction. */ CXTPPreviewCtrl(); /** * @brief * Handles control destruction. */ virtual ~CXTPPreviewCtrl(); /** * @brief * Registers the window class if it has not already been registered. * @param hInstance Instance of the resource where the control is located. * @return * TRUE if the window class was successfully registered, otherwise FALSE. */ BOOL RegisterWindowClass(HINSTANCE hInstance = NULL); /** * @brief * Creates a preview control window object. * @param dwStyle Bitwise combination (OR) of window styles; otherwise NULL for * the default window style. * @param rect The size and location of the window relative to the screen or * the parent window. * @param pParentWnd For a child window, pointer to the parent window; otherwise, a * pointer to the owner window if the window has an owner. * @param nID For a child window, the window ID; otherwise, the ID of a menu * for the window. * @param pContext CCreateContext pointer or NULL. * @return * TRUE if the method was successful, otherwise FALSE. */ virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); /** * @brief * Creates a preview control window object. * @param dwExStyle Bitwise combination (OR) of extended window styles; otherwise * NULL for the default extended window style. * @param dwStyle Bitwise combination (OR) of window styles; otherwise NULL for * the default window style. * @param x The initial horizontal distance of the window from the left side * of the screen or the parent window. * @param y The initial vertical distance of the window from the top of the * screen or the parent window. * @param nWidth The width, in pixels, of the window. * @param nHeight The height, in pixels, of the window. * @param hWndParent For a child window, the handle to the parent window; otherwise, * the handle of the owner window if the window has an owner. * @param nIDorHMenu For a child window, the window ID; otherwise, the ID of a menu * for the window. * @param lpParam Pointer to user data that is passed to the CWnd::OnCreate method * in the lpCreateParams field. * @return * TRUE if the method was successful, otherwise FALSE. */ virtual BOOL CreateEx(DWORD dwExStyle, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL); /** * @brief * Creates a preview control window object. * @param dwExStyle Bitwise combination (OR) of extended window styles; otherwise * NULL for the default extended window style. * @param dwStyle Bitwise combination (OR) of window styles; otherwise NULL for * the default window style. * @param rect The size and location of the window relative to the screen or * the parent window. * @param pParentWnd For a child window, pointer to the parent window; otherwise, a * pointer to the owner window if the window has an owner. * @param nID For a child window, the window ID; otherwise, the ID of a menu * for the window. * @param lpParam Pointer to user data that is passed to the CWnd::OnCreate method * in the lpCreateParams field. * @return * TRUE if the method was successful, otherwise FALSE. */ virtual BOOL CreateEx(DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL); using CWnd::Create; using CWnd::CreateEx; /** * @brief * Sets a path to a file to preview. * @param lpFilePath File path to preview. */ void Preview(LPCTSTR lpFilePath); /** * @brief * Sets a path to a file to preview. * @param pStream Preview data source stream. If NULL then lpImpliedFileName must be a * @param lpImpliedFileName An implied file name associated with stream data. Its extension * determines the preview provider type used for stream data. * full path. */ void Preview(IStream* pStream, LPCTSTR lpImpliedFileName); /** * @brief * Resets the currently loaded preview. */ void Reset(); /** * @brief * Adds a new preview provider object. The object will be destroyed by the * control upon control destruction. * @param provider A new provider object pointer. * @param associations A string that specifies a list of custom supported file * extensions that will be used in addition to the default * list of supported extensions provided by the provider * (e.g. "doc;docx;xls;xlsx"), or NULL to use only provider * supported extensions. * @details * Every time a new preview request is issued, the providers get checked * in the order of addition. The first provider that is able to create * a preview object for a new preview target is selected. * @see * IXTPPreviewProvider::GetDefaultFileAssociations, IXTPPreviewProvider::CreatePreview */ void AddProvider(IXTPPreviewProvider* provider, LPCTSTR associations = NULL); /** * @brief * Adds all known providers with their default associations in the following order: * 1. CXTPSystemPreviewProvider * 2. CXTPCommonPicturePreviewProvider * 3. CXTPGifPreviewProvider * 4. CXTPMsgPreviewProvider * 5. CXTPTextPreviewProvider * 6. CXTPXamlPreviewProvider * @see * AddProvider */ void AddDefaultProviders(); /** * @brief * Customizes the message displayed when a preview is being loaded. * @param message Custom message. Every occurence of the '%' symbol in the string * will be replaced with the preview target path/name. * @see * SetFailedMessage */ void SetLoadingMessage(LPCTSTR message); /** * @brief * Customizes the message displayed when a preview cannot be obtained. * @param message Custom message. Every occurence of the '%' symbol in the string * will be replaced with the preview target path/name. * @see * SetLoadingMessage */ void SetFailedMessage(LPCTSTR message); /** * @brief * Provides access to the background color value used for filling the * preview area. * @return * Current color value. * @see * GetForegroundColor */ COLORREF GetBackgroundColor() const; /** * @brief * Sets the background color value used for filling the * preview area. * @param cr New color value. * @see * GetForegroundColor */ void SetBackgroundColor(COLORREF cr); /** * @brief * Provides access to the foreground color value used for text messages * in the preview area. * @return * Current color value. * @see * GetBackgroundColor */ COLORREF GetForegroundColor() const; /** * @brief * Sets the foreground color value used for text messages * in the preview area. * @param cr New color value. * @see * GetBackgroundColor */ void SetForegroundColor(COLORREF cr); /** * @brief * Sets an automatic preview activation on loading. By default this behavior is not * enabled because it is undefined how some system provided preview handlers will behave on * activation. If the behavior is enabled then every time when a new preview is loaded its * provider tries actiate, set focus, or do whatever else is deemed to be an activate state * of a preview for that particular provider. A provider may not support this behavior at * all if it makes no sense for provided preview, for example a static picture. * @param bEnable TRUE to enable the behavior, FALSE to disable. */ void EnableAutoPreviewActivate(BOOL bEnable = TRUE); /** * @brief * Gets an automatic preview activation on loading. By default this behavior is not * enabled because it is undefined how some system provided preview handlers will behave on * activation. If the behavior is enabled then every time when a new preview is loaded its * provider tries actiate, set focus, or do whatever else is deemed to be an activate state * of a preview for that particular provider. A provider may not support this behavior at * all if it makes no sense for provided preview, for example a static picture. * @return * The current state of the behavior. */ BOOL IsAutoPreviewActivateEnabled() const; protected: /** @cond */ DECLARE_MESSAGE_MAP() virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual void PreSubclassWindow(); /** @endcond */ private: void SetCompositionWnd(HWND hCompositionWnd); BOOL IsExtensionInString(const CString& strAssociation, LPCTSTR lpExt) const; int CalcNavigatorHeight(); void CreateHostAndNavigator(); void ChangeChildrenPosition(WINDOWPOS* lpwndpos); afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnDestroy(); afx_msg void OnWindowPosChanging(WINDOWPOS* lpwndpos); afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos); afx_msg void OnFirst(); afx_msg void OnLast(); afx_msg void OnPrev(); afx_msg void OnNext(); private: CPtrArray m_providers; CStringArray m_additionalAssociations; CString m_strLoadingMessage; CString m_strFailedMessage; BOOL m_bChildrenCreated; BOOL m_bShowNavigator; CXTPPreviewHostWindow* m_pHostWindow; CXTPPreviewNavigatorWindow* m_pNavigatorWindow; CRect m_rPrevPlace; int m_iNavHeight; BOOL m_bSubclassed; HWND m_hCompositionWnd; COLORREF m_crBack; COLORREF m_crFore; BOOL m_bAutoActivate; }; /** @cond */ AFX_INLINE void CXTPPreviewCtrl::SetCompositionWnd(HWND hCompositionWnd) { m_hCompositionWnd = hCompositionWnd; } AFX_INLINE COLORREF CXTPPreviewCtrl::GetBackgroundColor() const { return m_crBack; } AFX_INLINE void CXTPPreviewCtrl::SetBackgroundColor(COLORREF cr) { m_crBack = cr; } AFX_INLINE COLORREF CXTPPreviewCtrl::GetForegroundColor() const { return m_crFore; } AFX_INLINE void CXTPPreviewCtrl::SetForegroundColor(COLORREF cr) { m_crFore = cr; } AFX_INLINE void CXTPPreviewCtrl::EnableAutoPreviewActivate(BOOL bEnable /*= TRUE*/) { m_bAutoActivate = bEnable; } AFX_INLINE BOOL CXTPPreviewCtrl::IsAutoPreviewActivateEnabled() const { return m_bAutoActivate; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPPREVIEWCTRL_H__) /** @endcond */