SFS moved to core
[AROS-Contrib.git] / ScalosV2 / TableClass.c
blobcfffacf4e7f82a52d0949a767c0e8953b588cb0c
1 // :ts=4 (Tabsize)
3 /*
4 ** Amiga Workbench® Replacement
5 **
6 ** (C) Copyright 1999,2000 Aliendesign
7 ** Stefan Sommerfeld, Jörg Rebenstorf
8 **
9 ** Redistribution and use in source and binary forms are permitted provided that
10 ** the above copyright notice and this paragraph are duplicated in all such
11 ** forms and that any documentation, advertising materials, and other
12 ** materials related to such distribution and use acknowledge that the
13 ** software was developed by Aliendesign.
14 ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
15 ** WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
16 ** MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 #include <proto/utility.h>
20 #include <proto/alib.h>
21 #include <string.h>
23 #include "Scalos.h"
24 #include "TableClass.h"
25 #include "ScalosIntern.h"
27 #include "scalos_protos.h"
28 #include "Debug.h"
29 #include "SubRoutines.h"
31 /****** Table.scalos/--background *******************************************
33 * Table class is used to identify what special infos an icon can have.
34 * Nearly all attributes of this class are relative to the current selected
35 * element, which can be selected using SCCM_Table_Entry.
37 *****************************************************************************
39 // /
41 /****** Table.scalos/SCCA_Table_Attribute ***********************************
43 * NAME
44 * SCCA_Table_Attribute -- (V40) ..G (ULONG)
46 * FUNCTION
47 * With the attribute of a field you can find or remove the entry and it's
48 * used to get information from an icon.
50 * Example:
51 * Attr: SCCA_DOSIcon_Size
52 * Name: "Size"
53 * Type: SCCV_Table_Type_Long
54 * Flags: 0
55 * Size: 4
57 *****************************************************************************
59 // /
60 /****** Table.scalos/SCCA_Table_Name ****************************************
62 * NAME
63 * SCCA_Table_Name -- (V40) ..G (char *)
65 * FUNCTION
66 * That's the name of the field. It is already translated to the current
67 * languange. It maybe using to identify the information for the user.
69 *****************************************************************************
71 // /
72 /****** Table.scalos/SCCA_Table_Count ***************************************
74 * NAME
75 * SCCA_Table_Count -- (V40) ..G (ULONG)
77 * FUNCTION
78 * Getting this attribute will return the current number of fields in the
79 * table.
81 *****************************************************************************
83 // /
84 /****** Table.scalos/SCCA_Table_Type ****************************************
86 * NAME
87 * SCCA_Table_Type -- (V40) ..G (ULONG)
89 * FUNCTION
90 * This attribute gives you information about the datatype of this field.
91 * See SCCM_Table_Add for more information.
93 *****************************************************************************
95 // /
96 /****** Table.scalos/SCCA_Table_Flags ***************************************
98 * NAME
99 * SCCA_Table_Flags -- (V40) ..G (ULONG)
101 * FUNCTION
102 * Which flags has the field. Currently there are no flags defined.
104 *****************************************************************************
106 // /
107 /****** Table.scalos/SCCA_Table_Size ****************************************
109 * NAME
110 * SCCA_Table_Size -- (V40) ..G (ULONG)
112 * FUNCTION
113 * This attribute is use to give size information of the field data. It's
114 * majorly used for SCCV_Table_Type_Raw, but it will return a valid value
115 * for each type.
117 *****************************************************************************
119 // /
121 /** Init a table
123 static ULONG Table_Init(struct SC_Class *cl, Object *obj, struct SCCP_Init *msg, struct TableInst *inst)
125 if (SC_DoSuperMethodA(cl,obj, (Msg) msg))
127 NewList((struct List *) &inst->list);
128 return(TRUE);
130 return(FALSE);
132 // /
134 /** Exit a table
136 static ULONG Table_Exit(struct SC_Class *cl, Object *obj, Msg msg, struct TableInst *inst)
138 FreeAllNodes(&inst->list);
139 return(SC_DoSuperMethodA(cl,obj, (Msg) msg));
141 // /
143 /****** Table.scalos/SCCM_Table_Add *****************************************
145 * NAME
146 * SCCM_Table_Add
148 * SYNOPSIS
149 * ULONG SC_DoMethod(obj,SCCM_Table_Add, ULONG Attr, char *Name, ULONG Type, ULONG Flags, ULONG Size);
151 * FUNCTION
152 * This methods addes the information of a new field to the table.
154 * INPUTS
155 * Attr - attribute to identify the field (e.g. SCCA_Icon_Name)
156 * Name - the name of the field, translated to the current language
157 * Type - datatype
158 * SCCV_Table_Type_String - pointer to a zero terminated string
159 * SCCV_Table_Type_Long - long value
160 * SCCV_Table_Type_Double - pointer to a double value
161 * SCCV_Table_Type_Time - pointer to 2 longs (secs,micros)
162 * SCCV_Table_Type_Raw - pointer to unknown data (check Size)
163 * Flags - flags for the datatype, currently none available
164 * Size - size of the Raw data. Must only be given if type is
165 * SCCV_Table_Type_Raw.
167 * RESULT
168 * TRUE if adding was successfully, else FALSE.
170 * NOTES
172 * SEE ALSO
173 * SCCM_Table_Remove
175 *****************************************************************************
177 static ULONG Table_Add(struct SC_Class *cl, Object *obj, struct SCCP_Table_Add *msg, struct TableInst *inst)
179 struct TableNode *tn;
181 if ((tn = (struct TableNode *) AllocNode(&inst->list,sizeof(struct TableNode) + strlen(msg->Name))))
183 tn->Attr = msg->Attr;
184 tn->Type = msg->Type;
185 tn->Flags = msg->Flags;
186 strcpy(&tn->Name,msg->Name);
187 inst->count++;
189 switch (tn->Type)
191 case SCCV_Table_Type_String :
192 tn->Size = strlen(&tn->Name);
193 break;
194 case SCCV_Table_Type_Long :
195 tn->Size = sizeof(ULONG);
196 break;
197 case SCCV_Table_Type_Double :
198 tn->Size = sizeof(double);
199 break;
200 case SCCV_Table_Type_Date :
201 tn->Size = 2*sizeof(ULONG);
202 break;
203 case SCCV_Table_Type_Raw :
204 tn->Size = msg->Size;
205 break;
208 if (inst->curnode == NULL)
209 inst->curnode = tn;
210 return(TRUE);
212 return(FALSE);
214 // /
216 /****** Table.scalos/SCCM_Table_Remove **************************************
218 * NAME
219 * SCCM_Table_Remove
221 * SYNOPSIS
222 * SC_DoMethod(obj,SCCM_Table_Remove, ULONG Attr);
224 * FUNCTION
225 * Remove an entry identified by the ID from the table. If it was the
226 * current entry, the previous entry will be selected.
228 * INPUTS
229 * Attr - attribute to identify the field (e.g. SCCA_Icon_Name)
231 * RESULT
233 * NOTES
235 * SEE ALSO
236 * SCCM_Table_Add
238 *****************************************************************************
240 static void Table_Rem(struct SC_Class *cl, Object *obj, struct SCCP_Table_Remove *msg, struct TableInst *inst)
242 struct MinNode *node;
244 for (node = inst->list.mlh_Head; node->mln_Succ; node = node->mln_Succ)
246 if ((((struct TableNode *) node)->Attr = msg->Attr))
248 if (((ULONG) inst->curnode) == ((ULONG) node))
250 if ((inst->curnode = (struct TableNode *) node->mln_Pred)->node.mln_Pred == NULL)
252 if (IsListEmpty((struct List *) &inst->list))
253 inst->curnode = NULL;
254 else
255 inst->curnode = (struct TableNode *) inst->list.mlh_Head;
259 FreeNode(node);
260 inst->count--;
261 inst->curnode = NULL;
262 return;
266 // /
268 /****** Table.scalos/SCCM_Table_Entry ***************************************
270 * NAME
271 * SCCM_Table_Entry
273 * SYNOPSIS
274 * ULONG SC_DoMethod(obj,SCCM_Table_Entry, ULONG Pos);
276 * FUNCTION
277 * This method selectes a current entry. All attributes are relative to this
278 * entry except SCCA_Table_Count. Preselected is the first entry.
280 * INPUTS
281 * Pos - one of these values
282 * SCCV_Table_Entry_First - select first entry
283 * SCCV_Table_Entry_Last - select last entry
284 * SCCV_Table_Entry_Next - select next entry
285 * SCCV_Table_Entry_Previous - select previous entry
287 * RESULT
288 * TRUE if the new entry was successfully selected.
290 * NOTES
292 * SEE ALSO
293 * SCCM_Table_Add, SCCM_Table_Remove
295 *****************************************************************************
297 static ULONG Table_Entry(struct SC_Class *cl, Object *obj, struct SCCP_Table_Entry *msg, struct TableInst *inst)
299 if (msg->Pos == SCCV_Table_Entry_Next)
301 if (inst->curnode)
303 inst->curnode = (struct TableNode *) inst->curnode->node.mln_Succ;
304 if (inst->curnode->node.mln_Succ != 0)
305 return(TRUE);
309 if (msg->Pos == SCCV_Table_Entry_Previous)
311 if (inst->curnode)
313 inst->curnode = (struct TableNode *) inst->curnode->node.mln_Pred;
314 if (inst->curnode->node.mln_Pred != 0)
315 return(TRUE);
319 if ((msg->Pos == SCCV_Table_Entry_First) && !(IsListEmpty((struct List *) &inst->list)))
321 inst->curnode = (struct TableNode *) inst->list.mlh_Head;
322 return(TRUE);
325 if ((msg->Pos == SCCV_Table_Entry_Last) && !(IsListEmpty((struct List *) &inst->list)))
327 inst->curnode = (struct TableNode *) inst->list.mlh_Tail;
328 return(TRUE);
331 return(FALSE);
333 // /
335 /** Get one attribute of all of the getable attributes
337 static ULONG Table_Get( struct SC_Class *cl, Object *obj, struct opGet *msg, struct TableInst *inst )
339 if (inst->curnode)
341 if (msg->opg_AttrID == SCCA_Table_Attribute)
343 *(msg->opg_Storage) = inst->curnode->Attr;
344 return(TRUE);
346 if (msg->opg_AttrID == SCCA_Table_Name)
348 *(msg->opg_Storage) = (ULONG) &inst->curnode->Name;
349 return(TRUE);
351 if (msg->opg_AttrID == SCCA_Table_Type)
353 *(msg->opg_Storage) = inst->curnode->Type;
354 return(TRUE);
356 if (msg->opg_AttrID == SCCA_Table_Flags)
358 *(msg->opg_Storage) = inst->curnode->Flags;
359 return(TRUE);
361 if (msg->opg_AttrID == SCCA_Table_Size)
363 *(msg->opg_Storage) = inst->curnode->Size;
364 return(TRUE);
368 if (msg->opg_AttrID == SCCA_Table_Count)
370 *(msg->opg_Storage) = inst->count;
371 return(TRUE);
374 return(SC_DoSuperMethodA(cl, obj, (Msg) msg));
376 // /
378 /*-------------------------- MethodList --------------------------------*/
380 struct SC_MethodData TableMethods[] =
382 { SCCM_Table_Add,(ULONG) Table_Add, sizeof(struct SCCP_Table_Add), 0, NULL },
383 { SCCM_Table_Remove,(ULONG) Table_Rem, sizeof(struct SCCP_Table_Remove), 0, NULL },
384 { SCCM_Table_Entry,(ULONG) Table_Entry, sizeof(struct SCCP_Table_Entry), 0, NULL },
385 { SCCM_Init,(ULONG) Table_Init, 0, 0, NULL },
386 { SCCM_Exit,(ULONG) Table_Exit, 0, 0, NULL },
387 { OM_GET,(ULONG) Table_Get, 0, 0, NULL },
388 { SCMETHOD_DONE, NULL, 0, 0, NULL }