Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / system / Wanderer / wandererprefsfont.c
blobd8e1547f894034425716516b9d0071b783cbff8b
1 /*
2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
5 #include "portable_macros.h"
6 #ifdef __AROS__
7 #define DEBUG 0
8 #endif
10 #include <exec/types.h>
11 #include <libraries/gadtools.h>
12 #include <libraries/mui.h>
14 #ifdef __AROS__
15 #include <zune/customclasses.h>
16 #else
17 #include <zune_AROS/customclasses.h>
18 #endif
20 #include <dos/notify.h>
22 #ifdef __AROS__
23 #include <workbench/handler.h>
24 #else
25 #include <workbench_AROS/handler.h>
26 #endif
28 #ifndef PROTO_EXEC_H
29 #include <proto/exec.h>
30 #endif
32 #ifndef PROTO_DOS_H
33 #include <proto/dos.h>
34 #endif
36 #ifndef PROTO_INTUITION_H
37 #include <proto/intuition.h>
38 #endif
40 #ifndef PROTO_GRAPHICS_H
41 #include <proto/graphics.h>
42 #endif
44 #ifndef PROTO_UTILITY_H
45 #include <proto/utility.h>
46 #endif
48 #ifndef PROTO_KEYMAP_H
49 #include <proto/keymap.h>
50 #endif
52 #ifndef PROTO_LOCALE_H
53 #include <proto/locale.h>
54 #endif
56 #ifndef PROTO_LAYERS_H
57 #include <proto/layers.h>
58 #endif
60 #ifndef PROTO_DATATYPES_H
61 #include <proto/datatypes.h>
62 #endif
64 #ifdef __AROS__
65 #ifndef PROTO_ALIB_H
66 #include <proto/alib.h>
67 #endif
68 #endif
70 #ifndef PROTO_ASL_H
71 #include <proto/asl.h>
72 #endif
74 #ifndef PROTO_DISKFONT_H
75 #include <proto/diskfont.h>
76 #endif
78 #ifndef PROTO_IFFPARSE_H
79 #include <proto/iffparse.h>
80 #endif
82 #include <stdlib.h>
83 #include <stdio.h>
84 #include <string.h>
86 #ifdef __AROS__
87 #include <prefs/prefhdr.h>
88 #else
89 #include <prefs_AROS/prefhdr.h>
90 #endif
92 #include <prefs/font.h>
94 #ifdef __AROS__
95 #include <aros/debug.h>
96 #endif
98 #include "wandererprefsfont.h"
100 #ifndef __AROS__
101 #define DEBUG 1
103 #ifdef DEBUG
104 #define D(x) if (DEBUG) x
105 #ifdef __amigaos4__
106 #define bug DebugPrintF
107 #else
108 #define bug kprintf
109 #endif
110 #else
111 #define D(...)
112 #endif
113 #endif
115 #define CHECK_PRHD_VERSION 1
116 #define CHECK_PRHD_SIZE 1
118 /** Data/Structs for font.prefs settings */
120 struct FilePrefHeader
122 UBYTE ph_Version;
123 UBYTE ph_Type;
124 UBYTE ph_Flags[4];
127 struct FileFontPrefs
129 UBYTE fp_Reserved[4 * 3];
130 UBYTE fp_Reserved2[2];
131 UBYTE fp_Type[2];
132 UBYTE fp_FrontPen;
133 UBYTE fp_BackPen;
134 UBYTE fp_Drawmode;
135 UBYTE fp_pad;
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];
143 LONG stopchunks[] =
145 ID_PREF, ID_FONT
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)
165 BOOL ok = FALSE;
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",
181 cn->cn_Type >> 24,
182 cn->cn_Type >> 16,
183 cn->cn_Type >> 8,
184 cn->cn_Type,
185 cn->cn_ID >> 24,
186 cn->cn_ID >> 16,
187 cn->cn_ID >> 8,
188 cn->cn_ID));
190 if ((cn->cn_ID == ID_PRHD)
191 #if CHECK_PRHD_SIZE
192 && (cn->cn_Size == sizeof(struct FilePrefHeader))
193 #endif
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"));
208 ok = TRUE;
210 #else
211 ok = TRUE;
212 #endif
218 } /* if (ParseIFF(iff, IFFPARSE_SCAN) == 0) */
220 } /* if ((StopChunk(iff, ID_PREF, ID_PRHD) == 0) && (StopChunks(... */
222 if (!ok)
224 CloseIFF(iff);
225 Close((BPTR)iff->iff_Stream);
226 FreeIFF(iff);
227 iff = NULL;
230 } /* if (OpenIFF(iff, IFFF_READ) == 0) */
231 else
233 Close((BPTR)iff->iff_Stream);
234 FreeIFF(iff);
235 iff = NULL;
238 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
239 else
241 FreeIFF(iff);
242 iff = NULL;
245 } /* if ((iff = AllocIFF())) */
247 return iff;
251 /*********************************************************************************************/
253 void KillIFF(struct IFFHandle *iff)
255 if (iff)
257 CloseIFF(iff);
258 Close((BPTR)iff->iff_Stream);
259 FreeIFF(iff);
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",
281 cn->cn_Type >> 24,
282 cn->cn_Type >> 16,
283 cn->cn_Type >> 8,
284 cn->cn_Type,
285 cn->cn_ID >> 24,
286 cn->cn_ID >> 16,
287 cn->cn_ID >> 8,
288 cn->cn_ID));
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))
297 UWORD type;
299 D(bug("[wanderer] WandererPrefs_CheckFont: Reading of ID_FONT chunk okay.\n"));
301 type = (fontprefs.fp_Type[0] << 8) + fontprefs.fp_Type[1];
303 #ifdef __AROS__
304 D(bug("[wanderer] WandererPrefs_CheckFont: Type = %d Name = %s\n", type, fontprefs.fp_Name));
305 #endif
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) */
333 KillIFF(iff);
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;