Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "cmdid.h"
30 : : #include "hintids.hxx"
31 : : #include <algorithm>
32 : :
33 : :
34 : : #include <svl/eitem.hxx>
35 : : #include <editeng/lrspitem.hxx>
36 : : #include <editeng/ulspitem.hxx>
37 : : #include <editeng/sizeitem.hxx>
38 : : #include <svx/pageitem.hxx>
39 : : #include <editeng/brshitem.hxx>
40 : : #include <editeng/frmdiritem.hxx>
41 : : #include <vcl/bitmap.hxx>
42 : : #include <vcl/graph.hxx>
43 : : #include <tgrditem.hxx>
44 : : #include <viewopt.hxx>
45 : : #include "colex.hxx"
46 : : #include "colmgr.hxx"
47 : :
48 : : /*-----------------------------------------------------------------------
49 : : Description: Taking the updated values from the set
50 : : -----------------------------------------------------------------------*/
51 : 0 : void SwPageExample::UpdateExample( const SfxItemSet& rSet )
52 : : {
53 : 0 : const SvxPageItem* pPage = 0;
54 : 0 : SfxItemPool* pPool = rSet.GetPool();
55 [ # # ]: 0 : sal_uInt16 nWhich = pPool->GetWhich( SID_ATTR_PAGE );
56 : :
57 [ # # ][ # # ]: 0 : if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
58 : : {
59 : : // alignment
60 [ # # ]: 0 : pPage = (const SvxPageItem*)&rSet.Get( nWhich );
61 : :
62 [ # # ]: 0 : if ( pPage )
63 : 0 : SetUsage( pPage->GetPageUsage() );
64 : : }
65 : :
66 [ # # ]: 0 : nWhich = pPool->GetWhich( SID_ATTR_PAGE_SIZE );
67 : :
68 [ # # ][ # # ]: 0 : if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
69 : : {
70 : : // orientation and size from PageItem
71 [ # # ]: 0 : const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( nWhich );
72 : 0 : SetSize( rSize.GetSize() );
73 : : }
74 : 0 : nWhich = RES_LR_SPACE;
75 [ # # ][ # # ]: 0 : if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
76 : : {
77 : : // set left and right border
78 [ # # ]: 0 : const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get( nWhich );
79 : :
80 : 0 : SetLeft( rLRSpace.GetLeft() );
81 : 0 : SetRight( rLRSpace.GetRight() );
82 : : }
83 : : else
84 : : {
85 : 0 : SetLeft( 0 );
86 : 0 : SetRight( 0 );
87 : : }
88 : :
89 : 0 : nWhich = RES_UL_SPACE;
90 : :
91 [ # # ][ # # ]: 0 : if ( rSet.GetItemState( nWhich, sal_False ) == SFX_ITEM_SET )
92 : : {
93 : : // set upper and lower border
94 [ # # ]: 0 : const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)rSet.Get( nWhich );
95 : :
96 : 0 : SetTop( rULSpace.GetUpper() );
97 : 0 : SetBottom( rULSpace.GetLower() );
98 : : }
99 : : else
100 : : {
101 : 0 : SetTop( 0 );
102 : 0 : SetBottom( 0 );
103 : : }
104 : :
105 : :
106 : : // evaluate header-attributes
107 : : const SfxPoolItem* pItem;
108 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_HEADERSET),
109 [ # # ]: 0 : sal_False, &pItem ) )
110 : : {
111 : 0 : const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
112 : : const SfxBoolItem& rHeaderOn =
113 [ # # ][ # # ]: 0 : (const SfxBoolItem&)rHeaderSet.Get( pPool->GetWhich( SID_ATTR_PAGE_ON ) );
114 : :
115 [ # # ]: 0 : if ( rHeaderOn.GetValue() )
116 : : {
117 : : const SvxSizeItem& rSize =
118 [ # # ][ # # ]: 0 : (const SvxSizeItem&)rHeaderSet.Get(pPool->GetWhich(SID_ATTR_PAGE_SIZE));
119 : :
120 : : const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rHeaderSet.Get(
121 [ # # ][ # # ]: 0 : pPool->GetWhich(SID_ATTR_ULSPACE));
122 : : const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rHeaderSet.Get(
123 [ # # ][ # # ]: 0 : pPool->GetWhich(SID_ATTR_LRSPACE));
124 : :
125 : 0 : SetHdHeight( rSize.GetSize().Height() - rUL.GetLower());
126 : 0 : SetHdDist( rUL.GetLower() );
127 : 0 : SetHdLeft( rLR.GetLeft() );
128 : 0 : SetHdRight( rLR.GetRight() );
129 : 0 : SetHeader( sal_True );
130 [ # # ][ # # ]: 0 : if ( rHeaderSet.GetItemState( RES_BACKGROUND ) == SFX_ITEM_SET )
131 : : {
132 : : const SvxBrushItem& rItem =
133 [ # # ]: 0 : (const SvxBrushItem&)rHeaderSet.Get( RES_BACKGROUND );
134 : 0 : SetHdColor( rItem.GetColor() );
135 : : }
136 [ # # ][ # # ]: 0 : if ( rHeaderSet.GetItemState( RES_BOX ) == SFX_ITEM_SET )
137 : : {
138 : : const SvxBoxItem& rItem =
139 [ # # ]: 0 : (const SvxBoxItem&)rHeaderSet.Get( RES_BOX );
140 [ # # ]: 0 : SetHdBorder( rItem );
141 : : }
142 : : }
143 : : else
144 : 0 : SetHeader( sal_False );
145 : : }
146 : :
147 [ # # ][ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_FOOTERSET),
148 [ # # ]: 0 : sal_False, &pItem ) )
149 : : {
150 : 0 : const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
151 : : const SfxBoolItem& rFooterOn =
152 [ # # ]: 0 : (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
153 : :
154 [ # # ]: 0 : if ( rFooterOn.GetValue() )
155 : : {
156 : : const SvxSizeItem& rSize =
157 [ # # ][ # # ]: 0 : (const SvxSizeItem&)rFooterSet.Get( pPool->GetWhich( SID_ATTR_PAGE_SIZE ) );
158 : :
159 : : const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rFooterSet.Get(
160 [ # # ][ # # ]: 0 : pPool->GetWhich( SID_ATTR_ULSPACE ) );
161 : : const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rFooterSet.Get(
162 [ # # ][ # # ]: 0 : pPool->GetWhich( SID_ATTR_LRSPACE ) );
163 : :
164 : 0 : SetFtHeight( rSize.GetSize().Height() - rUL.GetUpper());
165 : 0 : SetFtDist( rUL.GetUpper() );
166 : 0 : SetFtLeft( rLR.GetLeft() );
167 : 0 : SetFtRight( rLR.GetRight() );
168 : 0 : SetFooter( sal_True );
169 [ # # ][ # # ]: 0 : if( rFooterSet.GetItemState( RES_BACKGROUND ) == SFX_ITEM_SET )
170 : : {
171 : : const SvxBrushItem& rItem =
172 [ # # ]: 0 : (const SvxBrushItem&)rFooterSet.Get( RES_BACKGROUND );
173 : 0 : SetFtColor( rItem.GetColor() );
174 : : }
175 [ # # ][ # # ]: 0 : if( rFooterSet.GetItemState( RES_BOX ) == SFX_ITEM_SET )
176 : : {
177 : : const SvxBoxItem& rItem =
178 [ # # ]: 0 : (const SvxBoxItem&)rFooterSet.Get( RES_BOX );
179 [ # # ]: 0 : SetFtBorder( rItem );
180 : : }
181 : : }
182 : : else
183 : 0 : SetFooter( sal_False );
184 : : }
185 [ # # ]: 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND,
186 [ # # ]: 0 : sal_False, &pItem ) )
187 : : {
188 : 0 : SetColor( ( (const SvxBrushItem*)pItem )->GetColor() );
189 [ # # ]: 0 : const Graphic* pGrf = ( (const SvxBrushItem*)pItem )->GetGraphic();
190 : :
191 [ # # ]: 0 : if ( pGrf )
192 : : {
193 [ # # ]: 0 : Bitmap aBitmap = pGrf->GetBitmap();
194 [ # # ][ # # ]: 0 : SetBitmap( &aBitmap );
195 : : }
196 : : else
197 [ # # ]: 0 : SetBitmap( NULL );
198 : : }
199 : :
200 [ # # ]: 0 : Invalidate();
201 : 0 : }
202 : :
203 : 0 : void SwColExample::DrawPage( const Point& rOrg,
204 : : const sal_Bool bSecond,
205 : : const sal_Bool bEnabled )
206 : : {
207 : 0 : SwPageExample::DrawPage( rOrg, bSecond, bEnabled );
208 : : sal_uInt16 nColumnCount;
209 [ # # ][ # # ]: 0 : if( pColMgr && 0 != (nColumnCount = pColMgr->GetCount()))
[ # # ]
210 : : {
211 : 0 : long nL = GetLeft();
212 : 0 : long nR = GetRight();
213 : :
214 [ # # ][ # # ]: 0 : if ( GetUsage() == SVX_PAGE_MIRROR && !bSecond )
[ # # ]
215 : : {
216 : : // rotate for mirrored
217 : 0 : nL = GetRight();
218 : 0 : nR = GetLeft();
219 : : }
220 : :
221 [ # # ]: 0 : SetFillColor( Color( COL_LIGHTGRAY ) );
222 [ # # ]: 0 : Rectangle aRect;
223 : 0 : aRect.Right() = rOrg.X() + GetSize().Width() - nR;
224 : 0 : aRect.Left() = rOrg.X() + nL;
225 : 0 : aRect.Top() = rOrg.Y() + GetTop()
226 : 0 : + GetHdHeight() + GetHdDist();
227 : 0 : aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom()
228 : 0 : - GetFtHeight() - GetFtDist();
229 [ # # ]: 0 : DrawRect(aRect);
230 : :
231 [ # # ]: 0 : if(GetColor() == Color(COL_TRANSPARENT))
232 : : {
233 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
234 : 0 : const Color& rFieldColor = rStyleSettings.GetFieldColor();
235 [ # # ]: 0 : SetFillColor( rFieldColor );
236 : : }
237 : : else
238 [ # # ]: 0 : SetFillColor( GetColor() );
239 : :
240 : : // #97495# make sure that the automatic column widht's are always equal
241 : 0 : sal_Bool bAutoWidth = pColMgr->IsAutoWidth();
242 : 0 : sal_Int32 nAutoColWidth = 0;
243 [ # # ]: 0 : if(bAutoWidth)
244 : : {
245 : 0 : sal_Int32 nColumnWidthSum = 0;
246 : : sal_uInt16 i;
247 [ # # ]: 0 : for(i = 0; i < nColumnCount; ++i)
248 [ # # ]: 0 : nColumnWidthSum += pColMgr->GetColWidth( i );
249 : 0 : nAutoColWidth = nColumnWidthSum / nColumnCount;
250 : : }
251 : :
252 : : sal_uInt16 i;
253 [ # # ]: 0 : for( i = 0; i < nColumnCount; i++)
254 : : {
255 [ # # ]: 0 : if(!bAutoWidth)
256 [ # # ]: 0 : nAutoColWidth = pColMgr->GetColWidth( i );
257 : 0 : aRect.Right() = aRect.Left() + nAutoColWidth;
258 [ # # ]: 0 : DrawRect(aRect);
259 [ # # ]: 0 : if(i < nColumnCount - 1)
260 [ # # ]: 0 : aRect.Left() = aRect.Right() + pColMgr->GetGutterWidth(i);
261 : : }
262 [ # # ]: 0 : if(pColMgr->HasLine())
263 : : {
264 : 0 : Point aUp( rOrg.X() + nL, rOrg.Y() + GetTop() );
265 : 0 : Point aDown( rOrg.X() + nL, rOrg.Y() + GetSize().Height()
266 : 0 : - GetBottom() - GetFtHeight() - GetFtDist() );
267 : :
268 [ # # ][ # # ]: 0 : if( pColMgr->GetLineHeightPercent() != 100 )
269 : : {
270 : 0 : long nLength = aDown.Y() - aUp.Y();
271 [ # # ]: 0 : nLength -= nLength * pColMgr->GetLineHeightPercent() / 100;
272 [ # # # # ]: 0 : switch(pColMgr->GetAdjust())
273 : : {
274 : 0 : case COLADJ_BOTTOM: aUp.Y() += nLength; break;
275 : 0 : case COLADJ_TOP: aDown.Y() -= nLength; break;
276 : : case COLADJ_CENTER:
277 : 0 : aUp.Y() += nLength / 2;
278 : 0 : aDown.Y() -= nLength / 2;
279 : 0 : break;
280 : : default:; // prevent warning
281 : : }
282 : : }
283 : :
284 : : int nDist;
285 [ # # ]: 0 : for( i = 0; i < nColumnCount - 1; i++)
286 : : {
287 [ # # ]: 0 : int nGutter = pColMgr->GetGutterWidth(i);
288 [ # # ]: 0 : nDist = pColMgr->GetColWidth( i ) + nGutter;
289 : : nDist -= (i == 0) ?
290 : : nGutter/2 :
291 [ # # ]: 0 : 0;
292 : 0 : aUp.X() += nDist;
293 : 0 : aDown.X() += nDist;
294 [ # # ]: 0 : DrawLine( aUp, aDown );
295 : :
296 : : }
297 : : }
298 : : }
299 : 0 : }
300 : :
301 : 0 : SwColumnOnlyExample::SwColumnOnlyExample( Window* pParent, const ResId& rResId) :
302 : : Window(pParent, rResId),
303 [ # # ]: 0 : m_aFrmSize(1,1)
304 : : {
305 [ # # ][ # # ]: 0 : SetMapMode( MapMode( MAP_TWIP ) );
[ # # ]
306 : 0 : m_aWinSize = GetOutputSizePixel();
307 : 0 : m_aWinSize.Height() -= 4;
308 : 0 : m_aWinSize.Width() -= 4;
309 : :
310 [ # # ]: 0 : m_aWinSize = PixelToLogic( m_aWinSize );
311 : :
312 [ # # ]: 0 : SetBorderStyle( WINDOW_BORDER_MONO );
313 : :
314 [ # # ]: 0 : m_aFrmSize = SvxPaperInfo::GetPaperSize(PAPER_A4);// DIN A4
315 [ # # ]: 0 : ::FitToActualSize(m_aCols, (sal_uInt16)m_aFrmSize.Width());
316 : :
317 : 0 : long nHeight = m_aFrmSize.Height();
318 [ # # ]: 0 : Fraction aScale( m_aWinSize.Height(), nHeight );
319 [ # # ]: 0 : MapMode aMapMode( GetMapMode() );
320 [ # # ]: 0 : aMapMode.SetScaleX( aScale );
321 [ # # ]: 0 : aMapMode.SetScaleY( aScale );
322 [ # # ][ # # ]: 0 : SetMapMode( aMapMode );
323 : 0 : }
324 : :
325 : 0 : void SwColumnOnlyExample::Paint( const Rectangle& /*rRect*/ )
326 : : {
327 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
328 : 0 : const Color& rFieldColor = rStyleSettings.GetFieldColor();
329 : 0 : const Color& rDlgColor = rStyleSettings.GetDialogColor();
330 [ # # ]: 0 : const Color& rFieldTextColor = SwViewOption::GetFontColor();
331 : 0 : Color aGrayColor(COL_LIGHTGRAY);
332 [ # # ]: 0 : if(rFieldColor == aGrayColor)
333 [ # # ]: 0 : aGrayColor.Invert();
334 : :
335 [ # # ]: 0 : Size aLogSize(PixelToLogic(GetOutputSizePixel()));
336 [ # # ]: 0 : Rectangle aCompleteRect(Point(0,0), aLogSize);
337 [ # # ]: 0 : SetLineColor(rDlgColor);
338 [ # # ]: 0 : SetFillColor(rDlgColor);
339 [ # # ]: 0 : DrawRect(aCompleteRect);
340 : :
341 [ # # ]: 0 : SetLineColor( rFieldTextColor );
342 : 0 : Point aTL( (aLogSize.Width() - m_aFrmSize.Width()) / 2,
343 : 0 : (aLogSize.Height() - m_aFrmSize.Height()) / 2);
344 [ # # ]: 0 : Rectangle aRect(aTL, m_aFrmSize);
345 : :
346 : : //draw a shadow rectangle
347 [ # # ]: 0 : SetFillColor( Color(COL_GRAY) );
348 : 0 : Rectangle aShadowRect(aRect);
349 [ # # ]: 0 : aShadowRect.Move(aTL.Y(), aTL.Y());
350 [ # # ]: 0 : DrawRect(aShadowRect);
351 : :
352 [ # # ]: 0 : SetFillColor( rFieldColor );
353 [ # # ]: 0 : DrawRect(aRect);
354 : :
355 [ # # ]: 0 : SetFillColor( aGrayColor );
356 : :
357 : : //column seperator?
358 : 0 : long nLength = aLogSize.Height() - 2 * aTL.Y();
359 : 0 : Point aUp( aTL );
360 : 0 : Point aDown( aTL.X(), nLength );
361 : 0 : sal_Bool bLines = sal_False;
362 [ # # ]: 0 : if(m_aCols.GetLineAdj() != COLADJ_NONE)
363 : : {
364 : 0 : bLines = sal_True;
365 : :
366 : 0 : sal_uInt16 nPercent = m_aCols.GetLineHeight();
367 [ # # ]: 0 : if( nPercent != 100 )
368 : : {
369 : 0 : nLength -= nLength * nPercent / 100;
370 [ # # # # ]: 0 : switch(m_aCols.GetLineAdj())
371 : : {
372 : 0 : case COLADJ_BOTTOM: aUp.Y() += nLength; break;
373 : 0 : case COLADJ_TOP: aDown.Y() -= nLength; break;
374 : : case COLADJ_CENTER:
375 : 0 : aUp.Y() += nLength / 2;
376 : 0 : aDown.Y() -= nLength / 2;
377 : 0 : break;
378 : : default:; //prevent warning
379 : : }
380 : : }
381 : :
382 : : }
383 : 0 : const SwColumns& rCols = m_aCols.GetColumns();
384 : 0 : sal_uInt16 nColCount = rCols.size();
385 [ # # ]: 0 : if( nColCount )
386 : : {
387 [ # # ]: 0 : DrawRect(aRect);
388 [ # # ]: 0 : SetFillColor( rFieldColor );
389 [ # # ]: 0 : Rectangle aFrmRect(aTL, m_aFrmSize);
390 : 0 : long nSum = aTL.X();
391 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nColCount; i++)
392 : : {
393 [ # # ]: 0 : const SwColumn* pCol = &rCols[i];
394 : 0 : aFrmRect.Left() = nSum + pCol->GetLeft();//nSum + pCol->GetLeft() + aTL.X();
395 : 0 : nSum += pCol->GetWishWidth();
396 : 0 : aFrmRect.Right() = nSum - pCol->GetRight();
397 [ # # ]: 0 : DrawRect(aFrmRect);
398 : : }
399 [ # # ]: 0 : if(bLines )
400 : : {
401 : 0 : nSum = aTL.X();
402 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nColCount - 1; i++)
403 : : {
404 [ # # ]: 0 : nSum += rCols[i].GetWishWidth();
405 : 0 : aUp.X() = nSum;
406 : 0 : aDown.X() = nSum;
407 [ # # ]: 0 : DrawLine(aUp, aDown);
408 : : }
409 : : }
410 : : }
411 : 0 : }
412 : :
413 : 0 : void SwColumnOnlyExample::SetColumns(const SwFmtCol& rCol)
414 : : {
415 : 0 : m_aCols = rCol;
416 : 0 : sal_uInt16 nWishSum = m_aCols.GetWishWidth();
417 : 0 : long nFrmWidth = m_aFrmSize.Width();
418 : 0 : SwColumns& rCols = m_aCols.GetColumns();
419 : 0 : sal_uInt16 nColCount = rCols.size();
420 : :
421 [ # # ]: 0 : for(sal_uInt16 i = 0; i < nColCount; i++)
422 : : {
423 : 0 : SwColumn* pCol = &rCols[i];
424 : 0 : long nWish = pCol->GetWishWidth();
425 : 0 : nWish *= nFrmWidth;
426 : 0 : nWish /= nWishSum;
427 : 0 : pCol->SetWishWidth((sal_uInt16)nWish);
428 : 0 : long nLeft = pCol->GetLeft();
429 : 0 : nLeft *= nFrmWidth;
430 : 0 : nLeft /= nWishSum;
431 : 0 : pCol->SetLeft((sal_uInt16)nLeft);
432 : 0 : long nRight = pCol->GetRight();
433 : 0 : nRight *= nFrmWidth;
434 : 0 : nRight /= nWishSum;
435 : 0 : pCol->SetRight((sal_uInt16)nRight);
436 : : }
437 : : // #97495# make sure that the automatic column width's are always equal
438 [ # # ][ # # ]: 0 : if(nColCount && m_aCols.IsOrtho())
[ # # ]
439 : : {
440 : 0 : sal_Int32 nColumnWidthSum = 0;
441 : : sal_uInt16 i;
442 [ # # ]: 0 : for(i = 0; i < nColCount; ++i)
443 : : {
444 : 0 : SwColumn* pCol = &rCols[i];
445 : 0 : nColumnWidthSum += pCol->GetWishWidth();
446 : 0 : nColumnWidthSum -= (pCol->GetRight() + pCol->GetLeft());
447 : : }
448 : 0 : nColumnWidthSum /= nColCount;
449 [ # # ]: 0 : for(i = 0; i < nColCount; ++i)
450 : : {
451 : 0 : SwColumn* pCol = &rCols[i];
452 : 0 : pCol->SetWishWidth( static_cast< sal_uInt16 >(nColumnWidthSum + pCol->GetRight() + pCol->GetLeft()));
453 : : }
454 : : }
455 : 0 : }
456 : :
457 : 0 : SwPageGridExample::~SwPageGridExample()
458 : : {
459 [ # # ][ # # ]: 0 : delete pGridItem;
460 [ # # ]: 0 : }
461 : :
462 : 0 : void SwPageGridExample::DrawPage( const Point& rOrg,
463 : : const sal_Bool bSecond,
464 : : const sal_Bool bEnabled )
465 : : {
466 : 0 : SwPageExample::DrawPage(rOrg, bSecond, bEnabled);
467 [ # # ][ # # ]: 0 : if(pGridItem && pGridItem->GetGridType())
[ # # ]
468 : : {
469 : : //paint the grid now
470 : 0 : Color aLineColor = pGridItem->GetColor();
471 [ # # ]: 0 : if(aLineColor.GetColor() == COL_AUTO)
472 : : {
473 : 0 : aLineColor = GetFillColor();
474 [ # # ]: 0 : aLineColor.Invert();
475 : : }
476 [ # # ]: 0 : SetLineColor(aLineColor);
477 : 0 : long nL = GetLeft();
478 : 0 : long nR = GetRight();
479 : :
480 [ # # ][ # # ]: 0 : if ( GetUsage() == SVX_PAGE_MIRROR && !bSecond )
[ # # ]
481 : : {
482 : : // rotate for mirrored
483 : 0 : nL = GetRight();
484 : 0 : nR = GetLeft();
485 : : }
486 : :
487 [ # # ]: 0 : Rectangle aRect;
488 : 0 : aRect.Right() = rOrg.X() + GetSize().Width() - nR;
489 : 0 : aRect.Left() = rOrg.X() + nL;
490 : 0 : aRect.Top() = rOrg.Y() + GetTop()
491 : 0 : + GetHdHeight() + GetHdDist();
492 : 0 : aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom()
493 : 0 : - GetFtHeight() - GetFtDist();
494 : :
495 : : //increase the values to get a 'viewable' preview
496 : 0 : sal_Int32 nBaseHeight = pGridItem->GetBaseHeight() * 3;
497 : 0 : sal_Int32 nRubyHeight = pGridItem->GetRubyHeight() * 3;
498 : :
499 : : //detect height of rectangles
500 : : Rectangle aRubyRect(aRect.TopLeft(),
501 : : m_bVertical ?
502 : : Size(nRubyHeight, aRect.GetHeight()) :
503 [ # # ][ # # ]: 0 : Size(aRect.GetWidth(), nRubyHeight));
[ # # ][ # # ]
504 : : Rectangle aCharRect(aRect.TopLeft(),
505 : : m_bVertical ?
506 : : Size(nBaseHeight, aRect.GetHeight()) :
507 [ # # ][ # # ]: 0 : Size(aRect.GetWidth(), nBaseHeight));
[ # # ][ # # ]
508 : :
509 : 0 : sal_Int32 nLineHeight = nBaseHeight + nRubyHeight;
510 : :
511 : : //detect count of rectangles
512 [ # # ][ # # ]: 0 : sal_Int32 nLines = (m_bVertical ? aRect.GetWidth(): aRect.GetHeight()) / nLineHeight;
[ # # ]
513 [ # # ]: 0 : if(nLines > pGridItem->GetLines())
514 : 0 : nLines = pGridItem->GetLines();
515 : :
516 : : // determine start position
517 [ # # ]: 0 : if(m_bVertical)
518 : : {
519 [ # # ]: 0 : sal_Int16 nXStart = static_cast< sal_Int16 >(aRect.GetWidth() / 2 - nLineHeight * nLines /2);
520 [ # # ]: 0 : aRubyRect.Move(nXStart, 0);
521 [ # # ]: 0 : aCharRect.Move(nXStart, 0);
522 : : }
523 : : else
524 : : {
525 [ # # ]: 0 : sal_Int16 nYStart = static_cast< sal_Int16 >(aRect.GetHeight() / 2 - nLineHeight * nLines /2);
526 [ # # ]: 0 : aRubyRect.Move(0, nYStart);
527 [ # # ]: 0 : aCharRect.Move(0, nYStart);
528 : : }
529 : :
530 [ # # ]: 0 : if(pGridItem->IsRubyTextBelow())
531 [ # # ][ # # ]: 0 : m_bVertical ? aRubyRect.Move(nBaseHeight, 0) : aRubyRect.Move(0, nBaseHeight);
[ # # ]
532 : : else
533 [ # # ][ # # ]: 0 : m_bVertical ? aCharRect.Move(nRubyHeight, 0) : aCharRect.Move(0, nRubyHeight);
[ # # ]
534 : :
535 : : //vertical lines
536 : 0 : sal_Bool bBothLines = pGridItem->GetGridType() == GRID_LINES_CHARS;
537 [ # # ]: 0 : SetFillColor( Color( COL_TRANSPARENT ) );
538 [ # # ]: 0 : sal_Int32 nXMove = m_bVertical ? nLineHeight : 0;
539 [ # # ]: 0 : sal_Int32 nYMove = m_bVertical ? 0 : nLineHeight;
540 [ # # ]: 0 : for(sal_Int32 nLine = 0; nLine < nLines; nLine++)
541 : : {
542 [ # # ]: 0 : DrawRect(aRubyRect);
543 [ # # ]: 0 : DrawRect(aCharRect);
544 [ # # ]: 0 : if(bBothLines)
545 : : {
546 : 0 : Point aStart = aCharRect.TopLeft();
547 [ # # ][ # # ]: 0 : Point aEnd = m_bVertical ? aCharRect.TopRight() : aCharRect.BottomLeft();
[ # # ]
548 [ # # ][ # # ]: 0 : while(m_bVertical ? aStart.Y() < aRect.Bottom(): aStart.X() < aRect.Right())
549 : : {
550 [ # # ]: 0 : DrawLine(aStart, aEnd);
551 [ # # ]: 0 : if(m_bVertical)
552 : 0 : aStart.Y() = aEnd.Y() += nBaseHeight;
553 : : else
554 : 0 : aStart.X() = aEnd.X() += nBaseHeight;
555 : : }
556 : : }
557 [ # # ]: 0 : aRubyRect.Move(nXMove, nYMove);
558 [ # # ]: 0 : aCharRect.Move(nXMove, nYMove);
559 : : }
560 : : }
561 : 0 : }
562 : :
563 : 0 : void SwPageGridExample::UpdateExample( const SfxItemSet& rSet )
564 : : {
565 [ # # ]: 0 : DELETEZ(pGridItem);
566 : : //get the grid information
567 [ # # ]: 0 : if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_TEXTGRID, sal_True))
568 : 0 : pGridItem = (SwTextGridItem*)((const SwTextGridItem&)rSet.Get(RES_TEXTGRID)).Clone();
569 [ # # ]: 0 : if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( RES_FRAMEDIR, sal_True ))
570 : : {
571 : : const SvxFrameDirectionItem& rDirItem =
572 : 0 : (const SvxFrameDirectionItem&)rSet.Get(RES_FRAMEDIR);
573 : 0 : m_bVertical = rDirItem.GetValue() == FRMDIR_VERT_TOP_RIGHT||
574 [ # # ][ # # ]: 0 : rDirItem.GetValue() == FRMDIR_VERT_TOP_LEFT;
575 : : }
576 : 0 : SwPageExample::UpdateExample(rSet);
577 : 0 : }
578 : :
579 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|