ElementFormControl.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "../../Include/Rocket/Controls/ElementFormControl.h"
  28. namespace Rocket {
  29. namespace Controls {
  30. ElementFormControl::ElementFormControl(const Rocket::Core::String& tag) : Core::Element(tag)
  31. {
  32. SetProperty("tab-index", "auto");
  33. }
  34. ElementFormControl::~ElementFormControl()
  35. {
  36. }
  37. // Returns the name of the form control.
  38. Rocket::Core::String ElementFormControl::GetName() const
  39. {
  40. return GetAttribute<Rocket::Core::String>("name", "");
  41. }
  42. // Sets the name of the form control.
  43. void ElementFormControl::SetName(const Rocket::Core::String& name)
  44. {
  45. SetAttribute("name", name);
  46. }
  47. // Returns if this value should be submitted with the form
  48. bool ElementFormControl::IsSubmitted()
  49. {
  50. return true;
  51. }
  52. // Returns the disabled status of the form control.
  53. bool ElementFormControl::IsDisabled() const
  54. {
  55. return HasAttribute("disabled");
  56. }
  57. // Sets the disabled status of the form control.
  58. void ElementFormControl::SetDisabled(bool disable)
  59. {
  60. if (disable)
  61. {
  62. SetAttribute("disabled", "");
  63. Blur();
  64. }
  65. else
  66. RemoveAttribute("disabled");
  67. }
  68. // Checks for changes to the 'disabled' attribute.
  69. void ElementFormControl::OnAttributeChange(const Core::AttributeNameList& changed_attributes)
  70. {
  71. Core::Element::OnAttributeChange(changed_attributes);
  72. if (changed_attributes.find("disabled") != changed_attributes.end())
  73. SetPseudoClass("disabled", IsDisabled());
  74. }
  75. }
  76. }