Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / ui / dlg / tpaction.cxx
blob188068ed595c356e8b2b7f62566704158470a814
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 <comphelper/string.hxx>
26 #include <com/sun/star/embed/VerbAttributes.hpp>
27 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
29 #include <sdattr.hxx>
30 #include <sfx2/sfxresid.hxx>
31 #include <sfx2/strings.hrc>
33 #include <vcl/waitobj.hxx>
34 #include <osl/file.hxx>
35 #include <sfx2/app.hxx>
36 #include <unotools/pathoptions.hxx>
37 #include <svx/svdograf.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <unotools/localfilehelper.hxx>
40 #include <svl/aeitem.hxx>
41 #include <editeng/colritem.hxx>
42 #include <svx/svdoole2.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <sot/storage.hxx>
45 #include <basic/sbmeth.hxx>
46 #include <basic/sbmod.hxx>
47 #include <basic/sbstar.hxx>
48 #include <svx/xtable.hxx>
49 #include <vcl/svapp.hxx>
50 #include <vcl/mnemonic.hxx>
51 #include <svl/urihelper.hxx>
52 #include <sfx2/filedlghelper.hxx>
53 #include <svx/drawitem.hxx>
54 #include <View.hxx>
55 #include <sdresid.hxx>
56 #include <tpaction.hxx>
57 #include <strmname.h>
58 #include <ViewShell.hxx>
59 #include <drawdoc.hxx>
60 #include <DrawDocShell.hxx>
61 #include <strings.hrc>
63 #include <filedlg.hxx>
65 #include <algorithm>
67 using namespace ::com::sun::star;
68 using namespace com::sun::star::uno;
69 using namespace com::sun::star::lang;
71 #define DOCUMENT_TOKEN '#'
73 /**
74 * Constructor of the Tab dialog: appends the pages to the dialog
76 SdActionDlg::SdActionDlg (
77 vcl::Window* pParent, const SfxItemSet* pAttr, ::sd::View const * pView )
78 : SfxSingleTabDialog(pParent, *pAttr, "InteractionDialog",
79 "modules/simpress/ui/interactiondialog.ui")
80 , rOutAttrs(*pAttr)
82 VclPtr<SfxTabPage> pNewPage = SdTPAction::Create(get_content_area(), rOutAttrs);
83 assert(pNewPage); //Unable to create page
85 // formerly in PageCreated
86 static_cast<SdTPAction*>( pNewPage.get() )->SetView( pView );
87 static_cast<SdTPAction*>( pNewPage.get() )->Construct();
89 SetTabPage( pNewPage );
92 /**
93 * Action-TabPage
95 SdTPAction::SdTPAction(vcl::Window* pWindow, const SfxItemSet& rInAttrs)
96 : SfxTabPage(pWindow, "InteractionPage",
97 "modules/simpress/ui/interactionpage.ui", &rInAttrs)
98 , mpView(nullptr)
99 , mpDoc(nullptr)
100 , bTreeUpdated(false)
102 get(m_pLbAction, "listbox");
103 get(m_pFtTree, "fttree");
104 get(m_pLbTree, "tree");
105 get(m_pLbTreeDocument, "treedoc");
106 get(m_pLbOLEAction, "oleaction");
107 get(m_pFrame, "frame");
108 get(m_pEdtSound, "sound");
109 get(m_pEdtBookmark, "bookmark");
110 get(m_pEdtDocument, "document");
111 get(m_pEdtProgram, "program");
112 get(m_pEdtMacro, "macro");
113 get(m_pBtnSearch, "browse");
114 get(m_pBtnSeek, "find");
116 m_pLbOLEAction->set_width_request(m_pLbOLEAction->approximate_char_width() * 52);
117 m_pLbOLEAction->set_height_request(m_pLbOLEAction->GetTextHeight() * 12);
119 m_pBtnSearch->SetClickHdl( LINK( this, SdTPAction, ClickSearchHdl ) );
120 m_pBtnSeek->SetClickHdl( LINK( this, SdTPAction, ClickSearchHdl ) );
122 // this page needs ExchangeSupport
123 SetExchangeSupport();
125 m_pLbAction->SetSelectHdl( LINK( this, SdTPAction, ClickActionHdl ) );
126 m_pLbTree->SetSelectHdl( LINK( this, SdTPAction, SelectTreeHdl ) );
127 m_pEdtDocument->SetLoseFocusHdl( LINK( this, SdTPAction, CheckFileHdl ) );
128 m_pEdtMacro->SetLoseFocusHdl( LINK( this, SdTPAction, CheckFileHdl ) );
130 //Lock to initial max size
131 Size aSize(get_preferred_size());
132 set_width_request(aSize.Width());
133 set_height_request(aSize.Height());
135 ClickActionHdl( *m_pLbAction );
138 SdTPAction::~SdTPAction()
140 disposeOnce();
143 void SdTPAction::dispose()
145 m_pLbAction.clear();
146 m_pFtTree.clear();
147 m_pLbTree.clear();
148 m_pLbTreeDocument.clear();
149 m_pLbOLEAction.clear();
150 m_pFrame.clear();
151 m_pEdtSound.clear();
152 m_pEdtBookmark.clear();
153 m_pEdtDocument.clear();
154 m_pEdtProgram.clear();
155 m_pEdtMacro.clear();
156 m_pBtnSearch.clear();
157 m_pBtnSeek.clear();
158 SfxTabPage::dispose();
161 void SdTPAction::SetView( const ::sd::View* pSdView )
163 mpView = pSdView;
165 // get ColorTable and fill ListBox
166 ::sd::DrawDocShell* pDocSh = mpView->GetDocSh();
167 if( pDocSh && pDocSh->GetViewShell() )
169 mpDoc = pDocSh->GetDoc();
170 SfxViewFrame* pFrame = pDocSh->GetViewShell()->GetViewFrame();
171 m_pLbTree->SetViewFrame( pFrame );
172 m_pLbTreeDocument->SetViewFrame( pFrame );
174 pColList = pDocSh->GetItem( SID_COLOR_TABLE )->GetColorList();
175 DBG_ASSERT( pColList.is(), "No color table available!" );
177 else
179 OSL_FAIL("sd::SdTPAction::SetView(), no docshell or viewshell?");
183 void SdTPAction::Construct()
185 // fill OLE-Actionlistbox
186 SdrOle2Obj* pOleObj = nullptr;
187 SdrGrafObj* pGrafObj = nullptr;
188 bool bOLEAction = false;
190 if ( mpView->AreObjectsMarked() )
192 const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
193 SdrObject* pObj;
195 if (rMarkList.GetMarkCount() == 1)
197 SdrMark* pMark = rMarkList.GetMark(0);
198 pObj = pMark->GetMarkedSdrObj();
200 SdrInventor nInv = pObj->GetObjInventor();
201 sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
203 if (nInv == SdrInventor::Default && nSdrObjKind == OBJ_OLE2)
205 pOleObj = static_cast<SdrOle2Obj*>(pObj);
207 else if (nInv == SdrInventor::Default && nSdrObjKind == OBJ_GRAF)
209 pGrafObj = static_cast<SdrGrafObj*>(pObj);
213 if( pGrafObj )
215 bOLEAction = true;
217 aVerbVector.push_back( 0 );
218 m_pLbOLEAction->InsertEntry( MnemonicGenerator::EraseAllMnemonicChars( SdResId( STR_EDIT_OBJ ) ) );
220 else if( pOleObj )
222 uno::Reference < embed::XEmbeddedObject > xObj = pOleObj->GetObjRef();
223 if ( xObj.is() )
225 bOLEAction = true;
226 uno::Sequence < embed::VerbDescriptor > aVerbs;
229 aVerbs = xObj->getSupportedVerbs();
231 catch ( embed::NeedsRunningStateException& )
233 xObj->changeState( embed::EmbedStates::RUNNING );
234 aVerbs = xObj->getSupportedVerbs();
237 for( sal_Int32 i=0; i<aVerbs.getLength(); i++ )
239 embed::VerbDescriptor aVerb = aVerbs[i];
240 if( aVerb.VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU )
242 OUString aTmp( aVerb.VerbName );
243 aVerbVector.push_back( aVerb.VerbID );
244 m_pLbOLEAction->InsertEntry( MnemonicGenerator::EraseAllMnemonicChars( aTmp ) );
250 maCurrentActions.push_back( presentation::ClickAction_NONE );
251 maCurrentActions.push_back( presentation::ClickAction_PREVPAGE );
252 maCurrentActions.push_back( presentation::ClickAction_NEXTPAGE );
253 maCurrentActions.push_back( presentation::ClickAction_FIRSTPAGE );
254 maCurrentActions.push_back( presentation::ClickAction_LASTPAGE );
255 maCurrentActions.push_back( presentation::ClickAction_BOOKMARK );
256 maCurrentActions.push_back( presentation::ClickAction_DOCUMENT );
257 maCurrentActions.push_back( presentation::ClickAction_SOUND );
258 if( bOLEAction && m_pLbOLEAction->GetEntryCount() )
259 maCurrentActions.push_back( presentation::ClickAction_VERB );
260 maCurrentActions.push_back( presentation::ClickAction_PROGRAM );
261 maCurrentActions.push_back( presentation::ClickAction_MACRO );
262 maCurrentActions.push_back( presentation::ClickAction_STOPPRESENTATION );
264 // fill Action-Listbox
265 for (presentation::ClickAction & rAction : maCurrentActions)
267 const char* pRId = GetClickActionSdResId(rAction);
268 m_pLbAction->InsertEntry(SdResId(pRId));
273 bool SdTPAction::FillItemSet( SfxItemSet* rAttrs )
275 bool bModified = false;
276 presentation::ClickAction eCA = presentation::ClickAction_NONE;
278 if( m_pLbAction->GetSelectedEntryCount() )
279 eCA = GetActualClickAction();
281 if( m_pLbAction->IsValueChangedFromSaved() )
283 rAttrs->Put( SfxAllEnumItem( ATTR_ACTION, static_cast<sal_uInt16>(eCA) ) );
284 bModified = true;
286 else
287 rAttrs->InvalidateItem( ATTR_ACTION );
289 OUString aFileName = GetEditText( true );
290 if( aFileName.isEmpty() )
291 rAttrs->InvalidateItem( ATTR_ACTION_FILENAME );
292 else
294 if( mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
296 OUString aBaseURL = mpDoc->GetDocSh()->GetMedium()->GetBaseURL();
297 if( eCA == presentation::ClickAction_SOUND ||
298 eCA == presentation::ClickAction_DOCUMENT ||
299 eCA == presentation::ClickAction_PROGRAM )
300 aFileName = ::URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aFileName, URIHelper::GetMaybeFileHdl(), true, false,
301 INetURLObject::EncodeMechanism::WasEncoded,
302 INetURLObject::DecodeMechanism::Unambiguous );
304 rAttrs->Put( SfxStringItem( ATTR_ACTION_FILENAME, aFileName ) );
305 bModified = true;
307 else
309 OSL_FAIL("sd::SdTPAction::FillItemSet(), I need a medium!");
313 return bModified;
316 void SdTPAction::Reset( const SfxItemSet* rAttrs )
318 presentation::ClickAction eCA = presentation::ClickAction_NONE;
319 OUString aFileName;
321 // m_pLbAction
322 if( rAttrs->GetItemState( ATTR_ACTION ) != SfxItemState::DONTCARE )
324 eCA = static_cast<presentation::ClickAction>(static_cast<const SfxAllEnumItem&>( rAttrs->
325 Get( ATTR_ACTION ) ).GetValue());
326 SetActualClickAction( eCA );
328 else
329 m_pLbAction->SetNoSelection();
331 // m_pEdtSound
332 if( rAttrs->GetItemState( ATTR_ACTION_FILENAME ) != SfxItemState::DONTCARE )
334 aFileName = static_cast<const SfxStringItem&>( rAttrs->Get( ATTR_ACTION_FILENAME ) ).GetValue();
335 SetEditText( aFileName );
338 switch( eCA )
340 case presentation::ClickAction_BOOKMARK:
342 if( !m_pLbTree->SelectEntry( aFileName ) )
343 m_pLbTree->SelectAll( false );
345 break;
347 case presentation::ClickAction_DOCUMENT:
349 if( comphelper::string::getTokenCount(aFileName, DOCUMENT_TOKEN) == 2 )
350 m_pLbTreeDocument->SelectEntry( aFileName.getToken( 1, DOCUMENT_TOKEN ) );
352 break;
354 default:
355 break;
357 ClickActionHdl( *m_pLbAction );
359 m_pLbAction->SaveValue();
360 m_pEdtSound->SaveValue();
363 void SdTPAction::ActivatePage( const SfxItemSet& )
367 DeactivateRC SdTPAction::DeactivatePage( SfxItemSet* pPageSet )
369 if( pPageSet )
370 FillItemSet( pPageSet );
372 return DeactivateRC::LeavePage;
375 VclPtr<SfxTabPage> SdTPAction::Create( TabPageParent pWindow,
376 const SfxItemSet& rAttrs )
378 return VclPtr<SdTPAction>::Create( pWindow.pParent, rAttrs );
381 void SdTPAction::UpdateTree()
383 if( !bTreeUpdated && mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
385 //m_pLbTree->Clear();
386 m_pLbTree->Fill( mpDoc, true, mpDoc->GetDocSh()->GetMedium()->GetName() );
387 bTreeUpdated = true;
391 void SdTPAction::OpenFileDialog()
393 // Soundpreview only for interaction with sound
394 presentation::ClickAction eCA = GetActualClickAction();
395 bool bSound = ( eCA == presentation::ClickAction_SOUND );
396 bool bPage = ( eCA == presentation::ClickAction_BOOKMARK );
397 bool bDocument = ( eCA == presentation::ClickAction_DOCUMENT ||
398 eCA == presentation::ClickAction_PROGRAM );
399 bool bMacro = ( eCA == presentation::ClickAction_MACRO );
401 if( bPage )
403 // search in the TreeLB for the specified object
404 m_pLbTree->SelectEntry( GetEditText() );
406 else
408 OUString aFile( GetEditText() );
410 if (bSound)
412 SdOpenSoundFileDialog aFileDialog(GetFrameWeld());
414 if( !aFile.isEmpty() )
415 aFileDialog.SetPath( aFile );
417 if( aFileDialog.Execute() == ERRCODE_NONE )
419 aFile = aFileDialog.GetPath();
420 SetEditText( aFile );
423 else if (bMacro)
425 // choose macro dialog
426 OUString aScriptURL = SfxApplication::ChooseScript();
428 if ( !aScriptURL.isEmpty() )
430 SetEditText( aScriptURL );
433 else
435 sfx2::FileDialogHelper aFileDialog(
436 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
437 FileDialogFlags::NONE, GetFrameWeld());
439 if (bDocument && aFile.isEmpty())
440 aFile = SvtPathOptions().GetWorkPath();
442 aFileDialog.SetDisplayDirectory( aFile );
444 // The following is a workaround for #i4306#:
445 // The addition of the implicitly existing "all files"
446 // filter makes the (Windows system) open file dialog follow
447 // links on the desktop to directories.
448 aFileDialog.AddFilter (
449 SfxResId(STR_SFX_FILTERNAME_ALL),
450 "*.*");
452 if( aFileDialog.Execute() == ERRCODE_NONE )
454 aFile = aFileDialog.GetPath();
455 SetEditText( aFile );
457 if( bDocument )
458 CheckFileHdl( *m_pEdtDocument );
463 IMPL_LINK_NOARG(SdTPAction, ClickSearchHdl, Button*, void)
465 OpenFileDialog();
468 IMPL_LINK_NOARG(SdTPAction, ClickActionHdl, ListBox&, void)
470 presentation::ClickAction eCA = GetActualClickAction();
472 // hide controls we don't need
473 switch( eCA )
475 case presentation::ClickAction_NONE:
476 case presentation::ClickAction_INVISIBLE:
477 case presentation::ClickAction_PREVPAGE:
478 case presentation::ClickAction_NEXTPAGE:
479 case presentation::ClickAction_FIRSTPAGE:
480 case presentation::ClickAction_LASTPAGE:
481 case presentation::ClickAction_STOPPRESENTATION:
482 default:
483 m_pFtTree->Hide();
484 m_pLbTree->Hide();
485 m_pLbTreeDocument->Hide();
486 m_pLbOLEAction->Hide();
488 m_pFrame->Hide();
489 m_pEdtSound->Hide();
490 m_pEdtBookmark->Hide();
491 m_pEdtDocument->Hide();
492 m_pEdtProgram->Hide();
493 m_pEdtMacro->Hide();
494 m_pBtnSearch->Hide();
495 m_pBtnSeek->Hide();
496 break;
498 case presentation::ClickAction_SOUND:
499 case presentation::ClickAction_PROGRAM:
500 case presentation::ClickAction_MACRO:
501 m_pFtTree->Hide();
502 m_pLbTree->Hide();
503 m_pLbTreeDocument->Hide();
504 m_pLbOLEAction->Hide();
506 m_pEdtDocument->Hide();
508 if( eCA == presentation::ClickAction_MACRO )
510 m_pEdtSound->Hide();
511 m_pEdtProgram->Hide();
513 else if( eCA == presentation::ClickAction_PROGRAM )
515 m_pEdtSound->Hide();
516 m_pEdtMacro->Hide();
518 else if( eCA == presentation::ClickAction_SOUND )
520 m_pEdtProgram->Hide();
521 m_pEdtMacro->Hide();
524 m_pBtnSeek->Hide();
525 break;
527 case presentation::ClickAction_DOCUMENT:
528 m_pLbTree->Hide();
529 m_pLbOLEAction->Hide();
531 m_pEdtSound->Hide();
532 m_pEdtProgram->Hide();
533 m_pEdtMacro->Hide();
534 m_pEdtBookmark->Hide();
535 m_pBtnSeek->Hide();
536 break;
538 case presentation::ClickAction_BOOKMARK:
539 m_pLbTreeDocument->Hide();
540 m_pLbOLEAction->Hide();
541 m_pEdtSound->Hide();
542 m_pEdtDocument->Hide();
543 m_pEdtProgram->Hide();
544 m_pEdtMacro->Hide();
545 m_pBtnSearch->Hide();
546 break;
548 case presentation::ClickAction_VERB:
549 m_pLbTree->Hide();
550 m_pEdtDocument->Hide();
551 m_pEdtProgram->Hide();
552 m_pEdtBookmark->Hide();
553 m_pEdtMacro->Hide();
554 m_pBtnSearch->Hide();
555 m_pFrame->Hide();
556 m_pEdtSound->Hide();
557 m_pBtnSeek->Hide();
558 break;
561 // show controls we do need
562 switch( eCA )
564 case presentation::ClickAction_NONE:
565 case presentation::ClickAction_INVISIBLE:
566 case presentation::ClickAction_PREVPAGE:
567 case presentation::ClickAction_NEXTPAGE:
568 case presentation::ClickAction_FIRSTPAGE:
569 case presentation::ClickAction_LASTPAGE:
570 case presentation::ClickAction_STOPPRESENTATION:
571 // none
572 break;
574 case presentation::ClickAction_SOUND:
575 m_pFrame->Show();
576 m_pEdtSound->Show();
577 m_pEdtSound->Enable();
578 m_pBtnSearch->Show();
579 m_pBtnSearch->Enable();
580 m_pFrame->set_label( SdResId( STR_EFFECTDLG_SOUND ) );
581 break;
583 case presentation::ClickAction_PROGRAM:
584 case presentation::ClickAction_MACRO:
585 m_pFrame->Show();
586 m_pBtnSearch->Show();
587 m_pBtnSearch->Enable();
588 if( eCA == presentation::ClickAction_MACRO )
590 m_pEdtMacro->Show();
591 m_pFrame->set_label( SdResId( STR_EFFECTDLG_MACRO ) );
593 else
595 m_pEdtProgram->Show();
596 m_pFrame->set_label( SdResId( STR_EFFECTDLG_PROGRAM ) );
598 break;
600 case presentation::ClickAction_DOCUMENT:
601 m_pFtTree->Show();
602 m_pLbTreeDocument->Show();
604 m_pFrame->Show();
605 m_pEdtDocument->Show();
606 m_pBtnSearch->Show();
607 m_pBtnSearch->Enable();
609 m_pFtTree->SetText( SdResId( STR_EFFECTDLG_JUMP ) );
610 m_pFrame->set_label( SdResId( STR_EFFECTDLG_DOCUMENT ) );
612 CheckFileHdl( *m_pEdtDocument );
613 break;
615 case presentation::ClickAction_VERB:
616 m_pFtTree->Show();
617 m_pLbOLEAction->Show();
619 m_pFtTree->SetText( SdResId( STR_EFFECTDLG_ACTION ) );
620 break;
622 case presentation::ClickAction_BOOKMARK:
623 UpdateTree();
625 m_pFtTree->Show();
626 m_pLbTree->Show();
628 m_pFrame->Show();
629 m_pEdtBookmark->Show();
630 m_pBtnSeek->Show();
632 m_pFtTree->SetText( SdResId( STR_EFFECTDLG_JUMP ) );
633 m_pFrame->set_label( SdResId( STR_EFFECTDLG_PAGE_OBJECT ) );
634 break;
635 default:
636 break;
640 IMPL_LINK_NOARG(SdTPAction, SelectTreeHdl, SvTreeListBox*, void)
642 m_pEdtBookmark->SetText( m_pLbTree->GetSelectedEntry() );
645 IMPL_LINK_NOARG(SdTPAction, CheckFileHdl, Control&, void)
647 OUString aFile( GetEditText() );
649 if( aFile != aLastFile )
651 // check if it is a valid draw file
652 SfxMedium aMedium( aFile,
653 StreamMode::READ | StreamMode::NOCREATE );
655 if( aMedium.IsStorage() )
657 WaitObject aWait( GetParentDialog() );
659 bool bHideTreeDocument = true;
661 // is it a draw file?
662 // open with READ, otherwise the Storages might write into the file!
663 uno::Reference < embed::XStorage > xStorage = aMedium.GetStorage();
664 DBG_ASSERT( xStorage.is(), "No storage!" );
666 uno::Reference < container::XNameAccess > xAccess( xStorage, uno::UNO_QUERY );
667 if (xAccess.is())
671 if (xAccess->hasByName(pStarDrawXMLContent) ||
672 xAccess->hasByName(pStarDrawOldXMLContent))
674 if (SdDrawDocument* pBookmarkDoc = mpDoc->OpenBookmarkDoc(aFile))
676 aLastFile = aFile;
678 m_pLbTreeDocument->Clear();
679 m_pLbTreeDocument->Fill(pBookmarkDoc, true, aFile);
680 mpDoc->CloseBookmarkDoc();
681 m_pLbTreeDocument->Show();
682 bHideTreeDocument = false;
686 catch (...)
691 if (bHideTreeDocument)
692 m_pLbTreeDocument->Hide();
695 else
696 m_pLbTreeDocument->Hide();
700 presentation::ClickAction SdTPAction::GetActualClickAction()
702 presentation::ClickAction eCA = presentation::ClickAction_NONE;
703 sal_Int32 nPos = m_pLbAction->GetSelectedEntryPos();
705 if (nPos != LISTBOX_ENTRY_NOTFOUND && static_cast<size_t>(nPos) < maCurrentActions.size())
706 eCA = maCurrentActions[ nPos ];
707 return eCA;
710 void SdTPAction::SetActualClickAction( presentation::ClickAction eCA )
712 std::vector<css::presentation::ClickAction>::const_iterator pIter =
713 std::find(maCurrentActions.begin(),maCurrentActions.end(),eCA);
715 if ( pIter != maCurrentActions.end() )
716 m_pLbAction->SelectEntryPos( pIter-maCurrentActions.begin() );
719 void SdTPAction::SetEditText( OUString const & rStr )
721 presentation::ClickAction eCA = GetActualClickAction();
722 OUString aText(rStr);
724 // possibly convert URI back to system path
725 switch( eCA )
727 case presentation::ClickAction_DOCUMENT:
728 if( comphelper::string::getTokenCount(rStr, DOCUMENT_TOKEN) == 2 )
729 aText = rStr.getToken( 0, DOCUMENT_TOKEN );
731 SAL_FALLTHROUGH;
732 case presentation::ClickAction_SOUND:
733 case presentation::ClickAction_PROGRAM:
735 INetURLObject aURL( aText );
737 // try to convert to system path
738 OUString aTmpStr(aURL.getFSysPath(FSysStyle::Detect));
740 if( !aTmpStr.isEmpty() )
741 aText = aTmpStr; // was a system path
743 break;
744 default:
745 break;
748 // set the string to the corresponding control
749 switch( eCA )
751 case presentation::ClickAction_SOUND:
752 m_pEdtSound->SetText(aText );
753 break;
754 case presentation::ClickAction_VERB:
756 ::std::vector< long >::iterator aFound( ::std::find( aVerbVector.begin(), aVerbVector.end(), rStr.toInt32() ) );
757 if( aFound != aVerbVector.end() )
758 m_pLbOLEAction->SelectEntryPos( static_cast< short >( aFound - aVerbVector.begin() ) );
760 break;
761 case presentation::ClickAction_PROGRAM:
762 m_pEdtProgram->SetText( aText );
763 break;
764 case presentation::ClickAction_MACRO:
766 m_pEdtMacro->SetText( aText );
768 break;
769 case presentation::ClickAction_DOCUMENT:
770 m_pEdtDocument->SetText( aText );
771 break;
772 case presentation::ClickAction_BOOKMARK:
773 m_pEdtBookmark->SetText( aText );
774 break;
775 default:
776 break;
780 OUString SdTPAction::GetEditText( bool bFullDocDestination )
782 OUString aStr;
783 presentation::ClickAction eCA = GetActualClickAction();
785 switch( eCA )
787 case presentation::ClickAction_SOUND:
788 aStr = m_pEdtSound->GetText();
789 break;
790 case presentation::ClickAction_VERB:
792 const sal_Int32 nPos = m_pLbOLEAction->GetSelectedEntryPos();
793 if( static_cast<size_t>(nPos) < aVerbVector.size() )
794 aStr = OUString::number( aVerbVector[ nPos ] );
795 return aStr;
797 case presentation::ClickAction_DOCUMENT:
798 aStr = m_pEdtDocument->GetText();
799 break;
801 case presentation::ClickAction_PROGRAM:
802 aStr = m_pEdtProgram->GetText();
803 break;
805 case presentation::ClickAction_MACRO:
807 return m_pEdtMacro->GetText();
810 case presentation::ClickAction_BOOKMARK:
811 return m_pEdtBookmark->GetText();
813 default:
814 break;
817 // validate file URI
818 INetURLObject aURL( aStr );
819 OUString aBaseURL;
820 if( mpDoc && mpDoc->GetDocSh() && mpDoc->GetDocSh()->GetMedium() )
821 aBaseURL = mpDoc->GetDocSh()->GetMedium()->GetBaseURL();
823 if( !aStr.isEmpty() && aURL.GetProtocol() == INetProtocol::NotValid )
824 aURL = INetURLObject( ::URIHelper::SmartRel2Abs( INetURLObject(aBaseURL), aStr, URIHelper::GetMaybeFileHdl() ) );
826 // get adjusted file name
827 aStr = aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
829 if( bFullDocDestination &&
830 eCA == presentation::ClickAction_DOCUMENT &&
831 m_pLbTreeDocument->Control::IsVisible() &&
832 m_pLbTreeDocument->GetSelectionCount() > 0 )
834 OUString aTmpStr( m_pLbTreeDocument->GetSelectedEntry() );
835 if( !aTmpStr.isEmpty() )
837 aStr += OUStringLiteral1(DOCUMENT_TOKEN) + aTmpStr;
841 return aStr;
844 const char* SdTPAction::GetClickActionSdResId( presentation::ClickAction eCA )
846 switch( eCA )
848 case presentation::ClickAction_NONE: return STR_CLICK_ACTION_NONE;
849 case presentation::ClickAction_PREVPAGE: return STR_CLICK_ACTION_PREVPAGE;
850 case presentation::ClickAction_NEXTPAGE: return STR_CLICK_ACTION_NEXTPAGE;
851 case presentation::ClickAction_FIRSTPAGE: return STR_CLICK_ACTION_FIRSTPAGE;
852 case presentation::ClickAction_LASTPAGE: return STR_CLICK_ACTION_LASTPAGE;
853 case presentation::ClickAction_BOOKMARK: return STR_CLICK_ACTION_BOOKMARK;
854 case presentation::ClickAction_DOCUMENT: return STR_CLICK_ACTION_DOCUMENT;
855 case presentation::ClickAction_PROGRAM: return STR_CLICK_ACTION_PROGRAM;
856 case presentation::ClickAction_MACRO: return STR_CLICK_ACTION_MACRO;
857 case presentation::ClickAction_SOUND: return STR_CLICK_ACTION_SOUND;
858 case presentation::ClickAction_VERB: return STR_CLICK_ACTION_VERB;
859 case presentation::ClickAction_STOPPRESENTATION: return STR_CLICK_ACTION_STOPPRESENTATION;
860 default: OSL_FAIL( "No StringResource for ClickAction available!" );
862 return nullptr;
865 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */