Line data Source code
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 :
21 : #include "TabControl.hxx"
22 :
23 : #include <sfx2/viewfrm.hxx>
24 : #include <svx/svdlayer.hxx>
25 : #include <svx/svdpagv.hxx>
26 : #include <sfx2/dispatch.hxx>
27 :
28 :
29 : #include "sdattr.hxx"
30 : #include "sdmod.hxx"
31 : #include "app.hrc"
32 : #include "glob.hrc"
33 : #include "res_bmp.hrc"
34 : #include "DrawViewShell.hxx"
35 : #include "GraphicViewShell.hxx"
36 : #include "helpids.h"
37 : #include "View.hxx"
38 : #include "sdpage.hxx"
39 : #include "drawdoc.hxx"
40 : #include "Window.hxx"
41 : #include "unmodpg.hxx"
42 : #include "DrawDocShell.hxx"
43 : #include "sdresid.hxx"
44 :
45 :
46 : namespace sd {
47 :
48 : // -----------------------------------------
49 : // - SdTabControl::SdPageObjsTransferable -
50 : // -----------------------------------------
51 :
52 0 : TabControl::TabControlTransferable::~TabControlTransferable()
53 : {
54 0 : }
55 :
56 : // -----------------------------------------------------------------------------
57 :
58 0 : void TabControl::TabControlTransferable::AddSupportedFormats()
59 : {
60 0 : AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
61 0 : }
62 :
63 : // -----------------------------------------------------------------------------
64 :
65 0 : sal_Bool TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& )
66 : {
67 0 : return sal_False;
68 : }
69 :
70 : // -----------------------------------------------------------------------------
71 :
72 0 : void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
73 : {
74 0 : mrParent.DragFinished( nDropAction );
75 0 : }
76 :
77 :
78 65 : TabControl::TabControl(DrawViewShell* pViewSh, Window* pParent) :
79 : TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
80 : DragSourceHelper( this ),
81 : DropTargetHelper( this ),
82 : pDrViewSh(pViewSh),
83 65 : bInternalMove(sal_False)
84 : {
85 65 : EnableEditMode();
86 65 : SetSizePixel(Size(0, 0));
87 65 : SetMaxPageWidth( 150 );
88 65 : SetHelpId( HID_SD_TABBAR_PAGES );
89 65 : }
90 :
91 :
92 65 : TabControl::~TabControl()
93 : {
94 65 : }
95 :
96 0 : void TabControl::Select()
97 : {
98 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
99 : pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON |
100 0 : SFX_CALLMODE_RECORD);
101 0 : }
102 :
103 0 : void TabControl::MouseButtonDown(const MouseEvent& rMEvt)
104 : {
105 0 : if (rMEvt.IsLeft()
106 0 : && !rMEvt.IsMod1()
107 0 : && !rMEvt.IsMod2()
108 0 : && !rMEvt.IsShift())
109 : {
110 0 : Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
111 0 : sal_uInt16 aPageId = GetPageId(aPos);
112 :
113 0 : if (aPageId == 0)
114 : {
115 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
116 :
117 : pDispatcher->Execute(SID_INSERTPAGE_QUICK,
118 0 : SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
119 : }
120 : }
121 :
122 : // A single left click with pressed control key on a tab page first
123 : // switches to that page before the usual handling (copying with drag
124 : // and drop) takes place.
125 0 : else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
126 : {
127 0 : pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
128 : }
129 :
130 : // When only the right button is pressed then first process a
131 : // synthesized left button click to make the page the current one
132 : // whose tab has been clicked. When then the actual right button
133 : // click is processed the resulting context menu relates to the
134 : // now current page.
135 0 : if (rMEvt.IsRight() && ! rMEvt.IsLeft())
136 : {
137 : MouseEvent aSyntheticEvent (
138 0 : rMEvt.GetPosPixel(),
139 0 : rMEvt.GetClicks(),
140 0 : rMEvt.GetMode(),
141 : MOUSE_LEFT,
142 0 : rMEvt.GetModifier());
143 0 : TabBar::MouseButtonDown(aSyntheticEvent);
144 : }
145 :
146 0 : TabBar::MouseButtonDown(rMEvt);
147 0 : }
148 :
149 0 : void TabControl::DoubleClick()
150 : {
151 0 : if (GetCurPageId() != 0)
152 : {
153 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
154 : pDispatcher->Execute( SID_MODIFYPAGE,
155 0 : SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
156 : }
157 0 : }
158 :
159 :
160 0 : void TabControl::StartDrag( sal_Int8, const Point& )
161 : {
162 0 : bInternalMove = sal_True;
163 :
164 : // object is delete by reference mechanismn
165 0 : ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
166 0 : }
167 :
168 :
169 0 : void TabControl::DragFinished( sal_Int8 )
170 : {
171 0 : bInternalMove = sal_False;
172 0 : }
173 :
174 :
175 0 : sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
176 : {
177 0 : sal_Int8 nRet = DND_ACTION_NONE;
178 :
179 0 : if( rEvt.mbLeaving )
180 0 : EndSwitchPage();
181 :
182 0 : if( !pDrViewSh->GetDocSh()->IsReadOnly() )
183 : {
184 0 : SdDrawDocument* pDoc = pDrViewSh->GetDoc();
185 0 : Point aPos( rEvt.maPosPixel );
186 :
187 0 : if( bInternalMove )
188 : {
189 0 : if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
190 0 : HideDropPos();
191 : else
192 : {
193 0 : ShowDropPos( aPos );
194 0 : nRet = rEvt.mnAction;
195 : }
196 : }
197 : else
198 : {
199 0 : HideDropPos();
200 :
201 0 : sal_Int32 nPageId = GetPageId( aPos ) - 1;
202 :
203 0 : if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
204 : {
205 0 : nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
206 0 : SwitchPage( aPos );
207 : }
208 : }
209 : }
210 :
211 0 : return nRet;
212 : }
213 :
214 :
215 0 : sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
216 : {
217 0 : SdDrawDocument* pDoc = pDrViewSh->GetDoc();
218 0 : Point aPos( rEvt.maPosPixel );
219 0 : sal_Int8 nRet = DND_ACTION_NONE;
220 :
221 0 : if( bInternalMove )
222 : {
223 0 : sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
224 :
225 0 : switch (rEvt.mnAction)
226 : {
227 : case DND_ACTION_MOVE:
228 0 : if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
229 : {
230 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
231 0 : pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
232 : }
233 0 : break;
234 :
235 : case DND_ACTION_COPY:
236 : {
237 : // Copying the selected page to the place that rEvt points
238 : // takes place in three steps:
239 : // 1. Create a copy of the selected page. This copy will
240 : // lie directly behind the selected page.
241 : // 2. Move the copy to the desired place.
242 : // 3. Select the copy.
243 0 : if (pDrViewSh->IsSwitchPageAllowed())
244 : {
245 : // 1. Create a copy.
246 0 : sal_uInt16 nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
247 : // 2. Move page. For this first switch to the copy:
248 : // MovePages operates on the currently selected page(s).
249 0 : pDrViewSh->SwitchPage (nPageNumOfCopy);
250 : // Adapt target page id when necessary, i.e. page copy
251 : // has been inserted in front of the target page.
252 0 : sal_uInt16 nPageNum = nPageId;
253 0 : if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (sal_uInt16)-1))
254 0 : nPageNum += 1;
255 0 : if (pDoc->MovePages(nPageNum))
256 : {
257 : // 3. Switch to the copy that has been moved to its
258 : // final destination. Use an asynchron slot call to
259 : // be executed after the still pending ones.
260 0 : if (nPageNumOfCopy >= nPageNum || (nPageNum == (sal_uInt16)-1))
261 0 : nPageNum += 1;
262 0 : SetCurPageId (GetPageId(nPageNum));
263 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
264 : pDispatcher->Execute(SID_SWITCHPAGE,
265 0 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
266 : }
267 : }
268 :
269 0 : break;
270 : }
271 : }
272 :
273 0 : nRet = rEvt.mnAction;
274 : }
275 : else
276 : {
277 0 : sal_Int32 nPageId = GetPageId( aPos ) - 1;
278 :
279 0 : if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
280 : {
281 0 : nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
282 : }
283 : }
284 :
285 0 : HideDropPos();
286 0 : EndSwitchPage();
287 :
288 0 : return nRet;
289 : }
290 :
291 0 : void TabControl::Command(const CommandEvent& rCEvt)
292 : {
293 0 : sal_uInt16 nCmd = rCEvt.GetCommand();
294 :
295 0 : if ( nCmd == COMMAND_CONTEXTMENU )
296 : {
297 0 : sal_Bool bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
298 : sal_uInt16 nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
299 0 : RID_DRAW_PAGETAB_POPUP;
300 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
301 0 : pDispatcher->ExecutePopup( SdResId( nResId ) );
302 : }
303 0 : }
304 :
305 0 : long TabControl::StartRenaming()
306 : {
307 0 : sal_Bool bOK = sal_False;
308 :
309 0 : if (pDrViewSh->GetPageKind() == PK_STANDARD)
310 : {
311 0 : bOK = sal_True;
312 :
313 0 : ::sd::View* pView = pDrViewSh->GetView();
314 :
315 0 : if ( pView->IsTextEdit() )
316 0 : pView->SdrEndTextEdit();
317 : }
318 :
319 0 : return( bOK );
320 : }
321 :
322 0 : long TabControl::AllowRenaming()
323 : {
324 0 : sal_Bool bOK = sal_True;
325 :
326 0 : String aNewName( GetEditText() );
327 0 : String aCompareName( GetPageText( GetEditPageId() ) );
328 :
329 0 : if( aCompareName != aNewName )
330 : {
331 : // rename page
332 0 : if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
333 : {
334 0 : SetEditText( aNewName );
335 0 : EndRenaming();
336 : }
337 : else
338 : {
339 0 : bOK = sal_False;
340 : }
341 : }
342 0 : return( bOK );
343 : }
344 :
345 0 : void TabControl::EndRenaming()
346 : {
347 0 : if( !IsEditModeCanceled() )
348 0 : pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
349 0 : }
350 :
351 0 : void TabControl::ActivatePage()
352 : {
353 0 : if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
354 : {
355 0 : SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
356 : pDispatcher->Execute(SID_SWITCHPAGE,
357 0 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
358 : }
359 0 : }
360 :
361 0 : long TabControl::DeactivatePage()
362 : {
363 0 : return pDrViewSh->IsSwitchPageAllowed();
364 : }
365 :
366 :
367 :
368 :
369 0 : void TabControl::SendActivatePageEvent (void)
370 : {
371 : CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
372 0 : reinterpret_cast<void*>(GetCurPageId()));
373 0 : }
374 :
375 :
376 :
377 :
378 0 : void TabControl::SendDeactivatePageEvent (void)
379 : {
380 : CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
381 0 : reinterpret_cast<void*>(GetCurPageId()));
382 0 : }
383 :
384 33 : } // end of namespace sd
385 :
386 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|