xref: /aoo4110/main/toolkit/source/layout/core/root.hxx (revision b1cdbd2c)
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_ROOT_HXX
25 #define LAYOUT_CORE_ROOT_HXX
26 
27 #define _BACKWARD_BACKWARD_WARNING_H 1
28 #include <hash_map>
29 
30 #include <com/sun/star/awt/XLayoutRoot.hpp>
31 #include <com/sun/star/awt/XToolkit.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
33 #include <com/sun/star/io/XInputStream.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <cppuhelper/implbase3.hxx>
37 #include <cppuhelper/interfacecontainer.h>
38 #include <toolkit/dllapi.h>
39 
40 #include <layout/core/proplist.hxx>
41 
42 namespace layoutimpl
43 {
44 
45 namespace css = ::com::sun::star;
46 
47 css::uno::Reference< css::io::XInputStream > getFileAsStream( const rtl::OUString &rName );
48 
49 /* Interface generation code -- to hook to a parser. */
50 
51 /*
52   TODO: (ricardo) I think we should cut on LayoutRoot, stripping out its widget
53   proxy interface (just make it return the root widget). Would even make it easier
54   if there was interest to support multiple toplevel widgets in the same file.
55 
56   We also need to make sure the code gets diposed well... There is no need to keep
57   these objects around after initialization...
58 */
59 
60 
61 class LayoutWidget;
62 
63 class TOOLKIT_DLLPUBLIC LayoutRoot : public ::cppu::WeakImplHelper3<
64     css::awt::XLayoutRoot,
65     css::lang::XInitialization,
66     css::lang::XComponent>
67 {
68 protected:
69     ::osl::Mutex maMutex;
70 
71     typedef std::hash_map< rtl::OUString,
72                            css::uno::Reference< css::awt::XLayoutConstrains >,
73                            ::rtl::OUStringHash > ItemHash;
74     ItemHash maItems;
75 
76     sal_Bool mbDisposed;
77     css::uno::Reference< css::lang::XMultiServiceFactory > mxFactory;
78     ::cppu::OInterfaceContainerHelper *mpListeners;
79 
80     css::uno::Reference< css::awt::XWindow >          mxWindow;
81     css::uno::Reference< css::awt::XLayoutContainer > mxContainer;
82 
83     css::uno::Reference< css::awt::XToolkit > mxToolkit;
84     LayoutWidget *mpToplevel;
85     css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit;
86 
87     void error( rtl::OUString const& message );
88 
89 public:
90     LayoutRoot( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
91     virtual ~LayoutRoot();
92 
93     void addItem( const rtl::OUString &rName,
94                   const css::uno::Reference< css::awt::XLayoutConstrains > &xRef );
95 
setWindow(css::uno::Reference<css::awt::XLayoutConstrains> xPeer)96     void setWindow(    css::uno::Reference< css::awt::XLayoutConstrains > xPeer )
97     {
98         mxWindow = css::uno::Reference< css::awt::XWindow >( xPeer, css::uno::UNO_QUERY );
99     }
100 
101     // get XLayoutContainer
102     virtual css::uno::Reference< css::awt::XLayoutContainer > SAL_CALL getLayoutContainer() throw (css::uno::RuntimeException);
103 
104     // XInitialization
105     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException);
106 
107     // XNameAccess
108     virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException);
109     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (css::uno::RuntimeException);
110     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException);
111     virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException);
112     virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException);
113 
114     // XComponent
115     virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
116     virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) throw (css::uno::RuntimeException);
117     virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) throw (css::uno::RuntimeException);
118 
119     // generator
120     virtual LayoutWidget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs, css::uno::Reference< css::awt::XLayoutContainer > xParent );
121 };
122 
123 class TOOLKIT_DLLPUBLIC LayoutWidget
124 {
125     friend class LayoutRoot;
126 
127 public:
LayoutWidget()128     LayoutWidget() {}
129     LayoutWidget( css::uno::Reference< css::awt::XToolkit > xToolkit,
130                   css::uno::Reference< css::awt::XLayoutContainer > xToplevel,
131                   rtl::OUString unoName, long attrbs );
132     virtual ~LayoutWidget();
133 
134     virtual void setProperties( const PropList &rProps );
135     virtual void setProperty( rtl::OUString const& attr, rtl::OUString const& value );
136 
137     virtual bool addChild( LayoutWidget *pChild );
138     virtual void setChildProperties( LayoutWidget *pChild, const PropList &rProps );
139 
getPeer()140     inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer()
141     { return mxWidget; }
getContainer()142     inline css::uno::Reference< css::awt::XLayoutContainer > getContainer()
143     { return mxContainer; }
144 
145 protected:
146     css::uno::Reference< css::awt::XLayoutConstrains > mxWidget;
147     css::uno::Reference< css::awt::XLayoutContainer > mxContainer;
148 };
149 
150 } // namespace layoutimpl
151 
152 #endif /* LAYOUT_CORE_ROOT_HXX */
153