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