finally the biggest changes together with makefile. hardcoded flag removed.
[AROS-Contrib.git] / dopus / Program / main11.c
blob1499447fabfc89e0d4cd7f543e7ddac8a0dc35fe
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 #ifndef __AROS__
33 #include <libraries/screennotify.h>
34 #include <proto/sysinfo.h>
35 #endif
37 #define BUTPROP 1
38 #define BUTEXIT 2
40 extern UWORD __chip uniconifydata[2][20];
42 static struct AppIcon *appicon;
43 static struct AppMenuItem *appmenu;
44 static struct Image iconbutpropimage;
45 static struct PropInfo
46 iconbutpropinfo={
47 AUTOKNOB|FREEVERT|PROPNEWLOOK|PROPBORDERLESS,0,0,0,0x3000};
49 struct Image
50 uniconifyimage[2]={
51 {0,0,11,10,2,uniconifydata[0],3,0,NULL},
52 {0,0,11,10,2,uniconifydata[1],3,0,NULL}};
54 struct Gadget
55 dummybordergad={
56 NULL,-18,0,17,10,
57 GFLG_GADGHNONE|GFLG_RELRIGHT,
58 GACT_RIGHTBORDER,
59 GTYP_BOOLGADGET,
60 NULL,NULL,NULL,NULL,NULL,0,NULL},
61 iconbutpropgad={
62 &dummybordergad,-14,0,11,0,
63 GFLG_GADGHNONE|GFLG_RELRIGHT,
64 GACT_IMMEDIATE|GACT_RELVERIFY|GACT_FOLLOWMOUSE|GACT_RIGHTBORDER,
65 GTYP_PROPGADGET,
66 (APTR)&iconbutpropimage,NULL,NULL,NULL,(APTR)&iconbutpropinfo,BUTPROP,NULL},
67 iconbutexitgad={
68 &iconbutpropgad,0,0,11,10,
69 GFLG_GADGIMAGE|GFLG_GADGHIMAGE|GFLG_RELRIGHT,
70 GACT_RELVERIFY|GACT_RIGHTBORDER,
71 GTYP_BOOLGADGET,(APTR)&uniconifyimage[0],(APTR)&uniconifyimage[1],
72 NULL,NULL,NULL,BUTEXIT,NULL};
74 struct NewWindow
75 icon_win={
76 100,0,433,10,255,255,
77 ICON_IDCMP,
78 WFLG_CLOSEGADGET|WFLG_RMBTRAP|WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_NEWLOOKMENUS,
79 NULL,NULL,NULL,NULL,NULL,0,0,0,0,WBENCHSCREEN},
80 appicon_win={
81 0,0,1,1,255,255,ICON_IDCMP,
82 WFLG_BACKDROP|WFLG_BORDERLESS|WFLG_SIMPLE_REFRESH|WFLG_NOCAREREFRESH,
83 NULL,NULL,NULL,NULL,NULL,0,0,0,0,WBENCHSCREEN};
85 static int /*icon_tx,*/icon_ty,icon_len;
86 static UBYTE icon_fpen,icon_bpen;
87 static int icon_type,icon_gotclock;
88 static struct TextFont *winfont;
89 static char icontitletext[200];
90 static struct DOpusRemember *icon_key;
91 static struct MsgPort *iconify_time_port;
92 static struct timerequest iconify_timereq;
94 static struct DiskObject iconify_appicon={
95 0,0,
96 {NULL,0,0,80,41,GFLG_GADGBACKFILL,0,0,
97 (APTR)&appicon_image,NULL,NULL,NULL,NULL,NULL,NULL},
98 0,NULL,NULL,NO_ICON_POSITION,NO_ICON_POSITION,NULL,NULL,NULL};
100 void iconify(louise,buttons,banknum)
101 int louise,buttons,banknum;
103 ULONG class;
104 UWORD code,gadgetid;
105 struct DOpusDateTime dt;
106 struct Screen scrbuf,*sptr;
107 struct DrawInfo *drinfo;
109 wmes,chipc,fast,h,m,s,waitbits,
110 a,b,nheight,nwidth,buttonrows,oldrows,olddata_gadgetrow_offset,x,y,x1,y1,c,d,w,
111 fastnum,chipnum,bankcount,bankstep,menunum,itemnum,num,cdelay,
112 usage,oldusage=100;
113 char date[16],time[16],buf[50],buf1[50],buf2[50],ampm,formstring[100],*old;
114 struct dopusgadgetbanks *bank,*oldbank,**bankarray;
115 struct dopushotkey *hotkey;
116 struct dopusfuncpar par;
117 struct AppMessage *amsg;
118 struct MenuItem *item;
119 #ifndef __AROS__
120 struct SI_CpuUsage sicpu;
121 #endif
122 BOOL screennotify;
124 if (louise == 3)
126 screennotify = TRUE;
127 louise = 2;
129 else screennotify = FALSE;
131 endnotifies();
132 shutthingsdown(0/*louise*/);
134 status_iconified=1; status_flags&=~STATUS_ISINBUTTONS; cdelay=0;
135 GetWBScreen(&scrbuf);
136 nwidth=scrbuf.Width; nheight=scrbuf.Height;
137 winfont=scrbuf.RastPort.Font;
138 appicon=NULL; icon_key=NULL;
139 icon_type=config->icontype;
140 icon_gotclock=0;
142 if (/*system_version2 &&*/ (sptr=LockPubScreen(NULL))) {
143 drinfo=GetScreenDrawInfo(sptr);
144 icon_fpen=drinfo->dri_Pens[FILLTEXTPEN];
145 icon_bpen=drinfo->dri_Pens[FILLPEN];
146 FreeScreenDrawInfo(sptr,drinfo);
147 UnlockPubScreen(NULL,sptr);
149 else {
150 icon_fpen=1; icon_bpen=0;
153 oldrows=config->gadgetrows;
154 oldbank=dopus_curgadbank;
155 olddata_gadgetrow_offset=data_gadgetrow_offset;
157 if (buttons) {
158 bank=dopus_firstgadbank; bankcount=0;
159 while (bank) {
160 ++bankcount;
161 bank=bank->next;
163 if ((bankarray=LAllocRemember(&icon_key,bankcount*4,MEMF_CLEAR))) {
164 bank=dopus_firstgadbank;
165 for (a=0;a<bankcount;a++) {
166 bankarray[a]=bank;
167 bank=bank->next;
170 else bankcount=0;
171 icon_win.LeftEdge=config->iconbutx; icon_win.TopEdge=config->iconbuty;
172 icon_type&=~(ICON_NOWINDOW|ICON_APPICON);
173 if (buttons>1) {
174 buttonrows=buttons-1;
175 if (buttonrows!=2 && buttonrows!=3 && buttonrows!=6)
176 buttonrows=config->gadgetrows;
178 else buttonrows=config->gadgetrows;
179 if (buttonrows<2) buttonrows=2;
180 config->gadgetrows=buttonrows;
181 scr_gadget_rows=buttonrows;
182 bankstep=6/buttonrows;
184 else {
185 icon_win.LeftEdge=config->iconx;
186 icon_win.TopEdge=config->icony;
188 if (icon_type&ICON_APPICON) {
189 if (!WorkbenchBase ||
190 !(appmenu=AddAppMenuItemA(0,0,(UBYTE *)str_arexx_portname,appmsg_port,NULL)) ||
191 !(appicon=AddAppIconA(0,0,(UBYTE *)"Directory Opus",
192 appmsg_port,NULL,user_appicon == NULL ? &iconify_appicon : user_appicon,NULL))) {
193 icon_type&=~(ICON_APPICON);
194 if (appicon)
196 RemoveAppIcon(appicon);
197 appicon=NULL;
199 if (appmenu)
201 RemoveAppMenuItem(appmenu);
202 appmenu=NULL;
208 if (!(icon_type&(ICON_NOWINDOW|ICON_APPICON))) {
209 icon_win.Title=(STRPTR)str_space_string;
210 if (!(icon_type&(ICON_MEMORY|ICON_DATE|ICON_TIME|ICON_CPU))) {
211 if (buttons) strcpy(buf,"WW");
212 else strcpy(buf,"DirOpusWW");
214 else {
215 strcpy(buf,"W");
216 icon_gotclock=1;
217 if (icon_type&ICON_MEMORY) {
218 chipnum=getmaxmem(MEMF_CHIP/*,MEMF_ANY*/);
219 fastnum=getmaxmem(MEMF_FAST/*ANY,MEMF_CHIP*/);
220 if (icon_type&ICON_BYTES) {
221 chipnum+=3;
222 fastnum+=3;
224 if (icon_type&ICON_C_AND_F) {
225 if (fastnum<2) lsprintf(buf2,"%lc:",globstring[STR_CLOCK_MEM][0]);
226 else lsprintf(buf2,"%lc:",globstring[STR_CLOCK_CHIP][0]);
227 strcat(buf,buf2);
229 else {
230 if (fastnum<2) strcat(buf,globstring[STR_CLOCK_MEM]);
231 else strcat(buf,globstring[STR_CLOCK_CHIP]);
233 for (a=0;a<chipnum;a++) buf1[a]='8'; buf1[a]=0;
234 strcat(buf,buf1);
235 if (fastnum>1) {
236 if (icon_type&ICON_C_AND_F) lsprintf(buf2," %lc:",globstring[STR_CLOCK_FAST][0]);
237 else lsprintf(buf2," %s",globstring[STR_CLOCK_FAST]);
238 strcat(buf,buf2);
239 for (a=0;a<fastnum;a++) buf1[a]='8'; buf1[a]=0;
240 strcat(buf,buf1);
242 strcat(buf," ");
244 if (icon_type&ICON_CPU) strcat(buf,"CPU:100% ");
245 if (icon_type&ICON_DATE) strcat(buf,"88-WWW-88 ");
246 if (icon_type&ICON_TIME) {
247 strcat(buf,"88:88:88");
248 if (config->dateformat&DATE_12HOUR) strcat(buf,"P");
249 strcat(buf," ");
251 if ((icon_len=strlen(buf)) && buf[icon_len-1]!=' ') strcat(buf," ");
253 /* if (system_version2)*/ strcat(buf,"W");
256 icon_len=0;
258 icon_win.Height=scrbuf.WBorTop+winfont->tf_YSize+(/*system_version2?*/1/*:0*/);
259 icon_win.Width=dotextlength(&scrbuf.RastPort,buf,&icon_len,0);
260 icon_ty=((icon_win.Height-winfont->tf_YSize)/2)+winfont->tf_Baseline;
261 if (buttons) {
262 icon_win.Height+=buttonrows*(scr_font[FONT_ICONIFY]->tf_YSize+2)+scrbuf.WBorBottom;
263 icon_win.Width=scrbuf.Width;
264 // if (config->generalscreenflags&SCR_GENERAL_NEWLOOKMENU)
265 // icon_win.Flags|=WFLG_NEWLOOKMENUS;
266 // else icon_win.Flags&=~WFLG_NEWLOOKMENUS;
268 /*if (system_version2)*/ iconbutexitgad.LeftEdge=-14;
269 // else iconbutexitgad.LeftEdge=-16;
271 iconbutexitgad.TopEdge=scrbuf.WBorTop+winfont->tf_YSize+3;
272 dummybordergad.TopEdge=iconbutexitgad.TopEdge;
273 iconbutpropgad.TopEdge=iconbutexitgad.TopEdge+12;
274 iconbutpropgad.Height=icon_win.Height-iconbutpropgad.TopEdge-scrbuf.WBorBottom-1;
275 dummybordergad.NextGadget=NULL;
277 icon_win.FirstGadget=&iconbutexitgad;
279 else {
280 /*if (system_version2)*/ icon_win.Width+=50;
281 // else icon_win.Width+=88;
282 icon_win.FirstGadget=NULL;
285 if (icon_win.LeftEdge+icon_win.Width>nwidth)
286 icon_win.LeftEdge=nwidth-icon_win.Width;
287 if (icon_win.TopEdge+icon_win.Height>nheight)
288 icon_win.TopEdge=nheight-icon_win.Height-1;
289 if (icon_win.LeftEdge<0) icon_win.LeftEdge=0;
290 if (icon_win.TopEdge<0) icon_win.TopEdge=0;
292 if (!(Window=(struct Window *) OpenWindow(&icon_win))) goto uniconify;
293 main_rp=Window->RPort;
295 if (WorkbenchBase) dopus_appwindow=AddAppWindowA(APPWINID,0,Window,appmsg_port,NULL);
297 if (buttons) {
298 get_colour_table();
299 FixSliderBody(Window,&iconbutpropgad,(bankcount*6)/buttonrows,1,1);
300 /* if (!system_version2) {
301 SetAPen(main_rp,screen_pens[1].pen);
302 Move(main_rp,Window->Width-Window->BorderRight,Window->BorderTop);
303 Draw(main_rp,Window->Width-Window->BorderRight,Window->Height-Window->BorderBottom);
304 Move(main_rp,Window->Width-Window->BorderRight+1,Window->BorderTop);
305 Draw(main_rp,Window->Width-Window->BorderRight+1,Window->Height-Window->BorderBottom);
306 } */
307 SetFont(main_rp,scr_font[FONT_ICONIFY]);
308 scrdata_drive_width=0;
309 data_gadgetrow_offset=0;
310 if ((dopus_curgadbank=dopus_firstgadbank)) {
311 for (a=0;a<banknum;a++) {
312 if (!dopus_curgadbank->next) break;
313 dopus_curgadbank=dopus_curgadbank->next;
316 FixSliderPot(Window,&iconbutpropgad,a*bankstep,(bankcount*6)/buttonrows,1,1);
317 w=Window->Width-Window->BorderLeft-Window->BorderRight;
318 scrdata_gadget_width=w/7;
319 scrdata_gadget_xpos=((w-(scrdata_gadget_width*7))/2)+Window->BorderLeft;
320 if (scrdata_gadget_xpos<Window->BorderLeft) scrdata_gadget_xpos=Window->BorderLeft;
321 scrdata_gadget_offset=0;
322 scrdata_gadget_height=scr_font[FONT_ICONIFY]->tf_YSize+2;
323 scrdata_gadget_ypos=Window->BorderTop+1;
324 drawgadgets(1,0);
325 layout_menus();
326 status_flags|=STATUS_ISINBUTTONS;
328 else SetFont(main_rp,winfont);
330 if (!system_version2) {
331 icon_tx=30;
332 if (config->icontype&ICON_APPICON) icon_type&=~(ICON_APPICON);
335 SetDrMd(main_rp,JAM2);
336 if (icon_gotclock) {
337 if ((iconify_time_port=LCreatePort(0,0))) {
338 iconify_timereq.tr_node.io_Message.mn_Length=sizeof(iconify_timereq);
339 OpenDevice(TIMERNAME,UNIT_VBLANK,&iconify_timereq.tr_node,0);
340 iconify_timereq.tr_node.io_Message.mn_ReplyPort=iconify_time_port;
341 iconify_timereq.tr_node.io_Command=TR_ADDREQUEST;
342 iconify_timereq.tr_node.io_Flags=0;
343 iconify_timereq.tr_time.tv_secs=0;
344 iconify_timereq.tr_time.tv_micro=2;
345 SendIO(&iconify_timereq.tr_node);
347 else icon_gotclock=0;
349 else {
350 if (buttons) SetWindowTitles(Window,globstring[STR_BUTTON_STRIP],(char *)-1);
351 else SetWindowTitles(Window,"DirOpus",(char *)-1);
354 else if (icon_type&ICON_APPICON && !screennotify) Window=OpenWindowTags(&appicon_win,
355 WA_PubScreenName, (Tag)"Workbench",
356 WA_PubScreenFallBack, TRUE,
357 TAG_END);
359 if (screennotify) ReplyMsg((struct Message *)snm);
361 if (!(status_flags&STATUS_DONEREXX)) {
362 status_flags|=STATUS_DONEREXX;
363 rexx_command(config->startupscript,NULL);
366 FOREVER {
367 waitbits=0;
368 if (WorkbenchBase) {
369 if (icon_type&ICON_APPICON || dopus_appwindow)
370 waitbits|=1<<appmsg_port->mp_SigBit;
372 if (icon_gotclock) {
373 /* if (!system_version2) strcpy(formstring," ");
374 else*/ formstring[0]=0;
375 if (icon_type&ICON_MEMORY) {
376 chipc=AvailMem(MEMF_CHIP);
377 fast=AvailMem(MEMF_ANY)-chipc;
378 if (!(icon_type&ICON_BYTES)) {
379 chipc/=1024;
380 fast/=1024;
382 if (fastnum>1) {
383 if (icon_type&ICON_C_AND_F) {
384 lsprintf(buf1,"%lc:%%%ldld %lc:%%%ldld ",
385 globstring[STR_CLOCK_CHIP][0],chipnum,
386 globstring[STR_CLOCK_FAST][0],fastnum);
388 else {
389 lsprintf(buf1,"%s%%%ldld %s%%%ldld ",
390 globstring[STR_CLOCK_CHIP],chipnum,
391 globstring[STR_CLOCK_FAST],fastnum);
393 lsprintf(buf,buf1,chipc,fast);
395 else {
396 if (icon_type&ICON_C_AND_F) {
397 lsprintf(buf1,"%lc:%%%ldld ",
398 globstring[STR_CLOCK_MEM][0],chipnum);
400 else {
401 lsprintf(buf1,"%s%%%ldld ",
402 globstring[STR_CLOCK_MEM],chipnum);
404 lsprintf(buf,buf1,chipc);
406 strcat(formstring,buf);
408 #ifndef __AROS__
409 if (icon_type&ICON_CPU) {
410 if (sysinfo)
412 GetCpuUsage(sysinfo,&sicpu);
413 usage = 100 * sicpu.used_cputime_lastsec / sicpu.used_cputime_lastsec_hz;
415 else usage = getusage()/*/10*/;
417 if (! usage) usage=oldusage;
418 lsprintf(buf,"CPU:%3ld%% ",usage);
419 strcat(formstring,buf);
420 oldusage=usage;
422 #endif
423 DateStamp(&(dt.dat_Stamp));
424 initdatetime(&dt,date,time,0);
425 if (icon_type&ICON_DATE) {
426 strcat(formstring,date);
427 strcat(formstring," ");
429 if (icon_type&ICON_TIME) {
430 if (config->dateformat&DATE_12HOUR) {
431 h=dt.dat_Stamp.ds_Minute/60; m=dt.dat_Stamp.ds_Minute%60;
432 s=dt.dat_Stamp.ds_Tick/TICKS_PER_SECOND;
433 if (h>11) { ampm='P'; h-=12; }
434 else ampm='A';
435 if (h==0) h=12;
436 lsprintf(time,"%2ld:%02ld:%02ld%lc",h,m,s,ampm);
438 strcat(formstring,time);
439 strcat(formstring," ");
441 if (!cdelay) {
442 formstring[icon_len]=0;
443 iconstatustext(formstring,buttons);
445 waitbits|=1<<iconify_time_port->mp_SigBit;
447 if (Window) waitbits|=1<<Window->UserPort->mp_SigBit;
448 waitbits|=INPUTSIG_UNICONIFY|rexx_signalbit|INPUTSIG_HOTKEY|1<<snm_port->mp_SigBit;
449 if ((wmes=Wait(waitbits))&INPUTSIG_HOTKEY) {
450 if (dopus_globalhotkey==(struct dopushotkey *)-1) {
451 cleanupiconify();
452 status_iconified=0;
453 quit();
455 else if (dopus_globalhotkey==(struct dopushotkey *)-2) {
456 dopus_globalhotkey=NULL;
457 continue;
459 else if (dopus_globalhotkey) {
460 hotkey=dopus_globalhotkey; dopus_globalhotkey=NULL;
461 CopyMem((char *)&hotkey->func.which,(char *)&par,sizeof(struct dopusfuncpar));
462 par.which&=FLAG_OUTWIND|FLAG_NOQUOTE|FLAG_SHELLUP|FLAG_DOPUSUP;
463 par.which|=FLAG_ASYNC;
464 if (par.which&FLAG_OUTWIND) par.which|=FLAG_WB2F;
465 status_flags|=STATUS_FROMHOTKEY;
466 dofunctionstring(hotkey->func.function,hotkey->name,NULL,&par);
467 status_flags&=~STATUS_FROMHOTKEY;
470 #ifndef __AROS__
471 if (wmes & (1 << snm_port->mp_SigBit))
473 struct ScreenNotifyMessage *snm;
475 while (snm = (struct ScreenNotifyMessage *) GetMsg(snm_port))
477 if (snm->snm_Type == SCREENNOTIFY_TYPE_WORKBENCH)
479 switch ((ULONG)snm->snm_Value)
481 case FALSE: /* Workbench close notification */
482 if (icon_type&ICON_APPICON)
484 if (Window)
486 CloseWindow(Window);
487 Window = NULL;
490 else Signal((struct Task *)main_proc,INPUTSIG_UNICONIFY);
491 break;
492 case TRUE: /* Workbench open notification */
493 if (screennotify) Signal((struct Task *)main_proc,INPUTSIG_UNICONIFY);
494 break;
497 ReplyMsg((struct Message *) snm);
500 #endif
501 if (WorkbenchBase) {
502 if ((icon_type&ICON_APPICON || dopus_appwindow) &&
503 wmes&1<<appmsg_port->mp_SigBit) {
504 if (dopus_appwindow) ActivateWindow(Window);
505 while (amsg=(struct AppMessage *)GetMsg(appmsg_port)) {
506 if ((amsg->am_Type==AMTYPE_APPICON && amsg->am_NumArgs==0) || (amsg->am_Type==AMTYPE_APPMENUITEM)) {
507 ReplyMsg((struct Message *)amsg);
508 goto endiconify;
510 else if ((amsg->am_Type==AMTYPE_APPICON && Window) ||
511 (amsg->am_Type==AMTYPE_APPWINDOW && amsg->am_ID==APPWINID)) {
512 for (a=0;a<amsg->am_NumArgs;a++) {
513 if (amsg->am_ArgList[a].wa_Lock) {
514 if (status_flags&STATUS_ISINBUTTONS &&
515 amsg->am_MouseY>Window->BorderTop) {
516 if (dopus_curgadbank && (b=gadgetfrompos(amsg->am_MouseX,amsg->am_MouseY))!=-1) {
517 b+=data_gadgetrow_offset*7;
518 if (isvalidgad(&dopus_curgadbank->gadgets[b])) {
519 PathName(amsg->am_ArgList[a].wa_Lock,func_external_file,256);
520 if (func_external_file[0] &&
521 func_external_file[(strlen(func_external_file)-1)]==':' &&
522 !amsg->am_ArgList[a].wa_Name[0])
523 TackOn(func_external_file,"Disk.info",256);
524 else TackOn(func_external_file,amsg->am_ArgList[a].wa_Name,256);
525 if (!(CheckExist(func_external_file,NULL)))
527 StrConcat(func_external_file,".info",256);
528 if (! isicon(func_external_file)) func_external_file[0] = 0;
530 dofunctionstring(dopus_curgadbank->gadgets[b].function,
531 dopus_curgadbank->gadgets[b].name,
532 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[b].which);
533 if (!status_iconified) break;
534 cdelay=3;
535 ModifyIDCMP(Window,ICON_IDCMP);
539 else {
540 if (amsg->am_ArgList[a].wa_Name[0]) {
541 char pathbuf[256];
543 PathName(amsg->am_ArgList[a].wa_Lock,pathbuf,256);
544 strcpy(func_external_file,pathbuf);
545 TackOn(func_external_file,amsg->am_ArgList[a].wa_Name,256);
546 ftype_doubleclick(pathbuf,amsg->am_ArgList[a].wa_Name,0);
547 ModifyIDCMP(Window,ICON_IDCMP);
548 unbusy();
553 func_external_file[0]=0;
555 ReplyMsg((struct Message *)amsg);
556 if (!status_iconified) return;
560 if (wmes&rexx_signalbit) {
561 func_global_function=0;
562 rexx_dispatch(0);
563 if (func_global_function==FUNC_UNICONIFY) wmes=INPUTSIG_UNICONIFY;
564 else if (func_global_function==FUNC_QUIT) {
565 cleanupiconify();
566 status_iconified=0;
567 quit();
570 if (wmes&INPUTSIG_UNICONIFY) {
571 endiconify:
572 status_iconified=-1;
573 cleanupiconify();
574 goto uniconify;
576 if (Window && wmes&1<<Window->UserPort->mp_SigBit) {
577 while (getintuimsg()) {
578 class=IMsg->Class; code=IMsg->Code;
579 x=IMsg->MouseX; y=IMsg->MouseY;
580 if (class==IDCMP_GADGETUP || class==IDCMP_GADGETDOWN)
581 gadgetid=((struct Gadget *)IMsg->IAddress)->GadgetID;
582 ReplyMsg((struct Message *)IMsg);
583 switch (class) {
584 case IDCMP_MENUPICK:
585 if (!buttons) break;
586 Window->Flags|=RMBTRAP;
587 if (Window->MenuStrip && code!=MENUNULL) {
588 menunum=menu_real_number[MENUNUM(code)];
589 num=ITEMNUM(code);
590 item=menu_menus[menunum].FirstItem;
591 for (a=0,itemnum=0;a<num && item;a++) {
592 if (item->Flags&ITEMTEXT) ++itemnum;
593 item=item->NextItem;
595 if (item) {
596 a=(menunum*20)+itemnum;
597 if (!isvalidgad(&config->menu[a])) break;
598 dofunctionstring(config->menu[a].function,config->menu[a].name,
599 NULL,(struct dopusfuncpar *)&config->menu[a].which);
600 if (!status_iconified) return;
601 cdelay=3;
602 ModifyIDCMP(Window,ICON_IDCMP);
605 break;
606 case IDCMP_GADGETDOWN:
607 if (!buttons || gadgetid!=BUTPROP || !bankcount) break;
608 FOREVER {
609 bank=dopus_curgadbank; b=data_gadgetrow_offset;
610 data_gadgetrow_offset=GetSliderPos(&iconbutpropgad,(bankcount*6)/buttonrows,1);
611 a=data_gadgetrow_offset/bankstep;
612 data_gadgetrow_offset%=bankstep; data_gadgetrow_offset*=buttonrows;
613 dopus_curgadbank=bankarray[a];
614 if (bank!=dopus_curgadbank || data_gadgetrow_offset!=b) drawgadgets(0,0);
615 if (getintuimsg()) {
616 class=IMsg->Class;
617 ReplyMsg((struct Message *)IMsg);
618 if (class==IDCMP_MOUSEMOVE) continue;
619 if (class==IDCMP_GADGETUP) break;
621 Wait(1<<Window->UserPort->mp_SigBit);
623 FixSliderPot(Window,&iconbutpropgad,(a*bankstep)+(data_gadgetrow_offset/buttonrows),
624 (bankcount*6)/buttonrows,1,1);
625 break;
626 case IDCMP_GADGETUP:
627 if (!buttons) break;
628 if (gadgetid>=MAIN_GAD_BASE && gadgetid<MAIN_GAD_BASE+GADCOUNT) {
629 a=(gadgetid-MAIN_GAD_BASE)+(data_gadgetrow_offset*7);
630 if (!dopus_curgadbank || !(isvalidgad(&dopus_curgadbank->gadgets[a]))) break;
631 dofunctionstring(dopus_curgadbank->gadgets[a].function,
632 dopus_curgadbank->gadgets[a].name,
633 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[a].which);
634 if (!status_iconified) return;
635 cdelay=3;
636 ModifyIDCMP(Window,ICON_IDCMP);
638 else if (gadgetid==BUTEXIT) goto deiconify;
639 break;
640 case IDCMP_DISKREMOVED:
641 case IDCMP_DISKINSERTED:
642 setupchangestate();
643 break;
644 case IDCMP_CLOSEWINDOW:
645 if (!(a=simplerequest(globstring[STR_REALLY_QUIT],
646 globstring[STR_QUIT],str_cancelstring,globstring[STR_UNICONIFY],NULL))) break;
647 if (a==2) goto endiconify;
648 cleanupiconify();
649 status_iconified=0;
650 quit();
651 break;
652 case IDCMP_MOUSEBUTTONS:
653 if (code!=MENUDOWN) {
654 if (!(icon_type&(ICON_MEMORY|ICON_DATE|ICON_TIME|ICON_CPU)))
655 iconstatustext("Dir Opus",buttons);
656 break;
658 if (buttons) {
659 if (x<0 || y<Window->BorderTop ||
660 x>Window->Width || y>Window->Height) {
661 quickfixmenus();
662 break;
664 for (c=0;c<buttonrows;c++) {
665 a=42+((data_gadgetrow_offset+c)*7);
666 for (d=0;d<7;d++,a++) {
667 if (isvalidgad(&dopus_curgadbank->gadgets[a])) {
668 y1=(c*scrdata_gadget_height)+scrdata_gadget_ypos-1;
669 x1=scrdata_gadget_xpos+(d*scrdata_gadget_width);
670 if (x>=x1 && x<x1+scrdata_gadget_width && y>=y1 && y<y1+scrdata_gadget_height) {
671 if (!(dormbgadget(x1,y1,
672 &dopus_curgadbank->gadgets[a-42],
673 &dopus_curgadbank->gadgets[a]))) {
674 dofunctionstring(dopus_curgadbank->gadgets[a].function,
675 dopus_curgadbank->gadgets[a].name,
676 NULL,(struct dopusfuncpar *)&dopus_curgadbank->gadgets[a].which);
677 if (!status_iconified) return;
678 cdelay=3;
679 ModifyIDCMP(Window,ICON_IDCMP);
680 c=buttonrows;
681 break;
687 break;
689 deiconify:
690 status_iconified=-1;
691 cleanupiconify();
692 uniconify:
693 config->gadgetrows=oldrows;
694 dopus_curgadbank=oldbank; data_gadgetrow_offset=olddata_gadgetrow_offset;
695 SetUp(louise);
696 if (Window && status_publicscreen) ScreenToFront(Window->WScreen);
697 rexx_command(config->uniconscript,NULL);
698 startnotifies();
699 LFreeRemember(&icon_key);
700 return;
704 if (icon_gotclock && CheckIO(&iconify_timereq.tr_node)) {
705 WaitIO(&iconify_timereq.tr_node);
706 iconify_timereq.tr_time.tv_secs=1;
707 iconify_timereq.tr_time.tv_micro=0;
708 SendIO(&iconify_timereq.tr_node);
709 if (cdelay) {
710 if (!(--cdelay) && !system_version2) {
711 old=Window->Title;
712 SetWindowTitles(Window,str_space_string,(char *)-1);
713 SetWindowTitles(Window,old,(char *)-1);
720 void remiclock()
722 if (!(CheckIO(&iconify_timereq.tr_node))) AbortIO(&iconify_timereq.tr_node);
723 WaitIO(&iconify_timereq.tr_node);
724 CloseDevice(&iconify_timereq.tr_node);
725 LDeletePort(iconify_time_port);
728 int getmaxmem(type/*,nottype*/)
729 ULONG type/*,nottype*/;
731 // struct MemHeader *memory;
732 ULONG size=0;
733 int a;
735 Forbid();
736 memory=(struct MemHeader *)SysBase->MemList.lh_Head;
737 while (memory->mh_Node.ln_Succ) {
738 if ((!type || (memory->mh_Attributes&type)) &&
739 (!nottype || !(memory->mh_Attributes&nottype))) {
740 size+=(ULONG)((IPTR)memory->mh_Upper-(IPTR)memory->mh_Lower);
742 memory=(struct MemHeader *)memory->mh_Node.ln_Succ;
744 Permit();
746 size=AvailMem(type|MEMF_TOTAL);
747 size=(size+1023)/1024;
748 for (a=1;;a++) if (!(size/=10)) break;
749 return(a);
752 void iconstatustext(buf,buttons)
753 char *buf;
754 int buttons;
756 // HUX int a;
758 // if (system_version2) {
759 strcpy(icontitletext,buf);
760 SetWindowTitles(Window,icontitletext,(char *)-1);
761 /* }
762 else {
763 if (IntuitionBase->ActiveWindow==Window) {
764 SetAPen(main_rp,icon_fpen);
765 SetBPen(main_rp,icon_bpen);
767 else {
768 SetAPen(main_rp,0);
769 SetBPen(main_rp,1);
771 if (buttons) SetFont(main_rp,winfont);
772 a=strlen(buf);
773 Move(main_rp,icon_tx,icon_ty);
774 Text(main_rp,buf,a);
775 if (a<icon_len) Text(main_rp,str_space_string,icon_len-a);
776 if (buttons) SetFont(main_rp,scr_font[FONT_ICONIFY]);
777 } */
780 void cleanupiconify()
782 if (icon_type&ICON_APPICON) {
783 if (appicon)
785 RemoveAppIcon(appicon);
786 appicon=NULL;
788 if (appmenu)
790 RemoveAppMenuItem(appmenu);
791 appmenu=NULL;
793 if (Window) {
794 CloseWindow(Window);
795 Window=NULL;
798 else {
799 if (Window) {
800 if (status_flags&STATUS_ISINBUTTONS) {
801 free_colour_table();
802 if (WorkbenchBase && dopus_appwindow) {
803 RemoveAppWindow(dopus_appwindow);
804 dopus_appwindow=NULL;
806 config->iconbutx=Window->LeftEdge;
807 config->iconbuty=Window->TopEdge;
809 else {
810 config->iconx=Window->LeftEdge;
811 config->icony=Window->TopEdge;
814 if (icon_gotclock) remiclock();
815 if (Window) {
816 if (Window->MenuStrip) ClearMenuStrip(Window);
817 CloseWindow(Window); Window=NULL;
820 LFreeRemember(&icon_key);