fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / dlg / LayerTabBar.cxx
blob26ba6f57873cccf07e477a25bf6b34a8dbae0f9e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "LayerTabBar.hxx"
22 #include <svx/svdlayer.hxx>
23 #include <svx/svdpagv.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <sfx2/dispatch.hxx>
28 #include "sdattr.hxx"
29 #include "sdmod.hxx"
30 #include "helpids.h"
31 #include "app.hrc"
32 #include "glob.hrc"
33 #include "strings.hrc"
34 #include "res_bmp.hrc"
35 #include "DrawViewShell.hxx"
36 #include "Window.hxx"
37 #include "View.hxx"
38 #include "drawdoc.hxx"
39 #include "sdresid.hxx"
40 #include "DrawDocShell.hxx"
41 #include "drawview.hxx"
42 #include "undolayer.hxx"
45 namespace sd {
47 /**
48 * default constructor
50 LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
51 : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
52 DropTargetHelper( this ),
53 pDrViewSh(pViewSh)
55 EnableEditMode();
56 SetSizePixel(Size(0, 0));
57 SetMaxPageWidth( 150 );
58 SetHelpId( HID_SD_TABBAR_LAYERS );
62 LayerTabBar::LayerTabBar (
63 DrawViewShell* pViewSh,
64 Window* pParent,
65 const ResId& rResId)
66 : TabBar (pParent, rResId.GetWinBits()),
67 DropTargetHelper( this ),
68 pDrViewSh(pViewSh)
70 EnableEditMode();
73 LayerTabBar::~LayerTabBar()
77 void LayerTabBar::Select()
79 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
80 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
83 void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
85 sal_Bool bSetPageID=sal_False;
87 if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
89 Point aPosPixel = rMEvt.GetPosPixel();
90 sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
92 if (aLayerId == 0)
94 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
95 pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
97 bSetPageID=sal_True;
99 else if (rMEvt.IsShift())
101 // Toggle between layer visible / hidden
102 String aName(GetPageText(aLayerId));
103 SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
104 sal_Bool bVisible = pPV->IsLayerVisible(aName);
105 pPV->SetLayerVisible(aName, !bVisible);
106 pDrViewSh->ResetActualLayer();
110 // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
111 // because you want to activate the new layer
112 if( !bSetPageID )
113 TabBar::MouseButtonDown(rMEvt);
116 void LayerTabBar::DoubleClick()
118 if (GetCurPageId() != 0)
120 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
121 pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
127 * AcceptDrop-Event
130 sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
132 sal_Int8 nRet = DND_ACTION_NONE;
134 if( rEvt.mbLeaving )
135 EndSwitchPage();
137 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
139 sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
140 Point aPos( PixelToLogic( rEvt.maPosPixel ) );
141 sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
142 GetPageText( GetPageId( aPos ) ), sal_False );
144 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
146 SwitchPage( aPos );
149 return nRet;
153 * ExecuteDrop-Event
155 sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
157 sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
158 sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
159 GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), sal_False );
160 sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
162 EndSwitchPage();
164 return nRet;
168 void LayerTabBar::Command(const CommandEvent& rCEvt)
170 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
172 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
173 pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
177 long LayerTabBar::StartRenaming()
179 sal_Bool bOK = sal_True;
180 String aLayerName = GetPageText( GetEditPageId() );
181 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
182 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
183 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
184 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
185 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
187 if ( aLayerName == aLayoutLayer || aLayerName == aControlsLayer ||
188 aLayerName == aMeasureLinesLayer ||
189 aLayerName == aBackgroundLayer || aLayerName == aBackgroundObjLayer )
191 // It is not allowed to change this names
192 bOK = sal_False;
194 else
196 ::sd::View* pView = pDrViewSh->GetView();
198 if ( pView->IsTextEdit() )
200 pView->SdrEndTextEdit();
204 return(bOK);
207 long LayerTabBar::AllowRenaming()
209 sal_Bool bOK = sal_True;
211 // Check if names already exists
212 ::sd::View* pView = pDrViewSh->GetView();
213 SdDrawDocument& rDoc = pView->GetDoc();
214 String aLayerName = pView->GetActiveLayer();
215 SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
216 String aNewName( GetEditText() );
218 if ( aNewName.Len() == 0 ||
219 (rLayerAdmin.GetLayer( aNewName, sal_False ) && aLayerName != aNewName) )
221 // Name already exists
222 WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
223 String(SdResId( STR_WARN_NAME_DUPLICATE ) ) );
224 aWarningBox.Execute();
225 bOK = sal_False;
228 if (bOK)
230 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
231 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
232 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
233 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
234 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
236 if ( aNewName == aLayoutLayer || aNewName == aControlsLayer ||
237 aNewName == aMeasureLinesLayer ||
238 aNewName == aBackgroundLayer || aNewName == aBackgroundObjLayer )
240 // It is not allowed to use his names
241 bOK = sal_False;
245 return(bOK);
248 void LayerTabBar::EndRenaming()
250 if( !IsEditModeCanceled() )
252 ::sd::View* pView = pDrViewSh->GetView();
253 DrawView* pDrView = PTR_CAST( DrawView, pView );
255 SdDrawDocument& rDoc = pView->GetDoc();
256 String aLayerName = pView->GetActiveLayer();
257 SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
258 SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, sal_False);
260 if (pLayer)
262 String aNewName( GetEditText() );
264 DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
265 if( pDrView )
267 ::svl::IUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
268 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
269 &rDoc,
270 pLayer,
271 aLayerName,
272 pLayer->GetTitle(),
273 pLayer->GetDescription(),
274 pDrView->IsLayerVisible(aLayerName),
275 pDrView->IsLayerLocked(aLayerName),
276 pDrView->IsLayerPrintable(aLayerName),
277 aNewName,
278 pLayer->GetTitle(),
279 pLayer->GetDescription(),
280 pDrView->IsLayerVisible(aLayerName),
281 pDrView->IsLayerLocked(aLayerName),
282 pDrView->IsLayerPrintable(aLayerName)
284 pManager->AddUndoAction( pAction );
287 // First notify View since SetName() calls ResetActualLayer() and
288 // the View then already has to know the Layer
289 pView->SetActiveLayer(aNewName);
290 pLayer->SetName(aNewName);
291 rDoc.SetChanged(sal_True);
296 void LayerTabBar::ActivatePage()
298 if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL)
301 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
302 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
309 void LayerTabBar::SendActivatePageEvent (void)
311 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
312 reinterpret_cast<void*>(GetCurPageId()));
318 void LayerTabBar::SendDeactivatePageEvent (void)
320 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
321 reinterpret_cast<void*>(GetCurPageId()));
324 } // end of namespace sd
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */