From b35fc72bfb45a527d4c8b181019ab38cd3d813aa Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 4 Oct 2024 19:53:25 +0300 Subject: duplicate code removed --- plugins/TabSRMM/src/functions.h | 1 - plugins/TabSRMM/src/globals.cpp | 2 - plugins/TabSRMM/src/modplus.cpp | 144 -------------------------------- plugins/TabSRMM/tabsrmm.vcxproj | 1 - plugins/TabSRMM/tabsrmm.vcxproj.filters | 3 - src/mir_app/src/chat.h | 3 + src/mir_app/src/srmm_base.cpp | 10 +-- src/mir_app/src/srmm_toolbar.cpp | 5 +- 8 files changed, 11 insertions(+), 158 deletions(-) delete mode 100644 plugins/TabSRMM/src/modplus.cpp diff --git a/plugins/TabSRMM/src/functions.h b/plugins/TabSRMM/src/functions.h index a168f28323..fc21f1eebe 100644 --- a/plugins/TabSRMM/src/functions.h +++ b/plugins/TabSRMM/src/functions.h @@ -38,7 +38,6 @@ int IcoLibIconsChanged(WPARAM wParam, LPARAM lParam); int FontServiceFontsChanged(WPARAM wParam, LPARAM lParam); int SmileyAddOptionsChanged(WPARAM wParam, LPARAM lParam); int IEViewOptionsChanged(WPARAM wParam, LPARAM lParam); -int ModPlus_Init(); void RegisterFontServiceFonts(); diff --git a/plugins/TabSRMM/src/globals.cpp b/plugins/TabSRMM/src/globals.cpp index d2bc1c9f96..22f9580a84 100644 --- a/plugins/TabSRMM/src/globals.cpp +++ b/plugins/TabSRMM/src/globals.cpp @@ -233,8 +233,6 @@ int CGlobals::ModulesLoaded(WPARAM, LPARAM) ::Chat_ModulesLoaded(); ::BuildContainerMenu(); - ::ModPlus_Init(); - if (M.GetByte("avatarmode", -1) == -1) db_set_b(0, SRMSGMOD_T, "avatarmode", 2); diff --git a/plugins/TabSRMM/src/modplus.cpp b/plugins/TabSRMM/src/modplus.cpp deleted file mode 100644 index e3c9c5cdac..0000000000 --- a/plugins/TabSRMM/src/modplus.cpp +++ /dev/null @@ -1,144 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Miranda NG: the free IM client for Microsoft* Windows* -// -// Copyright (C) 2012-24 Miranda NG team, -// Copyright (c) 2000-09 Miranda ICQ/IM project, -// all portions of this codebase are copyrighted to the people -// listed in contributors.txt. -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// you should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -// part of tabSRMM messaging plugin for Miranda. -// -// (C) 2005-2010 by silvercircle _at_ gmail _dot_ com and contributors -// -// implements features of the tabSRMM "MADMOD" patch, developed by -// Mad Cluster in May 2008 -// -// the "mad mod" patch added the following features: -// -// ) typing sounds -// ) support for animated avatars through ACC (avs) -// ) a fully customizable tool bar providing services useable by external plugins -// to add and change buttons -// ) toolbar on the bottom -// ) image tag button -// ) client icon in status bar -// ) close tab/window on send and the "hide container feature" - -#include "stdafx.h" - -static wchar_t* getMenuEntry(int i) -{ - char MEntry[256]; - mir_snprintf(MEntry, "MenuEntry_%u", i); - return db_get_wsa(0, "tabmodplus", MEntry); -} - -static int RegisterCustomButton(WPARAM, LPARAM) -{ - BBButton bbd = {}; - bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISPUSHBUTTON | BBBF_NOREADONLY | BBBF_NOREADONLY; - bbd.dwButtonID = 1; - bbd.dwDefPos = 200; - bbd.hIcon = g_plugin.getIconHandle(IDI_IMAGETAG); - bbd.pszModuleName = "Tabmodplus"; - bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]"); - g_plugin.addButton(&bbd); - return 0; -} - -static int CustomButtonPressed(WPARAM wParam, LPARAM lParam) -{ - CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; - if (mir_strcmp(cbcd->pszModule, "Tabmodplus") || cbcd->dwButtonId != 1) - return 0; - - BBButton bbd = {}; - bbd.dwButtonID = 1; - bbd.pszModuleName = "Tabmodplus"; - Srmm_GetButtonState(cbcd->hwndFrom, &bbd); - - ptrW pszText; - CHARRANGE cr; - cr.cpMin = cr.cpMax = 0; - SendDlgItemMessage(cbcd->hwndFrom, IDC_SRMM_MESSAGE, EM_EXGETSEL, 0, (LPARAM)&cr); - UINT textlenght = cr.cpMax - cr.cpMin; - if (textlenght) { - pszText = (wchar_t*)mir_alloc((textlenght + 1)*sizeof(wchar_t)); - memset(pszText, 0, ((textlenght + 1) * sizeof(wchar_t))); - SendDlgItemMessage(cbcd->hwndFrom, IDC_SRMM_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText); - } - - size_t bufSize; - CMStringW pwszFormatedText; - - if (cbcd->flags & BBCF_RIGHTBUTTON) { - int menulimit = db_get_b(0, "tabmodplus", "MenuCount", 0); - if (menulimit != 0) { - HMENU hMenu = CreatePopupMenu(); - LIST arMenuLines(1); - - for (int menunum = 0; menunum < menulimit; menunum++) { - wchar_t *pwszText = getMenuEntry(menunum); - arMenuLines.insert(pwszText); - AppendMenu(hMenu, MF_STRING, menunum + 1, pwszText); - } - - int res = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, nullptr); - if (res != 0) { - bufSize = textlenght + mir_wstrlen(arMenuLines[res-1]) + 2; - pwszFormatedText.Format(arMenuLines[res-1], pszText.get()); - } - - for (auto &it : arMenuLines) - mir_free(it); - } - } - else if (textlenght) { - SendDlgItemMessage(cbcd->hwndFrom, IDC_SRMM_MESSAGE, EM_GETSELTEXT, 0, (LPARAM)pszText); - - pwszFormatedText.Format(L"[img]%s[/img]", pszText.get()); - - bbd.pwszTooltip = nullptr; - bbd.hIcon = nullptr; - bbd.bbbFlags = BBSF_RELEASED; - Srmm_SetButtonState(wParam, &bbd); - } - else if (bbd.bbbFlags & BBSF_PUSHED) { - pwszFormatedText = L"[img]"; - - bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]"); - Srmm_SetButtonState(wParam, &bbd); - } - else { - pwszFormatedText = L"[/img]"; - - bbd.pwszTooltip = LPGENW("Insert [img] tag / surround selected text with [img][/img]"); - Srmm_SetButtonState(wParam, &bbd); - } - - if (!pwszFormatedText.IsEmpty()) - SendDlgItemMessage(cbcd->hwndFrom, IDC_SRMM_MESSAGE, EM_REPLACESEL, TRUE, (LPARAM)pwszFormatedText.c_str()); - return 1; -} - -int ModPlus_Init() -{ - HookEvent(ME_MSG_BUTTONPRESSED, CustomButtonPressed); - - HookTemporaryEvent(ME_MSG_TOOLBARLOADED, RegisterCustomButton); - return 0; -} diff --git a/plugins/TabSRMM/tabsrmm.vcxproj b/plugins/TabSRMM/tabsrmm.vcxproj index ca0e2936ae..0b811c6f42 100644 --- a/plugins/TabSRMM/tabsrmm.vcxproj +++ b/plugins/TabSRMM/tabsrmm.vcxproj @@ -43,7 +43,6 @@ - diff --git a/plugins/TabSRMM/tabsrmm.vcxproj.filters b/plugins/TabSRMM/tabsrmm.vcxproj.filters index 8bc0b3e5c2..e4ae5a983c 100644 --- a/plugins/TabSRMM/tabsrmm.vcxproj.filters +++ b/plugins/TabSRMM/tabsrmm.vcxproj.filters @@ -53,9 +53,6 @@ Source Files - - Source Files - Source Files diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 9b2564bad0..84e9be92d9 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -30,6 +30,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define STREAMSTAGE_TAIL 2 #define STREAMSTAGE_STOP 3 +#define N_CUSTOM_BBCODES 3 +extern wchar_t *wszBbcodes[N_CUSTOM_BBCODES]; + #define DM_OPTIONSAPPLIED (WM_USER+14) void Srmm_CreateToolbarIcons(CSrmmBaseDialog *pDlg, int flags); diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 9495a98690..57b03ca48a 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -581,6 +581,8 @@ static void doMarkEventRead(MCONTACT hContact, MEVENT hEvent) Clist_RemoveEvent(-1, hEvent); } +wchar_t *wszBbcodes[N_CUSTOM_BBCODES] = { L"[img]", L"[code]", L"[quote]" }; + INT_PTR CSrmmBaseDialog::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { @@ -608,12 +610,10 @@ INT_PTR CSrmmBaseDialog::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) } if (wParam == IDC_CODE) { - switch (lParam) { - case 1: InsertBbcodeString(L"[code]"); break; - case 2: InsertBbcodeString(L"[quote]"); break; - default: + if (lParam > 0 && lParam < _countof(wszBbcodes)) + InsertBbcodeString(wszBbcodes[lParam-1]); + else Srmm_ClickToolbarIcon(m_hContact, wParam, m_hwnd, 0); - } } break; diff --git a/src/mir_app/src/srmm_toolbar.cpp b/src/mir_app/src/srmm_toolbar.cpp index b0ddabd7bd..1f7f2e0e9b 100644 --- a/src/mir_app/src/srmm_toolbar.cpp +++ b/src/mir_app/src/srmm_toolbar.cpp @@ -885,8 +885,9 @@ static int OnToolbarClicked(WPARAM, LPARAM lParam) return 0; HMENU hMenu = CreatePopupMenu(); - AppendMenuW(hMenu, MF_STRING, 1, TranslateT("[code]")); - AppendMenuW(hMenu, MF_STRING, 2, TranslateT("[quote]")); + for (int i = 0; i < N_CUSTOM_BBCODES; i++) + AppendMenuW(hMenu, MF_STRING, i + 1, wszBbcodes[i]); + int ret = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, nullptr); if (ret != 0) PostMessage(cbcd->hwndFrom, WM_COMMAND, IDC_CODE, ret); -- cgit v1.2.3