Line data Source code
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 "futext.hxx"
21 : #include <editeng/eeitem.hxx>
22 : #include <editeng/editerr.hxx>
23 : #include <svx/dlgutil.hxx>
24 : #include <svx/svxerr.hxx>
25 : #include <tools/urlobj.hxx>
26 : #include <vcl/help.hxx>
27 : #include <editeng/editstat.hxx>
28 : #include <svl/aeitem.hxx>
29 : #include <svl/intitem.hxx>
30 : #include <svx/svdotext.hxx>
31 : #include <svx/svdogrp.hxx>
32 : #include <editeng/flditem.hxx>
33 : #include <svl/style.hxx>
34 : #include <svx/svdpagv.hxx>
35 : #include <sfx2/viewfrm.hxx>
36 : #include <sfx2/dispatch.hxx>
37 : #include <sfx2/bindings.hxx>
38 : #include <sfx2/request.hxx>
39 : #include <editeng/editeng.hxx>
40 : #include <svx/svdoutl.hxx>
41 : #include <svx/svxids.hrc>
42 : #include <sfx2/docfile.hxx>
43 : #include <comphelper/processfactory.hxx>
44 : #include <editeng/outlobj.hxx>
45 : #include <svtools/langtab.hxx>
46 :
47 : #include <editeng/frmdiritem.hxx>
48 :
49 : #include <svx/svdetc.hxx>
50 : #include <editeng/editview.hxx>
51 :
52 : #include "sdresid.hxx"
53 : #include "app.hrc"
54 : #include "res_bmp.hrc"
55 : #include "ViewShell.hxx"
56 : #include "ViewShellBase.hxx"
57 : #include "View.hxx"
58 : #include "Outliner.hxx"
59 : #include "Window.hxx"
60 : #include "drawdoc.hxx"
61 : #include "sdpage.hxx"
62 : #include "sdmod.hxx"
63 : #include "FrameView.hxx"
64 : #include "ToolBarManager.hxx"
65 : #include "DrawDocShell.hxx"
66 : #include "glob.hrc"
67 : #include "pres.hxx"
68 : #include "optsitem.hxx"
69 :
70 : using namespace ::com::sun::star;
71 : using namespace ::com::sun::star::uno;
72 : using namespace ::com::sun::star::lang;
73 : using namespace ::com::sun::star::linguistic2;
74 :
75 : namespace sd {
76 :
77 : static sal_uInt16 SidArray[] = {
78 : SID_STYLE_FAMILY2, // 5542
79 : SID_STYLE_FAMILY5, // 5545
80 : SID_REDO, // 5700
81 : SID_UNDO, // 5701
82 : SID_CUT, // 5710
83 : SID_COPY, // 5711
84 : SID_ATTR_TABSTOP, // 10002
85 : SID_ATTR_CHAR_FONT, // 10007
86 : SID_ATTR_CHAR_POSTURE, // 10008
87 : SID_ATTR_CHAR_WEIGHT, // 10009
88 : SID_ATTR_CHAR_SHADOWED, //10010
89 : SID_ATTR_CHAR_STRIKEOUT, //10013
90 : SID_ATTR_CHAR_UNDERLINE, // 10014
91 : SID_ATTR_CHAR_FONTHEIGHT, // 10015
92 : SID_ATTR_CHAR_COLOR, // 10017
93 : SID_ATTR_CHAR_KERNING, //10018
94 : SID_ATTR_PARA_ADJUST_LEFT, // 10028
95 : SID_ATTR_PARA_ADJUST_RIGHT, // 10029
96 : SID_ATTR_PARA_ADJUST_CENTER, // 10030
97 : SID_ATTR_PARA_ADJUST_BLOCK, // 10031
98 : SID_ATTR_PARA_LINESPACE_10, // 10034
99 : SID_ATTR_PARA_LINESPACE_15, // 10035
100 : SID_ATTR_PARA_LINESPACE_20, // 10036
101 : SID_ATTR_PARA_ULSPACE, // 10042
102 : SID_ATTR_PARA_LRSPACE, // 10043
103 : SID_ATTR_TRANSFORM_POS_X, // 10088
104 : SID_ATTR_TRANSFORM_POS_Y, // 10089
105 : SID_ATTR_TRANSFORM_WIDTH, // 10090
106 : SID_ATTR_TRANSFORM_HEIGHT,// 10091
107 : SID_ATTR_TRANSFORM_ROT_X, // 10093
108 : SID_ATTR_TRANSFORM_ROT_Y, // 10094
109 : SID_ATTR_TRANSFORM_ANGLE, // 10095 //Added
110 : SID_OUTLINE_UP, // 10150
111 : SID_OUTLINE_DOWN, // 10151
112 : SID_OUTLINE_LEFT, // 10152
113 : SID_OUTLINE_RIGHT, // 10153
114 : SID_ATTR_TRANSFORM_PROTECT_POS,// 10236
115 : SID_ATTR_TRANSFORM_PROTECT_SIZE,// 10237 //Added
116 : SID_FORMTEXT_STYLE, // 10257
117 : SID_SET_SUPER_SCRIPT, // 10294
118 : SID_SET_SUB_SCRIPT, // 10295
119 : SID_ATTR_TRANSFORM_AUTOWIDTH,// 10310
120 : SID_ATTR_TRANSFORM_AUTOHEIGHT,// 10311 //Added
121 : SID_HYPERLINK_GETLINK, // 10361
122 : SID_CHARMAP, // 10503
123 : SID_TEXTDIRECTION_LEFT_TO_RIGHT, // 10907
124 : SID_TEXTDIRECTION_TOP_TO_BOTTOM, // 10908
125 : SID_ATTR_PARA_LEFT_TO_RIGHT, // 10950
126 : SID_ATTR_PARA_RIGHT_TO_LEFT, // 10951
127 : FN_NUM_BULLET_ON, // 20138
128 : SID_PARASPACE_INCREASE, // 27346
129 : SID_PARASPACE_DECREASE, // 27347
130 : 0 };
131 :
132 0 : TYPEINIT1( FuText, FuConstruct );
133 :
134 :
135 : static sal_Bool bTestText = 0;
136 :
137 : /**
138 : * base class for text functions
139 : */
140 0 : FuText::FuText( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
141 : : FuConstruct(pViewSh, pWin, pView, pDoc, rReq)
142 : , bFirstObjCreated(sal_False)
143 : , bJustEndedEdit(false)
144 0 : , rRequest (rReq)
145 : {
146 0 : }
147 :
148 0 : FunctionReference FuText::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
149 : {
150 0 : FunctionReference xFunc( new FuText( pViewSh, pWin, pView, pDoc, rReq ) );
151 0 : return xFunc;
152 : }
153 :
154 : /** Destruktor */
155 0 : void FuText::disposing()
156 : {
157 0 : if(mpView)
158 : {
159 0 : if(mpView->SdrEndTextEdit(sal_False) == SDRENDTEXTEDIT_DELETED)
160 0 : mxTextObj.reset( 0 );
161 :
162 : // reset the RequestHandler of the used Outliner to the handler of the document
163 0 : ::Outliner* pOutliner = mpView->GetTextEditOutliner();
164 :
165 0 : if (pOutliner)
166 0 : pOutliner->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(mpDoc->GetStyleSheetPool()));
167 : }
168 0 : }
169 :
170 : /*************************************************************************
171 : |*
172 : |* Execute functionality of this class:
173 : |*
174 : |* #71422: Start the functionality of this class in this method
175 : |* and not in the ctor.
176 : |* If you construct an object of this class and you put the
177 : |* address of this object to pFuActual you've got a problem,
178 : |* because some methods inside DoExecute use the pFuActual-Pointer.
179 : |* If the code inside DoExecute is executed inside the ctor,
180 : |* the value of pFuActual is not right. And the value will not
181 : |* be right until the ctor finished !!!
182 : |*
183 : \************************************************************************/
184 0 : void FuText::DoExecute( SfxRequest& )
185 : {
186 0 : mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBarShell(
187 : ToolBarManager::TBG_FUNCTION,
188 0 : RID_DRAW_TEXT_TOOLBOX);
189 :
190 0 : mpView->SetCurrentObj(OBJ_TEXT);
191 0 : mpView->SetEditMode(SDREDITMODE_EDIT);
192 :
193 0 : MouseEvent aMEvt(mpWindow->GetPointerPosPixel());
194 :
195 0 : if (nSlotId == SID_TEXTEDIT)
196 : {
197 : // Try to select an object
198 0 : SdrPageView* pPV = mpView->GetSdrPageView();
199 0 : SdrViewEvent aVEvt;
200 0 : mpView->PickAnything(aMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
201 0 : mpView->MarkObj(aVEvt.pRootObj, pPV);
202 :
203 0 : mxTextObj.reset( dynamic_cast< SdrTextObj* >( aVEvt.pObj ) );
204 : }
205 0 : else if (mpView->AreObjectsMarked())
206 : {
207 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
208 :
209 0 : if (rMarkList.GetMarkCount() == 1)
210 : {
211 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
212 0 : mxTextObj.reset( dynamic_cast< SdrTextObj* >( pObj ) );
213 : }
214 : }
215 :
216 : // check for table
217 0 : if (mpView->AreObjectsMarked())
218 : {
219 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
220 :
221 0 : if (rMarkList.GetMarkCount() == 1)
222 : {
223 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
224 0 : if( pObj && (pObj->GetObjInventor() == SdrInventor ) && (pObj->GetObjIdentifier() == OBJ_TABLE) )
225 : {
226 0 : mpViewShell->GetViewShellBase().GetToolBarManager()->AddToolBarShell( ToolBarManager::TBG_FUNCTION, RID_DRAW_TABLE_TOOLBOX );
227 : }
228 : }
229 : }
230 :
231 0 : sal_Bool bQuickDrag = sal_True;
232 :
233 0 : const SfxItemSet* pArgs = rRequest.GetArgs();
234 :
235 0 : if (pArgs
236 :
237 : // test for type before using
238 0 : && SID_TEXTEDIT == nSlotId
239 0 : && SFX_ITEM_SET == pArgs->GetItemState(SID_TEXTEDIT)
240 :
241 0 : && (sal_uInt16)((SfxUInt16Item&)pArgs->Get(SID_TEXTEDIT)).GetValue() == 2)
242 : {
243 : // Selection by doubleclick -> don't allow QuickDrag
244 0 : bQuickDrag = sal_False;
245 : }
246 :
247 0 : SetInEditMode(aMEvt, bQuickDrag);
248 0 : }
249 :
250 0 : sal_Bool FuText::MouseButtonDown(const MouseEvent& rMEvt)
251 : {
252 0 : bMBDown = sal_True;
253 0 : bJustEndedEdit = false;
254 :
255 0 : sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
256 :
257 0 : mpView->SetMarkHdlWhenTextEdit(sal_True);
258 0 : SdrViewEvent aVEvt;
259 0 : SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
260 :
261 0 : if (eHit == SDRHIT_TEXTEDIT)
262 : {
263 : // hit text -> SdrView handles event
264 0 : if (mpView->MouseButtonDown(rMEvt, mpWindow))
265 0 : return (sal_True);
266 : }
267 :
268 0 : if (rMEvt.GetClicks() == 1)
269 : {
270 0 : if (mpView->IsTextEdit() && eHit != SDRHIT_MARKEDOBJECT && eHit != SDRHIT_HANDLE)
271 : {
272 : // finish text input
273 0 : if(mpView->SdrEndTextEdit() == SDRENDTEXTEDIT_DELETED)
274 : {
275 : /* Bugfix from MBA: during a double click onto the unused? area
276 : in text mode, we get with the second click eHit =
277 : SDRHIT_TEXTEDITOBJ since it goes to the TextObject which was
278 : created with the first click. But this is removed by
279 : SdrEndTextEdit since it is empty. But it is still in the mark
280 : list. The call MarkObj further below accesses then the dead
281 : object. As a simple fix, we determine eHit after
282 : SdrEndTextEdit again, this returns then SDRHIT_NONE. */
283 0 : mxTextObj.reset( NULL );
284 0 : eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
285 : }
286 :
287 0 : mpView->SetCurrentObj(OBJ_TEXT);
288 0 : mpView->SetEditMode(SDREDITMODE_EDIT);
289 : }
290 :
291 0 : if (rMEvt.IsLeft() || rMEvt.IsRight())
292 : {
293 0 : mpWindow->CaptureMouse();
294 : SdrObject* pObj;
295 0 : SdrPageView* pPV = mpView->GetSdrPageView();
296 :
297 0 : if (eHit == SDRHIT_TEXTEDIT)
298 : {
299 0 : SetInEditMode(rMEvt, sal_False);
300 : }
301 : else
302 : {
303 0 : sal_Bool bMacro = sal_False;
304 :
305 0 : if (bMacro && mpView->PickObj(aMDPos,mpView->getHitTolLog(),pObj,pPV,SDRSEARCH_PICKMACRO))
306 : {
307 : // Macro
308 0 : sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
309 0 : mpView->BegMacroObj(aMDPos,nHitLog,pObj,pPV,mpWindow);
310 : }
311 : else
312 : {
313 0 : if (eHit != SDRHIT_HANDLE)
314 : {
315 : // deselect selection
316 0 : if (!rMEvt.IsShift() && eHit == SDRHIT_TEXTEDITOBJ)
317 : {
318 0 : mpView->UnmarkAll();
319 0 : mpView->SetDragMode(SDRDRAG_MOVE);
320 : }
321 : }
322 :
323 0 : if ( aVEvt.eEvent == SDREVENT_EXECUTEURL ||
324 0 : eHit == SDRHIT_HANDLE ||
325 0 : eHit == SDRHIT_MARKEDOBJECT ||
326 0 : eHit == SDRHIT_TEXTEDITOBJ ||
327 0 : ( eHit == SDRHIT_UNMARKEDOBJECT && bFirstObjCreated &&
328 0 : !bPermanent ) )
329 : {
330 : // Handle, hit marked or umarked object
331 0 : if (eHit == SDRHIT_TEXTEDITOBJ)
332 : {
333 : /* hit text of unmarked object:
334 : select object and set to EditMode */
335 0 : mpView->MarkObj(aVEvt.pRootObj, pPV);
336 :
337 0 : if (aVEvt.pObj && aVEvt.pObj->ISA(SdrTextObj))
338 : {
339 0 : mxTextObj.reset( static_cast<SdrTextObj*>(aVEvt.pObj) );
340 : }
341 :
342 0 : SetInEditMode(rMEvt, sal_True);
343 : }
344 0 : else if (aVEvt.eEvent == SDREVENT_EXECUTEURL && !rMEvt.IsMod2())
345 : {
346 : // execute URL
347 0 : mpWindow->ReleaseMouse();
348 0 : SfxStringItem aStrItem(SID_FILE_NAME, aVEvt.pURLField->GetURL());
349 0 : SfxStringItem aReferer(SID_REFERER, mpDocSh->GetMedium()->GetName());
350 0 : SfxBoolItem aBrowseItem( SID_BROWSE, sal_True );
351 0 : SfxViewFrame* pFrame = mpViewShell->GetViewFrame();
352 0 : mpWindow->ReleaseMouse();
353 :
354 0 : if (rMEvt.IsMod1())
355 : {
356 : // open in new frame
357 : pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
358 0 : &aStrItem, &aBrowseItem, &aReferer, 0L);
359 : }
360 : else
361 : {
362 : // open in current frame
363 0 : SfxFrameItem aFrameItem(SID_DOCFRAME, pFrame);
364 : pFrame->GetDispatcher()->Execute(SID_OPENDOC, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
365 0 : &aStrItem, &aFrameItem, &aBrowseItem, &aReferer, 0L);
366 0 : }
367 : }
368 : else
369 : {
370 : // drag object or handle
371 :
372 : // #i78748#
373 : // do the EndTextEdit first, it will delete the handles and force a
374 : // recreation. This will make aVEvt.pHdl to point to a deleted handle,
375 : // thus it is necessary to reset it and to get it again.
376 :
377 : // #i112855#
378 : // cl: I'm not sure why we checked here also for mxTextObj->GetOutlinerParaObjet
379 : // this caused SdrEndTextEdit() to be called also when not in text editing and
380 : // this does not make sense and caused troubles. (see issue 112855)
381 :
382 0 : if( mpView->IsTextEdit() )
383 : {
384 0 : mpView->SdrEndTextEdit();
385 0 : bJustEndedEdit = true;
386 :
387 0 : if(aVEvt.pHdl)
388 : {
389 : // force new handle identification, the pointer will be dead here
390 : // since SdrEndTextEdit has resetted (deleted) the handles.
391 0 : aVEvt.pHdl = 0;
392 0 : mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
393 : }
394 : }
395 :
396 0 : if (!aVEvt.pHdl)
397 : {
398 0 : if( eHit == SDRHIT_UNMARKEDOBJECT )
399 : {
400 0 : if ( !rMEvt.IsShift() )
401 0 : mpView->UnmarkAll();
402 :
403 0 : mpView->MarkObj(aVEvt.pRootObj, pPV);
404 : }
405 :
406 : // Drag object
407 0 : bFirstMouseMove = sal_True;
408 0 : aDragTimer.Start();
409 : }
410 :
411 :
412 0 : if ( ! rMEvt.IsRight())
413 : {
414 : // we need to pick again since SdrEndTextEdit can rebuild the handles list
415 0 : eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
416 0 : if( (eHit == SDRHIT_HANDLE) || (eHit == SDRHIT_MARKEDOBJECT) )
417 : {
418 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
419 0 : mpView->BegDragObj(aMDPos, (OutputDevice*) NULL, aVEvt.pHdl, nDrgLog);
420 : }
421 : }
422 0 : bReturn = true;
423 0 : }
424 : }
425 0 : else if ( nSlotId != SID_TEXTEDIT &&
426 0 : (bPermanent || !bFirstObjCreated) )
427 : {
428 : // create object
429 0 : mpView->SetCurrentObj(OBJ_TEXT);
430 0 : mpView->SetEditMode(SDREDITMODE_CREATE);
431 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
432 0 : mpView->BegCreateObj(aMDPos, (OutputDevice*) NULL, nDrgLog);
433 : }
434 : else
435 : {
436 : // select
437 0 : if( !rMEvt.IsShift() )
438 0 : mpView->UnmarkAll();
439 :
440 0 : mpView->BegMarkObj( aMDPos );
441 : }
442 : }
443 : }
444 : }
445 : }
446 0 : else if ( rMEvt.GetClicks() == 2 && !mpView->IsTextEdit() )
447 : {
448 0 : MouseEvent aMEvt( mpWindow->GetPointerPosPixel() );
449 0 : SetInEditMode( aMEvt, sal_False );
450 : }
451 :
452 0 : if (!bIsInDragMode)
453 : {
454 0 : ForcePointer(&rMEvt);
455 0 : mpViewShell->GetViewFrame()->GetBindings().Invalidate(SidArray);
456 : }
457 :
458 0 : return (bReturn);
459 : }
460 :
461 0 : sal_Bool FuText::MouseMove(const MouseEvent& rMEvt)
462 : {
463 0 : sal_Bool bReturn = FuDraw::MouseMove(rMEvt);
464 :
465 0 : if (aDragTimer.IsActive() )
466 : {
467 0 : if( bFirstMouseMove )
468 0 : bFirstMouseMove = sal_False;
469 : else
470 0 : aDragTimer.Stop();
471 : }
472 :
473 0 : if (!bReturn && mpView->IsAction() && !mpDocSh->IsReadOnly())
474 : {
475 0 : Point aPix(rMEvt.GetPosPixel());
476 0 : Point aPnt(mpWindow->PixelToLogic(aPix));
477 :
478 0 : ForceScroll(aPix);
479 0 : mpView->MovAction(aPnt);
480 : }
481 :
482 0 : ForcePointer(&rMEvt);
483 :
484 0 : return (bReturn);
485 : }
486 :
487 0 : void FuText::ImpSetAttributesForNewTextObject(SdrTextObj* pTxtObj)
488 : {
489 0 : if(mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS)
490 : {
491 0 : if( nSlotId == SID_ATTR_CHAR )
492 : {
493 : /* Create Impress text object (rescales to line height)
494 : We get the correct height during the subsequent creation of the
495 : object, otherwise we draw to much */
496 0 : SfxItemSet aSet(mpViewShell->GetPool());
497 0 : aSet.Put(SdrTextMinFrameHeightItem(0));
498 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_False));
499 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_True));
500 0 : pTxtObj->SetMergedItemSet(aSet);
501 0 : pTxtObj->AdjustTextFrameWidthAndHeight();
502 0 : aSet.Put(SdrTextMaxFrameHeightItem(pTxtObj->GetLogicRect().GetSize().Height()));
503 0 : pTxtObj->SetMergedItemSet(aSet);
504 : }
505 0 : else if( nSlotId == SID_ATTR_CHAR_VERTICAL )
506 : {
507 0 : SfxItemSet aSet(mpViewShell->GetPool());
508 0 : aSet.Put(SdrTextMinFrameWidthItem(0));
509 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
510 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_False));
511 :
512 : // Needs to be set since default is SDRTEXTHORZADJUST_BLOCK
513 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
514 0 : pTxtObj->SetMergedItemSet(aSet);
515 0 : pTxtObj->AdjustTextFrameWidthAndHeight();
516 0 : aSet.Put(SdrTextMaxFrameWidthItem(pTxtObj->GetLogicRect().GetSize().Width()));
517 0 : pTxtObj->SetMergedItemSet(aSet);
518 : }
519 : }
520 : else
521 : {
522 0 : if( nSlotId == SID_ATTR_CHAR_VERTICAL )
523 : {
524 : // draw text object, needs to be initialized when vertical text is used
525 0 : SfxItemSet aSet(mpViewShell->GetPool());
526 :
527 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
528 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_False));
529 :
530 : // Set defaults for vertical klick-n'drag text object, pool defaults are:
531 : // SdrTextVertAdjustItem: SDRTEXTVERTADJUST_TOP
532 : // SdrTextHorzAdjustItem: SDRTEXTHORZADJUST_BLOCK
533 : // Analog to that:
534 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BLOCK));
535 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
536 :
537 0 : pTxtObj->SetMergedItemSet(aSet);
538 : }
539 : }
540 0 : }
541 :
542 0 : void FuText::ImpSetAttributesFitToSize(SdrTextObj* pTxtObj)
543 : {
544 : // FitToSize (fit to frame)
545 0 : SfxItemSet aSet(mpViewShell->GetPool(), SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWWIDTH);
546 0 : SdrFitToSizeType eFTS = SDRTEXTFIT_PROPORTIONAL;
547 0 : aSet.Put(SdrTextFitToSizeTypeItem(eFTS));
548 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_False));
549 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_False));
550 0 : pTxtObj->SetMergedItemSet(aSet);
551 0 : pTxtObj->AdjustTextFrameWidthAndHeight();
552 0 : }
553 :
554 0 : void FuText::ImpSetAttributesFitToSizeVertical(SdrTextObj* pTxtObj)
555 : {
556 0 : SfxItemSet aSet(mpViewShell->GetPool(),
557 0 : SDRATTR_TEXT_AUTOGROWHEIGHT, SDRATTR_TEXT_AUTOGROWWIDTH);
558 0 : SdrFitToSizeType eFTS = SDRTEXTFIT_PROPORTIONAL;
559 0 : aSet.Put(SdrTextFitToSizeTypeItem(eFTS));
560 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_False));
561 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_False));
562 0 : pTxtObj->SetMergedItemSet(aSet);
563 0 : pTxtObj->AdjustTextFrameWidthAndHeight();
564 0 : }
565 :
566 0 : void FuText::ImpSetAttributesFitCommon(SdrTextObj* pTxtObj)
567 : {
568 : // Normal Textobject
569 0 : if (mpDoc->GetDocumentType() == DOCUMENT_TYPE_IMPRESS)
570 : {
571 0 : if( nSlotId == SID_ATTR_CHAR )
572 : {
573 : // Impress text object (rescales to line height)
574 0 : SfxItemSet aSet(mpViewShell->GetPool());
575 0 : aSet.Put(SdrTextMinFrameHeightItem(0));
576 0 : aSet.Put(SdrTextMaxFrameHeightItem(0));
577 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_True));
578 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_False));
579 0 : pTxtObj->SetMergedItemSet(aSet);
580 : }
581 0 : else if( nSlotId == SID_ATTR_CHAR_VERTICAL )
582 : {
583 0 : SfxItemSet aSet(mpViewShell->GetPool());
584 0 : aSet.Put(SdrTextMinFrameWidthItem(0));
585 0 : aSet.Put(SdrTextMaxFrameWidthItem(0));
586 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
587 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_False));
588 0 : pTxtObj->SetMergedItemSet(aSet);
589 : }
590 :
591 0 : pTxtObj->AdjustTextFrameWidthAndHeight();
592 : }
593 0 : }
594 :
595 0 : sal_Bool FuText::MouseButtonUp(const MouseEvent& rMEvt)
596 : {
597 0 : sal_Bool bReturn = sal_False;
598 : SdrObject* pObj;
599 : SdrPageView* pPV;
600 0 : if (aDragTimer.IsActive())
601 : {
602 0 : aDragTimer.Stop();
603 0 : bIsInDragMode = sal_False;
604 : }
605 :
606 0 : mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
607 :
608 0 : Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
609 :
610 0 : if( (mpView && mpView->MouseButtonUp(rMEvt, mpWindow)) || rMEvt.GetClicks() == 2 )
611 0 : return (sal_True); // handle event from SdrView
612 :
613 0 : sal_Bool bEmptyTextObj = sal_False;
614 :
615 0 : if (mxTextObj.is())
616 : {
617 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
618 :
619 0 : if (rMarkList.GetMarkCount() == 1
620 0 : && ( rMarkList.GetMark(0)->GetMarkedSdrObj() == mxTextObj.get()) )
621 : {
622 0 : if( mxTextObj.is() && !GetTextObj()->GetOutlinerParaObject() )
623 0 : bEmptyTextObj = sal_True;
624 : else
625 0 : bFirstObjCreated = sal_True;
626 : }
627 : else
628 : {
629 0 : mxTextObj.reset( 0 );
630 : }
631 : }
632 :
633 0 : if( mpView && mpView->IsDragObj())
634 : {
635 : // object was moved
636 0 : FrameView* pFrameView = mpViewShell->GetFrameView();
637 0 : sal_Bool bDragWithCopy = (rMEvt.IsMod1() && pFrameView->IsDragWithCopy());
638 :
639 0 : if (bDragWithCopy)
640 : {
641 0 : bDragWithCopy = !mpView->IsPresObjSelected(sal_False, sal_True);
642 : }
643 :
644 0 : mpView->SetDragWithCopy(bDragWithCopy);
645 0 : mpView->EndDragObj( mpView->IsDragWithCopy() );
646 0 : mpView->ForceMarkedToAnotherPage();
647 0 : mpView->SetCurrentObj(OBJ_TEXT);
648 :
649 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
650 :
651 0 : if (bJustEndedEdit)
652 : {
653 0 : bJustEndedEdit = false;
654 0 : FuPoor::cancel();
655 : }
656 0 : if ((rMEvt.GetClicks() != 2) &&
657 0 : !rMEvt.IsShift() && !rMEvt.IsMod1() && !rMEvt.IsMod2() && !rMEvt.IsRight() &&
658 0 : std::abs(aPnt.X() - aMDPos.X()) < nDrgLog &&
659 0 : std::abs(aPnt.Y() - aMDPos.Y()) < nDrgLog)
660 : {
661 : /*************************************************************
662 : * From text mode, you don't want to rotate immediately.
663 : **************************************************************/
664 0 : if (mpView->PickObj(aMDPos, mpView->getHitTolLog(), pObj, pPV, SDRSEARCH_ALSOONMASTER | SDRSEARCH_BEFOREMARK))
665 : {
666 0 : mpView->UnmarkAllObj();
667 0 : mpView->MarkObj(pObj,pPV,false,false);
668 0 : return (bReturn);
669 : }
670 : }
671 : }
672 0 : else if( mpView && mpView->IsCreateObj() && rMEvt.IsLeft())
673 : {
674 : // object was created
675 0 : mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetCreateObj() ) );
676 :
677 0 : if( mxTextObj.is() )
678 : {
679 : //AW outliner needs to be set to vertical when there is no
680 : // outliner object up to now; also it needs to be set back to not
681 : // vertical when there was a vertical one used last time.
682 0 : OutlinerParaObject* pOPO = GetTextObj()->GetOutlinerParaObject();
683 0 : SdrOutliner& rOutl = mxTextObj->GetModel()->GetDrawOutliner(GetTextObj());
684 0 : sal_Bool bVertical((pOPO && pOPO->IsVertical())
685 0 : || nSlotId == SID_ATTR_CHAR_VERTICAL
686 0 : || nSlotId == SID_TEXT_FITTOSIZE_VERTICAL);
687 0 : rOutl.SetVertical(bVertical);
688 :
689 : // Before ImpSetAttributesForNewTextObject the vertical writing mode
690 : // needs to be set at the object. This is done here at the OutlinerParaObject
691 : // directly to not mirror the layout text items involved. These items will be set
692 : // from ImpSetAttributesForNewTextObject and below.
693 0 : OutlinerParaObject* pPara = GetTextObj()->GetOutlinerParaObject();
694 :
695 0 : if(!pPara)
696 : {
697 0 : GetTextObj()->ForceOutlinerParaObject();
698 0 : pPara = GetTextObj()->GetOutlinerParaObject();
699 : }
700 :
701 0 : if(pPara && (bool)bVertical != pPara->IsVertical())
702 : {
703 : // set ParaObject orientation accordingly
704 0 : pPara->SetVertical(bVertical);
705 : }
706 :
707 0 : ImpSetAttributesForNewTextObject(GetTextObj());
708 : }
709 :
710 0 : if (!mpView->EndCreateObj(SDRCREATE_FORCEEND))
711 : {
712 : // it was not possible to create text object
713 0 : mxTextObj.reset(0);
714 : }
715 0 : else if (nSlotId == SID_TEXT_FITTOSIZE)
716 : {
717 0 : ImpSetAttributesFitToSize(GetTextObj());
718 :
719 0 : SetInEditMode(rMEvt, sal_False);
720 : }
721 0 : else if ( nSlotId == SID_TEXT_FITTOSIZE_VERTICAL )
722 : {
723 0 : ImpSetAttributesFitToSizeVertical(GetTextObj());
724 :
725 0 : SetInEditMode(rMEvt, sal_False);
726 : }
727 : else
728 : {
729 0 : ImpSetAttributesFitCommon(GetTextObj());
730 :
731 : // thereby the handles and the gray frame are correct
732 0 : mpView->AdjustMarkHdl();
733 0 : mpView->PickHandle(aPnt);
734 0 : SetInEditMode(rMEvt, sal_False);
735 : }
736 : }
737 0 : else if ( mpView && mpView->IsAction())
738 : {
739 0 : mpView->EndAction();
740 : }
741 :
742 0 : ForcePointer(&rMEvt);
743 0 : mpWindow->ReleaseMouse();
744 0 : sal_uInt16 nDrgLog1 = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
745 :
746 0 : if ( mpView && !mpView->AreObjectsMarked() &&
747 0 : std::abs(aMDPos.X() - aPnt.X()) < nDrgLog1 &&
748 0 : std::abs(aMDPos.Y() - aPnt.Y()) < nDrgLog1 &&
749 0 : !rMEvt.IsShift() && !rMEvt.IsMod2() )
750 : {
751 0 : SdrPageView* pPV2 = mpView->GetSdrPageView();
752 0 : SdrViewEvent aVEvt;
753 0 : mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
754 0 : mpView->MarkObj(aVEvt.pRootObj, pPV2);
755 : }
756 :
757 0 : if ( !mxTextObj.is() && mpView )
758 : {
759 0 : if ( ( (!bEmptyTextObj && bPermanent) ||
760 0 : (!bFirstObjCreated && !bPermanent) ) &&
761 0 : !mpDocSh->IsReadOnly() &&
762 0 : nSlotId != SID_TEXTEDIT )
763 : {
764 : // text body (left-justified AutoGrow)
765 0 : mpView->SetCurrentObj(OBJ_TEXT);
766 0 : mpView->SetEditMode(SDREDITMODE_CREATE);
767 0 : sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
768 0 : mpView->BegCreateObj(aMDPos, (OutputDevice*) NULL, nDrgLog);
769 :
770 0 : sal_Bool bSnapEnabled = mpView->IsSnapEnabled();
771 :
772 0 : if (bSnapEnabled)
773 0 : mpView->SetSnapEnabled(sal_False);
774 :
775 0 : aPnt.X() += nDrgLog + nDrgLog;
776 0 : aPnt.Y() += nDrgLog + nDrgLog;
777 0 : mpView->MovAction(aPnt);
778 :
779 0 : mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetCreateObj() ) );
780 :
781 0 : if(mxTextObj.is())
782 : {
783 0 : GetTextObj()->SetDisableAutoWidthOnDragging(sal_True);
784 : }
785 :
786 0 : if(!mpView->EndCreateObj(SDRCREATE_FORCEEND))
787 : {
788 0 : mxTextObj.reset(0);
789 : }
790 :
791 0 : if(bSnapEnabled)
792 0 : mpView->SetSnapEnabled(bSnapEnabled);
793 :
794 0 : if(mxTextObj.is())
795 : {
796 0 : SfxItemSet aSet(mpViewShell->GetPool());
797 0 : aSet.Put(SdrTextMinFrameHeightItem(0));
798 0 : aSet.Put(SdrTextMinFrameWidthItem(0));
799 0 : aSet.Put(SdrTextAutoGrowHeightItem(sal_True));
800 0 : aSet.Put(SdrTextAutoGrowWidthItem(sal_True));
801 :
802 0 : if(nSlotId == SID_ATTR_CHAR_VERTICAL)
803 : {
804 : // Here, all items which need to be different from pool default need to be set
805 : // again on the newly created text object.
806 : // Since this is a simple klick text object, it is first created, then SetVertical()
807 : // is used, then ImpSetAttributesForNewTextObject is called and then the object is
808 : // deleted again since not the minimum drag distance was travelled. Then, a new
809 : // klick text object is created and thus all that stuff needs to be set again here.
810 : //
811 : // Before using the new object the vertical writing mode
812 : // needs to be set. This is done here at the OutlinerParaObject
813 : // directly to not mirror the layout text items involved. These items will be set
814 : // below.
815 0 : OutlinerParaObject* pPara = GetTextObj()->GetOutlinerParaObject();
816 :
817 0 : if(!pPara)
818 : {
819 0 : GetTextObj()->ForceOutlinerParaObject();
820 0 : pPara = GetTextObj()->GetOutlinerParaObject();
821 : }
822 :
823 0 : if(pPara && sal_True != pPara->IsVertical())
824 : {
825 : // set ParaObject orientation accordingly
826 0 : pPara->SetVertical(sal_True);
827 : }
828 :
829 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
830 :
831 : // Analog to the else case below, for vertical simple click texts
832 : // one of the defaulted setted items from ImpSetAttributesForNewTextObject
833 : // needs to be adapted to non-block mode.
834 0 : const SfxItemSet& rSet = mpView->GetDefaultAttr();
835 0 : SvxFrameDirection eDirection = (SvxFrameDirection)((SvxFrameDirectionItem&)rSet.Get(EE_PARA_WRITINGDIR)).GetValue();
836 :
837 0 : if(FRMDIR_HORI_RIGHT_TOP == eDirection || FRMDIR_VERT_TOP_RIGHT == eDirection)
838 : {
839 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_BOTTOM));
840 : }
841 : else
842 : {
843 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
844 : }
845 : }
846 : else
847 : {
848 : // This is for Format/Page settings. Since this also leads
849 : // to the object defaults to be changed, i think this code can be
850 : // removed. CL. wanted to take a look before adding this.
851 :
852 : // Look in the object defaults if left-to-right is wanted. If
853 : // yes, set text anchoring to right to let the box grow to left.
854 0 : const SfxItemSet& rSet = mpView->GetDefaultAttr();
855 0 : SvxFrameDirection eDirection = (SvxFrameDirection)((SvxFrameDirectionItem&)rSet.Get(EE_PARA_WRITINGDIR)).GetValue();
856 :
857 0 : if(FRMDIR_HORI_RIGHT_TOP == eDirection)
858 : {
859 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
860 : }
861 : else
862 : {
863 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_LEFT));
864 : }
865 : }
866 :
867 0 : GetTextObj()->SetMergedItemSet(aSet);
868 0 : GetTextObj()->SetDisableAutoWidthOnDragging(sal_True);
869 0 : SetInEditMode(rMEvt, sal_False);
870 : }
871 :
872 0 : bFirstObjCreated = sal_True;
873 : }
874 : else
875 : {
876 : // switch to selection
877 0 : if (mpView->SdrEndTextEdit() == SDRENDTEXTEDIT_DELETED)
878 : {
879 0 : mxTextObj.reset(0);
880 : }
881 :
882 : mpViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_OBJECT_SELECT,
883 0 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
884 : }
885 : }
886 0 : if (bJustEndedEdit)
887 : {
888 0 : bJustEndedEdit = false;
889 0 : FuPoor::cancel();
890 : }
891 0 : bMBDown = sal_False;
892 0 : FuConstruct::MouseButtonUp(rMEvt);
893 0 : return (bReturn);
894 : }
895 :
896 : /**
897 : * handle keyboard events
898 : * @returns sal_True if the event was handled, sal_False otherwise
899 : */
900 0 : sal_Bool FuText::KeyInput(const KeyEvent& rKEvt)
901 : {
902 0 : sal_Bool bReturn = sal_False;
903 0 : mpView->SetMarkHdlWhenTextEdit(sal_True);
904 :
905 0 : KeyCode nCode = rKEvt.GetKeyCode();
906 0 : sal_Bool bShift = nCode.IsShift();
907 :
908 0 : if(mxTextObj.is())
909 : {
910 : // maybe object is deleted, test if it's equal to the selected object
911 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
912 0 : SdrObject* pSelectedObj = 0L;
913 :
914 0 : if(1 == rMarkList.GetMarkCount())
915 : {
916 0 : SdrMark* pMark = rMarkList.GetMark(0);
917 0 : pSelectedObj = pMark->GetMarkedSdrObj();
918 : }
919 :
920 0 : if(mxTextObj.get() != pSelectedObj)
921 : {
922 0 : mxTextObj.reset(0);
923 : }
924 : }
925 :
926 0 : if ( mxTextObj.is() && mxTextObj->GetObjInventor() == SdrInventor && mxTextObj->GetObjIdentifier() == OBJ_TITLETEXT && rKEvt.GetKeyCode().GetCode() == KEY_RETURN )
927 : {
928 : // title text object: always soft breaks
929 0 : bShift = sal_True;
930 : }
931 :
932 0 : sal_uInt16 nKey = nCode.GetCode();
933 0 : KeyCode aKeyCode (nKey, bShift, nCode.IsMod1(), nCode.IsMod2(), nCode.IsMod3() );
934 0 : KeyEvent aKEvt(rKEvt.GetCharCode(), aKeyCode);
935 :
936 0 : sal_Bool bOK = sal_True;
937 :
938 0 : if (mpDocSh->IsReadOnly())
939 : {
940 0 : bOK = !EditEngine::DoesKeyChangeText(aKEvt);
941 : }
942 0 : if( aKeyCode.GetCode() == KEY_PAGEUP || aKeyCode.GetCode() == KEY_PAGEDOWN )
943 : {
944 0 : bOK = sal_False; // default handling in base class
945 : }
946 :
947 0 : if (bOK && mpView->KeyInput(aKEvt, mpWindow) )
948 : {
949 0 : bReturn = sal_True;
950 :
951 0 : mpViewShell->GetViewFrame()->GetBindings().Invalidate( SidArray );
952 :
953 : }
954 0 : else if (aKeyCode == KEY_ESCAPE)
955 : {
956 0 : bReturn = cancel();
957 : }
958 :
959 0 : if( bPermanent )
960 : {
961 0 : mpView->SetCurrentObj(OBJ_TEXT);
962 0 : mpView->SetEditMode(SDREDITMODE_CREATE);
963 : }
964 :
965 0 : if (!bReturn)
966 : {
967 0 : bReturn = FuDraw::KeyInput(aKEvt);
968 : }
969 :
970 0 : return (bReturn);
971 : }
972 :
973 :
974 :
975 0 : void FuText::Activate()
976 : {
977 0 : mpView->SetQuickTextEditMode(mpViewShell->GetFrameView()->IsQuickEdit());
978 :
979 : // #i89661# it's no longer necessary to make it so big here, it's fine tuned
980 : // for text objects in SdrMarkView::CheckSingleSdrObjectHit
981 0 : mpView->SetHitTolerancePixel( 2 * HITPIX );
982 :
983 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
984 :
985 0 : if (pOLV)
986 0 : pOLV->ShowCursor();
987 :
988 0 : FuConstruct::Activate();
989 :
990 0 : if( pOLV )
991 0 : mpView->SetEditMode(SDREDITMODE_EDIT);
992 0 : }
993 :
994 :
995 0 : void FuText::Deactivate()
996 : {
997 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
998 :
999 0 : if (pOLV)
1000 0 : pOLV->HideCursor();
1001 :
1002 0 : mpView->SetHitTolerancePixel( HITPIX );
1003 :
1004 0 : FuConstruct::Deactivate();
1005 0 : }
1006 :
1007 :
1008 : /**
1009 : * Sets the object into the edit mode.
1010 : */
1011 0 : void FuText::SetInEditMode(const MouseEvent& rMEvt, sal_Bool bQuickDrag)
1012 : {
1013 0 : SdrPageView* pPV = mpView->GetSdrPageView();
1014 0 : if( mxTextObj.is() && (mxTextObj->GetPage() == pPV->GetPage()) )
1015 : {
1016 0 : mpView->SetCurrentObj(OBJ_TEXT);
1017 :
1018 0 : if( bPermanent )
1019 0 : mpView->SetEditMode(SDREDITMODE_CREATE);
1020 : else
1021 0 : mpView->SetEditMode(SDREDITMODE_EDIT);
1022 :
1023 0 : sal_Bool bEmptyOutliner = sal_False;
1024 :
1025 0 : if (!GetTextObj()->GetOutlinerParaObject() && mpView->GetTextEditOutliner())
1026 : {
1027 0 : ::Outliner* pOutl = mpView->GetTextEditOutliner();
1028 0 : sal_Int32 nParaAnz = pOutl->GetParagraphCount();
1029 0 : Paragraph* p1stPara = pOutl->GetParagraph( 0 );
1030 :
1031 0 : if (nParaAnz==1 && p1stPara)
1032 : {
1033 : // with only one paragraph
1034 0 : if (pOutl->GetText(p1stPara).Len() == 0)
1035 : {
1036 0 : bEmptyOutliner = sal_True;
1037 : }
1038 : }
1039 : }
1040 :
1041 0 : if (GetTextObj() != mpView->GetTextEditObject() || bEmptyOutliner)
1042 : {
1043 0 : sal_uInt32 nInv = mxTextObj->GetObjInventor();
1044 0 : sal_uInt16 nSdrObjKind = mxTextObj->GetObjIdentifier();
1045 :
1046 0 : if (nInv == SdrInventor && GetTextObj()->HasTextEdit() &&
1047 0 : (nSdrObjKind == OBJ_TEXT ||
1048 0 : nSdrObjKind == OBJ_TITLETEXT ||
1049 0 : nSdrObjKind == OBJ_OUTLINETEXT || !mxTextObj->IsEmptyPresObj() ) )
1050 : {
1051 : // create new outliner (owned by SdrObjEditView)
1052 0 : SdrOutliner* pOutl = SdrMakeOutliner( OUTLINERMODE_OUTLINEOBJECT, mpDoc );
1053 :
1054 0 : if (bEmptyOutliner)
1055 0 : mpView->SdrEndTextEdit(sal_True);
1056 :
1057 0 : SdrTextObj* pTextObj = GetTextObj();
1058 0 : if( pTextObj )
1059 : {
1060 0 : OutlinerParaObject* pOPO = pTextObj->GetOutlinerParaObject();
1061 0 : if( ( pOPO && pOPO->IsVertical() ) || (nSlotId == SID_ATTR_CHAR_VERTICAL) || (nSlotId == SID_TEXT_FITTOSIZE_VERTICAL) )
1062 0 : pOutl->SetVertical( sal_True );
1063 :
1064 0 : if( pTextObj->getTextCount() > 1 )
1065 : {
1066 0 : Point aPix(rMEvt.GetPosPixel());
1067 0 : Point aPnt(mpWindow->PixelToLogic(aPix));
1068 0 : pTextObj->setActiveText( pTextObj->CheckTextHit(aPnt ) );
1069 : }
1070 :
1071 0 : if (mpView->SdrBeginTextEdit(pTextObj, pPV, mpWindow, sal_True, pOutl) && mxTextObj->GetObjInventor() == SdrInventor)
1072 : {
1073 0 : bFirstObjCreated = sal_True;
1074 0 : DeleteDefaultText();
1075 :
1076 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
1077 :
1078 0 : nSdrObjKind = mxTextObj->GetObjIdentifier();
1079 :
1080 0 : SdrViewEvent aVEvt;
1081 0 : SdrHitKind eHit = mpView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
1082 :
1083 0 : if (eHit == SDRHIT_TEXTEDIT)
1084 : {
1085 : // hit text
1086 0 : if (nSdrObjKind == OBJ_TEXT ||
1087 0 : nSdrObjKind == OBJ_TITLETEXT ||
1088 0 : nSdrObjKind == OBJ_OUTLINETEXT ||
1089 0 : nSdrObjKind == OBJ_TABLE ||
1090 0 : nSlotId == SID_TEXTEDIT ||
1091 : !bQuickDrag)
1092 : {
1093 0 : pOLV->MouseButtonDown(rMEvt);
1094 0 : pOLV->MouseMove(rMEvt);
1095 0 : pOLV->MouseButtonUp(rMEvt);
1096 : }
1097 :
1098 0 : if (mpViewShell->GetFrameView()->IsQuickEdit() && bQuickDrag && GetTextObj()->GetOutlinerParaObject())
1099 : {
1100 0 : pOLV->MouseButtonDown(rMEvt);
1101 : }
1102 : }
1103 : else
1104 : {
1105 : // Move cursor to end of text
1106 0 : ESelection aNewSelection(EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND, EE_PARA_NOT_FOUND, EE_INDEX_NOT_FOUND);
1107 0 : if (pOLV != NULL)
1108 0 : pOLV->SetSelection(aNewSelection);
1109 0 : }
1110 : }
1111 : else
1112 : {
1113 0 : mpView->RestoreDefaultText(dynamic_cast< SdrTextObj* >( mxTextObj.get() ));
1114 : }
1115 : }
1116 : }
1117 : }
1118 : }
1119 : else
1120 : {
1121 0 : mxTextObj.reset(0);
1122 : }
1123 0 : }
1124 :
1125 : /**
1126 : * Text entry is started, if necessary delete the default text.
1127 : */
1128 0 : sal_Bool FuText::DeleteDefaultText()
1129 : {
1130 0 : sal_Bool bDeleted = sal_False;
1131 :
1132 0 : if ( mxTextObj.is() && mxTextObj->IsEmptyPresObj() )
1133 : {
1134 0 : SdPage* pPage = (SdPage*) mxTextObj->GetPage();
1135 :
1136 0 : if (pPage)
1137 : {
1138 0 : PresObjKind ePresObjKind = pPage->GetPresObjKind(mxTextObj.get());
1139 :
1140 0 : if ( (ePresObjKind == PRESOBJ_TITLE ||
1141 0 : ePresObjKind == PRESOBJ_OUTLINE ||
1142 0 : ePresObjKind == PRESOBJ_NOTES ||
1143 0 : ePresObjKind == PRESOBJ_TEXT) &&
1144 0 : !pPage->IsMasterPage() )
1145 : {
1146 0 : ::Outliner* pOutliner = mpView->GetTextEditOutliner();
1147 0 : SfxStyleSheet* pSheet = pOutliner->GetStyleSheet( 0 );
1148 0 : sal_Bool bIsUndoEnabled = pOutliner->IsUndoEnabled();
1149 0 : if( bIsUndoEnabled )
1150 0 : pOutliner->EnableUndo(sal_False);
1151 :
1152 0 : pOutliner->SetText( String(), pOutliner->GetParagraph( 0 ) );
1153 :
1154 0 : if( bIsUndoEnabled )
1155 0 : pOutliner->EnableUndo(sal_True);
1156 :
1157 0 : if (pSheet &&
1158 0 : (ePresObjKind == PRESOBJ_NOTES || ePresObjKind == PRESOBJ_TEXT))
1159 0 : pOutliner->SetStyleSheet(0, pSheet);
1160 :
1161 0 : mxTextObj->SetEmptyPresObj(sal_True);
1162 0 : bDeleted = sal_True;
1163 : }
1164 : }
1165 : }
1166 :
1167 0 : return(bDeleted);
1168 : }
1169 :
1170 0 : sal_Bool FuText::Command(const CommandEvent& rCEvt)
1171 : {
1172 0 : return( FuPoor::Command(rCEvt) );
1173 : }
1174 :
1175 0 : sal_Bool FuText::RequestHelp(const HelpEvent& rHEvt)
1176 : {
1177 0 : sal_Bool bReturn = sal_False;
1178 :
1179 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
1180 :
1181 0 : if ((Help::IsBalloonHelpEnabled() || Help::IsQuickHelpEnabled()) &&
1182 0 : mxTextObj.is() && pOLV && pOLV->GetFieldUnderMousePointer())
1183 : {
1184 0 : String aHelpText;
1185 0 : const SvxFieldItem* pFieldItem = pOLV->GetFieldUnderMousePointer();
1186 0 : const SvxFieldData* pField = pFieldItem->GetField();
1187 :
1188 0 : if (pField && pField->ISA(SvxURLField))
1189 : {
1190 : // URL-Field
1191 0 : aHelpText = INetURLObject::decode( ((const SvxURLField*)pField)->GetURL(), '%', INetURLObject::DECODE_WITH_CHARSET );
1192 : }
1193 0 : if (aHelpText.Len())
1194 : {
1195 0 : Rectangle aLogicPix = mpWindow->LogicToPixel(mxTextObj->GetLogicRect());
1196 0 : Rectangle aScreenRect(mpWindow->OutputToScreenPixel(aLogicPix.TopLeft()),
1197 0 : mpWindow->OutputToScreenPixel(aLogicPix.BottomRight()));
1198 :
1199 0 : if (Help::IsBalloonHelpEnabled())
1200 : {
1201 0 : bReturn = Help::ShowBalloon( (Window*)mpWindow, rHEvt.GetMousePosPixel(), aScreenRect, aHelpText);
1202 : }
1203 0 : else if (Help::IsQuickHelpEnabled())
1204 : {
1205 0 : bReturn = Help::ShowQuickHelp( (Window*)mpWindow, aScreenRect, aHelpText);
1206 : }
1207 0 : }
1208 : }
1209 :
1210 0 : if (!bReturn)
1211 : {
1212 0 : bReturn = FuConstruct::RequestHelp(rHEvt);
1213 : }
1214 :
1215 0 : return(bReturn);
1216 : }
1217 :
1218 0 : void FuText::ReceiveRequest(SfxRequest& rReq)
1219 : {
1220 0 : nSlotId = rReq.GetSlot();
1221 :
1222 : // then we call the base class (besides others, nSlotId is NOT set there)
1223 0 : FuPoor::ReceiveRequest(rReq);
1224 :
1225 0 : if (nSlotId == SID_TEXTEDIT || mpViewShell->GetFrameView()->IsQuickEdit() || SID_ATTR_CHAR == nSlotId)
1226 : {
1227 0 : MouseEvent aMEvt(mpWindow->GetPointerPosPixel());
1228 :
1229 0 : mxTextObj.reset(0);
1230 :
1231 0 : if (nSlotId == SID_TEXTEDIT)
1232 : {
1233 : // are we currently editing?
1234 0 : if(!bTestText)
1235 0 : mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetTextEditObject() ) );
1236 :
1237 0 : if (!mxTextObj.is())
1238 : {
1239 : // Try to select an object
1240 0 : SdrPageView* pPV = mpView->GetSdrPageView();
1241 0 : SdrViewEvent aVEvt;
1242 0 : mpView->PickAnything(aMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
1243 0 : mpView->MarkObj(aVEvt.pRootObj, pPV);
1244 :
1245 0 : if (aVEvt.pObj && aVEvt.pObj->ISA(SdrTextObj))
1246 : {
1247 0 : mxTextObj.reset( static_cast< SdrTextObj* >( aVEvt.pObj ) );
1248 0 : }
1249 : }
1250 : }
1251 0 : else if (mpView->AreObjectsMarked())
1252 : {
1253 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
1254 :
1255 0 : if (rMarkList.GetMarkCount() == 1)
1256 : {
1257 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
1258 :
1259 0 : if (pObj->ISA(SdrTextObj))
1260 : {
1261 0 : mxTextObj.reset( static_cast< SdrTextObj* >( pObj ) );
1262 : }
1263 : }
1264 : }
1265 :
1266 0 : sal_Bool bQuickDrag = sal_True;
1267 :
1268 0 : const SfxItemSet* pArgs = rReq.GetArgs();
1269 :
1270 0 : if (pArgs
1271 :
1272 : // test for type before using
1273 0 : && SID_TEXTEDIT == nSlotId
1274 0 : && SFX_ITEM_SET == pArgs->GetItemState(SID_TEXTEDIT)
1275 :
1276 0 : && (sal_uInt16) ((SfxUInt16Item&) pArgs->Get(SID_TEXTEDIT)).GetValue() == 2)
1277 : {
1278 : // selection wit double click -> do not allow QuickDrag
1279 0 : bQuickDrag = sal_False;
1280 : }
1281 :
1282 0 : SetInEditMode(aMEvt, bQuickDrag);
1283 : }
1284 0 : }
1285 :
1286 0 : void FuText::DoubleClick(const MouseEvent& )
1287 : {
1288 : // Nothing to do
1289 0 : }
1290 :
1291 : /** Removed the insertion of default text and putting a new text
1292 : object directly into edit mode.
1293 : */
1294 0 : SdrObject* FuText::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
1295 : {
1296 :
1297 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
1298 0 : mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
1299 0 : 0L, mpDoc);
1300 :
1301 0 : if(pObj)
1302 : {
1303 0 : if(pObj->ISA(SdrTextObj))
1304 : {
1305 0 : SdrTextObj* pText = (SdrTextObj*)pObj;
1306 0 : pText->SetLogicRect(rRectangle);
1307 :
1308 0 : sal_Bool bVertical = (SID_ATTR_CHAR_VERTICAL == nID || SID_TEXT_FITTOSIZE_VERTICAL == nID);
1309 0 : pText->SetVerticalWriting(bVertical);
1310 :
1311 0 : ImpSetAttributesForNewTextObject(pText);
1312 :
1313 0 : if (nSlotId == SID_TEXT_FITTOSIZE)
1314 : {
1315 0 : ImpSetAttributesFitToSize(pText);
1316 : }
1317 0 : else if ( nSlotId == SID_TEXT_FITTOSIZE_VERTICAL )
1318 : {
1319 0 : ImpSetAttributesFitToSizeVertical(pText);
1320 : }
1321 : else
1322 : {
1323 0 : ImpSetAttributesFitCommon(pText);
1324 : }
1325 :
1326 : // Put text object into edit mode.
1327 0 : SdrPageView* pPV = mpView->GetSdrPageView();
1328 0 : mpView->SdrBeginTextEdit(pText, pPV);
1329 : }
1330 : else
1331 : {
1332 : OSL_FAIL("Object is NO text object");
1333 : }
1334 : }
1335 :
1336 0 : return pObj;
1337 : }
1338 :
1339 :
1340 :
1341 :
1342 : /** is called when the currenct function should be aborted. <p>
1343 : This is used when a function gets a KEY_ESCAPE but can also
1344 : be called directly.
1345 :
1346 : @returns true if a active function was aborted
1347 : */
1348 0 : bool FuText::cancel()
1349 : {
1350 0 : if ( mpView->IsTextEdit() )
1351 : {
1352 0 : if(mpView->SdrEndTextEdit() == SDRENDTEXTEDIT_DELETED)
1353 0 : mxTextObj.reset(0);
1354 :
1355 0 : mpView->SetCurrentObj(OBJ_TEXT);
1356 0 : mpView->SetEditMode(SDREDITMODE_EDIT);
1357 0 : return true;
1358 : }
1359 : else
1360 : {
1361 0 : return false;
1362 : }
1363 : }
1364 :
1365 0 : void FuText::ChangeFontSize( bool bGrow, OutlinerView* pOLV, const FontList* pFontList, ::sd::View* pView )
1366 : {
1367 0 : if( !pFontList || !pView )
1368 0 : return;
1369 :
1370 0 : if( pOLV )
1371 : {
1372 0 : pOLV->GetEditView().ChangeFontSize( bGrow, pFontList );
1373 : }
1374 : else
1375 : {
1376 :
1377 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
1378 0 : for( sal_uInt32 nMark = 0; nMark < rMarkList.GetMarkCount(); nMark++ )
1379 : {
1380 0 : SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( rMarkList.GetMark(nMark)->GetMarkedSdrObj() );
1381 0 : if( pTextObj )
1382 : {
1383 0 : for( sal_Int32 nText = 0; nText < pTextObj->getTextCount(); nText++ )
1384 : {
1385 0 : pTextObj->setActiveText( nText );
1386 :
1387 : // Put text object into edit mode.
1388 0 : SdrPageView* pPV = pView->GetSdrPageView();
1389 0 : pView->SdrBeginTextEdit(pTextObj, pPV);
1390 :
1391 0 : pOLV = pView->GetTextEditOutlinerView();
1392 0 : if( pOLV )
1393 : {
1394 0 : EditEngine* pEditEngine = pOLV->GetEditView().GetEditEngine();
1395 0 : if( pEditEngine )
1396 : {
1397 0 : ESelection aSel;
1398 0 : aSel.nEndPara = pEditEngine->GetParagraphCount()-1;
1399 0 : aSel.nEndPos = pEditEngine->GetTextLen(aSel.nEndPara);
1400 0 : pOLV->SetSelection(aSel);
1401 : }
1402 :
1403 0 : ChangeFontSize( bGrow, pOLV, pFontList, pView );
1404 : }
1405 :
1406 0 : pView->SdrEndTextEdit();
1407 : }
1408 :
1409 0 : SfxItemSet aShapeSet( pTextObj->GetMergedItemSet() );
1410 0 : if( EditView::ChangeFontSize( bGrow, aShapeSet, pFontList ) )
1411 : {
1412 0 : pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT ) );
1413 0 : pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT_CJK ) );
1414 0 : pTextObj->SetObjectItemNoBroadcast( aShapeSet.Get( EE_CHAR_FONTHEIGHT_CTL ) );
1415 0 : }
1416 : }
1417 : }
1418 : }
1419 : }
1420 :
1421 33 : } // end of namespace sd
1422 :
1423 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|