Adding Items to a List
In Checkbook, when the user presses "Add", then "OK" in the check edit window,
an item is added to the list. This is done as follows:
- Allocate a new CheckType with malloc()
- Copy the fields in edit_check to the new CheckType
- Insert the new checktype pointer into the check[] array
- Add 1 to num_checks
- Call GSsetsclistnumitems()
Note the last step: anytime the number of items in a list changes,
GSsetsclistnumitems() should be called. Passing "TRUE" as the last parameter
causes the list to be redrawn. Also note that the number of list items is
actually 3*num_checks, since each check has three items in the list.
Deleting Items from a List
When the user presses "Delete", the current item (the one shown in red) is
removed from the list. This is done as follows:
- Deallocate the item with free()
- Move all check pointers after cur_item in check[] "down" one slot
- Subtract 1 from the number of checks
- Set cur_item to NO_ITEM
- Disable the "Edit" and "Delete" buttons, since there no longer is a current
item
- Call GSsetsclistnumitems()
The Complete Source Code
The source code for the completed checkbook
example is available.