2005-03-05 11:19:14 +00:00
|
|
|
/*
|
|
|
|
* RichEdit - structures and constant
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
|
|
|
*
|
|
|
|
* 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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-03-05 11:19:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __EDITSTR_H
|
|
|
|
#define __EDITSTR_H
|
|
|
|
|
|
|
|
#ifndef _WIN32_IE
|
|
|
|
#define _WIN32_IE 0x0400
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2006-02-22 18:56:11 +00:00
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winnls.h>
|
|
|
|
#include <winnt.h>
|
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
|
|
|
#include <richedit.h>
|
|
|
|
#include <commctrl.h>
|
2006-02-01 12:05:40 +00:00
|
|
|
#include <ole2.h>
|
|
|
|
#include <richole.h>
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
typedef struct tagME_String
|
|
|
|
{
|
|
|
|
WCHAR *szData;
|
|
|
|
int nLen, nBuffer;
|
|
|
|
} ME_String;
|
|
|
|
|
|
|
|
typedef struct tagME_Style
|
|
|
|
{
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
|
|
|
|
HFONT hFont; /* cached font for the style */
|
|
|
|
TEXTMETRICW tm; /* cached font metrics for the style */
|
|
|
|
int nRefs; /* reference count */
|
|
|
|
int nSequence; /* incremented when cache needs to be rebuilt, ie. every screen redraw */
|
|
|
|
} ME_Style;
|
|
|
|
|
|
|
|
typedef enum {
|
2006-08-07 15:27:16 +00:00
|
|
|
diInvalid,
|
2005-03-05 11:19:14 +00:00
|
|
|
diTextStart, /* start of the text buffer */
|
|
|
|
diParagraph, /* paragraph start */
|
2008-08-07 16:31:41 +00:00
|
|
|
diCell, /* cell start */
|
2005-03-05 11:19:14 +00:00
|
|
|
diRun, /* run (sequence of chars with the same character format) */
|
|
|
|
diStartRow, /* start of the row (line of text on the screen) */
|
|
|
|
diTextEnd, /* end of the text buffer */
|
|
|
|
|
|
|
|
/********************* these below are meant for finding only *********************/
|
2008-08-07 16:31:41 +00:00
|
|
|
diStartRowOrParagraph, /* 7 */
|
2005-03-05 11:19:14 +00:00
|
|
|
diStartRowOrParagraphOrEnd,
|
|
|
|
diRunOrParagraph,
|
|
|
|
diRunOrStartRow,
|
|
|
|
diParagraphOrEnd,
|
2008-08-07 16:31:41 +00:00
|
|
|
diRunOrParagraphOrEnd, /* 12 */
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2008-08-07 16:31:41 +00:00
|
|
|
diUndoInsertRun, /* 13 */
|
|
|
|
diUndoDeleteRun, /* 14 */
|
|
|
|
diUndoJoinParagraphs, /* 15 */
|
|
|
|
diUndoSplitParagraph, /* 16 */
|
|
|
|
diUndoSetParagraphFormat, /* 17 */
|
|
|
|
diUndoSetCharFormat, /* 18 */
|
|
|
|
diUndoEndTransaction, /* 19 - marks the end of a group of changes for undo */
|
|
|
|
diUndoPotentialEndTransaction, /* 20 - allows grouping typed chars for undo */
|
2005-03-05 11:19:14 +00:00
|
|
|
} ME_DIType;
|
|
|
|
|
2008-07-04 20:02:47 +00:00
|
|
|
#define SELECTIONBAR_WIDTH 9
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
/******************************** run flags *************************/
|
|
|
|
#define MERF_STYLEFLAGS 0x0FFF
|
|
|
|
/* run contains non-text content, which has its own rules for wrapping, sizing etc */
|
2008-03-16 20:46:36 +00:00
|
|
|
#define MERF_GRAPHICS 0x001
|
2005-04-16 10:48:35 +00:00
|
|
|
/* run is a tab (or, in future, any kind of content whose size is dependent on run position) */
|
2008-03-16 20:46:36 +00:00
|
|
|
#define MERF_TAB 0x002
|
2008-08-07 16:31:41 +00:00
|
|
|
/* run is a cell boundary */
|
|
|
|
#define MERF_ENDCELL 0x004 /* v4.1 */
|
2006-02-04 16:01:01 +00:00
|
|
|
|
2008-08-07 16:31:41 +00:00
|
|
|
#define MERF_NONTEXT (MERF_GRAPHICS | MERF_TAB | MERF_ENDCELL)
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
/* run is splittable (contains white spaces in the middle or end) */
|
|
|
|
#define MERF_SPLITTABLE 0x001000
|
|
|
|
/* run starts with whitespaces */
|
|
|
|
#define MERF_STARTWHITE 0x002000
|
|
|
|
/* run ends with whitespaces */
|
|
|
|
#define MERF_ENDWHITE 0x004000
|
|
|
|
/* run is completely made of whitespaces */
|
|
|
|
#define MERF_WHITESPACE 0x008000
|
|
|
|
/* run is a last (dummy) run in the paragraph */
|
|
|
|
#define MERF_SKIPPED 0x010000
|
|
|
|
/* flags that are calculated during text wrapping */
|
|
|
|
#define MERF_CALCBYWRAP 0x0F0000
|
|
|
|
/* the "end of paragraph" run, contains 1 character */
|
|
|
|
#define MERF_ENDPARA 0x100000
|
2008-03-16 20:46:36 +00:00
|
|
|
/* forcing the "end of row" run, contains 1 character */
|
|
|
|
#define MERF_ENDROW 0x200000
|
2006-01-31 12:01:26 +00:00
|
|
|
/* run is hidden */
|
2008-03-16 20:46:36 +00:00
|
|
|
#define MERF_HIDDEN 0x400000
|
2008-08-07 16:31:41 +00:00
|
|
|
/* start of a table row has an empty paragraph that should be skipped over. */
|
|
|
|
#define MERF_TABLESTART 0x800000 /* v4.1 */
|
2005-03-05 11:19:14 +00:00
|
|
|
|
2005-04-16 10:48:35 +00:00
|
|
|
/* runs with any of these flags set cannot be joined */
|
2008-03-16 20:46:36 +00:00
|
|
|
#define MERF_NOJOIN (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
|
2005-04-16 10:48:35 +00:00
|
|
|
/* runs that don't contain real text */
|
2008-03-16 20:46:36 +00:00
|
|
|
#define MERF_NOTEXT (MERF_GRAPHICS|MERF_TAB|MERF_ENDPARA|MERF_ENDROW)
|
2005-04-16 10:48:35 +00:00
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
/* those flags are kept when the row is split */
|
|
|
|
#define MERF_SPLITMASK (~(0))
|
|
|
|
|
|
|
|
/******************************** para flags *************************/
|
|
|
|
|
|
|
|
/* this paragraph was already wrapped and hasn't changed, every change resets that flag */
|
2008-08-07 16:31:41 +00:00
|
|
|
#define MEPF_REWRAP 0x01
|
|
|
|
#define MEPF_REPAINT 0x02
|
|
|
|
/* v4.1 */
|
|
|
|
#define MEPF_CELL 0x04 /* The paragraph is nested in a cell */
|
|
|
|
#define MEPF_ROWSTART 0x08 /* Hidden empty paragraph at the start of the row */
|
|
|
|
#define MEPF_ROWEND 0x10 /* Visible empty paragraph at the end of the row */
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
/******************************** structures *************************/
|
|
|
|
|
|
|
|
struct tagME_DisplayItem;
|
|
|
|
|
|
|
|
typedef struct tagME_Run
|
|
|
|
{
|
|
|
|
ME_String *strText;
|
|
|
|
ME_Style *style;
|
|
|
|
int nCharOfs; /* relative to para's offset */
|
|
|
|
int nWidth; /* width of full run, width of leading&trailing ws */
|
|
|
|
int nFlags;
|
|
|
|
int nAscent, nDescent; /* pixels above/below baseline */
|
|
|
|
POINT pt; /* relative to para's position */
|
2008-01-27 18:01:41 +00:00
|
|
|
REOBJECT *ole_obj; /* FIXME: should be a union with strText (at least) */
|
2008-04-26 18:29:53 +00:00
|
|
|
int nCR; int nLF; /* for MERF_ENDPARA: number of \r and \n characters encoded by run */
|
2005-03-05 11:19:14 +00:00
|
|
|
} ME_Run;
|
|
|
|
|
|
|
|
typedef struct tagME_Document {
|
|
|
|
struct tagME_DisplayItem *def_char_style;
|
|
|
|
struct tagME_DisplayItem *def_para_style;
|
|
|
|
int last_wrapped_line;
|
|
|
|
} ME_Document;
|
|
|
|
|
|
|
|
typedef struct tagME_Paragraph
|
|
|
|
{
|
|
|
|
PARAFORMAT2 *pFmt;
|
2008-07-08 17:38:54 +00:00
|
|
|
|
2008-08-07 16:31:41 +00:00
|
|
|
struct tagME_DisplayItem *pCell; /* v4.1 */
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
int nCharOfs;
|
|
|
|
int nFlags;
|
2008-08-07 16:31:41 +00:00
|
|
|
POINT pt;
|
|
|
|
int nHeight;
|
2005-03-09 11:48:59 +00:00
|
|
|
int nLastPaintYPos, nLastPaintHeight;
|
2005-06-30 18:10:22 +00:00
|
|
|
int nRows;
|
2005-03-05 11:19:14 +00:00
|
|
|
struct tagME_DisplayItem *prev_para, *next_para, *document;
|
|
|
|
} ME_Paragraph;
|
|
|
|
|
2008-08-07 16:31:41 +00:00
|
|
|
typedef struct tagME_Cell /* v4.1 */
|
|
|
|
{
|
|
|
|
int nNestingLevel; /* 0 for normal cells, and greater for nested cells */
|
|
|
|
int nRightBoundary;
|
|
|
|
POINT pt;
|
|
|
|
int nHeight, nWidth;
|
|
|
|
struct tagME_DisplayItem *prev_cell, *next_cell, *parent_cell;
|
|
|
|
} ME_Cell;
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
typedef struct tagME_Row
|
|
|
|
{
|
|
|
|
int nHeight;
|
|
|
|
int nBaseline;
|
|
|
|
int nWidth;
|
|
|
|
int nLMargin;
|
|
|
|
int nRMargin;
|
2008-08-07 16:31:41 +00:00
|
|
|
POINT pt;
|
2005-03-05 11:19:14 +00:00
|
|
|
} ME_Row;
|
|
|
|
|
2005-09-29 10:30:50 +00:00
|
|
|
/* the display item list layout is like this:
|
|
|
|
* - the document consists of paragraphs
|
|
|
|
* - each paragraph contains at least one run, the last run in the paragraph
|
|
|
|
* is an end-of-paragraph run
|
|
|
|
* - each formatted paragraph contains at least one row, which corresponds
|
|
|
|
* to a screen line (that's why there are no rows in an unformatted
|
|
|
|
* paragraph
|
|
|
|
* - the paragraphs contain "shortcut" pointers to the previous and the next
|
|
|
|
* paragraph, that makes iteration over paragraphs faster
|
|
|
|
* - the list starts with diTextStart and ends with diTextEnd
|
|
|
|
*/
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
typedef struct tagME_DisplayItem
|
|
|
|
{
|
|
|
|
ME_DIType type;
|
|
|
|
struct tagME_DisplayItem *prev, *next;
|
|
|
|
union {
|
|
|
|
ME_Run run;
|
|
|
|
ME_Row row;
|
2008-08-07 16:31:41 +00:00
|
|
|
ME_Cell cell;
|
2005-03-05 11:19:14 +00:00
|
|
|
ME_Paragraph para;
|
|
|
|
ME_Document doc; /* not used */
|
|
|
|
ME_Style *ustyle; /* used by diUndoSetCharFormat */
|
|
|
|
} member;
|
|
|
|
} ME_DisplayItem;
|
|
|
|
|
|
|
|
typedef struct tagME_UndoItem
|
|
|
|
{
|
|
|
|
ME_DisplayItem di;
|
|
|
|
int nStart, nLen;
|
2008-04-26 18:29:53 +00:00
|
|
|
int nCR, nLF; /* used by diUndoSplitParagraph */
|
2005-03-05 11:19:14 +00:00
|
|
|
} ME_UndoItem;
|
|
|
|
|
|
|
|
typedef struct tagME_TextBuffer
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pFirst, *pLast;
|
|
|
|
ME_Style *pCharStyle;
|
|
|
|
ME_Style *pDefaultStyle;
|
|
|
|
} ME_TextBuffer;
|
|
|
|
|
|
|
|
typedef struct tagME_Cursor
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun;
|
|
|
|
int nOffset;
|
|
|
|
} ME_Cursor;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
umAddToUndo,
|
|
|
|
umAddToRedo,
|
|
|
|
umIgnore,
|
|
|
|
umAddBackToUndo
|
|
|
|
} ME_UndoMode;
|
|
|
|
|
2008-07-07 15:03:53 +00:00
|
|
|
typedef enum {
|
|
|
|
stPosition = 0,
|
|
|
|
stWord,
|
2008-07-07 15:03:59 +00:00
|
|
|
stLine,
|
2008-07-07 15:04:02 +00:00
|
|
|
stParagraph,
|
|
|
|
stDocument
|
2008-07-07 15:03:53 +00:00
|
|
|
} ME_SelectionType;
|
|
|
|
|
2005-03-14 21:41:16 +00:00
|
|
|
typedef struct tagME_FontTableItem {
|
|
|
|
BYTE bCharSet;
|
|
|
|
WCHAR *szFaceName;
|
|
|
|
} ME_FontTableItem;
|
|
|
|
|
2005-04-13 11:11:03 +00:00
|
|
|
|
|
|
|
#define STREAMIN_BUFFER_SIZE 4096 /* M$ compatibility */
|
|
|
|
|
|
|
|
struct tagME_InStream {
|
|
|
|
EDITSTREAM *editstream;
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwUsed;
|
2005-09-12 20:30:37 +00:00
|
|
|
char buffer[STREAMIN_BUFFER_SIZE];
|
2005-04-13 11:11:03 +00:00
|
|
|
};
|
|
|
|
typedef struct tagME_InStream ME_InStream;
|
|
|
|
|
|
|
|
|
2005-03-14 21:41:16 +00:00
|
|
|
#define STREAMOUT_BUFFER_SIZE 4096
|
|
|
|
#define STREAMOUT_FONTTBL_SIZE 8192
|
|
|
|
#define STREAMOUT_COLORTBL_SIZE 1024
|
|
|
|
|
|
|
|
typedef struct tagME_OutStream {
|
|
|
|
EDITSTREAM *stream;
|
|
|
|
char buffer[STREAMOUT_BUFFER_SIZE];
|
|
|
|
UINT pos, written;
|
|
|
|
UINT nCodePage;
|
|
|
|
UINT nFontTblLen;
|
|
|
|
ME_FontTableItem fonttbl[STREAMOUT_FONTTBL_SIZE];
|
|
|
|
UINT nColorTblLen;
|
|
|
|
COLORREF colortbl[STREAMOUT_COLORTBL_SIZE];
|
|
|
|
UINT nDefaultFont;
|
2005-03-22 16:41:36 +00:00
|
|
|
UINT nDefaultCodePage;
|
2008-08-07 16:31:41 +00:00
|
|
|
/* nNestingLevel = 0 means we aren't in a cell, 1 means we are in a cell,
|
|
|
|
* an greater numbers mean we are in a cell nested within a cell. */
|
|
|
|
UINT nNestingLevel;
|
2005-03-14 21:41:16 +00:00
|
|
|
} ME_OutStream;
|
|
|
|
|
2005-03-08 16:26:23 +00:00
|
|
|
typedef struct tagME_FontCacheItem
|
|
|
|
{
|
|
|
|
LOGFONTW lfSpecs;
|
|
|
|
HFONT hFont;
|
|
|
|
int nRefs;
|
|
|
|
int nAge;
|
|
|
|
} ME_FontCacheItem;
|
|
|
|
|
|
|
|
#define HFONT_CACHE_SIZE 10
|
|
|
|
|
2005-03-05 11:19:14 +00:00
|
|
|
typedef struct tagME_TextEditor
|
|
|
|
{
|
|
|
|
HWND hWnd;
|
2005-07-21 10:33:32 +00:00
|
|
|
BOOL bEmulateVersion10;
|
2005-03-05 11:19:14 +00:00
|
|
|
ME_TextBuffer *pBuffer;
|
|
|
|
ME_Cursor *pCursors;
|
|
|
|
int nCursors;
|
|
|
|
SIZE sizeWindow;
|
2005-03-09 18:43:18 +00:00
|
|
|
int nTotalLength, nLastTotalLength;
|
2007-08-15 17:39:43 +00:00
|
|
|
int nHeight;
|
2005-03-05 11:19:14 +00:00
|
|
|
int nUDArrowX;
|
|
|
|
int nSequence;
|
|
|
|
COLORREF rgbBackColor;
|
2005-11-03 11:33:24 +00:00
|
|
|
HBRUSH hbrBackground;
|
2005-03-05 11:19:14 +00:00
|
|
|
BOOL bCaretAtEnd;
|
|
|
|
int nEventMask;
|
|
|
|
int nModifyStep;
|
2006-05-15 18:00:15 +00:00
|
|
|
ME_DisplayItem *pUndoStack, *pRedoStack, *pUndoStackBottom;
|
|
|
|
int nUndoStackSize;
|
|
|
|
int nUndoLimit;
|
2005-03-05 11:19:14 +00:00
|
|
|
ME_UndoMode nUndoMode;
|
|
|
|
int nParagraphs;
|
2005-03-09 11:48:59 +00:00
|
|
|
int nLastSelStart, nLastSelEnd;
|
2006-08-07 15:27:16 +00:00
|
|
|
ME_DisplayItem *pLastSelStartPara, *pLastSelEndPara;
|
2005-03-08 16:26:23 +00:00
|
|
|
ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE];
|
2005-07-24 16:17:43 +00:00
|
|
|
int nZoomNumerator, nZoomDenominator;
|
2005-08-15 09:47:14 +00:00
|
|
|
RECT rcFormat;
|
|
|
|
BOOL bRedraw;
|
2008-03-16 20:48:05 +00:00
|
|
|
BOOL bWordWrap;
|
2006-01-10 19:23:41 +00:00
|
|
|
int nInvalidOfs;
|
2006-08-09 19:33:42 +00:00
|
|
|
int nTextLimit;
|
2006-01-12 10:54:57 +00:00
|
|
|
EDITWORDBREAKPROCW pfnWordBreak;
|
2006-02-01 12:05:40 +00:00
|
|
|
LPRICHEDITOLECALLBACK lpOleCallback;
|
2006-02-19 06:32:24 +00:00
|
|
|
/*TEXTMODE variable; contains only one of each of the following options:
|
|
|
|
*TM_RICHTEXT or TM_PLAINTEXT
|
|
|
|
*TM_SINGLELEVELUNDO or TM_MULTILEVELUNDO
|
|
|
|
*TM_SINGLECODEPAGE or TM_MULTICODEPAGE*/
|
|
|
|
int mode;
|
2006-02-24 21:31:25 +00:00
|
|
|
BOOL bHideSelection;
|
2006-03-01 10:49:42 +00:00
|
|
|
BOOL AutoURLDetect_bEnable;
|
2006-08-04 19:47:44 +00:00
|
|
|
WCHAR cPasswordMask;
|
2007-06-05 12:56:55 +00:00
|
|
|
BOOL bHaveFocus;
|
2007-06-27 12:57:51 +00:00
|
|
|
/*for IME */
|
|
|
|
int imeStartIndex;
|
2008-07-07 15:03:53 +00:00
|
|
|
DWORD selofs; /* The size of the selection bar on the left side of control */
|
|
|
|
ME_SelectionType nSelectionType;
|
2008-04-27 18:08:55 +00:00
|
|
|
|
|
|
|
/* Track previous notified selection */
|
|
|
|
CHARRANGE notified_cr;
|
2008-07-20 16:29:19 +00:00
|
|
|
|
|
|
|
/* Cache previously set vertical scrollbar info */
|
|
|
|
SCROLLINFO vert_si;
|
2005-03-05 11:19:14 +00:00
|
|
|
} ME_TextEditor;
|
|
|
|
|
|
|
|
typedef struct tagME_Context
|
|
|
|
{
|
|
|
|
HDC hDC;
|
|
|
|
POINT pt;
|
|
|
|
POINT ptRowOffset;
|
|
|
|
RECT rcView;
|
|
|
|
HBRUSH hbrMargin;
|
2008-01-01 21:05:33 +00:00
|
|
|
SIZE dpi;
|
2005-03-05 11:19:14 +00:00
|
|
|
|
|
|
|
/* those are valid inside ME_WrapTextParagraph and related */
|
|
|
|
POINT ptFirstRun;
|
|
|
|
ME_TextEditor *editor;
|
|
|
|
int nSequence;
|
|
|
|
} ME_Context;
|
|
|
|
|
|
|
|
typedef struct tagME_WrapContext
|
|
|
|
{
|
|
|
|
ME_Style *style;
|
|
|
|
ME_Context *context;
|
|
|
|
int nLeftMargin, nRightMargin, nFirstMargin;
|
2008-03-16 20:48:05 +00:00
|
|
|
int nAvailWidth;
|
2005-03-05 11:19:14 +00:00
|
|
|
int nRow;
|
|
|
|
POINT pt;
|
|
|
|
BOOL bOverflown;
|
|
|
|
ME_DisplayItem *pRowStart;
|
|
|
|
|
|
|
|
ME_DisplayItem *pLastSplittableRun;
|
|
|
|
POINT ptLastSplittableRun;
|
|
|
|
} ME_WrapContext;
|
|
|
|
|
|
|
|
#endif
|