1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
36 #include <vcl/timer.hxx>
37 #include <com/sun/star/awt/XLayoutContainer.hpp>
41 using namespace ::com::sun::star
;
43 class AllocateTimer
: public Timer
45 typedef std::list
< uno::Reference
< awt::XLayoutContainer
> > ContainerList
;
46 ContainerList mxContainers
;
47 uno::Reference
< awt::XLayoutContainer
> mxLastAdded
;
52 // timer set to 0 -- just process it as soon as it gets idle
56 static inline bool isParentOf( uno::Reference
< awt::XLayoutContainer
> xParent
,
57 uno::Reference
< awt::XLayoutContainer
> xWidget
)
59 while ( xWidget
.is() )
61 if ( xWidget
== xParent
)
63 xWidget
= uno::Reference
< awt::XLayoutContainer
>( xWidget
->getParent(), uno::UNO_QUERY
);
68 static inline void eraseChildren( ContainerList::iterator
&it
, ContainerList
&list
)
70 ContainerList::iterator jt
= list
.begin();
71 while ( jt
!= list
.end() )
73 if ( it
!= jt
&& isParentOf( *it
, *jt
) )
74 jt
= list
.erase( jt
);
80 static inline bool isContainerDamaged( uno::Reference
< awt::XLayoutContainer
> xContainer
)
82 uno::Reference
< awt::XLayoutConstrains
> xConstrains( xContainer
, uno::UNO_QUERY
);
83 awt::Size
lastReq( xContainer
->getRequestedSize() );
84 awt::Size
curReq( xConstrains
->getMinimumSize() );
85 return lastReq
.Width
!= curReq
.Width
|| lastReq
.Height
!= curReq
.Height
;
88 void add( const uno::Reference
< awt::XLayoutContainer
> &xContainer
)
91 if ( mxLastAdded
== xContainer
)
93 mxLastAdded
= xContainer
;
95 mxContainers
.push_back( xContainer
);
98 virtual void Timeout()
100 mxLastAdded
= uno::Reference
< awt::XLayoutContainer
>();
102 // 1. remove duplications and children
103 for ( ContainerList::iterator it
= mxContainers
.begin();
104 it
!= mxContainers
.end(); it
++ )
105 eraseChildren( it
, mxContainers
);
107 // 2. check damage extent
108 for ( ContainerList::iterator it
= mxContainers
.begin();
109 it
!= mxContainers
.end(); it
++ )
111 uno::Reference
< awt::XLayoutContainer
> xContainer
= *it
;
112 while ( xContainer
->getParent().is() && isContainerDamaged( xContainer
) )
114 xContainer
= uno::Reference
< awt::XLayoutContainer
>(
115 xContainer
->getParent(), uno::UNO_QUERY
);
118 if ( *it
!= xContainer
)
120 // 2.2 replace it with parent
123 // 2.3 remove children of new parent
124 eraseChildren( it
, mxContainers
);
128 // 3. force re-calculations
129 for ( ContainerList::iterator it
= mxContainers
.begin();
130 it
!= mxContainers
.end(); it
++ )
131 (*it
)->allocateArea( (*it
)->getAllocatedArea() );
135 static void AddResizeTimeout( const uno::Reference
< awt::XLayoutContainer
> &xCont
)
137 static AllocateTimer timer
;
142 LayoutUnit::LayoutUnit() : LayoutUnit_Base()
146 void SAL_CALL
LayoutUnit::queueResize( const uno::Reference
< awt::XLayoutContainer
> &xContainer
)
147 throw( uno::RuntimeException
)
149 AddResizeTimeout( xContainer
);