2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #ifndef SFX_SIDEBAR_ENUM_CONTEXT_HXX
19 #define SFX_SIDEBAR_ENUM_CONTEXT_HXX
21 #include "sfx2/dllapi.h"
23 #include <rtl/ustring.hxx>
28 namespace sfx2
{ namespace sidebar
{
30 class SFX2_DLLPUBLIC EnumContext
36 Application_WriterGlobal
,
37 Application_WriterWeb
,
38 Application_WriterXML
,
39 Application_WriterForm
,
40 Application_WriterReport
,
45 // For your convenience to avoid duplicate code in the common
46 // case that Draw and Impress use identical context configurations.
47 Application_DrawImpress
,
49 // Also for your convenience for the different variants of Writer documents.
50 Application_WriterVariants
,
52 // Used only by deck or panel descriptors. Matches any
56 // Use this only in special circumstances. One might be the
57 // wish to disable a deck or panel during debugging.
60 __LastApplicationEnum
= Application_None
84 Context_SlidesorterPage
,
89 // Default context of an application. Do we need this?
92 // Used only by deck or panel descriptors. Matches any context.
95 // Special context name that is only used when a deck would
96 // otherwise be empty.
101 __LastContextEnum
= Context_Unknown
106 const Application eApplication
,
107 const Context eContext
);
109 const ::rtl::OUString
& rsApplicationName
,
110 const ::rtl::OUString
& rsContextName
);
112 /** Return a number that encodes both the application and context
114 Use the CombinedEnumContext macro in switch() statements and comparisons.
116 sal_Int32
GetCombinedContext(void) const;
118 /** This variant of the GetCombinedContext() method treats some
119 application names as identical to each other. Replacements
121 Draw or Impress -> DrawImpress
122 Writer or WriterWeb -> WriterAndWeb
123 Use the Application_DrawImpress or Application_WriterAndWeb values in the CombinedEnumContext macro.
125 sal_Int32
GetCombinedContext_DI(void) const;
127 const ::rtl::OUString
& GetApplicationName (void) const;
128 Application
GetApplication (void) const;
129 Application
GetApplication_DI (void) const;
131 const ::rtl::OUString
& GetContextName (void) const;
132 Context
GetContext (void) const;
134 bool operator == (const EnumContext aOther
);
135 bool operator != (const EnumContext aOther
);
137 /** When two contexts are matched against each other then
138 application or context name may have the wildcard value 'any'.
139 In order to prefer matches without wildcards over matches with
140 wildcards we introduce a integer evaluation for matches.
142 const static sal_Int32 NoMatch
;
143 const static sal_Int32 OptimalMatch
;
145 /** Return the numeric value that describes how good the match
146 between two contexts is.
147 Smaller values represent better matches.
149 sal_Int32
EvaluateMatch (const EnumContext
& rOther
) const;
151 /** Return the best match against the given list of contexts.
153 sal_Int32
EvaluateMatch (const ::std::vector
<EnumContext
>& rOthers
) const;
155 static Application
GetApplicationEnum (const ::rtl::OUString
& rsApplicationName
);
156 static const ::rtl::OUString
& GetApplicationName (const Application eApplication
);
158 static Context
GetContextEnum (const ::rtl::OUString
& rsContextName
);
159 static const ::rtl::OUString
& GetContextName (const Context eContext
);
162 Application meApplication
;
165 static void ProvideApplicationContainers (void);
166 static void ProvideContextContainers (void);
167 static void AddEntry (const ::rtl::OUString
& rsName
, const Application eApplication
);
168 static void AddEntry (const ::rtl::OUString
& rsName
, const Context eContext
);
172 #define CombinedEnumContext(a,e) ((static_cast<sal_uInt16>(::sfx2::sidebar::EnumContext::a)<<16)\
173 | static_cast<sal_uInt16>(::sfx2::sidebar::EnumContext::e))
175 } } // end of namespace sfx2::sidebar