Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
30 : : #include <hintids.hxx>
31 : : #include <vcl/msgbox.hxx>
32 : : #include <vcl/svapp.hxx>
33 : : #include <svl/urihelper.hxx>
34 : : #include <view.hxx>
35 : : #include <sfx2/docfile.hxx>
36 : : #include <sfx2/filedlghelper.hxx>
37 : : #include <docsh.hxx>
38 : : #include <wrtsh.hxx>
39 : : #include <fldbas.hxx>
40 : : #include <fldmgr.hxx>
41 : : #include <docufld.hxx>
42 : : #include <uitool.hxx>
43 : : #include <javaedit.hxx>
44 : :
45 : : #include <fldui.hrc>
46 : : #include <javaedit.hrc>
47 : :
48 : :
49 : : using namespace ::com::sun::star;
50 : :
51 : : // static ----------------------------------------------------------------
52 : :
53 : : // class SwJavaEditDialog ------------------------------------------------
54 : :
55 : :
56 : :
57 : 0 : SwJavaEditDialog::SwJavaEditDialog(Window* pParent, SwWrtShell* pWrtSh) :
58 : :
59 : : SvxStandardDialog(pParent, SW_RES(DLG_JAVAEDIT)),
60 : :
61 : : aTypeFT ( this, SW_RES( FT_TYPE ) ),
62 : : aTypeED ( this, SW_RES( ED_TYPE ) ),
63 : : aUrlRB ( this, SW_RES( RB_URL ) ),
64 : : aEditRB ( this, SW_RES( RB_EDIT ) ),
65 : : aUrlPB ( this, SW_RES( PB_URL ) ),
66 : : aUrlED ( this, SW_RES( ED_URL ) ),
67 : : aEditED ( this, SW_RES( ED_EDIT ) ),
68 : : aPostItFL ( this, SW_RES( FL_POSTIT ) ),
69 : :
70 : : aOKBtn ( this, SW_RES( BTN_POST_OK ) ),
71 : : aCancelBtn ( this, SW_RES( BTN_POST_CANCEL ) ),
72 : : aPrevBtn ( this, SW_RES( BTN_PREV ) ),
73 : : aNextBtn ( this, SW_RES( BTN_NEXT ) ),
74 : : aHelpBtn ( this, SW_RES( BTN_POST_HELP ) ),
75 : :
76 : : bNew(sal_True),
77 : : bIsUrl(sal_False),
78 : :
79 : : pSh(pWrtSh),
80 : : pFileDlg(NULL),
81 : 0 : pOldDefDlgParent(NULL)
82 : : {
83 : : // install handler
84 : 0 : aPrevBtn.SetClickHdl( LINK( this, SwJavaEditDialog, PrevHdl ) );
85 : 0 : aNextBtn.SetClickHdl( LINK( this, SwJavaEditDialog, NextHdl ) );
86 : 0 : aOKBtn.SetClickHdl( LINK( this, SwJavaEditDialog, OKHdl ) );
87 : :
88 : 0 : Link aLk = LINK(this, SwJavaEditDialog, RadioButtonHdl);
89 : 0 : aUrlRB.SetClickHdl(aLk);
90 : 0 : aEditRB.SetClickHdl(aLk);
91 : 0 : aUrlPB.SetClickHdl(LINK(this, SwJavaEditDialog, InsertFileHdl));
92 : :
93 : 0 : Font aFont( aEditED.GetFont() );
94 : 0 : aFont.SetWeight( WEIGHT_LIGHT );
95 : 0 : aEditED.SetFont( aFont );
96 : :
97 : 0 : pMgr = new SwFldMgr;
98 : 0 : pFld = (SwScriptField*)pMgr->GetCurFld();
99 : :
100 : 0 : bNew = !(pFld && pFld->GetTyp()->Which() == RES_SCRIPTFLD);
101 : :
102 : 0 : CheckTravel();
103 : :
104 : 0 : if( !bNew )
105 : 0 : SetText( SW_RES( STR_JAVA_EDIT ) );
106 : : else
107 : : // newly create
108 : 0 : SetText( SW_RES( STR_JAVA_INSERT ) );
109 : :
110 : 0 : FreeResource();
111 : :
112 : 0 : RadioButtonHdl(NULL);
113 : 0 : }
114 : :
115 : 0 : SwJavaEditDialog::~SwJavaEditDialog()
116 : : {
117 : 0 : delete pMgr;
118 : 0 : delete pFileDlg;
119 : 0 : Application::SetDefDialogParent( pOldDefDlgParent );
120 : 0 : }
121 : :
122 : 0 : IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, PrevHdl)
123 : : {
124 : 0 : SetFld();
125 : 0 : pMgr->GoPrev();
126 : 0 : pFld = (SwScriptField*)pMgr->GetCurFld();
127 : 0 : CheckTravel();
128 : 0 : RadioButtonHdl(NULL);
129 : :
130 : 0 : return 0;
131 : : }
132 : 0 : IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, PrevHdl)
133 : :
134 : 0 : IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, NextHdl)
135 : : {
136 : 0 : SetFld();
137 : 0 : pMgr->GoNext();
138 : 0 : pFld = (SwScriptField*)pMgr->GetCurFld();
139 : 0 : CheckTravel();
140 : 0 : RadioButtonHdl(NULL);
141 : :
142 : 0 : return 0;
143 : : }
144 : 0 : IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, NextHdl)
145 : :
146 : 0 : IMPL_LINK_NOARG(SwJavaEditDialog, OKHdl)
147 : : {
148 : 0 : SetFld();
149 : 0 : EndDialog( RET_OK );
150 : 0 : return 0;
151 : : }
152 : :
153 : 0 : void SwJavaEditDialog::Apply()
154 : : {
155 : 0 : }
156 : :
157 : 0 : void SwJavaEditDialog::CheckTravel()
158 : : {
159 : 0 : sal_Bool bTravel = sal_False;
160 : 0 : sal_Bool bNext(sal_False), bPrev(sal_False);
161 : :
162 : 0 : if(!bNew)
163 : : {
164 : : // Traveling only when more than one field
165 : 0 : pSh->StartAction();
166 : 0 : pSh->CreateCrsr();
167 : :
168 : 0 : bNext = pMgr->GoNext();
169 : 0 : if( bNext )
170 : 0 : pMgr->GoPrev();
171 : :
172 : 0 : if( 0 != ( bPrev = pMgr->GoPrev() ) )
173 : 0 : pMgr->GoNext();
174 : 0 : bTravel |= bNext|bPrev;
175 : :
176 : 0 : pSh->DestroyCrsr();
177 : 0 : pSh->EndAction();
178 : :
179 : 0 : if (pFld->IsCodeURL())
180 : : {
181 : 0 : String sURL(pFld->GetPar2());
182 : 0 : if(sURL.Len())
183 : : {
184 : 0 : INetURLObject aINetURL(sURL);
185 : 0 : if(INET_PROT_FILE == aINetURL.GetProtocol())
186 : 0 : sURL = aINetURL.PathToFileName();
187 : : }
188 : 0 : aUrlED.SetText(sURL);
189 : 0 : aEditED.SetText(aEmptyStr);
190 : 0 : aUrlRB.Check();
191 : : }
192 : : else
193 : : {
194 : 0 : aEditED.SetText(pFld->GetPar2());
195 : 0 : aUrlED.SetText(aEmptyStr);
196 : 0 : aEditRB.Check();
197 : : }
198 : 0 : aTypeED.SetText(pFld->GetPar1());
199 : : }
200 : :
201 : 0 : if ( !bTravel )
202 : : {
203 : 0 : aPrevBtn.Hide();
204 : 0 : aNextBtn.Hide();
205 : : }
206 : : else
207 : : {
208 : 0 : aPrevBtn.Enable(bPrev);
209 : 0 : aNextBtn.Enable(bNext);
210 : : }
211 : 0 : }
212 : :
213 : 0 : void SwJavaEditDialog::SetFld()
214 : : {
215 : 0 : if( !aOKBtn.IsEnabled() )
216 : 0 : return ;
217 : :
218 : 0 : aType = aTypeED.GetText();
219 : 0 : bIsUrl = aUrlRB.IsChecked();
220 : :
221 : 0 : if( bIsUrl )
222 : : {
223 : 0 : aText = aUrlED.GetText();
224 : 0 : if (!aText.isEmpty())
225 : : {
226 : 0 : SfxMedium* pMedium = pSh->GetView().GetDocShell()->GetMedium();
227 : 0 : INetURLObject aAbs;
228 : 0 : if( pMedium )
229 : 0 : aAbs = pMedium->GetURLObject();
230 : :
231 : : aText = URIHelper::SmartRel2Abs(
232 : 0 : aAbs, aText, URIHelper::GetMaybeFileHdl());
233 : : }
234 : : }
235 : : else
236 : 0 : aText = aEditED.GetText();
237 : :
238 : 0 : if( aType.isEmpty() )
239 : 0 : aType = "JavaScript";
240 : : }
241 : :
242 : 0 : sal_Bool SwJavaEditDialog::IsUpdate()
243 : : {
244 : 0 : return pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
245 : : }
246 : :
247 : 0 : IMPL_LINK_NOARG(SwJavaEditDialog, RadioButtonHdl)
248 : : {
249 : 0 : sal_Bool bEnable = aUrlRB.IsChecked();
250 : 0 : aUrlPB.Enable(bEnable);
251 : 0 : aUrlED.Enable(bEnable);
252 : 0 : aEditED.Enable(!bEnable);
253 : :
254 : 0 : if( !bNew )
255 : : {
256 : 0 : bEnable = !pSh->IsReadOnlyAvailable() || !pSh->HasReadonlySel();
257 : 0 : aOKBtn.Enable( bEnable );
258 : 0 : aUrlED.SetReadOnly( !bEnable );
259 : 0 : aEditED.SetReadOnly( !bEnable);
260 : 0 : aTypeED.SetReadOnly( !bEnable);
261 : 0 : if( aUrlPB.IsEnabled() && !bEnable )
262 : 0 : aUrlPB.Enable( sal_False );
263 : : }
264 : 0 : return 0;
265 : : }
266 : :
267 : 0 : IMPL_LINK( SwJavaEditDialog, InsertFileHdl, PushButton *, pBtn )
268 : : {
269 : 0 : if ( !pFileDlg )
270 : : {
271 : 0 : pOldDefDlgParent = Application::GetDefDialogParent();
272 : 0 : Application::SetDefDialogParent( pBtn );
273 : :
274 : : pFileDlg = new ::sfx2::FileDialogHelper(
275 : : ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
276 : 0 : SFXWB_INSERT, rtl::OUString("swriter") );
277 : : }
278 : :
279 : 0 : pFileDlg->StartExecuteModal( LINK( this, SwJavaEditDialog, DlgClosedHdl ) );
280 : 0 : return 0;
281 : : }
282 : :
283 : 0 : IMPL_LINK_NOARG(SwJavaEditDialog, DlgClosedHdl)
284 : : {
285 : 0 : if ( pFileDlg->GetError() == ERRCODE_NONE )
286 : : {
287 : 0 : String sFileName = pFileDlg->GetPath();
288 : 0 : if ( sFileName.Len() > 0 )
289 : : {
290 : 0 : INetURLObject aINetURL( sFileName );
291 : 0 : if ( INET_PROT_FILE == aINetURL.GetProtocol() )
292 : 0 : sFileName = aINetURL.PathToFileName();
293 : : }
294 : 0 : aUrlED.SetText( sFileName );
295 : : }
296 : :
297 : 0 : return 0;
298 : : }
299 : :
300 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|