MFC Grid manual

CColumn Class Reference

This class implements a column of the header. More...

#include <Dapfor/GUI/Column.h>

List of all members.


Serialization

virtual void Serialize (CArchive &ar)
 Serializes or deserializes data to/from the archive.
static int GetSerializeVersion ()
 Current serialization version.

Public Types

enum  Alignment { Auto, Left, Right, Center }
 Text alignment. More...
enum  ImageAlignment { ImageLeft, ImageRight, ImageCenter }
 Image alignment. More...
enum  NotificationType {
  NameChanged, WidthChanged, AlignmentChanged, DescriptionChanged,
  CellPaintFormatChanged, ColumnPaintFormatChanged, TextFormatChanged, CellImageChanged,
  ColumnImageChanged, VisibleChanged, EditableChanged, ColumnDelete
}
 Notification type. More...

Public Member Functions

 CColumn (Common::FID fid, const TString &name, int width, Alignment alignment=Auto, bool editable=false, int cellImageId=-1, int columnImageId=-1, const Common::CFormat *textFormat=0, const ICellPaintFormat *cellPaintFormat=0, const IColumnPaintFormat *columnPaintFormat=0, const TString &description=_T(""))
 Constructor.
 CColumn (const CColumn &column)
 Copy constructor.
virtual ~CColumn ()
 Destructor.
CColumnoperator= (const CColumn &)
Get- methods
Common::FID GetFid () const
 Gets field identifier.
const TString & GetName () const
 Gets a column name.
int GetWidth () const
 Gets a column width.
Alignment GetAlignment () const
 Gets text alignment.
bool IsEditable () const
 Indicates whether cells belonging to this column can be editable.
bool IsVisible () const
 Indicates whether the column is visible.
int GetCellImageId () const
 Gets Zero-based index of the image to draw an icon in the cell.
int GetColumnImageId () const
 Gets Zero-based index of the image to draw an icon in the column.
const Common::CFormatGetTextFormat () const
 Gets custom textual format to convert the non-formatted value to the formatted string.
const ICellPaintFormatGetCellPaintFormat () const
 Gets the format to draw the cells belonged to this column.
const IColumnPaintFormatGetColumnPaintFormat () const
 Gets custom format to draw this column.
TString GetDescription () const
 Gets the column description.
ImageAlignment GetImageAlignement () const
 Gets image alignment in cells.
Set- methods
void SetName (const TString &name)
 Sets a new column name.
bool SetWidth (int columnWidth)
 Sets a new column width.
void SetAlignment (Alignment alignment)
 Sets a new text alignment.
void SetEditable (bool bEditable)
 Allows cells to be editable.
void SetVisible (bool bVisible)
 Shows or hides a column.
void SetCellImageId (int imageId)
 Sets a new zero-based index of the image to draw an icon in the cell.
void SetColumnImageId (int imageId)
 Sets a new zero-based index of the image to draw an icon in the column.
const Common::CFormatSetTextFormat (const Common::CFormat *format)
 Sets a new textual format to convert the non-formatted value to the formatted string.
const ICellPaintFormatSetCellPaintFormat (const ICellPaintFormat *cellPaintFormat)
 Sets a new format to draw the cells belonged to this column.
const IColumnPaintFormatSetColumnPaintFormat (const IColumnPaintFormat *columnPaintFormat)
 Sets a new format to draw this column.
void SetDescription (const TString &description)
 Sets a new column description.
void SetImageAlignement (ImageAlignment alignment)
 Sets a new image alignment in cells.
Notifications
void Subscribe (INotify *callBack)
 Subscribes to events.
void Unsubscribe (INotify *callBack)
 Unsubscribes from events.

Protected Member Functions

void Notify (NotificationType type)
 Sends specified notification to all subscribers.

Classes

struct  INotify
 Interface for receiving notifications about column state modification. More...

Detailed Description

This class implements a column of the header.

This class contains the necessary data for displaying columns in the grid. The grid works with C++ objects of almost any class. The only condition is that these classes should inherit from Common::CDataObject. The basic application of the given interface is to give the opportunity of receiving as unformatted so formatted values through data fields identifiers. Unformatted data consists of values of basic types (long, double...) returned by data object functions. These functions can be called through integer identifiers, and then the received unformatted value can be converted into a string and displayed in the corresponding grid cell. Each column contains an identifier, and if it corresponds to a data object field identifier, value of this field is displayed in a grid cell via a system of formats. As mentioned above, data objects usually return an unformatted value that cannot be displayed directly on the screen. The way of displaying depends on text format that converts the value into a string. The type of chosen format is defined by the following: First the format is searched in a grid column. If it is not found, the search occurs in the data fields table (Common::CFieldMap) of the corresponding object and if the format is still not found, the default format returned by Common::CFormat::GetDefaultFormat() function is used. A class object of a column contains such parameters as column width, alignment of a text including an automatically defined one, depending on a field type, indexes of pictures for grid cells and for a header. A column can store graphic formats for an individual portrayal of cells within the bounds of a column, and also in a header.

It's also possible to organize a subscription for receiving notifications from CColumn class object. When internal data changes occur, all subscribers recieve notifications. When a column is inserted to a header, there is an automatic subscription to events that are later transfered in the grid. This way, when class Set-methods of a column is called, the grid updates screen contents in the appropriate way.

It is also important to note, that almost all the functions of CColumn class are thread-safe and can be called from any thread. All events are sent in such a way that during sending such synchronizing objects as critical section or mutex are not occupied.

Version:
2.1.0 Added ability to align images in cells

Member Enumeration Documentation

enum Alignment

Text alignment.

Enumerator:
Auto  alignment depends on field type (long, string, double, etc...)
Left  text is aligned to the left of the cell
Right  text is aligned to the right of the cell
Center  text is aligned in the center of the cell

enum ImageAlignment

Image alignment.

Enumerator:
ImageLeft  image is shown to the left of the cell.
ImageRight  image is shown to the right of the cell.
ImageCenter  image is shown in the center of the cell and over the text.

enum NotificationType

Notification type.

Enumerator:
NameChanged  Name of the column is changed.
WidthChanged  Width of the column is changed.
AlignmentChanged  Alignment type is changed.
DescriptionChanged  Column description is changed.
CellPaintFormatChanged  Cell painting format is changed.
ColumnPaintFormatChanged  Column painting format is changed.
TextFormatChanged  Text format that converts non-formatted data to strings is changed.
CellImageChanged  Image list or index of the icon drawn in the cell is changed.
ColumnImageChanged  Image list or index of the icon drawn in the column is changed.
VisibleChanged  Visibility of the column is changed.
EditableChanged  Editable flag is changed.
ColumnDelete  Is sent in the destructor of CColumn object.


Constructor & Destructor Documentation

CColumn ( Common::FID  fid,
const TString &  name,
int  width,
Alignment  alignment = Auto,
bool  editable = false,
int  cellImageId = -1,
int  columnImageId = -1,
const Common::CFormat textFormat = 0,
const ICellPaintFormat cellPaintFormat = 0,
const IColumnPaintFormat columnPaintFormat = 0,
const TString &  description = _T("") 
)

Constructor.

Parameters:
[in] fid field's identifier.
[in] name column name, which is displayed on the header.
[in] width Column width in pixels.
[in] alignment Text alignment
[in] editable Indicates that the cells belonged to this column can be editable
[in] cellImageId Zero-based index of the image to draw an icon in the cell. -1 means that icon drawing in the cells is not allowed
[in] columnImageId Zero-based index of the image to draw an icon in the column. -1 means that icon drawing in the column is not allowed
[in] textFormat Custom textual format to convert non-formatted value to the formatted string. Can be 0.
[in] cellPaintFormat Custom painting format to draw the cells belonged to this column. Can be 0.
[in] columnPaintFormat Custom format to draw this column. Can be 0.
[in] description Description of the column.

CColumn ( const CColumn column  ) 

Copy constructor.

Parameters:
[in] column The column to be copied.


Member Function Documentation

Common::FID GetFid (  )  const

Gets field identifier.

Returns:
Field's identifier.
Thread safety:
The function is thread safe.

const TString & GetName (  )  const

Gets a column name.

Returns:
Name of the column
Thread safety:
The function is thread safe.

int GetWidth (  )  const

Gets a column width.

Returns:
Column width in pixels
Thread safety:
The function is thread safe.

CColumn::Alignment GetAlignment (  )  const

Gets text alignment.

Returns:
Current text alignment
Thread safety:
The function is thread safe.

bool IsEditable (  )  const

Indicates whether cells belonging to this column can be editable.

Returns:
Value indicating whether the cells belonged to this column can be editable.
Thread safety:
The function is thread safe.

bool IsVisible (  )  const

Indicates whether the column is visible.

Returns:
Value indicating whether the column is visible. True - visible. False - invisible.
Thread safety:
The function is thread safe.

int GetCellImageId (  )  const

Gets Zero-based index of the image to draw an icon in the cell.

Returns:
Zero-based index of the image to draw an icon in the cell. -1 means that icon drawing in the cells is not allowed.
Thread safety:
The function is thread safe.

int GetColumnImageId (  )  const

Gets Zero-based index of the image to draw an icon in the column.

Returns:
Zero-based index of the image to draw an icon in the column. -1 means that icon drawing in the column is not allowed.
Thread safety:
The function is thread safe.

const Common::CFormat * GetTextFormat (  )  const

Gets custom textual format to convert the non-formatted value to the formatted string.

Returns:
Current textual format to convert non-formatted value to the formatted string if it exists. Otherwise - 0.
Thread safety:
The function is thread safe.

const ICellPaintFormat * GetCellPaintFormat (  )  const

Gets the format to draw the cells belonged to this column.

Returns:
Current format to draw the cells related to this column if it exists. Otherwise - 0.
Thread safety:
The function is thread safe.

const IColumnPaintFormat * GetColumnPaintFormat (  )  const

Gets custom format to draw this column.

Returns:
Current format to draw this column if it exists. Otherwise - 0.
Thread safety:
The function is thread safe.

TString GetDescription (  )  const

Gets the column description.

Returns:
description of the column
Thread safety:
The function is thread safe.

CColumn::ImageAlignment GetImageAlignement (  )  const

Gets image alignment in cells.

Returns:
Current image alignment

void SetName ( const TString &  name  ) 

Sets a new column name.

If the value has been really changed, then CColumn::NameChanged notification will be raised.

Parameters:
[in] name New column name
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

bool SetWidth ( int  columnWidth  ) 

Sets a new column width.

The width should be greater than zero. If the value has been really changed, then CColumn::WidthChanged notification will be raised.

Parameters:
[in] columnWidth New column width
Returns:
True if the new width has been successfully set. Otherwise false.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetAlignment ( Alignment  alignment  ) 

Sets a new text alignment.

If the value has been really changed, then CColumn::AlignmentChanged notification will be raised.

Parameters:
[in] alignment New text alignement.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetEditable ( bool  bEditable  ) 

Allows cells to be editable.

If the value has been really changed, then CColumn::EditableChanged notification will be raised.

Parameters:
[in] bEditable True - allows cells to be editable. False - forbids.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetVisible ( bool  bVisible  ) 

Shows or hides a column.

If the value has been really changed, then CColumn::VisibleChanged notification will be raised.

Parameters:
[in] bVisible True - shows the column. False - hides.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetCellImageId ( int  imageId  ) 

Sets a new zero-based index of the image to draw an icon in the cell.

If the value has been really changed, then CColumn::CellImageChanged notification will be raised.

Parameters:
[in] imageId New zero-based index of the image to draw an icon in the cell. -1 means that icon drawing in the cells is not allowed
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetColumnImageId ( int  imageId  ) 

Sets a new zero-based index of the image to draw an icon in the column.

If the value has been really changed, then CColumn::ColumnImageChanged notification will be raised.

Parameters:
[in] imageId New zero-based index of the image to draw an icon in the column. -1 means that icon drawing in the column is not allowed
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

const Common::CFormat * SetTextFormat ( const Common::CFormat format  ) 

Sets a new textual format to convert the non-formatted value to the formatted string.

If the value has been really changed, then CColumn::TextFormatChanged notification will be raised.

Parameters:
[in] format New textual format to convert non-formatted value to the formatted string
Returns:
Previous format.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

const ICellPaintFormat * SetCellPaintFormat ( const ICellPaintFormat cellPaintFormat  ) 

Sets a new format to draw the cells belonged to this column.

If the value has been really changed, then CColumn::CellPaintFormatChanged notification will be raised.

Parameters:
[in] cellPaintFormat New format to draw the cells belonged to this column. Can be 0.
Returns:
Previous format.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

const IColumnPaintFormat * SetColumnPaintFormat ( const IColumnPaintFormat columnPaintFormat  ) 

Sets a new format to draw this column.

If the value has been really changed, then CColumn::ColumnPaintFormatChanged notification will be raised.

Parameters:
[in] columnPaintFormat New format to draw this column. Can be 0.
Returns:
Previous format.
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetDescription ( const TString &  description  ) 

Sets a new column description.

If the value has been really changed, then CColumn::DescriptionChanged notification will be raised.

Parameters:
[in] description New description
Thread safety:
The function is thread safe. All notifications are raised without taking synchronizing objects like critical section or mutex.

void SetImageAlignement ( ImageAlignment  alignment  ) 

Sets a new image alignment in cells.

Parameters:
[in] alignment New image alignment

void Subscribe ( INotify callBack  ) 

Subscribes to events.

Parameters:
[in] callBack Callback interface to be called when an event is raised.
Thread safety:
The function is thread safe.

void Unsubscribe ( INotify callBack  ) 

Unsubscribes from events.

Parameters:
[in] callBack Callback interface to be unsubscribed from events receiving.
Thread safety:
The function is thread safe.

void Serialize ( CArchive &  ar  )  [virtual]

Serializes or deserializes data to/from the archive.

Parameters:
[in] ar Archive to store or restore the columns data.
Thread safety:
The function is not thread safe.

int GetSerializeVersion (  )  [static]

Current serialization version.

Returns:
Current serialization version
Thread safety:
The function is thread safe.

CColumn & operator= ( const CColumn column  ) 

Parameters:
[in] column The column to be copied.
Returns:
Reference to 'this'

void Notify ( NotificationType  type  )  [protected]

Sends specified notification to all subscribers.

Parameters:
[in] type Notification type.
Thread safety:
The function is thread safe. All notifications are sent without taking synchronizing objects like critical section or mutex.