]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/bmpcbox.h
Implememt GetColoursCount() in the generic wxPalette.
[wxWidgets.git] / include / wx / generic / bmpcbox.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/bmpcbox.h
3 // Purpose: wxBitmapComboBox
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: Aug-30-2006
7 // RCS-ID: $Id:
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_BMPCBOX_H_
13 #define _WX_GENERIC_BMPCBOX_H_
14
15
16 #define wxGENERIC_BITMAPCOMBOBOX 1
17
18 #if !wxUSE_ODCOMBOBOX
19 #error "Generic wxBitmapComboBox depends on wxOwnerDrawnComboBox"
20 #endif
21
22 #include "wx/odcombo.h"
23
24
25 // ----------------------------------------------------------------------------
26 // wxBitmapComboBox: a wxComboBox that allows images to be shown
27 // in front of string items.
28 // ----------------------------------------------------------------------------
29
30 class WXDLLIMPEXP_ADV wxBitmapComboBox : public wxOwnerDrawnComboBox,
31 public wxBitmapComboBoxBase
32 {
33 public:
34
35 // ctors and such
36 wxBitmapComboBox() : wxOwnerDrawnComboBox(), wxBitmapComboBoxBase()
37 {
38 Init();
39 }
40
41 wxBitmapComboBox(wxWindow *parent,
42 wxWindowID id = wxID_ANY,
43 const wxString& value = wxEmptyString,
44 const wxPoint& pos = wxDefaultPosition,
45 const wxSize& size = wxDefaultSize,
46 int n = 0,
47 const wxString choices[] = NULL,
48 long style = 0,
49 const wxValidator& validator = wxDefaultValidator,
50 const wxString& name = wxBitmapComboBoxNameStr)
51 : wxOwnerDrawnComboBox(),
52 wxBitmapComboBoxBase()
53 {
54 Init();
55
56 (void)Create(parent, id, value, pos, size, n,
57 choices, style, validator, name);
58 }
59
60 wxBitmapComboBox(wxWindow *parent,
61 wxWindowID id,
62 const wxString& value,
63 const wxPoint& pos,
64 const wxSize& size,
65 const wxArrayString& choices,
66 long style,
67 const wxValidator& validator = wxDefaultValidator,
68 const wxString& name = wxBitmapComboBoxNameStr);
69
70 bool Create(wxWindow *parent,
71 wxWindowID id,
72 const wxString& value,
73 const wxPoint& pos,
74 const wxSize& size,
75 int n,
76 const wxString choices[],
77 long style = 0,
78 const wxValidator& validator = wxDefaultValidator,
79 const wxString& name = wxBitmapComboBoxNameStr);
80
81 bool Create(wxWindow *parent,
82 wxWindowID id,
83 const wxString& value,
84 const wxPoint& pos,
85 const wxSize& size,
86 const wxArrayString& choices,
87 long style = 0,
88 const wxValidator& validator = wxDefaultValidator,
89 const wxString& name = wxBitmapComboBoxNameStr);
90
91 virtual ~wxBitmapComboBox();
92
93 // Adds item with image to the end of the combo box.
94 int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap)
95 { return DoAppendWithImage(item, bitmap); }
96
97 int Append(const wxString& item, const wxBitmap& bitmap, void *clientData)
98 { int n = DoAppendWithImage(item, bitmap); SetClientData(n, clientData); return n; }
99 int Append(const wxString& item, const wxBitmap& bitmap, wxClientData *clientData)
100 { int n = DoAppendWithImage(item, bitmap); SetClientObject(n, clientData); return n; }
101
102 // Returns size of image used in list.
103 virtual wxSize GetBitmapSize() const
104 {
105 return m_usedImgSize;
106 }
107
108 // Returns the image of the item with the given index.
109 virtual wxBitmap GetItemBitmap(unsigned int n) const;
110
111 // Inserts item with image into the list before pos. Not valid for wxCB_SORT or wxCB_SORT
112 // styles, use Append instead.
113 int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos)
114 { return DoInsertWithImage(item, bitmap, pos); }
115
116 int Insert(const wxString& item, const wxBitmap& bitmap,
117 unsigned int pos, void *clientData);
118 int Insert(const wxString& item, const wxBitmap& bitmap,
119 unsigned int pos, wxClientData *clientData);
120
121 // Sets the image for the given item.
122 virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap);
123
124 virtual void Clear();
125 virtual void Delete(unsigned int n);
126
127 protected:
128
129 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
130 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const;
131 virtual wxCoord OnMeasureItem(size_t item) const;
132 virtual wxCoord OnMeasureItemWidth(size_t item) const;
133
134 virtual int DoAppendWithImage(const wxString& item, const wxBitmap& bitmap);
135 virtual int DoInsertWithImage(const wxString& item, const wxBitmap& bitmap,
136 unsigned int pos);
137
138 virtual int DoAppend(const wxString& item);
139 virtual int DoInsert(const wxString& item, unsigned int pos);
140
141 virtual bool SetFont(const wxFont& font);
142
143 virtual wxSize DoGetBestSize() const;
144
145 // Event handlers
146 void OnResize(wxSizeEvent& event);
147
148 // Recalculates amount of empty space needed in front of
149 // text in control itself.
150 void DetermineIndent();
151
152 bool OnAddBitmap(const wxBitmap& bitmap);
153
154 // Adds image to position - called in Append/Insert before
155 // string is added.
156 bool DoInsertBitmap(const wxBitmap& image, unsigned int pos);
157
158
159 wxArrayPtrVoid m_bitmaps; // Images associated with items
160 wxSize m_usedImgSize; // Size of bitmaps
161
162 private:
163 int m_imgAreaWidth; // Width and height of area next to text field
164 int m_fontHeight;
165 bool m_inResize;
166
167 void Init();
168 void PostCreate();
169
170 DECLARE_EVENT_TABLE()
171
172 DECLARE_DYNAMIC_CLASS(wxBitmapComboBox)
173 };
174
175
176 #endif
177 // _WX_GENERIC_BMPCBOX_H_