2 Copyright © 2002-2006, 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 "wandererprefsintern.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"));
164 if (OpenIFF(iff
, IFFF_READ
) == 0)
168 D(bug("CreateIFF: OpenIFF okay.\n"));
170 if ((StopChunk(iff
, ID_PREF
, ID_PRHD
) == 0) &&
171 (StopChunks(iff
, stopchunks
, numstopchunks
) == 0))
173 D(bug("CreateIFF: StopChunk(PRHD) okay.\n"));
175 if (ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
177 struct ContextNode
*cn
;
179 cn
= CurrentChunk(iff
);
181 D(bug("CreateIFF: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
191 if ((cn
->cn_ID
== ID_PRHD
)
193 && (cn
->cn_Size
== sizeof(struct FilePrefHeader
))
197 struct FilePrefHeader h
;
199 D(bug("CreateIFF: PRHD chunk okay.\n"));
201 if (ReadChunkBytes(iff
, &h
, sizeof(h
)) == sizeof(h
))
203 D(bug("CreateIFF: Reading PRHD chunk okay.\n"));
205 #if CHECK_PRHD_VERSION
206 if (h
.ph_Version
== PHV_CURRENT
)
208 D(bug("CreateIFF: PrefHeader version is correct.\n"));
219 } /* if (ParseIFF(iff, IFFPARSE_SCAN) == 0) */
221 } /* if ((StopChunk(iff, ID_PREF, ID_PRHD) == 0) && (StopChunks(... */
226 Close((BPTR
)iff
->iff_Stream
);
231 } /* if (OpenIFF(iff, IFFF_READ) == 0) */
234 Close((BPTR
)iff
->iff_Stream
);
239 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
246 } /* if ((iff = AllocIFF())) */
252 /*********************************************************************************************/
254 void KillIFF(struct IFFHandle
*iff
)
259 Close((BPTR
)iff
->iff_Stream
);
264 /*********************************************************************************************/
266 static void WandererPrefs_CheckFont(struct WandererInternalPrefsData
*WIPD
)
268 struct IFFHandle
*iff
= NULL
;
270 D(bug("[wanderer] In WandererPrefs_CheckFont()\n"));
272 if ((iff
= CreateIFF("ENV:SYS/Font.prefs", stopchunks
, 1)))
274 while(ParseIFF(iff
, IFFPARSE_SCAN
) == 0)
276 struct ContextNode
*cn
;
277 struct FileFontPrefs fontprefs
;
279 cn
= CurrentChunk(iff
);
281 D(bug("[wanderer] WandererPrefs_CheckFont: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
291 if ((cn
->cn_ID
== ID_FONT
) && (cn
->cn_Size
== sizeof(fontprefs
)))
293 D(bug("[wanderer] WandererPrefs_CheckFont: ID_FONT chunk with correct size found.\n"));
295 if (ReadChunkBytes(iff
, &fontprefs
, sizeof(fontprefs
)) == 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];
305 D(bug("[wanderer] WandererPrefs_CheckFont: Type = %d Name = %s\n", type
, fontprefs
.fp_Name
));
308 if (type
== FP_WBFONT
)
310 struct TextFont
*oldWIPD_IconFont
= NULL
;
311 if (WIPD
->WIPD_IconFont
!= NULL
)
313 oldWIPD_IconFont
= WIPD
->WIPD_IconFont
;
315 WIPD
->WIPD_IconFontTA
.ta_Name
= fontprefs
.fp_Name
;
316 WIPD
->WIPD_IconFontTA
.ta_YSize
= (fontprefs
.fp_TextAttr_ta_YSize
[0] << 8) +
317 fontprefs
.fp_TextAttr_ta_YSize
[1];
318 WIPD
->WIPD_IconFontTA
.ta_Style
= fontprefs
.fp_TextAttr_ta_Style
;
319 WIPD
->WIPD_IconFontTA
.ta_Flags
= fontprefs
.fp_TextAttr_ta_Flags
;
321 WIPD
->WIPD_IconFont
= OpenDiskFont(&WIPD
->WIPD_IconFontTA
);
322 D(bug("[wanderer] WandererPrefs_CheckFont: Trying to use Font '%s' @ %x\n", WIPD
->WIPD_IconFontTA
.ta_Name
, WIPD
->WIPD_IconFont
));
323 if (oldWIPD_IconFont
!= NULL
)
325 // Cause all windows to update their used font ..
327 // Then close the old font ..
328 CloseFont(oldWIPD_IconFont
);
332 } /* if (ReadChunkBytes(iff, &fontprefs, sizeof(fontprefs)) == sizeof(fontprefs)) */
334 } /* if ((cn->cn_ID == ID_FONT) && (cn->cn_Size == sizeof(fontprefs))) */
336 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
340 } /* if ((iff = CreateIFF(filename))) */
343 IPTR
InitWandererPrefs(void)
345 struct WandererInternalPrefsData
*WIPD
= NULL
;
347 D(bug("[wanderer] In InitWandererPrefs()\n"));
349 if ((WIPD
= AllocVec(sizeof(struct WandererInternalPrefsData
), MEMF_CLEAR
|MEMF_PUBLIC
)) != NULL
)
351 D(bug("[wanderer] InitWandererPrefs: Allocated PrefsIntern @ %x\n", WIPD
));
352 WandererPrefs_CheckFont(WIPD
);