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