2 Copyright © 2003-2004, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <exec/types.h>
9 #include <utility/tagitem.h>
10 #include <libraries/asl.h>
11 #include <libraries/mui.h>
12 #include <prefs/prefhdr.h>
13 #include <prefs/font.h>
14 #include <zune/customclasses.h>
15 #include <zune/prefseditor.h>
17 #include <proto/exec.h>
18 #include <proto/intuition.h>
19 #include <proto/utility.h>
20 #include <proto/muimaster.h>
21 #include <proto/dos.h>
22 #include <proto/iffparse.h>
32 /*** Instance Data **********************************************************/
33 #define FP_COUNT (3) /* Number of entries in fped_FontPrefs array */
37 struct FontPrefs fped_FontPrefs
[FP_COUNT
];
38 Object
*fped_IconsString
,
43 /*** Macros *****************************************************************/
44 #define SETUP_INST_DATA struct FPEditor_DATA *data = INST_DATA(CLASS, self)
45 #define FP(i) (&(data->fped_FontPrefs[(i)]))
47 /*** Utility Functions ******************************************************/
49 void FontPrefs_Default(struct FontPrefs
*fp
[FP_COUNT
])
53 for (i
= 0; i
< FP_COUNT
; i
++)
56 fp
[i
]->fp_FrontPen
= 0; /* FIXME: Is this (really) default? Look it up! */
57 fp
[i
]->fp_BackPen
= 0; /* FIXME: Is this (really) default? Look it up! */
58 fp
[i
]->fp_DrawMode
= 0; /* FIXME: Is this (really) default? Look it up! */
60 fp
[i
]->fp_TextAttr
.ta_YSize
= 8; /* FIXME: Is this (really) default? Look it up! */
61 fp
[i
]->fp_TextAttr
.ta_Style
= FS_NORMAL
;
62 fp
[i
]->fp_TextAttr
.ta_Flags
= FPB_DISKFONT
; /* FIXME: Is this (really) default? Look it up! */
64 fp
[i
]->fp_Name
[0] = '\0';
65 strlcat(fp
[i
]->fp_Name
, "topaz.font", FONTNAMESIZE
); /* FIXME: Is this (really) default? Check it up! */
66 fp
[i
]->fp_TextAttr
.ta_Name
= fp
[i
]->fp_Name
;
71 STATIC VOID
convertEndian(struct FontPrefs
*fp
)
75 for (i
= 0; i
<= 2; i
++)
77 fp
->fp_Reserved
[i
] = AROS_BE2LONG(fp
->fp_Reserved
[i
]);
80 fp
->fp_Reserved2
= AROS_BE2WORD(fp
->fp_Reserved2
);
81 fp
->fp_Type
= AROS_BE2WORD(fp
->fp_Type
);
82 fp
->fp_TextAttr
.ta_YSize
= AROS_BE2WORD(fp
->fp_TextAttr
.ta_YSize
);
86 VOID FontPrefs2FontString
88 STRPTR buffer
, ULONG buffersize
, struct FontPrefs
*fp
93 buffer
, buffersize
, "%.*s/%d",
94 strlen(fp
->fp_TextAttr
.ta_Name
) - 5 /* strlen(".font") */,
95 fp
->fp_TextAttr
.ta_Name
, fp
->fp_TextAttr
.ta_YSize
99 BOOL
FontString2FontPrefs(struct FontPrefs
*fp
, CONST_STRPTR buffer
)
101 STRPTR separator
= PathPart((STRPTR
) buffer
);
102 ULONG nameLength
= separator
- buffer
;
103 ULONG suffixLength
= 5; /* strlen(".font") */
106 if (nameLength
+ suffixLength
>= FONTNAMESIZE
)
108 /* Not enough space for the font name */
114 fp
->fp_Name
, nameLength
+ suffixLength
+ 1, "%.*s.font",
115 (int) nameLength
, buffer
117 fp
->fp_TextAttr
.ta_Name
= fp
->fp_Name
;
119 StrToLong(FilePart((STRPTR
) buffer
), &size
);
120 fp
->fp_TextAttr
.ta_YSize
= size
;
125 BOOL Gadgets2FontPrefs
127 struct FPEditor_DATA
*data
132 // FIXME: error checking
133 GET(data
->fped_IconsString
, MUIA_String_Contents
, &str
);
134 FontString2FontPrefs(FP(FP_WBFONT
), str
);
136 GET(data
->fped_SystemString
, MUIA_String_Contents
, &str
);
137 FontString2FontPrefs(FP(FP_SYSFONT
), str
);
139 GET(data
->fped_ScreenString
, MUIA_String_Contents
, &str
);
140 FontString2FontPrefs(FP(FP_SCREENFONT
), str
);
145 BOOL FontPrefs2Gadgets
147 struct FPEditor_DATA
*data
150 TEXT buffer
[FONTNAMESIZE
+ 8];
152 // FIXME: error checking
153 FontPrefs2FontString(buffer
, FONTNAMESIZE
+ 8, FP(FP_WBFONT
));
154 NNSET(data
->fped_IconsString
, MUIA_String_Contents
, (IPTR
) buffer
);
156 FontPrefs2FontString(buffer
, FONTNAMESIZE
+ 8, FP(FP_SYSFONT
));
157 NNSET(data
->fped_SystemString
, MUIA_String_Contents
, (IPTR
) buffer
);
159 FontPrefs2FontString(buffer
, FONTNAMESIZE
+ 8, FP(FP_SCREENFONT
));
160 NNSET(data
->fped_ScreenString
, MUIA_String_Contents
, (IPTR
) buffer
);
165 /*** Methods ****************************************************************/
166 Object
*FPEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
168 Object
*iconsString
, *screenString
, *systemString
;
170 self
= (Object
*) DoSuperNewTags
174 MUIA_PrefsEditor_Name
, __(MSG_NAME
),
175 MUIA_PrefsEditor_Path
, (IPTR
) "SYS/Font.prefs",
177 Child
, (IPTR
) ColGroup(2),
178 Child
, (IPTR
) Label2(_(MSG_ICONS
)),
179 Child
, (IPTR
) PopaslObject
,
180 MUIA_Popasl_Type
, ASL_FontRequest
,
181 ASLFO_MaxHeight
, 100,
182 MUIA_Popstring_String
, (IPTR
) (iconsString
= StringObject
,
184 MUIA_Background
, MUII_TextBack
,
186 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
188 Child
, (IPTR
) Label2(_(MSG_SCREEN
)),
189 Child
, (IPTR
) PopaslObject
,
190 MUIA_Popasl_Type
, ASL_FontRequest
,
191 ASLFO_MaxHeight
, 100,
192 MUIA_Popstring_String
, (IPTR
) (screenString
= StringObject
,
194 MUIA_Background
, MUII_TextBack
,
196 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
198 Child
, (IPTR
) Label2(_(MSG_SYSTEM
)),
199 Child
, (IPTR
) PopaslObject
,
200 MUIA_Popasl_Type
, ASL_FontRequest
,
201 ASLFO_FixedWidthOnly
, TRUE
,
202 ASLFO_MaxHeight
, 100,
203 MUIA_Popstring_String
, (IPTR
) (systemString
= StringObject
,
205 MUIA_Background
, MUII_TextBack
,
207 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
217 data
->fped_IconsString
= iconsString
;
218 data
->fped_ScreenString
= screenString
;
219 data
->fped_SystemString
= systemString
;
221 /*-- Setup notifications -------------------------------------------*/
224 iconsString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
225 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
229 screenString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
230 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
234 systemString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
235 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
242 IPTR FPEditor__MUIM_PrefsEditor_ImportFH
244 Class
*CLASS
, Object
*self
,
245 struct MUIP_PrefsEditor_ImportFH
*message
249 struct ContextNode
*context
;
250 struct IFFHandle
*handle
;
254 if (!(handle
= AllocIFF()))
256 ShowError(_(MSG_CANT_ALLOCATE_IFFPTR
));
260 handle
->iff_Stream
= (IPTR
) message
->fh
;
261 InitIFFasDOS(handle
);
263 if ((error
= OpenIFF(handle
, IFFF_READ
)) == 0)
267 // FIXME: We want some sanity checking here!
268 for (i
= 0; i
< FP_COUNT
; i
++)
270 if ((error
= StopChunk(handle
, ID_PREF
, ID_FONT
)) == 0)
272 if ((error
= ParseIFF(handle
, IFFPARSE_SCAN
)) == 0)
274 context
= CurrentChunk(handle
);
276 error
= ReadChunkBytes
278 handle
, FP(i
), sizeof(struct FontPrefs
)
283 printf("Error: ReadChunkBytes() returned %ld!\n", error
);
286 FP(i
)->fp_TextAttr
.ta_Name
= FP(i
)->fp_Name
;
288 convertEndian(FP(i
));
292 printf("ParseIFF() failed, returncode %ld!\n", error
);
299 printf("StopChunk() failed, returncode %ld!\n", error
);
308 ShowError(_(MSG_CANT_OPEN_STREAM
));
313 if (success
) FontPrefs2Gadgets(data
);
318 IPTR FPEditor__MUIM_PrefsEditor_ExportFH
320 Class
*CLASS
, Object
*self
,
321 struct MUIP_PrefsEditor_ExportFH
*message
325 struct PrefHeader header
;
326 struct IFFHandle
*handle
;
330 Gadgets2FontPrefs(data
);
332 memset(&header
, 0, sizeof(struct PrefHeader
));
334 if ((handle
= AllocIFF()))
336 handle
->iff_Stream
= (IPTR
) message
->fh
;
338 InitIFFasDOS(handle
);
340 if (!(error
= OpenIFF(handle
, IFFF_WRITE
))) /* NULL = successful! */
344 PushChunk(handle
, ID_PREF
, ID_FORM
, IFFSIZE_UNKNOWN
); /* FIXME: IFFSIZE_UNKNOWN? */
346 header
.ph_Version
= PHV_CURRENT
;
349 PushChunk(handle
, ID_PREF
, ID_PRHD
, IFFSIZE_UNKNOWN
); /* FIXME: IFFSIZE_UNKNOWN? */
351 WriteChunkBytes(handle
, &header
, sizeof(struct PrefHeader
));
355 for (i
= 0; i
< FP_COUNT
; i
++)
357 error
= PushChunk(handle
, ID_PREF
, ID_FONT
, sizeof(struct FontPrefs
));
359 if (error
!= 0) // TODO: We need some error checking here!
361 printf("error: PushChunk() = %ld\n", error
);
364 convertEndian(FP(i
)); // Convert to m68k endian
366 error
= WriteChunkBytes(handle
, FP(i
), sizeof(struct FontPrefs
));
367 error
= PopChunk(handle
);
369 convertEndian(FP(i
)); // Revert to initial endian
371 if (error
!= 0) // TODO: We need some error checking here!
373 printf("error: PopChunk() = %ld\n", error
);
377 // Terminate the FORM
382 ShowError(_(MSG_CANT_OPEN_STREAM
));
391 // Do something more here - if IFF allocation has failed, something isn't right
392 ShowError(_(MSG_CANT_ALLOCATE_IFFPTR
));
399 /*** Setup ******************************************************************/
402 FPEditor
, NULL
, MUIC_PrefsEditor
, NULL
,
403 OM_NEW
, struct opSet
*,
404 MUIM_PrefsEditor_ImportFH
, struct MUIP_PrefsEditor_ImportFH
*,
405 MUIM_PrefsEditor_ExportFH
, struct MUIP_PrefsEditor_ExportFH
*