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 .
21 #include <vcl/outdev.hxx>
22 #include <vcl/window.hxx>
23 #include <vcl/decoview.hxx>
24 #include <vcl/svapp.hxx>
25 #include "cbutton.hxx"
27 //========================================================================
28 // class ScDDComboBoxButton
29 //========================================================================
31 ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice
* pOutputDevice
)
32 : pOut( pOutputDevice
)
37 // -------------------------------------------------------------------------
39 ScDDComboBoxButton::~ScDDComboBoxButton()
43 // -------------------------------------------------------------------------
45 void ScDDComboBoxButton::SetOutputDevice( OutputDevice
* pOutputDevice
)
50 // -------------------------------------------------------------------------
52 void ScDDComboBoxButton::SetOptSizePixel()
54 aBtnSize
= pOut
->LogicToPixel( Size(0,11), MAP_APPFONT
);
55 //aBtnSize.Width() = GetSystemMetrics( SM_CXVSCROLL ) - 1; // Win SDK-Funktion
56 aBtnSize
.Width() = pOut
->GetSettings().GetStyleSettings().GetScrollBarSize();
59 // -------------------------------------------------------------------------
61 void ScDDComboBoxButton::Draw( const Point
& rAt
,
64 sal_Bool bBtnIn
/* = sal_False */ )
66 if ( rSize
.Width() == 0 || rSize
.Height() == 0 )
67 return; // #i43092# rectangle with size 0 would have RECT_EMPTY as end position
70 sal_Bool bHadFill
= pOut
->IsFillColor();
71 Color aOldFill
= pOut
->GetFillColor();
72 sal_Bool bHadLine
= pOut
->IsLineColor();
73 Color aOldLine
= pOut
->GetLineColor();
74 sal_Bool bOldEnable
= pOut
->IsMapModeEnabled();
76 Rectangle
aBtnRect( rAt
, rSize
);
77 Rectangle aInnerRect
= aBtnRect
;
79 pOut
->EnableMapMode( false );
81 DecorationView
aDecoView( pOut
);
83 sal_uInt16 nButtonStyle
= BUTTON_DRAW_DEFAULT
;
84 if( bBtnIn
) // gedrueckt?
86 nButtonStyle
= BUTTON_DRAW_PRESSED
;
89 aInnerRect
=aDecoView
.DrawButton( aBtnRect
, nButtonStyle
);
92 aInnerRect
.Left() += 1;
93 aInnerRect
.Top() += 1;
94 aInnerRect
.Right() -= 1;
95 aInnerRect
.Bottom() -= 1;
97 Size aInnerSize
= aInnerRect
.GetSize();
98 Point aInnerCenter
= aInnerRect
.Center();
100 aInnerRect
.Top() = aInnerCenter
.Y() - (aInnerSize
.Width()>>1);
101 aInnerRect
.Bottom()= aInnerCenter
.Y() + (aInnerSize
.Width()>>1);
103 ImpDrawArrow( aInnerRect
, bState
);
107 pOut
->EnableMapMode( bOldEnable
);
109 pOut
->SetLineColor(aOldLine
);
111 pOut
->SetLineColor();
113 pOut
->SetFillColor(aOldFill
);
115 pOut
->SetFillColor();
118 //------------------------------------------------------------------------
120 void ScDDComboBoxButton::ImpDrawArrow( const Rectangle
& rRect
,
123 // no need to save old line and fill color here (is restored after the call)
125 Rectangle aPixRect
= rRect
;
126 Point aCenter
= aPixRect
.Center();
127 Size aSize
= aPixRect
.GetSize();
130 aSize3
.Width() = aSize
.Width() >> 1;
131 aSize3
.Height() = aSize
.Height() >> 1;
134 aSize4
.Width() = aSize
.Width() >> 2;
135 aSize4
.Height() = aSize
.Height() >> 2;
137 Rectangle aTempRect
= aPixRect
;
139 const StyleSettings
& rSett
= Application::GetSettings().GetStyleSettings();
140 Color
aColor( bState
? COL_LIGHTBLUE
: rSett
.GetButtonTextColor().GetColor() );
141 pOut
->SetFillColor( aColor
);
142 pOut
->SetLineColor( aColor
);
144 aTempRect
.Left() = aCenter
.X() - aSize4
.Width();
145 aTempRect
.Right() = aCenter
.X() + aSize4
.Width();
146 aTempRect
.Top() = aCenter
.Y() - aSize3
.Height();
147 aTempRect
.Bottom() = aCenter
.Y() - 1;
149 pOut
->DrawRect( aTempRect
);
151 Point
aPos1( aCenter
.X()-aSize3
.Width(), aCenter
.Y() );
152 Point
aPos2( aCenter
.X()+aSize3
.Width(), aCenter
.Y() );
153 while( aPos1
.X() <= aPos2
.X() )
155 pOut
->DrawLine( aPos1
, aPos2
);
156 aPos1
.X()++; aPos2
.X()--;
157 aPos1
.Y()++; aPos2
.Y()++;
160 pOut
->DrawLine( Point( aCenter
.X() - aSize3
.Width(), aPos1
.Y()+1 ),
161 Point( aCenter
.X() + aSize3
.Width(), aPos1
.Y()+1 ) );
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */