bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uiview / viewdlg2.cxx
blob136da959671e196e3613e8edb27c3f9d9bd77229
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
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>
28 #include <tools/shl.hxx>
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>
40 #include "swabstdlg.hxx"
41 #include "frmui.hrc"
42 #include "misc.hrc"
44 #include "view.hrc"
46 extern String* pOldGrfCat;
47 extern String* pOldTabCat;
48 extern String* pOldFrmCat;
49 extern String* pOldDrwCat;
51 void SwView::ExecDlgExt(SfxRequest &rReq)
53 Window *pMDI = &GetViewFrame()->GetWindow();
55 switch ( rReq.GetSlot() )
57 case FN_INSERT_CAPTION:
59 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
60 OSL_ENSURE(pFact, "SwAbstractDialogFactory fail!");
62 VclAbstractDialog* pDialog = pFact->CreateSwCaptionDialog( pMDI, *this, DLG_CAPTION );
63 OSL_ENSURE(pDialog, "Dialogdiet fail!");
64 if ( pDialog )
66 pDialog->Execute();
67 delete pDialog;
69 break;
71 case FN_EDIT_FOOTNOTE:
73 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
74 OSL_ENSURE(pFact, "Dialogdiet fail!");
75 AbstractInsFootNoteDlg* pDlg = pFact->CreateInsFootNoteDlg(
76 pMDI, *m_pWrtShell, sal_True);
77 OSL_ENSURE(pDlg, "Dialogdiet fail!");
79 pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
80 pDlg->SetText( SW_RESSTR(STR_EDIT_FOOTNOTE) );
81 pDlg->Execute();
82 delete pDlg;
83 break;
88 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
90 SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
92 sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
93 if (pModOpt->IsInsWithCaption(bWeb))
95 const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, (SwCapObjType)nType, pOleId);
96 if (pOpt && pOpt->UseCaption() == sal_True)
97 InsertCaption(pOpt);
101 void SwView::InsertCaption(const InsCaptionOpt *pOpt)
103 if (!pOpt)
104 return;
106 const String &rName = pOpt->GetCategory();
108 // Existiert Pool-Vorlage gleichen Namens?
109 SwWrtShell &rSh = GetWrtShell();
110 if(rName.Len())
112 sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
113 if( USHRT_MAX != nPoolId )
114 rSh.GetTxtCollFromPool(nPoolId);
115 // Pool-Vorlage existiert nicht: Existiert sie am Dokument?
116 else if( !rSh.GetParaStyle(rName) )
118 // Sie existiert auch nicht am Dokument: erzeugen
119 SwTxtFmtColl* pDerivedFrom = rSh.GetTxtCollFromPool(RES_POOLCOLL_LABEL);
120 rSh.MakeTxtFmtColl(rName, pDerivedFrom);
124 SelectionType eType = rSh.GetSelectionType();
125 if (eType & nsSelectionType::SEL_OLE)
126 eType = nsSelectionType::SEL_GRF;
128 // SwLabelType
129 const SwLabelType eT = eType & nsSelectionType::SEL_TBL ? LTYPE_TABLE :
130 eType & nsSelectionType::SEL_FRM ? LTYPE_FLY :
131 eType == nsSelectionType::SEL_TXT ? LTYPE_FLY :
132 eType & nsSelectionType::SEL_DRW ? LTYPE_DRAW :
133 LTYPE_OBJECT;
135 SwFldMgr aMgr(&rSh);
136 SwSetExpFieldType* pFldType =
137 (SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
138 if (!pFldType && rName.Len() )
140 // Neuen Feldtypen erzeugen
141 SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
142 aMgr.InsertFldType(aSwSetExpFieldType);
143 pFldType = (SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
146 if (!pOpt->IgnoreSeqOpts())
148 if (pFldType)
150 pFldType->SetDelimiter(pOpt->GetSeparator());
151 pFldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
155 sal_uInt16 nID = USHRT_MAX;
156 SwFieldType* pType = 0;
157 const sal_uInt16 nCount = aMgr.GetFldTypeCount();
158 if( rName.Len() )
160 for (sal_uInt16 i = 0; i < nCount; ++i)
162 pType = aMgr.GetFldType(USHRT_MAX, i);
163 String aTmpName( pType->GetName() );
164 if (aTmpName == rName && pType->Which() == RES_SETEXPFLD)
166 nID = i;
167 break;
171 rSh.StartAllAction();
173 GetWrtShell().InsertLabel( eT,
174 pOpt->GetCaption(),
175 !pOpt->IgnoreSeqOpts() ? aEmptyStr : pOpt->GetSeparator(),
176 pOpt->GetNumSeparator(),
177 !pOpt->GetPos(),
178 nID,
179 pOpt->GetCharacterStyle(),
180 pOpt->CopyAttributes() );
181 // Nummernformat setzen
182 if(pType)
183 ((SwSetExpFieldType*)pType)->SetSeqFormat(pOpt->GetNumType());
185 rSh.UpdateExpFlds( sal_True );
187 rSh.EndAllAction();
189 if ( rSh.IsFrmSelected() )
191 GetEditWin().StopInsFrm();
192 rSh.EnterSelFrmMode();
195 // Kategorie merken
196 String** ppStr = 0;
197 if (eType & nsSelectionType::SEL_GRF)
198 ppStr = &pOldGrfCat;
199 else if( eType & nsSelectionType::SEL_TBL)
200 ppStr = &pOldTabCat;
201 else if( eType & nsSelectionType::SEL_FRM)
202 ppStr = &pOldFrmCat;
203 else if( eType == nsSelectionType::SEL_TXT)
204 ppStr = &pOldFrmCat;
205 else if( eType & nsSelectionType::SEL_DRW)
206 ppStr = &pOldDrwCat;
208 if( ppStr )
210 if( !*ppStr )
211 *ppStr = new String( rName );
212 else
213 **ppStr = rName;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */