1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabcontr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "TabControl.hxx"
36 #include <sfx2/viewfrm.hxx>
37 #include <svx/svdlayer.hxx>
38 #include <svx/svdpagv.hxx>
39 #include <sfx2/dispatch.hxx>
46 #include "res_bmp.hrc"
47 #include "DrawViewShell.hxx"
48 #include "GraphicViewShell.hxx"
52 #include "drawdoc.hxx"
54 #include "unmodpg.hxx"
55 #include "DrawDocShell.hxx"
56 #include "sdresid.hxx"
61 #define SWITCH_TIMEOUT 20
63 // -----------------------------------------
64 // - SdTabControl::SdPageObjsTransferable -
65 // -----------------------------------------
67 TabControl::TabControlTransferable::~TabControlTransferable()
71 // -----------------------------------------------------------------------------
73 void TabControl::TabControlTransferable::AddSupportedFormats()
75 AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR
);
78 // -----------------------------------------------------------------------------
80 sal_Bool
TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor
& )
85 // -----------------------------------------------------------------------------
87 void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction
)
89 mrParent
.DragFinished( nDropAction
);
92 /*************************************************************************
94 |* Standard-Konstruktor
96 \************************************************************************/
98 TabControl::TabControl(DrawViewShell
* pViewSh
, Window
* pParent
) :
99 TabBar( pParent
, WinBits( WB_BORDER
| WB_3DLOOK
| WB_SCROLL
| WB_SIZEABLE
| WB_DRAG
) ),
100 DragSourceHelper( this ),
101 DropTargetHelper( this ),
106 SetSizePixel(Size(0, 0));
107 SetMaxPageWidth( 150 );
108 SetHelpId( HID_SD_TABBAR_PAGES
);
111 /*************************************************************************
115 \************************************************************************/
117 TabControl::~TabControl()
121 /*************************************************************************
123 \************************************************************************/
125 void TabControl::Select()
127 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
128 pDispatcher
->Execute(SID_SWITCHPAGE
, SFX_CALLMODE_ASYNCHRON
|
129 SFX_CALLMODE_RECORD
);
132 /*************************************************************************
134 \************************************************************************/
136 void TabControl::MouseButtonDown(const MouseEvent
& rMEvt
)
143 Point aPos
= PixelToLogic( rMEvt
.GetPosPixel() );
144 USHORT aPageId
= GetPageId(aPos
);
148 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
150 pDispatcher
->Execute(SID_INSERTPAGE_QUICK
,
151 SFX_CALLMODE_SYNCHRON
| SFX_CALLMODE_RECORD
);
155 // A single left click with pressed control key on a tab page first
156 // switches to that page before the usual handling (copying with drag
157 // and drop) takes place.
158 else if (rMEvt
.IsLeft() && rMEvt
.IsMod1() && !rMEvt
.IsMod2() && !rMEvt
.IsShift())
160 pDrViewSh
->SwitchPage (GetPageId (rMEvt
.GetPosPixel()) - 1);
163 // When only the right button is pressed then first process a
164 // synthesized left button click to make the page the current one
165 // whose tab has been clicked. When then the actual right button
166 // click is processed the resulting context menu relates to the
168 if (rMEvt
.IsRight() && ! rMEvt
.IsLeft())
170 MouseEvent
aSyntheticEvent (
175 rMEvt
.GetModifier());
176 TabBar::MouseButtonDown(aSyntheticEvent
);
179 TabBar::MouseButtonDown(rMEvt
);
182 /*************************************************************************
184 \************************************************************************/
186 void TabControl::DoubleClick()
188 if (GetCurPageId() != 0)
190 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
191 pDispatcher
->Execute( SID_MODIFYPAGE
,
192 SFX_CALLMODE_SYNCHRON
| SFX_CALLMODE_RECORD
);
196 /*************************************************************************
200 \************************************************************************/
202 void TabControl::StartDrag( sal_Int8
, const Point
& )
204 bInternalMove
= TRUE
;
206 // object is delete by reference mechanismn
207 ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE
);
210 /*************************************************************************
214 \************************************************************************/
216 void TabControl::DragFinished( sal_Int8
)
218 bInternalMove
= FALSE
;
221 /*************************************************************************
225 \************************************************************************/
227 sal_Int8
TabControl::AcceptDrop( const AcceptDropEvent
& rEvt
)
229 sal_Int8 nRet
= DND_ACTION_NONE
;
234 if( !pDrViewSh
->GetDocSh()->IsReadOnly() )
236 SdDrawDocument
* pDoc
= pDrViewSh
->GetDoc();
237 Point
aPos( rEvt
.maPosPixel
);
241 if( rEvt
.mbLeaving
|| ( pDrViewSh
->GetEditMode() == EM_MASTERPAGE
) )
246 nRet
= rEvt
.mnAction
;
253 sal_Int32 nPageId
= GetPageId( aPos
) - 1;
255 if( ( nPageId
>= 0 ) && pDoc
->GetPage( (USHORT
)nPageId
) )
257 nRet
= pDrViewSh
->AcceptDrop( rEvt
, *this, NULL
, (USHORT
)nPageId
, SDRLAYER_NOTFOUND
);
266 /*************************************************************************
270 \************************************************************************/
272 sal_Int8
TabControl::ExecuteDrop( const ExecuteDropEvent
& rEvt
)
274 SdDrawDocument
* pDoc
= pDrViewSh
->GetDoc();
275 Point
aPos( rEvt
.maPosPixel
);
276 sal_Int8 nRet
= DND_ACTION_NONE
;
280 USHORT nPageId
= ShowDropPos( aPos
) - 1;
282 switch (rEvt
.mnAction
)
284 case DND_ACTION_MOVE
:
285 if( pDrViewSh
->IsSwitchPageAllowed() && pDoc
->MovePages( nPageId
) )
287 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
288 pDispatcher
->Execute(SID_SWITCHPAGE
, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
292 case DND_ACTION_COPY
:
294 // Copying the selected page to the place that rEvt points
295 // takes place in three steps:
296 // 1. Create a copy of the selected page. This copy will
297 // lie directly behind the selected page.
298 // 2. Move the copy to the desired place.
299 // 3. Select the copy.
300 if (pDrViewSh
->IsSwitchPageAllowed())
303 USHORT nPageNumOfCopy
= pDoc
->DuplicatePage (GetCurPageId() - 1);
304 // 2. Move page. For this first switch to the copy:
305 // MovePages operates on the currently selected page(s).
306 pDrViewSh
->SwitchPage (nPageNumOfCopy
);
307 // Adapt target page id when necessary, i.e. page copy
308 // has been inserted in front of the target page.
309 USHORT nPageNum
= nPageId
;
310 if ((nPageNumOfCopy
<= nPageNum
) && (nPageNum
!= (USHORT
)-1))
312 if (pDoc
->MovePages(nPageNum
))
314 // 3. Switch to the copy that has been moved to its
315 // final destination. Use an asynchron slot call to
316 // be executed after the still pending ones.
317 if (nPageNumOfCopy
>= nPageNum
|| (nPageNum
== (USHORT
)-1))
319 SetCurPageId (GetPageId(nPageNum
));
320 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
321 pDispatcher
->Execute(SID_SWITCHPAGE
,
322 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
330 nRet
= rEvt
.mnAction
;
334 sal_Int32 nPageId
= GetPageId( aPos
) - 1;
336 if( ( nPageId
>= 0 ) && pDoc
->GetPage( (USHORT
)nPageId
) )
338 nRet
= pDrViewSh
->ExecuteDrop( rEvt
, *this, NULL
, (USHORT
)nPageId
, SDRLAYER_NOTFOUND
);
348 /*************************************************************************
350 \************************************************************************/
352 void TabControl::Command(const CommandEvent
& rCEvt
)
354 USHORT nCmd
= rCEvt
.GetCommand();
356 if ( nCmd
== COMMAND_CONTEXTMENU
)
358 BOOL bGraphicShell
= pDrViewSh
->ISA(GraphicViewShell
);
359 USHORT nResId
= bGraphicShell
? RID_GRAPHIC_PAGETAB_POPUP
:
360 RID_DRAW_PAGETAB_POPUP
;
361 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
362 pDispatcher
->ExecutePopup( SdResId( nResId
) );
366 /*************************************************************************
368 \************************************************************************/
370 long TabControl::StartRenaming()
374 if (pDrViewSh
->GetPageKind() == PK_STANDARD
)
378 ::sd::View
* pView
= pDrViewSh
->GetView();
380 if ( pView
->IsTextEdit() )
381 pView
->SdrEndTextEdit();
387 /*************************************************************************
389 \************************************************************************/
391 long TabControl::AllowRenaming()
395 String
aNewName( GetEditText() );
396 String
aCompareName( GetPageText( GetEditPageId() ) );
398 if( aCompareName
!= aNewName
)
401 if( pDrViewSh
->GetDocSh()->CheckPageName( this, aNewName
) )
403 SetEditText( aNewName
);
414 /*************************************************************************
416 \************************************************************************/
418 void TabControl::EndRenaming()
420 if( !IsEditModeCanceled() )
421 pDrViewSh
->RenameSlide( GetEditPageId(), GetEditText() );
425 /*************************************************************************
427 \************************************************************************/
429 void TabControl::ActivatePage()
431 if ( /*IsInSwitching && */ pDrViewSh
->IsSwitchPageAllowed() )
433 SfxDispatcher
* pDispatcher
= pDrViewSh
->GetViewFrame()->GetDispatcher();
434 pDispatcher
->Execute(SID_SWITCHPAGE
,
435 SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
440 /*************************************************************************
442 \************************************************************************/
444 long TabControl::DeactivatePage()
446 return pDrViewSh
->IsSwitchPageAllowed();
452 void TabControl::SendActivatePageEvent (void)
454 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED
,
455 reinterpret_cast<void*>(GetCurPageId()));
461 void TabControl::SendDeactivatePageEvent (void)
463 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED
,
464 reinterpret_cast<void*>(GetCurPageId()));
467 } // end of namespace sd