/** * @file XTPGaugeCtrl.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 * */ #if !defined(__XTPGAUGECTRL_H__) # define __XTPGAUGECTRL_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPGaugeTraits; class CXTPGaugeBaseType; class CXTPGaugeMeterType; class CXTPGaugeStateType; /** * @brief * The message gets sent to the gauge parent window when gauge state gets updated from the Gauge * control in the result of Gauge.update JavaScript call. * * @param wParam Not used. * @param lParam Pointer to CXTPGaugeBaseType object of the gauge that has triggered the event. * @returns Return value is not used. */ # define XTP_WM_GAUGEUPDATE CXTPGaugeCtrl::m_XTP_WM_GAUGEUPDATE /** * @brief * Adds XTP_WM_GAUGEUPDATE message handler to a message map. * * @see XTP_WM_GAUGEUPDATE */ # define ON_XTP_WM_GAUGEUPDATE(member) ON_REGISTERED_MESSAGE(XTP_WM_GAUGEUPDATE, member) /** * @brief * Provides a client site interface for a gauge control owner. */ struct IXTPGaugeClientSite { /** @cond */ virtual ~IXTPGaugeClientSite() { } /** @endcond */ /** * @brief * Notifies client site about a gauge update event. * @param type Gauge type. */ virtual void OnGaugeUpdated(CXTPGaugeBaseType& type) = 0; }; /** * @brief * Gauge control hosts a JavaScript and Markup based gauge implementation of a certain type and * provides a bidirectional data and event exchange between native and script implementation. * * @details * A complete gauge consists of 4 major parts: * - A gauge control: a window for Markup context * - A gauge type object: defines a set of common type specific actions and properties * - A gauge markup: defines a visual template of a gauge type and contains a type specific * gauge execution script in JavaScript * - A gauge traits object: a JavaScript object with a set of type and markup specific * properties used by the Markup embedded script. * * Main points to consider during custom gauge development are: * - A gauge control is capable to load any gauge types * - One gauge type object can work with any compatible gauge Markup ("type" value in the * traits must match gauge type name) * - One gauge Markup can accept any compatibe gauge traits object that will be used for * gauge * setup and customization according to the logic and rules defined in the Markup embedded * script. * * @see CXTPGaugeTraits * @see CXTPGaugeBaseType */ class _XTP_EXT_CLASS CXTPGaugeCtrl : public CWnd { friend class CXTPGaugeBaseType; DECLARE_DYNAMIC(CXTPGaugeCtrl); public: /** * @brief * Constructs gauge control object. */ CXTPGaugeCtrl(); /** * @brief * Handles gauge control object destruction. */ ~CXTPGaugeCtrl(); public: /** * @brief * Registers the window class if it has not already been registered. * * @param hInstance Instance of the resource where the control is located. * @returns TRUE if the window class was successfully registered, otherwise * FALSE. */ BOOL RegisterWindowClass(HINSTANCE hInstance = NULL); /** * @brief * Creates a Gauge 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 The create context of the window. * @returns TRUE if the method was successful, otherwise FALSE. * @see CreateEx(DWORD, DWORD, int, int, int, int, HWND, HMENU, LPVOID) * @see CreateEx(DWORD, DWORD, const RECT&, CWnd*, UINT, LPVOID) */ virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); /** * @brief * Creates a Gauge 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. * @returns TRUE if the method was successful, otherwise FALSE. * @see Create(DWORD, const RECT&, CWnd*, UINT, CCreateContext*) * @see CreateEx(DWORD, DWORD, const RECT&, CWnd*, UINT, LPVOID) */ 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 Gauge 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 lpParam Pointer to user data that is passed to the CWnd::OnCreate * method in the lpCreateParams field. * @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. * @returns TRUE if the method was successful, otherwise FALSE. * @see Create(DWORD, const RECT&, CWnd*, UINT, CCreateContext*) * @see CreateEx(DWORD, DWORD, int, int, int, int, HWND, HMENU, LPVOID) */ virtual BOOL CreateEx(DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL); using CWnd::Create; using CWnd::CreateEx; /** * @brief * Obtains an associated gauge client site interface. * @return The value of the associated client site interface. */ IXTPGaugeClientSite* GetCilentSite() const; /** * @brief * Sets an associated gauge client site interface. * @param pSite The new value of the associated client site interface. */ void SetCilentSite(IXTPGaugeClientSite* pSite); /** * @brief * Determines if any gauge type is currently loaded. * * @returns TRUE if loaded and FALSE otherwise. */ BOOL IsLoaded() const; /** * @brief * Loads a gauge using the specified gauge type from the data source provided using provided * gauge traits. * * @param pClass A gauge type class pointer. The type class must be derived from * CXTPGaugeBaseType * @param source A gauge Markup data stream object * @param traits A gauge traits object * @returns A generalized pointer to the loaded gauge type object or NULL if * loading has failed. */ CXTPGaugeBaseType* Load(CRuntimeClass* pClass, IStream& source, const CXTPGaugeTraits& traits); /** * @brief * Obtains a generalized pointer of the currently loaded gauge type object. * * @returns Gauge type object pointer or NULL is no gauge type is loaded. */ CXTPGaugeBaseType* GetType(); /** * @brief * Obtains a generalized pointer of the currently loaded gauge type object. * * @returns A const Gauge type object pointer or NULL is no gauge type is loaded. */ const CXTPGaugeBaseType* GetType() const; /** * @brief * Checks if the currently loaded gauge type is of the specified class. * * @param pClass A gauge type class pointer * @returns TRUE if the currently loaded gauge is of the the type specified, * FALSE otherwise or if no gauge type is loaded. */ BOOL IsType(CRuntimeClass* pClass) const; /** * @brief * A helper method for loading CXTPGaugeMeterType gauge. * * @param source A gauge Markup data stream object * @param traits A gauge traits object * @returns A generalized pointer to the loaded gauge type object or NULL if * loading has failed. */ CXTPGaugeMeterType* LoadMeterType(IStream& source, const CXTPGaugeTraits& traits); /** * @brief * A helpers method for obtaining the currently loaded gauge type as CXTPGaugeMeterType. * * @returns Gauge type pointer or NULL if no gauge type is loaded or the loaded * gauge has a different type. */ CXTPGaugeMeterType* GetMeterType(); /** * @brief * A helpers method for obtaining the currently loaded gauge type as CXTPGaugeMeterType. * * @returns A const Gauge type pointer or NULL if no gauge type is loaded or the * loaded gauge has a different type. */ const CXTPGaugeMeterType* GetMeterType() const; /** * @brief * Determines if the currently loaded gauge type is CXTPGaugeMeterType. * * @returns TRUE if the currently loaded gauge type is CXTPGaugeMeterType, * FALSE otherwise of if no gauge type is loaded. */ BOOL IsMeterType() const; /** * @brief * A helper method for loading CXTPGaugeStateType gauge. * * @param source A gauge Markup data stream object * @param traits A gauge traits object * @returns A generalized pointer to the loaded gauge type object or NULL if * loading has failed. */ CXTPGaugeStateType* LoadStateType(IStream& source, const CXTPGaugeTraits& traits); /** * @brief * A helpers method for obtaining the currently loaded gauge type as CXTPGaugeStateType. * * @returns Gauge type pointer or NULL if no gauge type is loaded or the loaded * gauge has a different type. */ CXTPGaugeStateType* GetStateType(); /** * @brief * A helpers method for obtaining the currently loaded gauge type as CXTPGaugeStateType. * * @returns Const Gauge type pointer or NULL if no gauge type is loaded or the * loaded gauge has a different type. */ const CXTPGaugeStateType* GetStateType() const; /** * @brief * Determines if the currently loaded gauge type is CXTPGaugeStateType. * * @returns TRUE if the currently loaded gauge type is CXTPGaugeStateType, * FALSE otherwise of if no gauge type is loaded. */ BOOL IsStateType() const; /** * @brief * Unloads the currently loaded gauge type. */ void Unload(); /** @cond */ BOOL IsTabStopEnabled() const; void EnableTabStop(BOOL bEnable = TRUE); void Draw(CDC* pDC, const CRect& rcPaint); static const UINT m_XTP_WM_GAUGEUPDATE; static const UINT m_XTP_WM_GAUGEDELAYREDRAW; /** @endcond */ private: void NotifyUpdate(CXTPGaugeBaseType& type); protected: /** @cond */ virtual BOOL PreCreateWindow(CREATESTRUCT& cs); virtual void PreSubclassWindow(); virtual BOOL OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult); DECLARE_MESSAGE_MAP() afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnDestroy(); afx_msg void OnPaint(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg LRESULT OnDelayRedraw(WPARAM, LPARAM); afx_msg void OnSetFocus(CWnd* pWnd); afx_msg void OnKillFocus(CWnd* pWnd); /** @endcond */ private: void OnInitialSetup(); void SetTransparentBackgroundColor(COLORREF color); void SetBackgroundColor(COLORREF color); void ApplyTransparentBackgroundColor(); private: BOOL m_bSubclassed; mutable BOOL m_bTabStopEnabled; BOOL m_bFocused; CXTPMarkupContext* m_pMarkupContext; CXTPGaugeBaseType* m_pType; COLORREF m_crTransparent; COLORREF m_crBackground; IXTPGaugeClientSite* m_pClientSite; }; AFX_INLINE IXTPGaugeClientSite* CXTPGaugeCtrl::GetCilentSite() const { return m_pClientSite; } AFX_INLINE void CXTPGaugeCtrl::SetCilentSite(IXTPGaugeClientSite* pSite) { m_pClientSite = pSite; } AFX_INLINE BOOL CXTPGaugeCtrl::IsLoaded() const { return (NULL != m_pType); } AFX_INLINE CXTPGaugeBaseType* CXTPGaugeCtrl::GetType() { return m_pType; } AFX_INLINE const CXTPGaugeBaseType* CXTPGaugeCtrl::GetType() const { return m_pType; } AFX_INLINE const CXTPGaugeMeterType* CXTPGaugeCtrl::GetMeterType() const { return const_cast(this)->GetMeterType(); } AFX_INLINE BOOL CXTPGaugeCtrl::IsMeterType() const { return (NULL != GetMeterType()); } AFX_INLINE const CXTPGaugeStateType* CXTPGaugeCtrl::GetStateType() const { return const_cast(this)->GetStateType(); } AFX_INLINE BOOL CXTPGaugeCtrl::IsStateType() const { return (NULL != GetStateType()); } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(__XTPGAUGECTRL_H__)