2005-03-05 12:19:14 +01:00
|
|
|
/*
|
|
|
|
* RichEdit - functions dealing with editor object
|
|
|
|
*
|
|
|
|
* Copyright 2004 by Krzysztof Foltman
|
2005-12-05 12:48:45 +01:00
|
|
|
* Copyright 2005 by Cihan Altinay
|
2006-01-13 13:54:11 +01:00
|
|
|
* Copyright 2005 by Phil Krylov
|
2008-01-27 19:02:14 +01:00
|
|
|
* Copyright 2008 Eric Pouech
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
API implementation status:
|
|
|
|
|
|
|
|
Messages (ANSI versions not done yet)
|
2006-03-01 11:49:42 +01:00
|
|
|
+ EM_AUTOURLDETECT 2.0
|
2005-04-11 14:50:48 +02:00
|
|
|
+ EM_CANPASTE
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_CANREDO 2.0
|
|
|
|
+ EM_CANUNDO
|
2005-07-26 12:33:00 +02:00
|
|
|
+ EM_CHARFROMPOS
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_DISPLAYBAND
|
|
|
|
+ EM_EMPTYUNDOBUFFER
|
|
|
|
+ EM_EXGETSEL
|
2006-08-09 21:33:42 +02:00
|
|
|
+ EM_EXLIMITTEXT
|
2005-07-06 12:32:59 +02:00
|
|
|
+ EM_EXLINEFROMCHAR
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_EXSETSEL
|
2005-07-06 12:32:59 +02:00
|
|
|
+ EM_FINDTEXT (only FR_DOWN flag implemented)
|
|
|
|
+ EM_FINDTEXTEX (only FR_DOWN flag implemented)
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_FINDWORDBREAK
|
|
|
|
- EM_FMTLINES
|
|
|
|
- EM_FORMATRANGE
|
2006-03-01 11:49:42 +01:00
|
|
|
+ EM_GETAUTOURLDETECT 2.0
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_GETBIDIOPTIONS 3.0
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETCHARFORMAT (partly done)
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_GETEDITSTYLE
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_GETEVENTMASK
|
2005-10-03 13:03:48 +02:00
|
|
|
+ EM_GETFIRSTVISIBLELINE (can be optimized if needed)
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETIMECOLOR 1.0asian
|
|
|
|
- EM_GETIMECOMPMODE 2.0
|
|
|
|
- EM_GETIMEOPTIONS 1.0asian
|
|
|
|
- EM_GETIMESTATUS
|
|
|
|
- EM_GETLANGOPTIONS 2.0
|
2006-08-09 21:33:42 +02:00
|
|
|
+ EM_GETLIMITTEXT
|
2006-07-31 07:59:43 +02:00
|
|
|
+ EM_GETLINE
|
2005-06-30 20:10:22 +02:00
|
|
|
+ EM_GETLINECOUNT returns number of rows, not of paragraphs
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_GETMODIFY
|
2009-01-21 17:08:31 +01:00
|
|
|
+ EM_GETOLEINTERFACE
|
2006-02-21 22:49:19 +01:00
|
|
|
+ EM_GETOPTIONS
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_GETPARAFORMAT
|
2006-08-04 21:47:44 +02:00
|
|
|
+ EM_GETPASSWORDCHAR 2.0
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETPUNCTUATION 1.0asian
|
2005-08-15 11:47:14 +02:00
|
|
|
+ EM_GETRECT
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETREDONAME 2.0
|
|
|
|
+ EM_GETSEL
|
|
|
|
+ EM_GETSELTEXT (ANSI&Unicode)
|
2009-01-14 19:24:02 +01:00
|
|
|
+ EM_GETSCROLLPOS 3.0
|
2005-03-05 12:19:14 +01:00
|
|
|
! - EM_GETTHUMB
|
2007-05-02 10:59:21 +02:00
|
|
|
+ EM_GETTEXTEX 2.0
|
2005-06-28 15:51:32 +02:00
|
|
|
+ EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
|
2009-02-02 07:32:29 +01:00
|
|
|
+ EM_GETTEXTMODE 2.0
|
2005-03-05 12:19:14 +01:00
|
|
|
? + EM_GETTEXTRANGE (ANSI&Unicode)
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_GETTYPOGRAPHYOPTIONS 3.0
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETUNDONAME
|
2006-01-12 11:54:57 +01:00
|
|
|
+ EM_GETWORDBREAKPROC
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETWORDBREAKPROCEX
|
|
|
|
- EM_GETWORDWRAPMODE 1.0asian
|
2005-07-24 18:17:43 +02:00
|
|
|
+ EM_GETZOOM 3.0
|
2006-02-24 22:31:25 +01:00
|
|
|
+ EM_HIDESELECTION
|
2007-01-23 20:39:38 +01:00
|
|
|
+ EM_LIMITTEXT (Also called EM_SETLIMITTEXT)
|
2005-07-06 13:12:10 +02:00
|
|
|
+ EM_LINEFROMCHAR
|
2005-07-06 12:32:59 +02:00
|
|
|
+ EM_LINEINDEX
|
2005-07-21 13:01:47 +02:00
|
|
|
+ EM_LINELENGTH
|
2005-05-23 11:54:32 +02:00
|
|
|
+ EM_LINESCROLL
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_PASTESPECIAL
|
2005-10-03 13:03:48 +02:00
|
|
|
+ EM_POSFROMCHAR
|
2005-04-11 14:50:48 +02:00
|
|
|
+ EM_REDO 2.0
|
2005-11-03 10:52:29 +01:00
|
|
|
+ EM_REQUESTRESIZE
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_REPLACESEL (proper style?) ANSI&Unicode
|
2006-08-08 22:08:43 +02:00
|
|
|
+ EM_SCROLL
|
2006-02-16 19:33:19 +01:00
|
|
|
+ EM_SCROLLCARET
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SELECTIONTYPE
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETBIDIOPTIONS 3.0
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_SETBKGNDCOLOR
|
2006-07-14 19:43:00 +02:00
|
|
|
+ EM_SETCHARFORMAT (partly done, no ANSI)
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETEDITSTYLE
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_SETEVENTMASK (few notifications supported)
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETFONTSIZE
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETIMECOLOR 1.0asian
|
|
|
|
- EM_SETIMEOPTIONS 1.0asian
|
2008-11-16 03:01:48 +01:00
|
|
|
- EM_SETIMESTATUS
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETLANGOPTIONS 2.0
|
|
|
|
- EM_SETLIMITTEXT
|
2008-10-10 22:36:54 +02:00
|
|
|
- EM_SETMARGINS
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_SETMODIFY (not sure if implementation is correct)
|
|
|
|
- EM_SETOLECALLBACK
|
2006-02-21 22:49:19 +01:00
|
|
|
+ EM_SETOPTIONS (partially implemented)
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETPALETTE 2.0
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_SETPARAFORMAT
|
2006-08-04 21:47:44 +02:00
|
|
|
+ EM_SETPASSWORDCHAR 2.0
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETPUNCTUATION 1.0asian
|
|
|
|
+ EM_SETREADONLY no beep on modification attempt
|
2005-08-15 11:47:14 +02:00
|
|
|
+ EM_SETRECT
|
|
|
|
+ EM_SETRECTNP (EM_SETRECT without repainting)
|
2005-03-05 12:19:14 +01:00
|
|
|
+ EM_SETSEL
|
2006-08-08 22:08:43 +02:00
|
|
|
+ EM_SETSCROLLPOS 3.0
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETTABSTOPS 3.0
|
2008-03-16 21:48:05 +01:00
|
|
|
- EM_SETTARGETDEVICE (partial)
|
2008-04-21 17:05:31 +02:00
|
|
|
+ EM_SETTEXTEX 3.0 (proper style?)
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETTEXTMODE 2.0
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_SETTYPOGRAPHYOPTIONS 3.0
|
2006-05-15 20:00:15 +02:00
|
|
|
+ EM_SETUNDOLIMIT 2.0
|
2006-01-12 11:54:57 +01:00
|
|
|
+ EM_SETWORDBREAKPROC (used only for word movement at the moment)
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETWORDBREAKPROCEX
|
|
|
|
- EM_SETWORDWRAPMODE 1.0asian
|
2005-07-24 18:17:43 +02:00
|
|
|
+ EM_SETZOOM 3.0
|
2006-08-08 22:08:43 +02:00
|
|
|
+ EM_SHOWSCROLLBAR 2.0
|
2008-06-25 16:29:19 +02:00
|
|
|
+ EM_STOPGROUPTYPING 2.0
|
2005-06-28 21:12:32 +02:00
|
|
|
+ EM_STREAMIN
|
2005-04-11 14:50:48 +02:00
|
|
|
+ EM_STREAMOUT
|
|
|
|
+ EM_UNDO
|
2005-03-05 12:19:14 +01:00
|
|
|
+ WM_CHAR
|
|
|
|
+ WM_CLEAR
|
2005-03-15 16:40:52 +01:00
|
|
|
+ WM_COPY
|
|
|
|
+ WM_CUT
|
2005-03-05 12:19:14 +01:00
|
|
|
+ WM_GETDLGCODE (the current implementation is incomplete)
|
|
|
|
+ WM_GETTEXT (ANSI&Unicode)
|
|
|
|
+ WM_GETTEXTLENGTH (ANSI version sucks)
|
2009-01-14 19:24:02 +01:00
|
|
|
+ WM_HSCROLL
|
2005-03-15 16:40:52 +01:00
|
|
|
+ WM_PASTE
|
2006-07-14 19:43:00 +02:00
|
|
|
+ WM_SETFONT
|
2005-03-05 12:19:14 +01:00
|
|
|
+ WM_SETTEXT (resets undo stack !) (proper style?) ANSI&Unicode
|
2009-09-24 15:02:51 +02:00
|
|
|
+ WM_STYLECHANGING (seems to do nothing)
|
|
|
|
+ WM_STYLECHANGED (seems to do nothing)
|
2008-07-23 13:55:46 +02:00
|
|
|
+ WM_UNICHAR
|
2009-01-14 19:24:02 +01:00
|
|
|
+ WM_VSCROLL
|
2008-07-23 13:55:46 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
Notifications
|
2008-07-23 13:55:46 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
* EN_CHANGE (sent from the wrong place)
|
|
|
|
- EN_CORRECTTEXT
|
|
|
|
- EN_DROPFILES
|
|
|
|
- EN_ERRSPACE
|
|
|
|
- EN_HSCROLL
|
|
|
|
- EN_IMECHANGE
|
|
|
|
+ EN_KILLFOCUS
|
|
|
|
- EN_LINK
|
|
|
|
- EN_MAXTEXT
|
|
|
|
- EN_MSGFILTER
|
|
|
|
- EN_OLEOPFAILED
|
|
|
|
- EN_PROTECTED
|
2005-11-03 10:52:29 +01:00
|
|
|
+ EN_REQUESTRESIZE
|
2005-03-05 12:19:14 +01:00
|
|
|
- EN_SAVECLIPBOARD
|
|
|
|
+ EN_SELCHANGE
|
|
|
|
+ EN_SETFOCUS
|
|
|
|
- EN_STOPNOUNDO
|
|
|
|
* EN_UPDATE (sent from the wrong place)
|
|
|
|
- EN_VSCROLL
|
|
|
|
|
|
|
|
Styles
|
|
|
|
|
|
|
|
- ES_AUTOHSCROLL
|
|
|
|
- ES_AUTOVSCROLL
|
|
|
|
- ES_CENTER
|
2006-08-08 22:08:43 +02:00
|
|
|
+ ES_DISABLENOSCROLL (scrollbar is always visible)
|
2005-03-05 12:19:14 +01:00
|
|
|
- ES_EX_NOCALLOLEINIT
|
|
|
|
- ES_LEFT
|
|
|
|
- ES_MULTILINE (currently single line controls aren't supported)
|
|
|
|
- ES_NOIME
|
|
|
|
- ES_READONLY (I'm not sure if beeping is the proper behaviour)
|
|
|
|
- ES_RIGHT
|
|
|
|
- ES_SAVESEL
|
|
|
|
- ES_SELFIME
|
|
|
|
- ES_SUNKEN
|
|
|
|
- ES_VERTICAL
|
|
|
|
- ES_WANTRETURN (don't know how to do WM_GETDLGCODE part)
|
|
|
|
- WS_SETFONT
|
2009-01-14 19:24:02 +01:00
|
|
|
+ WS_HSCROLL
|
2006-08-08 22:08:43 +02:00
|
|
|
+ WS_VSCROLL
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RICHED20 TODO (incomplete):
|
|
|
|
*
|
2005-04-11 14:50:48 +02:00
|
|
|
* - messages/styles/notifications listed above
|
2005-03-05 12:19:14 +01:00
|
|
|
* - add remaining CHARFORMAT/PARAFORMAT fields
|
|
|
|
* - right/center align should strip spaces from the beginning
|
2005-04-11 14:50:48 +02:00
|
|
|
* - pictures/OLE objects (not just smiling faces that lack API support ;-) )
|
|
|
|
* - COM interface (looks like a major pain in the TODO list)
|
2005-03-05 12:19:14 +01:00
|
|
|
* - calculate heights of pictures (half-done)
|
|
|
|
* - hysteresis during wrapping (related to scrollbars appearing/disappearing)
|
|
|
|
* - find/replace
|
|
|
|
* - how to implement EM_FORMATRANGE and EM_DISPLAYBAND ? (Mission Impossible)
|
2005-04-11 14:50:48 +02:00
|
|
|
* - italic caret with italic fonts
|
2005-03-05 12:19:14 +01:00
|
|
|
* - IME
|
|
|
|
* - most notifications aren't sent at all (the most important ones are)
|
|
|
|
* - when should EN_SELCHANGE be sent after text change ? (before/after EN_UPDATE?)
|
|
|
|
* - WM_SETTEXT may use wrong style (but I'm 80% sure it's OK)
|
|
|
|
* - EM_GETCHARFORMAT with SCF_SELECTION may not behave 100% like in original (but very close)
|
2005-07-22 20:26:46 +02:00
|
|
|
* - full justification
|
|
|
|
* - hyphenation
|
|
|
|
* - tables
|
2005-12-05 12:48:45 +01:00
|
|
|
* - ListBox & ComboBox not implemented
|
2005-03-05 12:19:14 +01:00
|
|
|
*
|
|
|
|
* Bugs that are probably fixed, but not so easy to verify:
|
|
|
|
* - EN_UPDATE/EN_CHANGE are handled very incorrectly (should be OK now)
|
|
|
|
* - undo for ME_JoinParagraphs doesn't store paragraph format ? (it does)
|
|
|
|
* - check/fix artificial EOL logic (bCursorAtEnd, hardly logical)
|
|
|
|
* - caret shouldn't be displayed when selection isn't empty
|
|
|
|
* - check refcounting in style management functions (looks perfect now, but no bugs is suspicious)
|
|
|
|
* - undo for setting default format (done, might be buggy)
|
|
|
|
* - styles might be not released properly (looks like they work like charm, but who knows?
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "editor.h"
|
2005-07-06 12:32:59 +02:00
|
|
|
#include "commdlg.h"
|
2005-03-21 11:52:26 +01:00
|
|
|
#include "winreg.h"
|
2005-03-05 12:19:14 +01:00
|
|
|
#define NO_SHLWAPI_STREAM
|
2005-03-21 11:52:26 +01:00
|
|
|
#include "shlwapi.h"
|
2005-03-07 18:15:33 +01:00
|
|
|
#include "rtf.h"
|
2007-06-27 14:57:51 +02:00
|
|
|
#include "imm.h"
|
2007-12-14 21:29:37 +01:00
|
|
|
#include "res.h"
|
2006-05-15 20:00:15 +02:00
|
|
|
|
|
|
|
#define STACK_SIZE_DEFAULT 100
|
|
|
|
#define STACK_SIZE_MAX 1000
|
2006-08-09 21:33:42 +02:00
|
|
|
|
|
|
|
#define TEXT_LIMIT_DEFAULT 32767
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(richedit);
|
|
|
|
|
2007-03-21 11:26:19 +01:00
|
|
|
static BOOL ME_RegisterEditorClass(HINSTANCE);
|
2009-08-13 14:44:02 +02:00
|
|
|
static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, ME_Cursor *start, int nChars);
|
2007-03-21 11:26:19 +01:00
|
|
|
|
|
|
|
static const WCHAR REListBox20W[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
|
|
|
|
static const WCHAR REComboBox20W[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
|
2007-12-14 21:29:37 +01:00
|
|
|
static HCURSOR hLeft;
|
2007-03-21 11:26:19 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
int me_debug = 0;
|
|
|
|
HANDLE me_heap = NULL;
|
|
|
|
|
2005-12-05 12:48:45 +01:00
|
|
|
static BOOL ME_ListBoxRegistered = FALSE;
|
|
|
|
static BOOL ME_ComboBoxRegistered = FALSE;
|
|
|
|
|
2007-03-21 11:26:19 +01:00
|
|
|
static inline int is_version_nt(void)
|
|
|
|
{
|
|
|
|
return !(GetVersion() & 0x80000000);
|
|
|
|
}
|
|
|
|
|
2005-07-05 14:49:14 +02:00
|
|
|
static ME_TextBuffer *ME_MakeText(void) {
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
ME_TextBuffer *buf = ALLOC_OBJ(ME_TextBuffer);
|
|
|
|
|
|
|
|
ME_DisplayItem *p1 = ME_MakeDI(diTextStart);
|
|
|
|
ME_DisplayItem *p2 = ME_MakeDI(diTextEnd);
|
|
|
|
|
|
|
|
p1->prev = NULL;
|
|
|
|
p1->next = p2;
|
|
|
|
p2->prev = p1;
|
|
|
|
p2->next = NULL;
|
|
|
|
p1->member.para.next_para = p2;
|
|
|
|
p2->member.para.prev_para = p1;
|
|
|
|
p2->member.para.nCharOfs = 0;
|
|
|
|
|
|
|
|
buf->pFirst = p1;
|
|
|
|
buf->pLast = p2;
|
|
|
|
buf->pCharStyle = NULL;
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
|
2005-03-08 20:03:01 +01:00
|
|
|
{
|
2005-04-13 13:11:03 +02:00
|
|
|
WCHAR *pText;
|
2011-09-26 04:17:19 +02:00
|
|
|
LRESULT total_bytes_read = 0;
|
2012-08-16 21:05:56 +02:00
|
|
|
BOOL is_read = FALSE;
|
|
|
|
static const char bom_utf8[] = {0xEF, 0xBB, 0xBF};
|
2011-09-26 04:17:19 +02:00
|
|
|
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("%08x %p\n", dwFormat, stream);
|
2011-09-26 04:17:19 +02:00
|
|
|
|
2005-03-08 20:03:01 +01:00
|
|
|
do {
|
2010-05-17 01:11:23 +02:00
|
|
|
LONG nWideChars = 0;
|
2012-08-18 11:56:12 +02:00
|
|
|
WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
|
2005-04-13 13:11:03 +02:00
|
|
|
|
|
|
|
if (!stream->dwSize)
|
|
|
|
{
|
|
|
|
ME_StreamInFill(stream);
|
|
|
|
if (stream->editstream->dwError)
|
|
|
|
break;
|
|
|
|
if (!stream->dwSize)
|
|
|
|
break;
|
2011-09-26 04:17:19 +02:00
|
|
|
total_bytes_read += stream->dwSize;
|
2005-04-13 13:11:03 +02:00
|
|
|
}
|
2011-09-26 04:17:19 +02:00
|
|
|
|
2005-03-08 20:03:01 +01:00
|
|
|
if (!(dwFormat & SF_UNICODE))
|
|
|
|
{
|
2012-08-16 21:05:56 +02:00
|
|
|
char * buf = stream->buffer;
|
|
|
|
DWORD size = stream->dwSize;
|
|
|
|
DWORD cp = CP_ACP;
|
|
|
|
|
|
|
|
if (!is_read)
|
|
|
|
{
|
|
|
|
is_read = TRUE;
|
|
|
|
if (stream->dwSize >= 3 && !memcmp(stream->buffer, bom_utf8, 3))
|
|
|
|
{
|
|
|
|
cp = CP_UTF8;
|
|
|
|
buf += 3;
|
|
|
|
size -= 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nWideChars = MultiByteToWideChar(cp, 0, buf, size, wszText, STREAMIN_BUFFER_SIZE);
|
2005-04-13 13:11:03 +02:00
|
|
|
pText = wszText;
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
|
|
|
else
|
2005-04-13 13:11:03 +02:00
|
|
|
{
|
|
|
|
nWideChars = stream->dwSize >> 1;
|
|
|
|
pText = (WCHAR *)stream->buffer;
|
|
|
|
}
|
2011-09-26 04:17:19 +02:00
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style);
|
2005-10-03 12:14:28 +02:00
|
|
|
if (stream->dwSize == 0)
|
2005-03-08 20:03:01 +01:00
|
|
|
break;
|
2005-04-20 16:25:03 +02:00
|
|
|
stream->dwSize = 0;
|
2005-03-08 20:03:01 +01:00
|
|
|
} while(1);
|
2011-09-26 04:17:19 +02:00
|
|
|
return total_bytes_read;
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2008-08-13 05:15:40 +02:00
|
|
|
static void ME_ApplyBorderProperties(RTF_Info *info,
|
|
|
|
ME_BorderRect *borderRect,
|
|
|
|
RTFBorder *borderDef)
|
|
|
|
{
|
|
|
|
int i, colorNum;
|
|
|
|
ME_Border *pBorders[] = {&borderRect->top,
|
|
|
|
&borderRect->left,
|
|
|
|
&borderRect->bottom,
|
|
|
|
&borderRect->right};
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
RTFColor *colorDef = info->colorList;
|
|
|
|
pBorders[i]->width = borderDef[i].width;
|
|
|
|
colorNum = borderDef[i].color;
|
|
|
|
while (colorDef && colorDef->rtfCNum != colorNum)
|
|
|
|
colorDef = colorDef->rtfNextColor;
|
|
|
|
if (colorDef)
|
|
|
|
pBorders[i]->colorRef = RGB(
|
|
|
|
colorDef->rtfCRed >= 0 ? colorDef->rtfCRed : 0,
|
|
|
|
colorDef->rtfCGreen >= 0 ? colorDef->rtfCGreen : 0,
|
|
|
|
colorDef->rtfCBlue >= 0 ? colorDef->rtfCBlue : 0);
|
|
|
|
else
|
|
|
|
pBorders[i]->colorRef = RGB(0, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:54:12 +02:00
|
|
|
void ME_RTFCharAttrHook(RTF_Info *info)
|
2005-03-11 11:24:56 +01:00
|
|
|
{
|
2005-03-17 11:23:40 +01:00
|
|
|
CHARFORMAT2W fmt;
|
2005-03-11 11:24:56 +01:00
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = 0;
|
2006-06-12 16:09:50 +02:00
|
|
|
fmt.dwEffects = 0;
|
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
switch(info->rtfMinor)
|
|
|
|
{
|
2005-03-15 16:40:52 +01:00
|
|
|
case rtfPlain:
|
2005-03-16 12:27:43 +01:00
|
|
|
/* FIXME add more flags once they're implemented */
|
2008-01-01 22:03:58 +01:00
|
|
|
fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINETYPE | CFM_STRIKEOUT | CFM_COLOR | CFM_BACKCOLOR | CFM_SIZE | CFM_WEIGHT;
|
2005-03-15 16:40:52 +01:00
|
|
|
fmt.dwEffects = CFE_AUTOCOLOR | CFE_AUTOBACKCOLOR;
|
2005-03-16 12:27:43 +01:00
|
|
|
fmt.yHeight = 12*20; /* 12pt */
|
2008-03-16 21:47:39 +01:00
|
|
|
fmt.wWeight = FW_NORMAL;
|
2008-01-01 22:03:58 +01:00
|
|
|
fmt.bUnderlineType = CFU_UNDERLINENONE;
|
2005-03-15 16:40:52 +01:00
|
|
|
break;
|
2005-03-11 11:24:56 +01:00
|
|
|
case rtfBold:
|
2008-03-16 21:47:32 +01:00
|
|
|
fmt.dwMask = CFM_BOLD | CFM_WEIGHT;
|
|
|
|
fmt.dwEffects = info->rtfParam ? CFE_BOLD : 0;
|
|
|
|
fmt.wWeight = info->rtfParam ? FW_BOLD : FW_NORMAL;
|
2005-03-11 11:24:56 +01:00
|
|
|
break;
|
|
|
|
case rtfItalic:
|
|
|
|
fmt.dwMask = CFM_ITALIC;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
|
|
|
break;
|
|
|
|
case rtfUnderline:
|
2008-01-01 22:03:58 +01:00
|
|
|
fmt.dwMask = CFM_UNDERLINETYPE;
|
|
|
|
fmt.bUnderlineType = info->rtfParam ? CFU_CF1UNDERLINE : CFU_UNDERLINENONE;
|
|
|
|
break;
|
|
|
|
case rtfDotUnderline:
|
|
|
|
fmt.dwMask = CFM_UNDERLINETYPE;
|
|
|
|
fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEDOTTED : CFU_UNDERLINENONE;
|
|
|
|
break;
|
|
|
|
case rtfDbUnderline:
|
|
|
|
fmt.dwMask = CFM_UNDERLINETYPE;
|
|
|
|
fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEDOUBLE : CFU_UNDERLINENONE;
|
|
|
|
break;
|
|
|
|
case rtfWordUnderline:
|
|
|
|
fmt.dwMask = CFM_UNDERLINETYPE;
|
|
|
|
fmt.bUnderlineType = info->rtfParam ? CFU_UNDERLINEWORD : CFU_UNDERLINENONE;
|
2005-06-12 12:43:24 +02:00
|
|
|
break;
|
|
|
|
case rtfNoUnderline:
|
2008-01-01 22:03:58 +01:00
|
|
|
fmt.dwMask = CFM_UNDERLINETYPE;
|
|
|
|
fmt.bUnderlineType = CFU_UNDERLINENONE;
|
2005-03-11 11:24:56 +01:00
|
|
|
break;
|
|
|
|
case rtfStrikeThru:
|
|
|
|
fmt.dwMask = CFM_STRIKEOUT;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
|
|
|
break;
|
2005-06-12 12:43:24 +02:00
|
|
|
case rtfSubScript:
|
|
|
|
case rtfSuperScript:
|
|
|
|
case rtfSubScrShrink:
|
|
|
|
case rtfSuperScrShrink:
|
|
|
|
case rtfNoSuperSub:
|
|
|
|
fmt.dwMask = CFM_SUBSCRIPT|CFM_SUPERSCRIPT;
|
|
|
|
if (info->rtfMinor == rtfSubScrShrink) fmt.dwEffects = CFE_SUBSCRIPT;
|
|
|
|
if (info->rtfMinor == rtfSuperScrShrink) fmt.dwEffects = CFE_SUPERSCRIPT;
|
|
|
|
if (info->rtfMinor == rtfNoSuperSub) fmt.dwEffects = 0;
|
|
|
|
break;
|
2006-01-31 13:01:26 +01:00
|
|
|
case rtfInvisible:
|
|
|
|
fmt.dwMask = CFM_HIDDEN;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
|
|
|
break;
|
2005-03-11 11:24:56 +01:00
|
|
|
case rtfBackColor:
|
|
|
|
fmt.dwMask = CFM_BACKCOLOR;
|
|
|
|
fmt.dwEffects = 0;
|
|
|
|
if (info->rtfParam == 0)
|
|
|
|
fmt.dwEffects = CFE_AUTOBACKCOLOR;
|
|
|
|
else if (info->rtfParam != rtfNoParam)
|
|
|
|
{
|
|
|
|
RTFColor *c = RTFGetColor(info, info->rtfParam);
|
2009-07-17 15:17:20 +02:00
|
|
|
if (c && c->rtfCBlue >= 0)
|
|
|
|
fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
|
|
|
|
else
|
|
|
|
fmt.dwEffects = CFE_AUTOBACKCOLOR;
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case rtfForeColor:
|
|
|
|
fmt.dwMask = CFM_COLOR;
|
|
|
|
fmt.dwEffects = 0;
|
|
|
|
if (info->rtfParam == 0)
|
|
|
|
fmt.dwEffects = CFE_AUTOCOLOR;
|
|
|
|
else if (info->rtfParam != rtfNoParam)
|
|
|
|
{
|
|
|
|
RTFColor *c = RTFGetColor(info, info->rtfParam);
|
2009-07-17 15:17:20 +02:00
|
|
|
if (c && c->rtfCBlue >= 0)
|
2006-10-09 13:11:32 +02:00
|
|
|
fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
|
2009-07-17 15:17:20 +02:00
|
|
|
else {
|
|
|
|
fmt.dwEffects = CFE_AUTOCOLOR;
|
|
|
|
}
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case rtfFontNum:
|
|
|
|
if (info->rtfParam != rtfNoParam)
|
|
|
|
{
|
|
|
|
RTFFont *f = RTFGetFont(info, info->rtfParam);
|
|
|
|
if (f)
|
|
|
|
{
|
2005-03-17 11:23:40 +01:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, f->rtfFName, -1, fmt.szFaceName, sizeof(fmt.szFaceName)/sizeof(WCHAR));
|
|
|
|
fmt.szFaceName[sizeof(fmt.szFaceName)/sizeof(WCHAR)-1] = '\0';
|
2005-03-22 17:41:36 +01:00
|
|
|
fmt.bCharSet = f->rtfFCharSet;
|
|
|
|
fmt.dwMask = CFM_FACE | CFM_CHARSET;
|
2008-03-16 21:47:25 +01:00
|
|
|
fmt.bPitchAndFamily = f->rtfFPitch | (f->rtfFFamily << 4);
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case rtfFontSize:
|
|
|
|
fmt.dwMask = CFM_SIZE;
|
|
|
|
if (info->rtfParam != rtfNoParam)
|
|
|
|
fmt.yHeight = info->rtfParam*10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fmt.dwMask) {
|
2005-03-17 11:23:40 +01:00
|
|
|
ME_Style *style2;
|
2005-03-11 11:24:56 +01:00
|
|
|
RTFFlushOutputBuffer(info);
|
2005-03-17 11:23:40 +01:00
|
|
|
/* FIXME too slow ? how come ? */
|
|
|
|
style2 = ME_ApplyStyle(info->style, &fmt);
|
|
|
|
ME_ReleaseStyle(info->style);
|
|
|
|
info->style = style2;
|
2005-08-22 12:06:08 +02:00
|
|
|
info->styleChanged = TRUE;
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 12:48:35 +02:00
|
|
|
/* FIXME this function doesn't get any information about context of the RTF tag, which is very bad,
|
|
|
|
the same tags mean different things in different contexts */
|
2008-09-11 04:54:12 +02:00
|
|
|
void ME_RTFParAttrHook(RTF_Info *info)
|
2005-03-11 11:24:56 +01:00
|
|
|
{
|
|
|
|
PARAFORMAT2 fmt;
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = 0;
|
|
|
|
|
|
|
|
switch(info->rtfMinor)
|
|
|
|
{
|
2006-02-04 17:01:01 +01:00
|
|
|
case rtfParDef: /* restores default paragraph attributes */
|
2008-08-13 05:15:36 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
info->borderType = RTFBorderParaLeft;
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
info->borderType = RTFBorderParaTop;
|
2008-08-07 18:31:41 +02:00
|
|
|
fmt.dwMask = PFM_ALIGNMENT | PFM_BORDER | PFM_LINESPACING | PFM_TABSTOPS |
|
|
|
|
PFM_OFFSET | PFM_RIGHTINDENT | PFM_SPACEAFTER | PFM_SPACEBEFORE |
|
|
|
|
PFM_STARTINDENT;
|
2008-03-16 21:46:10 +01:00
|
|
|
/* TODO: numbering, shading */
|
2005-03-11 11:24:56 +01:00
|
|
|
fmt.wAlignment = PFA_LEFT;
|
2005-04-16 12:48:35 +02:00
|
|
|
fmt.cTabCount = 0;
|
2008-03-16 21:46:10 +01:00
|
|
|
fmt.dxOffset = fmt.dxStartIndent = fmt.dxRightIndent = 0;
|
|
|
|
fmt.wBorderWidth = fmt.wBorders = 0;
|
2008-03-22 21:36:13 +01:00
|
|
|
fmt.wBorderSpace = 0;
|
2008-03-16 21:46:10 +01:00
|
|
|
fmt.bLineSpacingRule = 0;
|
|
|
|
fmt.dySpaceBefore = fmt.dySpaceAfter = 0;
|
2008-03-22 21:36:13 +01:00
|
|
|
fmt.dyLineSpacing = 0;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
if (info->tableDef && info->tableDef->tableRowStart &&
|
|
|
|
info->tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
ME_Cursor cursor;
|
|
|
|
ME_DisplayItem *para;
|
|
|
|
/* We are just after a table row. */
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
cursor = info->editor->pCursors[0];
|
2009-02-09 18:01:35 +01:00
|
|
|
para = cursor.pPara;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (para == info->tableDef->tableRowStart->member.para.next_para
|
|
|
|
&& !cursor.nOffset && !cursor.pRun->member.run.nCharOfs)
|
|
|
|
{
|
|
|
|
/* Since the table row end, no text has been inserted, and the \intbl
|
|
|
|
* control word has not be used. We can confirm that we are not in a
|
|
|
|
* table anymore.
|
|
|
|
*/
|
|
|
|
info->tableDef->tableRowStart = NULL;
|
2008-08-07 18:31:46 +02:00
|
|
|
info->canInheritInTbl = FALSE;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - v3.0 */
|
|
|
|
fmt.dwMask |= PFM_TABLE;
|
|
|
|
fmt.wEffects &= ~PFE_TABLE;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
2008-08-07 18:31:46 +02:00
|
|
|
case rtfNestLevel:
|
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
|
|
|
while (info->rtfParam > info->nestingLevel) {
|
|
|
|
RTFTable *tableDef = ALLOC_OBJ(RTFTable);
|
|
|
|
ZeroMemory(tableDef, sizeof(RTFTable));
|
|
|
|
tableDef->parent = info->tableDef;
|
|
|
|
info->tableDef = tableDef;
|
|
|
|
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
if (tableDef->tableRowStart &&
|
|
|
|
tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *para = tableDef->tableRowStart;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
para = ME_InsertTableRowStartAtParagraph(info->editor, para);
|
|
|
|
tableDef->tableRowStart = para;
|
|
|
|
} else {
|
|
|
|
ME_Cursor cursor;
|
|
|
|
WCHAR endl = '\r';
|
|
|
|
cursor = info->editor->pCursors[0];
|
|
|
|
if (cursor.nOffset || cursor.pRun->member.run.nCharOfs)
|
|
|
|
ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style);
|
|
|
|
tableDef->tableRowStart = ME_InsertTableRowStartFromCursor(info->editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
info->nestingLevel++;
|
|
|
|
}
|
|
|
|
info->canInheritInTbl = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2006-02-04 17:01:01 +01:00
|
|
|
case rtfInTable:
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
{
|
2008-08-07 18:31:46 +02:00
|
|
|
if (info->nestingLevel < 1)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
RTFTable *tableDef;
|
|
|
|
if (!info->tableDef)
|
|
|
|
{
|
|
|
|
info->tableDef = ALLOC_OBJ(RTFTable);
|
|
|
|
ZeroMemory(info->tableDef, sizeof(RTFTable));
|
|
|
|
}
|
|
|
|
tableDef = info->tableDef;
|
|
|
|
RTFFlushOutputBuffer(info);
|
2008-08-07 18:31:46 +02:00
|
|
|
if (tableDef->tableRowStart &&
|
|
|
|
tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2008-08-07 18:31:46 +02:00
|
|
|
ME_DisplayItem *para = tableDef->tableRowStart;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
para = ME_InsertTableRowStartAtParagraph(info->editor, para);
|
|
|
|
tableDef->tableRowStart = para;
|
|
|
|
} else {
|
|
|
|
ME_Cursor cursor;
|
2008-08-07 18:31:41 +02:00
|
|
|
WCHAR endl = '\r';
|
|
|
|
cursor = info->editor->pCursors[0];
|
|
|
|
if (cursor.nOffset || cursor.pRun->member.run.nCharOfs)
|
|
|
|
ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style);
|
2008-08-07 18:31:46 +02:00
|
|
|
tableDef->tableRowStart = ME_InsertTableRowStartFromCursor(info->editor);
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2008-08-07 18:31:46 +02:00
|
|
|
info->nestingLevel = 1;
|
|
|
|
info->canInheritInTbl = TRUE;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else { /* v1.0 - v3.0 */
|
|
|
|
fmt.dwMask |= PFM_TABLE;
|
|
|
|
fmt.wEffects |= PFE_TABLE;
|
|
|
|
}
|
2008-07-08 19:38:54 +02:00
|
|
|
break;
|
2006-02-04 17:01:01 +01:00
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
case rtfFirstIndent:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_STARTINDENT | PFM_OFFSET;
|
2008-08-07 16:17:12 +02:00
|
|
|
fmt.dxStartIndent += fmt.dxOffset + info->rtfParam;
|
2006-01-09 17:12:51 +01:00
|
|
|
fmt.dxOffset = -info->rtfParam;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
|
|
|
case rtfLeftIndent:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_STARTINDENT;
|
2008-08-07 16:17:12 +02:00
|
|
|
fmt.dxStartIndent = info->rtfParam - fmt.dxOffset;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
|
|
|
case rtfRightIndent:
|
|
|
|
fmt.dwMask = PFM_RIGHTINDENT;
|
|
|
|
fmt.dxRightIndent = info->rtfParam;
|
2005-03-11 11:24:56 +01:00
|
|
|
break;
|
|
|
|
case rtfQuadLeft:
|
|
|
|
case rtfQuadJust:
|
|
|
|
fmt.dwMask = PFM_ALIGNMENT;
|
|
|
|
fmt.wAlignment = PFA_LEFT;
|
|
|
|
break;
|
|
|
|
case rtfQuadRight:
|
|
|
|
fmt.dwMask = PFM_ALIGNMENT;
|
|
|
|
fmt.wAlignment = PFA_RIGHT;
|
|
|
|
break;
|
|
|
|
case rtfQuadCenter:
|
|
|
|
fmt.dwMask = PFM_ALIGNMENT;
|
|
|
|
fmt.wAlignment = PFA_CENTER;
|
|
|
|
break;
|
2005-04-16 12:48:35 +02:00
|
|
|
case rtfTabPos:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
if (!(fmt.dwMask & PFM_TABSTOPS))
|
|
|
|
{
|
|
|
|
fmt.cTabCount = 0;
|
|
|
|
}
|
2008-08-05 01:18:54 +02:00
|
|
|
if (fmt.cTabCount < MAX_TAB_STOPS && info->rtfParam < 0x1000000)
|
2005-04-16 12:48:35 +02:00
|
|
|
fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_TABSTOPS;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
2008-01-27 19:02:14 +01:00
|
|
|
case rtfKeep:
|
|
|
|
fmt.dwMask = PFM_KEEP;
|
|
|
|
fmt.wEffects = PFE_KEEP;
|
|
|
|
break;
|
|
|
|
case rtfNoWidowControl:
|
|
|
|
fmt.dwMask = PFM_NOWIDOWCONTROL;
|
|
|
|
fmt.wEffects = PFE_NOWIDOWCONTROL;
|
|
|
|
break;
|
|
|
|
case rtfKeepNext:
|
|
|
|
fmt.dwMask = PFM_KEEPNEXT;
|
|
|
|
fmt.wEffects = PFE_KEEPNEXT;
|
|
|
|
break;
|
|
|
|
case rtfSpaceAfter:
|
|
|
|
fmt.dwMask = PFM_SPACEAFTER;
|
|
|
|
fmt.dySpaceAfter = info->rtfParam;
|
|
|
|
break;
|
|
|
|
case rtfSpaceBefore:
|
|
|
|
fmt.dwMask = PFM_SPACEBEFORE;
|
|
|
|
fmt.dySpaceBefore = info->rtfParam;
|
|
|
|
break;
|
|
|
|
case rtfSpaceBetween:
|
|
|
|
fmt.dwMask = PFM_LINESPACING;
|
|
|
|
if ((int)info->rtfParam > 0)
|
|
|
|
{
|
|
|
|
fmt.dyLineSpacing = info->rtfParam;
|
|
|
|
fmt.bLineSpacingRule = 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fmt.dyLineSpacing = info->rtfParam;
|
|
|
|
fmt.bLineSpacingRule = 4;
|
|
|
|
}
|
2011-02-23 10:32:03 +01:00
|
|
|
break;
|
2008-01-27 19:02:14 +01:00
|
|
|
case rtfSpaceMultiply:
|
|
|
|
fmt.dwMask = PFM_LINESPACING;
|
|
|
|
fmt.dyLineSpacing = info->rtfParam * 20;
|
|
|
|
fmt.bLineSpacingRule = 5;
|
|
|
|
break;
|
|
|
|
case rtfParBullet:
|
|
|
|
fmt.dwMask = PFM_NUMBERING;
|
|
|
|
fmt.wNumbering = PFN_BULLET;
|
|
|
|
break;
|
|
|
|
case rtfParSimple:
|
|
|
|
fmt.dwMask = PFM_NUMBERING;
|
|
|
|
fmt.wNumbering = 2; /* FIXME: MSDN says it's not used ?? */
|
|
|
|
break;
|
|
|
|
case rtfParNumDecimal:
|
|
|
|
fmt.dwMask = PFM_NUMBERING;
|
|
|
|
fmt.wNumbering = 2; /* FIXME: MSDN says it's not used ?? */
|
|
|
|
break;
|
|
|
|
case rtfParNumIndent:
|
|
|
|
fmt.dwMask = PFM_NUMBERINGTAB;
|
|
|
|
fmt.wNumberingTab = info->rtfParam;
|
|
|
|
break;
|
|
|
|
case rtfParNumStartAt:
|
|
|
|
fmt.dwMask = PFM_NUMBERINGSTART;
|
|
|
|
fmt.wNumberingStart = info->rtfParam;
|
|
|
|
break;
|
|
|
|
case rtfBorderLeft:
|
2008-08-13 05:15:36 +02:00
|
|
|
info->borderType = RTFBorderParaLeft;
|
2008-01-27 19:02:14 +01:00
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
if (!(fmt.dwMask & PFM_BORDER))
|
|
|
|
{
|
|
|
|
fmt.wBorderSpace = 0;
|
|
|
|
fmt.wBorderWidth = 1;
|
|
|
|
fmt.wBorders = 0;
|
|
|
|
}
|
|
|
|
fmt.wBorders |= 1;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderRight:
|
2008-08-13 05:15:36 +02:00
|
|
|
info->borderType = RTFBorderParaRight;
|
2008-01-27 19:02:14 +01:00
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
if (!(fmt.dwMask & PFM_BORDER))
|
|
|
|
{
|
|
|
|
fmt.wBorderSpace = 0;
|
|
|
|
fmt.wBorderWidth = 1;
|
|
|
|
fmt.wBorders = 0;
|
|
|
|
}
|
|
|
|
fmt.wBorders |= 2;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderTop:
|
2008-08-13 05:15:36 +02:00
|
|
|
info->borderType = RTFBorderParaTop;
|
2008-01-27 19:02:14 +01:00
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
if (!(fmt.dwMask & PFM_BORDER))
|
|
|
|
{
|
|
|
|
fmt.wBorderSpace = 0;
|
|
|
|
fmt.wBorderWidth = 1;
|
|
|
|
fmt.wBorders = 0;
|
|
|
|
}
|
|
|
|
fmt.wBorders |= 4;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderBottom:
|
2008-08-13 05:15:36 +02:00
|
|
|
info->borderType = RTFBorderParaBottom;
|
2008-01-27 19:02:14 +01:00
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
if (!(fmt.dwMask & PFM_BORDER))
|
|
|
|
{
|
|
|
|
fmt.wBorderSpace = 0;
|
|
|
|
fmt.wBorderWidth = 1;
|
|
|
|
fmt.wBorders = 0;
|
|
|
|
}
|
|
|
|
fmt.wBorders |= 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderSingle:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-05-05 21:11:50 +02:00
|
|
|
fmt.wBorders &= ~0x700;
|
2008-01-27 19:02:14 +01:00
|
|
|
fmt.wBorders |= 1 << 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderThick:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-05-05 21:11:50 +02:00
|
|
|
fmt.wBorders &= ~0x700;
|
2008-01-27 19:02:14 +01:00
|
|
|
fmt.wBorders |= 2 << 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderShadow:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-05-05 21:11:50 +02:00
|
|
|
fmt.wBorders &= ~0x700;
|
2008-01-27 19:02:14 +01:00
|
|
|
fmt.wBorders |= 10 << 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderDouble:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-05-05 21:11:50 +02:00
|
|
|
fmt.wBorders &= ~0x700;
|
2008-01-27 19:02:14 +01:00
|
|
|
fmt.wBorders |= 7 << 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderDot:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-05-05 21:11:50 +02:00
|
|
|
fmt.wBorders &= ~0x700;
|
2008-01-27 19:02:14 +01:00
|
|
|
fmt.wBorders |= 11 << 8;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
|
|
|
case rtfBorderWidth:
|
2008-08-13 05:15:36 +02:00
|
|
|
{
|
|
|
|
int borderSide = info->borderType & RTFBorderSideMask;
|
|
|
|
RTFTable *tableDef = info->tableDef;
|
2008-01-27 19:02:14 +01:00
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
2008-03-16 21:45:39 +01:00
|
|
|
fmt.wBorderWidth |= ((info->rtfParam / 15) & 7) << 8;
|
2008-08-13 05:15:36 +02:00
|
|
|
if ((info->borderType & RTFBorderTypeMask) == RTFBorderTypeCell)
|
|
|
|
{
|
|
|
|
RTFBorder *border;
|
|
|
|
if (!tableDef || tableDef->numCellsDefined >= MAX_TABLE_CELLS)
|
|
|
|
break;
|
|
|
|
border = &tableDef->cells[tableDef->numCellsDefined].border[borderSide];
|
|
|
|
border->width = info->rtfParam;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
2008-08-13 05:15:36 +02:00
|
|
|
}
|
2008-01-27 19:02:14 +01:00
|
|
|
case rtfBorderSpace:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
|
|
|
/* we assume that borders have been created before (RTF spec) */
|
|
|
|
fmt.wBorderSpace = info->rtfParam;
|
2008-08-06 23:10:49 +02:00
|
|
|
fmt.dwMask = PFM_BORDER;
|
2008-01-27 19:02:14 +01:00
|
|
|
break;
|
2008-08-13 05:15:40 +02:00
|
|
|
case rtfBorderColor:
|
|
|
|
{
|
|
|
|
RTFTable *tableDef = info->tableDef;
|
|
|
|
int borderSide = info->borderType & RTFBorderSideMask;
|
|
|
|
int borderType = info->borderType & RTFBorderTypeMask;
|
|
|
|
switch(borderType)
|
|
|
|
{
|
|
|
|
case RTFBorderTypePara:
|
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
break;
|
|
|
|
/* v1.0 - 3.0 treat paragraph and row borders the same. */
|
|
|
|
case RTFBorderTypeRow:
|
|
|
|
if (tableDef) {
|
|
|
|
tableDef->border[borderSide].color = info->rtfParam;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case RTFBorderTypeCell:
|
|
|
|
if (tableDef && tableDef->numCellsDefined < MAX_TABLE_CELLS) {
|
|
|
|
tableDef->cells[tableDef->numCellsDefined].border[borderSide].color = info->rtfParam;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-03-25 12:05:55 +01:00
|
|
|
case rtfRTLPar:
|
|
|
|
fmt.dwMask = PFM_RTLPARA;
|
|
|
|
fmt.wEffects = PFE_RTLPARA;
|
|
|
|
break;
|
|
|
|
case rtfLTRPar:
|
|
|
|
fmt.dwMask = PFM_RTLPARA;
|
|
|
|
fmt.wEffects = 0;
|
|
|
|
break;
|
2008-08-13 05:15:40 +02:00
|
|
|
}
|
2005-03-11 11:24:56 +01:00
|
|
|
if (fmt.dwMask) {
|
|
|
|
RTFFlushOutputBuffer(info);
|
2005-03-17 11:23:40 +01:00
|
|
|
/* FIXME too slow ? how come ?*/
|
|
|
|
ME_SetSelectionParaFormat(info->editor, &fmt);
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:54:12 +02:00
|
|
|
void ME_RTFTblAttrHook(RTF_Info *info)
|
2006-02-04 17:01:01 +01:00
|
|
|
{
|
|
|
|
switch (info->rtfMinor)
|
|
|
|
{
|
|
|
|
case rtfRowDef:
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2008-08-13 05:15:36 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) /* v4.1 */
|
|
|
|
info->borderType = 0; /* Not sure */
|
|
|
|
else /* v1.0 - 3.0 */
|
|
|
|
info->borderType = RTFBorderRowTop;
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!info->tableDef) {
|
2008-08-13 05:15:29 +02:00
|
|
|
info->tableDef = ME_MakeTableDef(info->editor);
|
2008-08-07 18:31:41 +02:00
|
|
|
} else {
|
2008-08-13 05:15:29 +02:00
|
|
|
ME_InitTableDef(info->editor, info->tableDef);
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2006-02-04 17:01:01 +01:00
|
|
|
break;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
2006-02-04 17:01:01 +01:00
|
|
|
case rtfCellPos:
|
2008-09-11 23:25:16 +02:00
|
|
|
{
|
|
|
|
int cellNum;
|
2008-08-05 01:18:54 +02:00
|
|
|
if (!info->tableDef)
|
|
|
|
{
|
2008-08-13 05:15:29 +02:00
|
|
|
info->tableDef = ME_MakeTableDef(info->editor);
|
2008-08-05 01:18:54 +02:00
|
|
|
}
|
2008-09-11 23:25:16 +02:00
|
|
|
cellNum = info->tableDef->numCellsDefined;
|
|
|
|
if (cellNum >= MAX_TABLE_CELLS)
|
2008-08-05 01:18:54 +02:00
|
|
|
break;
|
2008-09-11 23:25:16 +02:00
|
|
|
info->tableDef->cells[cellNum].rightBoundary = info->rtfParam;
|
|
|
|
if (cellNum < MAX_TAB_STOPS) {
|
2008-08-07 18:31:41 +02:00
|
|
|
/* Tab stops were used to store cell positions before v4.1 but v4.1
|
|
|
|
* still seems to set the tabstops without using them. */
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = info->editor->pCursors[0].pPara;
|
2008-08-05 01:18:54 +02:00
|
|
|
PARAFORMAT2 *pFmt = para->member.para.pFmt;
|
|
|
|
pFmt->rgxTabs[cellNum] &= ~0x00FFFFFF;
|
|
|
|
pFmt->rgxTabs[cellNum] = 0x00FFFFFF & info->rtfParam;
|
|
|
|
}
|
|
|
|
info->tableDef->numCellsDefined++;
|
|
|
|
break;
|
2008-09-11 23:25:16 +02:00
|
|
|
}
|
2008-08-13 05:15:36 +02:00
|
|
|
case rtfRowBordTop:
|
|
|
|
info->borderType = RTFBorderRowTop;
|
|
|
|
break;
|
|
|
|
case rtfRowBordLeft:
|
|
|
|
info->borderType = RTFBorderRowLeft;
|
|
|
|
break;
|
|
|
|
case rtfRowBordBottom:
|
|
|
|
info->borderType = RTFBorderRowBottom;
|
|
|
|
break;
|
|
|
|
case rtfRowBordRight:
|
|
|
|
info->borderType = RTFBorderRowRight;
|
|
|
|
break;
|
|
|
|
case rtfCellBordTop:
|
|
|
|
info->borderType = RTFBorderCellTop;
|
|
|
|
break;
|
|
|
|
case rtfCellBordLeft:
|
|
|
|
info->borderType = RTFBorderCellLeft;
|
|
|
|
break;
|
|
|
|
case rtfCellBordBottom:
|
|
|
|
info->borderType = RTFBorderCellBottom;
|
|
|
|
break;
|
|
|
|
case rtfCellBordRight:
|
|
|
|
info->borderType = RTFBorderCellRight;
|
|
|
|
break;
|
2008-08-13 05:15:29 +02:00
|
|
|
case rtfRowGapH:
|
|
|
|
if (info->tableDef)
|
|
|
|
info->tableDef->gapH = info->rtfParam;
|
|
|
|
break;
|
|
|
|
case rtfRowLeftEdge:
|
|
|
|
if (info->tableDef)
|
|
|
|
info->tableDef->leftEdge = info->rtfParam;
|
|
|
|
break;
|
2008-08-05 01:18:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:54:12 +02:00
|
|
|
void ME_RTFSpecialCharHook(RTF_Info *info)
|
2008-08-05 01:18:54 +02:00
|
|
|
{
|
|
|
|
RTFTable *tableDef = info->tableDef;
|
|
|
|
switch (info->rtfMinor)
|
|
|
|
{
|
2008-08-07 18:31:46 +02:00
|
|
|
case rtfNestCell:
|
|
|
|
if (info->editor->bEmulateVersion10) /* v1.0 - v3.0 */
|
|
|
|
break;
|
|
|
|
/* else fall through since v4.1 treats rtfNestCell and rtfCell the same */
|
2008-08-05 01:18:54 +02:00
|
|
|
case rtfCell:
|
|
|
|
if (!tableDef)
|
|
|
|
break;
|
2006-02-04 17:01:01 +01:00
|
|
|
RTFFlushOutputBuffer(info);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (tableDef->tableRowStart)
|
|
|
|
{
|
2008-08-07 18:31:46 +02:00
|
|
|
if (!info->nestingLevel &&
|
|
|
|
tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
ME_DisplayItem *para = tableDef->tableRowStart;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
para = ME_InsertTableRowStartAtParagraph(info->editor, para);
|
|
|
|
tableDef->tableRowStart = para;
|
2008-08-07 18:31:46 +02:00
|
|
|
info->nestingLevel = 1;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
ME_InsertTableCellFromCursor(info->editor);
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - v3.0 */
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = info->editor->pCursors[0].pPara;
|
2008-08-05 01:18:54 +02:00
|
|
|
PARAFORMAT2 *pFmt = para->member.para.pFmt;
|
|
|
|
if (pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE &&
|
|
|
|
tableDef->numCellsInserted < tableDef->numCellsDefined)
|
|
|
|
{
|
|
|
|
WCHAR tab = '\t';
|
|
|
|
ME_InsertTextFromCursor(info->editor, 0, &tab, 1, info->style);
|
|
|
|
tableDef->numCellsInserted++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2008-08-07 18:31:46 +02:00
|
|
|
case rtfNestRow:
|
|
|
|
if (info->editor->bEmulateVersion10) /* v1.0 - v3.0 */
|
|
|
|
break;
|
|
|
|
/* else fall through since v4.1 treats rtfNestRow and rtfRow the same */
|
2008-08-05 01:18:54 +02:00
|
|
|
case rtfRow:
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
ME_DisplayItem *para, *cell, *run;
|
|
|
|
int i;
|
|
|
|
|
2008-08-05 01:18:54 +02:00
|
|
|
if (!tableDef)
|
|
|
|
break;
|
|
|
|
RTFFlushOutputBuffer(info);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!info->editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (!tableDef->tableRowStart)
|
|
|
|
break;
|
2008-08-07 18:31:46 +02:00
|
|
|
if (!info->nestingLevel &&
|
|
|
|
tableDef->tableRowStart->member.para.nFlags & MEPF_ROWEND)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
para = tableDef->tableRowStart;
|
|
|
|
para = para->member.para.next_para;
|
|
|
|
para = ME_InsertTableRowStartAtParagraph(info->editor, para);
|
|
|
|
tableDef->tableRowStart = para;
|
2008-08-07 18:31:46 +02:00
|
|
|
info->nestingLevel++;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
para = tableDef->tableRowStart;
|
|
|
|
cell = ME_FindItemFwd(para, diCell);
|
|
|
|
assert(cell && !cell->member.cell.prev_cell);
|
|
|
|
if (tableDef->numCellsDefined < 1)
|
|
|
|
{
|
|
|
|
/* 2000 twips appears to be the cell size that native richedit uses
|
|
|
|
* when no cell sizes are specified. */
|
|
|
|
const int defaultCellSize = 2000;
|
|
|
|
int nRightBoundary = defaultCellSize;
|
|
|
|
cell->member.cell.nRightBoundary = nRightBoundary;
|
|
|
|
while (cell->member.cell.next_cell) {
|
|
|
|
cell = cell->member.cell.next_cell;
|
|
|
|
nRightBoundary += defaultCellSize;
|
|
|
|
cell->member.cell.nRightBoundary = nRightBoundary;
|
|
|
|
}
|
|
|
|
para = ME_InsertTableCellFromCursor(info->editor);
|
|
|
|
cell = para->member.para.pCell;
|
|
|
|
cell->member.cell.nRightBoundary = nRightBoundary;
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < tableDef->numCellsDefined; i++)
|
|
|
|
{
|
2008-08-13 05:15:40 +02:00
|
|
|
RTFCell *cellDef = &tableDef->cells[i];
|
|
|
|
cell->member.cell.nRightBoundary = cellDef->rightBoundary;
|
|
|
|
ME_ApplyBorderProperties(info, &cell->member.cell.border,
|
|
|
|
cellDef->border);
|
2008-08-07 18:31:41 +02:00
|
|
|
cell = cell->member.cell.next_cell;
|
|
|
|
if (!cell)
|
|
|
|
{
|
|
|
|
para = ME_InsertTableCellFromCursor(info->editor);
|
|
|
|
cell = para->member.para.pCell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Cell for table row delimiter is empty */
|
|
|
|
cell->member.cell.nRightBoundary = tableDef->cells[i-1].rightBoundary;
|
|
|
|
}
|
2008-08-05 01:18:54 +02:00
|
|
|
|
2008-08-07 18:31:41 +02:00
|
|
|
run = ME_FindItemFwd(cell, diRun);
|
|
|
|
if (info->editor->pCursors[0].pRun != run ||
|
|
|
|
info->editor->pCursors[0].nOffset)
|
|
|
|
{
|
|
|
|
int nOfs, nChars;
|
|
|
|
/* Delete inserted cells that aren't defined. */
|
|
|
|
info->editor->pCursors[1].pRun = run;
|
2009-02-09 18:01:35 +01:00
|
|
|
info->editor->pCursors[1].pPara = ME_GetParagraph(run);
|
2008-08-07 18:31:41 +02:00
|
|
|
info->editor->pCursors[1].nOffset = 0;
|
2009-08-12 15:05:42 +02:00
|
|
|
nOfs = ME_GetCursorOfs(&info->editor->pCursors[1]);
|
|
|
|
nChars = ME_GetCursorOfs(&info->editor->pCursors[0]) - nOfs;
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(info->editor, &info->editor->pCursors[1],
|
|
|
|
nChars, TRUE);
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
|
2008-08-07 18:31:46 +02:00
|
|
|
para = ME_InsertTableRowEndFromCursor(info->editor);
|
2008-08-13 05:15:29 +02:00
|
|
|
para->member.para.pFmt->dxOffset = abs(info->tableDef->gapH);
|
|
|
|
para->member.para.pFmt->dxStartIndent = info->tableDef->leftEdge;
|
2008-08-13 05:15:40 +02:00
|
|
|
ME_ApplyBorderProperties(info, ¶->member.para.border,
|
|
|
|
tableDef->border);
|
2008-08-07 18:31:46 +02:00
|
|
|
info->nestingLevel--;
|
|
|
|
if (!info->nestingLevel)
|
|
|
|
{
|
|
|
|
if (info->canInheritInTbl) {
|
|
|
|
tableDef->tableRowStart = para;
|
|
|
|
} else {
|
|
|
|
while (info->tableDef) {
|
|
|
|
tableDef = info->tableDef;
|
|
|
|
info->tableDef = tableDef->parent;
|
|
|
|
heap_free(tableDef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
info->tableDef = tableDef->parent;
|
|
|
|
heap_free(tableDef);
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
} else { /* v1.0 - v3.0 */
|
2008-08-05 01:18:54 +02:00
|
|
|
WCHAR endl = '\r';
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = info->editor->pCursors[0].pPara;
|
2008-08-05 01:18:54 +02:00
|
|
|
PARAFORMAT2 *pFmt = para->member.para.pFmt;
|
2008-08-13 05:15:29 +02:00
|
|
|
pFmt->dxOffset = info->tableDef->gapH;
|
|
|
|
pFmt->dxStartIndent = info->tableDef->leftEdge;
|
2008-08-13 05:15:40 +02:00
|
|
|
|
|
|
|
ME_ApplyBorderProperties(info, ¶->member.para.border,
|
|
|
|
tableDef->border);
|
2008-08-05 01:18:54 +02:00
|
|
|
while (tableDef->numCellsInserted < tableDef->numCellsDefined)
|
|
|
|
{
|
|
|
|
WCHAR tab = '\t';
|
|
|
|
ME_InsertTextFromCursor(info->editor, 0, &tab, 1, info->style);
|
|
|
|
tableDef->numCellsInserted++;
|
|
|
|
}
|
2008-09-11 23:25:16 +02:00
|
|
|
pFmt->cTabCount = min(tableDef->numCellsDefined, MAX_TAB_STOPS);
|
2008-08-05 01:18:54 +02:00
|
|
|
if (!tableDef->numCellsDefined)
|
|
|
|
pFmt->wEffects &= ~PFE_TABLE;
|
|
|
|
ME_InsertTextFromCursor(info->editor, 0, &endl, 1, info->style);
|
|
|
|
tableDef->numCellsInserted = 0;
|
2006-02-04 17:01:01 +01:00
|
|
|
}
|
2008-08-05 01:18:54 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-08-13 05:15:21 +02:00
|
|
|
case rtfTab:
|
2008-08-05 01:18:54 +02:00
|
|
|
case rtfPar:
|
2008-08-13 05:15:21 +02:00
|
|
|
if (info->editor->bEmulateVersion10) { /* v1.0 - 3.0 */
|
|
|
|
ME_DisplayItem *para;
|
|
|
|
PARAFORMAT2 *pFmt;
|
|
|
|
RTFFlushOutputBuffer(info);
|
2009-02-09 18:01:35 +01:00
|
|
|
para = info->editor->pCursors[0].pPara;
|
2008-08-13 05:15:21 +02:00
|
|
|
pFmt = para->member.para.pFmt;
|
|
|
|
if (pFmt->dwMask & PFM_TABLE && pFmt->wEffects & PFE_TABLE)
|
|
|
|
{
|
|
|
|
/* rtfPar is treated like a space within a table. */
|
|
|
|
info->rtfClass = rtfText;
|
|
|
|
info->rtfMajor = ' ';
|
|
|
|
}
|
|
|
|
else if (info->rtfMinor == rtfPar && tableDef)
|
|
|
|
tableDef->numCellsInserted = 0;
|
|
|
|
}
|
2006-02-04 17:01:01 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-16 21:45:52 +01:00
|
|
|
static BOOL ME_RTFInsertOleObject(RTF_Info *info, HENHMETAFILE hemf, HBITMAP hbmp,
|
|
|
|
const SIZEL* sz)
|
2008-01-27 19:02:21 +01:00
|
|
|
{
|
|
|
|
LPOLEOBJECT lpObject = NULL;
|
|
|
|
LPSTORAGE lpStorage = NULL;
|
|
|
|
LPOLECLIENTSITE lpClientSite = NULL;
|
|
|
|
LPDATAOBJECT lpDataObject = NULL;
|
|
|
|
LPOLECACHE lpOleCache = NULL;
|
|
|
|
STGMEDIUM stgm;
|
|
|
|
FORMATETC fm;
|
|
|
|
CLSID clsid;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
DWORD conn;
|
|
|
|
|
2008-03-16 21:45:52 +01:00
|
|
|
if (hemf)
|
|
|
|
{
|
|
|
|
stgm.tymed = TYMED_ENHMF;
|
|
|
|
stgm.u.hEnhMetaFile = hemf;
|
|
|
|
fm.cfFormat = CF_ENHMETAFILE;
|
|
|
|
}
|
|
|
|
else if (hbmp)
|
|
|
|
{
|
|
|
|
stgm.tymed = TYMED_GDI;
|
|
|
|
stgm.u.hBitmap = hbmp;
|
|
|
|
fm.cfFormat = CF_BITMAP;
|
|
|
|
}
|
2008-01-27 19:02:21 +01:00
|
|
|
stgm.pUnkForRelease = NULL;
|
|
|
|
|
|
|
|
fm.ptd = NULL;
|
|
|
|
fm.dwAspect = DVASPECT_CONTENT;
|
|
|
|
fm.lindex = -1;
|
|
|
|
fm.tymed = stgm.tymed;
|
|
|
|
|
|
|
|
if (!info->lpRichEditOle)
|
|
|
|
{
|
|
|
|
CreateIRichEditOle(info->editor, (VOID**)&info->lpRichEditOle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
|
|
|
|
#if 0
|
|
|
|
/* FIXME: enable it when rich-edit properly implements this method */
|
|
|
|
IRichEditOle_GetClientSite(info->lpRichEditOle, &lpClientSite) == S_OK &&
|
|
|
|
IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
|
|
|
|
#endif
|
|
|
|
IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
|
|
|
|
IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
|
|
|
|
IOleCache_Cache(lpOleCache, &fm, 0, &conn) == S_OK &&
|
|
|
|
IOleObject_QueryInterface(lpObject, &IID_IDataObject, (void**)&lpDataObject) == S_OK &&
|
|
|
|
IDataObject_SetData(lpDataObject, &fm, &stgm, TRUE) == S_OK)
|
|
|
|
{
|
|
|
|
REOBJECT reobject;
|
|
|
|
|
|
|
|
reobject.cbStruct = sizeof(reobject);
|
|
|
|
reobject.cp = REO_CP_SELECTION;
|
|
|
|
reobject.clsid = clsid;
|
|
|
|
reobject.poleobj = lpObject;
|
|
|
|
reobject.pstg = lpStorage;
|
|
|
|
reobject.polesite = lpClientSite;
|
|
|
|
/* convert from twips to .01 mm */
|
|
|
|
reobject.sizel.cx = MulDiv(sz->cx, 254, 144);
|
|
|
|
reobject.sizel.cy = MulDiv(sz->cy, 254, 144);
|
|
|
|
reobject.dvaspect = DVASPECT_CONTENT;
|
|
|
|
reobject.dwFlags = 0; /* FIXME */
|
|
|
|
reobject.dwUser = 0;
|
|
|
|
|
2009-11-08 15:04:53 +01:00
|
|
|
ME_InsertOLEFromCursor(info->editor, &reobject, 0);
|
|
|
|
ret = TRUE;
|
2008-01-27 19:02:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpObject) IOleObject_Release(lpObject);
|
|
|
|
if (lpClientSite) IOleClientSite_Release(lpClientSite);
|
|
|
|
if (lpStorage) IStorage_Release(lpStorage);
|
|
|
|
if (lpDataObject) IDataObject_Release(lpDataObject);
|
|
|
|
if (lpOleCache) IOleCache_Release(lpOleCache);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ME_RTFReadPictGroup(RTF_Info *info)
|
|
|
|
{
|
|
|
|
SIZEL sz;
|
|
|
|
BYTE* buffer = NULL;
|
|
|
|
unsigned bufsz, bufidx;
|
|
|
|
BOOL flip;
|
|
|
|
BYTE val;
|
|
|
|
METAFILEPICT mfp;
|
|
|
|
HENHMETAFILE hemf;
|
2008-03-16 21:45:52 +01:00
|
|
|
HBITMAP hbmp;
|
2008-03-16 21:48:29 +01:00
|
|
|
enum gfxkind {gfx_unknown = 0, gfx_enhmetafile, gfx_metafile, gfx_dib} gfx = gfx_unknown;
|
2008-01-27 19:02:21 +01:00
|
|
|
|
|
|
|
RTFGetToken (info);
|
|
|
|
if (info->rtfClass == rtfEOF)
|
|
|
|
return;
|
|
|
|
mfp.mm = MM_TEXT;
|
|
|
|
/* fetch picture type */
|
|
|
|
if (RTFCheckMM (info, rtfPictAttr, rtfWinMetafile))
|
|
|
|
{
|
|
|
|
mfp.mm = info->rtfParam;
|
2008-03-16 21:48:29 +01:00
|
|
|
gfx = gfx_metafile;
|
2008-03-16 21:45:52 +01:00
|
|
|
}
|
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfDevIndBitmap))
|
|
|
|
{
|
|
|
|
if (info->rtfParam != 0) FIXME("dibitmap should be 0 (%d)\n", info->rtfParam);
|
|
|
|
gfx = gfx_dib;
|
2008-01-27 19:02:21 +01:00
|
|
|
}
|
2008-03-16 21:48:29 +01:00
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfEmfBlip))
|
|
|
|
{
|
|
|
|
gfx = gfx_enhmetafile;
|
|
|
|
}
|
2008-01-27 19:02:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("%d %d\n", info->rtfMajor, info->rtfMinor);
|
|
|
|
goto skip_group;
|
|
|
|
}
|
|
|
|
sz.cx = sz.cy = 0;
|
|
|
|
/* fetch picture attributes */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
RTFGetToken (info);
|
|
|
|
if (info->rtfClass == rtfEOF)
|
|
|
|
return;
|
|
|
|
if (info->rtfClass == rtfText)
|
|
|
|
break;
|
|
|
|
if (!RTFCheckCM (info, rtfControl, rtfPictAttr))
|
|
|
|
{
|
|
|
|
ERR("Expected picture attribute (%d %d)\n",
|
|
|
|
info->rtfClass, info->rtfMajor);
|
|
|
|
goto skip_group;
|
|
|
|
}
|
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfPicWid))
|
2008-03-16 21:45:52 +01:00
|
|
|
{
|
2008-03-16 21:48:29 +01:00
|
|
|
if (gfx == gfx_metafile) mfp.xExt = info->rtfParam;
|
2008-03-16 21:45:52 +01:00
|
|
|
}
|
2008-01-27 19:02:21 +01:00
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfPicHt))
|
2008-03-16 21:45:52 +01:00
|
|
|
{
|
2008-03-16 21:48:29 +01:00
|
|
|
if (gfx == gfx_metafile) mfp.yExt = info->rtfParam;
|
2008-03-16 21:45:52 +01:00
|
|
|
}
|
2008-01-27 19:02:21 +01:00
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfPicGoalWid))
|
|
|
|
sz.cx = info->rtfParam;
|
|
|
|
else if (RTFCheckMM (info, rtfPictAttr, rtfPicGoalHt))
|
|
|
|
sz.cy = info->rtfParam;
|
|
|
|
else
|
|
|
|
FIXME("Non supported attribute: %d %d %d\n", info->rtfClass, info->rtfMajor, info->rtfMinor);
|
|
|
|
}
|
|
|
|
/* fetch picture data */
|
|
|
|
bufsz = 1024;
|
|
|
|
bufidx = 0;
|
|
|
|
buffer = HeapAlloc(GetProcessHeap(), 0, bufsz);
|
|
|
|
val = info->rtfMajor;
|
|
|
|
for (flip = TRUE;; flip = !flip)
|
|
|
|
{
|
|
|
|
RTFGetToken (info);
|
|
|
|
if (info->rtfClass == rtfEOF)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
return; /* Warn ?? */
|
|
|
|
}
|
|
|
|
if (RTFCheckCM(info, rtfGroup, rtfEndGroup))
|
|
|
|
break;
|
|
|
|
if (info->rtfClass != rtfText) goto skip_group;
|
|
|
|
if (flip)
|
|
|
|
{
|
|
|
|
if (bufidx >= bufsz &&
|
|
|
|
!(buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, bufsz += 1024)))
|
|
|
|
goto skip_group;
|
|
|
|
buffer[bufidx++] = RTFCharToHex(val) * 16 + RTFCharToHex(info->rtfMajor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
val = info->rtfMajor;
|
|
|
|
}
|
|
|
|
if (flip) FIXME("wrong hex string\n");
|
|
|
|
|
2008-03-16 21:45:52 +01:00
|
|
|
switch (gfx)
|
|
|
|
{
|
|
|
|
case gfx_enhmetafile:
|
2008-03-16 21:48:29 +01:00
|
|
|
if ((hemf = SetEnhMetaFileBits(bufidx, buffer)))
|
|
|
|
ME_RTFInsertOleObject(info, hemf, NULL, &sz);
|
|
|
|
break;
|
|
|
|
case gfx_metafile:
|
2008-03-16 21:45:52 +01:00
|
|
|
if ((hemf = SetWinMetaFileBits(bufidx, buffer, NULL, &mfp)))
|
|
|
|
ME_RTFInsertOleObject(info, hemf, NULL, &sz);
|
|
|
|
break;
|
|
|
|
case gfx_dib:
|
|
|
|
{
|
|
|
|
BITMAPINFO* bi = (BITMAPINFO*)buffer;
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
unsigned nc = bi->bmiHeader.biClrUsed;
|
|
|
|
|
|
|
|
/* not quite right, especially for bitfields type of compression */
|
|
|
|
if (!nc && bi->bmiHeader.biBitCount <= 8)
|
|
|
|
nc = 1 << bi->bmiHeader.biBitCount;
|
|
|
|
if ((hbmp = CreateDIBitmap(hdc, &bi->bmiHeader,
|
|
|
|
CBM_INIT, (char*)(bi + 1) + nc * sizeof(RGBQUAD),
|
|
|
|
bi, DIB_RGB_COLORS)))
|
|
|
|
ME_RTFInsertOleObject(info, NULL, hbmp, &sz);
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-01-27 19:02:21 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
RTFRouteToken (info); /* feed "}" back to router */
|
|
|
|
return;
|
|
|
|
skip_group:
|
|
|
|
HeapFree(GetProcessHeap(), 0, buffer);
|
|
|
|
RTFSkipGroup(info);
|
|
|
|
RTFRouteToken(info); /* feed "}" back to router */
|
|
|
|
}
|
|
|
|
|
2008-01-27 19:02:28 +01:00
|
|
|
/* for now, lookup the \result part and use it, whatever the object */
|
|
|
|
static void ME_RTFReadObjectGroup(RTF_Info *info)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
RTFGetToken (info);
|
|
|
|
if (info->rtfClass == rtfEOF)
|
|
|
|
return;
|
|
|
|
if (RTFCheckCM(info, rtfGroup, rtfEndGroup))
|
|
|
|
break;
|
|
|
|
if (RTFCheckCM(info, rtfGroup, rtfBeginGroup))
|
|
|
|
{
|
|
|
|
RTFGetToken (info);
|
|
|
|
if (info->rtfClass == rtfEOF)
|
|
|
|
return;
|
|
|
|
if (RTFCheckCMM(info, rtfControl, rtfDestination, rtfObjResult))
|
|
|
|
{
|
|
|
|
int level = 1;
|
|
|
|
|
|
|
|
while (RTFGetToken (info) != rtfEOF)
|
|
|
|
{
|
|
|
|
if (info->rtfClass == rtfGroup)
|
|
|
|
{
|
|
|
|
if (info->rtfMajor == rtfBeginGroup) level++;
|
|
|
|
else if (info->rtfMajor == rtfEndGroup && --level < 0) break;
|
|
|
|
}
|
|
|
|
RTFRouteToken(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else RTFSkipGroup(info);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!RTFCheckCM (info, rtfControl, rtfObjAttr))
|
|
|
|
{
|
|
|
|
FIXME("Non supported attribute: %d %d %d\n", info->rtfClass, info->rtfMajor, info->rtfMinor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RTFRouteToken(info); /* feed "}" back to router */
|
|
|
|
}
|
|
|
|
|
2008-09-11 04:54:12 +02:00
|
|
|
static void ME_RTFReadHook(RTF_Info *info)
|
|
|
|
{
|
2005-03-11 11:24:56 +01:00
|
|
|
switch(info->rtfClass)
|
|
|
|
{
|
2005-03-16 12:27:43 +01:00
|
|
|
case rtfGroup:
|
|
|
|
switch(info->rtfMajor)
|
|
|
|
{
|
|
|
|
case rtfBeginGroup:
|
2005-03-18 11:24:51 +01:00
|
|
|
if (info->stackTop < maxStack) {
|
2009-07-17 19:24:13 +02:00
|
|
|
info->stack[info->stackTop].style = info->style;
|
|
|
|
ME_AddRefStyle(info->style);
|
2005-03-18 11:24:51 +01:00
|
|
|
info->stack[info->stackTop].codePage = info->codePage;
|
|
|
|
info->stack[info->stackTop].unicodeLength = info->unicodeLength;
|
2005-03-16 12:27:43 +01:00
|
|
|
}
|
2005-03-18 11:24:51 +01:00
|
|
|
info->stackTop++;
|
2005-08-22 12:06:08 +02:00
|
|
|
info->styleChanged = FALSE;
|
2005-03-16 12:27:43 +01:00
|
|
|
break;
|
|
|
|
case rtfEndGroup:
|
2005-03-17 11:23:40 +01:00
|
|
|
{
|
2005-03-16 12:27:43 +01:00
|
|
|
RTFFlushOutputBuffer(info);
|
2008-06-26 22:17:25 +02:00
|
|
|
info->stackTop--;
|
2009-08-10 16:53:53 +02:00
|
|
|
if (info->stackTop <= 0)
|
2005-10-03 20:45:39 +02:00
|
|
|
info->rtfClass = rtfEOF;
|
2009-08-10 16:53:53 +02:00
|
|
|
if (info->stackTop < 0)
|
2005-10-03 20:45:39 +02:00
|
|
|
return;
|
2009-07-17 19:24:13 +02:00
|
|
|
|
|
|
|
ME_ReleaseStyle(info->style);
|
|
|
|
info->style = info->stack[info->stackTop].style;
|
|
|
|
info->codePage = info->stack[info->stackTop].codePage;
|
|
|
|
info->unicodeLength = info->stack[info->stackTop].unicodeLength;
|
2005-03-16 12:27:43 +01:00
|
|
|
break;
|
2005-03-17 11:23:40 +01:00
|
|
|
}
|
2005-03-16 12:27:43 +01:00
|
|
|
}
|
|
|
|
break;
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
void
|
|
|
|
ME_StreamInFill(ME_InStream *stream)
|
|
|
|
{
|
|
|
|
stream->editstream->dwError = stream->editstream->pfnCallback(stream->editstream->dwCookie,
|
2005-09-12 22:30:37 +02:00
|
|
|
(BYTE *)stream->buffer,
|
2005-04-13 13:11:03 +02:00
|
|
|
sizeof(stream->buffer),
|
2005-09-12 22:30:37 +02:00
|
|
|
(LONG *)&stream->dwSize);
|
2005-04-13 13:11:03 +02:00
|
|
|
stream->dwUsed = 0;
|
|
|
|
}
|
|
|
|
|
2008-04-24 17:00:29 +02:00
|
|
|
static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream, BOOL stripLastCR)
|
2005-03-08 20:03:01 +01:00
|
|
|
{
|
|
|
|
RTF_Info parser;
|
|
|
|
ME_Style *style;
|
2009-08-12 15:05:46 +02:00
|
|
|
int from, to, nUndoMode;
|
2005-03-17 11:23:40 +01:00
|
|
|
int nEventMask = editor->nEventMask;
|
2005-04-13 13:11:03 +02:00
|
|
|
ME_InStream inStream;
|
2008-04-24 17:07:12 +02:00
|
|
|
BOOL invalidRTF = FALSE;
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor *selStart, *selEnd;
|
2011-09-26 04:17:19 +02:00
|
|
|
LRESULT num_read = 0; /* bytes read for SF_TEXT, non-control chars inserted for SF_RTF */
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
TRACE("stream==%p editor==%p format==0x%X\n", stream, editor, format);
|
2005-03-17 11:23:40 +01:00
|
|
|
editor->nEventMask = 0;
|
2008-01-16 22:57:25 +01:00
|
|
|
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &from, &to);
|
2009-08-13 14:44:18 +02:00
|
|
|
if (format & SFF_SELECTION && editor->mode & TM_RICHTEXT)
|
|
|
|
{
|
|
|
|
ME_GetSelection(editor, &selStart, &selEnd);
|
2005-03-08 20:03:01 +01:00
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
2005-03-11 11:24:56 +01:00
|
|
|
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, selStart, to - from, FALSE);
|
2008-08-28 21:24:27 +02:00
|
|
|
|
|
|
|
/* Don't insert text at the end of the table row */
|
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = editor->pCursors->pPara;
|
2008-08-28 21:24:27 +02:00
|
|
|
if (para->member.para.nFlags & MEPF_ROWEND)
|
|
|
|
{
|
|
|
|
para = para->member.para.next_para;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2008-08-28 21:24:27 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
}
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
{
|
|
|
|
para = para->member.para.next_para;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2008-08-28 21:24:27 +02:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
}
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
} else { /* v1.0 - 3.0 */
|
|
|
|
if (editor->pCursors[0].pRun->member.run.nFlags & MERF_ENDPARA &&
|
|
|
|
ME_IsInTable(editor->pCursors[0].pRun))
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-13 14:44:18 +02:00
|
|
|
} else {
|
2005-03-08 20:03:01 +01:00
|
|
|
style = editor->pBuffer->pDefaultStyle;
|
|
|
|
ME_AddRefStyle(style);
|
2008-12-16 09:43:43 +01:00
|
|
|
ME_SetSelection(editor, 0, 0);
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, &editor->pCursors[1],
|
|
|
|
ME_GetTextLength(editor), FALSE);
|
2005-03-11 11:24:56 +01:00
|
|
|
from = to = 0;
|
2005-03-08 20:03:01 +01:00
|
|
|
ME_ClearTempStyle(editor);
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_SetDefaultParaFormat(editor->pCursors[0].pPara->member.para.pFmt);
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2007-01-25 07:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Back up undo mode to a local variable */
|
|
|
|
nUndoMode = editor->nUndoMode;
|
|
|
|
|
|
|
|
/* Only create an undo if SFF_SELECTION is set */
|
|
|
|
if (!(format & SFF_SELECTION))
|
|
|
|
editor->nUndoMode = umIgnore;
|
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
inStream.editstream = stream;
|
|
|
|
inStream.editstream->dwError = 0;
|
|
|
|
inStream.dwSize = 0;
|
|
|
|
inStream.dwUsed = 0;
|
|
|
|
|
|
|
|
if (format & SF_RTF)
|
|
|
|
{
|
|
|
|
/* Check if it's really RTF, and if it is not, use plain text */
|
|
|
|
ME_StreamInFill(&inStream);
|
|
|
|
if (!inStream.editstream->dwError)
|
|
|
|
{
|
2008-04-22 00:50:14 +02:00
|
|
|
if ((!editor->bEmulateVersion10 && strncmp(inStream.buffer, "{\\rtf", 5) && strncmp(inStream.buffer, "{\\urtf", 6))
|
|
|
|
|| (editor->bEmulateVersion10 && *inStream.buffer != '{'))
|
2005-04-13 13:11:03 +02:00
|
|
|
{
|
2008-04-24 17:07:12 +02:00
|
|
|
invalidRTF = TRUE;
|
2008-04-29 05:43:49 +02:00
|
|
|
inStream.editstream->dwError = -16;
|
2005-04-13 13:11:03 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2005-04-13 13:11:03 +02:00
|
|
|
|
2008-04-24 17:07:12 +02:00
|
|
|
if (!invalidRTF && !inStream.editstream->dwError)
|
2005-03-08 20:03:01 +01:00
|
|
|
{
|
2005-04-13 13:11:03 +02:00
|
|
|
if (format & SF_RTF) {
|
2011-09-26 04:17:28 +02:00
|
|
|
from = ME_GetCursorOfs(&editor->pCursors[0]);
|
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
/* setup the RTF parser */
|
|
|
|
memset(&parser, 0, sizeof parser);
|
|
|
|
RTFSetEditStream(&parser, &inStream);
|
|
|
|
parser.rtfFormat = format&(SF_TEXT|SF_RTF);
|
|
|
|
parser.editor = editor;
|
|
|
|
parser.style = style;
|
|
|
|
WriterInit(&parser);
|
|
|
|
RTFInit(&parser);
|
|
|
|
RTFSetReadHook(&parser, ME_RTFReadHook);
|
2008-01-27 19:02:21 +01:00
|
|
|
RTFSetDestinationCallback(&parser, rtfPict, ME_RTFReadPictGroup);
|
2008-01-27 19:02:28 +01:00
|
|
|
RTFSetDestinationCallback(&parser, rtfObject, ME_RTFReadObjectGroup);
|
2008-08-07 18:31:46 +02:00
|
|
|
if (!parser.editor->bEmulateVersion10) /* v4.1 */
|
2008-09-11 19:32:06 +02:00
|
|
|
{
|
2008-08-07 18:31:46 +02:00
|
|
|
RTFSetDestinationCallback(&parser, rtfNoNestTables, RTFSkipGroup);
|
2008-09-11 19:32:06 +02:00
|
|
|
RTFSetDestinationCallback(&parser, rtfNestTableProps, RTFReadGroup);
|
|
|
|
}
|
2005-04-13 13:11:03 +02:00
|
|
|
BeginFile(&parser);
|
2008-01-27 19:02:21 +01:00
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
/* do the parsing */
|
|
|
|
RTFRead(&parser);
|
|
|
|
RTFFlushOutputBuffer(&parser);
|
2008-08-07 18:31:41 +02:00
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
2008-09-11 20:16:45 +02:00
|
|
|
if (parser.tableDef && parser.tableDef->tableRowStart &&
|
|
|
|
(parser.nestingLevel > 0 || parser.canInheritInTbl))
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
|
|
|
/* Delete any incomplete table row at the end of the rich text. */
|
|
|
|
int nOfs, nChars;
|
2008-09-11 20:16:45 +02:00
|
|
|
ME_DisplayItem *para;
|
2008-08-07 18:31:41 +02:00
|
|
|
|
|
|
|
parser.rtfMinor = rtfRow;
|
|
|
|
/* Complete the table row before deleting it.
|
|
|
|
* By doing it this way we will have the current paragraph format set
|
|
|
|
* properly to reflect that is not in the complete table, and undo items
|
|
|
|
* will be added for this change to the current paragraph format. */
|
2008-08-07 18:31:46 +02:00
|
|
|
if (parser.nestingLevel > 0)
|
|
|
|
{
|
2008-09-11 20:16:45 +02:00
|
|
|
while (parser.nestingLevel > 1)
|
|
|
|
ME_RTFSpecialCharHook(&parser); /* Decrements nestingLevel */
|
|
|
|
para = parser.tableDef->tableRowStart;
|
2008-08-07 18:31:46 +02:00
|
|
|
ME_RTFSpecialCharHook(&parser);
|
2008-09-11 20:16:45 +02:00
|
|
|
} else {
|
|
|
|
para = parser.tableDef->tableRowStart;
|
|
|
|
ME_RTFSpecialCharHook(&parser);
|
|
|
|
assert(para->member.para.nFlags & MEPF_ROWEND);
|
2008-08-07 18:31:41 +02:00
|
|
|
para = para->member.para.next_para;
|
|
|
|
}
|
|
|
|
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[1].pPara = para;
|
2008-08-07 18:31:41 +02:00
|
|
|
editor->pCursors[1].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[1].nOffset = 0;
|
2009-08-12 15:05:42 +02:00
|
|
|
nOfs = ME_GetCursorOfs(&editor->pCursors[1]);
|
|
|
|
nChars = ME_GetCursorOfs(&editor->pCursors[0]) - nOfs;
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, &editor->pCursors[1], nChars, TRUE);
|
2008-09-11 20:16:45 +02:00
|
|
|
if (parser.tableDef)
|
|
|
|
parser.tableDef->tableRowStart = NULL;
|
2008-08-07 18:31:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ME_CheckTablesForCorruption(editor);
|
2005-04-13 13:11:03 +02:00
|
|
|
RTFDestroy(&parser);
|
2008-01-27 19:02:21 +01:00
|
|
|
if (parser.lpRichEditOle)
|
|
|
|
IRichEditOle_Release(parser.lpRichEditOle);
|
2005-04-13 13:11:03 +02:00
|
|
|
|
2009-08-10 16:53:53 +02:00
|
|
|
if (parser.stackTop > 0)
|
|
|
|
{
|
|
|
|
while (--parser.stackTop >= 0)
|
|
|
|
{
|
|
|
|
ME_ReleaseStyle(parser.style);
|
|
|
|
parser.style = parser.stack[parser.stackTop].style;
|
|
|
|
}
|
|
|
|
if (!inStream.editstream->dwError)
|
|
|
|
inStream.editstream->dwError = HRESULT_FROM_WIN32(ERROR_HANDLE_EOF);
|
|
|
|
}
|
2008-06-26 22:17:25 +02:00
|
|
|
|
2008-04-27 05:49:35 +02:00
|
|
|
/* Remove last line break, as mandated by tests. This is not affected by
|
|
|
|
CR/LF counters, since RTF streaming presents only \para tokens, which
|
|
|
|
are converted according to the standard rules: \r for 2.0, \r\n for 1.0
|
|
|
|
*/
|
2008-04-24 17:00:29 +02:00
|
|
|
if (stripLastCR) {
|
2009-08-13 14:44:18 +02:00
|
|
|
int newto;
|
|
|
|
ME_GetSelection(editor, &selStart, &selEnd);
|
|
|
|
newto = ME_GetCursorOfs(selEnd);
|
2008-04-24 17:04:23 +02:00
|
|
|
if (newto > to + (editor->bEmulateVersion10 ? 1 : 0)) {
|
|
|
|
WCHAR lastchar[3] = {'\0', '\0'};
|
|
|
|
int linebreakSize = editor->bEmulateVersion10 ? 2 : 1;
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor linebreakCursor = *selEnd;
|
2008-04-24 17:00:29 +02:00
|
|
|
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_MoveCursorChars(editor, &linebreakCursor, -linebreakSize);
|
2009-08-12 15:05:51 +02:00
|
|
|
ME_GetTextW(editor, lastchar, 2, &linebreakCursor, linebreakSize, 0);
|
2008-04-24 17:04:23 +02:00
|
|
|
if (lastchar[0] == '\r' && (lastchar[1] == '\n' || lastchar[1] == '\0')) {
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, &linebreakCursor, linebreakSize, FALSE);
|
2008-04-24 17:00:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 04:17:28 +02:00
|
|
|
to = ME_GetCursorOfs(&editor->pCursors[0]);
|
|
|
|
num_read = to - from;
|
2008-04-24 17:00:29 +02:00
|
|
|
|
2005-04-13 13:11:03 +02:00
|
|
|
style = parser.style;
|
|
|
|
}
|
|
|
|
else if (format & SF_TEXT)
|
2011-09-26 04:17:19 +02:00
|
|
|
num_read = ME_StreamInText(editor, format, &inStream, style);
|
2005-04-13 13:11:03 +02:00
|
|
|
else
|
|
|
|
ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
|
|
|
|
/* put the cursor at the top */
|
|
|
|
if (!(format & SFF_SELECTION))
|
2008-12-16 09:43:43 +01:00
|
|
|
ME_SetSelection(editor, 0, 0);
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2007-01-12 07:09:44 +01:00
|
|
|
|
2007-01-25 07:11:07 +01:00
|
|
|
/* Restore saved undo mode */
|
|
|
|
editor->nUndoMode = nUndoMode;
|
|
|
|
|
|
|
|
/* even if we didn't add an undo, we need to commit anything on the stack */
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
|
|
|
|
/* If SFF_SELECTION isn't set, delete any undos from before we started too */
|
|
|
|
if (!(format & SFF_SELECTION))
|
2006-02-05 12:18:55 +01:00
|
|
|
ME_EmptyUndoStack(editor);
|
|
|
|
|
2007-01-25 07:11:07 +01:00
|
|
|
ME_ReleaseStyle(style);
|
2005-03-17 11:23:40 +01:00
|
|
|
editor->nEventMask = nEventMask;
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2005-03-17 11:23:40 +01:00
|
|
|
if (!(format & SFF_SELECTION)) {
|
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
}
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxShowCaret(editor->texthost, FALSE);
|
2005-03-17 11:23:40 +01:00
|
|
|
ME_MoveCaret(editor);
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxShowCaret(editor->texthost, TRUE);
|
2005-03-17 11:23:40 +01:00
|
|
|
ME_SendSelChange(editor);
|
2005-11-03 10:52:29 +01:00
|
|
|
ME_SendRequestResize(editor, FALSE);
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2011-09-26 04:17:19 +02:00
|
|
|
return num_read;
|
2005-03-07 18:15:33 +01:00
|
|
|
}
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2006-02-14 17:38:57 +01:00
|
|
|
typedef struct tagME_RTFStringStreamStruct
|
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
int pos;
|
|
|
|
int length;
|
|
|
|
} ME_RTFStringStreamStruct;
|
|
|
|
|
|
|
|
static DWORD CALLBACK ME_ReadFromRTFString(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
|
|
|
|
{
|
|
|
|
ME_RTFStringStreamStruct *pStruct = (ME_RTFStringStreamStruct *)dwCookie;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = min(cb, pStruct->length - pStruct->pos);
|
|
|
|
memmove(lpBuff, pStruct->string + pStruct->pos, count);
|
|
|
|
pStruct->pos += count;
|
|
|
|
*pcb = count;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ME_StreamInRTFString(ME_TextEditor *editor, BOOL selection, char *string)
|
|
|
|
{
|
|
|
|
EDITSTREAM es;
|
|
|
|
ME_RTFStringStreamStruct data;
|
|
|
|
|
|
|
|
data.string = string;
|
|
|
|
data.length = strlen(string);
|
|
|
|
data.pos = 0;
|
2008-12-22 00:09:17 +01:00
|
|
|
es.dwCookie = (DWORD_PTR)&data;
|
2006-02-14 17:38:57 +01:00
|
|
|
es.pfnCallback = ME_ReadFromRTFString;
|
2008-04-24 17:00:29 +02:00
|
|
|
ME_StreamIn(editor, SF_RTF | (selection ? SFF_SELECTION : 0), &es, FALSE);
|
2006-02-14 17:38:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-06 12:32:59 +02:00
|
|
|
static int
|
2007-08-11 17:07:50 +02:00
|
|
|
ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
const int nLen = lstrlenW(text);
|
|
|
|
const int nTextLen = ME_GetTextLength(editor);
|
2005-08-23 11:32:55 +02:00
|
|
|
int nMin, nMax;
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_Cursor cursor;
|
2006-03-21 12:43:56 +01:00
|
|
|
WCHAR wLastChar = ' ';
|
2005-08-23 11:32:55 +02:00
|
|
|
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
|
2005-08-23 11:32:55 +02:00
|
|
|
flags, chrg->cpMin, chrg->cpMax, debugstr_w(text));
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2006-03-21 12:43:56 +01:00
|
|
|
if (flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD))
|
2006-10-13 21:25:54 +02:00
|
|
|
FIXME("Flags 0x%08x not implemented\n",
|
2006-03-21 12:43:56 +01:00
|
|
|
flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD));
|
2005-07-06 12:32:59 +02:00
|
|
|
|
2006-02-20 19:35:14 +01:00
|
|
|
nMin = chrg->cpMin;
|
2005-08-23 11:32:55 +02:00
|
|
|
if (chrg->cpMax == -1)
|
2006-03-21 12:43:56 +01:00
|
|
|
nMax = nTextLen;
|
2005-08-23 11:32:55 +02:00
|
|
|
else
|
2006-03-21 12:43:56 +01:00
|
|
|
nMax = chrg->cpMax > nTextLen ? nTextLen : chrg->cpMax;
|
2009-02-09 18:01:35 +01:00
|
|
|
|
2008-04-30 07:25:50 +02:00
|
|
|
/* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
|
|
|
|
if (editor->bEmulateVersion10 && nMax == nTextLen)
|
|
|
|
{
|
|
|
|
flags |= FR_DOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In 1.0 emulation, cpMin must always be no greater than cpMax */
|
|
|
|
if (editor->bEmulateVersion10 && nMax < nMin)
|
|
|
|
{
|
|
|
|
if (chrgText)
|
|
|
|
{
|
|
|
|
chrgText->cpMin = -1;
|
|
|
|
chrgText->cpMax = -1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-02-20 19:35:14 +01:00
|
|
|
/* when searching up, if cpMin < cpMax, then instead of searching
|
|
|
|
* on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
|
2006-03-21 12:43:56 +01:00
|
|
|
* [cpMax, cpMin]. The exception is when cpMax is -1, in which
|
|
|
|
* case, it is always bigger than cpMin.
|
2006-02-20 19:35:14 +01:00
|
|
|
*/
|
2008-04-30 07:25:50 +02:00
|
|
|
if (!editor->bEmulateVersion10 && !(flags & FR_DOWN))
|
2005-08-23 11:32:55 +02:00
|
|
|
{
|
2006-02-20 19:35:14 +01:00
|
|
|
int nSwap = nMax;
|
|
|
|
|
2006-03-21 12:43:56 +01:00
|
|
|
nMax = nMin > nTextLen ? nTextLen : nMin;
|
|
|
|
if (nMin < nSwap || chrg->cpMax == -1)
|
2006-02-20 19:35:14 +01:00
|
|
|
nMin = 0;
|
|
|
|
else
|
|
|
|
nMin = nSwap;
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
2006-02-20 19:35:14 +01:00
|
|
|
|
|
|
|
if (!nLen || nMin < 0 || nMax < 0 || nMax < nMin)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
|
|
|
if (chrgText)
|
2006-02-15 13:37:31 +01:00
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
|
|
|
return -1;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
2009-02-06 07:09:47 +01:00
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
if (flags & FR_DOWN) /* Forward search */
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
/* If possible, find the character before where the search starts */
|
|
|
|
if ((flags & FR_WHOLEWORD) && nMin)
|
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
|
2013-01-30 16:10:20 +01:00
|
|
|
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_MoveCursorChars(editor, &cursor, 1);
|
|
|
|
} else {
|
|
|
|
ME_CursorFromCharOfs(editor, nMin, &cursor);
|
2006-03-21 12:43:56 +01:00
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:27 +02:00
|
|
|
while (cursor.pRun && ME_GetCursorOfs(&cursor) + nLen <= nMax)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_DisplayItem *pCurItem = cursor.pRun;
|
|
|
|
int nCurStart = cursor.nOffset;
|
2005-08-23 11:32:55 +02:00
|
|
|
int nMatched = 0;
|
|
|
|
|
2013-01-30 16:10:20 +01:00
|
|
|
while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurStart + nMatched ), text[nMatched], (flags & FR_MATCHCASE)))
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
|
|
|
|
break;
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nMatched++;
|
|
|
|
if (nMatched == nLen)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
ME_DisplayItem *pNextItem = pCurItem;
|
|
|
|
int nNextStart = nCurStart;
|
|
|
|
WCHAR wNextChar;
|
|
|
|
|
|
|
|
/* Check to see if next character is a whitespace */
|
|
|
|
if (flags & FR_WHOLEWORD)
|
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
if (nCurStart + nMatched == pCurItem->member.run.len)
|
2006-03-21 12:43:56 +01:00
|
|
|
{
|
|
|
|
pNextItem = ME_FindItemFwd(pCurItem, diRun);
|
|
|
|
nNextStart = -nMatched;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pNextItem)
|
2013-01-30 16:10:20 +01:00
|
|
|
wNextChar = *get_text( &pNextItem->member.run, nNextStart + nMatched );
|
2006-03-21 12:43:56 +01:00
|
|
|
else
|
|
|
|
wNextChar = ' ';
|
|
|
|
|
|
|
|
if (isalnumW(wNextChar))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:27 +02:00
|
|
|
cursor.nOffset += cursor.pPara->member.para.nCharOfs + cursor.pRun->member.run.nCharOfs;
|
2005-08-23 11:32:55 +02:00
|
|
|
if (chrgText)
|
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
chrgText->cpMin = cursor.nOffset;
|
|
|
|
chrgText->cpMax = cursor.nOffset + nLen;
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
2009-08-13 14:44:27 +02:00
|
|
|
TRACE("found at %d-%d\n", cursor.nOffset, cursor.nOffset + nLen);
|
|
|
|
return cursor.nOffset;
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
2013-01-31 14:48:00 +01:00
|
|
|
if (nCurStart + nMatched == pCurItem->member.run.len)
|
2005-08-23 11:32:55 +02:00
|
|
|
{
|
|
|
|
pCurItem = ME_FindItemFwd(pCurItem, diRun);
|
|
|
|
nCurStart = -nMatched;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 12:43:56 +01:00
|
|
|
if (pCurItem)
|
2013-01-30 16:10:20 +01:00
|
|
|
wLastChar = *get_text( &pCurItem->member.run, nCurStart + nMatched );
|
2006-03-21 12:43:56 +01:00
|
|
|
else
|
|
|
|
wLastChar = ' ';
|
|
|
|
|
2009-08-13 14:44:27 +02:00
|
|
|
cursor.nOffset++;
|
2013-01-31 14:48:00 +01:00
|
|
|
if (cursor.nOffset == cursor.pRun->member.run.len)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_NextRun(&cursor.pPara, &cursor.pRun);
|
|
|
|
cursor.nOffset = 0;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
|
|
|
else /* Backward search */
|
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
/* If possible, find the character after where the search ends */
|
|
|
|
if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
|
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
|
2013-01-30 16:10:20 +01:00
|
|
|
wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_MoveCursorChars(editor, &cursor, -1);
|
|
|
|
} else {
|
|
|
|
ME_CursorFromCharOfs(editor, nMax, &cursor);
|
2006-03-21 12:43:56 +01:00
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:27 +02:00
|
|
|
while (cursor.pRun && ME_GetCursorOfs(&cursor) - nLen >= nMin)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_DisplayItem *pCurItem = cursor.pRun;
|
|
|
|
ME_DisplayItem *pCurPara = cursor.pPara;
|
|
|
|
int nCurEnd = cursor.nOffset;
|
2005-08-23 11:32:55 +02:00
|
|
|
int nMatched = 0;
|
2009-02-02 07:32:36 +01:00
|
|
|
|
|
|
|
if (nCurEnd == 0)
|
2005-08-23 11:32:55 +02:00
|
|
|
{
|
2009-08-12 15:06:00 +02:00
|
|
|
ME_PrevRun(&pCurPara, &pCurItem);
|
2013-01-31 14:48:00 +01:00
|
|
|
nCurEnd = pCurItem->member.run.len + nMatched;
|
2006-03-21 12:43:56 +01:00
|
|
|
}
|
2009-02-02 07:32:36 +01:00
|
|
|
|
2013-01-30 16:10:20 +01:00
|
|
|
while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 ),
|
|
|
|
text[nLen - nMatched - 1], (flags & FR_MATCHCASE) ))
|
2006-03-21 12:43:56 +01:00
|
|
|
{
|
|
|
|
if ((flags & FR_WHOLEWORD) && isalnumW(wLastChar))
|
|
|
|
break;
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nMatched++;
|
|
|
|
if (nMatched == nLen)
|
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
ME_DisplayItem *pPrevItem = pCurItem;
|
|
|
|
int nPrevEnd = nCurEnd;
|
|
|
|
WCHAR wPrevChar;
|
2009-08-13 14:44:27 +02:00
|
|
|
int nStart;
|
2006-03-21 12:43:56 +01:00
|
|
|
|
|
|
|
/* Check to see if previous character is a whitespace */
|
|
|
|
if (flags & FR_WHOLEWORD)
|
|
|
|
{
|
|
|
|
if (nPrevEnd - nMatched == 0)
|
|
|
|
{
|
|
|
|
pPrevItem = ME_FindItemBack(pCurItem, diRun);
|
|
|
|
if (pPrevItem)
|
2013-01-31 14:48:00 +01:00
|
|
|
nPrevEnd = pPrevItem->member.run.len + nMatched;
|
2006-03-21 12:43:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pPrevItem)
|
2013-01-30 16:10:20 +01:00
|
|
|
wPrevChar = *get_text( &pPrevItem->member.run, nPrevEnd - nMatched - 1 );
|
2006-03-21 12:43:56 +01:00
|
|
|
else
|
|
|
|
wPrevChar = ' ';
|
|
|
|
|
|
|
|
if (isalnumW(wPrevChar))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:06:00 +02:00
|
|
|
nStart = pCurPara->member.para.nCharOfs
|
2009-02-02 07:32:36 +01:00
|
|
|
+ pCurItem->member.run.nCharOfs + nCurEnd - nMatched;
|
2005-08-23 11:32:55 +02:00
|
|
|
if (chrgText)
|
|
|
|
{
|
|
|
|
chrgText->cpMin = nStart;
|
|
|
|
chrgText->cpMax = nStart + nLen;
|
|
|
|
}
|
|
|
|
TRACE("found at %d-%d\n", nStart, nStart + nLen);
|
|
|
|
return nStart;
|
|
|
|
}
|
|
|
|
if (nCurEnd - nMatched == 0)
|
|
|
|
{
|
2009-08-12 15:06:00 +02:00
|
|
|
ME_PrevRun(&pCurPara, &pCurItem);
|
2006-02-24 13:49:05 +01:00
|
|
|
/* Don't care about pCurItem becoming NULL here; it's already taken
|
|
|
|
* care of in the exterior loop condition */
|
2013-01-31 14:48:00 +01:00
|
|
|
nCurEnd = pCurItem->member.run.len + nMatched;
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 12:43:56 +01:00
|
|
|
if (pCurItem)
|
2013-01-30 16:10:20 +01:00
|
|
|
wLastChar = *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 );
|
2006-03-21 12:43:56 +01:00
|
|
|
else
|
|
|
|
wLastChar = ' ';
|
|
|
|
|
2009-08-13 14:44:27 +02:00
|
|
|
cursor.nOffset--;
|
|
|
|
if (cursor.nOffset < 0)
|
2005-08-23 11:32:55 +02:00
|
|
|
{
|
2009-08-13 14:44:27 +02:00
|
|
|
ME_PrevRun(&cursor.pPara, &cursor.pRun);
|
2013-01-31 14:48:00 +01:00
|
|
|
cursor.nOffset = cursor.pRun->member.run.len;
|
2005-08-23 11:32:55 +02:00
|
|
|
}
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
}
|
2005-08-23 11:32:55 +02:00
|
|
|
TRACE("not found\n");
|
2006-02-15 13:37:31 +01:00
|
|
|
if (chrgText)
|
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
2005-07-06 12:32:59 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-16 09:43:24 +01:00
|
|
|
static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
|
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
int nChars;
|
|
|
|
ME_Cursor start;
|
2008-12-16 09:43:24 +01:00
|
|
|
|
2009-07-30 06:54:13 +02:00
|
|
|
if (!ex->cb || !pText) return 0;
|
|
|
|
|
2008-12-16 09:43:24 +01:00
|
|
|
if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
|
|
|
|
FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
|
|
|
|
|
|
|
|
if (ex->flags & GT_SELECTION)
|
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
int from, to;
|
|
|
|
int nStartCur = ME_GetSelectionOfs(editor, &from, &to);
|
|
|
|
start = editor->pCursors[nStartCur];
|
|
|
|
nChars = to - from;
|
2008-12-16 09:43:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(editor, &start);
|
2009-08-12 15:05:51 +02:00
|
|
|
nChars = INT_MAX;
|
2008-12-16 09:43:24 +01:00
|
|
|
}
|
|
|
|
if (ex->codepage == 1200)
|
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
return ME_GetTextW(editor, (LPWSTR)pText, ex->cb / sizeof(WCHAR) - 1,
|
|
|
|
&start, nChars, ex->flags & GT_USECRLF);
|
2008-12-16 09:43:24 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* potentially each char may be a CR, why calculate the exact value with O(N) when
|
|
|
|
we can just take a bigger buffer? :)
|
|
|
|
The above assumption still holds with CR/LF counters, since CR->CRLF expansion
|
|
|
|
occurs only in richedit 2.0 mode, in which line breaks have only one CR
|
|
|
|
*/
|
|
|
|
int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
|
2009-08-12 15:05:51 +02:00
|
|
|
DWORD buflen;
|
2008-12-16 09:43:24 +01:00
|
|
|
LPWSTR buffer;
|
|
|
|
LRESULT rc;
|
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
buflen = min(crlfmul * nChars, ex->cb - 1);
|
|
|
|
buffer = heap_alloc((buflen + 1) * sizeof(WCHAR));
|
2008-12-16 09:43:24 +01:00
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
nChars = ME_GetTextW(editor, buffer, buflen, &start, nChars, ex->flags & GT_USECRLF);
|
|
|
|
rc = WideCharToMultiByte(ex->codepage, 0, buffer, nChars + 1,
|
2008-12-16 09:43:24 +01:00
|
|
|
(LPSTR)pText, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
|
|
|
|
if (rc) rc--; /* do not count 0 terminator */
|
|
|
|
|
|
|
|
heap_free(buffer);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-23 05:14:33 +01:00
|
|
|
static int ME_GetTextRange(ME_TextEditor *editor, WCHAR *strText,
|
2009-08-12 15:06:18 +02:00
|
|
|
const ME_Cursor *start, int nLen, BOOL unicode)
|
2008-12-16 09:43:13 +01:00
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
if (!strText) return 0;
|
2009-03-23 05:14:33 +01:00
|
|
|
if (unicode) {
|
2009-08-12 15:06:18 +02:00
|
|
|
return ME_GetTextW(editor, strText, INT_MAX, start, nLen, 0);
|
2009-03-23 05:14:33 +01:00
|
|
|
} else {
|
2009-08-12 15:05:51 +02:00
|
|
|
int nChars;
|
2008-12-16 09:43:13 +01:00
|
|
|
WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
|
2009-08-12 15:05:51 +02:00
|
|
|
if (!p) return 0;
|
2009-08-12 15:06:18 +02:00
|
|
|
nChars = ME_GetTextW(editor, p, nLen, start, nLen, 0);
|
2009-03-23 05:14:33 +01:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)strText,
|
|
|
|
nLen+1, NULL, NULL);
|
2008-12-16 09:43:13 +01:00
|
|
|
FREE_OBJ(p);
|
|
|
|
return nChars;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-22 02:43:47 +02:00
|
|
|
typedef struct tagME_GlobalDestStruct
|
|
|
|
{
|
|
|
|
HGLOBAL hData;
|
|
|
|
int nLength;
|
|
|
|
} ME_GlobalDestStruct;
|
|
|
|
|
|
|
|
static DWORD CALLBACK ME_ReadFromHGLOBALUnicode(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
|
|
|
|
{
|
|
|
|
ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
|
|
|
|
int i;
|
|
|
|
WORD *pSrc, *pDest;
|
|
|
|
|
|
|
|
cb = cb >> 1;
|
|
|
|
pDest = (WORD *)lpBuff;
|
2008-11-03 22:36:03 +01:00
|
|
|
pSrc = GlobalLock(pData->hData);
|
2008-10-22 02:43:47 +02:00
|
|
|
for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
|
|
|
|
pDest[i] = pSrc[pData->nLength+i];
|
|
|
|
}
|
|
|
|
pData->nLength += i;
|
|
|
|
*pcb = 2*i;
|
|
|
|
GlobalUnlock(pData->hData);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD CALLBACK ME_ReadFromHGLOBALRTF(DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
|
|
|
|
{
|
|
|
|
ME_GlobalDestStruct *pData = (ME_GlobalDestStruct *)dwCookie;
|
|
|
|
int i;
|
|
|
|
BYTE *pSrc, *pDest;
|
|
|
|
|
|
|
|
pDest = lpBuff;
|
2008-11-03 22:36:03 +01:00
|
|
|
pSrc = GlobalLock(pData->hData);
|
2008-10-22 02:43:47 +02:00
|
|
|
for (i = 0; i<cb && pSrc[pData->nLength+i]; i++) {
|
|
|
|
pDest[i] = pSrc[pData->nLength+i];
|
|
|
|
}
|
|
|
|
pData->nLength += i;
|
|
|
|
*pcb = i;
|
|
|
|
GlobalUnlock(pData->hData);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ME_Paste(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
DWORD dwFormat = 0;
|
|
|
|
EDITSTREAM es;
|
|
|
|
ME_GlobalDestStruct gds;
|
|
|
|
UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
|
|
|
|
UINT cf = 0;
|
|
|
|
|
|
|
|
if (IsClipboardFormatAvailable(nRTFFormat))
|
|
|
|
cf = nRTFFormat, dwFormat = SF_RTF;
|
|
|
|
else if (IsClipboardFormatAvailable(CF_UNICODETEXT))
|
|
|
|
cf = CF_UNICODETEXT, dwFormat = SF_TEXT|SF_UNICODE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!OpenClipboard(editor->hWnd))
|
|
|
|
return FALSE;
|
|
|
|
gds.hData = GetClipboardData(cf);
|
|
|
|
gds.nLength = 0;
|
2008-12-22 00:09:17 +01:00
|
|
|
es.dwCookie = (DWORD_PTR)&gds;
|
2008-10-22 02:43:47 +02:00
|
|
|
es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
|
|
|
|
ME_StreamIn(editor, dwFormat|SFF_SELECTION, &es, FALSE);
|
|
|
|
|
|
|
|
CloseClipboard();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:05 +02:00
|
|
|
static BOOL ME_Copy(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
|
2008-10-22 02:43:47 +02:00
|
|
|
{
|
|
|
|
LPDATAOBJECT dataObj = NULL;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if (editor->cPasswordMask)
|
|
|
|
return FALSE; /* Copying or Cutting masked text isn't allowed */
|
|
|
|
|
|
|
|
if(editor->lpOleCallback)
|
2009-08-13 14:44:05 +02:00
|
|
|
{
|
|
|
|
CHARRANGE range;
|
|
|
|
range.cpMin = ME_GetCursorOfs(start);
|
|
|
|
range.cpMax = range.cpMin + nChars;
|
|
|
|
hr = IRichEditOleCallback_GetClipboardData(editor->lpOleCallback, &range, RECO_COPY, &dataObj);
|
|
|
|
}
|
2008-10-22 02:43:47 +02:00
|
|
|
if(FAILED(hr) || !dataObj)
|
2009-08-13 14:44:05 +02:00
|
|
|
hr = ME_GetDataObject(editor, start, nChars, &dataObj);
|
2008-10-22 02:43:47 +02:00
|
|
|
if(SUCCEEDED(hr)) {
|
|
|
|
hr = OleSetClipboard(dataObj);
|
|
|
|
IDataObject_Release(dataObj);
|
|
|
|
}
|
|
|
|
return SUCCEEDED(hr) != 0;
|
|
|
|
}
|
|
|
|
|
2008-01-01 22:03:22 +01:00
|
|
|
/* helper to send a msg filter notification */
|
|
|
|
static BOOL
|
|
|
|
ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM* wParam, LPARAM* lParam)
|
|
|
|
{
|
|
|
|
MSGFILTER msgf;
|
|
|
|
|
2009-09-30 16:46:37 +02:00
|
|
|
if (!editor->hWnd || !editor->hwndParent) return FALSE;
|
2009-03-05 23:06:47 +01:00
|
|
|
msgf.nmhdr.hwndFrom = editor->hWnd;
|
|
|
|
msgf.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
|
2008-01-01 22:03:22 +01:00
|
|
|
msgf.nmhdr.code = EN_MSGFILTER;
|
|
|
|
msgf.msg = msg;
|
|
|
|
msgf.wParam = *wParam;
|
|
|
|
msgf.lParam = *lParam;
|
2009-09-30 16:46:37 +02:00
|
|
|
if (SendMessageW(editor->hwndParent, WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
|
2008-01-01 22:03:22 +01:00
|
|
|
return FALSE;
|
|
|
|
*wParam = msgf.wParam;
|
|
|
|
*lParam = msgf.lParam;
|
|
|
|
msgf.wParam = *wParam;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-07-06 12:32:59 +02:00
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
|
|
|
|
{
|
2009-02-07 19:20:38 +01:00
|
|
|
ME_DisplayItem *startPara, *endPara;
|
|
|
|
ME_DisplayItem *prev_para;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_Cursor *from, *to;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_Cursor start;
|
|
|
|
int nChars;
|
2009-01-12 22:48:01 +01:00
|
|
|
|
2009-03-09 08:01:00 +01:00
|
|
|
if (!editor->AutoURLDetect_bEnable) return;
|
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
|
|
|
|
/* Find paragraph previous to the one that contains start cursor */
|
2009-08-12 15:05:46 +02:00
|
|
|
startPara = from->pPara;
|
2009-02-07 19:20:38 +01:00
|
|
|
prev_para = startPara->member.para.prev_para;
|
|
|
|
if (prev_para->type == diParagraph) startPara = prev_para;
|
2009-01-12 22:48:01 +01:00
|
|
|
|
|
|
|
/* Find paragraph that contains end cursor */
|
2009-08-12 15:05:46 +02:00
|
|
|
endPara = to->pPara->member.para.next_para;
|
2009-01-12 22:48:01 +01:00
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
start.pPara = startPara;
|
|
|
|
start.pRun = ME_FindItemFwd(startPara, diRun);
|
|
|
|
start.nOffset = 0;
|
|
|
|
nChars = endPara->member.para.nCharOfs - startPara->member.para.nCharOfs;
|
|
|
|
|
|
|
|
ME_UpdateLinkAttribute(editor, &start, nChars);
|
2009-01-12 22:48:01 +01:00
|
|
|
}
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
static BOOL
|
|
|
|
ME_KeyDown(ME_TextEditor *editor, WORD nKey)
|
|
|
|
{
|
|
|
|
BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
|
|
|
|
BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
|
2008-07-07 17:03:53 +02:00
|
|
|
|
2009-01-21 16:10:04 +01:00
|
|
|
if (editor->bMouseCaptured)
|
|
|
|
return FALSE;
|
2008-07-07 17:03:53 +02:00
|
|
|
if (nKey != VK_SHIFT && nKey != VK_CONTROL && nKey != VK_MENU)
|
|
|
|
editor->nSelectionType = stPosition;
|
|
|
|
|
2006-01-10 20:23:41 +01:00
|
|
|
switch (nKey)
|
|
|
|
{
|
|
|
|
case VK_LEFT:
|
|
|
|
case VK_RIGHT:
|
|
|
|
case VK_HOME:
|
|
|
|
case VK_END:
|
2008-07-04 21:30:51 +02:00
|
|
|
editor->nUDArrowX = -1;
|
|
|
|
/* fall through */
|
|
|
|
case VK_UP:
|
|
|
|
case VK_DOWN:
|
2006-01-10 20:23:41 +01:00
|
|
|
case VK_PRIOR:
|
|
|
|
case VK_NEXT:
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
|
2006-01-12 11:54:57 +01:00
|
|
|
ME_ArrowKey(editor, nKey, shift_is_down, ctrl_is_down);
|
2006-01-10 20:23:41 +01:00
|
|
|
return TRUE;
|
|
|
|
case VK_BACK:
|
|
|
|
case VK_DELETE:
|
2008-07-04 21:30:51 +02:00
|
|
|
editor->nUDArrowX = -1;
|
2006-01-10 20:23:41 +01:00
|
|
|
/* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_READONLY)
|
2006-01-10 20:23:41 +01:00
|
|
|
return FALSE;
|
|
|
|
if (ME_IsSelection(editor))
|
2008-06-25 16:29:19 +02:00
|
|
|
{
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_DeleteSelection(editor);
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
}
|
|
|
|
else if (nKey == VK_DELETE)
|
|
|
|
{
|
|
|
|
/* Delete stops group typing.
|
|
|
|
* (See MSDN remarks on EM_STOPGROUPTYPING message) */
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_DeleteTextAtCursor(editor, 1, 1);
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
}
|
|
|
|
else if (ME_ArrowKey(editor, VK_LEFT, FALSE, FALSE))
|
|
|
|
{
|
2008-08-07 18:31:41 +02:00
|
|
|
BOOL bDeletionSucceeded;
|
|
|
|
/* Backspace can be grouped for a single undo */
|
|
|
|
ME_ContinueCoalescingTransaction(editor);
|
|
|
|
bDeletionSucceeded = ME_DeleteTextAtCursor(editor, 1, 1);
|
|
|
|
if (!bDeletionSucceeded && !editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
/* Deletion was prevented so the cursor is moved back to where it was.
|
|
|
|
* (e.g. this happens when trying to delete cell boundaries)
|
|
|
|
*/
|
|
|
|
ME_ArrowKey(editor, VK_RIGHT, FALSE, FALSE);
|
|
|
|
}
|
|
|
|
ME_CommitCoalescingUndo(editor);
|
2008-06-25 16:29:19 +02:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
else
|
|
|
|
return TRUE;
|
2008-09-11 18:45:36 +02:00
|
|
|
ME_MoveCursorFromTableRowStartParagraph(editor);
|
2008-06-18 18:05:52 +02:00
|
|
|
ME_UpdateSelectionLinkAttribute(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_SendRequestResize(editor, FALSE);
|
|
|
|
return TRUE;
|
2009-01-11 08:59:09 +01:00
|
|
|
case VK_RETURN:
|
2009-10-04 21:48:44 +02:00
|
|
|
if (editor->bDialogMode)
|
|
|
|
{
|
|
|
|
if (ctrl_is_down)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!(editor->styleFlags & ES_WANTRETURN))
|
|
|
|
{
|
|
|
|
if (editor->hwndParent)
|
|
|
|
{
|
|
|
|
DWORD dw;
|
|
|
|
dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0);
|
|
|
|
if (HIWORD(dw) == DC_HASDEFID)
|
|
|
|
{
|
|
|
|
HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw));
|
|
|
|
if (hwDefCtrl)
|
|
|
|
{
|
2009-12-27 14:39:17 +01:00
|
|
|
SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE);
|
2009-10-04 21:48:44 +02:00
|
|
|
PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_MULTILINE)
|
2009-01-11 08:59:09 +01:00
|
|
|
{
|
|
|
|
ME_Cursor cursor = editor->pCursors[0];
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = cursor.pPara;
|
2009-01-11 08:59:09 +01:00
|
|
|
int from, to;
|
|
|
|
const WCHAR endl = '\r';
|
2012-01-19 22:35:56 +01:00
|
|
|
const WCHAR endlv10[] = {'\r','\n'};
|
2009-01-11 08:59:09 +01:00
|
|
|
ME_Style *style;
|
|
|
|
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_READONLY) {
|
2009-01-11 08:59:09 +01:00
|
|
|
MessageBeep(MB_ICONERROR);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &from, &to);
|
2009-01-11 08:59:09 +01:00
|
|
|
if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
|
|
|
|
{
|
|
|
|
if (!editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWEND) {
|
|
|
|
/* Add a new table row after this row. */
|
|
|
|
para = ME_AppendTableRow(editor, para);
|
|
|
|
para = para->member.para.next_para;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitUndo(editor);
|
2009-01-11 08:59:09 +01:00
|
|
|
ME_CheckTablesForCorruption(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2009-01-11 08:59:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-02-09 18:01:35 +01:00
|
|
|
else if (para == editor->pCursors[1].pPara &&
|
2009-01-11 08:59:09 +01:00
|
|
|
cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 &&
|
|
|
|
para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART &&
|
|
|
|
!para->member.para.prev_para->member.para.nCharOfs)
|
|
|
|
{
|
|
|
|
/* Insert a newline before the table. */
|
|
|
|
para = para->member.para.prev_para;
|
|
|
|
para->member.para.nFlags &= ~MEPF_ROWSTART;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
ME_InsertTextFromCursor(editor, 0, &endl, 1,
|
|
|
|
editor->pCursors[0].pRun->member.run.style);
|
|
|
|
para = editor->pBuffer->pFirst->member.para.next_para;
|
|
|
|
ME_SetDefaultParaFormat(para->member.para.pFmt);
|
|
|
|
para->member.para.nFlags = MEPF_REWRAP;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART;
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitCoalescingUndo(editor);
|
2009-01-11 08:59:09 +01:00
|
|
|
ME_CheckTablesForCorruption(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2009-01-11 08:59:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - 3.0 */
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = cursor.pPara;
|
2009-01-11 08:59:09 +01:00
|
|
|
if (ME_IsInTable(para))
|
|
|
|
{
|
|
|
|
if (cursor.pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
{
|
|
|
|
if (from == to) {
|
|
|
|
ME_ContinueCoalescingTransaction(editor);
|
|
|
|
para = ME_AppendTableRow(editor, para);
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitCoalescingUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2009-01-11 08:59:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ME_ContinueCoalescingTransaction(editor);
|
|
|
|
if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
|
|
|
|
!ME_IsInTable(para->member.para.prev_para))
|
|
|
|
{
|
|
|
|
/* Insert newline before table */
|
|
|
|
cursor.pRun = ME_FindItemBack(para, diRun);
|
2009-02-09 18:01:35 +01:00
|
|
|
if (cursor.pRun) {
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = cursor.pRun;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para->member.para.prev_para;
|
|
|
|
}
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
ME_InsertTextFromCursor(editor, 0, &endl, 1,
|
|
|
|
editor->pCursors[0].pRun->member.run.style);
|
|
|
|
} else {
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
para = ME_AppendTableRow(editor, para);
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2009-01-11 08:59:09 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
}
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitCoalescingUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2009-01-11 08:59:09 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
style = ME_GetInsertStyle(editor, 0);
|
|
|
|
ME_SaveTempStyle(editor);
|
|
|
|
ME_ContinueCoalescingTransaction(editor);
|
|
|
|
if (shift_is_down)
|
|
|
|
ME_InsertEndRowFromCursor(editor, 0);
|
|
|
|
else
|
2012-01-19 22:35:56 +01:00
|
|
|
if (!editor->bEmulateVersion10)
|
|
|
|
ME_InsertTextFromCursor(editor, 0, &endl, 1, style);
|
|
|
|
else
|
|
|
|
ME_InsertTextFromCursor(editor, 0, endlv10, 2, style);
|
2009-01-11 08:59:09 +01:00
|
|
|
ME_ReleaseStyle(style);
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitCoalescingUndo(editor);
|
2009-01-11 08:59:09 +01:00
|
|
|
SetCursor(NULL);
|
|
|
|
|
2009-03-09 08:01:00 +01:00
|
|
|
ME_UpdateSelectionLinkAttribute(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2009-01-11 08:59:09 +01:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2009-10-04 21:50:50 +02:00
|
|
|
case VK_ESCAPE:
|
|
|
|
if (editor->bDialogMode && editor->hwndParent)
|
|
|
|
PostMessageW(editor->hwndParent, WM_CLOSE, 0, 0);
|
|
|
|
return TRUE;
|
2009-10-04 22:16:08 +02:00
|
|
|
case VK_TAB:
|
|
|
|
if (editor->bDialogMode && editor->hwndParent)
|
|
|
|
SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, shift_is_down, 0);
|
|
|
|
return TRUE;
|
2008-10-22 02:43:47 +02:00
|
|
|
case 'A':
|
|
|
|
if (ctrl_is_down)
|
|
|
|
{
|
|
|
|
ME_SetSelection(editor, 0, -1);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'V':
|
|
|
|
if (ctrl_is_down)
|
|
|
|
return ME_Paste(editor);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
case 'X':
|
|
|
|
if (ctrl_is_down)
|
|
|
|
{
|
|
|
|
BOOL result;
|
2009-08-13 14:44:05 +02:00
|
|
|
int nOfs, nChars;
|
|
|
|
int nStartCur = ME_GetSelectionOfs(editor, &nOfs, &nChars);
|
|
|
|
ME_Cursor *selStart = &editor->pCursors[nStartCur];
|
2008-10-22 02:43:47 +02:00
|
|
|
|
2009-08-13 14:44:05 +02:00
|
|
|
nChars -= nOfs;
|
|
|
|
result = ME_Copy(editor, selStart, nChars);
|
2008-10-22 02:43:47 +02:00
|
|
|
if (result && nKey == 'X')
|
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, selStart, nChars, FALSE);
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, TRUE);
|
2008-10-22 02:43:47 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Z':
|
|
|
|
if (ctrl_is_down)
|
|
|
|
{
|
|
|
|
ME_Undo(editor);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'Y':
|
|
|
|
if (ctrl_is_down)
|
|
|
|
{
|
|
|
|
ME_Redo(editor);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
default:
|
2008-07-04 21:30:51 +02:00
|
|
|
if (nKey != VK_SHIFT && nKey != VK_CONTROL && nKey && nKey != VK_MENU)
|
|
|
|
editor->nUDArrowX = -1;
|
2006-01-10 20:23:41 +01:00
|
|
|
if (ctrl_is_down)
|
|
|
|
{
|
|
|
|
if (nKey == 'W')
|
|
|
|
{
|
|
|
|
CHARFORMAT2W chf;
|
|
|
|
char buf[2048];
|
2006-08-02 22:54:03 +02:00
|
|
|
chf.cbSize = sizeof(chf);
|
2006-01-10 20:23:41 +01:00
|
|
|
|
|
|
|
ME_GetSelectionCharFormat(editor, &chf);
|
|
|
|
ME_DumpStyleToBuf(&chf, buf);
|
|
|
|
MessageBoxA(NULL, buf, "Style dump", MB_OK);
|
|
|
|
}
|
|
|
|
if (nKey == 'Q')
|
|
|
|
{
|
|
|
|
ME_CheckCharOffsets(editor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-16 09:43:33 +01:00
|
|
|
static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode,
|
|
|
|
LPARAM flags, BOOL unicode)
|
|
|
|
{
|
|
|
|
WCHAR wstr;
|
|
|
|
|
2009-01-21 16:10:04 +01:00
|
|
|
if (editor->bMouseCaptured)
|
|
|
|
return 0;
|
|
|
|
|
2008-12-16 09:43:33 +01:00
|
|
|
if (unicode)
|
|
|
|
wstr = (WCHAR)charCode;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHAR charA = charCode;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, &charA, 1, &wstr, 1);
|
|
|
|
}
|
|
|
|
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_READONLY) {
|
2008-12-16 09:43:33 +01:00
|
|
|
MessageBeep(MB_ICONERROR);
|
|
|
|
return 0; /* FIXME really 0 ? */
|
|
|
|
}
|
|
|
|
|
2009-01-11 08:59:09 +01:00
|
|
|
if ((unsigned)wstr >= ' ' || wstr == '\t')
|
|
|
|
{
|
2008-12-16 09:43:33 +01:00
|
|
|
ME_Cursor cursor = editor->pCursors[0];
|
2009-02-09 18:01:35 +01:00
|
|
|
ME_DisplayItem *para = cursor.pPara;
|
2008-12-16 09:43:33 +01:00
|
|
|
int from, to;
|
|
|
|
BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &from, &to);
|
2009-01-11 08:59:09 +01:00
|
|
|
if (wstr == '\t' &&
|
2008-12-16 09:43:33 +01:00
|
|
|
/* v4.1 allows tabs to be inserted with ctrl key down */
|
2009-01-11 08:59:09 +01:00
|
|
|
!(ctrl_is_down && !editor->bEmulateVersion10))
|
2008-12-16 09:43:33 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *para;
|
|
|
|
BOOL bSelectedRow = FALSE;
|
|
|
|
|
2009-02-09 18:01:35 +01:00
|
|
|
para = cursor.pPara;
|
2008-12-16 09:43:33 +01:00
|
|
|
if (ME_IsSelection(editor) &&
|
|
|
|
cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
|
2009-08-12 15:05:42 +02:00
|
|
|
to == ME_GetCursorOfs(&editor->pCursors[0]) &&
|
2008-12-16 09:43:33 +01:00
|
|
|
para->member.para.prev_para->type == diParagraph)
|
|
|
|
{
|
|
|
|
para = para->member.para.prev_para;
|
|
|
|
bSelectedRow = TRUE;
|
|
|
|
}
|
|
|
|
if (ME_IsInTable(para))
|
|
|
|
{
|
|
|
|
ME_TabPressedInTable(editor, bSelectedRow);
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (!editor->bEmulateVersion10) { /* v4.1 */
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWEND) {
|
2009-01-11 08:59:09 +01:00
|
|
|
if (from == to) {
|
2008-12-16 09:43:33 +01:00
|
|
|
para = para->member.para.next_para;
|
|
|
|
if (para->member.para.nFlags & MEPF_ROWSTART)
|
|
|
|
para = para->member.para.next_para;
|
2009-02-09 18:01:35 +01:00
|
|
|
editor->pCursors[0].pPara = para;
|
2008-12-16 09:43:33 +01:00
|
|
|
editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
|
|
|
|
editor->pCursors[0].nOffset = 0;
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { /* v1.0 - 3.0 */
|
2009-01-11 08:59:09 +01:00
|
|
|
if (ME_IsInTable(cursor.pRun) &&
|
|
|
|
cursor.pRun->member.run.nFlags & MERF_ENDPARA &&
|
|
|
|
from == to)
|
2008-12-16 09:43:33 +01:00
|
|
|
{
|
2009-01-11 08:59:09 +01:00
|
|
|
/* Text should not be inserted at the end of the table. */
|
|
|
|
MessageBeep(-1);
|
|
|
|
return 0;
|
2008-12-16 09:43:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
|
|
|
|
/* WM_CHAR is restricted to nTextLimit */
|
|
|
|
if(editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
|
|
|
|
{
|
|
|
|
ME_Style *style = ME_GetInsertStyle(editor, 0);
|
|
|
|
ME_SaveTempStyle(editor);
|
|
|
|
ME_ContinueCoalescingTransaction(editor);
|
2009-01-11 08:59:09 +01:00
|
|
|
ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
|
2008-12-16 09:43:33 +01:00
|
|
|
ME_ReleaseStyle(style);
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitCoalescingUndo(editor);
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost, NULL, FALSE);
|
2008-12-16 09:43:33 +01:00
|
|
|
}
|
|
|
|
|
2009-03-09 08:01:00 +01:00
|
|
|
ME_UpdateSelectionLinkAttribute(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2008-12-16 09:43:33 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-07 17:04:02 +02:00
|
|
|
/* Process the message and calculate the new click count.
|
|
|
|
*
|
|
|
|
* returns: The click count if it is mouse down event, else returns 0. */
|
2008-12-15 10:32:01 +01:00
|
|
|
static int ME_CalculateClickCount(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
2008-07-07 17:04:02 +02:00
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
static int clickNum = 0;
|
|
|
|
if (msg < WM_MOUSEFIRST || msg > WM_MOUSELAST)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((msg == WM_LBUTTONDBLCLK) ||
|
|
|
|
(msg == WM_RBUTTONDBLCLK) ||
|
|
|
|
(msg == WM_MBUTTONDBLCLK) ||
|
|
|
|
(msg == WM_XBUTTONDBLCLK))
|
|
|
|
{
|
|
|
|
msg -= (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((msg == WM_LBUTTONDOWN) ||
|
|
|
|
(msg == WM_RBUTTONDOWN) ||
|
|
|
|
(msg == WM_MBUTTONDOWN) ||
|
|
|
|
(msg == WM_XBUTTONDOWN))
|
|
|
|
{
|
|
|
|
static MSG prevClickMsg;
|
|
|
|
MSG clickMsg;
|
2008-12-15 10:32:01 +01:00
|
|
|
/* Compare the editor instead of the hwnd so that the this
|
|
|
|
* can still be done for windowless richedit controls. */
|
|
|
|
clickMsg.hwnd = (HWND)editor;
|
2008-07-07 17:04:02 +02:00
|
|
|
clickMsg.message = msg;
|
|
|
|
clickMsg.wParam = wParam;
|
|
|
|
clickMsg.lParam = lParam;
|
|
|
|
clickMsg.time = GetMessageTime();
|
2008-07-08 14:05:26 +02:00
|
|
|
clickMsg.pt.x = (short)LOWORD(lParam);
|
|
|
|
clickMsg.pt.y = (short)HIWORD(lParam);
|
2008-07-07 17:04:02 +02:00
|
|
|
if ((clickNum != 0) &&
|
|
|
|
(clickMsg.message == prevClickMsg.message) &&
|
|
|
|
(clickMsg.hwnd == prevClickMsg.hwnd) &&
|
|
|
|
(clickMsg.wParam == prevClickMsg.wParam) &&
|
|
|
|
(clickMsg.time - prevClickMsg.time < GetDoubleClickTime()) &&
|
|
|
|
(abs(clickMsg.pt.x - prevClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
|
|
|
|
(abs(clickMsg.pt.y - prevClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
|
|
|
|
{
|
|
|
|
clickNum++;
|
|
|
|
} else {
|
|
|
|
clickNum = 1;
|
|
|
|
}
|
|
|
|
prevClickMsg = clickMsg;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return clickNum;
|
|
|
|
}
|
|
|
|
|
2008-07-09 15:36:00 +02:00
|
|
|
static BOOL ME_SetCursor(ME_TextEditor *editor)
|
2007-12-14 21:29:37 +01:00
|
|
|
{
|
2009-08-13 14:44:09 +02:00
|
|
|
ME_Cursor cursor;
|
2008-07-09 15:36:00 +02:00
|
|
|
POINT pt;
|
2008-07-09 15:36:12 +02:00
|
|
|
BOOL isExact;
|
2008-10-06 10:28:37 +02:00
|
|
|
SCROLLBARINFO sbi;
|
2008-07-09 15:36:00 +02:00
|
|
|
DWORD messagePos = GetMessagePos();
|
|
|
|
pt.x = (short)LOWORD(messagePos);
|
|
|
|
pt.y = (short)HIWORD(messagePos);
|
2008-10-06 10:28:37 +02:00
|
|
|
|
2009-01-20 07:41:36 +01:00
|
|
|
if (editor->hWnd)
|
2008-10-06 10:28:37 +02:00
|
|
|
{
|
2009-01-20 07:41:36 +01:00
|
|
|
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))
|
|
|
|
{
|
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-10-06 10:28:37 +02:00
|
|
|
}
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxScreenToClient(editor->texthost, &pt);
|
2008-10-06 10:28:37 +02:00
|
|
|
|
2009-01-11 08:59:20 +01:00
|
|
|
if (editor->nSelectionType == stLine && editor->bMouseCaptured) {
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
|
2008-12-18 07:56:49 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (!editor->bEmulateVersion10 /* v4.1 */ &&
|
|
|
|
pt.y < editor->rcFormat.top &&
|
|
|
|
pt.x < editor->rcFormat.left)
|
|
|
|
{
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
|
2008-12-18 07:56:49 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (pt.y < editor->rcFormat.top || pt.y > editor->rcFormat.bottom)
|
|
|
|
{
|
|
|
|
if (editor->bEmulateVersion10) /* v1.0 - 3.0 */
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_ARROW), FALSE);
|
2008-12-18 07:56:49 +01:00
|
|
|
else /* v4.1 */
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
|
2008-12-18 07:56:49 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (pt.x < editor->rcFormat.left)
|
2008-03-16 21:48:22 +01:00
|
|
|
{
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost, hLeft, FALSE);
|
2008-03-16 21:48:22 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-08-13 14:44:09 +02:00
|
|
|
ME_CharFromPos(editor, pt.x, pt.y, &cursor, &isExact);
|
2008-07-09 15:36:12 +02:00
|
|
|
if (isExact)
|
|
|
|
{
|
2009-03-09 08:01:00 +01:00
|
|
|
ME_Run *run;
|
|
|
|
|
|
|
|
run = &cursor.pRun->member.run;
|
|
|
|
if (run->style->fmt.dwMask & CFM_LINK &&
|
|
|
|
run->style->fmt.dwEffects & CFE_LINK)
|
2008-07-09 15:36:12 +02:00
|
|
|
{
|
2009-03-09 08:01:00 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_HAND),
|
|
|
|
FALSE);
|
|
|
|
return TRUE;
|
2008-07-09 15:36:12 +02:00
|
|
|
}
|
2009-03-09 08:01:00 +01:00
|
|
|
|
2008-07-09 15:36:12 +02:00
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
{
|
|
|
|
int selStart, selEnd;
|
2009-08-13 14:44:09 +02:00
|
|
|
int offset = ME_GetCursorOfs(&cursor);
|
2009-08-12 15:05:46 +02:00
|
|
|
|
|
|
|
ME_GetSelectionOfs(editor, &selStart, &selEnd);
|
2008-07-09 15:36:12 +02:00
|
|
|
if (selStart <= offset && selEnd >= offset) {
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_ARROW),
|
|
|
|
FALSE);
|
2008-07-09 15:36:12 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCursor(editor->texthost,
|
|
|
|
LoadCursorW(NULL, (WCHAR*)IDC_IBEAM), TRUE);
|
2008-07-09 15:36:12 +02:00
|
|
|
return TRUE;
|
2007-12-14 21:29:37 +01:00
|
|
|
}
|
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
static void ME_SetDefaultFormatRect(ME_TextEditor *editor)
|
|
|
|
{
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &editor->rcFormat);
|
2009-01-20 07:41:36 +01:00
|
|
|
editor->rcFormat.top += editor->exStyleFlags & WS_EX_CLIENTEDGE ? 1 : 0;
|
2008-12-18 07:56:49 +01:00
|
|
|
editor->rcFormat.left += 1 + editor->selofs;
|
|
|
|
editor->rcFormat.right -= 1;
|
|
|
|
}
|
|
|
|
|
2006-09-03 05:08:46 +02:00
|
|
|
static BOOL ME_ShowContextMenu(ME_TextEditor *editor, int x, int y)
|
2006-02-02 13:18:20 +01:00
|
|
|
{
|
|
|
|
CHARRANGE selrange;
|
|
|
|
HMENU menu;
|
|
|
|
int seltype = 0;
|
2009-01-20 07:41:36 +01:00
|
|
|
if(!editor->lpOleCallback || !editor->hWnd)
|
2006-09-03 05:08:46 +02:00
|
|
|
return FALSE;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &selrange.cpMin, &selrange.cpMax);
|
2006-02-02 13:18:20 +01:00
|
|
|
if(selrange.cpMin == selrange.cpMax)
|
|
|
|
seltype |= SEL_EMPTY;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: Handle objects */
|
|
|
|
seltype |= SEL_TEXT;
|
|
|
|
if(selrange.cpMax-selrange.cpMin > 1)
|
|
|
|
seltype |= SEL_MULTICHAR;
|
|
|
|
}
|
|
|
|
if(SUCCEEDED(IRichEditOleCallback_GetContextMenu(editor->lpOleCallback, seltype, NULL, &selrange, &menu)))
|
|
|
|
{
|
2009-09-30 16:46:37 +02:00
|
|
|
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, editor->hwndParent, NULL);
|
2006-02-02 13:18:20 +01:00
|
|
|
DestroyMenu(menu);
|
|
|
|
}
|
2006-09-03 05:08:46 +02:00
|
|
|
return TRUE;
|
2006-02-02 13:18:20 +01:00
|
|
|
}
|
2006-01-10 20:23:41 +01:00
|
|
|
|
2009-01-20 07:41:25 +01:00
|
|
|
ME_TextEditor *ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
|
2009-01-11 08:59:31 +01:00
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
|
2005-03-08 17:26:23 +01:00
|
|
|
int i;
|
2009-01-20 07:41:25 +01:00
|
|
|
DWORD props;
|
|
|
|
LONG selbarwidth;
|
|
|
|
|
|
|
|
ed->hWnd = NULL;
|
2009-09-30 16:46:37 +02:00
|
|
|
ed->hwndParent = NULL;
|
2009-12-16 11:34:01 +01:00
|
|
|
ed->sizeWindow.cx = ed->sizeWindow.cy = 0;
|
2009-01-20 07:41:25 +01:00
|
|
|
ed->texthost = texthost;
|
2009-01-11 08:59:31 +01:00
|
|
|
ed->bEmulateVersion10 = bEmulateVersion10;
|
2009-12-15 12:52:02 +01:00
|
|
|
ed->styleFlags = 0;
|
2009-01-20 07:41:25 +01:00
|
|
|
ITextHost_TxGetPropertyBits(texthost,
|
|
|
|
(TXTBIT_RICHTEXT|TXTBIT_MULTILINE|
|
|
|
|
TXTBIT_READONLY|TXTBIT_USEPASSWORD|
|
|
|
|
TXTBIT_HIDESELECTION|TXTBIT_SAVESELECTION|
|
|
|
|
TXTBIT_AUTOWORDSEL|TXTBIT_VERTICAL|
|
|
|
|
TXTBIT_WORDWRAP|TXTBIT_DISABLEDRAG),
|
|
|
|
&props);
|
|
|
|
ITextHost_TxGetScrollBars(texthost, &ed->styleFlags);
|
|
|
|
ed->styleFlags &= (WS_VSCROLL|WS_HSCROLL|ES_AUTOVSCROLL|
|
|
|
|
ES_AUTOHSCROLL|ES_DISABLENOSCROLL);
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->pBuffer = ME_MakeText();
|
2008-01-01 22:05:46 +01:00
|
|
|
ed->nZoomNumerator = ed->nZoomDenominator = 0;
|
2009-07-31 17:37:13 +02:00
|
|
|
ed->nAvailWidth = 0; /* wrap to client area */
|
2008-01-01 22:05:46 +01:00
|
|
|
ME_MakeFirstParagraph(ed);
|
2008-07-07 17:03:53 +02:00
|
|
|
/* The four cursors are for:
|
|
|
|
* 0 - The position where the caret is shown
|
|
|
|
* 1 - The anchored end of the selection (for normal selection)
|
|
|
|
* 2 & 3 - The anchored start and end respectively for word, line,
|
|
|
|
* or paragraph selection.
|
|
|
|
*/
|
2007-12-14 21:29:37 +01:00
|
|
|
ed->nCursors = 4;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
|
2009-08-12 15:06:05 +02:00
|
|
|
ME_SetCursorToStart(ed, &ed->pCursors[0]);
|
2009-02-09 18:01:35 +01:00
|
|
|
ed->pCursors[1] = ed->pCursors[0];
|
2008-01-04 21:12:09 +01:00
|
|
|
ed->pCursors[2] = ed->pCursors[0];
|
|
|
|
ed->pCursors[3] = ed->pCursors[1];
|
2005-03-09 19:43:18 +01:00
|
|
|
ed->nLastTotalLength = ed->nTotalLength = 0;
|
2009-01-14 19:24:02 +01:00
|
|
|
ed->nLastTotalWidth = ed->nTotalWidth = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->nUDArrowX = -1;
|
|
|
|
ed->rgbBackColor = -1;
|
2005-11-03 12:33:24 +01:00
|
|
|
ed->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->bCaretAtEnd = FALSE;
|
|
|
|
ed->nEventMask = 0;
|
|
|
|
ed->nModifyStep = 0;
|
2006-08-09 21:33:42 +02:00
|
|
|
ed->nTextLimit = TEXT_LIMIT_DEFAULT;
|
2013-01-29 14:41:48 +01:00
|
|
|
list_init( &ed->undo_stack );
|
|
|
|
list_init( &ed->redo_stack );
|
2006-05-15 20:00:15 +02:00
|
|
|
ed->nUndoStackSize = 0;
|
|
|
|
ed->nUndoLimit = STACK_SIZE_DEFAULT;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->nUndoMode = umAddToUndo;
|
|
|
|
ed->nParagraphs = 1;
|
2005-03-09 12:48:59 +01:00
|
|
|
ed->nLastSelStart = ed->nLastSelEnd = 0;
|
2009-08-12 15:06:05 +02:00
|
|
|
ed->pLastSelStartPara = ed->pLastSelEndPara = ed->pCursors[0].pPara;
|
2006-02-24 22:31:25 +01:00
|
|
|
ed->bHideSelection = FALSE;
|
2006-01-12 11:54:57 +01:00
|
|
|
ed->pfnWordBreak = NULL;
|
2006-02-01 13:05:40 +01:00
|
|
|
ed->lpOleCallback = NULL;
|
2009-02-02 07:32:29 +01:00
|
|
|
ed->mode = TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
|
2009-01-20 07:41:25 +01:00
|
|
|
ed->mode |= (props & TXTBIT_RICHTEXT) ? TM_RICHTEXT : TM_PLAINTEXT;
|
2006-11-10 07:40:58 +01:00
|
|
|
ed->AutoURLDetect_bEnable = FALSE;
|
2007-06-05 14:56:55 +02:00
|
|
|
ed->bHaveFocus = FALSE;
|
2009-10-04 20:41:48 +02:00
|
|
|
ed->bDialogMode = FALSE;
|
2009-01-11 08:59:20 +01:00
|
|
|
ed->bMouseCaptured = FALSE;
|
2005-03-08 17:26:23 +01:00
|
|
|
for (i=0; i<HFONT_CACHE_SIZE; i++)
|
|
|
|
{
|
|
|
|
ed->pFontCache[i].nRefs = 0;
|
|
|
|
ed->pFontCache[i].nAge = 0;
|
|
|
|
ed->pFontCache[i].hFont = NULL;
|
|
|
|
}
|
2009-01-15 20:46:25 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CheckCharOffsets(ed);
|
2008-12-18 07:56:49 +01:00
|
|
|
ed->bDefaultFormatRect = TRUE;
|
2009-01-20 07:41:25 +01:00
|
|
|
ITextHost_TxGetSelectionBarWidth(ed->texthost, &selbarwidth);
|
2009-02-25 22:18:36 +01:00
|
|
|
if (selbarwidth) {
|
|
|
|
/* FIXME: Convert selbarwidth from HIMETRIC to pixels */
|
|
|
|
ed->selofs = SELECTIONBAR_WIDTH;
|
|
|
|
ed->styleFlags |= ES_SELECTIONBAR;
|
|
|
|
} else {
|
|
|
|
ed->selofs = 0;
|
|
|
|
}
|
2008-07-07 17:03:53 +02:00
|
|
|
ed->nSelectionType = stPosition;
|
2007-12-14 21:29:37 +01:00
|
|
|
|
2009-01-20 07:41:25 +01:00
|
|
|
ed->cPasswordMask = 0;
|
|
|
|
if (props & TXTBIT_USEPASSWORD)
|
|
|
|
ITextHost_TxGetPasswordChar(texthost, &ed->cPasswordMask);
|
|
|
|
|
|
|
|
if (props & TXTBIT_AUTOWORDSEL)
|
|
|
|
ed->styleFlags |= ECO_AUTOWORDSELECTION;
|
2009-02-24 08:56:18 +01:00
|
|
|
if (props & TXTBIT_MULTILINE) {
|
2009-01-20 07:41:25 +01:00
|
|
|
ed->styleFlags |= ES_MULTILINE;
|
2009-02-24 08:56:18 +01:00
|
|
|
ed->bWordWrap = (props & TXTBIT_WORDWRAP) != 0;
|
|
|
|
} else {
|
|
|
|
ed->bWordWrap = FALSE;
|
|
|
|
}
|
2009-01-20 07:41:25 +01:00
|
|
|
if (props & TXTBIT_READONLY)
|
|
|
|
ed->styleFlags |= ES_READONLY;
|
|
|
|
if (!(props & TXTBIT_HIDESELECTION))
|
|
|
|
ed->styleFlags |= ES_NOHIDESEL;
|
|
|
|
if (props & TXTBIT_SAVESELECTION)
|
|
|
|
ed->styleFlags |= ES_SAVESEL;
|
|
|
|
if (props & TXTBIT_VERTICAL)
|
|
|
|
ed->styleFlags |= ES_VERTICAL;
|
|
|
|
if (props & TXTBIT_DISABLEDRAG)
|
|
|
|
ed->styleFlags |= ES_NOOLEDRAGDROP;
|
2009-01-15 20:46:25 +01:00
|
|
|
|
2008-04-27 20:08:55 +02:00
|
|
|
ed->notified_cr.cpMin = ed->notified_cr.cpMax = 0;
|
|
|
|
|
2009-01-14 19:24:02 +01:00
|
|
|
/* Default scrollbar information */
|
2008-07-20 18:29:19 +02:00
|
|
|
ed->vert_si.cbSize = sizeof(SCROLLINFO);
|
|
|
|
ed->vert_si.nMin = 0;
|
|
|
|
ed->vert_si.nMax = 0;
|
|
|
|
ed->vert_si.nPage = 0;
|
|
|
|
ed->vert_si.nPos = 0;
|
|
|
|
|
2009-01-14 19:24:02 +01:00
|
|
|
ed->horz_si.cbSize = sizeof(SCROLLINFO);
|
|
|
|
ed->horz_si.nMin = 0;
|
|
|
|
ed->horz_si.nMax = 0;
|
|
|
|
ed->horz_si.nPage = 0;
|
|
|
|
ed->horz_si.nPos = 0;
|
|
|
|
|
2008-07-30 16:09:14 +02:00
|
|
|
OleInitialize(NULL);
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
return ed;
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
static void ME_DestroyEditor(ME_TextEditor *editor)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
ME_DisplayItem *pFirst = editor->pBuffer->pFirst;
|
|
|
|
ME_DisplayItem *p = pFirst, *pNext = NULL;
|
2005-03-08 17:26:23 +01:00
|
|
|
int i;
|
2006-11-05 06:25:42 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
ME_EmptyUndoStack(editor);
|
|
|
|
while(p) {
|
|
|
|
pNext = p->next;
|
2006-11-05 06:25:42 +01:00
|
|
|
ME_DestroyDisplayItem(p);
|
2005-03-05 12:19:14 +01:00
|
|
|
p = pNext;
|
|
|
|
}
|
|
|
|
ME_ReleaseStyle(editor->pBuffer->pDefaultStyle);
|
2005-03-08 17:26:23 +01:00
|
|
|
for (i=0; i<HFONT_CACHE_SIZE; i++)
|
|
|
|
{
|
|
|
|
if (editor->pFontCache[i].hFont)
|
|
|
|
DeleteObject(editor->pFontCache[i].hFont);
|
|
|
|
}
|
2008-01-01 22:04:10 +01:00
|
|
|
if (editor->rgbBackColor != -1)
|
|
|
|
DeleteObject(editor->hbrBackground);
|
2006-02-01 13:05:40 +01:00
|
|
|
if(editor->lpOleCallback)
|
2012-08-01 12:56:19 +02:00
|
|
|
IRichEditOleCallback_Release(editor->lpOleCallback);
|
|
|
|
ITextHost_Release(editor->texthost);
|
2008-07-30 16:09:14 +02:00
|
|
|
OleUninitialize();
|
2005-11-03 12:33:24 +01:00
|
|
|
|
2006-11-05 06:25:42 +01:00
|
|
|
FREE_OBJ(editor->pBuffer);
|
|
|
|
FREE_OBJ(editor->pCursors);
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
FREE_OBJ(editor);
|
|
|
|
}
|
|
|
|
|
2005-05-16 10:51:19 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
TRACE("\n");
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
|
|
|
me_heap = HeapCreate (0, 0x10000, 0);
|
2007-03-21 11:26:19 +01:00
|
|
|
if (!ME_RegisterEditorClass(hinstDLL)) return FALSE;
|
2007-12-14 21:29:37 +01:00
|
|
|
hLeft = LoadCursorW(hinstDLL, MAKEINTRESOURCEW(OCR_REVERSE));
|
2006-11-02 09:25:35 +01:00
|
|
|
LookupInit();
|
2005-05-16 10:51:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2009-08-10 16:53:36 +02:00
|
|
|
UnregisterClassW(RICHEDIT_CLASS20W, 0);
|
|
|
|
UnregisterClassW(MSFTEDIT_CLASS, 0);
|
|
|
|
UnregisterClassA(RICHEDIT_CLASS20A, 0);
|
2005-05-16 10:51:19 +02:00
|
|
|
UnregisterClassA("RichEdit50A", 0);
|
2005-12-05 12:48:45 +01:00
|
|
|
if (ME_ListBoxRegistered)
|
2007-03-21 11:26:19 +01:00
|
|
|
UnregisterClassW(REListBox20W, 0);
|
2005-12-05 12:48:45 +01:00
|
|
|
if (ME_ComboBoxRegistered)
|
2007-03-21 11:26:19 +01:00
|
|
|
UnregisterClassW(REComboBox20W, 0);
|
2006-11-02 09:25:35 +01:00
|
|
|
LookupCleanup();
|
2005-05-16 10:51:19 +02:00
|
|
|
HeapDestroy (me_heap);
|
|
|
|
me_heap = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-21 13:58:24 +02:00
|
|
|
static const char * const edit_messages[] = {
|
|
|
|
"EM_GETSEL",
|
|
|
|
"EM_SETSEL",
|
|
|
|
"EM_GETRECT",
|
|
|
|
"EM_SETRECT",
|
|
|
|
"EM_SETRECTNP",
|
|
|
|
"EM_SCROLL",
|
|
|
|
"EM_LINESCROLL",
|
|
|
|
"EM_SCROLLCARET",
|
|
|
|
"EM_GETMODIFY",
|
|
|
|
"EM_SETMODIFY",
|
|
|
|
"EM_GETLINECOUNT",
|
|
|
|
"EM_LINEINDEX",
|
|
|
|
"EM_SETHANDLE",
|
|
|
|
"EM_GETHANDLE",
|
|
|
|
"EM_GETTHUMB",
|
|
|
|
"EM_UNKNOWN_BF",
|
|
|
|
"EM_UNKNOWN_C0",
|
|
|
|
"EM_LINELENGTH",
|
|
|
|
"EM_REPLACESEL",
|
|
|
|
"EM_UNKNOWN_C3",
|
|
|
|
"EM_GETLINE",
|
|
|
|
"EM_LIMITTEXT",
|
|
|
|
"EM_CANUNDO",
|
|
|
|
"EM_UNDO",
|
|
|
|
"EM_FMTLINES",
|
|
|
|
"EM_LINEFROMCHAR",
|
|
|
|
"EM_UNKNOWN_CA",
|
|
|
|
"EM_SETTABSTOPS",
|
|
|
|
"EM_SETPASSWORDCHAR",
|
|
|
|
"EM_EMPTYUNDOBUFFER",
|
|
|
|
"EM_GETFIRSTVISIBLELINE",
|
|
|
|
"EM_SETREADONLY",
|
|
|
|
"EM_SETWORDBREAKPROC",
|
|
|
|
"EM_GETWORDBREAKPROC",
|
|
|
|
"EM_GETPASSWORDCHAR",
|
|
|
|
"EM_SETMARGINS",
|
|
|
|
"EM_GETMARGINS",
|
|
|
|
"EM_GETLIMITTEXT",
|
|
|
|
"EM_POSFROMCHAR",
|
2008-11-16 03:01:48 +01:00
|
|
|
"EM_CHARFROMPOS",
|
|
|
|
"EM_SETIMESTATUS",
|
|
|
|
"EM_GETIMESTATUS"
|
2005-07-21 13:58:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const richedit_messages[] = {
|
|
|
|
"EM_CANPASTE",
|
|
|
|
"EM_DISPLAYBAND",
|
|
|
|
"EM_EXGETSEL",
|
|
|
|
"EM_EXLIMITTEXT",
|
|
|
|
"EM_EXLINEFROMCHAR",
|
|
|
|
"EM_EXSETSEL",
|
|
|
|
"EM_FINDTEXT",
|
|
|
|
"EM_FORMATRANGE",
|
|
|
|
"EM_GETCHARFORMAT",
|
|
|
|
"EM_GETEVENTMASK",
|
|
|
|
"EM_GETOLEINTERFACE",
|
|
|
|
"EM_GETPARAFORMAT",
|
|
|
|
"EM_GETSELTEXT",
|
2006-02-24 22:31:25 +01:00
|
|
|
"EM_HIDESELECTION",
|
2005-07-21 13:58:24 +02:00
|
|
|
"EM_PASTESPECIAL",
|
|
|
|
"EM_REQUESTRESIZE",
|
|
|
|
"EM_SELECTIONTYPE",
|
|
|
|
"EM_SETBKGNDCOLOR",
|
|
|
|
"EM_SETCHARFORMAT",
|
|
|
|
"EM_SETEVENTMASK",
|
|
|
|
"EM_SETOLECALLBACK",
|
|
|
|
"EM_SETPARAFORMAT",
|
|
|
|
"EM_SETTARGETDEVICE",
|
|
|
|
"EM_STREAMIN",
|
|
|
|
"EM_STREAMOUT",
|
|
|
|
"EM_GETTEXTRANGE",
|
|
|
|
"EM_FINDWORDBREAK",
|
|
|
|
"EM_SETOPTIONS",
|
|
|
|
"EM_GETOPTIONS",
|
|
|
|
"EM_FINDTEXTEX",
|
|
|
|
"EM_GETWORDBREAKPROCEX",
|
|
|
|
"EM_SETWORDBREAKPROCEX",
|
|
|
|
"EM_SETUNDOLIMIT",
|
|
|
|
"EM_UNKNOWN_USER_83",
|
|
|
|
"EM_REDO",
|
|
|
|
"EM_CANREDO",
|
|
|
|
"EM_GETUNDONAME",
|
|
|
|
"EM_GETREDONAME",
|
|
|
|
"EM_STOPGROUPTYPING",
|
|
|
|
"EM_SETTEXTMODE",
|
|
|
|
"EM_GETTEXTMODE",
|
|
|
|
"EM_AUTOURLDETECT",
|
|
|
|
"EM_GETAUTOURLDETECT",
|
|
|
|
"EM_SETPALETTE",
|
|
|
|
"EM_GETTEXTEX",
|
|
|
|
"EM_GETTEXTLENGTHEX",
|
|
|
|
"EM_SHOWSCROLLBAR",
|
|
|
|
"EM_SETTEXTEX",
|
|
|
|
"EM_UNKNOWN_USER_98",
|
|
|
|
"EM_UNKNOWN_USER_99",
|
|
|
|
"EM_SETPUNCTUATION",
|
|
|
|
"EM_GETPUNCTUATION",
|
|
|
|
"EM_SETWORDWRAPMODE",
|
|
|
|
"EM_GETWORDWRAPMODE",
|
|
|
|
"EM_SETIMECOLOR",
|
|
|
|
"EM_GETIMECOLOR",
|
|
|
|
"EM_SETIMEOPTIONS",
|
|
|
|
"EM_GETIMEOPTIONS",
|
|
|
|
"EM_CONVPOSITION",
|
|
|
|
"EM_UNKNOWN_USER_109",
|
|
|
|
"EM_UNKNOWN_USER_110",
|
|
|
|
"EM_UNKNOWN_USER_111",
|
|
|
|
"EM_UNKNOWN_USER_112",
|
|
|
|
"EM_UNKNOWN_USER_113",
|
|
|
|
"EM_UNKNOWN_USER_114",
|
|
|
|
"EM_UNKNOWN_USER_115",
|
|
|
|
"EM_UNKNOWN_USER_116",
|
|
|
|
"EM_UNKNOWN_USER_117",
|
|
|
|
"EM_UNKNOWN_USER_118",
|
|
|
|
"EM_UNKNOWN_USER_119",
|
|
|
|
"EM_SETLANGOPTIONS",
|
|
|
|
"EM_GETLANGOPTIONS",
|
|
|
|
"EM_GETIMECOMPMODE",
|
|
|
|
"EM_FINDTEXTW",
|
|
|
|
"EM_FINDTEXTEXW",
|
|
|
|
"EM_RECONVERSION",
|
|
|
|
"EM_SETIMEMODEBIAS",
|
|
|
|
"EM_GETIMEMODEBIAS"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_msg_name(UINT msg)
|
|
|
|
{
|
2006-06-22 00:01:31 +02:00
|
|
|
if (msg >= EM_GETSEL && msg <= EM_CHARFROMPOS)
|
2005-07-21 13:58:24 +02:00
|
|
|
return edit_messages[msg - EM_GETSEL];
|
|
|
|
if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
|
|
|
|
return richedit_messages[msg - EM_CANPASTE];
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-05-26 00:48:48 +02:00
|
|
|
static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
|
2007-03-22 12:09:43 +01:00
|
|
|
{
|
2009-01-12 22:48:01 +01:00
|
|
|
int x,y;
|
|
|
|
BOOL isExact;
|
2009-08-13 14:44:09 +02:00
|
|
|
ME_Cursor cursor; /* The start of the clicked text. */
|
2006-08-02 22:54:03 +02:00
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
ENLINK info;
|
|
|
|
x = (short)LOWORD(lParam);
|
|
|
|
y = (short)HIWORD(lParam);
|
2009-08-13 14:44:09 +02:00
|
|
|
ME_CharFromPos(editor, x, y, &cursor, &isExact);
|
2009-01-12 22:48:01 +01:00
|
|
|
if (!isExact) return;
|
2008-12-19 16:57:28 +01:00
|
|
|
|
2009-08-13 14:44:09 +02:00
|
|
|
if (cursor.pRun->member.run.style->fmt.dwMask & CFM_LINK &&
|
|
|
|
cursor.pRun->member.run.style->fmt.dwEffects & CFE_LINK)
|
2009-01-12 22:48:01 +01:00
|
|
|
{ /* The clicked run has CFE_LINK set */
|
2009-09-28 09:44:19 +02:00
|
|
|
info.nmhdr.hwndFrom = NULL;
|
|
|
|
info.nmhdr.idFrom = 0;
|
2009-01-12 22:48:01 +01:00
|
|
|
info.nmhdr.code = EN_LINK;
|
|
|
|
info.msg = msg;
|
|
|
|
info.wParam = wParam;
|
|
|
|
info.lParam = lParam;
|
2009-08-13 14:44:09 +02:00
|
|
|
cursor.nOffset = 0;
|
|
|
|
info.chrg.cpMin = ME_GetCursorOfs(&cursor);
|
2013-01-31 14:48:00 +01:00
|
|
|
info.chrg.cpMax = info.chrg.cpMin + cursor.pRun->member.run.len;
|
2009-09-28 09:44:19 +02:00
|
|
|
ITextHost_TxNotify(editor->texthost, info.nmhdr.code, &info);
|
2009-01-12 22:48:01 +01:00
|
|
|
}
|
2008-12-19 16:57:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define UNSUPPORTED_MSG(e) \
|
|
|
|
case e: \
|
|
|
|
FIXME(#e ": stub\n"); \
|
|
|
|
*phresult = S_FALSE; \
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Handle messages for windowless and windoweded richedit controls.
|
|
|
|
*
|
|
|
|
* The LRESULT that is returned is a return value for window procs,
|
|
|
|
* and the phresult parameter is the COM return code needed by the
|
|
|
|
* text services interface. */
|
2009-01-20 07:41:40 +01:00
|
|
|
LRESULT ME_HandleMessage(ME_TextEditor *editor, UINT msg, WPARAM wParam,
|
2008-12-19 16:57:28 +01:00
|
|
|
LPARAM lParam, BOOL unicode, HRESULT* phresult)
|
|
|
|
{
|
|
|
|
*phresult = S_OK;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
switch(msg) {
|
2008-12-19 16:57:28 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_DISPLAYBAND)
|
|
|
|
UNSUPPORTED_MSG(EM_FINDWORDBREAK)
|
|
|
|
UNSUPPORTED_MSG(EM_FMTLINES)
|
|
|
|
UNSUPPORTED_MSG(EM_FORMATRANGE)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_GETBIDIOPTIONS)
|
|
|
|
UNSUPPORTED_MSG(EM_GETEDITSTYLE)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_GETIMECOMPMODE)
|
2008-11-16 03:01:48 +01:00
|
|
|
UNSUPPORTED_MSG(EM_GETIMESTATUS)
|
|
|
|
UNSUPPORTED_MSG(EM_SETIMESTATUS)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
|
|
|
|
UNSUPPORTED_MSG(EM_GETREDONAME)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_GETTYPOGRAPHYOPTIONS)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_GETUNDONAME)
|
|
|
|
UNSUPPORTED_MSG(EM_GETWORDBREAKPROCEX)
|
|
|
|
UNSUPPORTED_MSG(EM_PASTESPECIAL)
|
|
|
|
UNSUPPORTED_MSG(EM_SELECTIONTYPE)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_SETBIDIOPTIONS)
|
|
|
|
UNSUPPORTED_MSG(EM_SETEDITSTYLE)
|
|
|
|
UNSUPPORTED_MSG(EM_SETFONTSIZE)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_SETLANGOPTIONS)
|
2008-10-10 22:36:54 +02:00
|
|
|
UNSUPPORTED_MSG(EM_SETMARGINS)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_SETPALETTE)
|
|
|
|
UNSUPPORTED_MSG(EM_SETTABSTOPS)
|
|
|
|
UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
|
2008-07-23 13:55:46 +02:00
|
|
|
|
2005-03-07 18:15:33 +01:00
|
|
|
/* Messages specific to Richedit controls */
|
2008-07-23 13:55:46 +02:00
|
|
|
|
2005-03-07 18:15:33 +01:00
|
|
|
case EM_STREAMIN:
|
2008-04-24 17:00:29 +02:00
|
|
|
return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam, TRUE);
|
2005-03-14 22:41:16 +01:00
|
|
|
case EM_STREAMOUT:
|
|
|
|
return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_GETDLGCODE:
|
|
|
|
{
|
2009-01-08 06:44:11 +01:00
|
|
|
UINT code = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
|
2009-10-04 20:41:48 +02:00
|
|
|
if (lParam)
|
|
|
|
editor->bDialogMode = TRUE;
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_MULTILINE)
|
2009-01-08 06:44:11 +01:00
|
|
|
code |= DLGC_WANTMESSAGE;
|
2005-03-05 12:19:14 +01:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
case EM_EMPTYUNDOBUFFER:
|
|
|
|
ME_EmptyUndoStack(editor);
|
|
|
|
return 0;
|
|
|
|
case EM_GETSEL:
|
|
|
|
{
|
2005-06-20 13:42:38 +02:00
|
|
|
/* Note: wParam/lParam can be NULL */
|
|
|
|
UINT from, to;
|
|
|
|
PUINT pfrom = wParam ? (PUINT)wParam : &from;
|
|
|
|
PUINT pto = lParam ? (PUINT)lParam : &to;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, (int *)pfrom, (int *)pto);
|
2005-06-20 13:42:38 +02:00
|
|
|
if ((*pfrom|*pto) & 0xFFFF0000)
|
|
|
|
return -1;
|
|
|
|
return MAKELONG(*pfrom,*pto);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
case EM_EXGETSEL:
|
|
|
|
{
|
|
|
|
CHARRANGE *pRange = (CHARRANGE *)lParam;
|
2009-08-12 15:05:46 +02:00
|
|
|
ME_GetSelectionOfs(editor, &pRange->cpMin, &pRange->cpMax);
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("EM_EXGETSEL = (%d,%d)\n", pRange->cpMin, pRange->cpMax);
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2006-05-15 20:00:15 +02:00
|
|
|
case EM_SETUNDOLIMIT:
|
|
|
|
{
|
|
|
|
if ((int)wParam < 0)
|
|
|
|
editor->nUndoLimit = STACK_SIZE_DEFAULT;
|
|
|
|
else
|
|
|
|
editor->nUndoLimit = min(wParam, STACK_SIZE_MAX);
|
|
|
|
/* Setting a max stack size keeps wine from getting killed
|
|
|
|
for hogging memory. Windows allocates all this memory at once, so
|
2007-06-07 11:48:55 +02:00
|
|
|
no program would realistically set a value above our maximum. */
|
2006-05-15 20:00:15 +02:00
|
|
|
return editor->nUndoLimit;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_CANUNDO:
|
2013-01-29 14:41:48 +01:00
|
|
|
return !list_empty( &editor->undo_stack );
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_CANREDO:
|
2013-01-29 14:41:48 +01:00
|
|
|
return !list_empty( &editor->redo_stack );
|
2005-08-22 11:20:06 +02:00
|
|
|
case WM_UNDO: /* FIXME: actually not the same */
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_UNDO:
|
2008-06-25 16:29:19 +02:00
|
|
|
return ME_Undo(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_REDO:
|
2008-06-25 16:29:19 +02:00
|
|
|
return ME_Redo(editor);
|
2006-02-21 22:49:19 +01:00
|
|
|
case EM_GETOPTIONS:
|
|
|
|
{
|
|
|
|
/* these flags are equivalent to the ES_* counterparts */
|
|
|
|
DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
|
2008-12-18 07:56:49 +01:00
|
|
|
ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN | ECO_SELECTIONBAR;
|
2009-01-15 20:46:25 +01:00
|
|
|
DWORD settings = editor->styleFlags & mask;
|
2006-02-21 22:49:19 +01:00
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
case EM_SETOPTIONS:
|
|
|
|
{
|
2009-01-20 07:41:36 +01:00
|
|
|
/* these flags are equivalent to ES_* counterparts, except for
|
|
|
|
* ECO_AUTOWORDSELECTION that doesn't have an ES_* counterpart,
|
|
|
|
* but is still stored in editor->styleFlags. */
|
|
|
|
const DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
|
|
|
|
ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN |
|
|
|
|
ECO_SELECTIONBAR | ECO_AUTOWORDSELECTION;
|
2009-01-15 20:46:25 +01:00
|
|
|
DWORD settings = mask & editor->styleFlags;
|
2008-12-18 07:56:49 +01:00
|
|
|
DWORD oldSettings = settings;
|
|
|
|
DWORD changedSettings;
|
2006-02-21 22:49:19 +01:00
|
|
|
|
|
|
|
switch(wParam)
|
|
|
|
{
|
|
|
|
case ECOOP_SET:
|
|
|
|
settings = lParam;
|
|
|
|
break;
|
|
|
|
case ECOOP_OR:
|
|
|
|
settings |= lParam;
|
|
|
|
break;
|
|
|
|
case ECOOP_AND:
|
|
|
|
settings &= lParam;
|
|
|
|
break;
|
|
|
|
case ECOOP_XOR:
|
|
|
|
settings ^= lParam;
|
|
|
|
}
|
2008-12-18 07:56:49 +01:00
|
|
|
changedSettings = oldSettings ^ settings;
|
|
|
|
|
2009-02-25 22:18:36 +01:00
|
|
|
if (changedSettings) {
|
2009-01-15 20:46:25 +01:00
|
|
|
editor->styleFlags = (editor->styleFlags & ~mask) | (settings & mask);
|
|
|
|
|
2009-02-25 22:18:36 +01:00
|
|
|
if (changedSettings & ECO_SELECTIONBAR)
|
|
|
|
{
|
|
|
|
ITextHost_TxInvalidateRect(editor->texthost, &editor->rcFormat, TRUE);
|
|
|
|
if (settings & ECO_SELECTIONBAR) {
|
|
|
|
assert(!editor->selofs);
|
|
|
|
editor->selofs = SELECTIONBAR_WIDTH;
|
|
|
|
editor->rcFormat.left += editor->selofs;
|
|
|
|
} else {
|
|
|
|
editor->rcFormat.left -= editor->selofs;
|
|
|
|
editor->selofs = 0;
|
|
|
|
}
|
|
|
|
ME_RewrapRepaint(editor);
|
2008-12-18 07:56:49 +01:00
|
|
|
}
|
2007-12-14 21:29:37 +01:00
|
|
|
|
2009-02-25 22:18:36 +01:00
|
|
|
if (changedSettings & settings & ECO_VERTICAL)
|
|
|
|
FIXME("ECO_VERTICAL not implemented yet!\n");
|
|
|
|
if (changedSettings & settings & ECO_AUTOHSCROLL)
|
|
|
|
FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
|
|
|
|
if (changedSettings & settings & ECO_AUTOVSCROLL)
|
|
|
|
FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
|
|
|
|
if (changedSettings & settings & ECO_NOHIDESEL)
|
|
|
|
FIXME("ECO_NOHIDESEL not implemented yet!\n");
|
|
|
|
if (changedSettings & settings & ECO_WANTRETURN)
|
|
|
|
FIXME("ECO_WANTRETURN not implemented yet!\n");
|
|
|
|
if (changedSettings & settings & ECO_AUTOWORDSELECTION)
|
|
|
|
FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
|
|
|
|
}
|
2006-02-21 22:49:19 +01:00
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_SETSEL:
|
|
|
|
{
|
2006-01-26 13:27:28 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SetSelection(editor, wParam, lParam);
|
2006-01-26 13:27:28 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxShowCaret(editor->texthost, FALSE);
|
2008-07-07 17:04:06 +02:00
|
|
|
ME_ShowCaret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendSelChange(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-08-08 22:08:43 +02:00
|
|
|
case EM_SETSCROLLPOS:
|
|
|
|
{
|
|
|
|
POINT *point = (POINT *)lParam;
|
2009-01-14 19:24:02 +01:00
|
|
|
ME_ScrollAbs(editor, point->x, point->y);
|
2006-08-08 22:08:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-01 11:49:42 +01:00
|
|
|
case EM_AUTOURLDETECT:
|
|
|
|
{
|
2009-01-14 19:24:02 +01:00
|
|
|
if (wParam==1 || wParam ==0)
|
2006-03-01 11:49:42 +01:00
|
|
|
{
|
|
|
|
editor->AutoURLDetect_bEnable = (BOOL)wParam;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
case EM_GETAUTOURLDETECT:
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
return editor->AutoURLDetect_bEnable;
|
2006-03-01 11:49:42 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_EXSETSEL:
|
|
|
|
{
|
2006-12-04 20:54:24 +01:00
|
|
|
int end;
|
2006-08-27 18:26:34 +02:00
|
|
|
CHARRANGE range = *(CHARRANGE *)lParam;
|
|
|
|
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("EM_EXSETSEL (%d,%d)\n", range.cpMin, range.cpMax);
|
2006-08-27 18:26:34 +02:00
|
|
|
|
2006-01-26 13:27:28 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2006-12-04 20:54:24 +01:00
|
|
|
end = ME_SetSelection(editor, range.cpMin, range.cpMax);
|
2006-01-26 13:27:28 +01:00
|
|
|
ME_InvalidateSelection(editor);
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxShowCaret(editor->texthost, FALSE);
|
2008-07-07 17:04:06 +02:00
|
|
|
ME_ShowCaret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendSelChange(editor);
|
2006-12-04 00:58:12 +01:00
|
|
|
|
2006-12-04 20:54:24 +01:00
|
|
|
return end;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-08-08 22:08:43 +02:00
|
|
|
case EM_SHOWSCROLLBAR:
|
|
|
|
{
|
2009-01-28 07:35:06 +01:00
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case SB_HORZ:
|
|
|
|
flags = WS_HSCROLL;
|
|
|
|
break;
|
|
|
|
case SB_VERT:
|
|
|
|
flags = WS_VSCROLL;
|
|
|
|
break;
|
|
|
|
case SB_BOTH:
|
|
|
|
flags = WS_HSCROLL|WS_VSCROLL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-24 08:39:03 +01:00
|
|
|
if (lParam) {
|
2009-01-28 07:35:06 +01:00
|
|
|
editor->styleFlags |= flags;
|
2009-02-24 08:39:03 +01:00
|
|
|
if (flags & WS_HSCROLL)
|
|
|
|
ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ,
|
|
|
|
editor->nTotalWidth > editor->sizeWindow.cx);
|
|
|
|
if (flags & WS_VSCROLL)
|
|
|
|
ITextHost_TxShowScrollBar(editor->texthost, SB_VERT,
|
|
|
|
editor->nTotalLength > editor->sizeWindow.cy);
|
|
|
|
} else {
|
|
|
|
editor->styleFlags &= ~flags;
|
|
|
|
ITextHost_TxShowScrollBar(editor->texthost, wParam, FALSE);
|
|
|
|
}
|
2006-08-08 22:08:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-07-20 12:28:44 +02:00
|
|
|
case EM_SETTEXTEX:
|
|
|
|
{
|
2007-05-02 10:59:21 +02:00
|
|
|
LPWSTR wszText;
|
2005-07-20 12:28:44 +02:00
|
|
|
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
|
2009-01-17 02:38:24 +01:00
|
|
|
size_t len = 0;
|
2005-07-20 12:28:44 +02:00
|
|
|
int from, to;
|
|
|
|
ME_Style *style;
|
2009-01-17 02:38:24 +01:00
|
|
|
BOOL bRtf, bUnicode, bSelection;
|
2007-01-11 08:46:35 +01:00
|
|
|
int oldModify = editor->nModifyStep;
|
2007-05-02 10:59:21 +02:00
|
|
|
|
|
|
|
if (!pStruct) return 0;
|
|
|
|
|
2009-01-17 02:38:24 +01:00
|
|
|
/* If we detect ascii rtf at the start of the string,
|
|
|
|
* we know it isn't unicode. */
|
|
|
|
bRtf = (lParam && (!strncmp((char *)lParam, "{\\rtf", 5) ||
|
2009-07-11 05:54:34 +02:00
|
|
|
!strncmp((char *)lParam, "{\\urtf", 6)));
|
2009-01-17 02:38:24 +01:00
|
|
|
bUnicode = !bRtf && pStruct->codepage == 1200;
|
|
|
|
|
2007-05-02 10:59:21 +02:00
|
|
|
TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
|
2009-01-17 02:38:24 +01:00
|
|
|
bUnicode ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
|
2007-05-02 10:59:21 +02:00
|
|
|
pStruct->flags, pStruct->codepage);
|
|
|
|
|
2009-01-17 02:38:24 +01:00
|
|
|
bSelection = (pStruct->flags & ST_SELECTION) != 0;
|
|
|
|
if (bSelection) {
|
2009-08-13 14:44:18 +02:00
|
|
|
int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
|
2005-07-20 12:28:44 +02:00
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to - from, FALSE);
|
2009-01-17 02:38:24 +01:00
|
|
|
} else {
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor start;
|
|
|
|
ME_SetCursorToStart(editor, &start);
|
|
|
|
ME_InternalDeleteText(editor, &start, ME_GetTextLength(editor), FALSE);
|
2009-01-17 02:38:24 +01:00
|
|
|
style = editor->pBuffer->pDefaultStyle;
|
|
|
|
}
|
2008-05-04 22:20:31 +02:00
|
|
|
|
2009-01-17 02:38:24 +01:00
|
|
|
if (bRtf) {
|
|
|
|
ME_StreamInRTFString(editor, bSelection, (char *)lParam);
|
|
|
|
if (bSelection) {
|
2010-01-11 00:17:36 +01:00
|
|
|
/* FIXME: The length returned doesn't include the rtf control
|
2009-01-17 02:38:24 +01:00
|
|
|
* characters, only the actual text. */
|
|
|
|
len = lParam ? strlen((char *)lParam) : 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* FIXME: make use of pStruct->codepage in the to unicode translation */
|
|
|
|
wszText = lParam ? ME_ToUnicode(bUnicode, (void *)lParam) : NULL;
|
|
|
|
len = wszText ? lstrlenW(wszText) : 0;
|
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
|
2009-12-13 15:58:43 +01:00
|
|
|
ME_EndToUnicode(bUnicode, wszText);
|
2005-07-20 12:28:44 +02:00
|
|
|
}
|
2008-05-04 22:20:31 +02:00
|
|
|
|
2009-01-17 02:38:24 +01:00
|
|
|
if (bSelection) {
|
|
|
|
ME_ReleaseStyle(style);
|
2009-03-09 08:01:00 +01:00
|
|
|
ME_UpdateSelectionLinkAttribute(editor);
|
2009-01-17 02:38:24 +01:00
|
|
|
} else {
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_Cursor cursor;
|
2009-01-17 02:38:24 +01:00
|
|
|
len = 1;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_SetCursorToStart(editor, &cursor);
|
|
|
|
ME_UpdateLinkAttribute(editor, &cursor, INT_MAX);
|
2005-07-20 12:28:44 +02:00
|
|
|
}
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
if (!(pStruct->flags & ST_KEEPUNDO))
|
2007-01-11 08:46:35 +01:00
|
|
|
{
|
|
|
|
editor->nModifyStep = oldModify;
|
2005-07-20 12:28:44 +02:00
|
|
|
ME_EmptyUndoStack(editor);
|
2007-01-11 08:46:35 +01:00
|
|
|
}
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2005-07-20 12:28:44 +02:00
|
|
|
return len;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_SETBKGNDCOLOR:
|
|
|
|
{
|
2008-01-01 22:04:10 +01:00
|
|
|
LRESULT lColor;
|
|
|
|
if (editor->rgbBackColor != -1) {
|
2005-11-03 12:33:24 +01:00
|
|
|
DeleteObject(editor->hbrBackground);
|
2008-01-01 22:04:10 +01:00
|
|
|
lColor = editor->rgbBackColor;
|
|
|
|
}
|
2009-01-20 07:41:32 +01:00
|
|
|
else lColor = ITextHost_TxGetSysColor(editor->texthost, COLOR_WINDOW);
|
2008-01-01 22:04:10 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (wParam)
|
2005-11-03 12:33:24 +01:00
|
|
|
{
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->rgbBackColor = -1;
|
2005-11-03 12:33:24 +01:00
|
|
|
editor->hbrBackground = GetSysColorBrush(COLOR_WINDOW);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
2005-11-03 12:33:24 +01:00
|
|
|
{
|
2005-08-15 11:47:14 +02:00
|
|
|
editor->rgbBackColor = lParam;
|
2005-11-03 12:33:24 +01:00
|
|
|
editor->hbrBackground = CreateSolidBrush(editor->rgbBackColor);
|
|
|
|
}
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxInvalidateRect(editor->texthost, NULL, TRUE);
|
|
|
|
ITextHost_TxViewChange(editor->texthost, TRUE);
|
2005-03-05 12:19:14 +01:00
|
|
|
return lColor;
|
|
|
|
}
|
|
|
|
case EM_GETMODIFY:
|
2008-04-27 20:17:28 +02:00
|
|
|
return editor->nModifyStep == 0 ? 0 : -1;
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_SETMODIFY:
|
|
|
|
{
|
|
|
|
if (wParam)
|
2007-01-11 08:46:35 +01:00
|
|
|
editor->nModifyStep = 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
editor->nModifyStep = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_SETREADONLY:
|
|
|
|
{
|
2009-01-20 07:41:36 +01:00
|
|
|
if (wParam)
|
2009-01-15 20:46:25 +01:00
|
|
|
editor->styleFlags |= ES_READONLY;
|
2009-01-20 07:41:36 +01:00
|
|
|
else
|
2009-01-15 20:46:25 +01:00
|
|
|
editor->styleFlags &= ~ES_READONLY;
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_SETEVENTMASK:
|
2005-08-22 20:56:21 +02:00
|
|
|
{
|
|
|
|
DWORD nOldMask = editor->nEventMask;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
editor->nEventMask = lParam;
|
2005-08-22 20:56:21 +02:00
|
|
|
return nOldMask;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETEVENTMASK:
|
|
|
|
return editor->nEventMask;
|
|
|
|
case EM_SETCHARFORMAT:
|
|
|
|
{
|
|
|
|
CHARFORMAT2W buf, *p;
|
2005-03-17 11:23:40 +01:00
|
|
|
BOOL bRepaint = TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
|
2007-09-26 19:58:24 +02:00
|
|
|
if (p == NULL) return 0;
|
2010-07-29 20:05:58 +02:00
|
|
|
if (wParam & SCF_ALL) {
|
|
|
|
if (editor->mode & TM_PLAINTEXT) {
|
2007-09-26 22:50:45 +02:00
|
|
|
ME_SetDefaultCharFormat(editor, p);
|
2010-07-29 20:05:58 +02:00
|
|
|
} else {
|
2009-08-12 15:06:13 +02:00
|
|
|
ME_Cursor start;
|
|
|
|
ME_SetCursorToStart(editor, &start);
|
|
|
|
ME_SetCharFormat(editor, &start, NULL, p);
|
2008-04-27 20:17:28 +02:00
|
|
|
editor->nModifyStep = 1;
|
|
|
|
}
|
2010-07-29 20:05:58 +02:00
|
|
|
} else if (wParam & SCF_SELECTION) {
|
|
|
|
if (editor->mode & TM_PLAINTEXT)
|
|
|
|
return 0;
|
|
|
|
if (wParam & SCF_WORD) {
|
|
|
|
FIXME("EM_SETCHARFORMAT: word selection not supported\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-12 15:05:46 +02:00
|
|
|
bRepaint = ME_IsSelection(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SetSelectionCharFormat(editor, p);
|
2009-08-12 15:05:46 +02:00
|
|
|
if (bRepaint) editor->nModifyStep = 1;
|
2010-07-29 20:05:58 +02:00
|
|
|
} else { /* SCF_DEFAULT */
|
|
|
|
ME_SetDefaultCharFormat(editor, p);
|
2005-03-17 11:23:40 +01:00
|
|
|
}
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitUndo(editor);
|
2005-03-17 11:23:40 +01:00
|
|
|
if (bRepaint)
|
2009-01-05 19:14:41 +01:00
|
|
|
{
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
ME_UpdateScrollBar(editor);
|
|
|
|
ME_Repaint(editor);
|
|
|
|
}
|
2007-09-25 22:11:14 +02:00
|
|
|
return 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
case EM_GETCHARFORMAT:
|
|
|
|
{
|
2005-07-11 12:22:33 +02:00
|
|
|
CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
|
|
|
|
if (dst->cbSize != sizeof(CHARFORMATA) &&
|
|
|
|
dst->cbSize != sizeof(CHARFORMATW) &&
|
|
|
|
dst->cbSize != sizeof(CHARFORMAT2A) &&
|
|
|
|
dst->cbSize != sizeof(CHARFORMAT2W))
|
|
|
|
return 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
tmp.cbSize = sizeof(tmp);
|
|
|
|
if (!wParam)
|
|
|
|
ME_GetDefaultCharFormat(editor, &tmp);
|
|
|
|
else
|
|
|
|
ME_GetSelectionCharFormat(editor, &tmp);
|
2005-07-11 12:22:33 +02:00
|
|
|
ME_CopyToCFAny(dst, &tmp);
|
|
|
|
return tmp.dwMask;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
case EM_SETPARAFORMAT:
|
2008-08-13 05:15:15 +02:00
|
|
|
{
|
|
|
|
BOOL result = ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
|
2009-01-05 19:14:41 +01:00
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
ME_UpdateScrollBar(editor);
|
|
|
|
ME_Repaint(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
2008-08-13 05:15:15 +02:00
|
|
|
return result;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETPARAFORMAT:
|
|
|
|
ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
|
2008-08-13 05:15:15 +02:00
|
|
|
return ((PARAFORMAT2 *)lParam)->dwMask;
|
2005-10-03 13:03:48 +02:00
|
|
|
case EM_GETFIRSTVISIBLELINE:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *p = editor->pBuffer->pFirst;
|
2009-01-14 19:24:02 +01:00
|
|
|
int y = editor->vert_si.nPos;
|
2005-10-03 13:03:48 +02:00
|
|
|
int ypara = 0;
|
|
|
|
int count = 0;
|
|
|
|
int ystart, yend;
|
|
|
|
while(p) {
|
|
|
|
p = ME_FindItemFwd(p, diStartRowOrParagraphOrEnd);
|
|
|
|
if (p->type == diTextEnd)
|
|
|
|
break;
|
|
|
|
if (p->type == diParagraph) {
|
2008-08-07 18:31:41 +02:00
|
|
|
ypara = p->member.para.pt.y;
|
2005-10-03 13:03:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-07 18:31:41 +02:00
|
|
|
ystart = ypara + p->member.row.pt.y;
|
2005-10-03 13:03:48 +02:00
|
|
|
yend = ystart + p->member.row.nHeight;
|
|
|
|
if (y < yend) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2006-02-24 22:31:25 +01:00
|
|
|
case EM_HIDESELECTION:
|
|
|
|
{
|
|
|
|
editor->bHideSelection = (wParam != 0);
|
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-05-23 11:54:32 +02:00
|
|
|
case EM_LINESCROLL:
|
|
|
|
{
|
2009-02-24 08:38:57 +01:00
|
|
|
if (!(editor->styleFlags & ES_MULTILINE))
|
|
|
|
return FALSE;
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_ScrollDown(editor, lParam * 8); /* FIXME follow the original */
|
2009-02-24 08:38:57 +01:00
|
|
|
return TRUE;
|
2005-05-23 11:54:32 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CLEAR:
|
|
|
|
{
|
|
|
|
int from, to;
|
2009-08-13 14:44:18 +02:00
|
|
|
int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
|
|
|
|
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, TRUE);
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_REPLACESEL:
|
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
int from, to, nStartCursor;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_Style *style;
|
2007-09-07 00:42:49 +02:00
|
|
|
LPWSTR wszText = lParam ? ME_ToUnicode(unicode, (void *)lParam) : NULL;
|
|
|
|
size_t len = wszText ? lstrlenW(wszText) : 0;
|
2005-03-08 17:26:23 +01:00
|
|
|
TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
|
2006-11-05 06:26:47 +01:00
|
|
|
|
2009-08-13 14:44:18 +02:00
|
|
|
nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
|
2005-03-08 20:03:01 +01:00
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
|
|
|
|
ME_ReleaseStyle(style);
|
|
|
|
/* drop temporary style if line end */
|
2006-11-05 06:26:47 +01:00
|
|
|
/*
|
|
|
|
* FIXME question: does abc\n mean: put abc,
|
|
|
|
* clear temp style, put \n? (would require a change)
|
|
|
|
*/
|
2005-03-05 12:19:14 +01:00
|
|
|
if (len>0 && wszText[len-1] == '\n')
|
|
|
|
ME_ClearTempStyle(editor);
|
2007-03-22 12:09:43 +01:00
|
|
|
ME_EndToUnicode(unicode, wszText);
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_UpdateSelectionLinkAttribute(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
if (!wParam)
|
|
|
|
ME_EmptyUndoStack(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2007-10-21 03:23:27 +02:00
|
|
|
return len;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-02-16 19:33:19 +01:00
|
|
|
case EM_SCROLLCARET:
|
2009-01-14 19:24:02 +01:00
|
|
|
ME_EnsureVisible(editor, &editor->pCursors[0]);
|
2006-02-16 19:33:19 +01:00
|
|
|
return 0;
|
2006-07-14 19:43:00 +02:00
|
|
|
case WM_SETFONT:
|
|
|
|
{
|
|
|
|
LOGFONTW lf;
|
|
|
|
CHARFORMAT2W fmt;
|
|
|
|
HDC hDC;
|
|
|
|
BOOL bRepaint = LOWORD(lParam);
|
2009-02-07 19:20:23 +01:00
|
|
|
|
2006-07-14 19:43:00 +02:00
|
|
|
if (!wParam)
|
2010-06-06 20:57:44 +02:00
|
|
|
wParam = (WPARAM)GetStockObject(SYSTEM_FONT);
|
2006-07-14 19:43:00 +02:00
|
|
|
GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf);
|
2009-01-20 07:41:32 +01:00
|
|
|
hDC = ITextHost_TxGetDC(editor->texthost);
|
2010-06-06 20:57:44 +02:00
|
|
|
ME_CharFormatFromLogFont(hDC, &lf, &fmt);
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxReleaseDC(editor->texthost, hDC);
|
2010-06-06 20:57:44 +02:00
|
|
|
if (editor->mode & TM_RICHTEXT) {
|
|
|
|
ME_Cursor start;
|
|
|
|
ME_SetCursorToStart(editor, &start);
|
|
|
|
ME_SetCharFormat(editor, &start, NULL, &fmt);
|
|
|
|
}
|
2006-07-14 19:43:00 +02:00
|
|
|
ME_SetDefaultCharFormat(editor, &fmt);
|
|
|
|
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitUndo(editor);
|
2009-02-07 19:20:23 +01:00
|
|
|
ME_MarkAllForWrapping(editor);
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
ME_UpdateScrollBar(editor);
|
2006-07-14 19:43:00 +02:00
|
|
|
if (bRepaint)
|
2009-02-07 19:20:23 +01:00
|
|
|
ME_Repaint(editor);
|
2006-07-14 19:43:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_SETTEXT:
|
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_Cursor cursor;
|
|
|
|
ME_SetCursorToStart(editor, &cursor);
|
|
|
|
ME_InternalDeleteText(editor, &cursor, ME_GetTextLength(editor), FALSE);
|
2005-07-21 13:28:39 +02:00
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
TRACE("WM_SETTEXT lParam==%lx\n",lParam);
|
2009-07-11 05:54:34 +02:00
|
|
|
if (!strncmp((char *)lParam, "{\\rtf", 5) ||
|
|
|
|
!strncmp((char *)lParam, "{\\urtf", 6))
|
2006-02-14 17:38:57 +01:00
|
|
|
{
|
|
|
|
/* Undocumented: WM_SETTEXT supports RTF text */
|
|
|
|
ME_StreamInRTFString(editor, 0, (char *)lParam);
|
|
|
|
}
|
|
|
|
else
|
2005-07-21 13:28:39 +02:00
|
|
|
{
|
2007-03-22 12:09:43 +01:00
|
|
|
LPWSTR wszText = ME_ToUnicode(unicode, (void *)lParam);
|
2006-02-14 17:38:57 +01:00
|
|
|
TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
|
|
|
|
if (lstrlenW(wszText) > 0)
|
|
|
|
{
|
2007-09-28 01:17:48 +02:00
|
|
|
int len = -1;
|
|
|
|
|
2006-02-14 17:38:57 +01:00
|
|
|
/* uses default style! */
|
2009-01-15 20:46:25 +01:00
|
|
|
if (!(editor->styleFlags & ES_MULTILINE))
|
2007-09-28 01:17:48 +02:00
|
|
|
{
|
|
|
|
WCHAR * p;
|
|
|
|
|
|
|
|
p = wszText;
|
|
|
|
while (*p != '\0' && *p != '\r' && *p != '\n') p++;
|
|
|
|
len = p - wszText;
|
|
|
|
}
|
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
|
2006-02-14 17:38:57 +01:00
|
|
|
}
|
2007-03-22 12:09:43 +01:00
|
|
|
ME_EndToUnicode(unicode, wszText);
|
2005-07-21 13:28:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("WM_SETTEXT - NULL\n");
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_SetCursorToStart(editor, &cursor);
|
|
|
|
ME_UpdateLinkAttribute(editor, &cursor, INT_MAX);
|
2008-04-27 22:47:26 +02:00
|
|
|
ME_SetSelection(editor, 0, 0);
|
2008-04-27 21:21:02 +02:00
|
|
|
editor->nModifyStep = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
ME_EmptyUndoStack(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2007-03-21 11:26:19 +01:00
|
|
|
return 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-04-11 14:50:48 +02:00
|
|
|
case EM_CANPASTE:
|
|
|
|
{
|
|
|
|
UINT nRTFFormat = RegisterClipboardFormatA("Rich Text Format");
|
|
|
|
if (IsClipboardFormatAvailable(nRTFFormat))
|
|
|
|
return TRUE;
|
|
|
|
if (IsClipboardFormatAvailable(CF_UNICODETEXT))
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-03-15 16:40:52 +01:00
|
|
|
case WM_PASTE:
|
2012-06-18 20:31:22 +02:00
|
|
|
case WM_MBUTTONDOWN:
|
2008-10-22 02:43:47 +02:00
|
|
|
ME_Paste(editor);
|
2005-03-15 16:40:52 +01:00
|
|
|
return 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CUT:
|
|
|
|
case WM_COPY:
|
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
int nFrom, nTo, nStartCur = ME_GetSelectionOfs(editor, &nFrom, &nTo);
|
|
|
|
int nChars = nTo - nFrom;
|
2009-08-13 14:44:05 +02:00
|
|
|
ME_Cursor *selStart = &editor->pCursors[nStartCur];
|
2008-10-22 02:43:47 +02:00
|
|
|
|
2009-08-13 14:44:05 +02:00
|
|
|
if (ME_Copy(editor, selStart, nChars) && msg == WM_CUT)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-13 14:44:18 +02:00
|
|
|
ME_InternalDeleteText(editor, selStart, nChars, FALSE);
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, TRUE);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_GETTEXTLENGTH:
|
2007-12-06 19:50:22 +01:00
|
|
|
{
|
|
|
|
GETTEXTLENGTHEX how;
|
|
|
|
|
2008-04-27 05:49:35 +02:00
|
|
|
/* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
|
2007-12-11 22:02:54 +01:00
|
|
|
how.flags = GTL_CLOSE | (editor->bEmulateVersion10 ? 0 : GTL_USECRLF) | GTL_NUMCHARS;
|
2007-12-06 19:50:22 +01:00
|
|
|
how.codepage = unicode ? 1200 : CP_ACP;
|
|
|
|
return ME_GetTextLengthEx(editor, &how);
|
|
|
|
}
|
2005-06-28 15:51:32 +02:00
|
|
|
case EM_GETTEXTLENGTHEX:
|
|
|
|
return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_GETTEXT:
|
|
|
|
{
|
2007-09-23 23:40:28 +02:00
|
|
|
GETTEXTEX ex;
|
2009-07-30 06:54:21 +02:00
|
|
|
ex.cb = wParam * (unicode ? sizeof(WCHAR) : sizeof(CHAR));
|
2007-09-23 23:40:28 +02:00
|
|
|
ex.flags = GT_USECRLF;
|
|
|
|
ex.codepage = unicode ? 1200 : CP_ACP;
|
|
|
|
ex.lpDefaultChar = NULL;
|
2008-02-06 04:07:40 +01:00
|
|
|
ex.lpUsedDefChar = NULL;
|
2009-07-30 06:54:21 +02:00
|
|
|
return ME_GetTextEx(editor, &ex, lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2005-06-29 21:21:34 +02:00
|
|
|
case EM_GETTEXTEX:
|
2008-12-16 09:43:24 +01:00
|
|
|
return ME_GetTextEx(editor, (GETTEXTEX*)wParam, lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETSELTEXT:
|
|
|
|
{
|
2009-08-12 15:06:18 +02:00
|
|
|
int nFrom, nTo, nStartCur = ME_GetSelectionOfs(editor, &nFrom, &nTo);
|
|
|
|
ME_Cursor *from = &editor->pCursors[nStartCur];
|
2009-03-23 05:14:33 +01:00
|
|
|
return ME_GetTextRange(editor, (WCHAR *)lParam, from,
|
2009-08-12 15:06:18 +02:00
|
|
|
nTo - nFrom, unicode);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-02-16 19:33:19 +01:00
|
|
|
case EM_GETSCROLLPOS:
|
|
|
|
{
|
2009-01-14 19:24:02 +01:00
|
|
|
POINT *point = (POINT *)lParam;
|
|
|
|
point->x = editor->horz_si.nPos;
|
|
|
|
point->y = editor->vert_si.nPos;
|
2009-07-22 03:06:00 +02:00
|
|
|
/* 16-bit scaled value is returned as stored in scrollinfo */
|
|
|
|
if (editor->horz_si.nMax > 0xffff)
|
|
|
|
point->x = MulDiv(point->x, 0xffff, editor->horz_si.nMax);
|
|
|
|
if (editor->vert_si.nMax > 0xffff)
|
|
|
|
point->y = MulDiv(point->y, 0xffff, editor->vert_si.nMax);
|
2009-01-14 19:24:02 +01:00
|
|
|
return 1;
|
2006-02-16 19:33:19 +01:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETTEXTRANGE:
|
|
|
|
{
|
|
|
|
TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
|
2009-08-12 15:06:18 +02:00
|
|
|
ME_Cursor start;
|
|
|
|
int nStart = rng->chrg.cpMin;
|
|
|
|
int nEnd = rng->chrg.cpMax;
|
2009-03-23 05:14:33 +01:00
|
|
|
int textlength = ME_GetTextLength(editor);
|
2009-08-12 15:06:18 +02:00
|
|
|
|
|
|
|
TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d textlength=%d\n",
|
|
|
|
rng->chrg.cpMin, rng->chrg.cpMax, unicode, textlength);
|
|
|
|
if (nStart < 0) return 0;
|
|
|
|
if ((nStart == 0 && nEnd == -1) || nEnd > textlength)
|
|
|
|
nEnd = textlength;
|
|
|
|
if (nStart >= nEnd) return 0;
|
|
|
|
|
|
|
|
ME_CursorFromCharOfs(editor, nStart, &start);
|
|
|
|
return ME_GetTextRange(editor, rng->lpstrText, &start, nEnd - nStart, unicode);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-07-31 07:59:43 +02:00
|
|
|
case EM_GETLINE:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *run;
|
|
|
|
const unsigned int nMaxChars = *(WORD *) lParam;
|
2008-04-26 23:43:14 +02:00
|
|
|
unsigned int nCharsLeft = nMaxChars;
|
2006-07-31 07:59:43 +02:00
|
|
|
char *dest = (char *) lParam;
|
2008-04-26 23:43:14 +02:00
|
|
|
BOOL wroteNull = FALSE;
|
2006-07-31 07:59:43 +02:00
|
|
|
|
|
|
|
TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
|
2007-03-22 12:09:43 +01:00
|
|
|
unicode ? "Unicode" : "Ansi");
|
2006-07-31 07:59:43 +02:00
|
|
|
|
|
|
|
run = ME_FindRowWithNumber(editor, wParam);
|
|
|
|
if (run == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
|
2009-01-28 07:34:56 +01:00
|
|
|
&& run->type == diRun)
|
2006-07-31 07:59:43 +02:00
|
|
|
{
|
2013-01-30 16:10:20 +01:00
|
|
|
WCHAR *str = get_text( &run->member.run, 0 );
|
2006-07-31 07:59:43 +02:00
|
|
|
unsigned int nCopy;
|
2009-01-28 07:34:56 +01:00
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
nCopy = min(nCharsLeft, run->member.run.len);
|
2006-07-31 07:59:43 +02:00
|
|
|
|
2007-03-22 12:09:43 +01:00
|
|
|
if (unicode)
|
2013-01-30 16:10:20 +01:00
|
|
|
memcpy(dest, str, nCopy * sizeof(WCHAR));
|
2006-07-31 07:59:43 +02:00
|
|
|
else
|
2013-01-30 16:10:20 +01:00
|
|
|
nCopy = WideCharToMultiByte(CP_ACP, 0, str, nCopy, dest,
|
2006-07-31 07:59:43 +02:00
|
|
|
nCharsLeft, NULL, NULL);
|
2007-03-22 12:09:43 +01:00
|
|
|
dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
|
2006-07-31 07:59:43 +02:00
|
|
|
nCharsLeft -= nCopy;
|
|
|
|
}
|
|
|
|
|
2008-04-26 23:43:14 +02:00
|
|
|
/* append line termination, space allowing */
|
|
|
|
if (nCharsLeft > 0)
|
2006-07-31 07:59:43 +02:00
|
|
|
{
|
2009-01-28 07:34:56 +01:00
|
|
|
if (unicode)
|
|
|
|
*((WCHAR *)dest) = '\0';
|
|
|
|
else
|
|
|
|
*dest = '\0';
|
|
|
|
nCharsLeft--;
|
|
|
|
wroteNull = TRUE;
|
2006-07-31 07:59:43 +02:00
|
|
|
}
|
|
|
|
|
2008-04-26 23:43:14 +02:00
|
|
|
TRACE("EM_GETLINE: got %u characters\n", nMaxChars - nCharsLeft);
|
|
|
|
return nMaxChars - nCharsLeft - (wroteNull ? 1 : 0);
|
2006-07-31 07:59:43 +02:00
|
|
|
}
|
2005-06-30 20:10:22 +02:00
|
|
|
case EM_GETLINECOUNT:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item = editor->pBuffer->pFirst->next;
|
|
|
|
int nRows = 0;
|
|
|
|
|
2008-04-27 16:24:15 +02:00
|
|
|
ME_DisplayItem *prev_para = NULL, *last_para = NULL;
|
|
|
|
|
2005-06-30 20:10:22 +02:00
|
|
|
while (item != editor->pBuffer->pLast)
|
|
|
|
{
|
|
|
|
assert(item->type == diParagraph);
|
2008-04-27 16:24:15 +02:00
|
|
|
prev_para = ME_FindItemBack(item, diRun);
|
|
|
|
if (prev_para) {
|
|
|
|
assert(prev_para->member.run.nFlags & MERF_ENDPARA);
|
|
|
|
}
|
2005-06-30 20:10:22 +02:00
|
|
|
nRows += item->member.para.nRows;
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
}
|
2008-04-27 16:24:15 +02:00
|
|
|
last_para = ME_FindItemBack(item, diRun);
|
|
|
|
assert(last_para);
|
|
|
|
assert(last_para->member.run.nFlags & MERF_ENDPARA);
|
2009-01-28 07:34:56 +01:00
|
|
|
if (editor->bEmulateVersion10 && prev_para &&
|
|
|
|
last_para->member.run.nCharOfs == 0 &&
|
2013-01-31 14:48:00 +01:00
|
|
|
prev_para->member.run.len == 1 &&
|
2013-01-30 16:10:20 +01:00
|
|
|
*get_text( &prev_para->member.run, 0 ) == '\r')
|
2008-04-27 16:24:15 +02:00
|
|
|
{
|
|
|
|
/* In 1.0 emulation, the last solitary \r at the very end of the text
|
|
|
|
(if one exists) is NOT a line break.
|
|
|
|
FIXME: this is an ugly hack. This should have a more regular model. */
|
|
|
|
nRows--;
|
|
|
|
}
|
|
|
|
|
2005-07-21 13:58:24 +02:00
|
|
|
TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows);
|
2005-06-30 20:10:22 +02:00
|
|
|
return max(1, nRows);
|
|
|
|
}
|
2005-07-06 13:12:10 +02:00
|
|
|
case EM_LINEFROMCHAR:
|
|
|
|
{
|
|
|
|
if (wParam == -1)
|
2009-08-12 15:05:42 +02:00
|
|
|
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
|
2005-07-06 13:12:10 +02:00
|
|
|
else
|
|
|
|
return ME_RowNumberFromCharOfs(editor, wParam);
|
|
|
|
}
|
2005-07-06 12:32:59 +02:00
|
|
|
case EM_EXLINEFROMCHAR:
|
|
|
|
{
|
2006-08-21 14:25:51 +02:00
|
|
|
if (lParam == -1)
|
2009-08-12 15:05:42 +02:00
|
|
|
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
|
2006-08-21 14:25:51 +02:00
|
|
|
else
|
|
|
|
return ME_RowNumberFromCharOfs(editor, lParam);
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
case EM_LINEINDEX:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item, *para;
|
2005-07-21 13:58:24 +02:00
|
|
|
int nCharOfs;
|
2005-07-06 12:32:59 +02:00
|
|
|
|
|
|
|
if (wParam == -1)
|
2005-07-06 13:12:10 +02:00
|
|
|
item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
|
2005-07-06 12:32:59 +02:00
|
|
|
else
|
|
|
|
item = ME_FindRowWithNumber(editor, wParam);
|
|
|
|
if (!item)
|
|
|
|
return -1;
|
|
|
|
para = ME_GetParagraph(item);
|
|
|
|
item = ME_FindItemFwd(item, diRun);
|
2005-07-21 13:58:24 +02:00
|
|
|
nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
|
|
|
|
TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
|
|
|
|
return nCharOfs;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
2005-07-21 13:01:47 +02:00
|
|
|
case EM_LINELENGTH:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item, *item_end;
|
2005-09-29 12:30:50 +02:00
|
|
|
int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
|
2009-02-06 07:09:51 +01:00
|
|
|
ME_DisplayItem *para, *run;
|
2009-01-27 09:39:03 +01:00
|
|
|
|
2005-07-21 13:01:47 +02:00
|
|
|
if (wParam > ME_GetTextLength(editor))
|
|
|
|
return 0;
|
|
|
|
if (wParam == -1)
|
|
|
|
{
|
|
|
|
FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-02-06 07:09:51 +01:00
|
|
|
ME_RunOfsFromCharOfs(editor, wParam, ¶, &run, NULL);
|
|
|
|
item = ME_RowStart(run);
|
|
|
|
nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0);
|
2006-08-03 20:37:45 +02:00
|
|
|
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
|
2009-02-06 07:09:51 +01:00
|
|
|
if (item_end->type == diStartRow) {
|
|
|
|
nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0);
|
|
|
|
} else {
|
|
|
|
ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
|
|
|
|
assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
|
2013-01-31 14:48:00 +01:00
|
|
|
nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
|
2008-04-27 01:14:13 +02:00
|
|
|
}
|
2005-09-29 12:30:50 +02:00
|
|
|
nChars = nNextLineOfs - nThisLineOfs;
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
|
2005-07-21 13:01:47 +02:00
|
|
|
return nChars;
|
|
|
|
}
|
2006-08-09 21:33:42 +02:00
|
|
|
case EM_EXLIMITTEXT:
|
|
|
|
{
|
2006-11-28 06:56:25 +01:00
|
|
|
if ((int)lParam < 0)
|
2006-08-09 21:33:42 +02:00
|
|
|
return 0;
|
|
|
|
if (lParam == 0)
|
|
|
|
editor->nTextLimit = 65536;
|
|
|
|
else
|
|
|
|
editor->nTextLimit = (int) lParam;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-01-23 20:39:38 +01:00
|
|
|
case EM_LIMITTEXT:
|
|
|
|
{
|
|
|
|
if (wParam == 0)
|
|
|
|
editor->nTextLimit = 65536;
|
|
|
|
else
|
|
|
|
editor->nTextLimit = (int) wParam;
|
|
|
|
return 0;
|
|
|
|
}
|
2006-08-09 21:33:42 +02:00
|
|
|
case EM_GETLIMITTEXT:
|
|
|
|
{
|
|
|
|
return editor->nTextLimit;
|
|
|
|
}
|
2005-07-06 12:32:59 +02:00
|
|
|
case EM_FINDTEXT:
|
|
|
|
{
|
2006-11-10 07:41:38 +01:00
|
|
|
LRESULT r;
|
2013-03-22 17:34:42 +01:00
|
|
|
if(!unicode){
|
|
|
|
FINDTEXTA *ft = (FINDTEXTA *)lParam;
|
|
|
|
int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
|
|
|
|
WCHAR *tmp;
|
|
|
|
|
|
|
|
if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
|
|
|
|
r = ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
|
|
|
|
FREE_OBJ( tmp );
|
|
|
|
}else{
|
|
|
|
FINDTEXTW *ft = (FINDTEXTW *)lParam;
|
|
|
|
r = ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
|
|
|
|
}
|
2006-11-10 07:41:38 +01:00
|
|
|
return r;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
case EM_FINDTEXTEX:
|
|
|
|
{
|
2006-11-10 07:41:38 +01:00
|
|
|
LRESULT r;
|
2013-03-22 17:34:42 +01:00
|
|
|
if(!unicode){
|
|
|
|
FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
|
|
|
|
int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
|
|
|
|
WCHAR *tmp;
|
|
|
|
|
|
|
|
if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
|
|
|
|
r = ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
|
|
|
|
FREE_OBJ( tmp );
|
|
|
|
}else{
|
|
|
|
FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
|
|
|
|
r = ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
|
|
|
|
}
|
2006-11-10 07:41:38 +01:00
|
|
|
return r;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
case EM_FINDTEXTW:
|
|
|
|
{
|
|
|
|
FINDTEXTW *ft = (FINDTEXTW *)lParam;
|
|
|
|
return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
|
|
|
|
}
|
|
|
|
case EM_FINDTEXTEXW:
|
|
|
|
{
|
|
|
|
FINDTEXTEXW *ex = (FINDTEXTEXW *)lParam;
|
|
|
|
return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
|
|
|
|
}
|
2005-07-24 18:17:43 +02:00
|
|
|
case EM_GETZOOM:
|
|
|
|
if (!wParam || !lParam)
|
|
|
|
return FALSE;
|
|
|
|
*(int *)wParam = editor->nZoomNumerator;
|
|
|
|
*(int *)lParam = editor->nZoomDenominator;
|
|
|
|
return TRUE;
|
|
|
|
case EM_SETZOOM:
|
|
|
|
return ME_SetZoom(editor, wParam, lParam);
|
2005-07-26 12:33:00 +02:00
|
|
|
case EM_CHARFROMPOS:
|
2009-08-13 14:44:09 +02:00
|
|
|
{
|
|
|
|
ME_Cursor cursor;
|
|
|
|
if (ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y,
|
|
|
|
&cursor, NULL))
|
|
|
|
return ME_GetCursorOfs(&cursor);
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
2005-10-03 13:03:48 +02:00
|
|
|
case EM_POSFROMCHAR:
|
|
|
|
{
|
2009-02-06 07:09:47 +01:00
|
|
|
ME_DisplayItem *pPara, *pRun;
|
2005-10-03 13:03:48 +02:00
|
|
|
int nCharOfs, nOffset, nLength;
|
|
|
|
POINTL pt = {0,0};
|
2009-01-14 19:24:02 +01:00
|
|
|
|
|
|
|
nCharOfs = wParam;
|
2005-10-03 13:03:48 +02:00
|
|
|
/* detect which API version we're dealing with */
|
|
|
|
if (wParam >= 0x40000)
|
|
|
|
nCharOfs = lParam;
|
|
|
|
nLength = ME_GetTextLength(editor);
|
2008-10-22 08:22:41 +02:00
|
|
|
nCharOfs = min(nCharOfs, nLength);
|
2008-10-28 23:16:23 +01:00
|
|
|
nCharOfs = max(nCharOfs, 0);
|
2008-10-22 08:22:41 +02:00
|
|
|
|
2009-02-06 07:09:47 +01:00
|
|
|
ME_RunOfsFromCharOfs(editor, nCharOfs, &pPara, &pRun, &nOffset);
|
2008-10-22 08:22:41 +02:00
|
|
|
assert(pRun->type == diRun);
|
|
|
|
pt.y = pRun->member.run.pt.y;
|
2013-04-17 13:56:37 +02:00
|
|
|
pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset, TRUE);
|
2009-02-06 07:09:47 +01:00
|
|
|
pt.y += pPara->member.para.pt.y + editor->rcFormat.top;
|
2008-12-18 07:56:49 +01:00
|
|
|
pt.x += editor->rcFormat.left;
|
2008-06-21 22:50:12 +02:00
|
|
|
|
2009-01-14 19:24:02 +01:00
|
|
|
pt.x -= editor->horz_si.nPos;
|
2008-12-15 10:31:25 +01:00
|
|
|
pt.y -= editor->vert_si.nPos;
|
2008-06-21 22:50:12 +02:00
|
|
|
|
2005-10-03 13:03:48 +02:00
|
|
|
if (wParam >= 0x40000) {
|
|
|
|
*(POINTL *)wParam = pt;
|
|
|
|
}
|
2008-06-23 20:49:49 +02:00
|
|
|
return (wParam >= 0x40000) ? 0 : MAKELONG( pt.x, pt.y );
|
2005-10-03 13:03:48 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CREATE:
|
2008-07-20 18:29:19 +02:00
|
|
|
{
|
2009-07-17 00:45:59 +02:00
|
|
|
INT max;
|
2008-07-20 18:29:19 +02:00
|
|
|
|
2008-12-18 07:56:49 +01:00
|
|
|
ME_SetDefaultFormatRect(editor);
|
2008-07-20 18:29:19 +02:00
|
|
|
|
2009-07-17 00:45:59 +02:00
|
|
|
max = (editor->styleFlags & ES_DISABLENOSCROLL) ? 1 : 0;
|
|
|
|
if (~editor->styleFlags & ES_DISABLENOSCROLL || editor->styleFlags & WS_VSCROLL)
|
|
|
|
ITextHost_TxSetScrollRange(editor->texthost, SB_VERT, 0, max, TRUE);
|
|
|
|
|
|
|
|
if (~editor->styleFlags & ES_DISABLENOSCROLL || editor->styleFlags & WS_HSCROLL)
|
|
|
|
ITextHost_TxSetScrollRange(editor->texthost, SB_HORZ, 0, max, TRUE);
|
|
|
|
|
2009-01-15 20:46:25 +01:00
|
|
|
if (editor->styleFlags & ES_DISABLENOSCROLL)
|
2009-07-17 00:45:59 +02:00
|
|
|
{
|
|
|
|
if (editor->styleFlags & WS_VSCROLL)
|
|
|
|
{
|
|
|
|
ITextHost_TxEnableScrollBar(editor->texthost, SB_VERT, ESB_DISABLE_BOTH);
|
|
|
|
ITextHost_TxShowScrollBar(editor->texthost, SB_VERT, TRUE);
|
|
|
|
}
|
|
|
|
if (editor->styleFlags & WS_HSCROLL)
|
|
|
|
{
|
|
|
|
ITextHost_TxEnableScrollBar(editor->texthost, SB_HORZ, ESB_DISABLE_BOTH);
|
|
|
|
ITextHost_TxShowScrollBar(editor->texthost, SB_HORZ, TRUE);
|
|
|
|
}
|
2009-01-20 07:41:36 +01:00
|
|
|
}
|
2008-07-20 18:29:19 +02:00
|
|
|
|
2010-05-19 08:32:23 +02:00
|
|
|
ME_CommitUndo(editor);
|
2005-03-09 12:48:59 +01:00
|
|
|
ME_WrapMarkedParagraphs(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_MoveCaret(editor);
|
|
|
|
return 0;
|
2008-07-20 18:29:19 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_DESTROY:
|
|
|
|
ME_DestroyEditor(editor);
|
2005-03-09 19:43:18 +01:00
|
|
|
return 0;
|
2008-07-09 15:36:00 +02:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
{
|
2008-07-09 15:36:12 +02:00
|
|
|
return ME_SetCursor(editor);
|
2008-07-09 15:36:00 +02:00
|
|
|
}
|
2008-07-05 10:23:53 +02:00
|
|
|
case WM_LBUTTONDBLCLK:
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_LBUTTONDOWN:
|
2008-07-05 10:23:53 +02:00
|
|
|
{
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
|
2008-01-01 22:03:22 +01:00
|
|
|
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetFocus(editor->texthost);
|
2008-07-05 10:23:53 +02:00
|
|
|
ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
|
2008-12-15 10:32:01 +01:00
|
|
|
ME_CalculateClickCount(editor, msg, wParam, lParam));
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCapture(editor->texthost, TRUE);
|
2009-01-11 08:59:20 +01:00
|
|
|
editor->bMouseCaptured = TRUE;
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2008-07-09 15:36:12 +02:00
|
|
|
if (!ME_SetCursor(editor)) goto do_default;
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2008-07-05 10:23:53 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_MOUSEMOVE:
|
2008-01-01 22:03:22 +01:00
|
|
|
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
2009-01-11 08:59:20 +01:00
|
|
|
if (editor->bMouseCaptured)
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2008-07-09 15:36:12 +02:00
|
|
|
/* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
|
2009-01-11 08:59:20 +01:00
|
|
|
if (editor->bMouseCaptured)
|
2008-07-09 15:36:12 +02:00
|
|
|
ME_SetCursor(editor);
|
2006-08-19 23:04:49 +02:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_LBUTTONUP:
|
2009-01-11 08:59:20 +01:00
|
|
|
if (editor->bMouseCaptured) {
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxSetCapture(editor->texthost, FALSE);
|
2009-01-11 08:59:20 +01:00
|
|
|
editor->bMouseCaptured = FALSE;
|
|
|
|
}
|
2008-07-07 17:04:02 +02:00
|
|
|
if (editor->nSelectionType == stDocument)
|
|
|
|
editor->nSelectionType = stPosition;
|
2008-01-01 22:03:22 +01:00
|
|
|
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
2008-03-16 21:48:22 +01:00
|
|
|
else
|
|
|
|
{
|
2008-07-09 15:36:12 +02:00
|
|
|
ME_SetCursor(editor);
|
2008-03-16 21:48:22 +01:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2008-01-01 22:03:22 +01:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_RBUTTONDOWN:
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
|
2008-01-01 22:03:22 +01:00
|
|
|
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
|
|
|
goto do_default;
|
2006-02-02 13:18:20 +01:00
|
|
|
case WM_CONTEXTMENU:
|
2006-09-03 05:08:46 +02:00
|
|
|
if (!ME_ShowContextMenu(editor, (short)LOWORD(lParam), (short)HIWORD(lParam)))
|
|
|
|
goto do_default;
|
2006-02-02 13:18:20 +01:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_SETFOCUS:
|
2007-06-05 14:56:55 +02:00
|
|
|
editor->bHaveFocus = TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_ShowCaret(editor);
|
|
|
|
ME_SendOldNotify(editor, EN_SETFOCUS);
|
|
|
|
return 0;
|
|
|
|
case WM_KILLFOCUS:
|
2008-06-25 16:29:19 +02:00
|
|
|
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
|
2007-06-05 14:56:55 +02:00
|
|
|
editor->bHaveFocus = FALSE;
|
2008-07-07 17:04:06 +02:00
|
|
|
ME_HideCaret(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SendOldNotify(editor, EN_KILLFOCUS);
|
|
|
|
return 0;
|
|
|
|
case WM_COMMAND:
|
|
|
|
TRACE("editor wnd command = %d\n", LOWORD(wParam));
|
|
|
|
return 0;
|
2008-01-01 22:03:22 +01:00
|
|
|
case WM_KEYUP:
|
|
|
|
if ((editor->nEventMask & ENM_KEYEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
|
|
|
goto do_default;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_KEYDOWN:
|
2008-01-01 22:03:22 +01:00
|
|
|
if ((editor->nEventMask & ENM_KEYEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
2006-01-10 20:23:41 +01:00
|
|
|
if (ME_KeyDown(editor, LOWORD(wParam)))
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
goto do_default;
|
2008-12-16 09:43:33 +01:00
|
|
|
case WM_CHAR:
|
2013-02-28 14:52:55 +01:00
|
|
|
if ((editor->nEventMask & ENM_KEYEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
2008-12-16 09:43:33 +01:00
|
|
|
return ME_Char(editor, wParam, lParam, unicode);
|
2008-07-23 13:55:46 +02:00
|
|
|
case WM_UNICHAR:
|
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
if(wParam == UNICODE_NOCHAR) return TRUE;
|
|
|
|
if(wParam <= 0x000fffff)
|
|
|
|
{
|
|
|
|
if(wParam > 0xffff) /* convert to surrogates */
|
|
|
|
{
|
|
|
|
wParam -= 0x10000;
|
2008-12-16 09:43:33 +01:00
|
|
|
ME_Char(editor, (wParam >> 10) + 0xd800, 0, TRUE);
|
|
|
|
ME_Char(editor, (wParam & 0x03ff) + 0xdc00, 0, TRUE);
|
|
|
|
} else {
|
|
|
|
ME_Char(editor, wParam, 0, TRUE);
|
2008-07-23 13:55:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2008-06-25 16:29:19 +02:00
|
|
|
case EM_STOPGROUPTYPING:
|
|
|
|
ME_CommitUndo(editor); /* End coalesced undos for typed characters */
|
|
|
|
return 0;
|
2009-01-14 19:24:02 +01:00
|
|
|
case WM_HSCROLL:
|
|
|
|
{
|
|
|
|
const int scrollUnit = 7;
|
|
|
|
|
|
|
|
switch(LOWORD(wParam))
|
|
|
|
{
|
|
|
|
case SB_LEFT:
|
|
|
|
ME_ScrollAbs(editor, 0, 0);
|
|
|
|
break;
|
|
|
|
case SB_RIGHT:
|
|
|
|
ME_ScrollAbs(editor,
|
|
|
|
editor->horz_si.nMax - (int)editor->horz_si.nPage,
|
|
|
|
editor->vert_si.nMax - (int)editor->vert_si.nPage);
|
|
|
|
break;
|
|
|
|
case SB_LINELEFT:
|
|
|
|
ME_ScrollLeft(editor, scrollUnit);
|
|
|
|
break;
|
|
|
|
case SB_LINERIGHT:
|
|
|
|
ME_ScrollRight(editor, scrollUnit);
|
|
|
|
break;
|
|
|
|
case SB_PAGELEFT:
|
|
|
|
ME_ScrollLeft(editor, editor->sizeWindow.cx);
|
|
|
|
break;
|
|
|
|
case SB_PAGERIGHT:
|
|
|
|
ME_ScrollRight(editor, editor->sizeWindow.cx);
|
|
|
|
break;
|
|
|
|
case SB_THUMBTRACK:
|
|
|
|
case SB_THUMBPOSITION:
|
|
|
|
{
|
2009-07-22 03:06:00 +02:00
|
|
|
int pos = HIWORD(wParam);
|
|
|
|
if (editor->horz_si.nMax > 0xffff)
|
|
|
|
pos = MulDiv(pos, editor->horz_si.nMax, 0xffff);
|
|
|
|
ME_HScrollAbs(editor, pos);
|
2009-01-14 19:24:02 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-02-25 08:26:42 +01:00
|
|
|
case EM_SCROLL: /* fall through */
|
2009-01-14 19:24:02 +01:00
|
|
|
case WM_VSCROLL:
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
int origNPos;
|
|
|
|
int lineHeight;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
|
|
|
origNPos = editor->vert_si.nPos;
|
2006-09-08 23:37:25 +02:00
|
|
|
lineHeight = 24;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
2009-01-29 09:26:40 +01:00
|
|
|
if (editor->pBuffer && editor->pBuffer->pDefaultStyle)
|
2006-09-08 23:37:25 +02:00
|
|
|
lineHeight = editor->pBuffer->pDefaultStyle->tm.tmHeight;
|
2006-02-25 08:26:42 +01:00
|
|
|
if (lineHeight <= 0) lineHeight = 24;
|
2009-01-14 19:24:02 +01:00
|
|
|
|
|
|
|
switch(LOWORD(wParam))
|
2005-03-21 11:27:24 +01:00
|
|
|
{
|
2009-01-14 19:24:02 +01:00
|
|
|
case SB_TOP:
|
|
|
|
ME_ScrollAbs(editor, 0, 0);
|
|
|
|
break;
|
|
|
|
case SB_BOTTOM:
|
|
|
|
ME_ScrollAbs(editor,
|
|
|
|
editor->horz_si.nMax - (int)editor->horz_si.nPage,
|
|
|
|
editor->vert_si.nMax - (int)editor->vert_si.nPage);
|
|
|
|
break;
|
2006-09-08 23:37:25 +02:00
|
|
|
case SB_LINEUP:
|
|
|
|
ME_ScrollUp(editor,lineHeight);
|
|
|
|
break;
|
|
|
|
case SB_LINEDOWN:
|
|
|
|
ME_ScrollDown(editor,lineHeight);
|
|
|
|
break;
|
|
|
|
case SB_PAGEUP:
|
|
|
|
ME_ScrollUp(editor,editor->sizeWindow.cy);
|
|
|
|
break;
|
|
|
|
case SB_PAGEDOWN:
|
|
|
|
ME_ScrollDown(editor,editor->sizeWindow.cy);
|
|
|
|
break;
|
|
|
|
case SB_THUMBTRACK:
|
|
|
|
case SB_THUMBPOSITION:
|
2009-01-06 06:34:28 +01:00
|
|
|
{
|
2009-07-22 03:06:00 +02:00
|
|
|
int pos = HIWORD(wParam);
|
|
|
|
if (editor->vert_si.nMax > 0xffff)
|
|
|
|
pos = MulDiv(pos, editor->vert_si.nMax, 0xffff);
|
|
|
|
ME_VScrollAbs(editor, pos);
|
2006-09-08 23:37:25 +02:00
|
|
|
break;
|
2009-01-06 06:34:28 +01:00
|
|
|
}
|
2005-03-21 11:27:24 +01:00
|
|
|
}
|
2006-02-25 08:26:42 +01:00
|
|
|
if (msg == EM_SCROLL)
|
2009-01-14 19:24:02 +01:00
|
|
|
return 0x00010000 | (((editor->vert_si.nPos - origNPos)/lineHeight) & 0xffff);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-04-11 16:22:21 +02:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
int gcWheelDelta;
|
2005-04-11 16:22:21 +02:00
|
|
|
UINT pulScrollLines;
|
2009-01-13 19:39:32 +01:00
|
|
|
BOOL ctrl_is_down;
|
2008-01-01 22:03:22 +01:00
|
|
|
|
|
|
|
if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
|
|
|
|
!ME_FilterEvent(editor, msg, &wParam, &lParam))
|
|
|
|
return 0;
|
|
|
|
|
2009-01-13 19:39:32 +01:00
|
|
|
ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
|
|
|
|
|
|
|
|
gcWheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
|
|
|
|
|
|
|
|
if (abs(gcWheelDelta) >= WHEEL_DELTA)
|
2006-09-08 23:37:25 +02:00
|
|
|
{
|
2009-01-13 19:39:32 +01:00
|
|
|
if (ctrl_is_down) {
|
|
|
|
int numerator;
|
|
|
|
if (!editor->nZoomNumerator || !editor->nZoomDenominator)
|
|
|
|
{
|
|
|
|
numerator = 100;
|
|
|
|
} else {
|
|
|
|
numerator = editor->nZoomNumerator * 100 / editor->nZoomDenominator;
|
|
|
|
}
|
|
|
|
numerator = numerator + (gcWheelDelta / WHEEL_DELTA) * 10;
|
|
|
|
if (numerator >= 10 && numerator <= 500)
|
|
|
|
ME_SetZoom(editor, numerator, 100);
|
|
|
|
} else {
|
|
|
|
SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
|
|
|
|
/* FIXME follow the original */
|
|
|
|
if (pulScrollLines)
|
|
|
|
ME_ScrollDown(editor,pulScrollLines * (-gcWheelDelta / WHEEL_DELTA) * 8);
|
|
|
|
}
|
2005-04-11 16:22:21 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-08-15 11:47:14 +02:00
|
|
|
case EM_GETRECT:
|
|
|
|
{
|
|
|
|
*((RECT *)lParam) = editor->rcFormat;
|
2008-12-18 07:56:49 +01:00
|
|
|
if (editor->bDefaultFormatRect)
|
|
|
|
((RECT *)lParam)->left -= editor->selofs;
|
2005-08-15 11:47:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_SETRECT:
|
|
|
|
case EM_SETRECTNP:
|
|
|
|
{
|
|
|
|
if (lParam)
|
|
|
|
{
|
2009-01-20 07:41:36 +01:00
|
|
|
int border = 0;
|
2008-12-18 07:56:49 +01:00
|
|
|
RECT clientRect;
|
2005-08-15 11:47:14 +02:00
|
|
|
RECT *rc = (RECT *)lParam;
|
2008-12-18 07:56:49 +01:00
|
|
|
|
2009-01-20 07:41:36 +01:00
|
|
|
border = editor->exStyleFlags & WS_EX_CLIENTEDGE ? 1 : 0;
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &clientRect);
|
2008-12-18 07:56:49 +01:00
|
|
|
if (wParam == 0)
|
2005-08-15 11:47:14 +02:00
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
editor->rcFormat.top = max(0, rc->top - border);
|
|
|
|
editor->rcFormat.left = max(0, rc->left - border);
|
|
|
|
editor->rcFormat.bottom = min(clientRect.bottom, rc->bottom);
|
|
|
|
editor->rcFormat.right = min(clientRect.right, rc->right + border);
|
|
|
|
} else if (wParam == 1) {
|
|
|
|
/* MSDN incorrectly says a wParam value of 1 causes the
|
|
|
|
* lParam rect to be used as a relative offset,
|
|
|
|
* however, the tests show it just prevents min/max bound
|
|
|
|
* checking. */
|
|
|
|
editor->rcFormat.top = rc->top - border;
|
|
|
|
editor->rcFormat.left = rc->left - border;
|
|
|
|
editor->rcFormat.bottom = rc->bottom;
|
|
|
|
editor->rcFormat.right = rc->right + border;
|
|
|
|
} else {
|
|
|
|
return 0;
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
2008-12-18 07:56:49 +01:00
|
|
|
editor->bDefaultFormatRect = FALSE;
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
ME_SetDefaultFormatRect(editor);
|
|
|
|
editor->bDefaultFormatRect = TRUE;
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
2009-02-07 19:20:23 +01:00
|
|
|
ME_MarkAllForWrapping(editor);
|
|
|
|
ME_WrapMarkedParagraphs(editor);
|
|
|
|
ME_UpdateScrollBar(editor);
|
2005-08-15 11:47:14 +02:00
|
|
|
if (msg != EM_SETRECTNP)
|
2009-02-07 19:20:23 +01:00
|
|
|
ME_Repaint(editor);
|
2005-08-15 11:47:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-11-03 10:52:29 +01:00
|
|
|
case EM_REQUESTRESIZE:
|
|
|
|
ME_SendRequestResize(editor, TRUE);
|
|
|
|
return 0;
|
2005-08-15 11:47:14 +02:00
|
|
|
case WM_SETREDRAW:
|
2008-12-19 16:57:28 +01:00
|
|
|
goto do_default;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2008-12-18 07:56:49 +01:00
|
|
|
RECT clientRect;
|
|
|
|
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxGetClientRect(editor->texthost, &clientRect);
|
2008-12-18 07:56:49 +01:00
|
|
|
if (editor->bDefaultFormatRect) {
|
|
|
|
ME_SetDefaultFormatRect(editor);
|
|
|
|
} else {
|
|
|
|
editor->rcFormat.right += clientRect.right - editor->prevClientRect.right;
|
|
|
|
editor->rcFormat.bottom += clientRect.bottom - editor->prevClientRect.bottom;
|
|
|
|
}
|
|
|
|
editor->prevClientRect = clientRect;
|
2005-07-24 18:17:43 +02:00
|
|
|
ME_RewrapRepaint(editor);
|
2008-12-19 16:57:28 +01:00
|
|
|
goto do_default;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2007-06-27 14:57:51 +02:00
|
|
|
/* IME messages to make richedit controls IME aware */
|
|
|
|
case WM_IME_SETCONTEXT:
|
|
|
|
case WM_IME_CONTROL:
|
|
|
|
case WM_IME_SELECT:
|
|
|
|
case WM_IME_COMPOSITIONFULL:
|
|
|
|
return 0;
|
|
|
|
case WM_IME_STARTCOMPOSITION:
|
|
|
|
{
|
2009-08-12 15:05:42 +02:00
|
|
|
editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
|
2007-06-27 14:57:51 +02:00
|
|
|
ME_DeleteSelection(editor);
|
2010-05-15 02:11:28 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2007-06-27 14:57:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_IME_COMPOSITION:
|
|
|
|
{
|
|
|
|
HIMC hIMC;
|
|
|
|
|
|
|
|
ME_Style *style = ME_GetInsertStyle(editor, 0);
|
2009-01-20 07:41:32 +01:00
|
|
|
hIMC = ITextHost_TxImmGetContext(editor->texthost);
|
2007-06-27 14:57:51 +02:00
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
ME_SaveTempStyle(editor);
|
2010-05-24 07:05:03 +02:00
|
|
|
if (lParam & (GCS_RESULTSTR|GCS_COMPSTR))
|
2007-06-27 14:57:51 +02:00
|
|
|
{
|
|
|
|
LPWSTR lpCompStr = NULL;
|
|
|
|
DWORD dwBufLen;
|
2010-05-24 07:05:03 +02:00
|
|
|
DWORD dwIndex = lParam & GCS_RESULTSTR;
|
|
|
|
if (!dwIndex)
|
|
|
|
dwIndex = GCS_COMPSTR;
|
2007-06-27 14:57:51 +02:00
|
|
|
|
2010-05-24 07:05:03 +02:00
|
|
|
dwBufLen = ImmGetCompositionStringW(hIMC, dwIndex, NULL, 0);
|
2007-06-27 14:57:51 +02:00
|
|
|
lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR));
|
2010-05-24 07:05:03 +02:00
|
|
|
ImmGetCompositionStringW(hIMC, dwIndex, lpCompStr, dwBufLen);
|
2007-06-27 14:57:51 +02:00
|
|
|
lpCompStr[dwBufLen/sizeof(WCHAR)] = 0;
|
|
|
|
ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style);
|
2010-05-24 07:04:42 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpCompStr);
|
2007-06-27 14:57:51 +02:00
|
|
|
|
2010-05-24 07:05:03 +02:00
|
|
|
if (dwIndex == GCS_COMPSTR)
|
|
|
|
ME_SetSelection(editor,editor->imeStartIndex,
|
|
|
|
editor->imeStartIndex + dwBufLen/sizeof(WCHAR));
|
2007-06-27 14:57:51 +02:00
|
|
|
}
|
|
|
|
ME_ReleaseStyle(style);
|
2010-05-24 07:04:53 +02:00
|
|
|
ME_CommitUndo(editor);
|
2010-07-29 03:17:40 +02:00
|
|
|
ME_UpdateRepaint(editor, FALSE);
|
2007-06-27 14:57:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_IME_ENDCOMPOSITION:
|
|
|
|
{
|
|
|
|
ME_DeleteSelection(editor);
|
|
|
|
editor->imeStartIndex=-1;
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETOLEINTERFACE:
|
2005-03-08 17:46:00 +01:00
|
|
|
{
|
|
|
|
LPVOID *ppvObj = (LPVOID*) lParam;
|
2006-02-23 05:05:11 +01:00
|
|
|
return CreateIRichEditOle(editor, ppvObj);
|
2005-03-08 17:46:00 +01:00
|
|
|
}
|
2006-08-04 21:47:44 +02:00
|
|
|
case EM_GETPASSWORDCHAR:
|
|
|
|
{
|
|
|
|
return editor->cPasswordMask;
|
|
|
|
}
|
2006-02-01 13:05:40 +01:00
|
|
|
case EM_SETOLECALLBACK:
|
|
|
|
if(editor->lpOleCallback)
|
2012-08-01 12:56:19 +02:00
|
|
|
IRichEditOleCallback_Release(editor->lpOleCallback);
|
|
|
|
editor->lpOleCallback = (IRichEditOleCallback*)lParam;
|
2006-02-01 13:05:40 +01:00
|
|
|
if(editor->lpOleCallback)
|
2012-08-01 12:56:19 +02:00
|
|
|
IRichEditOleCallback_AddRef(editor->lpOleCallback);
|
2006-02-01 13:05:40 +01:00
|
|
|
return TRUE;
|
2006-01-12 11:54:57 +01:00
|
|
|
case EM_GETWORDBREAKPROC:
|
|
|
|
return (LRESULT)editor->pfnWordBreak;
|
|
|
|
case EM_SETWORDBREAKPROC:
|
|
|
|
{
|
|
|
|
EDITWORDBREAKPROCW pfnOld = editor->pfnWordBreak;
|
|
|
|
|
|
|
|
editor->pfnWordBreak = (EDITWORDBREAKPROCW)lParam;
|
|
|
|
return (LRESULT)pfnOld;
|
|
|
|
}
|
2009-02-02 07:32:29 +01:00
|
|
|
case EM_GETTEXTMODE:
|
|
|
|
return editor->mode;
|
2006-02-19 07:32:24 +01:00
|
|
|
case EM_SETTEXTMODE:
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
int changes = 0;
|
2008-12-16 09:43:43 +01:00
|
|
|
|
2013-01-29 14:41:48 +01:00
|
|
|
if (ME_GetTextLength(editor) ||
|
|
|
|
!list_empty( &editor->undo_stack ) || !list_empty( &editor->redo_stack ))
|
2010-07-29 20:02:32 +02:00
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
/* Check for mutually exclusive flags in adjacent bits of wParam */
|
|
|
|
if ((wParam & (TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE)) &
|
|
|
|
(wParam & (TM_PLAINTEXT | TM_SINGLELEVELUNDO | TM_SINGLECODEPAGE)) << 1)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
|
2006-02-19 07:32:24 +01:00
|
|
|
{
|
2010-07-29 20:02:32 +02:00
|
|
|
mask |= TM_RICHTEXT | TM_PLAINTEXT;
|
|
|
|
changes |= wParam & (TM_RICHTEXT | TM_PLAINTEXT);
|
2011-01-12 08:23:40 +01:00
|
|
|
if (wParam & TM_PLAINTEXT) {
|
|
|
|
/* Clear selection since it should be possible to select the
|
|
|
|
* end of text run for rich text */
|
|
|
|
ME_InvalidateSelection(editor);
|
|
|
|
ME_SetCursorToStart(editor, &editor->pCursors[0]);
|
|
|
|
editor->pCursors[1] = editor->pCursors[0];
|
|
|
|
/* plain text can only have the default style. */
|
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
ME_AddRefStyle(editor->pBuffer->pDefaultStyle);
|
|
|
|
ME_ReleaseStyle(editor->pCursors[0].pRun->member.run.style);
|
|
|
|
editor->pCursors[0].pRun->member.run.style = editor->pBuffer->pDefaultStyle;
|
|
|
|
}
|
2006-02-19 07:32:24 +01:00
|
|
|
}
|
2010-07-29 20:02:32 +02:00
|
|
|
/* FIXME: Currently no support for undo level and code page options */
|
|
|
|
editor->mode = (editor->mode & ~mask) | changes;
|
|
|
|
return 0;
|
2006-08-04 21:47:44 +02:00
|
|
|
}
|
|
|
|
case EM_SETPASSWORDCHAR:
|
|
|
|
{
|
|
|
|
editor->cPasswordMask = wParam;
|
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-16 21:48:05 +01:00
|
|
|
case EM_SETTARGETDEVICE:
|
|
|
|
if (wParam == 0)
|
|
|
|
{
|
2009-02-24 08:56:18 +01:00
|
|
|
BOOL new = (lParam == 0 && (editor->styleFlags & ES_MULTILINE));
|
2009-02-02 07:32:20 +01:00
|
|
|
if (editor->nAvailWidth || editor->bWordWrap != new)
|
2008-04-14 20:56:51 +02:00
|
|
|
{
|
|
|
|
editor->bWordWrap = new;
|
2009-02-02 07:32:20 +01:00
|
|
|
editor->nAvailWidth = 0; /* wrap to client area */
|
2008-04-14 20:56:51 +02:00
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
}
|
2009-02-02 07:32:20 +01:00
|
|
|
} else {
|
|
|
|
int width = max(0, lParam);
|
2009-02-24 08:56:18 +01:00
|
|
|
if ((editor->styleFlags & ES_MULTILINE) &&
|
|
|
|
(!editor->bWordWrap || editor->nAvailWidth != width))
|
2009-02-02 07:32:20 +01:00
|
|
|
{
|
|
|
|
editor->nAvailWidth = width;
|
|
|
|
editor->bWordWrap = TRUE;
|
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
}
|
|
|
|
FIXME("EM_SETTARGETDEVICE doesn't use non-NULL target devices\n");
|
2008-03-16 21:48:05 +01:00
|
|
|
}
|
2009-02-02 07:32:20 +01:00
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
default:
|
|
|
|
do_default:
|
2008-12-19 16:57:28 +01:00
|
|
|
*phresult = S_FALSE;
|
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
|
|
|
|
LPARAM lParam, BOOL unicode)
|
|
|
|
{
|
|
|
|
ME_TextEditor *editor;
|
|
|
|
HRESULT hresult;
|
2009-01-20 07:41:32 +01:00
|
|
|
LRESULT lresult = 0;
|
2009-01-12 22:48:01 +01:00
|
|
|
|
|
|
|
TRACE("enter hwnd %p msg %04x (%s) %lx %lx, unicode %d\n",
|
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam, unicode);
|
|
|
|
|
|
|
|
editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
|
|
|
|
if (!editor)
|
|
|
|
{
|
|
|
|
if (msg == WM_NCCREATE)
|
|
|
|
{
|
|
|
|
CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
|
2009-01-20 07:41:25 +01:00
|
|
|
ITextHost *texthost;
|
|
|
|
|
2009-01-12 22:48:01 +01:00
|
|
|
TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
|
2009-09-30 16:46:37 +02:00
|
|
|
texthost = ME_CreateTextHost(hWnd, pcs, FALSE);
|
2009-01-20 07:41:25 +01:00
|
|
|
return texthost != NULL;
|
2009-01-12 22:48:01 +01:00
|
|
|
}
|
2010-07-08 01:10:02 +02:00
|
|
|
else
|
2009-01-12 22:48:01 +01:00
|
|
|
{
|
2010-07-08 01:10:02 +02:00
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
2009-01-12 22:48:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-20 07:41:36 +01:00
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_PAINT:
|
|
|
|
{
|
|
|
|
HDC hDC;
|
|
|
|
RECT rc;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
|
|
|
|
hDC = BeginPaint(editor->hWnd, &ps);
|
2010-07-29 03:17:13 +02:00
|
|
|
if (!editor->bEmulateVersion10 || (editor->nEventMask & ENM_UPDATE))
|
|
|
|
ME_SendOldNotify(editor, EN_UPDATE);
|
2009-01-20 07:41:36 +01:00
|
|
|
/* Erase area outside of the formatting rectangle */
|
|
|
|
if (ps.rcPaint.top < editor->rcFormat.top)
|
|
|
|
{
|
|
|
|
rc = ps.rcPaint;
|
|
|
|
rc.bottom = editor->rcFormat.top;
|
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
|
|
|
ps.rcPaint.top = editor->rcFormat.top;
|
|
|
|
}
|
|
|
|
if (ps.rcPaint.bottom > editor->rcFormat.bottom) {
|
|
|
|
rc = ps.rcPaint;
|
|
|
|
rc.top = editor->rcFormat.bottom;
|
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
|
|
|
ps.rcPaint.bottom = editor->rcFormat.bottom;
|
|
|
|
}
|
|
|
|
if (ps.rcPaint.left < editor->rcFormat.left) {
|
|
|
|
rc = ps.rcPaint;
|
|
|
|
rc.right = editor->rcFormat.left;
|
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
|
|
|
ps.rcPaint.left = editor->rcFormat.left;
|
|
|
|
}
|
|
|
|
if (ps.rcPaint.right > editor->rcFormat.right) {
|
|
|
|
rc = ps.rcPaint;
|
|
|
|
rc.left = editor->rcFormat.right;
|
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
|
|
|
ps.rcPaint.right = editor->rcFormat.right;
|
|
|
|
}
|
|
|
|
|
2012-05-08 04:11:55 +02:00
|
|
|
ME_PaintContent(editor, hDC, &ps.rcPaint);
|
2009-01-20 07:41:36 +01:00
|
|
|
EndPaint(editor->hWnd, &ps);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
{
|
|
|
|
HDC hDC = (HDC)wParam;
|
|
|
|
RECT rc;
|
|
|
|
|
|
|
|
if (GetUpdateRect(editor->hWnd, &rc, TRUE))
|
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case EM_SETOPTIONS:
|
|
|
|
{
|
|
|
|
DWORD dwStyle;
|
|
|
|
const DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
|
|
|
|
ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN |
|
|
|
|
ECO_SELECTIONBAR;
|
|
|
|
lresult = ME_HandleMessage(editor, msg, wParam, lParam, unicode, &hresult);
|
|
|
|
dwStyle = GetWindowLongW(hWnd, GWL_STYLE);
|
|
|
|
dwStyle = (dwStyle & ~mask) | (lresult & mask);
|
|
|
|
SetWindowLongW(hWnd, GWL_STYLE, dwStyle);
|
|
|
|
return lresult;
|
|
|
|
}
|
|
|
|
case EM_SETREADONLY:
|
|
|
|
{
|
|
|
|
DWORD dwStyle;
|
|
|
|
lresult = ME_HandleMessage(editor, msg, wParam, lParam, unicode, &hresult);
|
|
|
|
dwStyle = GetWindowLongW(hWnd, GWL_STYLE);
|
|
|
|
dwStyle &= ~ES_READONLY;
|
|
|
|
if (wParam)
|
|
|
|
dwStyle |= ES_READONLY;
|
|
|
|
SetWindowLongW(hWnd, GWL_STYLE, dwStyle);
|
|
|
|
return lresult;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
lresult = ME_HandleMessage(editor, msg, wParam, lParam, unicode, &hresult);
|
|
|
|
}
|
2009-01-12 22:48:01 +01:00
|
|
|
|
|
|
|
if (hresult == S_FALSE)
|
|
|
|
lresult = DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
|
|
|
|
TRACE("exit hwnd %p msg %04x (%s) %lx %lx, unicode %d -> %lu\n",
|
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam, unicode, lresult);
|
|
|
|
|
|
|
|
return lresult;
|
|
|
|
}
|
|
|
|
|
2007-03-22 12:09:43 +01:00
|
|
|
static LRESULT WINAPI RichEditWndProcW(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
BOOL unicode = TRUE;
|
|
|
|
|
|
|
|
/* Under Win9x RichEdit20W returns ANSI strings, see the tests. */
|
|
|
|
if (msg == WM_GETTEXT && (GetVersion() & 0x80000000))
|
|
|
|
unicode = FALSE;
|
|
|
|
|
|
|
|
return RichEditWndProc_common(hWnd, msg, wParam, lParam, unicode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT WINAPI RichEditWndProcA(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return RichEditWndProc_common(hWnd, msg, wParam, lParam, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RichEditANSIWndProc (RICHED20.10)
|
|
|
|
*/
|
|
|
|
LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return RichEditWndProcA(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
2005-07-24 18:17:43 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/******************************************************************
|
|
|
|
* RichEdit10ANSIWndProc (RICHED20.9)
|
|
|
|
*/
|
|
|
|
LRESULT WINAPI RichEdit10ANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2009-01-11 08:59:31 +01:00
|
|
|
if (msg == WM_NCCREATE && !GetWindowLongPtrW(hWnd, 0))
|
2005-07-21 12:33:32 +02:00
|
|
|
{
|
2009-01-20 07:41:25 +01:00
|
|
|
ITextHost *texthost;
|
2009-01-11 08:59:31 +01:00
|
|
|
CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
|
|
|
|
|
|
|
|
TRACE("WM_NCCREATE: hWnd %p style 0x%08x\n", hWnd, pcs->style);
|
2009-09-30 16:46:37 +02:00
|
|
|
texthost = ME_CreateTextHost(hWnd, pcs, TRUE);
|
2009-01-20 07:41:25 +01:00
|
|
|
return texthost != NULL;
|
2005-07-21 12:33:32 +02:00
|
|
|
}
|
2009-01-11 08:59:31 +01:00
|
|
|
return RichEditANSIWndProc(hWnd, msg, wParam, lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
|
|
|
|
{
|
2009-01-20 07:41:32 +01:00
|
|
|
ITextHost_TxNotify(editor->texthost, nCode, NULL);
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
/* Fill buffer with srcChars unicode characters from the start cursor.
|
|
|
|
*
|
|
|
|
* buffer: destination buffer
|
|
|
|
* buflen: length of buffer in characters excluding the NULL terminator.
|
|
|
|
* start: start of editor text to copy into buffer.
|
|
|
|
* srcChars: Number of characters to use from the editor text.
|
|
|
|
* bCRLF: if true, replaces all end of lines with \r\n pairs.
|
|
|
|
*
|
|
|
|
* returns the number of characters written excluding the NULL terminator.
|
|
|
|
*
|
|
|
|
* The written text is always NULL terminated.
|
|
|
|
*/
|
|
|
|
int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen,
|
|
|
|
const ME_Cursor *start, int srcChars, BOOL bCRLF)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
ME_DisplayItem *pRun, *pNextRun;
|
|
|
|
const WCHAR *pStart = buffer;
|
|
|
|
const WCHAR cr_lf[] = {'\r', '\n', 0};
|
|
|
|
const WCHAR *str;
|
|
|
|
int nLen;
|
2009-01-27 09:39:17 +01:00
|
|
|
|
2008-04-27 03:37:50 +02:00
|
|
|
/* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
|
|
|
|
if (editor->bEmulateVersion10) bCRLF = 0;
|
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
pRun = start->pRun;
|
|
|
|
assert(pRun);
|
|
|
|
pNextRun = ME_FindItemFwd(pRun, diRun);
|
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
nLen = pRun->member.run.len - start->nOffset;
|
2013-01-30 16:10:20 +01:00
|
|
|
str = get_text( &pRun->member.run, start->nOffset );
|
2009-08-12 15:05:51 +02:00
|
|
|
|
|
|
|
/* No '\r' is appended to the last paragraph. */
|
|
|
|
while (srcChars && buflen && pNextRun)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
int nFlags = pRun->member.run.nFlags;
|
2006-04-23 21:09:30 +02:00
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
if (bCRLF && nFlags & MERF_ENDPARA && ~nFlags & MERF_ENDCELL)
|
2008-08-07 18:31:41 +02:00
|
|
|
{
|
2009-08-12 15:05:51 +02:00
|
|
|
if (buflen == 1) break;
|
|
|
|
/* FIXME: native fails to reduce srcChars here for WM_GETTEXT or
|
|
|
|
* EM_GETTEXTEX, however, this is done for copying text which
|
|
|
|
* also uses this function. */
|
|
|
|
srcChars -= min(nLen, srcChars);
|
|
|
|
nLen = 2;
|
|
|
|
str = cr_lf;
|
2009-01-27 09:39:17 +01:00
|
|
|
} else {
|
2009-08-12 15:05:51 +02:00
|
|
|
nLen = min(nLen, srcChars);
|
|
|
|
srcChars -= nLen;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2009-08-12 15:05:51 +02:00
|
|
|
|
|
|
|
nLen = min(nLen, buflen);
|
|
|
|
buflen -= nLen;
|
|
|
|
|
|
|
|
CopyMemory(buffer, str, sizeof(WCHAR) * nLen);
|
|
|
|
|
2009-01-27 09:39:17 +01:00
|
|
|
buffer += nLen;
|
|
|
|
|
2009-08-12 15:05:51 +02:00
|
|
|
pRun = pNextRun;
|
|
|
|
pNextRun = ME_FindItemFwd(pRun, diRun);
|
|
|
|
|
2013-01-31 14:48:00 +01:00
|
|
|
nLen = pRun->member.run.len;
|
2013-01-30 16:10:20 +01:00
|
|
|
str = get_text( &pRun->member.run, 0 );
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2007-03-22 12:09:43 +01:00
|
|
|
*buffer = 0;
|
2009-08-12 15:05:51 +02:00
|
|
|
return buffer - pStart;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
2007-03-21 11:26:19 +01:00
|
|
|
static BOOL ME_RegisterEditorClass(HINSTANCE hInstance)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
|
|
|
WNDCLASSW wcW;
|
|
|
|
WNDCLASSA wcA;
|
|
|
|
|
2006-01-13 13:54:11 +01:00
|
|
|
wcW.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
2007-03-22 12:09:43 +01:00
|
|
|
wcW.lpfnWndProc = RichEditWndProcW;
|
2005-03-05 12:19:14 +01:00
|
|
|
wcW.cbClsExtra = 0;
|
2006-08-03 18:20:01 +02:00
|
|
|
wcW.cbWndExtra = sizeof(ME_TextEditor *);
|
2005-03-05 12:19:14 +01:00
|
|
|
wcW.hInstance = NULL; /* hInstance would register DLL-local class */
|
|
|
|
wcW.hIcon = NULL;
|
2008-03-16 21:48:22 +01:00
|
|
|
wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
|
2008-11-03 22:36:03 +01:00
|
|
|
wcW.hbrBackground = GetStockObject(NULL_BRUSH);
|
2005-03-05 12:19:14 +01:00
|
|
|
wcW.lpszMenuName = NULL;
|
2007-03-21 11:26:19 +01:00
|
|
|
|
|
|
|
if (is_version_nt())
|
|
|
|
{
|
2009-08-10 16:53:36 +02:00
|
|
|
wcW.lpszClassName = RICHEDIT_CLASS20W;
|
2007-03-21 11:26:19 +01:00
|
|
|
if (!RegisterClassW(&wcW)) return FALSE;
|
2009-08-10 16:53:36 +02:00
|
|
|
wcW.lpszClassName = MSFTEDIT_CLASS;
|
2007-03-21 11:26:19 +01:00
|
|
|
if (!RegisterClassW(&wcW)) return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* WNDCLASSA/W have the same layout */
|
|
|
|
wcW.lpszClassName = (LPCWSTR)"RichEdit20W";
|
|
|
|
if (!RegisterClassA((WNDCLASSA *)&wcW)) return FALSE;
|
|
|
|
wcW.lpszClassName = (LPCWSTR)"RichEdit50W";
|
|
|
|
if (!RegisterClassA((WNDCLASSA *)&wcW)) return FALSE;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2006-01-13 13:54:11 +01:00
|
|
|
wcA.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
2007-03-22 12:09:43 +01:00
|
|
|
wcA.lpfnWndProc = RichEditWndProcA;
|
2005-03-05 12:19:14 +01:00
|
|
|
wcA.cbClsExtra = 0;
|
2006-08-03 18:20:01 +02:00
|
|
|
wcA.cbWndExtra = sizeof(ME_TextEditor *);
|
2005-03-05 12:19:14 +01:00
|
|
|
wcA.hInstance = NULL; /* hInstance would register DLL-local class */
|
|
|
|
wcA.hIcon = NULL;
|
|
|
|
wcA.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
|
2008-11-03 22:36:03 +01:00
|
|
|
wcA.hbrBackground = GetStockObject(NULL_BRUSH);
|
2005-03-05 12:19:14 +01:00
|
|
|
wcA.lpszMenuName = NULL;
|
2009-08-10 16:53:36 +02:00
|
|
|
wcA.lpszClassName = RICHEDIT_CLASS20A;
|
2007-03-21 11:26:19 +01:00
|
|
|
if (!RegisterClassA(&wcA)) return FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
wcA.lpszClassName = "RichEdit50A";
|
2007-03-21 11:26:19 +01:00
|
|
|
if (!RegisterClassA(&wcA)) return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-01-30 18:16:05 +01:00
|
|
|
|
2009-05-26 00:48:48 +02:00
|
|
|
static LRESULT WINAPI REComboWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
2005-12-05 12:48:45 +01:00
|
|
|
/* FIXME: Not implemented */
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
|
2005-12-05 12:48:45 +01:00
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam);
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2009-05-26 00:48:48 +02:00
|
|
|
static LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
2005-12-05 12:48:45 +01:00
|
|
|
/* FIXME: Not implemented */
|
2007-05-24 16:41:17 +02:00
|
|
|
TRACE("hWnd %p msg %04x (%s) %08lx %08lx\n",
|
2005-12-05 12:48:45 +01:00
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam);
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/******************************************************************
|
|
|
|
* REExtendedRegisterClass (RICHED20.8)
|
|
|
|
*
|
|
|
|
* FIXME undocumented
|
2005-12-05 12:48:45 +01:00
|
|
|
* Need to check for errors and implement controls and callbacks
|
2005-03-05 12:19:14 +01:00
|
|
|
*/
|
2005-12-05 12:48:45 +01:00
|
|
|
LRESULT WINAPI REExtendedRegisterClass(void)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2005-12-05 12:48:45 +01:00
|
|
|
WNDCLASSW wcW;
|
|
|
|
UINT result;
|
|
|
|
|
|
|
|
FIXME("semi stub\n");
|
|
|
|
|
|
|
|
wcW.cbClsExtra = 0;
|
|
|
|
wcW.cbWndExtra = 4;
|
|
|
|
wcW.hInstance = NULL;
|
|
|
|
wcW.hIcon = NULL;
|
|
|
|
wcW.hCursor = NULL;
|
|
|
|
wcW.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|
|
|
wcW.lpszMenuName = NULL;
|
|
|
|
|
|
|
|
if (!ME_ListBoxRegistered)
|
|
|
|
{
|
|
|
|
wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS;
|
|
|
|
wcW.lpfnWndProc = REListWndProc;
|
2007-03-21 11:26:19 +01:00
|
|
|
wcW.lpszClassName = REListBox20W;
|
2005-12-05 12:48:45 +01:00
|
|
|
if (RegisterClassW(&wcW)) ME_ListBoxRegistered = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ME_ComboBoxRegistered)
|
|
|
|
{
|
|
|
|
wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
|
|
|
|
wcW.lpfnWndProc = REComboWndProc;
|
2007-03-21 11:26:19 +01:00
|
|
|
wcW.lpszClassName = REComboBox20W;
|
2005-12-05 12:48:45 +01:00
|
|
|
if (RegisterClassW(&wcW)) ME_ComboBoxRegistered = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
if (ME_ListBoxRegistered)
|
|
|
|
result += 1;
|
|
|
|
if (ME_ComboBoxRegistered)
|
|
|
|
result += 2;
|
|
|
|
|
|
|
|
return result;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-03-01 11:49:42 +01:00
|
|
|
|
2008-06-18 17:54:17 +02:00
|
|
|
static BOOL isurlspecial(WCHAR c)
|
|
|
|
{
|
|
|
|
static const WCHAR special_chars[] = {'.','/','%','@','*','|','\\','+','#',0};
|
|
|
|
return strchrW( special_chars, c ) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This proc takes a selection, and scans it forward in order to select the span
|
|
|
|
* of a possible URL candidate. A possible URL candidate must start with isalnum
|
|
|
|
* or one of the following special characters: *|/\+%#@ and must consist entirely
|
|
|
|
* of the characters allowed to start the URL, plus : (colon) which may occur
|
|
|
|
* at most once, and not at either end.
|
|
|
|
*/
|
2009-08-13 14:44:02 +02:00
|
|
|
static BOOL ME_FindNextURLCandidate(ME_TextEditor *editor,
|
|
|
|
const ME_Cursor *start,
|
|
|
|
int nChars,
|
|
|
|
ME_Cursor *candidate_min,
|
|
|
|
ME_Cursor *candidate_max)
|
2008-06-18 17:54:17 +02:00
|
|
|
{
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_Cursor cursor = *start;
|
2008-06-18 17:54:17 +02:00
|
|
|
BOOL foundColon = FALSE;
|
2009-08-13 14:44:02 +02:00
|
|
|
BOOL candidateStarted = FALSE;
|
2008-06-18 17:54:17 +02:00
|
|
|
WCHAR lastAcceptedChar = '\0';
|
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
while (nChars > 0)
|
2008-06-18 17:54:17 +02:00
|
|
|
{
|
2013-01-30 16:10:20 +01:00
|
|
|
WCHAR *strStart = get_text( &cursor.pRun->member.run, 0 );
|
2009-08-13 14:44:02 +02:00
|
|
|
WCHAR *str = strStart + cursor.nOffset;
|
2013-01-31 14:48:00 +01:00
|
|
|
int nLen = cursor.pRun->member.run.len - cursor.nOffset;
|
2009-08-13 14:44:02 +02:00
|
|
|
nChars -= nLen;
|
|
|
|
|
|
|
|
if (~cursor.pRun->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
{
|
2008-06-18 17:54:17 +02:00
|
|
|
/* Find start of candidate */
|
2009-08-13 14:44:02 +02:00
|
|
|
if (!candidateStarted)
|
|
|
|
{
|
|
|
|
while (nLen)
|
|
|
|
{
|
|
|
|
nLen--;
|
|
|
|
if (isalnumW(*str) || isurlspecial(*str))
|
|
|
|
{
|
|
|
|
cursor.nOffset = str - strStart;
|
|
|
|
*candidate_min = cursor;
|
|
|
|
candidateStarted = TRUE;
|
|
|
|
lastAcceptedChar = *str++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str++;
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find end of candidate */
|
2009-08-13 14:44:02 +02:00
|
|
|
if (candidateStarted) {
|
|
|
|
while (nLen)
|
|
|
|
{
|
|
|
|
nLen--;
|
|
|
|
if (*str == ':' && !foundColon) {
|
|
|
|
foundColon = TRUE;
|
|
|
|
} else if (!isalnumW(*str) && !isurlspecial(*str)) {
|
|
|
|
cursor.nOffset = str - strStart;
|
|
|
|
if (lastAcceptedChar == ':')
|
|
|
|
ME_MoveCursorChars(editor, &cursor, -1);
|
|
|
|
*candidate_max = cursor;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
lastAcceptedChar = *str++;
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* End of paragraph: skip it if before candidate span, or terminates
|
|
|
|
current active span */
|
2009-08-13 14:44:02 +02:00
|
|
|
if (candidateStarted) {
|
|
|
|
if (lastAcceptedChar == ':')
|
|
|
|
ME_MoveCursorChars(editor, &cursor, -1);
|
|
|
|
*candidate_max = cursor;
|
2008-06-18 17:54:17 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reaching this point means no span was found, so get next span */
|
2009-08-13 14:44:02 +02:00
|
|
|
if (!ME_NextRun(&cursor.pPara, &cursor.pRun)) {
|
|
|
|
if (candidateStarted) {
|
2008-06-18 17:54:17 +02:00
|
|
|
/* There are no further runs, so take end of text as end of candidate */
|
2009-08-13 14:44:02 +02:00
|
|
|
cursor.nOffset = str - strStart;
|
|
|
|
if (lastAcceptedChar == ':')
|
|
|
|
ME_MoveCursorChars(editor, &cursor, -1);
|
|
|
|
*candidate_max = cursor;
|
2008-06-18 17:54:17 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2009-08-13 14:44:02 +02:00
|
|
|
*candidate_max = *candidate_min = cursor;
|
2009-08-12 15:06:00 +02:00
|
|
|
return FALSE;
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
2009-08-13 14:44:02 +02:00
|
|
|
cursor.nOffset = 0;
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
if (candidateStarted) {
|
|
|
|
/* There are no further runs, so take end of text as end of candidate */
|
|
|
|
if (lastAcceptedChar == ':')
|
|
|
|
ME_MoveCursorChars(editor, &cursor, -1);
|
|
|
|
*candidate_max = cursor;
|
|
|
|
return TRUE;
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
2009-08-13 14:44:02 +02:00
|
|
|
*candidate_max = *candidate_min = cursor;
|
2008-06-18 17:54:17 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This proc evaluates the selection and returns TRUE if it can be considered an URL
|
|
|
|
*/
|
2009-08-12 15:05:56 +02:00
|
|
|
static BOOL ME_IsCandidateAnURL(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
|
2008-06-18 17:54:17 +02:00
|
|
|
{
|
2009-08-12 15:05:56 +02:00
|
|
|
#define MAX_PREFIX_LEN 9
|
2008-06-18 17:54:17 +02:00
|
|
|
struct prefix_s {
|
2009-08-12 15:05:56 +02:00
|
|
|
const WCHAR text[MAX_PREFIX_LEN];
|
2008-06-18 17:54:17 +02:00
|
|
|
int length;
|
2009-08-12 15:05:56 +02:00
|
|
|
}prefixes[] = {
|
|
|
|
{{'p','r','o','s','p','e','r','o',':'}, 9},
|
|
|
|
{{'t','e','l','n','e','t',':'}, 7},
|
|
|
|
{{'g','o','p','h','e','r',':'}, 7},
|
|
|
|
{{'m','a','i','l','t','o',':'}, 7},
|
|
|
|
{{'h','t','t','p','s',':'}, 6},
|
|
|
|
{{'f','i','l','e',':'}, 5},
|
|
|
|
{{'n','e','w','s',':'}, 5},
|
|
|
|
{{'w','a','i','s',':'}, 5},
|
|
|
|
{{'n','n','t','p',':'}, 5},
|
|
|
|
{{'h','t','t','p',':'}, 5},
|
|
|
|
{{'w','w','w','.'}, 4},
|
|
|
|
{{'f','t','p',':'}, 4},
|
2008-06-18 17:54:17 +02:00
|
|
|
};
|
2009-08-12 15:05:56 +02:00
|
|
|
WCHAR bufferW[MAX_PREFIX_LEN + 1];
|
2008-11-05 21:48:37 +01:00
|
|
|
unsigned int i;
|
2008-06-18 17:54:17 +02:00
|
|
|
|
2009-08-12 15:05:56 +02:00
|
|
|
ME_GetTextW(editor, bufferW, MAX_PREFIX_LEN, start, nChars, 0);
|
|
|
|
for (i = 0; i < sizeof(prefixes) / sizeof(*prefixes); i++)
|
2008-06-18 17:54:17 +02:00
|
|
|
{
|
2009-08-12 15:05:56 +02:00
|
|
|
if (nChars < prefixes[i].length) continue;
|
|
|
|
if (!memcmp(prefixes[i].text, bufferW, prefixes[i].length * sizeof(WCHAR)))
|
2008-06-18 17:54:17 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2009-08-12 15:05:56 +02:00
|
|
|
#undef MAX_PREFIX_LEN
|
2008-06-18 17:54:17 +02:00
|
|
|
}
|
2008-06-18 18:05:52 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This proc walks through the indicated selection and evaluates whether each
|
|
|
|
* section identified by ME_FindNextURLCandidate and in-between sections have
|
|
|
|
* their proper CFE_LINK attributes set or unset. If the CFE_LINK attribute is
|
|
|
|
* not what it is supposed to be, this proc sets or unsets it as appropriate.
|
|
|
|
*
|
2009-08-13 14:44:02 +02:00
|
|
|
* Since this function can cause runs to be split, do not depend on the value
|
|
|
|
* of the start cursor at the end of the function.
|
|
|
|
*
|
|
|
|
* nChars may be set to INT_MAX to update to the end of the text.
|
|
|
|
*
|
2008-06-18 18:05:52 +02:00
|
|
|
* Returns TRUE if at least one section was modified.
|
|
|
|
*/
|
2009-08-13 14:44:02 +02:00
|
|
|
static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, ME_Cursor *start, int nChars)
|
2008-06-18 18:05:52 +02:00
|
|
|
{
|
|
|
|
BOOL modified = FALSE;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_Cursor startCur = *start;
|
2008-06-18 18:05:52 +02:00
|
|
|
|
2009-03-09 08:01:00 +01:00
|
|
|
if (!editor->AutoURLDetect_bEnable) return FALSE;
|
|
|
|
|
2008-06-18 18:05:52 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
CHARFORMAT2W link;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_Cursor candidateStart, candidateEnd;
|
2008-06-18 18:05:52 +02:00
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
if (ME_FindNextURLCandidate(editor, &startCur, nChars,
|
|
|
|
&candidateStart, &candidateEnd))
|
2008-06-18 18:05:52 +02:00
|
|
|
{
|
|
|
|
/* Section before candidate is not an URL */
|
2009-08-13 14:44:02 +02:00
|
|
|
int cMin = ME_GetCursorOfs(&candidateStart);
|
|
|
|
int cMax = ME_GetCursorOfs(&candidateEnd);
|
2008-06-18 18:05:52 +02:00
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
if (!ME_IsCandidateAnURL(editor, &candidateStart, cMax - cMin))
|
|
|
|
candidateStart = candidateEnd;
|
|
|
|
nChars -= cMax - ME_GetCursorOfs(&startCur);
|
2008-06-18 18:05:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No more candidates until end of selection */
|
2009-08-13 14:44:02 +02:00
|
|
|
nChars = 0;
|
2008-06-18 18:05:52 +02:00
|
|
|
}
|
|
|
|
|
2009-08-13 14:44:02 +02:00
|
|
|
if (startCur.pRun != candidateStart.pRun ||
|
|
|
|
startCur.nOffset != candidateStart.nOffset)
|
2008-06-18 18:05:52 +02:00
|
|
|
{
|
|
|
|
/* CFE_LINK effect should be consistently unset */
|
|
|
|
link.cbSize = sizeof(link);
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_GetCharFormat(editor, &startCur, &candidateStart, &link);
|
2008-06-18 18:05:52 +02:00
|
|
|
if (!(link.dwMask & CFM_LINK) || (link.dwEffects & CFE_LINK))
|
|
|
|
{
|
|
|
|
/* CFE_LINK must be unset from this range */
|
|
|
|
memset(&link, 0, sizeof(CHARFORMAT2W));
|
|
|
|
link.cbSize = sizeof(link);
|
|
|
|
link.dwMask = CFM_LINK;
|
|
|
|
link.dwEffects = 0;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_SetCharFormat(editor, &startCur, &candidateStart, &link);
|
|
|
|
/* Update candidateEnd since setting character formats may split
|
|
|
|
* runs, which can cause a cursor to be at an invalid offset within
|
|
|
|
* a split run. */
|
2013-01-31 14:48:00 +01:00
|
|
|
while (candidateEnd.nOffset >= candidateEnd.pRun->member.run.len)
|
2009-08-13 14:44:02 +02:00
|
|
|
{
|
2013-01-31 14:48:00 +01:00
|
|
|
candidateEnd.nOffset -= candidateEnd.pRun->member.run.len;
|
2009-08-13 14:44:02 +02:00
|
|
|
candidateEnd.pRun = ME_FindItemFwd(candidateEnd.pRun, diRun);
|
|
|
|
}
|
2008-06-18 18:05:52 +02:00
|
|
|
modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-08-13 14:44:02 +02:00
|
|
|
if (candidateStart.pRun != candidateEnd.pRun ||
|
|
|
|
candidateStart.nOffset != candidateEnd.nOffset)
|
2008-06-18 18:05:52 +02:00
|
|
|
{
|
|
|
|
/* CFE_LINK effect should be consistently set */
|
|
|
|
link.cbSize = sizeof(link);
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_GetCharFormat(editor, &candidateStart, &candidateEnd, &link);
|
2008-06-18 18:05:52 +02:00
|
|
|
if (!(link.dwMask & CFM_LINK) || !(link.dwEffects & CFE_LINK))
|
|
|
|
{
|
|
|
|
/* CFE_LINK must be set on this range */
|
|
|
|
memset(&link, 0, sizeof(CHARFORMAT2W));
|
|
|
|
link.cbSize = sizeof(link);
|
|
|
|
link.dwMask = CFM_LINK;
|
|
|
|
link.dwEffects = CFE_LINK;
|
2009-08-13 14:44:02 +02:00
|
|
|
ME_SetCharFormat(editor, &candidateStart, &candidateEnd, &link);
|
2008-06-18 18:05:52 +02:00
|
|
|
modified = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2009-08-13 14:44:02 +02:00
|
|
|
startCur = candidateEnd;
|
|
|
|
} while (nChars > 0);
|
2008-06-18 18:05:52 +02:00
|
|
|
return modified;
|
|
|
|
}
|