Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Enhancements of Matthew R. Millers COptionTree

0.00/5 (No votes)
26 Apr 2006 2  
This article demonstrates an enhanced version of Matthew R. Millers Option Tree
Sample Image - screenshot1.jpg

Introduction

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.

Enhancements/Bug Fixes

  • 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 (pNotify of COptionTree) PreTranslateMessage with the button code and pointer of the underlying item.
  • Support of ListBoxes
  • Class COptionTreeItemEdit can be driven with an input mask (regular expression) to catch every type of input.
  • Class 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,
                                              DWORD dwOptions,
                                              DWORD dwAddStyle,
                                              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

Demo Description

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.

Bug Fixes

  • 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
  • Some COptionTreeItem derivates stayed visible on scrolling
  • Column sizing failed if COptionTree::_bAutoSizeColumn == false
  • COptionTree::EnsureVisible failed

New Features

  • Option 'Autosize column' added
  • User definable height for listbox
  • User definable offset for attribute text (call COptionTree::SetAttributeOffset)
  • Item Search by Label (/Attribute-Text: not implemented for all COptionTreeItem derivates)

    COptionTreeItem * COptionTree::FindItem(const CString& Text,
                                            const DWORD flag=OT_FI_LABEL,
                                            COptionTreeItem * pOffset=NULL)

Changes

  • Focus killed on scrolling for COptionTreeItemIPAddress, COptionTreeItemEdit, COptionTreeItemEditButton, COptionTreeItemDate
  • More proper drawing of Expand Box
  • COptionTreeCheckButton derived from COptionTreeItem
  • COptionTreeRadioButton derived from COptionTreeItem (to avoid multiple pointer instances to COptionTree)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here