summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-11-18 17:27:24 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-11-18 17:27:24 +0000
commit4491b4f5a8964a02784744de83902e1ca93013f7 (patch)
tree64aedc13d3c87c6d03b4ee54f7c876c67f28134c
parent730d5d09fc38c5c92cc5f862c043e604448dc929 (diff)
fix for red subscripts in Spell Checker
git-svn-id: http://svn.miranda-ng.org/main/trunk@11013 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/msapi/richedit5.h1628
-rw-r--r--plugins/SpellChecker/src/commons.h3
-rw-r--r--plugins/SpellChecker/src/utils.cpp3189
3 files changed, 3222 insertions, 1598 deletions
diff --git a/include/msapi/richedit5.h b/include/msapi/richedit5.h
new file mode 100644
index 0000000000..af75057c86
--- /dev/null
+++ b/include/msapi/richedit5.h
@@ -0,0 +1,1628 @@
+/*
+ * RICHEDIT.H
+ *
+ * Purpose:
+ * RICHEDIT v2.0-v6.0 public definitions
+ *
+ * Copyright (c) Microsoft Corporation. All rights reserved.
+ */
+
+#ifndef _RICHEDIT_
+#define _RICHEDIT_
+#pragma once
+#include <wtypes.h>
+#include <objbase.h>
+
+
+#ifdef _WIN32
+#include <pshpack4.h>
+#elif !defined(RC_INVOKED)
+#pragma pack(4)
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+// To mimic older RichEdit behavior, set _RICHEDIT_VER to appropriate value
+// Version 1.0 0x0100
+// Version 2.0 0x0200
+// Version 2.1 0x0210
+#ifndef _RICHEDIT_VER
+#define _RICHEDIT_VER 0x0800
+#endif
+
+#define cchTextLimitDefault 32767
+
+#define MSFTEDIT_CLASS L"RICHEDIT50W"
+// NOTE: MSFTEDIT.DLL only registers MSFTEDIT_CLASS. If an application wants
+// to use the following RichEdit classes, it needs to load riched20.dll.
+// Otherwise, CreateWindow with RICHEDIT_CLASS will fail.
+// This also applies to any dialog that uses RICHEDIT_CLASS
+// RichEdit 2.0 Window Class
+
+// On Windows CE, avoid possible conflicts on Win95
+#define CERICHEDIT_CLASSA "RichEditCEA"
+#define CERICHEDIT_CLASSW L"RichEditCEW"
+
+#define RICHEDIT_CLASSA "RichEdit20A"
+#define RICHEDIT_CLASS10A "RICHEDIT" // Richedit 1.0
+
+#ifndef MACPORT
+#define RICHEDIT_CLASSW L"RichEdit20W"
+#else //----------------------MACPORT
+#define RICHEDIT_CLASSW TEXT("RichEdit20W") // MACPORT change
+#endif // MACPORT
+
+#if (_RICHEDIT_VER >= 0x0200 )
+#ifdef UNICODE
+#define RICHEDIT_CLASS RICHEDIT_CLASSW
+#else
+#define RICHEDIT_CLASS RICHEDIT_CLASSA
+#endif // UNICODE
+#else
+#define RICHEDIT_CLASS RICHEDIT_CLASS10A
+#endif // _RICHEDIT_VER >= 0x0200
+
+// RichEdit messages
+
+#ifndef WM_CONTEXTMENU
+#define WM_CONTEXTMENU 0x007B
+#endif
+
+#ifndef WM_UNICHAR
+#define WM_UNICHAR 0x0109
+#endif
+
+#ifndef WM_PRINTCLIENT
+#define WM_PRINTCLIENT 0x0318
+#endif
+
+#ifndef EM_GETLIMITTEXT
+#define EM_GETLIMITTEXT (WM_USER + 37)
+#endif
+
+#ifndef EM_POSFROMCHAR
+#define EM_POSFROMCHAR (WM_USER + 38)
+#define EM_CHARFROMPOS (WM_USER + 39)
+#endif
+
+#ifndef EM_SCROLLCARET
+#define EM_SCROLLCARET (WM_USER + 49)
+#endif
+#define EM_CANPASTE (WM_USER + 50)
+#define EM_DISPLAYBAND (WM_USER + 51)
+#define EM_EXGETSEL (WM_USER + 52)
+#define EM_EXLIMITTEXT (WM_USER + 53)
+#define EM_EXLINEFROMCHAR (WM_USER + 54)
+#define EM_EXSETSEL (WM_USER + 55)
+#define EM_FINDTEXT (WM_USER + 56)
+#define EM_FORMATRANGE (WM_USER + 57)
+#define EM_GETCHARFORMAT (WM_USER + 58)
+#define EM_GETEVENTMASK (WM_USER + 59)
+#define EM_GETOLEINTERFACE (WM_USER + 60)
+#define EM_GETPARAFORMAT (WM_USER + 61)
+#define EM_GETSELTEXT (WM_USER + 62)
+#define EM_HIDESELECTION (WM_USER + 63)
+#define EM_PASTESPECIAL (WM_USER + 64)
+#define EM_REQUESTRESIZE (WM_USER + 65)
+#define EM_SELECTIONTYPE (WM_USER + 66)
+#define EM_SETBKGNDCOLOR (WM_USER + 67)
+#define EM_SETCHARFORMAT (WM_USER + 68)
+#define EM_SETEVENTMASK (WM_USER + 69)
+#define EM_SETOLECALLBACK (WM_USER + 70)
+#define EM_SETPARAFORMAT (WM_USER + 71)
+#define EM_SETTARGETDEVICE (WM_USER + 72)
+#define EM_STREAMIN (WM_USER + 73)
+#define EM_STREAMOUT (WM_USER + 74)
+#define EM_GETTEXTRANGE (WM_USER + 75)
+#define EM_FINDWORDBREAK (WM_USER + 76)
+#define EM_SETOPTIONS (WM_USER + 77)
+#define EM_GETOPTIONS (WM_USER + 78)
+#define EM_FINDTEXTEX (WM_USER + 79)
+#ifdef _WIN32
+#define EM_GETWORDBREAKPROCEX (WM_USER + 80)
+#define EM_SETWORDBREAKPROCEX (WM_USER + 81)
+#endif
+
+// RichEdit 2.0 messages
+#define EM_SETUNDOLIMIT (WM_USER + 82)
+#define EM_REDO (WM_USER + 84)
+#define EM_CANREDO (WM_USER + 85)
+#define EM_GETUNDONAME (WM_USER + 86)
+#define EM_GETREDONAME (WM_USER + 87)
+#define EM_STOPGROUPTYPING (WM_USER + 88)
+
+#define EM_SETTEXTMODE (WM_USER + 89)
+#define EM_GETTEXTMODE (WM_USER + 90)
+
+// enum for use with EM_GET/SETTEXTMODE
+typedef enum tagTextMode
+{
+ TM_PLAINTEXT = 1,
+ TM_RICHTEXT = 2, // Default behavior
+ TM_SINGLELEVELUNDO = 4,
+ TM_MULTILEVELUNDO = 8, // Default behavior
+ TM_SINGLECODEPAGE = 16,
+ TM_MULTICODEPAGE = 32 // Default behavior
+} TEXTMODE;
+
+#define EM_AUTOURLDETECT (WM_USER + 91)
+
+#if (_RICHEDIT_VER >= 0x0800)
+#define AURL_ENABLEURL 1
+#define AURL_ENABLEEMAILADDR 2
+#define AURL_ENABLETELNO 4
+#define AURL_ENABLEEAURLS 8
+#define AURL_ENABLEDRIVELETTERS 16
+#define AURL_DISABLEMIXEDLGC 32 // Disable mixed Latin Greek Cyrillic IDNs
+#endif
+
+#define EM_GETAUTOURLDETECT (WM_USER + 92)
+#define EM_SETPALETTE (WM_USER + 93)
+#define EM_GETTEXTEX (WM_USER + 94)
+#define EM_GETTEXTLENGTHEX (WM_USER + 95)
+#define EM_SHOWSCROLLBAR (WM_USER + 96)
+#define EM_SETTEXTEX (WM_USER + 97)
+
+// East Asia specific messages
+#define EM_SETPUNCTUATION (WM_USER + 100)
+#define EM_GETPUNCTUATION (WM_USER + 101)
+#define EM_SETWORDWRAPMODE (WM_USER + 102)
+#define EM_GETWORDWRAPMODE (WM_USER + 103)
+#define EM_SETIMECOLOR (WM_USER + 104)
+#define EM_GETIMECOLOR (WM_USER + 105)
+#define EM_SETIMEOPTIONS (WM_USER + 106)
+#define EM_GETIMEOPTIONS (WM_USER + 107)
+#define EM_CONVPOSITION (WM_USER + 108)
+
+#define EM_SETLANGOPTIONS (WM_USER + 120)
+#define EM_GETLANGOPTIONS (WM_USER + 121)
+#define EM_GETIMECOMPMODE (WM_USER + 122)
+
+#define EM_FINDTEXTW (WM_USER + 123)
+#define EM_FINDTEXTEXW (WM_USER + 124)
+
+// RE3.0 FE messages
+#define EM_RECONVERSION (WM_USER + 125)
+#define EM_SETIMEMODEBIAS (WM_USER + 126)
+#define EM_GETIMEMODEBIAS (WM_USER + 127)
+
+// BiDi specific messages
+#define EM_SETBIDIOPTIONS (WM_USER + 200)
+#define EM_GETBIDIOPTIONS (WM_USER + 201)
+
+#define EM_SETTYPOGRAPHYOPTIONS (WM_USER + 202)
+#define EM_GETTYPOGRAPHYOPTIONS (WM_USER + 203)
+
+// Extended edit style specific messages
+#define EM_SETEDITSTYLE (WM_USER + 204)
+#define EM_GETEDITSTYLE (WM_USER + 205)
+
+// Extended edit style masks
+#define SES_EMULATESYSEDIT 1
+#define SES_BEEPONMAXTEXT 2
+#define SES_EXTENDBACKCOLOR 4
+#define SES_MAPCPS 8 // Obsolete (never used)
+#if (_RICHEDIT_VER >= 0x0500)
+#define SES_HYPERLINKTOOLTIPS 8
+#endif
+#define SES_EMULATE10 16 // Obsolete (never used)
+#if (_RICHEDIT_VER >= 0x0700)
+#define SES_DEFAULTLATINLIGA 16
+#endif
+#define SES_USECRLF 32 // Obsolete (never used)
+#define SES_USEAIMM 64
+#define SES_NOIME 128
+
+#define SES_ALLOWBEEPS 256
+#define SES_UPPERCASE 512
+#define SES_LOWERCASE 1024
+#define SES_NOINPUTSEQUENCECHK 2048
+#define SES_BIDI 4096
+#define SES_SCROLLONKILLFOCUS 8192
+#define SES_XLTCRCRLFTOCR 16384
+#define SES_DRAFTMODE 32768
+
+#define SES_USECTF 0x00010000
+#define SES_HIDEGRIDLINES 0x00020000
+#define SES_USEATFONT 0x00040000
+#define SES_CUSTOMLOOK 0x00080000
+#define SES_LBSCROLLNOTIFY 0x00100000
+#define SES_CTFALLOWEMBED 0x00200000
+#define SES_CTFALLOWSMARTTAG 0x00400000
+#define SES_CTFALLOWPROOFING 0x00800000
+#if (_RICHEDIT_VER >= 0x0500)
+#define SES_LOGICALCARET 0x01000000
+#define SES_WORDDRAGDROP 0x02000000
+#define SES_SMARTDRAGDROP 0x04000000
+#define SES_MULTISELECT 0x08000000
+#define SES_CTFNOLOCK 0x10000000
+#define SES_NOEALINEHEIGHTADJUST 0x20000000
+#define SES_MAX 0x20000000
+#endif
+
+// Options for EM_SETLANGOPTIONS and EM_GETLANGOPTIONS
+#define IMF_AUTOKEYBOARD 0x0001
+#define IMF_AUTOFONT 0x0002
+#define IMF_IMECANCELCOMPLETE 0x0004 // High completes comp string when aborting, low cancels
+#define IMF_IMEALWAYSSENDNOTIFY 0x0008
+#define IMF_AUTOFONTSIZEADJUST 0x0010
+#define IMF_UIFONTS 0x0020
+#if (_RICHEDIT_VER >= 0x0800)
+#define IMF_NOIMPLICITLANG 0x0040
+#endif
+#define IMF_DUALFONT 0x0080
+#if (_RICHEDIT_VER >= 0x0800)
+#define IMF_NOKBDLIDFIXUP 0x0200
+#endif
+#define IMF_NORTFFONTSUBSTITUTE 0x0400
+#if (_RICHEDIT_VER >= 0x0800)
+#define IMF_SPELLCHECKING 0x0800
+#define IMF_TKBPREDICTION 0x1000
+#endif
+
+// Values for EM_GETIMECOMPMODE
+#define ICM_NOTOPEN 0x0000
+#define ICM_LEVEL3 0x0001
+#define ICM_LEVEL2 0x0002
+#define ICM_LEVEL2_5 0x0003
+#define ICM_LEVEL2_SUI 0x0004
+#define ICM_CTF 0x0005
+
+// Options for EM_SETTYPOGRAPHYOPTIONS
+#define TO_ADVANCEDTYPOGRAPHY 0x0001
+#define TO_SIMPLELINEBREAK 0x0002
+#define TO_DISABLECUSTOMTEXTOUT 0x0004
+#define TO_ADVANCEDLAYOUT 0x0008
+
+// Pegasus outline mode messages (RE 3.0)
+
+// Outline mode message
+#define EM_OUTLINE (WM_USER + 220)
+// Message for getting and restoring scroll pos
+#define EM_GETSCROLLPOS (WM_USER + 221)
+#define EM_SETSCROLLPOS (WM_USER + 222)
+// Change fontsize in current selection by wParam
+#define EM_SETFONTSIZE (WM_USER + 223)
+#define EM_GETZOOM (WM_USER + 224)
+#define EM_SETZOOM (WM_USER + 225)
+#define EM_GETVIEWKIND (WM_USER + 226)
+#define EM_SETVIEWKIND (WM_USER + 227)
+
+// RichEdit 4.0 messages
+#define EM_GETPAGE (WM_USER + 228)
+#define EM_SETPAGE (WM_USER + 229)
+#define EM_GETHYPHENATEINFO (WM_USER + 230)
+#define EM_SETHYPHENATEINFO (WM_USER + 231)
+
+#define EM_GETPAGEROTATE (WM_USER + 235)
+#define EM_SETPAGEROTATE (WM_USER + 236)
+#define EM_GETCTFMODEBIAS (WM_USER + 237)
+#define EM_SETCTFMODEBIAS (WM_USER + 238)
+#define EM_GETCTFOPENSTATUS (WM_USER + 240)
+#define EM_SETCTFOPENSTATUS (WM_USER + 241)
+#define EM_GETIMECOMPTEXT (WM_USER + 242)
+#define EM_ISIME (WM_USER + 243)
+#define EM_GETIMEPROPERTY (WM_USER + 244)
+
+// These messages control what rich edit does when it comes accross
+// OLE objects during RTF stream in. Normally rich edit queries the client
+// application only after OleLoad has been called. With these messages it is possible to
+// set the rich edit control to a mode where it will query the client application before
+// OleLoad is called
+#define EM_GETQUERYRTFOBJ (WM_USER + 269)
+#define EM_SETQUERYRTFOBJ (WM_USER + 270)
+
+// EM_SETPAGEROTATE wparam values
+#define EPR_0 0 // Text flows left to right and top to bottom
+#define EPR_270 1 // Text flows top to bottom and right to left
+#define EPR_180 2 // Text flows right to left and bottom to top
+#define EPR_90 3 // Text flows bottom to top and left to right
+#if (_RICHEDIT_VER >= 0x0800)
+#define EPR_SE 5 // Text flows top to bottom and left to right (Mongolian text layout)
+#endif
+
+
+// EM_SETCTFMODEBIAS wparam values
+#define CTFMODEBIAS_DEFAULT 0x0000
+#define CTFMODEBIAS_FILENAME 0x0001
+#define CTFMODEBIAS_NAME 0x0002
+#define CTFMODEBIAS_READING 0x0003
+#define CTFMODEBIAS_DATETIME 0x0004
+#define CTFMODEBIAS_CONVERSATION 0x0005
+#define CTFMODEBIAS_NUMERIC 0x0006
+#define CTFMODEBIAS_HIRAGANA 0x0007
+#define CTFMODEBIAS_KATAKANA 0x0008
+#define CTFMODEBIAS_HANGUL 0x0009
+#define CTFMODEBIAS_HALFWIDTHKATAKANA 0x000A
+#define CTFMODEBIAS_FULLWIDTHALPHANUMERIC 0x000B
+#define CTFMODEBIAS_HALFWIDTHALPHANUMERIC 0x000C
+
+// EM_SETIMEMODEBIAS lparam values
+#define IMF_SMODE_PLAURALCLAUSE 0x0001
+#define IMF_SMODE_NONE 0x0002
+
+// EM_GETIMECOMPTEXT wparam structure
+typedef struct _imecomptext {
+ LONG cb; // count of bytes in the output buffer.
+ DWORD flags; // value specifying the composition string type.
+ // Currently only support ICT_RESULTREADSTR
+} IMECOMPTEXT;
+#define ICT_RESULTREADSTR 1
+
+// Outline mode wparam values
+#define EMO_EXIT 0 // Enter normal mode, lparam ignored
+#define EMO_ENTER 1 // Enter outline mode, lparam ignored
+#define EMO_PROMOTE 2 // LOWORD(lparam) == 0 ==>
+ // promote to body-text
+ // LOWORD(lparam) != 0 ==>
+ // promote/demote current selection
+ // by indicated number of levels
+#define EMO_EXPAND 3 // HIWORD(lparam) = EMO_EXPANDSELECTION
+ // -> expands selection to level
+ // indicated in LOWORD(lparam)
+ // LOWORD(lparam) = -1/+1 corresponds
+ // to collapse/expand button presses
+ // in winword (other values are
+ // equivalent to having pressed these
+ // buttons more than once)
+ // HIWORD(lparam) = EMO_EXPANDDOCUMENT
+ // -> expands whole document to
+ // indicated level
+#define EMO_MOVESELECTION 4 // LOWORD(lparam) != 0 -> move current
+ // selection up/down by indicated amount
+#define EMO_GETVIEWMODE 5 // Returns VM_NORMAL or VM_OUTLINE
+
+// EMO_EXPAND options
+#define EMO_EXPANDSELECTION 0
+#define EMO_EXPANDDOCUMENT 1
+
+#define VM_NORMAL 4 // Agrees with RTF \viewkindN
+#define VM_OUTLINE 2
+#define VM_PAGE 9 // Screen page view (not print layout)
+
+/// New messages as of Win8
+#if (_RICHEDIT_VER >= 0x0800)
+
+#define EM_INSERTTABLE (WM_USER + 232)
+
+#pragma warning(push)
+#pragma warning(disable:4214) // Microsoft extension -- Bitfield not int
+
+// Data type defining table rows for EM_INSERTTABLE
+typedef struct _tableRowParms
+{ // EM_INSERTTABLE wparam is a (TABLEROWPARMS *)
+ BYTE cbRow; // Count of bytes in this structure
+ BYTE cbCell; // Count of bytes in TABLECELLPARMS
+ BYTE cCell; // Count of cells
+ BYTE cRow; // Count of rows
+ LONG dxCellMargin; // Cell left/right margin (\trgaph)
+ LONG dxIndent; // Row left (right if fRTL indent (similar to \trleft)
+ LONG dyHeight; // Row height (\trrh)
+ DWORD nAlignment:3; // Row alignment (like PARAFORMAT::bAlignment, \trql, trqr, \trqc)
+ DWORD fRTL:1; // Display cells in RTL order (\rtlrow)
+ DWORD fKeep:1; // Keep row together (\trkeep}
+ DWORD fKeepFollow:1; // Keep row on same page as following row (\trkeepfollow)
+ DWORD fWrap:1; // Wrap text to right/left (depending on bAlignment)
+ // (see \tdfrmtxtLeftN, \tdfrmtxtRightN)
+ DWORD fIdentCells:1; // lparam points at single struct valid for all cells
+ LONG cpStartRow; // cp where to insert table (-1 for selection cp)
+ // (can be used for either TRD by EM_GETTABLEPARMS)
+ BYTE bTableLevel; // Table nesting level (EM_GETTABLEPARMS only)
+ BYTE iCell; // Index of cell to insert/delete (EM_SETTABLEPARMS only)
+} TABLEROWPARMS;
+
+// Data type defining table cells for EM_INSERTTABLE
+typedef struct _tableCellParms
+{ // EM_INSERTTABLE lparam is a (TABLECELLPARMS *)
+ LONG dxWidth; // Cell width (\cellx)
+ WORD nVertAlign:2; // Vertical alignment (0/1/2 = top/center/bottom
+ // \clvertalt (def), \clvertalc, \clvertalb)
+ WORD fMergeTop:1; // Top cell for vertical merge (\clvmgf)
+ WORD fMergePrev:1; // Merge with cell above (\clvmrg)
+ WORD fVertical:1; // Display text top to bottom, right to left (\cltxtbrlv)
+ WORD fMergeStart:1; // Start set of horizontally merged cells (\clmgf)
+ WORD fMergeCont:1; // Merge with previous cell (\clmrg)
+ WORD wShading; // Shading in .01% (\clshdng) e.g., 10000 flips fore/back
+
+ SHORT dxBrdrLeft; // Left border width (\clbrdrl\brdrwN) (in twips)
+ SHORT dyBrdrTop; // Top border width (\clbrdrt\brdrwN)
+ SHORT dxBrdrRight; // Right border width (\clbrdrr\brdrwN)
+ SHORT dyBrdrBottom; // Bottom border width (\clbrdrb\brdrwN)
+ COLORREF crBrdrLeft; // Left border color (\clbrdrl\brdrcf)
+ COLORREF crBrdrTop; // Top border color (\clbrdrt\brdrcf)
+ COLORREF crBrdrRight; // Right border color (\clbrdrr\brdrcf)
+ COLORREF crBrdrBottom; // Bottom border color (\clbrdrb\brdrcf)
+ COLORREF crBackPat; // Background color (\clcbpat)
+ COLORREF crForePat; // Foreground color (\clcfpat)
+} TABLECELLPARMS;
+
+#pragma warning(pop)
+
+#define EM_GETAUTOCORRECTPROC (WM_USER + 233)
+#define EM_SETAUTOCORRECTPROC (WM_USER + 234)
+#define EM_CALLAUTOCORRECTPROC (WM_USER + 255)
+
+// AutoCorrect callback
+typedef int (WINAPI *AutoCorrectProc)(LANGID langid, const WCHAR *pszBefore, WCHAR *pszAfter, LONG cchAfter, LONG *pcchReplaced);
+
+#define ATP_NOCHANGE 0
+#define ATP_CHANGE 1
+#define ATP_NODELIMITER 2
+#define ATP_REPLACEALLTEXT 4
+
+#define EM_GETTABLEPARMS (WM_USER + 265)
+
+#define EM_SETEDITSTYLEEX (WM_USER + 275)
+#define EM_GETEDITSTYLEEX (WM_USER + 276)
+// wparam values for EM_SETEDITSTYLEEX/EM_GETEDITSTYLEEX
+// All unused bits are reserved.
+#define SES_EX_NOTABLE 0x00000004
+#define SES_EX_HANDLEFRIENDLYURL 0x00000100
+#define SES_EX_NOTHEMING 0x00080000
+#define SES_EX_NOACETATESELECTION 0x00100000
+#define SES_EX_USESINGLELINE 0x00200000
+#define SES_EX_MULTITOUCH 0x08000000 // Only works under Win8+
+#define SES_EX_HIDETEMPFORMAT 0x10000000
+#define SES_EX_USEMOUSEWPARAM 0x20000000 // Use wParam when handling WM_MOUSEMOVE message and do not call GetAsyncKeyState
+
+#define EM_GETSTORYTYPE (WM_USER + 290)
+#define EM_SETSTORYTYPE (WM_USER + 291)
+
+#define EM_GETELLIPSISMODE (WM_USER + 305)
+#define EM_SETELLIPSISMODE (WM_USER + 306)
+
+// DWORD: *lparam for EM_GETELLIPSISMODE, lparam for EM_SETELLIPSISMODE
+#define ELLIPSIS_MASK 0x00000003 // all meaningful bits
+#define ELLIPSIS_NONE 0x00000000 // ellipsis disabled
+#define ELLIPSIS_END 0x00000001 // ellipsis at the end (forced break)
+#define ELLIPSIS_WORD 0x00000003 // ellipsis at the end (word break)
+
+#define EM_SETTABLEPARMS (WM_USER + 307)
+
+#define EM_GETTOUCHOPTIONS (WM_USER + 310)
+#define EM_SETTOUCHOPTIONS (WM_USER + 311)
+#define EM_INSERTIMAGE (WM_USER + 314)
+#define EM_SETUIANAME (WM_USER + 320)
+#define EM_GETELLIPSISSTATE (WM_USER + 322)
+
+
+// Values for EM_SETTOUCHOPTIONS/EM_GETTOUCHOPTIONS
+#define RTO_SHOWHANDLES 1
+#define RTO_DISABLEHANDLES 2
+#define RTO_READINGMODE 3
+
+// lparam for EM_INSERTIMAGE
+typedef struct tagRICHEDIT_IMAGE_PARAMETERS
+{
+ LONG xWidth; // Units are HIMETRIC
+ LONG yHeight; // Units are HIMETRIC
+ LONG Ascent; // Units are HIMETRIC
+ LONG Type; // Valid values are TA_TOP, TA_BOTTOM and TA_BASELINE
+ LPCWSTR pwszAlternateText;
+ IStream * pIStream;
+} RICHEDIT_IMAGE_PARAMETERS;
+
+#endif
+
+// New notifications
+#define EN_MSGFILTER 0x0700
+#define EN_REQUESTRESIZE 0x0701
+#define EN_SELCHANGE 0x0702
+#define EN_DROPFILES 0x0703
+#define EN_PROTECTED 0x0704
+#define EN_CORRECTTEXT 0x0705 // PenWin specific
+#define EN_STOPNOUNDO 0x0706
+#define EN_IMECHANGE 0x0707 // East Asia specific
+#define EN_SAVECLIPBOARD 0x0708
+#define EN_OLEOPFAILED 0x0709
+#define EN_OBJECTPOSITIONS 0x070a
+#define EN_LINK 0x070b
+#define EN_DRAGDROPDONE 0x070c
+#define EN_PARAGRAPHEXPANDED 0x070d
+#define EN_PAGECHANGE 0x070e
+#define EN_LOWFIRTF 0x070f
+#define EN_ALIGNLTR 0x0710 // BiDi specific notification
+#define EN_ALIGNRTL 0x0711 // BiDi specific notification
+#if (_RICHEDIT_VER >= 0x0800)
+#define EN_CLIPFORMAT 0x0712
+#define EN_STARTCOMPOSITION 0x0713
+#define EN_ENDCOMPOSITION 0x0714
+
+// Notification structure for EN_ENDCOMPOSITION
+typedef struct _endcomposition
+{
+ NMHDR nmhdr;
+ DWORD dwCode;
+} ENDCOMPOSITIONNOTIFY;
+
+// Constants for ENDCOMPOSITIONNOTIFY dwCode
+#define ECN_ENDCOMPOSITION 0x0001
+#define ECN_NEWTEXT 0x0002
+#endif
+
+// Event notification masks
+#define ENM_NONE 0x00000000
+#define ENM_CHANGE 0x00000001
+#define ENM_UPDATE 0x00000002
+#define ENM_SCROLL 0x00000004
+#define ENM_SCROLLEVENTS 0x00000008
+#define ENM_DRAGDROPDONE 0x00000010
+#define ENM_PARAGRAPHEXPANDED 0x00000020
+#define ENM_PAGECHANGE 0x00000040
+#if (_RICHEDIT_VER >= 0x0800)
+#define ENM_CLIPFORMAT 0x00000080
+#endif
+#define ENM_KEYEVENTS 0x00010000
+#define ENM_MOUSEEVENTS 0x00020000
+#define ENM_REQUESTRESIZE 0x00040000
+#define ENM_SELCHANGE 0x00080000
+#define ENM_DROPFILES 0x00100000
+#define ENM_PROTECTED 0x00200000
+#define ENM_CORRECTTEXT 0x00400000 // PenWin specific
+#define ENM_IMECHANGE 0x00800000 // Used by RE1.0 compatibility
+#define ENM_LANGCHANGE 0x01000000
+#define ENM_OBJECTPOSITIONS 0x02000000
+#define ENM_LINK 0x04000000
+#define ENM_LOWFIRTF 0x08000000
+#if (_RICHEDIT_VER >= 0x0800)
+#define ENM_STARTCOMPOSITION 0x10000000
+#define ENM_ENDCOMPOSITION 0x20000000
+#define ENM_GROUPTYPINGCHANGE 0x40000000
+#define ENM_HIDELINKTOOLTIP 0x80000000
+#endif
+
+// New edit control styles
+#define ES_SAVESEL 0x00008000
+#define ES_SUNKEN 0x00004000
+#define ES_DISABLENOSCROLL 0x00002000
+// Same as WS_MAXIMIZE, but that doesn't make sense so we re-use the value
+#define ES_SELECTIONBAR 0x01000000
+// Same as ES_UPPERCASE, but re-used to completely disable OLE drag'n'drop
+#define ES_NOOLEDRAGDROP 0x00000008
+
+// Obsolete Edit Style
+#define ES_EX_NOCALLOLEINIT 0x00000000 // Not supported in RE 2.0/3.0
+
+// These flags are used in FE Windows
+#define ES_VERTICAL 0x00400000 // Not supported in RE 2.0/3.0
+#define ES_NOIME 0x00080000
+#define ES_SELFIME 0x00040000
+
+// Edit control options
+#define ECO_AUTOWORDSELECTION 0x00000001
+#define ECO_AUTOVSCROLL 0x00000040
+#define ECO_AUTOHSCROLL 0x00000080
+#define ECO_NOHIDESEL 0x00000100
+#define ECO_READONLY 0x00000800
+#define ECO_WANTRETURN 0x00001000
+#define ECO_SAVESEL 0x00008000
+#define ECO_SELECTIONBAR 0x01000000
+#define ECO_VERTICAL 0x00400000 // FE specific
+
+
+// ECO operations
+#define ECOOP_SET 0x0001
+#define ECOOP_OR 0x0002
+#define ECOOP_AND 0x0003
+#define ECOOP_XOR 0x0004
+
+// New word break function actions
+#define WB_CLASSIFY 3
+#define WB_MOVEWORDLEFT 4
+#define WB_MOVEWORDRIGHT 5
+#define WB_LEFTBREAK 6
+#define WB_RIGHTBREAK 7
+
+// East Asia specific flags
+#define WB_MOVEWORDPREV 4
+#define WB_MOVEWORDNEXT 5
+#define WB_PREVBREAK 6
+#define WB_NEXTBREAK 7
+
+#define PC_FOLLOWING 1
+#define PC_LEADING 2
+#define PC_OVERFLOW 3
+#define PC_DELIMITER 4
+#define WBF_WORDWRAP 0x010
+#define WBF_WORDBREAK 0x020
+#define WBF_OVERFLOW 0x040
+#define WBF_LEVEL1 0x080
+#define WBF_LEVEL2 0x100
+#define WBF_CUSTOM 0x200
+
+// East Asia specific flags
+#define IMF_FORCENONE 0x0001
+#define IMF_FORCEENABLE 0x0002
+#define IMF_FORCEDISABLE 0x0004
+#define IMF_CLOSESTATUSWINDOW 0x0008
+#define IMF_VERTICAL 0x0020
+#define IMF_FORCEACTIVE 0x0040
+#define IMF_FORCEINACTIVE 0x0080
+#define IMF_FORCEREMEMBER 0x0100
+#define IMF_MULTIPLEEDIT 0x0400
+
+// Word break flags (used with WB_CLASSIFY)
+#define WBF_CLASS ((BYTE) 0x0F)
+#define WBF_ISWHITE ((BYTE) 0x10)
+#define WBF_BREAKLINE ((BYTE) 0x20)
+#define WBF_BREAKAFTER ((BYTE) 0x40)
+
+// Data types
+
+#ifdef _WIN32
+// Extended edit word break proc (character set aware)
+typedef LONG (*EDITWORDBREAKPROCEX)(char *pchText, LONG cchText, BYTE bCharSet, INT action);
+#endif
+
+// All character format measurements are in twips
+typedef struct _charformat
+{
+ UINT cbSize;
+ DWORD dwMask;
+ DWORD dwEffects;
+ LONG yHeight;
+ LONG yOffset;
+ COLORREF crTextColor;
+ BYTE bCharSet;
+ BYTE bPitchAndFamily;
+ char szFaceName[LF_FACESIZE];
+} CHARFORMATA;
+
+typedef struct _charformatw
+{
+ UINT cbSize;
+ DWORD dwMask;
+ DWORD dwEffects;
+ LONG yHeight;
+ LONG yOffset;
+ COLORREF crTextColor;
+ BYTE bCharSet;
+ BYTE bPitchAndFamily;
+ WCHAR szFaceName[LF_FACESIZE];
+} CHARFORMATW;
+
+#if (_RICHEDIT_VER >= 0x0200)
+#ifdef UNICODE
+#define CHARFORMAT CHARFORMATW
+#else
+#define CHARFORMAT CHARFORMATA
+#endif // UNICODE
+#else
+#define CHARFORMAT CHARFORMATA
+#endif // _RICHEDIT_VER >= 0x0200
+
+// CHARFORMAT2 structure
+
+#if defined(__cplusplus)
+
+struct CHARFORMAT2W : _charformatw
+{
+ WORD wWeight; // Font weight (LOGFONT value)
+ SHORT sSpacing; // Amount to space between letters
+ COLORREF crBackColor; // Background color
+ LCID lcid; // Locale ID
+#if (_RICHEDIT_VER >= 0x0500)
+ union
+ {
+ DWORD dwReserved; // Name up to 5.0
+ DWORD dwCookie; // Client cookie opaque to RichEdit
+ };
+#else
+ DWORD dwReserved; // Name up to 5.0
+#endif
+ SHORT sStyle; // Style handle
+ WORD wKerning; // Twip size above which to kern char pair
+ BYTE bUnderlineType; // Underline type
+ BYTE bAnimation; // Animated text like marching ants
+ BYTE bRevAuthor; // Revision author index
+#if (_RICHEDIT_VER >= 0x0800)
+ BYTE bUnderlineColor; // Underline color
+#endif
+};
+
+struct CHARFORMAT2A : _charformat
+{
+ WORD wWeight; // Font weight (LOGFONT value)
+ SHORT sSpacing; // Amount to space between letters
+ COLORREF crBackColor; // Background color
+ LCID lcid; // Locale ID
+#if (_RICHEDIT_VER >= 0x0500)
+ union
+ {
+ DWORD dwReserved; // Name up to 5.0
+ DWORD dwCookie; // Client cookie opaque to RichEdit
+ };
+#else
+ DWORD dwReserved; // Name up to 5.0
+#endif
+ SHORT sStyle; // Style handle
+ WORD wKerning; // Twip size above which to kern char pair
+ BYTE bUnderlineType; // Underline type
+ BYTE bAnimation; // Animated text like marching ants
+ BYTE bRevAuthor; // Revision author index
+#if (_RICHEDIT_VER >= 0x0800)
+ BYTE bUnderlineColor; // Underline color
+#endif
+};
+
+#else // regular C-style
+
+typedef struct _charformat2w
+{
+ UINT cbSize;
+ DWORD dwMask;
+ DWORD dwEffects;
+ LONG yHeight;
+ LONG yOffset; // > 0 for superscript, < 0 for subscript
+ COLORREF crTextColor;
+ BYTE bCharSet;
+ BYTE bPitchAndFamily;
+ WCHAR szFaceName[LF_FACESIZE];
+ WORD wWeight; // Font weight (LOGFONT value)
+ SHORT sSpacing; // Amount to space between letters
+ COLORREF crBackColor; // Background color
+ LCID lcid; // Locale ID
+#if (_RICHEDIT_VER >= 0x0500)
+ union
+ {
+ DWORD dwReserved; // Name up to 5.0
+ DWORD dwCookie; // Client cookie opaque to RichEdit
+ };
+#else
+ DWORD dwReserved; // Name up to 5.0
+#endif
+ SHORT sStyle; // Style handle
+ WORD wKerning; // Twip size above which to kern char pair
+ BYTE bUnderlineType; // Underline type
+ BYTE bAnimation; // Animated text like marching ants
+ BYTE bRevAuthor; // Revision author index
+#if (_RICHEDIT_VER >= 0x0800)
+ BYTE bUnderlineColor; // Underline color
+#endif
+} CHARFORMAT2W;
+
+typedef struct _charformat2a
+{
+ UINT cbSize;
+ DWORD dwMask;
+ DWORD dwEffects;
+ LONG yHeight;
+ LONG yOffset; // > 0 for superscript, < 0 for subscript
+ COLORREF crTextColor;
+ BYTE bCharSet;
+ BYTE bPitchAndFamily;
+ char szFaceName[LF_FACESIZE];
+ WORD wWeight; // Font weight (LOGFONT value)
+ SHORT sSpacing; // Amount to space between letters
+ COLORREF crBackColor; // Background color
+ LCID lcid; // Locale ID
+#if (_RICHEDIT_VER >= 0x0500)
+ union
+ {
+ DWORD dwReserved; // Name up to 5.0
+ DWORD dwCookie; // Client cookie opaque to RichEdit
+ };
+#else
+ DWORD dwReserved; // Name up to 5.0
+#endif
+ SHORT sStyle; // Style handle
+ WORD wKerning; // Twip size above which to kern char pair
+ BYTE bUnderlineType; // Underline type
+ BYTE bAnimation; // Animated text like marching ants
+ BYTE bRevAuthor; // Revision author index
+#if (_RICHEDIT_VER >= 0x0800)
+ BYTE bUnderlineColor; // Underline color
+#endif
+} CHARFORMAT2A;
+
+#endif // C++
+
+#ifdef UNICODE
+#define CHARFORMAT2 CHARFORMAT2W
+#else
+#define CHARFORMAT2 CHARFORMAT2A
+#endif
+
+#define CHARFORMATDELTA (sizeof(CHARFORMAT2) - sizeof(CHARFORMAT))
+
+
+// CFM_COLOR mirrors CFE_AUTOCOLOR, a little hack to easily deal with autocolor
+
+// CHARFORMAT masks
+#define CFM_BOLD 0x00000001
+#define CFM_ITALIC 0x00000002
+#define CFM_UNDERLINE 0x00000004
+#define CFM_STRIKEOUT 0x00000008
+#define CFM_PROTECTED 0x00000010
+#define CFM_LINK 0x00000020 // Exchange hyperlink extension
+#define CFM_SIZE 0x80000000
+#define CFM_COLOR 0x40000000
+#define CFM_FACE 0x20000000
+#define CFM_OFFSET 0x10000000
+#define CFM_CHARSET 0x08000000
+
+// CHARFORMAT effects
+#define CFE_BOLD 0x00000001
+#define CFE_ITALIC 0x00000002
+#define CFE_UNDERLINE 0x00000004
+#define CFE_STRIKEOUT 0x00000008
+#define CFE_PROTECTED 0x00000010
+#define CFE_LINK 0x00000020
+#define CFE_AUTOCOLOR 0x40000000 // NOTE: this corresponds to
+ // CFM_COLOR, which controls it
+// Masks and effects defined for CHARFORMAT2 -- an (*) indicates
+// that the data is stored by RichEdit 2.0/3.0, but not displayed
+#define CFM_SMALLCAPS 0x00000040 // (*)
+#define CFM_ALLCAPS 0x00000080 // Displayed by 3.0
+#define CFM_HIDDEN 0x00000100 // Hidden by 3.0
+#define CFM_OUTLINE 0x00000200 // (*)
+#define CFM_SHADOW 0x00000400 // (*)
+#define CFM_EMBOSS 0x00000800 // (*)
+#define CFM_IMPRINT 0x00001000 // (*)
+#define CFM_DISABLED 0x00002000
+#define CFM_REVISED 0x00004000
+
+#define CFM_REVAUTHOR 0x00008000
+#define CFE_SUBSCRIPT 0x00010000 // Superscript and subscript are
+#define CFE_SUPERSCRIPT 0x00020000 // mutually exclusive
+#define CFM_ANIMATION 0x00040000 // (*)
+#define CFM_STYLE 0x00080000 // (*)
+#define CFM_KERNING 0x00100000
+#define CFM_SPACING 0x00200000 // Displayed by 3.0
+#define CFM_WEIGHT 0x00400000
+#define CFM_UNDERLINETYPE 0x00800000 // Many displayed by 3.0
+#if (_RICHEDIT_VER >= 0x0600)
+#define CFM_COOKIE 0x01000000 // RE 6.0
+#endif
+#define CFM_LCID 0x02000000
+#define CFM_BACKCOLOR 0x04000000 // Higher mask bits defined above
+
+#define CFM_SUBSCRIPT (CFE_SUBSCRIPT | CFE_SUPERSCRIPT)
+#define CFM_SUPERSCRIPT CFM_SUBSCRIPT
+
+// CHARFORMAT "ALL" masks
+#define CFM_EFFECTS (CFM_BOLD | CFM_ITALIC | CFM_UNDERLINE | CFM_COLOR | \
+ CFM_STRIKEOUT | CFE_PROTECTED | CFM_LINK)
+#define CFM_ALL (CFM_EFFECTS | CFM_SIZE | CFM_FACE | CFM_OFFSET | CFM_CHARSET)
+
+#define CFM_EFFECTS2 (CFM_EFFECTS | CFM_DISABLED | CFM_SMALLCAPS | CFM_ALLCAPS \
+ | CFM_HIDDEN | CFM_OUTLINE | CFM_SHADOW | CFM_EMBOSS \
+ | CFM_IMPRINT | CFM_REVISED \
+ | CFM_SUBSCRIPT | CFM_SUPERSCRIPT | CFM_BACKCOLOR)
+
+#if (_RICHEDIT_VER >= 0x0600)
+#define CFM_ALL2 (CFM_ALL | CFM_EFFECTS2 | CFM_BACKCOLOR | CFM_LCID \
+ | CFM_UNDERLINETYPE | CFM_WEIGHT | CFM_REVAUTHOR \
+ | CFM_SPACING | CFM_KERNING | CFM_STYLE | CFM_ANIMATION \
+ | CFM_COOKIE)
+#else
+#define CFM_ALL2 (CFM_ALL | CFM_EFFECTS2 | CFM_BACKCOLOR | CFM_LCID \
+ | CFM_UNDERLINETYPE | CFM_WEIGHT | CFM_REVAUTHOR \
+ | CFM_SPACING | CFM_KERNING | CFM_STYLE | CFM_ANIMATION)
+#endif
+
+#define CFE_SMALLCAPS CFM_SMALLCAPS
+#define CFE_ALLCAPS CFM_ALLCAPS
+#define CFE_HIDDEN CFM_HIDDEN
+#define CFE_OUTLINE CFM_OUTLINE
+#define CFE_SHADOW CFM_SHADOW
+#define CFE_EMBOSS CFM_EMBOSS
+#define CFE_IMPRINT CFM_IMPRINT
+#define CFE_DISABLED CFM_DISABLED
+#define CFE_REVISED CFM_REVISED
+
+// CFE_AUTOCOLOR and CFE_AUTOBACKCOLOR correspond to CFM_COLOR and
+// CFM_BACKCOLOR, respectively, which control them
+#define CFE_AUTOBACKCOLOR CFM_BACKCOLOR
+
+#define CFM_FONTBOUND 0x00100000
+#define CFM_LINKPROTECTED 0x00800000 // Word hyperlink field
+#define CFM_EXTENDED 0x02000000
+#define CFM_MATHNOBUILDUP 0x08000000
+#define CFM_MATH 0x10000000
+#define CFM_MATHORDINARY 0x20000000
+
+#define CFM_ALLEFFECTS (CFM_EFFECTS2 | CFM_FONTBOUND | CFM_EXTENDED | CFM_MATHNOBUILDUP | CFM_MATH | CFM_MATHORDINARY)
+
+#define CFE_FONTBOUND 0x00100000 // Font chosen by binder, not user
+#define CFE_LINKPROTECTED 0x00800000
+#define CFE_EXTENDED 0x02000000
+#define CFE_MATHNOBUILDUP 0x08000000
+#define CFE_MATH 0x10000000
+#define CFE_MATHORDINARY 0x20000000
+
+// Underline types. RE 1.0 displays only CFU_UNDERLINE
+#define CFU_CF1UNDERLINE 0xFF // Map charformat's bit underline to CF2
+#define CFU_INVERT 0xFE // For IME composition fake a selection
+#define CFU_UNDERLINETHICKLONGDASH 18 // (*) display as dash
+#define CFU_UNDERLINETHICKDOTTED 17 // (*) display as dot
+#define CFU_UNDERLINETHICKDASHDOTDOT 16 // (*) display as dash dot dot
+#define CFU_UNDERLINETHICKDASHDOT 15 // (*) display as dash dot
+#define CFU_UNDERLINETHICKDASH 14 // (*) display as dash
+#define CFU_UNDERLINELONGDASH 13 // (*) display as dash
+#define CFU_UNDERLINEHEAVYWAVE 12 // (*) display as wave
+#define CFU_UNDERLINEDOUBLEWAVE 11 // (*) display as wave
+#define CFU_UNDERLINEHAIRLINE 10 // (*) display as single
+#define CFU_UNDERLINETHICK 9
+#define CFU_UNDERLINEWAVE 8
+#define CFU_UNDERLINEDASHDOTDOT 7
+#define CFU_UNDERLINEDASHDOT 6
+#define CFU_UNDERLINEDASH 5
+#define CFU_UNDERLINEDOTTED 4
+#define CFU_UNDERLINEDOUBLE 3 // (*) display as single
+#define CFU_UNDERLINEWORD 2 // (*) display as single
+#define CFU_UNDERLINE 1
+#define CFU_UNDERLINENONE 0
+
+#define yHeightCharPtsMost 1638
+
+// EM_SETCHARFORMAT wParam masks
+#define SCF_SELECTION 0x0001
+#define SCF_WORD 0x0002
+#define SCF_DEFAULT 0x0000 // Set default charformat or paraformat
+#define SCF_ALL 0x0004 // Not valid with SCF_SELECTION or SCF_WORD
+#define SCF_USEUIRULES 0x0008 // Modifier for SCF_SELECTION; says that
+ // format came from a toolbar, etc., and
+ // hence UI formatting rules should be
+ // used instead of literal formatting
+#define SCF_ASSOCIATEFONT 0x0010 // Associate fontname with bCharSet (one
+ // possible for each of Western, ME, FE,
+ // Thai)
+#define SCF_NOKBUPDATE 0x0020 // Do not update KB layout for this change
+ // even if autokeyboard is on
+#define SCF_ASSOCIATEFONT2 0x0040 // Associate plane-2 (surrogate) font
+#if (_RICHEDIT_VER >= 0x0500)
+#define SCF_SMARTFONT 0x0080 // Apply font only if it can handle script (5.0)
+#define SCF_CHARREPFROMLCID 0x0100 // Get character repertoire from lcid (5.0)
+
+#define SPF_DONTSETDEFAULT 0x0002 // Suppress setting default on empty control
+#define SPF_SETDEFAULT 0x0004 // Set the default paraformat
+#endif
+
+typedef struct _charrange
+{
+ LONG cpMin;
+ LONG cpMax;
+} CHARRANGE;
+
+typedef struct _textrange
+{
+ CHARRANGE chrg;
+ LPSTR lpstrText; // Allocated by caller, zero terminated by RichEdit
+} TEXTRANGEA;
+
+typedef struct _textrangew
+{
+ CHARRANGE chrg;
+ LPWSTR lpstrText; // Allocated by caller, zero terminated by RichEdit
+} TEXTRANGEW;
+
+#if (_RICHEDIT_VER >= 0x0200)
+#ifdef UNICODE
+#define TEXTRANGE TEXTRANGEW
+#else
+#define TEXTRANGE TEXTRANGEA
+#endif // UNICODE
+#else
+#define TEXTRANGE TEXTRANGEA
+#endif // _RICHEDIT_VER >= 0x0200
+
+typedef DWORD (CALLBACK *EDITSTREAMCALLBACK)(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb);
+
+typedef struct _editstream
+{
+ DWORD_PTR dwCookie; // User value passed to callback as first parameter
+ DWORD dwError; // Last error
+ EDITSTREAMCALLBACK pfnCallback;
+} EDITSTREAM;
+
+// Stream formats. Flags are all in low word, since high word
+// gives possible codepage choice.
+#define SF_TEXT 0x0001
+#define SF_RTF 0x0002
+#define SF_RTFNOOBJS 0x0003 // Write only
+#define SF_TEXTIZED 0x0004 // Write only
+
+#define SF_UNICODE 0x0010 // Unicode file (UCS2 little endian)
+#define SF_USECODEPAGE 0x0020 // CodePage given by high word
+#define SF_NCRFORNONASCII 0x40 // Output \uN for nonASCII
+#define SFF_WRITEXTRAPAR 0x80 // Output \par at end
+
+// Flag telling stream operations to operate on selection only
+// EM_STREAMIN replaces current selection
+// EM_STREAMOUT streams out current selection
+#define SFF_SELECTION 0x8000
+
+// Flag telling stream operations to ignore some FE control words
+// having to do with FE word breaking and horiz vs vertical text.
+// Not used in RichEdit 2.0 and later
+#define SFF_PLAINRTF 0x4000
+
+// Flag telling file stream output (SFF_SELECTION flag not set) to persist
+// \viewscaleN control word.
+#define SFF_PERSISTVIEWSCALE 0x2000
+
+// Flag telling file stream input with SFF_SELECTION flag not set not to
+// close the document
+#define SFF_KEEPDOCINFO 0x1000
+
+// Flag telling stream operations to output in Pocket Word format
+#define SFF_PWD 0x0800
+
+// 3-bit field specifying the value of N - 1 to use for \rtfN or \pwdN
+#define SF_RTFVAL 0x0700
+
+typedef struct _findtext
+{
+ CHARRANGE chrg;
+ LPCSTR lpstrText;
+} FINDTEXTA;
+
+typedef struct _findtextw
+{
+ CHARRANGE chrg;
+ LPCWSTR lpstrText;
+} FINDTEXTW;
+
+#if (_RICHEDIT_VER >= 0x0200)
+#ifdef UNICODE
+#define FINDTEXT FINDTEXTW
+#else
+#define FINDTEXT FINDTEXTA
+#endif // UNICODE
+#else
+#define FINDTEXT FINDTEXTA
+#endif // _RICHEDIT_VER >= 0x0200
+
+typedef struct _findtextexa
+{
+ CHARRANGE chrg;
+ LPCSTR lpstrText;
+ CHARRANGE chrgText;
+} FINDTEXTEXA;
+
+typedef struct _findtextexw
+{
+ CHARRANGE chrg;
+ LPCWSTR lpstrText;
+ CHARRANGE chrgText;
+} FINDTEXTEXW;
+
+#if (_RICHEDIT_VER >= 0x0200)
+#ifdef UNICODE
+#define FINDTEXTEX FINDTEXTEXW
+#else
+#define FINDTEXTEX FINDTEXTEXA
+#endif // UNICODE
+#else
+#define FINDTEXTEX FINDTEXTEXA
+#endif // _RICHEDIT_VER >= 0x0200
+
+
+typedef struct _formatrange
+{
+ HDC hdc;
+ HDC hdcTarget;
+ RECT rc;
+ RECT rcPage;
+ CHARRANGE chrg;
+} FORMATRANGE;
+
+// All paragraph measurements are in twips
+
+#define MAX_TAB_STOPS 32
+#define lDefaultTab 720
+#define MAX_TABLE_CELLS 63
+
+typedef struct _paraformat
+{
+ UINT cbSize;
+ DWORD dwMask;
+ WORD wNumbering;
+ union
+ {
+ WORD wReserved;
+ WORD wEffects;
+ };
+ LONG dxStartIndent;
+ LONG dxRightIndent;
+ LONG dxOffset;
+ WORD wAlignment;
+ SHORT cTabCount;
+ LONG rgxTabs[MAX_TAB_STOPS];
+} PARAFORMAT;
+
+#ifdef __cplusplus
+struct PARAFORMAT2 : _paraformat
+{
+ LONG dySpaceBefore; // Vertical spacing before para
+ LONG dySpaceAfter; // Vertical spacing after para
+ LONG dyLineSpacing; // Line spacing depending on Rule
+ SHORT sStyle; // Style handle
+ BYTE bLineSpacingRule; // Rule for line spacing (see tom.doc)
+ BYTE bOutlineLevel; // Outline level
+ WORD wShadingWeight; // Shading in hundredths of a per cent
+ WORD wShadingStyle; // Nibble 0: style, 1: cfpat, 2: cbpat
+ WORD wNumberingStart; // Starting value for numbering
+ WORD wNumberingStyle; // Alignment, roman/arabic, (), ), ., etc.
+ WORD wNumberingTab; // Space bet FirstIndent & 1st-line text
+ WORD wBorderSpace; // Border-text spaces (nbl/bdr in pts)
+ WORD wBorderWidth; // Pen widths (nbl/bdr in half pts)
+ WORD wBorders; // Border styles (nibble/border)
+};
+
+#else // Regular C-style
+
+typedef struct _paraformat2
+{
+ UINT cbSize;
+ DWORD dwMask;
+ WORD wNumbering;
+ union
+ {
+ WORD wReserved;
+ WORD wEffects;
+ };
+ LONG dxStartIndent;
+ LONG dxRightIndent;
+ LONG dxOffset;
+ WORD wAlignment;
+ SHORT cTabCount;
+ LONG rgxTabs[MAX_TAB_STOPS];
+ LONG dySpaceBefore; // Vertical spacing before para
+ LONG dySpaceAfter; // Vertical spacing after para
+ LONG dyLineSpacing; // Line spacing depending on Rule
+ SHORT sStyle; // Style handle
+ BYTE bLineSpacingRule; // Rule for line spacing (see tom.doc)
+ BYTE bOutlineLevel; // Outline Level
+ WORD wShadingWeight; // Shading in hundredths of a per cent
+ WORD wShadingStyle; // Byte 0: style, nib 2: cfpat, 3: cbpat
+ WORD wNumberingStart; // Starting value for numbering
+ WORD wNumberingStyle; // Alignment, Roman/Arabic, (), ), ., etc.
+ WORD wNumberingTab; // Space bet 1st indent and 1st-line text
+ WORD wBorderSpace; // Border-text spaces (nbl/bdr in pts)
+ WORD wBorderWidth; // Pen widths (nbl/bdr in half twips)
+ WORD wBorders; // Border styles (nibble/border)
+} PARAFORMAT2;
+
+#endif // C++
+
+// PARAFORMAT mask values
+#define PFM_STARTINDENT 0x00000001
+#define PFM_RIGHTINDENT 0x00000002
+#define PFM_OFFSET 0x00000004
+#define PFM_ALIGNMENT 0x00000008
+#define PFM_TABSTOPS 0x00000010
+#define PFM_NUMBERING 0x00000020
+#define PFM_OFFSETINDENT 0x80000000
+
+// PARAFORMAT 2.0 masks and effects
+#define PFM_SPACEBEFORE 0x00000040
+#define PFM_SPACEAFTER 0x00000080
+#define PFM_LINESPACING 0x00000100
+#define PFM_STYLE 0x00000400
+#define PFM_BORDER 0x00000800 // (*)
+#define PFM_SHADING 0x00001000 // (*)
+#define PFM_NUMBERINGSTYLE 0x00002000 // RE 3.0
+#define PFM_NUMBERINGTAB 0x00004000 // RE 3.0
+#define PFM_NUMBERINGSTART 0x00008000 // RE 3.0
+
+#define PFM_RTLPARA 0x00010000
+#define PFM_KEEP 0x00020000 // (*)
+#define PFM_KEEPNEXT 0x00040000 // (*)
+#define PFM_PAGEBREAKBEFORE 0x00080000 // (*)
+#define PFM_NOLINENUMBER 0x00100000 // (*)
+#define PFM_NOWIDOWCONTROL 0x00200000 // (*)
+#define PFM_DONOTHYPHEN 0x00400000 // (*)
+#define PFM_SIDEBYSIDE 0x00800000 // (*)
+// The following three properties are read only
+#define PFM_COLLAPSED 0x01000000 // RE 3.0
+#define PFM_OUTLINELEVEL 0x02000000 // RE 3.0
+#define PFM_BOX 0x04000000 // RE 3.0
+#define PFM_RESERVED2 0x08000000 // RE 4.0
+#define PFM_TABLEROWDELIMITER 0x10000000 // RE 4.0
+#define PFM_TEXTWRAPPINGBREAK 0x20000000 // RE 3.0
+#define PFM_TABLE 0x40000000 // RE 3.0
+
+// PARAFORMAT "ALL" masks
+#define PFM_ALL (PFM_STARTINDENT | PFM_RIGHTINDENT | PFM_OFFSET | \
+ PFM_ALIGNMENT | PFM_TABSTOPS | PFM_NUMBERING | \
+ PFM_OFFSETINDENT| PFM_RTLPARA)
+
+// Note: PARAFORMAT has no effects (BiDi RichEdit 1.0 does have PFE_RTLPARA)
+#define PFM_EFFECTS (PFM_RTLPARA | PFM_KEEP | PFM_KEEPNEXT | PFM_TABLE \
+ | PFM_PAGEBREAKBEFORE | PFM_NOLINENUMBER \
+ | PFM_NOWIDOWCONTROL | PFM_DONOTHYPHEN | PFM_SIDEBYSIDE \
+ | PFM_TABLE | PFM_TABLEROWDELIMITER)
+
+#define PFM_ALL2 (PFM_ALL | PFM_EFFECTS | PFM_SPACEBEFORE | PFM_SPACEAFTER \
+ | PFM_LINESPACING | PFM_STYLE | PFM_SHADING | PFM_BORDER \
+ | PFM_NUMBERINGTAB | PFM_NUMBERINGSTART | PFM_NUMBERINGSTYLE)
+
+#define PFE_RTLPARA (PFM_RTLPARA >> 16)
+#define PFE_KEEP (PFM_KEEP >> 16) // (*)
+#define PFE_KEEPNEXT (PFM_KEEPNEXT >> 16) // (*)
+#define PFE_PAGEBREAKBEFORE (PFM_PAGEBREAKBEFORE >> 16) // (*)
+#define PFE_NOLINENUMBER (PFM_NOLINENUMBER >> 16) // (*)
+#define PFE_NOWIDOWCONTROL (PFM_NOWIDOWCONTROL >> 16) // (*)
+#define PFE_DONOTHYPHEN (PFM_DONOTHYPHEN >> 16) // (*)
+#define PFE_SIDEBYSIDE (PFM_SIDEBYSIDE >> 16) // (*)
+
+#define PFE_TEXTWRAPPINGBREAK (PFM_TEXTWRAPPINGBREAK>>16) // (*)
+
+// The following four effects are read only
+#define PFE_COLLAPSED (PFM_COLLAPSED >> 16) // (+)
+#define PFE_BOX (PFM_BOX >> 16) // (+)
+#define PFE_TABLE (PFM_TABLE >> 16) // Inside table row. RE 3.0
+#define PFE_TABLEROWDELIMITER (PFM_TABLEROWDELIMITER>>16) // Table row start. RE 4.0
+
+// PARAFORMAT numbering options
+#define PFN_BULLET 1 // tomListBullet
+
+// PARAFORMAT2 wNumbering options
+#define PFN_ARABIC 2 // tomListNumberAsArabic: 0, 1, 2, ...
+#define PFN_LCLETTER 3 // tomListNumberAsLCLetter: a, b, c, ...
+#define PFN_UCLETTER 4 // tomListNumberAsUCLetter: A, B, C, ...
+#define PFN_LCROMAN 5 // tomListNumberAsLCRoman: i, ii, iii, ...
+#define PFN_UCROMAN 6 // tomListNumberAsUCRoman: I, II, III, ...
+
+// PARAFORMAT2 wNumberingStyle options
+#define PFNS_PAREN 0x000 // default, e.g., 1)
+#define PFNS_PARENS 0x100 // tomListParentheses/256, e.g., (1)
+#define PFNS_PERIOD 0x200 // tomListPeriod/256, e.g., 1.
+#define PFNS_PLAIN 0x300 // tomListPlain/256, e.g., 1
+#define PFNS_NONUMBER 0x400 // Used for continuation w/o number
+
+#define PFNS_NEWNUMBER 0x8000 // Start new number with wNumberingStart
+ // (can be combined with other PFNS_xxx)
+// PARAFORMAT alignment options
+#define PFA_LEFT 1
+#define PFA_RIGHT 2
+#define PFA_CENTER 3
+
+// PARAFORMAT2 alignment options
+#define PFA_JUSTIFY 4 // New paragraph-alignment option 2.0 (*)
+#define PFA_FULL_INTERWORD 4 // These are supported in 3.0 with advanced
+
+// Notification structures
+#ifndef WM_NOTIFY
+#define WM_NOTIFY 0x004E
+
+typedef struct _nmhdr
+{
+ HWND hwndFrom;
+ UINT idFrom;
+ UINT code;
+} NMHDR;
+#endif // !WM_NOTIFY
+
+typedef struct _msgfilter
+{
+ NMHDR nmhdr;
+ UINT msg;
+ WPARAM wParam;
+ LPARAM lParam;
+} MSGFILTER;
+
+typedef struct _reqresize
+{
+ NMHDR nmhdr;
+ RECT rc;
+} REQRESIZE;
+
+typedef struct _selchange
+{
+ NMHDR nmhdr;
+ CHARRANGE chrg;
+ WORD seltyp;
+} SELCHANGE;
+
+#if (_RICHEDIT_VER >= 0x0800)
+typedef struct _grouptypingchange
+{
+ NMHDR nmhdr;
+ BOOL fGroupTyping;
+} GROUPTYPINGCHANGE;
+#endif
+
+typedef struct _clipboardformat
+{
+ NMHDR nmhdr;
+ CLIPFORMAT cf;
+} CLIPBOARDFORMAT;
+
+#define SEL_EMPTY 0x0000
+#define SEL_TEXT 0x0001
+#define SEL_OBJECT 0x0002
+#define SEL_MULTICHAR 0x0004
+#define SEL_MULTIOBJECT 0x0008
+
+// Used with IRichEditOleCallback::GetContextMenu, this flag will be
+// passed as a "selection type". It indicates that a context menu for
+// a right-mouse drag drop should be generated. The IOleObject parameter
+// will really be the IDataObject for the drop
+#define GCM_RIGHTMOUSEDROP 0x8000
+
+#if (_RICHEDIT_VER >= 0x0800)
+typedef struct _getcontextmenuex
+{
+ CHARRANGE chrg;
+ DWORD dwFlags;
+ POINT pt;
+ void* pvReserved;
+} GETCONTEXTMENUEX;
+
+// bits for GETCONTEXTMENUEX::dwFlags
+#define GCMF_GRIPPER 0x00000001
+#define GCMF_SPELLING 0x00000002 // pSpellingSuggestions is valid
+ // and points to the list of spelling suggestions
+#define GCMF_TOUCHMENU 0x00004000
+#define GCMF_MOUSEMENU 0x00002000
+#endif
+
+typedef struct _endropfiles
+{
+ NMHDR nmhdr;
+ HANDLE hDrop;
+ LONG cp;
+ BOOL fProtected;
+} ENDROPFILES;
+
+typedef struct _enprotected
+{
+ NMHDR nmhdr;
+ UINT msg;
+ WPARAM wParam;
+ LPARAM lParam;
+ CHARRANGE chrg;
+} ENPROTECTED;
+
+typedef struct _ensaveclipboard
+{
+ NMHDR nmhdr;
+ LONG cObjectCount;
+ LONG cch;
+} ENSAVECLIPBOARD;
+
+#ifndef MACPORT
+typedef struct _enoleopfailed
+{
+ NMHDR nmhdr;
+ LONG iob;
+ LONG lOper;
+ HRESULT hr;
+} ENOLEOPFAILED;
+#endif
+
+#define OLEOP_DOVERB 1
+
+typedef struct _objectpositions
+{
+ NMHDR nmhdr;
+ LONG cObjectCount;
+ LONG *pcpPositions;
+} OBJECTPOSITIONS;
+
+typedef struct _enlink
+{
+ NMHDR nmhdr;
+ UINT msg;
+ WPARAM wParam;
+ LPARAM lParam;
+ CHARRANGE chrg;
+} ENLINK;
+
+typedef struct _enlowfirtf
+{
+ NMHDR nmhdr;
+ char *szControl;
+} ENLOWFIRTF;
+
+// PenWin specific
+typedef struct _encorrecttext
+{
+ NMHDR nmhdr;
+ CHARRANGE chrg;
+ WORD seltyp;
+} ENCORRECTTEXT;
+
+// East Asia specific
+typedef struct _punctuation
+{
+ UINT iSize;
+ LPSTR szPunctuation;
+} PUNCTUATION;
+
+// East Asia specific
+typedef struct _compcolor
+{
+ COLORREF crText;
+ COLORREF crBackground;
+ DWORD dwEffects;
+}COMPCOLOR;
+
+
+// Clipboard formats - use as parameter to RegisterClipboardFormat()
+#define CF_RTF TEXT("Rich Text Format")
+#define CF_RTFNOOBJS TEXT("Rich Text Format Without Objects")
+#define CF_RETEXTOBJ TEXT("RichEdit Text and Objects")
+
+// Paste Special
+typedef struct _repastespecial
+{
+ DWORD dwAspect;
+ DWORD_PTR dwParam;
+} REPASTESPECIAL;
+
+// UndoName info
+typedef enum _undonameid
+{
+ UID_UNKNOWN = 0,
+ UID_TYPING = 1,
+ UID_DELETE = 2,
+ UID_DRAGDROP = 3,
+ UID_CUT = 4,
+ UID_PASTE = 5,
+ UID_AUTOTABLE = 6
+} UNDONAMEID;
+
+// Flags for the SETEXTEX data structure
+#define ST_DEFAULT 0
+#define ST_KEEPUNDO 1
+#define ST_SELECTION 2
+#define ST_NEWCHARS 4
+#if (_RICHEDIT_VER >= 0x0500)
+#define ST_UNICODE 8
+#endif
+
+// EM_SETTEXTEX info; this struct is passed in the wparam of the message
+typedef struct _settextex
+{
+ DWORD flags; // Flags (see the ST_XXX defines)
+ UINT codepage; // Code page for translation (CP_ACP for sys default,
+ // 1200 for Unicode, -1 for control default)
+} SETTEXTEX;
+
+// Flags for the GETEXTEX data structure
+#define GT_DEFAULT 0
+#define GT_USECRLF 1
+#define GT_SELECTION 2
+#define GT_RAWTEXT 4
+#define GT_NOHIDDENTEXT 8
+
+// EM_GETTEXTEX info; this struct is passed in the wparam of the message
+typedef struct _gettextex
+{
+ DWORD cb; // Count of bytes in the string
+ DWORD flags; // Flags (see the GT_XXX defines
+ UINT codepage; // Code page for translation (CP_ACP for sys default,
+ // 1200 for Unicode, -1 for control default)
+ LPCSTR lpDefaultChar; // Replacement for unmappable chars
+ LPBOOL lpUsedDefChar; // Pointer to flag set when def char used
+} GETTEXTEX;
+
+// Flags for the GETTEXTLENGTHEX data structure
+#define GTL_DEFAULT 0 // Do default (return # of chars)
+#define GTL_USECRLF 1 // Compute answer using CRLFs for paragraphs
+#define GTL_PRECISE 2 // Compute a precise answer
+#define GTL_CLOSE 4 // Fast computation of a "close" answer
+#define GTL_NUMCHARS 8 // Return number of characters
+#define GTL_NUMBYTES 16 // Return number of _bytes_
+
+// EM_GETTEXTLENGTHEX info; this struct is passed in the wparam of the msg
+typedef struct _gettextlengthex
+{
+ DWORD flags; // Flags (see GTL_XXX defines)
+ UINT codepage; // Code page for translation (CP_ACP for default,
+ // 1200 for Unicode)
+} GETTEXTLENGTHEX;
+
+// BiDi specific features
+typedef struct _bidioptions
+{
+ UINT cbSize;
+ WORD wMask;
+ WORD wEffects;
+} BIDIOPTIONS;
+
+// BIDIOPTIONS masks
+#if (_RICHEDIT_VER == 0x0100)
+#define BOM_DEFPARADIR 0x0001 // Default paragraph direction (implies alignment) (obsolete)
+#define BOM_PLAINTEXT 0x0002 // Use plain text layout (obsolete)
+#endif // _RICHEDIT_VER == 0x0100
+#define BOM_NEUTRALOVERRIDE 0x0004 // Override neutral layout (obsolete)
+#define BOM_CONTEXTREADING 0x0008 // Context reading order
+#define BOM_CONTEXTALIGNMENT 0x0010 // Context alignment
+#define BOM_LEGACYBIDICLASS 0x0040 // Legacy Bidi classification (obsolete)
+#if (_RICHEDIT_VER >= 0x0600)
+#define BOM_UNICODEBIDI 0x0080 // Use Unicode BiDi algorithm
+#endif
+
+// BIDIOPTIONS effects
+#if (_RICHEDIT_VER == 0x0100)
+#define BOE_RTLDIR 0x0001 // Default paragraph direction (implies alignment) (obsolete)
+#define BOE_PLAINTEXT 0x0002 // Use plain text layout (obsolete)
+#endif // _RICHEDIT_VER == 0x0100
+#define BOE_NEUTRALOVERRIDE 0x0004 // Override neutral layout (obsolete)
+#define BOE_CONTEXTREADING 0x0008 // Context reading order
+#define BOE_CONTEXTALIGNMENT 0x0010 // Context alignment
+#if (_RICHEDIT_VER >= 0x0800)
+#define BOE_FORCERECALC 0x0020 // Force recalc and redraw
+#endif
+#define BOE_LEGACYBIDICLASS 0x0040 // Legacy Bidi classification (obsolete)
+#if (_RICHEDIT_VER >= 0x0600)
+#define BOE_UNICODEBIDI 0x0080 // Use Unicode BiDi algorithm
+#endif
+
+// Additional EM_FINDTEXT[EX] flags
+#define FR_MATCHDIAC 0x20000000
+#define FR_MATCHKASHIDA 0x40000000
+#define FR_MATCHALEFHAMZA 0x80000000
+
+// UNICODE embedding character
+#ifndef WCH_EMBEDDING
+#define WCH_EMBEDDING (WCHAR)0xFFFC
+#endif // WCH_EMBEDDING
+
+// khyph - Kind of hyphenation
+typedef enum tagKHYPH
+{
+ khyphNil, // No Hyphenation
+ khyphNormal, // Normal Hyphenation
+ khyphAddBefore, // Add letter before hyphen
+ khyphChangeBefore, // Change letter before hyphen
+ khyphDeleteBefore, // Delete letter before hyphen
+ khyphChangeAfter, // Change letter after hyphen
+ khyphDelAndChange // Delete letter before hyphen and change
+ // letter preceding hyphen
+} KHYPH;
+
+typedef struct hyphresult
+{
+ KHYPH khyph; // Kind of hyphenation
+ long ichHyph; // Character which was hyphenated
+ WCHAR chHyph; // Depending on hyphenation type, character added, changed, etc.
+} HYPHRESULT;
+
+void WINAPI HyphenateProc(_In_ WCHAR *pszWord, LANGID langid, long ichExceed, HYPHRESULT *phyphresult);
+typedef struct tagHyphenateInfo
+{
+ SHORT cbSize; // Size of HYPHENATEINFO structure
+ SHORT dxHyphenateZone; // If a space character is closer to the margin
+ // than this value, don't hyphenate (in TWIPs)
+ void (WINAPI* pfnHyphenate)(WCHAR*, LANGID, long, HYPHRESULT*);
+} HYPHENATEINFO;
+
+#ifdef _WIN32
+#include <poppack.h>
+#elif !defined(RC_INVOKED)
+#pragma pack()
+#endif
+
+// Additional class for Richedit 6.0
+#if (_RICHEDIT_VER >= 0x0600 )
+#ifndef RICHEDIT60_CLASS
+#define RICHEDIT60_CLASS L"RICHEDIT60W"
+#endif
+#endif
+
+// The following identifiers are deprecated
+// They were in previous versions of richedit.h
+#define PFA_FULL_NEWSPAPER 5 // Not implemented
+#define PFA_FULL_INTERLETTER 6 // Not implemented
+#define PFA_FULL_SCALED 7 // Not implemented
+#define PFA_FULL_GLYPHS 8 // Not implemented
+
+#define AURL_ENABLEEA 1 // Deprecated: use AURL_ENABLEEAURLS
+
+#define GCM_TOUCHMENU 0x4000 // Deprecated: Use GCMF_TOUCHMENU
+#define GCM_MOUSEMENU 0x2000 // Deprecated: Use GCMF_MOUSEMENU
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+
+#endif // !_RICHEDIT_
diff --git a/plugins/SpellChecker/src/commons.h b/plugins/SpellChecker/src/commons.h
index 598627fcd2..a0841026e7 100644
--- a/plugins/SpellChecker/src/commons.h
+++ b/plugins/SpellChecker/src/commons.h
@@ -24,10 +24,11 @@ Boston, MA 02111-1307, USA.
#define OEMRESOURCE
#include <windows.h>
-#include <richedit.h>
+#include <msapi/richedit5.h>
#include <tom.h>
#include <richole.h>
#include <commctrl.h>
+
#include <map>
#include <vector>
#include <string>
diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp
index 77358aba0f..854ff61146 100644
--- a/plugins/SpellChecker/src/utils.cpp
+++ b/plugins/SpellChecker/src/utils.cpp
@@ -1,1598 +1,1593 @@
-/*
-Copyright (C) 2006-2010 Ricardo Pescuma Domenecci
-
-This is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public
-License as published by the Free Software Foundation; either
-version 2 of the License, or (at your option) any later version.
-
-This is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with this file; see the file license.txt. If
-not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
-*/
-
-#include "commons.h"
-
-typedef void(*FoundWrongWordCallback)(TCHAR *word, CHARRANGE pos, void *param);
-
-typedef map<HWND, Dialog *> DialogMapType;
-DialogMapType dialogs;
-DialogMapType menus;
-
-struct CHARFORMAT5 : public CHARFORMAT2
-{
- BYTE bUnderlineColor;
-};
-
-void SetUnderline(Dialog *dlg, int pos_start, int pos_end)
-{
- dlg->re->SetSel(pos_start, pos_end);
-
- CHARFORMAT5 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
- cf.dwEffects = CFE_UNDERLINE;
+/*
+Copyright (C) 2006-2010 Ricardo Pescuma Domenecci
+
+This is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this file; see the file license.txt. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.
+*/
+
+#include "commons.h"
+
+typedef void(*FoundWrongWordCallback)(TCHAR *word, CHARRANGE pos, void *param);
+
+typedef map<HWND, Dialog *> DialogMapType;
+DialogMapType dialogs;
+DialogMapType menus;
+
+void SetUnderline(Dialog *dlg, int pos_start, int pos_end)
+{
+ dlg->re->SetSel(pos_start, pos_end);
+
+ CHARFORMAT2 cf;
+ cf.cbSize = sizeof(CHARFORMAT2);
+ cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
+ cf.dwEffects = CFE_UNDERLINE;
cf.bUnderlineType = opts.underline_type + CFU_UNDERLINEDOUBLE;
- cf.bUnderlineColor = 0x05;
- dlg->re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
-
- dlg->markedSomeWord = TRUE;
-}
-
-BOOL IsMyUnderline(const CHARFORMAT2 &cf)
-{
- return (cf.dwEffects & CFE_UNDERLINE)
- && (cf.bUnderlineType & 0x0F) >= CFU_UNDERLINEDOUBLE
- && (cf.bUnderlineType & 0x0F) <= CFU_UNDERLINETHICK
- && (cf.bUnderlineType & ~0x0F) == 0x50;
-}
-
-void SetNoUnderline(RichEdit *re, int pos_start, int pos_end)
-{
- if (opts.handle_underscore) {
- for (int i = pos_start; i <= pos_end; i++) {
- re->SetSel(i, min(i + 1, pos_end));
-
- CHARFORMAT2 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
-
- BOOL mine = IsMyUnderline(cf);
- if (mine) {
- cf.cbSize = sizeof(CHARFORMAT2);
- cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
- cf.dwEffects = 0;
- cf.bUnderlineType = CFU_UNDERLINE;
- re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
- }
- }
- }
- else {
- re->SetSel(pos_start, pos_end);
-
- CHARFORMAT2 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
- cf.dwEffects = 0;
- cf.bUnderlineType = CFU_UNDERLINE;
- re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
- }
-}
-
-void SetNoUnderline(Dialog *dlg)
-{
- dlg->re->Stop();
- SetNoUnderline(dlg->re, 0, dlg->re->GetTextLength());
- dlg->markedSomeWord = FALSE;
- dlg->re->Start();
-}
-
-inline BOOL IsNumber(TCHAR c)
-{
- return c >= _T('0') && c <= _T('9');
-}
-
-inline BOOL IsURL(TCHAR c)
-{
- return (c >= _T('a') && c <= _T('z'))
- || (c >= _T('A') && c <= _T('Z'))
- || IsNumber(c)
- || c == _T('.') || c == _T('/')
- || c == _T('\\') || c == _T('?')
- || c == _T('=') || c == _T('&')
- || c == _T('%') || c == _T('-')
- || c == _T('_') || c == _T(':')
- || c == _T('@') || c == _T('#');
-}
-
-int FindURLEnd(Dialog *dlg, TCHAR *text, int start_pos, int *checked_until = NULL)
-{
- int num_slashes = 0;
- int num_ats = 0;
- int num_dots = 0;
-
- int i = start_pos;
-
- for (; IsURL(text[i]) || dlg->lang->isWordChar(text[i]); i++) {
- TCHAR c = text[i];
- if (c == _T('\\') || c == _T('/'))
- num_slashes++;
- else if (c == _T('.'))
- num_dots++;
- else if (c == _T('@'))
- num_ats++;
- }
-
- if (checked_until != NULL)
- *checked_until = i;
-
- if (num_slashes <= 0 && num_ats <= 0 && num_dots <= 0)
- return -1;
-
- if (num_slashes == 0 && num_ats == 0 && num_dots < 2)
- return -1;
-
- if (i - start_pos < 2)
- return -1;
-
- return i;
-}
-
-
-int ReplaceWord(Dialog *dlg, CHARRANGE &sel, TCHAR *new_word)
-{
- dlg->re->Stop();
- dlg->re->ResumeUndo();
-
- int dif = dlg->re->Replace(sel.cpMin, sel.cpMax, new_word);
-
- dlg->re->SuspendUndo();
- dlg->re->Start();
-
- return dif;
-}
-
-class TextParser
-{
-public:
- virtual ~TextParser() {}
-
- /// @return true when finished an word
- virtual bool feed(int pos, TCHAR c) = 0;
- virtual int getFirstCharPos() = 0;
- virtual void reset() = 0;
- virtual void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement) = 0;
-};
-
-class SpellParser : public TextParser
-{
- Dictionary *dict;
- int last_pos;
- BOOL found_real_char;
-
-public:
- SpellParser(Dictionary *dict) : dict(dict)
- {
- reset();
- }
-
- void reset()
- {
- last_pos = -1;
- found_real_char = FALSE;
- }
-
- bool feed(int pos, TCHAR c)
- {
- // Is inside a word?
- if (dict->isWordChar(c) || IsNumber(c)) {
- if (last_pos == -1)
- last_pos = pos;
-
- if (c != _T('-') && !IsNumber(c))
- found_real_char = TRUE;
-
- return false;
- }
-
- if (!found_real_char)
- last_pos = -1;
-
- return (last_pos != -1);
- }
-
- int getFirstCharPos()
- {
- if (!found_real_char)
- return -1;
- else
- return last_pos;
- }
-
- void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement)
- {
- // Is it correct?
- if (dict->spell(text))
- return;
-
- // Has to auto-correct?
- if (opts.auto_replace_dict) {
- *replacement = dict->autoSuggestOne(text);
- if (*replacement != NULL) {
- *replace = true;
- return;
- }
- }
-
- *mark = true;
- }
-};
-
-class AutoReplaceParser : public TextParser
-{
- AutoReplaceMap *ar;
- int last_pos;
-
-public:
- AutoReplaceParser(AutoReplaceMap *ar) : ar(ar)
- {
- reset();
- }
-
- void reset()
- {
- last_pos = -1;
- }
-
- bool feed(int pos, TCHAR c)
- {
- // Is inside a word?
- if (ar->isWordChar(c)) {
- if (last_pos == -1)
- last_pos = pos;
- return false;
- }
-
- return (last_pos != -1);
- }
-
- int getFirstCharPos()
- {
- return last_pos;
- }
-
- void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement)
- {
- *replacement = ar->autoReplace(text);
- if (*replacement != NULL)
- *replace = true;
- }
-};
-
-int CheckTextLine(Dialog *dlg, int line, TextParser *parser,
- BOOL ignore_upper, BOOL ignore_with_numbers, BOOL test_urls,
- const CHARRANGE &ignored, FoundWrongWordCallback callback, void *param)
-{
- int errors = 0;
- TCHAR text[1024];
- dlg->re->GetLine(line, text, SIZEOF(text));
- int len = lstrlen(text);
- int first_char = dlg->re->GetFirstCharOfLine(line);
-
- // Now lets get the words
- int next_char_for_url = 0;
- for (int pos = 0; pos < len; pos++) {
- int url_end = pos;
- if (pos >= next_char_for_url) {
- url_end = FindURLEnd(dlg, text, pos, &next_char_for_url);
- next_char_for_url++;
- }
-
- if (url_end > pos) {
- BOOL ignore_url = FALSE;
-
- if (test_urls) {
- // All the url must be handled by the parser
- parser->reset();
-
- BOOL feed = FALSE;
- for (int j = pos; !feed && j <= url_end; j++)
- feed = parser->feed(j, text[j]);
-
- if (feed || parser->getFirstCharPos() != pos)
- ignore_url = TRUE;
- }
- else ignore_url = TRUE;
-
- pos = url_end;
-
- if (ignore_url) {
- parser->reset();
- continue;
- }
- }
- else {
- TCHAR c = text[pos];
-
- BOOL feed = parser->feed(pos, c);
- if (!feed) {
- if (pos >= len - 1)
- pos = len; // To check the last block
- else
- continue;
- }
- }
-
- int last_pos = parser->getFirstCharPos();
- parser->reset();
-
- if (last_pos < 0)
- continue;
-
- // We found a word
- CHARRANGE sel = { first_char + last_pos, first_char + pos };
-
- // Is in ignored range?
- if (sel.cpMin <= ignored.cpMax && sel.cpMax >= ignored.cpMin)
- continue;
-
- if (ignore_upper) {
- BOOL upper = TRUE;
- for (int i = last_pos; i < pos && upper; i++)
- upper = !IsCharLower(text[i]);
- if (upper)
- continue;
- }
-
- if (ignore_with_numbers) {
- BOOL hasNumbers = FALSE;
- for (int i = last_pos; i < pos && !hasNumbers; i++)
- hasNumbers = IsNumber(text[i]);
- if (hasNumbers)
- continue;
- }
-
- text[pos] = 0;
-
- bool mark = false;
- bool replace = false;
- TCHAR *replacement = NULL;
- parser->deal(&text[last_pos], &mark, &replace, &replacement);
-
- if (replace) {
- // Replace in rich edit
- int dif = dlg->re->Replace(sel.cpMin, sel.cpMax, replacement);
- if (dif != 0) {
- // Read line again
- dlg->re->GetLine(line, text, SIZEOF(text));
- len = lstrlen(text);
-
- int old_first_char = first_char;
- first_char = dlg->re->GetFirstCharOfLine(line);
-
- pos = max(-1, pos + dif + old_first_char - first_char);
- }
-
- free(replacement);
- }
- else if (mark) {
- SetUnderline(dlg, sel.cpMin, sel.cpMax);
-
- if (callback != NULL)
- callback(&text[last_pos], sel, param);
-
- errors++;
- }
- }
-
- return errors;
-}
-
-// Checks for errors in all text
-int CheckText(Dialog *dlg, BOOL check_all, FoundWrongWordCallback callback = NULL, void *param = NULL)
-{
- int errors = 0;
-
- dlg->re->Stop();
-
- if (dlg->re->GetTextLength() > 0) {
- int lines = dlg->re->GetLineCount();
- int line = 0;
- CHARRANGE cur_sel = { -1, -1 };
-
- if (!check_all) {
- // Check only the current line, one up and one down
- int current_line = dlg->re->GetLineFromChar(dlg->re->GetSel().cpMin);
- line = max(line, current_line - 1);
- lines = min(lines, current_line + 2);
- cur_sel = dlg->re->GetSel();
- }
-
- for (; line < lines; line++) {
- int first_char = dlg->re->GetFirstCharOfLine(line);
-
- SetNoUnderline(dlg->re, first_char, first_char + dlg->re->GetLineLength(line));
-
- if (opts.auto_replace_user)
- errors += CheckTextLine(dlg, line, &AutoReplaceParser(dlg->lang->autoReplace),
- FALSE, FALSE, TRUE,
- cur_sel, callback, param);
-
- errors += CheckTextLine(dlg, line, &SpellParser(dlg->lang),
- opts.ignore_uppercase, opts.ignore_with_numbers, FALSE,
- cur_sel, callback, param);
- }
- }
-
- // Fix last char
- int len = dlg->re->GetTextLength();
- SetNoUnderline(dlg->re, len, len);
-
- dlg->re->Start();
- return errors;
-}
-
-void ToLocaleID(TCHAR *szKLName, size_t size)
-{
- TCHAR *stopped = NULL;
- USHORT langID = (USHORT)_tcstol(szKLName, &stopped, 16);
-
- TCHAR ini[32], end[32];
- GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO639LANGNAME, ini, SIZEOF(ini));
- GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO3166CTRYNAME, end, SIZEOF(end));
-
- mir_sntprintf(szKLName, size, _T("%s_%s"), ini, end);
-}
-
-void LoadDictFromKbdl(Dialog *dlg)
-{
- TCHAR szKLName[KL_NAMELENGTH + 1];
-
- // Use default input language
- HKL hkl = GetKeyboardLayout(0);
- mir_sntprintf(szKLName, SIZEOF(szKLName), _T("%x"), (int)LOWORD(hkl));
- ToLocaleID(szKLName, SIZEOF(szKLName));
-
- int d = GetClosestLanguage(szKLName);
- if (d >= 0) {
- dlg->lang = languages[d];
- dlg->lang->load();
-
- if (dlg->srmm)
- ModifyIcon(dlg);
- }
-}
-
-int TimerCheck(Dialog *dlg, BOOL forceCheck = FALSE)
-{
- KillTimer(dlg->hwnd, TIMER_ID);
-
- if (!dlg->enabled || dlg->lang == NULL)
- return -1;
-
- if (!dlg->lang->isLoaded()) {
- SetTimer(dlg->hwnd, TIMER_ID, 500, NULL);
- return -1;
- }
-
- // Don't check if field is read-only
- if (dlg->re->IsReadOnly())
- return -1;
-
- int len = dlg->re->GetTextLength();
- if (!forceCheck && len == dlg->old_text_len && !dlg->changed)
- return -1;
-
- dlg->old_text_len = len;
- dlg->changed = FALSE;
-
- return CheckText(dlg, TRUE);
-}
-
-LRESULT CALLBACK OwnerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- DialogMapType::iterator dlgit = dialogs.find(hwnd);
- if (dlgit == dialogs.end())
- return -1;
-
- Dialog *dlg = dlgit->second;
-
- if (msg == WM_COMMAND && (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624)) {
- if (opts.ask_when_sending_with_error) {
- int errors = TimerCheck(dlg, TRUE);
- if (errors > 0) {
- TCHAR text[500];
- mir_sntprintf(text, SIZEOF(text), TranslateT("There are %d spelling errors. Are you sure you want to send this message?"), errors);
- if (MessageBox(hwnd, text, TranslateT("Spell Checker"), MB_ICONQUESTION | MB_YESNO) == IDNO)
- return TRUE;
- }
- }
- else if (opts.auto_replace_dict || opts.auto_replace_user) {
- // Fix all
- TimerCheck(dlg);
- }
-
- if (dlg->markedSomeWord)
- // Remove underline
- SetNoUnderline(dlg);
-
- // Schedule to re-parse
- KillTimer(dlg->hwnd, TIMER_ID);
- SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
-
- dlg->changed = TRUE;
- }
-
- return mir_callNextSubclass(hwnd, OwnerProc, msg, wParam, lParam);
-}
-
-void ToggleEnabled(Dialog *dlg)
-{
- dlg->enabled = !dlg->enabled;
- db_set_b(dlg->hContact, MODULE_NAME, dlg->name, dlg->enabled);
-
- if (!dlg->enabled)
- SetNoUnderline(dlg);
- else {
- dlg->changed = TRUE;
- SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
- }
-
- if (dlg->srmm)
- ModifyIcon(dlg);
-}
-
-LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- DialogMapType::iterator dlgit = dialogs.find(hwnd);
- if (dlgit == dialogs.end())
- return -1;
-
- Dialog *dlg = dlgit->second;
- if (dlg == NULL)
- return -1;
-
- // Hotkey support
- MSG msgData = { 0 };
- msgData.hwnd = hwnd;
- msgData.message = msg;
- msgData.wParam = wParam;
- msgData.lParam = lParam;
-
- int action = CallService(MS_HOTKEY_CHECK, (WPARAM)&msgData, (LPARAM)"Spell Checker");
- if (action == HOTKEY_ACTION_TOGGLE) {
- ToggleEnabled(dlg);
- return 1;
- }
-
- LRESULT ret = mir_callNextSubclass(hwnd, EditProc, msg, wParam, lParam);
- if ((dlgit = dialogs.find(hwnd)) == dialogs.end())
- return ret;
-
- switch (msg) {
- case WM_KEYDOWN:
- if (wParam != VK_DELETE)
- break;
-
- case WM_CHAR:
- if (dlg->re->IsStopped())
- break;
-
- if (lParam & (1 << 28)) // ALT key
- break;
-
- if (GetKeyState(VK_CONTROL) & 0x8000) // CTRL key
- break;
-
- {
- TCHAR c = (TCHAR)wParam;
- BOOL deleting = (c == VK_BACK || c == VK_DELETE);
-
- // Need to do that to avoid changing the word while typing
- KillTimer(hwnd, TIMER_ID);
- SetTimer(hwnd, TIMER_ID, 1000, NULL);
-
- dlg->changed = TRUE;
-
- if (!deleting && (lParam & 0xFF) > 1) // Repeat rate
- break;
-
- if (!dlg->enabled || dlg->lang == NULL || !dlg->lang->isLoaded())
- break;
-
- // Don't check if field is read-only
- if (dlg->re->IsReadOnly())
- break;
-
- if (!deleting && !dlg->lang->isWordChar(c))
- CheckText(dlg, FALSE);
- else {
- // Remove underline of current word
- CHARFORMAT2 cf;
- cf.cbSize = sizeof(CHARFORMAT2);
- dlg->re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
-
- if (IsMyUnderline(cf)) {
- dlg->re->Stop();
-
- CHARRANGE sel = dlg->re->GetSel();
-
- TCHAR text[1024];
- int first_char;
- GetWordCharRange(dlg, sel, text, SIZEOF(text), first_char);
-
- SetNoUnderline(dlg->re, sel.cpMin, sel.cpMax);
-
- dlg->re->Start();
- }
- }
- }
- break;
-
- case EM_REPLACESEL:
- case WM_SETTEXT:
- case EM_SETTEXTEX:
- case EM_PASTESPECIAL:
- case WM_PASTE:
- if (dlg->re->IsStopped())
- break;
-
- KillTimer(hwnd, TIMER_ID);
- SetTimer(hwnd, TIMER_ID, 100, NULL);
-
- dlg->changed = TRUE;
- break;
-
- case WM_TIMER:
- if (wParam == TIMER_ID)
- TimerCheck(dlg);
- break;
-
- case WMU_DICT_CHANGED:
- KillTimer(hwnd, TIMER_ID);
- SetTimer(hwnd, TIMER_ID, 100, NULL);
-
- dlg->changed = TRUE;
- break;
-
- case WMU_KBDL_CHANGED:
- if (opts.auto_locale) {
- KillTimer(hwnd, TIMER_ID);
- SetTimer(hwnd, TIMER_ID, 100, NULL);
-
- dlg->changed = TRUE;
-
- LoadDictFromKbdl(dlg);
- }
- break;
-
- case WM_INPUTLANGCHANGE:
- // Allow others to process this message and we get only the result
- PostMessage(hwnd, WMU_KBDL_CHANGED, 0, 0);
- break;
- }
-
- return ret;
-}
-
-int GetClosestLanguage(TCHAR *lang_name)
-{
- int i;
-
- // Search the language by name
- for (i = 0; i < languages.getCount(); i++)
- if (lstrcmpi(languages[i]->language, lang_name) == 0)
- return i;
-
- // Try searching by the prefix only
- TCHAR lang[128];
- lstrcpyn(lang, lang_name, SIZEOF(lang));
-
- TCHAR *p = _tcschr(lang, _T('_'));
- if (p != NULL)
- *p = _T('\0');
-
- // First check if there is a language that is only the prefix
- for (i = 0; i < languages.getCount(); i++)
- if (lstrcmpi(languages[i]->language, lang) == 0)
- return i;
-
- // Now try any suffix
- size_t len = lstrlen(lang);
- for (i = 0; i < languages.getCount(); i++) {
- TCHAR *p = _tcschr(languages[i]->language, _T('_'));
- if (p == NULL)
- continue;
-
- int prefix_len = p - languages[i]->language;
- if (prefix_len != len)
- continue;
-
- if (_tcsnicmp(languages[i]->language, lang_name, len) == 0)
- return i;
- }
-
- return -1;
-}
-
-void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, char *setting, BOOL isProtocol = TRUE)
-{
- DBVARIANT dbv = { 0 };
- dbv.type = DBVT_TCHAR;
-
- DBCONTACTGETSETTING cgs = { 0 };
- cgs.szModule = group;
- cgs.szSetting = setting;
- cgs.pValue = &dbv;
-
- INT_PTR rc;
-
- int caps = (isProtocol ? CallProtoService(group, PS_GETCAPS, PFLAGNUM_4, 0) : 0);
- if (caps & PF4_INFOSETTINGSVC)
- rc = CallProtoService(group, PS_GETINFOSETTING, hContact, (LPARAM)&cgs);
- else {
- rc = CallService(MS_DB_CONTACT_GETSETTING_STR_EX, hContact, (LPARAM)&cgs);
- if (rc == CALLSERVICE_NOTFOUND)
- rc = db_get_ts(hContact, group, setting, &dbv);
- }
-
- if (!rc && dbv.type == DBVT_TCHAR && dbv.ptszVal != NULL) {
- TCHAR *lang = dbv.ptszVal;
-
- for (int i = 0; i < languages.getCount(); i++) {
- Dictionary *dict = languages[i];
- if (lstrcmpi(dict->localized_name, lang) == 0
- || lstrcmpi(dict->english_name, lang) == 0
- || lstrcmpi(dict->language, lang) == 0) {
- lstrcpyn(dlg->lang_name, dict->language, SIZEOF(dlg->lang_name));
- break;
- }
- }
- }
-
- if (!rc)
- db_free(&dbv);
-}
-
-void GetUserLanguageSetting(Dialog *dlg, char *setting)
-{
- char *proto = GetContactProto(dlg->hContact);
- if (proto == NULL)
- return;
-
- GetUserProtoLanguageSetting(dlg, dlg->hContact, proto, setting);
- if (dlg->lang_name[0] != _T('\0'))
- return;
-
- GetUserProtoLanguageSetting(dlg, dlg->hContact, "UserInfo", setting, FALSE);
- if (dlg->lang_name[0] != _T('\0'))
- return;
-
- // If not found and is inside meta, try to get from the meta
- MCONTACT hMetaContact = db_mc_getMeta(dlg->hContact);
- if (hMetaContact != NULL) {
- GetUserProtoLanguageSetting(dlg, hMetaContact, META_PROTO, setting);
- if (dlg->lang_name[0] != _T('\0'))
- return;
-
- GetUserProtoLanguageSetting(dlg, hMetaContact, "UserInfo", setting, FALSE);
- }
-}
-
-void GetContactLanguage(Dialog *dlg)
-{
- DBVARIANT dbv = { 0 };
-
- dlg->lang_name[0] = _T('\0');
-
- if (dlg->hContact == NULL) {
- if (!db_get_ts(NULL, MODULE_NAME, dlg->name, &dbv)) {
- lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
- db_free(&dbv);
- }
- }
- else {
- if (!db_get_ts(dlg->hContact, MODULE_NAME, "TalkLanguage", &dbv)) {
- lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
- db_free(&dbv);
- }
-
- if (dlg->lang_name[0] == _T('\0') && !db_get_ts(dlg->hContact, "eSpeak", "TalkLanguage", &dbv)) {
- lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
- db_free(&dbv);
- }
-
- // Try from metacontact
- if (dlg->lang_name[0] == _T('\0')) {
- MCONTACT hMetaContact = db_mc_getMeta(dlg->hContact);
- if (hMetaContact != NULL) {
- if (!db_get_ts(hMetaContact, MODULE_NAME, "TalkLanguage", &dbv)) {
- lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
- db_free(&dbv);
- }
-
- if (dlg->lang_name[0] == _T('\0') && !db_get_ts(hMetaContact, "eSpeak", "TalkLanguage", &dbv)) {
- lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
- db_free(&dbv);
- }
- }
- }
-
- // Try to get from Language info
- if (dlg->lang_name[0] == _T('\0'))
- GetUserLanguageSetting(dlg, "Language");
- if (dlg->lang_name[0] == _T('\0'))
- GetUserLanguageSetting(dlg, "Language1");
- if (dlg->lang_name[0] == _T('\0'))
- GetUserLanguageSetting(dlg, "Language2");
- if (dlg->lang_name[0] == _T('\0'))
- GetUserLanguageSetting(dlg, "Language3");
-
- // Use default lang
- if (dlg->lang_name[0] == _T('\0'))
- lstrcpyn(dlg->lang_name, opts.default_language, SIZEOF(dlg->lang_name));
- }
-
- int i = GetClosestLanguage(dlg->lang_name);
- if (i < 0) {
- // Lost a dict?
- lstrcpyn(dlg->lang_name, opts.default_language, SIZEOF(dlg->lang_name));
- i = GetClosestLanguage(dlg->lang_name);
- }
-
- if (i >= 0) {
- dlg->lang = languages[i];
- dlg->lang->load();
- }
- else dlg->lang = NULL;
-}
-
-void ModifyIcon(Dialog *dlg)
-{
- StatusIconData sid = { sizeof(sid) };
- sid.szModule = MODULE_NAME;
-
- for (int i = 0; i < languages.getCount(); i++) {
- sid.dwId = i;
-
- if (languages[i] == dlg->lang)
- sid.flags = (dlg->enabled ? 0 : MBF_DISABLED);
- else
- sid.flags = MBF_HIDDEN;
-
- Srmm_ModifyIcon(dlg->hContact, &sid);
- }
-}
-
-INT_PTR AddContactTextBoxService(WPARAM wParam, LPARAM lParam)
-{
- SPELLCHECKER_ITEM *sci = (SPELLCHECKER_ITEM *)wParam;
- if (sci == NULL || sci->cbSize != sizeof(SPELLCHECKER_ITEM))
- return -1;
-
- return AddContactTextBox(sci->hContact, sci->hwnd, sci->window_name, FALSE, NULL);
-}
-
-int AddContactTextBox(MCONTACT hContact, HWND hwnd, char *name, BOOL srmm, HWND hwndOwner)
-{
- if (languages.getCount() <= 0)
- return 0;
-
- if (dialogs.find(hwnd) == dialogs.end()) {
- // Fill dialog data
- Dialog *dlg = (Dialog *)malloc(sizeof(Dialog));
- ZeroMemory(dlg, sizeof(Dialog));
-
- dlg->re = new RichEdit(hwnd);
- if (!dlg->re->IsValid()) {
- delete dlg->re;
- free(dlg);
- return 0;
- }
-
- dlg->hContact = hContact;
- dlg->hwnd = hwnd;
- strncpy(dlg->name, name, sizeof(dlg->name));
- dlg->enabled = db_get_b(dlg->hContact, MODULE_NAME, dlg->name, 1);
- dlg->srmm = srmm;
-
- GetContactLanguage(dlg);
-
- if (opts.auto_locale)
- LoadDictFromKbdl(dlg);
-
- mir_subclassWindow(dlg->hwnd, EditProc);
- dialogs[hwnd] = dlg;
-
- if (dlg->srmm && hwndOwner != NULL) {
- dlg->hwnd_owner = hwndOwner;
- mir_subclassWindow(dlg->hwnd_owner, OwnerProc);
- dialogs[dlg->hwnd_owner] = dlg;
-
- ModifyIcon(dlg);
- }
-
- if (dlg->lang != NULL)
- dlg->lang->load();
-
- SetTimer(hwnd, TIMER_ID, 1000, NULL);
- }
-
- return 0;
-}
-
-#define DESTROY_MENY(_m_) if (_m_ != NULL) { DestroyMenu(_m_); _m_ = NULL; }
-
-void FreePopupData(Dialog *dlg)
-{
- DESTROY_MENY(dlg->hLanguageSubMenu);
- DESTROY_MENY(dlg->hWrongWordsSubMenu);
-
- if (dlg->wrong_words != NULL) {
- for (unsigned i = 0; i < dlg->wrong_words->size(); i++) {
- FREE((*dlg->wrong_words)[i].word);
-
- DESTROY_MENY((*dlg->wrong_words)[i].hMeSubMenu);
- DESTROY_MENY((*dlg->wrong_words)[i].hCorrectSubMenu);
- DESTROY_MENY((*dlg->wrong_words)[i].hReplaceSubMenu);
-
- FreeSuggestions((*dlg->wrong_words)[i].suggestions);
- }
-
- delete dlg->wrong_words;
- dlg->wrong_words = NULL;
- }
-}
-
-INT_PTR RemoveContactTextBoxService(WPARAM wParam, LPARAM lParam)
-{
- HWND hwnd = (HWND)wParam;
- if (hwnd == NULL)
- return -1;
-
- return RemoveContactTextBox(hwnd);
-}
-
-int RemoveContactTextBox(HWND hwnd)
-{
- DialogMapType::iterator dlgit = dialogs.find(hwnd);
- if (dlgit != dialogs.end()) {
- Dialog *dlg = dlgit->second;
-
- KillTimer(hwnd, TIMER_ID);
-
- mir_unsubclassWindow(hwnd, EditProc);
- dialogs.erase(hwnd);
- if (dlg->hwnd_owner != NULL)
- dialogs.erase(dlg->hwnd_owner);
-
- delete dlg->re;
- FreePopupData(dlg);
- free(dlg);
- }
-
- return 0;
-}
-
-// TODO Make this better
-BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, TCHAR *text, size_t text_len, int &first_char)
-{
- // Get line
- int line = dlg->re->GetLineFromChar(sel.cpMin);
-
- // Get text
- dlg->re->GetLine(line, text, text_len);
- first_char = dlg->re->GetFirstCharOfLine(line);
-
- // Find the word
- sel.cpMin--;
- while (sel.cpMin >= first_char && (dlg->lang->isWordChar(text[sel.cpMin - first_char])
- || IsNumber(text[sel.cpMin - first_char])))
- sel.cpMin--;
- sel.cpMin++;
-
- while (text[sel.cpMax - first_char] != _T('\0') && (dlg->lang->isWordChar(text[sel.cpMax - first_char])
- || IsNumber(text[sel.cpMax - first_char])))
- sel.cpMax++;
-
- // Has a word?
- if (sel.cpMin >= sel.cpMax)
- return FALSE;
-
- // See if it has only '-'s
- BOOL has_valid_char = FALSE;
- for (int i = sel.cpMin; i < sel.cpMax && !has_valid_char; i++)
- has_valid_char = (text[i - first_char] != _T('-'));
-
- return has_valid_char;
-}
-
-TCHAR *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel)
-{
- // Get text
- if (dlg->re->GetTextLength() <= 0)
- return NULL;
-
- // Get pos
- sel.cpMin = sel.cpMax = dlg->re->GetCharFromPos(pt);
-
- // Get text
- TCHAR text[1024];
- int first_char;
-
- if (!GetWordCharRange(dlg, sel, text, SIZEOF(text), first_char))
- return NULL;
-
- // copy the word
- text[sel.cpMax - first_char] = _T('\0');
- return _tcsdup(&text[sel.cpMin - first_char]);
-}
-
-
-void AppendSubmenu(HMENU hMenu, HMENU hSubMenu, TCHAR *name)
-{
- MENUITEMINFO mii = { sizeof(mii) };
- mii.cbSize = sizeof(MENUITEMINFO);
- mii.fMask = MIIM_SUBMENU | MIIM_TYPE;
- mii.fType = MFT_STRING;
- mii.hSubMenu = hSubMenu;
- mii.dwTypeData = name;
- mii.cch = lstrlen(name);
- InsertMenuItem(hMenu, 0, TRUE, &mii);
-}
-
-void AppendMenuItem(HMENU hMenu, int id, TCHAR *name, HICON hIcon, BOOL checked)
-{
- ICONINFO iconInfo;
- GetIconInfo(hIcon, &iconInfo);
-
- MENUITEMINFO mii = { sizeof(mii) };
- mii.fMask = MIIM_CHECKMARKS | MIIM_TYPE | MIIM_STATE;
- mii.fType = MFT_STRING;
- mii.fState = (checked ? MFS_CHECKED : 0);
- mii.wID = id;
- mii.hbmpChecked = iconInfo.hbmColor;
- mii.hbmpUnchecked = iconInfo.hbmColor;
- mii.dwTypeData = name;
- mii.cch = lstrlen(name);
- InsertMenuItem(hMenu, 0, TRUE, &mii);
-}
-
-#define LANGUAGE_MENU_ID_BASE 10
-#define WORD_MENU_ID_BASE 100
-#define AUTOREPLACE_MENU_ID_BASE 50
-
-void AddMenuForWord(Dialog *dlg, TCHAR *word, CHARRANGE &pos, HMENU hMenu, BOOL in_submenu, UINT base)
-{
- if (dlg->wrong_words == NULL)
- dlg->wrong_words = new vector<WrongWordPopupMenuData>(1);
- else
- dlg->wrong_words->resize(dlg->wrong_words->size() + 1);
-
- WrongWordPopupMenuData &data = (*dlg->wrong_words)[dlg->wrong_words->size() - 1];
- ZeroMemory(&data, sizeof(WrongWordPopupMenuData));
-
- // Get suggestions
- data.word = word;
- data.pos = pos;
- data.suggestions = dlg->lang->suggest(word);
-
- Suggestions &suggestions = data.suggestions;
-
- if (in_submenu) {
- data.hMeSubMenu = CreatePopupMenu();
- AppendSubmenu(hMenu, data.hMeSubMenu, word);
- hMenu = data.hMeSubMenu;
- }
-
- data.hReplaceSubMenu = CreatePopupMenu();
-
- InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + suggestions.count, TranslateT("Other..."));
- if (suggestions.count > 0) {
- InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
- for (int i = (int)suggestions.count - 1; i >= 0; i--)
- InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + i, suggestions.words[i]);
- }
-
- AppendSubmenu(hMenu, data.hReplaceSubMenu, TranslateT("Always replace with"));
-
- InsertMenu(hMenu, 0, MF_BYPOSITION, base + suggestions.count + 1, TranslateT("Ignore all"));
- InsertMenu(hMenu, 0, MF_BYPOSITION, base + suggestions.count, TranslateT("Add to dictionary"));
-
- if (suggestions.count > 0) {
- HMENU hSubMenu;
- if (opts.cascade_corrections) {
- hSubMenu = data.hCorrectSubMenu = CreatePopupMenu();
- AppendSubmenu(hMenu, hSubMenu, TranslateT("Corrections"));
- }
- else {
- InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
- hSubMenu = hMenu;
- }
-
- for (int i = (int)suggestions.count - 1; i >= 0; i--)
- InsertMenu(hSubMenu, 0, MF_BYPOSITION, base + i, suggestions.words[i]);
- }
-
- if (!in_submenu && opts.show_wrong_word) {
- InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
-
- TCHAR text[128];
- mir_sntprintf(text, SIZEOF(text), TranslateT("Wrong word: %s"), word);
- InsertMenu(hMenu, 0, MF_BYPOSITION, 0, text);
- }
-}
-
-struct FoundWrongWordParam
-{
- Dialog *dlg;
- int count;
-};
-
-void FoundWrongWord(TCHAR *word, CHARRANGE pos, void *param)
-{
- FoundWrongWordParam *p = (FoundWrongWordParam*)param;
-
- p->count++;
-
- AddMenuForWord(p->dlg, _tcsdup(word), pos, p->dlg->hWrongWordsSubMenu, TRUE, WORD_MENU_ID_BASE * p->count);
-}
-
-void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner)
-{
- FreePopupData(dlg);
- if (opts.use_flags) {
- dlg->hwnd_menu_owner = hwndOwner;
- menus[hwndOwner] = dlg;
- }
-
- BOOL wrong_word = FALSE;
-
- // Make menu
- if (GetMenuItemCount(hMenu) > 0)
- InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
-
- if (languages.getCount() > 0 && dlg->enabled) {
- dlg->hLanguageSubMenu = CreatePopupMenu();
-
- if (dlg->hwnd_menu_owner != NULL)
- mir_subclassWindow(dlg->hwnd_menu_owner, MenuWndProc);
-
- // First add languages
- for (int i = 0; i < languages.getCount(); i++)
- AppendMenu(dlg->hLanguageSubMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0),
- LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name);
-
- AppendSubmenu(hMenu, dlg->hLanguageSubMenu, TranslateT("Language"));
- }
-
- InsertMenu(hMenu, 0, MF_BYPOSITION, 1, TranslateT("Enable spell checking"));
- CheckMenuItem(hMenu, 1, MF_BYCOMMAND | (dlg->enabled ? MF_CHECKED : MF_UNCHECKED));
-
- // Get text
- if (dlg->lang != NULL && dlg->enabled) {
- if (opts.show_all_corrections) {
- dlg->hWrongWordsSubMenu = CreatePopupMenu();
-
- FoundWrongWordParam p = { dlg, 0 };
- CheckText(dlg, TRUE, FoundWrongWord, &p);
-
- if (p.count > 0)
- AppendSubmenu(hMenu, dlg->hWrongWordsSubMenu, TranslateT("Wrong words"));
- }
- else {
- CHARRANGE sel;
- TCHAR *word = GetWordUnderPoint(dlg, pt, sel);
- if (word != NULL && !dlg->lang->spell(word)) {
- InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
- AddMenuForWord(dlg, word, sel, hMenu, FALSE, WORD_MENU_ID_BASE);
- }
- }
- }
-}
-
-
-static void AddWordToDictCallback(BOOL canceled, Dictionary *dict,
- const TCHAR *find, const TCHAR *replace, BOOL useVariables,
- const TCHAR *original_find, void *param)
-{
- if (canceled)
- return;
-
- dict->autoReplace->add(find, replace, useVariables);
-
- HWND hwndParent = (HWND)param;
- if (hwndParent != NULL)
- PostMessage(hwndParent, WMU_DICT_CHANGED, 0, 0);
-}
-
-
-BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection)
-{
- BOOL ret = FALSE;
-
- if (selection == 1) {
- ToggleEnabled(dlg);
- ret = TRUE;
- }
- else if (selection >= LANGUAGE_MENU_ID_BASE && selection < LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) {
- SetNoUnderline(dlg);
-
- if (dlg->hContact == NULL)
- db_set_ts(NULL, MODULE_NAME, dlg->name,
- languages[selection - LANGUAGE_MENU_ID_BASE]->language);
- else
- db_set_ts(dlg->hContact, MODULE_NAME, "TalkLanguage",
- languages[selection - LANGUAGE_MENU_ID_BASE]->language);
-
- GetContactLanguage(dlg);
-
- if (dlg->srmm)
- ModifyIcon(dlg);
-
- ret = TRUE;
- }
- else if (selection > 0 && dlg->wrong_words != NULL
- && selection >= WORD_MENU_ID_BASE
- && selection < (dlg->wrong_words->size() + 1) * WORD_MENU_ID_BASE) {
- int pos = selection / WORD_MENU_ID_BASE;
- selection -= pos * WORD_MENU_ID_BASE;
- pos--; // 0 based
- WrongWordPopupMenuData &data = (*dlg->wrong_words)[pos];
-
- if (selection < data.suggestions.count) {
- // TODO Assert that text hasn't changed
- ReplaceWord(dlg, data.pos, data.suggestions.words[selection]);
- ret = TRUE;
- }
- else if (selection == data.suggestions.count) {
- dlg->lang->addWord(data.word);
- ret = TRUE;
- }
- else if (selection == data.suggestions.count + 1) {
- dlg->lang->ignoreWord(data.word);
- ret = TRUE;
- }
- else if (selection >= AUTOREPLACE_MENU_ID_BASE && selection < AUTOREPLACE_MENU_ID_BASE + data.suggestions.count + 1) {
- selection -= AUTOREPLACE_MENU_ID_BASE;
- if (selection == data.suggestions.count) {
- ShowAutoReplaceDialog(dlg->hwnd_owner != NULL ? dlg->hwnd_owner : dlg->hwnd, FALSE,
- dlg->lang, data.word, NULL, FALSE,
- TRUE, &AddWordToDictCallback, dlg->hwnd);
- }
- else {
- // TODO Assert that text hasn't changed
- ReplaceWord(dlg, data.pos, data.suggestions.words[selection]);
- dlg->lang->autoReplace->add(data.word, data.suggestions.words[selection]);
- ret = TRUE;
- }
- }
- }
-
- if (ret) {
- KillTimer(dlg->hwnd, TIMER_ID);
- SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
-
- dlg->changed = TRUE;
- }
-
- FreePopupData(dlg);
- return ret;
-}
-
-int MsgWindowPopup(WPARAM wParam, LPARAM lParam)
-{
- MessageWindowPopupData *mwpd = (MessageWindowPopupData *)lParam;
- if (mwpd == NULL || mwpd->cbSize < sizeof(MessageWindowPopupData) || mwpd->uFlags != MSG_WINDOWPOPUP_INPUT)
- return 0;
-
- DialogMapType::iterator dlgit = dialogs.find(mwpd->hwnd);
- if (dlgit == dialogs.end())
- return -1;
-
- Dialog *dlg = dlgit->second;
-
- POINT pt = mwpd->pt;
- ScreenToClient(dlg->hwnd, &pt);
-
- if (mwpd->uType == MSG_WINDOWPOPUP_SHOWING)
- AddItemsToMenu(dlg, mwpd->hMenu, pt, dlg->hwnd_owner);
- else if (mwpd->uType == MSG_WINDOWPOPUP_SELECTED)
- HandleMenuSelection(dlg, pt, mwpd->selection);
-
- return 0;
-}
-
-INT_PTR ShowPopupMenuService(WPARAM wParam, LPARAM lParam)
-{
- SPELLCHECKER_POPUPMENU *scp = (SPELLCHECKER_POPUPMENU *)wParam;
- if (scp == NULL || scp->cbSize != sizeof(SPELLCHECKER_POPUPMENU))
- return -1;
-
- return ShowPopupMenu(scp->hwnd, scp->hMenu, scp->pt, scp->hwndOwner == NULL ? scp->hwnd : scp->hwndOwner);
-}
-
-int ShowPopupMenu(HWND hwnd, HMENU hMenu, POINT pt, HWND hwndOwner)
-{
- DialogMapType::iterator dlgit = dialogs.find(hwnd);
- if (dlgit == dialogs.end())
- return -1;
-
- Dialog *dlg = dlgit->second;
-
- if (pt.x == 0xFFFF && pt.y == 0xFFFF) {
- CHARRANGE sel;
- SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
-
- // Get current cursor pos
- SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax);
- }
- else ScreenToClient(hwnd, &pt);
-
- BOOL create_menu = (hMenu == NULL);
- if (create_menu)
- hMenu = CreatePopupMenu();
-
- // Make menu
- AddItemsToMenu(dlg, hMenu, pt, hwndOwner);
-
- // Show menu
- POINT client = pt;
- ClientToScreen(hwnd, &pt);
- int selection = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndOwner, NULL);
-
- // Do action
- if (HandleMenuSelection(dlg, client, selection))
- selection = 0;
-
- if (create_menu)
- DestroyMenu(hMenu);
-
- return selection;
-}
-
-int MsgWindowEvent(WPARAM wParam, LPARAM lParam)
-{
- MessageWindowEventData *event = (MessageWindowEventData *)lParam;
- if (event == NULL)
- return 0;
-
- if (event->cbSize < sizeof(MessageWindowEventData))
- return 0;
-
- if (event->uType == MSG_WINDOW_EVT_OPEN)
- AddContactTextBox(event->hContact, event->hwndInput, "DefaultSRMM", TRUE, event->hwndWindow);
- else if (event->uType == MSG_WINDOW_EVT_CLOSING)
- RemoveContactTextBox(event->hwndInput);
-
- return 0;
-}
-
-
-int IconPressed(WPARAM hContact, LPARAM lParam)
-{
- StatusIconClickData *sicd = (StatusIconClickData *)lParam;
- if (sicd == NULL || strcmp(sicd->szModule, MODULE_NAME) != 0)
- return 0;
-
- if (hContact == NULL)
- return 0;
-
- // Find the dialog
- HWND hwnd = NULL;
- Dialog *dlg;
- for (DialogMapType::iterator it = dialogs.begin(); it != dialogs.end(); it++) {
- dlg = it->second;
- if (dlg->srmm && dlg->hContact == hContact) {
- hwnd = it->first;
- break;
- }
- }
-
- if (hwnd == NULL)
- return 0;
-
- if ((sicd->flags & MBCF_RIGHTBUTTON) == 0) {
- FreePopupData(dlg);
-
- // Show the menu
- HMENU hMenu = CreatePopupMenu();
-
- if (languages.getCount() > 0) {
- if (opts.use_flags) {
- menus[dlg->hwnd] = dlg;
- dlg->hwnd_menu_owner = dlg->hwnd;
- mir_subclassWindow(dlg->hwnd_menu_owner, MenuWndProc);
- }
-
- // First add languages
- for (int i = 0; i < languages.getCount(); i++)
- AppendMenu(hMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0), LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name);
-
- InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
- }
-
- InsertMenu(hMenu, 0, MF_BYPOSITION, 1, TranslateT("Enable spell checking"));
- CheckMenuItem(hMenu, 1, MF_BYCOMMAND | (dlg->enabled ? MF_CHECKED : MF_UNCHECKED));
-
- // Show menu
- int selection = TrackPopupMenu(hMenu, TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, dlg->hwnd, NULL);
- HandleMenuSelection(dlg, sicd->clickLocation, selection);
- DestroyMenu(hMenu);
- }
- else {
- // Enable / disable
- HandleMenuSelection(dlg, sicd->clickLocation, 1);
- }
-
- return 0;
-}
-
-LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- DialogMapType::iterator dlgit = menus.find(hwnd);
- if (dlgit == menus.end())
- return -1;
-
- Dialog *dlg = dlgit->second;
-
- switch (msg) {
- case WM_INITMENUPOPUP:
- {
- HMENU hMenu = (HMENU)wParam;
-
- int count = GetMenuItemCount(hMenu);
- for (int i = 0; i < count; i++) {
- unsigned id = GetMenuItemID(hMenu, i);
- if (id < LANGUAGE_MENU_ID_BASE || id >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
- continue;
-
- MENUITEMINFO mii = { 0 };
- mii.cbSize = sizeof(MENUITEMINFO);
- mii.fMask = MIIM_STATE;
- GetMenuItemInfo(hMenu, id, FALSE, &mii);
-
- // Make ownerdraw
- ModifyMenu(hMenu, id, mii.fState | MF_BYCOMMAND | MF_OWNERDRAW, id, NULL);
- }
- }
- break;
-
- case WM_DRAWITEM:
- {
- LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
- if (lpdis->CtlType != ODT_MENU || lpdis->itemID < LANGUAGE_MENU_ID_BASE || lpdis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
- break;
-
- int pos = lpdis->itemID - LANGUAGE_MENU_ID_BASE;
-
- Dictionary *dict = languages[pos];
-
- COLORREF clrfore = SetTextColor(lpdis->hDC,
- GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT));
- COLORREF clrback = SetBkColor(lpdis->hDC,
- GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU));
-
- FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU));
-
- RECT rc = lpdis->rcItem;
- rc.left += 2;
-
- // Checked?
- rc.right = rc.left + bmpChecked.bmWidth;
-
- if (lpdis->itemState & ODS_CHECKED) {
- rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - bmpChecked.bmHeight) / 2;
- rc.bottom = rc.top + bmpChecked.bmHeight;
-
- HDC hdcTemp = CreateCompatibleDC(lpdis->hDC);
- HBITMAP oldBmp = (HBITMAP)SelectObject(hdcTemp, hCheckedBmp);
-
- BitBlt(lpdis->hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hdcTemp, 0, 0, SRCCOPY);
-
- SelectObject(hdcTemp, oldBmp);
- DeleteDC(hdcTemp);
- }
-
- rc.left += bmpChecked.bmWidth + 2;
-
- // Draw icon
- if (dict->hIcolib) {
- HICON hFlag = Skin_GetIconByHandle(dict->hIcolib);
-
- rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - ICON_SIZE) / 2;
- DrawIconEx(lpdis->hDC, rc.left, rc.top, hFlag, 16, 16, 0, NULL, DI_NORMAL);
-
- Skin_ReleaseIcon(hFlag);
-
- rc.left += ICON_SIZE + 4;
- }
-
- // Draw text
- RECT rc_text = { 0, 0, 0xFFFF, 0xFFFF };
- DrawText(lpdis->hDC, dict->full_name, lstrlen(dict->full_name), &rc_text, DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT);
-
- rc.right = lpdis->rcItem.right - 2;
- rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - (rc_text.bottom - rc_text.top)) / 2;
- rc.bottom = rc.top + rc_text.bottom - rc_text.top;
- DrawText(lpdis->hDC, dict->full_name, lstrlen(dict->full_name), &rc, DT_END_ELLIPSIS | DT_NOPREFIX | DT_LEFT | DT_TOP | DT_SINGLELINE);
-
- // Restore old colors
- SetTextColor(lpdis->hDC, clrfore);
- SetBkColor(lpdis->hDC, clrback);
- }
- return TRUE;
-
- case WM_MEASUREITEM:
- LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam;
- if (lpmis->CtlType != ODT_MENU || lpmis->itemID < LANGUAGE_MENU_ID_BASE || lpmis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
- break;
-
- int pos = lpmis->itemID - LANGUAGE_MENU_ID_BASE;
-
- Dictionary *dict = languages[pos];
-
- HDC hdc = GetDC(hwnd);
-
- NONCLIENTMETRICS info;
- ZeroMemory(&info, sizeof(info));
- info.cbSize = sizeof(info);
- SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
- HFONT hFont = CreateFontIndirect(&info.lfMenuFont);
- HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);
-
- RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
-
- DrawText(hdc, dict->full_name, lstrlen(dict->full_name), &rc, DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT);
-
- lpmis->itemHeight = max(ICON_SIZE, max(bmpChecked.bmHeight, rc.bottom));
- lpmis->itemWidth = 2 + bmpChecked.bmWidth + 2 + ICON_SIZE + 4 + rc.right + 2;
-
- SelectObject(hdc, hFontOld);
- DeleteObject(hFont);
- ReleaseDC(hwnd, hdc);
-
- return TRUE;
- }
-
- return mir_callNextSubclass(hwnd, MenuWndProc, msg, wParam, lParam);
-}
-
-TCHAR* lstrtrim(TCHAR *str)
-{
- int len = lstrlen(str);
-
- int i;
- for (i = len - 1; i >= 0 && (str[i] == ' ' || str[i] == '\t'); --i);
- if (i < len - 1) {
- ++i;
- str[i] = _T('\0');
- len = i;
- }
-
- for (i = 0; i < len && (str[i] == ' ' || str[i] == '\t'); ++i);
- if (i > 0)
- memmove(str, &str[i], (len - i + 1) * sizeof(TCHAR));
-
- return str;
-}
-
-BOOL lstreq(TCHAR *a, TCHAR *b, size_t len)
-{
- a = CharLower(_tcsdup(a));
- b = CharLower(_tcsdup(b));
- BOOL ret;
- if (len >= 0)
- ret = !_tcsncmp(a, b, len);
- else
- ret = !_tcscmp(a, b);
- free(a);
- free(b);
- return ret;
-}
+ cf.bUnderlineColor = 0x05;
+ dlg->re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
+
+ dlg->markedSomeWord = TRUE;
+}
+
+BOOL IsMyUnderline(const CHARFORMAT2 &cf)
+{
+ return (cf.dwEffects & CFE_UNDERLINE)
+ && (cf.bUnderlineType & 0x0F) >= CFU_UNDERLINEDOUBLE
+ && (cf.bUnderlineType & 0x0F) <= CFU_UNDERLINETHICK
+ && (cf.bUnderlineColor) == 5;
+}
+
+void SetNoUnderline(RichEdit *re, int pos_start, int pos_end)
+{
+ if (opts.handle_underscore) {
+ for (int i = pos_start; i <= pos_end; i++) {
+ re->SetSel(i, min(i + 1, pos_end));
+
+ CHARFORMAT2 cf;
+ cf.cbSize = sizeof(CHARFORMAT2);
+ re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
+
+ BOOL mine = IsMyUnderline(cf);
+ if (mine) {
+ cf.cbSize = sizeof(CHARFORMAT2);
+ cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
+ cf.dwEffects = 0;
+ cf.bUnderlineType = CFU_UNDERLINE;
+ re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
+ }
+ }
+ }
+ else {
+ re->SetSel(pos_start, pos_end);
+
+ CHARFORMAT2 cf;
+ cf.cbSize = sizeof(CHARFORMAT2);
+ cf.dwMask = CFM_UNDERLINE | CFM_UNDERLINETYPE;
+ cf.dwEffects = 0;
+ cf.bUnderlineType = CFU_UNDERLINE;
+ re->SendMessage(EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
+ }
+}
+
+void SetNoUnderline(Dialog *dlg)
+{
+ dlg->re->Stop();
+ SetNoUnderline(dlg->re, 0, dlg->re->GetTextLength());
+ dlg->markedSomeWord = FALSE;
+ dlg->re->Start();
+}
+
+inline BOOL IsNumber(TCHAR c)
+{
+ return c >= _T('0') && c <= _T('9');
+}
+
+inline BOOL IsURL(TCHAR c)
+{
+ return (c >= _T('a') && c <= _T('z'))
+ || (c >= _T('A') && c <= _T('Z'))
+ || IsNumber(c)
+ || c == _T('.') || c == _T('/')
+ || c == _T('\\') || c == _T('?')
+ || c == _T('=') || c == _T('&')
+ || c == _T('%') || c == _T('-')
+ || c == _T('_') || c == _T(':')
+ || c == _T('@') || c == _T('#');
+}
+
+int FindURLEnd(Dialog *dlg, TCHAR *text, int start_pos, int *checked_until = NULL)
+{
+ int num_slashes = 0;
+ int num_ats = 0;
+ int num_dots = 0;
+
+ int i = start_pos;
+
+ for (; IsURL(text[i]) || dlg->lang->isWordChar(text[i]); i++) {
+ TCHAR c = text[i];
+ if (c == _T('\\') || c == _T('/'))
+ num_slashes++;
+ else if (c == _T('.'))
+ num_dots++;
+ else if (c == _T('@'))
+ num_ats++;
+ }
+
+ if (checked_until != NULL)
+ *checked_until = i;
+
+ if (num_slashes <= 0 && num_ats <= 0 && num_dots <= 0)
+ return -1;
+
+ if (num_slashes == 0 && num_ats == 0 && num_dots < 2)
+ return -1;
+
+ if (i - start_pos < 2)
+ return -1;
+
+ return i;
+}
+
+
+int ReplaceWord(Dialog *dlg, CHARRANGE &sel, TCHAR *new_word)
+{
+ dlg->re->Stop();
+ dlg->re->ResumeUndo();
+
+ int dif = dlg->re->Replace(sel.cpMin, sel.cpMax, new_word);
+
+ dlg->re->SuspendUndo();
+ dlg->re->Start();
+
+ return dif;
+}
+
+class TextParser
+{
+public:
+ virtual ~TextParser() {}
+
+ /// @return true when finished an word
+ virtual bool feed(int pos, TCHAR c) = 0;
+ virtual int getFirstCharPos() = 0;
+ virtual void reset() = 0;
+ virtual void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement) = 0;
+};
+
+class SpellParser : public TextParser
+{
+ Dictionary *dict;
+ int last_pos;
+ BOOL found_real_char;
+
+public:
+ SpellParser(Dictionary *dict) : dict(dict)
+ {
+ reset();
+ }
+
+ void reset()
+ {
+ last_pos = -1;
+ found_real_char = FALSE;
+ }
+
+ bool feed(int pos, TCHAR c)
+ {
+ // Is inside a word?
+ if (dict->isWordChar(c) || IsNumber(c)) {
+ if (last_pos == -1)
+ last_pos = pos;
+
+ if (c != _T('-') && !IsNumber(c))
+ found_real_char = TRUE;
+
+ return false;
+ }
+
+ if (!found_real_char)
+ last_pos = -1;
+
+ return (last_pos != -1);
+ }
+
+ int getFirstCharPos()
+ {
+ if (!found_real_char)
+ return -1;
+ else
+ return last_pos;
+ }
+
+ void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement)
+ {
+ // Is it correct?
+ if (dict->spell(text))
+ return;
+
+ // Has to auto-correct?
+ if (opts.auto_replace_dict) {
+ *replacement = dict->autoSuggestOne(text);
+ if (*replacement != NULL) {
+ *replace = true;
+ return;
+ }
+ }
+
+ *mark = true;
+ }
+};
+
+class AutoReplaceParser : public TextParser
+{
+ AutoReplaceMap *ar;
+ int last_pos;
+
+public:
+ AutoReplaceParser(AutoReplaceMap *ar) : ar(ar)
+ {
+ reset();
+ }
+
+ void reset()
+ {
+ last_pos = -1;
+ }
+
+ bool feed(int pos, TCHAR c)
+ {
+ // Is inside a word?
+ if (ar->isWordChar(c)) {
+ if (last_pos == -1)
+ last_pos = pos;
+ return false;
+ }
+
+ return (last_pos != -1);
+ }
+
+ int getFirstCharPos()
+ {
+ return last_pos;
+ }
+
+ void deal(const TCHAR *text, bool *mark, bool *replace, TCHAR **replacement)
+ {
+ *replacement = ar->autoReplace(text);
+ if (*replacement != NULL)
+ *replace = true;
+ }
+};
+
+int CheckTextLine(Dialog *dlg, int line, TextParser *parser,
+ BOOL ignore_upper, BOOL ignore_with_numbers, BOOL test_urls,
+ const CHARRANGE &ignored, FoundWrongWordCallback callback, void *param)
+{
+ int errors = 0;
+ TCHAR text[1024];
+ dlg->re->GetLine(line, text, SIZEOF(text));
+ int len = lstrlen(text);
+ int first_char = dlg->re->GetFirstCharOfLine(line);
+
+ // Now lets get the words
+ int next_char_for_url = 0;
+ for (int pos = 0; pos < len; pos++) {
+ int url_end = pos;
+ if (pos >= next_char_for_url) {
+ url_end = FindURLEnd(dlg, text, pos, &next_char_for_url);
+ next_char_for_url++;
+ }
+
+ if (url_end > pos) {
+ BOOL ignore_url = FALSE;
+
+ if (test_urls) {
+ // All the url must be handled by the parser
+ parser->reset();
+
+ BOOL feed = FALSE;
+ for (int j = pos; !feed && j <= url_end; j++)
+ feed = parser->feed(j, text[j]);
+
+ if (feed || parser->getFirstCharPos() != pos)
+ ignore_url = TRUE;
+ }
+ else ignore_url = TRUE;
+
+ pos = url_end;
+
+ if (ignore_url) {
+ parser->reset();
+ continue;
+ }
+ }
+ else {
+ TCHAR c = text[pos];
+
+ BOOL feed = parser->feed(pos, c);
+ if (!feed) {
+ if (pos >= len - 1)
+ pos = len; // To check the last block
+ else
+ continue;
+ }
+ }
+
+ int last_pos = parser->getFirstCharPos();
+ parser->reset();
+
+ if (last_pos < 0)
+ continue;
+
+ // We found a word
+ CHARRANGE sel = { first_char + last_pos, first_char + pos };
+
+ // Is in ignored range?
+ if (sel.cpMin <= ignored.cpMax && sel.cpMax >= ignored.cpMin)
+ continue;
+
+ if (ignore_upper) {
+ BOOL upper = TRUE;
+ for (int i = last_pos; i < pos && upper; i++)
+ upper = !IsCharLower(text[i]);
+ if (upper)
+ continue;
+ }
+
+ if (ignore_with_numbers) {
+ BOOL hasNumbers = FALSE;
+ for (int i = last_pos; i < pos && !hasNumbers; i++)
+ hasNumbers = IsNumber(text[i]);
+ if (hasNumbers)
+ continue;
+ }
+
+ text[pos] = 0;
+
+ bool mark = false;
+ bool replace = false;
+ TCHAR *replacement = NULL;
+ parser->deal(&text[last_pos], &mark, &replace, &replacement);
+
+ if (replace) {
+ // Replace in rich edit
+ int dif = dlg->re->Replace(sel.cpMin, sel.cpMax, replacement);
+ if (dif != 0) {
+ // Read line again
+ dlg->re->GetLine(line, text, SIZEOF(text));
+ len = lstrlen(text);
+
+ int old_first_char = first_char;
+ first_char = dlg->re->GetFirstCharOfLine(line);
+
+ pos = max(-1, pos + dif + old_first_char - first_char);
+ }
+
+ free(replacement);
+ }
+ else if (mark) {
+ SetUnderline(dlg, sel.cpMin, sel.cpMax);
+
+ if (callback != NULL)
+ callback(&text[last_pos], sel, param);
+
+ errors++;
+ }
+ }
+
+ return errors;
+}
+
+// Checks for errors in all text
+int CheckText(Dialog *dlg, BOOL check_all, FoundWrongWordCallback callback = NULL, void *param = NULL)
+{
+ int errors = 0;
+
+ dlg->re->Stop();
+
+ if (dlg->re->GetTextLength() > 0) {
+ int lines = dlg->re->GetLineCount();
+ int line = 0;
+ CHARRANGE cur_sel = { -1, -1 };
+
+ if (!check_all) {
+ // Check only the current line, one up and one down
+ int current_line = dlg->re->GetLineFromChar(dlg->re->GetSel().cpMin);
+ line = max(line, current_line - 1);
+ lines = min(lines, current_line + 2);
+ cur_sel = dlg->re->GetSel();
+ }
+
+ for (; line < lines; line++) {
+ int first_char = dlg->re->GetFirstCharOfLine(line);
+
+ SetNoUnderline(dlg->re, first_char, first_char + dlg->re->GetLineLength(line));
+
+ if (opts.auto_replace_user)
+ errors += CheckTextLine(dlg, line, &AutoReplaceParser(dlg->lang->autoReplace),
+ FALSE, FALSE, TRUE,
+ cur_sel, callback, param);
+
+ errors += CheckTextLine(dlg, line, &SpellParser(dlg->lang),
+ opts.ignore_uppercase, opts.ignore_with_numbers, FALSE,
+ cur_sel, callback, param);
+ }
+ }
+
+ // Fix last char
+ int len = dlg->re->GetTextLength();
+ SetNoUnderline(dlg->re, len, len);
+
+ dlg->re->Start();
+ return errors;
+}
+
+void ToLocaleID(TCHAR *szKLName, size_t size)
+{
+ TCHAR *stopped = NULL;
+ USHORT langID = (USHORT)_tcstol(szKLName, &stopped, 16);
+
+ TCHAR ini[32], end[32];
+ GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO639LANGNAME, ini, SIZEOF(ini));
+ GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SISO3166CTRYNAME, end, SIZEOF(end));
+
+ mir_sntprintf(szKLName, size, _T("%s_%s"), ini, end);
+}
+
+void LoadDictFromKbdl(Dialog *dlg)
+{
+ TCHAR szKLName[KL_NAMELENGTH + 1];
+
+ // Use default input language
+ HKL hkl = GetKeyboardLayout(0);
+ mir_sntprintf(szKLName, SIZEOF(szKLName), _T("%x"), (int)LOWORD(hkl));
+ ToLocaleID(szKLName, SIZEOF(szKLName));
+
+ int d = GetClosestLanguage(szKLName);
+ if (d >= 0) {
+ dlg->lang = languages[d];
+ dlg->lang->load();
+
+ if (dlg->srmm)
+ ModifyIcon(dlg);
+ }
+}
+
+int TimerCheck(Dialog *dlg, BOOL forceCheck = FALSE)
+{
+ KillTimer(dlg->hwnd, TIMER_ID);
+
+ if (!dlg->enabled || dlg->lang == NULL)
+ return -1;
+
+ if (!dlg->lang->isLoaded()) {
+ SetTimer(dlg->hwnd, TIMER_ID, 500, NULL);
+ return -1;
+ }
+
+ // Don't check if field is read-only
+ if (dlg->re->IsReadOnly())
+ return -1;
+
+ int len = dlg->re->GetTextLength();
+ if (!forceCheck && len == dlg->old_text_len && !dlg->changed)
+ return -1;
+
+ dlg->old_text_len = len;
+ dlg->changed = FALSE;
+
+ return CheckText(dlg, TRUE);
+}
+
+LRESULT CALLBACK OwnerProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ DialogMapType::iterator dlgit = dialogs.find(hwnd);
+ if (dlgit == dialogs.end())
+ return -1;
+
+ Dialog *dlg = dlgit->second;
+
+ if (msg == WM_COMMAND && (LOWORD(wParam) == IDOK || LOWORD(wParam) == 1624)) {
+ if (opts.ask_when_sending_with_error) {
+ int errors = TimerCheck(dlg, TRUE);
+ if (errors > 0) {
+ TCHAR text[500];
+ mir_sntprintf(text, SIZEOF(text), TranslateT("There are %d spelling errors. Are you sure you want to send this message?"), errors);
+ if (MessageBox(hwnd, text, TranslateT("Spell Checker"), MB_ICONQUESTION | MB_YESNO) == IDNO)
+ return TRUE;
+ }
+ }
+ else if (opts.auto_replace_dict || opts.auto_replace_user) {
+ // Fix all
+ TimerCheck(dlg);
+ }
+
+ if (dlg->markedSomeWord)
+ // Remove underline
+ SetNoUnderline(dlg);
+
+ // Schedule to re-parse
+ KillTimer(dlg->hwnd, TIMER_ID);
+ SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
+
+ dlg->changed = TRUE;
+ }
+
+ return mir_callNextSubclass(hwnd, OwnerProc, msg, wParam, lParam);
+}
+
+void ToggleEnabled(Dialog *dlg)
+{
+ dlg->enabled = !dlg->enabled;
+ db_set_b(dlg->hContact, MODULE_NAME, dlg->name, dlg->enabled);
+
+ if (!dlg->enabled)
+ SetNoUnderline(dlg);
+ else {
+ dlg->changed = TRUE;
+ SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
+ }
+
+ if (dlg->srmm)
+ ModifyIcon(dlg);
+}
+
+LRESULT CALLBACK EditProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ DialogMapType::iterator dlgit = dialogs.find(hwnd);
+ if (dlgit == dialogs.end())
+ return -1;
+
+ Dialog *dlg = dlgit->second;
+ if (dlg == NULL)
+ return -1;
+
+ // Hotkey support
+ MSG msgData = { 0 };
+ msgData.hwnd = hwnd;
+ msgData.message = msg;
+ msgData.wParam = wParam;
+ msgData.lParam = lParam;
+
+ int action = CallService(MS_HOTKEY_CHECK, (WPARAM)&msgData, (LPARAM)"Spell Checker");
+ if (action == HOTKEY_ACTION_TOGGLE) {
+ ToggleEnabled(dlg);
+ return 1;
+ }
+
+ LRESULT ret = mir_callNextSubclass(hwnd, EditProc, msg, wParam, lParam);
+ if ((dlgit = dialogs.find(hwnd)) == dialogs.end())
+ return ret;
+
+ switch (msg) {
+ case WM_KEYDOWN:
+ if (wParam != VK_DELETE)
+ break;
+
+ case WM_CHAR:
+ if (dlg->re->IsStopped())
+ break;
+
+ if (lParam & (1 << 28)) // ALT key
+ break;
+
+ if (GetKeyState(VK_CONTROL) & 0x8000) // CTRL key
+ break;
+
+ {
+ TCHAR c = (TCHAR)wParam;
+ BOOL deleting = (c == VK_BACK || c == VK_DELETE);
+
+ // Need to do that to avoid changing the word while typing
+ KillTimer(hwnd, TIMER_ID);
+ SetTimer(hwnd, TIMER_ID, 1000, NULL);
+
+ dlg->changed = TRUE;
+
+ if (!deleting && (lParam & 0xFF) > 1) // Repeat rate
+ break;
+
+ if (!dlg->enabled || dlg->lang == NULL || !dlg->lang->isLoaded())
+ break;
+
+ // Don't check if field is read-only
+ if (dlg->re->IsReadOnly())
+ break;
+
+ if (!deleting && !dlg->lang->isWordChar(c))
+ CheckText(dlg, FALSE);
+ else {
+ // Remove underline of current word
+ CHARFORMAT2 cf;
+ cf.cbSize = sizeof(CHARFORMAT2);
+ dlg->re->SendMessage(EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&cf);
+
+ if (IsMyUnderline(cf)) {
+ dlg->re->Stop();
+
+ CHARRANGE sel = dlg->re->GetSel();
+
+ TCHAR text[1024];
+ int first_char;
+ GetWordCharRange(dlg, sel, text, SIZEOF(text), first_char);
+
+ SetNoUnderline(dlg->re, sel.cpMin, sel.cpMax);
+
+ dlg->re->Start();
+ }
+ }
+ }
+ break;
+
+ case EM_REPLACESEL:
+ case WM_SETTEXT:
+ case EM_SETTEXTEX:
+ case EM_PASTESPECIAL:
+ case WM_PASTE:
+ if (dlg->re->IsStopped())
+ break;
+
+ KillTimer(hwnd, TIMER_ID);
+ SetTimer(hwnd, TIMER_ID, 100, NULL);
+
+ dlg->changed = TRUE;
+ break;
+
+ case WM_TIMER:
+ if (wParam == TIMER_ID)
+ TimerCheck(dlg);
+ break;
+
+ case WMU_DICT_CHANGED:
+ KillTimer(hwnd, TIMER_ID);
+ SetTimer(hwnd, TIMER_ID, 100, NULL);
+
+ dlg->changed = TRUE;
+ break;
+
+ case WMU_KBDL_CHANGED:
+ if (opts.auto_locale) {
+ KillTimer(hwnd, TIMER_ID);
+ SetTimer(hwnd, TIMER_ID, 100, NULL);
+
+ dlg->changed = TRUE;
+
+ LoadDictFromKbdl(dlg);
+ }
+ break;
+
+ case WM_INPUTLANGCHANGE:
+ // Allow others to process this message and we get only the result
+ PostMessage(hwnd, WMU_KBDL_CHANGED, 0, 0);
+ break;
+ }
+
+ return ret;
+}
+
+int GetClosestLanguage(TCHAR *lang_name)
+{
+ int i;
+
+ // Search the language by name
+ for (i = 0; i < languages.getCount(); i++)
+ if (lstrcmpi(languages[i]->language, lang_name) == 0)
+ return i;
+
+ // Try searching by the prefix only
+ TCHAR lang[128];
+ lstrcpyn(lang, lang_name, SIZEOF(lang));
+
+ TCHAR *p = _tcschr(lang, _T('_'));
+ if (p != NULL)
+ *p = _T('\0');
+
+ // First check if there is a language that is only the prefix
+ for (i = 0; i < languages.getCount(); i++)
+ if (lstrcmpi(languages[i]->language, lang) == 0)
+ return i;
+
+ // Now try any suffix
+ size_t len = lstrlen(lang);
+ for (i = 0; i < languages.getCount(); i++) {
+ TCHAR *p = _tcschr(languages[i]->language, _T('_'));
+ if (p == NULL)
+ continue;
+
+ int prefix_len = p - languages[i]->language;
+ if (prefix_len != len)
+ continue;
+
+ if (_tcsnicmp(languages[i]->language, lang_name, len) == 0)
+ return i;
+ }
+
+ return -1;
+}
+
+void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, char *setting, BOOL isProtocol = TRUE)
+{
+ DBVARIANT dbv = { 0 };
+ dbv.type = DBVT_TCHAR;
+
+ DBCONTACTGETSETTING cgs = { 0 };
+ cgs.szModule = group;
+ cgs.szSetting = setting;
+ cgs.pValue = &dbv;
+
+ INT_PTR rc;
+
+ int caps = (isProtocol ? CallProtoService(group, PS_GETCAPS, PFLAGNUM_4, 0) : 0);
+ if (caps & PF4_INFOSETTINGSVC)
+ rc = CallProtoService(group, PS_GETINFOSETTING, hContact, (LPARAM)&cgs);
+ else {
+ rc = CallService(MS_DB_CONTACT_GETSETTING_STR_EX, hContact, (LPARAM)&cgs);
+ if (rc == CALLSERVICE_NOTFOUND)
+ rc = db_get_ts(hContact, group, setting, &dbv);
+ }
+
+ if (!rc && dbv.type == DBVT_TCHAR && dbv.ptszVal != NULL) {
+ TCHAR *lang = dbv.ptszVal;
+
+ for (int i = 0; i < languages.getCount(); i++) {
+ Dictionary *dict = languages[i];
+ if (lstrcmpi(dict->localized_name, lang) == 0
+ || lstrcmpi(dict->english_name, lang) == 0
+ || lstrcmpi(dict->language, lang) == 0) {
+ lstrcpyn(dlg->lang_name, dict->language, SIZEOF(dlg->lang_name));
+ break;
+ }
+ }
+ }
+
+ if (!rc)
+ db_free(&dbv);
+}
+
+void GetUserLanguageSetting(Dialog *dlg, char *setting)
+{
+ char *proto = GetContactProto(dlg->hContact);
+ if (proto == NULL)
+ return;
+
+ GetUserProtoLanguageSetting(dlg, dlg->hContact, proto, setting);
+ if (dlg->lang_name[0] != _T('\0'))
+ return;
+
+ GetUserProtoLanguageSetting(dlg, dlg->hContact, "UserInfo", setting, FALSE);
+ if (dlg->lang_name[0] != _T('\0'))
+ return;
+
+ // If not found and is inside meta, try to get from the meta
+ MCONTACT hMetaContact = db_mc_getMeta(dlg->hContact);
+ if (hMetaContact != NULL) {
+ GetUserProtoLanguageSetting(dlg, hMetaContact, META_PROTO, setting);
+ if (dlg->lang_name[0] != _T('\0'))
+ return;
+
+ GetUserProtoLanguageSetting(dlg, hMetaContact, "UserInfo", setting, FALSE);
+ }
+}
+
+void GetContactLanguage(Dialog *dlg)
+{
+ DBVARIANT dbv = { 0 };
+
+ dlg->lang_name[0] = _T('\0');
+
+ if (dlg->hContact == NULL) {
+ if (!db_get_ts(NULL, MODULE_NAME, dlg->name, &dbv)) {
+ lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
+ db_free(&dbv);
+ }
+ }
+ else {
+ if (!db_get_ts(dlg->hContact, MODULE_NAME, "TalkLanguage", &dbv)) {
+ lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
+ db_free(&dbv);
+ }
+
+ if (dlg->lang_name[0] == _T('\0') && !db_get_ts(dlg->hContact, "eSpeak", "TalkLanguage", &dbv)) {
+ lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
+ db_free(&dbv);
+ }
+
+ // Try from metacontact
+ if (dlg->lang_name[0] == _T('\0')) {
+ MCONTACT hMetaContact = db_mc_getMeta(dlg->hContact);
+ if (hMetaContact != NULL) {
+ if (!db_get_ts(hMetaContact, MODULE_NAME, "TalkLanguage", &dbv)) {
+ lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
+ db_free(&dbv);
+ }
+
+ if (dlg->lang_name[0] == _T('\0') && !db_get_ts(hMetaContact, "eSpeak", "TalkLanguage", &dbv)) {
+ lstrcpyn(dlg->lang_name, dbv.ptszVal, SIZEOF(dlg->lang_name));
+ db_free(&dbv);
+ }
+ }
+ }
+
+ // Try to get from Language info
+ if (dlg->lang_name[0] == _T('\0'))
+ GetUserLanguageSetting(dlg, "Language");
+ if (dlg->lang_name[0] == _T('\0'))
+ GetUserLanguageSetting(dlg, "Language1");
+ if (dlg->lang_name[0] == _T('\0'))
+ GetUserLanguageSetting(dlg, "Language2");
+ if (dlg->lang_name[0] == _T('\0'))
+ GetUserLanguageSetting(dlg, "Language3");
+
+ // Use default lang
+ if (dlg->lang_name[0] == _T('\0'))
+ lstrcpyn(dlg->lang_name, opts.default_language, SIZEOF(dlg->lang_name));
+ }
+
+ int i = GetClosestLanguage(dlg->lang_name);
+ if (i < 0) {
+ // Lost a dict?
+ lstrcpyn(dlg->lang_name, opts.default_language, SIZEOF(dlg->lang_name));
+ i = GetClosestLanguage(dlg->lang_name);
+ }
+
+ if (i >= 0) {
+ dlg->lang = languages[i];
+ dlg->lang->load();
+ }
+ else dlg->lang = NULL;
+}
+
+void ModifyIcon(Dialog *dlg)
+{
+ StatusIconData sid = { sizeof(sid) };
+ sid.szModule = MODULE_NAME;
+
+ for (int i = 0; i < languages.getCount(); i++) {
+ sid.dwId = i;
+
+ if (languages[i] == dlg->lang)
+ sid.flags = (dlg->enabled ? 0 : MBF_DISABLED);
+ else
+ sid.flags = MBF_HIDDEN;
+
+ Srmm_ModifyIcon(dlg->hContact, &sid);
+ }
+}
+
+INT_PTR AddContactTextBoxService(WPARAM wParam, LPARAM lParam)
+{
+ SPELLCHECKER_ITEM *sci = (SPELLCHECKER_ITEM *)wParam;
+ if (sci == NULL || sci->cbSize != sizeof(SPELLCHECKER_ITEM))
+ return -1;
+
+ return AddContactTextBox(sci->hContact, sci->hwnd, sci->window_name, FALSE, NULL);
+}
+
+int AddContactTextBox(MCONTACT hContact, HWND hwnd, char *name, BOOL srmm, HWND hwndOwner)
+{
+ if (languages.getCount() <= 0)
+ return 0;
+
+ if (dialogs.find(hwnd) == dialogs.end()) {
+ // Fill dialog data
+ Dialog *dlg = (Dialog *)malloc(sizeof(Dialog));
+ ZeroMemory(dlg, sizeof(Dialog));
+
+ dlg->re = new RichEdit(hwnd);
+ if (!dlg->re->IsValid()) {
+ delete dlg->re;
+ free(dlg);
+ return 0;
+ }
+
+ dlg->hContact = hContact;
+ dlg->hwnd = hwnd;
+ strncpy(dlg->name, name, sizeof(dlg->name));
+ dlg->enabled = db_get_b(dlg->hContact, MODULE_NAME, dlg->name, 1);
+ dlg->srmm = srmm;
+
+ GetContactLanguage(dlg);
+
+ if (opts.auto_locale)
+ LoadDictFromKbdl(dlg);
+
+ mir_subclassWindow(dlg->hwnd, EditProc);
+ dialogs[hwnd] = dlg;
+
+ if (dlg->srmm && hwndOwner != NULL) {
+ dlg->hwnd_owner = hwndOwner;
+ mir_subclassWindow(dlg->hwnd_owner, OwnerProc);
+ dialogs[dlg->hwnd_owner] = dlg;
+
+ ModifyIcon(dlg);
+ }
+
+ if (dlg->lang != NULL)
+ dlg->lang->load();
+
+ SetTimer(hwnd, TIMER_ID, 1000, NULL);
+ }
+
+ return 0;
+}
+
+#define DESTROY_MENY(_m_) if (_m_ != NULL) { DestroyMenu(_m_); _m_ = NULL; }
+
+void FreePopupData(Dialog *dlg)
+{
+ DESTROY_MENY(dlg->hLanguageSubMenu);
+ DESTROY_MENY(dlg->hWrongWordsSubMenu);
+
+ if (dlg->wrong_words != NULL) {
+ for (unsigned i = 0; i < dlg->wrong_words->size(); i++) {
+ FREE((*dlg->wrong_words)[i].word);
+
+ DESTROY_MENY((*dlg->wrong_words)[i].hMeSubMenu);
+ DESTROY_MENY((*dlg->wrong_words)[i].hCorrectSubMenu);
+ DESTROY_MENY((*dlg->wrong_words)[i].hReplaceSubMenu);
+
+ FreeSuggestions((*dlg->wrong_words)[i].suggestions);
+ }
+
+ delete dlg->wrong_words;
+ dlg->wrong_words = NULL;
+ }
+}
+
+INT_PTR RemoveContactTextBoxService(WPARAM wParam, LPARAM lParam)
+{
+ HWND hwnd = (HWND)wParam;
+ if (hwnd == NULL)
+ return -1;
+
+ return RemoveContactTextBox(hwnd);
+}
+
+int RemoveContactTextBox(HWND hwnd)
+{
+ DialogMapType::iterator dlgit = dialogs.find(hwnd);
+ if (dlgit != dialogs.end()) {
+ Dialog *dlg = dlgit->second;
+
+ KillTimer(hwnd, TIMER_ID);
+
+ mir_unsubclassWindow(hwnd, EditProc);
+ dialogs.erase(hwnd);
+ if (dlg->hwnd_owner != NULL)
+ dialogs.erase(dlg->hwnd_owner);
+
+ delete dlg->re;
+ FreePopupData(dlg);
+ free(dlg);
+ }
+
+ return 0;
+}
+
+// TODO Make this better
+BOOL GetWordCharRange(Dialog *dlg, CHARRANGE &sel, TCHAR *text, size_t text_len, int &first_char)
+{
+ // Get line
+ int line = dlg->re->GetLineFromChar(sel.cpMin);
+
+ // Get text
+ dlg->re->GetLine(line, text, text_len);
+ first_char = dlg->re->GetFirstCharOfLine(line);
+
+ // Find the word
+ sel.cpMin--;
+ while (sel.cpMin >= first_char && (dlg->lang->isWordChar(text[sel.cpMin - first_char])
+ || IsNumber(text[sel.cpMin - first_char])))
+ sel.cpMin--;
+ sel.cpMin++;
+
+ while (text[sel.cpMax - first_char] != _T('\0') && (dlg->lang->isWordChar(text[sel.cpMax - first_char])
+ || IsNumber(text[sel.cpMax - first_char])))
+ sel.cpMax++;
+
+ // Has a word?
+ if (sel.cpMin >= sel.cpMax)
+ return FALSE;
+
+ // See if it has only '-'s
+ BOOL has_valid_char = FALSE;
+ for (int i = sel.cpMin; i < sel.cpMax && !has_valid_char; i++)
+ has_valid_char = (text[i - first_char] != _T('-'));
+
+ return has_valid_char;
+}
+
+TCHAR *GetWordUnderPoint(Dialog *dlg, POINT pt, CHARRANGE &sel)
+{
+ // Get text
+ if (dlg->re->GetTextLength() <= 0)
+ return NULL;
+
+ // Get pos
+ sel.cpMin = sel.cpMax = dlg->re->GetCharFromPos(pt);
+
+ // Get text
+ TCHAR text[1024];
+ int first_char;
+
+ if (!GetWordCharRange(dlg, sel, text, SIZEOF(text), first_char))
+ return NULL;
+
+ // copy the word
+ text[sel.cpMax - first_char] = _T('\0');
+ return _tcsdup(&text[sel.cpMin - first_char]);
+}
+
+
+void AppendSubmenu(HMENU hMenu, HMENU hSubMenu, TCHAR *name)
+{
+ MENUITEMINFO mii = { sizeof(mii) };
+ mii.cbSize = sizeof(MENUITEMINFO);
+ mii.fMask = MIIM_SUBMENU | MIIM_TYPE;
+ mii.fType = MFT_STRING;
+ mii.hSubMenu = hSubMenu;
+ mii.dwTypeData = name;
+ mii.cch = lstrlen(name);
+ InsertMenuItem(hMenu, 0, TRUE, &mii);
+}
+
+void AppendMenuItem(HMENU hMenu, int id, TCHAR *name, HICON hIcon, BOOL checked)
+{
+ ICONINFO iconInfo;
+ GetIconInfo(hIcon, &iconInfo);
+
+ MENUITEMINFO mii = { sizeof(mii) };
+ mii.fMask = MIIM_CHECKMARKS | MIIM_TYPE | MIIM_STATE;
+ mii.fType = MFT_STRING;
+ mii.fState = (checked ? MFS_CHECKED : 0);
+ mii.wID = id;
+ mii.hbmpChecked = iconInfo.hbmColor;
+ mii.hbmpUnchecked = iconInfo.hbmColor;
+ mii.dwTypeData = name;
+ mii.cch = lstrlen(name);
+ InsertMenuItem(hMenu, 0, TRUE, &mii);
+}
+
+#define LANGUAGE_MENU_ID_BASE 10
+#define WORD_MENU_ID_BASE 100
+#define AUTOREPLACE_MENU_ID_BASE 50
+
+void AddMenuForWord(Dialog *dlg, TCHAR *word, CHARRANGE &pos, HMENU hMenu, BOOL in_submenu, UINT base)
+{
+ if (dlg->wrong_words == NULL)
+ dlg->wrong_words = new vector<WrongWordPopupMenuData>(1);
+ else
+ dlg->wrong_words->resize(dlg->wrong_words->size() + 1);
+
+ WrongWordPopupMenuData &data = (*dlg->wrong_words)[dlg->wrong_words->size() - 1];
+ ZeroMemory(&data, sizeof(WrongWordPopupMenuData));
+
+ // Get suggestions
+ data.word = word;
+ data.pos = pos;
+ data.suggestions = dlg->lang->suggest(word);
+
+ Suggestions &suggestions = data.suggestions;
+
+ if (in_submenu) {
+ data.hMeSubMenu = CreatePopupMenu();
+ AppendSubmenu(hMenu, data.hMeSubMenu, word);
+ hMenu = data.hMeSubMenu;
+ }
+
+ data.hReplaceSubMenu = CreatePopupMenu();
+
+ InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + suggestions.count, TranslateT("Other..."));
+ if (suggestions.count > 0) {
+ InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+ for (int i = (int)suggestions.count - 1; i >= 0; i--)
+ InsertMenu(data.hReplaceSubMenu, 0, MF_BYPOSITION, base + AUTOREPLACE_MENU_ID_BASE + i, suggestions.words[i]);
+ }
+
+ AppendSubmenu(hMenu, data.hReplaceSubMenu, TranslateT("Always replace with"));
+
+ InsertMenu(hMenu, 0, MF_BYPOSITION, base + suggestions.count + 1, TranslateT("Ignore all"));
+ InsertMenu(hMenu, 0, MF_BYPOSITION, base + suggestions.count, TranslateT("Add to dictionary"));
+
+ if (suggestions.count > 0) {
+ HMENU hSubMenu;
+ if (opts.cascade_corrections) {
+ hSubMenu = data.hCorrectSubMenu = CreatePopupMenu();
+ AppendSubmenu(hMenu, hSubMenu, TranslateT("Corrections"));
+ }
+ else {
+ InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+ hSubMenu = hMenu;
+ }
+
+ for (int i = (int)suggestions.count - 1; i >= 0; i--)
+ InsertMenu(hSubMenu, 0, MF_BYPOSITION, base + i, suggestions.words[i]);
+ }
+
+ if (!in_submenu && opts.show_wrong_word) {
+ InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+
+ TCHAR text[128];
+ mir_sntprintf(text, SIZEOF(text), TranslateT("Wrong word: %s"), word);
+ InsertMenu(hMenu, 0, MF_BYPOSITION, 0, text);
+ }
+}
+
+struct FoundWrongWordParam
+{
+ Dialog *dlg;
+ int count;
+};
+
+void FoundWrongWord(TCHAR *word, CHARRANGE pos, void *param)
+{
+ FoundWrongWordParam *p = (FoundWrongWordParam*)param;
+
+ p->count++;
+
+ AddMenuForWord(p->dlg, _tcsdup(word), pos, p->dlg->hWrongWordsSubMenu, TRUE, WORD_MENU_ID_BASE * p->count);
+}
+
+void AddItemsToMenu(Dialog *dlg, HMENU hMenu, POINT pt, HWND hwndOwner)
+{
+ FreePopupData(dlg);
+ if (opts.use_flags) {
+ dlg->hwnd_menu_owner = hwndOwner;
+ menus[hwndOwner] = dlg;
+ }
+
+ BOOL wrong_word = FALSE;
+
+ // Make menu
+ if (GetMenuItemCount(hMenu) > 0)
+ InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+
+ if (languages.getCount() > 0 && dlg->enabled) {
+ dlg->hLanguageSubMenu = CreatePopupMenu();
+
+ if (dlg->hwnd_menu_owner != NULL)
+ mir_subclassWindow(dlg->hwnd_menu_owner, MenuWndProc);
+
+ // First add languages
+ for (int i = 0; i < languages.getCount(); i++)
+ AppendMenu(dlg->hLanguageSubMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0),
+ LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name);
+
+ AppendSubmenu(hMenu, dlg->hLanguageSubMenu, TranslateT("Language"));
+ }
+
+ InsertMenu(hMenu, 0, MF_BYPOSITION, 1, TranslateT("Enable spell checking"));
+ CheckMenuItem(hMenu, 1, MF_BYCOMMAND | (dlg->enabled ? MF_CHECKED : MF_UNCHECKED));
+
+ // Get text
+ if (dlg->lang != NULL && dlg->enabled) {
+ if (opts.show_all_corrections) {
+ dlg->hWrongWordsSubMenu = CreatePopupMenu();
+
+ FoundWrongWordParam p = { dlg, 0 };
+ CheckText(dlg, TRUE, FoundWrongWord, &p);
+
+ if (p.count > 0)
+ AppendSubmenu(hMenu, dlg->hWrongWordsSubMenu, TranslateT("Wrong words"));
+ }
+ else {
+ CHARRANGE sel;
+ TCHAR *word = GetWordUnderPoint(dlg, pt, sel);
+ if (word != NULL && !dlg->lang->spell(word)) {
+ InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+ AddMenuForWord(dlg, word, sel, hMenu, FALSE, WORD_MENU_ID_BASE);
+ }
+ }
+ }
+}
+
+
+static void AddWordToDictCallback(BOOL canceled, Dictionary *dict,
+ const TCHAR *find, const TCHAR *replace, BOOL useVariables,
+ const TCHAR *original_find, void *param)
+{
+ if (canceled)
+ return;
+
+ dict->autoReplace->add(find, replace, useVariables);
+
+ HWND hwndParent = (HWND)param;
+ if (hwndParent != NULL)
+ PostMessage(hwndParent, WMU_DICT_CHANGED, 0, 0);
+}
+
+
+BOOL HandleMenuSelection(Dialog *dlg, POINT pt, unsigned selection)
+{
+ BOOL ret = FALSE;
+
+ if (selection == 1) {
+ ToggleEnabled(dlg);
+ ret = TRUE;
+ }
+ else if (selection >= LANGUAGE_MENU_ID_BASE && selection < LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount()) {
+ SetNoUnderline(dlg);
+
+ if (dlg->hContact == NULL)
+ db_set_ts(NULL, MODULE_NAME, dlg->name,
+ languages[selection - LANGUAGE_MENU_ID_BASE]->language);
+ else
+ db_set_ts(dlg->hContact, MODULE_NAME, "TalkLanguage",
+ languages[selection - LANGUAGE_MENU_ID_BASE]->language);
+
+ GetContactLanguage(dlg);
+
+ if (dlg->srmm)
+ ModifyIcon(dlg);
+
+ ret = TRUE;
+ }
+ else if (selection > 0 && dlg->wrong_words != NULL
+ && selection >= WORD_MENU_ID_BASE
+ && selection < (dlg->wrong_words->size() + 1) * WORD_MENU_ID_BASE) {
+ int pos = selection / WORD_MENU_ID_BASE;
+ selection -= pos * WORD_MENU_ID_BASE;
+ pos--; // 0 based
+ WrongWordPopupMenuData &data = (*dlg->wrong_words)[pos];
+
+ if (selection < data.suggestions.count) {
+ // TODO Assert that text hasn't changed
+ ReplaceWord(dlg, data.pos, data.suggestions.words[selection]);
+ ret = TRUE;
+ }
+ else if (selection == data.suggestions.count) {
+ dlg->lang->addWord(data.word);
+ ret = TRUE;
+ }
+ else if (selection == data.suggestions.count + 1) {
+ dlg->lang->ignoreWord(data.word);
+ ret = TRUE;
+ }
+ else if (selection >= AUTOREPLACE_MENU_ID_BASE && selection < AUTOREPLACE_MENU_ID_BASE + data.suggestions.count + 1) {
+ selection -= AUTOREPLACE_MENU_ID_BASE;
+ if (selection == data.suggestions.count) {
+ ShowAutoReplaceDialog(dlg->hwnd_owner != NULL ? dlg->hwnd_owner : dlg->hwnd, FALSE,
+ dlg->lang, data.word, NULL, FALSE,
+ TRUE, &AddWordToDictCallback, dlg->hwnd);
+ }
+ else {
+ // TODO Assert that text hasn't changed
+ ReplaceWord(dlg, data.pos, data.suggestions.words[selection]);
+ dlg->lang->autoReplace->add(data.word, data.suggestions.words[selection]);
+ ret = TRUE;
+ }
+ }
+ }
+
+ if (ret) {
+ KillTimer(dlg->hwnd, TIMER_ID);
+ SetTimer(dlg->hwnd, TIMER_ID, 100, NULL);
+
+ dlg->changed = TRUE;
+ }
+
+ FreePopupData(dlg);
+ return ret;
+}
+
+int MsgWindowPopup(WPARAM wParam, LPARAM lParam)
+{
+ MessageWindowPopupData *mwpd = (MessageWindowPopupData *)lParam;
+ if (mwpd == NULL || mwpd->cbSize < sizeof(MessageWindowPopupData) || mwpd->uFlags != MSG_WINDOWPOPUP_INPUT)
+ return 0;
+
+ DialogMapType::iterator dlgit = dialogs.find(mwpd->hwnd);
+ if (dlgit == dialogs.end())
+ return -1;
+
+ Dialog *dlg = dlgit->second;
+
+ POINT pt = mwpd->pt;
+ ScreenToClient(dlg->hwnd, &pt);
+
+ if (mwpd->uType == MSG_WINDOWPOPUP_SHOWING)
+ AddItemsToMenu(dlg, mwpd->hMenu, pt, dlg->hwnd_owner);
+ else if (mwpd->uType == MSG_WINDOWPOPUP_SELECTED)
+ HandleMenuSelection(dlg, pt, mwpd->selection);
+
+ return 0;
+}
+
+INT_PTR ShowPopupMenuService(WPARAM wParam, LPARAM lParam)
+{
+ SPELLCHECKER_POPUPMENU *scp = (SPELLCHECKER_POPUPMENU *)wParam;
+ if (scp == NULL || scp->cbSize != sizeof(SPELLCHECKER_POPUPMENU))
+ return -1;
+
+ return ShowPopupMenu(scp->hwnd, scp->hMenu, scp->pt, scp->hwndOwner == NULL ? scp->hwnd : scp->hwndOwner);
+}
+
+int ShowPopupMenu(HWND hwnd, HMENU hMenu, POINT pt, HWND hwndOwner)
+{
+ DialogMapType::iterator dlgit = dialogs.find(hwnd);
+ if (dlgit == dialogs.end())
+ return -1;
+
+ Dialog *dlg = dlgit->second;
+
+ if (pt.x == 0xFFFF && pt.y == 0xFFFF) {
+ CHARRANGE sel;
+ SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sel);
+
+ // Get current cursor pos
+ SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)sel.cpMax);
+ }
+ else ScreenToClient(hwnd, &pt);
+
+ BOOL create_menu = (hMenu == NULL);
+ if (create_menu)
+ hMenu = CreatePopupMenu();
+
+ // Make menu
+ AddItemsToMenu(dlg, hMenu, pt, hwndOwner);
+
+ // Show menu
+ POINT client = pt;
+ ClientToScreen(hwnd, &pt);
+ int selection = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, 0, hwndOwner, NULL);
+
+ // Do action
+ if (HandleMenuSelection(dlg, client, selection))
+ selection = 0;
+
+ if (create_menu)
+ DestroyMenu(hMenu);
+
+ return selection;
+}
+
+int MsgWindowEvent(WPARAM wParam, LPARAM lParam)
+{
+ MessageWindowEventData *event = (MessageWindowEventData *)lParam;
+ if (event == NULL)
+ return 0;
+
+ if (event->cbSize < sizeof(MessageWindowEventData))
+ return 0;
+
+ if (event->uType == MSG_WINDOW_EVT_OPEN)
+ AddContactTextBox(event->hContact, event->hwndInput, "DefaultSRMM", TRUE, event->hwndWindow);
+ else if (event->uType == MSG_WINDOW_EVT_CLOSING)
+ RemoveContactTextBox(event->hwndInput);
+
+ return 0;
+}
+
+
+int IconPressed(WPARAM hContact, LPARAM lParam)
+{
+ StatusIconClickData *sicd = (StatusIconClickData *)lParam;
+ if (sicd == NULL || strcmp(sicd->szModule, MODULE_NAME) != 0)
+ return 0;
+
+ if (hContact == NULL)
+ return 0;
+
+ // Find the dialog
+ HWND hwnd = NULL;
+ Dialog *dlg;
+ for (DialogMapType::iterator it = dialogs.begin(); it != dialogs.end(); it++) {
+ dlg = it->second;
+ if (dlg->srmm && dlg->hContact == hContact) {
+ hwnd = it->first;
+ break;
+ }
+ }
+
+ if (hwnd == NULL)
+ return 0;
+
+ if ((sicd->flags & MBCF_RIGHTBUTTON) == 0) {
+ FreePopupData(dlg);
+
+ // Show the menu
+ HMENU hMenu = CreatePopupMenu();
+
+ if (languages.getCount() > 0) {
+ if (opts.use_flags) {
+ menus[dlg->hwnd] = dlg;
+ dlg->hwnd_menu_owner = dlg->hwnd;
+ mir_subclassWindow(dlg->hwnd_menu_owner, MenuWndProc);
+ }
+
+ // First add languages
+ for (int i = 0; i < languages.getCount(); i++)
+ AppendMenu(hMenu, MF_STRING | (languages[i] == dlg->lang ? MF_CHECKED : 0), LANGUAGE_MENU_ID_BASE + i, languages[i]->full_name);
+
+ InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, 0);
+ }
+
+ InsertMenu(hMenu, 0, MF_BYPOSITION, 1, TranslateT("Enable spell checking"));
+ CheckMenuItem(hMenu, 1, MF_BYCOMMAND | (dlg->enabled ? MF_CHECKED : MF_UNCHECKED));
+
+ // Show menu
+ int selection = TrackPopupMenu(hMenu, TPM_RETURNCMD, sicd->clickLocation.x, sicd->clickLocation.y, 0, dlg->hwnd, NULL);
+ HandleMenuSelection(dlg, sicd->clickLocation, selection);
+ DestroyMenu(hMenu);
+ }
+ else {
+ // Enable / disable
+ HandleMenuSelection(dlg, sicd->clickLocation, 1);
+ }
+
+ return 0;
+}
+
+LRESULT CALLBACK MenuWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ DialogMapType::iterator dlgit = menus.find(hwnd);
+ if (dlgit == menus.end())
+ return -1;
+
+ Dialog *dlg = dlgit->second;
+
+ switch (msg) {
+ case WM_INITMENUPOPUP:
+ {
+ HMENU hMenu = (HMENU)wParam;
+
+ int count = GetMenuItemCount(hMenu);
+ for (int i = 0; i < count; i++) {
+ unsigned id = GetMenuItemID(hMenu, i);
+ if (id < LANGUAGE_MENU_ID_BASE || id >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
+ continue;
+
+ MENUITEMINFO mii = { 0 };
+ mii.cbSize = sizeof(MENUITEMINFO);
+ mii.fMask = MIIM_STATE;
+ GetMenuItemInfo(hMenu, id, FALSE, &mii);
+
+ // Make ownerdraw
+ ModifyMenu(hMenu, id, mii.fState | MF_BYCOMMAND | MF_OWNERDRAW, id, NULL);
+ }
+ }
+ break;
+
+ case WM_DRAWITEM:
+ {
+ LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
+ if (lpdis->CtlType != ODT_MENU || lpdis->itemID < LANGUAGE_MENU_ID_BASE || lpdis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
+ break;
+
+ int pos = lpdis->itemID - LANGUAGE_MENU_ID_BASE;
+
+ Dictionary *dict = languages[pos];
+
+ COLORREF clrfore = SetTextColor(lpdis->hDC,
+ GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT));
+ COLORREF clrback = SetBkColor(lpdis->hDC,
+ GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU));
+
+ FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_MENU));
+
+ RECT rc = lpdis->rcItem;
+ rc.left += 2;
+
+ // Checked?
+ rc.right = rc.left + bmpChecked.bmWidth;
+
+ if (lpdis->itemState & ODS_CHECKED) {
+ rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - bmpChecked.bmHeight) / 2;
+ rc.bottom = rc.top + bmpChecked.bmHeight;
+
+ HDC hdcTemp = CreateCompatibleDC(lpdis->hDC);
+ HBITMAP oldBmp = (HBITMAP)SelectObject(hdcTemp, hCheckedBmp);
+
+ BitBlt(lpdis->hDC, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hdcTemp, 0, 0, SRCCOPY);
+
+ SelectObject(hdcTemp, oldBmp);
+ DeleteDC(hdcTemp);
+ }
+
+ rc.left += bmpChecked.bmWidth + 2;
+
+ // Draw icon
+ if (dict->hIcolib) {
+ HICON hFlag = Skin_GetIconByHandle(dict->hIcolib);
+
+ rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - ICON_SIZE) / 2;
+ DrawIconEx(lpdis->hDC, rc.left, rc.top, hFlag, 16, 16, 0, NULL, DI_NORMAL);
+
+ Skin_ReleaseIcon(hFlag);
+
+ rc.left += ICON_SIZE + 4;
+ }
+
+ // Draw text
+ RECT rc_text = { 0, 0, 0xFFFF, 0xFFFF };
+ DrawText(lpdis->hDC, dict->full_name, lstrlen(dict->full_name), &rc_text, DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT);
+
+ rc.right = lpdis->rcItem.right - 2;
+ rc.top = (lpdis->rcItem.bottom + lpdis->rcItem.top - (rc_text.bottom - rc_text.top)) / 2;
+ rc.bottom = rc.top + rc_text.bottom - rc_text.top;
+ DrawText(lpdis->hDC, dict->full_name, lstrlen(dict->full_name), &rc, DT_END_ELLIPSIS | DT_NOPREFIX | DT_LEFT | DT_TOP | DT_SINGLELINE);
+
+ // Restore old colors
+ SetTextColor(lpdis->hDC, clrfore);
+ SetBkColor(lpdis->hDC, clrback);
+ }
+ return TRUE;
+
+ case WM_MEASUREITEM:
+ LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam;
+ if (lpmis->CtlType != ODT_MENU || lpmis->itemID < LANGUAGE_MENU_ID_BASE || lpmis->itemID >= LANGUAGE_MENU_ID_BASE + (unsigned)languages.getCount())
+ break;
+
+ int pos = lpmis->itemID - LANGUAGE_MENU_ID_BASE;
+
+ Dictionary *dict = languages[pos];
+
+ HDC hdc = GetDC(hwnd);
+
+ NONCLIENTMETRICS info;
+ ZeroMemory(&info, sizeof(info));
+ info.cbSize = sizeof(info);
+ SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
+ HFONT hFont = CreateFontIndirect(&info.lfMenuFont);
+ HFONT hFontOld = (HFONT)SelectObject(hdc, hFont);
+
+ RECT rc = { 0, 0, 0xFFFF, 0xFFFF };
+
+ DrawText(hdc, dict->full_name, lstrlen(dict->full_name), &rc, DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_TOP | DT_CALCRECT);
+
+ lpmis->itemHeight = max(ICON_SIZE, max(bmpChecked.bmHeight, rc.bottom));
+ lpmis->itemWidth = 2 + bmpChecked.bmWidth + 2 + ICON_SIZE + 4 + rc.right + 2;
+
+ SelectObject(hdc, hFontOld);
+ DeleteObject(hFont);
+ ReleaseDC(hwnd, hdc);
+
+ return TRUE;
+ }
+
+ return mir_callNextSubclass(hwnd, MenuWndProc, msg, wParam, lParam);
+}
+
+TCHAR* lstrtrim(TCHAR *str)
+{
+ int len = lstrlen(str);
+
+ int i;
+ for (i = len - 1; i >= 0 && (str[i] == ' ' || str[i] == '\t'); --i);
+ if (i < len - 1) {
+ ++i;
+ str[i] = _T('\0');
+ len = i;
+ }
+
+ for (i = 0; i < len && (str[i] == ' ' || str[i] == '\t'); ++i);
+ if (i > 0)
+ memmove(str, &str[i], (len - i + 1) * sizeof(TCHAR));
+
+ return str;
+}
+
+BOOL lstreq(TCHAR *a, TCHAR *b, size_t len)
+{
+ a = CharLower(_tcsdup(a));
+ b = CharLower(_tcsdup(b));
+ BOOL ret;
+ if (len >= 0)
+ ret = !_tcsncmp(a, b, len);
+ else
+ ret = !_tcscmp(a, b);
+ free(a);
+ free(b);
+ return ret;
+}