1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <svx/sidebar/ValueSetWithTextControl.hxx>
20 #include <sfx2/sidebar/Theme.hxx>
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>
28 namespace svx::sidebar
{
30 ValueSetWithTextControl::ValueSetWithTextControl()
35 void ValueSetWithTextControl::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
37 ValueSet::SetDrawingArea(pDrawingArea
);
40 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
41 SetOutputSizePixel(aSize
);
46 void ValueSetWithTextControl::AddItem(
47 const OUString
& rItemText
,
48 const OUString
& rItemText2
)
50 ValueSetWithTextItem aItem
;
51 aItem
.maItemText
= rItemText
;
52 aItem
.maItemText2
= rItemText2
;
54 maItems
.push_back( aItem
);
56 InsertItem( maItems
.size() );
57 SetItemText( maItems
.size(), rItemText
);
60 void ValueSetWithTextControl::UserDraw( const UserDrawEvent
& rUDEvt
)
62 const tools::Rectangle aRect
= rUDEvt
.GetRect();
63 vcl::RenderContext
* pDev
= rUDEvt
.GetRenderContext();
65 const sal_uInt16 nItemId
= rUDEvt
.GetItemId();
67 const tools::Long nRectHeight
= aRect
.GetHeight();
69 vcl::Font
aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS
, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne
));
71 Size aSize
= aFont
.GetFontSize();
72 aSize
.setHeight( (nRectHeight
*4)/9 );
73 aFont
.SetFontSize( aSize
);
78 if ( GetSelectedItemId() == nItemId
)
80 tools::Rectangle aBackRect
= aRect
;
81 aBackRect
.AdjustTop(3 );
82 aBackRect
.AdjustBottom( -2 );
83 pDev
->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight
) );
84 pDev
->DrawRect(aBackRect
);
88 pDev
->SetFillColor( COL_TRANSPARENT
);
89 pDev
->DrawRect(aRect
);
92 if ( GetSelectedItemId() == nItemId
)
94 aFont
.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText
) );
98 aFont
.SetColor( Application::GetSettings().GetStyleSettings().GetFieldTextColor() );
101 tools::Rectangle aStrRect
= aRect
;
102 aStrRect
.AdjustTop(nRectHeight
/4 );
103 aStrRect
.AdjustBottom( -(nRectHeight
/4) );
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
);
119 } // end of namespace svx::sidebar
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */