LibreOffice Module svx (master)  1
LineWidthValueSet.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 #include "LineWidthValueSet.hxx"
20 
21 #include <i18nlangtag/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/svapp.hxx>
25 
26 namespace svx::sidebar {
27 
29  : ValueSet(nullptr)
30  , nSelItem(0)
31  , bCusEnable(false)
32 {
33 }
34 
36 {
37  SetColCount();
38  SetLineCount(9);
40 }
41 
43 {
44 }
45 
46 void LineWidthValueSet::SetUnit(std::array<OUString,9> const & strUnits)
47 {
48  maStrUnits = strUnits;
49 }
50 
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
58  }
59  else
60  {
62  GrabFocus();
63  }
64 }
65 
67 {
68  imgCus = img;
69 }
70 
72 {
73  bCusEnable = bEnable;
74 }
75 
77 {
78  tools::Rectangle aRect = rUDEvt.GetRect();
79  vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
80  sal_uInt16 nItemId = rUDEvt.GetItemId();
81 
82  tools::Long nRectHeight = aRect.GetHeight();
83  tools::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 
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(Application::GetSettings().GetStyleSettings().GetFieldTextColor());
111  else
112  aFont.SetColor(Application::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(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
141 
142  //draw line
143  if( nSelItem == nItemId )
144  pDev->SetLineColor(COL_WHITE);
145  else
146  pDev->SetLineColor(Application::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 
163 {
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);
168 }
169 
170 } // end of namespace svx::sidebar
171 
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
Size GetSizePixel() const
void DrawText(const Point &rStartPt, const OUString &rStr, sal_Int32 nIndex=0, sal_Int32 nLen=-1, MetricVector *pVector=nullptr, OUString *pDisplayText=nullptr, const SalLayoutGlyphs *pLayoutCache=nullptr)
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 &)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
const tools::Rectangle & GetRect() const
long Long
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
static const AllSettings & GetSettings()
tools::Long GetWidth() const
void SetLineCount(sal_uInt16 nNewLines=0)
const vcl::Font & GetFont() const
virtual void Resize() override
virtual OutputDevice & get_ref_device()=0
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void DrawLine(const Point &rStartPt, const Point &rEndPt)
void DrawRect(const tools::Rectangle &rRect)
static LanguageType getSystemLanguage()
void SetLineColor()
vcl::RenderContext * GetRenderContext() const
int i
void SetFillColor()
tools::Long Width() const
const Color & GetLineColor() const
const Size & GetFontSize() const
void SetUnit(std::array< OUString, 9 > const &strUnits)
void SetColor(const Color &)
sal_uInt16 GetItemId() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
void SelectItem(sal_uInt16 nItemId)
Point LogicToPixel(const Point &rLogicPt) const
void SetNoSelection()
void SetFont(const vcl::Font &rNewFont)
virtual void Resize() override
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
void SetColCount(sal_uInt16 nNewCols=1)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
void setHeight(tools::Long nHeight)
tools::Long GetHeight() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
virtual void set_size_request(int nWidth, int nHeight)=0
const Color & GetFillColor() const
std::array< OUString, 9 > maStrUnits