Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

First, some housecleaning. Mike Hanson pointed out that I needed a couple of additional lines of code (5 and 6) in my TakeAccepted handler:

...

Those two lines of code restrict the click operation to just the icon area; without them clicking anywhere in the cell that contains the icon would workchange the icon.  

But there's another problem with the original method - I'd neglected to return a value, yet the Register function docs specifically say you must return one of three values from the function:

Level:Benign

Calls any other handlers and the ACCEPT loop, if available.

Level:Notify

Doesn't call other handlers or the ACCEPT loop. This is like executing CYCLE when processing the event in an ACCEPT loop.

Level:Fatal

Doesn't call other handlers or the ACCEPT loop. This is like executing BREAK when processing the event in an ACCEPT loop.

I always want processing to continue normally, so I'm returning Level:Benign.

I also had a suggestion from Greg for a toggle capability, so I added a ToggleAll method. In an effort to reuse as much code as possible, I had it ToggleAll call the SetAll method with an equate indicating all values should be toggled:

...

There's a call to a new ToggleCurrentCheckbox method, which is marked private because it relies on the correct queue record being in memory, something that's under the class's control:

Code Block
CML_UI_ListCheckbox.ToggleCurrentCheckbox       procedure
    code
    self.ListQIconField = choose(self.ListQIconField=TrueValue,FalseValue,TrueValue)

This method is now called from TakeMouseClick, so the Choose logic exists in just one place. It doesn't really save any lines of code, but it does improve reuse and that's always something worth pursuing as it improves enhances maintainability.

And finally I added something that may only be practically in its current form for simple list boxes (and not ABC browses): the ability to press the space bar to toggle an entry and then advance to the next item. 

I added a Bool property (see Equates.clw - Bool equates to Signed which equates to Short) called ToggleAndAdvanceWithSpaceKey, and in the Initialize method I added this the following code which sets SpaceKey as an Alrt attribute on the list box and then registers an event handler, similar to the way I registered a handler for icon field selection. (Oh, and I updated the handler call by adding the list box FEQ as the last parameter, so the handler is only called for the list box not for all controls.)

Code Block
    if self.ToggleAndAdvanceWithSpaceKey
        self.ListFEQ{PROP:Alrt} = SpaceKey
        register(EVENT:AlertKey,address(self.TakeSpaceKey),address(self),,self.ListFEQ)
    end

...

As long as I don't get distracted with adding any more bells and whistles to the UI component, it's just about time to start thinking about data persistence: how . How can I save and load checkbox data? 

...

The second is the Long field following the field that will be used as a checkbox. So I did have to go into the list box formatter for the browse and add a local variable and configure it as having a checkbox:

In my simple hand coded test I defined the queue myself and added the extra Long field. In the ABC browse, enabling the Icon property caused the templates to generate that extra field.

Within the browse procedure I only had to add two lines of code to get the checkbox effect. 

The first time I ran the app, however, I got an odd effect. No icons showed at all until I clicked on the icon's location:

...

The available icons are determined by the class's Initialize method, using PROP:IconList assignments, and I had avoided using zero as an index value as I'm used to Clarion handling most arrays as 1-based. A value of zero indicated no icon at all. The help says that PROP:IconList is zero based, but when I changed my false equate from 2 to 0, I didn't get any icon display indicates no icon at all. 

I temporarily solved this by added

SELF.Q.Checked_Icon = 2

in the last embed so the unchecked icons display be default. 

But I'd still like to figure out why I can't use a false value of zero. I'll have to do some more experimenting. 

With the modification the browse works as expected, with one proviso.

...

And that sets the stage for persisting data... 

Download the source

CheckboxUI2.zip