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 
23 #ifndef __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
24 #define __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
25 
26 //_________________________________________________________________________________________________________________
27 //  includes
28 //_________________________________________________________________________________________________________________
29 
30 #include <sal/types.h>
31 #include <osl/mutex.hxx>
32 #include <vcl/image.hxx>
33 #include <vcl/bitmap.hxx>
34 #include <vcl/svapp.hxx>
35 #include <com/sun/star/uno/Sequence.h>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <framework/fwedllapi.h>
38 //_________________________________________________________________________________________________________________
39 //  types, enums, ...
40 //_________________________________________________________________________________________________________________
41 
42 /*-************************************************************************************************************//**
43     @descr          The method GetAddonsMenu() returns a list of property values.
44                     Use follow defines to seperate values by names.
45 *//*-*************************************************************************************************************/
46 #define ADDONSMENUITEM_STRING_URL                       "URL"
47 #define ADDONSMENUITEM_STRING_TITLE                     "Title"
48 #define ADDONSMENUITEM_STRING_TARGET                    "Target"
49 #define ADDONSMENUITEM_STRING_IMAGEIDENTIFIER           "ImageIdentifier"
50 #define ADDONSMENUITEM_STRING_CONTEXT                   "Context"
51 #define ADDONSMENUITEM_STRING_SUBMENU                   "Submenu"
52 #define ADDONSMENUITEM_STRING_CONTROLTYPE               "ControlType"
53 #define ADDONSMENUITEM_STRING_WIDTH                     "Width"
54 
55 #define STATUSBARITEM_STRING_ALIGN                      "Alignment"
56 #define STATUSBARITEM_STRING_AUTOSIZE                   "AutoSize"
57 #define STATUSBARITEM_STRING_OWNERDRAW                  "OwnerDraw"
58 
59 #define ADDONSMENUITEM_URL_LEN                          3
60 #define ADDONSMENUITEM_TITLE_LEN                        5
61 #define ADDONSMENUITEM_TARGET_LEN                       6
62 #define ADDONSMENUITEM_SUBMENU_LEN                      7
63 #define ADDONSMENUITEM_CONTEXT_LEN                      7
64 #define ADDONSMENUITEM_IMAGEIDENTIFIER_LEN              15
65 
66 #define ADDONSMENUITEM_PROPERTYNAME_URL                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_URL             ))
67 #define ADDONSMENUITEM_PROPERTYNAME_TITLE               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_TITLE           ))
68 #define ADDONSMENUITEM_PROPERTYNAME_TARGET              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_TARGET          ))
69 #define ADDONSMENUITEM_PROPERTYNAME_IMAGEIDENTIFIER     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_IMAGEIDENTIFIER ))
70 #define ADDONSMENUITEM_PROPERTYNAME_CONTEXT             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_CONTEXT         ))
71 #define ADDONSMENUITEM_PROPERTYNAME_SUBMENU             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_SUBMENU         ))
72 #define ADDONSMENUITEM_PROPERTYNAME_CONTROLTYPE         ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_CONTROLTYPE     ))
73 #define ADDONSMENUITEM_PROPERTYNAME_WIDTH               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ADDONSMENUITEM_STRING_WIDTH           ))
74 
75 #define STATUSBARITEM_PROPERTYNAME_ALIGN                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STATUSBARITEM_STRING_ALIGN            ))
76 #define STATUSBARITEM_PROPERTYNAME_AUTOSIZE             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STATUSBARITEM_STRING_AUTOSIZE         ))
77 #define STATUSBARITEM_PROPERTYNAME_OWNERDRAW            ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(STATUSBARITEM_STRING_OWNERDRAW        ))
78 
79 #define ADDONSPOPUPMENU_URL_PREFIX_STR                  "private:menu/Addon"
80 
81 #define ADDONSPOPUPMENU_URL_PREFIX                      ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ADDONSPOPUPMENU_URL_PREFIX_STR ))
82 
83 namespace framework
84 {
85 
86 typedef ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > MergeMenuDefinition;
87 
88 struct FWE_DLLPUBLIC MergeMenuInstruction
89 {
90     ::rtl::OUString     aMergePoint;
91     ::rtl::OUString     aMergeCommand;
92     ::rtl::OUString     aMergeCommandParameter;
93     ::rtl::OUString     aMergeFallback;
94     ::rtl::OUString     aMergeContext;
95     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > aMergeMenu;
96 };
97 typedef ::std::vector< MergeMenuInstruction > MergeMenuInstructionContainer;
98 
99 struct FWE_DLLPUBLIC MergeToolbarInstruction
100 {
101     ::rtl::OUString     aMergeToolbar;
102     ::rtl::OUString     aMergePoint;
103     ::rtl::OUString     aMergeCommand;
104     ::rtl::OUString     aMergeCommandParameter;
105     ::rtl::OUString     aMergeFallback;
106     ::rtl::OUString     aMergeContext;
107     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > aMergeToolbarItems;
108 };
109 
110 typedef ::std::vector< MergeToolbarInstruction > MergeToolbarInstructionContainer;
111 
112 struct FWE_DLLPUBLIC MergeStatusbarInstruction
113 {
114     ::rtl::OUString     aMergePoint;
115     ::rtl::OUString     aMergeCommand;
116     ::rtl::OUString     aMergeCommandParameter;
117     ::rtl::OUString     aMergeFallback;
118     ::rtl::OUString     aMergeContext;
119     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > aMergeStatusbarItems;
120 };
121 
122 typedef ::std::vector< MergeStatusbarInstruction > MergeStatusbarInstructionContainer;
123 
124 //_________________________________________________________________________________________________________________
125 //  forward declarations
126 //_________________________________________________________________________________________________________________
127 
128 /*-************************************************************************************************************//**
129     @short          forward declaration to our private date container implementation
130     @descr          We use these class as internal member to support small memory requirements.
131                     You can create the container if it is neccessary. The class which use these mechanism
132                     is faster and smaller then a complete implementation!
133 *//*-*************************************************************************************************************/
134 
135 class AddonsOptions_Impl;
136 
137 //_________________________________________________________________________________________________________________
138 //  declarations
139 //_________________________________________________________________________________________________________________
140 
141 /*-************************************************************************************************************//**
142     @short          collect informations about menu features
143     @descr          -
144 
145     @implements     -
146     @base           -
147 
148     @devstatus      ready to use
149 *//*-*************************************************************************************************************/
150 
151 class FWE_DLLPUBLIC AddonsOptions
152 {
153     //-------------------------------------------------------------------------------------------------------------
154     //  public methods
155     //-------------------------------------------------------------------------------------------------------------
156 
157     public:
158         //---------------------------------------------------------------------------------------------------------
159         //  constructor / destructor
160         //---------------------------------------------------------------------------------------------------------
161 
162         /*-****************************************************************************************************//**
163             @short      standard constructor and destructor
164             @descr      This will initialize an instance with default values.
165                         We implement these class with a refcount mechanism! Every instance of this class increase it
166                         at create and decrease it at delete time - but all instances use the same data container!
167                         He is implemented as a static member ...
168 
169             @seealso    member m_nRefCount
170             @seealso    member m_pDataContainer
171 
172             @param      -
173             @return     -
174 
175             @onerror    -
176         *//*-*****************************************************************************************************/
177 
178          AddonsOptions();
179         ~AddonsOptions();
180 
181         //---------------------------------------------------------------------------------------------------------
182         //  interface
183         //---------------------------------------------------------------------------------------------------------
184 
185         /*-****************************************************************************************************//**
186             @short      clears completely the addons menu
187             @descr      Call this methods to clear the addons menu
188                         To fill it again use AppendItem().
189 
190             @seealso    -
191 
192             @param      "eMenu" select right menu to clear.
193             @return     -
194 
195             @onerror    -
196         *//*-*****************************************************************************************************/
197 
198         void Clear();
199 
200         /*-****************************************************************************************************//**
201             @short      returns if an addons menu is available
202             @descr      Call to retrieve if a addons menu is available
203 
204 
205             @return     sal_True if there is a menu otherwise sal_False
206         *//*-*****************************************************************************************************/
207 
208         sal_Bool    HasAddonsMenu() const;
209 
210         /*-****************************************************************************************************//**
211             @short      returns if an addons help menu is available
212             @descr      Call to retrieve if a addons menu is available
213 
214 
215             @return     sal_True if there is a menu otherwise sal_False
216         *//*-*****************************************************************************************************/
217 
218         sal_Bool    HasAddonsHelpMenu() const;
219 
220         /*-****************************************************************************************************//**
221             @short      returns number of addons toolbars
222             @descr      Call to retrieve the number of addons toolbars
223 
224 
225             @return     number of addons toolbars
226         *//*-*****************************************************************************************************/
227         sal_Int32   GetAddonsToolBarCount() const ;
228 
229         /*-****************************************************************************************************//**
230             @short      returns the  complete addons menu
231             @descr      Call it to get all entries of the addon menu.
232                         We return a list of all nodes with his names and properties.
233 
234             @seealso    -
235 
236             @return     A list of menu items is returned.
237 
238             @onerror    We return an empty list.
239         *//*-*****************************************************************************************************/
240 
241         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsMenu() const;
242 
243         /*-****************************************************************************************************//**
244             @short      Gets the menu bar part of all addon components registered
245             @descr      -
246 
247             @seealso    -
248 
249             @return     A complete
250 
251             @onerror    We return sal_False
252         *//*-*****************************************************************************************************/
253 
254         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsMenuBarPart() const;
255 
256         /*-****************************************************************************************************//**
257             @short      Gets a toolbar part of an single addon
258             @descr      -
259 
260             @seealso    -
261 
262             @return     A complete
263 
264             @onerror    We return sal_False
265         *//*-*****************************************************************************************************/
266 
267         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsToolBarPart( sal_uInt32 nIndex ) const;
268 
269         /*-****************************************************************************************************//**
270             @short      Gets a unique toolbar resource name of an single addon
271             @descr      -
272 
273             @seealso    -
274 
275             @return     A complete
276 
277             @onerror    We return sal_False
278         *//*-*****************************************************************************************************/
279 
280         const ::rtl::OUString GetAddonsToolbarResourceName( sal_uInt32 nIndex ) const;
281 
282         /**
283          *  @short      Gets the UI name of a single addon toolbar
284          *  @return     The UI name of the toolbar as specified in the Addons.xcu configuration
285          *  @onerror    Returns an empty string
286          */
287         const ::rtl::OUString GetAddonsToolbarUIName( sal_uInt32 nIndex ) const;
288 
289         /*-****************************************************************************************************//**
290             @short      Retrieves all available merge instructions for the Office menu bar
291             @descr      -
292 
293             @seealso    -
294 
295             @return     The filled MergeMenuDefinitionContaier
296 
297             @onerror    We return sal_False
298         *//*-*****************************************************************************************************/
299 
300         const MergeMenuInstructionContainer& GetMergeMenuInstructions() const;
301 
302         /*-****************************************************************************************************//**
303             @short      Retrieves all available merge instructions for a single toolbar
304             @descr      -
305 
306             @seealso    -
307 
308             @return     The filled
309 
310             @onerror    We return sal_False
311         *//*-*****************************************************************************************************/
312         bool GetMergeToolbarInstructions( const ::rtl::OUString& rToolbarName, MergeToolbarInstructionContainer& rToolbar ) const;
313 
314         const MergeStatusbarInstructionContainer& GetMergeStatusbarInstructions() const;
315 
316         /*-****************************************************************************************************//**
317             @short      Gets the Add-On help menu part of all addon components registered
318             @descr      -
319 
320             @seealso    -
321 
322             @return     A complete
323 
324             @onerror    We return sal_False
325         *//*-*****************************************************************************************************/
326         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > >& GetAddonsHelpMenu() const;
327 
328         /*-****************************************************************************************************//**
329             @short      Retrieve an image for a command URL which is defined inside the addon menu configuration
330             @descr      Call it to retrieve an image for a command URL which is defined inside the addon menu configuration
331 
332             @seealso    -
333 
334             @return     An image which was defined in the configuration for the menu item. The image can be empty
335                         no bitmap was defined for the request image properties.
336 
337             @onerror    An empty image
338         *//*-*****************************************************************************************************/
339 
340         Image GetImageFromURL( const rtl::OUString& aURL, sal_Bool bBig, sal_Bool bHiContrast, sal_Bool bNoScale ) const;
341 
342         Image GetImageFromURL( const rtl::OUString& aURL, sal_Bool bBig, sal_Bool bHiContrast ) const;
343     //-------------------------------------------------------------------------------------------------------------
344     //  private methods
345     //-------------------------------------------------------------------------------------------------------------
346 
347         /*-****************************************************************************************************//**
348             @short      return a reference to a static mutex
349             @descr      These class is partially threadsafe (for de-/initialization only).
350                         All access methods are'nt safe!
351                         We create a static mutex only for one ime and use at different times.
352 
353             @seealso    -
354 
355             @param      -
356             @return     A reference to a static mutex member.
357 
358             @onerror    -
359         *//*-*****************************************************************************************************/
360 
361         static ::osl::Mutex& GetOwnStaticMutex();
362 
363         /*-****************************************************************************************************//**
364             @short      return a reference to a static mutex
365             @descr      These class is partially threadsafe (for de-/initialization only).
366                         All access methods are'nt safe!
367                         We create a static mutex only for one ime and use at different times.
368 
369             @seealso    -
370 
371             @param      -
372             @return     A reference to a static mutex member.
373 
374             @onerror    -
375         *//*-*****************************************************************************************************/
376         DECL_STATIC_LINK( AddonsOptions, Notify, void* );
377 
378     //-------------------------------------------------------------------------------------------------------------
379     //  private member
380     //-------------------------------------------------------------------------------------------------------------
381 
382     private:
383 
384         /*Attention
385 
386             Don't initialize these static member in these header!
387             a) Double dfined symbols will be detected ...
388             b) and unresolved externals exist at linking time.
389             Do it in your source only.
390          */
391 
392         static AddonsOptions_Impl*  m_pDataContainer    ;   /// impl. data container as dynamic pointer for smaller memory requirements!
393         static sal_Int32            m_nRefCount         ;   /// internal ref count mechanism
394 
395 };      // class SvtMenuOptions
396 
397 }
398 
399 #endif  // #ifndef __FRAMEWORK_CLASSES_ADDONSOPTIONS_HXX_
400