home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
MDBS.ZIP
/
LISTBOX.CLS
< prev
next >
Wrap
Text File
|
1990-01-15
|
7KB
|
223 lines
/*
** (C) Copyright 1989, 1990
** Micro Data Base Systems Inc.
** Lafayette, Indiana
*/
/* Class ListBox is the class of all listbox
type control windows. */
subclass(Control,
#ListBox,
nil,
true, true, false);$
/* Answer the window class name string. */
method ListBox::windowClassNameOf(self)
{
return WC_LISTBOX;
}
/* Add a string to a listbox for display. Answer with the index to the
string in the list box, or LIT_ERROR for errors, or LIT_MEMERR for
insufficient memory. */
method ListBox::add(self, itemText)
{
return loWord(sendMessage(self, LM_INSERTITEM, LIT_END, itemText));
}
/* Add a collection of strings to a list box. */
method ListBox::addAll(self, collection)
{
disableUpdate(self);
do(collection, ::( item ){
add(self, item);
});
enableUpdate(self);
return collection;
}
/* Remove the indexed item from the List Box. Answer the count of
remaining items in the List Box. */
method ListBox::remove(self, itemIndex)
{
return asInteger(sendMessage(self, LM_DELETEITEM, itemIndex, 0));
}
/* Answer the count of items contained in the List Box. */
method ListBox::countOf(self)
{
return loWord(sendMessage(self, LM_QUERYITEMCOUNT, 0, 0));
}
/* Answer the index of the currently selected item in the listbox. */
method ListBox::currentSelectionOf(self)
{
return loWord(sendMessage(self, LM_QUERYSELECTION, LIT_FIRST, 0));
}
/* Answer 'true' if the indexed item is selected in the List Box. */
method ListBox::isSelected(self, itemIndex)
{
return currentSelectionOf(self) == itemIndex;
}
/* Answer the text representing the indexed item in the List Box. */
method ListBox::textOf(self, itemIndex)
{
local itemLength, itemText ;
itemLength = textLengthOf(self, itemIndex);
itemText = new(String, itemLength);
sendMessage(self, LM_QUERYITEMTEXT,
makeLong(itemIndex, itemLength + 1), itemText);
return itemText;
}
/* Answer the length of the indexed item in the List Box. */
method ListBox::textLengthOf(self, itemIndex)
{
return loWord(sendMessage(self, LM_QUERYITEMTEXTLENGTH, itemIndex, 0));
}
/* Insert the string at the indexed position in the List Box. Answer the
index that the string was inserted. */
method ListBox::insert(self, itemIndex, itemText)
{
return asInteger(sendMessage(self, LM_INSERTITEM, itemIndex, itemText));
}
/* Remove all the strings from the list box. */
method ListBox::reset(self)
{
return sendMessage(self, LM_DELETEALL, 0, 0) != 0;
}
/* Change the selection to the first string in the List Box with the specified
prefix string. The search begins after the specified index. Answer the
index of the selected string. */
method ListBox::select(self, itemIndex, itemText)
{
return setSelection(self, search(self, itemIndex, itemText));
}
/* Search the list for a string that matches the given string
starting at the string following the given index. Answer
the index of the matching string, or LIT_NONE if no strings
match the given string. */
method ListBox::search(self, itemIndex, itemText)
{
return loWord(sendMessage(self,
LM_SEARCHSTRING,
makeLong(LSS_CASESENSITIVE,
itemIndex),
itemText));
}
/* Select the indexed string in the List Box and scroll it into view if
necessary. Removes the highlight from any previously selected string. */
method ListBox::setSelection(self, itemIndex)
{
if (sendMessage(self, LM_SELECTITEM, itemIndex, true) != 0)
return itemIndex;
return LIT_NONE;
}
/* Answer an array of the items contained in the List Box. */
method ListBox::itemsOf(self)
{
local count, index, vector ;
count = countOf(self);
if (count > 0) {
vector = new(Array, count);
for (index = 0; index < count; index = index + 1) {
vector[index] = textOf(self, index);
}
}
return vector;
}
/* Remove the currently selected item from the List Box. Answer the
count of remaining items in the List Box. */
method ListBox::removeCurrentSelectionOf(self)
{
return remove(self, currentSelectionOf(self));
}
/* Enumerate all the items in the list box through the
one argument block. */
method ListBox::do(self, block)
{
return do(itemsOf(self), ::(item){
valueOf(block, textOf(self, item));
});
}
/* Answer the index of the top item in the list box. */
method ListBox::topIndexOf(self)
{
return asInteger(sendMessage(self, LM_QUERYTOPINDEX, 0, 0));
}
/* Move the indexed item to the top of he list box. */
method ListBox::setTopIndex(self, itemIndex)
{
return sendMessage(self, LM_SETTOPINDEX, itemIndex, 0) != 0;
}
/* Change the text string for the indexed item. */
method ListBox::setItemText(self, itemIndex, itemText)
{
return sendMessage(self, LM_SETITEMTEXT, itemIndex, itemText) != 0;
}
/* Search the list for a string that matches the given string
starting at the string following the given index. Answer
the index of the matching string, or LIT_NONE if no strings
match the given string. */
method ListBox::searchSubString(self, itemIndex, itemText)
{
return loWord(sendMessage(self,
LM_SEARCHSTRING,
makeLong(LSS_CASESENSITIVE | LSS_SUBSTRING,
itemIndex),
itemText));
}
/* Return the default style. */
method ListBoxClass::defaultStyleOf(self)
{
return WS_TABSTOP | WS_CLIPSIBLINGS;
}
/* Return the corrseponding paint class. */
method ListBoxClass::paintClassOf(self)
{
return PaintListBox;
}
/* Return the default shape. */
method ListBoxClass::defaultShapeOf(self)
{
return rect(0,0,100,100);
}
/* Return the default title. */
method ListBoxClass::defaultTitleOf(self)
{
return EmptyString;
}
/* Answer a collection of indexes of the currently selected items
in the listbox. */
method ListBox::allCurrentSelectionsOf(self)
{
local ans, t, lastIndex;
t = new(OrderedCollection, 0);
lastIndex = LIT_FIRST;
while(LIT_NONE != (ans = sendMessage(self,
LM_QUERYSELECTION,
lastIndex, 0))) {
lastIndex = ans;
add(t, ans);
}
return t;
}