LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/app - applab.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 169 0.6 %
Date: 2012-12-17 Functions: 2 5 40.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             : 
      21             : #include <cstdarg>
      22             : 
      23             : #include <hintids.hxx>
      24             : 
      25             : #include <vcl/svapp.hxx>
      26             : #include <vcl/wrkwin.hxx>
      27             : #include <vcl/msgbox.hxx>
      28             : #include <sfx2/app.hxx>
      29             : #include <sfx2/dispatch.hxx>
      30             : #include <sfx2/printer.hxx>
      31             : #include <sfx2/request.hxx>
      32             : #include <sfx2/linkmgr.hxx>
      33             : #include <editeng/pbinitem.hxx>
      34             : #include <editeng/ulspitem.hxx>
      35             : #include <editeng/lrspitem.hxx>
      36             : #include <editeng/boxitem.hxx>
      37             : #include <editeng/paperinf.hxx>
      38             : #include <editeng/protitem.hxx>
      39             : #include <com/sun/star/frame/XStorable.hpp>
      40             : #include <com/sun/star/frame/XModel.hpp>
      41             : #include <fmthdft.hxx>
      42             : #include <fmtanchr.hxx>
      43             : #include <fmtfsize.hxx>
      44             : #include <fmtornt.hxx>
      45             : #include <swwait.hxx>
      46             : #include <gloshdl.hxx>
      47             : #include <mdiexp.hxx>
      48             : #include <frmatr.hxx>
      49             : #include <paratr.hxx>
      50             : #include <swmodule.hxx>
      51             : #include <view.hxx>
      52             : #include <docsh.hxx>
      53             : #include <fldbas.hxx>
      54             : #include <swundo.hxx>
      55             : #include <wrtsh.hxx>
      56             : #include <cmdid.h>
      57             : #include <dbmgr.hxx>
      58             : #include <fmtcol.hxx>
      59             : #include <expfld.hxx>
      60             : #include <fldmgr.hxx>
      61             : #include <label.hxx>
      62             : #include <labimg.hxx>
      63             : #include <section.hxx>
      64             : #include <pagedesc.hxx>
      65             : #include <poolfmt.hxx>
      66             : 
      67             : #include <app.hrc>
      68             : #include <poolfmt.hrc>
      69             : #include "swabstdlg.hxx"
      70             : #include "envelp.hrc"
      71             : #include <misc.hrc>
      72             : 
      73             : #include <IDocumentDeviceAccess.hxx>
      74             : 
      75             : using namespace ::com::sun::star;
      76             : using ::rtl::OUString;
      77             : 
      78             : // is in appenv.cxx
      79             : extern String InsertLabEnvText( SwWrtShell& , SwFldMgr& , const String& );
      80             : 
      81             : const char MASTER_LABEL[] = "MasterLabel";
      82             : 
      83           0 : static const SwFrmFmt *lcl_InsertBCText( SwWrtShell& rSh, const SwLabItem& rItem,
      84             :                         SwFrmFmt &rFmt,
      85             :                         sal_uInt16 nCol, sal_uInt16 nRow )
      86             : {
      87           0 :     SfxItemSet aSet(rSh.GetAttrPool(), RES_ANCHOR, RES_ANCHOR,
      88           0 :                         RES_VERT_ORIENT, RES_VERT_ORIENT, RES_HORI_ORIENT, RES_HORI_ORIENT, 0 );
      89             :     sal_uInt16 nPhyPageNum, nVirtPageNum;
      90           0 :     rSh.GetPageNum( nPhyPageNum, nVirtPageNum );
      91             : 
      92             :     //anchor frame to page
      93           0 :     aSet.Put( SwFmtAnchor( FLY_AT_PAGE, nPhyPageNum ) );
      94             :     aSet.Put( SwFmtHoriOrient( rItem.lLeft + nCol * rItem.lHDist,
      95           0 :                                text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ) );
      96             :     aSet.Put( SwFmtVertOrient( rItem.lUpper + nRow * rItem.lVDist,
      97           0 :                                text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ) );
      98           0 :     const SwFrmFmt *pFmt = rSh.NewFlyFrm(aSet, sal_True,  &rFmt );  // Insert Fly
      99             :     OSL_ENSURE( pFmt, "Fly not inserted" );
     100             : 
     101           0 :     rSh.UnSelectFrm();  //Frame was selected automatically
     102             : 
     103           0 :     rSh.SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) );
     104             : 
     105           0 :     if(!rItem.bSynchron || !(nCol|nRow))
     106             :     {
     107           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     108             :         OSL_ENSURE(pFact, "Dialogdiet fail!");
     109           0 :         ::GlossarySetActGroup fnSetActGroup = pFact->SetGlossaryActGroupFunc( DLG_RENAME_GLOS );
     110           0 :         if ( fnSetActGroup )
     111           0 :             (*fnSetActGroup)( rItem.sGlossaryGroup );
     112           0 :         SwGlossaryHdl* pGlosHdl = rSh.GetView().GetGlosHdl();
     113           0 :         pGlosHdl->SetCurGroup(rItem.sGlossaryGroup, sal_True);
     114           0 :         pGlosHdl->InsertGlossary( rItem.sGlossaryBlockName );
     115             :     }
     116             : 
     117           0 :     return pFmt;
     118             : }
     119             : 
     120           0 : static const SwFrmFmt *lcl_InsertLabText( SwWrtShell& rSh, const SwLabItem& rItem,
     121             :                         SwFrmFmt &rFmt, SwFldMgr& rFldMgr,
     122             :                         sal_uInt16 nCol, sal_uInt16 nRow, sal_Bool bLast )
     123             : {
     124           0 :     SfxItemSet aSet(rSh.GetAttrPool(), RES_ANCHOR, RES_ANCHOR,
     125           0 :                         RES_VERT_ORIENT, RES_VERT_ORIENT, RES_HORI_ORIENT, RES_HORI_ORIENT, 0 );
     126             :     sal_uInt16 nPhyPageNum, nVirtPageNum;
     127           0 :     rSh.GetPageNum( nPhyPageNum, nVirtPageNum );
     128             : 
     129             :     //anchor frame to page
     130           0 :     aSet.Put( SwFmtAnchor( FLY_AT_PAGE, nPhyPageNum ) );
     131             :     aSet.Put( SwFmtHoriOrient( rItem.lLeft + nCol * rItem.lHDist,
     132           0 :                                text::HoriOrientation::NONE, text::RelOrientation::PAGE_FRAME ) );
     133             :     aSet.Put( SwFmtVertOrient( rItem.lUpper + nRow * rItem.lVDist,
     134           0 :                                text::VertOrientation::NONE, text::RelOrientation::PAGE_FRAME ) );
     135           0 :     const SwFrmFmt *pFmt = rSh.NewFlyFrm(aSet, sal_True,  &rFmt );  // Insert Fly
     136             :     OSL_ENSURE( pFmt, "Fly not inserted" );
     137             : 
     138           0 :     rSh.UnSelectFrm();  //Frame was selected automatically
     139             : 
     140           0 :     rSh.SetTxtFmtColl( rSh.GetTxtCollFromPool( RES_POOLCOLL_STANDARD ) );
     141             : 
     142             :     // If applicable "next dataset"
     143           0 :     String sDBName;
     144           0 :     if( (!rItem.bSynchron || !(nCol|nRow)) && (sDBName = InsertLabEnvText( rSh, rFldMgr, rItem.aWriting )).Len() && !bLast )
     145             :     {
     146           0 :         sDBName.SetToken( 3, DB_DELIM, rtl::OUString("True"));
     147           0 :         SwInsertFld_Data aData(TYP_DBNEXTSETFLD, 0, sDBName, aEmptyStr, 0, &rSh );
     148           0 :         rFldMgr.InsertFld( aData );
     149             :     }
     150             : 
     151           0 :     return pFmt;
     152             : }
     153             : 
     154           0 : void SwModule::InsertLab(SfxRequest& rReq, sal_Bool bLabel)
     155             : {
     156             :     static sal_uInt16 nLabelTitleNo = 0;
     157             :     static sal_uInt16 nBCTitleNo = 0;
     158             : 
     159             :     // Create DB-Manager
     160           0 :     SwNewDBMgr* pNewDBMgr = new SwNewDBMgr;
     161             : 
     162             :     // Read SwLabItem from Config
     163           0 :     SwLabCfgItem aLabCfg(bLabel);
     164             : 
     165             :     // Move up Dialog
     166           0 :     SfxItemSet aSet( GetPool(), FN_LABEL, FN_LABEL, 0 );
     167           0 :     aSet.Put( aLabCfg.GetItem() );
     168             : 
     169           0 :     SwAbstractDialogFactory* pDialogFactory = SwAbstractDialogFactory::Create();
     170             :     OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!");
     171             : 
     172           0 :     AbstractSwLabDlg* pDlg = pDialogFactory->CreateSwLabDlg( 0, aSet, pNewDBMgr, bLabel, DLG_LAB );
     173             :     OSL_ENSURE(pDlg, "Dialogdiet fail!");
     174             : 
     175           0 :     if ( RET_OK == pDlg->Execute() )
     176             :     {
     177             :         // Read dialog, store item in config
     178             :         const SwLabItem& rItem = (const SwLabItem&) pDlg->
     179           0 :                                             GetOutputItemSet()->Get(FN_LABEL);
     180           0 :         aLabCfg.GetItem() = rItem;
     181           0 :         aLabCfg.Commit();
     182             : 
     183             :         // Create new document
     184           0 :         SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD));
     185           0 :         xDocSh->DoInitNew( 0 );
     186             : 
     187             :         // Printer
     188           0 :         Printer *pPrt = pDlg->GetPrt();
     189           0 :         if (pPrt)
     190             :         {
     191           0 :             SwDocShell *pDocSh = (SwDocShell*)(&*xDocSh);
     192           0 :             pDocSh->getIDocumentDeviceAccess()->setJobsetup(pPrt->GetJobSetup());
     193             :         }
     194             : 
     195           0 :         SfxViewFrame* pViewFrame = SfxViewFrame::DisplayNewDocument( *xDocSh, rReq );
     196             : 
     197           0 :         SwView      *pNewView = (SwView*) pViewFrame->GetViewShell();
     198           0 :         pNewView->AttrChangedNotify( &pNewView->GetWrtShell() );// So that SelectShell is being called.
     199             : 
     200             :         // Set document title
     201           0 :         String aTmp;
     202           0 :         if(bLabel)
     203             :         {
     204           0 :             aTmp = String(SW_RES( STR_LAB_TITLE));
     205           0 :             aTmp += String::CreateFromInt32(++nLabelTitleNo );
     206             :         }
     207             :         else
     208             :         {
     209           0 :             aTmp = pDlg->GetBusinessCardStr();
     210           0 :             aTmp += String::CreateFromInt32( ++nBCTitleNo );
     211             :         }
     212           0 :         xDocSh->SetTitle( aTmp );
     213             : 
     214           0 :         pViewFrame->GetFrame().Appear();
     215             : 
     216             :         // Determine Shell
     217           0 :         SwWrtShell *pSh = pNewView->GetWrtShellPtr();
     218             :         OSL_ENSURE( pSh, "missing WrtShell" );
     219             : 
     220             :         {   // block for locks the dispatcher!!
     221             : 
     222           0 :             SwWait aWait( (SwDocShell&)*xDocSh, sal_True );
     223             : 
     224           0 :             SET_CURR_SHELL(pSh);
     225           0 :             pSh->SetLabelDoc(rItem.bSynchron);
     226           0 :             pSh->DoUndo( sal_False );
     227           0 :             pSh->StartAllAction();
     228             : 
     229           0 :             pSh->SetNewDoc();       // Avoid performance problems
     230             : 
     231           0 :             SwPageDesc aDesc = pSh->GetPageDesc( 0 );
     232           0 :             SwFrmFmt&  rFmt  = aDesc.GetMaster();
     233             : 
     234             :             // Borders
     235           0 :             SvxLRSpaceItem aLRMargin( RES_LR_SPACE );
     236           0 :             SvxULSpaceItem aULMargin( RES_UL_SPACE );
     237           0 :             aLRMargin.SetLeft ((sal_uInt16) rItem.lLeft );
     238           0 :             aULMargin.SetUpper((sal_uInt16) rItem.lUpper);
     239           0 :             aLRMargin.SetRight( 0 );
     240           0 :             aULMargin.SetLower( 0 );
     241           0 :             rFmt.SetFmtAttr(aLRMargin);
     242           0 :             rFmt.SetFmtAttr(aULMargin);
     243             : 
     244             :             // Header and footer
     245           0 :             rFmt.SetFmtAttr(SwFmtHeader(sal_Bool(sal_False)));
     246           0 :             aDesc.ChgHeaderShare(sal_False);
     247           0 :             rFmt.SetFmtAttr(SwFmtFooter(sal_Bool(sal_False)));
     248           0 :             aDesc.ChgFooterShare(sal_False);
     249             : 
     250             : 
     251           0 :             aDesc.SetUseOn(nsUseOnPage::PD_ALL);                // Site numbering
     252             : 
     253             :             // Set page size
     254             :             long lPgWidth, lPgHeight;
     255           0 :             lPgWidth  = (rItem.lPWidth > MINLAY ? rItem.lPWidth : MINLAY);
     256           0 :             lPgHeight = (rItem.lPHeight > MINLAY ? rItem.lPHeight : MINLAY);
     257           0 :             rFmt.SetFmtAttr( SwFmtFrmSize( ATT_FIX_SIZE, lPgWidth, lPgHeight ));
     258             :             // Numbering type
     259           0 :             SvxNumberType aType;
     260           0 :             aType.SetNumberingType(SVX_NUM_NUMBER_NONE);
     261           0 :             aDesc.SetNumType( aType );
     262             : 
     263             :             // Followup template
     264           0 :             const SwPageDesc &rFollow = pSh->GetPageDesc( pSh->GetCurPageDesc() );
     265           0 :             aDesc.SetFollow( &rFollow );
     266             : 
     267           0 :             pPrt = pSh->getIDocumentDeviceAccess()->getPrinter( true );
     268           0 :             SvxPaperBinItem aItem( RES_PAPER_BIN );
     269           0 :             aItem.SetValue((sal_Int8)pPrt->GetPaperBin());
     270           0 :             rFmt.SetFmtAttr(aItem);
     271             : 
     272             :             // Determine orientation of the resulting page
     273           0 :             aDesc.SetLandscape(rItem.lPWidth > rItem.lPHeight);
     274             : 
     275           0 :             pSh->ChgPageDesc( 0, aDesc );
     276             : 
     277             :             // Insert frame
     278           0 :             SwFldMgr*        pFldMgr = new SwFldMgr;
     279           0 :             pFldMgr->SetEvalExpFlds(sal_False);
     280             : 
     281             :             // Prepare border template
     282           0 :             SwFrmFmt* pFmt = pSh->GetFrmFmtFromPool( RES_POOLFRM_LABEL );
     283           0 :             sal_Int32 iResultWidth = rItem.lLeft + (rItem.nCols - 1) * rItem.lHDist + rItem.lWidth - rItem.lPWidth;
     284           0 :             sal_Int32 iResultHeight = rItem.lUpper + (rItem.nRows - 1) * rItem.lVDist + rItem.lHeight - rItem.lPHeight;
     285           0 :             sal_Int32 iWidth = (iResultWidth > 0 ? rItem.lWidth - (iResultWidth / rItem.nCols) - 1 : rItem.lWidth);
     286           0 :             sal_Int32 iHeight = (iResultHeight > 0 ? rItem.lHeight - (iResultHeight / rItem.nRows) - 1 : rItem.lHeight);
     287           0 :             SwFmtFrmSize aFrmSize(  ATT_FIX_SIZE, iWidth, iHeight );
     288           0 :             pFmt->SetFmtAttr( aFrmSize );
     289             : 
     290             :             //frame represents label itself, no border space
     291           0 :             SvxULSpaceItem aFrmNoULSpace( 0, 0, RES_UL_SPACE );
     292           0 :             SvxLRSpaceItem aFrmNoLRSpace( 0, 0, 0, 0, RES_LR_SPACE );
     293           0 :             pFmt->SetFmtAttr( aFrmNoULSpace );
     294           0 :             pFmt->SetFmtAttr( aFrmNoLRSpace );
     295             : 
     296           0 :             const SwFrmFmt *pFirstFlyFmt = 0;
     297           0 :             if ( rItem.bPage )
     298             :             {
     299           0 :                 SwFmtVertOrient aFrmVertOrient( pFmt->GetVertOrient() );
     300           0 :                 aFrmVertOrient.SetVertOrient( text::VertOrientation::TOP );
     301           0 :                 pFmt->SetFmtAttr(aFrmVertOrient);
     302             : 
     303           0 :                 for ( sal_uInt16 i = 0; i < rItem.nRows; ++i )
     304             :                 {
     305           0 :                     for ( sal_uInt16 j = 0; j < rItem.nCols; ++j )
     306             :                     {
     307           0 :                         pSh->Push();
     308             :                         const SwFrmFmt *pTmp = ( bLabel ?
     309             :                                                  lcl_InsertLabText( *pSh, rItem, *pFmt, *pFldMgr, j, i,
     310           0 :                                                    i == rItem.nRows - 1 && j == rItem.nCols - 1 ) :
     311           0 :                                                  lcl_InsertBCText( *pSh, rItem, *pFmt, j, i ) );
     312           0 :                         if (!(i|j))
     313             :                         {
     314           0 :                             pFirstFlyFmt = pTmp;
     315             : 
     316           0 :                             if (rItem.bSynchron)
     317             :                             {
     318             :                                 // if there is no content in the fly then
     319             :                                 // dont leave the fly!!!
     320           0 :                                 pSh->Push();
     321           0 :                                 pSh->SttDoc();
     322           0 :                                 sal_Bool bInFly = 0 != pSh->WizzardGetFly();
     323           0 :                                 pSh->Pop( bInFly );
     324             : 
     325           0 :                                 if( bInFly )
     326           0 :                                     pSh->EndDoc(sal_True);  // select all content
     327             :                                                         // in the fly
     328             :                                 else
     329           0 :                                     pSh->SetMark();     // set only the mark
     330             : 
     331             :                                 SwSectionData aSect(CONTENT_SECTION,
     332           0 :                                     rtl::OUString(MASTER_LABEL));
     333           0 :                                 pSh->InsertSection(aSect);
     334             :                             }
     335             :                         }
     336           0 :                         else if (rItem.bSynchron)
     337             :                         {
     338             :                             SwSectionData aSect(FILE_LINK_SECTION,
     339           0 :                                     pSh->GetUniqueSectionName());
     340           0 :                             rtl::OUStringBuffer sLinkName;
     341           0 :                             sLinkName.append(sfx2::cTokenSeperator);
     342           0 :                             sLinkName.append(sfx2::cTokenSeperator);
     343           0 :                             sLinkName.append(MASTER_LABEL);
     344           0 :                             aSect.SetLinkFileName(sLinkName.makeStringAndClear());
     345           0 :                             aSect.SetProtectFlag(true);
     346           0 :                             pSh->Insert(aDotStr);   // Dummytext to allocate the Section
     347           0 :                             pSh->SttDoc();
     348           0 :                             pSh->EndDoc(sal_True);  // Select everything in the frame
     349           0 :                             pSh->InsertSection(aSect);
     350             :                         }
     351           0 :                         pSh->Pop( sal_False );
     352             :                     }
     353           0 :                 }
     354             :             }
     355             :             else
     356             :             {
     357             :                 pFirstFlyFmt = bLabel ?
     358             :                     lcl_InsertLabText( *pSh, rItem, *pFmt, *pFldMgr,
     359             :                             static_cast< sal_uInt16 >(rItem.nCol - 1),
     360           0 :                             static_cast< sal_uInt16 >(rItem.nRow - 1), sal_True ) :
     361             :                     lcl_InsertBCText(*pSh, rItem, *pFmt,
     362             :                             static_cast< sal_uInt16 >(rItem.nCol - 1),
     363           0 :                             static_cast< sal_uInt16 >(rItem.nRow - 1));
     364             :             }
     365             : 
     366             :             //fill the user fields
     367           0 :             if(!bLabel)
     368             :             {
     369           0 :                 uno::Reference< frame::XModel >  xModel = pSh->GetView().GetDocShell()->GetBaseModel();
     370             :                 OSL_ENSURE(pDialogFactory, "SwAbstractDialogFactory fail!");
     371           0 :                 SwLabDlgMethod SwLabDlgUpdateFieldInformation = pDialogFactory->GetSwLabDlgStaticMethod ();
     372           0 :                 SwLabDlgUpdateFieldInformation(xModel, rItem);
     373             :             }
     374             : 
     375           0 :             pFldMgr->SetEvalExpFlds(sal_True);
     376           0 :             pFldMgr->EvalExpFlds(pSh);
     377             : 
     378           0 :             delete pFldMgr;
     379             : 
     380           0 :             pSh->GotoFly(pFirstFlyFmt->GetName(), FLYCNTTYPE_ALL, sal_False);
     381             : 
     382           0 :             pSh->EndAllAction();
     383           0 :             pSh->DoUndo( sal_True );
     384             :         }
     385             : 
     386           0 :         if( rItem.aWriting.indexOf( '<' ) >= 0 )
     387             :         {
     388             :             // Open database browser on recently used database
     389           0 :             ShowDBObj( *pNewView, pSh->GetDBData() );
     390             :         }
     391             : 
     392           0 :         if( rItem.bSynchron )
     393             :         {
     394           0 :             SfxDispatcher* pDisp = pViewFrame->GetDispatcher();
     395             :             OSL_ENSURE(pDisp, "No dispatcher in frame?");
     396           0 :             pDisp->Execute(FN_SYNC_LABELS, SFX_CALLMODE_ASYNCHRON);
     397             :         }
     398           0 :         rReq.SetReturnValue(SfxVoidItem(bLabel ? FN_LABEL : FN_BUSINESS_CARD));
     399             :     }
     400           0 :     delete pDlg;
     401           0 :     delete pNewDBMgr;
     402          72 : }
     403             : 
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10