Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / dialog / paraprev.cxx
blob27dccbfd9f6a056de04cb3600c3d5fade863cd3f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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() :
26 nLeftMargin ( 0 ),
27 nRightMargin ( 0 ),
28 nFirstLineOffset ( 0 ),
29 nUpper ( 0 ),
30 nLower ( 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);
60 Size aTmp(1, 1);
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);
76 Size aSiz = aLineSiz;
77 Point aPnt;
78 aPnt.setX( DEF_MARGIN / 2 );
79 rRenderContext.SetFillColor(aGrayColor);
81 for (sal_uInt16 i = 0; i < 9; ++i)
83 if (i == 3)
85 rRenderContext.SetFillColor(COL_GRAY);
86 auto nTop = nUpper * aLineSiz.Height() / aSize.Height();
87 aPnt.AdjustY(nTop * 2 );
90 if (i == 6 )
91 rRenderContext.SetFillColor(aGrayColor);
93 if (3 <= i && 6 > i)
95 tools::Long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
96 tools::Long nFirst = nFirstLineOffset * aLineSiz.Width() / aSize.Width();
97 tools::Long nTmp = nLeft + nFirst;
99 if (i == 3)
101 aPnt.AdjustX(nTmp );
102 aSiz.AdjustWidth( -nTmp );
104 else
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)
115 switch (eLine)
117 case SvxPrevLineSpace::N1:
118 break;
119 case SvxPrevLineSpace::N115:
120 aPnt.AdjustY(nH / 6.67 ); // 1/.15 = 6.(6)
121 break;
122 case SvxPrevLineSpace::N15:
123 aPnt.AdjustY(nH / 2 );
124 break;
125 case SvxPrevLineSpace::N2:
126 aPnt.AdjustY(nH );
127 break;
128 case SvxPrevLineSpace::Prop:
129 case SvxPrevLineSpace::Min:
130 case SvxPrevLineSpace::Leading:
131 break;
135 aPnt.AdjustY(nH );
137 if (3 <= i && 5 >= i)
139 tools::Long nLW = tools::Long();
140 switch (i)
142 case 3:
143 nLW = aLineSiz.Width() * 8 / 10;
144 break;
145 case 4:
146 nLW = aLineSiz.Width() * 9 / 10;
147 break;
148 case 5:
149 nLW = aLineSiz.Width() / 2;
150 break;
153 if (nLW > aSiz.Width())
154 nLW = aSiz.Width();
156 switch (eAdjust)
158 case SvxAdjust::Left:
159 break;
160 case SvxAdjust::Right:
161 aPnt.AdjustX( aSiz.Width() - nLW );
162 break;
163 case SvxAdjust::Center:
164 aPnt.AdjustX(( aSiz.Width() - nLW ) / 2 );
165 break;
166 default: ; //prevent warning
168 if (SvxAdjust::Block == eAdjust)
170 if(5 == i)
172 switch( eLastLine )
174 case SvxAdjust::Left:
175 break;
176 case SvxAdjust::Right:
177 aPnt.AdjustX( aSiz.Width() - nLW );
178 break;
179 case SvxAdjust::Center:
180 aPnt.AdjustX(( aSiz.Width() - nLW ) / 2 );
181 break;
182 case SvxAdjust::Block:
183 nLW = aSiz.Width();
184 break;
185 default: ; //prevent warning
188 else
189 nLW = aSiz.Width();
191 aSiz.setWidth( nLW );
194 tools::Rectangle aRect(aPnt, aSiz);
196 rRenderContext.DrawRect( aRect );
198 if (5 == i)
200 auto nBottom = nLower * aLineSiz.Height() / aSize.Height();
201 aPnt.AdjustY(nBottom * 2 );
204 aPnt.AdjustY(nH );
205 // Reset, recalculate for each line
206 aPnt.setX( DEF_MARGIN / 2 );
207 aSiz = aLineSiz;
209 rRenderContext.Pop();
212 #undef DEF_MARGIN
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */