CCustomList Class Reference

#include <customlist.h>

List of all members.

Public Member Functions

 CCustomList ()
virtual ~CCustomList ()
void SetColumnWidth (INT32 colnum, INT32 offset)
BOOL CreateCustomHeader (UINT32 bitmapID)
BOOL GetSwitchState (UINT32 itemIndex, UINT32 switchIndex) const
INT32 GetItemCount () const
BOOL GetItemString (StringBase &itemString, UINT32 itemIndex, UINT32 columnIndex) const
INT32 GetSelectedItemIndex () const
BOOL AddItem (StringBase &itemString, KernelBitmap *pItemImage=0)
BOOL AddItem (StringBase &itemString, UINT32 bitmapEnabledID, UINT32 bitmapDisabledID)
BOOL AddRefsItem (UINT32 idStatusBitmap, StringBase &strItemName, StringBase &strDetails)
BOOL AddColourListItem (StringBase &colourName, INT32 red, INT32 green, INT32 blue, BOOL IsSpotColour=FALSE)
BOOL SetSwitchState (BOOL state, UINT32 itemIndex, UINT32 switchIndex)
void SetSelectedItemIndex (INT32 NewSel)
BOOL SetItemString (StringBase &itemString, UINT32 itemIndex, UINT32 columnIndex)
BOOL SetEnabled (BOOL enabled)
BOOL DeleteAllItems ()

Static Public Member Functions

static BOOL RegisterWindowClass ()
static LRESULT CALLBACK EXPORT CustomWindowProc (HWND hWnd, UINT32 nMsg, WPARAM wParam, LPARAM lParam)
static CCustomListGetGadget (CWindowID parentID, CGadgetID gadgetID)

Static Public Attributes

static const INT32 MAXCOLUMNS = 8
static const INT32 MAXROWS = 100
static const INT32 FONTHEIGHT = 14
static const INT32 ROWHEIGHT = 17
static const INT32 COLOUR_PATCH_WIDTH = 12
static const INT32 COLOUR_PATCH_HEIGHT = 12
static const CString WNDCLASSNAME = "cc_CustomList"

Protected Member Functions

virtual void PostNcDestroy ()
afx_msg INT32 OnCreate (LPCREATESTRUCT lpCreateStruct)
afx_msg void OnVScroll (UINT32 nSBCode, UINT32 nPos, CScrollBar *pScrollBar)
afx_msg void OnSetFocus (CWnd *pOldWnd)
afx_msg BOOL OnMouseWheel (UINT32 nFlags, short zDelta, CPoint pt)

Private Member Functions

void NewScrollableArea ()
CScrollBar * GetVScrollBar () const
CCustomListScrollableAreaGetScrollableArea () const

Private Attributes

CCustomListScrollableAream_ScrollableArea
CScrollBar * m_VScrollBar
INT32 * m_ColumnOffsetsArray
CBitmap m_hHeaderBitmap
CStatic m_hHeader

Friends

class CCustomListScrollableArea
class CCustomListRowWnd


Detailed Description

Definition at line 114 of file customlist.h.


Constructor & Destructor Documentation

CCustomList::CCustomList  ) 
 

Definition at line 154 of file customlist.cpp.

00154                          :
00155     m_VScrollBar(NULL),
00156     m_ScrollableArea(NULL)
00157 {
00158     // create column positioning data
00159     m_ColumnOffsetsArray = new INT32[MAXCOLUMNS];
00160     m_ColumnOffsetsArray[0] = 10; // indent for first offset
00161     for( INT32 i=1; i < MAXCOLUMNS ; i++)
00162         m_ColumnOffsetsArray[i] = -1;
00163 }

CCustomList::~CCustomList  )  [virtual]
 

Definition at line 209 of file customlist.cpp.

00210 {
00211     // delete column offsets array
00212     delete m_ColumnOffsetsArray;
00213     // delete CScrollbar
00214     delete m_VScrollBar ;
00215 }


Member Function Documentation

BOOL CCustomList::AddColourListItem StringBase colourName,
INT32  red,
INT32  green,
INT32  blue,
BOOL  IsSpotColour = FALSE
 

Definition at line 386 of file customlist.cpp.

00387 {
00388     //First create and insert the colour patch associated with the item
00389     //Create a memory DC and 2 bitmaps (enbled/disabled) compatible with the screen 
00390     HDC hDC = ::CreateCompatibleDC(NULL);
00391     ERROR3IF(hDC == NULL, "Couldn't create rendering DC");
00392 
00393     // do not create grey bitmaps for now (to add back in extend array to 2 and comment
00394     // below back in)
00395     HBITMAP bitmaps[1];
00396     bitmaps[0] = CreateScreenCompatibleBitmap(COLOUR_PATCH_WIDTH,   COLOUR_PATCH_HEIGHT);
00397     //bitmaps[1] = CreateScreenCompatibleBitmap(COLOUR_PATCH_WIDTH, COLOUR_PATCH_HEIGHT);
00398     //ERROR2IF(!(bitmaps[0] && bitmaps[1]), FALSE, "GDI Error");
00399 
00400     // And draw the colour patch into the bitmap
00401     for (INT32 i = 0; i <= 1; i++)
00402     {
00403         if (hDC != NULL)
00404         {
00405             HBITMAP OldBitmap = (HBITMAP) ::SelectObject(hDC, bitmaps[i]);
00406 
00407             COLORREF Colour = RGB(red, green, blue);
00408             if (i != 0)
00409             {
00410                 // Convert the colour to a greyscale
00411                 BYTE Grey = BYTE((red * 0.305) + (green * 0.586) + (blue * 0.109));
00412                 Colour = RGB(Grey, Grey, Grey);
00413             }
00414 
00415             HBRUSH Brush = ::CreateSolidBrush(Colour);
00416 
00417             ERROR3IF(Brush == NULL, "Couldn't create brush");
00418 
00419             HPEN BlackPen = (HPEN) ::GetStockObject(BLACK_PEN);
00420 
00421             HBRUSH WhiteBrush   = (HBRUSH) ::GetStockObject(WHITE_BRUSH);
00422             HPEN NullPen        = (HPEN) ::GetStockObject(NULL_PEN);
00423             HPEN OldPen         = (HPEN) ::SelectObject(hDC, NullPen);
00424             HBRUSH OldBrush     = (HBRUSH) ::SelectObject(hDC, WhiteBrush);
00425             if (IsSpotColour)
00426             {
00427                 // Spot colours are drawn as circles - but first, fill the bitmap with white,
00428                 // so that the un-covered corners of the square are a sensible colour.
00429 
00430                 ::Rectangle(hDC, 0, 0, COLOUR_PATCH_WIDTH+1, COLOUR_PATCH_HEIGHT+1);
00431                 ::SelectObject(hDC, BlackPen);
00432                 ::SelectObject(hDC, Brush);
00433                 ::Ellipse(hDC, 0, 0, COLOUR_PATCH_WIDTH, COLOUR_PATCH_HEIGHT);
00434 
00435             }
00436             else
00437             {
00438                 // Process colours are shown as rectangles
00439 
00440                 ::Rectangle(hDC, 0, 0, COLOUR_PATCH_WIDTH+1, COLOUR_PATCH_HEIGHT+1);
00441                 ::SelectObject(hDC, BlackPen);
00442                 ::SelectObject(hDC, Brush);
00443                 ::Rectangle(hDC, 0, 0, COLOUR_PATCH_WIDTH-1, COLOUR_PATCH_HEIGHT-1);
00444             
00445             }
00446 
00447             ::SelectObject(hDC, OldPen);
00448             ::SelectObject(hDC, OldBrush);
00449             ::SelectObject(hDC, OldBitmap);
00450 
00451             ::DeleteObject(Brush);
00452         }
00453     }
00454 
00455     DeleteDC(hDC);
00456 //  this->AddItem(colourName,bitmaps[0],bitmaps[1]);
00457     CCustomListRowWnd* pNewRow = GetScrollableArea()->AddRow();
00458     pNewRow ->AddCheck(0);
00459     pNewRow ->AddCheck(1);
00460     pNewRow ->AddBitmap(2,bitmaps[0],NULL);
00461     pNewRow ->AddText(3,(TCHAR*)colourName);
00462 
00463     return TRUE;
00464 }

BOOL CCustomList::AddItem StringBase itemString,
UINT32  bitmapEnabledID,
UINT32  bitmapDisabledID
 

Definition at line 297 of file customlist.cpp.

00298 {
00299     HBITMAP hItemBitmapEnabled = LoadBitmap (AfxGetResourceHandle(),MAKEINTRESOURCE(bitmapEnabledID));
00300     // the greyed bitmap feature is unimplemented for now
00301     //HBITMAP hItemBitmapDisabled = LoadBitmap (AfxGetResourceHandle(),MAKEINTRESOURCE(bitmapDisabledID));
00302 
00303     // note: RowWnd objects destroy any bitmaps on deletion 
00304     CCustomListRowWnd* pNewRow = GetScrollableArea()->AddRow();
00305     pNewRow ->AddCheck(0);
00306     pNewRow ->AddBitmap(1,hItemBitmapEnabled,NULL);
00307     pNewRow ->AddText(2,(TCHAR *)itemString);
00308 
00309     return TRUE;
00310 }

BOOL CCustomList::AddItem StringBase itemString,
KernelBitmap pItemImage = 0
 

Definition at line 235 of file customlist.cpp.

00236 {
00237     CCustomListRowWnd* pNewRow = GetScrollableArea()->AddRow();
00238     pNewRow ->AddCheck(0);
00239     pNewRow ->AddText(1,(TCHAR *)itemString);
00240     return TRUE;
00241 }

BOOL CCustomList::AddRefsItem UINT32  idStatusBitmap,
StringBase strItemName,
StringBase strDetails
 

Definition at line 244 of file customlist.cpp.

00245 {
00246     CCustomListRowWnd* pNewRow = GetScrollableArea()->AddRow();
00247     if (pNewRow)
00248     {
00249         if (idStatusBitmap!=0)
00250         {
00251             HBITMAP hBitmap = LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(idStatusBitmap));
00252             pNewRow->AddBitmap(0, hBitmap, NULL, 0xFFFFFF); // We know background colour is white for these bitmaps!
00253         }
00254         pNewRow->AddText(1, (TCHAR*)strItemName);
00255         pNewRow->AddText(2, (TCHAR*)strDetails);
00256         return TRUE;
00257     }
00258 
00259     return FALSE;
00260 }

BOOL CCustomList::CreateCustomHeader UINT32  bitmapID  ) 
 

Definition at line 543 of file customlist.cpp.

00544 {
00545     //The listview control has a built-in header, but we will create our own as we want it to display bitmaps
00546     //First get control's coordinates, so that we know where to place the header
00547 
00548     CRect listviewRect;
00549     GetWindowRect(&listviewRect);
00550     POINT listviewOrigin = { listviewRect.left, listviewRect.top };
00551     ::ScreenToClient((HWND) GetOwner()->m_hWnd, &listviewOrigin);
00552 
00553     if(!m_hHeaderBitmap.LoadBitmap(MAKEINTRESOURCE(bitmapID)))
00554         ERROR2RAW("Failed to load header bitmap");
00555 
00556     //Get the height of the bitmap so we can figure out the height of the header
00557     BITMAP bitmap ;
00558     if (!m_hHeaderBitmap.GetBitmap(&bitmap))
00559     {
00560         ERROR2RAW("Failed to get header bitmap data");
00561         return(FALSE);
00562     }
00563     //Change the background colour of the bitmap to the one used by dialog backgrounds, in case the colour scheme used is not the default 
00564     SetBitmapBkgToSystem(m_hHeaderBitmap);
00565     
00566     CRect srect;
00567     srect.left = listviewOrigin.x + m_ColumnOffsetsArray[0] + 1;
00568     srect.right = listviewRect.right  ;
00569     srect.top   = listviewOrigin.y - bitmap.bmHeight;
00570     srect.bottom = listviewOrigin.y;
00571 
00572     m_hHeader.Create(NULL, WS_VISIBLE | SS_BITMAP, srect, this->GetOwner());
00573     m_hHeader.SetBitmap(m_hHeaderBitmap);
00574     return TRUE;
00575 }

LRESULT CALLBACK EXPORT CCustomList::CustomWindowProc HWND  hWnd,
UINT32  nMsg,
WPARAM  wParam,
LPARAM  lParam
[static]
 

Definition at line 168 of file customlist.cpp.

00169 {
00170     // Create CCustomList object and attach it to window
00171     CCustomList* pWnd = new CCustomList;
00172     pWnd->Attach(hWnd);
00173     // Switch over to MFC WndProc
00174     ::SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)AfxWndProc);
00175     // and call it
00176     return ::CallWindowProc(AfxWndProc, hWnd, nMsg, wParam, lParam);
00177 }

BOOL CCustomList::DeleteAllItems  ) 
 

Definition at line 319 of file customlist.cpp.

00320 {
00321     if(m_ScrollableArea)
00322     {
00323         m_ScrollableArea->DestroyWindow();
00324         //delete m_ScrollableArea;
00325     }
00326     NewScrollableArea();
00327     return TRUE;
00328 }

CCustomList * CCustomList::GetGadget CWindowID  parentID,
CGadgetID  gadgetID
[static]
 

Definition at line 226 of file customlist.cpp.

00227 {
00228     HWND listwnd = ::GetDlgItem(hDlg, nIDDlgItem);
00229     CCustomList* pListGadget = (CCustomList*)CWnd::FromHandlePermanent(listwnd);
00230     return pListGadget ;
00231 }

INT32 CCustomList::GetItemCount  )  const
 

Definition at line 278 of file customlist.cpp.

00279 {
00280     return GetScrollableArea()->m_RowCount;
00281 }

BOOL CCustomList::GetItemString StringBase itemString,
UINT32  itemIndex,
UINT32  columnIndex
const
 

Definition at line 263 of file customlist.cpp.

00264 {
00265     CString s = GetScrollableArea()->GetRow(itemIndex)->GetText(columnIndex);
00266     itemString.Empty(); // ensure buffer is empty
00267     itemString+= s;
00268     return TRUE;
00269 }

CCustomListScrollableArea* CCustomList::GetScrollableArea  )  const [inline, private]
 

Definition at line 175 of file customlist.h.

00175 {return m_ScrollableArea;} // get the scrollable area 

INT32 CCustomList::GetSelectedItemIndex  )  const
 

Definition at line 284 of file customlist.cpp.

00285 {
00286     return GetScrollableArea()->m_CurrentSelectedRow;
00287 }

BOOL CCustomList::GetSwitchState UINT32  itemIndex,
UINT32  switchIndex
const
 

Definition at line 272 of file customlist.cpp.

00273 {
00274     return GetScrollableArea()->GetRow(itemIndex)->IsChecked(switchIndex);
00275 }

CScrollBar* CCustomList::GetVScrollBar  )  const [inline, private]
 

Definition at line 174 of file customlist.h.

00174 {return m_VScrollBar;}     // get vertical scrollbar

void CCustomList::NewScrollableArea  )  [private]
 

Definition at line 331 of file customlist.cpp.

00332 {
00333     m_ScrollableArea = new CCustomListScrollableArea(this);
00334     BOOL b = m_ScrollableArea->Create(_T("STATIC"), NULL, WS_CHILD | WS_VISIBLE,CRect(0,0,0,0),this,0,NULL);
00335 }

INT32 CCustomList::OnCreate LPCREATESTRUCT  lpCreateStruct  )  [protected]
 

Definition at line 338 of file customlist.cpp.

00339 {
00340     if (CWnd::OnCreate(lpCreateStruct) == -1)
00341         return -1;
00342 
00343     m_VScrollBar = new CScrollBar();
00344     CRect parentRect;
00345     CRect rect;
00346     GetClientRect(&parentRect);
00347     rect.left = parentRect.right - ::GetSystemMetrics(SM_CXVSCROLL) ;
00348     rect.top = 0;
00349     rect.right = parentRect.right ;
00350     rect.bottom = parentRect.bottom ;
00351     m_VScrollBar->Create(SBS_VERT, rect, this, NULL);
00352     m_VScrollBar->ShowWindow(SW_SHOW);
00353 
00354     NewScrollableArea();
00355 
00356     return 0;
00357 }

BOOL CCustomList::OnMouseWheel UINT32  nFlags,
short  zDelta,
CPoint  pt
[protected]
 

Definition at line 1104 of file customlist.cpp.

01105 {
01106     SCROLLINFO si;
01107     si.cbSize = sizeof(SCROLLINFO);
01108     si.fMask = SIF_TRACKPOS|SIF_PAGE|SIF_RANGE;
01109     GetVScrollBar()->GetScrollInfo(&si);
01110 
01111     INT32 nStep = GetKeyState(CAMKEY(CONTROL))<0 ? si.nPage : ROWHEIGHT ;
01112 
01113     INT32 newPos = GetVScrollBar()->GetScrollPos() - nStep*zDelta/WHEEL_DELTA;
01114 
01115     // force to zero if the first line would appear partially off screen
01116     if(newPos < ROWHEIGHT)
01117         newPos = 0;
01118     // keep the upper limit within bounds
01119     if(newPos > si.nMax)
01120         newPos = si.nMax;
01121 
01122     if (m_ScrollableArea)
01123     {
01124         m_ScrollableArea->HandleScrollMessage(SB_THUMBPOSITION, newPos);
01125     }
01126     return CWnd::OnMouseWheel(nFlags, zDelta, pt);
01127 }

void CCustomList::OnSetFocus CWnd *  pOldWnd  )  [protected]
 

Definition at line 580 of file customlist.cpp.

00581 {
00582     CWnd::OnSetFocus(pOldWnd);
00583     
00584     if(GetScrollableArea()->GetSafeHwnd()!=NULL)
00585     {
00586         if(GetScrollableArea()->m_RowCount > 0 && GetScrollableArea()->m_ListRowsArray)
00587         {
00588             INT32 Sel = GetScrollableArea()->m_CurrentSelectedRow;
00589             if(Sel==-1 || GetScrollableArea()->m_CurrentSelectedRow > GetScrollableArea()->m_RowCount)
00590                 Sel=0;
00591             GetScrollableArea()->SelectRow(Sel);
00592         }
00593     }
00594     
00595 }

void CCustomList::OnVScroll UINT32  nSBCode,
UINT32  nPos,
CScrollBar *  pScrollBar
[protected]
 

Definition at line 360 of file customlist.cpp.

00361 {
00362     m_ScrollableArea->HandleScrollMessage(nSBCode, nPos) ;
00363     CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
00364 }

void CCustomList::PostNcDestroy  )  [protected, virtual]
 

Definition at line 218 of file customlist.cpp.

00219 {
00220     delete this;
00221     CWnd::PostNcDestroy();
00222 }

BOOL CCustomList::RegisterWindowClass  )  [static]
 

Definition at line 182 of file customlist.cpp.

00183 {
00184     HINSTANCE hInst = AfxGetInstanceHandle();
00185     WNDCLASS wc;
00186     if (!(::GetClassInfo(hInst, WNDCLASSNAME, &wc)))
00187     {
00188         // Fill in the values for the class
00189         wc.style         = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS ;
00190         wc.lpfnWndProc   = (WNDPROC) CCustomList::CustomWindowProc;
00191         wc.cbClsExtra       = wc.cbWndExtra = 0;
00192         wc.hInstance     = hInst;
00193         wc.hIcon         = NULL;
00194         wc.hCursor       = LoadCursor (NULL, _R(IDC_ARROW));
00195         wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
00196         wc.lpszMenuName  = (LPSTR) NULL;
00197         wc.lpszClassName = (LPCTSTR) WNDCLASSNAME;
00198 
00199         // try and register the class
00200         if (!RegisterClass (&wc))
00201         {
00202             ASSERT(FALSE);
00203             return FALSE;
00204         }
00205     }
00206     return TRUE;
00207 }

void CCustomList::SetColumnWidth INT32  colnum,
INT32  offset
 

Definition at line 506 of file customlist.cpp.

BOOL CCustomList::SetEnabled BOOL  enabled  ) 
 

Definition at line 497 of file customlist.cpp.

00498 {
00499     GetScrollableArea()->SelectRow(-1); // deselect any selected row 
00500     EnableWindow(enabled);
00501     EnableDescendants(m_hWnd,enabled);
00502     return TRUE;
00503 }

BOOL CCustomList::SetItemString StringBase itemString,
UINT32  itemIndex,
UINT32  columnIndex
 

Definition at line 467 of file customlist.cpp.

00468 {
00469     GetScrollableArea()->GetRow(itemIndex)->SetText(columnIndex,(TCHAR*)  itemString);
00470     return TRUE;
00471 }

void CCustomList::SetSelectedItemIndex INT32  NewSel  ) 
 

Definition at line 313 of file customlist.cpp.

00314 {
00315     GetScrollableArea()->SelectRow(NewSel);
00316 }

BOOL CCustomList::SetSwitchState BOOL  state,
UINT32  itemIndex,
UINT32  switchIndex
 

Definition at line 290 of file customlist.cpp.

00291 {
00292     GetScrollableArea()->GetRow(itemIndex)->SetChecked(switchIndex,state);
00293     return TRUE;
00294 }


Friends And Related Function Documentation

friend class CCustomListRowWnd [friend]
 

Definition at line 117 of file customlist.h.

friend class CCustomListScrollableArea [friend]
 

Definition at line 116 of file customlist.h.


Member Data Documentation

const INT32 CCustomList::COLOUR_PATCH_HEIGHT = 12 [static]
 

Definition at line 125 of file customlist.h.

const INT32 CCustomList::COLOUR_PATCH_WIDTH = 12 [static]
 

Definition at line 124 of file customlist.h.

const INT32 CCustomList::FONTHEIGHT = 14 [static]
 

Definition at line 122 of file customlist.h.

INT32* CCustomList::m_ColumnOffsetsArray [private]
 

Definition at line 179 of file customlist.h.

CStatic CCustomList::m_hHeader [private]
 

Definition at line 181 of file customlist.h.

CBitmap CCustomList::m_hHeaderBitmap [private]
 

Definition at line 180 of file customlist.h.

CCustomListScrollableArea* CCustomList::m_ScrollableArea [private]
 

Definition at line 177 of file customlist.h.

CScrollBar* CCustomList::m_VScrollBar [private]
 

Definition at line 178 of file customlist.h.

const INT32 CCustomList::MAXCOLUMNS = 8 [static]
 

Definition at line 120 of file customlist.h.

const INT32 CCustomList::MAXROWS = 100 [static]
 

Definition at line 121 of file customlist.h.

const INT32 CCustomList::ROWHEIGHT = 17 [static]
 

Definition at line 123 of file customlist.h.

const CString CCustomList::WNDCLASSNAME = "cc_CustomList" [static]
 

Definition at line 126 of file customlist.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:13 2007 for Camelot by  doxygen 1.4.4