update dev300-m58
[ooovba.git] / sw / source / ui / frmdlg / colex.cxx
blob8b06398c80e49f8f62371067d14df3fb6985c361
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: colex.cxx,v $
10 * $Revision: 1.19 $
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_sw.hxx"
37 #include "cmdid.h"
38 #include "hintids.hxx"
39 #include <algorithm>
42 #include <svtools/eitem.hxx>
43 #include <svx/lrspitem.hxx>
44 #include <svx/ulspitem.hxx>
45 #include <svx/sizeitem.hxx>
46 #include <svx/pageitem.hxx>
47 #include <svx/brshitem.hxx>
48 #include <svx/frmdiritem.hxx>
49 #include <vcl/bitmap.hxx>
50 #include <vcl/graph.hxx>
51 #include <tgrditem.hxx>
52 #include <viewopt.hxx>
53 #include "colex.hxx"
54 #include "colmgr.hxx"
56 /*-----------------------------------------------------------------------
57 Beschreibung: Uebernahme der aktualisierten Werte aus dem Set
58 -----------------------------------------------------------------------*/
59 void SwPageExample::UpdateExample( const SfxItemSet& rSet )
61 const SvxPageItem* pPage = 0;
62 SfxItemPool* pPool = rSet.GetPool();
63 USHORT nWhich = pPool->GetWhich( SID_ATTR_PAGE );
65 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
67 // Ausrichtung
68 pPage = (const SvxPageItem*)&rSet.Get( nWhich );
70 if ( pPage )
71 SetUsage( pPage->GetPageUsage() );
74 nWhich = pPool->GetWhich( SID_ATTR_PAGE_SIZE );
76 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
78 // Orientation und Size aus dem PageItem
79 const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( nWhich );
80 SetSize( rSize.GetSize() );
82 nWhich = RES_LR_SPACE;
83 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
85 // linken und rechten Rand einstellen
86 const SvxLRSpaceItem& rLRSpace = (const SvxLRSpaceItem&)rSet.Get( nWhich );
88 SetLeft( rLRSpace.GetLeft() );
89 SetRight( rLRSpace.GetRight() );
91 else
93 SetLeft( 0 );
94 SetRight( 0 );
97 nWhich = RES_UL_SPACE;
99 if ( rSet.GetItemState( nWhich, FALSE ) == SFX_ITEM_SET )
101 // oberen und unteren Rand einstellen
102 const SvxULSpaceItem& rULSpace = (const SvxULSpaceItem&)rSet.Get( nWhich );
104 SetTop( rULSpace.GetUpper() );
105 SetBottom( rULSpace.GetLower() );
107 else
109 SetTop( 0 );
110 SetBottom( 0 );
114 // Kopfzeilen-Attribute auswerten
115 const SfxPoolItem* pItem;
116 if( SFX_ITEM_SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_HEADERSET),
117 FALSE, &pItem ) )
119 const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
120 const SfxBoolItem& rHeaderOn =
121 (const SfxBoolItem&)rHeaderSet.Get( pPool->GetWhich( SID_ATTR_PAGE_ON ) );
123 if ( rHeaderOn.GetValue() )
125 const SvxSizeItem& rSize =
126 (const SvxSizeItem&)rHeaderSet.Get(pPool->GetWhich(SID_ATTR_PAGE_SIZE));
128 const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rHeaderSet.Get(
129 pPool->GetWhich(SID_ATTR_ULSPACE));
130 const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rHeaderSet.Get(
131 pPool->GetWhich(SID_ATTR_LRSPACE));
133 SetHdHeight( rSize.GetSize().Height() - rUL.GetLower());
134 SetHdDist( rUL.GetLower() );
135 SetHdLeft( rLR.GetLeft() );
136 SetHdRight( rLR.GetRight() );
137 SetHeader( TRUE );
138 if ( rHeaderSet.GetItemState( RES_BACKGROUND ) == SFX_ITEM_SET )
140 const SvxBrushItem& rItem =
141 (const SvxBrushItem&)rHeaderSet.Get( RES_BACKGROUND );
142 SetHdColor( rItem.GetColor() );
144 if ( rHeaderSet.GetItemState( RES_BOX ) == SFX_ITEM_SET )
146 const SvxBoxItem& rItem =
147 (const SvxBoxItem&)rHeaderSet.Get( RES_BOX );
148 SetHdBorder( rItem );
151 else
152 SetHeader( FALSE );
155 if( SFX_ITEM_SET == rSet.GetItemState( pPool->GetWhich( SID_ATTR_PAGE_FOOTERSET),
156 FALSE, &pItem ) )
158 const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
159 const SfxBoolItem& rFooterOn =
160 (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
162 if ( rFooterOn.GetValue() )
164 const SvxSizeItem& rSize =
165 (const SvxSizeItem&)rFooterSet.Get( pPool->GetWhich( SID_ATTR_PAGE_SIZE ) );
167 const SvxULSpaceItem& rUL = (const SvxULSpaceItem&)rFooterSet.Get(
168 pPool->GetWhich( SID_ATTR_ULSPACE ) );
169 const SvxLRSpaceItem& rLR = (const SvxLRSpaceItem&)rFooterSet.Get(
170 pPool->GetWhich( SID_ATTR_LRSPACE ) );
172 SetFtHeight( rSize.GetSize().Height() - rUL.GetUpper());
173 SetFtDist( rUL.GetUpper() );
174 SetFtLeft( rLR.GetLeft() );
175 SetFtRight( rLR.GetRight() );
176 SetFooter( TRUE );
177 if( rFooterSet.GetItemState( RES_BACKGROUND ) == SFX_ITEM_SET )
179 const SvxBrushItem& rItem =
180 (const SvxBrushItem&)rFooterSet.Get( RES_BACKGROUND );
181 SetFtColor( rItem.GetColor() );
183 if( rFooterSet.GetItemState( RES_BOX ) == SFX_ITEM_SET )
185 const SvxBoxItem& rItem =
186 (const SvxBoxItem&)rFooterSet.Get( RES_BOX );
187 SetFtBorder( rItem );
190 else
191 SetFooter( FALSE );
193 if( SFX_ITEM_SET == rSet.GetItemState( RES_BACKGROUND,
194 FALSE, &pItem ) )
196 SetColor( ( (const SvxBrushItem*)pItem )->GetColor() );
197 const Graphic* pGrf = ( (const SvxBrushItem*)pItem )->GetGraphic();
199 if ( pGrf )
201 Bitmap aBitmap = pGrf->GetBitmap();
202 SetBitmap( &aBitmap );
204 else
205 SetBitmap( NULL );
208 Invalidate();
210 /*-----------------------------------------------------------------------
211 Beschreibung:
212 -----------------------------------------------------------------------*/
215 void SwColExample::DrawPage( const Point& rOrg,
216 const BOOL bSecond,
217 const BOOL bEnabled )
219 SwPageExample::DrawPage( rOrg, bSecond, bEnabled );
220 USHORT nColumnCount;
221 if( pColMgr && 0 != (nColumnCount = pColMgr->GetCount()))
223 long nL = GetLeft();
224 long nR = GetRight();
226 if ( GetUsage() == SVX_PAGE_MIRROR && !bSecond )
228 // fuer gespiegelt drehen
229 nL = GetRight();
230 nR = GetLeft();
233 SetFillColor( Color( COL_LIGHTGRAY ) );
234 Rectangle aRect;
235 aRect.Right() = rOrg.X() + GetSize().Width() - nR;
236 aRect.Left() = rOrg.X() + nL;
237 aRect.Top() = rOrg.Y() + GetTop()
238 + GetHdHeight() + GetHdDist();
239 aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom()
240 - GetFtHeight() - GetFtDist();
241 DrawRect(aRect);
243 if(GetColor() == Color(COL_TRANSPARENT))
245 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
246 const Color& rFieldColor = rStyleSettings.GetFieldColor();
247 SetFillColor( rFieldColor );
249 else
250 SetFillColor( GetColor() );
252 // #97495# make sure that the automatic column widht's are always equal
253 BOOL bAutoWidth = pColMgr->IsAutoWidth();
254 sal_Int32 nAutoColWidth = 0;
255 if(bAutoWidth)
257 sal_Int32 nColumnWidthSum = 0;
258 USHORT i;
259 for(i = 0; i < nColumnCount; ++i)
260 nColumnWidthSum += pColMgr->GetColWidth( i );
261 nAutoColWidth = nColumnWidthSum / nColumnCount;
264 USHORT i;
265 for( i = 0; i < nColumnCount; i++)
267 if(!bAutoWidth)
268 nAutoColWidth = pColMgr->GetColWidth( i );
269 aRect.Right() = aRect.Left() + nAutoColWidth;
270 DrawRect(aRect);
271 if(i < nColumnCount - 1)
272 aRect.Left() = aRect.Right() + pColMgr->GetGutterWidth(i);
274 if(pColMgr->HasLine())
276 Point aUp( rOrg.X() + nL, rOrg.Y() + GetTop() );
277 Point aDown( rOrg.X() + nL, rOrg.Y() + GetSize().Height()
278 - GetBottom() - GetFtHeight() - GetFtDist() );
280 if( pColMgr->GetLineHeightPercent() != 100 )
282 long nLength = aDown.Y() - aUp.Y();
283 nLength -= nLength * pColMgr->GetLineHeightPercent() / 100;
284 switch(pColMgr->GetAdjust())
286 case COLADJ_BOTTOM: aUp.Y() += nLength; break;
287 case COLADJ_TOP: aDown.Y() -= nLength; break;
288 case COLADJ_CENTER:
289 aUp.Y() += nLength / 2;
290 aDown.Y() -= nLength / 2;
291 break;
292 default:; // prevent warning
296 int nDist;
297 for( i = 0; i < nColumnCount - 1; i++)
299 int nGutter = pColMgr->GetGutterWidth(i);
300 nDist = pColMgr->GetColWidth( i ) + nGutter;
301 nDist -= (i == 0) ?
302 nGutter/2 :
304 aUp.X() += nDist;
305 aDown.X() += nDist;
306 DrawLine( aUp, aDown );
313 /*-----------------25.10.96 09.15-------------------
315 --------------------------------------------------*/
318 SwColumnOnlyExample::SwColumnOnlyExample( Window* pParent, const ResId& rResId) :
319 Window(pParent, rResId),
320 m_aFrmSize(1,1)
322 SetMapMode( MapMode( MAP_TWIP ) );
323 m_aWinSize = GetOutputSizePixel();
324 m_aWinSize.Height() -= 4;
325 m_aWinSize.Width() -= 4;
327 m_aWinSize = PixelToLogic( m_aWinSize );
329 SetBorderStyle( WINDOW_BORDER_MONO );
331 m_aFrmSize = SvxPaperInfo::GetPaperSize(PAPER_A4);// DIN A4
332 ::FitToActualSize(m_aCols, (USHORT)m_aFrmSize.Width());
334 long nHeight = m_aFrmSize.Height();
335 Fraction aScale( m_aWinSize.Height(), nHeight );
336 MapMode aMapMode( GetMapMode() );
337 aMapMode.SetScaleX( aScale );
338 aMapMode.SetScaleY( aScale );
339 SetMapMode( aMapMode );
342 /*-----------------25.10.96 09.16-------------------
344 --------------------------------------------------*/
347 void SwColumnOnlyExample::Paint( const Rectangle& /*rRect*/ )
349 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
350 const Color& rFieldColor = rStyleSettings.GetFieldColor();
351 const Color& rDlgColor = rStyleSettings.GetDialogColor();
352 const Color& rFieldTextColor = SwViewOption::GetFontColor();
353 Color aGrayColor(COL_LIGHTGRAY);
354 if(rFieldColor == aGrayColor)
355 aGrayColor.Invert();
357 Size aLogSize(PixelToLogic(GetOutputSizePixel()));
358 Rectangle aCompleteRect(Point(0,0), aLogSize);
359 SetLineColor(rDlgColor);
360 SetFillColor(rDlgColor);
361 DrawRect(aCompleteRect);
363 SetLineColor( rFieldTextColor );
364 Point aTL( (aLogSize.Width() - m_aFrmSize.Width()) / 2,
365 (aLogSize.Height() - m_aFrmSize.Height()) / 2);
366 Rectangle aRect(aTL, m_aFrmSize);
368 //draw a shadow rectangle
369 SetFillColor( Color(COL_GRAY) );
370 Rectangle aShadowRect(aRect);
371 aShadowRect.Move(aTL.Y(), aTL.Y());
372 DrawRect(aShadowRect);
374 SetFillColor( rFieldColor );
375 DrawRect(aRect);
377 SetFillColor( aGrayColor );
379 //Spaltentrenner?
380 long nLength = aLogSize.Height() - 2 * aTL.Y();
381 Point aUp( aTL );
382 Point aDown( aTL.X(), nLength );
383 BOOL bLines = FALSE;
384 if(m_aCols.GetLineAdj() != COLADJ_NONE)
386 bLines = TRUE;
388 USHORT nPercent = m_aCols.GetLineHeight();
389 if( nPercent != 100 )
391 nLength -= nLength * nPercent / 100;
392 switch(m_aCols.GetLineAdj())
394 case COLADJ_BOTTOM: aUp.Y() += nLength; break;
395 case COLADJ_TOP: aDown.Y() -= nLength; break;
396 case COLADJ_CENTER:
397 aUp.Y() += nLength / 2;
398 aDown.Y() -= nLength / 2;
399 break;
400 default:; //prevent warning
405 const SwColumns& rCols = m_aCols.GetColumns();
406 USHORT nColCount = rCols.Count();
407 if( nColCount )
409 DrawRect(aRect);
410 SetFillColor( rFieldColor );
411 Rectangle aFrmRect(aTL, m_aFrmSize);
412 long nSum = aTL.X();
413 for(USHORT i = 0; i < nColCount; i++)
415 SwColumn* pCol = rCols[i];
416 aFrmRect.Left() = nSum + pCol->GetLeft();//nSum + pCol->GetLeft() + aTL.X();
417 nSum += pCol->GetWishWidth();
418 aFrmRect.Right() = nSum - pCol->GetRight();
419 DrawRect(aFrmRect);
421 if(bLines )
423 nSum = aTL.X();
424 for(USHORT i = 0; i < nColCount - 1; i++)
426 nSum += rCols[i]->GetWishWidth();
427 aUp.X() = nSum;
428 aDown.X() = nSum;
429 DrawLine(aUp, aDown);
435 /*-----------------25.10.96 12.05-------------------
437 --------------------------------------------------*/
440 void SwColumnOnlyExample::SetColumns(const SwFmtCol& rCol)
442 m_aCols = rCol;
443 USHORT nWishSum = m_aCols.GetWishWidth();
444 long nFrmWidth = m_aFrmSize.Width();
445 SwColumns& rCols = m_aCols.GetColumns();
446 USHORT nColCount = rCols.Count();
448 for(USHORT i = 0; i < nColCount; i++)
450 SwColumn* pCol = rCols[i];
451 long nWish = pCol->GetWishWidth();
452 nWish *= nFrmWidth;
453 nWish /= nWishSum;
454 pCol->SetWishWidth((USHORT)nWish);
455 long nLeft = pCol->GetLeft();
456 nLeft *= nFrmWidth;
457 nLeft /= nWishSum;
458 pCol->SetLeft((USHORT)nLeft);
459 long nRight = pCol->GetRight();
460 nRight *= nFrmWidth;
461 nRight /= nWishSum;
462 pCol->SetRight((USHORT)nRight);
464 // #97495# make sure that the automatic column width's are always equal
465 if(nColCount && m_aCols.IsOrtho())
467 sal_Int32 nColumnWidthSum = 0;
468 USHORT i;
469 for(i = 0; i < nColCount; ++i)
471 SwColumn* pCol = rCols[i];
472 nColumnWidthSum += pCol->GetWishWidth();
473 nColumnWidthSum -= (pCol->GetRight() + pCol->GetLeft());
475 nColumnWidthSum /= nColCount;
476 for(i = 0; i < nColCount; ++i)
478 SwColumn* pCol = rCols[i];
479 pCol->SetWishWidth( static_cast< USHORT >(nColumnWidthSum + pCol->GetRight() + pCol->GetLeft()));
483 /* -----------------------------08.02.2002 11:44------------------------------
485 ---------------------------------------------------------------------------*/
486 SwPageGridExample::~SwPageGridExample()
488 delete pGridItem;
490 /* -----------------------------08.02.2002 11:48------------------------------
492 ---------------------------------------------------------------------------*/
493 #define MAX_ROWS 10
494 #define MAX_LINES 15
495 void SwPageGridExample::DrawPage( const Point& rOrg,
496 const BOOL bSecond,
497 const BOOL bEnabled )
499 SwPageExample::DrawPage(rOrg, bSecond, bEnabled);
500 if(pGridItem && pGridItem->GetGridType())
502 //paint the grid now
503 Color aLineColor = pGridItem->GetColor();
504 if(aLineColor.GetColor() == COL_AUTO)
506 aLineColor = GetFillColor();
507 aLineColor.Invert();
509 SetLineColor(aLineColor);
510 long nL = GetLeft();
511 long nR = GetRight();
513 if ( GetUsage() == SVX_PAGE_MIRROR && !bSecond )
515 // fuer gespiegelt drehen
516 nL = GetRight();
517 nR = GetLeft();
520 Rectangle aRect;
521 aRect.Right() = rOrg.X() + GetSize().Width() - nR;
522 aRect.Left() = rOrg.X() + nL;
523 aRect.Top() = rOrg.Y() + GetTop()
524 + GetHdHeight() + GetHdDist();
525 aRect.Bottom()= rOrg.Y() + GetSize().Height() - GetBottom()
526 - GetFtHeight() - GetFtDist();
528 //increase the values to get a 'viewable' preview
529 sal_Int32 nBaseHeight = pGridItem->GetBaseHeight() * 3;
530 sal_Int32 nRubyHeight = pGridItem->GetRubyHeight() * 3;
532 //detect height of rectangles
533 Rectangle aRubyRect(aRect.TopLeft(),
534 m_bVertical ?
535 Size(nRubyHeight, aRect.GetHeight()) :
536 Size(aRect.GetWidth(), nRubyHeight));
537 Rectangle aCharRect(aRect.TopLeft(),
538 m_bVertical ?
539 Size(nBaseHeight, aRect.GetHeight()) :
540 Size(aRect.GetWidth(), nBaseHeight));
542 sal_Int32 nLineHeight = nBaseHeight + nRubyHeight;
544 //detect count of rectangles
545 sal_Int32 nLines = (m_bVertical ? aRect.GetWidth(): aRect.GetHeight()) / nLineHeight;
546 if(nLines > pGridItem->GetLines())
547 nLines = pGridItem->GetLines();
549 // determine start position
550 if(m_bVertical)
552 sal_Int16 nXStart = static_cast< sal_Int16 >(aRect.GetWidth() / 2 - nLineHeight * nLines /2);
553 aRubyRect.Move(nXStart, 0);
554 aCharRect.Move(nXStart, 0);
556 else
558 sal_Int16 nYStart = static_cast< sal_Int16 >(aRect.GetHeight() / 2 - nLineHeight * nLines /2);
559 aRubyRect.Move(0, nYStart);
560 aCharRect.Move(0, nYStart);
563 if(pGridItem->IsRubyTextBelow())
564 m_bVertical ? aRubyRect.Move(nBaseHeight, 0) : aRubyRect.Move(0, nBaseHeight);
565 else
566 m_bVertical ? aCharRect.Move(nRubyHeight, 0) : aCharRect.Move(0, nRubyHeight);
568 //vertical lines
569 sal_Bool bBothLines = pGridItem->GetGridType() == GRID_LINES_CHARS;
570 SetFillColor( Color( COL_TRANSPARENT ) );
571 sal_Int32 nXMove = m_bVertical ? nLineHeight : 0;
572 sal_Int32 nYMove = m_bVertical ? 0 : nLineHeight;
573 for(sal_Int32 nLine = 0; nLine < nLines; nLine++)
575 DrawRect(aRubyRect);
576 DrawRect(aCharRect);
577 if(bBothLines)
579 Point aStart = aCharRect.TopLeft();
580 Point aEnd = m_bVertical ? aCharRect.TopRight() : aCharRect.BottomLeft();
581 while(m_bVertical ? aStart.Y() < aRect.Bottom(): aStart.X() < aRect.Right())
583 DrawLine(aStart, aEnd);
584 if(m_bVertical)
585 aStart.Y() = aEnd.Y() += nBaseHeight;
586 else
587 aStart.X() = aEnd.X() += nBaseHeight;
590 aRubyRect.Move(nXMove, nYMove);
591 aCharRect.Move(nXMove, nYMove);
595 /* -----------------------------08.02.2002 11:48------------------------------
597 ---------------------------------------------------------------------------*/
598 void SwPageGridExample::UpdateExample( const SfxItemSet& rSet )
600 DELETEZ(pGridItem);
601 //get the grid information
602 if(SFX_ITEM_AVAILABLE <= rSet.GetItemState(RES_TEXTGRID, TRUE))
603 pGridItem = (SwTextGridItem*)((const SwTextGridItem&)rSet.Get(RES_TEXTGRID)).Clone();
604 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( RES_FRAMEDIR, TRUE ))
606 const SvxFrameDirectionItem& rDirItem =
607 (const SvxFrameDirectionItem&)rSet.Get(RES_FRAMEDIR);
608 m_bVertical = rDirItem.GetValue() == FRMDIR_VERT_TOP_RIGHT||
609 rDirItem.GetValue() == FRMDIR_VERT_TOP_LEFT;
611 SwPageExample::UpdateExample(rSet);