Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / programs / nsgmls / OutputState.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
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.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30 #include "splib.h"
31 #include "OutputState.h"
32 #include "Event.h"
33 #include "Allocator.h"
34
35 #ifdef SP_NAMESPACE
36 namespace SP_NAMESPACE {
37 #endif
38
39 OutputState::OutputState()
40 : re_(0)
41 {
42   init();
43 }
44
45 void OutputState::init()
46 {
47   nextSerial_ = 0;
48   stack_.clear();
49   stack_.insert(new OutputStateLevel);
50 }
51
52 OutputStateLevel::OutputStateLevel()
53 : state(OutputState::afterStartTag), reSerial(0)
54 {
55 }
56
57 void OutputState::handleRe(EventHandler &handler, Allocator &alloc,
58                            const EventsWanted &eventsWanted, Char re,
59                            const Location &location)
60 {
61   re_ = re;
62   if (eventsWanted.wantInstanceMarkup())
63     handler.reOrigin(new (alloc) ReOriginEvent(re_, location, nextSerial_));
64   switch (top().state) {
65   case afterStartTag:
66     // it's the first RE in the element
67     if (eventsWanted.wantInstanceMarkup())
68       handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
69     top().state = afterRsOrRe;
70     break;
71   case afterRsOrRe:
72   case afterData:
73     top().state = pendingAfterRsOrRe;
74     top().reLocation = location;
75     top().reSerial = nextSerial_++;
76     break;
77   case pendingAfterRsOrRe:
78     // We now know that the pending RE won't be ignored as the last RE.
79     handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
80     top().state = pendingAfterRsOrRe;
81     top().reLocation = location;
82     top().reSerial = nextSerial_++;
83     break;
84   case pendingAfterMarkup:
85     // We've had only markup since the last RS or RE, so this
86     // RE is ignored.  Note that it's this RE that's ignored, not
87     // the pending one.
88     if (eventsWanted.wantInstanceMarkup())
89       handler.ignoredRe(new (alloc) IgnoredReEvent(re_, location, nextSerial_++));
90     top().state = pendingAfterRsOrRe;
91     break;
92   }
93 }
94
95 void OutputState::noteRs(EventHandler &, Allocator &, const EventsWanted &)
96 {
97   if (top().hasPendingRe())
98     top().state = pendingAfterRsOrRe;
99   else
100     top().state = afterRsOrRe;
101 }
102
103 void OutputState::noteMarkup(EventHandler &, Allocator &, const EventsWanted &)
104 {
105   switch (top().state) {
106   case afterRsOrRe:
107     top().state = afterStartTag;
108     break;
109   case pendingAfterRsOrRe:
110     top().state = pendingAfterMarkup;
111     break;
112   default:
113     break;                      // avoid warning
114   }
115 }
116
117 void OutputState::noteData(EventHandler &handler, Allocator &alloc,
118                            const EventsWanted &)
119 {
120   if (top().hasPendingRe())
121     handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
122   top().state = afterData;
123 }
124
125 void OutputState::noteStartElement(Boolean included,
126                                    EventHandler &handler, Allocator &alloc,
127                                    const EventsWanted &)
128 {
129   if (included)
130     stack_.insert(new OutputStateLevel);
131   else {
132     if (top().hasPendingRe())
133       handler.data(new (alloc) ReEvent(&re_, top().reLocation, top().reSerial));
134     top().state = afterStartTag;
135   }
136 }
137
138 void OutputState::noteEndElement(Boolean included, EventHandler &handler,
139                                  Allocator &alloc,
140                                  const EventsWanted &eventsWanted)
141 {
142   if (eventsWanted.wantInstanceMarkup() && top().hasPendingRe())
143     handler.ignoredRe(new (alloc) IgnoredReEvent(re_, top().reLocation,
144                                                  top().reSerial));
145   if (included) {
146     delete stack_.get();
147     noteMarkup(handler, alloc, eventsWanted);
148   }
149   else
150     top().state = afterData;
151 }
152
153 #ifdef SP_NAMESPACE
154 }
155 #endif