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 .
20 #include <comphelper/lok.hxx>
21 #include <vcl/outdev.hxx>
22 #include <vcl/decoview.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include <cbutton.hxx>
28 ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice
* pOutputDevice
)
29 : pOut( pOutputDevice
)
34 ScDDComboBoxButton::~ScDDComboBoxButton()
38 void ScDDComboBoxButton::SetOutputDevice( OutputDevice
* pOutputDevice
)
43 void ScDDComboBoxButton::SetOptSizePixel()
45 aBtnSize
= pOut
->LogicToPixel(Size(8, 11), MapMode(MapUnit::MapAppFont
));
46 aBtnSize
.setWidth( std::max(aBtnSize
.Width(), static_cast<tools::Long
>(pOut
->GetSettings().GetStyleSettings().GetScrollBarSize())) );
49 void ScDDComboBoxButton::Draw( const Point
& rAt
,
52 if ( rSize
.IsEmpty() )
56 bool bHadFill
= pOut
->IsFillColor();
57 Color aOldFill
= pOut
->GetFillColor();
58 bool bHadLine
= pOut
->IsLineColor();
59 Color aOldLine
= pOut
->GetLineColor();
60 bool bOldEnable
= pOut
->IsMapModeEnabled();
62 tools::Rectangle
aBtnRect( rAt
, rSize
);
64 if (!comphelper::LibreOfficeKit::isActive())
65 pOut
->EnableMapMode(false);
67 DecorationView
aDecoView( pOut
);
69 tools::Rectangle aInnerRect
=aDecoView
.DrawButton( aBtnRect
, DrawButtonFlags::Default
);
71 aInnerRect
.AdjustLeft(1 );
72 aInnerRect
.AdjustTop(1 );
73 aInnerRect
.AdjustRight( -1 );
74 aInnerRect
.AdjustBottom( -1 );
76 Size aInnerSize
= aInnerRect
.GetSize();
77 Point aInnerCenter
= aInnerRect
.Center();
79 aInnerRect
.SetTop( aInnerCenter
.Y() - (aInnerSize
.Width()>>1) );
80 aInnerRect
.SetBottom( aInnerCenter
.Y() + (aInnerSize
.Width()>>1) );
82 ImpDrawArrow( aInnerRect
);
85 pOut
->EnableMapMode( bOldEnable
);
87 pOut
->SetLineColor(aOldLine
);
91 pOut
->SetFillColor(aOldFill
);
96 void ScDDComboBoxButton::ImpDrawArrow( const tools::Rectangle
& rRect
)
98 // no need to save old line and fill color here (is restored after the call)
100 tools::Rectangle aPixRect
= rRect
;
101 Point aCenter
= aPixRect
.Center();
102 Size aSize
= aPixRect
.GetSize();
105 aSize3
.setWidth( aSize
.Width() >> 1 );
106 aSize3
.setHeight( aSize
.Height() >> 1 );
109 aSize4
.setWidth( aSize
.Width() >> 2 );
110 aSize4
.setHeight( aSize
.Height() >> 2 );
112 tools::Rectangle aTempRect
= aPixRect
;
114 const StyleSettings
& rSett
= Application::GetSettings().GetStyleSettings();
115 Color
aColor( rSett
.GetButtonTextColor() );
116 pOut
->SetFillColor( aColor
);
117 pOut
->SetLineColor( aColor
);
119 aTempRect
.SetLeft( aCenter
.X() - aSize4
.Width() );
120 aTempRect
.SetRight( aCenter
.X() + aSize4
.Width() );
121 aTempRect
.SetTop( aCenter
.Y() - aSize3
.Height() );
122 aTempRect
.SetBottom( aCenter
.Y() - 1 );
124 pOut
->DrawRect( aTempRect
);
126 Point
aPos1( aCenter
.X()-aSize3
.Width(), aCenter
.Y() );
127 Point
aPos2( aCenter
.X()+aSize3
.Width(), aCenter
.Y() );
128 while( aPos1
.X() <= aPos2
.X() )
130 pOut
->DrawLine( aPos1
, aPos2
);
131 aPos1
.AdjustX( 1 ); aPos2
.AdjustX( -1 );
132 aPos1
.AdjustY( 1 ); aPos2
.AdjustY( 1 );
135 pOut
->DrawLine( Point( aCenter
.X() - aSize3
.Width(), aPos1
.Y()+1 ),
136 Point( aCenter
.X() + aSize3
.Width(), aPos1
.Y()+1 ) );
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */