home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WLISTBOX.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-05
|
18KB
|
509 lines
/*************************************************************************
*
* WListBox -- Wrapper for the Windows 95 Listbox control.
*
* Events:
*
* BeginOwnerDraw -- Called before the first DrawItem.
*
* DataAvailable --
*
* DataClose --
*
* DataOpen --
*
* DataRequest --
*
* DoubleClick -- When a listbox item has been double-clicked
*
* DrawItem -- Called for owner-draw.
*
* EndOwnerDraw -- Called after last DrawItem.
*
* Select -- When a listbox item has been selected
*
*************************************************************************/
#ifndef _WLISTBOX_HPP_INCLUDED
#define _WLISTBOX_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WCONTROL_HPP_INCLUDED
# include "wcontrol.hpp"
#endif
#ifndef _WSTRING_HPP_INCLUDED
# include "wstring.hpp"
#endif
#ifndef _WDATATRG_HPP_INCLUDED
# include "wdatatrg.hpp"
#endif
#ifndef _WLOCALE_HPP_INCLUDED
# include "wlocale.hpp"
#endif
#ifndef _WDRAWITM_HPP_INCLUDED
# include "wdrawitm.hpp"
#endif
class WDataSource;
//
// ListBox styles
//
#define WLBSDefault ((WStyle)0x50A00141L) // WS_VISIBLE|LBS_HASSTRINGS|LBS_NOTIFY|WS_BORDER|WS_VSCROLL|WS_CHILD|LBS_NOINTEGRALHEIGHT
#define WLBSSingleSel ((WStyle)0x00000000L) // WS_OVERLAPPED
#define WLBSNotify ((WStyle)0x00000001L) // LBS_NOTIFY
#define WLBSSort ((WStyle)0x00000002L) // LBS_SORT
#define WLBSNoRedraw ((WStyle)0x00000004L) // LBS_NOREDRAW
#define WLBSMultipleSel ((WStyle)0x00000008L) // LBS_MULTIPLESEL
#define WLBSOwnerDrawFixed ((WStyle)0x00000010L) // LBS_OWNERDRAWFIXED
#define WLBSOwnerDrawVariable ((WStyle)0x00000020L) // LBS_OWNERDRAWVARIABLE
#define WLBSHasStrings ((WStyle)0x00000040L) // LBS_HASSTRINGS
#define WLBSUseTabStops ((WStyle)0x00000080L) // LBS_USETABSTOPS
#define WLBSNoIntegralHeight ((WStyle)0x00000100L) // LBS_NOINTEGRALHEIGHT
#define WLBSMultiColumn ((WStyle)0x00000200L) // LBS_MULTICOLUMN
#define WLBSWantKeyboardInput ((WStyle)0x00000400L) // LBS_WANTKEYBOARDINPUT
#define WLBSExtendedSel ((WStyle)0x00000800L) // LBS_EXTENDEDSEL
#define WLBSDisableNoScroll ((WStyle)0x00001000L) // LBS_DISABLENOSCROLL
#define WLBSNoData ((WStyle)0x00002000L) // LBS_NODATA
#define WLBSNoSel ((WStyle)0x00004000L) // LBS_NOSEL
#define WLBSSorted WLBSSort
#define WLBSMultipleSelection WLBSMultipleSel
#define WLBSNoSelection WLBSNoSel
class WCMCLASS WListBox : public WControl {
WDeclareSubclass( WListBox, WControl );
public:
/**************************************************************
* Constructors and destructors
**************************************************************/
WListBox();
~WListBox();
/**************************************************************
* Properties
**************************************************************/
// ColumnWidth
//
// Use to set the width in pixels of the columns in a
// multi-column listbox. A value of -1 means no width
// has been set.
WInt GetColumnWidth() const;
WBool SetColumnWidth( WInt width );
// Count
//
// Returns the number of items in the list box, or negative
// if an error occurs.
WInt GetCount() const;
// DataBindAsLookup
//
// DataTarget property
WBool GetDataBindAsLookup() const;
WBool SetDataBindAsLookup( WBool bindAsLookup );
// DataColumns
//
// DataTarget property
WString GetDataColumns() const;
WBool SetDataColumns( const WString & cols );
// DataLookupColumns
//
// DataTarget property
WString GetDataLookupColumns() const;
WBool SetDataLookupColumns( const WString & cols );
// DataLookupSource
//
// DataTarget property
WDataSource *GetDataLookupSource() const;
WBool SetDataLookupSource( WDataSource *source );
// DataSource
//
// DataTarget property
WDataSource *GetDataSource() const;
WBool SetDataSource( WDataSource *source );
// DataTrackRow
//
// DataTarget method
WBool GetDataTrackRow() const;
WBool SetDataTrackRow( WBool trackRow );
// HorizontalExtent
//
// The width, in pixels, by which a listbox can be scrolled
// horizontally (the scrollable width). If the value is set
// to -1, the horizontal extent will be calculated automatically
// on a one-time only basis based on the strings currently in
// the listbox.
WBool SetHorizontalExtent( WInt horizontalExtent );
WInt GetHorizontalExtent() const;
// FDXDataSource
WBool SetFDXDataSource( WStringArray * fdxDataSource );
WBool SetFDXDataSource( WIntArray * _fdxDataSourceIntArray );
WBool SetFDXDataSource( WInt * fdxDataSource );
WBool SetFDXDataSource( WBool * fdxDataSource );
// Selected
//
// For single-select listboxes, GetSelected() returns the index
// of the currently-selected item, or -1 if no selection,
// and SetSelected sets the current selection. SetSelected
// of -1 clears the selection.
//
// For multi-select listboxes, use GetSelected( WInt ) to
// determine if a specific index is selected. Use
// SetSelected to select or deselect an item, or use index
// -1 to select or deselect all items.
// Note: The multi-select versions of GetSelected and
// SetSelected are Item Properties, not Properties.
WInt GetSelected() const;
WBool SetSelected( WInt index );
// SelectedCount
//
// Returns the number of items selected in a multi-selection
// listbox, or -1 if an error occurs.
WInt GetSelectedCount() const;
// SelectedList
//
// An array of indices of selected items. If no items
// are selected, the array size is zero.
WIntArray GetSelectedList() const;
// Sort
//
// Get/set the sort mode.
WBool GetSort() const;
WBool SetSort( WBool sort );
// Locale (for type of sort)
//
//
WBool SetLocale( WLocaleID locID );
WLocaleID GetLocale();
// TopIndex
//
// Get/set the top index.
WInt GetTopIndex() const;
WBool SetTopIndex( WInt index );
/**************************************************************
* Methods
**************************************************************/
// Add
//
// Adds an item. If itemNumber is set to >= 0, item is
// inserted at the given location. If the list is sorted
// and itemNumber is set to -1, inserts in correct spot;
// otherwise adds to the end. Can also set optional
// per-item data.
// Returns the index of the item, or a negative value in
// case of error.
WInt Add( const WChar * string, WInt itemNumber=-1,
void * itemUserData=NULL, WBool addInSortedOrder=TRUE );
// DataAddLookupItem
//
// Allows the user to manually fill the list with lookup items.
// This is an alternative method to setting the DataLookupSource
// and DataLookupColumns properties.
WInt DataAddLookupItem( const WDataValue & value,
const WChar * string = NULL,
WInt itemNumber=-1, void * itemUserData=NULL,
WBool addInSortedOrder=TRUE );
// DataFetchLookupItems
//
// Forces the lookup items to be fetched from the database
// (according to the DataLookupSource and DataLookupColumns
// properties).
// This is normally done when either data source is opened...
WBool DataFetchLookupItems();
// Delete
//
// Deletes the specified item. If an item's data is set,
// invokes the WDeleteItemEvent event first. Returns the count
// of items remaining in the list, or negative if error occurs.
WInt Delete( WInt itemNumber );
// DeleteAll
WBool DeleteAll();
// Find
//
// Finds the first string that matches a given prefix. The
// search starts immediately AFTER the given index (use -1
// to search from the beginning) and wraps when the bottom
// is reached. The search is not case-sensitive. If exact
// is specified, the string must match exactly, otherwise
// a prefix match is done. Returns the index of the match
// or negative on error.
WInt Find( const WChar * match, WInt startAfter=-1,
WBool exact=FALSE ) const;
// MakeDraggable
WBool MakeDraggable();
// Reset
//
// Reset (clear) the list box.
void Reset();
// Retrieve
//
// Return the index of the listbox item closest to a given point
WLong Retrieve( const WPoint & pt ) const;
// Select
//
// Find and select an item. Searches for the first item whose
// prefix matches (case-insensitive) the given string. Returns
// the index of the new selected item, or negative if an error
// occurs. If startAfter is -1, search starts at first item.
WInt Select( const WChar * match, WInt startAfter=-1 );
/**************************************************************
* Item Properties
**************************************************************/
// DataLookupValue
//
// Get the lookup value associated with the given list item.
WDataValue GetDataLookupValue( WInt itemNumber ) const;
// Height
//
// Get/set height of listbox items. For get, negative value
// is returned to indicate error.
// NOTE: Low item heights lead to particularily ugly results.
WInt GetHeight( WInt itemNumber ) const;
WBool SetHeight( WInt itemNumber, WInt height );
// Text
//
// Get the text of a specific item in the list. First two
// versions return a WString, which is set to a null string
// if an error occurs. Last version copies it into a buffer
// and returns the length, or a negative value.
WString GetText( WInt itemNumber ) const;
// Selected
//
// c.f. Selected Property
WInt GetSelected( WInt whichItem ) const;
WBool SetSelected( WInt index, WBool selected );
// TextLength
//
// Get the length of the text of an item in the list (without
// the null character). A negative value is returned in case
// of error.
WInt GetTextLength( WInt itemNumber ) const;
// UserData
//
// Get/set per-item data. When getting data, a value of
// ((void *)-1) for the itemUserData indicates an error.
virtual WBool SetUserData( WInt itemNumber, void * itemUserData );
virtual void * GetUserData( WInt itemNumber ) const;
/**************************************************************
* Overrides
**************************************************************/
virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
virtual size_t GetTextLength() const;
virtual WBool WantsDragMessage( WULong whichButton ) const;
virtual WBool FillDragEventData( WDragEventData & event ) const;
virtual WBool ProcessCommand( WUInt id, WNotify code,
WNotifyInfo info, WLong & returns );
virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
void * data=NULL );
virtual WBool ProcessMessage( const WMessage & msg,
WLong & returns );
virtual WBool SetText( const WString & str );
virtual WString GetText() const;
virtual WBool SetUserData( void * userData );
virtual void * GetUserData() const;
virtual WBool SetHeight( const WInt & height, WBool update=TRUE );
virtual WInt GetHeight() const;
virtual WStyle GetDefaultStyle() const;
virtual WStyle GetDefaultExtendedStyle() const;
virtual const WChar * InitializeClass();
virtual WBool FDXIn();
virtual WBool FDXOut();
/**************************************************************
* Event Handlers
**************************************************************/
// Event handlers for the DataTarget
WBool DataOpenHandler( WListBox *, WDataOpenEventData *ev );
WBool DataCloseHandler( WListBox *, WDataCloseEventData *ev );
WBool DataAvailableHandler( WListBox *, WDataAvailableEventData *ev );
WBool DataRequestHandler( WListBox *, WDataRequestEventData *ev );
WBool DeleteItemHandler( WListBox *, WDeleteItemEventData *ev );
WBool DestroyEventHandler( WListBox *, WEventData * );
WBool DataLookupItemHandler( WListBox *, WDataLookupItemEventData *ev );
WBool DragEnterHandler( WListBox *, WDragEventData * ev );
WBool DragOverHandler( WListBox *, WDragEventData * ev );
WBool DragDropHandler( WListBox *, WDragEventData * ev );
WBool DragEndHandler( WListBox *, WDragEventData * ev );
/**************************************************************
* Internal
**************************************************************/
protected:
WBool AllocDTColumn();
WBool AllocLookup();
void * GetRealUserData( WInt itemNumber ) const;
WBool SetRealUserData( WInt itemNumber, void * itemUserData );
WBool IndirectUserData( WBool indirect );
WBool DoLookupDataAvailable( WDataAvailableEventData *ev );
WBool DoColumnDataAvailable( WDataAvailableEventData *ev );
void RenumberDataRows();
WBool HandleRefreshRow( WULong reason, WLong row, WInt count );
WBool AddDataRow( WLong row, WInt itemNumber = -1 );
WInt FindDataRow( WLong row, WInt itemCount = -1 );
void RemoveLookupItems();
/**************************************************************
* Data members
**************************************************************/
protected:
WInt _columnWidth;
WDataTargetColumn * _dataTargetColumn;
WBool _indirectUserData;
WBool _dataFilling;
WBool _wasPainting;
WDataLookup * _dataLookup;
WDataTargetCell * _dataTargetCell;
WBool _bindAsLookup;
WBool _ignoreDataAvailableMove;
WInt _initialValue;
WBool _wasEnabled;
WInt _addRow;
WStringArray * _fdxDataSourceStringArray;
WIntArray * _fdxDataSourceIntArray;
WInt * _fdxDataSourceInt;
WBool * _fdxDataSourceBool;
WInt _itemToMove;
WBool _draggable;
// Indirections for databound controls...
typedef WBool WCMDEF (WListBox::*CmdFuncPtr)( WUInt, WNotify,
WNotifyInfo, WLong & );
static CmdFuncPtr DBProcessCommandPtr;
WBool DBProcessCommand( WUInt id, WNotify code, WNotifyInfo info,
WLong & returns );
typedef WBool WCMDEF (WListBox::*SetIUDPtr)( WInt, void * );
static SetIUDPtr SetIndirectUserDataPtr;
WBool SetIndirectUserData( WInt itemNumber, void * itemUserData );
typedef void * WCMDEF (WListBox::*GetIUDPtr)( WInt );
static GetIUDPtr GetIndirectUserDataPtr;
void *GetIndirectUserData( WInt itemNumber );
typedef void WCMDEF (WListBox::*AddIndirectPtr)( WInt, const WChar* );
static AddIndirectPtr DBAddIndirectPtr;
void DBAddIndirect( WInt index, const WChar *text );
};
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WLISTBOX_HPP_INCLUDED