4 ** Amiga Workbench® Replacement
6 ** (C) Copyright 1999,2000 Aliendesign
7 ** Stefan Sommerfeld, Jörg Rebenstorf
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>
24 #include "TableClass.h"
25 #include "ScalosIntern.h"
27 #include "scalos_protos.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 *****************************************************************************
41 /****** Table.scalos/SCCA_Table_Attribute ***********************************
44 * SCCA_Table_Attribute -- (V40) ..G (ULONG)
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.
51 * Attr: SCCA_DOSIcon_Size
53 * Type: SCCV_Table_Type_Long
57 *****************************************************************************
60 /****** Table.scalos/SCCA_Table_Name ****************************************
63 * SCCA_Table_Name -- (V40) ..G (char *)
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 *****************************************************************************
72 /****** Table.scalos/SCCA_Table_Count ***************************************
75 * SCCA_Table_Count -- (V40) ..G (ULONG)
78 * Getting this attribute will return the current number of fields in the
81 *****************************************************************************
84 /****** Table.scalos/SCCA_Table_Type ****************************************
87 * SCCA_Table_Type -- (V40) ..G (ULONG)
90 * This attribute gives you information about the datatype of this field.
91 * See SCCM_Table_Add for more information.
93 *****************************************************************************
96 /****** Table.scalos/SCCA_Table_Flags ***************************************
99 * SCCA_Table_Flags -- (V40) ..G (ULONG)
102 * Which flags has the field. Currently there are no flags defined.
104 *****************************************************************************
107 /****** Table.scalos/SCCA_Table_Size ****************************************
110 * SCCA_Table_Size -- (V40) ..G (ULONG)
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
117 *****************************************************************************
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
);
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
));
143 /****** Table.scalos/SCCM_Table_Add *****************************************
149 * ULONG SC_DoMethod(obj,SCCM_Table_Add, ULONG Attr, char *Name, ULONG Type, ULONG Flags, ULONG Size);
152 * This methods addes the information of a new field to the table.
155 * Attr - attribute to identify the field (e.g. SCCA_Icon_Name)
156 * Name - the name of the field, translated to the current language
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.
168 * TRUE if adding was successfully, else FALSE.
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
);
191 case SCCV_Table_Type_String
:
192 tn
->Size
= strlen(&tn
->Name
);
194 case SCCV_Table_Type_Long
:
195 tn
->Size
= sizeof(ULONG
);
197 case SCCV_Table_Type_Double
:
198 tn
->Size
= sizeof(double);
200 case SCCV_Table_Type_Date
:
201 tn
->Size
= 2*sizeof(ULONG
);
203 case SCCV_Table_Type_Raw
:
204 tn
->Size
= msg
->Size
;
208 if (inst
->curnode
== NULL
)
216 /****** Table.scalos/SCCM_Table_Remove **************************************
222 * SC_DoMethod(obj,SCCM_Table_Remove, ULONG Attr);
225 * Remove an entry identified by the ID from the table. If it was the
226 * current entry, the previous entry will be selected.
229 * Attr - attribute to identify the field (e.g. SCCA_Icon_Name)
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
;
255 inst
->curnode
= (struct TableNode
*) inst
->list
.mlh_Head
;
261 inst
->curnode
= NULL
;
268 /****** Table.scalos/SCCM_Table_Entry ***************************************
274 * ULONG SC_DoMethod(obj,SCCM_Table_Entry, ULONG Pos);
277 * This method selectes a current entry. All attributes are relative to this
278 * entry except SCCA_Table_Count. Preselected is the first entry.
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
288 * TRUE if the new entry was successfully selected.
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
)
303 inst
->curnode
= (struct TableNode
*) inst
->curnode
->node
.mln_Succ
;
304 if (inst
->curnode
->node
.mln_Succ
!= 0)
309 if (msg
->Pos
== SCCV_Table_Entry_Previous
)
313 inst
->curnode
= (struct TableNode
*) inst
->curnode
->node
.mln_Pred
;
314 if (inst
->curnode
->node
.mln_Pred
!= 0)
319 if ((msg
->Pos
== SCCV_Table_Entry_First
) && !(IsListEmpty((struct List
*) &inst
->list
)))
321 inst
->curnode
= (struct TableNode
*) inst
->list
.mlh_Head
;
325 if ((msg
->Pos
== SCCV_Table_Entry_Last
) && !(IsListEmpty((struct List
*) &inst
->list
)))
327 inst
->curnode
= (struct TableNode
*) inst
->list
.mlh_Tail
;
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
)
341 if (msg
->opg_AttrID
== SCCA_Table_Attribute
)
343 *(msg
->opg_Storage
) = inst
->curnode
->Attr
;
346 if (msg
->opg_AttrID
== SCCA_Table_Name
)
348 *(msg
->opg_Storage
) = (ULONG
) &inst
->curnode
->Name
;
351 if (msg
->opg_AttrID
== SCCA_Table_Type
)
353 *(msg
->opg_Storage
) = inst
->curnode
->Type
;
356 if (msg
->opg_AttrID
== SCCA_Table_Flags
)
358 *(msg
->opg_Storage
) = inst
->curnode
->Flags
;
361 if (msg
->opg_AttrID
== SCCA_Table_Size
)
363 *(msg
->opg_Storage
) = inst
->curnode
->Size
;
368 if (msg
->opg_AttrID
== SCCA_Table_Count
)
370 *(msg
->opg_Storage
) = inst
->count
;
374 return(SC_DoSuperMethodA(cl
, obj
, (Msg
) msg
));
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
}