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