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
|
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
|
|
|
|
- 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)
|
2006-02-16 19:33:19 +01:00
|
|
|
+ EM_GETSCROLLPOS 3.0 (only Y value valid)
|
2005-03-05 12:19:14 +01:00
|
|
|
! - EM_GETTHUMB
|
2005-05-13 19:45:43 +02:00
|
|
|
- EM_GETTEXTEX 2.0
|
2005-06-28 15:51:32 +02:00
|
|
|
+ EM_GETTEXTLENGTHEX (GTL_PRECISE unimplemented)
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_GETTEXTMODE 2.0
|
|
|
|
? + 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
|
|
|
|
- EM_SETLANGOPTIONS 2.0
|
|
|
|
- EM_SETLIMITTEXT
|
|
|
|
+ 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
|
2005-03-05 12:19:14 +01:00
|
|
|
- EM_SETTARGETDEVICE
|
2005-07-20 12:28:44 +02:00
|
|
|
+ EM_SETTEXTEX 3.0 (unicode only, no rich text insertion handling, 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
|
2005-03-05 12:19:14 +01: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)
|
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
|
|
|
|
- WM_STYLECHANGING
|
|
|
|
- WM_STYLECHANGED (things like read-only flag)
|
|
|
|
- WM_UNICHAR
|
|
|
|
|
|
|
|
Notifications
|
|
|
|
|
|
|
|
* 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
|
|
|
|
- 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
|
|
|
|
* - Undo coalescing
|
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)
|
|
|
|
* - horizontal scrolling (not even started)
|
|
|
|
* - 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"
|
2006-01-30 18:16:05 +01:00
|
|
|
#include "imm.h"
|
|
|
|
#include "textserv.h"
|
2005-03-07 18:15:33 +01:00
|
|
|
#include "rtf.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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
|
2005-04-13 13:11:03 +02:00
|
|
|
WCHAR *pText;
|
2005-03-08 20:03:01 +01:00
|
|
|
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("%08x %p\n", dwFormat, stream);
|
2005-03-08 20:03:01 +01:00
|
|
|
|
|
|
|
do {
|
2005-04-13 13:11:03 +02:00
|
|
|
long nWideChars = 0;
|
|
|
|
|
|
|
|
if (!stream->dwSize)
|
|
|
|
{
|
|
|
|
ME_StreamInFill(stream);
|
|
|
|
if (stream->editstream->dwError)
|
|
|
|
break;
|
|
|
|
if (!stream->dwSize)
|
|
|
|
break;
|
|
|
|
}
|
2005-03-08 20:03:01 +01:00
|
|
|
|
|
|
|
if (!(dwFormat & SF_UNICODE))
|
|
|
|
{
|
|
|
|
/* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
|
2005-04-13 13:11:03 +02:00
|
|
|
nWideChars = MultiByteToWideChar(CP_ACP, 0, stream->buffer, stream->dwSize, wszText, STREAMIN_BUFFER_SIZE);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2005-03-15 16:40:52 +01:00
|
|
|
ME_CommitUndo(editor);
|
2006-01-26 13:28:35 +01:00
|
|
|
ME_UpdateRepaint(editor);
|
2005-03-08 20:03:01 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2005-07-05 14:49:14 +02:00
|
|
|
static 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 */
|
|
|
|
fmt.dwMask = CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | 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 */
|
|
|
|
fmt.wWeight = 400;
|
2005-03-15 16:40:52 +01:00
|
|
|
break;
|
2005-03-11 11:24:56 +01:00
|
|
|
case rtfBold:
|
|
|
|
fmt.dwMask = CFM_BOLD;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
|
|
|
break;
|
|
|
|
case rtfItalic:
|
|
|
|
fmt.dwMask = CFM_ITALIC;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
|
|
|
break;
|
|
|
|
case rtfUnderline:
|
|
|
|
fmt.dwMask = CFM_UNDERLINE;
|
|
|
|
fmt.dwEffects = info->rtfParam ? fmt.dwMask : 0;
|
2005-06-12 12:43:24 +02:00
|
|
|
fmt.bUnderlineType = CFU_CF1UNDERLINE;
|
|
|
|
break;
|
|
|
|
case rtfNoUnderline:
|
|
|
|
fmt.dwMask = CFM_UNDERLINE;
|
|
|
|
fmt.dwEffects = 0;
|
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);
|
|
|
|
fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
|
|
|
|
}
|
|
|
|
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);
|
2006-10-09 13:11:32 +02:00
|
|
|
if (c)
|
|
|
|
fmt.crTextColor = (c->rtfCBlue<<16)|(c->rtfCGreen<<8)|(c->rtfCRed);
|
|
|
|
else
|
|
|
|
fmt.crTextColor = 0;
|
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;
|
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 */
|
2005-07-05 14:49:14 +02:00
|
|
|
static 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 */
|
2005-04-16 12:48:35 +02:00
|
|
|
fmt.dwMask = PFM_ALIGNMENT | PFM_TABSTOPS | PFM_OFFSET | PFM_STARTINDENT;
|
2005-03-11 11:24:56 +01:00
|
|
|
fmt.wAlignment = PFA_LEFT;
|
2005-04-16 12:48:35 +02:00
|
|
|
fmt.cTabCount = 0;
|
|
|
|
fmt.dxOffset = fmt.dxStartIndent = 0;
|
2006-02-04 17:01:01 +01:00
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
ME_GetParagraph(info->editor->pCursors[0].pRun)->member.para.bTable = FALSE;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
2006-02-04 17:01:01 +01:00
|
|
|
case rtfInTable:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *para;
|
|
|
|
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
para = ME_GetParagraph(info->editor->pCursors[0].pRun);
|
|
|
|
assert(para->member.para.pCells);
|
|
|
|
para->member.para.bTable = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
case rtfFirstIndent:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
2006-01-09 17:12:51 +01:00
|
|
|
fmt.dwMask = PFM_STARTINDENT | PFM_OFFSET;
|
|
|
|
fmt.dxStartIndent += info->rtfParam + fmt.dxOffset;
|
|
|
|
fmt.dxOffset = -info->rtfParam;
|
2005-04-16 12:48:35 +02:00
|
|
|
break;
|
|
|
|
case rtfLeftIndent:
|
|
|
|
ME_GetSelectionParaFormat(info->editor, &fmt);
|
2006-01-09 17:12:51 +01:00
|
|
|
fmt.dwMask = PFM_STARTINDENT;
|
|
|
|
fmt.dxStartIndent = -fmt.dxOffset + info->rtfParam;
|
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.dwMask |= PFM_TABSTOPS;
|
|
|
|
fmt.cTabCount = 0;
|
|
|
|
}
|
|
|
|
if (fmt.cTabCount < MAX_TAB_STOPS)
|
|
|
|
fmt.rgxTabs[fmt.cTabCount++] = info->rtfParam;
|
|
|
|
break;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
static void ME_RTFTblAttrHook(RTF_Info *info)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *para;
|
|
|
|
|
|
|
|
switch (info->rtfMinor)
|
|
|
|
{
|
|
|
|
case rtfRowDef:
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
para = ME_GetParagraph(info->editor->pCursors[0].pRun);
|
|
|
|
|
2006-04-12 00:00:01 +02:00
|
|
|
/* Release possibly inherited cell definitions */
|
|
|
|
ME_DestroyTableCellList(para);
|
|
|
|
|
2006-02-04 17:01:01 +01:00
|
|
|
para->member.para.pCells = ALLOC_OBJ(ME_TableCell);
|
|
|
|
para->member.para.pCells->nRightBoundary = 0;
|
|
|
|
para->member.para.pCells->next = NULL;
|
|
|
|
para->member.para.pLastCell = para->member.para.pCells;
|
|
|
|
break;
|
|
|
|
case rtfCellPos:
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
para = ME_GetParagraph(info->editor->pCursors[0].pRun);
|
|
|
|
|
|
|
|
if (para->member.para.pLastCell->nRightBoundary)
|
|
|
|
{
|
|
|
|
ME_TableCell *pCell = ALLOC_OBJ(ME_TableCell);
|
|
|
|
|
|
|
|
pCell->next = NULL;
|
|
|
|
para->member.para.pLastCell->next = pCell;
|
|
|
|
para->member.para.pLastCell = pCell;
|
|
|
|
}
|
|
|
|
para->member.para.pLastCell->nRightBoundary = info->rtfParam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-05 14:49:14 +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) {
|
|
|
|
memcpy(&info->stack[info->stackTop].fmt, &info->style->fmt, sizeof(CHARFORMAT2W));
|
|
|
|
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
|
|
|
{
|
|
|
|
ME_Style *s;
|
2005-03-16 12:27:43 +01:00
|
|
|
RTFFlushOutputBuffer(info);
|
2005-10-03 20:45:39 +02:00
|
|
|
if (info->stackTop<=1) {
|
|
|
|
info->rtfClass = rtfEOF;
|
|
|
|
return;
|
|
|
|
}
|
2005-03-18 11:24:51 +01:00
|
|
|
info->stackTop--;
|
2005-10-03 20:45:39 +02:00
|
|
|
assert(info->stackTop >= 0);
|
2005-08-22 12:06:08 +02:00
|
|
|
if (info->styleChanged)
|
|
|
|
{
|
|
|
|
/* FIXME too slow ? how come ? */
|
|
|
|
s = ME_ApplyStyle(info->style, &info->stack[info->stackTop].fmt);
|
|
|
|
ME_ReleaseStyle(info->style);
|
|
|
|
info->style = s;
|
|
|
|
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
|
|
|
case rtfControl:
|
|
|
|
switch(info->rtfMajor)
|
|
|
|
{
|
|
|
|
case rtfCharAttr:
|
|
|
|
ME_RTFCharAttrHook(info);
|
|
|
|
break;
|
|
|
|
case rtfParAttr:
|
|
|
|
ME_RTFParAttrHook(info);
|
|
|
|
break;
|
2006-02-04 17:01:01 +01:00
|
|
|
case rtfTblAttr:
|
|
|
|
ME_RTFTblAttrHook(info);
|
|
|
|
break;
|
|
|
|
case rtfSpecialChar:
|
|
|
|
if (info->rtfMinor == rtfCell)
|
|
|
|
{
|
|
|
|
RTFFlushOutputBuffer(info);
|
|
|
|
ME_InsertTableCellFromCursor(info->editor, 0);
|
|
|
|
}
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-03-08 20:03:01 +01:00
|
|
|
static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream)
|
|
|
|
{
|
|
|
|
RTF_Info parser;
|
|
|
|
ME_Style *style;
|
2006-11-28 06:35:50 +01:00
|
|
|
int from, to, to2;
|
2005-03-17 11:23:40 +01:00
|
|
|
int nEventMask = editor->nEventMask;
|
2005-04-13 13:11:03 +02:00
|
|
|
ME_InStream inStream;
|
2005-03-07 18:15:33 +01:00
|
|
|
|
2005-04-20 16:25:03 +02:00
|
|
|
TRACE("stream==%p hWnd==%p format==0x%X\n", stream, editor->hWnd, (UINT)format);
|
2005-03-17 11:23:40 +01:00
|
|
|
editor->nEventMask = 0;
|
2005-03-08 20:03:01 +01:00
|
|
|
|
2005-03-11 11:24:56 +01:00
|
|
|
ME_GetSelection(editor, &from, &to);
|
2006-02-19 07:32:24 +01:00
|
|
|
if ((format & SFF_SELECTION) && (editor->mode & TM_RICHTEXT)) {
|
2005-03-08 20:03:01 +01:00
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
2005-03-11 11:24:56 +01:00
|
|
|
|
|
|
|
ME_InternalDeleteText(editor, from, to-from);
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
style = editor->pBuffer->pDefaultStyle;
|
|
|
|
ME_AddRefStyle(style);
|
|
|
|
SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
|
2005-03-11 11:24:56 +01:00
|
|
|
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
|
|
|
|
from = to = 0;
|
2005-03-08 20:03:01 +01:00
|
|
|
ME_ClearTempStyle(editor);
|
2005-03-17 11:23:40 +01:00
|
|
|
/* FIXME restore default paragraph formatting ! */
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2005-03-11 11:24:56 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2006-08-10 17:45:46 +02:00
|
|
|
if (strncmp(inStream.buffer, "{\\rtf", 5) && strncmp(inStream.buffer, "{\\urtf", 6))
|
2005-04-13 13:11:03 +02:00
|
|
|
{
|
|
|
|
format &= ~SF_RTF;
|
|
|
|
format |= SF_TEXT;
|
|
|
|
}
|
|
|
|
}
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2005-04-13 13:11:03 +02:00
|
|
|
|
|
|
|
if (!inStream.editstream->dwError)
|
2005-03-08 20:03:01 +01:00
|
|
|
{
|
2005-04-13 13:11:03 +02:00
|
|
|
if (format & SF_RTF) {
|
|
|
|
/* setup the RTF parser */
|
|
|
|
memset(&parser, 0, sizeof parser);
|
|
|
|
RTFSetEditStream(&parser, &inStream);
|
|
|
|
parser.rtfFormat = format&(SF_TEXT|SF_RTF);
|
|
|
|
parser.hwndEdit = editor->hWnd;
|
|
|
|
parser.editor = editor;
|
|
|
|
parser.style = style;
|
|
|
|
WriterInit(&parser);
|
|
|
|
RTFInit(&parser);
|
|
|
|
RTFSetReadHook(&parser, ME_RTFReadHook);
|
|
|
|
BeginFile(&parser);
|
|
|
|
|
|
|
|
/* do the parsing */
|
|
|
|
RTFRead(&parser);
|
|
|
|
RTFFlushOutputBuffer(&parser);
|
|
|
|
RTFDestroy(&parser);
|
|
|
|
|
|
|
|
style = parser.style;
|
|
|
|
}
|
|
|
|
else if (format & SF_TEXT)
|
|
|
|
ME_StreamInText(editor, format, &inStream, style);
|
|
|
|
else
|
|
|
|
ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
|
|
|
|
ME_GetSelection(editor, &to, &to2);
|
|
|
|
/* put the cursor at the top */
|
|
|
|
if (!(format & SFF_SELECTION))
|
|
|
|
SendMessageA(editor->hWnd, EM_SETSEL, 0, 0);
|
2005-03-08 20:03:01 +01:00
|
|
|
}
|
2007-01-12 07:09:44 +01:00
|
|
|
|
2006-02-05 12:18:55 +01:00
|
|
|
if (format & SFF_SELECTION)
|
2005-03-11 11:24:56 +01:00
|
|
|
{
|
2006-11-28 06:35:50 +01:00
|
|
|
/* even if we didn't add an undo, we need to commit the ones added earlier */
|
2006-02-05 12:18:55 +01:00
|
|
|
ME_CommitUndo(editor);
|
2005-03-11 11:24:56 +01:00
|
|
|
}
|
2006-02-05 12:18:55 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ME_EmptyUndoStack(editor);
|
|
|
|
}
|
|
|
|
|
2005-03-17 11:23:40 +01:00
|
|
|
ME_ReleaseStyle(style);
|
|
|
|
editor->nEventMask = nEventMask;
|
2005-08-15 11:47:14 +02:00
|
|
|
if (editor->bRedraw)
|
|
|
|
{
|
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
}
|
2005-03-17 11:23:40 +01:00
|
|
|
if (!(format & SFF_SELECTION)) {
|
|
|
|
ME_ClearTempStyle(editor);
|
|
|
|
}
|
|
|
|
ME_MoveCaret(editor);
|
|
|
|
ME_SendSelChange(editor);
|
2005-11-03 10:52:29 +01:00
|
|
|
ME_SendRequestResize(editor, FALSE);
|
2005-03-07 18:15:33 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
es.dwCookie = (DWORD)&data;
|
|
|
|
es.pfnCallback = ME_ReadFromRTFString;
|
|
|
|
ME_StreamIn(editor, SF_RTF | (selection ? SFF_SELECTION : 0), &es);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
ME_DisplayItem *
|
|
|
|
ME_FindItemAtOffset(ME_TextEditor *editor, ME_DIType nItemType, int nOffset, int *nItemOffset)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
|
|
|
|
|
|
|
|
while (item && item->member.para.next_para->member.para.nCharOfs <= nOffset)
|
|
|
|
item = ME_FindItemFwd(item, diParagraph);
|
|
|
|
|
|
|
|
if (!item)
|
|
|
|
return item;
|
|
|
|
|
|
|
|
nOffset -= item->member.para.nCharOfs;
|
|
|
|
if (nItemType == diParagraph) {
|
|
|
|
if (nItemOffset)
|
|
|
|
*nItemOffset = nOffset;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
item = ME_FindItemFwd(item, diRun);
|
|
|
|
} while (item && (item->member.run.nCharOfs + ME_StrLen(item->member.run.strText) <= nOffset));
|
|
|
|
if (item) {
|
|
|
|
nOffset -= item->member.run.nCharOfs;
|
|
|
|
if (nItemOffset)
|
|
|
|
*nItemOffset = nOffset;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-06 12:32:59 +02:00
|
|
|
static int
|
2006-07-21 22:05:00 +02:00
|
|
|
ME_FindText(ME_TextEditor *editor, DWORD flags, 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 nStart, nEnd;
|
|
|
|
int nMin, nMax;
|
|
|
|
ME_DisplayItem *item;
|
2005-07-06 12:32:59 +02:00
|
|
|
ME_DisplayItem *para;
|
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));
|
2005-07-06 12:32:59 +02: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;
|
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
|
|
|
*/
|
|
|
|
if (!(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
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
nStart = nMin - 1;
|
|
|
|
item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
if (chrgText)
|
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wLastChar = item->member.run.strText->szData[nStart];
|
|
|
|
}
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nStart = nMin;
|
|
|
|
item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
|
|
|
|
if (!item)
|
2006-02-15 13:37:31 +01:00
|
|
|
{
|
|
|
|
if (chrgText)
|
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
2005-08-23 11:32:55 +02:00
|
|
|
return -1;
|
2006-02-15 13:37:31 +01:00
|
|
|
}
|
2005-08-23 11:32:55 +02:00
|
|
|
|
|
|
|
para = ME_GetParagraph(item);
|
|
|
|
while (item
|
2006-02-11 18:39:17 +01:00
|
|
|
&& para->member.para.nCharOfs + item->member.run.nCharOfs + nStart + nLen <= nMax)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2005-08-23 11:32:55 +02:00
|
|
|
ME_DisplayItem *pCurItem = item;
|
|
|
|
int nCurStart = nStart;
|
|
|
|
int nMatched = 0;
|
|
|
|
|
2006-02-21 19:19:01 +01:00
|
|
|
while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[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)
|
|
|
|
{
|
|
|
|
if (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
|
|
|
|
{
|
|
|
|
pNextItem = ME_FindItemFwd(pCurItem, diRun);
|
|
|
|
nNextStart = -nMatched;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pNextItem)
|
|
|
|
wNextChar = pNextItem->member.run.strText->szData[nNextStart + nMatched];
|
|
|
|
else
|
|
|
|
wNextChar = ' ';
|
|
|
|
|
|
|
|
if (isalnumW(wNextChar))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nStart += para->member.para.nCharOfs + pCurItem->member.run.nCharOfs;
|
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 (nCurStart + nMatched == ME_StrLen(pCurItem->member.run.strText))
|
|
|
|
{
|
|
|
|
pCurItem = ME_FindItemFwd(pCurItem, diRun);
|
|
|
|
para = ME_GetParagraph(pCurItem);
|
|
|
|
nCurStart = -nMatched;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
}
|
2006-03-21 12:43:56 +01:00
|
|
|
if (pCurItem)
|
|
|
|
wLastChar = pCurItem->member.run.strText->szData[nCurStart + nMatched];
|
|
|
|
else
|
|
|
|
wLastChar = ' ';
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nStart++;
|
|
|
|
if (nStart == ME_StrLen(item->member.run.strText))
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2005-08-23 11:32:55 +02:00
|
|
|
item = ME_FindItemFwd(item, diRun);
|
|
|
|
para = ME_GetParagraph(item);
|
|
|
|
nStart = 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)
|
|
|
|
{
|
|
|
|
nEnd = nMax + 1;
|
|
|
|
item = ME_FindItemAtOffset(editor, diRun, nEnd, &nEnd);
|
|
|
|
if (!item)
|
|
|
|
{
|
|
|
|
if (chrgText)
|
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
wLastChar = item->member.run.strText->szData[nEnd];
|
|
|
|
}
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nEnd = nMax;
|
|
|
|
item = ME_FindItemAtOffset(editor, diRun, nEnd, &nEnd);
|
2006-03-21 12:43:56 +01:00
|
|
|
if (!item)
|
|
|
|
{
|
2006-02-15 13:37:31 +01:00
|
|
|
if (chrgText)
|
|
|
|
chrgText->cpMin = chrgText->cpMax = -1;
|
2005-08-23 11:32:55 +02:00
|
|
|
return -1;
|
2006-02-15 13:37:31 +01:00
|
|
|
}
|
2005-08-23 11:32:55 +02:00
|
|
|
|
|
|
|
para = ME_GetParagraph(item);
|
|
|
|
|
|
|
|
while (item
|
|
|
|
&& para->member.para.nCharOfs + item->member.run.nCharOfs + nEnd - nLen >= nMin)
|
2005-07-06 12:32:59 +02:00
|
|
|
{
|
2005-08-23 11:32:55 +02:00
|
|
|
ME_DisplayItem *pCurItem = item;
|
|
|
|
int nCurEnd = nEnd;
|
|
|
|
int nMatched = 0;
|
|
|
|
|
2006-03-21 12:43:56 +01:00
|
|
|
if (nCurEnd - nMatched == 0)
|
2005-08-23 11:32:55 +02:00
|
|
|
{
|
2006-03-21 12:43:56 +01:00
|
|
|
pCurItem = ME_FindItemBack(pCurItem, diRun);
|
|
|
|
para = ME_GetParagraph(pCurItem);
|
|
|
|
nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pCurItem && ME_CharCompare(pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1], text[nLen - nMatched - 1], (flags & FR_MATCHCASE)))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* Check to see if previous character is a whitespace */
|
|
|
|
if (flags & FR_WHOLEWORD)
|
|
|
|
{
|
|
|
|
if (nPrevEnd - nMatched == 0)
|
|
|
|
{
|
|
|
|
pPrevItem = ME_FindItemBack(pCurItem, diRun);
|
|
|
|
if (pPrevItem)
|
|
|
|
nPrevEnd = ME_StrLen(pPrevItem->member.run.strText) + nMatched;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pPrevItem)
|
|
|
|
wPrevChar = pPrevItem->member.run.strText->szData[nPrevEnd - nMatched - 1];
|
|
|
|
else
|
|
|
|
wPrevChar = ' ';
|
|
|
|
|
|
|
|
if (isalnumW(wPrevChar))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nStart = para->member.para.nCharOfs + 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)
|
|
|
|
{
|
|
|
|
pCurItem = ME_FindItemBack(pCurItem, diRun);
|
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 */
|
2005-08-23 11:32:55 +02:00
|
|
|
para = ME_GetParagraph(pCurItem);
|
|
|
|
nCurEnd = ME_StrLen(pCurItem->member.run.strText) + nMatched;
|
|
|
|
}
|
|
|
|
}
|
2006-03-21 12:43:56 +01:00
|
|
|
if (pCurItem)
|
|
|
|
wLastChar = pCurItem->member.run.strText->szData[nCurEnd - nMatched - 1];
|
|
|
|
else
|
|
|
|
wLastChar = ' ';
|
|
|
|
|
2005-08-23 11:32:55 +02:00
|
|
|
nEnd--;
|
|
|
|
if (nEnd < 0)
|
|
|
|
{
|
|
|
|
item = ME_FindItemBack(item, diRun);
|
|
|
|
para = ME_GetParagraph(item);
|
|
|
|
nEnd = ME_StrLen(item->member.run.strText);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
switch (nKey)
|
|
|
|
{
|
|
|
|
case VK_LEFT:
|
|
|
|
case VK_RIGHT:
|
|
|
|
case VK_UP:
|
|
|
|
case VK_DOWN:
|
|
|
|
case VK_HOME:
|
|
|
|
case VK_END:
|
|
|
|
case VK_PRIOR:
|
|
|
|
case VK_NEXT:
|
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:
|
|
|
|
/* FIXME backspace and delete aren't the same, they act different wrt paragraph style of the merged paragraph */
|
|
|
|
if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY)
|
|
|
|
return FALSE;
|
|
|
|
if (ME_IsSelection(editor))
|
|
|
|
ME_DeleteSelection(editor);
|
2006-01-12 11:54:57 +01:00
|
|
|
else if (nKey == VK_DELETE || ME_ArrowKey(editor, VK_LEFT, FALSE, FALSE))
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_DeleteTextAtCursor(editor, 1, 1);
|
|
|
|
else
|
|
|
|
return TRUE;
|
2006-08-07 17:27:16 +02:00
|
|
|
ME_CommitUndo(editor);
|
2006-01-10 20:23:41 +01:00
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
ME_SendRequestResize(editor, FALSE);
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if(!editor->lpOleCallback)
|
2006-09-03 05:08:46 +02:00
|
|
|
return FALSE;
|
2006-02-02 13:18:20 +01:00
|
|
|
ME_GetSelection(editor, (int *)&selrange.cpMin, (int *)&selrange.cpMax);
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, GetParent(editor->hWnd), NULL);
|
|
|
|
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
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_TextEditor *ME_MakeEditor(HWND hWnd) {
|
|
|
|
ME_TextEditor *ed = ALLOC_OBJ(ME_TextEditor);
|
|
|
|
HDC hDC;
|
2005-03-08 17:26:23 +01:00
|
|
|
int i;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->hWnd = hWnd;
|
2005-07-21 12:33:32 +02:00
|
|
|
ed->bEmulateVersion10 = FALSE;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->pBuffer = ME_MakeText();
|
|
|
|
hDC = GetDC(hWnd);
|
|
|
|
ME_MakeFirstParagraph(hDC, ed->pBuffer);
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
ed->bCaretShown = FALSE;
|
2006-11-10 07:41:16 +01:00
|
|
|
ed->nCursors = 2;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->pCursors = ALLOC_N_OBJ(ME_Cursor, ed->nCursors);
|
|
|
|
ed->pCursors[0].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
|
|
|
|
ed->pCursors[0].nOffset = 0;
|
|
|
|
ed->pCursors[1].pRun = ME_FindItemFwd(ed->pBuffer->pFirst, diRun);
|
|
|
|
ed->pCursors[1].nOffset = 0;
|
2005-03-09 19:43:18 +01:00
|
|
|
ed->nLastTotalLength = ed->nTotalLength = 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
ed->nUDArrowX = -1;
|
|
|
|
ed->nSequence = 0;
|
|
|
|
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;
|
2006-05-15 20:00:15 +02:00
|
|
|
ed->pUndoStack = ed->pRedoStack = ed->pUndoStackBottom = NULL;
|
|
|
|
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;
|
2006-08-07 17:27:16 +02:00
|
|
|
ed->pLastSelStartPara = ed->pLastSelEndPara = ME_FindItemFwd(ed->pBuffer->pFirst, diParagraph);
|
2005-07-24 18:17:43 +02:00
|
|
|
ed->nZoomNumerator = ed->nZoomDenominator = 0;
|
2005-08-15 11:47:14 +02:00
|
|
|
ed->bRedraw = TRUE;
|
2006-02-24 22:31:25 +01:00
|
|
|
ed->bHideSelection = FALSE;
|
2006-01-10 20:23:41 +01:00
|
|
|
ed->nInvalidOfs = -1;
|
2006-01-12 11:54:57 +01:00
|
|
|
ed->pfnWordBreak = NULL;
|
2006-02-01 13:05:40 +01:00
|
|
|
ed->lpOleCallback = NULL;
|
2006-02-19 07:32:24 +01:00
|
|
|
ed->mode = TM_RICHTEXT | TM_MULTILEVELUNDO | TM_MULTICODEPAGE;
|
2006-11-10 07:40:58 +01:00
|
|
|
ed->AutoURLDetect_bEnable = FALSE;
|
2005-08-15 11:47:14 +02:00
|
|
|
GetClientRect(hWnd, &ed->rcFormat);
|
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;
|
|
|
|
}
|
2006-08-08 22:08:43 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CheckCharOffsets(ed);
|
2006-08-04 21:47:44 +02:00
|
|
|
|
|
|
|
if (GetWindowLongW(hWnd, GWL_STYLE) & ES_PASSWORD)
|
|
|
|
ed->cPasswordMask = '*';
|
|
|
|
else
|
|
|
|
ed->cPasswordMask = 0;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
return ed;
|
|
|
|
}
|
|
|
|
|
2005-03-15 16:40:52 +01: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;
|
|
|
|
pSrc = (WORD *)GlobalLock(pData->hData);
|
|
|
|
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;
|
|
|
|
pSrc = (BYTE *)GlobalLock(pData->hData);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-07-06 12:32:59 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
void ME_DestroyEditor(ME_TextEditor *editor)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2005-11-03 12:33:24 +01:00
|
|
|
DeleteObject(editor->hbrBackground);
|
2006-02-01 13:05:40 +01:00
|
|
|
if(editor->lpOleCallback)
|
|
|
|
IUnknown_Release(editor->lpOleCallback);
|
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);
|
|
|
|
}
|
|
|
|
|
2006-01-24 14:00:32 +01:00
|
|
|
static const WCHAR wszClassName[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '2', '0', 'W', 0};
|
|
|
|
static const WCHAR wszClassName50[] = {'R', 'i', 'c', 'h', 'E', 'd', 'i', 't', '5', '0', 'W', 0};
|
|
|
|
static const WCHAR wszClassNameListBox[] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0};
|
|
|
|
static const WCHAR wszClassNameComboBox[] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0};
|
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);
|
|
|
|
ME_RegisterEditorClass(hinstDLL);
|
2006-11-02 09:25:35 +01:00
|
|
|
LookupInit();
|
2005-05-16 10:51:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
UnregisterClassW(wszClassName, 0);
|
|
|
|
UnregisterClassW(wszClassName50, 0);
|
|
|
|
UnregisterClassA("RichEdit20A", 0);
|
|
|
|
UnregisterClassA("RichEdit50A", 0);
|
2005-12-05 12:48:45 +01:00
|
|
|
if (ME_ListBoxRegistered)
|
|
|
|
UnregisterClassW(wszClassNameListBox, 0);
|
|
|
|
if (ME_ComboBoxRegistered)
|
|
|
|
UnregisterClassW(wszClassNameComboBox, 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-03-05 12:19:14 +01:00
|
|
|
#define UNSUPPORTED_MSG(e) \
|
|
|
|
case e: \
|
|
|
|
FIXME(#e ": stub\n"); \
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
|
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",
|
|
|
|
"EM_CHARFROMPOS"
|
|
|
|
};
|
|
|
|
|
|
|
|
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 "";
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/******************************************************************
|
|
|
|
* RichEditANSIWndProc (RICHED20.10)
|
|
|
|
*/
|
|
|
|
LRESULT WINAPI RichEditANSIWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
2006-08-02 22:54:03 +02:00
|
|
|
ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
|
2005-07-21 13:58:24 +02:00
|
|
|
|
2005-09-26 18:42:18 +02:00
|
|
|
TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
|
2005-08-15 11:47:14 +02:00
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam);
|
2005-07-21 13:58:24 +02:00
|
|
|
|
2006-08-02 22:54:03 +02:00
|
|
|
if (!editor && msg != WM_NCCREATE && msg != WM_NCDESTROY) {
|
|
|
|
ERR("RichEditANSIWndProc called with invalid hWnd %p - application bug?\n", hWnd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
switch(msg) {
|
|
|
|
|
|
|
|
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)
|
|
|
|
/* UNSUPPORTED_MSG(EM_GETIMESTATUS) missing in Wine headers */
|
|
|
|
UNSUPPORTED_MSG(EM_GETLANGOPTIONS)
|
|
|
|
/* UNSUPPORTED_MSG(EM_GETOLEINTERFACE) separate stub */
|
|
|
|
UNSUPPORTED_MSG(EM_GETREDONAME)
|
|
|
|
UNSUPPORTED_MSG(EM_GETTEXTMODE)
|
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)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_SETPALETTE)
|
|
|
|
UNSUPPORTED_MSG(EM_SETTABSTOPS)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_SETTARGETDEVICE)
|
2005-05-13 19:45:43 +02:00
|
|
|
UNSUPPORTED_MSG(EM_SETTYPOGRAPHYOPTIONS)
|
2005-03-05 12:19:14 +01:00
|
|
|
UNSUPPORTED_MSG(EM_SETWORDBREAKPROCEX)
|
|
|
|
UNSUPPORTED_MSG(WM_STYLECHANGING)
|
|
|
|
UNSUPPORTED_MSG(WM_STYLECHANGED)
|
|
|
|
/* UNSUPPORTED_MSG(WM_UNICHAR) FIXME missing in Wine headers */
|
|
|
|
|
2005-03-07 18:15:33 +01:00
|
|
|
/* Messages specific to Richedit controls */
|
2005-03-05 12:19:14 +01:00
|
|
|
|
2005-03-07 18:15:33 +01:00
|
|
|
case EM_STREAMIN:
|
2005-03-08 20:03:01 +01:00
|
|
|
return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam);
|
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:
|
|
|
|
{
|
|
|
|
UINT code = DLGC_WANTCHARS|DLGC_WANTARROWS;
|
2006-11-14 05:33:42 +01:00
|
|
|
if(lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
|
|
|
|
{
|
|
|
|
int vk = (int)((LPMSG)lParam)->wParam;
|
|
|
|
/* if style says we want return key */
|
|
|
|
if((vk == VK_RETURN) && (GetWindowLongW(hWnd, GWL_STYLE) & ES_WANTRETURN))
|
|
|
|
{
|
|
|
|
code |= DLGC_WANTMESSAGE;
|
|
|
|
}
|
|
|
|
/* we always handle ctrl-tab */
|
|
|
|
if((vk == VK_TAB) && (GetKeyState(VK_CONTROL) & 0x8000))
|
|
|
|
{
|
|
|
|
code |= DLGC_WANTMESSAGE;
|
|
|
|
}
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
return code;
|
|
|
|
}
|
|
|
|
case WM_NCCREATE:
|
|
|
|
{
|
|
|
|
CREATESTRUCTW *pcs = (CREATESTRUCTW *)lParam;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("WM_NCCREATE: style 0x%08x\n", pcs->style);
|
2005-03-05 12:19:14 +01:00
|
|
|
editor = ME_MakeEditor(hWnd);
|
2006-08-03 18:20:01 +02:00
|
|
|
SetWindowLongPtrW(hWnd, 0, (LONG_PTR)editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
pcs = 0; /* ignore */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
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;
|
2005-09-12 22:30:37 +02:00
|
|
|
ME_GetSelection(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;
|
|
|
|
ME_GetSelection(editor, (int *)&pRange->cpMin, (int *)&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
|
2006-06-15 17:38:04 +02:00
|
|
|
no program would realistically set a value above our maxiumum. */
|
2006-05-15 20:00:15 +02:00
|
|
|
return editor->nUndoLimit;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_CANUNDO:
|
|
|
|
return editor->pUndoStack != NULL;
|
|
|
|
case EM_CANREDO:
|
|
|
|
return editor->pRedoStack != NULL;
|
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:
|
|
|
|
ME_Undo(editor);
|
|
|
|
return 0;
|
|
|
|
case EM_REDO:
|
|
|
|
ME_Redo(editor);
|
|
|
|
return 0;
|
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 |
|
|
|
|
ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN;
|
|
|
|
DWORD settings = GetWindowLongW(hWnd, GWL_STYLE) & mask;
|
|
|
|
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
case EM_SETOPTIONS:
|
|
|
|
{
|
|
|
|
/* these flags are equivalent to ES_* counterparts
|
|
|
|
* ECO_READONLY is already implemented in the code, only requires
|
|
|
|
* setting the bit to work
|
|
|
|
*/
|
|
|
|
DWORD mask = ECO_VERTICAL | ECO_AUTOHSCROLL | ECO_AUTOVSCROLL |
|
|
|
|
ECO_NOHIDESEL | ECO_READONLY | ECO_WANTRETURN;
|
|
|
|
DWORD raw = GetWindowLongW(hWnd, GWL_STYLE);
|
|
|
|
DWORD settings = mask & raw;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
SetWindowLongW(hWnd, GWL_STYLE, (raw & ~mask) | (settings & mask));
|
|
|
|
|
|
|
|
if (lParam & ECO_AUTOWORDSELECTION)
|
|
|
|
FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
|
|
|
|
if (lParam & ECO_SELECTIONBAR)
|
|
|
|
FIXME("ECO_SELECTIONBAR not implemented yet!\n");
|
|
|
|
if (lParam & ECO_VERTICAL)
|
|
|
|
FIXME("ECO_VERTICAL not implemented yet!\n");
|
|
|
|
if (lParam & ECO_AUTOHSCROLL)
|
|
|
|
FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
|
|
|
|
if (lParam & ECO_AUTOVSCROLL)
|
|
|
|
FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
|
|
|
|
if (lParam & ECO_NOHIDESEL)
|
|
|
|
FIXME("ECO_NOHIDESEL not implemented yet!\n");
|
|
|
|
if (lParam & ECO_WANTRETURN)
|
|
|
|
FIXME("ECO_WANTRETURN not implemented yet!\n");
|
|
|
|
|
|
|
|
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);
|
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;
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_ScrollAbs(editor, point->y);
|
2006-08-08 22:08:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-03-01 11:49:42 +01:00
|
|
|
case EM_AUTOURLDETECT:
|
|
|
|
{
|
|
|
|
if (wParam==1 || wParam ==0)
|
|
|
|
{
|
|
|
|
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);
|
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:
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
ShowScrollBar(editor->hWnd, wParam, lParam);
|
2006-08-08 22:08:43 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-07-20 12:28:44 +02:00
|
|
|
case EM_SETTEXTEX:
|
|
|
|
{
|
|
|
|
LPWSTR wszText = (LPWSTR)lParam;
|
|
|
|
SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
|
2006-08-09 05:12:33 +02:00
|
|
|
size_t len = wszText ? lstrlenW(wszText) : 0;
|
2005-07-20 12:28:44 +02:00
|
|
|
int from, to;
|
|
|
|
ME_Style *style;
|
2007-01-11 08:46:35 +01:00
|
|
|
int oldModify = editor->nModifyStep;
|
2006-08-23 04:09:16 +02:00
|
|
|
TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage);
|
2005-07-20 12:28:44 +02:00
|
|
|
if (pStruct->codepage != 1200) {
|
|
|
|
FIXME("EM_SETTEXTEX only supports unicode right now!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* FIXME: this should support RTF strings too, according to MSDN */
|
|
|
|
if (pStruct->flags & ST_SELECTION) {
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
|
|
|
ME_InternalDeleteText(editor, from, to - from);
|
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, len, style);
|
|
|
|
ME_ReleaseStyle(style);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
|
2006-08-09 05:12:33 +02:00
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle);
|
2005-07-20 12:28:44 +02:00
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
2005-07-20 12:28:44 +02:00
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
return len;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_SETBKGNDCOLOR:
|
|
|
|
{
|
|
|
|
LRESULT lColor = ME_GetBackColor(editor);
|
2005-11-03 12:33:24 +01:00
|
|
|
if (editor->rgbBackColor != -1)
|
|
|
|
DeleteObject(editor->hbrBackground);
|
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);
|
|
|
|
}
|
2005-08-15 11:47:14 +02:00
|
|
|
if (editor->bRedraw)
|
|
|
|
{
|
|
|
|
InvalidateRect(hWnd, NULL, TRUE);
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
return lColor;
|
|
|
|
}
|
|
|
|
case EM_GETMODIFY:
|
|
|
|
return editor->nModifyStep == 0 ? 0 : 1;
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
long nStyle = GetWindowLongW(hWnd, GWL_STYLE);
|
|
|
|
if (wParam)
|
|
|
|
nStyle |= ES_READONLY;
|
|
|
|
else
|
|
|
|
nStyle &= ~ES_READONLY;
|
|
|
|
SetWindowLongW(hWnd, GWL_STYLE, nStyle);
|
|
|
|
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);
|
2006-02-19 07:32:24 +01:00
|
|
|
if (!wParam || (editor->mode & TM_PLAINTEXT))
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SetDefaultCharFormat(editor, p);
|
|
|
|
else if (wParam == (SCF_WORD | SCF_SELECTION))
|
2005-07-21 13:58:24 +02:00
|
|
|
FIXME("EM_SETCHARFORMAT: word selection not supported\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
else if (wParam == SCF_ALL)
|
|
|
|
ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), p);
|
2005-03-17 11:23:40 +01:00
|
|
|
else {
|
|
|
|
int from, to;
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
bRepaint = (from != to);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_SetSelectionCharFormat(editor, p);
|
2005-03-17 11:23:40 +01:00
|
|
|
}
|
2007-01-11 08:46:35 +01:00
|
|
|
editor->nModifyStep = 1;
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
2005-03-17 11:23:40 +01:00
|
|
|
if (bRepaint)
|
2006-11-28 09:50:25 +01:00
|
|
|
ME_RewrapRepaint(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
ME_SetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
|
2006-11-28 09:51:56 +01:00
|
|
|
ME_RewrapRepaint(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
return 0;
|
|
|
|
case EM_GETPARAFORMAT:
|
|
|
|
ME_GetSelectionParaFormat(editor, (PARAFORMAT2 *)lParam);
|
|
|
|
return 0;
|
2005-10-03 13:03:48 +02:00
|
|
|
case EM_GETFIRSTVISIBLELINE:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *p = editor->pBuffer->pFirst;
|
2006-09-08 23:37:25 +02:00
|
|
|
int y = ME_GetYScrollPos(editor);
|
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) {
|
|
|
|
ypara = p->member.para.nYPos;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ystart = ypara + p->member.row.nYPos;
|
|
|
|
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:
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_ScrollDown(editor, lParam * 8); /* FIXME follow the original */
|
2005-05-23 11:54:32 +02:00
|
|
|
return TRUE; /* Should return false if a single line richedit control */
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CLEAR:
|
|
|
|
{
|
|
|
|
int from, to;
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
ME_InternalDeleteText(editor, from, to-from);
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_REPLACESEL:
|
|
|
|
{
|
|
|
|
int from, to;
|
|
|
|
ME_Style *style;
|
|
|
|
LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
|
|
|
|
size_t len = lstrlenW(wszText);
|
2005-03-08 17:26:23 +01:00
|
|
|
TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
|
2006-11-05 06:26:47 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_GetSelection(editor, &from, &to);
|
2005-03-08 20:03:01 +01:00
|
|
|
style = ME_GetSelectionInsertStyle(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_InternalDeleteText(editor, from, to-from);
|
|
|
|
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);
|
2006-11-05 06:26:47 +01:00
|
|
|
ME_EndToUnicode(hWnd, wszText);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
if (!wParam)
|
|
|
|
ME_EmptyUndoStack(editor);
|
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-16 19:33:19 +01:00
|
|
|
case EM_SCROLLCARET:
|
|
|
|
{
|
|
|
|
int top, bottom; /* row's edges relative to document top */
|
2006-09-08 23:37:25 +02:00
|
|
|
int nPos;
|
2006-02-16 19:33:19 +01:00
|
|
|
ME_DisplayItem *para, *row;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
nPos = ME_GetYScrollPos(editor);
|
2006-02-16 19:33:19 +01:00
|
|
|
row = ME_RowStart(editor->pCursors[0].pRun);
|
|
|
|
para = ME_GetParagraph(row);
|
|
|
|
top = para->member.para.nYPos + row->member.row.nYPos;
|
|
|
|
bottom = top + row->member.row.nHeight;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
if (top < nPos) /* caret above window */
|
|
|
|
ME_ScrollAbs(editor, top);
|
|
|
|
else if (nPos + editor->sizeWindow.cy < bottom) /*below*/
|
|
|
|
ME_ScrollAbs(editor, bottom - editor->sizeWindow.cy);
|
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);
|
|
|
|
|
|
|
|
if (!wParam)
|
2006-08-09 22:01:47 +02:00
|
|
|
wParam = (WPARAM)GetStockObject(SYSTEM_FONT);
|
2006-07-14 19:43:00 +02:00
|
|
|
GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf);
|
|
|
|
hDC = GetDC(hWnd);
|
|
|
|
ME_CharFormatFromLogFont(hDC, &lf, &fmt);
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
ME_SetCharFormat(editor, 0, ME_GetTextLength(editor), &fmt);
|
|
|
|
ME_SetDefaultCharFormat(editor, &fmt);
|
|
|
|
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
if (bRepaint)
|
2006-11-28 08:35:58 +01:00
|
|
|
ME_RewrapRepaint(editor);
|
2006-07-14 19:43:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_SETTEXT:
|
|
|
|
{
|
|
|
|
ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor));
|
2005-07-21 13:28:39 +02:00
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
TRACE("WM_SETTEXT lParam==%lx\n",lParam);
|
2006-08-10 17:45:46 +02:00
|
|
|
if (!IsWindowUnicode(hWnd) && !strncmp((char *)lParam, "{\\rtf", 5))
|
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
|
|
|
{
|
2006-02-14 17:38:57 +01:00
|
|
|
LPWSTR wszText = ME_ToUnicode(hWnd, (void *)lParam);
|
|
|
|
TRACE("WM_SETTEXT - %s\n", debugstr_w(wszText)); /* debugstr_w() */
|
|
|
|
if (lstrlenW(wszText) > 0)
|
|
|
|
{
|
|
|
|
/* uses default style! */
|
|
|
|
ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle);
|
|
|
|
}
|
|
|
|
ME_EndToUnicode(hWnd, wszText);
|
2005-07-21 13:28:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
TRACE("WM_SETTEXT - NULL\n");
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
ME_EmptyUndoStack(editor);
|
2005-12-14 10:50:04 +01:00
|
|
|
ME_SetSelection(editor, 0, 0);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
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:
|
|
|
|
{
|
|
|
|
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 0;
|
|
|
|
|
2005-04-11 14:50:48 +02:00
|
|
|
if (!OpenClipboard(hWnd))
|
|
|
|
return 0;
|
2005-03-15 16:40:52 +01:00
|
|
|
gds.hData = GetClipboardData(cf);
|
|
|
|
gds.nLength = 0;
|
|
|
|
es.dwCookie = (DWORD)&gds;
|
|
|
|
es.pfnCallback = dwFormat == SF_RTF ? ME_ReadFromHGLOBALRTF : ME_ReadFromHGLOBALUnicode;
|
2006-02-06 11:26:34 +01:00
|
|
|
ME_StreamIn(editor, dwFormat|SFF_SELECTION, &es);
|
|
|
|
|
2005-03-15 16:40:52 +01:00
|
|
|
CloseClipboard();
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CUT:
|
|
|
|
case WM_COPY:
|
|
|
|
{
|
2006-02-23 05:09:59 +01:00
|
|
|
LPDATAOBJECT dataObj = NULL;
|
2006-02-22 19:56:11 +01:00
|
|
|
CHARRANGE range;
|
2006-02-23 05:09:59 +01:00
|
|
|
HRESULT hr = S_OK;
|
2006-08-04 21:47:44 +02:00
|
|
|
|
|
|
|
if (editor->cPasswordMask)
|
|
|
|
return 0; /* Copying or Cutting masked text isn't allowed */
|
|
|
|
|
2006-02-22 19:56:11 +01:00
|
|
|
ME_GetSelection(editor, (int*)&range.cpMin, (int*)&range.cpMax);
|
2006-02-23 05:09:59 +01:00
|
|
|
if(editor->lpOleCallback)
|
|
|
|
hr = IRichEditOleCallback_GetClipboardData(editor->lpOleCallback, &range, RECO_COPY, &dataObj);
|
|
|
|
if(FAILED(hr) || !dataObj)
|
|
|
|
hr = ME_GetDataObject(editor, &range, &dataObj);
|
2006-02-22 19:56:11 +01:00
|
|
|
if(SUCCEEDED(hr)) {
|
|
|
|
hr = OleSetClipboard(dataObj);
|
|
|
|
IDataObject_Release(dataObj);
|
2006-02-19 07:32:24 +01:00
|
|
|
}
|
2006-02-22 19:56:11 +01:00
|
|
|
if (SUCCEEDED(hr) && msg == WM_CUT)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2006-02-22 19:56:11 +01:00
|
|
|
ME_InternalDeleteText(editor, range.cpMin, range.cpMax-range.cpMin);
|
2005-03-05 12:19:14 +01:00
|
|
|
ME_CommitUndo(editor);
|
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case WM_GETTEXTLENGTH:
|
|
|
|
return ME_GetTextLength(editor);
|
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:
|
|
|
|
{
|
|
|
|
TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
|
|
|
|
tr.chrg.cpMin = 0;
|
|
|
|
tr.chrg.cpMax = wParam-1;
|
|
|
|
tr.lpstrText = (WCHAR *)lParam;
|
|
|
|
return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
|
|
|
|
}
|
2005-06-29 21:21:34 +02:00
|
|
|
case EM_GETTEXTEX:
|
|
|
|
{
|
|
|
|
GETTEXTEX *ex = (GETTEXTEX*)wParam;
|
2005-08-15 11:47:14 +02:00
|
|
|
int nStart, nCount;
|
2005-06-29 21:21:34 +02:00
|
|
|
|
2005-08-15 11:47:14 +02:00
|
|
|
if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
|
2006-10-13 21:25:54 +02:00
|
|
|
FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
|
2005-06-29 21:21:34 +02:00
|
|
|
|
2005-08-15 11:47:14 +02:00
|
|
|
if (ex->flags & GT_SELECTION)
|
|
|
|
{
|
|
|
|
ME_GetSelection(editor, &nStart, &nCount);
|
|
|
|
nCount -= nStart;
|
|
|
|
nCount = min(nCount, ex->cb - 1);
|
|
|
|
}
|
2005-06-29 21:21:34 +02:00
|
|
|
else
|
|
|
|
{
|
2005-08-15 11:47:14 +02:00
|
|
|
nStart = 0;
|
|
|
|
nCount = ex->cb - 1;
|
|
|
|
}
|
|
|
|
if (ex->codepage == 1200 || IsWindowUnicode(hWnd))
|
|
|
|
{
|
|
|
|
nCount = min(nCount, ex->cb / sizeof(WCHAR) - 1);
|
|
|
|
return ME_GetTextW(editor, (LPWSTR)lParam, nStart, nCount, ex->flags & GT_USECRLF);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-19 21:22:11 +02:00
|
|
|
/* potentially each char may be a CR, why calculate the exact value with O(N) when
|
|
|
|
we can just take a bigger buffer? :) */
|
|
|
|
int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
|
2006-10-24 07:26:28 +02:00
|
|
|
LPWSTR buffer = richedit_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
|
2005-10-19 21:22:11 +02:00
|
|
|
DWORD buflen = ex->cb;
|
|
|
|
LRESULT rc;
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
|
|
|
buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
|
2006-04-23 21:09:30 +02:00
|
|
|
rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefaultChar);
|
2005-10-19 21:22:11 +02:00
|
|
|
|
2006-10-24 07:26:28 +02:00
|
|
|
richedit_free(buffer);
|
2005-10-19 21:22:11 +02:00
|
|
|
return rc;
|
2005-06-29 21:21:34 +02:00
|
|
|
}
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETSELTEXT:
|
|
|
|
{
|
|
|
|
int from, to;
|
|
|
|
TEXTRANGEW tr; /* W and A differ only by rng->lpstrText */
|
|
|
|
ME_GetSelection(editor, &from, &to);
|
|
|
|
tr.chrg.cpMin = from;
|
|
|
|
tr.chrg.cpMax = to;
|
|
|
|
tr.lpstrText = (WCHAR *)lParam;
|
|
|
|
return RichEditANSIWndProc(hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
|
|
|
|
}
|
2006-02-16 19:33:19 +01:00
|
|
|
case EM_GETSCROLLPOS:
|
|
|
|
{
|
|
|
|
POINT *point = (POINT *)lParam;
|
|
|
|
point->x = 0; /* FIXME side scrolling not implemented */
|
2006-09-08 23:37:25 +02:00
|
|
|
point->y = ME_GetYScrollPos(editor);
|
2006-02-16 19:33:19 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case EM_GETTEXTRANGE:
|
|
|
|
{
|
|
|
|
TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
|
2006-10-13 21:25:54 +02:00
|
|
|
TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d emul1.0=%d length=%d\n",
|
2005-10-19 21:22:11 +02:00
|
|
|
rng->chrg.cpMin, rng->chrg.cpMax, IsWindowUnicode(hWnd),
|
|
|
|
editor->bEmulateVersion10, ME_GetTextLength(editor));
|
2005-03-05 12:19:14 +01:00
|
|
|
if (IsWindowUnicode(hWnd))
|
2005-08-15 11:47:14 +02:00
|
|
|
return ME_GetTextW(editor, rng->lpstrText, rng->chrg.cpMin, rng->chrg.cpMax-rng->chrg.cpMin, editor->bEmulateVersion10);
|
2005-03-05 12:19:14 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int nLen = rng->chrg.cpMax-rng->chrg.cpMin;
|
|
|
|
WCHAR *p = ALLOC_N_OBJ(WCHAR, nLen+1);
|
2005-08-15 11:47:14 +02:00
|
|
|
int nChars = ME_GetTextW(editor, p, rng->chrg.cpMin, nLen, editor->bEmulateVersion10);
|
2005-03-05 12:19:14 +01:00
|
|
|
/* FIXME this is a potential security hole (buffer overrun)
|
|
|
|
if you know more about wchar->mbyte conversion please explain
|
|
|
|
*/
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)rng->lpstrText, nLen+1, NULL, NULL);
|
|
|
|
FREE_OBJ(p);
|
|
|
|
return nChars;
|
|
|
|
}
|
|
|
|
}
|
2006-07-31 07:59:43 +02:00
|
|
|
case EM_GETLINE:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *run;
|
|
|
|
const BOOL bUnicode = IsWindowUnicode(hWnd);
|
|
|
|
const unsigned int nMaxChars = *(WORD *) lParam;
|
|
|
|
unsigned int nEndChars, nCharsLeft = nMaxChars;
|
|
|
|
char *dest = (char *) lParam;
|
2006-08-03 20:35:01 +02:00
|
|
|
/* rich text editor 1.0 uses \r\n for line end, 2.0 uses just \r;
|
|
|
|
we need to know how if we have the extra \n or not */
|
|
|
|
int nLF = editor->bEmulateVersion10;
|
2006-07-31 07:59:43 +02:00
|
|
|
|
|
|
|
TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
|
|
|
|
bUnicode ? "Unicode" : "Ansi");
|
|
|
|
|
|
|
|
run = ME_FindRowWithNumber(editor, wParam);
|
|
|
|
if (run == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
|
|
|
|
&& !(run->member.run.nFlags & MERF_ENDPARA))
|
|
|
|
{
|
|
|
|
unsigned int nCopy;
|
|
|
|
ME_String *strText;
|
|
|
|
if (run->type != diRun)
|
|
|
|
break;
|
|
|
|
strText = run->member.run.strText;
|
|
|
|
nCopy = min(nCharsLeft, strText->nLen);
|
|
|
|
|
|
|
|
if (bUnicode)
|
|
|
|
lstrcpynW((LPWSTR) dest, strText->szData, nCopy);
|
|
|
|
else
|
|
|
|
nCopy = WideCharToMultiByte(CP_ACP, 0, strText->szData, nCopy, dest,
|
|
|
|
nCharsLeft, NULL, NULL);
|
|
|
|
dest += nCopy * (bUnicode ? sizeof(WCHAR) : 1);
|
|
|
|
nCharsLeft -= nCopy;
|
|
|
|
}
|
|
|
|
|
2006-08-03 20:35:01 +02:00
|
|
|
/* append \r\0 (or \r\n\0 in 1.0), space allowing */
|
|
|
|
nEndChars = min(nCharsLeft, 2 + nLF);
|
2006-07-31 07:59:43 +02:00
|
|
|
nCharsLeft -= nEndChars;
|
|
|
|
if (bUnicode)
|
|
|
|
{
|
|
|
|
const WCHAR src[] = {'\r', '\0'};
|
2006-08-03 20:35:01 +02:00
|
|
|
const WCHAR src10[] = {'\r', '\n', '\0'};
|
|
|
|
lstrcpynW((LPWSTR) dest, nLF ? src10 : src, nEndChars);
|
2006-07-31 07:59:43 +02:00
|
|
|
}
|
|
|
|
else
|
2006-08-03 20:35:01 +02:00
|
|
|
lstrcpynA(dest, nLF ? "\r\n" : "\r", nEndChars);
|
2006-07-31 07:59:43 +02:00
|
|
|
|
|
|
|
TRACE("EM_GETLINE: got %u bytes\n", nMaxChars - nCharsLeft);
|
|
|
|
|
2006-08-03 20:35:01 +02:00
|
|
|
if (nEndChars == 2 + nLF)
|
2006-07-31 07:59:43 +02:00
|
|
|
return nMaxChars - nCharsLeft - 1; /* don't count \0 */
|
|
|
|
else
|
|
|
|
return nMaxChars - nCharsLeft;
|
|
|
|
}
|
2005-06-30 20:10:22 +02:00
|
|
|
case EM_GETLINECOUNT:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item = editor->pBuffer->pFirst->next;
|
|
|
|
int nRows = 0;
|
|
|
|
|
|
|
|
while (item != editor->pBuffer->pLast)
|
|
|
|
{
|
|
|
|
assert(item->type == diParagraph);
|
|
|
|
nRows += item->member.para.nRows;
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
}
|
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)
|
|
|
|
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor, 1));
|
|
|
|
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)
|
|
|
|
return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(editor,1));
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
item = ME_FindItemAtOffset(editor, diRun, wParam, NULL);
|
|
|
|
item = ME_RowStart(item);
|
2005-09-29 12:30:50 +02:00
|
|
|
nThisLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item, diRun), 0);
|
2006-08-03 20:37:45 +02:00
|
|
|
item_end = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
|
|
|
|
if (item_end->type == diStartRow)
|
2005-09-29 12:30:50 +02:00
|
|
|
nNextLineOfs = ME_CharOfsFromRunOfs(editor, ME_FindItemFwd(item_end, diRun), 0);
|
2005-07-21 13:01:47 +02:00
|
|
|
else
|
2005-10-10 12:44:01 +02:00
|
|
|
nNextLineOfs = ME_FindItemFwd(item, diParagraphOrEnd)->member.para.nCharOfs
|
|
|
|
- (editor->bEmulateVersion10?2:1);
|
2005-09-29 12:30:50 +02:00
|
|
|
nChars = nNextLineOfs - nThisLineOfs;
|
2005-07-21 13:01:47 +02:00
|
|
|
TRACE("EM_LINELENGTH(%d)==%d\n",wParam, nChars);
|
|
|
|
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:
|
|
|
|
{
|
|
|
|
FINDTEXTA *ft = (FINDTEXTA *)lParam;
|
|
|
|
int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
|
|
|
|
WCHAR *tmp;
|
2006-11-10 07:41:38 +01:00
|
|
|
LRESULT r;
|
|
|
|
|
2005-07-06 12:32:59 +02:00
|
|
|
if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
|
2006-11-10 07:41:38 +01:00
|
|
|
r = ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
|
|
|
|
FREE_OBJ( tmp );
|
|
|
|
return r;
|
2005-07-06 12:32:59 +02:00
|
|
|
}
|
|
|
|
case EM_FINDTEXTEX:
|
|
|
|
{
|
|
|
|
FINDTEXTEXA *ex = (FINDTEXTEXA *)lParam;
|
|
|
|
int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
|
|
|
|
WCHAR *tmp;
|
2006-11-10 07:41:38 +01:00
|
|
|
LRESULT r;
|
|
|
|
|
2005-07-06 12:32:59 +02:00
|
|
|
if ((tmp = ALLOC_N_OBJ(WCHAR, nChars)) != NULL)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
|
2006-11-10 07:41:38 +01:00
|
|
|
r = ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
|
|
|
|
FREE_OBJ( tmp );
|
|
|
|
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:
|
|
|
|
return ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y);
|
2005-10-03 13:03:48 +02:00
|
|
|
case EM_POSFROMCHAR:
|
|
|
|
{
|
|
|
|
ME_DisplayItem *pRun;
|
|
|
|
int nCharOfs, nOffset, nLength;
|
|
|
|
POINTL pt = {0,0};
|
|
|
|
|
|
|
|
nCharOfs = wParam;
|
|
|
|
/* detect which API version we're dealing with */
|
|
|
|
if (wParam >= 0x40000)
|
|
|
|
nCharOfs = lParam;
|
|
|
|
nLength = ME_GetTextLength(editor);
|
|
|
|
|
2005-10-10 20:00:52 +02:00
|
|
|
if (nCharOfs < nLength) {
|
2005-10-03 13:03:48 +02:00
|
|
|
ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset);
|
2005-10-10 20:00:52 +02:00
|
|
|
assert(pRun->type == diRun);
|
2005-10-03 13:03:48 +02:00
|
|
|
pt.y = pRun->member.run.pt.y;
|
|
|
|
pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset);
|
2005-10-10 20:00:52 +02:00
|
|
|
pt.y += ME_GetParagraph(pRun)->member.para.nYPos;
|
|
|
|
} else {
|
|
|
|
pt.x = 0;
|
|
|
|
pt.y = editor->pBuffer->pLast->member.para.nYPos;
|
2005-10-03 13:03:48 +02:00
|
|
|
}
|
|
|
|
if (wParam >= 0x40000) {
|
|
|
|
*(POINTL *)wParam = pt;
|
|
|
|
}
|
|
|
|
return MAKELONG( pt.x, pt.y );
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_CREATE:
|
2006-08-08 22:08:43 +02:00
|
|
|
if (GetWindowLongW(hWnd, GWL_STYLE) & WS_HSCROLL)
|
|
|
|
{ /* Squelch the default horizontal scrollbar it would make */
|
2006-09-08 23:37:25 +02:00
|
|
|
ShowScrollBar(editor->hWnd, SB_HORZ, FALSE);
|
|
|
|
}
|
2005-03-05 12:19:14 +01: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;
|
|
|
|
case WM_DESTROY:
|
|
|
|
ME_DestroyEditor(editor);
|
2006-08-03 18:20:01 +02:00
|
|
|
SetWindowLongPtrW(hWnd, 0, 0);
|
2005-03-09 19:43:18 +01:00
|
|
|
return 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
SetFocus(hWnd);
|
|
|
|
ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
|
|
|
|
SetCapture(hWnd);
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if (GetCapture() == hWnd)
|
|
|
|
ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2006-08-19 23:04:49 +02:00
|
|
|
break;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_LBUTTONUP:
|
|
|
|
if (GetCapture() == hWnd)
|
|
|
|
ReleaseCapture();
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
2006-01-13 13:54:11 +01:00
|
|
|
case WM_LBUTTONDBLCLK:
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_LinkNotify(editor,msg,wParam,lParam);
|
2006-01-13 13:54:11 +01:00
|
|
|
ME_SelectWord(editor);
|
|
|
|
break;
|
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_PAINT:
|
2005-08-15 11:47:14 +02:00
|
|
|
if (editor->bRedraw)
|
|
|
|
{
|
|
|
|
HDC hDC;
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
|
|
|
|
hDC = BeginPaint(hWnd, &ps);
|
|
|
|
ME_PaintContent(editor, hDC, FALSE, &ps.rcPaint);
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
break;
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
ME_ShowCaret(editor);
|
|
|
|
ME_SendOldNotify(editor, EN_SETFOCUS);
|
|
|
|
return 0;
|
|
|
|
case WM_KILLFOCUS:
|
|
|
|
ME_HideCaret(editor);
|
|
|
|
ME_SendOldNotify(editor, EN_KILLFOCUS);
|
|
|
|
return 0;
|
|
|
|
case WM_ERASEBKGND:
|
|
|
|
{
|
2005-08-15 11:47:14 +02:00
|
|
|
if (editor->bRedraw)
|
2005-03-05 12:19:14 +01:00
|
|
|
{
|
2005-08-15 11:47:14 +02:00
|
|
|
HDC hDC = (HDC)wParam;
|
|
|
|
RECT rc;
|
|
|
|
if (GetUpdateRect(hWnd,&rc,TRUE))
|
|
|
|
{
|
2005-11-03 12:33:24 +01:00
|
|
|
FillRect(hDC, &rc, editor->hbrBackground);
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
case WM_COMMAND:
|
|
|
|
TRACE("editor wnd command = %d\n", LOWORD(wParam));
|
|
|
|
return 0;
|
|
|
|
case WM_KEYDOWN:
|
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;
|
|
|
|
case WM_CHAR:
|
|
|
|
{
|
2005-08-22 11:20:06 +02:00
|
|
|
WCHAR wstr = LOWORD(wParam);
|
2006-03-01 11:49:42 +01:00
|
|
|
if (editor->AutoURLDetect_bEnable)
|
|
|
|
ME_AutoURLDetect(editor, wstr);
|
|
|
|
|
2005-08-22 11:20:06 +02:00
|
|
|
switch (wstr)
|
|
|
|
{
|
2006-08-03 19:53:54 +02:00
|
|
|
case 1: /* Ctrl-A */
|
|
|
|
ME_SetSelection(editor, 0, -1);
|
|
|
|
return 0;
|
2005-08-22 11:20:06 +02:00
|
|
|
case 3: /* Ctrl-C */
|
|
|
|
SendMessageW(editor->hWnd, WM_COPY, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (GetWindowLongW(editor->hWnd, GWL_STYLE) & ES_READONLY) {
|
|
|
|
MessageBeep(MB_ICONERROR);
|
|
|
|
return 0; /* FIXME really 0 ? */
|
|
|
|
}
|
2005-08-22 11:20:06 +02:00
|
|
|
|
|
|
|
switch (wstr)
|
|
|
|
{
|
|
|
|
case 22: /* Ctrl-V */
|
|
|
|
SendMessageW(editor->hWnd, WM_PASTE, 0, 0);
|
|
|
|
return 0;
|
|
|
|
case 24: /* Ctrl-X */
|
|
|
|
SendMessageW(editor->hWnd, WM_CUT, 0, 0);
|
|
|
|
return 0;
|
|
|
|
case 25: /* Ctrl-Y */
|
|
|
|
SendMessageW(editor->hWnd, EM_REDO, 0, 0);
|
|
|
|
return 0;
|
|
|
|
case 26: /* Ctrl-Z */
|
|
|
|
SendMessageW(editor->hWnd, EM_UNDO, 0, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-16 12:48:35 +02:00
|
|
|
if (((unsigned)wstr)>=' ' || wstr=='\r' || wstr=='\t') {
|
2005-03-05 12:19:14 +01:00
|
|
|
/* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
|
|
|
|
ME_Style *style = ME_GetInsertStyle(editor, 0);
|
|
|
|
ME_SaveTempStyle(editor);
|
|
|
|
ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
|
|
|
|
ME_ReleaseStyle(style);
|
|
|
|
ME_CommitUndo(editor);
|
|
|
|
ME_UpdateRepaint(editor);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-02-25 08:26:42 +01:00
|
|
|
case EM_SCROLL: /* fall through */
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_VSCROLL:
|
|
|
|
{
|
2006-09-08 23:37:25 +02:00
|
|
|
int origNPos;
|
|
|
|
int lineHeight;
|
|
|
|
|
|
|
|
origNPos = ME_GetYScrollPos(editor);
|
|
|
|
lineHeight = 24;
|
|
|
|
|
2006-02-25 08:26:42 +01:00
|
|
|
if (editor && 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;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
|
|
|
switch(LOWORD(wParam))
|
2005-03-21 11:27:24 +01:00
|
|
|
{
|
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:
|
|
|
|
ME_ScrollAbs(editor,HIWORD(wParam));
|
|
|
|
break;
|
2005-03-21 11:27:24 +01:00
|
|
|
}
|
2006-02-25 08:26:42 +01:00
|
|
|
if (msg == EM_SCROLL)
|
2006-09-08 23:37:25 +02:00
|
|
|
return 0x00010000 | (((ME_GetYScrollPos(editor) - 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;
|
2006-09-08 23:37:25 +02:00
|
|
|
|
2005-04-11 16:22:21 +02:00
|
|
|
SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
|
2006-09-08 23:37:25 +02:00
|
|
|
gcWheelDelta = -GET_WHEEL_DELTA_WPARAM(wParam);
|
|
|
|
|
2005-04-11 16:22:21 +02:00
|
|
|
if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
|
2006-09-08 23:37:25 +02:00
|
|
|
{
|
|
|
|
/* FIXME follow the original */
|
|
|
|
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;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case EM_SETRECT:
|
|
|
|
case EM_SETRECTNP:
|
|
|
|
{
|
|
|
|
if (lParam)
|
|
|
|
{
|
|
|
|
RECT *rc = (RECT *)lParam;
|
|
|
|
|
|
|
|
if (wParam)
|
|
|
|
{
|
|
|
|
editor->rcFormat.left += rc->left;
|
|
|
|
editor->rcFormat.top += rc->top;
|
|
|
|
editor->rcFormat.right += rc->right;
|
|
|
|
editor->rcFormat.bottom += rc->bottom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
editor->rcFormat = *rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GetClientRect(hWnd, &editor->rcFormat);
|
|
|
|
}
|
|
|
|
if (msg != EM_SETRECTNP)
|
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
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:
|
|
|
|
editor->bRedraw = wParam;
|
|
|
|
return 0;
|
2005-03-05 12:19:14 +01:00
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2005-08-15 11:47:14 +02:00
|
|
|
GetClientRect(hWnd, &editor->rcFormat);
|
2005-07-24 18:17:43 +02:00
|
|
|
ME_RewrapRepaint(editor);
|
2005-03-05 12:19:14 +01:00
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
IUnknown_Release(editor->lpOleCallback);
|
|
|
|
editor->lpOleCallback = (LPRICHEDITOLECALLBACK)lParam;
|
|
|
|
if(editor->lpOleCallback)
|
|
|
|
IUnknown_AddRef(editor->lpOleCallback);
|
|
|
|
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;
|
|
|
|
}
|
2006-02-19 07:32:24 +01:00
|
|
|
case EM_SETTEXTMODE:
|
|
|
|
{
|
|
|
|
LRESULT ret;
|
|
|
|
int mask = 0;
|
|
|
|
int changes = 0;
|
|
|
|
if ((ret = RichEditANSIWndProc(hWnd, WM_GETTEXTLENGTH, 0, 0)) == 0)
|
|
|
|
{
|
|
|
|
/*Check for valid wParam*/
|
|
|
|
if ((((wParam & TM_RICHTEXT) && ((wParam & TM_PLAINTEXT) << 1))) ||
|
|
|
|
(((wParam & TM_MULTILEVELUNDO) && ((wParam & TM_SINGLELEVELUNDO) << 1))) ||
|
|
|
|
(((wParam & TM_MULTICODEPAGE) && ((wParam & TM_SINGLECODEPAGE) << 1))))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
|
|
|
|
{
|
|
|
|
mask |= (TM_RICHTEXT | TM_PLAINTEXT);
|
|
|
|
changes |= (wParam & (TM_RICHTEXT | TM_PLAINTEXT));
|
|
|
|
}
|
|
|
|
/*FIXME: Currently no support for undo level and code page options*/
|
|
|
|
editor->mode = (editor->mode & (~mask)) | changes;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2006-08-04 21:47:44 +02:00
|
|
|
}
|
|
|
|
case EM_SETPASSWORDCHAR:
|
|
|
|
{
|
|
|
|
editor->cPasswordMask = wParam;
|
|
|
|
ME_RewrapRepaint(editor);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
default:
|
|
|
|
do_default:
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2005-07-21 12:33:32 +02:00
|
|
|
LRESULT result;
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
/* FIXME: this is NOT the same as 2.0 version */
|
2005-07-21 12:33:32 +02:00
|
|
|
result = RichEditANSIWndProc(hWnd, msg, wParam, lParam);
|
|
|
|
if (msg == WM_NCCREATE)
|
|
|
|
{
|
2006-08-03 18:20:01 +02:00
|
|
|
ME_TextEditor *editor = (ME_TextEditor *)GetWindowLongPtrW(hWnd, 0);
|
2005-07-21 12:33:32 +02:00
|
|
|
|
|
|
|
editor->bEmulateVersion10 = TRUE;
|
|
|
|
editor->pBuffer->pLast->member.para.nCharOfs = 2;
|
|
|
|
}
|
|
|
|
return result;
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ME_SendOldNotify(ME_TextEditor *editor, int nCode)
|
|
|
|
{
|
|
|
|
HWND hWnd = editor->hWnd;
|
|
|
|
SendMessageA(GetParent(hWnd), WM_COMMAND, (nCode<<16)|GetWindowLongW(hWnd, GWLP_ID), (LPARAM)hWnd);
|
|
|
|
}
|
|
|
|
|
2006-08-17 04:29:17 +02:00
|
|
|
void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
int x,y;
|
|
|
|
ME_Cursor tmpCursor;
|
2007-01-23 21:44:29 +01:00
|
|
|
int nCharOfs; /* The start of the clicked text. Absolute character offset */
|
|
|
|
|
2006-08-17 04:29:17 +02:00
|
|
|
ME_Run *tmpRun;
|
2007-01-23 21:44:29 +01:00
|
|
|
|
2006-08-17 04:29:17 +02:00
|
|
|
ENLINK info;
|
|
|
|
x = (short)LOWORD(lParam);
|
|
|
|
y = (short)HIWORD(lParam);
|
2007-01-23 21:44:29 +01:00
|
|
|
nCharOfs = ME_CharFromPos(editor, x, y);
|
|
|
|
ME_CursorFromCharOfs(editor, nCharOfs, &tmpCursor);
|
2006-08-17 04:29:17 +02:00
|
|
|
tmpRun = &tmpCursor.pRun->member.run;
|
2007-01-23 21:44:29 +01:00
|
|
|
|
|
|
|
if ((tmpRun->style->fmt.dwMask & CFM_LINK)
|
2006-08-17 04:29:17 +02:00
|
|
|
&& (tmpRun->style->fmt.dwEffects & CFE_LINK))
|
|
|
|
{ /* The clicked run has CFE_LINK set */
|
|
|
|
info.nmhdr.hwndFrom = editor->hWnd;
|
|
|
|
info.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
|
|
|
|
info.nmhdr.code = EN_LINK;
|
|
|
|
info.msg = msg;
|
|
|
|
info.wParam = wParam;
|
|
|
|
info.lParam = lParam;
|
|
|
|
info.chrg.cpMin = ME_CharOfsFromRunOfs(editor,tmpCursor.pRun,0);
|
|
|
|
info.chrg.cpMax = info.chrg.cpMin + ME_StrVLen(tmpRun->strText);
|
|
|
|
SendMessageW(GetParent(editor->hWnd), WM_NOTIFY,info.nmhdr.idFrom, (LPARAM)&info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
int ME_CountParagraphsBetween(ME_TextEditor *editor, int from, int to)
|
|
|
|
{
|
|
|
|
ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while(item && item->member.para.next_para->member.para.nCharOfs <= from)
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
if (!item)
|
|
|
|
return 0;
|
|
|
|
while(item && item->member.para.next_para->member.para.nCharOfs <= to) {
|
|
|
|
item = item->member.para.next_para;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2005-03-14 22:41:16 +01:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, int bCRLF)
|
|
|
|
{
|
2005-03-14 22:41:16 +01:00
|
|
|
ME_DisplayItem *item = ME_FindItemAtOffset(editor, diRun, nStart, &nStart);
|
2005-03-05 12:19:14 +01:00
|
|
|
int nWritten = 0;
|
2005-10-19 21:22:11 +02:00
|
|
|
WCHAR *pStart = buffer;
|
2005-03-05 12:19:14 +01:00
|
|
|
|
|
|
|
if (!item) {
|
|
|
|
*buffer = L'\0';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nStart)
|
|
|
|
{
|
|
|
|
int nLen = ME_StrLen(item->member.run.strText) - nStart;
|
|
|
|
if (nLen > nChars)
|
|
|
|
nLen = nChars;
|
|
|
|
CopyMemory(buffer, item->member.run.strText->szData + nStart, sizeof(WCHAR)*nLen);
|
|
|
|
nChars -= nLen;
|
|
|
|
nWritten += nLen;
|
|
|
|
if (!nChars)
|
|
|
|
return nWritten;
|
|
|
|
buffer += nLen;
|
|
|
|
nStart = 0;
|
|
|
|
item = ME_FindItemFwd(item, diRun);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(nChars && item)
|
|
|
|
{
|
|
|
|
int nLen = ME_StrLen(item->member.run.strText);
|
|
|
|
if (nLen > nChars)
|
|
|
|
nLen = nChars;
|
2006-04-23 21:09:30 +02:00
|
|
|
|
2005-03-05 12:19:14 +01:00
|
|
|
if (item->member.run.nFlags & MERF_ENDPARA)
|
|
|
|
{
|
2006-04-23 21:09:30 +02:00
|
|
|
if (!ME_FindItemFwd(item, diRun))
|
|
|
|
/* No '\r' is appended to the last paragraph. */
|
|
|
|
nLen = 0;
|
|
|
|
else {
|
|
|
|
*buffer = '\r';
|
|
|
|
if (bCRLF)
|
|
|
|
{
|
|
|
|
*(++buffer) = '\n';
|
|
|
|
nWritten++;
|
|
|
|
}
|
|
|
|
assert(nLen == 1);
|
|
|
|
/* our end paragraph consists of 2 characters now */
|
|
|
|
if (editor->bEmulateVersion10)
|
|
|
|
nChars--;
|
2005-08-15 11:47:14 +02:00
|
|
|
}
|
2005-03-05 12:19:14 +01:00
|
|
|
}
|
2006-04-23 21:09:30 +02:00
|
|
|
else
|
2005-03-05 12:19:14 +01:00
|
|
|
CopyMemory(buffer, item->member.run.strText->szData, sizeof(WCHAR)*nLen);
|
|
|
|
nChars -= nLen;
|
|
|
|
nWritten += nLen;
|
|
|
|
buffer += nLen;
|
|
|
|
|
|
|
|
if (!nChars)
|
|
|
|
{
|
2005-10-19 21:22:11 +02:00
|
|
|
TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
|
2005-03-05 12:19:14 +01:00
|
|
|
*buffer = L'\0';
|
|
|
|
return nWritten;
|
|
|
|
}
|
|
|
|
item = ME_FindItemFwd(item, diRun);
|
|
|
|
}
|
|
|
|
*buffer = L'\0';
|
2005-10-19 21:22:11 +02:00
|
|
|
TRACE("nWritten=%d, actual=%d\n", nWritten, buffer-pStart);
|
2005-03-05 12:19:14 +01:00
|
|
|
return nWritten;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ME_RegisterEditorClass(HINSTANCE hInstance)
|
|
|
|
{
|
|
|
|
BOOL bResult;
|
|
|
|
WNDCLASSW wcW;
|
|
|
|
WNDCLASSA wcA;
|
|
|
|
|
2006-01-13 13:54:11 +01:00
|
|
|
wcW.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
2005-03-05 12:19:14 +01:00
|
|
|
wcW.lpfnWndProc = RichEditANSIWndProc;
|
|
|
|
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;
|
|
|
|
wcW.hCursor = LoadCursorW(NULL, MAKEINTRESOURCEW(IDC_IBEAM));
|
|
|
|
wcW.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
|
|
|
|
wcW.lpszMenuName = NULL;
|
|
|
|
wcW.lpszClassName = wszClassName;
|
|
|
|
bResult = RegisterClassW(&wcW);
|
|
|
|
assert(bResult);
|
|
|
|
wcW.lpszClassName = wszClassName50;
|
|
|
|
bResult = RegisterClassW(&wcW);
|
|
|
|
assert(bResult);
|
|
|
|
|
2006-01-13 13:54:11 +01:00
|
|
|
wcA.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
|
2005-03-05 12:19:14 +01:00
|
|
|
wcA.lpfnWndProc = RichEditANSIWndProc;
|
|
|
|
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));
|
|
|
|
wcA.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
|
|
|
|
wcA.lpszMenuName = NULL;
|
|
|
|
wcA.lpszClassName = "RichEdit20A";
|
|
|
|
bResult = RegisterClassA(&wcA);
|
|
|
|
assert(bResult);
|
|
|
|
wcA.lpszClassName = "RichEdit50A";
|
|
|
|
bResult = RegisterClassA(&wcA);
|
|
|
|
assert(bResult);
|
|
|
|
}
|
2006-01-30 18:16:05 +01:00
|
|
|
|
2005-12-05 12:48:45 +01:00
|
|
|
LRESULT WINAPI REComboWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
/* FIXME: Not implemented */
|
|
|
|
TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
|
|
|
|
hWnd, msg, get_msg_name(msg), wParam, lParam);
|
|
|
|
return DefWindowProcW(hWnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT WINAPI REListWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
/* FIXME: Not implemented */
|
|
|
|
TRACE("hWnd %p msg %04x (%s) %08x %08lx\n",
|
|
|
|
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;
|
|
|
|
wcW.lpszClassName = wszClassNameListBox;
|
|
|
|
if (RegisterClassW(&wcW)) ME_ListBoxRegistered = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ME_ComboBoxRegistered)
|
|
|
|
{
|
|
|
|
wcW.style = CS_PARENTDC | CS_DBLCLKS | CS_GLOBALCLASS | CS_VREDRAW | CS_HREDRAW;
|
|
|
|
wcW.lpfnWndProc = REComboWndProc;
|
|
|
|
wcW.lpszClassName = wszClassNameComboBox;
|
|
|
|
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
|
|
|
|
|
|
|
int ME_AutoURLDetect(ME_TextEditor *editor, WCHAR curChar)
|
|
|
|
{
|
|
|
|
struct prefix_s {
|
2006-07-21 22:05:00 +02:00
|
|
|
const char *text;
|
2006-03-01 11:49:42 +01:00
|
|
|
int length;
|
|
|
|
} prefixes[12] = {
|
|
|
|
{"http:", 5},
|
|
|
|
{"file:", 6},
|
|
|
|
{"mailto:", 8},
|
|
|
|
{"ftp:", 5},
|
|
|
|
{"https:", 7},
|
|
|
|
{"gopher:", 8},
|
|
|
|
{"nntp:", 6},
|
|
|
|
{"prospero:", 10},
|
|
|
|
{"telnet:", 8},
|
|
|
|
{"news:", 6},
|
|
|
|
{"wais:", 6},
|
|
|
|
{"www.", 5}
|
|
|
|
};
|
|
|
|
CHARRANGE ins_pt;
|
|
|
|
int curf_ef, link_ef, def_ef;
|
|
|
|
int cur_prefx, prefx_cnt;
|
|
|
|
int sel_min, sel_max;
|
|
|
|
int car_pos = 0;
|
|
|
|
int text_pos=-1;
|
2006-03-02 18:03:32 +01:00
|
|
|
int URLmin, URLmax = 0;
|
2006-03-01 11:49:42 +01:00
|
|
|
CHARRANGE url;
|
|
|
|
FINDTEXTA ft;
|
|
|
|
CHARFORMAT2W cur_format;
|
|
|
|
CHARFORMAT2W default_format;
|
|
|
|
CHARFORMAT2W link;
|
|
|
|
RichEditANSIWndProc(editor->hWnd, EM_EXGETSEL, (WPARAM) 0, (LPARAM) &ins_pt);
|
|
|
|
sel_min = ins_pt.cpMin;
|
|
|
|
sel_max = ins_pt.cpMax;
|
|
|
|
if (sel_min==sel_max)
|
|
|
|
car_pos = sel_min;
|
|
|
|
if (sel_min!=sel_max)
|
|
|
|
car_pos = ME_GetTextLength(editor)+1;
|
|
|
|
cur_format.cbSize = sizeof(cur_format);
|
|
|
|
default_format.cbSize = sizeof(default_format);
|
|
|
|
RichEditANSIWndProc(editor->hWnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cur_format);
|
|
|
|
RichEditANSIWndProc(editor->hWnd, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &default_format);
|
|
|
|
link.cbSize = sizeof(link);
|
2006-08-17 04:29:17 +02:00
|
|
|
link.dwMask = CFM_LINK;
|
|
|
|
link.dwEffects = CFE_LINK;
|
2006-03-01 11:49:42 +01:00
|
|
|
curf_ef = cur_format.dwEffects & link.dwEffects;
|
|
|
|
def_ef = default_format.dwEffects & link.dwEffects;
|
|
|
|
link_ef = link.dwEffects & link.dwEffects;
|
|
|
|
if (curf_ef == link_ef)
|
|
|
|
{
|
|
|
|
if( curChar == '\n' || curChar=='\r' || curChar==' ')
|
|
|
|
{
|
|
|
|
ME_SetSelection(editor, car_pos, car_pos);
|
|
|
|
RichEditANSIWndProc(editor->hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &default_format);
|
|
|
|
text_pos=-1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (curf_ef == def_ef)
|
|
|
|
{
|
|
|
|
cur_prefx = 0;
|
|
|
|
prefx_cnt = (sizeof(prefixes)/sizeof(struct prefix_s))-1;
|
|
|
|
while (cur_prefx<=prefx_cnt)
|
|
|
|
{
|
|
|
|
if (text_pos == -1)
|
|
|
|
{
|
|
|
|
ft.lpstrText = prefixes[cur_prefx].text;
|
|
|
|
URLmin=max(0,(car_pos-prefixes[cur_prefx].length));
|
|
|
|
URLmax=max(0, car_pos);
|
|
|
|
if ((car_pos == 0) && (ME_GetTextLength(editor) != 0))
|
|
|
|
{
|
|
|
|
URLmax = ME_GetTextLength(editor)+1;
|
|
|
|
}
|
|
|
|
ft.chrg.cpMin = URLmin;
|
|
|
|
ft.chrg.cpMax = URLmax;
|
|
|
|
text_pos=RichEditANSIWndProc(editor->hWnd, EM_FINDTEXT, FR_DOWN, (LPARAM)&ft);
|
|
|
|
cur_prefx++;
|
|
|
|
}
|
|
|
|
if (text_pos != -1)
|
|
|
|
{
|
|
|
|
url.cpMin=text_pos;
|
|
|
|
url.cpMax=car_pos-1;
|
|
|
|
ME_SetCharFormat(editor, text_pos, (URLmax-text_pos), &link);
|
2006-09-08 23:37:25 +02:00
|
|
|
ME_RewrapRepaint(editor);
|
2006-03-01 11:49:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|