LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - javaedit.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 138 0.0 %
Date: 2014-04-11 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      35             : 
      36             : #include <fldui.hrc>
      37             : #include <globals.hrc>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : 
      41             : // static ----------------------------------------------------------------
      42             : 
      43             : // class SwJavaEditDialog ------------------------------------------------
      44             : 
      45           0 : SwJavaEditDialog::SwJavaEditDialog(Window* pParent, SwWrtShell* pWrtSh) :
      46             :     SvxStandardDialog(pParent, "InsertScriptDialog", "modules/swriter/ui/insertscript.ui"),
      47             : 
      48             :     bNew(sal_True),
      49             :     bIsUrl(sal_False),
      50             : 
      51             :     pSh(pWrtSh),
      52             :     pFileDlg(NULL),
      53           0 :     pOldDefDlgParent(NULL)
      54             : {
      55           0 :     get(m_pTypeED, "scripttype");
      56           0 :     get(m_pUrlRB, "url");
      57           0 :     get(m_pUrlED, "urlentry");
      58           0 :     get(m_pUrlPB, "browse");
      59           0 :     get(m_pEditRB, "text");
      60           0 :     get(m_pEditED, "textentry");
      61             : 
      62           0 :     get(m_pOKBtn, "ok");
      63           0 :     get(m_pPrevBtn, "previous");
      64           0 :     get(m_pNextBtn, "next");
      65             : 
      66             :     // install handler
      67           0 :     m_pPrevBtn->SetClickHdl( LINK( this, SwJavaEditDialog, PrevHdl ) );
      68           0 :     m_pNextBtn->SetClickHdl( LINK( this, SwJavaEditDialog, NextHdl ) );
      69           0 :     m_pOKBtn->SetClickHdl( LINK( this, SwJavaEditDialog, OKHdl ) );
      70             : 
      71           0 :     Link aLk = LINK(this, SwJavaEditDialog, RadioButtonHdl);
      72           0 :     m_pUrlRB->SetClickHdl(aLk);
      73           0 :     m_pEditRB->SetClickHdl(aLk);
      74           0 :     m_pUrlPB->SetClickHdl(LINK(this, SwJavaEditDialog, InsertFileHdl));
      75             : 
      76           0 :     Font aFont( m_pEditED->GetFont() );
      77           0 :     aFont.SetWeight( WEIGHT_LIGHT );
      78           0 :     m_pEditED->SetFont( aFont );
      79             : 
      80           0 :     pMgr = new SwFldMgr;
      81           0 :     pFld = (SwScriptField*)pMgr->GetCurFld();
      82             : 
      83           0 :     bNew = !(pFld && pFld->GetTyp()->Which() == RES_SCRIPTFLD);
      84             : 
      85           0 :     CheckTravel();
      86             : 
      87           0 :     if( !bNew )
      88           0 :         SetText( SW_RES( STR_JAVA_EDIT ) );
      89             : 
      90           0 :     RadioButtonHdl(NULL);
      91           0 : }
      92             : 
      93           0 : SwJavaEditDialog::~SwJavaEditDialog()
      94             : {
      95           0 :     delete pMgr;
      96           0 :     delete pFileDlg;
      97           0 :     Application::SetDefDialogParent( pOldDefDlgParent );
      98           0 : }
      99             : 
     100           0 : IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, PrevHdl)
     101             : {
     102           0 :     SetFld();
     103           0 :     pMgr->GoPrev();
     104           0 :     pFld = (SwScriptField*)pMgr->GetCurFld();
     105           0 :     CheckTravel();
     106           0 :     RadioButtonHdl(NULL);
     107             : 
     108           0 :     return 0;
     109             : }
     110           0 : IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, PrevHdl)
     111             : 
     112           0 : IMPL_LINK_NOARG_INLINE_START(SwJavaEditDialog, NextHdl)
     113             : {
     114           0 :     SetFld();
     115           0 :     pMgr->GoNext();
     116           0 :     pFld = (SwScriptField*)pMgr->GetCurFld();
     117           0 :     CheckTravel();
     118           0 :     RadioButtonHdl(NULL);
     119             : 
     120           0 :     return 0;
     121             : }
     122           0 : IMPL_LINK_NOARG_INLINE_END(SwJavaEditDialog, NextHdl)
     123             : 
     124           0 : IMPL_LINK_NOARG(SwJavaEditDialog, OKHdl)
     125             : {
     126           0 :     SetFld();
     127           0 :     EndDialog( RET_OK );
     128           0 :     return 0;
     129             : }
     130             : 
     131           0 : void SwJavaEditDialog::Apply()
     132             : {
     133           0 : }
     134             : 
     135           0 : void SwJavaEditDialog::CheckTravel()
     136             : {
     137           0 :     sal_Bool bTravel = sal_False;
     138           0 :     sal_Bool bNext(sal_False), bPrev(sal_False);
     139             : 
     140           0 :     if(!bNew)
     141             :     {
     142             :         // Traveling only when more than one field
     143           0 :         pSh->StartAction();
     144           0 :         pSh->CreateCrsr();
     145             : 
     146           0 :         bNext = pMgr->GoNext();
     147           0 :         if( bNext )
     148           0 :             pMgr->GoPrev();
     149             : 
     150           0 :         if( 0 != ( bPrev = pMgr->GoPrev() ) )
     151           0 :             pMgr->GoNext();
     152           0 :         bTravel |= bNext|bPrev;
     153             : 
     154           0 :         pSh->DestroyCrsr();
     155           0 :         pSh->EndAction();
     156             : 
     157           0 :         if (pFld->IsCodeURL())
     158             :         {
     159           0 :             OUString sURL(pFld->GetPar2());
     160           0 :             if(!sURL.isEmpty())
     161             :             {
     162           0 :                 INetURLObject aINetURL(sURL);
     163           0 :                 if(INET_PROT_FILE == aINetURL.GetProtocol())
     164           0 :                     sURL = aINetURL.PathToFileName();
     165             :             }
     166           0 :             m_pUrlED->SetText(sURL);
     167           0 :             m_pEditED->SetText(OUString());
     168           0 :             m_pUrlRB->Check();
     169             :         }
     170             :         else
     171             :         {
     172           0 :             m_pEditED->SetText(pFld->GetPar2());
     173           0 :             m_pUrlED->SetText(OUString());
     174           0 :             m_pEditRB->Check();
     175             :         }
     176           0 :         m_pTypeED->SetText(pFld->GetPar1());
     177             :     }
     178             : 
     179           0 :     if ( !bTravel )
     180             :     {
     181           0 :         m_pPrevBtn->Hide();
     182           0 :         m_pNextBtn->Hide();
     183             :     }
     184             :     else
     185             :     {
     186           0 :         m_pPrevBtn->Enable(bPrev);
     187           0 :         m_pNextBtn->Enable(bNext);
     188             :     }
     189           0 : }
     190             : 
     191           0 : void SwJavaEditDialog::SetFld()
     192             : {
     193           0 :     if( !m_pOKBtn->IsEnabled() )
     194           0 :         return ;
     195             : 
     196           0 :     aType = m_pTypeED->GetText();
     197           0 :     bIsUrl = m_pUrlRB->IsChecked();
     198             : 
     199           0 :     if( bIsUrl )
     200             :     {
     201           0 :         aText = m_pUrlED->GetText();
     202           0 :         if (!aText.isEmpty())
     203             :         {
     204           0 :             SfxMedium* pMedium = pSh->GetView().GetDocShell()->GetMedium();
     205           0 :             INetURLObject aAbs;
     206           0 :             if( pMedium )
     207           0 :                 aAbs = pMedium->GetURLObject();
     208             : 
     209           0 :             aText = URIHelper::SmartRel2Abs(
     210           0 :                 aAbs, aText, URIHelper::GetMaybeFileHdl());
     211             :         }
     212             :     }
     213             :     else
     214           0 :         aText = m_pEditED->GetText();
     215             : 
     216           0 :     if( aType.isEmpty() )
     217           0 :         aType = "JavaScript";
     218             : }
     219             : 
     220           0 : bool SwJavaEditDialog::IsUpdate() const
     221             : {
     222           0 :     return pFld && ( bIsUrl != pFld->GetFormat() || pFld->GetPar2() != aType || pFld->GetPar1() != aText );
     223             : }
     224             : 
     225           0 : IMPL_LINK_NOARG(SwJavaEditDialog, RadioButtonHdl)
     226             : {
     227           0 :     sal_Bool bEnable = m_pUrlRB->IsChecked();
     228           0 :     m_pUrlPB->Enable(bEnable);
     229           0 :     m_pUrlED->Enable(bEnable);
     230           0 :     m_pEditED->Enable(!bEnable);
     231             : 
     232           0 :     if( !bNew )
     233             :     {
     234           0 :         bEnable = !pSh->IsReadOnlyAvailable() || !pSh->HasReadonlySel();
     235           0 :         m_pOKBtn->Enable( bEnable );
     236           0 :         m_pUrlED->SetReadOnly( !bEnable );
     237           0 :         m_pEditED->SetReadOnly( !bEnable);
     238           0 :         m_pTypeED->SetReadOnly( !bEnable);
     239           0 :         if( m_pUrlPB->IsEnabled() && !bEnable )
     240           0 :             m_pUrlPB->Enable( false );
     241             :     }
     242           0 :     return 0;
     243             : }
     244             : 
     245           0 : IMPL_LINK( SwJavaEditDialog, InsertFileHdl, PushButton *, pBtn )
     246             : {
     247           0 :     if ( !pFileDlg )
     248             :     {
     249           0 :         pOldDefDlgParent = Application::GetDefDialogParent();
     250           0 :         Application::SetDefDialogParent( pBtn );
     251             : 
     252             :         pFileDlg = new ::sfx2::FileDialogHelper(
     253             :             ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
     254           0 :             SFXWB_INSERT, OUString("swriter") );
     255             :     }
     256             : 
     257           0 :     pFileDlg->StartExecuteModal( LINK( this, SwJavaEditDialog, DlgClosedHdl ) );
     258           0 :     return 0;
     259             : }
     260             : 
     261           0 : IMPL_LINK_NOARG(SwJavaEditDialog, DlgClosedHdl)
     262             : {
     263           0 :     if ( pFileDlg->GetError() == ERRCODE_NONE )
     264             :     {
     265           0 :         OUString sFileName = pFileDlg->GetPath();
     266           0 :         if ( !sFileName.isEmpty() )
     267             :         {
     268           0 :             INetURLObject aINetURL( sFileName );
     269           0 :             if ( INET_PROT_FILE == aINetURL.GetProtocol() )
     270           0 :                 sFileName = aINetURL.PathToFileName();
     271             :         }
     272           0 :         m_pUrlED->SetText( sFileName );
     273             :     }
     274             : 
     275           0 :     return 0;
     276             : }
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10