diff options
author | George Hazan <ghazan@miranda.im> | 2017-12-07 16:10:49 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-12-07 16:10:49 +0300 |
commit | ed441098d590945ca77d712e67067f8b5e35fa8e (patch) | |
tree | 63a95e018feb3dd0e8984beb6107cdc69a78242d /src/mir_app | |
parent | 7de7e2ef57ff8eb0491a4b9ecb93aa15936de13c (diff) |
fixes #1056 (Help > About page will only show once per client restart)
Diffstat (limited to 'src/mir_app')
-rw-r--r-- | src/mir_app/res/resource.rc | 1 | ||||
-rw-r--r-- | src/mir_app/src/help.cpp | 177 |
2 files changed, 82 insertions, 96 deletions
diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index f6c1a544ea..34acde8b42 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -1097,6 +1097,7 @@ END #endif // APSTUDIO_INVOKED
+IDR_CREDITS TEXT "../../docs/contributors.txt"
/////////////////////////////////////////////////////////////////////////////
//
diff --git a/src/mir_app/src/help.cpp b/src/mir_app/src/help.cpp index 79ea444757..25bf0aee24 100644 --- a/src/mir_app/src/help.cpp +++ b/src/mir_app/src/help.cpp @@ -25,108 +25,95 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "resource.h" -HWND hAboutDlg = nullptr; +static class CAboutDlg *pAboutDialog; -#define STR_VERSION_FORMAT L"Miranda NG\nv%S" - -static INT_PTR CALLBACK DlgProcAbout(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +class CAboutDlg : public CDlgBase { - static int iState = 0; - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_DEVS, _T(LEGAL_COPYRIGHT)); - { - char productVersion[56]; - Miranda_GetVersionText(productVersion, _countof(productVersion)); - - wchar_t str[64]; - mir_snwprintf(str, STR_VERSION_FORMAT, productVersion); - SetDlgItemText(hwndDlg, IDC_HEADERBAR, str); - } - ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_HIDE); - { - HRSRC hResInfo = FindResource(g_hInst, MAKEINTRESOURCE(IDR_CREDITS), L"TEXT"); - DWORD ResSize = SizeofResource(g_hInst, hResInfo); - HGLOBAL hRes = LoadResource(g_hInst, hResInfo); - char *pszMsg = (char*)LockResource(hRes); - if (pszMsg) { - char *pszMsgt = (char*)alloca(ResSize + 1); - memcpy(pszMsgt, pszMsg, ResSize); pszMsgt[ResSize] = 0; - - wchar_t *ptszMsg; - if (ResSize >= 3 && pszMsgt[0] == '\xef' && pszMsgt[1] == '\xbb' && pszMsgt[2] == '\xbf') - ptszMsg = Utf8DecodeW(pszMsgt + 3); - else - ptszMsg = mir_a2u_cp(pszMsgt, 1252); - - SetDlgItemText(hwndDlg, IDC_CREDITSFILE, ptszMsg); - UnlockResource(pszMsg); - mir_free(ptszMsg); - } - FreeResource(hRes); - } - Window_SetSkinIcon_IcoLib(hwndDlg, SKINICON_OTHER_MIRANDA); - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDOK: - case IDCANCEL: - DestroyWindow(hwndDlg); - return TRUE; - - case IDC_CONTRIBLINK: - if (iState) { - iState = 0; - SetDlgItemText(hwndDlg, IDC_CONTRIBLINK, TranslateT("Credits >")); - ShowWindow(GetDlgItem(hwndDlg, IDC_DEVS), SW_SHOW); - ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_HIDE); - } - else { - iState = 1; - SetDlgItemText(hwndDlg, IDC_CONTRIBLINK, TranslateT("< Copyright")); - ShowWindow(GetDlgItem(hwndDlg, IDC_DEVS), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_CREDITSFILE), SW_SHOW); - } - break; + int m_iState = 0; + + CCtrlBase ctrlHeaderBar, ctrlDevelopers, ctrlCredits, ctrlWhiteRect; + CCtrlButton btnLink; + +public: + CAboutDlg() : + CDlgBase(g_hInst, IDD_ABOUT), + btnLink(this, IDC_CONTRIBLINK), + ctrlCredits(this, IDC_CREDITSFILE), + ctrlHeaderBar(this, IDC_HEADERBAR), + ctrlWhiteRect(this, IDC_WHITERECT), + ctrlDevelopers(this, IDC_DEVS) + { + btnLink.OnClick = Callback(this, &CAboutDlg::onClick); + + ctrlCredits.UseSystemColors(); + ctrlWhiteRect.UseSystemColors(); + ctrlDevelopers.UseSystemColors(); + } + + virtual void OnInitDialog() override + { + ctrlDevelopers.SetText(_T(LEGAL_COPYRIGHT)); + + char productVersion[56]; + Miranda_GetVersionText(productVersion, _countof(productVersion)); + ctrlHeaderBar.SetText(CMStringW(FORMAT, L"Miranda NG\nv%S", productVersion)); + + HRSRC hResInfo = FindResource(g_hInst, MAKEINTRESOURCE(IDR_CREDITS), L"TEXT"); + DWORD ResSize = SizeofResource(g_hInst, hResInfo); + HGLOBAL hRes = LoadResource(g_hInst, hResInfo); + char *pszMsg = (char*)LockResource(hRes); + if (pszMsg) { + char *pszMsgt = (char*)alloca(ResSize + 1); + memcpy(pszMsgt, pszMsg, ResSize); pszMsgt[ResSize] = 0; + + ptrW ptszMsg; + if (ResSize >= 3 && pszMsgt[0] == '\xef' && pszMsgt[1] == '\xbb' && pszMsgt[2] == '\xbf') + ptszMsg = Utf8DecodeW(pszMsgt + 3); + else + ptszMsg = mir_a2u_cp(pszMsgt, 1252); + ctrlCredits.SetText(ptszMsg); + + UnlockResource(pszMsg); } - break; - - case WM_CTLCOLOREDIT: - case WM_CTLCOLORSTATIC: - switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { - case IDC_WHITERECT: - case IDC_CREDITSFILE: - case IDC_DEVS: - SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); - break; - - default: - return FALSE; + FreeResource(hRes); + ctrlCredits.Hide(); + + Window_SetSkinIcon_IcoLib(m_hwnd, SKINICON_OTHER_MIRANDA); + } + + virtual void OnDestroy() override + { + pAboutDialog = nullptr; + Window_FreeIcon_IcoLib(m_hwnd); + } + + void onClick(CCtrlButton*) + { + if (m_iState) { + btnLink.SetText(TranslateT("Credits >")); + ctrlDevelopers.Show(); + ctrlCredits.Hide(); } - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); - - case WM_DESTROY: - Window_FreeIcon_IcoLib(hwndDlg); - { - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_VERSION, WM_GETFONT, 0, 0); - SendDlgItemMessage(hwndDlg, IDC_VERSION, WM_SETFONT, SendDlgItemMessage(hwndDlg, IDOK, WM_GETFONT, 0, 0), 0); - DeleteObject(hFont); + else { + btnLink.SetText(TranslateT("< Copyright")); + ctrlDevelopers.Hide(); + ctrlCredits.Show(); } - break; + m_iState = !m_iState; } - return FALSE; -} +}; static INT_PTR AboutCommand(WPARAM wParam, LPARAM) { - if (hAboutDlg) { - SetForegroundWindow(hAboutDlg); - SetFocus(hAboutDlg); + if (pAboutDialog) { + SetForegroundWindow(pAboutDialog->GetHwnd()); + SetFocus(pAboutDialog->GetHwnd()); + } + else { + pAboutDialog = new CAboutDlg(); + pAboutDialog->SetParent((HWND)wParam); + pAboutDialog->Show(); } - else hAboutDlg = CreateDialog(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), (HWND)wParam, DlgProcAbout); return 0; } @@ -150,10 +137,8 @@ static INT_PTR BugCommand(WPARAM, LPARAM) int ShutdownHelpModule(WPARAM, LPARAM) { - if (hAboutDlg) { - DestroyWindow(hAboutDlg); - hAboutDlg = nullptr; - } + if (pAboutDialog) + pAboutDialog->Close(); return 0; } |