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