htmlhelp.cpp 20.1 KB
Newer Older
1 2
/******************************************************************************
 *
3
 * 
4
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
6 7 8 9 10 11 12
 *
 * 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 van Heesch's avatar
Dimitri van Heesch committed
13 14
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
15
 *
16 17
 * The original version of this file is largely based on a contribution from
 * Harm van der Heijden.
18 19 20 21 22 23
 */

#include <stdio.h>
#include <stdlib.h>
#include <qlist.h>
#include <qdict.h>
24
#include <qregexp.h>
25 26
#include <qfile.h>

Dimitri van Heesch's avatar
Dimitri van Heesch committed
27
#include "qtextcodec.h"
28
#include "sortdict.h"
29 30 31
#include "htmlhelp.h"
#include "config.h"
#include "message.h"
32
#include "doxygen.h"
33
#include "language.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
34
#include "portable.h"
35 36 37
#include "groupdef.h"
#include "memberdef.h"
#include "filedef.h"
38 39 40

//----------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
41
/** Class representing a field in the HTML help index. */
42 43 44 45 46 47
struct IndexField
{
  QCString name;
  QCString url;
  QCString anchor;
  bool     link;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
48
  bool     reversed;
49 50
};

Dimitri van Heesch's avatar
Dimitri van Heesch committed
51
/** Sorted dictionary of IndexField objects. */
52
class IndexFieldSDict : public SDict<IndexField>
53 54
{
  public:
55 56
    IndexFieldSDict() : SDict<IndexField>(17) {}
   ~IndexFieldSDict() {}
57
    int compareItems(QCollection::Item item1, QCollection::Item item2)
58
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
59
      return qstricmp(((IndexField *)item1)->name,((IndexField *)item2)->name);
60 61 62
    }
};

Dimitri van Heesch's avatar
Dimitri van Heesch committed
63 64
/** A helper class for HtmlHelp that manages a two level index in 
 *  alphabetical order.
65 66 67 68
 */
class HtmlHelpIndex
{
  public:
69
    HtmlHelpIndex(HtmlHelp *help);
70 71
   ~HtmlHelpIndex();
    void addItem(const char *first,const char *second, 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
72 73
                 const char *url, const char *anchor,
                 bool hasLink,bool reversed);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
74
    void writeFields(FTextStream &t);
75
  private:
76
    IndexFieldSDict *dict;   
77
    HtmlHelp *m_help;
78 79 80
};

/*! Constructs a new HtmlHelp index */
81
HtmlHelpIndex::HtmlHelpIndex(HtmlHelp *help) : m_help(help)
82
{
83 84
  dict = new IndexFieldSDict;
  dict->setAutoDelete(TRUE);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
}

/*! Destroys the HtmlHelp index */
HtmlHelpIndex::~HtmlHelpIndex()
{
  delete dict;
}

/*! Stores an item in the index if it is not already present. 
 *  Items are stored in alphetical order, by sorting on the
 *  concatenation of \a level1 and \a level2 (if present).
 *
 *  \param level1 the string at level 1 in the index.
 *  \param level2 the string at level 2 in the index (or 0 if not applicable).
 *  \param url the url of the documentation (without .html extension).
 *  \param anchor the anchor of the documentation within the page.
 *  \param hasLink if true, the url (without anchor) can be used in the 
 *         level1 item, when writing the header of a list of level2 items.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
103 104
 *  \param reversed TRUE if level1 is the member name and level2 the compound
 *         name.
105 106
 */
void HtmlHelpIndex::addItem(const char *level1,const char *level2,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
107 108
                       const char *url,const char *anchor,bool hasLink,
                       bool reversed)
109 110 111
{
  QCString key = level1; 
  if (level2) key+= (QCString)"?" + level2;
112 113 114 115
  if (key.find(QRegExp("@[0-9]+"))!=-1) // skip anonymous stuff
  {
    return;
  }
116 117 118 119 120
  if (dict->find(key)==0) // new key
  {
    //printf(">>>>>>>>> HtmlHelpIndex::addItem(%s,%s,%s,%s)\n",
    //      level1,level2,url,anchor);
    IndexField *f = new IndexField;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
121 122 123 124 125
    f->name     = key;
    f->url      = url;
    f->anchor   = anchor;
    f->link     = hasLink;
    f->reversed = reversed;
126
    dict->append(key,f);
127 128 129
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
130 131 132 133 134 135 136 137 138 139
static QCString field2URL(const IndexField *f,bool checkReversed)
{
  QCString result = f->url + Doxygen::htmlFileExtension;
  if (!f->anchor.isEmpty() && (!checkReversed || f->reversed)) 
  {
    result+="#"+f->anchor;  
  }
  return result;
}

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
/*! Writes the sorted list of index items into a html like list.
 *
 *  An list of calls with <code>name = level1,level2</code> as follows:
 *  <pre>
 *    a1,b1
 *    a1,b2
 *    a2,b1
 *    a2,b2
 *    a3
 *    a4,b1
 *  </pre>
 *
 *  Will result in the following list:
 *
 *  <pre>
 *    a1       -> link to url if hasLink==TRUE
 *      b1     -> link to url#anchor
 *      b2     -> link to url#anchor
 *    a2       -> link to url if hasLink==TRUE
 *      b1     -> link to url#anchor
 *      b2     -> link to url#anchor
 *    a3       -> link to url if hasLink==TRUE
 *    a4       -> link to url if hasLink==TRUE
 *      b1     -> link to url#anchor 
 *  </pre>
 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
166
void HtmlHelpIndex::writeFields(FTextStream &t)
167
{
168 169
  dict->sort();
  IndexFieldSDict::Iterator ifli(*dict);
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  IndexField *f;
  QCString lastLevel1;
  bool level2Started=FALSE;
  for (;(f=ifli.current());++ifli)
  {
    QCString level1,level2;
    int i;
    if ((i=f->name.find('?'))!=-1)
    {
      level1 = f->name.left(i);
      level2 = f->name.right(f->name.length()-i-1); 
    }
    else
    {
      level1  = f->name.copy();
    }

    if (level1!=lastLevel1)
    { // finish old list at level 2
      if (level2Started) t << "  </UL>" << endl;
      level2Started=FALSE;
191
    
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
      // <Antony>
      // Added this code so that an item with only one subitem is written
      // without any subitem.
      // For example:
      //   a1, b1 -> will create only a1, not separate subitem for b1
      //   a2, b2
      //   a2, b3
      QCString nextLevel1;
      IndexField* fnext = ++ifli;
      if (fnext)
      {
        nextLevel1 = fnext->name.left(fnext->name.find('?'));
        --ifli;
      }
      if (level1 != nextLevel1)
      {
        level2 = "";
      }
      // </Antony>

212 213 214
      if (level2.isEmpty())
      {
        t << "  <LI><OBJECT type=\"text/sitemap\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
215
        t << "<param name=\"Local\" value=\"" << field2URL(f,TRUE);
216
        t << "\">";
217
        t << "<param name=\"Name\" value=\"" << m_help->recode(level1) << "\">"
218 219 220 221 222 223 224
           "</OBJECT>\n";
      }
      else
      {
        if (f->link)
        {
          t << "  <LI><OBJECT type=\"text/sitemap\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
225
          t << "<param name=\"Local\" value=\"" << field2URL(f,TRUE);
226
          t << "\">";
227
          t << "<param name=\"Name\" value=\"" << m_help->recode(level1) << "\">"
228 229 230 231 232
               "</OBJECT>\n";
        }
        else
        {
          t << "  <LI><OBJECT type=\"text/sitemap\">";
233 234
          t << "<param name=\"See Also\" value=\"" << m_help->recode(level1) << "\">";
          t << "<param name=\"Name\" value=\"" << m_help->recode(level1) << "\">"
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
               "</OBJECT>\n";
        }
      }
    }
    if (!level2Started && !level2.isEmpty())
    { // start new list at level 2
      t << "  <UL>" << endl;
      level2Started=TRUE;
    }
    else if (level2Started && level2.isEmpty())
    { // end list at level 2
      t << "  </UL>" << endl;
      level2Started=FALSE;
    }
    if (level2Started)
    {
      t << "    <LI><OBJECT type=\"text/sitemap\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
252
      t << "<param name=\"Local\" value=\"" << field2URL(f,FALSE);
253
      t << "\">";
254
      t << "<param name=\"Name\" value=\"" << m_help->recode(level2) << "\">"
255 256 257 258
         "</OBJECT>\n";
    }
    lastLevel1 = level1.copy();
  } 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
259
  if (level2Started) t << "  </UL>" << endl;
260 261 262 263 264 265 266 267 268 269
}

//----------------------------------------------------------------------------

HtmlHelp *HtmlHelp::theInstance = 0;

/*! Constructs an html object. 
 *  The object has to be \link initialize() initialized\endlink before it can 
 *  be used.
 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
270
HtmlHelp::HtmlHelp() : indexFileDict(1009)
271 272 273 274
{
  /* initial depth */
  dc = 0;
  cf = kf = 0;
275
  index = new HtmlHelpIndex(this);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
276
  m_fromUtf8 = (void *)(-1);
277 278
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
279 280 281 282
HtmlHelp::~HtmlHelp()
{
  if (m_fromUtf8!=(void *)(-1))   portable_iconv_close(m_fromUtf8);
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
283
#if 0
284 285 286 287 288 289 290
/*! return a reference to the one and only instance of this class. 
 */
HtmlHelp *HtmlHelp::getInstance()
{
  if (theInstance==0) theInstance = new HtmlHelp;
  return theInstance;
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
291
#endif
292

293 294
static QDict<QCString> s_languageDict;

295 296 297 298 299 300 301
/*! This will create a contents file (index.hhc) and a index file (index.hhk)
 *  and write the header of those files. 
 *  It also creates a project file (index.hhp)
 *  \sa finalize()
 */
void HtmlHelp::initialize()
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
302
  const char *str = Config_getString("CHM_INDEX_ENCODING");
303
  if (!str) str = "CP1250"; // use safe and likely default
Dimitri van Heesch's avatar
Dimitri van Heesch committed
304
  m_fromUtf8 = portable_iconv_open(str,"UTF-8"); 
305 306
  if (m_fromUtf8==(void *)(-1))
  {
307
    err("unsupported character conversion for CHM_INDEX_ENCODING: '%s'->'UTF-8'\n", str);
308 309
    exit(1);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
310

311
  /* open the contents file */
312
  QCString fName = Config_getString("HTML_OUTPUT") + "/index.hhc";
313 314 315 316 317 318 319 320 321 322 323
  cf = new QFile(fName);
  if (!cf->open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fName.data());
    exit(1);
  }
  /* Write the header of the contents file */
  cts.setDevice(cf);
  cts << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
         "<HTML><HEAD></HEAD><BODY>\n"
         "<OBJECT type=\"text/site properties\">\n"
324
         "<param name=\"FrameName\" value=\"right\">\n"
325 326 327 328
         "</OBJECT>\n"
         "<UL>\n";
  
  /* open the contents file */
329
  fName = Config_getString("HTML_OUTPUT") + "/index.hhk";
330 331 332 333 334 335 336 337 338 339 340
  kf = new QFile(fName);
  if (!kf->open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fName.data());
    exit(1);
  }
  /* Write the header of the contents file */
  kts.setDevice(kf);
  kts << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
         "<HTML><HEAD></HEAD><BODY>\n"
         "<OBJECT type=\"text/site properties\">\n"
341
         "<param name=\"FrameName\" value=\"right\">\n"
342 343
         "</OBJECT>\n"
         "<UL>\n";
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 370 371 372 373 374 375

  /* language codes for Html help
     0x405 Czech
     0x406 Danish
     0x413 Dutch
     0xC09 English (Australia)
     0x809 English (Britain)
     0x1009 English (Canada)
     0x1809 English (Ireland)
     0x1409 English (New Zealand)
     0x1C09 English (South Africa)
     0x409 English (United States)
     0x40B Finnish
     0x40C French
     0x407 German
     0x408 Greece
     0x40E Hungarian
     0x410 Italian
     0x814 Norwegian
     0x415 Polish
     0x816 Portuguese(Portugal)
     0x416 Portuguese(Brazil)
     0x419 Russian
     0x80A Spanish(Mexico)
     0xC0A Spanish(Modern Sort)
     0x40A Spanish(Traditional Sort)
     0x41D Swedish
     0x41F Turkey
     0x411 Japanese
     0x412 Korean
     0x804 Chinese (PRC)
     0x404 Chinese (Taiwan)
376 377 378 379 380 381 382 383 384 385

     New LCIDs:
	 0x421 Indonesian
	 0x41A Croatian
	 0x418 Romanian
	 0x424 Slovenian
	 0x41B Slovak
	 0x422 Ukrainian
	 0x81A Serbian (Serbia, Latin)
	 0x403 Catalan
386
	 0x426 Latvian
387 388 389 390 391 392 393
	 0x427 Lithuanian
	 0x436 Afrikaans
	 0x42A Vietnamese
	 0x429 Persian (Iran)
	 0xC01 Arabic (Egypt) - I don't know which version of arabic is used inside translator_ar.h ,
     so I have chosen Egypt at random

394 395 396
  */
  s_languageDict.setAutoDelete(TRUE);
  s_languageDict.clear();
397 398 399 400 401 402
  s_languageDict.insert("czech",       new QCString("0x405 Czech"));
  s_languageDict.insert("danish",      new QCString("0x406 Danish"));
  s_languageDict.insert("dutch",       new QCString("0x413 Dutch"));
  s_languageDict.insert("finnish",     new QCString("0x40B Finnish"));
  s_languageDict.insert("french",      new QCString("0x40C French"));
  s_languageDict.insert("german",      new QCString("0x407 German"));
403
  s_languageDict.insert("greek",       new QCString("0x408 Greece"));
404 405 406 407
  s_languageDict.insert("hungarian",   new QCString("0x40E Hungarian"));
  s_languageDict.insert("italian",     new QCString("0x410 Italian"));
  s_languageDict.insert("norwegian",   new QCString("0x814 Norwegian"));
  s_languageDict.insert("polish",      new QCString("0x415 Polish"));
408
  s_languageDict.insert("portuguese",  new QCString("0x816 Portuguese(Portugal)"));
409 410
  s_languageDict.insert("brazil",      new QCString("0x416 Portuguese(Brazil)"));
  s_languageDict.insert("russian",     new QCString("0x419 Russian"));
411
  s_languageDict.insert("spanish",     new QCString("0x40A Spanish(Traditional Sort)"));
412
  s_languageDict.insert("swedish",     new QCString("0x41D Swedish"));
413
  s_languageDict.insert("turkish",     new QCString("0x41F Turkey"));
414 415 416
  s_languageDict.insert("japanese",    new QCString("0x411 Japanese"));
  s_languageDict.insert("japanese-en", new QCString("0x411 Japanese"));
  s_languageDict.insert("korean",      new QCString("0x412 Korean"));
417
  s_languageDict.insert("korean-en",   new QCString("0x412 Korean"));
418
  s_languageDict.insert("chinese",     new QCString("0x804 Chinese (PRC)"));
419
  s_languageDict.insert("chinese-traditional", new QCString("0x404 Chinese (Taiwan)"));
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434

  // new LCIDs
  s_languageDict.insert("indonesian",  new QCString("0x412 Indonesian"));
  s_languageDict.insert("croatian",    new QCString("0x41A Croatian"));
  s_languageDict.insert("romanian",    new QCString("0x418 Romanian"));
  s_languageDict.insert("slovene",     new QCString("0x424 Slovenian"));
  s_languageDict.insert("slovak",      new QCString("0x41B Slovak"));
  s_languageDict.insert("ukrainian",   new QCString("0x422 Ukrainian"));
  s_languageDict.insert("serbian",     new QCString("0x81A Serbian (Serbia, Latin)"));
  s_languageDict.insert("catalan",     new QCString("0x403 Catalan"));
  s_languageDict.insert("lithuanian",  new QCString("0x427 Lithuanian"));
  s_languageDict.insert("afrikaans",   new QCString("0x436 Afrikaans"));
  s_languageDict.insert("vietnamese",  new QCString("0x42A Vietnamese"));
  s_languageDict.insert("persian",     new QCString("0x429 Persian (Iran)"));
  s_languageDict.insert("arabic",      new QCString("0xC01 Arabic (Egypt)"));
435
  s_languageDict.insert("latvian",     new QCString("0x426 Latvian"));
436
}
437

438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454

static QCString getLanguageString()
{
  if (!theTranslator->idLanguage().isEmpty())
  {
    QCString *s = s_languageDict[theTranslator->idLanguage()];
    if (s)
    {
      return *s;
    }
  }
  // default language
  return "0x409 English (United States)";
}
  


455 456
void HtmlHelp::createProjectFile()
{
457
  /* Write the project file */
458
  QCString fName = Config_getString("HTML_OUTPUT") + "/index.hhp";
459 460 461
  QFile f(fName);
  if (f.open(IO_WriteOnly))
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
462
    FTextStream t(&f);
463
    
464
    QCString indexName="index"+Doxygen::htmlFileExtension;
465 466 467 468 469 470
    t << "[OPTIONS]\n";
    if (!Config_getString("CHM_FILE").isEmpty())
    {
      t << "Compiled file=" << Config_getString("CHM_FILE") << "\n";
    }
    t << "Compatibility=1.1\n"
471 472
         "Full-text search=Yes\n"
         "Contents file=index.hhc\n"
473
         "Default Window=main\n"
474
         "Default topic=" << indexName << "\n"
475
         "Index file=index.hhk\n"
476
         "Language=" << getLanguageString() << endl;
477 478
    if (Config_getBool("BINARY_TOC")) t << "Binary TOC=YES\n";
    if (Config_getBool("GENERATE_CHI")) t << "Create CHI file=YES\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
479
    t << "Title=" << recode(Config_getString("PROJECT_NAME")) << endl << endl;
480 481
    
    t << "[WINDOWS]" << endl;
482 483 484 485 486 487 488

    // NOTE: the 0x10387e number is a set of bits specifying the buttons
    //       which should appear in the CHM viewer; that specific value
    //       means "show all buttons including the font-size one";
    //       the font-size one is not normally settable by the HTML Help Workshop
    //       utility but the way to set it is described here:
    //          http://support.microsoft.com/?scid=kb%3Ben-us%3B240062&x=17&y=18
Dimitri van Heesch's avatar
Dimitri van Heesch committed
489
    t << "main=\"" << recode(Config_getString("PROJECT_NAME")) << "\",\"index.hhc\","
490
         "\"index.hhk\",\"" << indexName << "\",\"" << 
491
         indexName << "\",,,,,0x23520,,0x10387e,,,,,,,,0" << endl << endl;
492 493 494 495 496 497
    
    t << "[FILES]" << endl;
    char *s = indexFiles.first();
    while (s)
    {
      t << s << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
498
      s = indexFiles.next();
499
    }
500 501 502 503 504
    uint i;
    for (i=0;i<imageFiles.count();i++)
    {
      t << imageFiles.at(i) << endl;
    }
505 506 507 508 509 510 511 512
    f.close();
  }
  else
  {
    err("Could not open file %s for writing\n",fName.data());
  }
}

513 514
void HtmlHelp::addIndexFile(const char *s)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
515 516 517 518 519
  if (indexFileDict.find(s)==0)
  {
    indexFiles.append(s);
    indexFileDict.insert(s,(void *)0x8);
  }
520 521
}

522 523 524 525 526 527 528 529
/*! Finalizes the HTML help. This will finish and close the
 *  contents file (index.hhc) and the index file (index.hhk).
 *  \sa initialize()
 */
void HtmlHelp::finalize()
{
  // end the contents file
  cts << "</UL>\n";
530 531
  cts << "</BODY>\n";
  cts << "</HTML>\n";
532 533 534 535 536 537 538 539
  cts.unsetDevice();
  cf->close();
  delete cf;
  
  index->writeFields(kts);
  
  // end the index file
  kts << "</UL>\n";
540 541
  kts << "</BODY>\n";
  kts << "</HTML>\n";
542 543 544
  kts.unsetDevice();
  kf->close();
  delete kf;
545 546

  createProjectFile();
547
  s_languageDict.clear();
548 549 550 551 552 553
}

/*! Increase the level of the contents hierarchy. 
 *  This will start a new unnumbered HTML list in contents file.
 *  \sa decContentsDepth()
 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
554
void HtmlHelp::incContentsDepth()
555 556 557
{
  int i; for (i=0;i<dc+1;i++) cts << "  ";
  cts << "<UL>\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
558
  ++dc;
559 560 561 562 563 564
}

/*! Decrease the level of the contents hierarchy.
 *  This will end the unnumber HTML list.
 *  \sa incContentsDepth()
 */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
565
void HtmlHelp::decContentsDepth()
566 567 568
{
  int i; for (i=0;i<dc;i++) cts << "  ";
  cts << "</UL>\n";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
569
  --dc;
570 571
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
572 573 574 575 576 577 578
QCString HtmlHelp::recode(const QCString &s) 
{
  int iSize        = s.length();
  int oSize        = iSize*4+1;
  QCString output(oSize);
  size_t iLeft     = iSize;
  size_t oLeft     = oSize;
579
  char *iPtr       = s.data();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
580 581 582
  char *oPtr       = output.data();
  if (!portable_iconv(m_fromUtf8,&iPtr,&iLeft,&oPtr,&oLeft))
  {
583
    oSize -= (int)oLeft;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
584 585 586 587 588 589 590 591 592 593
    output.resize(oSize+1);
    output.at(oSize)='\0';
    return output;
  }
  else
  {
    return s;
  }
}

594
/*! Add an list item to the contents file.
595
 *  \param isDir boolean indicating if this is a dir or file entry
596 597
 *  \param name the name of the item.
 *  \param ref  the URL of to the item.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
598
 *  \param file the file in which the item is defined.
599
 *  \param anchor the anchor of the item.
600 601
 *  \param separateIndex not used.
 *  \param addToNavIndex not used.
602
 *  \param def not used.
603
 */
604
void HtmlHelp::addContentsItem(bool isDir,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
605 606 607
                               const char *name,
                               const char * /*ref*/, 
                               const char *file,
608 609
                               const char *anchor,
                               bool /* separateIndex */,
610 611
                               bool /* addToNavIndex */,
                               Definition * /* def */)
612
{
613
  // If we're using a binary toc then folders cannot have links. 
614
  if(Config_getBool("BINARY_TOC") && isDir) 
615
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
616
    file = 0;
617 618
    anchor = 0;
  }
619 620
  int i; for (i=0;i<dc;i++) cts << "  ";
  cts << "<LI><OBJECT type=\"text/sitemap\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
621
  cts << "<param name=\"Name\" value=\"" << recode(name) << "\">";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
622
  if (file)      // made file optional param - KPW
623
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
624 625 626 627 628 629 630 631 632 633 634 635 636
    if (file && (file[0]=='!' || file[0]=='^')) // special markers for user defined URLs
    {
      cts << "<param name=\"";
      if (file[0]=='^') cts << "URL"; else cts << "Local";
      cts << "\" value=\"";
      cts << &file[1];
    }
    else
    {
      cts << "<param name=\"Local\" value=\"";
      cts << file << Doxygen::htmlFileExtension;
      if (anchor) cts << "#" << anchor;  
    }
637 638
    cts << "\">";
  }
639 640 641 642 643 644 645 646 647 648 649
  cts << "<param name=\"ImageNumber\" value=\"";
  if (isDir)  // added - KPW
  {
    cts << (int)BOOK_CLOSED ;
  }
  else
  {
    cts << (int)TEXT;
  }
  cts << "\">";
  cts << "</OBJECT>\n";
650 651
}

652 653

void HtmlHelp::addIndexItem(Definition *context,MemberDef *md,
654
                            const char *sectionAnchor,const char *word)
655
{
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
  if (md)
  {
    static bool separateMemberPages = Config_getBool("SEPARATE_MEMBER_PAGES");
    if (context==0) // global member
    {
      if (md->getGroupDef())
        context = md->getGroupDef();
      else if (md->getFileDef())
        context = md->getFileDef();
    }
    if (context==0) return; // should not happen

    QCString cfname  = md->getOutputFileBase();
    QCString cfiname = context->getOutputFileBase();
    QCString level1  = context->name();
    QCString level2  = md->name();
    QCString contRef = separateMemberPages ? cfname : cfiname;
    QCString memRef  = cfname;
674
    QCString anchor  = sectionAnchor ? QCString(sectionAnchor) : md->anchor();
675 676 677 678 679 680
    index->addItem(level1,level2,contRef,anchor,TRUE,FALSE);
    index->addItem(level2,level1,memRef,anchor,TRUE,TRUE);
  }
  else if (context)
  {
    QCString level1  = word ? QCString(word) : context->name();
681
    index->addItem(level1,0,context->getOutputFileBase(),sectionAnchor,TRUE,FALSE);
682
  }
683
}
684

685 686 687 688 689
void HtmlHelp::addImageFile(const char *fileName)
{
  imageFiles.append(fileName);
}