xref: /aoo42x/main/sw/source/ui/fldui/javaedit.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 // include ---------------------------------------------------------------
32 
33 
34 
35 #define _JAVAEDIT_CXX
36 #include <hintids.hxx>
37 
38 #ifndef _MSGBOX_HXX //autogen
39 #include <vcl/msgbox.hxx>
40 #endif
41 #include <vcl/svapp.hxx>
42 #include <svl/urihelper.hxx>
43 #ifndef _VIEW_HXX
44 #include <view.hxx>
45 #endif
46 #include <sfx2/docfile.hxx>
47 #include <sfx2/filedlghelper.hxx>
48 #include <docsh.hxx>
49 #include <wrtsh.hxx>
50 #include <fldbas.hxx>
51 #include <fldmgr.hxx>
52 #include <docufld.hxx>
53 #include <uitool.hxx>
54 #ifndef _JAVAEDIT_HXX
55 #include <javaedit.hxx>
56 #endif
57 
58 #ifndef _FLDUI_HRC
59 #include <fldui.hrc>
60 #endif
61 #ifndef _JAVAEDIT_HRC
62 #include <javaedit.hrc>
63 #endif
64 
65 // static ----------------------------------------------------------------
66 
67 // class SwJavaEditDialog ------------------------------------------------
68 
69 
70 
SwJavaEditDialog(Window * pParent,SwWrtShell * pWrtSh)71 SwJavaEditDialog::SwJavaEditDialog(Window* pParent, SwWrtShell* pWrtSh) :
72 
73 	SvxStandardDialog(pParent, SW_RES(DLG_JAVAEDIT)),
74 
75 	aTypeFT 		( this, SW_RES( FT_TYPE ) ),
76 	aTypeED 		( this, SW_RES( ED_TYPE ) ),
77 	aUrlRB 			( this, SW_RES( RB_URL ) ),
78     aEditRB         ( this, SW_RES( RB_EDIT ) ),
79     aUrlPB          ( this, SW_RES( PB_URL ) ),
80 	aUrlED 			( this, SW_RES( ED_URL ) ),
81 	aEditED 		( this, SW_RES( ED_EDIT ) ),
82     aPostItFL       ( this, SW_RES( FL_POSTIT ) ),
83 
84     aOKBtn          ( this, SW_RES( BTN_POST_OK ) ),
85 	aCancelBtn		( this, SW_RES( BTN_POST_CANCEL ) ),
86 	aPrevBtn		( this, SW_RES( BTN_PREV ) ),
87 	aNextBtn		( this, SW_RES( BTN_NEXT ) ),
88 	aHelpBtn		( this, SW_RES( BTN_POST_HELP ) ),
89 
90     bNew(sal_True),
91     bIsUrl(sal_False),
92 
93     pSh(pWrtSh),
94     pFileDlg(NULL),
95     pOldDefDlgParent(NULL)
96 {
97 	// Handler installieren
98 	aPrevBtn.SetClickHdl( LINK( this, SwJavaEditDialog, PrevHdl ) );
99 	aNextBtn.SetClickHdl( LINK( this, SwJavaEditDialog, NextHdl ) );
100 	aOKBtn.SetClickHdl( LINK( this, SwJavaEditDialog, OKHdl ) );
101 
102 	Link aLk = LINK(this, SwJavaEditDialog, RadioButtonHdl);
103 	aUrlRB.SetClickHdl(aLk);
104 	aEditRB.SetClickHdl(aLk);
105 	aUrlPB.SetClickHdl(LINK(this, SwJavaEditDialog, InsertFileHdl));
106 
107 	Font aFont( aEditED.GetFont() );
108 	aFont.SetWeight( WEIGHT_LIGHT );
109 	aEditED.SetFont( aFont );
110 
111 	pMgr = new SwFldMgr;
112 	pFld = (SwScriptField*)pMgr->GetCurFld();
113 
114 	bNew = !(pFld && pFld->GetTyp()->Which() == RES_SCRIPTFLD);
115 
116 	CheckTravel();
117 
118 	if( !bNew )
119 		SetText( SW_RES( STR_JAVA_EDIT ) );
120 	else
121 		// neu anlegen
122 		SetText( SW_RES( STR_JAVA_INSERT ) );
123 
124 	FreeResource();
125 
126 	RadioButtonHdl(NULL);
127 }
128 
129 /*------------------------------------------------------------------------
130  Beschreibung:
131 ------------------------------------------------------------------------*/
132 
133 
134 
~SwJavaEditDialog()135 SwJavaEditDialog::~SwJavaEditDialog()
136 {
137 	delete pMgr;
138     delete pFileDlg;
139     Application::SetDefDialogParent( pOldDefDlgParent );
140 }
141 
142 /*------------------------------------------------------------------------
143  Beschreibung:
144 ------------------------------------------------------------------------*/
145 
146 
147 
IMPL_LINK_INLINE_START(SwJavaEditDialog,PrevHdl,Button *,EMPTYARG)148 IMPL_LINK_INLINE_START( SwJavaEditDialog, PrevHdl, Button *, EMPTYARG )
149 {
150 	SetFld();
151 	pMgr->GoPrev();
152 	pFld = (SwScriptField*)pMgr->GetCurFld();
153 	CheckTravel();
154 	RadioButtonHdl(NULL);
155 
156 	return 0;
157 }
IMPL_LINK_INLINE_END(SwJavaEditDialog,PrevHdl,Button *,EMPTYARG)158 IMPL_LINK_INLINE_END( SwJavaEditDialog, PrevHdl, Button *, EMPTYARG )
159 
160 /*------------------------------------------------------------------------
161  Beschreibung:
162 ------------------------------------------------------------------------*/
163 
164 
165 
166 IMPL_LINK_INLINE_START( SwJavaEditDialog, NextHdl, Button *, EMPTYARG )
167 {
168 	SetFld();
169 	pMgr->GoNext();
170 	pFld = (SwScriptField*)pMgr->GetCurFld();
171 	CheckTravel();
172 	RadioButtonHdl(NULL);
173 
174 	return 0;
175 }
IMPL_LINK_INLINE_END(SwJavaEditDialog,NextHdl,Button *,EMPTYARG)176 IMPL_LINK_INLINE_END( SwJavaEditDialog, NextHdl, Button *, EMPTYARG )
177 
178 /*------------------------------------------------------------------------
179  Beschreibung:
180 ------------------------------------------------------------------------*/
181 
182 
183 
184 IMPL_LINK( SwJavaEditDialog, OKHdl, Button *, EMPTYARG )
185 {
186 	SetFld();
187 	EndDialog( RET_OK );
188 	return 0;
189 }
190 
191 /*------------------------------------------------------------------------
192  Beschreibung:
193 ------------------------------------------------------------------------*/
194 
195 
196 
Apply()197 void SwJavaEditDialog::Apply()
198 {
199 }
200 
201 /*------------------------------------------------------------------------
202  Beschreibung:
203 ------------------------------------------------------------------------*/
204 
205 
206 
CheckTravel()207 void SwJavaEditDialog::CheckTravel()
208 {
209 	sal_Bool bTravel = sal_False;
210 	sal_Bool bNext(sal_False), bPrev(sal_False);
211 
212 	if(!bNew)
213 	{
214 		// Traveling nur bei mehr als einem Feld
215 		pSh->StartAction();
216 		pSh->CreateCrsr();
217 
218 		bNext = pMgr->GoNext();
219 		if( bNext )
220 			pMgr->GoPrev();
221 
222 		if( 0 != ( bPrev = pMgr->GoPrev() ) )
223 			pMgr->GoNext();
224 		bTravel |= bNext|bPrev;
225 
226 		pSh->DestroyCrsr();
227 		pSh->EndAction();
228 
229 		if (pFld->IsCodeURL())
230 		{
231 			String sURL(pFld->GetPar2());
232 			if(sURL.Len())
233 			{
234 				INetURLObject aINetURL(sURL);
235 				if(INET_PROT_FILE == aINetURL.GetProtocol())
236 					sURL = aINetURL.PathToFileName();
237 			}
238 			aUrlED.SetText(sURL);
239 			aEditED.SetText(aEmptyStr);
240 			aUrlRB.Check();
241 		}
242 		else
243 		{
244 			aEditED.SetText(pFld->GetPar2());
245 			aUrlED.SetText(aEmptyStr);
246 			aEditRB.Check();
247 		}
248 		aTypeED.SetText(pFld->GetPar1());
249 	}
250 
251 	if ( !bTravel )
252 	{
253 		aPrevBtn.Hide();
254 		aNextBtn.Hide();
255 	}
256 	else
257 	{
258 		aPrevBtn.Enable(bPrev);
259 		aNextBtn.Enable(bNext);
260 	}
261 }
262 
263 /*------------------------------------------------------------------------
264  Beschreibung:
265 ------------------------------------------------------------------------*/
266 
267 
268 
SetFld()269 void SwJavaEditDialog::SetFld()
270 {
271 	if( !aOKBtn.IsEnabled() )
272 		return ;
273 
274     aType = aTypeED.GetText();
275     bIsUrl = aUrlRB.IsChecked();
276 
277 	if( bIsUrl )
278 	{
279         aText = aUrlED.GetText();
280         if(aText.Len())
281         {
282             SfxMedium* pMedium = pSh->GetView().GetDocShell()->GetMedium();
283             INetURLObject aAbs;
284             if( pMedium )
285                 aAbs = pMedium->GetURLObject();
286 
287             aText = URIHelper::SmartRel2Abs(
288                 aAbs, aText, URIHelper::GetMaybeFileHdl());
289         }
290 	}
291 	else
292         aText = aEditED.GetText();
293 
294     if( !aType.Len() )
295         aType = String::CreateFromAscii("JavaScript");
296 }
297 
IsUpdate()298 sal_Bool SwJavaEditDialog::IsUpdate()
299 {
300     return pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
301 }
302 
303 /*------------------------------------------------------------------------
304  Beschreibung:
305 ------------------------------------------------------------------------*/
306 
IMPL_LINK(SwJavaEditDialog,RadioButtonHdl,RadioButton *,EMPTYARG)307 IMPL_LINK( SwJavaEditDialog, RadioButtonHdl, RadioButton *, EMPTYARG )
308 {
309 	sal_Bool bEnable = aUrlRB.IsChecked();
310 	aUrlPB.Enable(bEnable);
311 	aUrlED.Enable(bEnable);
312 	aEditED.Enable(!bEnable);
313 
314 	if( !bNew )
315 	{
316 		bEnable = !pSh->IsReadOnlyAvailable() || !pSh->HasReadonlySel();
317 		aOKBtn.Enable( bEnable );
318 		aUrlED.SetReadOnly( !bEnable );
319 		aEditED.SetReadOnly( !bEnable);
320 		aTypeED.SetReadOnly( !bEnable);
321 		if( aUrlPB.IsEnabled() && !bEnable )
322 			aUrlPB.Enable( sal_False );
323 	}
324 	return 0;
325 }
326 
327 /***************************************************************************
328 	Beschreibung:
329 ***************************************************************************/
330 
IMPL_LINK(SwJavaEditDialog,InsertFileHdl,PushButton *,pBtn)331 IMPL_LINK( SwJavaEditDialog, InsertFileHdl, PushButton *, pBtn )
332 {
333     if ( !pFileDlg )
334     {
335         pOldDefDlgParent = Application::GetDefDialogParent();
336         Application::SetDefDialogParent( pBtn );
337 
338         pFileDlg = new ::sfx2::FileDialogHelper(
339             (SFXWB_INSERT | WB_3DLOOK), String::CreateFromAscii("swriter") );
340     }
341 
342     pFileDlg->StartExecuteModal( LINK( this, SwJavaEditDialog, DlgClosedHdl ) );
343     return 0;
344 }
345 
IMPL_LINK(SwJavaEditDialog,DlgClosedHdl,sfx2::FileDialogHelper *,EMPTYARG)346 IMPL_LINK( SwJavaEditDialog, DlgClosedHdl, sfx2::FileDialogHelper *, EMPTYARG )
347 {
348     if ( pFileDlg->GetError() == ERRCODE_NONE )
349     {
350         String sFileName = pFileDlg->GetPath();
351         if ( sFileName.Len() > 0 )
352         {
353             INetURLObject aINetURL( sFileName );
354             if ( INET_PROT_FILE == aINetURL.GetProtocol() )
355                 sFileName = aINetURL.PathToFileName();
356         }
357         aUrlED.SetText( sFileName );
358     }
359 
360     return 0;
361 }
362 
363