| 1 |
#include "spin_wrapper_base.h" |
| 2 |
#include "wxgui_helpers.h" |
| 3 |
#include "xmlutils.h" |
| 4 |
|
| 5 |
SpinWrapperBase::SpinWrapperBase(int ID) |
| 6 |
: wxcWidget(ID) |
| 7 |
{ |
| 8 |
} |
| 9 |
|
| 10 |
SpinWrapperBase::~SpinWrapperBase() {} |
| 11 |
|
| 12 |
void SpinWrapperBase::EnsureSaneValues(wxString& min, wxString& max, int& imin, int& imax, int& val) const |
| 13 |
{ |
| 14 |
// Protect against empty range fields, which would otherwise generate code like spin->SetRange(0, ); |
| 15 |
// Also against max < min, which annoys gtk so much it throws its toys out of the pram and segfaults |
| 16 |
min = PropertyString(PROP_MINVALUE); |
| 17 |
if(min.empty()) { min = "0"; } |
| 18 |
max = PropertyString(PROP_MAXVALUE); |
| 19 |
if(max.empty()) { max = "100"; } |
| 20 |
imin = wxCrafter::ToNumber(min, 0); |
| 21 |
imax = wxCrafter::ToNumber(max, 100); |
| 22 |
if(imax < imin) { |
| 23 |
imax = imin + 100; // Well, why not? |
| 24 |
max = wxCrafter::ToString(imax); |
| 25 |
} |
| 26 |
// For 'value', ensure it's in range, otherwise gtk will be unhappy |
| 27 |
val = PropertyInt(PROP_VALUE); |
| 28 |
if(val < imin) { |
| 29 |
val = imin; |
| 30 |
} else if(val > imax) { |
| 31 |
val = imax; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
void SpinWrapperBase::LoadPropertiesFromXRC(const wxXmlNode* node) |
| 36 |
{ |
| 37 |
// First call the base-class for the standard things |
| 38 |
wxcWidget::LoadPropertiesFromXRC(node); |
| 39 |
|
| 40 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("min")); |
| 41 |
if(propertynode) { SetPropertyString(PROP_MINVALUE, propertynode->GetNodeContent()); } |
| 42 |
|
| 43 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("max")); |
| 44 |
if(propertynode) { SetPropertyString(PROP_MAXVALUE, propertynode->GetNodeContent()); } |
| 45 |
|
| 46 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("value")); |
| 47 |
if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); } |
| 48 |
} |
| 49 |
|
| 50 |
void SpinWrapperBase::LoadPropertiesFromwxSmith(const wxXmlNode* node) |
| 51 |
{ |
| 52 |
// First call the base-class for the standard things |
| 53 |
wxcWidget::LoadPropertiesFromwxSmith(node); |
| 54 |
|
| 55 |
wxXmlNode* propertynode = XmlUtils::FindFirstByTagName(node, wxT("min")); |
| 56 |
if(propertynode) { SetPropertyString(PROP_MINVALUE, propertynode->GetNodeContent()); } |
| 57 |
|
| 58 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("max")); |
| 59 |
if(propertynode) { SetPropertyString(PROP_MAXVALUE, propertynode->GetNodeContent()); } |
| 60 |
|
| 61 |
propertynode = XmlUtils::FindFirstByTagName(node, wxT("value")); |
| 62 |
if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); } |
| 63 |
} |
| 64 |
|
| 65 |
void SpinWrapperBase::LoadPropertiesFromwxFB(const wxXmlNode* node) |
| 66 |
{ |
| 67 |
// First call the base-class for the standard things |
| 68 |
wxcWidget::LoadPropertiesFromwxFB(node); |
| 69 |
|
| 70 |
wxXmlNode* propertynode = XmlUtils::FindNodeByName(node, "property", "min"); |
| 71 |
if(propertynode) { SetPropertyString(PROP_MINVALUE, propertynode->GetNodeContent()); } |
| 72 |
|
| 73 |
propertynode = XmlUtils::FindNodeByName(node, "property", "max"); |
| 74 |
if(propertynode) { SetPropertyString(PROP_MAXVALUE, propertynode->GetNodeContent()); } |
| 75 |
|
| 76 |
// XRC only does "value". wxFB does this plus initial. I presume they mean the same thing; perhaps 'value' sets the |
| 77 |
// spinctrl textctrl too |
| 78 |
propertynode = XmlUtils::FindNodeByName(node, "property", "value"); |
| 79 |
if(propertynode) { |
| 80 |
wxString value = propertynode->GetNodeContent(); |
| 81 |
if(!value.empty()) { |
| 82 |
SetPropertyString(PROP_VALUE, value); |
| 83 |
} else { |
| 84 |
propertynode = XmlUtils::FindNodeByName(node, "property", "initial"); |
| 85 |
if(propertynode) { SetPropertyString(PROP_VALUE, propertynode->GetNodeContent()); } |
| 86 |
} |
| 87 |
} |
| 88 |
} |