2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 /****************************************************************************************/
8 #include <exec/memory.h>
10 #include <intuition/intuition.h>
11 #include <intuition/imageclass.h>
12 #include <intuition/gadgetclass.h>
13 #include <libraries/locale.h>
14 #include <libraries/gadtools.h>
15 #include <devices/rawkeycodes.h>
17 #include <graphics/gfx.h>
18 #include <utility/hooks.h>
19 #include <workbench/startup.h>
21 #include <proto/exec.h>
22 #include <proto/dos.h>
23 #include <proto/intuition.h>
24 #include <proto/graphics.h>
25 #include <proto/gadtools.h>
26 #include <proto/alib.h>
31 #define CATCOMP_NUMBERS
40 #include <aros/debug.h>
42 /****************************************************************************************/
44 /* #define USE_WRITEMASK */
45 #define USE_SIMPLEREFRESH 0
47 #define DEFAULT_TABSIZE 8
49 #define INNER_SPACING_X 2
50 #define INNER_SPACING_Y 2
52 #define MAX_TEXTLINELEN 4096
54 #define ARG_TEMPLATE "FILE"
83 /****************************************************************************************/
93 /****************************************************************************************/
95 struct IntuitionBase
*IntuitionBase
;
96 struct GfxBase
*GfxBase
;
97 struct Library
*GadToolsBase
;
104 ULONG gotomask
, findmask
;
105 UBYTE filenamebuffer
[300];
107 /****************************************************************************************/
109 static struct RastPort
*rp
;
110 static struct RDArgs
*MyArgs
;
112 static struct Gadget
*gad
[NUM_GADGETS
], *firstgadget
, *activearrowgad
;
113 static struct Image
*img
[NUM_GADGETS
];
115 static struct LineNode
*linearray
;
117 static UBYTE
*filebuffer
;
119 static char *filename
, *fillename_dest
, s
[256], *searchtext
;
123 static UWORD tabsize
= DEFAULT_TABSIZE
;
125 static WORD fontwidth
, fontheight
, borderleft
, bordertop
;
126 static WORD shinepen
, shadowpen
, bgpen
, textpen
;
127 static WORD borderright
, borderbottom
, visiblex
, visibley
;
128 static WORD fontbaseline
, textstartx
, textstarty
, textendx
, textendy
;
129 static WORD textwidth
, textheight
, viewstartx
, viewstarty
;
130 static WORD winwidth
, winheight
;
132 static ULONG winmask
;
133 static LONG filelen
, num_lines
, max_textlen
;
134 static LONG search_startline
, found_line
= -1;
135 static WORD arrowticker
;
137 static BOOL in_main_loop
;
139 static IPTR Args
[NUM_ARGS
];
141 static BPTR oldlock
= (BPTR
)-1;
142 static BPTR parentlock
= (BPTR
)-1;
144 /*********************************************************************************************/
146 WORD
ShowMessage(CONST_STRPTR title
, CONST_STRPTR text
, CONST_STRPTR gadtext
)
148 struct EasyStruct es
;
150 es
.es_StructSize
= sizeof(es
);
153 es
.es_TextFormat
= text
;
154 es
.es_GadgetFormat
= gadtext
;
156 return EasyRequestArgs(win
, &es
, NULL
, NULL
);
159 /****************************************************************************************/
161 VOID
Cleanup(CONST_STRPTR msg
)
167 if (IntuitionBase
&& !((struct Process
*)FindTask(NULL
))->pr_CLI
)
169 ShowMessage("More", msg
, MSG(MSG_OK
));
171 printf("More: %s\n", msg
);
184 for(i
= 0; i
< NUM_GADGETS
;i
++)
186 if (gad
[i
]) RemoveGadget(win
, gad
[i
]);
192 for(i
= 0; i
< NUM_GADGETS
;i
++)
194 if (gad
[i
]) DisposeObject(gad
[i
]);
196 for(i
= 0; i
< NUM_IMAGES
;i
++)
198 if (img
[i
]) DisposeObject(img
[i
]);
201 if (vi
) FreeVisualInfo(vi
);
202 if (dri
) FreeScreenDrawInfo(scr
, dri
);
203 if (scr
) UnlockPubScreen(0, scr
);
205 if (linearray
) FreeVec(linearray
);
206 if (filebuffer
) FreeVec(filebuffer
);
210 if (oldlock
!= (BPTR
)-1) CurrentDir(oldlock
);
212 if (GadToolsBase
) CloseLibrary(GadToolsBase
);
213 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
214 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
216 if (MyArgs
) FreeArgs(MyArgs
);
222 /****************************************************************************************/
224 static void DosError(void)
226 Fault(IoErr(), 0, s
, 255);
229 ShowMessage("More", s
, MSG(MSG_OK
));
235 /****************************************************************************************/
237 static void GetArguments(int argc
, char **argv
)
241 if (!(MyArgs
= ReadArgs(ARG_TEMPLATE
, Args
, 0)))
246 filename
= (char *)Args
[ARG_FILE
];
250 struct WBStartup
*startup
= (struct WBStartup
*) argv
;
251 if (startup
->sm_NumArgs
> 1)
253 parentlock
= startup
->sm_ArgList
[1].wa_Lock
;
254 filename
= startup
->sm_ArgList
[1].wa_Name
;
255 if ((parentlock
== NULL
) || (filename
== NULL
))
258 oldlock
= CurrentDir(parentlock
);
262 if (!filename
) filename
= GetFile(TRUE
);
263 if (!filename
) Cleanup(NULL
);
265 strncpy(filenamebuffer
, filename
, 299);
269 /****************************************************************************************/
271 static void OpenLibs(void)
273 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
275 sprintf(s
, MSG(MSG_CANT_OPEN_LIB
), "intuition.library", 39);
279 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
281 sprintf(s
, MSG(MSG_CANT_OPEN_LIB
), "graphics.library", 39);
285 if (!(GadToolsBase
= OpenLibrary("gadtools.library", 39)))
287 sprintf(s
, MSG(MSG_CANT_OPEN_LIB
), "gadtools.library", 39);
292 /****************************************************************************************/
294 static UWORD
CalcTextLen(char *text
)
309 if (rc
> MAX_TEXTLINELEN
) rc
= MAX_TEXTLINELEN
;
314 /****************************************************************************************/
316 static BOOL
OpenFile(void)
318 struct LineNode
*new_linearray
;
319 UBYTE
*new_filebuffer
;
323 struct LineNode
*linepos
;
329 if (!(fh
= Open(filename
, MODE_OLDFILE
)))
335 if (Seek(fh
, 0, OFFSET_END
) >= 0) {
336 new_filelen
= Seek(fh
, 0, OFFSET_BEGINNING
);
340 new_filelen
= 0x10000;
351 if (!(new_filebuffer
= AllocVec(new_filelen
+ 1, MEMF_PUBLIC
)))
356 ShowMessage("More", MSG(MSG_NO_MEM
), MSG(MSG_OK
));
359 Cleanup(MSG(MSG_NO_MEM
));
362 if ((flen
=Read(fh
, new_filebuffer
, new_filelen
)) != new_filelen
&& seekable
)
364 FreeVec(new_filebuffer
);
371 new_filebuffer
[new_filelen
] = '\0';
375 filepos
= new_filebuffer
;
381 if (*filepos
++ == '\n') new_num_lines
++;
384 new_linearray
= AllocVec(new_num_lines
* sizeof(struct LineNode
), MEMF_PUBLIC
| MEMF_CLEAR
);
387 FreeVec(new_filebuffer
);
390 ShowMessage("More", MSG(MSG_NO_MEM
), MSG(MSG_OK
));
393 Cleanup(MSG(MSG_NO_MEM
));
396 linepos
= new_linearray
;
397 filepos
= new_filebuffer
;
401 while(act_line
<= new_num_lines
)
403 linepos
->text
= (char *)filepos
;
405 while ((*filepos
!= '\n') && (*filepos
!= '\0'))
407 linepos
->stringlen
++; filepos
++;
412 linepos
->textlen
= CalcTextLen(linepos
->text
);
413 if (linepos
->textlen
> max_textlen
) max_textlen
= linepos
->textlen
;
415 linepos
++; act_line
++;
418 if (filebuffer
) FreeVec(filebuffer
);
419 if (linearray
) FreeVec(linearray
);
421 filebuffer
= new_filebuffer
;
422 filelen
= new_filelen
;
423 linearray
= new_linearray
;
424 num_lines
= new_num_lines
;
429 /****************************************************************************************/
431 static void GetVisual(void)
433 if (!(scr
= LockPubScreen(0)))
435 Cleanup(MSG(MSG_CANT_LOCK_SCR
));
438 if (!(dri
= GetScreenDrawInfo(scr
)))
440 Cleanup(MSG(MSG_CANT_GET_DRI
));
443 if (!(vi
= GetVisualInfoA(scr
, 0)))
445 Cleanup(MSG(MSG_CANT_GET_VI
));
448 shinepen
= dri
->dri_Pens
[SHINEPEN
];
449 shadowpen
= dri
->dri_Pens
[SHADOWPEN
];
450 textpen
= dri
->dri_Pens
[TEXTPEN
];
451 bgpen
= dri
->dri_Pens
[BACKGROUNDPEN
];
454 /****************************************************************************************/
456 static void MakeGadgets(void)
458 static WORD img2which
[] =
467 IPTR imagew
[NUM_IMAGES
], imageh
[NUM_IMAGES
];
468 WORD v_offset
, h_offset
, btop
, i
;
470 for(i
= 0;i
< NUM_IMAGES
;i
++)
472 img
[i
] = NewObject(0, SYSICLASS
, SYSIA_DrawInfo
, (Tag
) dri
,
473 SYSIA_Which
, (Tag
) img2which
[i
],
476 if (!img
[i
]) Cleanup(MSG(MSG_CANT_CREATE_SYSIMAGE
));
478 GetAttr(IA_Width
, (Object
*)img
[i
], &imagew
[i
]);
479 GetAttr(IA_Height
, (Object
*)img
[i
], &imageh
[i
]);
482 btop
= scr
->WBorTop
+ dri
->dri_Font
->tf_YSize
+ 1;
484 v_offset
= imagew
[IMG_DOWNARROW
] / 4;
485 h_offset
= imageh
[IMG_LEFTARROW
] / 4;
488 gad
[GAD_UPARROW
] = NewObject(0, BUTTONGCLASS
, GA_Image
, (Tag
)img
[IMG_UPARROW
] ,
489 GA_RelRight
, -imagew
[IMG_UPARROW
] + 1 ,
490 GA_RelBottom
, -imageh
[IMG_DOWNARROW
] - imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] + 1 ,
491 GA_ID
, GAD_UPARROW
,
492 GA_RightBorder
, TRUE
,
493 GA_Immediate
, TRUE
,
494 GA_RelVerify
, TRUE
,
497 gad
[GAD_DOWNARROW
] = NewObject(0, BUTTONGCLASS
, GA_Image
, (Tag
)img
[IMG_DOWNARROW
] ,
498 GA_RelRight
, -imagew
[IMG_UPARROW
] + 1 ,
499 GA_RelBottom
, -imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] + 1 ,
500 GA_ID
, GAD_DOWNARROW
,
501 GA_RightBorder
, TRUE
,
502 GA_Previous
, (Tag
)gad
[GAD_UPARROW
] ,
503 GA_Immediate
, TRUE
,
504 GA_RelVerify
, TRUE
,
507 gad
[GAD_VERTSCROLL
] = NewObject(0, PROPGCLASS
, GA_Top
, btop
+ 1 ,
508 GA_RelRight
, -imagew
[IMG_DOWNARROW
] + v_offset
+ 1 ,
509 GA_Width
, imagew
[IMG_DOWNARROW
] - v_offset
* 2 ,
510 GA_RelHeight
, -imageh
[IMG_DOWNARROW
] - imageh
[IMG_UPARROW
] - imageh
[IMG_SIZE
] - btop
-2 ,
511 GA_ID
, GAD_VERTSCROLL
,
512 GA_Previous
, (Tag
)gad
[GAD_DOWNARROW
] ,
513 GA_RightBorder
, TRUE
,
514 GA_RelVerify
, TRUE
,
515 GA_Immediate
, TRUE
,
517 PGA_Borderless
, TRUE
,
520 PGA_Freedom
, FREEVERT
,
523 gad
[GAD_RIGHTARROW
] = NewObject(0, BUTTONGCLASS
, GA_Image
, (Tag
)img
[IMG_RIGHTARROW
] ,
524 GA_RelRight
, -imagew
[IMG_SIZE
] - imagew
[IMG_RIGHTARROW
] + 1,
525 GA_RelBottom
, -imageh
[IMG_RIGHTARROW
] + 1 ,
526 GA_ID
, GAD_RIGHTARROW
,
527 GA_BottomBorder
, TRUE
,
528 GA_Previous
, (Tag
)gad
[GAD_VERTSCROLL
] ,
529 GA_Immediate
, TRUE
,
530 GA_RelVerify
, TRUE
,
533 gad
[GAD_LEFTARROW
] = NewObject(0, BUTTONGCLASS
, GA_Image
, (Tag
)img
[IMG_LEFTARROW
] ,
534 GA_RelRight
, -imagew
[IMG_SIZE
] - imagew
[IMG_RIGHTARROW
] - imagew
[IMG_LEFTARROW
] + 1,
535 GA_RelBottom
, -imageh
[IMG_RIGHTARROW
] + 1 ,
536 GA_ID
, GAD_LEFTARROW
,
537 GA_BottomBorder
, TRUE
,
538 GA_Previous
, (Tag
)gad
[GAD_RIGHTARROW
] ,
539 GA_Immediate
, TRUE
,
540 GA_RelVerify
, TRUE
,
543 gad
[GAD_HORIZSCROLL
] = NewObject(0, PROPGCLASS
, GA_Left
, scr
->WBorLeft
,
544 GA_RelBottom
, -imageh
[IMG_LEFTARROW
] + h_offset
+ 1 ,
545 GA_RelWidth
, -imagew
[IMG_LEFTARROW
] - imagew
[IMG_RIGHTARROW
] - imagew
[IMG_SIZE
] - scr
->WBorRight
- 2,
546 GA_Height
, imageh
[IMG_LEFTARROW
] - (h_offset
* 2) ,
547 GA_ID
, GAD_HORIZSCROLL
,
548 GA_Previous
, (Tag
)gad
[GAD_LEFTARROW
] ,
549 GA_BottomBorder
, TRUE
,
550 GA_RelVerify
, TRUE
,
551 GA_Immediate
, TRUE
,
553 PGA_Borderless
, TRUE
,
556 PGA_Freedom
, FREEHORIZ
,
559 for(i
= 0;i
< NUM_GADGETS
;i
++)
561 if (!gad
[i
]) Cleanup(MSG(MSG_CANT_CREATE_GADGET
));
565 /****************************************************************************************/
567 static void CalcVisible(void)
569 visiblex
= (win
->Width
- borderleft
- borderright
-
570 INNER_SPACING_X
* 2) / fontwidth
;
572 visibley
= (win
->Height
- bordertop
- borderbottom
-
573 INNER_SPACING_Y
* 2) / fontheight
;
575 if (visiblex
< 1) visiblex
= 1;
576 if (visibley
< 1) visibley
= 1;
578 textendx
= textstartx
+ visiblex
* fontwidth
- 1;
579 textendy
= textstarty
+ visibley
* fontheight
- 1;
581 textwidth
= textendx
- textstartx
+ 1;
582 textheight
= textendy
- textstarty
+ 1;
585 /****************************************************************************************/
587 static void MySetAPen(struct RastPort
*rp
, LONG reg
)
589 static LONG oldreg
= -1;
598 /****************************************************************************************/
600 static void MySetBPen(struct RastPort
*rp
, LONG reg
)
602 static LONG oldreg
= -1;
611 /****************************************************************************************/
613 static void DrawTextLine(WORD viewline
, WORD columns
, BOOL clearright
)
615 static char tempstring
[MAX_TEXTLINELEN
+ 1];
616 static char c
, *stringpos
, *text
;
617 LONG realline
= viewline
+ viewstarty
;
618 WORD textlen
, i
= 0, t
, x
;
621 /* column < 0 means draw only first -column chars
623 ** column > 0 means draw only last column chars
625 ** column = 0 means draw whole line
630 clearright
= FALSE
; /* because already cleared by ScrollRaster */
633 if ((viewline
>= 0) && (viewline
< visibley
) &&
634 (realline
>= 0) && (realline
< num_lines
))
636 inverted
= linearray
[realline
].invert
;
638 text
= linearray
[realline
].text
;
639 textlen
= linearray
[realline
].textlen
;
641 stringpos
= tempstring
;
643 while((c
= *text
++) && (i
< textlen
))
647 for(t
= 0; (t
< tabsize
) && (i
< textlen
);t
++)
656 } /* while((c = *text++) && (i < textlen)) */
658 stringpos
= tempstring
+ viewstartx
;
665 if (i
> visiblex
) i
= visiblex
;
670 if (i
> (-columns
)) i
= (-columns
);
671 } else if (columns
> 0) {
672 x
= textstartx
+ (visiblex
- columns
) * fontwidth
;
673 stringpos
+= (visiblex
- columns
);
674 i
-= (visiblex
- columns
);
679 MySetAPen(rp
, textpen
);
680 MySetBPen(rp
, inverted
? shinepen
: bgpen
);
683 textstarty
+ (viewline
* fontheight
) + fontbaseline
);
685 Text(rp
, stringpos
, i
);
689 } /* if ((realline >= 0) && (realline < num_lines)) */
691 if ((i
< visiblex
) && clearright
)
693 MySetAPen(rp
, bgpen
);
694 RectFill(rp
, textstartx
+ (i
* fontwidth
),
695 textstarty
+ (viewline
* fontheight
),
697 textstarty
+ (viewline
* fontheight
) + fontheight
- 1);
701 /****************************************************************************************/
703 static void DrawAllText(void)
707 for(y
= 0;y
< visibley
;y
++)
709 DrawTextLine(y
, 0, TRUE
);
713 /****************************************************************************************/
715 static void SetWinTitle(void)
717 static UBYTE wintitle
[256];
721 if ((lock
= Lock(filename
, SHARED_LOCK
)))
723 NameFromLock(lock
, s
, 255);
726 sprintf(wintitle
, MSG(MSG_WIN_TITLE
), s
, num_lines
, filelen
);
728 SetWindowTitles(win
, wintitle
, (UBYTE
*)~0L);
731 /****************************************************************************************/
733 static void MakeWin(void)
735 if (!(win
= OpenWindowTags(NULL
, WA_PubScreen
, (IPTR
)scr
,
737 WA_Top
, scr
->BarHeight
+ 1 ,
740 WA_AutoAdjust
, TRUE
,
744 WA_CloseGadget
, TRUE
,
745 WA_DepthGadget
, TRUE
,
747 WA_SizeGadget
, TRUE
,
748 WA_SizeBBottom
, TRUE
,
749 WA_SizeBRight
, TRUE
,
751 WA_Gadgets
, (IPTR
)firstgadget
,
754 WA_MaxWidth
, scr
->Width
,
755 WA_MaxHeight
, scr
->Height
,
756 WA_ReportMouse
, TRUE
,
757 WA_NewLookMenus
, TRUE
,
758 WA_IDCMP
, IDCMP_CLOSEWINDOW
|
765 (USE_SIMPLEREFRESH
!= 0) * IDCMP_REFRESHWINDOW
|
770 Cleanup(MSG(MSG_CANT_CREATE_WIN
));
775 winmask
= 1L << win
->UserPort
->mp_SigBit
;
777 winwidth
= win
->Width
;
778 winheight
= win
->Height
;
785 SetWriteMask(rp
, 0x3);
788 fontwidth
= rp
->TxWidth
;
789 fontheight
= rp
->TxHeight
;
790 fontbaseline
= rp
->TxBaseline
;
792 borderleft
= win
->BorderLeft
;
793 bordertop
= win
->BorderTop
;
794 borderright
= win
->BorderRight
;
795 borderbottom
= win
->BorderBottom
;
797 textstartx
= borderleft
+ INNER_SPACING_X
;
798 textstarty
= bordertop
+ INNER_SPACING_Y
;
802 SetGadgetAttrs(gad
[GAD_HORIZSCROLL
], win
, 0, PGA_Top
, 0 ,
803 PGA_Total
, max_textlen
,
804 PGA_Visible
, visiblex
,
807 SetGadgetAttrs(gad
[GAD_VERTSCROLL
], win
, 0, PGA_Top
, 0 ,
808 PGA_Total
, num_lines
,
809 PGA_Visible
, visibley
,
814 SetMenuStrip(win
, menus
);
817 /****************************************************************************************/
819 static void NewWinSize(void)
821 WORD new_winwidth
, new_winheight
;
823 new_winwidth
= win
->Width
;
824 new_winheight
= win
->Height
;
828 if ((viewstartx
+ visiblex
) > max_textlen
)
830 viewstartx
= max_textlen
- visiblex
;
831 if (viewstartx
< 0) viewstartx
= 0;
834 if ((viewstarty
+ visibley
) > num_lines
)
836 viewstarty
= num_lines
- visibley
;
837 if (viewstarty
< 0) viewstarty
= 0;
840 SetGadgetAttrs(gad
[GAD_HORIZSCROLL
], win
, 0, PGA_Top
, viewstartx
,
841 PGA_Visible
, visiblex
,
844 SetGadgetAttrs(gad
[GAD_VERTSCROLL
], win
, 0, PGA_Top
, viewstarty
,
845 PGA_Visible
, visibley
,
848 if (new_winwidth
< winwidth
)
850 MySetAPen(rp
, bgpen
);
851 RectFill(rp
, textendx
+ 1,
852 bordertop
+ INNER_SPACING_Y
,
853 new_winwidth
- borderright
- 1,
854 new_winheight
- borderbottom
- 1);
857 if (new_winheight
< winheight
)
859 MySetAPen(rp
, bgpen
);
860 RectFill(rp
, borderleft
+ INNER_SPACING_X
,
862 new_winwidth
- borderright
- 1,
863 new_winheight
- borderbottom
- 1);
866 if ((new_winwidth
> winwidth
) ||
867 (new_winheight
> winheight
))
872 winwidth
= new_winwidth
;
873 winheight
= new_winheight
;
876 /****************************************************************************************/
878 #ifdef USE_SIMPLEREFRESH
880 /****************************************************************************************/
882 static void RefreshAll(void)
887 /****************************************************************************************/
889 static void HandleRefresh(void)
893 EndRefresh(win
, TRUE
);
896 /****************************************************************************************/
898 #endif /* USE_SIMPLEREFRESH */
900 /****************************************************************************************/
902 static void ScrollTo(WORD gadid
, LONG top
, BOOL refreshprop
)
906 MySetBPen(rp
, bgpen
);
911 if (top
+ visibley
> num_lines
)
913 top
= num_lines
- visibley
;
915 if (top
< 0) top
= 0;
917 if (top
!= viewstarty
)
919 dy
= top
- viewstarty
;
924 SetGadgetAttrs(gad
[gadid
], win
, 0, PGA_Top
, viewstarty
,
928 if (abs(dy
) >= visibley
)
935 #ifdef USE_SIMPLEREFRESH
944 if (rp
->Layer
->Flags
& LAYERREFRESH
)
949 ClipBlit(rp
, textstartx
,
950 textstarty
+ dy
* fontheight
,
954 textheight
- dy
* fontheight
,
958 for (y
= visibley
- dy
;y
< visibley
;y
++)
960 DrawTextLine(y
, 0, TRUE
);
965 #ifdef USE_SIMPLEREFRESH
974 if (rp
->Layer
->Flags
& LAYERREFRESH
)
980 ClipBlit(rp
, textstartx
,
983 textstarty
+ dy
* fontheight
,
985 textheight
- dy
* fontheight
,
988 for (y
= 0;y
< dy
;y
++)
990 DrawTextLine(y
, 0, TRUE
);
995 } /* if (top != viewstarty ) */
998 case GAD_HORIZSCROLL
:
999 if (top
+ visiblex
> max_textlen
)
1001 top
= max_textlen
- visiblex
;
1003 if (top
< 0) top
= 0;
1005 if (top
!= viewstartx
)
1007 dx
= top
- viewstartx
;
1012 SetGadgetAttrs(gad
[gadid
], win
, 0, PGA_Top
, viewstartx
,
1016 if (abs(dx
) >= visiblex
)
1023 #ifdef USE_SIMPLEREFRESH
1032 if (rp
->Layer
->Flags
& LAYERREFRESH
)
1037 ClipBlit(rp
, textstartx
+ dx
* fontwidth
,
1041 textwidth
- dx
* fontwidth
,
1045 for (y
= 0;y
< visibley
;y
++)
1047 DrawTextLine(y
, dx
, TRUE
);
1053 #ifdef USE_SIMPLEREFRESH
1062 if (rp
->Layer
->Flags
& LAYERREFRESH
)
1068 ClipBlit(rp
, textstartx
,
1070 rp
, textstartx
+ dx
* fontwidth
,
1072 textwidth
- dx
* fontwidth
,
1076 for (y
= 0;y
< visibley
;y
++)
1078 DrawTextLine(y
, -dx
, TRUE
);
1083 } /* if (top != viewstartx ) */
1086 } /* switch(gadid) */
1090 /****************************************************************************************/
1092 static void HandleScrollGadget(WORD gadid
)
1094 struct IntuiMessage
*msg
;
1100 WaitPort(win
->UserPort
);
1101 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
1105 case IDCMP_GADGETUP
:
1109 case IDCMP_MOUSEMOVE
:
1110 GetAttr(PGA_Top
, (Object
*)gad
[gadid
], &top
);
1111 ScrollTo(gadid
, top
, FALSE
);
1114 #ifdef USE_SIMPLEREFRESH
1115 case IDCMP_REFRESHWINDOW
:
1120 } /* switch (msg->Class) */
1121 ReplyMsg((struct Message
*)msg
);
1123 } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
1128 /****************************************************************************************/
1130 static BOOL
FindString(struct LineNode
*ln
, char *search
, LONG searchlen
)
1132 char *text
= ln
->text
;
1133 LONG textlen
= ln
->stringlen
;
1137 textlen
-= searchlen
;
1141 for(i
= 0;i
< searchlen
;i
++)
1143 if (toupper(text
[i
]) != toupper(search
[i
])) break;
1157 /****************************************************************************************/
1159 static void DoSearch(WORD kind
)
1161 LONG line
, searchlen
;
1164 if (!searchtext
) return;
1166 searchlen
= strlen(searchtext
);
1167 if (searchlen
== 0) return;
1169 if (kind
== SEARCH_NEW
)
1171 search_startline
= 0;
1175 line
= search_startline
;
1179 if (FindString(&linearray
[line
], searchtext
, searchlen
))
1182 if (found_line
>= 0)
1184 linearray
[found_line
].invert
= FALSE
;
1185 DrawTextLine(found_line
- viewstarty
, 0, TRUE
);
1188 ScrollTo(GAD_VERTSCROLL
, line
- visibley
/ 2, TRUE
);
1191 linearray
[found_line
].invert
= TRUE
;
1192 DrawTextLine(found_line
- viewstarty
, 0, TRUE
);
1195 if (kind
== SEARCH_NEXT
)
1198 if (line
< num_lines
)
1200 search_startline
= line
;
1209 search_startline
= line
;
1216 } /* while(!done) */
1220 /****************************************************************************************/
1222 static BOOL
HandleWin(void)
1224 struct IntuiMessage
*msg
;
1225 struct MenuItem
*item
;
1229 BOOL pagescroll
, maxscroll
, quitme
= FALSE
;
1231 while ((msg
= (struct IntuiMessage
*)GetMsg(win
->UserPort
)))
1235 case IDCMP_CLOSEWINDOW
:
1243 #ifdef USE_SIMPLEREFRESH
1244 case IDCMP_REFRESHWINDOW
:
1248 case IDCMP_GADGETDOWN
:
1249 gadid
= ((struct Gadget
*)msg
->IAddress
)->GadgetID
;
1254 case GAD_HORIZSCROLL
:
1255 case GAD_VERTSCROLL
:
1256 HandleScrollGadget(gadid
);
1260 activearrowgad
= (struct Gadget
*)msg
->IAddress
;
1261 ScrollTo(GAD_VERTSCROLL
, viewstarty
- 1, TRUE
);
1265 activearrowgad
= (struct Gadget
*)msg
->IAddress
;
1266 ScrollTo(GAD_VERTSCROLL
, viewstarty
+ 1, TRUE
);
1270 activearrowgad
= (struct Gadget
*)msg
->IAddress
;
1271 ScrollTo(GAD_HORIZSCROLL
, viewstartx
- 1, TRUE
);
1274 case GAD_RIGHTARROW
:
1275 activearrowgad
= (struct Gadget
*)msg
->IAddress
;
1276 ScrollTo(GAD_HORIZSCROLL
, viewstartx
+ 1, TRUE
);
1281 case IDCMP_INTUITICKS
:
1288 else if (activearrowgad
->Flags
& GFLG_SELECTED
)
1290 switch(activearrowgad
->GadgetID
)
1293 ScrollTo(GAD_VERTSCROLL
, viewstarty
- 1, TRUE
);
1297 ScrollTo(GAD_VERTSCROLL
, viewstarty
+ 1, TRUE
);
1301 ScrollTo(GAD_HORIZSCROLL
, viewstartx
- 1, TRUE
);
1304 case GAD_RIGHTARROW
:
1305 ScrollTo(GAD_HORIZSCROLL
, viewstartx
+ 1, TRUE
);
1312 case IDCMP_GADGETUP
:
1313 activearrowgad
= NULL
;
1316 case IDCMP_VANILLAKEY
:
1317 key
= toupper(msg
->Code
);
1322 else if (key
== ' ')
1324 ScrollTo(GAD_VERTSCROLL
, viewstarty
+ visibley
- 1, TRUE
);
1328 ScrollTo(GAD_VERTSCROLL
, viewstarty
- (visibley
- 1), TRUE
);
1332 ScrollTo(GAD_VERTSCROLL
, viewstarty
+ 1, TRUE
);
1334 else if (strchr(MSG(MSG_SHORTCUT_TOP
), key
))
1336 ScrollTo(GAD_VERTSCROLL
, 0, TRUE
);
1338 else if (strchr(MSG(MSG_SHORTCUT_BOTTOM
), key
))
1340 ScrollTo(GAD_VERTSCROLL
, num_lines
, TRUE
);
1342 else if (strchr(MSG(MSG_SHORTCUT_JUMP
), key
))
1344 Make_Goto_Requester();
1346 else if (strchr(MSG(MSG_SHORTCUT_FIND
), key
))
1348 Make_Find_Requester();
1350 else if (strchr(MSG(MSG_SHORTCUT_NEXT
), key
))
1352 DoSearch(SEARCH_NEXT
);
1354 else if (strchr(MSG(MSG_SHORTCUT_NEXT
), key
))
1356 DoSearch(SEARCH_PREV
);
1361 pagescroll
= (0 != (msg
->Qualifier
& (IEQUALIFIER_LSHIFT
| IEQUALIFIER_RSHIFT
)));
1362 maxscroll
= (0 != (msg
->Qualifier
& (IEQUALIFIER_LALT
| IEQUALIFIER_RALT
| IEQUALIFIER_CONTROL
)));
1364 code
= msg
->Code
; delta
= 1;
1368 case RAWKEY_NM_WHEEL_UP
:
1373 case RAWKEY_NM_WHEEL_DOWN
:
1378 case RAWKEY_NM_WHEEL_LEFT
:
1383 case RAWKEY_NM_WHEEL_RIGHT
:
1392 ScrollTo(GAD_VERTSCROLL
,
1393 maxscroll
? 0 : viewstarty
- (pagescroll
? visibley
- 1 : delta
),
1398 ScrollTo(GAD_VERTSCROLL
,
1399 maxscroll
? num_lines
: viewstarty
+ (pagescroll
? visibley
- 1 : delta
),
1404 ScrollTo(GAD_HORIZSCROLL
,
1405 maxscroll
? 0 : viewstartx
- (pagescroll
? visiblex
- 1 : delta
),
1410 ScrollTo(GAD_HORIZSCROLL
,
1411 maxscroll
? max_textlen
: viewstartx
+ (pagescroll
? visiblex
- 1 : delta
),
1416 ScrollTo(GAD_VERTSCROLL
, 0, TRUE
);
1420 ScrollTo(GAD_VERTSCROLL
, num_lines
, TRUE
);
1424 ScrollTo(GAD_VERTSCROLL
, viewstarty
- (visibley
- 1), TRUE
);
1427 case RAWKEY_PAGEDOWN
:
1428 ScrollTo(GAD_VERTSCROLL
, viewstarty
+ (visibley
- 1), TRUE
);
1431 } /* switch(msg->Code) */
1434 case IDCMP_MENUPICK
:
1436 while(men
!= MENUNULL
)
1438 if ((item
= ItemAddress(menus
, men
)))
1440 switch((ULONG
)GTMENUITEM_USERDATA(item
))
1442 case MSG_MEN_PROJECT_SAVEAS
:
1443 fillename_dest
= GetFile(FALSE
);
1444 if (!fillename_dest
)
1447 case MSG_MEN_PROJECT_PRINT
:
1448 sprintf(s
, "Run >NIL: Type \"%s\" TO \"%s\"", filenamebuffer
, fillename_dest
? fillename_dest
: "PRT:");
1449 if (System(s
, TAG_END
))
1451 fillename_dest
= NULL
;
1454 case MSG_MEN_PROJECT_ABOUT
:
1458 case MSG_MEN_PROJECT_QUIT
:
1462 case MSG_MEN_PROJECT_OPEN
:
1463 if ((filename
= GetFile(TRUE
)))
1467 strncpy(filenamebuffer
, filename
, 299);
1469 MySetAPen(rp
, bgpen
);
1470 RectFill(rp
, textstartx
, textstarty
, textendx
, textendy
);
1474 viewstartx
= viewstarty
= 0;
1476 SetGadgetAttrs(gad
[GAD_HORIZSCROLL
], win
, 0, PGA_Top
, viewstartx
,
1477 PGA_Visible
, visiblex
,
1478 PGA_Total
, max_textlen
,
1481 SetGadgetAttrs(gad
[GAD_VERTSCROLL
], win
, 0, PGA_Top
, viewstarty
,
1482 PGA_Visible
, visibley
,
1483 PGA_Total
, num_lines
,
1487 } /* if (OpenFile()) */
1489 } /* if ((filename = GetFile())) */
1493 case MSG_MEN_NAVIGATION_FIND
:
1494 Make_Find_Requester();
1497 case MSG_MEN_NAVIGATION_FIND_NEXT
:
1498 DoSearch(SEARCH_NEXT
);
1501 case MSG_MEN_NAVIGATION_FIND_PREV
:
1502 DoSearch(SEARCH_PREV
);
1505 case MSG_MEN_NAVIGATION_JUMP
:
1506 Make_Goto_Requester();
1509 } /* switch(GTMENUITEM_USERDATA(item)) */
1511 men
= item
->NextSelect
;
1516 } /* while(men != MENUNULL) */
1519 } /* switch(msg->Class) */
1521 ReplyMsg((struct Message
*)msg
);
1523 } /* while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort))) */
1528 /****************************************************************************************/
1530 static void HandleAll(void)
1535 BOOL quitme
= FALSE
;
1537 in_main_loop
= TRUE
;
1539 ScreenToFront(win
->WScreen
);
1543 sigs
= Wait(winmask
| gotomask
| findmask
);
1545 if (sigs
& winmask
) quitme
= HandleWin();
1547 if (sigs
& gotomask
)
1549 if (Handle_Goto_Requester(&line
))
1551 ScrollTo(GAD_VERTSCROLL
, line
- 1, TRUE
);
1555 if (sigs
& findmask
)
1557 if ((search_kind
= Handle_Find_Requester(&searchtext
)))
1559 DoSearch(search_kind
);
1563 } /* while(!quitme) */
1566 /****************************************************************************************/
1568 int main(int argc
, char **argv
)
1570 InitLocale("System/Utilities/More.catalog", 1);
1572 GetArguments(argc
, argv
);
1584 /****************************************************************************************/