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