Moved DejaVue fonts to contrib. They are only needed by applications
[AROS-Contrib.git] / dopus / Program / main16.c
blob59d27063549ab9ef22d2be055d54bbbb2e030b08
1 /*
3 Directory Opus 4
4 Original GPL release version 4.12
5 Copyright 1993-2000 Jonathan Potter
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 All users of Directory Opus 4 (including versions distributed
22 under the GPL) are entitled to upgrade to the latest version of
23 Directory Opus version 5 at a reduced price. Please see
24 http://www.gpsoft.com.au for more information.
26 The release of Directory Opus 4 under the GPL in NO WAY affects
27 the existing commercial status of Directory Opus 5.
31 #include "dopus.h"
32 #include <libraries/amigaguide.h>
33 //#include <proto/powerpacker.h>
35 int showfont(name,size,np)
36 char *name;
37 int size,np;
39 int base,y,fred,t,len;
40 unsigned char a;
41 struct TextFont *font;
42 char fontbuf[256],*fontptr;
43 static UWORD fcols[2]={0xfff,0};
44 struct TextAttr sfattr = { (STRPTR)name, size, 0, 0 };
45 struct RastPort *font_rp;
47 font = DiskfontBase ? OpenDiskFont(&sfattr) : OpenFont(&sfattr);
48 if (!font || !(setupfontdisplay(1,NULL))) {
49 doerror(-1);
50 return(0);
53 base=font->tf_Baseline;
54 SetFont(font_rp=fontwindow->RPort,font);
55 SetAPen(font_rp,1);
56 SetDrMd(font_rp,JAM1);
58 y=base;
59 a=font->tf_LoChar;
60 len=t=0;
62 Move(font_rp,0,y);
63 fontptr=fontbuf;
65 FOREVER {
66 len+=TextLength(font_rp,(char *)&a,1);
67 if (len>fontscreen->Width || t>254) {
68 Text(font_rp,fontbuf,t);
69 y+=size;
70 Move(font_rp,0,y);
71 len=t=0; fontptr=fontbuf;
72 if (y-base>fontscreen->Height) break;
74 *(fontptr++)=a; ++t;
75 if ((++a)>font->tf_HiChar) a=font->tf_LoChar;
78 ScreenToFront(fontscreen);
79 ActivateWindow(fontwindow);
80 FadeRGB4(fontscreen,fcols,2,1,config->fadetime);
81 show_global_font=font;
83 fred=WaitForMouseClick(0,fontwindow);
85 show_global_font=NULL;
86 if (fred!=-3) FadeRGB4(fontscreen,fcols,2,-1,config->fadetime);
88 cleanup_fontdisplay();
89 CloseFont(font);
91 return((fred==0)?1:-1);
94 int setupfontdisplay(depth,coltab)
95 int depth;
96 UWORD *coltab;
98 struct DimensionInfo dims;
99 struct RastPort *font_rp;
101 font_scr.Width=GfxBase->NormalDisplayColumns;
102 font_scr.Height=STDSCREENHEIGHT;
103 font_scr.Depth=depth;
104 // if (system_version2 >= OSVER_39)
106 font_scr.Extension[0].ti_Data = BestModeID(BIDTAG_DesiredWidth, font_scr.Width,
107 BIDTAG_DesiredHeight, font_scr.Height,
108 BIDTAG_Depth, font_scr.Depth,
109 BIDTAG_MonitorID, GetVPModeID(&Window->WScreen->ViewPort) & MONITOR_ID_MASK,
110 TAG_END);
111 D(bug("Font screen ModeID: %lx\n",font_scr.Extension[0].ti_Data));
112 if (font_scr.Extension[0].ti_Data == INVALID_ID) font_scr.Extension[0].ti_Data = HIRES_KEY;
113 if (GetDisplayInfoData(NULL,(UBYTE *)&dims,sizeof(struct DimensionInfo),DTAG_DIMS,font_scr.Extension[0].ti_Data))
115 font_scr.Width = dims.Nominal.MaxX-dims.Nominal.MinX+1;
116 font_scr.Height = dims.Nominal.MaxY-dims.Nominal.MinY+1;
119 if (!(fontscreen=OpenScreen((struct NewScreen *)&font_scr))) return(0);
120 font_win.Width=fontscreen->Width;
121 font_win.Height=fontscreen->Height;
122 font_win.Screen=fontscreen;
123 if (!(fontwindow=OpenWindow(&font_win))) {
124 CloseScreen(fontscreen);
125 return(0);
127 font_rp=fontwindow->RPort;
128 if (coltab) {
129 int a,num;
131 num=1<<depth;
132 // if (num>16) num=16;
133 for (a=0;a<num;a++) coltab[a]=GetRGB4(fontscreen->ViewPort.ColorMap,a);
135 LoadRGB4(&fontscreen->ViewPort,nullpalette,1<<depth);
136 setnullpointer(fontwindow);
137 return(1);
140 void cleanup_fontdisplay()
142 ScreenToFront(blankscreen ? blankscreen : Window->WScreen);
143 if (fontwindow) {
144 CloseWindow(fontwindow);
145 fontwindow=NULL;
147 if (fontscreen) {
148 CloseScreen(fontscreen);
149 fontscreen=NULL;
151 ActivateWindow(Window);
154 void readhelp(file)
155 char *file;
157 //D(bug("readhelp(%s)\n",file);Delay(50));
158 if (file) doreadhelp(file);
159 if (dopus_firsthelp) screen_gadgets[SCRGAD_TINYHELP].Flags&=~GFLG_DISABLED;
160 else screen_gadgets[SCRGAD_TINYHELP].Flags|=GFLG_DISABLED;
161 if (Window && config->generalscreenflags&SCR_GENERAL_TINYGADS)
162 dolittlegads(&screen_gadgets[SCRGAD_TINYHELP],&globstring[STR_TINY_BUTTONS][4],1);
165 void doreadhelp(file)
166 char *file;
168 int a,b,helpsize,inmsg;
169 char *helpbuf,*buf;
170 struct Help *temph,*curhelp;
172 //D(bug("doreadhelp(%s)\n",file);Delay(50));
173 freehelp();
174 if (!file[0] || !(buf=AllocMem(10000,MEMF_CLEAR))) return;
175 if (readfile(file,&helpbuf,&helpsize)) {
176 FreeMem(buf,10000);
177 return;
180 curhelp=NULL;
181 inmsg=0;
182 for (a=0;a<helpsize;a++) {
183 if (helpbuf[a]=='*' && !inmsg) {
184 inmsg=1; b=0;
185 continue;
187 else {
188 if (inmsg==1) {
189 if (b==9999 || helpbuf[a]=='\n') {
190 buf[b]=0;
191 if (!(temph=LAllocRemember(&help_key,sizeof(struct Help),MEMF_CLEAR))) break;
192 if (!(temph->lookup=LAllocRemember(&help_key,b+1,MEMF_CLEAR))) break;
193 CopyMem(buf,temph->lookup,b);
194 if (curhelp) curhelp->next=temph;
195 else dopus_firsthelp=temph;
196 curhelp=temph;
197 inmsg=2; b=0;
198 continue;
200 buf[b]=helpbuf[a];
201 ++b;
202 continue;
204 else if (inmsg==2) {
205 if (b==9999 || helpbuf[a]=='^') {
206 if (curhelp) {
207 buf[b]=0;
208 if (!(curhelp->message=LAllocRemember(&help_key,b+1,MEMF_CLEAR))) break;
209 CopyMem(buf,curhelp->message,b);
211 inmsg=0; b=0;
212 continue;
214 buf[b]=helpbuf[a];
215 ++b;
216 continue;
220 FreeMem(buf,10000);
221 FreeVec(helpbuf);
224 static STRPTR helpcontext[] = {
225 "Main",
226 "About",
227 "AddCustEntry",
228 "AddCustHandler",
229 "AddFile",
230 "AddIcon",
231 "Alarm",
232 "All",
233 "AnsiRead",
234 "ARexx",
235 "Assign",
236 "Beep",
237 "BufferList",
238 "Busy",
239 "ButtonIconify",
240 "CD",
241 "CheckAbort",
242 "CheckFit",
243 "ClearBuffers",
244 "ClearSizes",
245 "ClearWin",
246 "Clone",
247 "Comment",
248 "Configure",
249 "ContST",
250 "Copy",
251 "CopyAs",
252 "CopyWindow",
253 "DateStamp",
254 "Defaults",
255 "Delete",
256 "DirTree",
257 "DiskCopy",
258 "DiskCopyBG",
259 "DiskInfo",
260 "DisplayDir",
261 "DOpusToBack",
262 "DOpusToFront",
263 "Encrypt",
264 "ErrorHelp",
265 "Execute",
266 "FileInfo",
267 "FinishSection",
268 "Format",
269 "FormatBG",
270 "GetAll",
271 "GetDevices",
272 "GetDirs",
273 "GetEntry",
274 "GetFileType",
275 "GetFiles",
276 "GetNextSelected",
277 "GetSelectedAll",
278 "GetSelectedDirs",
279 "GetSelectedFiles",
280 "GetSizes",
281 "GetString",
282 "HexRead",
283 "Hunt",
284 "Iconify",
285 "IconInfo",
286 "Install",
287 "InstallBG",
288 "LastSaved",
289 "LoadConfig",
290 "LoopPlay",
291 "MakeDir",
292 "Modify",
293 "Move",
294 "MoveAs",
295 "NewCLI",
296 "NextDrives",
297 "None",
298 "notify",
299 "OtherWindow",
300 "Parent",
301 "ParentList",
302 "PatternMatch",
303 "Play",
304 "PlayST",
305 "Print",
306 "PrintDir",
307 "Protect",
308 "Query",
309 "Quit",
310 "Read",
311 "Redraw",
312 "Relabel",
313 "Remember",
314 "RemoveEntry",
315 "RemoveFile",
316 "Rename",
317 "Request",
318 "Rescan",
319 "Reselect",
320 "Restore",
321 "Root",
322 "Run",
323 "SaveConfig",
324 "ScanDir",
325 "ScrollH",
326 "ScrollToShow",
327 "ScrollV",
328 "Search",
329 "Select",
330 "SelectEntry",
331 "SelectFile",
332 "SetVar",
333 "SetWinTitle",
334 "Show",
335 "SmartRead",
336 "Status",
337 "StopST",
338 "SwapWindow",
339 "Toggle",
340 "TopText",
341 "Uniconify",
342 "User1",
343 "Verify",
344 "Version",
345 NULL };
347 char *getAGnode(char *buf,char *func)
349 int i;
351 for (i = 0; func[i] && func[i] != ' '; i++) buf[i] = func[i];
352 buf[i] = 0;
354 for(i = 0; helpcontext[i]; i++) if (stricmp(buf,helpcontext[i])==0) break;
356 if (helpcontext[i] == NULL) strcpy(buf,"Main");
358 return buf;
361 void dohelp(name,func,key,qual,defmsg)
362 char *name,*func;
363 int key,qual;
364 char *defmsg;
366 if (dopus_firsthelp)
368 char *msg=NULL,*buf=NULL,buf1[40],buf2[30];
369 struct Help *help=dopus_firsthelp;
370 int s,s1;
372 while (help) {
373 if (help->lookup) {
374 if (help->lookup[0]=='*' && func) {
375 if (Stricmp(help->lookup,func)==0) {
376 msg=help->message;
377 break;
380 else if (name) {
381 if (Stricmp(help->lookup,name)==0) {
382 msg=help->message;
383 break;
387 help=help->next;
389 if (!msg) msg = (defmsg ? defmsg : globstring[STR_HELP_NOT_AVAILABLE]);
391 if (key>0) {
392 RawkeyToStr(key,qual,buf2,NULL,30);
393 strcpy(buf1,globstring[STR_KEY]); strcat(buf1,buf2); strcat(buf1,"\n\n");
394 s1=strlen(buf1);
395 s=strlen(msg)+1;
396 if ((buf=AllocMem(s+s1,MEMF_CLEAR))) {
397 CopyMem(buf1,buf,s1);
398 CopyMem(msg,&buf[s1],s);
399 s+=s1;
400 msg=buf;
403 simplerequest(msg,globstring[STR_CONTINUE],NULL);
404 if (buf) FreeMem(buf,s);
406 else if (AmigaGuideBase && func)
408 struct NewAmigaGuide nag = {0};
409 AMIGAGUIDECONTEXT agc;
410 char buf[32];
412 nag.nag_Name = "DirectoryOpus.guide";
413 nag.nag_Screen = Window->WScreen;
414 nag.nag_Flags = 0 /*HTF_NOACTIVATE*/;
415 nag.nag_Context = helpcontext;
416 nag.nag_Node = getAGnode(buf,func[0]=='*'?func+1:func);
418 D(bug("Trying to display Amigaguide node \"%s\"\n",nag.nag_Node));
419 if ((agc = OpenAmigaGuide(&nag,NULL)))
421 CloseAmigaGuide(agc);
423 else simplerequest(defmsg ? defmsg : globstring[STR_HELP_NOT_AVAILABLE],globstring[STR_CONTINUE],NULL);
425 unbusy();
426 return;
429 void checkstringgads(a)
430 int a;
432 --a;
433 checkdir(str_pathbuffer[a],&path_strgadget[a]);
434 strcpy(dopus_curwin[a]->directory,str_pathbuffer[a]);
437 void setdirsize(dir,byte,win)
438 struct Directory *dir;
439 long long byte;
440 int win;
442 if (status_iconified || win==-1) return;
444 if (dir->size>0) {
445 dopus_curwin[win]->bytestot-=dir->size;
446 if (dir->selected) dopus_curwin[win]->bytessel-=dir->size;
448 if (byte<-1) byte=-1;
449 dir->size=byte;
450 if (dir->size!=-1) {
451 dopus_curwin[win]->bytestot+=byte;
452 if (dir->selected) dopus_curwin[win]->bytessel+=byte;