1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "wrapper.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/awt/XActionListener.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/awt/XButton.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/awt/XCheckBox.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/awt/XRadioButton.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp>
36*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
37*cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
38*cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx>
39*cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
40*cdf0e10cSrcweir #include <vcl/button.hxx>
41*cdf0e10cSrcweir #include <vcl/event.hxx>
42*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir #include <vcl/window.hxx>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #include <list>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <layout/core/helper.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace ::com::sun::star;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using rtl::OUString;
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir namespace layout
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir class ImageImpl
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir   public:
60*cdf0e10cSrcweir     uno::Reference< graphic::XGraphic > mxGraphic;
61*cdf0e10cSrcweir     ImageImpl( const char *pName )
62*cdf0e10cSrcweir         : mxGraphic( layoutimpl::loadGraphic( pName ) )
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         if ( !mxGraphic.is() )
65*cdf0e10cSrcweir         {
66*cdf0e10cSrcweir             DBG_ERROR1( "ERROR: failed to load image: `%s'\n", pName );
67*cdf0e10cSrcweir         }
68*cdf0e10cSrcweir     }
69*cdf0e10cSrcweir };
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir Image::Image( const char *pName )
72*cdf0e10cSrcweir     : pImpl( new ImageImpl( pName ) )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir Image::~Image()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     delete pImpl;
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir class ButtonImpl : public ControlImpl
82*cdf0e10cSrcweir                  , public ::cppu::WeakImplHelper1< awt::XActionListener >
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir     Link maClickHdl;
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir public:
87*cdf0e10cSrcweir     uno::Reference< awt::XButton > mxButton;
88*cdf0e10cSrcweir     ButtonImpl( Context *context, const PeerHandle &peer, Window *window )
89*cdf0e10cSrcweir         : ControlImpl( context, peer, window )
90*cdf0e10cSrcweir         , mxButton( peer, uno::UNO_QUERY )
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         /* We have default action when clicked, always listen. */
93*cdf0e10cSrcweir         mxButton->addActionListener( this );
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     ~ButtonImpl()
97*cdf0e10cSrcweir     {
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     virtual void Click() { /* make me pure virtual? */ };
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     Link& GetClickHdl ()
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         return maClickHdl;
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     virtual void SetClickHdl( Link const& link )
108*cdf0e10cSrcweir     {
109*cdf0e10cSrcweir         maClickHdl = link;
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     void SAL_CALL disposing( lang::EventObject const& e )
113*cdf0e10cSrcweir         throw (uno::RuntimeException)
114*cdf0e10cSrcweir     {
115*cdf0e10cSrcweir         mxButton->removeActionListener( this );
116*cdf0e10cSrcweir         ControlImpl::disposing (e);
117*cdf0e10cSrcweir         mxButton.clear ();
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     virtual void SAL_CALL actionPerformed( const awt::ActionEvent& )
121*cdf0e10cSrcweir         throw (uno::RuntimeException)
122*cdf0e10cSrcweir     {
123*cdf0e10cSrcweir         if ( !maClickHdl )
124*cdf0e10cSrcweir             Click();
125*cdf0e10cSrcweir         else
126*cdf0e10cSrcweir             maClickHdl.Call( static_cast<Window *>( mpWindow ) );
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     bool SetModeImage( uno::Reference< graphic::XGraphic > xGraph )
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         setProperty( "Graphic", uno::Any( xGraph ) );
132*cdf0e10cSrcweir         return true;
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir };
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir Button::~Button ()
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir String Button::GetStandardText (sal_uInt16 button_type)
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     return ::Button::GetStandardText (button_type);
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir void Button::SetText( OUString const& rStr )
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     if ( !getImpl().mxButton.is() )
148*cdf0e10cSrcweir         return;
149*cdf0e10cSrcweir     getImpl().mxButton->setLabel( rStr );
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir void Button::SetClickHdl( const Link& link )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     if (&getImpl () && getImpl().mxButton.is ())
155*cdf0e10cSrcweir         getImpl().SetClickHdl( link );
156*cdf0e10cSrcweir }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir Link& Button::GetClickHdl ()
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     return getImpl().GetClickHdl ();
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir bool Button::SetModeImage (Image const& image)
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     return getImpl().SetModeImage (image.getImpl().mxGraphic);
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir bool Button::SetModeImage (::Image const& image, BmpColorMode mode)
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     return GetButton ()->SetModeImage (image, mode);
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir void Button::SetImageAlign( ImageAlign eAlign )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir     getImpl().setProperty( "ImageAlign", uno::Any( (sal_Int16) eAlign ) );
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir void Button::Click()
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir IMPL_GET_IMPL( Button );
183*cdf0e10cSrcweir IMPL_CONSTRUCTORS( Button, Control, "button" );
184*cdf0e10cSrcweir IMPL_GET_WINDOW (Button);
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir class PushButtonImpl : public ButtonImpl
187*cdf0e10cSrcweir                  , public ::cppu::WeakImplHelper1< awt::XItemListener >
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     Link maToggleHdl;
190*cdf0e10cSrcweir public:
191*cdf0e10cSrcweir     PushButtonImpl( Context *context, const PeerHandle &peer, Window *window )
192*cdf0e10cSrcweir         : ButtonImpl( context, peer, window )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     void SetToggleHdl( const Link& link )
197*cdf0e10cSrcweir     {
198*cdf0e10cSrcweir         // XButton doesn't have an explicit event for Toggle. Anyway, it is a
199*cdf0e10cSrcweir         // superset of the clicks: all clicks, and explicit toggles
200*cdf0e10cSrcweir         if (!link && !!maToggleHdl)
201*cdf0e10cSrcweir             mxButton->removeActionListener( this );
202*cdf0e10cSrcweir         else if (!!link && !maToggleHdl)
203*cdf0e10cSrcweir             mxButton->addActionListener( this );
204*cdf0e10cSrcweir         maToggleHdl = link;
205*cdf0e10cSrcweir     }
206*cdf0e10cSrcweir     void SAL_CALL disposing( lang::EventObject const& e )
207*cdf0e10cSrcweir         throw (uno::RuntimeException)
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         ButtonImpl::disposing (e);
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir     virtual void SAL_CALL actionPerformed( awt::ActionEvent const& e )
212*cdf0e10cSrcweir         throw (uno::RuntimeException)
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         ButtonImpl::actionPerformed( e );
215*cdf0e10cSrcweir         fireToggle();
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir     virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& )
218*cdf0e10cSrcweir         throw (uno::RuntimeException)
219*cdf0e10cSrcweir     {
220*cdf0e10cSrcweir         maToggleHdl.Call( static_cast<Window *>( mpWindow ) );
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir     void fireToggle()
223*cdf0e10cSrcweir     {
224*cdf0e10cSrcweir         maToggleHdl.Call(  static_cast<Window *>( mpWindow ) );
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir };
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir PushButton::~PushButton ()
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     SetToggleHdl (Link ());
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void PushButton::Check( bool bCheck )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     getImpl().setProperty( "State", uno::Any( (sal_Int16) !!bCheck ) );
237*cdf0e10cSrcweir     // XButton doesn't have explicit toggle event
238*cdf0e10cSrcweir     getImpl().fireToggle();
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir bool PushButton::IsChecked() const
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     return !!( getImpl().getProperty( "State" ).get< sal_Int16 >() );
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void PushButton::Toggle()
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir     Check( true );
249*cdf0e10cSrcweir }
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir void PushButton::SetToggleHdl( const Link& link )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     if (&getImpl () && getImpl().mxButton.is ())
254*cdf0e10cSrcweir         getImpl().SetToggleHdl( link );
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir IMPL_GET_IMPL( PushButton );
258*cdf0e10cSrcweir IMPL_CONSTRUCTORS( PushButton, Button, "pushbutton" );
259*cdf0e10cSrcweir IMPL_GET_WINDOW (PushButton);
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir class RadioButtonImpl : public ButtonImpl
262*cdf0e10cSrcweir                       , public ::cppu::WeakImplHelper1< awt::XItemListener >
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir     Link maToggleHdl;
265*cdf0e10cSrcweir public:
266*cdf0e10cSrcweir     uno::Reference< awt::XRadioButton > mxRadioButton;
267*cdf0e10cSrcweir     RadioButtonImpl( Context *context, const PeerHandle &peer, Window *window )
268*cdf0e10cSrcweir         : ButtonImpl( context, peer, window )
269*cdf0e10cSrcweir         , mxRadioButton( peer, uno::UNO_QUERY )
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir     }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     void Check( bool bCheck )
274*cdf0e10cSrcweir     {
275*cdf0e10cSrcweir         if ( !mxRadioButton.is() )
276*cdf0e10cSrcweir             return;
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir #if 1
279*cdf0e10cSrcweir         // Have setState fire item event for
280*cdf0e10cSrcweir         // RadioGroups::RadioGroup::itemStateChanged ()
281*cdf0e10cSrcweir         ::RadioButton *r = static_cast<RadioButton*>(mpWindow)->GetRadioButton ();
282*cdf0e10cSrcweir         bool state = r->IsRadioCheckEnabled ();
283*cdf0e10cSrcweir         r->EnableRadioCheck();
284*cdf0e10cSrcweir         mxRadioButton->setState( !!bCheck );
285*cdf0e10cSrcweir         r->EnableRadioCheck (state);
286*cdf0e10cSrcweir #else
287*cdf0e10cSrcweir         mxRadioButton->setState( !!bCheck );
288*cdf0e10cSrcweir #endif
289*cdf0e10cSrcweir         fireToggle();
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir     bool IsChecked()
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         if ( !mxRadioButton.is() )
295*cdf0e10cSrcweir             return false;
296*cdf0e10cSrcweir         return mxRadioButton->getState();
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     void SetToggleHdl( const Link& link )
300*cdf0e10cSrcweir     {
301*cdf0e10cSrcweir         if (!link && !!maToggleHdl)
302*cdf0e10cSrcweir             mxRadioButton->removeItemListener( this );
303*cdf0e10cSrcweir         else if (!!link && !maToggleHdl)
304*cdf0e10cSrcweir             mxRadioButton->addItemListener( this );
305*cdf0e10cSrcweir         maToggleHdl = link;
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     inline void fireToggle()
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         maToggleHdl.Call(  static_cast<Window *>( mpWindow ) );
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     virtual void SetClickHdl( const Link& link )
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         // Keep RadioGroups::RadioGroup's actionListener at HEAD
316*cdf0e10cSrcweir         // of list.  This way, it can handle RadioGroup's button
317*cdf0e10cSrcweir         // states before all other callbacks and make sure the
318*cdf0e10cSrcweir         // client code has the right state.
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir         // IWBN to add an XRadioButton2 and layout::VCLXRadioButton
321*cdf0e10cSrcweir         // with {get,set}RadioGroup() (and a "radiogroup" property
322*cdf0e10cSrcweir         // even) and handle the grouping here in RadioButtonImpl.
323*cdf0e10cSrcweir         uno::Reference< uno::XInterface > x = static_cast<VCLXRadioButton*> (mpWindow->GetVCLXWindow ())->getFirstActionListener ();
324*cdf0e10cSrcweir         uno::Reference< awt::XActionListener > a = uno::Reference< awt::XActionListener> (x ,uno::UNO_QUERY );
325*cdf0e10cSrcweir         mxButton->removeActionListener (a);
326*cdf0e10cSrcweir         ButtonImpl::SetClickHdl (link);
327*cdf0e10cSrcweir         mxButton->addActionListener (a);
328*cdf0e10cSrcweir     }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     void SAL_CALL disposing( lang::EventObject const& e )
331*cdf0e10cSrcweir         throw (uno::RuntimeException)
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         ButtonImpl::disposing (e);
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& )
337*cdf0e10cSrcweir         throw (uno::RuntimeException)
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         maToggleHdl.Call( static_cast<Window *>( mpWindow ) );
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir };
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir RadioButton::~RadioButton ()
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir     SetToggleHdl (Link ());
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir void RadioButton::Check( bool bCheck )
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     getImpl().Check( bCheck );
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir bool RadioButton::IsChecked() const
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir     return getImpl().IsChecked();
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir void RadioButton::SetToggleHdl( const Link& link )
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir     if (&getImpl () && getImpl().mxRadioButton.is ())
361*cdf0e10cSrcweir         getImpl().SetToggleHdl( link );
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir IMPL_GET_IMPL( RadioButton );
365*cdf0e10cSrcweir IMPL_GET_WINDOW( RadioButton );
366*cdf0e10cSrcweir IMPL_GET_VCLXWINDOW( RadioButton );
367*cdf0e10cSrcweir IMPL_CONSTRUCTORS( RadioButton, Button, "radiobutton" );
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir class CheckBoxImpl : public ButtonImpl
370*cdf0e10cSrcweir                  , public ::cppu::WeakImplHelper1< awt::XItemListener >
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir     Link maToggleHdl;
373*cdf0e10cSrcweir   public:
374*cdf0e10cSrcweir     uno::Reference< awt::XCheckBox > mxCheckBox;
375*cdf0e10cSrcweir     CheckBoxImpl( Context *context, const PeerHandle &peer, Window *window )
376*cdf0e10cSrcweir         : ButtonImpl( context, peer, window )
377*cdf0e10cSrcweir         , mxCheckBox( peer, uno::UNO_QUERY )
378*cdf0e10cSrcweir     {
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir     void SetToggleHdl( const Link& link )
382*cdf0e10cSrcweir     {
383*cdf0e10cSrcweir         if (!link && !!maToggleHdl)
384*cdf0e10cSrcweir             mxCheckBox->removeItemListener( this );
385*cdf0e10cSrcweir         else if (!!link && !maToggleHdl)
386*cdf0e10cSrcweir             mxCheckBox->addItemListener( this );
387*cdf0e10cSrcweir         maToggleHdl = link;
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir     void SAL_CALL disposing( lang::EventObject const& e )
390*cdf0e10cSrcweir         throw (uno::RuntimeException)
391*cdf0e10cSrcweir     {
392*cdf0e10cSrcweir         ButtonImpl::disposing (e);
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir     virtual void SAL_CALL itemStateChanged( const awt::ItemEvent& )
395*cdf0e10cSrcweir         throw (uno::RuntimeException)
396*cdf0e10cSrcweir     {
397*cdf0e10cSrcweir         maToggleHdl.Call( static_cast<Window *>( mpWindow ) );
398*cdf0e10cSrcweir     }
399*cdf0e10cSrcweir };
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir CheckBox::~CheckBox ()
402*cdf0e10cSrcweir {
403*cdf0e10cSrcweir     SetToggleHdl (Link ());
404*cdf0e10cSrcweir }
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir void CheckBox::Check( bool bCheck )
407*cdf0e10cSrcweir {
408*cdf0e10cSrcweir     if ( !getImpl().mxCheckBox.is() )
409*cdf0e10cSrcweir         return;
410*cdf0e10cSrcweir     getImpl().mxCheckBox->setState( !!bCheck );
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir bool CheckBox::IsChecked() const
414*cdf0e10cSrcweir {
415*cdf0e10cSrcweir     if ( !getImpl().mxCheckBox.is() )
416*cdf0e10cSrcweir         return false;
417*cdf0e10cSrcweir     return getImpl().mxCheckBox->getState() != 0;
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir void CheckBox::SetToggleHdl( const Link& link )
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir     if (&getImpl () && getImpl().mxCheckBox.is ())
423*cdf0e10cSrcweir         getImpl().SetToggleHdl( link );
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir IMPL_GET_IMPL( CheckBox );
427*cdf0e10cSrcweir IMPL_CONSTRUCTORS( CheckBox, Button, "checkbox" );
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir #define BUTTON_IMPL(t, parent, response) \
430*cdf0e10cSrcweir     class t##Impl : public parent##Impl \
431*cdf0e10cSrcweir     { \
432*cdf0e10cSrcweir     public: \
433*cdf0e10cSrcweir         t##Impl( Context *context, PeerHandle const& peer, Window *window ) \
434*cdf0e10cSrcweir             : parent##Impl( context, peer, window ) \
435*cdf0e10cSrcweir         { \
436*cdf0e10cSrcweir         } \
437*cdf0e10cSrcweir         void Click() \
438*cdf0e10cSrcweir         { \
439*cdf0e10cSrcweir             if (Dialog *d = static_cast<Dialog *> (mpCtx)) \
440*cdf0e10cSrcweir                 d->EndDialog( response ); \
441*cdf0e10cSrcweir         } \
442*cdf0e10cSrcweir     }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir /* Common button types currently unavailable in OOo: */
445*cdf0e10cSrcweir /* mpReset */
446*cdf0e10cSrcweir /* mpApply */
447*cdf0e10cSrcweir /* mpAction */
448*cdf0e10cSrcweir #define RET_RESET 6
449*cdf0e10cSrcweir #define RET_APPLY 7
450*cdf0e10cSrcweir #define BUTTONID_RESET RET_RESET
451*cdf0e10cSrcweir #define BUTTONID_APPLY RET_APPLY
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir BUTTON_IMPL( OKButton, PushButton, BUTTONID_OK );
454*cdf0e10cSrcweir BUTTON_IMPL( CancelButton, PushButton, BUTTONID_CANCEL );
455*cdf0e10cSrcweir BUTTON_IMPL( YesButton, PushButton, BUTTONID_YES );
456*cdf0e10cSrcweir BUTTON_IMPL( NoButton, PushButton, BUTTONID_NO );
457*cdf0e10cSrcweir BUTTON_IMPL( RetryButton, PushButton, BUTTONID_RETRY );
458*cdf0e10cSrcweir BUTTON_IMPL( IgnoreButton, PushButton, BUTTONID_IGNORE );
459*cdf0e10cSrcweir BUTTON_IMPL( ResetButton, PushButton, BUTTONID_RESET );
460*cdf0e10cSrcweir BUTTON_IMPL( ApplyButton, PushButton, BUTTONID_APPLY ); /* Deprecated? */
461*cdf0e10cSrcweir BUTTON_IMPL( HelpButton, PushButton, BUTTONID_HELP );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir IMPL_CONSTRUCTORS( OKButton, PushButton, "okbutton" );
464*cdf0e10cSrcweir IMPL_CONSTRUCTORS( CancelButton, PushButton, "cancelbutton" );
465*cdf0e10cSrcweir IMPL_CONSTRUCTORS( YesButton, PushButton, "yesbutton" );
466*cdf0e10cSrcweir IMPL_CONSTRUCTORS( NoButton, PushButton, "nobutton" );
467*cdf0e10cSrcweir IMPL_CONSTRUCTORS( RetryButton, PushButton, "retrybutton" );
468*cdf0e10cSrcweir IMPL_CONSTRUCTORS( IgnoreButton, PushButton, "ignorebutton" );
469*cdf0e10cSrcweir IMPL_CONSTRUCTORS( ResetButton, PushButton, "resetbutton" );
470*cdf0e10cSrcweir IMPL_CONSTRUCTORS( ApplyButton, PushButton, "applybutton" );  /* Deprecated? */
471*cdf0e10cSrcweir IMPL_CONSTRUCTORS( HelpButton, PushButton, "helpbutton" );
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir IMPL_IMPL (ImageButton, PushButton)
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir IMPL_CONSTRUCTORS( ImageButton, PushButton, "imagebutton" );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir class AdvancedButtonImpl : public PushButtonImpl
479*cdf0e10cSrcweir {
480*cdf0e10cSrcweir protected:
481*cdf0e10cSrcweir     bool bAdvancedMode;
482*cdf0e10cSrcweir     std::list< Window*> maAdvanced;
483*cdf0e10cSrcweir     std::list< Window*> maSimple;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir public:
486*cdf0e10cSrcweir     rtl::OUString mAdvancedLabel;
487*cdf0e10cSrcweir     rtl::OUString mSimpleLabel;
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir protected:
490*cdf0e10cSrcweir     Window* Remove( std::list< Window*> lst, Window* w )
491*cdf0e10cSrcweir     {
492*cdf0e10cSrcweir         for ( std::list< Window*>::iterator it = maAdvanced.begin();
493*cdf0e10cSrcweir               it != maAdvanced.end(); it++ )
494*cdf0e10cSrcweir             if ( *it == w )
495*cdf0e10cSrcweir             {
496*cdf0e10cSrcweir                 lst.erase( it );
497*cdf0e10cSrcweir                 return *it;
498*cdf0e10cSrcweir             }
499*cdf0e10cSrcweir         return 0;
500*cdf0e10cSrcweir     }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir public:
503*cdf0e10cSrcweir     AdvancedButtonImpl( Context *context, PeerHandle const& peer, Window *window )
504*cdf0e10cSrcweir         : PushButtonImpl( context, peer, window )
505*cdf0e10cSrcweir         , bAdvancedMode( false )
506*cdf0e10cSrcweir           // TODO: i18n
507*cdf0e10cSrcweir           // Button::GetStandardText( BUTTON_ADVANCED );
508*cdf0e10cSrcweir           // Button::GetStandardText( BUTTON_SIMPLE );
509*cdf0e10cSrcweir         , mAdvancedLabel( rtl::OUString::createFromAscii( "Advanced..." ) )
510*cdf0e10cSrcweir         , mSimpleLabel( rtl::OUString::createFromAscii( "Simple..." ) )
511*cdf0e10cSrcweir     {
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir     void Click()
514*cdf0e10cSrcweir     {
515*cdf0e10cSrcweir         bAdvancedMode = !bAdvancedMode;
516*cdf0e10cSrcweir         if ( bAdvancedMode )
517*cdf0e10cSrcweir             advancedMode();
518*cdf0e10cSrcweir         else
519*cdf0e10cSrcweir             simpleMode();
520*cdf0e10cSrcweir     }
521*cdf0e10cSrcweir     void setAlign ()
522*cdf0e10cSrcweir     {
523*cdf0e10cSrcweir         ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton ();
524*cdf0e10cSrcweir         b->SetSymbolAlign (SYMBOLALIGN_RIGHT);
525*cdf0e10cSrcweir         b->SetSmallSymbol ();
526*cdf0e10cSrcweir         //mpWindow->SetStyle (mpWindow->GetStyle() | WB_CENTER);
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir     void advancedMode()
529*cdf0e10cSrcweir     {
530*cdf0e10cSrcweir         ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton ();
531*cdf0e10cSrcweir         b->SetSymbol (SYMBOL_PAGEUP);
532*cdf0e10cSrcweir         setAlign ();
533*cdf0e10cSrcweir         if (mSimpleLabel.getLength ())
534*cdf0e10cSrcweir             b->SetText (mSimpleLabel);
535*cdf0e10cSrcweir         for ( std::list< Window*>::iterator it = maAdvanced.begin();
536*cdf0e10cSrcweir               it != maAdvanced.end(); it++ )
537*cdf0e10cSrcweir             ( *it )->Show();
538*cdf0e10cSrcweir         for ( std::list< Window*>::iterator it = maSimple.begin();
539*cdf0e10cSrcweir               it != maSimple.end(); it++ )
540*cdf0e10cSrcweir             ( *it )->Hide();
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir         redraw ();
543*cdf0e10cSrcweir     }
544*cdf0e10cSrcweir     void simpleMode()
545*cdf0e10cSrcweir     {
546*cdf0e10cSrcweir         //mxButton->setLabel( mSimpleLabel );
547*cdf0e10cSrcweir         ::PushButton *b = static_cast<PushButton*> (mpWindow)->GetPushButton ();
548*cdf0e10cSrcweir         b->SetSymbol (SYMBOL_PAGEDOWN);
549*cdf0e10cSrcweir         if (mAdvancedLabel.getLength ())
550*cdf0e10cSrcweir             b->SetText (mAdvancedLabel);
551*cdf0e10cSrcweir         setAlign ();
552*cdf0e10cSrcweir         for ( std::list< Window*>::iterator it = maAdvanced.begin();
553*cdf0e10cSrcweir               it != maAdvanced.end(); it++ )
554*cdf0e10cSrcweir             ( *it )->Hide();
555*cdf0e10cSrcweir         for ( std::list< Window*>::iterator it = maSimple.begin();
556*cdf0e10cSrcweir               it != maSimple.end(); it++ )
557*cdf0e10cSrcweir             ( *it )->Show();
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir         redraw (true);
560*cdf0e10cSrcweir     }
561*cdf0e10cSrcweir     void AddAdvanced( Window* w )
562*cdf0e10cSrcweir     {
563*cdf0e10cSrcweir         maAdvanced.push_back( w );
564*cdf0e10cSrcweir         if ( !bAdvancedMode )
565*cdf0e10cSrcweir             w->Hide();
566*cdf0e10cSrcweir     }
567*cdf0e10cSrcweir     void AddSimple( Window* w )
568*cdf0e10cSrcweir     {
569*cdf0e10cSrcweir         maSimple.push_back( w );
570*cdf0e10cSrcweir         if ( bAdvancedMode )
571*cdf0e10cSrcweir             w->Hide();
572*cdf0e10cSrcweir     }
573*cdf0e10cSrcweir     void RemoveAdvanced( Window* w )
574*cdf0e10cSrcweir     {
575*cdf0e10cSrcweir         Remove( maAdvanced, w );
576*cdf0e10cSrcweir     }
577*cdf0e10cSrcweir     void RemoveSimple( Window* w )
578*cdf0e10cSrcweir     {
579*cdf0e10cSrcweir         Remove( maSimple, w );
580*cdf0e10cSrcweir     }
581*cdf0e10cSrcweir };
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir void AdvancedButton::AddAdvanced( Window* w )
584*cdf0e10cSrcweir {
585*cdf0e10cSrcweir     getImpl().AddAdvanced( w );
586*cdf0e10cSrcweir }
587*cdf0e10cSrcweir 
588*cdf0e10cSrcweir void AdvancedButton::AddSimple( Window* w )
589*cdf0e10cSrcweir {
590*cdf0e10cSrcweir     getImpl().AddSimple( w );
591*cdf0e10cSrcweir }
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir void AdvancedButton::RemoveAdvanced( Window* w )
594*cdf0e10cSrcweir {
595*cdf0e10cSrcweir     getImpl().RemoveAdvanced( w );
596*cdf0e10cSrcweir }
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir void AdvancedButton::RemoveSimple( Window* w )
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir     getImpl().RemoveSimple( w );
601*cdf0e10cSrcweir }
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir void AdvancedButton::SetAdvancedText (rtl::OUString const& text)
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir     if (text.getLength ())
606*cdf0e10cSrcweir         getImpl ().mAdvancedLabel = text;
607*cdf0e10cSrcweir }
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir void AdvancedButton::SetSimpleText (rtl::OUString const& text)
610*cdf0e10cSrcweir {
611*cdf0e10cSrcweir     if (text.getLength ())
612*cdf0e10cSrcweir         getImpl ().mSimpleLabel = text;
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir rtl::OUString AdvancedButton::GetAdvancedText () const
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     return getImpl ().mAdvancedLabel;
618*cdf0e10cSrcweir }
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir rtl::OUString AdvancedButton::GetSimpleText () const
621*cdf0e10cSrcweir {
622*cdf0e10cSrcweir     return getImpl ().mSimpleLabel;
623*cdf0e10cSrcweir }
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir void AdvancedButton::SetDelta (int)
626*cdf0e10cSrcweir {
627*cdf0e10cSrcweir }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir IMPL_CONSTRUCTORS_BODY( AdvancedButton, PushButton, "advancedbutton", getImpl().simpleMode () );
630*cdf0e10cSrcweir IMPL_GET_IMPL( AdvancedButton );
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir class MoreButtonImpl : public AdvancedButtonImpl
634*cdf0e10cSrcweir {
635*cdf0e10cSrcweir public:
636*cdf0e10cSrcweir     MoreButtonImpl( Context *context, PeerHandle const& peer, Window *window )
637*cdf0e10cSrcweir         : AdvancedButtonImpl( context, peer, window)
638*cdf0e10cSrcweir     {
639*cdf0e10cSrcweir         mSimpleLabel = Button::GetStandardText( BUTTON_MORE );
640*cdf0e10cSrcweir         mAdvancedLabel = Button::GetStandardText( BUTTON_LESS );
641*cdf0e10cSrcweir     }
642*cdf0e10cSrcweir     void AddWindow( Window* w ) { AddAdvanced( w ); }
643*cdf0e10cSrcweir     void RemoveWindow( Window* w ) { RemoveAdvanced( w ); }
644*cdf0e10cSrcweir };
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir // TODO
647*cdf0e10cSrcweir //BUTTON_IMPL( MoreButton, PushButton, 0 );
648*cdf0e10cSrcweir IMPL_CONSTRUCTORS_BODY( MoreButton, AdvancedButton, "morebutton", getImpl().simpleMode () );
649*cdf0e10cSrcweir IMPL_GET_IMPL( MoreButton );
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir void MoreButton::AddWindow( Window* w )
652*cdf0e10cSrcweir {
653*cdf0e10cSrcweir     getImpl().AddWindow( w );
654*cdf0e10cSrcweir }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir void MoreButton::RemoveWindow( Window* w )
657*cdf0e10cSrcweir {
658*cdf0e10cSrcweir     getImpl().RemoveWindow( w );
659*cdf0e10cSrcweir }
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir void MoreButton::SetMoreText (rtl::OUString const& text)
662*cdf0e10cSrcweir {
663*cdf0e10cSrcweir     SetAdvancedText (text);
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir void MoreButton::SetLessText (rtl::OUString const& text)
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir     SetSimpleText (text);
669*cdf0e10cSrcweir }
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir rtl::OUString MoreButton::GetMoreText () const
672*cdf0e10cSrcweir {
673*cdf0e10cSrcweir     return GetAdvancedText ();
674*cdf0e10cSrcweir }
675*cdf0e10cSrcweir 
676*cdf0e10cSrcweir rtl::OUString MoreButton::GetLessText () const
677*cdf0e10cSrcweir {
678*cdf0e10cSrcweir     return GetSimpleText ();
679*cdf0e10cSrcweir }
680*cdf0e10cSrcweir 
681*cdf0e10cSrcweir } // namespace layout
682