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