1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/dialoghelper.hxx>
21 #include <svx/paraprev.hxx>
22 #include <vcl/outdev.hxx>
23 #include <vcl/settings.hxx>
25 SvxParaPrevWindow::SvxParaPrevWindow() :
28 nFirstLineOffset ( 0 ),
31 eAdjust ( SvxAdjust::Left
),
32 eLastLine ( SvxAdjust::Left
),
33 eLine ( SvxPrevLineSpace::N1
)
35 aSize
= Size(11905, 16837);
38 void SvxParaPrevWindow::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
40 CustomWidgetController::SetDrawingArea(pDrawingArea
);
41 Size
aOptimalSize(getParagraphPreviewOptimalSize(pDrawingArea
->get_ref_device()));
42 pDrawingArea
->set_size_request(aOptimalSize
.Width(), aOptimalSize
.Height());
45 void SvxParaPrevWindow::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
47 DrawParagraph(rRenderContext
);
50 #define DEF_MARGIN 120
52 void SvxParaPrevWindow::DrawParagraph(vcl::RenderContext
& rRenderContext
)
54 // Count in Twips by default
55 rRenderContext
.Push(vcl::PushFlags::MAPMODE
);
56 rRenderContext
.SetMapMode(MapMode(MapUnit::MapTwip
));
58 Size
aWinSize(GetOutputSizePixel());
59 aWinSize
= rRenderContext
.PixelToLogic(aWinSize
);
61 aTmp
= rRenderContext
.PixelToLogic(aTmp
);
62 aWinSize
.AdjustWidth( -(aTmp
.Width() /2) );
63 aWinSize
.AdjustHeight( -(aTmp
.Height() /2) );
65 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
66 const Color
& rWinColor
= rStyleSettings
.GetWindowColor();
67 Color
aGrayColor(COL_LIGHTGRAY
);
69 rRenderContext
.SetFillColor(rWinColor
);
70 rRenderContext
.DrawRect(tools::Rectangle(Point(), aWinSize
));
72 rRenderContext
.SetLineColor();
74 tools::Long nH
= aWinSize
.Height() / 19;
75 Size
aLineSiz(aWinSize
.Width() - DEF_MARGIN
, nH
);
78 aPnt
.setX( DEF_MARGIN
/ 2 );
79 rRenderContext
.SetFillColor(aGrayColor
);
81 for (sal_uInt16 i
= 0; i
< 9; ++i
)
85 rRenderContext
.SetFillColor(COL_GRAY
);
86 auto nTop
= nUpper
* aLineSiz
.Height() / aSize
.Height();
87 aPnt
.AdjustY(nTop
* 2 );
91 rRenderContext
.SetFillColor(aGrayColor
);
95 tools::Long nLeft
= nLeftMargin
* aLineSiz
.Width() / aSize
.Width();
96 tools::Long nFirst
= nFirstLineOffset
* aLineSiz
.Width() / aSize
.Width();
97 tools::Long nTmp
= nLeft
+ nFirst
;
102 aSiz
.AdjustWidth( -nTmp
);
106 aPnt
.AdjustX(nLeft
);
107 aSiz
.AdjustWidth( -nLeft
);
109 tools::Long nRight
= nRightMargin
* aLineSiz
.Width() / aSize
.Width();
110 aSiz
.AdjustWidth( -nRight
);
113 if (4 == i
|| 5 == i
|| 6 == i
)
117 case SvxPrevLineSpace::N1
:
119 case SvxPrevLineSpace::N115
:
120 aPnt
.AdjustY(nH
/ 6.67 ); // 1/.15 = 6.(6)
122 case SvxPrevLineSpace::N15
:
123 aPnt
.AdjustY(nH
/ 2 );
125 case SvxPrevLineSpace::N2
:
128 case SvxPrevLineSpace::Prop
:
129 case SvxPrevLineSpace::Min
:
130 case SvxPrevLineSpace::Leading
:
137 if (3 <= i
&& 5 >= i
)
139 tools::Long nLW
= tools::Long();
143 nLW
= aLineSiz
.Width() * 8 / 10;
146 nLW
= aLineSiz
.Width() * 9 / 10;
149 nLW
= aLineSiz
.Width() / 2;
153 if (nLW
> aSiz
.Width())
158 case SvxAdjust::Left
:
160 case SvxAdjust::Right
:
161 aPnt
.AdjustX( aSiz
.Width() - nLW
);
163 case SvxAdjust::Center
:
164 aPnt
.AdjustX(( aSiz
.Width() - nLW
) / 2 );
166 default: ; //prevent warning
168 if (SvxAdjust::Block
== eAdjust
)
174 case SvxAdjust::Left
:
176 case SvxAdjust::Right
:
177 aPnt
.AdjustX( aSiz
.Width() - nLW
);
179 case SvxAdjust::Center
:
180 aPnt
.AdjustX(( aSiz
.Width() - nLW
) / 2 );
182 case SvxAdjust::Block
:
185 default: ; //prevent warning
191 aSiz
.setWidth( nLW
);
194 tools::Rectangle
aRect(aPnt
, aSiz
);
196 rRenderContext
.DrawRect( aRect
);
200 auto nBottom
= nLower
* aLineSiz
.Height() / aSize
.Height();
201 aPnt
.AdjustY(nBottom
* 2 );
205 // Reset, recalculate for each line
206 aPnt
.setX( DEF_MARGIN
/ 2 );
209 rRenderContext
.Pop();
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */