Windows Styled Listbox Marking

by Jeff Slarve

Published 1998-04-01    Printer-friendly version

Download the code here

Having seen many programs that have this capability, I have always wanted to be able to add "Windows Styled" marking to my browses. You know what I mean, where you can click on a row, hold down the SHIFT key, then click on another row and have all of the rows in between become marked (or unmarked). Or hold the CONTROL key down and mark multiple records individually, or hold the SHIFT key down and press the down arrow to mark all records below the current row, etc. Windows styled marking.

The CW list control does have a built-in "Mark" attribute, but it doesn't behave like anything that my users or I are used to seeing. You actually have to click on each row to mark it, and a lot of the expected functionality of the listbox is disabled when the "Mark" attribute is used.

Before C4 came around, I thought about writing my own listbox marking class, using colors instead of the "Mark" attribute. Seemed quite feasible to do, but I lost interest because of the thought of having to manage a way to handle the color fields in the queue. You see, for each field in a listbox column, you need four LONG variables to hold the color information for foreground, background, selected foreground, and selected background colors. I had no idea how to write some re-usable code (ala an OOP class) using a queue with an unknown structure.

Then C4 was released. Wow! There are lots of fantastic new features. One of the ones that was particularly intriguing was the PROP:VLBProc property (Virtual Listbox Procedure). Although it can do much more than just handle the listbox coloring, this ability alone made it possible for me to reconsider the writing of a "Windows Styled Marking" class. With this property, you don't have to bother with peppering your queue structure with color fields. The programmer is in control over how the behavior of various aspects of the listbox (such as colors) is handled. If you haven't checked out PROP:VLBProc, I recommend that you do. The sample program in the C4 help file does a great job of demonstrating its use.

The class that I have written is just "Phase One" of what it will probably end up being. Right now, it only works on file loaded queues (not page loaded). The reason for this is that I use a MARK field (byte) that exists within the queue itself. The class can be further modified to use an external marking queue, which would enable the use of this class on a page loaded browse, but it hasn't been done yet.

One thing that is kind of neat, though, is the fact that the ABC File loaded drop list template creates all of the necessary logic to easily make a file loaded listbox. It already creates the MARK field that we need in the queue, so there is no modification necessary. All you have to do is populate the file loaded drop list, and set the DROP property to zero. That's it!

Adding "Windows Styled Marking" to your listbox

To add the marking functionality to your listbox is really quite simple. One of these days, maybe a template will emerge to place the code for you, but for now, there is a little bit of embedded code to be typed.

This code requires C4. The embeds used below are from the ABC template chain, but this class will still work with the CLARION chain.

1. At the GLOBAL level:

In the AFTER GLOBAL INCLUDES embed, put this:

Include('WinMark.inc')

2. At the PROCEDURE level:

  • In the DATA FOR PROCEDURE embed, you need to instantiate the class. For each listbox in the procedure that uses "Windows Styled Marking", you need a different instantiation.
WMC JSWinMark
  • In the Window Manager INIT section (PRIORITY 8030)(after the window is opened, you need to call the INIT() method to initialize the class. This tells the class things that it needs to know so it can do it's job. The parameters are described below. Please look at the sample application.
ClassName.Init(TheWindowLabel,|
               TheListBoxFieldEquateLabel,|
               TheQueue,|
               TheMarkFieldOfTheQueue,|
               TheNumberOfColumnsInTheListBox)
WMC.Init(Window, ?LOC:DummyName, Queue:FileDrop, Queue:FileDrop.Mark, 2)
  • For each column of the listbox, you need to make a call to the SetCol() method. These calls are made directly after the Init() method shown above. The SetCol() method tells the class which variables are assigned to each column, and also the picture token used for formatting.
ClassName.SetCol(TheColumnNumber, TheDataField, ThePicture)
  WMC.SetCol(1,Queue:FileDrop.CON:Name,'@s30')
  WMC.SetCol(2,Queue:FileDrop.CON:Phone,'@s20')
  • In the CONTROL HANDLING embed, you need to call the event handling method. This calls the correct marking routines, depending on the event.
WMC.EventHandler

Although this might seem a little bit complicated at first, it is really easy to add marking to your listboxes once you get the hang of it. Take a look at the sample application. It demonstrates the use of the FileLoaded drop list template and the four embeds necessary to add the marking. It also shows the use of the MarkAll(), UnMarkAll(), and FlipAll() methods.

Hopefully, in the future, I (or someone else) will write a template to enable even easier implementation of this class, and maybe even add the page-loaded browse capability.

Printer-friendly version

 
 

Search

 

Advanced Search
Topical Index

Related Articles

Subscribe to
ClarionMag

One year: $189

(includes all back issues since '99)

Renewals from $139

Two years: $289

Renewals from $239

More Info

Subscribe Now!

ClarionMag Blog

RSS Feeds

Updates via Email

Enter your Email


Powered by FeedBlitz

Quick Links