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 #include "browserline.hxx"
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 #include <com/sun/star/inspection/PropertyLineElement.hpp>
33 #include <com/sun/star/graphic/GraphicProvider.hpp>
34 #include <com/sun/star/graphic/XGraphicProvider.hpp>
36 #include <comphelper/componentcontext.hxx>
37 #include <comphelper/processfactory.hxx>
38 #include <comphelper/string.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <vcl/svapp.hxx>
44 //............................................................................
47 //............................................................................
49 /** === begin UNO using === **/
50 using ::com::sun::star::uno::Reference
;
51 using ::com::sun::star::uno::XComponentContext
;
52 using ::com::sun::star::inspection::XPropertyControl
;
53 using ::com::sun::star::inspection::XPropertyControlContext
;
54 using ::com::sun::star::uno::UNO_QUERY_THROW
;
55 using ::com::sun::star::uno::Exception
;
56 using ::com::sun::star::graphic::GraphicProvider
;
57 using ::com::sun::star::graphic::XGraphicProvider
;
58 using ::com::sun::star::uno::Sequence
;
59 using ::com::sun::star::beans::PropertyValue
;
60 using ::com::sun::star::graphic::XGraphic
;
61 /** === end UNO using === **/
63 namespace PropertyLineElement
= ::com::sun::star::inspection::PropertyLineElement
;
65 //==================================================================
67 //==================================================================
68 DBG_NAME(OBrowserLine
)
69 //------------------------------------------------------------------
71 OBrowserLine::OBrowserLine( const ::rtl::OUString
& _rEntryName
, Window
* pParent
)
72 :m_sEntryName( _rEntryName
)
74 ,m_pControlWindow( NULL
)
75 ,m_pBrowseButton(NULL
)
76 ,m_pAdditionalBrowseButton( NULL
)
77 ,m_pClickListener( NULL
)
78 ,m_pTheParent(pParent
)
80 ,m_nEnableFlags( 0xFFFF )
81 ,m_bIndentTitle( false )
84 DBG_CTOR(OBrowserLine
,NULL
);
88 //------------------------------------------------------------------
89 OBrowserLine::~OBrowserLine()
91 implHideBrowseButton( true, false );
92 implHideBrowseButton( false, false );
94 DBG_DTOR(OBrowserLine
,NULL
);
97 //------------------------------------------------------------------
98 void OBrowserLine::IndentTitle( bool _bIndent
)
100 if ( m_bIndentTitle
!= _bIndent
)
102 m_bIndentTitle
= _bIndent
;
103 impl_layoutComponents();
107 //------------------------------------------------------------------
108 void OBrowserLine::SetComponentHelpIds( const rtl::OString
& _rHelpId
, const rtl::OString
& _sPrimaryButtonId
, const rtl::OString
& _sSecondaryButtonId
)
110 if ( m_pControlWindow
)
111 m_pControlWindow
->SetHelpId( _rHelpId
);
113 if ( m_pBrowseButton
)
115 m_pBrowseButton
->SetHelpId( _rHelpId
);
116 m_pBrowseButton
->SetUniqueId( _sPrimaryButtonId
);
118 if ( m_pAdditionalBrowseButton
)
120 m_pAdditionalBrowseButton
->SetHelpId( _rHelpId
);
121 m_pAdditionalBrowseButton
->SetUniqueId( _sSecondaryButtonId
);
126 //------------------------------------------------------------------
127 void OBrowserLine::setControl( const Reference
< XPropertyControl
>& _rxControl
)
129 m_xControl
= _rxControl
;
130 m_pControlWindow
= m_xControl
.is() ? VCLUnoHelper::GetWindow( _rxControl
->getControlWindow() ) : NULL
;
131 DBG_ASSERT( m_pControlWindow
, "OBrowserLine::setControl: setting NULL controls/windows is not allowed!" );
133 if ( m_pControlWindow
)
135 m_pControlWindow
->SetParent( m_pTheParent
);
136 m_pControlWindow
->Show();
138 impl_layoutComponents();
141 //------------------------------------------------------------------
142 Window
* OBrowserLine::GetRefWindow()
144 Window
* pRefWindow
=&m_aFtTitle
;
148 pRefWindow
=(Window
*)m_pBrowseButton
;
150 else if ( m_pControlWindow
)
152 pRefWindow
= m_pControlWindow
;
157 //------------------------------------------------------------------
158 void OBrowserLine::SetTabOrder(Window
* pRefWindow
, sal_uInt16 nFlags
)
160 m_aFtTitle
.SetZOrder(pRefWindow
,nFlags
);
161 if ( m_pControlWindow
)
162 m_pControlWindow
->SetZOrder( (Window
*)&m_aFtTitle
, WINDOW_ZORDER_BEHIND
);
164 if ( m_pBrowseButton
)
165 m_pBrowseButton
->SetZOrder( m_pControlWindow
, WINDOW_ZORDER_BEHIND
);
167 if ( m_pAdditionalBrowseButton
)
168 m_pAdditionalBrowseButton
->SetZOrder( m_pBrowseButton
, WINDOW_ZORDER_BEHIND
);
171 //------------------------------------------------------------------
172 sal_Bool
OBrowserLine::GrabFocus()
174 sal_Bool bRes
=sal_False
;
176 if ( m_pControlWindow
&& m_pControlWindow
->IsEnabled() )
178 m_pControlWindow
->GrabFocus();
181 else if ( m_pAdditionalBrowseButton
&& m_pAdditionalBrowseButton
->IsEnabled() )
183 m_pAdditionalBrowseButton
->GrabFocus();
186 else if ( m_pBrowseButton
&& m_pBrowseButton
->IsEnabled() )
188 m_pBrowseButton
->GrabFocus();
194 //------------------------------------------------------------------
195 void OBrowserLine::SetPosSizePixel( Point _rPos
, Size _rSize
)
198 m_aOutputSize
= _rSize
;
200 impl_layoutComponents();
203 //------------------------------------------------------------------
204 void OBrowserLine::Show(sal_Bool bFlag
)
206 m_aFtTitle
.Show(bFlag
);
207 if ( m_pControlWindow
)
208 m_pControlWindow
->Show( bFlag
);
209 if ( m_pBrowseButton
)
210 m_pBrowseButton
->Show( bFlag
);
211 if ( m_pAdditionalBrowseButton
)
212 m_pAdditionalBrowseButton
->Show( bFlag
);
215 //------------------------------------------------------------------
216 void OBrowserLine::Hide()
221 //------------------------------------------------------------------
222 sal_Bool
OBrowserLine::IsVisible()
224 return m_aFtTitle
.IsVisible();
227 //------------------------------------------------------------------
228 void OBrowserLine::impl_layoutComponents()
231 Point
aTitlePos( m_aLinePos
.X(), m_aLinePos
.Y() + 8 );
232 Size
aTitleSize( m_nNameWidth
- 3, m_aOutputSize
.Height() );
234 if ( m_bIndentTitle
)
236 Size
aIndent( m_pTheParent
->LogicToPixel( Size( 8, 0 ), MAP_APPFONT
) );
237 aTitlePos
.X() += aIndent
.Width();
238 aTitleSize
.Width() -= aIndent
.Width();
240 m_aFtTitle
.SetPosSizePixel( aTitlePos
, aTitleSize
);
243 sal_Int32 nBrowseButtonSize
= m_aOutputSize
.Height() - 4;
245 if ( m_pControlWindow
)
247 Point
aControlPos( m_aLinePos
.X() + m_nNameWidth
, m_aLinePos
.Y() + 2 );
248 m_pControlWindow
->SetPosPixel( aControlPos
);
250 Size
aControlSize( m_aOutputSize
.Width() - 4 - m_nNameWidth
- nBrowseButtonSize
- 4, m_pControlWindow
->GetSizePixel().Height() );
251 if ( m_pAdditionalBrowseButton
)
252 aControlSize
.Width() -= nBrowseButtonSize
+ 4;
253 m_pControlWindow
->SetSizePixel( aControlSize
);
256 if ( m_pBrowseButton
)
258 Point
aButtonPos( m_aOutputSize
.Width() - 4 - nBrowseButtonSize
, m_aLinePos
.Y() + 2 );
259 Size
aButtonSize( nBrowseButtonSize
, nBrowseButtonSize
);
260 m_pBrowseButton
->SetPosSizePixel( aButtonPos
, aButtonSize
);
262 if ( m_pAdditionalBrowseButton
)
264 aButtonPos
.X() -= nBrowseButtonSize
+ 4;
265 m_pAdditionalBrowseButton
->SetPosSizePixel( aButtonPos
, aButtonSize
);
270 //------------------------------------------------------------------
271 void OBrowserLine::SetTitle(const XubString
& _rNewTtile
)
273 if ( GetTitle() == _rNewTtile
)
275 // #99102# --------------
276 m_aFtTitle
.SetText( _rNewTtile
);
277 if ( m_pControlWindow
)
278 m_pControlWindow
->SetAccessibleName( _rNewTtile
);
279 if ( m_pBrowseButton
)
280 m_pBrowseButton
->SetAccessibleName( _rNewTtile
);
281 FullFillTitleString();
284 // #99102# ---------------------------------------------------------
285 void OBrowserLine::FullFillTitleString()
289 String aText
= m_aFtTitle
.GetText();
291 while( m_pTheParent
->GetTextWidth( aText
) < m_nNameWidth
)
292 aText
.AppendAscii("...........");
295 if (Application::GetSettings().GetLayoutRTL())
297 sal_Unicode cRTL_mark
= 0x200F;
298 aText
.Append(cRTL_mark
);
301 m_aFtTitle
.SetText(aText
);
305 //------------------------------------------------------------------
306 XubString
OBrowserLine::GetTitle() const
308 rtl::OUString sDisplayName
= m_aFtTitle
.GetText();
311 if (Application::GetSettings().GetLayoutRTL())
313 sal_Unicode cRTL_mark
= 0x200F;
314 sDisplayName
= comphelper::string::stripEnd(sDisplayName
, cRTL_mark
);
317 sDisplayName
= comphelper::string::stripEnd(sDisplayName
, '.');
322 //------------------------------------------------------------------
323 void OBrowserLine::SetReadOnly( bool _bReadOnly
)
325 if ( m_bReadOnly
!= _bReadOnly
)
327 m_bReadOnly
= _bReadOnly
;
328 implUpdateEnabledDisabled();
332 //------------------------------------------------------------------
335 void implSetBitIfAffected( sal_uInt16
& _nEnabledBits
, sal_Int16 _nAffectedMask
, sal_Int16 _nTestBit
, bool _bSet
)
337 if ( _nAffectedMask
& _nTestBit
)
340 _nEnabledBits
|= _nTestBit
;
342 _nEnabledBits
&= ~_nTestBit
;
346 void implEnable( Window
* _pWindow
, sal_uInt16 _nEnabledBits
, sal_uInt16 _nMatchBits
)
349 _pWindow
->Enable( ( _nEnabledBits
& _nMatchBits
) == _nMatchBits
);
352 void implEnable( Window
* _pWindow
, bool _bEnable
)
355 _pWindow
->Enable( _bEnable
);
359 //------------------------------------------------------------------
360 void OBrowserLine::implUpdateEnabledDisabled()
362 implEnable( &m_aFtTitle
, m_nEnableFlags
, PropertyLineElement::CompleteLine
);
363 if ( m_pControlWindow
)
364 implEnable( m_pControlWindow
, m_nEnableFlags
, PropertyLineElement::CompleteLine
| PropertyLineElement::InputControl
);
368 implEnable( m_pBrowseButton
, false );
369 implEnable( m_pAdditionalBrowseButton
, false );
373 implEnable( m_pBrowseButton
, m_nEnableFlags
, PropertyLineElement::CompleteLine
| PropertyLineElement::PrimaryButton
);
374 implEnable( m_pAdditionalBrowseButton
, m_nEnableFlags
, PropertyLineElement::CompleteLine
| PropertyLineElement::SecondaryButton
);
378 //------------------------------------------------------------------
379 void OBrowserLine::EnablePropertyLine( bool _bEnable
)
381 implSetBitIfAffected( m_nEnableFlags
, PropertyLineElement::CompleteLine
, PropertyLineElement::CompleteLine
, _bEnable
);
382 implUpdateEnabledDisabled();
385 //------------------------------------------------------------------
386 void OBrowserLine::EnablePropertyControls( sal_Int16 _nControls
, bool _bEnable
)
388 implSetBitIfAffected( m_nEnableFlags
, _nControls
, PropertyLineElement::InputControl
, _bEnable
);
389 implSetBitIfAffected( m_nEnableFlags
, _nControls
, PropertyLineElement::PrimaryButton
, _bEnable
);
390 implSetBitIfAffected( m_nEnableFlags
, _nControls
, PropertyLineElement::SecondaryButton
, _bEnable
);
391 implUpdateEnabledDisabled();
394 //------------------------------------------------------------------
395 PushButton
& OBrowserLine::impl_ensureButton( bool _bPrimary
)
397 PushButton
*& rpButton
= _bPrimary
? m_pBrowseButton
: m_pAdditionalBrowseButton
;
401 rpButton
= new PushButton( m_pTheParent
, WB_NOPOINTERFOCUS
);
402 rpButton
->SetGetFocusHdl( LINK( this, OBrowserLine
, OnButtonFocus
) );
403 rpButton
->SetClickHdl( LINK( this, OBrowserLine
, OnButtonClicked
) );
404 rpButton
->SetText( String::CreateFromAscii( "..." ) );
409 impl_layoutComponents();
414 //------------------------------------------------------------------
415 void OBrowserLine::impl_getImagesFromURL_nothrow( const ::rtl::OUString
& _rImageURL
, Image
& _out_rImage
)
419 Reference
< XComponentContext
> xContext( ::comphelper::getProcessComponentContext() );
420 Reference
< XGraphicProvider
> xGraphicProvider( GraphicProvider::create(xContext
) );
422 Sequence
< PropertyValue
> aMediaProperties(1);
423 aMediaProperties
[0].Name
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
424 aMediaProperties
[0].Value
<<= _rImageURL
;
426 Reference
< XGraphic
> xGraphic( xGraphicProvider
->queryGraphic( aMediaProperties
), UNO_QUERY_THROW
);
427 _out_rImage
= Image( xGraphic
);
429 catch( const Exception
& )
431 DBG_UNHANDLED_EXCEPTION();
435 //------------------------------------------------------------------
436 void OBrowserLine::ShowBrowseButton( const ::rtl::OUString
& _rImageURL
, sal_Bool _bPrimary
)
438 PushButton
& rButton( impl_ensureButton( _bPrimary
) );
440 OSL_PRECOND( !_rImageURL
.isEmpty(), "OBrowserLine::ShowBrowseButton: use the other version if you don't have an image!" );
442 impl_getImagesFromURL_nothrow( _rImageURL
, aImage
);
444 rButton
.SetModeImage( aImage
);
447 //------------------------------------------------------------------
448 void OBrowserLine::ShowBrowseButton( const Image
& _rImage
, sal_Bool _bPrimary
)
450 PushButton
& rButton( impl_ensureButton( _bPrimary
) );
452 rButton
.SetModeImage( _rImage
);
455 //------------------------------------------------------------------
456 void OBrowserLine::ShowBrowseButton( sal_Bool _bPrimary
)
458 impl_ensureButton( _bPrimary
);
461 //------------------------------------------------------------------
462 void OBrowserLine::implHideBrowseButton( sal_Bool _bPrimary
, bool _bReLayout
)
464 PushButton
*& rpButton
= _bPrimary
? m_pBrowseButton
: m_pAdditionalBrowseButton
;
474 impl_layoutComponents();
477 //------------------------------------------------------------------
478 void OBrowserLine::HideBrowseButton( sal_Bool _bPrimary
)
480 implHideBrowseButton( _bPrimary
, true );
483 //------------------------------------------------------------------
484 void OBrowserLine::SetTitleWidth(sal_uInt16 nWidth
)
486 if (m_nNameWidth
!= nWidth
+10)
488 m_nNameWidth
= nWidth
+10;
489 impl_layoutComponents();
492 FullFillTitleString();
495 //------------------------------------------------------------------
496 void OBrowserLine::SetClickListener( IButtonClickListener
* _pListener
)
498 m_pClickListener
= _pListener
;
501 //------------------------------------------------------------------
502 IMPL_LINK( OBrowserLine
, OnButtonClicked
, PushButton
*, _pButton
)
504 if ( m_pClickListener
)
505 m_pClickListener
->buttonClicked( this, _pButton
== m_pBrowseButton
);
510 //------------------------------------------------------------------
511 IMPL_LINK( OBrowserLine
, OnButtonFocus
, PushButton
*, /*pPB*/ )
513 if ( m_xControl
.is() )
517 Reference
< XPropertyControlContext
> xContext( m_xControl
->getControlContext(), UNO_QUERY_THROW
);
518 xContext
->focusGained( m_xControl
);
520 catch( const Exception
& )
522 DBG_UNHANDLED_EXCEPTION();
527 //............................................................................
529 //............................................................................
531 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */