LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/dialog - regionsw.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 107 0.9 %
Date: 2012-12-27 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             : #include <hintids.hxx>
      21             : #include <uitool.hxx>
      22             : #include <svl/urihelper.hxx>
      23             : #include <svl/PasswordHelper.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : #include <svl/stritem.hxx>
      26             : #include <svl/eitem.hxx>
      27             : #include <sot/formats.hxx>
      28             : #include <sfx2/passwd.hxx>
      29             : #include <sfx2/docfilt.hxx>
      30             : #include <sfx2/request.hxx>
      31             : #include <sfx2/docfile.hxx>
      32             : #include <sfx2/linkmgr.hxx>
      33             : #include <editeng/sizeitem.hxx>
      34             : #include <svtools/htmlcfg.hxx>
      35             : #include <section.hxx>
      36             : #include <docary.hxx>
      37             : #include <regionsw.hxx>
      38             : #include <basesh.hxx>
      39             : #include <wdocsh.hxx>
      40             : #include <view.hxx>
      41             : #include <swmodule.hxx>
      42             : #include <wrtsh.hxx>
      43             : #include <swundo.hxx>                   // for Undo-Ids
      44             : #include <column.hxx>
      45             : #include <fmtfsize.hxx>
      46             : #include <shellio.hxx>
      47             : #include <helpid.h>
      48             : #include <cmdid.h>
      49             : #include <regionsw.hrc>
      50             : #include <comcore.hrc>
      51             : #include <globals.hrc>
      52             : #include <sfx2/bindings.hxx>
      53             : #include <svx/htmlmode.hxx>
      54             : #include <svx/dlgutil.hxx>
      55             : #include "swabstdlg.hxx"
      56             : #include <boost/scoped_ptr.hpp>
      57             : 
      58           0 : void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
      59             : {
      60           0 :     SwWrtShell& rSh = GetShell();
      61           0 :     const SfxItemSet *pSet = rReq.GetArgs();
      62             : 
      63           0 :     SfxItemSet aSet(GetPool(),
      64             :             RES_COL, RES_COL,
      65             :             RES_LR_SPACE, RES_LR_SPACE,
      66             :             RES_COLUMNBALANCE, RES_FRAMEDIR,
      67             :             RES_BACKGROUND, RES_BACKGROUND,
      68             :             RES_FRM_SIZE, RES_FRM_SIZE,
      69             :             RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
      70             :             SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
      71           0 :             0);
      72             : 
      73           0 :     if (!pSet || pSet->Count()==0)
      74             :     {
      75           0 :         SwRect aRect;
      76           0 :         rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
      77             : 
      78           0 :         long nWidth = aRect.Width();
      79           0 :         aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
      80             : 
      81             :         // height=width for more consistent preview (analog to edit region)
      82           0 :         aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
      83           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
      84             :         OSL_ENSURE(pFact, "Dialogdiet fail!");
      85             :         AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
      86           0 :                                                         &GetView().GetViewFrame()->GetWindow(), aSet , rSh);
      87             :         OSL_ENSURE(aTabDlg, "Dialogdiet fail!");
      88           0 :         aTabDlg->Execute();
      89           0 :         rReq.Ignore();
      90           0 :         delete aTabDlg;
      91             :     }
      92             :     else
      93             :     {
      94           0 :         const SfxPoolItem *pItem = 0;
      95           0 :         String aTmpStr;
      96           0 :         if ( SFX_ITEM_SET ==
      97           0 :                 pSet->GetItemState(FN_PARAM_REGION_NAME, sal_True, &pItem) )
      98             :             aTmpStr = rSh.GetUniqueSectionName(
      99           0 :                     &((const SfxStringItem *)pItem)->GetValue() );
     100             :         else
     101           0 :             aTmpStr = rSh.GetUniqueSectionName();
     102             : 
     103           0 :         SwSectionData aSection(CONTENT_SECTION, aTmpStr);
     104           0 :         rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr));
     105             : 
     106           0 :         aSet.Put( *pSet );
     107           0 :         if(SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem)||
     108           0 :             SFX_ITEM_SET == pSet->GetItemState(FN_INSERT_REGION, sal_False, &pItem))
     109             :         {
     110           0 :             SwFmtCol aCol;
     111           0 :             SwRect aRect;
     112           0 :             rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
     113           0 :             long nWidth = aRect.Width();
     114             : 
     115           0 :             sal_uInt16 nCol = ((SfxUInt16Item *)pItem)->GetValue();
     116           0 :             if(nCol)
     117             :             {
     118           0 :                 aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
     119           0 :                 aSet.Put(aCol);
     120           0 :             }
     121             :         }
     122           0 :         else if(SFX_ITEM_SET == pSet->GetItemState(RES_COL, sal_False, &pItem))
     123             :         {
     124           0 :             aSet.Put(*pItem);
     125             :         }
     126             : 
     127             :         const sal_Bool bHidden = SFX_ITEM_SET ==
     128           0 :             pSet->GetItemState(FN_PARAM_REGION_HIDDEN, sal_True, &pItem)?
     129           0 :             (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
     130             :         const sal_Bool bProtect = SFX_ITEM_SET ==
     131           0 :             pSet->GetItemState(FN_PARAM_REGION_PROTECT, sal_True, &pItem)?
     132           0 :             (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
     133             :         // #114856# edit in readonly sections
     134             :         const sal_Bool bEditInReadonly = SFX_ITEM_SET ==
     135           0 :             pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, sal_True, &pItem)?
     136           0 :             (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
     137             : 
     138           0 :         aSection.SetProtectFlag(bProtect);
     139           0 :         aSection.SetHidden(bHidden);
     140             :         // #114856# edit in readonly sections
     141           0 :         aSection.SetEditInReadonlyFlag(bEditInReadonly);
     142             : 
     143           0 :         if(SFX_ITEM_SET ==
     144           0 :                 pSet->GetItemState(FN_PARAM_REGION_CONDITION, sal_True, &pItem))
     145           0 :             aSection.SetCondition(((const SfxStringItem *)pItem)->GetValue());
     146             : 
     147           0 :         String aFile, aSub;
     148           0 :         if(SFX_ITEM_SET ==
     149           0 :                 pSet->GetItemState(FN_PARAM_1, sal_True, &pItem))
     150           0 :             aFile = ((const SfxStringItem *)pItem)->GetValue();
     151             : 
     152           0 :         if(SFX_ITEM_SET ==
     153           0 :                 pSet->GetItemState(FN_PARAM_3, sal_True, &pItem))
     154           0 :             aSub = ((const SfxStringItem *)pItem)->GetValue();
     155             : 
     156             : 
     157           0 :         if(aFile.Len() || aSub.Len())
     158             :         {
     159           0 :             String sLinkFileName = rtl::OUString(sfx2::cTokenSeperator);
     160           0 :             sLinkFileName += sfx2::cTokenSeperator;
     161           0 :             sLinkFileName.SetToken(0, sfx2::cTokenSeperator,aFile);
     162             : 
     163           0 :             if(SFX_ITEM_SET ==
     164           0 :                     pSet->GetItemState(FN_PARAM_2, sal_True, &pItem))
     165             :                 sLinkFileName.SetToken(1, sfx2::cTokenSeperator,
     166           0 :                     ((const SfxStringItem *)pItem)->GetValue());
     167             : 
     168           0 :             sLinkFileName += aSub;
     169           0 :             aSection.SetType( FILE_LINK_SECTION );
     170           0 :             aSection.SetLinkFileName(sLinkFileName);
     171             :         }
     172           0 :         rSh.InsertSection(aSection, aSet.Count() ? &aSet : 0);
     173           0 :         rReq.Done();
     174           0 :     }
     175           0 : }
     176             : 
     177           0 : IMPL_STATIC_LINK( SwWrtShell, InsertRegionDialog, SwSectionData*, pSect )
     178             : {
     179           0 :     boost::scoped_ptr<SwSectionData> xSectionData(pSect);
     180           0 :     if (xSectionData.get())
     181             :     {
     182           0 :         SfxItemSet aSet(pThis->GetView().GetPool(),
     183             :                 RES_COL, RES_COL,
     184             :                 RES_BACKGROUND, RES_BACKGROUND,
     185             :                 RES_FRM_SIZE, RES_FRM_SIZE,
     186             :                 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
     187           0 :                 0);
     188           0 :         SwRect aRect;
     189           0 :         pThis->CalcBoundRect(aRect, FLY_AS_CHAR);
     190           0 :         long nWidth = aRect.Width();
     191           0 :         aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
     192             :         // height=width for more consistent preview (analog to edit region)
     193           0 :         aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
     194           0 :         SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     195             :         OSL_ENSURE(pFact, "Dialogdiet fail!");
     196             :         AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
     197           0 :                                                         &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis);
     198             :         OSL_ENSURE(aTabDlg, "Dialogdiet fail!");
     199           0 :         aTabDlg->SetSectionData(*xSectionData);
     200           0 :         aTabDlg->Execute();
     201             : 
     202           0 :         delete aTabDlg;
     203             :     }
     204           0 :     return 0;
     205             : }
     206             : 
     207           0 : void SwBaseShell::EditRegionDialog(SfxRequest& rReq)
     208             : {
     209           0 :     const SfxItemSet* pArgs = rReq.GetArgs();
     210           0 :     sal_uInt16 nSlot = rReq.GetSlot();
     211           0 :     const SfxPoolItem* pItem = 0;
     212           0 :     if(pArgs)
     213           0 :         pArgs->GetItemState(nSlot, sal_False, &pItem);
     214           0 :     SwWrtShell& rWrtShell = GetShell();
     215             : 
     216           0 :     switch ( nSlot )
     217             :     {
     218             :         case FN_EDIT_REGION:
     219             :         {
     220           0 :             Window* pParentWin = &GetView().GetViewFrame()->GetWindow();
     221           0 :             sal_Bool bStart = sal_True;
     222           0 :             if(bStart)
     223             :             {
     224           0 :                 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
     225             :                 OSL_ENSURE(pFact, "Dialogdiet fail!");
     226             :                 AbstractEditRegionDlg* pEditRegionDlg = pFact->CreateEditRegionDlg( MD_EDIT_REGION,
     227           0 :                                                         pParentWin, rWrtShell);
     228             :                 OSL_ENSURE(pEditRegionDlg, "Dialogdiet fail!");
     229           0 :                 if(pItem && pItem->ISA(SfxStringItem))
     230             :                 {
     231           0 :                     pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue());
     232             :                 }
     233           0 :                 pEditRegionDlg->Execute();
     234           0 :                 delete pEditRegionDlg;
     235             :             }
     236             :             else
     237           0 :                 InfoBox(pParentWin, SW_RES(REG_WRONG_PASSWORD)).Execute();
     238             :         }
     239           0 :         break;
     240             :     }
     241          30 : }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10