LibreOffice Module svx (master)  1
ValueSetWithTextControl.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  */
20 #include <sfx2/sidebar/Theme.hxx>
21 
22 #include <i18nlangtag/mslangid.hxx>
23 #include <svtools/valueset.hxx>
24 #include <vcl/event.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 
28 namespace svx::sidebar {
29 
31  : ValueSet(nullptr)
32 {
33 }
34 
36 {
37  ValueSet::SetDrawingArea(pDrawingArea);
38 
39  Size aSize(250, 300);
40  pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
41  SetOutputSizePixel(aSize);
42 
43  SetColCount();
44 }
45 
47  const OUString& rItemText,
48  const OUString& rItemText2 )
49 {
51  aItem.maItemText = rItemText;
52  aItem.maItemText2 = rItemText2;
53 
54  maItems.push_back( aItem );
55 
56  InsertItem( maItems.size() );
57  SetItemText( maItems.size(), rItemText );
58 }
59 
61 {
62  const tools::Rectangle aRect = rUDEvt.GetRect();
63  vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
64  pDev->Push();
65  const sal_uInt16 nItemId = rUDEvt.GetItemId();
66 
67  const long nRectHeight = aRect.GetHeight();
68 
69  vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne));
70  {
71  Size aSize = aFont.GetFontSize();
72  aSize.setHeight( (nRectHeight*4)/9 );
73  aFont.SetFontSize( aSize );
74  }
75 
76  {
77  //draw background
78  if ( GetSelectedItemId() == nItemId )
79  {
80  tools::Rectangle aBackRect = aRect;
81  aBackRect.AdjustTop(3 );
82  aBackRect.AdjustBottom( -2 );
84  pDev->DrawRect(aBackRect);
85  }
86  else
87  {
89  pDev->DrawRect(aRect);
90  }
91 
92  if ( GetSelectedItemId() == nItemId )
93  {
95  }
96  else
97  {
98  aFont.SetColor( Application::GetSettings().GetStyleSettings().GetFieldTextColor() );
99  }
100 
101  tools::Rectangle aStrRect = aRect;
102  aStrRect.AdjustTop(nRectHeight/4 );
103  aStrRect.AdjustBottom( -(nRectHeight/4) );
104 
105  const long nRectWidth = aRect.GetWidth();
106  aStrRect.AdjustLeft(8 );
107  aStrRect.AdjustRight( -((nRectWidth*2)/3) );
108  pDev->SetFont(aFont);
109  pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, DrawTextFlags::EndEllipsis);
110  aStrRect.AdjustLeft(nRectWidth/3 );
111  aStrRect.AdjustRight((nRectWidth*2)/3 );
112  pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, DrawTextFlags::EndEllipsis);
113  }
114 
115  Invalidate( aRect );
116  pDev->Pop();
117 }
118 
119 } // end of namespace svx::sidebar
120 
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 &)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
const tools::Rectangle & GetRect() const
static Color GetColor(const ThemeItem eItem)
static const AllSettings & GetSettings()
tools::Long GetWidth() const
sal_uInt16 GetSelectedItemId() const
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
void DrawRect(const tools::Rectangle &rRect)
void AddItem(const OUString &rItemText, const OUString &rItemText2)
static LanguageType getSystemLanguage()
vcl::RenderContext * GetRenderContext() const
void SetFillColor()
tools::Long Width() const
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
const Size & GetFontSize() const
void SetItemText(sal_uInt16 nItemId, const OUString &rStr)
void SetColor(const Color &)
sal_uInt16 GetItemId() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
void SetFont(const vcl::Font &rNewFont)
void SetColCount(sal_uInt16 nNewCols=1)
tools::Long Height() const
void setHeight(tools::Long nHeight)
tools::Long GetHeight() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
::std::vector< ValueSetWithTextItem > maItems
virtual void set_size_request(int nWidth, int nHeight)=0
void Push(PushFlags nFlags=PushFlags::ALL)
virtual void UserDraw(const UserDrawEvent &rUDEvt) override