Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
12 : * GNU Lesser General Public License Version 2.1
13 : * =============================================
14 : * Copyright 2000 by Sun Microsystems, Inc.
15 : * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 : *
17 : * This library is free software; you can redistribute it and/or
18 : * modify it under the terms of the GNU Lesser General Public
19 : * License version 2.1, as published by the Free Software Foundation.
20 : *
21 : * This library is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 : * Lesser General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU Lesser General Public
27 : * License along with this library; if not, write to the Free Software
28 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 : * MA 02111-1307 USA
30 : *
31 : *
32 : * Sun Industry Standards Source License Version 1.1
33 : * =================================================
34 : * The contents of this file are subject to the Sun Industry Standards
35 : * Source License Version 1.1 (the "License"); You may not use this file
36 : * except in compliance with the License. You may obtain a copy of the
37 : * License at http://www.openoffice.org/license.html.
38 : *
39 : * Software provided under this License is provided on an "AS IS" basis,
40 : * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 : * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 : * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 : * See the License for the specific provisions governing your rights and
44 : * obligations concerning the Software.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : /*************************************************************************
57 : * @file
58 : * Represente index source,index body and index index entry.
59 : ************************************************************************/
60 : #include "xfindex.hxx"
61 : #include "xfparagraph.hxx"
62 :
63 0 : XFIndex::XFIndex()
64 : {
65 0 : m_pTitle = NULL;
66 0 : m_eType = enumXFIndexTOC;
67 0 : m_bProtect = true;
68 0 : m_bSeparator = false;
69 0 : m_nMaxLevel = 0;
70 :
71 0 : for(sal_uInt16 i=1;i<MAX_TOC_LEVEL+1;i++)
72 : {
73 0 : m_aTOCSource[i].clear();
74 : }
75 0 : }
76 :
77 0 : XFIndex::~XFIndex()
78 : {
79 0 : if( m_pTitle )
80 0 : delete m_pTitle;
81 :
82 0 : for(sal_uInt16 i=1;i<MAX_TOC_LEVEL+1;i++)
83 : {
84 0 : m_aTOCSource[i].clear();
85 : }
86 :
87 0 : while(m_aTemplates.size()>0)
88 : {
89 0 : XFIndexTemplate * pTemplate = m_aTemplates.back();
90 0 : m_aTemplates.pop_back();
91 0 : delete pTemplate;pTemplate=NULL;
92 : }
93 0 : }
94 :
95 0 : void XFIndex::AddTemplate(const OUString& level, const OUString& style, XFIndexTemplate* templ)
96 : {
97 0 : templ->SetLevel( level );
98 0 : if(m_eType != enumXFIndexTOC) // TOC's styles are applied to template entries separately
99 : {
100 0 : templ->SetStyleName( style );
101 : }
102 0 : m_aTemplates.push_back( templ );
103 0 : }
104 :
105 0 : void XFIndex::SetProtected(bool protect)
106 : {
107 0 : m_bProtect = protect;
108 0 : }
109 :
110 0 : void XFIndex::SetSeparator(bool sep)
111 : {
112 0 : m_bSeparator = sep;
113 0 : }
114 :
115 0 : void XFIndex::AddTocSource(sal_uInt16 nLevel, const OUString& sStyleName)
116 : {
117 0 : if (nLevel > MAX_TOC_LEVEL)
118 : {
119 0 : return;
120 : }
121 :
122 0 : m_aTOCSource[nLevel].push_back(sStyleName);
123 : }
124 :
125 0 : void XFIndex::ToXml(IXFStream *pStrm)
126 : {
127 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
128 0 : pAttrList->Clear();
129 0 : OUString strIndexName;
130 0 : OUString strTplName;
131 0 : OUString strSourceName;
132 :
133 0 : if(m_eType == enumXFIndexTOC )
134 : {
135 0 : strIndexName = "text:table-of-content";
136 0 : strSourceName = "text:table-of-content-source";
137 0 : strTplName = "text:table-of-content-entry-template";
138 : }
139 0 : else if( m_eType == enumXFIndexAlphabetical )
140 : {
141 0 : strIndexName = "text:alphabetical-index";
142 0 : strSourceName = "text:alphabetical-index-source";
143 0 : strTplName = "text:alphabetical-index-entry-template";
144 : }
145 0 : else if( m_eType == enumXFIndexUserIndex )
146 : {
147 0 : strIndexName = "text:user-index";
148 0 : strSourceName = "text:text:user-index-source";
149 0 : strTplName = "text:user-index-entry-template";
150 : }
151 0 : else if( m_eType == enumXFIndexObject )
152 : {
153 0 : strIndexName = "text:object-index";
154 0 : strSourceName = "text:object-index-source";
155 0 : strTplName = "text:object-index-entry-template";
156 : }
157 0 : else if( m_eType == enumXFIndexIllustration )
158 : {
159 0 : strIndexName = "text:illustration-index";
160 0 : strSourceName = "text:illustration-index-source";
161 0 : strTplName = "text:illustration-index-entry-template";
162 : }
163 0 : else if( m_eType == enumXFIndexTableIndex )
164 : {
165 0 : strIndexName = "text:table-index";
166 0 : strSourceName = "text:table-index-source";
167 0 : strTplName = "text:table-index-entry-template";
168 : }
169 :
170 0 : if( !GetStyleName().isEmpty() )
171 0 : pAttrList->AddAttribute( "text:style-name", GetStyleName() );
172 0 : if( m_bProtect )
173 0 : pAttrList->AddAttribute( "text:protected", "true" );
174 : else
175 0 : pAttrList->AddAttribute( "text:protected", "false" );
176 :
177 0 : pAttrList->AddAttribute( "text:name", m_strTitle );
178 0 : pStrm->StartElement( strIndexName );
179 :
180 : //text:table-of-content-source:
181 0 : pAttrList->Clear();
182 :
183 0 : if(m_eType == enumXFIndexTOC )
184 : {
185 0 : pAttrList->AddAttribute( "text:outline-level", OUString::number(10));
186 0 : pAttrList->AddAttribute( "text:use-index-source-styles", "true");
187 0 : pAttrList->AddAttribute( "text:use-index-marks", "true");
188 0 : pAttrList->AddAttribute( "text:use-outline-level", "false");
189 : }
190 0 : if (m_bSeparator)
191 0 : pAttrList->AddAttribute( "text:alphabetical-separators", "true" );
192 :
193 0 : pStrm->StartElement( strSourceName );
194 : //title template:
195 0 : pAttrList->Clear();
196 :
197 0 : pStrm->StartElement( "text:index-title-template" );
198 0 : pStrm->Characters( m_strTitle );
199 0 : pStrm->EndElement( "text:index-title-template" );
200 :
201 : //entry templates:
202 0 : std::vector<XFIndexTemplate *>::iterator it;
203 0 : for (it = m_aTemplates.begin(); it != m_aTemplates.end(); ++it)
204 : {
205 0 : (*it)->SetTagName( strTplName);
206 0 : (*it)->ToXml(pStrm);
207 : }
208 :
209 : // by
210 0 : if(m_eType == enumXFIndexTOC )
211 : {
212 0 : for(sal_uInt16 i=1; i <= MAX_TOC_LEVEL; i++)
213 : {
214 0 : if (m_aTOCSource[i].empty())
215 : {
216 : // unnecessary to output this level
217 0 : continue;
218 : }
219 :
220 0 : pAttrList->Clear();
221 0 : pAttrList->AddAttribute( "text:outline-level", OUString::number(i));
222 0 : pStrm->StartElement( "text:index-source-styles" );
223 :
224 0 : std::vector<OUString>::iterator it_str;
225 0 : for (it_str = m_aTOCSource[i].begin(); it_str != m_aTOCSource[i].end(); ++it_str)
226 : {
227 0 : pAttrList->Clear();
228 0 : pAttrList->AddAttribute( "text:style-name", *it_str);
229 0 : pStrm->StartElement( "text:index-source-style" );
230 0 : pStrm->EndElement( "text:index-source-style" );
231 : }
232 0 : pStrm->EndElement( "text:index-source-styles" );
233 : }
234 : }
235 :
236 0 : pStrm->EndElement( strSourceName );
237 :
238 : //index-body:
239 0 : pAttrList->Clear();
240 0 : pStrm->StartElement( "text:index-body" );
241 : //index-title:
242 0 : if(!m_strTitle.isEmpty())
243 : {
244 0 : pAttrList->AddAttribute( "text:name", m_strTitle + "_Head" );
245 0 : pStrm->StartElement( "text:index-title" );
246 0 : if( m_pTitle )
247 0 : m_pTitle->ToXml(pStrm);
248 0 : pStrm->EndElement( "text:index-title" );
249 : }
250 :
251 0 : XFContentContainer::ToXml(pStrm);
252 0 : pStrm->EndElement( "text:index-body" );
253 :
254 0 : pStrm->EndElement( strIndexName );
255 0 : }
256 :
257 0 : void XFIndexTemplate::ToXml(IXFStream *pStrm)
258 : {
259 0 : IXFAttrList *pAttrList = pStrm->GetAttrList();
260 0 : pAttrList->Clear();
261 :
262 0 : pAttrList->AddAttribute( "text:outline-level", m_nLevel );
263 0 : pAttrList->AddAttribute( "text:style-name", m_strStyle );
264 0 : if( m_strTagName.isEmpty() )
265 0 : m_strTagName = "text:table-of-content-entry-template";
266 0 : pStrm->StartElement( m_strTagName );
267 :
268 0 : for( size_t i=0; i<m_aEntries.size(); i++ )
269 : {
270 0 : pAttrList->Clear();
271 :
272 0 : switch( m_aEntries[i].first )
273 : {
274 : case enumXFIndexTemplateChapter:
275 0 : if(!m_aEntries[i].second.isEmpty())
276 0 : pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
277 :
278 0 : pStrm->StartElement( "text:index-entry-chapter-number" );
279 0 : pStrm->EndElement( "text:index-entry-chapter-number" );
280 0 : break;
281 : case enumXFIndexTemplateText:
282 0 : if(!m_aEntries[i].second.isEmpty())
283 0 : pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
284 :
285 0 : pStrm->StartElement( "text:index-entry-text" );
286 0 : pStrm->EndElement( "text:index-entry-text" );
287 0 : break;
288 : case enumXFIndexTemplateTab:
289 0 : if( m_eTabType != enumXFTabRight )
290 0 : pAttrList->AddAttribute( "style:position", OUString::number(m_fTabLength) + "cm" );
291 :
292 0 : if(!m_aEntries[i].second.isEmpty())
293 0 : pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
294 :
295 0 : switch(m_eTabType)
296 : {
297 : case enumXFTabLeft:
298 0 : pAttrList->AddAttribute( "style:type", "left" );
299 0 : break;
300 : case enumXFTabCenter:
301 0 : pAttrList->AddAttribute( "style:type", "center" );
302 0 : break;
303 : case enumXFTabRight:
304 0 : pAttrList->AddAttribute( "style:type", "right" );
305 0 : break;
306 : case enumXFTabChar:
307 0 : pAttrList->AddAttribute( "style:type", "char" );
308 0 : break;
309 : default:
310 0 : break;
311 : }
312 : //delimiter:
313 0 : if( m_eTabType == enumXFTabChar )
314 0 : pAttrList->AddAttribute( "style:char", m_strTabDelimiter );
315 : //leader char:
316 0 : if( !m_strTabLeader.isEmpty() )
317 0 : pAttrList->AddAttribute( "style:leader-char", m_strTabLeader );
318 :
319 0 : pStrm->StartElement( "text:index-entry-tab-stop" );
320 0 : pStrm->EndElement( "text:index-entry-tab-stop" );
321 0 : break;
322 : case enumXFIndexTemplatePage:
323 0 : if(!m_aEntries[i].second.isEmpty())
324 0 : pAttrList->AddAttribute( "text:style-name", m_aEntries[i].second );
325 :
326 0 : pStrm->StartElement( "text:index-entry-page-number" );
327 0 : pStrm->EndElement( "text:index-entry-page-number" );
328 0 : break;
329 : case enumXFIndexTemplateLinkStart:
330 0 : pStrm->StartElement( "text:index-entry-link-start" );
331 0 : pStrm->EndElement( "text:index-entry-link-start" );
332 0 : break;
333 : case enumXFIndexTemplateLinkEnd:
334 0 : pStrm->StartElement( "text:index-entry-link-end" );
335 0 : pStrm->EndElement( "text:index-entry-link-end" );
336 0 : break;
337 : case enumXFIndexTemplateSpan:
338 0 : pAttrList->Clear();
339 0 : pAttrList->AddAttribute("text:style-name", GetStyleName());
340 0 : pStrm->StartElement( "text:index-entry-span" );
341 0 : pStrm->Characters(m_aTextEntries[i]);
342 0 : pStrm->EndElement( "text:index-entry-span" );
343 0 : break;
344 : case enumXFIndexTemplateBibliography:
345 0 : pStrm->StartElement( "text:index-entry-bibliography" );
346 0 : pStrm->EndElement( "text:index-entry-bibliography" );
347 0 : break;
348 : default:
349 0 : break;
350 : }
351 : }
352 :
353 0 : pStrm->EndElement( m_strTagName );
354 0 : }
355 :
356 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|