2 Copyright © 1995-1997 Stefan Stuntz.
3 Copyright © 2009-2011, The AROS Development Team.
9 #include <proto/muiscreen.h>
10 #include <proto/graphics.h>
11 #include <proto/alib.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
15 #include <datatypes/pictureclass.h>
20 #include "screenlist_class.h"
22 #define USE_PSI_SCREENON_HEADER
23 #define USE_PSI_SCREENON_BODY
24 #define USE_PSI_SCREENON_COLORS
25 #include "psi_screenon.bh"
28 #define USE_PSI_SCREENOF_BODY
29 #include "psi_screenof.bh"
32 #define USE_PSI_SCREENCN_BODY
33 #include "psi_screencn.bh"
36 #define USE_PSI_SCREENCF_BODY
37 #include "psi_screencf.bh"
40 /****************************************************************************************/
42 struct ScreenList_Data
53 struct Hook DisplayHook
;
56 /****************************************************************************************/
58 IPTR
ScreenList_ConstructFunc(struct Hook
*hook
, APTR pool
, struct MUI_PubScreenDesc
*src
)
60 struct MUI_PubScreenDesc
*desc
;
62 if ((desc
= MUIS_AllocPubScreenDesc(src
)))
64 desc
->Changed
= FALSE
;
65 desc
->UserData
= NULL
;
71 /****************************************************************************************/
73 VOID
ScreenList_DestructFunc(struct Hook
*hook
, APTR pool
, struct MUI_PubScreenDesc
*desc
)
75 MUIS_FreePubScreenDesc(desc
);
78 /****************************************************************************************/
80 LONG
ScreenList_CompareFunc(struct Hook
*hook
, struct MUI_PubScreenDesc
*d2
, struct MUI_PubScreenDesc
*d1
)
82 if (!strcmp(d1
->Name
, PSD_INITIAL_NAME
))
83 return strcmp(d2
->Name
, PSD_INITIAL_NAME
) ? 1 : 0;
84 else if (!strcmp(d2
->Name
, PSD_INITIAL_NAME
))
87 return stricmp(d1
->Name
, d2
->Name
);
90 /****************************************************************************************/
92 LONG
ScreenList_DisplayFunc(struct Hook
*hook
, char **array
, struct MUI_PubScreenDesc
*desc
)
94 struct ScreenList_Data
*data
= (APTR
)hook
->h_Data
;
100 static char buf1
[30], buf2
[30];
101 strcpy(buf1
, "\33b\33u");
102 strcpy(buf2
, "\33b\33u");
103 strcat(buf1
, GetStr(MSG_LIST_SCREENNAME
));
104 strcat(buf2
, GetStr(MSG_LIST_SCREENMODE
));
111 static struct NameInfo ni
;
112 static char buf1
[PSD_MAXLEN_NAME
+2];
113 static char buf2
[50];
115 strcpy(buf1
, desc
->UserData
? "\33b" : desc
->Changed
? "\33u" : "");
116 strcat(buf1
, desc
->Name
);
121 strcpy(ni.Name,GetStr(MSG_LIST_FOREIGNSCREEN));
122 sprintf(buf2,"\33O[%08lx]",data->iforeign[TestPubScreen(desc->Name) ? 1 : 0]);
127 if (!GetDisplayInfoData(0, (UBYTE
*)&ni
, sizeof(ni
), DTAG_NAME
, desc
->DisplayID
))
128 strcpy(ni
.Name
, GetStr(MSG_LIST_UNKNOWNMODE
));
130 sprintf(buf2
, "\33O[%08lx]", (unsigned long)(IPTR
)data
->inormal
[TestPubScreen(desc
->Name
) ? 1 : 0]);
141 /****************************************************************************************/
143 IPTR
ScreenList_Load(struct IClass
*cl
, Object
*obj
, struct MUIP_ScreenList_Load
*msg
)
146 struct MUI_PubScreenDesc
*desc
;
149 if ((pfh
= MUIS_OpenPubFile(msg
->name
,MODE_OLDFILE
)))
154 DoMethod(obj
, MUIM_List_Clear
);
156 set(obj
, MUIA_List_Quiet
, TRUE
);
158 while ((desc
= MUIS_ReadPubFile(pfh
)))
160 DoMethod(obj
, MUIM_List_InsertSingle
, desc
, MUIV_List_Insert_Sorted
);
163 set(obj
, MUIA_List_Quiet
, FALSE
);
165 MUIS_ClosePubFile(pfh
);
171 /****************************************************************************************/
173 IPTR
ScreenList_Save(struct IClass
*cl
, Object
*obj
, struct MUIP_ScreenList_Save
*msg
)
176 struct MUI_PubScreenDesc
*desc
;
180 DoMethod(obj
, MUIM_List_Sort
);
182 if ((pfh
= MUIS_OpenPubFile(msg
->name
, MODE_NEWFILE
)))
186 for (i
=0; result
; i
++)
188 DoMethod(obj
, MUIM_List_GetEntry
, i
, &desc
);
192 desc
->Changed
= FALSE
;
193 desc
->UserData
= NULL
;
195 if (!MUIS_WritePubFile(pfh
, desc
))
198 MUIS_ClosePubFile(pfh
);
204 /****************************************************************************************/
206 IPTR
ScreenList_Find(struct IClass
*cl
, Object
*obj
, struct MUIP_ScreenList_Find
*msg
)
209 struct MUI_PubScreenDesc
*desc
;
215 DoMethod(obj
, MUIM_List_GetEntry
, i
, &desc
);
218 if (!stricmp(desc
->Name
, msg
->name
))
221 set(obj
, MUIA_List_Active
, i
);
229 /****************************************************************************************/
231 static Object
*makescreenimage(UBYTE
*body
)
233 Object
*obj
= BodychunkObject
,
234 MUIA_FixWidth
, PSI_SCREENON_WIDTH
,
235 MUIA_FixHeight
, PSI_SCREENON_HEIGHT
,
236 MUIA_Bitmap_Width
, PSI_SCREENON_WIDTH
,
237 MUIA_Bitmap_Height
, PSI_SCREENON_HEIGHT
,
238 MUIA_Bodychunk_Depth
, PSI_SCREENON_DEPTH
,
239 MUIA_Bodychunk_Body
, (UBYTE
*)body
,
240 MUIA_Bodychunk_Compression
, PSI_SCREENON_COMPRESSION
,
241 MUIA_Bodychunk_Masking
, PSI_SCREENON_MASKING
,
242 MUIA_Bitmap_SourceColors
, (ULONG
*)psi_screenon_colors
,
243 MUIA_Bitmap_Transparent
, 0,
249 /****************************************************************************************/
251 IPTR
ScreenList_Setup(struct IClass
*cl
, Object
*obj
, Msg msg
)
253 struct ScreenList_Data
*data
= INST_DATA(cl
, obj
);
255 if (!DoSuperMethodA(cl
, obj
, msg
))
258 data
->onormal
[0] = makescreenimage((UBYTE
*)psi_screencn_body
);
259 data
->onormal
[1] = makescreenimage((UBYTE
*)psi_screenon_body
);
261 data->oforeign[0] = makescreenimage((UBYTE *)psi_screencf_body);
262 data->oforeign[1] = makescreenimage((UBYTE *)psi_screenof_body);
265 data
->inormal
[0] = (APTR
)DoMethod(obj
, MUIM_List_CreateImage
, data
->onormal
[0], 0);
266 data
->inormal
[1] = (APTR
)DoMethod(obj
, MUIM_List_CreateImage
, data
->onormal
[1], 0);
268 data->iforeign[0] = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->oforeign[0],0);
269 data->iforeign[1] = (APTR)DoMethod(obj,MUIM_List_CreateImage,data->oforeign[1],0);
272 MUI_RequestIDCMP(obj
, IDCMP_MOUSEBUTTONS
| IDCMP_RAWKEY
);
277 /****************************************************************************************/
279 IPTR
ScreenList_Cleanup(struct IClass
*cl
, Object
*obj
, Msg msg
)
281 struct ScreenList_Data
*data
= INST_DATA(cl
, obj
);
283 DoMethod(obj
, MUIM_List_DeleteImage
, data
->inormal
[0]);
284 DoMethod(obj
, MUIM_List_DeleteImage
, data
->inormal
[1]);
286 DoMethod(obj,MUIM_List_DeleteImage,data->iforeign[0]);
287 DoMethod(obj,MUIM_List_DeleteImage,data->iforeign[1]);
290 if (data
->onormal
[0])
291 MUI_DisposeObject(data
->onormal
[0]);
292 if (data
->onormal
[1])
293 MUI_DisposeObject(data
->onormal
[1]);
295 if (data->oforeign[0]) MUI_DisposeObject(data->oforeign[0]);
296 if (data->oforeign[1]) MUI_DisposeObject(data->oforeign[1]);
299 MUI_RejectIDCMP(obj
, IDCMP_MOUSEBUTTONS
| IDCMP_RAWKEY
);
301 return DoSuperMethodA(cl
, obj
, msg
);
304 /****************************************************************************************/
306 IPTR
ScreenList_New(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
308 static struct Hook ScreenList_ConstructHook
;
309 ScreenList_ConstructHook
.h_Entry
= HookEntry
;
310 ScreenList_ConstructHook
.h_SubEntry
= ScreenList_ConstructFunc
;
311 static struct Hook ScreenList_DestructHook
;
312 ScreenList_DestructHook
.h_Entry
= HookEntry
;
313 ScreenList_DestructHook
.h_SubEntry
= (HOOKFUNC
)ScreenList_DestructFunc
;
314 static struct Hook ScreenList_CompareHook
;
315 ScreenList_CompareHook
.h_Entry
= HookEntry
;
316 ScreenList_CompareHook
.h_SubEntry
= (HOOKFUNC
)ScreenList_CompareFunc
;
318 obj
=(Object
*)DoSuperNewTags(cl
, obj
, NULL
,
319 MUIA_List_ConstructHook
, &ScreenList_ConstructHook
,
320 MUIA_List_DestructHook
, &ScreenList_DestructHook
,
321 MUIA_List_CompareHook
, &ScreenList_CompareHook
,
322 MUIA_List_Format
, "DELTA=2,,,",
323 MUIA_List_Title
, TRUE
,
324 MUIA_List_MinLineHeight
, 14,
325 TAG_MORE
, msg
->ops_AttrList
);
329 struct ScreenList_Data
*data
= INST_DATA(cl
, obj
);
331 data
->DisplayHook
.h_Entry
= HookEntry
;
332 data
->DisplayHook
.h_SubEntry
= (HOOKFUNC
)ScreenList_DisplayFunc
;
333 data
->DisplayHook
.h_Data
= (APTR
)data
;
335 set(obj
, MUIA_List_DisplayHook
, &data
->DisplayHook
);
341 /****************************************************************************************/
343 BOOPSI_DISPATCHER(IPTR
, ScreenList_Dispatcher
, cl
, obj
, msg
)
345 switch (msg
->MethodID
)
347 case OM_NEW
: return ScreenList_New (cl
,obj
,(APTR
)msg
);
348 case MUIM_Setup
: return ScreenList_Setup (cl
,obj
,(APTR
)msg
);
349 case MUIM_Cleanup
: return ScreenList_Cleanup(cl
,obj
,(APTR
)msg
);
350 case MUIM_ScreenList_Save
: return ScreenList_Save (cl
,obj
,(APTR
)msg
);
351 case MUIM_ScreenList_Load
: return ScreenList_Load (cl
,obj
,(APTR
)msg
);
352 case MUIM_ScreenList_Find
: return ScreenList_Find (cl
,obj
,(APTR
)msg
);
355 return DoSuperMethodA(cl
,obj
,msg
);
357 BOOPSI_DISPATCHER_END
359 /****************************************************************************************/
361 VOID
ScreenList_Init(VOID
)
363 CL_ScreenList
= MUI_CreateCustomClass
365 NULL
, MUIC_List
, NULL
, sizeof(struct ScreenList_Data
), ScreenList_Dispatcher
369 /****************************************************************************************/
371 VOID
ScreenList_Exit(VOID
)
374 MUI_DeleteCustomClass(CL_ScreenList
);