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