Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "browserlistbox.hxx"
30 : : #include "propresid.hrc"
31 : : #include "proplinelistener.hxx"
32 : : #include "propcontrolobserver.hxx"
33 : : #include "linedescriptor.hxx"
34 : : #include "inspectorhelpwindow.hxx"
35 : :
36 : : #include <com/sun/star/lang/DisposedException.hpp>
37 : : #include <com/sun/star/lang/XComponent.hpp>
38 : : #include <com/sun/star/inspection/PropertyControlType.hpp>
39 : : #include <tools/debug.hxx>
40 : : #include <tools/diagnose_ex.h>
41 : : #include <comphelper/asyncnotification.hxx>
42 : : #include <cppuhelper/implbase1.hxx>
43 : : #include <vcl/svapp.hxx>
44 : : #include <osl/mutex.hxx>
45 : :
46 : : //............................................................................
47 : : namespace pcr
48 : : {
49 : : //............................................................................
50 : :
51 : : #define FRAME_OFFSET 4
52 : : // TODO: find out what this is really for ... and check if it does make sense in the new
53 : : // browser environment
54 : : #define LAYOUT_HELP_WINDOW_DISTANCE_APPFONT 3
55 : :
56 : : /** === begin UNO using === **/
57 : : using ::com::sun::star::uno::Any;
58 : : using ::com::sun::star::uno::Exception;
59 : : using ::com::sun::star::inspection::XPropertyControlContext;
60 : : using ::com::sun::star::uno::Reference;
61 : : using ::com::sun::star::inspection::XPropertyControl;
62 : : using ::com::sun::star::uno::RuntimeException;
63 : : using ::com::sun::star::lang::DisposedException;
64 : : using ::com::sun::star::lang::XComponent;
65 : : using ::com::sun::star::uno::UNO_QUERY;
66 : : using ::com::sun::star::graphic::XGraphic;
67 : : /** === end UNO using === **/
68 : : namespace PropertyControlType = ::com::sun::star::inspection::PropertyControlType;
69 : :
70 : : //==================================================================
71 : : //= ControlEvent
72 : : //==================================================================
73 : : enum ControlEventType
74 : : {
75 : : FOCUS_GAINED,
76 : : VALUE_CHANGED,
77 : : ACTIVATE_NEXT
78 : : };
79 : :
80 : 0 : struct ControlEvent : public ::comphelper::AnyEvent
81 : : {
82 : : Reference< XPropertyControl > xControl;
83 : : ControlEventType eType;
84 : :
85 : 0 : ControlEvent( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType )
86 : : :xControl( _rxControl )
87 : 0 : ,eType( _eType )
88 : : {
89 : 0 : }
90 : : };
91 : :
92 : : //==================================================================
93 : : //= SharedNotifier
94 : : //==================================================================
95 : : class SharedNotifier
96 : : {
97 : : private:
98 : : static ::osl::Mutex& getMutex();
99 : : static ::rtl::Reference< ::comphelper::AsyncEventNotifier > s_pNotifier;
100 : :
101 : : public:
102 : : static const ::rtl::Reference< ::comphelper::AsyncEventNotifier >&
103 : : getNotifier();
104 : :
105 : : private:
106 : : SharedNotifier(); // never implemented
107 : : SharedNotifier( const SharedNotifier& ); // never implemented
108 : : SharedNotifier& operator=( const SharedNotifier& ); // never implemented
109 : : };
110 : :
111 : : //------------------------------------------------------------------
112 : 0 : ::rtl::Reference< ::comphelper::AsyncEventNotifier > SharedNotifier::s_pNotifier;
113 : :
114 : : //------------------------------------------------------------------
115 : 0 : ::osl::Mutex& SharedNotifier::getMutex()
116 : : {
117 : 0 : static ::osl::Mutex s_aMutex;
118 : 0 : return s_aMutex;
119 : : }
120 : :
121 : : //------------------------------------------------------------------
122 : 0 : const ::rtl::Reference< ::comphelper::AsyncEventNotifier >& SharedNotifier::getNotifier()
123 : : {
124 : 0 : ::osl::MutexGuard aGuard( getMutex() );
125 : 0 : if ( !s_pNotifier.is() )
126 : : {
127 : : s_pNotifier.set(
128 : 0 : new ::comphelper::AsyncEventNotifier("browserlistbox"));
129 : 0 : s_pNotifier->launch();
130 : : //TODO: a protocol is missing how to join with the launched
131 : : // thread before exit(3), to ensure the thread is no longer
132 : : // relying on any infrastructure while that infrastructure is
133 : : // being shut down in atexit handlers
134 : : }
135 : 0 : return s_pNotifier;
136 : : }
137 : :
138 : : //==================================================================
139 : : //= PropertyControlContext_Impl
140 : : //==================================================================
141 : : /** implementation for of <type scope="com::sun::star::inspection">XPropertyControlContext</type>
142 : : which forwards all events to a non-UNO version of this interface
143 : : */
144 : : typedef ::cppu::WeakImplHelper1< XPropertyControlContext > PropertyControlContext_Impl_Base;
145 : : class PropertyControlContext_Impl :public PropertyControlContext_Impl_Base
146 : : ,public ::comphelper::IEventProcessor
147 : : {
148 : : public:
149 : : enum NotifcationMode
150 : : {
151 : : eSynchronously,
152 : : eAsynchronously
153 : : };
154 : :
155 : : private:
156 : : IControlContext* m_pContext;
157 : : NotifcationMode m_eMode;
158 : :
159 : : public:
160 : : /** creates an instance
161 : : @param _rContextImpl
162 : : the instance to delegate events to
163 : : */
164 : : PropertyControlContext_Impl( IControlContext& _rContextImpl );
165 : :
166 : : /** disposes the context.
167 : :
168 : : When you call this method, all subsequent callbacks to the
169 : : <type scope="com::sun::star::inspection">XPropertyControlContext</type> methods
170 : : will throw a <type scope="com::sun::star::lang">DisposedException</type>.
171 : : */
172 : : void SAL_CALL dispose();
173 : :
174 : : /** sets the notification mode, so that notifications recieved from the controls are
175 : : forwarded to our IControlContext either synchronously or asynchronously
176 : : @param _eMode
177 : : the new notification mode
178 : : */
179 : : void setNotificationMode( NotifcationMode _eMode );
180 : :
181 : : virtual void SAL_CALL acquire() throw();
182 : : virtual void SAL_CALL release() throw();
183 : :
184 : : protected:
185 : : ~PropertyControlContext_Impl();
186 : :
187 : : // XPropertyControlObserver
188 : : virtual void SAL_CALL focusGained( const Reference< XPropertyControl >& Control ) throw (RuntimeException);
189 : : virtual void SAL_CALL valueChanged( const Reference< XPropertyControl >& Control ) throw (RuntimeException);
190 : : // XPropertyControlContext
191 : : virtual void SAL_CALL activateNextControl( const Reference< XPropertyControl >& CurrentControl ) throw (RuntimeException);
192 : :
193 : : // IEventProcessor
194 : : virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
195 : :
196 : : private:
197 : : /** processes the given event, i.e. notifies it to our IControlContext
198 : : @param _rEvent
199 : : the event no notify
200 : : @precond
201 : : our mutex (well, the SolarMutex) is locked
202 : : */
203 : : void impl_processEvent_throw( const ::comphelper::AnyEvent& _rEvent );
204 : :
205 : : /** checks whether we're alive
206 : :
207 : : @throws DisposedException
208 : : if the instance is already disposed
209 : : */
210 : : void impl_checkAlive_throw() const;
211 : :
212 : : /** checks whether the instance is already disposed
213 : : */
214 : 0 : bool impl_isDisposed_nothrow() const { return m_pContext == NULL; }
215 : :
216 : : /** notifies the given event originating from the given control
217 : : @throws DisposedException
218 : : @param _rxControl
219 : : @param _eType
220 : : */
221 : : void impl_notify_throw( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType );
222 : : };
223 : :
224 : : //--------------------------------------------------------------------
225 : 0 : PropertyControlContext_Impl::PropertyControlContext_Impl( IControlContext& _rContextImpl )
226 : : :m_pContext( &_rContextImpl )
227 : 0 : ,m_eMode( eAsynchronously )
228 : : {
229 : 0 : }
230 : :
231 : : //--------------------------------------------------------------------
232 : 0 : PropertyControlContext_Impl::~PropertyControlContext_Impl()
233 : : {
234 : 0 : if ( !impl_isDisposed_nothrow() )
235 : 0 : dispose();
236 : 0 : }
237 : :
238 : : //--------------------------------------------------------------------
239 : 0 : void PropertyControlContext_Impl::impl_checkAlive_throw() const
240 : : {
241 : 0 : if ( impl_isDisposed_nothrow() )
242 : 0 : throw DisposedException( ::rtl::OUString(), *const_cast< PropertyControlContext_Impl* >( this ) );
243 : 0 : }
244 : :
245 : : //--------------------------------------------------------------------
246 : 0 : void SAL_CALL PropertyControlContext_Impl::dispose()
247 : : {
248 : 0 : SolarMutexGuard aGuard;
249 : 0 : if ( impl_isDisposed_nothrow() )
250 : 0 : return;
251 : :
252 : 0 : SharedNotifier::getNotifier()->removeEventsForProcessor( this );
253 : 0 : m_pContext = NULL;
254 : : }
255 : :
256 : : //--------------------------------------------------------------------
257 : 0 : void PropertyControlContext_Impl::setNotificationMode( NotifcationMode _eMode )
258 : : {
259 : 0 : SolarMutexGuard aGuard;
260 : 0 : m_eMode = _eMode;
261 : 0 : }
262 : :
263 : : //--------------------------------------------------------------------
264 : 0 : void PropertyControlContext_Impl::impl_notify_throw( const Reference< XPropertyControl >& _rxControl, ControlEventType _eType )
265 : : {
266 : 0 : ::comphelper::AnyEventRef pEvent;
267 : :
268 : : {
269 : 0 : SolarMutexGuard aGuard;
270 : 0 : impl_checkAlive_throw();
271 : 0 : pEvent = new ControlEvent( _rxControl, _eType );
272 : :
273 : 0 : if ( m_eMode == eSynchronously )
274 : : {
275 : 0 : impl_processEvent_throw( *pEvent );
276 : 0 : return;
277 : 0 : }
278 : : }
279 : :
280 : 0 : SharedNotifier::getNotifier()->addEvent( pEvent, this );
281 : : }
282 : :
283 : : //--------------------------------------------------------------------
284 : 0 : void SAL_CALL PropertyControlContext_Impl::focusGained( const Reference< XPropertyControl >& Control ) throw (RuntimeException)
285 : : {
286 : : OSL_TRACE( "PropertyControlContext_Impl: FOCUS_GAINED" );
287 : 0 : impl_notify_throw( Control, FOCUS_GAINED );
288 : 0 : }
289 : :
290 : : //--------------------------------------------------------------------
291 : 0 : void SAL_CALL PropertyControlContext_Impl::valueChanged( const Reference< XPropertyControl >& Control ) throw (RuntimeException)
292 : : {
293 : : OSL_TRACE( "PropertyControlContext_Impl: VALUE_CHANGED" );
294 : 0 : impl_notify_throw( Control, VALUE_CHANGED );
295 : 0 : }
296 : :
297 : : //--------------------------------------------------------------------
298 : 0 : void SAL_CALL PropertyControlContext_Impl::activateNextControl( const Reference< XPropertyControl >& CurrentControl ) throw (RuntimeException)
299 : : {
300 : : OSL_TRACE( "PropertyControlContext_Impl: ACTIVATE_NEXT" );
301 : 0 : impl_notify_throw( CurrentControl, ACTIVATE_NEXT );
302 : 0 : }
303 : :
304 : : //--------------------------------------------------------------------
305 : 0 : void SAL_CALL PropertyControlContext_Impl::acquire() throw()
306 : : {
307 : 0 : PropertyControlContext_Impl_Base::acquire();
308 : 0 : }
309 : :
310 : : //--------------------------------------------------------------------
311 : 0 : void SAL_CALL PropertyControlContext_Impl::release() throw()
312 : : {
313 : 0 : PropertyControlContext_Impl_Base::release();
314 : 0 : }
315 : :
316 : : //--------------------------------------------------------------------
317 : 0 : void PropertyControlContext_Impl::processEvent( const ::comphelper::AnyEvent& _rEvent )
318 : : {
319 : 0 : SolarMutexGuard aGuard;
320 : 0 : if ( impl_isDisposed_nothrow() )
321 : 0 : return;
322 : :
323 : : try
324 : : {
325 : 0 : impl_processEvent_throw( _rEvent );
326 : : }
327 : 0 : catch( const Exception& )
328 : : {
329 : : // can't handle otherwise, since our caller (the notification thread) does not allow
330 : : // for exceptions (it could itself abort only)
331 : : DBG_UNHANDLED_EXCEPTION();
332 : 0 : }
333 : : }
334 : :
335 : : //--------------------------------------------------------------------
336 : 0 : void PropertyControlContext_Impl::impl_processEvent_throw( const ::comphelper::AnyEvent& _rEvent )
337 : : {
338 : 0 : const ControlEvent& rControlEvent = static_cast< const ControlEvent& >( _rEvent );
339 : 0 : switch ( rControlEvent.eType )
340 : : {
341 : : case FOCUS_GAINED:
342 : : OSL_TRACE( "PropertyControlContext_Impl::processEvent: FOCUS_GAINED" );
343 : 0 : m_pContext->focusGained( rControlEvent.xControl );
344 : 0 : break;
345 : : case VALUE_CHANGED:
346 : : OSL_TRACE( "PropertyControlContext_Impl::processEvent: VALUE_CHANGED" );
347 : 0 : m_pContext->valueChanged( rControlEvent.xControl );
348 : 0 : break;
349 : : case ACTIVATE_NEXT:
350 : : OSL_TRACE( "PropertyControlContext_Impl::processEvent: ACTIVATE_NEXT" );
351 : 0 : m_pContext->activateNextControl( rControlEvent.xControl );
352 : 0 : break;
353 : : }
354 : 0 : }
355 : :
356 : : //==================================================================
357 : : //= OBrowserListBox
358 : : //==================================================================
359 : : DBG_NAME(OBrowserListBox)
360 : : //------------------------------------------------------------------
361 : 0 : OBrowserListBox::OBrowserListBox( Window* pParent, WinBits nWinStyle)
362 : : :Control(pParent, nWinStyle| WB_CLIPCHILDREN)
363 : : ,m_aLinesPlayground(this,WB_DIALOGCONTROL | WB_CLIPCHILDREN)
364 : : ,m_aVScroll(this,WB_VSCROLL|WB_REPEAT|WB_DRAG)
365 : 0 : ,m_pHelpWindow( new InspectorHelpWindow( this ) )
366 : : ,m_pLineListener(NULL)
367 : : ,m_pControlObserver( NULL )
368 : : ,m_nYOffset(0)
369 : : ,m_nCurrentPreferredHelpHeight(0)
370 : : ,m_nTheNameSize(0)
371 : : ,m_bIsActive(sal_False)
372 : : ,m_bUpdate(sal_True)
373 : 0 : ,m_pControlContextImpl( new PropertyControlContext_Impl( *this ) )
374 : : {
375 : : DBG_CTOR(OBrowserListBox,NULL);
376 : :
377 : 0 : ListBox aListBox(this,WB_DROPDOWN);
378 : 0 : aListBox.SetPosSizePixel(Point(0,0),Size(100,100));
379 : 0 : m_nRowHeight = (sal_uInt16)aListBox.GetSizePixel().Height()+2;
380 : 0 : SetBackground( pParent->GetBackground() );
381 : 0 : m_aLinesPlayground.SetBackground( GetBackground() );
382 : :
383 : 0 : m_aLinesPlayground.SetPosPixel(Point(0,0));
384 : 0 : m_aLinesPlayground.SetPaintTransparent(sal_True);
385 : 0 : m_aLinesPlayground.Show();
386 : 0 : m_aVScroll.Hide();
387 : 0 : m_aVScroll.SetScrollHdl(LINK(this, OBrowserListBox, ScrollHdl));
388 : 0 : }
389 : :
390 : : //------------------------------------------------------------------
391 : 0 : OBrowserListBox::~OBrowserListBox()
392 : : {
393 : : OSL_ENSURE( !IsModified(), "OBrowserListBox::~OBrowserListBox: still modified - should have been committed before!" );
394 : : // doing the commit here, while we, as well as our owner, as well as some other components,
395 : : // are already "half dead" (means within their dtor) is potentially dangerous.
396 : : // By definition, CommitModified has to be called (if necessary) before destruction
397 : :
398 : 0 : m_pControlContextImpl->dispose();
399 : 0 : m_pControlContextImpl.clear();
400 : :
401 : 0 : Hide();
402 : 0 : Clear();
403 : :
404 : : DBG_DTOR(OBrowserListBox,NULL);
405 : 0 : }
406 : :
407 : : //------------------------------------------------------------------
408 : 0 : sal_Bool OBrowserListBox::IsModified( ) const
409 : : {
410 : 0 : sal_Bool bModified = sal_False;
411 : :
412 : 0 : if ( m_bIsActive && m_xActiveControl.is() )
413 : 0 : bModified = m_xActiveControl->isModified();
414 : :
415 : 0 : return bModified;
416 : : }
417 : :
418 : : //------------------------------------------------------------------
419 : 0 : void OBrowserListBox::CommitModified( )
420 : : {
421 : 0 : if ( IsModified() && m_xActiveControl.is() )
422 : : {
423 : : // for the time of this commit, notify all events synchronously
424 : : // #i63814#
425 : 0 : m_pControlContextImpl->setNotificationMode( PropertyControlContext_Impl::eSynchronously );
426 : : try
427 : : {
428 : 0 : m_xActiveControl->notifyModifiedValue();
429 : : }
430 : 0 : catch( const Exception& )
431 : : {
432 : : DBG_UNHANDLED_EXCEPTION();
433 : : }
434 : 0 : m_pControlContextImpl->setNotificationMode( PropertyControlContext_Impl::eAsynchronously );
435 : : }
436 : 0 : }
437 : :
438 : : //------------------------------------------------------------------
439 : 0 : void OBrowserListBox::ActivateListBox(sal_Bool _bActive)
440 : : {
441 : 0 : m_bIsActive = _bActive;
442 : 0 : if (m_bIsActive)
443 : : {
444 : : // TODO: what's the sense of this?
445 : 0 : m_aVScroll.SetThumbPos(100);
446 : 0 : MoveThumbTo(0);
447 : 0 : Resize();
448 : : }
449 : 0 : }
450 : :
451 : : //------------------------------------------------------------------
452 : 0 : long OBrowserListBox::impl_getPrefererredHelpHeight()
453 : : {
454 : 0 : return HasHelpSection() ? m_pHelpWindow->GetOptimalHeightPixel() : 0;
455 : : }
456 : :
457 : : //------------------------------------------------------------------
458 : 0 : void OBrowserListBox::Resize()
459 : : {
460 : 0 : Rectangle aPlayground( Point( 0, 0 ), GetOutputSizePixel() );
461 : 0 : Size aHelpWindowDistance( LogicToPixel( Size( 0, LAYOUT_HELP_WINDOW_DISTANCE_APPFONT ), MAP_APPFONT ) );
462 : :
463 : 0 : long nHelpWindowHeight = m_nCurrentPreferredHelpHeight = impl_getPrefererredHelpHeight();
464 : 0 : bool bPositionHelpWindow = ( nHelpWindowHeight != 0 );
465 : :
466 : 0 : Rectangle aLinesArea( aPlayground );
467 : 0 : if ( bPositionHelpWindow )
468 : : {
469 : 0 : aLinesArea.Bottom() -= nHelpWindowHeight;
470 : 0 : aLinesArea.Bottom() -= aHelpWindowDistance.Height();
471 : : }
472 : 0 : m_aLinesPlayground.SetPosSizePixel( aLinesArea.TopLeft(), aLinesArea.GetSize() );
473 : :
474 : 0 : UpdateVScroll();
475 : :
476 : 0 : sal_Bool bNeedScrollbar = m_aLines.size() > (sal_uInt32)CalcVisibleLines();
477 : 0 : if ( !bNeedScrollbar )
478 : : {
479 : 0 : if ( m_aVScroll.IsVisible() )
480 : 0 : m_aVScroll.Hide();
481 : : // scroll to top
482 : 0 : m_nYOffset = 0;
483 : 0 : m_aVScroll.SetThumbPos( 0 );
484 : : }
485 : : else
486 : : {
487 : 0 : Size aVScrollSize( m_aVScroll.GetSizePixel() );
488 : :
489 : : // adjust the playground's width
490 : 0 : aLinesArea.Right() -= aVScrollSize.Width();
491 : 0 : m_aLinesPlayground.SetPosSizePixel( aLinesArea.TopLeft(), aLinesArea.GetSize() );
492 : :
493 : : // position the scrollbar
494 : 0 : aVScrollSize.Height() = aLinesArea.GetHeight();
495 : 0 : Point aVScrollPos( aLinesArea.GetWidth(), 0 );
496 : 0 : m_aVScroll.SetPosSizePixel( aVScrollPos, aVScrollSize );
497 : : }
498 : :
499 : 0 : for ( sal_uInt16 i = 0; i < m_aLines.size(); ++i )
500 : 0 : m_aOutOfDateLines.insert( i );
501 : :
502 : : // repaint
503 : 0 : EnablePaint(sal_False);
504 : 0 : UpdatePlayGround();
505 : 0 : EnablePaint(sal_True);
506 : :
507 : : // show the scrollbar
508 : 0 : if ( bNeedScrollbar )
509 : 0 : m_aVScroll.Show();
510 : :
511 : : // position the help window
512 : 0 : if ( bPositionHelpWindow )
513 : : {
514 : 0 : Rectangle aHelpArea( aPlayground );
515 : 0 : aHelpArea.Top() = aLinesArea.Bottom() + aHelpWindowDistance.Height();
516 : 0 : m_pHelpWindow->SetPosSizePixel( aHelpArea.TopLeft(), aHelpArea.GetSize() );
517 : : }
518 : 0 : }
519 : :
520 : : //------------------------------------------------------------------
521 : 0 : void OBrowserListBox::SetListener( IPropertyLineListener* _pListener )
522 : : {
523 : 0 : m_pLineListener = _pListener;
524 : 0 : }
525 : :
526 : : //------------------------------------------------------------------
527 : 0 : void OBrowserListBox::SetObserver( IPropertyControlObserver* _pObserver )
528 : : {
529 : 0 : m_pControlObserver = _pObserver;
530 : 0 : }
531 : :
532 : : //------------------------------------------------------------------
533 : 0 : void OBrowserListBox::EnableHelpSection( bool _bEnable )
534 : : {
535 : 0 : m_pHelpWindow->Show( _bEnable );
536 : 0 : Resize();
537 : 0 : }
538 : :
539 : : //------------------------------------------------------------------
540 : 0 : bool OBrowserListBox::HasHelpSection() const
541 : : {
542 : 0 : return m_pHelpWindow->IsVisible();
543 : : }
544 : :
545 : : //------------------------------------------------------------------
546 : 0 : void OBrowserListBox::SetHelpText( const ::rtl::OUString& _rHelpText )
547 : : {
548 : : OSL_ENSURE( HasHelpSection(), "OBrowserListBox::SetHelpText: help section not visible!" );
549 : 0 : m_pHelpWindow->SetText( _rHelpText );
550 : 0 : if ( m_nCurrentPreferredHelpHeight != impl_getPrefererredHelpHeight() )
551 : 0 : Resize();
552 : 0 : }
553 : :
554 : : //------------------------------------------------------------------
555 : 0 : void OBrowserListBox::SetHelpLineLimites( sal_Int32 _nMinLines, sal_Int32 _nMaxLines )
556 : : {
557 : 0 : m_pHelpWindow->SetLimits( _nMinLines, _nMaxLines );
558 : 0 : }
559 : :
560 : : //------------------------------------------------------------------
561 : 0 : sal_uInt16 OBrowserListBox::CalcVisibleLines()
562 : : {
563 : 0 : Size aSize(m_aLinesPlayground.GetOutputSizePixel());
564 : 0 : sal_uInt16 nResult = 0;
565 : 0 : if (0 != m_nRowHeight)
566 : 0 : nResult = (sal_uInt16) aSize.Height()/m_nRowHeight;
567 : :
568 : 0 : return nResult;
569 : : }
570 : :
571 : : //------------------------------------------------------------------
572 : 0 : void OBrowserListBox::UpdateVScroll()
573 : : {
574 : 0 : sal_uInt16 nLines = CalcVisibleLines();
575 : 0 : m_aVScroll.SetPageSize(nLines-1);
576 : 0 : m_aVScroll.SetVisibleSize(nLines-1);
577 : :
578 : 0 : size_t nCount = m_aLines.size();
579 : 0 : if (nCount>0)
580 : : {
581 : 0 : m_aVScroll.SetRange(Range(0,nCount-1));
582 : 0 : m_nYOffset = -m_aVScroll.GetThumbPos()*m_nRowHeight;
583 : : }
584 : : else
585 : : {
586 : 0 : m_aVScroll.SetRange(Range(0,0));
587 : 0 : m_nYOffset = 0;
588 : : }
589 : 0 : }
590 : :
591 : : //------------------------------------------------------------------
592 : 0 : void OBrowserListBox::PositionLine( sal_uInt16 _nIndex )
593 : : {
594 : 0 : Size aSize(m_aLinesPlayground.GetOutputSizePixel());
595 : 0 : Point aPos(0, m_nYOffset);
596 : :
597 : 0 : aSize.Height() = m_nRowHeight;
598 : :
599 : 0 : aPos.Y() += _nIndex * m_nRowHeight;
600 : :
601 : 0 : if ( _nIndex < m_aLines.size() )
602 : : {
603 : 0 : BrowserLinePointer pLine = m_aLines[ _nIndex ].pLine;
604 : :
605 : 0 : pLine->SetPosSizePixel( aPos, aSize );
606 : 0 : pLine->SetTitleWidth( m_nTheNameSize + 2 * FRAME_OFFSET );
607 : :
608 : : // show the line if necessary
609 : 0 : if ( !pLine->IsVisible() )
610 : 0 : pLine->Show();
611 : : }
612 : 0 : }
613 : :
614 : : //------------------------------------------------------------------
615 : 0 : void OBrowserListBox::UpdatePosNSize()
616 : : {
617 : 0 : for ( ::std::set< sal_uInt16 >::const_iterator aLoop = m_aOutOfDateLines.begin();
618 : 0 : aLoop != m_aOutOfDateLines.end();
619 : : ++aLoop
620 : : )
621 : : {
622 : : DBG_ASSERT( *aLoop < m_aLines.size(), "OBrowserListBox::UpdatePosNSize: invalid line index!" );
623 : 0 : if ( *aLoop < m_aLines.size() )
624 : 0 : PositionLine( *aLoop );
625 : : }
626 : 0 : m_aOutOfDateLines.clear();
627 : 0 : }
628 : :
629 : : //------------------------------------------------------------------
630 : 0 : void OBrowserListBox::UpdatePlayGround()
631 : : {
632 : 0 : sal_Int32 nThumbPos = m_aVScroll.GetThumbPos();
633 : 0 : sal_Int32 nLines = CalcVisibleLines();
634 : :
635 : 0 : sal_uInt16 nEnd = (sal_uInt16)(nThumbPos + nLines);
636 : 0 : if (nEnd >= m_aLines.size())
637 : 0 : nEnd = (sal_uInt16)m_aLines.size()-1;
638 : :
639 : 0 : if ( !m_aLines.empty() )
640 : : {
641 : 0 : for ( sal_uInt16 i = (sal_uInt16)nThumbPos; i <= nEnd; ++i )
642 : 0 : m_aOutOfDateLines.insert( i );
643 : 0 : UpdatePosNSize();
644 : : }
645 : 0 : }
646 : :
647 : : //------------------------------------------------------------------
648 : 0 : void OBrowserListBox::UpdateAll()
649 : : {
650 : 0 : Resize();
651 : 0 : }
652 : :
653 : : //------------------------------------------------------------------
654 : 0 : void OBrowserListBox::DisableUpdate()
655 : : {
656 : 0 : m_bUpdate = sal_False;
657 : 0 : }
658 : :
659 : : //------------------------------------------------------------------
660 : 0 : void OBrowserListBox::EnableUpdate()
661 : : {
662 : 0 : m_bUpdate = sal_True;
663 : 0 : UpdateAll();
664 : 0 : }
665 : :
666 : : //------------------------------------------------------------------
667 : 0 : void OBrowserListBox::SetPropertyValue(const ::rtl::OUString& _rEntryName, const Any& _rValue, bool _bUnknownValue )
668 : : {
669 : 0 : ListBoxLines::iterator line = m_aLines.begin();
670 : 0 : for ( ; line != m_aLines.end() && ( line->aName != _rEntryName ); ++line )
671 : : ;
672 : :
673 : 0 : if ( line != m_aLines.end() )
674 : : {
675 : 0 : if ( _bUnknownValue )
676 : : {
677 : 0 : Reference< XPropertyControl > xControl( line->pLine->getControl() );
678 : : OSL_ENSURE( xControl.is(), "OBrowserListBox::SetPropertyValue: illegal control!" );
679 : 0 : if ( xControl.is() )
680 : 0 : xControl->setValue( Any() );
681 : : }
682 : : else
683 : 0 : impl_setControlAsPropertyValue( *line, _rValue );
684 : : }
685 : 0 : }
686 : :
687 : : //------------------------------------------------------------------------
688 : 0 : sal_uInt16 OBrowserListBox::GetPropertyPos( const ::rtl::OUString& _rEntryName ) const
689 : : {
690 : 0 : sal_uInt16 nRet = LISTBOX_ENTRY_NOTFOUND;
691 : 0 : for ( ListBoxLines::const_iterator linePos = m_aLines.begin();
692 : 0 : linePos != m_aLines.end();
693 : : ++linePos
694 : : )
695 : : {
696 : 0 : if ( linePos->aName == _rEntryName )
697 : : {
698 : 0 : nRet = (sal_uInt16)( linePos - m_aLines.begin() );
699 : 0 : break;
700 : : }
701 : : }
702 : :
703 : 0 : return nRet;
704 : : }
705 : :
706 : : //------------------------------------------------------------------------
707 : 0 : bool OBrowserListBox::impl_getBrowserLineForName( const ::rtl::OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const
708 : : {
709 : 0 : ListBoxLines::const_iterator line = m_aLines.begin();
710 : 0 : for ( ; line != m_aLines.end() && ( line->aName != _rEntryName ); ++line )
711 : : ;
712 : :
713 : 0 : if ( line != m_aLines.end() )
714 : 0 : _out_rpLine = line->pLine;
715 : : else
716 : 0 : _out_rpLine.reset();
717 : 0 : return ( NULL != _out_rpLine.get() );
718 : : }
719 : :
720 : : //------------------------------------------------------------------------
721 : 0 : void OBrowserListBox::EnablePropertyControls( const ::rtl::OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable )
722 : : {
723 : 0 : BrowserLinePointer pLine;
724 : 0 : if ( impl_getBrowserLineForName( _rEntryName, pLine ) )
725 : 0 : pLine->EnablePropertyControls( _nControls, _bEnable );
726 : 0 : }
727 : :
728 : : //------------------------------------------------------------------------
729 : 0 : void OBrowserListBox::EnablePropertyLine( const ::rtl::OUString& _rEntryName, bool _bEnable )
730 : : {
731 : 0 : BrowserLinePointer pLine;
732 : 0 : if ( impl_getBrowserLineForName( _rEntryName, pLine ) )
733 : 0 : pLine->EnablePropertyLine( _bEnable );
734 : 0 : }
735 : :
736 : : //------------------------------------------------------------------------
737 : 0 : Reference< XPropertyControl > OBrowserListBox::GetPropertyControl( const ::rtl::OUString& _rEntryName )
738 : : {
739 : 0 : BrowserLinePointer pLine;
740 : 0 : if ( impl_getBrowserLineForName( _rEntryName, pLine ) )
741 : 0 : return pLine->getControl();
742 : 0 : return NULL;
743 : : }
744 : :
745 : : //------------------------------------------------------------------
746 : 0 : sal_uInt16 OBrowserListBox::InsertEntry(const OLineDescriptor& _rPropertyData, sal_uInt16 _nPos)
747 : : {
748 : : // create a new line
749 : 0 : BrowserLinePointer pBrowserLine( new OBrowserLine( _rPropertyData.sName, &m_aLinesPlayground ) );
750 : :
751 : : // check that the name is unique
752 : 0 : ListBoxLines::iterator it = m_aLines.begin();
753 : 0 : for ( ; it != m_aLines.end() && ( it->aName != _rPropertyData.sName ); ++it )
754 : : ;
755 : : OSL_ENSURE( it == m_aLines.end(), "OBrowserListBox::InsertEntry: already have another line for this name!" );
756 : :
757 : 0 : ListBoxLine aNewLine( _rPropertyData.sName, pBrowserLine, _rPropertyData.xPropertyHandler );
758 : 0 : sal_uInt16 nInsertPos = _nPos;
759 : 0 : if ( _nPos >= m_aLines.size() )
760 : : {
761 : 0 : nInsertPos = static_cast< sal_uInt16 >( m_aLines.size() );
762 : 0 : m_aLines.push_back( aNewLine );
763 : : }
764 : : else
765 : 0 : m_aLines.insert( m_aLines.begin() + _nPos, aNewLine );
766 : :
767 : 0 : pBrowserLine->SetTitleWidth(m_nTheNameSize);
768 : 0 : if (m_bUpdate)
769 : : {
770 : 0 : UpdateVScroll();
771 : 0 : Invalidate();
772 : : }
773 : :
774 : : // initialize the entry
775 : 0 : ChangeEntry(_rPropertyData, nInsertPos);
776 : :
777 : : // update the positions of possibly affected lines
778 : 0 : sal_uInt16 nUpdatePos = nInsertPos;
779 : 0 : while ( nUpdatePos < m_aLines.size() )
780 : 0 : m_aOutOfDateLines.insert( nUpdatePos++ );
781 : 0 : UpdatePosNSize( );
782 : :
783 : 0 : return nInsertPos;
784 : : }
785 : :
786 : : //------------------------------------------------------------------
787 : 0 : sal_Int32 OBrowserListBox::GetMinimumWidth()
788 : : {
789 : 0 : return m_nTheNameSize + 2 * FRAME_OFFSET + (m_nRowHeight - 4) * 8;
790 : : }
791 : :
792 : : //------------------------------------------------------------------
793 : 0 : sal_Int32 OBrowserListBox::GetMinimumHeight()
794 : : {
795 : : // assume that we want to display 5 rows, at least
796 : 0 : sal_Int32 nMinHeight = m_nRowHeight * 5;
797 : :
798 : 0 : if ( HasHelpSection() )
799 : : {
800 : 0 : Size aHelpWindowDistance( LogicToPixel( Size( 0, LAYOUT_HELP_WINDOW_DISTANCE_APPFONT ), MAP_APPFONT ) );
801 : 0 : nMinHeight += aHelpWindowDistance.Height();
802 : :
803 : 0 : nMinHeight += m_pHelpWindow->GetMinimalHeightPixel();
804 : : }
805 : :
806 : 0 : return nMinHeight;
807 : : }
808 : :
809 : : //------------------------------------------------------------------
810 : 0 : void OBrowserListBox::ShowEntry(sal_uInt16 _nPos)
811 : : {
812 : 0 : if ( _nPos < m_aLines.size() )
813 : : {
814 : 0 : sal_Int32 nThumbPos = m_aVScroll.GetThumbPos();
815 : :
816 : 0 : if (_nPos < nThumbPos)
817 : 0 : MoveThumbTo(_nPos);
818 : : else
819 : : {
820 : 0 : sal_Int32 nLines = CalcVisibleLines();
821 : 0 : if (_nPos >= nThumbPos + nLines)
822 : 0 : MoveThumbTo(_nPos - nLines + 1);
823 : : }
824 : : }
825 : :
826 : 0 : }
827 : :
828 : : //------------------------------------------------------------------
829 : 0 : void OBrowserListBox::MoveThumbTo(sal_Int32 _nNewThumbPos)
830 : : {
831 : : // disable painting to prevent flicker
832 : 0 : m_aLinesPlayground.EnablePaint(sal_False);
833 : :
834 : 0 : sal_Int32 nDelta = _nNewThumbPos - m_aVScroll.GetThumbPos();
835 : : // adjust the scrollbar
836 : 0 : m_aVScroll.SetThumbPos(_nNewThumbPos);
837 : 0 : sal_Int32 nThumbPos = _nNewThumbPos;
838 : :
839 : 0 : m_nYOffset = -m_aVScroll.GetThumbPos() * m_nRowHeight;
840 : :
841 : 0 : sal_Int32 nLines = CalcVisibleLines();
842 : 0 : sal_uInt16 nEnd = (sal_uInt16)(nThumbPos + nLines);
843 : :
844 : 0 : m_aLinesPlayground.Scroll(0, -nDelta * m_nRowHeight, SCROLL_CHILDREN);
845 : :
846 : 0 : if (1 == nDelta)
847 : : {
848 : : // TODO: what's the sense of this two PositionLines? Why not just one call?
849 : 0 : PositionLine(nEnd-1);
850 : 0 : PositionLine(nEnd);
851 : : }
852 : 0 : else if (-1 == nDelta)
853 : : {
854 : 0 : PositionLine((sal_uInt16)nThumbPos);
855 : : }
856 : 0 : else if (0 != nDelta)
857 : : {
858 : 0 : UpdatePlayGround();
859 : : }
860 : :
861 : 0 : m_aLinesPlayground.EnablePaint(sal_True);
862 : 0 : m_aLinesPlayground.Invalidate(INVALIDATE_CHILDREN);
863 : 0 : }
864 : :
865 : : //------------------------------------------------------------------
866 : 0 : IMPL_LINK(OBrowserListBox, ScrollHdl, ScrollBar*, _pScrollBar )
867 : : {
868 : : DBG_ASSERT(_pScrollBar == &m_aVScroll, "OBrowserListBox::ScrollHdl: where does this come from?");
869 : : (void)_pScrollBar;
870 : :
871 : : // disable painting to prevent flicker
872 : 0 : m_aLinesPlayground.EnablePaint(sal_False);
873 : :
874 : 0 : sal_Int32 nThumbPos = m_aVScroll.GetThumbPos();
875 : :
876 : 0 : sal_Int32 nDelta = m_aVScroll.GetDelta();
877 : 0 : m_nYOffset = -nThumbPos * m_nRowHeight;
878 : :
879 : 0 : sal_uInt16 nEnd = (sal_uInt16)(nThumbPos + CalcVisibleLines());
880 : :
881 : 0 : m_aLinesPlayground.Scroll(0, -nDelta * m_nRowHeight, SCROLL_CHILDREN);
882 : :
883 : 0 : if (1 == nDelta)
884 : : {
885 : 0 : PositionLine(nEnd-1);
886 : 0 : PositionLine(nEnd);
887 : : }
888 : 0 : else if (nDelta==-1)
889 : : {
890 : 0 : PositionLine((sal_uInt16)nThumbPos);
891 : : }
892 : 0 : else if (nDelta!=0 || m_aVScroll.GetType() == SCROLL_DONTKNOW)
893 : : {
894 : 0 : UpdatePlayGround();
895 : : }
896 : :
897 : 0 : m_aLinesPlayground.EnablePaint(sal_True);
898 : 0 : return 0;
899 : : }
900 : :
901 : : //------------------------------------------------------------------
902 : 0 : void OBrowserListBox::buttonClicked( OBrowserLine* _pLine, sal_Bool _bPrimary )
903 : : {
904 : : DBG_ASSERT( _pLine, "OBrowserListBox::buttonClicked: invalid browser line!" );
905 : 0 : if ( _pLine && m_pLineListener )
906 : : {
907 : 0 : m_pLineListener->Clicked( _pLine->GetEntryName(), _bPrimary );
908 : : }
909 : 0 : }
910 : :
911 : : //------------------------------------------------------------------
912 : 0 : void OBrowserListBox::impl_setControlAsPropertyValue( const ListBoxLine& _rLine, const Any& _rPropertyValue )
913 : : {
914 : 0 : Reference< XPropertyControl > xControl( _rLine.pLine->getControl() );
915 : : try
916 : : {
917 : 0 : if ( _rPropertyValue.getValueType().equals( _rLine.pLine->getControl()->getValueType() ) )
918 : : {
919 : 0 : xControl->setValue( _rPropertyValue );
920 : : }
921 : : else
922 : : {
923 : : #ifdef DBG_UTIL
924 : : if ( !_rLine.xHandler.is() )
925 : : {
926 : : ::rtl::OString sMessage( "OBrowserListBox::impl_setControlAsPropertyValue: no handler -> no conversion (property: '" );
927 : : ::rtl::OUString sPropertyName( _rLine.pLine->GetEntryName() );
928 : : sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US );
929 : : sMessage += ::rtl::OString( "')!" );
930 : : OSL_FAIL( sMessage.getStr() );
931 : : }
932 : : #endif
933 : 0 : if ( _rLine.xHandler.is() )
934 : : {
935 : 0 : Any aControlValue = _rLine.xHandler->convertToControlValue(
936 : 0 : _rLine.pLine->GetEntryName(), _rPropertyValue, xControl->getValueType() );
937 : 0 : xControl->setValue( aControlValue );
938 : : }
939 : : }
940 : : }
941 : 0 : catch( const Exception& )
942 : : {
943 : : DBG_UNHANDLED_EXCEPTION();
944 : 0 : }
945 : 0 : }
946 : :
947 : : //------------------------------------------------------------------
948 : 0 : Any OBrowserListBox::impl_getControlAsPropertyValue( const ListBoxLine& _rLine ) const
949 : : {
950 : 0 : Reference< XPropertyControl > xControl( _rLine.pLine->getControl() );
951 : 0 : Any aPropertyValue;
952 : : try
953 : : {
954 : : #ifdef DBG_UTIL
955 : : if ( !_rLine.xHandler.is() )
956 : : {
957 : : ::rtl::OString sMessage( "OBrowserListBox::impl_getControlAsPropertyValue: no handler -> no conversion (property: '" );
958 : : ::rtl::OUString sPropertyName( _rLine.pLine->GetEntryName() );
959 : : sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), RTL_TEXTENCODING_ASCII_US );
960 : : sMessage += ::rtl::OString( "')!" );
961 : : OSL_FAIL( sMessage.getStr() );
962 : : }
963 : : #endif
964 : 0 : if ( _rLine.xHandler.is() )
965 : 0 : aPropertyValue = _rLine.xHandler->convertToPropertyValue( _rLine.pLine->GetEntryName(), xControl->getValue() );
966 : : else
967 : 0 : aPropertyValue = xControl->getValue();
968 : : }
969 : 0 : catch( const Exception& )
970 : : {
971 : : DBG_UNHANDLED_EXCEPTION();
972 : : }
973 : 0 : return aPropertyValue;
974 : : }
975 : :
976 : : //------------------------------------------------------------------
977 : 0 : sal_uInt16 OBrowserListBox::impl_getControlPos( const Reference< XPropertyControl >& _rxControl ) const
978 : : {
979 : 0 : for ( ListBoxLines::const_iterator search = m_aLines.begin(); search != m_aLines.end(); ++search )
980 : 0 : if ( search->pLine->getControl().get() == _rxControl.get() )
981 : 0 : return sal_uInt16( search - m_aLines.begin() );
982 : :
983 : : OSL_FAIL( "OBrowserListBox::impl_getControlPos: invalid control - not part of any of our lines!" );
984 : 0 : return (sal_uInt16)-1;
985 : : }
986 : :
987 : : //--------------------------------------------------------------------
988 : 0 : void SAL_CALL OBrowserListBox::focusGained( const Reference< XPropertyControl >& _rxControl ) throw (RuntimeException)
989 : : {
990 : : DBG_TESTSOLARMUTEX();
991 : :
992 : : DBG_ASSERT( _rxControl.is(), "OBrowserListBox::focusGained: invalid event source!" );
993 : 0 : if ( !_rxControl.is() )
994 : 0 : return;
995 : :
996 : 0 : if ( m_pControlObserver )
997 : 0 : m_pControlObserver->focusGained( _rxControl );
998 : :
999 : 0 : m_xActiveControl = _rxControl;
1000 : 0 : ShowEntry( impl_getControlPos( m_xActiveControl ) );
1001 : : }
1002 : :
1003 : : //--------------------------------------------------------------------
1004 : 0 : void SAL_CALL OBrowserListBox::valueChanged( const Reference< XPropertyControl >& _rxControl ) throw (RuntimeException)
1005 : : {
1006 : : DBG_TESTSOLARMUTEX();
1007 : :
1008 : : DBG_ASSERT( _rxControl.is(), "OBrowserListBox::valueChanged: invalid event source!" );
1009 : 0 : if ( !_rxControl.is() )
1010 : 0 : return;
1011 : :
1012 : 0 : if ( m_pControlObserver )
1013 : 0 : m_pControlObserver->valueChanged( _rxControl );
1014 : :
1015 : 0 : if ( m_pLineListener )
1016 : : {
1017 : 0 : const ListBoxLine& rLine = m_aLines[ impl_getControlPos( _rxControl ) ];
1018 : : m_pLineListener->Commit(
1019 : 0 : rLine.pLine->GetEntryName(),
1020 : : impl_getControlAsPropertyValue( rLine )
1021 : 0 : );
1022 : : }
1023 : : }
1024 : :
1025 : : //--------------------------------------------------------------------
1026 : 0 : void SAL_CALL OBrowserListBox::activateNextControl( const Reference< XPropertyControl >& _rxCurrentControl ) throw (RuntimeException)
1027 : : {
1028 : : DBG_TESTSOLARMUTEX();
1029 : :
1030 : 0 : sal_uInt16 nLine = impl_getControlPos( _rxCurrentControl );
1031 : :
1032 : : // cycle forwards, 'til we've the next control which can grab the focus
1033 : 0 : ++nLine;
1034 : 0 : while ( static_cast< size_t >( nLine ) < m_aLines.size() )
1035 : : {
1036 : 0 : if ( m_aLines[nLine].pLine->GrabFocus() )
1037 : 0 : break;
1038 : 0 : ++nLine;
1039 : : }
1040 : :
1041 : : // wrap around?
1042 : 0 : if ( ( static_cast< size_t >( nLine ) >= m_aLines.size() ) && ( m_aLines.size() > 0 ) )
1043 : 0 : m_aLines[0].pLine->GrabFocus();
1044 : 0 : }
1045 : :
1046 : : //------------------------------------------------------------------
1047 : : namespace
1048 : : {
1049 : : //..............................................................
1050 : 0 : void lcl_implDisposeControl_nothrow( const Reference< XPropertyControl >& _rxControl )
1051 : : {
1052 : 0 : if ( !_rxControl.is() )
1053 : 0 : return;
1054 : : try
1055 : : {
1056 : 0 : _rxControl->setControlContext( NULL );
1057 : 0 : Reference< XComponent > xControlComponent( _rxControl, UNO_QUERY );
1058 : 0 : if ( xControlComponent.is() )
1059 : 0 : xControlComponent->dispose();
1060 : : }
1061 : 0 : catch( const Exception& )
1062 : : {
1063 : : DBG_UNHANDLED_EXCEPTION();
1064 : : }
1065 : : }
1066 : : }
1067 : :
1068 : : //------------------------------------------------------------------
1069 : 0 : void OBrowserListBox::Clear()
1070 : : {
1071 : 0 : for ( ListBoxLines::iterator loop = m_aLines.begin(); loop != m_aLines.end(); ++loop )
1072 : : {
1073 : : // hide the line
1074 : 0 : loop->pLine->Hide();
1075 : : // reset the listener
1076 : 0 : lcl_implDisposeControl_nothrow( loop->pLine->getControl() );
1077 : : }
1078 : :
1079 : 0 : clearContainer( m_aLines );
1080 : 0 : }
1081 : :
1082 : : //------------------------------------------------------------------
1083 : 0 : sal_Bool OBrowserListBox::RemoveEntry( const ::rtl::OUString& _rName )
1084 : : {
1085 : 0 : sal_uInt16 nPos = 0;
1086 : 0 : ListBoxLines::iterator it = m_aLines.begin();
1087 : 0 : for ( ; it != m_aLines.end() && ( it->aName != _rName ); ++it, ++nPos )
1088 : : ;
1089 : :
1090 : 0 : if ( it == m_aLines.end() )
1091 : 0 : return sal_False;
1092 : :
1093 : 0 : m_aLines.erase( it );
1094 : 0 : m_aOutOfDateLines.erase( (sal_uInt16)m_aLines.size() );
1095 : :
1096 : : // update the positions of possibly affected lines
1097 : 0 : while ( nPos < m_aLines.size() )
1098 : 0 : m_aOutOfDateLines.insert( nPos++ );
1099 : 0 : UpdatePosNSize( );
1100 : :
1101 : 0 : return sal_True;
1102 : : }
1103 : :
1104 : : //------------------------------------------------------------------
1105 : 0 : void OBrowserListBox::ChangeEntry( const OLineDescriptor& _rPropertyData, sal_uInt16 nPos )
1106 : : {
1107 : : OSL_PRECOND( _rPropertyData.Control.is(), "OBrowserListBox::ChangeEntry: invalid control!" );
1108 : 0 : if ( !_rPropertyData.Control.is() )
1109 : 0 : return;
1110 : :
1111 : 0 : if ( nPos == EDITOR_LIST_REPLACE_EXISTING )
1112 : 0 : nPos = GetPropertyPos( _rPropertyData.sName );
1113 : :
1114 : 0 : if ( nPos < m_aLines.size() )
1115 : : {
1116 : 0 : Window* pRefWindow = NULL;
1117 : 0 : if ( nPos > 0 )
1118 : 0 : pRefWindow = m_aLines[nPos-1].pLine->GetRefWindow();
1119 : :
1120 : : // the current line and control
1121 : 0 : ListBoxLine& rLine = m_aLines[nPos];
1122 : :
1123 : : // the old control and some data about it
1124 : 0 : Reference< XPropertyControl > xControl = rLine.pLine->getControl();
1125 : 0 : Window* pControlWindow = rLine.pLine->getControlWindow();
1126 : 0 : Point aControlPos;
1127 : 0 : if ( pControlWindow )
1128 : 0 : aControlPos = pControlWindow->GetPosPixel();
1129 : :
1130 : : // clean up the old control
1131 : 0 : lcl_implDisposeControl_nothrow( xControl );
1132 : :
1133 : : // set the new control at the line
1134 : 0 : rLine.pLine->setControl( _rPropertyData.Control );
1135 : 0 : xControl = rLine.pLine->getControl();
1136 : :
1137 : 0 : if ( xControl.is() )
1138 : 0 : xControl->setControlContext( m_pControlContextImpl.get() );
1139 : :
1140 : : // the initial property value
1141 : 0 : if ( _rPropertyData.bUnknownValue )
1142 : 0 : xControl->setValue( Any() );
1143 : : else
1144 : 0 : impl_setControlAsPropertyValue( rLine, _rPropertyData.aValue );
1145 : :
1146 : 0 : rLine.pLine->SetTitle(_rPropertyData.DisplayName);
1147 : 0 : rLine.xHandler = _rPropertyData.xPropertyHandler;
1148 : :
1149 : 0 : sal_uInt16 nTextWidth = (sal_uInt16)m_aLinesPlayground.GetTextWidth(_rPropertyData.DisplayName);
1150 : 0 : if (m_nTheNameSize< nTextWidth)
1151 : 0 : m_nTheNameSize = nTextWidth;
1152 : :
1153 : 0 : if ( _rPropertyData.HasPrimaryButton )
1154 : : {
1155 : 0 : if ( !_rPropertyData.PrimaryButtonImageURL.isEmpty() )
1156 : 0 : rLine.pLine->ShowBrowseButton( _rPropertyData.PrimaryButtonImageURL, true );
1157 : 0 : else if ( _rPropertyData.PrimaryButtonImage.is() )
1158 : 0 : rLine.pLine->ShowBrowseButton( Image( _rPropertyData.PrimaryButtonImage ), true );
1159 : : else
1160 : 0 : rLine.pLine->ShowBrowseButton( true );
1161 : :
1162 : 0 : if ( _rPropertyData.HasSecondaryButton )
1163 : : {
1164 : 0 : if ( !_rPropertyData.SecondaryButtonImageURL.isEmpty() )
1165 : 0 : rLine.pLine->ShowBrowseButton( _rPropertyData.SecondaryButtonImageURL, false );
1166 : 0 : else if ( _rPropertyData.SecondaryButtonImage.is() )
1167 : 0 : rLine.pLine->ShowBrowseButton( Image( _rPropertyData.SecondaryButtonImage ), false );
1168 : : else
1169 : 0 : rLine.pLine->ShowBrowseButton( false );
1170 : : }
1171 : : else
1172 : 0 : rLine.pLine->HideBrowseButton( false );
1173 : :
1174 : 0 : rLine.pLine->SetClickListener( this );
1175 : : }
1176 : : else
1177 : : {
1178 : 0 : rLine.pLine->HideBrowseButton( true );
1179 : 0 : rLine.pLine->HideBrowseButton( false );
1180 : : }
1181 : :
1182 : : DBG_ASSERT( ( _rPropertyData.IndentLevel == 0 ) || ( _rPropertyData.IndentLevel == 1 ),
1183 : : "OBrowserListBox::ChangeEntry: unsupported indent level!" );
1184 : 0 : rLine.pLine->IndentTitle( _rPropertyData.IndentLevel > 0 );
1185 : :
1186 : 0 : if ( nPos > 0 )
1187 : 0 : rLine.pLine->SetTabOrder( pRefWindow, WINDOW_ZORDER_BEHIND );
1188 : : else
1189 : 0 : rLine.pLine->SetTabOrder( pRefWindow, WINDOW_ZORDER_FIRST );
1190 : :
1191 : 0 : m_aOutOfDateLines.insert( nPos );
1192 : : rLine.pLine->SetComponentHelpIds(
1193 : : HelpIdUrl::getHelpId( _rPropertyData.HelpURL ),
1194 : : rtl::OUStringToOString( _rPropertyData.PrimaryButtonId, RTL_TEXTENCODING_UTF8 ),
1195 : : rtl::OUStringToOString( _rPropertyData.SecondaryButtonId, RTL_TEXTENCODING_UTF8 )
1196 : 0 : );
1197 : :
1198 : 0 : if ( _rPropertyData.bReadOnly )
1199 : : {
1200 : 0 : rLine.pLine->SetReadOnly( true );
1201 : :
1202 : : // user controls (i.e. the ones not provided by the usual
1203 : : // XPropertyControlFactory) have no chance to know that they should be read-only,
1204 : : // since XPropertyHandler::describePropertyLine does not transport this
1205 : : // information.
1206 : : // So, we manually switch this to read-only.
1207 : 0 : if ( xControl.is() && ( xControl->getControlType() == PropertyControlType::Unknown ) )
1208 : : {
1209 : 0 : Edit* pControlWindowAsEdit = dynamic_cast< Edit* >( rLine.pLine->getControlWindow() );
1210 : 0 : if ( pControlWindowAsEdit )
1211 : 0 : pControlWindowAsEdit->SetReadOnly( sal_True );
1212 : : else
1213 : 0 : pControlWindowAsEdit->Enable( sal_False );
1214 : : }
1215 : 0 : }
1216 : : }
1217 : : }
1218 : :
1219 : : //------------------------------------------------------------------
1220 : 0 : long OBrowserListBox::PreNotify( NotifyEvent& _rNEvt )
1221 : : {
1222 : 0 : switch ( _rNEvt.GetType() )
1223 : : {
1224 : : case EVENT_KEYINPUT:
1225 : : {
1226 : 0 : const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
1227 : 0 : if ( ( pKeyEvent->GetKeyCode().GetModifier() != 0 )
1228 : 0 : || ( ( pKeyEvent->GetKeyCode().GetCode() != KEY_PAGEUP )
1229 : 0 : && ( pKeyEvent->GetKeyCode().GetCode() != KEY_PAGEDOWN )
1230 : : )
1231 : : )
1232 : 0 : break;
1233 : :
1234 : 0 : long nScrollOffset = 0;
1235 : 0 : if ( m_aVScroll.IsVisible() )
1236 : : {
1237 : 0 : if ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEUP )
1238 : 0 : nScrollOffset = -m_aVScroll.GetPageSize();
1239 : 0 : else if ( pKeyEvent->GetKeyCode().GetCode() == KEY_PAGEDOWN )
1240 : 0 : nScrollOffset = m_aVScroll.GetPageSize();
1241 : : }
1242 : :
1243 : 0 : if ( nScrollOffset )
1244 : : {
1245 : 0 : long nNewThumbPos = m_aVScroll.GetThumbPos() + nScrollOffset;
1246 : 0 : nNewThumbPos = ::std::max( nNewThumbPos, m_aVScroll.GetRangeMin() );
1247 : 0 : nNewThumbPos = ::std::min( nNewThumbPos, m_aVScroll.GetRangeMax() );
1248 : 0 : m_aVScroll.DoScroll( nNewThumbPos );
1249 : 0 : nNewThumbPos = m_aVScroll.GetThumbPos();
1250 : :
1251 : 0 : sal_uInt16 nFocusControlPos = 0;
1252 : 0 : sal_uInt16 nActiveControlPos = impl_getControlPos( m_xActiveControl );
1253 : 0 : if ( nActiveControlPos < nNewThumbPos )
1254 : 0 : nFocusControlPos = (sal_uInt16)nNewThumbPos;
1255 : 0 : else if ( nActiveControlPos >= nNewThumbPos + CalcVisibleLines() )
1256 : 0 : nFocusControlPos = (sal_uInt16)nNewThumbPos + CalcVisibleLines() - 1;
1257 : 0 : if ( nFocusControlPos )
1258 : : {
1259 : 0 : if ( nFocusControlPos < m_aLines.size() )
1260 : : {
1261 : 0 : m_aLines[ nFocusControlPos ].pLine->GrabFocus();
1262 : : }
1263 : : else
1264 : : OSL_FAIL( "OBrowserListBox::PreNotify: internal error, invalid focus control position!" );
1265 : : }
1266 : : }
1267 : :
1268 : 0 : return 1L;
1269 : : // handled this. In particular, we also consume PageUp/Down events if we do not use them for scrolling,
1270 : : // otherwise they would be used to scroll the document view, which does not sound like it is desired by
1271 : : // the user.
1272 : : }
1273 : : }
1274 : 0 : return Control::PreNotify( _rNEvt );
1275 : : }
1276 : :
1277 : : //------------------------------------------------------------------
1278 : 0 : long OBrowserListBox::Notify( NotifyEvent& _rNEvt )
1279 : : {
1280 : 0 : switch ( _rNEvt.GetType() )
1281 : : {
1282 : : case EVENT_COMMAND:
1283 : : {
1284 : 0 : const CommandEvent* pCommand = _rNEvt.GetCommandEvent();
1285 : 0 : if ( ( COMMAND_WHEEL == pCommand->GetCommand() )
1286 : 0 : || ( COMMAND_STARTAUTOSCROLL == pCommand->GetCommand() )
1287 : 0 : || ( COMMAND_AUTOSCROLL == pCommand->GetCommand() )
1288 : : )
1289 : : {
1290 : : // interested in scroll events if we have a scrollbar
1291 : 0 : if ( m_aVScroll.IsVisible() )
1292 : : {
1293 : 0 : HandleScrollCommand( *pCommand, NULL, &m_aVScroll );
1294 : : }
1295 : : }
1296 : : }
1297 : 0 : break;
1298 : : }
1299 : :
1300 : 0 : return Control::Notify( _rNEvt );
1301 : : }
1302 : :
1303 : : //............................................................................
1304 : 0 : } // namespace pcr
1305 : : //............................................................................
1306 : :
1307 : :
1308 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|