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.

188 lines
5.5 KiB

  1. /****************************************************************************\
  2. * edslRare.c - SL Edit controls Routines Called rarely are to be
  3. * put in a seperate segment _EDSLRare. This file contains
  4. * these routines.
  5. *
  6. * Copyright (c) 1985 - 1999, Microsoft Corporation
  7. *
  8. * Single-Line Support Routines called Rarely
  9. *
  10. * Created: 02-08-89 sankar
  11. \****************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /***************************************************************************\
  15. * SLCreate
  16. *
  17. * Creates the edit control for the window hwnd by allocating memory
  18. * as required from the application's heap. Notifies parent if no memory
  19. * error (after cleaning up if needed). Returns TRUE if no error else return s
  20. * -1.
  21. *
  22. * History:
  23. \***************************************************************************/
  24. LONG SLCreate(
  25. PED ped,
  26. LPCREATESTRUCT lpCreateStruct) //!!! CREATESTRUCT AorW and in other routines
  27. {
  28. LPSTR lpWindowText;
  29. LONG windowStyle = ped->pwnd->style;
  30. /*
  31. * Do the standard creation stuff
  32. */
  33. if (!ECCreate(ped, windowStyle))
  34. return (-1);
  35. /*
  36. * Single lines always have no undo and 1 line
  37. */
  38. ped->cLines = 1;
  39. ped->undoType = UNDO_NONE;
  40. /*
  41. * Check if this edit control is part of a combobox and get a pointer to the
  42. * combobox structure.
  43. */
  44. if (windowStyle & ES_COMBOBOX)
  45. ped->listboxHwnd = GetDlgItem(lpCreateStruct->hwndParent, CBLISTBOXID);
  46. /*
  47. * Set the default font to be the system font.
  48. */
  49. ECSetFont(ped, NULL, FALSE);
  50. /*
  51. * Set the window text if needed. Return false if we can't set the text
  52. * SLSetText notifies the parent in case there is a no memory error.
  53. */
  54. if ((ULONG_PTR)lpCreateStruct->lpszName > gHighestUserAddress)
  55. lpWindowText = REBASEPTR(ped->pwnd, (PVOID)lpCreateStruct->lpszName);
  56. else
  57. lpWindowText = (LPSTR)lpCreateStruct->lpszName;
  58. if ((lpWindowText != NULL)
  59. && !IsEmptyString(lpWindowText, ped->fAnsi)
  60. && !ECSetText(ped, lpWindowText)) {
  61. return (-1);
  62. }
  63. if (windowStyle & ES_PASSWORD)
  64. ECSetPasswordChar(ped, (UINT)'*');
  65. return TRUE;
  66. }
  67. /***************************************************************************\
  68. * SLUndoHandler AorW
  69. *
  70. * Handles UNDO for single line edit controls.
  71. *
  72. * History:
  73. \***************************************************************************/
  74. BOOL SLUndo(
  75. PED ped)
  76. {
  77. PBYTE hDeletedText = ped->hDeletedText;
  78. BOOL fDelete = (BOOL)(ped->undoType & UNDO_DELETE);
  79. ICH cchDeleted = ped->cchDeleted;
  80. ICH ichDeleted = ped->ichDeleted;
  81. BOOL fUpdate = FALSE;
  82. if (ped->undoType == UNDO_NONE) {
  83. /*
  84. * No undo...
  85. */
  86. return FALSE;
  87. }
  88. ped->hDeletedText = NULL;
  89. ped->cchDeleted = 0;
  90. ped->ichDeleted = (ICH)-1;
  91. ped->undoType &= ~UNDO_DELETE;
  92. if (ped->undoType == UNDO_INSERT) {
  93. ped->undoType = UNDO_NONE;
  94. /*
  95. * Set the selection to the inserted text
  96. */
  97. SLSetSelection(ped, ped->ichInsStart, ped->ichInsEnd);
  98. ped->ichInsStart = ped->ichInsEnd = (ICH)-1;
  99. #ifdef NEVER
  100. /*
  101. * Now send a backspace to deleted and save it in the undo buffer...
  102. */
  103. SLCharHandler(pped, VK_BACK);
  104. fUpdate = TRUE;
  105. #else
  106. /*
  107. * Delete the selected text and save it in undo buff.
  108. * Call ECDeleteText() instead of sending a VK_BACK message
  109. * which results in an EN_UPDATE notification send even before
  110. * we insert the deleted chars. This results in Bug #6610.
  111. * Fix for Bug #6610 -- SANKAR -- 04/19/91 --
  112. */
  113. if (ECDeleteText(ped)) {
  114. /*
  115. * Text was deleted -- flag for update and clear selection
  116. */
  117. fUpdate = TRUE;
  118. SLSetSelection(ped, ichDeleted, ichDeleted);
  119. }
  120. #endif
  121. }
  122. if (fDelete) {
  123. HWND hwndSave = ped->hwnd; // Used for validation.
  124. /*
  125. * Insert deleted chars. Set the selection to the inserted text.
  126. */
  127. SLSetSelection(ped, ichDeleted, ichDeleted);
  128. SLInsertText(ped, hDeletedText, cchDeleted);
  129. UserGlobalFree(hDeletedText);
  130. if (!IsWindow(hwndSave))
  131. return FALSE;
  132. SLSetSelection(ped, ichDeleted, ichDeleted + cchDeleted);
  133. fUpdate = TRUE;
  134. }
  135. if (fUpdate) {
  136. /*
  137. * If we have something to update, send EN_UPDATE before and
  138. * EN_CHANGE after the actual update.
  139. * A part of the fix for Bug #6610 -- SANKAR -- 04/19/91 --
  140. */
  141. ECNotifyParent(ped, EN_UPDATE);
  142. if (FChildVisible(ped->hwnd)) {
  143. // JimA changed this to ECInvalidateClient(ped, FALSE) Nov 1994
  144. // GetClientRect(ped->hwnd, &rcEdit);
  145. // if (ped->fBorder && rcEdit.right - rcEdit.left && rcEdit.bottom - rcEdit.top) {
  146. //
  147. // /*
  148. // * Don't invalidate the border so that we avoid flicker
  149. // */
  150. // InflateRect(&rcEdit, -1, -1);
  151. // }
  152. // NtUserInvalidateRect(ped->hwnd, &rcEdit, FALSE);
  153. ECInvalidateClient(ped, FALSE);
  154. }
  155. ECNotifyParent(ped, EN_CHANGE);
  156. NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, ped->hwnd, OBJID_CLIENT, INDEXID_CONTAINER);
  157. }
  158. return TRUE;
  159. }