/** * @file XTPSyntaxEditLineMarksManager.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(__XTPSYNTAXEDITLINEMARKSMANAGER_H__) # define __XTPSYNTAXEDITLINEMARKSMANAGER_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" typedef LPCTSTR XTP_EDIT_LINEMARKTYPE; // You can define your own line mark types (as string constants) // Strings are case sensitive! // static const XTP_EDIT_LINEMARKTYPE xtpEditLMT_Bookmark = _T("Bookmark"); static const XTP_EDIT_LINEMARKTYPE xtpEditLMT_Breakpoint = _T("Breakpoint"); static const XTP_EDIT_LINEMARKTYPE xtpEditLMT_Collapsed = _T("Collapsed"); /** * @brief * Enumerates types of mark refreshing */ enum XTPSyntaxEditLineMarksRefreshType { xtpEditLMRefresh_Unknown = 0, /**< Unknown refresh state. */ xtpEditLMRefresh_Insert = 0x01, /**< Mark inserted. */ xtpEditLMRefresh_Delete = 0x02, /**< Mark deleted. */ xtpEditLMRefresh_Delete_only1 = 0x10, /**< Delete mark for first row of deleted text block. */ xtpEditLMRefresh_Delete_only2 = 0x20, /**< Delete mark for last row of deleted text block. */ xtpEditLMRefresh_InsertAt0 = 0x40, /**< Move mark for first row of inserted text block. */ }; /** @cond */ class _XTP_EXT_CLASS CXTPSyntaxEditVoidObj : public CXTPCmdTarget { public: typedef void(AFX_CDECL* TPFDeleter)(void*); protected: void* m_pPtr; /**< A pointer to a handled object */ TPFDeleter m_pfDeleter; public: /** * @param pPtr [in]Pointer to the handled object. * @param pfDeleter [in]pointer to function which should * delete object in pPtr. * By default this parameter is NULL. * @brief Default class constructor. * @see ~CXTPSmartPtrInternalT() */ CXTPSyntaxEditVoidObj(void* pPtr, TPFDeleter pfDeleter = NULL) { m_pPtr = pPtr; m_pfDeleter = pfDeleter; }; /** * @brief Default class destructor. * @details Call InternalRelease() for the not NULL handled object. * @see CXTPSmartPtrInternalT constructors */ virtual ~CXTPSyntaxEditVoidObj() { if (m_pfDeleter) { m_pfDeleter(m_pPtr); } else { SAFE_DELETE(m_pPtr); } }; /** * @brief Get a handled object. * @return Pointer to the handled object. */ operator void*() const { return m_pPtr; } void* GetPtr() const { return m_pPtr; } /** * @brief Check is handled object equal NULL. * @return TRUE if handled object equal NULL, else FALSE. */ BOOL operator!() const { return !m_pPtr; } }; typedef CXTPSmartPtrInternalT CXTPSyntaxEditVoidObjPtr; /** * @brief * Defines line marks manager parameter type. */ enum XTPSyntaxEditLMParamType { xtpEditLMPT_Unknown = 0, /**< Unknown type. */ xtpEditLMPT_DWORD = 1, /**< Specifies DWORD as a parameter type. */ xtpEditLMPT_double = 2, /**< Specifies double as a parameter type. */ xtpEditLMPT_Ptr = 3, /**< Specifies pointer as a parameter type. */ }; struct _XTP_EXT_CLASS XTP_EDIT_LMPARAM { // Data type XTPSyntaxEditLMParamType m_eType; // Data union { DWORD m_dwValue; /**< xtpEditLMPT_DWORD */ double m_dblValue; /**< xtpEditLMPT_double */ }; protected: CXTPSyntaxEditVoidObjPtr m_Ptr; public: // END Data XTP_EDIT_LMPARAM(); virtual ~XTP_EDIT_LMPARAM(); XTP_EDIT_LMPARAM(const XTP_EDIT_LMPARAM& rSrc); XTP_EDIT_LMPARAM(DWORD dwVal); XTP_EDIT_LMPARAM(double dblValue); XTP_EDIT_LMPARAM(void* pPtr); const XTP_EDIT_LMPARAM& operator=(const XTP_EDIT_LMPARAM& rSrc); const XTP_EDIT_LMPARAM& operator=(DWORD dwValue); const XTP_EDIT_LMPARAM& operator=(double dblValue); const XTP_EDIT_LMPARAM& operator=(void* pPtr); operator DWORD() const; operator double() const; operator void*() const; void SetPtr(void* pPtr, CXTPSyntaxEditVoidObj::TPFDeleter pfDeleter = NULL); void* GetPtr() const; BOOL IsValid() const; void Clear(); }; struct _XTP_EXT_CLASS XTP_EDIT_LMDATA { int m_nRow; XTP_EDIT_LMPARAM m_Param; XTP_EDIT_LMDATA(); virtual ~XTP_EDIT_LMDATA(); XTP_EDIT_LMDATA(const XTP_EDIT_LMDATA& rSrc); const XTP_EDIT_LMDATA& operator=(const XTP_EDIT_LMDATA& rSrc); }; /** @endcond */ /** * @brief * The CXTPSyntaxEditLineMarksManager class provides functionality to * manipulate marks on text lines. Used internally by the Smart Edit control. */ class _XTP_EXT_CLASS CXTPSyntaxEditLineMarksManager : public CXTPCmdTarget { /** @cond */ DECLARE_DYNAMIC(CXTPSyntaxEditLineMarksManager) /** @endcond */ public: /** * @brief * Default object constructor. */ CXTPSyntaxEditLineMarksManager(); /** * @brief * Destroys a CXTPSyntaxEditLineMarksManager object, handles * cleanup and de-allocation. */ virtual ~CXTPSyntaxEditLineMarksManager(); /** * @brief * Adds/removes a specified mark to/from a specified row. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. * @param pParam [in] Pointer to XTP_EDIT_LMPARAM. * The default value for this parameter is NULL. * @details * If the row does not have the specified mark, then the mark * will be added. * If the row does have the specified mark, then the mark * will be deleted. * @see * XTP_EDIT_LMPARAM */ void AddRemoveLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType, XTP_EDIT_LMPARAM* pParam = NULL); /** * @brief * Adds a specified mark to a specified row. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. * @param pParam [in] Pointer to XTP_EDIT_LMPARAM. * The default value for this parameter is NULL. * @see * XTP_EDIT_LMPARAM */ void SetLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType, XTP_EDIT_LMPARAM* pParam = NULL); /** * @brief * Removes a specified mark from a specified row. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. */ void DeleteLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); /** * @brief * Determines if a specified row has a specified mark. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. * @param pParam [in] Pointer to XTP_EDIT_LMPARAM. * The default value for this parameter is NULL. * @return * TRUE if the specified row has the specified mark, otherwise FALSE. */ BOOL HasRowMark(int nRow, const XTP_EDIT_LINEMARKTYPE& lmType, XTP_EDIT_LMPARAM* pParam = NULL) const; /** * @brief * Gets the position of the row with a specified mark type * that precedes a specified row. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. * @return * The POSITION of the row with the specified mark type * that precedes the specified row. */ POSITION FindPrevLineMark(int& nRow, const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Gets the position of the row with a specified mark type * that follows a specified row. * @param nRow [in] Row number. * @param lmType [in] Mark type identifier. * @return * The POSITION of the row with the specified mark type * that follows the specified row. */ POSITION FindNextLineMark(int& nRow, const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Gets the position of the last row with a specified mark type. * @param lmType [in] Mark type identifier. * @return * The POSITION of the last row with the specified mark type. */ POSITION GetLastLineMark(const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Gets the position of the first row with a specified mark type. * @param lmType [in] Mark type identifier. * @return * The POSITION of the first row with the specified mark type. */ POSITION GetFirstLineMark(const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Gets the identifier of the row with a specified mark type * that follows a specified position. * @param pos [in] Reference to a POSITION value. * @param lmType [in] Mark type identifier. * @return * A pointer to an XTP_EDIT_LMDATA structure that contains * the identifier of the row with the specified mark type * that follows the specified position. * @see * XTP_EDIT_LMDATA */ XTP_EDIT_LMDATA* GetNextLineMark(POSITION& pos, const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Gets the identifier of the row with a specified mark type * at a specified position. * @param pos [in] POSITION value. * @param lmType [in] Mark type identifier. * @return * A pointer to an XTP_EDIT_LMDATA structure that contains * the identifier of the row with the specified mark type * at the specified position. * @see * XTP_EDIT_LMDATA */ XTP_EDIT_LMDATA* GetLineMarkAt(const POSITION pos, const XTP_EDIT_LINEMARKTYPE lmType) const; /** * @brief * Refreshes the line marks for a specified range of rows. * @param nRowFrom [in] Start row. * @param nRowTo [in] End row. * @param nRefreshType [in] Refresh type; must be one of the values defined by * the XTPSyntaxEditLineMarksRefreshType enumeration. * @see * XTPSyntaxEditLineMarksRefreshType. */ virtual void RefreshLineMarks(int nRowFrom, int nRowTo, int nRefreshType); /** * @brief * Removes all line marks of a specified type. * @param lmType [in] Mark type identifier. */ void RemoveAll(const XTP_EDIT_LINEMARKTYPE lmType); /** * @brief * Gets the number of line marks of a specified type. * @param lmType [in] Mark type identifier. * @return * The number of line marks of the specified type. */ int GetCount(const XTP_EDIT_LINEMARKTYPE lmType) const; private: /** * @brief * This internal helper class is designed to store a sorted list of * line marks data objects. This class is based on CArray and provides * typical operations like fast binary searching inside it and basic * line marks manipulations. */ class CLineMarksList : public CXTPCmdTarget { public: /** * @brief * Default object destructor. */ virtual ~CLineMarksList(); /** * @brief * Adds a specified element to the list. * @param lmData [in] Reference to an XTP_EDIT_LMDATA structure. * @see * XTP_EDIT_LMDATA. */ void Add(const XTP_EDIT_LMDATA& lmData); /** * @brief * Removes the element with a specified key value from the list. * @param nKey [in] Key value. */ void Remove(const int nKey); /** * @brief * Removes all elements from the list. */ void RemoveAll(); /** * @brief * Gets the number of elements in the list. * @return * The number of elements in the list. */ int GetCount() const; /** * @brief * Gets the position of the element with a specified key value. * @param nKey [in] Key value. * @return * The POSITION of the element with the specified key value. */ POSITION FindAt(int nKey) const; /** * @brief * Gets the position of the element with the key value following * a specified key value. * @param nKey [in] Key value. * @return * The POSITION of the element with the key value following * the specified key value. */ POSITION FindNext(int nKey) const; /** * @brief * Gets the position of the element with the key value preceding * a specified key value. * @param nKey [in] Key value. * @return * The POSITION of the element with the key value preceding * the specified key value. */ POSITION FindPrev(int nKey) const; /** * @brief * Refreshes the line marks for a specified range of rows. * @param nRowFrom [in] Start row. * @param nRowTo [in] End row. * @param nRefreshType [in] Refresh type; must be one of the values defined by * the XTPSyntaxEditLineMarksRefreshType enumeration. * @see * XTPSyntaxEditLineMarksRefreshType */ void RefreshLineMarks(int nRowFrom, int nRowTo, int nRefreshType); /** * @brief * Gets the identifier of the row at a specified position. * @param pos [in] POSITION value. * @return * A pointer to an XTP_EDIT_LMDATA structure that contains * the identifier of the row at the specified position. */ XTP_EDIT_LMDATA* GetLineMarkAt(const POSITION pos) const; /** * @brief * Gets the position of the first row with a mark. * @return * The POSITION of the first row with a mark. */ POSITION GetFirstLineMark() const; /** * @brief * Gets the identifier of the row following a specified position. * @param pos [in] Reference to a POSITION value. * @return * A pointer to an XTP_EDIT_LMDATA structure that contains * the identifier of the row following the specified position. */ XTP_EDIT_LMDATA* GetNextLineMark(POSITION& pos) const; private: /** * @brief * Gets the index of the element with a specified key value. * @param nKey [in] Key value. * @return * The index of the element with the specified key value * if found, otherwise -1. */ int FindIndex(const int nKey) const; /** * @brief * Gets the index of the element with the key value preceding * a specified key value. * @param nKey [in] Key value. * @return * The index of the element with the key value preceding * the specified key value if found, otherwise -1. */ int FindLowerIndex(const int nKey) const; /** * @brief * Gets the index of the element with the key value following * a specified key value. * @param nKey [in] Key value. * @return * The index of the element with the key value following * the specified key value if found, otherwise -1. */ int FindUpperIndex(const int nKey) const; private: typedef CArray CXTPSyntaxEditLineMarkPointersArray; CXTPSyntaxEditLineMarkPointersArray m_array; /**< The array with the actual line data. */ }; public: typedef CXTPSmartPtrInternalT CLineMarksListPtr; /**< SmartPointer for the class. */ private: /** * @brief * This class contains a map of line marks lists corresponding to the * string values of line marks types. * It allows for adding a new list with the new line mark type * and retrieving a smart pointer of the requested list by its * line mark type. */ class CLineMarksListsMap { public: /** * @brief * Gets the list associated with a specified line mark type string. * @param szMarkType [in] Line mark type string. * @see * CLineMarksListPtr */ CLineMarksListPtr GetList(LPCTSTR szMarkType) const; /** * @brief * Adds a new list associated with a specified line mark type string. * @param szMarkType [in] Line mark type string. * @return * A pointer to the newly added list. * @see * CLineMarksListPtr */ CLineMarksListPtr AddList(LPCTSTR szMarkType); /** * @brief * Refreshes the line marks for a specified range of rows. * @param nRowFrom [in] Start row. * @param nRowTo [in] End row. * @param nRefreshType [in] Refresh type; must be one of the values defined by * the XTPSyntaxEditLineMarksRefreshType enumeration. * @see * XTPSyntaxEditLineMarksRefreshType */ void RefreshLineMarks(int nRowFrom, int nRowTo, int nRefreshType); private: CMap m_map; /**< A map containing line marks lists for every mark type. */ }; CLineMarksListsMap m_mapLists; /**< A collection of line marks lists for all line mark types. */ protected: # ifdef _XTP_ACTIVEX /** @cond */ DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPSyntaxEditLineMarksManager) afx_msg void OleAddRemoveLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg void OleSetLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg void OleDeleteLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg BOOL OleHasRowMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg POSITION OleFindPrevLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg POSITION OleFindNextLineMark(int nRow, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg POSITION OleGetLastLineMark(const XTP_EDIT_LINEMARKTYPE lmType); afx_msg POSITION OleGetFirstLineMark(const XTP_EDIT_LINEMARKTYPE lmType); afx_msg long OleGetLineMarkAt(const POSITION pos, const XTP_EDIT_LINEMARKTYPE lmType); afx_msg void OleRemoveAll(XTP_EDIT_LINEMARKTYPE lmType); afx_msg long OleGetCount(XTP_EDIT_LINEMARKTYPE lmType); /** @endcond */ # endif }; # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPSYNTAXEDITLINEMARKSMANAGER_H__) /** @endcond */