1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f6e50924SAndrew Rist * distributed with this work for additional information
6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist * software distributed under the License is distributed on an
15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17f6e50924SAndrew Rist * specific language governing permissions and limitations
18f6e50924SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20f6e50924SAndrew Rist *************************************************************/
21f6e50924SAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir #include <tools/poly.hxx>
26cdf0e10cSrcweir #include <vcl/metric.hxx>
27cdf0e10cSrcweir #include <vcl/svapp.hxx>
28cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
29cdf0e10cSrcweir #include <svx/swframeexample.hxx>
30cdf0e10cSrcweir #include <com/sun/star/text/TextContentAnchorType.hpp>
31cdf0e10cSrcweir #include <com/sun/star/text/HoriOrientation.hpp>
32cdf0e10cSrcweir #include <com/sun/star/text/VertOrientation.hpp>
33cdf0e10cSrcweir #include <com/sun/star/text/RelOrientation.hpp>
34cdf0e10cSrcweir #include <com/sun/star/text/WrapTextMode.hpp>
35cdf0e10cSrcweir
36cdf0e10cSrcweir using namespace ::com::sun::star::text;
37cdf0e10cSrcweir
38cdf0e10cSrcweir #define FLYINFLY_BORDER 3
39cdf0e10cSrcweir #define DEMOTEXT "Ij"
40cdf0e10cSrcweir #define C2S(cChar) UniString::CreateFromAscii(cChar)
41cdf0e10cSrcweir
SvxSwFrameExample(Window * pParent,const ResId & rResID)42cdf0e10cSrcweir SvxSwFrameExample::SvxSwFrameExample( Window *pParent, const ResId& rResID ) :
43cdf0e10cSrcweir
44cdf0e10cSrcweir Window(pParent, rResID),
45cdf0e10cSrcweir
46cdf0e10cSrcweir nHAlign (HoriOrientation::CENTER),
47cdf0e10cSrcweir nHRel (RelOrientation::FRAME),
48cdf0e10cSrcweir nVAlign (VertOrientation::TOP),
49cdf0e10cSrcweir nVRel (RelOrientation::PRINT_AREA),
50cdf0e10cSrcweir nWrap (WrapTextMode_NONE),
51cdf0e10cSrcweir nAnchor (TextContentAnchorType_AT_PAGE),
52cdf0e10cSrcweir bTrans (sal_False),
53cdf0e10cSrcweir aRelPos (Point(0,0))
54cdf0e10cSrcweir {
55cdf0e10cSrcweir InitColors_Impl();
56cdf0e10cSrcweir SetMapMode(MAP_PIXEL);
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
~SvxSwFrameExample()59cdf0e10cSrcweir SvxSwFrameExample::~SvxSwFrameExample()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
InitColors_Impl(void)63cdf0e10cSrcweir void SvxSwFrameExample::InitColors_Impl( void )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir const StyleSettings& rSettings = GetSettings().GetStyleSettings();
66cdf0e10cSrcweir m_aBgCol = Color( rSettings.GetWindowColor() ); // old: COL_WHITE
67cdf0e10cSrcweir
68cdf0e10cSrcweir sal_Bool bHC = rSettings.GetHighContrastMode();
69cdf0e10cSrcweir
70cdf0e10cSrcweir m_aFrameColor = Color( COL_LIGHTGREEN );
71cdf0e10cSrcweir m_aAlignColor = Color( COL_LIGHTRED );
72cdf0e10cSrcweir m_aTransColor = Color( COL_TRANSPARENT );
73cdf0e10cSrcweir
74cdf0e10cSrcweir m_aTxtCol = bHC?
75cdf0e10cSrcweir svtools::ColorConfig().GetColorValue(svtools::FONTCOLOR).nColor :
76cdf0e10cSrcweir Color( COL_GRAY ); // old: COL_GRAY
77cdf0e10cSrcweir m_aPrintAreaCol = bHC? m_aTxtCol : Color( COL_GRAY );
78cdf0e10cSrcweir m_aBorderCol = m_aTxtCol; // old: COL_BLACK;
79cdf0e10cSrcweir m_aBlankCol = bHC? m_aTxtCol : Color( COL_LIGHTGRAY );
80cdf0e10cSrcweir m_aBlankFrameCol = bHC? m_aTxtCol : Color( COL_GRAY );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
DataChanged(const DataChangedEvent & rDCEvt)83cdf0e10cSrcweir void SvxSwFrameExample::DataChanged( const DataChangedEvent& rDCEvt )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir Window::DataChanged( rDCEvt );
86cdf0e10cSrcweir
87cdf0e10cSrcweir if( rDCEvt.GetType() == DATACHANGED_SETTINGS && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
88cdf0e10cSrcweir InitColors_Impl();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
InitAllRects_Impl()91cdf0e10cSrcweir void SvxSwFrameExample::InitAllRects_Impl()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir // const Size aSz(GetOutputSizePixel());
94cdf0e10cSrcweir
95*c9a68a5cSmseidel // Page
96cdf0e10cSrcweir // aPage.SetSize(Size(aSz.Width() - 3, aSz.Height() - 3));
97cdf0e10cSrcweir aPage.SetSize( GetOutputSizePixel() );
98cdf0e10cSrcweir
99cdf0e10cSrcweir sal_uIntPtr nOutWPix = aPage.GetWidth();
100cdf0e10cSrcweir sal_uIntPtr nOutHPix = aPage.GetHeight();
101cdf0e10cSrcweir
102cdf0e10cSrcweir // PrintArea
103cdf0e10cSrcweir sal_uIntPtr nLBorder;
104cdf0e10cSrcweir sal_uIntPtr nRBorder;
105cdf0e10cSrcweir sal_uIntPtr nTBorder;
106cdf0e10cSrcweir sal_uIntPtr nBBorder;
107cdf0e10cSrcweir
108cdf0e10cSrcweir sal_uIntPtr nLTxtBorder;
109cdf0e10cSrcweir sal_uIntPtr nRTxtBorder;
110cdf0e10cSrcweir sal_uIntPtr nTTxtBorder;
111cdf0e10cSrcweir sal_uIntPtr nBTxtBorder;
112cdf0e10cSrcweir
113cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AS_CHARACTER)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir nLBorder = 14;
116cdf0e10cSrcweir nRBorder = 10;
117cdf0e10cSrcweir nTBorder = 10;
118cdf0e10cSrcweir nBBorder = 15;
119cdf0e10cSrcweir
120cdf0e10cSrcweir nLTxtBorder = 8;
121cdf0e10cSrcweir nRTxtBorder = 4;
122cdf0e10cSrcweir nTTxtBorder = 2;
123cdf0e10cSrcweir nBTxtBorder = 2;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir else
126cdf0e10cSrcweir {
127cdf0e10cSrcweir nLBorder = 2;
128cdf0e10cSrcweir nRBorder = 2;
129cdf0e10cSrcweir nTBorder = 2;
130cdf0e10cSrcweir nBBorder = 2;
131cdf0e10cSrcweir
132cdf0e10cSrcweir nLTxtBorder = 2;
133cdf0e10cSrcweir nRTxtBorder = 2;
134cdf0e10cSrcweir nTTxtBorder = 2;
135cdf0e10cSrcweir nBTxtBorder = 2;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir aPagePrtArea = Rectangle(Point(nLBorder, nTBorder), Point((nOutWPix - 1) - nRBorder, (nOutHPix - 1) - nBBorder));
138cdf0e10cSrcweir
139*c9a68a5cSmseidel // Beispiel-Text: Vorbereiten für die Textausgabe
140cdf0e10cSrcweir // Eine Textzeile
141cdf0e10cSrcweir aTextLine = aPagePrtArea;
142cdf0e10cSrcweir aTextLine.SetSize(Size(aTextLine.GetWidth(), 2));
143cdf0e10cSrcweir aTextLine.Left() += nLTxtBorder;
144cdf0e10cSrcweir aTextLine.Right() -= nRTxtBorder;
145cdf0e10cSrcweir aTextLine.Move(0, nTTxtBorder);
146cdf0e10cSrcweir
147*c9a68a5cSmseidel // Rechteck um Absatz incl. Ränder
148cdf0e10cSrcweir sal_uInt16 nLines = (sal_uInt16)((aPagePrtArea.GetHeight() / 2 - nTTxtBorder - nBTxtBorder)
149cdf0e10cSrcweir / (aTextLine.GetHeight() + 2));
150cdf0e10cSrcweir aPara = aPagePrtArea;
151cdf0e10cSrcweir aPara.SetSize(Size(aPara.GetWidth(),
152cdf0e10cSrcweir (aTextLine.GetHeight() + 2) * nLines + nTTxtBorder + nBTxtBorder));
153cdf0e10cSrcweir
154*c9a68a5cSmseidel // Rechteck um Absatz ohne Ränder
155cdf0e10cSrcweir aParaPrtArea = aPara;
156cdf0e10cSrcweir aParaPrtArea.Left() += nLTxtBorder;
157cdf0e10cSrcweir aParaPrtArea.Right() -= nRTxtBorder;
158cdf0e10cSrcweir aParaPrtArea.Top() += nTTxtBorder;
159cdf0e10cSrcweir aParaPrtArea.Bottom() -= nBTxtBorder;
160cdf0e10cSrcweir
161cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AS_CHARACTER || nAnchor == TextContentAnchorType_AT_CHARACTER)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir Font aFont = OutputDevice::GetDefaultFont(
164cdf0e10cSrcweir DEFAULTFONT_LATIN_TEXT, Application::GetSettings().GetLanguage(),
165cdf0e10cSrcweir DEFAULTFONT_FLAGS_ONLYONE, this );
166cdf0e10cSrcweir aFont.SetColor( m_aTxtCol );
167cdf0e10cSrcweir aFont.SetFillColor( m_aBgCol );
168cdf0e10cSrcweir aFont.SetWeight(WEIGHT_NORMAL);
169cdf0e10cSrcweir
170cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AS_CHARACTER)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir aFont.SetSize(Size(0, aParaPrtArea.GetHeight() - 2));
173cdf0e10cSrcweir SetFont(aFont);
174cdf0e10cSrcweir aParaPrtArea.SetSize(Size(GetTextWidth(C2S(DEMOTEXT)), GetTextHeight()));
175cdf0e10cSrcweir }
176cdf0e10cSrcweir else
177cdf0e10cSrcweir {
178cdf0e10cSrcweir aFont.SetSize(Size(0, aParaPrtArea.GetHeight() / 2));
179cdf0e10cSrcweir SetFont(aFont);
180cdf0e10cSrcweir aAutoCharFrame.SetSize(Size(GetTextWidth('A'), GetTextHeight()));
181cdf0e10cSrcweir aAutoCharFrame.SetPos(Point(aParaPrtArea.Left() + (aParaPrtArea.GetWidth() - aAutoCharFrame.GetWidth()) / 2,
182cdf0e10cSrcweir aParaPrtArea.Top() + (aParaPrtArea.GetHeight() - aAutoCharFrame.GetHeight()) / 2));
183cdf0e10cSrcweir }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
186*c9a68a5cSmseidel // Innerer Frame für am Frame verankerte Rahmen
187cdf0e10cSrcweir aFrameAtFrame = aPara;
188cdf0e10cSrcweir aFrameAtFrame.Left() += 9;
189cdf0e10cSrcweir aFrameAtFrame.Right() -= 5;
190cdf0e10cSrcweir aFrameAtFrame.Bottom() += 5;
191cdf0e10cSrcweir aFrameAtFrame.SetPos(Point(aFrameAtFrame.Left() + 2, (aPagePrtArea.Bottom() - aFrameAtFrame.GetHeight()) / 2 + 5));
192cdf0e10cSrcweir
193cdf0e10cSrcweir // Groesse des zu positionierenden Rahmens
194cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AS_CHARACTER)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir sal_uIntPtr nLFBorder = nAnchor == TextContentAnchorType_AT_PAGE ? nLBorder : nLTxtBorder;
197cdf0e10cSrcweir sal_uIntPtr nRFBorder = nAnchor == TextContentAnchorType_AT_PAGE ? nRBorder : nRTxtBorder;
198cdf0e10cSrcweir
199cdf0e10cSrcweir switch (nHRel)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir case RelOrientation::PAGE_LEFT:
202cdf0e10cSrcweir case RelOrientation::FRAME_LEFT:
203cdf0e10cSrcweir aFrmSize = Size(nLFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
204cdf0e10cSrcweir break;
205cdf0e10cSrcweir
206cdf0e10cSrcweir case RelOrientation::PAGE_RIGHT:
207cdf0e10cSrcweir case RelOrientation::FRAME_RIGHT:
208cdf0e10cSrcweir aFrmSize = Size(nRFBorder - 4, (aTextLine.GetHeight() + 2) * 3);
209cdf0e10cSrcweir break;
210cdf0e10cSrcweir
211cdf0e10cSrcweir default:
212cdf0e10cSrcweir aFrmSize = Size(nLBorder - 3, (aTextLine.GetHeight() + 2) * 3);
213cdf0e10cSrcweir break;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir aFrmSize.Width() = Max(5L, aFrmSize.Width());
216cdf0e10cSrcweir aFrmSize.Height() = Max(5L, aFrmSize.Height());
217cdf0e10cSrcweir }
218cdf0e10cSrcweir else
219cdf0e10cSrcweir {
220cdf0e10cSrcweir sal_uIntPtr nFreeWidth = aPagePrtArea.GetWidth() - GetTextWidth(C2S(DEMOTEXT));
221cdf0e10cSrcweir
222cdf0e10cSrcweir aFrmSize = Size(nFreeWidth / 2, (aTextLine.GetHeight() + 2) * 3);
223cdf0e10cSrcweir aDrawObj.SetSize(Size(Max(5L, (long)nFreeWidth / 3L), Max(5L, aFrmSize.Height() * 3L)));
224cdf0e10cSrcweir aDrawObj.SetPos(Point(aParaPrtArea.Right() + 1, aParaPrtArea.Bottom() / 2));
225cdf0e10cSrcweir aParaPrtArea.Right() = aDrawObj.Right();
226cdf0e10cSrcweir }
227cdf0e10cSrcweir }
228cdf0e10cSrcweir
CalcBoundRect_Impl(Rectangle & rRect)229cdf0e10cSrcweir void SvxSwFrameExample::CalcBoundRect_Impl(Rectangle &rRect)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir switch (nAnchor)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir case TextContentAnchorType_AT_PAGE:
234cdf0e10cSrcweir {
235cdf0e10cSrcweir switch (nHRel)
236cdf0e10cSrcweir {
237cdf0e10cSrcweir case RelOrientation::FRAME:
238cdf0e10cSrcweir case RelOrientation::PAGE_FRAME:
239cdf0e10cSrcweir rRect.Left() = aPage.Left();
240cdf0e10cSrcweir rRect.Right() = aPage.Right();
241cdf0e10cSrcweir break;
242cdf0e10cSrcweir
243cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
244cdf0e10cSrcweir case RelOrientation::PAGE_PRINT_AREA:
245cdf0e10cSrcweir rRect.Left() = aPagePrtArea.Left();
246cdf0e10cSrcweir rRect.Right() = aPagePrtArea.Right();
247cdf0e10cSrcweir break;
248cdf0e10cSrcweir
249cdf0e10cSrcweir case RelOrientation::PAGE_LEFT:
250cdf0e10cSrcweir rRect.Left() = aPage.Left();
251cdf0e10cSrcweir rRect.Right() = aPagePrtArea.Left();
252cdf0e10cSrcweir break;
253cdf0e10cSrcweir
254cdf0e10cSrcweir case RelOrientation::PAGE_RIGHT:
255cdf0e10cSrcweir rRect.Left() = aPagePrtArea.Right();
256cdf0e10cSrcweir rRect.Right() = aPage.Right();
257cdf0e10cSrcweir break;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir switch (nVRel)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
263cdf0e10cSrcweir case RelOrientation::PAGE_PRINT_AREA:
264cdf0e10cSrcweir rRect.Top() = aPagePrtArea.Top();
265cdf0e10cSrcweir rRect.Bottom() = aPagePrtArea.Bottom();
266cdf0e10cSrcweir break;
267cdf0e10cSrcweir
268cdf0e10cSrcweir case RelOrientation::FRAME:
269cdf0e10cSrcweir case RelOrientation::PAGE_FRAME:
270cdf0e10cSrcweir rRect.Top() = aPage.Top();
271cdf0e10cSrcweir rRect.Bottom() = aPage.Bottom();
272cdf0e10cSrcweir break;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir break;
276cdf0e10cSrcweir
277cdf0e10cSrcweir case TextContentAnchorType_AT_FRAME:
278cdf0e10cSrcweir {
279cdf0e10cSrcweir switch (nHRel)
280cdf0e10cSrcweir {
281cdf0e10cSrcweir case RelOrientation::FRAME:
282cdf0e10cSrcweir case RelOrientation::PAGE_FRAME:
283cdf0e10cSrcweir rRect.Left() = aFrameAtFrame.Left();
284cdf0e10cSrcweir rRect.Right() = aFrameAtFrame.Right();
285cdf0e10cSrcweir break;
286cdf0e10cSrcweir
287cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
288cdf0e10cSrcweir case RelOrientation::PAGE_PRINT_AREA:
289cdf0e10cSrcweir rRect.Left() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
290cdf0e10cSrcweir rRect.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
291cdf0e10cSrcweir break;
292cdf0e10cSrcweir
293cdf0e10cSrcweir case RelOrientation::PAGE_RIGHT:
294cdf0e10cSrcweir rRect.Left() = aFrameAtFrame.Left();
295cdf0e10cSrcweir rRect.Right() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
296cdf0e10cSrcweir break;
297cdf0e10cSrcweir
298cdf0e10cSrcweir case RelOrientation::PAGE_LEFT:
299cdf0e10cSrcweir rRect.Left() = aFrameAtFrame.Right();
300cdf0e10cSrcweir rRect.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
301cdf0e10cSrcweir break;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir switch (nVRel)
305cdf0e10cSrcweir {
306cdf0e10cSrcweir case RelOrientation::FRAME:
307cdf0e10cSrcweir case RelOrientation::PAGE_FRAME:
308cdf0e10cSrcweir rRect.Top() = aFrameAtFrame.Top();
309cdf0e10cSrcweir rRect.Bottom() = aFrameAtFrame.Bottom();
310cdf0e10cSrcweir break;
311cdf0e10cSrcweir
312cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
313cdf0e10cSrcweir case RelOrientation::PAGE_PRINT_AREA:
314cdf0e10cSrcweir rRect.Top() = aFrameAtFrame.Top() + FLYINFLY_BORDER;
315cdf0e10cSrcweir rRect.Bottom() = aFrameAtFrame.Bottom() - FLYINFLY_BORDER;
316cdf0e10cSrcweir break;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir }
319cdf0e10cSrcweir break;
320cdf0e10cSrcweir case TextContentAnchorType_AT_PARAGRAPH:
321cdf0e10cSrcweir case TextContentAnchorType_AT_CHARACTER:
322cdf0e10cSrcweir {
323cdf0e10cSrcweir switch (nHRel)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir case RelOrientation::FRAME:
326cdf0e10cSrcweir rRect.Left() = aPara.Left();
327cdf0e10cSrcweir rRect.Right() = aPara.Right();
328cdf0e10cSrcweir break;
329cdf0e10cSrcweir
330cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
331cdf0e10cSrcweir rRect.Left() = aParaPrtArea.Left();
332cdf0e10cSrcweir rRect.Right() = aParaPrtArea.Right();
333cdf0e10cSrcweir break;
334cdf0e10cSrcweir
335cdf0e10cSrcweir case RelOrientation::PAGE_LEFT:
336cdf0e10cSrcweir rRect.Left() = aPage.Left();
337cdf0e10cSrcweir rRect.Right() = aPagePrtArea.Left();
338cdf0e10cSrcweir break;
339cdf0e10cSrcweir
340cdf0e10cSrcweir case RelOrientation::PAGE_RIGHT:
341cdf0e10cSrcweir rRect.Left() = aPagePrtArea.Right();
342cdf0e10cSrcweir rRect.Right() = aPage.Right();
343cdf0e10cSrcweir break;
344cdf0e10cSrcweir
345cdf0e10cSrcweir case RelOrientation::PAGE_FRAME:
346cdf0e10cSrcweir rRect.Left() = aPage.Left();
347cdf0e10cSrcweir rRect.Right() = aPage.Right();
348cdf0e10cSrcweir break;
349cdf0e10cSrcweir
350cdf0e10cSrcweir case RelOrientation::PAGE_PRINT_AREA:
351cdf0e10cSrcweir rRect.Left() = aPagePrtArea.Left();
352cdf0e10cSrcweir rRect.Right() = aPagePrtArea.Right();
353cdf0e10cSrcweir break;
354cdf0e10cSrcweir
355cdf0e10cSrcweir case RelOrientation::FRAME_LEFT:
356cdf0e10cSrcweir rRect.Left() = aPara.Left();
357cdf0e10cSrcweir rRect.Right() = aParaPrtArea.Left();
358cdf0e10cSrcweir break;
359cdf0e10cSrcweir
360cdf0e10cSrcweir case RelOrientation::FRAME_RIGHT:
361cdf0e10cSrcweir rRect.Left() = aParaPrtArea.Right();
362cdf0e10cSrcweir rRect.Right() = aPara.Right();
363cdf0e10cSrcweir break;
364cdf0e10cSrcweir
365cdf0e10cSrcweir case RelOrientation::CHAR:
366cdf0e10cSrcweir rRect.Left() = aAutoCharFrame.Left();
367cdf0e10cSrcweir rRect.Right() = aAutoCharFrame.Left();
368cdf0e10cSrcweir break;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir
371cdf0e10cSrcweir switch (nVRel)
372cdf0e10cSrcweir {
373cdf0e10cSrcweir case RelOrientation::FRAME:
374cdf0e10cSrcweir rRect.Top() = aPara.Top();
375cdf0e10cSrcweir rRect.Bottom() = aPara.Bottom();
376cdf0e10cSrcweir break;
377cdf0e10cSrcweir
378cdf0e10cSrcweir case RelOrientation::PRINT_AREA:
379cdf0e10cSrcweir rRect.Top() = aParaPrtArea.Top();
380cdf0e10cSrcweir rRect.Bottom() = aParaPrtArea.Bottom();
381cdf0e10cSrcweir break;
382cdf0e10cSrcweir
383cdf0e10cSrcweir case RelOrientation::CHAR:
384cdf0e10cSrcweir if (nVAlign != VertOrientation::NONE &&
385cdf0e10cSrcweir nVAlign != VertOrientation::CHAR_BOTTOM)
386cdf0e10cSrcweir rRect.Top() = aAutoCharFrame.Top();
387cdf0e10cSrcweir else
388cdf0e10cSrcweir rRect.Top() = aAutoCharFrame.Bottom();
389cdf0e10cSrcweir rRect.Bottom() = aAutoCharFrame.Bottom();
390cdf0e10cSrcweir break;
391cdf0e10cSrcweir // OD 12.11.2003 #i22341#
392cdf0e10cSrcweir case RelOrientation::TEXT_LINE:
393cdf0e10cSrcweir rRect.Top() = aAutoCharFrame.Top();
394cdf0e10cSrcweir rRect.Bottom() = aAutoCharFrame.Top();
395cdf0e10cSrcweir break;
396cdf0e10cSrcweir }
397cdf0e10cSrcweir }
398cdf0e10cSrcweir break;
399cdf0e10cSrcweir
400cdf0e10cSrcweir case TextContentAnchorType_AS_CHARACTER:
401cdf0e10cSrcweir rRect.Left() = aParaPrtArea.Left();
402cdf0e10cSrcweir rRect.Right() = aParaPrtArea.Right();
403cdf0e10cSrcweir
404cdf0e10cSrcweir switch (nVAlign)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir case VertOrientation::NONE:
407cdf0e10cSrcweir case VertOrientation::TOP:
408cdf0e10cSrcweir case VertOrientation::CENTER:
409cdf0e10cSrcweir case VertOrientation::BOTTOM:
410cdf0e10cSrcweir {
411cdf0e10cSrcweir FontMetric aMetric(GetFontMetric());
412cdf0e10cSrcweir
413cdf0e10cSrcweir rRect.Top() = aParaPrtArea.Bottom() - aMetric.GetDescent();
414cdf0e10cSrcweir rRect.Bottom() = rRect.Top();
415cdf0e10cSrcweir }
416cdf0e10cSrcweir break;
417cdf0e10cSrcweir
418cdf0e10cSrcweir default:
419cdf0e10cSrcweir
420cdf0e10cSrcweir case VertOrientation::LINE_TOP:
421cdf0e10cSrcweir case VertOrientation::LINE_CENTER:
422cdf0e10cSrcweir case VertOrientation::LINE_BOTTOM:
423cdf0e10cSrcweir rRect.Top() = aParaPrtArea.Top();
424cdf0e10cSrcweir rRect.Bottom() = aDrawObj.Bottom();
425cdf0e10cSrcweir break;
426cdf0e10cSrcweir
427cdf0e10cSrcweir case VertOrientation::CHAR_TOP:
428cdf0e10cSrcweir case VertOrientation::CHAR_CENTER:
429cdf0e10cSrcweir case VertOrientation::CHAR_BOTTOM:
430cdf0e10cSrcweir rRect.Top() = aParaPrtArea.Top();
431cdf0e10cSrcweir rRect.Bottom() = aParaPrtArea.Bottom();
432cdf0e10cSrcweir break;
433cdf0e10cSrcweir }
434cdf0e10cSrcweir break;
435cdf0e10cSrcweir
436cdf0e10cSrcweir default:
437cdf0e10cSrcweir break;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir }
440cdf0e10cSrcweir
DrawInnerFrame_Impl(const Rectangle & rRect,const Color & rFillColor,const Color & rBorderColor)441cdf0e10cSrcweir Rectangle SvxSwFrameExample::DrawInnerFrame_Impl(const Rectangle &rRect, const Color &rFillColor, const Color &rBorderColor)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir DrawRect_Impl(rRect, rFillColor, rBorderColor);
444cdf0e10cSrcweir
445cdf0e10cSrcweir // Bereich, zu dem relativ positioniert wird, bestimmen
446cdf0e10cSrcweir Rectangle aRect(rRect); // aPagePrtArea = Default
447cdf0e10cSrcweir CalcBoundRect_Impl(aRect);
448cdf0e10cSrcweir
449cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AT_FRAME && &rRect == &aPagePrtArea)
450cdf0e10cSrcweir {
451*c9a68a5cSmseidel // draw test paragraph
452cdf0e10cSrcweir Rectangle aTxt(aTextLine);
453cdf0e10cSrcweir sal_Int32 nStep = aTxt.GetHeight() + 2;
454cdf0e10cSrcweir sal_uInt16 nLines = (sal_uInt16)(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
455cdf0e10cSrcweir
456cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nLines; i++)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir if (i == nLines - 1)
459cdf0e10cSrcweir aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
460cdf0e10cSrcweir DrawRect_Impl(aTxt, m_aTxtCol, m_aTransColor);
461cdf0e10cSrcweir aTxt.Move(0, nStep);
462cdf0e10cSrcweir }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir return aRect;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir
Paint(const Rectangle &)468cdf0e10cSrcweir void SvxSwFrameExample::Paint(const Rectangle&)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir InitAllRects_Impl();
471cdf0e10cSrcweir
472*c9a68a5cSmseidel // draw shadow
473cdf0e10cSrcweir // Rectangle aShadow(aPage);
474cdf0e10cSrcweir // aShadow += Point(3, 3);
475cdf0e10cSrcweir // DrawRect_Impl(aShadow, Color(COL_GRAY), aTransColor);
476cdf0e10cSrcweir
477*c9a68a5cSmseidel // draw page
478cdf0e10cSrcweir DrawRect_Impl( aPage, m_aBgCol, m_aBorderCol );
479cdf0e10cSrcweir
480*c9a68a5cSmseidel // draw PrintArea
481cdf0e10cSrcweir Rectangle aRect = DrawInnerFrame_Impl( aPagePrtArea, m_aTransColor, m_aPrintAreaCol );
482cdf0e10cSrcweir
483cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AT_FRAME)
484cdf0e10cSrcweir aRect = DrawInnerFrame_Impl( aFrameAtFrame, m_aBgCol, m_aBorderCol );
485cdf0e10cSrcweir
486cdf0e10cSrcweir long lXPos = 0;
487cdf0e10cSrcweir long lYPos = 0;
488cdf0e10cSrcweir
489cdf0e10cSrcweir // Horizontale Ausrichtung
490cdf0e10cSrcweir //
491cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AS_CHARACTER)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir switch (nHAlign)
494cdf0e10cSrcweir {
495cdf0e10cSrcweir case HoriOrientation::RIGHT:
496cdf0e10cSrcweir {
497cdf0e10cSrcweir lXPos = aRect.Right() - aFrmSize.Width() + 1;
498cdf0e10cSrcweir break;
499cdf0e10cSrcweir }
500cdf0e10cSrcweir case HoriOrientation::CENTER:
501cdf0e10cSrcweir {
502cdf0e10cSrcweir lXPos = aRect.Left() + (aRect.GetWidth() - aFrmSize.Width()) / 2;
503cdf0e10cSrcweir break;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir case HoriOrientation::NONE:
506cdf0e10cSrcweir {
507cdf0e10cSrcweir lXPos = aRect.Left() + aRelPos.X();
508cdf0e10cSrcweir break;
509cdf0e10cSrcweir }
510cdf0e10cSrcweir
511cdf0e10cSrcweir default: // HoriOrientation::LEFT
512cdf0e10cSrcweir lXPos = aRect.Left();
513cdf0e10cSrcweir break;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir }
516cdf0e10cSrcweir else
517cdf0e10cSrcweir lXPos = aRect.Right() + 2;
518cdf0e10cSrcweir
519cdf0e10cSrcweir // Vertikale Ausrichtung
520cdf0e10cSrcweir //
521cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AS_CHARACTER)
522cdf0e10cSrcweir {
523cdf0e10cSrcweir switch (nVAlign)
524cdf0e10cSrcweir {
525cdf0e10cSrcweir case VertOrientation::BOTTOM:
526cdf0e10cSrcweir case VertOrientation::LINE_BOTTOM:
527cdf0e10cSrcweir {
528cdf0e10cSrcweir // OD 12.11.2003 #i22341#
529cdf0e10cSrcweir if ( nVRel != RelOrientation::TEXT_LINE )
530cdf0e10cSrcweir {
531cdf0e10cSrcweir lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
532cdf0e10cSrcweir }
533cdf0e10cSrcweir else
534cdf0e10cSrcweir {
535cdf0e10cSrcweir lYPos = aRect.Top();
536cdf0e10cSrcweir }
537cdf0e10cSrcweir break;
538cdf0e10cSrcweir }
539cdf0e10cSrcweir case VertOrientation::CENTER:
540cdf0e10cSrcweir case VertOrientation::LINE_CENTER:
541cdf0e10cSrcweir {
542cdf0e10cSrcweir lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
543cdf0e10cSrcweir break;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir case VertOrientation::NONE:
546cdf0e10cSrcweir {
547cdf0e10cSrcweir // OD 12.11.2003 #i22341#
548cdf0e10cSrcweir if ( nVRel != RelOrientation::CHAR && nVRel != RelOrientation::TEXT_LINE )
549cdf0e10cSrcweir lYPos = aRect.Top() + aRelPos.Y();
550cdf0e10cSrcweir else
551cdf0e10cSrcweir lYPos = aRect.Top() - aRelPos.Y();
552cdf0e10cSrcweir break;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir default:
555cdf0e10cSrcweir // OD 12.11.2003 #i22341#
556cdf0e10cSrcweir if ( nVRel != RelOrientation::TEXT_LINE )
557cdf0e10cSrcweir {
558cdf0e10cSrcweir lYPos = aRect.Top();
559cdf0e10cSrcweir }
560cdf0e10cSrcweir else
561cdf0e10cSrcweir {
562cdf0e10cSrcweir lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
563cdf0e10cSrcweir }
564cdf0e10cSrcweir break;
565cdf0e10cSrcweir }
566cdf0e10cSrcweir }
567cdf0e10cSrcweir else
568cdf0e10cSrcweir {
569cdf0e10cSrcweir switch(nVAlign)
570cdf0e10cSrcweir {
571cdf0e10cSrcweir case VertOrientation::CENTER:
572cdf0e10cSrcweir case VertOrientation::CHAR_CENTER:
573cdf0e10cSrcweir case VertOrientation::LINE_CENTER:
574cdf0e10cSrcweir lYPos = aRect.Top() + (aRect.GetHeight() - aFrmSize.Height()) / 2;
575cdf0e10cSrcweir break;
576cdf0e10cSrcweir
577cdf0e10cSrcweir case VertOrientation::TOP:
578cdf0e10cSrcweir case VertOrientation::CHAR_BOTTOM:
579cdf0e10cSrcweir case VertOrientation::LINE_BOTTOM:
580cdf0e10cSrcweir lYPos = aRect.Bottom() - aFrmSize.Height() + 1;
581cdf0e10cSrcweir break;
582cdf0e10cSrcweir
583cdf0e10cSrcweir /* case VertOrientation::NONE:
584cdf0e10cSrcweir case VertOrientation::BOTTOM:
585cdf0e10cSrcweir case VertOrientation::CHAR_TOP:
586cdf0e10cSrcweir case VertOrientation::LINE_TOP:*/
587cdf0e10cSrcweir default:
588cdf0e10cSrcweir lYPos = aRect.Top() - aRelPos.Y();
589cdf0e10cSrcweir break;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir }
592cdf0e10cSrcweir
593cdf0e10cSrcweir Rectangle aFrmRect(Point(lXPos, lYPos), aFrmSize);
594cdf0e10cSrcweir
595cdf0e10cSrcweir Rectangle *pOuterFrame = &aPage;
596cdf0e10cSrcweir
597cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AT_FRAME)
598cdf0e10cSrcweir pOuterFrame = &aFrameAtFrame;
599cdf0e10cSrcweir
600cdf0e10cSrcweir if (aFrmRect.Left() < pOuterFrame->Left())
601cdf0e10cSrcweir aFrmRect.Move(pOuterFrame->Left() - aFrmRect.Left(), 0);
602cdf0e10cSrcweir if (aFrmRect.Right() > pOuterFrame->Right())
603cdf0e10cSrcweir aFrmRect.Move(pOuterFrame->Right() - aFrmRect.Right(), 0);
604cdf0e10cSrcweir
605cdf0e10cSrcweir if (aFrmRect.Top() < pOuterFrame->Top())
606cdf0e10cSrcweir aFrmRect.Move(0, pOuterFrame->Top() - aFrmRect.Top());
607cdf0e10cSrcweir if (aFrmRect.Bottom() > pOuterFrame->Bottom())
608cdf0e10cSrcweir aFrmRect.Move(0, pOuterFrame->Bottom() - aFrmRect.Bottom());
609cdf0e10cSrcweir
610*c9a68a5cSmseidel // draw test paragraph
611cdf0e10cSrcweir const long nTxtLineHeight = aTextLine.GetHeight();
612cdf0e10cSrcweir Rectangle aTxt(aTextLine);
613cdf0e10cSrcweir sal_Int32 nStep;
614cdf0e10cSrcweir sal_uInt16 nLines;
615cdf0e10cSrcweir
616cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AT_FRAME)
617cdf0e10cSrcweir {
618cdf0e10cSrcweir aTxt.Left() = aFrameAtFrame.Left() + FLYINFLY_BORDER;
619cdf0e10cSrcweir aTxt.Right() = aFrameAtFrame.Right() - FLYINFLY_BORDER;
620cdf0e10cSrcweir aTxt.Top() = aFrameAtFrame.Top() + FLYINFLY_BORDER;
621cdf0e10cSrcweir aTxt.Bottom() = aTxt.Top() + aTextLine.GetHeight() - 1;
622cdf0e10cSrcweir
623cdf0e10cSrcweir nStep = aTxt.GetHeight() + 2;
624cdf0e10cSrcweir nLines = (sal_uInt16)(((aFrameAtFrame.GetHeight() - 2 * FLYINFLY_BORDER) * 2 / 3)
625cdf0e10cSrcweir / (aTxt.GetHeight() + 2));
626cdf0e10cSrcweir }
627cdf0e10cSrcweir else
628cdf0e10cSrcweir {
629cdf0e10cSrcweir nStep = aTxt.GetHeight() + 2;
630cdf0e10cSrcweir nLines = (sal_uInt16)(aParaPrtArea.GetHeight() / (aTextLine.GetHeight() + 2));
631cdf0e10cSrcweir }
632cdf0e10cSrcweir
633cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AS_CHARACTER)
634cdf0e10cSrcweir {
635cdf0e10cSrcweir // Text simulieren
636cdf0e10cSrcweir //
637cdf0e10cSrcweir const long nOldR = aTxt.Right();
638cdf0e10cSrcweir const long nOldL = aTxt.Left();
639cdf0e10cSrcweir
640cdf0e10cSrcweir // OD 12.11.2003 #i22341#
641cdf0e10cSrcweir const bool bIgnoreWrap = nAnchor == TextContentAnchorType_AT_CHARACTER &&
642cdf0e10cSrcweir ( nHRel == RelOrientation::CHAR || nVRel == RelOrientation::CHAR ||
643cdf0e10cSrcweir nVRel == RelOrientation::TEXT_LINE );
644cdf0e10cSrcweir
645cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nLines; ++i)
646cdf0e10cSrcweir {
647cdf0e10cSrcweir if (i == (nLines - 1))
648cdf0e10cSrcweir aTxt.SetSize(Size(aTxt.GetWidth() / 2, aTxt.GetHeight()));
649cdf0e10cSrcweir
650cdf0e10cSrcweir if (aTxt.IsOver(aFrmRect) && nAnchor != TextContentAnchorType_AS_CHARACTER && !bIgnoreWrap)
651cdf0e10cSrcweir {
652cdf0e10cSrcweir switch(nWrap)
653cdf0e10cSrcweir {
654cdf0e10cSrcweir case WrapTextMode_NONE:
655cdf0e10cSrcweir aTxt.Top() = aFrmRect.Bottom() + nTxtLineHeight;
656cdf0e10cSrcweir aTxt.Bottom() = aTxt.Top() + nTxtLineHeight - 1;
657cdf0e10cSrcweir break;
658cdf0e10cSrcweir
659cdf0e10cSrcweir case WrapTextMode_LEFT:
660cdf0e10cSrcweir aTxt.Right() = aFrmRect.Left();
661cdf0e10cSrcweir break;
662cdf0e10cSrcweir
663cdf0e10cSrcweir case WrapTextMode_RIGHT:
664cdf0e10cSrcweir aTxt.Left() = aFrmRect.Right();
665cdf0e10cSrcweir break;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir }
668cdf0e10cSrcweir if (pOuterFrame->IsInside(aTxt))
669cdf0e10cSrcweir DrawRect_Impl( aTxt, m_aTxtCol, m_aTransColor );
670cdf0e10cSrcweir
671cdf0e10cSrcweir aTxt.Move(0, nStep);
672cdf0e10cSrcweir aTxt.Right() = nOldR;
673cdf0e10cSrcweir aTxt.Left() = nOldL;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir aTxt.Move(0, -nStep);
676cdf0e10cSrcweir
677cdf0e10cSrcweir if (nAnchor != TextContentAnchorType_AT_FRAME && aTxt.Bottom() > aParaPrtArea.Bottom())
678cdf0e10cSrcweir {
679*c9a68a5cSmseidel // Text wurde durch Rahmen verdrängt, daher Para-Höhe anpassen
680cdf0e10cSrcweir sal_uIntPtr nDiff = aTxt.Bottom() - aParaPrtArea.Bottom();
681cdf0e10cSrcweir aParaPrtArea.Bottom() += nDiff;
682cdf0e10cSrcweir aPara.Bottom() += nDiff;
683cdf0e10cSrcweir
684cdf0e10cSrcweir CalcBoundRect_Impl(aRect);
685cdf0e10cSrcweir
686cdf0e10cSrcweir aParaPrtArea.Bottom() -= nDiff;
687cdf0e10cSrcweir aPara.Bottom() -= nDiff;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir if (nAnchor == TextContentAnchorType_AT_CHARACTER && bIgnoreWrap)
690cdf0e10cSrcweir DrawText(aAutoCharFrame, 'A');
691cdf0e10cSrcweir }
692cdf0e10cSrcweir else
693cdf0e10cSrcweir {
694cdf0e10cSrcweir DrawText(aParaPrtArea, C2S(DEMOTEXT));
695cdf0e10cSrcweir DrawRect_Impl(aDrawObj, m_aBlankCol, m_aBlankFrameCol );
696cdf0e10cSrcweir }
697cdf0e10cSrcweir
698cdf0e10cSrcweir // Rechteck zeichnen, zu dem der Rahmen ausgerichtet wird:
699cdf0e10cSrcweir DrawRect_Impl(aRect, m_aTransColor, m_aAlignColor);
700cdf0e10cSrcweir
701cdf0e10cSrcweir // Frame anzeigen
702cdf0e10cSrcweir sal_Bool bDontFill = (nAnchor == TextContentAnchorType_AT_CHARACTER && aFrmRect.IsOver(aAutoCharFrame)) ? sal_True : bTrans;
703cdf0e10cSrcweir DrawRect_Impl( aFrmRect, bDontFill? m_aTransColor : m_aBgCol, m_aFrameColor );
704cdf0e10cSrcweir }
705cdf0e10cSrcweir
SetRelPos(const Point & rP)706cdf0e10cSrcweir void SvxSwFrameExample::SetRelPos(const Point& rP)
707cdf0e10cSrcweir {
708cdf0e10cSrcweir aRelPos = rP;
709cdf0e10cSrcweir
710cdf0e10cSrcweir if (aRelPos.X() > 0)
711cdf0e10cSrcweir aRelPos.X() = 5;
712cdf0e10cSrcweir if (aRelPos.X() < 0)
713cdf0e10cSrcweir aRelPos.X() = -5;
714cdf0e10cSrcweir
715cdf0e10cSrcweir if (aRelPos.Y() > 0)
716cdf0e10cSrcweir aRelPos.Y() = 5;
717cdf0e10cSrcweir if (aRelPos.Y() < 0)
718cdf0e10cSrcweir aRelPos.Y() = -5;
719cdf0e10cSrcweir }
720cdf0e10cSrcweir
DrawRect_Impl(const Rectangle & rRect,const Color & rFillColor,const Color & rLineColor)721cdf0e10cSrcweir void SvxSwFrameExample::DrawRect_Impl(const Rectangle &rRect, const Color &rFillColor, const Color &rLineColor)
722cdf0e10cSrcweir {
723cdf0e10cSrcweir SetFillColor(rFillColor);
724cdf0e10cSrcweir SetLineColor(rLineColor);
725cdf0e10cSrcweir Window::DrawRect(rRect);
726cdf0e10cSrcweir }
727*c9a68a5cSmseidel
728*c9a68a5cSmseidel /* vim: set noet sw=4 ts=4: */
729