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 <svx/sidebar/ValueSetWithTextControl.hxx>
20 #include <sfx2/sidebar/Theme.hxx>
21
22 #include <limits.h>
23 #include <i18nlangtag/mslangid.hxx>
24 #include <svtools/valueset.hxx>
25 #include <editeng/brushitem.hxx>
26 #include <vcl/graph.hxx>
27 #include <vcl/event.hxx>
28 #include <vcl/settings.hxx>
29
30 namespace svx { namespace sidebar {
31
ValueSetWithTextControl(Window * pParent,WinBits nBits)32 ValueSetWithTextControl::ValueSetWithTextControl(Window* pParent, WinBits nBits)
33 : ValueSet( pParent, nBits )
34 {
35 SetColCount();
36 }
37
38
AddItem(const OUString & rItemText,const OUString & rItemText2)39 void ValueSetWithTextControl::AddItem(
40 const OUString& rItemText,
41 const OUString& rItemText2 )
42 {
43 ValueSetWithTextItem aItem;
44 aItem.maItemText = rItemText;
45 aItem.maItemText2 = rItemText2;
46
47 maItems.push_back( aItem );
48
49 InsertItem( maItems.size() );
50 SetItemText( maItems.size(), rItemText );
51 }
52
UserDraw(const UserDrawEvent & rUDEvt)53 void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt )
54 {
55 const tools::Rectangle aRect = rUDEvt.GetRect();
56 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
57 pDev->Push();
58 const sal_uInt16 nItemId = rUDEvt.GetItemId();
59
60 const long nRectHeight = aRect.GetHeight();
61
62 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne));
63 {
64 Size aSize = aFont.GetFontSize();
65 aSize.setHeight( (nRectHeight*4)/9 );
66 aFont.SetFontSize( aSize );
67 }
68
69 {
70 //draw background
71 if ( GetSelectedItemId() == nItemId )
72 {
73 tools::Rectangle aBackRect = aRect;
74 aBackRect.AdjustTop(3 );
75 aBackRect.AdjustBottom( -2 );
76 pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) );
77 pDev->DrawRect(aBackRect);
78 }
79 else
80 {
81 pDev->SetFillColor( COL_TRANSPARENT );
82 pDev->DrawRect(aRect);
83 }
84
85 if ( GetSelectedItemId() == nItemId )
86 {
87 aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) );
88 }
89 else
90 {
91 aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
92 }
93
94 tools::Rectangle aStrRect = aRect;
95 aStrRect.AdjustTop(nRectHeight/4 );
96 aStrRect.AdjustBottom( -(nRectHeight/4) );
97
98 const long nRectWidth = aRect.GetWidth();
99 aStrRect.AdjustLeft(8 );
100 aStrRect.AdjustRight( -((nRectWidth*2)/3) );
101 pDev->SetFont(aFont);
102 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, DrawTextFlags::EndEllipsis);
103 aStrRect.AdjustLeft(nRectWidth/3 );
104 aStrRect.AdjustRight((nRectWidth*2)/3 );
105 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, DrawTextFlags::EndEllipsis);
106 }
107
108 Invalidate( aRect );
109 pDev->Pop();
110 }
111
112 } } // end of namespace svx::sidebar
113
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
115