ReactOS  0.4.14-dev-604-gcfdd483
editor.c File Reference
#include "editor.h"
#include "commdlg.h"
#include "winreg.h"
#include "shlwapi.h"
#include "rtf.h"
#include "imm.h"
#include "res.h"
Include dependency graph for editor.c:

Go to the source code of this file.

Classes

struct  tagME_RTFStringStreamStruct
 
struct  tagME_GlobalDestStruct
 
struct  paste_format
 

Macros

#define NONAMELESSUNION
 
#define NO_SHLWAPI_STREAM
 
#define STACK_SIZE_DEFAULT   100
 
#define STACK_SIZE_MAX   1000
 
#define TEXT_LIMIT_DEFAULT   32767
 
#define UNSUPPORTED_MSG(e)
 
#define MAX_PREFIX_LEN   9
 

Typedefs

typedef struct tagME_RTFStringStreamStruct ME_RTFStringStreamStruct
 
typedef struct tagME_GlobalDestStruct ME_GlobalDestStruct
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (richedit)
 
static BOOL ME_RegisterEditorClass (HINSTANCE)
 
static BOOL ME_UpdateLinkAttribute (ME_TextEditor *editor, ME_Cursor *start, int nChars)
 
static BOOL is_version_nt (void)
 
static ME_TextBufferME_MakeText (void)
 
static LRESULT ME_StreamInText (ME_TextEditor *editor, DWORD dwFormat, ME_InStream *stream, ME_Style *style)
 
static void ME_ApplyBorderProperties (RTF_Info *info, ME_BorderRect *borderRect, RTFBorder *borderDef)
 
void ME_RTFCharAttrHook (RTF_Info *info)
 
void ME_RTFParAttrHook (RTF_Info *info)
 
void ME_RTFTblAttrHook (RTF_Info *info)
 
void ME_RTFSpecialCharHook (RTF_Info *info)
 
static HRESULT insert_static_object (ME_TextEditor *editor, HENHMETAFILE hemf, HBITMAP hbmp, const SIZEL *sz)
 
static void ME_RTFReadShpPictGroup (RTF_Info *info)
 
static DWORD read_hex_data (RTF_Info *info, BYTE **out)
 
static void ME_RTFReadPictGroup (RTF_Info *info)
 
static void ME_RTFReadObjectGroup (RTF_Info *info)
 
static void ME_RTFReadParnumGroup (RTF_Info *info)
 
static void ME_RTFReadHook (RTF_Info *info)
 
void ME_StreamInFill (ME_InStream *stream)
 
static LRESULT ME_StreamIn (ME_TextEditor *editor, DWORD format, EDITSTREAM *stream, BOOL stripLastCR)
 
static DWORD CALLBACK ME_ReadFromRTFString (DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
 
static void ME_StreamInRTFString (ME_TextEditor *editor, BOOL selection, char *string)
 
static int ME_FindText (ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText)
 
static int ME_GetTextEx (ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
 
static int ME_GetTextRange (ME_TextEditor *editor, WCHAR *strText, const ME_Cursor *start, int nLen, BOOL unicode)
 
int set_selection (ME_TextEditor *editor, int to, int from)
 
static DWORD CALLBACK ME_ReadFromHGLOBALUnicode (DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
 
static DWORD CALLBACK ME_ReadFromHGLOBALRTF (DWORD_PTR dwCookie, LPBYTE lpBuff, LONG cb, LONG *pcb)
 
static HRESULT paste_rtf (ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
 
static HRESULT paste_text (ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
 
static HRESULT paste_emf (ME_TextEditor *editor, FORMATETC *fmt, STGMEDIUM *med)
 
static void init_paste_formats (void)
 
static BOOL paste_special (ME_TextEditor *editor, UINT cf, REPASTESPECIAL *ps, BOOL check_only)
 
static BOOL ME_Copy (ME_TextEditor *editor, const ME_Cursor *start, int nChars)
 
static BOOL copy_or_cut (ME_TextEditor *editor, BOOL cut)
 
static BOOL ME_FilterEvent (ME_TextEditor *editor, UINT msg, WPARAM *wParam, LPARAM *lParam)
 
static void ME_UpdateSelectionLinkAttribute (ME_TextEditor *editor)
 
static BOOL handle_enter (ME_TextEditor *editor)
 
static BOOL ME_KeyDown (ME_TextEditor *editor, WORD nKey)
 
static LRESULT ME_Char (ME_TextEditor *editor, WPARAM charCode, LPARAM flags, BOOL unicode)
 
static int ME_CalculateClickCount (ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
 
static BOOL is_link (ME_Run *run)
 
static BOOL ME_SetCursor (ME_TextEditor *editor)
 
static void ME_SetDefaultFormatRect (ME_TextEditor *editor)
 
static LONG ME_GetSelectionType (ME_TextEditor *editor)
 
static BOOL ME_ShowContextMenu (ME_TextEditor *editor, int x, int y)
 
ME_TextEditorME_MakeEditor (ITextHost *texthost, BOOL bEmulateVersion10)
 
void ME_DestroyEditor (ME_TextEditor *editor)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 
static int get_default_line_height (ME_TextEditor *editor)
 
static int calc_wheel_change (int *remain, int amount_per_click)
 
static const charget_msg_name (UINT msg)
 
static void ME_LinkNotify (ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
 
void ME_ReplaceSel (ME_TextEditor *editor, BOOL can_undo, const WCHAR *str, int len)
 
static void ME_SetText (ME_TextEditor *editor, void *text, BOOL unicode)
 
static LRESULT ME_WmCreate (ME_TextEditor *editor, LPARAM lParam, BOOL unicode)
 
static LRESULT handle_EM_SETCHARFORMAT (ME_TextEditor *editor, WPARAM flags, const CHARFORMAT2W *fmt_in)
 
LRESULT ME_HandleMessage (ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode, HRESULT *phresult)
 
static BOOL create_windowed_editor (HWND hwnd, CREATESTRUCTW *create, BOOL emulate_10)
 
static LRESULT RichEditWndProc_common (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
 
static LRESULT WINAPI RichEditWndProcW (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI RichEditWndProcA (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
LRESULT WINAPI RichEditANSIWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
LRESULT WINAPI RichEdit10ANSIWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
void ME_SendOldNotify (ME_TextEditor *editor, int nCode)
 
int ME_GetTextW (ME_TextEditor *editor, WCHAR *buffer, int buflen, const ME_Cursor *start, int srcChars, BOOL bCRLF, BOOL bEOP)
 
static LRESULT WINAPI REComboWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
static LRESULT WINAPI REListWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
LRESULT WINAPI REExtendedRegisterClass (void)
 
static int __cdecl wchar_comp (const void *key, const void *elem)
 
static BOOL isurlneutral (WCHAR c)
 
static BOOL ME_FindNextURLCandidate (ME_TextEditor *editor, const ME_Cursor *start, int nChars, ME_Cursor *candidate_min, ME_Cursor *candidate_max)
 
static BOOL ME_IsCandidateAnURL (ME_TextEditor *editor, const ME_Cursor *start, int nChars)
 

Variables

static const WCHAR REListBox20W [] = {'R','E','L','i','s','t','B','o','x','2','0','W', 0}
 
static const WCHAR REComboBox20W [] = {'R','E','C','o','m','b','o','B','o','x','2','0','W', 0}
 
static HCURSOR hLeft
 
BOOL me_debug = FALSE
 
HANDLE me_heap = NULL
 
static BOOL ME_ListBoxRegistered = FALSE
 
static BOOL ME_ComboBoxRegistered = FALSE
 
static const WCHAR rtfW [] = {'R','i','c','h',' ','T','e','x','t',' ','F','o','r','m','a','t',0}
 
static struct paste_format paste_formats []
 
static const char *const edit_messages []
 
static const char *const richedit_messages []
 

Macro Definition Documentation

◆ MAX_PREFIX_LEN

#define MAX_PREFIX_LEN   9

◆ NO_SHLWAPI_STREAM

#define NO_SHLWAPI_STREAM

Definition at line 232 of file editor.c.

◆ NONAMELESSUNION

#define NONAMELESSUNION

Definition at line 227 of file editor.c.

◆ STACK_SIZE_DEFAULT

#define STACK_SIZE_DEFAULT   100

Definition at line 242 of file editor.c.

◆ STACK_SIZE_MAX

#define STACK_SIZE_MAX   1000

Definition at line 243 of file editor.c.

◆ TEXT_LIMIT_DEFAULT

#define TEXT_LIMIT_DEFAULT   32767

Definition at line 245 of file editor.c.

◆ UNSUPPORTED_MSG

#define UNSUPPORTED_MSG (   e)
Value:
case e: \
FIXME(#e ": stub\n"); \
*phresult = S_FALSE; \
return 0;
#define e
Definition: ke_i.h:82
#define S_FALSE
Definition: winerror.h:2357

Definition at line 3589 of file editor.c.

Typedef Documentation

◆ ME_GlobalDestStruct

◆ ME_RTFStringStreamStruct

Function Documentation

◆ calc_wheel_change()

static int calc_wheel_change ( int remain,
int  amount_per_click 
)
inlinestatic

Definition at line 3276 of file editor.c.

3277 {
3278  int change = amount_per_click * (float)*remain / WHEEL_DELTA;
3279  *remain -= WHEEL_DELTA * change / amount_per_click;
3280  return change;
3281 }
#define WHEEL_DELTA
Definition: treelist.c:99
static float(__cdecl *square_half_float)(float x

Referenced by ME_HandleMessage().

◆ copy_or_cut()

static BOOL copy_or_cut ( ME_TextEditor editor,
BOOL  cut 
)
static

Definition at line 2360 of file editor.c.

2361 {
2362  BOOL result;
2363  int offs, num_chars;
2364  int start_cursor = ME_GetSelectionOfs(editor, &offs, &num_chars);
2365  ME_Cursor *sel_start = &editor->pCursors[start_cursor];
2366 
2367  if (cut && (editor->styleFlags & ES_READONLY))
2368  {
2370  return FALSE;
2371  }
2372 
2373  num_chars -= offs;
2374  result = ME_Copy(editor, sel_start, num_chars);
2375  if (result && cut)
2376  {
2377  ME_InternalDeleteText(editor, sel_start, num_chars, FALSE);
2378  ME_CommitUndo(editor);
2379  ME_UpdateRepaint(editor, TRUE);
2380  }
2381  return result;
2382 }
#define TRUE
Definition: types.h:120
DWORD styleFlags
Definition: editstr.h:392
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
#define ES_READONLY
Definition: pedump.c:675
void ME_UpdateRepaint(ME_TextEditor *editor, BOOL update_now) DECLSPEC_HIDDEN
Definition: paint.c:116
unsigned int BOOL
Definition: ntddk_ex.h:94
BOOL ME_InternalDeleteText(ME_TextEditor *editor, ME_Cursor *start, int nChars, BOOL bForce)
Definition: caret.c:315
#define MB_ICONERROR
Definition: winuser.h:781
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:227
BOOL WINAPI MessageBeep(_In_ UINT)
static BOOL ME_Copy(ME_TextEditor *editor, const ME_Cursor *start, int nChars)
Definition: editor.c:2336
ME_Cursor * pCursors
Definition: editstr.h:391
GLuint64EXT * result
Definition: glext.h:11304

Referenced by ME_HandleMessage(), and ME_KeyDown().

◆ create_windowed_editor()

static BOOL create_windowed_editor ( HWND  hwnd,
CREATESTRUCTW create,
BOOL  emulate_10 
)
static

Definition at line 4936 of file editor.c.

4937 {
4938  ITextHost *host = ME_CreateTextHost( hwnd, create, emulate_10 );
4939  ME_TextEditor *editor;
4940 
4941  if (!host) return FALSE;
4942 
4943  editor = ME_MakeEditor( host, emulate_10 );
4944  if (!editor)
4945  {
4946  ITextHost_Release( host );
4947  return FALSE;
4948  }
4949 
4952  editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */
4953  editor->hwndParent = create->hwndParent;
4954 
4955  SetWindowLongPtrW( hwnd, 0, (LONG_PTR)editor );
4956 
4957  return TRUE;
4958 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define TRUE
Definition: types.h:120
DWORD styleFlags
Definition: editstr.h:392
char * host
Definition: whois.c:55
#define GWL_EXSTYLE
Definition: winuser.h:845
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
#define ES_WANTRETURN
Definition: pedump.c:676
ME_TextEditor * ME_MakeEditor(ITextHost *texthost, BOOL bEmulateVersion10)
Definition: editor.c:3052
#define GWL_STYLE
Definition: winuser.h:846
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
ITextHost * ME_CreateTextHost(HWND hwnd, CREATESTRUCTW *cs, BOOL bEmulateVersion10) DECLSPEC_HIDDEN
Definition: txthost.c:44
DWORD exStyleFlags
Definition: editstr.h:393
#define SetWindowLongPtrW
Definition: winuser.h:5321
static const struct access_res create[16]
Definition: package.c:7720

Referenced by RichEdit10ANSIWndProc(), and RichEditWndProc_common().

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 3234 of file editor.c.

3235 {
3236  TRACE("\n");
3237  switch (fdwReason)
3238  {
3239  case DLL_PROCESS_ATTACH:
3240  DisableThreadLibraryCalls(hinstDLL);
3241  me_heap = HeapCreate (0, 0x10000, 0);
3242  if (!ME_RegisterEditorClass(hinstDLL)) return FALSE;
3244  LookupInit();
3245  break;
3246 
3247  case DLL_PROCESS_DETACH:
3248  if (lpvReserved) break;
3252  UnregisterClassA("RichEdit50A", 0);
3257  LookupCleanup();
3258  HeapDestroy (me_heap);
3259  release_typelib();
3260  break;
3261  }
3262  return TRUE;
3263 }
#define TRUE
Definition: types.h:120
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
static const WCHAR RICHEDIT_CLASS20W[]
Definition: richedit.h:50
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
static IN DWORD IN LPVOID lpvReserved
BOOL WINAPI HeapDestroy(HANDLE hHeap)
Definition: heapmem.c:85
static const WCHAR REListBox20W[]
Definition: editor.c:252
#define OCR_REVERSE
Definition: res.h:23
HANDLE me_heap
Definition: editor.c:257
static const WCHAR REComboBox20W[]
Definition: editor.c:253
static BOOL ME_ListBoxRegistered
Definition: editor.c:259
#define DLL_PROCESS_DETACH
Definition: compat.h:119
#define TRACE(s)
Definition: solgame.cpp:4
HCURSOR WINAPI LoadCursorW(_In_opt_ HINSTANCE, _In_ LPCWSTR)
Definition: cursoricon.c:2074
void release_typelib(void)
Definition: apps.c:159
static HCURSOR hLeft
Definition: editor.c:254
static const WCHAR MSFTEDIT_CLASS[]
Definition: richedit.h:40
static BOOL ME_ComboBoxRegistered
Definition: editor.c:260
void LookupCleanup(void)
Definition: reader.c:2210
void LookupInit(void)
Definition: reader.c:2191
#define RICHEDIT_CLASS20A
Definition: richedit.h:43
BOOL WINAPI UnregisterClassA(_In_ LPCSTR, HINSTANCE)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
static BOOL ME_RegisterEditorClass(HINSTANCE)
Definition: editor.c:5195

◆ get_default_line_height()

static int get_default_line_height ( ME_TextEditor editor)
inlinestatic

Definition at line 3265 of file editor.c.

3266 {
3267  int height = 0;
3268 
3269  if (editor->pBuffer && editor->pBuffer->pDefaultStyle)
3270  height = editor->pBuffer->pDefaultStyle->tm.tmHeight;
3271  if (height <= 0) height = 24;
3272 
3273  return height;
3274 }
TEXTMETRICW tm
Definition: editstr.h:80
ME_TextBuffer * pBuffer
Definition: editstr.h:390
ME_Style * pDefaultStyle
Definition: editstr.h:274
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
LONG tmHeight
Definition: wingdi.h:2382

Referenced by ME_HandleMessage().

◆ get_msg_name()

static const char* get_msg_name ( UINT  msg)
static

Definition at line 3410 of file editor.c.

3411 {
3412  if (msg >= EM_GETSEL && msg <= EM_CHARFROMPOS)
3413  return edit_messages[msg - EM_GETSEL];
3414  if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
3415  return richedit_messages[msg - EM_CANPASTE];
3416  return "";
3417 }
#define EM_CANPASTE
Definition: richedit.h:83
#define EM_CHARFROMPOS
Definition: richedit.h:78
#define EM_GETSEL
Definition: winuser.h:1979
#define EM_GETIMEMODEBIAS
Definition: richedit.h:152
static const char *const richedit_messages[]
Definition: editor.c:3328
#define msg(x)
Definition: auth_time.c:54
static const char *const edit_messages[]
Definition: editor.c:3283

Referenced by REComboWndProc(), REListWndProc(), and RichEditWndProc_common().

◆ handle_EM_SETCHARFORMAT()

static LRESULT handle_EM_SETCHARFORMAT ( ME_TextEditor editor,
WPARAM  flags,
const CHARFORMAT2W fmt_in 
)
static

Definition at line 3539 of file editor.c.

3540 {
3541  CHARFORMAT2W fmt;
3542  BOOL changed = TRUE;
3543  ME_Cursor start, end;
3544 
3545  if (!cfany_to_cf2w( &fmt, fmt_in )) return 0;
3546 
3547  if (flags & SCF_ALL)
3548  {
3549  if (editor->mode & TM_PLAINTEXT)
3550  {
3551  ME_SetDefaultCharFormat( editor, &fmt );
3552  }
3553  else
3554  {
3555  ME_SetCursorToStart( editor, &start );
3556  ME_SetCharFormat( editor, &start, NULL, &fmt );
3557  editor->nModifyStep = 1;
3558  }
3559  }
3560  else if (flags & SCF_SELECTION)
3561  {
3562  if (editor->mode & TM_PLAINTEXT) return 0;
3563  if (flags & SCF_WORD)
3564  {
3565  end = editor->pCursors[0];
3566  ME_MoveCursorWords( editor, &end, +1 );
3567  start = end;
3568  ME_MoveCursorWords( editor, &start, -1 );
3569  ME_SetCharFormat( editor, &start, &end, &fmt );
3570  }
3571  changed = ME_IsSelection( editor );
3572  ME_SetSelectionCharFormat( editor, &fmt );
3573  if (changed) editor->nModifyStep = 1;
3574  }
3575  else /* SCF_DEFAULT */
3576  {
3577  ME_SetDefaultCharFormat( editor, &fmt );
3578  }
3579 
3580  ME_CommitUndo( editor );
3581  if (changed)
3582  {
3583  ME_WrapMarkedParagraphs( editor );
3584  ME_UpdateScrollBar( editor );
3585  }
3586  return 1;
3587 }
#define TRUE
Definition: types.h:120
const char * fmt
Definition: wsprintf.c:30
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN
Definition: run.c:696
GLuint GLuint end
Definition: gl.h:1545
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
void ME_UpdateScrollBar(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:1148
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor)
Definition: caret.c:27
BOOL ME_MoveCursorWords(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs)
Definition: caret.c:754
BOOL ME_WrapMarkedParagraphs(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: wrap.c:1093
GLbitfield flags
Definition: glext.h:7161
#define SCF_ALL
Definition: richedit.h:237
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:227
BOOL cfany_to_cf2w(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN
Definition: style.c:36
#define TM_PLAINTEXT
Definition: richedit.h:1028
#define SCF_WORD
Definition: richedit.h:236
ME_Cursor * pCursors
Definition: editstr.h:391
GLuint start
Definition: gl.h:1545
void ME_SetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *mod) DECLSPEC_HIDDEN
Definition: style.c:540
void ME_SetCharFormat(ME_TextEditor *editor, ME_Cursor *start, ME_Cursor *end, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN
Definition: run.c:725
BOOL ME_IsSelection(ME_TextEditor *editor)
Definition: caret.c:1533
#define SCF_SELECTION
Definition: richedit.h:235
Definition: dsound.c:943

Referenced by ME_HandleMessage().

◆ handle_enter()

static BOOL handle_enter ( ME_TextEditor editor)
static

Definition at line 2434 of file editor.c.

2435 {
2436  BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
2437  BOOL shift_is_down = GetKeyState(VK_SHIFT) & 0x8000;
2438 
2439  if (editor->bDialogMode)
2440  {
2441  if (ctrl_is_down)
2442  return TRUE;
2443 
2444  if (!(editor->styleFlags & ES_WANTRETURN))
2445  {
2446  if (editor->hwndParent)
2447  {
2448  DWORD dw;
2449  dw = SendMessageW(editor->hwndParent, DM_GETDEFID, 0, 0);
2450  if (HIWORD(dw) == DC_HASDEFID)
2451  {
2452  HWND hwDefCtrl = GetDlgItem(editor->hwndParent, LOWORD(dw));
2453  if (hwDefCtrl)
2454  {
2455  SendMessageW(editor->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE);
2456  PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0);
2457  }
2458  }
2459  }
2460  return TRUE;
2461  }
2462  }
2463 
2464  if (editor->styleFlags & ES_MULTILINE)
2465  {
2466  static const WCHAR endl = '\r';
2467  static const WCHAR endlv10[] = {'\r','\n'};
2468  ME_Cursor cursor = editor->pCursors[0];
2469  ME_DisplayItem *para = cursor.pPara;
2470  int from, to;
2471  ME_Style *style, *eop_style;
2472 
2473  if (editor->styleFlags & ES_READONLY)
2474  {
2476  return TRUE;
2477  }
2478 
2479  ME_GetSelectionOfs(editor, &from, &to);
2480  if (editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
2481  {
2482  if (!editor->bEmulateVersion10) /* v4.1 */
2483  {
2484  if (para->member.para.nFlags & MEPF_ROWEND)
2485  {
2486  /* Add a new table row after this row. */
2487  para = ME_AppendTableRow(editor, para);
2488  para = para->member.para.next_para;
2489  editor->pCursors[0].pPara = para;
2490  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2491  editor->pCursors[0].nOffset = 0;
2492  editor->pCursors[1] = editor->pCursors[0];
2493  ME_CommitUndo(editor);
2495  ME_UpdateRepaint(editor, FALSE);
2496  return TRUE;
2497  }
2498  else if (para == editor->pCursors[1].pPara &&
2499  cursor.nOffset + cursor.pRun->member.run.nCharOfs == 0 &&
2500  para->member.para.prev_para->member.para.nFlags & MEPF_ROWSTART &&
2501  !para->member.para.prev_para->member.para.nCharOfs)
2502  {
2503  /* Insert a newline before the table. */
2504  para = para->member.para.prev_para;
2505  para->member.para.nFlags &= ~MEPF_ROWSTART;
2506  editor->pCursors[0].pPara = para;
2507  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2508  editor->pCursors[1] = editor->pCursors[0];
2509  ME_InsertTextFromCursor(editor, 0, &endl, 1,
2510  editor->pCursors[0].pRun->member.run.style);
2511  para = editor->pBuffer->pFirst->member.para.next_para;
2512  ME_SetDefaultParaFormat(editor, &para->member.para.fmt);
2513  para->member.para.nFlags = 0;
2514  mark_para_rewrap(editor, para);
2515  editor->pCursors[0].pPara = para;
2516  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2517  editor->pCursors[1] = editor->pCursors[0];
2518  para->member.para.next_para->member.para.nFlags |= MEPF_ROWSTART;
2519  ME_CommitCoalescingUndo(editor);
2521  ME_UpdateRepaint(editor, FALSE);
2522  return TRUE;
2523  }
2524  }
2525  else /* v1.0 - 3.0 */
2526  {
2527  ME_DisplayItem *para = cursor.pPara;
2528  if (ME_IsInTable(para))
2529  {
2530  if (cursor.pRun->member.run.nFlags & MERF_ENDPARA)
2531  {
2532  if (from == to)
2533  {
2535  para = ME_AppendTableRow(editor, para);
2536  editor->pCursors[0].pPara = para;
2537  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2538  editor->pCursors[0].nOffset = 0;
2539  editor->pCursors[1] = editor->pCursors[0];
2540  ME_CommitCoalescingUndo(editor);
2541  ME_UpdateRepaint(editor, FALSE);
2542  return TRUE;
2543  }
2544  }
2545  else
2546  {
2548  if (cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
2550  {
2551  /* Insert newline before table */
2552  cursor.pRun = ME_FindItemBack(para, diRun);
2553  if (cursor.pRun)
2554  {
2555  editor->pCursors[0].pRun = cursor.pRun;
2556  editor->pCursors[0].pPara = para->member.para.prev_para;
2557  }
2558  editor->pCursors[0].nOffset = 0;
2559  editor->pCursors[1] = editor->pCursors[0];
2560  ME_InsertTextFromCursor(editor, 0, &endl, 1,
2561  editor->pCursors[0].pRun->member.run.style);
2562  }
2563  else
2564  {
2565  editor->pCursors[1] = editor->pCursors[0];
2566  para = ME_AppendTableRow(editor, para);
2567  editor->pCursors[0].pPara = para;
2568  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2569  editor->pCursors[0].nOffset = 0;
2570  editor->pCursors[1] = editor->pCursors[0];
2571  }
2572  ME_CommitCoalescingUndo(editor);
2573  ME_UpdateRepaint(editor, FALSE);
2574  return TRUE;
2575  }
2576  }
2577  }
2578 
2579  style = ME_GetInsertStyle(editor, 0);
2580 
2581  /* Normally the new eop style is the insert style, however in a list it is copied from the existing
2582  eop style (this prevents the list label style changing when the new eop is inserted).
2583  No extra ref is taken here on eop_style. */
2584  if (para->member.para.fmt.wNumbering)
2585  eop_style = para->member.para.eop_run->style;
2586  else
2587  eop_style = style;
2589  if (shift_is_down)
2590  ME_InsertEndRowFromCursor(editor, 0);
2591  else
2592  if (!editor->bEmulateVersion10)
2593  ME_InsertTextFromCursor(editor, 0, &endl, 1, eop_style);
2594  else
2595  ME_InsertTextFromCursor(editor, 0, endlv10, 2, eop_style);
2596  ME_CommitCoalescingUndo(editor);
2597  SetCursor(NULL);
2598 
2600  ME_UpdateRepaint(editor, FALSE);
2601  ME_SaveTempStyle(editor, style); /* set the temp insert style for the new para */
2603  }
2604  return TRUE;
2605  }
2606  return FALSE;
2607 }
#define MEPF_ROWEND
Definition: editstr.h:149
void ME_SetDefaultParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN
Definition: para.c:992
ME_Paragraph para
Definition: editstr.h:266
#define TRUE
Definition: types.h:120
ME_Style * ME_GetInsertStyle(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN
Definition: style.c:476
#define WM_NEXTDLGCTL
Definition: winuser.h:1625
DWORD styleFlags
Definition: editstr.h:392
static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
Definition: editor.c:2406
#define ES_MULTILINE
Definition: pedump.c:667
void ME_CommitCoalescingUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:301
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style)
Definition: caret.c:550
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
struct tagME_DisplayItem * prev_para
Definition: editstr.h:221
UINT_PTR WPARAM
Definition: windef.h:207
#define ES_READONLY
Definition: pedump.c:675
ME_Style * style
Definition: editstr.h:164
void ME_InsertEndRowFromCursor(ME_TextEditor *editor, int nCursor)
Definition: caret.c:535
#define VK_RETURN
Definition: winuser.h:2176
void ME_ContinueCoalescingTransaction(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:265
#define DM_GETDEFID
Definition: winuser.h:2080
WORD wNumbering
Definition: richedit.h:668
void ME_UpdateRepaint(ME_TextEditor *editor, BOOL update_now) DECLSPEC_HIDDEN
Definition: paint.c:116
ME_DisplayItem * pFirst
Definition: editstr.h:272
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
unsigned int BOOL
Definition: ntddk_ex.h:94
#define DC_HASDEFID
Definition: winuser.h:2584
#define MERF_ENDPARA
Definition: editstr.h:126
ME_TextBuffer * pBuffer
Definition: editstr.h:390
#define VK_SHIFT
Definition: winuser.h:2177
#define ES_WANTRETURN
Definition: pedump.c:676
smooth NULL
Definition: ftsmooth.c:416
Definition: editstr.h:91
#define WM_KEYDOWN
Definition: winuser.h:1697
SHORT WINAPI GetKeyState(_In_ int)
ME_DisplayItem * ME_AppendTableRow(ME_TextEditor *editor, ME_DisplayItem *table_row) DECLSPEC_HIDDEN
Definition: table.c:407
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:462
BOOL bDialogMode
Definition: editstr.h:432
unsigned long DWORD
Definition: ntddk_ex.h:95
REFIID LPVOID DWORD dw
Definition: atlbase.h:40
ME_DisplayItem * pPara
Definition: editstr.h:279
BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN
Definition: table.c:273
ME_Run * eop_run
Definition: editstr.h:220
void ME_CheckTablesForCorruption(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: table.c:192
#define MEPF_ROWSTART
Definition: editstr.h:148
void ME_SaveTempStyle(ME_TextEditor *editor, ME_Style *style) DECLSPEC_HIDDEN
Definition: style.c:514
int nOffset
Definition: editstr.h:281
#define MB_ICONERROR
Definition: winuser.h:781
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:227
BOOL WINAPI MessageBeep(_In_ UINT)
const char cursor[]
Definition: icontest.c:13
BOOL bEmulateVersion10
Definition: editstr.h:389
ME_Cursor * pCursors
Definition: editstr.h:391
HCURSOR WINAPI SetCursor(_In_opt_ HCURSOR)
PARAFORMAT2 fmt
Definition: editstr.h:208
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
struct tagME_DisplayItem * next_para
Definition: editstr.h:221
ME_DisplayItem * pRun
Definition: editstr.h:280
#define VK_CONTROL
Definition: winuser.h:2178
BOOL WINAPI PostMessageW(_In_opt_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define HIWORD(l)
Definition: typedefs.h:246
ME_DisplayItem * ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:134
void mark_para_rewrap(ME_TextEditor *editor, ME_DisplayItem *para) DECLSPEC_HIDDEN
Definition: para.c:26
CardRegion * from
Definition: spigame.cpp:19
Arabic default style
Definition: afstyles.h:93
#define LOWORD(l)
Definition: pedump.c:82
int ME_GetTextLength(ME_TextEditor *editor)
Definition: caret.c:83
ME_DisplayItem * ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:111
union tagME_DisplayItem::@521 member

Referenced by ME_Char(), and ME_KeyDown().

◆ init_paste_formats()

static void init_paste_formats ( void  )
static

Definition at line 2272 of file editor.c.

2273 {
2274  struct paste_format *format;
2275  static int done;
2276 
2277  if (!done)
2278  {
2279  for (format = paste_formats; format->fmt.cfFormat; format++)
2280  {
2281  if (format->name)
2282  format->fmt.cfFormat = RegisterClipboardFormatW( format->name );
2283  }
2284  done = 1;
2285  }
2286 }
UINT WINAPI RegisterClipboardFormatW(_In_ LPCWSTR)
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static struct paste_format paste_formats[]

Referenced by paste_special().

◆ insert_static_object()

static HRESULT insert_static_object ( ME_TextEditor editor,
HENHMETAFILE  hemf,
HBITMAP  hbmp,
const SIZEL sz 
)
static

Definition at line 1123 of file editor.c.

1125 {
1126  LPOLEOBJECT lpObject = NULL;
1127  LPSTORAGE lpStorage = NULL;
1128  LPOLECLIENTSITE lpClientSite = NULL;
1129  LPDATAOBJECT lpDataObject = NULL;
1130  LPOLECACHE lpOleCache = NULL;
1131  LPRICHEDITOLE lpReOle = NULL;
1132  STGMEDIUM stgm;
1133  FORMATETC fm;
1134  CLSID clsid;
1135  HRESULT hr = E_FAIL;
1136  DWORD conn;
1137 
1138  if (hemf)
1139  {
1140  stgm.tymed = TYMED_ENHMF;
1141  stgm.u.hEnhMetaFile = hemf;
1142  fm.cfFormat = CF_ENHMETAFILE;
1143  }
1144  else if (hbmp)
1145  {
1146  stgm.tymed = TYMED_GDI;
1147  stgm.u.hBitmap = hbmp;
1148  fm.cfFormat = CF_BITMAP;
1149  }
1150  stgm.pUnkForRelease = NULL;
1151 
1152  fm.ptd = NULL;
1153  fm.dwAspect = DVASPECT_CONTENT;
1154  fm.lindex = -1;
1155  fm.tymed = stgm.tymed;
1156 
1157  if (!editor->reOle)
1158  {
1159  if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
1160  return hr;
1161  }
1162 
1163  if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
1164  IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (void**)&lpReOle) == S_OK &&
1165  IRichEditOle_GetClientSite(lpReOle, &lpClientSite) == S_OK &&
1166  IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
1167  IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
1168  IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
1169  IOleCache_Cache(lpOleCache, &fm, 0, &conn) == S_OK &&
1170  IOleObject_QueryInterface(lpObject, &IID_IDataObject, (void**)&lpDataObject) == S_OK &&
1171  IDataObject_SetData(lpDataObject, &fm, &stgm, TRUE) == S_OK)
1172  {
1173  REOBJECT reobject;
1174 
1175  reobject.cbStruct = sizeof(reobject);
1176  reobject.cp = REO_CP_SELECTION;
1177  reobject.clsid = clsid;
1178  reobject.poleobj = lpObject;
1179  reobject.pstg = lpStorage;
1180  reobject.polesite = lpClientSite;
1181  /* convert from twips to .01 mm */
1182  reobject.sizel.cx = MulDiv(sz->cx, 254, 144);
1183  reobject.sizel.cy = MulDiv(sz->cy, 254, 144);
1184  reobject.dvaspect = DVASPECT_CONTENT;
1185  reobject.dwFlags = 0; /* FIXME */
1186  reobject.dwUser = 0;
1187 
1188  ME_InsertOLEFromCursor(editor, &reobject, 0);
1189  hr = S_OK;
1190  }
1191 
1192  if (lpObject) IOleObject_Release(lpObject);
1193  if (lpClientSite) IOleClientSite_Release(lpClientSite);
1194  if (lpStorage) IStorage_Release(lpStorage);
1195  if (lpDataObject) IDataObject_Release(lpDataObject);
1196  if (lpOleCache) IOleCache_Release(lpOleCache);
1197  if (lpReOle) IRichEditOle_Release(lpReOle);
1198 
1199  return hr;
1200 }
interface IStorage * LPSTORAGE
Definition: objfwd.h:30
IUnknown * reOle
Definition: editstr.h:388
#define TRUE
Definition: types.h:120
#define CF_ENHMETAFILE
Definition: constants.h:409
HRESULT hr
Definition: shlfolder.c:183
RECO_DRAG struct _reobject REOBJECT
const GUID IID_IDataObject
#define E_FAIL
Definition: ddrawi.h:102
#define CF_BITMAP
Definition: constants.h:397
smooth NULL
Definition: ftsmooth.c:416
LONG cx
Definition: windef.h:334
const GUID IID_IOleObject
HBITMAP hbmp
#define CLSID_NULL
Definition: guiddef.h:99
LONG HRESULT
Definition: typedefs.h:77
LRESULT CreateIRichEditOle(IUnknown *outer_unk, ME_TextEditor *editor, LPVOID *ppvObj) DECLSPEC_HIDDEN
Definition: richole.c:5688
unsigned long DWORD
Definition: ntddk_ex.h:95
REFCLSID clsid
Definition: msctf.c:82
interface IDataObject * LPDATAOBJECT
Definition: objfwd.h:21
#define S_OK
Definition: intsafe.h:59
void ME_InsertOLEFromCursor(ME_TextEditor *editor, const REOBJECT *reo, int nCursor)
Definition: caret.c:501
HRESULT WINAPI OleCreateDefaultHandler(REFCLSID clsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj)
LONG cy
Definition: windef.h:335
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
const GUID IID_IOleCache

Referenced by ME_RTFReadPictGroup(), and paste_emf().

◆ is_link()

static BOOL is_link ( ME_Run run)
static

Definition at line 2888 of file editor.c.

2889 {
2890  return (run->style->fmt.dwMask & CFM_LINK) && (run->style->fmt.dwEffects & CFE_LINK);
2891 }
#define CFE_LINK
Definition: richedit.h:411
ME_Style * style
Definition: editstr.h:164
DWORD dwEffects
Definition: richedit.h:307
#define CFM_LINK
Definition: richedit.h:337
DWORD dwMask
Definition: richedit.h:306
CHARFORMAT2W fmt
Definition: editstr.h:77

Referenced by ME_LinkNotify(), and ME_SetCursor().

◆ is_version_nt()

static BOOL is_version_nt ( void  )
inlinestatic

Definition at line 262 of file editor.c.

263 {
264  return !(GetVersion() & 0x80000000);
265 }
DWORD WINAPI GetVersion(VOID)
Definition: version.c:22

Referenced by ME_RegisterEditorClass().

◆ isurlneutral()

static BOOL isurlneutral ( WCHAR  c)
static

Definition at line 5310 of file editor.c.

5311 {
5312  /* NB this list is sorted */
5313  static const WCHAR neutral_chars[] = {'!','\"','\'','(',')',',','-','.',':',';','<','>','?','[',']','{','}'};
5314 
5315  /* Some shortcuts */
5316  if (isalnum( c )) return FALSE;
5317  if (c > neutral_chars[ARRAY_SIZE( neutral_chars ) - 1]) return FALSE;
5318 
5319  return !!bsearch( &c, neutral_chars, ARRAY_SIZE( neutral_chars ), sizeof(c), wchar_comp );
5320 }
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
__wchar_t WCHAR
Definition: xmlstorage.h:180
const GLubyte * c
Definition: glext.h:8905
static int __cdecl wchar_comp(const void *key, const void *elem)
Definition: editor.c:5303
#define ARRAY_SIZE(a)
Definition: main.h:24
#define bsearch

Referenced by ME_FindNextURLCandidate().

◆ ME_ApplyBorderProperties()

static void ME_ApplyBorderProperties ( RTF_Info info,
ME_BorderRect borderRect,
RTFBorder borderDef 
)
static

Definition at line 395 of file editor.c.

398 {
399  int i, colorNum;
400  ME_Border *pBorders[] = {&borderRect->top,
401  &borderRect->left,
402  &borderRect->bottom,
403  &borderRect->right};
404  for (i = 0; i < 4; i++)
405  {
406  RTFColor *colorDef = info->colorList;
407  pBorders[i]->width = borderDef[i].width;
408  colorNum = borderDef[i].color;
409  while (colorDef && colorDef->rtfCNum != colorNum)
410  colorDef = colorDef->rtfNextColor;
411  if (colorDef)
412  pBorders[i]->colorRef = RGB(
413  colorDef->rtfCRed >= 0 ? colorDef->rtfCRed : 0,
414  colorDef->rtfCGreen >= 0 ? colorDef->rtfCGreen : 0,
415  colorDef->rtfCBlue >= 0 ? colorDef->rtfCBlue : 0);
416  else
417  pBorders[i]->colorRef = RGB(0, 0, 0);
418  }
419 }
Definition: rtf.h:978
ME_Border top
Definition: editstr.h:192
int width
Definition: rtf.h:1014
int rtfCRed
Definition: rtf.h:981
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
int rtfCGreen
Definition: rtf.h:982
int color
Definition: rtf.h:1015
int rtfCBlue
Definition: rtf.h:983
#define RGB(r, g, b)
Definition: wingdi.h:2939
COLORREF colorRef
Definition: editstr.h:187
ME_Border right
Definition: editstr.h:195
ME_Border bottom
Definition: editstr.h:194
int rtfCNum
Definition: rtf.h:980
ME_Border left
Definition: editstr.h:193
RTFColor * rtfNextColor
Definition: rtf.h:984

Referenced by ME_RTFSpecialCharHook().

◆ ME_CalculateClickCount()

static int ME_CalculateClickCount ( ME_TextEditor editor,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 2838 of file editor.c.

2840 {
2841  static int clickNum = 0;
2842  if (msg < WM_MOUSEFIRST || msg > WM_MOUSELAST)
2843  return 0;
2844 
2845  if ((msg == WM_LBUTTONDBLCLK) ||
2846  (msg == WM_RBUTTONDBLCLK) ||
2847  (msg == WM_MBUTTONDBLCLK) ||
2848  (msg == WM_XBUTTONDBLCLK))
2849  {
2851  }
2852 
2853  if ((msg == WM_LBUTTONDOWN) ||
2854  (msg == WM_RBUTTONDOWN) ||
2855  (msg == WM_MBUTTONDOWN) ||
2856  (msg == WM_XBUTTONDOWN))
2857  {
2858  static MSG prevClickMsg;
2859  MSG clickMsg;
2860  /* Compare the editor instead of the hwnd so that the this
2861  * can still be done for windowless richedit controls. */
2862  clickMsg.hwnd = (HWND)editor;
2863  clickMsg.message = msg;
2864  clickMsg.wParam = wParam;
2865  clickMsg.lParam = lParam;
2866  clickMsg.time = GetMessageTime();
2867  clickMsg.pt.x = (short)LOWORD(lParam);
2868  clickMsg.pt.y = (short)HIWORD(lParam);
2869  if ((clickNum != 0) &&
2870  (clickMsg.message == prevClickMsg.message) &&
2871  (clickMsg.hwnd == prevClickMsg.hwnd) &&
2872  (clickMsg.wParam == prevClickMsg.wParam) &&
2873  (clickMsg.time - prevClickMsg.time < GetDoubleClickTime()) &&
2874  (abs(clickMsg.pt.x - prevClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2875  (abs(clickMsg.pt.y - prevClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2876  {
2877  clickNum++;
2878  } else {
2879  clickNum = 1;
2880  }
2881  prevClickMsg = clickMsg;
2882  } else {
2883  return 0;
2884  }
2885  return clickNum;
2886 }
#define abs(i)
Definition: fconv.c:206
#define SM_CYDOUBLECLK
Definition: winuser.h:990
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
HANDLE HWND
Definition: compat.h:13
LONG WINAPI GetMessageTime(void)
Definition: message.c:1360
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
static UINT WPARAM wParam
Definition: editor.c:2867
#define WM_MOUSELAST
Definition: winuser.h:1783
int WINAPI GetSystemMetrics(_In_ int)
#define WM_LBUTTONDBLCLK
Definition: winuser.h:1760
#define WM_MBUTTONDBLCLK
Definition: winuser.h:1766
static UINT WPARAM LPARAM lParam
Definition: editor.c:2867
#define WM_MBUTTONDOWN
Definition: winuser.h:1764
#define msg(x)
Definition: auth_time.c:54
UINT WINAPI GetDoubleClickTime(void)
Definition: ntwrapper.h:314
#define WM_RBUTTONDBLCLK
Definition: winuser.h:1763
#define HIWORD(l)
Definition: typedefs.h:246
#define LOWORD(l)
Definition: pedump.c:82
#define SM_CXDOUBLECLK
Definition: winuser.h:989

Referenced by ME_HandleMessage().

◆ ME_Char()

static LRESULT ME_Char ( ME_TextEditor editor,
WPARAM  charCode,
LPARAM  flags,
BOOL  unicode 
)
static

Definition at line 2741 of file editor.c.

2743 {
2744  WCHAR wstr;
2745 
2746  if (editor->bMouseCaptured)
2747  return 0;
2748 
2749  if (editor->styleFlags & ES_READONLY)
2750  {
2752  return 0; /* FIXME really 0 ? */
2753  }
2754 
2755  if (unicode)
2756  wstr = (WCHAR)charCode;
2757  else
2758  {
2759  CHAR charA = charCode;
2760  MultiByteToWideChar(CP_ACP, 0, &charA, 1, &wstr, 1);
2761  }
2762 
2763  if (editor->bEmulateVersion10 && wstr == '\r')
2764  handle_enter(editor);
2765 
2766  if ((unsigned)wstr >= ' ' || wstr == '\t')
2767  {
2768  ME_Cursor cursor = editor->pCursors[0];
2769  ME_DisplayItem *para = cursor.pPara;
2770  int from, to;
2771  BOOL ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
2772  ME_GetSelectionOfs(editor, &from, &to);
2773  if (wstr == '\t' &&
2774  /* v4.1 allows tabs to be inserted with ctrl key down */
2775  !(ctrl_is_down && !editor->bEmulateVersion10))
2776  {
2777  ME_DisplayItem *para;
2778  BOOL bSelectedRow = FALSE;
2779 
2780  para = cursor.pPara;
2781  if (ME_IsSelection(editor) &&
2782  cursor.pRun->member.run.nCharOfs + cursor.nOffset == 0 &&
2783  to == ME_GetCursorOfs(&editor->pCursors[0]) &&
2784  para->member.para.prev_para->type == diParagraph)
2785  {
2786  para = para->member.para.prev_para;
2787  bSelectedRow = TRUE;
2788  }
2789  if (ME_IsInTable(para))
2790  {
2791  ME_TabPressedInTable(editor, bSelectedRow);
2792  ME_CommitUndo(editor);
2793  return 0;
2794  }
2795  } else if (!editor->bEmulateVersion10) { /* v4.1 */
2796  if (para->member.para.nFlags & MEPF_ROWEND) {
2797  if (from == to) {
2798  para = para->member.para.next_para;
2799  if (para->member.para.nFlags & MEPF_ROWSTART)
2800  para = para->member.para.next_para;
2801  editor->pCursors[0].pPara = para;
2802  editor->pCursors[0].pRun = ME_FindItemFwd(para, diRun);
2803  editor->pCursors[0].nOffset = 0;
2804  editor->pCursors[1] = editor->pCursors[0];
2805  }
2806  }
2807  } else { /* v1.0 - 3.0 */
2808  if (ME_IsInTable(cursor.pRun) &&
2809  cursor.pRun->member.run.nFlags & MERF_ENDPARA &&
2810  from == to)
2811  {
2812  /* Text should not be inserted at the end of the table. */
2813  MessageBeep(-1);
2814  return 0;
2815  }
2816  }
2817  /* FIXME maybe it would make sense to call EM_REPLACESEL instead ? */
2818  /* WM_CHAR is restricted to nTextLimit */
2819  if(editor->nTextLimit > ME_GetTextLength(editor) - (to-from))
2820  {
2821  ME_Style *style = ME_GetInsertStyle(editor, 0);
2823  ME_InsertTextFromCursor(editor, 0, &wstr, 1, style);
2825  ME_CommitCoalescingUndo(editor);
2827  }
2828 
2830  ME_UpdateRepaint(editor, FALSE);
2831  }
2832  return 0;
2833 }
#define MEPF_ROWEND
Definition: editstr.h:149
ME_Paragraph para
Definition: editstr.h:266
#define TRUE
Definition: types.h:120
ME_Style * ME_GetInsertStyle(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN
Definition: style.c:476
DWORD styleFlags
Definition: editstr.h:392
static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
Definition: editor.c:2406
#define CP_ACP
Definition: compat.h:99
char CHAR
Definition: xmlstorage.h:175
void ME_CommitCoalescingUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:301
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style)
Definition: caret.c:550
BOOL bMouseCaptured
Definition: editstr.h:447
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
struct tagME_DisplayItem * prev_para
Definition: editstr.h:221
#define ES_READONLY
Definition: pedump.c:675
void ME_ContinueCoalescingTransaction(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:265
void ME_UpdateRepaint(ME_TextEditor *editor, BOOL update_now) DECLSPEC_HIDDEN
Definition: paint.c:116
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MERF_ENDPARA
Definition: editstr.h:126
smooth NULL
Definition: ftsmooth.c:416
Definition: editstr.h:91
SHORT WINAPI GetKeyState(_In_ int)
static BOOL handle_enter(ME_TextEditor *editor)
Definition: editor.c:2434
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ITextHost_TxSetCursor(This, a, b)
Definition: editor.h:303
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:462
ME_DisplayItem * pPara
Definition: editstr.h:279
BOOL ME_IsInTable(ME_DisplayItem *pItem) DECLSPEC_HIDDEN
Definition: table.c:273
void ME_TabPressedInTable(ME_TextEditor *editor, BOOL bSelectedRow) DECLSPEC_HIDDEN
Definition: table.c:562
#define MEPF_ROWSTART
Definition: editstr.h:148
ITextHost * texthost
Definition: editstr.h:387
int nOffset
Definition: editstr.h:281
#define MB_ICONERROR
Definition: winuser.h:781
void ME_CommitUndo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:227
int ME_GetCursorOfs(const ME_Cursor *cursor)
Definition: caret.c:912
BOOL WINAPI MessageBeep(_In_ UINT)
const char cursor[]
Definition: icontest.c:13
BOOL bEmulateVersion10
Definition: editstr.h:389
ME_Cursor * pCursors
Definition: editstr.h:391
struct tagME_DisplayItem * next_para
Definition: editstr.h:221
ME_DisplayItem * pRun
Definition: editstr.h:280
#define MultiByteToWideChar
Definition: compat.h:100
BOOL ME_IsSelection(ME_TextEditor *editor)
Definition: caret.c:1533
#define VK_CONTROL
Definition: winuser.h:2178
ME_DisplayItem * ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:134
CardRegion * from
Definition: spigame.cpp:19
Arabic default style
Definition: afstyles.h:93
int ME_GetTextLength(ME_TextEditor *editor)
Definition: caret.c:83
union tagME_DisplayItem::@521 member

Referenced by ME_HandleMessage().

◆ ME_Copy()

static BOOL ME_Copy ( ME_TextEditor editor,
const ME_Cursor start,
int  nChars 
)
static

Definition at line 2336 of file editor.c.

2337 {
2338  LPDATAOBJECT dataObj = NULL;
2339  HRESULT hr = S_OK;
2340 
2341  if (editor->cPasswordMask)
2342  return FALSE; /* Copying or Cutting masked text isn't allowed */
2343 
2344  if(editor->lpOleCallback)
2345  {
2346  CHARRANGE range;
2347  range.cpMin = ME_GetCursorOfs(start);
2348  range.cpMax = range.cpMin + nChars;
2349  hr = IRichEditOleCallback_GetClipboardData(editor->lpOleCallback, &range, RECO_COPY, &dataObj);
2350  }
2351  if(FAILED(hr) || !dataObj)
2352  hr = ME_GetDataObject(editor, start, nChars, &dataObj);
2353  if(SUCCEEDED(hr)) {
2354  hr = OleSetClipboard(dataObj);
2355  IDataObject_Release(dataObj);
2356  }
2357  return SUCCEEDED(hr);
2358 }
HRESULT WINAPI OleSetClipboard(IDataObject *data)
Definition: clipboard.c:2199
HRESULT hr
Definition: shlfolder.c:183
HRESULT ME_GetDataObject(ME_TextEditor *editor, const ME_Cursor *start, int nChars, IDataObject **dataobj)
Definition: clipboard.c:405
smooth NULL
Definition: ftsmooth.c:416
LONG HRESULT
Definition: typedefs.h:77
interface IDataObject * LPDATAOBJECT
Definition: objfwd.h:21
LPRICHEDITOLECALLBACK lpOleCallback
Definition: editstr.h:422
GLenum GLint * range
Definition: glext.h:7539
int ME_GetCursorOfs(const ME_Cursor *cursor)
Definition: caret.c:912
#define S_OK
Definition: intsafe.h:59
GLuint start
Definition: gl.h:1545
WCHAR cPasswordMask
Definition: editstr.h:430
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by copy_or_cut().

◆ ME_DestroyEditor()

void ME_DestroyEditor ( ME_TextEditor editor)

Definition at line 3190 of file editor.c.

3191 {
3192  ME_DisplayItem *p = editor->pBuffer->pFirst, *pNext = NULL;
3193  ME_Style *s, *cursor2;
3194  int i;
3195 
3196  ME_ClearTempStyle(editor);
3197  ME_EmptyUndoStack(editor);
3198  editor->pBuffer->pFirst = NULL;
3199  while(p) {
3200  pNext = p->next;
3201  if (p->type == diParagraph)
3202  destroy_para(editor, p);
3203  else
3205  p = pNext;
3206  }
3207 
3208  LIST_FOR_EACH_ENTRY_SAFE( s, cursor2, &editor->style_list, ME_Style, entry )
3209  ME_DestroyStyle( s );
3210 
3212  for (i=0; i<HFONT_CACHE_SIZE; i++)
3213  {
3214  if (editor->pFontCache[i].hFont)
3215  DeleteObject(editor->pFontCache[i].hFont);
3216  }
3217  if (editor->rgbBackColor != -1)
3218  DeleteObject(editor->hbrBackground);
3219  if(editor->lpOleCallback)
3220  IRichEditOleCallback_Release(editor->lpOleCallback);
3221  ITextHost_Release(editor->texthost);
3222  if (editor->reOle)
3223  {
3224  IUnknown_Release(editor->reOle);
3225  editor->reOle = NULL;
3226  }
3227  OleUninitialize();
3228 
3229  heap_free(editor->pBuffer);
3230  heap_free(editor->pCursors);
3231  heap_free(editor);
3232 }
struct list style_list
Definition: editstr.h:449
IUnknown * reOle
Definition: editstr.h:388
void ME_DestroyStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:442
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: style.c:523
ME_DisplayItem * pFirst
Definition: editstr.h:272
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HBRUSH hbrBackground
Definition: editstr.h:402
void ME_DestroyDisplayItem(ME_DisplayItem *item) DECLSPEC_HIDDEN
Definition: list.c:160
ME_TextBuffer * pBuffer
Definition: editstr.h:390
smooth NULL
Definition: ftsmooth.c:416
void destroy_para(ME_TextEditor *editor, ME_DisplayItem *item) DECLSPEC_HIDDEN
Definition: para.c:48
ME_FontCacheItem pFontCache[HFONT_CACHE_SIZE]
Definition: editstr.h:414
ME_Style * pDefaultStyle
Definition: editstr.h:274
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:462
ITextHost * texthost
Definition: editstr.h:387
COLORREF rgbBackColor
Definition: editstr.h:401
uint32_t entry
Definition: isohybrid.c:63
GLdouble s
Definition: gl.h:2039
LPRICHEDITOLECALLBACK lpOleCallback
Definition: editstr.h:422
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
ME_Cursor * pCursors
Definition: editstr.h:391
#define HFONT_CACHE_SIZE
Definition: editstr.h:73
GLfloat GLfloat p
Definition: glext.h:8902
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
Definition: ole2.c:230
void ME_EmptyUndoStack(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:53
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ITextServicesImpl_Release(), and ME_HandleMessage().

◆ ME_FilterEvent()

static BOOL ME_FilterEvent ( ME_TextEditor editor,
UINT  msg,
WPARAM wParam,
LPARAM lParam 
)
static

Definition at line 2386 of file editor.c.

2387 {
2388  MSGFILTER msgf;
2389 
2390  if (!editor->hWnd || !editor->hwndParent) return FALSE;
2391  msgf.nmhdr.hwndFrom = editor->hWnd;
2392  msgf.nmhdr.idFrom = GetWindowLongW(editor->hWnd, GWLP_ID);
2393  msgf.nmhdr.code = EN_MSGFILTER;
2394  msgf.msg = msg;
2395  msgf.wParam = *wParam;
2396  msgf.lParam = *lParam;
2397  if (SendMessageW(editor->hwndParent, WM_NOTIFY, msgf.nmhdr.idFrom, (LPARAM)&msgf))
2398  return FALSE;
2399  *wParam = msgf.wParam;
2400  *lParam = msgf.lParam;
2401  msgf.wParam = *wParam;
2402 
2403  return TRUE;
2404 }
#define TRUE
Definition: types.h:120
WPARAM wParam
Definition: richedit.h:642
LPARAM lParam
Definition: richedit.h:643
UINT code
Definition: winuser.h:3134
UINT_PTR idFrom
Definition: winuser.h:3133
LONG WINAPI GetWindowLongW(_In_ HWND, _In_ int)
LONG_PTR LPARAM
Definition: windef.h:208
#define EN_MSGFILTER
Definition: richedit.h:191
static UINT WPARAM wParam
Definition: editor.c:2867
HWND hwndFrom
Definition: winuser.h:3132
UINT msg
Definition: richedit.h:641
static UINT WPARAM LPARAM lParam
Definition: editor.c:2867
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define msg(x)
Definition: auth_time.c:54
#define GWLP_ID
Definition: winuser.h:854
#define WM_NOTIFY
Definition: richedit.h:61
NMHDR nmhdr
Definition: richedit.h:640

Referenced by ME_HandleMessage().

◆ ME_FindNextURLCandidate()

static BOOL ME_FindNextURLCandidate ( ME_TextEditor editor,
const ME_Cursor start,
int  nChars,
ME_Cursor candidate_min,
ME_Cursor candidate_max 
)
static

This proc takes a selection, and scans it forward in order to select the span of a possible URL candidate. A possible URL candidate must start with isalnum or one of the following special characters: *|/+%#@ and must consist entirely of the characters allowed to start the URL, plus : (colon) which may occur at most once, and not at either end.

Definition at line 5329 of file editor.c.

5334 {
5335  ME_Cursor cursor = *start, neutral_end, space_end;
5336  BOOL candidateStarted = FALSE, quoted = FALSE;
5337  WCHAR c;
5338 
5339  while (nChars > 0)
5340  {
5341  WCHAR *str = get_text( &cursor.pRun->member.run, 0 );
5342  int run_len = cursor.pRun->member.run.len;
5343 
5344  nChars -= run_len - cursor.nOffset;
5345 
5346  /* Find start of candidate */
5347  if (!candidateStarted)
5348  {
5349  while (cursor.nOffset < run_len)
5350  {
5351  c = str[cursor.nOffset];
5352  if (!iswspace( c ) && !isurlneutral( c ))
5353  {
5354  *candidate_min = cursor;
5355  candidateStarted = TRUE;
5356  neutral_end.pPara = NULL;
5357  space_end.pPara = NULL;
5358  cursor.nOffset++;
5359  break;
5360  }
5361  quoted = (c == '<');
5362  cursor.nOffset++;
5363  }
5364  }
5365 
5366  /* Find end of candidate */
5367  if (candidateStarted)
5368  {
5369  while (cursor.nOffset < run_len)
5370  {
5371  c = str[cursor.nOffset];
5372  if (iswspace( c ))
5373  {
5374  if (quoted && c != '\r')
5375  {
5376  if (!space_end.pPara)
5377  {
5378  if (neutral_end.pPara)
5379  space_end = neutral_end;
5380  else
5381  space_end = cursor;
5382  }
5383  }
5384  else
5385  goto done;
5386  }
5387  else if (isurlneutral( c ))
5388  {
5389  if (quoted && c == '>')
5390  {
5391  neutral_end.pPara = NULL;
5392  space_end.pPara = NULL;
5393  goto done;
5394  }
5395  if (!neutral_end.pPara)
5396  neutral_end = cursor;
5397  }
5398  else
5399  neutral_end.pPara = NULL;
5400 
5401  cursor.nOffset++;
5402  }
5403  }
5404 
5405  cursor.nOffset = 0;
5406  if (!ME_NextRun(&cursor.pPara, &cursor.pRun, TRUE))
5407  goto done;
5408  }
5409 
5410 done:
5411  if (candidateStarted)
5412  {
5413  if (space_end.pPara)
5414  *candidate_max = space_end;
5415  else if (neutral_end.pPara)
5416  *candidate_max = neutral_end;
5417  else
5418  *candidate_max = cursor;
5419  return TRUE;
5420  }
5421  *candidate_max = *candidate_min = cursor;
5422  return FALSE;
5423 }
#define TRUE
Definition: types.h:120
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN
Definition: list.c:71
static BOOL isurlneutral(WCHAR c)
Definition: editor.c:5310
unsigned int BOOL
Definition: ntddk_ex.h:94
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
const GLubyte * c
Definition: glext.h:8905
#define iswspace(_c)
Definition: ctype.h:669
static WCHAR * get_text(const ME_Run *run, int offset)
Definition: editor.h:41
const char cursor[]
Definition: icontest.c:13
GLuint start
Definition: gl.h:1545
#define c
Definition: ke_i.h:80

Referenced by ME_UpdateLinkAttribute().

◆ ME_FindText()

static int ME_FindText ( ME_TextEditor editor,
DWORD  flags,
const CHARRANGE chrg,
const WCHAR text,
CHARRANGE chrgText 
)
static

Definition at line 1852 of file editor.c.

1853 {
1854  const int nLen = lstrlenW(text);
1855  const int nTextLen = ME_GetTextLength(editor);
1856  int nMin, nMax;
1857  ME_Cursor cursor;
1858  WCHAR wLastChar = ' ';
1859 
1860  TRACE("flags==0x%08x, chrg->cpMin==%d, chrg->cpMax==%d text==%s\n",
1861  flags, chrg->cpMin, chrg->cpMax, debugstr_w(text));
1862 
1863  if (flags & ~(FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD))
1864  FIXME("Flags 0x%08x not implemented\n",
1866 
1867  nMin = chrg->cpMin;
1868  if (chrg->cpMax == -1)
1869  nMax = nTextLen;
1870  else
1871  nMax = chrg->cpMax > nTextLen ? nTextLen : chrg->cpMax;
1872 
1873  /* In 1.0 emulation, if cpMax reaches end of text, add the FR_DOWN flag */
1874  if (editor->bEmulateVersion10 && nMax == nTextLen)
1875  {
1876  flags |= FR_DOWN;
1877  }
1878 
1879  /* In 1.0 emulation, cpMin must always be no greater than cpMax */
1880  if (editor->bEmulateVersion10 && nMax < nMin)
1881  {
1882  if (chrgText)
1883  {
1884  chrgText->cpMin = -1;
1885  chrgText->cpMax = -1;
1886  }
1887  return -1;
1888  }
1889 
1890  /* when searching up, if cpMin < cpMax, then instead of searching
1891  * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
1892  * [cpMax, cpMin]. The exception is when cpMax is -1, in which
1893  * case, it is always bigger than cpMin.
1894  */
1895  if (!editor->bEmulateVersion10 && !(flags & FR_DOWN))
1896  {
1897  int nSwap = nMax;
1898 
1899  nMax = nMin > nTextLen ? nTextLen : nMin;
1900  if (nMin < nSwap || chrg->cpMax == -1)
1901  nMin = 0;
1902  else
1903  nMin = nSwap;
1904  }
1905 
1906  if (!nLen || nMin < 0 || nMax < 0 || nMax < nMin)
1907  {
1908  if (chrgText)
1909  chrgText->cpMin = chrgText->cpMax = -1;
1910  return -1;
1911  }
1912 
1913  if (flags & FR_DOWN) /* Forward search */
1914  {
1915  /* If possible, find the character before where the search starts */
1916  if ((flags & FR_WHOLEWORD) && nMin)
1917  {
1918  ME_CursorFromCharOfs(editor, nMin - 1, &cursor);
1919  wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
1920  ME_MoveCursorChars(editor, &cursor, 1, FALSE);
1921  } else {
1922  ME_CursorFromCharOfs(editor, nMin, &cursor);
1923  }
1924 
1925  while (cursor.pRun && ME_GetCursorOfs(&cursor) + nLen <= nMax)
1926  {
1927  ME_DisplayItem *pCurItem = cursor.pRun;
1928  int nCurStart = cursor.nOffset;
1929  int nMatched = 0;
1930 
1931  while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurStart + nMatched ), text[nMatched], (flags & FR_MATCHCASE)))
1932  {
1933  if ((flags & FR_WHOLEWORD) && iswalnum(wLastChar))
1934  break;
1935 
1936  nMatched++;
1937  if (nMatched == nLen)
1938  {
1939  ME_DisplayItem *pNextItem = pCurItem;
1940  int nNextStart = nCurStart;
1941  WCHAR wNextChar;
1942 
1943  /* Check to see if next character is a whitespace */
1944  if (flags & FR_WHOLEWORD)
1945  {
1946  if (nCurStart + nMatched == pCurItem->member.run.len)
1947  {
1948  pNextItem = ME_FindItemFwd(pCurItem, diRun);
1949  nNextStart = -nMatched;
1950  }
1951 
1952  if (pNextItem)
1953  wNextChar = *get_text( &pNextItem->member.run, nNextStart + nMatched );
1954  else
1955  wNextChar = ' ';
1956 
1957  if (iswalnum(wNextChar))
1958  break;
1959  }
1960 
1961  cursor.nOffset += cursor.pPara->member.para.nCharOfs + cursor.pRun->member.run.nCharOfs;
1962  if (chrgText)
1963  {
1964  chrgText->cpMin = cursor.nOffset;
1965  chrgText->cpMax = cursor.nOffset + nLen;
1966  }
1967  TRACE("found at %d-%d\n", cursor.nOffset, cursor.nOffset + nLen);
1968  return cursor.nOffset;
1969  }
1970  if (nCurStart + nMatched == pCurItem->member.run.len)
1971  {
1972  pCurItem = ME_FindItemFwd(pCurItem, diRun);
1973  nCurStart = -nMatched;
1974  }
1975  }
1976  if (pCurItem)
1977  wLastChar = *get_text( &pCurItem->member.run, nCurStart + nMatched );
1978  else
1979  wLastChar = ' ';
1980 
1981  cursor.nOffset++;
1982  if (cursor.nOffset == cursor.pRun->member.run.len)
1983  {
1984  ME_NextRun(&cursor.pPara, &cursor.pRun, TRUE);
1985  cursor.nOffset = 0;
1986  }
1987  }
1988  }
1989  else /* Backward search */
1990  {
1991  /* If possible, find the character after where the search ends */
1992  if ((flags & FR_WHOLEWORD) && nMax < nTextLen - 1)
1993  {
1994  ME_CursorFromCharOfs(editor, nMax + 1, &cursor);
1995  wLastChar = *get_text( &cursor.pRun->member.run, cursor.nOffset );
1996  ME_MoveCursorChars(editor, &cursor, -1, FALSE);
1997  } else {
1998  ME_CursorFromCharOfs(editor, nMax, &cursor);
1999  }
2000 
2001  while (cursor.pRun && ME_GetCursorOfs(&cursor) - nLen >= nMin)
2002  {
2003  ME_DisplayItem *pCurItem = cursor.pRun;
2004  ME_DisplayItem *pCurPara = cursor.pPara;
2005  int nCurEnd = cursor.nOffset;
2006  int nMatched = 0;
2007 
2008  if (nCurEnd == 0)
2009  {
2010  ME_PrevRun(&pCurPara, &pCurItem, TRUE);
2011  nCurEnd = pCurItem->member.run.len;
2012  }
2013 
2014  while (pCurItem && ME_CharCompare( *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 ),
2015  text[nLen - nMatched - 1], (flags & FR_MATCHCASE) ))
2016  {
2017  if ((flags & FR_WHOLEWORD) && iswalnum(wLastChar))
2018  break;
2019 
2020  nMatched++;
2021  if (nMatched == nLen)
2022  {
2023  ME_DisplayItem *pPrevItem = pCurItem;
2024  int nPrevEnd = nCurEnd;
2025  WCHAR wPrevChar;
2026  int nStart;
2027 
2028  /* Check to see if previous character is a whitespace */
2029  if (flags & FR_WHOLEWORD)
2030  {
2031  if (nPrevEnd - nMatched == 0)
2032  {
2033  pPrevItem = ME_FindItemBack(pCurItem, diRun);
2034  if (pPrevItem)
2035  nPrevEnd = pPrevItem->member.run.len + nMatched;
2036  }
2037 
2038  if (pPrevItem)
2039  wPrevChar = *get_text( &pPrevItem->member.run, nPrevEnd - nMatched - 1 );
2040  else
2041  wPrevChar = ' ';
2042 
2043  if (iswalnum(wPrevChar))
2044  break;
2045  }
2046 
2047  nStart = pCurPara->member.para.nCharOfs
2048  + pCurItem->member.run.nCharOfs + nCurEnd - nMatched;
2049  if (chrgText)
2050  {
2051  chrgText->cpMin = nStart;
2052  chrgText->cpMax = nStart + nLen;
2053  }
2054  TRACE("found at %d-%d\n", nStart, nStart + nLen);
2055  return nStart;
2056  }
2057  if (nCurEnd - nMatched == 0)
2058  {
2059  ME_PrevRun(&pCurPara, &pCurItem, TRUE);
2060  /* Don't care about pCurItem becoming NULL here; it's already taken
2061  * care of in the exterior loop condition */
2062  nCurEnd = pCurItem->member.run.len + nMatched;
2063  }
2064  }
2065  if (pCurItem)
2066  wLastChar = *get_text( &pCurItem->member.run, nCurEnd - nMatched - 1 );
2067  else
2068  wLastChar = ' ';
2069 
2070  cursor.nOffset--;
2071  if (cursor.nOffset < 0)
2072  {
2073  ME_PrevRun(&cursor.pPara, &cursor.pRun, TRUE);
2074  cursor.nOffset = cursor.pRun->member.run.len;
2075  }
2076  }
2077  }
2078  TRACE("not found\n");
2079  if (chrgText)
2080  chrgText->cpMin = chrgText->cpMax = -1;
2081  return -1;
2082 }
ME_Paragraph para
Definition: editstr.h:266
#define TRUE
Definition: types.h:120
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) DECLSPEC_HIDDEN
Definition: run.c:171
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN
Definition: list.c:71
const WCHAR * text
Definition: package.c:1827
LONG cpMax
Definition: richedit.h:501
int nCharOfs
Definition: editstr.h:166
#define lstrlenW
Definition: compat.h:415
static int ME_CharCompare(WCHAR a, WCHAR b, int caseSensitive)
Definition: editor.h:106
#define iswalnum(_c)
Definition: ctype.h:671
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
Definition: editstr.h:91
int len
Definition: editstr.h:167
BOOL ME_PrevRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN
Definition: list.c:93
#define FR_MATCHCASE
Definition: commdlg.h:136
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLbitfield flags
Definition: glext.h:7161
static WCHAR * get_text(const ME_Run *run, int offset)
Definition: editor.h:41
int ME_GetCursorOfs(const ME_Cursor *cursor)
Definition: caret.c:912
#define FR_WHOLEWORD
Definition: commdlg.h:145
const char cursor[]
Definition: icontest.c:13
BOOL bEmulateVersion10
Definition: editstr.h:389
int ME_MoveCursorChars(ME_TextEditor *editor, ME_Cursor *cursor, int nRelOfs, BOOL final_eop)
Definition: caret.c:675
#define FR_DOWN
Definition: commdlg.h:127
ME_DisplayItem * ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:134
LONG cpMin
Definition: richedit.h:500
int ME_GetTextLength(ME_TextEditor *editor)
Definition: caret.c:83
ME_DisplayItem * ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:111
union tagME_DisplayItem::@521 member

Referenced by ME_HandleMessage().

◆ ME_GetSelectionType()

static LONG ME_GetSelectionType ( ME_TextEditor editor)
static

Definition at line 2993 of file editor.c.

2994 {
2995  LONG sel_type = SEL_EMPTY;
2996  LONG start, end;
2997 
2998  ME_GetSelectionOfs(editor, &start, &end);
2999  if (start == end)
3000  sel_type = SEL_EMPTY;
3001  else
3002  {
3003  LONG object_count = 0, character_count = 0;
3004  int i;
3005 
3006  for (i = 0; i < end - start; i++)
3007  {
3008  ME_Cursor cursor;
3009 
3010  ME_CursorFromCharOfs(editor, start + i, &cursor);
3011  if (cursor.pRun->member.run.reobj)
3012  object_count++;
3013  else
3014  character_count++;
3015  if (character_count >= 2 && object_count >= 2)
3017  }
3018  if (character_count)
3019  {
3020  sel_type |= SEL_TEXT;
3021  if (character_count >= 2)
3022  sel_type |= SEL_MULTICHAR;
3023  }
3024  if (object_count)
3025  {
3026  sel_type |= SEL_OBJECT;
3027  if (object_count >= 2)
3028  sel_type |= SEL_MULTIOBJECT;
3029  }
3030  }
3031  return sel_type;
3032 }
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) DECLSPEC_HIDDEN
Definition: run.c:171
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
GLuint GLuint end
Definition: gl.h:1545
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
long LONG
Definition: pedump.c:60
long object_count
Definition: nc_alloc.cpp:37
#define SEL_OBJECT
Definition: richedit.h:824
#define SEL_MULTICHAR
Definition: richedit.h:825
const char cursor[]
Definition: icontest.c:13
GLuint start
Definition: gl.h:1545
#define SEL_EMPTY
Definition: richedit.h:822
#define SEL_MULTIOBJECT
Definition: richedit.h:826
#define SEL_TEXT
Definition: richedit.h:823

Referenced by ME_HandleMessage(), and ME_ShowContextMenu().

◆ ME_GetTextEx()

static int ME_GetTextEx ( ME_TextEditor editor,
GETTEXTEX ex,
LPARAM  pText 
)
static

Definition at line 2084 of file editor.c.

2085 {
2086  int nChars;
2087  ME_Cursor start;
2088 
2089  if (!ex->cb || !pText) return 0;
2090 
2091  if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
2092  FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
2093 
2094  if (ex->flags & GT_SELECTION)
2095  {
2096  int from, to;
2097  int nStartCur = ME_GetSelectionOfs(editor, &from, &to);
2098  start = editor->pCursors[nStartCur];
2099  nChars = to - from;
2100  }
2101  else
2102  {
2103  ME_SetCursorToStart(editor, &start);
2104  nChars = INT_MAX;
2105  }
2106  if (ex->codepage == CP_UNICODE)
2107  {
2108  return ME_GetTextW(editor, (LPWSTR)pText, ex->cb / sizeof(WCHAR) - 1,
2109  &start, nChars, ex->flags & GT_USECRLF, FALSE);
2110  }
2111  else
2112  {
2113  /* potentially each char may be a CR, why calculate the exact value with O(N) when
2114  we can just take a bigger buffer? :)
2115  The above assumption still holds with CR/LF counters, since CR->CRLF expansion
2116  occurs only in richedit 2.0 mode, in which line breaks have only one CR
2117  */
2118  int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
2119  DWORD buflen;
2120  LPWSTR buffer;
2121  LRESULT rc;
2122 
2123  buflen = min(crlfmul * nChars, ex->cb - 1);
2124  buffer = heap_alloc((buflen + 1) * sizeof(WCHAR));
2125 
2126  nChars = ME_GetTextW(editor, buffer, buflen, &start, nChars, ex->flags & GT_USECRLF, FALSE);
2127  rc = WideCharToMultiByte(ex->codepage, 0, buffer, nChars + 1,
2128  (LPSTR)pText, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
2129  if (rc) rc--; /* do not count 0 terminator */
2130 
2131  heap_free(buffer);
2132  return rc;
2133  }
2134 }
Definition: comerr.c:44
LPCSTR pText
Definition: txtscale.cpp:79
#define WideCharToMultiByte
Definition: compat.h:101
#define INT_MAX
Definition: limits.h:40
#define GT_SELECTION
Definition: richedit.h:1038
GLuint buffer
Definition: glext.h:5915
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
char * LPSTR
Definition: xmlstorage.h:182
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen, const ME_Cursor *start, int srcChars, BOOL bCRLF, BOOL bEOP)
Definition: editor.c:5134
#define FIXME(fmt,...)
Definition: debug.h:110
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor)
Definition: caret.c:27
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
ME_Cursor * pCursors
Definition: editstr.h:391
GLuint start
Definition: gl.h:1545
#define min(a, b)
Definition: monoChain.cc:55
#define GT_USECRLF
Definition: richedit.h:1037
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LONG_PTR LRESULT
Definition: windef.h:209
CardRegion * from
Definition: spigame.cpp:19
#define CP_UNICODE
Definition: stg_prop.c:74
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_HandleMessage().

◆ ME_GetTextRange()

static int ME_GetTextRange ( ME_TextEditor editor,
WCHAR strText,
const ME_Cursor start,
int  nLen,
BOOL  unicode 
)
static

Definition at line 2136 of file editor.c.

2138 {
2139  if (!strText) return 0;
2140  if (unicode) {
2141  return ME_GetTextW(editor, strText, INT_MAX, start, nLen, FALSE, FALSE);
2142  } else {
2143  int nChars;
2144  WCHAR *p = heap_alloc((nLen+1) * sizeof(*p));
2145  if (!p) return 0;
2146  nChars = ME_GetTextW(editor, p, nLen, start, nLen, FALSE, FALSE);
2147  WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)strText,
2148  nLen+1, NULL, NULL);
2149  heap_free(p);
2150  return nChars;
2151  }
2152 }
#define WideCharToMultiByte
Definition: compat.h:101
#define INT_MAX
Definition: limits.h:40
#define CP_ACP
Definition: compat.h:99
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int buflen, const ME_Cursor *start, int srcChars, BOOL bCRLF, BOOL bEOP)
Definition: editor.c:5134
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLuint start
Definition: gl.h:1545
GLfloat GLfloat p
Definition: glext.h:8902
static BOOL heap_free(void *mem)
Definition: appwiz.h:75

Referenced by ME_HandleMessage().

◆ ME_GetTextW()

int ME_GetTextW ( ME_TextEditor editor,
WCHAR buffer,
int  buflen,
const ME_Cursor start,
int  srcChars,
BOOL  bCRLF,
BOOL  bEOP 
)

Definition at line 5134 of file editor.c.

5137 {
5138  ME_DisplayItem *pRun, *pNextRun;
5139  const WCHAR *pStart = buffer;
5140  const WCHAR cr_lf[] = {'\r', '\n', 0};
5141  const WCHAR *str;
5142  int nLen;
5143 
5144  /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
5145  if (editor->bEmulateVersion10) bCRLF = FALSE;
5146 
5147  pRun = start->pRun;
5148  assert(pRun);
5149  pNextRun = ME_FindItemFwd(pRun, diRun);
5150 
5151  nLen = pRun->member.run.len - start->nOffset;
5152  str = get_text( &pRun->member.run, start->nOffset );
5153 
5154  while (srcChars && buflen && pNextRun)
5155  {
5156  int nFlags = pRun->member.run.nFlags;
5157 
5158  if (bCRLF && nFlags & MERF_ENDPARA && ~nFlags & MERF_ENDCELL)
5159  {
5160  if (buflen == 1) break;
5161  /* FIXME: native fails to reduce srcChars here for WM_GETTEXT or
5162  * EM_GETTEXTEX, however, this is done for copying text which
5163  * also uses this function. */
5164  srcChars -= min(nLen, srcChars);
5165  nLen = 2;
5166  str = cr_lf;
5167  } else {
5168  nLen = min(nLen, srcChars);
5169  srcChars -= nLen;
5170  }
5171 
5172  nLen = min(nLen, buflen);
5173  buflen -= nLen;
5174 
5175  CopyMemory(buffer, str, sizeof(WCHAR) * nLen);
5176 
5177  buffer += nLen;
5178 
5179  pRun = pNextRun;
5180  pNextRun = ME_FindItemFwd(pRun, diRun);
5181 
5182  nLen = pRun->member.run.len;
5183  str = get_text( &pRun->member.run, 0 );
5184  }
5185  /* append '\r' to the last paragraph. */
5186  if (pRun->next->type == diTextEnd && bEOP)
5187  {
5188  *buffer = '\r';
5189  buffer ++;
5190  }
5191  *buffer = 0;
5192  return buffer - pStart;
5193 }
#define assert(x)
Definition: debug.h:53
GLuint buffer
Definition: glext.h:5915
struct tagME_DisplayItem * next
Definition: editstr.h:261
#define MERF_ENDPARA
Definition: editstr.h:126
const WCHAR * str
Definition: editstr.h:91
int len
Definition: editstr.h:167
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1640
int nFlags
Definition: editstr.h:169
#define MERF_ENDCELL
Definition: editstr.h:113
static WCHAR * get_text(const ME_Run *run, int offset)
Definition: editor.h:41
BOOL bEmulateVersion10
Definition: editstr.h:389
GLuint start
Definition: gl.h:1545
#define min(a, b)
Definition: monoChain.cc:55
static const WCHAR cr_lf[]
Definition: table.c:59
ME_DisplayItem * ME_FindItemFwd(ME_DisplayItem *di, ME_DIType nTypeOrClass) DECLSPEC_HIDDEN
Definition: list.c:134
union tagME_DisplayItem::@521 member

Referenced by fnTextSrv_TxGetText(), get_unicode_text(), ITextRange_fnGetText(), ITextSelection_fnGetText(), ME_GetTextEx(), ME_GetTextRange(), ME_IsCandidateAnURL(), ME_StreamIn(), and range_GetChar().

◆ ME_HandleMessage()

LRESULT ME_HandleMessage ( ME_TextEditor editor,
UINT  msg,
WPARAM  wParam,
LPARAM  lParam,
BOOL  unicode,
HRESULT phresult 
)

Definition at line 3600 of file editor.c.

3602 {
3603  *phresult = S_OK;
3604 
3605  switch(msg) {
3606 
3629 
3630 /* Messages specific to Richedit controls */
3631 
3632  case EM_STREAMIN:
3633  return ME_StreamIn(editor, wParam, (EDITSTREAM*)lParam, TRUE);
3634  case EM_STREAMOUT:
3635  return ME_StreamOut(editor, wParam, (EDITSTREAM *)lParam);
3636  case WM_GETDLGCODE:
3637  {
3639 
3640  if (lParam)
3641  editor->bDialogMode = TRUE;
3642  if (editor->styleFlags & ES_MULTILINE)
3644  if (!(editor->styleFlags & ES_SAVESEL))
3645  code |= DLGC_HASSETSEL;
3646  return code;
3647  }
3648  case EM_EMPTYUNDOBUFFER:
3649  ME_EmptyUndoStack(editor);
3650  return 0;
3651  case EM_GETSEL:
3652  {
3653  /* Note: wParam/lParam can be NULL */
3654  UINT from, to;
3655  PUINT pfrom = wParam ? (PUINT)wParam : &from;
3656  PUINT pto = lParam ? (PUINT)lParam : &to;
3657  ME_GetSelectionOfs(editor, (int *)pfrom, (int *)pto);
3658  if ((*pfrom|*pto) & 0xFFFF0000)
3659  return -1;
3660  return MAKELONG(*pfrom,*pto);
3661  }
3662  case EM_EXGETSEL:
3663  {
3664  CHARRANGE *pRange = (CHARRANGE *)lParam;
3665  ME_GetSelectionOfs(editor, &pRange->cpMin, &pRange->cpMax);
3666  TRACE("EM_EXGETSEL = (%d,%d)\n", pRange->cpMin, pRange->cpMax);
3667  return 0;
3668  }
3669  case EM_SETUNDOLIMIT:
3670  {
3671  if ((int)wParam < 0)
3672  editor->nUndoLimit = STACK_SIZE_DEFAULT;
3673  else
3674  editor->nUndoLimit = min(wParam, STACK_SIZE_MAX);
3675  /* Setting a max stack size keeps wine from getting killed
3676  for hogging memory. Windows allocates all this memory at once, so
3677  no program would realistically set a value above our maximum. */
3678  return editor->nUndoLimit;
3679  }
3680  case EM_CANUNDO:
3681  return !list_empty( &editor->undo_stack );
3682  case EM_CANREDO:
3683  return !list_empty( &editor->redo_stack );
3684  case WM_UNDO: /* FIXME: actually not the same */
3685  case EM_UNDO:
3686  return ME_Undo(editor);
3687  case EM_REDO:
3688  return ME_Redo(editor);
3689  case EM_GETOPTIONS:
3690  {
3691  /* these flags are equivalent to the ES_* counterparts */
3694  DWORD settings = editor->styleFlags & mask;
3695 
3696  return settings;
3697  }
3698  case EM_SETFONTSIZE:
3699  {
3700  CHARFORMAT2W cf;
3701  LONG tmp_size, size;
3702  BOOL is_increase = ((LONG)wParam > 0);
3703 
3704  if (editor->mode & TM_PLAINTEXT)
3705  return FALSE;
3706 
3707  cf.cbSize = sizeof(cf);
3708  cf.dwMask = CFM_SIZE;
3709  ME_GetSelectionCharFormat(editor, &cf);
3710  tmp_size = (cf.yHeight / 20) + wParam;
3711 
3712  if (tmp_size <= 1)
3713  size = 1;
3714  else if (tmp_size > 12 && tmp_size < 28 && tmp_size % 2)
3715  size = tmp_size + (is_increase ? 1 : -1);
3716  else if (tmp_size > 28 && tmp_size < 36)
3717  size = is_increase ? 36 : 28;
3718  else if (tmp_size > 36 && tmp_size < 48)
3719  size = is_increase ? 48 : 36;
3720  else if (tmp_size > 48 && tmp_size < 72)
3721  size = is_increase ? 72 : 48;
3722  else if (tmp_size > 72 && tmp_size < 80)
3723  size = is_increase ? 80 : 72;
3724  else if (tmp_size > 80 && tmp_size < 1638)
3725  size = 10 * (is_increase ? (tmp_size / 10 + 1) : (tmp_size / 10));
3726  else if (tmp_size >= 1638)
3727  size = 1638;
3728  else
3729  size = tmp_size;
3730 
3731  cf.yHeight = size * 20; /* convert twips to points */
3732  ME_SetSelectionCharFormat(editor, &cf);
3733  ME_CommitUndo(editor);
3734  ME_WrapMarkedParagraphs(editor);
3735  ME_UpdateScrollBar(editor);
3736 
3737  return TRUE;
3738  }
3739  case EM_SETOPTIONS:
3740  {
3741  /* these flags are equivalent to ES_* counterparts, except for
3742  * ECO_AUTOWORDSELECTION that doesn't have an ES_* counterpart,
3743  * but is still stored in editor->styleFlags. */
3747  DWORD settings = mask & editor->styleFlags;
3748  DWORD oldSettings = settings;
3749  DWORD changedSettings;
3750 
3751  switch(wParam)
3752  {
3753  case ECOOP_SET:
3754  settings = lParam;
3755  break;
3756  case ECOOP_OR:
3757  settings |= lParam;
3758  break;
3759  case ECOOP_AND:
3760  settings &= lParam;
3761  break;
3762  case ECOOP_XOR:
3763  settings ^= lParam;
3764  }
3765  changedSettings = oldSettings ^ settings;
3766 
3767  if (changedSettings) {
3768  editor->styleFlags = (editor->styleFlags & ~mask) | (settings & mask);
3769 
3770  if (changedSettings & ECO_SELECTIONBAR)
3771  {
3772  ITextHost_TxInvalidateRect(editor->texthost, &editor->rcFormat, TRUE);
3773  if (settings & ECO_SELECTIONBAR) {
3774  assert(!editor->selofs);
3775  editor->selofs = SELECTIONBAR_WIDTH;
3776  editor->rcFormat.left += editor->selofs;
3777  } else {
3778  editor->rcFormat.left -= editor->selofs;
3779  editor->selofs = 0;
3780  }
3781  ME_RewrapRepaint(editor);
3782  }
3783 
3784  if ((changedSettings & settings & ES_NOHIDESEL) && !editor->bHaveFocus)
3785  ME_InvalidateSelection( editor );
3786 
3787  if (changedSettings & settings & ECO_VERTICAL)
3788  FIXME("ECO_VERTICAL not implemented yet!\n");
3789  if (changedSettings & settings & ECO_AUTOHSCROLL)
3790  FIXME("ECO_AUTOHSCROLL not implemented yet!\n");
3791  if (changedSettings & settings & ECO_AUTOVSCROLL)
3792  FIXME("ECO_AUTOVSCROLL not implemented yet!\n");
3793  if (changedSettings & settings & ECO_WANTRETURN)
3794  FIXME("ECO_WANTRETURN not implemented yet!\n");
3795  if (changedSettings & settings & ECO_AUTOWORDSELECTION)
3796  FIXME("ECO_AUTOWORDSELECTION not implemented yet!\n");
3797  }
3798 
3799  return settings;
3800  }
3801  case EM_SETSEL:
3802  {
3803  return set_selection( editor, wParam, lParam );
3804  }
3805  case EM_SETSCROLLPOS:
3806  {
3807  POINT *point = (POINT *)lParam;
3808  ME_ScrollAbs(editor, point->x, point->y);
3809  return 0;
3810  }
3811  case EM_AUTOURLDETECT:
3812  {
3813  if (wParam==1 || wParam ==0)
3814  {
3815  editor->AutoURLDetect_bEnable = (BOOL)wParam;
3816  return 0;
3817  }
3818  return E_INVALIDARG;
3819  }
3820  case EM_GETAUTOURLDETECT:
3821  {
3822  return editor->AutoURLDetect_bEnable;
3823  }
3824  case EM_EXSETSEL:
3825  {
3827 
3828  return set_selection( editor, range.cpMin, range.cpMax );
3829  }
3830  case EM_SHOWSCROLLBAR:
3831  {
3832  DWORD flags;
3833 
3834  switch (wParam)
3835  {
3836  case SB_HORZ:
3837  flags = WS_HSCROLL;
3838  break;
3839  case SB_VERT:
3840  flags = WS_VSCROLL;
3841  break;
3842  case SB_BOTH:
3844  break;
3845  default:
3846  return 0;
3847  }
3848 
3849  if (lParam) {
3850  editor->styleFlags |= flags;
3851  if (flags & WS_HSCROLL)
3853  editor->nTotalWidth > editor->sizeWindow.cx);
3854  if (flags & WS_VSCROLL)
3856  editor->nTotalLength > editor->sizeWindow.cy);
3857  } else {
3858  editor->styleFlags &= ~flags;
3860  }
3861  return 0;
3862  }
3863  case EM_SETTEXTEX:
3864  {
3865  LPWSTR wszText;
3866  SETTEXTEX *pStruct = (SETTEXTEX *)wParam;
3867  int from, to, len;
3868  ME_Style *style;
3869  BOOL bRtf, bUnicode, bSelection, bUTF8;
3870  int oldModify = editor->nModifyStep;
3871  static const char utf8_bom[] = {0xef, 0xbb, 0xbf};
3872 
3873  if (!pStruct) return 0;
3874 
3875  /* If we detect ascii rtf at the start of the string,
3876  * we know it isn't unicode. */
3877  bRtf = (lParam && (!strncmp((char *)lParam, "{\\rtf", 5) ||
3878  !strncmp((char *)lParam, "{\\urtf", 6)));
3879  bUnicode = !bRtf && pStruct->codepage == CP_UNICODE;
3880  bUTF8 = (lParam && (!strncmp((char *)lParam, utf8_bom, 3)));
3881 
3882  TRACE("EM_SETTEXTEX - %s, flags %d, cp %d\n",
3883  bUnicode ? debugstr_w((LPCWSTR)lParam) : debugstr_a((LPCSTR)lParam),
3884  pStruct->flags, pStruct->codepage);
3885 
3886  bSelection = (pStruct->flags & ST_SELECTION) != 0;
3887  if (bSelection) {
3888  int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
3890  ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to - from, FALSE);
3891  } else {
3892  ME_Cursor start;
3893  ME_SetCursorToStart(editor, &start);
3894  ME_InternalDeleteText(editor, &start, ME_GetTextLength(editor), FALSE);
3895  style = editor->pBuffer->pDefaultStyle;
3896  }
3897 
3898  if (bRtf) {
3899  ME_StreamInRTFString(editor, bSelection, (char *)lParam);
3900  if (bSelection) {
3901  /* FIXME: The length returned doesn't include the rtf control
3902  * characters, only the actual text. */
3903  len = lParam ? strlen((char *)lParam) : 0;
3904  }
3905  } else {
3906  if (bUTF8 && !bUnicode) {
3907  wszText = ME_ToUnicode(CP_UTF8, (void *)(lParam+3), &len);
3908  ME_InsertTextFromCursor(editor, 0, wszText, len, style);
3909  ME_EndToUnicode(CP_UTF8, wszText);
3910  } else {
3911  wszText = ME_ToUnicode(pStruct->codepage, (void *)lParam, &len);
3912  ME_InsertTextFromCursor(editor, 0, wszText, len, style);
3913  ME_EndToUnicode(pStruct->codepage, wszText);
3914  }
3915  }
3916 
3917  if (bSelection) {
3920  } else {
3921  ME_Cursor cursor;
3922  len = 1;
3923  ME_SetCursorToStart(editor, &cursor);
3925  }
3926  ME_CommitUndo(editor);
3927  if (!(pStruct->flags & ST_KEEPUNDO))
3928  {
3929  editor->nModifyStep = oldModify;
3930  ME_EmptyUndoStack(editor);
3931  }
3932  ME_UpdateRepaint(editor, FALSE);
3933  return len;
3934  }
3935  case EM_SELECTIONTYPE:
3936  return ME_GetSelectionType(editor);
3937  case EM_SETBKGNDCOLOR:
3938  {
3939  LRESULT lColor;
3940  if (editor->rgbBackColor != -1) {
3941  DeleteObject(editor->hbrBackground);
3942  lColor = editor->rgbBackColor;
3943  }
3944  else lColor = ITextHost_TxGetSysColor(editor->texthost, COLOR_WINDOW);
3945 
3946  if (wParam)
3947  {
3948  editor->rgbBackColor = -1;
3950  }
3951  else
3952  {
3953  editor->rgbBackColor = lParam;
3954  editor->hbrBackground = CreateSolidBrush(editor->rgbBackColor);
3955  }
3957  return lColor;
3958  }
3959  case EM_GETMODIFY:
3960  return editor->nModifyStep == 0 ? 0 : -1;
3961  case EM_SETMODIFY:
3962  {
3963  if (wParam)
3964  editor->nModifyStep = 1;
3965  else
3966  editor->nModifyStep = 0;
3967 
3968  return 0;
3969  }
3970  case EM_SETREADONLY:
3971  {
3972  if (wParam)
3973  editor->styleFlags |= ES_READONLY;
3974  else
3975  editor->styleFlags &= ~ES_READONLY;
3976  return 1;
3977  }
3978  case EM_SETEVENTMASK:
3979  {
3980  DWORD nOldMask = editor->nEventMask;
3981 
3982  editor->nEventMask = lParam;
3983  return nOldMask;
3984  }
3985  case EM_GETEVENTMASK:
3986  return editor->nEventMask;
3987  case EM_SETCHARFORMAT:
3988  return handle_EM_SETCHARFORMAT( editor, wParam, (CHARFORMAT2W *)lParam );
3989  case EM_GETCHARFORMAT:
3990  {
3991  CHARFORMAT2W tmp, *dst = (CHARFORMAT2W *)lParam;
3992  if (dst->cbSize != sizeof(CHARFORMATA) &&
3993  dst->cbSize != sizeof(CHARFORMATW) &&
3994  dst->cbSize != sizeof(CHARFORMAT2A) &&
3995  dst->cbSize != sizeof(CHARFORMAT2W))
3996  return 0;
3997  tmp.cbSize = sizeof(tmp);
3998  if (!wParam)
3999  ME_GetDefaultCharFormat(editor, &tmp);
4000  else
4001  ME_GetSelectionCharFormat(editor, &tmp);
4002  cf2w_to_cfany(dst, &tmp);
4003  return tmp.dwMask;
4004  }
4005  case EM_SETPARAFORMAT:
4006  {
4008  ME_WrapMarkedParagraphs(editor);
4009  ME_UpdateScrollBar(editor);
4010  ME_CommitUndo(editor);
4011  return result;
4012  }
4013  case EM_GETPARAFORMAT:
4015  return ((PARAFORMAT2 *)lParam)->dwMask;
4017  {
4018  ME_DisplayItem *p = editor->pBuffer->pFirst;
4019  int y = editor->vert_si.nPos;
4020  int ypara = 0;
4021  int count = 0;
4022  int ystart, yend;
4023  while(p) {
4025  if (p->type == diTextEnd)
4026  break;
4027  if (p->type == diParagraph) {
4028  ypara = p->member.para.pt.y;
4029  continue;
4030  }
4031  ystart = ypara + p->member.row.pt.y;
4032  yend = ystart + p->member.row.nHeight;
4033  if (y < yend) {
4034  break;
4035  }
4036  count++;
4037  }
4038  return count;
4039  }
4040  case EM_HIDESELECTION:
4041  {
4042  editor->bHideSelection = (wParam != 0);
4043  ME_InvalidateSelection(editor);
4044  return 0;
4045  }
4046  case EM_LINESCROLL:
4047  {
4048  if (!(editor->styleFlags & ES_MULTILINE))
4049  return FALSE;
4050  ME_ScrollDown( editor, lParam * get_default_line_height( editor ) );
4051  return TRUE;
4052  }
4053  case WM_CLEAR:
4054  {
4055  int from, to;
4056  int nStartCursor = ME_GetSelectionOfs(editor, &from, &to);
4057  ME_InternalDeleteText(editor, &editor->pCursors[nStartCursor], to-from, FALSE);
4058  ME_CommitUndo(editor);
4059  ME_UpdateRepaint(editor, TRUE);
4060  return 0;
4061  }
4062  case EM_REPLACESEL:
4063  {
4064  int len = 0;
4065  LONG codepage = unicode ? CP_UNICODE : CP_ACP;
4066  LPWSTR wszText = ME_ToUnicode(codepage, (void *)lParam, &len);
4067 
4068  TRACE("EM_REPLACESEL - %s\n", debugstr_w(wszText));
4069 
4070  ME_ReplaceSel(editor, !!wParam, wszText, len);
4071  ME_EndToUnicode(codepage, wszText);
4072  return len;
4073  }
4074  case EM_SCROLLCARET:
4075  ME_EnsureVisible(editor, &editor->pCursors[0]);
4076  return 0;
4077  case WM_SETFONT:
4078  {
4079  LOGFONTW lf;
4080  CHARFORMAT2W fmt;
4081  HDC hDC;
4082  BOOL bRepaint = LOWORD(lParam);
4083 
4084  if (!wParam)
4086 
4087  if (!GetObjectW((HGDIOBJ)wParam, sizeof(LOGFONTW), &lf))
4088  return 0;
4089 
4090  hDC = ITextHost_TxGetDC(editor->texthost);
4093  if (editor->mode & TM_RICHTEXT) {
4094  ME_Cursor start;
4095  ME_SetCursorToStart(editor, &start);
4096  ME_SetCharFormat(editor, &start, NULL, &fmt);
4097  }
4098  ME_SetDefaultCharFormat(editor, &fmt);
4099 
4100  ME_CommitUndo(editor);
4101  ME_MarkAllForWrapping(editor);
4102  ME_WrapMarkedParagraphs(editor);
4103  ME_UpdateScrollBar(editor);
4104  if (bRepaint)
4105  ME_Repaint(editor);
4106  return 0;
4107  }
4108  case WM_SETTEXT:
4109  {
4110  ME_Cursor cursor;
4111  ME_SetCursorToStart(editor, &cursor);
4112  ME_InternalDeleteText(editor, &cursor, ME_GetTextLength(editor), FALSE);
4113  if (lParam)
4114  {
4115  TRACE("WM_SETTEXT lParam==%lx\n",lParam);
4116  if (!strncmp((char *)lParam, "{\\rtf", 5) ||
4117  !strncmp((char *)lParam, "{\\urtf", 6))
4118  {
4119  /* Undocumented: WM_SETTEXT supports RTF text */
4120  ME_StreamInRTFString(editor, 0, (char *)lParam);
4121  }
4122  else
4123  ME_SetText(editor, (void*)lParam, unicode);
4124  }
4125  else
4126  TRACE("WM_SETTEXT - NULL\n");
4127  ME_SetCursorToStart(editor, &cursor);
4129  set_selection_cursors(editor, 0, 0);
4130  editor->nModifyStep = 0;
4131  ME_CommitUndo(editor);
4132  ME_EmptyUndoStack(editor);
4133  ME_UpdateRepaint(editor, FALSE);
4134  return 1;
4135  }
4136  case EM_CANPASTE:
4137  return paste_special( editor, 0, NULL, TRUE );
4138  case WM_PASTE:
4139  case WM_MBUTTONDOWN:
4140  wParam = 0;
4141  lParam = 0;
4142  /* fall through */
4143  case EM_PASTESPECIAL:
4145  return 0;
4146  case WM_CUT:
4147  case WM_COPY:
4148  copy_or_cut(editor, msg == WM_CUT);
4149  return 0;
4150  case WM_GETTEXTLENGTH:
4151  {
4152  GETTEXTLENGTHEX how;
4153 
4154  /* CR/LF conversion required in 2.0 mode, verbatim in 1.0 mode */
4155  how.flags = GTL_CLOSE | (editor->bEmulateVersion10 ? 0 : GTL_USECRLF) | GTL_NUMCHARS;
4156  how.codepage = unicode ? CP_UNICODE : CP_ACP;
4157  return ME_GetTextLengthEx(editor, &how);
4158  }
4159  case EM_GETTEXTLENGTHEX:
4160  return ME_GetTextLengthEx(editor, (GETTEXTLENGTHEX *)wParam);
4161  case WM_GETTEXT:
4162  {
4163  GETTEXTEX ex;
4164  ex.cb = wParam * (unicode ? sizeof(WCHAR) : sizeof(CHAR));
4165  ex.flags = GT_USECRLF;
4166  ex.codepage = unicode ? CP_UNICODE : CP_ACP;
4167  ex.lpDefaultChar = NULL;
4168  ex.lpUsedDefChar = NULL;
4169  return ME_GetTextEx(editor, &ex, lParam);
4170  }
4171  case EM_GETTEXTEX:
4172  return ME_GetTextEx(editor, (GETTEXTEX*)wParam, lParam);
4173  case EM_GETSELTEXT:
4174  {
4175  int nFrom, nTo, nStartCur = ME_GetSelectionOfs(editor, &nFrom, &nTo);
4176  ME_Cursor *from = &editor->pCursors[nStartCur];
4177  return ME_GetTextRange(editor, (WCHAR *)lParam, from,
4178  nTo - nFrom, unicode);
4179  }
4180  case EM_GETSCROLLPOS:
4181  {
4182  POINT *point = (POINT *)lParam;
4183  point->x = editor->horz_si.nPos;
4184  point->y = editor->vert_si.nPos;
4185  /* 16-bit scaled value is returned as stored in scrollinfo */
4186  if (editor->horz_si.nMax > 0xffff)
4187  point->x = MulDiv(point->x, 0xffff, editor->horz_si.nMax);
4188  if (editor->vert_si.nMax > 0xffff)
4189  point->y = MulDiv(point->y, 0xffff, editor->vert_si.nMax);
4190  return 1;
4191  }
4192  case EM_GETTEXTRANGE:
4193  {
4194  TEXTRANGEW *rng = (TEXTRANGEW *)lParam;
4195  ME_Cursor start;
4196  int nStart = rng->chrg.cpMin;
4197  int nEnd = rng->chrg.cpMax;
4198  int textlength = ME_GetTextLength(editor);
4199 
4200  TRACE("EM_GETTEXTRANGE min=%d max=%d unicode=%d textlength=%d\n",
4201  rng->chrg.cpMin, rng->chrg.cpMax, unicode, textlength);
4202  if (nStart < 0) return 0;
4203  if ((nStart == 0 && nEnd == -1) || nEnd > textlength)
4204  nEnd = textlength;
4205  if (nStart >= nEnd) return 0;
4206 
4207  ME_CursorFromCharOfs(editor, nStart, &start);
4208  return ME_GetTextRange(editor, rng->lpstrText, &start, nEnd - nStart, unicode);
4209  }
4210  case EM_GETLINE:
4211  {
4212  ME_DisplayItem *run;
4213  const unsigned int nMaxChars = *(WORD *) lParam;
4214  unsigned int nCharsLeft = nMaxChars;
4215  char *dest = (char *) lParam;
4216  BOOL wroteNull = FALSE;
4217 
4218  TRACE("EM_GETLINE: row=%d, nMaxChars=%d (%s)\n", (int) wParam, nMaxChars,
4219  unicode ? "Unicode" : "Ansi");
4220 
4221  run = ME_FindRowWithNumber(editor, wParam);
4222  if (run == NULL)
4223  return 0;
4224 
4225  while (nCharsLeft && (run = ME_FindItemFwd(run, diRunOrStartRow))
4226  && run->type == diRun)
4227  {
4228  WCHAR *str = get_text( &run->member.run, 0 );
4229  unsigned int nCopy;
4230 
4231  nCopy = min(nCharsLeft, run->member.run.len);
4232 
4233  if (unicode)
4234  memcpy(dest, str, nCopy * sizeof(WCHAR));
4235  else
4236  nCopy = WideCharToMultiByte(CP_ACP, 0, str, nCopy, dest,
4237  nCharsLeft, NULL, NULL);
4238  dest += nCopy * (unicode ? sizeof(WCHAR) : 1);
4239  nCharsLeft -= nCopy;
4240  }
4241 
4242  /* append line termination, space allowing */
4243  if (nCharsLeft > 0)
4244  {
4245  if (unicode)
4246  *((WCHAR *)dest) = '\0';
4247  else
4248  *dest = '\0';
4249  nCharsLeft--;
4250  wroteNull = TRUE;
4251  }
4252 
4253  TRACE("EM_GETLINE: got %u characters\n", nMaxChars - nCharsLeft);
4254  return nMaxChars - nCharsLeft - (wroteNull ? 1 : 0);
4255  }
4256  case EM_GETLINECOUNT:
4257  {
4258  ME_DisplayItem *item = editor->pBuffer->pLast;
4259  int nRows = editor->total_rows;
4260  ME_DisplayItem *prev_para = NULL, *last_para = NULL;
4261 
4262  last_para = ME_FindItemBack(item, diRun);
4263  prev_para = ME_FindItemBack(last_para, diRun);
4264  assert(last_para);
4265  assert(last_para->member.run.nFlags & MERF_ENDPARA);
4266  if (editor->bEmulateVersion10 && prev_para &&
4267  last_para->member.run.nCharOfs == 0 &&
4268  prev_para->member.run.len == 1 &&
4269  *get_text( &prev_para->member.run, 0 ) == '\r')
4270  {
4271  /* In 1.0 emulation, the last solitary \r at the very end of the text
4272  (if one exists) is NOT a line break.
4273  FIXME: this is an ugly hack. This should have a more regular model. */
4274  nRows--;
4275  }
4276 
4277  TRACE("EM_GETLINECOUNT: nRows==%d\n", nRows);
4278  return max(1, nRows);
4279  }
4280  case EM_LINEFROMCHAR:
4281  {
4282  if (wParam == -1)
4283  return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
4284  else
4285  return ME_RowNumberFromCharOfs(editor, wParam);
4286  }
4287  case EM_EXLINEFROMCHAR:
4288  {
4289  if (lParam == -1)
4290  return ME_RowNumberFromCharOfs(editor, ME_GetCursorOfs(&editor->pCursors[1]));
4291  else
4292  return ME_RowNumberFromCharOfs(editor, lParam);
4293  }
4294  case EM_LINEINDEX:
4295  {
4296  ME_DisplayItem *item, *para;
4297  int nCharOfs;
4298 
4299  if (wParam == -1)
4300  item = ME_FindItemBack(editor->pCursors[0].pRun, diStartRow);
4301  else
4302  item = ME_FindRowWithNumber(editor, wParam);
4303  if (!item)
4304  return -1;
4305  para = ME_GetParagraph(item);
4307  nCharOfs = para->member.para.nCharOfs + item->member.run.nCharOfs;
4308  TRACE("EM_LINEINDEX: nCharOfs==%d\n", nCharOfs);
4309  return nCharOfs;
4310  }
4311  case EM_LINELENGTH:
4312  {
4313  ME_DisplayItem *item, *item_end;
4314  int nChars = 0, nThisLineOfs = 0, nNextLineOfs = 0;
4315  ME_DisplayItem *para, *run;
4316 
4317  if (wParam > ME_GetTextLength(editor))
4318  return 0;
4319  if (wParam == -1)
4320  {
4321  FIXME("EM_LINELENGTH: returning number of unselected characters on lines with selection unsupported.\n");
4322  return 0;
4323  }
4324  ME_RunOfsFromCharOfs(editor, wParam, &para, &run, NULL);
4325  item = ME_RowStart(run);
4326  nThisLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item, diRun), 0);
4328  if (item_end->type == diStartRow) {
4329  nNextLineOfs = ME_CharOfsFromRunOfs(editor, para, ME_FindItemFwd(item_end, diRun), 0);
4330  } else {
4331  ME_DisplayItem *endRun = ME_FindItemBack(item_end, diRun);
4332  assert(endRun && endRun->member.run.nFlags & MERF_ENDPARA);
4333  nNextLineOfs = item_end->member.para.nCharOfs - endRun->member.run.len;
4334  }
4335  nChars = nNextLineOfs - nThisLineOfs;
4336  TRACE("EM_LINELENGTH(%ld)==%d\n",wParam, nChars);
4337  return nChars;
4338  }
4339  case EM_EXLIMITTEXT:
4340  {
4341  if ((int)lParam < 0)
4342  return 0;
4343  if (lParam == 0)
4344  editor->nTextLimit = 65536;
4345  else
4346  editor->nTextLimit = (int) lParam;
4347  return 0;
4348  }
4349  case EM_LIMITTEXT:
4350  {
4351  if (wParam == 0)
4352  editor->nTextLimit = 65536;
4353  else
4354  editor->nTextLimit = (int) wParam;
4355  return 0;
4356  }
4357  case EM_GETLIMITTEXT:
4358  {
4359  return editor->nTextLimit;
4360  }
4361  case EM_FINDTEXT:
4362  {
4363  LRESULT r;
4364  if(!unicode){
4365  FINDTEXTA *ft = (FINDTEXTA *)lParam;
4366  int nChars = MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, NULL, 0);
4367  WCHAR *tmp;
4368 
4369  if ((tmp = heap_alloc(nChars * sizeof(*tmp))) != NULL)
4370  MultiByteToWideChar(CP_ACP, 0, ft->lpstrText, -1, tmp, nChars);
4371  r = ME_FindText(editor, wParam, &ft->chrg, tmp, NULL);
4372  heap_free(tmp);
4373  }else{
4374  FINDTEXTW *ft = (FINDTEXTW *)lParam;
4375  r = ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
4376  }
4377  return r;
4378  }
4379  case EM_FINDTEXTEX:
4380  {
4381  LRESULT r;
4382  if(!unicode){
4384  int nChars = MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, NULL, 0);
4385  WCHAR *tmp;
4386 
4387  if ((tmp = heap_alloc(nChars * sizeof(*tmp))) != NULL)
4388  MultiByteToWideChar(CP_ACP, 0, ex->lpstrText, -1, tmp, nChars);
4389  r = ME_FindText(editor, wParam, &ex->chrg, tmp, &ex->chrgText);
4390  heap_free(tmp);
4391  }else{
4393  r = ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
4394  }
4395  return r;
4396  }
4397  case EM_FINDTEXTW:
4398  {
4399  FINDTEXTW *ft = (FINDTEXTW *)lParam;
4400  return ME_FindText(editor, wParam, &ft->chrg, ft->lpstrText, NULL);
4401  }
4402  case EM_FINDTEXTEXW:
4403  {
4405  return ME_FindText(editor, wParam, &ex->chrg, ex->lpstrText, &ex->chrgText);
4406  }
4407  case EM_GETZOOM:
4408  if (!wParam || !lParam)
4409  return FALSE;
4410  *(int *)wParam = editor->nZoomNumerator;
4411  *(int *)lParam = editor->nZoomDenominator;
4412  return TRUE;
4413  case EM_SETZOOM:
4414  return ME_SetZoom(editor, wParam, lParam);
4415  case EM_CHARFROMPOS:
4416  {
4417  ME_Cursor cursor;
4418  if (ME_CharFromPos(editor, ((POINTL *)lParam)->x, ((POINTL *)lParam)->y,
4419  &cursor, NULL))
4420  return ME_GetCursorOfs(&cursor);
4421  else
4422  return -1;
4423  }
4424  case EM_POSFROMCHAR:
4425  {
4426  ME_DisplayItem *pPara, *pRun;
4427  int nCharOfs, nOffset, nLength;
4428  POINTL pt = {0,0};
4429 
4430  nCharOfs = wParam;
4431  /* detect which API version we're dealing with */
4432  if (wParam >= 0x40000)
4433  nCharOfs = lParam;
4434  nLength = ME_GetTextLength(editor);
4435  nCharOfs = min(nCharOfs, nLength);
4436  nCharOfs = max(nCharOfs, 0);
4437 
4438  ME_RunOfsFromCharOfs(editor, nCharOfs, &pPara, &pRun, &nOffset);
4439  assert(pRun->type == diRun);
4440  pt.y = pRun->member.run.pt.y;
4441  pt.x = pRun->member.run.pt.x + ME_PointFromChar(editor, &pRun->member.run, nOffset, TRUE);
4442  pt.y += pPara->member.para.pt.y + editor->rcFormat.top;
4443  pt.x += editor->rcFormat.left;
4444 
4445  pt.x -= editor->horz_si.nPos;
4446  pt.y -= editor->vert_si.nPos;
4447 
4448  if (wParam >= 0x40000) {
4449  *(POINTL *)wParam = pt;
4450  }
4451  return (wParam >= 0x40000) ? 0 : MAKELONG( pt.x, pt.y );
4452  }
4453  case WM_CREATE:
4454  return ME_WmCreate(editor, lParam, unicode);
4455  case WM_DESTROY:
4456  ME_DestroyEditor(editor);
4457  return 0;
4458  case WM_SETCURSOR:
4459  {
4460  POINT cursor_pos;
4461  if (wParam == (WPARAM)editor->hWnd && GetCursorPos(&cursor_pos) &&
4462  ScreenToClient(editor->hWnd, &cursor_pos))
4463  ME_LinkNotify(editor, msg, 0, MAKELPARAM(cursor_pos.x, cursor_pos.y));
4464  return ME_SetCursor(editor);
4465  }
4466  case WM_LBUTTONDBLCLK:
4467  case WM_LBUTTONDOWN:
4468  {
4469  ME_CommitUndo(editor); /* End coalesced undos for typed characters */
4470  if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
4471  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4472  return 0;
4473  ITextHost_TxSetFocus(editor->texthost);
4474  ME_LButtonDown(editor, (short)LOWORD(lParam), (short)HIWORD(lParam),
4477  editor->bMouseCaptured = TRUE;
4478  ME_LinkNotify(editor, msg, wParam, lParam);
4479  if (!ME_SetCursor(editor)) goto do_default;
4480  break;
4481  }
4482  case WM_MOUSEMOVE:
4483  if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
4484  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4485  return 0;
4486  if (editor->bMouseCaptured)
4487  ME_MouseMove(editor, (short)LOWORD(lParam), (short)HIWORD(lParam));
4488  else
4489  ME_LinkNotify(editor, msg, wParam, lParam);
4490  /* Set cursor if mouse is captured, since WM_SETCURSOR won't be received. */
4491  if (editor->bMouseCaptured)
4492  ME_SetCursor(editor);
4493  break;
4494  case WM_LBUTTONUP:
4495  if (editor->bMouseCaptured) {
4497  editor->bMouseCaptured = FALSE;
4498  }
4499  if (editor->nSelectionType == stDocument)
4500  editor->nSelectionType = stPosition;
4501  if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
4502  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4503  return 0;
4504  else
4505  {
4506  ME_SetCursor(editor);
4507  ME_LinkNotify(editor, msg, wParam, lParam);
4508  }
4509  break;
4510  case WM_RBUTTONUP:
4511  case WM_RBUTTONDOWN:
4512  case WM_RBUTTONDBLCLK:
4513  ME_CommitUndo(editor); /* End coalesced undos for typed characters */
4514  if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
4515  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4516  return 0;
4517  ME_LinkNotify(editor, msg, wParam, lParam);
4518  goto do_default;
4519  case WM_CONTEXTMENU:
4520  if (!ME_ShowContextMenu(editor, (short)LOWORD(lParam), (short)HIWORD(lParam)))
4521  goto do_default;
4522  break;
4523  case WM_SETFOCUS:
4524  editor->bHaveFocus = TRUE;
4525  create_caret(editor);
4526  update_caret(editor);
4527  ME_SendOldNotify(editor, EN_SETFOCUS);
4528  if (!editor->bHideSelection && !(editor->styleFlags & ES_NOHIDESEL))
4529  ME_InvalidateSelection( editor );
4530  return 0;
4531  case WM_KILLFOCUS:
4532  ME_CommitUndo(editor); /* End coalesced undos for typed characters */
4533  editor->bHaveFocus = FALSE;
4534  editor->wheel_remain = 0;
4535  hide_caret(editor);
4536  DestroyCaret();
4537  ME_SendOldNotify(editor, EN_KILLFOCUS);
4538  if (!editor->bHideSelection && !(editor->styleFlags & ES_NOHIDESEL))
4539  ME_InvalidateSelection( editor );
4540  return 0;
4541  case WM_COMMAND:
4542  TRACE("editor wnd command = %d\n", LOWORD(wParam));
4543  return 0;
4544  case WM_KEYUP:
4545  if ((editor->nEventMask & ENM_KEYEVENTS) &&
4546  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4547  return 0;
4548  goto do_default;
4549  case WM_KEYDOWN:
4550  if ((editor->nEventMask & ENM_KEYEVENTS) &&
4551  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4552  return 0;
4553  if (ME_KeyDown(editor, LOWORD(wParam)))
4554  return 0;
4555  goto do_default;
4556  case WM_CHAR:
4557  if ((editor->nEventMask & ENM_KEYEVENTS) &&
4558  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4559  return 0;
4560  return ME_Char(editor, wParam, lParam, unicode);
4561  case WM_UNICHAR:
4562  if (unicode)
4563  {
4564  if(wParam == UNICODE_NOCHAR) return TRUE;
4565  if(wParam <= 0x000fffff)
4566  {
4567  if(wParam > 0xffff) /* convert to surrogates */
4568  {
4569  wParam -= 0x10000;
4570  ME_Char(editor, (wParam >> 10) + 0xd800, 0, TRUE);
4571  ME_Char(editor, (wParam & 0x03ff) + 0xdc00, 0, TRUE);
4572  } else {
4573  ME_Char(editor, wParam, 0, TRUE);
4574  }
4575  }
4576  return 0;
4577  }
4578  break;
4579  case EM_STOPGROUPTYPING:
4580  ME_CommitUndo(editor); /* End coalesced undos for typed characters */
4581  return 0;
4582  case WM_HSCROLL:
4583  {
4584  const int scrollUnit = 7;
4585 
4586  switch(LOWORD(wParam))
4587  {
4588  case SB_LEFT:
4589  ME_ScrollAbs(editor, 0, 0);
4590  break;
4591  case SB_RIGHT:
4592  ME_ScrollAbs(editor,
4593  editor->horz_si.nMax - (int)editor->horz_si.nPage,
4594  editor->vert_si.nMax - (int)editor->vert_si.nPage);
4595  break;
4596  case SB_LINELEFT:
4597  ME_ScrollLeft(editor, scrollUnit);
4598  break;
4599  case SB_LINERIGHT:
4600  ME_ScrollRight(editor, scrollUnit);
4601  break;
4602  case SB_PAGELEFT:
4603  ME_ScrollLeft(editor, editor->sizeWindow.cx);
4604  break;
4605  case SB_PAGERIGHT:
4606  ME_ScrollRight(editor, editor->sizeWindow.cx);
4607  break;
4608  case SB_THUMBTRACK:
4609  case SB_THUMBPOSITION:
4610  {
4611  int pos = HIWORD(wParam);
4612  if (editor->horz_si.nMax > 0xffff)
4613  pos = MulDiv(pos, editor->horz_si.nMax, 0xffff);
4614  ME_HScrollAbs(editor, pos);
4615  break;
4616  }
4617  }
4618  break;
4619  }
4620  case EM_SCROLL: /* fall through */
4621  case WM_VSCROLL:
4622  {
4623  int origNPos;
4624  int lineHeight = get_default_line_height( editor );
4625 
4626  origNPos = editor->vert_si.nPos;
4627 
4628  switch(LOWORD(wParam))
4629  {
4630  case SB_TOP:
4631  ME_ScrollAbs(editor, 0, 0);
4632  break;
4633  case SB_BOTTOM:
4634  ME_ScrollAbs(editor,
4635  editor->horz_si.nMax - (int)editor->horz_si.nPage,
4636  editor->vert_si.nMax - (int)editor->vert_si.nPage);
4637  break;
4638  case SB_LINEUP:
4639  ME_ScrollUp(editor,lineHeight);
4640  break;
4641  case SB_LINEDOWN:
4642  ME_ScrollDown(editor,lineHeight);
4643  break;
4644  case SB_PAGEUP:
4645  ME_ScrollUp(editor,editor->sizeWindow.cy);
4646  break;
4647  case SB_PAGEDOWN:
4648  ME_ScrollDown(editor,editor->sizeWindow.cy);
4649  break;
4650  case SB_THUMBTRACK:
4651  case SB_THUMBPOSITION:
4652  {
4653  int pos = HIWORD(wParam);
4654  if (editor->vert_si.nMax > 0xffff)
4655  pos = MulDiv(pos, editor->vert_si.nMax, 0xffff);
4656  ME_VScrollAbs(editor, pos);
4657  break;
4658  }
4659  }
4660  if (msg == EM_SCROLL)
4661  return 0x00010000 | (((editor->vert_si.nPos - origNPos)/lineHeight) & 0xffff);
4662  break;
4663  }
4664  case WM_MOUSEWHEEL:
4665  {
4666  int delta;
4667  BOOL ctrl_is_down;
4668 
4669  if ((editor->nEventMask & ENM_MOUSEEVENTS) &&
4670  !ME_FilterEvent(editor, msg, &wParam, &lParam))
4671  return 0;
4672 
4673  ctrl_is_down = GetKeyState(VK_CONTROL) & 0x8000;
4674 
4675  delta = GET_WHEEL_DELTA_WPARAM(wParam);
4676 
4677  /* if scrolling changes direction, ignore left overs */
4678  if ((delta < 0 && editor->wheel_remain < 0) ||
4679  (delta > 0 && editor->wheel_remain > 0))
4680  editor->wheel_remain += delta;
4681  else
4682  editor->wheel_remain = delta;
4683 
4684  if (editor->wheel_remain)
4685  {
4686  if (ctrl_is_down) {
4687  int numerator;
4688  if (!editor->nZoomNumerator || !editor->nZoomDenominator)
4689  {
4690  numerator = 100;
4691  } else {
4692  numerator = editor->nZoomNumerator * 100 / editor->nZoomDenominator;
4693  }
4694  numerator += calc_wheel_change( &editor->wheel_remain, 10 );
4695  if (numerator >= 10 && numerator <= 500)
4696  ME_SetZoom(editor, numerator, 100);
4697  } else {
4698  UINT max_lines = 3;
4699  int lines = 0;
4700 
4701  SystemParametersInfoW( SPI_GETWHEELSCROLLLINES, 0, &max_lines, 0 );
4702  if (max_lines)
4703  lines = calc_wheel_change( &editor->wheel_remain, (int)max_lines );
4704  if (lines)
4705  ME_ScrollDown( editor, -lines * get_default_line_height( editor ) );
4706  }
4707  }
4708  break;
4709  }
4710  case EM_GETRECT:
4711  {
4712  *((RECT *)lParam) = editor->rcFormat;
4713  if (editor->bDefaultFormatRect)
4714  ((RECT *)lParam)->left -= editor->selofs;
4715  return 0;
4716  }
4717  case EM_SETRECT:
4718  case EM_SETRECTNP:
4719  {
4720  if (lParam)
4721  {
4722  int border = 0;
4723  RECT clientRect;
4724  RECT *rc = (RECT *)lParam;
4725 
4726  border = editor->exStyleFlags & WS_EX_CLIENTEDGE ? 1 : 0;
4727  ITextHost_TxGetClientRect(editor->texthost, &clientRect);
4728  if (wParam == 0)
4729  {
4730  editor->rcFormat.top = max(0, rc->top - border);
4731  editor->rcFormat.left = max(0, rc->left - border);
4732  editor->rcFormat.bottom = min(clientRect.bottom, rc->bottom);
4733  editor->rcFormat.right = min(clientRect.right, rc->right + border);
4734  } else if (wParam == 1) {
4735  /* MSDN incorrectly says a wParam value of 1 causes the
4736  * lParam rect to be used as a relative offset,
4737  * however, the tests show it just prevents min/max bound
4738  * checking. */
4739  editor->rcFormat.top = rc->top - border;
4740  editor->rcFormat.left = rc->left - border;
4741  editor->rcFormat.bottom = rc->bottom;
4742  editor->rcFormat.right = rc->right + border;
4743  } else {
4744  return 0;
4745  }
4746  editor->bDefaultFormatRect = FALSE;
4747  }
4748  else
4749  {
4750  ME_SetDefaultFormatRect(editor);
4751  editor->bDefaultFormatRect = TRUE;
4752  }
4753  ME_MarkAllForWrapping(editor);
4754  ME_WrapMarkedParagraphs(editor);
4755  ME_UpdateScrollBar(editor);
4756  if (msg != EM_SETRECTNP)
4757  ME_Repaint(editor);
4758  return 0;
4759  }
4760  case EM_REQUESTRESIZE:
4761  ME_SendRequestResize(editor, TRUE);
4762  return 0;
4763  case WM_SETREDRAW:
4764  goto do_default;
4765  case WM_WINDOWPOSCHANGED:
4766  {
4767  RECT clientRect;
4768  WINDOWPOS *winpos = (WINDOWPOS *)lParam;
4769 
4770  if (winpos->flags & SWP_NOCLIENTSIZE) goto do_default;
4771  ITextHost_TxGetClientRect(editor->texthost, &clientRect);
4772  if (editor->bDefaultFormatRect) {
4773  ME_SetDefaultFormatRect(editor);
4774  } else {
4775  editor->rcFormat.right += clientRect.right - editor->prevClientRect.right;
4776  editor->rcFormat.bottom += clientRect.bottom - editor->prevClientRect.bottom;
4777  }
4778  editor->prevClientRect = clientRect;
4779  ME_RewrapRepaint(editor);
4780  goto do_default;
4781  }
4782  /* IME messages to make richedit controls IME aware */
4783  case WM_IME_SETCONTEXT:
4784  case WM_IME_CONTROL:
4785  case WM_IME_SELECT:
4787  return 0;
4788  case WM_IME_STARTCOMPOSITION:
4789  {
4790  editor->imeStartIndex=ME_GetCursorOfs(&editor->pCursors[0]);
4791  ME_DeleteSelection(editor);
4792  ME_CommitUndo(editor);
4793  ME_UpdateRepaint(editor, FALSE);
4794  return 0;
4795  }
4796  case WM_IME_COMPOSITION:
4797  {
4798  HIMC hIMC;
4799 
4800  ME_Style *style = ME_GetInsertStyle(editor, 0);
4801  hIMC = ITextHost_TxImmGetContext(editor->texthost);
4802  ME_DeleteSelection(editor);
4803  ME_SaveTempStyle(editor, style);
4805  {
4806  LPWSTR lpCompStr = NULL;
4807  DWORD dwBufLen;
4808  DWORD dwIndex = lParam & GCS_RESULTSTR;
4809  if (!dwIndex)
4810  dwIndex = GCS_COMPSTR;
4811 
4812  dwBufLen = ImmGetCompositionStringW(hIMC, dwIndex, NULL, 0);
4813  lpCompStr = HeapAlloc(GetProcessHeap(),0,dwBufLen + sizeof(WCHAR));
4814  ImmGetCompositionStringW(hIMC, dwIndex, lpCompStr, dwBufLen);
4815  lpCompStr[dwBufLen/sizeof(WCHAR)] = 0;
4816  ME_InsertTextFromCursor(editor,0,lpCompStr,dwBufLen/sizeof(WCHAR),style);
4817  HeapFree(GetProcessHeap(), 0, lpCompStr);
4818 
4819  if (dwIndex == GCS_COMPSTR)
4820  set_selection_cursors(editor,editor->imeStartIndex,
4821  editor->imeStartIndex + dwBufLen/sizeof(WCHAR));
4822  }
4824  ME_CommitUndo(editor);
4825  ME_UpdateRepaint(editor, FALSE);
4826  return 0;
4827  }
4828  case WM_IME_ENDCOMPOSITION:
4829  {
4830  ME_DeleteSelection(editor);
4831  editor->imeStartIndex=-1;
4832  return 0;
4833  }
4834  case EM_GETOLEINTERFACE:
4835  {
4836  if (!editor->reOle)
4837  if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
4838  return 0;
4839  if (IUnknown_QueryInterface(editor->reOle, &IID_IRichEditOle, (LPVOID *)lParam) == S_OK)
4840  return 1;
4841  return 0;
4842  }
4843  case EM_GETPASSWORDCHAR:
4844  {
4845  return editor->cPasswordMask;
4846  }
4847  case EM_SETOLECALLBACK:
4848  if(editor->lpOleCallback)
4849  IRichEditOleCallback_Release(editor->lpOleCallback);
4851  if(editor->lpOleCallback)
4852  IRichEditOleCallback_AddRef(editor->lpOleCallback);
4853  return TRUE;
4854  case EM_GETWORDBREAKPROC:
4855  return (LRESULT)editor->pfnWordBreak;
4856  case EM_SETWORDBREAKPROC:
4857  {
4858  EDITWORDBREAKPROCW pfnOld = editor->pfnWordBreak;
4859 
4861  return (LRESULT)pfnOld;
4862  }
4863  case EM_GETTEXTMODE:
4864  return editor->mode;
4865  case EM_SETTEXTMODE:
4866  {
4867  int mask = 0;
4868  int changes = 0;
4869 
4870  if (ME_GetTextLength(editor) ||
4871  !list_empty( &editor->undo_stack ) || !list_empty( &editor->redo_stack ))
4872  return E_UNEXPECTED;
4873 
4874  /* Check for mutually exclusive flags in adjacent bits of wParam */
4877  return E_INVALIDARG;
4878 
4879  if (wParam & (TM_RICHTEXT | TM_PLAINTEXT))
4880  {
4883  if (wParam & TM_PLAINTEXT) {
4884  /* Clear selection since it should be possible to select the
4885  * end of text run for rich text */
4886  ME_InvalidateSelection(editor);
4887  ME_SetCursorToStart(editor, &editor->pCursors[0]);
4888  editor->pCursors[1] = editor->pCursors[0];
4889  /* plain text can only have the default style. */
4890  ME_ClearTempStyle(editor);
4893  editor->pCursors[0].pRun->member.run.style = editor->pBuffer->pDefaultStyle;
4894  }
4895  }
4896  /* FIXME: Currently no support for undo level and code page options */
4897  editor->mode = (editor->mode & ~mask) | changes;
4898  return 0;
4899  }
4900  case EM_SETPASSWORDCHAR:
4901  {
4902  editor->cPasswordMask = wParam;
4903  ME_RewrapRepaint(editor);
4904  return 0;
4905  }
4906  case EM_SETTARGETDEVICE:
4907  if (wParam == 0)
4908  {
4909  BOOL new = (lParam == 0 && (editor->styleFlags & ES_MULTILINE));
4910  if (editor->nAvailWidth || editor->bWordWrap != new)
4911  {
4912  editor->bWordWrap = new;
4913  editor->nAvailWidth = 0; /* wrap to client area */
4914  ME_RewrapRepaint(editor);
4915  }
4916  } else {
4917  int width = max(0, lParam);
4918  if ((editor->styleFlags & ES_MULTILINE) &&
4919  (!editor->bWordWrap || editor->nAvailWidth != width))
4920  {
4921  editor->nAvailWidth = width;
4922  editor->bWordWrap = TRUE;
4923  ME_RewrapRepaint(editor);
4924  }
4925  FIXME("EM_SETTARGETDEVICE doesn't use non-NULL target devices\n");
4926  }
4927  return TRUE;
4928  default:
4929  do_default:
4930  *phresult = S_FALSE;
4931  break;
4932  }
4933  return 0L;
4934 }
ME_DIType type
Definition: editstr.h:260
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define EM_LIMITTEXT
Definition: winuser.h:1982
static IClassFactory * cf
void ME_GetSelectionParaFormat(ME_TextEditor *editor, PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN
Definition: para.c:937
#define EM_GETSCROLLPOS
Definition: richedit.h:165
void ME_CharFormatFromLogFont(HDC hDC, const LOGFONTW *lf, CHARFORMAT2W *fmt) DECLSPEC_HIDDEN
Definition: style.c:331
struct mke2fs_defaults settings[]
#define WM_GETTEXTLENGTH
Definition: winuser.h:1601
#define ECO_AUTOVSCROLL
Definition: richedit.h:457
BOOL bHideSelection
Definition: editstr.h:428
#define SB_PAGEDOWN
Definition: winuser.h:569
void ME_InvalidateSelection(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:1317
#define EM_SETLANGOPTIONS
Definition: richedit.h:143
static void ME_SetText(ME_TextEditor *editor, void *text, BOOL unicode)
Definition: editor.c:3483
#define ITextHost_TxInvalidateRect(This, a, b)
Definition: editor.h:293
GLint GLint GLsizei width
Definition: gl.h:1546
#define SB_PAGEUP
Definition: winuser.h:568
#define ITextHost_TxReleaseDC(This, a)
Definition: editor.h:288
IUnknown * reOle
Definition: editstr.h:388
#define max(a, b)
Definition: svc.c:63
CHARRANGE chrg
Definition: richedit.h:586
ME_Paragraph para
Definition: editstr.h:266
#define TRUE
Definition: types.h:120
Definition: comerr.c:44
#define DLGC_WANTCHARS
Definition: winuser.h:2593
static CHANGE * changes
Definition: io.c:49
static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stream, BOOL stripLastCR)
Definition: editor.c:1581
#define DLGC_WANTMESSAGE
Definition: winuser.h:2588
static int ME_FindText(ME_TextEditor *editor, DWORD flags, const CHARRANGE *chrg, const WCHAR *text, CHARRANGE *chrgText)
Definition: editor.c:1852
BOOL AutoURLDetect_bEnable
Definition: editstr.h:429
#define EM_LINELENGTH
Definition: winuser.h:1985
ME_Style * ME_GetInsertStyle(ME_TextEditor *editor, int nCursor) DECLSPEC_HIDDEN
Definition: style.c:476
void ME_CursorFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_Cursor *pCursor) DECLSPEC_HIDDEN
Definition: run.c:171
long y
Definition: polytest.cpp:48
static BOOL paste_special(ME_TextEditor *editor, UINT cf, REPASTESPECIAL *ps, BOOL check_only)
Definition: editor.c:2288
#define WM_GETDLGCODE
Definition: winuser.h:1671
#define WM_CONTEXTMENU
Definition: richedit.h:64
#define WM_CHAR
Definition: winuser.h:1699
#define WM_LBUTTONDOWN
Definition: winuser.h:1758
int nZoomNumerator
Definition: editstr.h:415
#define WM_CUT
Definition: winuser.h:1843
#define WideCharToMultiByte
Definition: compat.h:101
#define ST_KEEPUNDO
Definition: richedit.h:1071
#define INT_MAX
Definition: limits.h:40
#define EM_SETZOOM
Definition: richedit.h:170
DWORD styleFlags
Definition: editstr.h:392
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define EM_SETMARGINS
Definition: winuser.h:1994
#define EM_GETTEXTRANGE
Definition: richedit.h:108
static BOOL ME_KeyDown(ME_TextEditor *editor, WORD nKey)
Definition: editor.c:2610
long x
Definition: polytest.cpp:48
BOOL ME_Undo(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: undo.c:414
#define EM_SETREADONLY
Definition: winuser.h:1997
static BOOL ME_SetCursor(ME_TextEditor *editor)
Definition: editor.c:2893
static int ME_GetTextEx(ME_TextEditor *editor, GETTEXTEX *ex, LPARAM pText)
Definition: editor.c:2084
#define SB_RIGHT
Definition: winuser.h:576
static void ME_UpdateSelectionLinkAttribute(ME_TextEditor *editor)
Definition: editor.c:2406
#define EM_GETEVENTMASK
Definition: richedit.h:92
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
LPWSTR ME_ToUnicode(LONG codepage, LPVOID psz, INT *len) DECLSPEC_HIDDEN
Definition: string.c:214
#define SB_VERT
Definition: winuser.h:553
void ME_ScrollDown(ME_TextEditor *editor, int cy) DECLSPEC_HIDDEN
Definition: paint.c:1121
#define pt(x, y)
Definition: drawing.c:79
static void ME_LinkNotify(ME_TextEditor *editor, UINT msg, WPARAM wParam, LPARAM lParam)
Definition: editor.c:3419
#define ENM_MOUSEEVENTS
Definition: richedit.h:476
#define EM_GETBIDIOPTIONS
Definition: richedit.h:155
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define WM_MOUSEWHEEL
Definition: treelist.c:96
#define CP_ACP
Definition: compat.h:99
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define EM_GETOLEINTERFACE
Definition: richedit.h:93
static char utf8_bom[3]
Definition: file.c:108
void ME_RunOfsFromCharOfs(ME_TextEditor *editor, int nCharOfs, ME_DisplayItem **ppPara, ME_DisplayItem **ppRun, int *pOfs) DECLSPEC_HIDDEN
Definition: run.c:184
char CHAR
Definition: xmlstorage.h:175
#define WM_GETTEXT
Definition: winuser.h:1600
#define SB_HORZ
Definition: winuser.h:552
#define EM_GETIMESTATUS
Definition: winuser.h:1969
JSAMPARRAY JDIMENSION max_lines
Definition: jpeglib.h:1054
#define MAKELPARAM(l, h)
Definition: winuser.h:3983
static LRESULT handle_EM_SETCHARFORMAT(ME_TextEditor *editor, WPARAM flags, const CHARFORMAT2W *fmt_in)
Definition: editor.c:3539
#define ES_MULTILINE
Definition: pedump.c:667
void ME_RewrapRepaint(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:142
static int calc_wheel_change(int *remain, int amount_per_click)
Definition: editor.c:3276
static HDC
Definition: imagelist.c:92
#define ECO_AUTOWORDSELECTION
Definition: richedit.h:456
_In_ DWORD nLength
Definition: wincon.h:461
#define WM_SETREDRAW
Definition: winuser.h:1598
const char * fmt
Definition: wsprintf.c:30
#define EM_SETWORDBREAKPROC
Definition: winuser.h:2002
void ME_ScrollUp(ME_TextEditor *editor, int cy) DECLSPEC_HIDDEN
Definition: paint.c:1116
void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, const WCHAR *str, int len, ME_Style *style)
Definition: caret.c:550
BOOL ME_SetSelectionParaFormat(ME_TextEditor *editor, const PARAFORMAT2 *pFmt) DECLSPEC_HIDDEN
Definition: para.c:907
LONG top
Definition: windef.h:307
static BOOL ME_UpdateLinkAttribute(ME_TextEditor *editor, ME_Cursor *start, int nChars)
Definition: editor.c:5475
ME_Style * ME_GetSelectionInsertStyle(ME_TextEditor *editor)
Definition: caret.c:1548
#define WM_IME_SELECT
Definition: winuser.h:1815
#define EM_EXLIMITTEXT
Definition: richedit.h:86
#define WM_PASTE
Definition: winuser.h:1845
#define assert(x)
Definition: debug.h:53
#define ITextHost_TxSetCapture(This, a)
Definition: editor.h:301
int ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs) DECLSPEC_HIDDEN
Definition: row.c:64
BOOL bDefaultFormatRect
Definition: editstr.h:418
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
LONG cpMax
Definition: richedit.h:501
#define EM_FORMATRANGE
Definition: richedit.h:90
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
BOOL bMouseCaptured
Definition: editstr.h:447
#define EM_SELECTIONTYPE
Definition: richedit.h:99
int ME_GetSelectionOfs(ME_TextEditor *editor, int *from, int *to)
Definition: caret.c:42
void ME_SetSelectionCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN
Definition: run.c:696
#define ITextHost_TxGetSysColor(This, a)
Definition: editor.h:312
UINT_PTR WPARAM
Definition: windef.h:207
#define ES_READONLY
Definition: pedump.c:675
#define ITextHost_TxGetClientRect(This, a)
Definition: editor.h:308
LONG left
Definition: windef.h:306
void ME_HScrollAbs(ME_TextEditor *editor, int x) DECLSPEC_HIDDEN
Definition: paint.c:1106
int ME_PointFromChar(ME_TextEditor *editor, ME_Run *pRun, int nOffset, BOOL visual_order) DECLSPEC_HIDDEN
Definition: run.c:598
int set_selection_cursors(ME_TextEditor *editor, int from, int to)
Definition: caret.c:132
#define EM_SETPALETTE
Definition: richedit.h:127
void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: style.c:523
#define EM_SETPARAFORMAT
Definition: richedit.h:104
#define DLGC_WANTTAB
Definition: winuser.h:2586
BOOL WINAPI GetCursorPos(_Out_ LPPOINT)
Definition: cursoricon.c:2635
ME_Style * style
Definition: editstr.h:164
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_ DWORD _In_ DWORD dwBufLen
Definition: wincrypt.h:4245
#define WM_CLEAR
Definition: winuser.h:1846
LONG right
Definition: windef.h:308
#define BOOL
Definition: nt_native.h:43
void ME_SendRequestResize(ME_TextEditor *editor, BOOL force) DECLSPEC_HIDDEN
Definition: wrap.c:1198
static LONG ME_GetSelectionType(ME_TextEditor *editor)
Definition: editor.c:2993
void ME_LButtonDown(ME_TextEditor *editor, int x, int y, int clickNum)
Definition: caret.c:1159
#define COLOR_WINDOW
Definition: winuser.h:908
#define WM_IME_COMPOSITIONFULL
Definition: winuser.h:1814
#define ENM_KEYEVENTS
Definition: richedit.h:475
#define EM_CANPASTE
Definition: richedit.h:83
#define DLGC_HASSETSEL
Definition: winuser.h:2589
POINTL point
Definition: edittest.c:50
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
LONG y
Definition: windef.h:330
#define EM_GETPARAFORMAT
Definition: richedit.h:94
#define EM_CHARFROMPOS
Definition: richedit.h:78
#define EM_GETSEL
Definition: winuser.h:1979
SCROLLINFO vert_si
Definition: editstr.h:443
#define EM_POSFROMCHAR
Definition: richedit.h:77
#define EM_CANREDO
Definition: richedit.h:118
#define EM_GETPASSWORDCHAR
Definition: winuser.h:1977
#define EM_EXGETSEL
Definition: richedit.h:85
void ME_UpdateRepaint(ME_TextEditor *editor, BOOL update_now) DECLSPEC_HIDDEN
Definition: paint.c:116
#define EM_FINDTEXTEXW
Definition: richedit.h:148
ME_DisplayItem * pFirst
Definition: editstr.h:272
#define ECOOP_SET
Definition: richedit.h:450
#define ECOOP_OR
Definition: richedit.h:451
#define EN_KILLFOCUS
Definition: winuser.h:2007
GLenum GLint GLuint mask
Definition: glext.h:6028
#define EN_SETFOCUS
Definition: winuser.h:2009
#define EM_GETTEXTEX
Definition: richedit.h:128
DWORD flags
Definition: richedit.h:1065
#define CP_UTF8
Definition: nls.h:20
#define WM_COPY
Definition: winuser.h:1844
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define WM_SETCURSOR
Definition: winuser.h:1618
BOOL cf2w_to_cfany(CHARFORMAT2W *to, const CHARFORMAT2W *from) DECLSPEC_HIDDEN
Definition: style.c:79
static LRESULT ME_Char(ME_TextEditor *editor, WPARAM charCode, LPARAM flags, BOOL unicode)
Definition: editor.c:2741
HBRUSH hbrBackground
Definition: editstr.h:402
#define debugstr_w
Definition: kernel32.h:32
LRESULT ME_StreamOut(ME_TextEditor *editor, DWORD dwFormat, EDITSTREAM *stream) DECLSPEC_HIDDEN
Definition: writer.c:1179
LPCSTR lpstrText
Definition: richedit.h:582
#define FIXME(fmt,...)
Definition: debug.h:110
void ME_DestroyEditor(ME_TextEditor *editor)
Definition: editor.c:3190
static BOOL ME_FilterEvent(ME_TextEditor *editor, UINT msg, WPARAM *wParam, LPARAM *lParam)
Definition: editor.c:2386
int codepage
Definition: win_iconv.c:156
#define S_FALSE
Definition: winerror.h:2357
#define EM_SETCHARFORMAT
Definition: richedit.h:101
void ME_VScrollAbs(ME_TextEditor *editor, int y) DECLSPEC_HIDDEN
Definition: paint.c:1111
CHARRANGE chrg
Definition: richedit.h:581
#define MERF_ENDPARA
Definition: editstr.h:126
#define EM_SETUNDOLIMIT
Definition: richedit.h:116
ME_TextBuffer * pBuffer
Definition: editstr.h:390
#define E_INVALIDARG
Definition: ddrawi.h:101
#define ECOOP_AND
Definition: richedit.h:452
const WCHAR * str
#define TM_MULTILEVELUNDO
Definition: richedit.h:1031
#define MAKELONG(a, b)
Definition: typedefs.h:248
#define EM_FINDTEXT
Definition: richedit.h:89
#define EM_GETEDITSTYLE
Definition: richedit.h:161
int ME_CharOfsFromRunOfs(ME_TextEditor *editor, const ME_DisplayItem *pPara, const ME_DisplayItem *pRun, int nOfs) DECLSPEC_HIDDEN
Definition: run.c:156
smooth NULL
Definition: ftsmooth.c:416
void ME_ScrollAbs(ME_TextEditor *editor, int x, int y) DECLSPEC_HIDDEN
Definition: paint.c:1043
void ME_Repaint(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:106
void ME_UpdateScrollBar(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:1148
Definition: editstr.h:91
#define SB_THUMBPOSITION
Definition: winuser.h:572
LPWSTR lpstrText
Definition: richedit.h:515
#define GCS_RESULTSTR
Definition: imm.h:366
#define SYSTEM_FONT
Definition: wingdi.h:910
LONG cx
Definition: windef.h:334
int len
Definition: editstr.h:167
#define WM_KEYDOWN
Definition: winuser.h:1697
static void ME_StreamInRTFString(ME_TextEditor *editor, BOOL selection, char *string)
Definition: editor.c:1837
#define EM_SETBKGNDCOLOR
Definition: richedit.h:100
UINT flags
Definition: winuser.h:3569
const char * LPCSTR
Definition: xmlstorage.h:183
#define EM_SETBIDIOPTIONS
Definition: richedit.h:154
DWORD HIMC
Definition: dimm.idl:75
#define UNSUPPORTED_MSG(e)
Definition: editor.c:3589
#define WM_SETTEXT
Definition: winuser.h:1599
#define EM_SETEVENTMASK
Definition: richedit.h:102
#define ITextHost_TxGetDC(This)
Definition: editor.h:287
#define WM_DESTROY
Definition: winuser.h:1591
#define EM_STREAMIN
Definition: richedit.h:106
void ME_GetDefaultCharFormat(ME_TextEditor *editor, CHARFORMAT2W *pFmt) DECLSPEC_HIDDEN
Definition: run.c:790
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
SHORT WINAPI GetKeyState(_In_ int)
#define STACK_SIZE_MAX
Definition: editor.c:243
#define EM_PASTESPECIAL
Definition: richedit.h:97
ME_DisplayItem * ME_RowStart(ME_DisplayItem *item) DECLSPEC_HIDDEN
Definition: row.c:31
void ME_SetCursorToStart(ME_TextEditor *editor, ME_Cursor *cursor)
Definition: caret.c:27