LibreOffice Module vcl (master) 1
EnumContext.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include <vcl/EnumContext.hxx>
20
21#include <osl/diagnose.h>
22#include <o3tl/enumarray.hxx>
23
24#include <map>
25
26namespace vcl {
27
28namespace {
29
30typedef ::std::map<OUString,EnumContext::Application> ApplicationMap;
31
32ApplicationMap maApplicationMap;
34
35typedef ::std::map<OUString,EnumContext::Context> ContextMap;
36
37ContextMap maContextMap;
39
40}
41
42const sal_Int32 EnumContext::NoMatch = 4;
43
45 : meApplication(Application::NONE),
46 meContext(Context::Unknown)
47{
48}
49
51 const Application eApplication,
52 const Context eContext)
53 : meApplication(eApplication),
54 meContext(eContext)
55{
56}
57
59{
61}
62
64{
65 switch (meApplication)
66 {
70
78
79 default:
80 return meApplication;
81 }
82}
83
84bool EnumContext::operator== (const EnumContext& rOther) const
85{
86 return meApplication==rOther.meApplication
87 && meContext==rOther.meContext;
88}
89
90bool EnumContext::operator!= (const EnumContext& rOther) const
91{
92 return meApplication!=rOther.meApplication
93 || meContext!=rOther.meContext;
94}
95
96void EnumContext::AddEntry (const OUString& rsName, const Application eApplication)
97{
98 maApplicationMap[rsName] = eApplication;
99 OSL_ASSERT(eApplication<=Application::LAST);
100 maApplicationVector[eApplication]=rsName;
101}
102
104{
105 if (!maApplicationMap.empty())
106 return;
107
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);
122
123}
124
126{
128
129 ApplicationMap::const_iterator iApplication(
130 maApplicationMap.find(rsApplicationName));
131 if (iApplication != maApplicationMap.end())
132 return iApplication->second;
133 else
135}
136
137const OUString& EnumContext::GetApplicationName (const Application eApplication)
138{
140 return maApplicationVector[eApplication];
141}
142
143void EnumContext::AddEntry (const OUString& rsName, const Context eContext)
144{
145 maContextMap[rsName] = eContext;
146 maContextVector[eContext] = rsName;
147}
148
150{
151 if (!maContextMap.empty())
152 return;
153
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("DrawFontwork", Context::DrawFontwork);
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("Math", Context::Math);
175 AddEntry("Media", Context::Media);
176 AddEntry("MultiObject", Context::MultiObject);
177 AddEntry("NotesPage", Context::NotesPage);
178 AddEntry("OLE", Context::OLE);
179 AddEntry("OutlineText", Context::OutlineText);
180 AddEntry("Pivot", Context::Pivot);
181 AddEntry("Printpreview", Context::Printpreview);
182 AddEntry("Series", Context::Series);
183 AddEntry("SlidesorterPage", Context::SlidesorterPage);
184 AddEntry("Table", Context::Table);
185 AddEntry("Text", Context::Text);
186 AddEntry("TextObject", Context::TextObject);
187 AddEntry("Trendline", Context::Trendline);
188 AddEntry("Sparkline", Context::Sparkline);
189
190 // other general contexts
191 AddEntry("any", Context::Any);
192 AddEntry("default", Context::Default);
193 AddEntry("empty", Context::Empty);
194}
195
197{
199
200 ContextMap::const_iterator iContext( maContextMap.find(rsContextName) );
201 if (iContext != maContextMap.end())
202 return iContext->second;
203 else
205}
206
207const OUString& EnumContext::GetContextName (const Context eContext)
208{
210 return maContextVector[eContext];
211}
212
213} // end of namespace vcl
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CombinedEnumContext(a, e)
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:237
sal_Int32 GetCombinedContext_DI() const
This variant of the GetCombinedContext() method treats some application names as identical to each ot...
Definition: EnumContext.cxx:58
static const sal_Int32 NoMatch
When two contexts are matched against each other, then application or context name may have the wildc...
Application meApplication
static void ProvideContextContainers()
static Application GetApplicationEnum(const OUString &rsApplicationName)
Application GetApplication_DI() const
Definition: EnumContext.cxx:63
bool operator!=(const EnumContext &rOther) const
Definition: EnumContext.cxx:90
bool operator==(const EnumContext &rOther) const
Definition: EnumContext.cxx:84
static const OUString & GetApplicationName(const Application eApplication)
static void AddEntry(const OUString &rsName, const Application eApplication)
Definition: EnumContext.cxx:96
static void ProvideApplicationContainers()
static const OUString & GetContextName(const Context eContext)
static Context GetContextEnum(const OUString &rsContextName)
NONE
Unknown