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
9 * $RCSfile: page.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_canvas.hxx"
34 #include <boost/bind.hpp>
39 Page::Page( const IRenderModuleSharedPtr
&rRenderModule
) :
40 mpRenderModule(rRenderModule
),
41 mpSurface(rRenderModule
->createSurface(::basegfx::B2ISize()))
49 ::std::for_each( mpFragments
.begin(),
51 ::boost::mem_fn(&PageFragment::refresh
));
55 bool Page::isValid() const
57 return mpSurface
&& mpSurface
->isValid();
60 FragmentSharedPtr
Page::allocateSpace( const ::basegfx::B2ISize
& rSize
)
62 SurfaceRect
rect(rSize
);
65 FragmentSharedPtr
pFragment(new PageFragment(rect
,this));
66 mpFragments
.push_back(pFragment
);
70 return FragmentSharedPtr();
73 bool Page::nakedFragment( const FragmentSharedPtr
& pFragment
)
75 SurfaceRect
rect(pFragment
->getSize());
78 pFragment
->setPage(this);
79 mpFragments
.push_back(pFragment
);
86 void Page::free( const FragmentSharedPtr
& pFragment
)
88 // the fragment passes as argument is no longer
89 // dedicated to this page. either it is about to
90 // be relocated to some other page or it will
91 // currently be deleted. in either case, simply
92 // remove the reference from our internal storage.
93 FragmentContainer_t::iterator
it(
95 mpFragments
.begin(),mpFragments
.end(),pFragment
));
96 mpFragments
.erase(it
,mpFragments
.end());
99 bool Page::insert( SurfaceRect
& r
)
101 const FragmentContainer_t::const_iterator
aEnd(mpFragments
.end());
102 FragmentContainer_t::const_iterator
it(mpFragments
.begin());
105 const SurfaceRect
&rect
= (*it
)->getRect();
106 const sal_Int32 x
= rect
.maPos
.getX();
107 const sal_Int32 y
= rect
.maPos
.getY();
108 // to avoid interpolation artifacts from other textures,
109 // one pixel gap between them
110 const sal_Int32 w
= rect
.maSize
.getX()+1;
111 const sal_Int32 h
= rect
.maSize
.getY()+1;
113 // probe location to the right
116 if(isValidLocation(r
))
119 // probe location at bottom
122 if(isValidLocation(r
))
131 return isValidLocation(r
);
134 bool Page::isValidLocation( const SurfaceRect
& r
) const
136 // the rectangle passed as argument has a valid
137 // location if and only if there's no intersection
138 // with existing areas.
139 SurfaceRect
aBoundary(mpRenderModule
->getPageSize()-basegfx::B2IVector(1,1));
140 if( !r
.inside(aBoundary
) )
143 const FragmentContainer_t::const_iterator
aEnd(mpFragments
.end());
144 FragmentContainer_t::const_iterator
it(mpFragments
.begin());
147 if(r
.intersection((*it
)->getRect()))