richedit: Use width from EM_SETTARGETDEVICE for wrapping.

The width for EM_SETTARGETDEVICE is used by some applications to set the
wrapping width to a certain distance in twips.  This can be used even
though the target device is ignored.
This commit is contained in:
Dylan Smith 2009-02-02 01:32:20 -05:00 committed by Alexandre Julliard
parent f20ba24404
commit 1a3551b630
6 changed files with 26 additions and 11 deletions

View File

@ -22,7 +22,7 @@
void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC) void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
{ {
c->nSequence = editor->nSequence++; c->nSequence = editor->nSequence++;
c->hDC = hDC; c->hDC = hDC;
c->editor = editor; c->editor = editor;
c->pt.x = 0; c->pt.x = 0;
@ -35,6 +35,10 @@ void ME_InitContext(ME_Context *c, ME_TextEditor *editor, HDC hDC)
} else { } else {
c->dpi.cx = c->dpi.cy = 96; c->dpi.cx = c->dpi.cy = 96;
} }
if (editor->nAvailWidth)
c->nAvailWidth = ME_twips2pointsX(c, editor->nAvailWidth);
else
c->nAvailWidth = c->rcView.right - c->rcView.left;
} }
void ME_DestroyContext(ME_Context *c) void ME_DestroyContext(ME_Context *c)

View File

@ -4332,14 +4332,23 @@ LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
if (wParam == 0) if (wParam == 0)
{ {
BOOL new = (lParam == 0); BOOL new = (lParam == 0);
if (editor->bWordWrap != new) if (editor->nAvailWidth || editor->bWordWrap != new)
{ {
editor->bWordWrap = new; editor->bWordWrap = new;
editor->nAvailWidth = 0; /* wrap to client area */
ME_RewrapRepaint(editor); ME_RewrapRepaint(editor);
} }
} else {
int width = max(0, lParam);
if (!editor->bWordWrap || editor->nAvailWidth != width)
{
editor->nAvailWidth = width;
editor->bWordWrap = TRUE;
ME_RewrapRepaint(editor);
}
FIXME("EM_SETTARGETDEVICE doesn't use non-NULL target devices\n");
} }
else FIXME("Unsupported yet non NULL device in EM_SETTARGETDEVICE\n"); return TRUE;
break;
default: default:
do_default: do_default:
*phresult = S_FALSE; *phresult = S_FALSE;

View File

@ -342,6 +342,7 @@ typedef struct tagME_TextEditor
SIZE sizeWindow; SIZE sizeWindow;
int nTotalLength, nLastTotalLength; int nTotalLength, nLastTotalLength;
int nTotalWidth, nLastTotalWidth; int nTotalWidth, nLastTotalWidth;
int nAvailWidth; /* 0 = wrap to client area, else wrap width in twips */
int nUDArrowX; int nUDArrowX;
int nSequence; int nSequence;
COLORREF rgbBackColor; COLORREF rgbBackColor;
@ -396,6 +397,7 @@ typedef struct tagME_Context
RECT rcView; RECT rcView;
HBRUSH hbrMargin; HBRUSH hbrMargin;
SIZE dpi; SIZE dpi;
int nAvailWidth;
/* those are valid inside ME_WrapTextParagraph and related */ /* those are valid inside ME_WrapTextParagraph and related */
POINT ptFirstRun; POINT ptFirstRun;
@ -413,9 +415,9 @@ typedef struct tagME_WrapContext
POINT pt; POINT pt;
BOOL bOverflown, bWordWrap; BOOL bOverflown, bWordWrap;
ME_DisplayItem *pRowStart; ME_DisplayItem *pRowStart;
ME_DisplayItem *pLastSplittableRun; ME_DisplayItem *pLastSplittableRun;
POINT ptLastSplittableRun; POINT ptLastSplittableRun;
} ME_WrapContext; } ME_WrapContext;
#endif #endif

View File

@ -5939,12 +5939,12 @@ static void test_word_wrap(void)
/* Test the effect of EM_SETTARGETDEVICE on word wrap. */ /* Test the effect of EM_SETTARGETDEVICE on word wrap. */
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1); res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1);
todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res); ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point); pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos); ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0); res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0);
todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res); ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point); pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos); ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
DestroyWindow(hwnd); DestroyWindow(hwnd);

View File

@ -77,7 +77,7 @@ static void ME_BeginRow(ME_WrapContext *wc, ME_DisplayItem *para)
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin; - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
wc->bWordWrap = TRUE; wc->bWordWrap = TRUE;
} else { } else {
wc->nAvailWidth = wc->context->rcView.right - wc->context->rcView.left wc->nAvailWidth = wc->context->nAvailWidth
- (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin; - (wc->nRow ? wc->nLeftMargin : wc->nFirstMargin) - wc->nRightMargin;
} }
wc->pt.x = wc->context->pt.x; wc->pt.x = wc->context->pt.x;

View File

@ -897,12 +897,12 @@ static void test_word_wrap(void)
/* Test the effect of EM_SETTARGETDEVICE on word wrap. */ /* Test the effect of EM_SETTARGETDEVICE on word wrap. */
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1); res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1);
todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res); ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point); pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos); ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0); res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0);
todo_wine ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res); ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point); pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos); ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
DestroyWindow(hwnd); DestroyWindow(hwnd);