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