Source code of Windows XP (NT5)
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.

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