Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <vcl/outdev.hxx>
22 : #include <vcl/window.hxx>
23 : #include <vcl/decoview.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <vcl/settings.hxx>
26 : #include "cbutton.hxx"
27 :
28 :
29 : // class ScDDComboBoxButton
30 :
31 :
32 226 : ScDDComboBoxButton::ScDDComboBoxButton( OutputDevice* pOutputDevice )
33 226 : : pOut( pOutputDevice )
34 : {
35 226 : SetOptSizePixel();
36 226 : }
37 :
38 222 : ScDDComboBoxButton::~ScDDComboBoxButton()
39 : {
40 222 : }
41 :
42 3158 : void ScDDComboBoxButton::SetOutputDevice( OutputDevice* pOutputDevice )
43 : {
44 3158 : pOut = pOutputDevice;
45 3158 : }
46 :
47 227 : void ScDDComboBoxButton::SetOptSizePixel()
48 : {
49 227 : aBtnSize = pOut->LogicToPixel( Size(0,11), MAP_APPFONT );
50 : //aBtnSize.Width() = GetSystemMetrics( SM_CXVSCROLL ) - 1; // Win SDK-Funktion
51 227 : aBtnSize.Width() = pOut->GetSettings().GetStyleSettings().GetScrollBarSize();
52 227 : }
53 :
54 1 : void ScDDComboBoxButton::Draw( const Point& rAt,
55 : const Size& rSize,
56 : bool bState,
57 : bool bBtnIn /* = false */ )
58 : {
59 1 : if ( rSize.Width() == 0 || rSize.Height() == 0 )
60 1 : return; // #i43092# rectangle with size 0 would have RECT_EMPTY as end position
61 :
62 : // save old state
63 1 : sal_Bool bHadFill = pOut->IsFillColor();
64 1 : Color aOldFill = pOut->GetFillColor();
65 1 : sal_Bool bHadLine = pOut->IsLineColor();
66 1 : Color aOldLine = pOut->GetLineColor();
67 1 : sal_Bool bOldEnable = pOut->IsMapModeEnabled();
68 :
69 1 : Rectangle aBtnRect( rAt, rSize );
70 1 : Rectangle aInnerRect = aBtnRect;
71 :
72 1 : pOut->EnableMapMode( false );
73 :
74 1 : DecorationView aDecoView( pOut);
75 :
76 1 : sal_uInt16 nButtonStyle = BUTTON_DRAW_DEFAULT;
77 1 : if( bBtnIn ) // gedrueckt?
78 : {
79 0 : nButtonStyle = BUTTON_DRAW_PRESSED;
80 : }
81 :
82 1 : aInnerRect=aDecoView.DrawButton( aBtnRect, nButtonStyle );
83 :
84 :
85 1 : aInnerRect.Left() += 1;
86 1 : aInnerRect.Top() += 1;
87 1 : aInnerRect.Right() -= 1;
88 1 : aInnerRect.Bottom() -= 1;
89 :
90 1 : Size aInnerSize = aInnerRect.GetSize();
91 1 : Point aInnerCenter = aInnerRect.Center();
92 :
93 1 : aInnerRect.Top() = aInnerCenter.Y() - (aInnerSize.Width()>>1);
94 1 : aInnerRect.Bottom()= aInnerCenter.Y() + (aInnerSize.Width()>>1);
95 :
96 1 : ImpDrawArrow( aInnerRect, bState );
97 :
98 :
99 : // restore old state
100 1 : pOut->EnableMapMode( bOldEnable );
101 1 : if (bHadLine)
102 0 : pOut->SetLineColor(aOldLine);
103 : else
104 1 : pOut->SetLineColor();
105 1 : if (bHadFill)
106 1 : pOut->SetFillColor(aOldFill);
107 : else
108 0 : pOut->SetFillColor();
109 : }
110 :
111 1 : void ScDDComboBoxButton::ImpDrawArrow( const Rectangle& rRect,
112 : bool bState )
113 : {
114 : // no need to save old line and fill color here (is restored after the call)
115 :
116 1 : Rectangle aPixRect = rRect;
117 1 : Point aCenter = aPixRect.Center();
118 1 : Size aSize = aPixRect.GetSize();
119 :
120 1 : Size aSize3;
121 1 : aSize3.Width() = aSize.Width() >> 1;
122 1 : aSize3.Height() = aSize.Height() >> 1;
123 :
124 1 : Size aSize4;
125 1 : aSize4.Width() = aSize.Width() >> 2;
126 1 : aSize4.Height() = aSize.Height() >> 2;
127 :
128 1 : Rectangle aTempRect = aPixRect;
129 :
130 1 : const StyleSettings& rSett = Application::GetSettings().GetStyleSettings();
131 1 : Color aColor( bState ? COL_LIGHTBLUE : rSett.GetButtonTextColor().GetColor() );
132 1 : pOut->SetFillColor( aColor );
133 1 : pOut->SetLineColor( aColor );
134 :
135 1 : aTempRect.Left() = aCenter.X() - aSize4.Width();
136 1 : aTempRect.Right() = aCenter.X() + aSize4.Width();
137 1 : aTempRect.Top() = aCenter.Y() - aSize3.Height();
138 1 : aTempRect.Bottom() = aCenter.Y() - 1;
139 :
140 1 : pOut->DrawRect( aTempRect );
141 :
142 1 : Point aPos1( aCenter.X()-aSize3.Width(), aCenter.Y() );
143 1 : Point aPos2( aCenter.X()+aSize3.Width(), aCenter.Y() );
144 6 : while( aPos1.X() <= aPos2.X() )
145 : {
146 4 : pOut->DrawLine( aPos1, aPos2 );
147 4 : aPos1.X()++; aPos2.X()--;
148 4 : aPos1.Y()++; aPos2.Y()++;
149 : }
150 :
151 3 : pOut->DrawLine( Point( aCenter.X() - aSize3.Width(), aPos1.Y()+1 ),
152 4 : Point( aCenter.X() + aSize3.Width(), aPos1.Y()+1 ) );
153 1 : }
154 :
155 :
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|