/src/libreoffice/vcl/source/window/EnumContext.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
26 | | namespace vcl { |
27 | | |
28 | | namespace { |
29 | | |
30 | | typedef ::std::map<OUString,EnumContext::Application> ApplicationMap; |
31 | | |
32 | | ApplicationMap maApplicationMap; |
33 | | o3tl::enumarray<EnumContext::Application, OUString> maApplicationVector; |
34 | | |
35 | | typedef ::std::map<OUString,EnumContext::Context> ContextMap; |
36 | | |
37 | | ContextMap maContextMap; |
38 | | o3tl::enumarray<EnumContext::Context, OUString> maContextVector; |
39 | | |
40 | | } |
41 | | |
42 | | const sal_Int32 EnumContext::NoMatch = 4; |
43 | | |
44 | | EnumContext::EnumContext() |
45 | 0 | : meApplication(Application::NONE), |
46 | 0 | meContext(Context::Unknown) |
47 | 0 | { |
48 | 0 | } |
49 | | |
50 | | EnumContext::EnumContext ( |
51 | | const Application eApplication, |
52 | | const Context eContext) |
53 | 0 | : meApplication(eApplication), |
54 | 0 | meContext(eContext) |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | sal_Int32 EnumContext::GetCombinedContext_DI() const |
59 | 0 | { |
60 | 0 | return CombinedEnumContext(GetApplication_DI(), meContext); |
61 | 0 | } |
62 | | |
63 | | EnumContext::Application EnumContext::GetApplication() const |
64 | 0 | { |
65 | 0 | return meApplication; |
66 | 0 | } |
67 | | |
68 | | EnumContext::Application EnumContext::GetApplication_DI() const |
69 | 0 | { |
70 | 0 | switch (meApplication) |
71 | 0 | { |
72 | 0 | case Application::Draw: |
73 | 0 | case Application::Impress: |
74 | 0 | return Application::DrawImpress; |
75 | | |
76 | 0 | case Application::Writer: |
77 | 0 | case Application::WriterGlobal: |
78 | 0 | case Application::WriterWeb: |
79 | 0 | case Application::WriterXML: |
80 | 0 | case Application::WriterForm: |
81 | 0 | case Application::WriterReport: |
82 | 0 | return Application::WriterVariants; |
83 | | |
84 | 0 | default: |
85 | 0 | return meApplication; |
86 | 0 | } |
87 | 0 | } |
88 | | |
89 | | bool EnumContext::operator== (const EnumContext& rOther) const |
90 | 0 | { |
91 | 0 | return meApplication==rOther.meApplication |
92 | 0 | && meContext==rOther.meContext; |
93 | 0 | } |
94 | | |
95 | | bool EnumContext::operator!= (const EnumContext& rOther) const |
96 | 0 | { |
97 | 0 | return meApplication!=rOther.meApplication |
98 | 0 | || meContext!=rOther.meContext; |
99 | 0 | } |
100 | | |
101 | | void EnumContext::AddEntry (const OUString& rsName, const Application eApplication) |
102 | 28 | { |
103 | 28 | maApplicationMap[rsName] = eApplication; |
104 | 28 | OSL_ASSERT(eApplication<=Application::LAST); |
105 | 28 | maApplicationVector[eApplication]=rsName; |
106 | 28 | } |
107 | | |
108 | | void EnumContext::ProvideApplicationContainers() |
109 | 8.47k | { |
110 | 8.47k | if (!maApplicationMap.empty()) |
111 | 8.47k | return; |
112 | | |
113 | 2 | AddEntry(u"com.sun.star.text.TextDocument"_ustr, EnumContext::Application::Writer); |
114 | 2 | AddEntry(u"com.sun.star.text.GlobalDocument"_ustr, EnumContext::Application::WriterGlobal); |
115 | 2 | AddEntry(u"com.sun.star.text.WebDocument"_ustr, EnumContext::Application::WriterWeb); |
116 | 2 | AddEntry(u"com.sun.star.xforms.XMLFormDocument"_ustr, EnumContext::Application::WriterXML); |
117 | 2 | AddEntry(u"com.sun.star.sdb.FormDesign"_ustr, EnumContext::Application::WriterForm); |
118 | 2 | AddEntry(u"com.sun.star.sdb.TextReportDesign"_ustr, EnumContext::Application::WriterReport); |
119 | 2 | AddEntry(u"com.sun.star.sheet.SpreadsheetDocument"_ustr, EnumContext::Application::Calc); |
120 | 2 | AddEntry(u"com.sun.star.chart2.ChartDocument"_ustr, EnumContext::Application::Chart); |
121 | 2 | AddEntry(u"com.sun.star.drawing.DrawingDocument"_ustr, EnumContext::Application::Draw); |
122 | 2 | AddEntry(u"com.sun.star.presentation.PresentationDocument"_ustr, EnumContext::Application::Impress); |
123 | 2 | AddEntry(u"com.sun.star.formula.FormulaProperties"_ustr, EnumContext::Application::Formula); |
124 | 2 | AddEntry(u"com.sun.star.sdb.OfficeDatabaseDocument"_ustr, EnumContext::Application::Base); |
125 | 2 | AddEntry(u"any"_ustr, EnumContext::Application::Any); |
126 | 2 | AddEntry(u"none"_ustr, EnumContext::Application::NONE); |
127 | | |
128 | 2 | } |
129 | | |
130 | | EnumContext::Application EnumContext::GetApplicationEnum (const OUString& rsApplicationName) |
131 | 8.47k | { |
132 | 8.47k | ProvideApplicationContainers(); |
133 | | |
134 | 8.47k | ApplicationMap::const_iterator iApplication( |
135 | 8.47k | maApplicationMap.find(rsApplicationName)); |
136 | 8.47k | if (iApplication != maApplicationMap.end()) |
137 | 8.47k | return iApplication->second; |
138 | 0 | else |
139 | 0 | return EnumContext::Application::NONE; |
140 | 8.47k | } |
141 | | |
142 | | const OUString& EnumContext::GetApplicationName (const Application eApplication) |
143 | 0 | { |
144 | 0 | ProvideApplicationContainers(); |
145 | 0 | return maApplicationVector[eApplication]; |
146 | 0 | } |
147 | | |
148 | | void EnumContext::AddEntry (const OUString& rsName, const Context eContext) |
149 | 82 | { |
150 | 82 | maContextMap[rsName] = eContext; |
151 | 82 | maContextVector[eContext] = rsName; |
152 | 82 | } |
153 | | |
154 | | void EnumContext::ProvideContextContainers() |
155 | 16.9k | { |
156 | 16.9k | if (!maContextMap.empty()) |
157 | 16.9k | return; |
158 | | |
159 | 2 | AddEntry(u"3DObject"_ustr, Context::ThreeDObject); |
160 | 2 | AddEntry(u"Annotation"_ustr, Context::Annotation); |
161 | 2 | AddEntry(u"Auditing"_ustr, Context::Auditing); |
162 | 2 | AddEntry(u"Axis"_ustr, Context::Axis); |
163 | 2 | AddEntry(u"Cell"_ustr, Context::Cell); |
164 | 2 | AddEntry(u"Chart"_ustr, Context::Chart); |
165 | 2 | AddEntry(u"ChartElements"_ustr, Context::ChartElements); |
166 | 2 | AddEntry(u"ChartLabel"_ustr, Context::ChartLabel); |
167 | 2 | AddEntry(u"ChartLegend"_ustr, Context::ChartLegend); |
168 | 2 | AddEntry(u"ChartTitle"_ustr, Context::ChartTitle); |
169 | 2 | AddEntry(u"Draw"_ustr, Context::Draw); |
170 | 2 | AddEntry(u"DrawFontwork"_ustr, Context::DrawFontwork); |
171 | 2 | AddEntry(u"DrawLine"_ustr, Context::DrawLine); |
172 | 2 | AddEntry(u"DrawPage"_ustr, Context::DrawPage); |
173 | 2 | AddEntry(u"DrawText"_ustr, Context::DrawText); |
174 | 2 | AddEntry(u"EditCell"_ustr, Context::EditCell); |
175 | 2 | AddEntry(u"ErrorBar"_ustr, Context::ErrorBar); |
176 | 2 | AddEntry(u"Form"_ustr, Context::Form); |
177 | 2 | AddEntry(u"Frame"_ustr, Context::Frame); |
178 | 2 | AddEntry(u"Graphic"_ustr, Context::Graphic); |
179 | 2 | AddEntry(u"Grid"_ustr, Context::Grid); |
180 | 2 | AddEntry(u"HandoutPage"_ustr, Context::HandoutPage); |
181 | 2 | AddEntry(u"MasterPage"_ustr, Context::MasterPage); |
182 | 2 | AddEntry(u"Math"_ustr, Context::Math); |
183 | 2 | AddEntry(u"Media"_ustr, Context::Media); |
184 | 2 | AddEntry(u"MultiObject"_ustr, Context::MultiObject); |
185 | 2 | AddEntry(u"NotesPage"_ustr, Context::NotesPage); |
186 | 2 | AddEntry(u"OLE"_ustr, Context::OLE); |
187 | 2 | AddEntry(u"OutlineText"_ustr, Context::OutlineText); |
188 | 2 | AddEntry(u"Pivot"_ustr, Context::Pivot); |
189 | 2 | AddEntry(u"Printpreview"_ustr, Context::Printpreview); |
190 | 2 | AddEntry(u"Series"_ustr, Context::Series); |
191 | 2 | AddEntry(u"SlidesorterPage"_ustr, Context::SlidesorterPage); |
192 | 2 | AddEntry(u"Table"_ustr, Context::Table); |
193 | 2 | AddEntry(u"Text"_ustr, Context::Text); |
194 | 2 | AddEntry(u"TextObject"_ustr, Context::TextObject); |
195 | 2 | AddEntry(u"Trendline"_ustr, Context::Trendline); |
196 | 2 | AddEntry(u"Sparkline"_ustr, Context::Sparkline); |
197 | | |
198 | | // other general contexts |
199 | 2 | AddEntry(u"any"_ustr, Context::Any); |
200 | 2 | AddEntry(u"default"_ustr, Context::Default); |
201 | 2 | AddEntry(u"empty"_ustr, Context::Empty); |
202 | 2 | } |
203 | | |
204 | | EnumContext::Context EnumContext::GetContextEnum (const OUString& rsContextName) |
205 | 0 | { |
206 | 0 | ProvideContextContainers(); |
207 | |
|
208 | 0 | ContextMap::const_iterator iContext( maContextMap.find(rsContextName) ); |
209 | 0 | if (iContext != maContextMap.end()) |
210 | 0 | return iContext->second; |
211 | 0 | else |
212 | 0 | return EnumContext::Context::Unknown; |
213 | 0 | } |
214 | | |
215 | | const OUString& EnumContext::GetContextName (const Context eContext) |
216 | 16.9k | { |
217 | 16.9k | ProvideContextContainers(); |
218 | 16.9k | return maContextVector[eContext]; |
219 | 16.9k | } |
220 | | |
221 | | } // end of namespace vcl |
222 | | |
223 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |