1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sd.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "LayerTabBar.hxx" 28cdf0e10cSrcweir #include <svx/svdlayer.hxx> 29cdf0e10cSrcweir #include <svx/svdpagv.hxx> 30cdf0e10cSrcweir #include <vcl/msgbox.hxx> 31cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include "sdattr.hxx" 35cdf0e10cSrcweir #include "app.hxx" 36cdf0e10cSrcweir #include "helpids.h" 37cdf0e10cSrcweir #include "app.hrc" 38cdf0e10cSrcweir #include "glob.hrc" 39cdf0e10cSrcweir #include "strings.hrc" 40cdf0e10cSrcweir #include "res_bmp.hrc" 41cdf0e10cSrcweir #include "DrawViewShell.hxx" 42cdf0e10cSrcweir #include "Window.hxx" 43cdf0e10cSrcweir #include "View.hxx" 44cdf0e10cSrcweir #include "drawdoc.hxx" 45cdf0e10cSrcweir #include "sdresid.hxx" 46cdf0e10cSrcweir #include "DrawDocShell.hxx" 47cdf0e10cSrcweir #include "drawview.hxx" 48cdf0e10cSrcweir #include "undolayer.hxx" 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace sd { 52cdf0e10cSrcweir 53cdf0e10cSrcweir #define SWITCH_TIMEOUT 20 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir /************************************************************************* 57cdf0e10cSrcweir |* 58cdf0e10cSrcweir |* Standard-Konstruktor 59cdf0e10cSrcweir |* 60cdf0e10cSrcweir \************************************************************************/ 61cdf0e10cSrcweir 62cdf0e10cSrcweir LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent) 63cdf0e10cSrcweir : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ), 64cdf0e10cSrcweir DropTargetHelper( this ), 65cdf0e10cSrcweir pDrViewSh(pViewSh) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir EnableEditMode(); 68cdf0e10cSrcweir SetSizePixel(Size(0, 0)); 69cdf0e10cSrcweir SetMaxPageWidth( 150 ); 70cdf0e10cSrcweir SetHelpId( HID_SD_TABBAR_LAYERS ); 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir 74cdf0e10cSrcweir LayerTabBar::LayerTabBar ( 75cdf0e10cSrcweir DrawViewShell* pViewSh, 76cdf0e10cSrcweir Window* pParent, 77cdf0e10cSrcweir const ResId& rResId) 78cdf0e10cSrcweir : TabBar (pParent, rResId.GetWinBits()), 79cdf0e10cSrcweir DropTargetHelper( this ), 80cdf0e10cSrcweir pDrViewSh(pViewSh) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir EnableEditMode(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir /************************************************************************* 86cdf0e10cSrcweir |* 87cdf0e10cSrcweir |* Destruktor 88cdf0e10cSrcweir |* 89cdf0e10cSrcweir \************************************************************************/ 90cdf0e10cSrcweir 91cdf0e10cSrcweir LayerTabBar::~LayerTabBar() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir /************************************************************************* 96cdf0e10cSrcweir |* 97cdf0e10cSrcweir \************************************************************************/ 98cdf0e10cSrcweir 99cdf0e10cSrcweir void LayerTabBar::Select() 100cdf0e10cSrcweir { 101cdf0e10cSrcweir SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher(); 102cdf0e10cSrcweir pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir 105cdf0e10cSrcweir /************************************************************************* 106cdf0e10cSrcweir |* 107cdf0e10cSrcweir \************************************************************************/ 108cdf0e10cSrcweir 109cdf0e10cSrcweir void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir sal_Bool bSetPageID=sal_False; 112cdf0e10cSrcweir 113cdf0e10cSrcweir if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2()) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir Point aPosPixel = rMEvt.GetPosPixel(); 116cdf0e10cSrcweir sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir if (aLayerId == 0) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher(); 121cdf0e10cSrcweir pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON); 122cdf0e10cSrcweir 123cdf0e10cSrcweir bSetPageID=sal_True; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir else if (rMEvt.IsShift()) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir // Toggle zw. Layer sichtbar / unsichtbar 128cdf0e10cSrcweir String aName(GetPageText(aLayerId)); 129cdf0e10cSrcweir SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView(); 130cdf0e10cSrcweir sal_Bool bVisible = pPV->IsLayerVisible(aName); 131cdf0e10cSrcweir pPV->SetLayerVisible(aName, !bVisible); 132cdf0e10cSrcweir pDrViewSh->ResetActualLayer(); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt); 137cdf0e10cSrcweir // because you want to activate the new layer 138cdf0e10cSrcweir if( !bSetPageID ) 139cdf0e10cSrcweir TabBar::MouseButtonDown(rMEvt); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir /************************************************************************* 143cdf0e10cSrcweir |* 144cdf0e10cSrcweir \************************************************************************/ 145cdf0e10cSrcweir 146cdf0e10cSrcweir void LayerTabBar::DoubleClick() 147cdf0e10cSrcweir { 148cdf0e10cSrcweir if (GetCurPageId() != 0) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher(); 151cdf0e10cSrcweir pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir /************************************************************************* 157cdf0e10cSrcweir |* 158cdf0e10cSrcweir |* AcceptDrop-Event 159cdf0e10cSrcweir |* 160cdf0e10cSrcweir \************************************************************************/ 161cdf0e10cSrcweir 162cdf0e10cSrcweir sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir sal_Int8 nRet = DND_ACTION_NONE; 165cdf0e10cSrcweir 166cdf0e10cSrcweir if( rEvt.mbLeaving ) 167cdf0e10cSrcweir EndSwitchPage(); 168cdf0e10cSrcweir 169cdf0e10cSrcweir if( !pDrViewSh->GetDocSh()->IsReadOnly() ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir sal_uInt16 nPageId = SDRPAGE_NOTFOUND; 172cdf0e10cSrcweir Point aPos( PixelToLogic( rEvt.maPosPixel ) ); 173cdf0e10cSrcweir sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( aPos ) ), sal_False ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId ); 176cdf0e10cSrcweir 177cdf0e10cSrcweir SwitchPage( aPos ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir return nRet; 181cdf0e10cSrcweir } 182cdf0e10cSrcweir 183cdf0e10cSrcweir /************************************************************************* 184cdf0e10cSrcweir |* 185cdf0e10cSrcweir |* ExecuteDrop-Event 186cdf0e10cSrcweir |* 187cdf0e10cSrcweir \************************************************************************/ 188cdf0e10cSrcweir 189cdf0e10cSrcweir sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt ) 190cdf0e10cSrcweir { 191cdf0e10cSrcweir sal_uInt16 nPageId = SDRPAGE_NOTFOUND; 192cdf0e10cSrcweir sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), sal_False ); 193cdf0e10cSrcweir sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId ); 194cdf0e10cSrcweir 195cdf0e10cSrcweir EndSwitchPage(); 196cdf0e10cSrcweir 197cdf0e10cSrcweir return nRet; 198cdf0e10cSrcweir 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir /************************************************************************* 202cdf0e10cSrcweir |* 203cdf0e10cSrcweir \************************************************************************/ 204cdf0e10cSrcweir 205cdf0e10cSrcweir void LayerTabBar::Command(const CommandEvent& rCEvt) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher(); 210cdf0e10cSrcweir pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP)); 211cdf0e10cSrcweir } 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweir /************************************************************************* 216cdf0e10cSrcweir |* 217cdf0e10cSrcweir \************************************************************************/ 218cdf0e10cSrcweir long LayerTabBar::StartRenaming() 219cdf0e10cSrcweir { 220cdf0e10cSrcweir sal_Bool bOK = sal_True; 221cdf0e10cSrcweir String aLayerName = GetPageText( GetEditPageId() ); 222cdf0e10cSrcweir String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) ); 223cdf0e10cSrcweir String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) ); 224cdf0e10cSrcweir String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) ); 225cdf0e10cSrcweir String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) ); 226cdf0e10cSrcweir String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if ( aLayerName == aLayoutLayer || aLayerName == aControlsLayer || 229cdf0e10cSrcweir aLayerName == aMeasureLinesLayer || 230cdf0e10cSrcweir aLayerName == aBackgroundLayer || aLayerName == aBackgroundObjLayer ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir // Diese Namen duerfen nicht veraendert werden 233cdf0e10cSrcweir bOK = sal_False; 234cdf0e10cSrcweir } 235cdf0e10cSrcweir else 236cdf0e10cSrcweir { 237cdf0e10cSrcweir ::sd::View* pView = pDrViewSh->GetView(); 238cdf0e10cSrcweir 239cdf0e10cSrcweir if ( pView->IsTextEdit() ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir pView->SdrEndTextEdit(); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir return(bOK); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir /************************************************************************* 249cdf0e10cSrcweir |* 250cdf0e10cSrcweir \************************************************************************/ 251cdf0e10cSrcweir 252cdf0e10cSrcweir long LayerTabBar::AllowRenaming() 253cdf0e10cSrcweir { 254cdf0e10cSrcweir sal_Bool bOK = sal_True; 255cdf0e10cSrcweir 256cdf0e10cSrcweir // Ueberpruefung auf schon vorhandene Namen 257cdf0e10cSrcweir ::sd::View* pView = pDrViewSh->GetView(); 258cdf0e10cSrcweir SdDrawDocument* pDoc = pView->GetDoc(); 259cdf0e10cSrcweir String aLayerName = pView->GetActiveLayer(); 260cdf0e10cSrcweir SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin(); 261cdf0e10cSrcweir String aNewName( GetEditText() ); 262cdf0e10cSrcweir 263cdf0e10cSrcweir if ( aNewName.Len() == 0 || 264cdf0e10cSrcweir (rLayerAdmin.GetLayer( aNewName, sal_False ) && aLayerName != aNewName) ) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir // Name ist schon vorhanden 267cdf0e10cSrcweir WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ), 268cdf0e10cSrcweir String(SdResId( STR_WARN_NAME_DUPLICATE ) ) ); 269cdf0e10cSrcweir aWarningBox.Execute(); 270cdf0e10cSrcweir bOK = sal_False; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir if (bOK) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) ); 276cdf0e10cSrcweir String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) ); 277cdf0e10cSrcweir String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) ); 278cdf0e10cSrcweir String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) ); 279cdf0e10cSrcweir String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) ); 280cdf0e10cSrcweir 281cdf0e10cSrcweir if ( aNewName == aLayoutLayer || aNewName == aControlsLayer || 282cdf0e10cSrcweir aNewName == aMeasureLinesLayer || 283cdf0e10cSrcweir aNewName == aBackgroundLayer || aNewName == aBackgroundObjLayer ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir // Diese Namen duerfen nicht vergeben werden 286cdf0e10cSrcweir bOK = sal_False; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir return(bOK); 291cdf0e10cSrcweir } 292cdf0e10cSrcweir 293cdf0e10cSrcweir /************************************************************************* 294cdf0e10cSrcweir |* 295cdf0e10cSrcweir \************************************************************************/ 296cdf0e10cSrcweir 297cdf0e10cSrcweir void LayerTabBar::EndRenaming() 298cdf0e10cSrcweir { 299cdf0e10cSrcweir if( !IsEditModeCanceled() ) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir ::sd::View* pView = pDrViewSh->GetView(); 302cdf0e10cSrcweir DrawView* pDrView = PTR_CAST( DrawView, pView ); 303cdf0e10cSrcweir 304cdf0e10cSrcweir SdDrawDocument* pDoc = pView->GetDoc(); 305cdf0e10cSrcweir String aLayerName = pView->GetActiveLayer(); 306cdf0e10cSrcweir SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin(); 307cdf0e10cSrcweir SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, sal_False); 308cdf0e10cSrcweir 309cdf0e10cSrcweir if (pLayer) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir String aNewName( GetEditText() ); 312cdf0e10cSrcweir 313cdf0e10cSrcweir DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" ); 314cdf0e10cSrcweir if( pDrView ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir ::svl::IUndoManager* pManager = pDoc->GetDocSh()->GetUndoManager(); 317cdf0e10cSrcweir SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction( 318cdf0e10cSrcweir pDoc, 319cdf0e10cSrcweir pLayer, 320cdf0e10cSrcweir aLayerName, 321cdf0e10cSrcweir pLayer->GetTitle(), 322cdf0e10cSrcweir pLayer->GetDescription(), 323cdf0e10cSrcweir pDrView->IsLayerVisible(aLayerName), 324cdf0e10cSrcweir pDrView->IsLayerLocked(aLayerName), 325cdf0e10cSrcweir pDrView->IsLayerPrintable(aLayerName), 326cdf0e10cSrcweir aNewName, 327cdf0e10cSrcweir pLayer->GetTitle(), 328cdf0e10cSrcweir pLayer->GetDescription(), 329cdf0e10cSrcweir pDrView->IsLayerVisible(aLayerName), 330cdf0e10cSrcweir pDrView->IsLayerLocked(aLayerName), 331cdf0e10cSrcweir pDrView->IsLayerPrintable(aLayerName) 332cdf0e10cSrcweir ); 333cdf0e10cSrcweir pManager->AddUndoAction( pAction ); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir // Zuerst View benachrichtigen, da innerhalb von SetName() schon 337cdf0e10cSrcweir // ResetActualLayer() gerufen wird und an der View der Layer dann 338cdf0e10cSrcweir // schon bekannt sein muss. 339cdf0e10cSrcweir pView->SetActiveLayer(aNewName); 340cdf0e10cSrcweir pLayer->SetName(aNewName); 341cdf0e10cSrcweir pDoc->SetChanged(sal_True); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir } 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346cdf0e10cSrcweir 347cdf0e10cSrcweir /************************************************************************* 348cdf0e10cSrcweir |* 349cdf0e10cSrcweir \************************************************************************/ 350cdf0e10cSrcweir 351cdf0e10cSrcweir void LayerTabBar::ActivatePage() 352cdf0e10cSrcweir { 353cdf0e10cSrcweir if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir 356cdf0e10cSrcweir SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher(); 357cdf0e10cSrcweir pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir } 360cdf0e10cSrcweir 361cdf0e10cSrcweir 362cdf0e10cSrcweir 363cdf0e10cSrcweir 364cdf0e10cSrcweir void LayerTabBar::SendActivatePageEvent (void) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED, 367cdf0e10cSrcweir reinterpret_cast<void*>(GetCurPageId())); 368cdf0e10cSrcweir } 369cdf0e10cSrcweir 370cdf0e10cSrcweir 371cdf0e10cSrcweir 372cdf0e10cSrcweir 373cdf0e10cSrcweir void LayerTabBar::SendDeactivatePageEvent (void) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED, 376cdf0e10cSrcweir reinterpret_cast<void*>(GetCurPageId())); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir 379cdf0e10cSrcweir } // end of namespace sd 380