コード例 #1
0
ファイル: main.cpp プロジェクト: pocketbook-free/pdfviewer
static void update_toc(GooList* items, int level)
{
	unsigned short ucs[256];
	char label[256];
	int i, j;

	if (! items) return;
	if (items->getLength() < 1) return;

	for (i = 0; i < items->getLength(); i++)
	{
		OutlineItem* outlineItem = (OutlineItem*)items->get(i);
		Unicode* title = outlineItem->getTitle();
		int tlen = outlineItem->getTitleLength();
		if (tlen > sizeof(ucs) - 1) tlen = sizeof(ucs) - 1;
		for (j = 0; j < tlen; j++) ucs[j] = (unsigned short)title[j];
		ucs[j] = 0;
		ucs2utf(ucs, label, sizeof(label));

		LinkAction* a = outlineItem->getAction();
		if (a && (a->getKind() == actionGoTo))
		{
			// page number is contained/referenced in a LinkGoTo
			LinkGoTo* g = static_cast< LinkGoTo* >(a);
			LinkDest* destination = g->getDest();
			if (!destination && g->getNamedDest())
			{
				GooString* s = g->getNamedDest();
				if (named_size <= named_count + 1)
				{
					named_size += 64;
					named_dest = (char**) realloc(named_dest, named_size * sizeof(char*));
				}
				named_dest[named_count] = strdup(s->getCString());
				add_toc_item(level, label, -1, 100000 + named_count);
				named_count++;
			}
			else if (destination && destination->isOk() && destination->isPageRef())
			{
				Ref page_ref = destination->getPageRef();
				int num = doc->findPage(page_ref.num, page_ref.gen);
				add_toc_item(level, label, num, num);
			}
			else
			{
				add_toc_item(level, label, -1, -1);
			}
		}
		else
		{
			add_toc_item(level, label, -1, -1);
		}
		outlineItem->open();
		GooList* children = outlineItem->getKids();
		if (children) update_toc(children, level + 1);
		outlineItem->close();
	}
}
コード例 #2
0
ファイル: menu.cpp プロジェクト: carlos-wong/gmenu2x
/*====================================
   LINKS MANAGEMENT
  ====================================*/
bool Menu::addActionLink(uint section, string title, LinkRunAction action, string description, string icon) {
	if (section>=sections.size()) return false;

	LinkAction *linkact = new LinkAction(gmenu2x,action);
	linkact->setSize(gmenu2x->skinConfInt["linkWidth"],gmenu2x->skinConfInt["linkHeight"]);
	linkact->setTitle(title);
	linkact->setDescription(description);
	if (gmenu2x->sc.exists(icon) || (icon.substr(0,5)=="skin:" && !gmenu2x->sc.getSkinFilePath(icon.substr(5,icon.length())).empty()) || fileExists(icon))
	linkact->setIcon(icon);

	sectionLinks(section)->push_back(linkact);
	return true;
}
コード例 #3
0
//-----------------------------------------------------------------------------
Link::Link(const DRect &rect, LinkAction &action, Catalog &catalog)
    : _rect(rect)
{
    switch ( action.getKind() ) {
    case actionGoTo: {
        LinkGoTo &lgoto = static_cast<LinkGoTo &>(action);
        LinkDest *dest = (lgoto.getDest() ? lgoto.getDest()->copy()
                          : catalog.findDest( lgoto.getNamedDest() ));
        int page = 1;
        if (dest) {
            if ( dest->isPageRef() ) {
                Ref pageref = dest->getPageRef();
                page = catalog.findPage(pageref.num, pageref.gen);
            } else page = dest->getPageNum();
            delete dest;
        }

        _href = QString("bkm://") + pageLinkName(page);
//        kdDebug(30516) << "link to page " << page << endl;
        break;
    }

    case actionGoToR: {
        LinkGoToR &lgotor = static_cast<LinkGoToR &>(action);
        _href = "file://";
        if ( lgotor.getFileName() )
            _href += lgotor.getFileName()->getCString();
        int page = 1;
        if ( lgotor.getDest() ) {
            LinkDest *dest = lgotor.getDest()->copy();
            if ( !dest->isPageRef() ) page = dest->getPageNum();
            delete dest;
        }

        kdDebug(30516) << "link to filename \"" << _href << "\" (page "
                       << page << ")" <<endl;
        break;
    }

    case actionLaunch: {
        LinkLaunch &llaunch = static_cast<LinkLaunch &>(action);
        _href = "file://";
        if ( llaunch.getFileName() )
            _href += llaunch.getFileName()->getCString();

        kdDebug(30516) << "link to launch/open \"" << _href << "\"" << endl;
        break;
    }

    case actionURI: {
        LinkURI &luri = static_cast<LinkURI &>(action);
        if ( luri.getURI() ) _href = luri.getURI()->getCString();

        kdDebug(30516) << "link to URI \"" << _href << "\"" << endl;
        break;
    }

    case actionMovie:
    case actionNamed:
    case actionUnknown:
        kdDebug(30516) << "unsupported link=" << action.getKind() << endl;
        break;
    }
}