xref: /trunk/main/sw/source/ui/dialog/regionsw.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <hintids.hxx>
29 #include <uitool.hxx>
30 #include <svl/urihelper.hxx>
31 #include <svl/PasswordHelper.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svl/stritem.hxx>
34 #include <svl/eitem.hxx>
35 #include <sot/formats.hxx>
36 #include <sfx2/passwd.hxx>
37 #include <sfx2/docfilt.hxx>
38 #include <sfx2/request.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/linkmgr.hxx>
41 #include <editeng/sizeitem.hxx>
42 #include <svtools/htmlcfg.hxx>
43 #include <section.hxx>
44 #include <docary.hxx>
45 #include <regionsw.hxx>
46 #include <basesh.hxx>
47 #include <wdocsh.hxx>
48 #include <view.hxx>
49 #include <swmodule.hxx>
50 #include <wrtsh.hxx>
51 #include <swundo.hxx>               	// fuer Undo-Ids
52 #include <column.hxx>
53 #include <fmtfsize.hxx>
54 #include <swunodef.hxx>
55 #include <shellio.hxx>
56 #include <helpid.h>
57 #include <cmdid.h>
58 #include <regionsw.hrc>
59 #include <comcore.hrc>
60 #include <globals.hrc>
61 #include <sfx2/bindings.hxx>
62 #include <svx/htmlmode.hxx>
63 #include <svx/dlgutil.hxx>
64 #include "swabstdlg.hxx"
65 
66 /*--------------------------------------------------------------------
67 	Beschreibung:	Bereiche einfuegen
68  --------------------------------------------------------------------*/
69 
70 
InsertRegionDialog(SfxRequest & rReq)71 void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
72 {
73 	SwWrtShell& rSh = GetShell();
74 	const SfxItemSet *pSet = rReq.GetArgs();
75 
76 	SfxItemSet aSet(GetPool(),
77 			RES_COL, RES_COL,
78             RES_LR_SPACE, RES_LR_SPACE,
79             RES_COLUMNBALANCE, RES_FRAMEDIR,
80 			RES_BACKGROUND, RES_BACKGROUND,
81 			RES_FRM_SIZE, RES_FRM_SIZE,
82 			RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
83 			SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
84             0);
85 
86 	if (!pSet || pSet->Count()==0)
87 	{
88 		SwRect aRect;
89         rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
90 
91 		long nWidth = aRect.Width();
92 		aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
93 
94 		// Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
95 		aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
96 		SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
97         DBG_ASSERT(pFact, "Dialogdiet fail!");
98         AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
99 														&GetView().GetViewFrame()->GetWindow(), aSet , rSh);
100         DBG_ASSERT(aTabDlg, "Dialogdiet fail!");
101         aTabDlg->Execute();
102         rReq.Ignore();
103         delete aTabDlg;
104     }
105 	else
106     {
107 		const SfxPoolItem *pItem = 0;
108         String aTmpStr;
109 		if ( SFX_ITEM_SET ==
110 				pSet->GetItemState(FN_PARAM_REGION_NAME, sal_True, &pItem) )
111 			aTmpStr = rSh.GetUniqueSectionName(
112 					&((const SfxStringItem *)pItem)->GetValue() );
113 		else
114 			aTmpStr = rSh.GetUniqueSectionName();
115 
116         SwSectionData aSection(CONTENT_SECTION, aTmpStr);
117         rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr));
118 
119 		aSet.Put( *pSet );
120         if(SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_COLUMNS, sal_False, &pItem)||
121             SFX_ITEM_SET == pSet->GetItemState(FN_INSERT_REGION, sal_False, &pItem))
122 		{
123 			SwFmtCol aCol;
124 			SwRect aRect;
125             rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
126 			long nWidth = aRect.Width();
127 
128 			sal_uInt16 nCol = ((SfxUInt16Item *)pItem)->GetValue();
129 			if(nCol)
130 			{
131                 aCol.Init( nCol, 0, static_cast< sal_uInt16 >(nWidth) );
132 				aSet.Put(aCol);
133 			}
134 		}
135 		else if(SFX_ITEM_SET == pSet->GetItemState(RES_COL, sal_False, &pItem))
136 		{
137 			aSet.Put(*pItem);
138 		}
139 
140         const sal_Bool bHidden = SFX_ITEM_SET ==
141 			pSet->GetItemState(FN_PARAM_REGION_HIDDEN, sal_True, &pItem)?
142 			(sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
143 		const sal_Bool bProtect = SFX_ITEM_SET ==
144 			pSet->GetItemState(FN_PARAM_REGION_PROTECT, sal_True, &pItem)?
145 			(sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
146         // --> FME 2004-06-22 #114856# edit in readonly sections
147         const sal_Bool bEditInReadonly = SFX_ITEM_SET ==
148             pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, sal_True, &pItem)?
149             (sal_Bool)((const SfxBoolItem *)pItem)->GetValue():sal_False;
150         // <--
151 
152         aSection.SetProtectFlag(bProtect);
153 		aSection.SetHidden(bHidden);
154         // --> FME 2004-06-22 #114856# edit in readonly sections
155         aSection.SetEditInReadonlyFlag(bEditInReadonly);
156         // <--
157 
158         if(SFX_ITEM_SET ==
159                 pSet->GetItemState(FN_PARAM_REGION_CONDITION, sal_True, &pItem))
160             aSection.SetCondition(((const SfxStringItem *)pItem)->GetValue());
161 
162         String aFile, aSub;
163 		if(SFX_ITEM_SET ==
164 				pSet->GetItemState(FN_PARAM_1, sal_True, &pItem))
165 			aFile = ((const SfxStringItem *)pItem)->GetValue();
166 
167         if(SFX_ITEM_SET ==
168 				pSet->GetItemState(FN_PARAM_3, sal_True, &pItem))
169 			aSub = ((const SfxStringItem *)pItem)->GetValue();
170 
171 
172 		if(aFile.Len() || aSub.Len())
173 		{
174             String sLinkFileName(sfx2::cTokenSeperator);
175             sLinkFileName += sfx2::cTokenSeperator;
176             sLinkFileName.SetToken(0, sfx2::cTokenSeperator,aFile);
177 
178 			if(SFX_ITEM_SET ==
179 					pSet->GetItemState(FN_PARAM_2, sal_True, &pItem))
180                 sLinkFileName.SetToken(1, sfx2::cTokenSeperator,
181 					((const SfxStringItem *)pItem)->GetValue());
182 
183 			sLinkFileName += aSub;
184 			aSection.SetType( FILE_LINK_SECTION );
185 			aSection.SetLinkFileName(sLinkFileName);
186 		}
187         rSh.InsertSection(aSection, aSet.Count() ? &aSet : 0);
188 		rReq.Done();
189 	}
190 }
191 
IMPL_STATIC_LINK(SwWrtShell,InsertRegionDialog,SwSectionData *,pSect)192 IMPL_STATIC_LINK( SwWrtShell, InsertRegionDialog, SwSectionData*, pSect )
193 {
194     ::std::auto_ptr<SwSectionData> pSectionData(pSect);
195     if (pSectionData.get())
196     {
197 		SfxItemSet aSet(pThis->GetView().GetPool(),
198 				RES_COL, RES_COL,
199 				RES_BACKGROUND, RES_BACKGROUND,
200 				RES_FRM_SIZE, RES_FRM_SIZE,
201 				SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
202 				0);
203 		SwRect aRect;
204         pThis->CalcBoundRect(aRect, FLY_AS_CHAR);
205 		long nWidth = aRect.Width();
206 		aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
207 		// Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
208 		aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
209 		SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
210         DBG_ASSERT(pFact, "Dialogdiet fail!");
211         AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
212 														&pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis);
213         DBG_ASSERT(aTabDlg, "Dialogdiet fail!");
214         aTabDlg->SetSectionData(*pSectionData);
215         aTabDlg->Execute();
216 
217         delete aTabDlg;
218 	}
219 	return 0;
220 }
221 
222 /*--------------------------------------------------------------------
223 	Beschreibung:	Bereich bearbeiten
224  --------------------------------------------------------------------*/
225 
EditRegionDialog(SfxRequest & rReq)226 void SwBaseShell::EditRegionDialog(SfxRequest& rReq)
227 {
228 	const SfxItemSet* pArgs = rReq.GetArgs();
229     sal_uInt16 nSlot = rReq.GetSlot();
230 	const SfxPoolItem* pItem = 0;
231 	if(pArgs)
232 		pArgs->GetItemState(nSlot, sal_False, &pItem);
233 	SwWrtShell& rWrtShell = GetShell();
234 
235 	switch ( nSlot )
236 	{
237 		case FN_EDIT_REGION:
238 		{
239 			Window* pParentWin = &GetView().GetViewFrame()->GetWindow();
240 			sal_Bool bStart = sal_True;
241             if(bStart)
242 			{
243 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
244                 DBG_ASSERT(pFact, "Dialogdiet fail!");
245                 AbstractEditRegionDlg* pEditRegionDlg = pFact->CreateEditRegionDlg( MD_EDIT_REGION,
246 														pParentWin, rWrtShell);
247                 DBG_ASSERT(pEditRegionDlg, "Dialogdiet fail!");
248 				if(pItem && pItem->ISA(SfxStringItem))
249                 {
250                     pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue());
251                 }
252                 pEditRegionDlg->Execute();
253 				delete pEditRegionDlg;
254 			}
255 			else
256 				InfoBox(pParentWin, SW_RES(REG_WRONG_PASSWORD)).Execute();
257 		}
258 		break;
259 	}
260 }
261