To offer a nice setup in my private application, I was looking for a smart tree control which can embed some useful GUI controls like edit, font, colour control and more. That's exactly what's provided by Matthew Millers' COptionTree. First of all, thank you for that work Matthew. But nothing is free of charge except death (which costs your life) and so unfortunately, the version posted in September 2002 has two serious weak points. I want to ask the reader to examine the article linked above to see the features of the tree control and its internals. The two major weak points I spoke about are:
- No drag and drop
- Very slow and so not really usable for large lists
The Option Tree provided by this article is very close to the genuine version. It is adapted to developer studio 2003 (.NET 7.1) and comes only with *.sln and *.vcproj. So users of developer studio 6 have to create a new project and add source files. (Once they do so, they will be surprised by some compiler errors caused by changed return types of some callbacks - it should not be a problem to change that.)
Those users having Matthews' Option Tree ported to 7.1 should easily be able to use this version. Some interfaces have just been enlarged with default values.
- Drag & drop within same item level
- Faster drawing (about 20 times - a draw is performed for visible items only; frequently used resources cached) and faster creation of tree
- Buttons to add, delete, restore default values and user definable can be integrated to item label. Once a button is pressed, a message is sent (or posted) to Receivers (
PreTranslateMessage with the button code and pointer of the underlying item.
- Support of
COptionTreeItemEdit can be driven with an input mask (regular expression) to catch every type of input.
COptionTreeItemEdit has a method called
PrepareEditItem similar to
CreateEditItem. The purpose of this method is to bypass the creation of parent
CEdit on building treecontrol. Once the user clicks this item, the edit control is created just in time. This improves the initial build of tree with many edit items - a type which is used most frequently presumably.
BOOL COptionTreeItemEdit::PrepareEditItem(const CString& sWindowText,
const CString& inputmask)
NOTE: Due to performance reasons, it is strongly recommended to call
Tree.LockUpdate() before filling the tree and
Tree.UnlockUpdate() once the work is done. Matthew forgot to point this out.
- Positioning of colour popup on multi screens corrected
- An item changed message is sent only if an item value has really been changed
- No trouble on scrolling by thumbtrack in large lists
The demo demonstrates the original and new features and performance enhancements. A test button can be used to insert 3000 items in one step and a microsecond based clock measures and displays the elapsed time.
Using the Code
The demo project contains all the source and project files. I put the tree files into a
library project, so it can statically be linked to any project. Below this tree project, the demo version is located in directory test. The test project links the tree lib statically. This is casually an example of using the tree lib. Simply load COptionTreeDemoDl.sln located in libtree/test, build and run it. Comments, bug reports and suggestions are welcome.
- After scrolling or expanding,
listbox and multiline edittext sometimes stayed visible
- No item changed notification was sent for date/time control if user edited values with keyboard
COptionTreeItem derivates stayed visible on scrolling
- Column sizing failed if
COptionTree::_bAutoSizeColumn == false
- Focus killed on scrolling for
- More proper drawing of Expand Box
COptionTreeCheckButton derived from
COptionTreeRadioButton derived from
COptionTreeItem (to avoid multiple pointer instances to