CGUIStringAttribute.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef __C_GUI_STRING_ATTRIBUTE_H_INCLUDED__
  2. #define __C_GUI_STRING_ATTRIBUTE_H_INCLUDED__
  3. #include "CGUIAttribute.h"
  4. #include "IGUIEditBox.h"
  5. #include "EGUIEditTypes.h"
  6. namespace irr
  7. {
  8. namespace gui
  9. {
  10. class CGUIStringAttribute : public CGUIAttribute
  11. {
  12. public:
  13. //
  14. CGUIStringAttribute(IGUIEnvironment* environment, IGUIElement *parent, s32 myParentID) :
  15. CGUIAttribute(environment, parent, myParentID),
  16. AttribEditBox(0)
  17. {
  18. core::rect<s32> r = getAbsolutePosition();
  19. core::rect<s32> r2(0, Environment->getSkin()->getFont()->getDimension(L"A").Height + 10,
  20. r.getWidth() - 5,
  21. Environment->getSkin()->getFont()->getDimension(L"A").Height*2 + 15 );
  22. AttribEditBox = environment->addEditBox(0, r2, true, this, -1);
  23. AttribEditBox->grab();
  24. AttribEditBox->setSubElement(true);
  25. AttribEditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
  26. }
  27. virtual ~CGUIStringAttribute()
  28. {
  29. if (AttribEditBox)
  30. AttribEditBox->drop();
  31. }
  32. virtual void setAttrib(io::IAttributes *attribs, u32 attribIndex)
  33. {
  34. AttribEditBox->setText(attribs->getAttributeAsStringW(attribIndex).c_str());
  35. CGUIAttribute::setAttrib(attribs, attribIndex);
  36. }
  37. //! save the attribute and possibly post the event to its parent
  38. virtual bool updateAttrib(bool sendEvent=true)
  39. {
  40. if (!Attribs)
  41. return true;
  42. Attribs->setAttribute(Index, AttribEditBox->getText());
  43. AttribEditBox->setText(Attribs->getAttributeAsStringW(Index).c_str());
  44. return CGUIAttribute::updateAttrib(sendEvent);
  45. }
  46. //! Returns the type name of the gui element.
  47. virtual const c8* getTypeName() const
  48. {
  49. return GUIEditElementTypeNames[EGUIEDIT_STRINGATTRIBUTE];
  50. }
  51. private:
  52. IGUIEditBox* AttribEditBox;
  53. };
  54. } // namespace gui
  55. } // namespace irr
  56. #endif