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 
28 #include "../../Include/Rocket/Controls/Controls.h"
29 #include "../../Include/Rocket/Core/ElementInstancerGeneric.h"
30 #include "../../Include/Rocket/Core/Factory.h"
31 #include "../../Include/Rocket/Core/StyleSheetSpecification.h"
32 #include "../../Include/Rocket/Core/XMLParser.h"
33 #include "../../Include/Rocket/Core/Plugin.h"
34 #include "../../Include/Rocket/Core/Core.h"
35 #include "ElementTextSelection.h"
36 #include "XMLNodeHandlerDataGrid.h"
37 #include "XMLNodeHandlerTabSet.h"
38 #include "XMLNodeHandlerTextArea.h"
39 #include "../../Include/Rocket/Controls/ElementFormControlInput.h"
40 
41 namespace Rocket {
42 namespace Controls {
43 
44 // Registers the custom element instancers.
RegisterElementInstancers()45 void RegisterElementInstancers()
46 {
47 	Core::ElementInstancer* instancer = new Core::ElementInstancerGeneric< ElementForm >();
48 	Core::Factory::RegisterElementInstancer("form", instancer);
49 	instancer->RemoveReference();
50 
51 	instancer = new Core::ElementInstancerGeneric< ElementFormControlInput >();
52 	Core::Factory::RegisterElementInstancer("input", instancer);
53 	instancer->RemoveReference();
54 
55 	instancer = new Core::ElementInstancerGeneric< ElementFormControlDataSelect >();
56 	instancer = Core::Factory::RegisterElementInstancer("dataselect", instancer);
57 	instancer->RemoveReference();
58 
59 	instancer = new Core::ElementInstancerGeneric< ElementFormControlSelect >();
60 	Core::Factory::RegisterElementInstancer("select", instancer);
61 	instancer->RemoveReference();
62 
63 	instancer = new Core::ElementInstancerGeneric< ElementFormControlTextArea >();
64 	Core::Factory::RegisterElementInstancer("textarea", instancer);
65 	instancer->RemoveReference();
66 
67 	instancer = new Core::ElementInstancerGeneric< ElementTextSelection >();
68 	Core::Factory::RegisterElementInstancer("#selection", instancer);
69 	instancer->RemoveReference();
70 
71 	instancer = new Core::ElementInstancerGeneric< ElementTabSet >();
72 	Core::Factory::RegisterElementInstancer("tabset", instancer);
73 	instancer->RemoveReference();
74 
75 	instancer = new Core::ElementInstancerGeneric< ElementDataGrid >();
76 	Core::Factory::RegisterElementInstancer("datagrid", instancer);
77 	instancer->RemoveReference();
78 
79 	instancer = new Core::ElementInstancerGeneric< ElementDataGridExpandButton >();
80 	Core::Factory::RegisterElementInstancer("datagridexpand", instancer);
81 	instancer->RemoveReference();
82 
83 	instancer = new Core::ElementInstancerGeneric< ElementDataGridCell >();
84 	Core::Factory::RegisterElementInstancer("#rktctl_datagridcell", instancer);
85 	instancer->RemoveReference();
86 
87 	instancer = new Core::ElementInstancerGeneric< ElementDataGridRow >();
88 	Core::Factory::RegisterElementInstancer("#rktctl_datagridrow", instancer);
89 	instancer->RemoveReference();
90 }
91 
RegisterXMLNodeHandlers()92 void RegisterXMLNodeHandlers()
93 {
94 	Core::XMLNodeHandler* node_handler = new XMLNodeHandlerDataGrid();
95 	Core::XMLParser::RegisterNodeHandler("datagrid", node_handler);
96 	node_handler->RemoveReference();
97 
98 	node_handler = new XMLNodeHandlerTabSet();
99 	Core::XMLParser::RegisterNodeHandler("tabset", node_handler);
100 	node_handler->RemoveReference();
101 
102 	node_handler = new XMLNodeHandlerTextArea();
103 	Core::XMLParser::RegisterNodeHandler("textarea", node_handler);
104 	node_handler->RemoveReference();
105 }
106 
107 static bool initialised = false;
108 
109 class ControlsPlugin : public Rocket::Core::Plugin
110 {
111 public:
OnShutdown()112 	void OnShutdown()
113 	{
114 		initialised = false;
115 		delete this;
116 	}
117 
GetEventClasses()118 	int GetEventClasses()
119 	{
120 		return Rocket::Core::Plugin::EVT_BASIC;
121 	}
122 };
123 
Initialise()124 void Initialise()
125 {
126 	// Prevent double initialisation
127 	if (!initialised)
128 	{
129 		Core::StyleSheetSpecification::RegisterProperty("min-rows", "0", false, false).AddParser("number");
130 
131 		// Register the element instancers for our custom elements.
132 		RegisterElementInstancers();
133 
134 		// Register the XML node handlers for our elements that require special parsing.
135 		RegisterXMLNodeHandlers();
136 
137 		// Register the controls plugin, so we'll be notified on Shutdown
138 		Rocket::Core::RegisterPlugin(new ControlsPlugin());
139 
140 		initialised = true;
141 	}
142 }
143 
144 }
145 }
146