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