merged tag LIBREOFFICE_3_2_99_3
[LibreOffice.git] / extensions / source / propctrlr / browserline.cxx
blobad43e61ca7f90aa119b2f4abcf96258d2544fbe6
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 "browserline.hxx"
33 /** === begin UNO includes === **/
34 #include <com/sun/star/inspection/PropertyLineElement.hpp>
35 #include <com/sun/star/graphic/XGraphicProvider.hpp>
36 /** === end UNO includes === **/
38 #include <vcl/svapp.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <tools/urlobj.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
44 #include <comphelper/processfactory.hxx>
45 #include <comphelper/componentcontext.hxx>
47 //............................................................................
48 namespace pcr
50 //............................................................................
52 /** === begin UNO using === **/
53 using ::com::sun::star::uno::Reference;
54 using ::com::sun::star::inspection::XPropertyControl;
55 using ::com::sun::star::inspection::XPropertyControlContext;
56 using ::com::sun::star::uno::UNO_QUERY_THROW;
57 using ::com::sun::star::uno::Exception;
58 using ::com::sun::star::graphic::XGraphicProvider;
59 using ::com::sun::star::uno::Sequence;
60 using ::com::sun::star::beans::PropertyValue;
61 using ::com::sun::star::graphic::XGraphic;
62 /** === end UNO using === **/
64 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
66 //==================================================================
67 //= OBrowserLine
68 //==================================================================
69 DBG_NAME(OBrowserLine)
70 //------------------------------------------------------------------
72 OBrowserLine::OBrowserLine( const ::rtl::OUString& _rEntryName, Window* pParent )
73 :m_sEntryName( _rEntryName )
74 ,m_aFtTitle(pParent)
75 ,m_pControlWindow( NULL )
76 ,m_pBrowseButton(NULL)
77 ,m_pAdditionalBrowseButton( NULL )
78 ,m_pClickListener( NULL )
79 ,m_pTheParent(pParent)
80 ,m_nNameWidth(0)
81 ,m_nEnableFlags( 0xFFFF )
82 ,m_bIndentTitle( false )
83 ,m_bReadOnly( false )
85 DBG_CTOR(OBrowserLine,NULL);
86 m_aFtTitle.Show();
89 //------------------------------------------------------------------
90 OBrowserLine::~OBrowserLine()
92 implHideBrowseButton( true, false );
93 implHideBrowseButton( false, false );
95 DBG_DTOR(OBrowserLine,NULL);
98 //------------------------------------------------------------------
99 void OBrowserLine::IndentTitle( bool _bIndent )
101 if ( m_bIndentTitle != _bIndent )
103 m_bIndentTitle = _bIndent;
104 impl_layoutComponents();
108 //------------------------------------------------------------------
109 void OBrowserLine::SetComponentHelpIds( const SmartId& _rHelpId, sal_uInt32 _bPrimaryButtonId, sal_uInt32 _nSecondaryButtonId )
111 if ( m_pControlWindow )
112 m_pControlWindow->SetSmartHelpId( _rHelpId );
114 if ( m_pBrowseButton )
116 m_pBrowseButton->SetSmartHelpId( _rHelpId );
117 m_pBrowseButton->SetUniqueId( _bPrimaryButtonId );
119 if ( m_pAdditionalBrowseButton )
121 m_pAdditionalBrowseButton->SetSmartHelpId( _rHelpId );
122 m_pAdditionalBrowseButton->SetUniqueId( _nSecondaryButtonId );
127 //------------------------------------------------------------------
128 void OBrowserLine::setControl( const Reference< XPropertyControl >& _rxControl )
130 m_xControl = _rxControl;
131 m_pControlWindow = m_xControl.is() ? VCLUnoHelper::GetWindow( _rxControl->getControlWindow() ) : NULL;
132 DBG_ASSERT( m_pControlWindow, "OBrowserLine::setControl: setting NULL controls/windows is not allowed!" );
134 if ( m_pControlWindow )
136 m_pControlWindow->SetParent( m_pTheParent );
137 m_pControlWindow->Show();
139 impl_layoutComponents();
142 //------------------------------------------------------------------
143 Window* OBrowserLine::GetRefWindow()
145 Window* pRefWindow=&m_aFtTitle;
147 if(m_pBrowseButton)
149 pRefWindow=(Window*)m_pBrowseButton;
151 else if ( m_pControlWindow )
153 pRefWindow = m_pControlWindow;
155 return pRefWindow;
158 //------------------------------------------------------------------
159 void OBrowserLine::SetTabOrder(Window* pRefWindow, sal_uInt16 nFlags )
161 m_aFtTitle.SetZOrder(pRefWindow,nFlags);
162 if ( m_pControlWindow )
163 m_pControlWindow->SetZOrder( (Window*)&m_aFtTitle, WINDOW_ZORDER_BEHIND );
165 if ( m_pBrowseButton )
166 m_pBrowseButton->SetZOrder( m_pControlWindow, WINDOW_ZORDER_BEHIND );
168 if ( m_pAdditionalBrowseButton )
169 m_pAdditionalBrowseButton->SetZOrder( m_pBrowseButton, WINDOW_ZORDER_BEHIND );
172 //------------------------------------------------------------------
173 sal_Bool OBrowserLine::GrabFocus()
175 sal_Bool bRes=sal_False;
177 if ( m_pControlWindow && m_pControlWindow->IsEnabled() )
179 m_pControlWindow->GrabFocus();
180 bRes = sal_True;
182 else if ( m_pAdditionalBrowseButton && m_pAdditionalBrowseButton->IsEnabled() )
184 m_pAdditionalBrowseButton->GrabFocus();
185 bRes = sal_True;
187 else if ( m_pBrowseButton && m_pBrowseButton->IsEnabled() )
189 m_pBrowseButton->GrabFocus();
190 bRes = sal_True;
192 return bRes;
195 //------------------------------------------------------------------
196 void OBrowserLine::SetPosSizePixel( Point _rPos, Size _rSize )
198 m_aLinePos = _rPos;
199 m_aOutputSize = _rSize;
201 impl_layoutComponents();
204 //------------------------------------------------------------------
205 void OBrowserLine::Show(sal_Bool bFlag)
207 m_aFtTitle.Show(bFlag);
208 if ( m_pControlWindow )
209 m_pControlWindow->Show( bFlag );
210 if ( m_pBrowseButton )
211 m_pBrowseButton->Show( bFlag );
212 if ( m_pAdditionalBrowseButton )
213 m_pAdditionalBrowseButton->Show( bFlag );
216 //------------------------------------------------------------------
217 void OBrowserLine::Hide()
219 Show(sal_False);
222 //------------------------------------------------------------------
223 sal_Bool OBrowserLine::IsVisible()
225 return m_aFtTitle.IsVisible();
228 //------------------------------------------------------------------
229 void OBrowserLine::impl_layoutComponents()
232 Point aTitlePos( m_aLinePos.X(), m_aLinePos.Y() + 8 );
233 Size aTitleSize( m_nNameWidth - 3, m_aOutputSize.Height() );
235 if ( m_bIndentTitle )
237 Size aIndent( m_pTheParent->LogicToPixel( Size( 8, 0 ), MAP_APPFONT ) );
238 aTitlePos.X() += aIndent.Width();
239 aTitleSize.Width() -= aIndent.Width();
241 m_aFtTitle.SetPosSizePixel( aTitlePos, aTitleSize );
244 sal_Int32 nBrowseButtonSize = m_aOutputSize.Height() - 4;
246 if ( m_pControlWindow )
248 Point aControlPos( m_aLinePos.X() + m_nNameWidth, m_aLinePos.Y() + 2 );
249 m_pControlWindow->SetPosPixel( aControlPos );
251 Size aControlSize( m_aOutputSize.Width() - 4 - m_nNameWidth - nBrowseButtonSize - 4, m_pControlWindow->GetSizePixel().Height() );
252 if ( m_pAdditionalBrowseButton )
253 aControlSize.Width() -= nBrowseButtonSize + 4;
254 m_pControlWindow->SetSizePixel( aControlSize );
257 if ( m_pBrowseButton )
259 Point aButtonPos( m_aOutputSize.Width() - 4 - nBrowseButtonSize, m_aLinePos.Y() + 2 );
260 Size aButtonSize( nBrowseButtonSize, nBrowseButtonSize );
261 m_pBrowseButton->SetPosSizePixel( aButtonPos, aButtonSize );
263 if ( m_pAdditionalBrowseButton )
265 aButtonPos.X() -= nBrowseButtonSize + 4;
266 m_pAdditionalBrowseButton->SetPosSizePixel( aButtonPos, aButtonSize );
271 //------------------------------------------------------------------
272 void OBrowserLine::SetTitle(const XubString& _rNewTtile )
274 if ( GetTitle() == _rNewTtile )
275 return;
276 // #99102# --------------
277 m_aFtTitle.SetText( _rNewTtile );
278 if ( m_pControlWindow )
279 m_pControlWindow->SetAccessibleName( _rNewTtile );
280 if ( m_pBrowseButton )
281 m_pBrowseButton->SetAccessibleName( _rNewTtile );
282 FullFillTitleString();
285 // #99102# ---------------------------------------------------------
286 void OBrowserLine::FullFillTitleString()
288 if( m_pTheParent )
290 String aText = m_aFtTitle.GetText();
292 while( m_pTheParent->GetTextWidth( aText ) < m_nNameWidth )
293 aText.AppendAscii("...........");
295 // for Issue 69452
296 if (Application::GetSettings().GetLayoutRTL())
298 sal_Unicode cRTL_mark = 0x200F;
299 aText.Append(cRTL_mark);
302 m_aFtTitle.SetText(aText);
306 //------------------------------------------------------------------
307 XubString OBrowserLine::GetTitle() const
309 String sDisplayName = m_aFtTitle.GetText();
311 // for Issue 69452
312 if (Application::GetSettings().GetLayoutRTL())
314 sal_Unicode cRTL_mark = 0x200F;
315 sDisplayName.EraseTrailingChars(cRTL_mark);
318 sDisplayName.EraseTrailingChars( '.' );
320 return sDisplayName;
323 //------------------------------------------------------------------
324 void OBrowserLine::SetReadOnly( bool _bReadOnly )
326 if ( m_bReadOnly != _bReadOnly )
328 m_bReadOnly = _bReadOnly;
329 implUpdateEnabledDisabled();
333 //------------------------------------------------------------------
334 namespace
336 void implSetBitIfAffected( sal_uInt16& _nEnabledBits, sal_Int16 _nAffectedMask, sal_Int16 _nTestBit, bool _bSet )
338 if ( _nAffectedMask & _nTestBit )
340 if ( _bSet )
341 _nEnabledBits |= _nTestBit;
342 else
343 _nEnabledBits &= ~_nTestBit;
347 void implEnable( Window* _pWindow, sal_uInt16 _nEnabledBits, sal_uInt16 _nMatchBits )
349 if ( _pWindow )
350 _pWindow->Enable( ( _nEnabledBits & _nMatchBits ) == _nMatchBits );
353 void implEnable( Window* _pWindow, bool _bEnable )
355 if ( _pWindow )
356 _pWindow->Enable( _bEnable );
360 //------------------------------------------------------------------
361 void OBrowserLine::implUpdateEnabledDisabled()
363 implEnable( &m_aFtTitle, m_nEnableFlags, PropertyLineElement::CompleteLine );
364 if ( m_pControlWindow )
365 implEnable( m_pControlWindow, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::InputControl );
367 if ( m_bReadOnly )
369 implEnable( m_pBrowseButton, false );
370 implEnable( m_pAdditionalBrowseButton, false );
372 else
374 implEnable( m_pBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::PrimaryButton );
375 implEnable( m_pAdditionalBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::SecondaryButton );
379 //------------------------------------------------------------------
380 void OBrowserLine::EnablePropertyLine( bool _bEnable )
382 implSetBitIfAffected( m_nEnableFlags, PropertyLineElement::CompleteLine, PropertyLineElement::CompleteLine, _bEnable );
383 implUpdateEnabledDisabled();
386 //------------------------------------------------------------------
387 void OBrowserLine::EnablePropertyControls( sal_Int16 _nControls, bool _bEnable )
389 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::InputControl, _bEnable );
390 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::PrimaryButton, _bEnable );
391 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::SecondaryButton, _bEnable );
392 implUpdateEnabledDisabled();
395 //------------------------------------------------------------------
396 PushButton& OBrowserLine::impl_ensureButton( bool _bPrimary )
398 PushButton*& rpButton = _bPrimary ? m_pBrowseButton : m_pAdditionalBrowseButton;
400 if ( !rpButton )
402 rpButton = new PushButton( m_pTheParent, WB_NOPOINTERFOCUS );
403 rpButton->SetGetFocusHdl( LINK( this, OBrowserLine, OnButtonFocus ) );
404 rpButton->SetClickHdl( LINK( this, OBrowserLine, OnButtonClicked ) );
405 rpButton->SetText( String::CreateFromAscii( "..." ) );
408 rpButton->Show();
410 impl_layoutComponents();
412 return *rpButton;
415 //------------------------------------------------------------------
416 void OBrowserLine::impl_getImagesFromURL_nothrow( const ::rtl::OUString& _rImageURL, Image& _out_rImage, Image& _out_rHCImage )
420 ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
421 Reference< XGraphicProvider > xGraphicProvider( aContext.createComponent( "com.sun.star.graphic.GraphicProvider" ), UNO_QUERY_THROW );
423 Sequence< PropertyValue > aMediaProperties(1);
424 aMediaProperties[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
425 aMediaProperties[0].Value <<= _rImageURL;
427 Reference< XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties ), UNO_QUERY_THROW );
428 _out_rImage = _out_rHCImage = Image( xGraphic );
430 // see if we find an HC version beside the normal graphic
431 INetURLObject aURL( _rImageURL );
432 ::rtl::OUString sBaseName( aURL.getBase() );
433 aURL.setBase( sBaseName + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_hc" ) ) );
434 ::rtl::OUString sHCImageURL( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
436 Reference< XGraphic > xHCGraphic;
439 aMediaProperties[0].Value <<= sHCImageURL;
440 xHCGraphic = xGraphicProvider->queryGraphic( aMediaProperties );
442 catch( const Exception& ) { }
444 if ( xHCGraphic.is() )
445 _out_rHCImage = Image( xHCGraphic );
447 catch( const Exception& )
449 DBG_UNHANDLED_EXCEPTION();
453 //------------------------------------------------------------------
454 void OBrowserLine::ShowBrowseButton( const ::rtl::OUString& _rImageURL, sal_Bool _bPrimary )
456 PushButton& rButton( impl_ensureButton( _bPrimary ) );
458 OSL_PRECOND( _rImageURL.getLength(), "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!" );
459 Image aImage, aHCImage;
460 impl_getImagesFromURL_nothrow( _rImageURL, aImage, aHCImage );
462 rButton.SetModeImage( aImage, BMP_COLOR_NORMAL );
463 rButton.SetModeImage( aHCImage, BMP_COLOR_HIGHCONTRAST );
466 //------------------------------------------------------------------
467 void OBrowserLine::ShowBrowseButton( const Image& _rImage, sal_Bool _bPrimary )
469 PushButton& rButton( impl_ensureButton( _bPrimary ) );
470 if ( !!_rImage )
471 rButton.SetModeImage( _rImage );
474 //------------------------------------------------------------------
475 void OBrowserLine::ShowBrowseButton( sal_Bool _bPrimary )
477 impl_ensureButton( _bPrimary );
480 //------------------------------------------------------------------
481 void OBrowserLine::implHideBrowseButton( sal_Bool _bPrimary, bool _bReLayout )
483 PushButton*& rpButton = _bPrimary ? m_pBrowseButton : m_pAdditionalBrowseButton;
485 if ( rpButton )
487 rpButton->Hide();
488 delete rpButton;
489 rpButton = NULL;
492 if ( _bReLayout )
493 impl_layoutComponents();
496 //------------------------------------------------------------------
497 void OBrowserLine::HideBrowseButton( sal_Bool _bPrimary )
499 implHideBrowseButton( _bPrimary, true );
502 //------------------------------------------------------------------
503 void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth)
505 if (m_nNameWidth != nWidth+10)
507 m_nNameWidth = nWidth+10;
508 impl_layoutComponents();
510 // #99102# ---------
511 FullFillTitleString();
514 //------------------------------------------------------------------
515 void OBrowserLine::SetClickListener( IButtonClickListener* _pListener )
517 m_pClickListener = _pListener;
520 //------------------------------------------------------------------
521 IMPL_LINK( OBrowserLine, OnButtonClicked, PushButton*, _pButton )
523 if ( m_pClickListener )
524 m_pClickListener->buttonClicked( this, _pButton == m_pBrowseButton );
526 return 0L;
529 //------------------------------------------------------------------
530 IMPL_LINK( OBrowserLine, OnButtonFocus, PushButton*, /*pPB*/ )
532 if ( m_xControl.is() )
536 Reference< XPropertyControlContext > xContext( m_xControl->getControlContext(), UNO_QUERY_THROW );
537 xContext->focusGained( m_xControl );
539 catch( const Exception& )
541 DBG_UNHANDLED_EXCEPTION();
544 return 0;
546 //............................................................................
547 } // namespace pcr
548 //............................................................................
550 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */