diff options
Diffstat (limited to 'plugins/TabSRMM/src/selectcontainer.cpp')
-rw-r--r-- | plugins/TabSRMM/src/selectcontainer.cpp | 77 |
1 files changed, 37 insertions, 40 deletions
diff --git a/plugins/TabSRMM/src/selectcontainer.cpp b/plugins/TabSRMM/src/selectcontainer.cpp index 6174bd48a4..63cf0477fa 100644 --- a/plugins/TabSRMM/src/selectcontainer.cpp +++ b/plugins/TabSRMM/src/selectcontainer.cpp @@ -28,34 +28,28 @@ #include "stdafx.h"
-INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+static INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- HWND hwndMsgDlg = nullptr;
-
- hwndMsgDlg = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ auto *pDlg = (CMsgDialog *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG: {
- wchar_t szNewTitle[128];
- RECT rc, rcParent;
-
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
- hwndMsgDlg = (HWND)lParam;
TranslateDialogDefault(hwndDlg);
- if (lParam) {
- CMsgDialog *dat = (CMsgDialog*)GetWindowLongPtr((HWND)lParam, GWLP_USERDATA);
- if (dat) {
- mir_snwprintf(szNewTitle, TranslateT("Select container for %s"), dat->m_cache->getNick());
- SetWindowText(hwndDlg, szNewTitle);
- }
+ pDlg = (CMsgDialog*)(lParam);
+ if (pDlg) {
+ wchar_t szNewTitle[128];
+ mir_snwprintf(szNewTitle, TranslateT("Select container for %s"), pDlg->m_cache->getNick());
+ SetWindowText(hwndDlg, szNewTitle);
}
SendMessage(hwndDlg, DM_SC_BUILDLIST, 0, 0);
SendDlgItemMessage(hwndDlg, IDC_NEWCONTAINERNAME, EM_LIMITTEXT, (WPARAM)CONTAINER_NAMELEN, 0);
SendDlgItemMessage(hwndDlg, IDC_NEWCONTAINER, EM_LIMITTEXT, (WPARAM)CONTAINER_NAMELEN, 0);
+ RECT rc, rcParent;
GetWindowRect(hwndDlg, &rc);
GetWindowRect(GetParent(hwndDlg), &rcParent);
SetWindowPos(hwndDlg, nullptr, (rcParent.left + rcParent.right - (rc.right - rc.left)) / 2, (rcParent.top + rcParent.bottom - (rc.bottom - rc.top)) / 2, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
@@ -64,26 +58,24 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L case WM_COMMAND:
switch (LOWORD(wParam)) {
- case IDOK: {
- wchar_t szName[CONTAINER_NAMELEN];
+ case IDOK:
+ wchar_t szName[CONTAINER_NAMELEN + 1];
LRESULT iItem;
if ((iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETCURSEL, 0, 0)) != LB_ERR) {
SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETTEXT, (WPARAM)iItem, (LPARAM)szName);
- if (IsWindow(hwndMsgDlg))
- SendMessage(hwndMsgDlg, DM_CONTAINERSELECTED, 0, (LPARAM)szName);
+ if (IsWindow(pDlg->GetHwnd()))
+ pDlg->SwitchToContainer(szName);
}
if (IsWindow(hwndDlg))
DestroyWindow(hwndDlg);
break;
- }
+
case IDCANCEL:
DestroyWindow(hwndDlg);
break;
- case IDC_DELETECONTAINER: {
- wchar_t szName[CONTAINER_NAMELEN + 1];
- LRESULT iItem;
-
+
+ case IDC_DELETECONTAINER:
if ((iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETCURSEL, 0, 0)) != LB_ERR) {
SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETTEXT, (WPARAM)iItem, (LPARAM)szName);
if (!wcsncmp(szName, L"default", CONTAINER_NAMELEN) || !wcsncmp(szName, TranslateT("Default container"), CONTAINER_NAMELEN))
@@ -97,18 +89,17 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L }
}
break;
- }
- case IDC_RENAMECONTAINER: {
- wchar_t szNewName[CONTAINER_NAMELEN], szName[CONTAINER_NAMELEN + 1];
- int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NEWCONTAINERNAME));
- if (iLen) {
+
+ case IDC_RENAMECONTAINER:
+ if (int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NEWCONTAINERNAME))) {
+ wchar_t szNewName[CONTAINER_NAMELEN];
GetDlgItemText(hwndDlg, IDC_NEWCONTAINERNAME, szNewName, _countof(szNewName));
if (!wcsncmp(szNewName, CGlobals::m_default_container_name, CONTAINER_NAMELEN) || !wcsncmp(szNewName, TranslateT("Default container"), CONTAINER_NAMELEN)) {
MessageBox(hwndDlg, TranslateT("You cannot rename the default container"), TranslateT("Error"), MB_OK | MB_ICONERROR);
break;
}
- int iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)szNewName);
+ iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)szNewName);
if (iItem != LB_ERR) {
wchar_t szOldName[CONTAINER_NAMELEN + 1];
SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETTEXT, (WPARAM)iItem, (LPARAM)szOldName);
@@ -138,14 +129,12 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L }
}
break;
- }
- case IDC_CREATENEW: {
- wchar_t szNewName[CONTAINER_NAMELEN], szName[CONTAINER_NAMELEN + 1];
- int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NEWCONTAINER));
- if (iLen) {
+ case IDC_CREATENEW:
+ if (int iLen = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_NEWCONTAINER))) {
+ wchar_t szNewName[CONTAINER_NAMELEN];
GetDlgItemText(hwndDlg, IDC_NEWCONTAINER, szNewName, _countof(szNewName));
- int iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)szNewName);
+ iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)szNewName);
if (iItem != LB_ERR || !wcsncmp(szNewName, CGlobals::m_default_container_name, CONTAINER_NAMELEN)) {
SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_GETTEXT, (WPARAM)iItem, (LPARAM)szName);
if (mir_wstrlen(szName) == mir_wstrlen(szNewName) || !wcsncmp(szNewName, CGlobals::m_default_container_name, CONTAINER_NAMELEN)) {
@@ -154,14 +143,15 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L break;
}
}
- if (IsWindow(hwndMsgDlg)) {
- SendMessage(hwndMsgDlg, DM_CONTAINERSELECTED, 0, (LPARAM)szNewName);
+
+ if (IsWindow(pDlg->GetHwnd())) {
+ pDlg->SwitchToContainer(szNewName);
if (IsWindow(hwndDlg))
DestroyWindow(hwndDlg);
}
}
break;
- }
+
case IDC_CNTLIST:
if (HIWORD(wParam) == LBN_DBLCLK)
SendMessage(hwndDlg, WM_COMMAND, IDOK, 0);
@@ -185,8 +175,7 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L }
// highlight the name of the container to which the message window currently is assigned
- TContainerData *pContainer = nullptr;
- SendMessage(hwndMsgDlg, DM_QUERYCONTAINER, 0, (LPARAM)&pContainer);
+ TContainerData *pContainer = pDlg->m_pContainer;
if (pContainer) {
LRESULT iItem = SendDlgItemMessage(hwndDlg, IDC_CNTLIST, LB_FINDSTRING, -1,
(LPARAM)(!mir_wstrcmp(pContainer->m_wszName, L"default") ? TranslateT("Default container") : pContainer->m_wszName));
@@ -197,3 +186,11 @@ INT_PTR CALLBACK SelectContainerDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, L }
return FALSE;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// chooses a new container for a window
+
+void CMsgDialog::SelectContainer()
+{
+ CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_SELECTCONTAINER), m_hwnd, SelectContainerDlgProc, (LPARAM)this);
+}
|