home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
pwrgu2.zip
/
POWERGU2.EXE
/
LISTCTLS
/
DRAWLIST
/
LISTDHDR.CPP
< prev
next >
Wrap
Text File
|
1995-08-23
|
4KB
|
122 lines
//************************************************************
// List Controls - List Box Custom Drawing
//
// Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
// All Rights Reserved.
//************************************************************
// os2.h needing for drawing primitives.
#define INCL_GPILOGCOLORTABLE
#define INCL_WINSYS
#define INCL_WINWINDOWMGR
extern "C" {
#include <os2.h>
}
#include <ilistbox.hpp>
#include <irect.hpp>
#include <ifont.hpp>
#include <icolor.hpp>
#include <istring.hpp>
#include "listdhdr.hpp"
#include "listitem.hpp"
Boolean DrawHandler::highlight ( IListBoxDrawItemEvent& event )
{
// Draw selection.
return this->drawListItem( event, true );
}
Boolean DrawHandler::unhighlight ( IListBoxDrawItemEvent& event )
{
// Draw without selection.
return this->drawListItem( event, false );
}
Boolean DrawHandler::draw ( IListBoxDrawItemEvent& event,
DrawFlag& flag )
{
if ( event.isSelected() )
{
flag = drewSelected;
return this->drawListItem( event, true );
}
else
return this->drawListItem( event, false );
}
// Handle the drawing of the list box items.
Boolean DrawHandler::drawListItem ( IListBoxDrawItemEvent& event,
Boolean selected )
{
IListBox* list = (IListBox*)event.controlWindow();
IRectangle rect = event.itemRect();
RECTL rectl = rect.asRECTL();
// Fill the background.
IColor
background = list->backgroundColor(),
foreground = list->foregroundColor(),
selectedBackground = list->hiliteBackgroundColor(),
selectedForeground = list->hiliteForegroundColor();
GpiCreateLogColorTable( event.itemPresSpaceHandle(),
0, LCOLF_RGB, 0, 0, 0 );
WinFillRect( event.itemPresSpaceHandle(),
&rectl,
selected ? selectedBackground.asRGBLong()
: background.asRGBLong() );
// Convert the item data from the list box item text.
ListItem* data =
(ListItem*)(list->itemText( event.itemId() ).asUnsigned());
// Determine the indent for the class based on the
// number of inherited classes.
if ( data->inheritedClasses() != 0 )
{
ISize indentSize( data->inheritedClasses() * (_indent+1), 0 );
rect.moveBy( indentSize );
}
// Draw a bitmap based on the collapsed flag
// if the class is not a leaf.
if ( data->children() )
{
// Make the bitmap a square the size of an item.
IRectangle rectBitmap( rect.bottomLeft(),
ISize( rect.height(),
rect.height() ));
rectl = rectBitmap.asRECTL();
WinDrawBitmap( event.itemPresSpaceHandle(),
data->collapsed() ? _collapseIcon : _expandIcon,
0,
(PPOINTL)&rectl,
selected ? selectedForeground.asRGBLong()
: foreground.asRGBLong(),
selected ? selectedBackground.asRGBLong()
: background.asRGBLong(),
DBM_STRETCH );
}
// Calculate the rectangle for the text based
// on the current font of the listbox.
IFont font( list );
rect
.moveBy( ISize( rect.height(), 0 ))
.sizeTo( ISize( font.textWidth( data->text() ) + 3,
rect.size().height() ));
rectl = rect.asRECTL();
// Draw the text.
unsigned long style = DT_VCENTER | DT_LEFT;
WinDrawText( event.itemPresSpaceHandle(),
-1,
data->text(),
&rectl,
selected ? selectedForeground.asRGBLong()
: foreground.asRGBLong(),
selected ? selectedBackground.asRGBLong()
: background.asRGBLong(),
style );
return true;
}