1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <hintids.hxx>
22 #include <svl/urihelper.hxx>
23 #include <svl/PasswordHelper.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <svl/stritem.hxx>
26 #include <svl/eitem.hxx>
27 #include <sot/formats.hxx>
28 #include <sfx2/passwd.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/request.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/linkmgr.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include <svtools/htmlcfg.hxx>
35 #include <section.hxx>
37 #include <regionsw.hxx>
41 #include <swmodule.hxx>
43 #include <swundo.hxx> // for Undo-Ids
45 #include <fmtfsize.hxx>
46 #include <shellio.hxx>
49 #include <regionsw.hrc>
50 #include <comcore.hrc>
51 #include <globals.hrc>
52 #include <sfx2/bindings.hxx>
53 #include <sfx2/htmlmode.hxx>
54 #include <svx/dlgutil.hxx>
55 #include "swabstdlg.hxx"
56 #include <boost/scoped_ptr.hpp>
58 void SwBaseShell::InsertRegionDialog(SfxRequest
& rReq
)
60 SwWrtShell
& rSh
= GetShell();
61 const SfxItemSet
*pSet
= rReq
.GetArgs();
63 SfxItemSet
aSet(GetPool(),
65 RES_LR_SPACE
, RES_LR_SPACE
,
66 RES_COLUMNBALANCE
, RES_FRAMEDIR
,
67 RES_BACKGROUND
, RES_BACKGROUND
,
68 RES_FRM_SIZE
, RES_FRM_SIZE
,
69 RES_FTN_AT_TXTEND
, RES_END_AT_TXTEND
,
70 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
73 if (!pSet
|| pSet
->Count()==0)
76 rSh
.CalcBoundRect(aRect
, FLY_AS_CHAR
);
78 long nWidth
= aRect
.Width();
79 aSet
.Put(SwFmtFrmSize(ATT_VAR_SIZE
, nWidth
));
81 // height=width for more consistent preview (analog to edit region)
82 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
83 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
84 OSL_ENSURE(pFact
, "Dialogdiet fail!");
85 AbstractInsertSectionTabDialog
* aTabDlg
= pFact
->CreateInsertSectionTabDialog( DLG_INSERT_SECTION
,
86 &GetView().GetViewFrame()->GetWindow(), aSet
, rSh
);
87 OSL_ENSURE(aTabDlg
, "Dialogdiet fail!");
94 const SfxPoolItem
*pItem
= 0;
97 pSet
->GetItemState(FN_PARAM_REGION_NAME
, sal_True
, &pItem
) )
99 String sRemoveWhenUniStringIsGone
= ((const SfxStringItem
*)pItem
)->GetValue();
100 aTmpStr
= rSh
.GetUniqueSectionName(&sRemoveWhenUniStringIsGone
);
103 aTmpStr
= rSh
.GetUniqueSectionName();
105 SwSectionData
aSection(CONTENT_SECTION
, aTmpStr
);
106 rReq
.SetReturnValue(SfxStringItem(FN_INSERT_REGION
, aTmpStr
));
109 if(SFX_ITEM_SET
== pSet
->GetItemState(SID_ATTR_COLUMNS
, sal_False
, &pItem
)||
110 SFX_ITEM_SET
== pSet
->GetItemState(FN_INSERT_REGION
, sal_False
, &pItem
))
114 rSh
.CalcBoundRect(aRect
, FLY_AS_CHAR
);
115 long nWidth
= aRect
.Width();
117 sal_uInt16 nCol
= ((SfxUInt16Item
*)pItem
)->GetValue();
120 aCol
.Init( nCol
, 0, static_cast< sal_uInt16
>(nWidth
) );
124 else if(SFX_ITEM_SET
== pSet
->GetItemState(RES_COL
, sal_False
, &pItem
))
129 const sal_Bool bHidden
= SFX_ITEM_SET
==
130 pSet
->GetItemState(FN_PARAM_REGION_HIDDEN
, sal_True
, &pItem
)?
131 (sal_Bool
)((const SfxBoolItem
*)pItem
)->GetValue():sal_False
;
132 const sal_Bool bProtect
= SFX_ITEM_SET
==
133 pSet
->GetItemState(FN_PARAM_REGION_PROTECT
, sal_True
, &pItem
)?
134 (sal_Bool
)((const SfxBoolItem
*)pItem
)->GetValue():sal_False
;
135 // #114856# edit in readonly sections
136 const sal_Bool bEditInReadonly
= SFX_ITEM_SET
==
137 pSet
->GetItemState(FN_PARAM_REGION_EDIT_IN_READONLY
, sal_True
, &pItem
)?
138 (sal_Bool
)((const SfxBoolItem
*)pItem
)->GetValue():sal_False
;
140 aSection
.SetProtectFlag(bProtect
);
141 aSection
.SetHidden(bHidden
);
142 // #114856# edit in readonly sections
143 aSection
.SetEditInReadonlyFlag(bEditInReadonly
);
146 pSet
->GetItemState(FN_PARAM_REGION_CONDITION
, sal_True
, &pItem
))
147 aSection
.SetCondition(((const SfxStringItem
*)pItem
)->GetValue());
151 pSet
->GetItemState(FN_PARAM_1
, sal_True
, &pItem
))
152 aFile
= ((const SfxStringItem
*)pItem
)->GetValue();
155 pSet
->GetItemState(FN_PARAM_3
, sal_True
, &pItem
))
156 aSub
= ((const SfxStringItem
*)pItem
)->GetValue();
159 if(aFile
.Len() || aSub
.Len())
161 String sLinkFileName
= OUString(sfx2::cTokenSeparator
);
162 sLinkFileName
+= sfx2::cTokenSeparator
;
163 sLinkFileName
.SetToken(0, sfx2::cTokenSeparator
,aFile
);
166 pSet
->GetItemState(FN_PARAM_2
, sal_True
, &pItem
))
167 sLinkFileName
.SetToken(1, sfx2::cTokenSeparator
,
168 ((const SfxStringItem
*)pItem
)->GetValue());
170 sLinkFileName
+= aSub
;
171 aSection
.SetType( FILE_LINK_SECTION
);
172 aSection
.SetLinkFileName(sLinkFileName
);
174 rSh
.InsertSection(aSection
, aSet
.Count() ? &aSet
: 0);
179 IMPL_STATIC_LINK( SwWrtShell
, InsertRegionDialog
, SwSectionData
*, pSect
)
181 boost::scoped_ptr
<SwSectionData
> xSectionData(pSect
);
182 if (xSectionData
.get())
184 SfxItemSet
aSet(pThis
->GetView().GetPool(),
186 RES_BACKGROUND
, RES_BACKGROUND
,
187 RES_FRM_SIZE
, RES_FRM_SIZE
,
188 SID_ATTR_PAGE_SIZE
, SID_ATTR_PAGE_SIZE
,
191 pThis
->CalcBoundRect(aRect
, FLY_AS_CHAR
);
192 long nWidth
= aRect
.Width();
193 aSet
.Put(SwFmtFrmSize(ATT_VAR_SIZE
, nWidth
));
194 // height=width for more consistent preview (analog to edit region)
195 aSet
.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE
, Size(nWidth
, nWidth
)));
196 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
197 OSL_ENSURE(pFact
, "Dialogdiet fail!");
198 AbstractInsertSectionTabDialog
* aTabDlg
= pFact
->CreateInsertSectionTabDialog( DLG_INSERT_SECTION
,
199 &pThis
->GetView().GetViewFrame()->GetWindow(),aSet
, *pThis
);
200 OSL_ENSURE(aTabDlg
, "Dialogdiet fail!");
201 aTabDlg
->SetSectionData(*xSectionData
);
209 void SwBaseShell::EditRegionDialog(SfxRequest
& rReq
)
211 const SfxItemSet
* pArgs
= rReq
.GetArgs();
212 sal_uInt16 nSlot
= rReq
.GetSlot();
213 const SfxPoolItem
* pItem
= 0;
215 pArgs
->GetItemState(nSlot
, sal_False
, &pItem
);
216 SwWrtShell
& rWrtShell
= GetShell();
222 Window
* pParentWin
= &GetView().GetViewFrame()->GetWindow();
224 SwAbstractDialogFactory
* pFact
= SwAbstractDialogFactory::Create();
225 OSL_ENSURE(pFact
, "Dialogdiet fail!");
226 AbstractEditRegionDlg
* pEditRegionDlg
= pFact
->CreateEditRegionDlg(pParentWin
, rWrtShell
);
227 OSL_ENSURE(pEditRegionDlg
, "Dialogdiet fail!");
228 if(pItem
&& pItem
->ISA(SfxStringItem
))
230 pEditRegionDlg
->SelectSection(((const SfxStringItem
*)pItem
)->GetValue());
232 pEditRegionDlg
->Execute();
233 delete pEditRegionDlg
;
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */