diff --git a/PowerEditor/installer/nppSetup.nsi b/PowerEditor/installer/nppSetup.nsi index 8068f0739..4380b91d2 100644 --- a/PowerEditor/installer/nppSetup.nsi +++ b/PowerEditor/installer/nppSetup.nsi @@ -497,6 +497,14 @@ commun: CreateDirectory "$SMPROGRAMS\Notepad++" CreateShortCut "$SMPROGRAMS\Notepad++\Uninstall.lnk" "$INSTDIR\uninstall.exe" + + ;clean + Delete "$INSTDIR\plugins\NPPTextFX\AsciiToEBCDIC.bin" + Delete "$INSTDIR\plugins\NPPTextFX\libTidy.dll" + Delete "$INSTDIR\plugins\NPPTextFX\W3C-CSSValidator.htm" + Delete "$INSTDIR\plugins\NPPTextFX\W3C-HTMLValidator.htm" + RMDir "$INSTDIR\plugins\NPPTextFX\" + ; remove unstable plugins IfFileExists "$INSTDIR\plugins\HexEditorPlugin.dll" 0 +3 MessageBox MB_OK "Due to the problem of compability with this version,$\nHexEditorPlugin.dll is about to be deleted." @@ -656,11 +664,11 @@ SubSection "Plugins" Plugins SetOutPath "$INSTDIR\plugins" File "..\bin\plugins\NPPTextFX.dll" - SetOutPath "$INSTDIR\plugins\NPPTextFX" - File "..\bin\plugins\NPPTextFX\AsciiToEBCDIC.bin" - File "..\bin\plugins\NPPTextFX\libTidy.dll" - File "..\bin\plugins\NPPTextFX\W3C-CSSValidator.htm" - File "..\bin\plugins\NPPTextFX\W3C-HTMLValidator.htm" + SetOutPath "$INSTDIR\plugins\Config\tidy" + File "..\bin\plugins\Config\tidy\AsciiToEBCDIC.bin" + File "..\bin\plugins\Config\tidy\libTidy.dll" + File "..\bin\plugins\Config\tidy\W3C-CSSValidator.htm" + File "..\bin\plugins\Config\tidy\W3C-HTMLValidator.htm" SetOutPath "$INSTDIR\plugins\doc" File "..\bin\plugins\doc\NPPTextFXdemo.TXT" @@ -883,12 +891,12 @@ SubSection un.Plugins Delete "$INSTDIR\plugins\NPPTextFX.dll" Delete "$INSTDIR\plugins\NPPTextFX.ini" Delete "$APPDATA\Notepad++\NPPTextFX.ini" - Delete "$INSTDIR\plugins\NPPTextFX\AsciiToEBCDIC.bin" - Delete "$INSTDIR\plugins\NPPTextFX\libTidy.dll" Delete "$INSTDIR\plugins\doc\NPPTextFXdemo.TXT" - Delete "$INSTDIR\plugins\NPPTextFX\W3C-CSSValidator.htm" - Delete "$INSTDIR\plugins\NPPTextFX\W3C-HTMLValidator.htm" - RMDir "$INSTDIR\plugins\NPPTextFX\" + Delete "$INSTDIR\plugins\Config\tidy\AsciiToEBCDIC.bin" + Delete "$INSTDIR\plugins\Config\tidy\libTidy.dll" + Delete "$INSTDIR\plugins\Config\tidy\W3C-CSSValidator.htm" + Delete "$INSTDIR\plugins\Config\tidy\W3C-HTMLValidator.htm" + RMDir "$INSTDIR\plugins\tidy\" RMDir "$INSTDIR\plugins\" SectionEnd diff --git a/PowerEditor/installer/packageAll.bat b/PowerEditor/installer/packageAll.bat index 17b3b0ed8..9b98865be 100644 --- a/PowerEditor/installer/packageAll.bat +++ b/PowerEditor/installer/packageAll.bat @@ -16,7 +16,7 @@ copy /Y SciLexer.dll .\zipped.package.release\unicode\ copy /Y ".\plugins\*.*" .\zipped.package.release\unicode\plugins\ copy /Y ".\plugins\APIs\*.xml" .\zipped.package.release\unicode\plugins\APIs copy /Y ".\plugins\doc\*.*" .\zipped.package.release\unicode\plugins\doc -copy /Y ".\plugins\NPPTextFX\*.*" .\zipped.package.release\unicode\plugins\NPPTextFX +copy /Y ".\plugins\Config\tidy\*.*" .\zipped.package.release\unicode\plugins\Config\tidy del /F /S /Q .\zipped.package.release\ansi\config.xml @@ -34,6 +34,7 @@ copy /Y contextMenu.xml .\zipped.package.release\ansi\ copy /Y shortcuts.xml .\zipped.package.release\ansi\ copy /Y doLocalConf.xml .\zipped.package.release\ansi\ copy /Y LINEDRAW.TTF .\zipped.package.release\ansi\ +copy /Y ".\plugins\Config\tidy\*.*" .\zipped.package.release\ansi\plugins\Config\tidy "C:\Program Files\7-Zip\7z.exe" a -tzip -r npp.bin.zip .\zipped.package.release\* "C:\Program Files\NSIS\makensis.exe" ..\installer\nppSetup.nsi diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 29b1b8a98..e01672008 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -147,45 +147,45 @@ int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) return EXCEPTION_CONTINUE_SEARCH; } -int getCpFromStringValue(const TCHAR * encodingStr) +int getCpFromStringValue(const char * encodingStr) { if (!encodingStr) return CP_ACP; - if (generic_stricmp(TEXT("windows-1250"), encodingStr) == 0) + if (stricmp("windows-1250", encodingStr) == 0) return 1250; - if (generic_stricmp(TEXT("windows-1251"), encodingStr) == 0) + if (stricmp("windows-1251", encodingStr) == 0) return 1251; - if (generic_stricmp(TEXT("windows-1252"), encodingStr) == 0) + if (stricmp("windows-1252", encodingStr) == 0) return 1252; - if (generic_stricmp(TEXT("windows-1253"), encodingStr) == 0) + if (stricmp("windows-1253", encodingStr) == 0) return 1253; - if (generic_stricmp(TEXT("windows-1254"), encodingStr) == 0) + if (stricmp("windows-1254", encodingStr) == 0) return 1254; - if (generic_stricmp(TEXT("windows-1255"), encodingStr) == 0) + if (stricmp("windows-1255", encodingStr) == 0) return 1255; - if (generic_stricmp(TEXT("windows-1256"), encodingStr) == 0) + if (stricmp("windows-1256", encodingStr) == 0) return 1256; - if (generic_stricmp(TEXT("windows-1257"), encodingStr) == 0) + if (stricmp("windows-1257", encodingStr) == 0) return 1257; - if (generic_stricmp(TEXT("windows-1258"), encodingStr) == 0) + if (stricmp("windows-1258", encodingStr) == 0) return 1258; - if (generic_stricmp(TEXT("big5"), encodingStr) == 0) + if (stricmp("big5", encodingStr) == 0) return 950; - if (generic_stricmp(TEXT("gb2312"), encodingStr) == 0) + if (stricmp("gb2312", encodingStr) == 0) return 936; - if (generic_stricmp(TEXT("shift_jis"), encodingStr) == 0) + if (stricmp("shift_jis", encodingStr) == 0) return 932; - if (generic_stricmp(TEXT("euc-kr"), encodingStr) == 0) + if (stricmp("euc-kr", encodingStr) == 0) return 51949; - if (generic_stricmp(TEXT("tis-620"), encodingStr) == 0) + if (stricmp("tis-620", encodingStr) == 0) return 874; - if (generic_stricmp(TEXT("iso-8859-8"), encodingStr) == 0) + if (stricmp("iso-8859-8", encodingStr) == 0) return 28598; - if (generic_stricmp(TEXT("utf-8"), encodingStr) == 0) + if (stricmp("utf-8", encodingStr) == 0) return 65001; return CP_ACP; diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h index 1f5894f74..9cf0fc279 100644 --- a/PowerEditor/src/MISC/Common/Common.h +++ b/PowerEditor/src/MISC/Common/Common.h @@ -90,7 +90,7 @@ void printInt(int int2print); void printStr(const TCHAR *str2print); void writeLog(const TCHAR *logFileName, const TCHAR *log2write); int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); -int getCpFromStringValue(const TCHAR * encodingStr); +int getCpFromStringValue(const char * encodingStr); std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false); void ClientRectToScreenRect(HWND hWnd, RECT* rect); diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 7e30a892f..f7296f0e1 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -76,34 +76,36 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p { ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); - _winVersion = (NppParameters::getInstance())->getWinVersion(); - TiXmlDocument *nativeLangDocRoot = (NppParameters::getInstance())->getNativeLang(); - if (nativeLangDocRoot) + + TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance())->getNativeLangA(); + + if (nativeLangDocRootA) { - _nativeLang = nativeLangDocRoot->FirstChild(TEXT("NotepadPlus")); - if (_nativeLang) + + _nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus"); + if (_nativeLangA) { - _nativeLang = _nativeLang->FirstChild(TEXT("Native-Langue")); - if (_nativeLang) + _nativeLangA = _nativeLangA->FirstChild("Native-Langue"); + if (_nativeLangA) { - TiXmlElement *element = _nativeLang->ToElement(); - const TCHAR *rtl = element->Attribute(TEXT("RTL")); + TiXmlElementA *element = _nativeLangA->ToElement(); + const char *rtl = element->Attribute("RTL"); if (rtl) - _isRTL = (lstrcmp(rtl, TEXT("yes")) == 0); + _isRTL = (strcmp(rtl, "yes") == 0); // get encoding - TiXmlDeclaration *declaration = _nativeLang->GetDocument()->FirstChild()->ToDeclaration(); + TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration(); if (declaration) { - const TCHAR * encodingStr = declaration->Encoding(); + const char * encodingStr = declaration->Encoding(); _nativeLangEncoding = getCpFromStringValue(encodingStr); } } } } else - _nativeLang = NULL; + _nativeLangA = NULL; TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance())->getToolIcons(); if (toolIconsDocRoot) @@ -1927,40 +1929,43 @@ BOOL Notepad_plus::notify(SCNotification *notification) TCHAR cloneToView[32] = TEXT("Clone to another View"); const TCHAR *pGoToView = goToView; const TCHAR *pCloneToView = cloneToView; + const char *goToViewA = NULL; + const char *cloneToViewA = NULL; + #ifdef UNICODE generic_string goToViewW = TEXT(""); generic_string cloneToViewW = TEXT(""); #endif - if (_nativeLang) + + if (_nativeLangA) { - TiXmlNode *tabBarMenu = _nativeLang->FirstChild(TEXT("Menu")); + TiXmlNodeA *tabBarMenu = _nativeLangA->FirstChild("Menu"); if (tabBarMenu) - tabBarMenu = tabBarMenu->FirstChild(TEXT("TabBar")); + tabBarMenu = tabBarMenu->FirstChild("TabBar"); if (tabBarMenu) { - for (TiXmlNode *childNode = tabBarMenu->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = tabBarMenu->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int ordre; - element->Attribute(TEXT("order"), &ordre); + element->Attribute("order", &ordre); if (ordre == 5) - pGoToView = element->Attribute(TEXT("name")); + goToViewA = element->Attribute("name"); else if (ordre == 6) - pCloneToView = element->Attribute(TEXT("name")); + cloneToViewA = element->Attribute("name"); } } #ifdef UNICODE WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - - const char *pGoToViewA = wmc->wchar2char(pGoToView, CP_ANSI_LATIN_1); - goToViewW = wmc->char2wchar(pGoToViewA, _nativeLangEncoding); + goToViewW = wmc->char2wchar(cloneToViewA, _nativeLangEncoding); + cloneToViewW = wmc->char2wchar(cloneToViewA, _nativeLangEncoding); pGoToView = goToViewW.c_str(); - - const char *pCloneToViewA = wmc->wchar2char(pCloneToView, CP_ANSI_LATIN_1); - cloneToViewW = wmc->char2wchar(pCloneToViewA, _nativeLangEncoding); pCloneToView = cloneToViewW.c_str(); +#else + pGoToView = goToViewA; + pCloneToView = cloneToViewA; #endif if (!pGoToView || !pGoToView[0]) pGoToView = goToView; @@ -2096,7 +2101,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) bool isFirstTime = !_goToLineDlg.isCreated(); _goToLineDlg.doDialog(_isRTL); if (isFirstTime) - changeDlgLang(_goToLineDlg.getHSelf(), TEXT("GoToLine")); + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); } } break; @@ -2121,216 +2126,153 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (!_tabPopupMenu.isCreated()) { - TCHAR close[32] = TEXT("Close me"); - TCHAR closeBut[32] = TEXT("Close all but me"); - TCHAR save[32] = TEXT("Save me"); - TCHAR saveAs[32] = TEXT("Save me As..."); - TCHAR print[32] = TEXT("Print me"); - TCHAR readOnly[32] = TEXT("Read only"); - TCHAR clearReadOnly[32] = TEXT("Clear read only flag"); - TCHAR goToNewInst[32] = TEXT("Go to new instance"); - TCHAR openInNewInst[32] = TEXT("Open in new instance"); - TCHAR goToView[32] = TEXT("Go to another View"); - TCHAR cloneToView[32] = TEXT("Clone to another View"); - TCHAR cilpFullPath[32] = TEXT("Full file path to Clipboard"); - TCHAR cilpFileName[32] = TEXT("File name to Clipboard"); - TCHAR cilpCurrentDir[32] = TEXT("Current dir path to Clipboard"); - TCHAR remove[32] = TEXT("Delete me"); - TCHAR rename[32] = TEXT("Rename me"); + const char close[32] = "Close me"; + const char closeBut[32] = "Close all but me"; + const char save[32] = "Save me"; + const char saveAs[32] = "Save me As..."; + const char print[32] = "Print me"; + const char readOnly[32] = "Read only"; + const char clearReadOnly[32] = "Clear read only flag"; + const char goToNewInst[32] = "Go to new instance"; + const char openInNewInst[32] = "Open in new instance"; + const char goToView[32] = "Go to another View"; + const char cloneToView[32] = "Clone to another View"; + const char cilpFullPath[32] = "Full file path to Clipboard"; + const char cilpFileName[32] = "File name to Clipboard"; + const char cilpCurrentDir[32] = "Current dir path to Clipboard"; + const char remove[32] = "Delete me"; + const char rename[32] = "Rename me"; - const TCHAR *pClose = close; - const TCHAR *pCloseBut = closeBut; - const TCHAR *pSave = save; - const TCHAR *pSaveAs = saveAs; - const TCHAR *pPrint = print; - const TCHAR *pReadOnly = readOnly; - const TCHAR *pClearReadOnly = clearReadOnly; - const TCHAR *pGoToView = goToView; - const TCHAR *pCloneToView = cloneToView; - const TCHAR *pGoToNewInst = goToNewInst; - const TCHAR *pOpenInNewInst = openInNewInst; - const TCHAR *pCilpFullPath = cilpFullPath; - const TCHAR *pCilpFileName = cilpFileName; - const TCHAR *pCilpCurrentDir = cilpCurrentDir; - const TCHAR *pRename = rename; - const TCHAR *pRemove = remove; -#ifdef UNICODE - basic_string goToViewW, cloneToViewW, goToNewInstW, openInNewInstW, closeW, closeButW, saveW, saveAsW, printW,\ - readOnlyW, clearReadOnlyW, cilpFullPathW, cilpFileNameW, cilpCurrentDirW, removeW, renameW; -#endif - if (_nativeLang) + const char *pClose = close; + const char *pCloseBut = closeBut; + const char *pSave = save; + const char *pSaveAs = saveAs; + const char *pPrint = print; + const char *pReadOnly = readOnly; + const char *pClearReadOnly = clearReadOnly; + const char *pGoToView = goToView; + const char *pCloneToView = cloneToView; + const char *pGoToNewInst = goToNewInst; + const char *pOpenInNewInst = openInNewInst; + const char *pCilpFullPath = cilpFullPath; + const char *pCilpFileName = cilpFileName; + const char *pCilpCurrentDir = cilpCurrentDir; + const char *pRename = rename; + const char *pRemove = remove; + + generic_string goToViewG, cloneToViewG, goToNewInstG, openInNewInstG, closeG, closeButG, saveG, saveAsG, printG,\ + readOnlyG, clearReadOnlyG, cilpFullPathG, cilpFileNameG, cilpCurrentDirG, removeG, renameG; + + if (_nativeLangA) { - TiXmlNode *tabBarMenu = _nativeLang->FirstChild(TEXT("Menu")); + TiXmlNodeA *tabBarMenu = _nativeLangA->FirstChild("Menu"); if (tabBarMenu) { - tabBarMenu = tabBarMenu->FirstChild(TEXT("TabBar")); + tabBarMenu = tabBarMenu->FirstChild("TabBar"); if (tabBarMenu) { - for (TiXmlNode *childNode = tabBarMenu->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = tabBarMenu->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int ordre; - element->Attribute(TEXT("order"), &ordre); + element->Attribute("order", &ordre); switch (ordre) { case 0 : - pClose = element->Attribute(TEXT("name")); break; + pClose = element->Attribute("name"); break; case 1 : - pCloseBut = element->Attribute(TEXT("name")); break; + pCloseBut = element->Attribute("name"); break; case 2 : - pSave = element->Attribute(TEXT("name")); break; + pSave = element->Attribute("name"); break; case 3 : - pSaveAs = element->Attribute(TEXT("name")); break; + pSaveAs = element->Attribute("name"); break; case 4 : - pPrint = element->Attribute(TEXT("name")); break; + pPrint = element->Attribute("name"); break; case 5 : - pGoToView = element->Attribute(TEXT("name")); break; + pGoToView = element->Attribute("name"); break; case 6 : - pCloneToView = element->Attribute(TEXT("name")); break; + pCloneToView = element->Attribute("name"); break; case 7 : - pCilpFullPath = element->Attribute(TEXT("name")); break; + pCilpFullPath = element->Attribute("name"); break; case 8 : - pCilpFileName = element->Attribute(TEXT("name")); break; + pCilpFileName = element->Attribute("name"); break; case 9 : - pCilpCurrentDir = element->Attribute(TEXT("name")); break; + pCilpCurrentDir = element->Attribute("name"); break; case 10 : - pRename = element->Attribute(TEXT("name")); break; + pRename = element->Attribute("name"); break; case 11 : - pRemove = element->Attribute(TEXT("name")); break; + pRemove = element->Attribute("name"); break; case 12 : - pReadOnly = element->Attribute(TEXT("name")); break; + pReadOnly = element->Attribute("name"); break; case 13 : - pClearReadOnly = element->Attribute(TEXT("name")); break; + pClearReadOnly = element->Attribute("name"); break; case 14 : - pGoToNewInst = element->Attribute(TEXT("name")); break; + pGoToNewInst = element->Attribute("name"); break; case 15 : - pOpenInNewInst = element->Attribute(TEXT("name")); break; + pOpenInNewInst = element->Attribute("name"); break; } } } } #ifdef UNICODE WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - - const char *pCharStrA = wmc->wchar2char(pGoToView, CP_ANSI_LATIN_1); - goToViewW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pGoToView = goToViewW.c_str(); - - pCharStrA = wmc->wchar2char(pCloneToView, CP_ANSI_LATIN_1); - cloneToViewW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pCloneToView = cloneToViewW.c_str(); - - pCharStrA = wmc->wchar2char(pGoToNewInst, CP_ANSI_LATIN_1); - goToNewInstW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pGoToNewInst = goToNewInstW.c_str(); - - pCharStrA = wmc->wchar2char(pOpenInNewInst, CP_ANSI_LATIN_1); - openInNewInstW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pOpenInNewInst = openInNewInstW.c_str(); - - pCharStrA = wmc->wchar2char(pClose, CP_ANSI_LATIN_1); - closeW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pClose = closeW.c_str(); - - pCharStrA = wmc->wchar2char(pCloseBut, CP_ANSI_LATIN_1); - closeButW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pCloseBut = closeButW.c_str(); - - pCharStrA = wmc->wchar2char(pSave, CP_ANSI_LATIN_1); - saveW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pSave = saveW.c_str(); - - pCharStrA = wmc->wchar2char(pSaveAs, CP_ANSI_LATIN_1); - saveAsW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pSaveAs = saveAsW.c_str(); - - pCharStrA = wmc->wchar2char(pPrint, CP_ANSI_LATIN_1); - printW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pPrint = printW.c_str(); - - pCharStrA = wmc->wchar2char(pReadOnly, CP_ANSI_LATIN_1); - readOnlyW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pReadOnly = readOnlyW.c_str(); - - pCharStrA = wmc->wchar2char(pClearReadOnly, CP_ANSI_LATIN_1); - clearReadOnlyW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pClearReadOnly = clearReadOnlyW.c_str(); - - pCharStrA = wmc->wchar2char(pCilpFullPath, CP_ANSI_LATIN_1); - cilpFullPathW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pCilpFullPath = cilpFullPathW.c_str(); - - pCharStrA = wmc->wchar2char(pCilpFileName, CP_ANSI_LATIN_1); - cilpFileNameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pCilpFileName = cilpFileNameW.c_str(); - - pCharStrA = wmc->wchar2char(pCilpCurrentDir, CP_ANSI_LATIN_1); - cilpCurrentDirW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pCilpCurrentDir = cilpCurrentDirW.c_str(); - - pCharStrA = wmc->wchar2char(pRename, CP_ANSI_LATIN_1); - removeW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pRename = removeW.c_str(); - - pCharStrA = wmc->wchar2char(pRemove, CP_ANSI_LATIN_1); - renameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); - pRemove = renameW.c_str(); + goToViewG = wmc->char2wchar(pGoToView, _nativeLangEncoding); + cloneToViewG = wmc->char2wchar(pCloneToView, _nativeLangEncoding); + goToNewInstG = wmc->char2wchar(pGoToNewInst, _nativeLangEncoding); + openInNewInstG = wmc->char2wchar(pOpenInNewInst, _nativeLangEncoding); + closeG = wmc->char2wchar(pClose, _nativeLangEncoding); + closeButG = wmc->char2wchar(pCloseBut, _nativeLangEncoding); + saveG = wmc->char2wchar(pSave, _nativeLangEncoding); + saveAsG = wmc->char2wchar(pSaveAs, _nativeLangEncoding); + printG = wmc->char2wchar(pPrint, _nativeLangEncoding); + readOnlyG = wmc->char2wchar(pReadOnly, _nativeLangEncoding); + clearReadOnlyG = wmc->char2wchar(pClearReadOnly, _nativeLangEncoding); + cilpFullPathG = wmc->char2wchar(pCilpFullPath, _nativeLangEncoding); + cilpFileNameG = wmc->char2wchar(pCilpFileName, _nativeLangEncoding); + cilpCurrentDirG = wmc->char2wchar(pCilpCurrentDir, _nativeLangEncoding); + removeG = wmc->char2wchar(pRename, _nativeLangEncoding); + renameG = wmc->char2wchar(pRemove, _nativeLangEncoding); +#else + goToViewG = pGoToView; + cloneToViewG = pCloneToView; + goToNewInstG = pGoToNewInst; + openInNewInstG = pOpenInNewInst; + closeG = pClose; + closeButG = pCloseBut; + saveG = pSave; + saveAsG = pSaveAs; + printG = pPrint; + readOnlyG = pReadOnly; + clearReadOnlyG = pClearReadOnly; + cilpFullPathG = pCilpFullPath; + cilpFileNameG = pCilpFileName; + cilpCurrentDirG = pCilpCurrentDir; + removeG = pRename; + renameG = pRemove; #endif - if (!pClose || !pClose[0]) - pClose = close; - if (!pCloseBut || !pCloseBut[0]) - pCloseBut = cloneToView; - if (!pSave || !pSave[0]) - pSave = save; - if (!pSaveAs || !pSaveAs[0]) - pSaveAs = saveAs; - if (!pPrint || !pPrint[0]) - pPrint = print; - if (!pGoToView || !pGoToView[0]) - pGoToView = goToView; - if (!pCloneToView || !pCloneToView[0]) - pCloneToView = cloneToView; - if (!pGoToNewInst || !pGoToNewInst[0]) - pGoToNewInst = goToNewInst; - if (!pOpenInNewInst || !pOpenInNewInst[0]) - pOpenInNewInst = openInNewInst; - if (!pCilpFullPath || !pCilpFullPath[0]) - pCilpFullPath = cilpFullPath; - if (!pCilpFileName || !pCilpFileName[0]) - pCilpFileName = cilpFileName; - if (!pCilpCurrentDir || !pCilpCurrentDir[0]) - pCilpCurrentDir = cilpCurrentDir; - if (!pRename || !pRename[0]) - pRename = rename; - if (!pRemove || !pRemove[0]) - pRemove = remove; - if (!pReadOnly || !pReadOnly[0]) - pReadOnly = readOnly; - if (!pClearReadOnly || !pClearReadOnly[0]) - pClearReadOnly = clearReadOnly; } vector itemUnitArray; - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, pClose)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, pCloseBut)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, pSave)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, pSaveAs)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, pRename)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_DELETE, pRemove)); - itemUnitArray.push_back(MenuItemUnit(IDM_FILE_PRINT, pPrint)); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, closeG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, closeButG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, saveG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, saveAsG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, renameG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_DELETE, removeG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_PRINT, printG.c_str())); itemUnitArray.push_back(MenuItemUnit(0, NULL)); - itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, pReadOnly)); - itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CLEARREADONLY, pClearReadOnly)); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, readOnlyG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CLEARREADONLY, clearReadOnlyG.c_str())); itemUnitArray.push_back(MenuItemUnit(0, NULL)); - itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, pCilpFullPath)); - itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, pCilpFileName)); - itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, pCilpCurrentDir)); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, cilpFullPathG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, cilpFileNameG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, cilpCurrentDirG.c_str())); itemUnitArray.push_back(MenuItemUnit(0, NULL)); - itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, pGoToView)); - itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, pCloneToView)); - itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, pGoToNewInst)); - itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, pOpenInNewInst)); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, goToViewG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, cloneToViewG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, goToNewInstG.c_str())); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, openInNewInstG.c_str())); _tabPopupMenu.create(_hSelf, itemUnitArray); @@ -3060,7 +3002,7 @@ void Notepad_plus::command(int id) if (isFirstTime) { - changeDlgLang(_runMacroDlg.getHSelf(), TEXT("MultiMacro")); + changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro"); } break; @@ -3100,34 +3042,30 @@ void Notepad_plus::command(int id) bool isFirstTime = !_findReplaceDlg.isCreated(); - if (_nativeLang) + if (_nativeLangA) { - TiXmlNode *dlgNode = _nativeLang->FirstChild(TEXT("Dialog")); + TiXmlNodeA *dlgNode = _nativeLangA->FirstChild("Dialog"); if (dlgNode) { - dlgNode = searchDlgNode(dlgNode, TEXT("Find")); + dlgNode = searchDlgNode(dlgNode, "Find"); if (dlgNode) { - const TCHAR *titre1 = (dlgNode->ToElement())->Attribute(TEXT("titleFind")); - const TCHAR *titre2 = (dlgNode->ToElement())->Attribute(TEXT("titleReplace")); - const TCHAR *titre3 = (dlgNode->ToElement())->Attribute(TEXT("titleFindInFiles")); + const char *titre1 = (dlgNode->ToElement())->Attribute("titleFind"); + const char *titre2 = (dlgNode->ToElement())->Attribute("titleReplace"); + const char *titre3 = (dlgNode->ToElement())->Attribute("titleFindInFiles"); if (titre1 && titre2 && titre3) { #ifdef UNICODE WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const char *pCharStrA = wmc->wchar2char(titre1, CP_ANSI_LATIN_1); - basic_string nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + basic_string nameW = wmc->char2wchar(titre1, _nativeLangEncoding); pNppParam->getFindDlgTabTitiles()._find = nameW; - pCharStrA = wmc->wchar2char(titre2, CP_ANSI_LATIN_1); - nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + nameW = wmc->char2wchar(titre2, _nativeLangEncoding); pNppParam->getFindDlgTabTitiles()._replace = nameW; - pCharStrA = wmc->wchar2char(titre3, CP_ANSI_LATIN_1); - nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + nameW = wmc->char2wchar(titre3, _nativeLangEncoding); pNppParam->getFindDlgTabTitiles()._findInFiles = nameW; - #else pNppParam->getFindDlgTabTitiles()._find = titre1; pNppParam->getFindDlgTabTitiles()._replace = titre2; @@ -3143,7 +3081,7 @@ void Notepad_plus::command(int id) _findReplaceDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit); if (isFirstTime) - changeDlgLang(_findReplaceDlg.getHSelf(), TEXT("Find")); + changeDlgLang(_findReplaceDlg.getHSelf(), "Find"); break; } @@ -3216,7 +3154,7 @@ void Notepad_plus::command(int id) bool isFirstTime = !_goToLineDlg.isCreated(); _goToLineDlg.doDialog(_isRTL); if (isFirstTime) - changeDlgLang(_goToLineDlg.getHSelf(), TEXT("GoToLine")); + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); break; } @@ -3225,7 +3163,7 @@ void Notepad_plus::command(int id) bool isFirstTime = !_colEditorDlg.isCreated(); _colEditorDlg.doDialog(_isRTL); if (isFirstTime) - changeDlgLang(_colEditorDlg.getHSelf(), TEXT("ColumnEditor")); + changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor"); break; } @@ -3740,7 +3678,7 @@ void Notepad_plus::command(int id) bool isFirstTime = !_runDlg.isCreated(); _runDlg.doDialog(_isRTL); if (isFirstTime) - changeDlgLang(_runDlg.getHSelf(), TEXT("Run")); + changeDlgLang(_runDlg.getHSelf(), "Run"); break; } @@ -4055,18 +3993,11 @@ void Notepad_plus::command(int id) { bool isFirstTime = !_aboutDlg.isCreated(); _aboutDlg.doDialog(); - if (isFirstTime && _nativeLang) + if (isFirstTime && _nativeLangA) { - const TCHAR *lang = (_nativeLang->ToElement())->Attribute(TEXT("name")); - const char * chineseString = "¤¤¤åÁcÅé"; - const TCHAR * chineseStringT; -#ifdef UNICODE - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - chineseStringT = wmc->char2wchar(chineseString, CP_ACP); //CP_ACP, CP_BIG5, which one to use? Depends on TinyXML conversion routines -#else - chineseStringT = chineseString; -#endif - if (lang && !lstrcmp(lang, chineseStringT)) + const char *lang = (_nativeLangA->ToElement())->Attribute("name"); + + if (_nativeLangEncoding == CP_BIG5) { char *authorName = "«J¤µ§^"; HWND hItem = ::GetDlgItem(_aboutDlg.getHSelf(), IDC_AUTHOR_NAME); @@ -4264,12 +4195,12 @@ void Notepad_plus::command(int id) WindowsDlg _windowsDlg; _windowsDlg.init(_hInst, _hSelf, _pDocTab); - TiXmlNode *dlgNode = NULL; - if (_nativeLang) + TiXmlNodeA *dlgNode = NULL; + if (_nativeLangA) { - dlgNode = _nativeLang->FirstChild(TEXT("Dialog")); + dlgNode = _nativeLangA->FirstChild("Dialog"); if (dlgNode) - dlgNode = searchDlgNode(dlgNode, TEXT("Window")); + dlgNode = searchDlgNode(dlgNode, "Window"); } _windowsDlg.doDialog(dlgNode); } @@ -4550,18 +4481,24 @@ void Notepad_plus::setTitle() Buffer * buf = _pEditView->getCurrentBuffer(); generic_string result = TEXT(""); - if (buf->isDirty()) { + if (buf->isDirty()) + { result += TEXT("*"); } - if (nppGUI._shortTitlebar) { + if (nppGUI._shortTitlebar) + { result += buf->getFileName(); - } else { + } + else + { result += buf->getFullPathName(); } result += TEXT(" - "); result += _className; - ::SetWindowText(_hSelf, result.c_str()); + //::SetWindowText(_hSelf, title); + ::SendMessage(_hSelf, WM_SETTEXT, 0, (LPARAM)result.c_str()); + } void Notepad_plus::activateNextDoc(bool direction) @@ -5150,6 +5087,107 @@ void Notepad_plus::showFunctionComp() { autoC->showFunctionComplete(); } +void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans) +{ + if (!_nativeLangA) return; + + TiXmlNodeA *mainMenu = _nativeLangA->FirstChild("Menu"); + if (!mainMenu) return; + + mainMenu = mainMenu->FirstChild("Main"); + if (!mainMenu) return; + + TiXmlNodeA *entriesRoot = mainMenu->FirstChild("Entries"); + if (!entriesRoot) return; + + const char *idName = NULL; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + if (element->Attribute("id", &id)) + { + const char *name = element->Attribute("name"); + +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, nameW); +#else + ::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, name); +#endif + } + else if (idName = element->Attribute("idName")) + { + const char *name = element->Attribute("name"); + if (!strcmp(idName, "Plugins")) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + pluginsTrans = nameW; +#else + pluginsTrans = name; +#endif + } + else if (!strcmp(idName, "Window")) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + windowTrans = nameW; +#else + windowTrans = name; +#endif + } + } + } + + TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands"); + for (TiXmlNodeA *childNode = menuCommandsRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + element->Attribute("id", &id); + const char *name = element->Attribute("name"); + +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, nameW); +#else + ::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, name); +#endif + } + + TiXmlNodeA *subEntriesRoot = mainMenu->FirstChild("SubEntries"); + + for (TiXmlNodeA *childNode = subEntriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int x, y; + element->Attribute("posX", &x); + element->Attribute("posY", &y); + const char *name = element->Attribute("name"); +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(::GetSubMenu(_mainMenuHandle, x), y, MF_BYPOSITION, 0, nameW); +#else + ::ModifyMenu(::GetSubMenu(_mainMenuHandle, x), y, MF_BYPOSITION, 0, name); +#endif + } + ::DrawMenuBar(_hSelf); +} + + +/* void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans) { if (!_nativeLang) return; @@ -5253,15 +5291,15 @@ void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string } ::DrawMenuBar(_hSelf); } - +*/ void Notepad_plus::changeConfigLang() { - if (!_nativeLang) return; + if (!_nativeLangA) return; - TiXmlNode *styleConfDlgNode = _nativeLang->FirstChild(TEXT("Dialog")); + TiXmlNodeA *styleConfDlgNode = _nativeLangA->FirstChild("Dialog"); if (!styleConfDlgNode) return; - styleConfDlgNode = styleConfDlgNode->FirstChild(TEXT("StyleConfig")); + styleConfDlgNode = styleConfDlgNode->FirstChild("StyleConfig"); if (!styleConfDlgNode) return; HWND hDlg = _configStyleDlg.getHSelf(); @@ -5271,34 +5309,32 @@ void Notepad_plus::changeConfigLang() #endif // Set Title - const TCHAR *titre = (styleConfDlgNode->ToElement())->Attribute(TEXT("title")); + const char *titre = (styleConfDlgNode->ToElement())->Attribute("title"); if ((titre && titre[0]) && hDlg) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); ::SetWindowText(hDlg, nameW); #else ::SetWindowText(hDlg, titre); #endif } - for (TiXmlNode *childNode = styleConfDlgNode->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = styleConfDlgNode->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { HWND hItem = ::GetDlgItem(hDlg, id); if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); @@ -5307,24 +5343,23 @@ void Notepad_plus::changeConfigLang() } } hDlg = _configStyleDlg.getHSelf(); - styleConfDlgNode = styleConfDlgNode->FirstChild(TEXT("SubDialog")); + styleConfDlgNode = styleConfDlgNode->FirstChild("SubDialog"); - for (TiXmlNode *childNode = styleConfDlgNode->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = styleConfDlgNode->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { HWND hItem = ::GetDlgItem(hDlg, id); if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); @@ -5334,7 +5369,8 @@ void Notepad_plus::changeConfigLang() } } -void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const TCHAR **translatedText) + +void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText) { const int iColorStyle = 0; const int iUnderline = 8; @@ -5349,8 +5385,7 @@ void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const TCHAR **t { #ifdef UNICODE WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const char *pCharStrA = wmc->wchar2char(translatedText[i], CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(translatedText[i], _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, translatedText[i]); @@ -5363,12 +5398,12 @@ void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const TCHAR **t void Notepad_plus::changeUserDefineLang() { - if (!_nativeLang) return; + if (!_nativeLangA) return; - TiXmlNode *userDefineDlgNode = _nativeLang->FirstChild(TEXT("Dialog")); + TiXmlNodeA *userDefineDlgNode = _nativeLangA->FirstChild("Dialog"); if (!userDefineDlgNode) return; - userDefineDlgNode = userDefineDlgNode->FirstChild(TEXT("UserDefine")); + userDefineDlgNode = userDefineDlgNode->FirstChild("UserDefine"); if (!userDefineDlgNode) return; UserDefineDialog *userDefineDlg = _pEditView->getUserDefineDlg(); @@ -5379,12 +5414,11 @@ void Notepad_plus::changeUserDefineLang() #endif // Set Title - const TCHAR *titre = (userDefineDlgNode->ToElement())->Attribute(TEXT("title")); + const char *titre = (userDefineDlgNode->ToElement())->Attribute("title"); if (titre && titre[0]) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); ::SetWindowText(hDlg, nameW); #else ::SetWindowText(hDlg, titre); @@ -5392,18 +5426,18 @@ void Notepad_plus::changeUserDefineLang() } // pour ses propres controls const int nbControl = 9; - const TCHAR *translatedText[nbControl]; + const char *translatedText[nbControl]; for (int i = 0 ; i < nbControl ; i++) translatedText[i] = NULL; - for (TiXmlNode *childNode = userDefineDlgNode->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = userDefineDlgNode->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { @@ -5413,8 +5447,7 @@ void Notepad_plus::changeUserDefineLang() if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); @@ -5470,7 +5503,7 @@ void Notepad_plus::changeUserDefineLang() }; int nbGpArray[nbDlg] = {nbGrpFolder, nbGrpKeywords, nbGrpComment, nbGrpOperator}; - const TCHAR nodeNameArray[nbDlg][16] = {TEXT("Folder"), TEXT("Keywords"), TEXT("Comment"), TEXT("Operator")}; + const char nodeNameArray[nbDlg][16] = {"Folder", "Keywords", "Comment", "Operator"}; for (int i = 0 ; i < nbDlg ; i++) { @@ -5485,38 +5518,36 @@ void Notepad_plus::changeUserDefineLang() case 3 : changeStyleCtrlsLang(hDlgArrary[i], operatorID[j], translatedText); break; } } - TiXmlNode *node = userDefineDlgNode->FirstChild(nodeNameArray[i]); + TiXmlNodeA *node = userDefineDlgNode->FirstChild(nodeNameArray[i]); if (node) { // Set Title - titre = (node->ToElement())->Attribute(TEXT("title")); + titre = (node->ToElement())->Attribute("title"); if (titre &&titre[0]) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); userDefineDlg->setTabName(i, nameW); #else userDefineDlg->setTabName(i, titre); #endif } - for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { HWND hItem = ::GetDlgItem(hDlgArrary[i], id); if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); @@ -5530,121 +5561,113 @@ void Notepad_plus::changeUserDefineLang() void Notepad_plus::changePrefereceDlgLang() { - changeDlgLang(_preference.getHSelf(), TEXT("Preference")); + changeDlgLang(_preference.getHSelf(), "Preference"); - TCHAR titre[64]; + char titre[128]; #ifdef UNICODE WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); #endif - changeDlgLang(_preference._barsDlg.getHSelf(), TEXT("Global"), titre); + changeDlgLang(_preference._barsDlg.getHSelf(), "Global", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("Global"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("Global"), titre); + _preference._ctrlTab.renameTab("Global", titre); #endif } - changeDlgLang(_preference._marginsDlg.getHSelf(), TEXT("Scintillas"), titre); + changeDlgLang(_preference._marginsDlg.getHSelf(), "Scintillas", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("Scintillas"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("Scintillas"), titre); + _preference._ctrlTab.renameTab("Scintillas", titre); #endif } - changeDlgLang(_preference._defaultNewDocDlg.getHSelf(), TEXT("NewDoc"), titre); + changeDlgLang(_preference._defaultNewDocDlg.getHSelf(), "NewDoc", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("NewDoc"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("NewDoc"), titre); + _preference._ctrlTab.renameTab("NewDoc", titre); #endif } - changeDlgLang(_preference._fileAssocDlg.getHSelf(), TEXT("FileAssoc"), titre); + + changeDlgLang(_preference._fileAssocDlg.getHSelf(), "FileAssoc", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("FileAssoc"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("FileAssoc"), titre); + _preference._ctrlTab.renameTab("FileAssoc", titre); #endif } - changeDlgLang(_preference._langMenuDlg.getHSelf(), TEXT("LangMenu"), titre); + changeDlgLang(_preference._langMenuDlg.getHSelf(), "LangMenu", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("LangMenu"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("LangMenu"), titre); + _preference._ctrlTab.renameTab("LangMenu", titre); #endif } - changeDlgLang(_preference._printSettingsDlg.getHSelf(), TEXT("Print1"), titre); + changeDlgLang(_preference._printSettingsDlg.getHSelf(), "Print1", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("Print1"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("Print1"), titre); + _preference._ctrlTab.renameTab("Print1", titre); #endif } - changeDlgLang(_preference._printSettings2Dlg.getHSelf(), TEXT("Print2"), titre); + changeDlgLang(_preference._printSettings2Dlg.getHSelf(), "Print2", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("Print2"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("Print2"), titre); + _preference._ctrlTab.renameTab("Print2", titre); #endif } - changeDlgLang(_preference._settingsDlg.getHSelf(), TEXT("MISC"), titre); + changeDlgLang(_preference._settingsDlg.getHSelf(), "MISC", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("MISC"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("MISC"), titre); + _preference._ctrlTab.renameTab("MISC", titre); #endif } - changeDlgLang(_preference._backupDlg.getHSelf(), TEXT("Backup"), titre); + changeDlgLang(_preference._backupDlg.getHSelf(), "Backup", titre); if (*titre) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); _preference._ctrlTab.renameTab(TEXT("Backup"), nameW); #else - _preference._ctrlTab.renameTab(TEXT("Backup"), titre); + _preference._ctrlTab.renameTab("Backup", titre); #endif } } void Notepad_plus::changeShortcutLang() { - if (!_nativeLang) return; + if (!_nativeLangA) return; NppParameters * pNppParam = NppParameters::getInstance(); vector & mainshortcuts = pNppParam->getUserShortcuts(); @@ -5652,55 +5675,68 @@ void Notepad_plus::changeShortcutLang() int mainSize = (int)mainshortcuts.size(); int scinSize = (int)scinshortcuts.size(); - TiXmlNode *shortcuts = _nativeLang->FirstChild(TEXT("Shortcuts")); + TiXmlNodeA *shortcuts = _nativeLangA->FirstChild("Shortcuts"); if (!shortcuts) return; - shortcuts = shortcuts->FirstChild(TEXT("Main")); + shortcuts = shortcuts->FirstChild("Main"); if (!shortcuts) return; - TiXmlNode *entriesRoot = shortcuts->FirstChild(TEXT("Entries")); + TiXmlNodeA *entriesRoot = shortcuts->FirstChild("Entries"); if (!entriesRoot) return; - for (TiXmlNode *childNode = entriesRoot->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int index, id; - if (element->Attribute(TEXT("index"), &index) && element->Attribute(TEXT("id"), &id)) + if (element->Attribute("index", &index) && element->Attribute("id", &id)) { if (index > -1 && index < mainSize) { //valid index only - const TCHAR *name = element->Attribute(TEXT("name")); + const char *name = element->Attribute("name"); CommandShortcut & csc = mainshortcuts[index]; - if (csc.getID() == id) { + if (csc.getID() == id) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + csc.setName(nameW); +#else csc.setName(name); +#endif } } } } //Scintilla - shortcuts = _nativeLang->FirstChild(TEXT("Shortcuts")); + shortcuts = _nativeLangA->FirstChild("Shortcuts"); if (!shortcuts) return; - shortcuts = shortcuts->FirstChild(TEXT("Scintilla")); + shortcuts = shortcuts->FirstChild("Scintilla"); if (!shortcuts) return; - entriesRoot = shortcuts->FirstChild(TEXT("Entries")); + entriesRoot = shortcuts->FirstChild("Entries"); if (!entriesRoot) return; - for (TiXmlNode *childNode = entriesRoot->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int index; - if (element->Attribute(TEXT("index"), &index)) + if (element->Attribute("index", &index)) { if (index > -1 && index < scinSize) { //valid index only - const TCHAR *name = element->Attribute(TEXT("name")); + const char *name = element->Attribute("name"); ScintillaKeyMap & skm = scinshortcuts[index]; +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + skm.setName(nameW); +#else skm.setName(name); +#endif } } } @@ -5709,36 +5745,44 @@ void Notepad_plus::changeShortcutLang() void Notepad_plus::changeShortcutmapperLang(ShortcutMapper * sm) { - if (!_nativeLang) return; + if (!_nativeLangA) return; - TiXmlNode *shortcuts = _nativeLang->FirstChild(TEXT("Dialog")); + TiXmlNodeA *shortcuts = _nativeLangA->FirstChild("Dialog"); if (!shortcuts) return; - shortcuts = shortcuts->FirstChild(TEXT("ShortcutMapper")); + shortcuts = shortcuts->FirstChild("ShortcutMapper"); if (!shortcuts) return; - for (TiXmlNode *childNode = shortcuts->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = shortcuts->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int index; - if (element->Attribute(TEXT("index"), &index)) + if (element->Attribute("index", &index)) { - if (index > -1 && index < 5) { //valid index only - const TCHAR *name = element->Attribute(TEXT("name")); + if (index > -1 && index < 5) //valid index only + { + const char *name = element->Attribute("name"); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + sm->translateTab(index, nameW); +#else sm->translateTab(index, name); +#endif } } } } -TiXmlNode * searchDlgNode(TiXmlNode *node, const TCHAR *dlgTagName) +TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName) { - TiXmlNode *dlgNode = node->FirstChild(dlgTagName); + TiXmlNodeA *dlgNode = node->FirstChild(dlgTagName); if (dlgNode) return dlgNode; - for (TiXmlNode *childNode = node->FirstChildElement(); + for (TiXmlNodeA *childNode = node->FirstChildElement(); childNode ; childNode = childNode->NextSibling() ) { @@ -5748,14 +5792,14 @@ TiXmlNode * searchDlgNode(TiXmlNode *node, const TCHAR *dlgTagName) return NULL; } -bool Notepad_plus::changeDlgLang(HWND hDlg, const TCHAR *dlgTagName, TCHAR *title) +bool Notepad_plus::changeDlgLang(HWND hDlg, const char *dlgTagName, char *title) { if (title) title[0] = '\0'; - if (!_nativeLang) return false; + if (!_nativeLangA) return false; - TiXmlNode *dlgNode = _nativeLang->FirstChild(TEXT("Dialog")); + TiXmlNodeA *dlgNode = _nativeLangA->FirstChild("Dialog"); if (!dlgNode) return false; dlgNode = searchDlgNode(dlgNode, dlgTagName); @@ -5766,37 +5810,35 @@ bool Notepad_plus::changeDlgLang(HWND hDlg, const TCHAR *dlgTagName, TCHAR *titl #endif // Set Title - const TCHAR *titre = (dlgNode->ToElement())->Attribute(TEXT("title")); + const char *titre = (dlgNode->ToElement())->Attribute("title"); if ((titre && titre[0]) && hDlg) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); ::SetWindowText(hDlg, nameW); #else ::SetWindowText(hDlg, titre); #endif if (title) - lstrcpy(title, titre); + strcpy(title, titre); } // Set the text of child control - for (TiXmlNode *childNode = dlgNode->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = dlgNode->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { HWND hItem = ::GetDlgItem(hDlg, id); if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, _nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); @@ -6746,7 +6788,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa _pEditView->getGenericSelectedText(str, strSize); _findReplaceDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit); if (isFirstTime) - changeDlgLang(_findReplaceDlg.getHSelf(), TEXT("Find")); + changeDlgLang(_findReplaceDlg.getHSelf(), "Find"); _findReplaceDlg.launchFindInFilesDlg(); const TCHAR *dir = NULL; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 47a5b791a..ccea2a78b 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -75,7 +75,7 @@ enum Views { */ struct TaskListInfo; -static TiXmlNode * searchDlgNode(TiXmlNode *node, const TCHAR *dlgTagName); +static TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); struct iconLocator { int listIndex; @@ -161,11 +161,13 @@ public: const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save); const TCHAR * fileSaveSession(size_t nbFile = 0, TCHAR ** fileNames = NULL); - bool changeDlgLang(HWND hDlg, const TCHAR *dlgTagName, TCHAR *title = NULL); + bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); void changeConfigLang(); void changeUserDefineLang(); void changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans); + //void changeMenuLangTmp(generic_string & pluginsTrans, generic_string & windowTrans); + void changePrefereceDlgLang(); void changeShortcutLang(); void changeShortcutmapperLang(ShortcutMapper * sm); @@ -201,7 +203,9 @@ private: SmartHighlighter _smartHighlighter; - TiXmlNode *_nativeLang, *_toolIcons; + TiXmlNode *_toolIcons; + TiXmlNodeA *_nativeLangA; + int _nativeLangEncoding; DocTabView _mainDocTab; @@ -676,7 +680,7 @@ private: void autoCompFromCurrentFile(bool autoInsert = true); void showFunctionComp(); - void changeStyleCtrlsLang(HWND hDlg, int *idArray, const TCHAR **translatedText); + void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); bool replaceAllFiles(); bool findInOpenedFiles(); diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index e8aaaeba3..169ff6c6b 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -418,7 +418,7 @@ winVer getWindowsVersion() NppParameters * NppParameters::_pSelf = new NppParameters; int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13; NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserStylerDoc(NULL),\ - _pXmlUserLangDoc(NULL), _pXmlNativeLangDoc(NULL),\ + _pXmlUserLangDoc(NULL), /*_pXmlNativeLangDoc(NULL), */_pXmlNativeLangDocA(NULL),\ _nbLang(0), _nbFile(0), _nbMaxFile(10), _pXmlToolIconsDoc(NULL),\ _pXmlShortcutDoc(NULL), _pXmlContextMenuDoc(NULL), _pXmlSessionDoc(NULL),\ _nbUserLang(0), _nbExternalLang(0), _hUser32(NULL), _hUXTheme(NULL),\ @@ -688,6 +688,7 @@ bool NppParameters::load() PathAppend(nativeLangPath, TEXT("nativeLang.xml")); } +/* _pXmlNativeLangDoc = new TiXmlDocument(nativeLangPath); loadOkay = _pXmlNativeLangDoc->LoadFile(); if (!loadOkay) @@ -695,8 +696,27 @@ bool NppParameters::load() delete _pXmlNativeLangDoc; _pXmlNativeLangDoc = NULL; isAllLaoded = false; - } - + } +*/ + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * nativeLangPathA = wmc->wchar2char(nativeLangPath, CP_ANSI_LATIN_1); + _pXmlNativeLangDocA = new TiXmlDocumentA(nativeLangPathA); +#else + _pXmlNativeLangDocA = new TiXmlDocumentA(nativeLangPath); +#endif + + loadOkay = _pXmlNativeLangDocA->LoadFile(); + if (!loadOkay) + { + delete _pXmlNativeLangDocA; + _pXmlNativeLangDocA = NULL; + isAllLaoded = false; + } + + + //---------------------------------// // toolbarIcons.xml : for per user // //---------------------------------// @@ -818,8 +838,8 @@ void NppParameters::destroyInstance() if (_pXmlUserLangDoc) delete _pXmlUserLangDoc; - if (_pXmlNativeLangDoc) - delete _pXmlNativeLangDoc; + if (_pXmlNativeLangDocA) + delete _pXmlNativeLangDocA; if (_pXmlToolIconsDoc) delete _pXmlToolIconsDoc; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 70e685377..2cd882525 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -19,7 +19,9 @@ #define PARAMETERS_H #include +#include "tinyxmlA.h" #include "tinyxml.h" + //#include "ScintillaEditView.h" #include "Scintilla.h" #include "ScintillaRef.h" @@ -996,8 +998,11 @@ public: }; int addExternalLangToEnd(ExternalLangContainer * externalLang); - - TiXmlDocument * getNativeLang() const {return _pXmlNativeLangDoc;}; + + //TiXmlDocument * getNativeLang() const {return _pXmlNativeLangDoc;}; + + TiXmlDocumentA * getNativeLangA() const {return _pXmlNativeLangDocA;}; + TiXmlDocument * getToolIcons() const {return _pXmlToolIconsDoc;}; bool isTransparentAvailable() const { @@ -1070,39 +1075,39 @@ public: FindDlgTabTitiles & getFindDlgTabTitiles() { return _findDlgTabTitiles;}; - const TCHAR * getNativeLangMenuString(int itemID) { - if (!_pXmlNativeLangDoc) + const char * getNativeLangMenuStringA(int itemID) { + if (!_pXmlNativeLangDocA) return NULL; - TiXmlNode * node = _pXmlNativeLangDoc->FirstChild(TEXT("NotepadPlus")); + TiXmlNodeA * node = _pXmlNativeLangDocA->FirstChild("NotepadPlus"); if (!node) return NULL; - node = node->FirstChild(TEXT("Native-Langue")); + node = node->FirstChild("Native-Langue"); if (!node) return NULL; - node = node->FirstChild(TEXT("Menu")); + node = node->FirstChild("Menu"); if (!node) return NULL; - node = node->FirstChild(TEXT("Main")); + node = node->FirstChild("Main"); if (!node) return NULL; - node = node->FirstChild(TEXT("Commands")); + node = node->FirstChild("Commands"); if (!node) return NULL; - for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - if (element->Attribute(TEXT("id"), &id) && (id == itemID)) + if (element->Attribute("id", &id) && (id == itemID)) { - return element->Attribute(TEXT("name")); + return element->Attribute("name"); } - } return NULL; }; + bool asNotepadStyle() const {return _asNotepadStyle;}; bool reloadPluginCmds() { @@ -1119,9 +1124,11 @@ private: static NppParameters *_pSelf; - TiXmlDocument *_pXmlDoc, *_pXmlUserDoc, *_pXmlUserStylerDoc, *_pXmlUserLangDoc, *_pXmlNativeLangDoc,\ + TiXmlDocument *_pXmlDoc, *_pXmlUserDoc, *_pXmlUserStylerDoc, *_pXmlUserLangDoc,\ *_pXmlToolIconsDoc, *_pXmlShortcutDoc, *_pXmlContextMenuDoc, *_pXmlSessionDoc; + TiXmlDocumentA *_pXmlNativeLangDocA; + vector _pXmlExternalLexerDoc; NppGUI _nppGUI; diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp new file mode 100644 index 000000000..ab4acdac7 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp @@ -0,0 +1,303 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + +#ifndef TIXMLA_USE_STL + + +#include +#include +#include + +#include "tinystrA.h" + +// TiXmlStringA constructor, based on a C string +TiXmlStringA::TiXmlStringA (const char* instring) +{ + unsigned newlen; + char * newstring; + + if (!instring) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = strlen (instring) + 1; + newstring = new char [newlen]; + memcpy (newstring, instring, newlen); + // strcpy (newstring, instring); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlStringA copy constructor +TiXmlStringA::TiXmlStringA (const TiXmlStringA& copy) +{ + unsigned newlen; + char * newstring; + + // Prevent copy to self! + if ( © == this ) + return; + + if (! copy . allocated) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . cstring); + memcpy (newstring, copy . cstring, newlen); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlStringA = operator. Safe when assign own content +void TiXmlStringA ::operator = (const char * content) +{ + unsigned newlen; + char * newstring; + + if (! content) + { + empty_it (); + return; + } + newlen = strlen (content) + 1; + newstring = new char [newlen]; + // strcpy (newstring, content); + memcpy (newstring, content, newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// = operator. Safe when assign own content +void TiXmlStringA ::operator = (const TiXmlStringA & copy) +{ + unsigned newlen; + char * newstring; + + if (! copy . length ()) + { + empty_it (); + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . c_str ()); + memcpy (newstring, copy . c_str (), newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + + +//// Checks if a TiXmlStringA contains only whitespace (same rules as isspace) +//bool TiXmlStringA::isblank () const +//{ +// char * lookup; +// for (lookup = cstring; * lookup; lookup++) +// if (! isspace (* lookup)) +// return false; +// return true; +//} + +// append a const char * to an existing TiXmlStringA +void TiXmlStringA::append( const char* str, int len ) +{ + char * new_string; + unsigned new_alloc, new_size, size_suffix; + + size_suffix = strlen (str); + if (len < (int) size_suffix) + size_suffix = len; + if (! size_suffix) + return; + + new_size = length () + size_suffix + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + // strcpy (new_string, cstring); + memcpy (new_string, cstring, length ()); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strncat (new_string, str, len); + memcpy (new_string + length (), + str, + size_suffix); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strncat (cstring, str, len); + memcpy (cstring + length (), + str, + size_suffix); + } + current_length = new_size - 1; + cstring [current_length] = 0; +} + + +// append a const char * to an existing TiXmlStringA +void TiXmlStringA::append( const char * suffix ) +{ + char * new_string; + unsigned new_alloc, new_size; + + new_size = length () + strlen (suffix) + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + memcpy (new_string, cstring, 1 + length ()); + // strcpy (new_string, cstring); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strcat (new_string, suffix); + memcpy (new_string + length (), + suffix, + strlen (suffix) + 1); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strcat (cstring, suffix); + memcpy (cstring + length (), + suffix, + strlen (suffix) + 1); + } + current_length = new_size - 1; +} + +// Check for TiXmlStringA equuivalence +//bool TiXmlStringA::operator == (const TiXmlStringA & compare) const +//{ +// return (! strcmp (c_str (), compare . c_str ())); +//} + +//unsigned TiXmlStringA::length () const +//{ +// if (allocated) +// // return strlen (cstring); +// return current_length; +// return 0; +//} + + +unsigned TiXmlStringA::find (char tofind, unsigned offset) const +{ + char * lookup; + + if (offset >= length ()) + return (unsigned) notfound; + for (lookup = cstring + offset; * lookup; lookup++) + if (* lookup == tofind) + return lookup - cstring; + return (unsigned) notfound; +} + + +bool TiXmlStringA::operator == (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) == 0 ); + } + return false; +} + + +bool TiXmlStringA::operator < (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) > 0 ); + } + return false; +} + + +bool TiXmlStringA::operator > (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) < 0 ); + } + return false; +} + + +#endif // TIXMLA_USE_STL diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h new file mode 100644 index 000000000..dca746e03 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h @@ -0,0 +1,236 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + + +#ifndef TIXMLA_USE_STL + +#ifndef _INCLUDED +#define TIXMLA_STRING_INCLUDED + +#pragma warning( disable : 4514 ) + +#include + +/* + TiXmlStringA is an emulation of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlStringA +{ + public : + // TiXmlStringA constructor, based on a string + TiXmlStringA (const char * instring); + + // TiXmlStringA empty constructor + TiXmlStringA () + { + allocated = 0; + cstring = NULL; + current_length = 0; + } + + // TiXmlStringA copy constructor + TiXmlStringA (const TiXmlStringA& copy); + + // TiXmlStringA destructor + ~ TiXmlStringA () + { + empty_it (); + } + + // Convert a TiXmlStringA into a classical char * + const char * c_str () const + { + if (allocated) + return cstring; + return ""; + } + + // Return the length of a TiXmlStringA + unsigned length () const + { + return ( allocated ) ? current_length : 0; + } + + // TiXmlStringA = operator + void operator = (const char * content); + + // = operator + void operator = (const TiXmlStringA & copy); + + // += operator. Maps to append + TiXmlStringA& operator += (const char * suffix) + { + append (suffix); + return *this; + } + + // += operator. Maps to append + TiXmlStringA& operator += (char single) + { + append (single); + return *this; + } + + // += operator. Maps to append + TiXmlStringA& operator += (TiXmlStringA & suffix) + { + append (suffix); + return *this; + } + bool operator == (const TiXmlStringA & compare) const; + bool operator < (const TiXmlStringA & compare) const; + bool operator > (const TiXmlStringA & compare) const; + + // Checks if a TiXmlStringA is empty + bool empty () const + { + return length () ? false : true; + } + + // Checks if a TiXmlStringA contains only whitespace (same rules as isspace) + // Not actually used in tinyxml. Conflicts with a C macro, "isblank", + // which is a problem. Commenting out. -lee +// bool isblank () const; + + // single char extraction + const char& at (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // find a char in a string. Return TiXmlStringA::notfound if not found + unsigned find (char lookup) const + { + return find (lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlStringA::notfound if not found + unsigned find (char tofind, unsigned offset) const; + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function clears the content of the TiXmlStringA if any exists. + */ + void reserve (unsigned size) + { + empty_it (); + if (size) + { + allocated = size; + TIXMLA_STRING cstring = new char [size]; + cstring [0] = 0; + current_length = 0; + } + } + + // [] operator + char& operator [] (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // Error value for find primitive + enum { notfound = 0xffffffff, + npos = notfound }; + + void append (const char *str, int len ); + + protected : + + // The base string + char * cstring; + // Number of chars allocated + unsigned allocated; + // Current string size + unsigned current_length; + + // New size computation. It is simplistic right now : it returns twice the amount + // we need + unsigned assign_new_size (unsigned minimum_to_allocate) + { + return minimum_to_allocate * 2; + } + + // Internal function that clears the content of a TiXmlStringA + void empty_it () + { + if (cstring) + delete [] cstring; + cstring = NULL; + allocated = 0; + current_length = 0; + } + + void append (const char *suffix ); + + // append function for another TiXmlStringA + void append (const TiXmlStringA & suffix) + { + append (suffix . c_str ()); + } + + // append for a single char. This could be improved a lot if needed + void append (char single) + { + char smallstr [2]; + smallstr [0] = single; + smallstr [1] = 0; + append (smallstr); + } + +} ; + +/* + TiXmlOutStreamA is an emulation of std::ostream. It is based on TiXmlStringA. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStreamA : public TiXmlStringA +{ +public : + TiXmlOutStreamA () : TiXmlStringA () {} + + // TiXmlOutStreamA << operator. Maps to TiXmlStringA::append + TiXmlOutStreamA & operator << (const char * in) + { + append (in); + return (* this); + } + + // TiXmlOutStreamA << operator. Maps to TiXmlStringA::append + TiXmlOutStreamA & operator << (const TiXmlStringA & in) + { + append (in . c_str ()); + return (* this); + } +} ; + +#endif // TIXMLA_STRING_INCLUDED +#endif // TIXMLA_USE_STL diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp new file mode 100644 index 000000000..7a7bde01c --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp @@ -0,0 +1,1258 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include +#include "tinyxmlA.h" + +#ifdef TIXMLA_USE_STL +#include +#endif + +bool TiXmlBaseA::condenseWhiteSpace = true; + +void TiXmlBaseA::PutString( const TIXMLA_STRING& str, TIXMLA_OSTREAM* stream ) +{ + TIXMLA_STRING buffer; + PutString( str, &buffer ); + (*stream) << buffer; +} + +void TiXmlBaseA::PutString( const TIXMLA_STRING& str, TIXMLA_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + int c = str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + while ( i<(int)str.length() ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 || c > 126 ) + { + // Easy pass at non-alpha/numeric/symbol + // 127 is the delete key. Below 32 is symbolic. + char buf[ 32 ]; + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + outString->append( buf, strlen( buf ) ); + ++i; + } + else + { + char realc = (char) c; + outString->append( &realc, 1 ); + ++i; + } + } +} + + +// <-- Strange class for a bug fix. Search for STL_STRING_BUG +TiXmlBaseA::StringToBuffer::StringToBuffer( const TIXMLA_STRING& str ) +{ + buffer = new char[ str.length()+1 ]; + if ( buffer ) + { + strcpy( buffer, str.c_str() ); + } +} + + +TiXmlBaseA::StringToBuffer::~StringToBuffer() +{ + delete [] buffer; +} +// End strange bug fix. --> + + +TiXmlNodeA::TiXmlNodeA( NodeType _type ) +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; + userData = 0; +} + + +TiXmlNodeA::~TiXmlNodeA() +{ + TiXmlNodeA* node = firstChild; + TiXmlNodeA* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNodeA::Clear() +{ + TiXmlNodeA* node = firstChild; + TiXmlNodeA* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNodeA* TiXmlNodeA::LinkEndChild( TiXmlNodeA* node ) +{ + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::InsertEndChild( const TiXmlNodeA& addThis ) +{ + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNodeA* TiXmlNodeA::InsertBeforeChild( TiXmlNodeA* beforeThis, const TiXmlNodeA& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) + return 0; + + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::InsertAfterChild( TiXmlNodeA* afterThis, const TiXmlNodeA& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) + return 0; + + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::ReplaceChild( TiXmlNodeA* replaceThis, const TiXmlNodeA& withThis ) +{ + if ( replaceThis->parent != this ) + return 0; + + TiXmlNodeA* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNodeA::RemoveChild( TiXmlNodeA* removeThis ) +{ + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +TiXmlNodeA* TiXmlNodeA::FirstChild( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = firstChild; node; node = node->next ) + { + if ( node->SValue() == TIXMLA_STRING( _value )) + return node; + } + return 0; +} + +TiXmlNodeA* TiXmlNodeA::LastChild( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + +TiXmlNodeA* TiXmlNodeA::IterateChildren( TiXmlNodeA* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + +TiXmlNodeA* TiXmlNodeA::IterateChildren( const char * val, TiXmlNodeA* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + +TiXmlNodeA* TiXmlNodeA::NextSibling( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = next; node; node = node->next ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + + +TiXmlNodeA* TiXmlNodeA::PreviousSibling( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = prev; node; node = node->prev ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + +void TiXmlElementA::RemoveAttribute( const char * name ) +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +TiXmlElementA* TiXmlNodeA::FirstChildElement() const +{ + TiXmlNodeA* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElementA* TiXmlNodeA::FirstChildElement( const char * _value ) const +{ + TiXmlNodeA* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +TiXmlElementA* TiXmlNodeA::NextSiblingElement() const +{ + TiXmlNodeA* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElementA* TiXmlNodeA::NextSiblingElement( const char * _value ) const +{ + TiXmlNodeA* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + + +TiXmlDocumentA* TiXmlNodeA::GetDocument() const +{ + const TiXmlNodeA* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElementA::TiXmlElementA (const char * _value) +: TiXmlNodeA( TiXmlNodeA::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + +TiXmlElementA::~TiXmlElementA() +{ + while( attributeSet.First() ) + { + TiXmlAttributeA* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + +const char * TiXmlElementA::Attribute( const char * name ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + + if ( node ) + return node->Value(); + + return 0; +} + + +const char * TiXmlElementA::Attribute( const char * name, int* i ) const +{ + const char * s = Attribute( name ); + if ( i ) + { + if ( s ) + *i = atoi( s ); + else + *i = 0; + } + return s; +} + + +const char * TiXmlElementA::Attribute( const char * name, double* d ) const +{ + const char * s = Attribute( name ); + if ( d ) + { + if ( s ) + *d = atof( s ); + else + *d = 0; + } + return s; +} + + +int TiXmlElementA::QueryIntAttribute( const char* name, int* ival ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( !node ) + return TIXMLA_NO_ATTRIBUTE; + + return node->QueryIntValue( ival ); +} + + +int TiXmlElementA::QueryDoubleAttribute( const char* name, double* dval ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( !node ) + return TIXMLA_NO_ATTRIBUTE; + + return node->QueryDoubleValue( dval ); +} + + +void TiXmlElementA::SetAttribute( const char * name, int val ) +{ + char buf[64]; + sprintf( buf, "%d", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElementA::SetAttribute( const char * name, const char * _value ) +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( node ) + { + node->SetValue( _value ); + return; + } + + TiXmlAttributeA* attrib = new TiXmlAttributeA( name, _value ); + if ( attrib ) + { + attributeSet.Add( attrib ); + } + else + { + TiXmlDocumentA* document = GetDocument(); + if ( document ) document->SetError( TIXMLA_ERROR_OUT_OF_MEMORY, 0, 0 ); + } +} + +void TiXmlElementA::Print( FILE* cfile, int depth ) const +{ + int i; + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNodeA* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + +void TiXmlElementA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << "<" << value; + + TiXmlAttributeA* attrib; + for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) + { + (*stream) << " "; + attrib->StreamOut( stream ); + } + + // If this node has children, give it a closing tag. Else + // make it an empty tag. + TiXmlNodeA* node; + if ( firstChild ) + { + (*stream) << ">"; + + for ( node = firstChild; node; node=node->NextSibling() ) + { + node->StreamOut( stream ); + } + (*stream) << ""; + } + else + { + (*stream) << " />"; + } +} + +TiXmlNodeA* TiXmlElementA::Clone() const +{ + TiXmlElementA* clone = new TiXmlElementA( Value() ); + if ( !clone ) + return 0; + + CopyToClone( clone ); + + // Clone the attributes, then clone the children. + TiXmlAttributeA* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + clone->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNodeA* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +TiXmlDocumentA::TiXmlDocumentA() : TiXmlNodeA( TiXmlNodeA::DOCUMENT ) +{ + tabsize = 4; + ClearError(); +} + +TiXmlDocumentA::TiXmlDocumentA( const char * documentName ) : TiXmlNodeA( TiXmlNodeA::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} + +bool TiXmlDocumentA::LoadFile() +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && LoadFile( buf.buffer ) ) + return true; + + return false; +} + + +bool TiXmlDocumentA::SaveFile() const +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && SaveFile( buf.buffer ) ) + return true; + + return false; +} + +bool TiXmlDocumentA::LoadFile( const char* filename ) +{ + // Delete the existing data: + Clear(); + location.Clear(); + + // There was a really terrifying little bug here. The code: + // value = filename + // in the STL case, cause the assignment method of the std::string to + // be called. What is strange, is that the std::string had the same + // address as it's c_str() method, and so bad things happen. Looks + // like a bug in the Microsoft STL implementation. + // See STL_STRING_BUG above. + // Fixed with the StringToBuffer class. + value = filename; + + FILE* file = fopen( value.c_str (), "r" ); + + if ( file ) + { + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length == 0 ) + { + fclose( file ); + return false; + } + + // If we have a file, assume it is all one big XML file, and read it in. + // The document parser may decide the document ends sooner than the entire file, however. + TIXMLA_STRING data; + data.reserve( length ); + + const int BUF_SIZE = 2048; + char buf[BUF_SIZE]; + + while( fgets( buf, BUF_SIZE, file ) ) + { + data += buf; + } + fclose( file ); + + Parse( data.c_str(), 0 ); + + if ( Error() ) + return false; + else + return true; + } + SetError( TIXMLA_ERROR_OPENING_FILE, 0, 0 ); + return false; +} + +bool TiXmlDocumentA::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = fopen( filename, "w" ); + if ( fp ) + { + Print( fp, 0 ); + fclose( fp ); + return true; + } + return false; +} + + +TiXmlNodeA* TiXmlDocumentA::Clone() const +{ + TiXmlDocumentA* clone = new TiXmlDocumentA(); + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->error = error; + clone->errorDesc = errorDesc.c_str (); + + TiXmlNodeA* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +void TiXmlDocumentA::Print( FILE* cfile, int depth ) const +{ + TiXmlNodeA* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + +void TiXmlDocumentA::StreamOut( TIXMLA_OSTREAM * out ) const +{ + TiXmlNodeA* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->StreamOut( out ); + + // Special rule for streams: stop after the root element. + // The stream in code will only read one element, so don't + // write more than one. + if ( node->ToElement() ) + break; + } +} + + +TiXmlAttributeA* TiXmlAttributeA::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + + +TiXmlAttributeA* TiXmlAttributeA::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + + +void TiXmlAttributeA::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXMLA_STRING n, v; + + PutString( Name(), &n ); + PutString( Value(), &v ); + + if (value.find ('\"') == TIXMLA_STRING::npos) + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + else + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); +} + + +void TiXmlAttributeA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + if (value.find( '\"' ) != TIXMLA_STRING::npos) + { + PutString( name, stream ); + (*stream) << "=" << "'"; + PutString( value, stream ); + (*stream) << "'"; + } + else + { + PutString( name, stream ); + (*stream) << "=" << "\""; + PutString( value, stream ); + (*stream) << "\""; + } +} + +int TiXmlAttributeA::QueryIntValue( int* ival ) const +{ + if ( sscanf( value.c_str(), "%d", ival ) == 1 ) + return TIXMLA_SUCCESS; + return TIXMLA_WRONG_TYPE; +} + +int TiXmlAttributeA::QueryDoubleValue( double* dval ) const +{ + if ( sscanf( value.c_str(), "%lf", dval ) == 1 ) + return TIXMLA_SUCCESS; + return TIXMLA_WRONG_TYPE; +} + +void TiXmlAttributeA::SetIntValue( int _value ) +{ + char buf [64]; + sprintf (buf, "%d", _value); + SetValue (buf); +} + +void TiXmlAttributeA::SetDoubleValue( double _value ) +{ + char buf [64]; + sprintf (buf, "%lf", _value); + SetValue (buf); +} + +const int TiXmlAttributeA::IntValue() const +{ + return atoi (value.c_str ()); +} + +const double TiXmlAttributeA::DoubleValue() const +{ + return atof (value.c_str ()); +} + +void TiXmlCommentA::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + +void TiXmlCommentA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << ""; +} + +TiXmlNodeA* TiXmlCommentA::Clone() const +{ + TiXmlCommentA* clone = new TiXmlCommentA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +void TiXmlTextA::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXMLA_STRING buffer; + PutString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); +} + + +void TiXmlTextA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + PutString( value, stream ); +} + + +TiXmlNodeA* TiXmlTextA::Clone() const +{ + TiXmlTextA* clone = 0; + clone = new TiXmlTextA( "" ); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlDeclarationA::TiXmlDeclarationA( const char * _version, + const char * _encoding, + const char * _standalone ) +: TiXmlNodeA( TiXmlNodeA::DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +void TiXmlDeclarationA::Print( FILE* cfile, int /*depth*/ ) const +{ + fprintf (cfile, ""); +} + +void TiXmlDeclarationA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << ""; +} + +TiXmlNodeA* TiXmlDeclarationA::Clone() const +{ + TiXmlDeclarationA* clone = new TiXmlDeclarationA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->version = version; + clone->encoding = encoding; + clone->standalone = standalone; + return clone; +} + + +void TiXmlUnknownA::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i"; // Don't use entities hear! It is unknown. +} + +TiXmlNodeA* TiXmlUnknownA::Clone() const +{ + TiXmlUnknownA* clone = new TiXmlUnknownA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlAttributeSetA::TiXmlAttributeSetA() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSetA::~TiXmlAttributeSetA() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSetA::Add( TiXmlAttributeA* addMe ) +{ + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSetA::Remove( TiXmlAttributeA* removeMe ) +{ + TiXmlAttributeA* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + +TiXmlAttributeA* TiXmlAttributeSetA::Find( const char * name ) const +{ + TiXmlAttributeA* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + + +#ifdef TIXMLA_USE_STL +TIXMLA_ISTREAM & operator >> (TIXMLA_ISTREAM & in, TiXmlNodeA & base) +{ + TIXMLA_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0 ); + return in; +} +#endif + + +TIXMLA_OSTREAM & operator<< (TIXMLA_OSTREAM & out, const TiXmlNodeA & base) +{ + base.StreamOut (& out); + return out; +} + + +#ifdef TIXMLA_USE_STL +std::string & operator<< (std::string& out, const TiXmlNodeA& base ) +{ + std::ostringstream os_stream( std::ostringstream::out ); + base.StreamOut( &os_stream ); + + out.append( os_stream.str() ); + return out; +} +#endif + + +TiXmlHandleA TiXmlHandleA::FirstChild() const +{ + if ( node ) + { + TiXmlNodeA* child = node->FirstChild(); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChild( const char * value ) const +{ + if ( node ) + { + TiXmlNodeA* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChildElement() const +{ + if ( node ) + { + TiXmlElementA* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChildElement( const char * value ) const +{ + if ( node ) + { + TiXmlElementA* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + +TiXmlHandleA TiXmlHandleA::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNodeA* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNodeA* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElementA* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElementA* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h new file mode 100644 index 000000000..572f7fd35 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h @@ -0,0 +1,1259 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXMLA_INCLUDED +#define TINYXMLA_INCLUDED + +#ifdef _MSC_VER +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#if defined( DEBUG ) && defined( _MSC_VER ) +#include +#define TIXMLA_LOG OutputDebugString +#else +#define TIXMLA_LOG printf +#endif + +#ifdef TIXMLA_USE_STL + #include + #include + //#include + #define TIXMLA_STRING std::string + #define TIXMLA_ISTREAM std::istream + #define TIXMLA_OSTREAM std::ostream +#else + #include "tinystrA.h" + #define TIXMLA_STRING TiXmlStringA + #define TIXMLA_OSTREAM TiXmlOutStreamA +#endif + +class TiXmlDocumentA; +class TiXmlElementA; +class TiXmlCommentA; +class TiXmlUnknownA; +class TiXmlAttributeA; +class TiXmlTextA; +class TiXmlDeclarationA; + +class TiXmlParsingDataA; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursorA +{ + TiXmlCursorA() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +// Only used by Attribute::Query functions +enum +{ + TIXMLA_SUCCESS, + TIXMLA_NO_ATTRIBUTE, + TIXMLA_WRONG_TYPE +}; + +/** TiXmlBaseA is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBaseA +{ + friend class TiXmlNodeA; + friend class TiXmlElementA; + friend class TiXmlDocumentA; + +public: + TiXmlBaseA() {} + virtual ~TiXmlBaseA() {} + + /** All TinyXml classes can print themselves to a filestream. + This is a formatted print, and will insert tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + values is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocumentA::Load(), + TiXmlDocumentA::LoadFile(), or any TiXmlNodeA::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocumentA::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocumentA::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + +protected: + // See STL_STRING_BUG + // Utility class to overcome a bug. + class StringToBuffer + { + public: + StringToBuffer( const TIXMLA_STRING& str ); + ~StringToBuffer(); + char* buffer; + }; + + static const char* SkipWhiteSpace( const char* ); + inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); } + + virtual void StreamOut (TIXMLA_OSTREAM *) const = 0; + + #ifdef TIXMLA_USE_STL + static bool StreamWhiteSpace( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + static bool StreamTo( TIXMLA_ISTREAM * in, int character, TIXMLA_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXMLA_STRING* name ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXMLA_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase ); // whether to ignore case in the end tag + + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ) = 0; + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value ); + + // Get a character, while interpreting entities. + inline static const char* GetChar( const char* p, char* _value ) + { + assert( p ); + if ( *p == '&' ) + { + return GetEntity( p, _value ); + } + else + { + *_value = *p; + return p+1; + } + } + + // Puts a string to a stream, expanding entities as it goes. + // Note this should not contian the '<', '>', etc, or they will be transformed into entities! + static void PutString( const TIXMLA_STRING& str, TIXMLA_OSTREAM* out ); + + static void PutString( const TIXMLA_STRING& str, TIXMLA_STRING* out ); + + // Return true if the next characters in the stream are any of the endTag sequences. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase ); + + + enum + { + TIXMLA_NO_ERROR = 0, + TIXMLA_ERROR, + TIXMLA_ERROR_OPENING_FILE, + TIXMLA_ERROR_OUT_OF_MEMORY, + TIXMLA_ERROR_PARSING_ELEMENT, + TIXMLA_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXMLA_ERROR_READING_ELEMENT_VALUE, + TIXMLA_ERROR_READING_ATTRIBUTES, + TIXMLA_ERROR_PARSING_EMPTY, + TIXMLA_ERROR_READING_END_TAG, + TIXMLA_ERROR_PARSING_UNKNOWN, + TIXMLA_ERROR_PARSING_COMMENT, + TIXMLA_ERROR_PARSING_DECLARATION, + TIXMLA_ERROR_DOCUMENT_EMPTY, + + TIXMLA_ERROR_STRING_COUNT + }; + static const char* errorString[ TIXMLA_ERROR_STRING_COUNT ]; + + TiXmlCursorA location; + +private: + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNodeA + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNodeA : public TiXmlBaseA +{ + friend class TiXmlDocumentA; + friend class TiXmlElementA; + +public: + #ifdef TIXMLA_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, TiXmlNodeA& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElementA (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocumentA will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const TiXmlNodeA& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const TiXmlNodeA& base ); + + #else + // Used internally, not part of the public API. + friend TIXMLA_OSTREAM& operator<< (TIXMLA_OSTREAM& out, const TiXmlNodeA& base); + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + DOCUMENT, + ELEMENT, + COMMENT, + UNKNOWN, + TEXT, + DECLARATION, + TYPECOUNT + }; + + virtual ~TiXmlNodeA(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNodeA. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char * Value() const { return value.c_str (); } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXMLA_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "" ); + } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNodeA* Parent() const { return parent; } + + TiXmlNodeA* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNodeA* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + + TiXmlNodeA* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNodeA* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNodeA* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + TiXmlNodeA* IterateChildren( TiXmlNodeA* previous ) const; + + /// This flavor of IterateChildren searches for children with a particular 'value' + TiXmlNodeA* IterateChildren( const char * value, TiXmlNodeA* previous ) const; + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* IterateChildren( const std::string& _value, TiXmlNodeA* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertEndChild( const TiXmlNodeA& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNodeA* LinkEndChild( TiXmlNodeA* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertBeforeChild( TiXmlNodeA* beforeThis, const TiXmlNodeA& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertAfterChild( TiXmlNodeA* afterThis, const TiXmlNodeA& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* ReplaceChild( TiXmlNodeA* replaceThis, const TiXmlNodeA& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNodeA* removeThis ); + + /// Navigate to a sibling node. + TiXmlNodeA* PreviousSibling() const { return prev; } + + /// Navigate to a sibling node. + TiXmlNodeA* PreviousSibling( const char * ) const; + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNodeA* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + TiXmlNodeA* NextSibling() const { return next; } + + /// Navigate to a sibling node with the given 'value'. + TiXmlNodeA* NextSibling( const char * ) const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElementA* NextSiblingElement() const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElementA* NextSiblingElement( const char * ) const; + + #ifdef TIXMLA_USE_STL + TiXmlElementA* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + TiXmlElementA* FirstChildElement() const; + + /// Convenience function to get through elements. + TiXmlElementA* FirstChildElement( const char * value ) const; + + #ifdef TIXMLA_USE_STL + TiXmlElementA* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: DOCUMENT, ELEMENT, COMMENT, + UNKNOWN, TEXT, and DECLARATION. + */ + virtual int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + TiXmlDocumentA* GetDocument() const; + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + TiXmlDocumentA* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocumentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElementA* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElementA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlCommentA* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlCommentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknownA* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknownA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlTextA* ToText() const { return ( this && type == TEXT ) ? (TiXmlTextA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclarationA* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclarationA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + + virtual TiXmlNodeA* Clone() const = 0; + + void SetUserData( void* user ) { userData = user; } + void* GetUserData() { return userData; } + +protected: + TiXmlNodeA( NodeType type ); + + #ifdef TIXMLA_USE_STL + // The real work of the input operator. + virtual void StreamIn( TIXMLA_ISTREAM* in, TIXMLA_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNodeA* Identify( const char* start ); + void CopyToClone( TiXmlNodeA* target ) const { target->SetValue (value.c_str() ); + target->userData = userData; } + + // Internal Value function returning a TIXMLA_STRING + TIXMLA_STRING SValue() const { return value ; } + + TiXmlNodeA* parent; + NodeType type; + + TiXmlNodeA* firstChild; + TiXmlNodeA* lastChild; + + TIXMLA_STRING value; + + TiXmlNodeA* prev; + TiXmlNodeA* next; + void* userData; +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttributeA : public TiXmlBaseA +{ + friend class TiXmlAttributeSetA; + +public: + /// Construct an empty attribute. + TiXmlAttributeA() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXMLA_USE_STL + /// std::string constructor. + TiXmlAttributeA( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttributeA( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. + const int IntValue() const; ///< Return the value of this attribute, converted to an integer. + const double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXMLA_SUCCESS. If it is not + an integer, it returns TIXMLA_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int value ); ///< Set the value from an integer. + void SetDoubleValue( double value ); ///< Set the value from a double. + + #ifdef TIXMLA_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) + { + StringToBuffer buf( _name ); + SetName ( buf.buffer ? buf.buffer : "error" ); + } + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "error" ); + } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + TiXmlAttributeA* Next() const; + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + TiXmlAttributeA* Previous() const; + + bool operator==( const TiXmlAttributeA& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttributeA& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttributeA& rhs ) const { return name > rhs.name; } + + /* [internal use] + Attribtue parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocumentA* doc ) { document = doc; } + +private: + TiXmlDocumentA* document; // A pointer back to a document, for error reporting. + TIXMLA_STRING name; + TIXMLA_STRING value; + TiXmlAttributeA* prev; + TiXmlAttributeA* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSetA +{ +public: + TiXmlAttributeSetA(); + ~TiXmlAttributeSetA(); + + void Add( TiXmlAttributeA* attribute ); + void Remove( TiXmlAttributeA* attribute ); + + TiXmlAttributeA* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttributeA* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttributeA* Find( const char * name ) const; + +private: + TiXmlAttributeA sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElementA : public TiXmlNodeA +{ +public: + /// Construct an element. + TiXmlElementA (const char * in_value); + + #ifdef TIXMLA_USE_STL + /// std::string constructor. + TiXmlElementA( const std::string& _value ) : TiXmlNodeA( TiXmlNodeA::ELEMENT ) + { + firstChild = lastChild = 0; + value = _value; + } + #endif + + virtual ~TiXmlElementA(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXMLA_SUCCESS. If it is not + an integer, it returns TIXMLA_WRONG_TYPE. If the attribute + does not exist, then TIXMLA_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* value ) const; + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * value ); + + #ifdef TIXMLA_USE_STL + const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); } + const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ) + { + StringToBuffer n( name ); + StringToBuffer v( _value ); + if ( n.buffer && v.buffer ) + SetAttribute (n.buffer, v.buffer ); + } + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ) + { + StringToBuffer n( name ); + if ( n.buffer ) + SetAttribute (n.buffer, _value); + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXMLA_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + TiXmlAttributeA* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttributeA* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + + virtual void Print( FILE* cfile, int depth ) const; + +protected: + + // Used to be public [internal use] + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + + /* [internal use] + Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, TiXmlParsingDataA* prevData ); + +private: + TiXmlAttributeSetA attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlCommentA : public TiXmlNodeA +{ +public: + /// Constructs an empty comment. + TiXmlCommentA() : TiXmlNodeA( TiXmlNodeA::COMMENT ) {} + virtual ~TiXmlCommentA() {} + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + // used to be public + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + /* [internal use] + Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); +}; + + +/** XML text. Contained in an element. +*/ +class TiXmlTextA : public TiXmlNodeA +{ + friend class TiXmlElementA; +public: + /// Constructor. + TiXmlTextA (const char * initValue) : TiXmlNodeA (TiXmlNodeA::TEXT) + { + SetValue( initValue ); + } + virtual ~TiXmlTextA() {} + + #ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlTextA( const std::string& initValue ) : TiXmlNodeA (TiXmlNodeA::TEXT) + { + SetValue( initValue ); + } + #endif + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected : + // [internal use] Creates a new Element and returns it. + virtual TiXmlNodeA* Clone() const; + virtual void StreamOut ( TIXMLA_OSTREAM * out ) const; + // [internal use] + bool Blank() const; // returns true if all white space and new lines + /* [internal use] + Attribtue parsing starts: First char of the text + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + // [internal use] + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclarationA : public TiXmlNodeA +{ +public: + /// Construct an empty declaration. + TiXmlDeclarationA() : TiXmlNodeA( TiXmlNodeA::DECLARATION ) {} + +#ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlDeclarationA( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : TiXmlNodeA( TiXmlNodeA::DECLARATION ) + { + version = _version; + encoding = _encoding; + standalone = _standalone; + } +#endif + + /// Construct. + TiXmlDeclarationA( const char* _version, + const char* _encoding, + const char* _standalone ); + + virtual ~TiXmlDeclarationA() {} + + /// Version. Will return empty if none was found. + const char * Version() const { return version.c_str (); } + /// Encoding. Will return empty if none was found. + const char * Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char * Standalone() const { return standalone.c_str (); } + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected: + // used to be public + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut ( TIXMLA_OSTREAM * out) const; + // [internal use] + // Attribtue parsing starts: next char past '<' + // returns: next char past '>' + + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + +private: + TIXMLA_STRING version; + TIXMLA_STRING encoding; + TIXMLA_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. +*/ +class TiXmlUnknownA : public TiXmlNodeA +{ +public: + TiXmlUnknownA() : TiXmlNodeA( TiXmlNodeA::UNKNOWN ) {} + virtual ~TiXmlUnknownA() {} + + // [internal use] + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut ( TIXMLA_OSTREAM * out ) const; + /* [internal use] + Attribute parsing starts: First char of the text + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocumentA : public TiXmlNodeA +{ +public: + /// Create an empty document, that has no name. + TiXmlDocumentA(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocumentA( const char * documentName ); + + #ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlDocumentA( const std::string& documentName ) : + TiXmlNodeA( TiXmlNodeA::DOCUMENT ) + { + value = documentName; + error = false; + } + #endif + + virtual ~TiXmlDocumentA() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile(); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + + #ifdef TIXMLA_USE_STL + bool LoadFile( const std::string& filename ) ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && LoadFile( f.buffer )); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && SaveFile( f.buffer )); + } + #endif + + /** Parse the given null terminated block of xml data. + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data = 0 ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + TiXmlElementA* RootElement() const { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + const int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() { return errorLocation.row+1; } + int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocumentA doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Dump the document to standard out. */ + void Print() const { Print( stdout, 0 ); } + + // [internal use] + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, TiXmlParsingDataA* prevData ); + +protected : + virtual void StreamOut ( TIXMLA_OSTREAM * out) const; + // [internal use] + virtual TiXmlNodeA* Clone() const; + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + +private: + bool error; + int errorId; + TIXMLA_STRING errorDesc; + int tabsize; + TiXmlCursorA errorLocation; +}; + + +/** + A TiXmlHandleA is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandleA is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElementA* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElementA* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElementA* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElementA* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandleA addresses the verbosity + of such code. A TiXmlHandleA checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandleA docHandle( &document ); + TiXmlElementA* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandleA handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElementA* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElementA* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandleA +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandleA( TiXmlNodeA* node ) { this->node = node; } + /// Copy constructor + TiXmlHandleA( const TiXmlHandleA& ref ) { this->node = ref.node; } + + /// Return a handle to the first child node. + TiXmlHandleA FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandleA FirstChild( const char * value ) const; + /// Return a handle to the first child element. + TiXmlHandleA FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandleA FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandleA Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandleA Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandleA ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandleA ChildElement( int index ) const; + + #ifdef TIXMLA_USE_STL + TiXmlHandleA FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandleA FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandleA Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandleA ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /// Return the handle as a TiXmlNodeA. This may return null. + TiXmlNodeA* Node() const { return node; } + /// Return the handle as a TiXmlElementA. This may return null. + TiXmlElementA* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /// Return the handle as a TiXmlTextA. This may return null. + TiXmlTextA* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + +private: + TiXmlNodeA* node; +}; + + +#endif + diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp new file mode 100644 index 000000000..2efeeb4e6 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp @@ -0,0 +1,50 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + +// The goal of the seperate error file is to make the first +// step towards localization. tinyxml (currently) only supports +// latin-1, but at least the error messages could now be translated. +// +// It also cleans up the code a bit. +// + +const char* TiXmlBaseA::errorString[ TIXMLA_ERROR_STRING_COUNT ] = +{ + "No error", + "Error", + "Failed to open file", + "Memory allocation failed.", + "Error parsing Element.", + "Failed to read Element name", + "Error reading Element value.", + "Error reading Attributes.", + "Error: empty tag.", + "Error reading end tag.", + "Error parsing Unknown.", + "Error parsing Comment.", + "Error parsing Declaration.", + "Error document empty." +}; diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp new file mode 100644 index 000000000..1a13817d9 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp @@ -0,0 +1,1157 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" +#include + +//#define DEBUG_PARSER + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBaseA::Entity TiXmlBaseA::entity[ NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + + +class TiXmlParsingDataA +{ + friend class TiXmlDocumentA; + public: + //TiXmlParsingDataA( const char* now, const TiXmlParsingDataA* prevData ); + void Stamp( const char* now ); + + const TiXmlCursorA& Cursor() { return cursor; } + //void Update( const char* now ); + + private: + // Only used by the document! + TiXmlParsingDataA( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursorA cursor; + const char* stamp; + int tabsize; +}; + + +void TiXmlParsingDataA::Stamp( const char* now ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*p) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + default: + // Eat the character + ++p; + + // Normal char - just advance one column + ++col; + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* TiXmlBaseA::SkipWhiteSpace( const char* p ) +{ + if ( !p || !*p ) + { + return 0; + } + while ( p && *p ) + { + if ( isspace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. + ++p; + else + break; + } + + return p; +} + +#ifdef TIXMLA_USE_STL +/*static*/ bool TiXmlBaseA::StreamWhiteSpace( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + if ( !IsWhiteSpace( c ) ) + return true; + *tag += in->get(); + } +} + +/*static*/ bool TiXmlBaseA::StreamTo( TIXMLA_ISTREAM * in, int character, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + + in->get(); + *tag += c; + } + return false; +} +#endif + +const char* TiXmlBaseA::ReadName( const char* p, TIXMLA_STRING * name ) +{ + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( isalpha( (unsigned char) *p ) || *p == '_' ) ) + { + while( p && *p + && ( isalnum( (unsigned char ) *p ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + (*name) += *p; + ++p; + } + return p; + } + return 0; +} + +const char* TiXmlBaseA::GetEntity( const char* p, char* value ) +{ + // Presume an entity, and pull it out. + TIXMLA_STRING ent; + int i; + + // Handle the &#x entities. + if ( strncmp( "&#x", p, 3 ) == 0 + && *(p+3) + && *(p+4) + && ( *(p+4) == ';' || *(p+5) == ';' ) + ) + { + *value = 0; + + if ( *(p+4) == ';' ) + { + // Short, one value entity. + if ( isalpha( *(p+3) ) ) *value += ( tolower( *(p+3) ) - 'a' + 10 ); + else *value += ( *(p+3) - '0' ); + + return p+5; + } + else + { + // two value entity + if ( isalpha( *(p+3) ) ) *value += ( tolower( *(p+3) ) - 'a' + 10 ) * 16; + else *value += ( *(p+3) - '0' ) * 16; + + if ( isalpha( *(p+4) ) ) *value += ( tolower( *(p+4) ) - 'a' + 10 ); + else *value += ( *(p+4) - '0' ); + + return p+6; + } + } + + // Now try to match it. + for( i=0; i" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXMLA_ERROR_PARSING_EMPTY, 0, 0 ); + return; + } + + while ( in->good() ) + { + int tagIndex = tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNodeA* node = Identify( tag->c_str() + tagIndex ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXMLA_ERROR, 0, 0 ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXMLA_ERROR, 0, 0 ); +} + +#endif + +const char* TiXmlDocumentA::Parse( const char* p, TiXmlParsingDataA* prevData ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXMLA_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingDataA data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + p = SkipWhiteSpace( p ); + if ( !p ) + { + SetError( TIXMLA_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + while ( p && *p ) + { + TiXmlNodeA* node = Identify( p ); + if ( node ) + { + p = node->Parse( p, &data ); + LinkEndChild( node ); + } + else + { + break; + } + p = SkipWhiteSpace( p ); + } + + // All is well. + return p; +} + +void TiXmlDocumentA::SetError( int err, const char* pError, TiXmlParsingDataA* data ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXMLA_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + //TiXmlParsingDataA data( pError, prevData ); + data->Stamp( pError ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNodeA* TiXmlNodeA::Identify( const char* p ) +{ + TiXmlNodeA* returnNode = 0; + + p = SkipWhiteSpace( p ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + TiXmlDocumentA* doc = GetDocument(); + p = SkipWhiteSpace( p ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false ) ) + { + document->SetError( TIXMLA_ERROR_PARSING_COMMENT, p, data ); + return 0; + } + p += strlen( startTag ); + p = ReadText( p, &value, false, endTag, false ); + return p; +} + + +const char* TiXmlAttributeA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + p = SkipWhiteSpace( p ); + if ( !p || !*p ) return 0; + + int tabsize = 4; + if ( document ) + tabsize = document->TabSize(); + +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, pErr, data ); + return 0; + } + p = SkipWhiteSpace( p ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + const char* end; + + if ( *p == '\'' ) + { + ++p; + end = "\'"; + p = ReadText( p, &value, false, end, false ); + } + else if ( *p == '"' ) + { + ++p; + end = "\""; + p = ReadText( p, &value, false, end, false ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !isspace( *p ) && *p != '\n' && *p != '\r' // whitespace + && *p != '/' && *p != '>' ) // tag end + { + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXMLA_USE_STL +void TiXmlTextA::StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == '<' ) + return; + + (*tag) += c; + in->get(); + } +} +#endif + +const char* TiXmlTextA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + value = ""; +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false ); + if ( p ) + return p-1; // don't truncate the '<' + return 0; +} + +#ifdef TIXMLA_USE_STL +void TiXmlDeclarationA::StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + (*tag) += c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* TiXmlDeclarationA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + p = SkipWhiteSpace( p ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocumentA* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXMLA_ERROR_PARSING_DECLARATION, 0, 0 ); + return 0; + } +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p ); + if ( StringEqual( p, "version", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !isspace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlTextA::Blank() const +{ + for ( unsigned i=0; iGetDocument()->FirstChild()->ToDeclaration(); + TiXmlDeclarationA *declaration = _dlgNode->GetDocument()->FirstChild()->ToDeclaration(); if (declaration) { - const TCHAR * encodingStr = declaration->Encoding(); + const char * encodingStr = declaration->Encoding(); nativeLangEncoding = getCpFromStringValue(encodingStr); } #endif // Set Title - const TCHAR *titre = (_dlgNode->ToElement())->Attribute(TEXT("title")); + const char *titre = (_dlgNode->ToElement())->Attribute("title"); if (titre && titre[0]) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(titre, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(titre, nativeLangEncoding); ::SetWindowText(_hSelf, nameW); #else ::SetWindowText(_hSelf, titre); @@ -413,22 +412,21 @@ bool WindowsDlg::changeDlgLang() } // Set the text of child control - for (TiXmlNode *childNode = _dlgNode->FirstChildElement(TEXT("Item")); + for (TiXmlNodeA *childNode = _dlgNode->FirstChildElement("Item"); childNode ; - childNode = childNode->NextSibling(TEXT("Item")) ) + childNode = childNode->NextSibling("Item") ) { - TiXmlElement *element = childNode->ToElement(); + TiXmlElementA *element = childNode->ToElement(); int id; - const TCHAR *sentinel = element->Attribute(TEXT("id"), &id); - const TCHAR *name = element->Attribute(TEXT("name")); + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); if (sentinel && (name && name[0])) { HWND hItem = ::GetDlgItem(_hSelf, id); if (hItem) { #ifdef UNICODE - const char *pCharStrA = wmc->wchar2char(name, CP_ANSI_LATIN_1); - const wchar_t *nameW = wmc->char2wchar(pCharStrA, nativeLangEncoding); + const wchar_t *nameW = wmc->char2wchar(name, nativeLangEncoding); ::SetWindowText(hItem, nameW); #else ::SetWindowText(hItem, name); diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h index 23e331450..1580804e9 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h @@ -61,7 +61,7 @@ class WindowsDlg : public SizeableDlg public : WindowsDlg(); - int doDialog(TiXmlNode *dlgNode); + int doDialog(TiXmlNodeA *dlgNode); virtual void init(HINSTANCE hInst, HWND parent, DocTabView *pTab); void doRefresh(bool invalidate = false); @@ -90,7 +90,7 @@ protected : std::vector _idxMap; int _lastSort; bool _isSorted; - TiXmlNode *_dlgNode; + TiXmlNodeA *_dlgNode; private: virtual void init(HINSTANCE hInst, HWND parent); diff --git a/PowerEditor/src/lastRecentFileList.cpp b/PowerEditor/src/lastRecentFileList.cpp index 13612aef3..65a83afdd 100644 --- a/PowerEditor/src/lastRecentFileList.cpp +++ b/PowerEditor/src/lastRecentFileList.cpp @@ -30,18 +30,28 @@ void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase) { void LastRecentFileList::updateMenu() { if (!_hasSeparators && _size > 0) { //add separators - const TCHAR * nativeLangOpenAllFiles = (NppParameters::getInstance())->getNativeLangMenuString(IDM_OPEN_ALL_RECENT_FILE); - const TCHAR * nativeLangCleanFilesList = (NppParameters::getInstance())->getNativeLangMenuString(IDM_CLEAN_RECENT_FILE_LIST); + const char * nativeLangOpenAllFiles = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_OPEN_ALL_RECENT_FILE); + const char * nativeLangCleanFilesList = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_CLEAN_RECENT_FILE_LIST); - const TCHAR * openAllFileStr = nativeLangOpenAllFiles?nativeLangOpenAllFiles:TEXT("Open All Recent Files"); - const TCHAR * cleanFileListStr = nativeLangCleanFilesList?nativeLangCleanFilesList:TEXT("Clean Recent Files List"); + const char * openAllFileStr = nativeLangOpenAllFiles?nativeLangOpenAllFiles:"Open All Recent Files"; + const char * cleanFileListStr = nativeLangCleanFilesList?nativeLangCleanFilesList:"Clean Recent Files List"; ::InsertMenu(_hMenu, _posBase + 0, MF_BYPOSITION, UINT(-1), 0); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * openAllFileStrW = wmc->char2wchar(openAllFileStr, CP_ANSI_LATIN_1); + ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStrW); + const wchar_t * cleanFileListStrW = wmc->char2wchar(cleanFileListStr, CP_ANSI_LATIN_1); + ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStrW); +#else ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStr); ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStr); +#endif ::InsertMenu(_hMenu, _posBase + 3, MF_BYPOSITION, UINT(-1), 0); _hasSeparators = true; - } else if (_hasSeparators && _size == 0) { //remove separators + } + else if (_hasSeparators && _size == 0) //remove separators + { ::RemoveMenu(_hMenu, _posBase + 3, MF_BYPOSITION); ::RemoveMenu(_hMenu, IDM_CLEAN_RECENT_FILE_LIST, MF_BYCOMMAND); ::RemoveMenu(_hMenu, IDM_OPEN_ALL_RECENT_FILE, MF_BYCOMMAND); diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index 0e419a3ec..c71ff4351 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -42,8 +42,8 @@ Name="VCCLCompilerTool" Optimization="0" FavorSizeOrSpeed="0" - AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL" + AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL" MinimalRebuild="true" ExceptionHandling="2" BasicRuntimeChecks="0" @@ -135,8 +135,8 @@ FavorSizeOrSpeed="1" OmitFramePointers="false" WholeProgramOptimization="false" - AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL" + AdditionalIncludeDirectories="..\src\WinControls\AboutDlg;..\..\scintilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScitillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL" StringPooling="true" ExceptionHandling="2" RuntimeLibrary="0" @@ -374,18 +374,34 @@ RelativePath="..\src\TinyXml\tinystr.cpp" > + + + + + + + + @@ -683,10 +699,18 @@ RelativePath="..\src\TinyXml\tinystr.h" > + + + +