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 :
21 : #include <sfx2/request.hxx>
22 : #include <sfx2/viewfrm.hxx>
23 : #include <sfx2/objface.hxx>
24 : #include <fldmgr.hxx>
25 : #include <expfld.hxx>
26 : #include <modcfg.hxx>
27 :
28 : #include <tools/shl.hxx>
29 :
30 : #include "swmodule.hxx"
31 : #include "view.hxx"
32 : #include "wview.hxx"
33 : #include "wrtsh.hxx"
34 : #include "cmdid.h"
35 : #include "caption.hxx"
36 : #include "poolfmt.hxx"
37 : #include "edtwin.hxx"
38 : #include <SwStyleNameMapper.hxx>
39 :
40 : #include "swabstdlg.hxx"
41 : #include "frmui.hrc"
42 : #include "misc.hrc"
43 :
44 : #include "view.hrc"
45 :
46 : extern String* pOldGrfCat;
47 : extern String* pOldTabCat;
48 : extern String* pOldFrmCat;
49 : extern String* pOldDrwCat;
50 :
51 0 : void SwView::ExecDlgExt(SfxRequest &rReq)
52 : {
53 0 : Window *pMDI = &GetViewFrame()->GetWindow();
54 :
55 0 : switch ( rReq.GetSlot() )
56 : {
57 : case FN_INSERT_CAPTION:
58 : {
59 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
60 : OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
61 :
62 0 : VclAbstractDialog* pDialog = pFact->CreateSwCaptionDialog( pMDI, *this, DLG_CAPTION );
63 : OSL_ENSURE(pDialog, "Dialogdiet fail!");
64 0 : if ( pDialog )
65 : {
66 0 : pDialog->Execute();
67 0 : delete pDialog;
68 : }
69 0 : break;
70 : }
71 : case FN_EDIT_FOOTNOTE:
72 : {
73 0 : SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
74 : OSL_ENSURE(pFact, "Dialogdiet fail!");
75 : AbstractInsFootNoteDlg* pDlg = pFact->CreateInsFootNoteDlg(
76 0 : pMDI, *m_pWrtShell, sal_True);
77 : OSL_ENSURE(pDlg, "Dialogdiet fail!");
78 :
79 0 : pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
80 0 : pDlg->SetText( SW_RESSTR(STR_EDIT_FOOTNOTE) );
81 0 : pDlg->Execute();
82 0 : delete pDlg;
83 0 : break;
84 : }
85 : }
86 0 : }
87 :
88 0 : void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
89 : {
90 0 : SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
91 :
92 0 : sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
93 0 : if (pModOpt->IsInsWithCaption(bWeb))
94 : {
95 0 : const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, (SwCapObjType)nType, pOleId);
96 0 : if (pOpt && pOpt->UseCaption() == sal_True)
97 0 : InsertCaption(pOpt);
98 : }
99 0 : }
100 :
101 0 : void SwView::InsertCaption(const InsCaptionOpt *pOpt)
102 : {
103 0 : if (!pOpt)
104 0 : return;
105 :
106 0 : const String &rName = pOpt->GetCategory();
107 :
108 : // Is there a pool template with the same name?
109 0 : SwWrtShell &rSh = GetWrtShell();
110 0 : if(rName.Len())
111 : {
112 0 : sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
113 0 : if( USHRT_MAX != nPoolId )
114 0 : rSh.GetTxtCollFromPool(nPoolId);
115 : // Pool template does not exist: Does it exist on the document?
116 0 : else if( !rSh.GetParaStyle(rName) )
117 : {
118 : // It also does not exist in the document: generate
119 0 : SwTxtFmtColl* pDerivedFrom = rSh.GetTxtCollFromPool(RES_POOLCOLL_LABEL);
120 0 : rSh.MakeTxtFmtColl(rName, pDerivedFrom);
121 : }
122 : }
123 :
124 0 : SelectionType eType = rSh.GetSelectionType();
125 0 : if (eType & nsSelectionType::SEL_OLE)
126 0 : eType = nsSelectionType::SEL_GRF;
127 :
128 0 : const SwLabelType eT = eType & nsSelectionType::SEL_TBL ? LTYPE_TABLE :
129 0 : eType & nsSelectionType::SEL_FRM ? LTYPE_FLY :
130 : eType == nsSelectionType::SEL_TXT ? LTYPE_FLY :
131 0 : eType & nsSelectionType::SEL_DRW ? LTYPE_DRAW :
132 0 : LTYPE_OBJECT;
133 :
134 0 : SwFldMgr aMgr(&rSh);
135 : SwSetExpFieldType* pFldType =
136 0 : (SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
137 0 : if (!pFldType && rName.Len() )
138 : {
139 : // Create new field types
140 0 : SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
141 0 : aMgr.InsertFldType(aSwSetExpFieldType);
142 0 : pFldType = (SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
143 : }
144 :
145 0 : if (!pOpt->IgnoreSeqOpts())
146 : {
147 0 : if (pFldType)
148 : {
149 0 : pFldType->SetDelimiter(pOpt->GetSeparator());
150 0 : pFldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
151 : }
152 : }
153 :
154 0 : sal_uInt16 nID = USHRT_MAX;
155 0 : SwFieldType* pType = 0;
156 0 : const sal_uInt16 nCount = aMgr.GetFldTypeCount();
157 0 : if( rName.Len() )
158 : {
159 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
160 : {
161 0 : pType = aMgr.GetFldType(USHRT_MAX, i);
162 0 : String aTmpName( pType->GetName() );
163 0 : if (aTmpName == rName && pType->Which() == RES_SETEXPFLD)
164 : {
165 0 : nID = i;
166 0 : break;
167 : }
168 0 : }
169 : }
170 0 : rSh.StartAllAction();
171 :
172 0 : GetWrtShell().InsertLabel( eT,
173 0 : pOpt->GetCaption(),
174 0 : !pOpt->IgnoreSeqOpts() ? aEmptyStr : pOpt->GetSeparator(),
175 0 : pOpt->GetNumSeparator(),
176 0 : !pOpt->GetPos(),
177 : nID,
178 0 : pOpt->GetCharacterStyle(),
179 0 : pOpt->CopyAttributes() );
180 : // Set Number Format
181 0 : if(pType)
182 0 : ((SwSetExpFieldType*)pType)->SetSeqFormat(pOpt->GetNumType());
183 :
184 0 : rSh.UpdateExpFlds( sal_True );
185 :
186 0 : rSh.EndAllAction();
187 :
188 0 : if ( rSh.IsFrmSelected() )
189 : {
190 0 : GetEditWin().StopInsFrm();
191 0 : rSh.EnterSelFrmMode();
192 : }
193 :
194 : // rember category
195 0 : String** ppStr = 0;
196 0 : if (eType & nsSelectionType::SEL_GRF)
197 0 : ppStr = &pOldGrfCat;
198 0 : else if( eType & nsSelectionType::SEL_TBL)
199 0 : ppStr = &pOldTabCat;
200 0 : else if( eType & nsSelectionType::SEL_FRM)
201 0 : ppStr = &pOldFrmCat;
202 0 : else if( eType == nsSelectionType::SEL_TXT)
203 0 : ppStr = &pOldFrmCat;
204 0 : else if( eType & nsSelectionType::SEL_DRW)
205 0 : ppStr = &pOldDrwCat;
206 :
207 0 : if( ppStr )
208 : {
209 0 : if( !*ppStr )
210 0 : *ppStr = new String( rName );
211 : else
212 0 : **ppStr = rName;
213 0 : }
214 99 : }
215 :
216 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|