bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / window / EnumContext.cxx
blob78bd6cbc675bf53becbea31104a49ce75ca6b43a
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 static ApplicationMap maApplicationMap;
33 static o3tl::enumarray<EnumContext::Application, OUString> maApplicationVector;
35 typedef ::std::map<OUString,EnumContext::Context> ContextMap;
37 static ContextMap maContextMap;
38 static o3tl::enumarray<EnumContext::Context, OUString> maContextVector;
42 const sal_Int32 EnumContext::NoMatch = 4;
43 const sal_Int32 EnumContext::OptimalMatch = 0; // Neither application nor context name is "any".
45 EnumContext::EnumContext()
46 : meApplication(Application::NONE),
47 meContext(Context::Unknown)
51 EnumContext::EnumContext (
52 const Application eApplication,
53 const Context eContext)
54 : meApplication(eApplication),
55 meContext(eContext)
59 sal_Int32 EnumContext::GetCombinedContext_DI() const
61 return CombinedEnumContext(GetApplication_DI(), meContext);
64 EnumContext::Application EnumContext::GetApplication_DI() const
66 switch (meApplication)
68 case Application::Draw:
69 case Application::Impress:
70 return Application::DrawImpress;
72 case Application::Writer:
73 case Application::WriterGlobal:
74 case Application::WriterWeb:
75 case Application::WriterXML:
76 case Application::WriterForm:
77 case Application::WriterReport:
78 return Application::WriterVariants;
80 default:
81 return meApplication;
85 bool EnumContext::operator== (const EnumContext& rOther)
87 return meApplication==rOther.meApplication
88 && meContext==rOther.meContext;
91 bool EnumContext::operator!= (const EnumContext& rOther)
93 return meApplication!=rOther.meApplication
94 || meContext!=rOther.meContext;
97 void EnumContext::AddEntry (const OUString& rsName, const Application eApplication)
99 maApplicationMap[rsName] = eApplication;
100 OSL_ASSERT(eApplication<=Application::LAST);
101 maApplicationVector[eApplication]=rsName;
104 void EnumContext::ProvideApplicationContainers()
106 if (!maApplicationMap.empty())
107 return;
109 AddEntry("com.sun.star.text.TextDocument", EnumContext::Application::Writer);
110 AddEntry("com.sun.star.text.GlobalDocument", EnumContext::Application::WriterGlobal);
111 AddEntry("com.sun.star.text.WebDocument", EnumContext::Application::WriterWeb);
112 AddEntry("com.sun.star.xforms.XMLFormDocument", EnumContext::Application::WriterXML);
113 AddEntry("com.sun.star.sdb.FormDesign", EnumContext::Application::WriterForm);
114 AddEntry("com.sun.star.sdb.TextReportDesign", EnumContext::Application::WriterReport);
115 AddEntry("com.sun.star.sheet.SpreadsheetDocument", EnumContext::Application::Calc);
116 AddEntry("com.sun.star.chart2.ChartDocument", EnumContext::Application::Chart);
117 AddEntry("com.sun.star.drawing.DrawingDocument", EnumContext::Application::Draw);
118 AddEntry("com.sun.star.presentation.PresentationDocument", EnumContext::Application::Impress);
119 AddEntry("com.sun.star.formula.FormulaProperties", EnumContext::Application::Formula);
120 AddEntry("com.sun.star.sdb.OfficeDatabaseDocument", EnumContext::Application::Base);
121 AddEntry("any", EnumContext::Application::Any);
122 AddEntry("none", EnumContext::Application::NONE);
126 EnumContext::Application EnumContext::GetApplicationEnum (const OUString& rsApplicationName)
128 ProvideApplicationContainers();
130 ApplicationMap::const_iterator iApplication(
131 maApplicationMap.find(rsApplicationName));
132 if (iApplication != maApplicationMap.end())
133 return iApplication->second;
134 else
135 return EnumContext::Application::NONE;
138 const OUString& EnumContext::GetApplicationName (const Application eApplication)
140 ProvideApplicationContainers();
141 return maApplicationVector[eApplication];
144 void EnumContext::AddEntry (const OUString& rsName, const Context eContext)
146 maContextMap[rsName] = eContext;
147 maContextVector[eContext] = rsName;
150 void EnumContext::ProvideContextContainers()
152 if (!maContextMap.empty())
153 return;
155 AddEntry("3DObject", Context::ThreeDObject);
156 AddEntry("Annotation", Context::Annotation);
157 AddEntry("Auditing", Context::Auditing);
158 AddEntry("Axis", Context::Axis);
159 AddEntry("Cell", Context::Cell);
160 AddEntry("Chart", Context::Chart);
161 AddEntry("ChartElements", Context::ChartElements);
162 AddEntry("Draw", Context::Draw);
163 AddEntry("DrawLine", Context::DrawLine);
164 AddEntry("DrawPage", Context::DrawPage);
165 AddEntry("DrawText", Context::DrawText);
166 AddEntry("EditCell", Context::EditCell);
167 AddEntry("ErrorBar", Context::ErrorBar);
168 AddEntry("Form", Context::Form);
169 AddEntry("Frame", Context::Frame);
170 AddEntry("Graphic", Context::Graphic);
171 AddEntry("Grid", Context::Grid);
172 AddEntry("HandoutPage", Context::HandoutPage);
173 AddEntry("MasterPage", Context::MasterPage);
174 AddEntry("Media", Context::Media);
175 AddEntry("MultiObject", Context::MultiObject);
176 AddEntry("NotesPage", Context::NotesPage);
177 AddEntry("OLE", Context::OLE);
178 AddEntry("OutlineText", Context::OutlineText);
179 AddEntry("Pivot", Context::Pivot);
180 AddEntry("Printpreview", Context::Printpreview);
181 AddEntry("Series", Context::Series);
182 AddEntry("SlidesorterPage", Context::SlidesorterPage);
183 AddEntry("Table", Context::Table);
184 AddEntry("Text", Context::Text);
185 AddEntry("TextObject", Context::TextObject);
186 AddEntry("Trendline", Context::Trendline);
188 // other general contexts
189 AddEntry("any", Context::Any);
190 AddEntry("default", Context::Default);
191 AddEntry("empty", Context::Empty);
194 EnumContext::Context EnumContext::GetContextEnum (const OUString& rsContextName)
196 ProvideContextContainers();
198 ContextMap::const_iterator iContext( maContextMap.find(rsContextName) );
199 if (iContext != maContextMap.end())
200 return iContext->second;
201 else
202 return EnumContext::Context::Unknown;
205 const OUString& EnumContext::GetContextName (const Context eContext)
207 ProvideContextContainers();
208 return maContextVector[eContext];
211 } // end of namespace vcl
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */