From 17715ed627a2c5bf2e20e358d9bedb2cbd83e846 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Tue, 25 Dec 2018 17:09:32 +0300 Subject: Folders: moved to m_gui --- plugins/Folders/res/folders.rc | 6 +- plugins/Folders/src/dlg_handlers.cpp | 324 ++++++++++++++++++----------------- plugins/Folders/src/resource.h | 3 - plugins/Folders/src/stdafx.h | 50 ++++++ 4 files changed, 217 insertions(+), 166 deletions(-) diff --git a/plugins/Folders/res/folders.rc b/plugins/Folders/res/folders.rc index 219ff827df..39dc450d81 100644 --- a/plugins/Folders/res/folders.rc +++ b/plugins/Folders/res/folders.rc @@ -57,12 +57,12 @@ STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - GROUPBOX "Custom folders",IDC_FOLDERS_GROUPBOX,0,1,313,250 + GROUPBOX "Custom folders",IDC_STATIC,0,1,313,250 LISTBOX IDC_FOLDERS_SECTIONS_LIST,14,12,77,116,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP LISTBOX IDC_FOLDERS_ITEMS_LIST,98,12,208,116,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Preview",IDC_PREVIEW_GROUPBOX,6,131,300,55 + GROUPBOX "Preview",IDC_STATIC,6,131,300,55 EDITTEXT IDC_PREVIEW_EDIT,14,143,284,35,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP - GROUPBOX "Edit",IDC_EDIT_FOLDER_GROUPBOX,6,189,300,58 + GROUPBOX "Edit",IDC_STATIC,6,189,300,58 EDITTEXT IDC_FOLDER_EDIT,14,202,284,14,ES_AUTOHSCROLL PUSHBUTTON "Refresh preview",IDC_REFRESH_BUTTON,14,227,71,14 PUSHBUTTON "Variables help",IDC_HELP_BUTTON,231,227,67,14 diff --git a/plugins/Folders/src/dlg_handlers.cpp b/plugins/Folders/src/dlg_handlers.cpp index 1bc3745c7f..836a427044 100644 --- a/plugins/Folders/src/dlg_handlers.cpp +++ b/plugins/Folders/src/dlg_handlers.cpp @@ -4,254 +4,258 @@ PFolderItem lastItem = nullptr; static int bInitializing = 0; -static PFolderItem GetSelectedItem(HWND hWnd) +CDlgBase *pHelpDialog = nullptr; + + +PFolderItem COptDialog::GetSelectedItem() { - int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0); + int index = m_lbItems.GetCurSel(); if (index == LB_ERR) return nullptr; - return (PFolderItem)SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETITEMDATA, index, 0); + return (PFolderItem)m_lbItems.GetItemData(index); } -static void GetEditText(HWND hWnd, wchar_t *buffer, int size) +void COptDialog::GetEditText(wchar_t *buffer, int size) { - GetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size); + m_edtEdit.GetText(buffer, size); } -static void SetEditText(HWND hWnd, const wchar_t *buffer) +void COptDialog::SetEditText(const wchar_t *buffer) { bInitializing = 1; - SetDlgItemText(hWnd, IDC_FOLDER_EDIT, buffer); + m_edtEdit.SetText(buffer); bInitializing = 0; } -static int ContainsSection(HWND hWnd, const wchar_t *section) +int COptDialog::ContainsSection(const wchar_t *section) { - int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM)section); + int index = m_lbSections.SendMsg(LB_FINDSTRINGEXACT, -1, (LPARAM)section); return (index != LB_ERR); } -static void LoadRegisteredFolderSections(HWND hWnd) +void COptDialog::LoadRegisteredFolderSections() { - HWND hwndList = GetDlgItem(hWnd, IDC_FOLDERS_SECTIONS_LIST); - for (auto &it : lstRegisteredFolders) { wchar_t *translated = mir_a2u(it->GetSection()); - if (!ContainsSection(hWnd, TranslateW(translated))) { - int idx = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)TranslateW(translated)); - SendMessage(hwndList, LB_SETITEMDATA, idx, (LPARAM)it->GetSection()); + if (!ContainsSection(TranslateW(translated))) { + int idx = m_lbSections.AddString(TranslateW(translated), 0); + m_lbSections.SetItemData(idx, (LPARAM)it->GetSection()); } - mir_free(translated); } } -static void LoadRegisteredFolderItems(HWND hWnd) +void COptDialog::LoadRegisteredFolderItems() { - int idx = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0); + int idx = m_lbSections.GetCurSel(); if (idx == LB_ERR) return; - char* szSection = (char*)SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETITEMDATA, idx, 0); - - HWND hwndItems = GetDlgItem(hWnd, IDC_FOLDERS_ITEMS_LIST); - SendMessage(hwndItems, LB_RESETCONTENT, 0, 0); + char* szSection = (char*)m_lbSections.GetItemData(idx); + m_lbItems.ResetContent(); for (auto &it : lstRegisteredFolders) { if (!mir_strcmp(szSection, it->GetSection())) { - idx = SendMessage(hwndItems, LB_ADDSTRING, 0, (LPARAM)TranslateW(it->GetUserName())); - SendMessage(hwndItems, LB_SETITEMDATA, idx, (LPARAM)it); + idx = m_lbItems.AddString(TranslateW(it->GetUserName()), 0); + m_lbItems.SetItemData(idx, (LPARAM)it); } } - SendMessage(hwndItems, LB_SETCURSEL, 0, 0); //select the first item - PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_FOLDERS_ITEMS_LIST, LBN_SELCHANGE), 0); //tell the dialog to refresh the preview + m_lbItems.SetCurSel(0); //select the first item + //PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_FOLDERS_ITEMS_LIST, LBN_SELCHANGE), 0); //tell the dialog to refresh the preview } -static void RefreshPreview(HWND hWnd) +void COptDialog::RefreshPreview() { wchar_t tmp[MAX_FOLDER_SIZE]; - GetEditText(hWnd, tmp, MAX_FOLDER_SIZE); - SetDlgItemText(hWnd, IDC_PREVIEW_EDIT, ExpandPath(tmp)); + GetEditText(tmp, MAX_FOLDER_SIZE); + m_edtPreview.SetText(ExpandPath(tmp)); } -static void LoadItem(HWND hWnd, PFolderItem item) +void COptDialog::LoadItem(PFolderItem item) { if (!item) return; - SetEditText(hWnd, item->GetFormat()); - RefreshPreview(hWnd); + SetEditText(item->GetFormat()); + RefreshPreview(); } -static void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply) +void COptDialog::SaveItem(PFolderItem item, int bEnableApply) { if (!item) return; wchar_t buffer[MAX_FOLDER_SIZE]; - GetEditText(hWnd, buffer, _countof(buffer)); + GetEditText(buffer, _countof(buffer)); item->SetFormat(buffer); if (bEnableApply) - SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); + NotifyChange(); } -static int ChangesNotSaved(HWND hWnd, PFolderItem item) +int COptDialog::ChangesNotSaved(PFolderItem item) { if (!item) return 0; wchar_t buffer[MAX_FOLDER_SIZE]; - GetEditText(hWnd, buffer, MAX_FOLDER_SIZE); + GetEditText(buffer, MAX_FOLDER_SIZE); return mir_wstrcmp(item->GetFormat(), buffer) != 0; } -static void CheckForChanges(HWND hWnd, int bNeedConfirmation = 1) +void COptDialog::CheckForChanges(int bNeedConfirmation = 1) { - if (ChangesNotSaved(hWnd, lastItem)) - if ((!bNeedConfirmation) || MessageBox(hWnd, TranslateT("Some changes weren't saved. Apply the changes now?"), TranslateT("Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES) - SaveItem(hWnd, lastItem, TRUE); + if (ChangesNotSaved(lastItem)) + if ((!bNeedConfirmation) || MessageBox(m_hwnd, TranslateT("Some changes weren't saved. Apply the changes now?"), TranslateT("Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES) + SaveItem(lastItem, TRUE); } /************************************** DIALOG HANDLERS *************************************/ -static INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM) +CHelpDialog::CHelpDialog() : + CDlgBase(g_plugin, IDD_VARIABLES_HELP), + m_btnClose(this, IDCLOSE), + m_redtHelp(this, IDC_HELP_RICHEDIT) +{ + m_btnClose.OnClick = Callback(this, &CHelpDialog::OnCloseClick); +} + +bool CHelpDialog::OnInitDialog() { wchar_t tszMessage[2048]; + mir_snwprintf(tszMessage, L"%s\r\n%s\r\n\r\n%s\t\t%s\r\n%%miranda_path%%\t\t%s\r\n%%profile_path%%\t\t%s\r\n\t\t\t%s\r\n%%current_profile%%\t\t%s\r\n\t\t\t%s\r\n\r\n\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n%s\r\n%s\r\n%s\r\n%%miranda_path%%\t\t\t%s\r\n%%profile_path%%\t\t\t%s\r\n%%current_profile%%\t\t\t%s\r\n%%temp%%\t\t\t\t%s\r\n%%profile_path%%\\%%current_profile%%\t%s\r\n%%miranda_path%%\\plugins\\config\t%s\r\n' %%miranda_path%%\\\\\\\\ '\t\t%s\r\n\r\n%s", + TranslateT("Don't forget to click on Apply to save the changes. If you don't then the changes won't"), + TranslateT("be saved to the database, they will only be valid for this session."), + TranslateT("Variable string"), + TranslateT("What it expands to:"), + TranslateT("Expands to your Miranda path (e.g., c:\\program files\\miranda ng)."), + TranslateT("Expands to your profile path - the value found in mirandaboot.ini,"), + TranslateT("ProfileDir section (usually inside Miranda's folder)."), + TranslateT("Expands to your current profile name without the extenstion."), + TranslateT("(e.g., default if your your profile is default.dat)."), + TranslateT("Environment variables"), + TranslateT("The plugin can also expand environment variables; the variables are specified like in any other"), + TranslateT("program that can use environment variables, i.e., %%."), + TranslateT("Note: Environment variables are expanded before any Miranda variables. So if you have, for"), + TranslateT("example, %profile_path% defined as a system variable then it will be expanded to that value"), + TranslateT("instead of expanding to Miranda's profile path."), + TranslateT("Examples:"), + TranslateT("If the value for the ProfileDir inside mirandaboot.ini, ProfileDir section is '.\\profiles\\', current"), + TranslateT("profile is 'default.dat' and Miranda path is 'c:\\program files\\miranda ng\\' then:"), + TranslateT("will expand to 'c:\\program files\\miranda ng'"), + TranslateT("will expand to 'c:\\program files\\miranda ng\\profiles'"), + TranslateT("will expand to 'default'"), + TranslateT("will expand to the temp folder of the current user."), + TranslateT("will expand to 'c:\\program files\\miranda ng\\profiles\\default'"), + TranslateT("will expand to 'c:\\program files\\miranda ng\\plugins\\config'"), + TranslateT("will expand to 'c:\\program files\\miranda ng'"), + TranslateT("Notice that the spaces at the beginning and the end of the string are trimmed, as well as the last.")); + m_redtHelp.SetText(tszMessage); + return true; +} - switch (msg) { - case WM_INITDIALOG: - mir_snwprintf(tszMessage, L"%s\r\n%s\r\n\r\n%s\t\t%s\r\n%%miranda_path%%\t\t%s\r\n%%profile_path%%\t\t%s\r\n\t\t\t%s\r\n%%current_profile%%\t\t%s\r\n\t\t\t%s\r\n\r\n\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n%s\r\n%s\r\n%s\r\n%%miranda_path%%\t\t\t%s\r\n%%profile_path%%\t\t\t%s\r\n%%current_profile%%\t\t\t%s\r\n%%temp%%\t\t\t\t%s\r\n%%profile_path%%\\%%current_profile%%\t%s\r\n%%miranda_path%%\\plugins\\config\t%s\r\n' %%miranda_path%%\\\\\\\\ '\t\t%s\r\n\r\n%s", - TranslateT("Don't forget to click on Apply to save the changes. If you don't then the changes won't"), - TranslateT("be saved to the database, they will only be valid for this session."), - TranslateT("Variable string"), - TranslateT("What it expands to:"), - TranslateT("Expands to your Miranda path (e.g., c:\\program files\\miranda ng)."), - TranslateT("Expands to your profile path - the value found in mirandaboot.ini,"), - TranslateT("ProfileDir section (usually inside Miranda's folder)."), - TranslateT("Expands to your current profile name without the extenstion."), - TranslateT("(e.g., default if your your profile is default.dat)."), - TranslateT("Environment variables"), - TranslateT("The plugin can also expand environment variables; the variables are specified like in any other"), - TranslateT("program that can use environment variables, i.e., %%."), - TranslateT("Note: Environment variables are expanded before any Miranda variables. So if you have, for"), - TranslateT("example, %profile_path% defined as a system variable then it will be expanded to that value"), - TranslateT("instead of expanding to Miranda's profile path."), - TranslateT("Examples:"), - TranslateT("If the value for the ProfileDir inside mirandaboot.ini, ProfileDir section is '.\\profiles\\', current"), - TranslateT("profile is 'default.dat' and Miranda path is 'c:\\program files\\miranda ng\\' then:"), - TranslateT("will expand to 'c:\\program files\\miranda ng'"), - TranslateT("will expand to 'c:\\program files\\miranda ng\\profiles'"), - TranslateT("will expand to 'default'"), - TranslateT("will expand to the temp folder of the current user."), - TranslateT("will expand to 'c:\\program files\\miranda ng\\profiles\\default'"), - TranslateT("will expand to 'c:\\program files\\miranda ng\\plugins\\config'"), - TranslateT("will expand to 'c:\\program files\\miranda ng'"), - TranslateT("Notice that the spaces at the beginning and the end of the string are trimmed, as well as the last.")); - SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, tszMessage); - TranslateDialogDefault(hWnd); - break; - - case WM_CLOSE: - DestroyWindow(hWnd); - break; - - case WM_COMMAND: - if (LOWORD(wParam) == IDCLOSE) - DestroyWindow(hWnd); - break; +bool CHelpDialog::OnClose() +{ + if (pHelpDialog == this) + pHelpDialog = nullptr; + return true; +} + +void CHelpDialog::OnCloseClick(CCtrlBase*) +{ + Close(); +} + +COptDialog::COptDialog() : + CDlgBase(g_plugin, IDD_OPT_FOLDERS), + m_lbSections(this, IDC_FOLDERS_SECTIONS_LIST), + m_lbItems(this, IDC_FOLDERS_ITEMS_LIST), + m_edtPreview(this, IDC_PREVIEW_EDIT), + m_edtEdit(this, IDC_FOLDER_EDIT), + m_btnRefresh(this, IDC_REFRESH_BUTTON), + m_btnHelp(this, IDC_HELP_BUTTON) +{ + m_edtEdit.OnChange = Callback(this, &COptDialog::OnEditChange); + m_btnRefresh.OnClick = Callback(this, &COptDialog::OnRefreshClick); + m_btnHelp.OnClick = Callback(this, &COptDialog::OnHelpClick); + m_lbSections.OnSelChange = Callback(this, &COptDialog::OnSectionsSelChange); + m_lbItems.OnSelChange = Callback(this, &COptDialog::OnItemsSelChange); +} + +bool COptDialog::OnInitDialog() +{ + lastItem = nullptr; + bInitializing = 1; + LoadRegisteredFolderSections(); + bInitializing = 0; + return true; +} + +void COptDialog::OnEditChange(CCtrlBase*) +{ + RefreshPreview(); + if (!bInitializing) + NotifyChange(); +} + +void COptDialog::OnRefreshClick(CCtrlBase*) +{ + RefreshPreview(); +} + +void COptDialog::OnHelpClick(CCtrlBase*) +{ + if (pHelpDialog == nullptr) { + pHelpDialog = new CHelpDialog(); + pHelpDialog->Show(); + } + else { + SetForegroundWindow(pHelpDialog->GetHwnd()); + SetFocus(pHelpDialog->GetHwnd()); } +} - return 0; +void COptDialog::OnSectionsSelChange(CCtrlBase*) +{ + CheckForChanges(); + LoadRegisteredFolderItems(); + lastItem = nullptr; + SetEditText(L""); + RefreshPreview(); } -static INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +void COptDialog::OnItemsSelChange(CCtrlBase*) { - PFolderItem item; - - switch (msg) { - case WM_INITDIALOG: - lastItem = nullptr; - TranslateDialogDefault(hWnd); - bInitializing = 1; - LoadRegisteredFolderSections(hWnd); - bInitializing = 0; - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_FOLDER_EDIT: - switch (HIWORD(wParam)) { - case EN_CHANGE: - RefreshPreview(hWnd); - if (!bInitializing) - SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); //show the apply button. - } - break; - - case IDC_REFRESH_BUTTON: - RefreshPreview(hWnd); - break; - - case IDC_HELP_BUTTON: - ShowWindow(CreateDialog(g_plugin.getInst(), MAKEINTRESOURCE(IDD_VARIABLES_HELP), hWnd, DlgProcVariables), SW_SHOW); - break; - - case IDC_FOLDERS_SECTIONS_LIST: - switch (HIWORD(wParam)) { - case LBN_SELCHANGE: - CheckForChanges(hWnd); - LoadRegisteredFolderItems(hWnd); - lastItem = nullptr; - SetEditText(hWnd, L""); - RefreshPreview(hWnd); - } - break; - - case IDC_FOLDERS_ITEMS_LIST: - switch (HIWORD(wParam)) { - case LBN_SELCHANGE: - item = GetSelectedItem(hWnd); - if (item != nullptr) { - CheckForChanges(hWnd); - LoadItem(hWnd, item); - } - lastItem = item; - } - } - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case 0: - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - item = GetSelectedItem(hWnd); - if (item) { - SaveItem(hWnd, item, FALSE); - LoadItem(hWnd, item); - } - - for (auto &it : lstRegisteredFolders) - it->Save(); - CallPathChangedEvents(); - } - } - break; + PFolderItem item = GetSelectedItem(); + if (item != nullptr) { + CheckForChanges(); + LoadItem(item); } + lastItem = item; +} - return 0; +bool COptDialog::OnApply() +{ + PFolderItem item = GetSelectedItem(); + if (item) { + SaveItem(item, FALSE); + LoadItem(item); + } + + for (auto &it : lstRegisteredFolders) + it->Save(); + CallPathChangedEvents(); + return true; } int OnOptionsInitialize(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = {}; - odp.position = 100000000; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FOLDERS); odp.szTitle.a = LPGEN("Folders"); odp.szGroup.a = LPGEN("Customize"); odp.flags = ODPF_BOLDGROUPS; - odp.pfnDlgProc = DlgProcOpts; + odp.pDialog = new COptDialog; g_plugin.addOptions(wParam, &odp); return 0; } diff --git a/plugins/Folders/src/resource.h b/plugins/Folders/src/resource.h index e8ff0247cf..604c976b42 100644 --- a/plugins/Folders/src/resource.h +++ b/plugins/Folders/src/resource.h @@ -5,11 +5,8 @@ #define IDD_OPT_FOLDERS 101 #define IDD_VARIABLES_HELP 102 #define IDC_FOLDERS_ITEMS_LIST 1002 -#define IDC_FOLDERS_GROUPBOX 1003 -#define IDC_EDIT_FOLDER_GROUPBOX 1004 #define IDC_FOLDER_EDIT 1005 #define IDC_REFRESH_BUTTON 1008 -#define IDC_PREVIEW_GROUPBOX 1009 #define IDC_PREVIEW_EDIT 1010 #define IDC_HELP_BUTTON 1011 #define IDC_HELP_RICHEDIT 1012 diff --git a/plugins/Folders/src/stdafx.h b/plugins/Folders/src/stdafx.h index 778d44d73a..d728034d9e 100644 --- a/plugins/Folders/src/stdafx.h +++ b/plugins/Folders/src/stdafx.h @@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include #include @@ -64,4 +65,53 @@ struct CMPlugin : public PLUGIN extern OBJLIST lstRegisteredFolders; +class COptDialog : public CDlgBase +{ +private: + CCtrlListBox m_lbSections, m_lbItems; + CCtrlEdit m_edtPreview, m_edtEdit; + CCtrlButton m_btnRefresh, m_btnHelp; + +protected: + bool OnInitDialog() override; + bool OnApply() override; + + void OnEditChange(CCtrlBase*); + void OnRefreshClick(CCtrlBase*); + void OnHelpClick(CCtrlBase*); + void OnSectionsSelChange(CCtrlBase*); + void OnItemsSelChange(CCtrlBase*); + + PFolderItem GetSelectedItem(); + void GetEditText(wchar_t *buffer, int size); + void SetEditText(const wchar_t *buffer); + int ContainsSection(const wchar_t *section); + void LoadRegisteredFolderSections(); + void LoadRegisteredFolderItems(); + void RefreshPreview(); + void LoadItem(PFolderItem item); + void SaveItem(PFolderItem item, int bEnableApply); + int ChangesNotSaved(PFolderItem item); + void CheckForChanges(int bNeedConfirmation); + +public: + COptDialog(); +}; + +class CHelpDialog : public CDlgBase +{ +private: + CCtrlButton m_btnClose; + CCtrlRichEdit m_redtHelp; + +protected: + bool OnInitDialog() override; + bool OnClose() override; + + void OnCloseClick(CCtrlBase*); + +public: + CHelpDialog(); +}; + #endif //FOLDERS_COMMONHEADERS_H \ No newline at end of file -- cgit v1.2.3