16
15
* You should have received a copy of the GNU General Public License
17
16
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
21
#include <wx/bmpcbox.h>
24
#include <wx/bmpbuttn.h>
22
25
#include "wxsbitmapcombobox.h"
23
#include "wxsimagelist.h"
24
#include "../properties/wxsimagelistdlg.h"
28
//------------------------------------------------------------------------------
29
wxsRegisterItem<wxsBitmapComboBox> Reg(_T("BitmapComboBox"), wxsTWidget, _T("Standard"), 350);
32
WXS_ST_BEGIN(wxsBitmapComboBoxStyles, wxEmptyString)
33
WXS_ST_CATEGORY("wxBitmapComboBox")
36
WXS_ST(wxTE_PROCESS_ENTER)
35
wxsRegisterItem<wxsBitmapComboBox> Reg(_T("BitmapComboBox"),wxsTWidget,_T("Standard"),50);
36
// wxsRegisterItem<wxsBitmapComboBox> Reg(
37
// _T("wxBitmapComboBox"), // Class name
38
// wxsTWidget, // Item type
39
// _T("wxWindows"), // License
40
// _T("Ron Collins"), // Author
41
// _T("rcoll@theriver.com"), // Author's email
42
// _T(""), // Item's homepage
43
// _T("Standard"), // Category in palette
44
// 50, // Priority in palette
45
// _T("ComboBox"), // Base part of names for new items
46
// wxsCPP, // List of coding languages supported by this item
48
// _T("wxBitmapCombo32.png"), // 32x32 bitmap
49
// _T("wxBitmapCombo16.png"), // 16x16 bitmap
50
// false); // We do not allow this item inside XRC files
53
WXS_ST_BEGIN(wxsBitmapComboBoxStyles,_T("wxBU_AUTODRAW"))
54
WXS_ST_CATEGORY("wxBitmapComboBox")
59
WXS_ST(wxTE_PROCESS_ENTER)
40
64
WXS_EV_BEGIN(wxsBitmapComboBoxEvents)
41
WXS_EVI(EVT_COMBOBOX, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEvent, Selected)
42
WXS_EVI(EVT_TEXT, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEvent, TextUpdated)
43
WXS_EVI(EVT_TEXT_ENTER, wxEVT_COMMAND_TEXT_ENTER, wxCommandEvent, TextEnter)
65
WXS_EVI(EVT_COMBOBOX,wxEVT_COMMAND_COMBOBOX_SELECTED,wxCommandEvent,Select)
66
WXS_EVI(EVT_TEXT,wxEVT_COMMAND_TEXT_UPDATED,wxCommandEvent,Text)
67
WXS_EVI(EVT_TEXT_ENTER,wxEVT_COMMAND_TEXT_ENTER,wxCommandEvent,TextEnter)
49
* \param Data wxsItemResData* The control's resource data.
52
wxsBitmapComboBox::wxsBitmapComboBox(wxsItemResData *Data):
71
//------------------------------------------------------------------------------
73
wxsBitmapComboBox::wxsBitmapComboBox(wxsItemResData* Data):
56
77
wxsBitmapComboBoxEvents,
57
wxsBitmapComboBoxStyles),
58
m_defaultSelection(-1)
62
/*! \brief Create the initial control.
67
void wxsBitmapComboBox::OnBuildCreatingCode()
73
AddHeader(_T("<wx/bmpcbox.h>"), GetInfo().ClassName, hfInPCH);
74
Codef(_T("%C(%W, %I, wxEmptyString, %P, %S, 0, 0, %T, %V, %N);\n"));
76
for(size_t i = 0; i < m_arrChoices.GetCount(); ++i)
78
if(m_defaultSelection == (int)i)
80
Codef(_T("%ASetSelection( "));
82
#if wxCHECK_VERSION(2, 9, 0)
83
Codef(_T("%AAppend(%t)"), m_arrChoices[i].wx_str());
85
Codef(_T("%AAppend(%t)"), m_arrChoices[i].c_str());
87
if(m_defaultSelection == (int)i)
94
// Find the image list.
95
wxsImageList *imageList = (wxsImageList *) wxsImageListDlg::FindTool(this, m_sImageList);
96
int iItemcount = m_arrChoices.GetCount();
98
wxString vv = GetVarName();
101
wxString ss = imageList->GetVarName();
102
int iImgCount = imageList->GetCount();
104
AddEventCode(_("\n"));
106
for(int i = 0;i < iImgCount;i++){
107
// Keep within the size limits of the combo box.
111
#if wxCHECK_VERSION(2, 9, 0)
112
tt.Printf(_("%s->SetItemBitmap(%d, %s->GetBitmap(%d));\n"), vv.wx_str(), i, ss.wx_str(), i);
114
tt.Printf(_("%s->SetItemBitmap(%d, %s->GetBitmap(%d));\n"), vv.c_str(), i, ss.c_str(), i);
116
// add all the bitmaps at the bottom of the code... after the wxsImage's and wxsImageList's have been coded
120
AddEventCode(_("\n"));
124
BuildSetupWindowCode();
130
wxsCodeMarks::Unknown(_T("wxsBitmapComboBox::OnBuildCreatingCode"), GetLanguage());
135
/*! \brief Build the control preview.
137
* \param parent wxWindow* The parent window.
138
* \param flags long The control flags.
139
* \return wxObject* The constructed control.
142
wxObject *wxsBitmapComboBox::OnBuildPreview(wxWindow *Parent, long Flags)
144
wxBitmapComboBox *preview = new wxBitmapComboBox(Parent, GetId(), wxEmptyString, Pos(Parent), Size(Parent), m_arrChoices, Style());
146
// Find the image list.
147
wxsImageList *imageList = (wxsImageList *) wxsImageListDlg::FindTool(this, m_sImageList);
149
int count = preview->GetCount();
151
for(int i = 0;i < imageList->GetCount();i++){
152
// Keep within the size limits of the combo box.
156
// SetItemBitmap() uses an unsigned int.
157
preview->SetItemBitmap((unsigned)i, imageList->GetPreview(i));
161
if(m_defaultSelection != -1){
162
preview->SetSelection(m_defaultSelection);
165
return SetupWindow(preview, Flags);
168
/*! \brief Enumerate the control's properties.
170
* \param flags long The control flags.
174
void wxsBitmapComboBox::OnEnumWidgetProperties(long Flags)
176
WXS_ARRAYSTRING(wxsBitmapComboBox, m_arrChoices, _("Choices"), _T("content"), _T("item"))
177
WXS_LONG(wxsBitmapComboBox, m_defaultSelection, _("Selection"), _T("selection"), -1)
179
static const wxChar *pImageNames[128];
180
static long iImageNames[128];
182
wxsItemResData *resData;
185
wxsImageList *imageList;
186
static const wxString sNone(_("<none>"));
188
// find available images, and pointer to current imagelist
190
resData = GetResourceData();
192
m_arrImageListNames[n] = sNone;
193
pImageNames[n] = (const wxChar *) m_arrImageListNames[n];
195
iResCount = resData->GetToolsCount();
196
for(i = 0;i < iResCount;i++){
197
tool = resData->GetTool(i);
198
s = tool->GetUserClass();
200
if((s == _T("wxImageList")) && (n < 127)){
201
s = tool->GetVarName();
202
m_arrImageListNames[n] = s;
203
pImageNames[n] = (const wxChar *) m_arrImageListNames[n];
207
if(s == m_sImageList){
208
imageList = (wxsImageList *) tool;
78
wxsBitmapComboBoxStyles)
85
mImageList = _("<none>");
90
//------------------------------------------------------------------------------
92
void wxsBitmapComboBox::OnBuildCreatingCode() {
97
// we only handle C++ constructs here
99
if (GetLanguage() != wxsCPP) wxsCodeMarks::Unknown(_T("wxsBitmapComboBox"),GetLanguage());
103
AddHeader(_T("<wx/bmpcbox.h>"),GetInfo().ClassName,hfInPCH);
105
// the basic constructor
108
Codef(_T("%C(%W, %I, wxEmptyString, %P, %S, 0, NULL, %T, %V, %N);\n"));
110
// was a valid image-list specified?
112
ilist = (wxsImageListEditorDlg::FindTool(this, mImageList) != NULL);
114
// add all text items, and the bitmaps at the bottom of the code
115
// bitmaps have to added after the wxsImages' and wxsImageList's were added
116
// note: first 2 items in mItems are used only in the dialog
118
for(i=2; i<mItems.GetCount(); i++) {
120
ParseComboItem(ss, tt, n);
124
Codef(_T("%s->Append(_T(\"%s\"));\n"), vv.c_str(), tt.c_str());
126
// add the bitmap at the bottom of the code
128
if ((ilist) && (n >= 0)) {
129
tt.Printf(_T("%s->SetItemBitmap(%d, %s->GetBitmap(%d));\n"), vv.c_str(), i-2, mImageList.c_str(), n);
134
AddEventCode(_T("\n"));
138
BuildSetupWindowCode();
142
//------------------------------------------------------------------------------
144
wxObject* wxsBitmapComboBox::OnBuildPreview(wxWindow* Parent,long Flags) {
146
wxBitmapComboBox *combo;
153
combo = new wxBitmapComboBox(Parent, GetId(), _T(""), Pos(Parent),Size(Parent),0, NULL, Style());
155
// a valid image-list specified?
157
ilist = (wxsImageList *) wxsImageListEditorDlg::FindTool(this, mImageList);
159
// make sure there is no random junk
163
// add items to combo-box
164
// note: first 2 items are used only in the dialog
166
for(i=2; i<mItems.GetCount(); i++) {
168
ParseComboItem(ss, tt, n);
172
if ((ilist != NULL) && (n >= 0)) combo->SetItemBitmap(i-2, ilist->GetPreview(n));
177
return SetupWindow(combo, Flags);
180
//------------------------------------------------------------------------------
182
void wxsBitmapComboBox::OnEnumWidgetProperties(long Flags) {
183
static wxString sImageNames[128];
184
static const wxChar *pImageNames[128];
190
// find available image lists and store them in our local static arrays
192
FindAllImageLists(aa);
194
if (n > 127) n = 127;
199
pImageNames[i] = (const wxChar *) sImageNames[i];
212
201
pImageNames[n] = NULL;
213
WXS_EDITENUM(wxsBitmapComboBox, m_sImageList, _("Image List"), _T("image_list"), pImageNames, sNone)
203
WXS_EDITENUM(wxsBitmapComboBox, mImageList, _("Image List"), _("mImageList"), pImageNames, _("<none>"))
205
// the list of items to appear in the combo box
207
UpdateComboItemList();
209
WXS_IMAGECOMBO(wxsBitmapComboBox, mItems, _("Combo Items"), _("mItems"));
210
WXS_ARRAYSTRING(wxsBitmapComboBox, mItems, _("Items as Text"), _("mItemsText"), _("item2"));
213
//------------------------------------------------------------------------------
214
// find all tools that are image lists and return their names
216
void wxsBitmapComboBox::FindAllImageLists(wxArrayString &aNames) {
223
// start the list with a chance to de-select any old list
226
aNames.Add(_("<none>"));
228
// find all tools that are "wxImageList"
230
res = GetResourceData();
231
n = res->GetToolsCount();
233
tool = res->GetTool(i);
234
ss = tool->GetUserClass();
236
if ((ss == _("wxImageList")) && (n < 127)) {
237
ss = tool->GetVarName();
243
//------------------------------------------------------------------------------
244
// update the list of combo items to send to the wsxImageComboEditDialog
246
void wxsBitmapComboBox::UpdateComboItemList(void) {
251
// first 2 items are always our var name and the name of the image list
259
// then copy over everything else the user entered last time
261
n = mItems.GetCount();
267
// then put back in original list
276
// make sure that FindTool has a valid wxsItem* to work from in the dialog
278
wxsImageListEditorDlg::FindTool(this, mImageList);
281
//------------------------------------------------------------------------------
283
void wxsBitmapComboBox::ParseComboItem(wxString inSource, wxString &outItem, int &outIndex) {
292
// a "," separates the image index from the text of the item
296
// if a "," was found, parse the index from the text
297
// if no ",", then no index and the entire string is text
299
if (i != wxNOT_FOUND) {
304
if (tt.ToLong(&ll)) outIndex = ll;