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>
22 #include <o3tl/enumarray.hxx>
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
),
58 sal_Int32
EnumContext::GetCombinedContext_DI() const
60 return CombinedEnumContext(GetApplication_DI(), meContext
);
63 EnumContext::Application
EnumContext::GetApplication() const
68 EnumContext::Application
EnumContext::GetApplication_DI() const
70 switch (meApplication
)
72 case Application::Draw
:
73 case Application::Impress
:
74 return Application::DrawImpress
;
76 case Application::Writer
:
77 case Application::WriterGlobal
:
78 case Application::WriterWeb
:
79 case Application::WriterXML
:
80 case Application::WriterForm
:
81 case Application::WriterReport
:
82 return Application::WriterVariants
;
89 bool EnumContext::operator== (const EnumContext
& rOther
) const
91 return meApplication
==rOther
.meApplication
92 && meContext
==rOther
.meContext
;
95 bool EnumContext::operator!= (const EnumContext
& rOther
) const
97 return meApplication
!=rOther
.meApplication
98 || meContext
!=rOther
.meContext
;
101 void EnumContext::AddEntry (const OUString
& rsName
, const Application eApplication
)
103 maApplicationMap
[rsName
] = eApplication
;
104 OSL_ASSERT(eApplication
<=Application::LAST
);
105 maApplicationVector
[eApplication
]=rsName
;
108 void EnumContext::ProvideApplicationContainers()
110 if (!maApplicationMap
.empty())
113 AddEntry("com.sun.star.text.TextDocument", EnumContext::Application::Writer
);
114 AddEntry("com.sun.star.text.GlobalDocument", EnumContext::Application::WriterGlobal
);
115 AddEntry("com.sun.star.text.WebDocument", EnumContext::Application::WriterWeb
);
116 AddEntry("com.sun.star.xforms.XMLFormDocument", EnumContext::Application::WriterXML
);
117 AddEntry("com.sun.star.sdb.FormDesign", EnumContext::Application::WriterForm
);
118 AddEntry("com.sun.star.sdb.TextReportDesign", EnumContext::Application::WriterReport
);
119 AddEntry("com.sun.star.sheet.SpreadsheetDocument", EnumContext::Application::Calc
);
120 AddEntry("com.sun.star.chart2.ChartDocument", EnumContext::Application::Chart
);
121 AddEntry("com.sun.star.drawing.DrawingDocument", EnumContext::Application::Draw
);
122 AddEntry("com.sun.star.presentation.PresentationDocument", EnumContext::Application::Impress
);
123 AddEntry("com.sun.star.formula.FormulaProperties", EnumContext::Application::Formula
);
124 AddEntry("com.sun.star.sdb.OfficeDatabaseDocument", EnumContext::Application::Base
);
125 AddEntry("any", EnumContext::Application::Any
);
126 AddEntry("none", EnumContext::Application::NONE
);
130 EnumContext::Application
EnumContext::GetApplicationEnum (const OUString
& rsApplicationName
)
132 ProvideApplicationContainers();
134 ApplicationMap::const_iterator
iApplication(
135 maApplicationMap
.find(rsApplicationName
));
136 if (iApplication
!= maApplicationMap
.end())
137 return iApplication
->second
;
139 return EnumContext::Application::NONE
;
142 const OUString
& EnumContext::GetApplicationName (const Application eApplication
)
144 ProvideApplicationContainers();
145 return maApplicationVector
[eApplication
];
148 void EnumContext::AddEntry (const OUString
& rsName
, const Context eContext
)
150 maContextMap
[rsName
] = eContext
;
151 maContextVector
[eContext
] = rsName
;
154 void EnumContext::ProvideContextContainers()
156 if (!maContextMap
.empty())
159 AddEntry("3DObject", Context::ThreeDObject
);
160 AddEntry("Annotation", Context::Annotation
);
161 AddEntry("Auditing", Context::Auditing
);
162 AddEntry("Axis", Context::Axis
);
163 AddEntry("Cell", Context::Cell
);
164 AddEntry("Chart", Context::Chart
);
165 AddEntry("ChartElements", Context::ChartElements
);
166 AddEntry("Draw", Context::Draw
);
167 AddEntry("DrawFontwork", Context::DrawFontwork
);
168 AddEntry("DrawLine", Context::DrawLine
);
169 AddEntry("DrawPage", Context::DrawPage
);
170 AddEntry("DrawText", Context::DrawText
);
171 AddEntry("EditCell", Context::EditCell
);
172 AddEntry("ErrorBar", Context::ErrorBar
);
173 AddEntry("Form", Context::Form
);
174 AddEntry("Frame", Context::Frame
);
175 AddEntry("Graphic", Context::Graphic
);
176 AddEntry("Grid", Context::Grid
);
177 AddEntry("HandoutPage", Context::HandoutPage
);
178 AddEntry("MasterPage", Context::MasterPage
);
179 AddEntry("Math", Context::Math
);
180 AddEntry("Media", Context::Media
);
181 AddEntry("MultiObject", Context::MultiObject
);
182 AddEntry("NotesPage", Context::NotesPage
);
183 AddEntry("OLE", Context::OLE
);
184 AddEntry("OutlineText", Context::OutlineText
);
185 AddEntry("Pivot", Context::Pivot
);
186 AddEntry("Printpreview", Context::Printpreview
);
187 AddEntry("Series", Context::Series
);
188 AddEntry("SlidesorterPage", Context::SlidesorterPage
);
189 AddEntry("Table", Context::Table
);
190 AddEntry("Text", Context::Text
);
191 AddEntry("TextObject", Context::TextObject
);
192 AddEntry("Trendline", Context::Trendline
);
193 AddEntry("Sparkline", Context::Sparkline
);
195 // other general contexts
196 AddEntry("any", Context::Any
);
197 AddEntry("default", Context::Default
);
198 AddEntry("empty", Context::Empty
);
201 EnumContext::Context
EnumContext::GetContextEnum (const OUString
& rsContextName
)
203 ProvideContextContainers();
205 ContextMap::const_iterator
iContext( maContextMap
.find(rsContextName
) );
206 if (iContext
!= maContextMap
.end())
207 return iContext
->second
;
209 return EnumContext::Context::Unknown
;
212 const OUString
& EnumContext::GetContextName (const Context eContext
)
214 ProvideContextContainers();
215 return maContextVector
[eContext
];
218 } // end of namespace vcl
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */