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.

179 lines
5.3 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * EDMLONCE.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. /* edmlonce.c - Edit controls Routines Called just once or twice are to be */
  17. /* put in a seperate segment _EDMLONCE. 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. /* Multi-Line Support Routines called just once */
  28. /****************************************************************************/
  29. void FAR PASCAL MLSizeHandler(ped)
  30. register PED ped;
  31. /* effects: Handles sizing of the edit control window and properly updating
  32. * the fields that are dependent on the size of the control. ie. text
  33. * characters visible etc.
  34. */
  35. {
  36. RECT rc;
  37. GetClientRect(ped->hwnd, (LPRECT)&rc);
  38. MLSetRectHandler(ped, (LPRECT)&rc);
  39. GetWindowRect(ped->hwnd, (LPRECT)&rc);
  40. ScreenToClient(ped->hwnd, (LPPOINT)&rc.left);
  41. ScreenToClient(ped->hwnd, (LPPOINT)&rc.right);
  42. InvalidateRect(ped->hwnd, (LPRECT) &rc, TRUE);
  43. /*UpdateWindow(ped->hwnd);*/
  44. }
  45. BOOL FAR PASCAL MLSetTextHandler(ped, lpstr)
  46. register PED ped;
  47. LPSTR lpstr;
  48. /* effects: Copies the null terminated text in lpstr to the ped. Notifies the
  49. * parent if there isn't enough memory. Returns TRUE if successful else FALSE
  50. * if memory error.
  51. */
  52. {
  53. BOOL fInsertSuccessful;
  54. /* Set the text and update the window if text was added */
  55. fInsertSuccessful = ECSetText(ped, lpstr);
  56. if (fInsertSuccessful)
  57. {
  58. MLStripCrCrLf(ped);
  59. /* Always build lines even if no text was inserted. */
  60. MLBuildchLines(ped, 0, 0, FALSE);
  61. /* Reset caret and selections since the text could have changed */
  62. ped->screenStart = ped->ichMinSel = ped->ichMaxSel = 0;
  63. ped->ichCaret = 0;
  64. ped->xOffset = 0;
  65. ped->iCaretLine = 0;
  66. ped->fDirty = FALSE;
  67. }
  68. ECEmptyUndo(ped);
  69. SetScrollPos(ped->hwnd, SB_VERT, 0, TRUE);
  70. SetScrollPos(ped->hwnd, SB_HORZ, 0, TRUE);
  71. /* We will always redraw the text whether or not the insert was successful
  72. * since we may set to null text. Since PaintHandler checks the redraw flag,
  73. * we won't bother to check it here.
  74. */
  75. InvalidateRect(ped->hwnd, (LPRECT)NULL, TRUE);
  76. /* Need to do the updatewindow to keep raid happy.*/
  77. UpdateWindow(ped->hwnd);
  78. return(fInsertSuccessful);
  79. }
  80. LONG FAR PASCAL MLCreateHandler(hwnd, ped, lpCreateStruct)
  81. HWND hwnd;
  82. register PED ped;
  83. LPCREATESTRUCT lpCreateStruct;
  84. /* effects: Creates the edit control for the window hwnd by allocating memory
  85. * as required from the application's heap. Notifies parent if no memory
  86. * error (after cleaning up if needed). Returns TRUE if no error else returns
  87. * -1.
  88. */
  89. {
  90. LONG windowStyle;
  91. LPSTR lpWindowText=lpCreateStruct->lpszName;
  92. RECT rc;
  93. /* Save the text across the local allocs in ECNcCreate */
  94. SwapHandle(&lpWindowText);
  95. /* Do the standard creation stuff */
  96. if (!ECCreate(hwnd, ped, lpCreateStruct))
  97. return(-1);
  98. /* Allocate line start array as a fixed block in local heap */
  99. if (!(ped->chLines = (int *)LocalAlloc(LPTR,2*sizeof(int))))
  100. return(-1);
  101. /* Call it one line of text... */
  102. ped->cLines = 1;
  103. /* Get values from the window instance data structure and put them in the
  104. * ped so that we can access them easier
  105. */
  106. windowStyle = GetWindowLong(hwnd, GWL_STYLE);
  107. /* If app wants WS_VSCROLL or WS_HSCROLL, it automatically gets AutoVScroll
  108. * or AutoHScroll.
  109. */
  110. if ((windowStyle & ES_AUTOVSCROLL) || (windowStyle & WS_VSCROLL))
  111. ped->fAutoVScroll = 1;
  112. ped->format = (LOWORD(windowStyle) & LOWORD(ES_FMTMASK));
  113. if (ped->format != ES_LEFT)
  114. {
  115. /* If user wants right or center justified text, then we turn off
  116. * AUTOHSCROLL and WS_HSCROLL since non-left styles don't make sense
  117. * otherwise.
  118. */
  119. windowStyle = windowStyle & ~WS_HSCROLL;
  120. SetWindowLong(hwnd, GWL_STYLE, windowStyle);
  121. ped->fAutoHScroll = FALSE;
  122. }
  123. if (windowStyle & WS_HSCROLL)
  124. ped->fAutoHScroll = 1;
  125. ped->fWrap = (!ped->fAutoHScroll && !(windowStyle & WS_HSCROLL));
  126. ped->fSingle = FALSE; /* Set multi line edit control */
  127. _asm int 3
  128. ped->cchTextMax = MAXTEXT; /* Max # chars we will allow user to enter */
  129. /* Set the default font to be the system font.
  130. */
  131. ECSetFont(ped, NULL, FALSE);
  132. SetRect((LPRECT)&rc, 0, 0, ped->aveCharWidth*10, ped->lineHeight);
  133. MLSetRectHandler(ped, (LPRECT)&rc);
  134. /* Set the window text if needed and notify parent if not enough memory to
  135. * set the initial text.
  136. */
  137. /* Restore the text from the save we did at the beginning */
  138. SwapHandle(&lpWindowText);
  139. if (lpWindowText && !MLSetTextHandler(ped, lpWindowText))
  140. return(-1);
  141. return(TRUE);
  142. }