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