Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -N -r6c67d46c243c6a275f2a427c991f82db59c63ef0 -r19b135b50b55b75d008526a799344bda9a62dc22 --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 6c67d46c243c6a275f2a427c991f82db59c63ef0) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 19b135b50b55b75d008526a799344bda9a62dc22) @@ -25,206 +25,248 @@ #include #include -using namespace std; - -BEGIN_ICTRANSLATE_NAMESPACE - -///////////////////////////////////////////////////////////////////////// -// types of notifications +namespace ictranslate +{ + ///////////////////////////////////////////////////////////////////////// + // types of notifications #define WM_RMNOTIFY (WM_USER + 2) // RMNT_LANGCHANGE, LPARAM - HIWORD - old language, LOWORD - new language #define RMNT_LANGCHANGE 0x0001 -typedef void(*PFNNOTIFYCALLBACK)(unsigned int); + typedef void(*PFNNOTIFYCALLBACK)(unsigned int); -class LIBICTRANSLATE_API CFormat -{ -public: - CFormat(); - explicit CFormat(const wchar_t* pszFormat); - ~CFormat(); + class LIBICTRANSLATE_API CFormat + { + public: + CFormat(); + explicit CFormat(const wchar_t* pszFormat); + ~CFormat(); - void SetFormat(const wchar_t* pszFormat); + void SetFormat(const wchar_t* pszFormat); - CFormat& SetParam(PCTSTR pszName, PCTSTR pszText); - CFormat& SetParam(PCTSTR pszName, unsigned long long ullData); - CFormat& SetParam(PCTSTR pszName, long long llData); - CFormat& SetParam(PCTSTR pszName, unsigned long ulData); - CFormat& SetParam(PCTSTR pszName, unsigned int uiData); - CFormat& SetParam(PCTSTR pszName, int iData); - CFormat& SetParam(PCTSTR pszName, bool bData); + CFormat& SetParam(PCTSTR pszName, PCTSTR pszText); + CFormat& SetParam(PCTSTR pszName, unsigned long long ullData); + CFormat& SetParam(PCTSTR pszName, long long llData); + CFormat& SetParam(PCTSTR pszName, unsigned long ulData); + CFormat& SetParam(PCTSTR pszName, unsigned int uiData); + CFormat& SetParam(PCTSTR pszName, int iData); + CFormat& SetParam(PCTSTR pszName, bool bData); - operator const wchar_t*() const { return m_strText.c_str(); } + operator const wchar_t*() const + { + return m_strText.c_str(); + } -protected: - std::wstring m_strText; -}; + protected: + std::wstring m_strText; + }; -/////////////////////////////////////////////////////////// -// language description structure -class LIBICTRANSLATE_API CTranslationItem -{ -public: - enum ECompareResult + /////////////////////////////////////////////////////////// + // language description structure + class LIBICTRANSLATE_API CTranslationItem { - eResult_Valid, // valid translation - eResult_Invalid, // Invalid checksum or translation - eResult_ContentWarning // the translation is suspicious - }; -public: - CTranslationItem(); - CTranslationItem(const CTranslationItem& rSrc); - CTranslationItem(const wchar_t* pszText, unsigned int uiChecksum); - ~CTranslationItem(); + public: + enum ECompareResult + { + eResult_Valid, // valid translation + eResult_Invalid, // Invalid checksum or translation + eResult_ContentWarning // the translation is suspicious + }; + public: + CTranslationItem(); + CTranslationItem(const CTranslationItem& rSrc); + CTranslationItem(const wchar_t* pszText, unsigned int uiChecksum); + ~CTranslationItem(); - CTranslationItem& operator=(const CTranslationItem& rSrc); + CTranslationItem& operator=(const CTranslationItem& rSrc); - void Clear(); + void Clear(); - const wchar_t* GetText() const; - void SetText(const wchar_t* pszText, bool bUnescapeString); - unsigned int GetChecksum() const { return m_uiChecksum; } - void SetChecksum(unsigned int uiChecksum) { m_uiChecksum = uiChecksum; } + const wchar_t* GetText() const; + void SetText(const wchar_t* pszText, bool bUnescapeString); + unsigned int GetChecksum() const + { + return m_uiChecksum; + } + void SetChecksum(unsigned int uiChecksum) + { + m_uiChecksum = uiChecksum; + } - void UnescapeString(); + void UnescapeString(); - ECompareResult Compare(const CTranslationItem& rReferenceItem); + ECompareResult Compare(const CTranslationItem& rReferenceItem); -protected: - bool GetFormatStrings(std::set& setFmtStrings) const; + protected: + bool GetFormatStrings(std::set& setFmtStrings) const; -protected: - wchar_t* m_pszText = nullptr; - size_t m_stTextLength = 0; - unsigned int m_uiChecksum = 0; -}; + protected: + wchar_t* m_pszText = nullptr; + size_t m_stTextLength = 0; + unsigned int m_uiChecksum = 0; + }; -typedef void(*PFNENUMCALLBACK)(unsigned int, const CTranslationItem*, void*); -typedef std::map translation_map; + typedef void(*PFNENUMCALLBACK)(unsigned int, const CTranslationItem*, void*); + typedef std::map translation_map; -class LIBICTRANSLATE_API CLangData -{ -public: -// construction/destruction - CLangData(); - CLangData(const CLangData& ld); - ~CLangData(); + class LIBICTRANSLATE_API CLangData + { + public: + // construction/destruction + CLangData(); + CLangData(const CLangData& ld); + ~CLangData(); - CLangData& operator=(const CLangData& rSrc); + CLangData& operator=(const CLangData& rSrc); - void Clear(); -// operations - bool ReadInfo(PCTSTR pszFile); - bool ReadTranslation(PCTSTR pszFile, bool bReadBase = false, bool bIgnoreVersion = false); - void WriteTranslation(PCTSTR pszPath); + void Clear(); + // operations + bool ReadInfo(PCTSTR pszFile); + bool ReadTranslation(PCTSTR pszFile, bool bReadBase = false, bool bIgnoreVersion = false); + void WriteTranslation(PCTSTR pszPath); -// translation retrieving/setting - const wchar_t* GetString(WORD wHiID, WORD wLoID); // retrieves string using group id and string id - void EnumStrings(PFNENUMCALLBACK pfnCallback, void* pData); // retrieves all translation items + // translation retrieving/setting + const wchar_t* GetString(WORD wHiID, WORD wLoID); // retrieves string using group id and string id + void EnumStrings(PFNENUMCALLBACK pfnCallback, void* pData); // retrieves all translation items - CTranslationItem* GetTranslationItem(unsigned int uiTranslationKey, bool bCreate); // retrieves pointer to the single translation item - bool Exists(unsigned int uiTranslationKey) const; - void CleanupTranslation(const CLangData& rReferenceTranslation); + CTranslationItem* GetTranslationItem(unsigned int uiTranslationKey, bool bCreate); // retrieves pointer to the single translation item + bool Exists(unsigned int uiTranslationKey) const; + void CleanupTranslation(const CLangData& rReferenceTranslation); -// attributes - void SetFilename(PCTSTR psz); - PCTSTR GetFilename(bool bFullPath) const; + // attributes + void SetFilename(PCTSTR psz); + PCTSTR GetFilename(bool bFullPath) const; - void SetLangName(PCTSTR psz); - PCTSTR GetLangName() const { return m_pszLngName; }; + void SetLangName(PCTSTR psz); + PCTSTR GetLangName() const + { + return m_pszLngName; + }; - void SetFontFace(PCTSTR psz); - PCTSTR GetFontFace() const { return m_pszFontFace; }; + void SetFontFace(PCTSTR psz); + PCTSTR GetFontFace() const + { + return m_pszFontFace; + }; - void SetPointSize(WORD wSize) { m_wPointSize=wSize; m_bModified = true; }; - WORD GetPointSize() const { return m_wPointSize; }; + void SetPointSize(WORD wSize) + { + m_wPointSize = wSize; m_bModified = true; + }; + WORD GetPointSize() const + { + return m_wPointSize; + }; - void SetDirection(bool brtl) { m_bRTL=brtl; m_bModified = true; }; - bool GetDirection() const { return m_bRTL; }; + void SetDirection(bool brtl) + { + m_bRTL = brtl; m_bModified = true; + }; + bool GetDirection() const + { + return m_bRTL; + }; - void SetHelpName(PCTSTR psz); - PCTSTR GetHelpName() const { return m_pszHelpName; }; + void SetHelpName(PCTSTR psz); + PCTSTR GetHelpName() const + { + return m_pszHelpName; + }; - void SetAuthor(PCTSTR psz); - PCTSTR GetAuthor() const { return m_pszAuthor; }; + void SetAuthor(PCTSTR psz); + PCTSTR GetAuthor() const + { + return m_pszAuthor; + }; - bool IsModified() const { return m_bModified; } - void SetModified() { m_bModified = true; } + bool IsModified() const + { + return m_bModified; + } + void SetModified() + { + m_bModified = true; + } - bool IsValidDescription() const; + bool IsValidDescription() const; -protected: - void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); - static void EnumAttributesCallback(bool bGroup, const wchar_t* pszName, const wchar_t* pszValue, void* pData); - static void UnescapeString(wchar_t* pszData); + protected: + void SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc); + static void EnumAttributesCallback(bool bGroup, const wchar_t* pszName, const wchar_t* pszValue, void* pData); + static void UnescapeString(wchar_t* pszData); -protected: - TCHAR *m_pszFilename; // file name of the language data (with path) - TCHAR *m_pszLngName; // name of the language (ie. Chinese (PRC)) - TCHAR *m_pszFontFace; // face name of the font that will be used in dialogs - WORD m_wPointSize; // font point size - TCHAR *m_pszHelpName; // help name (wo the directory) for this language - TCHAR *m_pszAuthor; // author name - bool m_bRTL; // does the language require right-to-left reading order ? + protected: + TCHAR *m_pszFilename; // file name of the language data (with path) + TCHAR *m_pszLngName; // name of the language (ie. Chinese (PRC)) + TCHAR *m_pszFontFace; // face name of the font that will be used in dialogs + WORD m_wPointSize; // font point size + TCHAR *m_pszHelpName; // help name (wo the directory) for this language + TCHAR *m_pszAuthor; // author name + bool m_bRTL; // does the language require right-to-left reading order ? - // strings (for controls in dialog boxes the ID contains hi:dlg ID, lo:ctrl ID, for strings hi part is 0) - translation_map m_mapTranslation; // maps string ID to the offset in pszStrings + // strings (for controls in dialog boxes the ID contains hi:dlg ID, lo:ctrl ID, for strings hi part is 0) + translation_map m_mapTranslation; // maps string ID to the offset in pszStrings -private: - unsigned int m_uiSectionID; ///< ID of the currently processed section - bool m_bUpdating; ///< Are we updating the language with base language ? - bool m_bModified; ///< States if the translation has been modified -}; + private: + unsigned int m_uiSectionID; ///< ID of the currently processed section + bool m_bUpdating; ///< Are we updating the language with base language ? + bool m_bModified; ///< States if the translation has been modified + }; -///////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////// -class LIBICTRANSLATE_API CResourceManager -{ -protected: - CResourceManager(); - ~CResourceManager(); + class LIBICTRANSLATE_API CResourceManager + { + protected: + CResourceManager(); + ~CResourceManager(); -public: - static CResourceManager& Acquire(); + public: + static CResourceManager& Acquire(); - void Init(HMODULE hrc); + void Init(HMODULE hrc); - void SetCallback(PFNNOTIFYCALLBACK pfn) { m_pfnCallback=pfn; }; + void SetCallback(PFNNOTIFYCALLBACK pfn) + { + m_pfnCallback = pfn; + }; - void Scan(LPCTSTR pszFolder, vector* pvData); - bool SetLanguage(PCTSTR pszPath); + void Scan(LPCTSTR pszFolder, std::vector* pvData); + bool SetLanguage(PCTSTR pszPath); - // loading functions - HGLOBAL LoadResource(LPCTSTR pszType, LPCTSTR pszName); - HACCEL LoadAccelerators(LPCTSTR pszName); - HBITMAP LoadBitmap(LPCTSTR pszName); - HCURSOR LoadCursor(LPCTSTR pszName); - HICON LoadIcon(LPCTSTR pszName); - HANDLE LoadImage(LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad); - HMENU LoadMenu(LPCTSTR pszName); - LPDLGTEMPLATE LoadDialog(LPCTSTR pszName); + // loading functions + HGLOBAL LoadResource(LPCTSTR pszType, LPCTSTR pszName); + HACCEL LoadAccelerators(LPCTSTR pszName); + HBITMAP LoadBitmap(LPCTSTR pszName); + HCURSOR LoadCursor(LPCTSTR pszName); + HICON LoadIcon(LPCTSTR pszName); + HANDLE LoadImage(LPCTSTR lpszName, UINT uType, int cxDesired, int cyDesired, UINT fuLoad); + HMENU LoadMenu(LPCTSTR pszName); + LPDLGTEMPLATE LoadDialog(LPCTSTR pszName); - PCTSTR LoadString(UINT uiID); - PCTSTR LoadString(WORD wGroup, WORD wID); + PCTSTR LoadString(UINT uiID); + PCTSTR LoadString(WORD wGroup, WORD wID); - // res updating functions - void UpdateMenu(HMENU hMenu, WORD wMenuID); + // res updating functions + void UpdateMenu(HMENU hMenu, WORD wMenuID); - const CLangData* GetLanguageData() const { return &m_ld; } + const CLangData* GetLanguageData() const + { + return &m_ld; + } -public: - CLangData m_ld; // current language data - list m_lhDialogs; // currently displayed dialog boxes (even hidden) + public: + CLangData m_ld; // current language data + std::list m_lhDialogs; // currently displayed dialog boxes (even hidden) - HMODULE m_hRes; - PFNNOTIFYCALLBACK m_pfnCallback; - CRITICAL_SECTION m_cs; + HMODULE m_hRes; + PFNNOTIFYCALLBACK m_pfnCallback; + CRITICAL_SECTION m_cs; -protected: - static CResourceManager S_ResourceManager; -}; + protected: + static CResourceManager S_ResourceManager; + }; +} -END_ICTRANSLATE_NAMESPACE - -#endif \ No newline at end of file +#endif