Hint added.
[AROS.git] / workbench / c / iprefs / fontprefs.c
blobb885ba1afced8c92f27bfb59f20fde06222afd34
1 /*
2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*********************************************************************************************/
11 #include "global.h"
13 #include <prefs/prefhdr.h>
14 #include <prefs/font.h>
16 #define DEBUG 0
17 #include <aros/debug.h>
19 /*********************************************************************************************/
21 struct FileFontPrefs
23 UBYTE fp_Reserved[4 * 3];
24 UBYTE fp_Reserved2[2];
25 UBYTE fp_Type[2];
26 UBYTE fp_FrontPen;
27 UBYTE fp_BackPen;
28 UBYTE fp_Drawmode;
29 UBYTE fp_pad;
30 UBYTE fp_TextAttr_ta_Name[4];
31 UBYTE fp_TextAttr_ta_YSize[2];
32 UBYTE fp_TextAttr_ta_Style;
33 UBYTE fp_TextAttr_ta_Flags;
34 BYTE fp_Name[FONTNAMESIZE];
37 /*********************************************************************************************/
39 LONG stopchunks[] =
41 ID_PREF, ID_FONT
44 /*********************************************************************************************/
46 void FontPrefs_Handler(STRPTR filename)
48 struct IFFHandle *iff;
50 D(bug("In IPrefs:FontPrefs_Handler\n"));
52 if ((iff = CreateIFF(filename, stopchunks, 1)))
54 while(ParseIFF(iff, IFFPARSE_SCAN) == 0)
56 struct ContextNode *cn;
57 struct FileFontPrefs fontprefs;
59 cn = CurrentChunk(iff);
61 D(bug("FontPrefs_Handler: ParseIFF okay. Chunk Type = %c%c%c%c ChunkID = %c%c%c%c\n",
62 cn->cn_Type >> 24,
63 cn->cn_Type >> 16,
64 cn->cn_Type >> 8,
65 cn->cn_Type,
66 cn->cn_ID >> 24,
67 cn->cn_ID >> 16,
68 cn->cn_ID >> 8,
69 cn->cn_ID));
71 if ((cn->cn_ID == ID_FONT) && (cn->cn_Size == sizeof(fontprefs)))
73 D(bug("FontPrefs_Handler: ID_FONT chunk with correct size found.\n"));
75 if (ReadChunkBytes(iff, &fontprefs, sizeof(fontprefs)) == sizeof(fontprefs))
77 struct TextAttr ta;
78 struct TextFont *font;
79 UWORD type;
81 D(bug("FontPrefs_Handler: Reading of ID_FONT chunk okay.\n"));
83 type = (fontprefs.fp_Type[0] << 8) + fontprefs.fp_Type[1];
85 D(bug("Type = %d Name = %s\n", type, fontprefs.fp_Name));
87 ta.ta_Name = fontprefs.fp_Name;
88 ta.ta_YSize = (fontprefs.fp_TextAttr_ta_YSize[0] << 8) +
89 fontprefs.fp_TextAttr_ta_YSize[1];
90 ta.ta_Style = fontprefs.fp_TextAttr_ta_Style;
91 ta.ta_Flags = fontprefs.fp_TextAttr_ta_Flags;
93 switch(type)
95 case FP_SYSFONT:
96 if ((font = OpenDiskFont(&ta)))
98 if (font->tf_Flags & FPF_PROPORTIONAL)
100 D(bug("FontPrefs_Handler: FP_SYSFONT Font is proportional although it may not be!\n"));
101 CloseFont(font);
103 else
105 Forbid();
106 GfxBase->DefaultFont = font;
107 Permit();
109 D(bug("FontPrefs_Handler: Installed new system font!\n"));
112 else
114 D(bug("FontPrefs_Handler: Could not open font!\n"));
116 break;
118 case FP_SCREENFONT:
119 if ((font = OpenDiskFont(&ta)))
121 BOOL closed = FALSE, cancel = FALSE;
122 TEXT screen_name[MAXPUBSCREENNAME + 1];
124 SetDefaultScreenFont(font);
125 D(bug("FontPrefs_Handler: Installed new screen font!\n"));
127 /* Keep trying to close WB screen unless user
128 cancels or it wasn't open in the first
129 place */
130 while (!(closed || cancel ||
131 NextPubScreen(NULL, screen_name) == NULL))
133 closed = CloseWorkBench();
134 if (!closed)
135 cancel = ShowMessage("System Request",
136 "Intuition is attempting to reset"
137 " the Workbench Screen.\n"
138 "Please close all windows,"
139 " except drawers.",
140 "Retry|Cancel") == 0;
142 if (closed)
143 OpenWorkBench();
145 else
147 D(bug("FontPrefs_Handler: Could not open font!\n"));
149 break;
151 case FP_WBFONT:
152 /* Hmm ... should IPrefs handle this, or should Workbench task
153 itself also setup a filenotification on font.prefs :-\ */
154 break;
156 } /* switch(type) */
158 } /* if (ReadChunkBytes(iff, &fontprefs, sizeof(fontprefs)) == sizeof(fontprefs)) */
160 } /* if ((cn->cn_ID == ID_FONT) && (cn->cn_Size == sizeof(fontprefs))) */
162 } /* while(ParseIFF(iff, IFFPARSE_SCAN) == 0) */
164 KillIFF(iff);
166 } /* if ((iff = CreateIFF(filename))) */
169 D(bug("In IPrefs:FontPrefs_Handler. Done with '%s'.\n", filename));
172 /*********************************************************************************************/