diff options
Diffstat (limited to 'protocols/Weather/src/weather_popup.cpp')
-rw-r--r-- | protocols/Weather/src/weather_popup.cpp | 475 |
1 files changed, 243 insertions, 232 deletions
diff --git a/protocols/Weather/src/weather_popup.cpp b/protocols/Weather/src/weather_popup.cpp index 992db0a69a..b9f938e41d 100644 --- a/protocols/Weather/src/weather_popup.cpp +++ b/protocols/Weather/src/weather_popup.cpp @@ -27,37 +27,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. // variables for weather_popup.c static MCONTACT hPopupContact; -//============ SHOW WEATHER POPUPS ============ - -//============ WEATHER ERROR POPUPS ============ +///////////////////////////////////////////////////////////////////////////////////////// +// wrapper function for displaying weather warning popup by triggering an event (threaded) +// lpzText = error text +// kind = display type (see m_popup.h) -// display weather error or notices (not threaded) -// wParam = error text -// lParam = display type -// Type can either be SM_WARNING, SM_NOTIFY, or SM_WEATHERALERT -int WeatherError(WPARAM wParam, LPARAM lParam) +int CWeatherProto::WPShowMessage(const wchar_t *lpzText, int kind) { - if (!g_plugin.bPopups) + if (!m_bPopups) return 0; - wchar_t* tszMsg = (wchar_t*)wParam; - - if ((uint32_t)lParam == SM_WARNING) - PUShowMessageW(tszMsg, SM_WARNING); - else if ((uint32_t)lParam == SM_NOTIFY) - PUShowMessageW(tszMsg, SM_NOTIFY); - else if ((uint32_t)lParam == SM_WEATHERALERT) { + if (kind == SM_WARNING) + PUShowMessageW(lpzText, SM_WARNING); + else if (kind == SM_NOTIFY) + PUShowMessageW(lpzText, SM_NOTIFY); + else if (kind == SM_WEATHERALERT) { POPUPDATAW ppd; wchar_t str1[512], str2[512]; // get the 2 strings - wcsncpy(str1, tszMsg, _countof(str1) - 1); - wcsncpy(str2, tszMsg, _countof(str2) - 1); + wcsncpy(str1, lpzText, _countof(str1) - 1); + wcsncpy(str2, lpzText, _countof(str2) - 1); wchar_t *chop = wcschr(str1, 255); if (chop != nullptr) *chop = '\0'; else str1[0] = 0; + chop = wcschr(str2, 255); if (chop != nullptr) wcsncpy(str2, chop + 1, _countof(str2) - 1); @@ -77,38 +73,28 @@ int WeatherError(WPARAM wParam, LPARAM lParam) return 0; } -// wrapper function for displaying weather warning popup by triggering an event -// (threaded) -// lpzText = error text -// kind = display type (see m_popup.h) -int WPShowMessage(const wchar_t* lpzText, uint16_t kind) -{ - NotifyEventHooks(hHookWeatherError, (WPARAM)lpzText, (LPARAM)kind); - return 0; -} - -//============ WEATHER POPUP PROCESSES ============ - +///////////////////////////////////////////////////////////////////////////////////////// // popup dialog pocess // for selecting actions when click on the popup window // use for displaying contact menu + static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - uint32_t ID = 0; - MCONTACT hContact; - hContact = PUGetContact(hWnd); + uint32_t ID; + MCONTACT hContact = PUGetContact(hWnd); + auto *ppro = (CWeatherProto*)Proto_GetContactInstance(hContact); switch (message) { case WM_COMMAND: - ID = opt.LeftClickAction; + ID = (ppro) ? ppro->opt.LeftClickAction : 0; if (ID != IDM_M7) PUDeletePopup(hWnd); - SendMessage(hPopupWindow, ID, hContact, 0); + SendMessage(hPopupWindow, ID, hContact, LPARAM(ppro)); return TRUE; case WM_CONTEXTMENU: - ID = opt.RightClickAction; + ID = (ppro) ? ppro->opt.RightClickAction : IDM_M7; if (ID != IDM_M7) PUDeletePopup(hWnd); - SendMessage(hPopupWindow, ID, hContact, 0); + SendMessage(hPopupWindow, ID, hContact, LPARAM(ppro)); return TRUE; case UM_FREEPLUGINDATA: @@ -119,21 +105,23 @@ static LRESULT CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPA return DefWindowProc(hWnd, message, wParam, lParam); } +///////////////////////////////////////////////////////////////////////////////////////// // display weather popups // wParam = the contact to display popup // lParam = whether the weather data is changed or not -int WeatherPopup(WPARAM hContact, LPARAM lParam) + +int CWeatherProto::WeatherPopup(MCONTACT hContact, bool bAlways) { // determine if the popup should display or not - if (g_plugin.bPopups && opt.UpdatePopup && (!opt.PopupOnChange || (BOOL)lParam) && !g_plugin.getByte(hContact, "DPopUp")) { + if (m_bPopups && opt.UpdatePopup && (!opt.PopupOnChange || bAlways) && !getByte(hContact, "DPopUp")) { WEATHERINFO winfo = LoadWeatherInfo(hContact); // setup the popup POPUPDATAW ppd; ppd.lchContact = hContact; ppd.PluginData = ppd.lchIcon = GetStatusIcon(winfo.hContact); - GetDisplay(&winfo, GetTextValue('P'), ppd.lpwzContactName); - GetDisplay(&winfo, GetTextValue('p'), ppd.lpwzText); + wcsncpy_s(ppd.lpwzContactName, GetDisplay(&winfo, GetTextValue('P')), _TRUNCATE); + wcsncpy_s(ppd.lpwzText, GetDisplay(&winfo, GetTextValue('p')), _TRUNCATE); ppd.PluginWindowProc = PopupDlgProc; ppd.colorBack = (opt.UseWinColors) ? GetSysColor(COLOR_BTNFACE) : opt.BGColour; ppd.colorText = (opt.UseWinColors) ? GetSysColor(COLOR_WINDOWTEXT) : opt.TextColour; @@ -143,24 +131,27 @@ int WeatherPopup(WPARAM hContact, LPARAM lParam) return 0; } - +///////////////////////////////////////////////////////////////////////////////////////// // process for the popup window // containing the code for popup actions -LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + +LRESULT CALLBACK CWeatherProto::PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { POINT pt; HMENU hMenu; + auto *ppro = (CWeatherProto *)lParam; + switch (uMsg) { case IDM_M2: // brief info - BriefInfo(wParam, 0); + ppro->BriefInfo(wParam, 0); break; case IDM_M3: // read complete forecast - LoadForecast(wParam, 0); + ppro->LoadForecast(wParam, 0); break; case IDM_M4: // display weather map - WeatherMap(wParam, 0); + ppro->WeatherMap(wParam, 0); break; case IDM_M5: // open history window @@ -168,7 +159,7 @@ LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam break; case IDM_M6: // open external log - ViewLog(wParam, 0); + ppro->ViewLog(wParam, 0); break; case IDM_M7: // display contact menu @@ -197,7 +188,7 @@ LRESULT CALLBACK PopupWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam return DefWindowProc(hWnd, uMsg, wParam, lParam);//FALSE; } -//============ POPUP OPTIONS ============ +///////////////////////////////////////////////////////////////////////////////////////// struct { @@ -218,225 +209,245 @@ static void SelectMenuItem(HMENU hMenu, int Check) CheckMenuItem(hMenu, i, MF_BYPOSITION | ((int)GetMenuItemID(hMenu, i) == Check) * 8); } -// temporary read the current option to memory -// but does not write to the database -void ReadPopupOpt(HWND hdlg) +class CPopupOptsDlg : public CWeatherDlgBase { - wchar_t str[512]; - - // popup colour - opt.TextColour = SendDlgItemMessage(hdlg, IDC_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0); - opt.BGColour = SendDlgItemMessage(hdlg, IDC_BGCOLOUR, CPM_GETCOLOUR, 0, 0); - - // get delay time - GetDlgItemText(hdlg, IDC_DELAY, str, _countof(str)); - int num = _wtoi(str); - opt.pDelay = num; - - // other options - opt.UseWinColors = (uint8_t)IsDlgButtonChecked(hdlg, IDC_USEWINCOLORS); - opt.UpdatePopup = (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP1); - opt.AlertPopup = (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP2); - opt.PopupOnChange = (uint8_t)IsDlgButtonChecked(hdlg, IDC_CH); - opt.ShowWarnings = (uint8_t)IsDlgButtonChecked(hdlg, IDC_W); -} + CCtrlEdit edtDelay; + CCtrlCheck chkUseWin; + CCtrlButton btnLeft, btnRight, btnPD1, btnPD2, btnPD3, btnPdef, btnVars, btnPreview; + + // temporary read the current option to memory + // but does not write to the database + void ReadPopupOpt(HWND hdlg) + { + wchar_t str[512]; + auto &opt = m_proto->opt; -// copied and modified from NewStatusNotify -INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - int ID; - HMENU hMenu, hMenu1; - RECT pos; - HWND button; - MCONTACT hContact; + // popup colour + opt.TextColour = SendDlgItemMessage(hdlg, IDC_TEXTCOLOUR, CPM_GETCOLOUR, 0, 0); + opt.BGColour = SendDlgItemMessage(hdlg, IDC_BGCOLOUR, CPM_GETCOLOUR, 0, 0); + + // get delay time + GetDlgItemText(hdlg, IDC_DELAY, str, _countof(str)); + int num = _wtoi(str); + opt.pDelay = num; - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hdlg); - SaveOptions(); + // other options + opt.UseWinColors = chkUseWin.IsChecked(); + opt.UpdatePopup = (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP1); + opt.AlertPopup = (uint8_t)IsDlgButtonChecked(hdlg, IDC_POP2); + opt.PopupOnChange = (uint8_t)IsDlgButtonChecked(hdlg, IDC_CH); + opt.ShowWarnings = (uint8_t)IsDlgButtonChecked(hdlg, IDC_W); + } + +public: + CPopupOptsDlg(CWeatherProto *ppro) : + CWeatherDlgBase(ppro, IDD_POPUP), + btnPD1(this, IDC_PD1), + btnPD2(this, IDC_PD2), + btnPD3(this, IDC_PD3), + btnPdef(this, IDC_PDEF), + btnVars(this, IDC_VAR3), + btnLeft(this, IDC_LeftClick), + btnRight(this, IDC_RightClick), + btnPreview(this, IDC_PREVIEW), + edtDelay(this, IDC_DELAY), + chkUseWin(this, IDC_USEWINCOLORS) + { + edtDelay.OnChange = Callback(this, &CPopupOptsDlg::onChanged_Delay); + chkUseWin.OnChange = Callback(this, &CPopupOptsDlg::onChanged_UseWin); + + btnPD1.OnClick = Callback(this, &CPopupOptsDlg::onClick_PD1); + btnPD2.OnClick = Callback(this, &CPopupOptsDlg::onClick_PD2); + btnPD3.OnClick = Callback(this, &CPopupOptsDlg::onChanged_Delay); + btnPdef.OnClick = Callback(this, &CPopupOptsDlg::onClick_Pdef); + btnVars.OnClick = Callback(this, &CPopupOptsDlg::onClick_Vars); + btnLeft.OnClick = Callback(this, &CPopupOptsDlg::onClick_Left); + btnRight.OnClick = Callback(this, &CPopupOptsDlg::onClick_Right); + btnPreview.OnClick = Callback(this, &CPopupOptsDlg::onClick_Preview); + } + + bool OnInitDialog() override + { + m_proto->SaveOptions(); // click actions - hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); - hMenu1 = GetSubMenu(hMenu, 0); + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); + HMENU hMenu1 = GetSubMenu(hMenu, 0); wchar_t str[512]; - GetMenuString(hMenu1, opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND); - SetDlgItemText(hdlg, IDC_LeftClick, TranslateW(str)); - GetMenuString(hMenu1, opt.RightClickAction, str, _countof(str), MF_BYCOMMAND); - SetDlgItemText(hdlg, IDC_RightClick, TranslateW(str)); + auto &opt = m_proto->opt; + GetMenuStringW(hMenu1, opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND); + SetDlgItemTextW(m_hwnd, IDC_LeftClick, TranslateW(str)); + GetMenuStringW(hMenu1, opt.RightClickAction, str, _countof(str), MF_BYCOMMAND); + SetDlgItemTextW(m_hwnd, IDC_RightClick, TranslateW(str)); DestroyMenu(hMenu); // other options - CheckDlgButton(hdlg, IDC_E, g_plugin.bPopups ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_POP2, opt.AlertPopup ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_POP1, opt.UpdatePopup ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CH, opt.PopupOnChange ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_W, opt.ShowWarnings ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_POP2, opt.AlertPopup ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_POP1, opt.UpdatePopup ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_CH, opt.PopupOnChange ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_W, opt.ShowWarnings ? BST_CHECKED : BST_UNCHECKED); for (auto &it : controls) - SetDlgItemText(hdlg, it.id, GetTextValue(it.c)); + SetDlgItemText(m_hwnd, it.id, m_proto->GetTextValue(it.c)); // setting popup delay option _ltow(opt.pDelay, str, 10); - SetDlgItemText(hdlg, IDC_DELAY, str); + SetDlgItemText(m_hwnd, IDC_DELAY, str); if (opt.pDelay == -1) - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD2); + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD2); else if (opt.pDelay == 0) - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD1); + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD1); else - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3); + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD3); // Colours. First step is configuring the colours. - SendDlgItemMessage(hdlg, IDC_BGCOLOUR, CPM_SETCOLOUR, 0, opt.BGColour); - SendDlgItemMessage(hdlg, IDC_TEXTCOLOUR, CPM_SETCOLOUR, 0, opt.TextColour); + SendDlgItemMessage(m_hwnd, IDC_BGCOLOUR, CPM_SETCOLOUR, 0, opt.BGColour); + SendDlgItemMessage(m_hwnd, IDC_TEXTCOLOUR, CPM_SETCOLOUR, 0, opt.TextColour); // Second step is disabling them if we want to use default Windows ones. - CheckDlgButton(hdlg, IDC_USEWINCOLORS, opt.UseWinColors ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOUR), !opt.UseWinColors); - EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOUR), !opt.UseWinColors); + chkUseWin.SetState(opt.UseWinColors); // buttons - SendDlgItemMessage(hdlg, IDC_PREVIEW, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hdlg, IDC_PDEF, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hdlg, IDC_LeftClick, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hdlg, IDC_RightClick, BUTTONSETASFLATBTN, TRUE, 0); - SendDlgItemMessage(hdlg, IDC_VAR3, BUTTONSETASFLATBTN, TRUE, 0); - return TRUE; + SendDlgItemMessage(m_hwnd, IDC_PREVIEW, BUTTONSETASFLATBTN, TRUE, 0); + SendDlgItemMessage(m_hwnd, IDC_PDEF, BUTTONSETASFLATBTN, TRUE, 0); + SendDlgItemMessage(m_hwnd, IDC_LeftClick, BUTTONSETASFLATBTN, TRUE, 0); + SendDlgItemMessage(m_hwnd, IDC_RightClick, BUTTONSETASFLATBTN, TRUE, 0); + SendDlgItemMessage(m_hwnd, IDC_VAR3, BUTTONSETASFLATBTN, TRUE, 0); + return true; + } - case WM_COMMAND: - // enable the "apply" button - if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - if (!((LOWORD(wParam) == IDC_UPDATE || LOWORD(wParam) == IDC_DEGREE) && - (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - //These are simple clicks: we don't save, but we tell the Options Page to enable the "Apply" button. - switch (LOWORD(wParam)) { - case IDC_BGCOLOUR: //Fall through - case IDC_TEXTCOLOUR: - // select new colors - if (HIWORD(wParam) == CPN_COLOURCHANGED) - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; + bool OnApply() override + { + ReadPopupOpt(m_hwnd); + + wchar_t textstr[MAX_TEXT_SIZE]; + for (auto &it : controls) { + GetDlgItemText(m_hwnd, it.id, textstr, _countof(textstr)); + if (!mir_wstrcmpi(textstr, GetDefaultText(it.c))) + m_proto->delSetting(it.setting); + else + m_proto->setWString(it.setting, textstr); + } - case IDC_USEWINCOLORS: - // use window color - enable/disable color selection controls - EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOUR), !(opt.UseWinColors)); - EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOUR), !(opt.UseWinColors)); - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; + // save the options, and update main menu + m_proto->SaveOptions(); + return true; + } - case IDC_E: - case IDC_CH: - SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - break; + void onChanged_UseWin(CCtrlCheck *pCheck) + { + // use window color - enable/disable color selection controls + bool bEnable = !pCheck->IsChecked(); + EnableWindow(GetDlgItem(m_hwnd, IDC_BGCOLOUR), bEnable); + EnableWindow(GetDlgItem(m_hwnd, IDC_TEXTCOLOUR), bEnable); + } - case IDC_RightClick: - // right click action selection menu - button = GetDlgItem(hdlg, IDC_RightClick); - GetWindowRect(button, &pos); - - hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); - hMenu1 = GetSubMenu(hMenu, 0); - TranslateMenu(hMenu1); - SelectMenuItem(hMenu1, opt.RightClickAction); - ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, nullptr); - if (ID) - opt.RightClickAction = ID; - DestroyMenu(hMenu); - - hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); - hMenu1 = GetSubMenu(hMenu, 0); - GetMenuString(hMenu1, opt.RightClickAction, str, _countof(str), MF_BYCOMMAND); - SetDlgItemText(hdlg, IDC_RightClick, TranslateW(str)); - DestroyMenu(hMenu); - break; + void onClick_Right(CCtrlButton *) + { + // right click action selection menu + RECT pos; + GetWindowRect(GetDlgItem(m_hwnd, IDC_RightClick), &pos); + + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); + HMENU hMenu1 = GetSubMenu(hMenu, 0); + TranslateMenu(hMenu1); + SelectMenuItem(hMenu1, m_proto->opt.RightClickAction); + int ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr); + if (ID) + m_proto->opt.RightClickAction = ID; + DestroyMenu(hMenu); - case IDC_LeftClick: - // left click action selection menu - button = GetDlgItem(hdlg, IDC_LeftClick); - GetWindowRect(button, &pos); - - hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); - hMenu1 = GetSubMenu(hMenu, 0); - TranslateMenu(hMenu1); - SelectMenuItem(hMenu1, opt.LeftClickAction); - ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, nullptr); - if (ID) opt.LeftClickAction = ID; - DestroyMenu(hMenu); - - hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); - hMenu1 = GetSubMenu(hMenu, 0); - GetMenuString(hMenu1, opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND); - SetDlgItemText(hdlg, IDC_LeftClick, TranslateW(str)); - DestroyMenu(hMenu); - break; + hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); + hMenu1 = GetSubMenu(hMenu, 0); - case IDC_PD1: - // Popup delay setting from popup plugin - SetDlgItemText(hdlg, IDC_DELAY, L"0"); - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD1); - break; + wchar_t str[512]; + GetMenuString(hMenu1, m_proto->opt.RightClickAction, str, _countof(str), MF_BYCOMMAND); + SetDlgItemText(m_hwnd, IDC_RightClick, TranslateW(str)); + DestroyMenu(hMenu); + } - case IDC_PD2: - // Popup delay = permanent - SetDlgItemText(hdlg, IDC_DELAY, L"-1"); - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD2); - break; + void onClick_Left(CCtrlButton *) + { + // left click action selection menu + RECT pos; + GetWindowRect(GetDlgItem(m_hwnd, IDC_LeftClick), &pos); + + HMENU hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); + HMENU hMenu1 = GetSubMenu(hMenu, 0); + TranslateMenu(hMenu1); + SelectMenuItem(hMenu1, m_proto->opt.LeftClickAction); + int ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, m_hwnd, nullptr); + if (ID) + m_proto->opt.LeftClickAction = ID; + DestroyMenu(hMenu); - case IDC_DELAY: - // if text is edited - CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3); - break; + hMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_PMENU)); + hMenu1 = GetSubMenu(hMenu, 0); - case IDC_PDEF: - // set the default value for popup texts - for (auto &it : controls) - SetDlgItemText(hdlg, it.id, GetDefaultText(it.c)); - break; + wchar_t str[512]; + GetMenuString(hMenu1, m_proto->opt.LeftClickAction, str, _countof(str), MF_BYCOMMAND); + SetDlgItemText(m_hwnd, IDC_LeftClick, TranslateW(str)); + DestroyMenu(hMenu); + } - case IDC_VAR3: - // display variable list - { - CMStringW wszText; - wszText += L" \n"; // to make the message box wider - wszText += TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set"); - wszText += L"\n"; - wszText += TranslateT("%[..]\tcustom variables"); - MessageBox(nullptr, wszText, TranslateT("Variable List"), MB_OK | MB_ICONASTERISK | MB_TOPMOST); - } - break; + void onClick_PD1(CCtrlButton *) + { + // Popup delay setting from popup plugin + SetDlgItemText(m_hwnd, IDC_DELAY, L"0"); + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD1); + } - case IDC_PREVIEW: - // popup preview - hContact = opt.DefStn; - ReadPopupOpt(hdlg); // read new options to memory - WeatherPopup((WPARAM)opt.DefStn, (BOOL)TRUE); // display popup using new opt - LoadOptions(); // restore old option in memory - opt.DefStn = hContact; - break; - } - break; + void onClick_PD2(CCtrlButton *) + { + // Popup delay = permanent + SetDlgItemText(m_hwnd, IDC_DELAY, L"-1"); + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD2); + } - case WM_NOTIFY: //Here we have pressed either the OK or the APPLY button. - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - ReadPopupOpt(hdlg); - - wchar_t textstr[MAX_TEXT_SIZE]; - for (auto &it : controls) { - GetDlgItemText(hdlg, it.id, textstr, _countof(textstr)); - if (!mir_wstrcmpi(textstr, GetDefaultText(it.c))) - g_plugin.delSetting(it.setting); - else - g_plugin.setWString(it.setting, textstr); - } - - // save the options, and update main menu - SaveOptions(); - return TRUE; - } - break; + void onChanged_Delay(CCtrlEdit *) + { + // if text is edited + CheckRadioButton(m_hwnd, IDC_PD1, IDC_PD3, IDC_PD3); } - return FALSE; + + void onClick_Pdef(CCtrlButton *) + { + // set the default value for popup texts + for (auto &it : controls) + SetDlgItemText(m_hwnd, it.id, GetDefaultText(it.c)); + } + + void onClick_Vars(CCtrlButton *) + { + // display variable list + CMStringW wszText; + wszText += L" \n"; // to make the message box wider + wszText += TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set"); + wszText += L"\n"; + wszText += TranslateT("%[..]\tcustom variables"); + MessageBox(nullptr, wszText, TranslateT("Variable List"), MB_OK | MB_ICONASTERISK | MB_TOPMOST); + } + + void onClick_Preview(CCtrlButton *) + { + // popup preview + MCONTACT hContact = m_proto->opt.DefStn; + ReadPopupOpt(m_hwnd); // read new options to memory + m_proto->WeatherPopup(m_proto->opt.DefStn, true); // display popup using new opt + m_proto->LoadOptions(); // restore old option in memory + m_proto->opt.DefStn = hContact; + } +}; + +void CWeatherProto::InitPopupOptions(WPARAM wParam) +{ + // if popup service exists, load the weather popup options + OPTIONSDIALOGPAGE odp = {}; + odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE; + odp.position = 100000000; + odp.szGroup.w = LPGENW("Popups"); + odp.szTitle.w = m_tszUserName; + odp.pDialog = new CPopupOptsDlg(this); + g_plugin.addOptions(wParam, &odp); } |