home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Buyer 1998 October
/
dpcb1098.iso
/
Business
/
Maxim
/
MAX5
/
data.z
/
OwnComboBox.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-05-15
|
8KB
|
238 lines
//////////////////////////////////////////////////////////////////////////////
// NAME.......: OwnComboBox.CPP
// PURPOSE....: Ownerdrawn combo (bmp and text) box for displaying
// appointment types and assoc. bmps (page 3)
// WRITTEN....: 96/09/27 by Darko Juvan
// DESCRIPTION: owner drawn combo box
//
// This code and information is provided "as is" without warranty of any
// kind, either expressed or implied, including but not limited to the
// implied warranties of merchantability and/or fitness for a particular
// purpose..
//
// Copyright (c) 1998 Multiactive Software Inc. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "OwnComboBox.h"
#include "TransBlt.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CBmpCombo, CComboBox)
//{{AFX_MSG_MAP(CBmpCombo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
#define new DEBUG_NEW
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: LoadBitmap()
//
// DESCRIPTION: load item bmp
//
//////////////////////////////////////////////////////////////////////////////
void CBmpComboData::LoadBitmap()
{
VERIFY (m_bmp.LoadBitmap(m_nBitmapID));
BITMAP bmpStruct;
m_bmp.GetObject (sizeof(BITMAP), &bmpStruct);
m_size.cx = bmpStruct.bmWidth;
m_size.cy = bmpStruct.bmHeight;
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: GetSize()
//
// DESCRIPTION: return size of bmp
//
//////////////////////////////////////////////////////////////////////////////
CSize CBmpComboData::GetSize()
{
ASSERT (m_nBitmapID != 0);
if (m_bmp.m_hObject == NULL)
LoadBitmap();
return m_size;
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: Focus ()
//
// DESCRIPTION: draw focus state
//
//////////////////////////////////////////////////////////////////////////////
void CBmpComboData::Focus (CDC* pDC, const CRect& rcDraw, BOOL bAddFocus)
{
// We can ignore bAddFocus since DrawFocusRect uses XOR
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: DrawItem ()
//
// DESCRIPTION: draw item (bmp and text)
//
//////////////////////////////////////////////////////////////////////////////
void CBmpComboData::DrawItem (CDC* pDC, const CRect& rcDraw, BOOL bSelected)
{
CRect rc(rcDraw);
if (m_bmp.m_hObject == NULL)
LoadBitmap();
CBrush br;
CRect rc2(rcDraw);
rc2.InflateRect(-1,-1);
if (bSelected)
{
br.CreateSolidBrush(GetSysColor (COLOR_HIGHLIGHT));
pDC->FrameRect(&rc2, &br);
}
else
{
br.CreateSolidBrush(GetSysColor (COLOR_WINDOW));
pDC->FrameRect(&rc2, &br);
}
// Draw the bitmap
TransparentBlt(pDC->GetSafeHdc(), (HBITMAP) m_bmp.GetSafeHandle(),
rc.left+5, rc.top+4);
// Shift the rectangle to the left to account for the space
// used by blitting the bitmap
rc.left += m_size.cx + 15;
// Draw the text
pDC->DrawText (m_sText, m_sText.GetLength(), rc,
DT_SINGLELINE | DT_VCENTER | DT_LEFT);
}
/////////////////////////////////////////////////////////////////////////////
// CBmpCombo
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: CBmpCombo()
//
// DESCRIPTION: constructor
//
//////////////////////////////////////////////////////////////////////////////
CBmpCombo::CBmpCombo()
{
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: ~CBmpCombo()
//
// DESCRIPTION: destructor
//
//////////////////////////////////////////////////////////////////////////////
CBmpCombo::~CBmpCombo()
{
}
/////////////////////////////////////////////////////////////////////////////
// CBmpCombo message handlers
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: DrawItem()
//
// DESCRIPTION: draw item in particular state
//
//////////////////////////////////////////////////////////////////////////////
void CBmpCombo::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
CDC* pDC = CDC::FromHandle(lpDIS->hDC);
CBmpComboData *pData = (CBmpComboData *) (lpDIS->itemData);
ASSERT(pData);
CRect rc (lpDIS->rcItem);
if (lpDIS->itemID == LB_ERR)
return;
if (lpDIS->itemID == -1){
/* We have a request to draw an item in the combo box, yet there
* are no combo box items. This is sent when the user TABS into
* an empty combo box or an empty combo box gets the focus. We
* have to indicate (somehow) that this owner-draw combo box has
* the focus. We do it in response to this message. Note that
* lpdis->itemData field would be invalid in this instance so
* we can't allow it to fall into our standard routines.
*/
pData->Focus(pDC, rc, lpDIS->itemState & ODS_FOCUS);
return;
}
if (lpDIS->itemAction & (ODA_DRAWENTIRE | ODA_SELECT) )
pData->DrawItem (pDC, rc, lpDIS->itemState & ODS_SELECTED);
if (lpDIS->itemAction & ODA_FOCUS)
pData->Focus(pDC, rc, lpDIS->itemState & ODS_FOCUS);
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: MeasureItem()
//
// DESCRIPTION: set the measure of item
//
//////////////////////////////////////////////////////////////////////////////
void CBmpCombo::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
CBmpComboData *pData = (CBmpComboData *) (lpMeasureItemStruct->itemData);
// MeasureItem is called only once for fixed sized list boxes, before
// they have any data! So we return 40 pixels just in case, otherwise
// we return the height of each item's bitmap.
lpMeasureItemStruct->itemHeight = 21; // a reasonable default
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: DeleteItem()
//
// DESCRIPTION: delete item
//
//////////////////////////////////////////////////////////////////////////////
void CBmpCombo::DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct)
{
CBmpComboData *pData = (CBmpComboData *) (lpDeleteItemStruct->itemData);
ASSERT(pData);
delete pData;
}
//////////////////////////////////////////////////////////////////////////////
//
// FUNCTION...: AddItem ()
//
// DESCRIPTION: add item
//
//////////////////////////////////////////////////////////////////////////////
int CBmpCombo::AddItem (const char* pszText, UINT nBitmapID)
{
CBmpComboData* pData = new CBmpComboData (pszText, nBitmapID);
int nRet = AddString ((LPCSTR) pData);
if (nRet == LB_ERR)
delete pData;
return nRet;
}