bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / dialog / regionsw.cxx
blob678a8fadb50835f1ac747d36c84075a56983799f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <sfx2/htmlmode.hxx>
54 #include <svx/dlgutil.hxx>
55 #include "swabstdlg.hxx"
56 #include <boost/scoped_ptr.hpp>
58 void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
60 SwWrtShell& rSh = GetShell();
61 const SfxItemSet *pSet = rReq.GetArgs();
63 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);
73 if (!pSet || pSet->Count()==0)
75 SwRect aRect;
76 rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
78 long nWidth = aRect.Width();
79 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
81 // height=width for more consistent preview (analog to edit region)
82 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
83 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
84 OSL_ENSURE(pFact, "Dialogdiet fail!");
85 AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
86 &GetView().GetViewFrame()->GetWindow(), aSet , rSh);
87 OSL_ENSURE(aTabDlg, "Dialogdiet fail!");
88 aTabDlg->Execute();
89 rReq.Ignore();
90 delete aTabDlg;
92 else
94 const SfxPoolItem *pItem = 0;
95 String aTmpStr;
96 if ( SFX_ITEM_SET ==
97 pSet->GetItemState(FN_PARAM_REGION_NAME, sal_True, &pItem) )
99 String sRemoveWhenUniStringIsGone = ((const SfxStringItem *)pItem)->GetValue();
100 aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
102 else
103 aTmpStr = rSh.GetUniqueSectionName();
105 SwSectionData aSection(CONTENT_SECTION, aTmpStr);
106 rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr));
108 aSet.Put( *pSet );
109 if(SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem)||
110 SFX_ITEM_SET == pSet->GetItemState(FN_INSERT_REGION, sal_False, &pItem))
112 SwFmtCol aCol;
113 SwRect aRect;
114 rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
115 long nWidth = aRect.Width();
117 sal_uInt16 nCol = ((SfxUInt16Item *)pItem)->GetValue();
118 if(nCol)
120 aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
121 aSet.Put(aCol);
124 else if(SFX_ITEM_SET == pSet->GetItemState(RES_COL, sal_False, &pItem))
126 aSet.Put(*pItem);
129 const sal_Bool bHidden = SFX_ITEM_SET ==
130 pSet->GetItemState(FN_PARAM_REGION_HIDDEN, sal_True, &pItem)?
131 (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
132 const sal_Bool bProtect = SFX_ITEM_SET ==
133 pSet->GetItemState(FN_PARAM_REGION_PROTECT, sal_True, &pItem)?
134 (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
135 // #114856# edit in readonly sections
136 const sal_Bool bEditInReadonly = SFX_ITEM_SET ==
137 pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, sal_True, &pItem)?
138 (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
140 aSection.SetProtectFlag(bProtect);
141 aSection.SetHidden(bHidden);
142 // #114856# edit in readonly sections
143 aSection.SetEditInReadonlyFlag(bEditInReadonly);
145 if(SFX_ITEM_SET ==
146 pSet->GetItemState(FN_PARAM_REGION_CONDITION, sal_True, &pItem))
147 aSection.SetCondition(((const SfxStringItem *)pItem)->GetValue());
149 String aFile, aSub;
150 if(SFX_ITEM_SET ==
151 pSet->GetItemState(FN_PARAM_1, sal_True, &pItem))
152 aFile = ((const SfxStringItem *)pItem)->GetValue();
154 if(SFX_ITEM_SET ==
155 pSet->GetItemState(FN_PARAM_3, sal_True, &pItem))
156 aSub = ((const SfxStringItem *)pItem)->GetValue();
159 if(aFile.Len() || aSub.Len())
161 String sLinkFileName = OUString(sfx2::cTokenSeparator);
162 sLinkFileName += sfx2::cTokenSeparator;
163 sLinkFileName.SetToken(0, sfx2::cTokenSeparator,aFile);
165 if(SFX_ITEM_SET ==
166 pSet->GetItemState(FN_PARAM_2, sal_True, &pItem))
167 sLinkFileName.SetToken(1, sfx2::cTokenSeparator,
168 ((const SfxStringItem *)pItem)->GetValue());
170 sLinkFileName += aSub;
171 aSection.SetType( FILE_LINK_SECTION );
172 aSection.SetLinkFileName(sLinkFileName);
174 rSh.InsertSection(aSection, aSet.Count() ? &aSet : 0);
175 rReq.Done();
179 IMPL_STATIC_LINK( SwWrtShell, InsertRegionDialog, SwSectionData*, pSect )
181 boost::scoped_ptr<SwSectionData> xSectionData(pSect);
182 if (xSectionData.get())
184 SfxItemSet aSet(pThis->GetView().GetPool(),
185 RES_COL, RES_COL,
186 RES_BACKGROUND, RES_BACKGROUND,
187 RES_FRM_SIZE, RES_FRM_SIZE,
188 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
190 SwRect aRect;
191 pThis->CalcBoundRect(aRect, FLY_AS_CHAR);
192 long nWidth = aRect.Width();
193 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
194 // height=width for more consistent preview (analog to edit region)
195 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
196 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
197 OSL_ENSURE(pFact, "Dialogdiet fail!");
198 AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
199 &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis);
200 OSL_ENSURE(aTabDlg, "Dialogdiet fail!");
201 aTabDlg->SetSectionData(*xSectionData);
202 aTabDlg->Execute();
204 delete aTabDlg;
206 return 0;
209 void SwBaseShell::EditRegionDialog(SfxRequest& rReq)
211 const SfxItemSet* pArgs = rReq.GetArgs();
212 sal_uInt16 nSlot = rReq.GetSlot();
213 const SfxPoolItem* pItem = 0;
214 if(pArgs)
215 pArgs->GetItemState(nSlot, sal_False, &pItem);
216 SwWrtShell& rWrtShell = GetShell();
218 switch ( nSlot )
220 case FN_EDIT_REGION:
222 Window* pParentWin = &GetView().GetViewFrame()->GetWindow();
224 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
225 OSL_ENSURE(pFact, "Dialogdiet fail!");
226 AbstractEditRegionDlg* pEditRegionDlg = pFact->CreateEditRegionDlg(pParentWin, rWrtShell);
227 OSL_ENSURE(pEditRegionDlg, "Dialogdiet fail!");
228 if(pItem && pItem->ISA(SfxStringItem))
230 pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue());
232 pEditRegionDlg->Execute();
233 delete pEditRegionDlg;
236 break;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */