| 1 |
#include "BitmapComboxWrapper.h" |
| 2 |
|
| 3 |
#include "BitmapTextArrayProperty.h" |
| 4 |
#include "BmpTextSelectorDlg.h" |
| 5 |
#include "allocator_mgr.h" |
| 6 |
#include "wxc_bitmap_code_generator.h" |
| 7 |
#include "wxgui_defs.h" |
| 8 |
#include "wxgui_helpers.h" |
| 9 |
|
| 10 |
BitmapComboxWrapper::BitmapComboxWrapper() |
| 11 |
: wxcWidget(ID_WXBITMAPCOMBOBOX) |
| 12 |
{ |
| 13 |
SetPropertyString(_("Common Settings"), "wxBitmapComboBox"); |
| 14 |
AddProperty(new BitmapTextArrayProperty(PROP_CB_CHOICES, "", _("Combobox drop down choices"))); |
| 15 |
AddProperty(new StringProperty( |
| 16 |
PROP_SELECTION, "-1", |
| 17 |
_("The zero-based position of any initially selected string, or -1 if none are to be selected"))); |
| 18 |
AddProperty(new StringProperty(PROP_VALUE, "", _("The combobox initial value"))); |
| 19 |
|
| 20 |
RegisterEventCommand("wxEVT_COMMAND_COMBOBOX_SELECTED", |
| 21 |
_("Process a wxEVT_COMMAND_COMBOBOX_SELECTED event, when an item on the list is selected. " |
| 22 |
"Note that calling GetValue returns the new value of selection.")); |
| 23 |
RegisterEventCommand("wxEVT_COMMAND_TEXT_UPDATED", |
| 24 |
_("Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text changes.")); |
| 25 |
RegisterEventCommand("wxEVT_COMMAND_TEXT_ENTER", |
| 26 |
_("Process a wxEVT_COMMAND_TEXT_ENTER event, when <RETURN> is pressed in the combobox.")); |
| 27 |
|
| 28 |
PREPEND_STYLE(wxCB_READONLY, false); |
| 29 |
PREPEND_STYLE(wxCB_SORT, false); |
| 30 |
PREPEND_STYLE(wxTE_PROCESS_ENTER, false); |
| 31 |
|
| 32 |
m_namePattern = "m_bmpComboBox"; |
| 33 |
SetName(GenerateName()); |
| 34 |
} |
| 35 |
|
| 36 |
BitmapComboxWrapper::~BitmapComboxWrapper() {} |
| 37 |
|
| 38 |
wxcWidget* BitmapComboxWrapper::Clone() const { return new BitmapComboxWrapper(); } |
| 39 |
|
| 40 |
wxString BitmapComboxWrapper::CppCtorCode() const |
| 41 |
{ |
| 42 |
wxArrayString labels, bitmaps; |
| 43 |
wxString options = PropertyString(PROP_CB_CHOICES); |
| 44 |
BmpTextVec_t arr = BmpTextSelectorDlg::FromString(options); |
| 45 |
for(size_t i = 0; i < arr.size(); ++i) { |
| 46 |
wxcCodeGeneratorHelper::Get().AddBitmap(arr.at(i).first); |
| 47 |
bitmaps.Add(wxcCodeGeneratorHelper::Get().BitmapCode(arr.at(i).first)); |
| 48 |
labels.Add(arr.at(i).second); |
| 49 |
} |
| 50 |
wxString code; |
| 51 |
code << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << WindowID() |
| 52 |
<< ", wxEmptyString" |
| 53 |
<< ", wxDefaultPosition, " << SizeAsString() << ", wxArrayString(), " << StyleFlags("0") << ");\n"; |
| 54 |
|
| 55 |
// Append the items |
| 56 |
for(size_t i = 0; i < labels.GetCount(); ++i) { |
| 57 |
code << GetName() << "->Append(" << wxCrafter::UNDERSCORE(labels.Item(i)) << ", " << bitmaps.Item(i) << ");\n"; |
| 58 |
} |
| 59 |
int sel = PropertyInt(PROP_SELECTION); |
| 60 |
if(sel != wxNOT_FOUND && sel < (int)labels.GetCount()) { |
| 61 |
code << GetName() << "->SetSelection(" << sel << ");\n"; |
| 62 |
} |
| 63 |
return code; |
| 64 |
} |
| 65 |
|
| 66 |
void BitmapComboxWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add("#include <wx/bmpcbox.h>"); } |
| 67 |
|
| 68 |
wxString BitmapComboxWrapper::GetWxClassName() const { return "wxBitmapComboBox"; } |
| 69 |
|
| 70 |
void BitmapComboxWrapper::LoadPropertiesFromXRC(const wxXmlNode* node) { wxUnusedVar(node); } |
| 71 |
void BitmapComboxWrapper::LoadPropertiesFromwxFB(const wxXmlNode* node) { wxUnusedVar(node); } |
| 72 |
void BitmapComboxWrapper::LoadPropertiesFromwxSmith(const wxXmlNode* node) { wxUnusedVar(node); } |
| 73 |
|
| 74 |
void BitmapComboxWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 75 |
{ |
| 76 |
wxString options = PropertyString(PROP_CB_CHOICES); |
| 77 |
text << XRCPrefix() << XRCStyle() << XRCSize() << XRCCommonAttributes(); |
| 78 |
BmpTextVec_t arr = BmpTextSelectorDlg::FromString(options); |
| 79 |
for(size_t i = 0; i < arr.size(); ++i) { |
| 80 |
text << "<object class=\"ownerdrawnitem\">"; |
| 81 |
text << "<text>" << wxCrafter::CDATA(arr.at(i).second) << "</text>"; |
| 82 |
text << XRCBitmap("bitmap", arr.at(i).first); |
| 83 |
text << "</object>"; |
| 84 |
} |
| 85 |
|
| 86 |
if(!HasStyle(wxCB_READONLY) && !PropertyString(PROP_HINT).empty()) { |
| 87 |
// set hint for non-readonly combobox |
| 88 |
text << "<hint>" << wxCrafter::CDATA(PropertyString(PROP_HINT)) << "</hint>"; |
| 89 |
} |
| 90 |
text << XRCSelection() << XRCSuffix(); |
| 91 |
} |