There are various techniques you can use. Guess the preferred method depends on which form you get the data and the kind of operations you need to perform.
Unless other constructs are needed, I like to keep all the data in one place. For example, the data you describe could be gathered in a single list looking like this:
(("FRUIT" ("APPLES" "ORANGES" "PEARS"))
("COLORS" ("RED" "GREEN" "BLUE"))
("CARS" ("VW" "CHEVY" "FORD")))
When using the dcl list functions, one would simply add the CAR items to the popup_list and specify a callback that populates the list_box with whatever of the CAR items is chosen in the popup.
For example:
Code:
// DCL definition
myTest : dialog {
label = "Test list controls";
: list_box {
key = "listbox";
width = 20;
}
: popup_list {
key = "popup";
width = 20;
}
ok_only;
}
;; LISP code
(defun populate_list (tile item lst)
(start_list tile)
(mapcar 'add_list (cadr (nth item lst)))
(end_list)
)
(defun listtest ()
;; set up data
(setq myList '(("FRUIT" ("APPLES" "ORANGES" "PEARS"))
("COLORS" ("RED" "GREEN" "BLUE"))
("CARS" ("VW" "CHEVY" "FORD"))
)
)
(setq dcl_id (load_dialog "testdlg.dcl"))
(cond ((new_dialog "myTest" dcl_id)
;; fill "popup" with CAR item of myList
(start_list "popup")
(mapcar 'add_list (mapcar 'car myList))
(end_list)
;; fill "listbox" initially, according to default value of "popup"
;; (value of "0" unless otherwise specified in the dcl definition)
(populate_list "listbox" 0 myList)
;; define callback to populate "listbox" according to
;; users choice in the "popup" tile
(action_tile "popup" "(populate_list \"listbox\" (atoi $value) myList)")
(start_dialog)
)
)
)
You will probably need to keep track of the chosen item(s) in the list_box. This could for be done by having the populate_list function return the sublist data plus setting the chosen item during callback from the list_box. Here's a simple example where the single choice is saved and returned (for single-selection list_box):
Code:
// DCL definition
myTest : dialog {
label = "Test list controls";
: list_box {
key = "listbox";
width = 20;
}
: popup_list {
key = "popup";
width = 20;
}
: edit_box {
key = "editbox";
width = 20;
}
ok_only;
}
;; LISP code
(defun populate_list (tile item lst cleartiles / sublst)
(start_list tile)
(mapcar 'add_list (setq sublst (cadr (nth item lst))))
(end_list)
;; clear any affected tiles
(foreach n cleartiles
(set_tile n "")
)
;; return sublist
sublst
)
(defun listtest ()
;; set up data
(setq myList '(("FRUIT" ("APPLES" "ORANGES" "PEARS"))
("COLORS" ("RED" "GREEN" "BLUE"))
("CARS" ("VW" "CHEVY" "FORD"))
)
)
(setq dcl_id (load_dialog "testdlg.dcl"))
(cond ((new_dialog "myTest" dcl_id)
(setq item "")
;; fill "popup" with CAR item of myList
(start_list "popup")
(mapcar 'add_list (mapcar 'car myList))
(end_list)
;; fill "listbox" according to default value of "popup" (value
;; of zero unless otherwise specified in the dcl definition)
(setq subitems (populate_list "listbox" 0 myList '("editbox")))
;; define callback to populate "listbox" according to
;; users choice in the "popup" tile. Save list of items
;; in order to extract an item from the list_box tile
;; (also clear any choices in affected tiles when replacing list)
(action_tile "popup" "(setq subitems (populate_list \"listbox\" (atoi $value) myList '(\"editbox\")))")
;; define callback to populate "editbox" and save current
;; choice in order to return it
(action_tile "listbox" "(set_tile \"editbox\" (setq item (nth (atoi $value) subitems)))")
(start_dialog)
;; report choice, if any
(princ (strcat "You chose " (if (/= item "") item "nothing")))
)
)
(princ)
)