Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / drawfunc / futext.cxx
blob8ea5fc2d90b35614c272abcdea8f10a3c03c3157
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svx/svddef.hxx>
22 #include <svx/svdoutl.hxx>
23 #include <editeng/outlobj.hxx>
24 #include <svx/sdtaaitm.hxx>
25 #include <svx/sdtacitm.hxx>
26 #include <svx/svdotext.hxx>
27 #include <editeng/unolingu.hxx>
28 #include <svx/svdocapt.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/viewfrm.hxx>
32 #include <svx/svxids.hrc>
33 #include <editeng/eeitem.hxx>
34 #include <svl/itemset.hxx>
36 #include "futext.hxx"
37 #include "drwlayer.hxx"
38 #include "sc.hrc"
39 #include "tabvwsh.hxx"
40 #include "drawview.hxx"
42 // Create default drawing objects via keyboard
43 #include "scresid.hxx"
45 // Maximal erlaubte Mausbewegung um noch Drag&Drop zu starten
46 //! fusel,fuconstr,futext - zusammenfassen!
47 #define SC_MAXDRAGMOVE 3
49 //------------------------------------------------------------------
51 static void lcl_InvalidateAttribs( SfxBindings& rBindings )
53 rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
54 rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
55 rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
56 rBindings.Invalidate( SID_ULINE_VAL_NONE );
57 rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
58 rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
59 rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
60 rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
61 rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
62 rBindings.Invalidate( SID_ATTR_CHAR_FONT );
63 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
64 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
65 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
66 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
67 rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
68 rBindings.Invalidate( SID_ALIGNLEFT );
69 rBindings.Invalidate( SID_ALIGNCENTERHOR );
70 rBindings.Invalidate( SID_ALIGNRIGHT );
71 rBindings.Invalidate( SID_ALIGNBLOCK );
72 rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_10 );
73 rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_15 );
74 rBindings.Invalidate( SID_ATTR_PARA_LINESPACE_20 );
75 rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
76 rBindings.Invalidate( SID_SET_SUB_SCRIPT );
77 rBindings.Invalidate( SID_HYPERLINK_GETLINK );
78 rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
79 rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
80 rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
81 rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
82 // pseudo slots for Format menu
83 rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
84 rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
85 rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
86 rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
87 rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
88 rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
89 rBindings.Invalidate( SID_SET_SUB_SCRIPT );
90 rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
91 rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
94 static void lcl_UpdateHyphenator( Outliner& rOutliner, SdrObject* pObj )
96 // use hyphenator only if hyphenation attribute is set
97 if ( pObj && ((const SfxBoolItem&)pObj->GetMergedItem(EE_PARA_HYPHENATE)).GetValue() ) {
98 com::sun::star::uno::Reference<com::sun::star::linguistic2::XHyphenator> xHyphenator( LinguMgr::GetHyphenator() );
99 rOutliner.SetHyphenator( xHyphenator );
103 /*************************************************************************
105 |* Basisklasse fuer Textfunktionen
107 \************************************************************************/
109 FuText::FuText(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
110 SdrModel* pDoc, SfxRequest& rReq) :
111 FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq),
112 pTextObj(NULL)
116 /*************************************************************************
118 |* Destruktor
120 \************************************************************************/
122 FuText::~FuText()
124 // StopEditMode(); // in Deactivate !
127 /*************************************************************************
129 |* MouseButtonDown-event
131 \************************************************************************/
133 sal_Bool FuText::MouseButtonDown(const MouseEvent& rMEvt)
135 // remember button state for creation of own MouseEvents
136 SetMouseButtonCode(rMEvt.GetButtons());
137 sal_Bool bStraightEnter = true;
139 if ( pView->MouseButtonDown(rMEvt, pWindow) )
140 return (sal_True); // Event von der SdrView ausgewertet
142 if ( pView->IsTextEdit() )
144 if ( IsEditingANote() )
146 if( !IsSizingOrMovingNote(rMEvt) )
148 StopEditMode(); // Danebengeklickt, Ende mit Edit
149 bStraightEnter = false;
152 else
154 StopEditMode(); // Clicked outside, ending edit.
155 pView->UnmarkAll();
156 bStraightEnter = false;
158 pView->SetCreateMode();
161 aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
163 if ( rMEvt.IsLeft() )
165 SdrHdl* pHdl = pView->PickHandle(aMDPos);
167 sal_uLong nHdlNum = pView->GetHdlNum(pHdl);
169 if (pHdl != NULL)
171 if (pView->HasMarkablePoints() && pView->IsPointMarkable(*pHdl))
173 sal_Bool bPointMarked=pView->IsPointMarked(*pHdl);
175 if ( rMEvt.IsShift() )
177 if (!bPointMarked)
179 pView->MarkPoint(*pHdl);
181 else
183 pView->UnmarkPoint(*pHdl);
186 else
188 if (!bPointMarked)
190 pView->UnmarkAllPoints();
191 pView->MarkPoint(*pHdl);
194 pHdl=pView->GetHdl(nHdlNum);
198 SdrObject* pObj;
199 SdrPageView* pPV;
201 if ( pHdl != NULL || pView->IsMarkedHit(aMDPos) )
203 if (pHdl == NULL &&
204 // pView->TakeTextEditObject(aMDPos, pObj, pPV) )
205 pView->PickObj(aMDPos, pView->getHitTolLog(), pObj, pPV, SDRSEARCH_PICKTEXTEDIT) )
207 SdrOutliner* pO = MakeOutliner();
208 lcl_UpdateHyphenator( *pO, pObj );
210 // vertical flag:
211 // deduced from slot ids only if text object has no content
213 sal_uInt16 nSlotID = aSfxRequest.GetSlot();
214 sal_Bool bVertical = ( nSlotID == SID_DRAW_TEXT_VERTICAL );
215 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
216 if ( pOPO )
217 bVertical = pOPO->IsVertical(); // content wins
218 pO->SetVertical( bVertical );
220 //!?? ohne uebergebenen Outliner stimmen die Defaults nicht ???!?
221 if ( pView->SdrBeginTextEdit(pObj, pPV, pWindow, sal_True, pO) )
223 // EditEngine-UndoManager anmelden
224 pViewShell->SetDrawTextUndo( &pO->GetUndoManager() );
226 OutlinerView* pOLV = pView->GetTextEditOutlinerView();
227 if ( pOLV->MouseButtonDown(rMEvt) )
228 return (sal_True); // Event an den Outliner
231 else
233 // disable tail & circular move for caption objects.
234 bool bDrag = false;
235 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
236 if( rMarkList.GetMarkCount() == 1 )
238 SdrObject* pMarkedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
239 if( ScDrawLayer::IsNoteCaption( pMarkedObj ) )
241 if(pHdl->GetKind() != HDL_POLY && pHdl->GetKind() != HDL_CIRC)
242 bDrag = true;
244 else
245 bDrag = true; // different object
247 else
248 bDrag = true; // several objects
250 if ( bDrag )
252 aDragTimer.Start();
253 pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl);
257 else
259 sal_Bool bMacro = false;
261 // if (bMacro && pView->TakeMacroObject(aMDPos,pObj,pPV))
262 if (bMacro && pView->PickObj(aMDPos, pView->getHitTolLog(), pObj, pPV, SDRSEARCH_PICKMACRO) )
265 pView->BegMacroObj(aMDPos,pObj,pPV,pWindow);
267 else
269 if (pView->IsEditMode())
271 sal_Bool bPointMode=pView->HasMarkablePoints();
273 if (!rMEvt.IsShift())
275 if (bPointMode)
277 pView->UnmarkAllPoints();
279 else
281 pView->UnmarkAll();
284 pView->SetDragMode(SDRDRAG_MOVE);
285 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
286 rBindings.Invalidate( SID_OBJECT_ROTATE );
287 rBindings.Invalidate( SID_OBJECT_MIRROR );
290 if ( pView->MarkObj(aMDPos, -2, false, rMEvt.IsMod1()) )
292 aDragTimer.Start();
294 pHdl=pView->PickHandle(aMDPos);
296 if (pHdl!=NULL)
298 pView->MarkPoint(*pHdl);
299 pHdl=pView->GetHdl(nHdlNum);
302 pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl);
304 else
306 if (bPointMode)
308 pView->BegMarkPoints(aMDPos);
310 else
312 pView->BegMarkObj(aMDPos);
316 else if (aSfxRequest.GetSlot() == SID_DRAW_NOTEEDIT )
318 // Notizen editieren -> keine neuen Textobjekte erzeugen,
319 // stattdessen Textmodus verlassen
321 pViewShell->GetViewData()->GetDispatcher().
322 Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
324 else
326 if (bStraightEnter)//Hack for that silly idea that creating text fields is inside the text routine
328 /**********************************************************
329 * Objekt erzeugen
330 **********************************************************/
331 // Hack to align object to nearest grid position where object
332 // would be anchored ( if it were cell anchored )
333 // Get grid offset for current position ( note: aPnt is
334 // also adjusted )
335 Point aGridOff = CurrentGridSyncOffsetAndPos( aMDPos );
337 bool bRet = pView->BegCreateObj(aMDPos, (OutputDevice*) NULL);
338 if ( bRet )
339 pView->GetCreateObj()->SetGridOffset( aGridOff );
341 else if (pView->PickObj(aMDPos, pView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER | SDRSEARCH_BEFOREMARK))
343 pView->UnmarkAllObj();
344 ScViewData& rViewData = *pViewShell->GetViewData();
345 rViewData.GetDispatcher().Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
346 pView->MarkObj(pObj,pPV,false,false);
348 pHdl=pView->PickHandle(aMDPos);
349 pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl);
350 return(sal_True);
358 if (!bIsInDragMode)
360 pWindow->CaptureMouse();
361 // ForcePointer(&rMEvt);
362 lcl_InvalidateAttribs( pViewShell->GetViewFrame()->GetBindings() );
365 pViewShell->SetActivePointer(pView->GetPreferedPointer(
366 pWindow->PixelToLogic(rMEvt.GetPosPixel()), pWindow ));
367 if (!bStraightEnter)
369 pView->UnmarkAll();
370 ScViewData& rViewData = *pViewShell->GetViewData();
371 rViewData.GetDispatcher().Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
374 // return (bReturn);
375 return sal_True;
378 /*************************************************************************
380 |* MouseMove-event
382 \************************************************************************/
384 sal_Bool FuText::MouseMove(const MouseEvent& rMEvt)
386 sal_Bool bReturn = false;
388 // pViewShell->SetActivePointer(aNewPointer);
390 pViewShell->SetActivePointer(pView->GetPreferedPointer(
391 pWindow->PixelToLogic(rMEvt.GetPosPixel()), pWindow ));
393 if (aDragTimer.IsActive() )
395 Point aOldPixel = pWindow->LogicToPixel( aMDPos );
396 Point aNewPixel = rMEvt.GetPosPixel();
397 if ( std::abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
398 std::abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
399 aDragTimer.Stop();
402 Point aPix(rMEvt.GetPosPixel());
403 Point aPnt(pWindow->PixelToLogic(aPix));
404 // if object is being created then more than likely the mouse
405 // position has been 'adjusted' for the current zoom, need to
406 // restore the mouse position here to ensure resize works as expected
407 if ( pView->GetCreateObj() )
408 aPnt -= pView->GetCreateObj()->GetGridOffset();
410 if ( pView->MouseMove(rMEvt, pWindow) )
411 return (sal_True); // Event von der SdrView ausgewertet
413 if ( pView->IsAction() )
415 ForceScroll(aPix);
416 pView->MovAction(aPnt);
419 return (bReturn);
422 /*************************************************************************
424 |* MouseButtonUp-event
426 \************************************************************************/
428 sal_Bool FuText::MouseButtonUp(const MouseEvent& rMEvt)
430 // remember button state for creation of own MouseEvents
431 SetMouseButtonCode(rMEvt.GetButtons());
433 sal_Bool bReturn = false;
435 if (aDragTimer.IsActive() )
437 aDragTimer.Stop();
440 lcl_InvalidateAttribs( pViewShell->GetViewFrame()->GetBindings() );
442 Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
444 if ( pView->MouseButtonUp(rMEvt, pWindow) )
445 return (sal_True); // Event von der SdrView ausgewertet
447 if ( pView->IsDragObj() )
449 pView->EndDragObj( rMEvt.IsShift() );
450 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
451 if (rMarkList.GetMarkCount() == 1)
453 SdrMark* pMark = rMarkList.GetMark(0);
454 SdrObject* pObj = pMark->GetMarkedSdrObj();
455 FuPoor* pPoor = pViewShell->GetViewData()->GetView()->GetDrawFuncPtr();
456 FuText* pText = static_cast<FuText*>(pPoor);
457 pText->StopDragMode(pObj );
459 pView->ForceMarkedToAnotherPage();
461 else if ( pView->IsCreateObj() )
463 if (rMEvt.IsLeft())
465 pView->EndCreateObj(SDRCREATE_FORCEEND);
466 if (aSfxRequest.GetSlot() == SID_DRAW_TEXT_MARQUEE)
468 // Lauftext-Objekt erzeugen?
470 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
471 if (rMarkList.GetMark(0))
473 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
475 // die fuer das Scrollen benoetigten Attribute setzen
476 SfxItemSet aItemSet( pDrDoc->GetItemPool(),
477 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST);
479 aItemSet.Put( SdrTextAutoGrowWidthItem( false ) );
480 aItemSet.Put( SdrTextAutoGrowHeightItem( false ) );
481 aItemSet.Put( SdrTextAniKindItem( SDRTEXTANI_SLIDE ) );
482 aItemSet.Put( SdrTextAniDirectionItem( SDRTEXTANI_LEFT ) );
483 aItemSet.Put( SdrTextAniCountItem( 1 ) );
484 aItemSet.Put( SdrTextAniAmountItem(
485 (sal_Int16)pWindow->PixelToLogic(Size(2,1)).Width()) );
486 pObj->SetMergedItemSetAndBroadcast(aItemSet);
490 // init object different when vertical writing
491 sal_uInt16 nSlotID(aSfxRequest.GetSlot());
492 sal_Bool bVertical = (SID_DRAW_TEXT_VERTICAL == nSlotID);
493 if(bVertical)
495 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
496 if(rMarkList.GetMark(0))
498 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
499 if(pObj && pObj->ISA(SdrTextObj))
501 SdrTextObj* pText = (SdrTextObj*)pObj;
502 SfxItemSet aSet(pDrDoc->GetItemPool());
504 pText->SetVerticalWriting(sal_True);
506 aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
507 aSet.Put(SdrTextAutoGrowHeightItem(false));
508 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
509 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
511 pText->SetMergedItemSet(aSet);
516 SetInEditMode();
518 // Modus verlassen bei einzelnem Klick
519 // (-> fuconstr)
521 if ( !pView->AreObjectsMarked() )
523 pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
525 SfxDispatcher& rDisp = pViewShell->GetViewData()->GetDispatcher();
526 if ( pView->AreObjectsMarked() )
527 rDisp.Execute(SID_OBJECT_SELECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
528 else
529 rDisp.Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
533 else if ( pView->IsAction() )
535 pView->EndAction();
537 else if( !pView->IsAction() )
539 pWindow->ReleaseMouse();
541 if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
543 pView->MarkObj(aPnt, -2, false, rMEvt.IsMod1());
545 SfxDispatcher& rDisp = pViewShell->GetViewData()->GetDispatcher();
546 if ( pView->AreObjectsMarked() )
547 rDisp.Execute(SID_OBJECT_SELECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
548 else
549 rDisp.Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
553 return (bReturn);
556 /*************************************************************************
558 |* Maus-Pointer umschalten
560 \************************************************************************/
562 void FuText::ForcePointer(const MouseEvent* /* pMEvt */)
564 pViewShell->SetActivePointer( aNewPointer );
569 /*************************************************************************
571 |* Tastaturereignisse bearbeiten
573 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
574 |* FALSE.
576 \************************************************************************/
578 sal_Bool FuText::KeyInput(const KeyEvent& rKEvt)
580 sal_Bool bReturn = false;
582 if ( pView->KeyInput(rKEvt, pWindow) )
584 bReturn = sal_True;
585 lcl_InvalidateAttribs( pViewShell->GetViewFrame()->GetBindings() );
587 else
589 bReturn = FuDraw::KeyInput(rKEvt);
592 return (bReturn);
597 /*************************************************************************
599 |* Function aktivieren
601 \************************************************************************/
603 void FuText::Activate()
605 pView->SetDragMode(SDRDRAG_MOVE);
606 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
607 rBindings.Invalidate( SID_OBJECT_ROTATE );
608 rBindings.Invalidate( SID_OBJECT_MIRROR );
610 // Sofort in den Edit Mode setzen
611 // SetInEditMode();
613 // if (!pTextObj)
615 /**********************************************************************
616 * Kein Textobjekt im EditMode, daher CreateMode setzen
617 **********************************************************************/
618 sal_uInt16 nObj = OBJ_TEXT;
620 pView->SetCurrentObj(nObj);
622 pView->SetCreateMode();
625 aNewPointer = Pointer(POINTER_TEXT);
627 aOldPointer = pWindow->GetPointer();
628 pViewShell->SetActivePointer( aNewPointer );
630 FuConstruct::Activate();
634 /*************************************************************************
636 |* Function deaktivieren
638 \************************************************************************/
640 void FuText::Deactivate()
642 FuConstruct::Deactivate();
643 pViewShell->SetActivePointer( aOldPointer );
644 StopEditMode();
648 /*************************************************************************
650 |* Selektion hat sich geaendert
652 \************************************************************************/
654 void FuText::SelectionHasChanged()
656 pView->SetDragMode(SDRDRAG_MOVE);
657 SfxBindings& rBindings = pViewShell->GetViewFrame()->GetBindings();
658 rBindings.Invalidate( SID_OBJECT_ROTATE );
659 rBindings.Invalidate( SID_OBJECT_MIRROR );
661 pTextObj = NULL;
663 if ( pView->AreObjectsMarked() )
665 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
667 if (rMarkList.GetMarkCount() == 1)
669 SdrMark* pMark = rMarkList.GetMark(0);
670 SdrObject* pObj = pMark->GetMarkedSdrObj();
672 sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
674 if (nSdrObjKind == OBJ_TEXT ||
675 nSdrObjKind == OBJ_TITLETEXT ||
676 nSdrObjKind == OBJ_OUTLINETEXT /* ||
677 pObj->ISA(SdrTextObj) */ )
679 pTextObj = (SdrTextObj*) pObj;
684 if (!pTextObj)
686 /**********************************************************************
687 * Kein Textobjekt im EditMode, daher CreateMode setzen
688 **********************************************************************/
689 sal_uInt16 nObj = OBJ_TEXT;
690 sal_uInt16 nIdent;
691 sal_uInt32 nInvent;
692 pView->TakeCurrentObj(nIdent, nInvent);
694 pView->SetCurrentObj(nObj);
696 pView->SetCreateMode();
700 /*************************************************************************
702 |* Objekt in Edit-Mode setzen
704 \************************************************************************/
706 void FuText::SetInEditMode(SdrObject* pObj, const Point* pMousePixel,
707 sal_Bool bCursorToEnd, const KeyEvent* pInitialKey)
709 /* It is possible to pass a special (unselected) object in pObj, e.g. the
710 caption object of a cell note. If pObj is 0, then the selected object
711 is used. The layer will be relocked in FuText::StopEditMode(). */
712 if ( pObj && (pObj->GetLayer() == SC_LAYER_INTERN) )
713 pView->UnlockInternalLayer();
715 if ( !pObj && pView->AreObjectsMarked() )
717 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
718 if (rMarkList.GetMarkCount() == 1)
720 SdrMark* pMark = rMarkList.GetMark(0);
721 pObj = pMark->GetMarkedSdrObj();
725 pTextObj = NULL;
727 if ( pObj )
729 sal_uInt16 nSdrObjKind = pObj->GetObjIdentifier();
731 if (nSdrObjKind == OBJ_TEXT ||
732 nSdrObjKind == OBJ_TITLETEXT ||
733 nSdrObjKind == OBJ_OUTLINETEXT ||
734 pObj->ISA(SdrTextObj))
736 SdrPageView* pPV = pView->GetSdrPageView();
738 if ( pObj->HasTextEdit() )
740 SdrOutliner* pO = MakeOutliner();
741 lcl_UpdateHyphenator( *pO, pObj );
743 // vertical flag:
744 // deduced from slot ids only if text object has no content
746 sal_uInt16 nSlotID = aSfxRequest.GetSlot();
747 sal_Bool bVertical = ( nSlotID == SID_DRAW_TEXT_VERTICAL );
748 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
749 if ( pOPO )
750 bVertical = pOPO->IsVertical(); // content wins
751 pO->SetVertical( bVertical );
753 //!?? ohne uebergebenen Outliner stimmen die Defaults nicht ???!?
754 if ( pView->SdrBeginTextEdit(pObj, pPV, pWindow, sal_True, pO) )
756 // EditEngine-UndoManager anmelden
757 pViewShell->SetDrawTextUndo( &pO->GetUndoManager() );
759 pTextObj = (SdrTextObj*) pObj;
760 pView->SetEditMode();
762 // set text cursor to click position or to end,
763 // pass initial key event to outliner view
764 if ( pMousePixel || bCursorToEnd || pInitialKey )
766 OutlinerView* pOLV = pView->GetTextEditOutlinerView();
767 if (pOLV)
769 if ( pMousePixel )
771 MouseEvent aEditEvt( *pMousePixel, 1, MOUSE_SYNTHETIC, MOUSE_LEFT, 0 );
772 pOLV->MouseButtonDown(aEditEvt);
773 pOLV->MouseButtonUp(aEditEvt);
775 else if ( bCursorToEnd )
777 ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
778 pOLV->SetSelection(aNewSelection);
781 if ( pInitialKey )
782 pOLV->PostKeyEvent( *pInitialKey );
791 // Create default drawing objects via keyboard
792 SdrObject* FuText::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
794 // case SID_DRAW_TEXT:
795 // case SID_DRAW_TEXT_VERTICAL:
796 // case SID_DRAW_TEXT_MARQUEE:
797 // case SID_DRAW_NOTEEDIT:
799 SdrObject* pObj = SdrObjFactory::MakeNewObject(
800 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
801 0L, pDrDoc);
803 if(pObj)
805 if(pObj->ISA(SdrTextObj))
807 SdrTextObj* pText = (SdrTextObj*)pObj;
808 pText->SetLogicRect(rRectangle);
810 // don't set default text, start edit mode instead
811 // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
812 // pText->SetText(aText);
814 sal_Bool bVertical = (SID_DRAW_TEXT_VERTICAL == nID);
815 sal_Bool bMarquee = (SID_DRAW_TEXT_MARQUEE == nID);
817 pText->SetVerticalWriting(bVertical);
819 if(bVertical)
821 SfxItemSet aSet(pDrDoc->GetItemPool());
823 aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
824 aSet.Put(SdrTextAutoGrowHeightItem(false));
825 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
826 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
828 pText->SetMergedItemSet(aSet);
831 if(bMarquee)
833 SfxItemSet aSet(pDrDoc->GetItemPool(), SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST);
835 aSet.Put( SdrTextAutoGrowWidthItem( false ) );
836 aSet.Put( SdrTextAutoGrowHeightItem( false ) );
837 aSet.Put( SdrTextAniKindItem( SDRTEXTANI_SLIDE ) );
838 aSet.Put( SdrTextAniDirectionItem( SDRTEXTANI_LEFT ) );
839 aSet.Put( SdrTextAniCountItem( 1 ) );
840 aSet.Put( SdrTextAniAmountItem( (sal_Int16)pWindow->PixelToLogic(Size(2,1)).Width()) );
842 pObj->SetMergedItemSetAndBroadcast(aSet);
845 SetInEditMode( pObj ); // start edit mode
847 else
849 OSL_FAIL("Object is NO text object");
853 return pObj;
856 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */