xref: /AOO41X/main/sc/source/ui/drawfunc/drtxtob2.cxx (revision 54628ca40d27d15cc98fe861da7fff7e60c2f7d6)
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 
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 
56 sal_uInt16 ScGetFontWorkId()
57 {
58     return SvxFontWorkChildWindow::GetChildWindowId();
59 }
60 
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 
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 
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 
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 
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         const SfxPoolItem* pItem;
204 
205         if ( pDrView->IsTextEdit() )
206             pDrView->ScEndTextEdit();
207 
208         if (    SFX_ITEM_SET ==
209                 rSet.GetItemState(XATTR_FORMTXTSTDFORM, sal_True, &pItem)
210              && XFTFORM_NONE !=
211                 ((const XFormTextStdFormItem*) pItem)->GetValue() )
212         {
213 
214             sal_uInt16 nId              = SvxFontWorkChildWindow::GetChildWindowId();
215             SfxViewFrame* pViewFrm  = pViewData->GetViewShell()->GetViewFrame();
216             SvxFontWorkDialog* pDlg = (SvxFontWorkDialog*)
217                                        (pViewFrm->
218                                             GetChildWindow(nId)->GetWindow());
219 
220             pDlg->CreateStdFormObj(*pDrView, *pDrView->GetSdrPageView(),
221                                     rSet, *rMarkList.GetMark(0)->GetMarkedSdrObj(),
222                                    ((const XFormTextStdFormItem*) pItem)->
223                                    GetValue());
224         }
225         else
226             pDrView->SetAttributes(rSet);
227     }
228 }
229 
230 void ScDrawTextObjectBar::GetFormTextState(SfxItemSet& rSet)
231 {
232     const SdrObject*    pObj        = NULL;
233     SvxFontWorkDialog*  pDlg        = NULL;
234     ScDrawView*         pDrView     = pViewData->GetView()->GetScDrawView();
235     const SdrMarkList&  rMarkList   = pDrView->GetMarkedObjectList();
236     sal_uInt16              nId = SvxFontWorkChildWindow::GetChildWindowId();
237 
238     SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
239     if ( pViewFrm->HasChildWindow(nId) )
240         pDlg = (SvxFontWorkDialog*)(pViewFrm->GetChildWindow(nId)->GetWindow());
241 
242     if ( rMarkList.GetMarkCount() == 1 )
243         pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
244 
245     if ( pObj == NULL || !pObj->ISA(SdrTextObj) ||
246         !((SdrTextObj*) pObj)->HasText() )
247     {
248         if ( pDlg )
249             pDlg->SetActive(sal_False);
250 
251         rSet.DisableItem(XATTR_FORMTXTSTYLE);
252         rSet.DisableItem(XATTR_FORMTXTADJUST);
253         rSet.DisableItem(XATTR_FORMTXTDISTANCE);
254         rSet.DisableItem(XATTR_FORMTXTSTART);
255         rSet.DisableItem(XATTR_FORMTXTMIRROR);
256         rSet.DisableItem(XATTR_FORMTXTSTDFORM);
257         rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
258         rSet.DisableItem(XATTR_FORMTXTOUTLINE);
259         rSet.DisableItem(XATTR_FORMTXTSHADOW);
260         rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
261         rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
262         rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
263     }
264     else
265     {
266         if ( pDlg )
267         {
268             SfxObjectShell* pDocSh = SfxObjectShell::Current();
269 
270             if ( pDocSh )
271             {
272                 const SfxPoolItem*  pItem = pDocSh->GetItem( SID_COLOR_TABLE );
273                 XColorTable*        pColorTable = NULL;
274 
275                 if ( pItem )
276                     pColorTable = ((SvxColorTableItem*)pItem)->GetColorTable();
277 
278                 pDlg->SetActive();
279 
280                 if ( pColorTable )
281                     pDlg->SetColorTable( pColorTable );
282                 else
283                     { DBG_ERROR( "ColorList not found :-/" ); }
284             }
285         }
286         SfxItemSet aViewAttr(pDrView->GetModel()->GetItemPool());
287         pDrView->GetAttributes(aViewAttr);
288         rSet.Set(aViewAttr);
289     }
290 }
291 
292 
293 
294 
295