Use hardcoded settings for VIA VT1708S (they are reported to work
[AROS.git] / workbench / prefs / PSI / screenpanel_class.c
blobefd5986450f7044c45d27e89e9c3982f3cb2f93b
1 /*
2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2011, The AROS Development Team.
4 All rights reserved.
6 $Id$
7 */
9 #include <proto/intuition.h>
10 #include <proto/muiscreen.h>
11 #include <proto/muimaster.h>
13 #include <string.h>
15 #include "screenlist_class.h"
16 #include "editwindow_class.h"
17 #include "editpanel_class.h"
18 #include "screenpanel_class.h"
20 /****************************************************************************************/
22 struct ScreenPanel_Data
24 Object *LV_Screens;
25 Object *BT_Create;
26 Object *BT_Copy;
27 Object *BT_Delete;
28 Object *BT_Edit;
29 Object *BT_Open;
30 Object *BT_Close;
31 Object *BT_Jump;
32 #ifdef MYDEBUG
33 Object *BT_Foo;
34 #endif
37 /****************************************************************************************/
39 IPTR ScreenPanel_Finish(struct IClass *cl, Object *obj, struct MUIP_ScreenPanel_Finish *msg)
41 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
42 struct MUI_PubScreenDesc *desc;
43 int i;
44 Object *win = msg->win;
45 BOOL ok = msg->ok;
47 for (i=0; ; i++)
49 DoMethod(data->LV_Screens, MUIM_List_GetEntry, i, &desc);
50 if (!desc)
51 return 0; /* should never happen */
52 if (desc->UserData == win)
53 break;
56 desc->UserData = NULL;
58 if (ok)
60 DoMethod(win, MUIM_EditPanel_GetScreen, desc);
61 desc->Changed = TRUE;
63 DoMethod(data->LV_Screens, MUIM_List_Redraw, i);
64 DoMethod(obj, MUIM_ScreenPanel_SetStates);
66 set(win, MUIA_Window_Open, FALSE);
67 DoMethod((Object *)xget(obj, MUIA_ApplicationObject), OM_REMMEMBER, win);
68 MUI_DisposeObject(win);
70 return 0;
72 /****************************************************************************************/
74 IPTR ScreenPanel_Edit(struct IClass *cl, Object *obj, Msg msg)
76 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
77 struct MUI_PubScreenDesc *desc;
79 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
81 if (desc)
83 set((Object *)xget(obj, MUIA_ApplicationObject), MUIA_Application_Sleep, TRUE);
85 if (!desc->UserData)
87 if ((desc->UserData = (APTR)NewObject(CL_EditWindow->mcc_Class, NULL,
88 MUIA_Window_Width , MUIV_Window_Width_MinMax(0),
89 MUIA_Window_Height, MUIV_Window_Height_MinMax(0),
90 MUIA_EditWindow_Title, desc->Name,
91 MUIA_EditWindow_Originator, obj,
92 TAG_DONE)))
94 DoMethod((Object *)xget(obj, MUIA_ApplicationObject), OM_ADDMEMBER, desc->UserData);
95 DoMethod(desc->UserData,MUIM_EditPanel_SetScreen, desc);
96 DoMethod(data->LV_Screens, MUIM_List_Redraw, MUIV_List_Redraw_Active);
100 if (desc->UserData)
101 set(desc->UserData, MUIA_Window_Open, TRUE);
102 else
103 DisplayBeep(0);
105 set((Object *)xget(obj, MUIA_ApplicationObject), MUIA_Application_Sleep, FALSE);
108 return 0;
111 /****************************************************************************************/
113 IPTR ScreenPanel_Delete(struct IClass *cl, Object *obj, Msg msg)
115 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
116 struct MUI_PubScreenDesc *desc;
118 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
119 if (desc)
121 if (!desc->UserData)
123 MUIS_ClosePubScreen(desc->Name);
124 DoMethod(data->LV_Screens, MUIM_List_Remove, MUIV_List_Remove_Active);
126 else
127 DisplayBeep(0);
130 return 0;
133 /****************************************************************************************/
135 IPTR ScreenPanel_Create(struct IClass *cl, Object *obj, Msg msg)
137 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
138 DoMethod(data->LV_Screens, MUIM_List_InsertSingle, NULL, MUIV_List_Insert_Bottom);
139 set(data->LV_Screens, MUIA_List_Active, MUIV_List_Active_Bottom);
141 return 0;
144 /****************************************************************************************/
146 IPTR ScreenPanel_Copy(struct IClass *cl, Object *obj, Msg msg)
148 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
149 struct MUI_PubScreenDesc *new,*src;
150 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &src);
151 if ((new = MUIS_AllocPubScreenDesc(src)))
153 char namebuf[PSD_MAXLEN_NAME];
154 strcpy(namebuf, new->Name);
155 strcpy(new->Name, ">");
156 stccpy(new->Name + 1, namebuf, PSD_MAXLEN_NAME - 1);
157 DoMethod(data->LV_Screens, MUIM_List_InsertSingle, new, MUIV_List_Insert_Bottom);
158 set(data->LV_Screens, MUIA_List_Active, MUIV_List_Active_Bottom);
159 MUIS_FreePubScreenDesc(new);
161 else
162 DisplayBeep(0);
164 return 0;
167 /****************************************************************************************/
169 IPTR ScreenPanel_SetStates(struct IClass *cl, Object *obj, Msg msg)
171 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
172 struct MUI_PubScreenDesc *desc;
173 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
174 if (desc)
177 if (desc->Foreign)
179 set(data->BT_Copy , MUIA_Disabled, FALSE);
180 set(data->BT_Delete, MUIA_Disabled, FALSE);
181 set(data->BT_Edit , MUIA_Disabled, FALSE);
182 set(data->BT_Open , MUIA_Disabled, TRUE );
183 set(data->BT_Close , MUIA_Disabled, TRUE );
184 set(data->BT_Jump , MUIA_Disabled, FALSE);
186 else
189 BOOL opened = TestPubScreen(desc->Name);
191 set(data->BT_Copy , MUIA_Disabled, FALSE);
192 set(data->BT_Delete, MUIA_Disabled, FALSE);
193 set(data->BT_Edit , MUIA_Disabled, FALSE);
194 set(data->BT_Open , MUIA_Disabled, opened);
195 set(data->BT_Close , MUIA_Disabled, !opened);
196 set(data->BT_Jump , MUIA_Disabled, FALSE);
199 else
201 set(data->BT_Copy , MUIA_Disabled, TRUE);
202 set(data->BT_Delete, MUIA_Disabled, TRUE);
203 set(data->BT_Edit , MUIA_Disabled, TRUE);
204 set(data->BT_Open , MUIA_Disabled, TRUE);
205 set(data->BT_Close , MUIA_Disabled, TRUE);
206 set(data->BT_Jump , MUIA_Disabled, TRUE);
209 return 0;
212 /****************************************************************************************/
214 IPTR ScreenPanel_Close(struct IClass *cl, Object *obj, Msg msg)
216 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
217 struct MUI_PubScreenDesc *desc;
218 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
219 if (!desc || !MUIS_ClosePubScreen(desc->Name))
220 DisplayBeep(0);
222 return 0;
225 /****************************************************************************************/
227 IPTR ScreenPanel_Open(struct IClass *cl, Object *obj, Msg msg)
229 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
230 struct MUI_PubScreenDesc *desc;
231 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
232 if (desc)
234 if (desc->Changed)
236 /* !!! */
238 if (!MUIS_OpenPubScreen(desc))
239 DisplayBeep(0);
241 else
242 DisplayBeep(0);
244 return 0;
247 /****************************************************************************************/
249 IPTR ScreenPanel_Jump(struct IClass *cl, Object *obj, Msg msg)
251 struct ScreenPanel_Data *data = INST_DATA(cl,obj);
252 struct MUI_PubScreenDesc *desc;
253 DoMethod(data->LV_Screens, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &desc);
254 if (desc)
256 if (desc->Changed)
258 /* !!! */
260 DoMethod
262 (Object *)xget(obj, MUIA_ApplicationObject), MUIM_Application_SetConfigItem,
263 MUICFG_PublicScreen, desc->Name
266 else
267 DisplayBeep(0);
269 return 0;
272 /****************************************************************************************/
274 IPTR ScreenPanel_Update(struct IClass *cl, Object *obj, Msg msg)
276 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
277 DoMethod(data->LV_Screens, MUIM_List_Redraw, MUIV_List_Redraw_All);
278 DoMethod(obj, MUIM_ScreenPanel_SetStates);
280 return 0;
283 /****************************************************************************************/
285 IPTR ScreenPanel_New(struct IClass *cl, Object *obj, struct opSet *msg)
287 struct ScreenPanel_Data tmp = {0};
289 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
290 MUIA_Group_Horiz, FALSE,
291 MUIA_Group_VertSpacing, 0,
292 Child, tmp.LV_Screens = ListviewObject,
293 MUIA_CycleChain, 1,
294 MUIA_Listview_List, NewObject
296 CL_ScreenList->mcc_Class, NULL, InputListFrame,
297 MUIA_List_AutoVisible, TRUE,
298 TAG_DONE
300 End,
301 Child, ColGroup(4), GroupSpacing(0), MUIA_Group_SameSize, TRUE,
302 Child, tmp.BT_Create = MakeButton(MSG_BUTTON_NEW),
303 Child, tmp.BT_Copy = MakeButton(MSG_BUTTON_COPY),
304 Child, tmp.BT_Delete = MakeButton(MSG_BUTTON_DELETE),
305 Child, tmp.BT_Edit = MakeButton(MSG_BUTTON_EDIT),
306 Child, tmp.BT_Open = MakeButton(MSG_BUTTON_OPEN),
307 Child, tmp.BT_Close = MakeButton(MSG_BUTTON_CLOSE),
308 Child, tmp.BT_Jump = MakeButton(MSG_BUTTON_JUMP),
309 #ifdef MYDEBUG
310 Child, tmp.BT_Foo = SimpleButton("Foo"),
311 #else
312 Child, HVSpace,
313 #endif
314 End,
315 TAG_DONE);
317 if (obj)
319 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
321 *data = tmp;
323 DoMethod(tmp.BT_Delete, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Delete);
324 DoMethod(tmp.BT_Create, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Create);
325 DoMethod(tmp.BT_Copy , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Copy );
326 DoMethod(tmp.BT_Edit , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Edit );
327 DoMethod(tmp.BT_Open , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Open );
328 DoMethod(tmp.BT_Close , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Close );
329 DoMethod(tmp.BT_Jump , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Jump );
330 #ifdef MYDEBUG
331 DoMethod(tmp.BT_Foo , MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_ScreenPanel_Foo );
332 #endif
333 DoMethod(tmp.LV_Screens, MUIM_Notify, MUIA_Listview_DoubleClick, TRUE, obj, 1, MUIM_ScreenPanel_Edit);
334 DoMethod(tmp.LV_Screens, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, obj, 1, MUIM_ScreenPanel_SetStates);
336 set(tmp.BT_Delete , MUIA_ShortHelp,GetStr(MSG_HELP_DELETESCREEN));
337 set(tmp.BT_Create , MUIA_ShortHelp,GetStr(MSG_HELP_NEWSCREEN ));
338 set(tmp.BT_Copy , MUIA_ShortHelp,GetStr(MSG_HELP_COPYSCREEN ));
339 set(tmp.BT_Edit , MUIA_ShortHelp,GetStr(MSG_HELP_EDITSCREEN ));
340 set(tmp.BT_Open , MUIA_ShortHelp,GetStr(MSG_HELP_OPENSCREEN ));
341 set(tmp.BT_Close , MUIA_ShortHelp,GetStr(MSG_HELP_CLOSESCREEN ));
342 set(tmp.BT_Jump , MUIA_ShortHelp,GetStr(MSG_HELP_JUMPSCREEN ));
343 set(tmp.LV_Screens, MUIA_ShortHelp,GetStr(MSG_HELP_SCREENLIST ));
345 DoMethod(obj, MUIM_ScreenPanel_SetStates);
348 return (IPTR)obj;
351 /****************************************************************************************/
353 IPTR ScreenPanel_Dispose(struct IClass *cl, Object *obj, Msg msg)
355 DoMethod(obj, MUIM_ScreenPanel_CloseWindows);
356 return(DoSuperMethodA(cl, obj, msg));
358 /****************************************************************************************/
360 IPTR ScreenPanel_CloseWindows(struct IClass *cl, Object *obj, Msg msg)
362 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
363 struct MUI_PubScreenDesc *desc;
364 int i;
365 for (i=0; ; i++)
367 DoMethod(data->LV_Screens, MUIM_List_GetEntry, i, &desc);
368 if (!desc)
369 break;
370 if (desc->UserData)
371 DoMethod(obj, MUIM_ScreenPanel_Finish, desc->UserData, FALSE);
374 return 0;
376 /****************************************************************************************/
378 #ifdef MYDEBUG
380 BOOL SavePubScreen(struct MUI_PubScreenDesc *desc)
382 BPTR file;
383 char filename[PSD_MAXLEN_NAME+16];
384 int p;
385 BOOL rc = FALSE;
387 strcpy(filename, "mui:Screens");
388 AddPart(filename, desc->Name, sizeof(filename));
389 strcat(filename, ".mps");
391 if (file = Open(filename,MODE_NEWFILE))
393 FPrintf(file, "T=\"%s\"\n", desc->Title );
394 FPrintf(file, "F=\"%s\"\n", desc->Font );
395 FPrintf(file, "B=\"%s\"\n", desc->Background );
396 FPrintf(file, "W=%ld\n" , desc->DisplayWidth);
397 FPrintf(file, "H=%ld\n" , desc->DisplayHeight);
398 FPrintf(file, "D=%ld\n" , desc->DisplayDepth);
399 FPrintf(file, "I=%ld\n" , desc->DisplayID );
400 if (desc->OverscanType) FPrintf(file, "OS\n");
401 if (desc->AutoScroll ) FPrintf(file, "AS\n");
402 if (desc->NoDrag ) FPrintf(file, "ND\n");
403 if (desc->Exclusive ) FPrintf(file, "EX\n");
404 if (desc->Interleaved ) FPrintf(file, "IN\n");
405 if (desc->SysDefault ) FPrintf(file, "SD\n");
406 if (desc->Behind ) FPrintf(file, "BH\n");
407 if (desc->AutoClose ) FPrintf(file, "AC\n");
408 if (desc->CloseGadget ) FPrintf(file, "CG\n");
410 FPrintf(file, "PEN=\"");
411 for (p = 0; p < PSD_NUMSYSPENS; p++)
412 FPrintf(file, "%ld:%ld ", p, desc->SystemPens[p]);
413 FPrintf(file, "\"\n");
415 FPrintf(file, "PAL=\"");
416 for (p = 0; p < PSD_NUMCOLS; p++)
417 FPrintf
419 file, "%ld:%02lx%02lx%02lx ", p < 4 ? p : p - 8,
420 desc->Palette[p].red >> 24,
421 desc->Palette[p].green >> 24,
422 desc->Palette[p].blue >> 24
424 FPrintf(file, "\"\n");
426 rc = TRUE;
428 Close(file);
431 return rc;
434 /****************************************************************************************/
436 IPTR ScreenPanel_Foo(struct IClass *cl, Object *obj, Msg msg)
438 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
439 struct MUI_PubScreenDesc *desc;
440 int i;
442 for (i = 0; ; i++)
444 int p;
446 DoMethod(data->LV_Screens, MUIM_List_GetEntry, i, &desc);
447 if (!desc)
448 break;
450 printf("N=\"%s\"\n", desc->Name );
451 printf("T=\"%s\"\n", desc->Title );
452 printf("F=\"%s\"\n", desc->Font );
453 printf("B=\"%s\"\n", desc->Background );
454 printf("W=%ld\n" , desc->DisplayWidth);
455 printf("H=%ld\n" , desc->DisplayHeight);
456 printf("D=%ld\n" , desc->DisplayDepth);
457 printf("I=%ld\n" , desc->DisplayID );
458 if (desc->OverscanType) printf("OS\n");
459 if (desc->AutoScroll ) printf("AS\n");
460 if (desc->NoDrag ) printf("ND\n");
461 if (desc->Exclusive ) printf("EX\n");
462 if (desc->Interleaved ) printf("IN\n");
463 if (desc->SysDefault ) printf("SD\n");
464 if (desc->Behind ) printf("BH\n");
465 if (desc->AutoClose ) printf("AC\n");
466 if (desc->CloseGadget ) printf("CG\n");
468 printf("PENS=\"");
469 for (p = 0; p < PSD_NUMSYSPENS; p++)
470 printf("%ld:%ld ", p, desc->SystemPens[p]);
471 printf("\"\n");
473 printf("PALETTE=\"");
474 for (p = 0; p < PSD_NUMCOLS; p++)
475 printf
477 "%ld:%02lx%02lx%02lx ", p < 4 ? p : p - 8,
478 desc->Palette[p].red >> 24,
479 desc->Palette[p].green >> 24,
480 desc->Palette[p].blue >> 24
482 printf("\"\n");
484 printf("\n");
487 if (!desc->Foreign)
489 SavePubScreen(desc);
492 return 0;
494 #endif
496 /****************************************************************************************/
498 BOOPSI_DISPATCHER(IPTR, ScreenPanel_Dispatcher, cl, obj, msg)
500 switch (msg->MethodID)
502 case OM_NEW:
503 return ScreenPanel_New(cl, obj, (APTR)msg);
505 case OM_DISPOSE:
506 return ScreenPanel_Dispose(cl, obj, (APTR)msg);
508 case MUIM_ScreenPanel_Create:
509 return ScreenPanel_Create(cl, obj, (APTR)msg);
511 case MUIM_ScreenPanel_Copy:
512 return ScreenPanel_Copy(cl, obj, (APTR)msg);
514 case MUIM_ScreenPanel_Delete:
515 return ScreenPanel_Delete(cl, obj, (APTR)msg);
517 case MUIM_ScreenPanel_Edit:
518 return ScreenPanel_Edit(cl, obj, (APTR)msg);
520 case MUIM_ScreenPanel_Finish:
521 return ScreenPanel_Finish(cl, obj, (APTR)msg);
523 case MUIM_ScreenPanel_CloseWindows:
524 return ScreenPanel_CloseWindows(cl, obj, (APTR)msg);
526 case MUIM_ScreenPanel_SetStates:
527 return ScreenPanel_SetStates(cl, obj, (APTR)msg);
529 case MUIM_ScreenPanel_Open:
530 return ScreenPanel_Open(cl, obj, (APTR)msg);
532 case MUIM_ScreenPanel_Close:
533 return ScreenPanel_Close(cl, obj, (APTR)msg);
535 case MUIM_ScreenPanel_Jump:
536 return ScreenPanel_Jump(cl, obj, (APTR)msg);
538 case MUIM_ScreenPanel_Update:
539 return ScreenPanel_Update(cl, obj, (APTR)msg);
540 #ifdef MYDEBUG
542 case MUIM_ScreenPanel_Foo:
543 return ScreenPanel_Foo(cl, obj, (APTR)msg);
544 #endif
546 case MUIM_ScreenList_Find:
548 struct ScreenPanel_Data *data = INST_DATA(cl, obj);
549 return(DoMethodA(data->LV_Screens, msg));
553 return DoSuperMethodA(cl,obj,msg);
555 BOOPSI_DISPATCHER_END
557 /****************************************************************************************/
559 VOID ScreenPanel_Init(VOID)
561 CL_ScreenPanel = MUI_CreateCustomClass
563 NULL, MUIC_Group, NULL, sizeof(struct ScreenPanel_Data ), ScreenPanel_Dispatcher
567 VOID ScreenPanel_Exit(VOID)
569 if (CL_ScreenPanel )
570 MUI_DeleteCustomClass(CL_ScreenPanel);