/** * @file XTPSyntaxEditLexColorFileReader.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(__XTPSYNTAXEDITLEXCOLORFILEREADER_H__) # define __XTPSYNTAXEDITLEXCOLORFILEREADER_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPSyntaxEditColorTheme; class CXTPNotifyConnection; class CXTPNotifyConnectionMT; struct XTP_EDIT_SCHEMAFILEINFO; class CXTPSyntaxEditSchemaFileInfoList; /** * @brief * This enumeration describes allowable configuration managers flags. */ enum XTPSyntaxEditCfgFlags { xtpEditCfgFileAdd = 0x0001, /**< File should be added.*/ xtpEditCfgFileRemove = 0x0002, /**< File should be removed.*/ }; /** * @brief * This storage class is designed to contain information from the color * settings file section. It helps to easily retrieve color information. */ class _XTP_EXT_CLASS CXTPSyntaxEditColorInfo { public: /** * @brief * Object constructor. * @param pTheme [in] Pointer to a CXTPSyntaxEditColorTheme object * (theme that this color information belongs to). */ CXTPSyntaxEditColorInfo(CXTPSyntaxEditColorTheme* pTheme); /** * @brief * Object constructor. * @param pTheme [in] Pointer to a CXTPSyntaxEditColorTheme object * (theme that this color information belongs to). * @param strClassName [in] Reference to the lex class name. */ CXTPSyntaxEditColorInfo(const CString& strClassName, CXTPSyntaxEditColorTheme* pTheme); /** * @brief * Destroys a CXTPSyntaxEditColorTheme() object, handles cleanup and * de-allocation */ virtual ~CXTPSyntaxEditColorInfo(); /** * @brief * Adds a parameter. * @param strName [in] Reference to the parameter name. * @param strValue [in] Reference to the parameter value. */ void AddParam(const CString& strName, const CString& strValue); /** * @brief * Retrieves the value of a parameter with a specified name. * @param strName [in] Name of the parameter to retrieve the value of. * @param bDynamic [in] TRUE to search for the value of the parameter * within parent themes (dynamically), * FALSE to only search for the value of the parameter * within the current theme. * @return * The value of the parameter with the specified name. */ const CString GetParam(const CString& strName, BOOL bDynamic = TRUE); /** * @brief * Retrieves the hexadecimal value of a parameter with a specified name. * @param strName [in] Name of the parameter to retrieve the value of. * @param bDynamic [in] TRUE to search for the value of the parameter * within parent themes (dynamically), * FALSE to only search for the value of the parameter * within the current theme. * @return * The hexadecimal value of the parameter with the specified name. */ DWORD GetHexParam(const CString& strName, BOOL bDynamic = TRUE); /** * @brief * Gets the first parameter name position. * @return * The first parameter name position. */ POSITION GetFirstParamNamePosition(); /** * @brief * Gets the next parameter name. * @param pos [in] Reference to a POSITION value. * @return * The next parameter name. */ const CString GetNextParamName(POSITION& pos); /** * @brief * Gets the lex class name. * @return * The lex class name. */ const CString GetClassName() const; private: CString m_strClassName; /**< Lex class name. */ CMapStringToString m_mapParams; /**< Name/value parameters map. */ CXTPSyntaxEditColorTheme* m_pTheme; /**< Pointer to the theme this color information belongs to. */ }; /** * @brief * This collection class stores the color info objects. */ class _XTP_EXT_CLASS CXTPSyntaxEditColorInfoArray : public CArray { typedef CArray TBase; public: /** * @brief * Constructor, creates and initializes the object. */ CXTPSyntaxEditColorInfoArray(){}; /** * @brief * Destructor, do the cleaups and destroys the object. */ virtual ~CXTPSyntaxEditColorInfoArray() { RemoveAll(); }; /** * @brief * Removes all of the color info objects. */ void RemoveAll() { for (int i = 0; i < GetSize(); i++) { if (GetAt(i)) { delete GetAt(i); } } TBase::RemoveAll(); } }; class CXTPSyntaxEditColorThemesManager; class CXTPSyntaxEditFileChangesMonitor; class CXTPSyntaxEditPropertiesTheme; /** * @brief * This class provides the functionality to read configuration information * from configuration files with a predefined structure. Its information * describes the color settings for the corresponding lexical items of * a given language. * You construct an instance of CXTPSyntaxEditColorTheme by calling its * constructor. Then you should call the Load member function * to read data from persistent storage. */ class _XTP_EXT_CLASS CXTPSyntaxEditColorTheme { friend class CXTPSyntaxEditPropertiesTheme; /** * @brief * Defines a custom array type to store CXTPSyntaxEditColorInfo structures. * @see * CXTPSyntaxEditColorInfo. */ typedef CMap CXTPSyntaxEditMapLexColorInfo; public: /** * @brief * Default object constructor. * @param pThemesManager [in] Pointer to the parent themes manager. */ CXTPSyntaxEditColorTheme(CXTPSyntaxEditColorThemesManager* pThemesManager); /** * @brief * Destroys a CXTPSyntaxEditColorTheme() object, handles cleanup and * de-allocation. */ virtual ~CXTPSyntaxEditColorTheme(); /** * @brief * Parses the associated color schema file and fills * internal color information structures. * @param csFileName [in] Reference to the configuration file name. */ virtual void Load(const CString& csFileName); /** * @brief * Loads a color scheme. * @param arPassedString [in] Reference to an array of color scheme attributes. */ virtual void LoadFromString(CStringArray& arPassedString); /** * @brief * Gets the name of the parent schema. * @return * The name of the parent schema. */ const CString GetParentThemeName(); /** * @brief * Gets the parent schema. * @return * A pointer to the parent schema if it exists, otherwise NULL. */ CXTPSyntaxEditColorTheme* GetParentTheme(); /** * @brief * Gets the color information. * @param strLexClass [in] Reference to the lex class name. * @param strThemeFilename [in] Reference to the configuration file name. * @param bDynamic [in] TRUE to search for the color information * within parent themes (dynamically), * FALSE to only search for the color information * within the current theme. * @details * strThemeFilename is required in order to avoid calling recursion. * @return * A pointer to the color information. */ CXTPSyntaxEditColorInfo* GetColorInfo(const CString& strLexClass, const CString& strThemeFilename, BOOL bDynamic = TRUE); /** * @brief * Gets the configuration file name. * @return * The configuration file name. */ CString GetFileName(); /** * @brief * Saves colors to the configuration file. * @param strParentThemeName Parent theme name. * @param pColorInfoArray_new Pointer to the colors information array. * @return * TRUE if successful, otherwise FALSE. * @see * GetFileName */ BOOL WriteCfgFile(CString strParentThemeName, CXTPSyntaxEditColorInfoArray* pColorInfoArray_new); protected: /** * @brief * Cleans up the collection. */ void Cleanup(); /** * @brief * Parses a single section of the configuration file and * creates a CXTPSyntaxEditColorInfo object from it. * @param csSection [in] Reference to the section name * (in the configuration file). * @return * A pointer to the newly created CXTPSyntaxEditColorInfo object. */ CXTPSyntaxEditColorInfo* ParseSection(const CString& csSection); /** * @brief * Parses a single section of the configuration file and * creates a CXTPSyntaxEditColorInfo object from it. * @param csSection [in] Reference to the section name * (in the configuration file). * @param arPassedString [in] Reference to a CStringArray object. * @return * A pointer to the newly created CXTPSyntaxEditColorInfo object. */ CXTPSyntaxEditColorInfo* ParseSectionFromString(const CString& csSection, CStringArray& arPassedString); private: CStringList m_arSections; /**< All section names from the theme configuration file. */ CString m_csFileName; /**< Filename of the corresponding theme configuration file. */ CXTPSyntaxEditMapLexColorInfo m_mapLexColorInfo; /**< Internal map - lex class name to color info. */ CXTPSyntaxEditColorThemesManager* m_pThemesManager; /**< Pointer to the parent themes manager. */ }; AFX_INLINE CString CXTPSyntaxEditColorTheme::GetFileName() { return m_csFileName; } /** * @brief * This class provides the functionality to store the set of * all color themes that would be written from configuration files. */ class _XTP_EXT_CLASS CXTPSyntaxEditColorThemesManager { typedef CMap CXTPSyntaxEditMapThemes; public: /** * @brief * Default object constructor. */ CXTPSyntaxEditColorThemesManager(); /** * @brief * Destroys a CXTPSyntaxEditColorThemesManager() object, * handles cleanup and de-allocation */ virtual ~CXTPSyntaxEditColorThemesManager(); /** * @brief * Loads a theme. * @param strThemeName [in] Reference to the theme name. * @param strThemeFilename [in] Reference to the configuration file name. */ void LoadTheme(const CString& strThemeName, const CString& strThemeFilename); /** * @brief * Loads a theme. * @param strThemeName [in] Reference to the theme name. * @param arPassedString [in] Reference to an array of attribute strings. */ void LoadThemeFromString(const CString& strThemeName, CStringArray& arPassedString); /** * @brief * Adds a new entity to the "theme name - configuration file" map. * @param strThemeName [in] Reference to the theme name. * @param strThemeFilename [in] Reference to the configuration file name. */ void AddThemeInfo(const CString& strThemeName, const CString& strThemeFilename); /** * @brief * Gets the color theme with a specified name. * @param strThemeName [in] Reference to the theme name. * @return * A pointer to the color theme with the specified name. * @see * CXTPSyntaxEditColorTheme */ CXTPSyntaxEditColorTheme* GetTheme(const CString& strThemeName); /** * @brief * Gets all theme names. * @return * A reference to the CStringArray object containing all themes names. */ CStringArray& GetThemes(); /** * @brief * Reloads configuration settings from a specified configuration file. * @param csFileName [in] Reference to the configuration file name. * @param nCfgFlags [in] Action flags. * @return * The reloaded theme name if found, otherwise an empty string. * @details * Does nothing if the specified file is not found in * the collection of files from the main configuration file. * @see * XTPSyntaxEditCfgFileRemove */ CString ReloadFile(const CString& csFileName, int nCfgFlags = 0); /** * @brief * Removes all loaded data. */ void RemoveAll(); private: CXTPSyntaxEditMapThemes m_mapThemes; /**< Themes map. */ CStringArray m_arThemeNames; /**< Themes names array. */ CMapStringToString m_mapFileToTheme; /**< Theme name to configuration file name map. */ }; typedef XTPSyntaxEditLexAnalyser::CXTPSyntaxEditLexTextSchema CXTPSyntaxEditTextSchema; typedef CXTPSmartPtrInternalT CXTPSyntaxEditLexTextSchemaPtr; typedef CXTPSyntaxEditLexTextSchemaPtr CXTPSyntaxEditTextSchemaPtr; /** * @brief * This class provides the functionality to store the set of * all text schemes that would be written from configuration files. */ class _XTP_EXT_CLASS CXTPSyntaxEditTextSchemesManager { typedef CMap CXTPSyntaxEditMapSchemes; public: /** * @brief * Default object constructor. */ CXTPSyntaxEditTextSchemesManager(); /** * @brief * Destroys a CXTPSyntaxEditTextSchemesManager() object, * handles cleanup and de-allocation. */ virtual ~CXTPSyntaxEditTextSchemesManager(); /** * @brief * Adds text scheme information. * @param info [in] Reference to the text scheme information. */ void AddTextSchemeInfo(XTP_EDIT_SCHEMAFILEINFO& info); /** * @brief * Implements common logic on creating new text scheme object and * loading it from file or resources. * @param info [in] Reference to schema information. */ void LoadTextScheme(XTP_EDIT_SCHEMAFILEINFO& info); /** * @brief * Implements common logic on creating new text scheme object and * loading it string - used for non-file configuration mode. * @param info [in] Reference to schema information. * @param p_sSyntaxScheme Pointer to syntax scheme string. */ void LoadTextStringScheme(XTP_EDIT_SCHEMAFILEINFO& info, CString* p_sSyntaxScheme); /** * @brief * Gets a schema by its name. * @param strSchemeName [in] Reference to the schema name. * @return * A CXTPSyntaxEditTextSchemaPtr object. * @see * CXTPSyntaxEditTextSchemaPtr */ CXTPSyntaxEditTextSchemaPtr GetSchema(const CString& strSchemeName); /** * @brief * Gets a schema name by its file name. * @param csFileName [in] Reference to the file name. * @return * The schema name. */ CString GetSchemaName(const CString& csFileName) const; /** * @brief * Gets a file name by its schema name. * @param strSchemeName [in] Reference to the schema name. * @return * The file name. */ CString GetSchemaFileName(const CString& strSchemeName) const; /** * @brief * Gets all scheme names. * @return * A reference to the CStringArray object containing all scheme names. */ CStringArray& GetSchemes(); /** * @brief * Gets the schema list. * @return * A pointer to a CXTPSyntaxEditSchemaFileInfoList object. */ CXTPSyntaxEditSchemaFileInfoList* GetSchemaList() const; /** * @brief * Finds a schema by its file extension. * @param strFileExt [in] Reference to the file extension string. * @return * A CXTPSyntaxEditTextSchemaPtr object. * @see * CXTPSyntaxEditTextSchemaPtr */ CXTPSyntaxEditTextSchemaPtr FindSchema(const CString& strFileExt) const; /** * @brief * Sets the theme for all text schemes. * @param pTheme [in] Pointer to the theme to be set. * @see * CXTPSyntaxEditColorTheme */ void SetTheme(CXTPSyntaxEditColorTheme* pTheme); /** * @brief * Reloads configuration settings from a specified configuration file. * @param csFileName [in] Reference to the configuration file name. * @param nCfgFlags [in] Action flags. * @details * Does nothing if the specified file is not found in * the collection of files from the main configuration file. * @return TRUE if successful, FALSE otherwise. */ BOOL ReloadFile(const CString& csFileName, int nCfgFlags = 0); /** * @brief * Removes all loaded data. */ void RemoveAll(); private: CXTPSyntaxEditMapSchemes m_mapSchemes; CXTPSyntaxEditSchemaFileInfoList* m_plistSchemes; CStringArray m_arSchemeNames; CCriticalSection m_csReadFile; }; AFX_INLINE CStringArray& CXTPSyntaxEditTextSchemesManager::GetSchemes() { return m_arSchemeNames; } AFX_INLINE CXTPSyntaxEditSchemaFileInfoList* CXTPSyntaxEditTextSchemesManager::GetSchemaList() const { return m_plistSchemes; } /** * @brief * This class manages all configuration parameters of the control. * It worries about read configuration files from the disk when * the Edit control is starting, stores it in internal structures * and refreshes parameters in case the configuration files are * changed after the control was started. * @see * CXTPSyntaxEditFileChangesMonitor, CXTPSyntaxEditColorThemesManager */ class _XTP_EXT_CLASS CXTPSyntaxEditConfigurationManager : public CXTPCmdTarget { public: /** * @brief * Configuration manager sub-objects */ enum XTPSyntaxEditCfgObjects { xtpEditCfgObjSchMan = 0x0001, /**< Schemes manager.*/ xtpEditCfgObjThemeMan = 0x0002, /**< Themes manager.*/ xtpEditCfgObjMainConfig = 0x0004, /**< Main configuration file.*/ }; /** * @brief * Default object constructor. */ CXTPSyntaxEditConfigurationManager(); /** * @brief * Destroys a CXTPSyntaxEditConfigurationManager() object, * handles cleanup and de-allocation */ virtual ~CXTPSyntaxEditConfigurationManager(); /** * @brief * Reloads settings from a specified file. * @param strConfigFilePath Reference to the string of the file's full path. * @details * Reloads configuration settings from the specified new configuration file. */ void ReloadConfig(const CString& strConfigFilePath); /** * @brief * Reloads configuration settings from the stored main configuration file. */ void ReloadConfig(); /** * @brief * Asynchronously reloads configuration settings from * the stored main configuration file. * @param nAsyncThreadPriority Priority for the working thread which * reloads the configuration. */ void ReloadConfigAsync(int nAsyncThreadPriority = THREAD_PRIORITY_NORMAL); /** * @brief * Gets the name of the main configuration file. * @return * The name of the main configuration file. * @see * CXTPSyntaxEditConfigurationManager::ReloadConfig */ CString GetConfigFile() const; /** * @brief * Reloads configuration settings from a specified configuration file. * @param csFileName [in] Reference to the configuration file name. * @param dwOwnerFlags [in] Owner flags. * @param nCfgFlags [in] Action flags. * @details * Does nothing if the specified file is not found in * the collection of files from the main configuration file. * @see * XTPSyntaxEditCfgFileRemove */ void ReloadFile(CString csFileName, DWORD dwOwnerFlags, int nCfgFlags = 0); /** * @brief * Gets the color theme manager. * @return * A reference to the color theme manager. */ CXTPSyntaxEditColorThemesManager& GetThemeManager(); /** * @brief * Gets the text scheme manager. * @return * A reference to the text scheme manager. */ CXTPSyntaxEditTextSchemesManager& GetTextSchemesManager(); /** * @brief * Sets the current theme name. * @param strThemeName [in] Reference to the theme name. * @param pActiveSch [in] Pointer to the active schema to apply the current theme. */ void SetTheme(const CString& strThemeName, CXTPSyntaxEditTextSchema* pActiveSch = NULL); /** * @brief * Closes the configuration monitor session. */ void Close(); /** * @brief * Gets the current theme name. * @return * The current theme name. */ CString GetCurrentTheme() const; /** * @brief * Gets the notification connection. * @return * A pointer to the notification connection. */ CXTPNotifyConnection* GetConnection() const; /** * @brief * Sets the syntax and color scheme. * @param pSyntaxScheme Syntax scheme. * @param pColorScheme Color scheme. */ void SetSyntaxAndColorScheme(CString* pSyntaxScheme, CString* pColorScheme) { p_sSyntaxScheme = pSyntaxScheme; p_sColorScheme = pColorScheme; } BOOL m_bUseMonitor; /**< TRUE if the control uses a special thread to synchronize syntax rules with files with Syntax and Color schemes, FALSE if the control works "off-line". */ BOOL m_bConfigFileMode; /**< TRUE if the control reads Config file with links to detailed setting (Syntax and Color schemes), FALSE if Syntax and Color schemes are passed as strings using special functions. */ CString m_sIniSet; /**< The ini file settings. */ CString* p_sSyntaxScheme; /**< Pointer to the syntax scheme. */ CString* p_sColorScheme; /**< Pointer to the color scheme. */ private: static UINT AFX_CDECL ReloadConfigAsync_Proc(LPVOID pThis); CString m_strMainIniFilename; /**< Main configuration file name. */ CXTPSyntaxEditFileChangesMonitor* m_pFolderMonitor; /**< Pointer to the folder monitor object. */ CXTPSyntaxEditColorThemesManager m_ColorThemeManager; /**< Color theme manager. */ CXTPSyntaxEditTextSchemesManager m_TextSchemesManager; /**< Text theme manager. */ CString m_strCurrentThemeName; /**< Current theme name. */ CXTPNotifyConnectionMT* m_pConnectMT; /**< Notification connection. */ CCriticalSection m_DataLockerCS; /**< Critical section. */ HANDLE m_hReloadThread; /**< Handle of monitoring thread. */ CEvent* m_pBreakReloadEvent; /**< Pointer to event. */ }; AFX_INLINE const CString CXTPSyntaxEditColorInfo::GetClassName() const { return m_strClassName; } AFX_INLINE CXTPSyntaxEditColorThemesManager& CXTPSyntaxEditConfigurationManager::GetThemeManager() { return m_ColorThemeManager; } AFX_INLINE CXTPSyntaxEditTextSchemesManager& CXTPSyntaxEditConfigurationManager::GetTextSchemesManager() { return m_TextSchemesManager; } AFX_INLINE CString CXTPSyntaxEditConfigurationManager::GetCurrentTheme() const { return m_strCurrentThemeName; } # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPSYNTAXEDITLEXCOLORFILEREADER_H__) /** @endcond */