ElementDataGridExpandButton.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/ElementDataGridExpandButton.h"
  28. #include "../../Include/Rocket/Controls/ElementDataGridRow.h"
  29. namespace Rocket {
  30. namespace Controls {
  31. ElementDataGridExpandButton::ElementDataGridExpandButton(const Rocket::Core::String& tag) : Core::Element(tag)
  32. {
  33. SetClass("collapsed", true);
  34. }
  35. ElementDataGridExpandButton::~ElementDataGridExpandButton()
  36. {
  37. }
  38. void ElementDataGridExpandButton::ProcessEvent(Core::Event& event)
  39. {
  40. Core::Element::ProcessEvent(event);
  41. if (event == "click" && event.GetCurrentElement() == this)
  42. {
  43. // Look for the first data grid row above us, and toggle their on/off
  44. // state.
  45. Core::Element* parent = GetParentNode();
  46. ElementDataGridRow* parent_row;
  47. do
  48. {
  49. parent_row = dynamic_cast< ElementDataGridRow* >(parent);
  50. parent = parent->GetParentNode();
  51. }
  52. while (parent && !parent_row);
  53. if (parent_row)
  54. {
  55. parent_row->ToggleRow();
  56. if (parent_row->IsRowExpanded())
  57. {
  58. SetClass("collapsed", false);
  59. SetClass("expanded", true);
  60. }
  61. else
  62. {
  63. SetClass("collapsed", true);
  64. SetClass("expanded", false);
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }