4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996
11 * UNDER CONSTRUCTION, please read EDIT.TODO
25 #define BUFLIMIT_MULTI 65534 /* maximum text buffer length (not including '\0') */
26 #define BUFLIMIT_SINGLE 32766
27 #define BUFSTART_MULTI 1024 /* starting length for multi-line control */
28 #define BUFSTART_SINGLE 256 /* starting length for single line control */
29 #define GROWLENGTH 64 /* buffers grow by this much */
30 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
49 UINT TextWidth
; /* width of the widest line in pixels */
54 UINT XOffset
; /* offset of the viewport in pixels */
55 UINT FirstVisibleLine
;
57 UINT LineHeight
; /* height of a screen line in pixels */
58 UINT AveCharWidth
; /* average character width in pixels */
63 UINT SelStart
; /* offset of selection start, == SelEnd if no selection */
64 UINT SelEnd
; /* offset of selection end == current caret position */
67 EDITWORDBREAKPROC WordBreakProc
;
72 #define SWAP_UINT(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
73 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT((x),(y)); } while(0)
75 /* macros to access window styles */
76 #define IsMultiLine(wndPtr) ((wndPtr)->dwStyle & ES_MULTILINE)
77 #define IsVScrollBar(wndPtr) ((wndPtr)->dwStyle & WS_VSCROLL)
78 #define IsHScrollBar(wndPtr) ((wndPtr)->dwStyle & WS_HSCROLL)
79 #define IsReadOnly(wndPtr) ((wndPtr)->dwStyle & ES_READONLY)
80 #define IsWordWrap(wndPtr) (((wndPtr)->dwStyle & ES_AUTOHSCROLL) == 0)
81 #define IsPassword(wndPtr) ((wndPtr)->dwStyle & ES_PASSWORD)
82 #define IsLower(wndPtr) ((wndPtr)->dwStyle & ES_LOWERCASE)
83 #define IsUpper(wndPtr) ((wndPtr)->dwStyle & ES_UPPERCASE)
85 #define EDITSTATEPTR(wndPtr) (*(EDITSTATE **)((wndPtr)->wExtra))
87 #define EDIT_SEND_CTLCOLOR(wndPtr,hdc) \
88 (SendMessage32A((wndPtr)->parent->hwndSelf, WM_CTLCOLOREDIT, \
89 (WPARAM32)(hdc), (LPARAM)(wndPtr)->hwndSelf ))
90 #define EDIT_NOTIFY_PARENT(wndPtr, wNotifyCode) \
91 (SendMessage32A((wndPtr)->parent->hwndSelf, WM_COMMAND, \
92 MAKEWPARAM((wndPtr)->wIDmenu, wNotifyCode), \
93 (LPARAM)(wndPtr)->hwndSelf ))
94 #define DPRINTF_EDIT_MSG(str) \
95 dprintf_edit(stddeb, \
96 "edit: " str ": hwnd=%04x, wParam=%04x, lParam=%08x\n", \
97 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
100 /*********************************************************************
104 * Files like these should really be kept in alphabetical order.
107 LRESULT
EditWndProc(HWND hwnd
, UINT msg
, WPARAM16 wParam
, LPARAM lParam
);
109 static void EDIT_BuildLineDefs(WND
*wndPtr
);
110 static INT
EDIT_CallWordBreakProc(WND
*wndPtr
, char *s
, INT index
, INT count
, INT action
);
111 static UINT
EDIT_ColFromWndX(WND
*wndPtr
, UINT line
, INT x
);
112 static void EDIT_DelEnd(WND
*wndPtr
);
113 static void EDIT_DelLeft(WND
*wndPtr
);
114 static void EDIT_DelRight(WND
*wndPtr
);
115 static UINT
EDIT_GetAveCharWidth(WND
*wndPtr
);
116 static UINT
EDIT_GetLineHeight(WND
*wndPtr
);
117 static void EDIT_GetLineRect(WND
*wndPtr
, UINT line
, UINT scol
, UINT ecol
, LPRECT16 rc
);
118 static char * EDIT_GetPointer(WND
*wndPtr
);
119 static char * EDIT_GetPasswordPointer(WND
*wndPtr
);
120 static LRESULT
EDIT_GetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
121 static BOOL
EDIT_GetRedraw(WND
*wndPtr
);
122 static LRESULT
EDIT_GetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
123 static UINT
EDIT_GetTextWidth(WND
*wndPtr
);
124 static UINT
EDIT_GetVisibleLineCount(WND
*wndPtr
);
125 static UINT
EDIT_GetWndWidth(WND
*wndPtr
);
126 static UINT
EDIT_GetXOffset(WND
*wndPtr
);
127 static void EDIT_InvalidateText(WND
*wndPtr
, UINT start
, UINT end
);
128 static UINT
EDIT_LineFromWndY(WND
*wndPtr
, INT y
);
129 static BOOL
EDIT_MakeFit(WND
*wndPtr
, UINT size
);
130 static void EDIT_MoveBackward(WND
*wndPtr
, BOOL extend
);
131 static void EDIT_MoveDownward(WND
*wndPtr
, BOOL extend
);
132 static void EDIT_MoveEnd(WND
*wndPtr
, BOOL extend
);
133 static void EDIT_MoveForward(WND
*wndPtr
, BOOL extend
);
134 static void EDIT_MoveHome(WND
*wndPtr
, BOOL extend
);
135 static void EDIT_MovePageDown(WND
*wndPtr
, BOOL extend
);
136 static void EDIT_MovePageUp(WND
*wndPtr
, BOOL extend
);
137 static void EDIT_MoveUpward(WND
*wndPtr
, BOOL extend
);
138 static void EDIT_MoveWordBackward(WND
*wndPtr
, BOOL extend
);
139 static void EDIT_MoveWordForward(WND
*wndPtr
, BOOL extend
);
140 static void EDIT_PaintLine(WND
*wndPtr
, HDC32 hdc
, UINT line
, BOOL rev
);
141 static UINT
EDIT_PaintText(WND
*wndPtr
, HDC32 hdc
, INT x
, INT y
, UINT line
, UINT col
, UINT count
, BOOL rev
);
142 static void EDIT_ReleasePointer(WND
*wndPtr
);
143 static LRESULT
EDIT_ReplaceSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
144 static void EDIT_ScrollIntoView(WND
*wndPtr
);
145 static INT
EDIT_WndXFromCol(WND
*wndPtr
, UINT line
, UINT col
);
146 static INT
EDIT_WndYFromLine(WND
*wndPtr
, UINT line
);
147 static INT
EDIT_WordBreakProc(char *s
, INT index
, INT count
, INT action
);
149 static LRESULT
EDIT_EM_CanUndo(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
150 static LRESULT
EDIT_EM_EmptyUndoBuffer(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
151 static LRESULT
EDIT_EM_FmtLines(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
152 static LRESULT
EDIT_EM_GetFirstVisibleLine(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
153 static LRESULT
EDIT_EM_GetHandle(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
154 static LRESULT
EDIT_EM_GetLine(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
155 static LRESULT
EDIT_EM_GetLineCount(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
156 static LRESULT
EDIT_EM_GetModify(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
157 static LRESULT
EDIT_EM_GetPasswordChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
158 static LRESULT
EDIT_EM_GetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
159 static LRESULT
EDIT_EM_GetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
160 static LRESULT
EDIT_EM_GetThumb(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
161 static LRESULT
EDIT_EM_GetWordBreakProc(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
162 static LRESULT
EDIT_EM_LimitText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
163 static LRESULT
EDIT_EM_LineFromChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
164 static LRESULT
EDIT_EM_LineIndex(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
165 static LRESULT
EDIT_EM_LineLength(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
166 static LRESULT
EDIT_EM_LineScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
167 static LRESULT
EDIT_EM_ReplaceSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
168 static LRESULT
EDIT_EM_Scroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
169 static LRESULT
EDIT_EM_SetHandle(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
170 static LRESULT
EDIT_EM_SetModify(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
171 static LRESULT
EDIT_EM_SetPasswordChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
172 static LRESULT
EDIT_EM_SetReadOnly(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
173 static LRESULT
EDIT_EM_SetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
174 static LRESULT
EDIT_EM_SetRectNP(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
175 static LRESULT
EDIT_EM_SetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
176 static LRESULT
EDIT_EM_SetTabStops(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
177 static LRESULT
EDIT_EM_SetWordBreakProc(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
178 static LRESULT
EDIT_EM_Undo(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
180 static LRESULT
EDIT_WM_Char(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
181 static LRESULT
EDIT_WM_Clear(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
182 static LRESULT
EDIT_WM_Copy(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
183 static LRESULT
EDIT_WM_Cut(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
184 static LRESULT
EDIT_WM_Create(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
185 static LRESULT
EDIT_WM_Destroy(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
186 static LRESULT
EDIT_WM_Enable(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
187 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
188 static LRESULT
EDIT_WM_GetDlgCode(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
189 static LRESULT
EDIT_WM_GetFont(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
190 static LRESULT
EDIT_WM_GetText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
191 static LRESULT
EDIT_WM_GetTextLength(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
192 static LRESULT
EDIT_WM_HScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
193 static LRESULT
EDIT_WM_KeyDown(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
194 static LRESULT
EDIT_WM_KillFocus(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
195 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
196 static LRESULT
EDIT_WM_LButtonDown(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
197 static LRESULT
EDIT_WM_LButtonUp(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
198 static LRESULT
EDIT_WM_MouseMove(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
199 static LRESULT
EDIT_WM_Paint(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
200 static LRESULT
EDIT_WM_Paste(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
201 static LRESULT
EDIT_WM_SetCursor(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
202 static LRESULT
EDIT_WM_SetFocus(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
203 static LRESULT
EDIT_WM_SetFont(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
204 static LRESULT
EDIT_WM_SetRedraw(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
205 static LRESULT
EDIT_WM_SetText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
206 static LRESULT
EDIT_WM_Size(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
207 static LRESULT
EDIT_WM_VScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
);
210 /*********************************************************************
212 * General shortcuts for variable names:
216 * UINT s; offset of selection start
217 * UINT e; offset of selection end
218 * UINT sl; line on which the selection starts
219 * UINT el; line on which the selection ends
220 * UINT sc; column on which the selection starts
221 * UINT ec; column on which the selection ends
222 * UINT li; line index (offset)
223 * UINT fv; first visible line
224 * UINT vlc; vissible line count
225 * UINT lc; line count
226 * UINT lh; line height (in pixels)
227 * UINT tw; text width (in pixels)
228 * UINT ww; window width (in pixels)
229 * UINT cw; character width (average, in pixels)
234 /*********************************************************************
239 LRESULT
EditWndProc(HWND hwnd
, UINT msg
, WPARAM16 wParam
, LPARAM lParam
)
241 LRESULT lResult
= 0L;
242 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
244 if ((!EDITSTATEPTR(wndPtr
)) && (msg
!= WM_CREATE
))
245 return DefWindowProc16(hwnd
, msg
, wParam
, lParam
);
249 DPRINTF_EDIT_MSG("EM_CANUNDO");
250 lResult
= EDIT_EM_CanUndo(wndPtr
, wParam
, lParam
);
252 case EM_EMPTYUNDOBUFFER
:
253 DPRINTF_EDIT_MSG("EM_EMPTYUNDOBUFFER");
254 lResult
= EDIT_EM_EmptyUndoBuffer(wndPtr
, wParam
, lParam
);
257 DPRINTF_EDIT_MSG("EM_FMTLINES");
258 lResult
= EDIT_EM_FmtLines(wndPtr
, wParam
, lParam
);
260 case EM_GETFIRSTVISIBLELINE
:
261 DPRINTF_EDIT_MSG("EM_GETFIRSTVISIBLELINE");
262 lResult
= EDIT_EM_GetFirstVisibleLine(wndPtr
, wParam
, lParam
);
265 DPRINTF_EDIT_MSG("EM_GETHANDLE");
266 lResult
= EDIT_EM_GetHandle(wndPtr
, wParam
, lParam
);
269 DPRINTF_EDIT_MSG("EM_GETLINE");
270 lResult
= EDIT_EM_GetLine(wndPtr
, wParam
, lParam
);
272 case EM_GETLINECOUNT
:
273 DPRINTF_EDIT_MSG("EM_GETLINECOUNT");
274 lResult
= EDIT_EM_GetLineCount(wndPtr
, wParam
, lParam
);
277 DPRINTF_EDIT_MSG("EM_GETMODIFY");
278 lResult
= EDIT_EM_GetModify(wndPtr
, wParam
, lParam
);
280 case EM_GETPASSWORDCHAR
:
281 DPRINTF_EDIT_MSG("EM_GETPASSWORDCHAR");
282 lResult
= EDIT_EM_GetPasswordChar(wndPtr
, wParam
, lParam
);
285 DPRINTF_EDIT_MSG("EM_GETRECT");
286 lResult
= EDIT_EM_GetRect(wndPtr
, wParam
, lParam
);
289 DPRINTF_EDIT_MSG("EM_GETSEL");
290 lResult
= EDIT_EM_GetSel(wndPtr
, wParam
, lParam
);
293 DPRINTF_EDIT_MSG("EM_GETTHUMB");
294 lResult
= EDIT_EM_GetThumb(wndPtr
, wParam
, lParam
);
296 case EM_GETWORDBREAKPROC
:
297 DPRINTF_EDIT_MSG("EM_GETWORDBREAKPROC");
298 lResult
= EDIT_EM_GetWordBreakProc(wndPtr
, wParam
, lParam
);
301 DPRINTF_EDIT_MSG("EM_LIMITTEXT");
302 lResult
= EDIT_EM_LimitText(wndPtr
, wParam
, lParam
);
304 case EM_LINEFROMCHAR
:
305 DPRINTF_EDIT_MSG("EM_LINEFROMCHAR");
306 lResult
= EDIT_EM_LineFromChar(wndPtr
, wParam
, lParam
);
309 DPRINTF_EDIT_MSG("EM_LINEINDEX");
310 lResult
= EDIT_EM_LineIndex(wndPtr
, wParam
, lParam
);
313 DPRINTF_EDIT_MSG("EM_LINELENGTH");
314 lResult
= EDIT_EM_LineLength(wndPtr
, wParam
, lParam
);
317 DPRINTF_EDIT_MSG("EM_LINESCROLL");
318 lResult
= EDIT_EM_LineScroll(wndPtr
, wParam
, lParam
);
321 DPRINTF_EDIT_MSG("EM_REPLACESEL");
322 lResult
= EDIT_EM_ReplaceSel(wndPtr
, wParam
, lParam
);
325 DPRINTF_EDIT_MSG("EM_SCROLL");
326 lResult
= EDIT_EM_Scroll(wndPtr
, wParam
, lParam
);
329 DPRINTF_EDIT_MSG("EM_SETHANDLE");
330 lResult
= EDIT_EM_SetHandle(wndPtr
, wParam
, lParam
);
333 DPRINTF_EDIT_MSG("EM_SETMODIFY");
334 lResult
= EDIT_EM_SetModify(wndPtr
, wParam
, lParam
);
336 case EM_SETPASSWORDCHAR
:
337 DPRINTF_EDIT_MSG("EM_SETPASSWORDCHAR");
338 lResult
= EDIT_EM_SetPasswordChar(wndPtr
, wParam
, lParam
);
341 DPRINTF_EDIT_MSG("EM_SETREADONLY");
342 lResult
= EDIT_EM_SetReadOnly(wndPtr
, wParam
, lParam
);
345 DPRINTF_EDIT_MSG("EM_SETRECT");
346 lResult
= EDIT_EM_SetRect(wndPtr
, wParam
, lParam
);
349 DPRINTF_EDIT_MSG("EM_SETRECTNP");
350 lResult
= EDIT_EM_SetRectNP(wndPtr
, wParam
, lParam
);
353 DPRINTF_EDIT_MSG("EM_SETSEL");
354 lResult
= EDIT_EM_SetSel(wndPtr
, wParam
, lParam
);
357 DPRINTF_EDIT_MSG("EM_SETTABSTOPS");
358 lResult
= EDIT_EM_SetTabStops(wndPtr
, wParam
, lParam
);
360 case EM_SETWORDBREAKPROC
:
361 DPRINTF_EDIT_MSG("EM_SETWORDBREAKPROC");
362 lResult
= EDIT_EM_SetWordBreakProc(wndPtr
, wParam
, lParam
);
366 DPRINTF_EDIT_MSG("EM_UNDO / WM_UNDO");
367 lResult
= EDIT_EM_Undo(wndPtr
, wParam
, lParam
);
370 DPRINTF_EDIT_MSG("WM_GETDLGCODE");
371 lResult
= EDIT_WM_GetDlgCode(wndPtr
, wParam
, lParam
);
374 DPRINTF_EDIT_MSG("WM_CHAR");
375 lResult
= EDIT_WM_Char(wndPtr
, wParam
, lParam
);
378 DPRINTF_EDIT_MSG("WM_CLEAR");
379 lResult
= EDIT_WM_Clear(wndPtr
, wParam
, lParam
);
382 DPRINTF_EDIT_MSG("WM_COPY");
383 lResult
= EDIT_WM_Copy(wndPtr
, wParam
, lParam
);
386 DPRINTF_EDIT_MSG("WM_CREATE");
387 lResult
= EDIT_WM_Create(wndPtr
, wParam
, lParam
);
390 DPRINTF_EDIT_MSG("WM_CUT");
391 lResult
= EDIT_WM_Cut(wndPtr
, wParam
, lParam
);
394 DPRINTF_EDIT_MSG("WM_DESTROY");
395 lResult
= EDIT_WM_Destroy(wndPtr
, wParam
, lParam
);
398 DPRINTF_EDIT_MSG("WM_ENABLE");
399 lResult
= EDIT_WM_Enable(wndPtr
, wParam
, lParam
);
402 DPRINTF_EDIT_MSG("WM_ERASEBKGND");
403 lResult
= EDIT_WM_EraseBkGnd(wndPtr
, wParam
, lParam
);
406 DPRINTF_EDIT_MSG("WM_GETFONT");
407 lResult
= EDIT_WM_GetFont(wndPtr
, wParam
, lParam
);
410 DPRINTF_EDIT_MSG("WM_GETTEXT");
411 lResult
= EDIT_WM_GetText(wndPtr
, wParam
, lParam
);
413 case WM_GETTEXTLENGTH
:
414 DPRINTF_EDIT_MSG("WM_GETTEXTLENGTH");
415 lResult
= EDIT_WM_GetTextLength(wndPtr
, wParam
, lParam
);
418 DPRINTF_EDIT_MSG("WM_HSCROLL");
419 lResult
= EDIT_WM_HScroll(wndPtr
, wParam
, lParam
);
422 DPRINTF_EDIT_MSG("WM_KEYDOWN");
423 lResult
= EDIT_WM_KeyDown(wndPtr
, wParam
, lParam
);
426 DPRINTF_EDIT_MSG("WM_KILLFOCUS");
427 lResult
= EDIT_WM_KillFocus(wndPtr
, wParam
, lParam
);
429 case WM_LBUTTONDBLCLK
:
430 DPRINTF_EDIT_MSG("WM_LBUTTONDBLCLK");
431 lResult
= EDIT_WM_LButtonDblClk(wndPtr
, wParam
, lParam
);
434 DPRINTF_EDIT_MSG("WM_LBUTTONDOWN");
435 lResult
= EDIT_WM_LButtonDown(wndPtr
, wParam
, lParam
);
438 DPRINTF_EDIT_MSG("WM_LBUTTONUP");
439 lResult
= EDIT_WM_LButtonUp(wndPtr
, wParam
, lParam
);
443 * DPRINTF_EDIT_MSG("WM_MOUSEMOVE");
445 lResult
= EDIT_WM_MouseMove(wndPtr
, wParam
, lParam
);
448 DPRINTF_EDIT_MSG("WM_PAINT");
449 lResult
= EDIT_WM_Paint(wndPtr
, wParam
, lParam
);
452 DPRINTF_EDIT_MSG("WM_PASTE");
453 lResult
= EDIT_WM_Paste(wndPtr
, wParam
, lParam
);
457 * DPRINTF_EDIT_MSG("WM_SETCURSOR");
459 lResult
= EDIT_WM_SetCursor(wndPtr
, wParam
, lParam
);
462 DPRINTF_EDIT_MSG("WM_SETFOCUS");
463 lResult
= EDIT_WM_SetFocus(wndPtr
, wParam
, lParam
);
466 DPRINTF_EDIT_MSG("WM_SETFONT");
467 lResult
= EDIT_WM_SetFont(wndPtr
, wParam
, lParam
);
470 DPRINTF_EDIT_MSG("WM_SETREDRAW");
471 lResult
= EDIT_WM_SetRedraw(wndPtr
, wParam
, lParam
);
474 DPRINTF_EDIT_MSG("WM_SETTEXT");
475 lResult
= EDIT_WM_SetText(wndPtr
, wParam
, lParam
);
478 DPRINTF_EDIT_MSG("WM_SIZE");
479 lResult
= EDIT_WM_Size(wndPtr
, wParam
, lParam
);
482 DPRINTF_EDIT_MSG("WM_VSCROLL");
483 lResult
= EDIT_WM_VScroll(wndPtr
, wParam
, lParam
);
486 lResult
= DefWindowProc16(hwnd
, msg
, wParam
, lParam
);
489 EDIT_ReleasePointer(wndPtr
);
494 /*********************************************************************
498 * Build array of pointers to text lines.
499 * Lines can end with '\0' (last line), nothing (if it is too long),
500 * a delimiter (usually ' '), a soft return '\r\r\n' or a hard return '\r\n'
503 static void EDIT_BuildLineDefs(WND
*wndPtr
)
505 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
506 char *text
= EDIT_GetPasswordPointer(wndPtr
);
507 int ww
= EDIT_GetWndWidth(wndPtr
);
517 hdc
= GetDC32(wndPtr
->hwndSelf
);
518 hFont
= (HFONT16
)EDIT_WM_GetFont(wndPtr
, 0, 0L);
519 if (hFont
) oldFont
= SelectObject32(hdc
, hFont
);
521 if (!IsMultiLine(wndPtr
)) {
523 es
->LineDefs
= xrealloc(es
->LineDefs
, sizeof(LINEDEF
));
524 es
->LineDefs
[0].offset
= 0;
525 es
->LineDefs
[0].length
= EDIT_WM_GetTextLength(wndPtr
, 0, 0L);
526 es
->LineDefs
[0].ending
= END_0
;
527 es
->TextWidth
= LOWORD(GetTabbedTextExtent(hdc
, text
,
528 es
->LineDefs
[0].length
,
529 es
->NumTabStops
, es
->TabStops
));
534 if (!(cp
= strstr(start
, "\r\n"))) {
536 length
= strlen(start
);
537 } else if ((cp
> start
) && (*(cp
- 1) == '\r')) {
539 length
= cp
- start
- 1;
544 width
= LOWORD(GetTabbedTextExtent(hdc
, start
, length
,
545 es
->NumTabStops
, es
->TabStops
));
547 if (IsWordWrap(wndPtr
) && (width
> ww
)) {
551 next
= EDIT_CallWordBreakProc(wndPtr
, start
,
552 prev
+ 1, length
, WB_RIGHT
);
553 width
= LOWORD(GetTabbedTextExtent(hdc
, start
, next
,
554 es
->NumTabStops
, es
->TabStops
));
555 } while (width
<= ww
);
561 width
= LOWORD(GetTabbedTextExtent(hdc
, start
, next
,
562 es
->NumTabStops
, es
->TabStops
));
563 } while (width
<= ww
);
567 if (EDIT_CallWordBreakProc(wndPtr
, start
, length
- 1,
568 length
, WB_ISDELIMITER
)) {
570 ending
= END_DELIMIT
;
573 width
= LOWORD(GetTabbedTextExtent(hdc
, start
, length
,
574 es
->NumTabStops
, es
->TabStops
));
577 es
->LineDefs
= xrealloc(es
->LineDefs
, (es
->LineCount
+ 1) * sizeof(LINEDEF
));
578 es
->LineDefs
[es
->LineCount
].offset
= start
- text
;
579 es
->LineDefs
[es
->LineCount
].length
= length
;
580 es
->LineDefs
[es
->LineCount
].ending
= ending
;
582 es
->TextWidth
= MAX(es
->TextWidth
, width
);
598 } while (*start
|| (ending
== END_SOFT
) || (ending
== END_HARD
));
600 if (hFont
) SelectObject32(hdc
, oldFont
);
601 ReleaseDC32(wndPtr
->hwndSelf
, hdc
);
607 /*********************************************************************
609 * EDIT_CallWordBreakProc
611 * Call appropriate WordBreakProc (internal or external).
614 static INT
EDIT_CallWordBreakProc(WND
*wndPtr
, char *s
, INT index
, INT count
, INT action
)
616 EDITWORDBREAKPROC wbp
= (EDITWORDBREAKPROC
)EDIT_EM_GetWordBreakProc(wndPtr
, 0, 0L);
618 if (!wbp
) return EDIT_WordBreakProc(s
, index
, count
, action
);
621 /* We need a SEGPTR here */
623 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
624 SEGPTR ptr
= LOCAL_LockSegptr( wndPtr
->hInstance
, es
->hBuf
) +
625 (UINT16
)(s
- EDIT_GetPointer(wndPtr
));
626 INT ret
= CallWordBreakProc( (FARPROC16
)wbp
, ptr
,
627 index
, count
, action
);
628 LOCAL_Unlock( wndPtr
->hInstance
, es
->hBuf
);
634 /*********************************************************************
638 * Calculates, for a given line and X-coordinate on the screen, the column.
641 static UINT
EDIT_ColFromWndX(WND
*wndPtr
, UINT line
, INT x
)
643 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
644 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, line
, 0L);
645 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, li
, 0L);
648 line
= MAX(0, MIN(line
, lc
- 1));
649 for (i
= 0 ; i
< ll
; i
++)
650 if (EDIT_WndXFromCol(wndPtr
, line
, i
) >= x
)
656 /*********************************************************************
660 * Delete all characters on this line to right of cursor.
663 static void EDIT_DelEnd(WND
*wndPtr
)
665 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(-1, 0));
666 EDIT_MoveEnd(wndPtr
, TRUE
);
667 EDIT_WM_Clear(wndPtr
, 0, 0L);
671 /*********************************************************************
675 * Delete character to left of cursor.
678 static void EDIT_DelLeft(WND
*wndPtr
)
680 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(-1, 0));
681 EDIT_MoveBackward(wndPtr
, TRUE
);
682 EDIT_WM_Clear(wndPtr
, 0, 0L);
686 /*********************************************************************
690 * Delete character to right of cursor.
693 static void EDIT_DelRight(WND
*wndPtr
)
695 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(-1, 0));
696 EDIT_MoveForward(wndPtr
, TRUE
);
697 EDIT_WM_Clear(wndPtr
, 0, 0L);
701 /*********************************************************************
703 * EDIT_GetAveCharWidth
706 static UINT
EDIT_GetAveCharWidth(WND
*wndPtr
)
708 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
710 return es
->AveCharWidth
;
714 /*********************************************************************
719 static UINT
EDIT_GetLineHeight(WND
*wndPtr
)
721 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
723 return es
->LineHeight
;
727 /*********************************************************************
731 * Calculates the bounding rectangle for a line from a starting
732 * column to an ending column.
735 static void EDIT_GetLineRect(WND
*wndPtr
, UINT line
, UINT scol
, UINT ecol
, LPRECT16 rc
)
737 rc
->top
= EDIT_WndYFromLine(wndPtr
, line
);
738 rc
->bottom
= rc
->top
+ EDIT_GetLineHeight(wndPtr
);
739 rc
->left
= EDIT_WndXFromCol(wndPtr
, line
, scol
);
740 rc
->right
= ((INT
)ecol
== -1) ? EDIT_GetWndWidth(wndPtr
) :
741 EDIT_WndXFromCol(wndPtr
, line
, ecol
);
745 /*********************************************************************
749 * This acts as a LOCAL_Lock(), but it locks only once. This way
750 * you can call it whenever you like, without unlocking.
753 static char *EDIT_GetPointer(WND
*wndPtr
)
755 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
757 if (!es
->text
&& es
->hBuf
)
758 es
->text
= LOCAL_Lock(wndPtr
->hInstance
, es
->hBuf
);
763 /*********************************************************************
765 * EDIT_GetPasswordPointer
769 static char *EDIT_GetPasswordPointer(WND
*wndPtr
)
771 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
772 char *text
= xstrdup(EDIT_GetPointer(wndPtr
));
775 if(es
->PasswordChar
) {
778 if(*p
!= '\r' && *p
!= '\n')
779 *p
= es
->PasswordChar
;
787 /*********************************************************************
791 * Beware: This is not the function called on EM_GETRECT.
792 * It expects a (LPRECT) in lParam, not a (SEGPTR).
793 * It is used internally, as if there were no pointer difficulties.
796 static LRESULT
EDIT_GetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
798 GetClientRect16( wndPtr
->hwndSelf
, (LPRECT16
)lParam
);
803 /*********************************************************************
808 static BOOL
EDIT_GetRedraw(WND
*wndPtr
)
810 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
816 /*********************************************************************
820 * Beware: This is not the function called on EM_GETSEL.
821 * It returns the start in the low word and the end in the high word.
822 * NB s can be greater than e.
825 static LRESULT
EDIT_GetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
827 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
829 return MAKELONG(es
->SelStart
, es
->SelEnd
);
832 /*********************************************************************
837 static UINT
EDIT_GetTextWidth(WND
*wndPtr
)
839 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
841 return es
->TextWidth
;
845 /*********************************************************************
847 * EDIT_GetVisibleLineCount
850 static UINT
EDIT_GetVisibleLineCount(WND
*wndPtr
)
854 EDIT_GetRect(wndPtr
, 0, (LPARAM
)&rc
);
855 return MAX(1, MAX(rc
.bottom
- rc
.top
, 0) / EDIT_GetLineHeight(wndPtr
));
859 /*********************************************************************
864 static UINT
EDIT_GetWndWidth(WND
*wndPtr
)
868 EDIT_GetRect(wndPtr
, 0, (LPARAM
)&rc
);
869 return rc
.right
- rc
.left
;
873 /*********************************************************************
878 static UINT
EDIT_GetXOffset(WND
*wndPtr
)
880 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
886 /*********************************************************************
888 * EDIT_InvalidateText
890 * Invalidate the text from offset start upto, but not including,
891 * offset end. Useful for (re)painting the selection.
892 * Regions outside the linewidth are not invalidated.
893 * end == -1 means end == TextLength.
894 * start and end need not be ordered.
897 static void EDIT_InvalidateText(WND
*wndPtr
, UINT start
, UINT end
)
899 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
900 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
914 end
= (UINT
)EDIT_WM_GetTextLength(wndPtr
, 0, 0L);
915 ORDER_UINT(start
, end
);
916 sl
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, start
, 0L);
917 el
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, end
, 0L);
918 if ((el
< fv
) || (sl
> fv
+ vlc
))
921 sc
= start
- (UINT
)EDIT_EM_LineIndex(wndPtr
, sl
, 0L);
922 ec
= end
- (UINT
)EDIT_EM_LineIndex(wndPtr
, el
, 0L);
929 ec
= (UINT
)EDIT_EM_LineLength(wndPtr
,
930 (UINT
)EDIT_EM_LineIndex(wndPtr
, el
, 0L), 0L);
932 EDIT_GetRect(wndPtr
, 0, (LPARAM
)&rcWnd
);
934 EDIT_GetLineRect(wndPtr
, sl
, sc
, ec
, &rcLine
);
935 if (IntersectRect16(&rcUpdate
, &rcWnd
, &rcLine
))
936 InvalidateRect16( wndPtr
->hwndSelf
, &rcUpdate
, FALSE
);
938 EDIT_GetLineRect(wndPtr
, sl
, sc
,
939 (UINT
)EDIT_EM_LineLength(wndPtr
,
940 (UINT
)EDIT_EM_LineIndex(wndPtr
, sl
, 0L), 0L),
942 if (IntersectRect16(&rcUpdate
, &rcWnd
, &rcLine
))
943 InvalidateRect16( wndPtr
->hwndSelf
, &rcUpdate
, FALSE
);
944 for (l
= sl
+ 1 ; l
< el
; l
++) {
945 EDIT_GetLineRect(wndPtr
, l
, 0,
946 (UINT
)EDIT_EM_LineLength(wndPtr
,
947 (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L), 0L),
949 if (IntersectRect16(&rcUpdate
, &rcWnd
, &rcLine
))
950 InvalidateRect16(wndPtr
->hwndSelf
, &rcUpdate
, FALSE
);
952 EDIT_GetLineRect(wndPtr
, el
, 0, ec
, &rcLine
);
953 if (IntersectRect16(&rcUpdate
, &rcWnd
, &rcLine
))
954 InvalidateRect16( wndPtr
->hwndSelf
, &rcUpdate
, FALSE
);
959 /*********************************************************************
963 * Calculates, for a given Y-coordinate on the screen, the line.
966 static UINT
EDIT_LineFromWndY(WND
*wndPtr
, INT y
)
968 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
969 UINT lh
= EDIT_GetLineHeight(wndPtr
);
970 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
972 return MAX(0, MIN(lc
- 1, y
/ lh
+ fv
));
976 /*********************************************************************
980 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
983 static BOOL
EDIT_MakeFit(WND
*wndPtr
, UINT size
)
985 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
987 if (size
<= es
->BufSize
)
989 if (size
> es
->BufLimit
)
991 size
= ((size
/ GROWLENGTH
) + 1) * GROWLENGTH
;
992 if (size
> es
->BufLimit
)
995 dprintf_edit(stddeb
, "edit: EDIT_MakeFit: trying to ReAlloc to %d+1\n", size
);
997 if (LOCAL_ReAlloc(wndPtr
->hInstance
, es
->hBuf
, size
+ 1, LMEM_MOVEABLE
)) {
998 es
->BufSize
= MIN(LOCAL_Size(wndPtr
->hInstance
, es
->hBuf
) - 1, es
->BufLimit
);
1005 /*********************************************************************
1010 static void EDIT_MoveBackward(WND
*wndPtr
, BOOL extend
)
1012 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1013 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1014 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1015 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1019 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
- 1, 0L);
1020 e
= li
+ (UINT
)EDIT_EM_LineLength(wndPtr
, li
, 0L);
1026 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1030 /*********************************************************************
1035 static void EDIT_MoveDownward(WND
*wndPtr
, BOOL extend
)
1037 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1038 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1039 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1040 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, e
, 0L);
1041 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1045 x
= EDIT_WndXFromCol(wndPtr
, l
, e
- li
);
1047 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L) +
1048 EDIT_ColFromWndX(wndPtr
, l
, x
);
1052 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1056 /*********************************************************************
1061 static void EDIT_MoveEnd(WND
*wndPtr
, BOOL extend
)
1063 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1064 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1065 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1066 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, e
, 0L);
1067 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1072 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1076 /*********************************************************************
1081 static void EDIT_MoveForward(WND
*wndPtr
, BOOL extend
)
1083 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1084 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1085 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1086 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, e
, 0L);
1087 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, e
, 0L);
1088 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1092 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
+ 1, 0L);
1097 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1101 /*********************************************************************
1105 * Home key: move to beginning of line.
1108 static void EDIT_MoveHome(WND
*wndPtr
, BOOL extend
)
1110 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1111 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1112 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1113 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1118 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1122 /*********************************************************************
1127 static void EDIT_MovePageDown(WND
*wndPtr
, BOOL extend
)
1129 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1130 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1131 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1132 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, e
, 0L);
1133 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1137 x
= EDIT_WndXFromCol(wndPtr
, l
, e
- li
);
1138 l
= MIN(lc
- 1, l
+ EDIT_GetVisibleLineCount(wndPtr
));
1139 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L) +
1140 EDIT_ColFromWndX(wndPtr
, l
, x
);
1144 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1148 /*********************************************************************
1153 static void EDIT_MovePageUp(WND
*wndPtr
, BOOL extend
)
1155 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1156 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1157 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1158 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1162 x
= EDIT_WndXFromCol(wndPtr
, l
, e
- li
);
1163 l
= MAX(0, l
- EDIT_GetVisibleLineCount(wndPtr
));
1164 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L) +
1165 EDIT_ColFromWndX(wndPtr
, l
, x
);
1169 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1173 /*********************************************************************
1178 static void EDIT_MoveUpward(WND
*wndPtr
, BOOL extend
)
1180 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1181 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1182 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1183 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1187 x
= EDIT_WndXFromCol(wndPtr
, l
, e
- li
);
1189 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L) +
1190 EDIT_ColFromWndX(wndPtr
, l
, x
);
1194 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1198 /*********************************************************************
1200 * EDIT_MoveWordBackward
1203 static void EDIT_MoveWordBackward(WND
*wndPtr
, BOOL extend
)
1205 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1206 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1207 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1208 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, e
, 0L);
1209 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1214 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
- 1, 0L);
1215 e
= li
+ (UINT
)EDIT_EM_LineLength(wndPtr
, li
, 0L);
1218 text
= EDIT_GetPointer(wndPtr
);
1219 e
= li
+ (UINT
)EDIT_CallWordBreakProc(wndPtr
,
1220 text
+ li
, e
- li
, ll
, WB_LEFT
);
1224 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1228 /*********************************************************************
1230 * EDIT_MoveWordForward
1233 static void EDIT_MoveWordForward(WND
*wndPtr
, BOOL extend
)
1235 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1236 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1237 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1238 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, e
, 0L);
1239 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, e
, 0L);
1240 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1245 e
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
+ 1, 0L);
1247 text
= EDIT_GetPointer(wndPtr
);
1248 e
= li
+ (UINT
)EDIT_CallWordBreakProc(wndPtr
,
1249 text
+ li
, e
- li
+ 1, ll
, WB_RIGHT
);
1253 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
1257 /*********************************************************************
1262 static void EDIT_PaintLine(WND
*wndPtr
, HDC32 hdc
, UINT line
, BOOL rev
)
1264 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
1265 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
1266 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
1274 if ((line
< fv
) || (line
> fv
+ vlc
) || (line
>= lc
))
1277 dprintf_edit(stddeb
, "edit: EDIT_PaintLine: line=%d\n", line
);
1279 x
= EDIT_WndXFromCol(wndPtr
, line
, 0);
1280 y
= EDIT_WndYFromLine(wndPtr
, line
);
1281 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, line
, 0L);
1282 ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, li
, 0L);
1283 s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1284 e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1286 s
= MIN(li
+ ll
, MAX(li
, s
));
1287 e
= MIN(li
+ ll
, MAX(li
, e
));
1288 if (rev
&& (s
!= e
) &&
1289 ((GetFocus32() == wndPtr
->hwndSelf
) ||
1290 (wndPtr
->dwStyle
& ES_NOHIDESEL
))) {
1291 x
+= EDIT_PaintText(wndPtr
, hdc
, x
, y
, line
, 0, s
- li
, FALSE
);
1292 x
+= EDIT_PaintText(wndPtr
, hdc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
1293 x
+= EDIT_PaintText(wndPtr
, hdc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
1295 x
+= EDIT_PaintText(wndPtr
, hdc
, x
, y
, line
, 0, ll
, FALSE
);
1299 /*********************************************************************
1304 static UINT
EDIT_PaintText(WND
*wndPtr
, HDC32 hdc
, INT x
, INT y
, UINT line
, UINT col
, UINT count
, BOOL rev
)
1306 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1316 BkColor
= GetBkColor32(hdc
);
1317 TextColor
= GetTextColor32(hdc
);
1319 SetBkColor(hdc
, GetSysColor(COLOR_HIGHLIGHT
));
1320 SetTextColor(hdc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
1322 text
= EDIT_GetPasswordPointer(wndPtr
);
1323 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, line
, 0L);
1324 xoff
= EDIT_GetXOffset(wndPtr
);
1325 ret
= LOWORD(TabbedTextOut(hdc
, x
, y
, text
+ li
+ col
, count
,
1326 es
->NumTabStops
, es
->TabStops
, -xoff
));
1329 SetBkColor(hdc
, BkColor
);
1330 SetTextColor(hdc
, TextColor
);
1336 /*********************************************************************
1338 * EDIT_ReleasePointer
1340 * This is the only helper function that can be called with es = NULL.
1341 * It is called at the end of EditWndProc() to unlock the buffer.
1344 static void EDIT_ReleasePointer(WND
*wndPtr
)
1346 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1350 if (es
->text
&& es
->hBuf
)
1351 LOCAL_Unlock(wndPtr
->hInstance
, es
->hBuf
);
1356 /*********************************************************************
1360 * Beware: This is not the function called on EM_REPLACESEL.
1361 * It expects a (char *) in lParam, not a (SEGPTR).
1362 * It is used internally, as if there were no pointer difficulties.
1365 static LRESULT
EDIT_ReplaceSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1367 const char *str
= (char *)lParam
;
1368 int strl
= strlen(str
);
1369 UINT tl
= (UINT
)EDIT_WM_GetTextLength(wndPtr
, 0, 0L);
1370 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1371 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1378 if (!EDIT_MakeFit(wndPtr
, tl
- (e
- s
) + strl
)) {
1379 EDIT_NOTIFY_PARENT(wndPtr
, EN_MAXTEXT
);
1382 redraw
= EDIT_GetRedraw(wndPtr
);
1383 EDIT_WM_SetRedraw(wndPtr
, FALSE
, 0L);
1384 EDIT_WM_Clear(wndPtr
, 0, 0L);
1385 tl
= EDIT_WM_GetTextLength(wndPtr
, 0, 0L);
1386 e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1387 text
= EDIT_GetPointer(wndPtr
);
1388 for (p
= text
+ tl
; p
>= text
+ e
; p
--)
1390 for (i
= 0 , p
= text
+ e
; i
< strl
; i
++)
1393 AnsiUpperBuff(p
, strl
);
1394 else if(IsLower(wndPtr
))
1395 AnsiLowerBuff(p
, strl
);
1396 EDIT_BuildLineDefs(wndPtr
);
1398 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(e
, e
));
1399 EDIT_EM_SetModify(wndPtr
, TRUE
, 0L);
1400 EDIT_NOTIFY_PARENT(wndPtr
, EN_UPDATE
);
1401 EDIT_WM_SetRedraw(wndPtr
, redraw
, 0L);
1403 InvalidateRect32( wndPtr
->hwndSelf
, NULL
, TRUE
);
1404 EDIT_NOTIFY_PARENT(wndPtr
, EN_CHANGE
);
1410 /*********************************************************************
1412 * EDIT_ScrollIntoView
1414 * Makes sure the caret is visible.
1417 static void EDIT_ScrollIntoView(WND
*wndPtr
)
1419 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1420 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1421 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
1422 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
1423 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
1424 UINT ww
= EDIT_GetWndWidth(wndPtr
);
1425 UINT cw
= EDIT_GetAveCharWidth(wndPtr
);
1426 INT x
= EDIT_WndXFromCol(wndPtr
, l
, e
- li
);
1431 dy
= l
- vlc
+ 1 - fv
;
1435 dx
= x
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1437 dx
= x
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1439 EDIT_EM_LineScroll(wndPtr
, 0, MAKELPARAM(dy
, dx
));
1441 EDIT_NOTIFY_PARENT(wndPtr
, EN_VSCROLL
);
1443 EDIT_NOTIFY_PARENT(wndPtr
, EN_HSCROLL
);
1448 /*********************************************************************
1452 * Calculates, for a given line and column, the X-coordinate on the screen.
1455 static INT
EDIT_WndXFromCol(WND
*wndPtr
, UINT line
, UINT col
)
1457 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1458 char *text
= EDIT_GetPasswordPointer(wndPtr
);
1462 HFONT32 oldFont
= 0;
1463 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
1464 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, line
, 0L);
1465 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, li
, 0L);
1466 UINT xoff
= EDIT_GetXOffset(wndPtr
);
1468 hdc
= GetDC32(wndPtr
->hwndSelf
);
1469 hFont
= (HFONT16
)EDIT_WM_GetFont(wndPtr
, 0, 0L);
1470 if (hFont
) oldFont
= SelectObject32(hdc
, hFont
);
1471 line
= MAX(0, MIN(line
, lc
- 1));
1473 ret
= LOWORD(GetTabbedTextExtent(hdc
,
1475 es
->NumTabStops
, es
->TabStops
)) - xoff
;
1476 if (hFont
) SelectObject32(hdc
, oldFont
);
1477 ReleaseDC32(wndPtr
->hwndSelf
, hdc
);
1483 /*********************************************************************
1487 * Calculates, for a given line, the Y-coordinate on the screen.
1490 static INT
EDIT_WndYFromLine(WND
*wndPtr
, UINT line
)
1492 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
1493 UINT lh
= EDIT_GetLineHeight(wndPtr
);
1495 return (line
- fv
) * lh
;
1499 /*********************************************************************
1501 * EDIT_WordBreakProc
1503 * Find the beginning of words.
1504 * Note: unlike the specs for a WordBreakProc, this function only
1505 * allows to be called without linebreaks between s[0] upto
1506 * s[count - 1]. Remember it is only called
1507 * internally, so we can decide this for ourselves.
1510 static INT
EDIT_WordBreakProc(char *s
, INT index
, INT count
, INT action
)
1514 dprintf_edit(stddeb
, "edit: EDIT_WordBreakProc: s=%p, index=%d"
1515 ", count=%d, action=%d\n", s
, index
, count
, action
);
1523 if (s
[index
] == ' ') {
1524 while (index
&& (s
[index
] == ' '))
1527 while (index
&& (s
[index
] != ' '))
1529 if (s
[index
] == ' ')
1533 while (index
&& (s
[index
] != ' '))
1535 if (s
[index
] == ' ')
1545 if (s
[index
] == ' ')
1546 while ((index
< count
) && (s
[index
] == ' ')) index
++;
1548 while (s
[index
] && (s
[index
] != ' ') && (index
< count
))
1550 while ((s
[index
] == ' ') && (index
< count
)) index
++;
1554 case WB_ISDELIMITER
:
1555 ret
= (s
[index
] == ' ');
1558 fprintf(stderr
, "edit: EDIT_WordBreakProc: unknown action code, please report !\n");
1565 /*********************************************************************
1570 static LRESULT
EDIT_EM_CanUndo(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1576 /*********************************************************************
1578 * EM_EMPTYUNDOBUFFER
1581 static LRESULT
EDIT_EM_EmptyUndoBuffer(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1587 /*********************************************************************
1592 static LRESULT
EDIT_EM_FmtLines(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1594 fprintf(stdnimp
, "edit: EM_FMTLINES: message not implemented.\n");
1595 return wParam
? -1L : 0L;
1599 /*********************************************************************
1601 * EM_GETFIRSTVISIBLELINE
1604 static LRESULT
EDIT_EM_GetFirstVisibleLine(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1606 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1608 return (LRESULT
)es
->FirstVisibleLine
;
1612 /*********************************************************************
1617 static LRESULT
EDIT_EM_GetHandle(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1619 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1621 return (LRESULT
)es
->hBuf
;
1625 /*********************************************************************
1630 static LRESULT
EDIT_EM_GetLine(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1637 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
1639 if (!IsMultiLine(wndPtr
))
1641 if ((UINT
)wParam
>= lc
)
1643 text
= EDIT_GetPointer(wndPtr
);
1644 src
= text
+ (UINT
)EDIT_EM_LineIndex(wndPtr
, wParam
, 0L);
1645 dst
= (char *)PTR_SEG_TO_LIN(lParam
);
1646 len
= MIN(*(WORD
*)dst
, (UINT
)EDIT_EM_LineLength(wndPtr
, wParam
, 0L));
1647 for (i
= 0 ; i
< len
; i
++) {
1652 return (LRESULT
)len
;
1656 /*********************************************************************
1661 static LRESULT
EDIT_EM_GetLineCount(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1663 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1665 return (LRESULT
)es
->LineCount
;
1669 /*********************************************************************
1674 static LRESULT
EDIT_EM_GetModify(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1676 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1678 return (LRESULT
)es
->TextChanged
;
1682 /*********************************************************************
1684 * EM_GETPASSWORDCHAR
1687 static LRESULT
EDIT_EM_GetPasswordChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1689 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1691 return (LRESULT
)es
->PasswordChar
;
1695 /*********************************************************************
1700 static LRESULT
EDIT_EM_GetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1702 return EDIT_GetRect(wndPtr
, wParam
, (LPARAM
)PTR_SEG_TO_LIN(lParam
));
1706 /*********************************************************************
1710 * Returns the ordered selection range so that
1711 * LOWORD(result) < HIWORD(result)
1714 static LRESULT
EDIT_EM_GetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1716 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1717 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1720 return MAKELONG(s
, e
);
1724 /*********************************************************************
1728 * FIXME: undocumented: is this right ?
1731 static LRESULT
EDIT_EM_GetThumb(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1733 return MAKELONG(EDIT_WM_VScroll(wndPtr
, EM_GETTHUMB
, 0L),
1734 EDIT_WM_HScroll(wndPtr
, EM_GETTHUMB
, 0L));
1738 /*********************************************************************
1740 * EM_GETWORDBREAKPROC
1743 static LRESULT
EDIT_EM_GetWordBreakProc(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1745 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1747 return (LRESULT
)es
->WordBreakProc
;
1751 /*********************************************************************
1756 static LRESULT
EDIT_EM_LimitText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1758 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1760 if (IsMultiLine(wndPtr
)) {
1762 es
->BufLimit
= MIN((UINT
)wParam
, BUFLIMIT_MULTI
);
1764 es
->BufLimit
= BUFLIMIT_MULTI
;
1767 es
->BufLimit
= MIN((UINT
)wParam
, BUFLIMIT_SINGLE
);
1769 es
->BufLimit
= BUFLIMIT_SINGLE
;
1775 /*********************************************************************
1780 static LRESULT
EDIT_EM_LineFromChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1784 if (!IsMultiLine(wndPtr
))
1786 if ((INT
)wParam
== -1)
1787 wParam
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1788 l
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L) - 1;
1789 while ((UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L) > (UINT
)wParam
)
1795 /*********************************************************************
1800 static LRESULT
EDIT_EM_LineIndex(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1802 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1805 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
1807 if ((INT
)wParam
== -1) {
1808 e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1810 while (es
->LineDefs
[l
].offset
> e
)
1812 return (LRESULT
)es
->LineDefs
[l
].offset
;
1814 if ((UINT
)wParam
>= lc
)
1816 return (LRESULT
)es
->LineDefs
[(UINT
)wParam
].offset
;
1820 /*********************************************************************
1825 static LRESULT
EDIT_EM_LineLength(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1827 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1833 if (!IsMultiLine(wndPtr
))
1834 return (LRESULT
)es
->LineDefs
[0].length
;
1835 if ((INT
)wParam
== -1) {
1836 s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1837 e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
1838 sl
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, s
, 0L);
1839 el
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
1840 return (LRESULT
)(s
- es
->LineDefs
[sl
].offset
+
1841 es
->LineDefs
[el
].offset
+
1842 es
->LineDefs
[el
].length
- e
);
1844 return (LRESULT
)es
->LineDefs
[(UINT
)EDIT_EM_LineFromChar(wndPtr
, wParam
, 0L)].length
;
1848 /*********************************************************************
1853 static LRESULT
EDIT_EM_LineScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1855 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1856 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
1857 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
1858 UINT nfv
= MAX(0, fv
+ (INT
)LOWORD(lParam
));
1859 UINT xoff
= EDIT_GetXOffset(wndPtr
);
1860 UINT nxoff
= MAX(0, xoff
+ (INT
)HIWORD(lParam
));
1861 UINT tw
= EDIT_GetTextWidth(wndPtr
);
1872 dy
= EDIT_WndYFromLine(wndPtr
, fv
) - EDIT_WndYFromLine(wndPtr
, nfv
);
1874 if (wndPtr
->hwndSelf
== GetFocus32())
1875 HideCaret(wndPtr
->hwndSelf
);
1876 if (EDIT_GetRedraw(wndPtr
))
1877 ScrollWindow32(wndPtr
->hwndSelf
, dx
, dy
, NULL
, NULL
);
1878 es
->FirstVisibleLine
= nfv
;
1879 es
->XOffset
= nxoff
;
1880 if (IsVScrollBar(wndPtr
))
1881 SetScrollPos32(wndPtr
->hwndSelf
, SB_VERT
,
1882 EDIT_WM_VScroll(wndPtr
, EM_GETTHUMB
, 0L), TRUE
);
1883 if (IsHScrollBar(wndPtr
))
1884 SetScrollPos32(wndPtr
->hwndSelf
, SB_HORZ
,
1885 EDIT_WM_HScroll(wndPtr
, EM_GETTHUMB
, 0L), TRUE
);
1886 if (wndPtr
->hwndSelf
== GetFocus32()) {
1887 GetCaretPos16(&pos
);
1888 SetCaretPos(pos
.x
+ dx
, pos
.y
+ dy
);
1889 ShowCaret(wndPtr
->hwndSelf
);
1896 /*********************************************************************
1901 static LRESULT
EDIT_EM_ReplaceSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1903 return (LRESULT
)EDIT_ReplaceSel(wndPtr
, wParam
,
1904 (LPARAM
)(char *)PTR_SEG_TO_LIN(lParam
));
1908 /*********************************************************************
1912 * FIXME: undocumented message.
1915 static LRESULT
EDIT_EM_Scroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1917 fprintf(stdnimp
, "edit: EM_SCROLL: message not implemented (undocumented), please report.\n");
1922 /*********************************************************************
1927 static LRESULT
EDIT_EM_SetHandle(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1929 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1931 if (IsMultiLine(wndPtr
)) {
1932 EDIT_ReleasePointer(wndPtr
);
1934 * old buffer is freed by caller
1936 es
->hBuf
= (HLOCAL16
)wParam
;
1937 es
->BufSize
= LOCAL_Size(wndPtr
->hInstance
, es
->hBuf
) - 1;
1939 es
->FirstVisibleLine
= 0;
1940 es
->SelStart
= es
->SelEnd
= 0;
1941 EDIT_EM_EmptyUndoBuffer(wndPtr
, 0, 0L);
1942 EDIT_EM_SetModify(wndPtr
, FALSE
, 0L);
1943 EDIT_BuildLineDefs(wndPtr
);
1944 if (EDIT_GetRedraw(wndPtr
))
1945 InvalidateRect32( wndPtr
->hwndSelf
, NULL
, TRUE
);
1946 EDIT_ScrollIntoView(wndPtr
);
1952 /*********************************************************************
1957 static LRESULT
EDIT_EM_SetModify(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1959 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1961 es
->TextChanged
= (BOOL
)wParam
;
1966 /*********************************************************************
1968 * EM_SETPASSWORDCHAR
1971 static LRESULT
EDIT_EM_SetPasswordChar(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1973 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
1975 es
->PasswordChar
= (char)wParam
;
1980 /*********************************************************************
1985 static LRESULT
EDIT_EM_SetReadOnly(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
1988 wndPtr
->dwStyle
|= ES_READONLY
;
1990 wndPtr
->dwStyle
&= ~(DWORD
)ES_READONLY
;
1995 /*********************************************************************
2000 static LRESULT
EDIT_EM_SetRect(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2002 fprintf(stdnimp
,"edit: EM_SETRECT: message not implemented, please report.\n");
2007 /*********************************************************************
2012 static LRESULT
EDIT_EM_SetRectNP(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2014 fprintf(stdnimp
,"edit: EM_SETRECTNP: message not implemented, please report.\n");
2019 /*********************************************************************
2024 static LRESULT
EDIT_EM_SetSel(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2026 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2027 UINT ns
= LOWORD(lParam
);
2028 UINT ne
= HIWORD(lParam
);
2029 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2030 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2033 UINT tl
= (UINT
)EDIT_WM_GetTextLength(wndPtr
, 0, 0L);
2035 if ((INT
)ns
== -1) {
2045 if (wndPtr
->hwndSelf
== GetFocus32()) {
2046 el
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, ne
, 0L);
2047 eli
= (UINT
)EDIT_EM_LineIndex(wndPtr
, el
, 0L);
2048 SetCaretPos(EDIT_WndXFromCol(wndPtr
, el
, ne
- eli
),
2049 EDIT_WndYFromLine(wndPtr
, el
));
2052 EDIT_ScrollIntoView(wndPtr
);
2053 if (EDIT_GetRedraw(wndPtr
)) {
2061 EDIT_InvalidateText(wndPtr
, s
, e
);
2062 EDIT_InvalidateText(wndPtr
, ns
, ne
);
2064 EDIT_InvalidateText(wndPtr
, s
, ne
);
2070 /*********************************************************************
2075 static LRESULT
EDIT_EM_SetTabStops(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2077 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2079 if (!IsMultiLine(wndPtr
))
2083 es
->NumTabStops
= (UINT
)wParam
;
2085 es
->TabStops
= NULL
;
2087 es
->TabStops
= (LPINT16
)xmalloc(wParam
* sizeof(INT16
));
2088 memcpy(es
->TabStops
, (LPINT16
)PTR_SEG_TO_LIN(lParam
),
2089 (UINT
)wParam
* sizeof(INT16
));
2095 /*********************************************************************
2097 * EM_SETWORDBREAKPROC
2100 static LRESULT
EDIT_EM_SetWordBreakProc(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2102 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2104 es
->WordBreakProc
= (EDITWORDBREAKPROC
)lParam
;
2109 /*********************************************************************
2114 static LRESULT
EDIT_EM_Undo(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2120 /*********************************************************************
2125 static LRESULT
EDIT_WM_Char(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2128 unsigned char c
= (unsigned char)wParam
;
2133 if (IsMultiLine(wndPtr
)) {
2134 if (IsReadOnly(wndPtr
)) {
2135 EDIT_MoveHome(wndPtr
, FALSE
);
2136 EDIT_MoveDownward(wndPtr
, FALSE
);
2138 EDIT_ReplaceSel(wndPtr
, 0, (LPARAM
)"\r\n");
2142 if (IsMultiLine(wndPtr
) && !IsReadOnly(wndPtr
))
2143 EDIT_ReplaceSel(wndPtr
, 0, (LPARAM
)"\t");
2146 if (!IsReadOnly(wndPtr
) && (c
>= ' ') && (c
!= 127)) {
2149 EDIT_ReplaceSel(wndPtr
, 0, (LPARAM
)str
);
2157 /*********************************************************************
2162 static LRESULT
EDIT_WM_Clear(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2164 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2165 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2170 redraw
= EDIT_GetRedraw(wndPtr
);
2171 EDIT_WM_SetRedraw(wndPtr
, FALSE
, 0L);
2173 text
= EDIT_GetPointer(wndPtr
);
2174 strcpy(text
+ s
, text
+ e
);
2175 EDIT_BuildLineDefs(wndPtr
);
2176 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, s
));
2177 EDIT_EM_SetModify(wndPtr
, TRUE
, 0L);
2178 EDIT_NOTIFY_PARENT(wndPtr
, EN_UPDATE
);
2179 EDIT_WM_SetRedraw(wndPtr
, redraw
, 0L);
2181 InvalidateRect32( wndPtr
->hwndSelf
, NULL
, TRUE
);
2182 EDIT_NOTIFY_PARENT(wndPtr
, EN_CHANGE
);
2189 /*********************************************************************
2194 static LRESULT
EDIT_WM_Copy(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2196 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2197 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2207 hdst
= GlobalAlloc16(GMEM_MOVEABLE
, (DWORD
)(e
- s
+ 1));
2208 dst
= GlobalLock16(hdst
);
2209 text
= EDIT_GetPointer(wndPtr
);
2211 for (i
= 0 ; i
< e
- s
; i
++)
2214 GlobalUnlock16(hdst
);
2215 OpenClipboard(wndPtr
->hwndSelf
);
2217 SetClipboardData(CF_TEXT
, hdst
);
2223 /*********************************************************************
2228 static LRESULT
EDIT_WM_Create(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2230 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
2234 es
= xmalloc(sizeof(EDITSTATE
));
2235 memset(es
, 0, sizeof(EDITSTATE
));
2236 *(EDITSTATE
**)wndPtr
->wExtra
= es
;
2238 if (cs
->style
& WS_VSCROLL
)
2239 cs
->style
|= ES_AUTOVSCROLL
;
2240 if (cs
->style
& WS_HSCROLL
)
2241 cs
->style
|= ES_AUTOHSCROLL
;
2243 /* remove the WS_CAPTION style if it has been set - this is really a */
2244 /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
2245 if ((cs
->style
& WS_BORDER
) && (cs
->style
& WS_DLGFRAME
))
2246 cs
->style
^= WS_DLGFRAME
;
2248 if (IsMultiLine(wndPtr
)) {
2249 es
->BufSize
= BUFSTART_MULTI
;
2250 es
->BufLimit
= BUFLIMIT_MULTI
;
2251 es
->PasswordChar
= '\0';
2253 es
->BufSize
= BUFSTART_SINGLE
;
2254 es
->BufLimit
= BUFLIMIT_SINGLE
;
2255 es
->PasswordChar
= (cs
->style
& ES_PASSWORD
) ? '*' : '\0';
2257 if (!LOCAL_HeapSize(wndPtr
->hInstance
)) {
2258 if (!LocalInit(wndPtr
->hInstance
, 0,
2259 GlobalSize16(wndPtr
->hInstance
))) {
2260 fprintf(stderr
, "edit: WM_CREATE: could not initialize local heap\n");
2263 dprintf_edit(stddeb
, "edit: WM_CREATE: local heap initialized\n");
2265 if (!(es
->hBuf
= LOCAL_Alloc(wndPtr
->hInstance
, LMEM_MOVEABLE
, es
->BufSize
+ 1))) {
2266 fprintf(stderr
, "edit: WM_CREATE: unable to allocate buffer\n");
2269 es
->BufSize
= LOCAL_Size(wndPtr
->hInstance
, es
->hBuf
) - 1;
2270 text
= EDIT_GetPointer(wndPtr
);
2272 EDIT_BuildLineDefs(wndPtr
);
2273 EDIT_WM_SetFont(wndPtr
, 0, 0L);
2274 if (cs
->lpszName
&& *(char *)PTR_SEG_TO_LIN(cs
->lpszName
) != '\0')
2275 EDIT_EM_ReplaceSel(wndPtr
, FALSE
, (LPARAM
)cs
->lpszName
);
2276 EDIT_WM_SetRedraw(wndPtr
, TRUE
, 0L);
2281 /*********************************************************************
2286 static LRESULT
EDIT_WM_Cut(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2288 EDIT_WM_Copy(wndPtr
, 0, 0L);
2289 EDIT_WM_Clear(wndPtr
, 0, 0L);
2294 /*********************************************************************
2299 static LRESULT
EDIT_WM_Destroy(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2301 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2306 EDIT_ReleasePointer(wndPtr
);
2307 LOCAL_Free(wndPtr
->hInstance
, es
->hBuf
);
2309 *(EDITSTATE
**)&wndPtr
->wExtra
= NULL
;
2314 /*********************************************************************
2319 static LRESULT
EDIT_WM_Enable(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2321 EDIT_InvalidateText(wndPtr
, 0, -1);
2326 /*********************************************************************
2331 static LRESULT
EDIT_WM_EraseBkGnd(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2336 hBrush
= (HBRUSH16
)EDIT_SEND_CTLCOLOR(wndPtr
, wParam
);
2337 if (!hBrush
) hBrush
= (HBRUSH32
)GetStockObject32(WHITE_BRUSH
);
2339 GetClientRect16(wndPtr
->hwndSelf
, &rc
);
2340 IntersectClipRect16( (HDC16
)wParam
, rc
.left
, rc
.top
,
2341 rc
.right
, rc
.bottom
);
2342 GetClipBox16((HDC16
)wParam
, &rc
);
2344 * FIXME: specs say that we should UnrealizeObject() the brush,
2345 * but the specs of UnrealizeObject() say that we shouldn't
2346 * unrealize a stock object. The default brush that
2347 * DefWndProc() returns is ... a stock object.
2349 FillRect16((HDC16
)wParam
, &rc
, hBrush
);
2354 /*********************************************************************
2359 static LRESULT
EDIT_WM_GetDlgCode(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2361 return DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
2365 /*********************************************************************
2370 static LRESULT
EDIT_WM_GetFont(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2372 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2374 return (LRESULT
)es
->hFont
;
2378 /*********************************************************************
2383 static LRESULT
EDIT_WM_GetText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2385 char *text
= EDIT_GetPointer(wndPtr
);
2387 LRESULT lResult
= 0L;
2390 if ((UINT
)wParam
> len
) {
2391 strcpy((char *)PTR_SEG_TO_LIN(lParam
), text
);
2392 lResult
= (LRESULT
)len
;
2398 /*********************************************************************
2403 static LRESULT
EDIT_WM_GetTextLength(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2405 char *text
= EDIT_GetPointer(wndPtr
);
2407 return (LRESULT
)strlen(text
);
2411 /*********************************************************************
2415 * FIXME: scrollbar code itself is broken, so this one is a hack.
2418 static LRESULT
EDIT_WM_HScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2420 UINT ww
= EDIT_GetWndWidth(wndPtr
);
2421 UINT tw
= EDIT_GetTextWidth(wndPtr
);
2422 UINT cw
= EDIT_GetAveCharWidth(wndPtr
);
2423 UINT xoff
= EDIT_GetXOffset(wndPtr
);
2436 dx
= -ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2439 dx
= ww
/ HSCROLL_FRACTION
/ cw
* cw
;
2451 case SB_THUMBPOSITION
:
2452 dx
= LOWORD(lParam
) * tw
/ 100 - xoff
;
2454 /* The next two are undocumented ! */
2456 ret
= tw
? MAKELONG(xoff
* 100 / tw
, 0) : 0;
2459 dx
= LOWORD(lParam
);
2466 EDIT_EM_LineScroll(wndPtr
, 0, MAKELPARAM(0, dx
));
2468 EDIT_NOTIFY_PARENT(wndPtr
, EN_HSCROLL
);
2474 /*********************************************************************
2478 * Handling of special keys that don't produce a WM_CHAR
2479 * (i.e. non-printable keys) & Backspace & Delete
2482 static LRESULT
EDIT_WM_KeyDown(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2484 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2485 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2489 if (GetKeyState(VK_MENU
) & 0x8000)
2492 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
2493 control
= GetKeyState(VK_CONTROL
) & 0x8000;
2498 if (IsMultiLine(wndPtr
) && (wParam
== VK_UP
))
2499 EDIT_MoveUpward(wndPtr
, shift
);
2502 EDIT_MoveWordBackward(wndPtr
, shift
);
2504 EDIT_MoveBackward(wndPtr
, shift
);
2508 if (IsMultiLine(wndPtr
) && (wParam
== VK_DOWN
))
2509 EDIT_MoveDownward(wndPtr
, shift
);
2511 EDIT_MoveWordForward(wndPtr
, shift
);
2513 EDIT_MoveForward(wndPtr
, shift
);
2516 EDIT_MoveHome(wndPtr
, shift
);
2519 EDIT_MoveEnd(wndPtr
, shift
);
2522 if (IsMultiLine(wndPtr
))
2523 EDIT_MovePageUp(wndPtr
, shift
);
2526 if (IsMultiLine(wndPtr
))
2527 EDIT_MovePageDown(wndPtr
, shift
);
2530 if (!IsReadOnly(wndPtr
) && !control
)
2532 EDIT_WM_Clear(wndPtr
, 0, 0L);
2534 EDIT_DelLeft(wndPtr
);
2537 if (!IsReadOnly(wndPtr
) && !(shift
&& control
))
2540 EDIT_WM_Cut(wndPtr
, 0, 0L);
2542 EDIT_WM_Clear(wndPtr
, 0, 0L);
2545 EDIT_DelLeft(wndPtr
);
2547 EDIT_DelEnd(wndPtr
);
2549 EDIT_DelRight(wndPtr
);
2554 if (!IsReadOnly(wndPtr
))
2555 EDIT_WM_Paste(wndPtr
, 0, 0L);
2557 EDIT_WM_Copy(wndPtr
, 0, 0L);
2564 /*********************************************************************
2569 static LRESULT
EDIT_WM_KillFocus(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2575 if(!(wndPtr
->dwStyle
& ES_NOHIDESEL
)) {
2576 s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2577 e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2578 EDIT_InvalidateText(wndPtr
, s
, e
);
2580 EDIT_NOTIFY_PARENT(wndPtr
, EN_KILLFOCUS
);
2585 /*********************************************************************
2589 * The caret position has been set on the WM_LBUTTONDOWN message
2592 static LRESULT
EDIT_WM_LButtonDblClk(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2595 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2596 UINT l
= (UINT
)EDIT_EM_LineFromChar(wndPtr
, e
, 0L);
2597 UINT li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
2598 UINT ll
= (UINT
)EDIT_EM_LineLength(wndPtr
, e
, 0L);
2599 char *text
= EDIT_GetPointer(wndPtr
);
2601 s
= li
+ EDIT_CallWordBreakProc (wndPtr
, text
+ li
, e
- li
, ll
, WB_LEFT
);
2602 e
= li
+ EDIT_CallWordBreakProc(wndPtr
, text
+ li
, e
- li
, ll
, WB_RIGHT
);
2603 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
2608 /*********************************************************************
2613 static LRESULT
EDIT_WM_LButtonDown(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2615 INT x
= (INT
)LOWORD(lParam
);
2616 INT y
= (INT
)HIWORD(lParam
);
2617 UINT l
= EDIT_LineFromWndY(wndPtr
, y
);
2621 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
2622 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
2625 SetFocus32(wndPtr
->hwndSelf
);
2626 SetCapture32(wndPtr
->hwndSelf
);
2627 l
= MIN(fv
+ vlc
- 1, MAX(fv
, l
));
2628 x
= MIN(EDIT_GetWndWidth(wndPtr
), MAX(0, x
));
2629 c
= EDIT_ColFromWndX(wndPtr
, l
, x
);
2630 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
2632 if (GetKeyState(VK_SHIFT
) & 0x8000)
2633 s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2636 EDIT_EM_SetSel(wndPtr
, 0, MAKELPARAM(s
, e
));
2641 /*********************************************************************
2646 static LRESULT
EDIT_WM_LButtonUp(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2648 if (GetCapture32() == wndPtr
->hwndSelf
)
2654 /*********************************************************************
2659 static LRESULT
EDIT_WM_MouseMove(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2670 if (GetCapture32() == wndPtr
->hwndSelf
) {
2671 x
= (INT
)LOWORD(lParam
);
2672 y
= (INT
)HIWORD(lParam
);
2673 fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
2674 vlc
= EDIT_GetVisibleLineCount(wndPtr
);
2675 l
= EDIT_LineFromWndY(wndPtr
, y
);
2676 l
= MIN(fv
+ vlc
- 1, MAX(fv
, l
));
2677 x
= MIN(EDIT_GetWndWidth(wndPtr
), MAX(0, x
));
2678 c
= EDIT_ColFromWndX(wndPtr
, l
, x
);
2679 s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2680 li
= (UINT
)EDIT_EM_LineIndex(wndPtr
, l
, 0L);
2681 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(s
, li
+ c
));
2687 /*********************************************************************
2692 static LRESULT
EDIT_WM_Paint(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2696 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
2697 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
2698 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
2701 HFONT32 oldFont
= 0;
2705 BOOL rev
= IsWindowEnabled(wndPtr
->hwndSelf
) &&
2706 ((GetFocus32() == wndPtr
->hwndSelf
) ||
2707 (wndPtr
->dwStyle
& ES_NOHIDESEL
));
2709 hdc
= BeginPaint16(wndPtr
->hwndSelf
, &ps
);
2710 GetClientRect16(wndPtr
->hwndSelf
, &rc
);
2711 IntersectClipRect16( hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2712 hFont
= EDIT_WM_GetFont(wndPtr
, 0, 0L);
2713 if (hFont
) oldFont
= SelectObject32(hdc
, hFont
);
2714 EDIT_SEND_CTLCOLOR(wndPtr
, hdc
);
2715 if (!IsWindowEnabled(wndPtr
->hwndSelf
))
2716 SetTextColor(hdc
, GetSysColor(COLOR_GRAYTEXT
));
2717 GetClipBox16(hdc
, &rcRgn
);
2718 for (i
= fv
; i
<= MIN(fv
+ vlc
, fv
+ lc
- 1) ; i
++ ) {
2719 EDIT_GetLineRect(wndPtr
, i
, 0, -1, &rcLine
);
2720 if (IntersectRect16(&rc
, &rcRgn
, &rcLine
))
2721 EDIT_PaintLine(wndPtr
, hdc
, i
, rev
);
2723 if (hFont
) SelectObject32(hdc
, oldFont
);
2724 EndPaint16(wndPtr
->hwndSelf
, &ps
);
2729 /*********************************************************************
2734 static LRESULT
EDIT_WM_Paste(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2739 OpenClipboard(wndPtr
->hwndSelf
);
2740 if ((hsrc
= GetClipboardData(CF_TEXT
))) {
2741 src
= (char *)GlobalLock16(hsrc
);
2742 EDIT_ReplaceSel(wndPtr
, 0, (LPARAM
)src
);
2743 GlobalUnlock16(hsrc
);
2750 /*********************************************************************
2755 static LRESULT
EDIT_WM_SetCursor(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2757 if (LOWORD(lParam
) == HTCLIENT
) {
2758 SetCursor(LoadCursor16(0, IDC_IBEAM
));
2765 /*********************************************************************
2770 static LRESULT
EDIT_WM_SetFocus(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2772 UINT s
= LOWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2773 UINT e
= HIWORD(EDIT_GetSel(wndPtr
, 0, 0L));
2775 CreateCaret(wndPtr
->hwndSelf
, 0, 2, EDIT_GetLineHeight(wndPtr
));
2776 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(s
, e
));
2777 if(!(wndPtr
->dwStyle
& ES_NOHIDESEL
))
2778 EDIT_InvalidateText(wndPtr
, s
, e
);
2779 ShowCaret(wndPtr
->hwndSelf
);
2780 EDIT_NOTIFY_PARENT(wndPtr
, EN_SETFOCUS
);
2785 /*********************************************************************
2790 static LRESULT
EDIT_WM_SetFont(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2793 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2794 LPARAM sel
= EDIT_GetSel(wndPtr
, 0, 0L);
2796 HFONT32 oldFont
= 0;
2798 es
->hFont
= (HFONT16
)wParam
;
2799 hdc
= GetDC32(wndPtr
->hwndSelf
);
2800 if (es
->hFont
) oldFont
= SelectObject32(hdc
, es
->hFont
);
2801 GetTextMetrics16(hdc
, &tm
);
2802 es
->LineHeight
= HIWORD(GetTextExtent(hdc
, "X", 1));
2803 es
->AveCharWidth
= tm
.tmAveCharWidth
;
2804 if (es
->hFont
) SelectObject32(hdc
, oldFont
);
2805 ReleaseDC32(wndPtr
->hwndSelf
, hdc
);
2806 EDIT_BuildLineDefs(wndPtr
);
2807 if ((BOOL
)lParam
&& EDIT_GetRedraw(wndPtr
))
2808 InvalidateRect32( wndPtr
->hwndSelf
, NULL
, TRUE
);
2809 if (wndPtr
->hwndSelf
== GetFocus32()) {
2811 CreateCaret(wndPtr
->hwndSelf
, 0, 2, EDIT_GetLineHeight(wndPtr
));
2812 EDIT_EM_SetSel(wndPtr
, 1, sel
);
2813 ShowCaret(wndPtr
->hwndSelf
);
2819 /*********************************************************************
2824 static LRESULT
EDIT_WM_SetRedraw(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2826 EDITSTATE
*es
= EDITSTATEPTR(wndPtr
);
2828 es
->Redraw
= (BOOL
)wParam
;
2833 /*********************************************************************
2838 static LRESULT
EDIT_WM_SetText(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2840 EDIT_EM_SetSel(wndPtr
, 1, MAKELPARAM(0, -1));
2841 EDIT_WM_Clear(wndPtr
, 0, 0L);
2843 EDIT_EM_ReplaceSel(wndPtr
, 0, lParam
);
2844 EDIT_EM_EmptyUndoBuffer(wndPtr
, 0, 0L);
2845 EDIT_EM_SetModify(wndPtr
, TRUE
, 0L);
2846 EDIT_ScrollIntoView(wndPtr
);
2851 /*********************************************************************
2856 static LRESULT
EDIT_WM_Size(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2858 if (EDIT_GetRedraw(wndPtr
) &&
2859 ((wParam
== SIZE_MAXIMIZED
) ||
2860 (wParam
== SIZE_RESTORED
))) {
2861 if (IsMultiLine(wndPtr
) && IsWordWrap(wndPtr
))
2862 EDIT_BuildLineDefs(wndPtr
);
2863 InvalidateRect32( wndPtr
->hwndSelf
, NULL
, TRUE
);
2869 /*********************************************************************
2873 * FIXME: scrollbar code itself is broken, so this one is a hack.
2876 static LRESULT
EDIT_WM_VScroll(WND
*wndPtr
, WPARAM32 wParam
, LPARAM lParam
)
2878 UINT lc
= (UINT
)EDIT_EM_GetLineCount(wndPtr
, 0, 0L);
2879 UINT fv
= (UINT
)EDIT_EM_GetFirstVisibleLine(wndPtr
, 0, 0L);
2880 UINT vlc
= EDIT_GetVisibleLineCount(wndPtr
);
2908 case SB_THUMBPOSITION
:
2909 dy
= LOWORD(lParam
) * (lc
- 1) / 100 - fv
;
2911 /* The next two are undocumented ! */
2913 ret
= (lc
> 1) ? MAKELONG(fv
* 100 / (lc
- 1), 0) : 0L;
2916 dy
= LOWORD(lParam
);
2923 EDIT_EM_LineScroll(wndPtr
, 0, MAKELPARAM(dy
, 0));
2925 EDIT_NOTIFY_PARENT(wndPtr
, EN_VSCROLL
);