Hint added.
[AROS.git] / workbench / prefs / font / fpeditor.c
blobce43e259f8414c865688953b9d702423e8554721
1 /*
2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <libraries/asl.h>
9 #include <libraries/mui.h>
10 #include <zune/customclasses.h>
11 #include <zune/prefseditor.h>
13 #include <proto/alib.h>
14 #include <proto/intuition.h>
15 #include <proto/dos.h>
17 #include <string.h>
18 #include <stdio.h>
20 #include "misc.h"
21 #include "locale.h"
22 #include "fpeditor.h"
23 #include "prefs.h"
25 /*** Instance Data **********************************************************/
26 struct FPEditor_DATA
28 struct FontPrefs fped_FontPrefs[FP_COUNT];
29 Object *fped_IconsString,
30 *fped_ScreenString,
31 *fped_SystemString;
34 /*** Macros *****************************************************************/
35 #define SETUP_INST_DATA struct FPEditor_DATA *data = INST_DATA(CLASS, self)
36 #define FP(i) (&(data->fped_FontPrefs[(i)]))
38 /*** Utility Functions ******************************************************/
39 static VOID FontPrefs2FontString
41 STRPTR buffer, ULONG buffersize, struct FontPrefs *fp
44 snprintf
46 buffer, buffersize, "%.*s/%d",
47 (int)strlen(fp->fp_TextAttr.ta_Name) - 5 /* strlen(".font") */,
48 fp->fp_TextAttr.ta_Name, fp->fp_TextAttr.ta_YSize
52 static BOOL FontString2FontPrefs(struct FontPrefs *fp, CONST_STRPTR buffer)
54 STRPTR separator = PathPart((STRPTR) buffer);
55 ULONG nameLength = separator - buffer;
56 ULONG suffixLength = 5; /* strlen(".font") */
57 ULONG size;
59 if (nameLength + suffixLength >= FONTNAMESIZE)
61 /* Not enough space for the font name */
62 return FALSE;
65 snprintf
67 fp->fp_Name, nameLength + suffixLength + 1, "%.*s.font",
68 (int) nameLength, buffer
70 fp->fp_TextAttr.ta_Name = fp->fp_Name;
72 StrToLong(FilePart((STRPTR) buffer), &size);
73 fp->fp_TextAttr.ta_YSize = size;
75 return TRUE;
78 static BOOL Gadgets2FontPrefs
80 struct FPEditor_DATA *data
83 STRPTR str = NULL;
85 // FIXME: error checking
86 GET(data->fped_IconsString, MUIA_String_Contents, &str);
87 FontString2FontPrefs(FP(FP_WBFONT), str);
88 FP(FP_WBFONT)->fp_Type = FP_WBFONT;
90 GET(data->fped_SystemString, MUIA_String_Contents, &str);
91 FontString2FontPrefs(FP(FP_SYSFONT), str);
92 FP(FP_SYSFONT)->fp_Type = FP_SYSFONT;
94 GET(data->fped_ScreenString, MUIA_String_Contents, &str);
95 FontString2FontPrefs(FP(FP_SCREENFONT), str);
96 FP(FP_SCREENFONT)->fp_Type = FP_SCREENFONT;
98 return TRUE;
101 static BOOL FontPrefs2Gadgets
103 struct FPEditor_DATA *data
106 TEXT buffer[FONTNAMESIZE + 8];
108 // FIXME: error checking
109 FontPrefs2FontString(buffer, FONTNAMESIZE + 8, FP(FP_WBFONT));
110 NNSET(data->fped_IconsString, MUIA_String_Contents, (IPTR) buffer);
112 FontPrefs2FontString(buffer, FONTNAMESIZE + 8, FP(FP_SYSFONT));
113 NNSET(data->fped_SystemString, MUIA_String_Contents, (IPTR) buffer);
115 FontPrefs2FontString(buffer, FONTNAMESIZE + 8, FP(FP_SCREENFONT));
116 NNSET(data->fped_ScreenString, MUIA_String_Contents, (IPTR) buffer);
118 return TRUE;
121 /*** Methods ****************************************************************/
122 static Object *FPEditor__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
124 Object *iconsString, *screenString, *systemString;
126 self = (Object *) DoSuperNewTags
128 CLASS, self, NULL,
130 MUIA_PrefsEditor_Name, __(MSG_NAME),
131 MUIA_PrefsEditor_Path, (IPTR) "SYS/font.prefs",
132 MUIA_PrefsEditor_IconTool, (IPTR) "SYS:Prefs/Font",
134 Child, (IPTR) ColGroup(2),
135 Child, (IPTR) Label2(_(MSG_ICONS)),
136 Child, (IPTR) PopaslObject,
137 MUIA_Popasl_Type, ASL_FontRequest,
138 ASLFO_MaxHeight, 100,
139 MUIA_Popstring_String, (IPTR) (iconsString = (Object *)StringObject,
140 TextFrame,
141 MUIA_Background, MUII_TextBack,
142 End),
143 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
144 End,
145 Child, (IPTR) Label2(_(MSG_SCREEN)),
146 Child, (IPTR) PopaslObject,
147 MUIA_Popasl_Type, ASL_FontRequest,
148 ASLFO_MaxHeight, 100,
149 MUIA_Popstring_String, (IPTR) (screenString = (Object *)StringObject,
150 TextFrame,
151 MUIA_Background, MUII_TextBack,
152 End),
153 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
154 End,
155 Child, (IPTR) Label2(_(MSG_SYSTEM)),
156 Child, (IPTR) PopaslObject,
157 MUIA_Popasl_Type, ASL_FontRequest,
158 ASLFO_FixedWidthOnly, TRUE,
159 ASLFO_MaxHeight, 100,
160 MUIA_Popstring_String, (IPTR) (systemString = (Object *)StringObject,
161 TextFrame,
162 MUIA_Background, MUII_TextBack,
163 End),
164 MUIA_Popstring_Button, (IPTR) PopButton(MUII_PopUp),
165 End,
166 End,
168 TAG_DONE
171 if (self != NULL)
173 SETUP_INST_DATA;
174 data->fped_IconsString = iconsString;
175 data->fped_ScreenString = screenString;
176 data->fped_SystemString = systemString;
178 /*-- Setup notifications -------------------------------------------*/
179 DoMethod
181 iconsString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
182 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
184 DoMethod
186 screenString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
187 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
189 DoMethod
191 systemString, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
192 (IPTR) self, 3, MUIM_Set, MUIA_PrefsEditor_Changed, TRUE
196 return self;
199 static IPTR FPEditor__MUIM_PrefsEditor_ImportFH
201 Class *CLASS, Object *self,
202 struct MUIP_PrefsEditor_ImportFH *message
205 SETUP_INST_DATA;
206 BOOL success = TRUE;
208 success = Prefs_ImportFH(message->fh, data->fped_FontPrefs);
209 if (success) FontPrefs2Gadgets(data);
211 return success;
214 static IPTR FPEditor__MUIM_PrefsEditor_ExportFH
216 Class *CLASS, Object *self,
217 struct MUIP_PrefsEditor_ExportFH *message
220 SETUP_INST_DATA;
221 BOOL success = TRUE;
223 Gadgets2FontPrefs(data);
224 success = Prefs_ExportFH(message->fh, data->fped_FontPrefs);
226 return success;
229 static IPTR FPEditor__MUIM_PrefsEditor_SetDefaults
231 Class *CLASS, Object *self,
232 Msg message
235 SETUP_INST_DATA;
236 BOOL success = TRUE;
238 success = Prefs_Default(data->fped_FontPrefs);
239 if (success) FontPrefs2Gadgets(data);
241 return success;
244 /*** Setup ******************************************************************/
245 ZUNE_CUSTOMCLASS_4
247 FPEditor, NULL, MUIC_PrefsEditor, NULL,
248 OM_NEW, struct opSet *,
249 MUIM_PrefsEditor_ImportFH, struct MUIP_PrefsEditor_ImportFH *,
250 MUIM_PrefsEditor_ExportFH, struct MUIP_PrefsEditor_ExportFH *,
251 MUIM_PrefsEditor_SetDefaults, Msg