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