xref: /trunk/main/vcl/source/window/window4.cxx (revision 9f62ea84a806e17e6f2bbff75724a7257a0eb5d9)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_vcl.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "vcl/window.hxx"
27cdf0e10cSrcweir #include "vcl/arrange.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "window.h"
30cdf0e10cSrcweir #include "svdata.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <map>
35cdf0e10cSrcweir #include <vector>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace com::sun::star;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace vcl
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     struct ExtWindowImpl
42cdf0e10cSrcweir     {
43cdf0e10cSrcweir         ExtWindowImpl()
44cdf0e10cSrcweir         : mbOwnedByParent( false )
45cdf0e10cSrcweir         {}
46cdf0e10cSrcweir         ~ExtWindowImpl()
47cdf0e10cSrcweir         {}
48cdf0e10cSrcweir 
49cdf0e10cSrcweir         boost::shared_ptr< WindowArranger >      mxLayout;
50cdf0e10cSrcweir         bool                                     mbOwnedByParent;
51cdf0e10cSrcweir         rtl::OUString                            maIdentifier;
52cdf0e10cSrcweir     };
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir void Window::ImplDeleteOwnedChildren()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     Window* pChild = mpWindowImpl->mpFirstChild;
58cdf0e10cSrcweir     while ( pChild )
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         Window* pDeleteCandidate = pChild;
61cdf0e10cSrcweir         pChild = pChild->mpWindowImpl->mpNext;
62cdf0e10cSrcweir         vcl::ExtWindowImpl* pDelImpl = pDeleteCandidate->ImplGetExtWindowImpl();
63cdf0e10cSrcweir         if( pDelImpl && pDelImpl->mbOwnedByParent )
64cdf0e10cSrcweir             delete pDeleteCandidate;
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir void Window::ImplFreeExtWindowImpl()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     ImplDeleteOwnedChildren();
71cdf0e10cSrcweir     if( mpWindowImpl )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         delete mpWindowImpl->mpExtImpl;
74cdf0e10cSrcweir         mpWindowImpl->mpExtImpl = NULL;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir vcl::ExtWindowImpl* Window::ImplGetExtWindowImpl() const
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = NULL;
81cdf0e10cSrcweir     if( mpWindowImpl )
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         if( ! mpWindowImpl->mpExtImpl && ! mpWindowImpl->mbInDtor )
84cdf0e10cSrcweir             mpWindowImpl->mpExtImpl = new vcl::ExtWindowImpl();
85cdf0e10cSrcweir         pImpl = mpWindowImpl->mpExtImpl;
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir     return pImpl;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir void Window::ImplExtResize()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     if( mpWindowImpl && mpWindowImpl->mpExtImpl )
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         if( mpWindowImpl->mpExtImpl->mxLayout.get() )
95cdf0e10cSrcweir             mpWindowImpl->mpExtImpl->mxLayout->setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir boost::shared_ptr< vcl::WindowArranger > Window::getLayout()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     boost::shared_ptr< vcl::WindowArranger > xRet;
102cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
103cdf0e10cSrcweir     if( pImpl )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         if( ! pImpl->mxLayout.get() )
106cdf0e10cSrcweir         {
107cdf0e10cSrcweir             pImpl->mxLayout.reset( new vcl::LabelColumn() );
108cdf0e10cSrcweir             pImpl->mxLayout->setParentWindow( this );
109cdf0e10cSrcweir             pImpl->mxLayout->setOuterBorder( -1 );
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir         xRet = pImpl->mxLayout;
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     return xRet;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir void Window::addWindow( Window* i_pWin, bool i_bTakeOwnership )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
120cdf0e10cSrcweir     if( pImpl && i_pWin )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
123cdf0e10cSrcweir         if( pChildImpl )
124cdf0e10cSrcweir         {
125cdf0e10cSrcweir             i_pWin->SetParent( this );
126cdf0e10cSrcweir             pChildImpl->mbOwnedByParent = i_bTakeOwnership;
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir     }
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir Window* Window::removeWindow( Window* i_pWin, Window* i_pNewParent )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     Window* pRet = NULL;
134cdf0e10cSrcweir     if( i_pWin )
135cdf0e10cSrcweir     {
136cdf0e10cSrcweir         vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
137cdf0e10cSrcweir         if( pImpl )
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
140cdf0e10cSrcweir             if( pChildImpl )
141cdf0e10cSrcweir             {
142cdf0e10cSrcweir                 if( ! i_pNewParent )
143cdf0e10cSrcweir                    pChildImpl->mbOwnedByParent = false;
144cdf0e10cSrcweir                i_pWin->SetParent( i_pNewParent );
145cdf0e10cSrcweir                pRet = i_pWin;
146cdf0e10cSrcweir             }
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     return pRet;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir Window* Window::findWindow( const rtl::OUString& i_rIdentifier ) const
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     if( getIdentifier() == i_rIdentifier )
155cdf0e10cSrcweir         return const_cast<Window*>(this);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     Window* pChild = mpWindowImpl->mpFirstChild;
158cdf0e10cSrcweir     while ( pChild )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         Window* pResult = pChild->findWindow( i_rIdentifier );
161cdf0e10cSrcweir         if( pResult )
162cdf0e10cSrcweir             return pResult;
163cdf0e10cSrcweir         pChild = pChild->mpWindowImpl->mpNext;
164cdf0e10cSrcweir     }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     return NULL;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir const rtl::OUString& Window::getIdentifier() const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     static rtl::OUString aEmptyStr;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     return (mpWindowImpl && mpWindowImpl->mpExtImpl) ? mpWindowImpl->mpExtImpl->maIdentifier : aEmptyStr;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir void Window::setIdentifier( const rtl::OUString& i_rIdentifier )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
179cdf0e10cSrcweir     if( pImpl )
180cdf0e10cSrcweir         pImpl->maIdentifier = i_rIdentifier;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir void Window::setProperties( const uno::Sequence< beans::PropertyValue >& i_rProps )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     const beans::PropertyValue* pVals = i_rProps.getConstArray();
186cdf0e10cSrcweir     for( sal_Int32 i = 0; i < i_rProps.getLength(); i++ )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir         if( pVals[i].Name.equalsAscii( "Enabled" ) )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             sal_Bool bVal = sal_True;
191cdf0e10cSrcweir             if( pVals[i].Value >>= bVal )
192cdf0e10cSrcweir                 Enable( bVal );
193cdf0e10cSrcweir         }
194cdf0e10cSrcweir         else if( pVals[i].Name.equalsAscii( "Visible" ) )
195cdf0e10cSrcweir         {
196cdf0e10cSrcweir             sal_Bool bVal = sal_True;
197cdf0e10cSrcweir             if( pVals[i].Value >>= bVal )
198cdf0e10cSrcweir                 Show( bVal );
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir         else if( pVals[i].Name.equalsAscii( "Text" ) )
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir             rtl::OUString aText;
203cdf0e10cSrcweir             if( pVals[i].Value >>= aText )
204cdf0e10cSrcweir                 SetText( aText );
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > Window::getProperties() const
210cdf0e10cSrcweir {
211cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aProps( 3 );
212cdf0e10cSrcweir     aProps[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
213cdf0e10cSrcweir     aProps[0].Value = uno::makeAny( sal_Bool( IsEnabled() ) );
214cdf0e10cSrcweir     aProps[1].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
215cdf0e10cSrcweir     aProps[1].Value = uno::makeAny( sal_Bool( IsVisible() ) );
216cdf0e10cSrcweir     aProps[2].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
217cdf0e10cSrcweir     aProps[2].Value = uno::makeAny( rtl::OUString( GetText() ) );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     return aProps;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222