1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
21 #include <hintids.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <vcl/svapp.hxx>
24 #include <svl/urihelper.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/filedlghelper.hxx>
32 #include <docufld.hxx>
34 #include <javaedit.hxx>
37 #include <globals.hrc>
40 using namespace ::com::sun::star
;
42 // static ----------------------------------------------------------------
44 // class SwJavaEditDialog ------------------------------------------------
48 SwJavaEditDialog::SwJavaEditDialog(Window
* pParent
, SwWrtShell
* pWrtSh
) :
49 SvxStandardDialog(pParent
, "InsertScriptDialog", "modules/swriter/ui/insertscript.ui"),
56 pOldDefDlgParent(NULL
)
58 get(m_pTypeED
, "scripttype");
60 get(m_pUrlED
, "urlentry");
61 get(m_pUrlPB
, "browse");
62 get(m_pEditRB
, "text");
63 get(m_pEditED
, "textentry");
66 get(m_pPrevBtn
, "previous");
67 get(m_pNextBtn
, "next");
70 m_pPrevBtn
->SetClickHdl( LINK( this, SwJavaEditDialog
, PrevHdl
) );
71 m_pNextBtn
->SetClickHdl( LINK( this, SwJavaEditDialog
, NextHdl
) );
72 m_pOKBtn
->SetClickHdl( LINK( this, SwJavaEditDialog
, OKHdl
) );
74 Link aLk
= LINK(this, SwJavaEditDialog
, RadioButtonHdl
);
75 m_pUrlRB
->SetClickHdl(aLk
);
76 m_pEditRB
->SetClickHdl(aLk
);
77 m_pUrlPB
->SetClickHdl(LINK(this, SwJavaEditDialog
, InsertFileHdl
));
79 Font
aFont( m_pEditED
->GetFont() );
80 aFont
.SetWeight( WEIGHT_LIGHT
);
81 m_pEditED
->SetFont( aFont
);
84 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
86 bNew
= !(pFld
&& pFld
->GetTyp()->Which() == RES_SCRIPTFLD
);
91 SetText( SW_RES( STR_JAVA_EDIT
) );
96 SwJavaEditDialog::~SwJavaEditDialog()
100 Application::SetDefDialogParent( pOldDefDlgParent
);
103 IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog
, PrevHdl
)
107 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
109 RadioButtonHdl(NULL
);
113 IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog
, PrevHdl
)
115 IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog
, NextHdl
)
119 pFld
= (SwScriptField
*)pMgr
->GetCurFld();
121 RadioButtonHdl(NULL
);
125 IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog
, NextHdl
)
127 IMPL_LINK_NOARG(SwJavaEditDialog
, OKHdl
)
134 void SwJavaEditDialog::Apply()
138 void SwJavaEditDialog::CheckTravel()
140 sal_Bool bTravel
= sal_False
;
141 sal_Bool
bNext(sal_False
), bPrev(sal_False
);
145 // Traveling only when more than one field
149 bNext
= pMgr
->GoNext();
153 if( 0 != ( bPrev
= pMgr
->GoPrev() ) )
155 bTravel
|= bNext
|bPrev
;
160 if (pFld
->IsCodeURL())
162 String
sURL(pFld
->GetPar2());
165 INetURLObject
aINetURL(sURL
);
166 if(INET_PROT_FILE
== aINetURL
.GetProtocol())
167 sURL
= aINetURL
.PathToFileName();
169 m_pUrlED
->SetText(sURL
);
170 m_pEditED
->SetText(aEmptyStr
);
175 m_pEditED
->SetText(pFld
->GetPar2());
176 m_pUrlED
->SetText(aEmptyStr
);
179 m_pTypeED
->SetText(pFld
->GetPar1());
189 m_pPrevBtn
->Enable(bPrev
);
190 m_pNextBtn
->Enable(bNext
);
194 void SwJavaEditDialog::SetFld()
196 if( !m_pOKBtn
->IsEnabled() )
199 aType
= m_pTypeED
->GetText();
200 bIsUrl
= m_pUrlRB
->IsChecked();
204 aText
= m_pUrlED
->GetText();
205 if (!aText
.isEmpty())
207 SfxMedium
* pMedium
= pSh
->GetView().GetDocShell()->GetMedium();
210 aAbs
= pMedium
->GetURLObject();
212 aText
= URIHelper::SmartRel2Abs(
213 aAbs
, aText
, URIHelper::GetMaybeFileHdl());
217 aText
= m_pEditED
->GetText();
219 if( aType
.isEmpty() )
220 aType
= "JavaScript";
223 bool SwJavaEditDialog::IsUpdate()
225 return pFld
&& ( bIsUrl
!= pFld
->GetFormat() || pFld
->GetPar2() != aType
|| pFld
->GetPar1() != aText
);
228 IMPL_LINK_NOARG(SwJavaEditDialog
, RadioButtonHdl
)
230 sal_Bool bEnable
= m_pUrlRB
->IsChecked();
231 m_pUrlPB
->Enable(bEnable
);
232 m_pUrlED
->Enable(bEnable
);
233 m_pEditED
->Enable(!bEnable
);
237 bEnable
= !pSh
->IsReadOnlyAvailable() || !pSh
->HasReadonlySel();
238 m_pOKBtn
->Enable( bEnable
);
239 m_pUrlED
->SetReadOnly( !bEnable
);
240 m_pEditED
->SetReadOnly( !bEnable
);
241 m_pTypeED
->SetReadOnly( !bEnable
);
242 if( m_pUrlPB
->IsEnabled() && !bEnable
)
243 m_pUrlPB
->Enable( sal_False
);
248 IMPL_LINK( SwJavaEditDialog
, InsertFileHdl
, PushButton
*, pBtn
)
252 pOldDefDlgParent
= Application::GetDefDialogParent();
253 Application::SetDefDialogParent( pBtn
);
255 pFileDlg
= new ::sfx2::FileDialogHelper(
256 ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
257 SFXWB_INSERT
, OUString("swriter") );
260 pFileDlg
->StartExecuteModal( LINK( this, SwJavaEditDialog
, DlgClosedHdl
) );
264 IMPL_LINK_NOARG(SwJavaEditDialog
, DlgClosedHdl
)
266 if ( pFileDlg
->GetError() == ERRCODE_NONE
)
268 String sFileName
= pFileDlg
->GetPath();
269 if ( sFileName
.Len() > 0 )
271 INetURLObject
aINetURL( sFileName
);
272 if ( INET_PROT_FILE
== aINetURL
.GetProtocol() )
273 sFileName
= aINetURL
.PathToFileName();
275 m_pUrlED
->SetText( sFileName
);
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */