1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: colex.cxx,v $
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"
38 #include "hintids.hxx"
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>
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
)
68 pPage
= (const SvxPageItem
*)&rSet
.Get( nWhich
);
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() );
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() );
114 // Kopfzeilen-Attribute auswerten
115 const SfxPoolItem
* pItem
;
116 if( SFX_ITEM_SET
== rSet
.GetItemState( pPool
->GetWhich( SID_ATTR_PAGE_HEADERSET
),
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() );
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
);
155 if( SFX_ITEM_SET
== rSet
.GetItemState( pPool
->GetWhich( SID_ATTR_PAGE_FOOTERSET
),
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() );
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
);
193 if( SFX_ITEM_SET
== rSet
.GetItemState( RES_BACKGROUND
,
196 SetColor( ( (const SvxBrushItem
*)pItem
)->GetColor() );
197 const Graphic
* pGrf
= ( (const SvxBrushItem
*)pItem
)->GetGraphic();
201 Bitmap aBitmap
= pGrf
->GetBitmap();
202 SetBitmap( &aBitmap
);
210 /*-----------------------------------------------------------------------
212 -----------------------------------------------------------------------*/
215 void SwColExample::DrawPage( const Point
& rOrg
,
217 const BOOL bEnabled
)
219 SwPageExample::DrawPage( rOrg
, bSecond
, bEnabled
);
221 if( pColMgr
&& 0 != (nColumnCount
= pColMgr
->GetCount()))
224 long nR
= GetRight();
226 if ( GetUsage() == SVX_PAGE_MIRROR
&& !bSecond
)
228 // fuer gespiegelt drehen
233 SetFillColor( Color( COL_LIGHTGRAY
) );
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();
243 if(GetColor() == Color(COL_TRANSPARENT
))
245 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
246 const Color
& rFieldColor
= rStyleSettings
.GetFieldColor();
247 SetFillColor( rFieldColor
);
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;
257 sal_Int32 nColumnWidthSum
= 0;
259 for(i
= 0; i
< nColumnCount
; ++i
)
260 nColumnWidthSum
+= pColMgr
->GetColWidth( i
);
261 nAutoColWidth
= nColumnWidthSum
/ nColumnCount
;
265 for( i
= 0; i
< nColumnCount
; i
++)
268 nAutoColWidth
= pColMgr
->GetColWidth( i
);
269 aRect
.Right() = aRect
.Left() + nAutoColWidth
;
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;
289 aUp
.Y() += nLength
/ 2;
290 aDown
.Y() -= nLength
/ 2;
292 default:; // prevent warning
297 for( i
= 0; i
< nColumnCount
- 1; i
++)
299 int nGutter
= pColMgr
->GetGutterWidth(i
);
300 nDist
= pColMgr
->GetColWidth( i
) + nGutter
;
306 DrawLine( aUp
, aDown
);
313 /*-----------------25.10.96 09.15-------------------
315 --------------------------------------------------*/
318 SwColumnOnlyExample::SwColumnOnlyExample( Window
* pParent
, const ResId
& rResId
) :
319 Window(pParent
, rResId
),
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
)
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
);
377 SetFillColor( aGrayColor
);
380 long nLength
= aLogSize
.Height() - 2 * aTL
.Y();
382 Point
aDown( aTL
.X(), nLength
);
384 if(m_aCols
.GetLineAdj() != COLADJ_NONE
)
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;
397 aUp
.Y() += nLength
/ 2;
398 aDown
.Y() -= nLength
/ 2;
400 default:; //prevent warning
405 const SwColumns
& rCols
= m_aCols
.GetColumns();
406 USHORT nColCount
= rCols
.Count();
410 SetFillColor( rFieldColor
);
411 Rectangle
aFrmRect(aTL
, m_aFrmSize
);
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();
424 for(USHORT i
= 0; i
< nColCount
- 1; i
++)
426 nSum
+= rCols
[i
]->GetWishWidth();
429 DrawLine(aUp
, aDown
);
435 /*-----------------25.10.96 12.05-------------------
437 --------------------------------------------------*/
440 void SwColumnOnlyExample::SetColumns(const SwFmtCol
& 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();
454 pCol
->SetWishWidth((USHORT
)nWish
);
455 long nLeft
= pCol
->GetLeft();
458 pCol
->SetLeft((USHORT
)nLeft
);
459 long nRight
= pCol
->GetRight();
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;
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()
490 /* -----------------------------08.02.2002 11:48------------------------------
492 ---------------------------------------------------------------------------*/
495 void SwPageGridExample::DrawPage( const Point
& rOrg
,
497 const BOOL bEnabled
)
499 SwPageExample::DrawPage(rOrg
, bSecond
, bEnabled
);
500 if(pGridItem
&& pGridItem
->GetGridType())
503 Color aLineColor
= pGridItem
->GetColor();
504 if(aLineColor
.GetColor() == COL_AUTO
)
506 aLineColor
= GetFillColor();
509 SetLineColor(aLineColor
);
511 long nR
= GetRight();
513 if ( GetUsage() == SVX_PAGE_MIRROR
&& !bSecond
)
515 // fuer gespiegelt drehen
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(),
535 Size(nRubyHeight
, aRect
.GetHeight()) :
536 Size(aRect
.GetWidth(), nRubyHeight
));
537 Rectangle
aCharRect(aRect
.TopLeft(),
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
552 sal_Int16 nXStart
= static_cast< sal_Int16
>(aRect
.GetWidth() / 2 - nLineHeight
* nLines
/2);
553 aRubyRect
.Move(nXStart
, 0);
554 aCharRect
.Move(nXStart
, 0);
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
);
566 m_bVertical
? aCharRect
.Move(nRubyHeight
, 0) : aCharRect
.Move(0, nRubyHeight
);
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
++)
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
);
585 aStart
.Y() = aEnd
.Y() += nBaseHeight
;
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
)
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
);