merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / tabcontr.cxx
blob31b1adc4fd96303885632e35a9d7eb742e7d4615
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabcontr.cxx,v $
10 * $Revision: 1.20 $
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>
42 #include "sdattr.hxx"
43 #include "app.hxx"
44 #include "app.hrc"
45 #include "glob.hrc"
46 #include "res_bmp.hrc"
47 #include "DrawViewShell.hxx"
48 #include "GraphicViewShell.hxx"
49 #include "helpids.h"
50 #include "View.hxx"
51 #include "sdpage.hxx"
52 #include "drawdoc.hxx"
53 #include "Window.hxx"
54 #include "unmodpg.hxx"
55 #include "DrawDocShell.hxx"
56 #include "sdresid.hxx"
59 namespace sd {
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& )
82 return sal_False;
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 ),
102 pDrViewSh(pViewSh),
103 bInternalMove(FALSE)
105 EnableEditMode();
106 SetSizePixel(Size(0, 0));
107 SetMaxPageWidth( 150 );
108 SetHelpId( HID_SD_TABBAR_PAGES );
111 /*************************************************************************
113 |* Destruktor
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)
138 if (rMEvt.IsLeft()
139 && !rMEvt.IsMod1()
140 && !rMEvt.IsMod2()
141 && !rMEvt.IsShift())
143 Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
144 USHORT aPageId = GetPageId(aPos);
146 if (aPageId == 0)
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
167 // now current page.
168 if (rMEvt.IsRight() && ! rMEvt.IsLeft())
170 MouseEvent aSyntheticEvent (
171 rMEvt.GetPosPixel(),
172 rMEvt.GetClicks(),
173 rMEvt.GetMode(),
174 MOUSE_LEFT,
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 /*************************************************************************
198 |* StartDrag-Request
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 /*************************************************************************
212 |* DragFinished
214 \************************************************************************/
216 void TabControl::DragFinished( sal_Int8 )
218 bInternalMove = FALSE;
221 /*************************************************************************
223 |* AcceptDrop-Event
225 \************************************************************************/
227 sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
229 sal_Int8 nRet = DND_ACTION_NONE;
231 if( rEvt.mbLeaving )
232 EndSwitchPage();
234 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
236 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
237 Point aPos( rEvt.maPosPixel );
239 if( bInternalMove )
241 if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
242 HideDropPos();
243 else
245 ShowDropPos( aPos );
246 nRet = rEvt.mnAction;
249 else
251 HideDropPos();
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 );
258 SwitchPage( aPos );
263 return nRet;
266 /*************************************************************************
268 |* ExecuteDrop-Event
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;
278 if( bInternalMove )
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);
290 break;
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())
302 // 1. Create a copy.
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))
311 nPageNum += 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))
318 nPageNum += 1;
319 SetCurPageId (GetPageId(nPageNum));
320 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
321 pDispatcher->Execute(SID_SWITCHPAGE,
322 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
326 break;
330 nRet = rEvt.mnAction;
332 else
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 );
342 HideDropPos();
343 EndSwitchPage();
345 return nRet;
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()
372 BOOL bOK = FALSE;
374 if (pDrViewSh->GetPageKind() == PK_STANDARD)
376 bOK = TRUE;
378 ::sd::View* pView = pDrViewSh->GetView();
380 if ( pView->IsTextEdit() )
381 pView->SdrEndTextEdit();
384 return( bOK );
387 /*************************************************************************
389 \************************************************************************/
391 long TabControl::AllowRenaming()
393 BOOL bOK = TRUE;
395 String aNewName( GetEditText() );
396 String aCompareName( GetPageText( GetEditPageId() ) );
398 if( aCompareName != aNewName )
400 // Seite umbenennen
401 if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
403 SetEditText( aNewName );
404 EndRenaming();
406 else
408 bOK = FALSE;
411 return( bOK );
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