Update ooo320-m1
[ooovba.git] / sw / source / ui / shells / textidx.cxx
blobc3fb70f483774995356148b304fd31f6aa8a9b92
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: textidx.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include <hintids.hxx>
35 #ifndef _MSGBOX_HXX //autogen
36 #include <vcl/msgbox.hxx>
37 #endif
38 #include <sfx2/request.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <svtools/stritem.hxx>
41 #include <svtools/eitem.hxx>
42 #include <svx/sizeitem.hxx>
43 #include <fmtfsize.hxx>
44 #include <fldbas.hxx>
45 #include <uiitems.hxx>
46 #include "viewopt.hxx"
47 #include "cmdid.h"
48 #include "view.hxx"
49 #include "wrtsh.hxx"
50 #include "swundo.hxx" // fuer Undo-Ids
51 #include "textsh.hxx"
52 #include "idxmrk.hxx"
53 #include "cnttab.hxx"
54 #include "toxmgr.hxx"
55 #include "swabstdlg.hxx"
56 #include <index.hrc>
57 #include <globals.hrc>
58 // STATIC DATA -----------------------------------------------------------
60 void SwTextShell::ExecIdx(SfxRequest &rReq)
62 const SfxItemSet *pArgs = rReq.GetArgs();
63 const SfxPoolItem* pItem = 0;
64 USHORT nSlot = rReq.GetSlot();
65 if(pArgs)
66 pArgs->GetItemState(nSlot, FALSE, &pItem );
68 SfxViewFrame* pVFrame = GetView().GetViewFrame();
69 Window *pMDI = &pVFrame->GetWindow();
71 switch( nSlot )
73 case FN_EDIT_AUTH_ENTRY_DLG :
75 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
76 DBG_ASSERT(pFact, "Dialogdiet fail!");
77 VclAbstractDialog* pDlg = pFact->CreateVclAbstractDialog( pMDI, GetShell(), DLG_EDIT_AUTHMARK);
78 DBG_ASSERT(pDlg, "Dialogdiet fail!");
79 pDlg->Execute();
80 delete pDlg;
82 break;
83 case FN_INSERT_AUTH_ENTRY_DLG:
85 // no BASIC support
86 pVFrame->ToggleChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
87 Invalidate(rReq.GetSlot());
89 break;
90 case FN_INSERT_IDX_ENTRY_DLG:
92 pVFrame->ToggleChildWindow(FN_INSERT_IDX_ENTRY_DLG);
93 Invalidate(rReq.GetSlot());
95 break;
96 case FN_EDIT_IDX_ENTRY_DLG:
98 SwTOXMgr aMgr(GetShellPtr());
99 USHORT nRet = RET_OK;
100 if(aMgr.GetTOXMarkCount() > 1)
101 { // Mehrere Marken, welche solls denn sein ?
103 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
104 DBG_ASSERT(pFact, "Dialogdiet fail!");
105 VclAbstractDialog* pMultDlg = pFact->CreateMultiTOXMarkDlg( DLG_MULTMRK,
106 pMDI, aMgr);
107 DBG_ASSERT(pMultDlg, "Dialogdiet fail!");
108 nRet = pMultDlg->Execute();
109 delete pMultDlg;
111 if( nRet == RET_OK)
113 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
114 DBG_ASSERT(pFact, "Dialogdiet fail!");
115 VclAbstractDialog* pDlg = pFact->CreateIndexMarkModalDlg( DLG_EDIT_IDXMARK, pMDI, GetShell(), aMgr.GetCurTOXMark() );
116 DBG_ASSERT(pDlg, "Dialogdiet fail!");
117 pDlg->Execute();
118 delete pDlg;
120 break;
122 case FN_IDX_MARK_TO_IDX:
124 GetShell().GotoTOXMarkBase();
125 break;
127 case FN_INSERT_MULTI_TOX:
129 SfxItemSet aSet(GetPool(),
130 RES_COL, RES_COL,
131 RES_BACKGROUND, RES_BACKGROUND,
132 RES_FRM_SIZE, RES_FRM_SIZE,
133 SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
134 RES_LR_SPACE, RES_LR_SPACE,
135 FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
136 0 );
137 SwWrtShell& rSh = GetShell();
138 SwRect aRect;
139 rSh.CalcBoundRect(aRect, FLY_IN_CNTNT);
141 long nWidth = aRect.Width();
142 aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
143 // Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
144 aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
145 const SwTOXBase* pCurTOX = 0;
146 BOOL bGlobal = FALSE;
147 if(pItem)
149 pCurTOX = (const SwTOXBase* )((SwPtrItem*)pItem)->GetValue();
150 bGlobal = TRUE;
152 else
153 pCurTOX = rSh.GetCurTOX();
154 if(pCurTOX)
156 const SfxItemSet* pSet = pCurTOX->GetAttrSet();
157 if(pSet)
158 aSet.Put(*pSet);
160 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
161 DBG_ASSERT(pFact, "Dialogdiet fail!");
162 AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
163 pMDI, aSet, rSh, (SwTOXBase* )pCurTOX,
164 USHRT_MAX, bGlobal);
165 DBG_ASSERT(pDlg, "Dialogdiet fail!");
166 pDlg->Execute();
167 delete pDlg;
169 break;
170 case FN_REMOVE_CUR_TOX:
172 SwWrtShell& rSh = GetShell();
173 const SwTOXBase* pBase = rSh.GetCurTOX();
174 DBG_ASSERT(pBase, "no TOXBase to remove");
175 if( pBase )
176 rSh.DeleteTOX(*pBase, TRUE);
178 break;
179 default:
180 ASSERT(!this, falscher Dispatcher);
181 return;
186 void SwTextShell::GetIdxState(SfxItemSet &rSet)
188 SwWrtShell& rSh = GetShell();
189 SfxViewFrame* pVFrame = GetView().GetViewFrame();
190 SwInsertIdxMarkWrapper *pIdxMrk = (SwInsertIdxMarkWrapper*)
191 pVFrame->GetChildWindow(FN_INSERT_IDX_ENTRY_DLG);
193 SfxChildWindow* pAuthMark = pVFrame->GetChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
195 const BOOL bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
196 const SwTOXBase* pBase = 0;
197 if( bHtmlMode || 0 != ( pBase = rSh.GetCurTOX()) )
199 if( pBase )
201 if(pBase->IsTOXBaseInReadonly())
203 rSet.DisableItem( FN_INSERT_MULTI_TOX );
207 rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG );
208 rSet.DisableItem( FN_EDIT_AUTH_ENTRY_DLG );
210 if(!pIdxMrk)
211 rSet.DisableItem( FN_INSERT_IDX_ENTRY_DLG );
212 else
213 rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG, TRUE));
215 if(!pAuthMark)
216 rSet.DisableItem( FN_INSERT_AUTH_ENTRY_DLG );
217 else
218 rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, TRUE));
221 else //if( SFX_ITEM_UNKNOWN != rSet.GetItemState( FN_EDIT_IDX_ENTRY_DLG ))
224 BOOL bEnableEdit = TRUE;
225 BOOL bInReadonly = rSh.HasReadonlySel();
226 if( rSh.HasSelection() || bInReadonly)
227 bEnableEdit = FALSE;
228 else
230 SwTOXMarks aArr;
231 rSh.GetCurTOXMarks( aArr );
232 if( !aArr.Count())
233 bEnableEdit = FALSE;
236 if(!bEnableEdit)
237 rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG );
239 if(bInReadonly)
241 rSet.DisableItem(FN_INSERT_IDX_ENTRY_DLG);
242 rSet.DisableItem( FN_INSERT_MULTI_TOX );
244 else
245 rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG,
246 0 != pIdxMrk));
249 SwField* pField = rSh.GetCurFld();
251 if(bInReadonly)
252 rSet.DisableItem(FN_INSERT_AUTH_ENTRY_DLG);
253 else
254 rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, 0 != pAuthMark));
256 if( bInReadonly || !pField ||
257 pField->GetTyp()->Which() != RES_AUTHORITY)
258 rSet.DisableItem(FN_EDIT_AUTH_ENTRY_DLG);
259 rSet.DisableItem(FN_REMOVE_CUR_TOX);
263 // -----------------------------------------------------------------------