xref: /AOO41X/main/vcl/source/control/button.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <tools/poly.hxx>
33*cdf0e10cSrcweir #include <tools/rc.h>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <vcl/image.hxx>
36*cdf0e10cSrcweir #include <vcl/bitmap.hxx>
37*cdf0e10cSrcweir #include <vcl/bitmapex.hxx>
38*cdf0e10cSrcweir #include <vcl/decoview.hxx>
39*cdf0e10cSrcweir #include <vcl/event.hxx>
40*cdf0e10cSrcweir #include <vcl/svapp.hxx>
41*cdf0e10cSrcweir #include <vcl/dialog.hxx>
42*cdf0e10cSrcweir #include <vcl/fixed.hxx>
43*cdf0e10cSrcweir #include <vcl/button.hxx>
44*cdf0e10cSrcweir #include <vcl/salnativewidgets.hxx>
45*cdf0e10cSrcweir #include <vcl/edit.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <svids.hrc>
48*cdf0e10cSrcweir #include <svdata.hxx>
49*cdf0e10cSrcweir #include <window.h>
50*cdf0e10cSrcweir #include <controldata.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // =======================================================================
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define PUSHBUTTON_VIEW_STYLE       (WB_3DLOOK |                        \
55*cdf0e10cSrcweir                                      WB_LEFT | WB_CENTER | WB_RIGHT |   \
56*cdf0e10cSrcweir                                      WB_TOP | WB_VCENTER | WB_BOTTOM |  \
57*cdf0e10cSrcweir                                      WB_WORDBREAK | WB_NOLABEL |        \
58*cdf0e10cSrcweir                                      WB_DEFBUTTON | WB_NOLIGHTBORDER |  \
59*cdf0e10cSrcweir                                      WB_RECTSTYLE | WB_SMALLSTYLE |     \
60*cdf0e10cSrcweir                                      WB_TOGGLE )
61*cdf0e10cSrcweir #define RADIOBUTTON_VIEW_STYLE      (WB_3DLOOK |                        \
62*cdf0e10cSrcweir                                      WB_LEFT | WB_CENTER | WB_RIGHT |   \
63*cdf0e10cSrcweir                                      WB_TOP | WB_VCENTER | WB_BOTTOM |  \
64*cdf0e10cSrcweir                                      WB_WORDBREAK | WB_NOLABEL)
65*cdf0e10cSrcweir #define CHECKBOX_VIEW_STYLE         (WB_3DLOOK |                        \
66*cdf0e10cSrcweir                                      WB_LEFT | WB_CENTER | WB_RIGHT |   \
67*cdf0e10cSrcweir                                      WB_TOP | WB_VCENTER | WB_BOTTOM |  \
68*cdf0e10cSrcweir                                      WB_WORDBREAK | WB_NOLABEL)
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // =======================================================================
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir class ImplCommonButtonData
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir public:
75*cdf0e10cSrcweir     Rectangle       maFocusRect;
76*cdf0e10cSrcweir     Rectangle       maSymbolRect;
77*cdf0e10cSrcweir     sal_uInt16          mnButtonState;
78*cdf0e10cSrcweir     sal_Bool            mbSmallSymbol;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     Image           maImage;
81*cdf0e10cSrcweir     Image           maImageHC;
82*cdf0e10cSrcweir     BitmapEx*       mpBitmapEx;
83*cdf0e10cSrcweir     BitmapEx*       mpBitmapExHC;
84*cdf0e10cSrcweir     ImageAlign      meImageAlign;
85*cdf0e10cSrcweir     SymbolAlign     meSymbolAlign;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir public:
88*cdf0e10cSrcweir                     ImplCommonButtonData();
89*cdf0e10cSrcweir                    ~ImplCommonButtonData();
90*cdf0e10cSrcweir };
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir // -----------------------------------------------------------------------
93*cdf0e10cSrcweir ImplCommonButtonData::ImplCommonButtonData()
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     mnButtonState   = 0;
96*cdf0e10cSrcweir     mbSmallSymbol = sal_False;
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     mpBitmapEx = NULL;
99*cdf0e10cSrcweir     mpBitmapExHC = NULL;
100*cdf0e10cSrcweir     meImageAlign = IMAGEALIGN_TOP;
101*cdf0e10cSrcweir     meSymbolAlign = SYMBOLALIGN_LEFT;
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir // -----------------------------------------------------------------------
105*cdf0e10cSrcweir ImplCommonButtonData::~ImplCommonButtonData()
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir     delete mpBitmapEx;
108*cdf0e10cSrcweir     delete mpBitmapExHC;
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir // =======================================================================
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir Button::Button( WindowType nType ) :
114*cdf0e10cSrcweir     Control( nType )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir     mpButtonData = new ImplCommonButtonData;
117*cdf0e10cSrcweir }
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir // -----------------------------------------------------------------------
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir Button::Button( Window* pParent, WinBits nStyle ) :
122*cdf0e10cSrcweir     Control( WINDOW_BUTTON )
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir     mpButtonData = new ImplCommonButtonData;
125*cdf0e10cSrcweir     ImplInit( pParent, nStyle, NULL );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir // -----------------------------------------------------------------------
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir Button::Button( Window* pParent, const ResId& rResId ) :
131*cdf0e10cSrcweir     Control( WINDOW_BUTTON )
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     rResId.SetRT( RSC_BUTTON );
134*cdf0e10cSrcweir     mpButtonData = new ImplCommonButtonData;
135*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
136*cdf0e10cSrcweir     ImplInit( pParent, nStyle, NULL );
137*cdf0e10cSrcweir     ImplLoadRes( rResId );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
140*cdf0e10cSrcweir         Show();
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir // -----------------------------------------------------------------------
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir Button::~Button()
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     delete mpButtonData;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir // -----------------------------------------------------------------------
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir void Button::Click()
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_BUTTON_CLICK, maClickHdl, this );
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir // -----------------------------------------------------------------------
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir XubString Button::GetStandardText( StandardButtonType eButton )
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir     static struct
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         sal_uInt32 nResId;
164*cdf0e10cSrcweir         const char* pDefText;
165*cdf0e10cSrcweir     } aResIdAry[BUTTON_COUNT] =
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         { SV_BUTTONTEXT_OK, "~OK" },
168*cdf0e10cSrcweir         { SV_BUTTONTEXT_CANCEL, "~Cancel" },
169*cdf0e10cSrcweir         { SV_BUTTONTEXT_YES, "~Yes" },
170*cdf0e10cSrcweir         { SV_BUTTONTEXT_NO, "~No" },
171*cdf0e10cSrcweir         { SV_BUTTONTEXT_RETRY, "~Retry" },
172*cdf0e10cSrcweir         { SV_BUTTONTEXT_HELP, "~Help" },
173*cdf0e10cSrcweir         { SV_BUTTONTEXT_CLOSE, "~Close" },
174*cdf0e10cSrcweir         { SV_BUTTONTEXT_MORE, "~More" },
175*cdf0e10cSrcweir         { SV_BUTTONTEXT_IGNORE, "~Ignore" },
176*cdf0e10cSrcweir         { SV_BUTTONTEXT_ABORT, "~Abort" },
177*cdf0e10cSrcweir         { SV_BUTTONTEXT_LESS, "~Less" }
178*cdf0e10cSrcweir     };
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     String aText;
181*cdf0e10cSrcweir     ResMgr* pResMgr = ImplGetResMgr();
182*cdf0e10cSrcweir     if( pResMgr )
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         ResId aResId( aResIdAry[(sal_uInt16)eButton].nResId, *pResMgr );
185*cdf0e10cSrcweir         aText = String( aResId );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir     else
188*cdf0e10cSrcweir     {
189*cdf0e10cSrcweir         ByteString aT( aResIdAry[(sal_uInt16)eButton].pDefText );
190*cdf0e10cSrcweir         aText = String( aT, RTL_TEXTENCODING_ASCII_US );
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir     return aText;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // -----------------------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir XubString Button::GetStandardHelpText( StandardButtonType /* eButton */ )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     XubString aHelpText;
200*cdf0e10cSrcweir     return aHelpText;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir // -----------------------------------------------------------------------
203*cdf0e10cSrcweir sal_Bool Button::SetModeImage( const Image& rImage, BmpColorMode eMode )
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     if( eMode == BMP_COLOR_NORMAL )
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         if ( rImage != mpButtonData->maImage )
208*cdf0e10cSrcweir         {
209*cdf0e10cSrcweir             delete mpButtonData->mpBitmapEx;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir             mpButtonData->mpBitmapEx = NULL;
212*cdf0e10cSrcweir             mpButtonData->maImage = rImage;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir             StateChanged( STATE_CHANGE_DATA );
215*cdf0e10cSrcweir         }
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     else if( eMode == BMP_COLOR_HIGHCONTRAST )
218*cdf0e10cSrcweir     {
219*cdf0e10cSrcweir 		if( rImage != mpButtonData->maImageHC )
220*cdf0e10cSrcweir 		{
221*cdf0e10cSrcweir             delete mpButtonData->mpBitmapExHC;
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir             mpButtonData->mpBitmapExHC = NULL;
224*cdf0e10cSrcweir             mpButtonData->maImageHC = rImage;
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir             StateChanged( STATE_CHANGE_DATA );
227*cdf0e10cSrcweir         }
228*cdf0e10cSrcweir     }
229*cdf0e10cSrcweir     else
230*cdf0e10cSrcweir         return sal_False;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     return sal_True;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir // -----------------------------------------------------------------------
236*cdf0e10cSrcweir const Image Button::GetModeImage( BmpColorMode eMode ) const
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     if( eMode == BMP_COLOR_NORMAL )
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir         return mpButtonData->maImage;
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir     else if( eMode == BMP_COLOR_HIGHCONTRAST )
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         return mpButtonData->maImageHC;
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir     else
247*cdf0e10cSrcweir         return Image();
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir // -----------------------------------------------------------------------
251*cdf0e10cSrcweir sal_Bool Button::HasImage() const
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     return !!(mpButtonData->maImage);
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir // -----------------------------------------------------------------------
257*cdf0e10cSrcweir void Button::SetImageAlign( ImageAlign eAlign )
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir     if ( mpButtonData->meImageAlign != eAlign )
260*cdf0e10cSrcweir     {
261*cdf0e10cSrcweir         mpButtonData->meImageAlign = eAlign;
262*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir // -----------------------------------------------------------------------
267*cdf0e10cSrcweir ImageAlign Button::GetImageAlign() const
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     return mpButtonData->meImageAlign;
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir // -----------------------------------------------------------------------
273*cdf0e10cSrcweir sal_Bool Button::SetModeBitmap( const BitmapEx& rBitmap, BmpColorMode eMode )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     if ( SetModeImage( rBitmap, eMode ) )
276*cdf0e10cSrcweir     {
277*cdf0e10cSrcweir         if( eMode == BMP_COLOR_NORMAL )
278*cdf0e10cSrcweir         {
279*cdf0e10cSrcweir             if ( !mpButtonData->mpBitmapEx )
280*cdf0e10cSrcweir                 mpButtonData->mpBitmapEx = new BitmapEx( rBitmap );
281*cdf0e10cSrcweir         }
282*cdf0e10cSrcweir         else if ( eMode == BMP_COLOR_HIGHCONTRAST )
283*cdf0e10cSrcweir         {
284*cdf0e10cSrcweir             if ( !mpButtonData->mpBitmapExHC )
285*cdf0e10cSrcweir                 mpButtonData->mpBitmapExHC = new BitmapEx( rBitmap );
286*cdf0e10cSrcweir         }
287*cdf0e10cSrcweir         else
288*cdf0e10cSrcweir             return sal_False;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir         return sal_True;
291*cdf0e10cSrcweir     }
292*cdf0e10cSrcweir     return sal_False;
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir // -----------------------------------------------------------------------
296*cdf0e10cSrcweir BitmapEx Button::GetModeBitmap( BmpColorMode eMode ) const
297*cdf0e10cSrcweir {
298*cdf0e10cSrcweir     BitmapEx aBmp;
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     if ( eMode == BMP_COLOR_NORMAL )
301*cdf0e10cSrcweir 	{
302*cdf0e10cSrcweir 		if ( mpButtonData->mpBitmapEx )
303*cdf0e10cSrcweir 			aBmp = *( mpButtonData->mpBitmapEx );
304*cdf0e10cSrcweir 	}
305*cdf0e10cSrcweir     else if ( eMode == BMP_COLOR_HIGHCONTRAST )
306*cdf0e10cSrcweir 	{
307*cdf0e10cSrcweir 		if ( mpButtonData->mpBitmapExHC )
308*cdf0e10cSrcweir 			aBmp = *( mpButtonData->mpBitmapExHC );
309*cdf0e10cSrcweir 	}
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir     return aBmp;
312*cdf0e10cSrcweir }
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir // -----------------------------------------------------------------------
315*cdf0e10cSrcweir void Button::SetFocusRect( const Rectangle& rFocusRect )
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     ImplSetFocusRect( rFocusRect );
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir // -----------------------------------------------------------------------
321*cdf0e10cSrcweir const Rectangle& Button::GetFocusRect() const
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     return ImplGetFocusRect();
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir // -----------------------------------------------------------------------
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir const Rectangle& Button::ImplGetSymbolRect() const
329*cdf0e10cSrcweir {
330*cdf0e10cSrcweir     return mpButtonData->maSymbolRect;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir void Button::ImplSetSymbolRect( const Rectangle& i_rRect )
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     mpButtonData->maSymbolRect = i_rRect;
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir // -----------------------------------------------------------------------
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir sal_uInt16 Button::ImplGetTextStyle( XubString& rText, WinBits nWinStyle,
341*cdf0e10cSrcweir                                  sal_uLong nDrawFlags )
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
344*cdf0e10cSrcweir     sal_uInt16 nTextStyle = FixedText::ImplGetTextStyle( nWinStyle & ~WB_DEFBUTTON );
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         if ( nTextStyle & TEXT_DRAW_MNEMONIC )
349*cdf0e10cSrcweir         {
350*cdf0e10cSrcweir             rText = GetNonMnemonicString( rText );
351*cdf0e10cSrcweir             nTextStyle &= ~TEXT_DRAW_MNEMONIC;
352*cdf0e10cSrcweir         }
353*cdf0e10cSrcweir     }
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
356*cdf0e10cSrcweir     {
357*cdf0e10cSrcweir         if ( !IsEnabled() )
358*cdf0e10cSrcweir             nTextStyle |= TEXT_DRAW_DISABLE;
359*cdf0e10cSrcweir     }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
362*cdf0e10cSrcweir          (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
363*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_MONO;
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir     return nTextStyle;
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir // -----------------------------------------------------------------------
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir void Button::ImplDrawAlignedImage( OutputDevice* pDev, Point& rPos,
371*cdf0e10cSrcweir                                    Size& rSize, sal_Bool bLayout,
372*cdf0e10cSrcweir                                    sal_uLong nImageSep, sal_uLong nDrawFlags,
373*cdf0e10cSrcweir                                    sal_uInt16 nTextStyle, Rectangle *pSymbolRect,
374*cdf0e10cSrcweir                                    bool bAddImageSep )
375*cdf0e10cSrcweir {
376*cdf0e10cSrcweir     XubString   aText( GetText() );
377*cdf0e10cSrcweir     sal_Bool        bDrawImage = HasImage() && ! ( ImplGetButtonState() & BUTTON_DRAW_NOIMAGE );
378*cdf0e10cSrcweir     sal_Bool        bDrawText  = aText.Len() && ! ( ImplGetButtonState() & BUTTON_DRAW_NOTEXT );
379*cdf0e10cSrcweir     sal_Bool        bHasSymbol = pSymbolRect ? sal_True : sal_False;
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     // No text and no image => nothing to do => return
382*cdf0e10cSrcweir     if ( !bDrawImage && !bDrawText && !bHasSymbol )
383*cdf0e10cSrcweir         return;
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir     WinBits         nWinStyle = GetStyle();
386*cdf0e10cSrcweir     Rectangle       aOutRect( rPos, rSize );
387*cdf0e10cSrcweir     MetricVector   *pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
388*cdf0e10cSrcweir     String         *pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
389*cdf0e10cSrcweir     ImageAlign      eImageAlign = mpButtonData->meImageAlign;
390*cdf0e10cSrcweir     Size            aImageSize = mpButtonData->maImage.GetSizePixel();
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir     if ( ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC ) &&
393*cdf0e10cSrcweir          ( nTextStyle & TEXT_DRAW_MNEMONIC ) )
394*cdf0e10cSrcweir     {
395*cdf0e10cSrcweir         aText = GetNonMnemonicString( aText );
396*cdf0e10cSrcweir         nTextStyle &= ~TEXT_DRAW_MNEMONIC;
397*cdf0e10cSrcweir     }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir     aImageSize.Width()  = CalcZoom( aImageSize.Width() );
400*cdf0e10cSrcweir     aImageSize.Height() = CalcZoom( aImageSize.Height() );
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir     // Drawing text or symbol only is simple, use style and output rectangle
403*cdf0e10cSrcweir     if ( bHasSymbol && !bDrawImage && !bDrawText )
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         *pSymbolRect = aOutRect;
406*cdf0e10cSrcweir         return;
407*cdf0e10cSrcweir     }
408*cdf0e10cSrcweir     else if ( bDrawText && !bDrawImage && !bHasSymbol )
409*cdf0e10cSrcweir     {
410*cdf0e10cSrcweir         DrawControlText( *pDev, aOutRect, aText, nTextStyle, pVector, pDisplayText );
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir         ImplSetFocusRect( aOutRect );
413*cdf0e10cSrcweir         rSize = aOutRect.GetSize();
414*cdf0e10cSrcweir         rPos = aOutRect.TopLeft();
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir         return;
417*cdf0e10cSrcweir     }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir     // check for HC mode ( image only! )
420*cdf0e10cSrcweir     Image    *pImage    = &(mpButtonData->maImage);
421*cdf0e10cSrcweir     BitmapEx *pBitmapEx = mpButtonData->mpBitmapEx;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     if( !!(mpButtonData->maImageHC) )
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         if( GetSettings().GetStyleSettings().GetHighContrastMode() )
426*cdf0e10cSrcweir         {
427*cdf0e10cSrcweir             pImage = &(mpButtonData->maImageHC);
428*cdf0e10cSrcweir             pBitmapEx = mpButtonData->mpBitmapExHC;
429*cdf0e10cSrcweir         }
430*cdf0e10cSrcweir     }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir     if ( pBitmapEx && ( pDev->GetOutDevType() == OUTDEV_PRINTER ) )
433*cdf0e10cSrcweir     {
434*cdf0e10cSrcweir         // Die Groesse richtet sich nach dem Bildschirm, soll auf
435*cdf0e10cSrcweir         // dem Drucker genau so aussehen...
436*cdf0e10cSrcweir         MapMode aMap100thMM( MAP_100TH_MM );
437*cdf0e10cSrcweir         aImageSize = PixelToLogic( aImageSize, aMap100thMM );
438*cdf0e10cSrcweir         aImageSize = pDev->LogicToPixel( aImageSize, aMap100thMM );
439*cdf0e10cSrcweir     }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir     Size aTextSize;
442*cdf0e10cSrcweir     Size aSymbolSize;
443*cdf0e10cSrcweir     Size aMax;
444*cdf0e10cSrcweir     Point aImagePos = rPos;
445*cdf0e10cSrcweir     Point aTextPos = rPos;
446*cdf0e10cSrcweir     Rectangle aUnion = Rectangle( aImagePos, aImageSize );
447*cdf0e10cSrcweir     Rectangle aSymbol;
448*cdf0e10cSrcweir     long nSymbolHeight = 0;
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     if ( bDrawText || bHasSymbol )
451*cdf0e10cSrcweir     {
452*cdf0e10cSrcweir         // Get the size of the text output area ( the symbol will be drawn in
453*cdf0e10cSrcweir         // this area as well, so the symbol rectangle will be calculated here, too )
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir         Rectangle   aRect = Rectangle( Point(), rSize );
456*cdf0e10cSrcweir         Size        aTSSize;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir         if ( bHasSymbol )
459*cdf0e10cSrcweir         {
460*cdf0e10cSrcweir             if ( bDrawText )
461*cdf0e10cSrcweir             {
462*cdf0e10cSrcweir                 nSymbolHeight = pDev->GetTextHeight();
463*cdf0e10cSrcweir                 if ( mpButtonData->mbSmallSymbol )
464*cdf0e10cSrcweir                     nSymbolHeight = nSymbolHeight * 3 / 4;
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir                 aSymbol = Rectangle( Point(), Size( nSymbolHeight, nSymbolHeight ) );
467*cdf0e10cSrcweir                 ImplCalcSymbolRect( aSymbol );
468*cdf0e10cSrcweir                 aRect.Left() += 3 * nSymbolHeight / 2;
469*cdf0e10cSrcweir                 aTSSize.Width() = 3 * nSymbolHeight / 2;
470*cdf0e10cSrcweir             }
471*cdf0e10cSrcweir             else
472*cdf0e10cSrcweir             {
473*cdf0e10cSrcweir                 aSymbol = Rectangle( Point(), rSize );
474*cdf0e10cSrcweir                 ImplCalcSymbolRect( aSymbol );
475*cdf0e10cSrcweir                 aTSSize.Width() = aSymbol.GetWidth();
476*cdf0e10cSrcweir             }
477*cdf0e10cSrcweir             aTSSize.Height() = aSymbol.GetHeight();
478*cdf0e10cSrcweir             aSymbolSize = aSymbol.GetSize();
479*cdf0e10cSrcweir         }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir         if ( bDrawText )
482*cdf0e10cSrcweir         {
483*cdf0e10cSrcweir             if ( ( eImageAlign == IMAGEALIGN_LEFT_TOP ) ||
484*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_LEFT ) ||
485*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_LEFT_BOTTOM ) ||
486*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_RIGHT_TOP ) ||
487*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_RIGHT ) ||
488*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_RIGHT_BOTTOM ) )
489*cdf0e10cSrcweir             {
490*cdf0e10cSrcweir                 aRect.Right() -= ( aImageSize.Width() + nImageSep );
491*cdf0e10cSrcweir             }
492*cdf0e10cSrcweir             else if ( ( eImageAlign == IMAGEALIGN_TOP_LEFT ) ||
493*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_TOP ) ||
494*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_TOP_RIGHT ) ||
495*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_BOTTOM_LEFT ) ||
496*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_BOTTOM ) ||
497*cdf0e10cSrcweir                 ( eImageAlign == IMAGEALIGN_BOTTOM_RIGHT ) )
498*cdf0e10cSrcweir             {
499*cdf0e10cSrcweir                 aRect.Bottom() -= ( aImageSize.Height() + nImageSep );
500*cdf0e10cSrcweir             }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir             aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
503*cdf0e10cSrcweir             aTextSize = aRect.GetSize();
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir             aTSSize.Width()  += aTextSize.Width();
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir             if ( aTSSize.Height() < aTextSize.Height() )
508*cdf0e10cSrcweir                 aTSSize.Height() = aTextSize.Height();
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir             if( bAddImageSep && bDrawImage )
511*cdf0e10cSrcweir             {
512*cdf0e10cSrcweir                 long nDiff = (aImageSize.Height() - aTextSize.Height()) / 3;
513*cdf0e10cSrcweir                 if( nDiff > 0 )
514*cdf0e10cSrcweir                     nImageSep += nDiff;
515*cdf0e10cSrcweir             }
516*cdf0e10cSrcweir         }
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir         aMax.Width() = aTSSize.Width() > aImageSize.Width() ? aTSSize.Width() : aImageSize.Width();
519*cdf0e10cSrcweir         aMax.Height() = aTSSize.Height() > aImageSize.Height() ? aTSSize.Height() : aImageSize.Height();
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir         // Now calculate the output area for the image and the text acording to the image align flags
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir         if ( ( eImageAlign == IMAGEALIGN_LEFT ) ||
524*cdf0e10cSrcweir              ( eImageAlign == IMAGEALIGN_RIGHT ) )
525*cdf0e10cSrcweir         {
526*cdf0e10cSrcweir             aImagePos.Y() = rPos.Y() + ( aMax.Height() - aImageSize.Height() ) / 2;
527*cdf0e10cSrcweir             aTextPos.Y()  = rPos.Y() + ( aMax.Height() - aTSSize.Height() ) / 2;
528*cdf0e10cSrcweir         }
529*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_LEFT_BOTTOM ) ||
530*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_RIGHT_BOTTOM ) )
531*cdf0e10cSrcweir         {
532*cdf0e10cSrcweir             aImagePos.Y() = rPos.Y() + aMax.Height() - aImageSize.Height();
533*cdf0e10cSrcweir             aTextPos.Y()  = rPos.Y() + aMax.Height() - aTSSize.Height();
534*cdf0e10cSrcweir         }
535*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_TOP ) ||
536*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_BOTTOM ) )
537*cdf0e10cSrcweir         {
538*cdf0e10cSrcweir             aImagePos.X() = rPos.X() + ( aMax.Width() - aImageSize.Width() ) / 2;
539*cdf0e10cSrcweir             aTextPos.X()  = rPos.X() + ( aMax.Width() - aTSSize.Width() ) / 2;
540*cdf0e10cSrcweir         }
541*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_TOP_RIGHT ) ||
542*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_BOTTOM_RIGHT ) )
543*cdf0e10cSrcweir         {
544*cdf0e10cSrcweir             aImagePos.X() = rPos.X() + aMax.Width() - aImageSize.Width();
545*cdf0e10cSrcweir             aTextPos.X()  = rPos.X() + aMax.Width() - aTSSize.Width();
546*cdf0e10cSrcweir         }
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir         if ( ( eImageAlign == IMAGEALIGN_LEFT_TOP ) ||
549*cdf0e10cSrcweir              ( eImageAlign == IMAGEALIGN_LEFT ) ||
550*cdf0e10cSrcweir              ( eImageAlign == IMAGEALIGN_LEFT_BOTTOM ) )
551*cdf0e10cSrcweir         {
552*cdf0e10cSrcweir             aTextPos.X() = rPos.X() + aImageSize.Width() + nImageSep;
553*cdf0e10cSrcweir         }
554*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_RIGHT_TOP ) ||
555*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_RIGHT ) ||
556*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_RIGHT_BOTTOM ) )
557*cdf0e10cSrcweir         {
558*cdf0e10cSrcweir             aImagePos.X() = rPos.X() + aTSSize.Width() + nImageSep;
559*cdf0e10cSrcweir         }
560*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_TOP_LEFT ) ||
561*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_TOP ) ||
562*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_TOP_RIGHT ) )
563*cdf0e10cSrcweir         {
564*cdf0e10cSrcweir             aTextPos.Y() = rPos.Y() + aImageSize.Height() + nImageSep;
565*cdf0e10cSrcweir         }
566*cdf0e10cSrcweir         else if ( ( eImageAlign == IMAGEALIGN_BOTTOM_LEFT ) ||
567*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_BOTTOM ) ||
568*cdf0e10cSrcweir                   ( eImageAlign == IMAGEALIGN_BOTTOM_RIGHT ) )
569*cdf0e10cSrcweir         {
570*cdf0e10cSrcweir             aImagePos.Y() = rPos.Y() + aTSSize.Height() + nImageSep;
571*cdf0e10cSrcweir         }
572*cdf0e10cSrcweir         else if ( eImageAlign == IMAGEALIGN_CENTER )
573*cdf0e10cSrcweir         {
574*cdf0e10cSrcweir             aImagePos.X() = rPos.X() + ( aMax.Width()  - aImageSize.Width() ) / 2;
575*cdf0e10cSrcweir             aImagePos.Y() = rPos.Y() + ( aMax.Height() - aImageSize.Height() ) / 2;
576*cdf0e10cSrcweir             aTextPos.X()  = rPos.X() + ( aMax.Width()  - aTSSize.Width() ) / 2;
577*cdf0e10cSrcweir             aTextPos.Y()  = rPos.Y() + ( aMax.Height() - aTSSize.Height() ) / 2;
578*cdf0e10cSrcweir         }
579*cdf0e10cSrcweir         aUnion = Rectangle( aImagePos, aImageSize );
580*cdf0e10cSrcweir         aUnion.Union( Rectangle( aTextPos, aTSSize ) );
581*cdf0e10cSrcweir     }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir     // Now place the combination of text and image in the output area of the button
584*cdf0e10cSrcweir     // according to the window style (WinBits)
585*cdf0e10cSrcweir     long nXOffset = 0;
586*cdf0e10cSrcweir     long nYOffset = 0;
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir     if ( nWinStyle & WB_CENTER )
589*cdf0e10cSrcweir     {
590*cdf0e10cSrcweir         nXOffset = ( rSize.Width() - aUnion.GetWidth() ) / 2;
591*cdf0e10cSrcweir     }
592*cdf0e10cSrcweir     else if ( nWinStyle & WB_RIGHT )
593*cdf0e10cSrcweir     {
594*cdf0e10cSrcweir         nXOffset = rSize.Width() - aUnion.GetWidth();
595*cdf0e10cSrcweir     }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     if ( nWinStyle & WB_VCENTER )
598*cdf0e10cSrcweir     {
599*cdf0e10cSrcweir         nYOffset = ( rSize.Height() - aUnion.GetHeight() ) / 2;
600*cdf0e10cSrcweir     }
601*cdf0e10cSrcweir     else if ( nWinStyle & WB_BOTTOM )
602*cdf0e10cSrcweir     {
603*cdf0e10cSrcweir         nYOffset = rSize.Height() - aUnion.GetHeight();
604*cdf0e10cSrcweir     }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir     // the top left corner should always be visible, so we don't allow negative offsets
607*cdf0e10cSrcweir     if ( nXOffset < 0 ) nXOffset = 0;
608*cdf0e10cSrcweir     if ( nYOffset < 0 ) nYOffset = 0;
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir     aImagePos.X() += nXOffset;
611*cdf0e10cSrcweir     aImagePos.Y() += nYOffset;
612*cdf0e10cSrcweir     aTextPos.X() += nXOffset;
613*cdf0e10cSrcweir     aTextPos.Y() += nYOffset;
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     // set rPos and rSize to the union
616*cdf0e10cSrcweir     rSize = aUnion.GetSize();
617*cdf0e10cSrcweir     rPos.X() += nXOffset;
618*cdf0e10cSrcweir     rPos.Y() += nYOffset;
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir     if ( bHasSymbol )
621*cdf0e10cSrcweir     {
622*cdf0e10cSrcweir         if ( mpButtonData->meSymbolAlign == SYMBOLALIGN_RIGHT )
623*cdf0e10cSrcweir         {
624*cdf0e10cSrcweir             Point aRightPos = Point( aTextPos.X() + aTextSize.Width() + aSymbolSize.Width()/2, aTextPos.Y() );
625*cdf0e10cSrcweir             *pSymbolRect = Rectangle( aRightPos, aSymbolSize );
626*cdf0e10cSrcweir         }
627*cdf0e10cSrcweir         else
628*cdf0e10cSrcweir         {
629*cdf0e10cSrcweir             *pSymbolRect = Rectangle( aTextPos, aSymbolSize );
630*cdf0e10cSrcweir             aTextPos.X() += ( 3 * nSymbolHeight / 2 );
631*cdf0e10cSrcweir         }
632*cdf0e10cSrcweir         if ( mpButtonData->mbSmallSymbol )
633*cdf0e10cSrcweir         {
634*cdf0e10cSrcweir             nYOffset = (aUnion.GetHeight() - aSymbolSize.Height())/2;
635*cdf0e10cSrcweir             pSymbolRect->setY( aTextPos.Y() + nYOffset );
636*cdf0e10cSrcweir         }
637*cdf0e10cSrcweir     }
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     sal_uInt16 nStyle = 0;
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     if ( ! ( nDrawFlags & WINDOW_DRAW_NODISABLE ) &&
642*cdf0e10cSrcweir          ! IsEnabled() )
643*cdf0e10cSrcweir         nStyle |= IMAGE_DRAW_DISABLE;
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir     if ( pBitmapEx && ( pDev->GetOutDevType() == OUTDEV_PRINTER ) )
646*cdf0e10cSrcweir     {
647*cdf0e10cSrcweir         // Fuer die BitmapEx ueberlegt sich KA noch, wie man die disablete
648*cdf0e10cSrcweir         // Darstellung hinbekommt...
649*cdf0e10cSrcweir         pBitmapEx->Draw( pDev, aImagePos, aImageSize /*, nStyle*/ );
650*cdf0e10cSrcweir     }
651*cdf0e10cSrcweir     else
652*cdf0e10cSrcweir     {
653*cdf0e10cSrcweir         if ( IsZoom() )
654*cdf0e10cSrcweir             pDev->DrawImage( aImagePos, aImageSize, *pImage, nStyle );
655*cdf0e10cSrcweir         else
656*cdf0e10cSrcweir             pDev->DrawImage( aImagePos, *pImage, nStyle );
657*cdf0e10cSrcweir     }
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir     if ( bDrawText )
660*cdf0e10cSrcweir     {
661*cdf0e10cSrcweir         ImplSetFocusRect( Rectangle( aTextPos, aTextSize ) );
662*cdf0e10cSrcweir         pDev->DrawText( Rectangle( aTextPos, aTextSize ), aText, nTextStyle, pVector, pDisplayText );
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir     else
665*cdf0e10cSrcweir     {
666*cdf0e10cSrcweir         ImplSetFocusRect( Rectangle( aImagePos, aImageSize ) );
667*cdf0e10cSrcweir     }
668*cdf0e10cSrcweir }
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir // -----------------------------------------------------------------------
671*cdf0e10cSrcweir void Button::ImplSetFocusRect( const Rectangle &rFocusRect )
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir     Rectangle aFocusRect = rFocusRect;
674*cdf0e10cSrcweir     Rectangle aOutputRect = Rectangle( Point(), GetOutputSizePixel() );
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir     if ( ! aFocusRect.IsEmpty() )
677*cdf0e10cSrcweir     {
678*cdf0e10cSrcweir         aFocusRect.Left()--;
679*cdf0e10cSrcweir         aFocusRect.Top()--;
680*cdf0e10cSrcweir         aFocusRect.Right()++;
681*cdf0e10cSrcweir         aFocusRect.Bottom()++;
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir     if ( aFocusRect.Left() < aOutputRect.Left() )   aFocusRect.Left() = aOutputRect.Left();
685*cdf0e10cSrcweir     if ( aFocusRect.Top() < aOutputRect.Top() )     aFocusRect.Top() = aOutputRect.Top();
686*cdf0e10cSrcweir     if ( aFocusRect.Right() > aOutputRect.Right() ) aFocusRect.Right() = aOutputRect.Right();
687*cdf0e10cSrcweir     if ( aFocusRect.Bottom() > aOutputRect.Bottom() ) aFocusRect.Bottom() = aOutputRect.Bottom();
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     mpButtonData->maFocusRect = aFocusRect;
690*cdf0e10cSrcweir }
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir // -----------------------------------------------------------------------
693*cdf0e10cSrcweir const Rectangle& Button::ImplGetFocusRect() const
694*cdf0e10cSrcweir {
695*cdf0e10cSrcweir     return mpButtonData->maFocusRect;
696*cdf0e10cSrcweir }
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir // -----------------------------------------------------------------------
699*cdf0e10cSrcweir sal_uInt16& Button::ImplGetButtonState()
700*cdf0e10cSrcweir {
701*cdf0e10cSrcweir     return mpButtonData->mnButtonState;
702*cdf0e10cSrcweir }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir // -----------------------------------------------------------------------
705*cdf0e10cSrcweir sal_uInt16 Button::ImplGetButtonState() const
706*cdf0e10cSrcweir {
707*cdf0e10cSrcweir     return mpButtonData->mnButtonState;
708*cdf0e10cSrcweir }
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir // -----------------------------------------------------------------------
711*cdf0e10cSrcweir void Button::ImplSetSymbolAlign( SymbolAlign eAlign )
712*cdf0e10cSrcweir {
713*cdf0e10cSrcweir     if ( mpButtonData->meSymbolAlign != eAlign )
714*cdf0e10cSrcweir     {
715*cdf0e10cSrcweir         mpButtonData->meSymbolAlign = eAlign;
716*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
717*cdf0e10cSrcweir     }
718*cdf0e10cSrcweir }
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir // -----------------------------------------------------------------------
721*cdf0e10cSrcweir SymbolAlign Button::ImplGetSymbolAlign() const
722*cdf0e10cSrcweir {
723*cdf0e10cSrcweir     return mpButtonData->meSymbolAlign;
724*cdf0e10cSrcweir }
725*cdf0e10cSrcweir // -----------------------------------------------------------------------
726*cdf0e10cSrcweir void Button::ImplSetSmallSymbol( sal_Bool bSmall )
727*cdf0e10cSrcweir {
728*cdf0e10cSrcweir     mpButtonData->mbSmallSymbol = bSmall;
729*cdf0e10cSrcweir }
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir // -----------------------------------------------------------------------
732*cdf0e10cSrcweir void Button::EnableImageDisplay( sal_Bool bEnable )
733*cdf0e10cSrcweir {
734*cdf0e10cSrcweir     if( bEnable )
735*cdf0e10cSrcweir         mpButtonData->mnButtonState &= ~BUTTON_DRAW_NOIMAGE;
736*cdf0e10cSrcweir     else
737*cdf0e10cSrcweir         mpButtonData->mnButtonState |= BUTTON_DRAW_NOIMAGE;
738*cdf0e10cSrcweir }
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir // -----------------------------------------------------------------------
741*cdf0e10cSrcweir sal_Bool Button::IsImageDisplayEnabled()
742*cdf0e10cSrcweir {
743*cdf0e10cSrcweir     return (mpButtonData->mnButtonState & BUTTON_DRAW_NOIMAGE) == 0;
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir 
746*cdf0e10cSrcweir // -----------------------------------------------------------------------
747*cdf0e10cSrcweir void Button::EnableTextDisplay( sal_Bool bEnable )
748*cdf0e10cSrcweir {
749*cdf0e10cSrcweir     if( bEnable )
750*cdf0e10cSrcweir         mpButtonData->mnButtonState &= ~BUTTON_DRAW_NOTEXT;
751*cdf0e10cSrcweir     else
752*cdf0e10cSrcweir         mpButtonData->mnButtonState |= BUTTON_DRAW_NOTEXT;
753*cdf0e10cSrcweir }
754*cdf0e10cSrcweir 
755*cdf0e10cSrcweir // -----------------------------------------------------------------------
756*cdf0e10cSrcweir sal_Bool Button::IsTextDisplayEnabled()
757*cdf0e10cSrcweir {
758*cdf0e10cSrcweir     return (mpButtonData->mnButtonState & BUTTON_DRAW_NOTEXT) == 0;
759*cdf0e10cSrcweir }
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir // -----------------------------------------------------------------------
762*cdf0e10cSrcweir void Button::SetSmallSymbol (bool small)
763*cdf0e10cSrcweir {
764*cdf0e10cSrcweir     ImplSetSmallSymbol (small);
765*cdf0e10cSrcweir }
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir bool Button::IsSmallSymbol () const
768*cdf0e10cSrcweir {
769*cdf0e10cSrcweir     return mpButtonData->mbSmallSymbol;
770*cdf0e10cSrcweir }
771*cdf0e10cSrcweir 
772*cdf0e10cSrcweir // =======================================================================
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir void PushButton::ImplInitPushButtonData()
775*cdf0e10cSrcweir {
776*cdf0e10cSrcweir     mpWindowImpl->mbPushButton    = sal_True;
777*cdf0e10cSrcweir 
778*cdf0e10cSrcweir     meSymbol        = SYMBOL_NOSYMBOL;
779*cdf0e10cSrcweir     meState         = STATE_NOCHECK;
780*cdf0e10cSrcweir     meSaveValue     = STATE_NOCHECK;
781*cdf0e10cSrcweir     mnDDStyle       = 0;
782*cdf0e10cSrcweir     mbPressed       = sal_False;
783*cdf0e10cSrcweir     mbInUserDraw    = sal_False;
784*cdf0e10cSrcweir }
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir // -----------------------------------------------------------------------
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir void PushButton::ImplInit( Window* pParent, WinBits nStyle )
789*cdf0e10cSrcweir {
790*cdf0e10cSrcweir     nStyle = ImplInitStyle( pParent->GetWindow( WINDOW_LASTCHILD ), nStyle );
791*cdf0e10cSrcweir     Button::ImplInit( pParent, nStyle, NULL );
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir     if ( nStyle & WB_NOLIGHTBORDER )
794*cdf0e10cSrcweir         ImplGetButtonState() |= BUTTON_DRAW_NOLIGHTBORDER;
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
797*cdf0e10cSrcweir }
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir // -----------------------------------------------------------------------
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir WinBits PushButton::ImplInitStyle( const Window* pPrevWindow, WinBits nStyle )
802*cdf0e10cSrcweir {
803*cdf0e10cSrcweir     if ( !(nStyle & WB_NOTABSTOP) )
804*cdf0e10cSrcweir         nStyle |= WB_TABSTOP;
805*cdf0e10cSrcweir 
806*cdf0e10cSrcweir     // if no alignment is given, default to "vertically centered". This is because since
807*cdf0e10cSrcweir     // #i26046#, we respect the vertical alignment flags (previously we didn't completely),
808*cdf0e10cSrcweir     // but we of course want to look as before when no vertical alignment is specified
809*cdf0e10cSrcweir     if ( ( nStyle & ( WB_TOP | WB_VCENTER | WB_BOTTOM ) ) == 0 )
810*cdf0e10cSrcweir         nStyle |= WB_VCENTER;
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir     if ( !(nStyle & WB_NOGROUP) &&
813*cdf0e10cSrcweir          (!pPrevWindow ||
814*cdf0e10cSrcweir           ((pPrevWindow->GetType() != WINDOW_PUSHBUTTON) &&
815*cdf0e10cSrcweir            (pPrevWindow->GetType() != WINDOW_OKBUTTON) &&
816*cdf0e10cSrcweir            (pPrevWindow->GetType() != WINDOW_CANCELBUTTON) &&
817*cdf0e10cSrcweir            (pPrevWindow->GetType() != WINDOW_HELPBUTTON)) ) )
818*cdf0e10cSrcweir         nStyle |= WB_GROUP;
819*cdf0e10cSrcweir     return nStyle;
820*cdf0e10cSrcweir }
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir // -----------------------------------------------------------------
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir const Font& PushButton::GetCanonicalFont( const StyleSettings& _rStyle ) const
825*cdf0e10cSrcweir {
826*cdf0e10cSrcweir     return _rStyle.GetPushButtonFont();
827*cdf0e10cSrcweir }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir // -----------------------------------------------------------------
830*cdf0e10cSrcweir const Color& PushButton::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir     return _rStyle.GetButtonTextColor();
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir // -----------------------------------------------------------------------
836*cdf0e10cSrcweir 
837*cdf0e10cSrcweir void PushButton::ImplInitSettings( sal_Bool bFont,
838*cdf0e10cSrcweir                                    sal_Bool bForeground, sal_Bool bBackground )
839*cdf0e10cSrcweir {
840*cdf0e10cSrcweir     Button::ImplInitSettings( bFont, bForeground );
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir     if ( bBackground )
843*cdf0e10cSrcweir     {
844*cdf0e10cSrcweir         SetBackground();
845*cdf0e10cSrcweir         // #i38498#: do not check for GetParent()->IsChildTransparentModeEnabled()
846*cdf0e10cSrcweir         // otherwise the formcontrol button will be overdrawn due to PARENTCLIPMODE_NOCLIP
847*cdf0e10cSrcweir         // for radio and checkbox this is ok as they shoud appear transparent in documents
848*cdf0e10cSrcweir         if ( IsNativeControlSupported( CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL ) ||
849*cdf0e10cSrcweir              (GetStyle() & WB_FLATBUTTON) != 0 )
850*cdf0e10cSrcweir         {
851*cdf0e10cSrcweir             EnableChildTransparentMode( sal_True );
852*cdf0e10cSrcweir             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
853*cdf0e10cSrcweir             SetPaintTransparent( sal_True );
854*cdf0e10cSrcweir             mpWindowImpl->mbUseNativeFocus = (GetStyle() & WB_FLATBUTTON)
855*cdf0e10cSrcweir                 ? false
856*cdf0e10cSrcweir                 : ImplGetSVData()->maNWFData.mbNoFocusRects;
857*cdf0e10cSrcweir         }
858*cdf0e10cSrcweir         else
859*cdf0e10cSrcweir         {
860*cdf0e10cSrcweir             EnableChildTransparentMode( sal_False );
861*cdf0e10cSrcweir             SetParentClipMode( 0 );
862*cdf0e10cSrcweir             SetPaintTransparent( sal_False );
863*cdf0e10cSrcweir         }
864*cdf0e10cSrcweir     }
865*cdf0e10cSrcweir }
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir // -----------------------------------------------------------------------
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir void PushButton::ImplDrawPushButtonFrame( Window* pDev,
870*cdf0e10cSrcweir                                           Rectangle& rRect, sal_uInt16 nStyle )
871*cdf0e10cSrcweir {
872*cdf0e10cSrcweir     if ( !(pDev->GetStyle() & (WB_RECTSTYLE | WB_SMALLSTYLE)) )
873*cdf0e10cSrcweir     {
874*cdf0e10cSrcweir         StyleSettings aStyleSettings = pDev->GetSettings().GetStyleSettings();
875*cdf0e10cSrcweir         if ( pDev->IsControlBackground() )
876*cdf0e10cSrcweir             aStyleSettings.Set3DColors( pDev->GetControlBackground() );
877*cdf0e10cSrcweir     }
878*cdf0e10cSrcweir 
879*cdf0e10cSrcweir     DecorationView aDecoView( pDev );
880*cdf0e10cSrcweir     if ( pDev->IsControlBackground() )
881*cdf0e10cSrcweir     {
882*cdf0e10cSrcweir         AllSettings     aSettings = pDev->GetSettings();
883*cdf0e10cSrcweir         AllSettings     aOldSettings = aSettings;
884*cdf0e10cSrcweir         StyleSettings   aStyleSettings = aSettings.GetStyleSettings();
885*cdf0e10cSrcweir         aStyleSettings.Set3DColors( pDev->GetControlBackground() );
886*cdf0e10cSrcweir         aSettings.SetStyleSettings( aStyleSettings );
887*cdf0e10cSrcweir         pDev->OutputDevice::SetSettings( aSettings );
888*cdf0e10cSrcweir         rRect = aDecoView.DrawButton( rRect, nStyle );
889*cdf0e10cSrcweir         pDev->OutputDevice::SetSettings( aOldSettings );
890*cdf0e10cSrcweir     }
891*cdf0e10cSrcweir     else
892*cdf0e10cSrcweir         rRect = aDecoView.DrawButton( rRect, nStyle );
893*cdf0e10cSrcweir }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir // -----------------------------------------------------------------------
896*cdf0e10cSrcweir 
897*cdf0e10cSrcweir sal_Bool PushButton::ImplHitTestPushButton( Window* pDev,
898*cdf0e10cSrcweir                                         const Point& rPos )
899*cdf0e10cSrcweir {
900*cdf0e10cSrcweir     Point       aTempPoint;
901*cdf0e10cSrcweir     Rectangle   aTestRect( aTempPoint, pDev->GetOutputSizePixel() );
902*cdf0e10cSrcweir 
903*cdf0e10cSrcweir     return aTestRect.IsInside( rPos );
904*cdf0e10cSrcweir }
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir // -----------------------------------------------------------------------
907*cdf0e10cSrcweir 
908*cdf0e10cSrcweir sal_uInt16 PushButton::ImplGetTextStyle( sal_uLong nDrawFlags ) const
909*cdf0e10cSrcweir {
910*cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir     sal_uInt16 nTextStyle = TEXT_DRAW_MNEMONIC | TEXT_DRAW_MULTILINE | TEXT_DRAW_ENDELLIPSIS;
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir     if ( ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO ) ||
915*cdf0e10cSrcweir          ( nDrawFlags & WINDOW_DRAW_MONO ) )
916*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_MONO;
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir     if ( GetStyle() & WB_WORDBREAK )
919*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_WORDBREAK;
920*cdf0e10cSrcweir     if ( GetStyle() & WB_NOLABEL )
921*cdf0e10cSrcweir         nTextStyle &= ~TEXT_DRAW_MNEMONIC;
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir     if ( GetStyle() & WB_LEFT )
924*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_LEFT;
925*cdf0e10cSrcweir     else if ( GetStyle() & WB_RIGHT )
926*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_RIGHT;
927*cdf0e10cSrcweir     else
928*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_CENTER;
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir     if ( GetStyle() & WB_TOP )
931*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_TOP;
932*cdf0e10cSrcweir     else if ( GetStyle() & WB_BOTTOM )
933*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_BOTTOM;
934*cdf0e10cSrcweir     else
935*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_VCENTER;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir     if ( ! ( (nDrawFlags & WINDOW_DRAW_NODISABLE) || IsEnabled() ) )
938*cdf0e10cSrcweir         nTextStyle |= TEXT_DRAW_DISABLE;
939*cdf0e10cSrcweir 
940*cdf0e10cSrcweir     return nTextStyle;
941*cdf0e10cSrcweir }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir // -----------------------------------------------------------------------
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir static void ImplDrawBtnDropDownArrow( OutputDevice* pDev,
946*cdf0e10cSrcweir                                       long nX, long nY,
947*cdf0e10cSrcweir                                       Color& rColor, sal_Bool bBlack )
948*cdf0e10cSrcweir {
949*cdf0e10cSrcweir     Color aOldLineColor = pDev->GetLineColor();
950*cdf0e10cSrcweir     Color aOldFillColor = pDev->GetFillColor();
951*cdf0e10cSrcweir 
952*cdf0e10cSrcweir     pDev->SetLineColor();
953*cdf0e10cSrcweir     if ( bBlack )
954*cdf0e10cSrcweir         pDev->SetFillColor( Color( COL_BLACK ) );
955*cdf0e10cSrcweir     else
956*cdf0e10cSrcweir         pDev->SetFillColor( rColor );
957*cdf0e10cSrcweir     pDev->DrawRect( Rectangle( nX+0, nY+0, nX+6, nY+0 ) );
958*cdf0e10cSrcweir     pDev->DrawRect( Rectangle( nX+1, nY+1, nX+5, nY+1 ) );
959*cdf0e10cSrcweir     pDev->DrawRect( Rectangle( nX+2, nY+2, nX+4, nY+2 ) );
960*cdf0e10cSrcweir     pDev->DrawRect( Rectangle( nX+3, nY+3, nX+3, nY+3 ) );
961*cdf0e10cSrcweir     if ( bBlack )
962*cdf0e10cSrcweir     {
963*cdf0e10cSrcweir         pDev->SetFillColor( rColor );
964*cdf0e10cSrcweir         pDev->DrawRect( Rectangle( nX+2, nY+1, nX+4, nY+1 ) );
965*cdf0e10cSrcweir         pDev->DrawRect( Rectangle( nX+3, nY+2, nX+3, nY+2 ) );
966*cdf0e10cSrcweir     }
967*cdf0e10cSrcweir     pDev->SetLineColor( aOldLineColor );
968*cdf0e10cSrcweir     pDev->SetFillColor( aOldFillColor );
969*cdf0e10cSrcweir }
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir // -----------------------------------------------------------------------
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir void PushButton::ImplDrawPushButtonContent( OutputDevice* pDev, sal_uLong nDrawFlags,
974*cdf0e10cSrcweir                                             const Rectangle& rRect,
975*cdf0e10cSrcweir                                             bool bLayout,
976*cdf0e10cSrcweir                                             bool bMenuBtnSep
977*cdf0e10cSrcweir                                             )
978*cdf0e10cSrcweir {
979*cdf0e10cSrcweir     const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
980*cdf0e10cSrcweir     Rectangle               aInRect = rRect;
981*cdf0e10cSrcweir     Color                   aColor;
982*cdf0e10cSrcweir     XubString               aText = PushButton::GetText(); // PushButton:: wegen MoreButton
983*cdf0e10cSrcweir     sal_uInt16                  nTextStyle = ImplGetTextStyle( nDrawFlags );
984*cdf0e10cSrcweir     sal_uInt16                  nStyle;
985*cdf0e10cSrcweir 
986*cdf0e10cSrcweir     if( aInRect.nRight < aInRect.nLeft || aInRect.nBottom < aInRect.nTop )
987*cdf0e10cSrcweir         aInRect.SetEmpty();
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir     pDev->Push( PUSH_CLIPREGION );
990*cdf0e10cSrcweir     pDev->IntersectClipRegion( aInRect );
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir     if ( nDrawFlags & WINDOW_DRAW_MONO )
993*cdf0e10cSrcweir         aColor = Color( COL_BLACK );
994*cdf0e10cSrcweir     else if ( IsControlForeground() )
995*cdf0e10cSrcweir         aColor = GetControlForeground();
996*cdf0e10cSrcweir     else if( nDrawFlags & WINDOW_DRAW_ROLLOVER )
997*cdf0e10cSrcweir         aColor = rStyleSettings.GetButtonRolloverTextColor();
998*cdf0e10cSrcweir     else
999*cdf0e10cSrcweir         aColor = rStyleSettings.GetButtonTextColor();
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir     pDev->SetTextColor( aColor );
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir     if ( IsEnabled() || (nDrawFlags & WINDOW_DRAW_NODISABLE) )
1004*cdf0e10cSrcweir         nStyle = 0;
1005*cdf0e10cSrcweir     else
1006*cdf0e10cSrcweir         nStyle = SYMBOL_DRAW_DISABLE;
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir     Size aSize = rRect.GetSize();
1009*cdf0e10cSrcweir     Point aPos = rRect.TopLeft();
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir     sal_uLong nImageSep = 1 + (pDev->GetTextHeight()-10)/2;
1012*cdf0e10cSrcweir     if( nImageSep < 1 )
1013*cdf0e10cSrcweir         nImageSep = 1;
1014*cdf0e10cSrcweir     if ( mnDDStyle == PUSHBUTTON_DROPDOWN_MENUBUTTON )
1015*cdf0e10cSrcweir     {
1016*cdf0e10cSrcweir         if ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
1017*cdf0e10cSrcweir         {
1018*cdf0e10cSrcweir             // calc Symbol- and Textrect
1019*cdf0e10cSrcweir             long nSymbolSize    = pDev->GetTextHeight() / 2 + 1;
1020*cdf0e10cSrcweir             aInRect.Right()    -= 5;
1021*cdf0e10cSrcweir             aInRect.Left()      = aInRect.Right() - nSymbolSize;
1022*cdf0e10cSrcweir             aSize.Width()      -= ( 5 + nSymbolSize );
1023*cdf0e10cSrcweir 
1024*cdf0e10cSrcweir             ImplDrawAlignedImage( pDev, aPos, aSize, bLayout, nImageSep,
1025*cdf0e10cSrcweir                                   nDrawFlags, nTextStyle, NULL, true );
1026*cdf0e10cSrcweir         }
1027*cdf0e10cSrcweir         else
1028*cdf0e10cSrcweir             ImplCalcSymbolRect( aInRect );
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir         if( ! bLayout )
1031*cdf0e10cSrcweir         {
1032*cdf0e10cSrcweir             long nDistance = (aInRect.GetHeight() > 10) ? 2 : 1;
1033*cdf0e10cSrcweir             DecorationView aDecoView( pDev );
1034*cdf0e10cSrcweir             if( bMenuBtnSep )
1035*cdf0e10cSrcweir             {
1036*cdf0e10cSrcweir                 long nX = aInRect.Left() - 2*nDistance;;
1037*cdf0e10cSrcweir                 Point aStartPt( nX, aInRect.Top()+nDistance );
1038*cdf0e10cSrcweir                 Point aEndPt( nX, aInRect.Bottom()-nDistance );
1039*cdf0e10cSrcweir                 aDecoView.DrawSeparator( aStartPt, aEndPt );
1040*cdf0e10cSrcweir             }
1041*cdf0e10cSrcweir             aDecoView.DrawSymbol( aInRect, SYMBOL_SPIN_DOWN, aColor, nStyle );
1042*cdf0e10cSrcweir             aInRect.Left() -= 2*nDistance;
1043*cdf0e10cSrcweir             ImplSetSymbolRect( aInRect );
1044*cdf0e10cSrcweir         }
1045*cdf0e10cSrcweir     }
1046*cdf0e10cSrcweir     else
1047*cdf0e10cSrcweir     {
1048*cdf0e10cSrcweir         Rectangle aSymbolRect;
1049*cdf0e10cSrcweir         // FIXME: (GetStyle() & WB_FLATBUTTON) != 0 is preliminary
1050*cdf0e10cSrcweir         // in the next major this should be replaced by "true"
1051*cdf0e10cSrcweir         ImplDrawAlignedImage( pDev, aPos, aSize, bLayout, nImageSep, nDrawFlags,
1052*cdf0e10cSrcweir                               nTextStyle, IsSymbol() ? &aSymbolRect : NULL, true );
1053*cdf0e10cSrcweir 
1054*cdf0e10cSrcweir         if ( IsSymbol() && ! bLayout )
1055*cdf0e10cSrcweir         {
1056*cdf0e10cSrcweir             DecorationView aDecoView( pDev );
1057*cdf0e10cSrcweir             aDecoView.DrawSymbol( aSymbolRect, meSymbol, aColor, nStyle );
1058*cdf0e10cSrcweir             ImplSetSymbolRect( aSymbolRect );
1059*cdf0e10cSrcweir         }
1060*cdf0e10cSrcweir 
1061*cdf0e10cSrcweir         if ( mnDDStyle == PUSHBUTTON_DROPDOWN_TOOLBOX && !bLayout )
1062*cdf0e10cSrcweir         {
1063*cdf0e10cSrcweir             sal_Bool    bBlack = sal_False;
1064*cdf0e10cSrcweir             Color   aArrowColor( COL_BLACK );
1065*cdf0e10cSrcweir 
1066*cdf0e10cSrcweir             if ( !(nDrawFlags & WINDOW_DRAW_MONO) )
1067*cdf0e10cSrcweir             {
1068*cdf0e10cSrcweir                 if ( !IsEnabled() )
1069*cdf0e10cSrcweir                     aArrowColor = rStyleSettings.GetShadowColor();
1070*cdf0e10cSrcweir                 else
1071*cdf0e10cSrcweir                 {
1072*cdf0e10cSrcweir                     aArrowColor = Color( COL_LIGHTGREEN );
1073*cdf0e10cSrcweir                     bBlack = sal_True;
1074*cdf0e10cSrcweir                 }
1075*cdf0e10cSrcweir             }
1076*cdf0e10cSrcweir 
1077*cdf0e10cSrcweir             ImplDrawBtnDropDownArrow( pDev, aInRect.Right()-6, aInRect.Top()+1,
1078*cdf0e10cSrcweir                                       aArrowColor, bBlack );
1079*cdf0e10cSrcweir         }
1080*cdf0e10cSrcweir     }
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir     UserDrawEvent aUDEvt( this, aInRect, 0 );
1083*cdf0e10cSrcweir     UserDraw( aUDEvt );
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir     pDev->Pop();  // restore clipregion
1086*cdf0e10cSrcweir }
1087*cdf0e10cSrcweir 
1088*cdf0e10cSrcweir // -----------------------------------------------------------------------
1089*cdf0e10cSrcweir 
1090*cdf0e10cSrcweir void PushButton::UserDraw( const UserDrawEvent& )
1091*cdf0e10cSrcweir {
1092*cdf0e10cSrcweir }
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir // -----------------------------------------------------------------------
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir void PushButton::ImplDrawPushButton( bool bLayout )
1097*cdf0e10cSrcweir {
1098*cdf0e10cSrcweir     if( !bLayout )
1099*cdf0e10cSrcweir         HideFocus();
1100*cdf0e10cSrcweir 
1101*cdf0e10cSrcweir     sal_uInt16                  nButtonStyle = ImplGetButtonState();
1102*cdf0e10cSrcweir     Point                   aPoint;
1103*cdf0e10cSrcweir     Size                    aOutSz( GetOutputSizePixel() );
1104*cdf0e10cSrcweir     Rectangle               aRect( aPoint, aOutSz );
1105*cdf0e10cSrcweir     Rectangle               aInRect = aRect;
1106*cdf0e10cSrcweir     Rectangle               aTextRect;
1107*cdf0e10cSrcweir     sal_Bool                    bNativeOK = sal_False;
1108*cdf0e10cSrcweir 
1109*cdf0e10cSrcweir     // adjust style if button should be rendered 'pressed'
1110*cdf0e10cSrcweir     if ( mbPressed )
1111*cdf0e10cSrcweir         nButtonStyle |= BUTTON_DRAW_PRESSED;
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir     // TODO: move this to Window class or make it a member !!!
1114*cdf0e10cSrcweir     ControlType aCtrlType = 0;
1115*cdf0e10cSrcweir     switch( GetParent()->GetType() )
1116*cdf0e10cSrcweir     {
1117*cdf0e10cSrcweir         case WINDOW_LISTBOX:
1118*cdf0e10cSrcweir         case WINDOW_MULTILISTBOX:
1119*cdf0e10cSrcweir         case WINDOW_TREELISTBOX:
1120*cdf0e10cSrcweir             aCtrlType = CTRL_LISTBOX;
1121*cdf0e10cSrcweir             break;
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir         case WINDOW_COMBOBOX:
1124*cdf0e10cSrcweir         case WINDOW_PATTERNBOX:
1125*cdf0e10cSrcweir         case WINDOW_NUMERICBOX:
1126*cdf0e10cSrcweir         case WINDOW_METRICBOX:
1127*cdf0e10cSrcweir         case WINDOW_CURRENCYBOX:
1128*cdf0e10cSrcweir         case WINDOW_DATEBOX:
1129*cdf0e10cSrcweir         case WINDOW_TIMEBOX:
1130*cdf0e10cSrcweir         case WINDOW_LONGCURRENCYBOX:
1131*cdf0e10cSrcweir             aCtrlType = CTRL_COMBOBOX;
1132*cdf0e10cSrcweir             break;
1133*cdf0e10cSrcweir         default:
1134*cdf0e10cSrcweir             break;
1135*cdf0e10cSrcweir     }
1136*cdf0e10cSrcweir 
1137*cdf0e10cSrcweir     sal_Bool bDropDown = ( IsSymbol() && (GetSymbol()==SYMBOL_SPIN_DOWN) && !GetText().Len() );
1138*cdf0e10cSrcweir 
1139*cdf0e10cSrcweir     if( bDropDown && (aCtrlType == CTRL_COMBOBOX || aCtrlType == CTRL_LISTBOX ) )
1140*cdf0e10cSrcweir     {
1141*cdf0e10cSrcweir         if( GetParent()->IsNativeControlSupported( aCtrlType, PART_ENTIRE_CONTROL) )
1142*cdf0e10cSrcweir         {
1143*cdf0e10cSrcweir             // skip painting if the button was already drawn by the theme
1144*cdf0e10cSrcweir             if( aCtrlType == CTRL_COMBOBOX )
1145*cdf0e10cSrcweir             {
1146*cdf0e10cSrcweir                 Edit* pEdit = static_cast<Edit*>(GetParent());
1147*cdf0e10cSrcweir                 if( pEdit->ImplUseNativeBorder( pEdit->GetStyle() ) )
1148*cdf0e10cSrcweir                     bNativeOK = sal_True;
1149*cdf0e10cSrcweir             }
1150*cdf0e10cSrcweir             else if( GetParent()->IsNativeControlSupported( aCtrlType, HAS_BACKGROUND_TEXTURE) )
1151*cdf0e10cSrcweir             {
1152*cdf0e10cSrcweir                 bNativeOK = sal_True;
1153*cdf0e10cSrcweir             }
1154*cdf0e10cSrcweir             if( !bNativeOK && GetParent()->IsNativeControlSupported( aCtrlType, PART_BUTTON_DOWN ) )
1155*cdf0e10cSrcweir             {
1156*cdf0e10cSrcweir                 // let the theme draw it, note we then need support
1157*cdf0e10cSrcweir                 // for CTRL_LISTBOX/PART_BUTTON_DOWN and CTRL_COMBOBOX/PART_BUTTON_DOWN
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir                 ImplControlValue    aControlValue;
1160*cdf0e10cSrcweir                 ControlState        nState = 0;
1161*cdf0e10cSrcweir 
1162*cdf0e10cSrcweir                 if ( mbPressed ) 						nState |= CTRL_STATE_PRESSED;
1163*cdf0e10cSrcweir                 if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )	nState |= CTRL_STATE_PRESSED;
1164*cdf0e10cSrcweir                 if ( HasFocus() )						nState |= CTRL_STATE_FOCUSED;
1165*cdf0e10cSrcweir                 if ( ImplGetButtonState() & BUTTON_DRAW_DEFAULT )	nState |= CTRL_STATE_DEFAULT;
1166*cdf0e10cSrcweir                 if ( Window::IsEnabled() ) 				nState |= CTRL_STATE_ENABLED;
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir                 if ( IsMouseOver() && aInRect.IsInside( GetPointerPosPixel() ) )
1169*cdf0e10cSrcweir                     nState |= CTRL_STATE_ROLLOVER;
1170*cdf0e10cSrcweir 
1171*cdf0e10cSrcweir                 bNativeOK = DrawNativeControl( aCtrlType, PART_BUTTON_DOWN, aInRect, nState,
1172*cdf0e10cSrcweir                                                 aControlValue, rtl::OUString() );
1173*cdf0e10cSrcweir             }
1174*cdf0e10cSrcweir         }
1175*cdf0e10cSrcweir     }
1176*cdf0e10cSrcweir 
1177*cdf0e10cSrcweir     if( bNativeOK )
1178*cdf0e10cSrcweir         return;
1179*cdf0e10cSrcweir 
1180*cdf0e10cSrcweir     bool bRollOver = (IsMouseOver() && aInRect.IsInside( GetPointerPosPixel() ));
1181*cdf0e10cSrcweir     bool bDrawMenuSep = true;
1182*cdf0e10cSrcweir     if( (GetStyle() & WB_FLATBUTTON) )
1183*cdf0e10cSrcweir     {
1184*cdf0e10cSrcweir         if( ! bRollOver && ! HasFocus() )
1185*cdf0e10cSrcweir             bDrawMenuSep = false;
1186*cdf0e10cSrcweir     }
1187*cdf0e10cSrcweir     if ( (bNativeOK=IsNativeControlSupported(CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL)) == sal_True )
1188*cdf0e10cSrcweir     {
1189*cdf0e10cSrcweir         PushButtonValue aControlValue;
1190*cdf0e10cSrcweir         Rectangle		 aCtrlRegion( aInRect );
1191*cdf0e10cSrcweir         ControlState	 nState = 0;
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir         if ( mbPressed || IsChecked() )                   nState |= CTRL_STATE_PRESSED;
1194*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED ) nState |= CTRL_STATE_PRESSED;
1195*cdf0e10cSrcweir         if ( HasFocus() )						nState |= CTRL_STATE_FOCUSED;
1196*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_DEFAULT )	nState |= CTRL_STATE_DEFAULT;
1197*cdf0e10cSrcweir         if ( Window::IsEnabled() ) 				nState |= CTRL_STATE_ENABLED;
1198*cdf0e10cSrcweir 
1199*cdf0e10cSrcweir         if ( bRollOver )
1200*cdf0e10cSrcweir             nState |= CTRL_STATE_ROLLOVER;
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir         if( GetStyle() & WB_BEVELBUTTON )
1203*cdf0e10cSrcweir             aControlValue.mbBevelButton = true;
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir         // draw frame into invisible window to have aInRect modified correctly
1206*cdf0e10cSrcweir         // but do not shift the inner rect for pressed buttons (ie remove BUTTON_DRAW_PRESSED)
1207*cdf0e10cSrcweir         // this assumes the theme has enough visual cues to signalize the button was pressed
1208*cdf0e10cSrcweir         //Window aWin( this );
1209*cdf0e10cSrcweir         //ImplDrawPushButtonFrame( &aWin, aInRect, nButtonStyle & ~BUTTON_DRAW_PRESSED );
1210*cdf0e10cSrcweir 
1211*cdf0e10cSrcweir         // looks better this way as symbols were displaced slightly using the above approach
1212*cdf0e10cSrcweir         aInRect.Top()+=4;
1213*cdf0e10cSrcweir         aInRect.Bottom()-=4;
1214*cdf0e10cSrcweir         aInRect.Left()+=4;
1215*cdf0e10cSrcweir         aInRect.Right()-=4;
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir         // prepare single line hint (needed on mac to decide between normal push button and
1218*cdf0e10cSrcweir         // rectangular bevel button look)
1219*cdf0e10cSrcweir         Size aFontSize( Application::GetSettings().GetStyleSettings().GetPushButtonFont().GetSize() );
1220*cdf0e10cSrcweir         aFontSize = LogicToPixel( aFontSize, MapMode( MAP_POINT ) );
1221*cdf0e10cSrcweir         Size aInRectSize( LogicToPixel( Size( aInRect.GetWidth(), aInRect.GetHeight() ) ) );
1222*cdf0e10cSrcweir         aControlValue.mbSingleLine = (aInRectSize.Height() < 2 * aFontSize.Height() );
1223*cdf0e10cSrcweir 
1224*cdf0e10cSrcweir         if( ((nState & CTRL_STATE_ROLLOVER)) || ! (GetStyle() & WB_FLATBUTTON) )
1225*cdf0e10cSrcweir         {
1226*cdf0e10cSrcweir             bNativeOK = DrawNativeControl( CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
1227*cdf0e10cSrcweir                             aControlValue, rtl::OUString()/*PushButton::GetText()*/ );
1228*cdf0e10cSrcweir         }
1229*cdf0e10cSrcweir         else
1230*cdf0e10cSrcweir         {
1231*cdf0e10cSrcweir             bNativeOK = true;
1232*cdf0e10cSrcweir         }
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir         // draw content using the same aInRect as non-native VCL would do
1235*cdf0e10cSrcweir         ImplDrawPushButtonContent( this,
1236*cdf0e10cSrcweir                                    (nState&CTRL_STATE_ROLLOVER) ? WINDOW_DRAW_ROLLOVER : 0,
1237*cdf0e10cSrcweir                                    aInRect, bLayout, bDrawMenuSep );
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir         if ( HasFocus() )
1240*cdf0e10cSrcweir             ShowFocus( ImplGetFocusRect() );
1241*cdf0e10cSrcweir     }
1242*cdf0e10cSrcweir 
1243*cdf0e10cSrcweir     if ( bNativeOK == sal_False )
1244*cdf0e10cSrcweir     {
1245*cdf0e10cSrcweir         // draw PushButtonFrame, aInRect has content size afterwards
1246*cdf0e10cSrcweir         if( (GetStyle() & WB_FLATBUTTON) )
1247*cdf0e10cSrcweir         {
1248*cdf0e10cSrcweir             Rectangle aTempRect( aInRect );
1249*cdf0e10cSrcweir             if( ! bLayout && bRollOver )
1250*cdf0e10cSrcweir                 ImplDrawPushButtonFrame( this, aTempRect, nButtonStyle );
1251*cdf0e10cSrcweir             aInRect.Left()   += 2;
1252*cdf0e10cSrcweir             aInRect.Top()    += 2;
1253*cdf0e10cSrcweir             aInRect.Right()  -= 2;
1254*cdf0e10cSrcweir             aInRect.Bottom() -= 2;
1255*cdf0e10cSrcweir         }
1256*cdf0e10cSrcweir         else
1257*cdf0e10cSrcweir         {
1258*cdf0e10cSrcweir             if( ! bLayout )
1259*cdf0e10cSrcweir                 ImplDrawPushButtonFrame( this, aInRect, nButtonStyle );
1260*cdf0e10cSrcweir         }
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir         // draw content
1263*cdf0e10cSrcweir         ImplDrawPushButtonContent( this, 0, aInRect, bLayout, bDrawMenuSep );
1264*cdf0e10cSrcweir 
1265*cdf0e10cSrcweir         if( ! bLayout && HasFocus() )
1266*cdf0e10cSrcweir         {
1267*cdf0e10cSrcweir             ShowFocus( ImplGetFocusRect() );
1268*cdf0e10cSrcweir         }
1269*cdf0e10cSrcweir     }
1270*cdf0e10cSrcweir }
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir // -----------------------------------------------------------------------
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir void PushButton::ImplSetDefButton( sal_Bool bSet )
1275*cdf0e10cSrcweir {
1276*cdf0e10cSrcweir     Size aSize( GetSizePixel() );
1277*cdf0e10cSrcweir     Point aPos( GetPosPixel() );
1278*cdf0e10cSrcweir     int dLeft(0), dRight(0), dTop(0), dBottom(0);
1279*cdf0e10cSrcweir     sal_Bool bSetPos = sal_False;
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir     if ( (IsNativeControlSupported(CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL)) == sal_True )
1282*cdf0e10cSrcweir     {
1283*cdf0e10cSrcweir         Rectangle aBound, aCont;
1284*cdf0e10cSrcweir         Rectangle aCtrlRect( 0, 0, 80, 20 ); // use a constant size to avoid accumulating
1285*cdf0e10cSrcweir                                              // will not work if the theme has dynamic adornment sizes
1286*cdf0e10cSrcweir         ImplControlValue aControlValue;
1287*cdf0e10cSrcweir         Rectangle		 aCtrlRegion( aCtrlRect );
1288*cdf0e10cSrcweir         ControlState	 nState = CTRL_STATE_DEFAULT|CTRL_STATE_ENABLED;
1289*cdf0e10cSrcweir 
1290*cdf0e10cSrcweir         // get native size of a 'default' button
1291*cdf0e10cSrcweir         // and adjust the VCL button if more space for adornment is required
1292*cdf0e10cSrcweir         if( GetNativeControlRegion( CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL, aCtrlRegion,
1293*cdf0e10cSrcweir                                 nState, aControlValue, rtl::OUString(),
1294*cdf0e10cSrcweir 								aBound, aCont ) )
1295*cdf0e10cSrcweir         {
1296*cdf0e10cSrcweir             dLeft = aCont.Left() - aBound.Left();
1297*cdf0e10cSrcweir             dTop = aCont.Top() - aBound.Top();
1298*cdf0e10cSrcweir             dRight = aBound.Right() - aCont.Right();
1299*cdf0e10cSrcweir             dBottom = aBound.Bottom() - aCont.Bottom();
1300*cdf0e10cSrcweir             bSetPos = dLeft || dTop || dRight || dBottom;
1301*cdf0e10cSrcweir         }
1302*cdf0e10cSrcweir     }
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir     if ( bSet )
1305*cdf0e10cSrcweir     {
1306*cdf0e10cSrcweir         if( !(ImplGetButtonState() & BUTTON_DRAW_DEFAULT) && bSetPos )
1307*cdf0e10cSrcweir         {
1308*cdf0e10cSrcweir             // adjust pos/size when toggling from non-default to default
1309*cdf0e10cSrcweir             aPos.Move(-dLeft, -dTop);
1310*cdf0e10cSrcweir             aSize.Width() += dLeft + dRight;
1311*cdf0e10cSrcweir             aSize.Height() += dTop + dBottom;
1312*cdf0e10cSrcweir         }
1313*cdf0e10cSrcweir         ImplGetButtonState() |= BUTTON_DRAW_DEFAULT;
1314*cdf0e10cSrcweir     }
1315*cdf0e10cSrcweir     else
1316*cdf0e10cSrcweir     {
1317*cdf0e10cSrcweir         if( (ImplGetButtonState() & BUTTON_DRAW_DEFAULT) && bSetPos )
1318*cdf0e10cSrcweir         {
1319*cdf0e10cSrcweir             // adjust pos/size when toggling from default to non-default
1320*cdf0e10cSrcweir             aPos.Move(dLeft, dTop);
1321*cdf0e10cSrcweir             aSize.Width() -= dLeft + dRight;
1322*cdf0e10cSrcweir             aSize.Height() -= dTop + dBottom;
1323*cdf0e10cSrcweir         }
1324*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_DEFAULT;
1325*cdf0e10cSrcweir     }
1326*cdf0e10cSrcweir     if( bSetPos )
1327*cdf0e10cSrcweir         SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height(), WINDOW_POSSIZE_ALL );
1328*cdf0e10cSrcweir 
1329*cdf0e10cSrcweir     Invalidate();
1330*cdf0e10cSrcweir }
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir // -----------------------------------------------------------------------
1333*cdf0e10cSrcweir 
1334*cdf0e10cSrcweir sal_Bool PushButton::ImplIsDefButton() const
1335*cdf0e10cSrcweir {
1336*cdf0e10cSrcweir     return (ImplGetButtonState() & BUTTON_DRAW_DEFAULT) != 0;
1337*cdf0e10cSrcweir }
1338*cdf0e10cSrcweir 
1339*cdf0e10cSrcweir // -----------------------------------------------------------------------
1340*cdf0e10cSrcweir 
1341*cdf0e10cSrcweir PushButton::PushButton( WindowType nType ) :
1342*cdf0e10cSrcweir     Button( nType )
1343*cdf0e10cSrcweir {
1344*cdf0e10cSrcweir     ImplInitPushButtonData();
1345*cdf0e10cSrcweir }
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir // -----------------------------------------------------------------------
1348*cdf0e10cSrcweir 
1349*cdf0e10cSrcweir PushButton::PushButton( Window* pParent, WinBits nStyle ) :
1350*cdf0e10cSrcweir     Button( WINDOW_PUSHBUTTON )
1351*cdf0e10cSrcweir {
1352*cdf0e10cSrcweir     ImplInitPushButtonData();
1353*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1354*cdf0e10cSrcweir }
1355*cdf0e10cSrcweir 
1356*cdf0e10cSrcweir // -----------------------------------------------------------------------
1357*cdf0e10cSrcweir 
1358*cdf0e10cSrcweir PushButton::PushButton( Window* pParent, const ResId& rResId ) :
1359*cdf0e10cSrcweir     Button( WINDOW_PUSHBUTTON )
1360*cdf0e10cSrcweir {
1361*cdf0e10cSrcweir     ImplInitPushButtonData();
1362*cdf0e10cSrcweir     rResId.SetRT( RSC_PUSHBUTTON );
1363*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
1364*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1365*cdf0e10cSrcweir     ImplLoadRes( rResId );
1366*cdf0e10cSrcweir 
1367*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
1368*cdf0e10cSrcweir         Show();
1369*cdf0e10cSrcweir }
1370*cdf0e10cSrcweir 
1371*cdf0e10cSrcweir // -----------------------------------------------------------------------
1372*cdf0e10cSrcweir 
1373*cdf0e10cSrcweir PushButton::~PushButton()
1374*cdf0e10cSrcweir {
1375*cdf0e10cSrcweir }
1376*cdf0e10cSrcweir 
1377*cdf0e10cSrcweir // -----------------------------------------------------------------------
1378*cdf0e10cSrcweir 
1379*cdf0e10cSrcweir void PushButton::MouseButtonDown( const MouseEvent& rMEvt )
1380*cdf0e10cSrcweir {
1381*cdf0e10cSrcweir     if ( rMEvt.IsLeft() &&
1382*cdf0e10cSrcweir          ImplHitTestPushButton( this, rMEvt.GetPosPixel() ) )
1383*cdf0e10cSrcweir     {
1384*cdf0e10cSrcweir         sal_uInt16 nTrackFlags = 0;
1385*cdf0e10cSrcweir 
1386*cdf0e10cSrcweir         if ( ( GetStyle() & WB_REPEAT ) &&
1387*cdf0e10cSrcweir              ! ( GetStyle() & WB_TOGGLE ) )
1388*cdf0e10cSrcweir             nTrackFlags |= STARTTRACK_BUTTONREPEAT;
1389*cdf0e10cSrcweir 
1390*cdf0e10cSrcweir         ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
1391*cdf0e10cSrcweir         ImplDrawPushButton();
1392*cdf0e10cSrcweir         StartTracking( nTrackFlags );
1393*cdf0e10cSrcweir 
1394*cdf0e10cSrcweir         if ( nTrackFlags & STARTTRACK_BUTTONREPEAT )
1395*cdf0e10cSrcweir             Click();
1396*cdf0e10cSrcweir     }
1397*cdf0e10cSrcweir }
1398*cdf0e10cSrcweir 
1399*cdf0e10cSrcweir // -----------------------------------------------------------------------
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir void PushButton::Tracking( const TrackingEvent& rTEvt )
1402*cdf0e10cSrcweir {
1403*cdf0e10cSrcweir     if ( rTEvt.IsTrackingEnded() )
1404*cdf0e10cSrcweir     {
1405*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
1406*cdf0e10cSrcweir         {
1407*cdf0e10cSrcweir             if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() )
1408*cdf0e10cSrcweir                 GrabFocus();
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir             if ( GetStyle() & WB_TOGGLE )
1411*cdf0e10cSrcweir             {
1412*cdf0e10cSrcweir                 // Don't toggle, when aborted
1413*cdf0e10cSrcweir                 if ( !rTEvt.IsTrackingCanceled() )
1414*cdf0e10cSrcweir                 {
1415*cdf0e10cSrcweir                     if ( IsChecked() )
1416*cdf0e10cSrcweir                     {
1417*cdf0e10cSrcweir                         Check( sal_False );
1418*cdf0e10cSrcweir                         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1419*cdf0e10cSrcweir                     }
1420*cdf0e10cSrcweir                     else
1421*cdf0e10cSrcweir                         Check( sal_True );
1422*cdf0e10cSrcweir                 }
1423*cdf0e10cSrcweir             }
1424*cdf0e10cSrcweir             else
1425*cdf0e10cSrcweir                 ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir             ImplDrawPushButton();
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir             // Bei Abbruch kein Click-Handler rufen
1430*cdf0e10cSrcweir             if ( !rTEvt.IsTrackingCanceled() )
1431*cdf0e10cSrcweir             {
1432*cdf0e10cSrcweir                 if ( ! ( ( GetStyle() & WB_REPEAT ) &&
1433*cdf0e10cSrcweir                          ! ( GetStyle() & WB_TOGGLE ) ) )
1434*cdf0e10cSrcweir                     Click();
1435*cdf0e10cSrcweir             }
1436*cdf0e10cSrcweir         }
1437*cdf0e10cSrcweir     }
1438*cdf0e10cSrcweir     else
1439*cdf0e10cSrcweir     {
1440*cdf0e10cSrcweir         if ( ImplHitTestPushButton( this, rTEvt.GetMouseEvent().GetPosPixel() ) )
1441*cdf0e10cSrcweir         {
1442*cdf0e10cSrcweir             if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
1443*cdf0e10cSrcweir             {
1444*cdf0e10cSrcweir                 if ( rTEvt.IsTrackingRepeat() && (GetStyle() & WB_REPEAT) &&
1445*cdf0e10cSrcweir                      ! ( GetStyle() & WB_TOGGLE ) )
1446*cdf0e10cSrcweir                     Click();
1447*cdf0e10cSrcweir             }
1448*cdf0e10cSrcweir             else
1449*cdf0e10cSrcweir             {
1450*cdf0e10cSrcweir                 ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
1451*cdf0e10cSrcweir                 ImplDrawPushButton();
1452*cdf0e10cSrcweir             }
1453*cdf0e10cSrcweir         }
1454*cdf0e10cSrcweir         else
1455*cdf0e10cSrcweir         {
1456*cdf0e10cSrcweir             if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
1457*cdf0e10cSrcweir             {
1458*cdf0e10cSrcweir                 ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1459*cdf0e10cSrcweir                 ImplDrawPushButton();
1460*cdf0e10cSrcweir             }
1461*cdf0e10cSrcweir         }
1462*cdf0e10cSrcweir     }
1463*cdf0e10cSrcweir }
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir // -----------------------------------------------------------------------
1466*cdf0e10cSrcweir 
1467*cdf0e10cSrcweir void PushButton::KeyInput( const KeyEvent& rKEvt )
1468*cdf0e10cSrcweir {
1469*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir     if ( !aKeyCode.GetModifier() &&
1472*cdf0e10cSrcweir          ((aKeyCode.GetCode() == KEY_RETURN) || (aKeyCode.GetCode() == KEY_SPACE)) )
1473*cdf0e10cSrcweir     {
1474*cdf0e10cSrcweir         if ( !(ImplGetButtonState() & BUTTON_DRAW_PRESSED) )
1475*cdf0e10cSrcweir         {
1476*cdf0e10cSrcweir             ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
1477*cdf0e10cSrcweir             ImplDrawPushButton();
1478*cdf0e10cSrcweir         }
1479*cdf0e10cSrcweir 
1480*cdf0e10cSrcweir         if ( ( GetStyle() & WB_REPEAT ) &&
1481*cdf0e10cSrcweir              ! ( GetStyle() & WB_TOGGLE ) )
1482*cdf0e10cSrcweir             Click();
1483*cdf0e10cSrcweir     }
1484*cdf0e10cSrcweir     else if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) && (aKeyCode.GetCode() == KEY_ESCAPE) )
1485*cdf0e10cSrcweir     {
1486*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1487*cdf0e10cSrcweir         ImplDrawPushButton();
1488*cdf0e10cSrcweir     }
1489*cdf0e10cSrcweir     else
1490*cdf0e10cSrcweir         Button::KeyInput( rKEvt );
1491*cdf0e10cSrcweir }
1492*cdf0e10cSrcweir 
1493*cdf0e10cSrcweir // -----------------------------------------------------------------------
1494*cdf0e10cSrcweir 
1495*cdf0e10cSrcweir void PushButton::KeyUp( const KeyEvent& rKEvt )
1496*cdf0e10cSrcweir {
1497*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
1498*cdf0e10cSrcweir 
1499*cdf0e10cSrcweir     if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) &&
1500*cdf0e10cSrcweir          ((aKeyCode.GetCode() == KEY_RETURN) || (aKeyCode.GetCode() == KEY_SPACE)) )
1501*cdf0e10cSrcweir     {
1502*cdf0e10cSrcweir         if ( GetStyle() & WB_TOGGLE )
1503*cdf0e10cSrcweir         {
1504*cdf0e10cSrcweir             if ( IsChecked() )
1505*cdf0e10cSrcweir             {
1506*cdf0e10cSrcweir                 Check( sal_False );
1507*cdf0e10cSrcweir                 ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1508*cdf0e10cSrcweir             }
1509*cdf0e10cSrcweir             else
1510*cdf0e10cSrcweir                 Check( sal_True );
1511*cdf0e10cSrcweir 
1512*cdf0e10cSrcweir             Toggle();
1513*cdf0e10cSrcweir         }
1514*cdf0e10cSrcweir         else
1515*cdf0e10cSrcweir             ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1516*cdf0e10cSrcweir 
1517*cdf0e10cSrcweir         ImplDrawPushButton();
1518*cdf0e10cSrcweir 
1519*cdf0e10cSrcweir         if ( !( ( GetStyle() & WB_REPEAT )  &&
1520*cdf0e10cSrcweir                 ! ( GetStyle() & WB_TOGGLE ) ) )
1521*cdf0e10cSrcweir             Click();
1522*cdf0e10cSrcweir     }
1523*cdf0e10cSrcweir     else
1524*cdf0e10cSrcweir         Button::KeyUp( rKEvt );
1525*cdf0e10cSrcweir }
1526*cdf0e10cSrcweir 
1527*cdf0e10cSrcweir // -----------------------------------------------------------------------
1528*cdf0e10cSrcweir 
1529*cdf0e10cSrcweir void PushButton::FillLayoutData() const
1530*cdf0e10cSrcweir {
1531*cdf0e10cSrcweir     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
1532*cdf0e10cSrcweir     const_cast<PushButton*>(this)->ImplDrawPushButton( true );
1533*cdf0e10cSrcweir }
1534*cdf0e10cSrcweir 
1535*cdf0e10cSrcweir // -----------------------------------------------------------------------
1536*cdf0e10cSrcweir 
1537*cdf0e10cSrcweir void PushButton::Paint( const Rectangle& )
1538*cdf0e10cSrcweir {
1539*cdf0e10cSrcweir     ImplDrawPushButton();
1540*cdf0e10cSrcweir }
1541*cdf0e10cSrcweir 
1542*cdf0e10cSrcweir // -----------------------------------------------------------------------
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir void PushButton::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
1545*cdf0e10cSrcweir                        sal_uLong nFlags )
1546*cdf0e10cSrcweir {
1547*cdf0e10cSrcweir     Point       aPos  = pDev->LogicToPixel( rPos );
1548*cdf0e10cSrcweir     Size        aSize = pDev->LogicToPixel( rSize );
1549*cdf0e10cSrcweir     Rectangle   aRect( aPos, aSize );
1550*cdf0e10cSrcweir     Rectangle   aTextRect;
1551*cdf0e10cSrcweir     Font        aFont = GetDrawPixelFont( pDev );
1552*cdf0e10cSrcweir 
1553*cdf0e10cSrcweir     pDev->Push();
1554*cdf0e10cSrcweir     pDev->SetMapMode();
1555*cdf0e10cSrcweir     pDev->SetFont( aFont );
1556*cdf0e10cSrcweir     if ( nFlags & WINDOW_DRAW_MONO )
1557*cdf0e10cSrcweir 	{
1558*cdf0e10cSrcweir         pDev->SetTextColor( Color( COL_BLACK ) );
1559*cdf0e10cSrcweir 	}
1560*cdf0e10cSrcweir     else
1561*cdf0e10cSrcweir 	{
1562*cdf0e10cSrcweir         pDev->SetTextColor( GetTextColor() );
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir 		// DecoView uses the FaceColor...
1565*cdf0e10cSrcweir 		AllSettings aSettings = pDev->GetSettings();
1566*cdf0e10cSrcweir 		StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1567*cdf0e10cSrcweir 		if ( IsControlBackground() )
1568*cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetControlBackground() );
1569*cdf0e10cSrcweir 		else
1570*cdf0e10cSrcweir 			aStyleSettings.SetFaceColor( GetSettings().GetStyleSettings().GetFaceColor() );
1571*cdf0e10cSrcweir 		aSettings.SetStyleSettings( aStyleSettings );
1572*cdf0e10cSrcweir 		pDev->SetSettings( aSettings );
1573*cdf0e10cSrcweir 	}
1574*cdf0e10cSrcweir     pDev->SetTextFillColor();
1575*cdf0e10cSrcweir 
1576*cdf0e10cSrcweir     DecorationView aDecoView( pDev );
1577*cdf0e10cSrcweir     sal_uInt16 nButtonStyle = 0;
1578*cdf0e10cSrcweir     if ( nFlags & WINDOW_DRAW_MONO )
1579*cdf0e10cSrcweir         nButtonStyle |= BUTTON_DRAW_MONO;
1580*cdf0e10cSrcweir     if ( IsChecked() )
1581*cdf0e10cSrcweir         nButtonStyle |= BUTTON_DRAW_CHECKED;
1582*cdf0e10cSrcweir     aRect = aDecoView.DrawButton( aRect, nButtonStyle );
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir     ImplDrawPushButtonContent( pDev, nFlags, aRect, false, true );
1585*cdf0e10cSrcweir     pDev->Pop();
1586*cdf0e10cSrcweir }
1587*cdf0e10cSrcweir 
1588*cdf0e10cSrcweir // -----------------------------------------------------------------------
1589*cdf0e10cSrcweir 
1590*cdf0e10cSrcweir void PushButton::Resize()
1591*cdf0e10cSrcweir {
1592*cdf0e10cSrcweir     Control::Resize();
1593*cdf0e10cSrcweir     Invalidate();
1594*cdf0e10cSrcweir }
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir // -----------------------------------------------------------------------
1597*cdf0e10cSrcweir 
1598*cdf0e10cSrcweir void PushButton::GetFocus()
1599*cdf0e10cSrcweir {
1600*cdf0e10cSrcweir     ShowFocus( ImplGetFocusRect() );
1601*cdf0e10cSrcweir     SetInputContext( InputContext( GetFont() ) );
1602*cdf0e10cSrcweir     Button::GetFocus();
1603*cdf0e10cSrcweir }
1604*cdf0e10cSrcweir 
1605*cdf0e10cSrcweir // -----------------------------------------------------------------------
1606*cdf0e10cSrcweir 
1607*cdf0e10cSrcweir void PushButton::LoseFocus()
1608*cdf0e10cSrcweir {
1609*cdf0e10cSrcweir     EndSelection();
1610*cdf0e10cSrcweir     HideFocus();
1611*cdf0e10cSrcweir     Button::LoseFocus();
1612*cdf0e10cSrcweir }
1613*cdf0e10cSrcweir 
1614*cdf0e10cSrcweir // -----------------------------------------------------------------------
1615*cdf0e10cSrcweir 
1616*cdf0e10cSrcweir void PushButton::StateChanged( StateChangedType nType )
1617*cdf0e10cSrcweir {
1618*cdf0e10cSrcweir     Button::StateChanged( nType );
1619*cdf0e10cSrcweir 
1620*cdf0e10cSrcweir     if ( (nType == STATE_CHANGE_ENABLE) ||
1621*cdf0e10cSrcweir          (nType == STATE_CHANGE_TEXT) ||
1622*cdf0e10cSrcweir          (nType == STATE_CHANGE_IMAGE) ||
1623*cdf0e10cSrcweir          (nType == STATE_CHANGE_DATA) ||
1624*cdf0e10cSrcweir          (nType == STATE_CHANGE_STATE) ||
1625*cdf0e10cSrcweir          (nType == STATE_CHANGE_UPDATEMODE) )
1626*cdf0e10cSrcweir     {
1627*cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1628*cdf0e10cSrcweir             Invalidate();
1629*cdf0e10cSrcweir     }
1630*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_STYLE )
1631*cdf0e10cSrcweir     {
1632*cdf0e10cSrcweir         SetStyle( ImplInitStyle( GetWindow( WINDOW_PREV ), GetStyle() ) );
1633*cdf0e10cSrcweir 
1634*cdf0e10cSrcweir         bool bIsDefButton = ( GetStyle() & WB_DEFBUTTON ) != 0;
1635*cdf0e10cSrcweir         bool bWasDefButton = ( GetPrevStyle() & WB_DEFBUTTON ) != 0;
1636*cdf0e10cSrcweir         if ( bIsDefButton != bWasDefButton )
1637*cdf0e10cSrcweir             ImplSetDefButton( bIsDefButton );
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
1640*cdf0e10cSrcweir         {
1641*cdf0e10cSrcweir             if ( (GetPrevStyle() & PUSHBUTTON_VIEW_STYLE) !=
1642*cdf0e10cSrcweir                  (GetStyle() & PUSHBUTTON_VIEW_STYLE) )
1643*cdf0e10cSrcweir                 Invalidate();
1644*cdf0e10cSrcweir         }
1645*cdf0e10cSrcweir     }
1646*cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ZOOM) ||
1647*cdf0e10cSrcweir               (nType == STATE_CHANGE_CONTROLFONT) )
1648*cdf0e10cSrcweir     {
1649*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
1650*cdf0e10cSrcweir         Invalidate();
1651*cdf0e10cSrcweir     }
1652*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
1653*cdf0e10cSrcweir     {
1654*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
1655*cdf0e10cSrcweir         Invalidate();
1656*cdf0e10cSrcweir     }
1657*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
1658*cdf0e10cSrcweir     {
1659*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
1660*cdf0e10cSrcweir         Invalidate();
1661*cdf0e10cSrcweir     }
1662*cdf0e10cSrcweir }
1663*cdf0e10cSrcweir 
1664*cdf0e10cSrcweir // -----------------------------------------------------------------------
1665*cdf0e10cSrcweir 
1666*cdf0e10cSrcweir void PushButton::DataChanged( const DataChangedEvent& rDCEvt )
1667*cdf0e10cSrcweir {
1668*cdf0e10cSrcweir     Button::DataChanged( rDCEvt );
1669*cdf0e10cSrcweir 
1670*cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1671*cdf0e10cSrcweir          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1672*cdf0e10cSrcweir          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1673*cdf0e10cSrcweir           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1674*cdf0e10cSrcweir     {
1675*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
1676*cdf0e10cSrcweir         Invalidate();
1677*cdf0e10cSrcweir     }
1678*cdf0e10cSrcweir }
1679*cdf0e10cSrcweir 
1680*cdf0e10cSrcweir // -----------------------------------------------------------------------
1681*cdf0e10cSrcweir 
1682*cdf0e10cSrcweir long PushButton::PreNotify( NotifyEvent& rNEvt )
1683*cdf0e10cSrcweir {
1684*cdf0e10cSrcweir     long nDone = 0;
1685*cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
1688*cdf0e10cSrcweir     {
1689*cdf0e10cSrcweir         if( pMouseEvt->IsEnterWindow() || pMouseEvt->IsLeaveWindow() )
1690*cdf0e10cSrcweir         {
1691*cdf0e10cSrcweir             // trigger redraw as mouse over state has changed
1692*cdf0e10cSrcweir 
1693*cdf0e10cSrcweir             // TODO: move this to Window class or make it a member !!!
1694*cdf0e10cSrcweir             ControlType aCtrlType = 0;
1695*cdf0e10cSrcweir             switch( GetParent()->GetType() )
1696*cdf0e10cSrcweir             {
1697*cdf0e10cSrcweir                 case WINDOW_LISTBOX:
1698*cdf0e10cSrcweir                 case WINDOW_MULTILISTBOX:
1699*cdf0e10cSrcweir                 case WINDOW_TREELISTBOX:
1700*cdf0e10cSrcweir                     aCtrlType = CTRL_LISTBOX;
1701*cdf0e10cSrcweir                     break;
1702*cdf0e10cSrcweir 
1703*cdf0e10cSrcweir                 case WINDOW_COMBOBOX:
1704*cdf0e10cSrcweir                 case WINDOW_PATTERNBOX:
1705*cdf0e10cSrcweir                 case WINDOW_NUMERICBOX:
1706*cdf0e10cSrcweir                 case WINDOW_METRICBOX:
1707*cdf0e10cSrcweir                 case WINDOW_CURRENCYBOX:
1708*cdf0e10cSrcweir                 case WINDOW_DATEBOX:
1709*cdf0e10cSrcweir                 case WINDOW_TIMEBOX:
1710*cdf0e10cSrcweir                 case WINDOW_LONGCURRENCYBOX:
1711*cdf0e10cSrcweir                     aCtrlType = CTRL_COMBOBOX;
1712*cdf0e10cSrcweir                     break;
1713*cdf0e10cSrcweir                 default:
1714*cdf0e10cSrcweir                     break;
1715*cdf0e10cSrcweir             }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir             sal_Bool bDropDown = ( IsSymbol() && (GetSymbol()==SYMBOL_SPIN_DOWN) && !GetText().Len() );
1718*cdf0e10cSrcweir 
1719*cdf0e10cSrcweir             if( bDropDown && GetParent()->IsNativeControlSupported( aCtrlType, PART_ENTIRE_CONTROL) &&
1720*cdf0e10cSrcweir                    !GetParent()->IsNativeControlSupported( aCtrlType, PART_BUTTON_DOWN) )
1721*cdf0e10cSrcweir             {
1722*cdf0e10cSrcweir                 Window *pBorder = GetParent()->GetWindow( WINDOW_BORDER );
1723*cdf0e10cSrcweir                 if(aCtrlType == CTRL_COMBOBOX)
1724*cdf0e10cSrcweir                 {
1725*cdf0e10cSrcweir                     // only paint the button part to avoid flickering of the combobox text
1726*cdf0e10cSrcweir                     Point aPt;
1727*cdf0e10cSrcweir                     Rectangle aClipRect( aPt, GetOutputSizePixel() );
1728*cdf0e10cSrcweir                     aClipRect.SetPos(pBorder->ScreenToOutputPixel(OutputToScreenPixel(aClipRect.TopLeft())));
1729*cdf0e10cSrcweir                     pBorder->Invalidate( aClipRect );
1730*cdf0e10cSrcweir                 }
1731*cdf0e10cSrcweir                 else
1732*cdf0e10cSrcweir                 {
1733*cdf0e10cSrcweir                     pBorder->Invalidate( INVALIDATE_NOERASE );
1734*cdf0e10cSrcweir                     pBorder->Update();
1735*cdf0e10cSrcweir                 }
1736*cdf0e10cSrcweir             }
1737*cdf0e10cSrcweir             else if( (GetStyle() & WB_FLATBUTTON) ||
1738*cdf0e10cSrcweir                      IsNativeControlSupported(CTRL_PUSHBUTTON, PART_ENTIRE_CONTROL) )
1739*cdf0e10cSrcweir             {
1740*cdf0e10cSrcweir                 Invalidate();
1741*cdf0e10cSrcweir             }
1742*cdf0e10cSrcweir         }
1743*cdf0e10cSrcweir     }
1744*cdf0e10cSrcweir 
1745*cdf0e10cSrcweir     return nDone ? nDone : Button::PreNotify(rNEvt);
1746*cdf0e10cSrcweir }
1747*cdf0e10cSrcweir 
1748*cdf0e10cSrcweir // -----------------------------------------------------------------------
1749*cdf0e10cSrcweir 
1750*cdf0e10cSrcweir void PushButton::Toggle()
1751*cdf0e10cSrcweir {
1752*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_PUSHBUTTON_TOGGLE, maToggleHdl, this );
1753*cdf0e10cSrcweir }
1754*cdf0e10cSrcweir 
1755*cdf0e10cSrcweir // -----------------------------------------------------------------------
1756*cdf0e10cSrcweir 
1757*cdf0e10cSrcweir void PushButton::SetSymbol( SymbolType eSymbol )
1758*cdf0e10cSrcweir {
1759*cdf0e10cSrcweir     if ( meSymbol != eSymbol )
1760*cdf0e10cSrcweir     {
1761*cdf0e10cSrcweir         meSymbol = eSymbol;
1762*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1763*cdf0e10cSrcweir     }
1764*cdf0e10cSrcweir }
1765*cdf0e10cSrcweir 
1766*cdf0e10cSrcweir // -----------------------------------------------------------------------
1767*cdf0e10cSrcweir void PushButton::SetSymbolAlign( SymbolAlign eAlign )
1768*cdf0e10cSrcweir {
1769*cdf0e10cSrcweir     ImplSetSymbolAlign( eAlign );
1770*cdf0e10cSrcweir }
1771*cdf0e10cSrcweir 
1772*cdf0e10cSrcweir // -----------------------------------------------------------------------
1773*cdf0e10cSrcweir SymbolAlign PushButton::GetSymbolAlign() const
1774*cdf0e10cSrcweir {
1775*cdf0e10cSrcweir     return ImplGetSymbolAlign();
1776*cdf0e10cSrcweir }
1777*cdf0e10cSrcweir 
1778*cdf0e10cSrcweir // -----------------------------------------------------------------------
1779*cdf0e10cSrcweir 
1780*cdf0e10cSrcweir void PushButton::SetDropDown( sal_uInt16 nStyle )
1781*cdf0e10cSrcweir {
1782*cdf0e10cSrcweir     if ( mnDDStyle != nStyle )
1783*cdf0e10cSrcweir     {
1784*cdf0e10cSrcweir         mnDDStyle = nStyle;
1785*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1786*cdf0e10cSrcweir     }
1787*cdf0e10cSrcweir }
1788*cdf0e10cSrcweir 
1789*cdf0e10cSrcweir // -----------------------------------------------------------------------
1790*cdf0e10cSrcweir 
1791*cdf0e10cSrcweir void PushButton::SetState( TriState eState )
1792*cdf0e10cSrcweir {
1793*cdf0e10cSrcweir     if ( meState != eState )
1794*cdf0e10cSrcweir     {
1795*cdf0e10cSrcweir         meState = eState;
1796*cdf0e10cSrcweir         if ( meState == STATE_NOCHECK )
1797*cdf0e10cSrcweir             ImplGetButtonState() &= ~(BUTTON_DRAW_CHECKED | BUTTON_DRAW_DONTKNOW);
1798*cdf0e10cSrcweir         else if ( meState == STATE_CHECK )
1799*cdf0e10cSrcweir         {
1800*cdf0e10cSrcweir             ImplGetButtonState() &= ~BUTTON_DRAW_DONTKNOW;
1801*cdf0e10cSrcweir             ImplGetButtonState() |= BUTTON_DRAW_CHECKED;
1802*cdf0e10cSrcweir         }
1803*cdf0e10cSrcweir         else // STATE_DONTKNOW
1804*cdf0e10cSrcweir         {
1805*cdf0e10cSrcweir             ImplGetButtonState() &= ~BUTTON_DRAW_CHECKED;
1806*cdf0e10cSrcweir             ImplGetButtonState() |= BUTTON_DRAW_DONTKNOW;
1807*cdf0e10cSrcweir         }
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_STATE );
1810*cdf0e10cSrcweir         Toggle();
1811*cdf0e10cSrcweir     }
1812*cdf0e10cSrcweir }
1813*cdf0e10cSrcweir 
1814*cdf0e10cSrcweir // -----------------------------------------------------------------------
1815*cdf0e10cSrcweir 
1816*cdf0e10cSrcweir void PushButton::SetPressed( sal_Bool bPressed )
1817*cdf0e10cSrcweir {
1818*cdf0e10cSrcweir     if ( mbPressed != bPressed )
1819*cdf0e10cSrcweir     {
1820*cdf0e10cSrcweir         mbPressed = bPressed;
1821*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
1822*cdf0e10cSrcweir     }
1823*cdf0e10cSrcweir }
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir // -----------------------------------------------------------------------
1826*cdf0e10cSrcweir 
1827*cdf0e10cSrcweir void PushButton::EndSelection()
1828*cdf0e10cSrcweir {
1829*cdf0e10cSrcweir     EndTracking( ENDTRACK_CANCEL );
1830*cdf0e10cSrcweir     if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
1831*cdf0e10cSrcweir     {
1832*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
1833*cdf0e10cSrcweir         if ( !mbPressed )
1834*cdf0e10cSrcweir             ImplDrawPushButton();
1835*cdf0e10cSrcweir     }
1836*cdf0e10cSrcweir }
1837*cdf0e10cSrcweir 
1838*cdf0e10cSrcweir // -----------------------------------------------------------------------
1839*cdf0e10cSrcweir 
1840*cdf0e10cSrcweir Size PushButton::CalcMinimumSize( long nMaxWidth ) const
1841*cdf0e10cSrcweir {
1842*cdf0e10cSrcweir 	Size aSize;
1843*cdf0e10cSrcweir 
1844*cdf0e10cSrcweir 	if ( IsSymbol() )
1845*cdf0e10cSrcweir     {
1846*cdf0e10cSrcweir         if ( IsSmallSymbol ())
1847*cdf0e10cSrcweir             aSize = Size( 16, 12 );
1848*cdf0e10cSrcweir         else
1849*cdf0e10cSrcweir             aSize = Size( 26, 24 );
1850*cdf0e10cSrcweir         if( mnDDStyle == PUSHBUTTON_DROPDOWN_MENUBUTTON )
1851*cdf0e10cSrcweir             aSize.Width() += 4;
1852*cdf0e10cSrcweir     }
1853*cdf0e10cSrcweir 	else if ( IsImage() && ! (ImplGetButtonState() & BUTTON_DRAW_NOIMAGE) )
1854*cdf0e10cSrcweir 		aSize = GetModeImage().GetSizePixel();
1855*cdf0e10cSrcweir 	if ( PushButton::GetText().Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
1856*cdf0e10cSrcweir 	{
1857*cdf0e10cSrcweir 		sal_uLong nDrawFlags = 0;
1858*cdf0e10cSrcweir 		Size textSize = GetTextRect( Rectangle( Point(), Size( nMaxWidth ? nMaxWidth : 0x7fffffff, 0x7fffffff ) ),
1859*cdf0e10cSrcweir 									 PushButton::GetText(), ImplGetTextStyle( nDrawFlags ) ).GetSize();
1860*cdf0e10cSrcweir 	   aSize.Width() += int( textSize.Width () * 1.15 );
1861*cdf0e10cSrcweir 	   aSize.Height() = std::max( aSize.Height(), long( textSize.Height() * 1.15 ) );
1862*cdf0e10cSrcweir 	}
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir 	// cf. ImplDrawPushButton ...
1865*cdf0e10cSrcweir     if( (GetStyle() & WB_SMALLSTYLE) == 0 )
1866*cdf0e10cSrcweir     {
1867*cdf0e10cSrcweir         aSize.Width() += 8;
1868*cdf0e10cSrcweir         aSize.Height() += 8;
1869*cdf0e10cSrcweir     }
1870*cdf0e10cSrcweir 
1871*cdf0e10cSrcweir     return CalcWindowSize( aSize );
1872*cdf0e10cSrcweir }
1873*cdf0e10cSrcweir 
1874*cdf0e10cSrcweir Size PushButton::GetOptimalSize(WindowSizeType eType) const
1875*cdf0e10cSrcweir {
1876*cdf0e10cSrcweir     switch (eType) {
1877*cdf0e10cSrcweir     case WINDOWSIZE_MINIMUM: {
1878*cdf0e10cSrcweir         return CalcMinimumSize();
1879*cdf0e10cSrcweir     }
1880*cdf0e10cSrcweir     default:
1881*cdf0e10cSrcweir         return Button::GetOptimalSize( eType );
1882*cdf0e10cSrcweir     }
1883*cdf0e10cSrcweir }
1884*cdf0e10cSrcweir 
1885*cdf0e10cSrcweir // =======================================================================
1886*cdf0e10cSrcweir 
1887*cdf0e10cSrcweir void OKButton::ImplInit( Window* pParent, WinBits nStyle )
1888*cdf0e10cSrcweir {
1889*cdf0e10cSrcweir     PushButton::ImplInit( pParent, nStyle );
1890*cdf0e10cSrcweir 
1891*cdf0e10cSrcweir     SetText( Button::GetStandardText( BUTTON_OK ) );
1892*cdf0e10cSrcweir     SetHelpText( Button::GetStandardHelpText( BUTTON_OK ) );
1893*cdf0e10cSrcweir }
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir // -----------------------------------------------------------------------
1896*cdf0e10cSrcweir 
1897*cdf0e10cSrcweir OKButton::OKButton( Window* pParent, WinBits nStyle ) :
1898*cdf0e10cSrcweir     PushButton( WINDOW_OKBUTTON )
1899*cdf0e10cSrcweir {
1900*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1901*cdf0e10cSrcweir }
1902*cdf0e10cSrcweir 
1903*cdf0e10cSrcweir // -----------------------------------------------------------------------
1904*cdf0e10cSrcweir 
1905*cdf0e10cSrcweir OKButton::OKButton( Window* pParent, const ResId& rResId ) :
1906*cdf0e10cSrcweir     PushButton( WINDOW_OKBUTTON )
1907*cdf0e10cSrcweir {
1908*cdf0e10cSrcweir     rResId.SetRT( RSC_OKBUTTON );
1909*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
1910*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1911*cdf0e10cSrcweir     ImplLoadRes( rResId );
1912*cdf0e10cSrcweir 
1913*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
1914*cdf0e10cSrcweir         Show();
1915*cdf0e10cSrcweir }
1916*cdf0e10cSrcweir 
1917*cdf0e10cSrcweir // -----------------------------------------------------------------------
1918*cdf0e10cSrcweir 
1919*cdf0e10cSrcweir void OKButton::Click()
1920*cdf0e10cSrcweir {
1921*cdf0e10cSrcweir     // Ist kein Link gesetzt, dann schliesse Parent
1922*cdf0e10cSrcweir     if ( !GetClickHdl() )
1923*cdf0e10cSrcweir     {
1924*cdf0e10cSrcweir         Window* pParent = GetParent();
1925*cdf0e10cSrcweir         if ( pParent->IsSystemWindow() )
1926*cdf0e10cSrcweir         {
1927*cdf0e10cSrcweir             if ( pParent->IsDialog() )
1928*cdf0e10cSrcweir             {
1929*cdf0e10cSrcweir                 if ( ((Dialog*)pParent)->IsInExecute() )
1930*cdf0e10cSrcweir                     ((Dialog*)pParent)->EndDialog( sal_True );
1931*cdf0e10cSrcweir                 // gegen rekursive Aufrufe schuetzen
1932*cdf0e10cSrcweir                 else if ( !((Dialog*)pParent)->IsInClose() )
1933*cdf0e10cSrcweir                 {
1934*cdf0e10cSrcweir                     if ( pParent->GetStyle() & WB_CLOSEABLE )
1935*cdf0e10cSrcweir                         ((Dialog*)pParent)->Close();
1936*cdf0e10cSrcweir                 }
1937*cdf0e10cSrcweir             }
1938*cdf0e10cSrcweir             else
1939*cdf0e10cSrcweir             {
1940*cdf0e10cSrcweir                 if ( pParent->GetStyle() & WB_CLOSEABLE )
1941*cdf0e10cSrcweir                     ((SystemWindow*)pParent)->Close();
1942*cdf0e10cSrcweir             }
1943*cdf0e10cSrcweir         }
1944*cdf0e10cSrcweir     }
1945*cdf0e10cSrcweir     else
1946*cdf0e10cSrcweir     {
1947*cdf0e10cSrcweir         PushButton::Click();
1948*cdf0e10cSrcweir     }
1949*cdf0e10cSrcweir }
1950*cdf0e10cSrcweir 
1951*cdf0e10cSrcweir // =======================================================================
1952*cdf0e10cSrcweir 
1953*cdf0e10cSrcweir void CancelButton::ImplInit( Window* pParent, WinBits nStyle )
1954*cdf0e10cSrcweir {
1955*cdf0e10cSrcweir     PushButton::ImplInit( pParent, nStyle );
1956*cdf0e10cSrcweir 
1957*cdf0e10cSrcweir     SetText( Button::GetStandardText( BUTTON_CANCEL ) );
1958*cdf0e10cSrcweir     SetHelpText( Button::GetStandardHelpText( BUTTON_CANCEL ) );
1959*cdf0e10cSrcweir }
1960*cdf0e10cSrcweir 
1961*cdf0e10cSrcweir // -----------------------------------------------------------------------
1962*cdf0e10cSrcweir 
1963*cdf0e10cSrcweir CancelButton::CancelButton( Window* pParent, WinBits nStyle ) :
1964*cdf0e10cSrcweir     PushButton( WINDOW_CANCELBUTTON )
1965*cdf0e10cSrcweir {
1966*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1967*cdf0e10cSrcweir }
1968*cdf0e10cSrcweir 
1969*cdf0e10cSrcweir // -----------------------------------------------------------------------
1970*cdf0e10cSrcweir 
1971*cdf0e10cSrcweir CancelButton::CancelButton( Window* pParent, const ResId& rResId ) :
1972*cdf0e10cSrcweir     PushButton( WINDOW_CANCELBUTTON )
1973*cdf0e10cSrcweir {
1974*cdf0e10cSrcweir     rResId.SetRT( RSC_CANCELBUTTON );
1975*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
1976*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
1977*cdf0e10cSrcweir     ImplLoadRes( rResId );
1978*cdf0e10cSrcweir 
1979*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
1980*cdf0e10cSrcweir         Show();
1981*cdf0e10cSrcweir }
1982*cdf0e10cSrcweir 
1983*cdf0e10cSrcweir // -----------------------------------------------------------------------
1984*cdf0e10cSrcweir 
1985*cdf0e10cSrcweir void CancelButton::Click()
1986*cdf0e10cSrcweir {
1987*cdf0e10cSrcweir     // Ist kein Link gesetzt, dann schliesse Parent
1988*cdf0e10cSrcweir     if ( !GetClickHdl() )
1989*cdf0e10cSrcweir     {
1990*cdf0e10cSrcweir         Window* pParent = GetParent();
1991*cdf0e10cSrcweir         if ( pParent->IsSystemWindow() )
1992*cdf0e10cSrcweir         {
1993*cdf0e10cSrcweir             if ( pParent->IsDialog() )
1994*cdf0e10cSrcweir             {
1995*cdf0e10cSrcweir                 if ( ((Dialog*)pParent)->IsInExecute() )
1996*cdf0e10cSrcweir                     ((Dialog*)pParent)->EndDialog( sal_False );
1997*cdf0e10cSrcweir                 // gegen rekursive Aufrufe schuetzen
1998*cdf0e10cSrcweir                 else if ( !((Dialog*)pParent)->IsInClose() )
1999*cdf0e10cSrcweir                 {
2000*cdf0e10cSrcweir                     if ( pParent->GetStyle() & WB_CLOSEABLE )
2001*cdf0e10cSrcweir                         ((Dialog*)pParent)->Close();
2002*cdf0e10cSrcweir                 }
2003*cdf0e10cSrcweir             }
2004*cdf0e10cSrcweir             else
2005*cdf0e10cSrcweir             {
2006*cdf0e10cSrcweir                 if ( pParent->GetStyle() & WB_CLOSEABLE )
2007*cdf0e10cSrcweir                     ((SystemWindow*)pParent)->Close();
2008*cdf0e10cSrcweir             }
2009*cdf0e10cSrcweir         }
2010*cdf0e10cSrcweir     }
2011*cdf0e10cSrcweir     else
2012*cdf0e10cSrcweir     {
2013*cdf0e10cSrcweir         PushButton::Click();
2014*cdf0e10cSrcweir     }
2015*cdf0e10cSrcweir }
2016*cdf0e10cSrcweir 
2017*cdf0e10cSrcweir // =======================================================================
2018*cdf0e10cSrcweir 
2019*cdf0e10cSrcweir void HelpButton::ImplInit( Window* pParent, WinBits nStyle )
2020*cdf0e10cSrcweir {
2021*cdf0e10cSrcweir     PushButton::ImplInit( pParent, nStyle | WB_NOPOINTERFOCUS );
2022*cdf0e10cSrcweir 
2023*cdf0e10cSrcweir     SetText( Button::GetStandardText( BUTTON_HELP ) );
2024*cdf0e10cSrcweir     SetHelpText( Button::GetStandardHelpText( BUTTON_HELP ) );
2025*cdf0e10cSrcweir }
2026*cdf0e10cSrcweir 
2027*cdf0e10cSrcweir // -----------------------------------------------------------------------
2028*cdf0e10cSrcweir 
2029*cdf0e10cSrcweir HelpButton::HelpButton( Window* pParent, WinBits nStyle ) :
2030*cdf0e10cSrcweir     PushButton( WINDOW_HELPBUTTON )
2031*cdf0e10cSrcweir {
2032*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
2033*cdf0e10cSrcweir }
2034*cdf0e10cSrcweir 
2035*cdf0e10cSrcweir // -----------------------------------------------------------------------
2036*cdf0e10cSrcweir 
2037*cdf0e10cSrcweir HelpButton::HelpButton( Window* pParent, const ResId& rResId ) :
2038*cdf0e10cSrcweir     PushButton( WINDOW_HELPBUTTON )
2039*cdf0e10cSrcweir {
2040*cdf0e10cSrcweir     rResId.SetRT( RSC_HELPBUTTON );
2041*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
2042*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
2043*cdf0e10cSrcweir     ImplLoadRes( rResId );
2044*cdf0e10cSrcweir 
2045*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
2046*cdf0e10cSrcweir         Show();
2047*cdf0e10cSrcweir }
2048*cdf0e10cSrcweir 
2049*cdf0e10cSrcweir // -----------------------------------------------------------------------
2050*cdf0e10cSrcweir 
2051*cdf0e10cSrcweir void HelpButton::Click()
2052*cdf0e10cSrcweir {
2053*cdf0e10cSrcweir     // Ist kein Link gesetzt, loese Hilfe aus
2054*cdf0e10cSrcweir     if ( !GetClickHdl() )
2055*cdf0e10cSrcweir     {
2056*cdf0e10cSrcweir         Window* pFocusWin = Application::GetFocusWindow();
2057*cdf0e10cSrcweir         if ( !pFocusWin )
2058*cdf0e10cSrcweir             pFocusWin = this;
2059*cdf0e10cSrcweir 
2060*cdf0e10cSrcweir         HelpEvent aEvt( pFocusWin->GetPointerPosPixel(), HELPMODE_CONTEXT );
2061*cdf0e10cSrcweir         pFocusWin->RequestHelp( aEvt );
2062*cdf0e10cSrcweir     }
2063*cdf0e10cSrcweir     PushButton::Click();
2064*cdf0e10cSrcweir }
2065*cdf0e10cSrcweir 
2066*cdf0e10cSrcweir // =======================================================================
2067*cdf0e10cSrcweir 
2068*cdf0e10cSrcweir void RadioButton::ImplInitRadioButtonData()
2069*cdf0e10cSrcweir {
2070*cdf0e10cSrcweir     mbChecked       = sal_False;
2071*cdf0e10cSrcweir     mbSaveValue     = sal_False;
2072*cdf0e10cSrcweir     mbRadioCheck    = sal_True;
2073*cdf0e10cSrcweir     mbStateChanged  = sal_False;
2074*cdf0e10cSrcweir }
2075*cdf0e10cSrcweir 
2076*cdf0e10cSrcweir // -----------------------------------------------------------------------
2077*cdf0e10cSrcweir 
2078*cdf0e10cSrcweir void RadioButton::ImplInit( Window* pParent, WinBits nStyle )
2079*cdf0e10cSrcweir {
2080*cdf0e10cSrcweir     nStyle = ImplInitStyle( pParent->GetWindow( WINDOW_LASTCHILD ), nStyle );
2081*cdf0e10cSrcweir     Button::ImplInit( pParent, nStyle, NULL );
2082*cdf0e10cSrcweir 
2083*cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
2084*cdf0e10cSrcweir }
2085*cdf0e10cSrcweir 
2086*cdf0e10cSrcweir // -----------------------------------------------------------------------
2087*cdf0e10cSrcweir 
2088*cdf0e10cSrcweir WinBits RadioButton::ImplInitStyle( const Window* pPrevWindow, WinBits nStyle )
2089*cdf0e10cSrcweir {
2090*cdf0e10cSrcweir     if ( !(nStyle & WB_NOGROUP) &&
2091*cdf0e10cSrcweir          (!pPrevWindow || (pPrevWindow->GetType() != WINDOW_RADIOBUTTON)) )
2092*cdf0e10cSrcweir         nStyle |= WB_GROUP;
2093*cdf0e10cSrcweir     if ( !(nStyle & WB_NOTABSTOP) )
2094*cdf0e10cSrcweir     {
2095*cdf0e10cSrcweir         if ( IsChecked() )
2096*cdf0e10cSrcweir             nStyle |= WB_TABSTOP;
2097*cdf0e10cSrcweir         else
2098*cdf0e10cSrcweir             nStyle &= ~WB_TABSTOP;
2099*cdf0e10cSrcweir     }
2100*cdf0e10cSrcweir     return nStyle;
2101*cdf0e10cSrcweir }
2102*cdf0e10cSrcweir 
2103*cdf0e10cSrcweir // -----------------------------------------------------------------
2104*cdf0e10cSrcweir 
2105*cdf0e10cSrcweir const Font& RadioButton::GetCanonicalFont( const StyleSettings& _rStyle ) const
2106*cdf0e10cSrcweir {
2107*cdf0e10cSrcweir     return _rStyle.GetRadioCheckFont();
2108*cdf0e10cSrcweir }
2109*cdf0e10cSrcweir 
2110*cdf0e10cSrcweir // -----------------------------------------------------------------
2111*cdf0e10cSrcweir const Color& RadioButton::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
2112*cdf0e10cSrcweir {
2113*cdf0e10cSrcweir     return _rStyle.GetRadioCheckTextColor();
2114*cdf0e10cSrcweir }
2115*cdf0e10cSrcweir 
2116*cdf0e10cSrcweir // -----------------------------------------------------------------------
2117*cdf0e10cSrcweir 
2118*cdf0e10cSrcweir void RadioButton::ImplInitSettings( sal_Bool bFont,
2119*cdf0e10cSrcweir                                     sal_Bool bForeground, sal_Bool bBackground )
2120*cdf0e10cSrcweir {
2121*cdf0e10cSrcweir     Button::ImplInitSettings( bFont, bForeground );
2122*cdf0e10cSrcweir 
2123*cdf0e10cSrcweir     if ( bBackground )
2124*cdf0e10cSrcweir     {
2125*cdf0e10cSrcweir         Window* pParent = GetParent();
2126*cdf0e10cSrcweir         if ( !IsControlBackground() &&
2127*cdf0e10cSrcweir             (pParent->IsChildTransparentModeEnabled() || IsNativeControlSupported( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL ) ) )
2128*cdf0e10cSrcweir         {
2129*cdf0e10cSrcweir             EnableChildTransparentMode( sal_True );
2130*cdf0e10cSrcweir             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
2131*cdf0e10cSrcweir             SetPaintTransparent( sal_True );
2132*cdf0e10cSrcweir             SetBackground();
2133*cdf0e10cSrcweir             if( IsNativeControlSupported( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL ) )
2134*cdf0e10cSrcweir                 mpWindowImpl->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects;
2135*cdf0e10cSrcweir         }
2136*cdf0e10cSrcweir         else
2137*cdf0e10cSrcweir         {
2138*cdf0e10cSrcweir             EnableChildTransparentMode( sal_False );
2139*cdf0e10cSrcweir             SetParentClipMode( 0 );
2140*cdf0e10cSrcweir             SetPaintTransparent( sal_False );
2141*cdf0e10cSrcweir 
2142*cdf0e10cSrcweir             if ( IsControlBackground() )
2143*cdf0e10cSrcweir                 SetBackground( GetControlBackground() );
2144*cdf0e10cSrcweir             else
2145*cdf0e10cSrcweir                 SetBackground( pParent->GetBackground() );
2146*cdf0e10cSrcweir         }
2147*cdf0e10cSrcweir     }
2148*cdf0e10cSrcweir }
2149*cdf0e10cSrcweir 
2150*cdf0e10cSrcweir //---------------------------------------------------------------------
2151*cdf0e10cSrcweir //--- 12.03.2003 18:46:14 ---------------------------------------------
2152*cdf0e10cSrcweir 
2153*cdf0e10cSrcweir void RadioButton::DrawRadioButtonState( )
2154*cdf0e10cSrcweir {
2155*cdf0e10cSrcweir 	ImplDrawRadioButtonState( );
2156*cdf0e10cSrcweir }
2157*cdf0e10cSrcweir 
2158*cdf0e10cSrcweir // -----------------------------------------------------------------------
2159*cdf0e10cSrcweir 
2160*cdf0e10cSrcweir void RadioButton::ImplInvalidateOrDrawRadioButtonState()
2161*cdf0e10cSrcweir {
2162*cdf0e10cSrcweir     if( ImplGetSVData()->maNWFData.mbCheckBoxNeedsErase )
2163*cdf0e10cSrcweir     {
2164*cdf0e10cSrcweir         if ( IsNativeControlSupported(CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL) )
2165*cdf0e10cSrcweir         {
2166*cdf0e10cSrcweir             Invalidate();
2167*cdf0e10cSrcweir             Update();
2168*cdf0e10cSrcweir             return;
2169*cdf0e10cSrcweir         }
2170*cdf0e10cSrcweir     }
2171*cdf0e10cSrcweir     ImplDrawRadioButtonState();
2172*cdf0e10cSrcweir }
2173*cdf0e10cSrcweir 
2174*cdf0e10cSrcweir void RadioButton::ImplDrawRadioButtonState()
2175*cdf0e10cSrcweir {
2176*cdf0e10cSrcweir     sal_uInt16 nButtonStyle = 0;
2177*cdf0e10cSrcweir     sal_Bool   bNativeOK = sal_False;
2178*cdf0e10cSrcweir 
2179*cdf0e10cSrcweir     // no native drawing for image radio buttons
2180*cdf0e10cSrcweir     if ( !maImage && (bNativeOK=IsNativeControlSupported(CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL)) == sal_True )
2181*cdf0e10cSrcweir     {
2182*cdf0e10cSrcweir         ImplControlValue		    aControlValue( mbChecked ? BUTTONVALUE_ON : BUTTONVALUE_OFF );
2183*cdf0e10cSrcweir         Rectangle					aCtrlRect( maStateRect.TopLeft(), maStateRect.GetSize() );
2184*cdf0e10cSrcweir         ControlState				nState = 0;
2185*cdf0e10cSrcweir 
2186*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )	nState |= CTRL_STATE_PRESSED;
2187*cdf0e10cSrcweir         if ( HasFocus() ) 						nState |= CTRL_STATE_FOCUSED;
2188*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_DEFAULT )	nState |= CTRL_STATE_DEFAULT;
2189*cdf0e10cSrcweir         if ( IsEnabled() )						nState |= CTRL_STATE_ENABLED;
2190*cdf0e10cSrcweir 
2191*cdf0e10cSrcweir         if ( IsMouseOver() && maMouseRect.IsInside( GetPointerPosPixel() ) )
2192*cdf0e10cSrcweir             nState |= CTRL_STATE_ROLLOVER;
2193*cdf0e10cSrcweir 
2194*cdf0e10cSrcweir         bNativeOK = DrawNativeControl( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL, aCtrlRect, nState,
2195*cdf0e10cSrcweir                     aControlValue,rtl::OUString() );
2196*cdf0e10cSrcweir 
2197*cdf0e10cSrcweir     }
2198*cdf0e10cSrcweir 
2199*cdf0e10cSrcweir if ( bNativeOK == sal_False )
2200*cdf0e10cSrcweir {
2201*cdf0e10cSrcweir     // kein Image-RadioButton
2202*cdf0e10cSrcweir     if ( !maImage )
2203*cdf0e10cSrcweir     {
2204*cdf0e10cSrcweir         sal_uInt16 nStyle = ImplGetButtonState();
2205*cdf0e10cSrcweir         if ( !IsEnabled() )
2206*cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_DISABLED;
2207*cdf0e10cSrcweir         if ( mbChecked )
2208*cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_CHECKED;
2209*cdf0e10cSrcweir         Image aImage = GetRadioImage( GetSettings(), nStyle );
2210*cdf0e10cSrcweir         if ( IsZoom() )
2211*cdf0e10cSrcweir             DrawImage( maStateRect.TopLeft(), maStateRect.GetSize(), aImage );
2212*cdf0e10cSrcweir         else
2213*cdf0e10cSrcweir             DrawImage( maStateRect.TopLeft(), aImage );
2214*cdf0e10cSrcweir     }
2215*cdf0e10cSrcweir     else
2216*cdf0e10cSrcweir     {
2217*cdf0e10cSrcweir         HideFocus();
2218*cdf0e10cSrcweir 
2219*cdf0e10cSrcweir         DecorationView          aDecoView( this );
2220*cdf0e10cSrcweir         const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
2221*cdf0e10cSrcweir         Rectangle               aImageRect  = maStateRect;
2222*cdf0e10cSrcweir         Size                    aImageSize  = maImage.GetSizePixel();
2223*cdf0e10cSrcweir         sal_Bool                    bEnabled    = IsEnabled();
2224*cdf0e10cSrcweir 
2225*cdf0e10cSrcweir         aImageSize.Width()  = CalcZoom( aImageSize.Width() );
2226*cdf0e10cSrcweir         aImageSize.Height() = CalcZoom( aImageSize.Height() );
2227*cdf0e10cSrcweir 
2228*cdf0e10cSrcweir         // Border und Selektionsstatus ausgeben
2229*cdf0e10cSrcweir         nButtonStyle = FRAME_DRAW_DOUBLEIN;
2230*cdf0e10cSrcweir         aImageRect = aDecoView.DrawFrame( aImageRect, nButtonStyle );
2231*cdf0e10cSrcweir         if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) || !bEnabled )
2232*cdf0e10cSrcweir             SetFillColor( rStyleSettings.GetFaceColor() );
2233*cdf0e10cSrcweir         else
2234*cdf0e10cSrcweir             SetFillColor( rStyleSettings.GetFieldColor() );
2235*cdf0e10cSrcweir         SetLineColor();
2236*cdf0e10cSrcweir         DrawRect( aImageRect );
2237*cdf0e10cSrcweir 
2238*cdf0e10cSrcweir         // Image ausgeben
2239*cdf0e10cSrcweir         nButtonStyle = 0;
2240*cdf0e10cSrcweir         if ( !bEnabled )
2241*cdf0e10cSrcweir             nButtonStyle |= IMAGE_DRAW_DISABLE;
2242*cdf0e10cSrcweir 
2243*cdf0e10cSrcweir 		// check for HC mode
2244*cdf0e10cSrcweir 		Image *pImage = &maImage;
2245*cdf0e10cSrcweir 		if( !!maImageHC )
2246*cdf0e10cSrcweir 		{
2247*cdf0e10cSrcweir 			if( rStyleSettings.GetHighContrastMode() )
2248*cdf0e10cSrcweir 				pImage = &maImageHC;
2249*cdf0e10cSrcweir 		}
2250*cdf0e10cSrcweir 
2251*cdf0e10cSrcweir         Point aImagePos( aImageRect.TopLeft() );
2252*cdf0e10cSrcweir         aImagePos.X() += (aImageRect.GetWidth()-aImageSize.Width())/2;
2253*cdf0e10cSrcweir         aImagePos.Y() += (aImageRect.GetHeight()-aImageSize.Height())/2;
2254*cdf0e10cSrcweir         if ( IsZoom() )
2255*cdf0e10cSrcweir             DrawImage( aImagePos, aImageSize, *pImage, nButtonStyle );
2256*cdf0e10cSrcweir         else
2257*cdf0e10cSrcweir             DrawImage( aImagePos, *pImage, nButtonStyle );
2258*cdf0e10cSrcweir 
2259*cdf0e10cSrcweir         aImageRect.Left()++;
2260*cdf0e10cSrcweir         aImageRect.Top()++;
2261*cdf0e10cSrcweir         aImageRect.Right()--;
2262*cdf0e10cSrcweir         aImageRect.Bottom()--;
2263*cdf0e10cSrcweir 
2264*cdf0e10cSrcweir         ImplSetFocusRect( aImageRect );
2265*cdf0e10cSrcweir 
2266*cdf0e10cSrcweir         if ( mbChecked )
2267*cdf0e10cSrcweir         {
2268*cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetHighlightColor() );
2269*cdf0e10cSrcweir             SetFillColor();
2270*cdf0e10cSrcweir             if ( (aImageSize.Width() >= 20) || (aImageSize.Height() >= 20) )
2271*cdf0e10cSrcweir             {
2272*cdf0e10cSrcweir                 aImageRect.Left()++;
2273*cdf0e10cSrcweir                 aImageRect.Top()++;
2274*cdf0e10cSrcweir                 aImageRect.Right()--;
2275*cdf0e10cSrcweir                 aImageRect.Bottom()--;
2276*cdf0e10cSrcweir             }
2277*cdf0e10cSrcweir             DrawRect( aImageRect );
2278*cdf0e10cSrcweir             aImageRect.Left()++;
2279*cdf0e10cSrcweir             aImageRect.Top()++;
2280*cdf0e10cSrcweir             aImageRect.Right()--;
2281*cdf0e10cSrcweir             aImageRect.Bottom()--;
2282*cdf0e10cSrcweir             DrawRect( aImageRect );
2283*cdf0e10cSrcweir         }
2284*cdf0e10cSrcweir 
2285*cdf0e10cSrcweir         if ( HasFocus() )
2286*cdf0e10cSrcweir             ShowFocus( ImplGetFocusRect() );
2287*cdf0e10cSrcweir     }
2288*cdf0e10cSrcweir }
2289*cdf0e10cSrcweir }
2290*cdf0e10cSrcweir 
2291*cdf0e10cSrcweir // -----------------------------------------------------------------------
2292*cdf0e10cSrcweir 
2293*cdf0e10cSrcweir void RadioButton::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
2294*cdf0e10cSrcweir                             const Point& rPos, const Size& rSize,
2295*cdf0e10cSrcweir                             const Size& rImageSize, Rectangle& rStateRect,
2296*cdf0e10cSrcweir                             Rectangle& rMouseRect, bool bLayout )
2297*cdf0e10cSrcweir {
2298*cdf0e10cSrcweir     WinBits                 nWinStyle = GetStyle();
2299*cdf0e10cSrcweir     XubString               aText( GetText() );
2300*cdf0e10cSrcweir     Rectangle               aRect( rPos, rSize );
2301*cdf0e10cSrcweir     MetricVector*			pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
2302*cdf0e10cSrcweir     String*					pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
2303*cdf0e10cSrcweir 
2304*cdf0e10cSrcweir     pDev->Push( PUSH_CLIPREGION );
2305*cdf0e10cSrcweir     pDev->IntersectClipRegion( Rectangle( rPos, rSize ) );
2306*cdf0e10cSrcweir 
2307*cdf0e10cSrcweir     // kein Image-RadioButton
2308*cdf0e10cSrcweir     if ( !maImage )
2309*cdf0e10cSrcweir     {
2310*cdf0e10cSrcweir         if ( ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) ) ||
2311*cdf0e10cSrcweir              ( HasImage() &&  ! (ImplGetButtonState() & BUTTON_DRAW_NOIMAGE) ) )
2312*cdf0e10cSrcweir         {
2313*cdf0e10cSrcweir             sal_uInt16 nTextStyle = Button::ImplGetTextStyle( aText, nWinStyle, nDrawFlags );
2314*cdf0e10cSrcweir 
2315*cdf0e10cSrcweir             const long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() );
2316*cdf0e10cSrcweir             Size aSize( rSize );
2317*cdf0e10cSrcweir             Point aPos( rPos );
2318*cdf0e10cSrcweir             aPos.X() += rImageSize.Width() + nImageSep;
2319*cdf0e10cSrcweir             aSize.Width() -= rImageSize.Width() + nImageSep;
2320*cdf0e10cSrcweir 
2321*cdf0e10cSrcweir             // if the text rect height is smaller than the height of the image
2322*cdf0e10cSrcweir             // then for single lines the default should be centered text
2323*cdf0e10cSrcweir             if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 &&
2324*cdf0e10cSrcweir                 (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK)  ) )
2325*cdf0e10cSrcweir             {
2326*cdf0e10cSrcweir                 nTextStyle &= ~(TEXT_DRAW_TOP|TEXT_DRAW_BOTTOM);
2327*cdf0e10cSrcweir                 nTextStyle |= TEXT_DRAW_VCENTER;
2328*cdf0e10cSrcweir                 aSize.Height() = rImageSize.Height();
2329*cdf0e10cSrcweir             }
2330*cdf0e10cSrcweir 
2331*cdf0e10cSrcweir             ImplDrawAlignedImage( pDev, aPos, aSize, bLayout, 1,
2332*cdf0e10cSrcweir                                   nDrawFlags, nTextStyle, NULL );
2333*cdf0e10cSrcweir 
2334*cdf0e10cSrcweir             rMouseRect          = Rectangle( aPos, aSize );
2335*cdf0e10cSrcweir             rMouseRect.Left()   = rPos.X();
2336*cdf0e10cSrcweir 
2337*cdf0e10cSrcweir             rStateRect.Left()   = rPos.X();
2338*cdf0e10cSrcweir             rStateRect.Top()    = rMouseRect.Top();
2339*cdf0e10cSrcweir 
2340*cdf0e10cSrcweir             if ( aSize.Height() > rImageSize.Height() )
2341*cdf0e10cSrcweir                 rStateRect.Top() += ( aSize.Height() - rImageSize.Height() ) / 2;
2342*cdf0e10cSrcweir             else
2343*cdf0e10cSrcweir             {
2344*cdf0e10cSrcweir                 rStateRect.Top() -= ( rImageSize.Height() - aSize.Height() ) / 2;
2345*cdf0e10cSrcweir                 if( rStateRect.Top() < 0 )
2346*cdf0e10cSrcweir                     rStateRect.Top() = 0;
2347*cdf0e10cSrcweir             }
2348*cdf0e10cSrcweir 
2349*cdf0e10cSrcweir             rStateRect.Right()  = rStateRect.Left() + rImageSize.Width()-1;
2350*cdf0e10cSrcweir             rStateRect.Bottom() = rStateRect.Top() + rImageSize.Height()-1;
2351*cdf0e10cSrcweir 
2352*cdf0e10cSrcweir             if ( rStateRect.Bottom() > rMouseRect.Bottom() )
2353*cdf0e10cSrcweir                 rMouseRect.Bottom() = rStateRect.Bottom();
2354*cdf0e10cSrcweir         }
2355*cdf0e10cSrcweir         else
2356*cdf0e10cSrcweir         {
2357*cdf0e10cSrcweir             if ( nWinStyle & WB_CENTER )
2358*cdf0e10cSrcweir                 rStateRect.Left() = rPos.X()+((rSize.Width()-rImageSize.Width())/2);
2359*cdf0e10cSrcweir             else if ( nWinStyle & WB_RIGHT )
2360*cdf0e10cSrcweir                 rStateRect.Left() = rPos.X()+rSize.Width()-rImageSize.Width(); //-1;
2361*cdf0e10cSrcweir             else
2362*cdf0e10cSrcweir                 rStateRect.Left() = rPos.X(); //+1;
2363*cdf0e10cSrcweir             if ( nWinStyle & WB_VCENTER )
2364*cdf0e10cSrcweir                 rStateRect.Top() = rPos.Y()+((rSize.Height()-rImageSize.Height())/2);
2365*cdf0e10cSrcweir             else if ( nWinStyle & WB_BOTTOM )
2366*cdf0e10cSrcweir                 rStateRect.Top() = rPos.Y()+rSize.Height()-rImageSize.Height(); //-1;
2367*cdf0e10cSrcweir             else
2368*cdf0e10cSrcweir                 rStateRect.Top() = rPos.Y(); //+1;
2369*cdf0e10cSrcweir             rStateRect.Right()  = rStateRect.Left()+rImageSize.Width()-1;
2370*cdf0e10cSrcweir             rStateRect.Bottom() = rStateRect.Top()+rImageSize.Height()-1;
2371*cdf0e10cSrcweir             rMouseRect          = rStateRect;
2372*cdf0e10cSrcweir 
2373*cdf0e10cSrcweir             ImplSetFocusRect( rStateRect );
2374*cdf0e10cSrcweir 
2375*cdf0e10cSrcweir /*  und oben -1, da CalcSize() auch Focus-Rechteck nicht mit einrechnet,
2376*cdf0e10cSrcweir da im Writer ansonsten die Images noch weiter oben haengen
2377*cdf0e10cSrcweir             rFocusRect          = rStateRect;
2378*cdf0e10cSrcweir             rFocusRect.Left()--;
2379*cdf0e10cSrcweir             rFocusRect.Top()--;
2380*cdf0e10cSrcweir             rFocusRect.Right()++;
2381*cdf0e10cSrcweir             rFocusRect.Bottom()++;
2382*cdf0e10cSrcweir */
2383*cdf0e10cSrcweir         }
2384*cdf0e10cSrcweir     }
2385*cdf0e10cSrcweir     else
2386*cdf0e10cSrcweir     {
2387*cdf0e10cSrcweir         sal_Bool        bTopImage   = (nWinStyle & WB_TOP) != 0;
2388*cdf0e10cSrcweir         Size        aImageSize  = maImage.GetSizePixel();
2389*cdf0e10cSrcweir         Rectangle   aImageRect( rPos, rSize );
2390*cdf0e10cSrcweir         long        nTextHeight = pDev->GetTextHeight();
2391*cdf0e10cSrcweir         long        nTextWidth  = pDev->GetCtrlTextWidth( aText );
2392*cdf0e10cSrcweir 
2393*cdf0e10cSrcweir         // Positionen und Groessen berechnen
2394*cdf0e10cSrcweir         if ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
2395*cdf0e10cSrcweir         {
2396*cdf0e10cSrcweir             Size aTmpSize( (aImageSize.Width()+8), (aImageSize.Height()+8) );
2397*cdf0e10cSrcweir             if ( bTopImage )
2398*cdf0e10cSrcweir             {
2399*cdf0e10cSrcweir                 aImageRect.Left() = (rSize.Width()-aTmpSize.Width())/2;
2400*cdf0e10cSrcweir                 aImageRect.Top()  = (rSize.Height()-(aTmpSize.Height()+nTextHeight+6))/2;
2401*cdf0e10cSrcweir             }
2402*cdf0e10cSrcweir             else
2403*cdf0e10cSrcweir                 aImageRect.Top()  = (rSize.Height()-aTmpSize.Height())/2;
2404*cdf0e10cSrcweir 
2405*cdf0e10cSrcweir             aImageRect.Right()  = aImageRect.Left()+aTmpSize.Width();
2406*cdf0e10cSrcweir             aImageRect.Bottom() = aImageRect.Top()+aTmpSize.Height();
2407*cdf0e10cSrcweir 
2408*cdf0e10cSrcweir             // Text ausgeben
2409*cdf0e10cSrcweir             Point aTxtPos = rPos;
2410*cdf0e10cSrcweir             if ( bTopImage )
2411*cdf0e10cSrcweir             {
2412*cdf0e10cSrcweir                 aTxtPos.X() += (rSize.Width()-nTextWidth)/2;
2413*cdf0e10cSrcweir                 aTxtPos.Y() += aImageRect.Bottom()+6;
2414*cdf0e10cSrcweir             }
2415*cdf0e10cSrcweir             else
2416*cdf0e10cSrcweir             {
2417*cdf0e10cSrcweir                 aTxtPos.X() += aImageRect.Right()+8;
2418*cdf0e10cSrcweir                 aTxtPos.Y() += (rSize.Height()-nTextHeight)/2;
2419*cdf0e10cSrcweir             }
2420*cdf0e10cSrcweir             pDev->DrawCtrlText( aTxtPos, aText, 0, STRING_LEN, TEXT_DRAW_MNEMONIC, pVector, pDisplayText );
2421*cdf0e10cSrcweir         }
2422*cdf0e10cSrcweir 
2423*cdf0e10cSrcweir         rMouseRect = aImageRect;
2424*cdf0e10cSrcweir         rStateRect = aImageRect;
2425*cdf0e10cSrcweir     }
2426*cdf0e10cSrcweir 
2427*cdf0e10cSrcweir     pDev->Pop();
2428*cdf0e10cSrcweir }
2429*cdf0e10cSrcweir 
2430*cdf0e10cSrcweir // -----------------------------------------------------------------------
2431*cdf0e10cSrcweir 
2432*cdf0e10cSrcweir void RadioButton::ImplDrawRadioButton( bool bLayout )
2433*cdf0e10cSrcweir {
2434*cdf0e10cSrcweir     if( !bLayout )
2435*cdf0e10cSrcweir         HideFocus();
2436*cdf0e10cSrcweir 
2437*cdf0e10cSrcweir     Size aImageSize;
2438*cdf0e10cSrcweir     if ( !maImage )
2439*cdf0e10cSrcweir         aImageSize = ImplGetRadioImageSize();
2440*cdf0e10cSrcweir     else
2441*cdf0e10cSrcweir         aImageSize  = maImage.GetSizePixel();
2442*cdf0e10cSrcweir     aImageSize.Width()  = CalcZoom( aImageSize.Width() );
2443*cdf0e10cSrcweir     aImageSize.Height() = CalcZoom( aImageSize.Height() );
2444*cdf0e10cSrcweir 
2445*cdf0e10cSrcweir     // Draw control text
2446*cdf0e10cSrcweir     ImplDraw( this, 0, Point(), GetOutputSizePixel(),
2447*cdf0e10cSrcweir               aImageSize, maStateRect, maMouseRect, bLayout );
2448*cdf0e10cSrcweir 
2449*cdf0e10cSrcweir     if( !bLayout || (IsNativeControlSupported(CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL)==sal_True) )
2450*cdf0e10cSrcweir     {
2451*cdf0e10cSrcweir         if ( !maImage && HasFocus() )
2452*cdf0e10cSrcweir             ShowFocus( ImplGetFocusRect() );
2453*cdf0e10cSrcweir 
2454*cdf0e10cSrcweir         ImplDrawRadioButtonState();
2455*cdf0e10cSrcweir     }
2456*cdf0e10cSrcweir }
2457*cdf0e10cSrcweir 
2458*cdf0e10cSrcweir // -----------------------------------------------------------------------
2459*cdf0e10cSrcweir 
2460*cdf0e10cSrcweir void RadioButton::GetRadioButtonGroup( std::vector< RadioButton* >& io_rGroup, bool bIncludeThis ) const
2461*cdf0e10cSrcweir {
2462*cdf0e10cSrcweir     // empty the list
2463*cdf0e10cSrcweir     io_rGroup.clear();
2464*cdf0e10cSrcweir 
2465*cdf0e10cSrcweir     // go back to first in group;
2466*cdf0e10cSrcweir     Window* pFirst = const_cast<RadioButton*>(this);
2467*cdf0e10cSrcweir     while( ( pFirst->GetStyle() & WB_GROUP ) == 0 )
2468*cdf0e10cSrcweir     {
2469*cdf0e10cSrcweir         Window* pWindow = pFirst->GetWindow( WINDOW_PREV );
2470*cdf0e10cSrcweir         if( pWindow )
2471*cdf0e10cSrcweir             pFirst = pWindow;
2472*cdf0e10cSrcweir         else
2473*cdf0e10cSrcweir             break;
2474*cdf0e10cSrcweir     }
2475*cdf0e10cSrcweir     // insert radiobuttons up to next group
2476*cdf0e10cSrcweir     do
2477*cdf0e10cSrcweir     {
2478*cdf0e10cSrcweir         if( pFirst->GetType() == WINDOW_RADIOBUTTON )
2479*cdf0e10cSrcweir         {
2480*cdf0e10cSrcweir             if( pFirst != this || bIncludeThis )
2481*cdf0e10cSrcweir                 io_rGroup.push_back( static_cast<RadioButton*>(pFirst) );
2482*cdf0e10cSrcweir         }
2483*cdf0e10cSrcweir         pFirst = pFirst->GetWindow( WINDOW_NEXT );
2484*cdf0e10cSrcweir     } while( pFirst && ( ( pFirst->GetStyle() & WB_GROUP ) == 0 ) );
2485*cdf0e10cSrcweir }
2486*cdf0e10cSrcweir 
2487*cdf0e10cSrcweir // -----------------------------------------------------------------------
2488*cdf0e10cSrcweir 
2489*cdf0e10cSrcweir void RadioButton::ImplUncheckAllOther()
2490*cdf0e10cSrcweir {
2491*cdf0e10cSrcweir     mpWindowImpl->mnStyle |= WB_TABSTOP;
2492*cdf0e10cSrcweir 
2493*cdf0e10cSrcweir     // Gruppe mit RadioButtons durchgehen und die gecheckten Buttons
2494*cdf0e10cSrcweir     Window* pWindow;
2495*cdf0e10cSrcweir     WinBits nStyle;
2496*cdf0e10cSrcweir     if ( !(GetStyle() & WB_GROUP) )
2497*cdf0e10cSrcweir     {
2498*cdf0e10cSrcweir         pWindow = GetWindow( WINDOW_PREV );
2499*cdf0e10cSrcweir         while ( pWindow )
2500*cdf0e10cSrcweir         {
2501*cdf0e10cSrcweir             nStyle = pWindow->GetStyle();
2502*cdf0e10cSrcweir 
2503*cdf0e10cSrcweir             if ( pWindow->GetType() == WINDOW_RADIOBUTTON )
2504*cdf0e10cSrcweir             {
2505*cdf0e10cSrcweir                 if ( ((RadioButton*)pWindow)->IsChecked() )
2506*cdf0e10cSrcweir                 {
2507*cdf0e10cSrcweir                     ImplDelData aDelData;
2508*cdf0e10cSrcweir                     pWindow->ImplAddDel( &aDelData );
2509*cdf0e10cSrcweir                     ((RadioButton*)pWindow)->SetState( sal_False );
2510*cdf0e10cSrcweir                     if ( aDelData.IsDelete() )
2511*cdf0e10cSrcweir                         return;
2512*cdf0e10cSrcweir                     pWindow->ImplRemoveDel( &aDelData );
2513*cdf0e10cSrcweir                 }
2514*cdf0e10cSrcweir                 // Um falsch gesetzt WB_TABSTOPS immer zu entfernen, nicht
2515*cdf0e10cSrcweir                 // innerhalb der if-Abfrage
2516*cdf0e10cSrcweir                 pWindow->mpWindowImpl->mnStyle &= ~WB_TABSTOP;
2517*cdf0e10cSrcweir             }
2518*cdf0e10cSrcweir 
2519*cdf0e10cSrcweir             if ( nStyle & WB_GROUP )
2520*cdf0e10cSrcweir                 break;
2521*cdf0e10cSrcweir 
2522*cdf0e10cSrcweir             pWindow = pWindow->GetWindow( WINDOW_PREV );
2523*cdf0e10cSrcweir         }
2524*cdf0e10cSrcweir     }
2525*cdf0e10cSrcweir 
2526*cdf0e10cSrcweir     pWindow = GetWindow( WINDOW_NEXT );
2527*cdf0e10cSrcweir     while ( pWindow )
2528*cdf0e10cSrcweir     {
2529*cdf0e10cSrcweir         nStyle = pWindow->GetStyle();
2530*cdf0e10cSrcweir 
2531*cdf0e10cSrcweir         if ( nStyle & WB_GROUP )
2532*cdf0e10cSrcweir             break;
2533*cdf0e10cSrcweir 
2534*cdf0e10cSrcweir         if ( pWindow->GetType() == WINDOW_RADIOBUTTON )
2535*cdf0e10cSrcweir         {
2536*cdf0e10cSrcweir             if ( ((RadioButton*)pWindow)->IsChecked() )
2537*cdf0e10cSrcweir             {
2538*cdf0e10cSrcweir                 ImplDelData aDelData;
2539*cdf0e10cSrcweir                 pWindow->ImplAddDel( &aDelData );
2540*cdf0e10cSrcweir                 ((RadioButton*)pWindow)->SetState( sal_False );
2541*cdf0e10cSrcweir                 if ( aDelData.IsDelete() )
2542*cdf0e10cSrcweir                     return;
2543*cdf0e10cSrcweir                 pWindow->ImplRemoveDel( &aDelData );
2544*cdf0e10cSrcweir             }
2545*cdf0e10cSrcweir             // Um falsch gesetzt WB_TABSTOPS immer zu entfernen, nicht
2546*cdf0e10cSrcweir             // innerhalb der if-Abfrage
2547*cdf0e10cSrcweir             pWindow->mpWindowImpl->mnStyle &= ~WB_TABSTOP;
2548*cdf0e10cSrcweir         }
2549*cdf0e10cSrcweir 
2550*cdf0e10cSrcweir         pWindow = pWindow->GetWindow( WINDOW_NEXT );
2551*cdf0e10cSrcweir     }
2552*cdf0e10cSrcweir }
2553*cdf0e10cSrcweir 
2554*cdf0e10cSrcweir // -----------------------------------------------------------------------
2555*cdf0e10cSrcweir 
2556*cdf0e10cSrcweir void RadioButton::ImplCallClick( sal_Bool bGrabFocus, sal_uInt16 nFocusFlags )
2557*cdf0e10cSrcweir {
2558*cdf0e10cSrcweir     mbStateChanged = !mbChecked;
2559*cdf0e10cSrcweir     mbChecked = sal_True;
2560*cdf0e10cSrcweir     mpWindowImpl->mnStyle |= WB_TABSTOP;
2561*cdf0e10cSrcweir     ImplInvalidateOrDrawRadioButtonState();
2562*cdf0e10cSrcweir     ImplDelData aDelData;
2563*cdf0e10cSrcweir     ImplAddDel( &aDelData );
2564*cdf0e10cSrcweir     if ( mbRadioCheck )
2565*cdf0e10cSrcweir         ImplUncheckAllOther();
2566*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
2567*cdf0e10cSrcweir         return;
2568*cdf0e10cSrcweir     if ( bGrabFocus )
2569*cdf0e10cSrcweir         ImplGrabFocus( nFocusFlags );
2570*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
2571*cdf0e10cSrcweir         return;
2572*cdf0e10cSrcweir     if ( mbStateChanged )
2573*cdf0e10cSrcweir         Toggle();
2574*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
2575*cdf0e10cSrcweir         return;
2576*cdf0e10cSrcweir     Click();
2577*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
2578*cdf0e10cSrcweir         return;
2579*cdf0e10cSrcweir     ImplRemoveDel( &aDelData );
2580*cdf0e10cSrcweir     mbStateChanged = sal_False;
2581*cdf0e10cSrcweir }
2582*cdf0e10cSrcweir 
2583*cdf0e10cSrcweir // -----------------------------------------------------------------------
2584*cdf0e10cSrcweir 
2585*cdf0e10cSrcweir RadioButton::RadioButton( Window* pParent, WinBits nStyle ) :
2586*cdf0e10cSrcweir     Button( WINDOW_RADIOBUTTON )
2587*cdf0e10cSrcweir {
2588*cdf0e10cSrcweir     ImplInitRadioButtonData();
2589*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
2590*cdf0e10cSrcweir }
2591*cdf0e10cSrcweir 
2592*cdf0e10cSrcweir // -----------------------------------------------------------------------
2593*cdf0e10cSrcweir 
2594*cdf0e10cSrcweir RadioButton::RadioButton( Window* pParent, const ResId& rResId ) :
2595*cdf0e10cSrcweir     Button( WINDOW_RADIOBUTTON )
2596*cdf0e10cSrcweir {
2597*cdf0e10cSrcweir     ImplInitRadioButtonData();
2598*cdf0e10cSrcweir     rResId.SetRT( RSC_RADIOBUTTON );
2599*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
2600*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
2601*cdf0e10cSrcweir     ImplLoadRes( rResId );
2602*cdf0e10cSrcweir 
2603*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
2604*cdf0e10cSrcweir         Show();
2605*cdf0e10cSrcweir }
2606*cdf0e10cSrcweir 
2607*cdf0e10cSrcweir // -----------------------------------------------------------------------
2608*cdf0e10cSrcweir 
2609*cdf0e10cSrcweir void RadioButton::ImplLoadRes( const ResId& rResId )
2610*cdf0e10cSrcweir {
2611*cdf0e10cSrcweir     Button::ImplLoadRes( rResId );
2612*cdf0e10cSrcweir 
2613*cdf0e10cSrcweir     //anderer Wert als Default ?
2614*cdf0e10cSrcweir     sal_uInt16 nChecked = ReadShortRes();
2615*cdf0e10cSrcweir     if ( nChecked )
2616*cdf0e10cSrcweir         SetState( sal_True );
2617*cdf0e10cSrcweir }
2618*cdf0e10cSrcweir 
2619*cdf0e10cSrcweir // -----------------------------------------------------------------------
2620*cdf0e10cSrcweir 
2621*cdf0e10cSrcweir RadioButton::~RadioButton()
2622*cdf0e10cSrcweir {
2623*cdf0e10cSrcweir }
2624*cdf0e10cSrcweir 
2625*cdf0e10cSrcweir // -----------------------------------------------------------------------
2626*cdf0e10cSrcweir 
2627*cdf0e10cSrcweir void RadioButton::MouseButtonDown( const MouseEvent& rMEvt )
2628*cdf0e10cSrcweir {
2629*cdf0e10cSrcweir     if ( rMEvt.IsLeft() && maMouseRect.IsInside( rMEvt.GetPosPixel() ) )
2630*cdf0e10cSrcweir     {
2631*cdf0e10cSrcweir         ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
2632*cdf0e10cSrcweir         ImplInvalidateOrDrawRadioButtonState();
2633*cdf0e10cSrcweir         StartTracking();
2634*cdf0e10cSrcweir         return;
2635*cdf0e10cSrcweir     }
2636*cdf0e10cSrcweir 
2637*cdf0e10cSrcweir     Button::MouseButtonDown( rMEvt );
2638*cdf0e10cSrcweir }
2639*cdf0e10cSrcweir 
2640*cdf0e10cSrcweir // -----------------------------------------------------------------------
2641*cdf0e10cSrcweir 
2642*cdf0e10cSrcweir void RadioButton::Tracking( const TrackingEvent& rTEvt )
2643*cdf0e10cSrcweir {
2644*cdf0e10cSrcweir     if ( rTEvt.IsTrackingEnded() )
2645*cdf0e10cSrcweir     {
2646*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
2647*cdf0e10cSrcweir         {
2648*cdf0e10cSrcweir             if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() )
2649*cdf0e10cSrcweir                 GrabFocus();
2650*cdf0e10cSrcweir 
2651*cdf0e10cSrcweir             ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
2652*cdf0e10cSrcweir 
2653*cdf0e10cSrcweir             // Bei Abbruch kein Click-Handler rufen
2654*cdf0e10cSrcweir             if ( !rTEvt.IsTrackingCanceled() )
2655*cdf0e10cSrcweir                 ImplCallClick();
2656*cdf0e10cSrcweir             else
2657*cdf0e10cSrcweir                 ImplInvalidateOrDrawRadioButtonState();
2658*cdf0e10cSrcweir         }
2659*cdf0e10cSrcweir     }
2660*cdf0e10cSrcweir     else
2661*cdf0e10cSrcweir     {
2662*cdf0e10cSrcweir         if ( maMouseRect.IsInside( rTEvt.GetMouseEvent().GetPosPixel() ) )
2663*cdf0e10cSrcweir         {
2664*cdf0e10cSrcweir             if ( !(ImplGetButtonState() & BUTTON_DRAW_PRESSED) )
2665*cdf0e10cSrcweir             {
2666*cdf0e10cSrcweir                 ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
2667*cdf0e10cSrcweir                 ImplInvalidateOrDrawRadioButtonState();
2668*cdf0e10cSrcweir             }
2669*cdf0e10cSrcweir         }
2670*cdf0e10cSrcweir         else
2671*cdf0e10cSrcweir         {
2672*cdf0e10cSrcweir             if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
2673*cdf0e10cSrcweir             {
2674*cdf0e10cSrcweir                 ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
2675*cdf0e10cSrcweir                 ImplInvalidateOrDrawRadioButtonState();
2676*cdf0e10cSrcweir             }
2677*cdf0e10cSrcweir         }
2678*cdf0e10cSrcweir     }
2679*cdf0e10cSrcweir }
2680*cdf0e10cSrcweir 
2681*cdf0e10cSrcweir // -----------------------------------------------------------------------
2682*cdf0e10cSrcweir 
2683*cdf0e10cSrcweir void RadioButton::KeyInput( const KeyEvent& rKEvt )
2684*cdf0e10cSrcweir {
2685*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
2686*cdf0e10cSrcweir 
2687*cdf0e10cSrcweir     if ( !aKeyCode.GetModifier() && (aKeyCode.GetCode() == KEY_SPACE) )
2688*cdf0e10cSrcweir     {
2689*cdf0e10cSrcweir         if ( !(ImplGetButtonState() & BUTTON_DRAW_PRESSED) )
2690*cdf0e10cSrcweir         {
2691*cdf0e10cSrcweir             ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
2692*cdf0e10cSrcweir             ImplInvalidateOrDrawRadioButtonState();
2693*cdf0e10cSrcweir         }
2694*cdf0e10cSrcweir     }
2695*cdf0e10cSrcweir     else if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) && (aKeyCode.GetCode() == KEY_ESCAPE) )
2696*cdf0e10cSrcweir     {
2697*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
2698*cdf0e10cSrcweir         ImplInvalidateOrDrawRadioButtonState();
2699*cdf0e10cSrcweir     }
2700*cdf0e10cSrcweir     else
2701*cdf0e10cSrcweir         Button::KeyInput( rKEvt );
2702*cdf0e10cSrcweir }
2703*cdf0e10cSrcweir 
2704*cdf0e10cSrcweir // -----------------------------------------------------------------------
2705*cdf0e10cSrcweir 
2706*cdf0e10cSrcweir void RadioButton::KeyUp( const KeyEvent& rKEvt )
2707*cdf0e10cSrcweir {
2708*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
2709*cdf0e10cSrcweir 
2710*cdf0e10cSrcweir     if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) && (aKeyCode.GetCode() == KEY_SPACE) )
2711*cdf0e10cSrcweir     {
2712*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
2713*cdf0e10cSrcweir         ImplCallClick();
2714*cdf0e10cSrcweir     }
2715*cdf0e10cSrcweir     else
2716*cdf0e10cSrcweir         Button::KeyUp( rKEvt );
2717*cdf0e10cSrcweir }
2718*cdf0e10cSrcweir 
2719*cdf0e10cSrcweir // -----------------------------------------------------------------------
2720*cdf0e10cSrcweir 
2721*cdf0e10cSrcweir void RadioButton::FillLayoutData() const
2722*cdf0e10cSrcweir {
2723*cdf0e10cSrcweir     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
2724*cdf0e10cSrcweir     const_cast<RadioButton*>(this)->ImplDrawRadioButton( true );
2725*cdf0e10cSrcweir }
2726*cdf0e10cSrcweir 
2727*cdf0e10cSrcweir // -----------------------------------------------------------------------
2728*cdf0e10cSrcweir 
2729*cdf0e10cSrcweir void RadioButton::Paint( const Rectangle& )
2730*cdf0e10cSrcweir {
2731*cdf0e10cSrcweir     ImplDrawRadioButton();
2732*cdf0e10cSrcweir }
2733*cdf0e10cSrcweir 
2734*cdf0e10cSrcweir // -----------------------------------------------------------------------
2735*cdf0e10cSrcweir 
2736*cdf0e10cSrcweir void RadioButton::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
2737*cdf0e10cSrcweir                         sal_uLong nFlags )
2738*cdf0e10cSrcweir {
2739*cdf0e10cSrcweir     if ( !maImage )
2740*cdf0e10cSrcweir     {
2741*cdf0e10cSrcweir         MapMode     aResMapMode( MAP_100TH_MM );
2742*cdf0e10cSrcweir         Point       aPos  = pDev->LogicToPixel( rPos );
2743*cdf0e10cSrcweir         Size        aSize = pDev->LogicToPixel( rSize );
2744*cdf0e10cSrcweir         Size        aImageSize = pDev->LogicToPixel( Size( 300, 300 ), aResMapMode );
2745*cdf0e10cSrcweir         Size        aBrd1Size = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode );
2746*cdf0e10cSrcweir         Size        aBrd2Size = pDev->LogicToPixel( Size( 60, 60 ), aResMapMode );
2747*cdf0e10cSrcweir         Font        aFont = GetDrawPixelFont( pDev );
2748*cdf0e10cSrcweir         Rectangle   aStateRect;
2749*cdf0e10cSrcweir         Rectangle   aMouseRect;
2750*cdf0e10cSrcweir         Rectangle   aFocusRect;
2751*cdf0e10cSrcweir 
2752*cdf0e10cSrcweir         aImageSize.Width()  = CalcZoom( aImageSize.Width() );
2753*cdf0e10cSrcweir         aImageSize.Height() = CalcZoom( aImageSize.Height() );
2754*cdf0e10cSrcweir         aBrd1Size.Width()   = CalcZoom( aBrd1Size.Width() );
2755*cdf0e10cSrcweir         aBrd1Size.Height()  = CalcZoom( aBrd1Size.Height() );
2756*cdf0e10cSrcweir         aBrd2Size.Width()   = CalcZoom( aBrd2Size.Width() );
2757*cdf0e10cSrcweir         aBrd2Size.Height()  = CalcZoom( aBrd2Size.Height() );
2758*cdf0e10cSrcweir 
2759*cdf0e10cSrcweir         if ( !aBrd1Size.Width() )
2760*cdf0e10cSrcweir             aBrd1Size.Width() = 1;
2761*cdf0e10cSrcweir         if ( !aBrd1Size.Height() )
2762*cdf0e10cSrcweir             aBrd1Size.Height() = 1;
2763*cdf0e10cSrcweir         if ( !aBrd2Size.Width() )
2764*cdf0e10cSrcweir             aBrd2Size.Width() = 1;
2765*cdf0e10cSrcweir         if ( !aBrd2Size.Height() )
2766*cdf0e10cSrcweir             aBrd2Size.Height() = 1;
2767*cdf0e10cSrcweir 
2768*cdf0e10cSrcweir         pDev->Push();
2769*cdf0e10cSrcweir         pDev->SetMapMode();
2770*cdf0e10cSrcweir         pDev->SetFont( aFont );
2771*cdf0e10cSrcweir         if ( nFlags & WINDOW_DRAW_MONO )
2772*cdf0e10cSrcweir             pDev->SetTextColor( Color( COL_BLACK ) );
2773*cdf0e10cSrcweir         else
2774*cdf0e10cSrcweir             pDev->SetTextColor( GetTextColor() );
2775*cdf0e10cSrcweir         pDev->SetTextFillColor();
2776*cdf0e10cSrcweir 
2777*cdf0e10cSrcweir         ImplDraw( pDev, nFlags, aPos, aSize,
2778*cdf0e10cSrcweir                   aImageSize, aStateRect, aMouseRect );
2779*cdf0e10cSrcweir 
2780*cdf0e10cSrcweir         Point   aCenterPos = aStateRect.Center();
2781*cdf0e10cSrcweir         long    nRadX = aImageSize.Width()/2;
2782*cdf0e10cSrcweir         long    nRadY = aImageSize.Height()/2;
2783*cdf0e10cSrcweir 
2784*cdf0e10cSrcweir         pDev->SetLineColor();
2785*cdf0e10cSrcweir         pDev->SetFillColor( Color( COL_BLACK ) );
2786*cdf0e10cSrcweir         pDev->DrawPolygon( Polygon( aCenterPos, nRadX, nRadY ) );
2787*cdf0e10cSrcweir         nRadX -= aBrd1Size.Width();
2788*cdf0e10cSrcweir         nRadY -= aBrd1Size.Height();
2789*cdf0e10cSrcweir         pDev->SetFillColor( Color( COL_WHITE ) );
2790*cdf0e10cSrcweir         pDev->DrawPolygon( Polygon( aCenterPos, nRadX, nRadY ) );
2791*cdf0e10cSrcweir         if ( mbChecked )
2792*cdf0e10cSrcweir         {
2793*cdf0e10cSrcweir             nRadX -= aBrd1Size.Width();
2794*cdf0e10cSrcweir             nRadY -= aBrd1Size.Height();
2795*cdf0e10cSrcweir             if ( !nRadX )
2796*cdf0e10cSrcweir                 nRadX = 1;
2797*cdf0e10cSrcweir             if ( !nRadY )
2798*cdf0e10cSrcweir                 nRadY = 1;
2799*cdf0e10cSrcweir             pDev->SetFillColor( Color( COL_BLACK ) );
2800*cdf0e10cSrcweir             pDev->DrawPolygon( Polygon( aCenterPos, nRadX, nRadY ) );
2801*cdf0e10cSrcweir         }
2802*cdf0e10cSrcweir 
2803*cdf0e10cSrcweir         pDev->Pop();
2804*cdf0e10cSrcweir     }
2805*cdf0e10cSrcweir     else
2806*cdf0e10cSrcweir     {
2807*cdf0e10cSrcweir         DBG_ERROR( "RadioButton::Draw() - not implemented for RadioButton with Image" );
2808*cdf0e10cSrcweir     }
2809*cdf0e10cSrcweir }
2810*cdf0e10cSrcweir 
2811*cdf0e10cSrcweir // -----------------------------------------------------------------------
2812*cdf0e10cSrcweir 
2813*cdf0e10cSrcweir void RadioButton::Resize()
2814*cdf0e10cSrcweir {
2815*cdf0e10cSrcweir     Control::Resize();
2816*cdf0e10cSrcweir     Invalidate();
2817*cdf0e10cSrcweir }
2818*cdf0e10cSrcweir 
2819*cdf0e10cSrcweir // -----------------------------------------------------------------------
2820*cdf0e10cSrcweir 
2821*cdf0e10cSrcweir void RadioButton::GetFocus()
2822*cdf0e10cSrcweir {
2823*cdf0e10cSrcweir     ShowFocus( ImplGetFocusRect() );
2824*cdf0e10cSrcweir     SetInputContext( InputContext( GetFont() ) );
2825*cdf0e10cSrcweir     Button::GetFocus();
2826*cdf0e10cSrcweir }
2827*cdf0e10cSrcweir 
2828*cdf0e10cSrcweir // -----------------------------------------------------------------------
2829*cdf0e10cSrcweir 
2830*cdf0e10cSrcweir void RadioButton::LoseFocus()
2831*cdf0e10cSrcweir {
2832*cdf0e10cSrcweir     if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
2833*cdf0e10cSrcweir     {
2834*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
2835*cdf0e10cSrcweir         ImplInvalidateOrDrawRadioButtonState();
2836*cdf0e10cSrcweir     }
2837*cdf0e10cSrcweir 
2838*cdf0e10cSrcweir     HideFocus();
2839*cdf0e10cSrcweir     Button::LoseFocus();
2840*cdf0e10cSrcweir }
2841*cdf0e10cSrcweir 
2842*cdf0e10cSrcweir // -----------------------------------------------------------------------
2843*cdf0e10cSrcweir 
2844*cdf0e10cSrcweir void RadioButton::StateChanged( StateChangedType nType )
2845*cdf0e10cSrcweir {
2846*cdf0e10cSrcweir     Button::StateChanged( nType );
2847*cdf0e10cSrcweir 
2848*cdf0e10cSrcweir     if ( nType == STATE_CHANGE_STATE )
2849*cdf0e10cSrcweir     {
2850*cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
2851*cdf0e10cSrcweir             Invalidate( maStateRect );
2852*cdf0e10cSrcweir     }
2853*cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ENABLE) ||
2854*cdf0e10cSrcweir               (nType == STATE_CHANGE_TEXT) ||
2855*cdf0e10cSrcweir               (nType == STATE_CHANGE_IMAGE) ||
2856*cdf0e10cSrcweir               (nType == STATE_CHANGE_DATA) ||
2857*cdf0e10cSrcweir               (nType == STATE_CHANGE_UPDATEMODE) )
2858*cdf0e10cSrcweir     {
2859*cdf0e10cSrcweir         if ( IsUpdateMode() )
2860*cdf0e10cSrcweir             Invalidate();
2861*cdf0e10cSrcweir     }
2862*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_STYLE )
2863*cdf0e10cSrcweir     {
2864*cdf0e10cSrcweir         SetStyle( ImplInitStyle( GetWindow( WINDOW_PREV ), GetStyle() ) );
2865*cdf0e10cSrcweir 
2866*cdf0e10cSrcweir         if ( (GetPrevStyle() & RADIOBUTTON_VIEW_STYLE) !=
2867*cdf0e10cSrcweir              (GetStyle() & RADIOBUTTON_VIEW_STYLE) )
2868*cdf0e10cSrcweir         {
2869*cdf0e10cSrcweir             if ( IsUpdateMode() )
2870*cdf0e10cSrcweir                 Invalidate();
2871*cdf0e10cSrcweir         }
2872*cdf0e10cSrcweir     }
2873*cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ZOOM) ||
2874*cdf0e10cSrcweir               (nType == STATE_CHANGE_CONTROLFONT) )
2875*cdf0e10cSrcweir     {
2876*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
2877*cdf0e10cSrcweir         Invalidate();
2878*cdf0e10cSrcweir     }
2879*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
2880*cdf0e10cSrcweir     {
2881*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
2882*cdf0e10cSrcweir         Invalidate();
2883*cdf0e10cSrcweir     }
2884*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
2885*cdf0e10cSrcweir     {
2886*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
2887*cdf0e10cSrcweir         Invalidate();
2888*cdf0e10cSrcweir     }
2889*cdf0e10cSrcweir }
2890*cdf0e10cSrcweir 
2891*cdf0e10cSrcweir // -----------------------------------------------------------------------
2892*cdf0e10cSrcweir 
2893*cdf0e10cSrcweir void RadioButton::DataChanged( const DataChangedEvent& rDCEvt )
2894*cdf0e10cSrcweir {
2895*cdf0e10cSrcweir     Button::DataChanged( rDCEvt );
2896*cdf0e10cSrcweir 
2897*cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
2898*cdf0e10cSrcweir          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
2899*cdf0e10cSrcweir          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
2900*cdf0e10cSrcweir           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
2901*cdf0e10cSrcweir     {
2902*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
2903*cdf0e10cSrcweir         Invalidate();
2904*cdf0e10cSrcweir     }
2905*cdf0e10cSrcweir }
2906*cdf0e10cSrcweir 
2907*cdf0e10cSrcweir // -----------------------------------------------------------------------
2908*cdf0e10cSrcweir 
2909*cdf0e10cSrcweir long RadioButton::PreNotify( NotifyEvent& rNEvt )
2910*cdf0e10cSrcweir {
2911*cdf0e10cSrcweir     long nDone = 0;
2912*cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
2913*cdf0e10cSrcweir 
2914*cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
2915*cdf0e10cSrcweir     {
2916*cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
2917*cdf0e10cSrcweir         {
2918*cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
2919*cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL) )
2920*cdf0e10cSrcweir             {
2921*cdf0e10cSrcweir                 if( ( maMouseRect.IsInside( GetPointerPosPixel()) &&
2922*cdf0e10cSrcweir                      !maMouseRect.IsInside( GetLastPointerPosPixel()) ) ||
2923*cdf0e10cSrcweir                     ( maMouseRect.IsInside( GetLastPointerPosPixel()) &&
2924*cdf0e10cSrcweir                      !maMouseRect.IsInside( GetPointerPosPixel()) ) ||
2925*cdf0e10cSrcweir                      pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow() )
2926*cdf0e10cSrcweir                 {
2927*cdf0e10cSrcweir                     Invalidate( maStateRect );
2928*cdf0e10cSrcweir                 }
2929*cdf0e10cSrcweir             }
2930*cdf0e10cSrcweir         }
2931*cdf0e10cSrcweir     }
2932*cdf0e10cSrcweir 
2933*cdf0e10cSrcweir     return nDone ? nDone : Button::PreNotify(rNEvt);
2934*cdf0e10cSrcweir }
2935*cdf0e10cSrcweir 
2936*cdf0e10cSrcweir // -----------------------------------------------------------------------
2937*cdf0e10cSrcweir 
2938*cdf0e10cSrcweir void RadioButton::Toggle()
2939*cdf0e10cSrcweir {
2940*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_RADIOBUTTON_TOGGLE, maToggleHdl, this );
2941*cdf0e10cSrcweir }
2942*cdf0e10cSrcweir 
2943*cdf0e10cSrcweir // -----------------------------------------------------------------------
2944*cdf0e10cSrcweir 
2945*cdf0e10cSrcweir sal_Bool RadioButton::SetModeRadioImage( const Image& rImage, BmpColorMode eMode )
2946*cdf0e10cSrcweir {
2947*cdf0e10cSrcweir     if( eMode == BMP_COLOR_NORMAL )
2948*cdf0e10cSrcweir {
2949*cdf0e10cSrcweir     if ( rImage != maImage )
2950*cdf0e10cSrcweir     {
2951*cdf0e10cSrcweir         maImage = rImage;
2952*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_DATA );
2953*cdf0e10cSrcweir     }
2954*cdf0e10cSrcweir }
2955*cdf0e10cSrcweir     else if( eMode == BMP_COLOR_HIGHCONTRAST )
2956*cdf0e10cSrcweir     {
2957*cdf0e10cSrcweir 		if( maImageHC != rImage )
2958*cdf0e10cSrcweir 		{
2959*cdf0e10cSrcweir 			maImageHC = rImage;
2960*cdf0e10cSrcweir 			StateChanged( STATE_CHANGE_DATA );
2961*cdf0e10cSrcweir 		}
2962*cdf0e10cSrcweir     }
2963*cdf0e10cSrcweir     else
2964*cdf0e10cSrcweir         return sal_False;
2965*cdf0e10cSrcweir 
2966*cdf0e10cSrcweir     return sal_True;
2967*cdf0e10cSrcweir }
2968*cdf0e10cSrcweir 
2969*cdf0e10cSrcweir // -----------------------------------------------------------------------
2970*cdf0e10cSrcweir 
2971*cdf0e10cSrcweir const Image& RadioButton::GetModeRadioImage( BmpColorMode eMode ) const
2972*cdf0e10cSrcweir {
2973*cdf0e10cSrcweir     if( eMode == BMP_COLOR_HIGHCONTRAST )
2974*cdf0e10cSrcweir         return maImageHC;
2975*cdf0e10cSrcweir     else
2976*cdf0e10cSrcweir         return maImage;
2977*cdf0e10cSrcweir }
2978*cdf0e10cSrcweir 
2979*cdf0e10cSrcweir // -----------------------------------------------------------------------
2980*cdf0e10cSrcweir 
2981*cdf0e10cSrcweir void RadioButton::SetState( sal_Bool bCheck )
2982*cdf0e10cSrcweir {
2983*cdf0e10cSrcweir     // TabStop-Flag richtig mitfuehren
2984*cdf0e10cSrcweir     if ( bCheck )
2985*cdf0e10cSrcweir         mpWindowImpl->mnStyle |= WB_TABSTOP;
2986*cdf0e10cSrcweir     else
2987*cdf0e10cSrcweir         mpWindowImpl->mnStyle &= ~WB_TABSTOP;
2988*cdf0e10cSrcweir 
2989*cdf0e10cSrcweir     if ( mbChecked != bCheck )
2990*cdf0e10cSrcweir     {
2991*cdf0e10cSrcweir         mbChecked = bCheck;
2992*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_STATE );
2993*cdf0e10cSrcweir         Toggle();
2994*cdf0e10cSrcweir     }
2995*cdf0e10cSrcweir }
2996*cdf0e10cSrcweir 
2997*cdf0e10cSrcweir // -----------------------------------------------------------------------
2998*cdf0e10cSrcweir 
2999*cdf0e10cSrcweir void RadioButton::Check( sal_Bool bCheck )
3000*cdf0e10cSrcweir {
3001*cdf0e10cSrcweir     // TabStop-Flag richtig mitfuehren
3002*cdf0e10cSrcweir     if ( bCheck )
3003*cdf0e10cSrcweir         mpWindowImpl->mnStyle |= WB_TABSTOP;
3004*cdf0e10cSrcweir     else
3005*cdf0e10cSrcweir         mpWindowImpl->mnStyle &= ~WB_TABSTOP;
3006*cdf0e10cSrcweir 
3007*cdf0e10cSrcweir     if ( mbChecked != bCheck )
3008*cdf0e10cSrcweir     {
3009*cdf0e10cSrcweir         mbChecked = bCheck;
3010*cdf0e10cSrcweir         ImplDelData aDelData;
3011*cdf0e10cSrcweir         ImplAddDel( &aDelData );
3012*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_STATE );
3013*cdf0e10cSrcweir         if ( aDelData.IsDelete() )
3014*cdf0e10cSrcweir             return;
3015*cdf0e10cSrcweir         if ( bCheck && mbRadioCheck )
3016*cdf0e10cSrcweir             ImplUncheckAllOther();
3017*cdf0e10cSrcweir         if ( aDelData.IsDelete() )
3018*cdf0e10cSrcweir             return;
3019*cdf0e10cSrcweir         Toggle();
3020*cdf0e10cSrcweir         ImplRemoveDel( &aDelData );
3021*cdf0e10cSrcweir     }
3022*cdf0e10cSrcweir }
3023*cdf0e10cSrcweir 
3024*cdf0e10cSrcweir // -----------------------------------------------------------------------
3025*cdf0e10cSrcweir 
3026*cdf0e10cSrcweir long RadioButton::ImplGetImageToTextDistance() const
3027*cdf0e10cSrcweir {
3028*cdf0e10cSrcweir     // 4 pixels, but take zoom into account, so the text doesn't "jump" relative to surrounding elements,
3029*cdf0e10cSrcweir     // which might have been aligned with the text of the check box
3030*cdf0e10cSrcweir     return CalcZoom( 4 );
3031*cdf0e10cSrcweir }
3032*cdf0e10cSrcweir 
3033*cdf0e10cSrcweir // -----------------------------------------------------------------------
3034*cdf0e10cSrcweir 
3035*cdf0e10cSrcweir Size RadioButton::ImplGetRadioImageSize() const
3036*cdf0e10cSrcweir {
3037*cdf0e10cSrcweir     Size aSize;
3038*cdf0e10cSrcweir     // why are IsNativeControlSupported and GetNativeControlRegion not const ?
3039*cdf0e10cSrcweir     RadioButton* pThis = const_cast<RadioButton*>(this);
3040*cdf0e10cSrcweir     bool bDefaultSize = true;
3041*cdf0e10cSrcweir     if( pThis->IsNativeControlSupported( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL ) )
3042*cdf0e10cSrcweir     {
3043*cdf0e10cSrcweir         ImplControlValue aControlValue;
3044*cdf0e10cSrcweir         // #i45896# workaround gcc3.3 temporary problem
3045*cdf0e10cSrcweir         Rectangle		 aCtrlRegion( Point( 0, 0 ), GetSizePixel() );
3046*cdf0e10cSrcweir         ControlState	 nState = CTRL_STATE_DEFAULT|CTRL_STATE_ENABLED;
3047*cdf0e10cSrcweir         Rectangle aBoundingRgn, aContentRgn;
3048*cdf0e10cSrcweir 
3049*cdf0e10cSrcweir         // get native size of a radio button
3050*cdf0e10cSrcweir         if( pThis->GetNativeControlRegion( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL, aCtrlRegion,
3051*cdf0e10cSrcweir                                            nState, aControlValue, rtl::OUString(),
3052*cdf0e10cSrcweir                                            aBoundingRgn, aContentRgn ) )
3053*cdf0e10cSrcweir         {
3054*cdf0e10cSrcweir             aSize = aContentRgn.GetSize();
3055*cdf0e10cSrcweir             bDefaultSize = false;
3056*cdf0e10cSrcweir         }
3057*cdf0e10cSrcweir     }
3058*cdf0e10cSrcweir     if( bDefaultSize )
3059*cdf0e10cSrcweir         aSize = GetRadioImage( GetSettings(), 0 ).GetSizePixel();
3060*cdf0e10cSrcweir     return aSize;
3061*cdf0e10cSrcweir }
3062*cdf0e10cSrcweir 
3063*cdf0e10cSrcweir static void LoadThemedImageList (const StyleSettings &rStyleSettings,
3064*cdf0e10cSrcweir 								 ImageList *pList, const ResId &rResId,
3065*cdf0e10cSrcweir                                  sal_uInt16 nImages)
3066*cdf0e10cSrcweir {
3067*cdf0e10cSrcweir 	Color aColorAry1[6];
3068*cdf0e10cSrcweir 	Color aColorAry2[6];
3069*cdf0e10cSrcweir 	aColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 );
3070*cdf0e10cSrcweir 	aColorAry1[1] = Color( 0xFF, 0xFF, 0x00 );
3071*cdf0e10cSrcweir 	aColorAry1[2] = Color( 0xFF, 0xFF, 0xFF );
3072*cdf0e10cSrcweir 	aColorAry1[3] = Color( 0x80, 0x80, 0x80 );
3073*cdf0e10cSrcweir 	aColorAry1[4] = Color( 0x00, 0x00, 0x00 );
3074*cdf0e10cSrcweir 	aColorAry1[5] = Color( 0x00, 0xFF, 0x00 );
3075*cdf0e10cSrcweir 	aColorAry2[0] = rStyleSettings.GetFaceColor();
3076*cdf0e10cSrcweir 	aColorAry2[1] = rStyleSettings.GetWindowColor();
3077*cdf0e10cSrcweir 	aColorAry2[2] = rStyleSettings.GetLightColor();
3078*cdf0e10cSrcweir 	aColorAry2[3] = rStyleSettings.GetShadowColor();
3079*cdf0e10cSrcweir 	aColorAry2[4] = rStyleSettings.GetDarkShadowColor();
3080*cdf0e10cSrcweir 	aColorAry2[5] = rStyleSettings.GetWindowTextColor();
3081*cdf0e10cSrcweir 
3082*cdf0e10cSrcweir 	Color aMaskColor(0x00, 0x00, 0xFF );
3083*cdf0e10cSrcweir         DBG_ASSERT( sizeof(aColorAry1) == sizeof(aColorAry2), "aColorAry1 must match aColorAry2" );
3084*cdf0e10cSrcweir 	// FIXME: do we want the mask for the checkbox ?
3085*cdf0e10cSrcweir 	pList->InsertFromHorizontalBitmap (rResId, nImages, &aMaskColor,
3086*cdf0e10cSrcweir         aColorAry1, aColorAry2, sizeof(aColorAry1) / sizeof(Color));
3087*cdf0e10cSrcweir }
3088*cdf0e10cSrcweir 
3089*cdf0e10cSrcweir Image RadioButton::GetRadioImage( const AllSettings& rSettings, sal_uInt16 nFlags )
3090*cdf0e10cSrcweir {
3091*cdf0e10cSrcweir     ImplSVData*             pSVData = ImplGetSVData();
3092*cdf0e10cSrcweir     const StyleSettings&    rStyleSettings = rSettings.GetStyleSettings();
3093*cdf0e10cSrcweir     sal_uInt16              nStyle = 0;
3094*cdf0e10cSrcweir 
3095*cdf0e10cSrcweir     if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
3096*cdf0e10cSrcweir         nStyle = STYLE_RADIOBUTTON_MONO;
3097*cdf0e10cSrcweir 
3098*cdf0e10cSrcweir     if ( !pSVData->maCtrlData.mpRadioImgList ||
3099*cdf0e10cSrcweir          (pSVData->maCtrlData.mnRadioStyle != nStyle) ||
3100*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastRadioFColor != rStyleSettings.GetFaceColor().GetColor()) ||
3101*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastRadioWColor != rStyleSettings.GetWindowColor().GetColor()) ||
3102*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastRadioLColor != rStyleSettings.GetLightColor().GetColor()) )
3103*cdf0e10cSrcweir     {
3104*cdf0e10cSrcweir         if ( pSVData->maCtrlData.mpRadioImgList )
3105*cdf0e10cSrcweir             delete pSVData->maCtrlData.mpRadioImgList;
3106*cdf0e10cSrcweir 
3107*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastRadioFColor = rStyleSettings.GetFaceColor().GetColor();
3108*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastRadioWColor = rStyleSettings.GetWindowColor().GetColor();
3109*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastRadioLColor = rStyleSettings.GetLightColor().GetColor();
3110*cdf0e10cSrcweir 
3111*cdf0e10cSrcweir         Color pColorAry1[6];
3112*cdf0e10cSrcweir         Color pColorAry2[6];
3113*cdf0e10cSrcweir         pColorAry1[0] = Color( 0xC0, 0xC0, 0xC0 );
3114*cdf0e10cSrcweir         pColorAry1[1] = Color( 0xFF, 0xFF, 0x00 );
3115*cdf0e10cSrcweir         pColorAry1[2] = Color( 0xFF, 0xFF, 0xFF );
3116*cdf0e10cSrcweir         pColorAry1[3] = Color( 0x80, 0x80, 0x80 );
3117*cdf0e10cSrcweir         pColorAry1[4] = Color( 0x00, 0x00, 0x00 );
3118*cdf0e10cSrcweir         pColorAry1[5] = Color( 0x00, 0xFF, 0x00 );
3119*cdf0e10cSrcweir         pColorAry2[0] = rStyleSettings.GetFaceColor();
3120*cdf0e10cSrcweir         pColorAry2[1] = rStyleSettings.GetWindowColor();
3121*cdf0e10cSrcweir         pColorAry2[2] = rStyleSettings.GetLightColor();
3122*cdf0e10cSrcweir         pColorAry2[3] = rStyleSettings.GetShadowColor();
3123*cdf0e10cSrcweir         pColorAry2[4] = rStyleSettings.GetDarkShadowColor();
3124*cdf0e10cSrcweir         pColorAry2[5] = rStyleSettings.GetWindowTextColor();
3125*cdf0e10cSrcweir 
3126*cdf0e10cSrcweir         ResMgr* pResMgr = ImplGetResMgr();
3127*cdf0e10cSrcweir         pSVData->maCtrlData.mpRadioImgList = new ImageList();
3128*cdf0e10cSrcweir         if( pResMgr )
3129*cdf0e10cSrcweir 	    LoadThemedImageList( rStyleSettings,
3130*cdf0e10cSrcweir 				 pSVData->maCtrlData.mpRadioImgList,
3131*cdf0e10cSrcweir 				 ResId( SV_RESID_BITMAP_RADIO+nStyle, *pResMgr ), 6 );
3132*cdf0e10cSrcweir 	pSVData->maCtrlData.mnRadioStyle = nStyle;
3133*cdf0e10cSrcweir     }
3134*cdf0e10cSrcweir 
3135*cdf0e10cSrcweir     sal_uInt16 nId;
3136*cdf0e10cSrcweir     if ( nFlags & BUTTON_DRAW_DISABLED )
3137*cdf0e10cSrcweir     {
3138*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_CHECKED )
3139*cdf0e10cSrcweir             nId = 6;
3140*cdf0e10cSrcweir         else
3141*cdf0e10cSrcweir             nId = 5;
3142*cdf0e10cSrcweir     }
3143*cdf0e10cSrcweir     else if ( nFlags & BUTTON_DRAW_PRESSED )
3144*cdf0e10cSrcweir     {
3145*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_CHECKED )
3146*cdf0e10cSrcweir             nId = 4;
3147*cdf0e10cSrcweir         else
3148*cdf0e10cSrcweir             nId = 3;
3149*cdf0e10cSrcweir     }
3150*cdf0e10cSrcweir     else
3151*cdf0e10cSrcweir     {
3152*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_CHECKED )
3153*cdf0e10cSrcweir             nId = 2;
3154*cdf0e10cSrcweir         else
3155*cdf0e10cSrcweir             nId = 1;
3156*cdf0e10cSrcweir     }
3157*cdf0e10cSrcweir     return pSVData->maCtrlData.mpRadioImgList->GetImage( nId );
3158*cdf0e10cSrcweir }
3159*cdf0e10cSrcweir 
3160*cdf0e10cSrcweir // -----------------------------------------------------------------------
3161*cdf0e10cSrcweir 
3162*cdf0e10cSrcweir void RadioButton::ImplSetMinimumNWFSize()
3163*cdf0e10cSrcweir {
3164*cdf0e10cSrcweir     Push( PUSH_MAPMODE );
3165*cdf0e10cSrcweir     SetMapMode( MAP_PIXEL );
3166*cdf0e10cSrcweir 
3167*cdf0e10cSrcweir     ImplControlValue aControlValue;
3168*cdf0e10cSrcweir     Size aCurSize( GetSizePixel() );
3169*cdf0e10cSrcweir     Rectangle aCtrlRegion( Point( 0, 0 ), aCurSize );
3170*cdf0e10cSrcweir     Rectangle aBoundingRgn, aContentRgn;
3171*cdf0e10cSrcweir 
3172*cdf0e10cSrcweir     // get native size of a radiobutton
3173*cdf0e10cSrcweir     if( GetNativeControlRegion( CTRL_RADIOBUTTON, PART_ENTIRE_CONTROL, aCtrlRegion,
3174*cdf0e10cSrcweir                                 CTRL_STATE_DEFAULT|CTRL_STATE_ENABLED, aControlValue, rtl::OUString(),
3175*cdf0e10cSrcweir                                 aBoundingRgn, aContentRgn ) )
3176*cdf0e10cSrcweir     {
3177*cdf0e10cSrcweir         Size aSize = aContentRgn.GetSize();
3178*cdf0e10cSrcweir 
3179*cdf0e10cSrcweir         if( aSize.Height() > aCurSize.Height() )
3180*cdf0e10cSrcweir         {
3181*cdf0e10cSrcweir             aCurSize.Height() = aSize.Height();
3182*cdf0e10cSrcweir             SetSizePixel( aCurSize );
3183*cdf0e10cSrcweir         }
3184*cdf0e10cSrcweir     }
3185*cdf0e10cSrcweir 
3186*cdf0e10cSrcweir     Pop();
3187*cdf0e10cSrcweir }
3188*cdf0e10cSrcweir 
3189*cdf0e10cSrcweir // -----------------------------------------------------------------------
3190*cdf0e10cSrcweir 
3191*cdf0e10cSrcweir Size RadioButton::CalcMinimumSize( long nMaxWidth ) const
3192*cdf0e10cSrcweir {
3193*cdf0e10cSrcweir     Size aSize;
3194*cdf0e10cSrcweir     if ( !maImage )
3195*cdf0e10cSrcweir         aSize = ImplGetRadioImageSize();
3196*cdf0e10cSrcweir     else
3197*cdf0e10cSrcweir         aSize = maImage.GetSizePixel();
3198*cdf0e10cSrcweir 
3199*cdf0e10cSrcweir     nMaxWidth -= aSize.Width();
3200*cdf0e10cSrcweir 
3201*cdf0e10cSrcweir     XubString aText = GetText();
3202*cdf0e10cSrcweir     if ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
3203*cdf0e10cSrcweir     {
3204*cdf0e10cSrcweir         // subtract what will be added later
3205*cdf0e10cSrcweir         nMaxWidth-=2;
3206*cdf0e10cSrcweir         nMaxWidth -= ImplGetImageToTextDistance();
3207*cdf0e10cSrcweir 
3208*cdf0e10cSrcweir         Size aTextSize = GetTextRect( Rectangle( Point(), Size( nMaxWidth > 0 ? nMaxWidth : 0x7fffffff, 0x7fffffff ) ),
3209*cdf0e10cSrcweir                                       aText, FixedText::ImplGetTextStyle( GetStyle() ) ).GetSize();
3210*cdf0e10cSrcweir         aSize.Width()+=2;   // for focus rect
3211*cdf0e10cSrcweir         aSize.Width() += ImplGetImageToTextDistance();
3212*cdf0e10cSrcweir         aSize.Width() += aTextSize.Width();
3213*cdf0e10cSrcweir         if ( aSize.Height() < aTextSize.Height() )
3214*cdf0e10cSrcweir             aSize.Height() = aTextSize.Height();
3215*cdf0e10cSrcweir     }
3216*cdf0e10cSrcweir     else if ( !maImage )
3217*cdf0e10cSrcweir     {
3218*cdf0e10cSrcweir /* da ansonsten im Writer die Control zu weit oben haengen
3219*cdf0e10cSrcweir         aSize.Width() += 2;
3220*cdf0e10cSrcweir         aSize.Height() += 2;
3221*cdf0e10cSrcweir */
3222*cdf0e10cSrcweir     }
3223*cdf0e10cSrcweir 
3224*cdf0e10cSrcweir     return CalcWindowSize( aSize );
3225*cdf0e10cSrcweir }
3226*cdf0e10cSrcweir 
3227*cdf0e10cSrcweir // -----------------------------------------------------------------------
3228*cdf0e10cSrcweir 
3229*cdf0e10cSrcweir Size RadioButton::GetOptimalSize(WindowSizeType eType) const
3230*cdf0e10cSrcweir {
3231*cdf0e10cSrcweir     switch (eType) {
3232*cdf0e10cSrcweir     case WINDOWSIZE_MINIMUM:
3233*cdf0e10cSrcweir         return CalcMinimumSize();
3234*cdf0e10cSrcweir     default:
3235*cdf0e10cSrcweir         return Button::GetOptimalSize( eType );
3236*cdf0e10cSrcweir     }
3237*cdf0e10cSrcweir }
3238*cdf0e10cSrcweir 
3239*cdf0e10cSrcweir // =======================================================================
3240*cdf0e10cSrcweir 
3241*cdf0e10cSrcweir void CheckBox::ImplInitCheckBoxData()
3242*cdf0e10cSrcweir {
3243*cdf0e10cSrcweir     meState         = STATE_NOCHECK;
3244*cdf0e10cSrcweir     meSaveValue     = STATE_NOCHECK;
3245*cdf0e10cSrcweir     mbTriState      = sal_False;
3246*cdf0e10cSrcweir }
3247*cdf0e10cSrcweir 
3248*cdf0e10cSrcweir // -----------------------------------------------------------------------
3249*cdf0e10cSrcweir 
3250*cdf0e10cSrcweir void CheckBox::ImplInit( Window* pParent, WinBits nStyle )
3251*cdf0e10cSrcweir {
3252*cdf0e10cSrcweir     nStyle = ImplInitStyle( pParent->GetWindow( WINDOW_LASTCHILD ), nStyle );
3253*cdf0e10cSrcweir     Button::ImplInit( pParent, nStyle, NULL );
3254*cdf0e10cSrcweir 
3255*cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
3256*cdf0e10cSrcweir }
3257*cdf0e10cSrcweir 
3258*cdf0e10cSrcweir // -----------------------------------------------------------------------
3259*cdf0e10cSrcweir 
3260*cdf0e10cSrcweir WinBits CheckBox::ImplInitStyle( const Window* pPrevWindow, WinBits nStyle )
3261*cdf0e10cSrcweir {
3262*cdf0e10cSrcweir     if ( !(nStyle & WB_NOTABSTOP) )
3263*cdf0e10cSrcweir         nStyle |= WB_TABSTOP;
3264*cdf0e10cSrcweir     if ( !(nStyle & WB_NOGROUP) &&
3265*cdf0e10cSrcweir          (!pPrevWindow || (pPrevWindow->GetType() != WINDOW_CHECKBOX)) )
3266*cdf0e10cSrcweir         nStyle |= WB_GROUP;
3267*cdf0e10cSrcweir     return nStyle;
3268*cdf0e10cSrcweir }
3269*cdf0e10cSrcweir 
3270*cdf0e10cSrcweir // -----------------------------------------------------------------
3271*cdf0e10cSrcweir 
3272*cdf0e10cSrcweir const Font& CheckBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
3273*cdf0e10cSrcweir {
3274*cdf0e10cSrcweir     return _rStyle.GetRadioCheckFont();
3275*cdf0e10cSrcweir }
3276*cdf0e10cSrcweir 
3277*cdf0e10cSrcweir // -----------------------------------------------------------------
3278*cdf0e10cSrcweir const Color& CheckBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
3279*cdf0e10cSrcweir {
3280*cdf0e10cSrcweir     return _rStyle.GetRadioCheckTextColor();
3281*cdf0e10cSrcweir }
3282*cdf0e10cSrcweir 
3283*cdf0e10cSrcweir // -----------------------------------------------------------------------
3284*cdf0e10cSrcweir 
3285*cdf0e10cSrcweir void CheckBox::ImplInitSettings( sal_Bool bFont,
3286*cdf0e10cSrcweir                                  sal_Bool bForeground, sal_Bool bBackground )
3287*cdf0e10cSrcweir {
3288*cdf0e10cSrcweir     Button::ImplInitSettings( bFont, bForeground );
3289*cdf0e10cSrcweir 
3290*cdf0e10cSrcweir     if ( bBackground )
3291*cdf0e10cSrcweir     {
3292*cdf0e10cSrcweir         Window* pParent = GetParent();
3293*cdf0e10cSrcweir         if ( !IsControlBackground() &&
3294*cdf0e10cSrcweir             (pParent->IsChildTransparentModeEnabled() || IsNativeControlSupported( CTRL_CHECKBOX, PART_ENTIRE_CONTROL ) ) )
3295*cdf0e10cSrcweir         {
3296*cdf0e10cSrcweir             EnableChildTransparentMode( sal_True );
3297*cdf0e10cSrcweir             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
3298*cdf0e10cSrcweir             SetPaintTransparent( sal_True );
3299*cdf0e10cSrcweir             SetBackground();
3300*cdf0e10cSrcweir             if( IsNativeControlSupported( CTRL_CHECKBOX, PART_ENTIRE_CONTROL ) )
3301*cdf0e10cSrcweir                 ImplGetWindowImpl()->mbUseNativeFocus = ImplGetSVData()->maNWFData.mbNoFocusRects;
3302*cdf0e10cSrcweir         }
3303*cdf0e10cSrcweir         else
3304*cdf0e10cSrcweir         {
3305*cdf0e10cSrcweir             EnableChildTransparentMode( sal_False );
3306*cdf0e10cSrcweir             SetParentClipMode( 0 );
3307*cdf0e10cSrcweir             SetPaintTransparent( sal_False );
3308*cdf0e10cSrcweir 
3309*cdf0e10cSrcweir             if ( IsControlBackground() )
3310*cdf0e10cSrcweir                 SetBackground( GetControlBackground() );
3311*cdf0e10cSrcweir             else
3312*cdf0e10cSrcweir                 SetBackground( pParent->GetBackground() );
3313*cdf0e10cSrcweir         }
3314*cdf0e10cSrcweir     }
3315*cdf0e10cSrcweir }
3316*cdf0e10cSrcweir 
3317*cdf0e10cSrcweir // -----------------------------------------------------------------------
3318*cdf0e10cSrcweir 
3319*cdf0e10cSrcweir void CheckBox::ImplLoadRes( const ResId& rResId )
3320*cdf0e10cSrcweir {
3321*cdf0e10cSrcweir     Button::ImplLoadRes( rResId );
3322*cdf0e10cSrcweir 
3323*cdf0e10cSrcweir     if ( rResId.GetRT() != RSC_TRISTATEBOX )
3324*cdf0e10cSrcweir     {
3325*cdf0e10cSrcweir         sal_uInt16 nChecked = ReadShortRes();
3326*cdf0e10cSrcweir         //anderer Wert als Default ?
3327*cdf0e10cSrcweir         if( nChecked )
3328*cdf0e10cSrcweir             Check( sal_True );
3329*cdf0e10cSrcweir     }
3330*cdf0e10cSrcweir }
3331*cdf0e10cSrcweir 
3332*cdf0e10cSrcweir // -----------------------------------------------------------------------
3333*cdf0e10cSrcweir 
3334*cdf0e10cSrcweir void CheckBox::ImplInvalidateOrDrawCheckBoxState()
3335*cdf0e10cSrcweir {
3336*cdf0e10cSrcweir     if( ImplGetSVData()->maNWFData.mbCheckBoxNeedsErase )
3337*cdf0e10cSrcweir     {
3338*cdf0e10cSrcweir         if ( IsNativeControlSupported(CTRL_CHECKBOX, PART_ENTIRE_CONTROL) )
3339*cdf0e10cSrcweir         {
3340*cdf0e10cSrcweir             Invalidate();
3341*cdf0e10cSrcweir             Update();
3342*cdf0e10cSrcweir             return;
3343*cdf0e10cSrcweir         }
3344*cdf0e10cSrcweir     }
3345*cdf0e10cSrcweir     ImplDrawCheckBoxState();
3346*cdf0e10cSrcweir }
3347*cdf0e10cSrcweir 
3348*cdf0e10cSrcweir void CheckBox::ImplDrawCheckBoxState()
3349*cdf0e10cSrcweir {
3350*cdf0e10cSrcweir     bool	bNativeOK = sal_True;
3351*cdf0e10cSrcweir 
3352*cdf0e10cSrcweir     if ( (bNativeOK=IsNativeControlSupported(CTRL_CHECKBOX, PART_ENTIRE_CONTROL)) == sal_True )
3353*cdf0e10cSrcweir     {
3354*cdf0e10cSrcweir         ImplControlValue    aControlValue( meState == STATE_CHECK ? BUTTONVALUE_ON : BUTTONVALUE_OFF );
3355*cdf0e10cSrcweir         Rectangle           aCtrlRegion( maStateRect );
3356*cdf0e10cSrcweir         ControlState        nState = 0;
3357*cdf0e10cSrcweir 
3358*cdf0e10cSrcweir         if ( HasFocus() ) 						nState |= CTRL_STATE_FOCUSED;
3359*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_DEFAULT )	nState |= CTRL_STATE_DEFAULT;
3360*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )	nState |= CTRL_STATE_PRESSED;
3361*cdf0e10cSrcweir         if ( IsEnabled() )						nState |= CTRL_STATE_ENABLED;
3362*cdf0e10cSrcweir 
3363*cdf0e10cSrcweir         if ( meState == STATE_CHECK )
3364*cdf0e10cSrcweir             aControlValue.setTristateVal( BUTTONVALUE_ON );
3365*cdf0e10cSrcweir         else if ( meState == STATE_DONTKNOW )
3366*cdf0e10cSrcweir             aControlValue.setTristateVal( BUTTONVALUE_MIXED );
3367*cdf0e10cSrcweir 
3368*cdf0e10cSrcweir         if ( IsMouseOver() && maMouseRect.IsInside( GetPointerPosPixel() ) )
3369*cdf0e10cSrcweir             nState |= CTRL_STATE_ROLLOVER;
3370*cdf0e10cSrcweir 
3371*cdf0e10cSrcweir         bNativeOK = DrawNativeControl( CTRL_CHECKBOX, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
3372*cdf0e10cSrcweir 	     						aControlValue, rtl::OUString() );
3373*cdf0e10cSrcweir     }
3374*cdf0e10cSrcweir 
3375*cdf0e10cSrcweir     if ( bNativeOK == sal_False )
3376*cdf0e10cSrcweir     {
3377*cdf0e10cSrcweir         sal_uInt16 nStyle = ImplGetButtonState();
3378*cdf0e10cSrcweir         if ( !IsEnabled() )
3379*cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_DISABLED;
3380*cdf0e10cSrcweir         if ( meState == STATE_DONTKNOW )
3381*cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_DONTKNOW;
3382*cdf0e10cSrcweir         else if ( meState == STATE_CHECK )
3383*cdf0e10cSrcweir             nStyle |= BUTTON_DRAW_CHECKED;
3384*cdf0e10cSrcweir         Image aImage = GetCheckImage( GetSettings(), nStyle );
3385*cdf0e10cSrcweir         if ( IsZoom() )
3386*cdf0e10cSrcweir             DrawImage( maStateRect.TopLeft(), maStateRect.GetSize(), aImage );
3387*cdf0e10cSrcweir         else
3388*cdf0e10cSrcweir             DrawImage( maStateRect.TopLeft(), aImage );
3389*cdf0e10cSrcweir     }
3390*cdf0e10cSrcweir }
3391*cdf0e10cSrcweir 
3392*cdf0e10cSrcweir // -----------------------------------------------------------------------
3393*cdf0e10cSrcweir 
3394*cdf0e10cSrcweir void CheckBox::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
3395*cdf0e10cSrcweir                          const Point& rPos, const Size& rSize,
3396*cdf0e10cSrcweir                          const Size& rImageSize, Rectangle& rStateRect,
3397*cdf0e10cSrcweir                          Rectangle& rMouseRect, bool bLayout )
3398*cdf0e10cSrcweir {
3399*cdf0e10cSrcweir     WinBits                 nWinStyle = GetStyle();
3400*cdf0e10cSrcweir     XubString               aText( GetText() );
3401*cdf0e10cSrcweir 
3402*cdf0e10cSrcweir     pDev->Push( PUSH_CLIPREGION | PUSH_LINECOLOR );
3403*cdf0e10cSrcweir     pDev->IntersectClipRegion( Rectangle( rPos, rSize ) );
3404*cdf0e10cSrcweir 
3405*cdf0e10cSrcweir     long nLineY = rPos.Y() + (rSize.Height()-1)/2;
3406*cdf0e10cSrcweir     if ( ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) ) ||
3407*cdf0e10cSrcweir          ( HasImage() && !  (ImplGetButtonState() & BUTTON_DRAW_NOIMAGE) ) )
3408*cdf0e10cSrcweir     {
3409*cdf0e10cSrcweir         sal_uInt16 nTextStyle = Button::ImplGetTextStyle( aText, nWinStyle, nDrawFlags );
3410*cdf0e10cSrcweir 
3411*cdf0e10cSrcweir         const long nImageSep = GetDrawPixel( pDev, ImplGetImageToTextDistance() );
3412*cdf0e10cSrcweir         Size aSize( rSize );
3413*cdf0e10cSrcweir         Point aPos( rPos );
3414*cdf0e10cSrcweir         aPos.X() += rImageSize.Width() + nImageSep;
3415*cdf0e10cSrcweir         aSize.Width() -= rImageSize.Width() + nImageSep;
3416*cdf0e10cSrcweir 
3417*cdf0e10cSrcweir         // if the text rect height is smaller than the height of the image
3418*cdf0e10cSrcweir         // then for single lines the default should be centered text
3419*cdf0e10cSrcweir         if( (nWinStyle & (WB_TOP|WB_VCENTER|WB_BOTTOM)) == 0 &&
3420*cdf0e10cSrcweir             (rImageSize.Height() > rSize.Height() || ! (nWinStyle & WB_WORDBREAK) ) )
3421*cdf0e10cSrcweir         {
3422*cdf0e10cSrcweir             nTextStyle &= ~(TEXT_DRAW_TOP|TEXT_DRAW_BOTTOM);
3423*cdf0e10cSrcweir             nTextStyle |= TEXT_DRAW_VCENTER;
3424*cdf0e10cSrcweir             aSize.Height() = rImageSize.Height();
3425*cdf0e10cSrcweir         }
3426*cdf0e10cSrcweir 
3427*cdf0e10cSrcweir         ImplDrawAlignedImage( pDev, aPos, aSize, bLayout, 1,
3428*cdf0e10cSrcweir                               nDrawFlags, nTextStyle, NULL );
3429*cdf0e10cSrcweir         nLineY = aPos.Y() + aSize.Height()/2;
3430*cdf0e10cSrcweir 
3431*cdf0e10cSrcweir         rMouseRect          = Rectangle( aPos, aSize );
3432*cdf0e10cSrcweir         rMouseRect.Left()   = rPos.X();
3433*cdf0e10cSrcweir         rStateRect.Left()   = rPos.X();
3434*cdf0e10cSrcweir         rStateRect.Top()    = rMouseRect.Top();
3435*cdf0e10cSrcweir 
3436*cdf0e10cSrcweir         if ( aSize.Height() > rImageSize.Height() )
3437*cdf0e10cSrcweir             rStateRect.Top() += ( aSize.Height() - rImageSize.Height() ) / 2;
3438*cdf0e10cSrcweir         else
3439*cdf0e10cSrcweir         {
3440*cdf0e10cSrcweir             rStateRect.Top() -= ( rImageSize.Height() - aSize.Height() ) / 2;
3441*cdf0e10cSrcweir             if( rStateRect.Top() < 0 )
3442*cdf0e10cSrcweir                 rStateRect.Top() = 0;
3443*cdf0e10cSrcweir         }
3444*cdf0e10cSrcweir 
3445*cdf0e10cSrcweir         rStateRect.Right()  = rStateRect.Left()+rImageSize.Width()-1;
3446*cdf0e10cSrcweir         rStateRect.Bottom() = rStateRect.Top()+rImageSize.Height()-1;
3447*cdf0e10cSrcweir         if ( rStateRect.Bottom() > rMouseRect.Bottom() )
3448*cdf0e10cSrcweir             rMouseRect.Bottom() = rStateRect.Bottom();
3449*cdf0e10cSrcweir     }
3450*cdf0e10cSrcweir     else
3451*cdf0e10cSrcweir     {
3452*cdf0e10cSrcweir         if ( nWinStyle & WB_CENTER )
3453*cdf0e10cSrcweir             rStateRect.Left() = rPos.X()+((rSize.Width()-rImageSize.Width())/2);
3454*cdf0e10cSrcweir         else if ( nWinStyle & WB_RIGHT )
3455*cdf0e10cSrcweir             rStateRect.Left() = rPos.X()+rSize.Width()-rImageSize.Width();
3456*cdf0e10cSrcweir         else
3457*cdf0e10cSrcweir             rStateRect.Left() = rPos.X();
3458*cdf0e10cSrcweir         if ( nWinStyle & WB_VCENTER )
3459*cdf0e10cSrcweir             rStateRect.Top() = rPos.Y()+((rSize.Height()-rImageSize.Height())/2);
3460*cdf0e10cSrcweir         else if ( nWinStyle & WB_BOTTOM )
3461*cdf0e10cSrcweir             rStateRect.Top() = rPos.Y()+rSize.Height()-rImageSize.Height();
3462*cdf0e10cSrcweir         else
3463*cdf0e10cSrcweir             rStateRect.Top() = rPos.Y();
3464*cdf0e10cSrcweir         rStateRect.Right()  = rStateRect.Left()+rImageSize.Width()-1;
3465*cdf0e10cSrcweir         rStateRect.Bottom() = rStateRect.Top()+rImageSize.Height()-1;
3466*cdf0e10cSrcweir         // provide space for focusrect
3467*cdf0e10cSrcweir         // note: this assumes that the control's size was adjusted
3468*cdf0e10cSrcweir         // accordingly in Get/LoseFocus, so the onscreen position won't change
3469*cdf0e10cSrcweir         if( HasFocus() )
3470*cdf0e10cSrcweir             rStateRect.Move( 1, 1 );
3471*cdf0e10cSrcweir         rMouseRect          = rStateRect;
3472*cdf0e10cSrcweir 
3473*cdf0e10cSrcweir         ImplSetFocusRect( rStateRect );
3474*cdf0e10cSrcweir     }
3475*cdf0e10cSrcweir 
3476*cdf0e10cSrcweir     const int nLineSpace = 4;
3477*cdf0e10cSrcweir     if( (GetStyle() & WB_CBLINESTYLE) != 0 &&
3478*cdf0e10cSrcweir         rMouseRect.Right()-1-nLineSpace < rPos.X()+rSize.Width() )
3479*cdf0e10cSrcweir     {
3480*cdf0e10cSrcweir         const StyleSettings&	rStyleSettings = GetSettings().GetStyleSettings();
3481*cdf0e10cSrcweir         if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
3482*cdf0e10cSrcweir             SetLineColor( Color( COL_BLACK ) );
3483*cdf0e10cSrcweir         else
3484*cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetShadowColor() );
3485*cdf0e10cSrcweir         long nLineX = rMouseRect.Right()+nLineSpace;
3486*cdf0e10cSrcweir         DrawLine( Point( nLineX, nLineY ), Point( rPos.X() + rSize.Width()-1, nLineY ) );
3487*cdf0e10cSrcweir         if ( !(rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
3488*cdf0e10cSrcweir         {
3489*cdf0e10cSrcweir             SetLineColor( rStyleSettings.GetLightColor() );
3490*cdf0e10cSrcweir             DrawLine( Point( nLineX, nLineY+1 ), Point( rPos.X() + rSize.Width()-1, nLineY+1 ) );
3491*cdf0e10cSrcweir         }
3492*cdf0e10cSrcweir     }
3493*cdf0e10cSrcweir 
3494*cdf0e10cSrcweir     pDev->Pop();
3495*cdf0e10cSrcweir }
3496*cdf0e10cSrcweir 
3497*cdf0e10cSrcweir // -----------------------------------------------------------------------
3498*cdf0e10cSrcweir 
3499*cdf0e10cSrcweir void CheckBox::ImplDrawCheckBox( bool bLayout )
3500*cdf0e10cSrcweir {
3501*cdf0e10cSrcweir     Size aImageSize = ImplGetCheckImageSize();
3502*cdf0e10cSrcweir     aImageSize.Width()  = CalcZoom( aImageSize.Width() );
3503*cdf0e10cSrcweir     aImageSize.Height() = CalcZoom( aImageSize.Height() );
3504*cdf0e10cSrcweir 
3505*cdf0e10cSrcweir     if( !bLayout )
3506*cdf0e10cSrcweir         HideFocus();
3507*cdf0e10cSrcweir 
3508*cdf0e10cSrcweir     ImplDraw( this, 0, Point(), GetOutputSizePixel(), aImageSize,
3509*cdf0e10cSrcweir               maStateRect, maMouseRect, bLayout );
3510*cdf0e10cSrcweir 
3511*cdf0e10cSrcweir     if( !bLayout )
3512*cdf0e10cSrcweir     {
3513*cdf0e10cSrcweir         ImplDrawCheckBoxState();
3514*cdf0e10cSrcweir         if ( HasFocus() )
3515*cdf0e10cSrcweir             ShowFocus( ImplGetFocusRect() );
3516*cdf0e10cSrcweir     }
3517*cdf0e10cSrcweir }
3518*cdf0e10cSrcweir 
3519*cdf0e10cSrcweir // -----------------------------------------------------------------------
3520*cdf0e10cSrcweir 
3521*cdf0e10cSrcweir void CheckBox::ImplCheck()
3522*cdf0e10cSrcweir {
3523*cdf0e10cSrcweir     TriState eNewState;
3524*cdf0e10cSrcweir     if ( meState == STATE_NOCHECK )
3525*cdf0e10cSrcweir         eNewState = STATE_CHECK;
3526*cdf0e10cSrcweir     else if ( !mbTriState )
3527*cdf0e10cSrcweir         eNewState = STATE_NOCHECK;
3528*cdf0e10cSrcweir     else if ( meState == STATE_CHECK )
3529*cdf0e10cSrcweir         eNewState = STATE_DONTKNOW;
3530*cdf0e10cSrcweir     else
3531*cdf0e10cSrcweir         eNewState = STATE_NOCHECK;
3532*cdf0e10cSrcweir     meState = eNewState;
3533*cdf0e10cSrcweir 
3534*cdf0e10cSrcweir     ImplDelData aDelData;
3535*cdf0e10cSrcweir     ImplAddDel( &aDelData );
3536*cdf0e10cSrcweir     if( (GetStyle() & WB_EARLYTOGGLE) )
3537*cdf0e10cSrcweir         Toggle();
3538*cdf0e10cSrcweir     ImplInvalidateOrDrawCheckBoxState();
3539*cdf0e10cSrcweir     if( ! (GetStyle() & WB_EARLYTOGGLE) )
3540*cdf0e10cSrcweir         Toggle();
3541*cdf0e10cSrcweir     if ( aDelData.IsDelete() )
3542*cdf0e10cSrcweir         return;
3543*cdf0e10cSrcweir     ImplRemoveDel( &aDelData );
3544*cdf0e10cSrcweir     Click();
3545*cdf0e10cSrcweir }
3546*cdf0e10cSrcweir 
3547*cdf0e10cSrcweir // -----------------------------------------------------------------------
3548*cdf0e10cSrcweir 
3549*cdf0e10cSrcweir CheckBox::CheckBox( Window* pParent, WinBits nStyle ) :
3550*cdf0e10cSrcweir     Button( WINDOW_CHECKBOX )
3551*cdf0e10cSrcweir {
3552*cdf0e10cSrcweir     ImplInitCheckBoxData();
3553*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
3554*cdf0e10cSrcweir }
3555*cdf0e10cSrcweir 
3556*cdf0e10cSrcweir // -----------------------------------------------------------------------
3557*cdf0e10cSrcweir 
3558*cdf0e10cSrcweir CheckBox::CheckBox( Window* pParent, const ResId& rResId ) :
3559*cdf0e10cSrcweir     Button( WINDOW_CHECKBOX )
3560*cdf0e10cSrcweir {
3561*cdf0e10cSrcweir     ImplInitCheckBoxData();
3562*cdf0e10cSrcweir     rResId.SetRT( RSC_CHECKBOX );
3563*cdf0e10cSrcweir     WinBits nStyle = ImplInitRes( rResId );
3564*cdf0e10cSrcweir     ImplInit( pParent, nStyle );
3565*cdf0e10cSrcweir     ImplLoadRes( rResId );
3566*cdf0e10cSrcweir 
3567*cdf0e10cSrcweir     if ( !(nStyle & WB_HIDE) )
3568*cdf0e10cSrcweir         Show();
3569*cdf0e10cSrcweir }
3570*cdf0e10cSrcweir 
3571*cdf0e10cSrcweir // -----------------------------------------------------------------------
3572*cdf0e10cSrcweir 
3573*cdf0e10cSrcweir void CheckBox::MouseButtonDown( const MouseEvent& rMEvt )
3574*cdf0e10cSrcweir {
3575*cdf0e10cSrcweir     if ( rMEvt.IsLeft() && maMouseRect.IsInside( rMEvt.GetPosPixel() ) )
3576*cdf0e10cSrcweir     {
3577*cdf0e10cSrcweir         ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
3578*cdf0e10cSrcweir         ImplInvalidateOrDrawCheckBoxState();
3579*cdf0e10cSrcweir         StartTracking();
3580*cdf0e10cSrcweir         return;
3581*cdf0e10cSrcweir     }
3582*cdf0e10cSrcweir 
3583*cdf0e10cSrcweir     Button::MouseButtonDown( rMEvt );
3584*cdf0e10cSrcweir }
3585*cdf0e10cSrcweir 
3586*cdf0e10cSrcweir // -----------------------------------------------------------------------
3587*cdf0e10cSrcweir 
3588*cdf0e10cSrcweir void CheckBox::Tracking( const TrackingEvent& rTEvt )
3589*cdf0e10cSrcweir {
3590*cdf0e10cSrcweir     if ( rTEvt.IsTrackingEnded() )
3591*cdf0e10cSrcweir     {
3592*cdf0e10cSrcweir         if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
3593*cdf0e10cSrcweir         {
3594*cdf0e10cSrcweir             if ( !(GetStyle() & WB_NOPOINTERFOCUS) && !rTEvt.IsTrackingCanceled() )
3595*cdf0e10cSrcweir                 GrabFocus();
3596*cdf0e10cSrcweir 
3597*cdf0e10cSrcweir             ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
3598*cdf0e10cSrcweir 
3599*cdf0e10cSrcweir             // Bei Abbruch kein Click-Handler rufen
3600*cdf0e10cSrcweir             if ( !rTEvt.IsTrackingCanceled() )
3601*cdf0e10cSrcweir                 ImplCheck();
3602*cdf0e10cSrcweir             else
3603*cdf0e10cSrcweir                 ImplInvalidateOrDrawCheckBoxState();
3604*cdf0e10cSrcweir         }
3605*cdf0e10cSrcweir     }
3606*cdf0e10cSrcweir     else
3607*cdf0e10cSrcweir     {
3608*cdf0e10cSrcweir         if ( maMouseRect.IsInside( rTEvt.GetMouseEvent().GetPosPixel() ) )
3609*cdf0e10cSrcweir         {
3610*cdf0e10cSrcweir             if ( !(ImplGetButtonState() & BUTTON_DRAW_PRESSED) )
3611*cdf0e10cSrcweir             {
3612*cdf0e10cSrcweir                 ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
3613*cdf0e10cSrcweir                 ImplInvalidateOrDrawCheckBoxState();
3614*cdf0e10cSrcweir             }
3615*cdf0e10cSrcweir         }
3616*cdf0e10cSrcweir         else
3617*cdf0e10cSrcweir         {
3618*cdf0e10cSrcweir             if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
3619*cdf0e10cSrcweir             {
3620*cdf0e10cSrcweir                 ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
3621*cdf0e10cSrcweir                 ImplInvalidateOrDrawCheckBoxState();
3622*cdf0e10cSrcweir             }
3623*cdf0e10cSrcweir         }
3624*cdf0e10cSrcweir     }
3625*cdf0e10cSrcweir }
3626*cdf0e10cSrcweir 
3627*cdf0e10cSrcweir // -----------------------------------------------------------------------
3628*cdf0e10cSrcweir 
3629*cdf0e10cSrcweir void CheckBox::KeyInput( const KeyEvent& rKEvt )
3630*cdf0e10cSrcweir {
3631*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
3632*cdf0e10cSrcweir 
3633*cdf0e10cSrcweir     if ( !aKeyCode.GetModifier() && (aKeyCode.GetCode() == KEY_SPACE) )
3634*cdf0e10cSrcweir     {
3635*cdf0e10cSrcweir         if ( !(ImplGetButtonState() & BUTTON_DRAW_PRESSED) )
3636*cdf0e10cSrcweir         {
3637*cdf0e10cSrcweir             ImplGetButtonState() |= BUTTON_DRAW_PRESSED;
3638*cdf0e10cSrcweir             ImplInvalidateOrDrawCheckBoxState();
3639*cdf0e10cSrcweir         }
3640*cdf0e10cSrcweir     }
3641*cdf0e10cSrcweir     else if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) && (aKeyCode.GetCode() == KEY_ESCAPE) )
3642*cdf0e10cSrcweir     {
3643*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
3644*cdf0e10cSrcweir         ImplInvalidateOrDrawCheckBoxState();
3645*cdf0e10cSrcweir     }
3646*cdf0e10cSrcweir     else
3647*cdf0e10cSrcweir         Button::KeyInput( rKEvt );
3648*cdf0e10cSrcweir }
3649*cdf0e10cSrcweir 
3650*cdf0e10cSrcweir // -----------------------------------------------------------------------
3651*cdf0e10cSrcweir 
3652*cdf0e10cSrcweir void CheckBox::KeyUp( const KeyEvent& rKEvt )
3653*cdf0e10cSrcweir {
3654*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
3655*cdf0e10cSrcweir 
3656*cdf0e10cSrcweir     if ( (ImplGetButtonState() & BUTTON_DRAW_PRESSED) && (aKeyCode.GetCode() == KEY_SPACE) )
3657*cdf0e10cSrcweir     {
3658*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
3659*cdf0e10cSrcweir         ImplCheck();
3660*cdf0e10cSrcweir     }
3661*cdf0e10cSrcweir     else
3662*cdf0e10cSrcweir         Button::KeyUp( rKEvt );
3663*cdf0e10cSrcweir }
3664*cdf0e10cSrcweir 
3665*cdf0e10cSrcweir // -----------------------------------------------------------------------
3666*cdf0e10cSrcweir 
3667*cdf0e10cSrcweir void CheckBox::FillLayoutData() const
3668*cdf0e10cSrcweir {
3669*cdf0e10cSrcweir     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
3670*cdf0e10cSrcweir     const_cast<CheckBox*>(this)->ImplDrawCheckBox( true );
3671*cdf0e10cSrcweir }
3672*cdf0e10cSrcweir 
3673*cdf0e10cSrcweir // -----------------------------------------------------------------------
3674*cdf0e10cSrcweir 
3675*cdf0e10cSrcweir void CheckBox::Paint( const Rectangle& )
3676*cdf0e10cSrcweir {
3677*cdf0e10cSrcweir     ImplDrawCheckBox();
3678*cdf0e10cSrcweir }
3679*cdf0e10cSrcweir 
3680*cdf0e10cSrcweir // -----------------------------------------------------------------------
3681*cdf0e10cSrcweir 
3682*cdf0e10cSrcweir void CheckBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
3683*cdf0e10cSrcweir                      sal_uLong nFlags )
3684*cdf0e10cSrcweir {
3685*cdf0e10cSrcweir     MapMode     aResMapMode( MAP_100TH_MM );
3686*cdf0e10cSrcweir     Point       aPos  = pDev->LogicToPixel( rPos );
3687*cdf0e10cSrcweir     Size        aSize = pDev->LogicToPixel( rSize );
3688*cdf0e10cSrcweir     Size        aImageSize = pDev->LogicToPixel( Size( 300, 300 ), aResMapMode );
3689*cdf0e10cSrcweir     Size        aBrd1Size = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode );
3690*cdf0e10cSrcweir     Size        aBrd2Size = pDev->LogicToPixel( Size( 30, 30 ), aResMapMode );
3691*cdf0e10cSrcweir     long        nCheckWidth = pDev->LogicToPixel( Size( 20, 20 ), aResMapMode ).Width();
3692*cdf0e10cSrcweir     Font        aFont = GetDrawPixelFont( pDev );
3693*cdf0e10cSrcweir     Rectangle   aStateRect;
3694*cdf0e10cSrcweir     Rectangle   aMouseRect;
3695*cdf0e10cSrcweir 
3696*cdf0e10cSrcweir     aImageSize.Width()  = CalcZoom( aImageSize.Width() );
3697*cdf0e10cSrcweir     aImageSize.Height() = CalcZoom( aImageSize.Height() );
3698*cdf0e10cSrcweir     aBrd1Size.Width()   = CalcZoom( aBrd1Size.Width() );
3699*cdf0e10cSrcweir     aBrd1Size.Height()  = CalcZoom( aBrd1Size.Height() );
3700*cdf0e10cSrcweir     aBrd2Size.Width()   = CalcZoom( aBrd2Size.Width() );
3701*cdf0e10cSrcweir     aBrd2Size.Height()  = CalcZoom( aBrd2Size.Height() );
3702*cdf0e10cSrcweir 
3703*cdf0e10cSrcweir     if ( !aBrd1Size.Width() )
3704*cdf0e10cSrcweir         aBrd1Size.Width() = 1;
3705*cdf0e10cSrcweir     if ( !aBrd1Size.Height() )
3706*cdf0e10cSrcweir         aBrd1Size.Height() = 1;
3707*cdf0e10cSrcweir     if ( !aBrd2Size.Width() )
3708*cdf0e10cSrcweir         aBrd2Size.Width() = 1;
3709*cdf0e10cSrcweir     if ( !aBrd2Size.Height() )
3710*cdf0e10cSrcweir         aBrd2Size.Height() = 1;
3711*cdf0e10cSrcweir     if ( !nCheckWidth )
3712*cdf0e10cSrcweir         nCheckWidth = 1;
3713*cdf0e10cSrcweir 
3714*cdf0e10cSrcweir     pDev->Push();
3715*cdf0e10cSrcweir     pDev->SetMapMode();
3716*cdf0e10cSrcweir     pDev->SetFont( aFont );
3717*cdf0e10cSrcweir     if ( nFlags & WINDOW_DRAW_MONO )
3718*cdf0e10cSrcweir         pDev->SetTextColor( Color( COL_BLACK ) );
3719*cdf0e10cSrcweir     else
3720*cdf0e10cSrcweir         pDev->SetTextColor( GetTextColor() );
3721*cdf0e10cSrcweir     pDev->SetTextFillColor();
3722*cdf0e10cSrcweir 
3723*cdf0e10cSrcweir     ImplDraw( pDev, nFlags, aPos, aSize,
3724*cdf0e10cSrcweir               aImageSize, aStateRect, aMouseRect, false );
3725*cdf0e10cSrcweir 
3726*cdf0e10cSrcweir     pDev->SetLineColor();
3727*cdf0e10cSrcweir     pDev->SetFillColor( Color( COL_BLACK ) );
3728*cdf0e10cSrcweir     pDev->DrawRect( aStateRect );
3729*cdf0e10cSrcweir     aStateRect.Left()   += aBrd1Size.Width();
3730*cdf0e10cSrcweir     aStateRect.Top()    += aBrd1Size.Height();
3731*cdf0e10cSrcweir     aStateRect.Right()  -= aBrd1Size.Width();
3732*cdf0e10cSrcweir     aStateRect.Bottom() -= aBrd1Size.Height();
3733*cdf0e10cSrcweir     if ( meState == STATE_DONTKNOW )
3734*cdf0e10cSrcweir         pDev->SetFillColor( Color( COL_LIGHTGRAY ) );
3735*cdf0e10cSrcweir     else
3736*cdf0e10cSrcweir         pDev->SetFillColor( Color( COL_WHITE ) );
3737*cdf0e10cSrcweir     pDev->DrawRect( aStateRect );
3738*cdf0e10cSrcweir 
3739*cdf0e10cSrcweir     if ( meState == STATE_CHECK )
3740*cdf0e10cSrcweir     {
3741*cdf0e10cSrcweir         aStateRect.Left()   += aBrd2Size.Width();
3742*cdf0e10cSrcweir         aStateRect.Top()    += aBrd2Size.Height();
3743*cdf0e10cSrcweir         aStateRect.Right()  -= aBrd2Size.Width();
3744*cdf0e10cSrcweir         aStateRect.Bottom() -= aBrd2Size.Height();
3745*cdf0e10cSrcweir         Point   aPos11( aStateRect.TopLeft() );
3746*cdf0e10cSrcweir         Point   aPos12( aStateRect.BottomRight() );
3747*cdf0e10cSrcweir         Point   aPos21( aStateRect.TopRight() );
3748*cdf0e10cSrcweir         Point   aPos22( aStateRect.BottomLeft() );
3749*cdf0e10cSrcweir         Point   aTempPos11( aPos11 );
3750*cdf0e10cSrcweir         Point   aTempPos12( aPos12 );
3751*cdf0e10cSrcweir         Point   aTempPos21( aPos21 );
3752*cdf0e10cSrcweir         Point   aTempPos22( aPos22 );
3753*cdf0e10cSrcweir         pDev->SetLineColor( Color( COL_BLACK ) );
3754*cdf0e10cSrcweir         long nDX = 0;
3755*cdf0e10cSrcweir         for ( long i = 0; i < nCheckWidth; i++ )
3756*cdf0e10cSrcweir         {
3757*cdf0e10cSrcweir             if ( !(i % 2) )
3758*cdf0e10cSrcweir             {
3759*cdf0e10cSrcweir                 aTempPos11.X() = aPos11.X()+nDX;
3760*cdf0e10cSrcweir                 aTempPos12.X() = aPos12.X()+nDX;
3761*cdf0e10cSrcweir                 aTempPos21.X() = aPos21.X()+nDX;
3762*cdf0e10cSrcweir                 aTempPos22.X() = aPos22.X()+nDX;
3763*cdf0e10cSrcweir             }
3764*cdf0e10cSrcweir             else
3765*cdf0e10cSrcweir             {
3766*cdf0e10cSrcweir                 nDX++;
3767*cdf0e10cSrcweir                 aTempPos11.X() = aPos11.X()-nDX;
3768*cdf0e10cSrcweir                 aTempPos12.X() = aPos12.X()-nDX;
3769*cdf0e10cSrcweir                 aTempPos21.X() = aPos21.X()-nDX;
3770*cdf0e10cSrcweir                 aTempPos22.X() = aPos22.X()-nDX;
3771*cdf0e10cSrcweir             }
3772*cdf0e10cSrcweir             pDev->DrawLine( aTempPos11, aTempPos12 );
3773*cdf0e10cSrcweir             pDev->DrawLine( aTempPos21, aTempPos22 );
3774*cdf0e10cSrcweir         }
3775*cdf0e10cSrcweir     }
3776*cdf0e10cSrcweir 
3777*cdf0e10cSrcweir     pDev->Pop();
3778*cdf0e10cSrcweir }
3779*cdf0e10cSrcweir 
3780*cdf0e10cSrcweir // -----------------------------------------------------------------------
3781*cdf0e10cSrcweir 
3782*cdf0e10cSrcweir void CheckBox::Resize()
3783*cdf0e10cSrcweir {
3784*cdf0e10cSrcweir     Control::Resize();
3785*cdf0e10cSrcweir     Invalidate();
3786*cdf0e10cSrcweir }
3787*cdf0e10cSrcweir 
3788*cdf0e10cSrcweir // -----------------------------------------------------------------------
3789*cdf0e10cSrcweir 
3790*cdf0e10cSrcweir void CheckBox::GetFocus()
3791*cdf0e10cSrcweir {
3792*cdf0e10cSrcweir     if ( !GetText().Len() || (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
3793*cdf0e10cSrcweir     {
3794*cdf0e10cSrcweir         // increase button size to have space for focus rect
3795*cdf0e10cSrcweir         // checkboxes without text will draw focusrect around the check
3796*cdf0e10cSrcweir         // See CheckBox::ImplDraw()
3797*cdf0e10cSrcweir         Point aPos( GetPosPixel() );
3798*cdf0e10cSrcweir         Size aSize( GetSizePixel() );
3799*cdf0e10cSrcweir         aPos.Move(-1,-1);
3800*cdf0e10cSrcweir         aSize.Height() += 2;
3801*cdf0e10cSrcweir         aSize.Width() += 2;
3802*cdf0e10cSrcweir         SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height(), WINDOW_POSSIZE_ALL );
3803*cdf0e10cSrcweir         ImplDrawCheckBox();
3804*cdf0e10cSrcweir     }
3805*cdf0e10cSrcweir     else
3806*cdf0e10cSrcweir         ShowFocus( ImplGetFocusRect() );
3807*cdf0e10cSrcweir 
3808*cdf0e10cSrcweir     SetInputContext( InputContext( GetFont() ) );
3809*cdf0e10cSrcweir     Button::GetFocus();
3810*cdf0e10cSrcweir }
3811*cdf0e10cSrcweir 
3812*cdf0e10cSrcweir // -----------------------------------------------------------------------
3813*cdf0e10cSrcweir 
3814*cdf0e10cSrcweir void CheckBox::LoseFocus()
3815*cdf0e10cSrcweir {
3816*cdf0e10cSrcweir     if ( ImplGetButtonState() & BUTTON_DRAW_PRESSED )
3817*cdf0e10cSrcweir     {
3818*cdf0e10cSrcweir         ImplGetButtonState() &= ~BUTTON_DRAW_PRESSED;
3819*cdf0e10cSrcweir         ImplInvalidateOrDrawCheckBoxState();
3820*cdf0e10cSrcweir     }
3821*cdf0e10cSrcweir 
3822*cdf0e10cSrcweir     HideFocus();
3823*cdf0e10cSrcweir     Button::LoseFocus();
3824*cdf0e10cSrcweir 
3825*cdf0e10cSrcweir     if ( !GetText().Len() || (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
3826*cdf0e10cSrcweir     {
3827*cdf0e10cSrcweir         // decrease button size again (see GetFocus())
3828*cdf0e10cSrcweir         // checkboxes without text will draw focusrect around the check
3829*cdf0e10cSrcweir         Point aPos( GetPosPixel() );
3830*cdf0e10cSrcweir         Size aSize( GetSizePixel() );
3831*cdf0e10cSrcweir         aPos.Move(1,1);
3832*cdf0e10cSrcweir         aSize.Height() -= 2;
3833*cdf0e10cSrcweir         aSize.Width() -= 2;
3834*cdf0e10cSrcweir         SetPosSizePixel( aPos.X(), aPos.Y(), aSize.Width(), aSize.Height(), WINDOW_POSSIZE_ALL );
3835*cdf0e10cSrcweir         ImplDrawCheckBox();
3836*cdf0e10cSrcweir     }
3837*cdf0e10cSrcweir }
3838*cdf0e10cSrcweir 
3839*cdf0e10cSrcweir // -----------------------------------------------------------------------
3840*cdf0e10cSrcweir 
3841*cdf0e10cSrcweir void CheckBox::StateChanged( StateChangedType nType )
3842*cdf0e10cSrcweir {
3843*cdf0e10cSrcweir     Button::StateChanged( nType );
3844*cdf0e10cSrcweir 
3845*cdf0e10cSrcweir     if ( nType == STATE_CHANGE_STATE )
3846*cdf0e10cSrcweir     {
3847*cdf0e10cSrcweir         if ( IsReallyVisible() && IsUpdateMode() )
3848*cdf0e10cSrcweir             Invalidate( maStateRect );
3849*cdf0e10cSrcweir     }
3850*cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ENABLE) ||
3851*cdf0e10cSrcweir               (nType == STATE_CHANGE_TEXT) ||
3852*cdf0e10cSrcweir               (nType == STATE_CHANGE_IMAGE) ||
3853*cdf0e10cSrcweir               (nType == STATE_CHANGE_DATA) ||
3854*cdf0e10cSrcweir               (nType == STATE_CHANGE_UPDATEMODE) )
3855*cdf0e10cSrcweir     {
3856*cdf0e10cSrcweir         if ( IsUpdateMode() )
3857*cdf0e10cSrcweir             Invalidate();
3858*cdf0e10cSrcweir     }
3859*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_STYLE )
3860*cdf0e10cSrcweir     {
3861*cdf0e10cSrcweir         SetStyle( ImplInitStyle( GetWindow( WINDOW_PREV ), GetStyle() ) );
3862*cdf0e10cSrcweir 
3863*cdf0e10cSrcweir         if ( (GetPrevStyle() & CHECKBOX_VIEW_STYLE) !=
3864*cdf0e10cSrcweir              (GetStyle() & CHECKBOX_VIEW_STYLE) )
3865*cdf0e10cSrcweir         {
3866*cdf0e10cSrcweir             if ( IsUpdateMode() )
3867*cdf0e10cSrcweir                 Invalidate();
3868*cdf0e10cSrcweir         }
3869*cdf0e10cSrcweir     }
3870*cdf0e10cSrcweir     else if ( (nType == STATE_CHANGE_ZOOM) ||
3871*cdf0e10cSrcweir               (nType == STATE_CHANGE_CONTROLFONT) )
3872*cdf0e10cSrcweir     {
3873*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
3874*cdf0e10cSrcweir         Invalidate();
3875*cdf0e10cSrcweir     }
3876*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
3877*cdf0e10cSrcweir     {
3878*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
3879*cdf0e10cSrcweir         Invalidate();
3880*cdf0e10cSrcweir     }
3881*cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
3882*cdf0e10cSrcweir     {
3883*cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
3884*cdf0e10cSrcweir         Invalidate();
3885*cdf0e10cSrcweir     }
3886*cdf0e10cSrcweir }
3887*cdf0e10cSrcweir 
3888*cdf0e10cSrcweir // -----------------------------------------------------------------------
3889*cdf0e10cSrcweir 
3890*cdf0e10cSrcweir void CheckBox::DataChanged( const DataChangedEvent& rDCEvt )
3891*cdf0e10cSrcweir {
3892*cdf0e10cSrcweir     Button::DataChanged( rDCEvt );
3893*cdf0e10cSrcweir 
3894*cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
3895*cdf0e10cSrcweir          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
3896*cdf0e10cSrcweir          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
3897*cdf0e10cSrcweir           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
3898*cdf0e10cSrcweir     {
3899*cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
3900*cdf0e10cSrcweir         Invalidate();
3901*cdf0e10cSrcweir     }
3902*cdf0e10cSrcweir }
3903*cdf0e10cSrcweir 
3904*cdf0e10cSrcweir // -----------------------------------------------------------------------
3905*cdf0e10cSrcweir 
3906*cdf0e10cSrcweir long CheckBox::PreNotify( NotifyEvent& rNEvt )
3907*cdf0e10cSrcweir {
3908*cdf0e10cSrcweir     long nDone = 0;
3909*cdf0e10cSrcweir     const MouseEvent* pMouseEvt = NULL;
3910*cdf0e10cSrcweir 
3911*cdf0e10cSrcweir     if( (rNEvt.GetType() == EVENT_MOUSEMOVE) && (pMouseEvt = rNEvt.GetMouseEvent()) != NULL )
3912*cdf0e10cSrcweir     {
3913*cdf0e10cSrcweir         if( !pMouseEvt->GetButtons() && !pMouseEvt->IsSynthetic() && !pMouseEvt->IsModifierChanged() )
3914*cdf0e10cSrcweir         {
3915*cdf0e10cSrcweir             // trigger redraw if mouse over state has changed
3916*cdf0e10cSrcweir             if( IsNativeControlSupported(CTRL_CHECKBOX, PART_ENTIRE_CONTROL) )
3917*cdf0e10cSrcweir             {
3918*cdf0e10cSrcweir                 if( ( maMouseRect.IsInside( GetPointerPosPixel()) &&
3919*cdf0e10cSrcweir                      !maMouseRect.IsInside( GetLastPointerPosPixel()) ) ||
3920*cdf0e10cSrcweir                     ( maMouseRect.IsInside( GetLastPointerPosPixel()) &&
3921*cdf0e10cSrcweir                      !maMouseRect.IsInside( GetPointerPosPixel()) ) ||
3922*cdf0e10cSrcweir                     pMouseEvt->IsLeaveWindow() || pMouseEvt->IsEnterWindow() )
3923*cdf0e10cSrcweir                 {
3924*cdf0e10cSrcweir                     Invalidate( maStateRect );
3925*cdf0e10cSrcweir                 }
3926*cdf0e10cSrcweir             }
3927*cdf0e10cSrcweir         }
3928*cdf0e10cSrcweir     }
3929*cdf0e10cSrcweir 
3930*cdf0e10cSrcweir     return nDone ? nDone : Button::PreNotify(rNEvt);
3931*cdf0e10cSrcweir }
3932*cdf0e10cSrcweir 
3933*cdf0e10cSrcweir // -----------------------------------------------------------------------
3934*cdf0e10cSrcweir 
3935*cdf0e10cSrcweir void CheckBox::Toggle()
3936*cdf0e10cSrcweir {
3937*cdf0e10cSrcweir     ImplCallEventListenersAndHandler( VCLEVENT_CHECKBOX_TOGGLE, maToggleHdl, this );
3938*cdf0e10cSrcweir }
3939*cdf0e10cSrcweir 
3940*cdf0e10cSrcweir // -----------------------------------------------------------------------
3941*cdf0e10cSrcweir 
3942*cdf0e10cSrcweir void CheckBox::SetState( TriState eState )
3943*cdf0e10cSrcweir {
3944*cdf0e10cSrcweir     if ( !mbTriState && (eState == STATE_DONTKNOW) )
3945*cdf0e10cSrcweir         eState = STATE_NOCHECK;
3946*cdf0e10cSrcweir 
3947*cdf0e10cSrcweir     if ( meState != eState )
3948*cdf0e10cSrcweir     {
3949*cdf0e10cSrcweir         meState = eState;
3950*cdf0e10cSrcweir         StateChanged( STATE_CHANGE_STATE );
3951*cdf0e10cSrcweir         Toggle();
3952*cdf0e10cSrcweir     }
3953*cdf0e10cSrcweir }
3954*cdf0e10cSrcweir 
3955*cdf0e10cSrcweir // -----------------------------------------------------------------------
3956*cdf0e10cSrcweir 
3957*cdf0e10cSrcweir void CheckBox::EnableTriState( sal_Bool bTriState )
3958*cdf0e10cSrcweir {
3959*cdf0e10cSrcweir     if ( mbTriState != bTriState )
3960*cdf0e10cSrcweir     {
3961*cdf0e10cSrcweir         mbTriState = bTriState;
3962*cdf0e10cSrcweir 
3963*cdf0e10cSrcweir         if ( !bTriState && (meState == STATE_DONTKNOW) )
3964*cdf0e10cSrcweir             SetState( STATE_NOCHECK );
3965*cdf0e10cSrcweir     }
3966*cdf0e10cSrcweir }
3967*cdf0e10cSrcweir 
3968*cdf0e10cSrcweir // -----------------------------------------------------------------------
3969*cdf0e10cSrcweir 
3970*cdf0e10cSrcweir long CheckBox::ImplGetImageToTextDistance() const
3971*cdf0e10cSrcweir {
3972*cdf0e10cSrcweir     // 4 pixels, but take zoom into account, so the text doesn't "jump" relative to surrounding elements,
3973*cdf0e10cSrcweir     // which might have been aligned with the text of the check box
3974*cdf0e10cSrcweir     return CalcZoom( 4 );
3975*cdf0e10cSrcweir }
3976*cdf0e10cSrcweir 
3977*cdf0e10cSrcweir // -----------------------------------------------------------------------
3978*cdf0e10cSrcweir 
3979*cdf0e10cSrcweir Size CheckBox::ImplGetCheckImageSize() const
3980*cdf0e10cSrcweir {
3981*cdf0e10cSrcweir     Size aSize;
3982*cdf0e10cSrcweir     // why are IsNativeControlSupported and GetNativeControlRegion not const ?
3983*cdf0e10cSrcweir     CheckBox* pThis = const_cast<CheckBox*>(this);
3984*cdf0e10cSrcweir     bool bDefaultSize = true;
3985*cdf0e10cSrcweir     if( pThis->IsNativeControlSupported( CTRL_CHECKBOX, PART_ENTIRE_CONTROL ) )
3986*cdf0e10cSrcweir     {
3987*cdf0e10cSrcweir         ImplControlValue aControlValue;
3988*cdf0e10cSrcweir         // #i45896# workaround gcc3.3 temporary problem
3989*cdf0e10cSrcweir         Rectangle		 aCtrlRegion( Point( 0, 0 ), GetSizePixel() );
3990*cdf0e10cSrcweir         ControlState	 nState = CTRL_STATE_DEFAULT|CTRL_STATE_ENABLED;
3991*cdf0e10cSrcweir         Rectangle aBoundingRgn, aContentRgn;
3992*cdf0e10cSrcweir 
3993*cdf0e10cSrcweir         // get native size of a check box
3994*cdf0e10cSrcweir         if( pThis->GetNativeControlRegion( CTRL_CHECKBOX, PART_ENTIRE_CONTROL, aCtrlRegion,
3995*cdf0e10cSrcweir                                            nState, aControlValue, rtl::OUString(),
3996*cdf0e10cSrcweir                                            aBoundingRgn, aContentRgn ) )
3997*cdf0e10cSrcweir         {
3998*cdf0e10cSrcweir             aSize = aContentRgn.GetSize();
3999*cdf0e10cSrcweir             bDefaultSize = false;
4000*cdf0e10cSrcweir         }
4001*cdf0e10cSrcweir     }
4002*cdf0e10cSrcweir     if( bDefaultSize )
4003*cdf0e10cSrcweir         aSize = GetCheckImage( GetSettings(), 0 ).GetSizePixel();
4004*cdf0e10cSrcweir     return aSize;
4005*cdf0e10cSrcweir }
4006*cdf0e10cSrcweir 
4007*cdf0e10cSrcweir Image CheckBox::GetCheckImage( const AllSettings& rSettings, sal_uInt16 nFlags )
4008*cdf0e10cSrcweir {
4009*cdf0e10cSrcweir     ImplSVData*             pSVData = ImplGetSVData();
4010*cdf0e10cSrcweir     const StyleSettings&    rStyleSettings = rSettings.GetStyleSettings();
4011*cdf0e10cSrcweir     sal_uInt16              nStyle = 0;
4012*cdf0e10cSrcweir 
4013*cdf0e10cSrcweir     if ( rStyleSettings.GetOptions() & STYLE_OPTION_MONO )
4014*cdf0e10cSrcweir         nStyle = STYLE_CHECKBOX_MONO;
4015*cdf0e10cSrcweir 
4016*cdf0e10cSrcweir     if ( !pSVData->maCtrlData.mpCheckImgList ||
4017*cdf0e10cSrcweir          (pSVData->maCtrlData.mnCheckStyle != nStyle) ||
4018*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastCheckFColor != rStyleSettings.GetFaceColor().GetColor()) ||
4019*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastCheckWColor != rStyleSettings.GetWindowColor().GetColor()) ||
4020*cdf0e10cSrcweir          (pSVData->maCtrlData.mnLastCheckLColor != rStyleSettings.GetLightColor().GetColor()) )
4021*cdf0e10cSrcweir     {
4022*cdf0e10cSrcweir         if ( pSVData->maCtrlData.mpCheckImgList )
4023*cdf0e10cSrcweir             delete pSVData->maCtrlData.mpCheckImgList;
4024*cdf0e10cSrcweir 
4025*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastCheckFColor = rStyleSettings.GetFaceColor().GetColor();
4026*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastCheckWColor = rStyleSettings.GetWindowColor().GetColor();
4027*cdf0e10cSrcweir         pSVData->maCtrlData.mnLastCheckLColor = rStyleSettings.GetLightColor().GetColor();
4028*cdf0e10cSrcweir 
4029*cdf0e10cSrcweir         ResMgr* pResMgr = ImplGetResMgr();
4030*cdf0e10cSrcweir         pSVData->maCtrlData.mpCheckImgList = new ImageList();
4031*cdf0e10cSrcweir         if( pResMgr )
4032*cdf0e10cSrcweir 	    LoadThemedImageList( rStyleSettings,
4033*cdf0e10cSrcweir 				 pSVData->maCtrlData.mpCheckImgList,
4034*cdf0e10cSrcweir 				 ResId( SV_RESID_BITMAP_CHECK+nStyle, *pResMgr ), 9 );
4035*cdf0e10cSrcweir         pSVData->maCtrlData.mnCheckStyle = nStyle;
4036*cdf0e10cSrcweir     }
4037*cdf0e10cSrcweir 
4038*cdf0e10cSrcweir     sal_uInt16 nId;
4039*cdf0e10cSrcweir     if ( nFlags & BUTTON_DRAW_DISABLED )
4040*cdf0e10cSrcweir     {
4041*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_DONTKNOW )
4042*cdf0e10cSrcweir             nId = 9;
4043*cdf0e10cSrcweir         else if ( nFlags & BUTTON_DRAW_CHECKED )
4044*cdf0e10cSrcweir             nId = 6;
4045*cdf0e10cSrcweir         else
4046*cdf0e10cSrcweir             nId = 5;
4047*cdf0e10cSrcweir     }
4048*cdf0e10cSrcweir     else if ( nFlags & BUTTON_DRAW_PRESSED )
4049*cdf0e10cSrcweir     {
4050*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_DONTKNOW )
4051*cdf0e10cSrcweir             nId = 8;
4052*cdf0e10cSrcweir         else if ( nFlags & BUTTON_DRAW_CHECKED )
4053*cdf0e10cSrcweir             nId = 4;
4054*cdf0e10cSrcweir         else
4055*cdf0e10cSrcweir             nId = 3;
4056*cdf0e10cSrcweir     }
4057*cdf0e10cSrcweir     else
4058*cdf0e10cSrcweir     {
4059*cdf0e10cSrcweir         if ( nFlags & BUTTON_DRAW_DONTKNOW )
4060*cdf0e10cSrcweir             nId = 7;
4061*cdf0e10cSrcweir         else if ( nFlags & BUTTON_DRAW_CHECKED )
4062*cdf0e10cSrcweir             nId = 2;
4063*cdf0e10cSrcweir         else
4064*cdf0e10cSrcweir             nId = 1;
4065*cdf0e10cSrcweir     }
4066*cdf0e10cSrcweir     return pSVData->maCtrlData.mpCheckImgList->GetImage( nId );
4067*cdf0e10cSrcweir }
4068*cdf0e10cSrcweir 
4069*cdf0e10cSrcweir // -----------------------------------------------------------------------
4070*cdf0e10cSrcweir 
4071*cdf0e10cSrcweir void CheckBox::ImplSetMinimumNWFSize()
4072*cdf0e10cSrcweir {
4073*cdf0e10cSrcweir     Push( PUSH_MAPMODE );
4074*cdf0e10cSrcweir     SetMapMode( MAP_PIXEL );
4075*cdf0e10cSrcweir 
4076*cdf0e10cSrcweir     ImplControlValue aControlValue;
4077*cdf0e10cSrcweir     Size aCurSize( GetSizePixel() );
4078*cdf0e10cSrcweir     Rectangle aCtrlRegion( Point( 0, 0 ), aCurSize );
4079*cdf0e10cSrcweir     Rectangle aBoundingRgn, aContentRgn;
4080*cdf0e10cSrcweir 
4081*cdf0e10cSrcweir     // get native size of a radiobutton
4082*cdf0e10cSrcweir     if( GetNativeControlRegion( CTRL_CHECKBOX, PART_ENTIRE_CONTROL, aCtrlRegion,
4083*cdf0e10cSrcweir                                 CTRL_STATE_DEFAULT|CTRL_STATE_ENABLED, aControlValue, rtl::OUString(),
4084*cdf0e10cSrcweir                                 aBoundingRgn, aContentRgn ) )
4085*cdf0e10cSrcweir     {
4086*cdf0e10cSrcweir         Size aSize = aContentRgn.GetSize();
4087*cdf0e10cSrcweir 
4088*cdf0e10cSrcweir         if( aSize.Height() > aCurSize.Height() )
4089*cdf0e10cSrcweir         {
4090*cdf0e10cSrcweir             aCurSize.Height() = aSize.Height();
4091*cdf0e10cSrcweir             SetSizePixel( aCurSize );
4092*cdf0e10cSrcweir         }
4093*cdf0e10cSrcweir     }
4094*cdf0e10cSrcweir 
4095*cdf0e10cSrcweir     Pop();
4096*cdf0e10cSrcweir }
4097*cdf0e10cSrcweir 
4098*cdf0e10cSrcweir // -----------------------------------------------------------------------
4099*cdf0e10cSrcweir 
4100*cdf0e10cSrcweir Size CheckBox::CalcMinimumSize( long nMaxWidth ) const
4101*cdf0e10cSrcweir {
4102*cdf0e10cSrcweir     Size aSize = ImplGetCheckImageSize();
4103*cdf0e10cSrcweir     nMaxWidth -= aSize.Width();
4104*cdf0e10cSrcweir 
4105*cdf0e10cSrcweir     XubString aText = GetText();
4106*cdf0e10cSrcweir     if ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
4107*cdf0e10cSrcweir     {
4108*cdf0e10cSrcweir         // subtract what will be added later
4109*cdf0e10cSrcweir         nMaxWidth-=2;
4110*cdf0e10cSrcweir         nMaxWidth -= ImplGetImageToTextDistance();
4111*cdf0e10cSrcweir 
4112*cdf0e10cSrcweir         Size aTextSize = GetTextRect( Rectangle( Point(), Size( nMaxWidth > 0 ? nMaxWidth : 0x7fffffff, 0x7fffffff ) ),
4113*cdf0e10cSrcweir                                       aText, FixedText::ImplGetTextStyle( GetStyle() ) ).GetSize();
4114*cdf0e10cSrcweir         aSize.Width()+=2;    // for focus rect
4115*cdf0e10cSrcweir         aSize.Width() += ImplGetImageToTextDistance();
4116*cdf0e10cSrcweir         aSize.Width() += aTextSize.Width();
4117*cdf0e10cSrcweir         if ( aSize.Height() < aTextSize.Height() )
4118*cdf0e10cSrcweir             aSize.Height() = aTextSize.Height();
4119*cdf0e10cSrcweir     }
4120*cdf0e10cSrcweir     else
4121*cdf0e10cSrcweir     {
4122*cdf0e10cSrcweir         // is this still correct ? since the checkbox now
4123*cdf0e10cSrcweir         // shows a focus rect it should be 2 pixels wider and longer
4124*cdf0e10cSrcweir /* da ansonsten im Writer die Control zu weit oben haengen
4125*cdf0e10cSrcweir         aSize.Width() += 2;
4126*cdf0e10cSrcweir         aSize.Height() += 2;
4127*cdf0e10cSrcweir */
4128*cdf0e10cSrcweir     }
4129*cdf0e10cSrcweir 
4130*cdf0e10cSrcweir     return CalcWindowSize( aSize );
4131*cdf0e10cSrcweir }
4132*cdf0e10cSrcweir 
4133*cdf0e10cSrcweir // -----------------------------------------------------------------------
4134*cdf0e10cSrcweir 
4135*cdf0e10cSrcweir Size CheckBox::GetOptimalSize(WindowSizeType eType) const
4136*cdf0e10cSrcweir {
4137*cdf0e10cSrcweir     switch (eType) {
4138*cdf0e10cSrcweir     case WINDOWSIZE_MINIMUM:
4139*cdf0e10cSrcweir         return CalcMinimumSize();
4140*cdf0e10cSrcweir     default:
4141*cdf0e10cSrcweir         return Button::GetOptimalSize( eType );
4142*cdf0e10cSrcweir     }
4143*cdf0e10cSrcweir }
4144*cdf0e10cSrcweir 
4145*cdf0e10cSrcweir // =======================================================================
4146*cdf0e10cSrcweir 
4147*cdf0e10cSrcweir ImageButton::ImageButton( WindowType nType ) :
4148*cdf0e10cSrcweir     PushButton( nType )
4149*cdf0e10cSrcweir {
4150*cdf0e10cSrcweir     ImplInitStyle();
4151*cdf0e10cSrcweir }
4152*cdf0e10cSrcweir 
4153*cdf0e10cSrcweir // -----------------------------------------------------------------------
4154*cdf0e10cSrcweir 
4155*cdf0e10cSrcweir ImageButton::ImageButton( Window* pParent, WinBits nStyle ) :
4156*cdf0e10cSrcweir     PushButton( pParent, nStyle )
4157*cdf0e10cSrcweir {
4158*cdf0e10cSrcweir     ImplInitStyle();
4159*cdf0e10cSrcweir }
4160*cdf0e10cSrcweir 
4161*cdf0e10cSrcweir // -----------------------------------------------------------------------
4162*cdf0e10cSrcweir 
4163*cdf0e10cSrcweir ImageButton::ImageButton( Window* pParent, const ResId& rResId ) :
4164*cdf0e10cSrcweir     PushButton( pParent, rResId.SetRT( RSC_IMAGEBUTTON ) )
4165*cdf0e10cSrcweir {
4166*cdf0e10cSrcweir     sal_uLong nObjMask = ReadLongRes();
4167*cdf0e10cSrcweir 
4168*cdf0e10cSrcweir     if ( RSC_IMAGEBUTTON_IMAGE & nObjMask )
4169*cdf0e10cSrcweir     {
4170*cdf0e10cSrcweir         SetModeImage( Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) ) );
4171*cdf0e10cSrcweir         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
4172*cdf0e10cSrcweir     }
4173*cdf0e10cSrcweir 
4174*cdf0e10cSrcweir     if ( RSC_IMAGEBUTTON_SYMBOL & nObjMask )
4175*cdf0e10cSrcweir         SetSymbol( (SymbolType)ReadLongRes() );
4176*cdf0e10cSrcweir 
4177*cdf0e10cSrcweir     if ( RSC_IMAGEBUTTON_STATE & nObjMask )
4178*cdf0e10cSrcweir         SetState( (TriState)ReadLongRes() );
4179*cdf0e10cSrcweir 
4180*cdf0e10cSrcweir     ImplInitStyle();
4181*cdf0e10cSrcweir }
4182*cdf0e10cSrcweir 
4183*cdf0e10cSrcweir // -----------------------------------------------------------------------
4184*cdf0e10cSrcweir 
4185*cdf0e10cSrcweir ImageButton::~ImageButton()
4186*cdf0e10cSrcweir {
4187*cdf0e10cSrcweir }
4188*cdf0e10cSrcweir 
4189*cdf0e10cSrcweir // -----------------------------------------------------------------------
4190*cdf0e10cSrcweir void ImageButton::ImplInitStyle()
4191*cdf0e10cSrcweir {
4192*cdf0e10cSrcweir     WinBits nStyle = GetStyle();
4193*cdf0e10cSrcweir 
4194*cdf0e10cSrcweir     if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
4195*cdf0e10cSrcweir         nStyle |= WB_CENTER;
4196*cdf0e10cSrcweir 
4197*cdf0e10cSrcweir     if ( ! ( nStyle & ( WB_TOP | WB_BOTTOM ) ) )
4198*cdf0e10cSrcweir         nStyle |= WB_VCENTER;
4199*cdf0e10cSrcweir 
4200*cdf0e10cSrcweir     SetStyle( nStyle );
4201*cdf0e10cSrcweir }
4202*cdf0e10cSrcweir 
4203*cdf0e10cSrcweir // =======================================================================
4204*cdf0e10cSrcweir 
4205*cdf0e10cSrcweir ImageRadioButton::ImageRadioButton( Window* pParent, WinBits nStyle ) :
4206*cdf0e10cSrcweir     RadioButton( pParent, nStyle )
4207*cdf0e10cSrcweir {
4208*cdf0e10cSrcweir }
4209*cdf0e10cSrcweir 
4210*cdf0e10cSrcweir // -----------------------------------------------------------------------
4211*cdf0e10cSrcweir 
4212*cdf0e10cSrcweir ImageRadioButton::ImageRadioButton( Window* pParent, const ResId& rResId ) :
4213*cdf0e10cSrcweir     RadioButton( pParent, rResId.SetRT( RSC_IMAGERADIOBUTTON ) )
4214*cdf0e10cSrcweir {
4215*cdf0e10cSrcweir     sal_uLong nObjMask = ReadLongRes();
4216*cdf0e10cSrcweir 
4217*cdf0e10cSrcweir     if ( RSC_IMAGERADIOBUTTON_IMAGE & nObjMask )
4218*cdf0e10cSrcweir     {
4219*cdf0e10cSrcweir         SetModeRadioImage( Image( ResId( (RSHEADER_TYPE*)GetClassRes(), *rResId.GetResMgr() ) ) );
4220*cdf0e10cSrcweir         IncrementRes( GetObjSizeRes( (RSHEADER_TYPE*)GetClassRes() ) );
4221*cdf0e10cSrcweir     }
4222*cdf0e10cSrcweir }
4223*cdf0e10cSrcweir 
4224*cdf0e10cSrcweir // -----------------------------------------------------------------------
4225*cdf0e10cSrcweir 
4226*cdf0e10cSrcweir ImageRadioButton::~ImageRadioButton()
4227*cdf0e10cSrcweir {
4228*cdf0e10cSrcweir }
4229*cdf0e10cSrcweir 
4230*cdf0e10cSrcweir // =======================================================================
4231*cdf0e10cSrcweir 
4232*cdf0e10cSrcweir TriStateBox::TriStateBox( Window* pParent, WinBits nStyle ) :
4233*cdf0e10cSrcweir     CheckBox( pParent, nStyle )
4234*cdf0e10cSrcweir {
4235*cdf0e10cSrcweir     EnableTriState( sal_True );
4236*cdf0e10cSrcweir }
4237*cdf0e10cSrcweir 
4238*cdf0e10cSrcweir // -----------------------------------------------------------------------
4239*cdf0e10cSrcweir 
4240*cdf0e10cSrcweir TriStateBox::TriStateBox( Window* pParent, const ResId& rResId ) :
4241*cdf0e10cSrcweir     CheckBox( pParent, rResId.SetRT( RSC_TRISTATEBOX ) )
4242*cdf0e10cSrcweir {
4243*cdf0e10cSrcweir     EnableTriState( sal_True );
4244*cdf0e10cSrcweir 
4245*cdf0e10cSrcweir     sal_uLong  nTriState        = ReadLongRes();
4246*cdf0e10cSrcweir     sal_uInt16 bDisableTriState = ReadShortRes();
4247*cdf0e10cSrcweir     //anderer Wert als Default ?
4248*cdf0e10cSrcweir     if ( (TriState)nTriState != STATE_NOCHECK )
4249*cdf0e10cSrcweir         SetState( (TriState)nTriState );
4250*cdf0e10cSrcweir     if ( bDisableTriState )
4251*cdf0e10cSrcweir         EnableTriState( sal_False );
4252*cdf0e10cSrcweir }
4253*cdf0e10cSrcweir 
4254*cdf0e10cSrcweir // -----------------------------------------------------------------------
4255*cdf0e10cSrcweir 
4256*cdf0e10cSrcweir TriStateBox::~TriStateBox()
4257*cdf0e10cSrcweir {
4258*cdf0e10cSrcweir }
4259*cdf0e10cSrcweir 
4260*cdf0e10cSrcweir // =======================================================================
4261*cdf0e10cSrcweir 
4262*cdf0e10cSrcweir DisclosureButton::DisclosureButton( Window* pParent, WinBits ) :
4263*cdf0e10cSrcweir     CheckBox( pParent, WB_NOBORDER )
4264*cdf0e10cSrcweir {
4265*cdf0e10cSrcweir }
4266*cdf0e10cSrcweir 
4267*cdf0e10cSrcweir // -----------------------------------------------------------------------
4268*cdf0e10cSrcweir 
4269*cdf0e10cSrcweir DisclosureButton::DisclosureButton( Window* pParent, const ResId& rResId ) :
4270*cdf0e10cSrcweir     CheckBox( pParent, rResId.SetRT( RSC_CHECKBOX ) )
4271*cdf0e10cSrcweir {
4272*cdf0e10cSrcweir }
4273*cdf0e10cSrcweir 
4274*cdf0e10cSrcweir // -----------------------------------------------------------------------
4275*cdf0e10cSrcweir 
4276*cdf0e10cSrcweir void DisclosureButton::ImplDrawCheckBoxState()
4277*cdf0e10cSrcweir {
4278*cdf0e10cSrcweir     /* HACK: DisclosureButton is currently assuming, that the disclosure sign
4279*cdf0e10cSrcweir        will fit into the rectangle occupied by a normal checkbox on all themes.
4280*cdf0e10cSrcweir        If this does not hold true for some theme, ImplGetCheckImageSize
4281*cdf0e10cSrcweir        would have to be overloaded for DisclosureButton; also GetNativeControlRegion
4282*cdf0e10cSrcweir        for CTRL_LISTNODE would have to be implemented and taken into account
4283*cdf0e10cSrcweir     */
4284*cdf0e10cSrcweir 
4285*cdf0e10cSrcweir     Rectangle aStateRect( GetStateRect() );
4286*cdf0e10cSrcweir 
4287*cdf0e10cSrcweir     ImplControlValue    aControlValue( GetState() == STATE_CHECK ? BUTTONVALUE_ON : BUTTONVALUE_OFF );
4288*cdf0e10cSrcweir     Rectangle           aCtrlRegion( aStateRect );
4289*cdf0e10cSrcweir     ControlState        nState = 0;
4290*cdf0e10cSrcweir 
4291*cdf0e10cSrcweir     if ( HasFocus() )						nState |= CTRL_STATE_FOCUSED;
4292*cdf0e10cSrcweir     if ( ImplGetButtonState() & BUTTON_DRAW_DEFAULT )	nState |= CTRL_STATE_DEFAULT;
4293*cdf0e10cSrcweir     if ( Window::IsEnabled() ) 				nState |= CTRL_STATE_ENABLED;
4294*cdf0e10cSrcweir     if ( IsMouseOver() && GetMouseRect().IsInside( GetPointerPosPixel() ) )
4295*cdf0e10cSrcweir         nState |= CTRL_STATE_ROLLOVER;
4296*cdf0e10cSrcweir 
4297*cdf0e10cSrcweir     if( ! DrawNativeControl( CTRL_LISTNODE, PART_ENTIRE_CONTROL, aCtrlRegion, nState,
4298*cdf0e10cSrcweir                            aControlValue, rtl::OUString() ) )
4299*cdf0e10cSrcweir     {
4300*cdf0e10cSrcweir         ImplSVCtrlData& rCtrlData( ImplGetSVData()->maCtrlData );
4301*cdf0e10cSrcweir         if( ! rCtrlData.mpDisclosurePlus )
4302*cdf0e10cSrcweir             rCtrlData.mpDisclosurePlus = new Image( BitmapEx( VclResId( SV_DISCLOSURE_PLUS ) ) );
4303*cdf0e10cSrcweir         if( ! rCtrlData.mpDisclosurePlusHC )
4304*cdf0e10cSrcweir             rCtrlData.mpDisclosurePlusHC = new Image( BitmapEx( VclResId( SV_DISCLOSURE_PLUS_HC ) ) );
4305*cdf0e10cSrcweir         if( ! rCtrlData.mpDisclosureMinus )
4306*cdf0e10cSrcweir             rCtrlData.mpDisclosureMinus = new Image( BitmapEx( VclResId( SV_DISCLOSURE_MINUS ) ) );
4307*cdf0e10cSrcweir         if( ! rCtrlData.mpDisclosureMinusHC )
4308*cdf0e10cSrcweir             rCtrlData.mpDisclosureMinusHC = new Image( BitmapEx( VclResId( SV_DISCLOSURE_MINUS_HC ) ) );
4309*cdf0e10cSrcweir 
4310*cdf0e10cSrcweir         Image* pImg = NULL;
4311*cdf0e10cSrcweir         if( GetSettings().GetStyleSettings().GetHighContrastMode() )
4312*cdf0e10cSrcweir             pImg = IsChecked() ? rCtrlData.mpDisclosureMinusHC : rCtrlData.mpDisclosurePlusHC;
4313*cdf0e10cSrcweir         else
4314*cdf0e10cSrcweir             pImg = IsChecked() ? rCtrlData.mpDisclosureMinus : rCtrlData.mpDisclosurePlus;
4315*cdf0e10cSrcweir 
4316*cdf0e10cSrcweir         DBG_ASSERT( pImg, "no disclosure image" );
4317*cdf0e10cSrcweir         if( ! pImg )
4318*cdf0e10cSrcweir             return;
4319*cdf0e10cSrcweir 
4320*cdf0e10cSrcweir         sal_uInt16 nStyle = 0;
4321*cdf0e10cSrcweir         if( ! IsEnabled() )
4322*cdf0e10cSrcweir             nStyle |= IMAGE_DRAW_DISABLE;
4323*cdf0e10cSrcweir 
4324*cdf0e10cSrcweir         Size aSize( aStateRect.GetSize() );
4325*cdf0e10cSrcweir         Size aImgSize( pImg->GetSizePixel() );
4326*cdf0e10cSrcweir         Point aOff( (aSize.Width() - aImgSize.Width())/2,
4327*cdf0e10cSrcweir                     (aSize.Height() - aImgSize.Height())/2 );
4328*cdf0e10cSrcweir         aOff += aStateRect.TopLeft();
4329*cdf0e10cSrcweir         DrawImage( aOff, *pImg, nStyle );
4330*cdf0e10cSrcweir     }
4331*cdf0e10cSrcweir }
4332*cdf0e10cSrcweir 
4333*cdf0e10cSrcweir // -----------------------------------------------------------------------
4334*cdf0e10cSrcweir 
4335*cdf0e10cSrcweir void DisclosureButton::KeyInput( const KeyEvent& rKEvt )
4336*cdf0e10cSrcweir {
4337*cdf0e10cSrcweir     KeyCode aKeyCode = rKEvt.GetKeyCode();
4338*cdf0e10cSrcweir 
4339*cdf0e10cSrcweir     if( !aKeyCode.GetModifier()  &&
4340*cdf0e10cSrcweir         ( ( aKeyCode.GetCode() == KEY_ADD ) ||
4341*cdf0e10cSrcweir           ( aKeyCode.GetCode() == KEY_SUBTRACT ) )
4342*cdf0e10cSrcweir         )
4343*cdf0e10cSrcweir     {
4344*cdf0e10cSrcweir         Check( aKeyCode.GetCode() == KEY_ADD );
4345*cdf0e10cSrcweir     }
4346*cdf0e10cSrcweir     else
4347*cdf0e10cSrcweir         Button::KeyInput( rKEvt );
4348*cdf0e10cSrcweir }
4349*cdf0e10cSrcweir 
4350*cdf0e10cSrcweir 
4351