StyleSheetFactory.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef ROCKETCORESTYLESHEETFACTORY_H
  28. #define ROCKETCORESTYLESHEETFACTORY_H
  29. #include "../../Include/Rocket/Core/Types.h"
  30. namespace Rocket {
  31. namespace Core {
  32. class StyleSheet;
  33. class StyleSheetNodeSelector;
  34. /**
  35. Creates stylesheets on the fly as needed. The factory keeps a cache of built sheets for optimisation.
  36. @author Lloyd Weehuizen
  37. */
  38. class StyleSheetFactory
  39. {
  40. public:
  41. /// Initialise the style factory
  42. static bool Initialise();
  43. /// Shutdown style manager
  44. static void Shutdown();
  45. /// Gets the named sheet, retrieving it from the cache if its already been loaded
  46. /// @param sheet name of sheet to load
  47. static StyleSheet* GetStyleSheet(const String& sheet);
  48. /// Builds and returns a stylesheet based on the list of input sheets
  49. /// Generated sheets will be cached for later use
  50. /// @param sheets List of sheets to combine into one
  51. static StyleSheet* GetStyleSheet(const StringList& sheets);
  52. /// Clear the style sheet cache.
  53. static void ClearStyleSheetCache();
  54. /// Returns one of the available node selectors.
  55. /// @param name[in] The name of the desired selector.
  56. /// @return The selector registered with the given name, or NULL if none exists.
  57. static StyleSheetNodeSelector* GetSelector(const String& name);
  58. private:
  59. StyleSheetFactory();
  60. ~StyleSheetFactory();
  61. // Loads an individual style sheet
  62. StyleSheet* LoadStyleSheet(const String& sheet);
  63. // Individual loaded stylesheets
  64. typedef std::map<String, StyleSheet*> StyleSheets;
  65. StyleSheets stylesheets;
  66. // Cache of combined style sheets
  67. StyleSheets stylesheet_cache;
  68. // Custom complex selectors available for style sheets.
  69. typedef std::map< String, StyleSheetNodeSelector* > SelectorMap;
  70. SelectorMap selectors;
  71. };
  72. }
  73. }
  74. #endif