1 /* ------------- textbox.c ------------ */
5 static void ComputeWindowTop(DFWINDOW
);
6 static void ComputeWindowLeft(DFWINDOW
);
7 static int ComputeVScrollBox(DFWINDOW
);
8 static int ComputeHScrollBox(DFWINDOW
);
9 static void MoveScrollBox(DFWINDOW
, int);
10 static char *GetTextLine(DFWINDOW
, int);
15 /* ------------ ADDTEXT Message -------------- */
16 static BOOL
AddTextMsg(DFWINDOW wnd
, char *txt
)
18 /* --- append text to the textbox's buffer --- */
19 unsigned adln
= strlen(txt
);
20 if (adln
> (unsigned)0xfff0)
22 if (wnd
->text
!= NULL
) {
23 /* ---- appending to existing text ---- */
24 unsigned txln
= strlen(wnd
->text
);
25 if ((long)txln
+adln
> (unsigned) 0xfff0)
27 if (txln
+adln
> wnd
->textlen
) {
28 wnd
->text
= DFrealloc(wnd
->text
, txln
+adln
+3);
29 wnd
->textlen
= txln
+adln
+1;
33 /* ------ 1st text appended ------ */
34 wnd
->text
= DFcalloc(1, adln
+3);
35 wnd
->textlen
= adln
+1;
37 if (wnd
->text
!= NULL
) {
38 /* ---- append the text ---- */
39 strcat(wnd
->text
, txt
);
40 strcat(wnd
->text
, "\n");
41 BuildTextPointers(wnd
);
47 /* ------------ DELETETEXT Message -------------- */
48 static void DeleteTextMsg(DFWINDOW wnd
, int lno
)
50 char *cp1
= TextLine(wnd
, lno
);
52 if (lno
== wnd
->wlines
)
55 char *cp2
= TextLine(wnd
, lno
+1);
56 memmove(cp1
, cp2
, strlen(cp2
)+1);
58 BuildTextPointers(wnd
);
61 /* ------------ INSERTTEXT Message -------------- */
62 static void InsertTextMsg(DFWINDOW wnd
, char *txt
, int lno
)
64 if (AddTextMsg(wnd
, txt
)) {
65 int len
= strlen(txt
);
66 char *cp2
= TextLine(wnd
, lno
);
67 char *cp1
= cp2
+len
+1;
68 memmove(cp1
, cp2
, strlen(cp2
)-len
);
71 BuildTextPointers(wnd
);
75 /* ------------ SETTEXT Message -------------- */
76 static void SetTextMsg(DFWINDOW wnd
, char *txt
)
78 /* -- assign new text value to textbox buffer -- */
79 unsigned int len
= strlen(txt
)+1;
80 DfSendMessage(wnd
, CLEARTEXT
, 0, 0);
82 wnd
->text
=DFrealloc(wnd
->text
, len
+1);
83 wnd
->text
[len
] = '\0';
84 strcpy(wnd
->text
, txt
);
85 BuildTextPointers(wnd
);
88 /* ------------ CLEARTEXT Message -------------- */
89 static void ClearTextMsg(DFWINDOW wnd
)
91 /* ----- clear text from textbox ----- */
92 if (wnd
->text
!= NULL
)
98 wnd
->wtop
= wnd
->wleft
= 0;
100 ClearTextPointers(wnd
);
103 /* ------------ KEYBOARD Message -------------- */
104 static int KeyboardMsg(DFWINDOW wnd
, PARAM p1
)
108 return DfSendMessage(wnd
,SCROLL
,FALSE
,0);
110 return DfSendMessage(wnd
,SCROLL
,TRUE
,0);
112 return DfSendMessage(wnd
,HORIZSCROLL
,TRUE
,0);
114 return DfSendMessage(wnd
,HORIZSCROLL
,FALSE
,0);
116 return DfSendMessage(wnd
,SCROLLPAGE
,FALSE
,0);
118 return DfSendMessage(wnd
,SCROLLPAGE
,TRUE
,0);
120 return DfSendMessage(wnd
,HORIZPAGE
,FALSE
,0);
122 return DfSendMessage(wnd
,HORIZPAGE
,TRUE
,0);
124 return DfSendMessage(wnd
,SCROLLDOC
,TRUE
,0);
126 return DfSendMessage(wnd
,SCROLLDOC
,FALSE
,0);
133 /* ------------ LEFT_BUTTON Message -------------- */
134 static int LeftButtonMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
136 int mx
= (int) p1
- GetLeft(wnd
);
137 int my
= (int) p2
- GetTop(wnd
);
138 if (TestAttribute(wnd
, VSCROLLBAR
) &&
139 mx
== WindowWidth(wnd
)-1) {
140 /* -------- in the right border ------- */
141 if (my
== 0 || my
== ClientHeight(wnd
)+1)
142 /* --- above or below the scroll bar --- */
145 /* -------- top scroll button --------- */
146 return DfSendMessage(wnd
, SCROLL
, FALSE
, 0);
147 if (my
== ClientHeight(wnd
))
148 /* -------- bottom scroll button --------- */
149 return DfSendMessage(wnd
, SCROLL
, TRUE
, 0);
150 /* ---------- in the scroll bar ----------- */
151 if (!VSliding
&& my
-1 == wnd
->VScrollBox
) {
154 rc
.lf
= rc
.rt
= GetRight(wnd
);
155 rc
.tp
= GetTop(wnd
)+2;
156 rc
.bt
= GetBottom(wnd
)-2;
157 return DfSendMessage(NULL
, MOUSE_TRAVEL
,
160 if (my
-1 < wnd
->VScrollBox
)
161 return DfSendMessage(wnd
,SCROLLPAGE
,FALSE
,0);
162 if (my
-1 > wnd
->VScrollBox
)
163 return DfSendMessage(wnd
,SCROLLPAGE
,TRUE
,0);
165 if (TestAttribute(wnd
, HSCROLLBAR
) &&
166 my
== WindowHeight(wnd
)-1) {
167 /* -------- in the bottom border ------- */
168 if (mx
== 0 || my
== ClientWidth(wnd
)+1)
169 /* ------ outside the scroll bar ---- */
172 return DfSendMessage(wnd
, HORIZSCROLL
,FALSE
,0);
173 if (mx
== WindowWidth(wnd
)-2)
174 return DfSendMessage(wnd
, HORIZSCROLL
,TRUE
,0);
175 if (!HSliding
&& mx
-1 == wnd
->HScrollBox
) {
176 /* --- hit the scroll box --- */
178 rc
.lf
= GetLeft(wnd
)+2;
179 rc
.rt
= GetRight(wnd
)-2;
180 rc
.tp
= rc
.bt
= GetBottom(wnd
);
181 /* - keep the mouse in the scroll bar - */
182 DfSendMessage(NULL
,MOUSE_TRAVEL
,(PARAM
)&rc
,0);
186 if (mx
-1 < wnd
->HScrollBox
)
187 return DfSendMessage(wnd
,HORIZPAGE
,FALSE
,0);
188 if (mx
-1 > wnd
->HScrollBox
)
189 return DfSendMessage(wnd
,HORIZPAGE
,TRUE
,0);
194 /* ------------ MOUSE_MOVED Message -------------- */
195 static BOOL
MouseMovedMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
197 int mx
= (int) p1
- GetLeft(wnd
);
198 int my
= (int) p2
- GetTop(wnd
);
200 /* ---- dragging the vertical scroll box --- */
201 if (my
-1 != wnd
->VScrollBox
) {
202 foreground
= FrameForeground(wnd
);
203 background
= FrameBackground(wnd
);
204 wputch(wnd
, SCROLLBARCHAR
, WindowWidth(wnd
)-1,
206 wnd
->VScrollBox
= my
-1;
207 wputch(wnd
, SCROLLBOXCHAR
, WindowWidth(wnd
)-1,
213 /* --- dragging the horizontal scroll box --- */
214 if (mx
-1 != wnd
->HScrollBox
) {
215 foreground
= FrameForeground(wnd
);
216 background
= FrameBackground(wnd
);
217 wputch(wnd
, SCROLLBARCHAR
, wnd
->HScrollBox
+1,
218 WindowHeight(wnd
)-1);
219 wnd
->HScrollBox
= mx
-1;
220 wputch(wnd
, SCROLLBOXCHAR
, mx
, WindowHeight(wnd
)-1);
227 /* ------------ BUTTON_RELEASED Message -------------- */
228 static void ButtonReleasedMsg(DFWINDOW wnd
)
230 if (HSliding
|| VSliding
) {
231 /* release the mouse ouside the scroll bar */
232 DfSendMessage(NULL
, MOUSE_TRAVEL
, 0, 0);
233 VSliding
? ComputeWindowTop(wnd
):ComputeWindowLeft(wnd
);
234 DfSendMessage(wnd
, PAINT
, 0, 0);
235 DfSendMessage(wnd
, KEYBOARD_CURSOR
, 0, 0);
236 VSliding
= HSliding
= FALSE
;
240 /* ------------ SCROLL Message -------------- */
241 static BOOL
ScrollMsg(DFWINDOW wnd
, PARAM p1
)
243 /* ---- vertical scroll one line ---- */
245 /* ----- scroll one line up ----- */
246 if (wnd
->wtop
+ClientHeight(wnd
) >= wnd
->wlines
)
251 /* ----- scroll one line down ----- */
256 if (isVisible(wnd
)) {
258 rc
= ClipRectangle(wnd
, ClientRect(wnd
));
260 /* ---- scroll the window ----- */
262 DfSendMessage(wnd
, PAINT
, 0, 0);
264 scroll_window(wnd
, rc
, (int)p1
);
266 /* -- write top line (down) -- */
267 WriteTextLine(wnd
,NULL
,wnd
->wtop
,FALSE
);
269 /* -- write bottom line (up) -- */
270 int y
=RectBottom(rc
)-GetClientTop(wnd
);
271 WriteTextLine(wnd
, NULL
,
276 /* ---- reset the scroll box ---- */
277 if (TestAttribute(wnd
, VSCROLLBAR
)) {
278 int vscrollbox
= ComputeVScrollBox(wnd
);
279 if (vscrollbox
!= wnd
->VScrollBox
)
280 MoveScrollBox(wnd
, vscrollbox
);
286 /* ------------ HORIZSCROLL Message -------------- */
287 static BOOL
HorizScrollMsg(DFWINDOW wnd
, PARAM p1
)
289 /* --- horizontal scroll one column --- */
291 /* --- scroll left --- */
292 if (wnd
->wleft
+ ClientWidth(wnd
)-1 >= wnd
->textwidth
)
297 /* --- scroll right --- */
302 DfSendMessage(wnd
, PAINT
, 0, 0);
306 /* ------------ SCROLLPAGE Message -------------- */
307 static void ScrollPageMsg(DFWINDOW wnd
, PARAM p1
)
309 /* --- vertical scroll one page --- */
310 if ((int) p1
== FALSE
) {
311 /* ---- page up ---- */
313 wnd
->wtop
-= ClientHeight(wnd
);
316 /* ---- page down ---- */
317 if (wnd
->wtop
+ClientHeight(wnd
) < wnd
->wlines
) {
318 wnd
->wtop
+= ClientHeight(wnd
);
319 if (wnd
->wtop
>wnd
->wlines
-ClientHeight(wnd
))
320 wnd
->wtop
=wnd
->wlines
-ClientHeight(wnd
);
325 DfSendMessage(wnd
, PAINT
, 0, 0);
328 /* ------------ HORIZSCROLLPAGE Message -------------- */
329 static void HorizScrollPageMsg(DFWINDOW wnd
, PARAM p1
)
331 /* --- horizontal scroll one page --- */
332 if ((int) p1
== FALSE
)
333 /* ---- page left ----- */
334 wnd
->wleft
-= ClientWidth(wnd
);
336 /* ---- page right ----- */
337 wnd
->wleft
+= ClientWidth(wnd
);
338 if (wnd
->wleft
> wnd
->textwidth
-ClientWidth(wnd
))
339 wnd
->wleft
= wnd
->textwidth
-ClientWidth(wnd
);
343 DfSendMessage(wnd
, PAINT
, 0, 0);
346 /* ------------ SCROLLDOC Message -------------- */
347 static void ScrollDocMsg(DFWINDOW wnd
, PARAM p1
)
349 /* --- scroll to beginning or end of document --- */
351 wnd
->wtop
= wnd
->wleft
= 0;
352 else if (wnd
->wtop
+ClientHeight(wnd
) < wnd
->wlines
){
353 wnd
->wtop
= wnd
->wlines
-ClientHeight(wnd
);
356 DfSendMessage(wnd
, PAINT
, 0, 0);
359 /* ------------ PAINT Message -------------- */
360 static void PaintMsg(DFWINDOW wnd
, PARAM p1
, PARAM p2
)
362 /* ------ paint the client area ----- */
367 /* ----- build the rectangle to paint ----- */
368 if ((DFRECT
*)p1
== NULL
)
369 rc
=RelativeWindowRect(wnd
, WindowRect(wnd
));
372 if (TestAttribute(wnd
, HASBORDER
) &&
373 RectRight(rc
) >= WindowWidth(wnd
)-1) {
374 if (RectLeft(rc
) >= WindowWidth(wnd
)-1)
376 RectRight(rc
) = WindowWidth(wnd
)-2;
378 rcc
= AdjustRectangle(wnd
, rc
);
380 if (!p2
&& wnd
!= inFocus
)
383 /* ----- blank line for padding ----- */
384 memset(blankline
, ' ', DfGetScreenWidth());
385 blankline
[RectRight(rcc
)+1] = '\0';
387 /* ------- each line within rectangle ------ */
388 for (y
= RectTop(rc
); y
<= RectBottom(rc
); y
++){
390 /* ---- test outside of Client area ---- */
391 if (TestAttribute(wnd
,
392 HASBORDER
| HASTITLEBAR
)) {
393 if (y
< TopBorderAdj(wnd
))
395 if (y
> WindowHeight(wnd
)-2)
398 yy
= y
-TopBorderAdj(wnd
);
399 if (yy
< wnd
->wlines
-wnd
->wtop
)
400 /* ---- paint a text line ---- */
401 WriteTextLine(wnd
, &rc
,
402 yy
+wnd
->wtop
, FALSE
);
404 /* ---- paint a blank line ---- */
405 SetStandardColor(wnd
);
406 writeline(wnd
, blankline
+RectLeft(rcc
),
407 RectLeft(rcc
)+BorderAdj(wnd
), y
, FALSE
);
410 /* ------- position the scroll box ------- */
411 if (TestAttribute(wnd
, VSCROLLBAR
|HSCROLLBAR
)) {
412 int hscrollbox
= ComputeHScrollBox(wnd
);
413 int vscrollbox
= ComputeVScrollBox(wnd
);
414 if (hscrollbox
!= wnd
->HScrollBox
||
415 vscrollbox
!= wnd
->VScrollBox
) {
416 wnd
->HScrollBox
= hscrollbox
;
417 wnd
->VScrollBox
= vscrollbox
;
418 DfSendMessage(wnd
, BORDER
, p1
, 0);
421 if (!p2
&& wnd
!= inFocus
)
425 /* ------------ CLOSE_WINDOW Message -------------- */
426 static void CloseWindowMsg(DFWINDOW wnd
)
428 DfSendMessage(wnd
, CLEARTEXT
, 0, 0);
429 if (wnd
->TextPointers
!= NULL
) {
430 free(wnd
->TextPointers
);
431 wnd
->TextPointers
= NULL
;
435 /* ----------- TEXTBOX Message-processing Module ----------- */
436 int TextBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
440 wnd
->HScrollBox
= wnd
->VScrollBox
= 1;
441 ClearTextPointers(wnd
);
444 return AddTextMsg(wnd
, (char *) p1
);
446 DeleteTextMsg(wnd
, (int) p1
);
449 InsertTextMsg(wnd
, (char *) p1
, (int) p2
);
452 SetTextMsg(wnd
, (char *) p1
);
458 if (WindowMoving
|| WindowSizing
)
460 if (KeyboardMsg(wnd
, p1
))
464 if (WindowSizing
|| WindowMoving
)
466 if (LeftButtonMsg(wnd
, p1
, p2
))
470 if (MouseMovedMsg(wnd
, p1
, p2
))
473 case DFM_BUTTON_RELEASED
:
474 ButtonReleasedMsg(wnd
);
477 return ScrollMsg(wnd
, p1
);
479 return HorizScrollMsg(wnd
, p1
);
481 ScrollPageMsg(wnd
, p1
);
484 HorizScrollPageMsg(wnd
, p1
);
487 ScrollDocMsg(wnd
, p1
);
492 PaintMsg(wnd
, p1
, p2
);
502 return BaseWndProc(TEXTBOX
, wnd
, msg
, p1
, p2
);
505 /* ------ compute the vertical scroll box position from
506 the text pointers --------- */
507 static int ComputeVScrollBox(DFWINDOW wnd
)
509 int pagelen
= wnd
->wlines
- ClientHeight(wnd
);
510 int barlen
= ClientHeight(wnd
)-2;
514 if (pagelen
< 1 || barlen
< 1)
517 if (pagelen
> barlen
)
518 lines_tick
= pagelen
/ barlen
;
520 lines_tick
= barlen
/ pagelen
;
521 vscrollbox
= 1 + (wnd
->wtop
/ lines_tick
);
522 if (vscrollbox
> ClientHeight(wnd
)-2 ||
523 wnd
->wtop
+ ClientHeight(wnd
) >= wnd
->wlines
)
524 vscrollbox
= ClientHeight(wnd
)-2;
529 /* ---- compute top text line from scroll box position ---- */
530 static void ComputeWindowTop(DFWINDOW wnd
)
532 int pagelen
= wnd
->wlines
- ClientHeight(wnd
);
533 if (wnd
->VScrollBox
== 0)
535 else if (wnd
->VScrollBox
== ClientHeight(wnd
)-2)
538 int barlen
= ClientHeight(wnd
)-2;
541 if (pagelen
> barlen
)
542 lines_tick
= barlen
? (pagelen
/ barlen
) : 0;
544 lines_tick
= pagelen
? (barlen
/ pagelen
) : 0;
545 wnd
->wtop
= (wnd
->VScrollBox
-1) * lines_tick
;
546 if (wnd
->wtop
+ ClientHeight(wnd
) > wnd
->wlines
)
553 /* ------ compute the horizontal scroll box position from
554 the text pointers --------- */
555 static int ComputeHScrollBox(DFWINDOW wnd
)
557 int pagewidth
= wnd
->textwidth
- ClientWidth(wnd
);
558 int barlen
= ClientWidth(wnd
)-2;
562 if (pagewidth
< 1 || barlen
< 1)
565 if (pagewidth
> barlen
)
566 chars_tick
= barlen
? (pagewidth
/ barlen
) : 0;
568 chars_tick
= pagewidth
? (barlen
/ pagewidth
) : 0;
569 hscrollbox
= 1 + (chars_tick
? (wnd
->wleft
/ chars_tick
) : 0);
570 if (hscrollbox
> ClientWidth(wnd
)-2 ||
571 wnd
->wleft
+ ClientWidth(wnd
) >= wnd
->textwidth
)
572 hscrollbox
= ClientWidth(wnd
)-2;
577 /* ---- compute left column from scroll box position ---- */
578 static void ComputeWindowLeft(DFWINDOW wnd
)
580 int pagewidth
= wnd
->textwidth
- ClientWidth(wnd
);
582 if (wnd
->HScrollBox
== 0)
584 else if (wnd
->HScrollBox
== ClientWidth(wnd
)-2)
585 wnd
->wleft
= pagewidth
;
587 int barlen
= ClientWidth(wnd
)-2;
590 if (pagewidth
> barlen
)
591 chars_tick
= pagewidth
/ barlen
;
593 chars_tick
= barlen
/ pagewidth
;
594 wnd
->wleft
= (wnd
->HScrollBox
-1) * chars_tick
;
595 if (wnd
->wleft
+ ClientWidth(wnd
) > wnd
->textwidth
)
596 wnd
->wleft
= pagewidth
;
602 /* ----- get the text to a specified line ----- */
603 static char *GetTextLine(DFWINDOW wnd
, int selection
)
608 cp
= cp1
= TextLine(wnd
, selection
);
609 while (*cp
&& *cp
!= '\n') {
613 line
= DFmalloc(len
+7);
614 memmove(line
, cp1
, len
);
619 /* ------- write a line of text to a textbox window ------- */
620 void WriteTextLine(DFWINDOW wnd
, DFRECT
*rcc
, int y
, BOOL reverse
)
624 unsigned char line
[200];
626 unsigned char *lp
, *svlp
;
631 /* ------ make sure y is inside the window ----- */
632 if (y
< wnd
->wtop
|| y
>= wnd
->wtop
+ClientHeight(wnd
))
635 /* ---- build the retangle within which can write ---- */
637 rc
= RelativeWindowRect(wnd
, WindowRect(wnd
));
638 if (TestAttribute(wnd
, HASBORDER
) &&
639 RectRight(rc
) >= WindowWidth(wnd
)-1)
640 RectRight(rc
) = WindowWidth(wnd
)-2;
645 /* ----- make sure rectangle is within window ------ */
646 if (RectLeft(rc
) >= WindowWidth(wnd
)-1)
648 if (RectRight(rc
) == 0)
650 rc
= AdjustRectangle(wnd
, rc
);
651 if (y
-wnd
->wtop
<RectTop(rc
) || y
-wnd
->wtop
>RectBottom(rc
))
654 /* --- get the text and length of the text line --- */
655 lp
= svlp
= GetTextLine(wnd
, y
);
658 lnlen
= LineLength(lp
);
660 /* -------- insert block color change controls ------- */
661 if (TextBlockMarked(wnd
)) {
662 int bbl
= wnd
->BlkBegLine
;
663 int bel
= wnd
->BlkEndLine
;
664 int bbc
= wnd
->BlkBegCol
;
665 int bec
= wnd
->BlkEndCol
;
668 /* ----- put lowest marker first ----- */
673 if (bbl
== bel
&& bbc
> bec
)
676 if (by
>= bbl
&& by
<= bel
) {
677 /* ------ the block includes this line ----- */
680 if (!(by
> bbl
&& by
< bel
)) {
681 /* --- the entire line is not in the block -- */
683 /* ---- the block begins on this line --- */
686 /* ---- the block ends on this line ---- */
689 if (blkend
== 0 && lnlen
== 0) {
693 /* ----- insert the reset color token ----- */
694 memmove(lp
+blkend
+1,lp
+blkend
,strlen(lp
+blkend
)+1);
695 lp
[blkend
] = RESETCOLOR
;
696 /* ----- insert the change color token ----- */
697 memmove(lp
+blkbeg
+3,lp
+blkbeg
,strlen(lp
+blkbeg
)+1);
698 lp
[blkbeg
] = CHANGECOLOR
;
699 /* ----- insert the color tokens ----- */
700 SetReverseColor(wnd
);
701 lp
[blkbeg
+1] = foreground
| 0x80;
702 lp
[blkbeg
+2] = background
| 0x80;
706 /* - make sure left margin doesn't overlap color change - */
707 for (i
= 0; i
< wnd
->wleft
+3; i
++) {
710 if (*(unsigned char *)(lp
+ i
) == RESETCOLOR
)
713 if (*(lp
+i
) && i
< wnd
->wleft
+3) {
714 if (wnd
->wleft
+4 > lnlen
)
720 /* --- it does, shift the color change over --- */
721 for (i
= 0; i
< wnd
->wleft
; i
++) {
724 if (*(unsigned char *)(lp
+ i
) == CHANGECOLOR
) {
725 *(lp
+wnd
->wleft
+2) = *(lp
+i
+2);
726 *(lp
+wnd
->wleft
+1) = *(lp
+i
+1);
727 *(lp
+wnd
->wleft
) = *(lp
+i
);
732 /* ------ build the line to display -------- */
734 if (lnlen
< wnd
->wleft
)
738 if (lnlen
> RectLeft(rc
)) {
739 /* ---- the line exceeds the rectangle ---- */
740 int ct
= RectLeft(rc
);
742 /* --- point to end of clipped line --- */
744 if (*(unsigned char *)lp
== CHANGECOLOR
)
746 else if (*(unsigned char *)lp
== RESETCOLOR
)
754 if (*(unsigned char*)lpp
==CHANGECOLOR
)
756 if (*(unsigned char*)lpp
==RESETCOLOR
) {
758 while (lpp
>= initlp
) {
759 if (*(unsigned char *)lpp
==
772 lnlen
= LineLength(lp
);
773 len
= min(lnlen
, RectWidth(rc
));
774 dif
= strlen(lp
) - lnlen
;
777 strncpy(line
, lp
, len
);
780 /* -------- pad the line --------- */
781 while (len
< RectWidth(rc
)+dif
)
785 /* ------ establish the line's main color ----- */
788 SetReverseColor(wnd
);
789 while ((cp
= strchr(cp
, CHANGECOLOR
)) != NULL
) {
791 *cp
++ = background
| 0x80;
793 if (*(unsigned char *)line
== CHANGECOLOR
)
797 SetStandardColor(wnd
);
798 /* ------- display the line -------- */
799 writeline(wnd
, line
+dif
,
800 RectLeft(rc
)+BorderAdj(wnd
),
801 y
-wnd
->wtop
+TopBorderAdj(wnd
), FALSE
);
805 void MarkTextBlock(DFWINDOW wnd
, int BegLine
, int BegCol
,
806 int EndLine
, int EndCol
)
808 wnd
->BlkBegLine
= BegLine
;
809 wnd
->BlkEndLine
= EndLine
;
810 wnd
->BlkBegCol
= BegCol
;
811 wnd
->BlkEndCol
= EndCol
;
814 /* ----- clear and initialize text line pointer array ----- */
815 void ClearTextPointers(DFWINDOW wnd
)
817 wnd
->TextPointers
= DFrealloc(wnd
->TextPointers
, sizeof(int));
818 *(wnd
->TextPointers
) = 0;
821 #define INITLINES 100
823 /* ---- build array of pointers to text lines ---- */
824 void BuildTextPointers(DFWINDOW wnd
)
826 char *cp
= wnd
->text
, *cp1
;
827 int incrs
= INITLINES
;
829 wnd
->textwidth
= wnd
->wlines
= 0;
831 if (incrs
== INITLINES
) {
833 wnd
->TextPointers
= DFrealloc(wnd
->TextPointers
,
834 (wnd
->wlines
+ INITLINES
) * sizeof(int));
836 off
= (unsigned int) ((unsigned int)cp
- (unsigned int)wnd
->text
);
837 *((wnd
->TextPointers
) + wnd
->wlines
) = off
;
841 while (*cp
&& *cp
!= '\n')
843 wnd
->textwidth
= max(wnd
->textwidth
, (int)(cp
- cp1
));
849 static void MoveScrollBox(DFWINDOW wnd
, int vscrollbox
)
851 foreground
= FrameForeground(wnd
);
852 background
= FrameBackground(wnd
);
853 wputch(wnd
, SCROLLBARCHAR
, WindowWidth(wnd
)-1,
855 wputch(wnd
, SCROLLBOXCHAR
, WindowWidth(wnd
)-1,
857 wnd
->VScrollBox
= vscrollbox
;
860 int TextLineNumber(DFWINDOW wnd
, char *lp
)
864 for (lineno
= 0; lineno
< wnd
->wlines
; lineno
++) {
865 cp
= wnd
->text
+ *((wnd
->TextPointers
) + lineno
);