1 #ifndef __STYLESHEETS_H__
2 #define __STYLESHEETS_H__
4 /**
5 * Phoebe DOM Implementation.
6 *
7 * This is a C++ approximation of the W3C DOM model, which follows
8 * fairly closely the specifications in the various .idl files, copies of
9 * which are provided for reference. Most important is this one:
10 *
11 * http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/idl-definitions.html
12 *
13 * Authors:
14 * Bob Jamison
15 *
16 * Copyright (C) 2005 Bob Jamison
17 *
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
22 *
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public
29 * License along with this library; if not, write to the Free Software
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 */
34 #include "dom.h"
36 #include <vector>
39 namespace org
40 {
41 namespace w3c
42 {
43 namespace dom
44 {
45 namespace stylesheets
46 {
50 //Make local definitions
51 typedef dom::DOMString DOMString;
52 typedef dom::Node Node;
56 /*#########################################################################
57 ## MediaList
58 #########################################################################*/
60 /**
61 *
62 */
63 class MediaList
64 {
65 public:
67 /**
68 *
69 */
70 virtual DOMString getMediaText()
71 {
72 return mediaText;
73 }
75 /**
76 *
77 */
78 virtual void setMediaText(const DOMString &val) throw (dom::DOMException)
79 {
80 mediaText = val;
81 }
83 /**
84 *
85 */
86 virtual unsigned long getLength()
87 {
88 return items.size();
89 }
91 /**
92 *
93 */
94 virtual DOMString item(unsigned long index)
95 {
96 if (index >= items.size())
97 return "";
98 return items[index];
99 }
101 /**
102 *
103 */
104 virtual void deleteMedium(const DOMString& oldMedium)
105 throw (dom::DOMException)
106 {
107 std::vector<DOMString>::iterator iter;
108 for (iter=items.begin() ; iter!=items.end() ; iter++)
109 {
110 if (*iter == oldMedium)
111 items.erase(iter);
112 }
113 }
115 /**
116 *
117 */
118 virtual void appendMedium(const DOMString& newMedium)
119 throw (dom::DOMException)
120 {
121 items.push_back(newMedium);
122 }
124 //##################
125 //# Non-API methods
126 //##################
128 /**
129 *
130 */
131 MediaList() {}
134 /**
135 *
136 */
137 MediaList(const MediaList &other)
138 {
139 mediaText = other.mediaText;
140 items = other.items;
141 }
143 /**
144 *
145 */
146 virtual ~MediaList() {}
148 protected:
150 DOMString mediaText;
152 std::vector<DOMString>items;
153 };
157 /*#########################################################################
158 ## StyleSheet
159 #########################################################################*/
161 /**
162 *
163 */
164 class StyleSheet
165 {
166 public:
168 /**
169 *
170 */
171 virtual DOMString getType()
172 {
173 return type;
174 }
176 /**
177 *
178 */
179 virtual bool getDisabled()
180 {
181 return disabled;
182 }
184 /**
185 *
186 */
187 virtual void setDisabled(bool val)
188 {
189 disabled = val;
190 }
192 /**
193 *
194 */
195 virtual Node *getOwnerNode()
196 {
197 return ownerNode;
198 }
200 /**
201 *
202 */
203 virtual StyleSheet *getParentStyleSheet()
204 {
205 return parentStylesheet;
206 }
208 /**
209 *
210 */
211 virtual DOMString getHref()
212 {
213 return href;
214 }
216 /**
217 *
218 */
219 virtual DOMString getTitle()
220 {
221 return title;
222 }
224 /**
225 *
226 */
227 virtual MediaList &getMedia()
228 {
229 MediaList &mediaListRef = mediaList;
230 return mediaListRef;
231 }
233 //##################
234 //# Non-API methods
235 //##################
237 /**
238 *
239 */
240 StyleSheet()
241 {
242 type = "";
243 disabled = false;
244 ownerNode = NULL;
245 parentStylesheet = NULL;
246 href = "";
247 title = "";
248 }
251 /**
252 *
253 */
254 StyleSheet(const StyleSheet &other)
255 {
256 type = other.type;
257 disabled = other.disabled;
258 ownerNode = other.ownerNode;
259 parentStylesheet = other.parentStylesheet;
260 href = other.href;
261 title = other.title;
262 mediaList = other.mediaList;
263 }
265 /**
266 *
267 */
268 virtual ~StyleSheet() {}
270 protected:
272 DOMString type;
274 bool disabled;
276 Node *ownerNode;
278 StyleSheet *parentStylesheet;
280 DOMString href;
282 DOMString title;
284 MediaList mediaList;
285 };
290 /*#########################################################################
291 ## StyleSheetList
292 #########################################################################*/
294 /**
295 *
296 */
297 class StyleSheetList
298 {
299 public:
301 /**
302 *
303 */
304 virtual unsigned long getLength()
305 {
306 return sheets.size();
307 }
309 /**
310 *
311 */
312 virtual StyleSheet *item(unsigned long index)
313 {
314 if (index >= sheets.size())
315 return NULL;
316 return sheets[index];
317 }
319 //##################
320 //# Non-API methods
321 //##################
323 /**
324 *
325 */
326 StyleSheetList() {}
328 /**
329 *
330 */
331 StyleSheetList(const StyleSheetList &other)
332 {
333 sheets = other.sheets;
334 }
336 /**
337 *
338 */
339 virtual ~StyleSheetList() {}
341 protected:
343 std::vector<StyleSheet *>sheets;
345 };
351 /*#########################################################################
352 ## LinkStyle
353 #########################################################################*/
355 /**
356 *
357 */
358 class LinkStyle
359 {
360 public:
362 /**
363 *
364 */
365 virtual StyleSheet &getSheet()
366 {
367 StyleSheet &sheetRef = sheet;
368 return sheetRef;
369 }
371 //##################
372 //# Non-API methods
373 //##################
375 /**
376 *
377 */
378 LinkStyle()
379 {
380 }
382 /**
383 *
384 */
385 LinkStyle(const LinkStyle &other)
386 {
387 sheet = other.sheet;
388 }
390 /**
391 *
392 */
393 virtual ~LinkStyle() {}
395 protected:
397 StyleSheet sheet;
399 };
404 /*#########################################################################
405 ## DocumentStyle
406 #########################################################################*/
408 /**
409 *
410 */
411 class DocumentStyle
412 {
413 public:
415 /**
416 *
417 */
418 virtual StyleSheetList &getStyleSheets()
419 {
420 StyleSheetList &listRef = styleSheets;
421 return listRef;
422 }
424 //##################
425 //# Non-API methods
426 //##################
428 /**
429 *
430 */
431 DocumentStyle() {}
433 /**
434 *
435 */
436 DocumentStyle(const DocumentStyle &other)
437 {
438 styleSheets = other.styleSheets;
439 }
441 /**
442 *
443 */
444 virtual ~DocumentStyle() {}
446 protected:
448 StyleSheetList styleSheets;
449 };
455 } //namespace stylesheets
456 } //namespace dom
457 } //namespace w3c
458 } //namespace org
461 #endif // __STYLESHEETS_H__
462 /*#########################################################################
463 ## E N D O F F I L E
464 #########################################################################*/