xref: /aoo41x/main/toolkit/source/layout/core/root.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef LAYOUT_CORE_ROOT_HXX
29 #define LAYOUT_CORE_ROOT_HXX
30 
31 #define _BACKWARD_BACKWARD_WARNING_H 1
32 #include <hash_map>
33 
34 #include <com/sun/star/awt/XLayoutRoot.hpp>
35 #include <com/sun/star/awt/XToolkit.hpp>
36 #include <com/sun/star/awt/XWindow.hpp>
37 #include <com/sun/star/io/XInputStream.hpp>
38 #include <com/sun/star/lang/XComponent.hpp>
39 #include <com/sun/star/lang/XInitialization.hpp>
40 #include <cppuhelper/implbase3.hxx>
41 #include <cppuhelper/interfacecontainer.h>
42 #include <toolkit/dllapi.h>
43 
44 #include <layout/core/proplist.hxx>
45 
46 namespace layoutimpl
47 {
48 
49 namespace css = ::com::sun::star;
50 
51 css::uno::Reference< css::io::XInputStream > getFileAsStream( const rtl::OUString &rName );
52 
53 /* Interface generation code -- to hook to a parser. */
54 
55 /*
56   TODO: (ricardo) I think we should cut on LayoutRoot, stripping out its widget
57   proxy interface (just make it return the root widget). Would even make it easier
58   if there was interest to support multiple toplevel widgets in the same file.
59 
60   We also need to make sure the code gets diposed well... There is no need to keep
61   these objects around after initialization...
62 */
63 
64 
65 class LayoutWidget;
66 
67 class TOOLKIT_DLLPUBLIC LayoutRoot : public ::cppu::WeakImplHelper3<
68     css::awt::XLayoutRoot,
69     css::lang::XInitialization,
70     css::lang::XComponent>
71 {
72 protected:
73     ::osl::Mutex maMutex;
74 
75     typedef std::hash_map< rtl::OUString,
76                            css::uno::Reference< css::awt::XLayoutConstrains >,
77                            ::rtl::OUStringHash > ItemHash;
78     ItemHash maItems;
79 
80     sal_Bool mbDisposed;
81     css::uno::Reference< css::lang::XMultiServiceFactory > mxFactory;
82     ::cppu::OInterfaceContainerHelper *mpListeners;
83 
84     css::uno::Reference< css::awt::XWindow >          mxWindow;
85     css::uno::Reference< css::awt::XLayoutContainer > mxContainer;
86 
87     css::uno::Reference< css::awt::XToolkit > mxToolkit;
88     LayoutWidget *mpToplevel;
89     css::uno::Reference< css::awt::XLayoutUnit > mxLayoutUnit;
90 
91     void error( rtl::OUString const& message );
92 
93 public:
94     LayoutRoot( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory );
95     virtual ~LayoutRoot();
96 
97     void addItem( const rtl::OUString &rName,
98                   const css::uno::Reference< css::awt::XLayoutConstrains > &xRef );
99 
100     void setWindow(    css::uno::Reference< css::awt::XLayoutConstrains > xPeer )
101     {
102         mxWindow = css::uno::Reference< css::awt::XWindow >( xPeer, css::uno::UNO_QUERY );
103     }
104 
105     // get XLayoutContainer
106     virtual css::uno::Reference< css::awt::XLayoutContainer > SAL_CALL getLayoutContainer() throw (css::uno::RuntimeException);
107 
108     // XInitialization
109     virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw (css::uno::Exception, css::uno::RuntimeException);
110 
111     // XNameAccess
112     virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException);
113     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (css::uno::RuntimeException);
114     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException);
115     virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException);
116     virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException);
117 
118     // XComponent
119     virtual void SAL_CALL dispose() throw (css::uno::RuntimeException);
120     virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) throw (css::uno::RuntimeException);
121     virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) throw (css::uno::RuntimeException);
122 
123     // generator
124     virtual LayoutWidget *create( rtl::OUString id, const rtl::OUString unoName, long attrbs, css::uno::Reference< css::awt::XLayoutContainer > xParent );
125 };
126 
127 class TOOLKIT_DLLPUBLIC LayoutWidget
128 {
129     friend class LayoutRoot;
130 
131 public:
132     LayoutWidget() {}
133     LayoutWidget( css::uno::Reference< css::awt::XToolkit > xToolkit,
134                   css::uno::Reference< css::awt::XLayoutContainer > xToplevel,
135                   rtl::OUString unoName, long attrbs );
136     virtual ~LayoutWidget();
137 
138     virtual void setProperties( const PropList &rProps );
139     virtual void setProperty( rtl::OUString const& attr, rtl::OUString const& value );
140 
141     virtual bool addChild( LayoutWidget *pChild );
142     virtual void setChildProperties( LayoutWidget *pChild, const PropList &rProps );
143 
144     inline css::uno::Reference< css::awt::XLayoutConstrains > getPeer()
145     { return mxWidget; }
146     inline css::uno::Reference< css::awt::XLayoutContainer > getContainer()
147     { return mxContainer; }
148 
149 protected:
150     css::uno::Reference< css::awt::XLayoutConstrains > mxWidget;
151     css::uno::Reference< css::awt::XLayoutContainer > mxContainer;
152 };
153 
154 } // namespace layoutimpl
155 
156 #endif /* LAYOUT_CORE_ROOT_HXX */
157