home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WDATATRG.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-12-20
|
18KB
|
657 lines
//
// wdatatrg.hpp
//
#ifndef _WDATATRG_HPP_INCLUDED
#define _WDATATRG_HPP_INCLUDED
//-----------------------------------------------------------------------
//
// Interfaces used to implement the binding of objects to data sources.
//
// These interfaces are meant to be embedded in other objects. All
// methods are virtual so that specializations can be created.
//
//-----------------------------------------------------------------------
#ifndef _WDATAOBJ_HPP_INCLUDED
#include "wdataobj.hpp"
#endif
// Define the basic type of a data target (single or multi/table valued).
enum WDataTargetType {
WDTTCell,
WDTTColumn, // Multi-value
WDTTTable, // Multi-value
WDTTLookup,
WDTTNavigator
};
#define WDTTIsMultiValued(T) ( (T)==WDTTTable || (T)==WDTTColumn )
#define WDTTIsTable(T) ( (T)==WDTTTable )
//
// WDataTarget -- An interface exposed by a bound object. This interface
// is what the data source uses to communicate with the
// object. The default implementation is to call events
// on a given event object.
//
class WCMCLASS WDataTarget : public WObject {
private:
WDataTarget( const WDataTarget & );
WDataTarget& operator=( const WDataTarget & );
public:
WDataTarget( WEventGenerator *eventTarget, WDataTargetType type );
~WDataTarget();
/*********************************************************
* Properties
*********************************************************/
// DataChanged
//
// The target sets this value when the data has changed.
// The source uses this to determine if it should invoke
// the DataRequest method.
virtual WBool GetDataChanged() const;
virtual WBool SetDataChanged( WBool changed );
// DataColumns
//
// A string that defines the column or columns that
// the target is interested in.
virtual WString GetDataColumns() const;
virtual WBool SetDataColumns( const WString & cols );
// DataSource
//
// Setting this registers the target with a WDataSource.
virtual WDataSource *GetDataSource() const;
virtual WBool SetDataSource( WDataSource *source );
// DataTouched
//
// The target sets this value when the data has been touched.
// Data changed back to old value is considered touched but
// not changed.
//
virtual WBool GetDataTouched() const;
virtual WBool SetDataTouched( WBool touched );
// Type
//
// What type of target this is.
WDataTargetType GetType() const;
/*********************************************************
* Methods (called by the data source)
*********************************************************/
// DataAvailable
//
// The data source calls this method when it has data
// available for the target (such as when the current
// row changes). The default implementation is to simply
// call the DataAvailable event on the event object.
virtual WBool DataAvailable( WDataAvailableEventData *event );
// DataClose
//
// The data source calls this method when its data set
// is no longer available.
virtual WBool DataClose( WDataCloseEventData *event );
// DataOpen
//
// The data source calls this method when a new set of
// data is available. The target can prepare itself
// and can also make calls back on the source to bind
// columns, etc.
virtual WBool DataOpen( WDataOpenEventData *event );
// DataRequest
//
// The data source calls this method when it wishes
// the target to send changed data back to the source.
// The default implementation is to simply call the
// DataRequest event on the event object.
virtual WBool DataRequest( WDataRequestEventData *event );
/*********************************************************
* Static functions
*********************************************************/
// ColumnsToIndexes
//
// Parse the given columns string and save the indexes in the given
// array, which is assumed to be at least numberToParse elements
// large.
static WBool ColumnsToIndexes( WDataSource * dataSource,
const WString & columns,
WShort * indexes,
WShort numberToParse );
// ColumnsToIndexesEx
//
// Parse given columns and save the indexes in an allocated array.
// Return a pointer to the array and the number of columns parsed.
static WBool ColumnsToIndexesEx( WDataSource * dataSource,
const WString & columns,
WShort ** indexes,
WShort & numberParsed );
protected:
WBool _dataChanged;
WBool _dataTouched;
WDataSource *_source;
WEventGenerator *_eventTarget;
WString _columns;
WDataTargetType _type;
};
//
// WDataTargetCell
//
// A specialization of WDataTarget for single-valued objects.
class WCMCLASS WDataTargetCell : public WDataTarget {
public:
WDataTargetCell( WEventGenerator *eventTarget );
~WDataTargetCell();
/*********************************************************
* Properties
*********************************************************/
// Index
WShort GetIndex() const;
// Nullable
WBool GetNullable() const;
// ReadOnly
WBool GetReadOnly() const;
// SourceValue
WDataValue GetSourceValue() const;
WBool SetSourceValue( const WDataValue & value );
/*********************************************************
* Overrides
*********************************************************/
virtual WBool SetDataColumns( const WString & cols );
protected:
// ParseColumns
WBool ParseColumns( WDataSource *src ) const;
WShort _index;
WBool _tried;
};
//
// WDataTargetBoolCell
//
class WCMCLASS WDataTargetBoolCell : public WDataTargetCell {
public:
WDataTargetBoolCell( WEventGenerator *eventTarget );
~WDataTargetBoolCell();
/*********************************************************
* Properties
*********************************************************/
// DataChecked
WBool GetDataChecked() const;
WBool SetDataChecked( WBool checked );
// DataIndeterminate
//
// TRUE if the current data value matches neither the checked nor
// the unchecked value.
WBool GetDataIndeterminate() const;
// DataValueChecked
WString GetDataValueChecked() const;
WBool SetDataValueChecked( const WString & str );
// DataValueUnchecked
WString GetDataValueUnchecked() const;
WBool SetDataValueUnchecked( const WString & str );
protected:
WString _checked;
WString _unchecked;
};
//
// WDataTargetColumn
//
// A specialization of WDataTarget for multiple-valued objects which display
// one column - ListBox.
// This does not support updates to the database.
//
class WCMCLASS WDataTargetColumn : public WDataTarget {
public:
WDataTargetColumn( WEventGenerator *eventTarget );
~WDataTargetColumn();
/*********************************************************
* Properties
*********************************************************/
// DataTrackRow
WBool GetDataTrackRow() const;
WBool SetDataTrackRow( WBool trackRow );
// SourceValues
WBool GetSourceValues( WDataValue *value, WDataValue *data ) const;
/*********************************************************
* Methods
*********************************************************/
// BindToSource
WBool BindToSource() const;
/*********************************************************
* Overrides
*********************************************************/
WBool SetDataColumns( const WString & cols );
protected:
// ParseColumns
WBool ParseColumns() const;
WBool _trackRow;
WShort _valueIndex;
WShort _dataIndex;
};
//
// WDataTargetTable
//
class WCMCLASS WDataTargetTable : public WDataTarget {
public:
WDataTargetTable( WEventGenerator *eventTarget );
~WDataTargetTable();
/*********************************************************
* Properties
*********************************************************/
// BottomRow
WLong GetBottomRow() const;
WBool SetBottomRow( WLong bottomRow );
// Column
const WDataColumn & GetColumn( WShort index ) const;
// ColumnChanged
WBool GetColumnChanged( WShort index ) const;
WBool SetColumnChanged( WShort index, WBool changed );
// ColumnCount
WShort GetColumnCount() const;
// ColumnName
WString GetColumnName( WShort index ) const;
// DataTrackRow
WBool GetDataTrackRow() const;
WBool SetDataTrackRow( WBool trackRow );
// DataGuardRows
WLong GetDataGuardRows() const;
WBool SetDataGuardRows( WLong guardRows );
// DataKeptRows
WLong GetDataKeptRows() const;
WBool SetDataKeptRows( WLong keptRows );
// SourceValue
WDataValue GetSourceValue( WShort index ) const;
WBool SetSourceValue( WShort index, const WDataValue & value );
// TopRow
WLong GetTopRow() const;
WBool SetTopRow( WLong topRow );
/*********************************************************
* Methods
*********************************************************/
// BindToSource
WBool BindToSource();
// FetchGuardRows
//
// Returns the number of guard rows fetched.
WLong FetchGuardRows( WLong checkRow, WBool restoreCurrentRow );
/*********************************************************
* Overrides
*********************************************************/
virtual WBool SetDataColumns( const WString & cols );
virtual WBool DataAvailable( WDataAvailableEventData *ev );
protected:
/*********************************************************
* Internal
*********************************************************/
// ParseColumns
WBool ParseColumns() const;
// SendGuardRowEvent
WBool SendGuardRowEvent( WDataSource *src, WLong row, WLong count,
WULong action, WBool top ) const;
/*********************************************************
* Data Members
*********************************************************/
WBool _trackRow;
WLong _guardRows;
WLong _keptRows;
WShort * _indexes;
WShort _columnCount;
WLong _topRow;
WLong _bottomRow;
WLong _addedRows;
WLong _deletedRows;
WBool _atTop;
WBool _atBottom;
WBool * _changed;
};
//
// WDataLookup -- A specialization of WDataTarget to support lookup-type
// bound objects.
// Calls the DataLookupItem event on the bound object.
// Does not call the DataOpen/Available/Request/Close events.
//
class WCMCLASS WDataLookup : public WDataTarget {
public:
WDataLookup( WEventGenerator *eventTarget );
~WDataLookup();
/*********************************************************
* Properties
*********************************************************/
// HasDisplayColumn
//
// TRUE if a display column was specified, FALSE if only a value
// column was specified
virtual WBool GetHasDisplayColumn() const;
/*********************************************************
* Methods
*********************************************************/
// FetchLookupItems
//
// Calls the WDataLookupItem event for each data item.
// This can be called directly by the target (the data source will be
// opened and closed automatically) and will otherwise be called
// internally when the specified data source is opened.
virtual WBool FetchLookupItems();
/*********************************************************
* Overrides
*********************************************************/
virtual WBool GetDataChanged() const;
virtual WBool SetDataChanged( WBool );
virtual WBool SetDataColumns( const WString & cols );
virtual WBool DataAvailable( WDataAvailableEventData * );
virtual WBool DataClose( WDataCloseEventData * );
virtual WBool DataOpen( WDataOpenEventData *event );
virtual WBool DataRequest( WDataRequestEventData * );
/*********************************************************
* Internal
*********************************************************/
protected:
// ParseColumns
WBool ParseColumns() const;
// SendLookupItemEvent
WBool SendLookupItemEvent( WDataSource *src, WDataValue *value,
WDataValue *displayValue,
WULong action ) const;
// DoFetch
WBool DoFetch( WDataSource * src, WBool weOpened ) const;
/*********************************************************
* Data Members
*********************************************************/
WShort _valueIndex;
WShort _displayIndex;
WBool _ignoreDataOpen;
};
//
// Events triggered by the data source
//
// These events originate in the data source.
//
//
// Reasons for data available/request
//
enum {
WDataReasonNone,
WDataReasonMove,
WDataReasonUpdate,
WDataReasonDelete,
WDataReasonPrepareForAdd,
WDataReasonAdd,
WDataReasonFill,
WDataReasonCancelUpdate,
WDataReasonClear,
WDataReasonEnable,
WDataReasonDisable,
WDataReasonEnableAlwaysRW,
WDataReasonDisableAlwaysRW
};
//
// Suggested actions for data available/request
//
enum {
WDataActionNone,
WDataActionRefreshRow, // moved to a new row
WDataActionFillBegin, // a fill is beginning
WDataActionFillEnd, // a fill is ending
WDataActionClear, // clear the control
WDataActionRenumber, // multi-value, recount internal row numbers
WDataActionNewState, // sent to navigators
WDataActionEnable,
WDataActionDisable,
WDataActionEnableAlwaysRW, // targets always read/write
WDataActionDisableAlwaysRW
};
//
// WDataOpenEventData
//
struct WDataOpenEventData : public WEventData {
WDataSource *dataSource;
WBool isRequery;
};
//
// WDataAvailableEventData
//
struct WDataAvailableEventData : public WEventData {
WDataSource *dataSource;
WLong currentRow;
WULong reason;
WULong suggestedAction;
};
//
// WDataRequestEventData
//
struct WDataRequestEventData : public WEventData {
WDataSource *dataSource;
WLong currentRow;
WULong reason;
WULong suggestedAction;
};
//
// WDataCloseEventData
//
struct WDataCloseEventData : public WEventData {
WDataSource *dataSource;
WBool isRequery;
};
//
// Events triggered by the data target
//
// These events originate in the data target.
//
//
// GuardRowEvent actions
//
enum {
WDTGRActionNone,
WDTGRActionGroupBegin, // start of guard row group
WDTGRActionGroupEnd, // end of guard row group
WDTGRActionAddRow, // add a row (top or bottom)
};
//
// WDataGuardRowEventData
//
struct WDataGuardRowEventData : public WEventData {
WDataSource * dataSource;
WLong currentRow;
WLong count; // Starts at 0, for current fill
WULong action;
WBool top; // TRUE if action refers to top row
};
//
// LookupItemEvent actions
//
enum {
WDTLIActionNone,
WDTLIActionFillBegin,
WDTLIActionFillEnd,
WDTLIActionAddRow,
};
//
// WDataLookupItemEventData
//
struct WDataLookupItemEventData : public WEventData {
WDataSource * dataSource;
WDataValue * value;
WDataValue * displayValue;
WULong action;
};
#endif