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.

480 lines
19 KiB

  1. #if !defined(__Edit_h__INCLUDED)
  2. #define __Edit_h__INCLUDED
  3. //
  4. // Problems arising with edit control and DrawThemeText cause us not to
  5. // render text using theme APIs. However, we still want to use a theme
  6. // handle to draw out client edge.
  7. // Uncomment the following to turn on theme defined text rendering
  8. // #define _USE_DRAW_THEME_TEXT_
  9. //
  10. //
  11. // Edit WndProc Prototype
  12. //
  13. extern LRESULT Edit_WndProc(
  14. HWND hwnd,
  15. UINT uMsg,
  16. WPARAM wParam,
  17. LPARAM lParam);
  18. #define DF_WINDOWFRAME (COLOR_WINDOWFRAME << 3)
  19. //
  20. // Edit macros
  21. //
  22. //
  23. // Instance data pointer access functions
  24. //
  25. #define Edit_GetPtr(hwnd) \
  26. (PED)GetWindowPtr(hwnd, 0)
  27. #define Edit_SetPtr(hwnd, p) \
  28. (PED)SetWindowPtr(hwnd, 0, p)
  29. //
  30. // We don't need 64-bit intermediate precision so we use this macro
  31. // instead of calling MulDiv.
  32. //
  33. #define MultDiv(x, y, z) \
  34. (((INT)(x) * (INT)(y) + (INT)(z) / 2) / (INT)(z))
  35. #define ISDELIMETERA(ch) \
  36. ((ch == ' ') || (ch == '\t'))
  37. #define ISDELIMETERW(ch) \
  38. ((ch == L' ') || (ch == L'\t'))
  39. #define AWCOMPARECHAR(ped,pbyte,awchar) \
  40. (ped->fAnsi ? (*(PUCHAR)(pbyte) == (UCHAR)(awchar)) : (*(LPWSTR)(pbyte) == (WCHAR)(awchar)))
  41. #define CALLWORDBREAKPROC(proc, pText, iStart, cch, iAction) \
  42. (* proc)(pText, iStart, cch, iAction)
  43. #ifndef NULL_HIMC
  44. #define NULL_HIMC (HIMC) 0
  45. #endif
  46. #define EditWndProc EditWndProcW
  47. #define SYS_ALTERNATE 0x2000
  48. #define FAREAST_CHARSET_BITS (FS_JISJAPAN | FS_CHINESESIMP | FS_WANSUNG | FS_CHINESETRAD)
  49. //
  50. // Length of the buffer for ASCII character width caching: for characters
  51. // 0x00 to 0xff (field charWidthBuffer in PED structure below).
  52. // As the upper half of the cache was not used by almost anyone and fixing
  53. // it's usage required a lot of conversion, we decided to get rid of it
  54. // MCostea #174031
  55. //
  56. #define CHAR_WIDTH_BUFFER_LENGTH 128
  57. //
  58. // NOTE: Text handle is sized as multiple of this constant
  59. // (should be power of 2).
  60. //
  61. #define CCHALLOCEXTRA 0x20
  62. //
  63. // Maximum width in pixels for a line/rectangle
  64. //
  65. #define MAXPIXELWIDTH 30000
  66. #define MAXCLIPENDPOS 32764
  67. //
  68. // Limit multiline edit controls to at most 1024 characters on a single line.
  69. // We will force a wrap if the user exceeds this limit.
  70. //
  71. #define MAXLINELENGTH 1024
  72. //
  73. // Allow an initial maximum of 30000 characters in all edit controls since
  74. // some apps will run into unsigned problems otherwise. If apps know about
  75. // the 64K limit, they can set the limit themselves.
  76. //
  77. #define MAXTEXT 30000
  78. //
  79. // Key modifiers which have been pressed. Code in KeyDownHandler and
  80. // CharHandler depend on these exact values.
  81. //
  82. #define NONEDOWN 0 // Neither shift nor control down
  83. #define CTRLDOWN 1 // Control key only down
  84. #define SHFTDOWN 2 // Shift key only down
  85. #define SHCTDOWN 3 // Shift and control keys down = CTRLDOWN + SHFTDOWN
  86. #define NOMODIFY 4 // Neither shift nor control down
  87. #define IDSYS_SCROLL 0x0000FFFEL
  88. //
  89. // ECTabTheTextOut draw codes
  90. //
  91. #define ECT_CALC 0
  92. #define ECT_NORMAL 1
  93. #define ECT_SELECTED 2
  94. typedef DWORD ICH;
  95. typedef ICH *LPICH;
  96. //
  97. // Types of undo supported in this ped
  98. //
  99. #define UNDO_NONE 0 // We can't undo the last operation.
  100. #define UNDO_INSERT 1 // We can undo the user's insertion of characters
  101. #define UNDO_DELETE 2 // We can undo the user's deletion of characters
  102. typedef struct
  103. {
  104. DWORD fDisableCut : 1;
  105. DWORD fDisablePaste : 1;
  106. DWORD fNeedSeparatorBeforeImeMenu : 1;
  107. DWORD fIME : 1;
  108. } EditMenuItemState;
  109. //
  110. // The following structure is used to store a selection block; In Multiline
  111. // edit controls, "StPos" and "EndPos" fields contain the Starting and Ending
  112. // lines of the block. In Single line edit controls, "StPos" and "EndPos"
  113. // contain the Starting and Ending character positions of the block;
  114. //
  115. typedef struct tagSELBLOCK
  116. {
  117. ICH StPos;
  118. ICH EndPos;
  119. } SELBLOCK, *LPSELBLOCK;
  120. //
  121. // The following structure is used to store complete information about a
  122. // a strip of text.
  123. //
  124. typedef struct
  125. {
  126. LPSTR lpString;
  127. ICH ichString;
  128. ICH nCount;
  129. int XStartPos;
  130. } STRIPINFO;
  131. typedef STRIPINFO *LPSTRIPINFO;
  132. typedef struct tagUNDO
  133. {
  134. UINT undoType; // Current type of undo we support
  135. PBYTE hDeletedText; // Pointer to text which has been deleted (for
  136. // undo) -- note, the memory is allocated as fixed
  137. ICH ichDeleted; // Starting index from which text was deleted
  138. ICH cchDeleted; // Count of deleted characters in buffer
  139. ICH ichInsStart; // Starting index from which text was inserted
  140. ICH ichInsEnd; // Ending index of inserted text
  141. } UNDO, *PUNDO;
  142. #define Pundo(ped) ((PUNDO)&(ped)->undoType)
  143. typedef struct tagED0 *PED0;
  144. //
  145. // Language pack edit control callouts.
  146. //
  147. // Functions are accessed through the pLpkEditCallout pointer in the ED
  148. // structure. pLpkEditCallout points to a structure containing a pointer
  149. // to each callout routine.
  150. //
  151. #define DECLARE_LPK_CALLOUT(_ret, _fn, _args) \
  152. _ret (__stdcall *##_fn) _args
  153. typedef struct tagLPKEDITCALLOUT
  154. {
  155. DECLARE_LPK_CALLOUT(BOOL, EditCreate, (PED0, HWND));
  156. DECLARE_LPK_CALLOUT(INT, EditIchToXY, (PED0, HDC, PSTR, ICH, ICH));
  157. DECLARE_LPK_CALLOUT(ICH, EditMouseToIch, (PED0, HDC, PSTR, ICH, INT));
  158. DECLARE_LPK_CALLOUT(ICH, EditCchInWidth, (PED0, HDC, PSTR, ICH, INT));
  159. DECLARE_LPK_CALLOUT(INT, EditGetLineWidth, (PED0, HDC, PSTR, ICH));
  160. DECLARE_LPK_CALLOUT(VOID, EditDrawText, (PED0, HDC, PSTR, INT, INT, INT, INT));
  161. DECLARE_LPK_CALLOUT(BOOL, EditHScroll, (PED0, HDC, PSTR));
  162. DECLARE_LPK_CALLOUT(ICH, EditMoveSelection, (PED0, HDC, PSTR, ICH, BOOL));
  163. DECLARE_LPK_CALLOUT(INT, EditVerifyText, (PED0, HDC, PSTR, ICH, PSTR, ICH));
  164. DECLARE_LPK_CALLOUT(VOID, EditNextWord , (PED0, HDC, PSTR, ICH, BOOL, LPICH, LPICH));
  165. DECLARE_LPK_CALLOUT(VOID, EditSetMenu, (PED0, HMENU));
  166. DECLARE_LPK_CALLOUT(INT, EditProcessMenu, (PED0, UINT));
  167. DECLARE_LPK_CALLOUT(INT, EditCreateCaret, (PED0, HDC, INT, INT, UINT));
  168. DECLARE_LPK_CALLOUT(ICH, EditAdjustCaret, (PED0, HDC, PSTR, ICH));
  169. } LPKEDITCALLOUT, *PLPKEDITCALLOUT;
  170. PLPKEDITCALLOUT g_pLpkEditCallout;
  171. #if defined(BUILD_WOW6432)
  172. //
  173. // In user a PWND is actually pointer to kernel memory, so
  174. // it needs to be 64-bits on wow6432 as well.
  175. //
  176. typedef VOID * _ptr64 PWND;
  177. #else
  178. typedef VOID * PWND;
  179. #endif
  180. //
  181. // ! WARNING ! Don't modify this struct. This is is the same user32's tagED struct.
  182. // Unfortunately the EditLpk callouts expect that struct. Change the
  183. // tagED struct below.
  184. //
  185. typedef struct tagED0
  186. {
  187. HANDLE hText; // Block of text we are editing
  188. ICH cchAlloc; // Number of chars we have allocated for hText
  189. ICH cchTextMax; // Max number bytes allowed in edit control
  190. ICH cch; // Current number of bytes of actual text
  191. ICH cLines; // Number of lines of text
  192. ICH ichMinSel; // Selection extent. MinSel is first selected char
  193. ICH ichMaxSel; // MaxSel is first unselected character
  194. ICH ichCaret; // Caret location. Caret is on left side of char
  195. ICH iCaretLine; // The line the caret is on. So that if word
  196. // wrapping, we can tell if the caret is at end
  197. // of a line of at beginning of next line...
  198. ICH ichScreenStart; // Index of left most character displayed on
  199. // screen for sl ec and index of top most line
  200. // for multiline edit controls
  201. ICH ichLinesOnScreen; // Number of lines we can display on screen
  202. UINT xOffset; // x (horizontal) scroll position in pixels
  203. // (for multiline text horizontal scroll bar)
  204. UINT charPasswordChar; // If non null, display this character instead
  205. // of the real text. So that we can implement
  206. // hidden text fields.
  207. INT cPasswordCharWidth; // Width of password char
  208. HWND hwnd; // Window for this edit control
  209. PWND pwnd; // placeholder for compatability with user's PED struct
  210. RECT rcFmt; // Client rectangle
  211. HWND hwndParent; // Parent of this edit control window
  212. // These vars allow us to automatically scroll
  213. // when the user holds the mouse at the bottom
  214. // of the multiline edit control window.
  215. POINT ptPrevMouse; // Previous point for the mouse for system timer.
  216. UINT prevKeys; // Previous key state for the mouse
  217. UINT fSingle : 1; // Single line edit control? (or multiline)
  218. UINT fNoRedraw : 1; // Redraw in response to a change?
  219. UINT fMouseDown : 1; // Is mouse button down? when moving mouse
  220. UINT fFocus : 1; // Does ec have the focus?
  221. UINT fDirty : 1; // Modify flag for the edit control
  222. UINT fDisabled : 1; // Window disabled?
  223. UINT fNonPropFont : 1; // Fixed width font?
  224. UINT fNonPropDBCS : 1; // Non-Propotional DBCS font
  225. UINT fBorder : 1; // Draw a border?
  226. UINT fAutoVScroll : 1; // Automatically scroll vertically
  227. UINT fAutoHScroll : 1; // Automatically scroll horizontally
  228. UINT fNoHideSel : 1; // Hide sel when we lose focus?
  229. UINT fDBCS : 1; // Are we using DBCS font set for editing?
  230. UINT fFmtLines : 1; // For multiline only. Do we insert CR CR LF at
  231. // word wrap breaks?
  232. UINT fWrap : 1; // Do int wrapping?
  233. UINT fCalcLines : 1; // Recalc ped->chLines array? (recalc line breaks?)
  234. UINT fEatNextChar : 1; // Hack for ALT-NUMPAD stuff with combo boxes.
  235. // If numlock is up, we want to eat the next
  236. // character generated by the keyboard driver
  237. // if user enter num pad ascii value...
  238. UINT fStripCRCRLF : 1; // CRCRLFs have been added to text. Strip them
  239. // before doing any internal edit control stuff
  240. UINT fInDialogBox : 1; // True if the ml edit control is in a dialog
  241. // box and we have to specially treat TABS and ENTER
  242. UINT fReadOnly : 1; // Is this a read only edit control? Only
  243. // allow scrolling, selecting and copying.
  244. UINT fCaretHidden : 1; // This indicates whether the caret is
  245. // currently hidden because the width or height
  246. // of the edit control is too small to show it.
  247. UINT fTrueType : 1; // Is the current font TrueType?
  248. UINT fAnsi : 1; // is the edit control Ansi or unicode
  249. UINT fWin31Compat : 1; // TRUE if created by Windows 3.1 app
  250. UINT f40Compat : 1; // TRUE if created by Windows 4.0 app
  251. UINT fFlatBorder : 1; // Do we have to draw this baby ourself?
  252. UINT fSawRButtonDown : 1;
  253. UINT fInitialized : 1; // If any more bits are needed, then
  254. UINT fSwapRoOnUp : 1; // Swap reading order on next keyup
  255. UINT fAllowRTL : 1; // Allow RTL processing
  256. UINT fDisplayCtrl : 1; // Display unicode control characters
  257. UINT fRtoLReading : 1; // Right to left reading order
  258. BOOL fInsertCompChr :1; // means WM_IME_COMPOSITION:CS_INSERTCHAR will come
  259. BOOL fReplaceCompChr :1; // means need to replace current composition str.
  260. BOOL fNoMoveCaret :1; // means stick to current caret pos.
  261. BOOL fResultProcess :1; // means now processing result.
  262. BOOL fKorea :1; // for Korea
  263. BOOL fInReconversion :1; // In reconversion mode
  264. BOOL fLShift :1; // L-Shift pressed with Ctrl
  265. WORD wImeStatus; // current IME status
  266. WORD cbChar; // count of bytes in the char size (1 or 2 if unicode)
  267. LPICH chLines; // index of the start of each line
  268. UINT format; // Left, center, or right justify multiline text.
  269. EDITWORDBREAKPROCA lpfnNextWord; // use CALLWORDBREAKPROC macro to call
  270. // Next word function
  271. INT maxPixelWidth; // WASICH Width (in pixels) of longest line
  272. UNDO; // Undo buffer
  273. HANDLE hFont; // Handle to the font for this edit control.
  274. // Null if system font.
  275. INT aveCharWidth; // Ave width of a character in the hFont
  276. INT lineHeight; // Height of a line in the hFont
  277. INT charOverhang; // Overhang associated with the hFont
  278. INT cxSysCharWidth; // System font ave width
  279. INT cySysCharHeight; // System font height
  280. HWND listboxHwnd; // ListBox hwnd. Non null if we are a combobox
  281. LPINT pTabStops; // Points to an array of tab stops; First
  282. // element contains the number of elements in
  283. // the array
  284. LPINT charWidthBuffer;
  285. BYTE charSet; // Character set for currently selected font
  286. // needed for all versions
  287. UINT wMaxNegA; // The biggest negative A width
  288. UINT wMaxNegAcharPos; // and how many characters it can span accross
  289. UINT wMaxNegC; // The biggest negative C width,
  290. UINT wMaxNegCcharPos; // and how many characters it can span accross
  291. UINT wLeftMargin; // Left margin width in pixels.
  292. UINT wRightMargin; // Right margin width in pixels.
  293. ICH ichStartMinSel;
  294. ICH ichStartMaxSel;
  295. PLPKEDITCALLOUT pLpkEditCallout;
  296. HBITMAP hCaretBitmap; // Current caret bitmap handle
  297. INT iCaretOffset; // Offset in pixels (for LPK use)
  298. HANDLE hInstance; // for WOW
  299. UCHAR seed; // used to encode and decode password text
  300. BOOLEAN fEncoded; // is the text currently encoded
  301. INT iLockLevel; // number of times the text has been locked
  302. BYTE DBCSVector[MAX_LEADBYTES]; // DBCS vector table
  303. HIMC hImcPrev; // place to save hImc if we disable IME
  304. POINT ptScreenBounding; // top left corner of edit window in screen
  305. } ED0, *PED0;
  306. typedef struct tagED
  307. {
  308. ED0; // lpk callouts expect user32's ped struct
  309. // so for compatability we'll give it to them.
  310. HTHEME hTheme; // Handle to the theme manager
  311. PWW pww; // RO pointer into the pwnd to ExStyle, Style, State, State2
  312. HFONT hFontSave; // saved the font
  313. LPWSTR pszCueBannerText; // pointer to the text for the cue banner (grey help text)
  314. UINT fHot : 1; // Is mouse over edit control?
  315. HWND hwndBalloon; // Balloon tip hwnd for EM_BALLOONTIP
  316. HFONT hFontPassword;
  317. } ED, *PED, **PPED;
  318. //
  319. // Edit function prototypes.
  320. //
  321. //
  322. // Defined in edit.c
  323. //
  324. PSTR Edit_Lock(PED);
  325. VOID Edit_Unlock(PED);
  326. VOID Edit_InOutReconversionMode(PED, BOOL);
  327. INT Edit_GetModKeys(INT);
  328. UINT Edit_TabTheTextOut(HDC, INT, INT, INT, INT, LPSTR, INT, ICH, PED, INT, BOOL, LPSTRIPINFO);
  329. ICH Edit_CchInWidth(PED, HDC, LPSTR, ICH, INT, BOOL);
  330. HBRUSH Edit_GetBrush(PED, HDC, LPBOOL);
  331. VOID Edit_Word(PED, ICH, BOOL, LPICH, LPICH);
  332. VOID Edit_SaveUndo(PUNDO, PUNDO, BOOL);
  333. VOID Edit_EmptyUndo(PUNDO);
  334. BOOL Edit_InsertText(PED, LPSTR, LPICH);
  335. ICH Edit_DeleteText(PED);
  336. VOID Edit_NotifyParent(PED, INT);
  337. VOID Edit_SetClip(PED, HDC, BOOL);
  338. HDC Edit_GetDC(PED, BOOL);
  339. VOID Edit_ReleaseDC(PED, HDC, BOOL);
  340. VOID Edit_ResetTextInfo(PED);
  341. BOOL Edit_SetEditText(PED, LPSTR);
  342. VOID Edit_InvalidateClient(PED, BOOL);
  343. BOOL Edit_CalcChangeSelection(PED, ICH, ICH, LPSELBLOCK, LPSELBLOCK);
  344. INT Edit_GetDBCSVector(PED, HDC, BYTE);
  345. LPSTR Edit_AnsiNext(PED, LPSTR);
  346. LPSTR Edit_AnsiPrev(PED, LPSTR, LPSTR);
  347. ICH Edit_NextIch(PED, LPSTR, ICH);
  348. ICH Edit_PrevIch(PED, LPSTR, ICH);
  349. BOOL Edit_IsDBCSLeadByte(PED, BYTE);
  350. WORD DbcsCombine(HWND, WORD);
  351. ICH Edit_AdjustIch(PED, LPSTR, ICH);
  352. ICH Edit_AdjustIchNext(PED, LPSTR, ICH);
  353. VOID Edit_UpdateFormat(PED, DWORD, DWORD);
  354. BOOL Edit_IsFullWidth(DWORD,WCHAR);
  355. __inline LRESULT Edit_ShowBalloonTipWrap(HWND, DWORD, DWORD, DWORD);
  356. //
  357. // Defined in editrare.c
  358. //
  359. INT Edit_GetStateId(PED ped);
  360. VOID Edit_SetMargin(PED, UINT, long, BOOL);
  361. INT UserGetCharDimensionsEx(HDC, HFONT, LPTEXTMETRICW, LPINT);
  362. ICH Edit_GetTextHandler(PED, ICH, LPSTR, BOOL);
  363. BOOL Edit_NcCreate(PED, HWND, LPCREATESTRUCT);
  364. BOOL Edit_Create(PED ped, LONG windowStyle);
  365. VOID Edit_NcDestroyHandler(HWND, PED);
  366. VOID Edit_SetPasswordCharHandler(PED, UINT);
  367. BOOL GetNegABCwidthInfo(PED ped, HDC hdc);
  368. VOID Edit_Size(PED ped, LPRECT lprc, BOOL fRedraw);
  369. BOOL Edit_SetFont(PED, HFONT, BOOL);
  370. BOOL Edit_IsCharNumeric(PED ped, DWORD keyPress);
  371. VOID Edit_EnableDisableIME(PED ped);
  372. VOID Edit_ImmSetCompositionWindow(PED ped, LONG, LONG);
  373. VOID Edit_SetCompositionFont(PED ped);
  374. VOID Edit_InitInsert(PED ped, HKL hkl);
  375. VOID Edit_SetCaretHandler(PED ped);
  376. LRESULT Edit_ImeComposition(PED ped, WPARAM wParam, LPARAM lParam);
  377. BOOL HanjaKeyHandler(PED ped); // Korean Support
  378. LRESULT Edit_RequestHandler(PED, WPARAM, LPARAM); // NT 5.0
  379. //
  380. // Single line Edit function prototypes
  381. //
  382. // Defined in editsl.c
  383. //
  384. INT EditSL_IchToLeftXPos(PED, HDC, ICH);
  385. VOID EditSL_SetCaretPosition(PED, HDC);
  386. VOID EditSL_DrawText(PED, HDC, ICH);
  387. BOOL EditSL_ScrollText(PED, HDC);
  388. ICH EditSL_InsertText(PED, LPSTR, ICH);
  389. VOID EditSL_ReplaceSel(PED, LPSTR);
  390. LRESULT EditSL_WndProc(PED, UINT, WPARAM, LPARAM);
  391. //
  392. // Multi line Edit function prototypes
  393. //
  394. // Defined in editsl.c
  395. //
  396. VOID EditML_Size(PED, BOOL);
  397. VOID EditML_SetCaretPosition(PED,HDC);
  398. VOID EditML_IchToXYPos(PED, HDC, ICH, BOOL, LPPOINT);
  399. VOID EditML_UpdateiCaretLine(PED ped);
  400. ICH EditML_InsertText(PED, LPSTR, ICH, BOOL);
  401. VOID EditML_ReplaceSel(PED, LPSTR);
  402. ICH EditML_DeleteText(PED);
  403. VOID EditML_BuildchLines(PED, ICH, int, BOOL, PLONG, PLONG);
  404. LONG EditML_Scroll(PED, BOOL, int, int, BOOL);
  405. LRESULT EditML_WndProc(PED, UINT, WPARAM, LPARAM);
  406. #endif // __Edit_h__INCLUDED