Line data Source code
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 :
21 : #include "LayerTabBar.hxx"
22 : #include <svx/svdlayer.hxx>
23 : #include <svx/svdpagv.hxx>
24 : #include <vcl/msgbox.hxx>
25 : #include <sfx2/dispatch.hxx>
26 :
27 :
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"
43 :
44 :
45 : namespace sd {
46 :
47 : /**
48 : * default constructor
49 : */
50 0 : LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
51 : : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
52 : DropTargetHelper( this ),
53 0 : pDrViewSh(pViewSh)
54 : {
55 0 : EnableEditMode();
56 0 : SetSizePixel(Size(0, 0));
57 0 : SetMaxPageWidth( 150 );
58 0 : SetHelpId( HID_SD_TABBAR_LAYERS );
59 0 : }
60 :
61 :
62 0 : LayerTabBar::LayerTabBar (
63 : DrawViewShell* pViewSh,
64 : Window* pParent,
65 : const ResId& rResId)
66 0 : : TabBar (pParent, rResId.GetWinBits()),
67 : DropTargetHelper( this ),
68 0 : pDrViewSh(pViewSh)
69 : {
70 0 : EnableEditMode();
71 0 : }
72 :
73 0 : LayerTabBar::~LayerTabBar()
74 : {
75 0 : }
76 :
77 0 : void LayerTabBar::Select()
78 : {
79 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
80 0 : pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
81 0 : }
82 :
83 0 : void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
84 : {
85 0 : sal_Bool bSetPageID=sal_False;
86 :
87 0 : if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
88 : {
89 0 : Point aPosPixel = rMEvt.GetPosPixel();
90 0 : sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
91 :
92 0 : if (aLayerId == 0)
93 : {
94 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
95 0 : pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
96 :
97 0 : bSetPageID=sal_True;
98 : }
99 0 : else if (rMEvt.IsShift())
100 : {
101 : // Toggle between layer visible / hidden
102 0 : OUString aName(GetPageText(aLayerId));
103 0 : SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
104 0 : sal_Bool bVisible = pPV->IsLayerVisible(aName);
105 0 : pPV->SetLayerVisible(aName, !bVisible);
106 0 : pDrViewSh->ResetActualLayer();
107 : }
108 : }
109 :
110 : // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
111 : // because you want to activate the new layer
112 0 : if( !bSetPageID )
113 0 : TabBar::MouseButtonDown(rMEvt);
114 0 : }
115 :
116 0 : void LayerTabBar::DoubleClick()
117 : {
118 0 : if (GetCurPageId() != 0)
119 : {
120 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
121 0 : pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
122 : }
123 0 : }
124 :
125 :
126 : /**
127 : * AcceptDrop-Event
128 : */
129 :
130 0 : sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
131 : {
132 0 : sal_Int8 nRet = DND_ACTION_NONE;
133 :
134 0 : if( rEvt.mbLeaving )
135 0 : EndSwitchPage();
136 :
137 0 : if( !pDrViewSh->GetDocSh()->IsReadOnly() )
138 : {
139 0 : sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
140 0 : Point aPos( PixelToLogic( rEvt.maPosPixel ) );
141 0 : sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
142 0 : GetPageText( GetPageId( aPos ) ), false );
143 :
144 0 : nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
145 :
146 0 : SwitchPage( aPos );
147 : }
148 :
149 0 : return nRet;
150 : }
151 :
152 : /**
153 : * ExecuteDrop-Event
154 : */
155 0 : sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
156 : {
157 0 : sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
158 0 : sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc().GetLayerAdmin().GetLayerID(
159 0 : GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), false );
160 0 : sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
161 :
162 0 : EndSwitchPage();
163 :
164 0 : return nRet;
165 :
166 : }
167 :
168 0 : void LayerTabBar::Command(const CommandEvent& rCEvt)
169 : {
170 0 : if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
171 : {
172 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
173 0 : pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
174 : }
175 0 : }
176 :
177 0 : long LayerTabBar::StartRenaming()
178 : {
179 0 : sal_Bool bOK = sal_True;
180 0 : OUString aLayerName = GetPageText( GetEditPageId() );
181 0 : OUString aLayoutLayer = SD_RESSTR(STR_LAYER_LAYOUT);
182 0 : OUString aControlsLayer = SD_RESSTR(STR_LAYER_CONTROLS);
183 0 : OUString aMeasureLinesLayer = SD_RESSTR(STR_LAYER_MEASURELINES);
184 0 : OUString aBackgroundLayer = SD_RESSTR(STR_LAYER_BCKGRND);
185 0 : OUString aBackgroundObjLayer = SD_RESSTR(STR_LAYER_BCKGRNDOBJ);
186 :
187 0 : if ( aLayerName == aLayoutLayer || aLayerName == aControlsLayer ||
188 0 : aLayerName == aMeasureLinesLayer ||
189 0 : aLayerName == aBackgroundLayer || aLayerName == aBackgroundObjLayer )
190 : {
191 : // It is not allowed to change this names
192 0 : bOK = sal_False;
193 : }
194 : else
195 : {
196 0 : ::sd::View* pView = pDrViewSh->GetView();
197 :
198 0 : if ( pView->IsTextEdit() )
199 : {
200 0 : pView->SdrEndTextEdit();
201 : }
202 : }
203 :
204 0 : return(bOK);
205 : }
206 :
207 0 : long LayerTabBar::AllowRenaming()
208 : {
209 0 : sal_Bool bOK = sal_True;
210 :
211 : // Check if names already exists
212 0 : ::sd::View* pView = pDrViewSh->GetView();
213 0 : SdDrawDocument& rDoc = pView->GetDoc();
214 0 : OUString aLayerName = pView->GetActiveLayer();
215 0 : SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
216 0 : OUString aNewName( GetEditText() );
217 :
218 0 : if (aNewName.isEmpty() ||
219 0 : (rLayerAdmin.GetLayer( aNewName, false ) && aLayerName != aNewName) )
220 : {
221 : // Name already exists
222 0 : WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
223 0 : SD_RESSTR( STR_WARN_NAME_DUPLICATE ) );
224 0 : aWarningBox.Execute();
225 0 : bOK = sal_False;
226 : }
227 :
228 0 : if (bOK)
229 : {
230 0 : OUString aLayoutLayer = SD_RESSTR(STR_LAYER_LAYOUT);
231 0 : OUString aControlsLayer = SD_RESSTR(STR_LAYER_CONTROLS);
232 0 : OUString aMeasureLinesLayer = SD_RESSTR(STR_LAYER_MEASURELINES);
233 0 : OUString aBackgroundLayer = SD_RESSTR(STR_LAYER_BCKGRND);
234 0 : OUString aBackgroundObjLayer = SD_RESSTR(STR_LAYER_BCKGRNDOBJ);
235 :
236 0 : if ( aNewName == aLayoutLayer || aNewName == aControlsLayer ||
237 0 : aNewName == aMeasureLinesLayer ||
238 0 : aNewName == aBackgroundLayer || aNewName == aBackgroundObjLayer )
239 : {
240 : // It is not allowed to use his names
241 0 : bOK = sal_False;
242 0 : }
243 : }
244 :
245 0 : return(bOK);
246 : }
247 :
248 0 : void LayerTabBar::EndRenaming()
249 : {
250 0 : if( !IsEditModeCanceled() )
251 : {
252 0 : ::sd::View* pView = pDrViewSh->GetView();
253 0 : DrawView* pDrView = PTR_CAST( DrawView, pView );
254 :
255 0 : SdDrawDocument& rDoc = pView->GetDoc();
256 0 : OUString aLayerName = pView->GetActiveLayer();
257 0 : SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
258 0 : SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, false);
259 :
260 0 : if (pLayer)
261 : {
262 0 : OUString aNewName( GetEditText() );
263 :
264 : DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
265 0 : if( pDrView )
266 : {
267 0 : ::svl::IUndoManager* pManager = rDoc.GetDocSh()->GetUndoManager();
268 : SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
269 : &rDoc,
270 : pLayer,
271 : aLayerName,
272 : pLayer->GetTitle(),
273 : pLayer->GetDescription(),
274 0 : pDrView->IsLayerVisible(aLayerName),
275 0 : pDrView->IsLayerLocked(aLayerName),
276 0 : pDrView->IsLayerPrintable(aLayerName),
277 : aNewName,
278 : pLayer->GetTitle(),
279 : pLayer->GetDescription(),
280 0 : pDrView->IsLayerVisible(aLayerName),
281 0 : pDrView->IsLayerLocked(aLayerName),
282 0 : pDrView->IsLayerPrintable(aLayerName)
283 0 : );
284 0 : pManager->AddUndoAction( pAction );
285 : }
286 :
287 : // First notify View since SetName() calls ResetActualLayer() and
288 : // the View then already has to know the Layer
289 0 : pView->SetActiveLayer(aNewName);
290 0 : pLayer->SetName(aNewName);
291 0 : rDoc.SetChanged(true);
292 0 : }
293 : }
294 0 : }
295 :
296 0 : void LayerTabBar::ActivatePage()
297 : {
298 0 : if ( /*IsInSwitching*/ true && pDrViewSh!=NULL)
299 : {
300 :
301 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
302 0 : pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
303 : }
304 0 : }
305 :
306 :
307 :
308 :
309 0 : void LayerTabBar::SendActivatePageEvent (void)
310 : {
311 : CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
312 0 : reinterpret_cast<void*>(GetCurPageId()));
313 0 : }
314 :
315 :
316 :
317 :
318 0 : void LayerTabBar::SendDeactivatePageEvent (void)
319 : {
320 : CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
321 0 : reinterpret_cast<void*>(GetCurPageId()));
322 0 : }
323 :
324 : } // end of namespace sd
325 :
326 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|