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 
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
25 
26 namespace sc::sidebar {
27 
29  : ValueSet(nullptr)
30  , nSelItem(0)
31 {
32 }
33 
35 {
36 }
37 
39 {
40  ValueSet::SetDrawingArea(pDrawingArea);
41  Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(80, 12 * 9), MapMode(MapUnit::MapAppFont));
42  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
43  SetOutputSizePixel(aSize);
44 
45  SetColCount();
46  SetLineCount( 9);
47 }
48 
49 void CellLineStyleValueSet::SetUnit(const OUString* str)
50 {
51  for (int i = 0; i < CELL_LINE_STYLE_ENTRIES; ++i)
52  {
53  maStrUnit[i] = str[i];
54  }
55 }
56 
57 void CellLineStyleValueSet::SetSelItem(sal_uInt16 nSel)
58 {
59  nSelItem = nSel;
60  if(nSel == 0)
61  {
62  SelectItem(1);
64  }
65  else
66  {
68  GrabFocus();
69  }
70 }
71 
73 {
74  tools::Rectangle aRect = rUDEvt.GetRect();
75  vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
76  sal_uInt16 nItemId = rUDEvt.GetItemId();
77 
78  tools::Long nRectHeight = aRect.GetHeight();
79  tools::Long nRectWidth = aRect.GetWidth();
80  Point aBLPos = aRect.TopLeft();
81 
82  vcl::Font aOldFont = pDev->GetFont();
83  Color aOldColor = pDev->GetLineColor();
84  Color aOldFillColor = pDev->GetFillColor();
85 
86  vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getConfiguredSystemLanguage(), GetDefaultFontFlags::OnlyOne));
87  Size aSize = aFont.GetFontSize();
88  aSize.setHeight( nRectHeight*3/5 );
89  aFont.SetFontSize( aSize );
90 
91  if( nSelItem == nItemId )
92  {
93  tools::Rectangle aBackRect = aRect;
94  aBackRect.AdjustTop(3 );
95  aBackRect.AdjustBottom( -2 );
96  pDev->SetFillColor(Color(50,107,197));
97  pDev->DrawRect(aBackRect);
98  }
99  else
100  {
101  pDev->SetFillColor( COL_TRANSPARENT );
102  pDev->DrawRect(aRect);
103  }
104 
105  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
106 
107  //draw text
108  if (nSelItem == nItemId )
109  aFont.SetColor(COL_WHITE);
110  else
111  aFont.SetColor(rStyleSettings.GetFieldTextColor()); //high contrast
112 
113  pDev->SetFont(aFont);
114  tools::Long nTextWidth = pDev->GetTextWidth(maStrUnit[nItemId - 1]);
115  tools::Long nTLX = aBLPos.X() + 5, nTLY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
116  tools::Long nTRX = aBLPos.X() + nRectWidth - nTextWidth - 15, nTRY = aBLPos.Y() + ( nRectHeight - nItemId )/2;
117  Point aStart(aBLPos.X() + nRectWidth - nTextWidth - 5 , aBLPos.Y() + nRectHeight/6);
118  pDev->DrawText(aStart, maStrUnit[nItemId - 1]); //can't set DrawTextFlags::EndEllipsis here, or the text will disappear
119 
120  //draw line
121  if( nSelItem == nItemId )
122  {
123  pDev->SetFillColor(COL_WHITE);
124  pDev->SetLineColor(COL_WHITE);
125  }
126  else
127  {
128  pDev->SetFillColor(rStyleSettings.GetFieldTextColor()); //high contrast
129  pDev->SetLineColor(rStyleSettings.GetFieldTextColor()); //high contrast
130  }
131 
132  switch( nItemId )
133  {
134  case 1:
135  case 2:
136  case 3:
137  case 4:
138  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + nItemId * 2 - 1 ));
139  break;
140  case 5:
141  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
142  pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 4 ));
143  break;
144  case 6:
145  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
146  pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
147  break;
148  case 7:
149  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 1 ));
150  pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 3 , nTRX, nTRY + 6 ));
151  break;
152  case 8:
153  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
154  pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 6 ));
155  break;
156  case 9:
157  pDev->DrawRect(tools::Rectangle(nTLX, nTLY , nTRX, nTRY + 3 ));
158  pDev->DrawRect(tools::Rectangle(nTLX, nTLY + 5 , nTRX, nTRY + 8 ));
159  break;
160  }
161 
162  Invalidate( aRect );
163  pDev->SetLineColor(aOldColor);
164  pDev->SetFillColor(aOldFillColor);
165  pDev->SetFont(aOldFont);
166 
167 }
168 
169 } // end of namespace sc::sidebar
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
static vcl::Font GetDefaultFont(DefaultFontType nType, LanguageType eLang, GetDefaultFontFlags nFlags, const OutputDevice *pOutDev=nullptr)
void SetFontSize(const Size &)
#define CELL_LINE_STYLE_ENTRIES
const tools::Rectangle & GetRect() const
long Long
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void SetLineCount(sal_uInt16 nNewLines=0)
const Color & GetFieldTextColor() const
constexpr tools::Long Width() const
const vcl::Font & GetFont() const
constexpr tools::Long GetWidth() const
virtual OutputDevice & get_ref_device()=0
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
vcl::RenderContext * GetRenderContext() const
int i
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()
const Color & GetLineColor() const
const Size & GetFontSize() const
OUString maStrUnit[CELL_LINE_STYLE_ENTRIES]
void SetColor(const Color &)
sal_uInt16 GetItemId() const
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
void SelectItem(sal_uInt16 nItemId)
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
constexpr tools::Long Height() const
void SetNoSelection()
void SetFont(const vcl::Font &rNewFont)
void SetColCount(sal_uInt16 nNewCols=1)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
static LanguageType getConfiguredSystemLanguage()
void setHeight(tools::Long nHeight)
virtual void set_size_request(int nWidth, int nHeight)=0
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 GetHeight() const