xref: /trunk/main/toolkit/source/layout/core/helper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 );
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     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
95                                                             const css::uno::Any& rValue );
96     using OPropertySetHelper::getFastPropertyValue;
97     virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue,
98                                                 sal_Int32 nHandle ) const;
99 
100     virtual css::uno::Reference <css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo ();
101 
102     struct Listener
103     {
104         virtual void propertiesChanged() = 0;
105     };
106 
setChangeListener(Listener * pListener)107     void setChangeListener( Listener *pListener )
108     {
109         mpListener = pListener;
110     }
111 
112 protected:
113     Listener *mpListener;
114 };
115 
116 css::uno::Any anyFromString (const rtl::OUString &value, const css::uno::Type &type);
117 
118 // The native widgets wrapper hierarchy may not reflect that of the layout
119 // hierarchy as some containers don't have an associated native widget.
120 // Use this function to get the native parent of the given peer.
121 css::uno::Reference< css::awt::XWindowPeer >
122 getParent( css::uno::Reference< css::uno::XInterface > xPeer );
123 
124 class TOOLKIT_DLLPUBLIC WidgetFactory
125 {
126 public:
127     static oslModule mSfx2Library;
128     static WindowCreator mSfx2CreateWidget;
129 
130     // Should use UNO services in due course
131     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);
132     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);
133     static css::uno::Reference <css::awt::XLayoutContainer> createContainer (rtl::OUString const& name);
134     static css::uno::Reference <css::awt::XLayoutConstrains> implCreateWidget (css::uno::Reference <css::uno::XInterface> xParent, rtl::OUString name, long attributes);
135     static Window* sfx2CreateWindow (VCLXWindow** component, Window* parent, rtl::OUString const& name, long& attributes);
136     static Window* layoutCreateWindow (VCLXWindow** component, Window *parent, rtl::OUString const& name, long& attributes);
137 };
138 
139 
140 css::uno::Reference< css::graphic::XGraphic > loadGraphic( const char *pName );
141 
142 } // end namespace layoutimpl
143 
144 #endif /* LAYOUT_CORE_HELPER_HXX */
145