xref: /trunk/main/filter/source/svg/svgscript.hxx (revision 22e87013)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 static const char aSVGScript1[] =
25 "<![CDATA[\n\
26 	var nCurSlide = 0;\n\
27 	var nSlides = 0;\n\
28 	var aSlides = new Object();\n\
29 	var aMasters = new Object();\n\
30 	var aMasterVisibilities = new Object();\n\
31 \n\
32 	function onClick( aEvt )\n\
33 	{\n\
34 		var nOffset = 0;\n\
35 \n\
36 		if( aEvt.getButton() == 0 )  \n\
37 			nOffset = 1;\n\
38 		else if( aEvt.getButton() == 2 ) \n\
39 			nOffset = -1;\n\
40 \n\
41 		if( 0 != nOffset )\n\
42 			switchSlide( aEvt, nOffset );\n\
43 	}\n\
44 \n\
45 	function onKeyPress( aEvt ) \n\
46 	{\n\
47 		var nCode = String.fromCharCode( aEvt.getCharCode() );\n\
48 		var nOffset = 0;\n\
49 \n\
50 		if( ( ' ' == nCode ) || \n\
51 			( ( !aEvt.getCtrlKey() && !aEvt.getAltKey() && !aEvt.getMetaKey() && !aEvt.getShiftKey() ) && \n\
52 			  ( aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_DOWN() ||\n\
53 				aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_RIGHT() ) ) )\n\
54 		{\n\
55 			nOffset = 1;\n\
56 		}\n\
57 		else if( ( !aEvt.getCtrlKey() && !aEvt.getAltKey() && !aEvt.getMetaKey() && !aEvt.getShiftKey() ) && \n\
58 				 ( aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_UP() ||\n\
59 				   aEvt.getKeyCode() == aEvt.DOM_VK_LEFT() ) )\n\
60 		{\n\
61 			nOffset = -1\n\
62 		}\n\
63 \n\
64 		if( 0 != nOffset )\n\
65 			switchSlide( aEvt, nOffset );\n\
66 	}\n\
67 \n\
68 ";
69 
70 static const char aSVGScript2[] =
71 "	function switchSlide( aEvt, nOffset ) \n\
72 	{\n\
73 		var nNextSlide = nCurSlide + nOffset;\n\
74 \n\
75 		if( nNextSlide < 0 && nSlides > 0 )\n\
76 			nNextSlide = nSlides - 1;\n\
77 		else if( nNextSlide >= nSlides ) \n\
78 			nNextSlide = 0;\n\
79 \n\
80 		aSlides[ nCurSlide ].setAttributeNS( null, \"visibility\", \"hidden\" );\n\
81 		aSlides[ nNextSlide ].setAttributeNS( null, \"visibility\", \"visible\" );\n\
82 \n\
83 		var aCurMaster = aMasters[ nCurSlide ];\n\
84 		var aCurMasterVisibility = aMasterVisibilities[ nCurSlide ];\n\
85 		\n\
86 		var aNextMaster = aMasters[ nNextSlide ];\n\
87 		var aNextMasterVisibility = aMasterVisibilities[ nNextSlide ];\n\
88 \n\
89 		if( ( aCurMaster != aNextMaster ) || ( aCurMasterVisibility != aNextMasterVisibility ) ) \n\
90 		{\n\
91 			if( aCurMaster != aNextMaster )\n\
92 				aCurMaster.setAttributeNS( null, \"visibility\", \"hidden\" );\n\
93 			\n\
94 			aNextMaster.setAttributeNS( null, \"visibility\", aNextMasterVisibility );\n\
95 		}\n\
96 \n\
97 		nCurSlide = nNextSlide; \n\
98 	}\n\
99 \n\
100 	function init() \n\
101 	{\n\
102 		nSlides = document.getElementById( \"meta_slides\" ).getAttributeNS( null, \"numberOfSlides\" );\n\
103 \n\
104 		for( i = 0; i < nSlides; i++ )\n\
105 		{\n\
106 			var aSlide = document.getElementById( \"meta_slide\" + i );\n\
107 			\n\
108 			aSlides[ i ] = document.getElementById( aSlide.getAttributeNS( null, \"slide\" ) );\n\
109 			aMasters[ i ] = document.getElementById( aSlide.getAttributeNS( null, \"master\" ) );\n\
110 			aMasterVisibilities[ i ] = aSlide.getAttributeNS( null, \"master-visibility\" );\n\
111 		}\n\
112 	}\n\
113 \n\
114 	init();\n\
115 ]]>";
116 
117 /*
118 <![CDATA[
119 	var nCurSlide = 0;
120 	var nSlides = 0;
121 	var aSlides = new Object();
122 	var aMasters = new Object();
123 	var aMasterVisibilities;
124 
125 	function onClick( aEvt )
126 	{
127 		var nOffset = 0;
128 
129 		if( aEvt.getButton() == 0 )
130 			nOffset = 1;
131 		else if( aEvt.getButton() == 2 )
132 			nOffset = -1;
133 
134 		if( 0 != nOffset )
135 			switchSlide( aEvt, nOffset );
136 	}
137 
138 	function onKeyPress( aEvt )
139 	{
140 		var nCode = String.fromCharCode( aEvt.getCharCode() );
141 		var nOffset = 0;
142 
143 		if( ( ' ' == nCode ) ||
144 			( ( !aEvt.getCtrlKey() && !aEvt.getAltKey() && !aEvt.getMetaKey() && !aEvt.getShiftKey() ) &&
145 			  ( aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_DOWN() ||
146 				aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_RIGHT() ) ) )
147 		{
148 			nOffset = 1;
149 		}
150 		else if( ( !aEvt.getCtrlKey() && !aEvt.getAltKey() && !aEvt.getMetaKey() && !aEvt.getShiftKey() ) &&
151 				 ( aEvt.getKeyCode() == aEvt.DOM_VK_PAGE_UP() ||
152 				   aEvt.getKeyCode() == aEvt.DOM_VK_LEFT() ) )
153 		{
154 			nOffset = -1
155 		}
156 
157 		if( 0 != nOffset )
158 			switchSlide( aEvt, nOffset );
159 	}
160 
161 	function switchSlide( aEvt, nOffset )
162 	{
163 		var nNextSlide = nCurSlide + nOffset;
164 
165 		if( nNextSlide < 0 && nSlides > 0 )
166 			nNextSlide = nSlides - 1;
167 		else if( nNextSlide >= nSlides )
168 			nNextSlide = 0;
169 
170 		aSlides[ nCurSlide ].setAttributeNS( null, "visibility", "hidden" );
171 		aSlides[ nNextSlide ].setAttributeNS( null, "visibility", "visible" );
172 
173 		var aCurMaster = aMasters[ nCurSlide ];
174 		var aCurMasterVisibility = aMasterVisibilities[ nCurSlide ];
175 
176 		var aNextMaster = aMasters[ nNextSlide ];
177 		var aNextMasterVisibility = aMasterVisibilities[ nNextSlide ];
178 
179 		if( ( aCurMaster != aNextMaster ) || ( aCurMasterVisibility != aNextMasterVisibility ) )
180 		{
181 			if( aCurMaster != aNextMaster )
182 				aCurMaster.setAttributeNS( null, "visibility", "hidden" );
183 
184 			aNextMaster.setAttributeNS( null, "visibility", aNextMasterVisibility );
185 		}
186 
187 		nCurSlide = nNextSlide;
188 	}
189 
190 	function init()
191 	{
192 		nSlides = document.getElementById( "meta_slides" ).getAttributeNS( null, "numberOfSlides" );
193 
194 		for( i = 0; i < nSlides; i++ )
195 		{
196 			var aSlide = document.getElementById( "meta_slide" + i );
197 
198 			aSlides[ i ] = document.getElementById( aSlide.getAttributeNS( null, "slide" ) );
199 			aMasters[ i ] = document.getElementById( aSlide.getAttributeNS( null, "master" ) );
200 			aMasterVisibilities[ i ] = aSlide.getAttributeNS( null, "master-visibility" );
201 		}
202 	}
203 
204 	init();
205 ]]*/
206