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