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