forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / bgui / fontreqclass.c
blob2c2f7308121b78b4cf04a90173e1f555c9928b8a
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * fontreqclass.c
7 * (C) Copyright 1998 Manuel Lemos.
8 * (C) Copyright 1996-1997 Ian J. Einman.
9 * (C) Copyright 1993-1996 Jaba Development.
10 * (C) Copyright 1993-1996 Jan van den Baard.
11 * All Rights Reserved.
13 * $Log$
14 * Revision 42.2 2004/06/16 20:16:48 verhaegs
15 * Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
17 * Revision 42.1 2000/05/15 19:27:01 stegerg
18 * another hundreds of REG() macro replacements in func headers/protos.
20 * Revision 42.0 2000/05/09 22:08:56 mlemos
21 * Bumped to revision 42.0 before handing BGUI to AROS team
23 * Revision 41.11 2000/05/09 19:54:15 mlemos
24 * Merged with the branch Manuel_Lemos_fixes.
26 * Revision 41.10.2.1 1999/08/11 02:30:38 mlemos
27 * Assured that the initial values passed to the font requester match the
28 * defaults of the ASLRequest() call.
30 * Revision 41.10 1998/02/25 21:12:02 mlemos
31 * Bumping to 41.10
33 * Revision 1.1 1998/02/25 17:08:16 mlemos
34 * Ian sources
39 #include "include/classdefs.h"
41 /// Class definitions.
43 * Object instance data.
45 typedef struct {
46 struct TextAttr fd_TextAttr; /* Selected font */
47 UBYTE fd_Name[MAX_FILE + 2]; /* Fontname buffer */
48 UBYTE fd_FrontPen; /* Selected FrontPen */
49 UBYTE fd_BackPen; /* Selected BackPen */
50 UBYTE fd_DrawMode; /* Selected DrawMode */
51 } FD;
52 ///
54 /// OM_NEW
56 * Create a shiny new object.
58 METHOD(FontReqClassNew, struct opSet *, ops)
60 IPTR rc;
61 struct TagItem *tags;
63 tags = DefTagList(BGUI_FONTREQ_OBJECT, ops->ops_AttrList);
66 * First we let the superclass create the object.
68 if ((rc = NewSuperObject(cl, obj, tags)))
70 FD *fd = INST_DATA(cl, rc);
72 fd->fd_Name[0]='\0';
73 fd->fd_TextAttr.ta_YSize=8;
74 fd->fd_TextAttr.ta_Style=FS_NORMAL;
75 fd->fd_TextAttr.ta_Flags=FPF_ROMFONT;
76 fd->fd_FrontPen=1;
77 fd->fd_BackPen=0;
78 fd->fd_DrawMode=JAM1;
81 * Setup user attributes.
83 if (AsmCoerceMethod(cl, (Object *)rc, OM_SET, tags, NULL) != ASLREQ_OK)
86 * Failure.
88 AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
89 rc = 0;
92 FreeTagItems(tags);
94 return rc;
96 METHOD_END
97 ///
98 /// OM_DISPOSE
100 * They want us gone.
102 METHOD(FontReqClassDispose, Msg, msg)
105 * The superclass does the rest.
107 return AsmDoSuperMethodA(cl, obj, msg);
109 METHOD_END
111 /// OM_SET, OM_UPDATE
113 * Change one or more of the object
114 * it's attributes.
116 METHOD(FontReqClassSetUpdate, struct opSet *, ops)
118 FD *fd = INST_DATA(cl, obj);
119 IPTR data, rc;
120 struct TagItem *tstate = ops->ops_AttrList;
121 struct TagItem *tag;
124 * First we let the superclass
125 * have a go at it.
127 rc = AsmDoSuperMethodA(cl, obj, (Msg)ops);
129 while ((tag = NextTagItem(&tstate)))
131 data = tag->ti_Data;
132 switch (tag->ti_Tag)
134 case ASLFO_InitialName:
135 case FONTREQ_Name:
136 fd->fd_Name[0] = 0;
137 if (data) strncpy(fd->fd_Name, (char *)data, MAX_FILE);
138 break;
139 case ASLFO_InitialSize:
140 case FONTREQ_Size:
141 fd->fd_TextAttr.ta_YSize = data;
142 break;
143 case ASLFO_InitialStyle:
144 case FONTREQ_Style:
145 fd->fd_TextAttr.ta_Style = data;
146 break;
147 case ASLFO_InitialFlags:
148 case FONTREQ_Flags:
149 fd->fd_TextAttr.ta_Flags = data;
150 break;
151 case ASLFO_InitialFrontPen:
152 case FONTREQ_FrontPen:
153 fd->fd_FrontPen = data;
154 break;
155 case ASLFO_InitialBackPen:
156 case FONTREQ_BackPen:
157 fd->fd_BackPen = data;
158 break;
159 case ASLFO_InitialDrawMode:
160 case FONTREQ_DrawMode:
161 fd->fd_DrawMode = data;
162 break;
163 case FONTREQ_TextAttr:
164 fd->fd_Name[0] = 0;
165 if (data)
167 fd->fd_TextAttr = *((struct TextAttr *)data);
168 if (fd->fd_TextAttr.ta_Name)
169 strncpy(fd->fd_Name, fd->fd_TextAttr.ta_Name, MAX_FILE);
170 fd->fd_TextAttr.ta_Name = fd->fd_Name;
172 break;
175 return rc;
177 METHOD_END
179 /// OM_GET
181 * Give one of the attributes.
183 METHOD(FontReqClassGet, struct opGet *, opg)
185 FD *fd = INST_DATA(cl, obj);
186 ULONG rc = 1;
187 IPTR *store = opg->opg_Storage;
188 IPTR attr = opg->opg_AttrID;
190 switch (attr)
192 case ASLFO_InitialName:
193 case FONTREQ_Name:
194 STORE fd->fd_Name;
195 break;
196 case ASLFO_InitialSize:
197 case FONTREQ_Size:
198 STORE fd->fd_TextAttr.ta_YSize;
199 break;
200 case ASLFO_InitialStyle:
201 case FONTREQ_Style:
202 STORE fd->fd_TextAttr.ta_Style;
203 break;
204 case ASLFO_InitialFlags:
205 case FONTREQ_Flags:
206 STORE fd->fd_TextAttr.ta_Flags;
207 break;
208 case ASLFO_InitialFrontPen:
209 case FONTREQ_FrontPen:
210 STORE fd->fd_FrontPen;
211 break;
212 case ASLFO_InitialBackPen:
213 case FONTREQ_BackPen:
214 STORE fd->fd_BackPen;
215 break;
216 case ASLFO_InitialDrawMode:
217 case FONTREQ_DrawMode:
218 STORE fd->fd_DrawMode;
219 break;
220 case FONTREQ_TextAttr:
221 STORE &fd->fd_TextAttr;
222 break;
223 default:
224 rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
225 break;
227 return rc;
229 METHOD_END
231 /// ASLM_DOREQUEST
233 * Pop up the FontRequester.
235 METHOD(FontReqClassDoRequest, Msg, msg)
237 FD *fd = INST_DATA(cl, obj);
238 struct FontRequester *fo;
239 ULONG rc = ASLREQ_OK;
241 DoSuperSetMethodNG(cl, obj, ASLFO_InitialName, fd->fd_Name,
242 ASLFO_InitialSize, fd->fd_TextAttr.ta_YSize,
243 ASLFO_InitialStyle, fd->fd_TextAttr.ta_Style,
244 ASLFO_InitialFlags, fd->fd_TextAttr.ta_Flags,
245 ASLFO_InitialFrontPen, fd->fd_FrontPen,
246 ASLFO_InitialBackPen, fd->fd_BackPen,
247 ASLFO_InitialDrawMode, fd->fd_DrawMode, TAG_DONE);
250 * Allocate FontRequester structure.
252 if ((fo = (struct FontRequester *)AsmDoSuperMethod(cl, obj, ASLM_ALLOCREQUEST)))
255 * Put up the requester.
257 if (AsmDoSuperMethod(cl, obj, ASLM_REQUEST))
260 * Copy font information.
262 DoSetMethodNG(obj, FONTREQ_TextAttr, &fo->fo_Attr,
263 FONTREQ_FrontPen, fo->fo_FrontPen,
264 FONTREQ_BackPen, fo->fo_BackPen,
265 FONTREQ_DrawMode, fo->fo_DrawMode, TAG_DONE);
266 } else
267 rc = ASLREQ_CANCEL;
269 * Remember these even if the requester was cancelled.
271 DoSuperSetMethodNG(cl, obj, ASLREQ_Bounds, &fo->fo_LeftEdge, TAG_DONE);
274 * Free the requester structure.
276 AsmDoSuperMethod(cl, obj, ASLM_FREEREQUEST);
277 } else
278 rc = ASLREQ_ERROR_NO_REQ;
280 return rc;
282 METHOD_END
285 /// Class initialization.
287 * Function table.
289 STATIC DPFUNC ClassFunc[] = {
290 { OM_NEW, FontReqClassNew, },
291 { OM_SET, FontReqClassSetUpdate, },
292 { OM_UPDATE, FontReqClassSetUpdate, },
293 { OM_GET, FontReqClassGet, },
294 { OM_DISPOSE, FontReqClassDispose, },
295 { ASLM_DOREQUEST, FontReqClassDoRequest, },
296 { DF_END, NULL },
300 * Simple class initialization.
302 makeproto Class *InitFontReqClass(void)
304 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_ASLREQ_OBJECT,
305 CLASS_ObjectSize, sizeof(FD),
306 CLASS_DFTable, ClassFunc,
307 TAG_DONE);