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 "CellLineStyleValueSet.hxx"
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
26 namespace sc::sidebar
{
28 CellLineStyleValueSet::CellLineStyleValueSet()
35 CellLineStyleValueSet::~CellLineStyleValueSet()
39 void CellLineStyleValueSet::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
41 ValueSet::SetDrawingArea(pDrawingArea
);
42 Size aSize
= pDrawingArea
->get_ref_device().LogicToPixel(Size(120, 12 * CELL_LINE_STYLE_ENTRIES
),
43 MapMode(MapUnit::MapAppFont
));
44 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
45 SetOutputSizePixel(aSize
);
48 SetLineCount(CELL_LINE_STYLE_ENTRIES
);
51 void CellLineStyleValueSet::SetUnit(const OUString
* str
)
53 for (int i
= 0; i
< CELL_LINE_STYLE_ENTRIES
; ++i
)
55 maStrUnit
[i
] = str
[i
];
59 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel
)
74 tools::Long
CellLineStyleValueSet::GetMaxTextWidth(const vcl::RenderContext
* pDev
)
76 if (mnMaxTextWidth
> 0)
77 return mnMaxTextWidth
;
79 for (int i
= 0; i
< CELL_LINE_STYLE_ENTRIES
; ++i
)
81 mnMaxTextWidth
= std::max(pDev
->GetTextWidth(maStrUnit
[i
]), mnMaxTextWidth
);
83 return mnMaxTextWidth
;
86 void CellLineStyleValueSet::UserDraw( const UserDrawEvent
& rUDEvt
)
88 tools::Rectangle aRect
= rUDEvt
.GetRect();
89 vcl::RenderContext
* pDev
= rUDEvt
.GetRenderContext();
90 sal_uInt16 nItemId
= rUDEvt
.GetItemId();
92 tools::Long nRectHeight
= aRect
.GetHeight();
93 tools::Long nRectWidth
= aRect
.GetWidth();
94 Point aBLPos
= aRect
.TopLeft();
96 vcl::Font aOldFont
= pDev
->GetFont();
97 Color aOldColor
= pDev
->GetLineColor();
98 Color aOldFillColor
= pDev
->GetFillColor();
100 vcl::Font
aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS
, MsLangId::getConfiguredSystemLanguage(), GetDefaultFontFlags::OnlyOne
));
101 Size aSize
= aFont
.GetFontSize();
102 aSize
.setHeight( nRectHeight
*3/5 );
103 aFont
.SetFontSize( aSize
);
105 if( nSelItem
== nItemId
)
107 tools::Rectangle aBackRect
= aRect
;
108 aBackRect
.AdjustTop(3 );
109 aBackRect
.AdjustBottom( -2 );
110 pDev
->SetFillColor(Color(50,107,197));
111 pDev
->DrawRect(aBackRect
);
115 pDev
->SetFillColor( COL_TRANSPARENT
);
116 pDev
->DrawRect(aRect
);
119 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
122 if (nSelItem
== nItemId
)
123 aFont
.SetColor(COL_WHITE
);
125 aFont
.SetColor(rStyleSettings
.GetFieldTextColor()); //high contrast
127 pDev
->SetFont(aFont
);
128 tools::Long nTextWidth
= GetMaxTextWidth(pDev
);
129 tools::Long nTLX
= aBLPos
.X() + 5, nTLY
= aBLPos
.Y() + ( nRectHeight
- nItemId
)/2;
130 tools::Long nTRX
= aBLPos
.X() + nRectWidth
- nTextWidth
- 15, nTRY
= aBLPos
.Y() + ( nRectHeight
- nItemId
)/2;
131 Point
aStart(aBLPos
.X() + nRectWidth
- nTextWidth
- 5 , aBLPos
.Y() + nRectHeight
/6);
132 pDev
->DrawText(aStart
, maStrUnit
[nItemId
- 1]); //can't set DrawTextFlags::EndEllipsis here, or the text will disappear
135 if( nSelItem
== nItemId
)
137 pDev
->SetFillColor(COL_WHITE
);
138 pDev
->SetLineColor(COL_WHITE
);
142 pDev
->SetFillColor(rStyleSettings
.GetFieldTextColor()); //high contrast
143 pDev
->SetLineColor(rStyleSettings
.GetFieldTextColor()); //high contrast
154 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ nItemId
* 2 - 1 ));
157 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ 1 ));
158 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
+ 3 , nTRX
, nTRY
+ 4 ));
161 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ 1 ));
162 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
+ 5 , nTRX
, nTRY
+ 6 ));
165 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ 1 ));
166 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
+ 3 , nTRX
, nTRY
+ 6 ));
169 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ 3 ));
170 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
+ 5 , nTRX
, nTRY
+ 6 ));
173 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
, nTRX
, nTRY
+ 3 ));
174 pDev
->DrawRect(tools::Rectangle(nTLX
, nTLY
+ 5 , nTRX
, nTRY
+ 8 ));
179 pDev
->SetLineColor(aOldColor
);
180 pDev
->SetFillColor(aOldFillColor
);
181 pDev
->SetFont(aOldFont
);
185 } // end of namespace sc::sidebar
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */