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