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, "Dialog creation failed!");
86 : boost::scoped_ptr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog(
87 0 : &GetView().GetViewFrame()->GetWindow(), aSet , rSh));
88 : OSL_ENSURE(aTabDlg, "Dialog creation failed!");
89 0 : aTabDlg->Execute();
90 0 : rReq.Ignore();
91 : }
92 : else
93 : {
94 0 : const SfxPoolItem *pItem = 0;
95 0 : OUString aTmpStr;
96 0 : if ( SfxItemState::SET ==
97 0 : pSet->GetItemState(FN_PARAM_REGION_NAME, true, &pItem) )
98 : {
99 0 : const OUString sRemoveWhenUniStringIsGone = ((const SfxStringItem *)pItem)->GetValue();
100 0 : aTmpStr = rSh.GetUniqueSectionName(&sRemoveWhenUniStringIsGone);
101 : }
102 : else
103 0 : aTmpStr = rSh.GetUniqueSectionName();
104 :
105 0 : SwSectionData aSection(CONTENT_SECTION, aTmpStr);
106 0 : rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr));
107 :
108 0 : aSet.Put( *pSet );
109 0 : if(SfxItemState::SET == pSet->GetItemState(SID_ATTR_COLUMNS, false, &pItem)||
110 0 : SfxItemState::SET == pSet->GetItemState(FN_INSERT_REGION, false, &pItem))
111 : {
112 0 : SwFmtCol aCol;
113 0 : SwRect aRect;
114 0 : rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
115 0 : long nWidth = aRect.Width();
116 :
117 0 : sal_uInt16 nCol = ((SfxUInt16Item *)pItem)->GetValue();
118 0 : if(nCol)
119 : {
120 0 : aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
121 0 : aSet.Put(aCol);
122 0 : }
123 : }
124 0 : else if(SfxItemState::SET == pSet->GetItemState(RES_COL, false, &pItem))
125 : {
126 0 : aSet.Put(*pItem);
127 : }
128 :
129 0 : const bool bHidden = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_HIDDEN, true, &pItem) &&
130 0 : ((const SfxBoolItem *)pItem)->GetValue();
131 0 : const bool bProtect = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_PROTECT, true, &pItem) &&
132 0 : ((const SfxBoolItem *)pItem)->GetValue();
133 : // #114856# edit in readonly sections
134 0 : const bool bEditInReadonly = SfxItemState::SET == pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, true, &pItem) &&
135 0 : ((const SfxBoolItem *)pItem)->GetValue();
136 :
137 0 : aSection.SetProtectFlag(bProtect);
138 0 : aSection.SetHidden(bHidden);
139 : // #114856# edit in readonly sections
140 0 : aSection.SetEditInReadonlyFlag(bEditInReadonly);
141 :
142 0 : if(SfxItemState::SET ==
143 0 : pSet->GetItemState(FN_PARAM_REGION_CONDITION, true, &pItem))
144 0 : aSection.SetCondition(((const SfxStringItem *)pItem)->GetValue());
145 :
146 0 : OUString aFile, aSub;
147 0 : if(SfxItemState::SET ==
148 0 : pSet->GetItemState(FN_PARAM_1, true, &pItem))
149 0 : aFile = ((const SfxStringItem *)pItem)->GetValue();
150 :
151 0 : if(SfxItemState::SET ==
152 0 : pSet->GetItemState(FN_PARAM_3, true, &pItem))
153 0 : aSub = ((const SfxStringItem *)pItem)->GetValue();
154 :
155 0 : if(!aFile.isEmpty() || !aSub.isEmpty())
156 : {
157 0 : OUString sLinkFileName = OUString(sfx2::cTokenSeparator);
158 0 : sLinkFileName += OUString(sfx2::cTokenSeparator);
159 0 : sLinkFileName = comphelper::string::setToken(sLinkFileName, 0, sfx2::cTokenSeparator, aFile);
160 :
161 0 : if(SfxItemState::SET ==
162 0 : pSet->GetItemState(FN_PARAM_2, true, &pItem))
163 : {
164 0 : sLinkFileName = comphelper::string::setToken(sLinkFileName, 1, sfx2::cTokenSeparator,
165 0 : ((const SfxStringItem *)pItem)->GetValue());
166 : }
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, "Dialog creation failed!");
196 : boost::scoped_ptr<AbstractInsertSectionTabDialog> aTabDlg(pFact->CreateInsertSectionTabDialog(
197 0 : &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis));
198 : OSL_ENSURE(aTabDlg, "Dialog creation failed!");
199 0 : aTabDlg->SetSectionData(*xSectionData);
200 0 : aTabDlg->Execute();
201 : }
202 0 : return 0;
203 : }
204 :
205 0 : void SwBaseShell::EditRegionDialog(SfxRequest& rReq)
206 : {
207 0 : const SfxItemSet* pArgs = rReq.GetArgs();
208 0 : sal_uInt16 nSlot = rReq.GetSlot();
209 0 : const SfxPoolItem* pItem = 0;
210 0 : if(pArgs)
211 0 : pArgs->GetItemState(nSlot, false, &pItem);
212 0 : SwWrtShell& rWrtShell = GetShell();
213 :
214 0 : switch ( nSlot )
215 : {
216 : case FN_EDIT_REGION:
217 : {
218 0 : vcl::Window* pParentWin = &GetView().GetViewFrame()->GetWindow();
219 : {
220 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
221 : OSL_ENSURE(pFact, "Dialog creation failed!");
222 0 : boost::scoped_ptr<AbstractEditRegionDlg> pEditRegionDlg(pFact->CreateEditRegionDlg(pParentWin, rWrtShell));
223 : OSL_ENSURE(pEditRegionDlg, "Dialog creation failed!");
224 0 : if(pItem && pItem->ISA(SfxStringItem))
225 : {
226 0 : pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue());
227 : }
228 0 : pEditRegionDlg->Execute();
229 : }
230 : }
231 0 : break;
232 : }
233 270 : }
234 :
235 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|