remove the second -lssl in the generated Makefile so that it doesn't break the build.
[AROS-Contrib.git] / dopus / Program / tasks.c
blob2fb126170b432c69f30d1b69adb8058aa1a0ea49
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 <proto/sysinfo.h>
34 #endif
36 #ifdef __AROS__
37 AROS_UFP2(struct InputEvent *, keyhandler,
38 AROS_UFPA(struct InputEvent *, oldevent, A0),
39 AROS_UFPA(APTR, userdata, A1)
41 #endif
44 #define HOTKEY_UNICONIFY 1
45 #define HOTKEY_ABORT 3
46 #define HOTKEY_MMB 5
47 #define HOTKEY_HOTKEY 10
49 struct ProgressBar
51 int barX, barY;
52 int descY;
53 int curr,max;
54 int last_w;
55 BOOL incignore;
56 BOOL hide;
59 void progressbar(struct ProgressBar *bar);
61 #ifdef INPUTDEV_HOTKEY
62 #ifdef __MORPHOS__
63 static struct InputEvent *keyhandler(void);
65 static struct EmulLibEntry GATE_keyhandler = { TRAP_LIB, 0, (void (*)(void))keyhandler };
66 #endif
67 #endif
68 struct Gadget
69 abortopgad={
70 NULL,0,0,104,0,GFLG_GADGHCOMP,GACT_RELVERIFY,GTYP_BOOLGADGET,
71 NULL,NULL,NULL,0,NULL,0,NULL};
73 static struct NewWindow
74 progresswindow={
75 0,0,0,0,255,255,
76 IDCMP_GADGETUP|IDCMP_RAWKEY,WFLG_RMBTRAP|WFLG_ACTIVATE,
77 NULL,NULL,NULL,NULL,NULL,0,0,0,0,CUSTOMSCREEN};
79 static struct Window *pwindow;
80 static struct RastPort *prp;
81 static struct DOpusRemember *prog_key;
82 static struct ProgressBar bar[2];
83 //int prog_barx[2],prog_bary[2],prog_texty[2],prog_val[2],prog_tot[2];
84 static int prog_xoff,prog_yoff,prog_xextra,prog_yextra,prog_areax;
85 #ifdef INPUTDEV_HOTKEY
86 static struct Interrupt
87 hotkey_interrupt={
88 #if (AROS_FLAVOUR && AROS_FLAVOUR_BINCOMPAT || !defined(__AROS__))
89 {NULL,NULL,2,52,"hotkeez_port"},
90 #else
91 {NULL,NULL,"hotkeez_port",2,52},
92 #endif
93 #ifdef __MORPHOS__
94 NULL,(VOID *)&GATE_keyhandler};
95 #else
96 NULL,(VOID *)keyhandler};
97 #endif
98 #endif
99 static struct NewBroker
100 hotkey_broker={
101 NB_VERSION,
102 NULL,
103 "Directory Opus © Jonathan Potter",
104 "The most amazing program ever written",
105 0,COF_SHOW_HIDE,100,NULL,0};
107 static IX hotkey_ix={IX_VERSION};
109 void __saveds hotkeytaskcode()
111 char cxname[20];
112 int top,__unused sig,waitbits,commodity=0,command,x,run=1;
113 struct dopustaskmsg *hmsg;
114 #ifdef INPUTDEV_HOTKEY
115 struct IOStdReq *inreq;
116 #endif
117 struct MsgPort *inputport/*,*idcmpport*/;
118 struct IntuiMessage *msg;
119 ULONG class,msgid,msgtype;
120 UWORD gadgetid/*,norm_height,norm_width*/;
121 // struct IntuiMessage *dummymsg;
122 struct dopushotkey *hotkey;
123 CxObj *broker,*hotkey_filter,*mmb_filter=NULL;
124 CxMsg *cxmsg;
126 norm_height=scrdata_norm_height;
127 norm_width=scrdata_norm_width;
129 hotkeymsg_port=LCreatePort(NULL,0);
130 inputport=LCreatePort(NULL,0);
131 // idcmpport=LCreatePort(NULL,0);
133 if (CxBase
134 #ifdef _USE_SMALL_Q
135 && !(status_flags&STATUS_IANSCRAP)
136 #endif
138 strcpy(cxname,"Directory Opus");
139 if (system_dopus_runcount)
141 char tmp[8];
143 lsprintf(tmp," (%ld)",(long int)(system_dopus_runcount+1));
144 strcat(cxname,tmp);
146 hotkey_broker.nb_Name = cxname;
147 hotkey_broker.nb_Port=inputport;
148 if ((broker=CxBroker(&hotkey_broker,NULL))) {
150 /* Initialise main hotkey */
151 if ((hotkey_filter=set_dopus_filter(broker,inputport,NULL,config->hotkeycode,config->hotkeyqual,HOTKEY_UNICONIFY,1))) {
153 hotkey_ix.ix_Code=IECODE_LBUTTON;
154 hotkey_ix.ix_Qualifier=IEQUALIFIER_RBUTTON;
155 hotkey_ix.ix_QualMask=0xffff&~(IEQUALIFIER_LEFTBUTTON|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_CAPSLOCK);
156 if (set_dopus_filter(broker,inputport,"rawmouse lbutton",
157 0,0,HOTKEY_ABORT,0)) {
159 hotkey_ix.ix_Code=IECODE_RBUTTON;
160 hotkey_ix.ix_Qualifier=IEQUALIFIER_LEFTBUTTON;
161 hotkey_ix.ix_QualMask=0xffff&~(IEQUALIFIER_RBUTTON|IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_CAPSLOCK);
162 if (set_dopus_filter(broker,inputport,"rawmouse rbutton",
163 0,0,HOTKEY_ABORT,0)) {
165 if (config->hotkeyflags&HOTKEY_USEMMB) {
166 hotkey_ix.ix_Code=IECODE_MBUTTON;
167 hotkey_ix.ix_Qualifier=IEQUALIFIER_MIDBUTTON;
168 hotkey_ix.ix_QualMask=0xffff&~(IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_CAPSLOCK);
169 mmb_filter=set_dopus_filter(broker,inputport,"rawmouse midbutton",
170 0,0,HOTKEY_MMB,1);
173 add_hotkey_objects(broker,inputport,1);
174 set_hotkey(hotkey_filter,config->hotkeycode,config->hotkeyqual);
176 ActivateCxObj(broker,1);
177 commodity=1;
182 if (broker && (!commodity)) {
183 add_hotkey_objects(broker,inputport,0);
184 DeleteCxObjAll(broker);
187 #ifdef INPUTDEV_HOTKEY
188 if (!commodity) {
189 inreq=(struct IOStdReq *)LCreateExtIO(inputport,sizeof(struct IOStdReq));
190 OpenDevice("input.device",NULL,(struct IORequest *)inreq,NULL);
191 inreq->io_Data=(APTR)&hotkey_interrupt;
192 inreq->io_Command=IND_ADDHANDLER;
193 DoIO((struct IORequest *)inreq);
195 #endif
196 waitbits=1<<hotkeymsg_port->mp_SigBit/*|1<<idcmpport->mp_SigBit*/;
197 if (commodity) waitbits|=1<<inputport->mp_SigBit;
198 #ifdef INPUTDEV_HOTKEY
199 else waitbits|=INPUTSIG_UNICONIFY|INPUTSIG_HOTKEY;
200 #endif
201 while(run) {
202 sig=Wait(waitbits);
203 command=0;
204 //D(bug("signal received\n"));
206 while ((dummymsg=(struct IntuiMessage *)GetMsg(idcmpport)))
207 FreeMem(dummymsg,sizeof(struct IntuiMessage));
209 if (commodity) {
210 while ((cxmsg=(CxMsg *)GetMsg(inputport))) {
211 msgid=CxMsgID(cxmsg);
212 msgtype=CxMsgType(cxmsg);
213 ReplyMsg((struct Message *)cxmsg);
214 switch (msgtype) {
215 case CXM_IEVENT:
216 if ((command=msgid)>=HOTKEY_HOTKEY) {
217 x=command-HOTKEY_HOTKEY; command=HOTKEY_HOTKEY;
218 hotkey=dopus_firsthotkey;
219 while (x-- && hotkey) hotkey=hotkey->next;
220 dopus_globalhotkey=hotkey;
222 break;
224 case CXM_COMMAND:
225 switch (msgid) {
226 case CXCMD_KILL:
227 command=HOTKEY_HOTKEY;
228 dopus_globalhotkey=(struct dopushotkey *)-1;
229 break;
231 case CXCMD_DISABLE:
232 ActivateCxObj(broker,0);
233 break;
235 case CXCMD_ENABLE:
236 ActivateCxObj(broker,1);
237 break;
239 case CXCMD_APPEAR:
240 command=HOTKEY_UNICONIFY;
241 break;
243 case CXCMD_DISAPPEAR:
244 command=HOTKEY_HOTKEY;
245 dopus_globalhotkey=(struct dopushotkey *)-2;
246 break;
248 break;
252 #ifdef INPUTDEV_HOTKEY
253 else {
254 if (sig&INPUTSIG_UNICONIFY)
255 command=HOTKEY_UNICONIFY;
256 else if (sig&INPUTSIG_HOTKEY)
257 command=HOTKEY_HOTKEY;
259 #endif
260 switch (command) {
261 case HOTKEY_ABORT:
262 if (IntuitionBase->ActiveWindow==Window) {
263 status_haveaborted=status_rexxabort=1;
264 Signal((struct Task *)main_proc,INPUTSIG_ABORT);
266 break;
268 case HOTKEY_MMB:
269 if (!(config->hotkeyflags&HOTKEY_USEMMB)) break;
270 case HOTKEY_UNICONIFY:
271 if (status_configuring==-1) break;
272 if (status_iconified==1) Signal((struct Task *)main_proc,INPUTSIG_UNICONIFY);
273 else if (status_iconified==0) {
274 if (MainScreen) {
275 if (!status_configuring && config->screenflags&SCRFLAGS_HALFHEIGHT)
276 top=main_scr.TopEdge;
277 else top=0;
279 if ((IntuitionBase->FirstScreen==MainScreen) &&
280 (MainScreen->TopEdge==top) &&
281 (!IntuitionBase->ActiveWindow || (IntuitionBase->ActiveWindow->WScreen==MainScreen)))
283 ScreenToBack(MainScreen);
284 if (Window->Parent && Window->Parent->WScreen==IntuitionBase->FirstScreen)
285 ActivateWindow(Window->Parent);
286 else ActivateWindow(IntuitionBase->FirstScreen->FirstWindow);
288 else
290 struct Window *window;
292 ScreenToFront(MainScreen);
293 if (MainScreen->FirstWindow==ansiread_window) window=Window;
294 else window=MainScreen->FirstWindow;
296 if (!(window->Flags&WFLG_BACKDROP)) WindowToFront(window);
297 ActivateWindow(window);
299 MoveScreen(MainScreen,0,top-MainScreen->TopEdge);
301 else {
302 if (IntuitionBase->ActiveWindow==Window &&
303 IntuitionBase->FirstScreen==Window->WScreen &&
304 Window->WScreen->LayerInfo.top_layer==Window->RPort->Layer) {
305 WindowToBack(Window);
306 if (Window->Parent) ActivateWindow(Window->Parent);
308 else {
309 ScreenToFront(Window->WScreen);
310 WindowToFront(Window);
311 ActivateWindow(Window);
315 break;
317 case HOTKEY_HOTKEY:
318 if (!status_configuring) Signal((struct Task *)main_proc,INPUTSIG_HOTKEY);
319 break;
322 if (pwindow) {
323 while ((msg=(struct IntuiMessage *)GetMsg(pwindow->UserPort))) {
324 if ((class=msg->Class)==IDCMP_GADGETUP)
325 gadgetid=((struct Gadget *)msg->IAddress)->GadgetID;
326 ReplyMsg((struct Message *)msg);
327 if (class==IDCMP_GADGETUP && gadgetid==0) {
328 status_haveaborted=status_rexxabort=1;
329 Signal((struct Task *)main_proc,INPUTSIG_ABORT);
334 while ((hmsg=(struct dopustaskmsg *)GetMsg(hotkeymsg_port))) {
336 #define BAR_ID (hmsg->flag)
338 switch (hmsg->command) {
339 case PROGRESS_UPDATE:
340 if (pwindow) {
341 //D(bug("UPDATE: BAR_ID=%ld\n",BAR_ID));
342 if (hmsg->value>-1)
344 bar[BAR_ID].curr = hmsg->value;
345 bar[BAR_ID].max = hmsg->total;
347 progressbar(&bar[BAR_ID]);
349 if (bar[BAR_ID].hide) break;
350 if (BAR_ID==0 || hmsg->data)
351 progresstext(bar[BAR_ID].descY,hmsg->value,hmsg->total,hmsg->data);
353 break;
355 case PROGRESS_INCREASE:
356 if (pwindow) {
357 if (bar[BAR_ID].incignore) break;
359 //D(bug("INCREASE: BAR_ID=%ld\n",BAR_ID));
360 bar[BAR_ID].curr += hmsg->value;
361 if (bar[BAR_ID].curr > bar[BAR_ID].max) bar[BAR_ID].curr = bar[BAR_ID].max;
363 progressbar(&bar[BAR_ID]);
364 if (bar[BAR_ID].hide) break;
365 progresstext(bar[BAR_ID].descY,bar[BAR_ID].curr,bar[BAR_ID].max,NULL);
367 break;
369 case PROGRESS_OPEN:
370 if (!pwindow) {
371 openprogresswindow(hmsg->data,hmsg->value,hmsg->total,BAR_ID);
372 if (pwindow)
374 SetBusyPointer(pwindow);
375 waitbits |= 1<<pwindow->UserPort->mp_SigBit;
378 break;
380 case PROGRESS_CLOSE:
381 if (pwindow) {
382 waitbits &= ~(1<<pwindow->UserPort->mp_SigBit);
383 CloseWindow(pwindow);
384 pwindow=NULL;
386 LFreeRemember(&prog_key);
387 break;
389 case TASK_QUIT:
390 run = 0;
391 break;
393 case HOTKEY_HOTKEYCHANGE:
394 if (commodity) {
395 set_hotkey(hotkey_filter,config->hotkeycode,config->hotkeyqual);
397 if (config->hotkeyflags&HOTKEY_USEMMB) {
398 if (!mmb_filter) {
399 hotkey_ix.ix_Code=IECODE_MBUTTON;
400 hotkey_ix.ix_Qualifier=IEQUALIFIER_MIDBUTTON;
401 hotkey_ix.ix_QualMask=0xffff&~(IEQUALIFIER_RELATIVEMOUSE|IEQUALIFIER_CAPSLOCK);
402 mmb_filter=set_dopus_filter(broker,inputport,"rawmouse midbutton",
403 0,0,HOTKEY_MMB,1);
406 else if (mmb_filter) {
407 DeleteCxObjAll(mmb_filter);
408 mmb_filter=NULL;
411 break;
413 case HOTKEY_KILLHOTKEYS:
414 if (commodity) add_hotkey_objects(broker,inputport,0);
415 break;
417 case HOTKEY_NEWHOTKEYS:
418 if (commodity) add_hotkey_objects(broker,inputport,1);
419 break;
421 ReplyMsg((struct Message *)hmsg);
425 if (commodity) {
426 D(bug("Removing commodity objects\n"));
427 add_hotkey_objects(broker,inputport,0);
428 DeleteCxObjAll(broker);
429 while ((cxmsg=(CxMsg *)GetMsg(inputport)))
430 ReplyMsg((struct Message *)cxmsg);
432 #ifdef INPUTDEV_HOTKEY
433 else {
434 inreq->io_Data=(APTR)&hotkey_interrupt;
435 inreq->io_Command=IND_REMHANDLER;
436 DoIO((struct IORequest *)inreq);
437 CloseDevice((struct IORequest *)inreq);
438 LDeleteExtIO((struct IORequest *)inreq);
440 #endif
441 if (pwindow) CloseWindow(pwindow);
442 LFreeRemember(&prog_key);
443 LDeletePort(inputport);
444 // ReplyMsg((struct Message *)hmsg);
445 LDeletePort(hotkeymsg_port);
446 // LDeletePort(idcmpport);
447 Wait(0);
450 void add_hotkey_objects(broker,port,add)
451 CxObj *broker;
452 struct MsgPort *port;
453 int add;
455 static CxObj **filter_table;
456 static int hotkey_count;
457 struct dopushotkey *hotkey;
458 int a;
460 if (filter_table) {
461 for (a = 0; a < hotkey_count; a++) DeleteCxObjAll(filter_table[a]);
462 FreeMem(filter_table,hotkey_count*sizeof(CxObj *));
463 filter_table = NULL;
466 if (add == 0) return;
468 for (hotkey = dopus_firsthotkey, hotkey_count = 0; hotkey; hotkey = hotkey->next)
469 hotkey_count++;
470 if (hotkey_count==0) return;
472 filter_table = AllocMem(hotkey_count*sizeof(CxObj *),MEMF_CLEAR);
473 if (filter_table == NULL) return;
475 for (a = 0, hotkey = dopus_firsthotkey; hotkey; hotkey = hotkey->next, a++)
476 filter_table[a] = set_dopus_filter(broker,port,NULL,
477 hotkey->code,hotkey->qualifier,
478 HOTKEY_HOTKEY+a,1);
481 CxObj *set_dopus_filter(broker,port,string,code,qual,command,translate)
482 CxObj *broker;
483 struct MsgPort *port;
484 char *string;
485 UWORD code,qual;
486 int command;
487 int translate;
489 CxObj *filter;
491 if ((filter=CxFilter(string))) {
492 if (!string) {
493 set_hotkey(filter,code,qual);
495 hotkey_ix.ix_Class=IECLASS_RAWKEY;
496 if (code==(UWORD)~0) {
497 hotkey_ix.ix_Code=0;
498 hotkey_ix.ix_CodeMask=0;
500 else {
501 hotkey_ix.ix_Code=code;
502 hotkey_ix.ix_CodeMask=0xff;
504 hotkey_ix.ix_Qualifier=qual&VALID_QUALIFIERS;
505 hotkey_ix.ix_QualMask=VALID_QUALIFIERS;
508 else {
509 hotkey_ix.ix_Class=IECLASS_RAWMOUSE;
510 hotkey_ix.ix_CodeMask=0xff;
511 hotkey_ix.ix_QualSame=0;
512 SetFilterIX(filter,&hotkey_ix);
514 AttachCxObj(broker,filter);
515 AttachCxObj(filter,CxSender(port,command));
516 if (translate) AttachCxObj(filter,CxTranslate(NULL));
518 return(filter);
520 return(NULL);
523 void set_hotkey(filter,code,qual)
524 CxObj *filter;
525 UWORD code,qual;
527 if (filter) {
528 hotkey_ix.ix_Class=IECLASS_RAWKEY;
529 if (qual==0 && code==(UWORD)~0) {
530 hotkey_ix.ix_Code=0xffff;
531 hotkey_ix.ix_CodeMask=0xffff;
532 // hotkey_ix.ix_Qualifier=0;
533 hotkey_ix.ix_Qualifier=0xffff;
535 else {
536 if (code==(UWORD)~0) {
537 hotkey_ix.ix_Code=0;
538 hotkey_ix.ix_CodeMask=0;
540 else {
541 hotkey_ix.ix_Code=code;
542 hotkey_ix.ix_CodeMask=0xff;
544 hotkey_ix.ix_Qualifier=qual&VALID_QUALIFIERS;
545 hotkey_ix.ix_QualMask=VALID_QUALIFIERS;
547 SetFilterIX(filter,&hotkey_ix);
551 void openprogresswindow(title,value,total,flag)
552 char *title;
553 int value,total,flag;
555 struct TextFont *font;
556 char *gadtxt[] = { globstring[STR_ABORT], NULL };
557 int a,incignore = 0;
559 if (flag & 0x80)
561 incignore = 1;
562 flag &= ~0x80;
563 D(bug("PROGRESS_INCREASE commands will be ignored\n"));
566 if (config->generalscreenflags&SCR_GENERAL_REQDRAG) {
567 prog_xoff=Window->WScreen->WBorLeft+2;
568 prog_yoff=Window->WScreen->WBorTop+Window->WScreen->Font->ta_YSize+2;
569 prog_xextra=prog_xoff+Window->WScreen->WBorRight-2;
571 else {
572 prog_xoff=2;
573 prog_yoff=1;
574 prog_xextra=0;
577 progresswindow.Width=384+(scr_font[FONT_REQUEST]->tf_XSize*8)+prog_xextra;
579 if (progresswindow.Width>Window->WScreen->Width) {
580 font=scr_font[FONT_GENERAL];
581 progresswindow.Width=432;
582 if (config->generalscreenflags&SCR_GENERAL_REQDRAG)
583 progresswindow.Width+=prog_xextra;
585 else font=scr_font[FONT_REQUEST];
587 progresswindow.Height=(font->tf_YSize*5)+22;
588 if (flag) {
589 progresswindow.Height+=(font->tf_YSize*2)+8;
590 prog_yextra=(font->tf_YSize*2)+8;
592 else prog_yextra=0;
594 if (config->generalscreenflags&SCR_GENERAL_REQDRAG) {
595 progresswindow.Height+=prog_yoff+Window->WScreen->WBorBottom-1;
596 progresswindow.Flags|=WFLG_DRAGBAR|WFLG_DEPTHGADGET;
597 progresswindow.Title=title;
599 else {
600 progresswindow.Flags|=WFLG_BORDERLESS;
601 progresswindow.Title=NULL;
604 centerwindow(&progresswindow);
605 if (!(pwindow=OpenWindow(&progresswindow))) return;
606 prp=pwindow->RPort;
607 setupwindreq(pwindow);
608 SetFont(prp,font);
610 Do3DBox(prp,
611 26+prog_xoff,
612 6+prog_yoff,
613 pwindow->Width-prog_xextra-56,
614 (font->tf_YSize*4)+prog_yextra,
615 screen_pens[config->gadgetbotcol].pen,
616 screen_pens[config->gadgettopcol].pen);
617 SetAPen(prp,screen_pens[config->requestfg].pen);
619 abortopgad.LeftEdge=(pwindow->Width-abortopgad.Width)/2;
620 abortopgad.Height=font->tf_YSize+4;
621 abortopgad.TopEdge=pwindow->Height-pwindow->BorderBottom-9-font->tf_YSize;
622 AddGadgetBorders(&prog_key,
623 &abortopgad,1,
624 screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
625 AddGadgets(pwindow,
626 &abortopgad,
627 gadtxt,
629 screen_pens[config->gadgettopcol].pen,
630 screen_pens[config->gadgetbotcol].pen,1);
632 SetAPen(prp,screen_pens[0].pen);
633 SetDrMd(prp,JAM2);
634 RectFill(prp,
635 26+prog_xoff,
636 6+prog_yoff,
637 (prog_areax=prog_xoff+pwindow->Width-prog_xextra-31),
638 prog_yoff+(font->tf_YSize*4)+prog_yextra+5);
640 for (a=0;a<2;a++) {
641 bar[a].last_w = 0;
642 bar[a].curr = value;
643 bar[a].max = total;
644 bar[a].incignore = incignore;
645 bar[a].hide = (a == 0) ? 0 : !flag;
646 bar[a].barX=(((pwindow->Width-356)/2)+28)-font->tf_XSize;
647 bar[a].barY=font->tf_YSize+3+prog_yoff;
648 if (a==0) bar[a].barY += prog_yextra+3;
650 if (! bar[a].hide)
652 Do3DBox(prp,
653 bar[a].barX,bar[a].barY,
654 300,font->tf_YSize,
655 screen_pens[config->gadgetbotcol].pen,
656 screen_pens[config->gadgettopcol].pen);
658 bar[a].descY=bar[a].barY+font->tf_YSize+(font->tf_YSize/2)+font->tf_Baseline;
660 SetAPen(prp,screen_pens[1].pen);
661 SetBPen(prp,screen_pens[0].pen);
662 Move(prp,bar[a].barX-(TextLength(prp,"0% ",3))-4,bar[a].barY+font->tf_Baseline);
663 Text(prp,"0%",2);
664 Move(prp,bar[a].barX+302+font->tf_XSize,bar[a].barY+font->tf_Baseline);
665 Text(prp,"100%",4);
667 if (a==0) progresstext(bar[a].descY,value,total,NULL);
668 progressbar(&bar[a]);
673 void progresstext(y,val,total,text)
674 int y,val,total;
675 char *text;
677 char buf[80],*ptr;
678 int x,y1,len;
680 D(bug("progresstext(Y=%ld,V=%ld,Vmax=%ld,%s)\n",y,val,total,text?text:"<NULL>"));
681 if (val==-1) ptr = globstring[total?STR_ABORTED:STR_COMPLETED];
682 else {
683 if (text) LStrnCpy(buf,text,(pwindow->Width-prog_xextra-56)/prp->Font->tf_XSize);
684 else lsprintf(buf,globstring[STR_REMAINING],val,total);
685 ptr=buf;
687 x=26+((pwindow->Width-prog_xextra-56-TextLength(prp,ptr,(len=strlen(ptr))))/2)+prog_xoff;
688 y1=y-prp->Font->tf_Baseline;
690 if (x>prog_xoff+26) {
691 SetAPen(prp,screen_pens[0].pen);
692 RectFill(prp,
693 prog_xoff+26,
695 x-1,
696 y1+prp->Font->tf_YSize);
699 SetAPen(prp,screen_pens[1].pen);
700 Move(prp,x,y);
701 Text(prp,ptr,len);
703 if (prp->cp_x<=prog_areax) {
704 SetAPen(prp,screen_pens[0].pen);
705 RectFill(prp,
706 prp->cp_x,
708 prog_areax-1,
709 y1+prp->Font->tf_YSize);
711 D(bug("progresstext() ends here\n"));
714 void progressbar(struct ProgressBar *bar)
716 int w;
717 BOOL draw;
719 if (bar->hide) return;
720 D(bug("progressbar(Y=%ld,V=%ld,Vmax=%ld)\n",bar->barY,bar->curr,bar->max));
721 if (bar->curr>0) {
722 float f=(float)(bar->curr)/(float)(bar->max);
724 if ((w=(int)(300*f))>300) w=300;
725 else if (w<1) w=1;
726 draw = (w != bar->last_w);
727 SetAPen(prp,screen_pens[3].pen);
729 else {
730 draw=TRUE;
731 w=300;
732 SetAPen(prp,screen_pens[0].pen);
734 if (draw)
736 RectFill(prp,bar->barX,bar->barY,bar->barX+w-1,bar->barY+prp->Font->tf_YSize-1);
737 bar->last_w = w;
739 D(bug("progressbar() ends here\n"));
742 #ifdef INPUTDEV_HOTKEY
743 #ifdef __MORPHOS__
744 struct InputEvent *keyhandler(void)
746 struct InputEvent *oldevent = (struct InputEvent *)REG_A0;
747 // APTR userdata = (APTR)REG_A1;
748 #else
749 #ifdef __AROS__
750 AROS_UFH2(struct InputEvent *, keyhandler,
751 AROS_UFHA(struct InputEvent *, oldevent, A0),
752 AROS_UFHA(APTR, userdata, A1)
755 AROS_USERFUNC_INIT
756 #else
757 struct InputEvent * __saveds keyhandler(register struct InputEvent *oldevent __asm("a0"),register APTR userdata __asm("a1"))
759 #endif
760 #endif
762 int wakeup=0;
763 struct dopushotkey *hotkey;
765 if (oldevent->ie_Class==IECLASS_RAWKEY) {
766 if ((config->hotkeycode==(UWORD)~0 || oldevent->ie_Code==config->hotkeycode) &&
767 (!config->hotkeyqual || (oldevent->ie_Qualifier&VALID_QUALIFIERS)==config->hotkeyqual))
768 wakeup=1;
769 else {
770 hotkey=dopus_firsthotkey;
771 while (hotkey) {
772 if (oldevent->ie_Code==hotkey->code &&
773 (oldevent->ie_Qualifier&VALID_QUALIFIERS)==hotkey->qualifier) {
774 dopus_globalhotkey=hotkey;
775 Signal(hotkey_task,INPUTSIG_HOTKEY);
776 oldevent->ie_Class=IECLASS_NULL;
777 break;
779 hotkey=hotkey->next;
783 else if (oldevent->ie_Class==IECLASS_RAWMOUSE) {
784 if ((oldevent->ie_Code&~IECODE_UP_PREFIX)==IECODE_LBUTTON) {
785 if (oldevent->ie_Qualifier&IEQUALIFIER_RBUTTON) wakeup=2;
787 else if (oldevent->ie_Code==IECODE_RBUTTON &&
788 oldevent->ie_Qualifier&IEQUALIFIER_LEFTBUTTON) wakeup=2;
789 else if (config->hotkeyflags&HOTKEY_USEMMB &&
790 oldevent->ie_Code==IECODE_MBUTTON) wakeup=1;
792 if (wakeup) {
793 if (wakeup==1 && hotkey_task) {
794 Signal(hotkey_task,INPUTSIG_UNICONIFY);
795 oldevent->ie_Class=IECLASS_NULL;
797 else if (wakeup==2) {
798 if (IntuitionBase->ActiveWindow==Window) {
799 status_haveaborted=status_rexxabort=1;
800 Signal((struct Task *)main_proc,INPUTSIG_ABORT);
804 return(oldevent);
806 #ifdef __AROS__
807 AROS_USERFUNC_EXIT
808 #endif
810 #endif
812 static char *Kstr = "K ";
814 void __saveds clocktask()
816 ULONG chipc,fast,wmes,h,m,s,/*secs,micro,*/cx,sig,cy,len,ct,chipnum,fastnum,a,active=1,usage;
817 UWORD clock_width,clock_height,scr_height;
818 char buf[160],date[20],time[20],formstring[160],memstring[160],ampm;
819 struct MsgPort *clock_time_port;
820 struct timerequest ctimereq;
821 struct DOpusDateTime datetime = {0};
822 struct dopustaskmsg *cmsg;
823 struct RastPort clock_rp;
824 #ifndef __AROS__
825 struct SI_CpuUsage sicpu;
826 #endif
828 Forbid();
829 CopyMem((char *)main_rp,(char *)&clock_rp,sizeof(struct RastPort));
830 SetDrawModes(&clock_rp,config->clockfg,config->clockbg,JAM2);
831 SetFont(&clock_rp,scr_font[FONT_CLOCK]);
832 scr_height=scrdata_height+scrdata_yoffset;
833 clock_width=scrdata_clock_width;
834 clock_height=scrdata_clock_height;
835 ct=scr_height-(clock_height-1);
836 cy=scrdata_clock_ypos+scr_font[FONT_CLOCK]->tf_Baseline-1;
837 Permit();
839 clockmsg_port=LCreatePort(NULL,0);
840 clock_time_port=LCreatePort(0,0);
842 OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)&ctimereq,0);
843 ctimereq.tr_node.io_Message.mn_ReplyPort=clock_time_port;
844 ctimereq.tr_node.io_Command=TR_ADDREQUEST;
845 ctimereq.tr_node.io_Flags=0;
846 ctimereq.tr_time.tv_secs=0;
847 ctimereq.tr_time.tv_micro=2;
848 SendIO(&ctimereq.tr_node);
850 chipnum=getmaxmem(MEMF_CHIP/*,MEMF_ANY*/);
851 fastnum=getmaxmem(MEMF_FAST/*ANY,MEMF_CHIP*/);
852 a=getmaxmem(MEMF_ANY/*,MEMF_ANY*/);
854 m = (config->scrclktype&SCRCLOCK_BYTES)?3:0;
855 s = (config->scrclktype&SCRCLOCK_BYTES)?1:0;
857 if (config->scrclktype&SCRCLOCK_C_AND_F) {
858 lsprintf(memstring,"%lc:%%-%ldld%s",globstring[STR_CLOCK_CHIP][0],(long int)(chipnum+m),Kstr+s);
859 if (fastnum>1) {
860 lsprintf(memstring+strlen(memstring),"%lc:%%-%ldld%s",globstring[STR_CLOCK_FAST][0],(long int)(fastnum+m),Kstr+s);
861 lsprintf(memstring+strlen(memstring),"%lc:%%-%ldld%s",globstring[STR_CLOCK_TOTAL][0],(long int)(a+m),Kstr+s);
864 else {
865 lsprintf(memstring,"%s%%-%ldld%s",globstring[STR_CLOCK_CHIP],(long int)(chipnum+m),Kstr+s);
866 if (fastnum>1) {
867 lsprintf(memstring+strlen(memstring),"%s%%-%ldld%s",globstring[STR_CLOCK_FAST],(long int)(fastnum+m),Kstr+s);
868 lsprintf(memstring+strlen(memstring),"%s%%-%ldld%s",globstring[STR_CLOCK_TOTAL],(long int)(a+m),Kstr+s);
872 if (!(config->scrclktype&(SCRCLOCK_MEMORY|SCRCLOCK_CPU|SCRCLOCK_DATE|SCRCLOCK_TIME)))
873 lsprintf(formstring,"Directory Opus Version %s Compiled %s %s",
874 str_version_string,comp_time,comp_date);
876 sig = 1<<clock_time_port->mp_SigBit | 1<<clockmsg_port->mp_SigBit;
878 FOREVER {
879 wmes=Wait(sig);
880 if (wmes&1<<clockmsg_port->mp_SigBit) {
881 while ((cmsg=(struct dopustaskmsg *)GetMsg(clockmsg_port))) {
882 switch (cmsg->command) {
883 case TASK_QUIT:
884 if (!(CheckIO(&ctimereq.tr_node)))
885 AbortIO(&ctimereq.tr_node);
886 WaitIO(&ctimereq.tr_node);
887 CloseDevice((struct IORequest *)&ctimereq);
888 LDeletePort(clock_time_port);
889 LDeletePort(clockmsg_port); clockmsg_port=NULL;
890 ReplyMsg((struct Message *)cmsg);
891 // Wait(0);
892 Forbid();
893 return;
894 case CLOCK_ACTIVE:
895 active=cmsg->value;
896 break;
898 ReplyMsg((struct Message *)cmsg);
901 if (wmes&1<<clock_time_port->mp_SigBit) {
902 // if (CheckIO((struct IORequest *)&ctimereq.tr_node)) {
903 // WaitIO((struct IORequest *)&ctimereq.tr_node);
904 if (active && !(Window->Flags&WFLG_MENUSTATE)) {
905 if (scr_height>ct+1) {
906 if (config->scrclktype&(SCRCLOCK_MEMORY|SCRCLOCK_CPU|SCRCLOCK_DATE|SCRCLOCK_TIME)) {
907 formstring[0]=0;
908 if (config->scrclktype&SCRCLOCK_MEMORY) {
909 chipc=AvailMem(MEMF_CHIP);
910 fast=AvailMem(MEMF_FAST/*ANY*/)/*-chipc*/;
911 if (!(config->scrclktype&SCRCLOCK_BYTES))
913 chipc/=1024;
914 fast/=1024;
916 /*if (fastnum>1)*/ lsprintf(buf,memstring,chipc,fast,chipc+fast);
917 // else lsprintf(buf,memstring,chipc);
918 strcat(formstring,buf);
920 if (config->scrclktype&SCRCLOCK_CPU) {
921 if (sysinfo)
923 #ifndef __AROS__
924 GetCpuUsage(sysinfo,&sicpu);
925 usage = 100 * sicpu.used_cputime_lastsec / sicpu.used_cputime_lastsec_hz;
926 #endif
928 else usage = getusage()/*/10*/;
930 lsprintf(buf,"CPU:%3ld%% ",(long int)usage);
931 strcat(formstring,buf);
933 if (config->scrclktype&(SCRCLOCK_DATE|SCRCLOCK_TIME)) {
934 DateStamp(&(datetime.dat_Stamp));
935 initdatetime(&datetime,date,time,0);
937 if (config->scrclktype&SCRCLOCK_DATE) {
938 lsprintf(buf,"%-9s ",date);
939 strcat(formstring,buf);
941 if (config->scrclktype&SCRCLOCK_TIME) {
942 if (config->dateformat&DATE_12HOUR) {
943 h=datetime.dat_Stamp.ds_Minute/60; m=datetime.dat_Stamp.ds_Minute%60;
944 s=datetime.dat_Stamp.ds_Tick/TICKS_PER_SECOND;
945 if (h>11) { ampm='P'; h-=12; }
946 else ampm='A';
947 if (h==0) h=12;
948 lsprintf(time,"%2ld:%02ld:%02ld%lc",(long int)h,(long int)m,(long int)s,ampm);
950 strcat(formstring,time);
954 len=strlen(formstring);
955 if (len>1 && formstring[len-2]==' ') len-=2;
956 cx=(clock_width-dotextlength(&clock_rp,formstring,(int *)&len,clock_width-4))/2;
957 cx+=scrdata_clock_xpos;
958 if (cx<scrdata_clock_xpos) cx=scrdata_clock_xpos;
960 SetAPen(&clock_rp,screen_pens[config->clockfg].pen);
961 Move(&clock_rp,cx,cy);
962 Text(&clock_rp,formstring,len);
963 SetAPen(&clock_rp,screen_pens[config->clockbg].pen);
965 if (cx>scrdata_clock_xpos)
966 RectFill(&clock_rp,scrdata_clock_xpos,ct,cx-1,scr_height-2);
967 if (clock_rp.cp_x<clock_width-1)
968 RectFill(&clock_rp,clock_rp.cp_x,ct,clock_width-2,scr_height-2);
971 ctimereq.tr_time.tv_secs=1;
972 ctimereq.tr_time.tv_micro=0;
973 SendIO(&ctimereq.tr_node);