xref: /trunk/main/sfx2/inc/sfx2/sidebar/EnumContext.hxx (revision 10405e3b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef SFX_SIDEBAR_ENUM_CONTEXT_HXX
23 #define SFX_SIDEBAR_ENUM_CONTEXT_HXX
24 
25 #include "sfx2/dllapi.h"
26 
27 #include <rtl/ustring.hxx>
28 
29 #include <vector>
30 
31 
32 namespace sfx2 { namespace sidebar {
33 
34 class SFX2_DLLPUBLIC EnumContext
35 {
36 public:
37     enum Application
38     {
39         Application_Writer,
40         Application_WriterGlobal,
41         Application_WriterWeb,
42         Application_WriterXML,
43         Application_WriterForm,
44         Application_WriterReport,
45         Application_Calc,
46         Application_Draw,
47         Application_Impress,
48 
49         // For your convenience to avoid duplicate code in the common
50         // case that Draw and Impress use identical context configurations.
51         Application_DrawImpress,
52 
53         // Also for your convenience for the different variants of Writer documents.
54         Application_WriterVariants,
55 
56         // Used only by deck or panel descriptors.  Matches any
57         // application.
58         Application_Any,
59 
60         // Use this only in special circumstances.  One might be the
61         // wish to disable a deck or panel during debugging.
62         Application_None,
63 
64         __LastApplicationEnum = Application_None
65     };
66     enum Context
67     {
68         Context_3DObject,
69         Context_Annotation,
70         Context_Auditing,
71         Context_Cell,
72         Context_Chart,
73         Context_Draw,
74         Context_DrawPage,
75         Context_DrawText,
76         Context_EditCell,
77         Context_Form,
78         Context_Frame,
79         Context_Graphic,
80         Context_HandoutPage,
81         Context_MasterPage,
82         Context_Media,
83         Context_MultiObject,
84         Context_NotesPage,
85         Context_OLE,
86         Context_OutlineText,
87         Context_Pivot,
88         Context_SlidesorterPage,
89         Context_Table,
90         Context_Text,
91         Context_TextObject,
92 
93         // Default context of an application.  Do we need this?
94         Context_Default,
95 
96         // Used only by deck or panel descriptors.  Matches any context.
97         Context_Any,
98 
99         // Special context name that is only used when a deck would
100         // otherwise be empty.
101         Context_Empty,
102 
103         Context_Unknown,
104 
105         __LastContextEnum = Context_Unknown
106     };
107 
108     EnumContext (void);
109     EnumContext (
110         const Application eApplication,
111         const Context eContext);
112     EnumContext (
113         const ::rtl::OUString& rsApplicationName,
114         const ::rtl::OUString& rsContextName);
115 
116     /** Return a number that encodes both the application and context
117         enums.
118         Use the CombinedEnumContext macro in switch() statements and comparisons.
119     */
120     sal_Int32 GetCombinedContext(void) const;
121 
122     /** This variant of the GetCombinedContext() method treats some
123         application names as identical to each other.  Replacements
124         made are:
125             Draw or Impress     -> DrawImpress
126             Writer or WriterWeb -> WriterAndWeb
127         Use the Application_DrawImpress or Application_WriterAndWeb values in the CombinedEnumContext macro.
128     */
129     sal_Int32 GetCombinedContext_DI(void) const;
130 
131     const ::rtl::OUString& GetApplicationName (void) const;
132     Application GetApplication (void) const;
133     Application GetApplication_DI (void) const;
134 
135     const ::rtl::OUString& GetContextName (void) const;
136     Context GetContext (void) const;
137 
138     bool operator == (const EnumContext aOther);
139     bool operator != (const EnumContext aOther);
140 
141     /** When two contexts are matched against each other then
142         application or context name may have the wildcard value 'any'.
143         In order to prefer matches without wildcards over matches with
144         wildcards we introduce a integer evaluation for matches.
145     */
146     const static sal_Int32 NoMatch;
147     const static sal_Int32 OptimalMatch;
148 
149     /** Return the numeric value that describes how good the match
150         between two contexts is.
151         Smaller values represent better matches.
152     */
153     sal_Int32 EvaluateMatch (const EnumContext& rOther) const;
154 
155     /** Return the best match against the given list of contexts.
156     */
157     sal_Int32 EvaluateMatch (const ::std::vector<EnumContext>& rOthers) const;
158 
159     static Application GetApplicationEnum (const ::rtl::OUString& rsApplicationName);
160     static const ::rtl::OUString& GetApplicationName (const Application eApplication);
161 
162     static Context GetContextEnum (const ::rtl::OUString& rsContextName);
163     static const ::rtl::OUString& GetContextName (const Context eContext);
164 
165 private:
166     Application meApplication;
167     Context meContext;
168 
169     static void ProvideApplicationContainers (void);
170     static void ProvideContextContainers (void);
171     static void AddEntry (const ::rtl::OUString& rsName, const Application eApplication);
172     static void AddEntry (const ::rtl::OUString& rsName, const Context eContext);
173 };
174 
175 
176 #define CombinedEnumContext(a,e) ((static_cast<sal_uInt16>(::sfx2::sidebar::EnumContext::a)<<16)\
177         | static_cast<sal_uInt16>(::sfx2::sidebar::EnumContext::e))
178 
179 } } // end of namespace sfx2::sidebar
180 
181 #endif
182