xref: /trunk/main/sw/source/ui/uiview/viewdlg2.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <sfx2/request.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/objface.hxx>
35 
36 #include <fldmgr.hxx>
37 #include <expfld.hxx>
38 #include <modcfg.hxx>
39 
40 #include <tools/shl.hxx>
41 
42 #include "swmodule.hxx"
43 #include "view.hxx"
44 #include "wview.hxx"
45 #include "wrtsh.hxx"
46 #include "cmdid.h"
47 #include "caption.hxx"
48 #include "poolfmt.hxx"
49 #include "edtwin.hxx"
50 #include <SwStyleNameMapper.hxx>
51 
52 #include "swabstdlg.hxx"
53 #include "frmui.hrc"
54 #include "misc.hrc"
55 
56 #include "view.hrc"
57 
58 extern String* pOldGrfCat;
59 extern String* pOldTabCat;
60 extern String* pOldFrmCat;
61 extern String* pOldDrwCat;
62 
63 /* -----------------06.11.98 13:45-------------------
64  *
65  * --------------------------------------------------*/
66 
67 void SwView::ExecDlgExt(SfxRequest &rReq)
68 {
69 	Window *pMDI = &GetViewFrame()->GetWindow();
70 
71 	switch ( rReq.GetSlot() )
72 	{
73 		case FN_INSERT_CAPTION:
74 		{
75             SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
76             DBG_ASSERT(pFact, "SwAbstractDialogFactory fail!");
77 
78             VclAbstractDialog* pDialog = pFact->CreateSwCaptionDialog( pMDI, *this, DLG_CAPTION );
79             DBG_ASSERT(pDialog, "Dialogdiet fail!");
80 			if ( pDialog )
81 			{
82 				pDialog->Execute();
83 				delete pDialog;
84 			}
85 			break;
86 		}
87 		case  FN_EDIT_FOOTNOTE:
88 		{
89 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
90             DBG_ASSERT(pFact, "Dialogdiet fail!");
91             AbstractInsFootNoteDlg* pDlg = pFact->CreateInsFootNoteDlg( DLG_INS_FOOTNOTE,
92 														pMDI, *pWrtShell, sal_True );
93             DBG_ASSERT(pDlg, "Dialogdiet fail!");
94 
95             pDlg->SetHelpId(GetStaticInterface()->GetSlot(FN_EDIT_FOOTNOTE)->GetCommand());
96             pDlg->SetText( SW_RESSTR(STR_EDIT_FOOTNOTE) );
97 			pDlg->Execute();
98 			delete pDlg;
99 			break;
100 		}
101 	}
102 }
103 
104 /* -----------------06.11.98 14:53-------------------
105  *
106  * --------------------------------------------------*/
107 
108 void SwView::AutoCaption(const sal_uInt16 nType, const SvGlobalName *pOleId)
109 {
110 	SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
111 
112 	sal_Bool bWeb = 0 != PTR_CAST(SwWebView, this);
113 	if (pModOpt->IsInsWithCaption(bWeb))
114 	{
115 		const InsCaptionOpt *pOpt = pModOpt->GetCapOption(bWeb, (SwCapObjType)nType, pOleId);
116 		if (pOpt && pOpt->UseCaption() == sal_True)
117 			InsertCaption(pOpt);
118 	}
119 }
120 
121 /* -----------------06.11.98 12:58-------------------
122  *
123  * --------------------------------------------------*/
124 
125 void SwView::InsertCaption(const InsCaptionOpt *pOpt)
126 {
127 	if (!pOpt)
128 		return;
129 
130 	const String &rName = pOpt->GetCategory();
131 
132 	// Existiert Pool-Vorlage gleichen Namens?
133 	SwWrtShell &rSh = GetWrtShell();
134     if(rName.Len())
135     {
136         sal_uInt16 nPoolId = SwStyleNameMapper::GetPoolIdFromUIName(rName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL);
137         if( USHRT_MAX != nPoolId )
138             rSh.GetTxtCollFromPool(nPoolId);
139             // Pool-Vorlage existiert nicht: Existiert sie am Dokument?
140         else if( !rSh.GetParaStyle(rName) )
141         {
142             // Sie existiert auch nicht am Dokument: erzeugen
143             SwTxtFmtColl* pDerivedFrom = rSh.GetTxtCollFromPool(RES_POOLCOLL_LABEL);
144             rSh.MakeTxtFmtColl(rName, pDerivedFrom);
145         }
146     }
147 
148 	SelectionType eType = rSh.GetSelectionType();
149 	if (eType & nsSelectionType::SEL_OLE)
150 		eType = nsSelectionType::SEL_GRF;
151 
152 	// SwLabelType
153     const SwLabelType eT = eType & nsSelectionType::SEL_TBL ? LTYPE_TABLE :
154 					  eType & nsSelectionType::SEL_FRM ? LTYPE_FLY :
155 					  eType == nsSelectionType::SEL_TXT ? LTYPE_FLY :
156 					  eType & nsSelectionType::SEL_DRW ? LTYPE_DRAW :
157 													LTYPE_OBJECT;
158 
159 	SwFldMgr aMgr(&rSh);
160 	SwSetExpFieldType* pFldType =
161 			(SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
162     if (!pFldType && rName.Len() )
163 	{
164 		// Neuen Feldtypen erzeugen
165 		SwSetExpFieldType aSwSetExpFieldType(rSh.GetDoc(), rName, nsSwGetSetExpType::GSE_SEQ);
166 		aMgr.InsertFldType(aSwSetExpFieldType);
167 		pFldType = (SwSetExpFieldType*)aMgr.GetFldType(RES_SETEXPFLD, rName);
168 	}
169 
170 	if (!pOpt->IgnoreSeqOpts())
171 	{
172 		if (pFldType)
173 		{
174 			pFldType->SetDelimiter(pOpt->GetSeparator());
175             pFldType->SetOutlineLvl( static_cast< sal_uInt8 >(pOpt->GetLevel()) );
176 		}
177 	}
178 
179     sal_uInt16       nID    = USHRT_MAX;
180 	SwFieldType* pType 	= 0;
181 	const sal_uInt16 nCount = aMgr.GetFldTypeCount();
182     if( rName.Len() )
183     {
184         for (sal_uInt16 i = 0; i < nCount; ++i)
185         {
186             pType = aMgr.GetFldType(USHRT_MAX, i);
187             String aTmpName( pType->GetName() );
188             if (aTmpName == rName && pType->Which() == RES_SETEXPFLD)
189             {
190                 nID = i;
191                 break;
192             }
193         }
194     }
195 	rSh.StartAllAction();
196 
197     GetWrtShell().InsertLabel( eT,
198                                 pOpt->GetCaption(),
199                                 !pOpt->IgnoreSeqOpts() ? aEmptyStr : pOpt->GetSeparator(),
200                                 pOpt->GetNumSeparator(),
201 								!pOpt->GetPos(),
202 								nID,
203                                 pOpt->GetCharacterStyle(),
204                                 pOpt->CopyAttributes() );
205 	// Nummernformat setzen
206     if(pType)
207 	    ((SwSetExpFieldType*)pType)->SetSeqFormat(pOpt->GetNumType());
208 
209 	rSh.UpdateExpFlds( sal_True );
210 
211 	rSh.EndAllAction();
212 
213 	if ( rSh.IsFrmSelected() )
214 	{
215 		GetEditWin().StopInsFrm();
216 		rSh.EnterSelFrmMode();
217 	}
218 
219 	// Kategorie merken
220 	String** ppStr = 0;
221 	if (eType & nsSelectionType::SEL_GRF)
222 		ppStr = &pOldGrfCat;
223 	else if( eType & nsSelectionType::SEL_TBL)
224 		ppStr = &pOldTabCat;
225 	else if( eType & nsSelectionType::SEL_FRM)
226 		ppStr = &pOldFrmCat;
227 	else if( eType == nsSelectionType::SEL_TXT)
228 		ppStr = &pOldFrmCat;
229 	else if( eType & nsSelectionType::SEL_DRW)
230 		ppStr = &pOldDrwCat;
231 
232 	if( ppStr )
233 	{
234 		if( !*ppStr )
235 			*ppStr = new String( rName );
236 		else
237 			**ppStr = rName;
238 	}
239 }
240 
241 
242