nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / window / EnumContext.cxx
blob7d3d704180f4c9a5b19ce88c1e4e63f8dd2eb1d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <o3tl/enumarray.hxx>
24 #include <map>
26 namespace vcl {
28 namespace {
30 typedef ::std::map<OUString,EnumContext::Application> ApplicationMap;
32 ApplicationMap maApplicationMap;
33 o3tl::enumarray<EnumContext::Application, OUString> maApplicationVector;
35 typedef ::std::map<OUString,EnumContext::Context> ContextMap;
37 ContextMap maContextMap;
38 o3tl::enumarray<EnumContext::Context, OUString> maContextVector;
42 const sal_Int32 EnumContext::NoMatch = 4;
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),
54 meContext(eContext)
58 sal_Int32 EnumContext::GetCombinedContext_DI() const
60 return CombinedEnumContext(GetApplication_DI(), meContext);
63 EnumContext::Application EnumContext::GetApplication_DI() const
65 switch (meApplication)
67 case Application::Draw:
68 case Application::Impress:
69 return Application::DrawImpress;
71 case Application::Writer:
72 case Application::WriterGlobal:
73 case Application::WriterWeb:
74 case Application::WriterXML:
75 case Application::WriterForm:
76 case Application::WriterReport:
77 return Application::WriterVariants;
79 default:
80 return meApplication;
84 bool EnumContext::operator== (const EnumContext& rOther) const
86 return meApplication==rOther.meApplication
87 && meContext==rOther.meContext;
90 bool EnumContext::operator!= (const EnumContext& rOther) const
92 return meApplication!=rOther.meApplication
93 || meContext!=rOther.meContext;
96 void EnumContext::AddEntry (const OUString& rsName, const Application eApplication)
98 maApplicationMap[rsName] = eApplication;
99 OSL_ASSERT(eApplication<=Application::LAST);
100 maApplicationVector[eApplication]=rsName;
103 void EnumContext::ProvideApplicationContainers()
105 if (!maApplicationMap.empty())
106 return;
108 AddEntry("com.sun.star.text.TextDocument", EnumContext::Application::Writer);
109 AddEntry("com.sun.star.text.GlobalDocument", EnumContext::Application::WriterGlobal);
110 AddEntry("com.sun.star.text.WebDocument", EnumContext::Application::WriterWeb);
111 AddEntry("com.sun.star.xforms.XMLFormDocument", EnumContext::Application::WriterXML);
112 AddEntry("com.sun.star.sdb.FormDesign", EnumContext::Application::WriterForm);
113 AddEntry("com.sun.star.sdb.TextReportDesign", EnumContext::Application::WriterReport);
114 AddEntry("com.sun.star.sheet.SpreadsheetDocument", EnumContext::Application::Calc);
115 AddEntry("com.sun.star.chart2.ChartDocument", EnumContext::Application::Chart);
116 AddEntry("com.sun.star.drawing.DrawingDocument", EnumContext::Application::Draw);
117 AddEntry("com.sun.star.presentation.PresentationDocument", EnumContext::Application::Impress);
118 AddEntry("com.sun.star.formula.FormulaProperties", EnumContext::Application::Formula);
119 AddEntry("com.sun.star.sdb.OfficeDatabaseDocument", EnumContext::Application::Base);
120 AddEntry("any", EnumContext::Application::Any);
121 AddEntry("none", EnumContext::Application::NONE);
125 EnumContext::Application EnumContext::GetApplicationEnum (const OUString& rsApplicationName)
127 ProvideApplicationContainers();
129 ApplicationMap::const_iterator iApplication(
130 maApplicationMap.find(rsApplicationName));
131 if (iApplication != maApplicationMap.end())
132 return iApplication->second;
133 else
134 return EnumContext::Application::NONE;
137 const OUString& EnumContext::GetApplicationName (const Application eApplication)
139 ProvideApplicationContainers();
140 return maApplicationVector[eApplication];
143 void EnumContext::AddEntry (const OUString& rsName, const Context eContext)
145 maContextMap[rsName] = eContext;
146 maContextVector[eContext] = rsName;
149 void EnumContext::ProvideContextContainers()
151 if (!maContextMap.empty())
152 return;
154 AddEntry("3DObject", Context::ThreeDObject);
155 AddEntry("Annotation", Context::Annotation);
156 AddEntry("Auditing", Context::Auditing);
157 AddEntry("Axis", Context::Axis);
158 AddEntry("Cell", Context::Cell);
159 AddEntry("Chart", Context::Chart);
160 AddEntry("ChartElements", Context::ChartElements);
161 AddEntry("Draw", Context::Draw);
162 AddEntry("DrawLine", Context::DrawLine);
163 AddEntry("DrawPage", Context::DrawPage);
164 AddEntry("DrawText", Context::DrawText);
165 AddEntry("EditCell", Context::EditCell);
166 AddEntry("ErrorBar", Context::ErrorBar);
167 AddEntry("Form", Context::Form);
168 AddEntry("Frame", Context::Frame);
169 AddEntry("Graphic", Context::Graphic);
170 AddEntry("Grid", Context::Grid);
171 AddEntry("HandoutPage", Context::HandoutPage);
172 AddEntry("MasterPage", Context::MasterPage);
173 AddEntry("Media", Context::Media);
174 AddEntry("MultiObject", Context::MultiObject);
175 AddEntry("NotesPage", Context::NotesPage);
176 AddEntry("OLE", Context::OLE);
177 AddEntry("OutlineText", Context::OutlineText);
178 AddEntry("Pivot", Context::Pivot);
179 AddEntry("Printpreview", Context::Printpreview);
180 AddEntry("Series", Context::Series);
181 AddEntry("SlidesorterPage", Context::SlidesorterPage);
182 AddEntry("Table", Context::Table);
183 AddEntry("Text", Context::Text);
184 AddEntry("TextObject", Context::TextObject);
185 AddEntry("Trendline", Context::Trendline);
187 // other general contexts
188 AddEntry("any", Context::Any);
189 AddEntry("default", Context::Default);
190 AddEntry("empty", Context::Empty);
193 EnumContext::Context EnumContext::GetContextEnum (const OUString& rsContextName)
195 ProvideContextContainers();
197 ContextMap::const_iterator iContext( maContextMap.find(rsContextName) );
198 if (iContext != maContextMap.end())
199 return iContext->second;
200 else
201 return EnumContext::Context::Unknown;
204 const OUString& EnumContext::GetContextName (const Context eContext)
206 ProvideContextContainers();
207 return maContextVector[eContext];
210 } // end of namespace vcl
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */