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