LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - fldedt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 165 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 18 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             : #include <boost/scoped_ptr.hpp>
      50             : #include <swuiexp.hxx>
      51             : 
      52           0 : void SwFieldEditDlg::EnsureSelection(SwField *pCurField, SwFieldMgr &rMgr)
      53             : {
      54           0 :     if (pSh->CrsrInsideInputField())
      55             :     {
      56             :         // move cursor to start of Input Field
      57           0 :         SwInputField* pInputField = dynamic_cast<SwInputField*>(pCurField);
      58           0 :         if (pInputField && pInputField->GetFormatField())
      59             :         {
      60           0 :             pSh->GotoField( *(pInputField->GetFormatField()) );
      61             :         }
      62             :     }
      63             : 
      64             :     /* Only create selection if there is none already.
      65             :        Normalize PaM instead of swapping. */
      66           0 :     if (!pSh->HasSelection())
      67             :     {
      68           0 :         SwShellCrsr* pCrsr = pSh->getShellCrsr(true);
      69           0 :         SwPosition aOrigPos(*pCrsr->GetPoint());
      70             : 
      71             :         //After this attempt it is possible that rMgr.GetCurField() != pCurField if
      72             :         //the field was in e.g. a zero height portion and so invisible in which
      73             :         //case it will be skipped over
      74           0 :         pSh->Right(CRSR_SKIP_CHARS, true, 1, false );
      75             :         //So (fdo#50640) if it didn't work then reposition back to the original
      76             :         //location where the field was
      77           0 :         SwField *pRealCurField = rMgr.GetCurField();
      78           0 :         bool bSelectionFailed = pCurField != pRealCurField;
      79           0 :         if (bSelectionFailed)
      80             :         {
      81           0 :             pCrsr->DeleteMark();
      82           0 :             *pCrsr->GetPoint() = aOrigPos;
      83           0 :         }
      84             :     }
      85             : 
      86           0 :     pSh->NormalizePam();
      87             : 
      88             :     assert(pCurField == rMgr.GetCurField());
      89           0 : }
      90             : 
      91           0 : SwFieldEditDlg::SwFieldEditDlg(SwView& rVw)
      92           0 :     : SfxSingleTabDialog(&rVw.GetViewFrame()->GetWindow(), 0,
      93             :         "EditFieldDialog", "modules/swriter/ui/editfielddialog.ui")
      94           0 :     , pSh(rVw.GetWrtShellPtr())
      95             : {
      96           0 :     get(m_pPrevBT, "prev");
      97           0 :     get(m_pNextBT, "next");
      98           0 :     get(m_pAddressBT, "edit");
      99             : 
     100           0 :     SwFieldMgr aMgr(pSh);
     101             : 
     102           0 :     SwField *pCurField = aMgr.GetCurField();
     103           0 :     if (!pCurField)
     104           0 :         return;
     105             : 
     106           0 :     SwViewShell::SetCareWin(this);
     107             : 
     108           0 :     EnsureSelection(pCurField, aMgr);
     109             : 
     110           0 :     sal_uInt16 nGroup = SwFieldMgr::GetGroup(false, pCurField->GetTypeId(), pCurField->GetSubType());
     111             : 
     112           0 :     CreatePage(nGroup);
     113             : 
     114           0 :     GetOKButton()->SetClickHdl(LINK(this, SwFieldEditDlg, OKHdl));
     115             : 
     116           0 :     m_pPrevBT->SetClickHdl(LINK(this, SwFieldEditDlg, NextPrevHdl));
     117           0 :     m_pNextBT->SetClickHdl(LINK(this, SwFieldEditDlg, NextPrevHdl));
     118             : 
     119           0 :     m_pAddressBT->SetClickHdl(LINK(this, SwFieldEditDlg, AddressHdl));
     120             : 
     121           0 :     Init();
     122             : }
     123             : 
     124             : // initialise controls
     125           0 : void SwFieldEditDlg::Init()
     126             : {
     127           0 :     VclPtr<SwFieldPage> pTabPage = static_cast<SwFieldPage*>(GetTabPage());
     128             : 
     129           0 :     if( pTabPage )
     130             :     {
     131           0 :         SwFieldMgr& rMgr = pTabPage->GetFieldMgr();
     132             : 
     133           0 :         SwField *pCurField = rMgr.GetCurField();
     134             : 
     135           0 :         if(!pCurField)
     136           0 :             return;
     137             : 
     138             :         // Traveling only when more than one field
     139           0 :         pSh->StartAction();
     140           0 :         pSh->CreateCrsr();
     141             : 
     142           0 :         bool bMove = rMgr.GoNext();
     143           0 :         if( bMove )
     144           0 :             rMgr.GoPrev();
     145           0 :         m_pNextBT->Enable(bMove);
     146             : 
     147           0 :         if( ( bMove = rMgr.GoPrev() ) )
     148           0 :             rMgr.GoNext();
     149           0 :         m_pPrevBT->Enable( bMove );
     150             : 
     151           0 :         if (pCurField->GetTypeId() == TYP_EXTUSERFLD)
     152           0 :             m_pAddressBT->Show();
     153             : 
     154           0 :         pSh->DestroyCrsr();
     155           0 :         pSh->EndAction();
     156             :     }
     157             : 
     158           0 :     GetOKButton()->Enable( !pSh->IsReadOnlyAvailable() ||
     159           0 :                            !pSh->HasReadonlySel() );
     160             : }
     161             : 
     162           0 : VclPtr<SfxTabPage> SwFieldEditDlg::CreatePage(sal_uInt16 nGroup)
     163             : {
     164             :     // create TabPage
     165           0 :     VclPtr<SfxTabPage> pTabPage;
     166             : 
     167           0 :     switch (nGroup)
     168             :     {
     169             :         case GRP_DOC:
     170           0 :             pTabPage = SwFieldDokPage::Create(get_content_area(), 0);
     171           0 :             break;
     172             :         case GRP_FKT:
     173           0 :             pTabPage = SwFieldFuncPage::Create(get_content_area(), 0);
     174           0 :             break;
     175             :         case GRP_REF:
     176           0 :             pTabPage = SwFieldRefPage::Create(get_content_area(), 0);
     177           0 :             break;
     178             :         case GRP_REG:
     179             :             {
     180           0 :                 SfxObjectShell* pDocSh = SfxObjectShell::Current();
     181           0 :                 SfxItemSet* pSet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
     182             :                 using namespace ::com::sun::star;
     183             :                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     184           0 :                     pDocSh->GetModel(), uno::UNO_QUERY_THROW);
     185             :                 uno::Reference<document::XDocumentProperties> xDocProps
     186           0 :                     = xDPS->getDocumentProperties();
     187             :                 uno::Reference< beans::XPropertySet > xUDProps(
     188           0 :                     xDocProps->getUserDefinedProperties(),
     189           0 :                     uno::UNO_QUERY_THROW);
     190           0 :                 pSet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) );
     191           0 :                 pTabPage = SwFieldDokInfPage::Create(get_content_area(), pSet);
     192           0 :                 break;
     193             :             }
     194             :         case GRP_DB:
     195           0 :             pTabPage = SwFieldDBPage::Create(get_content_area(), 0);
     196           0 :             static_cast<SwFieldDBPage*>(pTabPage.get())->SetWrtShell(*pSh);
     197           0 :             break;
     198             :         case GRP_VAR:
     199           0 :             pTabPage = SwFieldVarPage::Create(get_content_area(), 0);
     200           0 :             break;
     201             : 
     202             :     }
     203             : 
     204             :     assert(pTabPage);
     205             : 
     206           0 :     if (pTabPage)
     207             :     {
     208           0 :         static_cast<SwFieldPage*>(pTabPage.get())->SetWrtShell(pSh);
     209           0 :         SetTabPage(pTabPage);
     210             :     }
     211             : 
     212           0 :     return pTabPage;
     213             : }
     214             : 
     215           0 : SwFieldEditDlg::~SwFieldEditDlg()
     216             : {
     217           0 :     disposeOnce();
     218           0 : }
     219             : 
     220           0 : void SwFieldEditDlg::dispose()
     221             : {
     222           0 :     SwViewShell::SetCareWin(NULL);
     223           0 :     pSh->EnterStdMode();
     224           0 :     m_pPrevBT.clear();
     225           0 :     m_pNextBT.clear();
     226           0 :     m_pAddressBT.clear();
     227           0 :     SfxSingleTabDialog::dispose();
     228           0 : }
     229             : 
     230           0 : void SwFieldEditDlg::EnableInsert(bool bEnable)
     231             : {
     232           0 :     if( bEnable && pSh->IsReadOnlyAvailable() && pSh->HasReadonlySel() )
     233           0 :         bEnable = false;
     234           0 :     GetOKButton()->Enable( bEnable );
     235           0 : }
     236             : 
     237           0 : void SwFieldEditDlg::InsertHdl()
     238             : {
     239           0 :     GetOKButton()->Click();
     240           0 : }
     241             : 
     242             : // kick off changing of the field
     243           0 : IMPL_LINK_NOARG(SwFieldEditDlg, OKHdl)
     244             : {
     245           0 :     if (GetOKButton()->IsEnabled())
     246             :     {
     247           0 :         VclPtr<SfxTabPage> pTabPage = GetTabPage();
     248           0 :         if (pTabPage)
     249           0 :             pTabPage->FillItemSet(0);
     250           0 :         EndDialog( RET_OK );
     251             :     }
     252             : 
     253           0 :     return 0;
     254             : }
     255             : 
     256           0 : short SwFieldEditDlg::Execute()
     257             : {
     258             :     // without TabPage no dialog
     259           0 :     return GetTabPage() ? Dialog::Execute() : static_cast<short>(RET_CANCEL);
     260             : }
     261             : 
     262             : // Traveling between fields of the same type
     263           0 : IMPL_LINK( SwFieldEditDlg, NextPrevHdl, Button *, pButton )
     264             : {
     265           0 :     bool bNext = pButton == m_pNextBT;
     266             : 
     267           0 :     pSh->EnterStdMode();
     268             : 
     269           0 :     SwFieldType *pOldTyp = 0;
     270           0 :     VclPtr<SwFieldPage> pTabPage = static_cast<SwFieldPage*>(GetTabPage());
     271             : 
     272             :     //#112462# FillItemSet may delete the current field
     273             :     //that's why it has to be called before accessing the current field
     274           0 :     if( GetOKButton()->IsEnabled() )
     275           0 :         pTabPage->FillItemSet(0);
     276             : 
     277           0 :     SwFieldMgr& rMgr = pTabPage->GetFieldMgr();
     278           0 :     SwField *pCurField = rMgr.GetCurField();
     279           0 :     if (pCurField->GetTypeId() == TYP_DBFLD)
     280           0 :         pOldTyp = static_cast<SwDBFieldType*>(pCurField->GetTyp());
     281             : 
     282           0 :     rMgr.GoNextPrev( bNext, pOldTyp );
     283           0 :     pCurField = rMgr.GetCurField();
     284             : 
     285           0 :     EnsureSelection(pCurField, rMgr);
     286             : 
     287           0 :     sal_uInt16 nGroup = SwFieldMgr::GetGroup(false, pCurField->GetTypeId(), pCurField->GetSubType());
     288             : 
     289           0 :     if (nGroup != pTabPage->GetGroup())
     290           0 :         pTabPage = static_cast<SwFieldPage*>(CreatePage(nGroup).get());
     291             : 
     292           0 :     pTabPage->EditNewField();
     293             : 
     294           0 :     Init();
     295             : 
     296           0 :     return 0;
     297             : }
     298             : 
     299           0 : IMPL_LINK_NOARG(SwFieldEditDlg, AddressHdl)
     300             : {
     301           0 :     SwFieldPage* pTabPage = static_cast<SwFieldPage*>(GetTabPage());
     302           0 :     SwFieldMgr& rMgr = pTabPage->GetFieldMgr();
     303           0 :     SwField *pCurField = rMgr.GetCurField();
     304             : 
     305           0 :     SfxItemSet aSet( pSh->GetAttrPool(),
     306             :                         SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS,
     307           0 :                         0L );
     308             : 
     309           0 :     EditPosition nEditPos = EditPosition::UNKNOWN;
     310             : 
     311           0 :     switch(pCurField->GetSubType())
     312             :     {
     313           0 :         case EU_FIRSTNAME:  nEditPos = EditPosition::FIRSTNAME;  break;
     314           0 :         case EU_NAME:       nEditPos = EditPosition::LASTNAME;   break;
     315           0 :         case EU_SHORTCUT:   nEditPos = EditPosition::SHORTNAME;  break;
     316           0 :         case EU_COMPANY:    nEditPos = EditPosition::COMPANY;    break;
     317           0 :         case EU_STREET:     nEditPos = EditPosition::STREET;     break;
     318           0 :         case EU_TITLE:      nEditPos = EditPosition::TITLE;      break;
     319           0 :         case EU_POSITION:   nEditPos = EditPosition::POSITION;   break;
     320           0 :         case EU_PHONE_PRIVATE:nEditPos = EditPosition::TELPRIV;  break;
     321           0 :         case EU_PHONE_COMPANY:nEditPos = EditPosition::TELCOMPANY;   break;
     322           0 :         case EU_FAX:        nEditPos = EditPosition::FAX;        break;
     323           0 :         case EU_EMAIL:      nEditPos = EditPosition::EMAIL;      break;
     324           0 :         case EU_COUNTRY:    nEditPos = EditPosition::COUNTRY;    break;
     325           0 :         case EU_ZIP:        nEditPos = EditPosition::PLZ;        break;
     326           0 :         case EU_CITY:       nEditPos = EditPosition::CITY;       break;
     327           0 :         case EU_STATE:      nEditPos = EditPosition::STATE;      break;
     328             : 
     329           0 :         default:            nEditPos = EditPosition::UNKNOWN;    break;
     330             : 
     331             :     }
     332           0 :     aSet.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS, static_cast<sal_uInt16>(nEditPos)));
     333           0 :     SwAbstractDialogFactory* pFact = swui::GetFactory();
     334             :     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     335             : 
     336             :     boost::scoped_ptr<SfxAbstractDialog> pDlg(pFact->CreateSfxDialog( this, aSet,
     337           0 :         pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(),
     338           0 :         RC_DLG_ADDR ));
     339             :     OSL_ENSURE(pDlg, "Dialog creation failed!");
     340           0 :     if(RET_OK == pDlg->Execute())
     341             :     {
     342           0 :         pSh->UpdateFields( *pCurField );
     343             :     }
     344           0 :     return 0;
     345           0 : }
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11