1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <vcl/EnumContext.hxx>
21 #include <osl/diagnose.h>
29 typedef ::std::map
<rtl::OUString
,EnumContext::Application
> ApplicationMap
;
31 static ApplicationMap maApplicationMap
;
32 static ::std::vector
<rtl::OUString
> maApplicationVector
;
34 typedef ::std::map
<rtl::OUString
,EnumContext::Context
> ContextMap
;
36 static ContextMap maContextMap
;
37 static ::std::vector
<rtl::OUString
> maContextVector
;
41 const sal_Int32
EnumContext::NoMatch
= 4;
42 const sal_Int32
EnumContext::OptimalMatch
= 0; // Neither application nor context name is "any".
44 EnumContext::EnumContext()
45 : meApplication(Application_None
),
46 meContext(Context_Unknown
)
50 EnumContext::EnumContext (
51 const Application eApplication
,
52 const Context eContext
)
53 : meApplication(eApplication
),
58 EnumContext::EnumContext (
59 const ::rtl::OUString
& rsApplicationName
,
60 const ::rtl::OUString
& rsContextName
)
61 : meApplication(GetApplicationEnum(rsApplicationName
)),
62 meContext(GetContextEnum(rsContextName
))
66 sal_Int32
EnumContext::GetCombinedContext_DI() const
68 return CombinedEnumContext(GetApplication_DI(), meContext
);
71 EnumContext::Application
EnumContext::GetApplication_DI() const
73 switch (meApplication
)
75 case Application_Draw
:
76 case Application_Impress
:
77 return Application_DrawImpress
;
79 case Application_Writer
:
80 case Application_WriterGlobal
:
81 case Application_WriterWeb
:
82 case Application_WriterXML
:
83 case Application_WriterForm
:
84 case Application_WriterReport
:
85 return Application_WriterVariants
;
92 bool EnumContext::operator== (const EnumContext
& rOther
)
94 return meApplication
==rOther
.meApplication
95 && meContext
==rOther
.meContext
;
98 bool EnumContext::operator!= (const EnumContext
& rOther
)
100 return meApplication
!=rOther
.meApplication
101 || meContext
!=rOther
.meContext
;
104 void EnumContext::AddEntry (const ::rtl::OUString
& rsName
, const Application eApplication
)
106 maApplicationMap
[rsName
] = eApplication
;
107 OSL_ASSERT(eApplication
<=LastApplicationEnum
);
108 if (maApplicationVector
.size() <= size_t(eApplication
))
109 maApplicationVector
.resize(eApplication
+1);
110 maApplicationVector
[eApplication
]=rsName
;
113 void EnumContext::ProvideApplicationContainers()
115 if (maApplicationMap
.empty())
117 maApplicationVector
.resize(static_cast<size_t>(EnumContext::LastApplicationEnum
)+1);
118 AddEntry("com.sun.star.text.TextDocument", EnumContext::Application_Writer
);
119 AddEntry("com.sun.star.text.GlobalDocument", EnumContext::Application_WriterGlobal
);
120 AddEntry("com.sun.star.text.WebDocument", EnumContext::Application_WriterWeb
);
121 AddEntry("com.sun.star.xforms.XMLFormDocument", EnumContext::Application_WriterXML
);
122 AddEntry("com.sun.star.sdb.FormDesign", EnumContext::Application_WriterForm
);
123 AddEntry("com.sun.star.sdb.TextReportDesign", EnumContext::Application_WriterReport
);
124 AddEntry("com.sun.star.sheet.SpreadsheetDocument", EnumContext::Application_Calc
);
125 AddEntry("com.sun.star.chart2.ChartDocument", EnumContext::Application_Chart
);
126 AddEntry("com.sun.star.drawing.DrawingDocument", EnumContext::Application_Draw
);
127 AddEntry("com.sun.star.presentation.PresentationDocument", EnumContext::Application_Impress
);
129 AddEntry("any", EnumContext::Application_Any
);
130 AddEntry("none", EnumContext::Application_None
);
134 EnumContext::Application
EnumContext::GetApplicationEnum (const ::rtl::OUString
& rsApplicationName
)
136 ProvideApplicationContainers();
138 ApplicationMap::const_iterator
iApplication(
139 maApplicationMap
.find(rsApplicationName
));
140 if (iApplication
!= maApplicationMap
.end())
141 return iApplication
->second
;
143 return EnumContext::Application_None
;
146 const ::rtl::OUString
& EnumContext::GetApplicationName (const Application eApplication
)
148 ProvideApplicationContainers();
150 const sal_Int32
nIndex (eApplication
);
151 if (nIndex
<0 || nIndex
>= LastApplicationEnum
)
152 return maApplicationVector
[Application_None
];
154 return maApplicationVector
[nIndex
];
157 void EnumContext::AddEntry (const ::rtl::OUString
& rsName
, const Context eApplication
)
159 maContextMap
[rsName
] = eApplication
;
160 OSL_ASSERT(eApplication
<=LastContextEnum
);
161 if (maContextVector
.size() <= size_t(eApplication
))
162 maContextVector
.resize(eApplication
+1);
163 maContextVector
[eApplication
] = rsName
;
166 void EnumContext::ProvideContextContainers()
168 if (maContextMap
.empty())
170 maContextVector
.resize(static_cast<size_t>(LastContextEnum
)+1);
171 AddEntry("any", Context_Any
);
172 AddEntry("default", Context_Default
);
173 AddEntry("empty", Context_Empty
);
174 AddEntry("3DObject", Context_3DObject
);
175 AddEntry("Annotation", Context_Annotation
);
176 AddEntry("Auditing", Context_Auditing
);
177 AddEntry("Axis", Context_Axis
);
178 AddEntry("Cell", Context_Cell
);
179 AddEntry("Chart", Context_Chart
);
180 AddEntry("ChartElements", Context_ChartElements
);
181 AddEntry("Draw", Context_Draw
);
182 AddEntry("DrawLine", Context_DrawLine
);
183 AddEntry("DrawPage", Context_DrawPage
);
184 AddEntry("DrawText", Context_DrawText
);
185 AddEntry("EditCell", Context_EditCell
);
186 AddEntry("ErrorBar", Context_ErrorBar
);
187 AddEntry("Form", Context_Form
);
188 AddEntry("Frame", Context_Frame
);
189 AddEntry("Graphic", Context_Graphic
);
190 AddEntry("Grid", Context_Grid
);
191 AddEntry("HandoutPage", Context_HandoutPage
);
192 AddEntry("MasterPage", Context_MasterPage
);
193 AddEntry("Media", Context_Media
);
194 AddEntry("MultiObject", Context_MultiObject
);
195 AddEntry("NotesPage", Context_NotesPage
);
196 AddEntry("OLE", Context_OLE
);
197 AddEntry("OutlineText", Context_OutlineText
);
198 AddEntry("Pivot", Context_Pivot
);
199 AddEntry("Series", Context_Series
);
200 AddEntry("SlidesorterPage", Context_SlidesorterPage
);
201 AddEntry("Table", Context_Table
);
202 AddEntry("Text", Context_Text
);
203 AddEntry("TextObject", Context_TextObject
);
204 AddEntry("Trendline", Context_Trendline
);
208 EnumContext::Context
EnumContext::GetContextEnum (const ::rtl::OUString
& rsContextName
)
210 ProvideContextContainers();
212 ContextMap::const_iterator
iContext( maContextMap
.find(rsContextName
) );
213 if (iContext
!= maContextMap
.end())
214 return iContext
->second
;
216 return EnumContext::Context_Unknown
;
219 const ::rtl::OUString
& EnumContext::GetContextName (const Context eContext
)
221 ProvideContextContainers();
223 const sal_Int32
nIndex (eContext
);
224 if (nIndex
<0 || nIndex
>= LastContextEnum
)
225 return maContextVector
[Context_Unknown
];
227 return maContextVector
[nIndex
];
230 } // end of namespace vcl
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */