merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / fldui / javaedit.cxx
blob4464ac59c8e8ceb4dbfa4a687830ca44e1822458
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javaedit.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
38 // include ---------------------------------------------------------------
42 #define _JAVAEDIT_CXX
43 #include <hintids.hxx>
45 #ifndef _MSGBOX_HXX //autogen
46 #include <vcl/msgbox.hxx>
47 #endif
48 #include <vcl/svapp.hxx>
49 #include <svtools/urihelper.hxx>
50 #ifndef _VIEW_HXX
51 #include <view.hxx>
52 #endif
53 #include <sfx2/docfile.hxx>
54 #include <sfx2/filedlghelper.hxx>
55 #include <docsh.hxx>
56 #include <wrtsh.hxx>
57 #include <fldbas.hxx>
58 #include <fldmgr.hxx>
59 #include <docufld.hxx>
60 #include <uitool.hxx>
61 #ifndef _JAVAEDIT_HXX
62 #include <javaedit.hxx>
63 #endif
65 #ifndef _FLDUI_HRC
66 #include <fldui.hrc>
67 #endif
68 #ifndef _JAVAEDIT_HRC
69 #include <javaedit.hrc>
70 #endif
72 // static ----------------------------------------------------------------
74 // class SwJavaEditDialog ------------------------------------------------
78 SwJavaEditDialog::SwJavaEditDialog(Window* pParent, SwWrtShell* pWrtSh) :
80 SvxStandardDialog(pParent, SW_RES(DLG_JAVAEDIT)),
82 aTypeFT ( this, SW_RES( FT_TYPE ) ),
83 aTypeED ( this, SW_RES( ED_TYPE ) ),
84 aUrlRB ( this, SW_RES( RB_URL ) ),
85 aEditRB ( this, SW_RES( RB_EDIT ) ),
86 aUrlPB ( this, SW_RES( PB_URL ) ),
87 aUrlED ( this, SW_RES( ED_URL ) ),
88 aEditED ( this, SW_RES( ED_EDIT ) ),
89 aPostItFL ( this, SW_RES( FL_POSTIT ) ),
91 aOKBtn ( this, SW_RES( BTN_POST_OK ) ),
92 aCancelBtn ( this, SW_RES( BTN_POST_CANCEL ) ),
93 aPrevBtn ( this, SW_RES( BTN_PREV ) ),
94 aNextBtn ( this, SW_RES( BTN_NEXT ) ),
95 aHelpBtn ( this, SW_RES( BTN_POST_HELP ) ),
97 bNew(TRUE),
98 bIsUrl(FALSE),
100 pSh(pWrtSh),
101 pFileDlg(NULL),
102 pOldDefDlgParent(NULL)
104 // Handler installieren
105 aPrevBtn.SetClickHdl( LINK( this, SwJavaEditDialog, PrevHdl ) );
106 aNextBtn.SetClickHdl( LINK( this, SwJavaEditDialog, NextHdl ) );
107 aOKBtn.SetClickHdl( LINK( this, SwJavaEditDialog, OKHdl ) );
109 Link aLk = LINK(this, SwJavaEditDialog, RadioButtonHdl);
110 aUrlRB.SetClickHdl(aLk);
111 aEditRB.SetClickHdl(aLk);
112 aUrlPB.SetClickHdl(LINK(this, SwJavaEditDialog, InsertFileHdl));
114 Font aFont( aEditED.GetFont() );
115 aFont.SetWeight( WEIGHT_LIGHT );
116 aEditED.SetFont( aFont );
118 pMgr = new SwFldMgr;
119 pFld = (SwScriptField*)pMgr->GetCurFld();
121 bNew = !(pFld && pFld->GetTyp()->Which() == RES_SCRIPTFLD);
123 CheckTravel();
125 if( !bNew )
126 SetText( SW_RES( STR_JAVA_EDIT ) );
127 else
128 // neu anlegen
129 SetText( SW_RES( STR_JAVA_INSERT ) );
131 FreeResource();
133 RadioButtonHdl(NULL);
136 /*------------------------------------------------------------------------
137 Beschreibung:
138 ------------------------------------------------------------------------*/
142 SwJavaEditDialog::~SwJavaEditDialog()
144 delete pMgr;
145 delete pFileDlg;
146 Application::SetDefDialogParent( pOldDefDlgParent );
149 /*------------------------------------------------------------------------
150 Beschreibung:
151 ------------------------------------------------------------------------*/
155 IMPL_LINK_INLINE_START( SwJavaEditDialog, PrevHdl, Button *, EMPTYARG )
157 SetFld();
158 pMgr->GoPrev();
159 pFld = (SwScriptField*)pMgr->GetCurFld();
160 CheckTravel();
161 RadioButtonHdl(NULL);
163 return 0;
165 IMPL_LINK_INLINE_END( SwJavaEditDialog, PrevHdl, Button *, EMPTYARG )
167 /*------------------------------------------------------------------------
168 Beschreibung:
169 ------------------------------------------------------------------------*/
173 IMPL_LINK_INLINE_START( SwJavaEditDialog, NextHdl, Button *, EMPTYARG )
175 SetFld();
176 pMgr->GoNext();
177 pFld = (SwScriptField*)pMgr->GetCurFld();
178 CheckTravel();
179 RadioButtonHdl(NULL);
181 return 0;
183 IMPL_LINK_INLINE_END( SwJavaEditDialog, NextHdl, Button *, EMPTYARG )
185 /*------------------------------------------------------------------------
186 Beschreibung:
187 ------------------------------------------------------------------------*/
191 IMPL_LINK( SwJavaEditDialog, OKHdl, Button *, EMPTYARG )
193 SetFld();
194 EndDialog( RET_OK );
195 return 0;
198 /*------------------------------------------------------------------------
199 Beschreibung:
200 ------------------------------------------------------------------------*/
204 void SwJavaEditDialog::Apply()
208 /*------------------------------------------------------------------------
209 Beschreibung:
210 ------------------------------------------------------------------------*/
214 void SwJavaEditDialog::CheckTravel()
216 BOOL bTravel = FALSE;
217 BOOL bNext(FALSE), bPrev(FALSE);
219 if(!bNew)
221 // Traveling nur bei mehr als einem Feld
222 pSh->StartAction();
223 pSh->CreateCrsr();
225 bNext = pMgr->GoNext();
226 if( bNext )
227 pMgr->GoPrev();
229 if( 0 != ( bPrev = pMgr->GoPrev() ) )
230 pMgr->GoNext();
231 bTravel |= bNext|bPrev;
233 pSh->DestroyCrsr();
234 pSh->EndAction();
236 if (pFld->IsCodeURL())
238 String sURL(pFld->GetPar2());
239 if(sURL.Len())
241 INetURLObject aINetURL(sURL);
242 if(INET_PROT_FILE == aINetURL.GetProtocol())
243 sURL = aINetURL.PathToFileName();
245 aUrlED.SetText(sURL);
246 aEditED.SetText(aEmptyStr);
247 aUrlRB.Check();
249 else
251 aEditED.SetText(pFld->GetPar2());
252 aUrlED.SetText(aEmptyStr);
253 aEditRB.Check();
255 aTypeED.SetText(pFld->GetPar1());
258 if ( !bTravel )
260 aPrevBtn.Hide();
261 aNextBtn.Hide();
263 else
265 aPrevBtn.Enable(bPrev);
266 aNextBtn.Enable(bNext);
270 /*------------------------------------------------------------------------
271 Beschreibung:
272 ------------------------------------------------------------------------*/
276 void SwJavaEditDialog::SetFld()
278 if( !aOKBtn.IsEnabled() )
279 return ;
281 aType = aTypeED.GetText();
282 bIsUrl = aUrlRB.IsChecked();
284 if( bIsUrl )
286 aText = aUrlED.GetText();
287 if(aText.Len())
289 SfxMedium* pMedium = pSh->GetView().GetDocShell()->GetMedium();
290 INetURLObject aAbs;
291 if( pMedium )
292 aAbs = pMedium->GetURLObject();
294 aText = URIHelper::SmartRel2Abs(
295 aAbs, aText, URIHelper::GetMaybeFileHdl());
298 else
299 aText = aEditED.GetText();
301 if( !aType.Len() )
302 aType = String::CreateFromAscii("JavaScript");
305 BOOL SwJavaEditDialog::IsUpdate()
307 return pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
310 /*------------------------------------------------------------------------
311 Beschreibung:
312 ------------------------------------------------------------------------*/
314 IMPL_LINK( SwJavaEditDialog, RadioButtonHdl, RadioButton *, EMPTYARG )
316 BOOL bEnable = aUrlRB.IsChecked();
317 aUrlPB.Enable(bEnable);
318 aUrlED.Enable(bEnable);
319 aEditED.Enable(!bEnable);
321 if( !bNew )
323 bEnable = !pSh->IsReadOnlyAvailable() || !pSh->HasReadonlySel();
324 aOKBtn.Enable( bEnable );
325 aUrlED.SetReadOnly( !bEnable );
326 aEditED.SetReadOnly( !bEnable);
327 aTypeED.SetReadOnly( !bEnable);
328 if( aUrlPB.IsEnabled() && !bEnable )
329 aUrlPB.Enable( FALSE );
331 return 0;
334 /***************************************************************************
335 Beschreibung:
336 ***************************************************************************/
338 IMPL_LINK( SwJavaEditDialog, InsertFileHdl, PushButton *, pBtn )
340 if ( !pFileDlg )
342 pOldDefDlgParent = Application::GetDefDialogParent();
343 Application::SetDefDialogParent( pBtn );
345 pFileDlg = new ::sfx2::FileDialogHelper(
346 (SFXWB_INSERT | WB_3DLOOK), String::CreateFromAscii("swriter") );
349 pFileDlg->StartExecuteModal( LINK( this, SwJavaEditDialog, DlgClosedHdl ) );
350 return 0;
353 IMPL_LINK( SwJavaEditDialog, DlgClosedHdl, sfx2::FileDialogHelper *, EMPTYARG )
355 if ( pFileDlg->GetError() == ERRCODE_NONE )
357 String sFileName = pFileDlg->GetPath();
358 if ( sFileName.Len() > 0 )
360 INetURLObject aINetURL( sFileName );
361 if ( INET_PROT_FILE == aINetURL.GetProtocol() )
362 sFileName = aINetURL.PathToFileName();
364 aUrlED.SetText( sFileName );
367 return 0;