Index: src/ictranslate/ICTranslateDlg.cpp =================================================================== diff -u -rbee51aca3d5d9b67ecac4f528a3203738cc63455 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision bee51aca3d5d9b67ecac4f528a3203738cc63455) +++ src/ictranslate/ICTranslateDlg.cpp (.../ICTranslateDlg.cpp) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -4,6 +4,7 @@ #include "stdafx.h" #include "ictranslate.h" #include "ICTranslateDlg.h" +#include #ifdef _DEBUG #define new DEBUG_NEW @@ -55,13 +56,21 @@ void CICTranslateDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); + DDX_Control(pDX, IDC_SRCDATA_LIST, m_ctlBaseLanguageList); + DDX_Control(pDX, IDC_DSTDATA_LIST, m_ctlCustomLanguageList); + DDX_Control(pDX, IDC_SRCDATA_EDIT, m_ctlSrcText); + DDX_Control(pDX, IDC_DSTDATA_EDIT, m_ctlDstText); } BEGIN_MESSAGE_MAP(CICTranslateDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP + ON_COMMAND(ID_FILE_OPENBASETRANSLATION, &CICTranslateDlg::OnFileOpenBaseTranslation) + ON_COMMAND(ID_FILE_OPENYOURTRANSLATION, &CICTranslateDlg::OnFileOpenYourTranslation) + ON_NOTIFY(LVN_ITEMCHANGED, IDC_SRCDATA_LIST, &CICTranslateDlg::OnItemChangedSrcDataList) + ON_NOTIFY(LVN_ITEMCHANGED, IDC_DSTDATA_LIST, &CICTranslateDlg::OnItemChangedDstDataList) END_MESSAGE_MAP() @@ -81,8 +90,7 @@ if (pSysMenu != NULL) { CString strAboutMenu; - strAboutMenu.LoadString(IDS_ABOUTBOX); - if (!strAboutMenu.IsEmpty()) + if(strAboutMenu.LoadString(IDS_ABOUTBOX)) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); @@ -94,8 +102,24 @@ SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon - // TODO: Add extra initialization here + m_ctlBaseLanguageList.SetExtendedStyle(LVS_EX_FULLROWSELECT); + m_ctlCustomLanguageList.SetExtendedStyle(LVS_EX_FULLROWSELECT); + // setup the lists + LVCOLUMN lvc; + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; + lvc.fmt = LVCFMT_LEFT; + lvc.cx = 50; + lvc.pszText = _T("ID"); + + m_ctlBaseLanguageList.InsertColumn(0, &lvc); + m_ctlCustomLanguageList.InsertColumn(0, &lvc); + + lvc.cx = 150; + lvc.pszText = _T("Text"); + m_ctlBaseLanguageList.InsertColumn(1, &lvc); + m_ctlCustomLanguageList.InsertColumn(1, &lvc); + return TRUE; // return TRUE unless you set the focus to a control } @@ -148,3 +172,147 @@ return static_cast(m_hIcon); } +void CICTranslateDlg::OnFileOpenBaseTranslation() +{ + CFileDialog fd(TRUE, _T(".lng"), _T(""), OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, _T("Language files (*.lng)|*.lng|All files(*.*)|*.*||"), this); + if(fd.DoModal() == IDOK) + { + if(!m_ldBase.ReadTranslation(fd.GetPathName())) + AfxMessageBox(_T("Reading file failed")); + + // add texts to the list + m_ldBase.EnumStrings(&EnumLngStrings, &m_ctlBaseLanguageList); + } +} + +void CICTranslateDlg::OnFileOpenYourTranslation() +{ + CFileDialog fd(TRUE, _T(".lng"), _T(""), OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST, _T("Language files (*.lng)|*.lng|All files(*.*)|*.*||"), this); + if(fd.DoModal() == IDOK) + { + if(!m_ldCustom.ReadTranslation(fd.GetPathName())) + AfxMessageBox(_T("Reading file failed")); + + // add texts to the list + m_ctlCustomLanguageList.DeleteAllItems(); + m_ldCustom.EnumStrings(&EnumLngStrings, &m_ctlCustomLanguageList); + } +} + +void CICTranslateDlg::EnumLngStrings(uint_t uiID, const ictranslate::CTranslationItem* pTranslationItem, ptr_t pData) +{ + CListCtrl* pList = (CListCtrl*)pData; + assert(pTranslationItem); + if(!pTranslationItem) + return; + CString strID; + strID.Format(UIFMT, uiID); + + LVITEM lvi; + lvi.mask = LVIF_TEXT | LVIF_PARAM; + lvi.pszText = (PTSTR)(PCTSTR)strID; + lvi.iItem = 0; + lvi.iSubItem = 0; + lvi.lParam = uiID; + + pList->InsertItem(&lvi); + + lvi.mask = LVIF_TEXT; + lvi.pszText = (PTSTR)pTranslationItem->GetText(); + lvi.iItem = 0; + lvi.iSubItem = 1; + + pList->SetItem(&lvi); +} + +void CICTranslateDlg::OnItemChangedSrcDataList(NMHDR *pNMHDR, LRESULT *pResult) +{ + LPNMLISTVIEW pNMLV = reinterpret_cast(pNMHDR); + *pResult = 0; + + if(pNMLV->uNewState & LVIS_SELECTED) + { + // set the text to the edit box + m_ctlSrcText.SetWindowText(m_ctlBaseLanguageList.GetItemText(pNMLV->iItem, 1)); + + uint_t uiID = pNMLV->lParam; + + // to avoid infinite loop of selections, check if the current selection is already valid + POSITION pos = m_ctlCustomLanguageList.GetFirstSelectedItemPosition(); + if(pos) + { + int iPos = m_ctlCustomLanguageList.GetNextSelectedItem(pos); + uint_t uiCurrentID = m_ctlCustomLanguageList.GetItemData(iPos); + if(uiID == uiCurrentID) + return; + } +// m_ctlCustomLanguageList.SetItemState(-1, 0, LVIS_SELECTED); + + // search in the second list for the specified id + int iCount = m_ctlCustomLanguageList.GetItemCount(); + for(int i = 0; i < iCount; i++) + { + uint_t uiCustomID = m_ctlCustomLanguageList.GetItemData(i); + if(uiCustomID == uiID) + { + m_ctlCustomLanguageList.EnsureVisible(i, FALSE); + m_ctlCustomLanguageList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); + break; + } + } + } + else if(pNMLV->uOldState & LVIS_SELECTED) + { + m_ctlCustomLanguageList.SetItemState(-1, 0, LVIS_SELECTED); + m_ctlDstText.SetWindowText(_T("")); + } +} + +void CICTranslateDlg::OnItemChangedDstDataList(NMHDR *pNMHDR, LRESULT *pResult) +{ + LPNMLISTVIEW pNMLV = reinterpret_cast(pNMHDR); + *pResult = 0; + + if(pNMLV->uNewState & LVIS_SELECTED) + { + // set the text to the edit box + m_ctlDstText.SetWindowText(m_ctlCustomLanguageList.GetItemText(pNMLV->iItem, 1)); + + uint_t uiID = pNMLV->lParam; + + // to avoid infinite loop of selections, check if the current selection is already valid + POSITION pos = m_ctlBaseLanguageList.GetFirstSelectedItemPosition(); + if(pos) + { + int iPos = m_ctlBaseLanguageList.GetNextSelectedItem(pos); + uint_t uiCurrentID = m_ctlBaseLanguageList.GetItemData(iPos); + if(uiID == uiCurrentID) + return; + } +// m_ctlBaseLanguageList.SetItemState(-1, 0, LVIS_SELECTED); + + // search in the second list for the specified id + int iCount = m_ctlBaseLanguageList.GetItemCount(); + for(int i = 0; i < iCount; i++) + { + uint_t uiCustomID = m_ctlBaseLanguageList.GetItemData(i); + if(uiCustomID == uiID) + { + m_ctlBaseLanguageList.EnsureVisible(i, FALSE); + m_ctlBaseLanguageList.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); + break; + } + } + } + else if(pNMLV->uOldState & LVIS_SELECTED) + { + m_ctlBaseLanguageList.SetItemState(-1, 0, LVIS_SELECTED); + m_ctlSrcText.SetWindowText(_T("")); + } +} + +void CICTranslateDlg::UpdateCustomListImages() +{ + int iCount = m_ctlCustomLanguageList.GetItemCount(); + +} Index: src/ictranslate/ICTranslateDlg.h =================================================================== diff -u -rbee51aca3d5d9b67ecac4f528a3203738cc63455 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision bee51aca3d5d9b67ecac4f528a3203738cc63455) +++ src/ictranslate/ICTranslateDlg.h (.../ICTranslateDlg.h) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -2,8 +2,10 @@ // #pragma once +#include "../libictranslate/ResourceManager.h" +#include "afxcmn.h" +#include "afxwin.h" - // CICTranslateDlg dialog class CICTranslateDlg : public CDialog { @@ -17,15 +19,29 @@ protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support +protected: + static void EnumLngStrings(uint_t uiID, const ictranslate::CTranslationItem* pTranslationItem, ptr_t pData); + void UpdateCustomListImages(); // Implementation protected: HICON m_hIcon; + ictranslate::CLangData m_ldBase; + ictranslate::CLangData m_ldCustom; // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() + CListCtrl m_ctlBaseLanguageList; +public: + CListCtrl m_ctlCustomLanguageList; + CEdit m_ctlSrcText; + CEdit m_ctlDstText; + afx_msg void OnFileOpenBaseTranslation(); + afx_msg void OnFileOpenYourTranslation(); + afx_msg void OnItemChangedSrcDataList(NMHDR *pNMHDR, LRESULT *pResult); + afx_msg void OnItemChangedDstDataList(NMHDR *pNMHDR, LRESULT *pResult); }; Index: src/ictranslate/ictranslate.rc =================================================================== diff -u -rbee51aca3d5d9b67ecac4f528a3203738cc63455 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/ictranslate/ictranslate.rc (.../ictranslate.rc) (revision bee51aca3d5d9b67ecac4f528a3203738cc63455) +++ src/ictranslate/ictranslate.rc (.../ictranslate.rc) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -71,6 +71,24 @@ // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. IDR_MAINFRAME ICON "res\\ictranslate.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// Menu +// + +IDR_MAIN_MENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&New translation...", ID_FILE_NEWTRANSLATION + MENUITEM "&Open base translation...", ID_FILE_OPENBASETRANSLATION + MENUITEM "Open your translation...", ID_FILE_OPENYOURTRANSLATION + MENUITEM "&Save translation", ID_FILE_SAVETRANSLATION + MENUITEM "S&ave translation as...", ID_FILE_SAVETRANSLATIONAS + END +END + #endif // Polish resources ///////////////////////////////////////////////////////////////////////////// @@ -100,12 +118,19 @@ DEFPUSHBUTTON "OK",IDOK,113,41,50,14,WS_GROUP END -IDD_ICTRANSLATE_DIALOG DIALOGEX 0, 0, 320, 200 +IDD_ICTRANSLATE_DIALOG DIALOGEX 0, 0, 419, 223 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_APPWINDOW CAPTION "ICTranslate" +MENU IDR_MAIN_MENU FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN + CONTROL "",IDC_DSTDATA_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_EDITLABELS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,212,18,200,151 + CONTROL "",IDC_SRCDATA_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,7,18,197,153 + LTEXT "Base translation:",IDC_STATIC,7,7,196,8 + LTEXT "Your translation:",IDC_STATIC,212,7,200,8 + EDITTEXT IDC_SRCDATA_EDIT,7,179,198,37,ES_AUTOHSCROLL | ES_READONLY + EDITTEXT IDC_DSTDATA_EDIT,213,179,199,37,ES_AUTOHSCROLL END @@ -167,9 +192,9 @@ IDD_ICTRANSLATE_DIALOG, DIALOG BEGIN LEFTMARGIN, 7 - RIGHTMARGIN, 313 + RIGHTMARGIN, 412 TOPMARGIN, 7 - BOTTOMMARGIN, 193 + BOTTOMMARGIN, 216 END END #endif // APSTUDIO_INVOKED Index: src/ictranslate/ictranslate.vc90.vcproj =================================================================== diff -u -rbee51aca3d5d9b67ecac4f528a3203738cc63455 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/ictranslate/ictranslate.vc90.vcproj (.../ictranslate.vc90.vcproj) (revision bee51aca3d5d9b67ecac4f528a3203738cc63455) +++ src/ictranslate/ictranslate.vc90.vcproj (.../ictranslate.vc90.vcproj) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -445,5 +445,9 @@ + Index: src/ictranslate/resource.h =================================================================== diff -u -rbee51aca3d5d9b67ecac4f528a3203738cc63455 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/ictranslate/resource.h (.../resource.h) (revision bee51aca3d5d9b67ecac4f528a3203738cc63455) +++ src/ictranslate/resource.h (.../resource.h) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -2,20 +2,30 @@ // Microsoft Visual C++ generated include file. // Used by ictranslate.rc // -#define IDR_MAINFRAME 128 -#define IDM_ABOUTBOX 0x0010 -#define IDD_ABOUTBOX 100 -#define IDS_ABOUTBOX 101 -#define IDD_ICTRANSLATE_DIALOG 102 +#define IDM_ABOUTBOX 0x0010 +#define IDD_ABOUTBOX 100 +#define IDS_ABOUTBOX 101 +#define IDD_ICTRANSLATE_DIALOG 102 +#define IDR_MAINFRAME 128 +#define IDR_MAIN_MENU 129 +#define IDC_DSTDATA_LIST 1000 +#define IDC_SRCDATA_LIST 1001 +#define IDC_SRCDATA_EDIT 1002 +#define IDC_DSTDATA_EDIT 1003 +#define ID_FILE_NEWTRANSLATION 32771 +#define ID_FILE_OPENTRANSLATION 32772 +#define ID_FILE_SAVETRANSLATION 32773 +#define ID_FILE_SAVETRANSLATIONAS 32774 +#define ID_FILE_OPENYOURTRANSLATION 32775 +#define ID_FILE_OPENBASETRANSLATION 32776 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS - -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 32771 +#define _APS_NEXT_RESOURCE_VALUE 130 +#define _APS_NEXT_COMMAND_VALUE 32777 +#define _APS_NEXT_CONTROL_VALUE 1010 +#define _APS_NEXT_SYMED_VALUE 101 #endif #endif Index: src/libictranslate/ResourceManager.cpp =================================================================== diff -u -r3275c48bbd0163b93e9a13c72abb77be85e92c54 -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 3275c48bbd0163b93e9a13c72abb77be85e92c54) +++ src/libictranslate/ResourceManager.cpp (.../ResourceManager.cpp) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -20,6 +20,7 @@ #include "stdafx.h" #include "ResourceManager.h" #include "../libicpf/cfg.h" +#include "../libicpf/crc32.h" #include #ifdef _DEBUG @@ -30,6 +31,124 @@ #define EMPTY_STRING _t("") +CTranslationItem::CTranslationItem() : + m_pszText(NULL), + m_uiChecksum(0), + m_stTextLength(0) +{ +} + +CTranslationItem::CTranslationItem(const tchar_t* pszText, uint_t uiChecksum) : + m_pszText(NULL), + m_stTextLength(0), + m_uiChecksum(uiChecksum) +{ + if(pszText) + { + m_stTextLength = _tcslen(pszText); + if(m_stTextLength > 0) + { + m_pszText = new tchar_t[m_stTextLength + 1]; + _tcscpy(m_pszText, pszText); + + UnescapeString(); + } + } +} + +CTranslationItem::~CTranslationItem() +{ + Clear(); +} + +CTranslationItem& CTranslationItem::operator=(const CTranslationItem& rSrc) +{ + if(this != &rSrc) + { + Clear(); + if(rSrc.m_pszText) + { + m_stTextLength = rSrc.m_stTextLength; + if(m_stTextLength > 0) + { + m_pszText = new tchar_t[rSrc.m_stTextLength + 1]; + _tcscpy(m_pszText, rSrc.m_pszText); + } + } + m_uiChecksum = rSrc.m_uiChecksum; + } + + return *this; +} + +void CTranslationItem::Clear() +{ + delete [] m_pszText; + m_pszText = NULL; + m_stTextLength = 0; + m_uiChecksum = 0; +} + +void CTranslationItem::CalculateChecksum() +{ + if(m_pszText) + m_uiChecksum = icpf::crc32((const byte_t*)m_pszText, m_stTextLength*sizeof(tchar_t)); + else + m_uiChecksum = 0; +} + +void CTranslationItem::SetText(const tchar_t* pszText) +{ + delete [] m_pszText; + if(pszText) + { + m_stTextLength = _tcslen(pszText); + if(m_stTextLength > 0) + { + m_pszText = new tchar_t[m_stTextLength + 1]; + _tcscpy(m_pszText, pszText); + UnescapeString(); + return; + } + } + + m_pszText = NULL; + m_stTextLength = 0; +} + +void CTranslationItem::UnescapeString() +{ + if(!m_pszText) + return; + + const tchar_t* pszIn = m_pszText; + tchar_t* pszOut = m_pszText; + while (*pszIn != 0) + { + if (*pszIn == _T('\\')) + { + pszIn++; + switch(*pszIn++) + { + case _T('t'): + *pszOut++ = _T('\t'); + break; + case _T('r'): + *pszOut++ = _T('\r'); + break; + case _T('n'): + *pszOut++ = _T('\n'); + break; + default: + *pszOut++ = _T('\\'); + } + } + else + *pszOut++ = *pszIn++; + } + *pszOut = _T('\0'); +} + CLangData::CLangData() : m_pszFilename(NULL), m_pszLngName(NULL), @@ -51,11 +170,6 @@ delete [] m_pszHelpName; delete [] m_pszAuthor; delete [] m_pszVersion; - - for(strings_map::iterator it = m_mStrings.begin(); it != m_mStrings.end(); it++) - { - delete [] (*it).second; - } } void CLangData::Clear() @@ -75,12 +189,7 @@ delete [] m_pszVersion; m_pszVersion = NULL; - for(strings_map::iterator it = m_mStrings.begin(); it != m_mStrings.end(); it++) - { - delete [] (*it).second; - } - m_mStrings.clear(); - m_mChecksums.clear(); + m_mapTranslation.clear(); } CLangData::CLangData(const CLangData& ld) : @@ -212,59 +321,63 @@ } else { + uint_t uiID = 0; + uint_t uiChecksum = 0; + // parse the pszName to get both the string id and checksum const tchar_t* pszChecksum = _tcschr(pszName, _T('[')); if(pszChecksum == NULL) { - TRACE(_T("Warning! Old-style translation string %s; skipping.\n"), pszName); - return; // old-style translation; assume incompatibility - } + TRACE(_T("Warning! Old-style translation string %s.\n"), pszName); - UINT uiID = 0; - UINT uiChecksum = 0; - int iCount = _stscanf(pszName, UIFMT _T("[0x%lx]"), &uiID, &uiChecksum); - if(iCount != 2) + int iCount = _stscanf(pszName, UIFMT, &uiID); + if(iCount != 1) + { + TRACE(_T("Warning! Problem retrieving id from string '%s'\n"), pszName); + return; + } + } + else { - TRACE(_T("Warning! Problem retrieving checksum from string '%s'\n"), pszName); - return; + int iCount = _stscanf(pszName, UIFMT _T("[0x%lx]"), &uiID, &uiChecksum); + if(iCount != 2) + { + TRACE(_T("Warning! Problem retrieving id/checksum from string '%s'\n"), pszName); + return; + } } uint_t uiKey = pLangData->m_uiSectionID << 16 | uiID; + translation_map::iterator itTranslation = pLangData->m_mapTranslation.end(); if(pLangData->m_bUpdating) { // check if the checksum exists and matches - checksum_map::const_iterator itChecksum = pLangData->m_mChecksums.find(uiKey); - if(itChecksum == pLangData->m_mChecksums.end()) + itTranslation = pLangData->m_mapTranslation.find(uiKey); + if(itTranslation == pLangData->m_mapTranslation.end()) { TRACE(_T("Warning! Superfluous entry %lu in processed language file\n"), uiKey); return; // entry not found - probably superfluous entry in the language file } - if((*itChecksum).second != uiChecksum) + if((*itTranslation).second.GetChecksum() != uiChecksum) { TRACE(_T("Warning! Invalid checksum for string ID %lu in processed language file\n"), uiKey); return; // entry has invalid checksum (older version of translation) } - - // check if the entry already exists - strings_map::iterator it = pLangData->m_mStrings.find(uiKey); - if(it != pLangData->m_mStrings.end()) - { - delete [] (*it).second; - pLangData->m_mStrings.erase(it); - } } + else + { + std::pair pairTranslation = pLangData->m_mapTranslation.insert(translation_map::value_type(uiKey, CTranslationItem())); + itTranslation = pairTranslation.first; + } - size_t stLen = _tcslen(pszValue); - tchar_t* pszStr = new tchar_t[stLen + 1]; - _tcscpy(pszStr, pszValue); - - // convert escape strings into escape sequences - CLangData::UnescapeString(pszStr); - - pLangData->m_mStrings.insert(strings_map::value_type(uiKey, pszStr)); - if(!pLangData->m_bUpdating) - pLangData->m_mChecksums.insert(checksum_map::value_type(uiKey, uiChecksum)); + assert(itTranslation != pLangData->m_mapTranslation.end()); + if(itTranslation != pLangData->m_mapTranslation.end()) + { + (*itTranslation).second.SetText(pszValue); + if(!pLangData->m_bUpdating) + (*itTranslation).second.SetChecksum(uiChecksum); + } } } @@ -385,13 +498,21 @@ PCTSTR CLangData::GetString(WORD wHiID, WORD wLoID) { - strings_map::iterator it=m_mStrings.find((wHiID << 16) | wLoID); - if (it != m_mStrings.end()) - return (*it).second; + translation_map::const_iterator it=m_mapTranslation.find((wHiID << 16) | wLoID); + if (it != m_mapTranslation.end()) + return (*it).second.GetText(); else return EMPTY_STRING; } +void CLangData::EnumStrings(PFNENUMCALLBACK pfnCallback, ptr_t pData) +{ + for(translation_map::const_iterator iterTranslation = m_mapTranslation.begin(); iterTranslation != m_mapTranslation.end(); ++iterTranslation) + { + (*pfnCallback)((*iterTranslation).first, &(*iterTranslation).second, pData); + } +} + void CLangData::SetFilename(PCTSTR psz) { if (m_pszFilename) Index: src/libictranslate/ResourceManager.h =================================================================== diff -u -rf1ce2f1e90a5a90b713a998cda2d4cdaf2090fbd -r50fea83cc4ee863edac0fd3960e2249f99c33b03 --- src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision f1ce2f1e90a5a90b713a998cda2d4cdaf2090fbd) +++ src/libictranslate/ResourceManager.h (.../ResourceManager.h) (revision 50fea83cc4ee863edac0fd3960e2249f99c33b03) @@ -41,9 +41,34 @@ /////////////////////////////////////////////////////////// // language description structure -typedef std::map strings_map; -typedef std::map checksum_map; +class CTranslationItem +{ +public: + CTranslationItem(); + CTranslationItem(const tchar_t* pszText, uint_t uiChecksum); + ~CTranslationItem(); + CTranslationItem& operator=(const CTranslationItem& rSrc); + + void Clear(); + void CalculateChecksum(); + + const tchar_t* GetText() const { return m_pszText; } + void SetText(const tchar_t* pszText); + uint_t GetChecksum() const { return m_uiChecksum; } + void SetChecksum(uint_t uiChecksum) { m_uiChecksum = uiChecksum; } + + void UnescapeString(); + +protected: + tchar_t* m_pszText; + size_t m_stTextLength; + uint_t m_uiChecksum; +}; + +typedef void(*PFNENUMCALLBACK)(uint_t, const CTranslationItem*, ptr_t); +typedef std::map translation_map; + class LIBICTRANSLATE_API CLangData { public: @@ -61,6 +86,8 @@ PCTSTR GetString(WORD wHiID, WORD wLoID); + void EnumStrings(PFNENUMCALLBACK pfnCallback, ptr_t pData); + // attributes void SetFilename(PCTSTR psz); PCTSTR GetFilename(bool bFullPath) const; @@ -114,8 +141,7 @@ bool m_bRTL; // does the language require right-to-left reading order ? // strings (for controls in dialog boxes the ID contains hi:dlg ID, lo:ctrl ID, for strings hi part is 0) - strings_map m_mStrings; // maps string ID to the offset in pszStrings - checksum_map m_mChecksums; // checksums of strings + translation_map m_mapTranslation; // maps string ID to the offset in pszStrings private: uint_t m_uiSectionID; ///< ID of the currently processed section