Initial import of Scalos. To decrease size I have
[AROS-Contrib.git] / scalos / Modules / FormatDisk.Gadtools / GetInputFromWindow.c
blob79d7e47e262df545d0c272f94fc2b4b5aca32252
1 // GetInputFromWindow.c
2 // $Date$
3 // $Revision$
6 #include <string.h>
8 #include <exec/types.h>
9 #include <exec/exec.h>
10 #include <intuition/intuition.h>
11 #include <intuition/gadgetclass.h>
12 #include <dos/dos.h>
13 #include <dos/filehandler.h>
14 #include <workbench/startup.h>
15 #include <libraries/gadtools.h>
16 #include <workbench/icon.h>
17 #include <devices/trackdisk.h>
18 #include <dos/rdargs.h>
20 #include <proto/exec.h>
21 #include <proto/intuition.h>
22 #include <proto/dos.h>
23 #include <proto/gadtools.h>
24 #include <proto/icon.h>
25 #include <proto/graphics.h>
26 #include <proto/utility.h>
28 #include <defs.h>
30 #include "Format.h"
31 #define FormatDisk_NUMBERS
32 #include STR(SCALOSLOCALE)
34 #include "GUI.h"
36 //-----------------------------------------------------------------------------
38 extern BOOL FFS;
39 extern BOOL intl;
40 extern BOOL DirCache;
42 //-----------------------------------------------------------------------------
43 static void GetMsgidUnderScore(void);
44 //static ULONG FindUnderscoredToLower(STRPTR text);
46 static UWORD Name_key, FFS_key, INTL_key, Verify_key, WithTrash_key;
47 static UWORD Dircache_key, Trash_key, Format_key, QuickFormat_key, Cancel_key;
50 //------------------------------------------------------------------------------
51 //------------------------------------------------------------------------------
53 static void GetMsgidUnderScore(void)
55 Name_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_DEVNAME));
57 FFS_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_FFS));
59 INTL_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_INTL));
61 Verify_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_VERIFY));
63 WithTrash_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_TRASHCAN));
65 Dircache_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_DIRCACHE));
67 Trash_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_TRASHCAN_NAME));
69 Format_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_GUI_FORMAT));
71 QuickFormat_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_QUICK_FORMAT));
73 Cancel_key = FindUnderscoredToLower( (STRPTR) GetLocString(MSGID_GADGET_GUI_CANCEL));
76 //-----------------------------------------------------------------------------
78 ULONG FindUnderscoredToLower(STRPTR text)
80 ULONG c;
81 while(( c = *text++))
83 if( c == '_' ) return ToLower(*text);
85 return 0;
87 //-----------------------------------------------------------------------------
89 // Get input from the original window
90 prepResult getPrepInput(void)
92 struct IntuiMessage *mesg;
93 ULONG class;
94 ULONG code;
95 struct Gadget *gadget;
96 struct TagItem tags[2];
98 GetMsgidUnderScore();
100 // Setup tags that will be used to toggle the states of checkbox gadgets
101 tags[0].ti_Tag = GTCB_Checked;
102 tags[1].ti_Tag = TAG_DONE;
103 tags[1].ti_Data = 0UL;
105 // Loop until the user presses 'OK' or 'Cancel'
106 for(;;)
108 // Wait for input
109 Wait(1<<PrepWnd->UserPort->mp_SigBit);
111 // Get the input
112 mesg = GT_GetIMsg(PrepWnd->UserPort);
114 // Loop while there are messages to be processed
115 while (mesg != NULL)
117 // Get the message type, etc.
118 class = mesg->Class;
119 code = mesg->Code;
120 gadget = (struct Gadget *)mesg->IAddress;
122 // Reply to the message
123 GT_ReplyIMsg(mesg);
125 // Act on the message
126 switch(class)
128 // User clicked on close gadget. Treat it as a click on 'Cancel'
129 case IDCMP_CLOSEWINDOW:
130 return(eQuit);
132 // User pressed a gadget
133 case IDCMP_GADGETUP:
134 switch(gadget->GadgetID)
136 // Checkbox gadgets
137 // (each toggles the appropriate status flag)
139 // FastfileSystem
140 case GD_FFSGadget:
141 FFS = !FFS;
142 break;
144 // Withe Trashcan
145 case GD_IconGadget:
146 Icon = !Icon;
147 break;
149 // Verify
150 case GD_VerifyGadget:
151 Verify = !Verify;
152 break;
154 // International
155 case GD_IntlGadget:
156 intl = !intl;
157 break;
159 // DirCache
160 case GD_DirCacheGadget:
161 DirCache = !DirCache;
162 break;
164 // OK
165 case GD_OKGadget:
166 return(eOK);
168 // Quick format
169 case GD_QuickFmtGadget:
170 return(eQuick);
172 // Cancel
173 case GD_CancelGadget:
174 return(eCancel);
176 break;
178 // Keypress (gadget equivalents)
179 case IDCMP_VANILLAKEY:
180 if (code == Name_key)
181 ActivateGadget(PrepGadgets[GD_NameGadget], PrepWnd,NULL);
182 else if( code == FFS_key )
184 // Toggle the checkmark state of the gadget
185 tags[0].ti_Data = (FFS = !FFS);
186 GT_SetGadgetAttrsA(PrepGadgets[GD_FFSGadget], PrepWnd,NULL, tags);
188 else if( code == INTL_key )
190 if (!DirCache)
192 tags[0].ti_Data = (intl = !intl);
193 GT_SetGadgetAttrsA(PrepGadgets[GD_IntlGadget], PrepWnd,NULL, tags);
196 else if( code == Verify_key )
198 tags[0].ti_Data = (Verify = !Verify);
199 GT_SetGadgetAttrsA(PrepGadgets[GD_VerifyGadget], PrepWnd,NULL, tags);
201 else if( code == WithTrash_key )
203 tags[0].ti_Data = (Icon = !Icon);
204 GT_SetGadgetAttrsA(PrepGadgets[GD_IconGadget], PrepWnd,NULL, tags);
206 else if( code == Dircache_key )
208 tags[0].ti_Data = (DirCache = !DirCache);
209 GT_SetGadgetAttrsA(PrepGadgets[GD_DirCacheGadget], PrepWnd,NULL, tags);
211 else if( code == Trash_key )
213 if (Icon)
215 ActivateGadget(PrepGadgets[GD_TrashCanNameGadget], PrepWnd,NULL);
218 else if( code == Format_key )
219 return(eOK);
220 else if( code == QuickFormat_key )
221 return(eQuick);
222 else if( code == Cancel_key )
223 return(eCancel);
225 break;
228 // Get the next message
229 mesg = GT_GetIMsg(PrepWnd->UserPort);
232 // Update state of some gadgets.
233 GT_SetGadgetAttrs(PrepGadgets[GD_IntlGadget], PrepWnd, NULL, GA_Disabled, DirCache, TAG_DONE);
235 GT_SetGadgetAttrs(PrepGadgets[GD_TrashCanNameGadget], PrepWnd, NULL, GA_Disabled, !Icon, TAG_DONE);
237 d1(KPrintF(__FILE__ "/" __FUNC__ "/%ld: SELECTED FROM GUI: FFS = %ld INTL = %ld DIRCACHE = %ld ICON = %ld VERIFY = %ld\n",
238 __LINE__, FFS, intl, DirCache, Icon, Verify));
241 return(FALSE);