1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/gtk/bmpcbox.h
3 // Purpose:     wxBitmapComboBox
4 // Author:      Jaakko Salli
5 // Created:     2008-05-19
6 // Copyright:   (c) 2008 Jaakko Salli
7 // Licence:     wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef _WX_GTK_BMPCBOX_H_
11 #define _WX_GTK_BMPCBOX_H_
12 
13 
14 #include "wx/combobox.h"
15 
16 // ----------------------------------------------------------------------------
17 // wxBitmapComboBox: a wxComboBox that allows images to be shown
18 // in front of string items.
19 // ----------------------------------------------------------------------------
20 
21 class WXDLLIMPEXP_ADV wxBitmapComboBox : public wxComboBox,
22                                          public wxBitmapComboBoxBase
23 {
24 public:
25     // ctors and such
wxBitmapComboBox()26     wxBitmapComboBox() : wxComboBox(), wxBitmapComboBoxBase()
27     {
28         Init();
29     }
30 
31     wxBitmapComboBox(wxWindow *parent,
32                      wxWindowID id = wxID_ANY,
33                      const wxString& value = wxEmptyString,
34                      const wxPoint& pos = wxDefaultPosition,
35                      const wxSize& size = wxDefaultSize,
36                      int n = 0,
37                      const wxString choices[] = NULL,
38                      long style = 0,
39                      const wxValidator& validator = wxDefaultValidator,
40                      const wxString& name = wxASCII_STR(wxBitmapComboBoxNameStr))
wxComboBox()41         : wxComboBox(),
42           wxBitmapComboBoxBase()
43     {
44         Init();
45 
46         (void)Create(parent, id, value, pos, size, n,
47                      choices, style, validator, name);
48     }
49 
50     wxBitmapComboBox(wxWindow *parent,
51                      wxWindowID id,
52                      const wxString& value,
53                      const wxPoint& pos,
54                      const wxSize& size,
55                      const wxArrayString& choices,
56                      long style,
57                      const wxValidator& validator = wxDefaultValidator,
58                      const wxString& name = wxASCII_STR(wxBitmapComboBoxNameStr));
59 
60     bool Create(wxWindow *parent,
61                 wxWindowID id,
62                 const wxString& value,
63                 const wxPoint& pos,
64                 const wxSize& size,
65                 int n,
66                 const wxString choices[],
67                 long style = 0,
68                 const wxValidator& validator = wxDefaultValidator,
69                 const wxString& name = wxASCII_STR(wxBitmapComboBoxNameStr));
70 
71     bool Create(wxWindow *parent,
72                 wxWindowID id,
73                 const wxString& value,
74                 const wxPoint& pos,
75                 const wxSize& size,
76                 const wxArrayString& choices,
77                 long style = 0,
78                 const wxValidator& validator = wxDefaultValidator,
79                 const wxString& name = wxASCII_STR(wxBitmapComboBoxNameStr));
80 
81     virtual ~wxBitmapComboBox();
82 
83     // Sets the image for the given item.
84     virtual void SetItemBitmap(unsigned int n, const wxBitmap& bitmap) wxOVERRIDE;
85 
86     // Returns the image of the item with the given index.
87     virtual wxBitmap GetItemBitmap(unsigned int n) const wxOVERRIDE;
88 
89     // Returns size of the image used in list
GetBitmapSize()90     virtual wxSize GetBitmapSize() const wxOVERRIDE
91     {
92         return m_bitmapSize;
93     }
94 
95     // Adds item with image to the end of the combo box.
96     int Append(const wxString& item, const wxBitmap& bitmap = wxNullBitmap);
97     int Append(const wxString& item, const wxBitmap& bitmap, void *clientData);
98     int Append(const wxString& item, const wxBitmap& bitmap, wxClientData *clientData);
99 
100     // Inserts item with image into the list before pos. Not valid for wxCB_SORT
101     // styles, use Append instead.
102     int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos);
103     int Insert(const wxString& item, const wxBitmap& bitmap,
104                unsigned int pos, void *clientData);
105     int Insert(const wxString& item, const wxBitmap& bitmap,
106                unsigned int pos, wxClientData *clientData);
107 
108     // Override some wxTextEntry interface.
109     virtual void WriteText(const wxString& value) wxOVERRIDE;
110 
111     virtual wxString GetValue() const wxOVERRIDE;
112     virtual void Remove(long from, long to) wxOVERRIDE;
113 
114     virtual void SetInsertionPoint(long pos) wxOVERRIDE;
115     virtual long GetInsertionPoint() const wxOVERRIDE;
116     virtual long GetLastPosition() const wxOVERRIDE;
117 
118     virtual void SetSelection(long from, long to) wxOVERRIDE;
119     virtual void GetSelection(long *from, long *to) const wxOVERRIDE;
120 
SetSelection(int n)121     virtual void SetSelection(int n) wxOVERRIDE { wxComboBox::SetSelection(n); }
GetSelection()122     virtual int GetSelection() const wxOVERRIDE { return wxComboBox::GetSelection(); }
123 
124     virtual bool IsEditable() const wxOVERRIDE;
125     virtual void SetEditable(bool editable) wxOVERRIDE;
126 
127     virtual GtkWidget* GetConnectWidget() wxOVERRIDE;
128 
129 protected:
130     virtual GdkWindow *GTKGetWindow(wxArrayGdkWindows& windows) const wxOVERRIDE;
131 
132     virtual void GTKCreateComboBoxWidget() wxOVERRIDE;
133     virtual void GTKInsertComboBoxTextItem( unsigned int n, const wxString& text ) wxOVERRIDE;
134 
135     virtual wxSize DoGetBestSize() const wxOVERRIDE;
136 
137     wxSize                  m_bitmapSize;
138     int                     m_bitmapCellIndex;
139 
140 private:
141     void Init();
142 
143     wxDECLARE_DYNAMIC_CLASS(wxBitmapComboBox);
144 };
145 
146 #endif // _WX_GTK_BMPCBOX_H_
147