Debian Codegraph @

3rdparty/wxThings/wx/things/bmpcombo.h

raw symbols SCIP
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxBmpComboBox
3 // Purpose: A wxComboBox type button for bitmaps and strings
4 // Author: John Labenski
5 // Modified by:
6 // Created: 11/05/2002
7 // Copyright: (c) John Labenski
8 // Licence: wxWidgets licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 /*
12
13 wxBmpComboBox is a wxComboBox widget for bitmaps
14
15 You Append some bitmaps either individually or with an array. Since bitmaps are
16 refed this should be a fast process and you don't have to keep them around.
17 The size of the items is calculated from the max bitmap and max label so that
18 they will all line up nicely.
19
20 It acts just like a wxComboBox otherwise, sends a EVT_COMBOBOX when selections
21 are made with either the mouse on the pulldown list or by pressing the up/down
22 arrows.
23
24 */
25
26 #ifndef _WX_BMPCOMBO_H_
27 #define _WX_BMPCOMBO_H_
28
29 #include "wx/things/thingdef.h"
30 #include "wx/things/dropdown.h"
31
32 #if wxUSE_POPUPWIN
33
34 class WXDLLEXPORT wxMenu;
35 class WXDLLEXPORT wxBitmap;
36 class WXDLLEXPORT wxKeyEvent;
37 class WXDLLEXPORT wxPaintEvent;
38 class WXDLLEXPORT wxDC;
39 class WXDLLIMPEXP_THINGS wxCustomButton;
40 class WXDLLIMPEXP_THINGS wxBmpComboPopupChild;
41 class WXDLLIMPEXP_THINGS wxBmpComboLabel;
42
43 enum wxBmpComboBox_Style
44 {
45 // Position of the labels relative to the bitmaps, use only one
46 wxBMPCOMBO_LEFT = wxCB_DROPDOWN,
47 wxBMPCOMBO_RIGHT = wxCB_SIMPLE
48 };
49
50 class WXDLLIMPEXP_THINGS wxBmpComboBox : public DropDownBase
51 {
52 public:
53 wxBmpComboBox() : DropDownBase() { Init(); }
54
55 // Compatible with a wxComboBox, uses strings only
56 wxBmpComboBox(wxWindow *parent, wxWindowID id,
57 const wxString& value = wxEmptyString, // used only if first choice is !null
58 const wxPoint& pos = wxDefaultPosition,
59 const wxSize& size = wxDefaultSize,
60 int n = 0, const wxString choices[] = (const wxString *) nullptr,
61 long style = wxBMPCOMBO_RIGHT,
62 const wxValidator& val = wxDefaultValidator,
63 const wxString& name = wxT("wxBmpComboBox"))
64 :DropDownBase()
65 {
66 Init();
67 if ((n > 0) || (!value.IsEmpty()))
68 {
69 if ((n > 0) && choices)
70 {
71 for (int i=0; i<n; i++)
72 Append(choices[i], wxNullBitmap);
73 }
74 else
75 Append(value, wxNullBitmap);
76 }
77 Create(parent, id, pos, size, style, val, name);
78 }
79
80 // Native constructor (only adds first item) you probably want to
81 // use the largest item first so that the size is correct from the start.
82 wxBmpComboBox(wxWindow* parent, wxWindowID id,
83 const wxString& label,
84 const wxBitmap& bitmap,
85 const wxPoint& pos = wxDefaultPosition,
86 const wxSize& size = wxDefaultSize,
87 long style = wxBMPCOMBO_RIGHT,
88 const wxValidator& val = wxDefaultValidator,
89 const wxString& name = wxT("wxBmpComboBox"))
90 :DropDownBase()
91 {
92 Init();
93 Append(label, bitmap);
94 Create(parent, id, pos, size, style, val, name);
95 }
96
97 virtual ~wxBmpComboBox();
98
99 bool Create(wxWindow* parent, wxWindowID id,
100 const wxPoint& pos = wxDefaultPosition,
101 const wxSize& size = wxDefaultSize,
102 long style = wxBMPCOMBO_RIGHT,
103 const wxValidator& val = wxDefaultValidator,
104 const wxString& name = wxT("wxBmpComboBox"));
105
106 // Style is either wxBMPCOMBO_LEFT or wxBMPCOMBO_RIGHT
107 bool SetButtonStyle(long style);
108
109 // Append/Insert an item, either label and bitmap may be empty/null
110 int Append( const wxString &label, const wxBitmap &bitmap);
111
112 // Inserts item with image into the list before pos. Not valid for wxCB_SORT or wxCB_SORT
113 // styles, use Append instead.
114 int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos);
115
116 // Clear or delete a single or number of items starting from n
117 void Clear();
118 void Delete( unsigned int n, unsigned int count = 1 );
119
120 int GetCount() const { return m_labels.GetCount(); }
121
122 int GetSelection() const { return m_selection; }
123 void SetSelection( int n, bool send_event = false );
124 void SetNextSelection(bool foward, bool send_event = false);
125
126 wxString GetLabel( int n ) const;
127 wxBitmap GetItemBitmap( int n ) const;
128
129 void SetItemBitmap(int n, const wxBitmap &bitmap);
130 void SetLabel(int n, const wxString &label);
131 void SetItem(int n, const wxString &label, const wxBitmap &bitmap)
132 { SetLabel(n, label); SetItemBitmap(n, bitmap); }
133
134 virtual bool SetBackgroundColour(const wxColour &colour);
135
136 virtual void HidePopup();
137
138 // When adding/deleting many items freeze it and thaw when done
139 void Freeze() { m_frozen = true; }
140 void Thaw();
141
142 // implementation
143 wxBmpComboLabel* GetLabelWindow() { return m_labelWin; }
144 // Get the largest label, bitmap, item=(label+bitmap) size
145 wxSize GetLabelSize() const { return m_labelSize; }
146 wxSize GetBitmapSize() const { return m_bitmapSize; }
147 wxSize GetItemSize() const { return m_itemSize; }
148 void CalcLabelBitmapPos(int n, const wxSize &area, wxPoint &labelPos, wxPoint &bitmapPos) const;
149 void CalcLayout();
150 void DrawItem(wxDC &dc, int n) const;
151
152 protected:
153 virtual void DoSetSize(int x, int y, int width, int height,
154 int sizeFlags = wxSIZE_AUTO);
155
156 void OnSize( wxSizeEvent& event );
157 virtual wxSize DoGetBestSize() const;
158
159 virtual int DoGetBestDropHeight(int max_height);
160 virtual bool DoShowPopup();
161
162 wxBmpComboLabel *m_labelWin;
163
164 wxArrayPtrVoid m_bitmaps; // the individual bitmaps
165 wxArrayString m_labels; // the individual labels
166
167 wxSize m_labelSize; // the max size of all the labels
168 wxSize m_bitmapSize; // the max size of all the bitmaps
169 wxSize m_itemSize; // the max size of all the items
170
171 int m_selection;
172 int m_win_border; // the wxSUNKEN_BORDER size
173 long m_label_style;
174 bool m_frozen;
175
176 private:
177 void Init();
178 DECLARE_DYNAMIC_CLASS(wxBmpComboBox)
179 DECLARE_EVENT_TABLE()
180 };
181
182 // ==========================================================================
183 // wxBmpComboLabel - the main "window" to the left of the dropdown button
184 // ==========================================================================
185 class WXDLLIMPEXP_THINGS wxBmpComboLabel : public wxWindow
186 {
187 public:
188 wxBmpComboLabel(wxBmpComboBox *parent = nullptr, int style = wxSUNKEN_BORDER)
189 : wxWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, style),
190 m_bmpCombo(parent) {}
191
192 protected:
193 void OnPaint( wxPaintEvent &event );
194 void OnChar( wxKeyEvent &event );
195
196 wxBmpComboBox *m_bmpCombo;
197 private:
198 DECLARE_ABSTRACT_CLASS(wxBmpComboLabel)
199 DECLARE_EVENT_TABLE()
200 };
201
202 // ============================================================================
203 // wxBmpComboPopupChild - the child of the popup window
204 // ============================================================================
205
206 class WXDLLIMPEXP_THINGS wxBmpComboPopupChild : public wxScrolledWindow
207 {
208 public:
209 wxBmpComboPopupChild(wxWindow *parent, wxBmpComboBox *owner);
210
211 void DrawSelection( int n, wxDC& dc );
212
213 void OnMouse( wxMouseEvent &event );
214 void OnPaint( wxPaintEvent &event );
215 void OnKeyDown( wxKeyEvent &event );
216
217 wxBmpComboBox *m_bmpCombo;
218 int m_last_selection;
219
220 private:
221 DECLARE_ABSTRACT_CLASS(wxBmpComboPopupChild)
222 DECLARE_EVENT_TABLE()
223 };
224
225 #endif // wxUSE_POPUPWIN
226
227 #endif // _WX_BMPCOMBO_H_