1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "wrapper.hxx"
25 
26 #include <comphelper/processfactory.hxx>
27 #include <com/sun/star/awt/XMetricField.hpp>
28 #include <com/sun/star/awt/XNumericField.hpp>
29 #include <com/sun/star/awt/XTextComponent.hpp>
30 #include <com/sun/star/awt/XListBox.hpp>
31 #include <com/sun/star/awt/XComboBox.hpp>
32 #include <cppuhelper/implbase1.hxx>
33 #include <com/sun/star/awt/XActionListener.hpp>
34 #include <com/sun/star/awt/XItemListener.hpp>
35 #include <com/sun/star/awt/XMouseListener.hpp>
36 #include <vcl/combobox.hxx>
37 #include <vcl/lstbox.hxx>
38 
39 #include <toolkit/awt/vclxwindows.hxx>
40 
41 using namespace ::com::sun::star;
42 using rtl::OUString;
43 
44 #define LAYOUT_API_CALLS_HANDLER 0
45 
46 namespace layout
47 {
48 
49 class EditImpl : public ControlImpl
50                , public ::cppu::WeakImplHelper1< awt::XTextListener >
51 {
52 public:
53     Link maModifyHdl;
54 
55     uno::Reference< awt::XTextComponent > mxEdit;
EditImpl(Context * context,const PeerHandle & peer,Window * window)56     EditImpl( Context *context, const PeerHandle &peer, Window *window )
57         : ControlImpl( context, peer, window )
58         , mxEdit( peer, uno::UNO_QUERY )
59     {
60     }
61 
62     ~EditImpl ();
63 
64     virtual void SAL_CALL disposing( lang::EventObject const& e )
65         throw (uno::RuntimeException);
66 
67     virtual void SetModifyHdl( Link const& link );
68 
textChanged(const awt::TextEvent &)69     void SAL_CALL textChanged( const awt::TextEvent& /* rEvent */ )
70         throw (uno::RuntimeException)
71     {
72         maModifyHdl.Call( mpWindow );
73     }
74 };
75 
~EditImpl()76 EditImpl::~EditImpl ()
77 {
78 }
79 
disposing(lang::EventObject const & e)80 void SAL_CALL EditImpl::disposing( lang::EventObject const& e )
81     throw (uno::RuntimeException)
82 {
83     ControlImpl::disposing (e);
84     mxEdit.clear ();
85 }
86 
SetModifyHdl(Link const & link)87 void EditImpl::SetModifyHdl( Link const& link )
88 {
89     if (!link && !!maModifyHdl)
90         mxEdit->removeTextListener( this );
91     else if (!!link && !maModifyHdl)
92         mxEdit->addTextListener( this );
93     maModifyHdl = link;
94 }
95 
~Edit()96 Edit::~Edit ()
97 {
98     SetModifyHdl (Link ());
99 }
100 
SetSelection(Selection const & rSelection)101 void Edit::SetSelection( Selection const& rSelection )
102 {
103 #if LAYOUT_API_CALLS_HANDLER
104     if ( !getImpl().mxEdit.is() )
105         getImpl().mxEdit->setSelection( awt::Selection( rSelection.Min(), rSelection.Max() ) );
106 #else /* !LAYOUT_API_CALLS_HANDLER */
107     GetEdit ()->SetSelection (rSelection);
108 #endif /* !LAYOUT_API_CALLS_HANDLER */
109 }
110 
SetText(OUString const & rStr)111 void Edit::SetText( OUString const& rStr )
112 {
113 #if LAYOUT_API_CALLS_HANDLER
114     if ( getImpl().mxEdit.is() )
115         /// this calls handlers; endless loop in numfmt.cxx
116         getImpl().mxEdit->setText( rStr );
117 #else /* !LAYOUT_API_CALLS_HANDLER */
118     GetEdit ()->SetText (rStr);
119 #endif /* !LAYOUT_API_CALLS_HANDLER */
120 }
121 
GetText() const122 String Edit::GetText() const
123 {
124     if ( !getImpl().mxEdit.is() )
125         return getImpl().mxEdit->getText();
126     return OUString();
127 }
128 
SetModifyHdl(const Link & link)129 void Edit::SetModifyHdl( const Link& link )
130 {
131     if (&getImpl () && getImpl().mxEdit.is ())
132         getImpl().SetModifyHdl( link );
133 }
134 
135 IMPL_CONSTRUCTORS( Edit, Control, "edit" );
136 IMPL_GET_IMPL( Edit );
137 IMPL_GET_WINDOW (Edit);
138 
139 class MultiLineEditImpl : public EditImpl
140 {
141 public:
MultiLineEditImpl(Context * context,const PeerHandle & peer,Window * window)142     MultiLineEditImpl( Context *context, const PeerHandle &peer, Window *window )
143         : EditImpl( context, peer, window )
144     {
145     }
146 };
147 
148 IMPL_CONSTRUCTORS( MultiLineEdit, Edit, "multilineedit" );
149 IMPL_GET_IMPL( MultiLineEdit );
150 
151 class SpinFieldImpl : public EditImpl
152 {
153   public:
SpinFieldImpl(Context * context,const PeerHandle & peer,Window * window)154     SpinFieldImpl( Context *context, const PeerHandle &peer, Window *window )
155         : EditImpl( context, peer, window )
156     {
157     }
158 };
159 
160 IMPL_CONSTRUCTORS( SpinField, Edit, "spinfield" );
161 
162 class NumericFieldImpl : public SpinFieldImpl
163 {
164   public:
NumericFieldImpl(Context * context,const PeerHandle & peer,Window * window)165     NumericFieldImpl( Context *context, const PeerHandle &peer, Window *window )
166         : SpinFieldImpl( context, peer, window )
167     {
168     }
169 };
170 
171 class MetricFieldImpl : public SpinFieldImpl
172 {
173   public:
MetricFieldImpl(Context * context,const PeerHandle & peer,Window * window)174     MetricFieldImpl( Context *context, const PeerHandle &peer, Window *window )
175         : SpinFieldImpl( context, peer, window )
176     {
177     }
178 };
179 
180 IMPL_GET_IMPL( SpinField );
181 IMPL_GET_IMPL( NumericField );
182 IMPL_GET_IMPL( MetricField );
183 
184 class FormatterBaseImpl
185 {
186   protected:
187     PeerHandle mpeer;
188   public:
FormatterBaseImpl(const PeerHandle & peer)189     explicit FormatterBaseImpl( const PeerHandle &peer )
190         : mpeer( peer )
191     {
192     };
193 };
194 
FormatterBase(FormatterBaseImpl * pFormatImpl)195 FormatterBase::FormatterBase( FormatterBaseImpl *pFormatImpl )
196     : mpFormatImpl( pFormatImpl )
197 {
198 }
199 
200 class NumericFormatterImpl : public FormatterBaseImpl
201 {
202   public:
203     uno::Reference< awt::XNumericField > mxField;
NumericFormatterImpl(const PeerHandle & peer)204     explicit NumericFormatterImpl( const PeerHandle &peer )
205         : FormatterBaseImpl( peer )
206         , mxField( peer, uno::UNO_QUERY )
207     {
208     }
209 
210     // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx
valueToDouble(sal_Int64 nValue)211     double valueToDouble( sal_Int64 nValue )
212     {
213         sal_Int16 nDigits = mxField->getDecimalDigits();
214         double n = (double)nValue;
215         for ( sal_uInt16 d = 0; d < nDigits; d++ )
216             n /= 10;
217         return n;
218     } // FIXME: burn that CPU ! cut/paste from vclxwindows.cxx
doubleToValue(double nValue)219     sal_Int64 doubleToValue( double nValue )
220     {
221         sal_Int16 nDigits = mxField->getDecimalDigits();
222         double n = nValue;
223         for ( sal_uInt16 d = 0; d < nDigits; d++ )
224             n *= 10;
225         return (sal_Int64) n;
226     }
227 };
228 
229 class MetricFormatterImpl : public FormatterBaseImpl
230 {
231   public:
232     uno::Reference< awt::XMetricField > mxField;
MetricFormatterImpl(const PeerHandle & peer)233     explicit MetricFormatterImpl( const PeerHandle &peer )
234         : FormatterBaseImpl( peer )
235         , mxField( peer, uno::UNO_QUERY )
236     {
237     }
238 };
239 
NumericFormatter(FormatterBaseImpl * pImpl)240 NumericFormatter::NumericFormatter( FormatterBaseImpl *pImpl )
241     : FormatterBase( pImpl )
242 {
243 }
244 
getFormatImpl() const245 NumericFormatterImpl& NumericFormatter::getFormatImpl() const
246 {
247     return *( static_cast<NumericFormatterImpl *>( mpFormatImpl ) );
248 }
249 
250 #define SET_IMPL(vclmethod, idlmethod) \
251     void NumericFormatter::vclmethod( sal_Int64 nValue ) \
252     { \
253         if ( !getFormatImpl().mxField.is() ) \
254             return; \
255         getFormatImpl().mxField->idlmethod( getFormatImpl().valueToDouble( nValue ) ); \
256     }
257 
SET_IMPL(SetMin,setMin)258 SET_IMPL( SetMin, setMin )
259 SET_IMPL( SetMax, setMax )
260 SET_IMPL( SetLast, setLast )
261 SET_IMPL( SetFirst, setFirst )
262 SET_IMPL( SetValue, setValue )
263 SET_IMPL( SetSpinSize, setSpinSize )
264 
265 sal_Int64 NumericFormatter::GetValue() const
266 {
267     if ( !getFormatImpl().mxField.is() )
268         return 0;
269     return getFormatImpl().doubleToValue( getFormatImpl().mxField->getValue() );
270 }
271 
272 #undef SET_IMPL
273 
274 IMPL_CONSTRUCTORS_2( NumericField, SpinField, NumericFormatter, "numericfield" );
275 
MetricFormatter(FormatterBaseImpl * pImpl)276 MetricFormatter::MetricFormatter( FormatterBaseImpl *pImpl )
277     : FormatterBase( pImpl )
278 {
279 }
getFormatImpl() const280 MetricFormatterImpl& MetricFormatter::getFormatImpl() const
281 {    return *( static_cast<MetricFormatterImpl *>( mpFormatImpl ) );   }
282 
283 #define MetricUnitVclToUno(a) ((sal_uInt16)(a))
284 
285 #define SET_IMPL(vclmethod, idlmethod) \
286     void MetricFormatter::vclmethod( sal_Int64 nValue, FieldUnit nUnit ) \
287     { \
288         if ( !getFormatImpl().mxField.is() ) \
289             return; \
290         getFormatImpl().mxField->idlmethod( nValue, MetricUnitVclToUno( nUnit ) ); \
291     }
292 
SET_IMPL(SetMin,setMin)293 SET_IMPL( SetMin, setMin )
294 SET_IMPL( SetMax, setMax )
295 SET_IMPL( SetLast, setLast )
296 SET_IMPL( SetFirst, setFirst )
297 SET_IMPL( SetValue, setValue )
298 
299 #undef SET_IMPL
300 
301 void MetricFormatter::SetSpinSize( sal_Int64 nValue )
302 {
303     if ( !getFormatImpl().mxField.is() )
304         return;
305     getFormatImpl().mxField->setSpinSize( nValue );
306 }
307 
GetValue(FieldUnit nUnit) const308 sal_Int64 MetricFormatter::GetValue( FieldUnit nUnit ) const
309 {
310     if ( !getFormatImpl().mxField.is() )
311         return 0;
312     return getFormatImpl().mxField->getValue( MetricUnitVclToUno( nUnit ) );
313 }
314 
315 IMPL_CONSTRUCTORS_2( MetricField, SpinField, MetricFormatter, "metricfield" );
316 
317 class ComboBoxImpl : public EditImpl
318                    , public ::cppu::WeakImplHelper1< awt::XActionListener >
319                    , public ::cppu::WeakImplHelper1< awt::XItemListener >
320 {
321 public:
322     uno::Reference< awt::XComboBox > mxComboBox;
323 
324     Link maClickHdl;
325     Link maSelectHdl;
326 
327     Window *parent;
328 
ComboBoxImpl(Context * context,const PeerHandle & peer,Window * window)329     ComboBoxImpl( Context *context, const PeerHandle &peer, Window *window )
330         : EditImpl( context, peer, window )
331         , mxComboBox( peer, uno::UNO_QUERY )
332     {
333     }
334 
335     ~ComboBoxImpl ();
336 
InsertEntry(OUString const & rStr,sal_uInt16 nPos)337     sal_uInt16 InsertEntry( OUString const& rStr, sal_uInt16 nPos )
338     {
339         if ( nPos == COMBOBOX_APPEND )
340             nPos = GetEntryCount();
341         mxComboBox->addItem( rtl::OUString( rStr ), nPos );
342         return nPos;
343     }
344 
RemoveEntry(sal_uInt16 nPos)345     void RemoveEntry( sal_uInt16 nPos )
346     {
347         mxComboBox->removeItems( nPos, 1 );
348     }
349 
GetEntryPos(String const & rStr) const350     sal_uInt16 GetEntryPos( String const& rStr ) const
351     {
352         uno::Sequence< rtl::OUString> aItems( mxComboBox->getItems() );
353         rtl::OUString rKey( rStr );
354         sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength());
355         for (sal_uInt16 i = 0; i < n; i++)
356         {
357             if ( aItems[ i ] == rKey )
358                 return i;
359         }
360         return COMBOBOX_ENTRY_NOTFOUND;
361     }
362 
GetEntry(sal_uInt16 nPos) const363     OUString GetEntry( sal_uInt16 nPos ) const
364     {
365         return OUString( mxComboBox->getItem( nPos ) );
366     }
367 
GetEntryCount() const368     sal_uInt16 GetEntryCount() const
369     {
370         return mxComboBox->getItemCount();
371     }
372 
SetClickHdl(Link const & link)373     void SetClickHdl( Link const& link )
374     {
375         if (!link && !!maClickHdl)
376             mxComboBox->removeActionListener( this );
377         else if (!!link && !maClickHdl)
378             mxComboBox->addActionListener( this );
379         maClickHdl = link;
380     }
381 
SetSelectHdl(Link const & link)382     void SetSelectHdl( Link const& link )
383     {
384         if (!link && !!maSelectHdl)
385             mxComboBox->removeItemListener( this );
386         else if (!!link && !maSelectHdl)
387             mxComboBox->addItemListener( this );
388         maSelectHdl = link;
389     }
390 
391     void SAL_CALL disposing( lang::EventObject const& e )
392         throw (uno::RuntimeException);
393 
actionPerformed(const awt::ActionEvent &)394     void SAL_CALL actionPerformed (const awt::ActionEvent&)
395         throw (uno::RuntimeException)
396     {
397         ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow );
398         if ( !pComboBox )
399             return;
400         maClickHdl.Call( pComboBox );
401     }
402 
itemStateChanged(awt::ItemEvent const &)403     void SAL_CALL itemStateChanged( awt::ItemEvent const&)
404         throw (uno::RuntimeException)
405     {
406         ComboBox* pComboBox = static_cast<ComboBox*>( mpWindow );
407         if ( !pComboBox )
408             return;
409         maSelectHdl.Call( pComboBox );
410     }
411 };
412 
~ComboBox()413 ComboBox::~ComboBox ()
414 {
415 #ifndef __SUNPRO_CC
416     OSL_TRACE ("%s: deleting ComboBox for window: %p", __FUNCTION__, GetWindow ());
417 #endif
418 }
419 
~ComboBoxImpl()420 ComboBoxImpl::~ComboBoxImpl ()
421 {
422 #ifndef __SUNPRO_CC
423     OSL_TRACE ("%s: deleting ComboBoxImpl for window: %p", __FUNCTION__, mpWindow ? mpWindow->GetWindow () : 0);
424     OSL_TRACE ("%s: deleting ComboBoxImpl for listener: %p", __FUNCTION__, static_cast<XFocusListener*> (this));
425 #endif
426 }
427 
disposing(lang::EventObject const & e)428 void ComboBoxImpl::disposing( lang::EventObject const& e )
429     throw (uno::RuntimeException)
430 {
431     EditImpl::disposing (e);
432     mxComboBox.clear ();
433 }
434 
InsertEntry(String const & rStr,sal_uInt16 nPos)435 sal_uInt16 ComboBox::InsertEntry( String const& rStr, sal_uInt16 nPos )
436 {
437     return getImpl().InsertEntry( rStr, nPos );
438 }
439 
RemoveEntry(String const & rStr)440 void ComboBox::RemoveEntry( String const& rStr )
441 {
442     getImpl().RemoveEntry( GetEntryPos( rStr ) );
443 }
444 
RemoveEntry(sal_uInt16 nPos)445 void ComboBox::RemoveEntry( sal_uInt16 nPos )
446 {
447     getImpl().RemoveEntry( nPos );
448 }
449 
Clear()450 void ComboBox::Clear()
451 {
452     uno::Sequence< rtl::OUString> aNoItems;
453     getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) );
454 }
455 
GetEntryPos(String const & rStr) const456 sal_uInt16 ComboBox::GetEntryPos( String const& rStr ) const
457 {
458     return getImpl().GetEntryPos( rStr );
459 }
460 
GetEntry(sal_uInt16 nPos) const461 String ComboBox::GetEntry( sal_uInt16 nPos ) const
462 {
463     rtl::OUString rItem = getImpl().mxComboBox->getItem( nPos );
464     return OUString( rItem );
465 }
466 
GetEntryCount() const467 sal_uInt16 ComboBox::GetEntryCount() const
468 {
469     return getImpl().GetEntryCount();
470 }
471 
SetClickHdl(const Link & link)472 void ComboBox::SetClickHdl( const Link& link )
473 {
474     if (&getImpl () && getImpl().mxComboBox.is ())
475         getImpl().SetClickHdl( link );
476 }
477 
SetSelectHdl(const Link & link)478 void ComboBox::SetSelectHdl( const Link& link )
479 {
480     if (&getImpl () && getImpl().mxComboBox.is ())
481         getImpl().SetSelectHdl( link );
482 }
483 
EnableAutocomplete(bool enable,bool matchCase)484 void ComboBox::EnableAutocomplete (bool enable, bool matchCase)
485 {
486     GetComboBox ()->EnableAutocomplete (enable, matchCase);
487 }
488 
489 IMPL_CONSTRUCTORS_BODY( ComboBox, Edit, "combobox", getImpl().parent = parent; );
490 IMPL_GET_WINDOW (ComboBox);
491 /// IMPL_GET_IMPL( ComboBox );
492 
493 static ComboBoxImpl* null_combobox_impl = 0;
494 
getImpl() const495 ComboBoxImpl &ComboBox::getImpl () const
496 {
497     if (ComboBoxImpl* c = static_cast<ComboBoxImpl *>(mpImpl))
498         return *c;
499     return *null_combobox_impl;
500 }
501 
502 class ListBoxImpl : public ControlImpl
503                   , public ::cppu::WeakImplHelper1< awt::XActionListener >
504                   , public ::cppu::WeakImplHelper1< awt::XItemListener >
505                   , public ::cppu::WeakImplHelper1< awt::XMouseListener >
506 {
507     Link maClickHdl;
508     Link maSelectHdl;
509     Link maDoubleClickHdl;
510 
511 public:
512     uno::Reference< awt::XListBox > mxListBox;
ListBoxImpl(Context * context,const PeerHandle & peer,Window * window)513     ListBoxImpl( Context *context, const PeerHandle &peer, Window *window )
514         : ControlImpl( context, peer, window )
515         , mxListBox( peer, uno::UNO_QUERY )
516     {
517         SelectEntryPos (0, true);
518     }
519 
InsertEntry(String const & rStr,sal_uInt16 nPos)520     sal_uInt16 InsertEntry (String const& rStr, sal_uInt16 nPos)
521     {
522         if ( nPos == LISTBOX_APPEND )
523             nPos = mxListBox->getItemCount();
524         mxListBox->addItem( rtl::OUString( rStr ), nPos );
525         return nPos;
526     }
527 
RemoveEntry(sal_uInt16 nPos)528     void RemoveEntry( sal_uInt16 nPos )
529     {
530         mxListBox->removeItems( nPos, 1 );
531     }
532 
RemoveEntry(String const & rStr,sal_uInt16 nPos)533     sal_uInt16 RemoveEntry( String const& rStr, sal_uInt16 nPos)
534     {
535         if ( nPos == LISTBOX_APPEND )
536             nPos = mxListBox->getItemCount();
537         mxListBox->addItem( rtl::OUString( rStr ), nPos );
538         return nPos;
539     }
540 
GetEntryPos(String const & rStr) const541     sal_uInt16 GetEntryPos( String const& rStr ) const
542     {
543         uno::Sequence< rtl::OUString> aItems( mxListBox->getItems() );
544         rtl::OUString rKey( rStr );
545         sal_uInt16 n = sal::static_int_cast< sal_uInt16 >(aItems.getLength());
546         for (sal_uInt16 i = 0; i < n; i++)
547         {
548             if ( aItems[ i ] == rKey )
549                 return i;
550         }
551         return LISTBOX_ENTRY_NOTFOUND;
552     }
553 
GetEntry(sal_uInt16 nPos) const554     OUString GetEntry( sal_uInt16 nPos ) const
555     {
556         return mxListBox->getItem( nPos );
557     }
558 
GetEntryCount() const559     sal_uInt16 GetEntryCount() const
560     {
561         return mxListBox->getItemCount();
562     }
563 
SelectEntryPos(sal_uInt16 nPos,bool bSelect)564     void SelectEntryPos( sal_uInt16 nPos, bool bSelect )
565     {
566         mxListBox->selectItemPos( nPos, bSelect );
567     }
568 
GetSelectEntryCount() const569     sal_uInt16 GetSelectEntryCount() const
570     {
571         return sal::static_int_cast< sal_uInt16 >( mxListBox->getSelectedItems().getLength() );
572     }
573 
GetSelectEntryPos(sal_uInt16 nSelIndex) const574     sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex ) const
575     {
576         sal_uInt16 nSelected = 0;
577         if ( mxListBox->isMutipleMode() )
578         {
579             uno::Sequence< short > aItems( mxListBox->getSelectedItemsPos() );
580             if ( nSelIndex < aItems.getLength() )
581                 nSelected = aItems[ nSelIndex ];
582         }
583         else
584             nSelected = mxListBox->getSelectedItemPos();
585         return nSelected;
586     }
587 
disposing(lang::EventObject const & e)588     virtual void SAL_CALL disposing( lang::EventObject const& e )
589         throw (uno::RuntimeException)
590     {
591         ControlImpl::disposing (e);
592         mxListBox.clear ();
593     }
594 
GetClickHdl()595     Link& GetClickHdl ()
596     {
597         return maClickHdl;
598     }
599 
SetClickHdl(Link const & link)600     void SetClickHdl( Link const& link )
601     {
602         if (!link && !!maClickHdl)
603             mxListBox->removeActionListener( this );
604         else if (!!link && !maClickHdl)
605             mxListBox->addActionListener( this );
606         maClickHdl = link;
607     }
608 
actionPerformed(const awt::ActionEvent &)609     void SAL_CALL actionPerformed( const awt::ActionEvent& /* rEvent */ )
610         throw (uno::RuntimeException)
611     {
612         maClickHdl.Call( mpWindow );
613     }
614 
GetSelectHdl()615     Link& GetSelectHdl ()
616     {
617         return maSelectHdl;
618     }
619 
SetSelectHdl(Link const & link)620     void SetSelectHdl( Link const& link )
621     {
622         if (!link && !!maSelectHdl)
623             mxListBox->removeItemListener( this );
624         else if (!!link && !maSelectHdl)
625             mxListBox->addItemListener( this );
626         maSelectHdl = link;
627     }
628 
itemStateChanged(awt::ItemEvent const &)629     void SAL_CALL itemStateChanged (awt::ItemEvent const&)
630         throw (uno::RuntimeException)
631     {
632         maSelectHdl.Call (static_cast <ListBox*> (mpWindow));
633     }
634 
GetDoubleClickHdl()635     Link& GetDoubleClickHdl ()
636     {
637         return maDoubleClickHdl;
638     }
639 
SetDoubleClickHdl(Link const & link)640     void SetDoubleClickHdl (Link const& link)
641     {
642         if (!link && !!maDoubleClickHdl)
643             mxWindow->removeMouseListener (this);
644         else if (!!link && !maSelectHdl)
645             mxWindow->addMouseListener (this);
646         maDoubleClickHdl = link;
647     }
648 
mousePressed(awt::MouseEvent const &)649     void SAL_CALL mousePressed (awt::MouseEvent const&) throw (uno::RuntimeException)
650     {
651     }
mouseReleased(awt::MouseEvent const & e)652     void SAL_CALL mouseReleased (awt::MouseEvent const& e) throw (uno::RuntimeException)
653     {
654         if (e.ClickCount == 2)
655             maDoubleClickHdl.Call (mpWindow);
656     }
mouseEntered(awt::MouseEvent const &)657     void SAL_CALL mouseEntered (awt::MouseEvent const&) throw (uno::RuntimeException)
658     {
659     }
mouseExited(awt::MouseEvent const &)660     void SAL_CALL mouseExited (awt::MouseEvent const&) throw (uno::RuntimeException)
661     {
662     }
663 };
664 
~ListBox()665 ListBox::~ListBox ()
666 {
667 }
668 
InsertEntry(String const & rStr,sal_uInt16 nPos)669 sal_uInt16 ListBox::InsertEntry (String const& rStr, sal_uInt16 nPos)
670 {
671     return getImpl().InsertEntry(rStr, nPos);
672 }
673 
RemoveEntry(sal_uInt16 nPos)674 void ListBox::RemoveEntry( sal_uInt16 nPos )
675 {
676     return getImpl().RemoveEntry( nPos );
677 }
678 
RemoveEntry(String const & rStr)679 void ListBox::RemoveEntry( String const& rStr )
680 {
681     return getImpl().RemoveEntry( GetEntryPos( rStr ) );
682 }
683 
Clear()684 void ListBox::Clear()
685 {
686     uno::Sequence< rtl::OUString> aNoItems;
687     getImpl().setProperty( "StringItemList", uno::Any( aNoItems ) );
688 }
689 
GetEntryPos(String const & rStr) const690 sal_uInt16 ListBox::GetEntryPos( String const& rStr ) const
691 {
692     return getImpl().GetEntryPos( rStr );
693 }
694 
GetEntry(sal_uInt16 nPos) const695 String ListBox::GetEntry( sal_uInt16 nPos ) const
696 {
697     return getImpl().GetEntry( nPos );
698 }
699 
GetEntryCount() const700 sal_uInt16 ListBox::GetEntryCount() const
701 {
702     return getImpl().GetEntryCount();
703 }
704 
SelectEntryPos(sal_uInt16 nPos,bool bSelect)705 void ListBox::SelectEntryPos( sal_uInt16 nPos, bool bSelect )
706 {
707 #if LAYOUT_API_CALLS_HANDLER
708     getImpl().SelectEntryPos( nPos, bSelect );
709 #else /* !LAYOUT_API_CALLS_HANDLER */
710     GetListBox ()->SelectEntryPos (nPos, bSelect);
711 #endif /* !LAYOUT_API_CALLS_HANDLER */
712 }
713 
SelectEntry(String const & rStr,bool bSelect)714 void ListBox::SelectEntry( String const& rStr, bool bSelect )
715 {
716     SelectEntryPos( GetEntryPos( rStr ), bSelect );
717 }
718 
GetSelectEntryCount() const719 sal_uInt16 ListBox::GetSelectEntryCount() const
720 {
721     return getImpl().GetSelectEntryCount();
722 }
723 
GetSelectEntryPos(sal_uInt16 nSelIndex) const724 sal_uInt16 ListBox::GetSelectEntryPos( sal_uInt16 nSelIndex ) const
725 {
726     return getImpl().GetSelectEntryPos( nSelIndex );
727 }
728 
GetSelectEntry(sal_uInt16 nSelIndex) const729 String ListBox::GetSelectEntry( sal_uInt16 nSelIndex ) const
730 {
731     return GetEntry( GetSelectEntryPos( nSelIndex ) );
732 }
733 
GetSelectHdl()734 Link& ListBox::GetSelectHdl ()
735 {
736     return getImpl ().GetSelectHdl ();
737 }
738 
SetSelectHdl(Link const & link)739 void ListBox::SetSelectHdl( Link const& link )
740 {
741     getImpl().SetSelectHdl( link );
742 }
743 
GetClickHdl()744 Link& ListBox::GetClickHdl ()
745 {
746     return getImpl ().GetSelectHdl ();
747 }
748 
SetClickHdl(Link const & link)749 void ListBox::SetClickHdl( Link const& link )
750 {
751     if (&getImpl () && getImpl().mxListBox.is ())
752         getImpl().SetClickHdl( link );
753 }
754 
GetDoubleClickHdl()755 Link& ListBox::GetDoubleClickHdl ()
756 {
757     return getImpl ().GetSelectHdl ();
758 }
759 
SetDoubleClickHdl(Link const & link)760 void ListBox::SetDoubleClickHdl( Link const& link )
761 {
762     getImpl().SetDoubleClickHdl( link );
763 }
764 
SetEntryData(sal_uInt16 pos,void * data)765 void ListBox::SetEntryData( sal_uInt16 pos, void* data)
766 {
767     GetListBox ()->SetEntryData (pos, data);
768 }
769 
GetEntryData(sal_uInt16 pos) const770 void* ListBox::GetEntryData( sal_uInt16 pos) const
771 {
772     return GetListBox ()->GetEntryData (pos);
773 }
774 
SetNoSelection()775 void ListBox::SetNoSelection ()
776 {
777     GetListBox ()->SetNoSelection ();
778 }
779 
780 IMPL_CONSTRUCTORS (ListBox, Control, "listbox");
781 IMPL_GET_IMPL (ListBox);
782 IMPL_GET_WINDOW (ListBox);
783 
784 IMPL_IMPL (MultiListBox, ListBox)
785 IMPL_CONSTRUCTORS_BODY( MultiListBox, ListBox, "multilistbox", GetMultiListBox()->EnableMultiSelection( true ); );
786 IMPL_GET_IMPL( MultiListBox );
787 IMPL_GET_WINDOW( MultiListBox );
788 } // namespace layout
789