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
|
/*!
@file
@author Albert Semenov
@date 08/2010
*/
#include "Precompiled.h"
#include "PropertyFontHintingControl.h"
#include "FactoryManager.h"
namespace tools
{
FACTORY_ITEM_ATTRIBUTE(PropertyFontHintingControl)
PropertyFontHintingControl::PropertyFontHintingControl() :
mName(nullptr),
mComboBox(nullptr)
{
}
PropertyFontHintingControl::~PropertyFontHintingControl()
{
mComboBox->eventComboChangePosition -= MyGUI::newDelegate(this, &PropertyFontHintingControl::notifyComboChangePosition);
}
void PropertyFontHintingControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
{
PropertyControl::OnInitialise(_parent, _place, "PropertyComboBoxControl.layout");
assignWidget(mName, "Name", false);
assignWidget(mComboBox, "ComboBox");
mComboBox->addItem("use_native");
mComboBox->addItem("force_auto");
mComboBox->addItem("disable_auto");
mComboBox->addItem("disable_all");
mComboBox->beginToItemFirst();
mComboBox->eventComboChangePosition += MyGUI::newDelegate(this, &PropertyFontHintingControl::notifyComboChangePosition);
}
void PropertyFontHintingControl::updateCaption()
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
mName->setCaption(proper->getType()->getName());
}
void PropertyFontHintingControl::updateProperty()
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
{
mComboBox->setEnabled(!proper->getType()->getReadOnly());
size_t index = getComboIndex(proper->getValue());
mComboBox->setIndexSelected(index);
}
else
{
mComboBox->setIndexSelected(MyGUI::ITEM_NONE);
mComboBox->setEnabled(false);
}
}
void PropertyFontHintingControl::notifyComboChangePosition(MyGUI::ComboBox* _sender, size_t _index)
{
PropertyPtr proper = getProperty();
if (proper != nullptr)
{
std::string value = _index != MyGUI::ITEM_NONE ? mComboBox->getItemNameAt(_index) : "";
executeAction(value);
}
}
size_t PropertyFontHintingControl::getComboIndex(const MyGUI::UString& _name)
{
size_t result = MyGUI::ITEM_NONE;
size_t count = mComboBox->getItemCount();
for (size_t index = 0; index < count; ++index)
{
if (mComboBox->getItemNameAt(index) == _name)
{
result = index;
break;
}
}
return result;
}
}
|