xref: /aoo41x/main/vcl/source/window/window4.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "vcl/window.hxx"
31*cdf0e10cSrcweir #include "vcl/arrange.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "window.h"
34*cdf0e10cSrcweir #include "svdata.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <map>
39*cdf0e10cSrcweir #include <vector>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace com::sun::star;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir namespace vcl
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir     struct ExtWindowImpl
46*cdf0e10cSrcweir     {
47*cdf0e10cSrcweir         ExtWindowImpl()
48*cdf0e10cSrcweir         : mbOwnedByParent( false )
49*cdf0e10cSrcweir         {}
50*cdf0e10cSrcweir         ~ExtWindowImpl()
51*cdf0e10cSrcweir         {}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir         boost::shared_ptr< WindowArranger >      mxLayout;
54*cdf0e10cSrcweir         bool                                     mbOwnedByParent;
55*cdf0e10cSrcweir         rtl::OUString                            maIdentifier;
56*cdf0e10cSrcweir     };
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir void Window::ImplDeleteOwnedChildren()
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     Window* pChild = mpWindowImpl->mpFirstChild;
62*cdf0e10cSrcweir     while ( pChild )
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         Window* pDeleteCandidate = pChild;
65*cdf0e10cSrcweir         pChild = pChild->mpWindowImpl->mpNext;
66*cdf0e10cSrcweir         vcl::ExtWindowImpl* pDelImpl = pDeleteCandidate->ImplGetExtWindowImpl();
67*cdf0e10cSrcweir         if( pDelImpl && pDelImpl->mbOwnedByParent )
68*cdf0e10cSrcweir             delete pDeleteCandidate;
69*cdf0e10cSrcweir     }
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void Window::ImplFreeExtWindowImpl()
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     ImplDeleteOwnedChildren();
75*cdf0e10cSrcweir     if( mpWindowImpl )
76*cdf0e10cSrcweir     {
77*cdf0e10cSrcweir         delete mpWindowImpl->mpExtImpl;
78*cdf0e10cSrcweir         mpWindowImpl->mpExtImpl = NULL;
79*cdf0e10cSrcweir     }
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir vcl::ExtWindowImpl* Window::ImplGetExtWindowImpl() const
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = NULL;
85*cdf0e10cSrcweir     if( mpWindowImpl )
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         if( ! mpWindowImpl->mpExtImpl && ! mpWindowImpl->mbInDtor )
88*cdf0e10cSrcweir             mpWindowImpl->mpExtImpl = new vcl::ExtWindowImpl();
89*cdf0e10cSrcweir         pImpl = mpWindowImpl->mpExtImpl;
90*cdf0e10cSrcweir     }
91*cdf0e10cSrcweir     return pImpl;
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir void Window::ImplExtResize()
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     if( mpWindowImpl && mpWindowImpl->mpExtImpl )
97*cdf0e10cSrcweir     {
98*cdf0e10cSrcweir         if( mpWindowImpl->mpExtImpl->mxLayout.get() )
99*cdf0e10cSrcweir             mpWindowImpl->mpExtImpl->mxLayout->setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir boost::shared_ptr< vcl::WindowArranger > Window::getLayout()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     boost::shared_ptr< vcl::WindowArranger > xRet;
106*cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
107*cdf0e10cSrcweir     if( pImpl )
108*cdf0e10cSrcweir     {
109*cdf0e10cSrcweir         if( ! pImpl->mxLayout.get() )
110*cdf0e10cSrcweir         {
111*cdf0e10cSrcweir             pImpl->mxLayout.reset( new vcl::LabelColumn() );
112*cdf0e10cSrcweir             pImpl->mxLayout->setParentWindow( this );
113*cdf0e10cSrcweir             pImpl->mxLayout->setOuterBorder( -1 );
114*cdf0e10cSrcweir         }
115*cdf0e10cSrcweir         xRet = pImpl->mxLayout;
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     return xRet;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir void Window::addWindow( Window* i_pWin, bool i_bTakeOwnership )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
124*cdf0e10cSrcweir     if( pImpl && i_pWin )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
127*cdf0e10cSrcweir         if( pChildImpl )
128*cdf0e10cSrcweir         {
129*cdf0e10cSrcweir             i_pWin->SetParent( this );
130*cdf0e10cSrcweir             pChildImpl->mbOwnedByParent = i_bTakeOwnership;
131*cdf0e10cSrcweir         }
132*cdf0e10cSrcweir     }
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir Window* Window::removeWindow( Window* i_pWin, Window* i_pNewParent )
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir     Window* pRet = NULL;
138*cdf0e10cSrcweir     if( i_pWin )
139*cdf0e10cSrcweir     {
140*cdf0e10cSrcweir         vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
141*cdf0e10cSrcweir         if( pImpl )
142*cdf0e10cSrcweir         {
143*cdf0e10cSrcweir             vcl::ExtWindowImpl* pChildImpl = i_pWin->ImplGetExtWindowImpl();
144*cdf0e10cSrcweir             if( pChildImpl )
145*cdf0e10cSrcweir             {
146*cdf0e10cSrcweir                 if( ! i_pNewParent )
147*cdf0e10cSrcweir                    pChildImpl->mbOwnedByParent = false;
148*cdf0e10cSrcweir                i_pWin->SetParent( i_pNewParent );
149*cdf0e10cSrcweir                pRet = i_pWin;
150*cdf0e10cSrcweir             }
151*cdf0e10cSrcweir         }
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir     return pRet;
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir Window* Window::findWindow( const rtl::OUString& i_rIdentifier ) const
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     if( getIdentifier() == i_rIdentifier )
159*cdf0e10cSrcweir         return const_cast<Window*>(this);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     Window* pChild = mpWindowImpl->mpFirstChild;
162*cdf0e10cSrcweir     while ( pChild )
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         Window* pResult = pChild->findWindow( i_rIdentifier );
165*cdf0e10cSrcweir         if( pResult )
166*cdf0e10cSrcweir             return pResult;
167*cdf0e10cSrcweir         pChild = pChild->mpWindowImpl->mpNext;
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir     return NULL;
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir const rtl::OUString& Window::getIdentifier() const
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     static rtl::OUString aEmptyStr;
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     return (mpWindowImpl && mpWindowImpl->mpExtImpl) ? mpWindowImpl->mpExtImpl->maIdentifier : aEmptyStr;
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir void Window::setIdentifier( const rtl::OUString& i_rIdentifier )
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     vcl::ExtWindowImpl* pImpl = ImplGetExtWindowImpl();
183*cdf0e10cSrcweir     if( pImpl )
184*cdf0e10cSrcweir         pImpl->maIdentifier = i_rIdentifier;
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir void Window::setProperties( const uno::Sequence< beans::PropertyValue >& i_rProps )
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     const beans::PropertyValue* pVals = i_rProps.getConstArray();
190*cdf0e10cSrcweir     for( sal_Int32 i = 0; i < i_rProps.getLength(); i++ )
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         if( pVals[i].Name.equalsAscii( "Enabled" ) )
193*cdf0e10cSrcweir         {
194*cdf0e10cSrcweir             sal_Bool bVal = sal_True;
195*cdf0e10cSrcweir             if( pVals[i].Value >>= bVal )
196*cdf0e10cSrcweir                 Enable( bVal );
197*cdf0e10cSrcweir         }
198*cdf0e10cSrcweir         else if( pVals[i].Name.equalsAscii( "Visible" ) )
199*cdf0e10cSrcweir         {
200*cdf0e10cSrcweir             sal_Bool bVal = sal_True;
201*cdf0e10cSrcweir             if( pVals[i].Value >>= bVal )
202*cdf0e10cSrcweir                 Show( bVal );
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir         else if( pVals[i].Name.equalsAscii( "Text" ) )
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir             rtl::OUString aText;
207*cdf0e10cSrcweir             if( pVals[i].Value >>= aText )
208*cdf0e10cSrcweir                 SetText( aText );
209*cdf0e10cSrcweir         }
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > Window::getProperties() const
214*cdf0e10cSrcweir {
215*cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aProps( 3 );
216*cdf0e10cSrcweir     aProps[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
217*cdf0e10cSrcweir     aProps[0].Value = uno::makeAny( sal_Bool( IsEnabled() ) );
218*cdf0e10cSrcweir     aProps[1].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
219*cdf0e10cSrcweir     aProps[1].Value = uno::makeAny( sal_Bool( IsVisible() ) );
220*cdf0e10cSrcweir     aProps[2].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
221*cdf0e10cSrcweir     aProps[2].Value = uno::makeAny( rtl::OUString( GetText() ) );
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir     return aProps;
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226