xref: /aoo4110/main/sc/source/ui/drawfunc/drtxtob2.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include "scitems.hxx"
28 #include <editeng/adjitem.hxx>
29 #include <svx/drawitem.hxx>
30 #include <svx/fontwork.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <editeng/outlobj.hxx>
33 #include <svx/svdocapt.hxx>
34 #include <svx/xtextit.hxx>
35 #include <editeng/writingmodeitem.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/request.hxx>
40 #include <sot/formats.hxx>
41 #include <svl/whiter.hxx>
42 #include <svx/svdoashp.hxx>
43 #include "sc.hrc"
44 #include "drtxtob.hxx"
45 #include "viewdata.hxx"
46 #include "drawview.hxx"
47 #include "tabvwsh.hxx"
48 #include "impex.hxx"
49 #include "docsh.hxx"
50 #include "transobj.hxx"
51 #include "drwtrans.hxx"
52 #include "drwlayer.hxx"
53 
54 //------------------------------------------------------------------------
55 
ScGetFontWorkId()56 sal_uInt16 ScGetFontWorkId()
57 {
58 	return SvxFontWorkChildWindow::GetChildWindowId();
59 }
60 
IsNoteEdit()61 sal_Bool ScDrawTextObjectBar::IsNoteEdit()
62 {
63     return ScDrawLayer::IsNoteCaption( pViewData->GetView()->GetSdrView()->GetTextEditObject() );
64 }
65 
66 //	wenn kein Text editiert wird, Funktionen wie in drawsh
67 
ExecuteGlobal(SfxRequest & rReq)68 void __EXPORT ScDrawTextObjectBar::ExecuteGlobal( SfxRequest &rReq )
69 {
70 	ScTabView*	 pTabView  = pViewData->GetView();
71 	ScDrawView*  pView	   = pTabView->GetScDrawView();
72 
73 	sal_uInt16 nSlot = rReq.GetSlot();
74 	switch ( nSlot )
75 	{
76 		case SID_COPY:
77 			pView->DoCopy();
78 			break;
79 
80 		case SID_CUT:
81 			pView->DoCut();
82             pViewData->GetViewShell()->UpdateDrawShell();
83 			break;
84 
85 		case SID_PASTE:
86         case SID_PASTE_SPECIAL:
87 		case SID_CLIPBOARD_FORMAT_ITEMS:
88 		case SID_HYPERLINK_SETLINK:
89 			{
90 				//	cell methods are at cell shell, which is not available if
91 				//	ScDrawTextObjectBar is active
92 				//!	move paste etc. to view shell?
93 			}
94 			break;
95 
96 		case SID_SELECTALL:
97 			pView->MarkAll();
98 			break;
99 
100 		case SID_TEXTDIRECTION_LEFT_TO_RIGHT:
101 		case SID_TEXTDIRECTION_TOP_TO_BOTTOM:
102 			{
103 				SfxItemSet aAttr( pView->GetModel()->GetItemPool(), SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION, 0 );
104                 aAttr.Put( SvxWritingModeItem(
105                     nSlot == SID_TEXTDIRECTION_LEFT_TO_RIGHT ?
106                         com::sun::star::text::WritingMode_LR_TB : com::sun::star::text::WritingMode_TB_RL,
107                         SDRATTR_TEXTDIRECTION ) );
108 				pView->SetAttributes( aAttr );
109 				pViewData->GetScDrawView()->InvalidateDrawTextAttrs();	// Bidi slots may be disabled
110 				rReq.Done( aAttr );
111 			}
112 			break;
113 
114 		case SID_ENABLE_HYPHENATION:
115 			{
116 				SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, SID_ENABLE_HYPHENATION, sal_False);
117 				if( pItem )
118 				{
119 					SfxItemSet aSet( GetPool(), EE_PARA_HYPHENATE, EE_PARA_HYPHENATE );
120 					sal_Bool bValue = ( (const SfxBoolItem*) pItem)->GetValue();
121 					aSet.Put( SfxBoolItem( EE_PARA_HYPHENATE, bValue ) );
122 					pView->SetAttributes( aSet );
123 				}
124 				rReq.Done();
125 			}
126 			break;
127 	}
128 }
129 
GetGlobalClipState(SfxItemSet & rSet)130 void ScDrawTextObjectBar::GetGlobalClipState( SfxItemSet& rSet )
131 {
132 	//	cell methods are at cell shell, which is not available if
133 	//	ScDrawTextObjectBar is active -> disable everything
134 	//!	move paste etc. to view shell?
135 
136 	SfxWhichIter aIter(rSet);
137 	sal_uInt16 nWhich = aIter.FirstWhich();
138 	while (nWhich)
139 	{
140 		rSet.DisableItem( nWhich );
141 		nWhich = aIter.NextWhich();
142 	}
143 }
144 
ExecuteExtra(SfxRequest & rReq)145 void __EXPORT ScDrawTextObjectBar::ExecuteExtra( SfxRequest &rReq )
146 {
147 	ScTabView*	 pTabView  = pViewData->GetView();
148 	ScDrawView*  pView	   = pTabView->GetScDrawView();
149 
150 	sal_uInt16 nSlot = rReq.GetSlot();
151 	switch ( nSlot )
152 	{
153 		case SID_FONTWORK:
154 			{
155 				sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
156 				SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
157 
158 				if ( rReq.GetArgs() )
159 					pViewFrm->SetChildWindow( nId,
160 											   ((const SfxBoolItem&)
161 												(rReq.GetArgs()->Get(SID_FONTWORK))).
162 													GetValue() );
163 				else
164 					pViewFrm->ToggleChildWindow( nId );
165 
166 				pViewFrm->GetBindings().Invalidate( SID_FONTWORK );
167 				rReq.Done();
168 			}
169 			break;
170 
171         case SID_ATTR_PARA_LEFT_TO_RIGHT:
172         case SID_ATTR_PARA_RIGHT_TO_LEFT:
173             {
174                 SfxItemSet aAttr( pView->GetModel()->GetItemPool(),
175                                     EE_PARA_WRITINGDIR, EE_PARA_WRITINGDIR,
176                                     EE_PARA_JUST, EE_PARA_JUST,
177                                     0 );
178                 sal_Bool bLeft = ( nSlot == SID_ATTR_PARA_LEFT_TO_RIGHT );
179                 aAttr.Put( SvxFrameDirectionItem(
180                                 bLeft ? FRMDIR_HORI_LEFT_TOP : FRMDIR_HORI_RIGHT_TOP,
181                                 EE_PARA_WRITINGDIR ) );
182                 aAttr.Put( SvxAdjustItem(
183                                 bLeft ? SVX_ADJUST_LEFT : SVX_ADJUST_RIGHT,
184                                 EE_PARA_JUST ) );
185                 pView->SetAttributes( aAttr );
186 				pViewData->GetScDrawView()->InvalidateDrawTextAttrs();
187 				rReq.Done();		//! Done(aAttr) ?
188 
189             }
190             break;
191 	}
192 }
193 
ExecFormText(SfxRequest & rReq)194 void ScDrawTextObjectBar::ExecFormText(SfxRequest& rReq)
195 {
196 	ScTabView*			pTabView	= pViewData->GetView();
197 	ScDrawView* 		pDrView 	= pTabView->GetScDrawView();
198 	const SdrMarkList&	rMarkList	= pDrView->GetMarkedObjectList();
199 
200 	if ( rMarkList.GetMarkCount() == 1 && rReq.GetArgs() )
201 	{
202 		const SfxItemSet& rSet = *rReq.GetArgs();
203 
204 		if ( pDrView->IsTextEdit() )
205 			pDrView->ScEndTextEdit();
206 
207 		pDrView->SetAttributes(rSet);
208 	}
209 }
210 
GetFormTextState(SfxItemSet & rSet)211 void ScDrawTextObjectBar::GetFormTextState(SfxItemSet& rSet)
212 {
213 	const SdrObject*	pObj		= NULL;
214 	SvxFontWorkDialog*	pDlg		= NULL;
215 	ScDrawView* 		pDrView 	= pViewData->GetView()->GetScDrawView();
216 	const SdrMarkList&	rMarkList	= pDrView->GetMarkedObjectList();
217 	sal_uInt16				nId = SvxFontWorkChildWindow::GetChildWindowId();
218 
219 	SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
220 	if ( pViewFrm->HasChildWindow(nId) )
221 		pDlg = (SvxFontWorkDialog*)(pViewFrm->GetChildWindow(nId)->GetWindow());
222 
223 	if ( rMarkList.GetMarkCount() == 1 )
224 		pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
225 
226     const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >(pObj);
227     const bool bDeactivate(
228         !pObj ||
229         !pTextObj ||
230         !pTextObj->HasText() ||
231         dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
232 
233     if(bDeactivate)
234 	{
235 		if ( pDlg )
236 			pDlg->SetActive(sal_False);
237 
238 		rSet.DisableItem(XATTR_FORMTXTSTYLE);
239 		rSet.DisableItem(XATTR_FORMTXTADJUST);
240 		rSet.DisableItem(XATTR_FORMTXTDISTANCE);
241 		rSet.DisableItem(XATTR_FORMTXTSTART);
242 		rSet.DisableItem(XATTR_FORMTXTMIRROR);
243 		rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
244 		rSet.DisableItem(XATTR_FORMTXTOUTLINE);
245 		rSet.DisableItem(XATTR_FORMTXTSHADOW);
246 		rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
247 		rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
248 		rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
249 	}
250 	else
251 	{
252 		if ( pDlg )
253 		{
254 			SfxObjectShell* pDocSh = SfxObjectShell::Current();
255 
256 			if ( pDocSh )
257 			{
258                 const SfxPoolItem*  pItem = pDocSh->GetItem( SID_COLOR_TABLE );
259 				XColorListSharedPtr aColorTable;
260 
261 				if ( pItem )
262 					aColorTable = static_cast< const SvxColorTableItem* >(pItem)->GetColorTable();
263 
264 				pDlg->SetActive();
265 
266 				if ( aColorTable )
267 					pDlg->SetColorTable( aColorTable );
268 				else
269 					{ DBG_ERROR( "ColorList not found :-/" ); }
270 			}
271 		}
272 		SfxItemSet aViewAttr(pDrView->GetModel()->GetItemPool());
273 		pDrView->GetAttributes(aViewAttr);
274 		rSet.Set(aViewAttr);
275 	}
276 }
277 
278 
279 
280 
281