1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javaedit.cxx,v $
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
38 // include ---------------------------------------------------------------
43 #include <hintids.hxx>
45 #ifndef _MSGBOX_HXX //autogen
46 #include <vcl/msgbox.hxx>
48 #include <vcl/svapp.hxx>
49 #include <svtools/urihelper.hxx>
53 #include <sfx2/docfile.hxx>
54 #include <sfx2/filedlghelper.hxx>
59 #include <docufld.hxx>
62 #include <javaedit.hxx>
69 #include <javaedit.hrc>
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
) ),
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
);
119 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
121 bNew
= !(pFld
&& pFld
->GetTyp()->Which() == RES_SCRIPTFLD
);
126 SetText( SW_RES( STR_JAVA_EDIT
) );
129 SetText( SW_RES( STR_JAVA_INSERT
) );
133 RadioButtonHdl(NULL
);
136 /*------------------------------------------------------------------------
138 ------------------------------------------------------------------------*/
142 SwJavaEditDialog::~SwJavaEditDialog()
146 Application::SetDefDialogParent( pOldDefDlgParent
);
149 /*------------------------------------------------------------------------
151 ------------------------------------------------------------------------*/
155 IMPL_LINK_INLINE_START( SwJavaEditDialog
, PrevHdl
, Button
*, EMPTYARG
)
159 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
161 RadioButtonHdl(NULL
);
165 IMPL_LINK_INLINE_END( SwJavaEditDialog
, PrevHdl
, Button
*, EMPTYARG
)
167 /*------------------------------------------------------------------------
169 ------------------------------------------------------------------------*/
173 IMPL_LINK_INLINE_START( SwJavaEditDialog
, NextHdl
, Button
*, EMPTYARG
)
177 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
179 RadioButtonHdl(NULL
);
183 IMPL_LINK_INLINE_END( SwJavaEditDialog
, NextHdl
, Button
*, EMPTYARG
)
185 /*------------------------------------------------------------------------
187 ------------------------------------------------------------------------*/
191 IMPL_LINK( SwJavaEditDialog
, OKHdl
, Button
*, EMPTYARG
)
198 /*------------------------------------------------------------------------
200 ------------------------------------------------------------------------*/
204 void SwJavaEditDialog::Apply()
208 /*------------------------------------------------------------------------
210 ------------------------------------------------------------------------*/
214 void SwJavaEditDialog::CheckTravel()
216 BOOL bTravel
= FALSE
;
217 BOOL
bNext(FALSE
), bPrev(FALSE
);
221 // Traveling nur bei mehr als einem Feld
225 bNext
= pMgr
->GoNext();
229 if( 0 != ( bPrev
= pMgr
->GoPrev() ) )
231 bTravel
|= bNext
|bPrev
;
236 if (pFld
->IsCodeURL())
238 String
sURL(pFld
->GetPar2());
241 INetURLObject
aINetURL(sURL
);
242 if(INET_PROT_FILE
== aINetURL
.GetProtocol())
243 sURL
= aINetURL
.PathToFileName();
245 aUrlED
.SetText(sURL
);
246 aEditED
.SetText(aEmptyStr
);
251 aEditED
.SetText(pFld
->GetPar2());
252 aUrlED
.SetText(aEmptyStr
);
255 aTypeED
.SetText(pFld
->GetPar1());
265 aPrevBtn
.Enable(bPrev
);
266 aNextBtn
.Enable(bNext
);
270 /*------------------------------------------------------------------------
272 ------------------------------------------------------------------------*/
276 void SwJavaEditDialog::SetFld()
278 if( !aOKBtn
.IsEnabled() )
281 aType
= aTypeED
.GetText();
282 bIsUrl
= aUrlRB
.IsChecked();
286 aText
= aUrlED
.GetText();
289 SfxMedium
* pMedium
= pSh
->GetView().GetDocShell()->GetMedium();
292 aAbs
= pMedium
->GetURLObject();
294 aText
= URIHelper::SmartRel2Abs(
295 aAbs
, aText
, URIHelper::GetMaybeFileHdl());
299 aText
= aEditED
.GetText();
302 aType
= String::CreateFromAscii("JavaScript");
305 BOOL
SwJavaEditDialog::IsUpdate()
307 return pFld
&& ( bIsUrl
!= pFld
->GetFormat() || pFld
->GetPar2() != aType
|| pFld
->GetPar1() != aText
);
310 /*------------------------------------------------------------------------
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
);
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
);
334 /***************************************************************************
336 ***************************************************************************/
338 IMPL_LINK( SwJavaEditDialog
, InsertFileHdl
, PushButton
*, pBtn
)
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
) );
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
);