Initial commit
[profile/ivi/openjade.git] / style / ProcessContext.h
1 // Copyright (c) 1996 James Clark
2 // See the file copying.txt for copying permission.
3
4 #ifndef ProcessContext_INCLUDED
5 #define ProcessContext_INCLUDED 1
6
7 #include "Resource.h"
8 #include "Ptr.h"
9 #include "Vector.h"
10 #include "NCVector.h"
11 #include "Owner.h"
12 #include "Collector.h"
13 #include "Style.h"
14 #include "FOTBuilder.h"
15 #include "ELObj.h"
16 #include "SosofoObj.h"
17 #include "VM.h"
18 #include "ProcessingMode.h"
19 #include "Link.h"
20 #include "IList.h"
21 #include "IQueue.h"
22
23 #ifdef DSSSL_NAMESPACE
24 namespace DSSSL_NAMESPACE {
25 #endif
26
27 class Expression;
28
29 class ProcessContext : public Collector::DynamicRoot {
30 public:
31   ProcessContext(Interpreter &, FOTBuilder &);
32   FOTBuilder &currentFOTBuilder();
33   StyleStack &currentStyleStack();
34   void process(const NodePtr &);
35   void processNode(const NodePtr &, const ProcessingMode *, bool chunk = 1);
36   void processNodeSafe(const NodePtr &, const ProcessingMode *, bool chunk = 1);
37   void nextMatch(StyleObj *);
38   void processChildren(const ProcessingMode *);
39   void processChildrenTrim(const ProcessingMode *);
40   void trace(Collector &) const;
41   void startFlowObj();
42   void endFlowObj();
43   // Uses of label: do this
44   void startConnection(SymbolObj *, const Location &);
45   void endConnection();
46   // happens only for object with a non-principal port
47   void pushPorts(bool hasPrincipalPort,
48                  const Vector<SymbolObj *> &ports, const Vector<FOTBuilder *> &fotbs);
49   void popPorts();
50   void pushPrincipalPort(FOTBuilder* principalPort);
51   void popPrincipalPort();
52   // happens inside pushPorts() (if any)
53   void startMapContent(ELObj *, const Location &);
54   void endMapContent();
55   void startDiscardLabeled(SymbolObj *);
56   void endDiscardLabeled();
57   // table support
58   void startTable();
59   void endTable();
60   void startTablePart();
61   void endTablePart();
62   void addTableColumn(unsigned columnIndex, unsigned span, StyleObj *);
63   unsigned currentTableColumn();
64   void noteTableCell(unsigned colIndex, unsigned colSpan, unsigned rowSpan);
65   StyleObj *tableColumnStyle(unsigned columnIndex, unsigned span);
66   StyleObj *tableRowStyle();
67   void startTableRow(StyleObj *);
68   bool inTable() const;
69   bool inTableRow();
70   void endTableRow();
71   void clearPageType();
72   void setPageType(unsigned);
73   bool getPageType(unsigned &) const;
74
75   VM &vm();
76 private:
77   ProcessContext(const ProcessContext &); // undefined
78   void operator=(const ProcessContext &); // undefined
79   void badContentMap(bool &, const Location &);
80   void coverSpannedRows();
81   void restoreConnection(unsigned connectableLevel, size_t portIndex);
82   struct Port {
83     Port();
84     FOTBuilder *fotb;
85     IQueue<SaveFOTBuilder> saveQueue;
86     Vector<SymbolObj *> labels;
87     unsigned connected;
88   };
89   // A flow object with a port that can be connected to.
90   struct Connectable;
91   friend struct Connectable;
92   struct Connectable : public Link {
93     Connectable(int nPorts, const StyleStack &, unsigned);
94     NCVector<Port> ports;
95     StyleStack styleStack;
96     unsigned flowObjLevel;
97     Vector<SymbolObj *> principalPortLabels;
98   };
99   // An connection between a flow object and its flow parent
100   // made with label:.
101   struct Connection;
102   friend struct Connection;
103   struct Connection : public Link {
104     Connection(FOTBuilder *);
105     Connection(const StyleStack &, Port *, unsigned connectableLevel);
106     FOTBuilder *fotb;
107     StyleStack styleStack;
108     Port *port;
109     unsigned connectableLevel;
110     unsigned nBadFollow;
111   };
112   struct Table : public Link {
113     Table();
114     unsigned currentColumn;
115     // first index is column (zero-based)
116     // second is span - 1.
117     Vector<Vector<StyleObj *> > columnStyles;
118     // for each column, how many rows are covered
119     // starting with the current row
120     Vector<unsigned> covered;
121     unsigned nColumns;
122     StyleObj *rowStyle;
123     bool inTableRow;
124     unsigned rowConnectableLevel;
125   };
126   struct NodeStackEntry {
127     unsigned long elementIndex;
128     unsigned groveIndex;
129     const ProcessingMode *processingMode;
130   };
131   FOTBuilder ignoreFotb_;
132   IList<Connection> connectionStack_;
133   IList<Connectable> connectableStack_;
134   unsigned connectableStackLevel_;
135   IList<Table> tableStack_;
136   NCVector<IQueue<SaveFOTBuilder> > principalPortSaveQueues_;
137   VM vm_;
138   ProcessingMode::Specificity matchSpecificity_;
139   unsigned flowObjLevel_;
140   bool havePageType_;
141   unsigned pageType_;
142   Vector<NodeStackEntry> nodeStack_;
143   friend class CurrentNodeSetter;
144   friend struct Table;
145 };
146
147 inline
148 FOTBuilder &ProcessContext::currentFOTBuilder()
149 {
150   return *connectionStack_.head()->fotb;
151 }
152
153 inline
154 StyleStack &ProcessContext::currentStyleStack()
155 {
156   return connectionStack_.head()->styleStack;
157 }
158
159 inline
160 VM &ProcessContext::vm()
161 {
162   return vm_;
163 }
164
165 inline
166 void ProcessContext::startFlowObj()
167 {
168   flowObjLevel_++;
169 }
170
171 inline
172 void ProcessContext::setPageType(unsigned n)
173 {
174   havePageType_ = 1;
175   pageType_ = n;
176 }
177
178 inline
179 void ProcessContext::clearPageType()
180 {
181   havePageType_ = 0;
182 }
183
184 inline
185 bool ProcessContext::getPageType(unsigned &n) const
186 {
187   if (!havePageType_)
188     return 0;
189   n = pageType_;
190   return 1;
191 }
192
193 inline
194 bool ProcessContext::inTable() const
195 {
196   return !tableStack_.empty();
197 }
198
199 #ifdef DSSSL_NAMESPACE
200 }
201 #endif
202
203 #endif /* not ProcessContext_INCLUDED */
204