Build SDL as linklib.
[AROS-Contrib.git] / ScalosV2 / NodeListClass.c
bloba50d49b2c820cc2261080257ff8dfbbdebb07390
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 <proto/exec.h>
22 #include <string.h>
23 #include <exec/memory.h>
25 #include "Scalos.h"
26 #include "NodeListClass.h"
27 #include "ScalosIntern.h"
29 #include "scalos_protos.h"
30 #include "Debug.h"
31 #include "SubRoutines.h"
33 /****** NodeList.scalos/--background ****************************************
35 * The node list class was made to build an standard interface of lists and
36 * to make the work with list easier.
38 *****************************************************************************
40 // /
42 /****** NodeList.scalos/SCCA_NodeList_StringList ****************************
44 * NAME
45 * SCCA_NodeList_StringList -- (V40) I.. (BOOL)
47 * FUNCTION
48 * To generate a list of strings it's enough to set this attribute to TRUE.
49 * All elements are now strings. They will be copied automatically.
51 *****************************************************************************
53 // /
54 /****** NodeList.scalos/SCCA_NodeList_Argument ******************************
56 * NAME
57 * SCCA_NodeList_Argument -- (V40) ..G (ULONG) (char *)
59 * FUNCTION
60 * This attribute is used to get the argument from the current selected
61 * entry. If the List is a string list a pointer to the string will be
62 * return.
64 *****************************************************************************
66 // /
68 /** Init a NodeList
70 static ULONG NodeList_Init(struct SC_Class *cl, Object *obj, struct SCCP_Init *msg, struct NodeListInst *inst)
72 if (SC_DoSuperMethodA(cl,obj, (Msg) msg))
74 NewList((struct List *) &inst->list);
75 return(TRUE);
77 return(FALSE);
79 // /
81 /** Exit a NodeList
83 static ULONG NodeList_Exit(struct SC_Class *cl, Object *obj, Msg msg, struct NodeListInst *inst)
85 FreeAllNodes(&inst->list);
86 return(SC_DoSuperMethodA(cl,obj, (Msg) msg));
88 // /
90 /****** NodeList.scalos/SCCM_NodeList_Insert ********************************
92 * NAME
93 * SCCM_NodeList_Insert
95 * SYNOPSIS
96 * ULONG SC_DoMethod(obj,SCCM_NodeList_Insert, ULONG arg, ULONG pos);
98 * FUNCTION
99 * This method is used to insert new items to the list. The new entry will
100 * inserted relative to the current selected entry, according to the pos
101 * argument.
103 * INPUTS
104 * arg - the argument for this entry, if this is a string list the arg is
105 * from type (char *)
106 * pos - available values are:
107 * SCCV_NodeList_Insert_Before - insert the new entry before the
108 * current entry or as first entry
109 * if none is selected
110 * SCCV_NodeList_Insert_After - insert the new entry after the
111 * current entry or as last entry if
112 * none is selected
114 * RESULT
115 * TRUE if adding was successfully, else FALSE.
117 * NOTES
119 * SEE ALSO
120 * SCCM_NodeList_Remove
122 *****************************************************************************
124 static ULONG NodeList_Insert(struct SC_Class *cl, Object *obj, struct SCCP_NodeList_Insert *msg, struct NodeListInst *inst)
126 struct NodeListNode *node;
128 if (inst->stringlist)
130 if ((node = (struct NodeListNode *) AllocVec(sizeof(struct MinNode) + strlen((char *) msg->arg) + 1,MEMF_ANY)))
132 strcpy((char *) &node->arg, (char *) msg->arg);
134 else
135 return(FALSE);
137 else
139 if ((node = (struct NodeListNode *) AllocVec(sizeof(struct NodeListNode),MEMF_ANY)))
141 node->arg = msg->arg;
143 else
144 return(FALSE);
148 if (msg->pos == SCCV_NodeList_Insert_Before)
150 if (inst->curnode && (inst->curnode->node.mln_Pred->mln_Pred != NULL))
152 Insert((struct List *) &inst->list, (struct Node *) node,(struct Node *) inst->curnode->node.mln_Pred);
153 return(TRUE);
155 else
157 AddHead((struct List *) &inst->list, (struct Node *) node);
158 return(TRUE);
162 if (msg->pos == SCCV_NodeList_Insert_After)
164 if (inst->curnode)
166 Insert((struct List *) &inst->list, (struct Node *) node, (struct Node *) inst->curnode);
167 return(TRUE);
169 else
171 AddTail((struct List *) &inst->list, (struct Node *) node);
172 return(TRUE);
176 return(FALSE);
178 // /
180 /****** NodeList.scalos/SCCM_NodeList_Remove ********************************
182 * NAME
183 * SCCM_NodeList_Remove
185 * SYNOPSIS
186 * SC_DoMethod(obj,SCCM_NodeList_Remove);
188 * FUNCTION
189 * This method remove the current selected entry from the list.
191 * INPUTS
193 * RESULT
195 * NOTES
197 * SEE ALSO
199 *****************************************************************************
201 static void NodeList_Rem(struct SC_Class *cl, Object *obj, Msg msg, struct NodeListInst *inst)
203 struct NodeListNode *node = inst->curnode;
205 if (node)
207 if (node->node.mln_Succ->mln_Succ == NULL)
208 inst->curnode = NULL;
209 else
210 inst->curnode = (struct NodeListNode *) node->node.mln_Succ;
213 FreeNode(node);
215 // /
217 /****** NodeList.scalos/SCCM_NodeList_Entry *********************************
219 * NAME
220 * SCCM_NodeList_Entry
222 * SYNOPSIS
223 * ULONG SC_DoMethod(obj,SCCM_NodeList_Entry, ULONG Pos);
225 * FUNCTION
226 * This method selectes a current entry. All attributes are relative to
227 * this. Preselected is the first entry.
229 * INPUTS
230 * Pos - one of these values
231 * SCCV_NodeList_Entry_First - select first entry
232 * SCCV_NodeList_Entry_Last - select last entry
233 * SCCV_NodeList_Entry_Next - select next entry
234 * SCCV_NodeList_Entry_Previous - select previous entry
236 * RESULT
237 * TRUE if the new entry was successfully selected.
239 * NOTES
241 * SEE ALSO
243 *****************************************************************************
245 static ULONG NodeList_Entry(struct SC_Class *cl, Object *obj, struct SCCP_NodeList_Entry *msg, struct NodeListInst *inst)
247 if (msg->Pos == SCCV_NodeList_Entry_Next)
249 if (inst->curnode)
251 inst->curnode = (struct NodeListNode *) inst->curnode->node.mln_Succ;
252 if (inst->curnode->node.mln_Succ != 0)
253 return(TRUE);
257 if (msg->Pos == SCCV_NodeList_Entry_Previous)
259 if (inst->curnode)
261 inst->curnode = (struct NodeListNode *) inst->curnode->node.mln_Pred;
262 if (inst->curnode->node.mln_Pred != 0)
263 return(TRUE);
267 if ((msg->Pos == SCCV_NodeList_Entry_First) && !(IsListEmpty((struct List *) &inst->list)))
269 inst->curnode = (struct NodeListNode *) inst->list.mlh_Head;
270 return(TRUE);
273 if ((msg->Pos == SCCV_NodeList_Entry_Last) && !(IsListEmpty((struct List *) &inst->list)))
275 inst->curnode = (struct NodeListNode *) inst->list.mlh_Tail;
276 return(TRUE);
279 return(FALSE);
281 // /
283 /** Get one attribute of all of the getable attributes
285 static ULONG NodeList_Get( struct SC_Class *cl, Object *obj, struct opGet *msg, struct NodeListInst *inst )
287 if (inst->curnode)
289 if (msg->opg_AttrID == SCCA_NodeList_Argument)
291 if (inst->stringlist)
293 *(msg->opg_Storage) = (ULONG) &inst->curnode->arg;
295 else
297 *(msg->opg_Storage) = inst->curnode->arg;
299 return(TRUE);
303 return(SC_DoSuperMethodA(cl, obj, (Msg) msg));
305 // /
307 /*-------------------------- MethodList --------------------------------*/
309 struct SC_MethodData NodeListMethods[] =
311 { SCCM_NodeList_Insert,(ULONG) NodeList_Insert, sizeof(struct SCCP_NodeList_Insert), 0, NULL },
312 { SCCM_NodeList_Remove,(ULONG) NodeList_Rem, sizeof(ULONG), 0, NULL },
313 { SCCM_NodeList_Entry,(ULONG) NodeList_Entry, sizeof(struct SCCP_NodeList_Entry), 0, NULL },
314 { SCCM_Init,(ULONG) NodeList_Init, 0, 0, NULL },
315 { SCCM_Exit,(ULONG) NodeList_Exit, 0, 0, NULL },
316 { OM_GET,(ULONG) NodeList_Get, 0, 0, NULL },
317 { SCMETHOD_DONE, NULL, 0, 0, NULL }