revert between 56095 -> 55830 in arch
[AROS.git] / workbench / prefs / PSI / psi.c
blobc69c476642864b1d2bf25c861e271ff38df4034c
1 /*
2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2016, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #include <proto/exec.h>
10 #include <proto/dos.h>
11 #include <proto/gadtools.h>
12 #include <proto/locale.h>
13 #include <proto/intuition.h>
14 #include <proto/muimaster.h>
15 #include <proto/muiscreen.h>
17 #include <string.h>
18 #include <stdlib.h>
20 #include "psi.h"
21 #include "displayidinfo_class.h"
22 #include "displayidlist_class.h"
23 #include "editpanel_class.h"
24 #include "editwindow_class.h"
25 #include "mainwindow_class.h"
26 #include "screenlist_class.h"
27 #include "screenpanel_class.h"
28 #include "syspenfield_class.h"
30 /****************************************************************************/
31 /* Global Vars */
32 /****************************************************************************/
34 const char VersionString[] = "$VER: PSI 20.1 (10.06.2010)";
35 struct Catalog *Catalog;
37 /****************************************************************************/
38 /* Locale Stuff */
39 /****************************************************************************/
41 #define CATALOG_NAME "System/Prefs/PSI.catalog"
42 #define CATALOG_VERSION 19
44 /****************************************************************************************/
46 CONST_STRPTR GetStr(int num)
48 struct CatCompArrayType *cca = (struct CatCompArrayType *)CatCompArray;
49 while (cca->cca_ID != num) cca++;
50 if (LocaleBase)
51 return GetCatalogStr(Catalog,num,cca->cca_Str);
53 return (char *)cca->cca_Str;
56 /****************************************************************************************/
58 VOID LocalizeStringArray(CONST_STRPTR *array)
60 CONST_STRPTR *x;
61 for (x = array; *x; x++)
62 *x = GetStr((int)(IPTR)*x);
65 /****************************************************************************************/
67 VOID LocalizeNewMenu(struct NewMenu *nm)
69 for ( ; nm->nm_Type != NM_END; nm++)
70 if (nm->nm_Label != NM_BARLABEL)
71 nm->nm_Label = GetStr((int)(IPTR)nm->nm_Label);
74 /****************************************************************************************/
76 VOID InitLocale(VOID)
78 Catalog = OpenCatalog(NULL, CATALOG_NAME, OC_Version, CATALOG_VERSION, TAG_DONE);
80 LocalizeNewMenu(MainMenu);
81 LocalizeNewMenu(PaletteMenu);
82 /*LocalizeNewMenu(EditMenu);*/
83 LocalizeStringArray(CYA_Overscan);
84 LocalizeStringArray(CYA_EditPages);
87 /****************************************************************************************/
89 VOID ExitLocale(VOID)
91 if (Catalog)
93 CloseCatalog(Catalog);
94 Catalog = NULL;
99 /****************************************************************************/
100 /* Misc Help Functions */
101 /****************************************************************************/
103 IPTR xget(Object *obj, IPTR attribute)
105 IPTR x = 0;
106 get(obj, attribute, &x);
107 return x;
110 /****************************************************************************************/
112 char *getstr(Object *obj)
114 return (char *)xget(obj,MUIA_String_Contents);
117 /****************************************************************************************/
119 BOOL getbool(Object *obj)
121 return (BOOL)xget(obj, MUIA_Selected);
124 /****************************************************************************************/
126 VOID setstr(APTR str, LONG num)
128 DoMethod(str, MUIM_SetAsString, MUIA_String_Contents, "%ld", num);
131 /****************************************************************************************/
133 VOID settxt(APTR str, LONG num)
135 DoMethod(str, MUIM_SetAsString, MUIA_Text_Contents, "%ld", num);
138 /****************************************************************************************/
140 Object *MakeCheck(int num)
142 Object *obj = MUI_MakeObject(MUIO_Checkmark, GetStr(num));
143 if (obj)
144 set(obj, MUIA_CycleChain, 1);
146 return obj;
149 /****************************************************************************************/
151 Object *MakeButton(int num)
153 Object *obj = MUI_MakeObject(MUIO_Button, GetStr(num));
154 if (obj)
155 set(obj, MUIA_CycleChain, 1);
157 return obj;
160 /****************************************************************************************/
163 Object *MakeBackground(int num)
165 Object *obj;
167 obj = MUI_NewObject(MUIC_Popimage,
168 MUIA_Imageadjust_Type, MUIV_Imageadjust_Type_Background,
169 MUIA_Window_Title, "Adjust Screen Background",
170 MUIA_CycleChain, 1,
171 TAG_DONE);
173 return(obj);
177 /****************************************************************************************/
179 Object *MakeString(int maxlen,int num)
181 Object *obj = MUI_MakeObject(MUIO_String, GetStr(num), maxlen);
183 if (obj)
185 SetAttrs
187 obj,
188 MUIA_CycleChain, 1,
189 MUIA_String_AdvanceOnCR, TRUE,
190 TAG_DONE
194 return obj;
197 /****************************************************************************************/
199 Object *MakeCycle(CONST_STRPTR *array, int num)
201 Object *obj = MUI_MakeObject(MUIO_Cycle, GetStr(num), array);
202 if (obj)
203 set(obj, MUIA_CycleChain, 1);
205 return obj;
208 /****************************************************************************************/
210 Object *MakeSlider(int min, int max, int num)
212 Object *obj = MUI_MakeObject(MUIO_Slider, GetStr(num), min,max);
213 if (obj)
214 set(obj, MUIA_CycleChain, 1);
216 return obj;
219 /****************************************************************************************/
221 Object *MakeCLabel(int num)
223 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_Centered);
226 /****************************************************************************************/
228 Object *MakeLabel(int num)
230 return MUI_MakeObject(MUIO_Label, GetStr(num),0);
233 /****************************************************************************************/
235 Object *MakeLabel1(int num)
237 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_SingleFrame);
240 /****************************************************************************************/
242 Object *MakeLabel2(int num)
244 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_DoubleFrame);
247 Object *MakeLLabel(int num)
249 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_LeftAligned);
252 /****************************************************************************************/
254 Object *MakeLLabel1(int num)
256 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_LeftAligned | MUIO_Label_SingleFrame);
259 Object *MakeFreeLabel(int num)
261 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_FreeVert);
264 /****************************************************************************************/
266 Object *MakeFreeLLabel(int num)
268 return MUI_MakeObject(MUIO_Label, GetStr(num), MUIO_Label_FreeVert | MUIO_Label_LeftAligned);
271 /****************************************************************************************/
273 BOOL TestPubScreen(char *name)
275 struct List *pslist;
276 struct PubScreenNode *psn,*succ;
277 BOOL res = FALSE;
278 pslist = LockPubScreenList();
279 ForEntries(pslist,psn,succ)
281 if (!stricmp(psn->psn_Node.ln_Name,name))
283 res = TRUE;
284 break;
287 UnlockPubScreenList();
289 return res;
293 /****************************************************************************/
294 /* Init/Exit Functions */
295 /****************************************************************************/
297 VOID ExitClasses(VOID)
299 DispIDinfo_Exit();
300 DispIDlist_Exit();
301 EditPanel_Exit();
302 EditWindow_Exit();
303 MainWindow_Exit();
304 ScreenList_Exit();
305 ScreenPanel_Exit();
306 SysPenField_Exit();
309 /****************************************************************************************/
311 BOOL InitClasses(VOID)
313 DispIDinfo_Init();
314 DispIDlist_Init();
315 EditPanel_Init();
316 EditWindow_Init();
317 MainWindow_Init();
318 ScreenList_Init();
319 ScreenPanel_Init();
320 SysPenField_Init();
324 CL_SysPenField && CL_EditWindow && CL_EditPanel && CL_DispIDlist
325 && CL_DispIDinfo && CL_ScreenList && CL_ScreenPanel && CL_MainWindow
327 return TRUE;
329 ExitClasses();
331 return FALSE;
334 /****************************************************************************************/
336 const char CLITemplate[] = "NAME,OPEN/S,CLOSE/S";
338 const char CLIHelp[] = "\
340 Usage: PSI <name> OPEN/CLOSE\n\
341 <name>: name of (preconfigured) public screen\n\
342 OPEN : open this public screen\n\
343 CLOSE: close this public screen\n\
346 /****************************************************************************************/
348 LONG HandleArgs(Object *mainwin)
350 struct MUI_PubScreenDesc *desc;
351 struct RDArgs *rda,*rdas;
352 LONG msg = 0;
353 struct CLIArgs
355 char *Name;
356 IPTR Open;
357 IPTR Close;
358 } argarray = { 0,0,0 };
360 if ((rdas = AllocDosObject(DOS_RDARGS, NULL)))
362 rdas->RDA_ExtHelp = (char *)CLIHelp;
364 if ((rda = ReadArgs((char *)CLITemplate, (IPTR *)&argarray,rdas)))
366 if (argarray.Name)
368 DoMethod(mainwin, MUIM_ScreenList_Find, argarray.Name, &desc);
370 if (argarray.Open)
372 if (!desc)
373 msg = MSG_CLI_SCREENNOTFOUND;
374 else if (MUIS_OpenPubScreen(desc))
375 msg = MSG_CLI_SCREENOPENED;
376 else
377 msg = MSG_CLI_SCREENOPENFAILED;
379 else if (argarray.Close)
381 if (!desc)
382 msg = MSG_CLI_SCREENNOTFOUND;
383 else if (MUIS_ClosePubScreen(desc->Name))
384 msg = MSG_CLI_SCREENCLOSED;
385 else
386 msg = MSG_CLI_SCREENCLOSEFAILED;
389 else
391 if (argarray.Open || argarray.Close)
392 msg = MSG_CLI_SYNTAXERROR;
394 FreeArgs(rda);
396 FreeDosObject(DOS_RDARGS,rdas);
398 else
399 msg = MSG_CLI_OUTOFMEMORY;
401 return msg;
405 /****************************************************************************/
406 /* Main Program */
407 /****************************************************************************/
409 int main(int argc, char *argv[])
411 struct MUIS_InfoClient sic;
412 ULONG sigs=0;
413 Object *app;
414 Object *win;
415 int res;
416 int msg;
418 InitLocale();
420 if (InitClasses())
422 app = ApplicationObject,
423 MUIA_Application_Title , "PSI",
424 MUIA_Application_Version , VersionString,
425 MUIA_Application_Copyright , "©1995-97, Stefan Stuntz",
426 MUIA_Application_Author , "Stefan Stuntz",
427 MUIA_Application_Description, "Public Screen Inspector",
428 MUIA_Application_SingleTask , TRUE,
429 MUIA_Application_Base , "PSI",
430 MUIA_Application_Window , win = NewObject(CL_MainWindow->mcc_Class, NULL, TAG_DONE),
431 End;
433 if (app)
435 if (argc == 0)
436 msg = 0;
437 else
438 msg = HandleArgs(win);
440 if (!msg)
442 set(win, MUIA_Window_Open, TRUE);
444 /* special magic to keep track about public screen open/close status */
445 sic.task = FindTask(NULL);
446 sic.sigbit = SIGBREAKF_CTRL_E;
447 MUIS_AddInfoClient(&sic);
449 while (DoMethod(app, MUIM_Application_NewInput, &sigs) != MUIV_Application_ReturnID_Quit)
451 if (sigs)
453 sigs = Wait(sigs | SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_E | SIGBREAKF_CTRL_F);
455 /* quit when receiving break from console */
456 if (sigs & SIGBREAKF_CTRL_C)
457 break;
459 /* update listview whenever a screen was opened/closed */
460 if (sigs & SIGBREAKF_CTRL_E)
461 DoMethod(win, MUIM_ScreenPanel_Update);
463 /* deiconify & activate on ctrl-f just like the other prefs programs */
464 if (sigs & SIGBREAKF_CTRL_F)
466 set(app, MUIA_Application_Iconified, FALSE);
467 set(win, MUIA_Window_Open, TRUE);
472 MUIS_RemInfoClient(&sic);
474 DoMethod(win, MUIM_ScreenPanel_CloseWindows);
475 set(win, MUIA_Window_Open, FALSE);
477 MUI_DisposeObject(app);
479 else msg = MSG_CLI_NOAPPLICATION;
480 ExitClasses();
482 else msg = MSG_CLI_OUTOFMEMORY;
484 if (msg)
486 CONST_STRPTR str = GetStr(msg);
487 char *c = strchr(str,'(');
488 Write(Output(),str,strlen(str));
489 res = c ? atol(c+1) : RETURN_OK;
490 if (argc == 0)
491 Delay(100);
493 else
494 res = RETURN_OK;
496 ExitLocale();
497 /*return(res);*/
498 exit(res);