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