bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / sidebar / tools / ValueSetWithTextControl.cxx
blob80bceaeda36245d0fdaeeda31618548ca034947b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/dialogs.hrc>
21 #include <svx/dialmgr.hxx>
22 #include <sfx2/sidebar/Theme.hxx>
24 #include <limits.h>
25 #include <i18nlangtag/mslangid.hxx>
26 #include <svtools/valueset.hxx>
27 #include <editeng/brushitem.hxx>
28 #include <vcl/graph.hxx>
29 #include <vcl/settings.hxx>
31 namespace svx { namespace sidebar {
33 ValueSetWithTextControl::ValueSetWithTextControl(
34 const tControlType eControlType,
35 vcl::Window* pParent,
36 const ResId& rResId)
37 : ValueSet( pParent, rResId )
38 , meControlType( eControlType )
39 , maItems()
41 SetColCount( 1 );
44 void ValueSetWithTextControl::AddItem(
45 const Image& rItemImage,
46 const Image* pSelectedItemImage,
47 const OUString& rItemText,
48 const OUString* pItemHelpText )
50 if ( meControlType != IMAGE_TEXT )
52 return;
55 ValueSetWithTextItem aItem;
56 aItem.maItemImage = rItemImage;
57 aItem.maSelectedItemImage = (pSelectedItemImage != 0)
58 ? *pSelectedItemImage
59 : rItemImage;
61 if ( GetDPIScaleFactor() > 1 )
63 BitmapEx b = aItem.maItemImage.GetBitmapEx();
64 b.Scale(GetDPIScaleFactor(), GetDPIScaleFactor());
65 aItem.maItemImage = Image(b);
67 if ( pSelectedItemImage != 0 )
69 b = aItem.maSelectedItemImage.GetBitmapEx();
70 b.Scale(GetDPIScaleFactor(), GetDPIScaleFactor());
71 aItem.maSelectedItemImage = Image(b);
75 aItem.maItemText = rItemText;
77 maItems.push_back( aItem );
79 InsertItem( maItems.size() );
80 SetItemText( maItems.size(),
81 (pItemHelpText != 0) ? *pItemHelpText : rItemText );
85 void ValueSetWithTextControl::AddItem(
86 const OUString& rItemText,
87 const OUString& rItemText2,
88 const OUString* pItemHelpText )
90 if ( meControlType != TEXT_TEXT )
92 return;
95 ValueSetWithTextItem aItem;
96 aItem.maItemText = rItemText;
97 aItem.maItemText2 = rItemText2;
99 maItems.push_back( aItem );
101 InsertItem( maItems.size() );
102 SetItemText( maItems.size(),
103 (pItemHelpText != 0) ? *pItemHelpText : rItemText );
107 void ValueSetWithTextControl::ReplaceItemImages(
108 const sal_uInt16 nItemId,
109 const Image& rItemImage,
110 const Image* pSelectedItemImage )
112 if ( meControlType != IMAGE_TEXT )
114 return;
117 if ( nItemId == 0 ||
118 nItemId > maItems.size() )
120 return;
123 maItems[nItemId-1].maItemImage = rItemImage;
124 maItems[nItemId-1].maSelectedItemImage = (pSelectedItemImage != 0)
125 ? *pSelectedItemImage
126 : rItemImage;
128 //#ifndef MACOSX
129 if ( GetDPIScaleFactor() > 1 )
131 BitmapEx b = maItems[nItemId-1].maItemImage.GetBitmapEx();
132 b.Scale(GetDPIScaleFactor(), GetDPIScaleFactor());
133 maItems[nItemId-1].maItemImage = Image(b);
135 if ( pSelectedItemImage != 0 )
137 b = maItems[nItemId-1].maSelectedItemImage.GetBitmapEx();
138 b.Scale(GetDPIScaleFactor(), GetDPIScaleFactor());
139 maItems[nItemId-1].maSelectedItemImage = Image(b);
142 //#endif
146 void ValueSetWithTextControl::UserDraw( const UserDrawEvent& rUDEvt )
148 const Rectangle aRect = rUDEvt.GetRect();
149 vcl::RenderContext* pDev = rUDEvt.GetRenderContext();
150 pDev->Push( PushFlags::ALL );
151 const sal_uInt16 nItemId = rUDEvt.GetItemId();
153 const long nRectHeight = aRect.GetHeight();
154 const Point aBLPos = aRect.TopLeft();
156 vcl::Font aFont(OutputDevice::GetDefaultFont(DefaultFontType::UI_SANS, MsLangId::getSystemLanguage(), GetDefaultFontFlags::OnlyOne));
158 Size aSize = aFont.GetSize();
159 aSize.Height() = (nRectHeight*4)/9;
160 aFont.SetSize( aSize );
164 //draw background
165 if ( GetSelectItemId() == nItemId )
167 Rectangle aBackRect = aRect;
168 aBackRect.Top() += 3;
169 aBackRect.Bottom() -= 2;
170 pDev->SetFillColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_Highlight ) );
171 pDev->DrawRect(aBackRect);
173 else
175 pDev->SetFillColor( COL_TRANSPARENT );
176 pDev->DrawRect(aRect);
179 //draw image + text resp. text + text
180 Image* pImage = 0;
181 if ( GetSelectItemId() == nItemId )
183 aFont.SetColor( sfx2::sidebar::Theme::GetColor( sfx2::sidebar::Theme::Color_HighlightText ) );
184 pImage = &maItems[nItemId-1].maSelectedItemImage;
186 else
188 aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
189 pImage = &maItems[nItemId-1].maItemImage;
192 Rectangle aStrRect = aRect;
193 aStrRect.Top() += nRectHeight/4;
194 aStrRect.Bottom() -= nRectHeight/4;
196 switch ( meControlType )
198 case IMAGE_TEXT:
200 Point aImgStart(
201 aBLPos.X() + 4,
202 aBLPos.Y() + ( ( nRectHeight - pImage->GetSizePixel().Height() ) / 2 ) );
203 pDev->DrawImage( aImgStart, *pImage );
205 aStrRect.Left() += pImage->GetSizePixel().Width() + 12;
206 pDev->SetFont(aFont);
207 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, DrawTextFlags::EndEllipsis);
209 break;
210 case TEXT_TEXT:
212 const long nRectWidth = aRect.GetWidth();
213 aStrRect.Left() += 8;
214 aStrRect.Right() -= (nRectWidth*2)/3;
215 pDev->SetFont(aFont);
216 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText, DrawTextFlags::EndEllipsis);
217 aStrRect.Left() += nRectWidth/3;
218 aStrRect.Right() += (nRectWidth*2)/3;
219 pDev->DrawText(aStrRect, maItems[nItemId-1].maItemText2, DrawTextFlags::EndEllipsis);
221 break;
225 Invalidate( aRect );
226 pDev->Pop();
229 } } // end of namespace svx::sidebar
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */