Update ooo320-m1
[ooovba.git] / sc / source / ui / cctrl / cbuttonw.cxx
bloba0881397145e8f9489080a8db30887f53ef7142c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cbuttonw.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <vcl/outdev.hxx>
35 #include <vcl/window.hxx>
36 #include <vcl/decoview.hxx>
37 #include <vcl/svapp.hxx>
38 #include "cbutton.hxx"
40 //========================================================================
41 // class ScDDComboBoxButton
42 //========================================================================
44 ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice* pOutputDevice )
45 : pOut( pOutputDevice )
47 SetOptSizePixel();
50 // -------------------------------------------------------------------------
52 __EXPORT ScDDComboBoxButton::~ScDDComboBoxButton()
56 // -------------------------------------------------------------------------
58 void ScDDComboBoxButton::SetOutputDevice( OutputDevice* pOutputDevice )
60 pOut = pOutputDevice;
63 // -------------------------------------------------------------------------
65 void ScDDComboBoxButton::SetOptSizePixel()
67 aBtnSize = pOut->LogicToPixel( Size(0,11), MAP_APPFONT );
68 //aBtnSize.Width() = GetSystemMetrics( SM_CXVSCROLL ) - 1; // Win SDK-Funktion
69 aBtnSize.Width() = pOut->GetSettings().GetStyleSettings().GetScrollBarSize();
72 // -------------------------------------------------------------------------
74 void ScDDComboBoxButton::Draw( const Point& rAt,
75 const Size& rSize,
76 BOOL bState,
77 BOOL bBtnIn /* = FALSE */ )
79 if ( rSize.Width() == 0 || rSize.Height() == 0 )
80 return; // #i43092# rectangle with size 0 would have RECT_EMPTY as end position
82 // save old state
83 BOOL bHadFill = pOut->IsFillColor();
84 Color aOldFill = pOut->GetFillColor();
85 BOOL bHadLine = pOut->IsLineColor();
86 Color aOldLine = pOut->GetLineColor();
87 BOOL bOldEnable = pOut->IsMapModeEnabled();
89 Size aLogPix( 1, 1 );
90 Rectangle aBtnRect( rAt, rSize );
91 Rectangle aInnerRect = aBtnRect;
93 pOut->EnableMapMode( FALSE );
95 DecorationView aDecoView( pOut);
97 USHORT nButtonStyle = BUTTON_DRAW_DEFAULT;
98 if( bBtnIn ) // gedrueckt?
100 nButtonStyle = BUTTON_DRAW_PRESSED;
103 aInnerRect=aDecoView.DrawButton( aBtnRect, nButtonStyle );
106 aInnerRect.Left() += 1;
107 aInnerRect.Top() += 1;
108 aInnerRect.Right() -= 1;
109 aInnerRect.Bottom() -= 1;
111 Size aInnerSize = aInnerRect.GetSize();
112 Point aInnerCenter = aInnerRect.Center();
114 aInnerRect.Top() = aInnerCenter.Y() - (aInnerSize.Width()>>1);
115 aInnerRect.Bottom()= aInnerCenter.Y() + (aInnerSize.Width()>>1);
117 ImpDrawArrow( aInnerRect, bState );
120 // restore old state
121 pOut->EnableMapMode( bOldEnable );
122 if (bHadLine)
123 pOut->SetLineColor(aOldLine);
124 else
125 pOut->SetLineColor();
126 if (bHadFill)
127 pOut->SetFillColor(aOldFill);
128 else
129 pOut->SetFillColor();
132 //------------------------------------------------------------------------
134 void ScDDComboBoxButton::ImpDrawArrow( const Rectangle& rRect,
135 BOOL bState )
137 // no need to save old line and fill color here (is restored after the call)
139 Rectangle aPixRect = rRect;
140 Point aCenter = aPixRect.Center();
141 Size aSize = aPixRect.GetSize();
143 Size aSize3;
144 aSize3.Width() = aSize.Width() >> 1;
145 aSize3.Height() = aSize.Height() >> 1;
147 Size aSize4;
148 aSize4.Width() = aSize.Width() >> 2;
149 aSize4.Height() = aSize.Height() >> 2;
151 Rectangle aTempRect = aPixRect;
153 const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
154 Color aColor( bState ? COL_LIGHTBLUE : rSett.GetButtonTextColor().GetColor() );
155 pOut->SetFillColor( aColor );
156 pOut->SetLineColor( aColor );
158 aTempRect.Left() = aCenter.X() - aSize4.Width();
159 aTempRect.Right() = aCenter.X() + aSize4.Width();
160 aTempRect.Top() = aCenter.Y() - aSize3.Height();
161 aTempRect.Bottom() = aCenter.Y() - 1;
163 pOut->DrawRect( aTempRect );
165 Point aPos1( aCenter.X()-aSize3.Width(), aCenter.Y() );
166 Point aPos2( aCenter.X()+aSize3.Width(), aCenter.Y() );
167 while( aPos1.X() <= aPos2.X() )
169 pOut->DrawLine( aPos1, aPos2 );
170 aPos1.X()++; aPos2.X()--;
171 aPos1.Y()++; aPos2.Y()++;
174 pOut->DrawLine( Point( aCenter.X() - aSize3.Width(), aPos1.Y()+1 ),
175 Point( aCenter.X() + aSize3.Width(), aPos1.Y()+1 ) );