diff options
author | George Hazan <ghazan@miranda.im> | 2022-06-09 21:26:35 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-06-09 21:30:54 +0300 |
commit | 856ff580fd9d776c331a6b525fa7d73a24d92f64 (patch) | |
tree | 42c4912b0b9c406c15783af3fc6e8c4857b09de1 /protocols/Weather/src | |
parent | 68c2dea66f3e368cc1437f7890c8e62907890fcd (diff) |
UserInfo -> UI classes
Diffstat (limited to 'protocols/Weather/src')
-rw-r--r-- | protocols/Weather/src/stdafx.h | 16 | ||||
-rw-r--r-- | protocols/Weather/src/weather_info.cpp | 63 | ||||
-rw-r--r-- | protocols/Weather/src/weather_userinfo.cpp | 141 |
3 files changed, 111 insertions, 109 deletions
diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index ea25f3f28c..c0cee1d62e 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -512,13 +512,27 @@ void removeWindow(MCONTACT hContact); // functions in weather_userinfo.c int UserInfoInit(WPARAM wParam, LPARAM lParam); -INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); #define WM_UPDATEDATA WM_USER + 2687 int BriefInfo(WPARAM wParam, LPARAM lParam); INT_PTR BriefInfoSvc(WPARAM wParam, LPARAM lParam); +/////////////////////////////////////////////////////////////////////////////// +// UI Classes + +class WeatherMyDetailsDlg : public CUserInfoPageDlg +{ + CCtrlButton btnReload; + +public: + WeatherMyDetailsDlg(); + + bool OnInitDialog() override; + + void onClick_Reload(CCtrlButton *); +}; + //============ Plugin Class ============ struct CMPlugin : public PLUGIN<CMPlugin> diff --git a/protocols/Weather/src/weather_info.cpp b/protocols/Weather/src/weather_info.cpp index d9d76afe7f..5e4c79fb4a 100644 --- a/protocols/Weather/src/weather_info.cpp +++ b/protocols/Weather/src/weather_info.cpp @@ -74,12 +74,12 @@ static void INIInfo(HWND hwndDlg) SetDlgItemText(hwndDlg, IDC_MEMUSED, _ltow((long)memused, str, 10)); } -static const struct tag_Columns +struct { const wchar_t *name; unsigned size; } -columns[] = +static columns[] = { { LPGENW("Name"), 70 }, { LPGENW("Author"), 100 }, @@ -90,44 +90,37 @@ columns[] = { LPGENW("File Name"), 150 }, }; - -INT_PTR CALLBACK DlgProcINIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM) +WeatherMyDetailsDlg::WeatherMyDetailsDlg() : + CUserInfoPageDlg(g_plugin, IDD_INFO), + btnReload(this, IDC_RELOADINI) { - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - HWND hIniList = GetDlgItem(hwndDlg, IDC_INFOLIST); - LVCOLUMN lvc = {}; - - lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; - lvc.fmt = LVCFMT_LEFT; - for (int i = 0; i < 7; ++i) { - lvc.iSubItem = i; - lvc.pszText = TranslateW(columns[i].name); - lvc.cx = columns[i].size; - ListView_InsertColumn(hIniList, i, &lvc); - } - INIInfo(hwndDlg); - } - - break; - - case WM_DESTROY: - break; + btnReload.OnClick = Callback(this, &WeatherMyDetailsDlg::onClick_Reload); +} - case WM_COMMAND: - if (HIWORD(wParam) == BN_CLICKED && - LOWORD(wParam) == IDC_RELOADINI) { - DestroyWIList(); - LoadWIData(true); - INIInfo(hwndDlg); - } - break; +bool WeatherMyDetailsDlg::OnInitDialog() +{ + HWND hIniList = GetDlgItem(m_hwnd, IDC_INFOLIST); + + LVCOLUMN lvc = {}; + lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; + lvc.fmt = LVCFMT_LEFT; + for (auto &it : columns) { + lvc.iSubItem = int(&it - columns); + lvc.pszText = TranslateW(it.name); + lvc.cx = it.size; + ListView_InsertColumn(hIniList, lvc.iSubItem, &lvc); } - return 0; + + INIInfo(m_hwnd); + return true; } +void WeatherMyDetailsDlg::onClick_Reload(CCtrlButton*) +{ + DestroyWIList(); + LoadWIData(true); + INIInfo(m_hwnd); +} // get the info of individual ini file // pszSvc = the internal name of the service to get the data diff --git a/protocols/Weather/src/weather_userinfo.cpp b/protocols/Weather/src/weather_userinfo.cpp index 1008a6c44e..f17f797f73 100644 --- a/protocols/Weather/src/weather_userinfo.cpp +++ b/protocols/Weather/src/weather_userinfo.cpp @@ -239,98 +239,93 @@ static INT_PTR CALLBACK DlgProcMoreData(HWND hwndDlg, UINT msg, WPARAM wParam, L return FALSE; } -// dialog process for the weather tab under user info -// lParam = current contact -static INT_PTR CALLBACK DlgProcUIPage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////////////// +// User info dialog + +class WeatherUserInfoDlg : public CUserInfoPageDlg { - WEATHERINFO w; - wchar_t str[MAX_TEXT_SIZE]; + CCtrlButton btnDetail; + +public: + WeatherUserInfoDlg() : + CUserInfoPageDlg(g_plugin, IDD_USERINFO), + btnDetail(this, IDC_MOREDETAIL) + { + } + + bool OnInitDialog() override + { + SendDlgItemMessage(m_hwnd, IDC_MOREDETAIL, BUTTONSETASFLATBTN, TRUE, 0); - MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SendDlgItemMessage(hwndDlg, IDC_MOREDETAIL, BUTTONSETASFLATBTN, TRUE, 0); - // save the contact handle for later use - hContact = lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)hContact); // load weather info for the contact - w = LoadWeatherInfo(lParam); - SetDlgItemText(hwndDlg, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str)); + wchar_t str[MAX_TEXT_SIZE]; + WEATHERINFO w = LoadWeatherInfo(m_hContact); + SetDlgItemText(m_hwnd, IDC_INFO1, GetDisplay(&w, TranslateT("Current condition for %n"), str)); + + SendDlgItemMessage(m_hwnd, IDC_INFOICON, STM_SETICON, (WPARAM)GetStatusIconBig(m_hContact), 0); + + // bold and enlarge the current condition + LOGFONT lf; + HFONT hNormalFont = (HFONT)SendDlgItemMessage(m_hwnd, IDC_INFO2, WM_GETFONT, 0, 0); + GetObject(hNormalFont, sizeof(lf), &lf); + lf.lfWeight = FW_BOLD; + lf.lfWidth = 7; + lf.lfHeight = 15; + SendDlgItemMessage(m_hwnd, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0); - SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, (WPARAM)GetStatusIconBig(hContact), 0); - { - // bold and enlarge the current condition - LOGFONT lf; - HFONT hNormalFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0); - GetObject(hNormalFont, sizeof(lf), &lf); - lf.lfWeight = FW_BOLD; - lf.lfWidth = 7; - lf.lfHeight = 15; - SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0); - } // set the text for displaying other current weather conditions data GetDisplay(&w, L"%c %t", str); - SetDlgItemText(hwndDlg, IDC_INFO2, str); - SetDlgItemText(hwndDlg, IDC_INFO3, w.feel); - SetDlgItemText(hwndDlg, IDC_INFO4, w.pressure); + SetDlgItemText(m_hwnd, IDC_INFO2, str); + SetDlgItemText(m_hwnd, IDC_INFO3, w.feel); + SetDlgItemText(m_hwnd, IDC_INFO4, w.pressure); GetDisplay(&w, L"%i %w", str); - SetDlgItemText(hwndDlg, IDC_INFO5, str); - SetDlgItemText(hwndDlg, IDC_INFO6, w.dewpoint); - SetDlgItemText(hwndDlg, IDC_INFO7, w.sunrise); - SetDlgItemText(hwndDlg, IDC_INFO8, w.sunset); - SetDlgItemText(hwndDlg, IDC_INFO9, w.high); - SetDlgItemText(hwndDlg, IDC_INFO10, w.low); + SetDlgItemText(m_hwnd, IDC_INFO5, str); + SetDlgItemText(m_hwnd, IDC_INFO6, w.dewpoint); + SetDlgItemText(m_hwnd, IDC_INFO7, w.sunrise); + SetDlgItemText(m_hwnd, IDC_INFO8, w.sunset); + SetDlgItemText(m_hwnd, IDC_INFO9, w.high); + SetDlgItemText(m_hwnd, IDC_INFO10, w.low); GetDisplay(&w, TranslateT("Last update on: %u"), str); - SetDlgItemText(hwndDlg, IDC_INFO11, str); - SetDlgItemText(hwndDlg, IDC_INFO12, w.humid); - SetDlgItemText(hwndDlg, IDC_INFO13, w.vis); - break; + SetDlgItemText(m_hwnd, IDC_INFO11, str); + SetDlgItemText(m_hwnd, IDC_INFO12, w.humid); + SetDlgItemText(m_hwnd, IDC_INFO13, w.vis); + return true; + } - case WM_DESTROY: - DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_INFOICON, STM_SETICON, 0, 0)); - DeleteObject((HFONT)SendDlgItemMessage(hwndDlg, IDC_INFO2, WM_GETFONT, 0, 0)); - break; + void OnDestroy() override + { + DestroyIcon((HICON)SendDlgItemMessage(m_hwnd, IDC_INFOICON, STM_SETICON, 0, 0)); + DeleteObject((HFONT)SendDlgItemMessage(m_hwnd, IDC_INFO2, WM_GETFONT, 0, 0)); + } - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_MOREDETAIL: - HWND hMoreDataDlg = WindowList_Find(hDataWindowList, hContact); - if (hMoreDataDlg == nullptr) - hMoreDataDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_BRIEF), nullptr, DlgProcMoreData, hContact); - else { - SetForegroundWindow(hMoreDataDlg); - SetFocus(hMoreDataDlg); - } - ShowWindow(GetDlgItem(hMoreDataDlg, IDC_MTEXT), 0); - ShowWindow(GetDlgItem(hMoreDataDlg, IDC_DATALIST), 1); + void onClick_Detail(CCtrlButton *) + { + HWND hMoreDataDlg = WindowList_Find(hDataWindowList, m_hContact); + if (hMoreDataDlg == nullptr) + hMoreDataDlg = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_BRIEF), nullptr, DlgProcMoreData, m_hContact); + else { + SetForegroundWindow(hMoreDataDlg); + SetFocus(hMoreDataDlg); } - break; + ShowWindow(GetDlgItem(hMoreDataDlg, IDC_MTEXT), 0); + ShowWindow(GetDlgItem(hMoreDataDlg, IDC_DATALIST), 1); } - return 0; -} +}; -//============ CONTACT INFORMATION ============ -// -// initialize user info -// lParam = current contact int UserInfoInit(WPARAM wParam, LPARAM hContact) { - OPTIONSDIALOGPAGE odp = {}; - odp.position = 100000000; - odp.szTitle.a = MODULENAME; + USERINFOPAGE uip = {}; + uip.szTitle.a = MODULENAME; + uip.position = 100000000; if (hContact == 0) { - odp.pszTemplate = MAKEINTRESOURCEA(IDD_INFO); - odp.pfnDlgProc = DlgProcINIPage; - g_plugin.addUserInfo(wParam, &odp); + uip.pDialog = new WeatherMyDetailsDlg(); + g_plugin.addUserInfo(wParam, &uip); } else if (IsMyContact(hContact)) { // check if it is a weather contact - // register the contact info page - odp.pszTemplate = MAKEINTRESOURCEA(IDD_USERINFO); - odp.pfnDlgProc = DlgProcUIPage; - odp.flags = ODPF_BOLDGROUPS; - g_plugin.addUserInfo(wParam, &odp); + uip.pDialog = new WeatherUserInfoDlg(); + uip.flags = ODPF_BOLDGROUPS; + g_plugin.addUserInfo(wParam, &uip); } return 0; } |