merge the formfield patch from ooo-build
[ooovba.git] / canvas / source / tools / page.hxx
blob80693fa35dde06737e82024b1d4e64fd798c5c21
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: page.hxx,v $
10 * $Revision: 1.3 $
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 #ifndef INCLUDED_CANVAS_PAGE_HXX
32 #define INCLUDED_CANVAS_PAGE_HXX
34 #include <basegfx/vector/b2isize.hxx>
35 #include <basegfx/range/b2irectangle.hxx>
36 #include <canvas/rendering/icolorbuffer.hxx>
37 #include <canvas/rendering/irendermodule.hxx>
38 #include <canvas/rendering/isurface.hxx>
40 #include <list>
41 #include <vector>
42 #include <boost/shared_ptr.hpp>
43 #include "surfacerect.hxx"
45 namespace canvas
47 class PageFragment;
49 typedef ::boost::shared_ptr< PageFragment > FragmentSharedPtr;
51 /** One page of IRenderModule-provided texture space
53 class Page
55 public:
56 Page( const IRenderModuleSharedPtr& rRenderModule );
58 FragmentSharedPtr allocateSpace( const ::basegfx::B2ISize& rSize );
59 bool nakedFragment( const FragmentSharedPtr& pFragment );
60 void free( const FragmentSharedPtr& pFragment );
61 const ISurfaceSharedPtr& getSurface() const { return mpSurface; }
62 bool isValid() const;
63 void validate();
65 private:
66 typedef std::list<FragmentSharedPtr> FragmentContainer_t;
68 IRenderModuleSharedPtr mpRenderModule;
69 ISurfaceSharedPtr mpSurface;
70 FragmentContainer_t mpFragments;
72 bool insert( SurfaceRect& r );
73 bool isValidLocation( const SurfaceRect& r ) const;
76 typedef ::boost::shared_ptr< Page > PageSharedPtr;
79 /** A part of a page, which gets allocated to a surface
81 class PageFragment
83 public:
84 PageFragment( const SurfaceRect& r,
85 Page* pPage ) :
86 mpPage(pPage),
87 maRect(r),
88 mpBuffer(),
89 maSourceOffset()
93 /// Creates a 'naked' fragment.
94 PageFragment( const ::basegfx::B2ISize& rSize ) :
95 mpPage(NULL),
96 maRect(rSize),
97 mpBuffer(),
98 maSourceOffset()
102 bool isNaked() const { return (mpPage == NULL); }
103 const SurfaceRect& getRect() const { return maRect; }
104 const ::basegfx::B2IPoint& getPos() const { return maRect.maPos; }
105 const ::basegfx::B2ISize& getSize() const { return maRect.maSize; }
106 void setColorBuffer( const IColorBufferSharedPtr& pColorBuffer ) { mpBuffer=pColorBuffer; }
107 void setSourceOffset( const ::basegfx::B2IPoint& rOffset ) { maSourceOffset=rOffset; }
108 void setPage( Page* pPage ) { mpPage=pPage; }
110 void free( const FragmentSharedPtr& pFragment )
112 if(mpPage)
113 mpPage->free(pFragment);
115 mpPage=NULL;
118 bool select( bool bRefresh )
120 // request was made to select this fragment,
121 // but this fragment has not been located on any
122 // of the available pages, we need to hurry now.
123 if(!(mpPage))
124 return false;
126 ISurfaceSharedPtr pSurface(mpPage->getSurface());
128 // select this surface before wiping the contents
129 // since a specific implementation could trigger
130 // a rendering operation here...
131 if(!(pSurface->selectTexture()))
132 return false;
134 // call refresh() if requested, otherwise we're up to date...
135 return bRefresh ? refresh() : true;
138 bool refresh()
140 if(!(mpPage))
141 return false;
143 ISurfaceSharedPtr pSurface(mpPage->getSurface());
145 return pSurface->update( maRect.maPos,
146 ::basegfx::B2IRectangle(
147 maSourceOffset,
148 maSourceOffset + maRect.maSize ),
149 *mpBuffer );
152 private:
153 Page* mpPage;
154 SurfaceRect maRect;
155 IColorBufferSharedPtr mpBuffer;
156 ::basegfx::B2IPoint maSourceOffset;
160 #endif