bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / dlg / tpaction.cxx
blob5edca44aa8a396778d6f9c1f86c1d93d32716250
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 <svx/svxids.hrc>
21 #include <com/sun/star/presentation/ClickAction.hpp>
22 #include <com/sun/star/embed/NeedsRunningStateException.hpp>
23 #include <com/sun/star/embed/VerbDescriptor.hpp>
24 #include <com/sun/star/embed/EmbedStates.hpp>
25 #include <com/sun/star/embed/XEmbeddedObject.hpp>
26 #include <comphelper/string.hxx>
27 #include <com/sun/star/embed/VerbAttributes.hpp>
28 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 #include <sdattr.hrc>
31 #include <sfx2/sfxresid.hxx>
32 #include <sfx2/strings.hrc>
34 #include <tools/debug.hxx>
35 #include <vcl/waitobj.hxx>
36 #include <sfx2/app.hxx>
37 #include <unotools/pathoptions.hxx>
38 #include <svx/svdograf.hxx>
39 #include <svl/aeitem.hxx>
40 #include <svl/stritem.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <sfx2/docfile.hxx>
43 #include <svx/xtable.hxx>
44 #include <vcl/mnemonic.hxx>
45 #include <vcl/lstbox.hxx>
46 #include <svl/urihelper.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include <svx/drawitem.hxx>
49 #include <View.hxx>
50 #include <sdresid.hxx>
51 #include <tpaction.hxx>
52 #include <strmname.h>
53 #include <ViewShell.hxx>
54 #include <drawdoc.hxx>
55 #include <DrawDocShell.hxx>
56 #include <strings.hrc>
58 #include <filedlg.hxx>
60 #include <algorithm>
62 using namespace ::com::sun::star;
63 using namespace com::sun::star::uno;
64 using namespace com::sun::star::lang;
66 #define DOCUMENT_TOKEN '#'
68 /**
69 * Constructor of the Tab dialog: appends the pages to the dialog
71 SdActionDlg::SdActionDlg(weld::Window* pParent, const SfxItemSet* pAttr, ::sd::View const * pView)
72 : SfxSingleTabDialogController(pParent, pAttr, "modules/simpress/ui/interactiondialog.ui",
73 "InteractionDialog")
74 , rOutAttrs(*pAttr)
76 TabPageParent aParent(get_content_area(), this);
77 VclPtr<SfxTabPage> xNewPage = SdTPAction::Create(aParent, rOutAttrs);
79 // formerly in PageCreated
80 static_cast<SdTPAction*>( xNewPage.get() )->SetView( pView );
81 static_cast<SdTPAction*>( xNewPage.get() )->Construct();
83 SetTabPage(xNewPage);
86 /**
87 * Action-TabPage
89 SdTPAction::SdTPAction(TabPageParent pWindow, const SfxItemSet& rInAttrs)
90 : SfxTabPage(pWindow, "modules/simpress/ui/interactionpage.ui", "InteractionPage", &rInAttrs)
91 , mpView(nullptr)
92 , mpDoc(nullptr)
93 , bTreeUpdated(false)
94 , m_xLbAction(m_xBuilder->weld_combo_box("listbox"))
95 , m_xFtTree(m_xBuilder->weld_label("fttree"))
96 , m_xLbTree(new SdPageObjsTLV(m_xBuilder->weld_tree_view("tree")))
97 , m_xLbTreeDocument(new SdPageObjsTLV(m_xBuilder->weld_tree_view("treedoc")))
98 , m_xLbOLEAction(m_xBuilder->weld_tree_view("oleaction"))
99 , m_xFrame(m_xBuilder->weld_frame("frame"))
100 , m_xEdtSound(m_xBuilder->weld_entry("sound"))
101 , m_xEdtBookmark(m_xBuilder->weld_entry("bookmark"))
102 , m_xEdtDocument(m_xBuilder->weld_entry("document"))
103 , m_xEdtProgram(m_xBuilder->weld_entry("program"))
104 , m_xEdtMacro(m_xBuilder->weld_entry("macro"))
105 , m_xBtnSearch(m_xBuilder->weld_button("browse"))
106 , m_xBtnSeek(m_xBuilder->weld_button("find"))
108 m_xLbOLEAction->set_size_request(m_xLbOLEAction->get_approximate_digit_width() * 48,
109 m_xLbOLEAction->get_height_rows(12));
111 m_xBtnSearch->connect_clicked( LINK( this, SdTPAction, ClickSearchHdl ) );
112 m_xBtnSeek->connect_clicked( LINK( this, SdTPAction, ClickSearchHdl ) );
114 // this page needs ExchangeSupport
115 SetExchangeSupport();
117 m_xLbAction->connect_changed( LINK( this, SdTPAction, ClickActionHdl ) );
118 m_xLbTree->connect_changed( LINK( this, SdTPAction, SelectTreeHdl ) );
119 m_xEdtDocument->connect_focus_out( LINK( this, SdTPAction, CheckFileHdl ) );
120 m_xEdtMacro->connect_focus_out( LINK( this, SdTPAction, CheckFileHdl ) );
122 //Lock to initial max size
123 Size aSize(m_xContainer->get_preferred_size());
124 m_xContainer->set_size_request(aSize.Width(), aSize.Height());
126 ClickActionHdl( *m_xLbAction );
129 SdTPAction::~SdTPAction()
131 disposeOnce();
134 void SdTPAction::SetView( const ::sd::View* pSdView )
136 mpView = pSdView;
138 // get ColorTable and fill ListBox
139 ::sd::DrawDocShell* pDocSh = mpView->GetDocSh();
140 if( pDocSh && pDocSh->GetViewShell() )
142 mpDoc = pDocSh->GetDoc();
143 SfxViewFrame* pFrame = pDocSh->GetViewShell()->GetViewFrame();
144 m_xLbTree->SetViewFrame( pFrame );
145 m_xLbTreeDocument->SetViewFrame( pFrame );
147 pColList = pDocSh->GetItem( SID_COLOR_TABLE )->GetColorList();
148 DBG_ASSERT( pColList.is(), "No color table available!" );
150 else
152 OSL_FAIL("sd::SdTPAction::SetView(), no docshell or viewshell?");
156 void SdTPAction::Construct()
158 // fill OLE-Actionlistbox
159 SdrOle2Obj* pOleObj = nullptr;
160 SdrGrafObj* pGrafObj = nullptr;
161 bool bOLEAction = false;
163 if ( mpView->AreObjectsMarked() )
165 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
166 SdrObject* pObj;
168 if (rMarkList.GetMarkCount() == 1)
170 SdrMark* pMark = rMarkList.GetMark(0);
171 pObj = pMark->GetMarkedSdrObj();
173 SdrInventor nInv = pObj->GetObjInventor();
174 sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
176 if (nInv == SdrInventor::Default && nSdrObjKind == OBJ_OLE2)
178 pOleObj = static_cast<SdrOle2Obj*>(pObj);
180 else if (nInv == SdrInventor::Default && nSdrObjKind == OBJ_GRAF)
182 pGrafObj = static_cast<SdrGrafObj*>(pObj);
186 if( pGrafObj )
188 bOLEAction = true;
190 aVerbVector.push_back( 0 );
191 m_xLbOLEAction->append_text( MnemonicGenerator::EraseAllMnemonicChars( SdResId( STR_EDIT_OBJ ) ) );
193 else if( pOleObj )
195 const uno::Reference < embed::XEmbeddedObject >& xObj = pOleObj->GetObjRef();
196 if ( xObj.is() )
198 bOLEAction = true;
199 uno::Sequence < embed::VerbDescriptor > aVerbs;
202 aVerbs = xObj->getSupportedVerbs();
204 catch ( embed::NeedsRunningStateException& )
206 xObj->changeState( embed::EmbedStates::RUNNING );
207 aVerbs = xObj->getSupportedVerbs();
210 for( sal_Int32 i=0; i<aVerbs.getLength(); i++ )
212 embed::VerbDescriptor aVerb = aVerbs[i];
213 if( aVerb.VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
215 OUString aTmp( aVerb.VerbName );
216 aVerbVector.push_back( aVerb.VerbID );
217 m_xLbOLEAction->append_text( MnemonicGenerator::EraseAllMnemonicChars( aTmp ) );
223 maCurrentActions.push_back( presentation::ClickAction_NONE );
224 maCurrentActions.push_back( presentation::ClickAction_PREVPAGE );
225 maCurrentActions.push_back( presentation::ClickAction_NEXTPAGE );
226 maCurrentActions.push_back( presentation::ClickAction_FIRSTPAGE );
227 maCurrentActions.push_back( presentation::ClickAction_LASTPAGE );
228 maCurrentActions.push_back( presentation::ClickAction_BOOKMARK );
229 maCurrentActions.push_back( presentation::ClickAction_DOCUMENT );
230 maCurrentActions.push_back( presentation::ClickAction_SOUND );
231 if( bOLEAction && m_xLbOLEAction->n_children() )
232 maCurrentActions.push_back( presentation::ClickAction_VERB );
233 maCurrentActions.push_back( presentation::ClickAction_PROGRAM );
234 maCurrentActions.push_back( presentation::ClickAction_MACRO );
235 maCurrentActions.push_back( presentation::ClickAction_STOPPRESENTATION );
237 // fill Action-Listbox
238 for (presentation::ClickAction & rAction : maCurrentActions)
240 const char* pRId = GetClickActionSdResId(rAction);
241 m_xLbAction->append_text(SdResId(pRId));
246 bool SdTPAction::FillItemSet( SfxItemSet* rAttrs )
248 bool bModified = false;
249 presentation::ClickAction eCA = presentation::ClickAction_NONE;
251 if (m_xLbAction->get_active() != -1)
252 eCA = GetActualClickAction();
254 if( m_xLbAction->get_value_changed_from_saved() )
256 rAttrs->Put( SfxAllEnumItem( ATTR_ACTION, static_cast<sal_uInt16>(eCA) ) );
257 bModified = true;
259 else
260 rAttrs->InvalidateItem( ATTR_ACTION );
262 OUString aFileName = GetEditText( true );
263 if( aFileName.isEmpty() )
264 rAttrs->InvalidateItem( ATTR_ACTION_FILENAME );
265 else
267 if( mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
269 OUString aBaseURL = mpDoc->GetDocSh()->GetMedium()->GetBaseURL();
270 if( eCA == presentation::ClickAction_SOUND ||
271 eCA == presentation::ClickAction_DOCUMENT ||
272 eCA == presentation::ClickAction_PROGRAM )
273 aFileName = ::URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aFileName, URIHelper::GetMaybeFileHdl(), true, false,
274 INetURLObject::EncodeMechanism::WasEncoded,
275 INetURLObject::DecodeMechanism::Unambiguous );
277 rAttrs->Put( SfxStringItem( ATTR_ACTION_FILENAME, aFileName ) );
278 bModified = true;
280 else
282 OSL_FAIL("sd::SdTPAction::FillItemSet(), I need a medium!");
286 return bModified;
289 void SdTPAction::Reset( const SfxItemSet* rAttrs )
291 presentation::ClickAction eCA = presentation::ClickAction_NONE;
292 OUString aFileName;
294 // m_xLbAction
295 if( rAttrs->GetItemState( ATTR_ACTION ) != SfxItemState::DONTCARE )
297 eCA = static_cast<presentation::ClickAction>(static_cast<const SfxAllEnumItem&>( rAttrs->
298 Get( ATTR_ACTION ) ).GetValue());
299 SetActualClickAction( eCA );
301 else
302 m_xLbAction->set_active(-1);
304 // m_xEdtSound
305 if( rAttrs->GetItemState( ATTR_ACTION_FILENAME ) != SfxItemState::DONTCARE )
307 aFileName = static_cast<const SfxStringItem&>( rAttrs->Get( ATTR_ACTION_FILENAME ) ).GetValue();
308 SetEditText( aFileName );
311 switch( eCA )
313 case presentation::ClickAction_BOOKMARK:
315 if (!m_xLbTree->SelectEntry(aFileName))
316 m_xLbTree->unselect_all();
318 break;
320 case presentation::ClickAction_DOCUMENT:
322 if( comphelper::string::getTokenCount(aFileName, DOCUMENT_TOKEN) == 2 )
323 m_xLbTreeDocument->SelectEntry( aFileName.getToken( 1, DOCUMENT_TOKEN ) );
325 break;
327 default:
328 break;
330 ClickActionHdl( *m_xLbAction );
332 m_xLbAction->save_value();
333 m_xEdtSound->save_value();
336 void SdTPAction::ActivatePage( const SfxItemSet& )
340 DeactivateRC SdTPAction::DeactivatePage( SfxItemSet* pPageSet )
342 if( pPageSet )
343 FillItemSet( pPageSet );
345 return DeactivateRC::LeavePage;
348 VclPtr<SfxTabPage> SdTPAction::Create( TabPageParent pParent,
349 const SfxItemSet& rAttrs )
351 return VclPtr<SdTPAction>::Create( pParent, rAttrs );
354 void SdTPAction::UpdateTree()
356 if( !bTreeUpdated && mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
358 m_xLbTree->Fill( mpDoc, true, mpDoc->GetDocSh()->GetMedium()->GetName() );
359 bTreeUpdated = true;
363 void SdTPAction::OpenFileDialog()
365 // Soundpreview only for interaction with sound
366 presentation::ClickAction eCA = GetActualClickAction();
367 bool bSound = ( eCA == presentation::ClickAction_SOUND );
368 bool bPage = ( eCA == presentation::ClickAction_BOOKMARK );
369 bool bDocument = ( eCA == presentation::ClickAction_DOCUMENT ||
370 eCA == presentation::ClickAction_PROGRAM );
371 bool bMacro = ( eCA == presentation::ClickAction_MACRO );
373 if( bPage )
375 // search in the TreeLB for the specified object
376 m_xLbTree->SelectEntry(GetEditText());
378 else
380 OUString aFile( GetEditText() );
382 if (bSound)
384 SdOpenSoundFileDialog aFileDialog(GetDialogFrameWeld());
386 if( !aFile.isEmpty() )
387 aFileDialog.SetPath( aFile );
389 if( aFileDialog.Execute() == ERRCODE_NONE )
391 aFile = aFileDialog.GetPath();
392 SetEditText( aFile );
395 else if (bMacro)
397 // choose macro dialog
398 OUString aScriptURL = SfxApplication::ChooseScript(GetDialogFrameWeld());
400 if ( !aScriptURL.isEmpty() )
402 SetEditText( aScriptURL );
405 else
407 sfx2::FileDialogHelper aFileDialog(
408 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
409 FileDialogFlags::NONE, GetDialogFrameWeld());
411 if (bDocument && aFile.isEmpty())
412 aFile = SvtPathOptions().GetWorkPath();
414 aFileDialog.SetDisplayDirectory( aFile );
416 // The following is a workaround for #i4306#:
417 // The addition of the implicitly existing "all files"
418 // filter makes the (Windows system) open file dialog follow
419 // links on the desktop to directories.
420 aFileDialog.AddFilter (
421 SfxResId(STR_SFX_FILTERNAME_ALL),
422 "*.*");
424 if( aFileDialog.Execute() == ERRCODE_NONE )
426 aFile = aFileDialog.GetPath();
427 SetEditText( aFile );
429 if( bDocument )
430 CheckFileHdl( *m_xEdtDocument );
435 IMPL_LINK_NOARG(SdTPAction, ClickSearchHdl, weld::Button&, void)
437 OpenFileDialog();
440 IMPL_LINK_NOARG(SdTPAction, ClickActionHdl, weld::ComboBox&, void)
442 presentation::ClickAction eCA = GetActualClickAction();
444 // hide controls we don't need
445 switch( eCA )
447 case presentation::ClickAction_NONE:
448 case presentation::ClickAction_INVISIBLE:
449 case presentation::ClickAction_PREVPAGE:
450 case presentation::ClickAction_NEXTPAGE:
451 case presentation::ClickAction_FIRSTPAGE:
452 case presentation::ClickAction_LASTPAGE:
453 case presentation::ClickAction_STOPPRESENTATION:
454 default:
455 m_xFtTree->hide();
456 m_xLbTree->hide();
457 m_xLbTreeDocument->hide();
458 m_xLbOLEAction->hide();
460 m_xFrame->hide();
461 m_xEdtSound->hide();
462 m_xEdtBookmark->hide();
463 m_xEdtDocument->hide();
464 m_xEdtProgram->hide();
465 m_xEdtMacro->hide();
466 m_xBtnSearch->hide();
467 m_xBtnSeek->hide();
468 break;
470 case presentation::ClickAction_SOUND:
471 case presentation::ClickAction_PROGRAM:
472 case presentation::ClickAction_MACRO:
473 m_xFtTree->hide();
474 m_xLbTree->hide();
475 m_xLbTreeDocument->hide();
476 m_xLbOLEAction->hide();
478 m_xEdtDocument->hide();
480 if( eCA == presentation::ClickAction_MACRO )
482 m_xEdtSound->hide();
483 m_xEdtProgram->hide();
485 else if( eCA == presentation::ClickAction_PROGRAM )
487 m_xEdtSound->hide();
488 m_xEdtMacro->hide();
490 else if( eCA == presentation::ClickAction_SOUND )
492 m_xEdtProgram->hide();
493 m_xEdtMacro->hide();
496 m_xBtnSeek->hide();
497 break;
499 case presentation::ClickAction_DOCUMENT:
500 m_xLbTree->hide();
501 m_xLbOLEAction->hide();
503 m_xEdtSound->hide();
504 m_xEdtProgram->hide();
505 m_xEdtMacro->hide();
506 m_xEdtBookmark->hide();
507 m_xBtnSeek->hide();
508 break;
510 case presentation::ClickAction_BOOKMARK:
511 m_xLbTreeDocument->hide();
512 m_xLbOLEAction->hide();
513 m_xEdtSound->hide();
514 m_xEdtDocument->hide();
515 m_xEdtProgram->hide();
516 m_xEdtMacro->hide();
517 m_xBtnSearch->hide();
518 break;
520 case presentation::ClickAction_VERB:
521 m_xLbTree->hide();
522 m_xEdtDocument->hide();
523 m_xEdtProgram->hide();
524 m_xEdtBookmark->hide();
525 m_xEdtMacro->hide();
526 m_xBtnSearch->hide();
527 m_xFrame->hide();
528 m_xEdtSound->hide();
529 m_xBtnSeek->hide();
530 break;
533 // show controls we do need
534 switch( eCA )
536 case presentation::ClickAction_NONE:
537 case presentation::ClickAction_INVISIBLE:
538 case presentation::ClickAction_PREVPAGE:
539 case presentation::ClickAction_NEXTPAGE:
540 case presentation::ClickAction_FIRSTPAGE:
541 case presentation::ClickAction_LASTPAGE:
542 case presentation::ClickAction_STOPPRESENTATION:
543 // none
544 break;
546 case presentation::ClickAction_SOUND:
547 m_xFrame->show();
548 m_xEdtSound->show();
549 m_xEdtSound->set_sensitive(true);
550 m_xBtnSearch->show();
551 m_xBtnSearch->set_sensitive(true);
552 m_xFrame->set_label( SdResId( STR_EFFECTDLG_SOUND ) );
553 break;
555 case presentation::ClickAction_PROGRAM:
556 case presentation::ClickAction_MACRO:
557 m_xFrame->show();
558 m_xBtnSearch->show();
559 m_xBtnSearch->set_sensitive(true);
560 if( eCA == presentation::ClickAction_MACRO )
562 m_xEdtMacro->show();
563 m_xFrame->set_label( SdResId( STR_EFFECTDLG_MACRO ) );
565 else
567 m_xEdtProgram->show();
568 m_xFrame->set_label( SdResId( STR_EFFECTDLG_PROGRAM ) );
570 break;
572 case presentation::ClickAction_DOCUMENT:
573 m_xFtTree->show();
574 m_xLbTreeDocument->show();
576 m_xFrame->show();
577 m_xEdtDocument->show();
578 m_xBtnSearch->show();
579 m_xBtnSearch->set_sensitive(true);
581 m_xFtTree->set_label( SdResId( STR_EFFECTDLG_JUMP ) );
582 m_xFrame->set_label( SdResId( STR_EFFECTDLG_DOCUMENT ) );
584 CheckFileHdl( *m_xEdtDocument );
585 break;
587 case presentation::ClickAction_VERB:
588 m_xFtTree->show();
589 m_xLbOLEAction->show();
591 m_xFtTree->set_label( SdResId( STR_EFFECTDLG_ACTION ) );
592 break;
594 case presentation::ClickAction_BOOKMARK:
595 UpdateTree();
597 m_xFtTree->show();
598 m_xLbTree->show();
600 m_xFrame->show();
601 m_xEdtBookmark->show();
602 m_xBtnSeek->show();
604 m_xFtTree->set_label( SdResId( STR_EFFECTDLG_JUMP ) );
605 m_xFrame->set_label( SdResId( STR_EFFECTDLG_PAGE_OBJECT ) );
606 break;
607 default:
608 break;
612 IMPL_LINK_NOARG(SdTPAction, SelectTreeHdl, weld::TreeView&, void)
614 m_xEdtBookmark->set_text( m_xLbTree->get_selected_text() );
617 IMPL_LINK_NOARG(SdTPAction, CheckFileHdl, weld::Widget&, void)
619 OUString aFile( GetEditText() );
621 if( aFile == aLastFile )
622 return;
624 // check if it is a valid draw file
625 SfxMedium aMedium( aFile,
626 StreamMode::READ | StreamMode::NOCREATE );
628 if( aMedium.IsStorage() )
630 WaitObject aWait( GetParentDialog() );
632 bool bHideTreeDocument = true;
634 // is it a draw file?
635 // open with READ, otherwise the Storages might write into the file!
636 uno::Reference < embed::XStorage > xStorage = aMedium.GetStorage();
637 DBG_ASSERT( xStorage.is(), "No storage!" );
639 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
640 if (xAccess.is())
644 if (xAccess->hasByName(pStarDrawXMLContent) ||
645 xAccess->hasByName(pStarDrawOldXMLContent))
647 if (SdDrawDocument* pBookmarkDoc = mpDoc->OpenBookmarkDoc(aFile))
649 aLastFile = aFile;
651 m_xLbTreeDocument->clear();
652 m_xLbTreeDocument->Fill(pBookmarkDoc, true, aFile);
653 mpDoc->CloseBookmarkDoc();
654 m_xLbTreeDocument->show();
655 bHideTreeDocument = false;
659 catch (...)
664 if (bHideTreeDocument)
665 m_xLbTreeDocument->hide();
668 else
669 m_xLbTreeDocument->hide();
672 presentation::ClickAction SdTPAction::GetActualClickAction()
674 presentation::ClickAction eCA = presentation::ClickAction_NONE;
675 int nPos = m_xLbAction->get_active();
676 if (nPos != -1 && static_cast<size_t>(nPos) < maCurrentActions.size())
677 eCA = maCurrentActions[ nPos ];
678 return eCA;
681 void SdTPAction::SetActualClickAction( presentation::ClickAction eCA )
683 std::vector<css::presentation::ClickAction>::const_iterator pIter =
684 std::find(maCurrentActions.begin(),maCurrentActions.end(),eCA);
686 if ( pIter != maCurrentActions.end() )
687 m_xLbAction->set_active(pIter-maCurrentActions.begin());
690 void SdTPAction::SetEditText( OUString const & rStr )
692 presentation::ClickAction eCA = GetActualClickAction();
693 OUString aText(rStr);
695 // possibly convert URI back to system path
696 switch( eCA )
698 case presentation::ClickAction_DOCUMENT:
699 if( comphelper::string::getTokenCount(rStr, DOCUMENT_TOKEN) == 2 )
700 aText = rStr.getToken( 0, DOCUMENT_TOKEN );
702 [[fallthrough]];
703 case presentation::ClickAction_SOUND:
704 case presentation::ClickAction_PROGRAM:
706 INetURLObject aURL( aText );
708 // try to convert to system path
709 OUString aTmpStr(aURL.getFSysPath(FSysStyle::Detect));
711 if( !aTmpStr.isEmpty() )
712 aText = aTmpStr; // was a system path
714 break;
715 default:
716 break;
719 // set the string to the corresponding control
720 switch( eCA )
722 case presentation::ClickAction_SOUND:
723 m_xEdtSound->set_text(aText );
724 break;
725 case presentation::ClickAction_VERB:
727 ::std::vector< long >::iterator aFound( ::std::find( aVerbVector.begin(), aVerbVector.end(), rStr.toInt32() ) );
728 if( aFound != aVerbVector.end() )
729 m_xLbOLEAction->select(aFound - aVerbVector.begin());
731 break;
732 case presentation::ClickAction_PROGRAM:
733 m_xEdtProgram->set_text( aText );
734 break;
735 case presentation::ClickAction_MACRO:
736 m_xEdtMacro->set_text( aText );
737 break;
738 case presentation::ClickAction_DOCUMENT:
739 m_xEdtDocument->set_text( aText );
740 break;
741 case presentation::ClickAction_BOOKMARK:
742 m_xEdtBookmark->set_text( aText );
743 break;
744 default:
745 break;
749 OUString SdTPAction::GetEditText( bool bFullDocDestination )
751 OUString aStr;
752 presentation::ClickAction eCA = GetActualClickAction();
754 switch( eCA )
756 case presentation::ClickAction_SOUND:
757 aStr = m_xEdtSound->get_text();
758 break;
759 case presentation::ClickAction_VERB:
761 const int nPos = m_xLbOLEAction->get_selected_index();
762 if (nPos != -1 && static_cast<size_t>(nPos) < aVerbVector.size() )
763 aStr = OUString::number( aVerbVector[ nPos ] );
764 return aStr;
766 case presentation::ClickAction_DOCUMENT:
767 aStr = m_xEdtDocument->get_text();
768 break;
770 case presentation::ClickAction_PROGRAM:
771 aStr = m_xEdtProgram->get_text();
772 break;
774 case presentation::ClickAction_MACRO:
776 return m_xEdtMacro->get_text();
779 case presentation::ClickAction_BOOKMARK:
780 return m_xEdtBookmark->get_text();
782 default:
783 break;
786 // validate file URI
787 INetURLObject aURL( aStr );
788 OUString aBaseURL;
789 if( mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
790 aBaseURL = mpDoc->GetDocSh()->GetMedium()->GetBaseURL();
792 if( !aStr.isEmpty() && aURL.GetProtocol() == INetProtocol::NotValid )
793 aURL = INetURLObject( ::URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aStr, URIHelper::GetMaybeFileHdl() ) );
795 // get adjusted file name
796 aStr = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
798 if( bFullDocDestination &&
799 eCA == presentation::ClickAction_DOCUMENT &&
800 m_xLbTreeDocument->get_visible() &&
801 m_xLbTreeDocument->get_selected() )
803 OUString aTmpStr( m_xLbTreeDocument->get_selected_text() );
804 if( !aTmpStr.isEmpty() )
806 aStr += OUStringLiteral1(DOCUMENT_TOKEN) + aTmpStr;
810 return aStr;
813 const char* SdTPAction::GetClickActionSdResId( presentation::ClickAction eCA )
815 switch( eCA )
817 case presentation::ClickAction_NONE: return STR_CLICK_ACTION_NONE;
818 case presentation::ClickAction_PREVPAGE: return STR_CLICK_ACTION_PREVPAGE;
819 case presentation::ClickAction_NEXTPAGE: return STR_CLICK_ACTION_NEXTPAGE;
820 case presentation::ClickAction_FIRSTPAGE: return STR_CLICK_ACTION_FIRSTPAGE;
821 case presentation::ClickAction_LASTPAGE: return STR_CLICK_ACTION_LASTPAGE;
822 case presentation::ClickAction_BOOKMARK: return STR_CLICK_ACTION_BOOKMARK;
823 case presentation::ClickAction_DOCUMENT: return STR_CLICK_ACTION_DOCUMENT;
824 case presentation::ClickAction_PROGRAM: return STR_CLICK_ACTION_PROGRAM;
825 case presentation::ClickAction_MACRO: return STR_CLICK_ACTION_MACRO;
826 case presentation::ClickAction_SOUND: return STR_CLICK_ACTION_SOUND;
827 case presentation::ClickAction_VERB: return STR_CLICK_ACTION_VERB;
828 case presentation::ClickAction_STOPPRESENTATION: return STR_CLICK_ACTION_STOPPRESENTATION;
829 default: OSL_FAIL( "No StringResource for ClickAction available!" );
831 return nullptr;
834 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */