2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
5 #include "portable_macros.h"
10 #include <exec/types.h>
11 #include <libraries/gadtools.h>
12 #include <libraries/mui.h>
15 #include <zune/customclasses.h>
17 #include <zune_AROS/customclasses.h>
20 #include <dos/notify.h>
23 #include <workbench/handler.h>
25 #include <workbench_AROS/handler.h>
29 #include <proto/exec.h>
33 #include <proto/dos.h>
36 #ifndef PROTO_INTUITION_H
37 #include <proto/intuition.h>
40 #ifndef PROTO_GRAPHICS_H
41 #include <proto/graphics.h>
44 #ifndef PROTO_UTILITY_H
45 #include <proto/utility.h>
48 #ifndef PROTO_KEYMAP_H
49 #include <proto/keymap.h>
52 #ifndef PROTO_LOCALE_H
53 #include <proto/locale.h>
56 #ifndef PROTO_LAYERS_H
57 #include <proto/layers.h>
60 #ifndef PROTO_DATATYPES_H
61 #include <proto/datatypes.h>
66 #include <proto/alib.h>
71 #include <proto/asl.h>
74 #ifndef PROTO_DISKFONT_H
75 #include <proto/diskfont.h>
78 #ifndef PROTO_IFFPARSE_H
79 #include <proto/iffparse.h>
87 #include <prefs/prefhdr.h>
89 #include <prefs_AROS/prefhdr.h>
92 #include <prefs/font.h>
95 #include <aros/debug.h>
98 #include "wandererprefsfont.h"
104 #define D(x) if (DEBUG) x
106 #define bug DebugPrintF
115 #define CHECK_PRHD_VERSION 1
116 #define CHECK_PRHD_SIZE 1
118 /** Data/Structs for font.prefs settings */
120 struct FilePrefHeader
129 UBYTE fp_Reserved
[4 * 3];
130 UBYTE fp_Reserved2
[2];
136 UBYTE fp_TextAttr_ta_Name
[4];
137 UBYTE fp_TextAttr_ta_YSize
[2];
138 UBYTE fp_TextAttr_ta_Style
;
139 UBYTE fp_TextAttr_ta_Flags
;
140 BYTE fp_Name
[FONTNAMESIZE
];
148 /** Data pertaining to wanderers internal prefs configured state */
150 struct IFFHandle
*CreateIFF(STRPTR filename
, LONG
*stopchunks
, LONG numstopchunks
)
152 struct IFFHandle
*iff
;
154 D(bug("CreateIFF: filename = \"%s\"\n", filename
));
156 if ((iff
= AllocIFF()))
158 D(bug("CreateIFF: AllocIFF okay.\n"));
159 if ((iff
->iff_Stream
= (IPTR
) Open(filename
, MODE_OLDFILE
)))
161 D(bug("CreateIFF: Open() okay.\n"));InitIFFasDOS(iff
);
163 if (OpenIFF(iff
, IFFF_READ
) == 0)
167 D(bug("CreateIFF: OpenIFF okay.\n"));
169 if ((StopChunk(iff
, ID_PREF
, ID_PRHD
) == 0)
170 && (StopChunks(iff
, stopchunks
, numstopchunks
) == 0))
172 D(bug("CreateIFF: StopChunk(PRHD) okay.\n"));
174 if (ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
176 struct ContextNode
*cn
;
178 cn
= CurrentChunk(iff
);
180 D(bug("CreateIFF: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
190 if ((cn
->cn_ID
== ID_PRHD
)
192 && (cn
->cn_Size
== sizeof(struct FilePrefHeader
))
196 struct FilePrefHeader h
;
198 D(bug("CreateIFF: PRHD chunk okay.\n"));
200 if (ReadChunkBytes(iff
, &h
, sizeof(h
)) == sizeof(h
))
202 D(bug("CreateIFF: Reading PRHD chunk okay.\n"));
204 #if CHECK_PRHD_VERSION
205 if (h
.ph_Version
== PHV_CURRENT
)
207 D(bug("CreateIFF: PrefHeader version is correct.\n"));
218 } /* if (ParseIFF(iff, IFFPARSE_SCAN) == 0) */
220 } /* if ((StopChunk(iff, ID_PREF, ID_PRHD) == 0) && (StopChunks(... */
225 Close((BPTR
)iff
->iff_Stream
);
230 } /* if (OpenIFF(iff, IFFF_READ) == 0) */
233 Close((BPTR
)iff
->iff_Stream
);
238 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
245 } /* if ((iff = AllocIFF())) */
251 /*********************************************************************************************/
253 void KillIFF(struct IFFHandle
*iff
)
258 Close((BPTR
)iff
->iff_Stream
);
263 /*********************************************************************************************/
265 void WandererPrefs_ReloadFontPrefs(CONST_STRPTR prefsfile
, struct WandererFontPrefsData
*wfpd
)
267 struct IFFHandle
*iff
= NULL
;
269 D(bug("[wanderer] In WandererPrefs_CheckFont()\n"));
271 if ((iff
= CreateIFF((STRPTR
)prefsfile
, stopchunks
, 1)))
273 while (ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
275 struct ContextNode
*cn
;
276 struct FileFontPrefs fontprefs
;
278 cn
= CurrentChunk(iff
);
280 D(bug("[wanderer] WandererPrefs_CheckFont: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
290 if ((cn
->cn_ID
== ID_FONT
) && (cn
->cn_Size
== sizeof(fontprefs
)))
292 D(bug("[wanderer] WandererPrefs_CheckFont: ID_FONT chunk with correct size found.\n"));
294 if (ReadChunkBytes(iff
, &fontprefs
, sizeof(fontprefs
))
295 == sizeof(fontprefs
))
299 D(bug("[wanderer] WandererPrefs_CheckFont: Reading of ID_FONT chunk okay.\n"));
301 type
= (fontprefs
.fp_Type
[0] << 8) + fontprefs
.fp_Type
[1];
304 D(bug("[wanderer] WandererPrefs_CheckFont: Type = %d Name = %s\n", type
, fontprefs
.fp_Name
));
307 if (type
== FP_WBFONT
)
309 if (wfpd
->wfpd_IconFont
!= NULL
)
311 WandererPrefs_CloseOldIconFont(wfpd
);
312 wfpd
->wfpd_OldIconFont
= wfpd
->wfpd_IconFont
;
314 wfpd
->wfpd_IconFontTA
.ta_Name
= fontprefs
.fp_Name
;
315 wfpd
->wfpd_IconFontTA
.ta_YSize
=
316 (fontprefs
.fp_TextAttr_ta_YSize
[0] << 8)
317 + fontprefs
.fp_TextAttr_ta_YSize
[1];
318 wfpd
->wfpd_IconFontTA
.ta_Style
=
319 fontprefs
.fp_TextAttr_ta_Style
;
320 wfpd
->wfpd_IconFontTA
.ta_Flags
=
321 fontprefs
.fp_TextAttr_ta_Flags
;
323 wfpd
->wfpd_IconFont
= OpenDiskFont(&wfpd
->wfpd_IconFontTA
);
324 D(bug("[wanderer] WandererPrefs_CheckFont: Trying to use Font '%s' @ %x\n", wfpd
->wfpd_IconFontTA
.ta_Name
, wfpd
->wfpd_IconFont
));
327 } /* if (ReadChunkBytes(iff, &fontprefs, sizeof(fontprefs)) == sizeof(fontprefs)) */
329 } /* if ((cn->cn_ID == ID_FONT) && (cn->cn_Size == sizeof(fontprefs))) */
331 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
335 } /* if ((iff = CreateIFF(filename))) */
338 void WandererPrefs_CloseOldIconFont(struct WandererFontPrefsData
*wfpd
)
340 if (wfpd
->wfpd_OldIconFont
)
342 CloseFont(wfpd
->wfpd_OldIconFont
);
343 wfpd
->wfpd_OldIconFont
= NULL
;