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