1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19 #include "LineWidthValueSet.hxx"
20
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/event.hxx>
24
25 namespace svx { namespace sidebar {
26
LineWidthValueSet(vcl::Window * pParent)27 LineWidthValueSet::LineWidthValueSet(vcl::Window* pParent)
28 : ValueSet(pParent, WB_TABSTOP)
29 , nSelItem(0)
30 , bCusEnable(false)
31 {
32 }
33
Resize()34 void LineWidthValueSet::Resize()
35 {
36 SetColCount();
37 SetLineCount(9);
38 ValueSet::Resize();
39 }
40
~LineWidthValueSet()41 LineWidthValueSet::~LineWidthValueSet()
42 {
43 disposeOnce();
44 }
45
SetUnit(std::array<OUString,9> const & strUnits)46 void LineWidthValueSet::SetUnit(std::array<OUString,9> const & strUnits)
47 {
48 maStrUnits = strUnits;
49 }
50
SetSelItem(sal_uInt16 nSel)51 void LineWidthValueSet::SetSelItem(sal_uInt16 nSel)
52 {
53 nSelItem = nSel;
54 if(nSel == 0)
55 {
56 SelectItem(1); // ,false); // 'false' nut supported by AOO
57 SetNoSelection();
58 }
59 else
60 {
61 SelectItem(nSelItem);
62 GrabFocus();
63 }
64 }
65
SetImage(const Image & img)66 void LineWidthValueSet::SetImage(const Image& img)
67 {
68 imgCus = img;
69 }
70
SetCusEnable(bool bEnable)71 void LineWidthValueSet::SetCusEnable(bool bEnable)
72 {
73 bCusEnable = bEnable;
74 }
75
UserDraw(const UserDrawEvent & rUDEvt)76 void LineWidthValueSet::UserDraw( const UserDrawEvent& rUDEvt )
77 {
78 tools::Rectangle aRect = rUDEvt.GetRect();
79 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
80 sal_uInt16 nItemId = rUDEvt.GetItemId();
81
82 long nRectHeight = aRect.GetHeight();
83 long nRectWidth = aRect.GetWidth();
84 Point aBLPos = aRect.TopLeft();
85
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();
92
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 );
97
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);
100 if(nItemId == 9)
101 {
102 Point aImgStart(aBLPos.X() + 5, aBLPos.Y() + ( nRectHeight - 23 ) / 2);
103 pDev->DrawImage(aImgStart, imgCus);
104 // Point aStart(aImgStart.X() + 14 + 20 , aBLPos.Y() + nRectHeight/6);
105 tools::Rectangle aStrRect = aRect;
106 aStrRect.AdjustTop(nRectHeight/6 );
107 aStrRect.AdjustBottom( -(nRectHeight/6) );
108 aStrRect.AdjustLeft(imgCus.GetSizePixel().Width() + 20 );
109 if(bCusEnable)
110 aFont.SetColor(GetSettings().GetStyleSettings().GetFieldTextColor());
111 else
112 aFont.SetColor(GetSettings().GetStyleSettings().GetDisableColor());
113
114 pDev->SetFont(aFont);
115 pDev->DrawText(aStrRect, maStrUnits[ nItemId - 1 ], DrawTextFlags::EndEllipsis);
116 }
117 else
118 {
119 if( nSelItem == nItemId )
120 {
121 tools::Rectangle aBackRect = aRect;
122 aBackRect.AdjustTop(3 );
123 aBackRect.AdjustBottom( -2 );
124 pDev->SetFillColor(Color(50,107,197));
125 pDev->DrawRect(aBackRect);
126 }
127 else
128 {
129 pDev->SetFillColor( COL_TRANSPARENT );
130 pDev->DrawRect(aRect);
131 }
132
133 //draw text
134 if(nSelItem == nItemId )
135 aFont.SetColor(COL_WHITE);
136 else
137 aFont.SetColor(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
141
142 //draw line
143 if( nSelItem == nItemId )
144 pDev->SetLineColor(COL_WHITE);
145 else
146 pDev->SetLineColor(GetSettings().GetStyleSettings().GetFieldTextColor());
147
148 for(sal_uInt16 i = 1; i <= nItemId; i++)
149 {
150 pDev->DrawLine(aLineStart,aLineEnd );
151 aLineStart.setY(aLineStart.getY() + 1);
152 aLineEnd.setY (aLineEnd.getY() + 1);
153 }
154 }
155
156 Invalidate( aRect );
157 pDev->SetLineColor(aOldColor);
158 pDev->SetFillColor(aOldFillColor);
159 pDev->SetFont(aOldFont);
160 }
161
GetOptimalSize() const162 Size LineWidthValueSet::GetOptimalSize() const
163 {
164 return LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont));
165 }
166
167 } } // end of namespace svx::sidebar
168
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
170