From 5d1adca6a83289d3dcc23bc0af82193da69d9d96 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 17 Jun 2018 21:30:32 +0300 Subject: GetTabWindow applied to all another places --- plugins/TabSRMM/src/chat_window.cpp | 12 +++-------- plugins/TabSRMM/src/container.cpp | 27 ++++++----------------- plugins/TabSRMM/src/functions.h | 2 +- plugins/TabSRMM/src/msgdialog.cpp | 14 ++++-------- plugins/TabSRMM/src/msgs.cpp | 5 +---- plugins/TabSRMM/src/sidebar.cpp | 9 +++----- plugins/TabSRMM/src/tabctrl.cpp | 43 ++++++++++++------------------------- plugins/TabSRMM/src/userprefs.cpp | 29 ++++++++++--------------- 8 files changed, 44 insertions(+), 97 deletions(-) (limited to 'plugins') diff --git a/plugins/TabSRMM/src/chat_window.cpp b/plugins/TabSRMM/src/chat_window.cpp index 6dd8682774..6fdf4e0cd4 100644 --- a/plugins/TabSRMM/src/chat_window.cpp +++ b/plugins/TabSRMM/src/chat_window.cpp @@ -771,15 +771,12 @@ void CChatRoomDlg::CloseTab() i++; TabCtrl_SetCurSel(m_hwndParent, i); - TCITEM item = {}; - item.mask = TCIF_PARAM; - TabCtrl_GetItem(m_hwndParent, i, &item); // retrieve dialog hwnd for the now active tab... - m_pContainer->m_hwndActive = (HWND)item.lParam; + m_pContainer->m_hwndActive = GetTabWindow(m_hwndParent, i); RECT rc; SendMessage(m_pContainer->m_hwnd, DM_QUERYCLIENTAREA, 0, (LPARAM)&rc); SetWindowPos(m_pContainer->m_hwndActive, HWND_TOP, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), SWP_SHOWWINDOW); - ShowWindow((HWND)item.lParam, SW_SHOW); + ShowWindow(m_pContainer->m_hwndActive, SW_SHOW); SetForegroundWindow(m_pContainer->m_hwndActive); SetFocus(m_pContainer->m_hwndActive); SendMessage(m_pContainer->m_hwnd, WM_SIZE, 0, 0); @@ -2458,11 +2455,8 @@ void ShowRoom(TContainerData *pContainer, SESSION_INFO *si) pContainer->iTabIndex = iCount; if (iCount > 0) { - TCITEM item = {}; for (int i = iCount - 1; i >= 0; i--) { - item.mask = TCIF_PARAM; - TabCtrl_GetItem(hwndTab, i, &item); - HWND hwnd = (HWND)item.lParam; + HWND hwnd = GetTabWindow(hwndTab, i); CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (dat) { int relPos = M.GetDword(dat->m_hContact, "tabindex", i * 100); diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index cb0f86dc4f..b1a30a8193 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -41,7 +41,7 @@ static TContainerData* TSAPI RemoveContainerFromList(TContainerData*); static bool fForceOverlayIcons = false; -static HWND GetTabWindow(HWND hwndTab, int i) +HWND GetTabWindow(HWND hwndTab, int i) { if (i < 0) return nullptr; @@ -1942,24 +1942,14 @@ int TSAPI GetTabIndexFromHWND(HWND hwndTab, HWND hwnd) { int iItems = TabCtrl_GetItemCount(hwndTab); - TCITEM item = {}; - item.mask = TCIF_PARAM; for (int i = 0; i < iItems; i++) { - TabCtrl_GetItem(hwndTab, i, &item); - if ((HWND)item.lParam == hwnd) + HWND pDlg = GetTabWindow(hwndTab, i); + if (pDlg == hwnd) return i; } return -1; } -HWND TSAPI GetHWNDFromTabIndex(HWND hwndTab, int idx) -{ - TCITEM item = {}; - item.mask = TCIF_PARAM; - TabCtrl_GetItem(hwndTab, idx, &item); - return (HWND)item.lParam; -} - // activates the tab belonging to the given client HWND (handle of the actual // message window. @@ -1981,7 +1971,7 @@ int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd) void TSAPI CloseOtherTabs(HWND hwndTab, CTabBaseDlg &dat) { for (int idxt = 0; idxt < dat.m_pContainer->iChilds;) { - HWND otherTab = GetHWNDFromTabIndex(hwndTab, idxt); + HWND otherTab = GetTabWindow(hwndTab, idxt); if (otherTab != nullptr && otherTab != dat.GetHwnd()) SendMessage(otherTab, WM_CLOSE, 1, 0); else @@ -2307,14 +2297,11 @@ void TSAPI BroadCastContainer(const TContainerData *pContainer, UINT message, WP return; HWND hwndTab = GetDlgItem(pContainer->m_hwnd, IDC_MSGTABS); - TCITEM item = {}; - item.mask = TCIF_PARAM; - int nCount = TabCtrl_GetItemCount(hwndTab); for (int i = 0; i < nCount; i++) { - TabCtrl_GetItem(hwndTab, i, &item); - if (IsWindow((HWND)item.lParam)) - SendMessage((HWND)item.lParam, message, wParam, lParam); + HWND hDlg = GetTabWindow(hwndTab, i); + if (IsWindow(hDlg)) + SendMessage(hDlg, message, wParam, lParam); } } diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index 1027d21c3b..5b1c88200d 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -80,7 +80,7 @@ TContainerData* TSAPI CreateContainer(const wchar_t *name, int iTemp, MCONTACT h TContainerData* TSAPI FindContainerByName(const wchar_t *name); int TSAPI GetTabIndexFromHWND(HWND hwndTab, HWND hwnd); -HWND TSAPI GetHWNDFromTabIndex(HWND hwndTab, int idx); +HWND TSAPI GetTabWindow(HWND hwndTab, int idx); int TSAPI GetTabItemFromMouse(HWND hwndTab, POINT *pt); void TSAPI CloseOtherTabs(HWND hwndTab, CTabBaseDlg &dat); int TSAPI ActivateTabFromHWND(HWND hwndTab, HWND hwnd); diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index 8929da899f..8711846b61 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -1141,12 +1141,9 @@ void CSrmmWindow::onClick_Ok(CCtrlButton*) int tabCount = TabCtrl_GetItemCount(m_hwndParent); ptrA szFromStream(m_message.GetRichTextRtf(!m_SendFormat)); - TCITEM tci = {}; - tci.mask = TCIF_PARAM; for (int i = 0; i < tabCount; i++) { - TabCtrl_GetItem(m_hwndParent, i, &tci); // get the contact from the tabs lparam which hopefully is the tabs hwnd so we can get its userdata.... hopefully - HWND contacthwnd = (HWND)tci.lParam; + HWND contacthwnd = GetTabWindow(m_hwndParent, i); if (IsWindow(contacthwnd)) { // if the contact hwnd is the current contact then ignore it and let the normal code deal with the msg if (contacthwnd != m_hwnd) { @@ -3013,15 +3010,12 @@ INT_PTR CSrmmWindow::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) i++; TabCtrl_SetCurSel(m_hwndParent, i); - TCITEM item = {}; - item.mask = TCIF_PARAM; - TabCtrl_GetItem(m_hwndParent, i, &item); // retrieve dialog hwnd for the now active tab... - - m_pContainer->m_hwndActive = (HWND)item.lParam; + // retrieve dialog hwnd for the now active tab... + m_pContainer->m_hwndActive = GetTabWindow(m_hwndParent, i); SendMessage(m_pContainer->m_hwnd, DM_QUERYCLIENTAREA, 0, (LPARAM)&rc); SetWindowPos(m_pContainer->m_hwndActive, HWND_TOP, rc.left, rc.top, (rc.right - rc.left), (rc.bottom - rc.top), SWP_SHOWWINDOW); - ShowWindow((HWND)item.lParam, SW_SHOW); + ShowWindow(m_pContainer->m_hwndActive, SW_SHOW); SetForegroundWindow(m_pContainer->m_hwndActive); SetFocus(m_pContainer->m_hwndActive); } diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index 2f659e5233..ac2a69d626 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -617,11 +617,8 @@ HWND TSAPI CreateNewTabForContact(TContainerData *pContainer, MCONTACT hContact, pContainer->iTabIndex = iCount; if (iCount > 0) { - TCITEM item = {}; for (int i = iCount - 1; i >= 0; i--) { - item.mask = TCIF_PARAM; - TabCtrl_GetItem(hwndTab, i, &item); - HWND hwnd = (HWND)item.lParam; + HWND hwnd = GetTabWindow(hwndTab, i); CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (dat) { int relPos = M.GetDword(dat->m_hContact, "tabindex", i * 100); diff --git a/plugins/TabSRMM/src/sidebar.cpp b/plugins/TabSRMM/src/sidebar.cpp index cf64ff1ad1..27a7e69825 100644 --- a/plugins/TabSRMM/src/sidebar.cpp +++ b/plugins/TabSRMM/src/sidebar.cpp @@ -496,17 +496,14 @@ void CSideBar::populateAll() int iItems = (int)TabCtrl_GetItemCount(hwndTab); - TCITEM item = {}; - item.mask = TCIF_PARAM; - m_iTopButtons = 0; for (int i = 0; i < iItems; i++) { - TabCtrl_GetItem(hwndTab, i, &item); - if (item.lParam == 0 || !IsWindow((HWND)item.lParam)) + HWND hDlg = GetTabWindow(hwndTab, i); + if (hDlg == 0 || !IsWindow(hDlg)) continue; - CSrmmWindow *dat = (CSrmmWindow*)::GetWindowLongPtr((HWND)item.lParam, GWLP_USERDATA); + CSrmmWindow *dat = (CSrmmWindow*)::GetWindowLongPtr(hDlg, GWLP_USERDATA); if (dat == nullptr) continue; diff --git a/plugins/TabSRMM/src/tabctrl.cpp b/plugins/TabSRMM/src/tabctrl.cpp index 87098af94a..c8b6566781 100644 --- a/plugins/TabSRMM/src/tabctrl.cpp +++ b/plugins/TabSRMM/src/tabctrl.cpp @@ -611,9 +611,6 @@ static void PaintWorker(HWND hwnd, TabControlData *tabdat) InvalidateRect(hwnd, nullptr, FALSE); tabdat->iHoveredTabIndex = hotItem; - TCITEM tci = {}; - tci.mask = TCIF_PARAM; - tabdat->fAeroTabs = (CSkin::m_fAeroSkinsValid && (isAero || PluginConfig.m_fillColor)) ? TRUE : FALSE; tabdat->fCloseButton = (tabdat->pContainer->dwFlagsEx & TCF_CLOSEBUTTON ? TRUE : FALSE); tabdat->helperDat = nullptr; @@ -846,10 +843,9 @@ page_done: if (i == iActive) continue; - TabCtrl_GetItem(hwnd, i, &tci); CSrmmWindow *dat = nullptr; - if (tci.lParam) - dat = (CSrmmWindow*)GetWindowLongPtr((HWND)tci.lParam, GWLP_USERDATA); + if (HWND hDlg = GetTabWindow(hwnd, i)) + dat = (CSrmmWindow*)GetWindowLongPtr(hDlg, GWLP_USERDATA); TabCtrl_GetItemRect(hwnd, i, &rcItem); if (!bClassicDraw && uiBottom) { rcItem.top -= PluginConfig.tabConfig.m_bottomAdjust; @@ -881,9 +877,8 @@ page_done: int nHint = 0; rcItem = rctActive; - TabCtrl_GetItem(hwnd, iActive, &tci); - if (tci.lParam) - dat = (CSrmmWindow*)GetWindowLongPtr((HWND)tci.lParam, GWLP_USERDATA); + if (HWND hDlg = GetTabWindow(hwnd, iActive)) + dat = (CSrmmWindow*)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (!bClassicDraw && !(dwStyle & TCS_BUTTONS)) { InflateRect(&rcItem, 2, 2); @@ -1110,14 +1105,12 @@ static LRESULT CALLBACK TabControlSubclassProc(HWND hwnd, UINT msg, WPARAM wPara if (DragDetect(hwnd, pt) && TabCtrl_GetItemCount(hwnd) > 1) { int i = GetTabItemFromMouse(hwnd, &pt); if (i != -1) { - TCITEM tc; - tc.mask = TCIF_PARAM; - TabCtrl_GetItem(hwnd, i, &tc); - CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr((HWND)tc.lParam, GWLP_USERDATA); + HWND hDlg = GetTabWindow(hwnd, i); + CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (dat) { tabdat->bDragging = TRUE; tabdat->iBeginIndex = i; - tabdat->hwndDrag = (HWND)tc.lParam; + tabdat->hwndDrag = hDlg; tabdat->dragDat = dat; tabdat->fSavePos = TRUE; tabdat->himlDrag = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 1, 0); @@ -1137,15 +1130,12 @@ static LRESULT CALLBACK TabControlSubclassProc(HWND hwnd, UINT msg, WPARAM wPara if (DragDetect(hwnd, pt) && TabCtrl_GetItemCount(hwnd) > 1) { int i = GetTabItemFromMouse(hwnd, &pt); if (i != -1) { - TCITEM tc; - tc.mask = TCIF_PARAM; - TabCtrl_GetItem(hwnd, i, &tc); - - CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr((HWND)tc.lParam, GWLP_USERDATA); + HWND hDlg = GetTabWindow(hwnd, i); + CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (dat) { tabdat->bDragging = TRUE; tabdat->iBeginIndex = i; - tabdat->hwndDrag = (HWND)tc.lParam; + tabdat->hwndDrag = hDlg; tabdat->dragDat = dat; tabdat->himlDrag = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 1, 0); tabdat->fSavePos = FALSE; @@ -1257,18 +1247,13 @@ static LRESULT CALLBACK TabControlSubclassProc(HWND hwnd, UINT msg, WPARAM wPara ti.cbSize = sizeof(ti); ti.ptCursor = pt; - TCITEM item = {}; - item.mask = TCIF_PARAM; int nItem = GetTabItemFromMouse(hwnd, &pt); if (nItem >= 0 && nItem < TabCtrl_GetItemCount(hwnd)) { - TabCtrl_GetItem(hwnd, nItem, &item); - - /* - * get the message window data for the session to which this tab item belongs - */ + // get the message window data for the session to which this tab item belongs + HWND hDlg = GetTabWindow(hwnd, nItem); CSrmmWindow *dat = nullptr; - if (IsWindow((HWND)item.lParam) && item.lParam != 0) - dat = (CSrmmWindow*)GetWindowLongPtr((HWND)item.lParam, GWLP_USERDATA); + if (IsWindow(hDlg) && hDlg != 0) + dat = (CSrmmWindow*)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (dat) { tabdat->fTipActive = TRUE; ti.isGroup = 0; diff --git a/plugins/TabSRMM/src/userprefs.cpp b/plugins/TabSRMM/src/userprefs.cpp index 65494b062b..7b6e0c214c 100644 --- a/plugins/TabSRMM/src/userprefs.cpp +++ b/plugins/TabSRMM/src/userprefs.cpp @@ -400,7 +400,7 @@ static INT_PTR CALLBACK DlgProcUserPrefsLogOptions(HWND hwndDlg, UINT msg, WPARA INT_PTR CALLBACK DlgProcUserPrefsFrame(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { MCONTACT hContact = (MCONTACT)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - TCITEM tci; + HWND hwndTab = GetDlgItem(hwndDlg, IDC_OPTIONSTAB); switch (msg) { case WM_INITDIALOG: @@ -418,23 +418,23 @@ INT_PTR CALLBACK DlgProcUserPrefsFrame(HWND hwndDlg, UINT msg, WPARAM wParam, LP mir_snwprintf(szBuffer, TranslateT("Set messaging options for %s"), Clist_GetContactDisplayName(hContact)); SetWindowText(hwndDlg, szBuffer); - memset(&tci, 0, sizeof(tci)); + TCITEM tci; tci.mask = TCIF_PARAM | TCIF_TEXT; tci.lParam = (LPARAM)CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_USERPREFS), hwndDlg, DlgProcUserPrefs, hContact); tci.pszText = TranslateT("General"); - TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), 0, &tci); + TabCtrl_InsertItem(hwndTab, 0, &tci); MoveWindow((HWND)tci.lParam, 6, DPISCALEY_S(32), rcClient.right - 12, rcClient.bottom - DPISCALEY_S(80), 1); ShowWindow((HWND)tci.lParam, SW_SHOW); EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB); tci.lParam = (LPARAM)CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_USERPREFS1), hwndDlg, DlgProcUserPrefsLogOptions, hContact); tci.pszText = TranslateT("Message Log"); - TabCtrl_InsertItem(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), 1, &tci); + TabCtrl_InsertItem(hwndTab, 1, &tci); MoveWindow((HWND)tci.lParam, 6, DPISCALEY_S(32), rcClient.right - 12, rcClient.bottom - DPISCALEY_S(80), 1); ShowWindow((HWND)tci.lParam, SW_HIDE); EnableThemeDialogTexture((HWND)tci.lParam, ETDT_ENABLETAB); } - TabCtrl_SetCurSel(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), 0); + TabCtrl_SetCurSel(hwndTab, 0); ShowWindow(hwndDlg, SW_SHOW); return TRUE; @@ -443,15 +443,11 @@ INT_PTR CALLBACK DlgProcUserPrefsFrame(HWND hwndDlg, UINT msg, WPARAM wParam, LP case IDC_OPTIONSTAB: switch (((LPNMHDR)lParam)->code) { case TCN_SELCHANGING: - tci.mask = TCIF_PARAM; - TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_OPTIONSTAB)), &tci); - ShowWindow((HWND)tci.lParam, SW_HIDE); + ShowWindow(GetTabWindow(hwndTab, TabCtrl_GetCurSel(hwndTab)), SW_HIDE); break; case TCN_SELCHANGE: - tci.mask = TCIF_PARAM; - TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), TabCtrl_GetCurSel(GetDlgItem(hwndDlg, IDC_OPTIONSTAB)), &tci); - ShowWindow((HWND)tci.lParam, SW_SHOW); + ShowWindow(GetTabWindow(hwndTab, TabCtrl_GetCurSel(hwndTab)), SW_SHOW); break; } break; @@ -466,15 +462,12 @@ INT_PTR CALLBACK DlgProcUserPrefsFrame(HWND hwndDlg, UINT msg, WPARAM wParam, LP case IDOK: DWORD dwActionToTake = 0; // child pages request which action to take - HWND hwnd = Srmm_FindWindow(hContact); + HWND hwnd = Srmm_FindWindow(hContact); - tci.mask = TCIF_PARAM; + int count = TabCtrl_GetItemCount(hwndTab); + for (int i = 0; i < count; i++) + SendMessage(GetTabWindow(hwndTab, i), WM_COMMAND, WM_USER + 100, (LPARAM)&dwActionToTake); - int count = TabCtrl_GetItemCount(GetDlgItem(hwndDlg, IDC_OPTIONSTAB)); - for (int i = 0; i < count; i++) { - TabCtrl_GetItem(GetDlgItem(hwndDlg, IDC_OPTIONSTAB), i, &tci); - SendMessage((HWND)tci.lParam, WM_COMMAND, WM_USER + 100, (LPARAM)&dwActionToTake); - } if (hwnd) { CSrmmWindow *dat = (CSrmmWindow*)GetWindowLongPtr(hwnd, GWLP_USERDATA); if (dat) { -- cgit v1.2.3