1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/bmpcbox.h
3 // Purpose: wxBitmapComboBox
4 // Author: Jaakko Salli
6 // Created: Aug-30-2006
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_BMPCBOX_H_
13 #define _WX_GENERIC_BMPCBOX_H_
16 #define wxGENERIC_BITMAPCOMBOBOX 1
18 #include "wx/odcombo.h"
20 // ----------------------------------------------------------------------------
21 // wxBitmapComboBox: a wxComboBox that allows images to be shown
22 // in front of string items.
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_ADV wxBitmapComboBox
: public wxOwnerDrawnComboBox
,
26 public wxBitmapComboBoxBase
31 wxBitmapComboBox() : wxOwnerDrawnComboBox(), wxBitmapComboBoxBase()
36 wxBitmapComboBox(wxWindow
*parent
,
37 wxWindowID id
= wxID_ANY
,
38 const wxString
& value
= wxEmptyString
,
39 const wxPoint
& pos
= wxDefaultPosition
,
40 const wxSize
& size
= wxDefaultSize
,
42 const wxString choices
[] = NULL
,
44 const wxValidator
& validator
= wxDefaultValidator
,
45 const wxString
& name
= wxBitmapComboBoxNameStr
)
46 : wxOwnerDrawnComboBox(),
47 wxBitmapComboBoxBase()
51 (void)Create(parent
, id
, value
, pos
, size
, n
,
52 choices
, style
, validator
, name
);
55 wxBitmapComboBox(wxWindow
*parent
,
57 const wxString
& value
,
60 const wxArrayString
& choices
,
62 const wxValidator
& validator
= wxDefaultValidator
,
63 const wxString
& name
= wxBitmapComboBoxNameStr
);
65 bool Create(wxWindow
*parent
,
67 const wxString
& value
,
71 const wxString choices
[],
73 const wxValidator
& validator
= wxDefaultValidator
,
74 const wxString
& name
= wxBitmapComboBoxNameStr
);
76 bool Create(wxWindow
*parent
,
78 const wxString
& value
,
81 const wxArrayString
& choices
,
83 const wxValidator
& validator
= wxDefaultValidator
,
84 const wxString
& name
= wxBitmapComboBoxNameStr
);
86 virtual ~wxBitmapComboBox();
88 // Adds item with image to the end of the combo box.
89 int Append(const wxString
& item
, const wxBitmap
& bitmap
= wxNullBitmap
)
90 { return DoAppendWithImage(item
, bitmap
); }
92 int Append(const wxString
& item
, const wxBitmap
& bitmap
, void *clientData
)
93 { int n
= DoAppendWithImage(item
, bitmap
); SetClientData(n
, clientData
); return n
; }
94 int Append(const wxString
& item
, const wxBitmap
& bitmap
, wxClientData
*clientData
)
95 { int n
= DoAppendWithImage(item
, bitmap
); SetClientObject(n
, clientData
); return n
; }
97 // Returns size of image used in list.
98 virtual wxSize
GetBitmapSize() const
100 return m_usedImgSize
;
103 // Returns the image of the item with the given index.
104 virtual wxBitmap
GetItemBitmap(unsigned int n
) const;
106 // Inserts item with image into the list before pos. Not valid for wxCB_SORT or wxCB_SORT
107 // styles, use Append instead.
108 int Insert(const wxString
& item
, const wxBitmap
& bitmap
, unsigned int pos
)
109 { return DoInsertWithImage(item
, bitmap
, pos
); }
111 int Insert(const wxString
& item
, const wxBitmap
& bitmap
,
112 unsigned int pos
, void *clientData
);
113 int Insert(const wxString
& item
, const wxBitmap
& bitmap
,
114 unsigned int pos
, wxClientData
*clientData
);
116 // Sets the image for the given item.
117 virtual void SetItemBitmap(unsigned int n
, const wxBitmap
& bitmap
);
119 virtual void Clear();
120 virtual void Delete(unsigned int n
);
124 virtual void OnDrawBackground(wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const;
125 virtual void OnDrawItem(wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const;
126 virtual wxCoord
OnMeasureItem(size_t item
) const;
127 virtual wxCoord
OnMeasureItemWidth(size_t item
) const;
129 virtual int DoAppendWithImage(const wxString
& item
, const wxBitmap
& bitmap
);
130 virtual int DoInsertWithImage(const wxString
& item
, const wxBitmap
& bitmap
,
133 virtual int DoAppend(const wxString
& item
);
134 virtual int DoInsert(const wxString
& item
, unsigned int pos
);
136 virtual bool SetFont(const wxFont
& font
);
138 virtual wxSize
DoGetBestSize() const;
141 void OnSize(wxSizeEvent
& event
);
143 // Recalculates amount of empty space needed in front of
144 // text in control itself.
145 void DetermineIndent();
147 bool OnAddBitmap(const wxBitmap
& bitmap
);
149 // Adds image to position - called in Append/Insert before
151 bool DoInsertBitmap(const wxBitmap
& image
, unsigned int pos
);
154 wxArrayPtrVoid m_bitmaps
; // Images associated with items
155 wxSize m_usedImgSize
; // Size of bitmaps
158 int m_imgAreaWidth
; // Width and height of area next to text field
165 DECLARE_EVENT_TABLE()
167 DECLARE_DYNAMIC_CLASS(wxBitmapComboBox
)
170 #endif // _WX_GENERIC_BMPCBOX_H_