1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "vcl/window.hxx"
31 #include "vcl/arrange.hxx"
36 #include "com/sun/star/beans/PropertyValue.hpp"
41 using namespace com::sun::star
;
48 : mbOwnedByParent( false )
53 boost::shared_ptr
< WindowArranger
> mxLayout
;
55 rtl::OUString maIdentifier
;
59 void Window::ImplDeleteOwnedChildren()
61 Window
* pChild
= mpWindowImpl
->mpFirstChild
;
64 Window
* pDeleteCandidate
= pChild
;
65 pChild
= pChild
->mpWindowImpl
->mpNext
;
66 vcl::ExtWindowImpl
* pDelImpl
= pDeleteCandidate
->ImplGetExtWindowImpl();
67 if( pDelImpl
&& pDelImpl
->mbOwnedByParent
)
68 delete pDeleteCandidate
;
72 void Window::ImplFreeExtWindowImpl()
74 ImplDeleteOwnedChildren();
77 delete mpWindowImpl
->mpExtImpl
;
78 mpWindowImpl
->mpExtImpl
= NULL
;
82 vcl::ExtWindowImpl
* Window::ImplGetExtWindowImpl() const
84 vcl::ExtWindowImpl
* pImpl
= NULL
;
87 if( ! mpWindowImpl
->mpExtImpl
&& ! mpWindowImpl
->mbInDtor
)
88 mpWindowImpl
->mpExtImpl
= new vcl::ExtWindowImpl();
89 pImpl
= mpWindowImpl
->mpExtImpl
;
94 void Window::ImplExtResize()
96 if( mpWindowImpl
&& mpWindowImpl
->mpExtImpl
)
98 if( mpWindowImpl
->mpExtImpl
->mxLayout
.get() )
99 mpWindowImpl
->mpExtImpl
->mxLayout
->setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
103 boost::shared_ptr
< vcl::WindowArranger
> Window::getLayout()
105 boost::shared_ptr
< vcl::WindowArranger
> xRet
;
106 vcl::ExtWindowImpl
* pImpl
= ImplGetExtWindowImpl();
109 if( ! pImpl
->mxLayout
.get() )
111 pImpl
->mxLayout
.reset( new vcl::LabelColumn() );
112 pImpl
->mxLayout
->setParentWindow( this );
113 pImpl
->mxLayout
->setOuterBorder( -1 );
115 xRet
= pImpl
->mxLayout
;
121 void Window::addWindow( Window
* i_pWin
, bool i_bTakeOwnership
)
123 vcl::ExtWindowImpl
* pImpl
= ImplGetExtWindowImpl();
124 if( pImpl
&& i_pWin
)
126 vcl::ExtWindowImpl
* pChildImpl
= i_pWin
->ImplGetExtWindowImpl();
129 i_pWin
->SetParent( this );
130 pChildImpl
->mbOwnedByParent
= i_bTakeOwnership
;
135 Window
* Window::findWindow( const rtl::OUString
& i_rIdentifier
) const
137 if( getIdentifier() == i_rIdentifier
)
138 return const_cast<Window
*>(this);
140 Window
* pChild
= mpWindowImpl
->mpFirstChild
;
143 Window
* pResult
= pChild
->findWindow( i_rIdentifier
);
146 pChild
= pChild
->mpWindowImpl
->mpNext
;
152 const rtl::OUString
& Window::getIdentifier() const
154 static rtl::OUString aEmptyStr
;
156 return (mpWindowImpl
&& mpWindowImpl
->mpExtImpl
) ? mpWindowImpl
->mpExtImpl
->maIdentifier
: aEmptyStr
;
159 void Window::setProperties( const uno::Sequence
< beans::PropertyValue
>& i_rProps
)
161 const beans::PropertyValue
* pVals
= i_rProps
.getConstArray();
162 for( sal_Int32 i
= 0; i
< i_rProps
.getLength(); i
++ )
164 if ( pVals
[i
].Name
== "Enabled" )
166 sal_Bool bVal
= sal_True
;
167 if( pVals
[i
].Value
>>= bVal
)
170 else if ( pVals
[i
].Name
== "Visible" )
172 sal_Bool bVal
= sal_True
;
173 if( pVals
[i
].Value
>>= bVal
)
176 else if ( pVals
[i
].Name
== "Text" )
179 if( pVals
[i
].Value
>>= aText
)
185 uno::Sequence
< beans::PropertyValue
> Window::getProperties() const
187 uno::Sequence
< beans::PropertyValue
> aProps( 3 );
188 aProps
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) );
189 aProps
[0].Value
= uno::makeAny( sal_Bool( IsEnabled() ) );
190 aProps
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Visible" ) );
191 aProps
[1].Value
= uno::makeAny( sal_Bool( IsVisible() ) );
192 aProps
[2].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) );
193 aProps
[2].Value
= uno::makeAny( rtl::OUString( GetText() ) );
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */