ReactOS  0.4.14-dev-55-g2da92ac
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)
 
static int handle_EM_EXSETSEL (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)
 
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 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 3538 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 3274 of file editor.c.

3275 {
3276  int change = amount_per_click * (float)*remain / WHEEL_DELTA;
3277  *remain -= WHEEL_DELTA * change / amount_per_click;
3278  return change;
3279 }
#define WHEEL_DELTA
Definition: treelist.c:99

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:301
#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 4924 of file editor.c.

4925 {
4926  ITextHost *host = ME_CreateTextHost( hwnd, create, emulate_10 );
4927  ME_TextEditor *editor;
4928 
4929  if (!host) return FALSE;
4930 
4931  editor = ME_MakeEditor( host, emulate_10 );
4932  if (!editor)
4933  {
4934  ITextHost_Release( host );
4935  return FALSE;
4936  }
4937 
4940  editor->hWnd = hwnd; /* FIXME: Remove editor's dependence on hWnd */
4941  editor->hwndParent = create->hwndParent;
4942 
4943  SetWindowLongPtrW( hwnd, 0, (LONG_PTR)editor );
4944 
4945  return TRUE;
4946 }
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:46
DWORD exStyleFlags
Definition: editstr.h:393
#define SetWindowLongPtrW
Definition: winuser.h:5247
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 3232 of file editor.c.

3233 {
3234  TRACE("\n");
3235  switch (fdwReason)
3236  {
3237  case DLL_PROCESS_ATTACH:
3238  DisableThreadLibraryCalls(hinstDLL);
3239  me_heap = HeapCreate (0, 0x10000, 0);
3240  if (!ME_RegisterEditorClass(hinstDLL)) return FALSE;
3242  LookupInit();
3243  break;
3244 
3245  case DLL_PROCESS_DETACH:
3246  if (lpvReserved) break;
3250  UnregisterClassA("RichEdit50A", 0);
3255  LookupCleanup();
3256  HeapDestroy (me_heap);
3257  release_typelib();
3258  break;
3259  }
3260  return TRUE;
3261 }
#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:155
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:5178

◆ get_default_line_height()

static int get_default_line_height ( ME_TextEditor editor)
inlinestatic

Definition at line 3263 of file editor.c.

3264 {
3265  int height = 0;
3266 
3267  if (editor->pBuffer && editor->pBuffer->pDefaultStyle)
3268  height = editor->pBuffer->pDefaultStyle->tm.tmHeight;
3269  if (height <= 0) height = 24;
3270 
3271  return height;
3272 }
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:2378

Referenced by ME_HandleMessage().

◆ get_msg_name()

static const char* get_msg_name ( UINT  msg)
static

Definition at line 3408 of file editor.c.

3409 {
3410  if (msg >= EM_GETSEL && msg <= EM_CHARFROMPOS)
3411  return edit_messages[msg - EM_GETSEL];
3412  if (msg >= EM_CANPASTE && msg <= EM_GETIMEMODEBIAS)
3413  return richedit_messages[msg - EM_CANPASTE];
3414  return "";
3415 }
#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:3326
#define msg(x)
Definition: auth_time.c:54
static const char *const edit_messages[]
Definition: editor.c:3281

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

◆ handle_EM_EXSETSEL()

static int handle_EM_EXSETSEL ( ME_TextEditor editor,
int  to,
int  from 
)
static

Definition at line 2153 of file editor.c.

2154 {
2155  int end;
2156 
2157  TRACE("%d - %d\n", to, from );
2158 
2159  ME_InvalidateSelection( editor );
2160  end = ME_SetSelection( editor, to, from );
2161  ME_InvalidateSelection( editor );
2162  ITextHost_TxShowCaret( editor->texthost, FALSE );
2163  ME_ShowCaret( editor );
2164  ME_SendSelChange( editor );
2165 
2166  return end;
2167 }
void ME_InvalidateSelection(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: paint.c:1327
void ME_ShowCaret(ME_TextEditor *ed)
Definition: caret.c:285
GLuint GLuint end
Definition: gl.h:1545
int ME_SetSelection(ME_TextEditor *editor, int from, int to)
Definition: caret.c:126
#define ITextHost_TxShowCaret(This, a)
Definition: editor.h:297
#define TRACE(s)
Definition: solgame.cpp:4
void ME_SendSelChange(ME_TextEditor *editor)
Definition: caret.c:1541
ITextHost * texthost
Definition: editstr.h:387
CardRegion * from
Definition: spigame.cpp:19

Referenced by ME_HandleMessage(), and ME_KeyDown().

◆ 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:993
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:457
#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:536
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:521
#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:443
union tagME_DisplayItem::@508 member
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:495
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

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  STGMEDIUM stgm;
1132  FORMATETC fm;
1133  CLSID clsid;
1134  HRESULT hr = E_FAIL;
1135  DWORD conn;
1136 
1137  if (hemf)
1138  {
1139  stgm.tymed = TYMED_ENHMF;
1140  stgm.u.hEnhMetaFile = hemf;
1141  fm.cfFormat = CF_ENHMETAFILE;
1142  }
1143  else if (hbmp)
1144  {
1145  stgm.tymed = TYMED_GDI;
1146  stgm.u.hBitmap = hbmp;
1147  fm.cfFormat = CF_BITMAP;
1148  }
1149  stgm.pUnkForRelease = NULL;
1150 
1151  fm.ptd = NULL;
1152  fm.dwAspect = DVASPECT_CONTENT;
1153  fm.lindex = -1;
1154  fm.tymed = stgm.tymed;
1155 
1156  if (!editor->reOle)
1157  {
1158  if (!CreateIRichEditOle(NULL, editor, (LPVOID *)&editor->reOle))
1159  return hr;
1160  }
1161 
1162  if (OleCreateDefaultHandler(&CLSID_NULL, NULL, &IID_IOleObject, (void**)&lpObject) == S_OK &&
1163  IRichEditOle_GetClientSite(editor->reOle, &lpClientSite) == S_OK &&
1164  IOleObject_SetClientSite(lpObject, lpClientSite) == S_OK &&
1165  IOleObject_GetUserClassID(lpObject, &clsid) == S_OK &&
1166  IOleObject_QueryInterface(lpObject, &IID_IOleCache, (void**)&lpOleCache) == S_OK &&
1167  IOleCache_Cache(lpOleCache, &fm, 0, &conn) == S_OK &&
1168  IOleObject_QueryInterface(lpObject, &IID_IDataObject, (void**)&lpDataObject) == S_OK &&
1169  IDataObject_SetData(lpDataObject, &fm, &stgm, TRUE) == S_OK)
1170  {
1171  REOBJECT reobject;
1172 
1173  reobject.cbStruct = sizeof(reobject);
1174  reobject.cp = REO_CP_SELECTION;
1175  reobject.clsid = clsid;
1176  reobject.poleobj = lpObject;
1177  reobject.pstg = lpStorage;
1178  reobject.polesite = lpClientSite;
1179  /* convert from twips to .01 mm */
1180  reobject.sizel.cx = MulDiv(sz->cx, 254, 144);
1181  reobject.sizel.cy = MulDiv(sz->cy, 254, 144);
1182  reobject.dvaspect = DVASPECT_CONTENT;
1183  reobject.dwFlags = 0; /* FIXME */
1184  reobject.dwUser = 0;
1185 
1186  ME_InsertOLEFromCursor(editor, &reobject, 0);
1187  hr = S_OK;
1188  }
1189 
1190  if (lpObject) IOleObject_Release(lpObject);
1191  if (lpClientSite) IOleClientSite_Release(lpClientSite);
1192  if (lpStorage) IStorage_Release(lpStorage);
1193  if (lpDataObject) IDataObject_Release(lpDataObject);
1194  if (lpOleCache) IOleCache_Release(lpOleCache);
1195 
1196  return hr;
1197 }
interface IStorage * LPSTORAGE
Definition: objfwd.h:30
#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:319
const GUID IID_IOleObject
HBITMAP hbmp
IRichEditOle * reOle
Definition: editstr.h:388
#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:5693
unsigned long DWORD
Definition: ntddk_ex.h:95
REFCLSID clsid
Definition: msctf.c:84
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:487
HRESULT WINAPI OleCreateDefaultHandler(REFCLSID clsid, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj)
LONG cy
Definition: windef.h:320
#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 5293 of file editor.c.

5294 {
5295  /* NB this list is sorted */
5296  static const WCHAR neutral_chars[] = {'!','\"','\'','(',')',',','-','.',':',';','<','>','?','[',']','{','}'};
5297 
5298  /* Some shortcuts */
5299  if (isalnum( c )) return FALSE;
5300  if (c > neutral_chars[ARRAY_SIZE( neutral_chars ) - 1]) return FALSE;
5301 
5302  return !!bsearch( &c, neutral_chars, ARRAY_SIZE( neutral_chars ), sizeof(c), wchar_comp );
5303 }
_Check_return_ _CRTIMP int __cdecl isalnum(_In_ int _C)
static int wchar_comp(const void *key, const void *elem)
Definition: editor.c:5286
__wchar_t WCHAR
Definition: xmlstorage.h:180
const GLubyte * c
Definition: glext.h:8905
#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:2935
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:93
#define WM_RBUTTONDOWN
Definition: winuser.h:1761
static UINT WPARAM wParam
Definition: editor.c:2851
#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:2851
#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:457
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:536
BOOL bMouseCaptured
Definition: editstr.h:445
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:304
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:443
union tagME_DisplayItem::@508 member
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:898
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:1521
#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

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:898
#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 3188 of file editor.c.

3189 {
3190  ME_DisplayItem *p = editor->pBuffer->pFirst, *pNext = NULL;
3191  ME_Style *s, *cursor2;
3192  int i;
3193 
3194  ME_ClearTempStyle(editor);
3195  ME_EmptyUndoStack(editor);
3196  editor->pBuffer->pFirst = NULL;
3197  while(p) {
3198  pNext = p->next;
3199  if (p->type == diParagraph)
3200  destroy_para(editor, p);
3201  else
3203  p = pNext;
3204  }
3205 
3206  LIST_FOR_EACH_ENTRY_SAFE( s, cursor2, &editor->style_list, ME_Style, entry )
3207  ME_DestroyStyle( s );
3208 
3210  for (i=0; i<HFONT_CACHE_SIZE; i++)
3211  {
3212  if (editor->pFontCache[i].hFont)
3213  DeleteObject(editor->pFontCache[i].hFont);
3214  }
3215  if (editor->rgbBackColor != -1)
3216  DeleteObject(editor->hbrBackground);
3217  if(editor->lpOleCallback)
3218  IRichEditOleCallback_Release(editor->lpOleCallback);
3219  ITextHost_Release(editor->texthost);
3220  if (editor->reOle)
3221  {
3222  IRichEditOle_Release(editor->reOle);
3223  editor->reOle = NULL;
3224  }
3225  OleUninitialize();
3226 
3227  heap_free(editor->pBuffer);
3228  heap_free(editor->pCursors);
3229  heap_free(editor);
3230 }
struct list style_list
Definition: editstr.h:447
void ME_DestroyStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:423
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
void ME_ClearTempStyle(ME_TextEditor *editor) DECLSPEC_HIDDEN
Definition: style.c:504
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
IRichEditOle * reOle
Definition: editstr.h:388
void ME_ReleaseStyle(ME_Style *item) DECLSPEC_HIDDEN
Definition: style.c:443
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:233
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:3133
UINT_PTR idFrom
Definition: winuser.h:3132
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:2851
HWND hwndFrom
Definition: winuser.h:3131
UINT msg
Definition: richedit.h:641
static UINT WPARAM LPARAM lParam
Definition: editor.c:2851
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 5312 of file editor.c.

5317 {
5318  ME_Cursor cursor = *start, neutral_end, space_end;
5319  BOOL candidateStarted = FALSE, quoted = FALSE;
5320  WCHAR c;
5321 
5322  while (nChars > 0)
5323  {
5324  WCHAR *str = get_text( &cursor.pRun->member.run, 0 );
5325  int run_len = cursor.pRun->member.run.len;
5326 
5327  nChars -= run_len - cursor.nOffset;
5328 
5329  /* Find start of candidate */
5330  if (!candidateStarted)
5331  {
5332  while (cursor.nOffset < run_len)
5333  {
5334  c = str[cursor.nOffset];
5335  if (!isspaceW( c ) && !isurlneutral( c ))
5336  {
5337  *candidate_min = cursor;
5338  candidateStarted = TRUE;
5339  neutral_end.pPara = NULL;
5340  space_end.pPara = NULL;
5341  cursor.nOffset++;
5342  break;
5343  }
5344  quoted = (c == '<');
5345  cursor.nOffset++;
5346  }
5347  }
5348 
5349  /* Find end of candidate */
5350  if (candidateStarted)
5351  {
5352  while (cursor.nOffset < run_len)
5353  {
5354  c = str[cursor.nOffset];
5355  if (isspaceW( c ))
5356  {
5357  if (quoted && c != '\r')
5358  {
5359  if (!space_end.pPara)
5360  {
5361  if (neutral_end.pPara)
5362  space_end = neutral_end;
5363  else
5364  space_end = cursor;
5365  }
5366  }
5367  else
5368  goto done;
5369  }
5370  else if (isurlneutral( c ))
5371  {
5372  if (quoted && c == '>')
5373  {
5374  neutral_end.pPara = NULL;
5375  space_end.pPara = NULL;
5376  goto done;
5377  }
5378  if (!neutral_end.pPara)
5379  neutral_end = cursor;
5380  }
5381  else
5382  neutral_end.pPara = NULL;
5383 
5384  cursor.nOffset++;
5385  }
5386  }
5387 
5388  cursor.nOffset = 0;
5389  if (!ME_NextRun(&cursor.pPara, &cursor.pRun, TRUE))
5390  goto done;
5391  }
5392 
5393 done:
5394  if (candidateStarted)
5395  {
5396  if (space_end.pPara)
5397  *candidate_max = space_end;
5398  else if (neutral_end.pPara)
5399  *candidate_max = neutral_end;
5400  else
5401  *candidate_max = cursor;
5402  return TRUE;
5403  }
5404  *candidate_max = *candidate_min = cursor;
5405  return FALSE;
5406 }
#define TRUE
Definition: types.h:120
BOOL ME_NextRun(ME_DisplayItem **para, ME_DisplayItem **run, BOOL all_para) DECLSPEC_HIDDEN
Definition: list.c:71
WINE_UNICODE_INLINE int isspaceW(WCHAR wc)
Definition: unicode.h:165
static BOOL isurlneutral(WCHAR c)
Definition: editor.c:5293
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
static WCHAR * get_text(const ME_Run *run, int offset)
Definition: editor.h:42
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 1851 of file editor.c.

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

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 2083 of file editor.c.

2084 {
2085  int nChars;
2086  ME_Cursor start;
2087 
2088  if (!ex->cb || !pText) return 0;
2089 
2090  if (ex->flags & ~(GT_SELECTION | GT_USECRLF))
2091  FIXME("GETTEXTEX flags 0x%08x not supported\n", ex->flags & ~(GT_SELECTION | GT_USECRLF));
2092 
2093  if (ex->flags & GT_SELECTION)
2094  {
2095  int from, to;
2096  int nStartCur = ME_GetSelectionOfs(editor, &from, &to);
2097  start = editor->pCursors[nStartCur];
2098  nChars = to - from;
2099  }
2100  else
2101  {
2102  ME_SetCursorToStart(editor, &start);
2103  nChars = INT_MAX;
2104  }
2105  if (ex->codepage == CP_UNICODE)
2106  {
2107  return ME_GetTextW(editor, (LPWSTR)pText, ex->cb / sizeof(WCHAR) - 1,
2108  &start, nChars, ex->flags & GT_USECRLF, FALSE);
2109  }
2110  else
2111  {
2112  /* potentially each char may be a CR, why calculate the exact value with O(N) when
2113  we can just take a bigger buffer? :)
2114  The above assumption still holds with CR/LF counters, since CR->CRLF expansion
2115  occurs only in richedit 2.0 mode, in which line breaks have only one CR
2116  */
2117  int crlfmul = (ex->flags & GT_USECRLF) ? 2 : 1;
2118  DWORD buflen;
2119  LPWSTR buffer;
2120  LRESULT rc;
2121 
2122  buflen = min(crlfmul * nChars, ex->cb - 1);
2123  buffer = heap_alloc((buflen + 1) * sizeof(WCHAR));
2124 
2125  nChars = ME_GetTextW(editor, buffer, buflen, &start, nChars, ex->flags & GT_USECRLF, FALSE);
2126  rc = WideCharToMultiByte(ex->codepage, 0, buffer, nChars + 1,
2127  (LPSTR)pText, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
2128  if (rc) rc--; /* do not count 0 terminator */
2129 
2130  heap_free(buffer);
2131  return rc;
2132  }
2133 }
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:5117
#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:81
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 2135 of file editor.c.

2137 {
2138  if (!strText) return 0;
2139  if (unicode) {
2140  return ME_GetTextW(editor, strText, INT_MAX, start, nLen, FALSE, FALSE);
2141  } else {
2142  int nChars;
2143  WCHAR *p = heap_alloc((nLen+1) * sizeof(*p));
2144  if (!p) return 0;
2145  nChars = ME_GetTextW(editor, p, nLen, start, nLen, FALSE, FALSE);
2146  WideCharToMultiByte(CP_ACP, 0, p, nChars+1, (char *)strText,
2147  nLen+1, NULL, NULL);
2148  heap_free(p);
2149  return nChars;
2150  }
2151 }
#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:5117
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 5117 of file editor.c.

5120 {
5121  ME_DisplayItem *pRun, *pNextRun;
5122  const WCHAR *pStart = buffer;
5123  const WCHAR cr_lf[] = {'\r', '\n', 0};
5124  const WCHAR *str;
5125  int nLen;
5126 
5127  /* bCRLF flag is only honored in 2.0 and up. 1.0 must always return text verbatim */
5128  if (editor->bEmulateVersion10) bCRLF = FALSE;
5129 
5130  pRun = start->pRun;
5131  assert(pRun);
5132  pNextRun = ME_FindItemFwd(pRun, diRun);
5133 
5134  nLen = pRun->member.run.len - start->nOffset;
5135  str = get_text( &pRun->member.run, start->nOffset );
5136 
5137  while (srcChars && buflen && pNextRun)
5138  {
5139  int nFlags = pRun->member.run.nFlags;
5140 
5141  if (bCRLF && nFlags & MERF_ENDPARA && ~nFlags & MERF_ENDCELL)
5142  {
5143  if (buflen == 1) break;
5144  /* FIXME: native fails to reduce srcChars here for WM_GETTEXT or
5145  * EM_GETTEXTEX, however, this is done for copying text which
5146  * also uses this function. */
5147  srcChars -= min(nLen, srcChars);
5148  nLen = 2;
5149  str = cr_lf;
5150  } else {
5151  nLen = min(nLen, srcChars);
5152  srcChars -= nLen;
5153  }
5154 
5155  nLen = min(nLen, buflen);
5156  buflen -= nLen;
5157 
5158  CopyMemory(buffer, str, sizeof(WCHAR) * nLen);
5159 
5160  buffer += nLen;
5161 
5162  pRun = pNextRun;
5163  pNextRun = ME_FindItemFwd(pRun, diRun);
5164 
5165  nLen = pRun->member.run.len;
5166  str = get_text( &pRun->member.run, 0 );
5167  }
5168  /* append '\r' to the last paragraph. */
5169  if (pRun->next->type == diTextEnd && bEOP)
5170  {
5171  *buffer = '\r';
5172  buffer ++;
5173  }
5174  *buffer = 0;
5175  return buffer - pStart;
5176 }
#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:1633
union tagME_DisplayItem::@508 member
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:42
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

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 3549 of file editor.c.

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