1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_extensions.hxx"
31 #include "browserlistbox.hxx"
32 #include "propresid.hrc"
33 #include "proplinelistener.hxx"
34 #include "propcontrolobserver.hxx"
35 #include "linedescriptor.hxx"
36 #include "inspectorhelpwindow.hxx"
38 /** === begin UNO includes === **/
39 #include <com/sun/star/lang/DisposedException.hpp>
40 #include <com/sun/star/lang/XComponent.hpp>
41 #include <com/sun/star/inspection/PropertyControlType.hpp>
42 /** === end UNO includes === **/
43 #include <tools/debug.hxx>
44 #include <tools/diagnose_ex.h>
45 #include <comphelper/asyncnotification.hxx>
46 #include <cppuhelper/implbase1.hxx>
47 #include <vcl/svapp.hxx>
48 #include <osl/mutex.hxx>
50 //............................................................................
53 //............................................................................
55 #define FRAME_OFFSET 4
56 // TODO: find out what this is really for ... and check if it does make sense in the new
57 // browser environment
58 #define LAYOUT_HELP_WINDOW_DISTANCE_APPFONT 3
60 /** === begin UNO using === **/
61 using ::com::sun::star::uno::Any
;
62 using ::com::sun::star::uno::Exception
;
63 using ::com::sun::star::inspection::XPropertyControlContext
;
64 using ::com::sun::star::uno::Reference
;
65 using ::com::sun::star::inspection::XPropertyControl
;
66 using ::com::sun::star::uno::RuntimeException
;
67 using ::com::sun::star::lang::DisposedException
;
68 using ::com::sun::star::lang::XComponent
;
69 using ::com::sun::star::uno::UNO_QUERY
;
70 using ::com::sun::star::graphic::XGraphic
;
71 /** === end UNO using === **/
72 namespace PropertyControlType
= ::com::sun::star::inspection::PropertyControlType
;
74 //==================================================================
76 //==================================================================
84 struct ControlEvent
: public ::comphelper::AnyEvent
86 Reference
< XPropertyControl
> xControl
;
87 ControlEventType eType
;
89 ControlEvent( const Reference
< XPropertyControl
>& _rxControl
, ControlEventType _eType
)
90 :xControl( _rxControl
)
96 //==================================================================
98 //==================================================================
102 static ::osl::Mutex
& getMutex();
103 static ::rtl::Reference
< ::comphelper::AsyncEventNotifier
> s_pNotifier
;
106 static const ::rtl::Reference
< ::comphelper::AsyncEventNotifier
>&
110 SharedNotifier(); // never implemented
111 SharedNotifier( const SharedNotifier
& ); // never implemented
112 SharedNotifier
& operator=( const SharedNotifier
& ); // never implemented
115 //------------------------------------------------------------------
116 ::rtl::Reference
< ::comphelper::AsyncEventNotifier
> SharedNotifier::s_pNotifier
;
118 //------------------------------------------------------------------
119 ::osl::Mutex
& SharedNotifier::getMutex()
121 static ::osl::Mutex s_aMutex
;
125 //------------------------------------------------------------------
126 const ::rtl::Reference
< ::comphelper::AsyncEventNotifier
>& SharedNotifier::getNotifier()
128 ::osl::MutexGuard
aGuard( getMutex() );
129 if ( !s_pNotifier
.is() )
131 s_pNotifier
.set( new ::comphelper::AsyncEventNotifier
);
132 s_pNotifier
->create();
137 //==================================================================
138 //= PropertyControlContext_Impl
139 //==================================================================
140 /** implementation for of <type scope="com::sun::star::inspection">XPropertyControlContext</type>
141 which forwards all events to a non-UNO version of this interface
143 typedef ::cppu::WeakImplHelper1
< XPropertyControlContext
> PropertyControlContext_Impl_Base
;
144 class PropertyControlContext_Impl
:public PropertyControlContext_Impl_Base
145 ,public ::comphelper::IEventProcessor
155 IControlContext
* m_pContext
;
156 NotifcationMode m_eMode
;
159 /** creates an instance
161 the instance to delegate events to
163 PropertyControlContext_Impl( IControlContext
& _rContextImpl
);
165 /** disposes the context.
167 When you call this method, all subsequent callbacks to the
168 <type scope="com::sun::star::inspection">XPropertyControlContext</type> methods
169 will throw a <type scope="com::sun::star::lang">DisposedException</type>.
171 void SAL_CALL
dispose();
173 /** sets the notification mode, so that notifications recieved from the controls are
174 forwarded to our IControlContext either synchronously or asynchronously
176 the new notification mode
178 void setNotificationMode( NotifcationMode _eMode
);
180 virtual void SAL_CALL
acquire() throw();
181 virtual void SAL_CALL
release() throw();
184 ~PropertyControlContext_Impl();
186 // XPropertyControlObserver
187 virtual void SAL_CALL
focusGained( const Reference
< XPropertyControl
>& Control
) throw (RuntimeException
);
188 virtual void SAL_CALL
valueChanged( const Reference
< XPropertyControl
>& Control
) throw (RuntimeException
);
189 // XPropertyControlContext
190 virtual void SAL_CALL
activateNextControl( const Reference
< XPropertyControl
>& CurrentControl
) throw (RuntimeException
);
193 virtual void processEvent( const ::comphelper::AnyEvent
& _rEvent
);
196 /** processes the given event, i.e. notifies it to our IControlContext
200 our mutex (well, the SolarMutex) is locked
202 void impl_processEvent_throw( const ::comphelper::AnyEvent
& _rEvent
);
204 /** checks whether we're alive
206 @throws DisposedException
207 if the instance is already disposed
209 void impl_checkAlive_throw() const;
211 /** checks whether the instance is already disposed
213 bool impl_isDisposed_nothrow() const { return m_pContext
== NULL
; }
215 /** notifies the given event originating from the given control
216 @throws DisposedException
220 void impl_notify_throw( const Reference
< XPropertyControl
>& _rxControl
, ControlEventType _eType
);
223 //--------------------------------------------------------------------
224 PropertyControlContext_Impl::PropertyControlContext_Impl( IControlContext
& _rContextImpl
)
225 :m_pContext( &_rContextImpl
)
226 ,m_eMode( eAsynchronously
)
230 //--------------------------------------------------------------------
231 PropertyControlContext_Impl::~PropertyControlContext_Impl()
233 if ( !impl_isDisposed_nothrow() )
237 //--------------------------------------------------------------------
238 void PropertyControlContext_Impl::impl_checkAlive_throw() const
240 if ( impl_isDisposed_nothrow() )
241 throw DisposedException( ::rtl::OUString(), *const_cast< PropertyControlContext_Impl
* >( this ) );
244 //--------------------------------------------------------------------
245 void SAL_CALL
PropertyControlContext_Impl::dispose()
247 SolarMutexGuard aGuard
;
248 if ( impl_isDisposed_nothrow() )
251 SharedNotifier::getNotifier()->removeEventsForProcessor( this );
255 //--------------------------------------------------------------------
256 void PropertyControlContext_Impl::setNotificationMode( NotifcationMode _eMode
)
258 SolarMutexGuard aGuard
;
262 //--------------------------------------------------------------------
263 void PropertyControlContext_Impl::impl_notify_throw( const Reference
< XPropertyControl
>& _rxControl
, ControlEventType _eType
)
265 ::comphelper::AnyEventRef pEvent
;
268 SolarMutexGuard aGuard
;
269 impl_checkAlive_throw();
270 pEvent
= new ControlEvent( _rxControl
, _eType
);
272 if ( m_eMode
== eSynchronously
)
274 impl_processEvent_throw( *pEvent
);
279 SharedNotifier::getNotifier()->addEvent( pEvent
, this );
282 //--------------------------------------------------------------------
283 void SAL_CALL
PropertyControlContext_Impl::focusGained( const Reference
< XPropertyControl
>& Control
) throw (RuntimeException
)
285 DBG_TRACE( "PropertyControlContext_Impl: FOCUS_GAINED" );
286 impl_notify_throw( Control
, FOCUS_GAINED
);
289 //--------------------------------------------------------------------
290 void SAL_CALL
PropertyControlContext_Impl::valueChanged( const Reference
< XPropertyControl
>& Control
) throw (RuntimeException
)
292 DBG_TRACE( "PropertyControlContext_Impl: VALUE_CHANGED" );
293 impl_notify_throw( Control
, VALUE_CHANGED
);
296 //--------------------------------------------------------------------
297 void SAL_CALL
PropertyControlContext_Impl::activateNextControl( const Reference
< XPropertyControl
>& CurrentControl
) throw (RuntimeException
)
299 DBG_TRACE( "PropertyControlContext_Impl: ACTIVATE_NEXT" );
300 impl_notify_throw( CurrentControl
, ACTIVATE_NEXT
);
303 //--------------------------------------------------------------------
304 void SAL_CALL
PropertyControlContext_Impl::acquire() throw()
306 PropertyControlContext_Impl_Base::acquire();
309 //--------------------------------------------------------------------
310 void SAL_CALL
PropertyControlContext_Impl::release() throw()
312 PropertyControlContext_Impl_Base::release();
315 //--------------------------------------------------------------------
316 void PropertyControlContext_Impl::processEvent( const ::comphelper::AnyEvent
& _rEvent
)
318 SolarMutexGuard aGuard
;
319 if ( impl_isDisposed_nothrow() )
324 impl_processEvent_throw( _rEvent
);
326 catch( const Exception
& )
328 // can't handle otherwise, since our caller (the notification thread) does not allow
329 // for exceptions (it could itself abort only)
330 DBG_UNHANDLED_EXCEPTION();
334 //--------------------------------------------------------------------
335 void PropertyControlContext_Impl::impl_processEvent_throw( const ::comphelper::AnyEvent
& _rEvent
)
337 const ControlEvent
& rControlEvent
= static_cast< const ControlEvent
& >( _rEvent
);
338 switch ( rControlEvent
.eType
)
341 DBG_TRACE( "PropertyControlContext_Impl::processEvent: FOCUS_GAINED" );
342 m_pContext
->focusGained( rControlEvent
.xControl
);
345 DBG_TRACE( "PropertyControlContext_Impl::processEvent: VALUE_CHANGED" );
346 m_pContext
->valueChanged( rControlEvent
.xControl
);
349 DBG_TRACE( "PropertyControlContext_Impl::processEvent: ACTIVATE_NEXT" );
350 m_pContext
->activateNextControl( rControlEvent
.xControl
);
355 //==================================================================
357 //==================================================================
358 DBG_NAME(OBrowserListBox
)
359 //------------------------------------------------------------------
360 OBrowserListBox::OBrowserListBox( Window
* pParent
, WinBits nWinStyle
)
361 :Control(pParent
, nWinStyle
| WB_CLIPCHILDREN
)
362 ,m_aLinesPlayground(this,WB_DIALOGCONTROL
| WB_CLIPCHILDREN
)
363 ,m_aVScroll(this,WB_VSCROLL
|WB_REPEAT
|WB_DRAG
)
364 ,m_pHelpWindow( new InspectorHelpWindow( this ) )
365 ,m_pLineListener(NULL
)
366 ,m_pControlObserver( NULL
)
368 ,m_nCurrentPreferredHelpHeight(0)
370 ,m_bIsActive(sal_False
)
372 ,m_pControlContextImpl( new PropertyControlContext_Impl( *this ) )
374 DBG_CTOR(OBrowserListBox
,NULL
);
376 ListBox
aListBox(this,WB_DROPDOWN
);
377 aListBox
.SetPosSizePixel(Point(0,0),Size(100,100));
378 m_nRowHeight
= (sal_uInt16
)aListBox
.GetSizePixel().Height()+2;
379 SetBackground( pParent
->GetBackground() );
380 m_aLinesPlayground
.SetBackground( GetBackground() );
382 m_aLinesPlayground
.SetPosPixel(Point(0,0));
383 m_aLinesPlayground
.SetPaintTransparent(sal_True
);
384 m_aLinesPlayground
.Show();
386 m_aVScroll
.SetScrollHdl(LINK(this, OBrowserListBox
, ScrollHdl
));
389 //------------------------------------------------------------------
390 OBrowserListBox::~OBrowserListBox()
392 OSL_ENSURE( !IsModified(), "OBrowserListBox::~OBrowserListBox: still modified - should have been committed before!" );
393 // doing the commit here, while we, as well as our owner, as well as some other components,
394 // are already "half dead" (means within their dtor) is potentially dangerous.
395 // By definition, CommitModified has to be called (if necessary) before destruction
396 // #105868# - 2002-12-13 - fs@openoffice.org
398 m_pControlContextImpl
->dispose();
399 m_pControlContextImpl
.clear();
404 DBG_DTOR(OBrowserListBox
,NULL
);
407 //------------------------------------------------------------------
408 sal_Bool
OBrowserListBox::IsModified( ) const
410 sal_Bool bModified
= sal_False
;
412 if ( m_bIsActive
&& m_xActiveControl
.is() )
413 bModified
= m_xActiveControl
->isModified();
418 //------------------------------------------------------------------
419 void OBrowserListBox::CommitModified( )
421 if ( IsModified() && m_xActiveControl
.is() )
423 // for the time of this commit, notify all events synchronously
424 // #i63814# / 2006-03-31 / frank.schoenheit@sun.com
425 m_pControlContextImpl
->setNotificationMode( PropertyControlContext_Impl::eSynchronously
);
428 m_xActiveControl
->notifyModifiedValue();
430 catch( const Exception
& )
432 DBG_UNHANDLED_EXCEPTION();
434 m_pControlContextImpl
->setNotificationMode( PropertyControlContext_Impl::eAsynchronously
);
438 //------------------------------------------------------------------
439 void OBrowserListBox::ActivateListBox(sal_Bool _bActive
)
441 m_bIsActive
= _bActive
;
444 // TODO: what's the sense of this?
445 m_aVScroll
.SetThumbPos(100);
451 //------------------------------------------------------------------
452 long OBrowserListBox::impl_getPrefererredHelpHeight()
454 return HasHelpSection() ? m_pHelpWindow
->GetOptimalHeightPixel() : 0;
457 //------------------------------------------------------------------
458 void OBrowserListBox::Resize()
460 Rectangle
aPlayground( Point( 0, 0 ), GetOutputSizePixel() );
461 Size
aHelpWindowDistance( LogicToPixel( Size( 0, LAYOUT_HELP_WINDOW_DISTANCE_APPFONT
), MAP_APPFONT
) );
463 long nHelpWindowHeight
= m_nCurrentPreferredHelpHeight
= impl_getPrefererredHelpHeight();
464 bool bPositionHelpWindow
= ( nHelpWindowHeight
!= 0 );
466 Rectangle
aLinesArea( aPlayground
);
467 if ( bPositionHelpWindow
)
469 aLinesArea
.Bottom() -= nHelpWindowHeight
;
470 aLinesArea
.Bottom() -= aHelpWindowDistance
.Height();
472 m_aLinesPlayground
.SetPosSizePixel( aLinesArea
.TopLeft(), aLinesArea
.GetSize() );
476 sal_Bool bNeedScrollbar
= m_aOrderedLines
.size() > (sal_uInt32
)CalcVisibleLines();
477 if ( !bNeedScrollbar
)
479 if ( m_aVScroll
.IsVisible() )
483 m_aVScroll
.SetThumbPos( 0 );
487 Size
aVScrollSize( m_aVScroll
.GetSizePixel() );
489 // adjust the playground's width
490 aLinesArea
.Right() -= aVScrollSize
.Width();
491 m_aLinesPlayground
.SetPosSizePixel( aLinesArea
.TopLeft(), aLinesArea
.GetSize() );
493 // position the scrollbar
494 aVScrollSize
.Height() = aLinesArea
.GetHeight();
495 Point
aVScrollPos( aLinesArea
.GetWidth(), 0 );
496 m_aVScroll
.SetPosSizePixel( aVScrollPos
, aVScrollSize
);
499 for ( sal_uInt16 i
= 0; i
< m_aOrderedLines
.size(); ++i
)
500 m_aOutOfDateLines
.insert( i
);
503 EnablePaint(sal_False
);
505 EnablePaint(sal_True
);
507 // show the scrollbar
508 if ( bNeedScrollbar
)
511 // position the help window
512 if ( bPositionHelpWindow
)
514 Rectangle
aHelpArea( aPlayground
);
515 aHelpArea
.Top() = aLinesArea
.Bottom() + aHelpWindowDistance
.Height();
516 m_pHelpWindow
->SetPosSizePixel( aHelpArea
.TopLeft(), aHelpArea
.GetSize() );
520 //------------------------------------------------------------------
521 void OBrowserListBox::SetListener( IPropertyLineListener
* _pListener
)
523 m_pLineListener
= _pListener
;
526 //------------------------------------------------------------------
527 void OBrowserListBox::SetObserver( IPropertyControlObserver
* _pObserver
)
529 m_pControlObserver
= _pObserver
;
532 //------------------------------------------------------------------
533 void OBrowserListBox::EnableHelpSection( bool _bEnable
)
535 m_pHelpWindow
->Show( _bEnable
);
539 //------------------------------------------------------------------
540 bool OBrowserListBox::HasHelpSection() const
542 return m_pHelpWindow
->IsVisible();
545 //------------------------------------------------------------------
546 void OBrowserListBox::SetHelpText( const ::rtl::OUString
& _rHelpText
)
548 OSL_ENSURE( HasHelpSection(), "OBrowserListBox::SetHelpText: help section not visible!" );
549 m_pHelpWindow
->SetText( _rHelpText
);
550 if ( m_nCurrentPreferredHelpHeight
!= impl_getPrefererredHelpHeight() )
554 //------------------------------------------------------------------
555 void OBrowserListBox::SetHelpLineLimites( sal_Int32 _nMinLines
, sal_Int32 _nMaxLines
)
557 m_pHelpWindow
->SetLimits( _nMinLines
, _nMaxLines
);
560 //------------------------------------------------------------------
561 sal_uInt16
OBrowserListBox::CalcVisibleLines()
563 Size
aSize(m_aLinesPlayground
.GetOutputSizePixel());
564 sal_uInt16 nResult
= 0;
565 if (0 != m_nRowHeight
)
566 nResult
= (sal_uInt16
) aSize
.Height()/m_nRowHeight
;
571 //------------------------------------------------------------------
572 void OBrowserListBox::UpdateVScroll()
574 sal_uInt16 nLines
= CalcVisibleLines();
575 m_aVScroll
.SetPageSize(nLines
-1);
576 m_aVScroll
.SetVisibleSize(nLines
-1);
578 size_t nCount
= m_aLines
.size();
581 m_aVScroll
.SetRange(Range(0,nCount
-1));
582 m_nYOffset
= -m_aVScroll
.GetThumbPos()*m_nRowHeight
;
586 m_aVScroll
.SetRange(Range(0,0));
591 //------------------------------------------------------------------
592 void OBrowserListBox::PositionLine( sal_uInt16 _nIndex
)
594 Size
aSize(m_aLinesPlayground
.GetOutputSizePixel());
595 Point
aPos(0, m_nYOffset
);
597 aSize
.Height() = m_nRowHeight
;
599 aPos
.Y() += _nIndex
* m_nRowHeight
;
601 if ( _nIndex
< m_aOrderedLines
.size() )
603 m_aOrderedLines
[ _nIndex
]->second
.pLine
->SetPosSizePixel( aPos
, aSize
);
605 m_aOrderedLines
[ _nIndex
]->second
.pLine
->SetTitleWidth( m_nTheNameSize
+ 2 * FRAME_OFFSET
);
607 // show the line if necessary
608 if ( !m_aOrderedLines
[ _nIndex
]->second
.pLine
->IsVisible() )
609 m_aOrderedLines
[ _nIndex
]->second
.pLine
->Show();
613 //------------------------------------------------------------------
614 void OBrowserListBox::UpdatePosNSize()
616 for ( ::std::set
< sal_uInt16
>::const_iterator aLoop
= m_aOutOfDateLines
.begin();
617 aLoop
!= m_aOutOfDateLines
.end();
621 DBG_ASSERT( *aLoop
< m_aOrderedLines
.size(), "OBrowserListBox::UpdatePosNSize: invalid line index!" );
622 if ( *aLoop
< m_aOrderedLines
.size() )
623 PositionLine( *aLoop
);
625 m_aOutOfDateLines
.clear();
628 //------------------------------------------------------------------
629 void OBrowserListBox::UpdatePlayGround()
631 sal_Int32 nThumbPos
= m_aVScroll
.GetThumbPos();
632 sal_Int32 nLines
= CalcVisibleLines();
634 sal_uInt16 nEnd
= (sal_uInt16
)(nThumbPos
+ nLines
);
635 if (nEnd
>= m_aOrderedLines
.size())
636 nEnd
= (sal_uInt16
)m_aOrderedLines
.size()-1;
638 if ( !m_aOrderedLines
.empty() )
640 for ( sal_uInt16 i
= (sal_uInt16
)nThumbPos
; i
<= nEnd
; ++i
)
641 m_aOutOfDateLines
.insert( i
);
646 //------------------------------------------------------------------
647 void OBrowserListBox::UpdateAll()
652 //------------------------------------------------------------------
653 void OBrowserListBox::DisableUpdate()
655 m_bUpdate
= sal_False
;
658 //------------------------------------------------------------------
659 void OBrowserListBox::EnableUpdate()
661 m_bUpdate
= sal_True
;
665 //------------------------------------------------------------------
666 void OBrowserListBox::SetPropertyValue(const ::rtl::OUString
& _rEntryName
, const Any
& _rValue
, bool _bUnknownValue
)
668 ListBoxLines::iterator line
= m_aLines
.find( _rEntryName
);
669 if ( line
!= m_aLines
.end() )
671 if ( _bUnknownValue
)
673 Reference
< XPropertyControl
> xControl( line
->second
.pLine
->getControl() );
674 OSL_ENSURE( xControl
.is(), "OBrowserListBox::SetPropertyValue: illegal control!" );
676 xControl
->setValue( Any() );
679 impl_setControlAsPropertyValue( line
->second
, _rValue
);
683 //------------------------------------------------------------------------
684 sal_uInt16
OBrowserListBox::GetPropertyPos( const ::rtl::OUString
& _rEntryName
) const
686 sal_uInt16 nRet
= LISTBOX_ENTRY_NOTFOUND
;
687 for ( OrderedListBoxLines::const_iterator linePos
= m_aOrderedLines
.begin();
688 linePos
!= m_aOrderedLines
.end();
692 if ( (*linePos
)->first
== _rEntryName
)
694 nRet
= (sal_uInt16
)( linePos
- m_aOrderedLines
.begin() );
702 //------------------------------------------------------------------------
703 bool OBrowserListBox::impl_getBrowserLineForName( const ::rtl::OUString
& _rEntryName
, BrowserLinePointer
& _out_rpLine
) const
705 ListBoxLines::const_iterator line
= m_aLines
.find( _rEntryName
);
706 if ( line
!= m_aLines
.end() )
707 _out_rpLine
= line
->second
.pLine
;
710 return ( NULL
!= _out_rpLine
.get() );
713 //------------------------------------------------------------------------
714 void OBrowserListBox::EnablePropertyControls( const ::rtl::OUString
& _rEntryName
, sal_Int16 _nControls
, bool _bEnable
)
716 BrowserLinePointer pLine
;
717 if ( impl_getBrowserLineForName( _rEntryName
, pLine
) )
718 pLine
->EnablePropertyControls( _nControls
, _bEnable
);
721 //------------------------------------------------------------------------
722 void OBrowserListBox::EnablePropertyLine( const ::rtl::OUString
& _rEntryName
, bool _bEnable
)
724 BrowserLinePointer pLine
;
725 if ( impl_getBrowserLineForName( _rEntryName
, pLine
) )
726 pLine
->EnablePropertyLine( _bEnable
);
729 //------------------------------------------------------------------------
730 Reference
< XPropertyControl
> OBrowserListBox::GetPropertyControl( const ::rtl::OUString
& _rEntryName
)
732 BrowserLinePointer pLine
;
733 if ( impl_getBrowserLineForName( _rEntryName
, pLine
) )
734 return pLine
->getControl();
738 //------------------------------------------------------------------
739 sal_uInt16
OBrowserListBox::InsertEntry(const OLineDescriptor
& _rPropertyData
, sal_uInt16 _nPos
)
742 BrowserLinePointer
pBrowserLine( new OBrowserLine( _rPropertyData
.sName
, &m_aLinesPlayground
) );
744 ListBoxLine
aNewLine( pBrowserLine
, _rPropertyData
.xPropertyHandler
);
745 ::std::pair
< ListBoxLines::iterator
, bool > insertPoint
=
746 m_aLines
.insert( ListBoxLines::value_type( _rPropertyData
.sName
, aNewLine
) );
747 OSL_ENSURE( insertPoint
.second
, "OBrowserListBox::InsertEntry: already have another line for this name!" );
749 sal_uInt16 nInsertPos
= _nPos
;
750 if ( nInsertPos
> m_aOrderedLines
.size() )
751 nInsertPos
= EDITOR_LIST_APPEND
;
752 if ( EDITOR_LIST_APPEND
== nInsertPos
)
754 nInsertPos
= (sal_uInt16
)m_aOrderedLines
.size();
755 m_aOrderedLines
.push_back( insertPoint
.first
);
758 m_aOrderedLines
.insert( m_aOrderedLines
.begin() + nInsertPos
, insertPoint
.first
);
760 pBrowserLine
->SetTitleWidth(m_nTheNameSize
);
767 // initialize the entry
768 ChangeEntry(_rPropertyData
, nInsertPos
);
770 // update the positions of possibly affected lines
771 sal_uInt16 nUpdatePos
= nInsertPos
;
772 while ( nUpdatePos
< m_aOrderedLines
.size() )
773 m_aOutOfDateLines
.insert( nUpdatePos
++ );
779 //------------------------------------------------------------------
780 sal_Int32
OBrowserListBox::GetMinimumWidth()
782 return m_nTheNameSize
+ 2 * FRAME_OFFSET
+ (m_nRowHeight
- 4) * 8;
785 //------------------------------------------------------------------
786 sal_Int32
OBrowserListBox::GetMinimumHeight()
788 // assume that we want to display 5 rows, at least
789 sal_Int32 nMinHeight
= m_nRowHeight
* 5;
791 if ( HasHelpSection() )
793 Size
aHelpWindowDistance( LogicToPixel( Size( 0, LAYOUT_HELP_WINDOW_DISTANCE_APPFONT
), MAP_APPFONT
) );
794 nMinHeight
+= aHelpWindowDistance
.Height();
796 nMinHeight
+= m_pHelpWindow
->GetMinimalHeightPixel();
802 //------------------------------------------------------------------
803 void OBrowserListBox::ShowEntry(sal_uInt16 _nPos
)
805 if ( _nPos
< m_aOrderedLines
.size() )
807 sal_Int32 nThumbPos
= m_aVScroll
.GetThumbPos();
809 if (_nPos
< nThumbPos
)
813 sal_Int32 nLines
= CalcVisibleLines();
814 if (_nPos
>= nThumbPos
+ nLines
)
815 MoveThumbTo(_nPos
- nLines
+ 1);
821 //------------------------------------------------------------------
822 void OBrowserListBox::MoveThumbTo(sal_Int32 _nNewThumbPos
)
824 // disable painting to prevent flicker
825 m_aLinesPlayground
.EnablePaint(sal_False
);
827 sal_Int32 nDelta
= _nNewThumbPos
- m_aVScroll
.GetThumbPos();
828 // adjust the scrollbar
829 m_aVScroll
.SetThumbPos(_nNewThumbPos
);
830 sal_Int32 nThumbPos
= _nNewThumbPos
;
832 m_nYOffset
= -m_aVScroll
.GetThumbPos() * m_nRowHeight
;
834 sal_Int32 nLines
= CalcVisibleLines();
835 sal_uInt16 nEnd
= (sal_uInt16
)(nThumbPos
+ nLines
);
837 m_aLinesPlayground
.Scroll(0, -nDelta
* m_nRowHeight
, SCROLL_CHILDREN
);
841 // TODO: what's the sense of this two PositionLines? Why not just one call?
842 PositionLine(nEnd
-1);
845 else if (-1 == nDelta
)
847 PositionLine((sal_uInt16
)nThumbPos
);
849 else if (0 != nDelta
)
854 m_aLinesPlayground
.EnablePaint(sal_True
);
855 m_aLinesPlayground
.Invalidate(INVALIDATE_CHILDREN
);
858 //------------------------------------------------------------------
859 IMPL_LINK(OBrowserListBox
, ScrollHdl
, ScrollBar
*, _pScrollBar
)
861 DBG_ASSERT(_pScrollBar
== &m_aVScroll
, "OBrowserListBox::ScrollHdl: where does this come from?");
864 // disable painting to prevent flicker
865 m_aLinesPlayground
.EnablePaint(sal_False
);
867 sal_Int32 nThumbPos
= m_aVScroll
.GetThumbPos();
869 sal_Int32 nDelta
= m_aVScroll
.GetDelta();
870 m_nYOffset
= -nThumbPos
* m_nRowHeight
;
872 sal_uInt16 nEnd
= (sal_uInt16
)(nThumbPos
+ CalcVisibleLines());
874 m_aLinesPlayground
.Scroll(0, -nDelta
* m_nRowHeight
, SCROLL_CHILDREN
);
878 PositionLine(nEnd
-1);
883 PositionLine((sal_uInt16
)nThumbPos
);
885 else if (nDelta
!=0 || m_aVScroll
.GetType() == SCROLL_DONTKNOW
)
890 m_aLinesPlayground
.EnablePaint(sal_True
);
894 //------------------------------------------------------------------
895 void OBrowserListBox::buttonClicked( OBrowserLine
* _pLine
, sal_Bool _bPrimary
)
897 DBG_ASSERT( _pLine
, "OBrowserListBox::buttonClicked: invalid browser line!" );
898 if ( _pLine
&& m_pLineListener
)
900 m_pLineListener
->Clicked( _pLine
->GetEntryName(), _bPrimary
);
904 //------------------------------------------------------------------
905 void OBrowserListBox::impl_setControlAsPropertyValue( const ListBoxLine
& _rLine
, const Any
& _rPropertyValue
)
907 Reference
< XPropertyControl
> xControl( _rLine
.pLine
->getControl() );
910 if ( _rPropertyValue
.getValueType().equals( _rLine
.pLine
->getControl()->getValueType() ) )
912 xControl
->setValue( _rPropertyValue
);
917 if ( !_rLine
.xHandler
.is() )
919 ::rtl::OString
sMessage( "OBrowserListBox::impl_setControlAsPropertyValue: no handler -> no conversion (property: '" );
920 ::rtl::OUString
sPropertyName( _rLine
.pLine
->GetEntryName() );
921 sMessage
+= ::rtl::OString( sPropertyName
.getStr(), sPropertyName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
922 sMessage
+= ::rtl::OString( "')!" );
923 DBG_ERROR( sMessage
);
926 if ( _rLine
.xHandler
.is() )
928 Any aControlValue
= _rLine
.xHandler
->convertToControlValue(
929 _rLine
.pLine
->GetEntryName(), _rPropertyValue
, xControl
->getValueType() );
930 xControl
->setValue( aControlValue
);
934 catch( const Exception
& )
936 DBG_UNHANDLED_EXCEPTION();
940 //------------------------------------------------------------------
941 Any
OBrowserListBox::impl_getControlAsPropertyValue( const ListBoxLine
& _rLine
) const
943 Reference
< XPropertyControl
> xControl( _rLine
.pLine
->getControl() );
948 if ( !_rLine
.xHandler
.is() )
950 ::rtl::OString
sMessage( "OBrowserListBox::impl_getControlAsPropertyValue: no handler -> no conversion (property: '" );
951 ::rtl::OUString
sPropertyName( _rLine
.pLine
->GetEntryName() );
952 sMessage
+= ::rtl::OString( sPropertyName
.getStr(), sPropertyName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
953 sMessage
+= ::rtl::OString( "')!" );
954 DBG_ERROR( sMessage
);
957 if ( _rLine
.xHandler
.is() )
958 aPropertyValue
= _rLine
.xHandler
->convertToPropertyValue( _rLine
.pLine
->GetEntryName(), xControl
->getValue() );
960 aPropertyValue
= xControl
->getValue();
962 catch( const Exception
& )
964 DBG_UNHANDLED_EXCEPTION();
966 return aPropertyValue
;
969 //------------------------------------------------------------------
970 sal_uInt16
OBrowserListBox::impl_getControlPos( const Reference
< XPropertyControl
>& _rxControl
) const
972 for ( OrderedListBoxLines::const_iterator search
= m_aOrderedLines
.begin();
973 search
!= m_aOrderedLines
.end();
976 if ( (*search
)->second
.pLine
->getControl().get() == _rxControl
.get() )
977 return sal_uInt16( search
- m_aOrderedLines
.begin() );
978 DBG_ERROR( "OBrowserListBox::impl_getControlPos: invalid control - not part of any of our lines!" );
979 return (sal_uInt16
)-1;
982 //--------------------------------------------------------------------
983 void SAL_CALL
OBrowserListBox::focusGained( const Reference
< XPropertyControl
>& _rxControl
) throw (RuntimeException
)
985 DBG_TESTSOLARMUTEX();
987 DBG_ASSERT( _rxControl
.is(), "OBrowserListBox::focusGained: invalid event source!" );
988 if ( !_rxControl
.is() )
991 if ( m_pControlObserver
)
992 m_pControlObserver
->focusGained( _rxControl
);
994 m_xActiveControl
= _rxControl
;
995 ShowEntry( impl_getControlPos( m_xActiveControl
) );
998 //--------------------------------------------------------------------
999 void SAL_CALL
OBrowserListBox::valueChanged( const Reference
< XPropertyControl
>& _rxControl
) throw (RuntimeException
)
1001 DBG_TESTSOLARMUTEX();
1003 DBG_ASSERT( _rxControl
.is(), "OBrowserListBox::valueChanged: invalid event source!" );
1004 if ( !_rxControl
.is() )
1007 if ( m_pControlObserver
)
1008 m_pControlObserver
->valueChanged( _rxControl
);
1010 if ( m_pLineListener
)
1012 const ListBoxLine
& rLine
= impl_getControlLine( _rxControl
);
1013 m_pLineListener
->Commit(
1014 rLine
.pLine
->GetEntryName(),
1015 impl_getControlAsPropertyValue( rLine
)
1020 //--------------------------------------------------------------------
1021 void SAL_CALL
OBrowserListBox::activateNextControl( const Reference
< XPropertyControl
>& _rxCurrentControl
) throw (RuntimeException
)
1023 DBG_TESTSOLARMUTEX();
1025 sal_uInt16 nLine
= impl_getControlPos( _rxCurrentControl
);
1027 // cycle forwards, 'til we've the next control which can grab the focus
1029 while ( (size_t)nLine
< m_aOrderedLines
.size() )
1031 if ( m_aOrderedLines
[nLine
]->second
.pLine
->GrabFocus() )
1036 if ( ( (size_t)nLine
>= m_aOrderedLines
.size() )
1037 && ( m_aOrderedLines
.size() > 0 )
1040 m_aOrderedLines
[0]->second
.pLine
->GrabFocus();
1043 //------------------------------------------------------------------
1046 //..............................................................
1047 void lcl_implDisposeControl_nothrow( const Reference
< XPropertyControl
>& _rxControl
)
1049 if ( !_rxControl
.is() )
1053 _rxControl
->setControlContext( NULL
);
1054 Reference
< XComponent
> xControlComponent( _rxControl
, UNO_QUERY
);
1055 if ( xControlComponent
.is() )
1056 xControlComponent
->dispose();
1058 catch( const Exception
& )
1060 DBG_UNHANDLED_EXCEPTION();
1065 //------------------------------------------------------------------
1066 void OBrowserListBox::Clear()
1068 for ( ListBoxLines::iterator loop
= m_aLines
.begin();
1069 loop
!= m_aLines
.end();
1074 loop
->second
.pLine
->Hide();
1075 // reset the listener
1076 lcl_implDisposeControl_nothrow( loop
->second
.pLine
->getControl() );
1079 clearContainer( m_aLines
);
1080 clearContainer( m_aOrderedLines
);
1083 //------------------------------------------------------------------
1084 sal_Bool
OBrowserListBox::RemoveEntry( const ::rtl::OUString
& _rName
)
1086 sal_uInt16 nPos
= GetPropertyPos( _rName
);
1087 if ( nPos
== LISTBOX_ENTRY_NOTFOUND
)
1090 OrderedListBoxLines::iterator orderedPos
= m_aOrderedLines
.begin() + nPos
;
1091 BrowserLinePointer pLine
= (*orderedPos
)->second
.pLine
;
1093 lcl_implDisposeControl_nothrow( pLine
->getControl() );
1095 m_aLines
.erase( *orderedPos
);
1096 m_aOrderedLines
.erase( orderedPos
);
1097 m_aOutOfDateLines
.erase( (sal_uInt16
)m_aOrderedLines
.size() );
1098 // this index *may* have been out of date, which is obsoleted now by m_aOrderedLines shrinking
1100 // update the positions of possibly affected lines
1101 while ( nPos
< m_aOrderedLines
.size() )
1102 m_aOutOfDateLines
.insert( nPos
++ );
1108 //------------------------------------------------------------------
1109 void OBrowserListBox::ChangeEntry( const OLineDescriptor
& _rPropertyData
, sal_uInt16 nPos
)
1111 OSL_PRECOND( _rPropertyData
.Control
.is(), "OBrowserListBox::ChangeEntry: invalid control!" );
1112 if ( !_rPropertyData
.Control
.is() )
1115 if ( nPos
== EDITOR_LIST_REPLACE_EXISTING
)
1116 nPos
= GetPropertyPos( _rPropertyData
.sName
);
1118 if ( nPos
< m_aOrderedLines
.size() )
1120 Window
* pRefWindow
= NULL
;
1122 pRefWindow
= m_aOrderedLines
[nPos
-1]->second
.pLine
->GetRefWindow();
1124 // the current line and control
1125 ListBoxLine
& rLine
= m_aOrderedLines
[nPos
]->second
;
1127 // the old control and some data about it
1128 Reference
< XPropertyControl
> xControl
= rLine
.pLine
->getControl();
1129 Window
* pControlWindow
= rLine
.pLine
->getControlWindow();
1131 if ( pControlWindow
)
1132 aControlPos
= pControlWindow
->GetPosPixel();
1134 // clean up the old control
1135 lcl_implDisposeControl_nothrow( xControl
);
1137 // set the new control at the line
1138 rLine
.pLine
->setControl( _rPropertyData
.Control
);
1139 xControl
= rLine
.pLine
->getControl();
1141 if ( xControl
.is() )
1142 xControl
->setControlContext( m_pControlContextImpl
.get() );
1144 // the initial property value
1145 if ( _rPropertyData
.bUnknownValue
)
1146 xControl
->setValue( Any() );
1148 impl_setControlAsPropertyValue( rLine
, _rPropertyData
.aValue
);
1150 rLine
.pLine
->SetTitle(_rPropertyData
.DisplayName
);
1151 rLine
.xHandler
= _rPropertyData
.xPropertyHandler
;
1153 sal_uInt16 nTextWidth
= (sal_uInt16
)m_aLinesPlayground
.GetTextWidth(_rPropertyData
.DisplayName
);
1154 if (m_nTheNameSize
< nTextWidth
)
1155 m_nTheNameSize
= nTextWidth
;
1157 if ( _rPropertyData
.HasPrimaryButton
)
1159 if ( _rPropertyData
.PrimaryButtonImageURL
.getLength() )
1160 rLine
.pLine
->ShowBrowseButton( _rPropertyData
.PrimaryButtonImageURL
, true );
1161 else if ( _rPropertyData
.PrimaryButtonImage
.is() )
1162 rLine
.pLine
->ShowBrowseButton( Image( _rPropertyData
.PrimaryButtonImage
), true );
1164 rLine
.pLine
->ShowBrowseButton( true );
1166 if ( _rPropertyData
.HasSecondaryButton
)
1168 if ( _rPropertyData
.SecondaryButtonImageURL
.getLength() )
1169 rLine
.pLine
->ShowBrowseButton( _rPropertyData
.SecondaryButtonImageURL
, false );
1170 else if ( _rPropertyData
.SecondaryButtonImage
.is() )
1171 rLine
.pLine
->ShowBrowseButton( Image( _rPropertyData
.SecondaryButtonImage
), false );
1173 rLine
.pLine
->ShowBrowseButton( false );
1176 rLine
.pLine
->HideBrowseButton( false );
1178 rLine
.pLine
->SetClickListener( this );
1182 rLine
.pLine
->HideBrowseButton( true );
1183 rLine
.pLine
->HideBrowseButton( false );
1186 DBG_ASSERT( ( _rPropertyData
.IndentLevel
== 0 ) || ( _rPropertyData
.IndentLevel
== 1 ),
1187 "OBrowserListBox::ChangeEntry: unsupported indent level!" );
1188 rLine
.pLine
->IndentTitle( _rPropertyData
.IndentLevel
> 0 );
1191 rLine
.pLine
->SetTabOrder( pRefWindow
, WINDOW_ZORDER_BEHIND
);
1193 rLine
.pLine
->SetTabOrder( pRefWindow
, WINDOW_ZORDER_FIRST
);
1195 m_aOutOfDateLines
.insert( nPos
);
1196 rLine
.pLine
->SetComponentHelpIds(
1197 HelpIdUrl::getHelpId( _rPropertyData
.HelpURL
),
1198 _rPropertyData
.PrimaryButtonId
,
1199 _rPropertyData
.SecondaryButtonId
1202 if ( _rPropertyData
.bReadOnly
)
1204 rLine
.pLine
->SetReadOnly( true );
1206 // user controls (i.e. the ones not provided by the usual
1207 // XPropertyControlFactory) have no chance to know that they should be read-only,
1208 // since XPropertyHandler::describePropertyLine does not transport this
1210 // So, we manually switch this to read-only.
1211 if ( xControl
.is() && ( xControl
->getControlType() == PropertyControlType::Unknown
) )
1213 Edit
* pControlWindowAsEdit
= dynamic_cast< Edit
* >( rLine
.pLine
->getControlWindow() );
1214 if ( pControlWindowAsEdit
)
1215 pControlWindowAsEdit
->SetReadOnly( TRUE
);
1217 pControlWindowAsEdit
->Enable( FALSE
);
1223 //------------------------------------------------------------------
1224 long OBrowserListBox::PreNotify( NotifyEvent
& _rNEvt
)
1226 switch ( _rNEvt
.GetType() )
1228 case EVENT_KEYINPUT
:
1230 const KeyEvent
* pKeyEvent
= _rNEvt
.GetKeyEvent();
1231 if ( ( pKeyEvent
->GetKeyCode().GetModifier() != 0 )
1232 || ( ( pKeyEvent
->GetKeyCode().GetCode() != KEY_PAGEUP
)
1233 && ( pKeyEvent
->GetKeyCode().GetCode() != KEY_PAGEDOWN
)
1238 long nScrollOffset
= 0;
1239 if ( m_aVScroll
.IsVisible() )
1241 if ( pKeyEvent
->GetKeyCode().GetCode() == KEY_PAGEUP
)
1242 nScrollOffset
= -m_aVScroll
.GetPageSize();
1243 else if ( pKeyEvent
->GetKeyCode().GetCode() == KEY_PAGEDOWN
)
1244 nScrollOffset
= m_aVScroll
.GetPageSize();
1247 if ( nScrollOffset
)
1249 long nNewThumbPos
= m_aVScroll
.GetThumbPos() + nScrollOffset
;
1250 nNewThumbPos
= ::std::max( nNewThumbPos
, m_aVScroll
.GetRangeMin() );
1251 nNewThumbPos
= ::std::min( nNewThumbPos
, m_aVScroll
.GetRangeMax() );
1252 m_aVScroll
.DoScroll( nNewThumbPos
);
1253 nNewThumbPos
= m_aVScroll
.GetThumbPos();
1255 sal_uInt16 nFocusControlPos
= 0;
1256 sal_uInt16 nActiveControlPos
= impl_getControlPos( m_xActiveControl
);
1257 if ( nActiveControlPos
< nNewThumbPos
)
1258 nFocusControlPos
= (sal_uInt16
)nNewThumbPos
;
1259 else if ( nActiveControlPos
>= nNewThumbPos
+ CalcVisibleLines() )
1260 nFocusControlPos
= (sal_uInt16
)nNewThumbPos
+ CalcVisibleLines() - 1;
1261 if ( nFocusControlPos
)
1263 if ( nFocusControlPos
< m_aOrderedLines
.size() )
1265 m_aOrderedLines
[ nFocusControlPos
]->second
.pLine
->GrabFocus();
1268 OSL_ENSURE( false, "OBrowserListBox::PreNotify: internal error, invalid focus control position!" );
1273 // handled this. In particular, we also consume PageUp/Down events if we do not use them for scrolling,
1274 // otherwise they would be used to scroll the document view, which does not sound like it is desired by
1278 return Control::PreNotify( _rNEvt
);
1281 //------------------------------------------------------------------
1282 long OBrowserListBox::Notify( NotifyEvent
& _rNEvt
)
1284 switch ( _rNEvt
.GetType() )
1288 const CommandEvent
* pCommand
= _rNEvt
.GetCommandEvent();
1289 if ( ( COMMAND_WHEEL
== pCommand
->GetCommand() )
1290 || ( COMMAND_STARTAUTOSCROLL
== pCommand
->GetCommand() )
1291 || ( COMMAND_AUTOSCROLL
== pCommand
->GetCommand() )
1294 // interested in scroll events if we have a scrollbar
1295 if ( m_aVScroll
.IsVisible() )
1297 HandleScrollCommand( *pCommand
, NULL
, &m_aVScroll
);
1304 return Control::Notify( _rNEvt
);
1307 //............................................................................
1309 //............................................................................
1312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */