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 .
19 #include "LineWidthValueSet.hxx"
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
26 namespace svx::sidebar
{
28 LineWidthValueSet::LineWidthValueSet()
35 void LineWidthValueSet::Resize()
42 LineWidthValueSet::~LineWidthValueSet()
46 void LineWidthValueSet::SetUnit(std::array
<OUString
,9> const & strUnits
)
48 maStrUnits
= strUnits
;
51 void LineWidthValueSet::SetSelItem(sal_uInt16 nSel
)
56 SelectItem(1); // ,false); // 'false' nut supported by AOO
66 void LineWidthValueSet::SetImage(const Image
& img
)
71 void LineWidthValueSet::SetCusEnable(bool bEnable
)
76 void LineWidthValueSet::UserDraw( const UserDrawEvent
& rUDEvt
)
78 tools::Rectangle aRect
= rUDEvt
.GetRect();
79 vcl::RenderContext
* pDev
= rUDEvt
.GetRenderContext();
80 sal_uInt16 nItemId
= rUDEvt
.GetItemId();
82 tools::Long nRectHeight
= aRect
.GetHeight();
83 tools::Long nRectWidth
= aRect
.GetWidth();
84 Point aBLPos
= aRect
.TopLeft();
86 //const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
87 //Color aBackColor(0,0,200);
88 //const Color aTextColor = rStyleSettings.GetFieldTextColor();
89 vcl::Font aOldFont
= pDev
->GetFont();
90 Color aOldColor
= pDev
->GetLineColor();
91 Color aOldFillColor
= pDev
->GetFillColor();
93 vcl::Font
aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS
, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne
));
94 Size aSize
= aFont
.GetFontSize();
95 aSize
.setHeight( nRectHeight
*3/5 );
96 aFont
.SetFontSize( aSize
);
98 Point
aLineStart(aBLPos
.X() + 5, aBLPos
.Y() + ( nRectHeight
- nItemId
)/2);
99 Point
aLineEnd(aBLPos
.X() + nRectWidth
* 7 / 9 - 10, aBLPos
.Y() + ( nRectHeight
- nItemId
)/2);
102 Point
aImgStart(aBLPos
.X() + 5, aBLPos
.Y() + ( nRectHeight
- 23 ) / 2);
103 pDev
->DrawImage(aImgStart
, imgCus
);
105 tools::Rectangle aStrRect
= aRect
;
106 aStrRect
.AdjustTop(nRectHeight
/6 );
107 aStrRect
.AdjustBottom( -(nRectHeight
/6) );
108 aStrRect
.AdjustLeft(imgCus
.GetSizePixel().Width() + 20 );
110 aFont
.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
112 aFont
.SetColor(Application::GetSettings().GetStyleSettings().GetDisableColor());
114 pDev
->SetFont(aFont
);
115 pDev
->DrawText(aStrRect
, maStrUnits
[ nItemId
- 1 ], DrawTextFlags::EndEllipsis
);
119 if( nSelItem
== nItemId
)
121 tools::Rectangle aBackRect
= aRect
;
122 aBackRect
.AdjustTop(3 );
123 aBackRect
.AdjustBottom( -2 );
124 pDev
->SetFillColor(Color(50,107,197));
125 pDev
->DrawRect(aBackRect
);
129 pDev
->SetFillColor( COL_TRANSPARENT
);
130 pDev
->DrawRect(aRect
);
134 if(nSelItem
== nItemId
)
135 aFont
.SetColor(COL_WHITE
);
137 aFont
.SetColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
138 pDev
->SetFont(aFont
);
139 Point
aStart(aBLPos
.X() + nRectWidth
* 7 / 9 , aBLPos
.Y() + nRectHeight
/6);
140 pDev
->DrawText(aStart
, maStrUnits
[ nItemId
- 1 ]); //can't set DrawTextFlags::EndEllipsis here ,or the text will disappear
143 if( nSelItem
== nItemId
)
144 pDev
->SetLineColor(COL_WHITE
);
146 pDev
->SetLineColor(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
148 for(sal_uInt16 i
= 1; i
<= nItemId
; i
++)
150 pDev
->DrawLine(aLineStart
,aLineEnd
);
151 aLineStart
.setY(aLineStart
.getY() + 1);
152 aLineEnd
.setY (aLineEnd
.getY() + 1);
157 pDev
->SetLineColor(aOldColor
);
158 pDev
->SetFillColor(aOldFillColor
);
159 pDev
->SetFont(aOldFont
);
162 void LineWidthValueSet::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
164 ValueSet::SetDrawingArea(pDrawingArea
);
165 Size
aSize(pDrawingArea
->get_ref_device().LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont
)));
166 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
167 SetOutputSizePixel(aSize
);
170 } // end of namespace svx::sidebar
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */