Fix for a crash which happened when a document couldn't be opened.
[AROS-Contrib.git] / fish / surf / getfilenames.c
blob4b7ad69297889f873e1c86c2f516516f9a93fda7
1 #include <aros/oldprograms.h>
2 #include <intuition/intuition.h>
3 #include "scrnio.ih"
4 #include <exec/memory.h>
5 #ifdef MANX
6 #include <functions.h>
7 #endif
9 #include "scrndef.h"
10 #include "mytypes.h"
13 #define StringSize 40
14 #define ROW 8
15 #define COL 8
16 #define TextX COL
17 #define TextY (ROW/2)
18 #define StringX 8
19 #define StringY 12
20 #define ReqSizeX 50*COL
21 #define ReqSizeY 6*ROW
23 #define CodeGo 100
24 #define CodeCancel 101
27 * declarations for a cancel button to be used by both
28 * requestors.
30 static struct IntuiText TextCancel = {
31 1,-1,JAM1, 2, 1, NULL,(UBYTE *) "Cancel", NULL };
33 static short S_Cancel[] = {
34 -2,-1, -2,ROW+1, 6*COL+2,ROW+1, 6*COL+2,-1, -2,-1
37 static struct Border B_Cancel = { 0, 0, 1, 0, JAM1, 5, S_Cancel, NULL };
39 static struct Gadget G_Cancel = {
40 NULL,
41 10*COL, ROW *4, 6*COL, ROW, /* loc and size of hit box */
42 GADGHBOX, /* complemented when pressed */
43 RELVERIFY, /* just get gadget up messages */
44 BOOLGADGET | REQGADGET,
45 (APTR)&B_Cancel, NULL,
46 &TextCancel,
47 0, NULL,
48 (int)CodeCancel,
49 NULL
53 * String gadget to get ilbm filename
55 static char OutTitle[] = { "output filename:" };
56 static char InTitle[] = { "input filename:" };
58 static struct IntuiText TextOutFile = {
59 1,1,JAM1, TextX, TextY, NULL,
60 (UBYTE *)OutTitle, NULL
62 static struct IntuiText TextInFile = {
63 1,1,JAM1, TextX, TextY, NULL,
64 (UBYTE *)InTitle, NULL
68 static char OutNameBuff[StringSize] = { "out.ilbm" };
69 static char InNameBuff[StringSize] = { "in.ilbm" };
70 static char undo[StringSize];
72 static struct StringInfo S_OutFile = {
73 (UBYTE *)OutNameBuff,
74 (UBYTE *)undo,
76 sizeof( OutNameBuff),
79 13,
81 0,0,NULL,0, NULL
84 static struct StringInfo S_InFile = {
85 (UBYTE *)InNameBuff,
86 (UBYTE *)undo,
88 sizeof( InNameBuff),
91 13,
93 0,0,NULL,0, NULL
96 static short BD_InOut[] = {
97 -2,-1, -2, ROW, (StringSize-1)*COL+1,ROW,
98 (StringSize-1)*COL+1,-1, -2, -1
101 static struct Border B_InOut = { 0, 0, 1, 0, JAM1, 5, BD_InOut, NULL };
103 static struct Gadget G_OutFile = {
104 &G_Cancel,
105 StringX , StringY, /* loc */
106 sizeof(OutNameBuff)*COL, ROW, /* size */
107 GADGHCOMP,
108 RELVERIFY /* | STRINGCENTER */,
109 STRGADGET | REQGADGET,
110 (APTR)&B_InOut, /* border */
111 NULL, /* high lighted */
112 &TextOutFile,
114 (APTR) &S_OutFile,
115 (int)CodeGo,
116 NULL
120 static struct Gadget G_InFile = {
121 &G_Cancel,
122 StringX , StringY, /* loc */
123 sizeof(InNameBuff)*COL, ROW, /* size */
124 GADGHCOMP,
125 RELVERIFY/* | STRINGCENTER */,
126 STRGADGET | REQGADGET,
127 (APTR)&B_InOut, /* border */
128 NULL, /* high lighted */
129 NULL, /* text */
131 (APTR) &S_InFile,
132 (int)CodeGo,
133 NULL
136 static struct Requester R_InFile = {
137 NULL,
138 COL*10, ROW*4, ReqSizeX, ReqSizeY,
139 0, 0,
140 &G_InFile,
141 NULL,
142 &TextInFile,
144 2, /* backfill */
145 NULL,
147 NULL,
148 NULL,
149 NULL,
155 static struct Requester R_OutFile = {
156 NULL,
157 COL*10, ROW*4, ReqSizeX, ReqSizeY,
158 0, 0,
159 &G_OutFile,
160 NULL,
161 &TextOutFile,
163 2, /* backfill */
164 NULL,
165 { },
166 NULL,
167 NULL,
168 NULL,
171 static bool
172 WaitForUser() {
173 struct IntuiMessage mycopy,
174 *orig;
175 for(;;) {
176 Wait( 1<< CntrlWin->UserPort->mp_SigBit );
179 * handle messages for the control window
182 while( (orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort )) ) {
184 mycopy = *orig;
185 ReplyMsg( (struct Message *)orig );
187 if( mycopy.Class == GADGETUP ) {
188 USHORT code;
190 code = ((struct Gadget*)mycopy.IAddress)->GadgetID;
191 if( code == CodeGo ) return( true );
192 if( code == CodeCancel) return(false);
200 char *GetInFile()
202 bool answer;
203 Request( &R_InFile, CntrlWin);
204 answer = WaitForUser();
205 EndRequest( &R_InFile, CntrlWin);
206 return( answer?InNameBuff: NULL);
210 char *GetOutFile()
212 bool answer;
213 Request( &R_OutFile, CntrlWin);
214 answer = WaitForUser();
215 EndRequest( &R_OutFile, CntrlWin);
216 return( answer?OutNameBuff: NULL);