2 #define USHORT unsigned short
3 #include <intuition/iobsolete.h>
5 /*********************************************************/
6 /* Programmname : WindowTool */
7 /* Autor : Klaas Hermanns */
8 /* Aktuelle Version : 1.00 */
9 /* Erstellungsdatum : 25-05-92 */
10 /* Compileranweisungen : lmk lmkfile */
11 /*********************************************************/
12 #define VERSIONSTRING "1.00"
13 #define DATESTRING __DATE__" "__TIME__
17 #include <exec/exec.h>
18 #include <exec/types.h>
19 #include <graphics/displayinfo.h>
20 #include <graphics/text.h>
21 #include <graphics/clip.h>
22 #include <dos/datetime.h>
24 #include <dos/dosextens.h>
25 #include <intuition/intuitionbase.h>
26 #include <intuition/intuition.h>
27 #include <intuition/screens.h>
28 #include <intuition/gadgetclass.h>
29 #include <libraries/commodities.h>
30 #include <libraries/gadtools.h>
31 #include <libraries/asl.h>
32 #include <libraries/reqtools.h>
33 #include <proto/exec.h>
34 #include <proto/dos.h>
35 #include <proto/intuition.h>
36 #include <proto/gadtools.h>
37 #include <proto/asl.h>
38 #include <proto/alib.h>
39 #include <proto/commodities.h>
40 #include <proto/icon.h>
41 #include <proto/reqtools.h>
42 #include <workbench/startup.h>
43 #include <workbench/workbench.h>
44 #include <aros/debug.h>
46 #define DEFAULTPRIORITY 21
58 #define GD_Gadget10 10
59 #define GD_Gadget11 11
60 #define GD_GadgetSave 50 /* Save */
61 #define GD_GadgetHide 51 /* Hide */
62 #define GD_GadgetQuit 52 /* Quit */
63 #define GD_GadgetCancel 53 /* Cancel */
65 extern void activetofront(void);
66 extern void closewindow(void);
67 extern void bigwindow(void);
68 extern void smallwindow(void);
69 extern void zipwindow(void);
70 extern void activatefront(void);
71 extern void worktofront(void);
73 extern void checkstartup(int,char **,struct WBStartup
*);
75 extern int windowopen
;
76 extern struct Window
*Wnd
;
77 extern struct Screen
*Scr
;
78 extern APTR VisualInfo
;
79 extern struct Gadget
*GList
;
80 extern struct Gadget
*Gadgets
[14];
81 extern struct Menu
*Menus
;
82 extern long InitStuff(void);
83 extern void CleanStuff(void);
84 extern struct IntuiText IText
[];
85 extern char windowtitle
[];
89 struct Library
*CxBase
;
90 extern struct ExecBase
*SysBase
;
91 struct IntuitionBase
*IntuitionBase
;
92 struct Library
*GadToolsBase
;
93 struct Library
*AslBase
;
94 struct ReqToolsBase
*ReqToolsBase
;
95 struct GfxBase
*GfxBase
;
96 struct Library
*IconBase
;
98 extern struct WBStartup
*WBenchMsg
;
104 void switchstate(void);
108 BOOL state
=0; /* Status 0=Normal,~0=Dauerabfrage */
110 #define NEWSETTINGSFLAG 2
112 /* Werte für Commoditie */
115 CxObj
*broker
,*filter
[KEYNUMMER
];
120 "WindowTool V1.0 by Klaas Hemanns .",
121 "Just a nice programm ...",
122 NBU_NOTIFY
|NBU_UNIQUE
,COF_SHOW_HIDE
,DEFAULTPRIORITY
,0,0
125 /* Werte für Fensterabfrage */
126 struct IntuiMessage
*mes
; /* Erhaltene Message */
127 long class; /* Message Class */
128 short code
; /* Message Code */
131 ULONG waitsignals
; /* Signale, auf die gewartet werden */
133 char oldkeys
[KEYNUMMER
][256]; /* Alte Tastenkombinationen (werden beim */
134 /* Öffnen des Windows neu gesetzt */
136 char keys
[KEYNUMMER
][256]= /* aktuelle Tastenkombinationen */
138 "rshift ralt j", /* StopKey */
139 "shift alt DEL", /* NewShell */
140 "control ralt lalt q", /* Quit */
141 "lcommand b", /* Cycle */
142 "lcommand v", /* Work */
143 "lcommand g", /* Closewindow */
145 "lcommand x", /* ActivateFrontWindow */
146 "lcommand a", /* Big Active Window */
147 "lcommand s", /* Small Active Window */
148 "lcommand d", /* Zip Active Window */
149 "lcommand h", /* Popup */
150 "lcommand f" /* ActiveToFront */
153 enum { BK_ID
,NS_ID
,Q_ID
,B_ID
,V_ID
,CL_ID
,AF_ID
,BW_ID
,SW_ID
,ZW_ID
,PU_ID
,ATF_ID
};
155 char prgname
[256]; /* Programm Pfad und Name */
157 char filename
[34]="windowtool.config"; /* Default Settings */
158 char dirname
[256]="s:";
159 char fullname
[300]; /* Nur Zwischenspeicher */
161 struct TagItem reqtags
[]=
163 {RT_ReqPos
,REQPOS_CENTERSCR
},{TAG_END
,0}
166 BOOL
filereq(int typ
)
168 struct rtFileRequester
*filereq
;
169 char *match
="#?.config";
172 if ((filereq
= rtAllocRequestA (RT_FILEREQ
, NULL
)))
174 rtChangeReqAttr(filereq
,RTFI_Dir
,dirname
,RTFI_MatchPat
,match
,TAG_END
);
178 if (rtFileRequest (filereq
, filename
, "Save configuration",RTFI_Flags
,FREQF_SAVE
,TAG_END
))
183 if (rtFileRequest (filereq
, filename
, "Load configuration",TAG_END
))
186 strcpy(dirname
,filereq
->Dir
);
187 rtFreeRequest (filereq
);
190 rtEZRequest ("Error:\nNo memory for filerequester !", "Continue", NULL
, NULL
);
197 strcpy(fullname
,dirname
);
198 AddPart((UBYTE
*)fullname
,(UBYTE
*)filename
,300);
199 if((fh
=Open((UBYTE
*)fullname
,MODE_NEWFILE
)))
202 for(k
=0;k
<KEYNUMMER
;k
++)
205 Write(fh
,keys
[k
],strlen(keys
[k
]));
210 else rtEZRequest("Error:\nUnable to open\nconfigurationfile\n%s !","Continue",NULL
, reqtags
,fullname
);
214 if(filereq(0)==TRUE
) save();
217 extern char *tt
[]; /* NAMEN DER TOOLTYPES-KEYS */
219 USHORT chip imagedata
[]=
221 0x0000,0x0000,0x0000,0x0400,0x0000,0x0000,0x0000,0x0C00,
222 0x0000,0x0000,0x0000,0x0C00,0x0000,0x0000,0x0000,0x0C00,
223 0x0000,0x0000,0x0010,0x0C00,0x0000,0x0000,0x0010,0x0C00,
224 0x0000,0x0000,0x0010,0x0C00,0x0000,0x1F04,0x0010,0x0C00,
225 0x0000,0x398E,0x0010,0x0C00,0x0000,0x018E,0x0010,0x0C00,
226 0x0000,0x070E,0x0010,0x0C00,0x0000,0x0C04,0x0010,0x0C00,
227 0x0000,0x0E04,0x0010,0x0C00,0x0000,0x0000,0x0010,0x0C00,
228 0x0000,0x0E0E,0x0010,0x0C00,0x0000,0x0000,0x0010,0x0C00,
229 0x0000,0x0000,0x0010,0x0C00,0x0000,0x0000,0x0010,0x0C00,
230 0x0000,0x0000,0x0010,0x0C00,0x001F,0xFFFF,0xFFE0,0x0C00,
231 0x0000,0x0000,0x0000,0x0C00,0x7FFF,0xFFFF,0xFFFF,0xFC00,
232 0x0000,0x0000,0x0000,0x0000,0xFFFF,0xFFFF,0xFFFF,0xF800,
233 0xD555,0x5555,0x5555,0x5000,0xD555,0x5555,0x5555,0x5000,
234 0xD53F,0xFFFF,0xFFE5,0x5000,0xD57F,0xFFFF,0xFFC5,0x5000,
235 0xD578,0x0000,0x0085,0x5000,0xD571,0x5555,0x5405,0x5000,
236 0xD575,0x4051,0x5505,0x5000,0xD575,0x4451,0x5505,0x5000,
237 0xD575,0x5451,0x5505,0x5000,0xD575,0x5051,0x5505,0x5000,
238 0xD575,0x5151,0x5505,0x5000,0xD575,0x5151,0x5505,0x5000,
239 0xD575,0x5555,0x5505,0x5000,0xD575,0x5151,0x5505,0x5000,
240 0xD571,0x5555,0x5405,0x5000,0xD578,0x0000,0x0085,0x5000,
241 0xD570,0x0000,0x0045,0x5000,0xD560,0x0000,0x0025,0x5000,
242 0xD540,0x0000,0x0015,0x5000,0xD555,0x5555,0x5555,0x5000,
243 0x8000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
247 0,0,54,23,2,imagedata
,3,0,0
251 char tooltypes
[KEYNUMMER
][256];
252 IPTR tooltypesadr
[KEYNUMMER
+1];
254 struct DiskObject
*diskobj
;
255 struct DiskObject mydiskobj
=
257 WB_DISKMAGIC
,WB_DISKVERSION
,
259 0,0,0,53,23,GADGIMAGE
,RELVERIFY
,BOOLGADGET
,
263 WBTOOL
,0,0,NO_ICON_POSITION
,NO_ICON_POSITION
,0,0,4096
266 mydiskobj
.do_ToolTypes
=(STRPTR
*)&tooltypesadr
[0];
268 for(k
=0;k
<KEYNUMMER
;k
++)
270 tooltypesadr
[k
]=(IPTR
)tooltypes
[k
];
271 sprintf(tooltypes
[k
],"%s=%s",tt
[k
],keys
[k
]);
275 if((diskobj
=GetDiskObject(prgname
)))
277 mydiskobj
.do_Gadget
.LeftEdge
=diskobj
->do_Gadget
.LeftEdge
;
278 mydiskobj
.do_Gadget
.TopEdge
=diskobj
->do_Gadget
.TopEdge
;
279 mydiskobj
.do_Gadget
.Width
=diskobj
->do_Gadget
.Width
;
280 mydiskobj
.do_Gadget
.Height
=diskobj
->do_Gadget
.Height
;
281 mydiskobj
.do_Gadget
.Flags
=diskobj
->do_Gadget
.Flags
;
282 mydiskobj
.do_Gadget
.Activation
=diskobj
->do_Gadget
.Activation
;
283 mydiskobj
.do_Gadget
.GadgetRender
=diskobj
->do_Gadget
.GadgetRender
;
284 mydiskobj
.do_Gadget
.SelectRender
=diskobj
->do_Gadget
.SelectRender
;
285 mydiskobj
.do_Gadget
.GadgetID
=diskobj
->do_Gadget
.GadgetID
;
286 mydiskobj
.do_Gadget
.UserData
=diskobj
->do_Gadget
.UserData
;
287 mydiskobj
.do_CurrentX
=diskobj
->do_CurrentX
;
288 mydiskobj
.do_CurrentY
=diskobj
->do_CurrentY
;
289 mydiskobj
.do_StackSize
=diskobj
->do_StackSize
;
292 PutDiskObject(prgname
,&mydiskobj
);
293 if(diskobj
)FreeDiskObject(diskobj
);
299 strcpy(fullname
,dirname
);
300 AddPart((UBYTE
*)fullname
,(UBYTE
*)filename
,300);
301 if((fh
=Open((UBYTE
*)fullname
,MODE_OLDFILE
)))
305 Seek(fh
,0,OFFSET_END
);
306 memlen
=Seek(fh
,0,OFFSET_BEGINNING
);
307 if(memlen
==0) rtEZRequest("Error:\nconfigurationfile\n%s\nis empty!","Continue",NULL
, reqtags
,fullname
);
309 if((mem
=AllocMem(memlen
,0)))
314 for(k
=0,aktu
=0;aktu
<memlen
&& k
<KEYNUMMER
;aktu
++,k
++)
316 for(;mem
[aktu
]!='\"';aktu
++);
317 if(aktu
>memlen
){ rtEZRequest("Error:\nError in\nconfigurationfile\n%s !","Continue",NULL
, reqtags
,fullname
);break;}
320 for(;mem
[aktu
]!='\"';aktu
++);
321 if(aktu
>memlen
){ rtEZRequest("Error:\nError in\nconfigurationfile\n%s !","Continue",NULL
, reqtags
,fullname
);break;}
324 strcpy(keys
[k
],&mem
[a
]);
326 if(k
==KEYNUMMER
)setkeys();
329 else rtEZRequest("Error:\nNo memory to load\nconfigurationfile\n%s !","Continue",NULL
, reqtags
,fullname
);
332 else rtEZRequest("Error:\nError while opening the configurationfile\n%s !","Continue",NULL
, reqtags
,fullname
);
342 struct DiskObject
*infoobj
;
346 if((infoobj
=GetDiskObject(prgname
)))
348 if((key
=FindToolType(infoobj
->do_ToolTypes
,"SETTINGS")))
350 strcpy(filename
,FilePart(key
));
351 *((char *)PathPart(key
))=0;
355 for(k
=0;k
<KEYNUMMER
;k
++)
356 if((key
=FindToolType(infoobj
->do_ToolTypes
,tt
[k
])))
359 FreeDiskObject(infoobj
);
361 else rtEZRequest("Error:\nUnable to open %s.info !","Continue",NULL
,reqtags
,prgname
);
363 /* Öffnet Window neu */
367 if(windowopen
==FALSE
) for(k
=0;k
<KEYNUMMER
;k
++) /* KEYS SICHERN */
368 strcpy(oldkeys
[k
],keys
[k
]);
371 rtEZRequest( "Error:\nUnable to open HotkeyPrefsWindow !",
372 "Continue",NULL
, reqtags
,NULL
);
376 waitsignals
= (1L<<Wnd
->UserPort
->mp_SigBit
) |
377 (1<<mp
->mp_SigBit
) | SIGBREAKF_CTRL_C
;
381 /* Schließt Window */
385 waitsignals
=(1<<mp
->mp_SigBit
) | SIGBREAKF_CTRL_C
;
391 for(k
=0;k
<KEYNUMMER
;k
++)
393 if(windowopen
==TRUE
)GT_SetGadgetAttrs(Gadgets
[k
],Wnd
,0,GTST_String
,keys
[k
],TAG_DONE
);
394 DeleteCxObjAll(filter
[k
]);
395 filter
[k
]=HotKey(keys
[k
],mp
,k
);
396 AttachCxObj(broker
,filter
[k
]);
400 strcpy(&windowtitle
[26],keys
[10]);
401 SetWindowTitles(Wnd
,windowtitle
,(char *)-1);
407 if(rtEZRequestA("Quit WindowTool ?\n","Yes|No",
408 NULL
, NULL
,NULL
) )ende(0);;
410 /* About Requester */
413 rtEZRequest( "WindowTool V"VERSIONSTRING
" ("DATESTRING
")\n"
414 "This program is Giftware\n"
415 "Copyright 1992 by Klaas Hermanns\n"
416 "(Weberstraße 42/4190 Kleve/Germany)",
417 "Continue",NULL
, reqtags
,NULL
);
430 checkstartup(argc
,argv
,WBenchMsg
);
437 waitsignals
= (1L<<Wnd
->UserPort
->mp_SigBit
) |
438 (1<<mp
->mp_SigBit
) | SIGBREAKF_CTRL_C
;
440 else waitsignals
= (1<<mp
->mp_SigBit
) | SIGBREAKF_CTRL_C
;
442 if(flags
&NEWSETTINGSFLAG
)open();
446 if(state
==0)signals
=Wait(waitsignals
);
447 else while(0==(signals
=CheckSignal( waitsignals
)));
449 if(signals
& SIGBREAKF_CTRL_C
) quit();
450 if(Wnd
&& (signals
& 1L<<Wnd
->UserPort
->mp_SigBit
))
453 if(windowopen
==FALSE
)break;
454 if(!(mes
=(struct IntuiMessage
*)GT_GetIMsg(Wnd
->UserPort
)))break;
458 gad
=(struct Gadget
*)mes
->IAddress
;
462 case IDCMP_REFRESHWINDOW
:GT_BeginRefresh(Wnd
);
463 GT_RefreshWindow(Wnd
,0);
464 PrintIText( Wnd
->RPort
, IText
, 0l, 0l );
465 GT_EndRefresh(Wnd
,TRUE
);
467 case IDCMP_CHANGEWINDOW
:
469 case IDCMP_CLOSEWINDOW
:
473 switch(gad
->GadgetID
)
475 case GD_GadgetSave
:save();break; /*SAVE*/
476 case GD_GadgetHide
:popdown();break;
477 case GD_GadgetQuit
:quit();break;
478 case GD_GadgetCancel
:
479 for(k
=0;k
<KEYNUMMER
;k
++)/* KEYS ZURÜCK */
481 strcpy(keys
[k
],oldkeys
[k
]);
482 DeleteCxObjAll(filter
[k
]);
483 filter
[k
]=HotKey(keys
[k
],mp
,k
);
484 AttachCxObj(broker
,filter
[k
]);
488 default:if(gad
->GadgetID
<KEYNUMMER
)
491 DeleteCxObjAll(filter
[k
]);
492 strcpy(keys
[k
],((struct StringInfo
*)gad
->SpecialInfo
)->Buffer
);
493 filter
[k
]=HotKey(keys
[k
],mp
,k
);
494 AttachCxObj(broker
,filter
[k
]);
495 ActivateGadget(Gadgets
[k
==11 ? 0 : k
+1],Wnd
,0);
497 if(gad
->GadgetID
==GD_Gadget10
)
499 strcpy(&windowtitle
[26],keys
[10]);
500 SetWindowTitles(Wnd
,windowtitle
,(char *)-1);
506 switch(MENUNUM(code
))
508 case 0:switch(ITEMNUM(code
))
510 case 0:for(k
=0;k
<KEYNUMMER
;k
++)
511 GT_SetGadgetAttrs(Gadgets
[k
],Wnd
,0,GTST_String
,"",TAG_DONE
);
513 case 1:openas();break; /* OPEN */
514 case 2:openinfo();break; /* OPEN INFO */
515 case 4:save();break; /* SAVE */
516 case 5:saveas();break; /* SAVE AS */
517 case 6:saveasinfo();break; /* SAVE AS INFO */
518 case 8:about(); /* About */
520 case 10:popdown(); /* HIDE */
523 for(k
=0;k
<KEYNUMMER
;k
++)/* KEYS ZURÜCK */
525 strcpy(keys
[k
],oldkeys
[k
]);
526 DeleteCxObjAll(filter
[k
]);
527 filter
[k
]=HotKey(keys
[k
],mp
,k
);
528 AttachCxObj(broker
,filter
[k
]);
532 case 13:quit(); /* QUIT */
539 case IDCMP_VANILLAKEY
:
549 case 'C':for(k
=0;k
<KEYNUMMER
;k
++)/* KEYS ZURÜCK */
551 strcpy(keys
[k
],oldkeys
[k
]);
552 DeleteCxObjAll(filter
[k
]);
553 filter
[k
]=HotKey(keys
[k
],mp
,k
);
554 AttachCxObj(broker
,filter
[k
]);
562 case 'O':ActivateGadget(Gadgets
[0],Wnd
,0);break;
564 case 'N':ActivateGadget(Gadgets
[1],Wnd
,0);break;
566 case 'U':ActivateGadget(Gadgets
[2],Wnd
,0);break;
568 case 'Y':ActivateGadget(Gadgets
[3],Wnd
,0);break;
570 case 'R':ActivateGadget(Gadgets
[4],Wnd
,0);break;
572 case 'L':ActivateGadget(Gadgets
[5],Wnd
,0);break;
574 case 'A':ActivateGadget(Gadgets
[6],Wnd
,0);break;
576 case 'B':ActivateGadget(Gadgets
[7],Wnd
,0);break;
578 case 'M':ActivateGadget(Gadgets
[8],Wnd
,0);break;
580 case 'Z':ActivateGadget(Gadgets
[9],Wnd
,0);break;
582 case 'W':ActivateGadget(Gadgets
[10],Wnd
,0);break;
584 case 'T':ActivateGadget(Gadgets
[11],Wnd
,0);break;
590 if(signals
& (1<<mp
->mp_SigBit
))
592 while((msg
=(struct Message
*)GetMsg(mp
)))
594 id
=CxMsgID((CxMsg
*)msg
);
596 switch( CxMsgType((CxMsg
*)msg
) )
602 case V_ID
:worktofront();
604 case AF_ID
:activatefront();
608 case BK_ID
:switchstate();
612 case NS_ID
:system("newshell");
614 case BW_ID
:bigwindow();
616 case SW_ID
:smallwindow();
618 case ZW_ID
:zipwindow();
622 case ATF_ID
:activetofront();
624 case CL_ID
:closewindow();
633 case CXCMD_DISABLE
:ActivateCxObj(broker
,0);break;
634 case CXCMD_ENABLE
:ActivateCxObj(broker
,-1);break;
635 case CXCMD_KILL
:quit();break;
637 case CXCMD_APPEAR
:popup();break;
638 case CXCMD_DISAPPEAR
:popdown();break;
654 if(!(AslBase
=(struct Library
*)OpenLibrary("asl.library",37)))
655 ende("asl.library not found !");
656 if(!(GadToolsBase
=(struct Library
*)OpenLibrary("gadtools.library",37)))
657 ende("gadtools.library not found !");
658 if(!(GfxBase
=(struct GfxBase
*)OpenLibrary("graphics.library",37)))
659 ende("graphics.library not found !");
660 if(!(IntuitionBase
=(struct IntuitionBase
*)OpenLibrary("intuition.library",37)))
661 ende("Intuition.library not found !");
662 if(!( ReqToolsBase
=(struct ReqToolsBase
*)OpenLibrary(REQTOOLSNAME
,REQTOOLSVERSION
)))
663 ende("reqtools.library not found !");
664 if(!(CxBase
=(struct Library
*)OpenLibrary("commodities.library",37)))
665 ende("commodities.library not found !");
666 if(!(IconBase
=OpenLibrary("icon.library",37)))
667 ende("icon.library not found !");
673 if(!(mp
=(struct MsgPort
*)CreateMsgPort()))ende("Unable to create MsgPort !");
676 for(k
=0;k
<KEYNUMMER
;k
++)
678 filter
[k
]=HotKey(keys
[k
],mp
,k
);
682 if(!(broker
=(CxObj
*)CxBroker(&nb
,0)))ende(0);/* WT läuft schon */
684 for(k
=0;k
<KEYNUMMER
;k
++)
685 AttachCxObj(broker
,filter
[k
]);
687 ActivateCxObj(broker
,-1);
690 void ende(char *text
)
692 if(text
)rtEZRequest(text
,"Continue",NULL
, reqtags
,NULL
);
696 if(broker
)DeleteCxObjAll(broker
);
697 if(mp
)DeleteMsgPort(mp
);
699 if(CxBase
)CloseLibrary(CxBase
);
703 CloseLibrary((struct Library
*)IntuitionBase
);
705 if(ReqToolsBase
)CloseLibrary ((struct Library
*)ReqToolsBase
);
706 if(GfxBase
)CloseLibrary ((struct Library
*)GfxBase
);
707 if(GadToolsBase
)CloseLibrary(GadToolsBase
);
708 if(AslBase
)CloseLibrary(AslBase
);
709 if(IconBase
)CloseLibrary(IconBase
);
715 void switchstate(void)
718 oldpri
=SetTaskPri(FindTask(0),oldpri
);