| 1 |
#include "spin_ctrl_wrapper.h" |
| 2 |
|
| 3 |
#include "allocator_mgr.h" |
| 4 |
#include "string_property.h" |
| 5 |
#include "wxgui_defs.h" |
| 6 |
#include "wxgui_helpers.h" |
| 7 |
#include "xmlutils.h" |
| 8 |
|
| 9 |
#include <wx/spinctrl.h> |
| 10 |
|
| 11 |
SpinCtrlWrapper::SpinCtrlWrapper() |
| 12 |
: SpinWrapperBase(ID_WXSPINCTRL) |
| 13 |
{ |
| 14 |
PREPEND_STYLE_TRUE(wxSP_ARROW_KEYS); |
| 15 |
PREPEND_STYLE_FALSE(wxSP_WRAP); |
| 16 |
|
| 17 |
RegisterEvent(wxT("wxEVT_SPINCTRL"), wxT("wxSpinEvent"), |
| 18 |
_("Generated whenever the numeric value of the spinctrl is updated")); |
| 19 |
RegisterEventCommand(wxT("wxEVT_COMMAND_TEXT_UPDATED"), |
| 20 |
_("Process a wxEVT_COMMAND_TEXT_UPDATED event, when the combobox text changes.")); |
| 21 |
|
| 22 |
SetPropertyString(_("Common Settings"), "wxSpinCtrl"); |
| 23 |
AddProperty(new StringProperty(PROP_VALUE, wxT("0"), _("The initial value"))); |
| 24 |
AddProperty(new StringProperty(PROP_MINVALUE, wxT("0"), _("Minimal value"))); |
| 25 |
AddProperty(new StringProperty(PROP_MAXVALUE, wxT("100"), _("Maximal value"))); |
| 26 |
|
| 27 |
m_namePattern = wxT("m_spinCtrl"); |
| 28 |
SetName(GenerateName()); |
| 29 |
} |
| 30 |
|
| 31 |
SpinCtrlWrapper::~SpinCtrlWrapper() {} |
| 32 |
|
| 33 |
wxcWidget* SpinCtrlWrapper::Clone() const { return new SpinCtrlWrapper(); } |
| 34 |
|
| 35 |
wxString SpinCtrlWrapper::CppCtorCode() const |
| 36 |
{ |
| 37 |
wxString code; |
| 38 |
wxString min, max; |
| 39 |
int imin, imax, val; |
| 40 |
EnsureSaneValues(min, max, imin, imax, val); |
| 41 |
|
| 42 |
code << CPPStandardWxCtorWithValue(wxT("wxSP_ARROW_KEYS")); |
| 43 |
code << GetName() << wxT("->SetRange(") << min << wxT(", ") << max << wxT(");\n"); |
| 44 |
// Set the value again now the range has been set: a value >100 (the default max) would previously have been |
| 45 |
// rejected |
| 46 |
code << GetName() << wxT("->SetValue(") << val << wxT(");\n"); |
| 47 |
return code; |
| 48 |
} |
| 49 |
|
| 50 |
void SpinCtrlWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add(wxT("#include <wx/spinctrl.h>")); } |
| 51 |
|
| 52 |
wxString SpinCtrlWrapper::GetWxClassName() const { return wxT("wxSpinCtrl"); } |
| 53 |
|
| 54 |
void SpinCtrlWrapper::ToXRC(wxString& text, XRC_TYPE type) const |
| 55 |
{ |
| 56 |
wxString min, max; |
| 57 |
int imin, imax, val; |
| 58 |
EnsureSaneValues(min, max, imin, imax, val); |
| 59 |
|
| 60 |
// build the xrc prefix. notice that we don't use the "subclass" property |
| 61 |
// see: https://github.com/eranif/codelite/issues/3054 |
| 62 |
wxString xrc_prefix; |
| 63 |
xrc_prefix << "<object class=\"" << GetWxClassName() << "\" name=\"" << wxCrafter::XMLEncode(GetName()) << "\">"; |
| 64 |
|
| 65 |
text << xrc_prefix << XRCStyle() << XRCSize() << XRCCommonAttributes() << wxT("<value>") |
| 66 |
<< wxCrafter::XMLEncode(wxCrafter::ToString(val)) << wxT("</value>") << wxT("<min>") |
| 67 |
<< wxCrafter::XMLEncode(min) << wxT("</min>") << wxT("<max>") << wxCrafter::XMLEncode(max) << wxT("</max>") |
| 68 |
<< XRCSuffix(); |
| 69 |
} |