merge the formfield patch from ooo-build
[ooovba.git] / sdext / source / presenter / PresenterUIPainter.cxx
blob96f5e40d67298fa1472f6264213245b6abd516a5
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: PresenterUIPainter.cxx,v $
11 * $Revision: 1.4 $
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 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterUIPainter.hxx"
37 #include "PresenterCanvasHelper.hxx"
38 #include "PresenterGeometryHelper.hxx"
39 #include <com/sun/star/rendering/CompositeOperation.hpp>
40 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
45 namespace sdext { namespace presenter {
48 void PresenterUIPainter::PaintHorizontalBitmapComposite (
49 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
50 const css::awt::Rectangle& rRepaintBox,
51 const css::awt::Rectangle& rBoundingBox,
52 const css::uno::Reference<css::rendering::XBitmap>& rxLeftBitmap,
53 const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
54 const css::uno::Reference<css::rendering::XBitmap>& rxRightBitmap)
56 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
58 // The bounding box lies completly outside the repaint area.
59 // Nothing has to be repainted.
60 return;
63 // Get bitmap sizes.
64 geometry::IntegerSize2D aLeftBitmapSize;
65 if (rxLeftBitmap.is())
66 aLeftBitmapSize = rxLeftBitmap->getSize();
67 geometry::IntegerSize2D aCenterBitmapSize;
68 if (rxRepeatableCenterBitmap.is())
69 aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
70 geometry::IntegerSize2D aRightBitmapSize;
71 if (rxRightBitmap.is())
72 aRightBitmapSize = rxRightBitmap->getSize();
74 // Prepare painting.
75 rendering::ViewState aViewState (
76 geometry::AffineMatrix2D(1,0,0, 0,1,0),
77 NULL);
79 rendering::RenderState aRenderState (
80 geometry::AffineMatrix2D(1,0,0, 0,1,0),
81 NULL,
82 Sequence<double>(4),
83 rendering::CompositeOperation::SOURCE);
85 // Paint the left bitmap once.
86 if (rxLeftBitmap.is())
88 const awt::Rectangle aLeftBoundingBox (
89 rBoundingBox.X,
90 rBoundingBox.Y,
91 ::std::min(aLeftBitmapSize.Width, rBoundingBox.Width),
92 rBoundingBox.Height);
93 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
94 PresenterGeometryHelper::CreatePolygon(
95 PresenterGeometryHelper::Intersection(rRepaintBox, aLeftBoundingBox),
96 rxCanvas->getDevice()));
97 aRenderState.AffineTransform.m02 = aLeftBoundingBox.X;
98 aRenderState.AffineTransform.m12
99 = aLeftBoundingBox.Y + (aLeftBoundingBox.Height - aLeftBitmapSize.Height) / 2;
100 rxCanvas->drawBitmap(rxLeftBitmap, aViewState, aRenderState);
103 // Paint the right bitmap once.
104 if (rxRightBitmap.is())
106 const awt::Rectangle aRightBoundingBox (
107 rBoundingBox.X + rBoundingBox.Width - aRightBitmapSize.Width,
108 rBoundingBox.Y,
109 ::std::min(aRightBitmapSize.Width, rBoundingBox.Width),
110 rBoundingBox.Height);
111 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
112 PresenterGeometryHelper::CreatePolygon(
113 PresenterGeometryHelper::Intersection(rRepaintBox, aRightBoundingBox),
114 rxCanvas->getDevice()));
115 aRenderState.AffineTransform.m02
116 = aRightBoundingBox.X + aRightBoundingBox.Width - aRightBitmapSize.Width;
117 aRenderState.AffineTransform.m12
118 = aRightBoundingBox.Y + (aRightBoundingBox.Height - aRightBitmapSize.Height) / 2;
119 rxCanvas->drawBitmap(rxRightBitmap, aViewState, aRenderState);
122 // Paint the center bitmap to fill the remaining space.
123 if (rxRepeatableCenterBitmap.is())
125 const awt::Rectangle aCenterBoundingBox (
126 rBoundingBox.X + aLeftBitmapSize.Width,
127 rBoundingBox.Y,
128 rBoundingBox.Width - aLeftBitmapSize.Width - aRightBitmapSize.Width,
129 rBoundingBox.Height);
130 if (aCenterBoundingBox.Width > 0)
132 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
133 PresenterGeometryHelper::CreatePolygon(
134 PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
135 rxCanvas->getDevice()));
136 sal_Int32 nX (aCenterBoundingBox.X);
137 const sal_Int32 nRight (aCenterBoundingBox.X + aCenterBoundingBox.Width - 1);
138 aRenderState.AffineTransform.m12
139 = aCenterBoundingBox.Y + (aCenterBoundingBox.Height-aCenterBitmapSize.Height) / 2;
140 while(nX <= nRight)
142 aRenderState.AffineTransform.m02 = nX;
143 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
144 nX += aCenterBitmapSize.Width;
153 void PresenterUIPainter::PaintVerticalBitmapComposite (
154 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
155 const css::awt::Rectangle& rRepaintBox,
156 const css::awt::Rectangle& rBoundingBox,
157 const css::uno::Reference<css::rendering::XBitmap>& rxTopBitmap,
158 const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
159 const css::uno::Reference<css::rendering::XBitmap>& rxBottomBitmap)
161 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
163 // The bounding box lies completly outside the repaint area.
164 // Nothing has to be repainted.
165 return;
168 // Get bitmap sizes.
169 geometry::IntegerSize2D aTopBitmapSize;
170 if (rxTopBitmap.is())
171 aTopBitmapSize = rxTopBitmap->getSize();
172 geometry::IntegerSize2D aCenterBitmapSize;
173 if (rxRepeatableCenterBitmap.is())
174 aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
175 geometry::IntegerSize2D aBottomBitmapSize;
176 if (rxBottomBitmap.is())
177 aBottomBitmapSize = rxBottomBitmap->getSize();
179 // Prepare painting.
180 rendering::ViewState aViewState (
181 geometry::AffineMatrix2D(1,0,0, 0,1,0),
182 NULL);
184 rendering::RenderState aRenderState (
185 geometry::AffineMatrix2D(1,0,0, 0,1,0),
186 NULL,
187 Sequence<double>(4),
188 rendering::CompositeOperation::SOURCE);
190 // Paint the top bitmap once.
191 if (rxTopBitmap.is())
193 const awt::Rectangle aTopBoundingBox (
194 rBoundingBox.X,
195 rBoundingBox.Y,
196 rBoundingBox.Width,
197 ::std::min(aTopBitmapSize.Height, rBoundingBox.Height));
198 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
199 PresenterGeometryHelper::CreatePolygon(
200 PresenterGeometryHelper::Intersection(rRepaintBox, aTopBoundingBox),
201 rxCanvas->getDevice()));
202 aRenderState.AffineTransform.m02
203 = aTopBoundingBox.X + (aTopBoundingBox.Width - aTopBitmapSize.Width) / 2;
204 aRenderState.AffineTransform.m12 = aTopBoundingBox.Y;
205 rxCanvas->drawBitmap(rxTopBitmap, aViewState, aRenderState);
208 // Paint the bottom bitmap once.
209 if (rxBottomBitmap.is())
211 const sal_Int32 nBBoxHeight (::std::min(aBottomBitmapSize.Height, rBoundingBox.Height));
212 const awt::Rectangle aBottomBoundingBox (
213 rBoundingBox.X,
214 rBoundingBox.Y + rBoundingBox.Height - nBBoxHeight,
215 rBoundingBox.Width,
216 nBBoxHeight);
217 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
218 PresenterGeometryHelper::CreatePolygon(
219 PresenterGeometryHelper::Intersection(rRepaintBox, aBottomBoundingBox),
220 rxCanvas->getDevice()));
221 aRenderState.AffineTransform.m02
222 = aBottomBoundingBox.X + (aBottomBoundingBox.Width - aBottomBitmapSize.Width) / 2;
223 aRenderState.AffineTransform.m12
224 = aBottomBoundingBox.Y + aBottomBoundingBox.Height - aBottomBitmapSize.Height;
225 rxCanvas->drawBitmap(rxBottomBitmap, aViewState, aRenderState);
228 // Paint the center bitmap to fill the remaining space.
229 if (rxRepeatableCenterBitmap.is())
231 const awt::Rectangle aCenterBoundingBox (
232 rBoundingBox.X,
233 rBoundingBox.Y + aTopBitmapSize.Height,
234 rBoundingBox.Width,
235 rBoundingBox.Height - aTopBitmapSize.Height - aBottomBitmapSize.Height);
236 if (aCenterBoundingBox.Height > 0)
238 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
239 PresenterGeometryHelper::CreatePolygon(
240 PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
241 rxCanvas->getDevice()));
242 sal_Int32 nY (aCenterBoundingBox.Y);
243 const sal_Int32 nBottom (aCenterBoundingBox.Y + aCenterBoundingBox.Height - 1);
244 aRenderState.AffineTransform.m02
245 = aCenterBoundingBox.X + (aCenterBoundingBox.Width-aCenterBitmapSize.Width) / 2;
246 while(nY <= nBottom)
248 aRenderState.AffineTransform.m12 = nY;
249 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
250 nY += aCenterBitmapSize.Height;
260 } } // end of namespace sdext::presenter