#include <dropdown.h>
Inheritance diagram for DropDown:
Public Member Functions | |
DropDown () | |
DropDown constructor. | |
virtual | ~DropDown () |
DropDown destructor. | |
virtual BOOL | Init (CWindowID ParentWindow, CGadgetID ParentControl) |
DropDown initialiser. | |
void | ClearList (void) |
Clears all items from the list. | |
Static Public Member Functions | |
static void | KillDropDownsByWindow (CWindowID Window) |
Kills all the dropdowns associated with a particular window This is called when that window is dying. We can't delete the dropdowns but we can deinit them so they won't cause anyone eny hassle. | |
Protected Member Functions | |
virtual void | KillList () |
virtual BOOL | HasIcon (void *ItemData) |
Determine if an item needs an icon next to it. | |
virtual BOOL | DrawIcon (void *ItemData, wxDC &dc, wxRect &IconRect, BOOL Disabled, INT32 flags) |
Draws the icon for an item. | |
virtual wxSize | DrawText (void *ItemData, wxDC &dc, wxRect &TextRect, INT32 item, INT32 flags, BOOL Draw) |
Draws the text for an item. | |
virtual wxString | GetText (void *ItemData, INT32 Item) |
void | SetListRedraw (BOOL Enable) |
Enables/Disables redraw of the combobox. Put around a sequence of calls to AddItem to stop flickery redraws as you add items. | |
void | AddItem (void *ItemData) |
Adds another item or divider to the end of the current list. | |
void | DeleteItem (INT32 index) |
Removes an item from the list. | |
void | SetSelectedIndex (INT32 SelectedIndex) |
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 * | GetItemData (INT32 ItemIndex) |
Retrieves the data for a given item in the list. | |
INT32 | GetNumberOfItems (void) |
Determines the number of items in the list. | |
wxOwnerDrawnComboBox * | GetBox () |
Return the pointer to the combo box (once class is initialized) or NULL on error. | |
virtual wxSize | HandleDrawItemInternal (wxDC &dc, const wxRect &Rect, INT32 item, INT32 flags, BOOL Draw) |
Handles redraw of items in a DropDown control. | |
Protected Attributes | |
BOOL | Initialised |
CWindowID | ParentDlg |
CGadgetID | ParentGadget |
wxCamVListBoxComboPopup * | m_pPopup |
Static Protected Attributes | |
static List | CurrentDropDowns |
Friends | |
class | DialogManager |
class | wxCamVListBoxComboPopup |
Definition at line 131 of file dropdown.h.
|
DropDown constructor.
Definition at line 188 of file dropdown.cpp. 00189 { 00190 ParentDlg = NULL; 00191 m_pPopup = NULL; 00192 ParentGadget = 0; 00193 Initialised = FALSE; 00194 }
|
|
DropDown destructor.
Definition at line 209 of file dropdown.cpp. 00210 { 00211 if (Initialised) 00212 { 00213 // Do any deinit here 00214 Init(NULL, 0); 00215 } 00216 }
|
|
Adds another item or divider to the end of the current list.
Definition at line 391 of file dropdown.cpp. 00392 { 00393 wxOwnerDrawnComboBox * pGadget = GetBox(); 00394 if (!pGadget) 00395 return; 00396 INT32 n=pGadget->Append(wxEmptyString); // put in an empty string first 00397 m_pPopup->SetItemClientData(n, ItemData, wxClientData_Void); 00398 if (ItemData) 00399 pGadget->SetString(n, GetText(ItemData, n)); 00400 }
|
|
Clears all items from the list.
Definition at line 338 of file dropdown.cpp. 00339 { 00340 wxOwnerDrawnComboBox * pGadget = GetBox(); 00341 if (!pGadget) 00342 return; 00343 pGadget->Clear(); 00344 }
|
|
Removes an item from the list.
Reimplemented in CBitmapDropDown. Definition at line 414 of file dropdown.cpp. 00415 { 00416 wxOwnerDrawnComboBox * pGadget = GetBox(); 00417 if (!pGadget) 00418 return; 00419 INT32 count = (INT32)pGadget->GetCount(); 00420 if (index >= 0 && index < count) 00421 { 00422 pGadget->Delete(index); 00423 } 00424 else 00425 { 00426 ERROR3("DropDown::RemoveItem - attempt to delete non-existing item"); 00427 } 00428 }
|
|
Draws the icon for an item.
This method MUST be overridden by derived classes to provide redraw of their dropdown list items. The base class does nothing. On entry, the DC is ready for you to draw into, including having the camelot palette selected in etc.
Reimplemented in ColourDropDown, and FontDropDown. Definition at line 684 of file dropdown.cpp. 00685 { 00686 return(TRUE); 00687 }
|
|
Draws the text for an item.
This method MUST be overridden by derived classes to provide redraw of their dropdown list items. The base class draws nothing. Note that on entry, the text FG/BG colours have been set up appropriately for the state of the item (shaded, selected, etc) Basically, all you have to do is find the text and do a DrawText call.
Definition at line 723 of file dropdown.cpp. 00724 { 00725 if (Draw) 00726 { 00727 if ( (m_pPopup->wxVListBox::GetSelection() == (INT32)item) && !(flags & wxODCB_PAINTING_CONTROL) ) 00728 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); 00729 else 00730 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); 00731 } 00732 00733 wxString Text = GetText(ItemData, item); 00734 wxCoord w, h; 00735 dc.GetTextExtent(Text, &w, &h); 00736 wxSize size(w,dc.GetCharHeight()); 00737 00738 if (Draw) 00739 dc.DrawText( Text, TextRect.x, TextRect.y ); 00740 00741 return size; 00742 }
|
|
Return the pointer to the combo box (once class is initialized) or NULL on error.
Definition at line 230 of file dropdown.cpp. 00231 { 00232 wxWindow * pGadget = DialogManager::GetGadget(ParentDlg, ParentGadget); 00233 ERROR2IF(!pGadget || !pGadget->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox)), NULL, "Bad Dropdown Gadget"); 00234 return (wxOwnerDrawnComboBox *)pGadget; 00235 }
|
|
Retrieves the data for a given item in the list.
Reimplemented in CBitmapDropDown. Definition at line 470 of file dropdown.cpp. 00471 { 00472 wxOwnerDrawnComboBox * pGadget = GetBox(); 00473 if (!pGadget) 00474 return NULL; 00475 return m_pPopup->GetItemClientData(ItemIndex); 00476 }
|
|
Determines the number of items in the list.
Definition at line 494 of file dropdown.cpp. 00495 { 00496 wxOwnerDrawnComboBox * pGadget = GetBox(); 00497 if (!pGadget) 00498 return 0; 00499 return((INT32)pGadget->GetCount()); 00500 }
|
|
Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown. Definition at line 164 of file dropdown.h.
|
|
Handles redraw of items in a DropDown control.
This method should only be overridden in extreme circumstances If the item data for this item is NULL, then a divider line will be drawn. Otherwise, your derived DrawIcon and DrawText methods will be called. Scope: private
Reimplemented in CBitmapDropDown. Definition at line 533 of file dropdown.cpp. 00534 { 00535 const INT32 border = 2; 00536 00537 if (CCamApp::IsDisabled()) // Inside an error handler 00538 return(wxDefaultSize); 00539 00540 wxOwnerDrawnComboBox * pGadget = GetBox(); 00541 00542 // if ((INT32)pInfo->itemID == -1 || (INT32)pInfo->itemData == -1) // Draw item -1: just exit 00543 // return(FALSE); 00544 00545 void * ItemData = GetItemData(item); 00546 // Determine if it is a divider item 00547 if (!ItemData) 00548 { 00549 // It's a divider, so draw it specially - it is a simple black line across the center of the rectangle 00550 wxCoord midpoint = Rect.GetTop()+Rect.GetHeight()/2; 00551 if (Draw) 00552 { 00553 wxPen OldPen=dc.GetPen(); 00554 dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT))); 00555 dc.DrawLine(Rect.GetLeft(), midpoint, Rect.GetRight()+1, midpoint); 00556 dc.SetPen(OldPen); 00557 } 00558 return(wxSize(-1,5)); 00559 } 00560 00561 // If we aren't drawing, we should get the size of the text and return that appopriately modified 00562 if (!Draw) 00563 { 00564 // Call the derived class 00565 wxRect def(-1,-1,-1,-1); 00566 wxSize TextSize = DrawText(ItemData, dc, def, item, flags, FALSE); // Rect is unused here as Draw is FALSE 00567 TextSize.x+=2*border; 00568 TextSize.y+=2*border; // This gives us the bounding rect as we leave some space around it 00569 if (HasIcon(ItemData)) 00570 { 00571 // There is an icon. It's width is equal to the text height less 2 (deflated in both 00572 // directions. There is also a 6 pixel space 00573 TextSize.x += (TextSize.y-2)+6; 00574 } 00575 return TextSize; 00576 } 00577 00578 wxRect rect=Rect; 00579 rect.Deflate(border); 00580 00581 // Calculate where the colour splodge (if any) will go (also used to shift text to the right later) 00582 wxRect IconRect=rect; 00583 IconRect.Deflate(1); 00584 IconRect.SetWidth(IconRect.GetHeight()); 00585 00586 wxRect TextRect=rect; 00587 00588 wxPalette * OldPal = NULL; 00589 00590 // If it's a special item with a colour splodge, or a normal colour item, draw the colour splodge 00591 if (HasIcon(ItemData)) 00592 { 00593 if (PaletteManager::UsePalette()) 00594 OldPal = PaletteManager::StartPaintPalette(&dc); 00595 00596 // Call the derived class to draw the icon 00597 if (Draw) 00598 DrawIcon(ItemData, dc, IconRect, !pGadget->IsEnabled(), flags); 00599 00600 // Shift the text to the right of the icon 00601 INT32 shift=IconRect.GetWidth()+6; 00602 TextRect.Offset(shift,0); 00603 INT32 NewWidth=TextRect.GetWidth()-shift; 00604 TextRect.SetWidth(NewWidth<1?1:NewWidth); 00605 } 00606 00607 if (TextRect.GetWidth()>1) // if there's room to draw any text, draw it 00608 { 00609 // Call derived class to draw the text 00610 if (Draw) 00611 DrawText(ItemData, dc, TextRect, item, flags, TRUE); 00612 } 00613 00614 // Restore the DC's previous palette if we selected our one in 00615 if (OldPal) 00616 PaletteManager::StopPaintPalette(&dc, OldPal); 00617 00618 return(wxDefaultSize); 00619 }
|
|
Determine if an item needs an icon next to it.
This method MUST be overridden by derived classes to provide redraw of their dropdown list items. The base class returns FALSE If you return TRUE, you must also provide the DrawIcon method
Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown. Definition at line 648 of file dropdown.cpp. 00649 { 00650 return(FALSE); 00651 }
|
|
DropDown initialiser.
Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown. Definition at line 254 of file dropdown.cpp. 00255 { 00256 if (Window) 00257 { 00258 wxWindow * pGadget = DialogManager::GetGadget(Window, Gadget); 00259 if (pGadget && pGadget->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox))) 00260 { 00261 if (!Initialised) // Only ever add myself to the list once 00262 { 00263 m_pPopup = new wxCamVListBoxComboPopup(this); 00264 ERROR2IF(!m_pPopup, FALSE, "Could not get new list popup"); 00265 ((wxOwnerDrawnComboBox *)pGadget)->SetPopupControl(m_pPopup); 00266 CurrentDropDowns.AddHead(this); 00267 } 00268 00269 ParentDlg = Window; 00270 ParentGadget = Gadget; 00271 00272 Initialised = TRUE; 00273 return(TRUE); 00274 } 00275 ERROR3("DropDown::Init failed - illegal Gadget"); 00276 return(FALSE); 00277 } 00278 else 00279 { 00280 // release all memory 00281 KillList(); 00282 ClearList(); 00283 ParentDlg=NULL; 00284 ParentGadget=0; 00285 Initialised=FALSE; 00286 CurrentDropDowns.RemoveItem(this); 00287 return TRUE; 00288 } 00289 }
|
|
Kills all the dropdowns associated with a particular window This is called when that window is dying. We can't delete the dropdowns but we can deinit them so they won't cause anyone eny hassle.
Definition at line 304 of file dropdown.cpp. 00305 { 00306 // First kill any associated with this window 00307 DropDown *Ptr = (DropDown *) CurrentDropDowns.GetHead(); 00308 while (Ptr != NULL) 00309 { 00310 DropDown * Next = (DropDown *) CurrentDropDowns.GetNext(Ptr); // as we may remove this item from the list 00311 if (Ptr->Initialised && (Ptr->ParentDlg==Window)) 00312 Ptr->Init(NULL, 0); 00313 Ptr = Next; 00314 } 00315 00316 // Now process children if any 00317 wxWindowList::Node * pNode = Window->GetChildren().GetFirst(); 00318 while (pNode) 00319 { 00320 KillDropDownsByWindow(pNode->GetData()); 00321 pNode = pNode->GetNext(); 00322 } 00323 return; 00324 }
|
|
Reimplemented in FontDropDown. Definition at line 149 of file dropdown.h.
|
|
Enables/Disables redraw of the combobox. Put around a sequence of calls to AddItem to stop flickery redraws as you add items.
Definition at line 362 of file dropdown.cpp. 00363 { 00364 wxOwnerDrawnComboBox * pGadget = GetBox(); 00365 if (!pGadget) 00366 return; 00367 if (Enable) 00368 pGadget->Thaw(); 00369 else 00370 pGadget->Freeze(); 00371 }
|
|
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 in CBitmapDropDown. Definition at line 445 of file dropdown.cpp. 00446 { 00447 wxOwnerDrawnComboBox * pGadget = GetBox(); 00448 if (!pGadget) 00449 return; 00450 pGadget->SetSelection(SelectedIndex); // And set the appropriate selected item 00451 }
|
|
Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown. Definition at line 133 of file dropdown.h. |
|
Definition at line 134 of file dropdown.h. |
|
Definition at line 147 of file dropdown.h. |
|
Definition at line 202 of file dropdown.h. |
|
Definition at line 206 of file dropdown.h. |
|
Definition at line 204 of file dropdown.h. |
|
Definition at line 205 of file dropdown.h. |