Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

485 lines
12 KiB

  1. /*
  2. * _COMMON.H
  3. *
  4. * Purpose:
  5. * MSFTEDIT private common definitions
  6. *
  7. * Copyright (c) 1995-2001, Microsoft Corporation. All rights reserved.
  8. */
  9. #ifndef _COMMON_H
  10. #define _COMMON_H
  11. // REVIEW macro.
  12. //
  13. #define __LINE(l) #l
  14. #define __LINE_(l) __LINE(l)
  15. #define _LINE_ __LINE_(__LINE__)
  16. #define REVIEW __FILE__ "(" __LINE_(__LINE__) ") : "
  17. #pragma message ("Compiling Common.H")
  18. #ifdef NT
  19. #ifndef WINNT
  20. #define WINNT
  21. #endif
  22. #endif
  23. #ifndef _UNICODE
  24. #define _UNICODE
  25. #endif
  26. #ifndef STRICT
  27. #define STRICT
  28. #endif
  29. #define NOSHELLDEBUG //disables asserts in shell.h
  30. // Build dependent conditional definitions
  31. #if defined(EBOOK_CE)
  32. #define NOACCESSIBILITY
  33. #define NOMAGELLAN
  34. #define NODROPFILES
  35. #define NOMETAFILES
  36. #define NOFONTSUBINFO
  37. #define NOFEPROCESSING
  38. #define NOPRIVATEMESSAGE
  39. #define NOCOMPLEXSCRIPTS
  40. #define NODELAYLOAD
  41. #define NOANSIWINDOWS
  42. //#define NOWINDOWHOSTS - need hosted window for text boxes
  43. #define NORIGHTTOLEFT
  44. #define NOAUTOFONT
  45. #define NOPLAINTEXT
  46. #define NOPALETTE
  47. #define NOLISTCOMBOBOXES
  48. #define NOFULLDEBUG
  49. #define THICKCARET
  50. #define LIMITEDMEMORY
  51. #define SLOWCPU
  52. #define NOREGISTERTYPELIB
  53. #define NODRAGDROP
  54. #define NOWORDBREAKPROC
  55. #define NORBUTTON
  56. #define NODRAFTMODE
  57. #define NOVERSIONINFO
  58. #define NOINKOBJECT
  59. #define W32INCLUDE "w32wince.cpp"
  60. #pragma warning (disable : 4702)
  61. #else // Normal build
  62. #define W32INCLUDE "w32win32.cpp"
  63. #endif
  64. #define WINVER 0x0500
  65. // 4201 : nameless struct/union
  66. // 4514 : unreferenced inline function has been removed
  67. // 4505 : unreferenced local function has been removed
  68. #pragma warning (disable : 4201 4514 4505)
  69. #ifdef NOFULLDEBUG
  70. // 4800 : forcing value to bool 'true' or 'false' (performance warning)
  71. #pragma warning (disable : 4800)
  72. #endif
  73. #include <limits.h>
  74. #if defined(DEBUG) && !defined(NOFULLDEBUG)
  75. #include <stdio.h>
  76. #endif
  77. #include <windows.h>
  78. #include <windowsx.h>
  79. #ifndef NOACCESSIBILITY
  80. #include <winable.h>
  81. #endif
  82. #include "imm.h"
  83. /*
  84. * Types
  85. */
  86. #include <ourtypes.h>
  87. #define QWORD UINT64 // 64 flags used for CharFlags
  88. // for the benefit of the outside world, richedit.h uses cpMax instead
  89. // of cpMost. I highly prefer cpMost
  90. #ifdef cpMax
  91. #error "cpMax hack won't work"
  92. #endif
  93. //Everyone should call the W32->GetObject define and this makes calls to
  94. //Win32 GetObject fail.
  95. #undef GetObject
  96. #define cpMax cpMost
  97. #include <richedit.h>
  98. #include <richole.h>
  99. #undef cpMax
  100. #include "_debug.h"
  101. // Return TRUE if LF <= ch <= CR. NB: ch must be unsigned;
  102. // WCHAR and unsigned short give wrong results!
  103. #define IN_RANGE(n1, b, n2) ((unsigned)((b) - (n1)) <= unsigned((n2) - (n1)))
  104. #define IsASCIIDigit(b) IN_RANGE('0', b, '9')
  105. #define IsASCIIEOP(ch) IN_RANGE(LF, ch, CR)
  106. #define IsZerowidthCharacter(ch) IN_RANGE(ZWSP, ch, RTLMARK)
  107. // disable
  108. // 4710 : function not inlined
  109. // 4512 : assignment operator not generated
  110. // 4201 : nameless struct union
  111. // 4100 : unreferenced formal;
  112. // 4706 : assignment within conditional expression (oould be bad, but common)
  113. // 4127 : conditional expression is constant (if (1))
  114. // 4242 : truncation warning
  115. // 4244 : truncation warning
  116. // 4267 : conversion from 'size_t' to 'int'
  117. #pragma warning (disable : 4710 4512 4201 4100 4127 4706 4242 4244 4267)
  118. #pragma warning(3:4121) // structure is sensitive to alignment
  119. #pragma warning(3:4130) // logical operation on address of string constant
  120. #pragma warning(3:4132) // const object should be initialized
  121. #pragma warning(3:4509) // use of SEH with destructor
  122. #include "resource.h"
  123. // Use explicit ASCII values for LF and CR, since MAC compilers
  124. // interchange values of '\r' and '\n'
  125. #define CELL 7
  126. #define TAB TEXT('\t')
  127. #define LF 10
  128. #define VT TEXT('\v')
  129. #define FF 12
  130. #define CR 13
  131. #define BOM 0xFEFF
  132. #define BULLET 0x2022
  133. #define EMDASH 0x2014
  134. #define EMSPACE 0x2003
  135. #define ENDASH 0x2013
  136. #define ENQUAD 0x2000
  137. #define ENSPACE 0x2002
  138. #define EURO 0x20AC
  139. #define KASHIDA 0x640
  140. #define LDBLQUOTE 0x201c
  141. #define LQUOTE 0x2018
  142. #define LTRMARK 0x200E
  143. #define NBSPACE 0xA0
  144. #define NBHYPHEN 0x2011
  145. #define NOTACHAR 0xFFFF
  146. #define PS 0x2029
  147. #define RBOM 0xFFFE
  148. #define RDBLQUOTE 0x201D
  149. #define RQUOTE 0x2019
  150. #define RTLMARK 0x200F
  151. #define SOFTHYPHEN 0xAD
  152. #define TRD // Table Row Delimiter (START/ENDFIELD CR)
  153. #define UTF16 0xDC00
  154. #define UTF16_LEAD 0xD800
  155. #define UTF16_TRAIL 0xDC00
  156. #define ZWJ 0x200D
  157. #define ZWNJ 0x200C
  158. #define ZWSP 0x200B
  159. #define STARTFIELD 0xFFF9
  160. #define SEPARATOR 0xFFFA
  161. #define ENDFIELD 0xFFFB
  162. /*
  163. * IsEOP(ch)
  164. *
  165. * @func
  166. * Used to determine if ch is an EOP char, i.e., CR, LF, VT, FF, CELL,
  167. * PS, or LS (Unicode paragraph/line separator). For speed, this
  168. * function is inlined.
  169. *
  170. * @rdesc
  171. * TRUE if ch is an end-of-paragraph char
  172. */
  173. __inline BOOL IsEOP(unsigned ch)
  174. {
  175. return IN_RANGE(CELL, ch, CR) && ch != TAB || (ch | 1) == PS;
  176. }
  177. BOOL IsRTF(char *pstr, LONG cb);
  178. #include <tom.h>
  179. #define CP_INFINITE tomForward
  180. #include "zmouse.h"
  181. #include "_util.h"
  182. #ifdef DEBUG
  183. #define EM_DBGPED (WM_USER + 150)
  184. #endif
  185. #define EM_GETCODEPAGE (WM_USER + 151)
  186. // MIN
  187. #ifdef min
  188. #undef min
  189. #endif
  190. #define __min(a,b) (((a) < (b)) ? (a) : (b))
  191. inline int min(int v1, int v2) {return __min(v1, v2);}
  192. inline UINT min(UINT v1, UINT v2) {return __min(v1, v2);}
  193. inline float min(float v1, float v2) {return __min(v1, v2);}
  194. inline double min(double v1, double v2) {return __min(v1, v2);}
  195. inline __int64 min(__int64 v1, __int64 v2) {return __min(v1, v2);}
  196. // MAX
  197. #ifdef max
  198. #undef max
  199. #endif
  200. #define __max(a,b) (((a) > (b)) ? (a) : (b))
  201. inline int max(int v1, int v2) {return __max(v1, v2);}
  202. inline UINT max(UINT v1, UINT v2) {return __max(v1, v2);}
  203. inline float max(float v1, float v2) {return __max(v1, v2);}
  204. inline double max(double v1, double v2) {return __max(v1, v2);}
  205. inline __int64 max(__int64 v1, __int64 v2) {return __max(v1, v2);}
  206. // ABS
  207. #ifdef abs
  208. #undef abs
  209. #endif
  210. #define __abs(a) (((a) < 0) ? 0 - (a) : (a))
  211. #pragma function(abs)
  212. inline int __cdecl abs(int v) {return __abs(v);}
  213. inline float abs(float v) {return __abs(v);}
  214. inline double abs(double v) {return __abs(v);}
  215. inline __int64 abs(__int64 v) {return __abs(v);}
  216. #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
  217. #include "_cfpf.h"
  218. // Interesting OS versions
  219. #define VERS4 4
  220. // conversions between byte and character counts
  221. #define CbOfCch(_x) ((_x) * 2)
  222. #define CchOfCb(_x) ((_x) / 2)
  223. #define cKinsokuCategories 16
  224. #define OLEstrcmp wcscmp
  225. #define OLEstrcpy wcscpy
  226. #define OLEsprintf wsprintf
  227. #define OLEstrlen wcslen
  228. // index (window long) of the PED
  229. #define ibPed 0
  230. // Timer ids
  231. #define RETID_BGND_RECALC 0x01af
  232. #define RETID_AUTOSCROLL 0x01b0
  233. #define RETID_SMOOTHSCROLL 0x01b1
  234. #define RETID_DRAGDROP 0x01b2
  235. #define RETID_MAGELLANTRACK 0x01b3
  236. #define RETID_VISEFFECTS 0x01b4
  237. // Timer id when mouse is captured
  238. #define ID_LB_CAPTURE 28988
  239. #define ID_LB_CAPTURE_DEFAULT 250 // duration
  240. // Timer id when type search is required
  241. #define ID_LB_SEARCH 28989
  242. #define ID_LB_SEARCH_DEFAULT 1250 // duration 1.25 second
  243. // Count of characters in CRLF marker
  244. #define cchCRLF 2
  245. #define cchCR 1
  246. // RichEdit 1.0 uses a CRLF for an EOD marker
  247. #define CCH_EOD_10 2
  248. // RichEdit 2.0 uses a simple CR for the EOD marker
  249. #define CCH_EOD_20 1
  250. extern const WCHAR szCRLF[];
  251. extern const WCHAR szCR[];
  252. extern HINSTANCE hinstRE; // DLL instance
  253. #include <shellapi.h>
  254. #ifdef DUAL_FORMATETC
  255. #undef DUAL_FORMATETC
  256. #endif
  257. #define DUAL_FORMATETC FORMATETC
  258. extern "C"
  259. {
  260. LRESULT CALLBACK RichEditWndProc(HWND, UINT, WPARAM, LPARAM);
  261. LRESULT CALLBACK RichEditANSIWndProc(HWND, UINT, WPARAM, LPARAM);
  262. }
  263. // Multi-Threading support
  264. extern CRITICAL_SECTION g_CriticalSection;
  265. // a class to simplify critical section management
  266. class CLock
  267. {
  268. public:
  269. CLock()
  270. {
  271. EnterCriticalSection(&g_CriticalSection);
  272. }
  273. ~CLock()
  274. {
  275. LeaveCriticalSection(&g_CriticalSection);
  276. }
  277. };
  278. enum HITTEST
  279. {
  280. HT_Undefined = 0, // Hit hasn't been determined
  281. HT_Nothing,
  282. HT_OutlineSymbol,
  283. HT_LeftOfText,
  284. HT_BulletArea,
  285. HT_RightOfText,
  286. HT_BelowText,
  287. HT_AboveScreen,
  288. HT_Text, // All hits are in text from HT_Text on so
  289. HT_Link, // if(hit >= HT_Text) identifies text of some kind
  290. HT_Italic,
  291. HT_Object
  292. };
  293. typedef BYTE TFLOW;
  294. #define tflowES 0 //Latin
  295. #define tflowSW 1 //Vertical
  296. #define tflowWN 2 //Upside down
  297. #define tflowNE 3
  298. const inline BOOL IsUVerticalTflow(TFLOW tflow)
  299. {
  300. return tflow & 0x00000001L;
  301. }
  302. //This has the same names as RECT, but is of a different
  303. //type so that the compiler can assist us in writing proper code.
  304. struct RECTUV
  305. {
  306. long left;
  307. long top;
  308. long right;
  309. long bottom;
  310. };
  311. struct SIZEUV
  312. {
  313. LONG du;
  314. LONG dv;
  315. };
  316. #ifdef NOLINESERVICES
  317. typedef struct tagPOINTUV
  318. {
  319. LONG u;
  320. LONG v;
  321. } POINTUV;
  322. #endif //NOLINESERVICES
  323. #define ST_CHECKPROTECTION 0x8000
  324. #define ST_10REPLACESEL 0x10000000
  325. #define ST_10WM_SETTEXT 0x20000000
  326. /* REListbox1.0 Window Class. */
  327. // For Windows CE to avaoid possible conflicts on WIn95.
  328. #define CELISTBOX_CLASSA "REListBoxCEA"
  329. #define CELISTBOX_CLASSW L"REListBoxCEW"
  330. #define LISTBOX_CLASSW L"REListBox50W"
  331. #define COMBOBOX_CLASSW L"REComboBox50W"
  332. #ifdef DEBUG
  333. //Debug api for dumping CTxtStory arrays.
  334. extern "C" {
  335. extern void DumpDoc(void *);
  336. }
  337. #endif
  338. #ifndef NOLINESERVICES
  339. #include "_ls.h"
  340. #endif
  341. // Our Win32 wrapper class
  342. #include "_w32sys.h"
  343. typedef BOOL (WINAPI *AutoCorrectProc)(LANGID langid, const WCHAR *pszBefore, WCHAR *pszAfter, LONG cchAfter, LONG *pcchReplaced);
  344. #define EM_GETAUTOCORRECTPROC (WM_USER + 233)
  345. #define EM_SETAUTOCORRECTPROC (WM_USER + 234)
  346. #define EM_INSERTTABLE (WM_USER + 232)
  347. typedef struct _tableRowParms
  348. { // EM_INSERTTABLE wparam is a (TABLEROWPARMS *)
  349. BYTE cbRow; // Count of bytes in this structure
  350. BYTE cbCell; // Count of bytes in TABLECELLPARMS
  351. BYTE cCell; // Count of cells
  352. BYTE cRow; // Count of rows
  353. LONG dxCellMargin; // Cell left/right margin (\trgaph)
  354. LONG dxIndent; // Row left (right if fRTL indent (similar to \trleft)
  355. LONG dyHeight; // Row height (\trrh)
  356. DWORD nAlignment:3; // Row alignment (like PARAFORMAT::bAlignment, \trql, trqr, \trqc)
  357. DWORD fRTL:1; // Display cells in RTL order (\rtlrow)
  358. DWORD fKeep:1; // Keep row together (\trkeep}
  359. DWORD fKeepFollow:1; // Keep row on same page as following row (\trkeepfollow)
  360. DWORD fWrap:1; // Wrap text to right/left (depending on bAlignment)
  361. // (see \tdfrmtxtLeftN, \tdfrmtxtRightN)
  362. DWORD fIdentCells:1; // lparam points at single struct valid for all cells
  363. } TABLEROWPARMS;
  364. typedef struct _tableCellParms
  365. { // EM_INSERTTABLE lparam is a (TABLECELLPARMS *)
  366. LONG dxWidth; // Cell width (\cellx)
  367. WORD nVertAlign:2; // Vertical alignment (0/1/2 = top/center/bottom
  368. // \clvertalt (def), \clvertalc, \clvertalb)
  369. WORD fMergeTop:1; // Top cell for vertical merge (\clvmgf)
  370. WORD fMergePrev:1; // Merge with cell above (\clvmrg)
  371. WORD fVertical:1; // Display text top to bottom, right to left (\cltxtbrlv)
  372. WORD wShading; // Shading in .01% (\clshdng) e.g., 10000 flips fore/back
  373. SHORT dxBrdrLeft; // Left border width (\clbrdrl\brdrwN) (in twips)
  374. SHORT dyBrdrTop; // Top border width (\clbrdrt\brdrwN)
  375. SHORT dxBrdrRight; // Right border width (\clbrdrr\brdrwN)
  376. SHORT dyBrdrBottom; // Bottom border width (\clbrdrb\brdrwN)
  377. COLORREF crBrdrLeft; // Left border color (\clbrdrl\brdrcf)
  378. COLORREF crBrdrTop; // Top border color (\clbrdrt\brdrcf)
  379. COLORREF crBrdrRight; // Right border color (\clbrdrr\brdrcf)
  380. COLORREF crBrdrBottom; // Bottom border color (\clbrdrb\brdrcf)
  381. COLORREF crBackPat; // Background color (\clcbpat)
  382. COLORREF crForePat; // Foreground color (\clcfpat)
  383. } TABLECELLPARMS;
  384. // This interface enables clients to do custom rendering. Return FALSE for
  385. // GetCharWidthW and RichEdit will call the OS to fetch character widths.
  386. interface ICustomTextOut
  387. {
  388. virtual BOOL WINAPI ExtTextOutW(HDC, int, int, UINT, CONST RECT *, LPCWSTR, UINT, CONST INT *) = 0;
  389. virtual BOOL WINAPI GetCharWidthW(HDC, UINT, UINT, LPINT) = 0;
  390. virtual BOOL WINAPI NotifyCreateFont(HDC) = 0;
  391. virtual void WINAPI NotifyDestroyFont(HFONT) = 0;
  392. };
  393. STDAPI SetCustomTextOutHandlerEx(ICustomTextOut **ppcto, DWORD dwFlags);
  394. #endif