summaryrefslogtreecommitdiff
path: root/libs/mTextControl/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-29 15:12:14 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-29 15:12:14 +0300
commit29407ee1ab79789842fb274b1ed7ac4be83d7d67 (patch)
treec57bdb7d0f7e561d6e291392db987f0a171e08d6 /libs/mTextControl/src
parent83b1ddb1ac3352011cb98c28878ebb777547b0fd (diff)
mTextControl: no need to create this window every time the function is called
Diffstat (limited to 'libs/mTextControl/src')
-rw-r--r--libs/mTextControl/src/richeditutils.cpp15
-rw-r--r--libs/mTextControl/src/services.cpp5
-rw-r--r--libs/mTextControl/src/stdafx.h2
3 files changed, 15 insertions, 7 deletions
diff --git a/libs/mTextControl/src/richeditutils.cpp b/libs/mTextControl/src/richeditutils.cpp
index 31ac38a35b..24392a7560 100644
--- a/libs/mTextControl/src/richeditutils.cpp
+++ b/libs/mTextControl/src/richeditutils.cpp
@@ -108,6 +108,7 @@ void InitRichEdit(ITextServices *ts)
/////////////////////////////////////////////////////////////////////////////////////////
static ATOM winClass = 0;
+static HWND hwndProxy = 0;
static LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
@@ -120,7 +121,7 @@ static LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam,
return 1;
}
-HWND CreateProxyWindow(ITextServices *ts)
+HWND CreateProxyWindow()
{
if (winClass == 0) {
WNDCLASSEX wcl = {};
@@ -134,13 +135,19 @@ HWND CreateProxyWindow(ITextServices *ts)
winClass = RegisterClassExW(&wcl);
}
- 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;
+ if (hwndProxy == 0)
+ hwndProxy = CreateWindow(L"NBRichEditProxyWndClass", L"", 0, 0, 0, 0, 0, nullptr, nullptr, g_hInst, nullptr);
+
+ return hwndProxy;
}
void DestroyProxyWindow()
{
+ if (hwndProxy) {
+ SetWindowLongPtr(hwndProxy, GWLP_USERDATA, 0);
+ DestroyWindow(hwndProxy);
+ }
+
if (winClass != 0)
UnregisterClassW(L"NBRichEditProxyWndClass", g_hInst);
} \ No newline at end of file
diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp
index 317646dcbb..2716bce13b 100644
--- a/libs/mTextControl/src/services.cpp
+++ b/libs/mTextControl/src/services.cpp
@@ -50,7 +50,8 @@ void MText_InitFormatting1(TextObject *text)
bbCodeParse(text->ftd);
// smilies
- HWND hwnd = CreateProxyWindow(text->ftd->getTextService());
+ HWND hwnd = CreateProxyWindow();
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)text->ftd->getTextService());
SMADD_RICHEDIT sm = {};
sm.hwndRichEditControl = hwnd;
@@ -59,7 +60,7 @@ void MText_InitFormatting1(TextObject *text)
sm.flags = SAFLRE_INSERTEMF;
CallService(MS_SMILEYADD_REPLACESMILEYS, 0, (LPARAM)&sm);
- DestroyWindow(hwnd);
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, 0);
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/mTextControl/src/stdafx.h b/libs/mTextControl/src/stdafx.h
index 44d4514d31..302d594b39 100644
--- a/libs/mTextControl/src/stdafx.h
+++ b/libs/mTextControl/src/stdafx.h
@@ -43,7 +43,7 @@ extern HINSTANCE g_hInst;
extern PCreateTextServices MyCreateTextServices;
void InitRichEdit(ITextServices *ts);
-HWND CreateProxyWindow(ITextServices *ts);
+HWND CreateProxyWindow();
#define MODULTITLE "Text Display"
#define MODULENAME "MTextControl"