From bd80013253c1fabc856c05c4f839d00ec18b2b06 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Mon, 23 Jul 2012 12:31:44 +0000 Subject: QuickMessages, QuickReplies: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1119 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/QuickReplies/src/common.h | 71 ++++++++++ plugins/QuickReplies/src/events.cpp | 186 ++++++++++++++++++++++++++ plugins/QuickReplies/src/options.cpp | 210 ++++++++++++++++++++++++++++++ plugins/QuickReplies/src/quickreplies.cpp | 69 ++++++++++ plugins/QuickReplies/src/resource.h | 29 +++++ plugins/QuickReplies/src/version.h | 20 +++ 6 files changed, 585 insertions(+) create mode 100644 plugins/QuickReplies/src/common.h create mode 100644 plugins/QuickReplies/src/events.cpp create mode 100644 plugins/QuickReplies/src/options.cpp create mode 100644 plugins/QuickReplies/src/quickreplies.cpp create mode 100644 plugins/QuickReplies/src/resource.h create mode 100644 plugins/QuickReplies/src/version.h (limited to 'plugins/QuickReplies/src') diff --git a/plugins/QuickReplies/src/common.h b/plugins/QuickReplies/src/common.h new file mode 100644 index 0000000000..e65994372c --- /dev/null +++ b/plugins/QuickReplies/src/common.h @@ -0,0 +1,71 @@ +/* +Copyright (C) 2010 Unsane + +This is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this file; see the file license.txt. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. +*/ + + +#ifndef __QUICK_REPLY_H__ +#define __QUICK_REPLY_H__ + +#define MIRANDA_VER 0x0A00 + +#include +#include +#include + +#include "tchar.h" + +#include +#include +#include +#include +#include +#include + +#include "m_msg_buttonsbar.h" +#include "m_variables.h" + +#include "resource.h" +#include "version.h" + +#define MODULE_NAME __INTERNAL_NAME +#define TEXT_LIMIT 2048 +#define IDC_MESSAGE 1002 +#define IDC_CHATMESSAGE 1009 + +#define MS_QUICKREPLIES_SERVICE MODULE_NAME"/Service" + +extern HINSTANCE hInstance; + +extern BYTE iNumber; + +extern HANDLE hOnOptInitialized; +extern HANDLE hOnButtonPressed; +extern HANDLE hQuickRepliesService; +extern HANDLE hOnModulesLoaded; +extern HANDLE hOnPreShutdown; + +typedef std::wstring tString; + +INT_PTR QuickRepliesService(WPARAM wParam, LPARAM lParam); + +int OnModulesLoaded(WPARAM wParam, LPARAM lParam); +int OnOptInitialized(WPARAM wParam, LPARAM lParam); +int OnButtonPressed(WPARAM wParam, LPARAM lParam); +int OnPreShutdown(WPARAM wParam, LPARAM lParam); + +#endif //__QUICK_REPLY_H__ \ No newline at end of file diff --git a/plugins/QuickReplies/src/events.cpp b/plugins/QuickReplies/src/events.cpp new file mode 100644 index 0000000000..2227c6d6f1 --- /dev/null +++ b/plugins/QuickReplies/src/events.cpp @@ -0,0 +1,186 @@ +/* +Copyright (C) 2010 Unsane + +This is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this file; see the file license.txt. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +using namespace std; + +BYTE iNumber; + +HANDLE hOnOptInitialized; +HANDLE hOnButtonPressed; +HANDLE hQuickRepliesService; + +INT_PTR QuickRepliesService(WPARAM, LPARAM) +{ + return TRUE; +} + +int OnModulesLoaded(WPARAM wParam, LPARAM lParam) +{ + UnhookEvent(hOnModulesLoaded); + HANDLE hIcon = NULL; + char buttonName[32]; + + if (!ServiceExists(MS_QUICKREPLIES_SERVICE)) + { + iNumber = 0; + hQuickRepliesService = CreateServiceFunction(MS_QUICKREPLIES_SERVICE, QuickRepliesService); + } + else iNumber = DBGetContactSettingByte(NULL, MODULE_NAME, "InstancesCount", 0); + DBWriteContactSettingByte(NULL, MODULE_NAME, "InstancesCount", iNumber + 1); + + hOnOptInitialized = HookEvent(ME_OPT_INITIALISE, OnOptInitialized); + hOnButtonPressed = HookEvent(ME_MSG_BUTTONPRESSED, OnButtonPressed); + + char buttonNameTranslated[32]; + mir_snprintf(buttonName, SIZEOF(buttonName), "Button %x", iNumber + 1); + mir_snprintf(buttonNameTranslated, SIZEOF(buttonNameTranslated), "%s %x",Translate("Button"), iNumber + 1); + + SKINICONDESC sid = {0}; + sid.cbSize = sizeof(sid); + sid.pszSection = "TabSRMM/Quick Replies"; + sid.cx = sid.cy = 16; + sid.pszDescription = buttonNameTranslated; + sid.pszName = buttonName; + sid.hDefaultIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_QICON)); + hIcon = Skin_AddIcon(&sid); + + if (ServiceExists(MS_BB_ADDBUTTON)) { + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + + BBButton bbd = {0}; + bbd.cbSize = sizeof(BBButton); + bbd.bbbFlags = BBBF_ISIMBUTTON | BBBF_ISCHATBUTTON | BBBF_ISLSIDEBUTTON; + bbd.pszModuleName = buttonName; + bbd.ptszTooltip = _T("Quick Replies\r\nLeft button - open menu\r\nRight button - options page"); + bbd.hIcon = hIcon; + bbd.dwButtonID = iNumber; + bbd.dwDefPos = 220; + + CallService(MS_BB_ADDBUTTON, 0, (LPARAM)&bbd); + } + + return 0; +} + +int OnButtonPressed(WPARAM wParam, LPARAM lParam) +{ + char key[64]; + int index = 0; + int count = 0; + HMENU hMenu = NULL; + char buttonName[32]; + tString replies = _T(""); + vector replyList; + CustomButtonClickData *cbcd = (CustomButtonClickData *)lParam; + + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + if (strcmp(cbcd->pszModule, buttonName)) + return 0; + + if (cbcd->dwButtonId != iNumber) + return 1; + + mir_snprintf(key, 64, "RepliesCount_%x", iNumber); + count = DBGetContactSettingWord(NULL, MODULE_NAME, key, 0); + + { + if (count == 0 || cbcd->flags & BBCF_RIGHTBUTTON) + { + mir_snprintf(buttonName, SIZEOF(buttonName), "Button %x", iNumber + 1); + + OPENOPTIONSDIALOG ood = {0}; + ood.cbSize = sizeof(ood); + ood.pszGroup = "Message Sessions"; + ood.pszPage = "Quick Replies"; + ood.pszTab = buttonName; + + CallService(MS_OPT_OPENOPTIONS, NULL, (LPARAM)&ood); + + return 0; + } + + hMenu = CreatePopupMenu(); + + DBVARIANT dbv = {0}; + + for (int i = 0; i < count; i++) + { + mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); + DBGetContactSettingTString(NULL, MODULE_NAME, key, &dbv); + + if (dbv.ptszVal == NULL) + replyList.push_back(_T("")); + else + replyList.push_back((TCHAR*)variables_parsedup(dbv.ptszVal, 0, (HANDLE)wParam)); + + if (_tcscmp(dbv.ptszVal, _T("---"))) + AppendMenu((HMENU)hMenu, MF_STRING, i + 1, replyList[i].c_str()); + else + AppendMenu((HMENU)hMenu, MF_SEPARATOR, i + 1, NULL); + } + + DBFreeVariant(&dbv); + } + + { + int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, cbcd->pt.x, cbcd->pt.y, 0, cbcd->hwndFrom, NULL); + if (index > 0) + { + if (_tcscmp(replyList.at(index - 1).c_str(), _T(""))) + { + HWND hEdit = GetDlgItem(cbcd->hwndFrom, IDC_MESSAGE); + if (!hEdit) hEdit = GetDlgItem(cbcd->hwndFrom, IDC_CHATMESSAGE); + + SendMessage(hEdit, EM_REPLACESEL, TRUE, (LPARAM)replyList.at(index - 1).c_str()); + + mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); + if ((BYTE)DBGetContactSettingByte(NULL, MODULE_NAME, key, 1) || cbcd->flags & BBCF_CONTROLPRESSED) + SendMessage(cbcd->hwndFrom, WM_COMMAND, IDOK, 0); + } + } + } + + for (std::vector::reverse_iterator item = replyList.rbegin(); item != replyList.rend(); ++item) + ((tString)*item).clear(); + replyList.clear(); + + return 1; +} + +int OnPreShutdown(WPARAM wParam, LPARAM lParam) +{ + if (ServiceExists(MS_BB_REMOVEBUTTON)) + { + char buttonName[32]; + mir_snprintf(buttonName, SIZEOF(buttonName), MODULE_NAME" %x", iNumber + 1); + + BBButton bbd = {0}; + bbd.cbSize = sizeof(BBButton); + bbd.pszModuleName = buttonName; + bbd.dwButtonID = iNumber; + + CallService(MS_BB_REMOVEBUTTON, 0, (LPARAM)&bbd); + } + UnhookEvent(hOnButtonPressed); + UnhookEvent(hOnOptInitialized); + UnhookEvent(hOnPreShutdown); + return 0; +} \ No newline at end of file diff --git a/plugins/QuickReplies/src/options.cpp b/plugins/QuickReplies/src/options.cpp new file mode 100644 index 0000000000..3c96f42e89 --- /dev/null +++ b/plugins/QuickReplies/src/options.cpp @@ -0,0 +1,210 @@ +/* +Copyright (C) 2010 Unsane + +This is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this file; see the file license.txt. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +static WNDPROC OldMessageEditProc; + +static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) +{ + switch(msg) + { + case WM_CHAR: + { + if (wParam == 1 && GetKeyState(VK_CONTROL) & 0x8000) + { // ctrl-a + SendMessage(hwnd, EM_SETSEL, 0, -1); + return 0; + } + + if (wParam == 26 && GetKeyState(VK_CONTROL) & 0x8000) + { // ctrl-z + SendMessage(hwnd, EM_UNDO, 0, 0); + return 0; + } + + if (wParam == 127 && GetKeyState(VK_CONTROL) & 0x8000) + { // ctrl-backspace + DWORD start, end; + WCHAR text[1024]; + + SendMessage(hwnd, EM_GETSEL, (WPARAM) & end, (LPARAM) (PDWORD) NULL); + SendMessage(hwnd, WM_KEYDOWN, VK_LEFT, 0); + SendMessage(hwnd, EM_GETSEL, (WPARAM) & start, (LPARAM) (PDWORD) NULL); + GetWindowText(hwnd, text, 1024); + MoveMemory(text + start, text + end, sizeof(WCHAR) * (wcslen(text) + 1 - end)); + SetWindowText(hwnd, text); + //SAFE_FREE((void**)&text); + SendMessage(hwnd, EM_SETSEL, start, start); + SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hwnd), EN_CHANGE), (LPARAM) hwnd); + return 0; + } + } + break; + } + + return CallWindowProc(OldMessageEditProc, hwnd, msg, wParam, lParam); +} + +INT_PTR CALLBACK DlgProcOptionsPage(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG: + { + char key[64]; + int count = 0; + DBVARIANT dbv = {0}; + tString replies = _T(""); + + TranslateDialogDefault(hwndDlg); + variables_skin_helpbutton(hwndDlg, IDC_VARIABLES); + + SendDlgItemMessage(hwndDlg, IDC_REPLIES, EM_LIMITTEXT, TEXT_LIMIT, 0); + OldMessageEditProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_REPLIES), GWLP_WNDPROC, (LONG_PTR)MessageEditSubclassProc); + + mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); + CheckDlgButton(hwndDlg, IDC_IMMEDIATELY, (BYTE)DBGetContactSettingWord(NULL, MODULE_NAME, key, 1)); + + mir_snprintf(key, 64, "RepliesCount_%x", iNumber); + count = DBGetContactSettingWord(NULL, MODULE_NAME, key, 0); + + for (int i = 0; i < count; i++) + { + mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); + if (!DBGetContactSettingTString(NULL, MODULE_NAME, key, &dbv)) + if(dbv.ptszVal != NULL) + replies.append(dbv.ptszVal); + if (i < count - 1) + replies.append(_T("\r\n")); + } + SetDlgItemText(hwndDlg, IDC_REPLIES, replies.c_str()); + + DBFreeVariant(&dbv); + + return TRUE; + } + break; + + case WM_COMMAND: + { + if (HIWORD(wParam) == BN_CLICKED) + { + switch(LOWORD(wParam)) + { + case IDC_VARIABLES: + { + variables_showhelp(hwndDlg, IDC_REPLIES, VHF_SIMPLEDLG, NULL, NULL); + } + break; + + case IDC_IMMEDIATELY: + { + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + } + break; + } + } + } + break; + + case WM_NOTIFY: + { + NMHDR *p = ((LPNMHDR)lParam); + + switch (p->code) + { + case PSN_APPLY: + { + char key[64]; + int count = 0; + TCHAR tszReplies[TEXT_LIMIT]; + + mir_snprintf(key, 64, "RepliesCount_%x", iNumber); + count = DBGetContactSettingByte(NULL, MODULE_NAME, key, 0); + + for (int i = 0; i < count; i++) + { + mir_snprintf(key, 64, "Reply_%x_%x", iNumber, i); + DBDeleteContactSetting(NULL, MODULE_NAME, key); + } + + GetDlgItemText(hwndDlg, IDC_REPLIES, tszReplies, TEXT_LIMIT); + { + tString replies = tszReplies; + + if (replies.length() > 0) + replies.append(_T("\r\n")); + + count = 0; + tString::size_type pos = tString::npos; + while ((pos = replies.find(_T("\r\n"))) != tString::npos) + { + mir_snprintf(key, 64, "Reply_%x_%x", iNumber, count++); + DBWriteContactSettingTString(NULL, MODULE_NAME, key, replies.substr(0, pos).c_str()); + replies = replies.substr(pos + 2); + } + } + + mir_snprintf(key, 64, "RepliesCount_%x", iNumber); + DBWriteContactSettingWord(NULL, MODULE_NAME, key, count); + + mir_snprintf(key, 64, "ImmediatelySend_%x", iNumber); + DBWriteContactSettingByte(NULL, MODULE_NAME, key, (BYTE)IsDlgButtonChecked(hwndDlg, IDC_IMMEDIATELY)); + + mir_free(key); + + return TRUE; + } + break; + } + } + break; + } + + if (HIWORD(wParam) == EN_CHANGE && GetFocus() == (HWND)lParam) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + + return FALSE; +} + +static UINT expertOnlyControls[] = { IDC_VARIABLES, IDC_VARIABLES_HINT }; + +int OnOptInitialized(WPARAM wParam, LPARAM lParam) +{ + char tabName[32]; + mir_snprintf(tabName, SIZEOF(tabName), "Button %x", iNumber + 1); + + OPTIONSDIALOGPAGE odp = {0}; + odp.cbSize = sizeof(odp); + odp.pszGroup = LPGEN("Message Sessions"); + odp.pszTitle = LPGEN("Quick Replies"); + odp.pszTab = tabName; + odp.position = iNumber; + odp.hInstance = hInstance; + + odp.expertOnlyControls = expertOnlyControls; + odp.nExpertOnlyControls = SIZEOF(expertOnlyControls); + + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS_PAGE); + odp.pfnDlgProc = DlgProcOptionsPage; + Options_AddPage(wParam, &odp); + + return 0; +} \ No newline at end of file diff --git a/plugins/QuickReplies/src/quickreplies.cpp b/plugins/QuickReplies/src/quickreplies.cpp new file mode 100644 index 0000000000..063ef0c8d3 --- /dev/null +++ b/plugins/QuickReplies/src/quickreplies.cpp @@ -0,0 +1,69 @@ +/* +Copyright (C) 2010 Unsane + +This is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with this file; see the file license.txt. If +not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. +*/ + +#include "common.h" + +HINSTANCE hInstance = NULL; +int hLangpack; + +HANDLE hOnModulesLoaded; +HANDLE hOnPreShutdown; + +PLUGININFOEX pluginInfoEx = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // {A6A031B6-D32F-4842-98C6-EC716C576B77} + {0xa6a031b6, 0xd32f, 0x4842, {0x98, 0xc6, 0xec, 0x71, 0x6c, 0x57, 0x6b, 0x77}} +}; + +BOOL WINAPI DllMain(HINSTANCE hInstanceDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + hInstance = hInstanceDLL; + + return TRUE; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfoEx; +} + +extern "C" __declspec(dllexport) int Load(void) +{ + + mir_getLP(&pluginInfoEx); + + hOnModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); + hOnPreShutdown = HookEvent(ME_SYSTEM_PRESHUTDOWN, OnPreShutdown); + + return 0; +} + +extern "C" __declspec(dllexport) int Unload(void) +{ + DestroyServiceFunction(hQuickRepliesService); + return 0; +} diff --git a/plugins/QuickReplies/src/resource.h b/plugins/QuickReplies/src/resource.h new file mode 100644 index 0000000000..a27459012f --- /dev/null +++ b/plugins/QuickReplies/src/resource.h @@ -0,0 +1,29 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by resources.rc +// +#define IDD_OPTIONS_PAGE 101 +#define IDI_QICON 102 +#define IDC_THEMELIST 1001 +#define IDC_RELOAD 1002 +#define IDC_TITLE 1003 +#define IDC_DESCRIPTION 1004 +#define IDC_CONTACTS 1005 +#define IDC_PREVIEW 1006 +#define IDC_NOPREVIEW 1007 +#define IDC_AUTHORS 1008 +#define IDC_IMMEDIATELY 1009 +#define IDC_REPLIES 1010 +#define IDC_VARIABLES 1011 +#define IDC_VARIABLES_HINT 1013 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1014 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/QuickReplies/src/version.h b/plugins/QuickReplies/src/version.h new file mode 100644 index 0000000000..6c87a94d0d --- /dev/null +++ b/plugins/QuickReplies/src/version.h @@ -0,0 +1,20 @@ +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 8 +#define __RELEASE_NUM 1 +#define __BUILD_NUM 0 + +#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM +#define __FILEVERSION_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM + +#define __STRINGIFY_IMPL(x) #x +#define __STRINGIFY(x) __STRINGIFY_IMPL(x) +#define __VERSION_STRING __STRINGIFY(__FILEVERSION_DOTS) + +#define __PLUGIN_NAME "Quick Replies" +#define __INTERNAL_NAME "QuickReplies" +#define __FILENAME "quickreplies.dll" +#define __DESCRIPTION "Plugin for quick insert (or sending) pre-defined messages in message input area." +#define __AUTHOR "Unsane" +#define __AUTHOREMAIL "" +#define __AUTHORWEB "http://nightly.miranda.im/" +#define __COPYRIGHT "© 2010 Unsane" -- cgit v1.2.3