Update ooo320-m1
[ooovba.git] / sd / source / ui / dlg / LayerTabBar.cxx
blobaecfc03237df6b57d8fc3952ebbadda0b22ed2aa
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: LayerTabBar.cxx,v $
10 * $Revision: 1.8 $
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_sd.hxx"
34 #include "LayerTabBar.hxx"
35 #include <svx/svdlayer.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <sfx2/dispatch.hxx>
41 #include "sdattr.hxx"
42 #include "app.hxx"
43 #include "helpids.h"
44 #include "app.hrc"
45 #include "glob.hrc"
46 #include "strings.hrc"
47 #include "res_bmp.hrc"
48 #include "DrawViewShell.hxx"
49 #include "Window.hxx"
50 #include "View.hxx"
51 #include "drawdoc.hxx"
52 #include "sdresid.hxx"
53 #include "DrawDocShell.hxx"
54 #include "drawview.hxx"
55 #include "undolayer.hxx"
58 namespace sd {
60 #define SWITCH_TIMEOUT 20
63 /*************************************************************************
65 |* Standard-Konstruktor
67 \************************************************************************/
69 LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
70 : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
71 DropTargetHelper( this ),
72 pDrViewSh(pViewSh)
74 EnableEditMode();
75 SetSizePixel(Size(0, 0));
76 SetMaxPageWidth( 150 );
77 SetHelpId( HID_SD_TABBAR_LAYERS );
81 LayerTabBar::LayerTabBar (
82 DrawViewShell* pViewSh,
83 Window* pParent,
84 const ResId& rResId)
85 : TabBar (pParent, rResId.GetWinBits()),
86 DropTargetHelper( this ),
87 pDrViewSh(pViewSh)
89 EnableEditMode();
92 /*************************************************************************
94 |* Destruktor
96 \************************************************************************/
98 LayerTabBar::~LayerTabBar()
102 /*************************************************************************
104 \************************************************************************/
106 void LayerTabBar::Select()
108 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
109 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
112 /*************************************************************************
114 \************************************************************************/
116 void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
118 BOOL bSetPageID=FALSE;
120 if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
122 Point aPosPixel = rMEvt.GetPosPixel();
123 USHORT aLayerId = GetPageId( PixelToLogic(aPosPixel) );
125 if (aLayerId == 0)
127 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
128 pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
130 bSetPageID=TRUE;
132 else if (rMEvt.IsShift())
134 // Toggle zw. Layer sichtbar / unsichtbar
135 String aName(GetPageText(aLayerId));
136 SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
137 BOOL bVisible = pPV->IsLayerVisible(aName);
138 pPV->SetLayerVisible(aName, !bVisible);
139 pDrViewSh->ResetActualLayer();
143 // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
144 // because you want to activate the new layer
145 if( !bSetPageID )
146 TabBar::MouseButtonDown(rMEvt);
149 /*************************************************************************
151 \************************************************************************/
153 void LayerTabBar::DoubleClick()
155 if (GetCurPageId() != 0)
157 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
158 pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
163 /*************************************************************************
165 |* AcceptDrop-Event
167 \************************************************************************/
169 sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
171 sal_Int8 nRet = DND_ACTION_NONE;
173 if( rEvt.mbLeaving )
174 EndSwitchPage();
176 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
178 USHORT nPageId = SDRPAGE_NOTFOUND;
179 Point aPos( PixelToLogic( rEvt.maPosPixel ) );
180 USHORT nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( aPos ) ), FALSE );
182 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
184 SwitchPage( aPos );
187 return nRet;
190 /*************************************************************************
192 |* ExecuteDrop-Event
194 \************************************************************************/
196 sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
198 USHORT nPageId = SDRPAGE_NOTFOUND;
199 USHORT nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), FALSE );
200 sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
202 EndSwitchPage();
204 return nRet;
208 /*************************************************************************
210 \************************************************************************/
212 void LayerTabBar::Command(const CommandEvent& rCEvt)
214 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
216 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
217 pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
222 /*************************************************************************
224 \************************************************************************/
225 long LayerTabBar::StartRenaming()
227 BOOL bOK = TRUE;
228 String aLayerName = GetPageText( GetEditPageId() );
229 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
230 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
231 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
232 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
233 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
235 if ( aLayerName == aLayoutLayer || aLayerName == aControlsLayer ||
236 aLayerName == aMeasureLinesLayer ||
237 aLayerName == aBackgroundLayer || aLayerName == aBackgroundObjLayer )
239 // Diese Namen duerfen nicht veraendert werden
240 bOK = FALSE;
242 else
244 ::sd::View* pView = pDrViewSh->GetView();
246 if ( pView->IsTextEdit() )
248 pView->SdrEndTextEdit();
252 return(bOK);
255 /*************************************************************************
257 \************************************************************************/
259 long LayerTabBar::AllowRenaming()
261 BOOL bOK = TRUE;
263 // Ueberpruefung auf schon vorhandene Namen
264 ::sd::View* pView = pDrViewSh->GetView();
265 SdDrawDocument* pDoc = pView->GetDoc();
266 String aLayerName = pView->GetActiveLayer();
267 SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
268 String aNewName( GetEditText() );
270 if ( aNewName.Len() == 0 ||
271 (rLayerAdmin.GetLayer( aNewName, FALSE ) && aLayerName != aNewName) )
273 // Name ist schon vorhanden
274 WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
275 String(SdResId( STR_WARN_NAME_DUPLICATE ) ) );
276 aWarningBox.Execute();
277 bOK = FALSE;
280 if (bOK)
282 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
283 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
284 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
285 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
286 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
288 if ( aNewName == aLayoutLayer || aNewName == aControlsLayer ||
289 aNewName == aMeasureLinesLayer ||
290 aNewName == aBackgroundLayer || aNewName == aBackgroundObjLayer )
292 // Diese Namen duerfen nicht vergeben werden
293 bOK = FALSE;
297 return(bOK);
300 /*************************************************************************
302 \************************************************************************/
304 void LayerTabBar::EndRenaming()
306 if( !IsEditModeCanceled() )
308 ::sd::View* pView = pDrViewSh->GetView();
309 DrawView* pDrView = PTR_CAST( DrawView, pView );
311 SdDrawDocument* pDoc = pView->GetDoc();
312 String aLayerName = pView->GetActiveLayer();
313 SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
314 SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, FALSE);
316 if (pLayer)
318 String aNewName( GetEditText() );
320 DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
321 if( pDrView )
323 SfxUndoManager* pManager = pDoc->GetDocSh()->GetUndoManager();
324 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
325 pDoc,
326 pLayer,
327 aLayerName,
328 pLayer->GetTitle(),
329 pLayer->GetDescription(),
330 pDrView->IsLayerVisible(aLayerName),
331 pDrView->IsLayerLocked(aLayerName),
332 pDrView->IsLayerPrintable(aLayerName),
333 aNewName,
334 pLayer->GetTitle(),
335 pLayer->GetDescription(),
336 pDrView->IsLayerVisible(aLayerName),
337 pDrView->IsLayerLocked(aLayerName),
338 pDrView->IsLayerPrintable(aLayerName)
340 pManager->AddUndoAction( pAction );
343 // Zuerst View benachrichtigen, da innerhalb von SetName() schon
344 // ResetActualLayer() gerufen wird und an der View der Layer dann
345 // schon bekannt sein muss.
346 pView->SetActiveLayer(aNewName);
347 pLayer->SetName(aNewName);
348 pDoc->SetChanged(TRUE);
354 /*************************************************************************
356 \************************************************************************/
358 void LayerTabBar::ActivatePage()
360 if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL)
363 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
364 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
371 void LayerTabBar::SendActivatePageEvent (void)
373 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
374 reinterpret_cast<void*>(GetCurPageId()));
380 void LayerTabBar::SendDeactivatePageEvent (void)
382 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
383 reinterpret_cast<void*>(GetCurPageId()));
386 } // end of namespace sd