/src/libreoffice/sd/source/ui/dlg/LayerTabBar.cxx
Line | Count | Source |
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/vclevent.hxx> |
26 | | #include <vcl/weld/MessageDialog.hxx> |
27 | | #include <vcl/weld/weld.hxx> |
28 | | #include <sfx2/dispatch.hxx> |
29 | | #include <sfx2/viewfrm.hxx> |
30 | | |
31 | | #include <helpids.h> |
32 | | #include <app.hrc> |
33 | | #include <strings.hrc> |
34 | | |
35 | | #include <DrawViewShell.hxx> |
36 | | #include <View.hxx> |
37 | | #include <drawdoc.hxx> |
38 | | #include <sdresid.hxx> |
39 | | #include <unokywds.hxx> |
40 | | #include <DrawDocShell.hxx> |
41 | | #include <drawview.hxx> |
42 | | #include <undolayer.hxx> |
43 | | |
44 | | #include <svx/sdr/overlay/overlaymanager.hxx> |
45 | | #include <svx/sdr/overlay/overlayselection.hxx> |
46 | | #include <svx/svditer.hxx> |
47 | | #include <sdpage.hxx> |
48 | | #include <svx/sdrpaintwindow.hxx> |
49 | | |
50 | | #include <officecfg/Office/Draw.hxx> |
51 | | |
52 | | namespace sd { |
53 | | |
54 | | /** |
55 | | * default constructor |
56 | | */ |
57 | | LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, vcl::Window* pParent) |
58 | 0 | : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL ) ), |
59 | 0 | DropTargetHelper( this ), |
60 | 0 | pDrViewSh(pViewSh), |
61 | 0 | m_aBringLayerObjectsToAttentionDelayTimer("LayerTabBar m_aBringLayerObjectsToAttentionDelayTimer") |
62 | 0 | { |
63 | 0 | EnableEditMode(); |
64 | 0 | SetSizePixel(Size(0, 0)); |
65 | 0 | SetMaxPageWidth( 150 ); |
66 | 0 | SetHelpId( HID_SD_TABBAR_LAYERS ); |
67 | |
|
68 | 0 | m_aBringLayerObjectsToAttentionDelayTimer.SetInvokeHandler( |
69 | 0 | LINK(this, LayerTabBar, BringLayerObjectsToAttentionDelayTimerHdl)); |
70 | 0 | m_aBringLayerObjectsToAttentionDelayTimer.SetTimeout(500); |
71 | 0 | } Unexecuted instantiation: sd::LayerTabBar::LayerTabBar(sd::DrawViewShell*, vcl::Window*) Unexecuted instantiation: sd::LayerTabBar::LayerTabBar(sd::DrawViewShell*, vcl::Window*) |
72 | | |
73 | | LayerTabBar::~LayerTabBar() |
74 | 0 | { |
75 | 0 | disposeOnce(); |
76 | 0 | } |
77 | | |
78 | | void LayerTabBar::dispose() |
79 | 0 | { |
80 | 0 | DropTargetHelper::dispose(); |
81 | 0 | TabBar::dispose(); |
82 | 0 | } |
83 | | |
84 | | OUString LayerTabBar::convertToLocalizedName(const OUString& rName) |
85 | 0 | { |
86 | 0 | if ( rName == sUNO_LayerName_background ) |
87 | 0 | return SdResId( STR_LAYER_BCKGRND ); |
88 | | |
89 | 0 | if ( rName == sUNO_LayerName_background_objects ) |
90 | 0 | return SdResId( STR_LAYER_BCKGRNDOBJ ); |
91 | | |
92 | 0 | if ( rName == sUNO_LayerName_layout ) |
93 | 0 | return SdResId( STR_LAYER_LAYOUT ); |
94 | | |
95 | 0 | if ( rName == sUNO_LayerName_controls ) |
96 | 0 | return SdResId( STR_LAYER_CONTROLS ); |
97 | | |
98 | 0 | if ( rName == sUNO_LayerName_measurelines ) |
99 | 0 | return SdResId( STR_LAYER_MEASURELINES ); |
100 | | |
101 | 0 | return rName; |
102 | 0 | } |
103 | | |
104 | | // Use a method name, that is specific to LayerTabBar to make code better readable |
105 | | const OUString & LayerTabBar::GetLayerName(sal_uInt16 nPageId) const |
106 | 0 | { |
107 | 0 | return GetAuxiliaryText(nPageId); |
108 | 0 | } |
109 | | |
110 | | void LayerTabBar::SetLayerName( sal_uInt16 nPageId, const OUString& rText ) |
111 | 0 | { |
112 | 0 | SetAuxiliaryText(nPageId, rText); |
113 | 0 | } |
114 | | |
115 | | // Here "Page" is a tab in the LayerTabBar. |
116 | | void LayerTabBar::InsertPage( sal_uInt16 nPageId, const OUString& rText, |
117 | | TabBarPageBits nBits, sal_uInt16 nPos) |
118 | 0 | { |
119 | 0 | OUString sLocalizedName(convertToLocalizedName(rText)); |
120 | 0 | TabBar::InsertPage(nPageId, sLocalizedName, nBits, nPos ); |
121 | 0 | SetLayerName(nPageId, rText); |
122 | 0 | } |
123 | | |
124 | | void LayerTabBar::SetPageText( sal_uInt16 nPageId, const OUString& rText ) |
125 | 0 | { |
126 | 0 | OUString sLocalizedName(convertToLocalizedName(rText)); |
127 | 0 | SetLayerName(nPageId, rText); |
128 | 0 | TabBar::SetPageText(nPageId, sLocalizedName); |
129 | 0 | } |
130 | | |
131 | | bool LayerTabBar::IsLocalizedNameOfStandardLayer(std::u16string_view rName) |
132 | 0 | { |
133 | 0 | return ( rName == SdResId(STR_LAYER_LAYOUT) |
134 | 0 | || rName == SdResId(STR_LAYER_CONTROLS) |
135 | 0 | || rName == SdResId(STR_LAYER_MEASURELINES) |
136 | 0 | || rName == SdResId(STR_LAYER_BCKGRND) |
137 | 0 | || rName == SdResId(STR_LAYER_BCKGRNDOBJ) ); |
138 | 0 | } |
139 | | |
140 | | bool LayerTabBar::IsRealNameOfStandardLayer(std::u16string_view rName) |
141 | 0 | { |
142 | 0 | return ( rName == sUNO_LayerName_layout |
143 | 0 | || rName == sUNO_LayerName_controls |
144 | 0 | || rName == sUNO_LayerName_measurelines |
145 | 0 | || rName == sUNO_LayerName_background |
146 | 0 | || rName == sUNO_LayerName_background_objects ); |
147 | 0 | } |
148 | | |
149 | | void LayerTabBar::Select() |
150 | 0 | { |
151 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
152 | 0 | { |
153 | 0 | SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); |
154 | 0 | pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::SYNCHRON); |
155 | 0 | } |
156 | 0 | } |
157 | | |
158 | | void LayerTabBar::MouseMove(const MouseEvent &rMEvt) |
159 | 0 | { |
160 | 0 | sal_uInt16 nPageId = 0; |
161 | 0 | if (!rMEvt.IsLeaveWindow()) |
162 | 0 | nPageId = GetPageId(rMEvt.GetPosPixel()); |
163 | 0 | BringLayerObjectsToAttention(nPageId); |
164 | 0 | return; |
165 | 0 | } |
166 | | |
167 | | void LayerTabBar::BringLayerObjectsToAttention(const sal_uInt16 nPageId) |
168 | 0 | { |
169 | 0 | if (nPageId == m_nBringLayerObjectsToAttentionLastPageId) |
170 | 0 | return; |
171 | | |
172 | 0 | m_aBringLayerObjectsToAttentionDelayTimer.Stop(); |
173 | |
|
174 | 0 | if (m_xOverlayObject && m_xOverlayObject->getOverlayManager()) |
175 | 0 | m_xOverlayObject->getOverlayManager()->remove(*m_xOverlayObject); |
176 | |
|
177 | 0 | m_nBringLayerObjectsToAttentionLastPageId = nPageId; |
178 | |
|
179 | 0 | std::vector<basegfx::B2DRange> aRanges; |
180 | |
|
181 | 0 | if (nPageId != 0) |
182 | 0 | { |
183 | 0 | sal_uInt16 nDisableLayerObjectsOverlay |
184 | 0 | = officecfg::Office::Draw::Misc::DisableLayerHighlighting::get(); |
185 | 0 | OUString aLayerName(GetLayerName(nPageId)); |
186 | 0 | if (nDisableLayerObjectsOverlay > 0 // don't show tooltip message when 0 - meaning feature is turned off |
187 | 0 | && pDrViewSh->GetView()->GetSdrPageView()->IsLayerVisible(aLayerName)) |
188 | 0 | { |
189 | 0 | SdrLayerAdmin& rLayerAdmin = pDrViewSh->GetDoc()->GetLayerAdmin(); |
190 | 0 | SdrObjListIter aIter(pDrViewSh->GetActualPage(), SdrIterMode::DeepWithGroups); |
191 | 0 | while (aIter.IsMore()) |
192 | 0 | { |
193 | 0 | SdrObject* pObj = aIter.Next(); |
194 | 0 | assert(pObj != nullptr); |
195 | 0 | if (!pObj) |
196 | 0 | continue; |
197 | 0 | const SdrLayer* pSdrLayer = rLayerAdmin.GetLayerPerID(pObj->GetLayer()); |
198 | 0 | if (!pSdrLayer) |
199 | 0 | continue; |
200 | 0 | if (aLayerName == pSdrLayer->GetName()) |
201 | 0 | { |
202 | 0 | ::tools::Rectangle aRect(pObj->GetLogicRect()); |
203 | 0 | if (!aRect.IsEmpty()) |
204 | 0 | { |
205 | 0 | aRanges.emplace_back(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom()); |
206 | 0 | if (aRanges.size() > nDisableLayerObjectsOverlay) |
207 | 0 | { |
208 | 0 | OUString sHelpText = SdResId(STR_LAYER_HIGHLIGHTING_DISABLED); |
209 | 0 | sHelpText = sHelpText.replaceFirst( |
210 | 0 | "%1", OUString::number(nDisableLayerObjectsOverlay)); |
211 | 0 | SetQuickHelpText(sHelpText); |
212 | 0 | m_xOverlayObject.reset(); |
213 | 0 | return; |
214 | 0 | } |
215 | 0 | } |
216 | | // skip over objects in groups |
217 | 0 | if (pObj->IsGroupObject()) |
218 | 0 | { |
219 | 0 | SdrObjListIter aSubListIter(pObj->GetSubList(), SdrIterMode::DeepWithGroups); |
220 | 0 | while (aSubListIter.IsMore()) |
221 | 0 | { |
222 | 0 | aIter.Next(); |
223 | 0 | aSubListIter.Next(); |
224 | 0 | } |
225 | 0 | } |
226 | 0 | } |
227 | 0 | } |
228 | 0 | } |
229 | 0 | } |
230 | | |
231 | 0 | SetQuickHelpText(u""_ustr); |
232 | |
|
233 | 0 | if (aRanges.empty()) |
234 | 0 | m_xOverlayObject.reset(); |
235 | 0 | else |
236 | 0 | { |
237 | 0 | m_xOverlayObject.reset(new sdr::overlay::OverlaySelection( |
238 | 0 | sdr::overlay::OverlayType::Invert, |
239 | 0 | Color(), std::move(aRanges), true/*unused for Invert type*/)); |
240 | 0 | m_aBringLayerObjectsToAttentionDelayTimer.Start(); |
241 | 0 | } |
242 | 0 | } |
243 | | |
244 | | IMPL_LINK_NOARG(LayerTabBar, BringLayerObjectsToAttentionDelayTimerHdl, Timer *, void) |
245 | 0 | { |
246 | 0 | m_aBringLayerObjectsToAttentionDelayTimer.Stop(); |
247 | 0 | if (m_xOverlayObject) |
248 | 0 | { |
249 | 0 | if (SdrView* pView = pDrViewSh->GetDrawView()) |
250 | 0 | { |
251 | 0 | if (SdrPaintWindow* pPaintWindow = pView->GetPaintWindow(0)) |
252 | 0 | { |
253 | 0 | const rtl::Reference<sdr::overlay::OverlayManager>& xOverlayManager = |
254 | 0 | pPaintWindow->GetOverlayManager(); |
255 | 0 | xOverlayManager->add(*m_xOverlayObject); |
256 | 0 | } |
257 | 0 | } |
258 | 0 | } |
259 | 0 | } |
260 | | |
261 | | void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt) |
262 | 0 | { |
263 | 0 | bool bSetPageID=false; |
264 | |
|
265 | 0 | if (rMEvt.IsLeft()) |
266 | 0 | { |
267 | 0 | Point aPosPixel = rMEvt.GetPosPixel(); |
268 | 0 | sal_uInt16 aTabId = GetPageId( PixelToLogic(aPosPixel) ); |
269 | 0 | if (aTabId == 0) |
270 | 0 | { |
271 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
272 | 0 | { |
273 | 0 | SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); |
274 | 0 | pDispatcher->Execute(SID_INSERTLAYER, SfxCallMode::SYNCHRON); |
275 | |
|
276 | 0 | bSetPageID=true; |
277 | 0 | } |
278 | 0 | } |
279 | 0 | else if (rMEvt.IsMod2()) |
280 | 0 | { |
281 | | // direct editing of tab text |
282 | | // make sure the clicked tab is the current tab otherwise Edit() acts on the wrong tab |
283 | 0 | if ( aTabId != GetCurPageId()) |
284 | 0 | { |
285 | 0 | MouseEvent aSyntheticEvent (rMEvt.GetPosPixel(), 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0); |
286 | 0 | TabBar::MouseButtonDown(aSyntheticEvent); |
287 | 0 | } |
288 | 0 | } |
289 | 0 | else if (rMEvt.IsMod1() || rMEvt.IsShift()) |
290 | 0 | { |
291 | | // keyboard Shortcuts to change layer attributes |
292 | |
|
293 | 0 | OUString aName(GetLayerName(aTabId)); |
294 | 0 | SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView(); |
295 | | |
296 | | // Save old state |
297 | |
|
298 | 0 | bool bOldPrintable = pPV->IsLayerPrintable(aName); |
299 | 0 | bool bOldVisible = pPV->IsLayerVisible(aName); |
300 | 0 | bool bOldLocked = pPV->IsLayerLocked(aName); |
301 | |
|
302 | 0 | bool bNewPrintable = bOldPrintable; |
303 | 0 | bool bNewVisible = bOldVisible; |
304 | 0 | bool bNewLocked = bOldLocked; |
305 | |
|
306 | 0 | if (rMEvt.IsMod1() && rMEvt.IsShift()) |
307 | 0 | { |
308 | | // Shift+Ctrl: Toggle between layer printable / not printable |
309 | 0 | bNewPrintable = !bOldPrintable; |
310 | 0 | pPV->SetLayerPrintable(aName, bNewPrintable); |
311 | 0 | } |
312 | 0 | else if (rMEvt.IsShift()) |
313 | 0 | { |
314 | | // Shift: Toggle between layer visible / hidden |
315 | | // see also SID_TOGGLELAYERVISIBILITY / tdf#113439 |
316 | 0 | bNewVisible = !bOldVisible; |
317 | 0 | pPV->SetLayerVisible(aName, bNewVisible); |
318 | 0 | } |
319 | 0 | else // if (rMEvt.IsMod1()) |
320 | 0 | { |
321 | | // Ctrl: Toggle between layer locked / unlocked |
322 | 0 | bNewLocked = !bOldLocked; |
323 | 0 | pPV->SetLayerLocked(aName, bNewLocked); |
324 | 0 | } |
325 | |
|
326 | 0 | pDrViewSh->ResetActualLayer(); |
327 | | |
328 | | // Add Undo action |
329 | |
|
330 | 0 | ::sd::View* pView = pDrViewSh->GetView(); |
331 | 0 | DrawView* pDrView = dynamic_cast<DrawView*>(pView); |
332 | |
|
333 | 0 | SdDrawDocument& rDoc = pView->GetDoc(); |
334 | 0 | SdrLayer* pLayer = rDoc.GetLayerAdmin().GetLayer(aName); |
335 | |
|
336 | 0 | if (pLayer) |
337 | 0 | { |
338 | 0 | assert (pDrView && "Change layer attribute undo action is only working with a SdDrawView"); |
339 | 0 | if(pDrView) |
340 | 0 | { |
341 | 0 | SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager(); |
342 | 0 | std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction( |
343 | 0 | rDoc, |
344 | 0 | pLayer, |
345 | 0 | aName, |
346 | 0 | pLayer->GetTitle(), |
347 | 0 | pLayer->GetDescription(), |
348 | 0 | bOldVisible, |
349 | 0 | bOldLocked, |
350 | 0 | bOldPrintable, |
351 | 0 | aName, |
352 | 0 | pLayer->GetTitle(), |
353 | 0 | pLayer->GetDescription(), |
354 | 0 | bNewVisible, |
355 | 0 | bNewLocked, |
356 | 0 | bNewPrintable |
357 | 0 | )); |
358 | 0 | pManager->AddUndoAction(std::move(pAction)); |
359 | 0 | } |
360 | 0 | } |
361 | | |
362 | | // Mark document changed |
363 | |
|
364 | 0 | pView->GetDoc().SetChanged(); |
365 | 0 | } |
366 | 0 | } |
367 | | |
368 | | // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt); |
369 | | // because you want to activate the new layer |
370 | 0 | if( !bSetPageID ) |
371 | 0 | TabBar::MouseButtonDown(rMEvt); |
372 | 0 | } |
373 | | |
374 | | void LayerTabBar::DoubleClick() |
375 | 0 | { |
376 | 0 | if (GetCurPageId() != 0) |
377 | 0 | { |
378 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
379 | 0 | { |
380 | 0 | SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); |
381 | 0 | pDispatcher->Execute( SID_MODIFYLAYER, SfxCallMode::SYNCHRON ); |
382 | 0 | } |
383 | 0 | } |
384 | 0 | } |
385 | | |
386 | | /** |
387 | | * AcceptDrop-Event |
388 | | */ |
389 | | |
390 | | sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt ) |
391 | 0 | { |
392 | 0 | sal_Int8 nRet = DND_ACTION_NONE; |
393 | |
|
394 | 0 | if( rEvt.mbLeaving ) |
395 | 0 | EndSwitchPage(); |
396 | |
|
397 | 0 | if( !pDrViewSh->GetDocSh()->IsReadOnly() ) |
398 | 0 | { |
399 | 0 | Point aPos( PixelToLogic( rEvt.maPosPixel ) ); |
400 | 0 | OUString sLayerName( GetLayerName(GetPageId(aPos)) ); |
401 | 0 | SdrLayerID nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(sLayerName); |
402 | |
|
403 | 0 | nRet = pDrViewSh->AcceptDrop( rEvt, *this, nullptr, SDRPAGE_NOTFOUND, nLayerId ); |
404 | |
|
405 | 0 | SwitchPage( aPos ); |
406 | 0 | } |
407 | |
|
408 | 0 | return nRet; |
409 | 0 | } |
410 | | |
411 | | /** |
412 | | * ExecuteDrop-Event |
413 | | */ |
414 | | sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt ) |
415 | 0 | { |
416 | 0 | Point aPos( PixelToLogic(rEvt.maPosPixel) ); |
417 | 0 | OUString sLayerName( GetLayerName(GetPageId(aPos)) ); |
418 | 0 | SdrLayerID nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(sLayerName); |
419 | |
|
420 | 0 | sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, nullptr, SDRPAGE_NOTFOUND, nLayerId ); |
421 | |
|
422 | 0 | EndSwitchPage(); |
423 | |
|
424 | 0 | return nRet; |
425 | |
|
426 | 0 | } |
427 | | |
428 | | void LayerTabBar::Command(const CommandEvent& rCEvt) |
429 | 0 | { |
430 | 0 | if ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) |
431 | 0 | { |
432 | 0 | BringLayerObjectsToAttention(); |
433 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
434 | 0 | { |
435 | 0 | SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); |
436 | 0 | pDispatcher->ExecutePopup(u"layertab"_ustr); |
437 | 0 | } |
438 | 0 | } |
439 | 0 | } |
440 | | |
441 | | bool LayerTabBar::StartRenaming() |
442 | 0 | { |
443 | 0 | bool bOK = true; |
444 | 0 | OUString aLayerName = GetLayerName( GetEditPageId() ); |
445 | |
|
446 | 0 | if ( IsRealNameOfStandardLayer(aLayerName)) |
447 | 0 | { |
448 | | // It is not allowed to change these names |
449 | 0 | bOK = false; |
450 | 0 | } |
451 | 0 | else |
452 | 0 | { |
453 | 0 | ::sd::View* pView = pDrViewSh->GetView(); |
454 | |
|
455 | 0 | if ( pView->IsTextEdit() ) |
456 | 0 | { |
457 | 0 | pView->SdrEndTextEdit(); |
458 | 0 | } |
459 | 0 | } |
460 | |
|
461 | 0 | return bOK; |
462 | 0 | } |
463 | | |
464 | | TabBarAllowRenamingReturnCode LayerTabBar::AllowRenaming() |
465 | 0 | { |
466 | 0 | bool bOK = true; |
467 | | |
468 | | // Check if names already exists |
469 | 0 | ::sd::View* pView = pDrViewSh->GetView(); |
470 | 0 | SdDrawDocument& rDoc = pView->GetDoc(); |
471 | 0 | OUString aLayerName = pView->GetActiveLayer(); |
472 | 0 | SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin(); |
473 | 0 | OUString aNewName( GetEditText() ); |
474 | |
|
475 | 0 | if (aNewName.isEmpty() || |
476 | 0 | (rLayerAdmin.GetLayer( aNewName ) && aLayerName != aNewName) ) |
477 | 0 | { |
478 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
479 | 0 | { |
480 | | // Name already exists. |
481 | 0 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(pFrame->GetFrameWeld(), |
482 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
483 | 0 | SdResId(STR_WARN_NAME_DUPLICATE))); |
484 | 0 | xWarn->run(); |
485 | 0 | bOK = false; |
486 | 0 | } |
487 | 0 | } |
488 | |
|
489 | 0 | if (bOK) |
490 | 0 | { |
491 | 0 | if ( IsLocalizedNameOfStandardLayer(aNewName) || IsRealNameOfStandardLayer(aNewName) ) |
492 | 0 | { |
493 | | // Standard layer names may not be changed. |
494 | 0 | bOK = false; |
495 | 0 | } |
496 | 0 | } |
497 | |
|
498 | 0 | return bOK ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO; |
499 | 0 | } |
500 | | |
501 | | void LayerTabBar::EndRenaming() |
502 | 0 | { |
503 | 0 | if( IsEditModeCanceled() ) |
504 | 0 | return; |
505 | | |
506 | 0 | ::sd::View* pView = pDrViewSh->GetView(); |
507 | 0 | DrawView* pDrView = dynamic_cast<DrawView*>( pView ); |
508 | |
|
509 | 0 | SdDrawDocument& rDoc = pView->GetDoc(); |
510 | 0 | OUString aLayerName = pView->GetActiveLayer(); |
511 | 0 | SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin(); |
512 | 0 | SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName); |
513 | |
|
514 | 0 | if (!pLayer) |
515 | 0 | return; |
516 | | |
517 | 0 | OUString aNewName( GetEditText() ); |
518 | 0 | assert (pDrView && "Rename layer undo action is only working with a SdDrawView"); |
519 | 0 | if( pDrView ) |
520 | 0 | { |
521 | 0 | SfxUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager(); |
522 | 0 | std::unique_ptr<SdLayerModifyUndoAction> pAction(new SdLayerModifyUndoAction( |
523 | 0 | rDoc, |
524 | 0 | pLayer, |
525 | 0 | aLayerName, |
526 | 0 | pLayer->GetTitle(), |
527 | 0 | pLayer->GetDescription(), |
528 | 0 | pDrView->IsLayerVisible(aLayerName), |
529 | 0 | pDrView->IsLayerLocked(aLayerName), |
530 | 0 | pDrView->IsLayerPrintable(aLayerName), |
531 | 0 | aNewName, |
532 | 0 | pLayer->GetTitle(), |
533 | 0 | pLayer->GetDescription(), |
534 | 0 | pDrView->IsLayerVisible(aLayerName), |
535 | 0 | pDrView->IsLayerLocked(aLayerName), |
536 | 0 | pDrView->IsLayerPrintable(aLayerName) |
537 | 0 | )); |
538 | 0 | pManager->AddUndoAction( std::move(pAction) ); |
539 | 0 | } |
540 | | |
541 | | // First notify View since SetName() calls ResetActualLayer() and |
542 | | // the View then already has to know the Layer |
543 | 0 | pView->SetActiveLayer(aNewName); |
544 | 0 | pLayer->SetName(aNewName); |
545 | 0 | rDoc.SetChanged(); |
546 | 0 | } |
547 | | |
548 | | void LayerTabBar::ActivatePage() |
549 | 0 | { |
550 | 0 | if (pDrViewSh!=nullptr) |
551 | 0 | { |
552 | 0 | if (SfxViewFrame* pFrame = pDrViewSh->GetViewFrame()) |
553 | 0 | { |
554 | 0 | SfxDispatcher* pDispatcher = pFrame->GetDispatcher(); |
555 | 0 | pDispatcher->Execute(SID_SWITCHLAYER, SfxCallMode::ASYNCHRON); |
556 | 0 | } |
557 | 0 | } |
558 | 0 | } |
559 | | |
560 | | void LayerTabBar::SendActivatePageEvent() |
561 | 0 | { |
562 | 0 | CallEventListeners (VclEventId::TabbarPageActivated, |
563 | 0 | reinterpret_cast<void*>(GetCurPageId())); |
564 | 0 | } |
565 | | |
566 | | void LayerTabBar::SendDeactivatePageEvent() |
567 | 0 | { |
568 | 0 | CallEventListeners (VclEventId::TabbarPageDeactivated, |
569 | 0 | reinterpret_cast<void*>(GetCurPageId())); |
570 | 0 | } |
571 | | |
572 | | } // end of namespace sd |
573 | | |
574 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |