Better GUI layout.
[AROS.git] / workbench / c / R / gui.c
blob69d58f6c7843976ce8c9860cc6d247b49cb7b763
1 /*
2 Copyright © 2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <libraries/mui.h>
7 #include <libraries/asl.h>
9 #include <proto/muimaster.h>
10 #include <proto/intuition.h>
11 #include <proto/exec.h>
12 #include <proto/alib.h>
14 #include <stdio.h>
16 #define DEBUG 1
17 #include <aros/debug.h>
19 #include "r.h"
21 #define ID_OK (99)
23 Object *application, *window;
24 struct Hook execute_btn_hook;
27 AROS_UFH3(void, execute_btn_func,
28 AROS_UFHA(struct Hook *, h, A0),
29 AROS_UFHA(Object *, object, A2),
30 AROS_UFHA(struct Req **, msg, A1))
32 AROS_USERFUNC_INIT
34 D(bug("[R/execute_btn_func] msg %p *msg %p\n", msg, *msg));
35 (*msg)->do_execute = TRUE;
36 DoMethod(application, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
38 AROS_USERFUNC_EXIT
42 BOOL create_gui(struct Req *req)
44 Object *ok_btn, *cancel_btn, *str_group, *chk_group;
45 struct TagItem str_group_tags[50];
46 struct TagItem chk_group_tags[50];
48 LONG i, str_cnt, chk_cnt;
50 execute_btn_hook.h_Entry = (HOOKFUNC)execute_btn_func;
54 bug(" i Name A F K M N S T\n");
55 for (i = 0; i < req->arg_cnt; i++)
57 bug
59 "%2d %25s %c %c %c %c %c %c\n",
60 i, req->cargs[i].argname,
61 req->cargs[i].a_flag ? 'X' : '-',
62 req->cargs[i].f_flag ? 'X' : '-',
63 req->cargs[i].k_flag ? 'X' : '-',
64 req->cargs[i].m_flag ? 'X' : '-',
65 req->cargs[i].n_flag ? 'X' : '-',
66 req->cargs[i].s_flag ? 'X' : '-',
67 req->cargs[i].t_flag ? 'X' : '-'
72 for
74 i = 0, str_cnt = 0, chk_cnt = 0;
75 i < req->arg_cnt && str_cnt < 40 && chk_cnt < 40;
76 i++
79 Object *new_obj = NULL;
80 Object *new_arg_obj = NULL; // the object with the argument's value
82 if (req->cargs[i].s_flag || req->cargs[i].t_flag) // Switch
84 new_obj = Label(req->cargs[i].argname);
85 if (new_obj)
87 chk_group_tags[chk_cnt].ti_Tag = Child;
88 chk_group_tags[chk_cnt].ti_Data = (IPTR)new_obj;
89 chk_cnt++;
91 new_arg_obj = MUI_MakeObject(MUIO_Checkmark, NULL);
92 if (new_arg_obj)
94 chk_group_tags[chk_cnt].ti_Tag = Child;
95 chk_group_tags[chk_cnt].ti_Data = (IPTR)new_arg_obj;
96 req->cargs[i].object = new_arg_obj;
97 chk_cnt++;
100 else if (req->cargs[i].n_flag) // Numeric
102 new_obj = Label(req->cargs[i].argname);
103 if (new_obj)
105 str_group_tags[str_cnt].ti_Tag = Child;
106 str_group_tags[str_cnt].ti_Data = (IPTR)new_obj;
107 str_cnt++;
109 new_arg_obj = StringObject,
110 StringFrame,
111 MUIA_CycleChain, 1,
112 MUIA_String_Accept , "+-0123456879",
113 End;
114 if (new_arg_obj)
116 str_group_tags[str_cnt].ti_Tag = Child;
117 str_group_tags[str_cnt].ti_Data = (IPTR)new_arg_obj;
118 req->cargs[i].object = new_arg_obj;
119 str_cnt++;
122 else if (req->cargs[i].m_flag) // Multiple
124 new_obj = Label(req->cargs[i].argname);
125 if (new_obj)
127 str_group_tags[str_cnt].ti_Tag = Child;
128 str_group_tags[str_cnt].ti_Data = (IPTR)new_obj;
129 str_cnt++;
131 new_arg_obj = PopaslObject,
132 MUIA_Popasl_Type, ASL_FileRequest,
133 ASLFR_DoMultiSelect, TRUE,
134 MUIA_Popstring_String, (IPTR)(new_arg_obj = StringObject,
135 StringFrame,
136 MUIA_CycleChain, 1,
137 End),
138 MUIA_Popstring_Button, (IPTR)PopButton(MUII_PopUp),
139 End;
140 if (new_arg_obj)
142 str_group_tags[str_cnt].ti_Tag = Child;
143 str_group_tags[str_cnt].ti_Data = (IPTR)new_arg_obj;
144 req->cargs[i].object = new_arg_obj;
145 str_cnt++;
148 else
150 new_obj = Label(req->cargs[i].argname);
151 if (new_obj)
153 str_group_tags[str_cnt].ti_Tag = Child;
154 str_group_tags[str_cnt].ti_Data = (IPTR)new_obj;
155 str_cnt++;
157 new_arg_obj = PopaslObject,
158 MUIA_Popasl_Type, ASL_FileRequest,
159 MUIA_Popstring_String, (IPTR)(new_arg_obj = StringObject,
160 StringFrame,
161 MUIA_CycleChain, 1,
162 End),
163 MUIA_Popstring_Button, (IPTR)PopButton(MUII_PopUp),
164 End;
165 if (new_arg_obj)
167 str_group_tags[str_cnt].ti_Tag = Child;
168 str_group_tags[str_cnt].ti_Data = (IPTR)new_arg_obj;
169 req->cargs[i].object = new_arg_obj;
170 str_cnt++;
175 // create string group
176 str_group_tags[str_cnt].ti_Tag = MUIA_Group_Columns;
177 str_group_tags[str_cnt].ti_Data = 2;
178 str_cnt++;
179 str_group_tags[str_cnt].ti_Tag = TAG_DONE;
180 str_group = MUI_NewObjectA(MUIC_Group, str_group_tags);
182 // fill empty check slots
183 for (i = 0; i < chk_cnt % 8; i++)
185 chk_group_tags[chk_cnt].ti_Tag = Child;
186 chk_group_tags[chk_cnt].ti_Data = (IPTR)HVSpace;
187 chk_cnt++;
190 // create check group
191 chk_group_tags[chk_cnt].ti_Tag = MUIA_Group_Columns;
192 chk_group_tags[chk_cnt].ti_Data = 8;
193 chk_cnt++;
194 chk_group_tags[chk_cnt].ti_Tag = TAG_DONE;
195 chk_group = MUI_NewObjectA(MUIC_Group, chk_group_tags);
197 application = (Object *)ApplicationObject,
198 MUIA_Application_Title, "R", //__(MSG_TITLE),
199 MUIA_Application_Version, (IPTR) VERSION,
200 MUIA_Application_Description, "R", //__(MSG_TITLE),
201 MUIA_Application_Base, (IPTR) "REQUEST",
202 MUIA_Application_UseCommodities, FALSE,
203 SubWindow, (IPTR)(window = (Object *)WindowObject,
204 MUIA_Window_Title, "R - The GUI Generator", //__(MSG_TITLE),
205 MUIA_Window_ID, MAKE_ID('R','E','Q','U'),
206 WindowContents, VGroup,
207 Child, VGroup,
208 GroupFrame,
209 Child, str_group,
210 Child, HVSpace,
211 Child, chk_group,
212 End,
213 Child, (IPTR) (RectangleObject,
214 MUIA_Rectangle_HBar, TRUE,
215 MUIA_FixHeight, 2,
216 End),
217 Child, HGroup,
218 MUIA_Group_SameWidth, TRUE,
219 Child, ok_btn = SimpleButton("Execute"),
220 Child, HVSpace,
221 Child, cancel_btn = SimpleButton("Cancel"),
222 End,
223 End,
224 End),
225 End;
227 if (application)
229 DoMethod
231 window,
232 MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
233 (IPTR)application, 2,
234 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
237 DoMethod
239 cancel_btn,
240 MUIM_Notify, MUIA_Pressed, FALSE,
241 (IPTR)application, 2,
242 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit
245 DoMethod
247 ok_btn,
248 MUIM_Notify, MUIA_Pressed, FALSE,
249 (IPTR)application, 3,
250 MUIM_CallHook, &execute_btn_hook, req
253 SET(window, MUIA_Window_Open, TRUE);
255 return TRUE;
257 return FALSE;
261 BOOL handle_gui(struct Req *req)
263 DoMethod(application, MUIM_Application_Execute);
264 SET(window, MUIA_Window_Open, FALSE);
265 return req->do_execute;
269 BOOL get_gui_bool(struct CArg *carg)
271 return XGET(carg->object, MUIA_Selected);
275 CONST_STRPTR get_gui_string(struct CArg *carg)
277 return (CONST_STRPTR)XGET(carg->object, MUIA_String_Contents);
281 void cleanup_gui(void)
283 if (application) MUI_DisposeObject(application);