xref: /aoo41x/main/sc/source/ui/view/tabcont.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
32cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
33cdf0e10cSrcweir #include <sfx2/docfile.hxx>
34cdf0e10cSrcweir #include <vcl/sound.hxx>
35cdf0e10cSrcweir #include <tools/urlobj.hxx>
36cdf0e10cSrcweir #include <vcl/svapp.hxx>
37cdf0e10cSrcweir #include "tabcont.hxx"
38cdf0e10cSrcweir #include "tabvwsh.hxx"
39cdf0e10cSrcweir #include "docsh.hxx"
40cdf0e10cSrcweir #include "scmod.hxx"
41cdf0e10cSrcweir #include "scresid.hxx"
42cdf0e10cSrcweir #include "sc.hrc"
43cdf0e10cSrcweir #include "globstr.hrc"
44cdf0e10cSrcweir #include "transobj.hxx"
45cdf0e10cSrcweir #include "clipparam.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //==================================================================
51cdf0e10cSrcweir 
ScTabControl(Window * pParent,ScViewData * pData)52cdf0e10cSrcweir ScTabControl::ScTabControl( Window* pParent, ScViewData* pData ) :
53cdf0e10cSrcweir 			TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL |
54cdf0e10cSrcweir 									WB_RANGESELECT | WB_MULTISELECT | WB_DRAG | WB_SIZEABLE ) ),
55cdf0e10cSrcweir 			DropTargetHelper( this ),
56cdf0e10cSrcweir 			DragSourceHelper( this ),
57cdf0e10cSrcweir 			pViewData( pData ),
58cdf0e10cSrcweir             nMouseClickPageId( TabBar::PAGE_NOT_FOUND ),
59cdf0e10cSrcweir             nSelPageIdByMouse( TabBar::PAGE_NOT_FOUND ),
60cdf0e10cSrcweir             bErrorShown( sal_False )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	String aString;
65cdf0e10cSrcweir     Color aTabBgColor;
66cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
67cdf0e10cSrcweir 	for (SCTAB i=0; i<nCount; i++)
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		if (pDoc->IsVisible(i))
70cdf0e10cSrcweir 		{
71cdf0e10cSrcweir 			if (pDoc->GetName(i,aString))
72cdf0e10cSrcweir 			{
73cdf0e10cSrcweir 				if ( pDoc->IsScenario(i) )
74cdf0e10cSrcweir 					InsertPage( static_cast<sal_uInt16>(i)+1, aString, TPB_SPECIAL );
75cdf0e10cSrcweir 				else
76cdf0e10cSrcweir 					InsertPage( static_cast<sal_uInt16>(i)+1, aString );
77cdf0e10cSrcweir                 if ( !pDoc->IsDefaultTabBgColor(i) )
78cdf0e10cSrcweir                 {
79cdf0e10cSrcweir                     aTabBgColor = pDoc->GetTabBgColor(i);
80cdf0e10cSrcweir                     SetTabBgColor( static_cast<sal_uInt16>(i)+1, aTabBgColor );
81cdf0e10cSrcweir                 }
82cdf0e10cSrcweir 			}
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	SetSizePixel( Size(SC_TABBAR_DEFWIDTH, 0) );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	SetSplitHdl( LINK( pViewData->GetView(), ScTabView, TabBarResize ) );
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	EnableEditMode();
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
~ScTabControl()95cdf0e10cSrcweir ScTabControl::~ScTabControl()
96cdf0e10cSrcweir {
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
GetMaxId() const99cdf0e10cSrcweir sal_uInt16 ScTabControl::GetMaxId() const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	sal_uInt16 nVisCnt = GetPageCount();
102cdf0e10cSrcweir 	if (nVisCnt)
103cdf0e10cSrcweir 		return GetPageId(nVisCnt-1);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	return 0;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
GetPrivatDropPos(const Point & rPos)108cdf0e10cSrcweir SCTAB ScTabControl::GetPrivatDropPos(const Point& rPos )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	sal_uInt16 nPos = ShowDropPos(rPos);
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	SCTAB nRealPos = static_cast<SCTAB>(nPos);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	if(nPos !=0 )
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir 		ScDocument* pDoc = pViewData->GetDocument();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		SCTAB nCount = pDoc->GetTableCount();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 		sal_uInt16 nViewPos=0;
121cdf0e10cSrcweir 		nRealPos = nCount;
122cdf0e10cSrcweir 		for (SCTAB i=0; i<nCount; i++)
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			if (pDoc->IsVisible(i))
125cdf0e10cSrcweir 			{
126cdf0e10cSrcweir 				nViewPos++;
127cdf0e10cSrcweir 				if(nViewPos==nPos)
128cdf0e10cSrcweir 				{
129cdf0e10cSrcweir 					SCTAB j;
130cdf0e10cSrcweir 					for (j=i+1; j<nCount; j++)
131cdf0e10cSrcweir 					{
132cdf0e10cSrcweir 						if (pDoc->IsVisible(j))
133cdf0e10cSrcweir 						{
134cdf0e10cSrcweir 							break;
135cdf0e10cSrcweir 						}
136cdf0e10cSrcweir 					}
137cdf0e10cSrcweir 					nRealPos =j;
138cdf0e10cSrcweir 					break;
139cdf0e10cSrcweir 				}
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 	return nRealPos ;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)146cdf0e10cSrcweir void ScTabControl::MouseButtonDown( const MouseEvent& rMEvt )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
149cdf0e10cSrcweir 	if ( !pScMod->IsModalMode() && !pScMod->IsFormulaMode() && !IsInEditMode() )
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		//	View aktivieren
152cdf0e10cSrcweir 		pViewData->GetViewShell()->SetActive();			// Appear und SetViewFrame
153cdf0e10cSrcweir 		pViewData->GetView()->ActiveGrabFocus();
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     /*  #47745# Click into free area -> insert new sheet (like in Draw).
157cdf0e10cSrcweir         Needing clean left click without modifiers (may be context menu).
158cdf0e10cSrcweir         #106948# Remember clicks to all pages, to be able to move mouse pointer later. */
159cdf0e10cSrcweir     if( rMEvt.IsLeft() && (rMEvt.GetModifier() == 0) )
160cdf0e10cSrcweir         nMouseClickPageId = GetPageId( rMEvt.GetPosPixel() );
161cdf0e10cSrcweir     else
162cdf0e10cSrcweir         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	TabBar::MouseButtonDown( rMEvt );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rMEvt)167cdf0e10cSrcweir void ScTabControl::MouseButtonUp( const MouseEvent& rMEvt )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     // mouse button down and up on same page?
172cdf0e10cSrcweir     if( nMouseClickPageId != GetPageId( aPos ) )
173cdf0e10cSrcweir         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     if ( rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && nMouseClickPageId != 0 && nMouseClickPageId != TAB_PAGE_NOTFOUND )
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         SfxDispatcher* pDispatcher = pViewData->GetViewShell()->GetViewFrame()->GetDispatcher();
178cdf0e10cSrcweir         pDispatcher->Execute( FID_TAB_MENU_RENAME, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir     if( nMouseClickPageId == 0 )
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         // Click in the area next to the existing tabs:
184cdf0e10cSrcweir         // #i70320# if several sheets are selected, deselect all ecxept the current sheet,
185cdf0e10cSrcweir         // otherwise add new sheet
186cdf0e10cSrcweir         sal_uInt16 nSlot = ( GetSelectPageCount() > 1 ) ? FID_TAB_DESELECTALL : FID_INS_TABLE;
187cdf0e10cSrcweir         SfxDispatcher* pDispatcher = pViewData->GetViewShell()->GetViewFrame()->GetDispatcher();
188cdf0e10cSrcweir         pDispatcher->Execute( nSlot, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
189cdf0e10cSrcweir         // forget page ID, to be really sure that the dialog is not called twice
190cdf0e10cSrcweir         nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
191cdf0e10cSrcweir     }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	TabBar::MouseButtonUp( rMEvt );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
Select()196cdf0e10cSrcweir void ScTabControl::Select()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     /*  Remember last clicked page ID. */
199cdf0e10cSrcweir     nSelPageIdByMouse = nMouseClickPageId;
200cdf0e10cSrcweir     /*  Reset nMouseClickPageId, so that next Select() call may invalidate
201cdf0e10cSrcweir         nSelPageIdByMouse (i.e. if called from keyboard). */
202cdf0e10cSrcweir     nMouseClickPageId = TabBar::PAGE_NOT_FOUND;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
205cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
206cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
207cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
208cdf0e10cSrcweir 	SCTAB i;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 	if ( pScMod->IsTableLocked() )		// darf jetzt nicht umgeschaltet werden ?
211cdf0e10cSrcweir 	{
212cdf0e10cSrcweir 		//	den alten Zustand des TabControls wiederherstellen:
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
215cdf0e10cSrcweir 			SelectPage( static_cast<sal_uInt16>(i)+1, rMark.GetTableSelect(i) );
216cdf0e10cSrcweir 		SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 		Sound::Beep();
219cdf0e10cSrcweir 		return;
220cdf0e10cSrcweir 	}
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 	sal_uInt16 nCurId = GetCurPageId();
223cdf0e10cSrcweir 	if (!nCurId) return;			// kann vorkommen, wenn bei Excel-Import alles versteckt ist
224cdf0e10cSrcweir 	sal_uInt16 nPage = nCurId - 1;
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	// OLE-inplace deaktivieren
227cdf0e10cSrcweir 	if ( nPage != static_cast<sal_uInt16>(pViewData->GetTabNo()) )
228cdf0e10cSrcweir 		pViewData->GetView()->DrawMarkListHasChanged();
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	//	InputEnterHandler nur wenn nicht Referenzeingabe
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	sal_Bool bRefMode = pScMod->IsFormulaMode();
233cdf0e10cSrcweir 	if (!bRefMode)
234cdf0e10cSrcweir 		pScMod->InputEnterHandler();
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	for (i=0; i<nCount; i++)
237cdf0e10cSrcweir 		rMark.SelectTable( i, IsPageSelected(static_cast<sal_uInt16>(i)+1) );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir /*		Markierungen werden per Default nicht pro Tabelle gehalten
240cdf0e10cSrcweir 	sal_uInt16 nSelCnt = GetSelectPageCount();
241cdf0e10cSrcweir 	if (nSelCnt>1)
242cdf0e10cSrcweir 		pDoc->ExtendMarksFromTable( nPage );
243cdf0e10cSrcweir */
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 	SfxDispatcher& rDisp = pViewData->GetDispatcher();
246cdf0e10cSrcweir 	if (rDisp.IsLocked())
247cdf0e10cSrcweir 		pViewData->GetView()->SetTabNo( static_cast<SCTAB>(nPage) );
248cdf0e10cSrcweir 	else
249cdf0e10cSrcweir 	{
250cdf0e10cSrcweir 		//	Tabelle fuer Basic ist 1-basiert
251cdf0e10cSrcweir 		SfxUInt16Item aItem( SID_CURRENTTAB, nPage + 1 );
252cdf0e10cSrcweir 		rDisp.Execute( SID_CURRENTTAB, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
253cdf0e10cSrcweir 								&aItem, (void*) NULL );
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	SfxBindings& rBind = pViewData->GetBindings();
257cdf0e10cSrcweir 	rBind.Invalidate( FID_FILL_TAB );
258cdf0e10cSrcweir     rBind.Invalidate( FID_TAB_DESELECTALL );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	rBind.Invalidate( FID_INS_TABLE );
261cdf0e10cSrcweir 	rBind.Invalidate( FID_TAB_APPEND );
262cdf0e10cSrcweir 	rBind.Invalidate( FID_TAB_MOVE );
263cdf0e10cSrcweir 	rBind.Invalidate( FID_TAB_RENAME );
264cdf0e10cSrcweir 	rBind.Invalidate( FID_DELETE_TABLE );
265cdf0e10cSrcweir 	rBind.Invalidate( FID_TABLE_SHOW );
266cdf0e10cSrcweir 	rBind.Invalidate( FID_TABLE_HIDE );
267cdf0e10cSrcweir     rBind.Invalidate( FID_TAB_SET_TAB_BG_COLOR );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 		//	SetReference nur wenn der Konsolidieren-Dialog offen ist
270cdf0e10cSrcweir 		//	(fuer Referenzen ueber mehrere Tabellen)
271cdf0e10cSrcweir 		//	bei anderen gibt das nur unnoetiges Gezappel
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	if ( bRefMode && pViewData->GetRefType() == SC_REFTYPE_REF )
274cdf0e10cSrcweir 		if ( pViewData->GetViewShell()->GetViewFrame()->HasChildWindow(SID_OPENDLG_CONSOLIDATE) )
275cdf0e10cSrcweir 		{
276cdf0e10cSrcweir 			ScRange aRange(
277cdf0e10cSrcweir 					pViewData->GetRefStartX(), pViewData->GetRefStartY(), pViewData->GetRefStartZ(),
278cdf0e10cSrcweir 					pViewData->GetRefEndX(), pViewData->GetRefEndY(), pViewData->GetRefEndZ() );
279cdf0e10cSrcweir 			pScMod->SetReference( aRange, pDoc, &rMark );
280cdf0e10cSrcweir 			pScMod->EndReference();						// wegen Auto-Hide
281cdf0e10cSrcweir 		}
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
UpdateStatus()284cdf0e10cSrcweir void ScTabControl::UpdateStatus()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
287cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
288cdf0e10cSrcweir 	sal_Bool bActive = pViewData->IsActive();
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	SCTAB nCount = pDoc->GetTableCount();
291cdf0e10cSrcweir 	SCTAB i;
292cdf0e10cSrcweir 	String aString;
293cdf0e10cSrcweir 	SCTAB nMaxCnt = Max( nCount, static_cast<SCTAB>(GetMaxId()) );
294cdf0e10cSrcweir     Color aTabBgColor;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	sal_Bool bModified = sal_False;										// Tabellen-Namen
297cdf0e10cSrcweir 	for (i=0; i<nMaxCnt && !bModified; i++)
298cdf0e10cSrcweir 	{
299cdf0e10cSrcweir 		if (pDoc->IsVisible(i))
300cdf0e10cSrcweir         {
301cdf0e10cSrcweir 			pDoc->GetName(i,aString);
302cdf0e10cSrcweir             aTabBgColor = pDoc->GetTabBgColor(i);
303cdf0e10cSrcweir         }
304cdf0e10cSrcweir 		else
305cdf0e10cSrcweir         {
306cdf0e10cSrcweir 			aString.Erase();
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir         if ( (GetPageText(static_cast<sal_uInt16>(i)+1) != aString) || (GetTabBgColor(static_cast<sal_uInt16>(i)+1) != aTabBgColor) )
310cdf0e10cSrcweir 			bModified = sal_True;
311cdf0e10cSrcweir 	}
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	if (bModified)
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		Clear();
316cdf0e10cSrcweir 		for (i=0; i<nCount; i++)
317cdf0e10cSrcweir 		{
318cdf0e10cSrcweir 			if (pDoc->IsVisible(i))
319cdf0e10cSrcweir 			{
320cdf0e10cSrcweir 				if (pDoc->GetName(i,aString))
321cdf0e10cSrcweir 				{
322cdf0e10cSrcweir 					if ( pDoc->IsScenario(i) )
323cdf0e10cSrcweir 						InsertPage( static_cast<sal_uInt16>(i)+1, aString, TPB_SPECIAL );
324cdf0e10cSrcweir 					else
325cdf0e10cSrcweir 						InsertPage( static_cast<sal_uInt16>(i)+1, aString );
326cdf0e10cSrcweir                     if ( !pDoc->IsDefaultTabBgColor(i) )
327cdf0e10cSrcweir                     {
328cdf0e10cSrcweir                         aTabBgColor = pDoc->GetTabBgColor(i);
329cdf0e10cSrcweir                         SetTabBgColor( static_cast<sal_uInt16>(i)+1, aTabBgColor );
330cdf0e10cSrcweir                     }
331cdf0e10cSrcweir 				}
332cdf0e10cSrcweir 			}
333cdf0e10cSrcweir 		}
334cdf0e10cSrcweir 	}
335cdf0e10cSrcweir 	SetCurPageId( static_cast<sal_uInt16>(pViewData->GetTabNo()) + 1 );
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 	if (bActive)
338cdf0e10cSrcweir 	{
339cdf0e10cSrcweir 		bModified = sal_False;											// Selektion
340cdf0e10cSrcweir 		for (i=0; i<nMaxCnt && !bModified; i++)
341cdf0e10cSrcweir 			if ( rMark.GetTableSelect(i) != IsPageSelected(static_cast<sal_uInt16>(i)+1) )
342cdf0e10cSrcweir 				bModified = sal_True;
343cdf0e10cSrcweir 
344cdf0e10cSrcweir         // #i99576# the following loop is mis-optimized on unxsoli4 and the reason
345cdf0e10cSrcweir         // why this file is in NOOPTFILES.
346cdf0e10cSrcweir 		if ( bModified )
347cdf0e10cSrcweir 			for (i=0; i<nCount; i++)
348cdf0e10cSrcweir 				SelectPage( static_cast<sal_uInt16>(i)+1, rMark.GetTableSelect(i) );
349cdf0e10cSrcweir 	}
350cdf0e10cSrcweir 	else
351cdf0e10cSrcweir 	{
352cdf0e10cSrcweir 	}
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
ActivateView(sal_Bool bActivate)355cdf0e10cSrcweir void ScTabControl::ActivateView(sal_Bool bActivate)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir //	ScDocument* pDoc = pViewData->GetDocument();
358cdf0e10cSrcweir 	ScMarkData& rMark = pViewData->GetMarkData();
359cdf0e10cSrcweir 
360cdf0e10cSrcweir //	ResetMark direkt in TabView
361cdf0e10cSrcweir //	pDoc->ResetMark();
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 	sal_uInt16 nCurId = GetCurPageId();
364cdf0e10cSrcweir 	if (!nCurId) return;			// kann vorkommen, wenn bei Excel-Import alles versteckt ist
365cdf0e10cSrcweir 	sal_uInt16 nPage = nCurId - 1;
366cdf0e10cSrcweir //    sal_uInt16 nCount = GetMaxId();
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 	/*
369cdf0e10cSrcweir 	sal_uInt16 i;
370cdf0e10cSrcweir 	for (i=0; i<nCount; i++)
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		SelectPage( i+1, sal_False );
373cdf0e10cSrcweir 		if (bActivate)
374cdf0e10cSrcweir 			rMark.SelectTable( i, sal_False );
375cdf0e10cSrcweir 	}
376cdf0e10cSrcweir 	*/
377cdf0e10cSrcweir 	if (bActivate)
378cdf0e10cSrcweir 	{
379cdf0e10cSrcweir 		SelectPage( nPage+1, sal_True );
380cdf0e10cSrcweir 		rMark.SelectTable( static_cast<SCTAB>(nPage), sal_True );
381cdf0e10cSrcweir 	}
382cdf0e10cSrcweir 	Invalidate();
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
SetSheetLayoutRTL(sal_Bool bSheetRTL)385cdf0e10cSrcweir void ScTabControl::SetSheetLayoutRTL( sal_Bool bSheetRTL )
386cdf0e10cSrcweir {
387cdf0e10cSrcweir     SetEffectiveRTL( bSheetRTL );
388cdf0e10cSrcweir     nSelPageIdByMouse = TabBar::PAGE_NOT_FOUND;
389cdf0e10cSrcweir }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)392cdf0e10cSrcweir void ScTabControl::Command( const CommandEvent& rCEvt )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	ScModule*		pScMod	 = SC_MOD();
395cdf0e10cSrcweir 	ScTabViewShell* pViewSh  = pViewData->GetViewShell();
396cdf0e10cSrcweir 	sal_Bool 			bDisable = pScMod->IsFormulaMode() || pScMod->IsModalMode();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	// ViewFrame erstmal aktivieren (Bug 19493):
399cdf0e10cSrcweir 	pViewSh->SetActive();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 	sal_uInt16 nCmd = rCEvt.GetCommand();
402cdf0e10cSrcweir 	if ( nCmd == COMMAND_CONTEXTMENU )
403cdf0e10cSrcweir 	{
404cdf0e10cSrcweir 		if (!bDisable)
405cdf0e10cSrcweir 		{
406cdf0e10cSrcweir             // #i18735# select the page that is under the mouse cursor
407cdf0e10cSrcweir             // if multiple tables are selected and the one under the cursor
408cdf0e10cSrcweir             // is not part of them then unselect them
409cdf0e10cSrcweir 			sal_uInt16 nId = GetPageId( rCEvt.GetMousePosPixel() );
410cdf0e10cSrcweir 			if (nId)
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir                 sal_Bool bAlreadySelected = IsPageSelected( nId );
413cdf0e10cSrcweir                 //make the clicked page the current one
414cdf0e10cSrcweir                 SetCurPageId( nId );
415cdf0e10cSrcweir                 //change the selection when the current one is not already
416cdf0e10cSrcweir                 //selected or part of a multi selection
417cdf0e10cSrcweir                 if(!bAlreadySelected)
418cdf0e10cSrcweir                 {
419cdf0e10cSrcweir                     sal_uInt16 nCount = GetMaxId();
420cdf0e10cSrcweir 
421cdf0e10cSrcweir                     for (sal_uInt16 i=1; i<=nCount; i++)
422cdf0e10cSrcweir                         SelectPage( i, i==nId );
423cdf0e10cSrcweir                     Select();
424cdf0e10cSrcweir                 }
425cdf0e10cSrcweir 			}
426cdf0e10cSrcweir 
427cdf0e10cSrcweir             // #i52073# OLE inplace editing has to be stopped before showing the sheet tab context menu
428cdf0e10cSrcweir             pViewSh->DeactivateOle();
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 			//	Popup-Menu:
431cdf0e10cSrcweir 			//	get Dispatcher from ViewData (ViewFrame) instead of Shell (Frame), so it can't be null
432cdf0e10cSrcweir 			pViewData->GetDispatcher().ExecutePopup( ScResId(RID_POPUP_TAB) );
433cdf0e10cSrcweir 		}
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir }
436cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point & rPosPixel)437cdf0e10cSrcweir void ScTabControl::StartDrag( sal_Int8 /* nAction */, const Point& rPosPixel )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
440cdf0e10cSrcweir 	sal_Bool bDisable = pScMod->IsFormulaMode() || pScMod->IsModalMode();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 	if (!bDisable)
443cdf0e10cSrcweir 	{
444cdf0e10cSrcweir 		Region aRegion( Rectangle(0,0,0,0) );
445cdf0e10cSrcweir 		CommandEvent aCEvt( rPosPixel, COMMAND_STARTDRAG, sal_True );	// needed for StartDrag
446cdf0e10cSrcweir 		if (TabBar::StartDrag( aCEvt, aRegion ))
447cdf0e10cSrcweir 			DoDrag( aRegion );
448cdf0e10cSrcweir 	}
449cdf0e10cSrcweir }
450cdf0e10cSrcweir 
DoDrag(const Region &)451cdf0e10cSrcweir void ScTabControl::DoDrag( const Region& /* rRegion */ )
452cdf0e10cSrcweir {
453cdf0e10cSrcweir 	ScDocShell* pDocSh = pViewData->GetDocShell();
454cdf0e10cSrcweir 	ScDocument* pDoc = pDocSh->GetDocument();
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 	SCTAB nTab = pViewData->GetTabNo();
457cdf0e10cSrcweir     ScRange aTabRange( 0, 0, nTab, MAXCOL, MAXROW, nTab );
458cdf0e10cSrcweir 	ScMarkData aTabMark = pViewData->GetMarkData();
459cdf0e10cSrcweir 	aTabMark.ResetMark();	// doesn't change marked table information
460cdf0e10cSrcweir     aTabMark.SetMarkArea( aTabRange );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir 	ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP );
463cdf0e10cSrcweir     ScClipParam aClipParam(aTabRange, false);
464cdf0e10cSrcweir     pDoc->CopyToClip(aClipParam, pClipDoc, &aTabMark, false);
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	TransferableObjectDescriptor aObjDesc;
467cdf0e10cSrcweir 	pDocSh->FillTransferableObjectDescriptor( aObjDesc );
468cdf0e10cSrcweir 	aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
469cdf0e10cSrcweir 	// maSize is set in ScTransferObj ctor
470cdf0e10cSrcweir 
471cdf0e10cSrcweir 	ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
472cdf0e10cSrcweir 	com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> xTransferable( pTransferObj );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 	pTransferObj->SetDragSourceFlags( SC_DROP_TABLE );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir 	pTransferObj->SetDragSource( pDocSh, aTabMark );
477cdf0e10cSrcweir 
478cdf0e10cSrcweir 	Window* pWindow = pViewData->GetActiveWin();
479cdf0e10cSrcweir 	SC_MOD()->SetDragObject( pTransferObj, NULL );		// for internal D&D
480cdf0e10cSrcweir 	pTransferObj->StartDrag( pWindow, DND_ACTION_COPYMOVE | DND_ACTION_LINK );
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
lcl_DocShellNr(ScDocument * pDoc)483cdf0e10cSrcweir sal_uInt16 lcl_DocShellNr( ScDocument* pDoc )
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	sal_uInt16 nShellCnt = 0;
486cdf0e10cSrcweir 	SfxObjectShell* pShell = SfxObjectShell::GetFirst();
487cdf0e10cSrcweir 	while ( pShell )
488cdf0e10cSrcweir 	{
489cdf0e10cSrcweir 		if ( pShell->Type() == TYPE(ScDocShell) )
490cdf0e10cSrcweir 		{
491cdf0e10cSrcweir 			if ( ((ScDocShell*)pShell)->GetDocument() == pDoc )
492cdf0e10cSrcweir 				return nShellCnt;
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 			++nShellCnt;
495cdf0e10cSrcweir 		}
496cdf0e10cSrcweir 		pShell = SfxObjectShell::GetNext( *pShell );
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	DBG_ERROR("Dokument nicht gefunden");
500cdf0e10cSrcweir 	return 0;
501cdf0e10cSrcweir }
502cdf0e10cSrcweir 
ExecuteDrop(const ExecuteDropEvent & rEvt)503cdf0e10cSrcweir sal_Int8 ScTabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir 	EndSwitchPage();
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 	ScDocument* pDoc = pViewData->GetDocument();
508cdf0e10cSrcweir 	const ScDragData& rData = SC_MOD()->GetDragData();
509cdf0e10cSrcweir 	if ( rData.pCellTransfer && ( rData.pCellTransfer->GetDragSourceFlags() & SC_DROP_TABLE ) &&
510cdf0e10cSrcweir 			rData.pCellTransfer->GetSourceDocument() == pDoc )
511cdf0e10cSrcweir 	{
512cdf0e10cSrcweir 		// moving of tables within the document
513cdf0e10cSrcweir 		SCTAB nPos = GetPrivatDropPos( rEvt.maPosPixel );
514cdf0e10cSrcweir 		HideDropPos();
515cdf0e10cSrcweir 
516cdf0e10cSrcweir         if ( nPos == rData.pCellTransfer->GetVisibleTab() && rEvt.mnAction == DND_ACTION_MOVE )
517cdf0e10cSrcweir         {
518cdf0e10cSrcweir             // #i83005# do nothing - don't move to the same position
519cdf0e10cSrcweir             // (too easily triggered unintentionally, and might take a long time in large documents)
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir         else
522cdf0e10cSrcweir         {
523cdf0e10cSrcweir             if ( !pDoc->GetChangeTrack() && pDoc->IsDocEditable() )
524cdf0e10cSrcweir             {
525cdf0e10cSrcweir                 //! use table selection from the tab control where dragging was started?
526cdf0e10cSrcweir                 pViewData->GetView()->MoveTable( lcl_DocShellNr(pDoc), nPos, rEvt.mnAction != DND_ACTION_MOVE );
527cdf0e10cSrcweir 
528cdf0e10cSrcweir                 rData.pCellTransfer->SetDragWasInternal();          // don't delete
529cdf0e10cSrcweir                 return sal_True;
530cdf0e10cSrcweir             }
531cdf0e10cSrcweir             else
532cdf0e10cSrcweir                 Sound::Beep();
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir 	}
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 	return 0;
537cdf0e10cSrcweir }
538cdf0e10cSrcweir 
AcceptDrop(const AcceptDropEvent & rEvt)539cdf0e10cSrcweir sal_Int8 ScTabControl::AcceptDrop( const AcceptDropEvent& rEvt )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir 	if ( rEvt.mbLeaving )
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		EndSwitchPage();
544cdf0e10cSrcweir 		HideDropPos();
545cdf0e10cSrcweir 		return rEvt.mnAction;
546cdf0e10cSrcweir 	}
547cdf0e10cSrcweir 
548cdf0e10cSrcweir 	const ScDocument* pDoc = pViewData->GetDocument();
549cdf0e10cSrcweir 	const ScDragData& rData = SC_MOD()->GetDragData();
550cdf0e10cSrcweir 	if ( rData.pCellTransfer && ( rData.pCellTransfer->GetDragSourceFlags() & SC_DROP_TABLE ) &&
551cdf0e10cSrcweir 			rData.pCellTransfer->GetSourceDocument() == pDoc )
552cdf0e10cSrcweir 	{
553cdf0e10cSrcweir 		// moving of tables within the document
554cdf0e10cSrcweir 		if ( !pDoc->GetChangeTrack() && pDoc->IsDocEditable() )
555cdf0e10cSrcweir 		{
556cdf0e10cSrcweir 			ShowDropPos( rEvt.maPosPixel );
557cdf0e10cSrcweir 			return rEvt.mnAction;
558cdf0e10cSrcweir 		}
559cdf0e10cSrcweir 	}
560cdf0e10cSrcweir 	else 					// switch sheets for all formats
561cdf0e10cSrcweir 	{
562cdf0e10cSrcweir 		SwitchPage( rEvt.maPosPixel );		// switch sheet after timeout
563cdf0e10cSrcweir 		return 0;							// nothing can be dropped here
564cdf0e10cSrcweir 	}
565cdf0e10cSrcweir 
566cdf0e10cSrcweir 	return 0;
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
StartRenaming()569cdf0e10cSrcweir long ScTabControl::StartRenaming()
570cdf0e10cSrcweir {
571cdf0e10cSrcweir 	if ( pViewData->GetDocument()->IsDocEditable() )
572cdf0e10cSrcweir         return TABBAR_RENAMING_YES;
573cdf0e10cSrcweir 	else
574cdf0e10cSrcweir         return TABBAR_RENAMING_NO;
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
AllowRenaming()577cdf0e10cSrcweir long ScTabControl::AllowRenaming()
578cdf0e10cSrcweir {
579cdf0e10cSrcweir 	ScTabViewShell* pViewSh = pViewData->GetViewShell();
580cdf0e10cSrcweir 	DBG_ASSERT( pViewSh, "pViewData->GetViewShell()" );
581cdf0e10cSrcweir 
582cdf0e10cSrcweir     long nRet = TABBAR_RENAMING_CANCEL;
583cdf0e10cSrcweir 	sal_uInt16 nId = GetEditPageId();
584cdf0e10cSrcweir 	if ( nId )
585cdf0e10cSrcweir 	{
586cdf0e10cSrcweir 		SCTAB nTab = nId - 1;
587cdf0e10cSrcweir 		String aNewName = GetEditText();
588cdf0e10cSrcweir 		sal_Bool bDone = pViewSh->RenameTable( aNewName, nTab );
589cdf0e10cSrcweir 		if ( bDone )
590cdf0e10cSrcweir             nRet = TABBAR_RENAMING_YES;
591cdf0e10cSrcweir 		else if ( bErrorShown )
592cdf0e10cSrcweir 		{
593cdf0e10cSrcweir 			//	if the error message from this TabControl is currently visible,
594cdf0e10cSrcweir 			//	don't end edit mode now, to avoid problems when returning to
595cdf0e10cSrcweir 			//	the other call (showing the error) - this should not happen
596cdf0e10cSrcweir 			DBG_ERROR("ScTabControl::AllowRenaming: nested calls");
597cdf0e10cSrcweir             nRet = TABBAR_RENAMING_NO;
598cdf0e10cSrcweir 		}
599cdf0e10cSrcweir 		else if ( Application::IsInModalMode() )
600cdf0e10cSrcweir 		{
601cdf0e10cSrcweir 			//	#73472# don't show error message above any modal dialog
602cdf0e10cSrcweir 			//	instead cancel renaming without error message
603cdf0e10cSrcweir             nRet = TABBAR_RENAMING_CANCEL;
604cdf0e10cSrcweir 		}
605cdf0e10cSrcweir 		else
606cdf0e10cSrcweir 		{
607cdf0e10cSrcweir 			bErrorShown = sal_True;
608cdf0e10cSrcweir 			pViewSh->ErrorMessage( STR_INVALIDTABNAME );
609cdf0e10cSrcweir 			bErrorShown = sal_False;
610cdf0e10cSrcweir             nRet = TABBAR_RENAMING_NO;
611cdf0e10cSrcweir 		}
612cdf0e10cSrcweir 	}
613cdf0e10cSrcweir 	return nRet;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
EndRenaming()616cdf0e10cSrcweir void ScTabControl::EndRenaming()
617cdf0e10cSrcweir {
618cdf0e10cSrcweir 	if ( HasFocus() )
619cdf0e10cSrcweir 		pViewData->GetView()->ActiveGrabFocus();
620cdf0e10cSrcweir }
621cdf0e10cSrcweir 
Mirror()622cdf0e10cSrcweir void ScTabControl::Mirror()
623cdf0e10cSrcweir {
624cdf0e10cSrcweir     TabBar::Mirror();
625cdf0e10cSrcweir     if( nSelPageIdByMouse != TabBar::PAGE_NOT_FOUND )
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         Rectangle aRect( GetPageRect( GetCurPageId() ) );
628cdf0e10cSrcweir         if( !aRect.IsEmpty() )
629cdf0e10cSrcweir             SetPointerPosPixel( aRect.Center() );
630cdf0e10cSrcweir         nSelPageIdByMouse = TabBar::PAGE_NOT_FOUND;  // only once after a Select()
631cdf0e10cSrcweir     }
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 
636