Experiment:
[AROS-Contrib.git] / bgui / filereqclass.c
blob0e5e57c1427f0ff335e5e814f8154bd1d8d94ceb
1 /*
2 * @(#) $Header$
4 * BGUI library
5 * filereqclass.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:53 mlemos
21 * Bumped to revision 42.0 before handing BGUI to AROS team
23 * Revision 41.11 2000/05/09 19:54:14 mlemos
24 * Merged with the branch Manuel_Lemos_fixes.
26 * Revision 41.10.2.1 1999/07/03 15:17:35 mlemos
27 * Replaced the calls to CallHookPkt to BGUI_CallHookPkt.
29 * Revision 41.10 1998/02/25 21:12:00 mlemos
30 * Bumping to 41.10
32 * Revision 1.1 1998/02/25 17:08:12 mlemos
33 * Ian sources
38 #include "include/classdefs.h"
40 /// Class definitions.
42 * Object instance data.
44 typedef struct {
45 struct Hook *fd_MultiHook; /* Multi-select hook */
46 UBYTE fd_Drawer [MAX_DRAWER + 2]; /* Drawer buffer */
47 UBYTE fd_File [MAX_FILE + 2]; /* Filename buffer */
48 UBYTE fd_Path [MAX_PATH + 2]; /* Full path buffer */
49 UBYTE fd_Pattern[MAX_PATTERN + 2]; /* Pattern buffer */
50 } FD;
51 ///
53 /// OM_NEW
55 * Create a shiny new object.
57 METHOD(FileReqClassNew, struct opSet *, ops)
59 ULONG rc;
60 struct TagItem *tags;
62 tags = DefTagList(BGUI_FILEREQ_OBJECT, ops->ops_AttrList);
65 * First we let the superclass create the object.
67 if (rc = NewSuperObject(cl, obj, tags))
70 * Setup user attributes.
72 if (AsmCoerceMethod(cl, (Object *)rc, OM_SET, tags, NULL) != ASLREQ_OK)
75 * Failure.
77 AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
78 rc = 0;
81 FreeTagItems(tags);
83 return rc;
85 METHOD_END
86 ///
87 /// OM_DISPOSE
89 * They want us gone.
91 METHOD(FileReqClassDispose, Msg, msg)
94 * The superclass does the rest.
96 return AsmDoSuperMethodA(cl, obj, msg);
98 METHOD_END
99 ///
100 /// OM_SET, OM_UPDATE
102 * Change one or more of the object
103 * it's attributes.
105 METHOD(FileReqClassSetUpdate, struct opSet *, ops)
107 FD *fd = INST_DATA(cl, obj);
108 struct TagItem *tag, *tstate = ops->ops_AttrList;
109 ULONG data, rc;
110 BOOL path_update = FALSE;
113 * First we let the superclass have a go at it.
115 rc = AsmDoSuperMethodA(cl, obj, (Msg)ops);
117 while (tag = NextTagItem(&tstate))
119 data = tag->ti_Data;
120 switch (tag->ti_Tag)
122 case FILEREQ_MultiHook:
123 fd->fd_MultiHook = (struct Hook *)data;
124 break;
125 case ASLFR_InitialFile:
126 case FILEREQ_File:
127 strncpy(fd->fd_File, (UBYTE *)data, MAX_FILE);
128 path_update = TRUE;
129 break;
130 case ASLFR_InitialDrawer:
131 case FILEREQ_Drawer:
132 strncpy(fd->fd_Drawer, (UBYTE *)data, MAX_DRAWER);
133 path_update = TRUE;
134 break;
135 case ASLFR_InitialPattern:
136 case FILEREQ_Pattern:
137 strncpy(fd->fd_Pattern, (UBYTE *)data, MAX_PATTERN);
138 break;
140 if (path_update)
142 strncpy(fd->fd_Path, fd->fd_Drawer, MAX_PATH);
143 AddPart(fd->fd_Path, fd->fd_File, MAX_PATH);
146 return rc;
148 METHOD_END
150 /// OM_GET
152 * Give one of the attributes.
154 METHOD(FileReqClassGet, struct opGet *, opg)
156 FD *fd = INST_DATA(cl, obj);
157 ULONG rc = 1, *store = opg->opg_Storage, attr = opg->opg_AttrID;
159 switch (attr)
161 case ASLFR_InitialDrawer:
162 case FILEREQ_Drawer:
163 STORE fd->fd_Drawer;
164 break;
165 case ASLFR_InitialFile:
166 case FILEREQ_File:
167 STORE fd->fd_File;
168 break;
169 case ASLFR_InitialPattern:
170 case FILEREQ_Pattern:
171 STORE fd->fd_Pattern;
172 break;
173 case FILEREQ_Path:
174 STORE fd->fd_Path;
175 break;
176 case FILEREQ_MultiHook:
177 STORE fd->fd_MultiHook;
178 break;
179 default:
180 rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
181 break;
183 return rc;
185 METHOD_END
187 /// ASLM_DOREQUEST
189 * Pop up the filerequester.
191 METHOD(FileReqClassDoRequest, Msg, msg)
193 FD *fd = INST_DATA(cl, obj);
194 struct FileRequester *fr;
195 ULONG rc = ASLREQ_OK;
197 DoSuperSetMethodNG(cl, obj, ASLFR_InitialFile, fd->fd_File,
198 ASLFR_InitialDrawer, fd->fd_Drawer,
199 ASLFR_InitialPattern, fd->fd_Pattern, TAG_DONE);
202 * Allocate filerequester structure.
204 if (fr = (struct FileRequester *)AsmDoSuperMethod(cl, obj, ASLM_ALLOCREQUEST))
207 * Put up the requester.
209 if (AsmDoSuperMethod(cl, obj, ASLM_REQUEST))
212 * Copy drawer, file and pattern strings.
214 DoSetMethodNG(obj, FILEREQ_File, fr->fr_File,
215 FILEREQ_Drawer, fr->fr_Drawer,
216 FILEREQ_Pattern, fr->fr_Pattern, TAG_DONE);
219 * Do we have a multi-select hook?
221 if (fd->fd_MultiHook)
224 * Any multi-selections made?
226 if (fr->fr_NumArgs)
227 BGUI_CallHookPkt(fd->fd_MultiHook, (VOID *)obj, (VOID *)fr);
230 } else
231 rc = ASLREQ_CANCEL;
234 * Remember these even if the requester was cancelled.
236 DoSuperSetMethodNG(cl, obj, ASLREQ_Bounds, &fr->fr_LeftEdge, TAG_DONE);
239 * Free the requester structure.
241 AsmDoSuperMethod(cl, obj, ASLM_FREEREQUEST);
242 } else
243 rc = ASLREQ_ERROR_NO_REQ;
245 return rc;
247 METHOD_END
250 /// Class initialization.
252 * Function table.
254 STATIC DPFUNC ClassFunc[] = {
255 OM_NEW, (FUNCPTR)FileReqClassNew,
256 OM_SET, (FUNCPTR)FileReqClassSetUpdate,
257 OM_UPDATE, (FUNCPTR)FileReqClassSetUpdate,
258 OM_GET, (FUNCPTR)FileReqClassGet,
259 OM_DISPOSE, (FUNCPTR)FileReqClassDispose,
260 ASLM_DOREQUEST, (FUNCPTR)FileReqClassDoRequest,
261 DF_END, NULL
265 * Simple class initialization.
267 makeproto Class *InitFileReqClass(void)
269 return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_ASLREQ_OBJECT,
270 CLASS_ObjectSize, sizeof(FD),
271 CLASS_DFTable, ClassFunc,
272 TAG_DONE);