Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "../inc/wwstyles.hxx"
31 : :
32 : : #include <functional> //std::unary_function
33 : : #include <algorithm> //std::find_if
34 : : #include <tools/string.hxx> //do we have to...
35 : :
36 : : #include "staticassert.hxx" //StaticAssert
37 : :
38 : : namespace
39 : : {
40 : : class SameName: public std::unary_function<const sal_Char*, bool>
41 : : {
42 : : private:
43 : : const String &mrName;
44 : : public:
45 : 0 : explicit SameName(const String &rName) : mrName(rName) {}
46 : 0 : bool operator() (const sal_Char *pEntry) const
47 : 0 : { return mrName.EqualsAscii(pEntry); }
48 : : };
49 : :
50 : 0 : const sal_Char **GetStiNames() throw()
51 : : {
52 : : static const sal_Char *stiName[] =
53 : : {
54 : : "Normal",
55 : : "Heading 1",
56 : : "Heading 2",
57 : : "Heading 3",
58 : : "Heading 4",
59 : : "Heading 5",
60 : : "Heading 6",
61 : : "Heading 7",
62 : : "Heading 8",
63 : : "Heading 9",
64 : : "Index 1",
65 : : "Index 2",
66 : : "Index 3",
67 : : "Index 4",
68 : : "Index 5",
69 : : "Index 6",
70 : : "Index 7",
71 : : "Index 8",
72 : : "Index 9",
73 : : "TOC 1",
74 : : "TOC 2",
75 : : "TOC 3",
76 : : "TOC 4",
77 : : "TOC 5",
78 : : "TOC 6",
79 : : "TOC 7",
80 : : "TOC 8",
81 : : "TOC 9",
82 : : "Normal Indent",
83 : : "Footnote Text",
84 : : "Annotation Text",
85 : : "Header",
86 : : "Footer",
87 : : "Index Heading",
88 : : "Caption",
89 : : "Table of Figures",
90 : : "Envelope Address",
91 : : "Envelope Return",
92 : : "Footnote Reference",
93 : : "Annotation Reference",
94 : : "Line Number",
95 : : "Page Number",
96 : : "Endnote Reference",
97 : : "Endnote Text",
98 : : "Table of Authorities",
99 : : "Macro Text",
100 : : "TOA Heading",
101 : : "List",
102 : : "List 2",
103 : : "List 3",
104 : : "List 4",
105 : : "List 5",
106 : : "List Bullet",
107 : : "List Bullet 2",
108 : : "List Bullet 3",
109 : : "List Bullet 4",
110 : : "List Bullet 5",
111 : : "List Number",
112 : : "List Number 2",
113 : : "List Number 3",
114 : : "List Number 4",
115 : : "List Number 5",
116 : : "Title",
117 : : "Closing",
118 : : "Signature",
119 : : "Default Paragraph Font",
120 : : "Body Text",
121 : : "Body Text Indent",
122 : : "List Continue",
123 : : "List Continue 2",
124 : : "List Continue 3",
125 : : "List Continue 4",
126 : : "List Continue 5",
127 : : "Message Header",
128 : : "Subtitle",
129 : : "Salutation",
130 : : "Date",
131 : : "Body Text First Indent",
132 : : "Body Text First Indent 2",
133 : : "Note Heading",
134 : : "Body Text 2",
135 : : "Body Text 3",
136 : : "Body Text Indent 2",
137 : : "Body Text Indent 3",
138 : : "Block Text",
139 : : "Hyperlink",
140 : : "Followed Hyperlink",
141 : : "Strong",
142 : : "Emphasis",
143 : : "Document Map",
144 : : "Plain Text"
145 : : };
146 : :
147 : : OSL_ENSURE( (sizeof (stiName) / sizeof (stiName[0])) == ww::stiMax, "WrongSizeOfArray" );
148 : :
149 : 0 : return stiName;
150 : : }
151 : : }
152 : :
153 : : namespace ww
154 : : {
155 : : //Original code/idea by Takashi Ono for CJK
156 : 0 : sti GetCanonicalStiFromEnglishName(const String &rName) throw()
157 : : {
158 : : typedef const sal_Char** myIter;
159 : 0 : sti eRet = stiUser;
160 : 0 : myIter aBegin = GetStiNames();
161 : 0 : myIter aEnd(aBegin);
162 [ # # ]: 0 : std::advance(aEnd, stiMax);
163 [ # # ]: 0 : myIter aIter = std::find_if(aBegin, aEnd, SameName(rName));
164 [ # # ]: 0 : if (aIter != aEnd)
165 [ # # ]: 0 : eRet = static_cast<sti>(std::distance(aBegin, aIter));
166 : 0 : return eRet;
167 : : }
168 : :
169 : 0 : const sal_Char* GetEnglishNameFromSti(sti eSti) throw()
170 : : {
171 [ # # ]: 0 : if (eSti >= stiMax)
172 : 0 : return 0;
173 : : else
174 : 0 : return GetStiNames()[eSti];
175 : : }
176 : :
177 : 0 : bool StandardStiIsCharStyle(sti eSti) throw()
178 : : {
179 [ # # ]: 0 : switch (eSti)
180 : : {
181 : : case stiFtnRef:
182 : : case stiAtnRef:
183 : : case stiLnn:
184 : : case stiPgn:
185 : : case stiEdnRef:
186 : : case stiNormalChar:
187 : 0 : return true;
188 : : default:
189 : 0 : return false;
190 : : }
191 : : }
192 : :
193 : 0 : sti GetCanonicalStiFromStc(sal_uInt8 stc) throw()
194 : : {
195 [ # # ]: 0 : if (stc == 0)
196 : 0 : return stiNormal;
197 [ # # ]: 0 : else if (stc < 222)
198 : 0 : return stiUser;
199 : : else
200 : : {
201 : : static sti aMapping[] =
202 : : {
203 : : stiNil, stiAtnRef, stiAtnText, stiToc8, stiToc7, stiToc6,
204 : : stiToc5, stiToc4, stiToc3, stiToc2, stiToc1, stiIndex7,
205 : : stiIndex6, stiIndex5, stiIndex4, stiIndex3, stiIndex2,
206 : : stiIndex1, stiLnn, stiIndexHeading, stiFooter, stiHeader,
207 : : stiFtnRef, stiFtnText, stiLev9, stiLev8, stiLev7, stiLev6,
208 : : stiLev5, stiLev4, stiLev3, stiLev2, stiLev1, stiNormIndent
209 : : };
210 : 0 : return aMapping[stc-222];
211 : : }
212 : : }
213 : : }
214 : :
215 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|