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