bump product version to 4.1.6.2
[LibreOffice.git] / extensions / source / propctrlr / browserline.cxx
bloba8ec00ca0b77f3ab45343fa2c10c1c85a91a11c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "browserline.hxx"
22 #include <com/sun/star/uno/XComponentContext.hpp>
23 #include <com/sun/star/inspection/PropertyLineElement.hpp>
24 #include <com/sun/star/graphic/GraphicProvider.hpp>
25 #include <com/sun/star/graphic/XGraphicProvider.hpp>
27 #include <comphelper/componentcontext.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <comphelper/string.hxx>
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <vcl/svapp.hxx>
35 //............................................................................
36 namespace pcr
38 //............................................................................
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::XComponentContext;
42 using ::com::sun::star::inspection::XPropertyControl;
43 using ::com::sun::star::inspection::XPropertyControlContext;
44 using ::com::sun::star::uno::UNO_QUERY_THROW;
45 using ::com::sun::star::uno::Exception;
46 using ::com::sun::star::graphic::GraphicProvider;
47 using ::com::sun::star::graphic::XGraphicProvider;
48 using ::com::sun::star::uno::Sequence;
49 using ::com::sun::star::beans::PropertyValue;
50 using ::com::sun::star::graphic::XGraphic;
52 namespace PropertyLineElement = ::com::sun::star::inspection::PropertyLineElement;
54 //==================================================================
55 //= OBrowserLine
56 //==================================================================
57 DBG_NAME(OBrowserLine)
58 //------------------------------------------------------------------
60 OBrowserLine::OBrowserLine( const OUString& _rEntryName, Window* pParent )
61 :m_sEntryName( _rEntryName )
62 ,m_aFtTitle(pParent)
63 ,m_pControlWindow( NULL )
64 ,m_pBrowseButton(NULL)
65 ,m_pAdditionalBrowseButton( NULL )
66 ,m_pClickListener( NULL )
67 ,m_pTheParent(pParent)
68 ,m_nNameWidth(0)
69 ,m_nEnableFlags( 0xFFFF )
70 ,m_bIndentTitle( false )
71 ,m_bReadOnly( false )
73 DBG_CTOR(OBrowserLine,NULL);
74 m_aFtTitle.Show();
77 //------------------------------------------------------------------
78 OBrowserLine::~OBrowserLine()
80 implHideBrowseButton( true, false );
81 implHideBrowseButton( false, false );
83 DBG_DTOR(OBrowserLine,NULL);
86 //------------------------------------------------------------------
87 void OBrowserLine::IndentTitle( bool _bIndent )
89 if ( m_bIndentTitle != _bIndent )
91 m_bIndentTitle = _bIndent;
92 impl_layoutComponents();
96 //------------------------------------------------------------------
97 void OBrowserLine::SetComponentHelpIds( const OString& _rHelpId, const OString& _sPrimaryButtonId, const OString& _sSecondaryButtonId )
99 if ( m_pControlWindow )
100 m_pControlWindow->SetHelpId( _rHelpId );
102 if ( m_pBrowseButton )
104 m_pBrowseButton->SetHelpId( _rHelpId );
105 m_pBrowseButton->SetUniqueId( _sPrimaryButtonId );
107 if ( m_pAdditionalBrowseButton )
109 m_pAdditionalBrowseButton->SetHelpId( _rHelpId );
110 m_pAdditionalBrowseButton->SetUniqueId( _sSecondaryButtonId );
115 //------------------------------------------------------------------
116 void OBrowserLine::setControl( const Reference< XPropertyControl >& _rxControl )
118 m_xControl = _rxControl;
119 m_pControlWindow = m_xControl.is() ? VCLUnoHelper::GetWindow( _rxControl->getControlWindow() ) : NULL;
120 DBG_ASSERT( m_pControlWindow, "OBrowserLine::setControl: setting NULL controls/windows is not allowed!" );
122 if ( m_pControlWindow )
124 m_pControlWindow->SetParent( m_pTheParent );
125 m_pControlWindow->Show();
127 impl_layoutComponents();
130 //------------------------------------------------------------------
131 Window* OBrowserLine::GetRefWindow()
133 Window* pRefWindow=&m_aFtTitle;
135 if(m_pBrowseButton)
137 pRefWindow=(Window*)m_pBrowseButton;
139 else if ( m_pControlWindow )
141 pRefWindow = m_pControlWindow;
143 return pRefWindow;
146 //------------------------------------------------------------------
147 void OBrowserLine::SetTabOrder(Window* pRefWindow, sal_uInt16 nFlags )
149 m_aFtTitle.SetZOrder(pRefWindow,nFlags);
150 if ( m_pControlWindow )
151 m_pControlWindow->SetZOrder( (Window*)&m_aFtTitle, WINDOW_ZORDER_BEHIND );
153 if ( m_pBrowseButton )
154 m_pBrowseButton->SetZOrder( m_pControlWindow, WINDOW_ZORDER_BEHIND );
156 if ( m_pAdditionalBrowseButton )
157 m_pAdditionalBrowseButton->SetZOrder( m_pBrowseButton, WINDOW_ZORDER_BEHIND );
160 //------------------------------------------------------------------
161 sal_Bool OBrowserLine::GrabFocus()
163 sal_Bool bRes=sal_False;
165 if ( m_pControlWindow && m_pControlWindow->IsEnabled() )
167 m_pControlWindow->GrabFocus();
168 bRes = sal_True;
170 else if ( m_pAdditionalBrowseButton && m_pAdditionalBrowseButton->IsEnabled() )
172 m_pAdditionalBrowseButton->GrabFocus();
173 bRes = sal_True;
175 else if ( m_pBrowseButton && m_pBrowseButton->IsEnabled() )
177 m_pBrowseButton->GrabFocus();
178 bRes = sal_True;
180 return bRes;
183 //------------------------------------------------------------------
184 void OBrowserLine::SetPosSizePixel( Point _rPos, Size _rSize )
186 m_aLinePos = _rPos;
187 m_aOutputSize = _rSize;
189 impl_layoutComponents();
192 //------------------------------------------------------------------
193 void OBrowserLine::Show(sal_Bool bFlag)
195 m_aFtTitle.Show(bFlag);
196 if ( m_pControlWindow )
197 m_pControlWindow->Show( bFlag );
198 if ( m_pBrowseButton )
199 m_pBrowseButton->Show( bFlag );
200 if ( m_pAdditionalBrowseButton )
201 m_pAdditionalBrowseButton->Show( bFlag );
204 //------------------------------------------------------------------
205 void OBrowserLine::Hide()
207 Show(sal_False);
210 //------------------------------------------------------------------
211 sal_Bool OBrowserLine::IsVisible()
213 return m_aFtTitle.IsVisible();
216 //------------------------------------------------------------------
217 void OBrowserLine::impl_layoutComponents()
220 Point aTitlePos( m_aLinePos.X(), m_aLinePos.Y() + 8 );
221 Size aTitleSize( m_nNameWidth - 3, m_aOutputSize.Height() );
223 if ( m_bIndentTitle )
225 Size aIndent( m_pTheParent->LogicToPixel( Size( 8, 0 ), MAP_APPFONT ) );
226 aTitlePos.X() += aIndent.Width();
227 aTitleSize.Width() -= aIndent.Width();
229 m_aFtTitle.SetPosSizePixel( aTitlePos, aTitleSize );
232 sal_Int32 nBrowseButtonSize = m_aOutputSize.Height() - 4;
234 if ( m_pControlWindow )
236 Point aControlPos( m_aLinePos.X() + m_nNameWidth, m_aLinePos.Y() + 2 );
237 m_pControlWindow->SetPosPixel( aControlPos );
239 Size aControlSize( m_aOutputSize.Width() - 4 - m_nNameWidth - nBrowseButtonSize - 4, m_pControlWindow->GetSizePixel().Height() );
240 if ( m_pAdditionalBrowseButton )
241 aControlSize.Width() -= nBrowseButtonSize + 4;
242 m_pControlWindow->SetSizePixel( aControlSize );
245 if ( m_pBrowseButton )
247 Point aButtonPos( m_aOutputSize.Width() - 4 - nBrowseButtonSize, m_aLinePos.Y() + 2 );
248 Size aButtonSize( nBrowseButtonSize, nBrowseButtonSize );
249 m_pBrowseButton->SetPosSizePixel( aButtonPos, aButtonSize );
251 if ( m_pAdditionalBrowseButton )
253 aButtonPos.X() -= nBrowseButtonSize + 4;
254 m_pAdditionalBrowseButton->SetPosSizePixel( aButtonPos, aButtonSize );
259 //------------------------------------------------------------------
260 void OBrowserLine::SetTitle(const XubString& _rNewTtile )
262 if ( GetTitle() == _rNewTtile )
263 return;
264 // #99102# --------------
265 m_aFtTitle.SetText( _rNewTtile );
266 if ( m_pControlWindow )
267 m_pControlWindow->SetAccessibleName( _rNewTtile );
268 if ( m_pBrowseButton )
269 m_pBrowseButton->SetAccessibleName( _rNewTtile );
270 FullFillTitleString();
273 // #99102# ---------------------------------------------------------
274 void OBrowserLine::FullFillTitleString()
276 if( m_pTheParent )
278 String aText = m_aFtTitle.GetText();
280 while( m_pTheParent->GetTextWidth( aText ) < m_nNameWidth )
281 aText.AppendAscii("...........");
283 // for Issue 69452
284 if (Application::GetSettings().GetLayoutRTL())
286 sal_Unicode cRTL_mark = 0x200F;
287 aText.Append(cRTL_mark);
290 m_aFtTitle.SetText(aText);
294 //------------------------------------------------------------------
295 XubString OBrowserLine::GetTitle() const
297 OUString sDisplayName = m_aFtTitle.GetText();
299 // for Issue 69452
300 if (Application::GetSettings().GetLayoutRTL())
302 sal_Unicode cRTL_mark = 0x200F;
303 sDisplayName = comphelper::string::stripEnd(sDisplayName, cRTL_mark);
306 sDisplayName = comphelper::string::stripEnd(sDisplayName, '.');
308 return sDisplayName;
311 //------------------------------------------------------------------
312 void OBrowserLine::SetReadOnly( bool _bReadOnly )
314 if ( m_bReadOnly != _bReadOnly )
316 m_bReadOnly = _bReadOnly;
317 implUpdateEnabledDisabled();
321 //------------------------------------------------------------------
322 namespace
324 void implSetBitIfAffected( sal_uInt16& _nEnabledBits, sal_Int16 _nAffectedMask, sal_Int16 _nTestBit, bool _bSet )
326 if ( _nAffectedMask & _nTestBit )
328 if ( _bSet )
329 _nEnabledBits |= _nTestBit;
330 else
331 _nEnabledBits &= ~_nTestBit;
335 void implEnable( Window* _pWindow, sal_uInt16 _nEnabledBits, sal_uInt16 _nMatchBits )
337 if ( _pWindow )
338 _pWindow->Enable( ( _nEnabledBits & _nMatchBits ) == _nMatchBits );
341 void implEnable( Window* _pWindow, bool _bEnable )
343 if ( _pWindow )
344 _pWindow->Enable( _bEnable );
348 //------------------------------------------------------------------
349 void OBrowserLine::implUpdateEnabledDisabled()
351 implEnable( &m_aFtTitle, m_nEnableFlags, PropertyLineElement::CompleteLine );
352 if ( m_pControlWindow )
353 implEnable( m_pControlWindow, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::InputControl );
355 if ( m_bReadOnly )
357 implEnable( m_pBrowseButton, false );
358 implEnable( m_pAdditionalBrowseButton, false );
360 else
362 implEnable( m_pBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::PrimaryButton );
363 implEnable( m_pAdditionalBrowseButton, m_nEnableFlags, PropertyLineElement::CompleteLine | PropertyLineElement::SecondaryButton );
367 //------------------------------------------------------------------
368 void OBrowserLine::EnablePropertyLine( bool _bEnable )
370 implSetBitIfAffected( m_nEnableFlags, PropertyLineElement::CompleteLine, PropertyLineElement::CompleteLine, _bEnable );
371 implUpdateEnabledDisabled();
374 //------------------------------------------------------------------
375 void OBrowserLine::EnablePropertyControls( sal_Int16 _nControls, bool _bEnable )
377 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::InputControl, _bEnable );
378 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::PrimaryButton, _bEnable );
379 implSetBitIfAffected( m_nEnableFlags, _nControls, PropertyLineElement::SecondaryButton, _bEnable );
380 implUpdateEnabledDisabled();
383 //------------------------------------------------------------------
384 PushButton& OBrowserLine::impl_ensureButton( bool _bPrimary )
386 PushButton*& rpButton = _bPrimary ? m_pBrowseButton : m_pAdditionalBrowseButton;
388 if ( !rpButton )
390 rpButton = new PushButton( m_pTheParent, WB_NOPOINTERFOCUS );
391 rpButton->SetGetFocusHdl( LINK( this, OBrowserLine, OnButtonFocus ) );
392 rpButton->SetClickHdl( LINK( this, OBrowserLine, OnButtonClicked ) );
393 rpButton->SetText(OUString("..."));
396 rpButton->Show();
398 impl_layoutComponents();
400 return *rpButton;
403 //------------------------------------------------------------------
404 void OBrowserLine::impl_getImagesFromURL_nothrow( const OUString& _rImageURL, Image& _out_rImage )
408 Reference< XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
409 Reference< XGraphicProvider > xGraphicProvider( GraphicProvider::create(xContext) );
411 Sequence< PropertyValue > aMediaProperties(1);
412 aMediaProperties[0].Name = OUString( "URL" );
413 aMediaProperties[0].Value <<= _rImageURL;
415 Reference< XGraphic > xGraphic( xGraphicProvider->queryGraphic( aMediaProperties ), UNO_QUERY_THROW );
416 _out_rImage = Image( xGraphic );
418 catch( const Exception& )
420 DBG_UNHANDLED_EXCEPTION();
424 //------------------------------------------------------------------
425 void OBrowserLine::ShowBrowseButton( const OUString& _rImageURL, sal_Bool _bPrimary )
427 PushButton& rButton( impl_ensureButton( _bPrimary ) );
429 OSL_PRECOND( !_rImageURL.isEmpty(), "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!" );
430 Image aImage;
431 impl_getImagesFromURL_nothrow( _rImageURL, aImage );
433 rButton.SetModeImage( aImage );
436 //------------------------------------------------------------------
437 void OBrowserLine::ShowBrowseButton( const Image& _rImage, sal_Bool _bPrimary )
439 PushButton& rButton( impl_ensureButton( _bPrimary ) );
440 if ( !!_rImage )
441 rButton.SetModeImage( _rImage );
444 //------------------------------------------------------------------
445 void OBrowserLine::ShowBrowseButton( sal_Bool _bPrimary )
447 impl_ensureButton( _bPrimary );
450 //------------------------------------------------------------------
451 void OBrowserLine::implHideBrowseButton( sal_Bool _bPrimary, bool _bReLayout )
453 PushButton*& rpButton = _bPrimary ? m_pBrowseButton : m_pAdditionalBrowseButton;
455 if ( rpButton )
457 rpButton->Hide();
458 delete rpButton;
459 rpButton = NULL;
462 if ( _bReLayout )
463 impl_layoutComponents();
466 //------------------------------------------------------------------
467 void OBrowserLine::HideBrowseButton( sal_Bool _bPrimary )
469 implHideBrowseButton( _bPrimary, true );
472 //------------------------------------------------------------------
473 void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth)
475 if (m_nNameWidth != nWidth+10)
477 m_nNameWidth = nWidth+10;
478 impl_layoutComponents();
480 // #99102# ---------
481 FullFillTitleString();
484 //------------------------------------------------------------------
485 void OBrowserLine::SetClickListener( IButtonClickListener* _pListener )
487 m_pClickListener = _pListener;
490 //------------------------------------------------------------------
491 IMPL_LINK( OBrowserLine, OnButtonClicked, PushButton*, _pButton )
493 if ( m_pClickListener )
494 m_pClickListener->buttonClicked( this, _pButton == m_pBrowseButton );
496 return 0L;
499 //------------------------------------------------------------------
500 IMPL_LINK( OBrowserLine, OnButtonFocus, PushButton*, /*pPB*/ )
502 if ( m_xControl.is() )
506 Reference< XPropertyControlContext > xContext( m_xControl->getControlContext(), UNO_QUERY_THROW );
507 xContext->focusGained( m_xControl );
509 catch( const Exception& )
511 DBG_UNHANDLED_EXCEPTION();
514 return 0;
516 //............................................................................
517 } // namespace pcr
518 //............................................................................
520 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */