I have a tree control with a matching CTreeCtrl object contained in a CPropertyPage-derived class. The tree control has check boxes using the appropriate tree control style flag. The idea is that the tree control represents a directory structure of files and which ones you want to select to put in a zip archive. If you select a folder, then all files in that folder should become selected and vice-versa. Except that I also have some files that must be excluded but I want to show them in the tree anyway for recognition that the file exists and has been excluded by global user options other than unchecking its checkbox in the tree control.
I want to manage these check boxes by doing the following things:
- Some items should have the check box disabled. If I can't directly do an EnableWindow(FALSE) kind of thing on that checkbox or tree item, then I'll have to implement it simply by unchecking the box whenever it becomes checked. But what is the best way?
- If a group becomes checked, then I want to go through and check all of its child items (except for some that don't apply like the ones that must remain unchecked at all times, which is logic that I can handle). Likewise, if the group becomes unchecked, then I want to go through and uncheck all of its child items.
- If an item is unchecked and none of its sibling items are checked, then I want to uncheck its parent item (if it has one) and so on up the tree if applicable
I can handle the tree relationships pretty easily. I'm pretty familiar with that sort of thing. What I'm most curious about is the notification events and architecture I should go for to implement the check boxes...
Is there an event or notification that is ONLY for the check box state change? Or do I have to respond to every click (TVN_CLICK) on the tree control and then check the state of every item in the tree to see if something changed? If so does that mean I need to keep a completely parallel copy of the data represented by the tree in order to do this comparison?
Is it better to handle these events in the CPropertyPage class that contains the tree cotnrol, or should I derive a class from CTreeCtrl and handle it all in there?
Is there a way to do a tri-state checkbox in a tree control? And is there a way to EnableWindow(FALSE) or the equivalent on just one item of a tree control, or just one item's check box? I want to know the best possible way to represent 4 states of items in the tree: unchecked, partly checked (contains some items that are checked and some that are not), fully checked (either doesn't have children or all children are also checked), and uncheckable (disabled). If there's no way to do everything I want, I'd rather suffer the limitations of the built-in checkbox support in the tree control than create my own set of checkbox images and write my own checkbox handling code to duplicate that functionality on my own. That is to say that if I can't get all 4 states that I want using the built-in checkbox support, I'll settle for the default two states (checked and unchecked) and work around that.