Commit 887ffec9 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

riched20: Handle WM_SETCURSOR in the host.

parent cd5b064a
......@@ -233,6 +233,7 @@
#include "shlwapi.h"
#include "rtf.h"
#include "imm.h"
#include "res.h"
#define STACK_SIZE_DEFAULT 100
#define STACK_SIZE_MAX 1000
......@@ -243,7 +244,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(richedit);
static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, ME_Cursor *start, int nChars);
HCURSOR cursor_reverse = NULL;
HINSTANCE dll_instance = NULL;
BOOL me_debug = FALSE;
HANDLE me_heap = NULL;
......@@ -2817,96 +2818,52 @@ static BOOL is_link( ME_Run *run )
return (run->style->fmt.dwMask & CFM_LINK) && (run->style->fmt.dwEffects & CFE_LINK);
}
static BOOL ME_SetCursor(ME_TextEditor *editor)
void editor_set_cursor( ME_TextEditor *editor, int x, int y )
{
ME_Cursor cursor;
POINT pt;
BOOL isExact;
SCROLLBARINFO sbi;
DWORD messagePos = GetMessagePos();
pt.x = (short)LOWORD(messagePos);
pt.y = (short)HIWORD(messagePos);
ME_Cursor pos;
BOOL is_exact;
static HCURSOR cursor_arrow, cursor_hand, cursor_ibeam, cursor_reverse;
HCURSOR cursor;
if (editor->hWnd)
{
sbi.cbSize = sizeof(sbi);
GetScrollBarInfo(editor->hWnd, OBJID_HSCROLL, &sbi);
if (!(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)) &&
PtInRect(&sbi.rcScrollBar, pt))
{
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
return TRUE;
}
sbi.cbSize = sizeof(sbi);
GetScrollBarInfo(editor->hWnd, OBJID_VSCROLL, &sbi);
if (!(sbi.rgstate[0] & (STATE_SYSTEM_INVISIBLE|STATE_SYSTEM_OFFSCREEN)) &&
PtInRect(&sbi.rcScrollBar, pt))
if (!cursor_arrow)
{
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
return TRUE;
}
cursor_arrow = LoadCursorW( NULL, MAKEINTRESOURCEW( IDC_ARROW ) );
cursor_hand = LoadCursorW( NULL, MAKEINTRESOURCEW( IDC_HAND ) );
cursor_ibeam = LoadCursorW( NULL, MAKEINTRESOURCEW( IDC_IBEAM ) );
cursor_reverse = LoadCursorW( dll_instance, MAKEINTRESOURCEW( OCR_REVERSE ) );
}
ITextHost_TxScreenToClient(editor->texthost, &pt);
if (editor->nSelectionType == stLine && editor->bMouseCaptured)
cursor = cursor_ibeam;
if ((editor->nSelectionType == stLine && editor->bMouseCaptured) ||
(!editor->bEmulateVersion10 && y < editor->rcFormat.top && x < editor->rcFormat.left))
cursor = cursor_reverse;
else if (y < editor->rcFormat.top || y > editor->rcFormat.bottom)
{
ITextHost_TxSetCursor( editor->texthost, cursor_reverse, FALSE );
return TRUE;
if (editor->bEmulateVersion10) cursor = cursor_arrow;
else cursor = cursor_ibeam;
}
if (!editor->bEmulateVersion10 /* v4.1 */ &&
pt.y < editor->rcFormat.top &&
pt.x < editor->rcFormat.left)
{
ITextHost_TxSetCursor( editor->texthost, cursor_reverse, FALSE );
return TRUE;
}
if (pt.y < editor->rcFormat.top || pt.y > editor->rcFormat.bottom)
{
if (editor->bEmulateVersion10) /* v1.0 - 3.0 */
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
else /* v4.1 */
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
return TRUE;
}
if (pt.x < editor->rcFormat.left)
else if (x < editor->rcFormat.left) cursor = cursor_reverse;
else
{
ITextHost_TxSetCursor( editor->texthost, cursor_reverse, FALSE );
return TRUE;
}
ME_CharFromPos(editor, pt.x, pt.y, &cursor, &isExact);
if (isExact)
ME_CharFromPos( editor, x, y, &pos, &is_exact );
if (is_exact)
{
ME_Run *run = cursor.run;
ME_Run *run = pos.run;
if (is_link( run ))
{
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_HAND),
FALSE);
return TRUE;
}
if (is_link( run )) cursor = cursor_hand;
if (ME_IsSelection(editor))
else if (ME_IsSelection( editor ))
{
int selStart, selEnd;
int offset = ME_GetCursorOfs(&cursor);
int start, end, offset = ME_GetCursorOfs( &pos );
ME_GetSelectionOfs(editor, &selStart, &selEnd);
if (selStart <= offset && selEnd >= offset) {
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_ARROW),
FALSE);
return TRUE;
ME_GetSelectionOfs( editor, &start, &end );
if (start <= offset && end >= offset) cursor = cursor_arrow;
}
}
}
ITextHost_TxSetCursor(editor->texthost,
LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
return TRUE;
ITextHost_TxSetCursor( editor->texthost, cursor, cursor == cursor_ibeam );
}
static LONG ME_GetSelectionType(ME_TextEditor *editor)
......@@ -3130,7 +3087,7 @@ static inline int calc_wheel_change( int *remain, int amount_per_click )
return change;
}
static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
void link_notify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
{
int x,y;
BOOL isExact;
......@@ -3936,14 +3893,6 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
}
case WM_CREATE:
return ME_WmCreate( editor );
case WM_SETCURSOR:
{
POINT cursor_pos;
if (wParam == (WPARAM)editor->hWnd && GetCursorPos(&cursor_pos) &&
ScreenToClient(editor->hWnd, &cursor_pos))
ME_LinkNotify(editor, msg, 0, MAKELPARAM(cursor_pos.x, cursor_pos.y));
return ME_SetCursor(editor);
}
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
{
......@@ -3953,14 +3902,14 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
ME_CalculateClickCount(editor, msg, wParam, lParam));
ITextHost_TxSetCapture(editor->texthost, TRUE);
editor->bMouseCaptured = TRUE;
ME_LinkNotify(editor, msg, wParam, lParam);
link_notify( editor, msg, wParam, lParam );
break;
}
case WM_MOUSEMOVE:
if (editor->bMouseCaptured)
ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
else
ME_LinkNotify(editor, msg, wParam, lParam);
link_notify( editor, msg, wParam, lParam );
break;
case WM_LBUTTONUP:
if (editor->bMouseCaptured) {
......@@ -3971,14 +3920,14 @@ LRESULT editor_handle_message( ME_TextEditor *editor, UINT msg, WPARAM wParam,
editor->nSelectionType = stPosition;
else
{
ME_LinkNotify(editor, msg, wParam, lParam);
link_notify( editor, msg, wParam, lParam );
}
break;
case WM_RBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONDBLCLK:
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
ME_LinkNotify(editor, msg, wParam, lParam);
link_notify( editor, msg, wParam, lParam );
goto do_default;
case WM_CONTEXTMENU:
if (!ME_ShowContextMenu(editor, (short)LOWORD(lParam), (short)HIWORD(lParam)))
......
......@@ -22,8 +22,8 @@
struct _RTF_Info;
extern HINSTANCE dll_instance DECLSPEC_HIDDEN;
extern HANDLE me_heap DECLSPEC_HIDDEN;
extern HCURSOR cursor_reverse DECLSPEC_HIDDEN;
#define RUN_IS_HIDDEN(run) ((run)->style->fmt.dwMask & CFM_HIDDEN \
&& (run)->style->fmt.dwEffects & CFE_HIDDEN)
......@@ -288,6 +288,8 @@ HRESULT editor_copy_or_cut( ME_TextEditor *editor, BOOL cut, ME_Cursor *start, i
IDataObject **data_out ) DECLSPEC_HIDDEN;
ME_Paragraph *editor_end_para( ME_TextEditor *editor ) DECLSPEC_HIDDEN;
ME_Paragraph *editor_first_para( ME_TextEditor *editor ) DECLSPEC_HIDDEN;
void editor_set_cursor( ME_TextEditor *editor, int x, int y ) DECLSPEC_HIDDEN;
void link_notify( ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam ) DECLSPEC_HIDDEN;
/* table.c */
ME_Cell *cell_create( void ) DECLSPEC_HIDDEN;
......
......@@ -28,7 +28,6 @@
#include "wine/debug.h"
#include "editstr.h"
#include "rtf.h"
#include "res.h"
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
......@@ -1207,6 +1206,20 @@ static LRESULT RichEditWndProc_common( HWND hwnd, UINT msg, WPARAM wparam,
InvalidateRect( hwnd, NULL, TRUE );
break;
case WM_SETCURSOR:
{
POINT pos;
RECT rect;
if (hwnd != (HWND)wparam) break;
GetCursorPos( &pos );
ScreenToClient( hwnd, &pos );
ITextHost_TxGetClientRect( &host->ITextHost_iface, &rect );
if (PtInRect( &rect, pos ))
ITextServices_OnTxSetCursor( host->text_srv, DVASPECT_CONTENT, 0, NULL, NULL, NULL, NULL, NULL, pos.x, pos.y );
else ITextHost_TxSetCursor( &host->ITextHost_iface, LoadCursorW( NULL, MAKEINTRESOURCEW( IDC_ARROW ) ), FALSE );
break;
}
case EM_SETEVENTMASK:
host->event_mask = lparam;
hr = ITextServices_TxSendMessage( host->text_srv, msg, wparam, lparam, &res );
......@@ -1468,10 +1481,10 @@ BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, void *reserved )
switch (reason)
{
case DLL_PROCESS_ATTACH:
dll_instance = instance;
DisableThreadLibraryCalls( instance );
me_heap = HeapCreate( 0, 0x10000, 0 );
if (!register_classes( instance )) return FALSE;
cursor_reverse = LoadCursorW( instance, MAKEINTRESOURCEW( OCR_REVERSE ) );
LookupInit();
break;
......
......@@ -184,14 +184,21 @@ DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_TxGetVScroll( ITextServices *iface,
}
DEFINE_THISCALL_WRAPPER(fnTextSrv_OnTxSetCursor,40)
DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxSetCursor(ITextServices *iface, DWORD dwDrawAspect, LONG lindex,
void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcDraw,
HDC hicTargetDev, LPCRECT lprcClient, INT x, INT y)
DECLSPEC_HIDDEN HRESULT __thiscall fnTextSrv_OnTxSetCursor( ITextServices *iface, DWORD aspect, LONG index,
void *aspect_info, DVTARGETDEVICE *td, HDC draw,
HDC target, const RECT *client, INT x, INT y )
{
struct text_services *services = impl_from_ITextServices( iface );
FIXME( "%p: STUB\n", services );
return E_NOTIMPL;
TRACE( "%p: %d, %d, %p, %p, draw %p target %p client %s pos (%d, %d)\n", services, aspect, index, aspect_info, td, draw,
target, wine_dbgstr_rect( client ), x, y );
if (aspect != DVASPECT_CONTENT || index || aspect_info || td || draw || target || client)
FIXME( "Ignoring most params\n" );
link_notify( services->editor, WM_SETCURSOR, 0, MAKELPARAM( x, y ) );
editor_set_cursor( services->editor, x, y );
return S_OK;
}
DEFINE_THISCALL_WRAPPER(fnTextSrv_TxQueryHitPoint,44)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment