/*
 * Copyright (c) 2017-2023 XMLmind Software. All rights reserved.
 *
 * This file is part of the XMLmind XML Editor project.
 * For conditions of distribution and use, see the accompanying legal.txt file.
 *
 * Displays the TOC of a DocBook document.
 */

@import "inline.imp";

*,
*:comment,
*:processing-instruction,
set > *,
book > *,
part > *,
reference > *,
preface > *,
chapter > *,
article > *,
appendix > *,
section > *,
sect1 > *,
sect2 > *,
sect3 > *,
sect4 > *,
sect5 > *,
setinfo > *,
bookinfo > *,
partinfo > *,
referenceinfo > *,
prefaceinfo > *,
chapterinfo > *,
articleinfo > *,
appendixinfo > *,
sectioninfo > *,
sect1info > *,
sect2info > *,
sect3info > *,
sect4info > *,
sect5info > * {
    display: none;
}

set,
book,
part,
reference,
preface,
chapter,
article,
appendix {
    display: block;
    collapsible: yes;
    not-collapsible-head: 1; /* title or metainfo */
    margin-top: 0.5ex;
    margin-left: 4ex;
}

refentry {
    display: block;
    content: "RefEntry: " xpath("join(.//refname, ', ')");
    margin-left: 4ex;
}

/* Unlike dedication, toc, etc, which are leaves with an optional title,
   partintro may contain sections. But we'll not show them here. */
partintro,
dedication,
toc,
lot,
bibliography,
index,
setindex,
colophon,
glossary {
    display: block;
    margin-left: 4ex;
}

partintro {
    content: xpath("if(./title, string(./title), 'Introduction')");
}

dedication {
    content: xpath("if(./title, string(./title), 'Dedication')");
}

toc {
    content: xpath("if(./title, string(./title), 'Contents')");
}

lot {
    content: xpath("if(./title, string(./title), 'List of Figures')");
}

bibliography {
    content: xpath("if(./bibliographyinfo/title, string(./bibliographyinfo/title), ./title, string(./title), 'Bibliography')");
}

index {
    content: xpath("if(./indexinfo/title, string(./indexinfo/title), ./title, string(./title), 'Index')");
}

setindex {
    content: xpath("if(./setindexinfo/title, string(./setindexinfo/title), ./title, string(./title), 'Index')");
}

colophon {
    content: xpath("if(./title, string(./title), 'Colophon')");
}

glossary {
    content: xpath("if(./glossaryinfo/title, string(./glossaryinfo/title), ./title, string(./title), 'Glossary')");
}

section,
sect1,
sect2,
sect3,
sect4,
sect5 {
    display: block;
    margin-left: 4ex;
}

*:root {
    margin-top: 0;
    margin-left: 0;
}

setinfo:contains-element(title),
bookinfo:contains-element(title),
partinfo:contains-element(title),
referenceinfo:contains-element(title),
prefaceinfo:contains-element(title),
chapterinfo:contains-element(title),
articleinfo:contains-element(title),
appendixinfo:contains-element(title),
sectioninfo:contains-element(title),
sect1info:contains-element(title),
sect2info:contains-element(title),
sect3info:contains-element(title),
sect4info:contains-element(title),
sect5info:contains-element(title) {
    display: block; 
}

title {
    display: block;
    margin: 0 2px; /* This trick allows to make a difference between the title 
                      and its containing division when pressing Up/Down in
                      the NavigationPane. */
}

title * {
    display: inline;
}

title indexterm {
    display: none;
}

set > title,
book > title,
part > title,
reference > title,
preface > title,
chapter > title,
article > title,
appendix > title,
setinfo > title,
bookinfo > title,
partinfo > title,
referenceinfo > title,
prefaceinfo > title,
chapterinfo > title,
articleinfo > title,
appendixinfo > title {
    font-size: 1.1em;
    font-weight: bold;
    margin-top: 0.25ex;
    margin-bottom: 0.25ex;
}

article > appendix > title,
article > appendix > appendixinfo > title {
    font-size: 1em;
    font-weight: normal;
    margin-top: 0;
    margin-bottom: 0;
}

/*
 * Title which is the first child of a division OR
 * Title following in the first (hidden) metainfo child of a division.
 */

@property-value collapserex() collapser(hide-when-disabled, yes,
                                        show-level-menu, yes);

set > title:first-child:before,
set > setinfo:first-child + title:before {
    content: collapserex() " Set: ";
}

book > title:first-child:before,
book > bookinfo:first-child + title:before {
    content: collapserex() " Book: ";
}

reference > title:first-child:before,
reference > referenceinfo:first-child + title:before {
    content: collapserex() " Reference: ";
}

preface > title:first-child:before,
preface > prefaceinfo:first-child + title:before {
    content: collapserex() " Preface: ";
}

article > title:first-child:before,
article > articleinfo:first-child + title:before {
    content: collapserex() " Article: ";
}

part > title:first-child:before,
part > partinfo:first-child + title:before { 
    content: collapserex() " Part " simple-counter(n-, upper-roman) ": "; 
}

chapter > title:first-child:before,
chapter > chapterinfo:first-child + title:before { 
    content: collapserex() " Chapter " simple-counter(n-, decimal) ": "; 
}

appendix > title:first-child:before,
appendix > appendixinfo:first-child + title:before  { 
    content: collapserex() " Appendix " simple-counter(n-, upper-alpha) ": "; 
}

article > appendix > title:first-child:before,
article > appendix > appendixinfo:first-child + title:before  { 
    content: "Appendix " simple-counter(n-, upper-alpha) ": "; 
}

sect1 > title:first-child:before,
sect1 > sect1info:first-child + title:before { 
    content: simple-counter(n-) ". "; 
}

sect2 > title:first-child:before,
sect2 > sect2info:first-child + title:before { 
    content: simple-counter(nn-) ". "; 
}

sect3 > title:first-child:before,
sect3 > sect3info:first-child + title:before { 
    content: simple-counter(nnn-) ". "; 
}

sect4 > title:first-child:before,
sect4 > sect4info:first-child + title:before { 
    content: simple-counter(nnnn-) ". "; 
}

section > title:first-child:before,
section > sectioninfo:first-child + title:before { 
    content: simple-counter(n-) ". "; 
}

section section > title:first-child:before,
section section > sectioninfo:first-child + title:before { 
    content: simple-counter(nn-) ". "; 
}

section section section > title:first-child:before,
section section section > sectioninfo:first-child + title:before { 
    content: simple-counter(nnn-) ". "; 
}

section section section section > title:first-child:before,
section section section section > sectioninfo:first-child + title:before { 
    content: simple-counter(nnnn-) ". "; 
}

section section section * section > title:first-child:before,
section section section * section > sectioninfo:first-child + title:before { 
    content: ""; 
}

/*
 * Title contained in the first metainfo child of a division.
 */

set > setinfo:first-child > title:before {
    content: collapserex() " Set: ";
}

book > bookinfo:first-child > title:before {
    content: collapserex() " Book: ";
}

reference > referenceinfo:first-child > title:before {
    content: collapserex() " Reference: ";
}

preface > prefaceinfo:first-child > title:before {
    content: collapserex() " Preface: ";
}

article > articleinfo:first-child > title:before {
    content: collapserex() " Article: ";
}

part > partinfo:first-child > title:before { 
    content: collapserex() " Part " simple-counter(n--, upper-roman) ": "; 
}

chapter > chapterinfo:first-child > title:before { 
    content: collapserex() " Chapter " simple-counter(n--, decimal) ": "; 
}

appendix > appendixinfo:first-child > title:before { 
    content: collapserex() " Appendix " simple-counter(n--, upper-alpha) ": "; 
}

sect1 > sect1info:first-child > title:before { 
    content: simple-counter(n--) ". "; 
}

sect2 > sect2info:first-child > title:before { 
    content: simple-counter(nn--) ". "; 
}

sect3 > sect3info:first-child > title:before { 
    content: simple-counter(nnn--) ". "; 
}

sect4 > sect4info:first-child > title:before { 
    content: simple-counter(nnnn--) ". "; 
}

section > sectioninfo:first-child > title:before { 
    content: simple-counter(n--) ". "; 
}

section section > sectioninfo:first-child > title:before { 
    content: simple-counter(nn--) ". "; 
}

section section section > sectioninfo:first-child > title:before { 
    content: simple-counter(nnn--) ". "; 
}

section section section section > sectioninfo:first-child > title:before { 
    content: simple-counter(nnnn--) ". "; 
}

section section section * section > sectioninfo:first-child > title:before { 
    content: ""; 
}

/*
 * Tooltip
 */

/* First ancestor having property sourceURL is at worst the document itself. */
@property-value lookup-source-url() 
    xpath("relativize-uri(property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL', ancestor-or-self::node()[property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL')][1]), property('{http://www.xmlmind.com/xmleditor/namespace/property}sourceURL', /))");

set,
book,
part,
reference,
preface,
chapter,
article,
appendix,
refentry,
partintro,
dedication,
toc,
lot,
bibliography,
index,
setindex,
colophon,
glossary,
section,
sect1,
sect2,
sect3,
sect4,
sect5 {
    tooltip-content: lookup-source-url();
}

set[id],
book[id],
part[id],
reference[id],
preface[id],
chapter[id],
article[id],
appendix[id],
refentry[id],
partintro[id],
dedication[id],
toc[id],
lot[id],
bibliography[id],
index[id],
setindex[id],
colophon[id],
glossary[id],
section[id],
sect1[id],
sect2[id],
sect3[id],
sect4[id],
sect5[id] {
    tooltip-content: lookup-source-url() "#" attr(id);
}

