LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - fldedt.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 151 0.0 %
Date: 2014-04-14 Functions: 0 16 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 <vcl/msgbox.hxx>
      21             : #include <sfx2/basedlgs.hxx>
      22             : #include <sfx2/viewfrm.hxx>
      23             : #include <sfx2/request.hxx>
      24             : #include <sfx2/app.hxx>
      25             : #include <svx/optgenrl.hxx>
      26             : #include <docufld.hxx>
      27             : #include <expfld.hxx>
      28             : #include <view.hxx>
      29             : #include <dbfld.hxx>
      30             : #include <wrtsh.hxx>
      31             : #include <flddb.hxx>
      32             : #include <flddinf.hxx>
      33             : #include <fldvar.hxx>
      34             : #include <flddok.hxx>
      35             : #include <fldfunc.hxx>
      36             : #include <fldref.hxx>
      37             : #include <fldedt.hxx>
      38             : #include <crsskip.hxx>
      39             : 
      40             : #include <cmdid.h>
      41             : #include <helpid.h>
      42             : #include <globals.hrc>
      43             : #include <fldui.hrc>
      44             : #include "swabstdlg.hxx"
      45             : #include "dialog.hrc"
      46             : 
      47             : #include <com/sun/star/document/XDocumentProperties.hpp>
      48             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      49             : 
      50             : namespace swui
      51             : {
      52             :     SwAbstractDialogFactory * GetFactory();
      53             : }
      54             : 
      55           0 : SwFldEditDlg::SwFldEditDlg(SwView& rVw)
      56           0 :     : SfxSingleTabDialog(&rVw.GetViewFrame()->GetWindow(), 0,
      57             :         "EditFieldDialog", "modules/swriter/ui/editfielddialog.ui")
      58           0 :     , pSh(rVw.GetWrtShellPtr())
      59             : {
      60           0 :     get(m_pPrevBT, "prev");
      61           0 :     get(m_pNextBT, "next");
      62           0 :     get(m_pAddressBT, "edit");
      63             : 
      64           0 :     SwFldMgr aMgr(pSh);
      65             : 
      66           0 :     SwField *pCurFld = aMgr.GetCurFld();
      67           0 :     if(!pCurFld)
      68           0 :         return;
      69             : 
      70           0 :     pSh->SetCareWin(this);
      71             : 
      72           0 :     if ( pSh->CrsrInsideInputFld() )
      73             :     {
      74             :         // move cursor to start of Input Field
      75           0 :         SwInputField* pInputFld = dynamic_cast<SwInputField*>(pCurFld);
      76           0 :         if ( pInputFld != NULL
      77           0 :              && pInputFld->GetFmtFld() != NULL )
      78             :         {
      79           0 :             pSh->GotoField( *(pInputFld->GetFmtFld()) );
      80             :         }
      81             :     }
      82             : 
      83           0 :     if ( ! pSh->HasSelection() )
      84             :     {
      85           0 :         pSh->Right(CRSR_SKIP_CHARS, true, 1, false);
      86             :     }
      87             : 
      88           0 :     pSh->NormalizePam();
      89             : 
      90           0 :     sal_uInt16 nGroup = aMgr.GetGroup(false, pCurFld->GetTypeId(), pCurFld->GetSubType());
      91             : 
      92           0 :     CreatePage(nGroup);
      93             : 
      94           0 :     GetOKButton()->SetClickHdl(LINK(this, SwFldEditDlg, OKHdl));
      95             : 
      96           0 :     m_pPrevBT->SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
      97           0 :     m_pNextBT->SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
      98             : 
      99           0 :     m_pAddressBT->SetClickHdl(LINK(this, SwFldEditDlg, AddressHdl));
     100             : 
     101           0 :     Init();
     102             : }
     103             : 
     104             : /*--------------------------------------------------------------------
     105             :     Description: initialise controls
     106             :  --------------------------------------------------------------------*/
     107           0 : void SwFldEditDlg::Init()
     108             : {
     109           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     110             : 
     111           0 :     if( pTabPage )
     112             :     {
     113           0 :         SwFldMgr& rMgr = pTabPage->GetFldMgr();
     114             : 
     115           0 :         SwField *pCurFld = rMgr.GetCurFld();
     116             : 
     117           0 :         if(!pCurFld)
     118           0 :             return;
     119             : 
     120             :         // Traveling only when more than one field
     121           0 :         pSh->StartAction();
     122           0 :         pSh->CreateCrsr();
     123             : 
     124           0 :         sal_Bool bMove = rMgr.GoNext();
     125           0 :         if( bMove )
     126           0 :             rMgr.GoPrev();
     127           0 :         m_pNextBT->Enable(bMove);
     128             : 
     129           0 :         if( 0 != ( bMove = rMgr.GoPrev() ) )
     130           0 :             rMgr.GoNext();
     131           0 :         m_pPrevBT->Enable( bMove );
     132             : 
     133           0 :         if (pCurFld->GetTypeId() == TYP_EXTUSERFLD)
     134           0 :             m_pAddressBT->Show();
     135             : 
     136           0 :         pSh->DestroyCrsr();
     137           0 :         pSh->EndAction();
     138             :     }
     139             : 
     140           0 :     GetOKButton()->Enable( !pSh->IsReadOnlyAvailable() ||
     141           0 :                            !pSh->HasReadonlySel() );
     142             : }
     143             : 
     144           0 : SfxTabPage* SwFldEditDlg::CreatePage(sal_uInt16 nGroup)
     145             : {
     146             :     // create TabPage
     147           0 :     SfxTabPage* pTabPage = 0;
     148             : 
     149           0 :     switch (nGroup)
     150             :     {
     151             :         case GRP_DOC:
     152           0 :             pTabPage = SwFldDokPage::Create(get_content_area(), *(SfxItemSet*)0);
     153           0 :             break;
     154             :         case GRP_FKT:
     155           0 :             pTabPage = SwFldFuncPage::Create(get_content_area(), *(SfxItemSet*)0);
     156           0 :             break;
     157             :         case GRP_REF:
     158           0 :             pTabPage = SwFldRefPage::Create(get_content_area(), *(SfxItemSet*)0);
     159           0 :             break;
     160             :         case GRP_REG:
     161             :             {
     162           0 :                 SfxObjectShell* pDocSh = SfxObjectShell::Current();
     163           0 :                 SfxItemSet* pSet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
     164             :                 using namespace ::com::sun::star;
     165             :                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     166           0 :                     pDocSh->GetModel(), uno::UNO_QUERY_THROW);
     167             :                 uno::Reference<document::XDocumentProperties> xDocProps
     168           0 :                     = xDPS->getDocumentProperties();
     169             :                 uno::Reference< beans::XPropertySet > xUDProps(
     170           0 :                     xDocProps->getUserDefinedProperties(),
     171           0 :                     uno::UNO_QUERY_THROW);
     172           0 :                 pSet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) );
     173           0 :                 pTabPage = SwFldDokInfPage::Create(get_content_area(), *pSet);
     174           0 :                 break;
     175             :             }
     176             :         case GRP_DB:
     177           0 :             pTabPage = SwFldDBPage::Create(get_content_area(), *(SfxItemSet*)0);
     178           0 :             static_cast<SwFldDBPage*>(pTabPage)->SetWrtShell(*pSh);
     179           0 :             break;
     180             :         case GRP_VAR:
     181           0 :             pTabPage = SwFldVarPage::Create(get_content_area(), *(SfxItemSet*)0);
     182           0 :             break;
     183             : 
     184             :     }
     185             : 
     186             :     assert(pTabPage);
     187             : 
     188           0 :     if (pTabPage)
     189             :     {
     190           0 :         static_cast<SwFldPage*>(pTabPage)->SetWrtShell(pSh);
     191           0 :         SetTabPage(pTabPage);
     192             :     }
     193             : 
     194           0 :     return pTabPage;
     195             : }
     196             : 
     197           0 : SwFldEditDlg::~SwFldEditDlg()
     198             : {
     199           0 :     pSh->SetCareWin(NULL);
     200           0 :     pSh->EnterStdMode();
     201           0 : }
     202             : 
     203           0 : void SwFldEditDlg::EnableInsert(sal_Bool bEnable)
     204             : {
     205           0 :     if( bEnable && pSh->IsReadOnlyAvailable() && pSh->HasReadonlySel() )
     206           0 :         bEnable = sal_False;
     207           0 :     GetOKButton()->Enable( bEnable );
     208           0 : }
     209             : 
     210           0 : void SwFldEditDlg::InsertHdl()
     211             : {
     212           0 :     GetOKButton()->Click();
     213           0 : }
     214             : 
     215             : /*--------------------------------------------------------------------
     216             :      Description: kick off changing of the field
     217             :  --------------------------------------------------------------------*/
     218           0 : IMPL_LINK_NOARG(SwFldEditDlg, OKHdl)
     219             : {
     220           0 :     if (GetOKButton()->IsEnabled())
     221             :     {
     222           0 :         SfxTabPage* pTabPage = GetTabPage();
     223           0 :         if (pTabPage)
     224             :         {
     225           0 :             pTabPage->FillItemSet(*(SfxItemSet*)0);
     226             : 
     227             :         }
     228           0 :         EndDialog( RET_OK );
     229             :     }
     230             : 
     231           0 :     return 0;
     232             : }
     233             : 
     234           0 : short SwFldEditDlg::Execute()
     235             : {
     236             :     // without TabPage no dialog
     237           0 :     return GetTabPage() ? Dialog::Execute() : static_cast<short>(RET_CANCEL);
     238             : }
     239             : 
     240             : /*--------------------------------------------------------------------
     241             :     Description: Traveling between fields of the same type
     242             :  --------------------------------------------------------------------*/
     243           0 : IMPL_LINK( SwFldEditDlg, NextPrevHdl, Button *, pButton )
     244             : {
     245           0 :     bool bNext = pButton == m_pNextBT;
     246             : 
     247           0 :     pSh->EnterStdMode();
     248             : 
     249           0 :     SwFieldType *pOldTyp = 0;
     250           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     251             : 
     252             :     //#112462# FillItemSet may delete the current field
     253             :     //that's why it has to be called before accessing the current field
     254           0 :     if( GetOKButton()->IsEnabled() )
     255           0 :         pTabPage->FillItemSet(*(SfxItemSet*)0);
     256             : 
     257           0 :     SwFldMgr& rMgr = pTabPage->GetFldMgr();
     258           0 :     SwField *pCurFld = rMgr.GetCurFld();
     259           0 :     if (pCurFld->GetTypeId() == TYP_DBFLD)
     260           0 :         pOldTyp = (SwDBFieldType*)pCurFld->GetTyp();
     261             : 
     262           0 :     rMgr.GoNextPrev( bNext, pOldTyp );
     263           0 :     pCurFld = rMgr.GetCurFld();
     264             : 
     265             :     /* #108536# Only create selection if there is none
     266             :         already. Normalize PaM instead of swapping. */
     267           0 :     if ( ! pSh->HasSelection() )
     268           0 :         pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     269             : 
     270           0 :     pSh->NormalizePam();
     271             : 
     272           0 :     sal_uInt16 nGroup = rMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType());
     273             : 
     274           0 :     if (nGroup != pTabPage->GetGroup())
     275           0 :         pTabPage = (SwFldPage*)CreatePage(nGroup);
     276             : 
     277           0 :     pTabPage->EditNewField();
     278             : 
     279           0 :     Init();
     280             : 
     281           0 :     return 0;
     282             : }
     283             : 
     284           0 : IMPL_LINK_NOARG(SwFldEditDlg, AddressHdl)
     285             : {
     286           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     287           0 :     SwFldMgr& rMgr = pTabPage->GetFldMgr();
     288           0 :     SwField *pCurFld = rMgr.GetCurFld();
     289             : 
     290           0 :     SfxItemSet aSet( pSh->GetAttrPool(),
     291             :                         SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS,
     292           0 :                         0L );
     293             : 
     294           0 :     sal_uInt16 nEditPos = UNKNOWN_EDIT;
     295             : 
     296           0 :     switch(pCurFld->GetSubType())
     297             :     {
     298           0 :         case EU_FIRSTNAME:  nEditPos = FIRSTNAME_EDIT;  break;
     299           0 :         case EU_NAME:       nEditPos = LASTNAME_EDIT;   break;
     300           0 :         case EU_SHORTCUT:   nEditPos = SHORTNAME_EDIT;  break;
     301           0 :         case EU_COMPANY:    nEditPos = COMPANY_EDIT;    break;
     302           0 :         case EU_STREET:     nEditPos = STREET_EDIT;     break;
     303           0 :         case EU_TITLE:      nEditPos = TITLE_EDIT;      break;
     304           0 :         case EU_POSITION:   nEditPos = POSITION_EDIT;   break;
     305           0 :         case EU_PHONE_PRIVATE:nEditPos = TELPRIV_EDIT;  break;
     306           0 :         case EU_PHONE_COMPANY:nEditPos = TELCOMPANY_EDIT;   break;
     307           0 :         case EU_FAX:        nEditPos = FAX_EDIT;        break;
     308           0 :         case EU_EMAIL:      nEditPos = EMAIL_EDIT;      break;
     309           0 :         case EU_COUNTRY:    nEditPos = COUNTRY_EDIT;    break;
     310           0 :         case EU_ZIP:        nEditPos = PLZ_EDIT;        break;
     311           0 :         case EU_CITY:       nEditPos = CITY_EDIT;       break;
     312           0 :         case EU_STATE:      nEditPos = STATE_EDIT;      break;
     313             : 
     314           0 :         default:            nEditPos = UNKNOWN_EDIT;    break;
     315             : 
     316             :     }
     317           0 :     aSet.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS, nEditPos));
     318           0 :     SwAbstractDialogFactory* pFact = swui::GetFactory();
     319             :     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     320             : 
     321             :     SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aSet,
     322           0 :         pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(),
     323           0 :         RC_DLG_ADDR );
     324             :     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     325           0 :     if(RET_OK == pDlg->Execute())
     326             :     {
     327           0 :         pSh->UpdateFlds( *pCurFld );
     328             :     }
     329           0 :     delete pDlg;
     330           0 :     return 0;
     331           0 : }
     332             : 
     333             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10