added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / workbench / utilities / Snoopy / gui.c
blob241e7c7424a1830d737dc9810a2def139dfb63cb
1 /*
2 Copyright © 2006-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <aros/debug.h>
9 #include <proto/muimaster.h>
10 #include <libraries/mui.h>
11 #include <proto/intuition.h>
13 #include "main.h"
14 #include "gui.h"
15 #include "setup.h"
16 #include "patches.h"
17 #include "locale.h"
19 #define VERSION "$VER: Snoopy 0.7 (10.11.2007) © 2006-2007 The AROS Dev Team"
21 static Object *app, *window, *saveBtn, *openBtn, *useBtn, *undoBtn, *resetBtn, *cancelBtn;
22 static Object *failCM, *cliCM, *pathCM, *devCM, *ignoreCM;
23 static Object *nameNum, *actionNum, *targetNum, *optionNum;
24 static Object *changeDirCM, *deleteCM, *executeCM, *getVarCM, *loadSegCM, *lockCM, *makeDirCM, *makeLinkCM;
25 static Object *openCM, *renameCM, *runCommandCM, *setVarCM, *systemCM, *findPortCM, *findResidentCM, *findSemaphoreCM;
26 static Object *findTaskCM, *lockScreenCM, *openDeviceCM, *openFontCM, *openLibraryCM, *openResourceCM, *readToolTypesCM;
28 static struct Hook save_hook, open_hook, use_hook, undo_hook, reset_hook, cancel_hook;
30 AROS_UFH3S(void, save_function,
31 AROS_UFHA(struct Hook *, h, A0),
32 AROS_UFHA(Object *, object, A2),
33 AROS_UFHA(APTR, msg, A1))
35 AROS_USERFUNC_INIT
37 oldsetup = setup;
38 gui_get();
39 patches_set();
40 if ( ! setup_save())
42 MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_OK), MSG(MSG_ERROR_SAVE), PREFFILE);
45 AROS_USERFUNC_EXIT
48 AROS_UFH3S(void, open_function,
49 AROS_UFHA(struct Hook *, h, A0),
50 AROS_UFHA(Object *, object, A2),
51 AROS_UFHA(APTR, msg, A1))
53 AROS_USERFUNC_INIT
55 if ( ! setup_open() )
57 MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_OK), MSG(MSG_ERROR_LOAD), PREFFILE);
59 gui_set();
60 patches_set();
62 AROS_USERFUNC_EXIT
65 AROS_UFH3S(void, reset_function,
66 AROS_UFHA(struct Hook *, h, A0),
67 AROS_UFHA(Object *, object, A2),
68 AROS_UFHA(APTR, msg, A1))
70 AROS_USERFUNC_INIT
72 oldsetup = setup;
73 setup_reset();
74 gui_set();
75 patches_set();
77 AROS_USERFUNC_EXIT
80 AROS_UFH3S(void, use_function,
81 AROS_UFHA(struct Hook *, h, A0),
82 AROS_UFHA(Object *, object, A2),
83 AROS_UFHA(APTR, msg, A1))
85 AROS_USERFUNC_INIT
87 oldsetup = setup;
88 gui_get();
89 patches_set();
91 AROS_USERFUNC_EXIT
94 AROS_UFH3S(void, undo_function,
95 AROS_UFHA(struct Hook *, h, A0),
96 AROS_UFHA(Object *, object, A2),
97 AROS_UFHA(APTR, msg, A1))
99 AROS_USERFUNC_INIT
101 setup = oldsetup;
102 gui_set();
103 patches_set();
105 AROS_USERFUNC_EXIT
108 AROS_UFH3S(void, cancel_function,
109 AROS_UFHA(struct Hook *, h, A0),
110 AROS_UFHA(Object *, object, A2),
111 AROS_UFHA(APTR, msg, A1))
113 AROS_USERFUNC_INIT
115 // FIXME: original SnoopDos has a separate task for the patches. When cancelling SnoopDos the GUI
116 // is removed and the patchtask stays in RAM. We can't do that because we have no separate task.
117 // The cancelling function of Snoopy is more for debugging.
118 if (MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_RESET_PATCHES), MSG(MSG_ASK_RESET)))
120 set(saveBtn, MUIA_Disabled, TRUE);
121 set(openBtn, MUIA_Disabled, TRUE);
122 set(useBtn, MUIA_Disabled, TRUE);
123 set(undoBtn, MUIA_Disabled, TRUE);
124 set(resetBtn, MUIA_Disabled, TRUE);
125 set(cancelBtn, MUIA_Disabled, TRUE);
126 patches_reset();
127 if (MUI_Request ( app, window, 0, MSG(MSG_TITLE), MSG(MSG_REMOVE_SNOOP), MSG(MSG_ASK_REMOVE)))
129 DoMethod(app, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
132 AROS_USERFUNC_EXIT
135 void gui_init(void)
137 save_hook.h_Entry = (APTR)save_function;
138 open_hook.h_Entry = (APTR)open_function;
139 use_hook.h_Entry = (APTR)use_function;
140 undo_hook.h_Entry = (APTR)undo_function;
141 reset_hook.h_Entry = (APTR)reset_function;
142 cancel_hook.h_Entry = (APTR)cancel_function;
144 app = ApplicationObject,
145 MUIA_Application_Title, (IPTR) MSG(MSG_TITLE),
146 MUIA_Application_Version, (IPTR) VERSION,
147 MUIA_Application_Copyright, (IPTR) MSG(MSG_COPYRIGHT),
148 MUIA_Application_Author, (IPTR) MSG(MSG_AUTHOR),
149 MUIA_Application_Description, (IPTR) MSG(MSG_DESCRIPTION),
150 MUIA_Application_Base, (IPTR) MSG(MSG_PORTNAME),
151 MUIA_Application_SingleTask, TRUE,
153 SubWindow, (IPTR)(window = WindowObject,
154 MUIA_Window_Title, (IPTR)MSG(MSG_TITLE),
155 MUIA_Window_CloseGadget, FALSE,
156 WindowContents, (IPTR)(VGroup,
157 Child, (IPTR)(HGroup,
158 Child, (IPTR)(VGroup,
159 Child, (IPTR)(ColGroup(2),
160 GroupFrameT(MSG(MSG_SETTINGS)),
161 Child, (IPTR)Label(MSG(MSG_SHOW_FAILS)),
162 Child, (IPTR)(failCM = MUI_MakeObject(MUIO_Checkmark, "")),
163 Child, (IPTR)Label(MSG(MSG_CLI_NUMBER)),
164 Child, (IPTR)(cliCM = MUI_MakeObject(MUIO_Checkmark, "")),
165 Child, (IPTR)Label(MSG(MSG_FULL_PATH)),
166 Child, (IPTR)(pathCM = MUI_MakeObject(MUIO_Checkmark, "")),
167 Child, (IPTR)Label(MSG(MSG_DEVICE)),
168 Child, (IPTR)(devCM = MUI_MakeObject(MUIO_Checkmark, "")),
169 Child, (IPTR)Label(MSG(MSG_IGNORE_WB)),
170 Child, (IPTR)(ignoreCM = MUI_MakeObject(MUIO_Checkmark, "")),
171 Child, (IPTR)HVSpace,
172 Child, (IPTR)HVSpace,
173 End),
174 Child, (IPTR)(ColGroup(2),
175 GroupFrameT(MSG(MSG_OUTPUT_FIELD)),
176 Child, (IPTR)Label(MSG(MSG_NAME)),
177 Child, (IPTR)(nameNum = SliderObject,
178 MUIA_Numeric_Min, 10,
179 MUIA_Numeric_Max, 50,
180 End),
181 Child, (IPTR)Label(MSG(MSG_ACTION)),
182 Child, (IPTR)(actionNum = SliderObject,
183 MUIA_Numeric_Min, 10,
184 MUIA_Numeric_Max, 50,
185 End),
186 Child, (IPTR)Label(MSG(MSG_TARGET)),
187 Child, (IPTR)(targetNum = SliderObject,
188 MUIA_Numeric_Min, 10,
189 MUIA_Numeric_Max, 50,
190 End),
191 Child, (IPTR)Label(MSG(MSG_OPTION)),
192 Child, (IPTR)(optionNum = SliderObject,
193 MUIA_Numeric_Min, 10,
194 MUIA_Numeric_Max, 50,
195 End),
196 End),
197 End),
198 Child, (IPTR)(VGroup,
199 Child, (IPTR)(ColGroup(2),
200 GroupFrameT(MSG(MSG_SYSTEM_FUNC)),
201 Child, (IPTR)Label("FindPort"),
202 Child, (IPTR)(findPortCM = MUI_MakeObject(MUIO_Checkmark, "")),
203 Child, (IPTR)Label("FindResident"),
204 Child, (IPTR)(findResidentCM = MUI_MakeObject(MUIO_Checkmark, "")),
205 Child, (IPTR)Label("FindSemaphore"),
206 Child, (IPTR)(findSemaphoreCM = MUI_MakeObject(MUIO_Checkmark, "")),
207 Child, (IPTR)Label("FindTask"),
208 Child, (IPTR)(findTaskCM = MUI_MakeObject(MUIO_Checkmark, "")),
209 Child, (IPTR)Label("LockScreen"),
210 Child, (IPTR)(lockScreenCM = MUI_MakeObject(MUIO_Checkmark, "")),
211 Child, (IPTR)Label("OpenDevice"),
212 Child, (IPTR)(openDeviceCM = MUI_MakeObject(MUIO_Checkmark, "")),
213 Child, (IPTR)Label("OpenFont"),
214 Child, (IPTR)(openFontCM = MUI_MakeObject(MUIO_Checkmark, "")),
215 Child, (IPTR)Label("OpenLibrary"),
216 Child, (IPTR)(openLibraryCM = MUI_MakeObject(MUIO_Checkmark, "")),
217 Child, (IPTR)Label("OpenResource"),
218 Child, (IPTR)(openResourceCM = MUI_MakeObject(MUIO_Checkmark, "")),
219 Child, (IPTR)Label("ReadToolTypes"),
220 Child, (IPTR)(readToolTypesCM = MUI_MakeObject(MUIO_Checkmark, "")),
221 Child, (IPTR)HVSpace,
222 Child, (IPTR)HVSpace,
223 End),
224 End),
225 Child, (IPTR)(VGroup,
226 Child, (IPTR)(ColGroup(2),
227 GroupFrameT(MSG(MSG_DOS_FUNC)),
228 Child, (IPTR)Label("ChangeDir"),
229 Child, (IPTR)(changeDirCM = MUI_MakeObject(MUIO_Checkmark, "")),
230 Child, (IPTR)Label("Delete"),
231 Child, (IPTR)(deleteCM = MUI_MakeObject(MUIO_Checkmark, "")),
232 Child, (IPTR)Label("Execute"),
233 Child, (IPTR)(executeCM = MUI_MakeObject(MUIO_Checkmark, "")),
234 Child, (IPTR)Label("GetVar"),
235 Child, (IPTR)(getVarCM = MUI_MakeObject(MUIO_Checkmark, "")),
236 Child, (IPTR)Label("LoadSeg"),
237 Child, (IPTR)(loadSegCM = MUI_MakeObject(MUIO_Checkmark, "")),
238 Child, (IPTR)Label("Lock"),
239 Child, (IPTR)(lockCM = MUI_MakeObject(MUIO_Checkmark, "")),
240 Child, (IPTR)Label("MakeDir"),
241 Child, (IPTR)(makeDirCM = MUI_MakeObject(MUIO_Checkmark, "")),
242 Child, (IPTR)Label("MakeLink"),
243 Child, (IPTR)(makeLinkCM = MUI_MakeObject(MUIO_Checkmark, "")),
244 Child, (IPTR)Label("Open"),
245 Child, (IPTR)(openCM = MUI_MakeObject(MUIO_Checkmark, "")),
246 Child, (IPTR)Label("Rename"),
247 Child, (IPTR)(renameCM = MUI_MakeObject(MUIO_Checkmark, "")),
248 Child, (IPTR)Label("RunCommand"),
249 Child, (IPTR)(runCommandCM = MUI_MakeObject(MUIO_Checkmark, "")),
250 Child, (IPTR)Label("SetVar"),
251 Child, (IPTR)(setVarCM = MUI_MakeObject(MUIO_Checkmark, "")),
252 Child, (IPTR)Label("System"),
253 Child, (IPTR)(systemCM = MUI_MakeObject(MUIO_Checkmark, "")),
254 Child, (IPTR)HVSpace,
255 Child, (IPTR)HVSpace,
256 End),
257 End),
258 End),
259 Child, (IPTR) (RectangleObject,
260 MUIA_Rectangle_HBar, TRUE,
261 MUIA_FixHeight, 2,
262 End),
263 Child, (IPTR)(HGroup,
264 Child, (IPTR)(saveBtn = SimpleButton(MSG(MSG_SAVE))),
265 Child, (IPTR)(openBtn = SimpleButton(MSG(MSG_OPEN))),
266 Child, (IPTR)HVSpace,
267 Child, (IPTR)(useBtn = SimpleButton(MSG(MSG_USE))),
268 Child, (IPTR)(undoBtn = SimpleButton(MSG(MSG_UNDO))),
269 Child, (IPTR)(resetBtn = SimpleButton(MSG(MSG_RESET))),
270 Child, (IPTR)HVSpace,
271 Child, (IPTR)(cancelBtn = SimpleButton(MSG(MSG_CANCEL))),
272 End),
273 End), // WindowContents
274 End), // WindowObject
275 End; // ApplicationObject
277 if ( ! app)
279 D(bug("Cant create application\n"));
280 return;
283 // disable unavailable functions
284 set(pathCM, MUIA_Disabled, TRUE);
285 set(devCM, MUIA_Disabled, TRUE);
287 gui_set();
288 set(window, MUIA_Window_Open, TRUE);
290 DoMethod(saveBtn, MUIM_Notify, MUIA_Pressed, FALSE,
291 (IPTR)app, 2, MUIM_CallHook, (IPTR)&save_hook);
293 DoMethod(openBtn, MUIM_Notify, MUIA_Pressed, FALSE,
294 (IPTR)app, 2, MUIM_CallHook, (IPTR)&open_hook);
296 DoMethod(useBtn, MUIM_Notify, MUIA_Pressed, FALSE,
297 (IPTR)app, 2, MUIM_CallHook, (IPTR)&use_hook);
299 DoMethod(undoBtn, MUIM_Notify, MUIA_Pressed, FALSE,
300 (IPTR)app, 2, MUIM_CallHook, (IPTR)&undo_hook);
302 DoMethod(resetBtn, MUIM_Notify, MUIA_Pressed, FALSE,
303 (IPTR)app, 2, MUIM_CallHook, (IPTR)&reset_hook);
305 DoMethod(cancelBtn, MUIM_Notify, MUIA_Pressed, FALSE,
306 (IPTR)app, 2, MUIM_CallHook, (IPTR)&cancel_hook);
309 void gui_handleevents(void)
311 DoMethod(app, MUIM_Application_Execute);
314 void gui_cleanup(void)
316 MUI_DisposeObject(app);
319 void gui_set(void)
321 set(failCM, MUIA_Selected, setup.onlyShowFails);
322 set(cliCM, MUIA_Selected, setup.showCliNr);
323 set(pathCM, MUIA_Selected, setup.showPaths);
324 set(devCM, MUIA_Selected, setup.useDevNames);
325 set(ignoreCM, MUIA_Selected, setup.ignoreWB);
327 set(changeDirCM, MUIA_Selected, setup.enableChangeDir);
328 set(deleteCM, MUIA_Selected, setup.enableDelete);
329 set(executeCM, MUIA_Selected, setup.enableExecute);
330 set(getVarCM, MUIA_Selected, setup.enableGetVar);
331 set(loadSegCM, MUIA_Selected, setup.enableLoadSeg);
332 set(lockCM, MUIA_Selected, setup.enableLock);
333 set(makeDirCM, MUIA_Selected, setup.enableMakeDir);
334 set(makeLinkCM, MUIA_Selected, setup.enableMakeLink);
335 set(openCM, MUIA_Selected, setup.enableOpen);
336 set(renameCM, MUIA_Selected, setup.enableRename);
337 set(runCommandCM, MUIA_Selected, setup.enableRunCommand);
338 set(setVarCM, MUIA_Selected, setup.enableSetVar);
339 set(systemCM, MUIA_Selected, setup.enableSystem);
341 set(findPortCM, MUIA_Selected, setup.enableFindPort);
342 set(findResidentCM, MUIA_Selected, setup.enableFindResident);
343 set(findSemaphoreCM, MUIA_Selected, setup.enableFindSemaphore);
344 set(findTaskCM, MUIA_Selected, setup.enableFindTask);
345 set(lockScreenCM, MUIA_Selected, setup.enableLockScreen);
346 set(openDeviceCM, MUIA_Selected, setup.enableOpenDevice);
347 set(openFontCM, MUIA_Selected, setup.enableOpenFont);
348 set(openLibraryCM, MUIA_Selected, setup.enableOpenLibrary);
349 set(openResourceCM, MUIA_Selected, setup.enableOpenResource);
350 set(readToolTypesCM, MUIA_Selected, setup.enableReadToolTypes);
352 set(nameNum, MUIA_Numeric_Value, setup.nameLen);
353 set(actionNum, MUIA_Numeric_Value, setup.actionLen);
354 set(targetNum, MUIA_Numeric_Value, setup.targetLen);
355 set(optionNum, MUIA_Numeric_Value, setup.optionLen);
358 void gui_get(void)
360 setup.onlyShowFails = XGET(failCM, MUIA_Selected);
361 setup.showCliNr = XGET(cliCM, MUIA_Selected);
362 setup.showPaths = XGET(pathCM, MUIA_Selected);
363 setup.useDevNames = XGET(devCM, MUIA_Selected);
364 setup.ignoreWB = XGET(ignoreCM, MUIA_Selected);
366 setup.enableChangeDir = XGET(changeDirCM, MUIA_Selected);
367 setup.enableDelete = XGET(deleteCM, MUIA_Selected);
368 setup.enableExecute = XGET(executeCM, MUIA_Selected);
369 setup.enableGetVar = XGET(getVarCM, MUIA_Selected);
370 setup.enableLoadSeg = XGET(loadSegCM, MUIA_Selected);
371 setup.enableLock = XGET(lockCM, MUIA_Selected);
372 setup.enableMakeDir = XGET(makeDirCM, MUIA_Selected);
373 setup.enableMakeLink = XGET(makeLinkCM, MUIA_Selected);
374 setup.enableOpen = XGET(openCM, MUIA_Selected);
375 setup.enableRename = XGET(renameCM, MUIA_Selected);
376 setup.enableRunCommand = XGET(runCommandCM, MUIA_Selected);
377 setup.enableSetVar = XGET(setVarCM, MUIA_Selected);
378 setup.enableSystem = XGET(systemCM, MUIA_Selected);
380 setup.enableFindPort = XGET(findPortCM, MUIA_Selected);
381 setup.enableFindResident = XGET(findResidentCM, MUIA_Selected);
382 setup.enableFindSemaphore = XGET(findSemaphoreCM, MUIA_Selected);
383 setup.enableFindTask = XGET(findTaskCM, MUIA_Selected);
384 setup.enableLockScreen = XGET(lockScreenCM, MUIA_Selected);
385 setup.enableOpenDevice = XGET(openDeviceCM, MUIA_Selected);
386 setup.enableOpenFont = XGET(openFontCM, MUIA_Selected);
387 setup.enableOpenLibrary = XGET(openLibraryCM, MUIA_Selected);
388 setup.enableOpenResource = XGET(openResourceCM, MUIA_Selected);
389 setup.enableReadToolTypes = XGET(readToolTypesCM, MUIA_Selected);
391 setup.nameLen = XGET(nameNum, MUIA_Numeric_Value);
392 setup.actionLen = XGET(actionNum, MUIA_Numeric_Value);
393 setup.targetLen = XGET(targetNum, MUIA_Numeric_Value);
394 setup.optionLen = XGET(optionNum, MUIA_Numeric_Value);