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