dochandler.cpp 57.9 KB
Newer Older
dimitri's avatar
dimitri committed
1 2 3 4 5
/******************************************************************************
 *
 * $Id$
 *
 *
dimitri's avatar
dimitri committed
6
 * Copyright (C) 1997-2006 by Dimitri van Heesch.
dimitri's avatar
dimitri committed
7 8 9 10 11 12 13 14 15
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby 
 * granted. No representations are made about the suitability of this software 
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 */

dimitri's avatar
dimitri committed
16 17
#include <qmap.h>

dimitri's avatar
dimitri committed
18
#include "dochandler.h"
dimitri's avatar
dimitri committed
19
#include "debug.h"
dimitri's avatar
dimitri committed
20 21
#include "linkedtexthandler.h"

dimitri's avatar
dimitri committed
22

dimitri's avatar
dimitri committed
23 24
//----------------------------------------------------------------------

dimitri's avatar
dimitri committed
25 26 27 28 29
class TypeNameMapper
{
  public:
    TypeNameMapper()
    {
dimitri's avatar
dimitri committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
      m_map.insert("see",       SimpleSectHandler::See);
      m_map.insert("return",    SimpleSectHandler::Return);
      m_map.insert("author",    SimpleSectHandler::Author);
      m_map.insert("version",   SimpleSectHandler::Version);
      m_map.insert("since",     SimpleSectHandler::Since);
      m_map.insert("date",      SimpleSectHandler::Date);
      m_map.insert("bug",       SimpleSectHandler::Bug);
      m_map.insert("note",      SimpleSectHandler::Note);
      m_map.insert("warning",   SimpleSectHandler::Warning);
      m_map.insert("par",       SimpleSectHandler::Par);
      m_map.insert("deprecated",SimpleSectHandler::Deprecated);
      m_map.insert("pre",       SimpleSectHandler::Pre);
      m_map.insert("post",      SimpleSectHandler::Post);
      m_map.insert("invariant", SimpleSectHandler::Invar);
      m_map.insert("remark",    SimpleSectHandler::Remark);
      m_map.insert("attention", SimpleSectHandler::Attention);
      m_map.insert("todo",      SimpleSectHandler::Todo);
      m_map.insert("test",      SimpleSectHandler::Test);
      m_map.insert("rcs",       SimpleSectHandler::RCS);
      m_map.insert("enumvalues",SimpleSectHandler::EnumValues);
      m_map.insert("examples",  SimpleSectHandler::Examples);
dimitri's avatar
dimitri committed
51 52 53
    }
    SimpleSectHandler::Types stringToType(const QString &typeStr)
    {
dimitri's avatar
dimitri committed
54
      return m_map[typeStr];
dimitri's avatar
dimitri committed
55 56
    }
  private:
dimitri's avatar
dimitri committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    QMap<QString,SimpleSectHandler::Types> m_map;
};

class HighlightMapper
{
  public:
    HighlightMapper()
    {
      m_map.insert("comment",        HighlightHandler::Comment);
      m_map.insert("keyword",        HighlightHandler::Keyword);
      m_map.insert("keywordtype",    HighlightHandler::KeywordType);
      m_map.insert("keywordflow",    HighlightHandler::KeywordFlow);
      m_map.insert("charliteral",    HighlightHandler::CharLiteral);
      m_map.insert("stringliteral",  HighlightHandler::StringLiteral);
      m_map.insert("preprocessor",   HighlightHandler::Preprocessor);
    }
    HighlightHandler::HighlightKind stringToKind(const QString &kindStr)
    {
      return m_map[kindStr];
    }
  private:
    QMap<QString,HighlightHandler::HighlightKind> m_map;
dimitri's avatar
dimitri committed
79 80
};

dimitri's avatar
dimitri committed
81
static TypeNameMapper *s_typeMapper;
dimitri's avatar
dimitri committed
82
static HighlightMapper *s_highlightMapper;
dimitri's avatar
dimitri committed
83

dimitri's avatar
dimitri committed
84 85 86
void dochandler_init()
{
  s_typeMapper = new TypeNameMapper;
dimitri's avatar
dimitri committed
87
  s_highlightMapper = new HighlightMapper;
dimitri's avatar
dimitri committed
88 89 90 91 92
}

void dochandler_exit()
{
  delete s_typeMapper;
dimitri's avatar
dimitri committed
93
  delete s_highlightMapper;
dimitri's avatar
dimitri committed
94
}
dimitri's avatar
dimitri committed
95
  
dimitri's avatar
dimitri committed
96 97 98 99
//----------------------------------------------------------------------
// MarkupHandler
//----------------------------------------------------------------------

dimitri's avatar
dimitri committed
100
MarkupHandler::MarkupHandler(QList<DocImpl> &children,QString &curString)
dimitri's avatar
dimitri committed
101 102
  : m_children(children), m_curString(curString), 
    m_curMarkup(IDocMarkup::Normal), m_headingLevel(0)
dimitri's avatar
dimitri committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
{
  addStartHandler("bold",this,&MarkupHandler::startBold);
  addEndHandler("bold",this,&MarkupHandler::endBold);
  
  addStartHandler("emphasis",this,&MarkupHandler::startEmphasis);
  addEndHandler("emphasis",this,&MarkupHandler::endEmphasis);
  
  addStartHandler("computeroutput",this,&MarkupHandler::startComputerOutput);
  addEndHandler("computeroutput",this,&MarkupHandler::endComputerOutput);

  addStartHandler("center",this,&MarkupHandler::startCenter);
  addEndHandler("center",this,&MarkupHandler::endCenter);

  addStartHandler("small",this,&MarkupHandler::startSmallFont);
  addEndHandler("small",this,&MarkupHandler::endSmallFont);

  addStartHandler("subscript",this,&MarkupHandler::startSubscript);
  addEndHandler("subscript",this,&MarkupHandler::endSubscript);

  addStartHandler("superscript",this,&MarkupHandler::startSuperscript);
  addEndHandler("superscript",this,&MarkupHandler::endSuperscript);
dimitri's avatar
dimitri committed
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144

  addStartHandler("preformatted",this,&MarkupHandler::startPreformatted);
  addEndHandler("preformatted",this,&MarkupHandler::endPreformatted);

  addStartHandler("heading1",this,&MarkupHandler::startHeading1);
  addEndHandler("heading1",this,&MarkupHandler::endHeading1);
  
  addStartHandler("heading2",this,&MarkupHandler::startHeading2);
  addEndHandler("heading2",this,&MarkupHandler::endHeading2);

  addStartHandler("heading3",this,&MarkupHandler::startHeading3);
  addEndHandler("heading3",this,&MarkupHandler::endHeading3);

  addStartHandler("heading4",this,&MarkupHandler::startHeading4);
  addEndHandler("heading4",this,&MarkupHandler::endHeading4);

  addStartHandler("heading5",this,&MarkupHandler::startHeading5);
  addEndHandler("heading5",this,&MarkupHandler::endHeading5);

  addStartHandler("heading6",this,&MarkupHandler::startHeading6);
  addEndHandler("heading6",this,&MarkupHandler::endHeading6);
dimitri's avatar
dimitri committed
145 146 147 148 149 150 151 152 153 154
}

MarkupHandler::~MarkupHandler()
{
}

void MarkupHandler::addTextNode()
{
  if (!m_curString.isEmpty())
  {
dimitri's avatar
dimitri committed
155
    m_children.append(new TextNode(m_curString,m_curMarkup,m_headingLevel));
dimitri's avatar
dimitri committed
156
    debug(2,"addTextNode() text=%s markup=%x\n",m_curString.data(),m_curMarkup);
dimitri's avatar
dimitri committed
157 158 159 160 161 162 163
    m_curString="";
  }
}

void MarkupHandler::startBold(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
164 165
  m_children.append(new MarkupModifierNode(IDocMarkup::Bold,TRUE));
  m_curMarkup |= IDocMarkup::Bold;
dimitri's avatar
dimitri committed
166 167 168 169 170
}

void MarkupHandler::endBold()
{
  addTextNode();
dimitri's avatar
dimitri committed
171 172
  m_children.append(new MarkupModifierNode(IDocMarkup::Bold,FALSE));
  m_curMarkup &= ~IDocMarkup::Bold;
dimitri's avatar
dimitri committed
173 174 175 176 177
}

void MarkupHandler::startEmphasis(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
178 179
  m_children.append(new MarkupModifierNode(IDocMarkup::Emphasis,TRUE));
  m_curMarkup |= IDocMarkup::Emphasis;
dimitri's avatar
dimitri committed
180 181 182 183 184
}

void MarkupHandler::endEmphasis()
{
  addTextNode();
dimitri's avatar
dimitri committed
185 186
  m_children.append(new MarkupModifierNode(IDocMarkup::Emphasis,FALSE));
  m_curMarkup &= ~IDocMarkup::Emphasis;
dimitri's avatar
dimitri committed
187 188 189 190 191
}

void MarkupHandler::startComputerOutput(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
192 193
  m_children.append(new MarkupModifierNode(IDocMarkup::ComputerOutput,TRUE));
  m_curMarkup |= IDocMarkup::ComputerOutput;
dimitri's avatar
dimitri committed
194 195 196 197 198
}

void MarkupHandler::endComputerOutput()
{
  addTextNode();
dimitri's avatar
dimitri committed
199 200
  m_children.append(new MarkupModifierNode(IDocMarkup::ComputerOutput,FALSE));
  m_curMarkup &= ~IDocMarkup::ComputerOutput;
dimitri's avatar
dimitri committed
201 202 203 204 205
}

void MarkupHandler::startCenter(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
206 207
  m_children.append(new MarkupModifierNode(IDocMarkup::Center,TRUE));
  m_curMarkup |= IDocMarkup::Center;
dimitri's avatar
dimitri committed
208 209 210 211 212
}

void MarkupHandler::endCenter()
{
  addTextNode();
dimitri's avatar
dimitri committed
213 214
  m_children.append(new MarkupModifierNode(IDocMarkup::Center,FALSE));
  m_curMarkup &= ~IDocMarkup::Center;
dimitri's avatar
dimitri committed
215 216 217 218 219
}

void MarkupHandler::startSmallFont(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
220 221
  m_children.append(new MarkupModifierNode(IDocMarkup::SmallFont,TRUE));
  m_curMarkup |= IDocMarkup::SmallFont;
dimitri's avatar
dimitri committed
222 223 224 225 226
}

void MarkupHandler::endSmallFont()
{
  addTextNode();
dimitri's avatar
dimitri committed
227 228
  m_children.append(new MarkupModifierNode(IDocMarkup::SmallFont,FALSE));
  m_curMarkup &= ~IDocMarkup::SmallFont;
dimitri's avatar
dimitri committed
229 230 231 232 233
}

void MarkupHandler::startSubscript(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
234 235
  m_children.append(new MarkupModifierNode(IDocMarkup::Subscript,TRUE));
  m_curMarkup |= IDocMarkup::Subscript;
dimitri's avatar
dimitri committed
236 237 238 239 240
}

void MarkupHandler::endSubscript()
{
  addTextNode();
dimitri's avatar
dimitri committed
241 242
  m_children.append(new MarkupModifierNode(IDocMarkup::Subscript,FALSE));
  m_curMarkup &= ~IDocMarkup::Subscript;
dimitri's avatar
dimitri committed
243 244 245 246 247
}

void MarkupHandler::startSuperscript(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
dimitri's avatar
dimitri committed
248 249
  m_children.append(new MarkupModifierNode(IDocMarkup::Superscript,TRUE));
  m_curMarkup |= IDocMarkup::Superscript;
dimitri's avatar
dimitri committed
250 251 252 253 254
}

void MarkupHandler::endSuperscript()
{
  addTextNode();
dimitri's avatar
dimitri committed
255 256
  m_children.append(new MarkupModifierNode(IDocMarkup::Superscript,FALSE));
  m_curMarkup &= ~IDocMarkup::Superscript;
dimitri's avatar
dimitri committed
257 258
}

dimitri's avatar
dimitri committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
void MarkupHandler::startPreformatted(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Preformatted,TRUE));
  m_curMarkup |= IDocMarkup::Preformatted;
}

void MarkupHandler::endPreformatted()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Preformatted,FALSE));
  m_curMarkup &= ~IDocMarkup::Preformatted;
}

void MarkupHandler::startHeading1(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,1));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=1;
}

void MarkupHandler::endHeading1()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,1));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}

void MarkupHandler::startHeading2(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,2));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=2;
}

void MarkupHandler::endHeading2()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,2));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}

void MarkupHandler::startHeading3(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,3));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=3;
}

void MarkupHandler::endHeading3()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,3));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}

void MarkupHandler::startHeading4(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,4));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=4;
}

void MarkupHandler::endHeading4()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,4));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}

void MarkupHandler::startHeading5(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,5));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=5;
}

void MarkupHandler::endHeading5()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,5));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}

void MarkupHandler::startHeading6(const QXmlAttributes & /*attrib*/)
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,TRUE,6));
  m_curMarkup |= IDocMarkup::Heading;
  m_headingLevel=6;
}

void MarkupHandler::endHeading6()
{
  addTextNode();
  m_children.append(new MarkupModifierNode(IDocMarkup::Heading,FALSE,6));
  m_curMarkup &= ~IDocMarkup::Heading;
  m_headingLevel=0;
}


dimitri's avatar
dimitri committed
370 371 372 373 374
//----------------------------------------------------------------------
// ListItemHandler
//----------------------------------------------------------------------

ListItemHandler::ListItemHandler(IBaseHandler *parent) 
dimitri's avatar
dimitri committed
375
  : m_parent(parent)
dimitri's avatar
dimitri committed
376
{
dimitri's avatar
dimitri committed
377 378
  m_children.setAutoDelete(TRUE);
  
dimitri's avatar
dimitri committed
379 380 381 382 383 384 385 386 387 388 389 390
  addEndHandler("listitem",this,&ListItemHandler::endListItem);

  addStartHandler("para",this,&ListItemHandler::startParagraph);
}

ListItemHandler::~ListItemHandler()
{
}

void ListItemHandler::startListItem(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
391
  debug(2,"start list item handler\n");
dimitri's avatar
dimitri committed
392 393 394 395
}

void ListItemHandler::endListItem()
{
dimitri's avatar
dimitri committed
396
  debug(2,"end list item handler\n");
dimitri's avatar
dimitri committed
397 398 399 400 401 402 403 404 405 406
  m_parent->setDelegate(0);
}

void ListItemHandler::startParagraph(const QXmlAttributes& attrib)
{
  ParagraphHandler *parHandler = new ParagraphHandler(this);
  parHandler->startParagraph(attrib);
  m_children.append(parHandler);
}

dimitri's avatar
dimitri committed
407 408 409 410 411
IDocIterator *ListItemHandler::contents() const
{
  return new ListItemIterator(*this);
}

dimitri's avatar
dimitri committed
412
//----------------------------------------------------------------------
dimitri's avatar
dimitri committed
413
// OrderedListHandler
dimitri's avatar
dimitri committed
414 415
//----------------------------------------------------------------------

dimitri's avatar
dimitri committed
416
OrderedListHandler::OrderedListHandler(IBaseHandler *parent) : m_parent(parent)
dimitri's avatar
dimitri committed
417 418
{
  m_children.setAutoDelete(TRUE);
dimitri's avatar
dimitri committed
419 420 421
  addEndHandler("orderedlist",this,&OrderedListHandler::endOrderedList);
  addStartHandler("listitem",this,&OrderedListHandler::startOrderedListItem);
}
dimitri's avatar
dimitri committed
422

dimitri's avatar
dimitri committed
423 424 425 426 427 428 429
OrderedListHandler::~OrderedListHandler()
{
}

void OrderedListHandler::startOrderedList(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
430 431
}

dimitri's avatar
dimitri committed
432
void OrderedListHandler::endOrderedList()
dimitri's avatar
dimitri committed
433
{
dimitri's avatar
dimitri committed
434
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
435 436
}

dimitri's avatar
dimitri committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
void OrderedListHandler::startOrderedListItem(const QXmlAttributes& attrib)
{
  ListItemHandler *liHandler = new ListItemHandler(this);
  liHandler->startListItem(attrib);
  m_children.append(liHandler);
}

IDocIterator *OrderedListHandler::elements() const
{
  return new OrderedListIterator(*this);
}

//----------------------------------------------------------------------
// ItemizedListHandler
//----------------------------------------------------------------------

ItemizedListHandler::ItemizedListHandler(IBaseHandler *parent) : m_parent(parent)
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("itemizedlist",this,&ItemizedListHandler::endItemizedList);
  addStartHandler("listitem",this,&ItemizedListHandler::startItemizedListItem);
}

ItemizedListHandler::~ItemizedListHandler()
{
}

void ItemizedListHandler::startItemizedList(const QXmlAttributes& /*attrib*/)
dimitri's avatar
dimitri committed
465 466 467 468
{
  m_parent->setDelegate(this);
}

dimitri's avatar
dimitri committed
469
void ItemizedListHandler::endItemizedList()
dimitri's avatar
dimitri committed
470 471 472 473
{
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
474
void ItemizedListHandler::startItemizedListItem(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
475 476 477 478 479 480
{
  ListItemHandler *liHandler = new ListItemHandler(this);
  liHandler->startListItem(attrib);
  m_children.append(liHandler);
}

dimitri's avatar
dimitri committed
481 482 483 484 485
IDocIterator *ItemizedListHandler::elements() const
{
  return new ItemizedListIterator(*this);
}

dimitri's avatar
dimitri committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
//----------------------------------------------------------------------
// TocListHandler
//----------------------------------------------------------------------

TocListHandler::TocListHandler(IBaseHandler *parent) : m_parent(parent)
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("toclist",this,&TocListHandler::endTocList);
  addStartHandler("tocitem",this,&TocListHandler::startTocItem);
}

TocListHandler::~TocListHandler()
{
}

void TocListHandler::startTocList(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
}

void TocListHandler::endTocList()
{
  m_parent->setDelegate(0);
}

void TocListHandler::startTocItem(const QXmlAttributes& attrib)
{
  TocItemHandler *tiHandler = new TocItemHandler(this);
  tiHandler->startTocItem(attrib);
  m_children.append(tiHandler);
}

IDocIterator *TocListHandler::elements() const
{
  return new TocListIterator(*this);
}

//----------------------------------------------------------------------
// TocItemHandler
//----------------------------------------------------------------------

TocItemHandler::TocItemHandler(IBaseHandler *parent) : m_parent(parent)
{
  addEndHandler("tocitem",this,&TocItemHandler::endTocItem);
}

TocItemHandler::~TocItemHandler()
{
}

void TocItemHandler::startTocItem(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
  m_id = attrib.value("id");
  m_curString="";
}

void TocItemHandler::endTocItem()
{
  m_title = m_curString;
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
549 550 551 552
//----------------------------------------------------------------------
// ParameterHandler
//----------------------------------------------------------------------

dimitri's avatar
dimitri committed
553
ParameterHandler::ParameterHandler(IBaseHandler *parent) : 
dimitri's avatar
dimitri committed
554
  m_parent(parent)
dimitri's avatar
dimitri committed
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570
{
  addEndHandler("parametername",this,&ParameterHandler::endParameterName);
}

ParameterHandler::~ParameterHandler()
{
}

void ParameterHandler::startParameterName(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
}

void ParameterHandler::endParameterName()
{
  m_name = m_curString;
dimitri's avatar
dimitri committed
571
  debug(2,"parameter %s\n",m_name.data());
dimitri's avatar
dimitri committed
572 573 574 575
  m_curString="";
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
//----------------------------------------------------------------------
// ParameterListHandler
//----------------------------------------------------------------------

ParameterItemHandler::ParameterItemHandler(IBaseHandler *parent) 
  : m_parent(parent)
{
  addEndHandler("parameteritem",this,&ParameterItemHandler::endParameterItem);
  addStartHandler("parameternamelist");
  addEndHandler("parameternamelist");
  addStartHandler("parametername",this,&ParameterItemHandler::startParameterName);
  addStartHandler("parameterdescription");
  addEndHandler("parameterdescription");
  addStartHandler("para",this,&ParameterItemHandler::startParagraph);
  m_parameters.setAutoDelete(TRUE);
  m_description = 0;
}

ParameterItemHandler::~ParameterItemHandler()
{
  delete m_description;
}

void ParameterItemHandler::startParameterItem(const QXmlAttributes&)
dimitri's avatar
dimitri committed
600 601 602 603
{
  m_parent->setDelegate(this);
}

dimitri's avatar
dimitri committed
604
void ParameterItemHandler::endParameterItem()
dimitri's avatar
dimitri committed
605 606 607 608
{
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
609 610 611 612 613 614 615 616
void ParameterItemHandler::startParameterName(const QXmlAttributes& attrib)
{
  ParameterHandler *param = new ParameterHandler(this);
  m_parameters.append(param);
  param->startParameterName(attrib);
}

void ParameterItemHandler::startParagraph(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
617 618 619 620
{
  m_description = new ParagraphHandler(this);
  m_description->startParagraph(attrib);
}
dimitri's avatar
dimitri committed
621

dimitri's avatar
dimitri committed
622 623 624 625 626
IDocIterator *ParameterItemHandler::paramNames() const
{
  return new ParameterItemIterator(*this);
}

dimitri's avatar
dimitri committed
627 628 629 630 631
//----------------------------------------------------------------------
// ParameterListHandler
//----------------------------------------------------------------------

ParameterListHandler::ParameterListHandler(IBaseHandler *parent) 
dimitri's avatar
dimitri committed
632
  : m_parent(parent)
dimitri's avatar
dimitri committed
633 634
{
  addEndHandler("parameterlist",this,&ParameterListHandler::endParameterList);
dimitri's avatar
dimitri committed
635 636
  addStartHandler("parameteritem",this,&ParameterListHandler::startParameterItem);
  m_paramItems.setAutoDelete(TRUE);
dimitri's avatar
dimitri committed
637 638 639 640 641 642
}

ParameterListHandler::~ParameterListHandler()
{
}

dimitri's avatar
dimitri committed
643
void ParameterListHandler::startParameterList(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
644
{
dimitri's avatar
dimitri committed
645 646 647 648 649 650
  QString kind = attrib.value("kind");
  if (kind=="retval")         m_type=RetVal;
  else if (kind=="exception") m_type=Exception;
  else if (kind=="param")     m_type=Param;
  else
  {
dimitri's avatar
dimitri committed
651
    debug(1,"Error: invalid parameterlist type: %s\n",kind.data());
dimitri's avatar
dimitri committed
652
  }
dimitri's avatar
dimitri committed
653
  debug(2,"parameterlist kind=%s\n",kind.data());
dimitri's avatar
dimitri committed
654 655 656 657 658 659 660 661
  m_parent->setDelegate(this);
}

void ParameterListHandler::endParameterList()
{
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
662
void ParameterListHandler::startParameterItem(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
663
{
dimitri's avatar
dimitri committed
664 665 666
  ParameterItemHandler *paramItem = new ParameterItemHandler(this);
  m_paramItems.append(paramItem);
  paramItem->startParameterItem(attrib);
dimitri's avatar
dimitri committed
667 668
}

dimitri's avatar
dimitri committed
669 670 671 672 673
IDocIterator *ParameterListHandler::params() const
{
  return new ParameterListIterator(*this);
}

dimitri's avatar
dimitri committed
674 675 676 677 678
//----------------------------------------------------------------------
// LinkHandler
//----------------------------------------------------------------------

LinkHandler::LinkHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
679
  : m_parent(parent)
dimitri's avatar
dimitri committed
680 681 682 683 684 685 686 687 688 689 690
{
  addEndHandler("link",this,&LinkHandler::endLink);
}

LinkHandler::~LinkHandler()
{
}

void LinkHandler::startLink(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
691
  debug(2,"Start link\n");
dimitri's avatar
dimitri committed
692 693 694 695 696 697 698 699 700
  m_ref = attrib.value("linkend");
  m_curString="";
}

void LinkHandler::endLink()
{
  m_text = m_curString;
  m_curString="";
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
701
  debug(2,"End link\n");
dimitri's avatar
dimitri committed
702 703 704 705 706 707 708
}

//----------------------------------------------------------------------
// EMailHandler
//----------------------------------------------------------------------

EMailHandler::EMailHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
709
  : m_parent(parent)
dimitri's avatar
dimitri committed
710 711 712 713 714 715 716 717 718 719 720
{
  addEndHandler("email",this,&EMailHandler::endEMail);
}

EMailHandler::~EMailHandler()
{
}

void EMailHandler::startEMail(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
721
  debug(2,"Start email\n");
dimitri's avatar
dimitri committed
722 723 724 725 726 727 728 729
  m_curString="";
}

void EMailHandler::endEMail()
{
  m_address = m_curString;
  m_curString="";
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
730
  debug(2,"End email\n");
dimitri's avatar
dimitri committed
731 732 733 734 735 736 737
}

//----------------------------------------------------------------------
// ULinkHandler
//----------------------------------------------------------------------

ULinkHandler::ULinkHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
738
  :  m_parent(parent)
dimitri's avatar
dimitri committed
739 740 741 742 743 744 745 746 747 748 749
{
  addEndHandler("ulink",this,&ULinkHandler::endULink);
}

ULinkHandler::~ULinkHandler()
{
}

void ULinkHandler::startULink(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
750
  debug(2,"Start ulink\n");
dimitri's avatar
dimitri committed
751 752 753 754 755 756 757 758 759
  m_url = attrib.value("url");
  m_curString="";
}

void ULinkHandler::endULink()
{
  m_text = m_curString;
  m_curString="";
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
760
  debug(2,"End ulink\n");
dimitri's avatar
dimitri committed
761 762
}

dimitri's avatar
dimitri committed
763 764 765 766 767
//----------------------------------------------------------------------
// LineBreakHandler
//----------------------------------------------------------------------

LineBreakHandler::LineBreakHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
768
  : m_parent(parent)
dimitri's avatar
dimitri committed
769
{
dimitri's avatar
dimitri committed
770
  addEndHandler("linebreak",this,&LineBreakHandler::endLineBreak);
dimitri's avatar
dimitri committed
771 772 773 774 775 776 777 778 779
}

LineBreakHandler::~LineBreakHandler()
{
}

void LineBreakHandler::startLineBreak(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
780
  debug(2,"Start linebreak\n");
dimitri's avatar
dimitri committed
781 782 783 784 785
}

void LineBreakHandler::endLineBreak()
{
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
786
  debug(2,"End linebreak\n");
dimitri's avatar
dimitri committed
787 788 789 790 791 792 793
}

//----------------------------------------------------------------------
// HRulerHandler
//----------------------------------------------------------------------

HRulerHandler::HRulerHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
794
  : m_parent(parent)
dimitri's avatar
dimitri committed
795
{
dimitri's avatar
dimitri committed
796
  addEndHandler("hruler",this,&HRulerHandler::endHRuler);
dimitri's avatar
dimitri committed
797 798 799 800 801 802 803 804 805
}

HRulerHandler::~HRulerHandler()
{
}

void HRulerHandler::startHRuler(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
806
  debug(2,"Start hruler\n");
dimitri's avatar
dimitri committed
807 808 809 810 811
}

void HRulerHandler::endHRuler()
{
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
812
  debug(2,"End hruler\n");
dimitri's avatar
dimitri committed
813 814 815 816 817 818 819
}

//----------------------------------------------------------------------
// RefHandler
//----------------------------------------------------------------------

RefHandler::RefHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
820
  : m_parent(parent)
dimitri's avatar
dimitri committed
821
{
dimitri's avatar
dimitri committed
822
  addEndHandler("ref",this,&RefHandler::endRef);
dimitri's avatar
dimitri committed
823 824 825 826 827 828 829 830 831
}

RefHandler::~RefHandler()
{
}

void RefHandler::startRef(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
832
  m_refId = attrib.value("refid");
dimitri's avatar
dimitri committed
833
  m_extId = attrib.value("external");
dimitri's avatar
dimitri committed
834 835 836 837
  ASSERT(attrib.value("kindref")=="compound" || 
         attrib.value("kindref")=="member");
  m_targetKind = attrib.value("kindref")=="compound" ?  Compound : Member;
  debug(2,"Start ref refId=%s\n",m_refId.data());
dimitri's avatar
dimitri committed
838 839 840 841 842 843 844
  m_curString="";
}

void RefHandler::endRef()
{
  m_linkText = m_curString;
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
845
  debug(2,"End ref: text=`%s'\n",m_linkText.data());
dimitri's avatar
dimitri committed
846 847 848 849 850 851 852 853
}


//----------------------------------------------------------------------
// TitleHandler
//----------------------------------------------------------------------

TitleHandler::TitleHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
854
  : m_parent(parent)
dimitri's avatar
dimitri committed
855 856 857 858 859
{
  m_children.setAutoDelete(TRUE);
  m_markupHandler = new MarkupHandler(m_children,m_curString);
  setFallBackHandler(m_markupHandler);
  addStartHandler("ref",this,&TitleHandler::startRef);
dimitri's avatar
dimitri committed
860
  addEndHandler("title",this,&TitleHandler::endTitle);
dimitri's avatar
dimitri committed
861 862 863 864 865 866 867 868 869 870
}

TitleHandler::~TitleHandler()
{
  delete m_markupHandler;
}

void TitleHandler::startTitle(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
871
  debug(2,"Start title\n");
dimitri's avatar
dimitri committed
872 873 874 875 876 877 878
  m_curString="";
}

void TitleHandler::endTitle()
{
  addTextNode();
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
879
  debug(2,"End title\n");
dimitri's avatar
dimitri committed
880 881 882 883 884 885
}

void TitleHandler::addTextNode()
{
  if (!m_curString.isEmpty())
  {
dimitri's avatar
dimitri committed
886 887 888 889 890 891 892 893 894
    m_children.append(
                      new TextNode(
                                   m_curString,
                                   m_markupHandler->markup(),
                                   m_markupHandler->headingLevel()
                                  )
                     );
    debug(2,"addTextNode() text=\"%s\" markup=%x headingLevel=%d\n",
        m_curString.data(),m_markupHandler->markup(),m_markupHandler->headingLevel());
dimitri's avatar
dimitri committed
895 896 897 898 899 900 901 902 903 904 905
    m_curString="";
  }
}

void TitleHandler::startRef(const QXmlAttributes& attrib)
{
  RefHandler *ref = new RefHandler(this);
  ref->startRef(attrib);
  m_children.append(ref);
}

dimitri's avatar
dimitri committed
906 907 908 909 910
IDocIterator *TitleHandler::title() const
{
  return new TitleIterator(*this);
}

dimitri's avatar
dimitri committed
911 912 913 914 915
//----------------------------------------------------------------------
// SimpleSectHandler
//----------------------------------------------------------------------

SimpleSectHandler::SimpleSectHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
916
  : m_parent(parent), m_paragraph(0), m_title(0)
dimitri's avatar
dimitri committed
917 918 919
{
  addStartHandler("title",this,&SimpleSectHandler::startTitle);
  addStartHandler("para",this,&SimpleSectHandler::startParagraph);
dimitri's avatar
dimitri committed
920
  addEndHandler("simplesect",this,&SimpleSectHandler::endSimpleSect);
dimitri's avatar
dimitri committed
921 922 923 924 925 926 927 928
}

SimpleSectHandler::~SimpleSectHandler()
{
}

void SimpleSectHandler::startSimpleSect(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
929 930 931
  m_typeString = attrib.value("kind");
  m_type = s_typeMapper->stringToType(m_typeString);
  debug(2,"start simple section %s\n",m_typeString.data());
dimitri's avatar
dimitri committed
932 933 934 935 936
  m_parent->setDelegate(this);
}

void SimpleSectHandler::endSimpleSect()
{
dimitri's avatar
dimitri committed
937
  debug(2,"end simple section\n");
dimitri's avatar
dimitri committed
938 939 940
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
941
void SimpleSectHandler::startTitle(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
942
{
dimitri's avatar
dimitri committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
  ASSERT(m_title==0);
  m_title = new TitleHandler(this);
  m_title->startTitle(attrib);
}

void SimpleSectHandler::startParagraph(const QXmlAttributes& attrib)
{
  ASSERT(m_paragraph==0);
  m_paragraph = new ParagraphHandler(this);
  m_paragraph->startParagraph(attrib);
}

//----------------------------------------------------------------------
// VariableListEntryHandler
//----------------------------------------------------------------------

VariableListEntryHandler::VariableListEntryHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
960
   : m_parent(parent), m_description(0), m_linkedTextHandler(0)
dimitri's avatar
dimitri committed
961 962 963 964
{
  addStartHandler("term",this,&VariableListEntryHandler::startTerm);
  addEndHandler("term",this,&VariableListEntryHandler::endTerm);
  addStartHandler("para",this,&VariableListEntryHandler::startParagraph);
dimitri's avatar
dimitri committed
965 966
  addEndHandler("varlistentry",this,&VariableListEntryHandler::endVarListEntry);
  addEndHandler("listitem",this,&VariableListEntryHandler::endListItem);
dimitri's avatar
dimitri committed
967 968 969 970 971 972 973 974 975 976
}

VariableListEntryHandler::~VariableListEntryHandler()
{
  delete m_description;
}

void VariableListEntryHandler::startVarListEntry(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
977
  debug(2,"start varlistentry\n");
dimitri's avatar
dimitri committed
978 979
}

dimitri's avatar
dimitri committed
980 981 982
void VariableListEntryHandler::endVarListEntry()
{
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
983
  debug(2,"end varlistentry\n");
dimitri's avatar
dimitri committed
984 985 986 987 988
}

void VariableListEntryHandler::startListItem(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
989
  debug(2,"start listitem\n");
dimitri's avatar
dimitri committed
990 991 992 993 994
}

void VariableListEntryHandler::endListItem()
{
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
995
  debug(2,"end listitem\n");
dimitri's avatar
dimitri committed
996 997 998
}

void VariableListEntryHandler::startTerm(const QXmlAttributes& /*attrib*/)
dimitri's avatar
dimitri committed
999 1000
{
  m_curString="";
dimitri's avatar
dimitri committed
1001 1002
  m_linkedTextHandler = new LinkedTextHandler(this,m_term);
  m_linkedTextHandler->start("term");
dimitri's avatar
dimitri committed
1003 1004
}

dimitri's avatar
dimitri committed
1005 1006
void VariableListEntryHandler::endTerm()
{
dimitri's avatar
dimitri committed
1007
  delete m_linkedTextHandler;
dimitri's avatar
dimitri committed
1008
}
dimitri's avatar
dimitri committed
1009

dimitri's avatar
dimitri committed
1010
void VariableListEntryHandler::startParagraph(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
1011
{
dimitri's avatar
dimitri committed
1012 1013 1014 1015 1016
  ASSERT(m_description==0);
  m_description = new ParagraphHandler(this);
  m_description->startParagraph(attrib);
}

dimitri's avatar
dimitri committed
1017 1018 1019 1020
ILinkedTextIterator *VariableListEntryHandler::term() const 
{ 
  return new LinkedTextIterator(m_term); 
}
dimitri's avatar
dimitri committed
1021 1022 1023 1024 1025 1026 1027


//----------------------------------------------------------------------
// VariableListHandler
//----------------------------------------------------------------------

VariableListHandler::VariableListHandler(IBaseHandler *parent) 
dimitri's avatar
dimitri committed
1028
  : m_parent(parent)
dimitri's avatar
dimitri committed
1029 1030 1031 1032
{
  m_entries.setAutoDelete(TRUE);
  addStartHandler("varlistentry",this,&VariableListHandler::startVarListEntry);
  addStartHandler("listitem",this,&VariableListHandler::startListItem);
dimitri's avatar
dimitri committed
1033
  addEndHandler("variablelist",this,&VariableListHandler::endVariableList);
dimitri's avatar
dimitri committed
1034 1035 1036 1037 1038 1039 1040 1041 1042
}

VariableListHandler::~VariableListHandler()
{
}

void VariableListHandler::startVariableList(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1043
  debug(2,"start variablelist\n");
dimitri's avatar
dimitri committed
1044 1045 1046 1047
}

void VariableListHandler::endVariableList()
{
dimitri's avatar
dimitri committed
1048
  debug(2,"end variablelist\n");
dimitri's avatar
dimitri committed
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
  m_parent->setDelegate(0);
}

void VariableListHandler::startVarListEntry(const QXmlAttributes& attrib)
{
  VariableListEntryHandler *vle = new VariableListEntryHandler(this);
  vle->startVarListEntry(attrib);
  m_curEntry = vle;
  m_entries.append(vle);
}

void VariableListHandler::startListItem(const QXmlAttributes& attrib)
{
  ASSERT(m_curEntry!=0);
  m_curEntry->startListItem(attrib);
dimitri's avatar
dimitri committed
1064 1065
}

dimitri's avatar
dimitri committed
1066 1067 1068 1069 1070
IDocIterator *VariableListHandler::entries() const
{
  return new VariableListIterator(*this);
}

dimitri's avatar
dimitri committed
1071 1072 1073 1074 1075
//----------------------------------------------------------------------
// HighlightHandler
//----------------------------------------------------------------------

HighlightHandler::HighlightHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1076
  : m_parent(parent)
dimitri's avatar
dimitri committed
1077
{
dimitri's avatar
dimitri committed
1078
  m_children.setAutoDelete(TRUE);
dimitri's avatar
dimitri committed
1079
  addEndHandler("highlight",this,&HighlightHandler::endHighlight);
dimitri's avatar
dimitri committed
1080
  addStartHandler("ref",this,&HighlightHandler::startRef);
dimitri's avatar
dimitri committed
1081
  addStartHandler("sp",this,&HighlightHandler::startSpace);
dimitri's avatar
dimitri committed
1082
  m_hl = IDocHighlight::Invalid;
dimitri's avatar
dimitri committed
1083 1084 1085 1086 1087 1088 1089 1090
}

HighlightHandler::~HighlightHandler()
{
}

void HighlightHandler::startHighlight(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1091 1092
  m_hlString = attrib.value("class");
  m_hl = s_highlightMapper->stringToKind(m_hlString);
dimitri's avatar
dimitri committed
1093 1094
  m_curString="";
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1095
  debug(2,"start highlight\n");
dimitri's avatar
dimitri committed
1096 1097 1098 1099
}

void HighlightHandler::endHighlight()
{
dimitri's avatar
dimitri committed
1100
  addTextNode();
dimitri's avatar
dimitri committed
1101
  debug(2,"end highlight class=`%s'\n",m_hlString.data());
dimitri's avatar
dimitri committed
1102 1103 1104
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1105 1106 1107 1108 1109 1110 1111 1112
void HighlightHandler::startRef(const QXmlAttributes& attrib)
{
  addTextNode();
  RefHandler *rh = new RefHandler(this);
  m_children.append(rh);
  rh->startRef(attrib);
}

dimitri's avatar
dimitri committed
1113 1114 1115 1116 1117 1118
void HighlightHandler::startSpace(const QXmlAttributes&)
{
  m_curString=" ";
  addTextNode();
}

dimitri's avatar
dimitri committed
1119 1120 1121 1122
void HighlightHandler::addTextNode()
{
  if (!m_curString.isEmpty())
  {
dimitri's avatar
dimitri committed
1123
    m_children.append(new TextNode(m_curString,IDocMarkup::Normal,0));
dimitri's avatar
dimitri committed
1124 1125 1126 1127 1128 1129
    debug(2,"addTextNode() text=\"%s\"\n",
        m_curString.data());
    m_curString="";
  }
}

dimitri's avatar
dimitri committed
1130 1131 1132 1133 1134
IDocIterator *HighlightHandler::codeElements() const
{
  return new HighlightIterator(*this);
}

dimitri's avatar
dimitri committed
1135 1136 1137 1138 1139
//----------------------------------------------------------------------
// CodeLineHandler
//----------------------------------------------------------------------

CodeLineHandler::CodeLineHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1140
  : m_parent(parent)
dimitri's avatar
dimitri committed
1141 1142 1143 1144
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("codeline",this,&CodeLineHandler::endCodeLine);
  addEndHandler("linenumber",this,&CodeLineHandler::endLineNumber);
dimitri's avatar
dimitri committed
1145 1146
  addStartHandler("highlight",this,&CodeLineHandler::startHighlight);
  addStartHandler("ref",this,&CodeLineHandler::startRef);
dimitri's avatar
dimitri committed
1147
  m_lineNumber = 0;
dimitri's avatar
dimitri committed
1148 1149 1150 1151 1152 1153 1154 1155 1156
}

CodeLineHandler::~CodeLineHandler()
{
}

void CodeLineHandler::startCodeLine(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1157
  debug(2,"start codeline\n");
dimitri's avatar
dimitri committed
1158 1159 1160 1161
}

void CodeLineHandler::endCodeLine()
{
dimitri's avatar
dimitri committed
1162
  addTextNode();
dimitri's avatar
dimitri committed
1163
  debug(2,"end codeline\n");
dimitri's avatar
dimitri committed
1164 1165 1166
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1167
void CodeLineHandler::startLineNumber(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
1168 1169
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1170
  debug(2,"start linenumber\n");
dimitri's avatar
dimitri committed
1171 1172
  m_lineNumber = attrib.value("line").toInt();
  m_refId = attrib.value("refid");
dimitri's avatar
dimitri committed
1173 1174 1175 1176 1177 1178
}

void CodeLineHandler::endLineNumber()
{
  m_parent->setDelegate(0);
}
dimitri's avatar
dimitri committed
1179

dimitri's avatar
dimitri committed
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
void CodeLineHandler::startHighlight(const QXmlAttributes& attrib)
{
  addTextNode();
  HighlightHandler *hlh = new HighlightHandler(this);
  m_children.append(hlh);
  hlh->startHighlight(attrib);
}

void CodeLineHandler::startRef(const QXmlAttributes& attrib)
{
  addTextNode();
  RefHandler *rh = new RefHandler(this);
  m_children.append(rh);
  rh->startRef(attrib);
}

void CodeLineHandler::addTextNode()
{
  if (!m_curString.isEmpty())
  {
dimitri's avatar
dimitri committed
1200
    m_children.append(new TextNode(m_curString,IDocMarkup::Normal,0));
dimitri's avatar
dimitri committed
1201
    debug(2,"addTextNode() text=\"%s\"\n",
dimitri's avatar
dimitri committed
1202 1203 1204 1205 1206
        m_curString.data());
    m_curString="";
  }
}

dimitri's avatar
dimitri committed
1207 1208 1209 1210 1211 1212
IDocIterator *CodeLineHandler::codeElements() const
{
  return new CodeLineIterator(*this);
}


dimitri's avatar
dimitri committed
1213 1214 1215 1216 1217
//----------------------------------------------------------------------
// ProgramListingHandler
//----------------------------------------------------------------------

ProgramListingHandler::ProgramListingHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1218
  : m_parent(parent)
dimitri's avatar
dimitri committed
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
{
  m_children.setAutoDelete(TRUE);
  m_hasLineNumber=FALSE;
  addEndHandler("programlisting",this,&ProgramListingHandler::endProgramListing);

  addStartHandler("linenumber",this,&ProgramListingHandler::startLineNumber);
  addStartHandler("codeline",this,&ProgramListingHandler::startCodeLine);
}

ProgramListingHandler::~ProgramListingHandler()
{
}

void ProgramListingHandler::startProgramListing(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1235
  debug(2,"start programlisting\n");
dimitri's avatar
dimitri committed
1236 1237 1238 1239
}

void ProgramListingHandler::endProgramListing()
{
dimitri's avatar
dimitri committed
1240
  debug(2,"end programlisting\n");
dimitri's avatar
dimitri committed
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268
  m_parent->setDelegate(0);
}

void ProgramListingHandler::startLineNumber(const QXmlAttributes& attrib)
{
  CodeLineHandler *clh = new CodeLineHandler(this);
  m_children.append(clh);
  m_hasLineNumber=TRUE;
  clh->startLineNumber(attrib);
}
  
void ProgramListingHandler::startCodeLine(const QXmlAttributes& attrib)
{
  CodeLineHandler *clh = 0;
  if (!m_hasLineNumber) 
  {
    clh = new CodeLineHandler(this);
    m_children.append(clh);
  }
  else
  {
    clh = m_children.getLast();
  }
  ASSERT(clh!=0);
  clh->startCodeLine(attrib);
  m_hasLineNumber=FALSE; 
}

dimitri's avatar
dimitri committed
1269 1270 1271 1272 1273 1274 1275
IDocIterator *ProgramListingHandler::codeLines() const
{
  return new ProgramListingIterator(*this);
}



dimitri's avatar
dimitri committed
1276 1277 1278 1279 1280
//----------------------------------------------------------------------
// FormulaHandler
//----------------------------------------------------------------------

FormulaHandler::FormulaHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1281
  : m_parent(parent)
dimitri's avatar
dimitri committed
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299
{
  addEndHandler("formula",this,&FormulaHandler::endFormula);
}

FormulaHandler::~FormulaHandler()
{
}

void FormulaHandler::startFormula(const QXmlAttributes& attrib)
{
  m_id = attrib.value("id");
  m_curString="";
  m_parent->setDelegate(this);
}

void FormulaHandler::endFormula()
{
  m_text = m_curString;
dimitri's avatar
dimitri committed
1300
  debug(2,"formula id=`%s' text=`%s'\n",m_id.data(),m_text.data());
dimitri's avatar
dimitri committed
1301 1302 1303
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329
//----------------------------------------------------------------------
// AnchorHandler
//----------------------------------------------------------------------

AnchorHandler::AnchorHandler(IBaseHandler *parent)
  : m_parent(parent)
{
  addEndHandler("anchor",this,&AnchorHandler::endAnchor);
}

AnchorHandler::~AnchorHandler()
{
}

void AnchorHandler::startAnchor(const QXmlAttributes& attrib)
{
  m_id = attrib.value("id");
  m_parent->setDelegate(this);
}

void AnchorHandler::endAnchor()
{
  debug(2,"anchor id=`%s'\n",m_id.data());
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1330 1331 1332 1333 1334
//----------------------------------------------------------------------
// ImageHandler
//----------------------------------------------------------------------

ImageHandler::ImageHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1335
  : m_parent(parent)
dimitri's avatar
dimitri committed
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
{
  addEndHandler("image",this,&ImageHandler::endImage);
}

ImageHandler::~ImageHandler()
{
}

void ImageHandler::startImage(const QXmlAttributes& attrib)
{
  m_name = attrib.value("name");
  m_curString="";
  m_parent->setDelegate(this);
}

void ImageHandler::endImage()
{
  m_caption = m_curString;
dimitri's avatar
dimitri committed
1354
  debug(2,"image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
dimitri's avatar
dimitri committed
1355 1356 1357 1358 1359 1360 1361 1362
  m_parent->setDelegate(0);
}

//----------------------------------------------------------------------
// DotFileHandler
//----------------------------------------------------------------------

DotFileHandler::DotFileHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1363
  : m_parent(parent)
dimitri's avatar
dimitri committed
1364
{
dimitri's avatar
dimitri committed
1365
  addEndHandler("dotfile",this,&DotFileHandler::endDotFile);
dimitri's avatar
dimitri committed
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
}

DotFileHandler::~DotFileHandler()
{
}

void DotFileHandler::startDotFile(const QXmlAttributes& attrib)
{
  m_name = attrib.value("name");
  m_curString="";
  m_parent->setDelegate(this);
}

void DotFileHandler::endDotFile()
{
  m_caption = m_curString;
dimitri's avatar
dimitri committed
1382
  debug(2,"image name=`%s' caption=`%s'\n",m_name.data(),m_caption.data());
dimitri's avatar
dimitri committed
1383 1384 1385 1386 1387 1388 1389 1390
  m_parent->setDelegate(0);
}

//----------------------------------------------------------------------
// IndexEntryHandler
//----------------------------------------------------------------------

IndexEntryHandler::IndexEntryHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1391
  : m_parent(parent)
dimitri's avatar
dimitri committed
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
{
  addEndHandler("indexentry",this,&IndexEntryHandler::endIndexEntry);
  addStartHandler("primaryie",this,&IndexEntryHandler::startPrimaryIE);
  addEndHandler("primaryie",this,&IndexEntryHandler::endPrimaryIE);
  addStartHandler("secondaryie",this,&IndexEntryHandler::startSecondaryIE);
  addEndHandler("secondaryie",this,&IndexEntryHandler::endSecondaryIE);
}

IndexEntryHandler::~IndexEntryHandler()
{
}

void IndexEntryHandler::startIndexEntry(const QXmlAttributes& /*attrib*/)
{
dimitri's avatar
dimitri committed
1406
  debug(2,"start index entry\n");
dimitri's avatar
dimitri committed
1407 1408 1409 1410 1411
  m_parent->setDelegate(this);
}

void IndexEntryHandler::endIndexEntry()
{
dimitri's avatar
dimitri committed
1412
  debug(2,"index entry primary=`%s' secondary=`%s'\n",
dimitri's avatar
dimitri committed
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
      m_primary.data(),m_secondary.data());
  m_parent->setDelegate(0);
}

void IndexEntryHandler::startPrimaryIE(const QXmlAttributes& /*attrib*/)
{
  m_curString="";
}

void IndexEntryHandler::endPrimaryIE()
{
  m_primary = m_curString;
}

void IndexEntryHandler::startSecondaryIE(const QXmlAttributes& /*attrib*/)
{
  m_curString="";
}

void IndexEntryHandler::endSecondaryIE()
{
  m_secondary = m_curString;
}

dimitri's avatar
dimitri committed
1437 1438 1439 1440 1441
//----------------------------------------------------------------------
// EntryHandler
//----------------------------------------------------------------------

EntryHandler::EntryHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1442
  : m_parent(parent)
dimitri's avatar
dimitri committed
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("entry",this,&EntryHandler::endEntry);
  addStartHandler("para",this,&EntryHandler::startParagraph);
}

EntryHandler::~EntryHandler()
{
}

void EntryHandler::startEntry(const QXmlAttributes&)
{
  m_parent->setDelegate(this);
}

void EntryHandler::endEntry()
{
  m_parent->setDelegate(0);
}

void EntryHandler::startParagraph(const QXmlAttributes& attrib)
{
  ParagraphHandler *ph = new ParagraphHandler(this);
  ph->startParagraph(attrib);
  m_children.append(ph);
}

dimitri's avatar
dimitri committed
1470 1471 1472 1473 1474
IDocIterator *EntryHandler::contents() const
{
  return new EntryIterator(*this);
}

dimitri's avatar
dimitri committed
1475 1476 1477 1478 1479
//----------------------------------------------------------------------
// RowHandler
//----------------------------------------------------------------------

RowHandler::RowHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1480
  : m_parent(parent)
dimitri's avatar
dimitri committed
1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("row",this,&RowHandler::endRow);
  addStartHandler("entry",this,&RowHandler::startEntry);
}

RowHandler::~RowHandler()
{
}

void RowHandler::startRow(const QXmlAttributes&)
{
  m_parent->setDelegate(this);
}

void RowHandler::endRow()
{
  m_parent->setDelegate(0);
}

void RowHandler::startEntry(const QXmlAttributes& attrib)
{
  EntryHandler *eh = new EntryHandler(this);
  eh->startEntry(attrib);
  m_children.append(eh);
}

dimitri's avatar
dimitri committed
1508 1509 1510 1511 1512
IDocIterator *RowHandler::entries() const
{
  return new RowIterator(*this);
}

dimitri's avatar
dimitri committed
1513 1514 1515 1516 1517
//----------------------------------------------------------------------
// TableHandler
//----------------------------------------------------------------------

TableHandler::TableHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1518
  :  m_parent(parent)
dimitri's avatar
dimitri committed
1519 1520 1521 1522
{
  m_children.setAutoDelete(TRUE);
  addEndHandler("table",this,&TableHandler::endTable);
  addStartHandler("row",this,&TableHandler::startRow);
dimitri's avatar
dimitri committed
1523 1524
  addStartHandler("caption",this,&TableHandler::startCaption);
  addEndHandler("caption",this,&TableHandler::endCaption);
dimitri's avatar
dimitri committed
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534
}

TableHandler::~TableHandler()
{
}

void TableHandler::startTable(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
  m_numColumns = attrib.value("cols").toInt();
dimitri's avatar
dimitri committed
1535
  debug(2,"table cols=%d\n",m_numColumns);
dimitri's avatar
dimitri committed
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
}

void TableHandler::endTable()
{
  m_parent->setDelegate(0);
}

void TableHandler::startRow(const QXmlAttributes& attrib)
{
  RowHandler *rh = new RowHandler(this);
  rh->startRow(attrib);
  m_children.append(rh);
}
dimitri's avatar
dimitri committed
1549

dimitri's avatar
dimitri committed
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
void TableHandler::startCaption(const QXmlAttributes& /*attrib*/)
{
  m_curString="";
}

void TableHandler::endCaption()
{
  m_caption = m_curString;
}

dimitri's avatar
dimitri committed
1560 1561 1562 1563 1564
IDocIterator *TableHandler::rows() const
{
  return new TableIterator(*this);
}

dimitri's avatar
dimitri committed
1565
//----------------------------------------------------------------------
dimitri's avatar
dimitri committed
1566
// CopyHandler
dimitri's avatar
dimitri committed
1567 1568
//----------------------------------------------------------------------

dimitri's avatar
dimitri committed
1569 1570
CopyHandler::CopyHandler(IBaseHandler *parent) 
  : m_parent(parent)
dimitri's avatar
dimitri committed
1571 1572
{
  m_children.setAutoDelete(TRUE);
dimitri's avatar
dimitri committed
1573 1574 1575 1576
  
  addEndHandler("copydoc",this,&CopyHandler::endCopy);

  addStartHandler("para",this,&CopyHandler::startParagraph);
dimitri's avatar
dimitri committed
1577 1578
}

dimitri's avatar
dimitri committed
1579
CopyHandler::~CopyHandler()
dimitri's avatar
dimitri committed
1580 1581 1582
{
}

dimitri's avatar
dimitri committed
1583
void CopyHandler::startCopy(const QXmlAttributes& /*attrib*/)
dimitri's avatar
dimitri committed
1584 1585
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1586
  debug(2,"start copy handler\n");
dimitri's avatar
dimitri committed
1587 1588
}

dimitri's avatar
dimitri committed
1589
void CopyHandler::endCopy()
dimitri's avatar
dimitri committed
1590
{
dimitri's avatar
dimitri committed
1591
  debug(2,"end copy handler\n");
dimitri's avatar
dimitri committed
1592 1593 1594
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1595
void CopyHandler::startParagraph(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
1596
{
dimitri's avatar
dimitri committed
1597 1598 1599 1600 1601 1602 1603 1604
  ParagraphHandler *parHandler = new ParagraphHandler(this);
  parHandler->startParagraph(attrib);
  m_children.append(parHandler);
}

IDocIterator *CopyHandler::contents() const
{
  return new CopyIterator(*this);
dimitri's avatar
dimitri committed
1605 1606
}

dimitri's avatar
dimitri committed
1607 1608 1609 1610 1611
//----------------------------------------------------------------------
// VerbatimHandler
//----------------------------------------------------------------------

VerbatimHandler::VerbatimHandler(IBaseHandler *parent)
dimitri's avatar
dimitri committed
1612
  :  m_parent(parent), m_type(IDocVerbatim::Invalid)
dimitri's avatar
dimitri committed
1613 1614
{
  addEndHandler("verbatim",this,&VerbatimHandler::endVerbatim);
dimitri's avatar
dimitri committed
1615 1616
  addEndHandler("latexonly",this,&VerbatimHandler::endVerbatim);
  addEndHandler("htmlonly",this,&VerbatimHandler::endVerbatim);
dimitri's avatar
dimitri committed
1617 1618 1619 1620 1621 1622
}

VerbatimHandler::~VerbatimHandler()
{
}

dimitri's avatar
dimitri committed
1623
void VerbatimHandler::startVerbatim(const QXmlAttributes&,Types type)
dimitri's avatar
dimitri committed
1624
{
dimitri's avatar
dimitri committed
1625
  m_type = type;
dimitri's avatar
dimitri committed
1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
  m_parent->setDelegate(this);
  m_curString="";
}

void VerbatimHandler::endVerbatim()
{
  m_text = m_curString;
  m_parent->setDelegate(0);
}

dimitri's avatar
dimitri committed
1636

dimitri's avatar
dimitri committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669
//----------------------------------------------------------------------
// SymbolHandler
//----------------------------------------------------------------------

SymbolHandler::SymbolHandler(IBaseHandler *parent,Types type)
  :  m_parent(parent), m_letter('\0'), m_type(type)
{
  addEndHandler("symbol");
  switch (type)
  {
    case IDocSymbol::Invalid: m_typeString="invalid"; break;
    case IDocSymbol::Umlaut:  m_typeString="umlaut"; break;
    case IDocSymbol::Acute:   m_typeString="acute"; break;
    case IDocSymbol::Grave:   m_typeString="grave"; break;
    case IDocSymbol::Circ:    m_typeString="circ"; break;
    case IDocSymbol::Tilde:   m_typeString="tilde"; break;
    case IDocSymbol::Szlig:   m_typeString="szlig"; break;
    case IDocSymbol::Cedil:   m_typeString="cedil"; break;
    case IDocSymbol::Ring:    m_typeString="ring"; break;
    case IDocSymbol::Nbsp:    m_typeString="nbsp"; break;
    case IDocSymbol::Copy:    m_typeString="copy"; break;
  }
}

SymbolHandler::~SymbolHandler()
{
}

void SymbolHandler::startSymbol(const QXmlAttributes& attrib)
{
  QString ls = attrib.value("char");
  if (!ls.isEmpty()) m_letter = ls.latin1()[0];
}
dimitri's avatar
dimitri committed
1670

dimitri's avatar
dimitri committed
1671 1672 1673 1674 1675
//----------------------------------------------------------------------
// ParagraphHandler
//----------------------------------------------------------------------

ParagraphHandler::ParagraphHandler(IBaseHandler *parent) 
dimitri's avatar
dimitri committed
1676
  : m_parent(parent)
dimitri's avatar
dimitri committed
1677 1678 1679 1680
{
  m_children.setAutoDelete(TRUE);

  m_markupHandler = new MarkupHandler(m_children,m_curString);
dimitri's avatar
dimitri committed
1681 1682

  // preformatted
dimitri's avatar
dimitri committed
1683 1684 1685 1686
  setFallBackHandler(m_markupHandler);

  addEndHandler("para",this,&ParagraphHandler::endParagraph);

dimitri's avatar
dimitri committed
1687 1688 1689 1690 1691
  addStartHandler("linebreak",this,&ParagraphHandler::startLineBreak);
  addStartHandler("hruler",this,&ParagraphHandler::startHRuler);
  addStartHandler("programlisting",this,&ParagraphHandler::startProgramListing);
  addStartHandler("verbatim",this,&ParagraphHandler::startVerbatim);
  addStartHandler("indexentry",this,&ParagraphHandler::startIndexEntry);
dimitri's avatar
dimitri committed
1692
  addStartHandler("orderedlist",this,&ParagraphHandler::startOrderedList);
dimitri's avatar
dimitri committed
1693
  addStartHandler("itemizedlist",this,&ParagraphHandler::startItemizedList);
dimitri's avatar
dimitri committed
1694
  addStartHandler("simplesect",this,&ParagraphHandler::startSimpleSect);
dimitri's avatar
dimitri committed
1695
  // TODO: title
dimitri's avatar
dimitri committed
1696
  addStartHandler("variablelist",this,&ParagraphHandler::startVariableList);
dimitri's avatar
dimitri committed
1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707
  addStartHandler("table",this,&ParagraphHandler::startTable);
  // TODO: heading
  addStartHandler("image",this,&ParagraphHandler::startImage);
  addStartHandler("dotfile",this,&ParagraphHandler::startDotFile);
  addStartHandler("toclist",this,&ParagraphHandler::startTocList);
  // TODO: language???
  addStartHandler("parameterlist",this,&ParagraphHandler::startParameterList);
  // TODO: xrefsect
  addStartHandler("copydoc",this,&ParagraphHandler::startCopyDoc);

  addStartHandler("ref",this,&ParagraphHandler::startRef);
dimitri's avatar
dimitri committed
1708 1709 1710
  addStartHandler("ulink",this,&ParagraphHandler::startULink);
  addStartHandler("email",this,&ParagraphHandler::startEMail);
  addStartHandler("link",this,&ParagraphHandler::startLink);
dimitri's avatar
dimitri committed
1711
  addStartHandler("formula",this,&ParagraphHandler::startFormula);
dimitri's avatar
dimitri committed
1712 1713
  addStartHandler("latexonly",this,&ParagraphHandler::startHtmlOnly);
  addStartHandler("htmlonly",this,&ParagraphHandler::startLatexOnly);
dimitri's avatar
dimitri committed
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
  addStartHandler("umlaut",this,&ParagraphHandler::startUmlaut);
  addStartHandler("acute",this,&ParagraphHandler::startAcute);
  addStartHandler("grave",this,&ParagraphHandler::startGrave);
  addStartHandler("circ",this,&ParagraphHandler::startCirc);
  addStartHandler("tilde",this,&ParagraphHandler::startTilde);
  addStartHandler("szlig",this,&ParagraphHandler::startSzlig);
  addStartHandler("cedil",this,&ParagraphHandler::startCedil);
  addStartHandler("ring",this,&ParagraphHandler::startRing);
  addStartHandler("nbsp",this,&ParagraphHandler::startNbsp);
  addStartHandler("copy",this,&ParagraphHandler::startCopy);
dimitri's avatar
dimitri committed
1724
  addStartHandler("anchor",this,&ParagraphHandler::startAnchor);
dimitri's avatar
dimitri committed
1725 1726 1727 1728
}

ParagraphHandler::~ParagraphHandler()
{
dimitri's avatar
dimitri committed
1729
  delete m_markupHandler;
dimitri's avatar
dimitri committed
1730 1731 1732 1733 1734
}

void ParagraphHandler::startParagraph(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
1735
  debug(2,"para\n");
dimitri's avatar
dimitri committed
1736 1737 1738 1739 1740
}

void ParagraphHandler::endParagraph()
{
  addTextNode();
dimitri's avatar
dimitri committed
1741
  debug(2,"end para\n");
dimitri's avatar
dimitri committed
1742 1743 1744 1745 1746 1747
  m_parent->setDelegate(0);
}

void ParagraphHandler::startItemizedList(const QXmlAttributes& attrib)
{
  addTextNode();
dimitri's avatar
dimitri committed
1748 1749
  ItemizedListHandler *listHandler = new ItemizedListHandler(this);
  listHandler->startItemizedList(attrib);
dimitri's avatar
dimitri committed
1750 1751 1752 1753 1754 1755
  m_children.append(listHandler);
}

void ParagraphHandler::startOrderedList(const QXmlAttributes& attrib)
{
  addTextNode();
dimitri's avatar
dimitri committed
1756 1757
  OrderedListHandler *listHandler = new OrderedListHandler(this);
  listHandler->startOrderedList(attrib);
dimitri's avatar
dimitri committed
1758 1759 1760
  m_children.append(listHandler);
}

dimitri's avatar
dimitri committed
1761 1762 1763
void ParagraphHandler::startParameterList(const QXmlAttributes& attrib)
{
  addTextNode();
dimitri's avatar
dimitri committed
1764 1765 1766
  ParameterListHandler *listHandler = new ParameterListHandler(this);
  listHandler->startParameterList(attrib);
  m_children.append(listHandler);
dimitri's avatar
dimitri committed
1767 1768
}

dimitri's avatar
dimitri committed
1769 1770 1771 1772 1773 1774 1775 1776
void ParagraphHandler::startSimpleSect(const QXmlAttributes& attrib)
{
  addTextNode();
  SimpleSectHandler *sectHandler = new SimpleSectHandler(this);
  sectHandler->startSimpleSect(attrib);
  m_children.append(sectHandler);
}

dimitri's avatar
dimitri committed
1777 1778
void ParagraphHandler::startRef(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1779
  addTextNode();
dimitri's avatar
dimitri committed
1780 1781 1782 1783 1784 1785 1786
  RefHandler *ref = new RefHandler(this);
  ref->startRef(attrib);
  m_children.append(ref);
}

void ParagraphHandler::startVariableList(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1787
  addTextNode();
dimitri's avatar
dimitri committed
1788 1789 1790 1791 1792 1793 1794
  VariableListHandler *vl = new VariableListHandler(this);
  vl->startVariableList(attrib);
  m_children.append(vl);
}

void ParagraphHandler::startHRuler(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1795
  addTextNode();
dimitri's avatar
dimitri committed
1796 1797 1798 1799 1800 1801 1802
  HRulerHandler *hr = new HRulerHandler(this);
  hr->startHRuler(attrib);
  m_children.append(hr);
}

void ParagraphHandler::startLineBreak(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1803
  addTextNode();
dimitri's avatar
dimitri committed
1804 1805 1806 1807 1808
  LineBreakHandler *lb = new LineBreakHandler(this);
  lb->startLineBreak(attrib);
  m_children.append(lb);
}

dimitri's avatar
dimitri committed
1809 1810
void ParagraphHandler::startULink(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1811
  addTextNode();
dimitri's avatar
dimitri committed
1812 1813 1814 1815 1816 1817 1818
  ULinkHandler *uh = new ULinkHandler(this);
  uh->startULink(attrib);
  m_children.append(uh);
}

void ParagraphHandler::startEMail(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1819
  addTextNode();
dimitri's avatar
dimitri committed
1820 1821 1822 1823 1824 1825 1826
  EMailHandler *eh = new EMailHandler(this);
  eh->startEMail(attrib);
  m_children.append(eh);
}

void ParagraphHandler::startLink(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1827
  addTextNode();
dimitri's avatar
dimitri committed
1828 1829 1830 1831 1832 1833 1834
  LinkHandler *lh = new LinkHandler(this);
  lh->startLink(attrib);
  m_children.append(lh);
}

void ParagraphHandler::startProgramListing(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1835
  addTextNode();
dimitri's avatar
dimitri committed
1836 1837 1838 1839 1840
  ProgramListingHandler *pl = new ProgramListingHandler(this);
  pl->startProgramListing(attrib);
  m_children.append(pl);
}

dimitri's avatar
dimitri committed
1841 1842
void ParagraphHandler::startFormula(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1843
  addTextNode();
dimitri's avatar
dimitri committed
1844 1845 1846 1847 1848 1849 1850
  FormulaHandler *fh = new FormulaHandler(this);
  fh->startFormula(attrib);
  m_children.append(fh);
}

void ParagraphHandler::startImage(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1851
  addTextNode();
dimitri's avatar
dimitri committed
1852 1853 1854 1855 1856 1857 1858
  ImageHandler *ih = new ImageHandler(this);
  ih->startImage(attrib);
  m_children.append(ih);
}

void ParagraphHandler::startDotFile(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1859
  addTextNode();
dimitri's avatar
dimitri committed
1860 1861 1862 1863 1864 1865 1866
  DotFileHandler *df = new DotFileHandler(this);
  df->startDotFile(attrib);
  m_children.append(df);
}

void ParagraphHandler::startIndexEntry(const QXmlAttributes& attrib)
{
dimitri's avatar
dimitri committed
1867
  addTextNode();
dimitri's avatar
dimitri committed
1868 1869 1870 1871 1872
  IndexEntryHandler *df = new IndexEntryHandler(this);
  df->startIndexEntry(attrib);
  m_children.append(df);
}

dimitri's avatar
dimitri committed
1873 1874 1875 1876 1877 1878 1879 1880
void ParagraphHandler::startTable(const QXmlAttributes& attrib)
{
  addTextNode();
  TableHandler *th = new TableHandler(this);
  th->startTable(attrib);
  m_children.append(th);
}

dimitri's avatar
dimitri committed
1881
void ParagraphHandler::startVerbatim(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
1882 1883
{
  addTextNode();
dimitri's avatar
dimitri committed
1884 1885 1886
  VerbatimHandler *vh = new VerbatimHandler(this);
  vh->startVerbatim(attrib,IDocVerbatim::Verbatim);
  m_children.append(vh);
dimitri's avatar
dimitri committed
1887 1888
}

dimitri's avatar
dimitri committed
1889 1890 1891 1892 1893 1894 1895 1896 1897
void ParagraphHandler::startHtmlOnly(const QXmlAttributes& attrib)
{
  addTextNode();
  VerbatimHandler *vh = new VerbatimHandler(this);
  vh->startVerbatim(attrib,IDocVerbatim::HtmlOnly);
  m_children.append(vh);
}

void ParagraphHandler::startLatexOnly(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
1898 1899 1900
{
  addTextNode();
  VerbatimHandler *vh = new VerbatimHandler(this);
dimitri's avatar
dimitri committed
1901
  vh->startVerbatim(attrib,IDocVerbatim::LatexOnly);
dimitri's avatar
dimitri committed
1902 1903 1904
  m_children.append(vh);
}

dimitri's avatar
dimitri committed
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
void ParagraphHandler::startUmlaut(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Umlaut);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startAcute(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Acute);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startGrave(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Grave);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startCirc(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Circ);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startTilde(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Tilde);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startSzlig(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Szlig);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startCedil(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Cedil);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startRing(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Ring);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startNbsp(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Nbsp);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

void ParagraphHandler::startCopy(const QXmlAttributes& attrib)
{
  addTextNode();
  SymbolHandler *sh = new SymbolHandler(this,IDocSymbol::Copy);
  sh->startSymbol(attrib);
  m_children.append(sh);
}

dimitri's avatar
dimitri committed
1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
void ParagraphHandler::startAnchor(const QXmlAttributes& attrib)
{
  addTextNode();
  AnchorHandler *ah = new AnchorHandler(this);
  ah->startAnchor(attrib);
  m_children.append(ah);
}

void ParagraphHandler::startCopyDoc(const QXmlAttributes& attrib)
{
  addTextNode();
  CopyHandler *ch = new CopyHandler(this);
  ch->startCopy(attrib);
  m_children.append(ch);
}

void ParagraphHandler::startTocList(const QXmlAttributes& attrib)
{
  addTextNode();
  TocListHandler *th = new TocListHandler(this);
  th->startTocList(attrib);
  m_children.append(th);
}

dimitri's avatar
dimitri committed
2009 2010 2011 2012
void ParagraphHandler::addTextNode()
{
  if (!m_curString.isEmpty())
  {
dimitri's avatar
dimitri committed
2013 2014 2015 2016 2017 2018 2019 2020 2021
    m_children.append(
                      new TextNode(
                                   m_curString,
                                   m_markupHandler->markup(),
                                   m_markupHandler->headingLevel()
                                  )
                     );
    debug(2,"addTextNode() text=\"%s\" markup=%x headingLevel=%d\n",
        m_curString.data(),m_markupHandler->markup(),m_markupHandler->headingLevel());
dimitri's avatar
dimitri committed
2022 2023 2024 2025
    m_curString="";
  }
}

dimitri's avatar
dimitri committed
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035
IDocIterator *ParagraphHandler::contents() const
{
  return new ParagraphIterator(*this);
}

//----------------------------------------------------------------------
// DocSectionHandler
//----------------------------------------------------------------------

DocSectionHandler::DocSectionHandler(IBaseHandler *parent,int level)
dimitri's avatar
dimitri committed
2036
  : m_parent(parent), m_internal(0), m_level(level), m_title(0)
dimitri's avatar
dimitri committed
2037 2038
{
  QString sectionKey;
dimitri's avatar
dimitri committed
2039 2040 2041 2042 2043 2044 2045 2046 2047 2048
  m_paragraphs.setAutoDelete(TRUE);
  m_subsections.setAutoDelete(TRUE);
  addStartHandler("title",this,&DocSectionHandler::startTitle);
  addStartHandler("para",this,&DocSectionHandler::startParagraph);
  if (level<6) 
  {
    sectionKey.sprintf("sect%d",level+1);
    addStartHandler(sectionKey,this,&DocSectionHandler::startSubSection);
  }
  addStartHandler("internal",this,&DocSectionHandler::startInternal);
dimitri's avatar
dimitri committed
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059
  sectionKey.sprintf("sect%d",level);
  addEndHandler(sectionKey,this,&DocSectionHandler::endDocSection);
}

DocSectionHandler::~DocSectionHandler()
{
}

void DocSectionHandler::startDocSection(const QXmlAttributes& attrib)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
2060
  debug(2,"Start docsection\n");
dimitri's avatar
dimitri committed
2061 2062 2063 2064 2065 2066
  m_id = attrib.value("id");
}

void DocSectionHandler::endDocSection()
{
  m_parent->setDelegate(0);
dimitri's avatar
dimitri committed
2067
  debug(2,"End docsection\n");
dimitri's avatar
dimitri committed
2068 2069
}

dimitri's avatar
dimitri committed
2070
void DocSectionHandler::startSubSection(const QXmlAttributes& attrib)
dimitri's avatar
dimitri committed
2071
{
dimitri's avatar
dimitri committed
2072 2073 2074
  DocSectionHandler *secHandler = new DocSectionHandler(this,m_level+1);
  secHandler->startDocSection(attrib);
  m_subsections.append(secHandler);
dimitri's avatar
dimitri committed
2075 2076
}

dimitri's avatar
dimitri committed
2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127
void DocSectionHandler::startParagraph(const QXmlAttributes& attrib)
{
  ParagraphHandler *parHandler = new ParagraphHandler(this);
  parHandler->startParagraph(attrib);
  m_paragraphs.append(parHandler);
}

void DocSectionHandler::startInternal(const QXmlAttributes& attrib)
{
  m_internal = new DocInternalHandler(this,m_level);
  m_internal->startInternal(attrib);
}

void DocSectionHandler::startTitle(const QXmlAttributes& attrib)
{
  m_title = new TitleHandler(this);
  m_title->startTitle(attrib);
}

IDocIterator *DocSectionHandler::paragraphs() const
{
  return new DocSectionParaIterator(*this);
}

IDocIterator *DocSectionHandler::subSections() const
{
  return new DocSectionSubIterator(*this);
}

IDocInternal *DocSectionHandler::internal() const 
{ 
  return m_internal; 
}

//----------------------------------------------------------------------
// DocInternal
//----------------------------------------------------------------------

DocInternalHandler::DocInternalHandler(IBaseHandler *parent,int level)
  : m_parent(parent), m_level(level)
{
  m_paragraphs.setAutoDelete(TRUE);
  m_subsections.setAutoDelete(TRUE);
  addStartHandler("para",this,&DocInternalHandler::startParagraph);
  QString sectionKey;
  sectionKey.sprintf("sect%d",level+1);
  addStartHandler(sectionKey,this,&DocInternalHandler::startSubSection);
  addEndHandler("internal",this,&DocInternalHandler::endInternal);
}

DocInternalHandler::~DocInternalHandler()
dimitri's avatar
dimitri committed
2128 2129 2130
{
}

dimitri's avatar
dimitri committed
2131
void DocInternalHandler::startInternal(const QXmlAttributes&)
dimitri's avatar
dimitri committed
2132
{
dimitri's avatar
dimitri committed
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147
  m_parent->setDelegate(this);
  debug(2,"Start internal\n");
}

void DocInternalHandler::endInternal()
{
  m_parent->setDelegate(0);
  debug(2,"End internal\n");
}

void DocInternalHandler::startSubSection(const QXmlAttributes& attrib)
{
  DocSectionHandler *secHandler = new DocSectionHandler(this,m_level+1);
  secHandler->startDocSection(attrib);
  m_subsections.append(secHandler);
dimitri's avatar
dimitri committed
2148 2149
}

dimitri's avatar
dimitri committed
2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
void DocInternalHandler::startParagraph(const QXmlAttributes& attrib)
{
  ParagraphHandler *parHandler = new ParagraphHandler(this);
  parHandler->startParagraph(attrib);
  m_paragraphs.append(parHandler);
}

IDocIterator *DocInternalHandler::paragraphs() const
{
  return new DocInternalParaIterator(*this);
}

IDocIterator *DocInternalHandler::subSections() const
{
  return new DocInternalSubIterator(*this);
}


dimitri's avatar
dimitri committed
2168 2169 2170 2171 2172 2173
//----------------------------------------------------------------------
// DocHandler
//----------------------------------------------------------------------

DocHandler::DocHandler(IBaseHandler *parent) : m_parent(parent)
{
dimitri's avatar
dimitri committed
2174 2175
  m_children.setAutoDelete(TRUE);

dimitri's avatar
dimitri committed
2176 2177
  addEndHandler("briefdescription",this,&DocHandler::endDoc);
  addEndHandler("detaileddescription",this,&DocHandler::endDoc);
dimitri's avatar
dimitri committed
2178
  addEndHandler("inbodydescription",this,&DocHandler::endDoc);
dimitri's avatar
dimitri committed
2179 2180
  //addEndHandler("internal"); // TODO: implement this as a section
  addStartHandler("internal",this,&DocHandler::startInternal);
dimitri's avatar
dimitri committed
2181 2182

  addStartHandler("para",this,&DocHandler::startParagraph);
dimitri's avatar
dimitri committed
2183 2184
  addStartHandler("sect1",this,&DocHandler::startSect1);
  addStartHandler("title",this,&DocHandler::startTitle);
dimitri's avatar
dimitri committed
2185
  //addStartHandler("internal");
dimitri's avatar
dimitri committed
2186 2187 2188 2189 2190 2191 2192 2193 2194
}

DocHandler::~DocHandler()
{
}

void DocHandler::startDoc(const QXmlAttributes& /*attrib*/)
{
  m_parent->setDelegate(this);
dimitri's avatar
dimitri committed
2195
  debug(2,"start dochandler\n");
dimitri's avatar
dimitri committed
2196 2197 2198 2199
}

void DocHandler::endDoc()
{
dimitri's avatar
dimitri committed
2200
  debug(2,"end dochandler\n");
dimitri's avatar
dimitri committed
2201 2202 2203 2204 2205 2206 2207 2208 2209 2210
  m_parent->setDelegate(0);
}

void DocHandler::startParagraph(const QXmlAttributes& attrib)
{
  ParagraphHandler *parHandler = new ParagraphHandler(this);
  parHandler->startParagraph(attrib);
  m_children.append(parHandler);
}

dimitri's avatar
dimitri committed
2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224
void DocHandler::startSect1(const QXmlAttributes& attrib)
{
  DocSectionHandler *secHandler = new DocSectionHandler(this,1);
  secHandler->startDocSection(attrib);
  m_children.append(secHandler);
}

void DocHandler::startTitle(const QXmlAttributes& attrib)
{
  TitleHandler *titleHandler = new TitleHandler(this);
  titleHandler->startTitle(attrib);
  m_children.append(titleHandler);
}

dimitri's avatar
dimitri committed
2225 2226 2227 2228 2229 2230
void DocHandler::startInternal(const QXmlAttributes& attrib)
{
  m_internal = new DocInternalHandler(this,1);
  m_internal->startInternal(attrib);
}

dimitri's avatar
dimitri committed
2231 2232 2233 2234 2235
IDocIterator *DocHandler::contents() const
{
  return new DocIterator(*this);
}

dimitri's avatar
dimitri committed
2236 2237 2238 2239 2240
IDocInternal *DocHandler::internal() const 
{ 
  return m_internal; 
}