xref: /trunk/main/cui/source/dialogs/hldocntp.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "hldocntp.hxx"
32*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
33*cdf0e10cSrcweir #include <sfx2/docfac.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
35*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h>
36*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/uno/Exception.hpp>
38*cdf0e10cSrcweir #include <unotools/localfilehelper.hxx>
39*cdf0e10cSrcweir #include <tools/config.hxx>
40*cdf0e10cSrcweir #include <vcl/image.hxx>
41*cdf0e10cSrcweir #include <tools/urlobj.hxx>
42*cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
43*cdf0e10cSrcweir #include <unotools/dynamicmenuoptions.hxx>
44*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
45*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
46*cdf0e10cSrcweir #include <unotools/ucbhelper.hxx>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include "hyperdlg.hrc"
49*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
55*cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs;
56*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using namespace ::rtl;
59*cdf0e10cSrcweir using namespace ::com::sun::star;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir /*************************************************************************
62*cdf0e10cSrcweir |*
63*cdf0e10cSrcweir |* Data-struct for documenttypes in listbox
64*cdf0e10cSrcweir |*
65*cdf0e10cSrcweir |************************************************************************/
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir struct DocumentTypeData
68*cdf0e10cSrcweir {
69*cdf0e10cSrcweir     String aStrURL;
70*cdf0e10cSrcweir     String aStrExt;
71*cdf0e10cSrcweir     DocumentTypeData (String aURL, String aExt) : aStrURL(aURL), aStrExt(aExt)
72*cdf0e10cSrcweir     {}
73*cdf0e10cSrcweir };
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir sal_Bool SvxHyperlinkNewDocTp::ImplGetURLObject( const String& rPath, const String& rBase, INetURLObject& aURLObject ) const
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     sal_Bool bIsValidURL = rPath.Len() != 0;
78*cdf0e10cSrcweir     if ( bIsValidURL )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         aURLObject.SetURL( rPath );
81*cdf0e10cSrcweir         if ( aURLObject.GetProtocol() == INET_PROT_NOT_VALID )      // test if the source is already a valid url
82*cdf0e10cSrcweir         {                                                           // if not we have to create a url from a physical file name
83*cdf0e10cSrcweir             bool wasAbs;
84*cdf0e10cSrcweir             INetURLObject base(rBase);
85*cdf0e10cSrcweir             base.setFinalSlash();
86*cdf0e10cSrcweir             aURLObject = base.smartRel2Abs(
87*cdf0e10cSrcweir                 rPath, wasAbs, true, INetURLObject::ENCODE_ALL,
88*cdf0e10cSrcweir                 RTL_TEXTENCODING_UTF8, true);
89*cdf0e10cSrcweir         }
90*cdf0e10cSrcweir         bIsValidURL = aURLObject.GetProtocol() != INET_PROT_NOT_VALID;
91*cdf0e10cSrcweir         if ( bIsValidURL )
92*cdf0e10cSrcweir         {
93*cdf0e10cSrcweir             String aBase( aURLObject.getName( INetURLObject::LAST_SEGMENT, sal_False ) );
94*cdf0e10cSrcweir             if ( ( aBase.Len() == 0 ) || ( aBase.GetChar( 0 ) == '.' ) )
95*cdf0e10cSrcweir                 bIsValidURL = sal_False;
96*cdf0e10cSrcweir         }
97*cdf0e10cSrcweir         if ( bIsValidURL )
98*cdf0e10cSrcweir         {
99*cdf0e10cSrcweir             sal_uInt16 nPos = maLbDocTypes.GetSelectEntryPos();
100*cdf0e10cSrcweir             if ( nPos != LISTBOX_ENTRY_NOTFOUND )
101*cdf0e10cSrcweir                 aURLObject.SetExtension( ((DocumentTypeData*)maLbDocTypes.GetEntryData( nPos ))->aStrExt );
102*cdf0e10cSrcweir         }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir     return bIsValidURL;
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir /*************************************************************************
109*cdf0e10cSrcweir |*
110*cdf0e10cSrcweir |* Contructor / Destructor
111*cdf0e10cSrcweir |*
112*cdf0e10cSrcweir |************************************************************************/
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir SvxHyperlinkNewDocTp::SvxHyperlinkNewDocTp ( Window *pParent, const SfxItemSet& rItemSet)
115*cdf0e10cSrcweir :   SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_NEWDOCUMENT ), rItemSet ),
116*cdf0e10cSrcweir     maGrpNewDoc     ( this, CUI_RES (GRP_NEWDOCUMENT) ),
117*cdf0e10cSrcweir     maRbtEditNow    ( this, CUI_RES (RB_EDITNOW) ),
118*cdf0e10cSrcweir     maRbtEditLater  ( this, CUI_RES (RB_EDITLATER) ),
119*cdf0e10cSrcweir     maFtPath        ( this, CUI_RES (FT_PATH_NEWDOC) ),
120*cdf0e10cSrcweir     maCbbPath       ( this, INET_PROT_FILE ),
121*cdf0e10cSrcweir     maBtCreate      ( this, CUI_RES (BTN_CREATE) ),
122*cdf0e10cSrcweir     maFtDocTypes    ( this, CUI_RES (FT_DOCUMENT_TYPES) ),
123*cdf0e10cSrcweir     maLbDocTypes    ( this, CUI_RES (LB_DOCUMENT_TYPES) )
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     // Set HC bitmaps and disable display of bitmap names.
126*cdf0e10cSrcweir     maBtCreate.SetModeImage( Image( CUI_RES( IMG_CREATE_HC ) ), BMP_COLOR_HIGHCONTRAST );
127*cdf0e10cSrcweir     maBtCreate.EnableTextDisplay (sal_False);
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     InitStdControls();
130*cdf0e10cSrcweir     FreeResource();
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     SetExchangeSupport ();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     maCbbPath.SetPosSizePixel ( LogicToPixel( Point( COL_2 , 25 ), MAP_APPFONT ),
135*cdf0e10cSrcweir                                 LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
136*cdf0e10cSrcweir     maCbbPath.Show();
137*cdf0e10cSrcweir     maCbbPath.SetBaseURL(SvtPathOptions().GetWorkPath());
138*cdf0e10cSrcweir //  maCbbPath.SetHelpId( HID_HYPERDLG_DOC_PATH );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     // set defaults
141*cdf0e10cSrcweir     maRbtEditNow.Check();
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     maBtCreate.SetClickHdl        ( LINK ( this, SvxHyperlinkNewDocTp, ClickNewHdl_Impl ) );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     maBtCreate.SetAccessibleRelationMemberOf( &maGrpNewDoc );
146*cdf0e10cSrcweir     maBtCreate.SetAccessibleRelationLabeledBy( &maFtPath );
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     FillDocumentList ();
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir SvxHyperlinkNewDocTp::~SvxHyperlinkNewDocTp ()
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<maLbDocTypes.GetEntryCount(); n++ )
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         DocumentTypeData* pTypeData = (DocumentTypeData*)
156*cdf0e10cSrcweir                                       maLbDocTypes.GetEntryData ( n );
157*cdf0e10cSrcweir         delete pTypeData;
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir /*************************************************************************
162*cdf0e10cSrcweir |*
163*cdf0e10cSrcweir |* Fill the all dialog-controls except controls in groupbox "more..."
164*cdf0e10cSrcweir |*
165*cdf0e10cSrcweir |************************************************************************/
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void SvxHyperlinkNewDocTp::FillDlgFields ( String& /*aStrURL*/ )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir #define INTERNETSHORTCUT_ID_TAG       "InternetShortcut"
173*cdf0e10cSrcweir #define INTERNETSHORTCUT_TITLE_TAG    "Title"
174*cdf0e10cSrcweir #define INTERNETSHORTCUT_TARGET_TAG   "Target"
175*cdf0e10cSrcweir #define INTERNETSHORTCUT_FOLDER_TAG   "Folder"
176*cdf0e10cSrcweir #define INTERNETSHORTCUT_URL_TAG      "URL"
177*cdf0e10cSrcweir #define INTERNETSHORTCUT_ICONID_TAG   "IconIndex"
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir void SvxHyperlinkNewDocTp::FillDocumentList ()
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     EnterWait();
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     uno::Sequence< uno::Sequence< beans::PropertyValue > >
184*cdf0e10cSrcweir         aDynamicMenuEntries( SvtDynamicMenuOptions().GetMenu( E_NEWMENU ) );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     sal_uInt32 i, nCount = aDynamicMenuEntries.getLength();
187*cdf0e10cSrcweir     for ( i = 0; i < nCount; i++ )
188*cdf0e10cSrcweir     {
189*cdf0e10cSrcweir         uno::Sequence< beans::PropertyValue >& rDynamicMenuEntry = aDynamicMenuEntries[ i ];
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir         rtl::OUString aDocumentUrl, aTitle, aImageId, aTargetName;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir         for ( int e = 0; e < rDynamicMenuEntry.getLength(); e++ )
194*cdf0e10cSrcweir         {
195*cdf0e10cSrcweir             if ( rDynamicMenuEntry[ e ].Name == DYNAMICMENU_PROPERTYNAME_URL )
196*cdf0e10cSrcweir                 rDynamicMenuEntry[ e ].Value >>= aDocumentUrl;
197*cdf0e10cSrcweir             else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_TITLE )
198*cdf0e10cSrcweir                 rDynamicMenuEntry[e].Value >>= aTitle;
199*cdf0e10cSrcweir             else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_IMAGEIDENTIFIER )
200*cdf0e10cSrcweir                 rDynamicMenuEntry[e].Value >>= aImageId;
201*cdf0e10cSrcweir             else if ( rDynamicMenuEntry[e].Name == DYNAMICMENU_PROPERTYNAME_TARGETNAME )
202*cdf0e10cSrcweir                 rDynamicMenuEntry[e].Value >>= aTargetName;
203*cdf0e10cSrcweir         }
204*cdf0e10cSrcweir         //#i96822# business cards, labels and database should not be inserted here
205*cdf0e10cSrcweir         if( aDocumentUrl.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "private:factory/swriter?slot=21051" ) ) ||
206*cdf0e10cSrcweir                 aDocumentUrl.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "private:factory/swriter?slot=21052" )) ||
207*cdf0e10cSrcweir                 aDocumentUrl.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "private:factory/sdatabase?Interactive" )))
208*cdf0e10cSrcweir             continue;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir         // Insert into listbox
211*cdf0e10cSrcweir         if ( aDocumentUrl.getLength() )
212*cdf0e10cSrcweir         {
213*cdf0e10cSrcweir             if ( aDocumentUrl.equalsAscii( "private:factory/simpress?slot=6686" ) )             // SJ: #106216# do not start
214*cdf0e10cSrcweir                 aDocumentUrl = String( RTL_CONSTASCII_USTRINGPARAM( "private:factory/simpress" ) ); // the AutoPilot for impress
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir             // insert private-url and default-extension as user-data
217*cdf0e10cSrcweir             const SfxFilter* pFilter = SfxFilter::GetDefaultFilterFromFactory( aDocumentUrl );
218*cdf0e10cSrcweir             if ( pFilter )
219*cdf0e10cSrcweir             {
220*cdf0e10cSrcweir                 // insert doc-name and image
221*cdf0e10cSrcweir                 String aTitleName( aTitle );
222*cdf0e10cSrcweir                 aTitleName.Erase( aTitleName.Search( (sal_Unicode)'~' ), 1 );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir                 sal_Int16 nPos = maLbDocTypes.InsertEntry ( aTitleName );
225*cdf0e10cSrcweir                 String aStrDefExt( pFilter->GetDefaultExtension () );
226*cdf0e10cSrcweir                 DocumentTypeData *pTypeData = new DocumentTypeData ( aDocumentUrl, aStrDefExt.Copy( 2, aStrDefExt.Len() ) );
227*cdf0e10cSrcweir                 maLbDocTypes.SetEntryData ( nPos, pTypeData );
228*cdf0e10cSrcweir             }
229*cdf0e10cSrcweir         }
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir     maLbDocTypes.SelectEntryPos ( 0 );
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     LeaveWait();
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir /*************************************************************************
237*cdf0e10cSrcweir |*
238*cdf0e10cSrcweir |* retrieve and prepare data from dialog-fields
239*cdf0e10cSrcweir |*
240*cdf0e10cSrcweir |************************************************************************/
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir void SvxHyperlinkNewDocTp::GetCurentItemData ( String& aStrURL, String& aStrName,
243*cdf0e10cSrcweir                                                String& aStrIntName, String& aStrFrame,
244*cdf0e10cSrcweir                                                SvxLinkInsertMode& eMode )
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir     // get data from dialog-controls
247*cdf0e10cSrcweir     aStrURL = maCbbPath.GetText();
248*cdf0e10cSrcweir     INetURLObject aURL;
249*cdf0e10cSrcweir     if ( ImplGetURLObject( aStrURL, maCbbPath.GetBaseURL(), aURL ) )
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir         aStrURL     = aURL.GetMainURL( INetURLObject::NO_DECODE );
252*cdf0e10cSrcweir     }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
255*cdf0e10cSrcweir }
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir /*************************************************************************
258*cdf0e10cSrcweir |*
259*cdf0e10cSrcweir |* static method to create Tabpage
260*cdf0e10cSrcweir |*
261*cdf0e10cSrcweir |************************************************************************/
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir IconChoicePage* SvxHyperlinkNewDocTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     return( new SvxHyperlinkNewDocTp( pWindow, rItemSet ) );
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir /*************************************************************************
269*cdf0e10cSrcweir |*
270*cdf0e10cSrcweir |* Set initial focus
271*cdf0e10cSrcweir |*
272*cdf0e10cSrcweir |************************************************************************/
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void SvxHyperlinkNewDocTp::SetInitFocus()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     maCbbPath.GrabFocus();
277*cdf0e10cSrcweir }
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir /*************************************************************************
280*cdf0e10cSrcweir |*
281*cdf0e10cSrcweir |* Ask page whether an insert is possible
282*cdf0e10cSrcweir |*
283*cdf0e10cSrcweir \************************************************************************/
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir sal_Bool SvxHyperlinkNewDocTp::AskApply()
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     INetURLObject aINetURLObject;
288*cdf0e10cSrcweir     sal_Bool bRet = ImplGetURLObject( maCbbPath.GetText(), maCbbPath.GetBaseURL(), aINetURLObject );
289*cdf0e10cSrcweir     if ( !bRet )
290*cdf0e10cSrcweir     {
291*cdf0e10cSrcweir         WarningBox aWarning( this, WB_OK, CUI_RESSTR(RID_SVXSTR_HYPDLG_NOVALIDFILENAME) );
292*cdf0e10cSrcweir         aWarning.Execute();
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir     return bRet;
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir /*************************************************************************
298*cdf0e10cSrcweir |*
299*cdf0e10cSrcweir |* Any action to do after apply-button is pressed
300*cdf0e10cSrcweir |*
301*cdf0e10cSrcweir \************************************************************************/
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir void SvxHyperlinkNewDocTp::DoApply ()
304*cdf0e10cSrcweir {
305*cdf0e10cSrcweir     EnterWait();
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     // get data from dialog-controls
308*cdf0e10cSrcweir     String aStrNewName = maCbbPath.GetText();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     if ( aStrNewName == aEmptyStr )
311*cdf0e10cSrcweir         aStrNewName = maStrInitURL;
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     ///////////////////////////////////////////////////////
314*cdf0e10cSrcweir     // create a real URL-String
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     INetURLObject aURL;
317*cdf0e10cSrcweir     if ( ImplGetURLObject( aStrNewName, maCbbPath.GetBaseURL(), aURL ) )
318*cdf0e10cSrcweir     {
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir         ///////////////////////////////////////////////////////
321*cdf0e10cSrcweir         // create Document
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir         aStrNewName = aURL.GetURLPath( INetURLObject::NO_DECODE );
324*cdf0e10cSrcweir         SfxViewFrame *pViewFrame = NULL;
325*cdf0e10cSrcweir         try
326*cdf0e10cSrcweir         {
327*cdf0e10cSrcweir             bool bCreate = true;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir             // check if file exists, warn before we overwrite it
330*cdf0e10cSrcweir             {
331*cdf0e10cSrcweir                 com::sun::star::uno::Reference < com::sun::star::task::XInteractionHandler > xHandler;
332*cdf0e10cSrcweir                 SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ, xHandler );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir                 sal_Bool bOk = pIStm && ( pIStm->GetError() == 0);
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir                 if( pIStm )
337*cdf0e10cSrcweir                     delete pIStm;
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir                 if( bOk )
340*cdf0e10cSrcweir                 {
341*cdf0e10cSrcweir                     WarningBox aWarning( this, WB_YES_NO, CUI_RESSTR(RID_SVXSTR_HYPERDLG_QUERYOVERWRITE) );
342*cdf0e10cSrcweir                     bCreate = aWarning.Execute() == BUTTON_YES;
343*cdf0e10cSrcweir                 }
344*cdf0e10cSrcweir             }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir             if( bCreate )
347*cdf0e10cSrcweir             {
348*cdf0e10cSrcweir                 // current document
349*cdf0e10cSrcweir                 SfxViewFrame* pCurrentDocFrame = SfxViewFrame::Current();
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir                 if ( aStrNewName != aEmptyStr )
352*cdf0e10cSrcweir                 {
353*cdf0e10cSrcweir                     // get private-url
354*cdf0e10cSrcweir                     sal_uInt16 nPos = maLbDocTypes.GetSelectEntryPos();
355*cdf0e10cSrcweir                     if( nPos == LISTBOX_ENTRY_NOTFOUND )
356*cdf0e10cSrcweir                         nPos=0;
357*cdf0e10cSrcweir                     String aStrDocName ( ( ( DocumentTypeData* )
358*cdf0e10cSrcweir                                          maLbDocTypes.GetEntryData( nPos ) )->aStrURL );
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir                     // create items
361*cdf0e10cSrcweir                     SfxStringItem aName( SID_FILE_NAME, aStrDocName );
362*cdf0e10cSrcweir                     SfxStringItem aReferer( SID_REFERER, UniString::CreateFromAscii(
363*cdf0e10cSrcweir                                                 RTL_CONSTASCII_STRINGPARAM( "private:user" ) ) );
364*cdf0e10cSrcweir                     SfxStringItem aFrame( SID_TARGETNAME, UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "_blank" ) ) );
365*cdf0e10cSrcweir                     //SfxBoolItem aFrame( SID_OPEN_NEW_VIEW, sal_True );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir                     String aStrFlags ( sal_Unicode('S') );
368*cdf0e10cSrcweir                     if ( maRbtEditLater.IsChecked() )
369*cdf0e10cSrcweir                     {
370*cdf0e10cSrcweir                         aStrFlags += sal_Unicode('H');
371*cdf0e10cSrcweir                     }
372*cdf0e10cSrcweir                     SfxStringItem aFlags (SID_OPTIONS, aStrFlags);
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir                     // open url
375*cdf0e10cSrcweir                     const SfxPoolItem* pReturn = GetDispatcher()->Execute( SID_OPENDOC,
376*cdf0e10cSrcweir                                                                            SFX_CALLMODE_SYNCHRON,
377*cdf0e10cSrcweir                                                                            &aName, &aFlags,
378*cdf0e10cSrcweir                                                                            &aFrame, &aReferer, 0L );
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir                     // save new doc
381*cdf0e10cSrcweir                     const SfxViewFrameItem *pItem = PTR_CAST( SfxViewFrameItem, pReturn );  // SJ: pReturn is NULL if the Hyperlink
382*cdf0e10cSrcweir                     if ( pItem )                                                            // creation is cancelled #106216#
383*cdf0e10cSrcweir                     {
384*cdf0e10cSrcweir                         pViewFrame = pItem->GetFrame();
385*cdf0e10cSrcweir                         if (pViewFrame)
386*cdf0e10cSrcweir                         {
387*cdf0e10cSrcweir                             //SfxViewFrame *pViewFrame = pFrame->GetCurrentViewFrame();
388*cdf0e10cSrcweir                             SfxStringItem aNewName( SID_FILE_NAME, aURL.GetMainURL( INetURLObject::NO_DECODE ) );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir                             pViewFrame->GetDispatcher()->Execute( SID_SAVEASDOC,
391*cdf0e10cSrcweir                                                                   SFX_CALLMODE_SYNCHRON,
392*cdf0e10cSrcweir                                                                   &aNewName, 0L );
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir                         }
395*cdf0e10cSrcweir                     }
396*cdf0e10cSrcweir                 }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir                 if ( maRbtEditNow.IsChecked() && pCurrentDocFrame )
399*cdf0e10cSrcweir                 {
400*cdf0e10cSrcweir                     pCurrentDocFrame->ToTop();
401*cdf0e10cSrcweir                 }
402*cdf0e10cSrcweir             }
403*cdf0e10cSrcweir         }
404*cdf0e10cSrcweir         catch( uno::Exception )
405*cdf0e10cSrcweir         {
406*cdf0e10cSrcweir         }
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir         if ( pViewFrame && maRbtEditLater.IsChecked() )
409*cdf0e10cSrcweir         {
410*cdf0e10cSrcweir             SfxObjectShell* pObjShell = pViewFrame->GetObjectShell();
411*cdf0e10cSrcweir             pObjShell->DoClose();
412*cdf0e10cSrcweir         }
413*cdf0e10cSrcweir     }
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir     LeaveWait();
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir /*************************************************************************
419*cdf0e10cSrcweir |*
420*cdf0e10cSrcweir |* Click on imagebutton : new
421*cdf0e10cSrcweir |*
422*cdf0e10cSrcweir |************************************************************************/
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir IMPL_LINK ( SvxHyperlinkNewDocTp, ClickNewHdl_Impl, void *, EMPTYARG )
425*cdf0e10cSrcweir {
426*cdf0e10cSrcweir     rtl::OUString                       aService( RTL_CONSTASCII_USTRINGPARAM( FOLDER_PICKER_SERVICE_NAME ) );
427*cdf0e10cSrcweir     uno::Reference < XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
428*cdf0e10cSrcweir     uno::Reference < XFolderPicker >            xFolderPicker( xFactory->createInstance( aService ), UNO_QUERY );
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir     String              aStrURL;
431*cdf0e10cSrcweir     String              aTempStrURL( maCbbPath.GetText() );
432*cdf0e10cSrcweir     utl::LocalFileHelper::ConvertSystemPathToURL( aTempStrURL, maCbbPath.GetBaseURL(), aStrURL );
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir     String              aStrPath = aStrURL;
435*cdf0e10cSrcweir     sal_Bool                bZeroPath = ( aStrPath.Len() == 0 );
436*cdf0e10cSrcweir     sal_Bool                bHandleFileName = bZeroPath;    // when path has length of 0, then the rest should always be handled
437*cdf0e10cSrcweir                                                         //  as file name, otherwise we do not yet know
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     if( bZeroPath )
440*cdf0e10cSrcweir         aStrPath = SvtPathOptions().GetWorkPath();
441*cdf0e10cSrcweir     else if( !::utl::UCBContentHelper::IsFolder( aStrURL ) )
442*cdf0e10cSrcweir         bHandleFileName = sal_True;
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     xFolderPicker->setDisplayDirectory( aStrPath );
445*cdf0e10cSrcweir     DisableClose( sal_True );
446*cdf0e10cSrcweir     sal_Int16 nResult = xFolderPicker->execute();
447*cdf0e10cSrcweir     DisableClose( sal_False );
448*cdf0e10cSrcweir     if( ExecutableDialogResults::OK == nResult )
449*cdf0e10cSrcweir     {
450*cdf0e10cSrcweir         sal_Char const  sSlash[] = "/";
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir         INetURLObject   aURL( aStrURL, INET_PROT_FILE );
453*cdf0e10cSrcweir         String          aStrName;
454*cdf0e10cSrcweir         if( bHandleFileName )
455*cdf0e10cSrcweir             aStrName = bZeroPath? aTempStrURL : String(aURL.getName());
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir         maCbbPath.SetBaseURL( xFolderPicker->getDirectory() );
458*cdf0e10cSrcweir         String          aStrTmp( xFolderPicker->getDirectory() );
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir         if( aStrTmp.GetChar( aStrTmp.Len() - 1 ) != sSlash[0] )
461*cdf0e10cSrcweir             aStrTmp.AppendAscii( sSlash );
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir         // append old file name
464*cdf0e10cSrcweir         if( bHandleFileName )
465*cdf0e10cSrcweir             aStrTmp += aStrName;
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir         INetURLObject   aNewURL( aStrTmp );
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir         if( aStrName.Len() > 0 && aNewURL.getExtension().getLength() > 0 &&
470*cdf0e10cSrcweir             maLbDocTypes.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
471*cdf0e10cSrcweir         {
472*cdf0e10cSrcweir             // get private-url
473*cdf0e10cSrcweir             sal_uInt16 nPos = maLbDocTypes.GetSelectEntryPos();
474*cdf0e10cSrcweir             aNewURL.setExtension( ( ( DocumentTypeData* ) maLbDocTypes.GetEntryData( nPos ) )->aStrExt );
475*cdf0e10cSrcweir         }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir         if( aNewURL.GetProtocol() == INET_PROT_FILE )
478*cdf0e10cSrcweir         {
479*cdf0e10cSrcweir             utl::LocalFileHelper::ConvertURLToSystemPath( aNewURL.GetMainURL( INetURLObject::NO_DECODE ), aStrTmp );
480*cdf0e10cSrcweir         }
481*cdf0e10cSrcweir         else
482*cdf0e10cSrcweir         {
483*cdf0e10cSrcweir             aStrTmp = aNewURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
484*cdf0e10cSrcweir         }
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir         maCbbPath.SetText ( aStrTmp );
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir     return( 0L );
489*cdf0e10cSrcweir }
490*cdf0e10cSrcweir 
491