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 #include <svx/svddef.hxx>
21 #include <svx/svdoutl.hxx>
22 #include <editeng/outlobj.hxx>
23 #include <svx/sdtaaitm.hxx>
24 #include <svx/sdtacitm.hxx>
25 #include <svx/svdotext.hxx>
26 #include <svx/sdtagitm.hxx>
27 #include <editeng/unolingu.hxx>
28 #include <sfx2/bindings.hxx>
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svx/svxids.hrc>
32 #include <editeng/eeitem.hxx>
33 #include <svl/itemset.hxx>
34 #include <osl/diagnose.h>
35 
36 #include <futext.hxx>
37 #include <drwlayer.hxx>
38 #include <sc.hrc>
39 #include <tabvwsh.hxx>
40 #include <drawview.hxx>
41 
42 // maximum of mouse movement which allows to start Drag&Drop
43 //! fusel,fuconstr,futext - combined!
44 #define SC_MAXDRAGMOVE  3
45 
lcl_InvalidateAttribs(SfxBindings & rBindings)46 static void lcl_InvalidateAttribs( SfxBindings& rBindings )
47 {
48     rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
49     rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
50     rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
51     rBindings.Invalidate( SID_ULINE_VAL_NONE );
52     rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
53     rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
54     rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
55     rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
56     rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
57     rBindings.Invalidate( SID_ATTR_CHAR_BACK_COLOR );
58     rBindings.Invalidate( SID_ATTR_CHAR_FONT );
59     rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
60     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
61     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
62     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
63     rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
64     rBindings.Invalidate( SID_ALIGNLEFT );
65     rBindings.Invalidate( SID_ALIGNCENTERHOR );
66     rBindings.Invalidate( SID_ALIGNRIGHT );
67     rBindings.Invalidate( SID_ALIGNBLOCK );
68     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_10 );
69     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_15 );
70     rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_20 );
71     rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
72     rBindings.Invalidate( SID_SET_SUB_SCRIPT );
73     rBindings.Invalidate( SID_HYPERLINK_GETLINK );
74     rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
75     rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
76     rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
77     rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
78     rBindings.Invalidate( SID_TABLE_VERT_NONE );
79     rBindings.Invalidate( SID_TABLE_VERT_CENTER );
80     rBindings.Invalidate( SID_TABLE_VERT_BOTTOM );
81     // pseudo slots for Format menu
82     rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
83     rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
84     rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
85     rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
86     rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
87     rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
88     rBindings.Invalidate( SID_SET_SUB_SCRIPT );
89     rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
90     rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
91 }
92 
lcl_UpdateHyphenator(Outliner & rOutliner,const SdrObject * pObj)93 static void lcl_UpdateHyphenator( Outliner& rOutliner, const SdrObject* pObj )
94 {
95     // use hyphenator only if hyphenation attribute is set
96     if ( pObj && pObj->GetMergedItem(EE_PARA_HYPHENATE).GetValue() ) {
97             css::uno::Reference<css::linguistic2::XHyphenator> xHyphenator( LinguMgr::GetHyphenator() );
98             rOutliner.SetHyphenator( xHyphenator );
99     }
100 }
101 
FuText(ScTabViewShell & rViewSh,vcl::Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,const SfxRequest & rReq)102 FuText::FuText(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
103                SdrModel* pDoc, const SfxRequest& rReq)
104     : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
105 {
106 }
107 
~FuText()108 FuText::~FuText()
109 {
110 //  StopEditMode();                 // in Deactivate !
111 }
112 
MouseButtonDown(const MouseEvent & rMEvt)113 bool FuText::MouseButtonDown(const MouseEvent& rMEvt)
114 {
115     // remember button state for creation of own MouseEvents
116     SetMouseButtonCode(rMEvt.GetButtons());
117     bool bStraightEnter = true;
118 
119     if ( pView->MouseButtonDown(rMEvt, pWindow->GetOutDev()) )
120         return true;                 // event handled from SdrView
121 
122     if ( pView->IsTextEdit() )
123     {
124         if ( IsEditingANote() )
125         {
126             if( !IsSizingOrMovingNote(rMEvt) )
127             {
128                 StopEditMode();            // Clicked outside, ending edit
129                 bStraightEnter = false;
130             }
131         }
132         else
133         {
134             StopEditMode();            // Clicked outside, ending edit
135             pView->UnmarkAll();
136             bStraightEnter = false;
137         }
138         pView->SetCreateMode();
139     }
140 
141     aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
142 
143     if ( rMEvt.IsLeft() )
144     {
145         SdrHdl* pHdl = pView->PickHandle(aMDPos);
146         const size_t nHdlNum = pView->GetHdlNum(pHdl);
147         if (pHdl != nullptr)
148         {
149             if (pView->HasMarkablePoints() && pView->IsPointMarkable(*pHdl))
150             {
151                 bool bPointMarked=pView->IsPointMarked(*pHdl);
152 
153                 if ( rMEvt.IsShift() )
154                 {
155                     if (!bPointMarked)
156                     {
157                         pView->MarkPoint(*pHdl);
158                     }
159                     else
160                     {
161                         pView->UnmarkPoint(*pHdl);
162                     }
163                 }
164                 else
165                 {
166                     if (!bPointMarked)
167                     {
168                         pView->UnmarkAllPoints();
169                         pView->MarkPoint(*pHdl);
170                     }
171                 }
172                 pHdl=pView->GetHdl(nHdlNum);
173             }
174         }
175 
176         SdrPageView* pPV = nullptr;
177 
178         if ( pHdl != nullptr || pView->IsMarkedHit(aMDPos) )
179         {
180             SdrObject* pObj = (pHdl == nullptr) ?
181                 pView->PickObj(aMDPos, pView->getHitTolLog(), pPV, SdrSearchOptions::PICKTEXTEDIT) :
182                 nullptr;
183             if (pObj)
184             {
185                 std::unique_ptr<SdrOutliner> pO = MakeOutliner();
186                 lcl_UpdateHyphenator( *pO, pObj );
187 
188                 //  vertical flag:
189                 //  deduced from slot ids only if text object has no content
190                 sal_uInt16 nSlotID = aSfxRequest.GetSlot();
191                 bool bVertical = ( nSlotID == SID_DRAW_TEXT_VERTICAL );
192                 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
193                 if ( pOPO )
194                     bVertical = pOPO->IsVertical();     // content wins
195                 pO->SetVertical( bVertical );
196 
197                 //!?? the default values are not correct when result is without outliner ???!?
198                 auto pOTemp = pO.get();
199                 if ( pView->SdrBeginTextEdit(pObj, pPV, pWindow, true, pO.release()) )
200                 {
201                     // subscribe EditEngine-UndoManager
202                     rViewShell.SetDrawTextUndo( &pOTemp->GetUndoManager() );
203 
204                     OutlinerView* pOLV = pView->GetTextEditOutlinerView();
205                     if ( pOLV->MouseButtonDown(rMEvt) )
206                         return true; // Event to the Outliner
207                 }
208             }
209             else
210             {
211                 // disable tail & circular move for caption objects.
212                 bool bDrag = false;
213                 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
214                 if( rMarkList.GetMarkCount() == 1 )
215                 {
216                     SdrObject* pMarkedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
217                     if( ScDrawLayer::IsNoteCaption( pMarkedObj ) )
218                     {
219                         if(pHdl->GetKind() != SdrHdlKind::Poly && pHdl->GetKind() != SdrHdlKind::Circle)
220                             bDrag = true;
221                     }
222                     else
223                         bDrag = true;   // different object
224                 }
225                 else
226                     bDrag = true;       // several objects
227 
228                 if ( bDrag )
229                 {
230                     aDragTimer.Start();
231                     pView->BegDragObj(aMDPos, nullptr, pHdl);
232                 }
233             }
234         }
235         else
236         {
237             if (pView->IsEditMode())
238             {
239                 bool bPointMode=pView->HasMarkablePoints();
240 
241                 if (!rMEvt.IsShift())
242                 {
243                     if (bPointMode)
244                     {
245                         pView->UnmarkAllPoints();
246                     }
247                     else
248                     {
249                         pView->UnmarkAll();
250                     }
251 
252                     pView->SetDragMode(SdrDragMode::Move);
253                     SfxBindings& rBindings = rViewShell.GetViewFrame()->GetBindings();
254                     rBindings.Invalidate( SID_OBJECT_ROTATE );
255                     rBindings.Invalidate( SID_OBJECT_MIRROR );
256                 }
257 
258                 if ( pView->MarkObj(aMDPos, -2, false, rMEvt.IsMod1()) )
259                 {
260                     aDragTimer.Start();
261 
262                     pHdl=pView->PickHandle(aMDPos);
263 
264                     if (pHdl!=nullptr)
265                     {
266                         pView->MarkPoint(*pHdl);
267                         pHdl=pView->GetHdl(nHdlNum);
268                     }
269 
270                     pView->BegDragObj(aMDPos, nullptr, pHdl);
271                 }
272                 else
273                 {
274                     if (bPointMode)
275                     {
276                         pView->BegMarkPoints(aMDPos);
277                     }
278                     else
279                     {
280                         pView->BegMarkObj(aMDPos);
281                     }
282                 }
283             }
284             else if (aSfxRequest.GetSlot() == SID_DRAW_NOTEEDIT )
285             {
286                 //  Edit notes -> create no new text objects
287                 //  and leave text mode
288                 rViewShell.GetViewData().GetDispatcher().
289                     Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
290             }
291             else
292             {
293                 if (bStraightEnter)//Hack for that silly idea that creating text fields is inside the text routine
294                 {
295                     // create object
296                     pView->BegCreateObj(aMDPos);
297                 }
298                 else if (SdrObject* pObj = pView->PickObj(aMDPos, pView->getHitTolLog(), pPV, SdrSearchOptions::ALSOONMASTER | SdrSearchOptions::BEFOREMARK))
299                 {
300                     pView->UnmarkAllObj();
301                     ScViewData& rViewData = rViewShell.GetViewData();
302                     rViewData.GetDispatcher().Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
303                     pView->MarkObj(pObj,pPV);
304 
305                     pHdl=pView->PickHandle(aMDPos);
306                     pView->BegDragObj(aMDPos, nullptr, pHdl);
307                     return true;
308                 }
309             }
310         }
311     }
312 
313     if (!bIsInDragMode)
314     {
315         pWindow->CaptureMouse();
316 //      ForcePointer(&rMEvt);
317         lcl_InvalidateAttribs( rViewShell.GetViewFrame()->GetBindings() );
318     }
319 
320     rViewShell.SetActivePointer(pView->GetPreferredPointer(
321                     pWindow->PixelToLogic(rMEvt.GetPosPixel()), pWindow->GetOutDev() ));
322     if (!bStraightEnter)
323     {
324             pView->UnmarkAll();
325             ScViewData& rViewData = rViewShell.GetViewData();
326             rViewData.GetDispatcher().Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
327     }
328 
329     return true;
330 }
331 
MouseMove(const MouseEvent & rMEvt)332 bool FuText::MouseMove(const MouseEvent& rMEvt)
333 {
334     rViewShell.SetActivePointer(pView->GetPreferredPointer(
335                     pWindow->PixelToLogic(rMEvt.GetPosPixel()), pWindow->GetOutDev() ));
336 
337     if (aDragTimer.IsActive() )
338     {
339         Point aOldPixel = pWindow->LogicToPixel( aMDPos );
340         Point aNewPixel = rMEvt.GetPosPixel();
341         if ( std::abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
342              std::abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
343             aDragTimer.Stop();
344     }
345 
346     Point aPix(rMEvt.GetPosPixel());
347     Point aPnt(pWindow->PixelToLogic(aPix));
348 
349     if ( pView->MouseMove(rMEvt, pWindow->GetOutDev()) )
350         return true; // event handled from SdrView
351 
352     if ( pView->IsAction() )
353     {
354         ForceScroll(aPix);
355         pView->MovAction(aPnt);
356     }
357 
358     return false;
359 }
360 
MouseButtonUp(const MouseEvent & rMEvt)361 bool FuText::MouseButtonUp(const MouseEvent& rMEvt)
362 {
363     // remember button state for creation of own MouseEvents
364     SetMouseButtonCode(rMEvt.GetButtons());
365 
366     if (aDragTimer.IsActive() )
367     {
368         aDragTimer.Stop();
369     }
370 
371     lcl_InvalidateAttribs( rViewShell.GetViewFrame()->GetBindings() );
372 
373     Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
374 
375     if ( pView->MouseButtonUp(rMEvt, pWindow->GetOutDev()) )
376         return true; // Event evaluated by SdrView
377 
378     if ( pView->IsDragObj() )
379     {
380         pView->EndDragObj( rMEvt.IsShift() );
381         pView->ForceMarkedToAnotherPage();
382     }
383     else if ( pView->IsCreateObj() )
384     {
385         if (rMEvt.IsLeft())
386         {
387             pView->EndCreateObj(SdrCreateCmd::ForceEnd);
388             if (aSfxRequest.GetSlot() == SID_DRAW_TEXT_MARQUEE)
389             {
390                 // create marquee-object?
391                 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
392                 if (rMarkList.GetMark(0))
393                 {
394                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
395 
396                     // set needed attributes for scrolling
397                     SfxItemSet aItemSet( pDrDoc->GetItemPool(),
398                                             svl::Items<SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST>{});
399 
400                     aItemSet.Put( makeSdrTextAutoGrowWidthItem( false ) );
401                     aItemSet.Put( makeSdrTextAutoGrowHeightItem( false ) );
402                     aItemSet.Put( SdrTextAniKindItem( SdrTextAniKind::Slide ) );
403                     aItemSet.Put( SdrTextAniDirectionItem( SdrTextAniDirection::Left ) );
404                     aItemSet.Put( SdrTextAniCountItem( 1 ) );
405                     aItemSet.Put( SdrTextAniAmountItem(
406                                     static_cast<sal_Int16>(pWindow->PixelToLogic(Size(2,1)).Width())) );
407                     pObj->SetMergedItemSetAndBroadcast(aItemSet);
408                 }
409             }
410 
411             // init object different when vertical writing
412             sal_uInt16 nSlotID(aSfxRequest.GetSlot());
413             bool bVertical = (SID_DRAW_TEXT_VERTICAL == nSlotID);
414             if(bVertical)
415             {
416                 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
417                 if(rMarkList.GetMark(0))
418                 {
419                     SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
420                     if(auto pText = dynamic_cast<SdrTextObj*>( pObj))
421                     {
422                         SfxItemSet aSet(pDrDoc->GetItemPool());
423 
424                         pText->SetVerticalWriting(true);
425 
426                         aSet.Put(makeSdrTextAutoGrowWidthItem(true));
427                         aSet.Put(makeSdrTextAutoGrowHeightItem(false));
428                         aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
429                         aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
430 
431                         pText->SetMergedItemSet(aSet);
432                     }
433                 }
434             }
435 
436             SetInEditMode();
437 
438                 // leave mode when sole click (-> fuconstr)
439             if ( !pView->AreObjectsMarked() )
440             {
441                 pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
442 
443                 SfxDispatcher& rDisp = rViewShell.GetViewData().GetDispatcher();
444                 if ( pView->AreObjectsMarked() )
445                     rDisp.Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
446                 else
447                     rDisp.Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
448             }
449         }
450     }
451     else if ( pView->IsAction() )
452     {
453         pView->EndAction();
454     }
455     else if( !pView->IsAction() )
456     {
457         pWindow->ReleaseMouse();
458 
459         if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
460         {
461             pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
462 
463             SfxDispatcher& rDisp = rViewShell.GetViewData().GetDispatcher();
464             if ( pView->AreObjectsMarked() )
465                 rDisp.Execute(SID_OBJECT_SELECT, SfxCallMode::SLOT | SfxCallMode::RECORD);
466             else
467                 rDisp.Execute(aSfxRequest.GetSlot(), SfxCallMode::SLOT | SfxCallMode::RECORD);
468         }
469     }
470 
471     return false;
472 }
473 
474 // switch mouse-pointer
ForcePointer(const MouseEvent *)475 void FuText::ForcePointer(const MouseEvent* /* pMEvt */)
476 {
477     rViewShell.SetActivePointer( aNewPointer );
478 }
479 
480 // modify keyboard events
481 // if a KeyEvent is being processed, then the return value is sal_True, else FALSE.
KeyInput(const KeyEvent & rKEvt)482 bool FuText::KeyInput(const KeyEvent& rKEvt)
483 {
484     bool bReturn = false;
485 
486     if ( pView->KeyInput(rKEvt, pWindow) )
487     {
488         bReturn = true;
489         lcl_InvalidateAttribs( rViewShell.GetViewFrame()->GetBindings() );
490     }
491     else
492     {
493         bReturn = FuDraw::KeyInput(rKEvt);
494     }
495 
496     return bReturn;
497 }
498 
Activate()499 void FuText::Activate()
500 {
501     pView->SetDragMode(SdrDragMode::Move);
502     SfxBindings& rBindings = rViewShell.GetViewFrame()->GetBindings();
503     rBindings.Invalidate( SID_OBJECT_ROTATE );
504     rBindings.Invalidate( SID_OBJECT_MIRROR );
505 
506 // instant set the edit mode
507 //  SetInEditMode();
508 
509 //  if (!pTextObj)
510     {
511         // no text object in EditMode, therefore set CreateMode
512 
513         pView->SetCurrentObj(OBJ_TEXT);
514 
515         pView->SetCreateMode();
516     }
517 
518     aNewPointer = PointerStyle::Text;
519 
520     aOldPointer = pWindow->GetPointer();
521     rViewShell.SetActivePointer( aNewPointer );
522 
523     FuConstruct::Activate();
524 }
525 
Deactivate()526 void FuText::Deactivate()
527 {
528     FuConstruct::Deactivate();
529     rViewShell.SetActivePointer( aOldPointer );
530     StopEditMode();
531 }
532 
533 // switch object to Edit-Mode
SetInEditMode(SdrObject * pObj,const Point * pMousePixel,bool bCursorToEnd,const KeyEvent * pInitialKey)534 void FuText::SetInEditMode(SdrObject* pObj, const Point* pMousePixel,
535                             bool bCursorToEnd, const KeyEvent* pInitialKey)
536 {
537     /*  It is possible to pass a special (unselected) object in pObj, e.g. the
538         caption object of a cell note. If pObj is 0, then the selected object
539         is used. The layer will be relocked in FuText::StopEditMode(). */
540     if ( pObj && (pObj->GetLayer() == SC_LAYER_INTERN) )
541         pView->UnlockInternalLayer();
542 
543     if ( !pObj && pView->AreObjectsMarked() )
544     {
545         const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
546         if (rMarkList.GetMarkCount() == 1)
547         {
548             SdrMark* pMark = rMarkList.GetMark(0);
549             pObj = pMark->GetMarkedSdrObj();
550         }
551     }
552 
553     if ( !pObj )
554         return;
555 
556     sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
557 
558     if (!(nSdrObjKind == OBJ_TEXT ||
559         nSdrObjKind == OBJ_TITLETEXT ||
560         nSdrObjKind == OBJ_OUTLINETEXT ||
561         dynamic_cast<const SdrTextObj*>( pObj) !=  nullptr))
562         return;
563 
564     SdrPageView* pPV = pView->GetSdrPageView();
565 
566     if ( !pObj->HasTextEdit() )
567         return;
568 
569     std::unique_ptr<SdrOutliner> pO = MakeOutliner();
570     lcl_UpdateHyphenator( *pO, pObj );
571 
572     //  vertical flag:
573     //  deduced from slot ids only if text object has no content
574 
575     sal_uInt16 nSlotID = aSfxRequest.GetSlot();
576     bool bVertical = ( nSlotID == SID_DRAW_TEXT_VERTICAL );
577     OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
578     if ( pOPO )
579         bVertical = pOPO->IsVertical();     // content wins
580     pO->SetVertical( bVertical );
581 
582     //!??  without returned Outliner the defaults are not correct ???!?
583     auto pOTemp = pO.get();
584     if ( !pView->SdrBeginTextEdit(pObj, pPV, pWindow, true, pO.release()) )
585         return;
586 
587     //  Toggle out of paste mode if we are in it, otherwise
588     //  pressing return in this object will instead go to the
589     //  sheet and be considered an overwrite-cell instruction
590     rViewShell.GetViewData().SetPasteMode(ScPasteFlags::NONE);
591     rViewShell.UpdateCopySourceOverlay();
592 
593     //  EditEngine-UndoManager anmelden
594     rViewShell.SetDrawTextUndo( &pOTemp->GetUndoManager() );
595 
596     pView->SetEditMode();
597 
598     //  set text cursor to click position or to end,
599     //  pass initial key event to outliner view
600     if ( !(pMousePixel || bCursorToEnd || pInitialKey) )
601         return;
602 
603     OutlinerView* pOLV = pView->GetTextEditOutlinerView();
604     if (!pOLV)
605         return;
606 
607     if ( pMousePixel )
608     {
609         MouseEvent aEditEvt( *pMousePixel, 1, MouseEventModifiers::SYNTHETIC, MOUSE_LEFT, 0 );
610         pOLV->MouseButtonDown(aEditEvt);
611         pOLV->MouseButtonUp(aEditEvt);
612     }
613     else if ( bCursorToEnd )
614     {
615         ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
616         pOLV->SetSelection(aNewSelection);
617     }
618 
619     if ( pInitialKey )
620         pOLV->PostKeyEvent( *pInitialKey );
621 }
622 
623 // Create default drawing objects via keyboard
CreateDefaultObject(const sal_uInt16 nID,const tools::Rectangle & rRectangle)624 SdrObjectUniquePtr FuText::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle)
625 {
626     // case SID_DRAW_TEXT:
627     // case SID_DRAW_TEXT_VERTICAL:
628     // case SID_DRAW_TEXT_MARQUEE:
629     // case SID_DRAW_NOTEEDIT:
630 
631     SdrObjectUniquePtr pObj(SdrObjFactory::MakeNewObject(
632         *pDrDoc,
633         pView->GetCurrentObjInventor(),
634         pView->GetCurrentObjIdentifier()));
635 
636     if(pObj)
637     {
638         if(auto pText = dynamic_cast<SdrTextObj*>( pObj.get() ))
639         {
640             pText->SetLogicRect(rRectangle);
641 
642             // don't set default text, start edit mode instead
643             // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
644             // pText->SetText(aText);
645 
646             bool bVertical = (SID_DRAW_TEXT_VERTICAL == nID);
647             bool bMarquee = (SID_DRAW_TEXT_MARQUEE == nID);
648 
649             pText->SetVerticalWriting(bVertical);
650 
651             if(bVertical)
652             {
653                 SfxItemSet aSet(pDrDoc->GetItemPool());
654 
655                 aSet.Put(makeSdrTextAutoGrowWidthItem(true));
656                 aSet.Put(makeSdrTextAutoGrowHeightItem(false));
657                 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
658                 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
659 
660                 pText->SetMergedItemSet(aSet);
661             }
662 
663             if(bMarquee)
664             {
665                 SfxItemSet aSet(pDrDoc->GetItemPool(), svl::Items<SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST>{});
666 
667                 aSet.Put( makeSdrTextAutoGrowWidthItem( false ) );
668                 aSet.Put( makeSdrTextAutoGrowHeightItem( false ) );
669                 aSet.Put( SdrTextAniKindItem( SdrTextAniKind::Slide ) );
670                 aSet.Put( SdrTextAniDirectionItem( SdrTextAniDirection::Left ) );
671                 aSet.Put( SdrTextAniCountItem( 1 ) );
672                 aSet.Put( SdrTextAniAmountItem( static_cast<sal_Int16>(pWindow->PixelToLogic(Size(2,1)).Width())) );
673 
674                 pObj->SetMergedItemSetAndBroadcast(aSet);
675             }
676 
677             SetInEditMode( pObj.get() );      // start edit mode
678         }
679         else
680         {
681             OSL_FAIL("Object is NO text object");
682         }
683     }
684 
685     return pObj;
686 }
687 
688 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
689