1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <vcl/outdev.hxx> 32*cdf0e10cSrcweir #include <vcl/window.hxx> 33*cdf0e10cSrcweir #include <vcl/decoview.hxx> 34*cdf0e10cSrcweir #include <vcl/svapp.hxx> 35*cdf0e10cSrcweir #include "cbutton.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir //======================================================================== 38*cdf0e10cSrcweir // class ScDDComboBoxButton 39*cdf0e10cSrcweir //======================================================================== 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice* pOutputDevice ) 42*cdf0e10cSrcweir : pOut( pOutputDevice ) 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir SetOptSizePixel(); 45*cdf0e10cSrcweir } 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir // ------------------------------------------------------------------------- 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir __EXPORT ScDDComboBoxButton::~ScDDComboBoxButton() 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // ------------------------------------------------------------------------- 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir void ScDDComboBoxButton::SetOutputDevice( OutputDevice* pOutputDevice ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir pOut = pOutputDevice; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ------------------------------------------------------------------------- 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir void ScDDComboBoxButton::SetOptSizePixel() 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir aBtnSize = pOut->LogicToPixel( Size(0,11), MAP_APPFONT ); 65*cdf0e10cSrcweir //aBtnSize.Width() = GetSystemMetrics( SM_CXVSCROLL ) - 1; // Win SDK-Funktion 66*cdf0e10cSrcweir aBtnSize.Width() = pOut->GetSettings().GetStyleSettings().GetScrollBarSize(); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir // ------------------------------------------------------------------------- 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void ScDDComboBoxButton::Draw( const Point& rAt, 72*cdf0e10cSrcweir const Size& rSize, 73*cdf0e10cSrcweir sal_Bool bState, 74*cdf0e10cSrcweir sal_Bool bBtnIn /* = sal_False */ ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir if ( rSize.Width() == 0 || rSize.Height() == 0 ) 77*cdf0e10cSrcweir return; // #i43092# rectangle with size 0 would have RECT_EMPTY as end position 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // save old state 80*cdf0e10cSrcweir sal_Bool bHadFill = pOut->IsFillColor(); 81*cdf0e10cSrcweir Color aOldFill = pOut->GetFillColor(); 82*cdf0e10cSrcweir sal_Bool bHadLine = pOut->IsLineColor(); 83*cdf0e10cSrcweir Color aOldLine = pOut->GetLineColor(); 84*cdf0e10cSrcweir sal_Bool bOldEnable = pOut->IsMapModeEnabled(); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir Size aLogPix( 1, 1 ); 87*cdf0e10cSrcweir Rectangle aBtnRect( rAt, rSize ); 88*cdf0e10cSrcweir Rectangle aInnerRect = aBtnRect; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir pOut->EnableMapMode( sal_False ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir DecorationView aDecoView( pOut); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir sal_uInt16 nButtonStyle = BUTTON_DRAW_DEFAULT; 95*cdf0e10cSrcweir if( bBtnIn ) // gedrueckt? 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir nButtonStyle = BUTTON_DRAW_PRESSED; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir aInnerRect=aDecoView.DrawButton( aBtnRect, nButtonStyle ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir aInnerRect.Left() += 1; 104*cdf0e10cSrcweir aInnerRect.Top() += 1; 105*cdf0e10cSrcweir aInnerRect.Right() -= 1; 106*cdf0e10cSrcweir aInnerRect.Bottom() -= 1; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir Size aInnerSize = aInnerRect.GetSize(); 109*cdf0e10cSrcweir Point aInnerCenter = aInnerRect.Center(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir aInnerRect.Top() = aInnerCenter.Y() - (aInnerSize.Width()>>1); 112*cdf0e10cSrcweir aInnerRect.Bottom()= aInnerCenter.Y() + (aInnerSize.Width()>>1); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir ImpDrawArrow( aInnerRect, bState ); 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // restore old state 118*cdf0e10cSrcweir pOut->EnableMapMode( bOldEnable ); 119*cdf0e10cSrcweir if (bHadLine) 120*cdf0e10cSrcweir pOut->SetLineColor(aOldLine); 121*cdf0e10cSrcweir else 122*cdf0e10cSrcweir pOut->SetLineColor(); 123*cdf0e10cSrcweir if (bHadFill) 124*cdf0e10cSrcweir pOut->SetFillColor(aOldFill); 125*cdf0e10cSrcweir else 126*cdf0e10cSrcweir pOut->SetFillColor(); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //------------------------------------------------------------------------ 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir void ScDDComboBoxButton::ImpDrawArrow( const Rectangle& rRect, 132*cdf0e10cSrcweir sal_Bool bState ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir // no need to save old line and fill color here (is restored after the call) 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir Rectangle aPixRect = rRect; 137*cdf0e10cSrcweir Point aCenter = aPixRect.Center(); 138*cdf0e10cSrcweir Size aSize = aPixRect.GetSize(); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir Size aSize3; 141*cdf0e10cSrcweir aSize3.Width() = aSize.Width() >> 1; 142*cdf0e10cSrcweir aSize3.Height() = aSize.Height() >> 1; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir Size aSize4; 145*cdf0e10cSrcweir aSize4.Width() = aSize.Width() >> 2; 146*cdf0e10cSrcweir aSize4.Height() = aSize.Height() >> 2; 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir Rectangle aTempRect = aPixRect; 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir const StyleSettings& rSett = Application::GetSettings().GetStyleSettings(); 151*cdf0e10cSrcweir Color aColor( bState ? COL_LIGHTBLUE : rSett.GetButtonTextColor().GetColor() ); 152*cdf0e10cSrcweir pOut->SetFillColor( aColor ); 153*cdf0e10cSrcweir pOut->SetLineColor( aColor ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir aTempRect.Left() = aCenter.X() - aSize4.Width(); 156*cdf0e10cSrcweir aTempRect.Right() = aCenter.X() + aSize4.Width(); 157*cdf0e10cSrcweir aTempRect.Top() = aCenter.Y() - aSize3.Height(); 158*cdf0e10cSrcweir aTempRect.Bottom() = aCenter.Y() - 1; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir pOut->DrawRect( aTempRect ); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir Point aPos1( aCenter.X()-aSize3.Width(), aCenter.Y() ); 163*cdf0e10cSrcweir Point aPos2( aCenter.X()+aSize3.Width(), aCenter.Y() ); 164*cdf0e10cSrcweir while( aPos1.X() <= aPos2.X() ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir pOut->DrawLine( aPos1, aPos2 ); 167*cdf0e10cSrcweir aPos1.X()++; aPos2.X()--; 168*cdf0e10cSrcweir aPos1.Y()++; aPos2.Y()++; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir pOut->DrawLine( Point( aCenter.X() - aSize3.Width(), aPos1.Y()+1 ), 172*cdf0e10cSrcweir Point( aCenter.X() + aSize3.Width(), aPos1.Y()+1 ) ); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179