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