xref: /aoo41x/main/sw/source/ui/shells/textidx.cxx (revision 69a74367)
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 #include <hintids.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <sfx2/request.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svl/stritem.hxx>
32 #include <svl/eitem.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include <fmtfsize.hxx>
35 #include <fldbas.hxx>
36 #include <uiitems.hxx>
37 #include "viewopt.hxx"
38 #include "cmdid.h"
39 #include "view.hxx"
40 #include "wrtsh.hxx"
41 #include "swundo.hxx"               	// fuer Undo-Ids
42 #include "textsh.hxx"
43 #include "idxmrk.hxx"
44 #include "cnttab.hxx"
45 #include "toxmgr.hxx"
46 #include "swabstdlg.hxx"
47 #include <index.hrc>
48 #include <globals.hrc>
49 
50 
51 // STATIC DATA -----------------------------------------------------------
52 
ExecIdx(SfxRequest & rReq)53 void SwTextShell::ExecIdx(SfxRequest &rReq)
54 {
55 	const SfxItemSet *pArgs = rReq.GetArgs();
56 	const SfxPoolItem* pItem = 0;
57 	sal_uInt16 nSlot = rReq.GetSlot();
58 	if(pArgs)
59 	   pArgs->GetItemState(nSlot, sal_False, &pItem );
60 
61 	SfxViewFrame* pVFrame = GetView().GetViewFrame();
62 	Window *pMDI = &pVFrame->GetWindow();
63 
64 	switch( nSlot )
65 	{
66 		case FN_EDIT_AUTH_ENTRY_DLG :
67 		{
68 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
69             DBG_ASSERT(pFact, "Dialogdiet fail!");
70             VclAbstractDialog* pDlg = pFact->CreateVclAbstractDialog( pMDI, GetShell(), DLG_EDIT_AUTHMARK);
71             DBG_ASSERT(pDlg, "Dialogdiet fail!");
72 			pDlg->Execute();
73 			delete pDlg;
74 		}
75 		break;
76 		case FN_INSERT_AUTH_ENTRY_DLG:
77 		{
78 			// no BASIC support
79 			pVFrame->ToggleChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
80 			Invalidate(rReq.GetSlot());
81 		}
82 		break;
83 		case FN_INSERT_IDX_ENTRY_DLG:
84 		{
85 			pVFrame->ToggleChildWindow(FN_INSERT_IDX_ENTRY_DLG);
86 			Invalidate(rReq.GetSlot());
87 		}
88 		break;
89 		case FN_EDIT_IDX_ENTRY_DLG:
90 		{
91 			SwTOXMgr aMgr(GetShellPtr());
92 			sal_uInt16 nRet = RET_OK;
93 			if(aMgr.GetTOXMarkCount() > 1)
94 			{	// Mehrere Marken, welche solls denn sein ?
95 				//
96 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
97                 DBG_ASSERT(pFact, "Dialogdiet fail!");
98                 VclAbstractDialog* pMultDlg = pFact->CreateMultiTOXMarkDlg( DLG_MULTMRK,
99 														pMDI, aMgr);
100                 DBG_ASSERT(pMultDlg, "Dialogdiet fail!");
101 				nRet = pMultDlg->Execute();
102 				delete pMultDlg;
103 			}
104 			if(	nRet == RET_OK)
105 			{
106 				SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
107                 DBG_ASSERT(pFact, "Dialogdiet fail!");
108                 VclAbstractDialog* pDlg = pFact->CreateIndexMarkModalDlg( DLG_EDIT_IDXMARK, pMDI, GetShell(), aMgr.GetCurTOXMark() );
109                 DBG_ASSERT(pDlg, "Dialogdiet fail!");
110 				pDlg->Execute();
111 				delete pDlg;
112 			}
113 			break;
114 		}
115 		case FN_IDX_MARK_TO_IDX:
116 		{
117 			GetShell().GotoTOXMarkBase();
118 			break;
119 		}
120 		case FN_INSERT_MULTI_TOX:
121 		{
122 			SfxItemSet aSet(GetPool(),
123 							RES_COL, RES_COL,
124 							RES_BACKGROUND, RES_BACKGROUND,
125 							RES_FRM_SIZE, RES_FRM_SIZE,
126 							SID_ATTR_PAGE_SIZE, SID_ATTR_PAGE_SIZE,
127 							RES_LR_SPACE, RES_LR_SPACE,
128 							FN_PARAM_TOX_TYPE, FN_PARAM_TOX_TYPE,
129 							0	);
130 			SwWrtShell& rSh = GetShell();
131 			SwRect aRect;
132             rSh.CalcBoundRect(aRect, FLY_AS_CHAR);
133 
134 			long nWidth = aRect.Width();
135 			aSet.Put(SwFmtFrmSize(ATT_VAR_SIZE, nWidth));
136 			// Hoehe=Breite fuer konsistentere Vorschau (analog zu Bereich bearbeiten)
137 			aSet.Put(SvxSizeItem(SID_ATTR_PAGE_SIZE, Size(nWidth, nWidth)));
138 			const SwTOXBase* pCurTOX = 0;
139 			sal_Bool bGlobal = sal_False;
140 			if(pItem)
141 			{
142 				pCurTOX = (const SwTOXBase* )((SwPtrItem*)pItem)->GetValue();
143 				bGlobal = sal_True;
144 			}
145 			else
146 				pCurTOX = rSh.GetCurTOX();
147 			if(pCurTOX)
148 			{
149 				const SfxItemSet* pSet = pCurTOX->GetAttrSet();
150 				if(pSet)
151 					aSet.Put(*pSet);
152 			}
153 			SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
154             DBG_ASSERT(pFact, "Dialogdiet fail!");
155             AbstractMultiTOXTabDialog* pDlg = pFact->CreateMultiTOXTabDialog( DLG_MULTI_TOX,
156 														pMDI, aSet, rSh, (SwTOXBase* )pCurTOX,
157 														USHRT_MAX, bGlobal);
158             DBG_ASSERT(pDlg, "Dialogdiet fail!");
159 			pDlg->Execute();
160 			delete pDlg;
161 		}
162 		break;
163 		case FN_REMOVE_CUR_TOX:
164 		{
165 			SwWrtShell& rSh = GetShell();
166 			const SwTOXBase* pBase = rSh.GetCurTOX();
167 			DBG_ASSERT(pBase, "no TOXBase to remove");
168 			if( pBase )
169 				rSh.DeleteTOX(*pBase, sal_True);
170 		}
171 		break;
172 		default:
173 			ASSERT(!this, falscher Dispatcher);
174 			return;
175 	}
176 }
177 
178 
GetIdxState(SfxItemSet & rSet)179 void SwTextShell::GetIdxState(SfxItemSet &rSet)
180 {
181 	SwWrtShell& rSh = GetShell();
182 	SfxViewFrame* pVFrame = GetView().GetViewFrame();
183 	SwInsertIdxMarkWrapper *pIdxMrk = (SwInsertIdxMarkWrapper*)
184 						pVFrame->GetChildWindow(FN_INSERT_IDX_ENTRY_DLG);
185 
186 	SfxChildWindow* pAuthMark = pVFrame->GetChildWindow(FN_INSERT_AUTH_ENTRY_DLG);
187 
188 	const sal_Bool bHtmlMode = 0 != ::GetHtmlMode( GetView().GetDocShell() );
189 	const SwTOXBase* pBase = 0;
190 	if( bHtmlMode || 0 != ( pBase = rSh.GetCurTOX()) )
191 	{
192 		if( pBase )
193 		{
194 			if(pBase->IsTOXBaseInReadonly())
195 			{
196 				rSet.DisableItem( FN_INSERT_MULTI_TOX );
197 			}
198 		}
199 
200 		rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG );
201 		rSet.DisableItem( FN_EDIT_AUTH_ENTRY_DLG );
202 
203 		if(!pIdxMrk)
204 			rSet.DisableItem( FN_INSERT_IDX_ENTRY_DLG );
205 		else
206 			rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG, sal_True));
207 
208 		if(!pAuthMark)
209 			rSet.DisableItem( FN_INSERT_AUTH_ENTRY_DLG );
210 		else
211 			rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, sal_True));
212 
213 	}
214     else if ( rSh.CrsrInsideInputFld() )
215     {
216         rSet.DisableItem( FN_INSERT_IDX_ENTRY_DLG );
217         rSet.DisableItem( FN_INSERT_AUTH_ENTRY_DLG );
218         rSet.DisableItem( FN_EDIT_AUTH_ENTRY_DLG );
219         rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG );
220         rSet.DisableItem( FN_INSERT_MULTI_TOX );
221         rSet.DisableItem( FN_REMOVE_CUR_TOX );
222     }
223 	else
224 	{
225 
226 		sal_Bool bEnableEdit = sal_True;
227 		sal_Bool bInReadonly = rSh.HasReadonlySel();
228 		if( rSh.HasSelection() || bInReadonly)
229 			bEnableEdit = sal_False;
230 		else
231 		{
232 			SwTOXMarks aArr;
233 			rSh.GetCurTOXMarks( aArr );
234 			if( !aArr.Count())
235 				bEnableEdit = sal_False;
236 		}
237 
238 		if(!bEnableEdit)
239 			rSet.DisableItem( FN_EDIT_IDX_ENTRY_DLG );
240 
241 		if(bInReadonly)
242 		{
243 			rSet.DisableItem(FN_INSERT_IDX_ENTRY_DLG);
244 			rSet.DisableItem( FN_INSERT_MULTI_TOX );
245 		}
246 		else
247 			rSet.Put(SfxBoolItem(FN_INSERT_IDX_ENTRY_DLG,
248 									0 != pIdxMrk));
249 
250 
251 		SwField* pField = rSh.GetCurFld();
252 
253 		if(bInReadonly)
254 			rSet.DisableItem(FN_INSERT_AUTH_ENTRY_DLG);
255 		else
256 			rSet.Put(SfxBoolItem(FN_INSERT_AUTH_ENTRY_DLG, 0 != pAuthMark));
257 
258 		if(	bInReadonly || !pField ||
259 			pField->GetTyp()->Which() != RES_AUTHORITY)
260 			rSet.DisableItem(FN_EDIT_AUTH_ENTRY_DLG);
261 		rSet.DisableItem(FN_REMOVE_CUR_TOX);
262 	}
263 }
264 
265 // -----------------------------------------------------------------------
266 
267