1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: doclinkdialog.cxx,v $
*
* $Revision: 1.11 $
*
* last change: $Author: hr $ $Date: 2007-06-27 17:03:00 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"
#ifdef SVX_DLLIMPLEMENTATION
#undef SVX_DLLIMPLEMENTATION
#endif
#ifndef _SVX_DOCLINKDIALOG_HXX_
#include "doclinkdialog.hxx"
#endif
#ifndef _SVX_DOCLINKDIALOG_HRC_
#include "doclinkdialog.hrc"
#endif
#include <svx/dialogs.hrc>
#include <svx/svxids.hrc>
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
#ifndef SVTOOLS_FILENOTATION_HXX_
#include <svtools/filenotation.hxx>
#endif
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
#ifndef _UCBHELPER_CONTENT_HXX
#include <ucbhelper/content.hxx>
#endif
#include <svx/dialmgr.hxx>
#ifndef _URLOBJ_HXX
#include <tools/urlobj.hxx>
#endif
#ifndef _FILEDLGHELPER_HXX
#include <sfx2/filedlghelper.hxx>
#endif
#ifndef _SFX_DOCFILT_HACK_HXX
#include <sfx2/docfilt.hxx>
#endif
//......................................................................
namespace svx
{
//......................................................................
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::svt;
//==================================================================
//= ODocumentLinkDialog
//==================================================================
//------------------------------------------------------------------
ODocumentLinkDialog::ODocumentLinkDialog( Window* _pParent, sal_Bool _bCreateNew )
:ModalDialog( _pParent, SVX_RES(DLG_DOCUMENTLINK) )
,m_aURLLabel (this, SVX_RES(FT_URL))
,m_aURL (this, SVX_RES(CMB_URL))
,m_aBrowseFile (this, SVX_RES(PB_BROWSEFILE))
,m_aNameLabel (this, SVX_RES(FT_NAME))
,m_aName (this, SVX_RES(ET_NAME))
,m_aBottomLine (this, SVX_RES(FL_BOTTOM))
,m_aOK (this, SVX_RES(BTN_OK))
,m_aCancel (this, SVX_RES(BTN_CANCEL))
,m_aHelp (this, SVX_RES(BTN_HELP))
,m_bCreatingNew(_bCreateNew)
{
String sText = String( SVX_RES( m_bCreatingNew ? STR_NEW_LINK : STR_EDIT_LINK ) );
SetText(sText);
FreeResource();
String sTemp = String::CreateFromAscii("*.odb");
m_aURL.SetFilter(sTemp);
m_aName.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
m_aURL.SetModifyHdl( LINK(this, ODocumentLinkDialog, OnTextModified) );
m_aBrowseFile.SetClickHdl( LINK(this, ODocumentLinkDialog, OnBrowseFile) );
m_aOK.SetClickHdl( LINK(this, ODocumentLinkDialog, OnOk) );
m_aURL.SetDropDownLineCount(10);
validate();
// m_aURL.SetHelpId( HID_DOCLINKEDIT_URL );
m_aURL.SetDropDownLineCount( 5 );
}
//------------------------------------------------------------------
void ODocumentLinkDialog::set( const String& _rName, const String& _rURL )
{
m_aName.SetText(_rName);
m_aURL.SetText(_rURL);
validate();
}
//------------------------------------------------------------------
void ODocumentLinkDialog::get( String& _rName, String& _rURL ) const
{
_rName = m_aName.GetText();
_rURL = m_aURL.GetText();
}
//------------------------------------------------------------------
void ODocumentLinkDialog::validate( )
{
m_aOK.Enable( (0 != m_aName.GetText().Len()) && ( 0 != m_aURL.GetText().Len() ) );
}
//------------------------------------------------------------------
IMPL_LINK( ODocumentLinkDialog, OnOk, void*, EMPTYARG )
{
// get the current URL
::rtl::OUString sURL = m_aURL.GetText();
OFileNotation aTransformer(sURL);
sURL = aTransformer.get(OFileNotation::N_URL);
// check for the existence of the selected file
sal_Bool bFileExists = sal_False;
try
{
::ucbhelper::Content aFile(sURL, Reference< XCommandEnvironment >());
if (aFile.isDocument())
bFileExists = sal_True;
}
catch(Exception&)
{
}
if (!bFileExists)
{
String sMsg = String(SVX_RES(STR_LINKEDDOC_DOESNOTEXIST));
sMsg.SearchAndReplaceAscii("$file$", m_aURL.GetText());
ErrorBox aError(this, WB_OK , sMsg);
aError.Execute();
return 0L;
} // if (!bFileExists)
String sCurrentText = m_aName.GetText();
if ( m_aNameValidator.IsSet() )
{
if ( !m_aNameValidator.Call( &sCurrentText ) )
{
String sMsg = String(SVX_RES(STR_NAME_CONFLICT));
sMsg.SearchAndReplaceAscii("$file$", sCurrentText);
InfoBox aError(this, sMsg);
aError.Execute();
m_aName.SetSelection(Selection(0,sCurrentText.Len()));
m_aName.GrabFocus();
return 0L;
}
}
EndDialog(RET_OK);
return 0L;
}
//------------------------------------------------------------------
IMPL_LINK( ODocumentLinkDialog, OnBrowseFile, void*, EMPTYARG )
{
::sfx2::FileDialogHelper aFileDlg(WB_3DLOOK | WB_STDMODAL | WB_OPEN);
static const String s_sDatabaseType = String::CreateFromAscii("StarOffice XML (Base)");
const SfxFilter* pFilter = SfxFilter::GetFilterByName( s_sDatabaseType);
if ( pFilter )
{
aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension());
aFileDlg.SetCurrentFilter(pFilter->GetUIName());
}
String sPath = m_aURL.GetText();
if (sPath.Len())
{
OFileNotation aTransformer( sPath, OFileNotation::N_SYSTEM );
aFileDlg.SetDisplayDirectory( aTransformer.get( OFileNotation::N_URL ) );
}
if (0 != aFileDlg.Execute())
return 0L;
if (0 == m_aName.GetText().Len())
{ // default the name to the base of the chosen URL
INetURLObject aParser;
aParser.SetSmartProtocol(INET_PROT_FILE);
aParser.SetSmartURL(aFileDlg.GetPath());
m_aName.SetText(aParser.getBase(INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET));
m_aName.SetSelection(Selection(0,m_aName.GetText().Len()));
m_aName.GrabFocus();
}
else
m_aURL.GrabFocus();
// get the path in system notation
OFileNotation aTransformer(aFileDlg.GetPath(), OFileNotation::N_URL);
m_aURL.SetText(aTransformer.get(OFileNotation::N_SYSTEM));
validate();
return 0L;
}
//------------------------------------------------------------------
IMPL_LINK( ODocumentLinkDialog, OnTextModified, Control*, EMPTYARG )
{
validate( );
return 0L;
}
//......................................................................
} // namespace svx
//......................................................................
|