bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / fldui / javaedit.cxx
blob4d27dd6636c1f6e70f083f7d01893d1f79d80022
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <view.hxx>
26 #include <sfx2/docfile.hxx>
27 #include <sfx2/filedlghelper.hxx>
28 #include <docsh.hxx>
29 #include <wrtsh.hxx>
30 #include <fldbas.hxx>
31 #include <fldmgr.hxx>
32 #include <docufld.hxx>
33 #include <uitool.hxx>
34 #include <javaedit.hxx>
36 #include <fldui.hrc>
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"),
51 bNew(sal_True),
52 bIsUrl(sal_False),
54 pSh(pWrtSh),
55 pFileDlg(NULL),
56 pOldDefDlgParent(NULL)
58 get(m_pTypeED, "scripttype");
59 get(m_pUrlRB, "url");
60 get(m_pUrlED, "urlentry");
61 get(m_pUrlPB, "browse");
62 get(m_pEditRB, "text");
63 get(m_pEditED, "textentry");
65 get(m_pOKBtn, "ok");
66 get(m_pPrevBtn, "previous");
67 get(m_pNextBtn, "next");
69 // install handler
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 );
83 pMgr = new SwFldMgr;
84 pFld = (SwScriptField*)pMgr->GetCurFld();
86 bNew = !(pFld && pFld->GetTyp()->Which() == RES_SCRIPTFLD);
88 CheckTravel();
90 if( !bNew )
91 SetText( SW_RES( STR_JAVA_EDIT ) );
93 RadioButtonHdl(NULL);
96 SwJavaEditDialog::~SwJavaEditDialog()
98 delete pMgr;
99 delete pFileDlg;
100 Application::SetDefDialogParent( pOldDefDlgParent );
103 IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, PrevHdl)
105 SetFld();
106 pMgr->GoPrev();
107 pFld = (SwScriptField*)pMgr->GetCurFld();
108 CheckTravel();
109 RadioButtonHdl(NULL);
111 return 0;
113 IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, PrevHdl)
115 IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, NextHdl)
117 SetFld();
118 pMgr->GoNext();
119 pFld = (SwScriptField*)pMgr->GetCurFld();
120 CheckTravel();
121 RadioButtonHdl(NULL);
123 return 0;
125 IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, NextHdl)
127 IMPL_LINK_NOARG(SwJavaEditDialog, OKHdl)
129 SetFld();
130 EndDialog( RET_OK );
131 return 0;
134 void SwJavaEditDialog::Apply()
138 void SwJavaEditDialog::CheckTravel()
140 sal_Bool bTravel = sal_False;
141 sal_Bool bNext(sal_False), bPrev(sal_False);
143 if(!bNew)
145 // Traveling only when more than one field
146 pSh->StartAction();
147 pSh->CreateCrsr();
149 bNext = pMgr->GoNext();
150 if( bNext )
151 pMgr->GoPrev();
153 if( 0 != ( bPrev = pMgr->GoPrev() ) )
154 pMgr->GoNext();
155 bTravel |= bNext|bPrev;
157 pSh->DestroyCrsr();
158 pSh->EndAction();
160 if (pFld->IsCodeURL())
162 String sURL(pFld->GetPar2());
163 if(sURL.Len())
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);
171 m_pUrlRB->Check();
173 else
175 m_pEditED->SetText(pFld->GetPar2());
176 m_pUrlED->SetText(aEmptyStr);
177 m_pEditRB->Check();
179 m_pTypeED->SetText(pFld->GetPar1());
182 if ( !bTravel )
184 m_pPrevBtn->Hide();
185 m_pNextBtn->Hide();
187 else
189 m_pPrevBtn->Enable(bPrev);
190 m_pNextBtn->Enable(bNext);
194 void SwJavaEditDialog::SetFld()
196 if( !m_pOKBtn->IsEnabled() )
197 return ;
199 aType = m_pTypeED->GetText();
200 bIsUrl = m_pUrlRB->IsChecked();
202 if( bIsUrl )
204 aText = m_pUrlED->GetText();
205 if (!aText.isEmpty())
207 SfxMedium* pMedium = pSh->GetView().GetDocShell()->GetMedium();
208 INetURLObject aAbs;
209 if( pMedium )
210 aAbs = pMedium->GetURLObject();
212 aText = URIHelper::SmartRel2Abs(
213 aAbs, aText, URIHelper::GetMaybeFileHdl());
216 else
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);
235 if( !bNew )
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 );
245 return 0;
248 IMPL_LINK( SwJavaEditDialog, InsertFileHdl, PushButton *, pBtn )
250 if ( !pFileDlg )
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 ) );
261 return 0;
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 );
278 return 0;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */