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