| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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 |
|
| 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 |
|
| 56 |
wxBmpComboBox(wxWindow *parent, wxWindowID id, |
| 57 |
const wxString& value = wxEmptyString, |
| 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 |
|
| 81 |
|
| 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 |
|
| 107 |
bool SetButtonStyle(long style); |
| 108 |
|
| 109 |
|
| 110 |
int Append( const wxString &label, const wxBitmap &bitmap); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos); |
| 115 |
|
| 116 |
|
| 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 |
|
| 139 |
void Freeze() { m_frozen = true; } |
| 140 |
void Thaw(); |
| 141 |
|
| 142 |
|
| 143 |
wxBmpComboLabel* GetLabelWindow() { return m_labelWin; } |
| 144 |
|
| 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; |
| 165 |
wxArrayString m_labels; |
| 166 |
|
| 167 |
wxSize m_labelSize; |
| 168 |
wxSize m_bitmapSize; |
| 169 |
wxSize m_itemSize; |
| 170 |
|
| 171 |
int m_selection; |
| 172 |
int m_win_border; |
| 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 |
|
| 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 |
|
| 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 |
| 226 |
|
| 227 |
#endif |