[Try 2] [3/3] riched20:EM_FORMATRANGE Implementation Patch
Dylan Smith
dylan.ah.smith at gmail.com
Sun Feb 21 17:15:12 CST 2010
On Sun, Feb 21, 2010 at 9:33 AM, James McKenzie
<jjmckenzie51 at earthlink.net> wrote:
> This is how I calculated the value to be the same as that returned by
> EM_FORMATRANGE when run in Windows(whatever). If you have a better
> method, that would be great.
>
I have a better method, it is returning textlength + 1 in this case,
because this is the behaviour that native riched20 has for this case.
I have sent you patches plenty of times, so you know what I think is
the correct code for this case. Attached is a patch that changes you
code to what I think it should be for handling this issue.
The wrapping issue should be handled as a separately.
>
>> As I have mentioned to you before in an offlist email, this will cause
>> problems with applications which try to print all the pages in a loop
>> with cpMax=-1 to specify to print to the end of the text, and cpMin
>> for following calls set to the return value of preview calls to send
>> EM_FORMATRANGE messages. The return value will cause an endless loop
>> for long enough text with more characters than the width of the page
>> in twips.
>>
>
> Hmm. This is not something that I have tested, nor is there a test in
> riched20 for this. Do you think this should have a test case?
What I provided was the most severe realistic test case I could think
of, and I previously provided you a sample rtf file and a patch that
shows the behaviour in wordpad.
The automated tests are not very extensive, so I have attached a patch
for the automated tests that adds two very simple test cases.
-------------- next part --------------
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index dd8df2b..db64680 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -4812,9 +4812,10 @@ static void test_WM_PASTE(void)
static void test_EM_FORMATRANGE(void)
{
- int i, tpp_x, tpp_y;
+ int r, i, tpp_x, tpp_y;
HDC hdc;
HWND hwndRichEdit = new_richedit(NULL);
+ FORMATRANGE fr;
static const struct {
const char *string; /* The string */
int first; /* First 'pagebreak', 0 for don't care */
@@ -4834,14 +4835,33 @@ static void test_EM_FORMATRANGE(void)
tpp_x = 1440 / GetDeviceCaps(hdc, LOGPIXELSX);
tpp_y = 1440 / GetDeviceCaps(hdc, LOGPIXELSY);
+ SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
+ fr.hdc = fr.hdcTarget = hdc;
+ fr.rc.top = fr.rcPage.top = fr.rc.left = fr.rcPage.left = 0;
+ fr.rc.right = fr.rcPage.right = 500 * tpp_x;
+ fr.rc.bottom = fr.rcPage.bottom = 500 * tpp_y;
+ fr.chrg.cpMin = 0;
+ fr.chrg.cpMax = -1;
+ r = SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, (LPARAM)&fr);
+ ok(r == 2, "r=%d expected r=2\n", r);
+
+ SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"ab");
+ fr.hdc = fr.hdcTarget = hdc;
+ fr.rc.top = fr.rcPage.top = fr.rc.left = fr.rcPage.left = 0;
+ fr.rc.right = fr.rcPage.right = 500 * tpp_x;
+ fr.rc.bottom = fr.rcPage.bottom = 500 * tpp_y;
+ fr.chrg.cpMin = 0;
+ fr.chrg.cpMax = -1;
+ r = SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, (LPARAM)&fr);
+ ok(r == 3, "r=%d expected r=3\n", r);
+
SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, 0);
for (i = 0; i < sizeof(fmtstrings)/sizeof(fmtstrings[0]); i++)
{
- FORMATRANGE fr;
GETTEXTLENGTHEX gtl;
SIZE stringsize;
- int r, len;
+ int len;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) fmtstrings[i].string);
-------------- next part --------------
diff --git a/dlls/riched20/paint.c b/dlls/riched20/paint.c
index 6b22722..752a4b6 100644
--- a/dlls/riched20/paint.c
+++ b/dlls/riched20/paint.c
@@ -83,7 +84,7 @@ LPARAM ME_FormatContent(ME_TextEditor *editor, FORMATRANGE *pfr, BOOL bDraw)
int cyOffset = -1;
int iEndOffset = -1;
int textlength = ME_GetTextLength(editor);
- int targetBottom, numCharPrintable = 0;
+ int targetBottom;
if (!pfr || pfr->chrg.cpMin >= textlength)
return textlength;
@@ -100,7 +101,6 @@ LPARAM ME_FormatContent(ME_TextEditor *editor, FORMATRANGE *pfr, BOOL bDraw)
c.rcView.top = ME_twips2targetY(&c, pfr->rc.top);
c.rcView.bottom = ME_twips2targetY(&c, pfr->rc.bottom);
c.nAvailWidth = c.rcView.right - c.rcView.left;
- numCharPrintable = c.nAvailWidth / (1440/c.dpiTarget.cy);
targetBottom = c.rcView.bottom;
@@ -169,7 +169,7 @@ LPARAM ME_FormatContent(ME_TextEditor *editor, FORMATRANGE *pfr, BOOL bDraw)
if (iEndOffset == -1)
{
- iEndOffset = numCharPrintable + 1;
+ iEndOffset = textlength + 1;
targetBottom = c.pt.y - cyOffset;
}
pfr->rc.bottom = (LONGLONG)targetBottom * 1440 / c.dpiTarget.cy + pfr->rc.top;
More information about the wine-devel
mailing list