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