2 * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
13 #include <GraphicsDefs.h>
23 static const size_t kCommandLength
= 32;
25 enum group_destination
{
30 ALL_DESTINATIONS
= 255
36 Parser(BPositionIO
&stream
);
39 status_t
Parse(RTF::Header
&header
);
52 void SetParent(Group
*parent
);
53 Group
*Parent() const;
55 virtual bool IsDefinitionDelimiter();
56 virtual void Parse(char first
, BDataIO
&stream
, char &last
) throw (status_t
) = 0;
57 virtual void PrintToStream(int32 level
= 0);
64 class Group
: public Element
{
69 status_t
AddElement(RTF::Element
*element
);
70 uint32
CountElements() const;
71 Element
*ElementAt(uint32 index
) const;
73 Element
*FindDefinitionStart(int32 index
, int32
*_startIndex
= NULL
) const;
74 Command
*FindDefinition(const char *name
, int32 index
= 0) const;
75 Group
*FindGroup(const char *name
) const;
77 const char *Name() const;
79 void DetermineDestination();
80 group_destination
Destination() const;
82 virtual void Parse(char first
, BDataIO
&stream
, char &last
) throw (status_t
);
86 group_destination fDestination
;
89 class Header
: public Group
{
94 int32
Version() const;
95 const char *Charset() const;
97 rgb_color
Color(int32 index
);
99 virtual void Parse(char first
, BDataIO
&stream
, char &last
) throw (status_t
);
106 class Text
: public Element
{
111 status_t
SetTo(const char *text
);
112 const char *String() const;
113 uint32
Length() const;
115 virtual bool IsDefinitionDelimiter();
116 virtual void Parse(char first
, BDataIO
&stream
, char &last
) throw (status_t
);
122 class Command
: public Element
{
127 status_t
SetName(const char *name
);
131 void SetOption(int32 option
);
132 bool HasOption() const;
133 int32
Option() const;
135 virtual void Parse(char first
, BDataIO
&stream
, char &last
) throw (status_t
);
143 //---------------------------------
147 Iterator(Element
&start
, group_destination destination
= ALL_DESTINATIONS
);
149 void SetTo(Element
&start
, group_destination destination
= ALL_DESTINATIONS
);
152 bool HasNext() const;
157 Stack
<Element
*> fStack
;
158 group_destination fDestination
;
163 Worker(RTF::Header
&start
);
166 void Work() throw (status_t
);
169 virtual void Group(RTF::Group
*group
);
170 virtual void GroupEnd(RTF::Group
*group
);
171 virtual void Command(RTF::Command
*command
);
172 virtual void Text(RTF::Text
*text
);
174 RTF::Header
&Start();
176 void Abort(status_t status
);
179 void Dispatch(RTF::Element
*element
);