1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26
27 #include "TabControl.hxx"
28
29 #include <sfx2/viewfrm.hxx>
30 #include <svx/svdlayer.hxx>
31 #include <svx/svdpagv.hxx>
32 #include <sfx2/dispatch.hxx>
33
34
35 #include "sdattr.hxx"
36 #include "app.hxx"
37 #include "app.hrc"
38 #include "glob.hrc"
39 #include "res_bmp.hrc"
40 #include "DrawViewShell.hxx"
41 #include "GraphicViewShell.hxx"
42 #include "helpids.h"
43 #include "View.hxx"
44 #include "sdpage.hxx"
45 #include "drawdoc.hxx"
46 #include "Window.hxx"
47 #include "unmodpg.hxx"
48 #include "DrawDocShell.hxx"
49 #include "sdresid.hxx"
50
51
52 namespace sd {
53
54 #define SWITCH_TIMEOUT 20
55
56 // -----------------------------------------
57 // - SdTabControl::SdPageObjsTransferable -
58 // -----------------------------------------
59
~TabControlTransferable()60 TabControl::TabControlTransferable::~TabControlTransferable()
61 {
62 }
63
64 // -----------------------------------------------------------------------------
65
AddSupportedFormats()66 void TabControl::TabControlTransferable::AddSupportedFormats()
67 {
68 AddFormat( SOT_FORMATSTR_ID_STARDRAW_TABBAR );
69 }
70
71 // -----------------------------------------------------------------------------
72
GetData(const::com::sun::star::datatransfer::DataFlavor &)73 sal_Bool TabControl::TabControlTransferable::GetData( const ::com::sun::star::datatransfer::DataFlavor& )
74 {
75 return sal_False;
76 }
77
78 // -----------------------------------------------------------------------------
79
DragFinished(sal_Int8 nDropAction)80 void TabControl::TabControlTransferable::DragFinished( sal_Int8 nDropAction )
81 {
82 mrParent.DragFinished( nDropAction );
83 }
84
85 /*************************************************************************
86 |*
87 |* Standard-Konstruktor
88 |*
89 \************************************************************************/
90
TabControl(DrawViewShell * pViewSh,Window * pParent)91 TabControl::TabControl(DrawViewShell* pViewSh, Window* pParent) :
92 TabBar( pParent, WinBits( WB_BORDER | WB_3DLOOK | WB_SCROLL | WB_SIZEABLE | WB_DRAG) ),
93 DragSourceHelper( this ),
94 DropTargetHelper( this ),
95 RrePageID(1),
96 pDrViewSh(pViewSh),
97 bInternalMove(sal_False)
98 {
99 EnableEditMode();
100 SetSizePixel(Size(0, 0));
101 SetMaxPageWidth( 150 );
102 SetHelpId( HID_SD_TABBAR_PAGES );
103 }
104
105 /*************************************************************************
106 |*
107 |* Destruktor
108 |*
109 \************************************************************************/
110
~TabControl()111 TabControl::~TabControl()
112 {
113 }
114
115 /*************************************************************************
116 |*
117 \************************************************************************/
118
Select()119 void TabControl::Select()
120 {
121 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
122 pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON |
123 SFX_CALLMODE_RECORD);
124 }
125
126 /*************************************************************************
127 |*
128 \************************************************************************/
129
MouseButtonDown(const MouseEvent & rMEvt)130 void TabControl::MouseButtonDown(const MouseEvent& rMEvt)
131 {
132 if (rMEvt.IsLeft()
133 && !rMEvt.IsMod1()
134 && !rMEvt.IsMod2()
135 && !rMEvt.IsShift())
136 {
137 Point aPos = PixelToLogic( rMEvt.GetPosPixel() );
138 sal_uInt16 aPageId = GetPageId(aPos);
139
140 //Solution: initialize
141 if(RrePageID!=aPageId)
142 pDrViewSh->FreshNavigatrEntry();
143 RrePageID=aPageId;
144 if (aPageId == 0)
145 {
146 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
147
148 pDispatcher->Execute(SID_INSERTPAGE_QUICK,
149 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
150 }
151 }
152
153 // A single left click with pressed control key on a tab page first
154 // switches to that page before the usual handling (copying with drag
155 // and drop) takes place.
156 else if (rMEvt.IsLeft() && rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsShift())
157 {
158 pDrViewSh->SwitchPage (GetPageId (rMEvt.GetPosPixel()) - 1);
159 }
160
161 // When only the right button is pressed then first process a
162 // synthesized left button click to make the page the current one
163 // whose tab has been clicked. When then the actual right button
164 // click is processed the resulting context menu relates to the
165 // now current page.
166 if (rMEvt.IsRight() && ! rMEvt.IsLeft())
167 {
168 MouseEvent aSyntheticEvent (
169 rMEvt.GetPosPixel(),
170 rMEvt.GetClicks(),
171 rMEvt.GetMode(),
172 MOUSE_LEFT,
173 rMEvt.GetModifier());
174 TabBar::MouseButtonDown(aSyntheticEvent);
175 }
176
177 TabBar::MouseButtonDown(rMEvt);
178 }
179
180 /*************************************************************************
181 |*
182 \************************************************************************/
183
DoubleClick()184 void TabControl::DoubleClick()
185 {
186 if (GetCurPageId() != 0)
187 {
188 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
189 pDispatcher->Execute( SID_MODIFYPAGE,
190 SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
191 }
192 }
193
194 /*************************************************************************
195 |*
196 |* StartDrag-Request
197 |*
198 \************************************************************************/
199
StartDrag(sal_Int8,const Point &)200 void TabControl::StartDrag( sal_Int8, const Point& )
201 {
202 bInternalMove = sal_True;
203
204 // object is delete by reference mechanismn
205 ( new TabControl::TabControlTransferable( *this ) )->StartDrag( this, DND_ACTION_COPYMOVE );
206 }
207
208 /*************************************************************************
209 |*
210 |* DragFinished
211 |*
212 \************************************************************************/
213
DragFinished(sal_Int8)214 void TabControl::DragFinished( sal_Int8 )
215 {
216 bInternalMove = sal_False;
217 }
218
219 /*************************************************************************
220 |*
221 |* AcceptDrop-Event
222 |*
223 \************************************************************************/
224
AcceptDrop(const AcceptDropEvent & rEvt)225 sal_Int8 TabControl::AcceptDrop( const AcceptDropEvent& rEvt )
226 {
227 sal_Int8 nRet = DND_ACTION_NONE;
228
229 if( rEvt.mbLeaving )
230 EndSwitchPage();
231
232 if( !pDrViewSh->GetDocSh()->IsReadOnly() )
233 {
234 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
235 Point aPos( rEvt.maPosPixel );
236
237 if( bInternalMove )
238 {
239 if( rEvt.mbLeaving || ( pDrViewSh->GetEditMode() == EM_MASTERPAGE ) )
240 HideDropPos();
241 else
242 {
243 ShowDropPos( aPos );
244 nRet = rEvt.mnAction;
245 }
246 }
247 else
248 {
249 HideDropPos();
250
251 sal_Int32 nPageId = GetPageId( aPos ) - 1;
252
253 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
254 {
255 nRet = pDrViewSh->AcceptDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
256 SwitchPage( aPos );
257 }
258 }
259 }
260
261 return nRet;
262 }
263
264 /*************************************************************************
265 |*
266 |* ExecuteDrop-Event
267 |*
268 \************************************************************************/
269
ExecuteDrop(const ExecuteDropEvent & rEvt)270 sal_Int8 TabControl::ExecuteDrop( const ExecuteDropEvent& rEvt )
271 {
272 SdDrawDocument* pDoc = pDrViewSh->GetDoc();
273 Point aPos( rEvt.maPosPixel );
274 sal_Int8 nRet = DND_ACTION_NONE;
275
276 if( bInternalMove )
277 {
278 sal_uInt16 nPageId = ShowDropPos( aPos ) - 1;
279
280 switch (rEvt.mnAction)
281 {
282 case DND_ACTION_MOVE:
283 if( pDrViewSh->IsSwitchPageAllowed() && pDoc->MovePages( nPageId ) )
284 {
285 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
286 pDispatcher->Execute(SID_SWITCHPAGE, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
287 }
288 break;
289
290 case DND_ACTION_COPY:
291 {
292 // Copying the selected page to the place that rEvt points
293 // takes place in three steps:
294 // 1. Create a copy of the selected page. This copy will
295 // lie directly behind the selected page.
296 // 2. Move the copy to the desired place.
297 // 3. Select the copy.
298 if (pDrViewSh->IsSwitchPageAllowed())
299 {
300 // 1. Create a copy.
301 sal_uInt16 nPageNumOfCopy = pDoc->DuplicatePage (GetCurPageId() - 1);
302 // 2. Move page. For this first switch to the copy:
303 // MovePages operates on the currently selected page(s).
304 pDrViewSh->SwitchPage (nPageNumOfCopy);
305 // Adapt target page id when necessary, i.e. page copy
306 // has been inserted in front of the target page.
307 sal_uInt16 nPageNum = nPageId;
308 if ((nPageNumOfCopy <= nPageNum) && (nPageNum != (sal_uInt16)-1))
309 nPageNum += 1;
310 if (pDoc->MovePages(nPageNum))
311 {
312 // 3. Switch to the copy that has been moved to its
313 // final destination. Use an asynchron slot call to
314 // be executed after the still pending ones.
315 if (nPageNumOfCopy >= nPageNum || (nPageNum == (sal_uInt16)-1))
316 nPageNum += 1;
317 SetCurPageId (GetPageId(nPageNum));
318 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
319 pDispatcher->Execute(SID_SWITCHPAGE,
320 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
321 }
322 }
323
324 break;
325 }
326 }
327
328 nRet = rEvt.mnAction;
329 }
330 else
331 {
332 sal_Int32 nPageId = GetPageId( aPos ) - 1;
333
334 if( ( nPageId >= 0 ) && pDoc->GetPage( (sal_uInt16)nPageId ) )
335 {
336 nRet = pDrViewSh->ExecuteDrop( rEvt, *this, NULL, (sal_uInt16)nPageId, SDRLAYER_NOTFOUND );
337 }
338 }
339
340 HideDropPos();
341 EndSwitchPage();
342
343 return nRet;
344 }
345
346 /*************************************************************************
347 |*
348 \************************************************************************/
349
Command(const CommandEvent & rCEvt)350 void TabControl::Command(const CommandEvent& rCEvt)
351 {
352 sal_uInt16 nCmd = rCEvt.GetCommand();
353
354 if ( nCmd == COMMAND_CONTEXTMENU )
355 {
356 sal_Bool bGraphicShell = pDrViewSh->ISA(GraphicViewShell);
357 sal_uInt16 nResId = bGraphicShell ? RID_GRAPHIC_PAGETAB_POPUP :
358 RID_DRAW_PAGETAB_POPUP;
359 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
360 pDispatcher->ExecutePopup( SdResId( nResId ) );
361 }
362 }
363
364 /*************************************************************************
365 |*
366 \************************************************************************/
367
StartRenaming()368 long TabControl::StartRenaming()
369 {
370 sal_Bool bOK = sal_False;
371
372 if (pDrViewSh->GetPageKind() == PK_STANDARD)
373 {
374 bOK = sal_True;
375
376 ::sd::View* pView = pDrViewSh->GetView();
377
378 if ( pView->IsTextEdit() )
379 pView->SdrEndTextEdit();
380 }
381
382 return( bOK );
383 }
384
385 /*************************************************************************
386 |*
387 \************************************************************************/
388
AllowRenaming()389 long TabControl::AllowRenaming()
390 {
391 sal_Bool bOK = sal_True;
392
393 String aNewName( GetEditText() );
394 String aCompareName( GetPageText( GetEditPageId() ) );
395
396 if( aCompareName != aNewName )
397 {
398 // Seite umbenennen
399 if( pDrViewSh->GetDocSh()->CheckPageName( this, aNewName ) )
400 {
401 SetEditText( aNewName );
402 EndRenaming();
403 }
404 else
405 {
406 bOK = sal_False;
407 }
408 }
409 return( bOK );
410 }
411
412 /*************************************************************************
413 |*
414 \************************************************************************/
415
EndRenaming()416 void TabControl::EndRenaming()
417 {
418 if( !IsEditModeCanceled() )
419 pDrViewSh->RenameSlide( GetEditPageId(), GetEditText() );
420 }
421
422
423 /*************************************************************************
424 |*
425 \************************************************************************/
426
ActivatePage()427 void TabControl::ActivatePage()
428 {
429 if ( /*IsInSwitching && */ pDrViewSh->IsSwitchPageAllowed() )
430 {
431 SfxDispatcher* pDispatcher = pDrViewSh->GetViewFrame()->GetDispatcher();
432 pDispatcher->Execute(SID_SWITCHPAGE,
433 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
434 }
435 }
436
437
438 /*************************************************************************
439 |*
440 \************************************************************************/
441
DeactivatePage()442 long TabControl::DeactivatePage()
443 {
444 return pDrViewSh->IsSwitchPageAllowed();
445 }
446
447
448
449
SendActivatePageEvent(void)450 void TabControl::SendActivatePageEvent (void)
451 {
452 CallEventListeners (VCLEVENT_TABBAR_PAGEACTIVATED,
453 reinterpret_cast<void*>(GetCurPageId()));
454 }
455
456
457
458
SendDeactivatePageEvent(void)459 void TabControl::SendDeactivatePageEvent (void)
460 {
461 CallEventListeners (VCLEVENT_TABBAR_PAGEDEACTIVATED,
462 reinterpret_cast<void*>(GetCurPageId()));
463 }
464
465 } // end of namespace sd
466