2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - painting functions
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2006-01-13 13:53:35 +01:00
|
|
|
* Copyright 2005 by Phil Krylov
|
2005-03-05 12:19:14 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
2008-12-19 15:54:58 +01:00
|
|
|
void ME_PaintContent(ME_TextEditor *editor, HDC hDC, BOOL bOnlyNew, const RECT *rcUpdate)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_DisplayItem *item;
|
|
|
|
ME_Context c;
|
2005-03-09 19:43:18 +01:00
|
|
|
int yoffset;
|
2008-12-19 15:54:58 +01:00
|
|
|
int ys, ye;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
editor->nSequence++;
|
2005-03-21 11:27:24 +01:00
|
|
|
yoffset = ME_GetYScrollPos(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_InitContext(&c, editor, hDC);
|
|
|
|
SetBkMode(hDC, TRANSPARENT);
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_MoveCaret(editor); /* Calls ME_WrapMarkedParagraphs */
|
2005-03-05 12:19:14 +01:00
|
|
|
item = editor->pBuffer->pFirst->next;
|
2008-12-19 15:54:58 +01:00
|
|
|
/* This context point is an offset for the paragraph positions stored
|
|
|
|
* during wrapping. It shouldn't be modified during painting. */
|
|
|
|
c.pt.x = c.rcView.left;
|
|
|
|
c.pt.y = c.rcView.top - yoffset;
|
|
|
|
while(item != editor->pBuffer->pLast)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
assert(item->type == diParagraph);
|
2008-12-19 15:54:58 +01:00
|
|
|
|
|
|
|
ys = c.pt.y + item->member.para.pt.y;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (item->member.para.pCell
|
|
|
|
!= item->member.para.next_para->member.para.pCell)
|
|
|
|
{
|
|
|
|
ME_Cell *cell = NULL;
|
|
|
|
cell = &ME_FindItemBack(item->member.para.next_para, diCell)->member.cell;
|
2008-12-19 15:54:58 +01:00
|
|
|
ye = c.pt.y + cell->pt.y + cell->nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
} else {
|
2008-12-19 15:54:58 +01:00
|
|
|
ye = ys + item->member.para.nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2008-12-19 15:54:58 +01:00
|
|
|
if (item->member.para.pCell && !(item->member.para.nFlags & MEPF_ROWEND) &&
|
2008-08-13 05:15:36 +02:00
|
|
|
item->member.para.pCell != item->member.para.prev_para->member.para.pCell)
|
|
|
|
{
|
|
|
|
/* the border shifts the text down */
|
2008-12-19 15:54:58 +01:00
|
|
|
ys -= item->member.para.pCell->member.cell.yTextOffset;
|
2008-08-13 05:15:36 +02:00
|
|
|
}
|
2008-12-19 15:54:58 +01:00
|
|
|
|
2005-03-09 12:48:59 +01:00
|
|
|
if (!bOnlyNew || (item->member.para.nFlags & MEPF_REPAINT))
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
/* Draw the pargraph if any of the paragraph is in the update region. */
|
2005-03-09 19:43:18 +01:00
|
|
|
BOOL bPaint = (rcUpdate == NULL);
|
|
|
|
if (rcUpdate)
|
2008-12-19 15:54:58 +01:00
|
|
|
bPaint = ys < rcUpdate->bottom && ye > rcUpdate->top;
|
2005-03-09 19:43:18 +01:00
|
|
|
if (bPaint)
|
|
|
|
{
|
|
|
|
ME_DrawParagraph(&c, item);
|
2008-12-18 07:56:49 +01:00
|
|
|
/* Clear the repaint flag if the whole paragraph is in the
|
|
|
|
* update region. */
|
2008-12-19 15:54:58 +01:00
|
|
|
if (!rcUpdate || (rcUpdate->top <= ys && rcUpdate->bottom >= ye))
|
2005-03-19 18:06:17 +01:00
|
|
|
item->member.para.nFlags &= ~MEPF_REPAINT;
|
2005-03-09 19:43:18 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
}
|
2008-12-19 15:54:58 +01:00
|
|
|
if (c.pt.y + editor->nTotalLength < c.rcView.bottom)
|
2008-12-18 07:56:49 +01:00
|
|
|
{
|
|
|
|
/* Fill space after the end of the text. */
|
2008-12-19 15:54:58 +01:00
|
|
|
RECT rc;
|
|
|
|
rc.top = c.pt.y + editor->nTotalLength;
|
|
|
|
rc.left = c.rcView.left;
|
|
|
|
rc.bottom = c.rcView.bottom;
|
|
|
|
rc.right = c.rcView.right;
|
2008-12-18 07:56:49 +01:00
|
|
|
|
2005-03-09 19:43:18 +01:00
|
|
|
if (bOnlyNew)
|
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
/* Only erase region drawn from previous call to ME_PaintContent */
|
2008-12-19 15:54:58 +01:00
|
|
|
if (editor->nTotalLength < editor->nLastTotalLength)
|
|
|
|
rc.bottom = c.pt.y + editor->nLastTotalLength;
|
2005-03-09 19:43:18 +01:00
|
|
|
else
|
2008-12-19 15:54:58 +01:00
|
|
|
SetRectEmpty(&rc);
|
2005-03-09 19:43:18 +01:00
|
|
|
}
|
2008-12-18 07:56:49 +01:00
|
|
|
|
2008-12-19 15:54:58 +01:00
|
|
|
IntersectRect(&rc, &rc, rcUpdate);
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2008-12-19 15:54:58 +01:00
|
|
|
if (!IsRectEmpty(&rc))
|
2005-11-03 12:33:24 +01:00
|
|
|
FillRect(hDC, &rc, c.editor->hbrBackground);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-11-03 10:52:29 +01:00
|
|
|
if (editor->nTotalLength != editor->nLastTotalLength)
|
|
|
|
ME_SendRequestResize(editor, FALSE);
|
2005-03-09 19:43:18 +01:00
|
|
|
editor->nLastTotalLength = editor->nTotalLength;
|
2008-03-16 21:48:13 +01:00
|
|
|
ME_DestroyContext(&c, NULL);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_Repaint(ME_TextEditor *editor)
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
if (ME_WrapMarkedParagraphs(editor))
|
2005-08-15 11:47:14 +02:00
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_UpdateScrollBar(editor);
|
|
|
|
FIXME("ME_Repaint had to call ME_WrapMarkedParagraphs\n");
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
2008-10-19 10:43:07 +02:00
|
|
|
if (!IsWindowVisible(editor->hWnd))
|
|
|
|
return;
|
2008-06-29 03:04:58 +02:00
|
|
|
if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
|
|
|
|
ME_SendOldNotify(editor, EN_UPDATE);
|
2006-09-08 23:37:25 +02:00
|
|
|
UpdateWindow(editor->hWnd);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_UpdateRepaint(ME_TextEditor *editor)
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
/* Should be called whenever the contents of the control have changed */
|
|
|
|
ME_Cursor *pCursor;
|
2008-04-21 17:02:52 +02:00
|
|
|
BOOL wrappedParagraphs;
|
2008-01-01 22:05:40 +01:00
|
|
|
|
2008-04-21 17:02:52 +02:00
|
|
|
wrappedParagraphs = ME_WrapMarkedParagraphs(editor);
|
|
|
|
if (wrappedParagraphs)
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_UpdateScrollBar(editor);
|
|
|
|
|
|
|
|
/* Ensure that the cursor is visible */
|
|
|
|
pCursor = &editor->pCursors[0];
|
|
|
|
ME_EnsureVisible(editor, pCursor->pRun);
|
|
|
|
|
2006-11-26 06:04:20 +01:00
|
|
|
/* send EN_CHANGE if the event mask asks for it */
|
|
|
|
if(editor->nEventMask & ENM_CHANGE)
|
|
|
|
{
|
2007-09-19 16:31:14 +02:00
|
|
|
editor->nEventMask &= ~ENM_CHANGE;
|
2006-11-26 06:04:20 +01:00
|
|
|
ME_SendOldNotify(editor, EN_CHANGE);
|
2007-09-19 16:31:14 +02:00
|
|
|
editor->nEventMask |= ENM_CHANGE;
|
2006-11-26 06:04:20 +01:00
|
|
|
}
|
2008-10-19 10:43:17 +02:00
|
|
|
ME_Repaint(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
}
|
|
|
|
|
2005-07-24 18:17:43 +02:00
|
|
|
void
|
|
|
|
ME_RewrapRepaint(ME_TextEditor *editor)
|
2006-09-08 23:37:25 +02:00
|
|
|
{
|
|
|
|
/* RewrapRepaint should be called whenever the control has changed in
|
|
|
|
* looks, but not content. Like resizing. */
|
|
|
|
|
2005-07-24 18:17:43 +02:00
|
|
|
ME_MarkAllForWrapping(editor);
|
2008-10-18 03:29:55 +02:00
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
ME_UpdateScrollBar(editor);
|
2008-10-19 10:43:17 +02:00
|
|
|
ME_Repaint(editor);
|
2005-07-24 18:17:43 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
int ME_twips2pointsX(ME_Context *c, int x)
|
2008-01-01 22:04:40 +01:00
|
|
|
{
|
|
|
|
if (c->editor->nZoomNumerator == 0)
|
2008-01-01 22:05:33 +01:00
|
|
|
return x * c->dpi.cx / 1440;
|
2008-01-01 22:04:40 +01:00
|
|
|
else
|
2008-01-01 22:05:33 +01:00
|
|
|
return x * c->dpi.cx * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ME_twips2pointsY(ME_Context *c, int y)
|
|
|
|
{
|
|
|
|
if (c->editor->nZoomNumerator == 0)
|
|
|
|
return y * c->dpi.cy / 1440;
|
|
|
|
else
|
|
|
|
return y * c->dpi.cy * c->editor->nZoomNumerator / 1440 / c->editor->nZoomDenominator;
|
2008-01-01 22:04:40 +01:00
|
|
|
}
|
2005-07-24 18:17:43 +02:00
|
|
|
|
2008-07-11 00:28:41 +02:00
|
|
|
static void ME_HighlightSpace(ME_Context *c, int x, int y, LPCWSTR szText,
|
|
|
|
int nChars, ME_Style *s, int width,
|
|
|
|
int nSelFrom, int nSelTo, int ymin, int cy)
|
|
|
|
{
|
|
|
|
HDC hDC = c->hDC;
|
|
|
|
HGDIOBJ hOldFont = NULL;
|
|
|
|
SIZE sz;
|
|
|
|
int selWidth;
|
|
|
|
/* Only highlight if there is a selection in the run and when
|
|
|
|
* EM_HIDESELECTION is not being used to hide the selection. */
|
|
|
|
if (nSelFrom >= nChars || nSelTo < 0 || nSelFrom >= nSelTo
|
|
|
|
|| c->editor->bHideSelection)
|
|
|
|
return;
|
|
|
|
hOldFont = ME_SelectStyleFont(c, s);
|
|
|
|
if (width <= 0)
|
|
|
|
{
|
|
|
|
GetTextExtentPoint32W(hDC, szText, nChars, &sz);
|
|
|
|
width = sz.cx;
|
|
|
|
}
|
|
|
|
if (nSelFrom < 0) nSelFrom = 0;
|
|
|
|
if (nSelTo > nChars) nSelTo = nChars;
|
|
|
|
GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
|
|
|
|
x += sz.cx;
|
|
|
|
if (nSelTo != nChars)
|
|
|
|
{
|
|
|
|
GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
|
|
|
|
selWidth = sz.cx;
|
|
|
|
} else {
|
|
|
|
selWidth = width - sz.cx;
|
|
|
|
}
|
|
|
|
ME_UnselectStyleFont(c, s, hOldFont);
|
|
|
|
|
2008-07-11 00:28:45 +02:00
|
|
|
if (c->editor->bEmulateVersion10)
|
|
|
|
PatBlt(hDC, x, ymin, selWidth, cy, DSTINVERT);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RECT rect;
|
|
|
|
HBRUSH hBrush;
|
|
|
|
rect.left = x;
|
|
|
|
rect.top = ymin;
|
|
|
|
rect.right = x + selWidth;
|
|
|
|
rect.bottom = ymin + cy;
|
|
|
|
hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
|
|
|
|
FillRect(hDC, &rect, hBrush);
|
|
|
|
DeleteObject(hBrush);
|
|
|
|
}
|
2008-07-11 00:28:41 +02:00
|
|
|
}
|
|
|
|
|
2008-07-11 00:26:56 +02:00
|
|
|
static void ME_DrawTextWithStyle(ME_Context *c, int x, int y, LPCWSTR szText,
|
|
|
|
int nChars, ME_Style *s, int width,
|
|
|
|
int nSelFrom, int nSelTo, int ymin, int cy)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
HDC hDC = c->hDC;
|
|
|
|
HGDIOBJ hOldFont;
|
2008-01-01 22:04:10 +01:00
|
|
|
COLORREF rgbOld;
|
2005-06-12 12:43:24 +02:00
|
|
|
int yOffset = 0, yTwipsOffset = 0;
|
2008-01-01 22:04:04 +01:00
|
|
|
SIZE sz;
|
|
|
|
COLORREF rgb;
|
2008-07-11 00:28:45 +02:00
|
|
|
HPEN hPen = NULL, hOldPen = NULL;
|
|
|
|
BOOL bHighlightedText = (nSelFrom < nChars && nSelTo >= 0
|
|
|
|
&& nSelFrom < nSelTo && !c->editor->bHideSelection);
|
|
|
|
int xSelStart = x, xSelEnd = x;
|
2008-07-11 00:26:56 +02:00
|
|
|
int *lpDx = NULL;
|
|
|
|
/* lpDx is only needed for tabs to make sure the underline done automatically
|
|
|
|
* by the font extends to the end of the tab. Tabs are always stored as
|
|
|
|
* a single character run, so we can handle this case separately, since
|
|
|
|
* otherwise lpDx would need to specify the lengths of each character. */
|
|
|
|
if (width && nChars == 1)
|
|
|
|
lpDx = &width; /* Make sure underline for tab extends across tab space */
|
2008-01-01 22:04:04 +01:00
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
hOldFont = ME_SelectStyleFont(c, s);
|
2005-06-12 12:43:24 +02:00
|
|
|
if ((s->fmt.dwMask & s->fmt.dwEffects) & CFM_OFFSET) {
|
|
|
|
yTwipsOffset = s->fmt.yOffset;
|
|
|
|
}
|
|
|
|
if ((s->fmt.dwMask & s->fmt.dwEffects) & (CFM_SUPERSCRIPT | CFM_SUBSCRIPT)) {
|
|
|
|
if (s->fmt.dwEffects & CFE_SUPERSCRIPT) yTwipsOffset = s->fmt.yHeight/3;
|
|
|
|
if (s->fmt.dwEffects & CFE_SUBSCRIPT) yTwipsOffset = -s->fmt.yHeight/12;
|
|
|
|
}
|
|
|
|
if (yTwipsOffset)
|
2008-01-01 22:05:33 +01:00
|
|
|
yOffset = ME_twips2pointsY(c, yTwipsOffset);
|
2008-07-11 00:28:45 +02:00
|
|
|
|
|
|
|
if ((s->fmt.dwMask & CFM_LINK) && (s->fmt.dwEffects & CFE_LINK))
|
|
|
|
rgb = RGB(0,0,255);
|
|
|
|
else if ((s->fmt.dwMask & CFM_COLOR) && (s->fmt.dwEffects & CFE_AUTOCOLOR))
|
|
|
|
rgb = GetSysColor(COLOR_WINDOWTEXT);
|
|
|
|
else
|
|
|
|
rgb = s->fmt.crTextColor;
|
|
|
|
|
|
|
|
/* Determine the area that is selected in the run. */
|
2008-01-01 22:04:04 +01:00
|
|
|
GetTextExtentPoint32W(hDC, szText, nChars, &sz);
|
2008-07-11 00:26:56 +02:00
|
|
|
/* Treat width as an optional parameter. We can get the width from the
|
|
|
|
* text extent of the string if it isn't specified. */
|
|
|
|
if (!width) width = sz.cx;
|
2008-07-11 00:28:45 +02:00
|
|
|
if (bHighlightedText)
|
|
|
|
{
|
|
|
|
if (nSelFrom <= 0)
|
|
|
|
{
|
|
|
|
nSelFrom = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetTextExtentPoint32W(hDC, szText, nSelFrom, &sz);
|
|
|
|
xSelStart = x + sz.cx;
|
|
|
|
}
|
|
|
|
if (nSelTo >= nChars)
|
|
|
|
{
|
|
|
|
nSelTo = nChars;
|
|
|
|
xSelEnd = x + width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetTextExtentPoint32W(hDC, szText+nSelFrom, nSelTo-nSelFrom, &sz);
|
|
|
|
xSelEnd = xSelStart + sz.cx;
|
|
|
|
}
|
|
|
|
}
|
2008-07-11 00:26:56 +02:00
|
|
|
|
2008-07-11 00:28:45 +02:00
|
|
|
/* Choose the pen type for underlining the text. */
|
2008-01-01 22:04:04 +01:00
|
|
|
if (s->fmt.dwMask & CFM_UNDERLINETYPE)
|
|
|
|
{
|
|
|
|
switch (s->fmt.bUnderlineType)
|
|
|
|
{
|
|
|
|
case CFU_UNDERLINE:
|
|
|
|
case CFU_UNDERLINEWORD: /* native seems to map it to simple underline (MSDN) */
|
|
|
|
case CFU_UNDERLINEDOUBLE: /* native seems to map it to simple underline (MSDN) */
|
|
|
|
hPen = CreatePen(PS_SOLID, 1, rgb);
|
|
|
|
break;
|
|
|
|
case CFU_UNDERLINEDOTTED:
|
|
|
|
hPen = CreatePen(PS_DOT, 1, rgb);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WINE_FIXME("Unknown underline type (%u)\n", s->fmt.bUnderlineType);
|
|
|
|
/* fall through */
|
|
|
|
case CFU_CF1UNDERLINE: /* this type is supported in the font, do nothing */
|
|
|
|
case CFU_UNDERLINENONE:
|
|
|
|
hPen = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
if (hPen)
|
2008-01-01 22:04:04 +01:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
hOldPen = SelectObject(hDC, hPen);
|
2008-01-01 22:04:04 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
|
|
|
|
rgbOld = SetTextColor(hDC, rgb);
|
|
|
|
if (bHighlightedText && !c->editor->bEmulateVersion10)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
COLORREF rgbBackOld;
|
|
|
|
RECT dim;
|
|
|
|
/* FIXME: should use textmetrics info for Descent info */
|
|
|
|
if (hPen)
|
|
|
|
MoveToEx(hDC, x, y - yOffset + 1, NULL);
|
|
|
|
if (xSelStart > x)
|
2008-07-11 00:26:56 +02:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nSelFrom, NULL);
|
|
|
|
if (hPen)
|
|
|
|
LineTo(hDC, xSelStart, y - yOffset + 1);
|
2008-07-11 00:26:56 +02:00
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
dim.top = ymin;
|
|
|
|
dim.bottom = ymin + cy;
|
|
|
|
dim.left = xSelStart;
|
|
|
|
dim.right = xSelEnd;
|
|
|
|
SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
|
|
|
|
rgbBackOld = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT));
|
|
|
|
ExtTextOutW(hDC, xSelStart, y-yOffset, ETO_OPAQUE, &dim,
|
|
|
|
szText+nSelFrom, nSelTo-nSelFrom, lpDx);
|
|
|
|
if (hPen)
|
|
|
|
LineTo(hDC, xSelEnd, y - yOffset + 1);
|
|
|
|
SetBkColor(hDC, rgbBackOld);
|
|
|
|
if (xSelEnd < x + width)
|
2008-07-11 00:26:56 +02:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
SetTextColor(hDC, rgb);
|
|
|
|
ExtTextOutW(hDC, xSelEnd, y-yOffset, 0, NULL, szText+nSelTo,
|
|
|
|
nChars-nSelTo, NULL);
|
|
|
|
if (hPen)
|
|
|
|
LineTo(hDC, x + width, y - yOffset + 1);
|
2008-07-11 00:26:56 +02:00
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ExtTextOutW(hDC, x, y-yOffset, 0, NULL, szText, nChars, lpDx);
|
|
|
|
|
|
|
|
/* FIXME: should use textmetrics info for Descent info */
|
|
|
|
if (hPen)
|
2008-07-11 00:26:56 +02:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
MoveToEx(hDC, x, y - yOffset + 1, NULL);
|
|
|
|
LineTo(hDC, x + width, y - yOffset + 1);
|
2008-07-11 00:26:56 +02:00
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
|
|
|
|
if (bHighlightedText) /* v1.0 inverts the selection */
|
2008-07-11 00:26:56 +02:00
|
|
|
{
|
2008-07-11 00:28:45 +02:00
|
|
|
PatBlt(hDC, xSelStart, ymin, xSelEnd-xSelStart, cy, DSTINVERT);
|
2008-07-11 00:26:56 +02:00
|
|
|
}
|
2008-07-11 00:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hPen)
|
|
|
|
{
|
|
|
|
SelectObject(hDC, hOldPen);
|
|
|
|
DeleteObject(hPen);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
SetTextColor(hDC, rgbOld);
|
2008-01-01 22:05:33 +01:00
|
|
|
ME_UnselectStyleFont(c, s, hOldFont);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2007-08-13 23:41:55 +02:00
|
|
|
static void ME_DebugWrite(HDC hDC, const POINT *pt, LPCWSTR szText) {
|
2005-03-05 12:19:14 +01:00
|
|
|
int align = SetTextAlign(hDC, TA_LEFT|TA_TOP);
|
|
|
|
HGDIOBJ hFont = SelectObject(hDC, GetStockObject(DEFAULT_GUI_FONT));
|
|
|
|
COLORREF color = SetTextColor(hDC, RGB(128,128,128));
|
|
|
|
TextOutW(hDC, pt->x, pt->y, szText, lstrlenW(szText));
|
|
|
|
SelectObject(hDC, hFont);
|
|
|
|
SetTextAlign(hDC, align);
|
|
|
|
SetTextColor(hDC, color);
|
|
|
|
}
|
|
|
|
|
2006-08-04 21:47:44 +02:00
|
|
|
static void ME_DrawRun(ME_Context *c, int x, int y, ME_DisplayItem *rundi, ME_Paragraph *para)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_Run *run = &rundi->member.run;
|
2008-01-01 22:05:22 +01:00
|
|
|
ME_DisplayItem *start;
|
2005-03-05 12:19:14 +01:00
|
|
|
int runofs = run->nCharOfs+para->nCharOfs;
|
2006-01-13 13:53:35 +01:00
|
|
|
int nSelFrom, nSelTo;
|
|
|
|
const WCHAR wszSpace[] = {' ', 0};
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2006-01-31 13:01:26 +01:00
|
|
|
if (run->nFlags & MERF_HIDDEN)
|
|
|
|
return;
|
|
|
|
|
2008-01-01 22:05:22 +01:00
|
|
|
start = ME_FindItemBack(rundi, diStartRow);
|
2006-01-13 13:53:35 +01:00
|
|
|
ME_GetSelection(c->editor, &nSelFrom, &nSelTo);
|
|
|
|
|
|
|
|
/* Draw selected end-of-paragraph mark */
|
2005-03-17 11:23:40 +01:00
|
|
|
/* you can always comment it out if you need visible paragraph marks */
|
2008-07-11 00:26:56 +02:00
|
|
|
if (run->nFlags & MERF_ENDPARA)
|
2008-07-11 00:28:41 +02:00
|
|
|
{
|
|
|
|
if (runofs >= nSelFrom && runofs < nSelTo)
|
|
|
|
{
|
|
|
|
ME_HighlightSpace(c, x, y, wszSpace, 1, run->style, 0, 0, 1,
|
2008-12-19 15:54:58 +01:00
|
|
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
2008-07-11 00:28:41 +02:00
|
|
|
start->member.row.nHeight);
|
|
|
|
}
|
2005-03-17 11:23:40 +01:00
|
|
|
return;
|
2008-07-11 00:28:41 +02:00
|
|
|
}
|
2006-01-13 13:53:35 +01:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
if (run->nFlags & (MERF_TAB | MERF_ENDCELL))
|
2008-07-11 00:26:56 +02:00
|
|
|
{
|
|
|
|
/* wszSpace is used instead of the tab character because otherwise
|
|
|
|
* an unwanted symbol can be inserted instead. */
|
|
|
|
ME_DrawTextWithStyle(c, x, y, wszSpace, 1, run->style, run->nWidth,
|
2008-12-18 07:56:49 +01:00
|
|
|
nSelFrom-runofs, nSelTo-runofs,
|
2008-12-19 15:54:58 +01:00
|
|
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
2008-07-11 00:26:56 +02:00
|
|
|
start->member.row.nHeight);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-01-13 13:53:35 +01:00
|
|
|
if (run->nFlags & MERF_GRAPHICS)
|
2008-01-27 19:01:41 +01:00
|
|
|
ME_DrawOLE(c, x, y, run, para, (runofs >= nSelFrom) && (runofs < nSelTo));
|
2006-01-13 13:53:35 +01:00
|
|
|
else
|
2006-08-04 21:47:44 +02:00
|
|
|
{
|
|
|
|
if (c->editor->cPasswordMask)
|
|
|
|
{
|
|
|
|
ME_String *szMasked = ME_MakeStringR(c->editor->cPasswordMask,ME_StrVLen(run->strText));
|
2008-07-11 00:26:56 +02:00
|
|
|
ME_DrawTextWithStyle(c, x, y,
|
|
|
|
szMasked->szData, ME_StrVLen(szMasked), run->style, run->nWidth,
|
2008-12-18 07:56:49 +01:00
|
|
|
nSelFrom-runofs,nSelTo-runofs,
|
2008-12-19 15:54:58 +01:00
|
|
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
2008-12-18 07:56:49 +01:00
|
|
|
start->member.row.nHeight);
|
2006-08-04 21:47:44 +02:00
|
|
|
ME_DestroyString(szMasked);
|
|
|
|
}
|
|
|
|
else
|
2008-07-11 00:26:56 +02:00
|
|
|
ME_DrawTextWithStyle(c, x, y,
|
|
|
|
run->strText->szData, ME_StrVLen(run->strText), run->style, run->nWidth,
|
2008-12-18 07:56:49 +01:00
|
|
|
nSelFrom-runofs,nSelTo-runofs,
|
2008-12-19 15:54:58 +01:00
|
|
|
c->pt.y + para->pt.y + start->member.row.pt.y,
|
2008-12-18 07:56:49 +01:00
|
|
|
start->member.row.nHeight);
|
2008-07-11 00:26:56 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2008-06-19 23:52:00 +02:00
|
|
|
static const struct {unsigned width_num : 4, width_den : 4, pen_style : 4, dble : 1;} border_details[] = {
|
2008-03-16 21:45:31 +01:00
|
|
|
/* none */ {0, 1, PS_SOLID, FALSE},
|
2008-01-01 22:04:46 +01:00
|
|
|
/* 3/4 */ {3, 4, PS_SOLID, FALSE},
|
|
|
|
/* 1 1/2 */ {3, 2, PS_SOLID, FALSE},
|
|
|
|
/* 2 1/4 */ {9, 4, PS_SOLID, FALSE},
|
|
|
|
/* 3 */ {3, 1, PS_SOLID, FALSE},
|
|
|
|
/* 4 1/2 */ {9, 2, PS_SOLID, FALSE},
|
|
|
|
/* 6 */ {6, 1, PS_SOLID, FALSE},
|
|
|
|
/* 3/4 double */ {3, 4, PS_SOLID, TRUE},
|
|
|
|
/* 1 1/2 double */ {3, 2, PS_SOLID, TRUE},
|
|
|
|
/* 2 1/4 double */ {9, 4, PS_SOLID, TRUE},
|
|
|
|
/* 3/4 gray */ {3, 4, PS_DOT /* FIXME */, FALSE},
|
|
|
|
/* 1 1/2 dashed */ {3, 2, PS_DASH, FALSE},
|
|
|
|
};
|
|
|
|
|
2008-06-19 23:52:00 +02:00
|
|
|
static const COLORREF pen_colors[16] = {
|
2008-01-01 22:04:46 +01:00
|
|
|
/* Black */ RGB(0x00, 0x00, 0x00), /* Blue */ RGB(0x00, 0x00, 0xFF),
|
|
|
|
/* Cyan */ RGB(0x00, 0xFF, 0xFF), /* Green */ RGB(0x00, 0xFF, 0x00),
|
|
|
|
/* Magenta */ RGB(0xFF, 0x00, 0xFF), /* Red */ RGB(0xFF, 0x00, 0x00),
|
|
|
|
/* Yellow */ RGB(0xFF, 0xFF, 0x00), /* White */ RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
/* Dark blue */ RGB(0x00, 0x00, 0x80), /* Dark cyan */ RGB(0x00, 0x80, 0x80),
|
|
|
|
/* Dark green */ RGB(0x00, 0x80, 0x80), /* Dark magenta */ RGB(0x80, 0x00, 0x80),
|
|
|
|
/* Dark red */ RGB(0x80, 0x00, 0x00), /* Dark yellow */ RGB(0x80, 0x80, 0x00),
|
|
|
|
/* Dark gray */ RGB(0x80, 0x80, 0x80), /* Light gray */ RGB(0xc0, 0xc0, 0xc0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ME_GetBorderPenWidth(ME_TextEditor* editor, int idx)
|
|
|
|
{
|
|
|
|
int width;
|
|
|
|
|
|
|
|
if (editor->nZoomNumerator == 0)
|
|
|
|
{
|
|
|
|
width = border_details[idx].width_num + border_details[idx].width_den / 2;
|
|
|
|
width /= border_details[idx].width_den;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = border_details[idx].width_num * editor->nZoomNumerator;
|
|
|
|
width += border_details[idx].width_den * editor->nZoomNumerator / 2;
|
|
|
|
width /= border_details[idx].width_den * editor->nZoomDenominator;
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ME_GetParaBorderWidth(ME_TextEditor* editor, int flags)
|
|
|
|
{
|
|
|
|
int idx = (flags >> 8) & 0xF;
|
|
|
|
int width;
|
|
|
|
|
|
|
|
if (idx >= sizeof(border_details) / sizeof(border_details[0]))
|
|
|
|
{
|
|
|
|
FIXME("Unsupported border value %d\n", idx);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
width = ME_GetBorderPenWidth(editor, idx);
|
|
|
|
if (border_details[idx].dble) width = width * 2 + 1;
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:05:33 +01:00
|
|
|
int ME_GetParaLineSpace(ME_Context* c, ME_Paragraph* para)
|
2008-01-01 22:04:58 +01:00
|
|
|
{
|
|
|
|
int sp = 0, ls = 0;
|
|
|
|
if (!(para->pFmt->dwMask & PFM_LINESPACING)) return 0;
|
|
|
|
|
|
|
|
/* FIXME: how to compute simply the line space in ls ??? */
|
|
|
|
/* FIXME: does line spacing include the line itself ??? */
|
|
|
|
switch (para->pFmt->bLineSpacingRule)
|
|
|
|
{
|
|
|
|
case 0: sp = ls; break;
|
|
|
|
case 1: sp = (3 * ls) / 2; break;
|
|
|
|
case 2: sp = 2 * ls; break;
|
2008-01-01 22:05:33 +01:00
|
|
|
case 3: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); if (sp < ls) sp = ls; break;
|
|
|
|
case 4: sp = ME_twips2pointsY(c, para->pFmt->dyLineSpacing); break;
|
2008-01-01 22:04:58 +01:00
|
|
|
case 5: sp = para->pFmt->dyLineSpacing / 20; break;
|
|
|
|
default: FIXME("Unsupported spacing rule value %d\n", para->pFmt->bLineSpacingRule);
|
|
|
|
}
|
2008-01-01 22:05:33 +01:00
|
|
|
if (c->editor->nZoomNumerator == 0)
|
2008-01-01 22:04:58 +01:00
|
|
|
return sp;
|
|
|
|
else
|
2008-01-01 22:05:33 +01:00
|
|
|
return sp * c->editor->nZoomNumerator / c->editor->nZoomDenominator;
|
2008-01-01 22:04:58 +01:00
|
|
|
}
|
|
|
|
|
2008-04-24 22:04:26 +02:00
|
|
|
static void ME_DrawParaDecoration(ME_Context* c, ME_Paragraph* para, int y, RECT* bounds)
|
2008-01-01 22:04:46 +01:00
|
|
|
{
|
2008-04-24 22:04:26 +02:00
|
|
|
int idx, border_width, top_border, bottom_border;
|
2008-01-01 22:04:52 +01:00
|
|
|
RECT rc;
|
2008-08-13 05:15:36 +02:00
|
|
|
BOOL hasParaBorder;
|
2008-01-01 22:04:46 +01:00
|
|
|
|
2008-04-24 22:04:26 +02:00
|
|
|
SetRectEmpty(bounds);
|
|
|
|
if (!(para->pFmt->dwMask & (PFM_BORDER | PFM_SPACEBEFORE | PFM_SPACEAFTER))) return;
|
|
|
|
|
|
|
|
border_width = top_border = bottom_border = 0;
|
|
|
|
idx = (para->pFmt->wBorders >> 8) & 0xF;
|
2008-08-13 05:15:36 +02:00
|
|
|
hasParaBorder = (!(c->editor->bEmulateVersion10 &&
|
|
|
|
para->pFmt->dwMask & PFM_TABLE &&
|
|
|
|
para->pFmt->wEffects & PFE_TABLE) &&
|
|
|
|
(para->pFmt->dwMask & PFM_BORDER) &&
|
|
|
|
idx != 0 &&
|
|
|
|
(para->pFmt->wBorders & 0xF));
|
|
|
|
if (hasParaBorder)
|
2008-04-24 22:04:26 +02:00
|
|
|
{
|
2008-08-13 05:15:36 +02:00
|
|
|
/* FIXME: wBorders is not stored as MSDN says in v1.0 - 4.1 of richedit
|
|
|
|
* controls. It actually stores the paragraph or row border style. Although
|
|
|
|
* the value isn't used for drawing, it is used for streaming out rich text.
|
|
|
|
*
|
|
|
|
* wBorders stores the border style for each side (top, left, bottom, right)
|
|
|
|
* using nibble (4 bits) to store each border style. The rich text format
|
|
|
|
* control words, and their associated value are the following:
|
|
|
|
* \brdrdash 0
|
|
|
|
* \brdrdashsm 1
|
|
|
|
* \brdrdb 2
|
|
|
|
* \brdrdot 3
|
|
|
|
* \brdrhair 4
|
|
|
|
* \brdrs 5
|
|
|
|
* \brdrth 6
|
|
|
|
* \brdrtriple 7
|
|
|
|
*
|
|
|
|
* The order of the sides stored actually differs from v1.0 to 3.0 and v4.1.
|
|
|
|
* The mask corresponding to each side for the version are the following:
|
|
|
|
* mask v1.0-3.0 v4.1
|
|
|
|
* 0x000F top left
|
|
|
|
* 0x00F0 left top
|
|
|
|
* 0x0F00 bottom right
|
|
|
|
* 0xF000 right bottom
|
|
|
|
*/
|
2008-04-24 22:04:26 +02:00
|
|
|
if (para->pFmt->wBorders & 0x00B0)
|
|
|
|
FIXME("Unsupported border flags %x\n", para->pFmt->wBorders);
|
|
|
|
border_width = ME_GetParaBorderWidth(c->editor, para->pFmt->wBorders);
|
|
|
|
if (para->pFmt->wBorders & 4) top_border = border_width;
|
|
|
|
if (para->pFmt->wBorders & 8) bottom_border = border_width;
|
|
|
|
}
|
2008-01-01 22:04:46 +01:00
|
|
|
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->dwMask & PFM_SPACEBEFORE)
|
|
|
|
{
|
|
|
|
rc.left = c->rcView.left;
|
|
|
|
rc.right = c->rcView.right;
|
|
|
|
rc.top = y;
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->top = ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
|
|
|
|
rc.bottom = y + bounds->top + top_border;
|
2008-01-01 22:04:52 +01:00
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->dwMask & PFM_SPACEAFTER)
|
|
|
|
{
|
|
|
|
rc.left = c->rcView.left;
|
|
|
|
rc.right = c->rcView.right;
|
|
|
|
rc.bottom = y + para->nHeight;
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->bottom = ME_twips2pointsY(c, para->pFmt->dySpaceAfter);
|
|
|
|
rc.top = rc.bottom - bounds->bottom - bottom_border;
|
2008-01-01 22:04:52 +01:00
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
}
|
|
|
|
|
2008-08-13 05:15:36 +02:00
|
|
|
/* Native richedit doesn't support paragraph borders in v1.0 - 4.1,
|
|
|
|
* but might support it in later versions. */
|
|
|
|
if (hasParaBorder) {
|
2008-01-01 22:04:52 +01:00
|
|
|
int pen_width;
|
|
|
|
COLORREF pencr;
|
|
|
|
HPEN pen = NULL, oldpen = NULL;
|
|
|
|
POINT pt;
|
|
|
|
|
|
|
|
if (para->pFmt->wBorders & 64) /* autocolor */
|
2008-01-01 22:04:46 +01:00
|
|
|
pencr = GetSysColor(COLOR_WINDOWTEXT);
|
2008-01-01 22:04:52 +01:00
|
|
|
else
|
2008-01-01 22:04:46 +01:00
|
|
|
pencr = pen_colors[(para->pFmt->wBorders >> 12) & 0xF];
|
|
|
|
|
2008-01-01 22:04:52 +01:00
|
|
|
pen_width = ME_GetBorderPenWidth(c->editor, idx);
|
|
|
|
pen = CreatePen(border_details[idx].pen_style, pen_width, pencr);
|
|
|
|
oldpen = SelectObject(c->hDC, pen);
|
|
|
|
MoveToEx(c->hDC, 0, 0, &pt);
|
|
|
|
|
|
|
|
/* before & after spaces are not included in border */
|
2008-04-24 22:04:26 +02:00
|
|
|
|
|
|
|
/* helper to draw the double lines in case of corner */
|
|
|
|
#define DD(x) ((para->pFmt->wBorders & (x)) ? (pen_width + 1) : 0)
|
|
|
|
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->wBorders & 1)
|
|
|
|
{
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom);
|
2008-01-01 22:04:52 +01:00
|
|
|
if (border_details[idx].dble) {
|
2008-04-24 22:04:26 +02:00
|
|
|
rc.left = c->rcView.left + 1;
|
|
|
|
rc.right = rc.left + border_width;
|
|
|
|
rc.top = y + bounds->top;
|
|
|
|
rc.bottom = y + para->nHeight - bounds->bottom;
|
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
MoveToEx(c->hDC, c->rcView.left + pen_width + 1, y + bounds->top + DD(4), NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.left + pen_width + 1, y + para->nHeight - bounds->bottom - DD(8));
|
2008-01-01 22:04:52 +01:00
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->left += border_width;
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->wBorders & 2)
|
|
|
|
{
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.right - 1, y + bounds->top, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right - 1, y + para->nHeight - bounds->bottom);
|
2008-01-01 22:04:52 +01:00
|
|
|
if (border_details[idx].dble) {
|
2008-04-24 22:04:26 +02:00
|
|
|
rc.left = c->rcView.right - pen_width - 1;
|
|
|
|
rc.right = c->rcView.right - 1;
|
|
|
|
rc.top = y + bounds->top;
|
|
|
|
rc.bottom = y + para->nHeight - bounds->bottom;
|
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
MoveToEx(c->hDC, c->rcView.right - 1 - pen_width - 1, y + bounds->top + DD(4), NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right - 1 - pen_width - 1, y + para->nHeight - bounds->bottom - DD(8));
|
2008-01-01 22:04:52 +01:00
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->right += border_width;
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->wBorders & 4)
|
|
|
|
{
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.left, y + bounds->top, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right, y + bounds->top);
|
2008-01-01 22:04:52 +01:00
|
|
|
if (border_details[idx].dble) {
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.left + DD(1), y + bounds->top + pen_width + 1, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right - DD(2), y + bounds->top + pen_width + 1);
|
2008-01-01 22:04:52 +01:00
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->top += border_width;
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
2008-01-01 22:04:52 +01:00
|
|
|
if (para->pFmt->wBorders & 8)
|
|
|
|
{
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.left, y + para->nHeight - bounds->bottom - 1, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right, y + para->nHeight - bounds->bottom - 1);
|
2008-01-01 22:04:52 +01:00
|
|
|
if (border_details[idx].dble) {
|
2008-04-24 22:04:26 +02:00
|
|
|
MoveToEx(c->hDC, c->rcView.left + DD(1), y + para->nHeight - bounds->bottom - 1 - pen_width - 1, NULL);
|
|
|
|
LineTo(c->hDC, c->rcView.right - DD(2), y + para->nHeight - bounds->bottom - 1 - pen_width - 1);
|
2008-01-01 22:04:52 +01:00
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
bounds->bottom += border_width;
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
2008-04-24 22:04:26 +02:00
|
|
|
#undef DD
|
2008-01-01 22:04:52 +01:00
|
|
|
|
|
|
|
MoveToEx(c->hDC, pt.x, pt.y, NULL);
|
|
|
|
SelectObject(c->hDC, oldpen);
|
|
|
|
DeleteObject(pen);
|
2008-01-01 22:04:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-13 05:15:32 +02:00
|
|
|
static void ME_DrawTableBorders(ME_Context *c, ME_DisplayItem *paragraph)
|
|
|
|
{
|
|
|
|
ME_Paragraph *para = ¶graph->member.para;
|
2008-08-13 05:15:36 +02:00
|
|
|
if (!c->editor->bEmulateVersion10) /* v4.1 */
|
2008-08-13 05:15:32 +02:00
|
|
|
{
|
2008-08-13 05:15:36 +02:00
|
|
|
if (para->pCell)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
ME_Cell *cell = ¶->pCell->member.cell;
|
|
|
|
ME_DisplayItem *paraAfterRow;
|
|
|
|
HPEN pen, oldPen;
|
|
|
|
LOGBRUSH logBrush;
|
|
|
|
HBRUSH brush;
|
|
|
|
COLORREF color;
|
|
|
|
POINT oldPt;
|
|
|
|
int width;
|
|
|
|
BOOL atTop = (para->pCell != para->prev_para->member.para.pCell);
|
|
|
|
BOOL atBottom = (para->pCell != para->next_para->member.para.pCell);
|
2008-12-19 15:54:58 +01:00
|
|
|
int top = c->pt.y + (atTop ? cell->pt.y : para->pt.y);
|
2008-08-13 05:15:36 +02:00
|
|
|
int bottom = (atBottom ?
|
2008-12-19 15:54:58 +01:00
|
|
|
c->pt.y + cell->pt.y + cell->nHeight :
|
2008-08-13 05:15:36 +02:00
|
|
|
top + para->nHeight + (atTop ? cell->yTextOffset : 0));
|
2008-12-19 15:54:58 +01:00
|
|
|
rc.left = c->pt.x + cell->pt.x;
|
2008-08-13 05:15:36 +02:00
|
|
|
rc.right = rc.left + cell->nWidth;
|
|
|
|
if (atTop) {
|
|
|
|
/* Erase gap before text if not all borders are the same height. */
|
|
|
|
width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
|
|
|
|
rc.top = top + width;
|
|
|
|
width = cell->yTextOffset - width;
|
|
|
|
rc.bottom = rc.top + width;
|
|
|
|
if (width) {
|
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Draw cell borders.
|
2008-12-19 15:54:58 +01:00
|
|
|
* The order borders are draw in is left, top, bottom, right in order
|
2008-08-13 05:15:36 +02:00
|
|
|
* to be consistent with native richedit. This is noticeable from the
|
|
|
|
* overlap of borders of different colours. */
|
|
|
|
if (!(para->nFlags & MEPF_ROWEND)) {
|
|
|
|
rc.top = top;
|
|
|
|
rc.bottom = bottom;
|
|
|
|
if (cell->border.left.width > 0)
|
|
|
|
{
|
2008-08-13 05:15:40 +02:00
|
|
|
color = cell->border.left.colorRef;
|
2008-08-13 05:15:36 +02:00
|
|
|
width = max(ME_twips2pointsX(c, cell->border.left.width), 1);
|
|
|
|
} else {
|
|
|
|
color = RGB(192,192,192);
|
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
logBrush.lbStyle = BS_SOLID;
|
|
|
|
logBrush.lbColor = color;
|
|
|
|
logBrush.lbHatch = 0;
|
|
|
|
pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
|
|
|
|
width, &logBrush, 0, NULL);
|
|
|
|
oldPen = SelectObject(c->hDC, pen);
|
|
|
|
MoveToEx(c->hDC, rc.left, rc.top, &oldPt);
|
|
|
|
LineTo(c->hDC, rc.left, rc.bottom);
|
|
|
|
SelectObject(c->hDC, oldPen);
|
|
|
|
DeleteObject(pen);
|
|
|
|
MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atTop) {
|
|
|
|
if (cell->border.top.width > 0)
|
|
|
|
{
|
2008-08-13 05:15:40 +02:00
|
|
|
brush = CreateSolidBrush(cell->border.top.colorRef);
|
2008-08-13 05:15:36 +02:00
|
|
|
width = max(ME_twips2pointsY(c, cell->border.top.width), 1);
|
|
|
|
} else {
|
|
|
|
brush = GetStockObject(LTGRAY_BRUSH);
|
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
rc.top = top;
|
|
|
|
rc.bottom = rc.top + width;
|
|
|
|
FillRect(c->hDC, &rc, brush);
|
2008-08-13 05:15:40 +02:00
|
|
|
if (cell->border.top.width > 0)
|
|
|
|
DeleteObject(brush);
|
2008-08-13 05:15:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw the bottom border if at the last paragraph in the cell, and when
|
|
|
|
* in the last row of the table. */
|
|
|
|
if (atBottom) {
|
|
|
|
int oldLeft = rc.left;
|
|
|
|
width = max(ME_twips2pointsY(c, cell->border.bottom.width), 1);
|
|
|
|
paraAfterRow = ME_GetTableRowEnd(paragraph)->member.para.next_para;
|
|
|
|
if (paraAfterRow->member.para.nFlags & MEPF_ROWSTART) {
|
|
|
|
ME_DisplayItem *nextEndCell;
|
|
|
|
nextEndCell = ME_FindItemBack(ME_GetTableRowEnd(paraAfterRow), diCell);
|
|
|
|
assert(nextEndCell && !nextEndCell->member.cell.next_cell);
|
2008-12-19 15:54:58 +01:00
|
|
|
rc.left = c->pt.x + nextEndCell->member.cell.pt.x;
|
2008-08-13 05:15:36 +02:00
|
|
|
/* FIXME: Native draws FROM the bottom of the table rather than
|
|
|
|
* TO the bottom of the table in this case, but just doing so here
|
2008-12-18 07:56:49 +01:00
|
|
|
* will cause the next row to erase the border. */
|
2008-08-13 05:15:36 +02:00
|
|
|
/*
|
|
|
|
rc.top = bottom;
|
|
|
|
rc.bottom = rc.top + width;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
if (rc.left < rc.right) {
|
|
|
|
if (cell->border.bottom.width > 0) {
|
2008-08-13 05:15:40 +02:00
|
|
|
brush = CreateSolidBrush(cell->border.bottom.colorRef);
|
2008-08-13 05:15:36 +02:00
|
|
|
} else {
|
|
|
|
brush = GetStockObject(LTGRAY_BRUSH);
|
|
|
|
}
|
|
|
|
rc.bottom = bottom;
|
|
|
|
rc.top = rc.bottom - width;
|
|
|
|
FillRect(c->hDC, &rc, brush);
|
2008-08-13 05:15:40 +02:00
|
|
|
if (cell->border.bottom.width > 0)
|
|
|
|
DeleteObject(brush);
|
2008-08-13 05:15:36 +02:00
|
|
|
}
|
|
|
|
rc.left = oldLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Right border only drawn if at the end of the table row. */
|
|
|
|
if (!cell->next_cell->member.cell.next_cell &&
|
|
|
|
!(para->nFlags & MEPF_ROWSTART))
|
|
|
|
{
|
|
|
|
rc.top = top;
|
|
|
|
rc.bottom = bottom;
|
|
|
|
if (cell->border.right.width > 0) {
|
2008-08-13 05:15:40 +02:00
|
|
|
color = cell->border.right.colorRef;
|
2008-08-13 05:15:36 +02:00
|
|
|
width = max(ME_twips2pointsX(c, cell->border.right.width), 1);
|
|
|
|
} else {
|
|
|
|
color = RGB(192,192,192);
|
|
|
|
width = 1;
|
|
|
|
}
|
|
|
|
logBrush.lbStyle = BS_SOLID;
|
|
|
|
logBrush.lbColor = color;
|
|
|
|
logBrush.lbHatch = 0;
|
|
|
|
pen = ExtCreatePen(PS_GEOMETRIC|PS_SOLID|PS_ENDCAP_FLAT|PS_JOIN_MITER,
|
|
|
|
width, &logBrush, 0, NULL);
|
|
|
|
oldPen = SelectObject(c->hDC, pen);
|
|
|
|
MoveToEx(c->hDC, rc.right - 1, rc.top, &oldPt);
|
|
|
|
LineTo(c->hDC, rc.right - 1, rc.bottom);
|
|
|
|
SelectObject(c->hDC, oldPen);
|
|
|
|
DeleteObject(pen);
|
|
|
|
MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - 3.0 */
|
|
|
|
/* Draw simple table border */
|
2008-08-13 05:15:32 +02:00
|
|
|
if (para->pFmt->dwMask & PFM_TABLE && para->pFmt->wEffects & PFE_TABLE) {
|
|
|
|
HPEN pen = NULL, oldpen = NULL;
|
|
|
|
int i, firstX, startX, endX, rowY, rowBottom, nHeight;
|
|
|
|
POINT oldPt;
|
|
|
|
PARAFORMAT2 *pNextFmt;
|
|
|
|
|
2008-08-13 05:15:40 +02:00
|
|
|
pen = CreatePen(PS_SOLID, 0, para->border.top.colorRef);
|
2008-08-13 05:15:32 +02:00
|
|
|
oldpen = SelectObject(c->hDC, pen);
|
|
|
|
|
|
|
|
/* Find the start relative to the text */
|
2008-12-19 15:54:58 +01:00
|
|
|
firstX = c->pt.x + ME_FindItemFwd(paragraph, diRun)->member.run.pt.x;
|
2008-08-13 05:15:32 +02:00
|
|
|
/* Go back by the horizontal gap, which is stored in dxOffset */
|
|
|
|
firstX -= ME_twips2pointsX(c, para->pFmt->dxOffset);
|
|
|
|
/* The left edge, stored in dxStartIndent affected just the first edge */
|
|
|
|
startX = firstX - ME_twips2pointsX(c, para->pFmt->dxStartIndent);
|
2008-12-19 15:54:58 +01:00
|
|
|
rowY = c->pt.y + para->pt.y;
|
2008-08-13 05:15:32 +02:00
|
|
|
if (para->pFmt->dwMask & PFM_SPACEBEFORE)
|
|
|
|
rowY += ME_twips2pointsY(c, para->pFmt->dySpaceBefore);
|
|
|
|
nHeight = ME_FindItemFwd(paragraph, diStartRow)->member.row.nHeight;
|
|
|
|
rowBottom = rowY + nHeight;
|
|
|
|
|
|
|
|
/* Draw horizontal lines */
|
|
|
|
MoveToEx(c->hDC, firstX, rowY, &oldPt);
|
|
|
|
i = para->pFmt->cTabCount - 1;
|
|
|
|
endX = startX + ME_twips2pointsX(c, para->pFmt->rgxTabs[i] & 0x00ffffff) + 1;
|
|
|
|
LineTo(c->hDC, endX, rowY);
|
|
|
|
pNextFmt = para->next_para->member.para.pFmt;
|
|
|
|
/* The bottom of the row only needs to be drawn if the next row is
|
|
|
|
* not a table. */
|
|
|
|
if (!(pNextFmt && pNextFmt->dwMask & PFM_TABLE && pNextFmt->wEffects &&
|
|
|
|
para->nRows == 1))
|
|
|
|
{
|
|
|
|
/* Decrement rowBottom to draw the bottom line within the row, and
|
|
|
|
* to not draw over this line when drawing the vertical lines. */
|
|
|
|
rowBottom--;
|
|
|
|
MoveToEx(c->hDC, firstX, rowBottom, NULL);
|
|
|
|
LineTo(c->hDC, endX, rowBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Draw vertical lines */
|
|
|
|
MoveToEx(c->hDC, firstX, rowY, NULL);
|
|
|
|
LineTo(c->hDC, firstX, rowBottom);
|
|
|
|
for (i = 0; i < para->pFmt->cTabCount; i++)
|
|
|
|
{
|
|
|
|
int rightBoundary = para->pFmt->rgxTabs[i] & 0x00ffffff;
|
|
|
|
endX = startX + ME_twips2pointsX(c, rightBoundary);
|
|
|
|
MoveToEx(c->hDC, endX, rowY, NULL);
|
|
|
|
LineTo(c->hDC, endX, rowBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
MoveToEx(c->hDC, oldPt.x, oldPt.y, NULL);
|
|
|
|
SelectObject(c->hDC, oldpen);
|
|
|
|
DeleteObject(pen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
void ME_DrawParagraph(ME_Context *c, ME_DisplayItem *paragraph)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
int align = SetTextAlign(c->hDC, TA_BASELINE);
|
|
|
|
ME_DisplayItem *p;
|
|
|
|
ME_Run *run;
|
|
|
|
ME_Paragraph *para = NULL;
|
2008-08-13 05:15:25 +02:00
|
|
|
RECT rc, bounds;
|
2008-12-19 15:54:58 +01:00
|
|
|
int y;
|
2008-08-13 05:15:25 +02:00
|
|
|
int height = 0, baseline = 0, no=0;
|
2008-01-01 22:04:34 +01:00
|
|
|
BOOL visible = FALSE;
|
2008-01-01 22:04:46 +01:00
|
|
|
|
2008-12-19 15:54:58 +01:00
|
|
|
rc.left = c->pt.x;
|
2008-08-07 18:31:41 +02:00
|
|
|
rc.right = c->rcView.right;
|
2008-12-19 15:54:58 +01:00
|
|
|
|
|
|
|
assert(paragraph);
|
|
|
|
para = ¶graph->member.para;
|
|
|
|
y = c->pt.y + para->pt.y;
|
|
|
|
if (para->pCell)
|
|
|
|
{
|
|
|
|
ME_Cell *cell = ¶->pCell->member.cell;
|
|
|
|
rc.left = c->pt.x + cell->pt.x;
|
|
|
|
rc.right = rc.left + cell->nWidth;
|
|
|
|
}
|
|
|
|
if (para->nFlags & MEPF_ROWSTART) {
|
|
|
|
ME_Cell *cell = ¶->next_para->member.para.pCell->member.cell;
|
|
|
|
rc.right = c->pt.x + cell->pt.x;
|
|
|
|
} else if (para->nFlags & MEPF_ROWEND) {
|
|
|
|
ME_Cell *cell = ¶->prev_para->member.para.pCell->member.cell;
|
|
|
|
rc.left = c->pt.x + cell->pt.x + cell->nWidth;
|
|
|
|
}
|
|
|
|
ME_DrawParaDecoration(c, para, y, &bounds);
|
|
|
|
y += bounds.top;
|
|
|
|
rc.left += bounds.left;
|
|
|
|
rc.right -= bounds.right;
|
|
|
|
|
|
|
|
for (p = paragraph->next; p != para->next_para; p = p->next)
|
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
switch(p->type) {
|
|
|
|
case diParagraph:
|
2008-12-19 15:54:58 +01:00
|
|
|
assert(FALSE);
|
2008-01-01 22:04:34 +01:00
|
|
|
break;
|
|
|
|
case diStartRow:
|
2005-03-05 12:19:14 +01:00
|
|
|
y += height;
|
2008-08-07 18:31:41 +02:00
|
|
|
rc.top = y;
|
2008-12-19 15:54:58 +01:00
|
|
|
if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND)) {
|
|
|
|
rc.bottom = y + para->nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
} else {
|
2008-12-18 07:56:49 +01:00
|
|
|
rc.bottom = y + p->member.row.nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
visible = RectVisible(c->hDC, &rc);
|
|
|
|
if (visible) {
|
2008-01-01 22:04:10 +01:00
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
if (me_debug)
|
|
|
|
{
|
|
|
|
const WCHAR wszRowDebug[] = {'r','o','w','[','%','d',']',0};
|
|
|
|
WCHAR buf[128];
|
|
|
|
POINT pt = c->pt;
|
|
|
|
wsprintfW(buf, wszRowDebug, no);
|
|
|
|
pt.y = 12+y;
|
|
|
|
ME_DebugWrite(c->hDC, &pt, buf);
|
|
|
|
}
|
2008-08-13 05:15:36 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
height = p->member.row.nHeight;
|
|
|
|
baseline = p->member.row.nBaseline;
|
|
|
|
break;
|
|
|
|
case diRun:
|
|
|
|
assert(para);
|
|
|
|
run = &p->member.run;
|
|
|
|
if (visible && me_debug) {
|
2008-12-19 15:54:58 +01:00
|
|
|
RECT rc;
|
|
|
|
rc.left = c->pt.x + run->pt.x;
|
2008-12-18 07:56:49 +01:00
|
|
|
rc.right = rc.left + run->nWidth;
|
2008-12-19 15:54:58 +01:00
|
|
|
rc.top = c->pt.y + para->pt.y + run->pt.y;
|
2008-12-18 07:56:49 +01:00
|
|
|
rc.bottom = rc.bottom + height;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("rc = (%d, %d, %d, %d)\n", rc.left, rc.top, rc.right, rc.bottom);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (run->nFlags & MERF_SKIPPED)
|
|
|
|
DrawFocusRect(c->hDC, &rc);
|
|
|
|
else
|
|
|
|
FrameRect(c->hDC, &rc, GetSysColorBrush(COLOR_GRAYTEXT));
|
|
|
|
}
|
|
|
|
if (visible)
|
2008-12-19 15:54:58 +01:00
|
|
|
ME_DrawRun(c, c->pt.x + run->pt.x,
|
|
|
|
c->pt.y + para->pt.y + run->pt.y + baseline, p, para);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (me_debug)
|
|
|
|
{
|
|
|
|
/* I'm using %ls, hope wsprintfW is not going to use wrong (4-byte) WCHAR version */
|
|
|
|
const WCHAR wszRunDebug[] = {'[','%','d',':','%','x',']',' ','%','l','s',0};
|
|
|
|
WCHAR buf[2560];
|
|
|
|
POINT pt;
|
2008-12-19 15:54:58 +01:00
|
|
|
pt.x = c->pt.x + run->pt.x;
|
|
|
|
pt.y = c->pt.y + para->pt.y + run->pt.y;
|
2005-03-05 12:19:14 +01:00
|
|
|
wsprintfW(buf, wszRunDebug, no, p->member.run.nFlags, p->member.run.strText->szData);
|
|
|
|
ME_DebugWrite(c->hDC, &pt, buf);
|
|
|
|
}
|
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
case diCell:
|
|
|
|
/* Clear any space at the bottom of the cell after the text. */
|
2008-12-19 15:54:58 +01:00
|
|
|
if (para->nFlags & (MEPF_ROWSTART|MEPF_ROWEND))
|
2008-08-07 18:31:41 +02:00
|
|
|
break;
|
|
|
|
y += height;
|
2008-12-19 15:54:58 +01:00
|
|
|
rc.top = c->pt.y + para->pt.y + para->nHeight;
|
|
|
|
rc.bottom = c->pt.y + p->member.cell.pt.y + p->member.cell.nHeight;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (RectVisible(c->hDC, &rc))
|
|
|
|
{
|
|
|
|
FillRect(c->hDC, &rc, c->editor->hbrBackground);
|
|
|
|
}
|
2008-08-13 05:15:36 +02:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
no++;
|
|
|
|
}
|
2008-08-13 05:15:32 +02:00
|
|
|
|
|
|
|
ME_DrawTableBorders(c, paragraph);
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
SetTextAlign(c->hDC, align);
|
|
|
|
}
|
|
|
|
|
2006-09-08 23:37:25 +02:00
|
|
|
void ME_ScrollAbs(ME_TextEditor *editor, int absY)
|
|
|
|
{
|
|
|
|
ME_Scroll(editor, absY, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_ScrollUp(ME_TextEditor *editor, int cy)
|
|
|
|
{
|
|
|
|
ME_Scroll(editor, cy, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_ScrollDown(ME_TextEditor *editor, int cy)
|
|
|
|
{
|
|
|
|
ME_Scroll(editor, cy, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_Scroll(ME_TextEditor *editor, int value, int type)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
SCROLLINFO si;
|
2006-09-08 23:37:25 +02:00
|
|
|
int nOrigPos, nNewPos, nActualScroll;
|
2008-09-18 07:17:45 +02:00
|
|
|
HWND hWnd;
|
|
|
|
LONG winStyle;
|
|
|
|
BOOL bScrollBarIsVisible, bScrollBarWillBeVisible;
|
2005-03-19 18:06:17 +01:00
|
|
|
|
2006-09-08 23:37:25 +02:00
|
|
|
nOrigPos = ME_GetYScrollPos(editor);
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
si.cbSize = sizeof(SCROLLINFO);
|
2005-03-19 18:06:17 +01:00
|
|
|
si.fMask = SIF_POS;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 1:
|
2008-04-11 04:17:14 +02:00
|
|
|
/*Scroll absolutely*/
|
2006-09-08 23:37:25 +02:00
|
|
|
si.nPos = value;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* Scroll up - towards the beginning of the document */
|
|
|
|
si.nPos = nOrigPos - value;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* Scroll down - towards the end of the document */
|
|
|
|
si.nPos = nOrigPos + value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("ME_Scroll called incorrectly\n");
|
|
|
|
si.nPos = 0;
|
|
|
|
}
|
|
|
|
|
2008-10-19 10:43:17 +02:00
|
|
|
nNewPos = SetScrollInfo(editor->hWnd, SB_VERT, &si, TRUE);
|
2008-09-18 04:02:08 +02:00
|
|
|
editor->vert_si.nPos = nNewPos;
|
2006-09-08 23:37:25 +02:00
|
|
|
nActualScroll = nOrigPos - nNewPos;
|
2008-10-19 10:43:17 +02:00
|
|
|
if (abs(nActualScroll) > editor->sizeWindow.cy)
|
|
|
|
InvalidateRect(editor->hWnd, NULL, TRUE);
|
|
|
|
else
|
|
|
|
ScrollWindowEx(editor->hWnd, 0, nActualScroll, NULL, NULL, NULL, NULL, SW_INVALIDATE);
|
|
|
|
ME_Repaint(editor);
|
2006-09-08 23:37:25 +02:00
|
|
|
|
2008-09-18 07:17:45 +02:00
|
|
|
hWnd = editor->hWnd;
|
|
|
|
winStyle = GetWindowLongW(hWnd, GWL_STYLE);
|
|
|
|
bScrollBarIsVisible = (winStyle & WS_VSCROLL) != 0;
|
2008-12-19 14:15:04 +01:00
|
|
|
bScrollBarWillBeVisible = (editor->nTotalLength > editor->sizeWindow.cy)
|
2008-09-18 07:17:45 +02:00
|
|
|
|| (winStyle & ES_DISABLENOSCROLL);
|
|
|
|
if (bScrollBarIsVisible != bScrollBarWillBeVisible)
|
|
|
|
{
|
|
|
|
ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
|
|
|
|
}
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_UpdateScrollBar(editor);
|
2005-03-19 18:06:17 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2006-09-08 23:37:25 +02:00
|
|
|
|
2008-09-19 17:37:27 +02:00
|
|
|
void ME_UpdateScrollBar(ME_TextEditor *editor)
|
2006-09-08 23:37:25 +02:00
|
|
|
{
|
2008-04-11 04:17:14 +02:00
|
|
|
/* Note that this is the only function that should ever call SetScrolLInfo
|
2006-09-08 23:37:25 +02:00
|
|
|
* with SIF_PAGE or SIF_RANGE. SetScrollPos and SetScrollRange should never
|
|
|
|
* be used at all. */
|
|
|
|
|
|
|
|
HWND hWnd;
|
2005-03-19 18:06:17 +01:00
|
|
|
SCROLLINFO si;
|
2006-09-08 23:37:25 +02:00
|
|
|
BOOL bScrollBarWasVisible,bScrollBarWillBeVisible;
|
|
|
|
|
|
|
|
if (ME_WrapMarkedParagraphs(editor))
|
|
|
|
FIXME("ME_UpdateScrollBar had to call ME_WrapMarkedParagraphs\n");
|
|
|
|
|
|
|
|
hWnd = editor->hWnd;
|
2005-03-19 18:06:17 +01:00
|
|
|
si.cbSize = sizeof(si);
|
2006-09-08 23:37:25 +02:00
|
|
|
bScrollBarWasVisible = ME_GetYScrollVisible(editor);
|
2008-12-19 14:15:04 +01:00
|
|
|
bScrollBarWillBeVisible = editor->nTotalLength > editor->sizeWindow.cy;
|
2006-08-08 22:08:43 +02:00
|
|
|
|
2008-09-18 04:02:08 +02:00
|
|
|
si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
|
2008-07-20 18:29:19 +02:00
|
|
|
if (GetWindowLongW(hWnd, GWL_STYLE) & ES_DISABLENOSCROLL)
|
|
|
|
{
|
2008-09-18 15:38:55 +02:00
|
|
|
si.fMask |= SIF_DISABLENOSCROLL;
|
2008-07-20 18:29:19 +02:00
|
|
|
bScrollBarWillBeVisible = TRUE;
|
|
|
|
}
|
|
|
|
|
2006-09-08 23:37:25 +02:00
|
|
|
if (bScrollBarWasVisible != bScrollBarWillBeVisible)
|
|
|
|
{
|
|
|
|
ShowScrollBar(hWnd, SB_VERT, bScrollBarWillBeVisible);
|
2005-03-19 18:06:17 +01:00
|
|
|
ME_MarkAllForWrapping(editor);
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
si.nMin = 0;
|
2008-06-24 20:25:52 +02:00
|
|
|
si.nMax = editor->nTotalLength;
|
2008-09-18 04:02:08 +02:00
|
|
|
si.nPos = editor->vert_si.nPos;
|
2008-06-24 20:25:52 +02:00
|
|
|
si.nPage = editor->sizeWindow.cy;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
2008-07-20 18:29:19 +02:00
|
|
|
if (!(si.nMin == editor->vert_si.nMin && si.nMax == editor->vert_si.nMax && si.nPage == editor->vert_si.nPage))
|
|
|
|
{
|
|
|
|
TRACE("min=%d max=%d page=%d\n", si.nMin, si.nMax, si.nPage);
|
|
|
|
editor->vert_si.nMin = si.nMin;
|
|
|
|
editor->vert_si.nMax = si.nMax;
|
|
|
|
editor->vert_si.nPage = si.nPage;
|
|
|
|
if (bScrollBarWillBeVisible)
|
|
|
|
{
|
2008-10-19 10:43:17 +02:00
|
|
|
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
|
2008-07-20 18:29:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (bScrollBarWasVisible && !(si.fMask & SIF_DISABLENOSCROLL))
|
2008-09-18 04:02:08 +02:00
|
|
|
{
|
2008-10-19 10:43:17 +02:00
|
|
|
SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
|
2008-07-20 18:29:19 +02:00
|
|
|
ShowScrollBar(hWnd, SB_VERT, FALSE);
|
2008-09-18 04:02:08 +02:00
|
|
|
ME_ScrollAbs(editor, 0);
|
|
|
|
}
|
2008-07-20 18:29:19 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2005-03-21 11:27:24 +01:00
|
|
|
int ME_GetYScrollPos(ME_TextEditor *editor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2008-09-18 04:02:08 +02:00
|
|
|
return editor->vert_si.nPos;
|
2006-09-08 23:37:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL ME_GetYScrollVisible(ME_TextEditor *editor)
|
|
|
|
{ /* Returns true if the scrollbar is visible */
|
2008-07-20 18:29:19 +02:00
|
|
|
return (editor->vert_si.nMax - editor->vert_si.nMin >= max(editor->vert_si.nPage - 1, 0));
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_EnsureVisible(ME_TextEditor *editor, ME_DisplayItem *pRun)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRow = ME_FindItemBack(pRun, diStartRow);
|
|
|
|
ME_DisplayItem *pPara = ME_FindItemBack(pRun, diParagraph);
|
2005-03-19 18:06:17 +01:00
|
|
|
int y, yrel, yheight, yold;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
assert(pRow);
|
|
|
|
assert(pPara);
|
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
y = pPara->member.para.pt.y+pRow->member.row.pt.y;
|
2005-03-05 12:19:14 +01:00
|
|
|
yheight = pRow->member.row.nHeight;
|
2005-03-21 11:27:24 +01:00
|
|
|
yold = ME_GetYScrollPos(editor);
|
2005-03-19 18:06:17 +01:00
|
|
|
yrel = y - yold;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
if (y < yold)
|
|
|
|
ME_ScrollAbs(editor,y);
|
|
|
|
else if (yrel + yheight > editor->sizeWindow.cy)
|
|
|
|
ME_ScrollAbs(editor,y+yheight-editor->sizeWindow.cy);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_InvalidateFromOfs(ME_TextEditor *editor, int nCharOfs)
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
int x, y, height;
|
|
|
|
ME_Cursor tmp;
|
|
|
|
|
|
|
|
ME_RunOfsFromCharOfs(editor, nCharOfs, &tmp.pRun, &tmp.nOffset);
|
|
|
|
ME_GetCursorCoordinates(editor, &tmp, &x, &y, &height);
|
|
|
|
|
|
|
|
rc.left = 0;
|
|
|
|
rc.top = y;
|
|
|
|
rc.bottom = y + height;
|
|
|
|
rc.right = editor->rcFormat.right;
|
|
|
|
InvalidateRect(editor->hWnd, &rc, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_InvalidateSelection(ME_TextEditor *editor)
|
|
|
|
{
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_DisplayItem *para1, *para2;
|
|
|
|
int nStart, nEnd;
|
|
|
|
int len = ME_GetTextLength(editor);
|
|
|
|
|
|
|
|
ME_GetSelection(editor, &nStart, &nEnd);
|
|
|
|
/* if both old and new selection are 0-char (= caret only), then
|
|
|
|
there's no (inverted) area to be repainted, neither old nor new */
|
|
|
|
if (nStart == nEnd && editor->nLastSelStart == editor->nLastSelEnd)
|
|
|
|
return;
|
2006-08-04 23:40:06 +02:00
|
|
|
ME_WrapMarkedParagraphs(editor);
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_GetSelectionParas(editor, ¶1, ¶2);
|
|
|
|
assert(para1->type == diParagraph);
|
|
|
|
assert(para2->type == diParagraph);
|
|
|
|
/* last selection markers aren't always updated, which means
|
|
|
|
they can point past the end of the document */
|
2007-12-08 06:31:10 +01:00
|
|
|
if (editor->nLastSelStart > len || editor->nLastSelEnd > len) {
|
|
|
|
ME_MarkForPainting(editor,
|
|
|
|
ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph),
|
|
|
|
ME_FindItemFwd(editor->pBuffer->pFirst, diTextEnd));
|
|
|
|
} else {
|
|
|
|
/* if the start part of selection is being expanded or contracted... */
|
|
|
|
if (nStart < editor->nLastSelStart) {
|
|
|
|
ME_MarkForPainting(editor, para1, ME_FindItemFwd(editor->pLastSelStartPara, diParagraphOrEnd));
|
|
|
|
} else
|
|
|
|
if (nStart > editor->nLastSelStart) {
|
|
|
|
ME_MarkForPainting(editor, editor->pLastSelStartPara, ME_FindItemFwd(para1, diParagraphOrEnd));
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2007-12-08 06:31:10 +01:00
|
|
|
/* if the end part of selection is being contracted or expanded... */
|
|
|
|
if (nEnd < editor->nLastSelEnd) {
|
|
|
|
ME_MarkForPainting(editor, para2, ME_FindItemFwd(editor->pLastSelEndPara, diParagraphOrEnd));
|
|
|
|
} else
|
|
|
|
if (nEnd > editor->nLastSelEnd) {
|
|
|
|
ME_MarkForPainting(editor, editor->pLastSelEndPara, ME_FindItemFwd(para2, diParagraphOrEnd));
|
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
2006-08-07 17:27:16 +02:00
|
|
|
|
|
|
|
ME_InvalidateMarkedParagraphs(editor);
|
|
|
|
/* remember the last invalidated position */
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_GetSelection(editor, &editor->nLastSelStart, &editor->nLastSelEnd);
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_GetSelectionParas(editor, &editor->pLastSelStartPara, &editor->pLastSelEndPara);
|
|
|
|
assert(editor->pLastSelStartPara->type == diParagraph);
|
|
|
|
assert(editor->pLastSelEndPara->type == diParagraph);
|
2006-01-10 20:23:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ME_QueueInvalidateFromCursor(ME_TextEditor *editor, int nCursor)
|
|
|
|
{
|
|
|
|
editor->nInvalidOfs = ME_GetCursorOfs(editor, nCursor);
|
|
|
|
}
|
|
|
|
|
2005-07-24 18:17:43 +02:00
|
|
|
|
|
|
|
BOOL
|
|
|
|
ME_SetZoom(ME_TextEditor *editor, int numerator, int denominator)
|
|
|
|
{
|
|
|
|
/* TODO: Zoom images and objects */
|
|
|
|
|
|
|
|
if (numerator != 0)
|
|
|
|
{
|
|
|
|
if (denominator == 0)
|
|
|
|
return FALSE;
|
|
|
|
if (1.0 / 64.0 > (float)numerator / (float)denominator
|
|
|
|
|| (float)numerator / (float)denominator > 64.0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->nZoomNumerator = numerator;
|
|
|
|
editor->nZoomDenominator = denominator;
|
|
|
|
|
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
return TRUE;
|
|
|
|
}
|