From e3f92ff9b8922e06a717a84b76c4e43cbb165f28 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 3 Apr 2020 19:59:38 +0300 Subject: mtextcontrol became an usual library --- plugins/ExternalAPI/m_text.h | 314 +++-------------------------- plugins/NewStory/NewStory.vcxproj | 5 + plugins/NewStory/src/history_control.cpp | 4 +- plugins/mTextControl/mtextcontrol.vcxproj | 4 +- plugins/mTextControl/src/main.cpp | 66 +++--- plugins/mTextControl/src/richeditutils.cpp | 4 +- plugins/mTextControl/src/services.cpp | 230 +++++---------------- plugins/mTextControl/src/services.h | 8 - plugins/mTextControl/src/stdafx.h | 14 +- plugins/mTextControl/src/textcontrol.cpp | 13 +- plugins/mTextControl/src/textusers.cpp | 49 ++--- plugins/mTextControl/src/textusers.h | 5 - 12 files changed, 136 insertions(+), 580 deletions(-) diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h index 3a7ed7a408..2c4a5b231e 100644 --- a/plugins/ExternalAPI/m_text.h +++ b/plugins/ExternalAPI/m_text.h @@ -1,68 +1,22 @@ #ifndef __mtext_h__ #define __mtext_h__ -// NEW mtextcontrol interface: -// -// obtain the full mtextcontrol interface from the library. it is much faster as use of -// miranda core CallService to access to mtextcontrol (no core traffic). -// This interface provides full access to mtextcontrol internal functions, -// thus enabling devs to fully utilize the mtextcontrol API. -// All functions will be exported as miranda services for compatibility. -// -// the interface is populated during the Load(PLUGINLINK *link) handler, so you can assume it is ready when Miranda -// throw the ME_SYSTEM_MODULESLOADED event and you can generate a warning in your ModulesLoaded() when -// it depends on the mtextcontrol interface and the mtextcontrol plugin is missing. -// -// example: -// -// MTEXT_INTERFACE MText = {0}; -// -// mir_getMTI(&MText); -// -// all interface function designed as old mtextcontrol helper functions. -// therefore it is easy to convert your old plugin code to new interface. -// -// example: -// -// old code: MTextCreate (... -// new code: MText.Create(... - // Text control #define MTEXTCONTROLCLASS "MTextControl" #define MTM_SETUSER WM_USER #define MTM_UPDATE WM_USER+1 -#if defined(_WIN32) || defined(__WIN32__) - #define DLL_CALLCONV __stdcall -#endif - -struct MTEXT_INTERFACE -{ - size_t cbSize; - DWORD version; - HANDLE (DLL_CALLCONV *Register) (const char *userTitle, DWORD options); - HANDLE (DLL_CALLCONV *Create) (HANDLE userHandle, TCHAR *text); - HANDLE (DLL_CALLCONV *CreateEx) (HANDLE userHandle, void *text, DWORD flags); - int (DLL_CALLCONV *Measure) (HDC dc, SIZE *sz, HANDLE text); - int (DLL_CALLCONV *Display) (HDC dc, POINT pos, SIZE sz, HANDLE text); - int (DLL_CALLCONV *SetParent) (HANDLE text, HWND hwnd, RECT rect); - int (DLL_CALLCONV *SendMsg) (HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam); - HWND (DLL_CALLCONV *CreateProxy) (HANDLE text); - int (DLL_CALLCONV *Destroy) (HANDLE text); -}; +#ifdef MTEXTCONTROL_EXPORTS + #define MTEXTCONTROL_EXPORT __declspec(dllexport) +#else + #define MTEXTCONTROL_EXPORT __declspec(dllimport) +#endif -// get access to the interface -// wParam = 0 -// lParam = (LPARAM)(MTEXT_INTERFACE*)Mtext -// dont vorget to set cbSize before call service -#define MS_TEXT_GETINTERFACE "MText/GetInterface" +#define MTEXTCONTROL_DLL(T) MTEXTCONTROL_EXPORT T __stdcall -__forceinline INT_PTR mir_getMTI(MTEXT_INTERFACE *dest) -{ - dest->cbSize = sizeof(*dest); - INT_PTR result = CallService(MS_TEXT_GETINTERFACE, 0, (LPARAM)dest); - return result; -} +#ifdef __cplusplus +extern "C" { +#endif enum { @@ -89,259 +43,39 @@ enum MTEXT_FLG_BIDI_RTL = 0x00000002 }; -#if defined(UNICODE) || defined (_UNICODE) - #define MTEXT_FLG_TCHAR MTEXT_FLG_WCHAR -#else - #define MTEXT_FLG_TCHAR MTEXT_FLG_CHAR -#endif - -// used in MS_TEXT_CREATEEX -typedef struct tagMTEXTCREATE -{ - DWORD cbSize; - MCONTACT hContact; - void *text; // this is 'char *' or 'WCHAR *' - DWORD flags; - - #ifdef __cplusplus - tagMTEXTCREATE(): - text(nullptr), hContact(0), flags(0) - { - cbSize = sizeof(*this); - } - #endif -} MTEXTCREATE, *LPMTEXTCREATE; - -// used in MS_TEXT_MEASURE and MS_TEXT_DISPLAY -typedef struct tagMTEXTDISPLAY -{ - DWORD cbSize; - HDC dc; - POINT pos; - SIZE sz; - HANDLE text; - - #ifdef __cplusplus - tagMTEXTDISPLAY(): - dc(nullptr), text(nullptr) - { - cbSize = sizeof(*this); - pos.x = pos.y = 0; - sz.cx = sz.cy = 0; - } - #endif -} MTEXTDISPLAY, *LPMTEXTDISPLAY; - -// used in MS_TEXT_SETPARENT -typedef struct tagMTEXTSETPARENT -{ - HANDLE text; - HWND hwnd; - RECT rc; - - #ifdef __cplusplus - tagMTEXTSETPARENT(): - hwnd(nullptr), text(nullptr) - { - } - #endif -} MTEXTSETPARENT, *LPMTEXTSETPARENT; - -// used in MS_TEXT_SENDMESSAGE -typedef struct tagMTEXTMESSAGE -{ - HWND hwnd; - HANDLE text; - UINT msg; - WPARAM wParam; - LPARAM lParam; - - #ifdef __cplusplus - tagMTEXTMESSAGE(): - hwnd(nullptr), text(nullptr), msg(0), wParam(0), lParam(0) - { - } - #endif -} MTEXTMESSAGE, *LPMTEXTMESSAGE; - -//--------------------------------------------------------------------------- -// deprecatet service and helper functions -// replaced by new mtext interface !!!!!!! -//--------------------------------------------------------------------------- -#if defined(NOHELPERS) || defined(MIRANDA_NOHELPERS) - #define MTEXT_NOHELPERS -#endif - // subscribe to MText services -// wParam = (WPARAM)(DOWRD)defaultOptions -// lParam = (LPARAM)(char *)userTitle -// result = (LRESULT)(HANDLE)userHandle -#define MS_TEXT_REGISTER "MText/Register" - -#ifndef MTEXT_NOHELPERS -__inline HANDLE MTextRegister(const char *userTitle, DWORD options) -{ - return (HANDLE)CallService(MS_TEXT_REGISTER, (WPARAM)options, (LPARAM)userTitle); -} -#endif // MTEXT_NOHELPERS +MTEXTCONTROL_DLL(HANDLE) MTextRegister(const char *userTitle, DWORD options); // allocate text object (unicode) -// wParam = (WPARAM)(HANDLE)userHandle -// lParam = (LPARAM)(WCHAR *)text -// result = (LRESULT)(HANDLE)textHandle -#define MS_TEXT_CREATEW "MText/CreateW" - -#ifndef MTEXT_NOHELPERS -__inline HANDLE MTextCreateW(HANDLE userHandle, WCHAR *text) -{ - return (HANDLE)CallService(MS_TEXT_CREATEW, (WPARAM)userHandle, (LPARAM)text); -} -#endif // MTEXT_NOHELPERS +MTEXTCONTROL_DLL(HANDLE) MTextCreateW(HANDLE userHandle, WCHAR *text); // allocate text object (advanced) -// wParam = (WPARAM)(HANDLE)userHandle -// lParam = (LPARAM)(LPMTEXTCREATE)createInfo -// result = (LRESULT)(HANDLE)textHandle -#define MS_TEXT_CREATEEX "MText/CreateEx" +MTEXTCONTROL_DLL(HANDLE) MTextCreateEx(HANDLE userHandle, void *text, DWORD flags); -#ifndef MTEXT_NOHELPERS -__inline HANDLE MTextCreateEx(HANDLE userHandle, MCONTACT hContact, void *text, DWORD flags) -{ - #ifdef __cplusplus - MTEXTCREATE textCreate; - #else - MTEXTCREATE textCreate = {0}; - textCreate.cbSize = sizeof(textCreate); - #endif - textCreate.hContact = hContact; - textCreate.text = text; - textCreate.flags = flags; - return (HANDLE)CallService(MS_TEXT_CREATEEX, (WPARAM)userHandle, (LPARAM)&textCreate); -} -#endif // MTEXT_NOHELPERS +// destroys text object +MTEXTCONTROL_DLL(int) MTextDestroy(HANDLE text); -// measure text object -// wParam = (LPARAM)(LPMTEXTDISPLAY)displayInfo +// measures text object // result = 1 (success), 0 (failure) -// displayInfo->size.cx is interpreted as maximum width allowed. -// wrapped text size is stored in displayInfo->size, text -#define MS_TEXT_MEASURE "MText/Measure" - -#ifndef MTEXT_NOHELPERS -__inline int MTextMeasure(HDC dc, SIZE *sz, HANDLE text) -{ - #ifdef __cplusplus - MTEXTDISPLAY displayInfo; - #else - MTEXTDISPLAY displayInfo = {0}; - displayInfo.cbSize = sizeof(displayInfo); - #endif - displayInfo.dc = dc; - displayInfo.pos.x = displayInfo.pos.y = 0; - displayInfo.sz = *sz; - displayInfo.text = text; - int result = (int)CallService(MS_TEXT_MEASURE, (WPARAM)&displayInfo, 0); - *sz = displayInfo.sz; - return result; -} -#endif // MTEXT_NOHELPERS +// sz->cx is interpreted as maximum width allowed. +// wrapped text size is stored in sz, text +MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HANDLE text); // display text object -// wParam = (LPARAM)(LPMTEXTDISPLAY)displayInfo // result = 1 (success), 0 (failure) -#define MS_TEXT_DISPLAY "MText/Display" - -#ifndef MTEXT_NOHELPERS -__inline int MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) -{ - #ifdef __cplusplus - MTEXTDISPLAY displayInfo; - #else - MTEXTDISPLAY displayInfo = {0}; - displayInfo.cbSize = sizeof(displayInfo); - #endif - displayInfo.dc = dc; - displayInfo.pos = pos; - displayInfo.sz = sz; - displayInfo.text = text; - return (int)CallService(MS_TEXT_DISPLAY, (WPARAM)&displayInfo, 0); -} -#endif // MTEXT_NOHELPERS +MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text); // set parent window for text object (this is required for mouse handling, etc) -// wParam = (WPARAM)(LPMTEXTSETPARENT)info -// result = message result -#define MS_TEXT_SETPARENT "MText/SetParent" - -#ifndef MTEXT_NOHELPERS -__inline int MTextSetParent(HANDLE text, HWND hwnd, RECT rect) -{ - MTEXTSETPARENT info; - info.text = text; - info.hwnd = hwnd; - info.rc = rect; - return (int)CallService(MS_TEXT_SETPARENT, (WPARAM)&info, 0); -} -#endif // MTEXT_NOHELPERS +MTEXTCONTROL_DLL(int) MTextSetParent(HANDLE text, HWND hwnd, RECT rect); // send message to an object -// wParam = (WPARAM)(LPMTEXTMESSAGE)message -// result = message result -#define MS_TEXT_SENDMESSAGE "MText/SendMessage" +MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam); -#ifndef MTEXT_NOHELPERS -__inline int MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam) -{ - #ifdef __cplusplus - MTEXTMESSAGE message; - #else - MTEXTMESSAGE message = {0}; - #endif - message.hwnd = hwnd; - message.text = text; - message.msg = msg; - message.wParam = wParam; - message.lParam = lParam; - return (int)CallService(MS_TEXT_SENDMESSAGE, (WPARAM)&message, 0); -} -#endif // MTEXT_NOHELPERS +// creates a proxy window +MTEXTCONTROL_DLL(HWND) MTextCreateProxy(HANDLE text); -// create a proxy window -// wParam = (LPARAM)(HANDLE)textHandle -#define MS_TEXT_CREATEPROXY "MText/CreateProxy" - -#ifndef MTEXT_NOHELPERS -__inline HWND MTextCreateProxy(HANDLE text) -{ - return (HWND)CallService(MS_TEXT_CREATEPROXY, (WPARAM)text, 0); +#ifdef __cplusplus } -#endif // MTEXT_NOHELPERS - -// destroy text object -// wParam = (LPARAM)(HANDLE)textHandle -#define MS_TEXT_DESTROY "MText/Destroy" - -#ifndef MTEXT_NOHELPERS -__inline int MTextDestroy(HANDLE text) -{ - return (int)CallService(MS_TEXT_DESTROY, (WPARAM)text, 0); -} -#endif // MTEXT_NOHELPERS - -//#define MS_TEXT_QDISPLAY "MText/QDisplay" -//#define MS_TEXT_QDISPLAYW "MText/QDisplayW" - -// T-definitions for unicode -#if defined(UNICODE) || defined (_UNICODE) - #define MS_TEXT_CREATET MS_TEXT_CREATEW - #ifndef MTEXT_NOHELPERS - #define MTextCreateT MTextCreateW - #endif -#else - #define MS_TEXT_CREATET MS_TEXT_CREATE - #ifndef MTEXT_NOHELPERS - #define MTextCreateT MTextCreate - #endif #endif #endif // __mtext_h__ diff --git a/plugins/NewStory/NewStory.vcxproj b/plugins/NewStory/NewStory.vcxproj index 60b6c075ab..9aed0cb0b9 100644 --- a/plugins/NewStory/NewStory.vcxproj +++ b/plugins/NewStory/NewStory.vcxproj @@ -18,6 +18,11 @@ x64 + + + {e26d2311-c164-48cf-ba24-5ceda873d1b2} + + NewStory {A7FAD273-8C71-4D72-A84F-2D160F2DC589} diff --git a/plugins/NewStory/src/history_control.cpp b/plugins/NewStory/src/history_control.cpp index 315c9b39bd..2d31fd9023 100644 --- a/plugins/NewStory/src/history_control.cpp +++ b/plugins/NewStory/src/history_control.cpp @@ -786,7 +786,7 @@ static int LayoutItem(HWND hwnd, HistoryArray *items, int index) HFONT hfnt = (HFONT)SelectObject(hdc, fonts[fontid].hfnt); if (!item->data) { TCHAR *buf = TplFormatString(tpl, item->hContact, item); - item->data = MTextCreateT(htuLog, buf); + item->data = MTextCreateW(htuLog, buf); free(buf); } @@ -862,7 +862,7 @@ static int PaintItem(HDC hdc, HistoryArray *items, int index, int top, int width if (!item->data) { TCHAR *buf = TplFormatString(tpl, item->hContact, item); - item->data = MTextCreateT(htuLog, buf); + item->data = MTextCreateW(htuLog, buf); free(buf); if (!item->data) return 0; diff --git a/plugins/mTextControl/mtextcontrol.vcxproj b/plugins/mTextControl/mtextcontrol.vcxproj index 0305c22d08..4f6e13e81a 100644 --- a/plugins/mTextControl/mtextcontrol.vcxproj +++ b/plugins/mTextControl/mtextcontrol.vcxproj @@ -23,11 +23,11 @@ {E26D2311-C164-48CF-BA24-5CEDA873D1B2} - + - MTEXT_NOHELPERS;%(PreprocessorDefinitions) + MTEXTCONTROL_EXPORTS;%(PreprocessorDefinitions) \ No newline at end of file diff --git a/plugins/mTextControl/src/main.cpp b/plugins/mTextControl/src/main.cpp index d1ded43909..edd26d0e98 100644 --- a/plugins/mTextControl/src/main.cpp +++ b/plugins/mTextControl/src/main.cpp @@ -21,58 +21,38 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" -CMPlugin g_plugin; - HMODULE hMsfteditDll = nullptr; +HINSTANCE g_hInst = nullptr; PCreateTextServices MyCreateTextServices = nullptr; -///////////////////////////////////////////////////////////////////////////////////////// - -PLUGININFOEX pluginInfoEx = -{ - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), - __DESCRIPTION, - __AUTHOR, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, - // {69B9443B-DC58-4876-AD39-E3F418A133C5} - { 0x69b9443b, 0xdc58, 0x4876, { 0xad, 0x39, 0xe3, 0xf4, 0x18, 0xa1, 0x33, 0xc5 } } -}; - -CMPlugin::CMPlugin() : - PLUGIN("MTextControl", pluginInfoEx) -{} - -///////////////////////////////////////////////////////////////////////////////////////// - void MTextControl_RegisterClass(); -int CMPlugin::Load() -{ - MyCreateTextServices = nullptr; - hMsfteditDll = LoadLibrary(L"msftedit.dll"); - if (hMsfteditDll) - MyCreateTextServices = (PCreateTextServices)GetProcAddress(hMsfteditDll, "CreateTextServices"); - - LoadTextUsers(); - LoadServices(); - - MTextControl_RegisterClass(); - return 0; -} - ///////////////////////////////////////////////////////////////////////////////////////// void UnloadEmfCache(); -int CMPlugin::Unload() +BOOL APIENTRY DllMain(HINSTANCE hInst, DWORD ul_reason_for_call, LPVOID) { - UnloadTextUsers(); - UnloadEmfCache(); - FreeLibrary(hMsfteditDll); - return 0; + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH: + g_hInst = hInst; + MyCreateTextServices = nullptr; + hMsfteditDll = LoadLibrary(L"msftedit.dll"); + if (hMsfteditDll) + MyCreateTextServices = (PCreateTextServices)GetProcAddress(hMsfteditDll, "CreateTextServices"); + + LoadTextUsers(); + + MTextControl_RegisterClass(); + break; + + case DLL_PROCESS_DETACH: + UnloadTextUsers(); + UnloadEmfCache(); + FreeLibrary(hMsfteditDll); + break; + } + + return TRUE; } diff --git a/plugins/mTextControl/src/richeditutils.cpp b/plugins/mTextControl/src/richeditutils.cpp index c5cb7eeb9e..4da0b75d40 100644 --- a/plugins/mTextControl/src/richeditutils.cpp +++ b/plugins/mTextControl/src/richeditutils.cpp @@ -127,14 +127,14 @@ HWND CreateProxyWindow(ITextServices *ts) wcl.cbSize = sizeof(wcl); wcl.lpfnWndProc = RichEditProxyWndProc; wcl.style = CS_GLOBALCLASS; - wcl.hInstance = g_plugin.getInst(); + wcl.hInstance = g_hInst; wcl.hCursor = LoadCursor(nullptr, IDC_ARROW); wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wcl.lpszClassName = L"NBRichEditProxyWndClass"; winClass = RegisterClassEx(&wcl); } - HWND hwnd = CreateWindow(L"NBRichEditProxyWndClass", L"", 0, 0, 0, 0, 0, nullptr, nullptr, g_plugin.getInst(), nullptr); + HWND hwnd = CreateWindow(L"NBRichEditProxyWndClass", L"", 0, 0, 0, 0, 0, nullptr, nullptr, g_hInst, nullptr); SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ts); return hwnd; } diff --git a/plugins/mTextControl/src/services.cpp b/plugins/mTextControl/src/services.cpp index d004fc2c07..8d4e637050 100644 --- a/plugins/mTextControl/src/services.cpp +++ b/plugins/mTextControl/src/services.cpp @@ -28,8 +28,9 @@ struct TextObject ~TextObject() { if (ftd) delete ftd; } }; -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // elper functions + void MText_InitFormatting0(IFormattedTextDraw *ftd, DWORD) { LRESULT lResult; @@ -69,48 +70,11 @@ void MText_InitFormatting1(TextObject *text) */ } -//--------------------------------------------------------------------------- -// NEW mtextcontrol interface: -// -// obtain the full mtextcontrol interface from the library. it is much faster as use of -// miranda core CallService to access to mtextcontrol (no core traffic). -// This interface provides full access to mtextcontrol internal functions, -// thus enabling devs to fully utilize the mtextcontrol API. -// All functions will be exported as miranda services for compatibility. -// -// the interface is populated during the Load(void) handler, so you can assume it is ready when Miranda -// throw the ME_SYSTEM_MODULESLOADED event and you can generate a warning in your ModulesLoaded() when -// it depends on the mtextcontrol interface and the mtextcontrol plugin is missing. -// -// example: -// -// MTEXT_INTERFACE MText = {0}; -// -// mir_getMTI(&MText); -// -// all interface function designed as old mtextcontrol helper functions. -// therefore it is easy to convert your old plugin code to new interface. -// -// example: -// -// old code: MTextCreate (... -// new code: MText.Create(... - -//--------------------------------------------------------------------------- -// subscribe to MText services -INT_PTR MText_Register(WPARAM wParam, LPARAM lParam) -{ - DWORD userOptions = (DWORD)wParam; - char *userTitle = (char *)lParam; - return (INT_PTR)MTI_TextUserAdd(userTitle, userOptions); -} - -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (unicode) -HANDLE DLL_CALLCONV -MTI_MTextCreateW(HANDLE userHandle, WCHAR *text) -{ +MTEXTCONTROL_DLL(HANDLE) MTextCreateW(HANDLE userHandle, WCHAR *text) +{ TextObject *result = new TextObject; result->options = TextUserGetOptions(userHandle); result->ftd = new CFormattedTextDraw; @@ -122,22 +86,12 @@ MTI_MTextCreateW(HANDLE userHandle, WCHAR *text) MText_InitFormatting1(result); return (HANDLE)result; - } -INT_PTR MText_CreateW(WPARAM wParam, LPARAM lParam) -{ - - //HANDLE userHandle = (HANDLE)wParam; - //WCHAR *wtext = (WCHAR *)lParam; - return (INT_PTR)(HANDLE)MTI_MTextCreateW((HANDLE)wParam, (WCHAR *)lParam); - -} - -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // allocate text object (advanced) -HANDLE DLL_CALLCONV -MTI_MTextCreateEx(HANDLE userHandle, void *text, DWORD flags) + +MTEXTCONTROL_DLL(HANDLE) MTextCreateEx(HANDLE userHandle, void *text, DWORD flags) { TextObject *result = new TextObject; result->options = TextUserGetOptions(userHandle); @@ -146,26 +100,20 @@ MTI_MTextCreateEx(HANDLE userHandle, void *text, DWORD flags) InitRichEdit(result->ftd->getTextService()); MText_InitFormatting0(result->ftd, result->options); - if (flags & MTEXT_FLG_WCHAR) result->ftd->putTextW((WCHAR *)text); - else result->ftd->putTextA((char *)text); + if (flags & MTEXT_FLG_WCHAR) + result->ftd->putTextW((WCHAR *)text); + else + result->ftd->putTextA((char *)text); MText_InitFormatting1(result); delete result; return nullptr; } -INT_PTR MText_CreateEx(WPARAM wParam, LPARAM lParam) -{ - HANDLE userHandle = (HANDLE)wParam; - MTEXTCREATE *textCreate = (MTEXTCREATE *)lParam; - MTI_MTextCreateEx(userHandle, textCreate->text, textCreate->flags); - return 0; -} - -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // measure text object -int DLL_CALLCONV -MTI_MTextMeasure(HDC dc, SIZE *sz, HANDLE text) + +MTEXTCONTROL_DLL(int) MTextMeasure(HDC dc, SIZE *sz, HANDLE text) { if (!text) return 0; @@ -173,42 +121,30 @@ MTI_MTextMeasure(HDC dc, SIZE *sz, HANDLE text) ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight); sz->cx = lWidth; sz->cy = lHeight; - // FancyMeasure(((TextObject *)text)->fancy, displayInfo); - - return 0; -} - -INT_PTR MText_Measure(WPARAM wParam, LPARAM) -{ - LPMTEXTDISPLAY displayInfo = (LPMTEXTDISPLAY)wParam; - if (!displayInfo) return 0; - if (!(TextObject *)displayInfo->text) return 0; - MTI_MTextMeasure(displayInfo->dc, &displayInfo->sz, displayInfo->text); return 0; } -int DLL_CALLCONV -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // display text object -MTI_MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) + +MTEXTCONTROL_DLL(int) MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) { if (!text) return 0; COLORREF cl = GetTextColor(dc); - // if (GetTextColor(dc)&0xffffff != 0) - { - LRESULT lResult; - CHARFORMAT cf = { 0 }; - cf.cbSize = sizeof(cf); - cf.dwMask = CFM_COLOR; - cf.crTextColor = cl; - ((TextObject *)text)->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); - } + + LRESULT lResult; + CHARFORMAT cf = { 0 }; + cf.cbSize = sizeof(cf); + cf.dwMask = CFM_COLOR; + cf.crTextColor = cl; + ((TextObject *)text)->ftd->getTextService()->TxSendMessage(EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf, &lResult); SetBkMode(dc, TRANSPARENT); long lWidth = sz.cx, lHeight; ((TextObject *)text)->ftd->get_NaturalSize(dc, &lWidth, &lHeight); + RECT rt; rt.left = pos.x; rt.top = pos.y; @@ -219,42 +155,25 @@ MTI_MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text) return 0; } -INT_PTR MText_Display(WPARAM wParam, LPARAM) -{ - LPMTEXTDISPLAY displayInfo = (LPMTEXTDISPLAY)wParam; - if (!displayInfo) return 0; - if (!displayInfo->text) return 0; - MTI_MTextDisplay(displayInfo->dc, displayInfo->pos, displayInfo->sz, displayInfo->text); - return 0; -} - -int DLL_CALLCONV -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // set parent window for text object (this is required for mouse handling, etc) -MTI_MTextSetParent(HANDLE text, HWND hwnd, RECT rect) -{ - if (!text) return 0; - ((TextObject *)text)->ftd->setParentWnd(hwnd, rect); - return 0; -} -INT_PTR MText_SetParent(WPARAM wParam, LPARAM) +MTEXTCONTROL_DLL(int) MTextSetParent(HANDLE text, HWND hwnd, RECT rect) { - LPMTEXTSETPARENT info = (LPMTEXTSETPARENT)wParam; - //TextObject *text = (TextObject *)info->text; - if (!info) return 0; - if (!info->text) return 0; - MTI_MTextSetParent(info->text, info->hwnd, info->rc); + if (text) + ((TextObject *)text)->ftd->setParentWnd(hwnd, rect); return 0; } -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // send message to an object -int DLL_CALLCONV -MTI_MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam) + +MTEXTCONTROL_DLL(int) MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam) { + if (!text) + return 0; + LRESULT lResult; - if (!text) return 0; ((TextObject *)text)->ftd->getTextService()->TxSendMessage(msg, wParam, lParam, &lResult); if (hwnd && (msg == WM_MOUSEMOVE)) { @@ -266,81 +185,22 @@ MTI_MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lPa return lResult; } -INT_PTR MText_SendMessage(WPARAM wParam, LPARAM) -{ - LPMTEXTMESSAGE message = (LPMTEXTMESSAGE)wParam; - if (!message->text) return 0; - return (INT_PTR)MTI_MTextSendMessage(message->hwnd, message->text, message->msg, message->wParam, message->lParam); -} - -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // create a proxy window -HWND DLL_CALLCONV -MTI_MTextCreateProxy(HANDLE text) -{ - if (!text) return nullptr; - return CreateProxyWindow(((TextObject *)text)->ftd->getTextService()); -} -INT_PTR MText_CreateProxy(WPARAM wParam, LPARAM) +MTEXTCONTROL_DLL(HWND) MTextCreateProxy(HANDLE text) { - if (!wParam) return 0; - return (INT_PTR)MTI_MTextCreateProxy((HANDLE)wParam); + if (!text) + return nullptr; + + return CreateProxyWindow(((TextObject *)text)->ftd->getTextService()); } -int DLL_CALLCONV -//--------------------------------------------------------------------------- +///////////////////////////////////////////////////////////////////////////////////////// // destroy text object -MTI_MTextDestroy(HANDLE text) -{ - //HANDLE textHandle = (HANDLE)wParam; - //TextObject *text = (TextObject *)textHandle; - if (text) delete (TextObject *)text; - return 0; -} -INT_PTR MText_Destroy(WPARAM wParam, LPARAM) +MTEXTCONTROL_DLL(int) MTextDestroy(HANDLE text) { - HANDLE textHandle = (HANDLE)wParam; - TextObject *text = (TextObject *)textHandle; - if (text) delete text; + if (text) delete (TextObject *)text; return 0; } - -//--------------------------------------------------------------------------- -// populate the interface -INT_PTR MText_GetInterface(WPARAM, LPARAM lParam) -{ - MTEXT_INTERFACE *MText = (MTEXT_INTERFACE *)lParam; - if (MText == nullptr) - return CALLSERVICE_NOTFOUND; - - MText->version = PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM); - MText->Register = MTI_TextUserAdd; - MText->Create = MTI_MTextCreateW; - MText->CreateEx = MTI_MTextCreateEx; - MText->Measure = MTI_MTextMeasure; - MText->Display = MTI_MTextDisplay; - MText->SetParent = MTI_MTextSetParent; - MText->SendMsg = MTI_MTextSendMessage; - MText->CreateProxy = MTI_MTextCreateProxy; - MText->Destroy = MTI_MTextDestroy; - - return S_OK; -} - -//--------------------------------------------------------------------------- -// Load / Unload services -void LoadServices() -{ - CreateServiceFunction(MS_TEXT_REGISTER, MText_Register); - CreateServiceFunction(MS_TEXT_CREATEW, MText_CreateW); - CreateServiceFunction(MS_TEXT_CREATEEX, MText_CreateEx); - CreateServiceFunction(MS_TEXT_MEASURE, MText_Measure); - CreateServiceFunction(MS_TEXT_DISPLAY, MText_Display); - CreateServiceFunction(MS_TEXT_SETPARENT, MText_SetParent); - CreateServiceFunction(MS_TEXT_SENDMESSAGE, MText_SendMessage); - CreateServiceFunction(MS_TEXT_CREATEPROXY, MText_CreateProxy); - CreateServiceFunction(MS_TEXT_DESTROY, MText_Destroy); - CreateServiceFunction(MS_TEXT_GETINTERFACE, MText_GetInterface); -} diff --git a/plugins/mTextControl/src/services.h b/plugins/mTextControl/src/services.h index d91b1366b3..8a75e24eed 100644 --- a/plugins/mTextControl/src/services.h +++ b/plugins/mTextControl/src/services.h @@ -22,13 +22,5 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA void LoadServices(); -__declspec(dllexport) HANDLE DLL_CALLCONV MTI_MTextCreateW(HANDLE userHandle, WCHAR *text); -__declspec(dllexport) HANDLE DLL_CALLCONV MTI_MTextCreateEx(HANDLE userHandle, void *text, DWORD flags); -__declspec(dllexport) int DLL_CALLCONV MTI_MTextMeasure(HDC dc, SIZE *sz, HANDLE text); -__declspec(dllexport) int DLL_CALLCONV MTI_MTextDisplay(HDC dc, POINT pos, SIZE sz, HANDLE text); -__declspec(dllexport) int DLL_CALLCONV MTI_MTextSetParent(HANDLE text, HWND hwnd, RECT rect); -__declspec(dllexport) int DLL_CALLCONV MTI_MTextSendMessage(HWND hwnd, HANDLE text, UINT msg, WPARAM wParam, LPARAM lParam); -__declspec(dllexport) HWND DLL_CALLCONV MTI_MTextCreateProxy(HANDLE text); -__declspec(dllexport) int DLL_CALLCONV MTI_MTextDestroy(HANDLE text); #endif // __services_h__ diff --git a/plugins/mTextControl/src/stdafx.h b/plugins/mTextControl/src/stdafx.h index ef5263042a..1608622157 100644 --- a/plugins/mTextControl/src/stdafx.h +++ b/plugins/mTextControl/src/stdafx.h @@ -30,7 +30,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include -#include #include #include #include @@ -39,24 +38,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include "version.h" -#include "services.h" #include "textusers.h" +extern HINSTANCE g_hInst; extern PCreateTextServices MyCreateTextServices; void InitRichEdit(ITextServices *ts); HWND CreateProxyWindow(ITextServices *ts); #define MODULTITLE "Text Display" - -// globals - -struct CMPlugin : public PLUGIN -{ - CMPlugin(); - - int Load() override; - int Unload() override; -}; +#define MODULENAME "MTextControl" #endif // __headers_h__ diff --git a/plugins/mTextControl/src/textcontrol.cpp b/plugins/mTextControl/src/textcontrol.cpp index a9f3263794..596677f23f 100644 --- a/plugins/mTextControl/src/textcontrol.cpp +++ b/plugins/mTextControl/src/textcontrol.cpp @@ -36,7 +36,7 @@ void MTextControl_RegisterClass() wcl.cbSize = sizeof(wcl); wcl.lpfnWndProc = MTextControlWndProc; wcl.style = CS_GLOBALCLASS; - wcl.hInstance = g_plugin.getInst(); + wcl.hInstance = g_hInst; wcl.hCursor = LoadCursor(nullptr, IDC_ARROW); wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wcl.lpszClassName = L"MTextControl"; @@ -66,15 +66,15 @@ LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case MTM_UPDATE: if (data->text) delete[] data->text; - if (data->mtext) MTI_MTextDestroy(data->mtext); + if (data->mtext) MTextDestroy(data->mtext); { int textLength = GetWindowTextLength(hwnd); data->text = new wchar_t[textLength + 1]; GetWindowText(hwnd, data->text, textLength + 1); - data->mtext = MTI_MTextCreateW(data->htu, data->text); + data->mtext = MTextCreateW(data->htu, data->text); RECT rc; GetClientRect(hwnd, &rc); - MTI_MTextSetParent(data->mtext, hwnd, rc); + MTextSetParent(data->mtext, hwnd, rc); InvalidateRect(hwnd, nullptr, TRUE); } @@ -91,7 +91,7 @@ LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM case WM_MOUSEMOVE: if (data && data->mtext) - return MTI_MTextSendMessage(hwnd, data->mtext, msg, wParam, lParam); + return MTextSendMessage(hwnd, data->mtext, msg, wParam, lParam); break; } @@ -134,7 +134,7 @@ LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM, LPARAM) SIZE sz; sz.cx = rc.right - rc.left; sz.cy = rc.bottom - rc.top - 4; - MTI_MTextDisplay(hdc, pos, sz, data->mtext); + MTextDisplay(hdc, pos, sz, data->mtext); if (hfntSave) SelectObject(hdc, hfntSave); @@ -142,6 +142,5 @@ LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM, LPARAM) // Release the device context EndPaint(hwnd, &ps); - return 0; } diff --git a/plugins/mTextControl/src/textusers.cpp b/plugins/mTextControl/src/textusers.cpp index 22abd621ae..5b879a70de 100644 --- a/plugins/mTextControl/src/textusers.cpp +++ b/plugins/mTextControl/src/textusers.cpp @@ -21,32 +21,17 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA HANDLE htuDefault = nullptr; -TextUser *textUserFirst = nullptr; -TextUser *textUserLast = nullptr; +static TextUser *textUserFirst = nullptr; +static TextUser *textUserLast = nullptr; -void LoadTextUsers() -{ - htuDefault = MTI_TextUserAdd("Text Controls", MTEXT_FANCY_MASK); -} - -void UnloadTextUsers() -{ - while (textUserFirst) { - delete[] textUserFirst->name; - TextUser *next = textUserFirst->next; - delete[] textUserFirst; - textUserFirst = next; - } -} - -HANDLE DLL_CALLCONV MTI_TextUserAdd(const char *userTitle, DWORD options) +MTEXTCONTROL_DLL(HANDLE) MTextRegister(const char *userTitle, DWORD options) { TextUser *textUserNew = new TextUser; textUserNew->name = new char[mir_strlen(userTitle) + 1]; mir_strcpy(textUserNew->name, userTitle); textUserNew->options = - (g_plugin.getDword(userTitle, options)&MTEXT_FANCY_MASK) | (textUserNew->options&MTEXT_SYSTEM_MASK); - g_plugin.setDword(userTitle, textUserNew->options); + (db_get_dw(0, MODULENAME, userTitle, options)&MTEXT_FANCY_MASK) | (textUserNew->options&MTEXT_SYSTEM_MASK); + db_set_dw(0, MODULENAME, userTitle, textUserNew->options); textUserNew->prev = textUserLast; textUserNew->next = nullptr; if (textUserLast) { @@ -55,7 +40,7 @@ HANDLE DLL_CALLCONV MTI_TextUserAdd(const char *userTitle, DWORD options) } else textUserFirst = textUserLast = textUserNew; - return (HANDLE)textUserNew; + return textUserNew; } DWORD TextUserGetOptions(HANDLE userHandle) @@ -73,12 +58,28 @@ void TextUserSetOptions(HANDLE userHandle, DWORD options) void TextUsersSave() { for (TextUser *textUser = textUserFirst; textUser; textUser = textUser->next) - g_plugin.setDword(textUser->name, textUser->options); + db_set_dw(0, MODULENAME, textUser->name, textUser->options); } void TextUsersReset() { for (TextUser *textUser = textUserFirst; textUser; textUser = textUser->next) - textUser->options = - (g_plugin.getDword(textUser->name, 0)&MTEXT_FANCY_MASK) | (textUser->options&MTEXT_SYSTEM_MASK); + textUser->options = (db_get_dw(0, MODULENAME, textUser->name, 0) & MTEXT_FANCY_MASK) | (textUser->options&MTEXT_SYSTEM_MASK); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +void LoadTextUsers() +{ + htuDefault = MTextRegister("Text Controls", MTEXT_FANCY_MASK); +} + +void UnloadTextUsers() +{ + while (textUserFirst) { + delete[] textUserFirst->name; + TextUser *next = textUserFirst->next; + delete[] textUserFirst; + textUserFirst = next; + } } diff --git a/plugins/mTextControl/src/textusers.h b/plugins/mTextControl/src/textusers.h index 28e2fb27d3..845386c859 100644 --- a/plugins/mTextControl/src/textusers.h +++ b/plugins/mTextControl/src/textusers.h @@ -29,16 +29,11 @@ struct TextUser : public MZeroedObject TextUser *prev, *next; }; -extern TextUser *textUserFirst; -extern TextUser *textUserLast; - void LoadTextUsers(); void UnloadTextUsers(); extern HANDLE htuDefault; -__declspec(dllexport) HANDLE DLL_CALLCONV MTI_TextUserAdd(const char *userTitle, DWORD options); - DWORD TextUserGetOptions(HANDLE userHandle); void TextUserSetOptions(HANDLE userHandle, DWORD options); void TextUsersSave(); -- cgit v1.2.3