Problem: How do you use TOutline with style "otOwnerDraw"?


I encountered a problem using TOutline component.  It wouldn't be a problem if I used the
standard style (otStandard) Outline, but I had to use user-define style (otOwnerDraw) in order to
put an extra check box next to each title captions.  And then, my nightmare began.

The basic problem is how my I can get a list of VISIBLE items EFFECTIVELY.  I figured out that
the proper time to draw (and redraw) title captions and icons inside Outline box was when
OnDrawItem event being triggered.  The OnDrawItem has 4 parameters, and one of them is
index, which indicates the index number of Outline.  Notice that OnDrawItem's index parameter
indicates the order of that item among all VISIBLE items.  By contrast, TOutline's index property
indicates the order of an item among among all items, regardless of visibility.

OnDrawItem's index parameter causes me a big headache because there's no direct way for me
to know what that item really is.  To illustrate the problem, let's suppose we have a outline with the
following content:


By default, only the top level is visible, and OnDrawItem event will be triggered 4 times to draw the
4 top level items (Fruit, Entainment, Communication, Dance).  The value of parameter "index" will
be 0 at the first time OnDrawItem being triggered, 1 at the second time and so on.

Here's question:  how do I know what item I should draw?  I cannot use OnDrawItem's index
parameter with Outline's index property, because they are two different index.  For example, when
OnDrawItem's index value is 1, I should draw text "Entertainment" on the corresponding canvas.
However, Outline.Items[1] is "Apple"; "Enterment" is under Outline.Items[4].  OK, how can my
program knows that "Entertainment" is the item to display?  My appoarch is to go through the
WHOLE item list and check the visible property of each item until I find the right item.  Since the
OnDrawItem's index value is 1, I should use the second visible item on Outline's item list.  So I
use a loop and check each items one by one until I find the second visible item.  Yeah, I know it
sounds kinda dumb, but that's what I can think of.  This appoarch can get slow exponentially as
the item list increase.

What I want is a list of VISIBLE items (contrast to all items), so that I can pick the right item right
away using the value of OnDrawItem's index parameter.

Does anyone one have a better solution?  For those who use TOutline with style otOwnerDraw,
how do you put items in the Outline box?  Is there any source code related to Outline that I can
reference to?

Sorry for the long message, but I hope my dump experience can help you in some sense.