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