]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/bmpcbox.h
prevent crash if panel/kicker is killed, bug 1872724
[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 #include "wx/odcombo.h"
19
20 // ----------------------------------------------------------------------------
21 // wxBitmapComboBox: a wxComboBox that allows images to be shown
22 // in front of string items.
23 // ----------------------------------------------------------------------------
24
25 class WXDLLIMPEXP_ADV wxBitmapComboBox : public wxOwnerDrawnComboBox,
26 public wxBitmapComboBoxBase
27 {
28 public:
29
30 // ctors and such
31 wxBitmapComboBox() : wxOwnerDrawnComboBox(), wxBitmapComboBoxBase()
32 {
33 Init();
34 }
35
36 wxBitmapComboBox(wxWindow *parent,
37 wxWindowID id = wxID_ANY,
38 const wxString& value = wxEmptyString,
39 const wxPoint& pos = wxDefaultPosition,
40 const wxSize& size = wxDefaultSize,
41 int n = 0,
42 const wxString choices[] = NULL,
43 long style = 0,
44 const wxValidator& validator = wxDefaultValidator,
45 const wxString& name = wxBitmapComboBoxNameStr)
46 : wxOwnerDrawnComboBox(),
47 wxBitmapComboBoxBase()
48 {
49 Init();
50
51 (void)Create(parent, id, value, pos, size, n,
52 choices, style, validator, name);
53 }
54
55 wxBitmapComboBox(wxWindow *parent,
56 wxWindowID id,
57 const wxString& value,
58 const wxPoint& pos,
59 const wxSize& size,
60 const wxArrayString& choices,
61 long style,
62 const wxValidator& validator = wxDefaultValidator,
63 const wxString& name = wxBitmapComboBoxNameStr);
64
65 bool Create(wxWindow *parent,
66 wxWindowID id,
67 const wxString& value,
68 const wxPoint& pos,
69 const wxSize& size,
70 int n,
71 const wxString choices[],
72 long style = 0,
73 const wxValidator& validator = wxDefaultValidator,
74 const wxString& name = wxBitmapComboBoxNameStr);
75
76 bool Create(wxWindow *parent,
77 wxWindowID id,
78 const wxString& value,
79 const wxPoint& pos,
80 const wxSize& size,
81 const wxArrayString& choices,
82 long style = 0,
83 const wxValidator& validator = wxDefaultValidator,
84 const wxString& name = wxBitmapComboBoxNameStr);
85
86 virtual ~wxBitmapComboBox();
87
88 // Adds item with image to the end of the combo box.
89 int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap);
90 int Append(const wxString& item, const wxBitmap& bitmap, void *clientData);
91 int Append(const wxString& item, const wxBitmap& bitmap, wxClientData *clientData);
92
93 // Inserts item with image into the list before pos. Not valid for wxCB_SORT
94 // styles, use Append instead.
95 int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos);
96 int Insert(const wxString& item, const wxBitmap& bitmap,
97 unsigned int pos, void *clientData);
98 int Insert(const wxString& item, const wxBitmap& bitmap,
99 unsigned int pos, wxClientData *clientData);
100
101 // Returns size of image used in list.
102 virtual wxSize GetBitmapSize() const
103 {
104 return m_usedImgSize;
105 }
106
107 // Returns the image of the item with the given index.
108 virtual wxBitmap GetItemBitmap(unsigned int n) const;
109
110 // Sets the image for the given item.
111 virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap);
112
113 virtual void DoClear();
114 virtual void DoDeleteOneItem(unsigned int n);
115
116 protected:
117
118 virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const;
119 virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const;
120 virtual wxCoord OnMeasureItem(size_t item) const;
121 virtual wxCoord OnMeasureItemWidth(size_t item) const;
122
123 virtual int DoInsertItems(const wxArrayStringsAdapter & items,
124 unsigned int pos,
125 void **clientData, wxClientDataType type);
126
127 virtual bool SetFont(const wxFont& font);
128
129 virtual wxSize DoGetBestSize() const;
130
131 // Event handlers
132 void OnSize(wxSizeEvent& event);
133
134 // Recalculates amount of empty space needed in front of
135 // text in control itself.
136 void DetermineIndent();
137
138 bool OnAddBitmap(const wxBitmap& bitmap);
139
140 // Adds image to position - called in Append/Insert before
141 // string is added.
142 bool DoInsertBitmap(const wxBitmap& image, unsigned int pos);
143
144
145 wxArrayPtrVoid m_bitmaps; // Images associated with items
146 wxSize m_usedImgSize; // Size of bitmaps
147
148 private:
149 int m_imgAreaWidth; // Width and height of area next to text field
150 int m_fontHeight;
151 bool m_inResize;
152
153 void Init();
154 void PostCreate();
155
156 DECLARE_EVENT_TABLE()
157
158 DECLARE_DYNAMIC_CLASS(wxBitmapComboBox)
159 };
160
161 #endif // _WX_GENERIC_BMPCBOX_H_