1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*!
@file
@author Albert Semenov
@date 08/2010
*/
#include "Precompiled.h"
#include "PropertyInt4Control.h"
#include "Localise.h"
namespace tools
{
PropertyInt4Control::PropertyInt4Control() :
mName(nullptr),
mEdit(nullptr)
{
}
PropertyInt4Control::~PropertyInt4Control()
{
mEdit->eventEditTextChange -= MyGUI::newDelegate(this, &PropertyInt4Control::notifyEditTextChange);
}
void PropertyInt4Control::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
{
PropertyControl::OnInitialise(_parent, _place, "PropertyEditControl.layout");
assignWidget(mName, "Name", false);
assignWidget(mEdit, "Edit");
mEdit->eventEditTextChange += MyGUI::newDelegate(this, &PropertyInt4Control::notifyEditTextChange);
}
void PropertyInt4Control::updateCaption()
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
mName->setCaption(proper->getType()->getName());
}
void PropertyInt4Control::updateProperty()
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
{
mEdit->setEnabled(!proper->getType()->getReadOnly());
if (mEdit->getOnlyText() != proper->getValue())
mEdit->setCaption(proper->getValue());
bool validate = isValidate();
setColour(validate);
}
else
{
mEdit->setCaption("");
mEdit->setEnabled(false);
}
}
void PropertyInt4Control::notifyEditTextChange(MyGUI::EditBox* _sender)
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
{
bool validate = isValidate();
if (validate)
executeAction(getClearValue());
setColour(validate);
}
}
bool PropertyInt4Control::isValidate()
{
MyGUI::UString value = mEdit->getOnlyText();
int value1 = 0;
int value2 = 0;
int value3 = 0;
int value4 = 0;
if (!MyGUI::utility::parseComplex(value, value1, value2, value3, value4))
return false;
return true;
}
MyGUI::UString PropertyInt4Control::getClearValue()
{
MyGUI::UString value = mEdit->getOnlyText();
int value1 = 0;
int value2 = 0;
int value3 = 0;
int value4 = 0;
if (MyGUI::utility::parseComplex(value, value1, value2, value3, value4))
return MyGUI::utility::toString(value1, " ", value2, " ", value3, " ", value4);
return "";
}
void PropertyInt4Control::setColour(bool _validate)
{
MyGUI::UString value = mEdit->getOnlyText();
if (!_validate)
value = replaceTags("ColourError") + value;
size_t index = mEdit->getTextCursor();
mEdit->setCaption(value);
mEdit->setTextCursor(index);
}
}
|