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