1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26
27 #include "LayerTabBar.hxx"
28 #include <svx/svdlayer.hxx>
29 #include <svx/svdpagv.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <sfx2/dispatch.hxx>
32
33
34 #include "sdattr.hxx"
35 #include "app.hxx"
36 #include "helpids.h"
37 #include "app.hrc"
38 #include "glob.hrc"
39 #include "strings.hrc"
40 #include "res_bmp.hrc"
41 #include "DrawViewShell.hxx"
42 #include "Window.hxx"
43 #include "View.hxx"
44 #include "drawdoc.hxx"
45 #include "sdresid.hxx"
46 #include "DrawDocShell.hxx"
47 #include "drawview.hxx"
48 #include "undolayer.hxx"
49
50
51 namespace sd {
52
53 #define SWITCH_TIMEOUT 20
54
55
56 /*************************************************************************
57 |*
58 |* Standard-Konstruktor
59 |*
60 \************************************************************************/
61
LayerTabBar(DrawViewShell * pViewSh,Window * pParent)62 LayerTabBar::LayerTabBar(DrawViewShell* pViewSh, Window* pParent)
63 : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE ) ),
64 DropTargetHelper( this ),
65 pDrViewSh(pViewSh)
66 {
67 EnableEditMode();
68 SetSizePixel(Size(0, 0));
69 SetMaxPageWidth( 150 );
70 SetHelpId( HID_SD_TABBAR_LAYERS );
71 }
72
73
LayerTabBar(DrawViewShell * pViewSh,Window * pParent,const ResId & rResId)74 LayerTabBar::LayerTabBar (
75 DrawViewShell* pViewSh,
76 Window* pParent,
77 const ResId& rResId)
78 : TabBar (pParent, rResId.GetWinBits()),
79 DropTargetHelper( this ),
80 pDrViewSh(pViewSh)
81 {
82 EnableEditMode();
83 }
84
85 /*************************************************************************
86 |*
87 |* Destruktor
88 |*
89 \************************************************************************/
90
~LayerTabBar()91 LayerTabBar::~LayerTabBar()
92 {
93 }
94
95 /*************************************************************************
96 |*
97 \************************************************************************/
98
Select()99 void LayerTabBar::Select()
100 {
101 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
102 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
103 }
104
105 /*************************************************************************
106 |*
107 \************************************************************************/
108
MouseButtonDown(const MouseEvent & rMEvt)109 void LayerTabBar::MouseButtonDown(const MouseEvent& rMEvt)
110 {
111 sal_Bool bSetPageID=sal_False;
112
113 if (rMEvt.IsLeft() && !rMEvt.IsMod1() && !rMEvt.IsMod2())
114 {
115 Point aPosPixel = rMEvt.GetPosPixel();
116 sal_uInt16 aLayerId = GetPageId( PixelToLogic(aPosPixel) );
117
118 if (aLayerId == 0)
119 {
120 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
121 pDispatcher->Execute(SID_INSERTLAYER, SFX_CALLMODE_SYNCHRON);
122
123 bSetPageID=sal_True;
124 }
125 else if (rMEvt.IsShift())
126 {
127 // Toggle zw. Layer sichtbar / unsichtbar
128 String aName(GetPageText(aLayerId));
129 SdrPageView* pPV = pDrViewSh->GetView()->GetSdrPageView();
130 sal_Bool bVisible = pPV->IsLayerVisible(aName);
131 pPV->SetLayerVisible(aName, !bVisible);
132 pDrViewSh->ResetActualLayer();
133 }
134 }
135
136 // If you insert a new layer you must not call TabBar::MouseButtonDown(rMEvt);
137 // because you want to activate the new layer
138 if( !bSetPageID )
139 TabBar::MouseButtonDown(rMEvt);
140 }
141
142 /*************************************************************************
143 |*
144 \************************************************************************/
145
DoubleClick()146 void LayerTabBar::DoubleClick()
147 {
148 if (GetCurPageId() != 0)
149 {
150 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
151 pDispatcher->Execute( SID_MODIFYLAYER, SFX_CALLMODE_SYNCHRON );
152 }
153 }
154
155
156 /*************************************************************************
157 |*
158 |* AcceptDrop-Event
159 |*
160 \************************************************************************/
161
AcceptDrop(const AcceptDropEvent & rEvt)162 sal_Int8 LayerTabBar::AcceptDrop( const AcceptDropEvent& rEvt )
163 {
164 sal_Int8 nRet = DND_ACTION_NONE;
165
166 if( rEvt.mbLeaving )
167 EndSwitchPage();
168
169 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
170 {
171 sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
172 Point aPos( PixelToLogic( rEvt.maPosPixel ) );
173 sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( aPos ) ), sal_False );
174
175 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, nPageId, nLayerId );
176
177 SwitchPage( aPos );
178 }
179
180 return nRet;
181 }
182
183 /*************************************************************************
184 |*
185 |* ExecuteDrop-Event
186 |*
187 \************************************************************************/
188
ExecuteDrop(const ExecuteDropEvent & rEvt)189 sal_Int8 LayerTabBar::ExecuteDrop( const ExecuteDropEvent& rEvt )
190 {
191 sal_uInt16 nPageId = SDRPAGE_NOTFOUND;
192 sal_uInt16 nLayerId = pDrViewSh->GetView()->GetDoc()->GetLayerAdmin().GetLayerID( GetPageText( GetPageId( PixelToLogic( rEvt.maPosPixel ) ) ), sal_False );
193 sal_Int8 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, nPageId, nLayerId );
194
195 EndSwitchPage();
196
197 return nRet;
198
199 }
200
201 /*************************************************************************
202 |*
203 \************************************************************************/
204
Command(const CommandEvent & rCEvt)205 void LayerTabBar::Command(const CommandEvent& rCEvt)
206 {
207 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
208 {
209 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
210 pDispatcher->ExecutePopup(SdResId(RID_LAYERTAB_POPUP));
211 }
212 }
213
214
215 /*************************************************************************
216 |*
217 \************************************************************************/
StartRenaming()218 long LayerTabBar::StartRenaming()
219 {
220 sal_Bool bOK = sal_True;
221 String aLayerName = GetPageText( GetEditPageId() );
222 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
223 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
224 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
225 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
226 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
227
228 if ( aLayerName == aLayoutLayer || aLayerName == aControlsLayer ||
229 aLayerName == aMeasureLinesLayer ||
230 aLayerName == aBackgroundLayer || aLayerName == aBackgroundObjLayer )
231 {
232 // Diese Namen duerfen nicht veraendert werden
233 bOK = sal_False;
234 }
235 else
236 {
237 ::sd::View* pView = pDrViewSh->GetView();
238
239 if ( pView->IsTextEdit() )
240 {
241 pView->SdrEndTextEdit();
242 }
243 }
244
245 return(bOK);
246 }
247
248 /*************************************************************************
249 |*
250 \************************************************************************/
251
AllowRenaming()252 long LayerTabBar::AllowRenaming()
253 {
254 sal_Bool bOK = sal_True;
255
256 // Ueberpruefung auf schon vorhandene Namen
257 ::sd::View* pView = pDrViewSh->GetView();
258 SdDrawDocument* pDoc = pView->GetDoc();
259 String aLayerName = pView->GetActiveLayer();
260 SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
261 String aNewName( GetEditText() );
262
263 if ( aNewName.Len() == 0 ||
264 (rLayerAdmin.GetLayer( aNewName, sal_False ) && aLayerName != aNewName) )
265 {
266 // Name ist schon vorhanden
267 WarningBox aWarningBox( &pDrViewSh->GetViewFrame()->GetWindow(), WinBits( WB_OK ),
268 String(SdResId( STR_WARN_NAME_DUPLICATE ) ) );
269 aWarningBox.Execute();
270 bOK = sal_False;
271 }
272
273 if (bOK)
274 {
275 String aLayoutLayer ( SdResId(STR_LAYER_LAYOUT) );
276 String aControlsLayer ( SdResId(STR_LAYER_CONTROLS) );
277 String aMeasureLinesLayer ( SdResId(STR_LAYER_MEASURELINES) );
278 String aBackgroundLayer( SdResId(STR_LAYER_BCKGRND) );
279 String aBackgroundObjLayer( SdResId(STR_LAYER_BCKGRNDOBJ) );
280
281 if ( aNewName == aLayoutLayer || aNewName == aControlsLayer ||
282 aNewName == aMeasureLinesLayer ||
283 aNewName == aBackgroundLayer || aNewName == aBackgroundObjLayer )
284 {
285 // Diese Namen duerfen nicht vergeben werden
286 bOK = sal_False;
287 }
288 }
289
290 return(bOK);
291 }
292
293 /*************************************************************************
294 |*
295 \************************************************************************/
296
EndRenaming()297 void LayerTabBar::EndRenaming()
298 {
299 if( !IsEditModeCanceled() )
300 {
301 ::sd::View* pView = pDrViewSh->GetView();
302 DrawView* pDrView = PTR_CAST( DrawView, pView );
303
304 SdDrawDocument* pDoc = pView->GetDoc();
305 String aLayerName = pView->GetActiveLayer();
306 SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
307 SdrLayer* pLayer = rLayerAdmin.GetLayer(aLayerName, sal_False);
308
309 if (pLayer)
310 {
311 String aNewName( GetEditText() );
312
313 DBG_ASSERT( pDrView, "Rename layer undo action is only working with a SdDrawView" );
314 if( pDrView )
315 {
316 ::svl::IUndoManager* pManager = pDoc->GetDocSh()->GetUndoManager();
317 SdLayerModifyUndoAction* pAction = new SdLayerModifyUndoAction(
318 pDoc,
319 pLayer,
320 aLayerName,
321 pLayer->GetTitle(),
322 pLayer->GetDescription(),
323 pDrView->IsLayerVisible(aLayerName),
324 pDrView->IsLayerLocked(aLayerName),
325 pDrView->IsLayerPrintable(aLayerName),
326 aNewName,
327 pLayer->GetTitle(),
328 pLayer->GetDescription(),
329 pDrView->IsLayerVisible(aLayerName),
330 pDrView->IsLayerLocked(aLayerName),
331 pDrView->IsLayerPrintable(aLayerName)
332 );
333 pManager->AddUndoAction( pAction );
334 }
335
336 // Zuerst View benachrichtigen, da innerhalb von SetName() schon
337 // ResetActualLayer() gerufen wird und an der View der Layer dann
338 // schon bekannt sein muss.
339 pView->SetActiveLayer(aNewName);
340 pLayer->SetName(aNewName);
341 pDoc->SetChanged(sal_True);
342 }
343 }
344 }
345
346
347 /*************************************************************************
348 |*
349 \************************************************************************/
350
ActivatePage()351 void LayerTabBar::ActivatePage()
352 {
353 if ( /*IsInSwitching*/ 1 && pDrViewSh!=NULL)
354 {
355
356 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
357 pDispatcher->Execute(SID_SWITCHLAYER, SFX_CALLMODE_ASYNCHRON);
358 }
359 }
360
361
362
363
SendActivatePageEvent(void)364 void LayerTabBar::SendActivatePageEvent (void)
365 {
366 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
367 reinterpret_cast<void*>(GetCurPageId()));
368 }
369
370
371
372
SendDeactivatePageEvent(void)373 void LayerTabBar::SendDeactivatePageEvent (void)
374 {
375 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
376 reinterpret_cast<void*>(GetCurPageId()));
377 }
378
379 } // end of namespace sd
380