Huw Davies : riched20: Handle dialog mode in the host.
Alexandre Julliard
julliard at winehq.org
Wed Mar 17 16:23:14 CDT 2021
Module: wine
Branch: master
Commit: 7a038cae5790a633a5d1f93f8ef47db4461f6ea6
URL: https://source.winehq.org/git/wine.git/?a=commit;h=7a038cae5790a633a5d1f93f8ef47db4461f6ea6
Author: Huw Davies <huw at codeweavers.com>
Date: Wed Mar 17 08:45:24 2021 +0000
riched20: Handle dialog mode in the host.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/riched20/editor.c | 47 ----------------------------------------
dlls/riched20/editstr.h | 1 -
dlls/riched20/txthost.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 56 insertions(+), 49 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 6f38231de9b..77787906344 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2411,34 +2411,8 @@ static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
static BOOL handle_enter(ME_TextEditor *editor)
{
- BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
- if (editor->bDialogMode)
- {
- if (ctrl_is_down)
- return TRUE;
-
- if (!(editor->styleFlags & ES_WANTRETURN))
- {
- if (editor->hwndParent)
- {
- DWORD dw;
- dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0);
- if (HIWORD(dw) == DC_HASDEFID)
- {
- HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw));
- if (hwDefCtrl)
- {
- SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE);
- PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0);
- }
- }
- }
- return TRUE;
- }
- }
-
if (editor->props & TXTBIT_MULTILINE)
{
ME_Cursor cursor = editor->pCursors[0];
@@ -2647,14 +2621,6 @@ ME_KeyDown(ME_TextEditor *editor, WORD nKey)
if (!editor->bEmulateVersion10)
return handle_enter(editor);
break;
- case VK_ESCAPE:
- if (editor->bDialogMode && editor->hwndParent)
- PostMessageW(editor->hwndParent, WM_CLOSE, 0, 0);
- return TRUE;
- case VK_TAB:
- if (editor->bDialogMode && editor->hwndParent)
- SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, shift_is_down, 0);
- return TRUE;
case 'A':
if (ctrl_is_down)
{
@@ -3068,7 +3034,6 @@ ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
ed->mode |= (ed->props & TXTBIT_RICHTEXT) ? TM_RICHTEXT : TM_PLAINTEXT;
ed->AutoURLDetect_bEnable = FALSE;
ed->bHaveFocus = FALSE;
- ed->bDialogMode = FALSE;
ed->bMouseCaptured = FALSE;
ed->caret_hidden = FALSE;
ed->caret_height = 0;
@@ -3399,18 +3364,6 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam, TRUE);
case EM_STREAMOUT:
return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
- case WM_GETDLGCODE:
- {
- UINT code = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS;
-
- if (lParam)
- editor->bDialogMode = TRUE;
- if (editor->props & TXTBIT_MULTILINE)
- code |= DLGC_WANTMESSAGE;
- if (!(editor->props & TXTBIT_SAVESELECTION))
- code |= DLGC_HASSETSEL;
- return code;
- }
case EM_EMPTYUNDOBUFFER:
ME_EmptyUndoStack(editor);
return 0;
diff --git a/dlls/riched20/editstr.h b/dlls/riched20/editstr.h
index f689194901c..1fbf70ee6b2 100644
--- a/dlls/riched20/editstr.h
+++ b/dlls/riched20/editstr.h
@@ -424,7 +424,6 @@ typedef struct tagME_TextEditor
BOOL AutoURLDetect_bEnable;
WCHAR cPasswordMask;
BOOL bHaveFocus;
- BOOL bDialogMode; /* Indicates that we are inside a dialog window */
/*for IME */
int imeStartIndex;
DWORD selofs; /* The size of the selection bar on the left side of control */
diff --git a/dlls/riched20/txthost.c b/dlls/riched20/txthost.c
index a8286905659..ddbb879a75f 100644
--- a/dlls/riched20/txthost.c
+++ b/dlls/riched20/txthost.c
@@ -39,7 +39,8 @@ struct host
ITextServices *text_srv;
ME_TextEditor *editor; /* to be removed */
HWND window, parent;
- BOOL emulate_10;
+ unsigned int emulate_10 : 1;
+ unsigned int dialog_mode : 1;
PARAFORMAT2 para_fmt;
DWORD props, scrollbars, event_mask;
};
@@ -84,6 +85,7 @@ struct host *host_create( HWND hwnd, CREATESTRUCTW *cs, BOOL emulate_10 )
texthost->window = hwnd;
texthost->parent = cs->hwndParent;
texthost->emulate_10 = emulate_10;
+ texthost->dialog_mode = 0;
memset( &texthost->para_fmt, 0, sizeof(texthost->para_fmt) );
texthost->para_fmt.cbSize = sizeof(texthost->para_fmt);
texthost->para_fmt.dwMask = PFM_ALIGNMENT;
@@ -844,6 +846,31 @@ static HRESULT set_options( struct host *host, DWORD op, DWORD value, LRESULT *r
return hr;
}
+/* handle dialog mode VK_RETURN. Returns TRUE if message has been processed */
+static BOOL handle_dialog_enter( struct host *host )
+{
+ BOOL ctrl_is_down = GetKeyState( VK_CONTROL ) & 0x8000;
+
+ if (ctrl_is_down) return TRUE;
+
+ if (host->editor->styleFlags & ES_WANTRETURN) return FALSE;
+
+ if (host->parent)
+ {
+ DWORD id = SendMessageW( host->parent, DM_GETDEFID, 0, 0 );
+ if (HIWORD( id ) == DC_HASDEFID)
+ {
+ HWND ctrl = GetDlgItem( host->parent, LOWORD( id ));
+ if (ctrl)
+ {
+ SendMessageW( host->parent, WM_NEXTDLGCTL, (WPARAM)ctrl, TRUE );
+ PostMessageW( ctrl, WM_KEYDOWN, VK_RETURN, 0 );
+ }
+ }
+ }
+ return TRUE;
+}
+
static LRESULT send_msg_filter( struct host *host, UINT msg, WPARAM *wparam, LPARAM *lparam )
{
MSGFILTER msgf;
@@ -905,6 +932,7 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam,
WCHAR wc = wparam;
if (!unicode) MultiByteToWideChar( CP_ACP, 0, (char *)&wparam, 1, &wc, 1 );
+ if (wparam == '\r' && host->dialog_mode && host->emulate_10 && handle_dialog_enter( host )) break;
hr = ITextServices_TxSendMessage( host->text_srv, msg, wc, lparam, &res );
break;
}
@@ -958,6 +986,14 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam,
}
break;
}
+ case WM_GETDLGCODE:
+ if (lparam) host->dialog_mode = TRUE;
+
+ res = DLGC_WANTCHARS | DLGC_WANTTAB | DLGC_WANTARROWS;
+ if (host->props & TXTBIT_MULTILINE) res |= DLGC_WANTMESSAGE;
+ if (!(host->props & TXTBIT_SAVESELECTION)) res |= DLGC_HASSETSEL;
+ break;
+
case EM_GETLINE:
if (unicode) hr = ITextServices_TxSendMessage( host->text_srv, msg, wparam, lparam, &res );
else hr = get_lineA( host->text_srv, wparam, lparam, &res );
@@ -1014,6 +1050,25 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam,
else hr = get_text_rangeA( host, (TEXTRANGEA *)lparam, &res );
break;
+ case WM_KEYDOWN:
+ switch (LOWORD( wparam ))
+ {
+ case VK_ESCAPE:
+ if (host->dialog_mode && host->parent)
+ PostMessageW( host->parent, WM_CLOSE, 0, 0 );
+ break;
+ case VK_TAB:
+ if (host->dialog_mode && host->parent)
+ SendMessageW( host->parent, WM_NEXTDLGCTL, GetKeyState( VK_SHIFT ) & 0x8000, 0 );
+ break;
+ case VK_RETURN:
+ if (host->dialog_mode && !host->emulate_10 && handle_dialog_enter( host )) break;
+ /* fall through */
+ default:
+ hr = ITextServices_TxSendMessage( host->text_srv, msg, wparam, lparam, &res );
+ }
+ break;
+
case WM_PAINT:
{
HDC hdc;
More information about the wine-cvs
mailing list