xref: /aoo41x/main/sc/source/ui/cctrl/cbuttonw.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/outdev.hxx>
28cdf0e10cSrcweir #include <vcl/window.hxx>
29cdf0e10cSrcweir #include <vcl/decoview.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include "cbutton.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //========================================================================
34cdf0e10cSrcweir //	class ScDDComboBoxButton
35cdf0e10cSrcweir //========================================================================
36cdf0e10cSrcweir 
ScDDComboBoxButton(OutputDevice * pOutputDevice)37cdf0e10cSrcweir ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice* pOutputDevice )
38cdf0e10cSrcweir 	:	pOut( pOutputDevice )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	SetOptSizePixel();
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // -------------------------------------------------------------------------
44cdf0e10cSrcweir 
~ScDDComboBoxButton()45cdf0e10cSrcweir __EXPORT ScDDComboBoxButton::~ScDDComboBoxButton()
46cdf0e10cSrcweir {
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // -------------------------------------------------------------------------
50cdf0e10cSrcweir 
SetOutputDevice(OutputDevice * pOutputDevice)51cdf0e10cSrcweir void ScDDComboBoxButton::SetOutputDevice( OutputDevice* pOutputDevice )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     pOut = pOutputDevice;
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -------------------------------------------------------------------------
57cdf0e10cSrcweir 
SetOptSizePixel()58cdf0e10cSrcweir void ScDDComboBoxButton::SetOptSizePixel()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	aBtnSize = pOut->LogicToPixel( Size(0,11), MAP_APPFONT );
61cdf0e10cSrcweir 	//aBtnSize.Width() = GetSystemMetrics( SM_CXVSCROLL ) - 1; // Win SDK-Funktion
62cdf0e10cSrcweir 	aBtnSize.Width() = pOut->GetSettings().GetStyleSettings().GetScrollBarSize();
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir // -------------------------------------------------------------------------
66cdf0e10cSrcweir 
Draw(const Point & rAt,const Size & rSize,sal_Bool bState,sal_Bool bBtnIn)67cdf0e10cSrcweir void ScDDComboBoxButton::Draw( const Point&	rAt,
68cdf0e10cSrcweir 							   const Size&	rSize,
69cdf0e10cSrcweir                                sal_Bool         bState,
70cdf0e10cSrcweir 							   sal_Bool			bBtnIn  /* = sal_False */ )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     if ( rSize.Width() == 0 || rSize.Height() == 0 )
73cdf0e10cSrcweir         return;     // #i43092# rectangle with size 0 would have RECT_EMPTY as end position
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	// save old state
76cdf0e10cSrcweir 	sal_Bool		bHadFill   = pOut->IsFillColor();
77cdf0e10cSrcweir 	Color		aOldFill   = pOut->GetFillColor();
78cdf0e10cSrcweir 	sal_Bool		bHadLine   = pOut->IsLineColor();
79cdf0e10cSrcweir 	Color		aOldLine   = pOut->GetLineColor();
80cdf0e10cSrcweir 	sal_Bool		bOldEnable = pOut->IsMapModeEnabled();
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	Size		aLogPix( 1, 1 );
83cdf0e10cSrcweir 	Rectangle	aBtnRect( rAt, rSize );
84cdf0e10cSrcweir 	Rectangle	aInnerRect = aBtnRect;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	pOut->EnableMapMode( sal_False );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	DecorationView aDecoView( pOut);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	sal_uInt16 nButtonStyle = BUTTON_DRAW_DEFAULT;
91cdf0e10cSrcweir 	if( bBtnIn )	// gedrueckt?
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		nButtonStyle = BUTTON_DRAW_PRESSED;
94cdf0e10cSrcweir 	}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	aInnerRect=aDecoView.DrawButton( aBtnRect, nButtonStyle );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	aInnerRect.Left()   += 1;
100cdf0e10cSrcweir 	aInnerRect.Top()    += 1;
101cdf0e10cSrcweir 	aInnerRect.Right()  -= 1;
102cdf0e10cSrcweir 	aInnerRect.Bottom() -= 1;
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	Size  aInnerSize   = aInnerRect.GetSize();
105cdf0e10cSrcweir 	Point aInnerCenter = aInnerRect.Center();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	aInnerRect.Top()   = aInnerCenter.Y() - (aInnerSize.Width()>>1);
108cdf0e10cSrcweir 	aInnerRect.Bottom()= aInnerCenter.Y() + (aInnerSize.Width()>>1);
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     ImpDrawArrow( aInnerRect, bState );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	// restore old state
114cdf0e10cSrcweir 	pOut->EnableMapMode( bOldEnable );
115cdf0e10cSrcweir 	if (bHadLine)
116cdf0e10cSrcweir 		pOut->SetLineColor(aOldLine);
117cdf0e10cSrcweir 	else
118cdf0e10cSrcweir 		pOut->SetLineColor();
119cdf0e10cSrcweir 	if (bHadFill)
120cdf0e10cSrcweir 		pOut->SetFillColor(aOldFill);
121cdf0e10cSrcweir 	else
122cdf0e10cSrcweir 		pOut->SetFillColor();
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //------------------------------------------------------------------------
126cdf0e10cSrcweir 
ImpDrawArrow(const Rectangle & rRect,sal_Bool bState)127cdf0e10cSrcweir void ScDDComboBoxButton::ImpDrawArrow( const Rectangle& rRect,
128cdf0e10cSrcweir                                        sal_Bool             bState )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	// no need to save old line and fill color here (is restored after the call)
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	Rectangle	aPixRect = rRect;
133cdf0e10cSrcweir 	Point		aCenter  = aPixRect.Center();
134cdf0e10cSrcweir 	Size      	aSize    = aPixRect.GetSize();
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	Size aSize3;
137cdf0e10cSrcweir 	aSize3.Width() = aSize.Width() >> 1;
138cdf0e10cSrcweir 	aSize3.Height() = aSize.Height() >> 1;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	Size aSize4;
141cdf0e10cSrcweir 	aSize4.Width() = aSize.Width() >> 2;
142cdf0e10cSrcweir 	aSize4.Height() = aSize.Height() >> 2;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	Rectangle aTempRect = aPixRect;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
147cdf0e10cSrcweir     Color aColor( bState ? COL_LIGHTBLUE : rSett.GetButtonTextColor().GetColor() );
148cdf0e10cSrcweir     pOut->SetFillColor( aColor );
149cdf0e10cSrcweir     pOut->SetLineColor( aColor );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	aTempRect.Left()   = aCenter.X() - aSize4.Width();
152cdf0e10cSrcweir 	aTempRect.Right()  = aCenter.X() + aSize4.Width();
153cdf0e10cSrcweir 	aTempRect.Top()    = aCenter.Y() - aSize3.Height();
154cdf0e10cSrcweir 	aTempRect.Bottom() = aCenter.Y() - 1;
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 	pOut->DrawRect( aTempRect );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	Point aPos1( aCenter.X()-aSize3.Width(), aCenter.Y() );
159cdf0e10cSrcweir 	Point aPos2( aCenter.X()+aSize3.Width(), aCenter.Y() );
160cdf0e10cSrcweir 	while( aPos1.X() <= aPos2.X() )
161cdf0e10cSrcweir 	{
162cdf0e10cSrcweir 		pOut->DrawLine( aPos1, aPos2 );
163cdf0e10cSrcweir 		aPos1.X()++; aPos2.X()--;
164cdf0e10cSrcweir 		aPos1.Y()++; aPos2.Y()++;
165cdf0e10cSrcweir 	}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	pOut->DrawLine( Point( aCenter.X() - aSize3.Width(), aPos1.Y()+1 ),
168cdf0e10cSrcweir 					Point( aCenter.X() + aSize3.Width(), aPos1.Y()+1 ) );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
175