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.

288 lines
8.4 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * EDSLRARE.C
  8. * Win16 edit control code
  9. *
  10. * History:
  11. *
  12. * Created 28-May-1991 by Jeff Parsons (jeffpar)
  13. * Copied from WIN31 and edited (as little as possible) for WOW16.
  14. --*/
  15. /****************************************************************************/
  16. /* edslRare.c - SL Edit controls Routines Called rarely are to be */
  17. /* put in a seperate segment _EDSLRare. This file contains */
  18. /* these routines. */
  19. /* */
  20. /* */
  21. /* Created: 02-08-89 sankar */
  22. /****************************************************************************/
  23. #define NO_LOCALOBJ_TAGS
  24. #include "user.h"
  25. #include "edit.h"
  26. /****************************************************************************/
  27. /* Single-Line Support Routines called Rarely */
  28. /****************************************************************************/
  29. void FAR PASCAL SLSetSelectionHandler(ped, ichSelStart, ichSelEnd)
  30. register PED ped;
  31. ICH ichSelStart;
  32. ICH ichSelEnd;
  33. /* effects: Sets the PED to have the new selection specified.
  34. */
  35. {
  36. register HDC hdc = ECGetEditDC(ped, FALSE);
  37. if (ichSelStart == 0xFFFF)
  38. /* Set no selection if we specify -1 */
  39. ichSelStart = ichSelEnd = ped->ichCaret;
  40. /* Bounds ichSelStart, ichSelEnd are checked in SLChangeSelection... */
  41. SLChangeSelection(ped, hdc, ichSelStart, ichSelEnd);
  42. /* Put the caret at the end of the selected text */
  43. ped->ichCaret = ped->ichMaxSel;
  44. SLSetCaretPosition(ped,hdc);
  45. /* We may need to scroll the text to bring the caret into view... */
  46. SLScrollText(ped,hdc);
  47. ECReleaseEditDC(ped,hdc,FALSE);
  48. }
  49. void FAR PASCAL SLSizeHandler(ped)
  50. register PED ped;
  51. /* effects: Handles sizing of the edit control window and properly updating
  52. * the fields that are dependent on the size of the control. ie. text
  53. * characters visible etc.
  54. */
  55. {
  56. RECT rc;
  57. GetClientRect(ped->hwnd, &rc);
  58. if (!(rc.right-rc.left) || !(rc.bottom-rc.top))
  59. {
  60. if (ped->rcFmt.right-ped->rcFmt.left)
  61. /* Don't do anything if we are becomming zero width or height and
  62. out formatting rect is already set... */
  63. return;
  64. /* Otherwise set some initial values to avoid divide by zero problems
  65. later... */
  66. SetRect((LPRECT)&rc,0,0,10,10);
  67. }
  68. CopyRect(&ped->rcFmt, &rc);
  69. if (ped->fBorder)
  70. /* Shrink client area to make room for the border */
  71. InflateRect((LPRECT)&ped->rcFmt,
  72. -(min(ped->aveCharWidth,ped->cxSysCharWidth)/2),
  73. -(min(ped->lineHeight,ped->cySysCharHeight)/4));
  74. #ifdef BROKEN
  75. ped->rcFmt.bottom = min(ped->rcFmt.top+
  76. max(ped->lineHeight,ped->cySysCharHeight),
  77. ped->rcFmt.bottom);
  78. #else
  79. ped->rcFmt.bottom = min(ped->rcFmt.top+
  80. ped->lineHeight,
  81. ped->rcFmt.bottom);
  82. #endif
  83. }
  84. BOOL FAR PASCAL SLSetTextHandler(ped, lpstr)
  85. register PED ped;
  86. LPSTR lpstr;
  87. /* effects: Copies the null terminated text in lpstr to the ped. Notifies the
  88. * parent if there isn't enough memory. Returns TRUE if successful else
  89. * FALSE.
  90. */
  91. {
  92. BOOL fInsertSuccessful;
  93. RECT rcEdit;
  94. SwapHandle(&lpstr);
  95. ECEmptyUndo(ped);
  96. SwapHandle(&lpstr);
  97. /* Add the text and update the window if text was added. The parent is
  98. * notified of no memory in ECSetText.
  99. */
  100. if (fInsertSuccessful = ECSetText(ped, lpstr))
  101. ped->fDirty = FALSE;
  102. ECEmptyUndo(ped);
  103. if (!ped->listboxHwnd)
  104. ECNotifyParent(ped, EN_UPDATE);
  105. #ifndef WOW
  106. if (FChildVisible(ped->hwnd))
  107. #else
  108. if (IsWindowVisible(GetParent(ped->hwnd)))
  109. #endif
  110. {
  111. /* We will always redraw the text whether or not the insert was
  112. * successful since we may set to null text.
  113. */
  114. GetClientRect(ped->hwnd, (LPRECT)&rcEdit);
  115. if (ped->fBorder &&
  116. rcEdit.right-rcEdit.left && rcEdit.bottom-rcEdit.top)
  117. {
  118. /* Don't invalidate the border so that we avoid flicker */
  119. InflateRect((LPRECT)&rcEdit, -1, -1);
  120. }
  121. InvalidateRect(ped->hwnd, (LPRECT)&rcEdit, FALSE);
  122. UpdateWindow(ped->hwnd);
  123. }
  124. if (!ped->listboxHwnd)
  125. ECNotifyParent(ped, EN_CHANGE);
  126. return(fInsertSuccessful);
  127. }
  128. LONG FAR PASCAL SLCreateHandler(hwnd, ped, lpCreateStruct)
  129. HWND hwnd;
  130. register PED ped;
  131. LPCREATESTRUCT lpCreateStruct;
  132. /* effects: Creates the edit control for the window hwnd by allocating memory
  133. * as required from the application's heap. Notifies parent if no memory
  134. * error (after cleaning up if needed). Returns TRUE if no error else returns
  135. * -1.
  136. */
  137. {
  138. LPSTR lpWindowText = lpCreateStruct->lpszName;
  139. LONG windowStyle = GetWindowLong(hwnd, GWL_STYLE);
  140. /* Save text across the local allocs in ECNcCreate */
  141. SwapHandle(&lpWindowText);
  142. /* Do the standard creation stuff */
  143. if (!ECCreate(hwnd, ped, lpCreateStruct))
  144. return(-1);
  145. ped->fSingle = TRUE; /* Set single line edit control */
  146. /* Single lines always have no undo and 1 line */
  147. ped->cLines = 1;
  148. ped->undoType = UNDO_NONE;
  149. /* Check if this edit control is part of a combobox and get a pointer to the
  150. * combobox structure.
  151. */
  152. if (windowStyle & ES_COMBOBOX)
  153. ped->listboxHwnd = GetDlgItem(lpCreateStruct->hwndParent,CBLISTBOXID);
  154. /* Set the default font to be the system font.
  155. */
  156. ECSetFont(ped, NULL, FALSE);
  157. /* Set the window text if needed. Return false if we can't set the text
  158. * SLSetText notifies the parent in case there is a no memory error.
  159. */
  160. /* Restore text */
  161. SwapHandle(&lpWindowText);
  162. if (lpWindowText && *lpWindowText && !SLSetTextHandler(ped, lpWindowText))
  163. return(-1);
  164. if (windowStyle & ES_PASSWORD)
  165. ECSetPasswordChar(ped, (WORD)'*');
  166. return(TRUE);
  167. }
  168. BOOL FAR PASCAL SLUndoHandler(ped)
  169. register PED ped;
  170. /* effects: Handles UNDO for single line edit controls. */
  171. {
  172. HANDLE hDeletedText = ped->hDeletedText;
  173. BOOL fDelete = (BOOL)(ped->undoType & UNDO_DELETE);
  174. WORD cchDeleted = ped->cchDeleted;
  175. WORD ichDeleted = ped->ichDeleted;
  176. BOOL fUpdate = FALSE;
  177. RECT rcEdit;
  178. if (ped->undoType == UNDO_NONE)
  179. /* No undo... */
  180. return(FALSE);
  181. ped->hDeletedText = NULL;
  182. ped->cchDeleted = 0;
  183. ped->ichDeleted = -1;
  184. ped->undoType &= ~UNDO_DELETE;
  185. if (ped->undoType == UNDO_INSERT)
  186. {
  187. ped->undoType = UNDO_NONE;
  188. /* Set the selection to the inserted text */
  189. SLSetSelectionHandler(ped, ped->ichInsStart, ped->ichInsEnd);
  190. ped->ichInsStart = ped->ichInsEnd = -1;
  191. #ifdef NEVER
  192. /* Now send a backspace to deleted and save it in the undo buffer... */
  193. SLCharHandler(ped, VK_BACK, NOMODIFY);
  194. fUpdate = TRUE;
  195. #else
  196. /* Delete the selected text and save it in undo buff */
  197. /* Call ECDeleteText() instead of sending a VK_BACK message which
  198. * results in a EN_UPDATE notification sent even before we insert
  199. * the deleted chars. This results in Bug #6610.
  200. * Fix for Bug #6610 -- SANKAR -- 04/19/91 --
  201. */
  202. if (ECDeleteText(ped))
  203. fUpdate = TRUE;
  204. #endif
  205. }
  206. if (fDelete)
  207. {
  208. /* Insert deleted chars */
  209. /* Set the selection to the inserted text */
  210. SLSetSelectionHandler(ped, ichDeleted, ichDeleted);
  211. SLInsertText(ped, GlobalLock(hDeletedText), cchDeleted);
  212. GlobalUnlock(hDeletedText);
  213. GlobalFree(hDeletedText);
  214. SLSetSelectionHandler(ped, ichDeleted, ichDeleted+cchDeleted);
  215. fUpdate=TRUE;
  216. }
  217. if(fUpdate)
  218. {
  219. /* If we have something to update, send EN_UPDATE before and EN_CHANGE
  220. * after the actual update.
  221. * A part of the Fix for Bug #6610 -- SANKAR -- 04/19/91 --
  222. */
  223. ECNotifyParent(ped, EN_UPDATE);
  224. #ifndef WOW
  225. if (FChildVisible(ped->hwnd))
  226. #else
  227. if (IsWindowVisible(GetParent(ped->hwnd)))
  228. #endif
  229. {
  230. GetClientRect(ped->hwnd, (LPRECT)&rcEdit);
  231. if (ped->fBorder && rcEdit.right-rcEdit.left &&
  232. rcEdit.bottom-rcEdit.top)
  233. {
  234. /* Don't invalidate the border so that we avoid flicker */
  235. InflateRect((LPRECT)&rcEdit, -1, -1);
  236. }
  237. InvalidateRect(ped->hwnd, (LPRECT)&rcEdit, FALSE);
  238. UpdateWindow(ped->hwnd);
  239. }
  240. ECNotifyParent(ped,EN_CHANGE);
  241. }
  242. return(TRUE);
  243. }
  244.