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