xref: /AOO41X/main/sc/source/ui/drawfunc/drtxtob2.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "scitems.hxx"
32*cdf0e10cSrcweir #include <editeng/adjitem.hxx>
33*cdf0e10cSrcweir #include <svx/drawitem.hxx>
34*cdf0e10cSrcweir #include <svx/fontwork.hxx>
35*cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
36*cdf0e10cSrcweir #include <editeng/outlobj.hxx>
37*cdf0e10cSrcweir #include <svx/svdocapt.hxx>
38*cdf0e10cSrcweir #include <svx/xtextit.hxx>
39*cdf0e10cSrcweir #include <editeng/writingmodeitem.hxx>
40*cdf0e10cSrcweir #include <sfx2/bindings.hxx>
41*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
42*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
43*cdf0e10cSrcweir #include <sfx2/request.hxx>
44*cdf0e10cSrcweir #include <sot/formats.hxx>
45*cdf0e10cSrcweir #include <svl/whiter.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include "sc.hrc"
48*cdf0e10cSrcweir #include "drtxtob.hxx"
49*cdf0e10cSrcweir #include "viewdata.hxx"
50*cdf0e10cSrcweir #include "drawview.hxx"
51*cdf0e10cSrcweir #include "tabvwsh.hxx"
52*cdf0e10cSrcweir #include "impex.hxx"
53*cdf0e10cSrcweir #include "docsh.hxx"
54*cdf0e10cSrcweir #include "transobj.hxx"
55*cdf0e10cSrcweir #include "drwtrans.hxx"
56*cdf0e10cSrcweir #include "drwlayer.hxx"
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //------------------------------------------------------------------------
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir sal_uInt16 ScGetFontWorkId()
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir 	return SvxFontWorkChildWindow::GetChildWindowId();
63*cdf0e10cSrcweir }
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir sal_Bool ScDrawTextObjectBar::IsNoteEdit()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     return ScDrawLayer::IsNoteCaption( pViewData->GetView()->GetSdrView()->GetTextEditObject() );
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir //	wenn kein Text editiert wird, Funktionen wie in drawsh
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void __EXPORT ScDrawTextObjectBar::ExecuteGlobal( SfxRequest &rReq )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	ScTabView*	 pTabView  = pViewData->GetView();
75*cdf0e10cSrcweir 	ScDrawView*  pView	   = pTabView->GetScDrawView();
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	sal_uInt16 nSlot = rReq.GetSlot();
78*cdf0e10cSrcweir 	switch ( nSlot )
79*cdf0e10cSrcweir 	{
80*cdf0e10cSrcweir 		case SID_COPY:
81*cdf0e10cSrcweir 			pView->DoCopy();
82*cdf0e10cSrcweir 			break;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 		case SID_CUT:
85*cdf0e10cSrcweir 			pView->DoCut();
86*cdf0e10cSrcweir             pViewData->GetViewShell()->UpdateDrawShell();
87*cdf0e10cSrcweir 			break;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 		case SID_PASTE:
90*cdf0e10cSrcweir         case SID_PASTE_SPECIAL:
91*cdf0e10cSrcweir 		case SID_CLIPBOARD_FORMAT_ITEMS:
92*cdf0e10cSrcweir 		case SID_HYPERLINK_SETLINK:
93*cdf0e10cSrcweir 			{
94*cdf0e10cSrcweir 				//	cell methods are at cell shell, which is not available if
95*cdf0e10cSrcweir 				//	ScDrawTextObjectBar is active
96*cdf0e10cSrcweir 				//!	move paste etc. to view shell?
97*cdf0e10cSrcweir 			}
98*cdf0e10cSrcweir 			break;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 		case SID_SELECTALL:
101*cdf0e10cSrcweir 			pView->MarkAll();
102*cdf0e10cSrcweir 			break;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 		case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
105*cdf0e10cSrcweir 		case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
106*cdf0e10cSrcweir 			{
107*cdf0e10cSrcweir 				SfxItemSet aAttr( pView->GetModel()->GetItemPool(), SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 0 );
108*cdf0e10cSrcweir                 aAttr.Put( SvxWritingModeItem(
109*cdf0e10cSrcweir                     nSlot == SID_TEXTDIRECTION_LEFT_TO_RIGHT ?
110*cdf0e10cSrcweir                         com::sun::star::text::WritingMode_LR_TB : com::sun::star::text::WritingMode_TB_RL,
111*cdf0e10cSrcweir                         SDRATTR_TEXTDIRECTION ) );
112*cdf0e10cSrcweir 				pView->SetAttributes( aAttr );
113*cdf0e10cSrcweir 				pViewData->GetScDrawView()->InvalidateDrawTextAttrs();	// Bidi slots may be disabled
114*cdf0e10cSrcweir 				rReq.Done( aAttr );
115*cdf0e10cSrcweir 			}
116*cdf0e10cSrcweir 			break;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 		case SID_ENABLE_HYPHENATION:
119*cdf0e10cSrcweir 			{
120*cdf0e10cSrcweir 				SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_ENABLE_HYPHENATION, sal_False);
121*cdf0e10cSrcweir 				if( pItem )
122*cdf0e10cSrcweir 				{
123*cdf0e10cSrcweir 					SfxItemSet aSet( GetPool(), EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
124*cdf0e10cSrcweir 					sal_Bool bValue = ( (const SfxBoolItem*) pItem)->GetValue();
125*cdf0e10cSrcweir 					aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, bValue ) );
126*cdf0e10cSrcweir 					pView->SetAttributes( aSet );
127*cdf0e10cSrcweir 				}
128*cdf0e10cSrcweir 				rReq.Done();
129*cdf0e10cSrcweir 			}
130*cdf0e10cSrcweir 			break;
131*cdf0e10cSrcweir 	}
132*cdf0e10cSrcweir }
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir void ScDrawTextObjectBar::GetGlobalClipState( SfxItemSet& rSet )
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir 	//	cell methods are at cell shell, which is not available if
137*cdf0e10cSrcweir 	//	ScDrawTextObjectBar is active -> disable everything
138*cdf0e10cSrcweir 	//!	move paste etc. to view shell?
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
141*cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
142*cdf0e10cSrcweir 	while (nWhich)
143*cdf0e10cSrcweir 	{
144*cdf0e10cSrcweir 		rSet.DisableItem( nWhich );
145*cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
146*cdf0e10cSrcweir 	}
147*cdf0e10cSrcweir }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir void __EXPORT ScDrawTextObjectBar::ExecuteExtra( SfxRequest &rReq )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir 	ScTabView*	 pTabView  = pViewData->GetView();
152*cdf0e10cSrcweir 	ScDrawView*  pView	   = pTabView->GetScDrawView();
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 	sal_uInt16 nSlot = rReq.GetSlot();
155*cdf0e10cSrcweir 	switch ( nSlot )
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		case SID_FONTWORK:
158*cdf0e10cSrcweir 			{
159*cdf0e10cSrcweir 				sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
160*cdf0e10cSrcweir 				SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 				if ( rReq.GetArgs() )
163*cdf0e10cSrcweir 					pViewFrm->SetChildWindow( nId,
164*cdf0e10cSrcweir 											   ((const SfxBoolItem&)
165*cdf0e10cSrcweir 												(rReq.GetArgs()->Get(SID_FONTWORK))).
166*cdf0e10cSrcweir 													GetValue() );
167*cdf0e10cSrcweir 				else
168*cdf0e10cSrcweir 					pViewFrm->ToggleChildWindow( nId );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 				pViewFrm->GetBindings().Invalidate( SID_FONTWORK );
171*cdf0e10cSrcweir 				rReq.Done();
172*cdf0e10cSrcweir 			}
173*cdf0e10cSrcweir 			break;
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir         case SID_ATTR_PARA_LEFT_TO_RIGHT:
176*cdf0e10cSrcweir         case SID_ATTR_PARA_RIGHT_TO_LEFT:
177*cdf0e10cSrcweir             {
178*cdf0e10cSrcweir                 SfxItemSet aAttr( pView->GetModel()->GetItemPool(),
179*cdf0e10cSrcweir                                     EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
180*cdf0e10cSrcweir                                     EE_PARA_JUST, EE_PARA_JUST,
181*cdf0e10cSrcweir                                     0 );
182*cdf0e10cSrcweir                 sal_Bool bLeft = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT );
183*cdf0e10cSrcweir                 aAttr.Put( SvxFrameDirectionItem(
184*cdf0e10cSrcweir                                 bLeft ? FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP,
185*cdf0e10cSrcweir                                 EE_PARA_WRITINGDIR ) );
186*cdf0e10cSrcweir                 aAttr.Put( SvxAdjustItem(
187*cdf0e10cSrcweir                                 bLeft ? SVX_ADJUST_LEFT : SVX_ADJUST_RIGHT,
188*cdf0e10cSrcweir                                 EE_PARA_JUST ) );
189*cdf0e10cSrcweir                 pView->SetAttributes( aAttr );
190*cdf0e10cSrcweir 				pViewData->GetScDrawView()->InvalidateDrawTextAttrs();
191*cdf0e10cSrcweir 				rReq.Done();		//! Done(aAttr) ?
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir             }
194*cdf0e10cSrcweir             break;
195*cdf0e10cSrcweir 	}
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir void ScDrawTextObjectBar::ExecFormText(SfxRequest& rReq)
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir 	ScTabView*			pTabView	= pViewData->GetView();
201*cdf0e10cSrcweir 	ScDrawView* 		pDrView 	= pTabView->GetScDrawView();
202*cdf0e10cSrcweir 	const SdrMarkList&	rMarkList	= pDrView->GetMarkedObjectList();
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
205*cdf0e10cSrcweir 	{
206*cdf0e10cSrcweir 		const SfxItemSet& rSet = *rReq.GetArgs();
207*cdf0e10cSrcweir 		const SfxPoolItem* pItem;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		if ( pDrView->IsTextEdit() )
210*cdf0e10cSrcweir 			pDrView->ScEndTextEdit();
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 		if (	SFX_ITEM_SET ==
213*cdf0e10cSrcweir 				rSet.GetItemState(XATTR_FORMTXTSTDFORM, sal_True, &pItem)
214*cdf0e10cSrcweir 			 && XFTFORM_NONE !=
215*cdf0e10cSrcweir 				((const XFormTextStdFormItem*) pItem)->GetValue() )
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 			sal_uInt16 nId				= SvxFontWorkChildWindow::GetChildWindowId();
219*cdf0e10cSrcweir 			SfxViewFrame* pViewFrm	= pViewData->GetViewShell()->GetViewFrame();
220*cdf0e10cSrcweir 			SvxFontWorkDialog* pDlg	= (SvxFontWorkDialog*)
221*cdf0e10cSrcweir 									   (pViewFrm->
222*cdf0e10cSrcweir 											GetChildWindow(nId)->GetWindow());
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 			pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
225*cdf0e10cSrcweir 									rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
226*cdf0e10cSrcweir 								   ((const XFormTextStdFormItem*) pItem)->
227*cdf0e10cSrcweir 								   GetValue());
228*cdf0e10cSrcweir 		}
229*cdf0e10cSrcweir 		else
230*cdf0e10cSrcweir 			pDrView->SetAttributes(rSet);
231*cdf0e10cSrcweir 	}
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void ScDrawTextObjectBar::GetFormTextState(SfxItemSet& rSet)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	const SdrObject*	pObj		= NULL;
237*cdf0e10cSrcweir 	SvxFontWorkDialog*	pDlg		= NULL;
238*cdf0e10cSrcweir 	ScDrawView* 		pDrView 	= pViewData->GetView()->GetScDrawView();
239*cdf0e10cSrcweir 	const SdrMarkList&	rMarkList	= pDrView->GetMarkedObjectList();
240*cdf0e10cSrcweir 	sal_uInt16				nId = SvxFontWorkChildWindow::GetChildWindowId();
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
243*cdf0e10cSrcweir 	if ( pViewFrm->HasChildWindow(nId) )
244*cdf0e10cSrcweir 		pDlg = (SvxFontWorkDialog*)(pViewFrm->GetChildWindow(nId)->GetWindow());
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	if ( rMarkList.GetMarkCount() == 1 )
247*cdf0e10cSrcweir 		pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	if ( pObj == NULL || !pObj->ISA(SdrTextObj) ||
250*cdf0e10cSrcweir 		!((SdrTextObj*) pObj)->HasText() )
251*cdf0e10cSrcweir 	{
252*cdf0e10cSrcweir 		if ( pDlg )
253*cdf0e10cSrcweir 			pDlg->SetActive(sal_False);
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSTYLE);
256*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTADJUST);
257*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTDISTANCE);
258*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSTART);
259*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTMIRROR);
260*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSTDFORM);
261*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
262*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTOUTLINE);
263*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSHADOW);
264*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
265*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
266*cdf0e10cSrcweir 		rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir 	else
269*cdf0e10cSrcweir 	{
270*cdf0e10cSrcweir 		if ( pDlg )
271*cdf0e10cSrcweir 		{
272*cdf0e10cSrcweir 			SfxObjectShell* pDocSh = SfxObjectShell::Current();
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 			if ( pDocSh )
275*cdf0e10cSrcweir 			{
276*cdf0e10cSrcweir                 const SfxPoolItem*  pItem = pDocSh->GetItem( SID_COLOR_TABLE );
277*cdf0e10cSrcweir 				XColorTable*		pColorTable = NULL;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 				if ( pItem )
280*cdf0e10cSrcweir 					pColorTable = ((SvxColorTableItem*)pItem)->GetColorTable();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 				pDlg->SetActive();
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 				if ( pColorTable )
285*cdf0e10cSrcweir 					pDlg->SetColorTable( pColorTable );
286*cdf0e10cSrcweir 				else
287*cdf0e10cSrcweir 					{ DBG_ERROR( "ColorList not found :-/" ); }
288*cdf0e10cSrcweir 			}
289*cdf0e10cSrcweir 		}
290*cdf0e10cSrcweir 		SfxItemSet aViewAttr(pDrView->GetModel()->GetItemPool());
291*cdf0e10cSrcweir 		pDrView->GetAttributes(aViewAttr);
292*cdf0e10cSrcweir 		rSet.Set(aViewAttr);
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299