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 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
|
/* -*- 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 <futext.hxx>
#include <editeng/eeitem.hxx>
#include <svx/sdrpagewindow.hxx>
#include <svx/sdrpaintwindow.hxx>
#include <tools/urlobj.hxx>
#include <vcl/help.hxx>
#include <editeng/fhgtitem.hxx>
#include <svl/intitem.hxx>
#include <svl/stritem.hxx>
#include <svx/svdotext.hxx>
#include <editeng/flditem.hxx>
#include <svl/style.hxx>
#include <svx/svdpagv.hxx>
#include <svx/sdtmfitm.hxx>
#include <svx/sdtagitm.hxx>
#include <svx/sdtfsitm.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
#include <editeng/editeng.hxx>
#include <svx/svdoutl.hxx>
#include <svx/svxids.hrc>
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <sfx2/docfile.hxx>
#include <editeng/outlobj.hxx>
#include <osl/diagnose.h>
#include <editeng/frmdiritem.hxx>
#include <svx/svdetc.hxx>
#include <editeng/editview.hxx>
#include <sdresid.hxx>
#include <app.hrc>
#include <ViewShell.hxx>
#include <ViewShellBase.hxx>
#include <View.hxx>
#include <Window.hxx>
#include <drawdoc.hxx>
#include <sdpage.hxx>
#include <FrameView.hxx>
#include <ToolBarManager.hxx>
#include <DrawDocShell.hxx>
#include <strings.hrc>
#include <pres.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::linguistic2;
namespace sd {
const sal_uInt16 SidArray[] = {
SID_STYLE_FAMILY2, // 5542
SID_STYLE_FAMILY5, // 5545
SID_REDO, // 5700
SID_UNDO, // 5701
SID_CUT, // 5710
SID_COPY, // 5711
SID_ATTR_TABSTOP, // 10002
SID_ATTR_CHAR_FONT, // 10007
SID_ATTR_CHAR_POSTURE, // 10008
SID_ATTR_CHAR_WEIGHT, // 10009
SID_ATTR_CHAR_SHADOWED, // 10010
SID_ATTR_CHAR_STRIKEOUT, // 10013
SID_ATTR_CHAR_UNDERLINE, // 10014
SID_ATTR_CHAR_FONTHEIGHT, // 10015
SID_ATTR_CHAR_COLOR, // 10017
SID_ATTR_CHAR_KERNING, // 10018
SID_ATTR_CHAR_CASEMAP, // 10019
SID_ATTR_PARA_ADJUST_LEFT, // 10028
SID_ATTR_PARA_ADJUST_RIGHT, // 10029
SID_ATTR_PARA_ADJUST_CENTER, // 10030
SID_ATTR_PARA_ADJUST_BLOCK, // 10031
SID_ATTR_PARA_LINESPACE_10, // 10034
SID_ATTR_PARA_LINESPACE_15, // 10035
SID_ATTR_PARA_LINESPACE_20, // 10036
SID_ATTR_PARA_ULSPACE, // 10042
SID_ATTR_PARA_LRSPACE, // 10043
SID_ATTR_TRANSFORM_POS_X, // 10088
SID_ATTR_TRANSFORM_POS_Y, // 10089
SID_ATTR_TRANSFORM_WIDTH, // 10090
SID_ATTR_TRANSFORM_HEIGHT, // 10091
SID_ATTR_TRANSFORM_ROT_X, // 10093
SID_ATTR_TRANSFORM_ROT_Y, // 10094
SID_ATTR_TRANSFORM_ANGLE, // 10095 //Added
SID_OUTLINE_UP, // 10150
SID_OUTLINE_DOWN, // 10151
SID_OUTLINE_LEFT, // 10152
SID_OUTLINE_RIGHT, // 10153
SID_ATTR_TRANSFORM_PROTECT_POS, // 10236
SID_ATTR_TRANSFORM_PROTECT_SIZE, // 10237 //Added
SID_FORMTEXT_STYLE, // 10257
SID_SET_SUPER_SCRIPT, // 10294
SID_SET_SUB_SCRIPT, // 10295
SID_ATTR_TRANSFORM_AUTOWIDTH, // 10310
SID_ATTR_TRANSFORM_AUTOHEIGHT, // 10311 //Added
SID_HYPERLINK_GETLINK, // 10361
SID_DEC_INDENT, // 10461
SID_INC_INDENT, // 10462
SID_CHARMAP, // 10503
SID_TEXTDIRECTION_LEFT_TO_RIGHT, // 10907
SID_TEXTDIRECTION_TOP_TO_BOTTOM, // 10908
SID_ATTR_PARA_LEFT_TO_RIGHT, // 10950
SID_ATTR_PARA_RIGHT_TO_LEFT, // 10951
SID_PARASPACE_INCREASE, // 11145
SID_PARASPACE_DECREASE, // 11146
FN_NUM_BULLET_ON, // 20138
0 };
/**
* base class for text functions
*/
FuText::FuText( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
: FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
, bFirstObjCreated(false)
, bJustEndedEdit(false)
, rRequest (rReq)
{
}
rtl::Reference<FuPoor> FuText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
{
rtl::Reference<FuPoor> xFunc( new FuText( pViewSh, pWin, pView, pDoc, rReq ) );
return xFunc;
}
void FuText::disposing()
{
if(mpView)
{
if(mpView->SdrEndTextEdit() == SdrEndTextEditKind::Deleted)
mxTextObj.reset(nullptr);
// reset the RequestHandler of the used Outliner to the handler of the document
::Outliner* pOutliner = mpView->GetTextEditOutliner();
if (pOutliner)
pOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
}
}
/*************************************************************************
|*
|* Execute functionality of this class:
|*
|* #71422: Start the functionality of this class in this method
|* and not in the ctor.
|* If you construct an object of this class and you put the
|* address of this object to pFuActual you've got a problem,
|* because some methods inside DoExecute use the pFuActual-Pointer.
|* If the code inside DoExecute is executed inside the ctor,
|* the value of pFuActual is not right. And the value will not
|* be right until the ctor finished !!!
|*
\************************************************************************/
void FuText::DoExecute( SfxRequest& )
{
mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBarShell(
ToolBarManager::ToolBarGroup::Function,
ToolbarId::Draw_Text_Toolbox_Sd);
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Edit);
MouseEvent aMEvt(mpWindow->GetPointerPosPixel());
if (nSlotId == SID_TEXTEDIT)
{
// Try to select an object
SdrPageView* pPV = mpView->GetSdrPageView();
SdrViewEvent aVEvt;
mpView->PickAnything(aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
mpView->MarkObj(aVEvt.mpRootObj, pPV);
mxTextObj.reset( dynamic_cast< SdrTextObj* >( aVEvt.mpObj ) );
}
else if (mpView->AreObjectsMarked())
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1)
{
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
mxTextObj.reset( dynamic_cast< SdrTextObj* >( pObj ) );
}
}
// check for table
if (mpView->AreObjectsMarked())
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1)
{
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
if( pObj && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == SdrObjKind::Table) )
{
mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBarShell(ToolBarManager::ToolBarGroup::Function, ToolbarId::Draw_Table_Toolbox);
}
}
}
bool bQuickDrag = true;
const SfxItemSet* pArgs = rRequest.GetArgs();
if (pArgs
// test for type before using
&& SID_TEXTEDIT == nSlotId
&& SfxItemState::SET == pArgs->GetItemState(SID_TEXTEDIT)
&& static_cast<const SfxUInt16Item&>(pArgs->Get(SID_TEXTEDIT)).GetValue() == 2)
{
// Selection by doubleclick -> don't allow QuickDrag
bQuickDrag = false;
}
SetInEditMode(aMEvt, bQuickDrag);
}
bool FuText::MouseButtonDown(const MouseEvent& rMEvt)
{
bMBDown = true;
bJustEndedEdit = false;
bool bReturn = FuDraw::MouseButtonDown(rMEvt);
SdrViewEvent aVEvt;
SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
// handle URL also during the text editing
if (rMEvt.GetClicks() == 1 && rMEvt.IsLeft() && rMEvt.IsMod1())
{
OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
if (mxTextObj.is() && pOLV && pOLV->GetFieldUnderMousePointer())
{
const SvxFieldItem* pFieldItem = pOLV->GetFieldUnderMousePointer();
if (pFieldItem)
{
const SvxFieldData* pField = pFieldItem->GetField();
if (auto pURLField = dynamic_cast< const SvxURLField *>( pField ))
{
eHit = SdrHitKind::MarkedObject;
aVEvt.meEvent = SdrEventKind::ExecuteUrl;
aVEvt.mpURLField = pURLField;
}
}
}
}
if (eHit == SdrHitKind::TextEdit)
{
// hit text -> SdrView handles event
if (mpView->MouseButtonDown(rMEvt, mpWindow->GetOutDev()))
return true;
}
if (rMEvt.GetClicks() == 1)
{
if (mpView->IsTextEdit() && eHit != SdrHitKind::MarkedObject && eHit != SdrHitKind::Handle)
{
// finish text input
if(mpView->SdrEndTextEdit() == SdrEndTextEditKind::Deleted)
{
/* Bugfix from MBA: during a double click onto the unused? area
in text mode, we get with the second click eHit =
SdrHitKind::TextEditObj since it goes to the TextObject which was
created with the first click. But this is removed by
SdrEndTextEdit since it is empty. But it is still in the mark
list. The call MarkObj further below accesses then the dead
object. As a simple fix, we determine eHit after
SdrEndTextEdit again, this returns then SdrHitKind::NONE. */
mxTextObj.reset(nullptr);
eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
}
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Edit);
}
if (rMEvt.IsLeft() || rMEvt.IsRight())
{
mpWindow->CaptureMouse();
SdrPageView* pPV = mpView->GetSdrPageView();
if (eHit == SdrHitKind::TextEdit)
{
SetInEditMode(rMEvt, false);
}
else
{
// Don't remark table when clicking in it, mark change triggers a lot of updating
bool bMarkChanges = true;
rtl::Reference< sdr::SelectionController > xSelectionController(mpView->getSelectionController());
if (eHit == SdrHitKind::TextEditObj && xSelectionController.is())
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1 && rMarkList.GetMark(0)->GetMarkedSdrObj() == aVEvt.mpRootObj)
bMarkChanges = false;
}
if (eHit != SdrHitKind::Handle)
{
// deselect selection
if (!rMEvt.IsShift() && eHit == SdrHitKind::TextEditObj)
{
if(bMarkChanges)
{
mpView->UnmarkAll();
mpView->SetDragMode(SdrDragMode::Move);
}
}
}
if ( aVEvt.meEvent == SdrEventKind::ExecuteUrl ||
eHit == SdrHitKind::Handle ||
eHit == SdrHitKind::MarkedObject ||
eHit == SdrHitKind::TextEditObj ||
( eHit == SdrHitKind::UnmarkedObject && bFirstObjCreated &&
!bPermanent ) )
{
// Handle, hit marked or unmarked object
if (eHit == SdrHitKind::TextEditObj)
{
/* hit text of unmarked object:
select object and set to EditMode */
if (bMarkChanges)
mpView->MarkObj(aVEvt.mpRootObj, pPV);
if (auto pSdrTextObj = dynamic_cast<SdrTextObj*>(aVEvt.mpObj))
{
mxTextObj.reset( pSdrTextObj );
}
SetInEditMode(rMEvt, true);
}
else if (aVEvt.meEvent == SdrEventKind::ExecuteUrl && !rMEvt.IsMod2())
{
// execute URL
mpWindow->ReleaseMouse();
SfxStringItem aStrItem(SID_FILE_NAME, aVEvt.mpURLField->GetURL());
SfxStringItem aReferer(SID_REFERER, mpDocSh->GetMedium()->GetName());
SfxBoolItem aBrowseItem( SID_BROWSE, true );
SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
mpWindow->ReleaseMouse();
if (rMEvt.IsMod1())
{
// open in new frame
pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
{ &aStrItem, &aBrowseItem, &aReferer });
}
else
{
// open in current frame
SfxFrameItem aFrameItem(SID_DOCFRAME, pFrame);
pFrame->GetDispatcher()->ExecuteList(SID_OPENDOC,
SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
{ &aStrItem, &aFrameItem, &aBrowseItem, &aReferer });
}
}
else
{
// drag object or handle
// #i78748#
// do the EndTextEdit first, it will delete the handles and force a
// recreation. This will make aVEvt.mpHdl to point to a deleted handle,
// thus it is necessary to reset it and to get it again.
// #i112855#
// cl: I'm not sure why we checked here also for mxTextObj->GetOutlinerParaObject
// this caused SdrEndTextEdit() to be called also when not in text editing and
// this does not make sense and caused troubles. (see issue 112855)
if( mpView->IsTextEdit() )
{
mpView->SdrEndTextEdit();
bJustEndedEdit = true;
if(aVEvt.mpHdl)
{
// force new handle identification, the pointer will be dead here
// since SdrEndTextEdit has reset (deleted) the handles.
aVEvt.mpHdl = nullptr;
mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
}
}
if (!aVEvt.mpHdl)
{
if( eHit == SdrHitKind::UnmarkedObject )
{
if ( !rMEvt.IsShift() )
mpView->UnmarkAll();
mpView->MarkObj(aVEvt.mpRootObj, pPV);
}
// Drag object
bFirstMouseMove = true;
aDragTimer.Start();
}
if ( ! rMEvt.IsRight())
{
// we need to pick again since SdrEndTextEdit can rebuild the handles list
eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
if( (eHit == SdrHitKind::Handle) || (eHit == SdrHitKind::MarkedObject) )
{
sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
mpView->BegDragObj(aMDPos, nullptr, aVEvt.mpHdl, nDrgLog);
}
}
bReturn = true;
}
}
else if ( nSlotId != SID_TEXTEDIT &&
(bPermanent || !bFirstObjCreated) )
{
// create object
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Create);
sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
mpView->BegCreateObj(aMDPos, nullptr, nDrgLog);
}
else
{
// select
if( !rMEvt.IsShift() )
mpView->UnmarkAll();
mpView->BegMarkObj( aMDPos );
}
}
}
}
else if ( rMEvt.GetClicks() == 2 && !mpView->IsTextEdit() )
{
MouseEvent aMEvt( mpWindow->GetPointerPosPixel() );
SetInEditMode( aMEvt, false );
}
if (!bIsInDragMode)
{
ForcePointer(&rMEvt);
mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
}
return bReturn;
}
bool FuText::MouseMove(const MouseEvent& rMEvt)
{
bool bReturn = FuDraw::MouseMove(rMEvt);
if (aDragTimer.IsActive() )
{
if( bFirstMouseMove )
bFirstMouseMove = false;
else
aDragTimer.Stop();
}
if (!bReturn && mpView->IsAction() && !mpDocSh->IsReadOnly())
{
Point aPix(rMEvt.GetPosPixel());
Point aPnt(mpWindow->PixelToLogic(aPix));
ForceScroll(aPix);
mpView->MovAction(aPnt);
}
ForcePointer(&rMEvt);
return bReturn;
}
void FuText::ImpSetAttributesForNewTextObject(SdrTextObj* pTxtObj)
{
if(mpDoc->GetDocumentType() == DocumentType::Impress)
{
if( nSlotId == SID_ATTR_CHAR )
{
/* Create Impress text object (rescales to line height)
We get the correct height during the subsequent creation of the
object, otherwise we draw too much */
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextMinFrameHeightItem(0));
aSet.Put(makeSdrTextAutoGrowWidthItem(false));
aSet.Put(makeSdrTextAutoGrowHeightItem(true));
pTxtObj->SetMergedItemSet(aSet);
pTxtObj->AdjustTextFrameWidthAndHeight();
aSet.Put(makeSdrTextMaxFrameHeightItem(pTxtObj->GetLogicRect().GetSize().Height()));
pTxtObj->SetMergedItemSet(aSet);
const SfxViewShell* pCurrentViewShell = SfxViewShell::Current();
if (pCurrentViewShell && (pCurrentViewShell->isLOKMobilePhone() || pCurrentViewShell->isLOKTablet()))
pTxtObj->SetText(SdResId(STR_PRESOBJ_TEXT_EDIT_MOBILE));
}
else if( nSlotId == SID_ATTR_CHAR_VERTICAL )
{
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextMinFrameWidthItem(0));
aSet.Put(makeSdrTextAutoGrowWidthItem(true));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
// Needs to be set since default is SDRTEXTHORZADJUST_BLOCK
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
pTxtObj->SetMergedItemSet(aSet);
pTxtObj->AdjustTextFrameWidthAndHeight();
aSet.Put(makeSdrTextMaxFrameWidthItem(pTxtObj->GetLogicRect().GetSize().Width()));
pTxtObj->SetMergedItemSet(aSet);
}
}
else
{
if( nSlotId == SID_ATTR_CHAR_VERTICAL )
{
// draw text object, needs to be initialized when vertical text is used
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextAutoGrowWidthItem(true));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
// Set defaults for vertical click-n'drag text object, pool defaults are:
// SdrTextVertAdjustItem: SDRTEXTVERTADJUST_TOP
// SdrTextHorzAdjustItem: SDRTEXTHORZADJUST_BLOCK
// Analog to that:
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BLOCK));
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
pTxtObj->SetMergedItemSet(aSet);
}
}
}
void FuText::ImpSetAttributesFitToSize(SdrTextObj* pTxtObj)
{
// FitToSize (fit to frame)
SfxItemSetFixed<SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWWIDTH> aSet(mpViewShell->GetPool());
aSet.Put(SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_PROPORTIONAL));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
aSet.Put(makeSdrTextAutoGrowWidthItem(false));
pTxtObj->SetMergedItemSet(aSet);
pTxtObj->AdjustTextFrameWidthAndHeight();
}
void FuText::ImpSetAttributesFitToSizeVertical(SdrTextObj* pTxtObj)
{
SfxItemSetFixed<SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWWIDTH> aSet(mpViewShell->GetPool());
aSet.Put(SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_PROPORTIONAL));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
aSet.Put(makeSdrTextAutoGrowWidthItem(false));
pTxtObj->SetMergedItemSet(aSet);
pTxtObj->AdjustTextFrameWidthAndHeight();
}
void FuText::ImpSetAttributesFitCommon(SdrTextObj* pTxtObj)
{
// Normal Textobject
if (mpDoc->GetDocumentType() != DocumentType::Impress)
return;
if( nSlotId == SID_ATTR_CHAR )
{
// Impress text object (rescales to line height)
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextMinFrameHeightItem(0));
aSet.Put(makeSdrTextMaxFrameHeightItem(0));
aSet.Put(makeSdrTextAutoGrowHeightItem(true));
aSet.Put(makeSdrTextAutoGrowWidthItem(false));
pTxtObj->SetMergedItemSet(aSet);
}
else if( nSlotId == SID_ATTR_CHAR_VERTICAL )
{
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextMinFrameWidthItem(0));
aSet.Put(makeSdrTextMaxFrameWidthItem(0));
aSet.Put(makeSdrTextAutoGrowWidthItem(true));
aSet.Put(makeSdrTextAutoGrowHeightItem(false));
pTxtObj->SetMergedItemSet(aSet);
}
pTxtObj->AdjustTextFrameWidthAndHeight();
}
bool FuText::MouseButtonUp(const MouseEvent& rMEvt)
{
bool bReturn = false;
if (aDragTimer.IsActive())
{
aDragTimer.Stop();
bIsInDragMode = false;
}
mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
if( (mpView && mpView->MouseButtonUp(rMEvt, mpWindow->GetOutDev())) || rMEvt.GetClicks() == 2 )
return true; // handle event from SdrView
bool bEmptyTextObj = false;
if (mxTextObj.is())
{
bool bReset = true;
if (mpView)
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1
&& ( rMarkList.GetMark(0)->GetMarkedSdrObj() == mxTextObj.get()) )
{
if( mxTextObj.is() && !GetTextObj()->GetOutlinerParaObject() )
bEmptyTextObj = true;
else
bFirstObjCreated = true;
bReset = false;
}
}
if (bReset)
{
mxTextObj.reset(nullptr);
}
}
if( mpView && mpView->IsDragObj())
{
// object was moved
FrameView* pFrameView = mpViewShell->GetFrameView();
bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
if (bDragWithCopy)
{
bDragWithCopy = !mpView->IsPresObjSelected(false);
}
mpView->SetDragWithCopy(bDragWithCopy);
mpView->EndDragObj( mpView->IsDragWithCopy() );
mpView->ForceMarkedToAnotherPage();
mpView->SetCurrentObj(SdrObjKind::Text);
sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
if (bJustEndedEdit)
{
bJustEndedEdit = false;
FuPoor::cancel();
}
if ((rMEvt.GetClicks() != 2) &&
!rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsRight() &&
std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
{
/*************************************************************
* From text mode, you don't want to rotate immediately.
**************************************************************/
SdrPageView* pPV;
SdrObject* pObj = mpView->PickObj(aMDPos, mpView->getHitTolLog(), pPV, SdrSearchOptions::ALSOONMASTER | SdrSearchOptions::BEFOREMARK);
if (pObj && pPV->IsObjMarkable(pObj))
{
mpView->UnmarkAllObj();
mpView->MarkObj(pObj,pPV);
return bReturn;
}
}
}
else if( mpView && mpView->IsCreateObj() && rMEvt.IsLeft())
{
// object was created
mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetCreateObj() ) );
if( mxTextObj.is() )
{
//AW outliner needs to be set to vertical when there is no
// outliner object up to now; also it needs to be set back to not
// vertical when there was a vertical one used last time.
OutlinerParaObject* pOPO = GetTextObj()->GetOutlinerParaObject();
SdrOutliner& rOutl(mxTextObj->getSdrModelFromSdrObject().GetDrawOutliner(GetTextObj()));
bool bVertical((pOPO && pOPO->IsEffectivelyVertical())
|| nSlotId == SID_ATTR_CHAR_VERTICAL
|| nSlotId == SID_TEXT_FITTOSIZE_VERTICAL);
rOutl.SetVertical(bVertical);
// Before ImpSetAttributesForNewTextObject the vertical writing mode
// needs to be set at the object. This is done here at the OutlinerParaObject
// directly to not mirror the layout text items involved. These items will be set
// from ImpSetAttributesForNewTextObject and below.
OutlinerParaObject* pPara = GetTextObj()->GetOutlinerParaObject();
if(!pPara)
{
GetTextObj()->ForceOutlinerParaObject();
pPara = GetTextObj()->GetOutlinerParaObject();
}
if(pPara && bVertical != pPara->IsEffectivelyVertical())
{
// set ParaObject orientation accordingly
pPara->SetVertical(bVertical);
}
ImpSetAttributesForNewTextObject(GetTextObj());
}
if (!mpView->EndCreateObj(SdrCreateCmd::ForceEnd))
{
// it was not possible to create text object
mxTextObj.reset(nullptr);
}
else if (nSlotId == SID_TEXT_FITTOSIZE)
{
ImpSetAttributesFitToSize(GetTextObj());
SetInEditMode(rMEvt, false);
}
else if ( nSlotId == SID_TEXT_FITTOSIZE_VERTICAL )
{
ImpSetAttributesFitToSizeVertical(GetTextObj());
SetInEditMode(rMEvt, false);
}
else
{
ImpSetAttributesFitCommon(GetTextObj());
// thereby the handles and the gray frame are correct
mpView->AdjustMarkHdl();
mpView->PickHandle(aPnt);
SetInEditMode(rMEvt, false);
}
}
else if ( mpView && mpView->IsAction())
{
mpView->EndAction();
}
ForcePointer(&rMEvt);
mpWindow->ReleaseMouse();
sal_uInt16 nDrgLog1 = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
if ( mpView && !mpView->AreObjectsMarked() &&
std::abs(aMDPos.X() - aPnt.X()) < nDrgLog1 &&
std::abs(aMDPos.Y() - aPnt.Y()) < nDrgLog1 &&
!rMEvt.IsShift() && !rMEvt.IsMod2() )
{
SdrPageView* pPV2 = mpView->GetSdrPageView();
SdrViewEvent aVEvt;
mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
mpView->MarkObj(aVEvt.mpRootObj, pPV2);
}
if ( !mxTextObj.is() && mpView )
{
if ( ( (!bEmptyTextObj && bPermanent) ||
(!bFirstObjCreated && !bPermanent) ) &&
!mpDocSh->IsReadOnly() &&
nSlotId != SID_TEXTEDIT )
{
// text body (left-justified AutoGrow)
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Create);
sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
mpView->BegCreateObj(aMDPos, nullptr, nDrgLog);
bool bSnapEnabled = mpView->IsSnapEnabled();
if (bSnapEnabled)
mpView->SetSnapEnabled(false);
aPnt.AdjustX(nDrgLog + nDrgLog );
aPnt.AdjustY(nDrgLog + nDrgLog );
mpView->MovAction(aPnt);
mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetCreateObj() ) );
if(mxTextObj.is())
{
GetTextObj()->SetDisableAutoWidthOnDragging(true);
}
if(!mpView->EndCreateObj(SdrCreateCmd::ForceEnd))
{
mxTextObj.reset(nullptr);
}
if(bSnapEnabled)
mpView->SetSnapEnabled(bSnapEnabled);
if(mxTextObj.is())
{
SfxItemSet aSet(mpViewShell->GetPool());
aSet.Put(makeSdrTextMinFrameHeightItem(0));
aSet.Put(makeSdrTextMinFrameWidthItem(0));
aSet.Put(makeSdrTextAutoGrowHeightItem(true));
aSet.Put(makeSdrTextAutoGrowWidthItem(true));
if(nSlotId == SID_ATTR_CHAR_VERTICAL)
{
// Here, all items which need to be different from pool default need to be set
// again on the newly created text object.
// Since this is a simple click text object, it is first created, then SetVertical()
// is used, then ImpSetAttributesForNewTextObject is called and then the object is
// deleted again since not the minimum drag distance was travelled. Then, a new
// click text object is created and thus all that stuff needs to be set again here.
// Before using the new object the vertical writing mode
// needs to be set. This is done here at the OutlinerParaObject
// directly to not mirror the layout text items involved. These items will be set
// below.
OutlinerParaObject* pPara = GetTextObj()->GetOutlinerParaObject();
if(!pPara)
{
GetTextObj()->ForceOutlinerParaObject();
pPara = GetTextObj()->GetOutlinerParaObject();
}
if(pPara && !pPara->IsEffectivelyVertical())
{
// set ParaObject orientation accordingly
pPara->SetVertical(true);
}
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
// Analog to the else case below, for vertical simple click texts
// one of the default set items from ImpSetAttributesForNewTextObject
// needs to be adapted to non-block mode.
const SfxItemSet& rSet = mpView->GetDefaultAttr();
SvxFrameDirection eDirection = rSet.Get(EE_PARA_WRITINGDIR).GetValue();
if(SvxFrameDirection::Horizontal_RL_TB == eDirection || SvxFrameDirection::Vertical_RL_TB == eDirection)
{
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BOTTOM));
}
else
{
aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
}
}
else
{
// This is for Format/Page settings. Since this also leads
// to the object defaults to be changed, i think this code can be
// removed. CL. wanted to take a look before adding this.
// Look in the object defaults if left-to-right is wanted. If
// yes, set text anchoring to right to let the box grow to left.
const SfxItemSet& rSet = mpView->GetDefaultAttr();
SvxFrameDirection eDirection = rSet.Get(EE_PARA_WRITINGDIR).GetValue();
if(SvxFrameDirection::Horizontal_RL_TB == eDirection)
{
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
}
else
{
aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_LEFT));
}
}
GetTextObj()->SetMergedItemSet(aSet);
GetTextObj()->SetDisableAutoWidthOnDragging(true);
SetInEditMode(rMEvt, false);
}
bFirstObjCreated = true;
}
else
{
// switch to selection
if (mpView->SdrEndTextEdit() == SdrEndTextEditKind::Deleted)
{
mxTextObj.reset(nullptr);
}
mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_OBJECT_SELECT,
SfxCallMode::ASYNCHRON | SfxCallMode::RECORD );
}
}
if (bJustEndedEdit)
{
bJustEndedEdit = false;
FuPoor::cancel();
}
bMBDown = false;
FuConstruct::MouseButtonUp(rMEvt);
return bReturn;
}
/**
* handle keyboard events
* @returns sal_True if the event was handled, sal_False otherwise
*/
bool FuText::KeyInput(const KeyEvent& rKEvt)
{
bool bReturn = false;
vcl::KeyCode nCode = rKEvt.GetKeyCode();
bool bShift = nCode.IsShift();
if(mxTextObj.is())
{
// maybe object is deleted, test if it's equal to the selected object
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
SdrObject* pSelectedObj = nullptr;
if(1 == rMarkList.GetMarkCount())
{
SdrMark* pMark = rMarkList.GetMark(0);
pSelectedObj = pMark->GetMarkedSdrObj();
}
if(mxTextObj.get() != pSelectedObj)
{
mxTextObj.reset(nullptr);
}
}
if ( mxTextObj.is() && mxTextObj->GetObjInventor() == SdrInventor::Default && mxTextObj->GetObjIdentifier() == SdrObjKind::TitleText && rKEvt.GetKeyCode().GetCode() == KEY_RETURN )
{
// title text object: always soft breaks
bShift = true;
}
sal_uInt16 nKey = nCode.GetCode();
vcl::KeyCode aKeyCode (nKey, bShift, nCode.IsMod1(), nCode.IsMod2(), nCode.IsMod3() );
KeyEvent aKEvt(rKEvt.GetCharCode(), aKeyCode);
bool bOK = true;
if (mpDocSh->IsReadOnly())
{
bOK = !EditEngine::DoesKeyChangeText(aKEvt);
}
if( aKeyCode.GetCode() == KEY_PAGEUP || aKeyCode.GetCode() == KEY_PAGEDOWN )
{
bOK = false; // default handling in base class
}
if (bOK && mpView->KeyInput(aKEvt, mpWindow) )
{
bReturn = true;
mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
}
else if (aKeyCode == KEY_ESCAPE)
{
bReturn = cancel();
}
if( bPermanent )
{
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Create);
}
if (!bReturn)
{
bReturn = FuDraw::KeyInput(aKEvt);
}
return bReturn;
}
void FuText::Activate()
{
mpView->SetQuickTextEditMode(mpViewShell->GetFrameView()->IsQuickEdit());
// #i89661# it's no longer necessary to make it so big here, it's fine tuned
// for text objects in SdrMarkView::CheckSingleSdrObjectHit
mpView->SetHitTolerancePixel( 2 * HITPIX );
OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
if (pOLV)
pOLV->ShowCursor(/*bGotoCursor=*/true, /*bActivate=*/true);
FuConstruct::Activate();
if( pOLV )
mpView->SetEditMode(SdrViewEditMode::Edit);
}
void FuText::Deactivate()
{
OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
if (pOLV)
pOLV->HideCursor(/*bDeactivate=*/true);
mpView->SetHitTolerancePixel( HITPIX );
FuConstruct::Deactivate();
}
/**
* Sets the object into the edit mode.
*/
void FuText::SetInEditMode(const MouseEvent& rMEvt, bool bQuickDrag)
{
SdrPageView* pPV = mpView->GetSdrPageView();
if( mxTextObj.is() && (mxTextObj->getSdrPageFromSdrObject() == pPV->GetPage()) )
{
mpView->SetCurrentObj(SdrObjKind::Text);
if( bPermanent )
mpView->SetEditMode(SdrViewEditMode::Create);
else
mpView->SetEditMode(SdrViewEditMode::Edit);
bool bEmptyOutliner = false;
if (!GetTextObj()->GetOutlinerParaObject() && mpView->GetTextEditOutliner())
{
::Outliner* pOutl = mpView->GetTextEditOutliner();
sal_Int32 nParagraphCnt = pOutl->GetParagraphCount();
Paragraph* p1stPara = pOutl->GetParagraph( 0 );
if (nParagraphCnt==1 && p1stPara)
{
// with only one paragraph
if (pOutl->GetText(p1stPara).isEmpty())
{
bEmptyOutliner = true;
}
}
}
if (GetTextObj() != mpView->GetTextEditObject() || bEmptyOutliner)
{
SdrInventor nInv = mxTextObj->GetObjInventor();
SdrObjKind nSdrObjKind = mxTextObj->GetObjIdentifier();
if (nInv == SdrInventor::Default && GetTextObj()->HasTextEdit() &&
(nSdrObjKind == SdrObjKind::Text ||
nSdrObjKind == SdrObjKind::TitleText ||
nSdrObjKind == SdrObjKind::OutlineText || !mxTextObj->IsEmptyPresObj() ) )
{
// create new outliner (owned by SdrObjEditView)
std::unique_ptr<SdrOutliner> pOutl = SdrMakeOutliner(OutlinerMode::OutlineObject, *mpDoc);
if (bEmptyOutliner)
mpView->SdrEndTextEdit(true);
SdrTextObj* pTextObj = GetTextObj();
if( pTextObj )
{
OutlinerParaObject* pOPO = pTextObj->GetOutlinerParaObject();
if( pOPO && pOPO->IsEffectivelyVertical() )
{
pOutl->SetVertical(pOPO->GetVertical());
pOutl->SetRotation(pOPO->GetRotation());
}
else if (nSlotId == SID_ATTR_CHAR_VERTICAL || nSlotId == SID_TEXT_FITTOSIZE_VERTICAL)
pOutl->SetVertical( true );
if( pTextObj->getTextCount() > 1 )
{
Point aPix(rMEvt.GetPosPixel());
Point aPnt(mpWindow->PixelToLogic(aPix));
pTextObj->setActiveText( pTextObj->CheckTextHit(aPnt ) );
}
if (mpView->SdrBeginTextEdit(pTextObj, pPV, mpWindow, true, pOutl.release()) && mxTextObj->GetObjInventor() == SdrInventor::Default)
{
//tdf#102293 flush overlay before going on to pass clicks down to
//the outline view which will want to paint selections
for (sal_uInt32 b = 0; b < pPV->PageWindowCount(); ++b)
{
const SdrPageWindow& rPageWindow = *pPV->GetPageWindow(b);
if (!rPageWindow.GetPaintWindow().OutputToWindow())
continue;
const rtl::Reference< sdr::overlay::OverlayManager >& xManager = rPageWindow.GetOverlayManager();
if (!xManager.is())
continue;
xManager->flush();
}
bFirstObjCreated = true;
DeleteDefaultText();
OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
nSdrObjKind = mxTextObj->GetObjIdentifier();
SdrViewEvent aVEvt;
SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
if (eHit == SdrHitKind::TextEdit)
{
// hit text
if (nSdrObjKind == SdrObjKind::Text ||
nSdrObjKind == SdrObjKind::TitleText ||
nSdrObjKind == SdrObjKind::OutlineText ||
nSdrObjKind == SdrObjKind::Table ||
nSlotId == SID_TEXTEDIT ||
!bQuickDrag)
{
pOLV->MouseButtonDown(rMEvt);
pOLV->MouseMove(rMEvt);
pOLV->MouseButtonUp(rMEvt);
}
if (mpViewShell->GetFrameView()->IsQuickEdit() && bQuickDrag && GetTextObj()->GetOutlinerParaObject())
{
pOLV->MouseButtonDown(rMEvt);
}
}
else
{
// Move cursor to end of text
ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
if (pOLV != nullptr)
pOLV->SetSelection(aNewSelection);
}
}
else
{
mpView->RestoreDefaultText( mxTextObj.get() );
}
}
}
}
}
else
{
mxTextObj.reset(nullptr);
}
}
/**
* Text entry is started, if necessary delete the default text.
*/
void FuText::DeleteDefaultText()
{
if ( !(mxTextObj.is() && mxTextObj->IsEmptyPresObj()) )
return;
SdPage* pPage = static_cast<SdPage*>( mxTextObj->getSdrPageFromSdrObject() );
if (!pPage)
return;
PresObjKind ePresObjKind = pPage->GetPresObjKind(mxTextObj.get());
if ( !(ePresObjKind == PresObjKind::Title ||
ePresObjKind == PresObjKind::Outline ||
ePresObjKind == PresObjKind::Notes ||
ePresObjKind == PresObjKind::Text ) ||
pPage->IsMasterPage() )
return;
::Outliner* pOutliner = mpView->GetTextEditOutliner();
SfxStyleSheet* pSheet = pOutliner->GetStyleSheet( 0 );
bool bIsUndoEnabled = pOutliner->IsUndoEnabled();
if( bIsUndoEnabled )
pOutliner->EnableUndo(false);
pOutliner->SetText( OUString(), pOutliner->GetParagraph( 0 ) );
if( bIsUndoEnabled )
pOutliner->EnableUndo(true);
if (pSheet &&
(ePresObjKind == PresObjKind::Notes || ePresObjKind == PresObjKind::Text))
pOutliner->SetStyleSheet(0, pSheet);
mxTextObj->SetEmptyPresObj(true);
}
bool FuText::RequestHelp(const HelpEvent& rHEvt)
{
bool bReturn = false;
OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
if ((Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled()) &&
mxTextObj.is() && pOLV && pOLV->GetFieldUnderMousePointer())
{
OUString aHelpText;
const SvxFieldItem* pFieldItem = pOLV->GetFieldUnderMousePointer();
const SvxFieldData* pField = pFieldItem->GetField();
if (auto pURLField = dynamic_cast< const SvxURLField *>( pField ))
{
// URL-Field
aHelpText = INetURLObject::decode( pURLField->GetURL(), INetURLObject::DecodeMechanism::WithCharset );
}
if (!aHelpText.isEmpty())
{
::tools::Rectangle aLogicPix = mpWindow->LogicToPixel(mxTextObj->GetLogicRect());
::tools::Rectangle aScreenRect(mpWindow->OutputToScreenPixel(aLogicPix.TopLeft()),
mpWindow->OutputToScreenPixel(aLogicPix.BottomRight()));
if (Help::IsBalloonHelpEnabled())
{
Help::ShowBalloon( static_cast<vcl::Window*>(mpWindow), rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
bReturn = true;
}
else if (Help::IsQuickHelpEnabled())
{
Help::ShowQuickHelp( static_cast<vcl::Window*>(mpWindow), aScreenRect, aHelpText);
bReturn = true;
}
}
}
if (!bReturn)
{
bReturn = FuConstruct::RequestHelp(rHEvt);
}
return bReturn;
}
void FuText::ReceiveRequest(SfxRequest& rReq)
{
nSlotId = rReq.GetSlot();
// then we call the base class (besides others, nSlotId is NOT set there)
FuPoor::ReceiveRequest(rReq);
if (!(nSlotId == SID_TEXTEDIT || mpViewShell->GetFrameView()->IsQuickEdit() || SID_ATTR_CHAR == nSlotId))
return;
MouseEvent aMEvt(mpWindow->GetPointerPosPixel());
mxTextObj.reset(nullptr);
if (nSlotId == SID_TEXTEDIT)
{
// are we currently editing?
mxTextObj.reset( mpView->GetTextEditObject() );
if (!mxTextObj.is())
{
// Try to select an object
SdrPageView* pPV = mpView->GetSdrPageView();
SdrViewEvent aVEvt;
mpView->PickAnything(aMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
mpView->MarkObj(aVEvt.mpRootObj, pPV);
if (auto pSdrTextObj = dynamic_cast<SdrTextObj*>(aVEvt.mpObj))
{
mxTextObj.reset( pSdrTextObj );
}
}
}
else if (mpView->AreObjectsMarked())
{
const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
if (rMarkList.GetMarkCount() == 1)
{
SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
if( auto pTextObj = dynamic_cast<SdrTextObj *>( pObj ))
{
mxTextObj.reset( pTextObj );
}
}
}
bool bQuickDrag = true;
const SfxItemSet* pArgs = rReq.GetArgs();
if (pArgs
// test for type before using
&& SID_TEXTEDIT == nSlotId
&& SfxItemState::SET == pArgs->GetItemState(SID_TEXTEDIT)
&& static_cast<const SfxUInt16Item&>( pArgs->Get(SID_TEXTEDIT)).GetValue() == 2)
{
// selection with double click -> do not allow QuickDrag
bQuickDrag = false;
}
SetInEditMode(aMEvt, bQuickDrag);
}
void FuText::DoubleClick(const MouseEvent& )
{
// Nothing to do
}
/** Removed the insertion of default text and putting a new text
object directly into edit mode.
*/
SdrObjectUniquePtr FuText::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
{
SdrObjectUniquePtr pObj( SdrObjFactory::MakeNewObject(
mpView->getSdrModelFromSdrView(),
mpView->GetCurrentObjInventor(),
mpView->GetCurrentObjIdentifier(),
nullptr) );
if(pObj)
{
if( auto pText = dynamic_cast< SdrTextObj *>( pObj.get() ) )
{
pText->SetLogicRect(rRectangle);
bool bVertical = (SID_ATTR_CHAR_VERTICAL == nID || SID_TEXT_FITTOSIZE_VERTICAL == nID);
pText->SetVerticalWriting(bVertical);
ImpSetAttributesForNewTextObject(pText);
if (nSlotId == SID_TEXT_FITTOSIZE)
{
ImpSetAttributesFitToSize(pText);
}
else if ( nSlotId == SID_TEXT_FITTOSIZE_VERTICAL )
{
ImpSetAttributesFitToSizeVertical(pText);
}
else
{
ImpSetAttributesFitCommon(pText);
}
// Put text object into edit mode.
SdrPageView* pPV = mpView->GetSdrPageView();
mpView->SdrBeginTextEdit(pText, pPV);
}
else
{
OSL_FAIL("Object is NO text object");
}
}
return pObj;
}
/** is called when the current function should be aborted. <p>
This is used when a function gets a KEY_ESCAPE but can also
be called directly.
@returns true if an active function was aborted
*/
bool FuText::cancel()
{
if ( mpView->IsTextEdit() )
{
if(mpView->SdrEndTextEdit() == SdrEndTextEditKind::Deleted)
mxTextObj.reset(nullptr);
mpView->SetCurrentObj(SdrObjKind::Text);
mpView->SetEditMode(SdrViewEditMode::Edit);
return true;
}
else
{
return false;
}
}
void FuText::ChangeFontSize( bool bGrow, OutlinerView* pOLV, const FontList* pFontList, ::sd::View* pView )
{
if( !pFontList || !pView )
return;
if( pOLV )
{
pOLV->GetEditView().ChangeFontSize( bGrow, pFontList );
}
else
{
pView->BegUndo(SdResId(bGrow ? STR_GROW_FONT_SIZE : STR_SHRINK_FONT_SIZE));
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
for( size_t nMark = 0; nMark < rMarkList.GetMarkCount(); ++nMark )
{
SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( rMarkList.GetMark(nMark)->GetMarkedSdrObj() );
if( pTextObj )
{
rtl::Reference<sdr::SelectionController> xSelectionController(pView->getSelectionController());
if (xSelectionController.is() && xSelectionController->ChangeFontSize(bGrow, pFontList))
{
continue;
}
for( sal_Int32 nText = 0; nText < pTextObj->getTextCount(); nText++ )
{
pTextObj->setActiveText( nText );
// Put text object into edit mode.
SdrPageView* pPV = pView->GetSdrPageView();
pView->SdrBeginTextEdit(pTextObj, pPV);
pOLV = pView->GetTextEditOutlinerView();
if( pOLV )
{
EditEngine* pEditEngine = pOLV->GetEditView().GetEditEngine();
if( pEditEngine )
{
ESelection aSel;
aSel.nEndPara = pEditEngine->GetParagraphCount()-1;
aSel.nEndPos = pEditEngine->GetTextLen(aSel.nEndPara);
pOLV->SetSelection(aSel);
}
ChangeFontSize( bGrow, pOLV, pFontList, pView );
}
pView->SdrEndTextEdit();
}
SfxItemSet aShapeSet( pTextObj->GetMergedItemSet() );
if( EditView::ChangeFontSize( bGrow, aShapeSet, pFontList ) )
{
pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT ) );
pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT_CJK ) );
pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT_CTL ) );
}
}
}
pView->EndUndo();
}
}
void FuText::InvalidateBindings()
{
mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
}
} // end of namespace sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|