1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sfx2/dispatch.hxx>
24 #include <vcl/commandevent.hxx>
25 #include <vcl/vclevent.hxx>
29 #include <DrawViewShell.hxx>
32 #include <drawdoc.hxx>
33 #include <DrawDocShell.hxx>
38 TabControl::TabControlTransferable::~TabControlTransferable()
42 void TabControl::TabControlTransferable::AddSupportedFormats()
44 AddFormat( SotClipboardFormatId::STARDRAW_TABBAR
);
47 bool TabControl::TabControlTransferable::GetData( const css::datatransfer::DataFlavor
& /*rFlavor*/, const OUString
& /*rDestDoc*/ )
52 void TabControl::TabControlTransferable::DragFinished( sal_Int8
/*nDropAction*/ )
54 mrParent
.DragFinished();
57 TabControl::TabControl(DrawViewShell
* pViewSh
, vcl::Window
* pParent
) :
58 TabBar( pParent
, WinBits( WB_BORDER
| WB_3DLOOK
| WB_SCROLL
| WB_SIZEABLE
| WB_DRAG
) ),
59 DragSourceHelper( this ),
60 DropTargetHelper( this ),
65 SetSizePixel(Size(0, 0));
66 SetMaxPageWidth( 150 );
67 SetHelpId( HID_SD_TABBAR_PAGES
);
70 TabControl::~TabControl()
75 void TabControl::dispose()
77 DragSourceHelper::dispose();
78 DropTargetHelper::dispose();
82 void TabControl::Select()
84 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
85 pDispatcher
->Execute(SID_SWITCHPAGE
, SfxCallMode::ASYNCHRON
|
89 void TabControl::MouseButtonDown(const MouseEvent
& rMEvt
)
96 Point aPos
= PixelToLogic( rMEvt
.GetPosPixel() );
97 sal_uInt16 aPageId
= GetPageId(aPos
);
102 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
104 pDispatcher
->Execute(SID_INSERTPAGE_QUICK
,
105 SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
109 // A single left click with pressed control key on a tab page first
110 // switches to that page before the usual handling (copying with drag
111 // and drop) takes place.
112 else if (rMEvt
.IsLeft() && rMEvt
.IsMod1() && !rMEvt
.IsMod2() && !rMEvt
.IsShift())
114 pDrViewSh
->SwitchPage (GetPageId (rMEvt
.GetPosPixel()) - 1);
117 // When only the right button is pressed then first process a
118 // synthesized left button click to make the page the current one
119 // whose tab has been clicked. When then the actual right button
120 // click is processed the resulting context menu relates to the
122 if (rMEvt
.IsRight() && ! rMEvt
.IsLeft())
124 MouseEvent
aSyntheticEvent (
129 rMEvt
.GetModifier());
130 TabBar::MouseButtonDown(aSyntheticEvent
);
133 TabBar::MouseButtonDown(rMEvt
);
136 void TabControl::DoubleClick()
138 if (GetCurPageId() != 0)
140 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
141 pDispatcher
->Execute( SID_MODIFYPAGE
,
142 SfxCallMode::SYNCHRON
| SfxCallMode::RECORD
);
146 void TabControl::StartDrag( sal_Int8
, const Point
& )
148 bInternalMove
= true;
150 // object is delete by reference mechanism
151 ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE
);
154 void TabControl::DragFinished()
156 bInternalMove
= false;
159 sal_Int8
TabControl::AcceptDrop( const AcceptDropEvent
& rEvt
)
161 sal_Int8 nRet
= DND_ACTION_NONE
;
166 if( !pDrViewSh
->GetDocSh()->IsReadOnly() )
168 SdDrawDocument
* pDoc
= pDrViewSh
->GetDoc();
169 Point
aPos( rEvt
.maPosPixel
);
173 if( rEvt
.mbLeaving
|| ( pDrViewSh
->GetEditMode() == EditMode::MasterPage
) )
178 nRet
= rEvt
.mnAction
;
185 sal_Int32 nPageId
= GetPageId( aPos
) - 1;
187 if( ( nPageId
>= 0 ) && pDoc
->GetPage( static_cast<sal_uInt16
>(nPageId
) ) )
189 nRet
= pDrViewSh
->AcceptDrop( rEvt
, *this, nullptr, static_cast<sal_uInt16
>(nPageId
), SDRLAYER_NOTFOUND
);
198 sal_Int8
TabControl::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
200 SdDrawDocument
* pDoc
= pDrViewSh
->GetDoc();
201 Point
aPos( rEvt
.maPosPixel
);
202 sal_Int8 nRet
= DND_ACTION_NONE
;
206 sal_uInt16 nPageId
= ShowDropPos( aPos
) - 1;
208 switch (rEvt
.mnAction
)
210 case DND_ACTION_MOVE
:
211 if( pDrViewSh
->IsSwitchPageAllowed() && pDoc
->MovePages( nPageId
) )
213 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
214 pDispatcher
->Execute(SID_SWITCHPAGE
, SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
218 case DND_ACTION_COPY
:
220 // Copying the selected page to the place that rEvt points
221 // takes place in three steps:
222 // 1. Create a copy of the selected page. This copy will
223 // lie directly behind the selected page.
224 // 2. Move the copy to the desired place.
225 // 3. Select the copy.
226 if (pDrViewSh
->IsSwitchPageAllowed())
229 sal_uInt16 nPageNumOfCopy
= pDoc
->DuplicatePage (GetCurPageId() - 1);
230 // 2. Move page. For this first switch to the copy:
231 // MovePages operates on the currently selected page(s).
232 pDrViewSh
->SwitchPage (nPageNumOfCopy
);
233 // Adapt target page id when necessary, i.e. page copy
234 // has been inserted in front of the target page.
235 sal_uInt16 nPageNum
= nPageId
;
236 if ((nPageNumOfCopy
<= nPageNum
) && (nPageNum
!= sal_uInt16(-1)))
238 if (pDoc
->MovePages(nPageNum
))
240 // 3. Switch to the copy that has been moved to its
241 // final destination. Use an asynchron slot call to
242 // be executed after the still pending ones.
243 if (nPageNumOfCopy
>= nPageNum
|| (nPageNum
== sal_uInt16(-1)))
245 SetCurPageId (GetPageId(nPageNum
));
246 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
247 pDispatcher
->Execute(SID_SWITCHPAGE
,
248 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
256 nRet
= rEvt
.mnAction
;
260 sal_Int32 nPageId
= GetPageId( aPos
) - 1;
262 if( ( nPageId
>= 0 ) && pDoc
->GetPage( static_cast<sal_uInt16
>(nPageId
) ) )
264 nRet
= pDrViewSh
->ExecuteDrop( rEvt
, *this, nullptr, static_cast<sal_uInt16
>(nPageId
), SDRLAYER_NOTFOUND
);
274 void TabControl::Command(const CommandEvent
& rCEvt
)
276 if ( rCEvt
.GetCommand() == CommandEventId::ContextMenu
)
278 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
279 pDispatcher
->ExecutePopup("pagetab");
283 bool TabControl::StartRenaming()
287 if (pDrViewSh
->GetPageKind() == PageKind::Standard
)
291 ::sd::View
* pView
= pDrViewSh
->GetView();
293 if ( pView
->IsTextEdit() )
294 pView
->SdrEndTextEdit();
300 TabBarAllowRenamingReturnCode
TabControl::AllowRenaming()
304 OUString
aNewName( GetEditText() );
305 OUString
aCompareName( GetPageText( GetEditPageId() ) );
307 if( aCompareName
!= aNewName
)
310 if (pDrViewSh
->GetDocSh()->CheckPageName(GetFrameWeld(), aNewName
))
312 SetEditText( aNewName
);
320 return bOK
? TABBAR_RENAMING_YES
: TABBAR_RENAMING_NO
;
323 void TabControl::EndRenaming()
325 if( !IsEditModeCanceled() )
326 pDrViewSh
->RenameSlide( GetEditPageId(), GetEditText() );
329 void TabControl::ActivatePage()
331 if ( /*IsInSwitching && */ pDrViewSh
->IsSwitchPageAllowed() )
333 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
334 pDispatcher
->Execute(SID_SWITCHPAGE
,
335 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
339 bool TabControl::DeactivatePage()
341 return pDrViewSh
->IsSwitchPageAllowed();
344 void TabControl::SendActivatePageEvent()
346 CallEventListeners (VclEventId::TabbarPageActivated
,
347 reinterpret_cast<void*>(GetCurPageId()));
350 void TabControl::SendDeactivatePageEvent()
352 CallEventListeners (VclEventId::TabbarPageDeactivated
,
353 reinterpret_cast<void*>(GetCurPageId()));
356 } // end of namespace sd
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */