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/builderfactory.hxx>
23 #include <vcl/settings.hxx>
25 SvxParaPrevWindow::SvxParaPrevWindow( vcl::Window
* pParent
, WinBits nBits
) :
26 Window( pParent
, nBits
),
32 eAdjust ( SVX_ADJUST_LEFT
),
33 eLastLine ( SVX_ADJUST_LEFT
),
34 eLine ( SVX_PREV_LINESPACE_1
),
38 // Count in Twips by default
39 SetMapMode(MapMode(MAP_TWIP
));
41 aSize
= Size(11905, 16837);
43 SetBorderStyle(WindowBorderStyle::MONO
);
46 VCL_BUILDER_FACTORY_ARGS(SvxParaPrevWindow
, WB_BORDER
)
48 Size
SvxParaPrevWindow::GetOptimalSize() const
50 return getParagraphPreviewOptimalSize(this);
53 void SvxParaPrevWindow::Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
&)
55 DrawParagraph(rRenderContext
, true);
58 #define DEF_MARGIN 120
60 void SvxParaPrevWindow::DrawParagraph(vcl::RenderContext
& rRenderContext
, bool bAll
)
62 Size
aWinSize(GetOutputSizePixel());
63 aWinSize
= rRenderContext
.PixelToLogic(aWinSize
);
65 aTmp
= PixelToLogic(aTmp
);
66 aWinSize
.Width() -= aTmp
.Width() /2;
67 aWinSize
.Height() -= aTmp
.Height() /2;
69 const StyleSettings
& rStyleSettings
= rRenderContext
.GetSettings().GetStyleSettings();
70 const Color
& rWinColor
= rStyleSettings
.GetWindowColor();
71 Color
aGrayColor(COL_LIGHTGRAY
);
73 rRenderContext
.SetFillColor(Color(rWinColor
));
75 rRenderContext
.DrawRect(Rectangle(Point(), aWinSize
));
77 rRenderContext
.SetLineColor();
79 long nH
= aWinSize
.Height() / 19;
80 Size
aLineSiz(aWinSize
.Width() - DEF_MARGIN
, nH
);
83 aPnt
.X() = DEF_MARGIN
/ 2;
84 rRenderContext
.SetFillColor(aGrayColor
);
86 for (sal_uInt16 i
= 0; i
< 9; ++i
)
90 rRenderContext
.SetFillColor(Color(COL_GRAY
));
91 long nTop
= nUpper
* aLineSiz
.Height() / aSize
.Height();
96 rRenderContext
.SetFillColor(aGrayColor
);
100 long nLeft
= nLeftMargin
* aLineSiz
.Width() / aSize
.Width();
101 long nFirst
= nFirstLineOfst
* aLineSiz
.Width() / aSize
.Width();
102 long nTmp
= nLeft
+ nFirst
;
107 aSiz
.Width() -= nTmp
;
112 aSiz
.Width() -= nLeft
;
114 long nRight
= nRightMargin
* aLineSiz
.Width() / aSize
.Width();
115 aSiz
.Width() -= nRight
;
118 if (4 == i
|| 5 == i
|| 6 == i
)
122 case SVX_PREV_LINESPACE_1
:
124 case SVX_PREV_LINESPACE_15
:
127 case SVX_PREV_LINESPACE_2
:
130 case SVX_PREV_LINESPACE_PROP
:
131 case SVX_PREV_LINESPACE_MIN
:
132 case SVX_PREV_LINESPACE_DURCH
:
139 if (3 <= i
&& 5 >= i
)
145 nLW
= aLineSiz
.Width() * 8 / 10;
148 nLW
= aLineSiz
.Width() * 9 / 10;
151 nLW
= aLineSiz
.Width() / 2;
155 if (nLW
> aSiz
.Width())
160 case SVX_ADJUST_LEFT
:
162 case SVX_ADJUST_RIGHT
:
163 aPnt
.X() += ( aSiz
.Width() - nLW
);
165 case SVX_ADJUST_CENTER
:
166 aPnt
.X() += ( aSiz
.Width() - nLW
) / 2;
168 default: ; //prevent warning
170 if (SVX_ADJUST_BLOCK
== eAdjust
)
176 case SVX_ADJUST_LEFT
:
178 case SVX_ADJUST_RIGHT
:
179 aPnt
.X() += ( aSiz
.Width() - nLW
);
181 case SVX_ADJUST_CENTER
:
182 aPnt
.X() += ( aSiz
.Width() - nLW
) / 2;
184 case SVX_ADJUST_BLOCK
:
187 default: ; //prevent warning
196 Rectangle
aRect(aPnt
, aSiz
);
198 if (Lines
[i
] != aRect
|| bAll
)
202 Color aFillCol
= rRenderContext
.GetFillColor();
203 rRenderContext
.SetFillColor(rWinColor
);
204 rRenderContext
.DrawRect(Lines
[i
]);
205 rRenderContext
.SetFillColor(aFillCol
);
207 rRenderContext
.DrawRect( aRect
);
213 long nBottom
= nLower
* aLineSiz
.Height() / aSize
.Height();
214 aPnt
.Y() += nBottom
* 2;
218 // Reset, recalculate for each line
219 aPnt
.X() = DEF_MARGIN
/ 2;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */