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 
24 #ifndef LAYOUT_CORE_HELPER_HXX
25 #define LAYOUT_CORE_HELPER_HXX
26 
27 #include <toolkit/dllapi.h>
28 #include <vector>
29 
30 #include <com/sun/star/awt/XLayoutConstrains.hpp>
31 #include <com/sun/star/awt/XLayoutContainer.hpp>
32 #include <com/sun/star/awt/XVclWindowPeer.hpp>
33 #include <com/sun/star/xml/input/XRoot.hpp>
34 #include <com/sun/star/graphic/XGraphic.hpp>
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/propshlp.hxx>
37 #include <osl/module.h>
38 #include <rtl/ustring.hxx>
39 
40 class Window;
41 class VCLXWindow;
42 extern "C"
43 {
44 	typedef Window* (SAL_CALL *WindowCreator) (VCLXWindow** component, rtl::OUString const& name, Window* parent, long& attributes);
45 }
46 
47 namespace layoutimpl
48 {
49 
50 namespace css = ::com::sun::star;
51 
52 /* ChildProps -- a helper to set child properties for the XLayoutContainer interface. */
53 
54 class LockHelper
55 {
56 public:
57     osl::Mutex               maGuard;
58     cppu::OBroadcastHelper maBrdcstHelper;
LockHelper()59     LockHelper() : maBrdcstHelper( maGuard )
60     {
61     }
62 };
63 
64 class PropHelper : public LockHelper
65                  , public cppu::OPropertySetHelper
66                  , public cppu::OWeakObject
67 {
68     cppu::OPropertyArrayHelper *pHelper;
69 
70     struct PropDetails
71     {
72         rtl::OUString  aName;
73         css::uno::Type aType;
74         void          *pValue;
75     };
76     std::vector< PropDetails > maDetails;
77 
78 protected:
79     void addProp( char const *pName, sal_Int32 nNameLen, rtl_TextEncoding e,
80                   css::uno::Type aType, void *pPtr );
81 
82 public:
83     PropHelper();
84 
85     // com::sun::star::uno::XInterface
acquire()86     void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
release()87     void SAL_CALL release() throw() { OWeakObject::release(); }
88     ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
89 
90     // cppu::OPropertySetHelper
91     virtual cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
92     virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any &,
93                                                         css::uno::Any &, sal_Int32 nHandle, const css::uno::Any & )
94         throw(css::lang::IllegalArgumentException);
95     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
96                                                             const css::uno::Any& rValue ) throw (css::uno::Exception);
97     using OPropertySetHelper::getFastPropertyValue;
98     virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue,
99                                                 sal_Int32 nHandle ) const;
100 
101     virtual css::uno::Reference <css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo () throw (css::uno::RuntimeException);
102 
103     struct Listener
104     {
105         virtual void propertiesChanged() = 0;
106     };
107 
setChangeListener(Listener * pListener)108     void setChangeListener( Listener *pListener )
109     {
110         mpListener = pListener;
111     }
112 
113 protected:
114     Listener *mpListener;
115 };
116 
117 css::uno::Any anyFromString (const rtl::OUString &value, const css::uno::Type &type);
118 
119 // The native widgets wrapper hierarchy may not reflect that of the layout
120 // hierarchy as some containers don't have an associated native widget.
121 // Use this function to get the native parent of the given peer.
122 css::uno::Reference< css::awt::XWindowPeer >
123 getParent( css::uno::Reference< css::uno::XInterface > xPeer );
124 
125 class TOOLKIT_DLLPUBLIC WidgetFactory
126 {
127 public:
128 	static oslModule mSfx2Library;
129 	static WindowCreator mSfx2CreateWidget;
130 
131     // Should use UNO services in due course
132     static css::uno::Reference <css::awt::XLayoutConstrains> toolkitCreateWidget (css::uno::Reference <css::awt::XToolkit> xToolkit, css::uno::Reference <css::uno::XInterface> xParent, rtl::OUString const& name, long properties);
133     static css::uno::Reference< css::awt::XLayoutConstrains > createWidget( css::uno::Reference <css::awt::XToolkit > xToolkit, css::uno::Reference< css::uno::XInterface > xParent, rtl::OUString const &name, long properties);
134     static css::uno::Reference <css::awt::XLayoutContainer> createContainer (rtl::OUString const& name);
135     static css::uno::Reference <css::awt::XLayoutConstrains> implCreateWidget (css::uno::Reference <css::uno::XInterface> xParent, rtl::OUString name, long attributes);
136     static Window* sfx2CreateWindow (VCLXWindow** component, Window* parent, rtl::OUString const& name, long& attributes);
137     static Window* layoutCreateWindow (VCLXWindow** component, Window *parent, rtl::OUString const& name, long& attributes);
138 };
139 
140 
141 css::uno::Reference< css::graphic::XGraphic > loadGraphic( const char *pName );
142 
143 } // end namespace layoutimpl
144 
145 #endif /* LAYOUT_CORE_HELPER_HXX */
146