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