diff options
author | George Hazan <ghazan@miranda.im> | 2020-04-03 16:49:50 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2020-04-03 16:49:50 +0300 |
commit | 8beac85f6a7b0538622b67e9d2739155792777a2 (patch) | |
tree | 7b452c8344ed72b3c6f700f1e89dff93b7450daf /plugins | |
parent | 58a9d3dbd775650dd1a8ac51ec78748184b4a657 (diff) |
mTextControl: code cleaning
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ExternalAPI/m_text.h | 25 | ||||
-rw-r--r-- | plugins/mTextControl/src/FormattedTextDraw.cpp | 2 | ||||
-rw-r--r-- | plugins/mTextControl/src/FormattedTextDraw.h | 4 | ||||
-rw-r--r-- | plugins/mTextControl/src/ImageDataObjectHlp.cpp | 1 | ||||
-rw-r--r-- | plugins/mTextControl/src/ImageDataObjectHlp.h | 1 | ||||
-rw-r--r-- | plugins/mTextControl/src/fancy_rtf.cpp | 2 | ||||
-rw-r--r-- | plugins/mTextControl/src/fancy_rtf.h | 6 | ||||
-rw-r--r-- | plugins/mTextControl/src/main.cpp | 11 | ||||
-rw-r--r-- | plugins/mTextControl/src/richeditutils.cpp | 61 | ||||
-rw-r--r-- | plugins/mTextControl/src/richeditutils.h | 12 | ||||
-rw-r--r-- | plugins/mTextControl/src/services.cpp | 15 | ||||
-rw-r--r-- | plugins/mTextControl/src/stdafx.h | 10 | ||||
-rw-r--r-- | plugins/mTextControl/src/textcontrol.h | 25 |
13 files changed, 55 insertions, 120 deletions
diff --git a/plugins/ExternalAPI/m_text.h b/plugins/ExternalAPI/m_text.h index 0099be9a77..3a7ed7a408 100644 --- a/plugins/ExternalAPI/m_text.h +++ b/plugins/ExternalAPI/m_text.h @@ -36,19 +36,20 @@ #define DLL_CALLCONV __stdcall
#endif
-typedef struct _tagMTEXT_interface {
+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);
+ 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);
-} MTEXT_INTERFACE;
+};
// get access to the interface
// wParam = 0
@@ -56,7 +57,7 @@ typedef struct _tagMTEXT_interface { // dont vorget to set cbSize before call service
#define MS_TEXT_GETINTERFACE "MText/GetInterface"
-__forceinline INT_PTR mir_getMTI( MTEXT_INTERFACE* dest )
+__forceinline INT_PTR mir_getMTI(MTEXT_INTERFACE *dest)
{
dest->cbSize = sizeof(*dest);
INT_PTR result = CallService(MS_TEXT_GETINTERFACE, 0, (LPARAM)dest);
diff --git a/plugins/mTextControl/src/FormattedTextDraw.cpp b/plugins/mTextControl/src/FormattedTextDraw.cpp index 346cb8f1e2..4a72932d26 100644 --- a/plugins/mTextControl/src/FormattedTextDraw.cpp +++ b/plugins/mTextControl/src/FormattedTextDraw.cpp @@ -5,7 +5,7 @@ // FormattedTextDraw.cpp : Implementation of CFormattedTextDraw
#include "stdafx.h"
-
+#include "FormattedTextDraw.h"
const IID IID_ITextServices = { // 8d33f740-cf58-11ce-a89d-00aa006cadc5
0x8d33f740,
diff --git a/plugins/mTextControl/src/FormattedTextDraw.h b/plugins/mTextControl/src/FormattedTextDraw.h index c44d1f25e5..55c1e73254 100644 --- a/plugins/mTextControl/src/FormattedTextDraw.h +++ b/plugins/mTextControl/src/FormattedTextDraw.h @@ -22,8 +22,6 @@ struct COOKIE size_t cbSize, cbCount;
};
-extern HRESULT(WINAPI *MyCreateTextServices)(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
-
/////////////////////////////////////////////////////////////////////////////
// IFormatttedTextDraw
interface IFormattedTextDraw
@@ -188,4 +186,6 @@ public: ITextDocument *m_spTextDocument;
};
+void bbCodeParse(IFormattedTextDraw *ts);
+
#endif //__FORMATTEDTEXTDRAW_H_
diff --git a/plugins/mTextControl/src/ImageDataObjectHlp.cpp b/plugins/mTextControl/src/ImageDataObjectHlp.cpp index 3c7a66eb55..e928834ff1 100644 --- a/plugins/mTextControl/src/ImageDataObjectHlp.cpp +++ b/plugins/mTextControl/src/ImageDataObjectHlp.cpp @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. //code taken partly from public example on the internet, source unknown.
#include "stdafx.h"
+#include "ImageDataObjectHlp.h"
struct EMFCACHE
{
diff --git a/plugins/mTextControl/src/ImageDataObjectHlp.h b/plugins/mTextControl/src/ImageDataObjectHlp.h index 4884d2a1f2..bae3a59305 100644 --- a/plugins/mTextControl/src/ImageDataObjectHlp.h +++ b/plugins/mTextControl/src/ImageDataObjectHlp.h @@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. void UnloadEmfCache();
HENHMETAFILE CacheIconToEmf(HICON hIcon);
-//bool InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap, HGLOBAL hGlobal);
bool InsertBitmap(IRichEditOle* pRichEditOle, HENHMETAFILE hEmf);
#endif
diff --git a/plugins/mTextControl/src/fancy_rtf.cpp b/plugins/mTextControl/src/fancy_rtf.cpp index 6aacfe0362..179b908236 100644 --- a/plugins/mTextControl/src/fancy_rtf.cpp +++ b/plugins/mTextControl/src/fancy_rtf.cpp @@ -1,4 +1,6 @@ #include "stdafx.h"
+#include "ImageDataObjectHlp.h"
+#include "FormattedTextDraw.h"
struct BBCodeInfo
{
diff --git a/plugins/mTextControl/src/fancy_rtf.h b/plugins/mTextControl/src/fancy_rtf.h deleted file mode 100644 index ed1fcb1d2c..0000000000 --- a/plugins/mTextControl/src/fancy_rtf.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __fancy_rtf_h__
-#define __fancy_rtf_h__
-
-void bbCodeParse(IFormattedTextDraw *ts);
-
-#endif // __fancy_rtf_h__
diff --git a/plugins/mTextControl/src/main.cpp b/plugins/mTextControl/src/main.cpp index 512b86a543..d1ded43909 100644 --- a/plugins/mTextControl/src/main.cpp +++ b/plugins/mTextControl/src/main.cpp @@ -25,8 +25,7 @@ CMPlugin g_plugin; HMODULE hMsfteditDll = nullptr;
-typedef HRESULT(WINAPI *pfnMyCreateTextServices)(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
-pfnMyCreateTextServices MyCreateTextServices = nullptr;
+PCreateTextServices MyCreateTextServices = nullptr;
/////////////////////////////////////////////////////////////////////////////////////////
@@ -50,14 +49,15 @@ CMPlugin::CMPlugin() : /////////////////////////////////////////////////////////////////////////////////////////
+void MTextControl_RegisterClass();
+
int CMPlugin::Load()
{
MyCreateTextServices = nullptr;
hMsfteditDll = LoadLibrary(L"msftedit.dll");
if (hMsfteditDll)
- MyCreateTextServices = (pfnMyCreateTextServices)GetProcAddress(hMsfteditDll, "CreateTextServices");
+ MyCreateTextServices = (PCreateTextServices)GetProcAddress(hMsfteditDll, "CreateTextServices");
- LoadRichEdit();
LoadTextUsers();
LoadServices();
@@ -67,10 +67,11 @@ int CMPlugin::Load() /////////////////////////////////////////////////////////////////////////////////////////
+void UnloadEmfCache();
+
int CMPlugin::Unload()
{
UnloadTextUsers();
- UnloadRichEdit();
UnloadEmfCache();
FreeLibrary(hMsfteditDll);
return 0;
diff --git a/plugins/mTextControl/src/richeditutils.cpp b/plugins/mTextControl/src/richeditutils.cpp index 694be13db4..c5cb7eeb9e 100644 --- a/plugins/mTextControl/src/richeditutils.cpp +++ b/plugins/mTextControl/src/richeditutils.cpp @@ -3,16 +3,12 @@ class CREOleCallback : public IRichEditOleCallback
{
private:
- unsigned refCount;
- IStorage *pictStg;
- int nextStgId;
+ unsigned refCount = 1;
+ IStorage *pictStg = nullptr;
+ int nextStgId = 0;
+
public:
- CREOleCallback()
- {
- refCount = 1;
- pictStg = nullptr;
- nextStgId = 0;
- }
+ CREOleCallback() {}
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID * ppvObj)
{
@@ -101,15 +97,19 @@ public: }
};
-IRichEditOleCallback *reOleCallback = nullptr;
+static CREOleCallback reOleCallback;
void InitRichEdit(ITextServices *ts)
{
LRESULT lResult;
- ts->TxSendMessage(EM_SETOLECALLBACK, 0, (LPARAM)reOleCallback, &lResult);
+ ts->TxSendMessage(EM_SETOLECALLBACK, 0, (LPARAM)&reOleCallback, &lResult);
}
-LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static ATOM winClass = 0;
+
+static LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
ITextServices *ts = (ITextServices *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (ts && (msg != WM_DESTROY)) {
@@ -120,33 +120,20 @@ LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM return 1;
}
-void LoadRichEdit()
-{
- reOleCallback = new CREOleCallback;
-
- WNDCLASSEX wcl;
- wcl.cbSize = sizeof(wcl);
- wcl.lpfnWndProc = RichEditProxyWndProc;
- wcl.style = CS_GLOBALCLASS;
- wcl.cbClsExtra = 0;
- wcl.cbWndExtra = 0;
- wcl.hInstance = g_plugin.getInst();
- wcl.hIcon = nullptr;
- wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
- wcl.lpszMenuName = nullptr;
- wcl.lpszClassName = L"NBRichEditProxyWndClass";
- wcl.hIconSm = nullptr;
- RegisterClassEx(&wcl);
-}
-
-void UnloadRichEdit()
-{
- delete reOleCallback;
-}
-
HWND CreateProxyWindow(ITextServices *ts)
{
+ if (winClass == 0) {
+ WNDCLASSEX wcl = {};
+ wcl.cbSize = sizeof(wcl);
+ wcl.lpfnWndProc = RichEditProxyWndProc;
+ wcl.style = CS_GLOBALCLASS;
+ wcl.hInstance = g_plugin.getInst();
+ 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);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)ts);
return hwnd;
diff --git a/plugins/mTextControl/src/richeditutils.h b/plugins/mTextControl/src/richeditutils.h deleted file mode 100644 index a459f62f6a..0000000000 --- a/plugins/mTextControl/src/richeditutils.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __richeditutils_h__
-#define __richeditutils_h__
-
-extern IRichEditOleCallback *reOleCallback;
-
-void LoadRichEdit();
-void UnloadRichEdit();
-
-void InitRichEdit(ITextServices *ts);
-HWND CreateProxyWindow(ITextServices *ts);
-
-#endif // __richeditutils_h__
diff --git a/plugins/mTextControl/src/services.cpp b/plugins/mTextControl/src/services.cpp index c75673f918..d004fc2c07 100644 --- a/plugins/mTextControl/src/services.cpp +++ b/plugins/mTextControl/src/services.cpp @@ -18,20 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "stdafx.h"
-
-static HANDLE hService[11] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
-
-INT_PTR MText_Register(WPARAM, LPARAM);
-INT_PTR MText_Create(WPARAM, LPARAM);
-INT_PTR MText_CreateW(WPARAM, LPARAM);
-INT_PTR MText_CreateEx(WPARAM, LPARAM);
-INT_PTR MText_Measure(WPARAM, LPARAM);
-INT_PTR MText_Display(WPARAM, LPARAM);
-INT_PTR MText_SetParent(WPARAM, LPARAM);
-INT_PTR MText_SendMessage(WPARAM, LPARAM);
-INT_PTR MText_CreateProxy(WPARAM, LPARAM);
-INT_PTR MText_Destroy(WPARAM, LPARAM);
-INT_PTR MText_GetInterface(WPARAM, LPARAM);
+#include "FormattedTextDraw.h"
struct TextObject
{
diff --git a/plugins/mTextControl/src/stdafx.h b/plugins/mTextControl/src/stdafx.h index 27ec265e2d..ef5263042a 100644 --- a/plugins/mTextControl/src/stdafx.h +++ b/plugins/mTextControl/src/stdafx.h @@ -41,11 +41,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "version.h"
#include "services.h"
#include "textusers.h"
-#include "richeditutils.h"
-#include "ImageDataObjectHlp.h"
-#include "FormattedTextDraw.h"
-#include "fancy_rtf.h"
-#include "textcontrol.h"
+
+extern PCreateTextServices MyCreateTextServices;
+
+void InitRichEdit(ITextServices *ts);
+HWND CreateProxyWindow(ITextServices *ts);
#define MODULTITLE "Text Display"
diff --git a/plugins/mTextControl/src/textcontrol.h b/plugins/mTextControl/src/textcontrol.h deleted file mode 100644 index ef694263ae..0000000000 --- a/plugins/mTextControl/src/textcontrol.h +++ /dev/null @@ -1,25 +0,0 @@ -/*
-Miranda Text Control - Plugin for Miranda IM
-Copyright (C) 2005 Victor Pavlychko (nullbie@gmail.com)
-
-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
-*/
-
-#ifndef __textcontrol_h__
-#define __textcontrol_h__
-
-void MTextControl_RegisterClass();
-
-#endif // __textcontrol_h__
\ No newline at end of file |