summaryrefslogtreecommitdiff
path: root/libs/mTextControl
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-10-30 13:25:54 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-10-30 13:25:54 +0300
commit029872c0b8993f84ac2cad5ac701d6056aad2d7d (patch)
tree6d994284218075bbe8ff460949258c93e44cb8c2 /libs/mTextControl
parenteb7783cca53e945354b83aa3899ca9cdb0602dbd (diff)
code cleaning
Diffstat (limited to 'libs/mTextControl')
-rw-r--r--libs/mTextControl/src/services.cpp4
-rw-r--r--libs/mTextControl/src/textcontrol.cpp143
2 files changed, 72 insertions, 75 deletions
diff --git a/libs/mTextControl/src/services.cpp b/libs/mTextControl/src/services.cpp
index c3d568e56c..bd7eee6a50 100644
--- a/libs/mTextControl/src/services.cpp
+++ b/libs/mTextControl/src/services.cpp
@@ -119,9 +119,7 @@ MTEXTCONTROL_DLL(TextObject *) MTextCreateEx(HANDLE userHandle, void *text, uint
result->ftd->putTextA((char *)text);
}
MText_InitFormatting1(result);
- delete result;
-
- return nullptr;
+ return result;
}
/////////////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/mTextControl/src/textcontrol.cpp b/libs/mTextControl/src/textcontrol.cpp
index 30caf61b95..f1b92d2f10 100644
--- a/libs/mTextControl/src/textcontrol.cpp
+++ b/libs/mTextControl/src/textcontrol.cpp
@@ -19,10 +19,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "stdafx.h"
-LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM wParam, LPARAM lParam);
-//LRESULT MTextControl_Measure(HWND hwnd, int maxw, SIZE *size);
-
struct TextControlData
{
HANDLE htu;
@@ -30,25 +26,55 @@ struct TextControlData
struct TextObject *mtext;
};
-void MTextControl_RegisterClass()
-{
- WNDCLASSEX wcl = {};
- wcl.cbSize = sizeof(wcl);
- wcl.lpfnWndProc = MTextControlWndProc;
- wcl.style = CS_GLOBALCLASS;
- wcl.hInstance = g_hInst;
- wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
- wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
- wcl.lpszClassName = L"MTextControl";
- RegisterClassExW(&wcl);
-}
+/// Paint ////////////////////////////////////
-void MTextControl_UnregisterClass()
+static LRESULT MTextControl_OnPaint(HWND hwnd)
{
- UnregisterClassW(L"MTextControl", g_hInst);
+ PAINTSTRUCT ps;
+ HDC hdc = BeginPaint(hwnd, &ps);
+ {
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ FrameRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
+ }
+
+ SetTextColor(hdc, RGB(0, 0, 0));
+ SetBkMode(hdc, TRANSPARENT);
+
+ // Find the text to draw
+ TextControlData *data = (TextControlData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ if (data->mtext) {
+ HFONT hfntSave = nullptr;
+ HFONT hfnt = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
+ if (!hfnt)
+ hfnt = (HFONT)SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0);
+ if (hfnt) {
+ LOGFONT lf;
+ GetObject(hfnt, sizeof(lf), &lf);
+ hfntSave = (HFONT)SelectObject(hdc, hfnt);
+ }
+
+ // Draw the text
+ RECT rc;
+ GetClientRect(hwnd, &rc);
+ POINT pos;
+ pos.x = 0;
+ pos.y = 2;
+ SIZE sz;
+ sz.cx = rc.right - rc.left;
+ sz.cy = rc.bottom - rc.top - 4;
+ MTextDisplay(hdc, pos, sz, data->mtext);
+
+ if (hfntSave)
+ SelectObject(hdc, hfntSave);
+ }
+
+ // Release the device context
+ EndPaint(hwnd, &ps);
+ return 0;
}
-LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
TextControlData *data = (TextControlData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
switch (msg) {
@@ -63,29 +89,28 @@ LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
case MTM_SETUSER:
data->htu = wParam ? (HANDLE)wParam : htuDefault;
- // falldown, DefWindowProc won't process WM_USER ;)
+ __fallthrough;
case WM_SETTEXT:
DefWindowProc(hwnd, msg, wParam, lParam);
- // falldown
+ __fallthrough;
case MTM_UPDATE:
if (data->text) delete[] data->text;
if (data->mtext) MTextDestroy(data->mtext);
{
- int textLength = GetWindowTextLength(hwnd);
+ int textLength = GetWindowTextLengthW(hwnd);
data->text = new wchar_t[textLength + 1];
- GetWindowText(hwnd, data->text, textLength + 1);
- data->mtext = MTextCreateW(data->htu, 0, data->text);
-
- MTextSetParent(data->mtext, hwnd);
-
- InvalidateRect(hwnd, nullptr, TRUE);
+ GetWindowTextW(hwnd, data->text, textLength + 1);
}
+
+ data->mtext = MTextCreateW(data->htu, 0, data->text);
+ MTextSetParent(data->mtext, hwnd);
+ InvalidateRect(hwnd, nullptr, TRUE);
return TRUE;
case WM_PAINT:
- return MTextControl_OnPaint(hwnd, wParam, lParam);
+ return MTextControl_OnPaint(hwnd);
case WM_ERASEBKGND:
RECT rc;
@@ -102,49 +127,23 @@ LRESULT CALLBACK MTextControlWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
return DefWindowProc(hwnd, msg, wParam, lParam);
}
-/// Paint ////////////////////////////////////
-LRESULT MTextControl_OnPaint(HWND hwnd, WPARAM, LPARAM)
-{
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(hwnd, &ps);
- {
- RECT rc;
- GetClientRect(hwnd, &rc);
- FrameRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
- }
-
- SetTextColor(hdc, RGB(0, 0, 0));
- SetBkMode(hdc, TRANSPARENT);
-
- // Find the text to draw
- TextControlData *data = (TextControlData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
- if (data->mtext) {
- HFONT hfntSave = nullptr;
- HFONT hfnt = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
- if (!hfnt)
- hfnt = (HFONT)SendMessage(GetParent(hwnd), WM_GETFONT, 0, 0);
- if (hfnt) {
- LOGFONT lf;
- GetObject(hfnt, sizeof(lf), &lf);
- hfntSave = (HFONT)SelectObject(hdc, hfnt);
- }
+/////////////////////////////////////////////////////////////////////////////////////////
+// Module entry point
- // Draw the text
- RECT rc;
- GetClientRect(hwnd, &rc);
- POINT pos;
- pos.x = 0;
- pos.y = 2;
- SIZE sz;
- sz.cx = rc.right - rc.left;
- sz.cy = rc.bottom - rc.top - 4;
- MTextDisplay(hdc, pos, sz, data->mtext);
-
- if (hfntSave)
- SelectObject(hdc, hfntSave);
- }
+void MTextControl_RegisterClass()
+{
+ WNDCLASSEX wcl = {};
+ wcl.cbSize = sizeof(wcl);
+ wcl.lpfnWndProc = MTextControlWndProc;
+ wcl.style = CS_GLOBALCLASS;
+ wcl.hInstance = g_hInst;
+ wcl.hCursor = LoadCursor(nullptr, IDC_ARROW);
+ wcl.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
+ wcl.lpszClassName = L"MTextControl";
+ RegisterClassExW(&wcl);
+}
- // Release the device context
- EndPaint(hwnd, &ps);
- return 0;
+void MTextControl_UnregisterClass()
+{
+ UnregisterClassW(L"MTextControl", g_hInst);
}