fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / inc / helper / mischelper.hxx
blob6aa0015ade49040336268e88bafc970ce2411ae5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
21 #define INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
23 #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/document/XDocumentEventListener.hpp>
26 #include <com/sun/star/lang/XEventListener.hpp>
27 #include <com/sun/star/util/XChangesListener.hpp>
28 #include <com/sun/star/container/XContainerListener.hpp>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <cppuhelper/implbase1.hxx>
34 #include <i18nlangtag/lang.h>
35 #include <svl/languageoptions.hxx>
36 #include <rtl/ustring.hxx>
37 #include <fwidllapi.h>
39 #include <set>
41 namespace framework
44 // menu ids for language status bar control
45 enum LangMenuIDs
47 MID_LANG_SEL_1 = 1, // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
48 MID_LANG_SEL_2,
49 MID_LANG_SEL_3,
50 MID_LANG_SEL_4,
51 MID_LANG_SEL_5,
52 MID_LANG_SEL_6,
53 MID_LANG_SEL_7,
54 MID_LANG_SEL_8,
55 MID_LANG_SEL_9,
56 MID_LANG_SEL_NONE,
57 MID_LANG_SEL_RESET,
58 MID_LANG_SEL_MORE,
60 MID_LANG_PARA_SEPARATOR,
61 MID_LANG_PARA_STRING,
63 MID_LANG_PARA_1,
64 MID_LANG_PARA_2,
65 MID_LANG_PARA_3,
66 MID_LANG_PARA_4,
67 MID_LANG_PARA_5,
68 MID_LANG_PARA_6,
69 MID_LANG_PARA_7,
70 MID_LANG_PARA_8,
71 MID_LANG_PARA_9,
72 MID_LANG_PARA_NONE,
73 MID_LANG_PARA_RESET,
74 MID_LANG_PARA_MORE,
77 inline bool IsScriptTypeMatchingToLanguage( SvtScriptType nScriptType, LanguageType nLang )
79 return bool(nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
82 inline void RetrieveTypeNameFromResourceURL( const OUString& aResourceURL, OUString& aType, OUString& aName )
84 const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17;
85 const char RESOURCEURL_PREFIX[] = "private:resource/";
87 if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
88 ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
90 OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ));
91 sal_Int32 nToken = 0;
92 sal_Int32 nPart = 0;
95 OUString sToken = aTmpStr.getToken( 0, '/', nToken);
96 if ( !sToken.isEmpty() )
98 if ( nPart == 0 )
99 aType = sToken;
100 else if ( nPart == 1 )
101 aName = sToken;
102 else
103 break;
104 nPart++;
107 while( nToken >=0 );
111 class FWI_DLLPUBLIC LanguageGuessingHelper
113 mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing > m_xLanguageGuesser;
114 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
116 public:
117 LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xContext) : m_xContext(_xContext){}
119 ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing > GetGuesser() const;
122 FWI_DLLPUBLIC OUString RetrieveLabelFromCommand( const OUString& aCmdURL
123 ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xContext
124 ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xUICommandLabels
125 ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
126 ,OUString& _rModuleIdentifier
127 ,bool& _rIni
128 ,const sal_Char* _pName);
130 FWI_DLLPUBLIC void FillLangItems( std::set< OUString > &rLangItems,
131 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
132 const LanguageGuessingHelper & rLangGuessHelper,
133 SvtScriptType nScriptType,
134 const OUString & rCurLang,
135 const OUString & rKeyboardLang,
136 const OUString & rGuessedTextLang );
138 //It's common for an object to want to create and own a Broadcaster and set
139 //itself as a Listener on its own Broadcaster member.
141 //However, calling addListener on a Broadcaster means that the Broadcaster adds
142 //a reference to the Listener leading to an ownership cycle where the Listener
143 //owns the Broadcaster which "owns" the Listener.
145 //The WeakContainerListener allows breaking this cycle and retrofitting
146 //afflicted implentations fairly easily.
148 //OriginalListener owns the Broadcaster which "owns" the WeakContainerListener
149 //which forwards the events to the OriginalListener without taking ownership of
150 //it.
151 class WeakContainerListener : public ::cppu::WeakImplHelper1<com::sun::star::container::XContainerListener>
153 private:
154 com::sun::star::uno::WeakReference<com::sun::star::container::XContainerListener> mxOwner;
156 public:
157 WeakContainerListener(com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner)
158 : mxOwner(xOwner)
162 virtual ~WeakContainerListener()
166 // container.XContainerListener
167 virtual void SAL_CALL elementInserted(const com::sun::star::container::ContainerEvent& rEvent)
168 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
170 com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
171 com::sun::star::uno::UNO_QUERY);
172 if (xOwner.is())
173 xOwner->elementInserted(rEvent);
176 virtual void SAL_CALL elementRemoved(const com::sun::star::container::ContainerEvent& rEvent)
177 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
179 com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
180 com::sun::star::uno::UNO_QUERY);
181 if (xOwner.is())
182 xOwner->elementRemoved(rEvent);
185 virtual void SAL_CALL elementReplaced(const com::sun::star::container::ContainerEvent& rEvent)
186 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
188 com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
189 com::sun::star::uno::UNO_QUERY);
190 if (xOwner.is())
191 xOwner->elementReplaced(rEvent);
194 // lang.XEventListener
195 virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
196 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
198 com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
199 com::sun::star::uno::UNO_QUERY);
200 if (xOwner.is())
201 xOwner->disposing(rEvent);
206 class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XChangesListener>
208 private:
209 com::sun::star::uno::WeakReference<com::sun::star::util::XChangesListener> mxOwner;
211 public:
212 WeakChangesListener(com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner)
213 : mxOwner(xOwner)
217 virtual ~WeakChangesListener()
221 // util.XChangesListener
222 virtual void SAL_CALL changesOccurred(const com::sun::star::util::ChangesEvent& rEvent)
223 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
225 com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
226 com::sun::star::uno::UNO_QUERY);
227 if (xOwner.is())
228 xOwner->changesOccurred(rEvent);
231 // lang.XEventListener
232 virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
233 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
235 com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
236 com::sun::star::uno::UNO_QUERY);
237 if (xOwner.is())
238 xOwner->disposing(rEvent);
243 class WeakEventListener : public ::cppu::WeakImplHelper1<com::sun::star::lang::XEventListener>
245 private:
246 com::sun::star::uno::WeakReference<com::sun::star::lang::XEventListener> mxOwner;
248 public:
249 WeakEventListener(com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner)
250 : mxOwner(xOwner)
254 virtual ~WeakEventListener()
258 // lang.XEventListener
259 virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
260 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
262 com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner(mxOwner.get(),
263 com::sun::star::uno::UNO_QUERY);
264 if (xOwner.is())
265 xOwner->disposing(rEvent);
270 class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star::document::XDocumentEventListener>
272 private:
273 com::sun::star::uno::WeakReference<com::sun::star::document::XDocumentEventListener> mxOwner;
275 public:
276 WeakDocumentEventListener(com::sun::star::uno::Reference<com::sun::star::document::XDocumentEventListener> xOwner)
277 : mxOwner(xOwner)
281 virtual ~WeakDocumentEventListener()
285 virtual void SAL_CALL documentEventOccured(const com::sun::star::document::DocumentEvent& rEvent)
286 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
288 com::sun::star::uno::Reference<com::sun::star::document::XDocumentEventListener> xOwner(mxOwner.get(),
289 com::sun::star::uno::UNO_QUERY);
290 if (xOwner.is())
291 xOwner->documentEventOccured(rEvent);
295 // lang.XEventListener
296 virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
297 throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
299 com::sun::star::uno::Reference<com::sun::star::document::XDocumentEventListener> xOwner(mxOwner.get(),
300 com::sun::star::uno::UNO_QUERY);
301 if (xOwner.is())
302 xOwner->disposing(rEvent);
307 } // namespace framework
309 #endif // INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */