[USER32][COMCTL32] Edit control: Fix alignment mask (#9115)

Based on JIRA user I_Kill_Bug's "Edit Alignment.patch".
JIRA issue: CORE-20631
- Add (ES_LEFT | ES_RIGHT | ES_CENTER) flags to
  style_change_mask variable.
This commit is contained in:
Katayama Hirofumi MZ
2026-06-09 13:52:46 +09:00
committed by GitHub
parent 2dddf48071
commit 19b19ec305
8 changed files with 155 additions and 0 deletions
+5
View File
@@ -3991,8 +3991,13 @@ static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLES
/* Only a subset of changes can be applied after the control
* has been created.
*/
#ifdef __REACTOS__
style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
ES_NUMBER | ES_LEFT | ES_RIGHT | ES_CENTER;
#else
style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
ES_NUMBER;
#endif
if (es->style & ES_MULTILINE)
style_change_mask |= ES_WANTRETURN;
@@ -1,4 +1,5 @@
add_subdirectory(biditext)
add_subdirectory(editalign)
add_subdirectory(messagebox)
add_subdirectory(paintdesktop)
add_subdirectory(psmtest)
@@ -0,0 +1,6 @@
add_rc_deps(editalign.rc ${CMAKE_CURRENT_SOURCE_DIR}/editalign.ico)
add_executable(editalign editalign.c editalign.rc)
set_module_type(editalign win32gui UNICODE)
add_importlibs(editalign gdi32 user32 comctl32 msvcrt kernel32 ntdll)
add_rostests_file(TARGET editalign SUBDIR suppl)
@@ -0,0 +1,107 @@
/*
* PROJECT: ReactOS Tests
* LICENSE: LGPL-2.0+ (https://spdx.org/licenses/LGPL-2.0+)
* PURPOSE: Tests text alignment of EDIT control
* COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ ([email protected])
*/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <dlgs.h>
#include "resource.h"
static HINSTANCE g_hInstance = NULL;
static HWND g_hMainWnd = NULL;
static void SetEditAlign(HWND hwndEdit, LONG_PTR add_style)
{
LONG_PTR style = GetWindowLongPtr(hwndEdit, GWL_STYLE);
style &= ~(ES_LEFT | ES_CENTER | ES_RIGHT);
style |= add_style;
SetWindowLongPtr(hwndEdit, GWL_STYLE, style);
InvalidateRect(hwndEdit, NULL, TRUE);
}
static void SetMultiline(HWND hwnd, HWND hwndEdit, BOOL bMultiline)
{
TCHAR text[1024];
GetWindowText(hwndEdit, text, ARRAYSIZE(text));
RECT rc;
GetWindowRect(hwndEdit, &rc);
MapWindowPoints(NULL, hwnd, (LPPOINT)&rc, sizeof(RECT) / sizeof(POINT));
DWORD exstyle = (LONG)GetWindowLongPtr(hwndEdit, GWL_EXSTYLE);
DWORD style = (LONG)GetWindowLongPtr(hwndEdit, GWL_STYLE);
style &= ~ES_MULTILINE;
if (bMultiline)
style |= ES_MULTILINE;
DestroyWindow(hwndEdit);
CreateWindowEx(exstyle, TEXT("EDIT"), text, style,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
hwnd, (HMENU)UlongToHandle(edt1), g_hInstance, NULL);
HFONT hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
SendDlgItemMessage(hwnd, edt1, WM_SETFONT, (WPARAM)hFont, TRUE);
}
static INT_PTR CALLBACK
DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
g_hMainWnd = hwnd;
SetDlgItemText(hwnd, edt1, TEXT("Text"));
CheckRadioButton(hwnd, rad1, rad3, rad1);
return TRUE;
}
case WM_COMMAND:
{
HWND hwndEdit = GetDlgItem(hwnd, edt1);
switch (LOWORD(wParam))
{
case IDCANCEL: // Cancel
EndDialog(hwnd, LOWORD(wParam));
break;
case rad1: // Left
if (HIWORD(wParam) == BN_CLICKED)
SetEditAlign(hwndEdit, ES_LEFT);
break;
case rad2: // Center
if (HIWORD(wParam) == BN_CLICKED)
SetEditAlign(hwndEdit, ES_CENTER);
break;
case rad3: // Right
if (HIWORD(wParam) == BN_CLICKED)
SetEditAlign(hwndEdit, ES_RIGHT);
break;
case chx1: // Multiline
if (HIWORD(wParam) == BN_CLICKED)
{
if (IsDlgButtonChecked(hwnd, chx1) == BST_CHECKED)
SetMultiline(hwnd, hwndEdit, TRUE);
else
SetMultiline(hwnd, hwndEdit, FALSE);
}
}
break;
}
}
return 0;
}
INT WINAPI
wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
INT nCmdShow)
{
g_hInstance = hInstance;
InitCommonControls();
DialogBoxW(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DialogProc);
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

@@ -0,0 +1,29 @@
/*
* PROJECT: ReactOS Tests
* LICENSE: LGPL-2.0+ (https://spdx.org/licenses/LGPL-2.0+)
* PURPOSE: Tests text alignment of EDIT control
* COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ ([email protected])
*/
#include <windows.h>
#include "resource.h"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS EditAlign test program"
#define REACTOS_STR_INTERNAL_NAME "editalign"
#define REACTOS_STR_ORIGINAL_FILENAME "editalign.exe"
#include <reactos/version.rc>
#include <reactos/manifest_exe.rc>
IDI_MAIN ICON "editalign.ico"
IDD_MAIN DIALOG 0, 0, 215, 135
CAPTION "EditAlign"
STYLE DS_CENTER | DS_MODALFRAME | WS_POPUPWINDOW | WS_CAPTION
FONT 9, "MS Shell Dlg"
{
EDITTEXT edt1, 37, 13, 122, 61, ES_WANTRETURN
AUTORADIOBUTTON "ES_LEFT", rad1, 11, 83, 60, 14, WS_TABSTOP
AUTORADIOBUTTON "ES_CENTER", rad2, 77, 83, 60, 14, WS_TABSTOP
AUTORADIOBUTTON "ES_RIGHT", rad3, 145, 83, 60, 14, WS_TABSTOP
AUTOCHECKBOX "Multiline", chx1, 141, 115, 60, 14
}
@@ -0,0 +1,2 @@
#define IDD_MAIN 100
#define IDI_MAIN 100
+5
View File
@@ -4158,8 +4158,13 @@ static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLES
/* Only a subset of changes can be applied after the control
* has been created.
*/
#ifdef __REACTOS__
style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
ES_NUMBER | ES_LEFT | ES_RIGHT | ES_CENTER;
#else
style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
ES_NUMBER;
#endif
if (es->style & ES_MULTILINE)
style_change_mask |= ES_WANTRETURN;