LibreOffice Module sd (master) 1
LayerTabBar.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <LayerTabBar.hxx>
21#include <svx/svdlayer.hxx>
22#include <svx/svdpagv.hxx>
23#include <vcl/commandevent.hxx>
24#include <vcl/svapp.hxx>
25#include <vcl/weld.hxx>
26#include <sfx2/dispatch.hxx>
27#include <sfx2/viewfrm.hxx>
28
29#include <helpids.h>
30#include <app.hrc>
31#include <strings.hrc>
32
33#include <DrawViewShell.hxx>
34#include <View.hxx>
35#include <drawdoc.hxx>
36#include <sdresid.hxx>
37#include <unokywds.hxx>
38#include <DrawDocShell.hxx>
39#include <drawview.hxx>
40#include <undolayer.hxx>
41
42namespace sd {
43
48 : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL ) ),
49 DropTargetHelper( this ),
50 pDrViewSh(pViewSh)
51{
53 SetSizePixel(Size(0, 0));
54 SetMaxPageWidth( 150 );
56}
57
59{
60 disposeOnce();
61}
62
64{
65 DropTargetHelper::dispose();
67}
68
69OUString LayerTabBar::convertToLocalizedName(const OUString& rName)
70{
71 if ( rName == sUNO_LayerName_background )
72 return SdResId( STR_LAYER_BCKGRND );
73
75 return SdResId( STR_LAYER_BCKGRNDOBJ );
76
77 if ( rName == sUNO_LayerName_layout )
78 return SdResId( STR_LAYER_LAYOUT );
79
80 if ( rName == sUNO_LayerName_controls )
81 return SdResId( STR_LAYER_CONTROLS );
82
83 if ( rName == sUNO_LayerName_measurelines )
84 return SdResId( STR_LAYER_MEASURELINES );
85
86 return rName;
87}
88
89// Use a method name, that is specific to LayerTabBar to make code better readable
90OUString LayerTabBar::GetLayerName(sal_uInt16 nPageId) const
91{
93}
94
95void LayerTabBar::SetLayerName( sal_uInt16 nPageId, const OUString& rText )
96{
98}
99
100// Here "Page" is a tab in the LayerTabBar.
101void LayerTabBar::InsertPage( sal_uInt16 nPageId, const OUString& rText,
102 TabBarPageBits nBits, sal_uInt16 nPos)
103{
104 OUString sLocalizedName(convertToLocalizedName(rText));
105 TabBar::InsertPage(nPageId, sLocalizedName, nBits, nPos );
106 SetLayerName(nPageId, rText);
107}
108
109void LayerTabBar::SetPageText( sal_uInt16 nPageId, const OUString& rText )
110{
111 OUString sLocalizedName(convertToLocalizedName(rText));
112 SetLayerName(nPageId, rText);
113 TabBar::SetPageText(nPageId, sLocalizedName);
114}
115
116bool LayerTabBar::IsLocalizedNameOfStandardLayer(std::u16string_view rName)
117{
118 return ( rName == SdResId(STR_LAYER_LAYOUT)
119 || rName == SdResId(STR_LAYER_CONTROLS)
120 || rName == SdResId(STR_LAYER_MEASURELINES)
121 || rName == SdResId(STR_LAYER_BCKGRND)
122 || rName == SdResId(STR_LAYER_BCKGRNDOBJ) );
123}
124
125bool LayerTabBar::IsRealNameOfStandardLayer(std::u16string_view rName)
126{
127 return ( rName == sUNO_LayerName_layout
128 || rName == sUNO_LayerName_controls
130 || rName == sUNO_LayerName_background
132}
133
135{
137 pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::ASYNCHRON);
138}
139
141{
142 bool bSetPageID=false;
143
144 if (rMEvt.IsLeft())
145 {
146 Point aPosPixel = rMEvt.GetPosPixel();
147 sal_uInt16 aTabId = GetPageId( PixelToLogic(aPosPixel) );
148 if (aTabId == 0)
149 {
151 pDispatcher->Execute(SID_INSERTLAYER, SfxCallMode::SYNCHRON);
152
153 bSetPageID=true;
154 }
155 else if (rMEvt.IsMod2())
156 {
157 // direct editing of tab text
158 // make sure the clicked tab is the current tab otherwise Edit() acts on the wrong tab
159 if ( aTabId != GetCurPageId())
160 {
161 MouseEvent aSyntheticEvent (rMEvt.GetPosPixel(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0);
162 TabBar::MouseButtonDown(aSyntheticEvent);
163 }
164 }
165 else if (rMEvt.IsMod1() || rMEvt.IsShift())
166 {
167 // keyboard Shortcuts to change layer attributes
168
169 OUString aName(GetLayerName(aTabId));
171
172 // Save old state
173
174 bool bOldPrintable = pPV->IsLayerPrintable(aName);
175 bool bOldVisible = pPV->IsLayerVisible(aName);
176 bool bOldLocked = pPV->IsLayerLocked(aName);
177
178 bool bNewPrintable = bOldPrintable;
179 bool bNewVisible = bOldVisible;
180 bool bNewLocked = bOldLocked;
181
182 if (rMEvt.IsMod1() && rMEvt.IsShift())
183 {
184 // Shift+Ctrl: Toggle between layer printable / not printable
185 bNewPrintable = !bOldPrintable;
186 pPV->SetLayerPrintable(aName, bNewPrintable);
187 }
188 else if (rMEvt.IsShift())
189 {
190 // Shift: Toggle between layer visible / hidden
191 // see also SID_TOGGLELAYERVISIBILITY / tdf#113439
192 bNewVisible = !bOldVisible;
193 pPV->SetLayerVisible(aName, bNewVisible);
194 }
195 else // if (rMEvt.IsMod1())
196 {
197 // Ctrl: Toggle between layer locked / unlocked
198 bNewLocked = !bOldLocked;
199 pPV->SetLayerLocked(aName, bNewLocked);
200 }
201
203
204 // Add Undo action
205
206 ::sd::View* pView = pDrViewSh->GetView();
207 DrawView* pDrView = dynamic_cast<DrawView*>(pView);
208
209 SdDrawDocument& rDoc = pView->GetDoc();
210 SdrLayer* pLayer = rDoc.GetLayerAdmin().GetLayer(aName);
211
212 if (pLayer)
213 {
214 assert (pDrView && "Change layer attribute undo action is only working with a SdDrawView");
215 if(pDrView)
216 {
217 SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
218 std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction(
219 &rDoc,
220 pLayer,
221 aName,
222 pLayer->GetTitle(),
223 pLayer->GetDescription(),
224 bOldVisible,
225 bOldLocked,
226 bOldPrintable,
227 aName,
228 pLayer->GetTitle(),
229 pLayer->GetDescription(),
230 bNewVisible,
231 bNewLocked,
232 bNewPrintable
233 ));
234 pManager->AddUndoAction(std::move(pAction));
235 }
236 }
237
238 // Mark document changed
239
240 pView->GetDoc().SetChanged();
241 }
242 }
243
244 // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
245 // because you want to activate the new layer
246 if( !bSetPageID )
248}
249
251{
252 if (GetCurPageId() != 0)
253 {
255 pDispatcher->Execute( SID_MODIFYLAYER, SfxCallMode::SYNCHRON );
256 }
257}
258
264{
266
267 if( rEvt.mbLeaving )
269
270 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
271 {
272 Point aPos( PixelToLogic( rEvt.maPosPixel ) );
273 OUString sLayerName( GetLayerName(GetPageId(aPos)) );
274 SdrLayerID nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(sLayerName);
275
276 nRet = pDrViewSh->AcceptDrop( rEvt, *this, nullptr, SDRPAGE_NOTFOUND, nLayerId );
277
278 SwitchPage( aPos );
279 }
280
281 return nRet;
282}
283
288{
289 Point aPos( PixelToLogic(rEvt.maPosPixel) );
290 OUString sLayerName( GetLayerName(GetPageId(aPos)) );
291 SdrLayerID nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(sLayerName);
292
293 sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, nullptr, SDRPAGE_NOTFOUND, nLayerId );
294
296
297 return nRet;
298
299}
300
302{
303 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
304 {
306 pDispatcher->ExecutePopup("layertab");
307 }
308}
309
311{
312 bool bOK = true;
313 OUString aLayerName = GetLayerName( GetEditPageId() );
314
315 if ( IsRealNameOfStandardLayer(aLayerName))
316 {
317 // It is not allowed to change these names
318 bOK = false;
319 }
320 else
321 {
322 ::sd::View* pView = pDrViewSh->GetView();
323
324 if ( pView->IsTextEdit() )
325 {
326 pView->SdrEndTextEdit();
327 }
328 }
329
330 return bOK;
331}
332
334{
335 bool bOK = true;
336
337 // Check if names already exists
338 ::sd::View* pView = pDrViewSh->GetView();
339 SdDrawDocument& rDoc = pView->GetDoc();
340 OUString aLayerName = pView->GetActiveLayer();
341 SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
342 OUString aNewName( GetEditText() );
343
344 if (aNewName.isEmpty() ||
345 (rLayerAdmin.GetLayer( aNewName ) && aLayerName != aNewName) )
346 {
347 // Name already exists.
348 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pDrViewSh->GetViewFrame()->GetFrameWeld(),
349 VclMessageType::Warning, VclButtonsType::Ok,
350 SdResId(STR_WARN_NAME_DUPLICATE)));
351 xWarn->run();
352 bOK = false;
353 }
354
355 if (bOK)
356 {
358 {
359 // Standard layer names may not be changed.
360 bOK = false;
361 }
362 }
363
365}
366
368{
369 if( IsEditModeCanceled() )
370 return;
371
372 ::sd::View* pView = pDrViewSh->GetView();
373 DrawView* pDrView = dynamic_cast<DrawView*>( pView );
374
375 SdDrawDocument& rDoc = pView->GetDoc();
376 OUString aLayerName = pView->GetActiveLayer();
377 SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
378 SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName);
379
380 if (!pLayer)
381 return;
382
383 OUString aNewName( GetEditText() );
384 assert (pDrView && "Rename layer undo action is only working with a SdDrawView");
385 if( pDrView )
386 {
387 SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
388 std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction(
389 &rDoc,
390 pLayer,
391 aLayerName,
392 pLayer->GetTitle(),
393 pLayer->GetDescription(),
394 pDrView->IsLayerVisible(aLayerName),
395 pDrView->IsLayerLocked(aLayerName),
396 pDrView->IsLayerPrintable(aLayerName),
397 aNewName,
398 pLayer->GetTitle(),
399 pLayer->GetDescription(),
400 pDrView->IsLayerVisible(aLayerName),
401 pDrView->IsLayerLocked(aLayerName),
402 pDrView->IsLayerPrintable(aLayerName)
403 ));
404 pManager->AddUndoAction( std::move(pAction) );
405 }
406
407 // First notify View since SetName() calls ResetActualLayer() and
408 // the View then already has to know the Layer
409 pView->SetActiveLayer(aNewName);
410 pLayer->SetName(aNewName);
411 rDoc.SetChanged();
412}
413
415{
416 if (pDrViewSh!=nullptr)
417 {
418
420 pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::ASYNCHRON);
421 }
422}
423
425{
426 CallEventListeners (VclEventId::TabbarPageActivated,
427 reinterpret_cast<void*>(GetCurPageId()));
428}
429
431{
432 CallEventListeners (VclEventId::TabbarPageDeactivated,
433 reinterpret_cast<void*>(GetCurPageId()));
434}
435
436} // end of namespace sd
437
438/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 nPageId
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
CommandEventId GetCommand() const
bool IsMod1() const
bool IsMod2() const
const Point & GetPosPixel() const
bool IsLeft() const
bool IsShift() const
virtual SAL_DLLPRIVATE void SetChanged(bool bFlag=true) override
Definition: drawdoc.cxx:658
SAL_DLLPRIVATE::sd::DrawDocShell * GetDocSh() const
Definition: drawdoc.hxx:242
SdrLayerID GetLayerID(const OUString &rName) const
SdrLayer * GetLayer(sal_uInt16 i)
const OUString & GetTitle() const
const OUString & GetDescription() const
void SetName(const OUString &rNewName)
const SdrLayerAdmin & GetLayerAdmin() const
virtual bool IsTextEdit() const final override
bool IsLayerVisible(const OUString &rName) const
void SetLayerVisible(const OUString &rName, bool bShow)
void SetLayerLocked(const OUString &rName, bool bLock)
void SetLayerPrintable(const OUString &rName, bool bPrn)
bool IsLayerLocked(const OUString &rName) const
bool IsLayerPrintable(const OUString &rName) const
bool IsLayerVisible(const OUString &rName) const
bool IsLayerPrintable(const OUString &rName) const
void SetActiveLayer(const OUString &rName)
bool IsLayerLocked(const OUString &rName) const
SdrPageView * GetSdrPageView() const
const OUString & GetActiveLayer() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
void ExecutePopup(const OUString &rResName, vcl::Window *pWin=nullptr, const Point *pPos=nullptr)
bool IsReadOnly() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
SfxDispatcher * GetDispatcher()
weld::Window * GetFrameWeld() const
sal_uInt16 GetEditPageId() const
void SetAuxiliaryText(sal_uInt16 nPageId, const OUString &rText)
OUString GetAuxiliaryText(sal_uInt16 nPageId) const
void EndSwitchPage()
virtual void SetPageText(sal_uInt16 nPageId, const OUString &rText)
const OUString & GetEditText() const
void EnableEditMode()
void SetMaxPageWidth(tools::Long nMaxWidth)
bool IsEditModeCanceled() const
virtual void InsertPage(sal_uInt16 nPageId, const OUString &rText, TabBarPageBits nBits=TabBarPageBits::NONE, sal_uInt16 nPos=TabBar::APPEND)
sal_uInt16 GetPageId(sal_uInt16 nPos) const
void SwitchPage(const Point &rPos)
sal_uInt16 GetCurPageId() const
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void dispose() override
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt, DropTargetHelper &rTargetHelper, ::sd::Window *pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer) override
AcceptDrop.
Definition: drviews1.cxx:1322
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt, DropTargetHelper &rTargetHelper, ::sd::Window *pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer) override
ExecuteDrop.
Definition: drviews1.cxx:1339
void ResetActualLayer()
Select new refreshed page, in case of a page order change (eg.
Definition: drviews1.cxx:1211
Derivative of sd::View; contains also a pointer to the document.
Definition: drawview.hxx:35
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
AcceptDrop-Event.
virtual void dispose() override
Definition: LayerTabBar.cxx:63
void SetLayerName(sal_uInt16 nPageId, const OUString &rText)
Definition: LayerTabBar.cxx:95
virtual void DoubleClick() override
void SendDeactivatePageEvent()
Inform all listeners of this control that the current layer has been deactivated.
virtual TabBarAllowRenamingReturnCode AllowRenaming() override
virtual void EndRenaming() override
OUString GetLayerName(sal_uInt16 nPageId) const
Definition: LayerTabBar.cxx:90
virtual void SetPageText(sal_uInt16 nPageId, const OUString &rText) override
LayerTabBar(DrawViewShell *pDrViewSh, vcl::Window *pParent)
default constructor
Definition: LayerTabBar.cxx:47
virtual bool StartRenaming() override
static bool IsLocalizedNameOfStandardLayer(std::u16string_view rName)
virtual void Command(const CommandEvent &rCEvt) override
static OUString convertToLocalizedName(const OUString &rName)
Definition: LayerTabBar.cxx:69
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
ExecuteDrop-Event.
virtual SD_DLLPUBLIC void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void InsertPage(sal_uInt16 nPageId, const OUString &rText, TabBarPageBits nBits=TabBarPageBits::NONE, sal_uInt16 nPos=TabBar::APPEND) override
void SendActivatePageEvent()
Inform all listeners of this control that the current layer has been activated.
virtual ~LayerTabBar() override
Definition: LayerTabBar.cxx:58
DrawViewShell * pDrViewSh
static bool IsRealNameOfStandardLayer(std::u16string_view rName)
virtual void Select() override
virtual void ActivatePage() override
SD_DLLPUBLIC DrawDocShell * GetDocSh() const
Definition: viewshel.cxx:1407
::sd::View * GetView() const
Definition: ViewShell.hxx:144
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
SdDrawDocument & GetDoc() const
Definition: View.hxx:293
virtual void SetHelpId(const OUString &) override
#define MOUSE_LEFT
constexpr OUStringLiteral HID_SD_TABBAR_LAYERS
Definition: helpids.h:38
OUString aName
sal_uInt16 nPos
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
#define SDRPAGE_NOTFOUND
TabBarAllowRenamingReturnCode
TABBAR_RENAMING_NO
TABBAR_RENAMING_YES
TabBarPageBits
#define DND_ACTION_NONE
signed char sal_Int8
constexpr OUStringLiteral sUNO_LayerName_measurelines
Definition: unokywds.hxx:33
constexpr OUStringLiteral sUNO_LayerName_background_objects
Definition: unokywds.hxx:30
constexpr OUStringLiteral sUNO_LayerName_layout
Definition: unokywds.hxx:31
constexpr OUStringLiteral sUNO_LayerName_controls
Definition: unokywds.hxx:32
constexpr OUStringLiteral sUNO_LayerName_background
Definition: unokywds.hxx:29
sal_Int64 WinBits
WinBits const WB_3DLOOK
WinBits const WB_BORDER
WinBits const WB_SCROLL