DropDown Class Reference

#include <dropdown.h>

Inheritance diagram for DropDown:

ListItem CCObject SimpleCCObject CBitmapDropDown ColourDropDown FontDropDown DocumentFontDropDown List of all members.

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.
wxOwnerDrawnComboBoxGetBox ()
 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
wxCamVListBoxComboPopupm_pPopup

Static Protected Attributes

static List CurrentDropDowns

Friends

class DialogManager
class wxCamVListBoxComboPopup

Detailed Description

Definition at line 131 of file dropdown.h.


Constructor & Destructor Documentation

DropDown::DropDown  ) 
 

DropDown constructor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 29/8/95
Notes: Follow this up with a call to Init()

See also:
DropDown::Init; ColourDropDown; FontDropDown

Definition at line 188 of file dropdown.cpp.

00189 {
00190     ParentDlg = NULL;
00191     m_pPopup = NULL;
00192     ParentGadget = 0;
00193     Initialised = FALSE;
00194 }

DropDown::~DropDown  )  [virtual]
 

DropDown destructor.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 29/8/95

Definition at line 209 of file dropdown.cpp.

00210 {
00211     if (Initialised)
00212     {
00213         // Do any deinit here
00214         Init(NULL, 0);
00215     }
00216 }


Member Function Documentation

void DropDown::AddItem void *  ItemData  )  [protected]
 

Adds another item or divider to the end of the current list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemData - A data value to associate with this item. This must be unique [INPUTS] so you can use this ItemData to determine how to redraw the item. The value NULL is special: It puts a non-selectable divider line into the 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 }

void DropDown::ClearList void   ) 
 

Clears all items from the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95

Definition at line 338 of file dropdown.cpp.

00339 {
00340     wxOwnerDrawnComboBox * pGadget = GetBox();
00341     if (!pGadget)
00342         return;
00343     pGadget->Clear();
00344 }

void DropDown::DeleteItem INT32  index  )  [protected]
 

Removes an item from the list.

Author:
Martin Wuerthner <xara@mw-software.com> Date: 22/05/06
Parameters:
index - the index of the item to be removed [INPUTS]

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 }

BOOL DropDown::DrawIcon void *  ItemData,
wxDC &  dc,
wxRect &  IconRect,
BOOL  Disabled,
INT32  flags
[protected, virtual]
 

Draws the icon for an item.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemData - Your item data [INPUTS] dc - The DC to render into IconRect - points at a rectangle (square in fact) to be drawn within Disabled - TRUE if the item is disabled so should be drawn greyed
Returns:
TRUE if this item needs an icon to the left of it, FALSE if not
Notes: Called by HandleDrawItemInternal when this object has been identified as the owner of the control to be redrawn - ONLY called if HasIcon returned TRUE

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.

See also:
DropDown::HasIcon; DropDown::DrawText; ColourDropDown::DrawIcon

Reimplemented in ColourDropDown, and FontDropDown.

Definition at line 684 of file dropdown.cpp.

00685 {
00686     return(TRUE);
00687 }

wxSize DropDown::DrawText void *  ItemData,
wxDC &  dc,
wxRect &  TextRect,
INT32  item,
INT32  flags,
BOOL  Draw
[protected, virtual]
 

Draws the text for an item.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemData - Your item data [INPUTS] wxDC& - the DC to draw into TextRect - points at a rectangle in which the text should be rendered Item - the index of the item flags - the flags sent to OnDrawItem Draw - TRUE to Draw, FALSE to just get a size
Returns:
The size of the text
Notes: Called by HandleDrawItemInternal when this object has been identified as the owner of the control to be redrawn, if HasIcon returned TRUE

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.

See also:
DropDown::DrawIcon; DropDown::DrawIcon; ColourDropDown::DrawText

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 }

wxOwnerDrawnComboBox * DropDown::GetBox  )  [protected]
 

Return the pointer to the combo box (once class is initialized) or NULL on error.

Author:
AlexBligh Date: 13/05/2005
Returns:
A pointer to the combo box

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 }

void * DropDown::GetItemData INT32  ItemIndex  )  [protected]
 

Retrieves the data for a given item in the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemIndex - the index (0 based) of the item in the drop list (e.g. as [INPUTS] given to you by GetSelectedValueIndex() on DIM_SELECTION_CHANGED)
Returns:
NULL, or the data word held in the indexed item

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 }

INT32 DropDown::GetNumberOfItems void   )  [protected]
 

Determines the number of items in the list.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Returns:
A count of how many items are in the list. Indexes in the list will go from 0 to GetNumberOfItems()-1

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 }

virtual wxString DropDown::GetText void *  ItemData,
INT32  Item
[inline, protected, virtual]
 

Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown.

Definition at line 164 of file dropdown.h.

00164 {return wxEmptyString;}

wxSize DropDown::HandleDrawItemInternal wxDC &  dc,
const wxRect &  Rect,
INT32  item,
INT32  flags,
BOOL  Draw
[protected, virtual]
 

Handles redraw of items in a DropDown control.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 29/8/95
Parameters:
hDlg - The CWindowID of the control which needs redrawing [INPUTS] wParam, lParam - As for the WM_DRAWITEM message
Returns:
TRUE if it handled (claimed) the message FALSE if it did not handle the message
Notes: Called by HandleDrawItem when this object has been identified as the owner of the control to be redrawn.

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

See also:
DropDown::HasIcon; DropDown::DrawIcon; DropDown::DrawText

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 }

BOOL DropDown::HasIcon void *  ItemData  )  [protected, virtual]
 

Determine if an item needs an icon next to it.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
ItemData - Your item data [INPUTS]
Returns:
TRUE if this item needs an icon to the left of it, FALSE if not
Notes: Called by HandleDrawItemInternal when this object has been identified as the owner of the control to be redrawn.

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

See also:
DropDown::DrawIcon; DropDown::DrawText

Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown.

Definition at line 648 of file dropdown.cpp.

00649 {
00650     return(FALSE);
00651 }

BOOL DropDown::Init CWindowID  Window,
CGadgetID  Gadget
[virtual]
 

DropDown initialiser.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 29/8/95
Parameters:
Window - The Window in which your dropdown list gadget resides or NULL to denitialise [INPUTS] Gadget - The GadgetID of the deropdown list gadget
Returns:
TRUE if it succeeded in connecting itself to your gadget FALSE if it failed

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 }

void DropDown::KillDropDownsByWindow CWindowID  Window  )  [static]
 

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.

Author:
Alex Bligh <alex@alex.org.uk> Date: 15/05/2005

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 }

virtual void DropDown::KillList void   )  [inline, protected, virtual]
 

Reimplemented in FontDropDown.

Definition at line 149 of file dropdown.h.

00149 {} // allow reclaiming of memory on death

void DropDown::SetListRedraw BOOL  Enable  )  [protected]
 

Enables/Disables redraw of the combobox. Put around a sequence of calls to AddItem to stop flickery redraws as you add items.

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
Enable - TRUE to enable, FALSE to disable redraw [INPUTS]

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 }

void DropDown::SetSelectedIndex INT32  SelectedIndex  )  [protected]
 

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!).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> Date: 13/9/95
Parameters:
SelectedIndex - the index (0 based) of the item in the drop list [INPUTS]

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 }


Friends And Related Function Documentation

friend class DialogManager [friend]
 

Reimplemented in CBitmapDropDown, ColourDropDown, and FontDropDown.

Definition at line 133 of file dropdown.h.

friend class wxCamVListBoxComboPopup [friend]
 

Definition at line 134 of file dropdown.h.


Member Data Documentation

List DropDown::CurrentDropDowns [static, protected]
 

Definition at line 147 of file dropdown.h.

BOOL DropDown::Initialised [protected]
 

Definition at line 202 of file dropdown.h.

wxCamVListBoxComboPopup* DropDown::m_pPopup [protected]
 

Definition at line 206 of file dropdown.h.

CWindowID DropDown::ParentDlg [protected]
 

Definition at line 204 of file dropdown.h.

CGadgetID DropDown::ParentGadget [protected]
 

Definition at line 205 of file dropdown.h.


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