// Copyright © 2010 sss // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h" extern HINSTANCE hInst; static BOOL CALLBACK DlgProcReplacerOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); static BOOL CheckStateLoadDB(HWND hwndDlg, int idCtrl, const char* szSetting, BYTE bDef) { BOOL state = DBGetContactSettingByte(NULL, szReplacerModuleName, szSetting, bDef); CheckDlgButton(hwndDlg, idCtrl, state); return state; } static BOOL CheckStateStoreDB(HWND hwndDlg, int idCtrl, const char* szSetting) { BOOL state = IsDlgButtonChecked(hwndDlg, idCtrl); DBWriteContactSettingByte(NULL, szReplacerModuleName, szSetting, (BYTE)state); return state; } int ReplacerOptInit(WPARAM wParam,LPARAM lParam) { OPTIONSDIALOGPAGE odp = { 0 }; odp.cbSize = sizeof(odp); odp.hInstance = hInst; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_REPLACER); odp.pszTitle = szReplacerModuleName; odp.pszGroup = "Message Sessions"; odp.pszTab = "Main"; odp.flags=ODPF_BOLDGROUPS; odp.pfnDlgProc = DlgProcReplacerOpts; CallService(MS_OPT_ADDPAGE,wParam,(LPARAM)&odp); return 0; } HWND hwnd_list_p = NULL; int item_num = 0; bool bTargetWord = false; bool bEdit = false; static BOOL CALLBACK DlgProcReplacerOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hwndList1 = GetDlgItem(hwndDlg, IDC_LIST1); HWND hwndList2 = GetDlgItem(hwndDlg, IDC_LIST2); LVCOLUMN col = {0}; LVITEM item = {0}; NMLISTVIEW * hdr = (NMLISTVIEW *) lParam; void ShowWordEditDialog(); switch (msg) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); col.pszText = _T("Source word:"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 80; ListView_InsertColumn(hwndList1, 0, &col); col.pszText = _T("Target word:"); col.mask = LVCF_TEXT | LVCF_WIDTH; col.fmt = LVCFMT_LEFT; col.cx = 80; ListView_InsertColumn(hwndList2, 0, &col); int i = 0, iRow = 0; char *setting = new char [32]; TCHAR *buf = NULL; mir_snprintf(setting, 31, "szSourceWord%d", i); buf = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T("")); while(_tcslen(buf) > 0) { item.mask = LVIF_TEXT; item.iSubItem = 0; item.pszText = buf; iRow = ListView_InsertItem(hwndList1, &item); ListView_SetItemText(hwndList1, iRow, 0, buf); mir_free(buf); ZeroMemory(&item,sizeof(item)); ListView_SetColumnWidth(hwndList1, 0, LVSCW_AUTOSIZE); i++; mir_snprintf(setting, 31, "szSourceWord%d", i); buf = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T("")); } mir_free(buf); delete [] setting; return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_ADD: { bEdit = false; ShowWordEditDialog(); if(hwnd_list_p == hwndList1) { } else if(hwnd_list_p == hwndList2) { } } break; case IDC_CHANGE: { bEdit = true; ShowWordEditDialog(); if(hwnd_list_p == hwndList1) { } else if(hwnd_list_p == hwndList2) { } } break; case IDC_DELETE: { if(hwnd_list_p == hwndList1) { } else if(hwnd_list_p == hwndList2) { } } break; default: break; } SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } case WM_NOTIFY: { if(hdr && IsWindowVisible(hdr->hdr.hwndFrom) && hdr->iItem != (-1)) { if(hdr->hdr.code == NM_CLICK) { hwnd_list_p = hdr->hdr.hwndFrom; item_num = hdr->iItem; bTargetWord = (hwnd_list_p==hwndList2)?true:false; int iRow = 0; if(hdr->hdr.hwndFrom == hwndList1) { ListView_DeleteAllItems(hwndList2); char *setting = new char [32]; TCHAR *buf = NULL; mir_snprintf(setting, 31, "szTargetWords%d", hdr->iItem); buf = UniGetContactSettingUtf(NULL, szReplacerModuleName, setting, _T("")); wstring str = buf; mir_free(buf); wstring::size_type p1 = 0, p2 = 0, end = 0; p1 = str.find(_T("\n")); //nice delimiter for(;;) { if(p1 = wstring::npos) { if(end == 0) { item.mask = LVIF_TEXT; item.iSubItem = 0; item.pszText = _T(""); iRow = ListView_InsertItem(hwndList2, &item); ListView_SetItemText(hwndList2, iRow, 0, _T("")); ZeroMemory(&item,sizeof(item)); ListView_SetColumnWidth(hwndList2, 0, LVSCW_AUTOSIZE); } break; } p2 = str.find(_T("\n"), p1); if(p2 < end || p2 == p1) break; end = p2; item.mask = LVIF_TEXT; item.iSubItem = 0; item.pszText = (TCHAR*)str.substr(p1, p2-p1).c_str(); iRow = ListView_InsertItem(hwndList2, &item); ListView_SetItemText(hwndList2, iRow, 0, (TCHAR*)str.substr(p1, p2-p1).c_str()); ZeroMemory(&item,sizeof(item)); ListView_SetColumnWidth(hwndList2, 0, LVSCW_AUTOSIZE); p1 = p2; } mir_free(buf); } if(hdr->hdr.hwndFrom == hwndList2) { } } } switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { return TRUE; } } } break; } return FALSE; } HWND hwndWordEdit = NULL; static BOOL CALLBACK DlgProcWordEditDialog(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: { TranslateDialogDefault(hwndDlg); if(bEdit) { SetWindowText(hwndDlg, bTargetWord?_T("Edit target word or phrase"):_T("Edit source word or phrase")); TCHAR word[512]; ListView_GetItemText(hwnd_list_p, item_num, 0, word, 511); SetWindowText(GetDlgItem(hwndDlg, IDC_EDIT_WORD), word); } else SetWindowText(hwndDlg, bTargetWord?_T("Add target word or phrase"):_T("Add source word or phrase")); return TRUE; } case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_OK: DestroyWindow(hwndDlg); break; case IDC_CANCEL: DestroyWindow(hwndDlg); break; default: break; } break; } case WM_NOTIFY: { // switch (((LPNMHDR)lParam)->code) // { // default: // break; // } } break; case WM_CLOSE: DestroyWindow(hwndDlg); break; case WM_DESTROY: hwndWordEdit = NULL; break; } return FALSE; } void ShowWordEditDialog() { if (hwndWordEdit == NULL) { hwndWordEdit = CreateDialog(hInst, MAKEINTRESOURCE(IDD_WORD_EDIT), NULL, DlgProcWordEditDialog); } SetForegroundWindow(hwndWordEdit); }