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 <svx/svdlayer.hxx>
24 #include <svx/svdpagv.hxx>
25 #include <sfx2/dispatch.hxx>
31 #include "res_bmp.hrc"
32 #include "DrawViewShell.hxx"
33 #include "GraphicViewShell.hxx"
37 #include "drawdoc.hxx"
39 #include "unmodpg.hxx"
40 #include "DrawDocShell.hxx"
41 #include "sdresid.hxx"
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*/ )
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 ),
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
|
91 void TabControl::MouseButtonDown(const MouseEvent
& rMEvt
)
98 Point aPos
= PixelToLogic( rMEvt
.GetPosPixel() );
99 sal_uInt16 aPageId
= GetPageId(aPos
);
102 if(RrePageID
!=aPageId
)
103 pDrViewSh
->FreshNavigatrEntry();
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
127 if (rMEvt
.IsRight() && ! rMEvt
.IsLeft())
129 MouseEvent
aSyntheticEvent (
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
;
171 if( !pDrViewSh
->GetDocSh()->IsReadOnly() )
173 SdDrawDocument
* pDoc
= pDrViewSh
->GetDoc();
174 Point
aPos( rEvt
.maPosPixel
);
178 if( rEvt
.mbLeaving
|| ( pDrViewSh
->GetEditMode() == EM_MASTERPAGE
) )
183 nRet
= rEvt
.mnAction
;
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
);
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
;
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
);
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())
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))
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))
250 SetCurPageId (GetPageId(nPageNum
));
251 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
252 pDispatcher
->Execute(SID_SWITCHPAGE
,
253 SfxCallMode::ASYNCHRON
| SfxCallMode::RECORD
);
261 nRet
= rEvt
.mnAction
;
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
);
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()
295 if (pDrViewSh
->GetPageKind() == PK_STANDARD
)
299 ::sd::View
* pView
= pDrViewSh
->GetView();
301 if ( pView
->IsTextEdit() )
302 pView
->SdrEndTextEdit();
308 TabBarAllowRenamingReturnCode
TabControl::AllowRenaming()
312 OUString
aNewName( GetEditText() );
313 OUString
aCompareName( GetPageText( GetEditPageId() ) );
315 if( aCompareName
!= aNewName
)
318 if( pDrViewSh
->GetDocSh()->CheckPageName( this, aNewName
) )
320 SetEditText( aNewName
);
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: */