2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: OutputState.C /main/1 1996/07/29 16:59:44 cde-hp $ */
24 // Copyright (c) 1994 James Clark
25 // See the file COPYING for copying permission.
28 #pragma implementation
31 #include "OutputState.h"
33 #include "Allocator.h"
36 namespace SP_NAMESPACE {
39 OutputState::OutputState()
44 void OutputState::init()
48 stack_.insert(new OutputStateLevel);
51 OutputStateLevel::OutputStateLevel()
52 : state(OutputState::afterStartTag)
56 void OutputState::handleRe(EventHandler &handler, Allocator &alloc,
57 const EventsWanted &eventsWanted, Char re,
58 const Location &location)
61 if (eventsWanted.wantInstanceMarkup())
62 handler.reOrigin(new (alloc) ReOriginEvent(re_, location, nextSerial_));
63 switch (top().state) {
65 // it's the first RE in the element
66 if (eventsWanted.wantInstanceMarkup())
67 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
68 top().state = afterRsOrRe;
72 top().state = pendingAfterRsOrRe;
73 top().reLocation = location;
74 top().reSerial = nextSerial_++;
76 case pendingAfterRsOrRe:
77 // We now know that the pending RE won't be ignored as the last RE.
78 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
79 top().state = pendingAfterRsOrRe;
80 top().reLocation = location;
81 top().reSerial = nextSerial_++;
83 case pendingAfterMarkup:
84 // We've had only markup since the last RS or RE, so this
85 // RE is ignored. Note that it's this RE that's ignored, not
87 if (eventsWanted.wantInstanceMarkup())
88 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
89 top().state = pendingAfterRsOrRe;
94 void OutputState::noteRs(EventHandler &, Allocator &, const EventsWanted &)
96 if (top().hasPendingRe())
97 top().state = pendingAfterRsOrRe;
99 top().state = afterRsOrRe;
102 void OutputState::noteMarkup(EventHandler &, Allocator &, const EventsWanted &)
104 switch (top().state) {
106 top().state = afterStartTag;
108 case pendingAfterRsOrRe:
109 top().state = pendingAfterMarkup;
112 break; // avoid warning
116 void OutputState::noteData(EventHandler &handler, Allocator &alloc,
117 const EventsWanted &)
119 if (top().hasPendingRe())
120 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
121 top().state = afterData;
124 void OutputState::noteStartElement(Boolean included,
125 EventHandler &handler, Allocator &alloc,
126 const EventsWanted &)
129 stack_.insert(new OutputStateLevel);
131 if (top().hasPendingRe())
132 handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
133 top().state = afterStartTag;
137 void OutputState::noteEndElement(Boolean included, EventHandler &handler,
139 const EventsWanted &eventsWanted)
141 if (eventsWanted.wantInstanceMarkup() && top().hasPendingRe())
142 handler.ignoredRe(new (alloc) IgnoredReEvent(re_, top().reLocation,
146 noteMarkup(handler, alloc, eventsWanted);
149 top().state = afterData;