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>
21 #include <proto/exec.h>
23 #include <exec/memory.h>
26 #include "NodeListClass.h"
27 #include "ScalosIntern.h"
29 #include "scalos_protos.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 *****************************************************************************
42 /****** NodeList.scalos/SCCA_NodeList_StringList ****************************
45 * SCCA_NodeList_StringList -- (V40) I.. (BOOL)
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 *****************************************************************************
54 /****** NodeList.scalos/SCCA_NodeList_Argument ******************************
57 * SCCA_NodeList_Argument -- (V40) ..G (ULONG) (char *)
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
64 *****************************************************************************
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
);
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
));
90 /****** NodeList.scalos/SCCM_NodeList_Insert ********************************
93 * SCCM_NodeList_Insert
96 * ULONG SC_DoMethod(obj,SCCM_NodeList_Insert, ULONG arg, ULONG pos);
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
104 * arg - the argument for this entry, if this is a string list the arg is
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
115 * TRUE if adding was successfully, else FALSE.
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
);
139 if ((node
= (struct NodeListNode
*) AllocVec(sizeof(struct NodeListNode
),MEMF_ANY
)))
141 node
->arg
= msg
->arg
;
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
);
157 AddHead((struct List
*) &inst
->list
, (struct Node
*) node
);
162 if (msg
->pos
== SCCV_NodeList_Insert_After
)
166 Insert((struct List
*) &inst
->list
, (struct Node
*) node
, (struct Node
*) inst
->curnode
);
171 AddTail((struct List
*) &inst
->list
, (struct Node
*) node
);
180 /****** NodeList.scalos/SCCM_NodeList_Remove ********************************
183 * SCCM_NodeList_Remove
186 * SC_DoMethod(obj,SCCM_NodeList_Remove);
189 * This method remove the current selected entry from the list.
199 *****************************************************************************
201 static void NodeList_Rem(struct SC_Class
*cl
, Object
*obj
, Msg msg
, struct NodeListInst
*inst
)
203 struct NodeListNode
*node
= inst
->curnode
;
207 if (node
->node
.mln_Succ
->mln_Succ
== NULL
)
208 inst
->curnode
= NULL
;
210 inst
->curnode
= (struct NodeListNode
*) node
->node
.mln_Succ
;
217 /****** NodeList.scalos/SCCM_NodeList_Entry *********************************
220 * SCCM_NodeList_Entry
223 * ULONG SC_DoMethod(obj,SCCM_NodeList_Entry, ULONG Pos);
226 * This method selectes a current entry. All attributes are relative to
227 * this. Preselected is the first entry.
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
237 * TRUE if the new entry was successfully selected.
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
)
251 inst
->curnode
= (struct NodeListNode
*) inst
->curnode
->node
.mln_Succ
;
252 if (inst
->curnode
->node
.mln_Succ
!= 0)
257 if (msg
->Pos
== SCCV_NodeList_Entry_Previous
)
261 inst
->curnode
= (struct NodeListNode
*) inst
->curnode
->node
.mln_Pred
;
262 if (inst
->curnode
->node
.mln_Pred
!= 0)
267 if ((msg
->Pos
== SCCV_NodeList_Entry_First
) && !(IsListEmpty((struct List
*) &inst
->list
)))
269 inst
->curnode
= (struct NodeListNode
*) inst
->list
.mlh_Head
;
273 if ((msg
->Pos
== SCCV_NodeList_Entry_Last
) && !(IsListEmpty((struct List
*) &inst
->list
)))
275 inst
->curnode
= (struct NodeListNode
*) inst
->list
.mlh_Tail
;
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
)
289 if (msg
->opg_AttrID
== SCCA_NodeList_Argument
)
291 if (inst
->stringlist
)
293 *(msg
->opg_Storage
) = (ULONG
) &inst
->curnode
->arg
;
297 *(msg
->opg_Storage
) = inst
->curnode
->arg
;
303 return(SC_DoSuperMethodA(cl
, obj
, (Msg
) msg
));
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
}