bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / tabcontr.cxx
blobd66f3198575e9574eae80094308aa132b066f728
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TabControl.hxx"
22 #include <sfx2/viewfrm.hxx>
23 #include <svx/svdlayer.hxx>
24 #include <svx/svdpagv.hxx>
25 #include <sfx2/dispatch.hxx>
27 #include "sdattr.hxx"
28 #include "sdmod.hxx"
29 #include "app.hrc"
30 #include "glob.hrc"
31 #include "res_bmp.hrc"
32 #include "DrawViewShell.hxx"
33 #include "GraphicViewShell.hxx"
34 #include "helpids.h"
35 #include "View.hxx"
36 #include "sdpage.hxx"
37 #include "drawdoc.hxx"
38 #include "Window.hxx"
39 #include "unmodpg.hxx"
40 #include "DrawDocShell.hxx"
41 #include "sdresid.hxx"
43 namespace sd {
45 // - SdTabControl::SdPageObjsTransferable -
47 TabControl::TabControlTransferable::~TabControlTransferable()
51 void TabControl::TabControlTransferable::AddSupportedFormats()
53 AddFormat( SotClipboardFormatId::STARDRAW_TABBAR );
56 bool TabControl::TabControlTransferable::GetData( const css::datatransfer::DataFlavor& /*rFlavor*/, const OUString& /*rDestDoc*/ )
58 return false;
61 void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
63 mrParent.DragFinished( nDropAction );
66 TabControl::TabControl(DrawViewShell* pViewSh, vcl::Window* pParent) :
67 TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
68 DragSourceHelper( this ),
69 DropTargetHelper( this ),
70 RrePageID(1),
71 pDrViewSh(pViewSh),
72 bInternalMove(false)
74 EnableEditMode();
75 SetSizePixel(Size(0, 0));
76 SetMaxPageWidth( 150 );
77 SetHelpId( HID_SD_TABBAR_PAGES );
80 TabControl::~TabControl()
84 void TabControl::Select()
86 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
87 pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON |
88 SfxCallMode::RECORD);
91 void TabControl::MouseButtonDown(const MouseEvent& rMEvt)
93 if (rMEvt.IsLeft()
94 && !rMEvt.IsMod1()
95 && !rMEvt.IsMod2()
96 && !rMEvt.IsShift())
98 Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
99 sal_uInt16 aPageId = GetPageId(aPos);
101 //initialize
102 if(RrePageID!=aPageId)
103 pDrViewSh->FreshNavigatrEntry();
104 RrePageID=aPageId;
105 if (aPageId == 0)
107 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
109 pDispatcher->Execute(SID_INSERTPAGE_QUICK,
110 SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
114 // A single left click with pressed control key on a tab page first
115 // switches to that page before the usual handling (copying with drag
116 // and drop) takes place.
117 else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
119 pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
122 // When only the right button is pressed then first process a
123 // synthesized left button click to make the page the current one
124 // whose tab has been clicked. When then the actual right button
125 // click is processed the resulting context menu relates to the
126 // now current page.
127 if (rMEvt.IsRight() && ! rMEvt.IsLeft())
129 MouseEvent aSyntheticEvent (
130 rMEvt.GetPosPixel(),
131 rMEvt.GetClicks(),
132 rMEvt.GetMode(),
133 MOUSE_LEFT,
134 rMEvt.GetModifier());
135 TabBar::MouseButtonDown(aSyntheticEvent);
138 TabBar::MouseButtonDown(rMEvt);
141 void TabControl::DoubleClick()
143 if (GetCurPageId() != 0)
145 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
146 pDispatcher->Execute( SID_MODIFYPAGE,
147 SfxCallMode::SYNCHRON | SfxCallMode::RECORD );
151 void TabControl::StartDrag( sal_Int8, const Point& )
153 bInternalMove = true;
155 // object is delete by reference mechanismn
156 ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
159 void TabControl::DragFinished( sal_Int8 )
161 bInternalMove = false;
164 sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
166 sal_Int8 nRet = DND_ACTION_NONE;
168 if( rEvt.mbLeaving )
169 EndSwitchPage();
171 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
173 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
174 Point aPos( rEvt.maPosPixel );
176 if( bInternalMove )
178 if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
179 HideDropPos();
180 else
182 ShowDropPos( aPos );
183 nRet = rEvt.mnAction;
186 else
188 HideDropPos();
190 sal_Int32 nPageId = GetPageId( aPos ) - 1;
192 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
194 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
195 SwitchPage( aPos );
200 return nRet;
203 sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
205 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
206 Point aPos( rEvt.maPosPixel );
207 sal_Int8 nRet = DND_ACTION_NONE;
209 if( bInternalMove )
211 sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
213 switch (rEvt.mnAction)
215 case DND_ACTION_MOVE:
216 if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
218 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
219 pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
221 break;
223 case DND_ACTION_COPY:
225 // Copying the selected page to the place that rEvt points
226 // takes place in three steps:
227 // 1. Create a copy of the selected page. This copy will
228 // lie directly behind the selected page.
229 // 2. Move the copy to the desired place.
230 // 3. Select the copy.
231 if (pDrViewSh->IsSwitchPageAllowed())
233 // 1. Create a copy.
234 sal_uInt16 nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
235 // 2. Move page. For this first switch to the copy:
236 // MovePages operates on the currently selected page(s).
237 pDrViewSh->SwitchPage (nPageNumOfCopy);
238 // Adapt target page id when necessary, i.e. page copy
239 // has been inserted in front of the target page.
240 sal_uInt16 nPageNum = nPageId;
241 if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (sal_uInt16)-1))
242 nPageNum += 1;
243 if (pDoc->MovePages(nPageNum))
245 // 3. Switch to the copy that has been moved to its
246 // final destination. Use an asynchron slot call to
247 // be executed after the still pending ones.
248 if (nPageNumOfCopy >= nPageNum || (nPageNum == (sal_uInt16)-1))
249 nPageNum += 1;
250 SetCurPageId (GetPageId(nPageNum));
251 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
252 pDispatcher->Execute(SID_SWITCHPAGE,
253 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
257 break;
261 nRet = rEvt.mnAction;
263 else
265 sal_Int32 nPageId = GetPageId( aPos ) - 1;
267 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
269 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
273 HideDropPos();
274 EndSwitchPage();
276 return nRet;
279 void TabControl::Command(const CommandEvent& rCEvt)
281 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
283 bool bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
284 sal_uInt16 nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
285 RID_DRAW_PAGETAB_POPUP;
286 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
287 pDispatcher->ExecutePopup( SdResId( nResId ) );
291 bool TabControl::StartRenaming()
293 bool bOK = false;
295 if (pDrViewSh->GetPageKind() == PK_STANDARD)
297 bOK = true;
299 ::sd::View* pView = pDrViewSh->GetView();
301 if ( pView->IsTextEdit() )
302 pView->SdrEndTextEdit();
305 return bOK;
308 TabBarAllowRenamingReturnCode TabControl::AllowRenaming()
310 bool bOK = true;
312 OUString aNewName( GetEditText() );
313 OUString aCompareName( GetPageText( GetEditPageId() ) );
315 if( aCompareName != aNewName )
317 // rename page
318 if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
320 SetEditText( aNewName );
321 EndRenaming();
323 else
325 bOK = false;
328 return bOK ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
331 void TabControl::EndRenaming()
333 if( !IsEditModeCanceled() )
334 pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
337 void TabControl::ActivatePage()
339 if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
341 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
342 pDispatcher->Execute(SID_SWITCHPAGE,
343 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
347 bool TabControl::DeactivatePage()
349 return pDrViewSh->IsSwitchPageAllowed();
352 void TabControl::SendActivatePageEvent()
354 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
355 reinterpret_cast<void*>(GetCurPageId()));
358 void TabControl::SendDeactivatePageEvent()
360 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
361 reinterpret_cast<void*>(GetCurPageId()));
364 } // end of namespace sd
366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */