xref: /core/cui/source/dialogs/insdlg.cxx (revision 62d1a50659bfbf472748d844fba0f58be2d11c30)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/beans/PropertyValue.hpp>
22 #include <com/sun/star/embed/EmbedStates.hpp>
23 #include <com/sun/star/embed/XInsertObjectDialog.hpp>
24 #include <com/sun/star/embed/MSOLEObjectSystemCreator.hpp>
25 #include <com/sun/star/task/InteractionHandler.hpp>
26 #include <com/sun/star/ucb/CommandAbortedException.hpp>
27 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
28 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
29 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
30 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/propertyvalue.hxx>
33 
34 #include <insdlg.hxx>
35 #include <dialmgr.hxx>
36 #include <osl/diagnose.h>
37 #include <svtools/imagemgr.hxx>
38 #include <svtools/strings.hrc>
39 #include <svtools/svtresid.hxx>
40 
41 #include <tools/urlobj.hxx>
42 #include <tools/debug.hxx>
43 #include <tools/stream.hxx>
44 #include <comphelper/diagnose_ex.hxx>
45 #include <utility>
46 #include <vcl/image.hxx>
47 #include <vcl/weld.hxx>
48 #include <vcl/svapp.hxx>
49 #include <comphelper/classids.hxx>
50 #include <sfx2/filedlghelper.hxx>
51 #include <sfx2/frmdescr.hxx>
52 #include <sfx2/viewsh.hxx>
53 #include <comphelper/seqstream.hxx>
54 #include <sfx2/viewfrm.hxx>
55 
56 #include <strings.hrc>
57 
58 using namespace ::com::sun::star;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::ui::dialogs;
62 
IsCreateNew() const63 bool InsertObjectDialog_Impl::IsCreateNew() const
64 {
65     return false;
66 }
67 
GetIconIfIconified(OUString *)68 uno::Reference< io::XInputStream > InsertObjectDialog_Impl::GetIconIfIconified( OUString* /*pGraphicMediaType*/ )
69 {
70     return uno::Reference< io::XInputStream >();
71 }
72 
InsertObjectDialog_Impl(weld::Window * pParent,const OUString & rUIXMLDescription,const OUString & rID,css::uno::Reference<css::embed::XStorage> xStorage)73 InsertObjectDialog_Impl::InsertObjectDialog_Impl(weld::Window* pParent,
74     const OUString& rUIXMLDescription, const OUString& rID,
75     css::uno::Reference < css::embed::XStorage > xStorage)
76     : GenericDialogController(pParent, rUIXMLDescription, rID)
77     , m_xStorage(std::move( xStorage ))
78     , aCnt( m_xStorage )
79 {
80 }
81 
IMPL_LINK_NOARG(SvInsertOleDlg,DoubleClickHdl,weld::TreeView &,bool)82 IMPL_LINK_NOARG(SvInsertOleDlg, DoubleClickHdl, weld::TreeView&, bool)
83 {
84     m_xDialog->response(RET_OK);
85     return true;
86 }
87 
IMPL_LINK_NOARG(SvInsertOleDlg,BrowseHdl,weld::Button &,void)88 IMPL_LINK_NOARG(SvInsertOleDlg, BrowseHdl, weld::Button&, void)
89 {
90     sfx2::FileDialogHelper aHelper(ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, m_xDialog.get());
91     aHelper.SetContext(sfx2::FileDialogHelper::InsertOLE);
92     const Reference< XFilePicker3 >& xFilePicker = aHelper.GetFilePicker();
93 
94     // add filter
95     try
96     {
97         xFilePicker->appendFilter(CuiResId(RID_CUISTR_FILTER_ALL), u"*.*"_ustr);
98     }
99     catch( const IllegalArgumentException& )
100     {
101         TOOLS_WARN_EXCEPTION("cui.dialogs", "caught IllegalArgumentException when registering filter" );
102     }
103 
104     if( xFilePicker->execute() == ExecutableDialogResults::OK )
105     {
106         Sequence< OUString > aPathSeq( xFilePicker->getSelectedFiles() );
107         INetURLObject aObj( aPathSeq[0] );
108         m_xEdFilepath->set_text(aObj.PathToFileName());
109     }
110 }
111 
IMPL_LINK(SvInsertOleDlg,RadioHdl,weld::Toggleable &,rButton,void)112 IMPL_LINK(SvInsertOleDlg, RadioHdl, weld::Toggleable&, rButton, void)
113 {
114     if (!rButton.get_active())
115         return;
116 
117     if (m_xRbNewObject->get_active())
118     {
119         m_xObjectTypeFrame->show();
120         m_xFileFrame->hide();
121     }
122     else
123     {
124         m_xFileFrame->show();
125         m_xObjectTypeFrame->hide();
126     }
127 }
128 
SvInsertOleDlg(weld::Window * pParent,const Reference<embed::XStorage> & xStorage,const SvObjectServerList * pServers)129 SvInsertOleDlg::SvInsertOleDlg(weld::Window* pParent, const Reference<embed::XStorage>& xStorage,
130         const SvObjectServerList* pServers)
131     : InsertObjectDialog_Impl( pParent, u"cui/ui/insertoleobject.ui"_ustr, u"InsertOLEObjectDialog"_ustr, xStorage)
132     , m_pServers( pServers )
133     , m_xRbNewObject(m_xBuilder->weld_radio_button(u"createnew"_ustr))
134     , m_xRbObjectFromfile(m_xBuilder->weld_radio_button(u"createfromfile"_ustr))
135     , m_xObjectTypeFrame(m_xBuilder->weld_frame(u"objecttypeframe"_ustr))
136     , m_xLbObjecttype(m_xBuilder->weld_tree_view(u"types"_ustr))
137     , m_xFileFrame(m_xBuilder->weld_frame(u"fileframe"_ustr))
138     , m_xEdFilepath(m_xBuilder->weld_entry(u"urled"_ustr))
139     , m_xBtnFilepath(m_xBuilder->weld_button(u"urlbtn"_ustr))
140     , m_xCbFilelink(m_xBuilder->weld_check_button(u"linktofile"_ustr))
141     , m_xCbAsIcon(m_xBuilder->weld_check_button(u"asicon"_ustr))
142 {
143     m_xLbObjecttype->set_size_request(m_xLbObjecttype->get_approximate_digit_width() * 32,
144                                       m_xLbObjecttype->get_height_rows(6));
145     m_xLbObjecttype->connect_row_activated(LINK(this, SvInsertOleDlg, DoubleClickHdl));
146     m_xBtnFilepath->connect_clicked(LINK( this, SvInsertOleDlg, BrowseHdl));
147     Link<weld::Toggleable&,void> aLink( LINK( this, SvInsertOleDlg, RadioHdl ) );
148     m_xRbNewObject->connect_toggled( aLink );
149     m_xRbObjectFromfile->connect_toggled( aLink );
150     m_xRbNewObject->set_active(true);
151 }
152 
run()153 short SvInsertOleDlg::run()
154 {
155     short nRet = RET_OK;
156     SvObjectServerList  aObjS;
157     if ( !m_pServers )
158     {
159         // if no list was provided, take the complete one
160         aObjS.FillInsertObjects();
161         m_pServers = &aObjS;
162     }
163 
164     // fill listbox and select default
165     m_xLbObjecttype->freeze();
166     for ( size_t i = 0; i < m_pServers->Count(); i++ )
167         m_xLbObjecttype->append_text((*m_pServers)[i].GetHumanName());
168     m_xLbObjecttype->thaw();
169     m_xLbObjecttype->select(0);
170 
171     DBG_ASSERT( m_xStorage.is(), "No storage!");
172     if ( m_xStorage.is() && ( nRet = InsertObjectDialog_Impl::run() ) == RET_OK )
173     {
174         OUString aFileName;
175         OUString aName;
176         bool bCreateNew = IsCreateNew();
177         if ( bCreateNew )
178         {
179             // create and insert new embedded object
180             OUString aServerName = m_xLbObjecttype->get_selected_text();
181             const SvObjectServer* pS = m_pServers->Get( aServerName );
182             if ( pS )
183             {
184                 if( pS->GetClassName() == SvGlobalName( SO3_OUT_CLASSID ) )
185                 {
186                     try
187                     {
188                         uno::Reference < embed::XInsertObjectDialog > xDialogCreator(
189                             embed::MSOLEObjectSystemCreator::create( ::comphelper::getProcessComponentContext() ),
190                             uno::UNO_QUERY );
191 
192                         if ( xDialogCreator.is() )
193                         {
194                             aName = aCnt.CreateUniqueObjectName();
195 
196                             uno::Reference<task::XStatusIndicator> xProgress;
197                             OUString aProgressText;
198                             if (SfxViewFrame* pFrame = SfxViewFrame::Current())
199                             {
200                                 // Have a current frame, create a matching progressbar, but don't start it yet.
201                                 uno::Reference<frame::XFrame> xFrame
202                                     = pFrame->GetFrame().GetFrameInterface();
203                                 uno::Reference<task::XStatusIndicatorFactory> xProgressFactory(
204                                     xFrame, uno::UNO_QUERY);
205                                 if (xProgressFactory.is())
206                                 {
207                                     xProgress = xProgressFactory->createStatusIndicator();
208                                     if (xProgress)
209                                     {
210                                         aProgressText = CuiResId(RID_CUISTR_OLE_INSERT);
211                                     }
212                                 }
213                             }
214 
215                             const embed::InsertedObjectInfo aNewInf = xDialogCreator->createInstanceByDialog(
216                                                                     m_xStorage,
217                                                                     aName,
218                                                                     {comphelper::makePropertyValue(u"StatusIndicator"_ustr, xProgress),
219                                                                      comphelper::makePropertyValue(u"StatusIndicatorText"_ustr, aProgressText)} );
220 
221                             OSL_ENSURE( aNewInf.Object.is(), "The object must be created or an exception must be thrown!" );
222                             m_xObj = aNewInf.Object;
223                             for ( const auto& opt : aNewInf.Options )
224                                 if ( opt.Name == "Icon" )
225                                 {
226                                     opt.Value >>= m_aIconMetaFile;
227                                 }
228                                 else if ( opt.Name == "IconFormat" )
229                                 {
230                                     datatransfer::DataFlavor aFlavor;
231                                     if ( opt.Value >>= aFlavor )
232                                         m_aIconMediaType = aFlavor.MimeType;
233                                 }
234 
235                         }
236                     }
237                     catch( ucb::CommandAbortedException& )
238                     {
239                         // the user has pressed cancel
240                     }
241                     catch( uno::Exception& )
242                     {
243                         // TODO: Error handling
244                     }
245                 }
246                 else
247                 {
248                     // create object with desired ClassId
249                     m_xObj = aCnt.CreateEmbeddedObject( pS->GetClassName().GetByteSequence(), aName );
250                 }
251 
252                 if ( !m_xObj.is() )
253                 {
254                     if( !aFileName.isEmpty() )  // from OLE Dialog
255                     {
256                         // object couldn't be created from file
257                         // global Resource from svtools (former so3 resource)
258                         OUString aErr(SvtResId(STR_ERROR_OBJNOCREATE_FROM_FILE));
259                         aErr = aErr.replaceFirst( "%", aFileName );
260 
261                         std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
262                                                                   VclMessageType::Warning, VclButtonsType::Ok, aErr));
263                         xBox->run();
264                     }
265                     else
266                     {
267                         // object couldn't be created
268                         // global Resource from svtools (former so3 resource)
269                         OUString aErr(SvtResId(STR_ERROR_OBJNOCREATE));
270                         aErr = aErr.replaceFirst( "%", aServerName );
271 
272                         std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
273                                                                   VclMessageType::Warning, VclButtonsType::Ok, aErr));
274                         xBox->run();
275                     }
276                 }
277             }
278         }
279         else
280         {
281             aFileName = m_xEdFilepath->get_text();
282             INetURLObject aURL;
283             aURL.SetSmartProtocol( INetProtocol::File );
284             aURL.SetSmartURL( aFileName );
285             aFileName = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
286             bool bLink = m_xCbFilelink->get_active();
287 
288             if ( !aFileName.isEmpty() )
289             {
290                 const uno::Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
291                 uno::Reference< task::XInteractionHandler2 > xInteraction(
292                     task::InteractionHandler::createWithParent(xContext, nullptr) );
293 
294                 // create MediaDescriptor for file to create object from
295                 uno::Sequence < beans::PropertyValue > aMedium{
296                     comphelper::makePropertyValue(u"URL"_ustr, aFileName),
297                     comphelper::makePropertyValue(u"InteractionHandler"_ustr, xInteraction)
298                 };
299 
300                 // create object from media descriptor
301 
302                 uno::Reference<task::XStatusIndicator> xProgress;
303                 if (SfxViewFrame* pFrame = SfxViewFrame::Current())
304                 {
305                     // Have a current frame, create visual indication that insert is in progress.
306                     uno::Reference<frame::XFrame> xFrame = pFrame->GetFrame().GetFrameInterface();
307                     uno::Reference<task::XStatusIndicatorFactory> xProgressFactory(xFrame, uno::UNO_QUERY);
308                     if (xProgressFactory.is())
309                     {
310                         xProgress = xProgressFactory->createStatusIndicator();
311                         if (xProgress)
312                         {
313                             OUString aOleInsert(CuiResId(RID_CUISTR_OLE_INSERT));
314                             xProgress->start(aOleInsert, 100);
315                         }
316                     }
317                 }
318 
319                 if ( bLink )
320                     m_xObj = aCnt.InsertEmbeddedLink( aMedium, aName );
321                 else
322                     m_xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
323 
324                 if (xProgress.is())
325                 {
326                     xProgress->end();
327                 }
328             }
329 
330             if ( !m_xObj.is() )
331             {
332                 // object couldn't be created from file
333                 // global Resource from svtools (former so3 resource)
334                 OUString aErr(SvtResId(STR_ERROR_OBJNOCREATE_FROM_FILE));
335                 aErr = aErr.replaceFirst( "%", aFileName );
336 
337                 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(),
338                                                           VclMessageType::Warning, VclButtonsType::Ok, aErr));
339                 xBox->run();
340             }
341             else
342             {
343                 if (m_xCbAsIcon->get_active())
344                 {
345                     //something nice here I guess would be to write the filename into
346                     //the image with this icon above it
347                     Image aImage = SvFileInformationManager::GetImage(aURL, true);
348                     SvMemoryStream aTemp;
349                     WriteDIBBitmapEx(BitmapEx(aImage.GetBitmap()), aTemp);
350                     m_aIconMetaFile = Sequence<sal_Int8>(static_cast<const sal_Int8*>(aTemp.GetData()), aTemp.TellEnd());
351                     m_aIconMediaType = "application/x-openoffice-bitmap;windows_formatname=\"Bitmap\"";
352                 }
353             }
354         }
355     }
356 
357     m_pServers = nullptr;
358     return nRet;
359 }
360 
GetIconIfIconified(OUString * pGraphicMediaType)361 uno::Reference< io::XInputStream > SvInsertOleDlg::GetIconIfIconified( OUString* pGraphicMediaType )
362 {
363     if ( m_aIconMetaFile.hasElements() )
364     {
365         if ( pGraphicMediaType )
366             *pGraphicMediaType = m_aIconMediaType;
367 
368         return uno::Reference< io::XInputStream >( new ::comphelper::SequenceInputStream( m_aIconMetaFile ) );
369     }
370 
371     return uno::Reference< io::XInputStream >();
372 }
373 
374 
SfxInsertFloatingFrameDialog(weld::Window * pParent,const css::uno::Reference<css::embed::XStorage> & xStorage)375 SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog(weld::Window *pParent,
376                             const css::uno::Reference < css::embed::XStorage >& xStorage)
377     : InsertObjectDialog_Impl(pParent, u"cui/ui/insertfloatingframe.ui"_ustr, u"InsertFloatingFrameDialog"_ustr,
378                               xStorage)
379 {
380     Init();
381 }
382 
SfxInsertFloatingFrameDialog(weld::Window * pParent,const uno::Reference<embed::XEmbeddedObject> & xObj)383 SfxInsertFloatingFrameDialog::SfxInsertFloatingFrameDialog(weld::Window *pParent,
384                             const uno::Reference < embed::XEmbeddedObject >& xObj)
385     : InsertObjectDialog_Impl(pParent, u"cui/ui/insertfloatingframe.ui"_ustr, u"InsertFloatingFrameDialog"_ustr,
386                               uno::Reference<embed::XStorage>())
387 {
388     m_xObj = xObj;
389 
390     Init();
391 }
392 
Init()393 void SfxInsertFloatingFrameDialog::Init()
394 {
395     m_xEDName = m_xBuilder->weld_entry(u"edname"_ustr);
396     m_xEDURL = m_xBuilder->weld_entry(u"edurl"_ustr);
397     m_xBTOpen = m_xBuilder->weld_button(u"buttonbrowse"_ustr);
398     m_xRBScrollingOn = m_xBuilder->weld_radio_button(u"scrollbaron"_ustr);
399     m_xRBScrollingOff = m_xBuilder->weld_radio_button(u"scrollbaroff"_ustr);
400     m_xRBScrollingAuto = m_xBuilder->weld_radio_button(u"scrollbarauto"_ustr);
401     m_xRBFrameBorderOn = m_xBuilder->weld_radio_button(u"borderon"_ustr);
402     m_xRBFrameBorderOff = m_xBuilder->weld_radio_button(u"borderoff"_ustr);
403     m_xFTMarginWidth = m_xBuilder->weld_label(u"widthlabel"_ustr);
404     m_xNMMarginWidth = m_xBuilder->weld_spin_button(u"width"_ustr);
405     m_xCBMarginWidthDefault = m_xBuilder->weld_check_button(u"defaultwidth"_ustr);
406     m_xFTMarginHeight = m_xBuilder->weld_label(u"heightlabel"_ustr);
407     m_xNMMarginHeight = m_xBuilder->weld_spin_button(u"height"_ustr);
408     m_xCBMarginHeightDefault = m_xBuilder->weld_check_button(u"defaultheight"_ustr);
409 
410     Link<weld::Toggleable&, void> aLink(LINK(this, SfxInsertFloatingFrameDialog, CheckHdl));
411     m_xCBMarginWidthDefault->connect_toggled(aLink);
412     m_xCBMarginHeightDefault->connect_toggled(aLink);
413 
414     m_xCBMarginWidthDefault->set_active(true);
415     m_xCBMarginHeightDefault->set_active(true);
416     m_xRBScrollingAuto->set_active(true);
417     m_xRBFrameBorderOn->set_active(true);
418 
419     m_xBTOpen->connect_clicked(LINK(this, SfxInsertFloatingFrameDialog, OpenHdl));
420 }
421 
run()422 short SfxInsertFloatingFrameDialog::run()
423 {
424     short nRet = RET_OK;
425     bool bOK = false;
426     uno::Reference < beans::XPropertySet > xSet;
427     if ( m_xObj.is() )
428     {
429         try
430         {
431             if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
432                 m_xObj->changeState( embed::EmbedStates::RUNNING );
433             xSet.set( m_xObj->getComponent(), uno::UNO_QUERY );
434             OUString aStr;
435             uno::Any aAny = xSet->getPropertyValue( u"FrameURL"_ustr );
436             if ( aAny >>= aStr )
437                 m_xEDURL->set_text( aStr );
438             aAny = xSet->getPropertyValue( u"FrameName"_ustr );
439             if ( aAny >>= aStr )
440                 m_xEDName->set_text(aStr);
441 
442             sal_Int32 nSize = SIZE_NOT_SET;
443             aAny = xSet->getPropertyValue( u"FrameMarginWidth"_ustr );
444             aAny >>= nSize;
445 
446             if ( nSize == SIZE_NOT_SET )
447             {
448                 m_xCBMarginWidthDefault->set_active(true);
449                 m_xNMMarginWidth->set_text(OUString::number(DEFAULT_MARGIN_WIDTH));
450                 m_xFTMarginWidth->set_sensitive(false);
451                 m_xNMMarginWidth->set_sensitive(false);
452             }
453             else
454                 m_xNMMarginWidth->set_text(OUString::number(nSize));
455 
456             aAny = xSet->getPropertyValue( u"FrameMarginHeight"_ustr );
457             aAny >>= nSize;
458 
459             if ( nSize == SIZE_NOT_SET )
460             {
461                 m_xCBMarginHeightDefault->set_active(true);
462                 m_xNMMarginHeight->set_text(OUString::number(DEFAULT_MARGIN_HEIGHT));
463                 m_xFTMarginHeight->set_sensitive(false);
464                 m_xNMMarginHeight->set_sensitive(false);
465             }
466             else
467                 m_xNMMarginHeight->set_text(OUString::number(nSize));
468 
469             bool bScrollOn = false;
470             bool bScrollOff = false;
471             bool bScrollAuto = false;
472 
473             bool bSet = false;
474             aAny = xSet->getPropertyValue( u"FrameIsAutoScroll"_ustr );
475             aAny >>= bSet;
476             if ( !bSet )
477             {
478                 aAny = xSet->getPropertyValue( u"FrameIsScrollingMode"_ustr );
479                 aAny >>= bSet;
480                 bScrollOn = bSet;
481                 bScrollOff = !bSet;
482             }
483             else
484                 bScrollAuto = true;
485 
486             m_xRBScrollingOn->set_sensitive(bScrollOn);
487             m_xRBScrollingOff->set_sensitive(bScrollOff);
488             m_xRBScrollingAuto->set_sensitive(bScrollAuto);
489 
490             bSet = false;
491             aAny = xSet->getPropertyValue( u"FrameIsAutoBorder"_ustr );
492             aAny >>= bSet;
493             if ( !bSet )
494             {
495                 aAny = xSet->getPropertyValue( u"FrameIsBorder"_ustr );
496                 aAny >>= bSet;
497                 m_xRBFrameBorderOn->set_active(bSet);
498                 m_xRBFrameBorderOff->set_active(!bSet);
499             }
500 
501             bOK = true;
502         }
503         catch ( uno::Exception& )
504         {
505             OSL_FAIL( "No IFrame!" );
506         }
507     }
508     else
509     {
510         DBG_ASSERT( m_xStorage.is(), "No storage!");
511         bOK = m_xStorage.is();
512     }
513 
514     if (!bOK)
515         return RET_OK;
516 
517     nRet = InsertObjectDialog_Impl::run();
518     if ( nRet == RET_OK )
519     {
520         OUString aURL;
521         if (!m_xEDURL->get_text().isEmpty())
522         {
523             // URL can be a valid and absolute URL or a system file name
524             INetURLObject aObj;
525             aObj.SetSmartProtocol( INetProtocol::File );
526             if ( aObj.SetSmartURL( m_xEDURL->get_text() ) )
527                 aURL = aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE );
528         }
529 
530         if ( !m_xObj.is() && !aURL.isEmpty() )
531         {
532             // create the object
533             OUString aName;
534             SvGlobalName aClassId( SO3_IFRAME_CLASSID );
535             m_xObj = aCnt.CreateEmbeddedObject( aClassId.GetByteSequence(), aName );
536             if ( m_xObj->getCurrentState() == embed::EmbedStates::LOADED )
537                 m_xObj->changeState( embed::EmbedStates::RUNNING );
538             xSet.set( m_xObj->getComponent(), uno::UNO_QUERY );
539         }
540 
541         if ( m_xObj.is() )
542         {
543             try
544             {
545                 bool bIPActive = m_xObj->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE;
546                 if ( bIPActive )
547                     m_xObj->changeState( embed::EmbedStates::RUNNING );
548 
549                 OUString aName = m_xEDName->get_text();
550                 ScrollingMode eScroll = ScrollingMode::No;
551                 if (m_xRBScrollingOn->get_active())
552                     eScroll = ScrollingMode::Yes;
553                 if (m_xRBScrollingOff->get_active())
554                     eScroll = ScrollingMode::No;
555                 if (m_xRBScrollingAuto->get_active())
556                     eScroll = ScrollingMode::Auto;
557 
558                 bool bHasBorder = m_xRBFrameBorderOn->get_active();
559 
560                 tools::Long lMarginWidth;
561                 if (!m_xCBMarginWidthDefault->get_active())
562                     lMarginWidth = static_cast<tools::Long>(m_xNMMarginWidth->get_text().toInt32());
563                 else
564                     lMarginWidth = SIZE_NOT_SET;
565 
566                 tools::Long lMarginHeight;
567                 if (!m_xCBMarginHeightDefault->get_active())
568                     lMarginHeight = static_cast<tools::Long>(m_xNMMarginHeight->get_text().toInt32());
569                 else
570                     lMarginHeight = SIZE_NOT_SET;
571 
572                 xSet->setPropertyValue( u"FrameURL"_ustr, Any( aURL ) );
573                 xSet->setPropertyValue( u"FrameName"_ustr, Any( aName ) );
574 
575                 if ( eScroll == ScrollingMode::Auto )
576                     xSet->setPropertyValue( u"FrameIsAutoScroll"_ustr, Any( true ) );
577                 else
578                     xSet->setPropertyValue( u"FrameIsScrollingMode"_ustr, Any( eScroll == ScrollingMode::Yes ) );
579 
580                 xSet->setPropertyValue( u"FrameIsBorder"_ustr, Any( bHasBorder ) );
581                 xSet->setPropertyValue( u"FrameMarginWidth"_ustr, Any( sal_Int32( lMarginWidth ) ) );
582                 xSet->setPropertyValue( u"FrameMarginHeight"_ustr, Any( sal_Int32( lMarginHeight ) ) );
583 
584                 if ( bIPActive )
585                     m_xObj->changeState( embed::EmbedStates::INPLACE_ACTIVE );
586             }
587             catch ( uno::Exception& )
588             {
589                 OSL_FAIL( "No IFrame!" );
590             }
591         }
592     }
593 
594     return nRet;
595 }
596 
IMPL_LINK(SfxInsertFloatingFrameDialog,CheckHdl,weld::Toggleable &,rButton,void)597 IMPL_LINK(SfxInsertFloatingFrameDialog, CheckHdl, weld::Toggleable&, rButton, void)
598 {
599     weld::CheckButton& rCB = dynamic_cast<weld::CheckButton&>(rButton);
600     if (&rCB == m_xCBMarginWidthDefault.get())
601     {
602         if (rCB.get_active())
603             m_xNMMarginWidth->set_text(OUString::number(DEFAULT_MARGIN_WIDTH));
604         m_xFTMarginWidth->set_sensitive(!rCB.get_active());
605         m_xNMMarginWidth->set_sensitive(!rCB.get_active());
606     }
607 
608     if (&rCB == m_xCBMarginHeightDefault.get())
609     {
610         if (rCB.get_active())
611             m_xNMMarginHeight->set_text(OUString::number(DEFAULT_MARGIN_HEIGHT));
612         m_xFTMarginHeight->set_sensitive(!rCB.get_active());
613         m_xNMMarginHeight->set_sensitive(!rCB.get_active());
614     }
615 }
616 
IMPL_LINK_NOARG(SfxInsertFloatingFrameDialog,OpenHdl,weld::Button &,void)617 IMPL_LINK_NOARG( SfxInsertFloatingFrameDialog, OpenHdl, weld::Button&, void)
618 {
619     // create the file dialog
620     sfx2::FileDialogHelper aFileDlg(
621             ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, OUString(),
622             SfxFilterFlags::NONE, SfxFilterFlags::NONE, m_xDialog.get());
623 
624     // set the title
625     aFileDlg.SetTitle(CuiResId(RID_CUISTR_SELECT_FILE_IFRAME));
626 
627     // show the dialog
628     if ( aFileDlg.Execute() == ERRCODE_NONE )
629         m_xEDURL->set_text(INetURLObject(aFileDlg.GetPath()).GetMainURL(INetURLObject::DecodeMechanism::WithCharset));
630 }
631 
632 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
633