wip commit. acpi button driver.
[AROS.git] / test / Zune / string.c
blobba0a4102ecc982db1159a42329e36b5fb6078335
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/types.h>
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
11 #include <proto/alib.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
14 #include <proto/intuition.h>
15 #include <proto/muimaster.h>
16 #include <libraries/mui.h>
17 #include <libraries/coolimages.h>
20 #define AddContents(obj) \
21 DoMethod(root, MUIM_Group_InitChange); \
22 DoMethod(root, OM_ADDMEMBER, (IPTR)obj);\
23 DoMethod(root, MUIM_Group_ExitChange);
25 #define DelContents(obj) \
26 DoMethod(root, MUIM_Group_InitChange); \
27 DoMethod(root, OM_REMMEMBER, (IPTR)obj);\
28 DoMethod(root, MUIM_Group_ExitChange); \
29 MUI_DisposeObject(obj);
31 Object *app;
32 Object *wnd;
33 Object *root;
34 Object *btabort, *btproceed;
36 int quit = FALSE;
38 enum
40 Push_NULL,
41 Push_Proceed,
42 Push_Abort,
45 /* ######################################################################## */
48 const char GuiWinTitle[] ="String Test";
49 struct Screen *scr;
52 void init_gui()
55 scr = LockPubScreen(NULL);
57 app = ApplicationObject,
58 MUIA_Application_Title, "String Test",
60 SubWindow, wnd = WindowObject,
61 MUIA_Window_Title, GuiWinTitle,
62 MUIA_Window_Width, 400,
63 MUIA_Window_Height, 300,
64 MUIA_Window_CloseGadget, FALSE,
65 MUIA_Window_NoMenus, TRUE,
66 MUIA_Window_ID, MAKE_ID('T','E','S','T'),
67 WindowContents,
68 VGroup,
69 Child, root = VGroup, End,
70 Child, HBar(TRUE),
71 Child, HGroup,
72 MUIA_Group_SameSize, TRUE,
73 Child, btproceed = CoolImageIDButton("Proceed", COOL_USEIMAGE_ID),
74 Child, btabort = CoolImageIDButton("Abort", COOL_CANCELIMAGE_ID),
75 End,
76 End,
77 End,
78 End;
80 if (app == NULL)
82 /* failed to initialize GUI */
83 printf("Failed to intialize Zune GUI\n");
85 set(app,MUIA_Window_DefaultObject, (IPTR)root);
86 set(btproceed,MUIA_CycleChain,1);
87 set(btabort,MUIA_CycleChain,1);
89 DoMethod(btproceed, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
90 MUIM_Application_ReturnID, Push_Proceed);
91 DoMethod(btabort, MUIM_Notify, MUIA_Pressed, FALSE,(IPTR)app, 2,
92 MUIM_Application_ReturnID, Push_Abort);
93 set(wnd, MUIA_Window_Open, TRUE);
97 * Close GUI
99 void deinit_gui()
101 set(wnd, MUIA_Window_Open, FALSE);
102 MUI_DisposeObject(app);
108 * Ask user for a number
110 long int request_number(long int def)
112 long int retval;
113 long int min, max;
115 retval = def;
116 max = 999;
117 min = 0;
121 char *out;
122 BOOL running = TRUE;
123 Object *st, *wc;
124 ULONG val, sigs = 0;
126 out = StrDup("TEST");
128 wc = VGroup,
129 Child, VGroup, GroupFrame,
130 Child, TextObject,
131 MUIA_Text_Contents, (IPTR)(out),
132 End,
133 Child, st = StringObject,
134 StringFrame,
135 MUIA_String_Accept, (IPTR)"-0123456789",
136 MUIA_String_Integer, retval,
137 MUIA_String_AdvanceOnCR,TRUE,
138 MUIA_CycleChain, TRUE,
139 End,
140 End,
141 End;
143 if (wc)
145 AddContents(wc);
147 while (running)
149 switch (val = DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
151 case MUIV_Application_ReturnID_Quit:
152 case Push_Abort:
153 quit = TRUE; running = FALSE;
154 break;
155 case Push_Proceed:
156 GetAttr(MUIA_String_Integer, st, &retval);
157 if ( retval < max && retval > min)
159 running = FALSE;
161 break;
162 default:
163 break;
166 sigs = CheckSignal(SIGBREAKF_CTRL_C | sigs);
169 GetAttr(MUIA_String_Integer, st, &retval);
171 DelContents(wc);
173 FreeVec(out);
177 return retval;
181 char *request_string(char *def)
183 char *retval, *string, *secret;
184 char *out;
185 BOOL running = TRUE;
186 Object *st, *tst, *wc;
187 ULONG val, sigs = 0;
189 string = def;
191 out = StrDup("test");
192 secret = NULL;
194 wc = VGroup, GroupFrame,
195 Child, TextObject,
196 MUIA_Text_Contents, (IPTR)(out),
197 End,
198 Child, st = StringObject,
199 StringFrame,
200 MUIA_String_Contents, (IPTR)string,
201 MUIA_String_MaxLen, 12,
202 MUIA_String_AdvanceOnCR,TRUE,
203 MUIA_CycleChain, TRUE,
204 End,
205 Child, tst = StringObject,
206 StringFrame,
207 MUIA_String_Contents, (IPTR)secret,
208 MUIA_String_MaxLen, 12,
209 MUIA_String_Secret, TRUE,
210 MUIA_String_AdvanceOnCR,TRUE,
211 MUIA_CycleChain, TRUE,
212 End,
213 End;
215 if (wc)
217 AddContents(wc);
219 while (running)
221 switch (val = DoMethod(app,MUIM_Application_NewInput,(IPTR)&sigs))
223 case MUIV_Application_ReturnID_Quit:
224 case Push_Abort:
225 quit = TRUE; running = FALSE;
226 break;
227 case Push_Proceed:
228 running = FALSE;
229 break;
230 default:
231 break;
233 sigs = CheckSignal(SIGBREAKF_CTRL_C | sigs);
236 get(st, MUIA_String_Contents, &string);
237 if (strlen(string)==0)
239 get(tst, MUIA_String_Contents, &secret);
240 retval = StrDup(secret);
242 else retval = StrDup(string);
244 DelContents(wc);
246 else
248 retval = StrDup(string);
250 FreeVec(out);
252 return retval;
256 int main()
258 char *string;
259 long int intval;
261 init_gui();
263 for(;;)
265 string = request_string("blah");
266 printf("you entered string <%s>\n",string);
267 FreeVec(string);
268 if(quit) break;
269 intval = request_number(99);
270 printf("you entered number <%ld>\n",intval);
271 if(quit) break;
273 deinit_gui();
275 return 0;