LibreOffice Module sc (master) 1
CellLineStyleValueSet.cxx
Go to the documentation of this file.
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
22#include <vcl/event.hxx>
23#include <vcl/settings.hxx>
24#include <vcl/svapp.hxx>
25
26namespace sc::sidebar {
27
29 : ValueSet(nullptr)
30 , mnMaxTextWidth(0)
31 , nSelItem(0)
32{
33}
34
36{
37}
38
40{
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);
46
49}
50
51void CellLineStyleValueSet::SetUnit(const OUString* str)
52{
53 for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
54 {
55 maStrUnit[i] = str[i];
56 }
57}
58
60{
61 nSelItem = nSel;
62 if(nSel == 0)
63 {
64 SelectItem(1);
66 }
67 else
68 {
70 GrabFocus();
71 }
72}
73
75{
76 if (mnMaxTextWidth > 0)
77 return mnMaxTextWidth;
78
79 for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
80 {
82 }
83 return mnMaxTextWidth;
84}
85
87{
88 tools::Rectangle aRect = rUDEvt.GetRect();
89 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
90 sal_uInt16 nItemId = rUDEvt.GetItemId();
91
92 tools::Long nRectHeight = aRect.GetHeight();
93 tools::Long nRectWidth = aRect.GetWidth();
94 Point aBLPos = aRect.TopLeft();
95
96 vcl::Font aOldFont = pDev->GetFont();
97 Color aOldColor = pDev->GetLineColor();
98 Color aOldFillColor = pDev->GetFillColor();
99
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 );
104
105 if( nSelItem == nItemId )
106 {
107 tools::Rectangle aBackRect = aRect;
108 aBackRect.AdjustTop(3 );
109 aBackRect.AdjustBottom( -2 );
110 pDev->SetFillColor(Color(50,107,197));
111 pDev->DrawRect(aBackRect);
112 }
113 else
114 {
116 pDev->DrawRect(aRect);
117 }
118
119 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
120
121 //draw text
122 if (nSelItem == nItemId )
123 aFont.SetColor(COL_WHITE);
124 else
125 aFont.SetColor(rStyleSettings.GetFieldTextColor()); //high contrast
126
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
133
134 //draw line
135 if( nSelItem == nItemId )
136 {
137 pDev->SetFillColor(COL_WHITE);
138 pDev->SetLineColor(COL_WHITE);
139 }
140 else
141 {
142 pDev->SetFillColor(rStyleSettings.GetFieldTextColor()); //high contrast
143 pDev->SetLineColor(rStyleSettings.GetFieldTextColor()); //high contrast
144 }
145
146 switch( nItemId )
147 {
148 case 1:
149 case 2:
150 case 3:
151 case 4:
152 case 5:
153 case 6:
154 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 ));
155 break;
156 case 7:
157 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
158 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
159 break;
160 case 8:
161 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
162 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
163 break;
164 case 9:
165 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
166 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
167 break;
168 case 10:
169 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
170 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
171 break;
172 case 11:
173 pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
174 pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
175 break;
176 }
177
178 Invalidate( aRect );
179 pDev->SetLineColor(aOldColor);
180 pDev->SetFillColor(aOldFillColor);
181 pDev->SetFont(aOldFont);
182
183}
184
185} // end of namespace sc::sidebar
186
187/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CELL_LINE_STYLE_ENTRIES
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static LanguageType getConfiguredSystemLanguage()
const vcl::Font & GetFont() const
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
tools::Long GetTextWidth(const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, vcl::text::TextLayoutCache const *=nullptr, SalLayoutGlyphs const *const pLayoutCache=nullptr) const
void SetFillColor()
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const Color & GetLineColor() const
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, std::vector< tools::Rectangle > *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
const Color & GetFillColor() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
const Color & GetFieldTextColor() const
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
sal_uInt16 GetItemId() const
void SelectItem(sal_uInt16 nItemId)
void SetLineCount(sal_uInt16 nNewLines=0)
void SetColCount(sal_uInt16 nNewCols=1)
void SetNoSelection()
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
tools::Long GetMaxTextWidth(const vcl::RenderContext *pDev)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
OUString maStrUnit[CELL_LINE_STYLE_ENTRIES]
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
constexpr tools::Long GetWidth() const
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
constexpr tools::Long GetHeight() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void SetFontSize(const Size &)
void SetColor(const Color &)
const Size & GetFontSize() const
virtual OutputDevice & get_ref_device()=0
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
int i
long Long