4 * Copyright David W. Metcalfe, 1994
9 static char Copyright
[] = "Copyright David W. Metcalfe, 1994";
21 /* #define DEBUG_EDIT /* */
22 /* #undef DEBUG_EDIT /* */
26 #define NOTIFY_PARENT(hWndCntrl, wNotifyCode) \
27 SendMessage(GetParent(hWndCntrl), WM_COMMAND, \
28 GetDlgCtrlID(hWndCntrl), MAKELPARAM(hWndCntrl, wNotifyCode));
30 #define MAXTEXTLEN 30000 /* maximum text buffer length */
31 #define EDITLEN 1024 /* starting length for multi-line control */
32 #define ENTRYLEN 256 /* starting length for single line control */
33 #define GROWLENGTH 64 /* buffers grow by this much */
35 #define HSCROLLDIM (ClientWidth(wndPtr) / 3)
36 /* "line" dimension for horizontal scroll */
40 int wlines
; /* number of lines of text */
41 int wtop
; /* top line that is displayed */
42 int wleft
; /* left pixel that is displayed */
43 unsigned int textlen
; /* text buffer length */
44 int textwidth
; /* width of longest line in pixels */
45 RECT fmtrc
; /* rectangle in which to format text */
46 int txtht
; /* height of text line in pixels */
47 HANDLE hText
; /* handle to text buffer */
48 HANDLE hCharWidths
; /* widths of chars in font */
49 HANDLE hTextPtrs
; /* list of line offsets */
50 HANDLE hBlankLine
; /* to fill blank lines quickly */
51 int CurrCol
; /* current column */
52 int CurrLine
; /* current line */
53 int WndCol
; /* current window column */
54 int WndRow
; /* current window row */
55 BOOL TextChanged
; /* TRUE if text has changed */
56 BOOL PaintBkgd
; /* paint control background */
57 unsigned int MaxTextLen
; /* maximum text buffer length */
58 int SelBegLine
; /* beginning line of selection */
59 int SelBegCol
; /* beginning column of selection */
60 int SelEndLine
; /* ending line of selection */
61 int SelEndCol
; /* ending column of selection */
62 HFONT hFont
; /* handle of current font (if not default) */
63 HANDLE hDeletedText
; /* handle to deleted txet buffer for undo */
64 int DeletedLength
; /* length of deleted text */
65 int DeletedCurrLine
; /* starting line from which text was deleted */
66 int DeletedCurrCol
; /* starting col from which text was deleted */
67 int NumTabStops
; /* number of tab stops in buffer hTabStops */
68 HANDLE hTabStops
; /* handle of tab stops buffer */
72 #define ClientWidth(wndPtr) (wndPtr->rectClient.right - \
73 wndPtr->rectClient.left)
74 #define ClientHeight(wndPtr, es) ((wndPtr->rectClient.bottom - \
75 wndPtr->rectClient.top) / es->txtht)
76 #define EditBufLen(wndPtr) (wndPtr->dwStyle & ES_MULTILINE \
78 #define CurrChar (EDIT_TextLine(hwnd, es->CurrLine) + es->CurrCol)
79 #define SelMarked(es) (es->SelBegLine != 0 || es->SelBegCol != 0 || \
80 es->SelEndLine != 0 || es->SelEndCol != 0)
81 #define ROUNDUP(numer, denom) (((numer) % (denom)) \
82 ? ((((numer) + (denom)) / (denom)) * (denom)) \
85 /* macros to access window styles */
86 #define IsAutoVScroll() (wndPtr->dwStyle & ES_AUTOVSCROLL)
87 #define IsAutoHScroll() (wndPtr->dwStyle & ES_AUTOHSCROLL)
88 #define IsMultiLine() (wndPtr->dwStyle & ES_MULTILINE)
89 #define IsVScrollBar() (wndPtr->dwStyle & WS_VSCROLL)
90 #define IsHScrollBar() (wndPtr->dwStyle & WS_HSCROLL)
92 /* internal variables */
93 static BOOL TextMarking
; /* TRUE if text marking in progress */
94 static BOOL ButtonDown
; /* TRUE if left mouse button down */
95 static int ButtonRow
; /* row in text buffer when button pressed */
96 static int ButtonCol
; /* col in text buffer when button pressed */
97 static BOOL Print
= FALSE
;
100 LONG
EditWndProc(HWND hWnd
, WORD uMsg
, WORD wParam
, LONG lParam
);
101 long EDIT_NCCreateMsg(HWND hwnd
, LONG lParam
);
102 long EDIT_CreateMsg(HWND hwnd
, LONG lParam
);
103 void EDIT_ClearTextPointers(HWND hwnd
);
104 void EDIT_BuildTextPointers(HWND hwnd
);
105 void EDIT_ModTextPointers(HWND hwnd
, int lineno
, int var
);
106 void EDIT_PaintMsg(HWND hwnd
);
107 HANDLE
EDIT_GetTextLine(HWND hwnd
, int selection
);
108 char *EDIT_TextLine(HWND hwnd
, int sel
);
109 int EDIT_StrLength(HWND hwnd
, char *str
, int len
, int pcol
);
110 int EDIT_LineLength(HWND hwnd
, int num
);
111 void EDIT_WriteTextLine(HWND hwnd
, RECT
*rc
, int y
);
112 void EDIT_WriteText(HWND hwnd
, char *lp
, int off
, int len
, int row
,
113 int col
, RECT
*rc
, BOOL blank
, BOOL reverse
);
114 HANDLE
EDIT_GetStr(HWND hwnd
, char *lp
, int off
, int len
, int *diff
);
115 void EDIT_CharMsg(HWND hwnd
, WORD wParam
);
116 void EDIT_KeyTyped(HWND hwnd
, short ch
);
117 int EDIT_CharWidth(HWND hwnd
, short ch
, int pcol
);
118 int EDIT_GetNextTabStop(HWND hwnd
, int pcol
);
119 void EDIT_Forward(HWND hwnd
);
120 void EDIT_Downward(HWND hwnd
);
121 void EDIT_Upward(HWND hwnd
);
122 void EDIT_Backward(HWND hwnd
);
123 void EDIT_End(HWND hwnd
);
124 void EDIT_Home(HWND hwnd
);
125 void EDIT_StickEnd(HWND hwnd
);
126 void EDIT_KeyDownMsg(HWND hwnd
, WORD wParam
);
127 void EDIT_KeyHScroll(HWND hwnd
, WORD opt
);
128 void EDIT_KeyVScrollLine(HWND hwnd
, WORD opt
);
129 void EDIT_KeyVScrollPage(HWND hwnd
, WORD opt
);
130 void EDIT_KeyVScrollDoc(HWND hwnd
, WORD opt
);
131 int EDIT_ComputeVScrollPos(HWND hwnd
);
132 int EDIT_ComputeHScrollPos(HWND hwnd
);
133 void EDIT_DelKey(HWND hwnd
);
134 void EDIT_VScrollMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
135 void EDIT_VScrollLine(HWND hwnd
, WORD opt
);
136 void EDIT_VScrollPage(HWND hwnd
, WORD opt
);
137 void EDIT_HScrollMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
138 void EDIT_SizeMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
139 void EDIT_LButtonDownMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
140 void EDIT_MouseMoveMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
141 int EDIT_PixelToChar(HWND hwnd
, int row
, int *pixel
);
142 LONG
EDIT_SetTextMsg(HWND hwnd
, LONG lParam
);
143 void EDIT_ClearText(HWND hwnd
);
144 void EDIT_SetSelMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
145 void EDIT_GetLineCol(HWND hwnd
, int off
, int *line
, int *col
);
146 void EDIT_DeleteSel(HWND hwnd
);
147 void EDIT_ClearSel(HWND hwnd
);
148 int EDIT_TextLineNumber(HWND hwnd
, char *lp
);
149 void EDIT_SetAnchor(HWND hwnd
, int row
, int col
);
150 void EDIT_ExtendSel(HWND hwnd
, int x
, int y
);
151 void EDIT_WriteSel(HWND hwnd
, int y
, int start
, int end
);
152 void EDIT_StopMarking(HWND hwnd
);
153 LONG
EDIT_GetLineMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
154 LONG
EDIT_GetSelMsg(HWND hwnd
);
155 void EDIT_ReplaceSel(HWND hwnd
, LONG lParam
);
156 void EDIT_InsertText(HWND hwnd
, char *str
, int len
);
157 LONG
EDIT_LineFromCharMsg(HWND hwnd
, WORD wParam
);
158 LONG
EDIT_LineIndexMsg(HWND hwnd
, WORD wParam
);
159 LONG
EDIT_LineLengthMsg(HWND hwnd
, WORD wParam
);
160 void EDIT_SetFont(HWND hwnd
, WORD wParam
, LONG lParam
);
161 void EDIT_SaveDeletedText(HWND hwnd
, char *deltext
, int len
, int line
,
163 void EDIT_ClearDeletedText(HWND hwnd
);
164 LONG
EDIT_UndoMsg(HWND hwnd
);
165 unsigned int EDIT_HeapAlloc(HWND hwnd
, int bytes
);
166 void *EDIT_HeapAddr(HWND hwnd
, unsigned int handle
);
167 unsigned int EDIT_HeapReAlloc(HWND hwnd
, unsigned int handle
, int bytes
);
168 void EDIT_HeapFree(HWND hwnd
, unsigned int handle
);
169 unsigned int EDIT_HeapSize(HWND hwnd
, unsigned int handle
);
170 void EDIT_SetHandleMsg(HWND hwnd
, WORD wParam
);
171 LONG
EDIT_SetTabStopsMsg(HWND hwnd
, WORD wParam
, LONG lParam
);
172 void EDIT_CopyToClipboard(HWND hwnd
);
173 void EDIT_PasteMsg(HWND hwnd
);
174 void swap(int *a
, int *b
);
177 LONG
EditWndProc(HWND hwnd
, WORD uMsg
, WORD wParam
, LONG lParam
)
183 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
185 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
189 lResult
= es
->hDeletedText
;
192 case EM_EMPTYUNDOBUFFER
:
193 EDIT_ClearDeletedText(hwnd
);
197 fprintf(stdnimp
,"edit: EM_FMTLINES message received\n");
204 case EM_GETFIRSTVISIBLELINE
:
214 lResult
= EDIT_GetLineMsg(hwnd
, wParam
, lParam
);
219 case EM_GETLINECOUNT
:
221 lResult
= es
->wlines
;
227 lResult
= es
->TextChanged
;
230 case EM_GETPASSWORDCHAR
:
231 fprintf(stdnimp
,"edit: cannot process EM_GETPASSWORDCHAR message\n");
235 GetWindowRect(hwnd
, (LPRECT
)lParam
);
239 lResult
= EDIT_GetSelMsg(hwnd
);
242 case EM_GETWORDBREAKPROC
:
243 fprintf(stdnimp
,"edit: cannot process EM_GETWORDBREAKPROC message\n");
248 es
->MaxTextLen
= wParam
;
249 else if (IsMultiLine())
250 es
->MaxTextLen
= 65535;
252 es
->MaxTextLen
= 32767;
255 case EM_LINEFROMCHAR
:
256 lResult
= EDIT_LineFromCharMsg(hwnd
, wParam
);
261 lResult
= EDIT_LineIndexMsg(hwnd
, wParam
);
267 lResult
= EDIT_LineLengthMsg(hwnd
, wParam
);
271 fprintf(stdnimp
,"edit: cannot process EM_LINESCROLL message\n");
276 EDIT_ReplaceSel(hwnd
, lParam
);
277 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
282 EDIT_SetHandleMsg(hwnd
, wParam
);
286 es
->TextChanged
= wParam
;
289 case EM_SETPASSWORDCHAR
:
290 fprintf(stdnimp
,"edit: cannot process EM_SETPASSWORDCHAR message\n");
294 fprintf(stdnimp
,"edit: cannot process EM_SETREADONLY message\n");
299 fprintf(stdnimp
,"edit: cannot process EM_SETRECT(NP) message\n");
304 EDIT_SetSelMsg(hwnd
, wParam
, lParam
);
305 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
310 lResult
= EDIT_SetTabStopsMsg(hwnd
, wParam
, lParam
);
313 case EM_SETWORDBREAKPROC
:
314 fprintf(stdnimp
,"edit: cannot process EM_SETWORDBREAKPROC message\n");
319 lResult
= EDIT_UndoMsg(hwnd
);
320 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
325 return DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
328 EDIT_CharMsg(hwnd
, wParam
);
332 EDIT_CopyToClipboard(hwnd
);
337 lResult
= EDIT_CreateMsg(hwnd
, lParam
);
341 EDIT_CopyToClipboard(hwnd
);
342 EDIT_DeleteSel(hwnd
);
346 EDIT_HeapFree(hwnd
, es
->hTextPtrs
);
347 EDIT_HeapFree(hwnd
, es
->hCharWidths
);
348 EDIT_HeapFree(hwnd
, es
->hText
);
349 EDIT_HeapFree(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
353 InvalidateRect(hwnd
, NULL
, FALSE
);
357 textPtr
= EDIT_HeapAddr(hwnd
, es
->hText
);
358 if ((int)wParam
> (len
= strlen(textPtr
)))
360 strcpy((char *)lParam
, textPtr
);
361 lResult
= (DWORD
)len
;
367 case WM_GETTEXTLENGTH
:
368 textPtr
= EDIT_HeapAddr(hwnd
, es
->hText
);
369 lResult
= (DWORD
)strlen(textPtr
);
373 EDIT_HScrollMsg(hwnd
, wParam
, lParam
);
377 EDIT_KeyDownMsg(hwnd
, wParam
);
382 NOTIFY_PARENT(hwnd
, EN_KILLFOCUS
);
388 EDIT_LButtonDownMsg(hwnd
, wParam
, lParam
);
389 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
396 EDIT_StopMarking(hwnd
);
401 EDIT_MouseMoveMsg(hwnd
, wParam
, lParam
);
402 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
411 lResult
= EDIT_NCCreateMsg(hwnd
, lParam
);
423 CreateCaret(hwnd
, 0, 2, es
->txtht
);
424 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
426 NOTIFY_PARENT(hwnd
, EN_SETFOCUS
);
431 EDIT_SetFont(hwnd
, wParam
, lParam
);
432 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
437 EDIT_SetTextMsg(hwnd
, lParam
);
441 EDIT_SizeMsg(hwnd
, wParam
, lParam
);
446 EDIT_VScrollMsg(hwnd
, wParam
, lParam
);
450 lResult
= DefWindowProc(hwnd
, uMsg
, wParam
, lParam
);
458 /*********************************************************************
459 * WM_NCCREATE message function
462 long EDIT_NCCreateMsg(HWND hwnd
, LONG lParam
)
464 CREATESTRUCT
*createStruct
= (CREATESTRUCT
*)lParam
;
465 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
467 unsigned int *textPtrs
;
471 /* store pointer to local or global heap in window structure so that */
472 /* EDITSTATE structure itself can be stored on local heap */
473 if (HEAP_LocalFindHeap(createStruct
->hInstance
)!=NULL
)
474 (MDESC
**)*(LONG
*)(wndPtr
->wExtra
+ 2) =
475 &HEAP_LocalFindHeap(createStruct
->hInstance
)->free_list
;
478 (MDESC
**)*(LONG
*)(wndPtr
->wExtra
+ 2) =
479 GlobalLock(createStruct
->hInstance
);
480 /* GlobalUnlock(createStruct->hInstance); */
482 /* allocate space for state variable structure */
483 (HANDLE
)(*(wndPtr
->wExtra
)) = EDIT_HeapAlloc(hwnd
, sizeof(EDITSTATE
));
484 es
= (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
485 es
->hTextPtrs
= EDIT_HeapAlloc(hwnd
, sizeof(int));
486 textPtrs
= (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
487 es
->hCharWidths
= EDIT_HeapAlloc(hwnd
, 256 * sizeof(short));
489 /* --- text buffer */
490 es
->MaxTextLen
= MAXTEXTLEN
+ 1;
491 if (!(createStruct
->lpszName
))
493 es
->textlen
= EditBufLen(wndPtr
) + 1;
494 es
->hText
= EDIT_HeapAlloc(hwnd
, EditBufLen(wndPtr
) + 2);
495 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
496 memset(text
, 0, es
->textlen
+ 2);
497 EDIT_ClearTextPointers(hwnd
);
501 if (strlen(createStruct
->lpszName
) < EditBufLen(wndPtr
))
503 es
->textlen
= EditBufLen(wndPtr
) + 1;
504 es
->hText
= EDIT_HeapAlloc(hwnd
, EditBufLen(wndPtr
) + 2);
505 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
506 strcpy(text
, createStruct
->lpszName
);
507 *(text
+ es
->textlen
) = '\0';
511 es
->hText
= EDIT_HeapAlloc(hwnd
,
512 strlen(createStruct
->lpszName
) + 2);
513 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
514 strcpy(text
, createStruct
->lpszName
);
515 es
->textlen
= strlen(createStruct
->lpszName
) + 1;
517 *(text
+ es
->textlen
+ 1) = '\0';
518 EDIT_BuildTextPointers(hwnd
);
521 if ((createStruct
->style
& WS_VSCROLL
) ||
522 (createStruct
->style
& WS_HSCROLL
)) NC_CreateScrollBars(hwnd
);
524 /* ES_AUTOVSCROLL and ES_AUTOHSCROLL are automatically applied if */
525 /* the corresponding WM_* message is set */
526 if (createStruct
->style
& WS_VSCROLL
)
527 wndPtr
->dwStyle
|= ES_AUTOVSCROLL
;
528 if (createStruct
->style
& WS_HSCROLL
)
529 wndPtr
->dwStyle
|= ES_AUTOHSCROLL
;
531 /* remove the WS_CAPTION style if it has been set - this is really a */
532 /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
533 if (wndPtr
->dwStyle
& WS_BORDER
&& wndPtr
->dwStyle
& WS_DLGFRAME
)
534 wndPtr
->dwStyle
^= WS_DLGFRAME
;
540 /*********************************************************************
541 * WM_CREATE message function
544 long EDIT_CreateMsg(HWND hwnd
, LONG lParam
)
547 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
549 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
555 /* initialize state variable structure */
556 /* --- char width array */
558 charWidths
= (short *)EDIT_HeapAddr(hwnd
, es
->hCharWidths
);
559 memset(charWidths
, 0, 256 * sizeof(short));
560 GetCharWidth(hdc
, 0, 255, charWidths
);
562 /* --- other structure variables */
563 GetTextMetrics(hdc
, &tm
);
564 es
->txtht
= tm
.tmHeight
+ tm
.tmExternalLeading
;
566 es
->wtop
= es
->wleft
= 0;
567 es
->CurrCol
= es
->CurrLine
= 0;
568 es
->WndCol
= es
->WndRow
= 0;
569 es
->TextChanged
= FALSE
;
571 es
->SelBegLine
= es
->SelBegCol
= 0;
572 es
->SelEndLine
= es
->SelEndCol
= 0;
574 es
->hDeletedText
= 0;
575 es
->DeletedLength
= 0;
577 es
->hTabStops
= EDIT_HeapAlloc(hwnd
, sizeof(int));
579 /* allocate space for a line full of blanks to speed up */
581 es
->hBlankLine
= EDIT_HeapAlloc(hwnd
, (ClientWidth(wndPtr
) /
582 charWidths
[32]) + 2);
583 text
= EDIT_HeapAddr(hwnd
, es
->hBlankLine
);
584 memset(text
, ' ', (ClientWidth(wndPtr
) / charWidths
[32]) + 2);
586 /* set up text cursor for edit class */
587 CLASS_FindClassByName("EDIT", &classPtr
);
588 classPtr
->wc
.hCursor
= LoadCursor(0, IDC_IBEAM
);
590 /* paint background on first WM_PAINT */
591 es
->PaintBkgd
= TRUE
;
593 ReleaseDC(hwnd
, hdc
);
598 /*********************************************************************
599 * EDIT_ClearTextPointers
601 * Clear and initialize text line pointer array.
604 void EDIT_ClearTextPointers(HWND hwnd
)
606 unsigned int *textPtrs
;
607 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
609 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
611 es
->hTextPtrs
= EDIT_HeapReAlloc(hwnd
, es
->hTextPtrs
, sizeof(int));
612 textPtrs
= (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
617 /*********************************************************************
618 * EDIT_BuildTextPointers
620 * Build array of pointers to text lines.
623 #define INITLINES 100
625 void EDIT_BuildTextPointers(HWND hwnd
)
627 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
629 int incrs
= INITLINES
;
630 unsigned int off
, len
, temp
;
632 unsigned int *textPtrs
;
635 es
= (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
636 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
637 textPtrs
= (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
638 charWidths
= (short *)EDIT_HeapAddr(hwnd
, es
->hCharWidths
);
640 es
->textwidth
= es
->wlines
= 0;
643 /* advance through text buffer */
646 /* increase size of text pointer array */
647 if (incrs
== INITLINES
)
650 es
->hTextPtrs
= EDIT_HeapReAlloc(hwnd
, es
->hTextPtrs
,
651 (es
->wlines
+ INITLINES
) * sizeof(int));
652 textPtrs
= (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
654 off
= (unsigned int)(cp
- text
); /* offset of beginning of line */
655 *(textPtrs
+ es
->wlines
) = off
;
660 /* advance through current line */
661 while (*cp
&& *cp
!= '\n')
663 len
+= EDIT_CharWidth(hwnd
, (BYTE
)*cp
, len
);
664 /* width of line in pixels */
667 es
->textwidth
= max(es
->textwidth
, len
);
669 cp
++; /* skip '\n' */
672 off
= (unsigned int)(cp
- text
);
673 *(textPtrs
+ es
->wlines
) = off
;
677 /*********************************************************************
678 * EDIT_ModTextPointers
680 * Modify text pointers from a specified position.
683 void EDIT_ModTextPointers(HWND hwnd
, int lineno
, int var
)
685 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
687 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
688 unsigned int *textPtrs
=
689 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
691 while (lineno
< es
->wlines
)
692 *(textPtrs
+ lineno
++) += var
;
696 /*********************************************************************
697 * WM_PAINT message function
700 void EDIT_PaintMsg(HWND hwnd
)
706 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
708 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
710 hdc
= BeginPaint(hwnd
, &ps
);
713 dprintf_edit(stddeb
,"WM_PAINT: rc=(%d,%d), (%d,%d)\n", rc
.left
, rc
.top
,
714 rc
.right
, rc
.bottom
);
717 FillWindow(GetParent(hwnd
), hwnd
, hdc
, CTLCOLOR_EDIT
);
719 for (y
= (rc
.top
/ es
->txtht
); y
<= (rc
.bottom
/ es
->txtht
); y
++)
721 if (y
< es
->wlines
- es
->wtop
)
722 EDIT_WriteTextLine(hwnd
, &rc
, y
+ es
->wtop
);
729 /*********************************************************************
732 * Get a copy of the text in the specified line.
735 HANDLE
EDIT_GetTextLine(HWND hwnd
, int selection
)
742 dprintf_edit(stddeb
,"GetTextLine %d\n", selection
);
743 cp
= cp1
= EDIT_TextLine(hwnd
, selection
);
744 /* advance through line */
745 while (*cp
&& *cp
!= '\n')
751 /* store selected line and return handle */
752 hLine
= EDIT_HeapAlloc(hwnd
, len
+ 6);
753 line
= (char *)EDIT_HeapAddr(hwnd
, hLine
);
754 memmove(line
, cp1
, len
);
760 /*********************************************************************
763 * Return a pointer to the text in the specified line.
766 char *EDIT_TextLine(HWND hwnd
, int sel
)
768 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
770 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
771 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
772 unsigned int *textPtrs
=
773 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
775 return (text
+ *(textPtrs
+ sel
));
779 /*********************************************************************
782 * Return length of string _str_ of length _len_ characters in pixels.
783 * The current column offset in pixels _pcol_ is required to calculate
784 * the width of a tab.
787 int EDIT_StrLength(HWND hwnd
, char *str
, int len
, int pcol
)
790 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
792 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
794 for (i
= 0; i
< len
; i
++)
795 plen
+= EDIT_CharWidth(hwnd
, (BYTE
)(*(str
+ i
)), pcol
+ plen
);
797 dprintf_edit(stddeb
,"EDIT_StrLength: returning %d\n", plen
);
802 /*********************************************************************
805 * Return length of line _num_ in characters.
808 int EDIT_LineLength(HWND hwnd
, int num
)
810 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
812 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
813 char *cp
= EDIT_TextLine(hwnd
, num
);
816 cp1
= strchr(cp
, '\n');
817 return cp1
? (int)(cp1
- cp
) : strlen(cp
);
821 /*********************************************************************
824 * Write the line of text at offset _y_ in text buffer to a window.
827 void EDIT_WriteTextLine(HWND hwnd
, RECT
*rect
, int y
)
830 unsigned char line
[200];
835 int sbl
, sel
, sbc
, sec
;
838 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
840 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
842 /* initialize rectangle if NULL, else copy */
846 GetClientRect(hwnd
, &rc
);
848 dprintf_edit(stddeb
,"WriteTextLine %d\n", y
);
850 /* make sure y is inside the window */
851 if (y
< es
->wtop
|| y
> (es
->wtop
+ ClientHeight(wndPtr
, es
)))
853 dprintf_edit(stddeb
,"EDIT_WriteTextLine: y (%d) is not a displayed line\n", y
);
857 /* make sure rectangle is within window */
858 if (rc
.left
>= ClientWidth(wndPtr
) - 1)
860 dprintf_edit(stddeb
,"EDIT_WriteTextLine: rc.left (%d) is greater than right edge\n",
866 dprintf_edit(stddeb
,"EDIT_WriteTextLine: rc.right (%d) is less than left edge\n",
870 if (y
- es
->wtop
< (rc
.top
/ es
->txtht
) ||
871 y
- es
->wtop
> (rc
.bottom
/ es
->txtht
))
873 dprintf_edit(stddeb
,"EDIT_WriteTextLine: y (%d) is outside window\n", y
);
877 /* get the text and length of line */
878 if ((hLine
= EDIT_GetTextLine(hwnd
, y
)) == 0)
880 lp
= (unsigned char *)EDIT_HeapAddr(hwnd
, hLine
);
881 lnlen
= EDIT_StrLength(hwnd
, lp
, strlen(lp
), 0);
884 /* build the line to display */
885 if (lnlen
< es
->wleft
)
893 lnlen
= lnlen1
- off
;
894 len
= min(lnlen
, rc
.right
- rc
.left
);
899 sbl
= es
->SelBegLine
;
900 sel
= es
->SelEndLine
;
904 /* put lowest marker first */
910 if (sbl
== sel
&& sbc
> sec
)
913 if (y
< sbl
|| y
> sel
)
914 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
, rc
.left
, &rc
,
916 else if (y
> sbl
&& y
< sel
)
917 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
, rc
.left
, &rc
,
921 col
= EDIT_StrLength(hwnd
, lp
, sbc
, 0);
922 if (col
> (es
->wleft
+ rc
.left
))
924 len
= min(col
- off
, rc
.right
- off
);
925 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
926 rc
.left
, &rc
, FALSE
, FALSE
);
931 col
= EDIT_StrLength(hwnd
, lp
, sec
, 0);
932 if (col
< (es
->wleft
+ rc
.right
))
934 len
= min(col
- off
, rc
.right
- off
);
935 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
936 off
- es
->wleft
, &rc
, FALSE
, TRUE
);
938 len
= min(lnlen
- off
, rc
.right
- off
);
939 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
940 off
- es
->wleft
, &rc
, TRUE
, FALSE
);
944 len
= min(lnlen
- off
, rc
.right
- off
);
945 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
946 off
- es
->wleft
, &rc
, TRUE
, TRUE
);
951 len
= min(lnlen
- off
, rc
.right
- off
);
952 if (col
< (es
->wleft
+ rc
.right
))
953 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
954 off
- es
->wleft
, &rc
, TRUE
, TRUE
);
959 col
= EDIT_StrLength(hwnd
, lp
, sec
, 0);
960 if (col
< (es
->wleft
+ rc
.right
))
962 len
= min(col
- off
, rc
.right
- off
);
963 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
964 off
- es
->wleft
, &rc
, FALSE
, TRUE
);
966 len
= min(lnlen
- off
, rc
.right
- off
);
967 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
,
968 off
- es
->wleft
, &rc
, TRUE
, FALSE
);
973 EDIT_WriteText(hwnd
, lp
, off
, len
, y
- es
->wtop
, rc
.left
, &rc
,
976 EDIT_HeapFree(hwnd
, hLine
);
980 /*********************************************************************
983 * Write text to a window
985 * off - offset in text line (in pixels)
986 * len - length from off (in pixels)
987 * row - line in window
988 * col - column in window
989 * rc - rectangle in which to display line
990 * blank - blank remainder of line?
991 * reverse - reverse color of line?
994 void EDIT_WriteText(HWND hwnd
, char *lp
, int off
, int len
, int row
,
995 int col
, RECT
*rc
, BOOL blank
, BOOL reverse
)
999 char *str
, *cp
, *cp1
;
1000 int diff
, num_spaces
, tabwidth
, scol
;
1002 COLORREF oldTextColor
, oldBkgdColor
;
1004 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1006 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1007 short *charWidths
= (short *)EDIT_HeapAddr(hwnd
, es
->hCharWidths
);
1008 char *blanks
= (char *)EDIT_HeapAddr(hwnd
, es
->hBlankLine
);
1010 dprintf_edit(stddeb
,"EDIT_WriteText lp=%s, off=%d, len=%d, row=%d, col=%d, reverse=%d\n", lp
, off
, len
, row
, col
, reverse
);
1013 hStr
= EDIT_GetStr(hwnd
, lp
, off
, len
, &diff
);
1014 str
= (char *)EDIT_HeapAddr(hwnd
, hStr
);
1015 hrgnClip
= CreateRectRgnIndirect(rc
);
1016 SelectClipRgn(hdc
, hrgnClip
);
1019 oldfont
= (HFONT
)SelectObject(hdc
, (HANDLE
)es
->hFont
);
1021 SendMessage(GetParent(hwnd
), WM_CTLCOLOR
, (WORD
)hdc
,
1022 MAKELPARAM(hwnd
, CTLCOLOR_EDIT
));
1026 oldBkgdColor
= GetBkColor(hdc
);
1027 oldTextColor
= GetTextColor(hdc
);
1028 SetBkColor(hdc
, oldTextColor
);
1029 SetTextColor(hdc
, oldBkgdColor
);
1032 if (strlen(blanks
) < (ClientWidth(wndPtr
) / charWidths
[32]) + 2)
1034 es
->hBlankLine
= EDIT_HeapReAlloc(hwnd
, es
->hBlankLine
,
1035 (ClientWidth(wndPtr
) / charWidths
[32]) + 2);
1036 blanks
= EDIT_HeapAddr(hwnd
, es
->hBlankLine
);
1037 memset(blanks
, ' ', (ClientWidth(wndPtr
) / charWidths
[32]) + 2);
1040 if (!(cp
= strchr(str
, VK_TAB
)))
1041 TextOut(hdc
, col
- diff
, row
* es
->txtht
, str
, strlen(str
));
1044 TextOut(hdc
, col
- diff
, row
* es
->txtht
, str
, (int)(cp
- str
));
1045 scol
= EDIT_StrLength(hwnd
, str
, (int)(cp
- str
), 0);
1046 tabwidth
= EDIT_CharWidth(hwnd
, VK_TAB
, scol
);
1047 num_spaces
= tabwidth
/ charWidths
[32] + 1;
1048 TextOut(hdc
, scol
, row
* es
->txtht
, blanks
, num_spaces
);
1052 while (cp1
= strchr(cp
, VK_TAB
))
1054 TextOut(hdc
, scol
, row
* es
->txtht
, cp
, (int)(cp1
- cp
));
1055 scol
+= EDIT_StrLength(hwnd
, cp
, (int)(cp1
- cp
), scol
);
1056 tabwidth
= EDIT_CharWidth(hwnd
, VK_TAB
, scol
);
1057 num_spaces
= tabwidth
/ charWidths
[32] + 1;
1058 TextOut(hdc
, scol
, row
* es
->txtht
, blanks
, num_spaces
);
1063 TextOut(hdc
, scol
, row
* es
->txtht
, cp
, strlen(cp
));
1068 SetBkColor(hdc
, oldBkgdColor
);
1069 SetTextColor(hdc
, oldTextColor
);
1072 /* blank out remainder of line if appropriate */
1075 if ((rc
->right
- col
) > len
)
1077 num_spaces
= (rc
->right
- col
- len
) / charWidths
[32];
1078 TextOut(hdc
, col
+ len
, row
* es
->txtht
, blanks
, num_spaces
);
1083 SelectObject(hdc
, (HANDLE
)oldfont
);
1085 EDIT_HeapFree(hwnd
, hStr
);
1086 ReleaseDC(hwnd
, hdc
);
1090 /*********************************************************************
1093 * Return sub-string starting at pixel _off_ of length _len_ pixels.
1094 * If _off_ is part way through a character, the negative offset of
1095 * the beginning of the character is returned in _diff_, else _diff_
1099 HANDLE
EDIT_GetStr(HWND hwnd
, char *lp
, int off
, int len
, int *diff
)
1103 int ch
= 0, i
= 0, j
, s_i
;
1105 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1107 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1109 dprintf_edit(stddeb
,"EDIT_GetStr %s %d %d\n", lp
, off
, len
);
1114 i
+= EDIT_CharWidth(hwnd
, (BYTE
)(*(lp
+ ch
)), i
);
1118 /* if stepped past _off_, go back a character */
1127 while (i
< len
+ off
)
1129 i
+= EDIT_CharWidth(hwnd
, (BYTE
)(*(lp
+ ch
)), i
);
1133 hStr
= EDIT_HeapAlloc(hwnd
, ch
- ch1
+ 3);
1134 str
= (char *)EDIT_HeapAddr(hwnd
, hStr
);
1135 for (i
= ch1
, j
= 0; i
< ch
; i
++, j
++)
1138 dprintf_edit(stddeb
,"EDIT_GetStr: returning %s\n", str
);
1143 /*********************************************************************
1144 * WM_CHAR message function
1147 void EDIT_CharMsg(HWND hwnd
, WORD wParam
)
1149 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1151 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1153 dprintf_edit(stddeb
,"EDIT_CharMsg: wParam=%c\n", (char)wParam
);
1162 EDIT_KeyTyped(hwnd
, wParam
);
1168 EDIT_KeyTyped(hwnd
, wParam
);
1172 if (wParam
>= 20 && wParam
<= 126)
1173 EDIT_KeyTyped(hwnd
, wParam
);
1179 /*********************************************************************
1182 * Process keystrokes that produce displayable characters.
1185 void EDIT_KeyTyped(HWND hwnd
, short ch
)
1187 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1189 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1190 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
1191 char *currchar
= CurrChar
;
1193 BOOL FullPaint
= FALSE
;
1195 dprintf_edit(stddeb
,"EDIT_KeyTyped: ch=%c\n", (char)ch
);
1197 /* delete selected text (if any) */
1199 EDIT_DeleteSel(hwnd
);
1201 /* test for typing at end of maximum buffer size */
1202 if (currchar
== text
+ es
->MaxTextLen
)
1204 NOTIFY_PARENT(hwnd
, EN_ERRSPACE
);
1208 if (*currchar
== '\0' && IsMultiLine())
1210 /* insert a newline at end of text */
1212 *(currchar
+ 1) = '\0';
1213 EDIT_BuildTextPointers(hwnd
);
1216 /* insert the typed character */
1217 if (text
[es
->textlen
- 1] != '\0')
1219 /* current text buffer is full */
1220 if (es
->textlen
== es
->MaxTextLen
)
1222 /* text buffer is at maximum size */
1223 NOTIFY_PARENT(hwnd
, EN_ERRSPACE
);
1227 /* increase the text buffer size */
1228 es
->textlen
+= GROWLENGTH
;
1229 /* but not above maximum size */
1230 if (es
->textlen
> es
->MaxTextLen
)
1231 es
->textlen
= es
->MaxTextLen
;
1232 es
->hText
= EDIT_HeapReAlloc(hwnd
, es
->hText
, es
->textlen
+ 2);
1234 NOTIFY_PARENT(hwnd
, EN_ERRSPACE
);
1235 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
1236 text
[es
->textlen
- 1] = '\0';
1237 currchar
= CurrChar
;
1239 /* make space for new character and put char in buffer */
1240 memmove(currchar
+ 1, currchar
, strlen(currchar
) + 1);
1242 EDIT_ModTextPointers(hwnd
, es
->CurrLine
+ 1, 1);
1243 es
->TextChanged
= TRUE
;
1244 NOTIFY_PARENT(hwnd
, EN_UPDATE
);
1246 /* re-adjust textwidth, if necessary, and redraw line */
1248 if (IsMultiLine() && es
->wlines
> 1)
1250 es
->textwidth
= max(es
->textwidth
,
1251 EDIT_StrLength(hwnd
, EDIT_TextLine(hwnd
, es
->CurrLine
),
1252 (int)(EDIT_TextLine(hwnd
, es
->CurrLine
+ 1) -
1253 EDIT_TextLine(hwnd
, es
->CurrLine
)), 0));
1256 es
->textwidth
= max(es
->textwidth
,
1257 EDIT_StrLength(hwnd
, text
, strlen(text
), 0));
1258 EDIT_WriteTextLine(hwnd
, NULL
, es
->wtop
+ es
->WndRow
);
1265 EDIT_BuildTextPointers(hwnd
);
1269 /* invalidate rest of window */
1270 GetClientRect(hwnd
, &rc
);
1272 rc
.top
= es
->WndRow
* es
->txtht
;
1273 InvalidateRect(hwnd
, &rc
, FALSE
);
1275 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
1278 NOTIFY_PARENT(hwnd
, EN_CHANGE
);
1282 /* test end of window */
1283 if (es
->WndCol
>= ClientWidth(wndPtr
) -
1284 EDIT_CharWidth(hwnd
, (BYTE
)ch
, es
->WndCol
+ es
->wleft
))
1286 /* TODO:- Word wrap to be handled here */
1288 /* if (!(currchar == text + es->MaxTextLen - 2)) */
1289 EDIT_KeyHScroll(hwnd
, SB_LINEDOWN
);
1291 es
->WndCol
+= EDIT_CharWidth(hwnd
, (BYTE
)ch
, es
->WndCol
+ es
->wleft
);
1293 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
1295 NOTIFY_PARENT(hwnd
, EN_CHANGE
);
1299 /*********************************************************************
1302 * Return the width of the given character in pixels.
1303 * The current column offset in pixels _pcol_ is required to calculate
1304 * the width of a tab.
1307 int EDIT_CharWidth(HWND hwnd
, short ch
, int pcol
)
1309 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1311 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1312 short *charWidths
= (short *)EDIT_HeapAddr(hwnd
, es
->hCharWidths
);
1315 return (charWidths
[ch
]);
1317 return (EDIT_GetNextTabStop(hwnd
, pcol
) - pcol
);
1321 /*********************************************************************
1322 * EDIT_GetNextTabStop
1324 * Return the next tab stop beyond _pcol_.
1327 int EDIT_GetNextTabStop(HWND hwnd
, int pcol
)
1330 int baseUnitWidth
= LOWORD(GetDialogBaseUnits());
1331 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1333 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1334 unsigned short *tabstops
= EDIT_HeapAddr(hwnd
, es
->hTabStops
);
1336 if (es
->NumTabStops
== 0)
1337 return ROUNDUP(pcol
, 8 * baseUnitWidth
);
1338 else if (es
->NumTabStops
== 1)
1339 return ROUNDUP(pcol
, *tabstops
* baseUnitWidth
/ 4);
1342 for (i
= 0; i
< es
->NumTabStops
; i
++)
1344 if (*(tabstops
+ i
) * baseUnitWidth
/ 4 >= pcol
)
1345 return (*(tabstops
+ i
) * baseUnitWidth
/ 4);
1352 /*********************************************************************
1355 * Cursor right key: move right one character position.
1358 void EDIT_Forward(HWND hwnd
)
1360 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1362 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1363 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
1365 if (*CurrChar
== '\0')
1368 if (*CurrChar
== '\n')
1371 EDIT_Downward(hwnd
);
1375 es
->WndCol
+= EDIT_CharWidth(hwnd
, (BYTE
)(*CurrChar
), es
->WndCol
+ es
->wleft
);
1377 if (es
->WndCol
>= ClientWidth(wndPtr
))
1378 EDIT_KeyHScroll(hwnd
, SB_LINEDOWN
);
1384 /*********************************************************************
1387 * Cursor down key: move down one line.
1390 void EDIT_Downward(HWND hwnd
)
1392 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1394 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1396 dprintf_edit(stddeb
,"EDIT_Downward: WndRow=%d, wtop=%d, wlines=%d\n",
1397 es
->WndRow
, es
->wtop
, es
->wlines
);
1399 if (IsMultiLine() && (es
->WndRow
+ es
->wtop
+ 1 < es
->wlines
))
1402 if (es
->WndRow
== ClientHeight(wndPtr
, es
) - 1)
1405 EDIT_KeyVScrollLine(hwnd
, SB_LINEDOWN
);
1409 EDIT_StickEnd(hwnd
);
1414 /*********************************************************************
1417 * Cursor up key: move up one line.
1420 void EDIT_Upward(HWND hwnd
)
1422 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1424 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1426 if (IsMultiLine() && es
->CurrLine
!= 0)
1429 if (es
->WndRow
== 0)
1432 EDIT_KeyVScrollLine(hwnd
, SB_LINEUP
);
1436 EDIT_StickEnd(hwnd
);
1441 /*********************************************************************
1444 * Cursor left key: move left one character position.
1447 void EDIT_Backward(HWND hwnd
)
1449 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1451 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1452 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
1457 if (*CurrChar
== VK_TAB
)
1458 es
->WndCol
-= EDIT_CharWidth(hwnd
, (BYTE
)(*CurrChar
),
1459 EDIT_StrLength(hwnd
,
1460 EDIT_TextLine(hwnd
, es
->CurrLine
),
1463 es
->WndCol
-= EDIT_CharWidth(hwnd
, (BYTE
)(*CurrChar
), 0);
1465 EDIT_KeyHScroll(hwnd
, SB_LINEUP
);
1467 else if (IsMultiLine() && es
->CurrLine
!= 0)
1475 /*********************************************************************
1478 * End key: move to end of line.
1481 void EDIT_End(HWND hwnd
)
1484 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1486 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1487 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
1489 while (*CurrChar
&& *CurrChar
!= '\n')
1491 es
->WndCol
+= EDIT_CharWidth(hwnd
, (BYTE
)(*CurrChar
), es
->WndCol
+ es
->wleft
);
1495 if (es
->WndCol
>= ClientWidth(wndPtr
))
1497 es
->wleft
= es
->WndCol
- ClientWidth(wndPtr
) + HSCROLLDIM
;
1498 es
->WndCol
-= es
->wleft
;
1499 InvalidateRect(hwnd
, NULL
, FALSE
);
1505 /*********************************************************************
1508 * Home key: move to beginning of line.
1511 void EDIT_Home(HWND hwnd
)
1514 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1516 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1518 es
->CurrCol
= es
->WndCol
= 0;
1522 InvalidateRect(hwnd
, NULL
, FALSE
);
1528 /*********************************************************************
1531 * Stick the cursor to the end of the line.
1534 void EDIT_StickEnd(HWND hwnd
)
1536 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1538 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1539 int len
= EDIT_LineLength(hwnd
, es
->CurrLine
);
1540 char *cp
= EDIT_TextLine(hwnd
, es
->CurrLine
);
1543 es
->CurrCol
= min(len
, es
->CurrCol
);
1544 es
->WndCol
= min(EDIT_StrLength(hwnd
, cp
, len
, 0) - es
->wleft
, es
->WndCol
);
1545 currpel
= EDIT_StrLength(hwnd
, cp
, es
->CurrCol
, 0);
1547 if (es
->wleft
> currpel
)
1549 es
->wleft
= max(0, currpel
- 20);
1550 es
->WndCol
= currpel
- es
->wleft
;
1553 else if (currpel
- es
->wleft
>= ClientWidth(wndPtr
))
1555 es
->wleft
= currpel
- (ClientWidth(wndPtr
) - 5);
1556 es
->WndCol
= currpel
- es
->wleft
;
1562 /*********************************************************************
1563 * WM_KEYDOWN message function
1566 void EDIT_KeyDownMsg(HWND hwnd
, WORD wParam
)
1568 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1570 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1572 dprintf_edit(stddeb
,"EDIT_KeyDownMsg: key=%x\n", wParam
);
1579 EDIT_ClearSel(hwnd
);
1583 EDIT_Backward(hwnd
);
1588 EDIT_ClearSel(hwnd
);
1590 EDIT_Downward(hwnd
);
1597 EDIT_ClearSel(hwnd
);
1603 EDIT_ClearSel(hwnd
);
1604 EDIT_Backward(hwnd
);
1609 EDIT_ClearSel(hwnd
);
1615 EDIT_ClearSel(hwnd
);
1623 EDIT_ClearSel(hwnd
);
1624 EDIT_KeyVScrollPage(hwnd
, SB_PAGEUP
);
1632 EDIT_ClearSel(hwnd
);
1633 EDIT_KeyVScrollPage(hwnd
, SB_PAGEDOWN
);
1639 EDIT_DeleteSel(hwnd
);
1642 if (es
->CurrCol
== 0 && es
->CurrLine
== 0)
1644 EDIT_Backward(hwnd
);
1651 EDIT_DeleteSel(hwnd
);
1657 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
1662 /*********************************************************************
1665 * Scroll text horizontally using cursor keys.
1668 void EDIT_KeyHScroll(HWND hwnd
, WORD opt
)
1672 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1674 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1676 if (opt
== SB_LINEDOWN
)
1678 es
->wleft
+= HSCROLLDIM
;
1679 es
->WndCol
-= HSCROLLDIM
;
1685 if (es
->wleft
- HSCROLLDIM
< 0)
1687 es
->WndCol
+= es
->wleft
;
1692 es
->wleft
-= HSCROLLDIM
;
1693 es
->WndCol
+= HSCROLLDIM
;
1697 InvalidateRect(hwnd
, NULL
, FALSE
);
1702 hscrollpos
= EDIT_ComputeHScrollPos(hwnd
);
1703 SetScrollPos(hwnd
, SB_HORZ
, hscrollpos
, TRUE
);
1708 /*********************************************************************
1709 * EDIT_KeyVScrollLine
1711 * Scroll text vertically by one line using keyboard.
1714 void EDIT_KeyVScrollLine(HWND hwnd
, WORD opt
)
1718 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1720 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1725 if (opt
== SB_LINEDOWN
)
1727 /* move down one line */
1728 if (es
->wtop
+ ClientHeight(wndPtr
, es
) >= es
->wlines
)
1734 /* move up one line */
1740 if (IsWindowVisible(hwnd
))
1742 /* adjust client bottom to nearest whole line */
1743 GetClientRect(hwnd
, &rc
);
1744 rc
.bottom
= (rc
.bottom
/ es
->txtht
) * es
->txtht
;
1746 if (opt
== SB_LINEUP
)
1748 /* move up one line (scroll window down) */
1749 ScrollWindow(hwnd
, 0, es
->txtht
, &rc
, &rc
);
1750 /* write top line */
1751 EDIT_WriteTextLine(hwnd
, NULL
, es
->wtop
);
1756 /* move down one line (scroll window up) */
1757 ScrollWindow(hwnd
, 0, -(es
->txtht
), &rc
, &rc
);
1758 /* write bottom line */
1759 y
= (((rc
.bottom
- rc
.top
) / es
->txtht
) - 1);
1760 EDIT_WriteTextLine(hwnd
, NULL
, es
->wtop
+ y
);
1765 /* reset the vertical scroll bar */
1768 vscrollpos
= EDIT_ComputeVScrollPos(hwnd
);
1769 SetScrollPos(hwnd
, SB_VERT
, vscrollpos
, TRUE
);
1774 /*********************************************************************
1775 * EDIT_KeyVScrollPage
1777 * Scroll text vertically by one page using keyboard.
1780 void EDIT_KeyVScrollPage(HWND hwnd
, WORD opt
)
1784 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1786 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1790 if (opt
== SB_PAGEUP
)
1793 es
->wtop
-= ClientHeight(wndPtr
, es
);
1797 if (es
->wtop
+ ClientHeight(wndPtr
, es
) < es
->wlines
)
1799 es
->wtop
+= ClientHeight(wndPtr
, es
);
1800 if (es
->wtop
> es
->wlines
- ClientHeight(wndPtr
, es
))
1801 es
->wtop
= es
->wlines
- ClientHeight(wndPtr
, es
);
1807 es
->CurrLine
= es
->wtop
+ es
->WndRow
;
1808 EDIT_StickEnd(hwnd
);
1809 InvalidateRect(hwnd
, NULL
, TRUE
);
1812 /* reset the vertical scroll bar */
1815 vscrollpos
= EDIT_ComputeVScrollPos(hwnd
);
1816 SetScrollPos(hwnd
, SB_VERT
, vscrollpos
, TRUE
);
1822 /*********************************************************************
1823 * EDIT_KeyVScrollDoc
1825 * Scroll text to top and bottom of document using keyboard.
1828 void EDIT_KeyVScrollDoc(HWND hwnd
, WORD opt
)
1832 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1834 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1840 es
->wtop
= es
->wleft
= 0;
1841 else if (es
->wtop
+ ClientHeight(wndPtr
, es
) < es
->wlines
)
1843 es
->wtop
= es
->wlines
- ClientHeight(wndPtr
, es
);
1847 es
->CurrLine
= es
->wlines
;
1848 es
->WndRow
= es
->wlines
- es
->wtop
;
1850 InvalidateRect(hwnd
, NULL
, TRUE
);
1853 /* reset the vertical scroll bar */
1856 vscrollpos
= EDIT_ComputeVScrollPos(hwnd
);
1857 SetScrollPos(hwnd
, SB_VERT
, vscrollpos
, TRUE
);
1862 /*********************************************************************
1863 * EDIT_ComputeVScrollPos
1865 * Compute the vertical scroll bar position from the window
1866 * position and text width.
1869 int EDIT_ComputeVScrollPos(HWND hwnd
)
1872 short minpos
, maxpos
;
1873 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1875 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1877 GetScrollRange(hwnd
, SB_VERT
, &minpos
, &maxpos
);
1879 if (es
->wlines
> ClientHeight(wndPtr
, es
))
1880 vscrollpos
= (double)(es
->wtop
) / (double)(es
->wlines
-
1881 ClientHeight(wndPtr
, es
)) * (maxpos
- minpos
);
1883 vscrollpos
= minpos
;
1889 /*********************************************************************
1890 * EDIT_ComputeHScrollPos
1892 * Compute the horizontal scroll bar position from the window
1893 * position and text width.
1896 int EDIT_ComputeHScrollPos(HWND hwnd
)
1899 short minpos
, maxpos
;
1900 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1902 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1904 GetScrollRange(hwnd
, SB_HORZ
, &minpos
, &maxpos
);
1906 if (es
->textwidth
> ClientWidth(wndPtr
))
1907 hscrollpos
= (double)(es
->wleft
) / (double)(es
->textwidth
-
1908 ClientWidth(wndPtr
)) * (maxpos
- minpos
);
1910 hscrollpos
= minpos
;
1916 /*********************************************************************
1919 * Delete character to right of cursor.
1922 void EDIT_DelKey(HWND hwnd
)
1925 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1927 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1928 char *currchar
= CurrChar
;
1929 BOOL repaint
= *currchar
== '\n';
1931 if (IsMultiLine() && *currchar
== '\n' && *(currchar
+ 1) == '\0')
1933 strcpy(currchar
, currchar
+ 1);
1934 NOTIFY_PARENT(hwnd
, EN_UPDATE
);
1938 EDIT_BuildTextPointers(hwnd
);
1939 GetClientRect(hwnd
, &rc
);
1940 rc
.top
= es
->WndRow
* es
->txtht
;
1941 InvalidateRect(hwnd
, &rc
, FALSE
);
1946 EDIT_ModTextPointers(hwnd
, es
->CurrLine
+ 1, -1);
1947 EDIT_WriteTextLine(hwnd
, NULL
, es
->WndRow
+ es
->wtop
);
1950 es
->TextChanged
= TRUE
;
1951 NOTIFY_PARENT(hwnd
, EN_CHANGE
);
1954 /*********************************************************************
1955 * WM_VSCROLL message function
1958 void EDIT_VScrollMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
1960 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1962 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
1972 EDIT_VScrollLine(hwnd
, wParam
);
1977 EDIT_VScrollPage(hwnd
, wParam
);
1982 SetCaretPos(es
->WndCol
, es
->WndRow
);
1987 /*********************************************************************
1990 * Scroll text vertically by one line using scrollbars.
1993 void EDIT_VScrollLine(HWND hwnd
, WORD opt
)
1997 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1999 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2001 dprintf_edit(stddeb
,"EDIT_VScrollLine: direction=%d\n", opt
);
2003 if (opt
== SB_LINEDOWN
)
2005 /* move down one line */
2006 if (es
->wtop
+ ClientHeight(wndPtr
, es
) >= es
->wlines
)
2012 /* move up one line */
2018 if (IsWindowVisible(hwnd
))
2020 /* adjust client bottom to nearest whole line */
2021 GetClientRect(hwnd
, &rc
);
2022 rc
.bottom
= (rc
.bottom
/ es
->txtht
) * es
->txtht
;
2024 if (opt
== SB_LINEUP
)
2026 /* move up one line (scroll window down) */
2027 ScrollWindow(hwnd
, 0, es
->txtht
, &rc
, &rc
);
2028 /* write top line */
2029 EDIT_WriteTextLine(hwnd
, NULL
, es
->wtop
);
2034 /* move down one line (scroll window up) */
2035 ScrollWindow(hwnd
, 0, -(es
->txtht
), &rc
, &rc
);
2036 /* write bottom line */
2037 y
= ((rc
.bottom
- rc
.top
/ es
->txtht
) - 1);
2038 EDIT_WriteTextLine(hwnd
, NULL
, es
->wtop
+ y
);
2045 /*********************************************************************
2048 * Scroll text vertically by one page using keyboard.
2051 void EDIT_VScrollPage(HWND hwnd
, WORD opt
)
2055 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2057 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2059 if (opt
== SB_PAGEUP
)
2062 es
->wtop
-= ClientHeight(wndPtr
, es
);
2066 if (es
->wtop
+ ClientHeight(wndPtr
, es
) < es
->wlines
)
2068 es
->wtop
+= ClientHeight(wndPtr
, es
);
2069 if (es
->wtop
> es
->wlines
- ClientHeight(wndPtr
, es
))
2070 es
->wtop
= es
->wlines
- ClientHeight(wndPtr
, es
);
2076 InvalidateRect(hwnd
, NULL
, TRUE
);
2079 /* reset the vertical scroll bar */
2082 vscrollpos
= EDIT_ComputeVScrollPos(hwnd
);
2083 SetScrollPos(hwnd
, SB_VERT
, vscrollpos
, TRUE
);
2088 /*********************************************************************
2089 * WM_HSCROLL message function
2092 void EDIT_HScrollMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2094 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2096 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2104 SetCaretPos(es
->WndCol
, es
->WndRow
* es
->txtht
);
2111 /*********************************************************************
2112 * WM_SIZE message function
2115 void EDIT_SizeMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2118 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2120 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2122 if (wParam
!= SIZE_MAXIMIZED
&& wParam
!= SIZE_RESTORED
) return;
2124 InvalidateRect(hwnd
, NULL
, TRUE
);
2125 es
->PaintBkgd
= TRUE
;
2130 /*********************************************************************
2131 * WM_LBUTTONDOWN message function
2134 void EDIT_LButtonDownMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2139 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2141 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2144 EDIT_ClearSel(hwnd
);
2146 es
->WndRow
= HIWORD(lParam
) / es
->txtht
;
2147 if (es
->WndRow
> es
->wlines
- es
->wtop
- 1)
2150 es
->WndRow
= es
->wlines
- es
->wtop
- 1;
2155 es
->CurrLine
= es
->wtop
+ es
->WndRow
;
2157 cp
= EDIT_TextLine(hwnd
, es
->CurrLine
);
2158 len
= EDIT_LineLength(hwnd
, es
->CurrLine
);
2159 es
->WndCol
= LOWORD(lParam
);
2160 if (es
->WndCol
> EDIT_StrLength(hwnd
, cp
, len
, 0) - es
->wleft
|| end
)
2161 es
->WndCol
= EDIT_StrLength(hwnd
, cp
, len
, 0) - es
->wleft
;
2162 es
->CurrCol
= EDIT_PixelToChar(hwnd
, es
->CurrLine
, &(es
->WndCol
));
2165 ButtonRow
= es
->CurrLine
;
2166 ButtonCol
= es
->CurrCol
;
2170 /*********************************************************************
2171 * WM_MOUSEMOVE message function
2174 void EDIT_MouseMoveMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2176 if (wParam
!= MK_LBUTTON
)
2181 EDIT_SetAnchor(hwnd
, ButtonRow
, ButtonCol
);
2187 EDIT_ExtendSel(hwnd
, LOWORD(lParam
), HIWORD(lParam
));
2191 /*********************************************************************
2194 * Convert a pixel offset in the given row to a character offset,
2195 * adjusting the pixel offset to the nearest whole character if
2199 int EDIT_PixelToChar(HWND hwnd
, int row
, int *pixel
)
2201 int ch
= 0, i
= 0, s_i
;
2203 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2205 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2207 dprintf_edit(stddeb
,"EDIT_PixelToChar: row=%d, pixel=%d\n", row
, *pixel
);
2209 text
= EDIT_TextLine(hwnd
, row
);
2213 i
+= EDIT_CharWidth(hwnd
, (BYTE
)(*(text
+ ch
)), i
);
2217 /* if stepped past _pixel_, go back a character */
2228 /*********************************************************************
2229 * WM_SETTEXT message function
2232 LONG
EDIT_SetTextMsg(HWND hwnd
, LONG lParam
)
2237 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2239 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2241 if (strlen((char *)lParam
) <= es
->MaxTextLen
)
2243 len
= strlen((char *)lParam
);
2244 EDIT_ClearText(hwnd
);
2246 es
->hText
= EDIT_HeapReAlloc(hwnd
, es
->hText
, len
+ 3);
2247 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2248 strcpy(text
, (char *)lParam
);
2249 text
[len
+ 1] = '\0';
2250 text
[len
+ 2] = '\0';
2251 EDIT_BuildTextPointers(hwnd
);
2252 InvalidateRect(hwnd
, NULL
, TRUE
);
2253 es
->PaintBkgd
= TRUE
;
2254 es
->TextChanged
= TRUE
;
2262 /*********************************************************************
2265 * Clear text from text buffer.
2268 void EDIT_ClearText(HWND hwnd
)
2270 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2272 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2273 unsigned int blen
= EditBufLen(wndPtr
) + 2;
2276 es
->hText
= EDIT_HeapReAlloc(hwnd
, es
->hText
, blen
);
2277 text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2278 memset(text
, 0, blen
);
2281 es
->CurrLine
= es
->CurrCol
= 0;
2282 es
->WndRow
= es
->WndCol
= 0;
2283 es
->wleft
= es
->wtop
= 0;
2285 es
->TextChanged
= FALSE
;
2286 EDIT_ClearTextPointers(hwnd
);
2290 /*********************************************************************
2291 * EM_SETSEL message function
2294 void EDIT_SetSelMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2297 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2299 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2301 so
= LOWORD(lParam
);
2302 eo
= HIWORD(lParam
);
2304 if (so
== -1) /* if so == -1, clear selection */
2306 EDIT_ClearSel(hwnd
);
2310 if (so
== eo
) /* if so == eo, set caret only */
2312 EDIT_GetLineCol(hwnd
, so
, &(es
->CurrLine
), &(es
->CurrCol
));
2313 es
->WndRow
= es
->CurrLine
- es
->wtop
;
2317 if (es
->WndRow
< 0 || es
->WndRow
> ClientHeight(wndPtr
, es
))
2319 es
->wtop
= es
->CurrLine
;
2322 es
->WndCol
= EDIT_StrLength(hwnd
,
2323 EDIT_TextLine(hwnd
, es
->CurrLine
),
2324 es
->CurrCol
, 0) - es
->wleft
;
2325 if (es
->WndCol
> ClientWidth(wndPtr
))
2327 es
->wleft
= es
->WndCol
;
2330 else if (es
->WndCol
< 0)
2332 es
->wleft
+= es
->WndCol
;
2337 else /* otherwise set selection */
2342 EDIT_GetLineCol(hwnd
, so
, &(es
->SelBegLine
), &(es
->SelBegCol
));
2343 EDIT_GetLineCol(hwnd
, eo
, &(es
->SelEndLine
), &(es
->SelEndCol
));
2344 es
->CurrLine
= es
->SelEndLine
;
2345 es
->CurrCol
= es
->SelEndCol
;
2346 es
->WndRow
= es
->SelEndLine
- es
->wtop
;
2348 if (!wParam
) /* don't suppress scrolling of text */
2352 es
->wtop
= es
->SelEndLine
;
2355 else if (es
->WndRow
> ClientHeight(wndPtr
, es
))
2357 es
->wtop
+= es
->WndRow
- ClientHeight(wndPtr
, es
);
2358 es
->WndRow
= ClientHeight(wndPtr
, es
);
2360 es
->WndCol
= EDIT_StrLength(hwnd
,
2361 EDIT_TextLine(hwnd
, es
->SelEndLine
),
2362 es
->SelEndCol
, 0) - es
->wleft
;
2363 if (es
->WndCol
> ClientWidth(wndPtr
))
2365 es
->wleft
+= es
->WndCol
- ClientWidth(wndPtr
);
2366 es
->WndCol
= ClientWidth(wndPtr
);
2368 else if (es
->WndCol
< 0)
2370 es
->wleft
+= es
->WndCol
;
2375 InvalidateRect(hwnd
, NULL
, TRUE
);
2381 /*********************************************************************
2384 * Return line and column in text buffer from character offset.
2387 void EDIT_GetLineCol(HWND hwnd
, int off
, int *line
, int *col
)
2391 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2393 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2394 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2395 unsigned int *textPtrs
=
2396 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
2398 /* check for (0,0) */
2406 if (off
> strlen(text
)) off
= strlen(text
);
2408 for (lineno
= 0; lineno
< es
->wlines
; lineno
++)
2410 cp
= text
+ *(textPtrs
+ lineno
);
2411 if (off
== (int)(cp
- text
))
2417 if (off
< (int)(cp
- text
))
2422 *col
= off
- (int)(cp1
- text
);
2424 if (*(text
+ *col
) == '\0')
2430 /*********************************************************************
2433 * Delete the current selected text (if any)
2436 void EDIT_DeleteSel(HWND hwnd
)
2440 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2442 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2443 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2447 bbl
= EDIT_TextLine(hwnd
, es
->SelBegLine
) + es
->SelBegCol
;
2448 bel
= EDIT_TextLine(hwnd
, es
->SelEndLine
) + es
->SelEndCol
;
2449 len
= (int)(bel
- bbl
);
2450 EDIT_SaveDeletedText(hwnd
, bbl
, len
, es
->SelBegLine
, es
->SelBegCol
);
2451 es
->TextChanged
= TRUE
;
2454 es
->CurrLine
= es
->SelBegLine
;
2455 es
->CurrCol
= es
->SelBegCol
;
2456 es
->WndRow
= es
->SelBegLine
- es
->wtop
;
2459 es
->wtop
= es
->SelBegLine
;
2462 es
->WndCol
= EDIT_StrLength(hwnd
, bbl
- es
->SelBegCol
,
2463 es
->SelBegCol
, 0) - es
->wleft
;
2465 EDIT_BuildTextPointers(hwnd
);
2466 es
->PaintBkgd
= TRUE
;
2467 EDIT_ClearSel(hwnd
);
2472 /*********************************************************************
2475 * Clear the current selection.
2478 void EDIT_ClearSel(HWND hwnd
)
2480 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2482 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2484 es
->SelBegLine
= es
->SelBegCol
= 0;
2485 es
->SelEndLine
= es
->SelEndCol
= 0;
2487 InvalidateRect(hwnd
, NULL
, TRUE
);
2492 /*********************************************************************
2493 * EDIT_TextLineNumber
2495 * Return the line number in the text buffer of the supplied
2496 * character pointer.
2499 int EDIT_TextLineNumber(HWND hwnd
, char *lp
)
2503 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2505 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2506 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2507 unsigned int *textPtrs
=
2508 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
2510 for (lineno
= 0; lineno
< es
->wlines
; lineno
++)
2512 cp
= text
+ *(textPtrs
+ lineno
);
2522 /*********************************************************************
2525 * Set down anchor for text marking.
2528 void EDIT_SetAnchor(HWND hwnd
, int row
, int col
)
2531 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2533 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2537 EDIT_ClearSel(hwnd
);
2538 es
->SelBegLine
= es
->SelEndLine
= row
;
2539 es
->SelBegCol
= es
->SelEndCol
= col
;
2542 InvalidateRect(hwnd
, NULL
, FALSE
);
2548 /*********************************************************************
2551 * Extend selection to the given screen co-ordinates.
2554 void EDIT_ExtendSel(HWND hwnd
, int x
, int y
)
2556 int bbl
, bel
, bbc
, bec
;
2560 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2562 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2564 dprintf_edit(stddeb
,"EDIT_ExtendSel: x=%d, y=%d\n", x
, y
);
2566 bbl
= es
->SelEndLine
;
2567 bbc
= es
->SelEndCol
;
2568 cp
= EDIT_TextLine(hwnd
, es
->wtop
+ y
/ es
->txtht
);
2569 len
= EDIT_LineLength(hwnd
, es
->wtop
+ y
/ es
->txtht
);
2571 es
->WndRow
= y
/ es
->txtht
;
2572 if (es
->WndRow
> es
->wlines
- es
->wtop
- 1)
2575 es
->WndRow
= es
->wlines
- es
->wtop
- 1;
2580 es
->CurrLine
= es
->wtop
+ es
->WndRow
;
2581 es
->SelEndLine
= es
->CurrLine
;
2584 if (es
->WndCol
> EDIT_StrLength(hwnd
, cp
, len
, 0) - es
->wleft
|| end
)
2585 es
->WndCol
= EDIT_StrLength(hwnd
, cp
, len
, 0) - es
->wleft
;
2586 es
->CurrCol
= EDIT_PixelToChar(hwnd
, es
->CurrLine
, &(es
->WndCol
));
2587 es
->SelEndCol
= es
->CurrCol
- 1;
2589 bel
= es
->SelEndLine
;
2590 bec
= es
->SelEndCol
;
2592 /* return if no new characters to mark */
2593 if (bbl
== bel
&& bbc
== bec
)
2596 /* put lowest marker first */
2602 if (bbl
== bel
&& bbc
> bec
)
2605 for (y
= bbl
; y
<= bel
; y
++)
2607 if (y
== bbl
&& y
== bel
)
2608 EDIT_WriteSel(hwnd
, y
, bbc
, bec
);
2610 EDIT_WriteSel(hwnd
, y
, bbc
, -1);
2612 EDIT_WriteSel(hwnd
, y
, 0, bec
);
2614 EDIT_WriteSel(hwnd
, y
, 0, -1);
2619 /*********************************************************************
2622 * Display selection by reversing pixels in selected text.
2623 * If end == -1, selection applies to end of line.
2626 void EDIT_WriteSel(HWND hwnd
, int y
, int start
, int end
)
2632 HBRUSH hbrush
, holdbrush
;
2634 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2636 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2638 dprintf_edit(stddeb
,"EDIT_WriteSel: y=%d start=%d end=%d\n", y
, start
,end
);
2639 GetClientRect(hwnd
, &rc
);
2641 /* make sure y is within the window */
2642 if (y
< es
->wtop
|| y
> (es
->wtop
+ ClientHeight(wndPtr
, es
)))
2645 /* get pointer to text */
2646 cp
= EDIT_TextLine(hwnd
, y
);
2648 /* get length of line if end == -1 */
2650 end
= EDIT_LineLength(hwnd
, y
);
2652 scol
= EDIT_StrLength(hwnd
, cp
, start
, 0);
2653 if (scol
> rc
.right
) return;
2654 if (scol
< rc
.left
) scol
= rc
.left
;
2655 ecol
= EDIT_StrLength(hwnd
, cp
, end
, 0);
2656 if (ecol
< rc
.left
) return;
2657 if (ecol
> rc
.right
) ecol
= rc
.right
;
2660 hbrush
= GetStockObject(BLACK_BRUSH
);
2661 holdbrush
= (HBRUSH
)SelectObject(hdc
, (HANDLE
)hbrush
);
2662 olddm
= SetROP2(hdc
, R2_XORPEN
);
2663 Rectangle(hdc
, scol
, y
* es
->txtht
, ecol
, (y
+ 1) * es
->txtht
);
2664 SetROP2(hdc
, olddm
);
2665 SelectObject(hdc
, (HANDLE
)holdbrush
);
2666 ReleaseDC(hwnd
, hdc
);
2670 /*********************************************************************
2673 * Stop text marking (selection).
2676 void EDIT_StopMarking(HWND hwnd
)
2678 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2680 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2682 TextMarking
= FALSE
;
2683 if (es
->SelBegLine
> es
->SelEndLine
)
2685 swap(&(es
->SelBegLine
), &(es
->SelEndLine
));
2686 swap(&(es
->SelBegCol
), &(es
->SelEndCol
));
2688 if (es
->SelBegLine
== es
->SelEndLine
&& es
->SelBegCol
> es
->SelEndCol
)
2689 swap(&(es
->SelBegCol
), &(es
->SelEndCol
));
2693 /*********************************************************************
2694 * EM_GETLINE message function
2697 LONG
EDIT_GetLineMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
2701 char *buffer
= (char *)lParam
;
2702 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2704 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2706 cp
= EDIT_TextLine(hwnd
, wParam
);
2707 cp1
= EDIT_TextLine(hwnd
, wParam
+ 1);
2708 len
= min((int)(cp1
- cp
), (WORD
)(*buffer
));
2709 strncpy(buffer
, cp
, len
);
2715 /*********************************************************************
2716 * EM_GETSEL message function
2719 LONG
EDIT_GetSelMsg(HWND hwnd
)
2722 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2724 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2725 unsigned int *textPtrs
=
2726 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
2728 so
= *(textPtrs
+ es
->SelBegLine
) + es
->SelBegCol
;
2729 eo
= *(textPtrs
+ es
->SelEndLine
) + es
->SelEndCol
;
2731 return MAKELONG(so
, eo
);
2735 /*********************************************************************
2736 * EM_REPLACESEL message function
2739 void EDIT_ReplaceSel(HWND hwnd
, LONG lParam
)
2741 EDIT_DeleteSel(hwnd
);
2742 EDIT_InsertText(hwnd
, (char *)lParam
, strlen((char *)lParam
));
2743 InvalidateRect(hwnd
, NULL
, TRUE
);
2748 /*********************************************************************
2751 * Insert text at current line and column.
2754 void EDIT_InsertText(HWND hwnd
, char *str
, int len
)
2757 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2759 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2760 char *text
= EDIT_HeapAddr(hwnd
, es
->hText
);
2762 plen
= strlen(text
) + len
;
2763 if (plen
+ 1 > es
->textlen
)
2765 es
->hText
= EDIT_HeapReAlloc(hwnd
, es
->hText
, es
->textlen
+ len
);
2766 es
->textlen
= plen
+ 1;
2768 memmove(CurrChar
+ len
, CurrChar
, strlen(CurrChar
) + 1);
2769 memcpy(CurrChar
, str
, len
);
2771 EDIT_BuildTextPointers(hwnd
);
2772 es
->PaintBkgd
= TRUE
;
2773 es
->TextChanged
= TRUE
;
2775 EDIT_GetLineCol(hwnd
, (int)((CurrChar
+ len
) - text
), &(es
->CurrLine
),
2777 es
->WndRow
= es
->CurrLine
- es
->wtop
;
2778 es
->WndCol
= EDIT_StrLength(hwnd
, EDIT_TextLine(hwnd
, es
->CurrLine
),
2779 es
->CurrCol
, 0) - es
->wleft
;
2783 /*********************************************************************
2784 * EM_LINEFROMCHAR message function
2787 LONG
EDIT_LineFromCharMsg(HWND hwnd
, WORD wParam
)
2790 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2792 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2794 if (wParam
== (WORD
)-1)
2795 return (LONG
)(es
->SelBegLine
);
2797 EDIT_GetLineCol(hwnd
, wParam
, &row
, &col
);
2803 /*********************************************************************
2804 * EM_LINEINDEX message function
2807 LONG
EDIT_LineIndexMsg(HWND hwnd
, WORD wParam
)
2809 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2811 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2812 unsigned int *textPtrs
=
2813 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
2815 if (wParam
== (WORD
)-1)
2816 wParam
= es
->CurrLine
;
2818 return (LONG
)(*(textPtrs
+ wParam
));
2822 /*********************************************************************
2823 * EM_LINELENGTH message function
2826 LONG
EDIT_LineLengthMsg(HWND hwnd
, WORD wParam
)
2829 int sbl
, sbc
, sel
, sec
;
2830 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2832 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2833 unsigned int *textPtrs
=
2834 (unsigned int *)EDIT_HeapAddr(hwnd
, es
->hTextPtrs
);
2836 if (wParam
== (WORD
)-1)
2840 sbl
= es
->SelBegLine
;
2841 sbc
= es
->SelBegCol
;
2842 sel
= es
->SelEndLine
;
2843 sec
= es
->SelEndCol
;
2850 if (sbl
== sel
&& sbc
> sec
)
2855 len
= *(textPtrs
+ sbl
+ 1) - *(textPtrs
+ sbl
) - 1;
2856 return len
- sec
- sbc
;
2859 len
= *(textPtrs
+ sel
+ 1) - *(textPtrs
+ sel
) - sec
- 1;
2862 else /* no selection marked */
2864 len
= *(textPtrs
+ es
->CurrLine
+ 1) -
2865 *(textPtrs
+ es
->CurrLine
) - 1;
2869 else /* line number specified */
2871 EDIT_GetLineCol(hwnd
, wParam
, &row
, &col
);
2872 len
= *(textPtrs
+ row
+ 1) - *(textPtrs
+ row
);
2878 /*********************************************************************
2879 * WM_SETFONT message function
2882 void EDIT_SetFont(HWND hwnd
, WORD wParam
, LONG lParam
)
2887 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2889 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2890 short *charWidths
= (short *)EDIT_HeapAddr(hwnd
, es
->hCharWidths
);
2894 oldfont
= (HFONT
)SelectObject(hdc
, (HANDLE
)es
->hFont
);
2895 GetCharWidth(hdc
, 0, 255, charWidths
);
2896 GetTextMetrics(hdc
, &tm
);
2897 es
->txtht
= tm
.tmHeight
+ tm
.tmExternalLeading
;
2898 SelectObject(hdc
, (HANDLE
)oldfont
);
2899 ReleaseDC(hwnd
, hdc
);
2901 es
->WndRow
= (es
->CurrLine
- es
->wtop
) / es
->txtht
;
2902 es
->WndCol
= EDIT_StrLength(hwnd
, EDIT_TextLine(hwnd
, es
->CurrLine
),
2903 es
->CurrCol
, 0) - es
->wleft
;
2905 InvalidateRect(hwnd
, NULL
, TRUE
);
2906 es
->PaintBkgd
= TRUE
;
2907 if (lParam
) UpdateWindow(hwnd
);
2911 /*********************************************************************
2912 * EDIT_SaveDeletedText
2914 * Save deleted text in deleted text buffer.
2917 void EDIT_SaveDeletedText(HWND hwnd
, char *deltext
, int len
,
2921 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2923 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2925 es
->hDeletedText
= GlobalReAlloc(es
->hDeletedText
, len
, GMEM_MOVEABLE
);
2926 if (!es
->hDeletedText
) return;
2927 text
= (char *)GlobalLock(es
->hDeletedText
);
2928 memcpy(text
, deltext
, len
);
2929 GlobalUnlock(es
->hDeletedText
);
2930 es
->DeletedLength
= len
;
2931 es
->DeletedCurrLine
= line
;
2932 es
->DeletedCurrCol
= col
;
2936 /*********************************************************************
2937 * EDIT_ClearDeletedText
2939 * Clear deleted text buffer.
2942 void EDIT_ClearDeletedText(HWND hwnd
)
2944 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2946 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2948 GlobalFree(es
->hDeletedText
);
2949 es
->hDeletedText
= 0;
2950 es
->DeletedLength
= 0;
2954 /*********************************************************************
2955 * EM_UNDO message function
2958 LONG
EDIT_UndoMsg(HWND hwnd
)
2961 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
2963 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
2965 if (es
->hDeletedText
)
2967 text
= (char *)GlobalLock(es
->hDeletedText
);
2968 es
->CurrLine
= es
->DeletedCurrLine
;
2969 es
->CurrCol
= es
->DeletedCurrCol
;
2970 EDIT_InsertText(hwnd
, text
, es
->DeletedLength
);
2971 GlobalUnlock(es
->hDeletedText
);
2972 EDIT_ClearDeletedText(hwnd
);
2974 es
->SelBegLine
= es
->CurrLine
;
2975 es
->SelBegCol
= es
->CurrCol
;
2976 EDIT_GetLineCol(hwnd
, (int)((CurrChar
+ es
->DeletedLength
) - text
),
2977 &(es
->CurrLine
), &(es
->CurrCol
));
2978 es
->WndRow
= es
->CurrLine
- es
->wtop
;
2979 es
->WndCol
= EDIT_StrLength(hwnd
, EDIT_TextLine(hwnd
, es
->CurrLine
),
2980 es
->CurrCol
, 0) - es
->wleft
;
2981 es
->SelEndLine
= es
->CurrLine
;
2982 es
->SelEndCol
= es
->CurrCol
;
2984 InvalidateRect(hwnd
, NULL
, TRUE
);
2993 /*********************************************************************
2996 * Allocate the specified number of bytes on the specified local heap.
2999 unsigned int EDIT_HeapAlloc(HWND hwnd
, int bytes
)
3001 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3003 ret
= ((unsigned int)HEAP_Alloc((MDESC
**)
3004 *(LONG
*)(wndPtr
->wExtra
+ 2),
3005 GMEM_MOVEABLE
, bytes
) & 0xffff);
3007 printf("EDIT_HeapAlloc: Out of heap-memory\n");
3012 /*********************************************************************
3015 * Return the address of the memory pointed to by the handle.
3018 void *EDIT_HeapAddr(HWND hwnd
, unsigned int handle
)
3020 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3022 return ((void *)((handle
) ? ((handle
) | ((unsigned int)
3023 (*(MDESC
**)*(LONG
*)(wndPtr
->wExtra
+ 2))
3024 & 0xffff0000)) : 0));
3028 /*********************************************************************
3031 * Reallocate the memory pointed to by the handle.
3034 unsigned int EDIT_HeapReAlloc(HWND hwnd
, unsigned int handle
, int bytes
)
3036 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3038 return ((unsigned int)HEAP_ReAlloc((MDESC
**)
3039 *(LONG
*)(wndPtr
->wExtra
+ 2),
3040 EDIT_HeapAddr(hwnd
, handle
),
3041 bytes
, GMEM_MOVEABLE
) & 0xffff);
3045 /*********************************************************************
3048 * Frees the memory pointed to by the handle.
3051 void EDIT_HeapFree(HWND hwnd
, unsigned int handle
)
3053 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3055 HEAP_Free((MDESC
**)*(LONG
*)(wndPtr
->wExtra
+ 2),
3056 EDIT_HeapAddr(hwnd
, handle
));
3060 /*********************************************************************
3063 * Return the size of the given object on the local heap.
3066 unsigned int EDIT_HeapSize(HWND hwnd
, unsigned int handle
)
3068 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3070 return HEAP_LocalSize((MDESC
**)*(LONG
*)(wndPtr
->wExtra
+ 2), handle
);
3074 /*********************************************************************
3075 * EM_SETHANDLE message function
3078 void EDIT_SetHandleMsg(HWND hwnd
, WORD wParam
)
3081 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3083 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
3088 es
->MaxTextLen
= EDIT_HeapSize(hwnd
, es
->hText
);
3090 es
->wtop
= es
->wleft
= 0;
3091 es
->CurrLine
= es
->CurrCol
= 0;
3092 es
->WndRow
= es
->WndCol
= 0;
3093 es
->TextChanged
= FALSE
;
3095 es
->SelBegLine
= es
->SelBegCol
= 0;
3096 es
->SelEndLine
= es
->SelEndCol
= 0;
3098 es
->PaintBkgd
= TRUE
;
3099 InvalidateRect(hwnd
, NULL
, TRUE
);
3105 /*********************************************************************
3106 * EM_SETTABSTOPS message function
3109 LONG
EDIT_SetTabStopsMsg(HWND hwnd
, WORD wParam
, LONG lParam
)
3111 unsigned short *tabstops
;
3112 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3114 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
3116 es
->NumTabStops
= wParam
;
3118 es
->hTabStops
= EDIT_HeapReAlloc(hwnd
, es
->hTabStops
, 1);
3119 else if (wParam
== 1)
3121 es
->hTabStops
= EDIT_HeapReAlloc(hwnd
, es
->hTabStops
, 1);
3122 tabstops
= (unsigned short *)EDIT_HeapAddr(hwnd
, es
->hTabStops
);
3123 *tabstops
= (unsigned short)lParam
;
3127 es
->hTabStops
= EDIT_HeapReAlloc(hwnd
, es
->hTabStops
, wParam
);
3128 tabstops
= (unsigned short *)EDIT_HeapAddr(hwnd
, es
->hTabStops
);
3129 memcpy(tabstops
, (unsigned short *)lParam
, wParam
);
3135 /*********************************************************************
3136 * EDIT_CopyToClipboard
3138 * Copy the specified text to the clipboard.
3141 void EDIT_CopyToClipboard(HWND hwnd
)
3147 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
3149 (EDITSTATE
*)EDIT_HeapAddr(hwnd
, (HANDLE
)(*(wndPtr
->wExtra
)));
3151 bbl
= EDIT_TextLine(hwnd
, es
->SelBegLine
) + es
->SelBegCol
;
3152 bel
= EDIT_TextLine(hwnd
, es
->SelEndLine
) + es
->SelEndCol
;
3153 len
= (int)(bel
- bbl
);
3155 hMem
= GlobalAlloc(GHND
, (DWORD
)(len
+ 1));
3156 lpMem
= GlobalLock(hMem
);
3158 for (i
= 0; i
< len
; i
++)
3162 OpenClipboard(hwnd
);
3164 SetClipboardData(CF_TEXT
, hMem
);
3169 /*********************************************************************
3170 * WM_PASTE message function
3173 void EDIT_PasteMsg(HWND hwnd
)
3178 OpenClipboard(hwnd
);
3179 if (!(hClipMem
= GetClipboardData(CF_TEXT
)))
3181 /* no text in clipboard */
3185 lpClipMem
= GlobalLock(hClipMem
);
3186 EDIT_InsertText(hwnd
, lpClipMem
, strlen(lpClipMem
));
3187 GlobalUnlock(hClipMem
);
3189 InvalidateRect(hwnd
, NULL
, TRUE
);
3194 /*********************************************************************
3198 void swap(int *a
, int *b
)