Fix typo causing incorrect desktop sorting
[AROS.git] / workbench / system / Wanderer / wandererprefsinternal.c
blob75a14b779821d379edcc6991bf9bbe5545e90a33
1 /*
2 Copyright © 2002-2006, 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 "wandererprefsintern.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"));
162 InitIFFasDOS(iff);
164 if (OpenIFF(iff, IFFF_READ) == 0)
166 BOOL ok = FALSE;
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",
182 cn->cn_Type >> 24,
183 cn->cn_Type >> 16,
184 cn->cn_Type >> 8,
185 cn->cn_Type,
186 cn->cn_ID >> 24,
187 cn->cn_ID >> 16,
188 cn->cn_ID >> 8,
189 cn->cn_ID));
191 if ((cn->cn_ID == ID_PRHD)
192 #if CHECK_PRHD_SIZE
193 && (cn->cn_Size == sizeof(struct FilePrefHeader))
194 #endif
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"));
209 ok = TRUE;
211 #else
212 ok = TRUE;
213 #endif
219 } /* if (ParseIFF(iff, IFFPARSE_SCAN) == 0) */
221 } /* if ((StopChunk(iff, ID_PREF, ID_PRHD) == 0) && (StopChunks(... */
223 if (!ok)
225 CloseIFF(iff);
226 Close((BPTR)iff->iff_Stream);
227 FreeIFF(iff);
228 iff = NULL;
231 } /* if (OpenIFF(iff, IFFF_READ) == 0) */
232 else
234 Close((BPTR)iff->iff_Stream);
235 FreeIFF(iff);
236 iff = NULL;
239 } /* if ((iff->iff_Stream = (IPTR)Open(filename, MODE_OLDFILE))) */
240 else
242 FreeIFF(iff);
243 iff = NULL;
246 } /* if ((iff = AllocIFF())) */
248 return iff;
252 /*********************************************************************************************/
254 void KillIFF(struct IFFHandle *iff)
256 if (iff)
258 CloseIFF(iff);
259 Close((BPTR)iff->iff_Stream);
260 FreeIFF(iff);
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",
282 cn->cn_Type >> 24,
283 cn->cn_Type >> 16,
284 cn->cn_Type >> 8,
285 cn->cn_Type,
286 cn->cn_ID >> 24,
287 cn->cn_ID >> 16,
288 cn->cn_ID >> 8,
289 cn->cn_ID));
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))
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];
304 #ifdef __AROS__
305 D(bug("[wanderer] WandererPrefs_CheckFont: Type = %d Name = %s\n", type, fontprefs.fp_Name));
306 #endif
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) */
338 KillIFF(iff);
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);
355 return (IPTR) WIPD;