forwarding a radium compilation fix.
[AROS-Contrib.git] / fish / windowtool / gadgets.c
blob371f2daf1c78b5e4c108cdedb323d660cda05354
1 #include <string.h>
2 #include <exec/types.h>
3 #include <intuition/intuition.h>
4 #include <intuition/gadgetclass.h>
5 #include <libraries/gadtools.h>
6 #include <graphics/displayinfo.h>
7 #include <proto/exec.h>
8 #include <proto/intuition.h>
9 #include <proto/gadtools.h>
10 #include <aros/debug.h>
12 #define GD_Gadget0 0
13 #define GD_Gadget1 1
14 #define GD_Gadget2 2
15 #define GD_Gadget3 3
16 #define GD_Gadget4 4
17 #define GD_Gadget5 5
18 #define GD_Gadget6 6
19 #define GD_Gadget7 7
20 #define GD_Gadget8 8
21 #define GD_Gadget9 9
22 #define GD_Gadget10 10
23 #define GD_Gadget11 11
24 #define GD_GadgetSave 50 /* Save */
25 #define GD_GadgetHide 51 /* Hide */
26 #define GD_GadgetQuit 52 /* Quit */
27 #define GD_GadgetCancel 53 /* Cancel */
29 #define KEYNUMMER 12
30 extern char keys[KEYNUMMER][256];
32 int windowopen=FALSE;
33 char windowtitle[80]="WindowTool 1.0 : Hotkey = "; /* 25 */
35 struct Window *Wnd = 0l;
36 struct Screen *Scr = 0l;
37 APTR VisualInfo = 0l;
38 struct Gadget *GList = 0l;
39 struct Gadget *Gadgets[16];
40 struct Menu *Menus = 0l;
41 UWORD Zoom[4] = { 0, 0, 200, 11 };
43 struct TextAttr topaz8 = {
44 ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
46 struct TagItem WindowTags[] = {
47 {WA_Left, -10},
48 {WA_Top, -10},
49 {WA_Width, 610},
50 {WA_Height, 138},
51 {WA_IDCMP, IDCMP_GADGETUP|IDCMP_MENUPICK|IDCMP_VANILLAKEY|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_CHANGEWINDOW},
52 {WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE},
53 {WA_Gadgets, 0l},
54 {WA_Title, (IPTR)windowtitle},
55 {WA_MinWidth, 200},
56 {WA_MinHeight, 11},
57 {WA_MaxWidth, 611},
58 {WA_MaxHeight, 137},
59 {WA_Zoom, (IPTR)Zoom},
60 {TAG_DONE }};
62 struct IntuiText IText[] = { {
63 2, 0, JAM1,45, 17, &topaz8, (UBYTE *)"Hotkeys:", NULL } };
65 struct NewMenu NewMenu[] = {
66 {NM_TITLE, "Project", 0l, 0, 0, 0l},
67 {NM_ITEM, "New", "N", 0, 0, 0l},
68 {NM_ITEM, "Open...", "O", 0, 0, 0l},
69 {NM_ITEM, "Open .Info", 0, 0, 0, 0l},
70 {NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l},
71 {NM_ITEM, "Save", "S", 0, 0, 0l},
72 {NM_ITEM, "Save As...", "A", 0, 0, 0l},
73 {NM_ITEM, "Save As .info",0, 0, 0, 0l},
74 {NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l},
75 {NM_ITEM, "About...", 0, 0, 0, 0l},
76 {NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l},
77 {NM_ITEM, "Hide", "H", 0, 0, 0l},
78 {NM_ITEM, "Cancel", "C", 0, 0, 0l},
79 {NM_ITEM, NM_BARLABEL, 0l, 0, 0l, 0l},
80 {NM_ITEM, "Quit...", "Q", 0, 0, 0l},
81 {NM_END, 0l, 0l, 0, 0l, 0l }};
83 long InitStuff( void )
85 struct NewGadget ng;
86 struct Gadget *g;
88 if(windowopen==TRUE)
90 WindowToFront(Wnd);
91 ActivateWindow(Wnd);
92 return(0);
95 if ( NOT( Scr = LockPubScreen( "Workbench" )))
96 return( 1l );
98 if ( NOT( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
99 return( 2l );
101 if ( NOT( g = CreateContext( &GList )))
102 return( 3l );
104 ng.ng_LeftEdge = 110;
105 ng.ng_TopEdge = 29;
106 ng.ng_Width = 173;
107 ng.ng_Height = 13;
108 ng.ng_GadgetText = "St_op";
109 ng.ng_TextAttr = &topaz8;
110 ng.ng_GadgetID = GD_Gadget0;
111 ng.ng_Flags = PLACETEXT_LEFT;
112 ng.ng_VisualInfo = VisualInfo;
114 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[0], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
116 Gadgets[ 0 ] = g;
118 ng.ng_TopEdge = 44;
119 ng.ng_GadgetText = "_Newshell";
120 ng.ng_GadgetID = GD_Gadget1;
122 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[1], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
124 Gadgets[ 1 ] = g;
126 ng.ng_TopEdge = 59;
127 ng.ng_GadgetText = "Q_uit";
128 ng.ng_GadgetID = GD_Gadget2;
130 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[2], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
132 Gadgets[ 2 ] = g;
134 ng.ng_TopEdge = 74;
135 ng.ng_GadgetText = "C_ycle";
136 ng.ng_GadgetID = GD_Gadget3;
138 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[3], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
140 Gadgets[ 3 ] = g;
142 ng.ng_TopEdge = 89;
143 ng.ng_GadgetText = "Wo_rkbench";
144 ng.ng_GadgetID = GD_Gadget4;
146 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[4], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
148 Gadgets[ 4 ] = g;
150 ng.ng_TopEdge = 104;
151 ng.ng_GadgetText = "C_loseWindow";
152 ng.ng_GadgetID = GD_Gadget5;
154 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[5], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
156 Gadgets[ 5 ] = g;
158 ng.ng_LeftEdge = 409;
159 ng.ng_TopEdge = 29;
160 ng.ng_GadgetText = "_ActivateFront";
161 ng.ng_GadgetID = GD_Gadget6;
163 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[6], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
165 Gadgets[ 6 ] = g;
167 ng.ng_TopEdge = 44;
168 ng.ng_GadgetText = "Make_Big";
169 ng.ng_GadgetID = GD_Gadget7;
171 g = CreateGadget( STRING_KIND, g, &ng, GTST_String,keys[7],GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
173 Gadgets[ 7 ] = g;
175 ng.ng_TopEdge = 59;
176 ng.ng_GadgetText = "MakeS_mall";
177 ng.ng_GadgetID = GD_Gadget8;
179 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[8], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
181 Gadgets[ 8 ] = g;
183 ng.ng_TopEdge = 74;
184 ng.ng_GadgetText = "_Zip";
185 ng.ng_GadgetID = GD_Gadget9;
187 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[9], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
189 Gadgets[ 9 ] = g;
191 ng.ng_TopEdge = 89;
192 ng.ng_GadgetText = "Sho_w";
193 ng.ng_GadgetID = GD_Gadget10;
195 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[10], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
197 Gadgets[ 10 ] = g;
199 ng.ng_GadgetText = "Ac_tiveToFront";
200 ng.ng_TopEdge = 104;
201 ng.ng_GadgetID = GD_Gadget11;
203 g = CreateGadget( STRING_KIND, g, &ng,GTST_String,keys[11], GTST_MaxChars, 256, GT_Underscore, '_', TAG_DONE );
205 Gadgets[ 11 ] = g;
207 ng.ng_LeftEdge = 110;
208 ng.ng_TopEdge = 120;
209 ng.ng_Width = 83;
210 ng.ng_GadgetText = "_Save";
211 ng.ng_GadgetID = GD_GadgetSave;
212 ng.ng_Flags = PLACETEXT_IN;
214 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE );
216 Gadgets[ 12 ] = g;
218 ng.ng_LeftEdge = 201;
219 ng.ng_GadgetText = "_Hide";
220 ng.ng_GadgetID = GD_GadgetHide;
222 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE );
224 Gadgets[ 13 ] = g;
226 ng.ng_LeftEdge = 381;
227 ng.ng_GadgetText = "_Quit";
228 ng.ng_GadgetID = GD_GadgetQuit;
230 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE );
232 Gadgets[ 14 ] = g;
234 ng.ng_LeftEdge = 292;
235 ng.ng_GadgetText = "_Cancel";
236 ng.ng_GadgetID = GD_GadgetCancel;
238 g = CreateGadget( BUTTON_KIND, g, &ng, GT_Underscore, '_', TAG_DONE );
240 Gadgets[ 15 ] = g;
242 if ( NOT g )
243 return( 4l );
245 WindowTags[ 6 ].ti_Data = (IPTR)GList;
247 if ( NOT( Menus = CreateMenus( NewMenu, GTMN_FrontPen, 0l, TAG_DONE )))
248 return( 6l );
250 LayoutMenus( Menus, VisualInfo, GTMN_TextAttr, &topaz8, TAG_DONE );
252 if(WindowTags[0].ti_Data==-10) /* Bei -10 1.Aufruf und in die mitte */
253 { /* setzen */
254 WindowTags[0].ti_Data=(Scr->Width-WindowTags[2].ti_Data)/2;
255 WindowTags[1].ti_Data=(Scr->Height-WindowTags[3].ti_Data)/2;
258 strcpy(&windowtitle[26],keys[10]);
260 if ( NOT( Wnd = OpenWindowTagList( 0l, WindowTags )))
261 return( 5l );
263 SetMenuStrip( Wnd, Menus );
264 GT_RefreshWindow( Wnd, 0l );
266 PrintIText( Wnd->RPort, IText, 0l, 0l );
268 windowopen=TRUE;
270 return( 0l );
273 void CleanStuff( void )
275 if(windowopen==FALSE)return;
277 if ( Menus ) {
278 ClearMenuStrip( Wnd );
279 FreeMenus( Menus );
282 if ( Wnd )
284 WindowTags[0].ti_Data = (LONG)Wnd->LeftEdge;
285 WindowTags[1].ti_Data = (LONG)Wnd->TopEdge;
286 WindowTags[2].ti_Data = (LONG)Wnd->Width;
287 WindowTags[3].ti_Data = (LONG)Wnd->Height;
288 CloseWindow( Wnd );
289 Wnd = NULL;
292 if ( GList )
293 FreeGadgets( GList );
295 if ( VisualInfo )
296 FreeVisualInfo( VisualInfo );
298 if ( Scr )
299 UnlockPubScreen( 0l, Scr );
300 windowopen=FALSE;