LibreOffice Module sd (master) 1
tabcontr.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <TabControl.hxx>
21
22#include <sfx2/viewfrm.hxx>
23#include <sfx2/dispatch.hxx>
24#include <vcl/commandevent.hxx>
25#include <vcl/vclevent.hxx>
26
27#include <app.hrc>
28
29#include <DrawViewShell.hxx>
30#include <helpids.h>
31#include <View.hxx>
32#include <drawdoc.hxx>
33#include <DrawDocShell.hxx>
34
35namespace sd {
36
37
39{
40}
41
43{
44 AddFormat( SotClipboardFormatId::STARDRAW_TABBAR );
45}
46
47bool TabControl::TabControlTransferable::GetData( const css::datatransfer::DataFlavor& /*rFlavor*/, const OUString& /*rDestDoc*/ )
48{
49 return false;
50}
51
53{
54 mrParent.DragFinished();
55}
56
59 DragSourceHelper( this ),
60 DropTargetHelper( this ),
61 pDrViewSh(pViewSh),
62 bInternalMove(false)
63{
65 SetSizePixel(Size(0, 0));
66 SetMaxPageWidth( 150 );
68}
69
71{
72 disposeOnce();
73}
74
76{
77 DragSourceHelper::dispose();
78 DropTargetHelper::dispose();
80}
81
83{
85 pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON |
86 SfxCallMode::RECORD);
87}
88
90{
91 if (rMEvt.IsLeft()
92 && !rMEvt.IsMod1()
93 && !rMEvt.IsMod2()
94 && !rMEvt.IsShift())
95 {
96 Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
97 sal_uInt16 aPageId = GetPageId(aPos);
98
99 //initialize
100 if (aPageId == 0)
101 {
103
104 pDispatcher->Execute(SID_INSERTPAGE_QUICK,
105 SfxCallMode::SYNCHRON | SfxCallMode::RECORD);
106 }
107 }
108
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())
113 {
114 pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
115 }
116
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
121 // now current page.
122 if (rMEvt.IsRight() && ! rMEvt.IsLeft())
123 {
124 MouseEvent aSyntheticEvent (
125 rMEvt.GetPosPixel(),
126 rMEvt.GetClicks(),
127 rMEvt.GetMode(),
129 rMEvt.GetModifier());
130 TabBar::MouseButtonDown(aSyntheticEvent);
131 }
132
134}
135
137{
138 if (GetCurPageId() != 0)
139 {
141 pDispatcher->Execute( SID_MODIFYPAGE,
142 SfxCallMode::SYNCHRON | SfxCallMode::RECORD );
143 }
144}
145
147{
148 bInternalMove = true;
149
150 // object is delete by reference mechanism
152}
153
155{
156 bInternalMove = false;
157}
158
160{
162
163 if( rEvt.mbLeaving )
165
166 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
167 {
169 Point aPos( rEvt.maPosPixel );
170
171 if( bInternalMove )
172 {
174 HideDropPos();
175 else
176 {
177 ShowDropPos( aPos );
178 nRet = rEvt.mnAction;
179 }
180 }
181 else
182 {
183 HideDropPos();
184
185 sal_Int32 nPageId = GetPageId( aPos ) - 1;
186
187 if( ( nPageId >= 0 ) && pDoc->GetPage( static_cast<sal_uInt16>(nPageId) ) )
188 {
189 nRet = pDrViewSh->AcceptDrop( rEvt, *this, nullptr, static_cast<sal_uInt16>(nPageId), SDRLAYER_NOTFOUND );
190 SwitchPage( aPos );
191 }
192 }
193 }
194
195 return nRet;
196}
197
199{
201 Point aPos( rEvt.maPosPixel );
203
204 if( bInternalMove )
205 {
206 sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
207
208 switch (rEvt.mnAction)
209 {
210 case DND_ACTION_MOVE:
212 {
214 pDispatcher->Execute(SID_SWITCHPAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
215 }
216 break;
217
218 case DND_ACTION_COPY:
219 {
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.
227 {
228 // 1. Create a copy.
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)))
237 nPageNum += 1;
238 if (pDoc->MovePages(nPageNum))
239 {
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)))
244 nPageNum += 1;
245 SetCurPageId (GetPageId(nPageNum));
247 pDispatcher->Execute(SID_SWITCHPAGE,
248 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
249 }
250 }
251
252 break;
253 }
254 }
255
256 nRet = rEvt.mnAction;
257 }
258 else
259 {
260 sal_Int32 nPageId = GetPageId( aPos ) - 1;
261
262 if( ( nPageId >= 0 ) && pDoc->GetPage( static_cast<sal_uInt16>(nPageId) ) )
263 {
264 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, nullptr, static_cast<sal_uInt16>(nPageId), SDRLAYER_NOTFOUND );
265 }
266 }
267
268 HideDropPos();
270
271 return nRet;
272}
273
275{
276 if ( rCEvt.GetCommand() == CommandEventId::ContextMenu )
277 {
279 pDispatcher->ExecutePopup("pagetab");
280 }
281}
282
284{
285 bool bOK = false;
286
288 {
289 bOK = true;
290
291 ::sd::View* pView = pDrViewSh->GetView();
292
293 if ( pView->IsTextEdit() )
294 pView->SdrEndTextEdit();
295 }
296
297 return bOK;
298}
299
301{
302 bool bOK = true;
303
304 OUString aNewName( GetEditText() );
305 OUString aCompareName( GetPageText( GetEditPageId() ) );
306
307 if( aCompareName != aNewName )
308 {
309 // rename page
310 if (pDrViewSh->GetDocSh()->CheckPageName(GetFrameWeld(), aNewName))
311 {
312 SetEditText( aNewName );
313 EndRenaming();
314 }
315 else
316 {
317 bOK = false;
318 }
319 }
321}
322
324{
325 if( !IsEditModeCanceled() )
327}
328
330{
331 if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
332 {
334 pDispatcher->Execute(SID_SWITCHPAGE,
335 SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
336 }
337}
338
340{
342}
343
345{
346 CallEventListeners (VclEventId::TabbarPageActivated,
347 reinterpret_cast<void*>(GetCurPageId()));
348}
349
351{
352 CallEventListeners (VclEventId::TabbarPageDeactivated,
353 reinterpret_cast<void*>(GetCurPageId()));
354}
355
356} // end of namespace sd
357
358/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BaseContainerNodeSharedPtr & mrParent
sal_uInt16 nPageId
CommandEventId GetCommand() const
bool IsMod1() const
MouseEventModifiers GetMode() const
bool IsMod2() const
sal_uInt16 GetModifier() const
sal_uInt16 GetClicks() const
bool IsRight() const
const Point & GetPosPixel() const
bool IsLeft() const
bool IsShift() const
SAL_DLLPRIVATE sal_uInt16 DuplicatePage(sal_uInt16 nPageNum)
This method acts as a simplified front end for the more complex <member>DuplicatePage()</member> meth...
Definition: drawdoc2.cxx:1215
SAL_DLLPRIVATE bool MovePages(sal_uInt16 nTargetPage)
Definition: drawdoc2.cxx:726
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual bool IsTextEdit() const final override
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
void ExecutePopup(const OUString &rResName, vcl::Window *pWin=nullptr, const Point *pPos=nullptr)
bool IsReadOnly() const
SfxDispatcher * GetDispatcher()
sal_uInt16 GetEditPageId() const
void SetCurPageId(sal_uInt16 nPageId)
sal_uInt16 ShowDropPos(const Point &rPos)
void HideDropPos()
void EndSwitchPage()
void SetEditText(const OUString &rText)
const OUString & GetEditText() const
void EnableEditMode()
void SetMaxPageWidth(tools::Long nMaxWidth)
bool IsEditModeCanceled() const
OUString GetPageText(sal_uInt16 nPageId) const
sal_uInt16 GetPageId(sal_uInt16 nPos) const
void SwitchPage(const Point &rPos)
sal_uInt16 GetCurPageId() const
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void dispose() override
bool CheckPageName(weld::Window *pWin, OUString &rName)
checks, if the given name is a valid new name for a slide
Definition: docshel2.cxx:270
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
EditMode GetEditMode() const
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt, DropTargetHelper &rTargetHelper, ::sd::Window *pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer) override
AcceptDrop.
Definition: drviews1.cxx:1322
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt, DropTargetHelper &rTargetHelper, ::sd::Window *pTargetWindow, sal_uInt16 nPage, SdrLayerID nLayer) override
ExecuteDrop.
Definition: drviews1.cxx:1339
bool SwitchPage(sal_uInt16 nPage, bool bAllowChangeFocus=true)
Switch to desired page.
Definition: drviews1.cxx:831
bool RenameSlide(sal_uInt16 nPageId, const OUString &rName)
Renames the given slide using an SvxNameDialog.
Definition: drviewsb.cxx:45
bool IsSwitchPageAllowed() const
Check if page change is allowed.
Definition: drviews1.cxx:1196
PageKind GetPageKind() const
virtual bool GetData(const css::datatransfer::DataFlavor &rFlavor, const OUString &rDestDoc) override
Definition: tabcontr.cxx:47
virtual ~TabControlTransferable() override
Definition: tabcontr.cxx:38
virtual void DragFinished(sal_Int8 nDropAction) override
Definition: tabcontr.cxx:52
virtual void AddSupportedFormats() override
Definition: tabcontr.cxx:42
void SendDeactivatePageEvent()
Inform all listeners of this control that the current page has been deactivated.
Definition: tabcontr.cxx:350
virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt) override
Definition: tabcontr.cxx:198
virtual ~TabControl() override
Definition: tabcontr.cxx:70
DrawViewShell * pDrViewSh
Definition: TabControl.hxx:56
virtual sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt) override
Definition: tabcontr.cxx:159
virtual void EndRenaming() override
Definition: tabcontr.cxx:323
virtual bool DeactivatePage() override
Definition: tabcontr.cxx:339
virtual void dispose() override
Definition: tabcontr.cxx:75
virtual bool StartRenaming() override
Definition: tabcontr.cxx:283
virtual void ActivatePage() override
Definition: tabcontr.cxx:329
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: tabcontr.cxx:89
void DragFinished()
Definition: tabcontr.cxx:154
virtual TabBarAllowRenamingReturnCode AllowRenaming() override
Definition: tabcontr.cxx:300
void SendActivatePageEvent()
Inform all listeners of this control that the current page has been activated.
Definition: tabcontr.cxx:344
virtual void DoubleClick() override
Definition: tabcontr.cxx:136
TabControl(DrawViewShell *pDrViewSh, vcl::Window *pParent)
Definition: tabcontr.cxx:57
virtual void Command(const CommandEvent &rCEvt) override
Definition: tabcontr.cxx:274
virtual void StartDrag(sal_Int8 nAction, const Point &rPosPixel) override
Definition: tabcontr.cxx:146
virtual void Select() override
Definition: tabcontr.cxx:82
SD_DLLPUBLIC DrawDocShell * GetDocSh() const
Definition: viewshel.cxx:1407
SdDrawDocument * GetDoc() const
Definition: viewshel.cxx:1412
::sd::View * GetView() const
Definition: ViewShell.hxx:144
SD_DLLPUBLIC SfxViewFrame * GetViewFrame() const
Definition: viewshel.cxx:118
virtual SdrEndTextEditKind SdrEndTextEdit(bool bDontDeleteReally=false) override
ends current text editing
Definition: sdview.cxx:772
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
virtual void SetHelpId(const OUString &) override
#define MOUSE_LEFT
constexpr OUStringLiteral HID_SD_TABBAR_PAGES
Definition: helpids.h:37
sal_Int8 mnAction
constexpr SdrLayerID SDRLAYER_NOTFOUND(-1)
TabBarAllowRenamingReturnCode
TABBAR_RENAMING_NO
TABBAR_RENAMING_YES
#define DND_ACTION_COPYMOVE
#define DND_ACTION_MOVE
#define DND_ACTION_COPY
#define DND_ACTION_NONE
signed char sal_Int8
sal_Int64 WinBits
WinBits const WB_DRAG
WinBits const WB_SIZEABLE
WinBits const WB_3DLOOK
WinBits const WB_BORDER
WinBits const WB_SCROLL