summaryrefslogtreecommitdiff
path: root/toolkit
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-02-13 15:51:44 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-02-14 09:56:31 +0100
commit91cc66dfa77cb0130d0bc99875275f7267b7f95a (patch)
treee0d2841ea721fc4bdf0ff4e1fd125a73e438baef /toolkit
parent26df9f97bfcd3cbc071dde1dc5cba1703c04f1f9 (diff)
move VCLXFileControl to toolkit
Change-Id: I39bb417fe7e033a8f368fa04d4a30b2388bcddfb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88615 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'toolkit')
-rw-r--r--toolkit/Library_tk.mk2
-rw-r--r--toolkit/inc/controls/filectrl.hxx70
-rw-r--r--toolkit/source/awt/vclxtoolkit.cxx6
-rw-r--r--toolkit/source/awt/vclxwindows.cxx289
-rw-r--r--toolkit/source/controls/filectrl.cxx241
5 files changed, 608 insertions, 0 deletions
diff --git a/toolkit/Library_tk.mk b/toolkit/Library_tk.mk
index a582bd4e76b2..55639910d7fb 100644
--- a/toolkit/Library_tk.mk
+++ b/toolkit/Library_tk.mk
@@ -50,6 +50,7 @@ $(eval $(call gb_Library_use_libraries,tk,\
sal \
salhelper \
i18nlangtag \
+ svl \
tl \
utl \
vcl \
@@ -82,6 +83,7 @@ $(eval $(call gb_Library_add_exception_objects,tk,\
toolkit/source/controls/controlmodelcontainerbase \
toolkit/source/controls/dialogcontrol \
toolkit/source/controls/eventcontainer \
+ toolkit/source/controls/filectrl \
toolkit/source/controls/formattedcontrol \
toolkit/source/controls/geometrycontrolmodel \
toolkit/source/controls/grid/defaultgridcolumnmodel \
diff --git a/toolkit/inc/controls/filectrl.hxx b/toolkit/inc/controls/filectrl.hxx
new file mode 100644
index 000000000000..cb01ff29b0fe
--- /dev/null
+++ b/toolkit/inc/controls/filectrl.hxx
@@ -0,0 +1,70 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <vcl/window.hxx>
+#include <vcl/button.hxx>
+
+class Edit;
+
+// Flags for internal use of FileControl
+enum class FileControlMode_Internal
+{
+ INRESIZE = 0x0001,
+ ORIGINALBUTTONTEXT = 0x0002,
+};
+
+namespace o3tl
+{
+ template<> struct typed_flags<FileControlMode_Internal> : is_typed_flags<FileControlMode_Internal, 0x03> {};
+}
+
+
+class FileControl final : public vcl::Window
+{
+ VclPtr<Edit> maEdit;
+ VclPtr<PushButton> maButton;
+ OUString const maButtonText;
+ FileControlMode_Internal mnInternalFlags;
+
+ void Resize() override;
+ void GetFocus() override;
+ void StateChanged( StateChangedType nType ) override;
+ WinBits ImplInitStyle( WinBits nStyle );
+ DECL_LINK( ButtonHdl, Button*, void );
+
+public:
+ FileControl( vcl::Window* pParent, WinBits nStyle );
+ virtual ~FileControl() override;
+ virtual void dispose() override;
+
+ Edit& GetEdit() { return *maEdit; }
+ PushButton& GetButton() { return *maButton; }
+
+ void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags ) override;
+
+ void SetText( const OUString& rStr ) override;
+ OUString GetText() const override;
+
+ void SetEditModifyHdl( const Link<Edit&,void>& rLink );
+};
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
index 01c0d3cd2499..bf875134d9cf 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -78,6 +78,7 @@
#include <toolkit/helper/property.hxx>
#include <toolkit/helper/convert.hxx>
+#include <controls/filectrl.hxx>
#include <vcl/button.hxx>
#include <vcl/combobox.hxx>
#include <vcl/ctrl.hxx>
@@ -1802,6 +1803,11 @@ vcl::Window* VCLXToolkit::ImplCreateWindow( VCLXWindow** ppNewComp,
pNewWindow = VclPtr<ProgressBar>::Create( pParent, nWinBits );
*ppNewComp = new VCLXProgressBar;
}
+ else if (aServiceName == "filecontrol")
+ {
+ pNewWindow = VclPtr<FileControl>::Create( pParent, nWinBits );
+ *ppNewComp = new VCLXFileControl;
+ }
break;
default:
OSL_ENSURE( false, "VCLXToolkit::ImplCreateWindow: unknown window type!" );
diff --git a/toolkit/source/awt/vclxwindows.cxx b/toolkit/source/awt/vclxwindows.cxx
index 5789fe5ebf80..1a500e869e7e 100644
--- a/toolkit/source/awt/vclxwindows.cxx
+++ b/toolkit/source/awt/vclxwindows.cxx
@@ -40,6 +40,7 @@
#include <comphelper/processfactory.hxx>
#include <sal/log.hxx>
+#include <controls/filectrl.hxx>
#include <vcl/button.hxx>
#include <vcl/graph.hxx>
#include <vcl/lstbox.hxx>
@@ -6881,4 +6882,292 @@ void VCLXProgressBar::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
VCLXWindow::ImplGetPropertyIds( rIds, true );
}
+VCLXFileControl::VCLXFileControl() : maTextListeners( *this )
+{
+}
+
+VCLXFileControl::~VCLXFileControl()
+{
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( pControl )
+ pControl->GetEdit().SetModifyHdl( Link<Edit&,void>() );
+}
+
+css::uno::Any VCLXFileControl::queryInterface( const css::uno::Type & rType )
+{
+ css::uno::Any aRet = ::cppu::queryInterface( rType,
+ static_cast< css::awt::XTextComponent* >(this),
+ static_cast< css::awt::XTextLayoutConstrains* >(this),
+ static_cast< css::lang::XTypeProvider* >(this) );
+ return (aRet.hasValue() ? aRet : VCLXWindow::queryInterface( rType ));
+}
+
+IMPL_IMPLEMENTATION_ID( VCLXFileControl )
+
+// css::lang::XTypeProvider
+css::uno::Sequence< css::uno::Type > VCLXFileControl::getTypes()
+{
+ static const ::cppu::OTypeCollection aTypeList(
+ cppu::UnoType<css::lang::XTypeProvider>::get(),
+ cppu::UnoType<css::awt::XTextComponent>::get(),
+ cppu::UnoType<css::awt::XTextLayoutConstrains>::get(),
+ VCLXWindow::getTypes()
+ );
+ return aTypeList.getTypes();
+}
+
+namespace
+{
+ void lcl_setWinBits( vcl::Window* _pWindow, WinBits _nBits, bool _bSet )
+ {
+ WinBits nStyle = _pWindow->GetStyle();
+ if ( _bSet )
+ nStyle |= _nBits;
+ else
+ nStyle &= ~_nBits;
+ _pWindow->SetStyle( nStyle );
+ }
+}
+
+void SAL_CALL VCLXFileControl::setProperty( const OUString& PropertyName, const css::uno::Any& Value)
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( !pControl )
+ return;
+
+ sal_uInt16 nPropType = GetPropertyId( PropertyName );
+ switch ( nPropType )
+ {
+ case BASEPROPERTY_HIDEINACTIVESELECTION:
+ {
+ bool bValue(false);
+ OSL_VERIFY( Value >>= bValue );
+
+ lcl_setWinBits( pControl, WB_NOHIDESELECTION, !bValue );
+ lcl_setWinBits( &pControl->GetEdit(), WB_NOHIDESELECTION, !bValue );
+ }
+ break;
+
+ default:
+ VCLXWindow::setProperty( PropertyName, Value );
+ break;
+ }
+}
+
+void VCLXFileControl::SetWindow( const VclPtr< vcl::Window > &pWindow )
+{
+ VclPtr< FileControl > pPrevFileControl = GetAsDynamic< FileControl >();
+ if ( pPrevFileControl )
+ pPrevFileControl->SetEditModifyHdl( Link<Edit&,void>() );
+
+ FileControl* pNewFileControl = dynamic_cast<FileControl*>( pWindow.get() );
+ if ( pNewFileControl )
+ pNewFileControl->SetEditModifyHdl( LINK( this, VCLXFileControl, ModifyHdl ) );
+
+ VCLXWindow::SetWindow( pWindow );
+}
+
+void VCLXFileControl::addTextListener( const css::uno::Reference< css::awt::XTextListener > & l )
+{
+ maTextListeners.addInterface( l );
+}
+
+void VCLXFileControl::removeTextListener( const css::uno::Reference< css::awt::XTextListener > & l )
+{
+ maTextListeners.removeInterface( l );
+}
+
+void VCLXFileControl::setText( const OUString& aText )
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr<vcl::Window> pWindow = GetWindow();
+ if ( pWindow )
+ {
+ pWindow->SetText( aText );
+
+ // also in Java a textChanged is triggered, not in VCL.
+ // css::awt::Toolkit should be JAVA-compliant...
+ ModifyHdl();
+ }
+}
+
+void VCLXFileControl::insertText( const css::awt::Selection& rSel, const OUString& aText )
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl )
+ {
+ pFileControl->GetEdit().SetSelection( Selection( rSel.Min, rSel.Max ) );
+ pFileControl->GetEdit().ReplaceSelected( aText );
+ }
+}
+
+OUString VCLXFileControl::getText()
+{
+ SolarMutexGuard aGuard;
+
+ OUString aText;
+ VclPtr<vcl::Window> pWindow = GetWindow();
+ if ( pWindow )
+ aText = pWindow->GetText();
+ return aText;
+}
+
+OUString VCLXFileControl::getSelectedText()
+{
+ SolarMutexGuard aGuard;
+
+ OUString aText;
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl)
+ aText = pFileControl->GetEdit().GetSelected();
+ return aText;
+
+}
+
+void VCLXFileControl::setSelection( const css::awt::Selection& aSelection )
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl )
+ pFileControl->GetEdit().SetSelection( Selection( aSelection.Min, aSelection.Max ) );
+}
+
+css::awt::Selection VCLXFileControl::getSelection()
+{
+ SolarMutexGuard aGuard;
+
+ css::awt::Selection aSel;
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl )
+ {
+ aSel.Min = pFileControl->GetEdit().GetSelection().Min();
+ aSel.Max = pFileControl->GetEdit().GetSelection().Max();
+ }
+ return aSel;
+}
+
+sal_Bool VCLXFileControl::isEditable()
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ return pFileControl && !pFileControl->GetEdit().IsReadOnly() && pFileControl->GetEdit().IsEnabled();
+}
+
+void VCLXFileControl::setEditable( sal_Bool bEditable )
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl )
+ pFileControl->GetEdit().SetReadOnly( !bEditable );
+}
+
+void VCLXFileControl::setMaxTextLen( sal_Int16 nLen )
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ if ( pFileControl )
+ pFileControl->GetEdit().SetMaxTextLen( nLen );
+}
+
+sal_Int16 VCLXFileControl::getMaxTextLen()
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr< FileControl > pFileControl = GetAs< FileControl >();
+ return pFileControl ? pFileControl->GetEdit().GetMaxTextLen() : 0;
+}
+
+
+IMPL_LINK_NOARG(VCLXFileControl, ModifyHdl, Edit&, void)
+{
+ ModifyHdl();
+}
+
+void VCLXFileControl::ModifyHdl()
+{
+ css::awt::TextEvent aEvent;
+ aEvent.Source = static_cast<cppu::OWeakObject*>(this);
+ maTextListeners.textChanged( aEvent );
+}
+
+css::awt::Size VCLXFileControl::getMinimumSize()
+{
+ SolarMutexGuard aGuard;
+
+ css::awt::Size aSz;
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( pControl )
+ {
+ Size aTmpSize = pControl->GetEdit().CalcMinimumSize();
+ aTmpSize.AdjustWidth(pControl->GetButton().CalcMinimumSize().Width() );
+ aSz = AWTSize(pControl->CalcWindowSize( aTmpSize ));
+ }
+ return aSz;
+}
+
+css::awt::Size VCLXFileControl::getPreferredSize()
+{
+ css::awt::Size aSz = getMinimumSize();
+ aSz.Height += 4;
+ return aSz;
+}
+
+css::awt::Size VCLXFileControl::calcAdjustedSize( const css::awt::Size& rNewSize )
+{
+ SolarMutexGuard aGuard;
+
+ css::awt::Size aSz =rNewSize;
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( pControl )
+ {
+ css::awt::Size aMinSz = getMinimumSize();
+ if ( aSz.Height != aMinSz.Height )
+ aSz.Height = aMinSz.Height;
+ }
+ return aSz;
+}
+
+css::awt::Size VCLXFileControl::getMinimumSize( sal_Int16 nCols, sal_Int16 )
+{
+ SolarMutexGuard aGuard;
+
+ css::awt::Size aSz;
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( pControl )
+ {
+ aSz = AWTSize(pControl->GetEdit().CalcSize( nCols ));
+ aSz.Width += pControl->GetButton().CalcMinimumSize().Width();
+ }
+ return aSz;
+}
+
+void VCLXFileControl::getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
+{
+ SolarMutexGuard aGuard;
+
+ nCols = 0;
+ nLines = 1;
+ VclPtr< FileControl > pControl = GetAs< FileControl >();
+ if ( pControl )
+ nCols = pControl->GetEdit().GetMaxVisChars();
+}
+
+void VCLXFileControl::ImplGetPropertyIds( std::vector< sal_uInt16 > &rIds )
+{
+ PushPropertyIds( rIds,
+ // FIXME: elide duplication ?
+ BASEPROPERTY_HIDEINACTIVESELECTION,
+ 0);
+ VCLXWindow::ImplGetPropertyIds( rIds, true );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/toolkit/source/controls/filectrl.cxx b/toolkit/source/controls/filectrl.cxx
new file mode 100644
index 000000000000..3757f91da678
--- /dev/null
+++ b/toolkit/source/controls/filectrl.cxx
@@ -0,0 +1,241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <controls/filectrl.hxx>
+
+#include <com/sun/star/ui/dialogs/FilePicker.hpp>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+#include <comphelper/processfactory.hxx>
+#include <osl/file.h>
+#include <osl/diagnose.h>
+#include <svl/svlresid.hxx>
+#include <svl/svl.hrc>
+#include <tools/urlobj.hxx>
+#include <vcl/edit.hxx>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::ui;
+
+
+FileControl::FileControl( vcl::Window* pParent, WinBits nStyle ) :
+ Window( pParent, nStyle|WB_DIALOGCONTROL ),
+ maEdit( VclPtr<Edit>::Create(this, (nStyle&(~WB_BORDER))|WB_NOTABSTOP) ),
+ maButton( VclPtr<PushButton>::Create( this, (nStyle&(~WB_BORDER))|WB_NOLIGHTBORDER|WB_NOPOINTERFOCUS|WB_NOTABSTOP ) ),
+ maButtonText( SvlResId(STR_FILECTRL_BUTTONTEXT) ),
+ mnInternalFlags( FileControlMode_Internal::ORIGINALBUTTONTEXT )
+{
+ maButton->SetClickHdl( LINK( this, FileControl, ButtonHdl ) );
+
+ maButton->Show();
+ maEdit->Show();
+
+ SetCompoundControl( true );
+
+ SetStyle( ImplInitStyle( GetStyle() ) );
+}
+
+
+WinBits FileControl::ImplInitStyle( WinBits nStyle )
+{
+ if ( !( nStyle & WB_NOTABSTOP ) )
+ {
+ maEdit->SetStyle( (maEdit->GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) );
+ maButton->SetStyle( (maButton->GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) );
+ }
+ else
+ {
+ maEdit->SetStyle( (maEdit->GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) );
+ maButton->SetStyle( (maButton->GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) );
+ }
+
+ const WinBits nAlignmentStyle = ( WB_TOP | WB_VCENTER | WB_BOTTOM );
+ maEdit->SetStyle( ( maEdit->GetStyle() & ~nAlignmentStyle ) | ( nStyle & nAlignmentStyle ) );
+
+ if ( !(nStyle & WB_NOGROUP) )
+ nStyle |= WB_GROUP;
+
+ if ( !(nStyle & WB_NOBORDER ) )
+ nStyle |= WB_BORDER;
+
+ nStyle &= ~WB_TABSTOP;
+
+ return nStyle;
+}
+
+
+FileControl::~FileControl()
+{
+ disposeOnce();
+}
+
+void FileControl::dispose()
+{
+ maEdit.disposeAndClear();
+ maButton.disposeAndClear();
+ Window::dispose();
+}
+
+void FileControl::SetText( const OUString& rStr )
+{
+ maEdit->SetText( rStr );
+}
+
+
+OUString FileControl::GetText() const
+{
+ return maEdit->GetText();
+}
+
+
+void FileControl::StateChanged( StateChangedType nType )
+{
+ if ( nType == StateChangedType::Enable )
+ {
+ maEdit->Enable( IsEnabled() );
+ maButton->Enable( IsEnabled() );
+ }
+ else if ( nType == StateChangedType::Zoom )
+ {
+ GetEdit().SetZoom( GetZoom() );
+ GetButton().SetZoom( GetZoom() );
+ }
+ else if ( nType == StateChangedType::Style )
+ {
+ SetStyle( ImplInitStyle( GetStyle() ) );
+ }
+ else if ( nType == StateChangedType::ControlFont )
+ {
+ GetEdit().SetControlFont( GetControlFont() );
+ // Only use height of the button, as in HTML
+ // always Courier is used
+ vcl::Font aFont = GetButton().GetControlFont();
+ aFont.SetFontSize( GetControlFont().GetFontSize() );
+ GetButton().SetControlFont( aFont );
+ }
+ else if ( nType == StateChangedType::ControlForeground )
+ {
+ GetEdit().SetControlForeground( GetControlForeground() );
+ GetButton().SetControlForeground( GetControlForeground() );
+ }
+ else if ( nType == StateChangedType::ControlBackground )
+ {
+ GetEdit().SetControlBackground( GetControlBackground() );
+ GetButton().SetControlBackground( GetControlBackground() );
+ }
+ Window::StateChanged( nType );
+}
+
+
+void FileControl::Resize()
+{
+ static const long ButtonBorder = 10;
+
+ if( mnInternalFlags & FileControlMode_Internal::INRESIZE )
+ return;
+ mnInternalFlags |= FileControlMode_Internal::INRESIZE;//InResize = sal_True
+
+ Size aOutSz = GetOutputSizePixel();
+ long nButtonTextWidth = maButton->GetTextWidth( maButtonText );
+ if ( !(mnInternalFlags & FileControlMode_Internal::ORIGINALBUTTONTEXT) ||
+ ( nButtonTextWidth < aOutSz.Width()/3 ) )
+ {
+ maButton->SetText( maButtonText );
+ }
+ else
+ {
+ OUString aSmallText( "..." );
+ maButton->SetText( aSmallText );
+ nButtonTextWidth = maButton->GetTextWidth( aSmallText );
+ }
+
+ long nButtonWidth = nButtonTextWidth+ButtonBorder;
+ maEdit->setPosSizePixel( 0, 0, aOutSz.Width()-nButtonWidth, aOutSz.Height() );
+ maButton->setPosSizePixel( aOutSz.Width()-nButtonWidth, 0, nButtonWidth, aOutSz.Height() );
+
+ mnInternalFlags &= ~FileControlMode_Internal::INRESIZE; //InResize = sal_False
+}
+
+
+void FileControl::GetFocus()
+{
+ if (!maEdit || maEdit->IsDisposed())
+ return;
+ maEdit->GrabFocus();
+}
+
+void FileControl::SetEditModifyHdl( const Link<Edit&,void>& rLink )
+{
+ if (!maEdit || maEdit->IsDisposed())
+ return;
+ maEdit->SetModifyHdl(rLink);
+}
+
+void FileControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags nFlags )
+{
+ WinBits nOldEditStyle = GetEdit().GetStyle();
+ if ( GetStyle() & WB_BORDER )
+ GetEdit().SetStyle( nOldEditStyle|WB_BORDER );
+ GetEdit().Draw( pDev, rPos, rSize, nFlags );
+ if ( GetStyle() & WB_BORDER )
+ GetEdit().SetStyle( nOldEditStyle );
+}
+
+IMPL_LINK_NOARG(FileControl, ButtonHdl, Button*, void)
+{
+ try
+ {
+ Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
+ Reference < dialogs::XFilePicker3 > xFilePicker = dialogs::FilePicker::createWithMode( xContext, dialogs::TemplateDescription::FILEOPEN_SIMPLE );
+ // transform the system notation text into a file URL
+ OUString sSystemNotation = GetText(), sFileURL;
+ oslFileError nError = osl_getFileURLFromSystemPath( sSystemNotation.pData, &sFileURL.pData );
+ if ( nError == osl_File_E_INVAL )
+ sFileURL = GetText(); // #97709# Maybe URL is already a file URL...
+
+ //#90430# Check if URL is really a file URL
+ OUString aTmp;
+ if ( osl_getSystemPathFromFileURL( sFileURL.pData, &aTmp.pData ) == osl_File_E_None )
+ {
+ // initially set this directory
+ xFilePicker->setDisplayDirectory( sFileURL );
+ }
+
+ if ( xFilePicker->execute() )
+ {
+ Sequence < OUString > aPathSeq = xFilePicker->getSelectedFiles();
+
+ if ( aPathSeq.hasElements() )
+ {
+ OUString aNewText = aPathSeq[0];
+ INetURLObject aObj( aNewText );
+ if ( aObj.GetProtocol() == INetProtocol::File )
+ aNewText = aObj.PathToFileName();
+ SetText( aNewText );
+ maEdit->GetModifyHdl().Call( *maEdit );
+ }
+ }
+ }
+ catch( const Exception& )
+ {
+ OSL_FAIL( "FileControl::ImplBrowseFile: caught an exception while executing the file picker!" );
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */