LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/fldui - fldedt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 166 0.0 %
Date: 2012-12-17 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 <view.hxx>
      28             : #include <dbfld.hxx>
      29             : #include <wrtsh.hxx>
      30             : #include <flddb.hxx>
      31             : #include <flddinf.hxx>
      32             : #include <fldvar.hxx>
      33             : #include <flddok.hxx>
      34             : #include <fldfunc.hxx>
      35             : #include <fldref.hxx>
      36             : #include <fldedt.hxx>
      37             : #include <crsskip.hxx>
      38             : 
      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, 0),
      57           0 :     pSh         (rVw.GetWrtShellPtr()),
      58             :     aPrevBT     (this, SW_RES(BTN_FLDEDT_PREV)),
      59             :     aNextBT     (this, SW_RES(BTN_FLDEDT_NEXT)),
      60           0 :     aAddressBT  (this, SW_RES(PB_FLDEDT_ADDRESS))
      61             : {
      62           0 :     SwFldMgr aMgr(pSh);
      63             : 
      64           0 :     SwField *pCurFld = aMgr.GetCurFld();
      65           0 :     if(!pCurFld)
      66           0 :         return;
      67             : 
      68           0 :     pSh->SetCareWin(this);
      69             : 
      70             :     /* #108536# Only create selection if there is none
      71             :         already. Normalize PaM instead of swapping. */
      72           0 :     if ( ! pSh->HasSelection() )
      73           0 :         pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
      74             : 
      75           0 :     pSh->NormalizePam();
      76             : 
      77           0 :     sal_uInt16 nGroup = aMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType());
      78             : 
      79           0 :     CreatePage(nGroup);
      80             : 
      81           0 :     GetOKButton()->SetClickHdl(LINK(this, SwFldEditDlg, OKHdl));
      82             : 
      83             :     // position buttons ourselves because otherwise when font sizes are
      84             :     // varying, they are in the woods, and because PB uses fixed pixel sizes
      85             :     // for its buttons and dialog width in SingleTabDlg.
      86           0 :     aPrevBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aPrevBT.GetPosPixel().Y()));
      87           0 :     sal_uInt16 nWidth = static_cast< sal_uInt16 >(GetOKButton()->GetOutputSize().Width() / 2 - 3);
      88           0 :     Size aNewSize(LogicToPixel(Size(nWidth, GetOKButton()->GetOutputSize().Height())));
      89           0 :     aPrevBT.SetSizePixel(aNewSize);
      90             : 
      91           0 :     aNextBT.SetSizePixel(aPrevBT.GetSizePixel());
      92             : 
      93           0 :     long nXPos = GetOKButton()->GetPosPixel().X() + GetOKButton()->GetSizePixel().Width()
      94           0 :                     - aNextBT.GetSizePixel().Width() - 1;
      95           0 :     aNextBT.SetPosPixel(Point(nXPos, aNextBT.GetPosPixel().Y()));
      96             : 
      97           0 :     aAddressBT.SetPosPixel(Point(GetOKButton()->GetPosPixel().X(), aAddressBT.GetPosPixel().Y()));
      98           0 :     aAddressBT.SetSizePixel(GetOKButton()->GetSizePixel());
      99             : 
     100           0 :     aPrevBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
     101           0 :     aNextBT.SetClickHdl(LINK(this, SwFldEditDlg, NextPrevHdl));
     102             : 
     103           0 :     aAddressBT.SetClickHdl(LINK(this, SwFldEditDlg, AddressHdl));
     104           0 :     aAddressBT.SetHelpId(HID_FLDEDT_ADDRESS);
     105             : 
     106           0 :     Init();
     107             : }
     108             : 
     109             : /*--------------------------------------------------------------------
     110             :     Description: initialise controls
     111             :  --------------------------------------------------------------------*/
     112           0 : void SwFldEditDlg::Init()
     113             : {
     114           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     115             : 
     116           0 :     if( pTabPage )
     117             :     {
     118           0 :         SwFldMgr& rMgr = pTabPage->GetFldMgr();
     119             : 
     120           0 :         SwField *pCurFld = rMgr.GetCurFld();
     121             : 
     122           0 :         if(!pCurFld)
     123           0 :             return;
     124             : 
     125             :         // Traveling only when more than one field
     126           0 :         pSh->StartAction();
     127           0 :         pSh->CreateCrsr();
     128             : 
     129           0 :         sal_Bool bMove = rMgr.GoNext();
     130           0 :         if( bMove )
     131           0 :             rMgr.GoPrev();
     132           0 :         aNextBT.Enable(bMove);
     133             : 
     134           0 :         if( 0 != ( bMove = rMgr.GoPrev() ) )
     135           0 :             rMgr.GoNext();
     136           0 :         aPrevBT.Enable( bMove );
     137             : 
     138           0 :         if (pCurFld->GetTypeId() == TYP_EXTUSERFLD)
     139           0 :             aAddressBT.Show();
     140             : 
     141           0 :         pSh->DestroyCrsr();
     142           0 :         pSh->EndAction();
     143             :     }
     144             : 
     145           0 :     GetOKButton()->Enable( !pSh->IsReadOnlyAvailable() ||
     146           0 :                            !pSh->HasReadonlySel() );
     147             : }
     148             : 
     149           0 : SfxTabPage* SwFldEditDlg::CreatePage(sal_uInt16 nGroup)
     150             : {
     151             :     // create TabPage
     152           0 :     SfxTabPage* pTabPage = 0;
     153           0 :     const char* pHelpId = 0;
     154             : 
     155           0 :     switch (nGroup)
     156             :     {
     157             :         case GRP_DOC:
     158           0 :             pTabPage = SwFldDokPage::Create(this, *(SfxItemSet*)0);
     159           0 :             pHelpId = HID_EDIT_FLD_DOK;
     160           0 :             break;
     161             :         case GRP_FKT:
     162           0 :             pTabPage = SwFldFuncPage::Create(this, *(SfxItemSet*)0);
     163           0 :             pHelpId = HID_EDIT_FLD_FUNC;
     164           0 :             break;
     165             :         case GRP_REF:
     166           0 :             pTabPage = SwFldRefPage::Create(this, *(SfxItemSet*)0);
     167           0 :             pHelpId = HID_EDIT_FLD_REF;
     168           0 :             break;
     169             :         case GRP_REG:
     170             :             {
     171           0 :                 SfxObjectShell* pDocSh = SfxObjectShell::Current();
     172           0 :                 SfxItemSet* pSet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
     173             :                 using namespace ::com::sun::star;
     174             :                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     175           0 :                     pDocSh->GetModel(), uno::UNO_QUERY_THROW);
     176             :                 uno::Reference<document::XDocumentProperties> xDocProps
     177           0 :                     = xDPS->getDocumentProperties();
     178             :                 uno::Reference< beans::XPropertySet > xUDProps(
     179           0 :                     xDocProps->getUserDefinedProperties(),
     180           0 :                     uno::UNO_QUERY_THROW);
     181           0 :                 pSet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) );
     182           0 :                 pTabPage = SwFldDokInfPage::Create(this, *pSet);
     183           0 :                 pHelpId = HID_EDIT_FLD_DOKINF;
     184           0 :                 break;
     185             :             }
     186             :         case GRP_DB:
     187           0 :             pTabPage = SwFldDBPage::Create(this, *(SfxItemSet*)0);
     188           0 :             static_cast<SwFldDBPage*>(pTabPage)->SetWrtShell(*pSh);
     189           0 :             pHelpId = HID_EDIT_FLD_DB;
     190           0 :             break;
     191             :         case GRP_VAR:
     192           0 :             pTabPage = SwFldVarPage::Create(this, *(SfxItemSet*)0);
     193           0 :             pHelpId = HID_EDIT_FLD_VAR;
     194           0 :             break;
     195             : 
     196             :     }
     197             : 
     198           0 :     pTabPage->SetHelpId(pHelpId);
     199           0 :     static_cast<SwFldPage*>(pTabPage)->SetWrtShell(pSh);
     200             : 
     201           0 :     SetTabPage(pTabPage);
     202             : 
     203           0 :     String sTitle(GetText());
     204           0 :     sTitle.Insert(rtl::OUString(": "), 0);
     205           0 :     sTitle.Insert(SW_RESSTR(STR_FLD_EDIT_DLG), 0);
     206           0 :     SetText(sTitle);
     207             : 
     208           0 :     return pTabPage;
     209             : }
     210             : 
     211           0 : SwFldEditDlg::~SwFldEditDlg()
     212             : {
     213           0 :     pSh->SetCareWin(NULL);
     214           0 :     pSh->EnterStdMode();
     215           0 : }
     216             : 
     217           0 : void SwFldEditDlg::EnableInsert(sal_Bool bEnable)
     218             : {
     219           0 :     if( bEnable && pSh->IsReadOnlyAvailable() && pSh->HasReadonlySel() )
     220           0 :         bEnable = sal_False;
     221           0 :     GetOKButton()->Enable( bEnable );
     222           0 : }
     223             : 
     224           0 : void SwFldEditDlg::InsertHdl()
     225             : {
     226           0 :     GetOKButton()->Click();
     227           0 : }
     228             : 
     229             : /*--------------------------------------------------------------------
     230             :      Description: kick off changing of the field
     231             :  --------------------------------------------------------------------*/
     232           0 : IMPL_LINK_NOARG(SwFldEditDlg, OKHdl)
     233             : {
     234           0 :     if (GetOKButton()->IsEnabled())
     235             :     {
     236           0 :         SfxTabPage* pTabPage = GetTabPage();
     237           0 :         if (pTabPage)
     238             :         {
     239           0 :             pTabPage->FillItemSet(*(SfxItemSet*)0);
     240             : 
     241             :         }
     242           0 :         EndDialog( RET_OK );
     243             :     }
     244             : 
     245           0 :     return 0;
     246             : }
     247             : 
     248           0 : short SwFldEditDlg::Execute()
     249             : {
     250             :     // without TabPage no dialog
     251           0 :     return GetTabPage() ? Dialog::Execute() : RET_CANCEL;
     252             : }
     253             : 
     254             : /*--------------------------------------------------------------------
     255             :     Description: Traveling between fields of the same type
     256             :  --------------------------------------------------------------------*/
     257           0 : IMPL_LINK( SwFldEditDlg, NextPrevHdl, Button *, pButton )
     258             : {
     259           0 :     sal_Bool bNext = pButton == &aNextBT;
     260             : 
     261           0 :     pSh->EnterStdMode();
     262             : 
     263           0 :     SwFieldType *pOldTyp = 0;
     264           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     265             : 
     266             :     //#112462# FillItemSet may delete the current field
     267             :     //that's why it has to be called before accessing the current field
     268           0 :     if( GetOKButton()->IsEnabled() )
     269           0 :         pTabPage->FillItemSet(*(SfxItemSet*)0);
     270             : 
     271           0 :     SwFldMgr& rMgr = pTabPage->GetFldMgr();
     272           0 :     SwField *pCurFld = rMgr.GetCurFld();
     273           0 :     if (pCurFld->GetTypeId() == TYP_DBFLD)
     274           0 :         pOldTyp = (SwDBFieldType*)pCurFld->GetTyp();
     275             : 
     276           0 :     rMgr.GoNextPrev( bNext, pOldTyp );
     277           0 :     pCurFld = rMgr.GetCurFld();
     278             : 
     279             :     /* #108536# Only create selection if there is none
     280             :         already. Normalize PaM instead of swapping. */
     281           0 :     if ( ! pSh->HasSelection() )
     282           0 :         pSh->Right(CRSR_SKIP_CHARS, sal_True, 1, sal_False );
     283             : 
     284           0 :     pSh->NormalizePam();
     285             : 
     286           0 :     sal_uInt16 nGroup = rMgr.GetGroup(sal_False, pCurFld->GetTypeId(), pCurFld->GetSubType());
     287             : 
     288           0 :     if (nGroup != pTabPage->GetGroup())
     289           0 :         pTabPage = (SwFldPage*)CreatePage(nGroup);
     290             : 
     291           0 :     pTabPage->EditNewField();
     292             : 
     293           0 :     Init();
     294             : 
     295           0 :     return 0;
     296             : }
     297             : 
     298           0 : IMPL_LINK_NOARG(SwFldEditDlg, AddressHdl)
     299             : {
     300           0 :     SwFldPage* pTabPage = (SwFldPage*)GetTabPage();
     301           0 :     SwFldMgr& rMgr = pTabPage->GetFldMgr();
     302           0 :     SwField *pCurFld = rMgr.GetCurFld();
     303             : 
     304           0 :     SfxItemSet aSet( pSh->GetAttrPool(),
     305             :                         SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS,
     306           0 :                         0L );
     307             : 
     308           0 :     sal_uInt16 nEditPos = UNKNOWN_EDIT;
     309             : 
     310           0 :     switch(pCurFld->GetSubType())
     311             :     {
     312           0 :         case EU_FIRSTNAME:  nEditPos = FIRSTNAME_EDIT;  break;
     313           0 :         case EU_NAME:       nEditPos = LASTNAME_EDIT;   break;
     314           0 :         case EU_SHORTCUT:   nEditPos = SHORTNAME_EDIT;  break;
     315           0 :         case EU_COMPANY:    nEditPos = COMPANY_EDIT;    break;
     316           0 :         case EU_STREET:     nEditPos = STREET_EDIT;     break;
     317           0 :         case EU_TITLE:      nEditPos = TITLE_EDIT;      break;
     318           0 :         case EU_POSITION:   nEditPos = POSITION_EDIT;   break;
     319           0 :         case EU_PHONE_PRIVATE:nEditPos = TELPRIV_EDIT;  break;
     320           0 :         case EU_PHONE_COMPANY:nEditPos = TELCOMPANY_EDIT;   break;
     321           0 :         case EU_FAX:        nEditPos = FAX_EDIT;        break;
     322           0 :         case EU_EMAIL:      nEditPos = EMAIL_EDIT;      break;
     323           0 :         case EU_COUNTRY:    nEditPos = COUNTRY_EDIT;    break;
     324           0 :         case EU_ZIP:        nEditPos = PLZ_EDIT;        break;
     325           0 :         case EU_CITY:       nEditPos = CITY_EDIT;       break;
     326           0 :         case EU_STATE:      nEditPos = STATE_EDIT;      break;
     327             : 
     328           0 :         default:            nEditPos = UNKNOWN_EDIT;    break;
     329             : 
     330             :     }
     331           0 :     aSet.Put(SfxUInt16Item(SID_FIELD_GRABFOCUS, nEditPos));
     332           0 :     SwAbstractDialogFactory* pFact = swui::GetFactory();
     333             :     OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
     334             : 
     335             :     SfxAbstractDialog* pDlg = pFact->CreateSfxDialog( this, aSet,
     336           0 :         pSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface(),
     337           0 :         RC_DLG_ADDR );
     338             :     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     339           0 :     if(RET_OK == pDlg->Execute())
     340             :     {
     341           0 :         pSh->UpdateFlds( *pCurFld );
     342             :     }
     343           0 :     delete pDlg;
     344           0 :     return 0;
     345           0 : }
     346             : 
     347             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10