2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
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>
25 /*** Instance Data **********************************************************/
28 struct FontPrefs fped_FontPrefs
[FP_COUNT
];
29 Object
*fped_IconsString
,
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
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") */
59 if (nameLength
+ suffixLength
>= FONTNAMESIZE
)
61 /* Not enough space for the font name */
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
;
78 static BOOL Gadgets2FontPrefs
80 struct FPEditor_DATA
*data
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
;
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
);
121 /*** Methods ****************************************************************/
122 static Object
*FPEditor__OM_NEW(Class
*CLASS
, Object
*self
, struct opSet
*message
)
124 Object
*iconsString
, *screenString
, *systemString
;
126 self
= (Object
*) DoSuperNewTags
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
,
141 MUIA_Background
, MUII_TextBack
,
143 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
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
,
151 MUIA_Background
, MUII_TextBack
,
153 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
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
,
162 MUIA_Background
, MUII_TextBack
,
164 MUIA_Popstring_Button
, (IPTR
) PopButton(MUII_PopUp
),
174 data
->fped_IconsString
= iconsString
;
175 data
->fped_ScreenString
= screenString
;
176 data
->fped_SystemString
= systemString
;
178 /*-- Setup notifications -------------------------------------------*/
181 iconsString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
182 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
186 screenString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
187 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
191 systemString
, MUIM_Notify
, MUIA_String_Acknowledge
, MUIV_EveryTime
,
192 (IPTR
) self
, 3, MUIM_Set
, MUIA_PrefsEditor_Changed
, TRUE
199 static IPTR FPEditor__MUIM_PrefsEditor_ImportFH
201 Class
*CLASS
, Object
*self
,
202 struct MUIP_PrefsEditor_ImportFH
*message
208 success
= Prefs_ImportFH(message
->fh
, data
->fped_FontPrefs
);
209 if (success
) FontPrefs2Gadgets(data
);
214 static IPTR FPEditor__MUIM_PrefsEditor_ExportFH
216 Class
*CLASS
, Object
*self
,
217 struct MUIP_PrefsEditor_ExportFH
*message
223 Gadgets2FontPrefs(data
);
224 success
= Prefs_ExportFH(message
->fh
, data
->fped_FontPrefs
);
229 static IPTR FPEditor__MUIM_PrefsEditor_SetDefaults
231 Class
*CLASS
, Object
*self
,
238 success
= Prefs_Default(data
->fped_FontPrefs
);
239 if (success
) FontPrefs2Gadgets(data
);
244 /*** Setup ******************************************************************/
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