finally the biggest changes together with makefile. hardcoded flag removed.
[AROS-Contrib.git] / dopus / Program / main.c
blobb6b3200c0f1e42358646928f558b9b758bb4b7b2
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 <proto/locale.h>
33 #ifndef __AROS__
34 #include <proto/screennotify.h>
35 #include <proto/sysinfo.h>
36 #include <proto/multiuser.h>
37 #endif
38 #define _NO_PPCINLINE
40 #ifdef DEBUG
41 extern UWORD __chip uniconifydata[2][20];
42 extern UWORD __chip appicon_data[];
43 #endif
45 static BOOL staybehindWB;
47 extern BOOL useAHI;
49 static struct EasyStruct alert_es =
51 sizeof(struct EasyStruct),
53 "Directory Opus alert",
55 "Abort"
58 int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
59 void chkabort(void) { return; }
61 int main(argc,argv)
62 int argc;
63 char *argv[];
65 int a,in,iconstart,sup,ck,nsee;
66 struct WBStartup *WBmsg;
67 struct WBArg *p;
68 // struct DiskObject *dobj;
69 const char **toolarray;
70 char *s,*startdir=NULL,buf[32];
71 // BPTR lock;
74 #ifndef __SASC
75 SysBase = *( (void **)4L );
76 #endif
78 #ifndef __MORPHOS__
79 /* Verify useable OS version */
80 if (SysBase->LibNode.lib_Version>=40) system_version2=OSVER_40;
81 else if (SysBase->LibNode.lib_Version==39) system_version2=OSVER_39;
82 // else if (SysBase->LibNode.lib_Version==38) system_version2=OSVER_38;
83 // else if (SysBase->LibNode.lib_Version==37) system_version2=OSVER_37;
84 // else system_version2=OSVER_34;
85 else
87 IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",0);
88 DisplayAlert(RECOVERY_ALERT,"\0\0\xf You need Kickstart 3.0 or above to run Directory Opus!\0",26);
89 CloseLibrary((struct Library *) IntuitionBase);
91 return 5;
93 #ifdef __SASC_60
94 __exit(0);
95 #else
96 _exit(0);
97 #endif
100 #endif
101 /* Get pointer to our Process structure and set our WindowPtr for
102 errors to -1 (no errors appear). */
104 main_proc=(struct Process *) FindTask(NULL);
106 if ( main_proc->pr_StackSize < 16384 )
108 IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",36);
109 alert_es.es_TextFormat="You need at least 16384 bytes of stack to run Directory Opus!";
110 EasyRequestArgs(NULL,&alert_es,NULL,NULL);
111 CloseLibrary((struct Library *) IntuitionBase);
113 return 5;
115 #ifdef __SASC_60
116 __exit(0);
117 #else
118 _exit(0);
119 #endif
123 /* Attempt to open the DOPUS.LIBRARY. Look first in default search path, and
124 then look for it on the distribution disk. If we can't find it display an
125 appropriate alert and exit */
127 if (!(DOpusBase=(struct DOpusBase *)OpenLibrary("dopus.library",DOPUSLIB_VERSION)))
128 if (!(DOpusBase=(struct DOpusBase *)OpenLibrary("PROGDIR:dopus.library",DOPUSLIB_VERSION)))
129 if (!(DOpusBase=(struct DOpusBase *)OpenLibrary("PROGDIR:libs/dopus.library",DOPUSLIB_VERSION)))
130 if (!(DOpusBase=(struct DOpusBase *)OpenLibrary("DOpus:libs/dopus.library",DOPUSLIB_VERSION)))
131 DOpusBase = NULL;
132 if (!DOpusBase || (DOpusBase->LibNode.lib_Revision < DOPUSLIB_REVISION))
135 IntuitionBase=(struct IntuitionBase *) OpenLibrary("intuition.library",36);
137 alert_es.es_TextFormat="You need dopus.library v%ld.%ld or later to use Directory Opus!";
138 EasyRequest(NULL,&alert_es,NULL,DOPUSLIB_VERSION,DOPUSLIB_REVISION);
139 CloseLibrary((struct Library *) DOpusBase);
140 CloseLibrary((struct Library *) IntuitionBase);
142 return 5;
144 #ifdef __SASC_60
145 __exit(0);
146 #else
147 _exit(0);
148 #endif
152 /* status_flags contains various flags; initialise it to 0 to start with */
154 // status_flags=0;
156 windowptr_save = main_proc->pr_WindowPtr;
157 main_proc->pr_WindowPtr = (APTR)-1;
159 /* Initialise and open the other libraries that we need or want */
161 GfxBase = DOpusBase->GfxBase;
162 IntuitionBase = DOpusBase->IntuitionBase;
163 LayersBase = DOpusBase->LayersBase;
164 #ifdef __SASC
165 DOSBase = (struct DosLibrary *)OpenLibrary( "dos.library", 39 );
166 #endif
167 DiskfontBase = OpenLibrary("diskfont.library",0);
168 IconBase = OpenLibrary("icon.library",0);
169 WorkbenchBase = OpenLibrary("workbench.library",37);
170 CxBase = OpenLibrary("commodities.library",37);
171 RexxSysBase = (struct RxsLib *)OpenLibrary("rexxsyslib.library",0);
172 UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library",37);
173 CyberGfxBase = OpenLibrary("cybergraphics.library",40);
174 #ifndef __AROS__
175 PopupMenuBase = (struct PopupMenuBase *)OpenLibrary("popupmenu.library", 9);
177 // AccountsBase=NULL;
179 Forbid();
180 if (FindName(&SysBase->LibList,"services.library")) {
181 if ((AccountsBase = OpenLibrary("accounts.library",0))) {
182 user_info = AllocUserInfo();
183 group_info = AllocGroupInfo();
186 if (FindName(&SysBase->LibList,"multiuser.library")) {
187 if ((muBase = (struct muBase *)OpenLibrary("multiuser.library",39)))
189 mu_userinfo = muAllocUserInfo();
190 mu_groupinfo = muAllocGroupInfo();
193 Permit();
195 // OpenXFDlib();
197 // PPBase=(struct PPBase *)open_dopus_library("powerpacker.library",0);
198 MUSICBase = (struct MusicBase *)open_dopus_library("inovamusic.library",0);
199 ScreenNotifyBase = OpenLibrary("screennotify.library",0);
200 #endif
201 LocaleBase = OpenLibrary("locale.library",38);
202 DataTypesBase = OpenLibrary("datatypes.library",39);
203 AmigaGuideBase = OpenLibrary("amigaguide.library",39);
204 GadToolsBase = OpenLibrary("gadtools.library",39);
206 /* Restore window pointer now that we've got our libraries */
208 main_proc->pr_WindowPtr = windowptr_save;
210 /* Initialise various data */
212 D(bug("DOpusBase->cycletop: %lx\n",DOpusBase->pdb_cycletop));
213 D(bug("DOpusBase->cyclebot: %lx\n",DOpusBase->pdb_cyclebot));
214 D(bug("DOpusBase->check: %lx\n",DOpusBase->pdb_check));
215 D(bug("uniconifydata: %lx\n",uniconifydata));
216 D(bug("appicon_data: %lx\n",appicon_data));
217 D(bug("pageflip_data1: %lx\n",pageflip_data1));
218 D(bug("pageflip_data2: %lx\n",pageflip_data2));
219 D(bug("null_pointer: %lx\n",null_pointer));
220 D(bug("beepwave: %lx\n",beepwave));
222 // str_hunt_name[0]=0;
223 // str_search_string[0]=0;
224 // str_filter[0]=0;
225 // str_filter_parsed[0]=0;
227 if ((str_last_rexx_result = AllocVec(256,MEMF_ANY))) str_last_rexx_result[0] = 0;
228 else quit();
230 func_single_file[0]=0;
231 func_external_file[0]=0;
233 for (a=0;a<NUMFONTS;a++) scr_font[a]=NULL;
234 for (a=0;a<3;a++) external_mod_segment[a]=0;
236 for (a=0;a<2;a++) {
237 dos_notify_req[a]=NULL;
238 dos_notify_names[a][0]=0;
239 dopus_curwin[a]=dopus_firstwin[a]=NULL;
240 data_buffer_count[a]=0;
241 completion[a].memory=NULL;
242 completion[a].firstentry=NULL;
243 completion[a].currententry=NULL;
244 completion[a].path[0]=0;
247 for (a=0;a<16;a++) screen_pens[a].alloc=0;
249 func_reselection.reselection_list=NULL;
251 scrdata_is_pal=getpal();
253 iconstart=in=0;
254 strcpy(str_config_basename,"DirectoryOpus");
255 ck=1;
257 if (argc/*>=1*/) {
258 if (IconBase) user_appicon = GetDiskObject(argv[0]);
260 for (a=1;a<argc;a++) {
261 if (argv[a][0]=='-') {
262 switch (argv[a][1]) {
263 case 'i': iconstart=1; break;
264 case 'b': iconstart=2; break;
265 case 'c': LStrnCpy(str_config_basename,&argv[a][2],256); break;
266 case 'g': ck=0; break;
267 #ifdef _USE_SMALL_Q
268 case 'q': status_flags|=STATUS_IANSCRAP; break;
269 #endif
270 #ifdef _USE_CAPITAL_Q
271 case 'Q': status_flags|=STATUS_IANSCRAP2; break;
272 #endif
273 case 'x': xfdMasterBase = (struct xfdMasterBase *)OpenLibrary("xfdmaster.library",38); break;
274 case 'X': xadMasterBase = (struct xadMasterBase *)OpenLibrary("xadmaster.library",4); break;
275 case 'B': staybehindWB = TRUE;
278 else startdir = argv[a];
281 else if (/*argc==0 && */IconBase) {
282 WBmsg=(struct WBStartup *)argv;
283 p=WBmsg->sm_ArgList;
284 if ((user_appicon=/*dobj=*/GetDiskObject(p->wa_Name))) {
285 toolarray=(const char **)user_appicon/*dobj*/->do_ToolTypes;
286 if ((s=(char *)FindToolType(toolarray,"ICONSTART"))) iconstart=atoi(s);
287 if ((s=(char *)FindToolType(toolarray,"BUTTONSTART"))) iconstart=atoi(s)?2:iconstart;
288 if ((s=(char *)FindToolType(toolarray,"CONFIGFILE"))) LStrnCpy(str_config_basename,s,256);
289 if ((s=(char *)FindToolType(toolarray,"CHECK"))) ck=atoi(s);
290 if (FindToolType(toolarray,"USEAHI")) useAHI=TRUE;
291 if (FindToolType(toolarray,"FORCEOPENXFD")) xfdMasterBase = (struct xfdMasterBase *)OpenLibrary("xfdmaster.library",38);
292 if (FindToolType(toolarray,"FORCEOPENXAD")) xadMasterBase = (struct xadMasterBase *)OpenLibrary("xadmaster.library",4);
293 if (FindToolType(toolarray,"BEHINDWB")) staybehindWB = TRUE;
294 #ifndef __AROS__
295 if (FindToolType(toolarray,"USESYSINFO"))
297 D(bug("Opening sysinfo.library v2..."));
298 if ((SysInfoBase = OpenLibrary(SYSINFONAME,2L)))
300 D(bug("success\n"));
301 if ((sysinfo = InitSysInfo()))
303 D(bug("InitSysInfo() successful\n"));
304 if (!(sysinfo->cpu_usage_implemented & CPU_USAGEF_LASTSEC_IMPLEMENTED))
306 D(bug("CPU_USAGEF_LASTSEC not implemented! Falling back to standard CPU meter\n"));
307 FreeSysInfo(sysinfo);
308 sysinfo = NULL;
309 CloseLibrary(SysInfoBase);
312 CloseLibrary(SysInfoBase);
314 else D(bug("FAILED!\n"));
316 #endif
318 if (WBmsg->sm_NumArgs > 1) for (a = 1; a < WBmsg->sm_NumArgs; a++)
320 p = &(WBmsg->sm_ArgList[a]);
321 NameFromLock(p->wa_Lock,buf,32);
322 startdir = buf;
325 if (user_appicon)
327 user_appicon->do_CurrentX = NO_ICON_POSITION;
328 user_appicon->do_CurrentY = NO_ICON_POSITION;
331 old_pr_cis=main_proc->pr_CIS;
332 old_pr_cos=main_proc->pr_COS;
333 old_pr_consoletask=main_proc->pr_ConsoleTask;
335 nil_file_handle=Open("NIL:",MODE_NEWFILE);
336 main_proc->pr_CIS=nil_file_handle;
337 main_proc->pr_COS=nil_file_handle;
338 #ifdef __AROS__
339 #warning Set pr_ConsoleTask to something sensible instead of NULL
340 main_proc->pr_ConsoleTask=NULL;
341 #else
342 main_proc->pr_ConsoleTask=(APTR)((struct FileHandle *)BADDR(nil_file_handle))->fh_Type;
343 #endif
345 if ((s=strstri(BaseName(str_config_basename),".CFG"))) *s=0;
347 allocstrings();
349 nullpalette=(UWORD *)astring(sizeof(UWORD)*256);
351 scrdata_norm_width=GfxBase->NormalDisplayColumns;
352 scrdata_norm_height=GfxBase->NormalDisplayRows;
354 // main_proc->pr_WindowPtr = (APTR)-1; //HUX done at top already
356 FindSystemFile("DOpusRT",str_dopusrt_path,256,SYSFILE_COMMAND);
358 config=(struct Config *)astring(sizeof(struct Config));
360 /* Initialized in data.c */
362 filetype_key=NULL;
363 dopus_firsttype=NULL;
364 dopus_firstgadbank=NULL;
365 dopus_curgadbank=NULL;
366 dopus_firsthotkey=NULL;
368 read_configuration(0);
370 if (startdir) LStrnCpy(config->autodirs[0],startdir,69);
372 #ifndef __AROS__
373 initlistermenu();
374 #endif
376 // if (!(lock=Lock("ENV:",ACCESS_READ))) Assign("ENV:","RAM:");
377 // else UnLock(lock);
379 if (!(install_arbiter()) ||
380 !(count_port=LCreatePort(NULL,0)) ||
381 !(general_port=LCreatePort(NULL,0)) ||
382 !(snm_port = LCreatePort(NULL,0)) ||
383 !(arexx_port=CreateUniquePort("DOPUS",str_arexx_portname,&system_dopus_runcount))) quit();
385 rexx_signalbit = 1<<arexx_port->mp_SigBit;
387 #ifndef __AROS__
388 if (ScreenNotifyBase) snm_handle = AddWorkbenchClient(snm_port,0);
389 #endif
391 if (WorkbenchBase) {
392 if (!(appmsg_port=LCreatePort(0,0))) quit();
394 for (a=0;a<2;a++) {
395 if ((dos_notify_req[a]=LAllocRemember(&general_key,sizeof(struct NotifyRequest),MEMF_ANY|MEMF_CLEAR)))
396 dos_notify_req[a]->nr_Name=dos_notify_names[a];
399 if (!(keyboard_req=(struct IOStdReq *)
400 LCreateExtIO(general_port,sizeof(struct IOStdReq)))) quit();
401 if ((OpenDevice("keyboard.device",0,(struct IORequest *)keyboard_req,0))!=0) {
402 LDeleteExtIO((struct IORequest *)keyboard_req); keyboard_req=NULL;
403 quit();
406 if (! CxBase)
408 if (!(input_req=(struct IOStdReq *)LCreateExtIO(general_port,sizeof(struct IOStdReq))))
409 quit();
410 if ((OpenDevice("input.device",0,(struct IORequest *)input_req,0))!=0)
412 LDeleteExtIO((struct IORequest *)input_req);
413 input_req=NULL;
414 quit();
417 ramdisk_lock=Lock("RAM:",ACCESS_READ);
419 strcpy(str_select_pattern[0],"*");
420 strcpy(str_select_pattern[3],"*");
422 struct DOpusDateTime dt;
424 DateStamp(&dt.dat_Stamp);
425 initdatetime(&dt,str_select_pattern[1],NULL,1);
428 init_menus();
430 if (ck && (FindTask("dopus_hotkeez"))) {
431 status_iconified=1;
432 switch ( simplerequest( globstring[ STR_DOPUS_ALREADY_RUNNING ], globstring[ STR_RUN ], str_cancelstring, globstring[ STR_BRING_TO_FRONT ], NULL ) ) // HUX
434 case 2:
436 // Signal(FindTask("dopus_hotkeez"),INPUTSIG_UNICONIFY);
437 if (CxBase)
439 struct InputEvent ie;
441 ie.ie_NextEvent = NULL;
442 ie.ie_Class = IECLASS_RAWKEY;
443 ie.ie_Code = config->hotkeycode;
444 ie.ie_Qualifier = config->hotkeyqual;
445 AddIEvents(&ie);
448 case 0:
449 quit();
450 break;
451 default:
452 status_iconified=0;
455 hotkey_task = NULL;
457 data_colorclock = (scrdata_is_pal ? 3546895 : 3579545);
459 setup_externals();
461 setupchangestate();
463 do_remember_config(remember_data);
465 if (!(dir_memory_pool=LibCreatePool(MEMF_ANY|MEMF_CLEAR,16384,1024)))
466 quit();
468 allocdirbuffers(config->bufcount);
470 for (a=0;a<2;a++) horiz_propimage[a].Width=65;
472 #ifdef __AROS__
473 hotkey_task=(struct Task *) CreateTask("dopus_hotkeez",config->priority+1,hotkeytaskcode,AROS_STACKSIZE);
474 #else
475 hotkey_task=(struct Task *) CreateTask("dopus_hotkeez",config->priority+1,hotkeytaskcode,4096); // JRZ: was 2048
476 #endif
478 if (iconstart) SetUp(-1);
480 sup=nsee=0;
481 if (config->autodirs[0][0] || config->autodirs[1][0]) {
482 if (!iconstart) {
483 sup=1;
484 SetUp(1);
485 busy();
487 nsee=1;
488 for (a=0;a<2;a++) {
489 if (config->autodirs[a][0]) {
490 strcpy(str_pathbuffer[a],config->autodirs[a]);
491 checkdir(str_pathbuffer[a],(sup)?&path_strgadget[a]:NULL);
492 strcpy(dopus_curwin[a]->directory,str_pathbuffer[a]);
493 getdir(dopus_curwin[a],a,0);
497 if (iconstart) {
498 status_configuring=0;
499 iconify(sup+1,iconstart-1,0);
501 else if (!sup) SetUp(1);
502 if (nsee) {
503 for (a=0;a<2;a++) {
504 seename(a);
505 checkdir(str_pathbuffer[a],&path_strgadget[a]);
506 fixhorizprop(a);
509 if (!iconstart) unbusy();
511 doidcmp();
512 return 0;
515 int SetUp(tit)
516 int tit;
518 int y,a,b,c,count=0,lim=48,num,other_offset;
519 struct Screen scrbuf,*pubscr=NULL;
520 struct DimensionInfo dims;
521 DisplayInfoHandle *handle;
522 struct dopusgadgetbanks *bank;
523 struct RastPort testrastport;
525 removewindowgadgets(Window);
527 SetTaskPri((struct Task *)main_proc,config->priority);
528 if (hotkey_task) SetTaskPri(hotkey_task,config->priority+1);
529 status_configuring=-1; status_iconified=0;
531 main_scr.ViewModes=HIRES;
532 config->screenmode=checkscreenmode(config->screenmode);
534 main_win.Flags=WFLG_NW_EXTENDED|WFLG_NEWLOOKMENUS|WFLG_NOCAREREFRESH;
535 mainwindow_tags[0].ti_Tag=TAG_SKIP;
536 // mainwindow_tags[0].ti_Data=0;
537 #ifdef _USE_CAPITAL_Q
538 if (status_flags&STATUS_IANSCRAP2) {
539 mainwindow_tags[2].ti_Tag=TAG_SKIP;
540 // mainwindow_tags[2].ti_Data=0;
542 #endif
543 if (config->screenmode==MODE_PUBLICSCREEN && /*system_version2 &&*/
544 (pubscr=LockPubScreen(config->pubscreen_name))) {
545 CopyMem((char *)pubscr,(char *)&scrbuf,sizeof(struct Screen));
547 else {
548 GetWBScreen(&scrbuf);
549 if (config->screenmode==MODE_PUBLICSCREEN) config->screenmode=MODE_WORKBENCHUSE;
552 setup_draw_info();
554 if (config->screenmode==MODE_WORKBENCHUSE || config->screenmode==MODE_PUBLICSCREEN)
555 status_publicscreen=1;
556 else {
557 status_publicscreen=0;
558 if (config->screenmode==MODE_WORKBENCHCLONE) {
559 mainscreen_tags[SCREENTAGS_DISPLAYID].ti_Data=clone_screen(NULL,&main_scr);
561 /* else if (!system_version2) {
562 if (config->screenflags&SCRFLAGS_DEFWIDTH)
563 main_scr.Width=GfxBase->NormalDisplayColumns;
564 else main_scr.Width=config->scrw;
565 if (config->screenflags&SCRFLAGS_DEFHEIGHT) {
566 if (config->screenmode==HIRESLACE_KEY)
567 main_scr.Height=GfxBase->NormalDisplayRows*2;
568 else main_scr.Height=GfxBase->NormalDisplayRows;
570 else main_scr.Height=config->scrh;
571 if (config->screenmode==HIRESLACE_KEY) main_scr.ViewModes|=LACE;
572 } */
573 else {
574 if ((handle=FindDisplayInfo(config->screenmode)) &&
575 (GetDisplayInfoData(handle,(UBYTE *)&dims,sizeof(struct DimensionInfo),
576 DTAG_DIMS,0))) {
577 mainscreen_tags[SCREENTAGS_DISPLAYID].ti_Data=(IPTR)config->screenmode;
578 if (config->screenflags&SCRFLAGS_DEFWIDTH)
579 main_scr.Width=(dims.TxtOScan.MaxX-dims.TxtOScan.MinX)+1;
580 else main_scr.Width=config->scrw;
581 if (config->screenflags&SCRFLAGS_DEFHEIGHT)
582 main_scr.Height=(dims.TxtOScan.MaxY-dims.TxtOScan.MinY)+1;
583 else main_scr.Height=config->scrh;
585 else {
586 main_scr.Width=scrbuf.Width;
587 main_scr.Height=scrbuf.Height;
588 main_scr.ViewModes=scrbuf.ViewPort.Modes;
593 if (config->scrdepth<2) config->scrdepth=2;
594 main_scr.Depth=config->scrdepth;
596 if (config->gadgetrows<0 || config->gadgetrows>6) config->gadgetrows=6;
597 scr_gadget_rows=config->gadgetrows;
598 if (data_gadgetrow_offset+scr_gadget_rows>6) data_gadgetrow_offset=0;
600 tryfonts:
601 if (count==5) {
602 status_iconified=1;
603 simplerequest(globstring[STR_UNABLE_TO_OPEN_WINDOW],globstring[STR_CONTINUE],NULL);
604 status_iconified=0;
605 quit();
607 else if (count==4) {
608 for (a=0;a<NUMFONTS;a++) {
609 if (config->fontsizes[a]>8) {
610 strcpy(config->fontbufs[a],"topaz.font");
611 config->fontsizes[a]=8;
615 else if (count) {
616 if (Window) busy();
617 for (a=0;a<NUMFONTS;a++) {
618 if (config->fontsizes[a]>lim) config->fontsizes[a]/=2;
620 lim/=2;
623 config->fontsizes[0]=8;
624 for (a=0;a<FONT_LAST;a++) {
625 freefont(a);
626 b=config->fontsizes[a];
627 scr_font[a]=getfont(config->fontbufs[a],&b,(a==FONT_GENERAL)||(a==FONT_TEXT));
628 config->fontsizes[a]=b;
631 if (Window && count) unbusy();
633 scrdata_font_xsize=scr_font[FONT_DIRS]->tf_XSize;
634 scrdata_font_ysize=scr_font[FONT_DIRS]->tf_YSize;
635 scrdata_font_baseline=scr_font[FONT_DIRS]->tf_Baseline;
637 screen_attr.ta_Name=(STRPTR)config->fontbufs[FONT_GENERAL];
638 menu_attr.ta_Name=(STRPTR)config->fontbufs[FONT_MENUS];
639 menu_attr.ta_YSize=config->fontsizes[FONT_MENUS];
640 main_screen_attr.ta_Name=(STRPTR)config->fontbufs[FONT_SCREEN];
641 main_screen_attr.ta_YSize=config->fontsizes[FONT_SCREEN];
643 if (tit>-1) {
644 if (config->screenmode==MODE_WORKBENCHUSE) main_win.Type=WBENCHSCREEN;
645 else if (pubscr) {
646 main_win.Type=PUBLICSCREEN;
647 mainwindow_tags[0].ti_Tag=WA_PubScreen;
648 mainwindow_tags[0].ti_Data=(IPTR)pubscr;
650 else {
651 main_win.Type=CUSTOMSCREEN;
653 // if (system_version2) {
654 main_scr.LeftEdge=(GfxBase->NormalDisplayColumns-main_scr.Width)/2;
655 if (main_scr.LeftEdge<0) main_scr.LeftEdge=0;
656 /* }
657 else main_scr.LeftEdge=0;
659 main_scr.TopEdge=0;
660 if (config->screenflags&SCRFLAGS_HALFHEIGHT) {
661 if (main_scr.Height<400) config->screenflags&=~SCRFLAGS_HALFHEIGHT;
662 else {
663 main_scr.Height/=2;
664 main_scr.TopEdge=main_scr.Height;
668 if (!MainScreen) {
669 if (!(MainScreen=(struct Screen *) OpenScreen((struct NewScreen *)&main_scr))) {
670 status_iconified=1;
671 simplerequest(globstring[STR_UNABLE_TO_OPEN_WINDOW],globstring[STR_CONTINUE],NULL);
672 status_iconified=0;
673 if (config->screenmode==HIRES_KEY && config->scrw==640 &&
674 config->scrh==200+(scrdata_is_pal*56) && config->screenflags==0 &&
675 config->scrdepth==2) quit();
676 config->screenmode=HIRES_KEY;
677 config->scrw=640;
678 config->scrh=200+(scrdata_is_pal*56);
679 config->scrdepth=2;
680 config->screenflags=0;
681 if (pubscr) UnlockPubScreen(NULL,pubscr);
682 return(SetUp(tit));
684 // main_vp=&(MainScreen->ViewPort);
685 load_palette(MainScreen,config->new_palette);
687 main_win.Screen=MainScreen;
688 /*if (system_version2)*/ PubScreenStatus(MainScreen,0);
689 #ifdef _USE_CAPITAL_Q
690 if (status_flags&STATUS_IANSCRAP2) ShowTitle(MainScreen,FALSE);
691 #endif
692 CopyMem((char *)MainScreen,(char *)&scrbuf,sizeof(struct Screen));
697 if (config->generalscreenflags&SCR_GENERAL_WINBORDERS && MainScreen)
698 status_publicscreen=1;
700 /* Screen clock bar */
702 scrdata_clock_height=scr_font[FONT_CLOCK]->tf_YSize+2;
703 if (scrdata_clock_height<10) scrdata_clock_height=10;
705 /* Status bar */
707 if (config->generalscreenflags&SCR_GENERAL_TITLESTATUS)
708 scrdata_status_height=0;
709 else scrdata_status_height=scr_font[FONT_STATUS]->tf_YSize+3;
711 /* Disk name bars */
713 scrdata_diskname_height=scr_font[FONT_NAMES]->tf_YSize+2;
715 /* String gadgets */
717 scrdata_string_height=config->stringheight;
718 if (scrdata_string_height<scr_font[FONT_STRING]->tf_YSize)
719 scrdata_string_height=scr_font[FONT_STRING]->tf_YSize;
721 /* Calculate window borders */
723 if (status_publicscreen) {
724 if (MainScreen) {
725 scrdata_xoffset=MainScreen->WBorLeft;
726 #ifdef __AROS__
727 scrdata_yoffset=MainScreen->WBorTop+MainScreen->Font->ta_YSize+1;
728 #else
729 scrdata_yoffset=MainScreen->WBorTop+scr_font[FONT_SCREEN]->tf_YSize+1;
730 #endif
732 else {
733 scrdata_xoffset=scrbuf.WBorLeft;
734 scrdata_yoffset=scrbuf.WBorTop+scrbuf.Font->ta_YSize+1;
737 else {
738 scrdata_xoffset=0;
739 #ifdef _USE_CAPITAL_Q
740 if (status_flags&STATUS_IANSCRAP2) scrdata_yoffset=0;
741 else
742 #endif
743 if (MainScreen) scrdata_yoffset=MainScreen->BarHeight+1;
744 else scrdata_yoffset=GfxBase->DefaultFont->tf_YSize+3;
747 /* Calculcate minimum window width and height */
749 scr_min_width=(config->sliderwidth+8)*2+(config->arrowsize[1]+config->arrowsize[2])*4;
750 if (scr_gadget_rows) scr_min_width+=8*(scr_font[FONT_GADGETS]->tf_XSize*2);
751 scr_min_width+=scrdata_font_xsize*8;
753 scr_min_height=
754 ((status_publicscreen)?scrdata_yoffset:0)+
755 scrdata_status_height+
756 scrdata_diskname_height+
757 (config->arrowsize[0]*3)+
758 config->sliderheight+
759 scrdata_string_height+
760 scrdata_clock_height+
761 (scr_font[FONT_GADGETS]->tf_YSize*2)+
764 if (main_scr.Width<scr_min_width) main_scr.Width=scr_min_width;
765 if (main_scr.Height<scr_min_height) main_scr.Height=scr_min_height;
766 if (Window) WindowLimits(Window,scr_min_width,scr_min_height,-1,-1);
767 else {
768 main_win.MinWidth=scr_min_width;
769 main_win.MinHeight=scr_min_height;
772 /* Get window size */
774 if (status_publicscreen) main_win.Width=config->scr_winw;
775 else main_win.Width=config->scrw;
776 if (config->screenflags&SCRFLAGS_DEFWIDTH || main_win.Width<0)
777 main_win.Width=scrbuf.Width;
778 if (main_win.Width>scrbuf.Width) main_win.Width=scrbuf.Width;
780 if (status_publicscreen) main_win.Height=config->scr_winh;
781 else main_win.Height=main_scr.Height;
782 if (config->screenflags&SCRFLAGS_DEFHEIGHT || main_win.Height<0) {
783 main_win.Height=scrbuf.Height;
784 if (status_publicscreen) {
785 config->scr_winy=scrbuf.BarHeight+1;
786 main_win.Height-=config->scr_winy;
789 if (main_win.Height>scrbuf.Height) main_win.Height=scrbuf.Height;
791 /* If window is already open use it's dimensions (this is a mess actually) */
792 if (Window) {
793 main_win.Width=Window->Width;
794 main_win.Height=Window->Height;
797 /* Adjust for window borders */
799 if (status_publicscreen) {
800 scrdata_width=main_win.Width-scrdata_xoffset-scrbuf.WBorRight;
801 scrdata_height=main_win.Height-scrdata_yoffset-scrbuf.WBorBottom;
803 else {
804 scrdata_width=main_scr.Width-scrdata_xoffset;
805 scrdata_height=main_scr.Height-scrdata_yoffset;
808 /* Screen clock bar */
810 scrdata_clock_width=scrdata_width-((config->generalscreenflags&SCR_GENERAL_TINYGADS)?115:1);
811 scrdata_clock_xpos=scrdata_xoffset+2;
812 scrdata_clock_ypos=(scrdata_yoffset+scrdata_height+1)-scrdata_clock_height+1;
814 /* Disk name bars */
816 scrdata_diskname_ypos=scrdata_status_height+1+scrdata_yoffset;
818 /* Fuck knows */
820 scrdata_scr_height=scrdata_height;
821 scrdata_gadget_height=scr_font[FONT_GADGETS]->tf_YSize+2;
823 FOREVER {
824 other_offset=
825 (scrdata_diskname_ypos-scrdata_yoffset)+
826 scrdata_diskname_height+
827 scrdata_string_height+
828 config->sliderheight+
829 (scr_gadget_rows*scrdata_gadget_height)+
830 scrdata_clock_height+9;
832 scrdata_dispwin_ypos=scrdata_diskname_ypos+scrdata_diskname_height;
834 scrdata_dispwin_height=scrdata_scr_height-other_offset;/*+scrdata_yoffset;*/
836 if (((config->arrowsize[0]*2)+8+scrdata_font_ysize)>scrdata_dispwin_height ||
837 (other_offset>scrdata_scr_height-(config->sliderheight+32))) {
839 if (scr_gadget_rows==6) scr_gadget_rows=3;
840 else if (scr_gadget_rows>0) --scr_gadget_rows;
841 else {
842 ++count;
843 goto tryfonts;
845 continue;
847 else break;
850 scrdata_dispwin_lines=scrdata_dispwin_height/scrdata_font_ysize;
851 scrdata_dirwin_height=scrdata_dispwin_lines*scrdata_font_ysize;
852 scrdata_dirwin_bottom=
853 scrdata_yoffset+
854 (scrdata_scr_height-
855 scrdata_string_height-
856 config->sliderheight-
857 (scr_gadget_rows*scrdata_gadget_height)-
858 scrdata_clock_height-32);
860 scrdata_gadget_ypos=scrdata_dirwin_bottom+33+scrdata_string_height+config->sliderheight;
862 scrdata_prop_height=scrdata_dispwin_height-((config->arrowsize[0]+2)*2);
864 scrdata_gadget_width=scrdata_width/8;
865 scrdata_drive_width=0;
866 InitRastPort(&testrastport);
867 SetFont(&testrastport,scr_font[FONT_GADGETS]);
868 for (a=0;a<USEDRIVECOUNT;a++) {
869 if ((b=TextLength(&testrastport,config->drive[a].name,
870 strlen(config->drive[a].name)))>scrdata_drive_width) scrdata_drive_width=b;
872 if (scrdata_drive_width>0) {
873 scrdata_drive_width+=4;
874 if (scrdata_drive_width<=scrdata_gadget_width)
875 scrdata_gadget_width=((scrdata_width-scrdata_drive_width)/7);
876 scrdata_drive_width=scrdata_width-(scrdata_gadget_width*7);
878 else {
879 scrdata_drive_width=0;
880 scrdata_gadget_width=scrdata_width/7;
883 SetFont(&testrastport,scr_font[FONT_DIRS]);
884 getprotdatelengths(&testrastport);
886 string_extend.Font=scr_font[FONT_STRING];
887 if (config->stringfgcol==config->stringbgcol)
888 ++config->stringfgcol;
889 if (config->stringselfgcol==config->stringselbgcol)
890 ++config->stringselfgcol;
891 path_stringinfo[0].Extension=&string_extend;
892 path_stringinfo[1].Extension=&string_extend;
894 if (scr_gadget_rows) {
895 bank=dopus_firstgadbank;
896 for (num=0;bank;num++) bank=bank->next;
897 scr_gadget_bank_count=(num*6)/scr_gadget_rows;
899 else scr_gadget_bank_count=0;
901 if (config->generalscreenflags&SCR_GENERAL_GADSLIDERS && scr_gadget_rows) {
902 int slider_width=0;
904 if (scrdata_drive_width) slider_width+=16;
905 if (scr_gadget_bank_count>1) slider_width+=16;
907 scrdata_gadget_width=((scrdata_width-slider_width-scrdata_drive_width)/7);
908 a=scrdata_width-((scrdata_gadget_width*7)+scrdata_drive_width);
910 if (scrdata_drive_width) {
911 if (scr_gadget_bank_count>1) {
912 drive_propgad.Width=gadget_propgad.Width=(a/2)-8;
913 if (a%2) ++gadget_propgad.Width;
915 else {
916 drive_propgad.Width=a-8;
917 if (drive_propgad.Width>8) {
918 scrdata_drive_width+=drive_propgad.Width-8;
919 drive_propgad.Width=8;
923 else gadget_propgad.Width=a-8;
926 scrdata_gadget_offset=(scrdata_width-((scrdata_gadget_width*7)+scrdata_drive_width))/2;
927 if (config->generalscreenflags&SCR_GENERAL_GADSLIDERS && scr_gadget_rows) {
928 if (scr_gadget_bank_count>1) scrdata_gadget_offset-=gadget_propgad.Width+8;
929 else if (scrdata_drive_width) scrdata_gadget_offset-=drive_propgad.Width+8;
931 if (scrdata_gadget_offset>scrdata_width) scrdata_gadget_offset=0;
933 scrdata_gadget_offset+=scrdata_xoffset;
934 scrdata_gadget_xpos=scrdata_gadget_offset+scrdata_drive_width;
936 if (config->generalscreenflags&SCR_GENERAL_NEWLOOKPROP /*&& system_version2*/) {
937 status_flags|=STATUS_NEWLOOK;
938 for (a=0;a<2;a++) {
939 vert_propinfo[a].Flags=AUTOKNOB|PROPNEWLOOK|FREEVERT|PROPBORDERLESS;
940 horiz_propinfo[a].Flags=AUTOKNOB|PROPNEWLOOK|FREEHORIZ|PROPBORDERLESS;
942 drive_propinfo.Flags|=AUTOKNOB|PROPNEWLOOK|FREEVERT|PROPBORDERLESS;
943 gadget_propinfo.Flags|=AUTOKNOB|PROPNEWLOOK|FREEVERT|PROPBORDERLESS;
945 else {
946 status_flags&=~STATUS_NEWLOOK;
947 for (a=0;a<2;a++) {
948 vert_propinfo[a].Flags=FREEVERT|PROPBORDERLESS;
949 horiz_propinfo[a].Flags=FREEHORIZ|PROPBORDERLESS;
951 drive_propinfo.Flags=FREEVERT|PROPBORDERLESS;
952 gadget_propinfo.Flags=FREEVERT|PROPBORDERLESS;
955 if (config->generalscreenflags&SCR_GENERAL_GADSLIDERS && scr_gadget_rows) {
957 if (scrdata_drive_width>0) {
958 scrdata_gadget_xpos+=drive_propgad.Width+8;
960 drive_propgad.LeftEdge=scrdata_gadget_offset+scrdata_drive_width+4;
961 drive_propgad.TopEdge=scrdata_gadget_ypos+1;
962 drive_propgad.Height=scr_gadget_rows*scrdata_gadget_height-4;
963 drive_propimage.Width=drive_propgad.Width;
964 drive_propimage.Height=drive_propgad.Height;
965 FixSliderBody(NULL,&drive_propgad,USEDRIVECOUNT,scr_gadget_rows,0);
968 if (scr_gadget_bank_count>1) {
969 gadget_propgad.LeftEdge=scrdata_gadget_xpos+(scrdata_gadget_width*7)+4;
970 gadget_propgad.TopEdge=scrdata_gadget_ypos+1;
971 gadget_propgad.Height=scr_gadget_rows*scrdata_gadget_height-4;
972 gadget_propimage.Width=gadget_propgad.Width;
973 gadget_propimage.Height=gadget_propgad.Height;
974 FixSliderBody(NULL,&gadget_propgad,scr_gadget_bank_count,1,0);
977 if (status_flags&STATUS_NEWLOOK) gadget_propimage.Height=0;
980 if (tit>-1) {
981 layoutcenter(config->windowdelta);
983 if (config->generalscreenflags&SCR_GENERAL_TINYGADS) {
984 for (a=0;a<6;a++) {
985 screen_gadgets[SCRGAD_TINYHELP+a].LeftEdge=
986 scrdata_clock_xpos+scrdata_clock_width+(a*19)-1;
987 screen_gadgets[SCRGAD_TINYHELP+a].TopEdge=
988 scrdata_clock_ypos-2;
989 screen_gadgets[SCRGAD_TINYHELP+a].Height=scrdata_clock_height;
991 screen_gadgets[SCRGAD_TINYHELP].Flags&=~GFLG_SELECTED;
992 screen_gadgets[SCRGAD_TINYAREXX].NextGadget=&screen_gadgets[SCRGAD_TINYHELP];
994 else screen_gadgets[SCRGAD_TINYAREXX].NextGadget=&screen_gadgets[SCRGAD_MOVELEFT1];
996 for (y=0;y<2;y++) {
997 fixhlen(y);
998 vert_propimage[y].LeftEdge=horiz_propimage[y].LeftEdge=0;
999 vert_propimage[y].TopEdge=horiz_propimage[y].TopEdge=0;
1000 vert_propimage[y].Width=config->sliderwidth;
1001 vert_propimage[y].Height=0;
1002 horiz_propimage[y].Height=config->sliderheight;
1003 vert_propimage[y].ImageData=horiz_propimage[y].ImageData=NULL;
1004 vert_propimage[y].PlanePick=horiz_propimage[y].PlanePick=0;
1005 vert_propimage[y].NextImage=horiz_propimage[y].NextImage=NULL;
1006 FixSliderBody(NULL,&horiz_propgad[y],dopus_curwin[y]->hlen,scrdata_dispwin_nchars[y],0);
1009 if (status_publicscreen) {
1010 if (MainScreen) {
1011 main_win.LeftEdge=config->scr_winx;
1012 main_win.TopEdge=config->scr_winy;
1014 else {
1015 main_win.LeftEdge=config->wbwinx;
1016 main_win.TopEdge=config->wbwiny;
1018 if (main_win.LeftEdge+main_win.Width>scrbuf.Width)
1019 main_win.LeftEdge=scrbuf.Width-main_win.Width;
1020 if (main_win.TopEdge+main_win.Height>scrbuf.Height)
1021 main_win.TopEdge=scrbuf.Height-main_win.Height;
1022 if (main_win.LeftEdge<0) main_win.LeftEdge=0;
1023 if (main_win.TopEdge<0) main_win.TopEdge=0;
1024 main_win.Flags|=WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET;
1025 main_win.Title=str_arexx_portname;
1027 else {
1028 main_win.LeftEdge=0;
1029 main_win.TopEdge=0;
1030 main_win.Flags|=WFLG_ACTIVATE|WFLG_BACKDROP|WFLG_RMBTRAP|WFLG_BORDERLESS;
1031 main_win.Title=NULL;
1034 // if (config->generalscreenflags&SCR_GENERAL_NEWLOOKMENU)
1035 // main_win.Flags|=WFLG_NEWLOOKMENUS;
1037 if (!Window) {
1038 if (!(Window=OpenWindow((struct NewWindow *)&main_win))) {
1039 if (MainScreen) ScreenToFront(MainScreen);
1040 simplerequest(globstring[STR_UNABLE_TO_OPEN_WINDOW],globstring[STR_CONTINUE],NULL);
1041 if (config->screenmode==HIRES_KEY && config->scr_winw==640 &&
1042 config->scr_winh==200+(scrdata_is_pal*56) && config->scrdepth==2 &&
1043 config->screenflags==0) quit();
1044 config->screenmode=HIRES_KEY;
1045 config->scr_winw=640;
1046 config->scr_winh=200+(scrdata_is_pal*56);
1047 config->scrdepth=2;
1048 config->screenflags=0;
1049 if (MainScreen) CloseScreen(MainScreen);
1050 MainScreen=NULL;
1051 if (pubscr) UnlockPubScreen(NULL,pubscr);
1052 return(SetUp(tit));
1054 main_win.Width=Window->Width;
1055 main_win.Height=Window->Height;
1056 if (pubscr) ScreenToFront(pubscr);
1057 get_colour_table();
1059 else {
1060 RefreshWindowFrame(Window);
1061 SetAPen(main_rp,0);
1062 rectfill(main_rp,
1063 scrdata_xoffset,
1064 scrdata_yoffset,
1065 scrdata_width,
1066 scrdata_height);
1069 main_rp=Window->RPort;
1070 main_rp->GelsInfo=&drag_gelsinfo;
1071 InitGels(&drag_dummy_sprite1,&drag_dummy_sprite2,&drag_gelsinfo);
1073 string_extend.Pens[0]=screen_pens[config->stringfgcol].pen;
1074 string_extend.Pens[1]=screen_pens[config->stringbgcol].pen;
1075 string_extend.ActivePens[0]=screen_pens[config->stringselfgcol].pen;
1076 string_extend.ActivePens[1]=screen_pens[config->stringselbgcol].pen;
1078 drive_propimage.PlaneOnOff=screen_pens[config->slidercol].pen;
1079 gadget_propimage.PlaneOnOff=screen_pens[config->slidercol].pen;
1080 drive_propgad.MutualExclude=screen_pens[config->sliderbgcol].pen;
1081 gadget_propgad.MutualExclude=screen_pens[config->sliderbgcol].pen;
1083 for (y=0;y<2;y++) {
1084 vert_propimage[y].PlaneOnOff=screen_pens[config->slidercol].pen;
1085 horiz_propimage[y].PlaneOnOff=screen_pens[config->slidercol].pen;
1086 vert_propimage[y].NextImage=horiz_propimage[y].NextImage=NULL;
1087 vert_propgad[y].MutualExclude=screen_pens[config->sliderbgcol].pen;
1088 horiz_propgad[y].MutualExclude=screen_pens[config->sliderbgcol].pen;
1091 if (status_publicscreen) {
1092 if (WorkbenchBase && !dopus_appwindow)
1093 dopus_appwindow=AddAppWindowA(APPWINID,0,Window,appmsg_port,NULL);
1095 SetWindowTitles(Window,(char *)-1,str_arexx_portname);
1096 screen_gadgets[SCRGAD_LEFTPARENT].Width=Window->BorderLeft+2;
1097 screen_gadgets[SCRGAD_RIGHTPARENT].Width=Window->BorderRight+2;
1099 size_gadgets[0].LeftEdge=Window->Width-Window->BorderRight-1;
1100 size_gadgets[0].TopEdge=Window->Height-16;
1101 size_gadgets[0].Width=Window->BorderRight+1;
1102 size_gadgets[0].Height=17;
1104 size_gadgets[1].LeftEdge=Window->Width-32;
1105 size_gadgets[1].TopEdge=Window->Height-Window->BorderBottom-1;
1106 size_gadgets[1].Width=33;
1107 size_gadgets[1].Height=Window->BorderBottom+1;
1109 else {
1110 screen_gadgets[SCRGAD_LEFTPARENT].Width=2;
1111 screen_gadgets[SCRGAD_RIGHTPARENT].Width=2;
1114 if ((Window->WScreen->Width/Window->WScreen->Height) == 1) status_flags|=STATUS_SQUAREPIXEL;
1115 else status_flags&=~STATUS_SQUAREPIXEL;
1117 if (config->generalflags&GENERAL_DRAG) allocdragbuffers();
1119 b=(scrdata_dispwin_height-scrdata_dirwin_height)/2;
1120 if (b<0) b=0;
1122 if (scrdata_dispwin_lines<5) c=scrdata_font_ysize/2;
1123 else if (scrdata_dispwin_lines<9) c=scrdata_font_ysize*2;
1124 else c=scrdata_font_ysize*3;
1126 for (a=0;a<2;a++) {
1127 scrdata_dirwin_ypos[a]=scrdata_dispwin_ypos+b;
1128 CopyMem((char *)main_rp,(char *)&dir_rp[a],sizeof(struct RastPort));
1129 SetFont(&dir_rp[a],scr_font[FONT_DIRS]);
1130 SetDrMd(&dir_rp[a],JAM2);
1132 scr_scroll_borders[a].MinX=
1133 scrdata_dirwin_xpos[a]+(((scrdata_dispwin_nchars[a]/2)-6)/**scrdata_font_xsize*/);
1134 scr_scroll_borders[a].MaxX=
1135 scrdata_dirwin_xpos[a]+(((scrdata_dispwin_nchars[a]/2)+6)/**scrdata_font_xsize*/);
1136 scr_scroll_borders[a].MinY=
1137 scrdata_dirwin_ypos[a]+(((scrdata_dispwin_lines/2)*scrdata_font_ysize)-c);
1138 scr_scroll_borders[a].MaxY=
1139 scrdata_dirwin_ypos[a]+(((scrdata_dispwin_lines/2)*scrdata_font_ysize)+c);
1142 if (scrdata_status_height>0) scrdata_status_width=scrdata_width-4;
1143 else {
1144 struct Gadget *gad;
1145 int min=0,max=0;
1147 if (status_publicscreen) {
1148 gad=Window->FirstGadget;
1150 while (gad) {
1151 if (gad->GadgetType&GTYP_SYSGADGET && gad->TopEdge==0) {
1152 if (gad->LeftEdge<0) {
1153 if (gad->LeftEdge<min) min=gad->LeftEdge;
1155 else if (gad->LeftEdge+gad->Width>max) max=gad->LeftEdge+gad->Width;
1157 gad=gad->NextGadget;
1160 scrdata_status_width=Window->Width-max+min-8-Window->WScreen->BarHBorder;
1162 else {
1163 gad=MainScreen->FirstGadget;
1165 while (gad) {
1166 if (gad->LeftEdge<min) min=gad->LeftEdge;
1167 gad=gad->NextGadget;
1170 scrdata_status_width=MainScreen->Width+min-8-MainScreen->BarHBorder;
1174 scrdata_status_xpos=2+scrdata_xoffset;
1175 scrdata_status_ypos=1+scrdata_yoffset;
1177 if (MainScreen && !staybehindWB) ScreenToFront(MainScreen);
1178 main_proc->pr_WindowPtr = (config->errorflags & ERROR_ENABLE_DOS) ? Window : (APTR)-1L;
1180 layout_menus();
1182 setupdisplay(1);
1184 initclock();
1187 status_iconified=0;
1188 if (tit==1) dostatustext(globstring[STR_WELCOME_TO_DOPUS]);
1189 else if (tit==2) dostatustext(globstring[STR_WELCOME_BACK_TO_DOPUS]);
1190 if (tit>-1 && !(status_flags&STATUS_DONEREXX)) {
1191 status_flags|=STATUS_DONEREXX;
1192 rexx_command(config->startupscript,NULL);
1194 status_configuring=0;
1196 if (pubscr) UnlockPubScreen(NULL,pubscr);
1197 return(1);
1200 void setupdisplay(all)
1201 int all;
1203 int a;
1205 drawscreen();
1206 for (a=0;a<2;a++) {
1207 if (config->generalscreenflags&SCR_GENERAL_NEWLOOKPROP /*&& system_version2*/)
1208 RefreshGList(horiz_propgad,Window,NULL,2);
1209 fixhorizprop(a);
1210 if (!all) doposhprop(a);
1212 setupgadgets();
1213 drawgadgets((all)?1:-1,0);
1214 fix_rmb_gadgets();
1215 if (config->generalscreenflags&SCR_GENERAL_TINYGADS)
1216 dolittlegads(&screen_gadgets[SCRGAD_TINYFILTER],&globstring[STR_TINY_BUTTONS][6],1);
1218 if (scr_gadget_rows) {
1219 if (config->generalscreenflags&SCR_GENERAL_GADSLIDERS) {
1220 if (scrdata_drive_width) {
1221 FixSliderPot(NULL,&drive_propgad,data_drive_offset,
1222 USEDRIVECOUNT,scr_gadget_rows,0);
1223 ShowSlider(Window,&drive_propgad);
1225 if (scr_gadget_bank_count>1) {
1226 fixgadgetprop();
1227 ShowSlider(Window,&gadget_propgad);
1230 data_drive_offset-=scr_gadget_rows;
1231 nextdrives();
1234 for (a=0;a<2;a++) {
1235 refreshwindow(a,3);
1236 doposprop(a);
1240 void drawscreen()
1242 int a;
1244 SetDrMd(main_rp,JAM1);
1246 dolittlegads(&screen_gadgets[SCRGAD_TINYBUFFERLIST],globstring[STR_TINY_BUTTONS],
1247 config->generalscreenflags&SCR_GENERAL_TINYGADS?10:4);
1249 /* Directory Windows */
1251 for (a=0;a<2;a++) {
1252 SetAPen(main_rp,screen_pens[config->filesbg].pen);
1253 rectfill(main_rp,
1254 scrdata_dispwin_xpos[a]+2,
1255 scrdata_dispwin_ypos,
1256 scrdata_dispwin_width[a],
1257 scrdata_dispwin_height);
1258 do3dbox(main_rp,
1259 scrdata_dispwin_xpos[a]+2,
1260 scrdata_dispwin_ypos,
1261 scrdata_dispwin_width[a],
1262 scrdata_dispwin_height);
1263 do3dbox(main_rp,
1264 scrdata_diskname_xpos[a]+2,
1265 scrdata_diskname_ypos,
1266 scrdata_diskname_width[a],
1267 scrdata_diskname_height-2);
1270 /* Sliders/String gadgets */
1272 for (a=0;a<2;a++) {
1273 do3dbox(main_rp,
1274 vert_propgad[a].LeftEdge-2,
1275 vert_propgad[a].TopEdge-1,
1276 config->sliderwidth+4,
1277 scrdata_prop_height+2);
1278 do3dbox(main_rp,
1279 horiz_propgad[a].LeftEdge-2,
1280 horiz_propgad[a].TopEdge-1,
1281 horiz_propgad[a].Width+4,
1282 config->sliderheight+2);
1283 Do3DStringBox(main_rp,
1284 path_strgadget[a].LeftEdge,
1285 path_strgadget[a].TopEdge,
1286 path_strgadget[a].Width,
1287 scrdata_string_height,
1288 screen_pens[config->gadgettopcol].pen,
1289 screen_pens[config->gadgetbotcol].pen);
1292 /* Arrows */
1294 doarrowgadgets(&screen_gadgets[SCRGAD_MOVEUP1],0);
1295 doarrowgadgets(&screen_gadgets[SCRGAD_MOVEDOWN1],1);
1296 doarrowgadgets(&screen_gadgets[SCRGAD_MOVELEFT1],3);
1297 doarrowgadgets(&screen_gadgets[SCRGAD_MOVERIGHT1],2);
1298 doarrowgadgets(&screen_gadgets[SCRGAD_BUFFERLEFT1],3);
1299 doarrowgadgets(&screen_gadgets[SCRGAD_BUFFERRIGHT1],2);
1301 /* Status bar */
1303 if (scrdata_status_height>0) {
1304 do3dbox(main_rp,
1305 scrdata_status_xpos,
1306 scrdata_status_ypos,
1307 scrdata_status_width,
1308 scrdata_status_height-2);
1309 SetAPen(main_rp,screen_pens[config->statusbg].pen);
1310 rectfill(main_rp,
1311 scrdata_status_xpos,
1312 scrdata_status_ypos,
1313 scrdata_status_width,
1314 scrdata_status_height-2);
1317 /* Clock bar */
1319 if (!clock_task) {
1320 SetAPen(main_rp,screen_pens[config->clockbg].pen);
1321 rectfill(main_rp,
1322 scrdata_clock_xpos,
1323 scrdata_clock_ypos,
1324 scrdata_clock_width-3,
1325 scrdata_clock_height-2);
1326 do3dbox(main_rp,
1327 scrdata_clock_xpos,
1328 scrdata_clock_ypos-1,
1329 scrdata_clock_width-3,
1330 scrdata_clock_height-2);
1333 doactive(0,0);
1335 SetAPen(main_rp,screen_pens[1].pen);
1338 struct TextFont *getfont(font,size,noprop)
1339 char *font;
1340 int *size,noprop;
1342 // BPTR lock;
1343 struct TextFont *tf;
1344 static struct TextAttr sfont={NULL,0,0,0/*FPF_DESIGNED*/};
1346 sfont.ta_Name=(STRPTR)font; sfont.ta_YSize=*size;
1347 if ((tf=OpenFont(&sfont)) && tf->tf_YSize==sfont.ta_YSize &&
1348 (!(tf->tf_Flags&FPF_PROPORTIONAL) || !noprop)) return(tf);
1349 /* if (tf) CloseFont(tf);
1350 main_proc->pr_WindowPtr=(APTR)-1;
1351 if (!(lock=Lock("FONTS:",ACCESS_READ))) {
1352 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
1353 strcpy(font,"topaz.font");
1354 *size=8;
1355 sfont.ta_YSize=8;
1356 tf=OpenFont(&sfont);
1358 else {
1359 UnLock(lock);
1361 if (!DiskfontBase || !(tf=OpenDiskFont(&sfont))) {
1362 if ((tf=OpenFont(&sfont))) *size=tf->tf_YSize;
1364 if (!tf || (tf->tf_Flags&FPF_PROPORTIONAL && noprop)) {
1365 if (tf) CloseFont(tf);
1366 strcpy(font,"topaz.font");
1367 *size=8;
1368 sfont.ta_YSize=8;
1369 // tf=OpenFont(&sfont);
1370 tf=OpenDiskFont(&sfont);
1372 /* }
1373 if (config->errorflags&ERROR_ENABLE_DOS) main_proc->pr_WindowPtr=(APTR)Window;
1375 return(tf);
1378 void allocstrings()
1380 int a;
1382 for (a=0;a<16;a++) rexx_args[a]=astring(256);
1383 str_arexx_command=astring(256);
1384 for (a=0;a<4;a++) str_select_pattern[a]=astring(80);
1385 for (a=0;a<2;a++) {
1386 rexx_pathbuffer[a]=astring(256);
1387 dopus_specialwin[a]=(struct DirectoryWindow *)astring(sizeof(struct DirectoryWindow));
1389 menu_menuitem=(struct MenuItem *)astring(MENUCOUNT*sizeof(struct MenuItem));
1390 menu_itemnames=astring(MENUCOUNT*MAXMENULENGTH);
1391 menu_intuitext=(struct IntuiText *)astring(MENUCOUNT*2*sizeof(struct IntuiText));
1392 main_gadgets=(struct Gadget *)astring((GADCOUNT/2)*sizeof(struct Gadget));
1393 drive_gadgets=(struct Gadget *)astring(6*sizeof(struct Gadget));
1394 str_space_string=astring(MAXDISPLAYLENGTH);
1395 for (a=0;a<MAXDISPLAYLENGTH-1;a++) str_space_string[a]=' ';
1396 str_last_statustext=astring(512);
1397 remember_data=(struct RememberData *)astring(sizeof(struct RememberData));
1400 char *astring(len)
1401 int len;
1403 char *foo;
1405 if (!(foo=LAllocRemember(&general_key,len,MEMF_CLEAR))) quit();
1406 return(foo);
1409 void allocdragbuffers()
1411 int a,w;
1413 freedragbuffers();
1414 drag_sprite.Depth=Window->WScreen->RastPort.BitMap->Depth;
1415 #ifdef __AROS__
1416 if (drag_sprite.Depth > 8) drag_sprite.Depth = 8;
1417 #endif
1419 a=35;
1420 w=(gettextlength(scr_font[FONT_DIRS],str_space_string,&a,0)+15);
1421 a=(scrdata_dispwin_width[0]>scrdata_dispwin_width[1])?scrdata_dispwin_width[0]:scrdata_dispwin_width[1];
1422 if (w>a) w=a;
1423 drag_sprite.Width=w/16;
1424 drag_sprite.Height=scr_font[FONT_DIRS]->tf_YSize;
1426 if (!(drag_bob_buffer=AllocRaster(drag_sprite.Width*16,drag_sprite.Height*drag_sprite.Depth)))
1427 return;
1428 if (!(drag_bob_savebuffer=AllocRaster(drag_sprite.Width*16,drag_sprite.Height*drag_sprite.Depth))) {
1429 freedragbuffers();
1430 return;
1433 InitBitMap(&drag_bob_bitmap,drag_sprite.Depth,drag_sprite.Width*16,drag_sprite.Height);
1434 for (a=0;a<drag_sprite.Depth;a++) {
1435 drag_bob_bitmap.Planes[a]=
1436 drag_bob_buffer+(RASSIZE(drag_sprite.Width*16,drag_sprite.Height)*a);
1438 for (;a<8;a++) drag_bob_bitmap.Planes[a]=NULL;
1440 InitRastPort(&drag_bob_rastport);
1441 drag_bob_rastport.BitMap=&drag_bob_bitmap;
1442 SetFont(&drag_bob_rastport,scr_font[FONT_DIRS]);
1443 SetDrMd(&drag_bob_rastport,JAM1);
1444 drag_sprite.ImageData=(WORD *)drag_bob_buffer;
1445 drag_sprite.PlanePick=(1<<drag_sprite.Depth)-1;
1446 drag_bob.SaveBuffer=(WORD *)drag_bob_savebuffer;
1449 void freedragbuffers()
1451 if (drag_bob_buffer)
1452 FreeRaster(drag_bob_buffer,drag_sprite.Width*16,drag_sprite.Height*drag_sprite.Depth);
1453 if (drag_bob_savebuffer)
1454 FreeRaster(drag_bob_savebuffer,drag_sprite.Width*16,drag_sprite.Height*drag_sprite.Depth);
1455 drag_bob_buffer=drag_bob_savebuffer=NULL;
1458 void load_palette(screen,palette)
1459 struct Screen *screen;
1460 ULONG *palette;
1462 ULONG backup_palette[98];
1463 int numcols;
1465 numcols=1<<screen->RastPort.BitMap->Depth;
1466 if (numcols>16) numcols=16;
1468 CopyMem((char *)palette,(char *)&backup_palette[1],numcols*3*sizeof(ULONG));
1469 backup_palette[0]=numcols<<16;
1470 backup_palette[(numcols*3)+1]=0;
1472 LoadRGB32(&screen->ViewPort,backup_palette);
1475 void get_palette(screen,palette)
1476 struct Screen *screen;
1477 ULONG *palette;
1479 int numcols;
1481 #ifdef __AROS__
1482 numcols=1<<((screen->RastPort.BitMap->Depth > 8) ? 8 : screen->RastPort.BitMap->Depth);
1483 #else
1484 numcols=1<<((screen->RastPort.BitMap->Depth > 4) ? 4 : screen->RastPort.BitMap->Depth);
1485 #endif
1487 GetRGB32(screen->ViewPort.ColorMap,0,numcols,palette);
1490 struct Library *open_dopus_library(name,ver)
1491 char *name;
1492 int ver;
1494 char buf[80];
1495 struct Library *lib;
1497 if ((lib=OpenLibrary(name,ver))) return(lib);
1498 FindSystemFile(name,buf,80,SYSFILE_LIBRARY);
1499 return (OpenLibrary(buf,ver));
1502 void read_configuration(def)
1503 int def;
1505 char buf[256];
1507 freedynamiccfg();
1508 get_config_file(buf,".CFG");
1509 if (def || !(readsetup(buf)))
1511 getdefaultconfig();
1513 if (LocaleBase)
1515 int i;
1517 if ((locale = OpenLocale(NULL)))
1519 for (i = 0; locale->loc_LanguageName && (locale->loc_LanguageName[i] != '.'); i++)
1520 config->language[i] = locale->loc_LanguageName[i];
1521 config->language[i] = 0;
1524 read_data_files(1);
1527 void read_data_files(fb)
1528 int fb;
1530 char buf[256];
1532 if (get_data_file(buf,"HLP",fb)) readhelp(buf);
1533 else if (get_data_file(buf,"guide",fb)) readhelp(NULL);
1535 // get_data_file(buf,"STR",fb);
1536 // readstrings(buf);
1537 readstrings("dopus4.catalog");
1540 int get_data_file(buf,suff,fb)
1541 char *buf,*suff;
1542 int fb;
1544 char temp[40];
1546 lsprintf(temp,"DO_%s.%s",config->language,suff);
1547 if (!config->language[0] || !(FindSystemFile(temp,buf,256,SYSFILE_DATA))) {
1548 if (!fb) {
1549 buf[0]=0;
1550 return(0);
1552 lsprintf(temp,"DirectoryOpus.%s",suff);
1553 FindSystemFile(temp,buf,256,SYSFILE_DATA);
1555 return(1);
1558 void get_config_file(buf,suff)
1559 char *buf,*suff;
1561 char temp[256];
1563 StrCombine(temp,str_config_basename,suff,256);
1564 if (CheckExist(temp,NULL)<0) {
1565 strcpy(buf,temp);
1566 return;
1568 if (BaseName(str_config_basename))
1569 StrCombine(temp,BaseName(str_config_basename),suff,256);
1570 if (!(FindSystemFile(temp,buf,256,SYSFILE_DATA))) {
1571 StrCombine(temp,"DirectoryOpus",suff,256);
1572 if (!(FindSystemFile(temp,buf,256,SYSFILE_DATA))) {
1573 if (CheckExist("PROGDIR:S",NULL)) StrCombine(buf,"PROGDIR:S/DirectoryOpus",suff,256);
1574 else StrCombine(buf,"S:DirectoryOpus",suff,256);
1579 void setup_draw_info()
1581 int a,b;
1582 struct DrawInfo *drinfo;
1583 struct Screen *wbscreen;
1585 // if (system_version2) {
1586 mainscreen_tags[SCREENTAGS_DISPLAYID].ti_Data=0;
1587 if ((wbscreen=LockPubScreen(NULL))) {
1588 drinfo=GetScreenDrawInfo(wbscreen);
1589 b=drinfo->dri_NumPens;
1590 if (b>NUMDRIPENS) b=NUMDRIPENS;
1591 for (a=0;a<b;a++) scr_drawinfo[a]=drinfo->dri_Pens[a];
1592 FreeScreenDrawInfo(wbscreen,drinfo);
1593 UnlockPubScreen(NULL,wbscreen);
1595 /* }
1596 else for (a=0;a<NUMDRIPENS;a++) scr_drawinfo[a]=(UWORD)~0;
1598 scr_drawinfo[SHINEPEN]=config->gadgettopcol;
1599 scr_drawinfo[SHADOWPEN]=config->gadgetbotcol;
1600 scr_drawinfo[NUMDRIPENS]=(UWORD)~0;
1603 struct Library *OpenXFDlib(void)
1605 if (xfdMasterBase == NULL)
1607 Forbid();
1608 if (FindName(&SysBase->LibList,"xfdmaster.library"))
1610 xfdMasterBase = (struct xfdMasterBase *)OpenLibrary("xfdmaster.library",38);
1611 if (((struct Library *)xfdMasterBase)->lib_Version < 38)
1613 CloseLibrary((struct Library *)xfdMasterBase);
1614 xfdMasterBase = NULL;
1617 Permit();
1619 return (struct Library *)xfdMasterBase;
1622 struct Library *OpenXADlib(void)
1624 if (xadMasterBase == NULL)
1626 Forbid();
1627 if (FindName(&SysBase->LibList,"xadmaster.library"))
1629 xadMasterBase = (struct xadMasterBase *)OpenLibrary("xadmaster.library",4);
1630 if (((struct Library *)xadMasterBase)->lib_Version < 4)
1632 CloseLibrary((struct Library *)xadMasterBase);
1633 xadMasterBase = NULL;
1636 Permit();
1638 return (struct Library *)xadMasterBase;
1640 int atoi(const char *str)
1642 LONG ret;
1644 StrToLong((STRPTR)str,&ret);
1646 return ret;