xref: /aoo41x/main/vcl/source/window/window4.cxx (revision 9f62ea84)
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 #include "precompiled_vcl.hxx"
25 
26 #include "vcl/window.hxx"
27 #include "vcl/arrange.hxx"
28 
29 #include "window.h"
30 #include "svdata.hxx"
31 
32 #include "com/sun/star/beans/PropertyValue.hpp"
33 
34 #include <map>
35 #include <vector>
36 
37 using namespace com::sun::star;
38 
39 namespace vcl
40 {
41     struct ExtWindowImpl
42     {
43         ExtWindowImpl()
44         : mbOwnedByParent( false )
45         {}
46         ~ExtWindowImpl()
47         {}
48 
49         boost::shared_ptr< WindowArranger >      mxLayout;
50         bool                                     mbOwnedByParent;
51         rtl::OUString                            maIdentifier;
52     };
53 }
54 
55 void Window::ImplDeleteOwnedChildren()
56 {
57     Window* pChild = mpWindowImpl->mpFirstChild;
58     while ( pChild )
59     {
60         Window* pDeleteCandidate = pChild;
61         pChild = pChild->mpWindowImpl->mpNext;
62         vcl::ExtWindowImpl* pDelImpl = pDeleteCandidate->ImplGetExtWindowImpl();
63         if( pDelImpl && pDelImpl->mbOwnedByParent )
64             delete pDeleteCandidate;
65     }
66 }
67 
68 void Window::ImplFreeExtWindowImpl()
69 {
70     ImplDeleteOwnedChildren();
71     if( mpWindowImpl )
72     {
73         delete mpWindowImpl->mpExtImpl;
74         mpWindowImpl->mpExtImpl = NULL;
75     }
76 }
77 
78 vcl::ExtWindowImpl* Window::ImplGetExtWindowImpl() const
79 {
80     vcl::ExtWindowImpl* pImpl = NULL;
81     if( mpWindowImpl )
82     {
83         if( ! mpWindowImpl->mpExtImpl && ! mpWindowImpl->mbInDtor )
84             mpWindowImpl->mpExtImpl = new vcl::ExtWindowImpl();
85         pImpl = mpWindowImpl->mpExtImpl;
86     }
87     return pImpl;
88 }
89 
90 void Window::ImplExtResize()
91 {
92     if( mpWindowImpl && mpWindowImpl->mpExtImpl )
93     {
94         if( mpWindowImpl->mpExtImpl->mxLayout.get() )
95             mpWindowImpl->mpExtImpl->mxLayout->setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
96     }
97 }
98 
99 boost::shared_ptr< vcl::WindowArranger > Window::getLayout()
100 {
101     boost::shared_ptr< vcl::WindowArranger > xRet;
102     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
103     if( pImpl )
104     {
105         if( ! pImpl->mxLayout.get() )
106         {
107             pImpl->mxLayout.reset( new vcl::LabelColumn() );
108             pImpl->mxLayout->setParentWindow( this );
109             pImpl->mxLayout->setOuterBorder( -1 );
110         }
111         xRet = pImpl->mxLayout;
112     }
113 
114     return xRet;
115 }
116 
117 void Window::addWindow( Window* i_pWin, bool i_bTakeOwnership )
118 {
119     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
120     if( pImpl && i_pWin )
121     {
122         vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
123         if( pChildImpl )
124         {
125             i_pWin->SetParent( this );
126             pChildImpl->mbOwnedByParent = i_bTakeOwnership;
127         }
128     }
129 }
130 
131 Window* Window::removeWindow( Window* i_pWin, Window* i_pNewParent )
132 {
133     Window* pRet = NULL;
134     if( i_pWin )
135     {
136         vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
137         if( pImpl )
138         {
139             vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
140             if( pChildImpl )
141             {
142                 if( ! i_pNewParent )
143                    pChildImpl->mbOwnedByParent = false;
144                i_pWin->SetParent( i_pNewParent );
145                pRet = i_pWin;
146             }
147         }
148     }
149     return pRet;
150 }
151 
152 Window* Window::findWindow( const rtl::OUString& i_rIdentifier ) const
153 {
154     if( getIdentifier() == i_rIdentifier )
155         return const_cast<Window*>(this);
156 
157     Window* pChild = mpWindowImpl->mpFirstChild;
158     while ( pChild )
159     {
160         Window* pResult = pChild->findWindow( i_rIdentifier );
161         if( pResult )
162             return pResult;
163         pChild = pChild->mpWindowImpl->mpNext;
164     }
165 
166     return NULL;
167 }
168 
169 const rtl::OUString& Window::getIdentifier() const
170 {
171     static rtl::OUString aEmptyStr;
172 
173     return (mpWindowImpl && mpWindowImpl->mpExtImpl) ? mpWindowImpl->mpExtImpl->maIdentifier : aEmptyStr;
174 }
175 
176 void Window::setIdentifier( const rtl::OUString& i_rIdentifier )
177 {
178     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
179     if( pImpl )
180         pImpl->maIdentifier = i_rIdentifier;
181 }
182 
183 void Window::setProperties( const uno::Sequence< beans::PropertyValue >& i_rProps )
184 {
185     const beans::PropertyValue* pVals = i_rProps.getConstArray();
186     for( sal_Int32 i = 0; i < i_rProps.getLength(); i++ )
187     {
188         if( pVals[i].Name.equalsAscii( "Enabled" ) )
189         {
190             sal_Bool bVal = sal_True;
191             if( pVals[i].Value >>= bVal )
192                 Enable( bVal );
193         }
194         else if( pVals[i].Name.equalsAscii( "Visible" ) )
195         {
196             sal_Bool bVal = sal_True;
197             if( pVals[i].Value >>= bVal )
198                 Show( bVal );
199         }
200         else if( pVals[i].Name.equalsAscii( "Text" ) )
201         {
202             rtl::OUString aText;
203             if( pVals[i].Value >>= aText )
204                 SetText( aText );
205         }
206     }
207 }
208 
209 uno::Sequence< beans::PropertyValue > Window::getProperties() const
210 {
211     uno::Sequence< beans::PropertyValue > aProps( 3 );
212     aProps[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
213     aProps[0].Value = uno::makeAny( sal_Bool( IsEnabled() ) );
214     aProps[1].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
215     aProps[1].Value = uno::makeAny( sal_Bool( IsVisible() ) );
216     aProps[2].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
217     aProps[2].Value = uno::makeAny( rtl::OUString( GetText() ) );
218 
219     return aProps;
220 }
221 
222