home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ool.zip
/
OOL
/
source
/
xcont.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-04-04
|
21KB
|
640 lines
#include "XContInf.h"
#include "XContObj.h"
#include "XString.h"
#include "XContain.h"
#include "XContCol.h"
#include "XDate.h"
#include "XTime.h"
#include "XBitmap.h"
#include "XIcon.h"
#include "xsize.h"
#include <string.h>
XContainerColumn :: ~XContainerColumn()
{
if (owner && info)
WinSendMsg(owner->GetHandle(), CM_FREEDETAILFIELDINFO, MPARAM(info), MPFROMSHORT(1));
}
/*@ XContainerColumn::XContainerColumn( XContainerControl * ow, void * titleData, SHORT dataColumn, LONG dataSettings, LONG titleSettings, LONG width)
@group constructors/destructors
@remarks If a container should be displayed in detail-mode you must add columns to it. Therfore
you construct one or more XContainerColums, add these with XContainerControll::AddColumn
and finaly call XContainerControll::UpdateColumns.
@parameters <t '°' c=2>
°XContainerControl * theOwner °the owner of the column
°void * theTitle °the title of the column, the parameter can be a
pointer to a string or contain a handle for a
bitmap or icon
°SHORT dataColumn °a zero-based index which points to the data-column
which will be used in XContainerObject::SetColumnData()
°LONG dataSettings °Information about the datas in the column
<t '°' c=2>
°COL_LEFT °field is left-justified
°COL_RIGHT °field is right-justified
°COL_CENTER °field is horizontal centered
°COL_TOP °field is top-justified
°COL_VCENTER °field is vertictal centered
°COL_BOTTOM °field is bottom-justified
°COL_INVISIBLE °the column is invisible
°COL_SEPARATOR °vertical separator
°COL_HORZSEPARATOR °horizontal separator
°COL_BITMAPORICON °the data contain a handle to a bitmap/icon
°COL_STRING °the data contain a string
°COL_DATE °the data contain a date
°COL_TIME °the data contain a time-value
°COL_ULONG °the data contain a ULONG value
°COL_FIREADONLY °datas are readonly
</t>
Can be or-ed;
°LONG titleSettings °Information about the title of the column
<t '°' c=2>
°COL_LEFT °title is left-justified
°COL_RIGHT °title is right-justified
°COL_CENTER °title is horizontal centered
°COL_TOP °title is top-justified
°COL_VCENTER °title is vertictal centered
°COL_BOTTOM °title is bottom-justified
°COL_SEPARATOR °vertical separator
°COL_HORZSEPARATOR °horizontal separator
°COL_BITMAPORICON °the title contain is a bitmap/icon
°COL_FTITLEREADONLY °title is readonly
</t>
Can be or-ed;
°LONG widthOfColumn °the width of the column in window-pixel. If zero
the width of the column is set dynamicaly.<BR>
Default is zero.
</t>
*/
XContainerColumn :: XContainerColumn(XContainerControl * ow, void *titleData, SHORT dataColumn, LONG dataSettings, LONG titleSettings, LONG width)
{
owner = ow;
info = (FIELDINFO *) WinSendMsg(owner->GetHandle(), CM_ALLOCDETAILFIELDINFO, MPFROMSHORT(1), 0);
info->flData = dataSettings;
info->flTitle = titleSettings;
info->offStruct = sizeof(RECORDCORE) + dataColumn * 4 + sizeof(void *);
info->pUserData = this;
col = dataColumn;
if (width > 0)
info->cxWidth = width;
info->pTitleData = titleData;
}
/*@ XContainerColumn::GetColumnNumber()
@group misc
@remarks Returns the number of the column in the container
@returns SHORT number
*/
/*@ XContainerColumn::SetTitle()
@group title
@remarks Set the title
@parameters char * title
*/
/*@ XContainerColumn::SetTitle()
@group title
@remarks Set the title
@parameters XBitmap * bitmap for the title (tilt-attributes must have COL_BITMAPORICON)
*/
/*@ XContainerColumn::SetTitle()
@group title
@remarks Set the title
@parameters XIcon * bitmap for the title (tilt-attributes must have COL_BITMAPORICON)
*/
/*@ XContainerColumn::SetTitleAttributes()
@group title
@remarks Set attributes for the title
@parameters LONG attruibute (see constructor for details)
*/
/*@ XContainerColumn::SetDataAttributes()
@group data
@remarks Set attributes for the datas
@parameters LONG attruibute (see constructor for details)
*/
/*@ XContainerColumn::GetDataAttributes()
@group data
@remarks Query attributes for the datas
@returns LONG attruibute (see constructor for details)
*/
/*@ XContainerColumn::GetTitleAttributes()
@group title
@remarks Query attributes for the title
@returns LONG attruibute (see constructor for details)
*/
/*@ XContainerColumn::GetTitle()
@group title
@remarks Query the title of a column
@parameters XString * buffer buffer to hold the data
*/
void XContainerColumn::GetTitle(XString * buffer)
{
strcpy(buffer->GetBuffer(100), (char *) info->pTitleData);
buffer->ReleaseBuffer();
}
/*@ XContainerColumn::GetNextColumn()
@group misc
@remarks Returns a pointer to the next column of the container
@returns XContainerColumn * column
*/
/*@ XContainerObject::GetIcon( XIcon * icon )
@group icon/bitmap
@remarks Querry the icon of the object
@parameters XIcon * buffer
*/
void XContainerObject::GetIcon(XIcon * icon)
{
if (icon->handle && icon->loaded)
{
WinFreeFileIcon(icon->handle);
icon->loaded = FALSE;
}
icon->handle = core->hptrIcon;
}
/*@ XContainerObject :: GetBitmap( XBitmap * bitmap )
@group icon/bitmap
@remarks Get the bitmap of the object
@parameters XBitmap * buffer
*/
void XContainerObject::GetBitmap(XBitmap * bitmap)
{
if (bitmap->hbm)
GpiDeleteBitmap(bitmap->hbm);
bitmap->hbm = core->hbmBitmap;
}
/*@ XContainerObject::XContainerObject( XContainerControl * owner, SHORT columns, LONG emphasis)
@group constructors/destructors
@remarks Construct a container-item
@parameters XContainerControl * owner<BR>
SHORT columns count of columns in detail-view (default is NULL)
*/
XContainerObject :: XContainerObject(XContainerControl * owner, SHORT columns, LONG emphasis)
{
core = (RECORDCORE *) WinSendMsg(owner->GetHandle(), CM_ALLOCRECORD, MPFROMLONG(sizeof(void *) + columns * sizeof(void *)), MPFROMSHORT(1));
core->flRecordAttr = emphasis;
RECORDCORE *pr = (RECORDCORE *) ((PBYTE) core + sizeof(RECORDCORE));
void *pp = this;
memcpy(pr, &pp, sizeof(void *));
}
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
char * data
*/
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
LONG data
*/
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
XBitmap * data
*/
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
XIcon * data
*/
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
XDate * data
*/
/*@ XContainerObject::SetColumnData()
@group columns
@remarks Set data for an column for detail-view
@parameters SHORT column column-number (zero-based index)
XTime * data
*/
/*@ XContainerObject::SetIcon()
@group icon/bitmap
@remarks Set object-icon
@parameters XIcon * icon
*/
/*@ XContainerObject::SetMiniIcon()
@group icon/bitmap
@remarks Set object mini-icon
@parameters XIcon * icon
*/
/*@ XContainerObject::SetBitmap()
@group icon/bitmap
@remarks Set object-bitmap.
@parameters XBitmap * bitmap
*/
/*@ XContainerObject::SetMiniBitmap()
@group icon/bitmap
@remarks Set the mini-bitmap of the object
@parameters XBitmap * bitmap
*/
/*@ XContainerObject::SetTitle()
@group title
@remarks Set the title of the object. Memory for the title is allocated by the object.
@parameters char * title
*/
/*@ XContainerObject::GetEmphasis()
@group emphasis
@remarks Query emphasis of the object.
@returns LONG emphasis (see XContainer::SetObjectEmphasis() for details)
*/
/*@ XContainerObject :: GetTitle( XString * s)
@group title
@remarks Query the title of the object;
@parameters XString * buffer
*/
void XContainerObject::GetTitle(XString * s)
{
*s = title;
/*
char *b = s->GetBuffer((int) strlen((char *) core->pszIcon) + 1);
strcpy(b, (char *) core->pszIcon);
s->ReleaseBuffer();
*/
}
SHORT EXPENTRY SortRecord(const PRECORDCORE p1, const PRECORDCORE p2, const void *)
{
XContainerObject *obj1, *obj2;
PRECORDCORE pr = (PRECORDCORE) ((PBYTE) p1 + sizeof(RECORDCORE));
memcpy(&obj1, pr, 4);
pr = (PRECORDCORE) ((PBYTE) p2 + sizeof(RECORDCORE));
memcpy(&obj2, pr, 4);
return obj1->Sort(obj2);
}
/*@
@class XContainerInfo
@type overview
@symbol _
@remarks XContainerInfo is a class to set/query general attributes for a XContainerControl.
To make changes to the settings:
<OL COMPACT>
<LI>query the current setting via XContainerControl::GetInfo()
<LI>make the changes in the used instance of XContainerInfo
<LI>call XContainerControl::SetInfo() with the used instance of XContainerInfo
</OL>
*/
/*@ XContainerInfo::XContainerInfo( char * title, LONG style)
@group constructors/destructors
@remarks Constructor of XContainerInfo
@parameters <t '°' c=2>
°char * theTitle °The title of the container.
Default is empty.
°LONG theStyle °style of the container. Valid styles are:
<t '°' c=2>
°CO_TEXT °the container is in text-mode
°CO_NAME °the container is in name-mode
°CO_ICON °the container is in icon-mode
°CO_DETAIL °the container is in detail-mode
°CO_FLOW °arrange objects dynamicaly (text and
name mode only)
°CO_MINI °the container use small icons
°CO_TREE °the container is in tree-mode
°CO_OWNERPAINTBACKGROUND °the owner will draw the background
(see XBackgroundDrawEvent and
XBackgroundDrawHandler)
°CO_TREELINE °draw the tree-line in tree-mode
°CO_DRAWBITMAP °draw icons
°CO_DRAWICON °draw bitmaps
°CO_TITLE °show the container-title
°CO_TITLELEFT °title is left-justified
°CO_TITLERIGHT °title is right-justified
°CO_TITLECENTER °title is centered
°CO_TITLESEPARATOR °the title is drawn with a separator
°CO_TITLEREADONLY °the title cannot been edited by the user
°CO_DETAILTITLES °in detail-mode the titles of XContainerColumn
are shown
</t>
The attributes can be or-ed<BR>
Default is CO_ICON.
</t>
*/
XContainerInfo :: XContainerInfo(char *title, LONG style)
{
memset(&cnrinfo, 0, sizeof(cnrinfo));
changes = 0;
if (title)
SetTitle(title);
if (style)
SetAttributes(style);
}
/*@ XContainerInfo :: EnableSorting( const BOOL enable)
@group misc
@remarks Enables sorting records when they are inserted.
@parameters BOOL sort Set TRUE if the container items should be sorted
when they are inserted. Therefor you must override the
method XContainerObject::Sort.
Default is TRUE.
*/
void XContainerInfo::EnableSorting(const BOOL enable)
{
if (enable)
cnrinfo.pSortRecord = (void *) SortRecord;
else
cnrinfo.pSortRecord = NULL;
changes |= CMA_PSORTRECORD;
}
/*@ XContainerInfo :: SetAttributes( const LONG attribute )
@group set/query attributes
@remarks Specify here how the container should be displayed. After you have set
up the XContainerInfo use XContainerColumn::SetInfo()
@parameters LONG newAttributes attributes how the container should be displayed ( see XContainerInfo() )
*/
void XContainerInfo::SetAttributes(const LONG attribute)
{
cnrinfo.flWindowAttr = attribute;
changes |= CMA_FLWINDOWATTR;
}
/*@ XContainerInfo :: SetTitle( const char * t )
@group set/query container title
@remarks Set the title of the container.
@parameters char * theTitle
*/
void XContainerInfo::SetTitle(const char *t)
{
cnrinfo.pszCnrTitle = (PSZ) t;
changes |= CMA_CNRTITLE;
}
/*@ XContainerInfo :: EnableBackgroundPainting( const BOOL enable)
@group set/query attributes
@remarks Enable/disable background drawing by the application. To draw the background you must install
a XBackgroundDrawHandler
@parameters BOOL enable TRUE=enable, FALSE=disable
*/
void XContainerInfo::EnableBackgroundPainting(const BOOL enable)
{
if (enable)
cnrinfo.flWindowAttr |= CA_OWNERPAINTBACKGROUND;
else
{
if (cnrinfo.flWindowAttr & CA_OWNERPAINTBACKGROUND)
cnrinfo.flWindowAttr ^= CA_OWNERPAINTBACKGROUND;
}
changes |= CMA_FLWINDOWATTR;
}
/*@ XContainerInfo :: IsBackgroundPaintingEnabled()
@group set/query attributes
@remarks Query if owner-draw for the background is enabled or not.
@returns BOOL result
*/
BOOL XContainerInfo::IsBackgroundPaintingEnabled() const
{
return (cnrinfo.flWindowAttr & CA_OWNERPAINTBACKGROUND ? TRUE : FALSE);
}
/*@ XContainerInfo :: SetSplitbarColumn( const XContainerColumn * col)
@group splitbar
@remarks Set a splitbar in a container.
@parameters XContainerColumn * theColumn the XContainerColumn after that the splitbar will be displayed
*/
void XContainerInfo::SetSplitbarColumn(const XContainerColumn * col)
{
cnrinfo.pFieldInfoLast = col->info;
changes |= CMA_PFIELDINFOLAST;
}
/*@ XContainerInfo :: GetAttributes( void )
@group set/query container title
@remarks Query the attributes of the container.
@returns LONG theAttributes the attributes which are set for the container (can be or-ed). See XContainerInfo()
*/
LONG XContainerInfo::GetAttributes(void) const
{
return cnrinfo.flWindowAttr;
}
/*@ XContainerInfo :: GetTitle( XString * s )
@group set/query container title
@remarks Query the containers title
@parameters XString * theTitleBuffer here the title will be stored
*/
void XContainerInfo::GetTitle(XString * s)
{
char *b = s->GetBuffer((int) strlen((char *) cnrinfo.pszCnrTitle) + 1);
strcpy(b, (char *) cnrinfo.pszCnrTitle);
}
/*@ XContainerInfo :: SetSplitbarPos( const LONG pos )
@group splitbar
@remarks Set the position of the splitbar of a container.
@parameters LONG position the position in window-pixels
*/
void XContainerInfo::SetSplitbarPos(const LONG pos)
{
changes |= CMA_XVERTSPLITBAR;
cnrinfo.xVertSplitbar = pos;
}
/*@ XContainerInfo::GetSplitbarPos()
@group splitbar
@remarks Query the position of the splitbar of a container.
@returns LONG the position in window-pixels
*/
/*@ XContainerInfo::SetTreeBitmapSize(const XSize * size)
@group misc
@remarks Set the size of the expanded and collapsed bitmaps/icons in tree-view
@parameters XSize * size
*/
void XContainerInfo::SetTreeBitmapSize(const XSize * size)
{
changes |= CMA_SLTREEBITMAPORICON;
cnrinfo.slTreeBitmapOrIcon.cx = size->GetWidth();
cnrinfo.slTreeBitmapOrIcon.cy = size->GetHeight();
}
/*@ XContainerInfo::SetBitmapSize(const XSize * size)
@group misc
@remarks Set the size of bitmaps/icons
@parameters XSize * size
*/
void XContainerInfo::SetBitmapSize(const XSize * size)
{
changes |= CMA_SLBITMAPORICON;
cnrinfo.slBitmapOrIcon.cx = size->GetWidth();
cnrinfo.slBitmapOrIcon.cy = size->GetHeight();
}
/*@ XContainerInfo :: GetBitmapSize( XSize * )
@group misc
@remarks Query the size of bitmaps/icons
@parameters XSize * size buffer to hold the size
*/
void XContainerInfo::GetBitmapSize( XSize * s)
{
s->SetWidth( cnrinfo.slBitmapOrIcon.cx );
s->SetHeight( cnrinfo.slBitmapOrIcon.cy );
}
/*@ XContainerInfo :: SetExpandedBitmap( const XBitmap * bmp)
@group misc
@remarks Replace the expanded-bitmap.
@parameters XBitmap * the new bitmap
*/
void XContainerInfo::SetExpandedBitmap(const XBitmap * bmp)
{
changes |= CMA_TREEBITMAP;
cnrinfo.hbmExpanded = bmp->GetHandle();
}
/*@ XContainerInfo :: SetExpandedBitmap( const XIcon * ico)
@group misc
@remarks Replace the expanded-icon.
@parameters XIcon * the new icon
*/
void XContainerInfo::SetExpandedBitmap(const XIcon * ico)
{
changes |= CMA_TREEICON;
cnrinfo.hptrExpanded = ico->GetHandle();
}
/*@ XContainerInfo :: SetCollapsedBitmap( const XBitmap * bmp)
@group misc
@remarks Replace the collapsed-bitmap.
@parameters XBitmap * the new bitmap
*/
void XContainerInfo::SetCollapsedBitmap(const XBitmap * bmp)
{
changes |= CMA_TREEBITMAP;
cnrinfo.hbmCollapsed = bmp->GetHandle();
}
/*@ XContainerInfo :: SetCollapsedBitmap( const XIcon * ico)
@group misc
@remarks Replace the collapsed-icon.
@parameters XIcon * the new icon
*/
void XContainerInfo::SetCollapsedBitmap(const XIcon * ico)
{
changes |= CMA_TREEICON;
cnrinfo.hptrCollapsed = ico->GetHandle();
}
/*@ XContainerInfo::GetObjectCount()
@group misc
@remarks Query the count of objects in the container.
@returns LONG objectCount
*/
/*@ XContainerInfo :: SetTreeLineWidth( const SHORT w)
@group misc
@remarks Set the width of the trees line in tree-view.
@parameters SHORT width (in pixels)
*/
void XContainerInfo::SetTreeLineWidth(const SHORT w)
{
changes |= CMA_CXTREELINE;
cnrinfo.cxTreeLine = w;
}
/*@ XContainerInfo :: SetTreeLineSpacing( const SHORT w)
@group misc
@remarks Set the horizontal spacing between two levels in tree-view.
@parameters SHORT width (in pixels)
*/
void XContainerInfo::SetTreeLineSpacing(const SHORT w)
{
changes |= CMA_CXTREEINDENT;
cnrinfo.cxTreeIndent = w;
}
/*@ XContainerInfo :: SetSpacing( const SHORT w)
@group misc
@remarks Set the vertical spacing between two objects.
@parameters SHORT spacing (in pixels)
*/
void XContainerInfo::SetSpacing(const SHORT w)
{
changes |= CMA_LINESPACING;
cnrinfo.cyLineSpacing = w;
}