#include <bitmapdropdown.h>
Inheritance diagram for CBitmapDropDown:
Public Member Functions | |
CBitmapDropDown () | |
virtual | ~CBitmapDropDown () |
virtual BOOL | Init (CWindowID Window, CGadgetID Gadget) |
void | AddItem (UINT32 uiBitmapResID, String_256 strText) |
void | AddDivider () |
void | SetSelectedIndex (INT32 iSelectedIndex) |
Sets the index of the selected item in the list. Take care never to set a divider as the selected item (it'll work, but it's a silly item to have selected!). | |
void | SetUnselectedIntem (UINT32 uiBitmapID, String_256 strText) |
void | DeleteItem (INT32 index) |
Protected Member Functions | |
void * | GetItemData (INT32 iItemIndex) |
virtual BOOL | HasIcon (void *pvItemData) |
virtual BOOL | HasText (void *pvItemData) |
virtual wxString | GetText (void *pvItemData, INT32 iItem) |
virtual wxSize | HandleDrawItemInternal (wxDC &dc, const wxRect &Rect, INT32 item, INT32 flags, BOOL Draw) |
virtual wxSize | DrawIcon (wxDC &dc, const wxRect &Rect, INT32 item, INT32 flags, BOOL Draw) |
Protected Attributes | |
std::vector< CBDDItemInfo > | m_vecItems |
CBDDItemInfo | m_oUnselectedItemInfo |
Friends | |
class | DialogManager |
Definition at line 185 of file bitmapdropdown.h.
|
Definition at line 268 of file bitmapdropdown.cpp.
|
|
Definition at line 274 of file bitmapdropdown.cpp.
|
|
Function : CBitmapDropDown::AddDivider Author : Mikhail Tatarnikov Purpose : Add a divider Returns : void Exceptions: Parameters: None Notes : Definition at line 311 of file bitmapdropdown.cpp. 00312 { 00313 DropDown::AddItem(NULL); 00314 }
|
|
Function : CBitmapDropDown::AddItem Author : Mikhail Tatarnikov Purpose : Adds a new item (icon + text) Returns : void Exceptions: Parameters: [in] UINT32 uiBitmapResID - bitmap resource for the item; [in] String_256 strText - item label. Notes : Definition at line 291 of file bitmapdropdown.cpp. 00292 { 00293 m_vecItems.push_back(CBDDItemInfo(uiBitmapResID, strText)); 00294 00295 // Get the point to the last stored 00296 CBDDItemInfo* poItem = &(m_vecItems[m_vecItems.size() - 1]); 00297 DropDown::AddItem((void*)poItem); 00298 00299 SetSelectedIndex(0); 00300 }
|
|
Function : CBitmapDropDown::DeleteItem Author : Mikhail Tatarnikov Purpose : Removes an item from dropdown Returns : void Exceptions: Parameters: [in] INT32 iIndex - index of an item to be removed. Notes : Reimplemented from DropDown. Definition at line 325 of file bitmapdropdown.cpp.
|
|
Function : CBitmapDropDown::DrawIcon Author : Mikhail Tatarnikov Purpose : Draws item icon Returns : wxSize - the icon size Exceptions: Parameters: [in] wxDC& dc - device context to draw to; [in] const wxRect& Rect - the clipping area for the item; [in] INT32 item - item index; [in] INT32 flags - flags (see odcombo.h, the only specified flag at the moment of writing is wxCP_PAINTING_CONTROL); [in] BOOL Draw - TRUE if we should draw, FALSE in case of size measurement. Notes : Definition at line 588 of file bitmapdropdown.cpp. 00589 { 00590 // wxBitmap * pBitmap = CamArtProvider::Get()->FindBitmap(BitmapID, (CamArtFlags)(CAF_DEFAUL T| (Disabled?CAF_GREYED:0))); 00591 wxSize szBitmap(0, 0); 00592 00593 void* pvItemData = GetItemData(item); 00594 CBDDItemInfo* pItemInfo = reinterpret_cast<CBDDItemInfo*>(pvItemData); 00595 00596 wxBitmap* pBitmap = CamArtProvider::Get()->FindBitmap(pItemInfo->GetBitmapID(), CAF_DEFAULT); 00597 if (!pBitmap) 00598 return szBitmap; 00599 00600 szBitmap.x = pBitmap->GetWidth(); 00601 szBitmap.y = pBitmap->GetHeight(); 00602 00603 if (Draw) 00604 { 00605 dc.DrawBitmap(*pBitmap, rcIcon.GetLeft(), rcIcon.GetTop(), TRUE); 00606 /* 00607 // Calculate the destination bitmap size (the bitmap can be bigger than the draw rect, so 00608 // we need to shrink it. 00609 wxSize szDestination; 00610 szDestination.x = min(szBitmap.x, rcIcon.GetWidth()); 00611 szDestination.y = min(szBitmap.y, rcIcon.GetHeight()); 00612 00613 wxMemoryDC dcMem; 00614 dcMem.SelectObject(*pBitmap); 00615 00616 dc.Blit(rcIcon.GetLeft(), rcIcon.GetTop(), szDestination.x, szDestination.y, &dcMem, 0, 0); 00617 */ 00618 } 00619 return szBitmap; 00620 }
|
|
Function : CBitmapDropDown::GetItemData Author : Mikhail Tatarnikov Purpose : Obtains the data for an item. Returns : void* - the pointer to the data. Exceptions: Parameters: [in] INT32 iItemIndex - item index to get data for. Notes : Since the information is stored in the internal array (not in the combobox itself), we need to override the default behaivour. Reimplemented from DropDown. Definition at line 341 of file bitmapdropdown.cpp. 00342 { 00343 // Check if we are requested information about "unselected" item. 00344 if (iItemIndex < 0) 00345 return (void*)(&m_oUnselectedItemInfo); 00346 00347 // The normal items are stored in the items collection. 00348 CBDDItemInfo* poItem = &(m_vecItems[iItemIndex]); 00349 00350 return (void*)poItem; 00351 }
|
|
Function : CBitmapDropDown::GetText Author : Mikhail Tatarnikov Purpose : Obtains label for the item. Returns : wxString - Exceptions: Parameters: [in] void* pvItemData - the item data; [in] INT32 iItem - the item index. Notes : Reimplemented from DropDown. Definition at line 398 of file bitmapdropdown.cpp. 00399 { 00400 if (!pvItemData) 00401 return DropDown::GetText(pvItemData, iItem); 00402 00403 CBDDItemInfo* pItemInfo = reinterpret_cast<CBDDItemInfo*>(pvItemData); 00404 00405 return pItemInfo->GetText(); 00406 }
|
|
Function : CBitmapDropDown::HandleDrawItemInternal Author : Mikhail Tatarnikov Purpose : Handles items drawing Returns : wxSize - the size of the item. Exceptions: Parameters: [in] wxDC& dc - device context to draw to; [in] const wxRect& Rect - the clipping area for the item; [in] INT32 item - item index; [in] INT32 flags - flags (see odcombo.h, the only specified flag at the moment of writing is wxCP_PAINTING_CONTROL); [in] BOOL Draw - TRUE if we should draw, FALSE in case of size measurement. Notes : Reimplemented from DropDown. Definition at line 474 of file bitmapdropdown.cpp. 00475 { 00476 const INT32 ciBorderSize = 2; 00477 const INT32 ciInterval = 6; 00478 00479 00480 if (CCamApp::IsDisabled()) // Inside an error handler 00481 return (wxDefaultSize); 00482 00483 // wxOwnerDrawnComboBox* pGadget = GetBox(); 00484 00485 // if ((INT32)pInfo->itemID == -1 || (INT32)pInfo->itemData == -1) // Draw item -1: just exit 00486 // return(FALSE); 00487 00488 void* pvItemData = GetItemData(item); 00489 00490 // Determine if it is a divider item 00491 if (!pvItemData) 00492 { 00493 // It's a divider, so draw it specially - it is a simple black line across the center of the rectangle 00494 if (Draw) 00495 { 00496 wxCoord midpoint = Rect.GetTop()+Rect.GetHeight()/2; 00497 wxPen OldPen=dc.GetPen(); 00498 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT))); 00499 dc.DrawLine(Rect.GetLeft(), midpoint, Rect.GetRight()+1, midpoint); 00500 dc.SetPen(OldPen); 00501 } 00502 return(wxSize(-1,5)); 00503 } 00504 00505 // CBDDItemInfo* pItemInfo = reinterpret_cast<CBDDItemInfo*>(pvItemData); 00506 00507 if (!Draw) 00508 { 00509 // The item height is the icon height, if any. We don't shrink the icon. 00510 // If there's no icon, the height is the text height. 00511 wxRect rcDummy(-1, -1, -1, -1); 00512 00513 // Obtain the icon size. 00514 wxSize szIcon(0, 0); 00515 if (HasIcon(pvItemData)) 00516 szIcon = DrawIcon(dc, rcDummy, item, flags, FALSE); 00517 00518 // Obtain the text size. 00519 wxSize szText(0, 0); 00520 if (HasText(pvItemData)) 00521 szText = DrawText(pvItemData, dc, rcDummy, item, flags, FALSE); 00522 00523 wxSize szItem; 00524 szItem.y = max(szText.y, szIcon.y); 00525 szItem.x = szIcon.x + szText.x; 00526 00527 // If both text and icon exist, there should be an interval between them 00528 if (HasIcon(pvItemData) && HasText(pvItemData)) 00529 szItem.x += ciInterval; 00530 00531 // Add a border. 00532 szItem.x += 2*ciBorderSize; 00533 szItem.y += 2*ciBorderSize; 00534 00535 return szItem; 00536 } 00537 00538 00539 00540 wxRect rcTemp = Rect; 00541 rcTemp.Deflate(ciBorderSize); 00542 00543 wxPalette* popalOld = NULL; 00544 00545 // Draw the icon, if any. 00546 if (HasIcon(pvItemData)) 00547 { 00548 if (PaletteManager::UsePalette()) 00549 popalOld = PaletteManager::StartPaintPalette(&dc); 00550 00551 wxSize szIcon = DrawIcon(dc, rcTemp, item, flags, TRUE); 00552 00553 // Calculate the text size. 00554 INT32 iShift = szIcon.x + ciInterval; 00555 rcTemp.Offset(iShift, 0); 00556 00557 INT32 iNewWidth = rcTemp.GetWidth() - ciInterval; 00558 rcTemp.SetWidth(iNewWidth < 1 ? 1 : iNewWidth); 00559 } 00560 00561 00562 00563 if (HasText(pvItemData)) 00564 DrawText(pvItemData, dc, rcTemp, item, flags, TRUE); 00565 00566 // Restore the DC's previous palette if we selected our one in 00567 if (popalOld) 00568 PaletteManager::StopPaintPalette(&dc, popalOld); 00569 00570 return(wxDefaultSize); 00571 }
|
|
Function : CBitmapDropDown::HasIcon Author : Mikhail Tatarnikov Purpose : Determines if the item (represented by its data) has an icon Returns : BOOL - TRUE if icon was supplied for the item, FALSE otherwise. Exceptions: Parameters: [in] void* pvItemData - the item data. Notes : Reimplemented from DropDown. Definition at line 363 of file bitmapdropdown.cpp. 00364 { 00365 CBDDItemInfo* pItemInfo = reinterpret_cast<CBDDItemInfo*>(pvItemData); 00366 if (pItemInfo->GetBitmapID() != (UINT32)-1) 00367 return TRUE; 00368 00369 return FALSE; 00370 }
|
|
Function : CBitmapDropDown::HasText Author : Mikhail Tatarnikov Purpose : Determines whether an item has text label Returns : BOOL - TRUE if text was supplied for the item, FALSE otherwise. Exceptions: Parameters: [in] void* pvItemData - the item data. Notes : Definition at line 381 of file bitmapdropdown.cpp. 00382 { 00383 CBDDItemInfo* pItemInfo = reinterpret_cast<CBDDItemInfo*>(pvItemData); 00384 return pItemInfo->HasText(); 00385 }
|
|
Function : CBitmapDropDown::Init Author : Mikhail Tatarnikov Purpose : Initialize the control Returns : BOOL - TRUE if success, FALSE otherwise. Exceptions: Parameters: [in] CWindowID Window - the parent window, NULL to deinitialize; [in] CGadgetID Gadget - the control ID. Notes : Reimplemented from DropDown. Definition at line 420 of file bitmapdropdown.cpp. 00421 { 00422 if (Window) 00423 { 00424 // Obtain the gadget and check if it has an appropriate class (we can 00425 // be attached to owner-draw combobox obly). 00426 wxWindow * pGadget = DialogManager::GetGadget(Window, Gadget); 00427 if (pGadget && pGadget->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox))) 00428 { 00429 if (!Initialised) // Only ever add myself to the list once 00430 { 00431 m_pPopup = new wxCamBitmapDropdownPopup(this); 00432 ERROR2IF(!m_pPopup, FALSE, "Could not get new list popup"); 00433 ((wxOwnerDrawnComboBox *)pGadget)->SetPopupControl(m_pPopup); 00434 CurrentDropDowns.AddHead(this); 00435 } 00436 00437 ParentDlg = Window; 00438 ParentGadget = Gadget; 00439 00440 Initialised = TRUE; 00441 return(TRUE); 00442 } 00443 ERROR3("CBitmapDropDown::Init failed - illegal Gadget"); 00444 return(FALSE); 00445 } 00446 else 00447 { 00448 // release all memory 00449 KillList(); 00450 ClearList(); 00451 ParentDlg=NULL; 00452 ParentGadget=0; 00453 Initialised=FALSE; 00454 CurrentDropDowns.RemoveItem(this); 00455 return TRUE; 00456 } 00457 }
|
|
Sets the index of the selected item in the list. Take care never to set a divider as the selected item (it'll work, but it's a silly item to have selected!).
Reimplemented from DropDown. Definition at line 204 of file bitmapdropdown.h. 00204 {DropDown::SetSelectedIndex(iSelectedIndex);}
|
|
Function : CBitmapDropDown::SetUnselectedIntem Author : Mikhail Tatarnikov Purpose : Sets the information for "unselected item" Returns : void Exceptions: Parameters: [in] UINT32 uiBitmapID - the "unselected" item bitmap; [in] String_256 strText - label for the item. Notes : These bitmap and label will be drawn when no item is selected (by default nothing is drawn) Definition at line 634 of file bitmapdropdown.cpp. 00635 { 00636 m_oUnselectedItemInfo = CBDDItemInfo(uiBitmapID, strText); 00637 }
|
|
Reimplemented from DropDown. Definition at line 187 of file bitmapdropdown.h. |
|
Definition at line 235 of file bitmapdropdown.h. |
|
Definition at line 232 of file bitmapdropdown.h. |