Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <sfx2/request.hxx>
21 : #include <sfx2/bindings.hxx>
22 : #include <sfx2/dispatch.hxx>
23 :
24 : #include <svl/itemiter.hxx>
25 :
26 : #include <svx/globl3d.hxx>
27 : #include <svx/svxids.hrc>
28 : #include <svx/svdotable.hxx>
29 : #include <editeng/outliner.hxx>
30 : #include <editeng/eeitem.hxx>
31 : #include <editeng/editeng.hxx>
32 :
33 : #include "sdmod.hxx"
34 :
35 : #include "fuformatpaintbrush.hxx"
36 : #include "drawview.hxx"
37 : #include "DrawDocShell.hxx"
38 : #include "DrawViewShell.hxx"
39 : #include "FrameView.hxx"
40 : #include "drawdoc.hxx"
41 : #include "Outliner.hxx"
42 : #include "ViewShellBase.hxx"
43 :
44 : #include "Window.hxx"
45 :
46 : namespace sd {
47 :
48 0 : TYPEINIT1( FuFormatPaintBrush, FuText );
49 :
50 0 : FuFormatPaintBrush::FuFormatPaintBrush( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
51 : : FuText(pViewSh, pWin, pView, pDoc, rReq)
52 : , mbPermanent( false )
53 0 : , mbOldIsQuickTextEditMode( true )
54 : {
55 0 : }
56 :
57 0 : rtl::Reference<FuPoor> FuFormatPaintBrush::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq )
58 : {
59 0 : rtl::Reference<FuPoor> xFunc( new FuFormatPaintBrush( pViewSh, pWin, pView, pDoc, rReq ) );
60 0 : xFunc->DoExecute( rReq );
61 0 : return xFunc;
62 : }
63 :
64 0 : void FuFormatPaintBrush::DoExecute( SfxRequest& rReq )
65 : {
66 0 : const SfxItemSet *pArgs = rReq.GetArgs();
67 0 : if( pArgs && pArgs->Count() >= 1 )
68 : {
69 0 : mbPermanent = static_cast<bool>(static_cast<const SfxBoolItem &>(pArgs->Get(SID_FORMATPAINTBRUSH)).GetValue());
70 : }
71 :
72 0 : if( mpView )
73 : {
74 0 : mpView->TakeFormatPaintBrush( mxItemSet );
75 : }
76 0 : }
77 :
78 0 : void FuFormatPaintBrush::implcancel()
79 : {
80 0 : if( mpViewShell && mpViewShell->GetViewFrame() )
81 : {
82 0 : SfxViewFrame* pViewFrame = mpViewShell->GetViewFrame();
83 0 : pViewFrame->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
84 0 : pViewFrame->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON);
85 : }
86 0 : }
87 :
88 0 : static void unmarkimpl( SdrView* pView )
89 : {
90 0 : pView->SdrEndTextEdit();
91 0 : pView->UnMarkAll();
92 0 : }
93 :
94 0 : bool FuFormatPaintBrush::MouseButtonDown(const MouseEvent& rMEvt)
95 : {
96 0 : if(mpView&&mpWindow)
97 : {
98 0 : SdrViewEvent aVEvt;
99 0 : SdrHitKind eHit = mpView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
100 :
101 0 : if( (eHit == SDRHIT_TEXTEDIT) || (eHit == SDRHIT_TEXTEDITOBJ && ( mpViewShell->GetFrameView()->IsQuickEdit() || dynamic_cast< sdr::table::SdrTableObj* >( aVEvt.pObj ) != NULL ) ))
102 : {
103 0 : SdrObject* pPickObj=0;
104 0 : SdrPageView* pPV=0;
105 0 : sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
106 0 : mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pPickObj, pPV, SdrSearchOptions::PICKMARKABLE);
107 :
108 0 : if( (pPickObj != 0) && !pPickObj->IsEmptyPresObj() )
109 : {
110 : // if we text hit another shape than the one currently selected, unselect the old one now
111 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
112 0 : if( rMarkList.GetMarkCount() > 0 )
113 : {
114 0 : if( rMarkList.GetMarkCount() == 1 )
115 : {
116 0 : if( rMarkList.GetMark(0)->GetMarkedSdrObj() != pPickObj )
117 : {
118 :
119 : // if current selected shape is not that of the hit text edit, deselect it
120 0 : unmarkimpl( mpView );
121 : }
122 : }
123 : else
124 : {
125 : // more than one shape selected, deselect all of them
126 0 : unmarkimpl( mpView );
127 : }
128 : }
129 0 : MouseEvent aMEvt( rMEvt.GetPosPixel(), rMEvt.GetClicks(), rMEvt.GetMode(), rMEvt.GetButtons(), 0 );
130 0 : return FuText::MouseButtonDown(aMEvt);
131 : }
132 :
133 0 : if( aVEvt.pObj == 0 )
134 0 : aVEvt.pObj = pPickObj;
135 : }
136 :
137 0 : unmarkimpl( mpView );
138 :
139 0 : if( aVEvt.pObj )
140 : {
141 0 : sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
142 0 : bool bToggle = false;
143 0 : mpView->MarkObj(mpWindow->PixelToLogic( rMEvt.GetPosPixel() ), nHitLog, bToggle, false);
144 0 : return true;
145 0 : }
146 : }
147 0 : return false;
148 : }
149 :
150 0 : bool FuFormatPaintBrush::MouseMove(const MouseEvent& rMEvt)
151 : {
152 0 : bool bReturn = false;
153 0 : if( mpWindow && mpView )
154 : {
155 0 : if ( mpView->IsTextEdit() )
156 : {
157 0 : bReturn = FuText::MouseMove( rMEvt );
158 0 : mpWindow->SetPointer(Pointer(PointerStyle::Fill));
159 : }
160 : else
161 : {
162 0 : sal_uInt16 nHitLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(HITPIX,0)).Width() );
163 0 : SdrObject* pObj=0;
164 0 : SdrPageView* pPV=0;
165 0 : bool bOverMarkableObject = mpView->PickObj( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ),nHitLog, pObj, pPV, SdrSearchOptions::PICKMARKABLE);
166 :
167 0 : if(bOverMarkableObject && HasContentForThisType(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
168 0 : mpWindow->SetPointer(Pointer(PointerStyle::Fill));
169 : else
170 0 : mpWindow->SetPointer(Pointer(PointerStyle::Arrow));
171 : }
172 : }
173 0 : return bReturn;
174 : }
175 :
176 0 : bool FuFormatPaintBrush::MouseButtonUp(const MouseEvent& rMEvt)
177 : {
178 0 : if( mxItemSet.get() && mpView && mpView->AreObjectsMarked() )
179 : {
180 0 : bool bNoCharacterFormats = false;
181 0 : bool bNoParagraphFormats = false;
182 : {
183 0 : if( (rMEvt.GetModifier()&KEY_MOD1) && (rMEvt.GetModifier()&KEY_SHIFT) )
184 0 : bNoCharacterFormats = true;
185 0 : else if( rMEvt.GetModifier() & KEY_MOD1 )
186 0 : bNoParagraphFormats = true;
187 : }
188 :
189 0 : OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
190 0 : if( pOLV )
191 0 : pOLV->MouseButtonUp(rMEvt);
192 :
193 0 : Paste( bNoCharacterFormats, bNoParagraphFormats );
194 0 : if(mpViewShell)
195 0 : mpViewShell->GetViewFrame()->GetBindings().Invalidate(SID_FORMATPAINTBRUSH);
196 :
197 0 : if( mbPermanent )
198 0 : return true;
199 : }
200 :
201 0 : implcancel();
202 0 : return true;
203 : }
204 :
205 0 : bool FuFormatPaintBrush::KeyInput(const KeyEvent& rKEvt)
206 : {
207 0 : if( (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) && mpViewShell )
208 : {
209 0 : implcancel();
210 0 : return true;
211 : }
212 0 : return FuPoor::KeyInput(rKEvt);
213 : }
214 :
215 0 : void FuFormatPaintBrush::Activate()
216 : {
217 0 : mbOldIsQuickTextEditMode = mpViewShell->GetFrameView()->IsQuickEdit();
218 0 : if( !mbOldIsQuickTextEditMode )
219 : {
220 0 : mpViewShell->GetFrameView()->SetQuickEdit(true);
221 0 : mpView->SetQuickTextEditMode(true);
222 : }
223 0 : }
224 :
225 0 : void FuFormatPaintBrush::Deactivate()
226 : {
227 0 : if( !mbOldIsQuickTextEditMode )
228 : {
229 0 : mpViewShell->GetFrameView()->SetQuickEdit(false);
230 0 : mpView->SetQuickTextEditMode(false);
231 : }
232 0 : }
233 :
234 0 : bool FuFormatPaintBrush::HasContentForThisType( sal_uInt32 nObjectInventor, sal_uInt16 nObjectIdentifier ) const
235 : {
236 0 : if( mxItemSet.get() == 0 )
237 0 : return false;
238 0 : if( !mpView || (!SdrObjEditView::SupportsFormatPaintbrush( nObjectInventor, nObjectIdentifier) ) )
239 0 : return false;
240 0 : return true;
241 : }
242 :
243 0 : void FuFormatPaintBrush::Paste( bool bNoCharacterFormats, bool bNoParagraphFormats )
244 : {
245 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
246 0 : if( mxItemSet.get() && ( rMarkList.GetMarkCount() == 1 ) )
247 : {
248 0 : SdrObject* pObj( NULL );
249 0 : bool bUndo = mpDoc->IsUndoEnabled();
250 :
251 0 : if( bUndo && !mpView->GetTextEditOutlinerView() )
252 0 : pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
253 :
254 : // n685123: ApplyFormatPaintBrush itself would store undo information
255 : // except in a few cases (?)
256 0 : if( pObj )
257 : {
258 0 : OUString sLabel( mpViewShell->GetViewShellBase().RetrieveLabelFromCommand(".uno:FormatPaintbrush" ) );
259 0 : mpDoc->BegUndo( sLabel );
260 0 : mpDoc->AddUndo( mpDoc->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, false, true ) );
261 : }
262 :
263 0 : mpView->ApplyFormatPaintBrush( *mxItemSet.get(), bNoCharacterFormats, bNoParagraphFormats );
264 :
265 0 : if( pObj )
266 : {
267 0 : mpDoc->EndUndo();
268 : }
269 : }
270 0 : }
271 :
272 4175 : /* static */ void FuFormatPaintBrush::GetMenuState( DrawViewShell& rDrawViewShell, SfxItemSet &rSet )
273 : {
274 4175 : const SdrMarkList& rMarkList = rDrawViewShell.GetDrawView()->GetMarkedObjectList();
275 :
276 4175 : if( rMarkList.GetMarkCount() == 1 )
277 : {
278 10 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
279 10 : if( pObj && SdrObjEditView::SupportsFormatPaintbrush(pObj->GetObjInventor(),pObj->GetObjIdentifier()) )
280 4185 : return;
281 : }
282 4165 : rSet.DisableItem( SID_FORMATPAINTBRUSH );
283 : }
284 :
285 66 : } // end of namespace sd
286 :
287 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|