update dev300-m58
[ooovba.git] / sw / source / ui / dialog / regionsw.cxx
blobabda1181f360aa57edb70fab60949a6435f03c5f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: regionsw.cxx,v $
10 * $Revision: 1.40 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <uitool.hxx>
37 #include <svtools/urihelper.hxx>
38 #include <svtools/PasswordHelper.hxx>
39 #ifndef _MSGBOX_HXX //autogen
40 #include <vcl/msgbox.hxx>
41 #endif
42 #include <svtools/stritem.hxx>
43 #include <svtools/eitem.hxx>
44 #include <sot/formats.hxx>
45 #ifndef _PASSWD_HXX //autogen
46 #include <sfx2/passwd.hxx>
47 #endif
48 #include <sfx2/docfilt.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <sfx2/linkmgr.hxx>
52 #ifndef _SVX_SIZEITEM_HXX //autogen
54 #include <svx/sizeitem.hxx>
55 #endif
57 #include <svx/htmlcfg.hxx>
58 #include <section.hxx>
59 #include <docary.hxx>
60 #include <regionsw.hxx>
61 #ifndef _BASESH_HXX
62 #include <basesh.hxx>
63 #endif
64 #ifndef _WDOCSH_HXX
65 #include <wdocsh.hxx>
66 #endif
67 #ifndef _VIEW_HXX
68 #include <view.hxx>
69 #endif
70 #include <swmodule.hxx>
71 #include <wrtsh.hxx>
72 #include <swundo.hxx> // fuer Undo-Ids
73 #include <column.hxx>
74 #include <fmtfsize.hxx>
75 #include <swunodef.hxx>
76 #include <shellio.hxx>
78 #ifndef _HELPID_H
79 #include <helpid.h>
80 #endif
81 #ifndef _CMDID_H
82 #include <cmdid.h>
83 #endif
84 #ifndef _REGIONSW_HRC
85 #include <regionsw.hrc>
86 #endif
87 #ifndef _COMCORE_HRC
88 #include <comcore.hrc>
89 #endif
90 #ifndef _GLOBALS_HRC
91 #include <globals.hrc>
92 #endif
93 #include <sfx2/bindings.hxx>
94 #include <svx/htmlmode.hxx>
95 #include <svx/dlgutil.hxx>
96 #include "swabstdlg.hxx"
98 /*--------------------------------------------------------------------
99 Beschreibung: Bereiche einfuegen
100 --------------------------------------------------------------------*/
103 void SwBaseShell::InsertRegionDialog(SfxRequest& rReq)
105 SwWrtShell& rSh = GetShell();
106 const SfxItemSet *pSet = rReq.GetArgs();
108 SfxItemSet aSet(GetPool(),
109 RES_COL, RES_COL,
110 RES_LR_SPACE, RES_LR_SPACE,
111 RES_COLUMNBALANCE, RES_FRAMEDIR,
112 RES_BACKGROUND, RES_BACKGROUND,
113 RES_FRM_SIZE, RES_FRM_SIZE,
114 RES_FTN_AT_TXTEND, RES_END_AT_TXTEND,
115 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
118 if (!pSet || pSet->Count()==0)
120 SwRect aRect;
121 rSh.CalcBoundRect(aRect, FLY_IN_CNTNT);
123 long nWidth = aRect.Width();
124 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
126 // Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
127 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
128 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
129 DBG_ASSERT(pFact, "Dialogdiet fail!");
130 AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
131 &GetView().GetViewFrame()->GetWindow(), aSet , rSh);
132 DBG_ASSERT(aTabDlg, "Dialogdiet fail!");
133 aTabDlg->Execute();
134 rReq.Ignore();
135 delete aTabDlg;
137 else
139 const SfxPoolItem *pItem = 0;
140 String aTmpStr;
141 if ( SFX_ITEM_SET ==
142 pSet->GetItemState(FN_PARAM_REGION_NAME, TRUE, &pItem) )
143 aTmpStr = rSh.GetUniqueSectionName(
144 &((const SfxStringItem *)pItem)->GetValue() );
145 else
146 aTmpStr = rSh.GetUniqueSectionName();
148 SwSection aSection(CONTENT_SECTION,aTmpStr);
149 rReq.SetReturnValue(SfxStringItem(FN_INSERT_REGION, aTmpStr));
151 aSet.Put( *pSet );
152 if(SFX_ITEM_SET == pSet->GetItemState(SID_ATTR_COLUMNS, FALSE, &pItem)||
153 SFX_ITEM_SET == pSet->GetItemState(FN_INSERT_REGION, FALSE, &pItem))
155 SwFmtCol aCol;
156 SwRect aRect;
157 rSh.CalcBoundRect(aRect, FLY_IN_CNTNT);
158 long nWidth = aRect.Width();
160 USHORT nCol = ((SfxUInt16Item *)pItem)->GetValue();
161 if(nCol)
163 aCol.Init( nCol, 0, static_cast< USHORT >(nWidth) );
164 aSet.Put(aCol);
167 else if(SFX_ITEM_SET == pSet->GetItemState(RES_COL, FALSE, &pItem))
169 aSet.Put(*pItem);
172 const BOOL bHidden = SFX_ITEM_SET ==
173 pSet->GetItemState(FN_PARAM_REGION_HIDDEN, TRUE, &pItem)?
174 (BOOL)((const SfxBoolItem *)pItem)->GetValue():FALSE;
175 const BOOL bProtect = SFX_ITEM_SET ==
176 pSet->GetItemState(FN_PARAM_REGION_PROTECT, TRUE, &pItem)?
177 (BOOL)((const SfxBoolItem *)pItem)->GetValue():FALSE;
178 // --> FME 2004-06-22 #114856# edit in readonly sections
179 const BOOL bEditInReadonly = SFX_ITEM_SET ==
180 pSet->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY, TRUE, &pItem)?
181 (BOOL)((const SfxBoolItem *)pItem)->GetValue():FALSE;
182 // <--
184 aSection.SetProtect(bProtect);
185 aSection.SetHidden(bHidden);
186 // --> FME 2004-06-22 #114856# edit in readonly sections
187 aSection.SetEditInReadonly(bEditInReadonly);
188 // <--
190 if(SFX_ITEM_SET ==
191 pSet->GetItemState(FN_PARAM_REGION_CONDITION, TRUE, &pItem))
192 aSection.SetCondition(((const SfxStringItem *)pItem)->GetValue());
194 String aFile, aSub;
195 if(SFX_ITEM_SET ==
196 pSet->GetItemState(FN_PARAM_1, TRUE, &pItem))
197 aFile = ((const SfxStringItem *)pItem)->GetValue();
199 if(SFX_ITEM_SET ==
200 pSet->GetItemState(FN_PARAM_3, TRUE, &pItem))
201 aSub = ((const SfxStringItem *)pItem)->GetValue();
204 if(aFile.Len() || aSub.Len())
206 String sLinkFileName(sfx2::cTokenSeperator);
207 sLinkFileName += sfx2::cTokenSeperator;
208 sLinkFileName.SetToken(0, sfx2::cTokenSeperator,aFile);
210 if(SFX_ITEM_SET ==
211 pSet->GetItemState(FN_PARAM_2, TRUE, &pItem))
212 sLinkFileName.SetToken(1, sfx2::cTokenSeperator,
213 ((const SfxStringItem *)pItem)->GetValue());
215 sLinkFileName += aSub;
216 aSection.SetType( FILE_LINK_SECTION );
217 aSection.SetLinkFileName(sLinkFileName);
219 rSh.InsertSection(aSection, aSet.Count() ? &aSet : 0);
220 rReq.Done();
224 IMPL_STATIC_LINK( SwWrtShell, InsertRegionDialog, SwSection*, pSect )
226 if( pSect )
228 SfxItemSet aSet(pThis->GetView().GetPool(),
229 RES_COL, RES_COL,
230 RES_BACKGROUND, RES_BACKGROUND,
231 RES_FRM_SIZE, RES_FRM_SIZE,
232 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
234 SwRect aRect;
235 pThis->CalcBoundRect(aRect, FLY_IN_CNTNT);
236 long nWidth = aRect.Width();
237 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
238 // Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
239 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
240 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
241 DBG_ASSERT(pFact, "Dialogdiet fail!");
242 AbstractInsertSectionTabDialog* aTabDlg = pFact->CreateInsertSectionTabDialog( DLG_INSERT_SECTION,
243 &pThis->GetView().GetViewFrame()->GetWindow(),aSet , *pThis);
244 DBG_ASSERT(aTabDlg, "Dialogdiet fail!");
245 aTabDlg->SetSection(*pSect);
246 aTabDlg->Execute();
248 delete pSect;
249 delete aTabDlg;
251 return 0;
254 /*--------------------------------------------------------------------
255 Beschreibung: Bereich bearbeiten
256 --------------------------------------------------------------------*/
258 void SwBaseShell::EditRegionDialog(SfxRequest& rReq)
260 const SfxItemSet* pArgs = rReq.GetArgs();
261 USHORT nSlot = rReq.GetSlot();
262 const SfxPoolItem* pItem = 0;
263 if(pArgs)
264 pArgs->GetItemState(nSlot, FALSE, &pItem);
265 SwWrtShell& rWrtShell = GetShell();
267 switch ( nSlot )
269 case FN_EDIT_REGION:
271 Window* pParentWin = &GetView().GetViewFrame()->GetWindow();
272 BOOL bStart = TRUE;
273 if(bStart)
275 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
276 DBG_ASSERT(pFact, "Dialogdiet fail!");
277 AbstractEditRegionDlg* pEditRegionDlg = pFact->CreateEditRegionDlg( MD_EDIT_REGION,
278 pParentWin, rWrtShell);
279 DBG_ASSERT(pEditRegionDlg, "Dialogdiet fail!");
280 if(pItem && pItem->ISA(SfxStringItem))
282 pEditRegionDlg->SelectSection(((const SfxStringItem*)pItem)->GetValue());
284 pEditRegionDlg->Execute();
285 delete pEditRegionDlg;
287 else
288 InfoBox(pParentWin, SW_RES(REG_WRONG_PASSWORD)).Execute();
290 break;