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{
48 const vcl::Font aFont(Application::GetSettings().GetStyleSettings().GetLabelFont());
49 const sal_Int32 nRowHeight = aFont.GetFontSize().Height() * 9 / 4; // see UserDraw()
50 const Size aSize(GetOutputSizePixel().Width(), nRowHeight * maItems.size());
51 GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
52 SetOutputSizePixel(aSize);
53}
54
56 const OUString& rItemText,
57 const OUString& rItemText2 )
58{
60 aItem.maItemText = rItemText;
61 aItem.maItemText2 = rItemText2;
62
63 maItems.push_back( aItem );
64
65 InsertItem( maItems.size() );
66 SetItemText( maItems.size(), rItemText );
67}
68
70{
71 const tools::Rectangle aRect = rUDEvt.GetRect();
72 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
73 pDev->Push();
74 const sal_uInt16 nItemId = rUDEvt.GetItemId();
75
76 const tools::Long nRectHeight = aRect.GetHeight();
77
78 vcl::Font aFont(Application::GetSettings().GetStyleSettings().GetLabelFont());
79 {
80 Size aSize = aFont.GetFontSize();
81 aSize.setHeight( (nRectHeight*4)/9 );
82 aFont.SetFontSize( aSize );
83 }
84
85 {
86 //draw background
87 if ( GetSelectedItemId() == nItemId )
88 {
89 tools::Rectangle aBackRect = aRect;
90 aBackRect.AdjustTop(3 );
91 aBackRect.AdjustBottom( -2 );
93 pDev->DrawRect(aBackRect);
94 }
95 else
96 {
98 pDev->DrawRect(aRect);
99 }
100
101 if ( GetSelectedItemId() == nItemId )
102 {
104 }
105 else
106 {
107 aFont.SetColor( Application::GetSettings().GetStyleSettings().GetFieldTextColor() );
108 }
109
110 tools::Rectangle aStrRect = aRect;
111 aStrRect.AdjustTop(nRectHeight/4 );
112 aStrRect.AdjustBottom( -(nRectHeight/4) );
113
114 const tools::Long nRectWidth = aRect.GetWidth();
115 aStrRect.AdjustLeft(8 );
116 aStrRect.AdjustRight( -((nRectWidth*2)/3) );
117 pDev->SetFont(aFont);
118 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, DrawTextFlags::EndEllipsis);
119 aStrRect.AdjustLeft(nRectWidth/3 );
120 aStrRect.AdjustRight((nRectWidth*2)/3 );
121 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, DrawTextFlags::EndEllipsis);
122 }
123
124 Invalidate( aRect );
125 pDev->Pop();
126}
127
128} // end of namespace svx::sidebar
129
130/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
void SetFont(const vcl::Font &rNewFont)
void DrawRect(const tools::Rectangle &rRect)
void SetFillColor()
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
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