xref: /aoo42x/main/sd/source/core/pglink.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #ifndef _SVXLINK_HXX
32 #include <sfx2/linkmgr.hxx>
33 #endif
34 
35 #include "pglink.hxx"
36 #include "sdpage.hxx"
37 #include "drawdoc.hxx"
38 
39 
40 /*************************************************************************
41 |*
42 |*		Ctor
43 |*
44 \************************************************************************/
45 
46 SdPageLink::SdPageLink(SdPage* pPg, const String& rFileName,
47 					   const String& rBookmarkName) :
48     ::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, FORMAT_FILE),
49 	pPage(pPg)
50 {
51 	pPage->SetFileName(rFileName);
52 	pPage->SetBookmarkName(rBookmarkName);
53 }
54 
55 
56 /*************************************************************************
57 |*
58 |* Dtor
59 |*
60 \************************************************************************/
61 
62 
63 SdPageLink::~SdPageLink()
64 {
65 }
66 
67 /*************************************************************************
68 |*
69 |* Daten haben sich geaendert
70 |*
71 \************************************************************************/
72 
73 void SdPageLink::DataChanged( const String& ,
74 									   const ::com::sun::star::uno::Any& )
75 {
76 	SdDrawDocument* pDoc = (SdDrawDocument*) pPage->GetModel();
77 	sfx2::LinkManager* pLinkManager = pDoc!=NULL ? pDoc->GetLinkManager() : NULL;
78 
79 	if (pLinkManager)
80 	{
81 		/**********************************************************************
82 		* Nur Standardseiten duerfen gelinkt sein
83 		* Die entsprechenden Notizseiten werden automatisch aktualisiert
84 		**********************************************************************/
85 		String aFileName;
86 		String aBookmarkName;
87 		String aFilterName;
88 		pLinkManager->GetDisplayNames( this,0, &aFileName, &aBookmarkName,
89 									  &aFilterName);
90 		pPage->SetFileName(aFileName);
91 		pPage->SetBookmarkName(aBookmarkName);
92 
93 		SdDrawDocument* pBookmarkDoc = pDoc->OpenBookmarkDoc(aFileName);
94 
95 		if (pBookmarkDoc)
96 		{
97 			/******************************************************************
98 			* Die gelinkte Seite wird im Model replaced
99 			******************************************************************/
100 			if (aBookmarkName.Len() == 0)
101 			{
102 				// Kein Seitenname angegeben: es wird die erste Seite genommen
103 				aBookmarkName = pBookmarkDoc->GetSdPage(0, PK_STANDARD)->GetName();
104 				pPage->SetBookmarkName(aBookmarkName);
105 			}
106 
107 			List aBookmarkList;
108 			aBookmarkList.Insert(&aBookmarkName);
109 			sal_uInt16 nInsertPos = pPage->GetPageNum();
110 			sal_Bool bLink = sal_True;
111 			sal_Bool bReplace = sal_True;
112 			sal_Bool bNoDialogs = sal_False;
113 			sal_Bool bCopy = sal_False;
114 
115 			if( pDoc->pDocLockedInsertingLinks )
116 			{
117 				// resolving links while loading pDoc
118 				bNoDialogs = sal_True;
119 				bCopy = sal_True;
120 			}
121 
122 			pDoc->InsertBookmarkAsPage(&aBookmarkList, NULL, bLink, bReplace,
123 									   nInsertPos, bNoDialogs, NULL, bCopy, sal_True, sal_True);
124 
125 			if( !pDoc->pDocLockedInsertingLinks )
126 				pDoc->CloseBookmarkDoc();
127 		}
128 	}
129 }
130 
131 /*************************************************************************
132 |*
133 |* Link an oder abmelden
134 |*
135 \************************************************************************/
136 
137 void SdPageLink::Closed()
138 {
139 	// Die Verbindung wird aufgehoben
140 	pPage->SetFileName(String());
141 	pPage->SetBookmarkName(String());
142 
143 	SvBaseLink::Closed();
144 }
145 
146 
147 
148