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 */
21
23#include <svtools/valueset.hxx>
24#include <vcl/event.hxx>
25#include <vcl/settings.hxx>
26#include <vcl/svapp.hxx>
27
28namespace 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
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 tools::Long nRectHeight = aRect.GetHeight();
68
69 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getConfiguredSystemLanguage(), 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 tools::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: */
static const AllSettings & GetSettings()
static LanguageType getConfiguredSystemLanguage()
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void SetFillColor()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
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)
constexpr tools::Long Height() const
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
sal_uInt16 GetItemId() const
void InsertItem(sal_uInt16 nItemId, const Image &rImage)
void SetItemText(sal_uInt16 nItemId, const OUString &rStr)
sal_uInt16 GetSelectedItemId() const
void SetColCount(sal_uInt16 nNewCols=1)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
static Color GetColor(const ThemeItem eItem)
void AddItem(const OUString &rItemText, const OUString &rItemText2)
virtual SVX_DLLPRIVATE void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
::std::vector< ValueSetWithTextItem > maItems
virtual SVX_DLLPRIVATE void UserDraw(const UserDrawEvent &rUDEvt) override
constexpr tools::Long GetWidth() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
constexpr tools::Long GetHeight() const
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
void SetFontSize(const Size &)
void SetColor(const Color &)
const Size & GetFontSize() const
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
long Long