fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / view / tabcontr.cxx
blob92168e298c89acb0634ac0ea13115b3eaf0ccce5
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 .
21 #include "TabControl.hxx"
23 #include <sfx2/viewfrm.hxx>
24 #include <svx/svdlayer.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <sfx2/dispatch.hxx>
29 #include "sdattr.hxx"
30 #include "sdmod.hxx"
31 #include "app.hrc"
32 #include "glob.hrc"
33 #include "res_bmp.hrc"
34 #include "DrawViewShell.hxx"
35 #include "GraphicViewShell.hxx"
36 #include "helpids.h"
37 #include "View.hxx"
38 #include "sdpage.hxx"
39 #include "drawdoc.hxx"
40 #include "Window.hxx"
41 #include "unmodpg.hxx"
42 #include "DrawDocShell.hxx"
43 #include "sdresid.hxx"
46 namespace sd {
48 // -----------------------------------------
49 // - SdTabControl::SdPageObjsTransferable -
50 // -----------------------------------------
52 TabControl::TabControlTransferable::~TabControlTransferable()
56 // -----------------------------------------------------------------------------
58 void TabControl::TabControlTransferable::AddSupportedFormats()
60 AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
63 // -----------------------------------------------------------------------------
65 sal_Bool TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& )
67 return sal_False;
70 // -----------------------------------------------------------------------------
72 void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
74 mrParent.DragFinished( nDropAction );
78 TabControl::TabControl(DrawViewShell* pViewSh, Window* pParent) :
79 TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
80 DragSourceHelper( this ),
81 DropTargetHelper( this ),
82 pDrViewSh(pViewSh),
83 bInternalMove(sal_False)
85 EnableEditMode();
86 SetSizePixel(Size(0, 0));
87 SetMaxPageWidth( 150 );
88 SetHelpId( HID_SD_TABBAR_PAGES );
92 TabControl::~TabControl()
96 void TabControl::Select()
98 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
99 pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON |
100 SFX_CALLMODE_RECORD);
103 void TabControl::MouseButtonDown(const MouseEvent& rMEvt)
105 if (rMEvt.IsLeft()
106 && !rMEvt.IsMod1()
107 && !rMEvt.IsMod2()
108 && !rMEvt.IsShift())
110 Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
111 sal_uInt16 aPageId = GetPageId(aPos);
113 if (aPageId == 0)
115 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
117 pDispatcher->Execute(SID_INSERTPAGE_QUICK,
118 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
122 // A single left click with pressed control key on a tab page first
123 // switches to that page before the usual handling (copying with drag
124 // and drop) takes place.
125 else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
127 pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
130 // When only the right button is pressed then first process a
131 // synthesized left button click to make the page the current one
132 // whose tab has been clicked. When then the actual right button
133 // click is processed the resulting context menu relates to the
134 // now current page.
135 if (rMEvt.IsRight() && ! rMEvt.IsLeft())
137 MouseEvent aSyntheticEvent (
138 rMEvt.GetPosPixel(),
139 rMEvt.GetClicks(),
140 rMEvt.GetMode(),
141 MOUSE_LEFT,
142 rMEvt.GetModifier());
143 TabBar::MouseButtonDown(aSyntheticEvent);
146 TabBar::MouseButtonDown(rMEvt);
149 void TabControl::DoubleClick()
151 if (GetCurPageId() != 0)
153 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
154 pDispatcher->Execute( SID_MODIFYPAGE,
155 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
160 void TabControl::StartDrag( sal_Int8, const Point& )
162 bInternalMove = sal_True;
164 // object is delete by reference mechanismn
165 ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
169 void TabControl::DragFinished( sal_Int8 )
171 bInternalMove = sal_False;
175 sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
177 sal_Int8 nRet = DND_ACTION_NONE;
179 if( rEvt.mbLeaving )
180 EndSwitchPage();
182 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
184 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
185 Point aPos( rEvt.maPosPixel );
187 if( bInternalMove )
189 if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
190 HideDropPos();
191 else
193 ShowDropPos( aPos );
194 nRet = rEvt.mnAction;
197 else
199 HideDropPos();
201 sal_Int32 nPageId = GetPageId( aPos ) - 1;
203 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
205 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
206 SwitchPage( aPos );
211 return nRet;
215 sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
217 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
218 Point aPos( rEvt.maPosPixel );
219 sal_Int8 nRet = DND_ACTION_NONE;
221 if( bInternalMove )
223 sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
225 switch (rEvt.mnAction)
227 case DND_ACTION_MOVE:
228 if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
230 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
231 pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
233 break;
235 case DND_ACTION_COPY:
237 // Copying the selected page to the place that rEvt points
238 // takes place in three steps:
239 // 1. Create a copy of the selected page. This copy will
240 // lie directly behind the selected page.
241 // 2. Move the copy to the desired place.
242 // 3. Select the copy.
243 if (pDrViewSh->IsSwitchPageAllowed())
245 // 1. Create a copy.
246 sal_uInt16 nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
247 // 2. Move page. For this first switch to the copy:
248 // MovePages operates on the currently selected page(s).
249 pDrViewSh->SwitchPage (nPageNumOfCopy);
250 // Adapt target page id when necessary, i.e. page copy
251 // has been inserted in front of the target page.
252 sal_uInt16 nPageNum = nPageId;
253 if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (sal_uInt16)-1))
254 nPageNum += 1;
255 if (pDoc->MovePages(nPageNum))
257 // 3. Switch to the copy that has been moved to its
258 // final destination. Use an asynchron slot call to
259 // be executed after the still pending ones.
260 if (nPageNumOfCopy >= nPageNum || (nPageNum == (sal_uInt16)-1))
261 nPageNum += 1;
262 SetCurPageId (GetPageId(nPageNum));
263 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
264 pDispatcher->Execute(SID_SWITCHPAGE,
265 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
269 break;
273 nRet = rEvt.mnAction;
275 else
277 sal_Int32 nPageId = GetPageId( aPos ) - 1;
279 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
281 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
285 HideDropPos();
286 EndSwitchPage();
288 return nRet;
291 void TabControl::Command(const CommandEvent& rCEvt)
293 sal_uInt16 nCmd = rCEvt.GetCommand();
295 if ( nCmd == COMMAND_CONTEXTMENU )
297 sal_Bool bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
298 sal_uInt16 nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
299 RID_DRAW_PAGETAB_POPUP;
300 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
301 pDispatcher->ExecutePopup( SdResId( nResId ) );
305 long TabControl::StartRenaming()
307 sal_Bool bOK = sal_False;
309 if (pDrViewSh->GetPageKind() == PK_STANDARD)
311 bOK = sal_True;
313 ::sd::View* pView = pDrViewSh->GetView();
315 if ( pView->IsTextEdit() )
316 pView->SdrEndTextEdit();
319 return( bOK );
322 long TabControl::AllowRenaming()
324 sal_Bool bOK = sal_True;
326 String aNewName( GetEditText() );
327 String aCompareName( GetPageText( GetEditPageId() ) );
329 if( aCompareName != aNewName )
331 // rename page
332 if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
334 SetEditText( aNewName );
335 EndRenaming();
337 else
339 bOK = sal_False;
342 return( bOK );
345 void TabControl::EndRenaming()
347 if( !IsEditModeCanceled() )
348 pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
351 void TabControl::ActivatePage()
353 if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
355 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
356 pDispatcher->Execute(SID_SWITCHPAGE,
357 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
361 long TabControl::DeactivatePage()
363 return pDrViewSh->IsSwitchPageAllowed();
369 void TabControl::SendActivatePageEvent (void)
371 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
372 reinterpret_cast<void*>(GetCurPageId()));
378 void TabControl::SendDeactivatePageEvent (void)
380 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
381 reinterpret_cast<void*>(GetCurPageId()));
384 } // end of namespace sd
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */