Added a simple RTF::Worker class that can be subclassed in order to work
with the RTF document step by step. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10568 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
9932029846
commit
63c6a88ba0
@ -746,3 +746,92 @@ Iterator::Next()
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Worker::Worker(RTF::Header &start)
|
||||
:
|
||||
fStart(start)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Worker::~Worker()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Dispatch(Element *element)
|
||||
{
|
||||
if (RTF::Group *group = dynamic_cast<RTF::Group *>(element)) {
|
||||
fSkip = false;
|
||||
Group(group);
|
||||
|
||||
if (fSkip)
|
||||
return;
|
||||
|
||||
for (int32 i = 0; (element = group->ElementAt(i)) != NULL; i++)
|
||||
Dispatch(element);
|
||||
|
||||
GroupEnd(group);
|
||||
} else if (RTF::Command *command = dynamic_cast<RTF::Command *>(element)) {
|
||||
Command(command);
|
||||
} else if (RTF::Text *text = dynamic_cast<RTF::Text *>(element)) {
|
||||
Text(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Work() throw (status_t)
|
||||
{
|
||||
Dispatch(&fStart);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Group(RTF::Group *group)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::GroupEnd(RTF::Group *group)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Command(RTF::Command *command)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Text(RTF::Text *text)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
RTF::Header &
|
||||
Worker::Start()
|
||||
{
|
||||
return fStart;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Skip()
|
||||
{
|
||||
fSkip = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Worker::Abort(status_t status)
|
||||
{
|
||||
throw status;
|
||||
}
|
||||
|
||||
|
@ -158,6 +158,30 @@ class Iterator {
|
||||
group_destination fDestination;
|
||||
};
|
||||
|
||||
class Worker {
|
||||
public:
|
||||
Worker(RTF::Header &start);
|
||||
virtual ~Worker();
|
||||
|
||||
void Work() throw (status_t);
|
||||
|
||||
protected:
|
||||
virtual void Group(RTF::Group *group);
|
||||
virtual void GroupEnd(RTF::Group *group);
|
||||
virtual void Command(RTF::Command *command);
|
||||
virtual void Text(RTF::Text *text);
|
||||
|
||||
RTF::Header &Start();
|
||||
void Skip();
|
||||
void Abort(status_t status);
|
||||
|
||||
private:
|
||||
void Dispatch(RTF::Element *element);
|
||||
|
||||
RTF::Header &fStart;
|
||||
bool fSkip;
|
||||
};
|
||||
|
||||
} // namespace RTF
|
||||
|
||||
#endif /* RTF_H */
|
||||
|
Loading…
Reference in New Issue
Block a user