xref: /AOO41X/main/sc/source/ui/drawfunc/fuconstr.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
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 <editeng/outliner.hxx>
28 #include <editeng/outlobj.hxx>
29 #include <svx/svdotext.hxx>
30 #include <svx/svdouno.hxx>
31 #include <sfx2/dispatch.hxx>
32 
33 #include "fuconstr.hxx"
34 #include "fudraw.hxx"
35 #include "tabvwsh.hxx"
36 #include "futext.hxx"
37 #include "sc.hrc"
38 #include "drawview.hxx"
39 
40 //  Maximal erlaubte Mausbewegung um noch Drag&Drop zu starten
41 //! fusel,fuconstr,futext - zusammenfassen!
42 #define SC_MAXDRAGMOVE  3
43 
44 //------------------------------------------------------------------------
45 
46 /*************************************************************************
47 |*
48 |* Konstruktor
49 |*
50 \************************************************************************/
51 
FuConstruct(ScTabViewShell * pViewSh,Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,SfxRequest & rReq)52 FuConstruct::FuConstruct(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
53                    SdrModel* pDoc, SfxRequest& rReq) :
54     FuDraw(pViewSh, pWin, pViewP, pDoc, rReq)
55 {
56 }
57 
58 /*************************************************************************
59 |*
60 |* Destruktor
61 |*
62 \************************************************************************/
63 
~FuConstruct()64 FuConstruct::~FuConstruct()
65 {
66 }
67 
Command(const CommandEvent & rCEvt)68 sal_uInt8 FuConstruct::Command(const CommandEvent& rCEvt)
69 {
70     //  special code for non-VCL OS2/UNX removed
71 
72     return FuDraw::Command( rCEvt );
73 }
74 
75 /*************************************************************************
76 |*
77 |* MouseButtonDown-event
78 |*
79 \************************************************************************/
80 
MouseButtonDown(const MouseEvent & rMEvt)81 sal_Bool __EXPORT FuConstruct::MouseButtonDown(const MouseEvent& rMEvt)
82 {
83     // #95491# remember button state for creation of own MouseEvents
84     SetMouseButtonCode(rMEvt.GetButtons());
85 
86     sal_Bool bReturn = FuDraw::MouseButtonDown(rMEvt);
87 
88     if ( pView->IsAction() )
89     {
90         if ( rMEvt.IsRight() )
91             pView->BckAction();
92         return sal_True;
93     }
94 
95     aDragTimer.Start();
96 
97     aMDPos = pWindow->PixelToLogic( rMEvt.GetPosPixel() );
98 
99     if ( rMEvt.IsLeft() )
100     {
101         pWindow->CaptureMouse();
102 
103         SdrHdl* pHdl = pView->PickHandle(aMDPos);
104 
105         if ( pHdl != NULL || pView->IsMarkedHit(aMDPos) )
106         {
107             pView->BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, 1);
108             bReturn = sal_True;
109         }
110         else if ( pView->AreObjectsMarked() )
111         {
112             pView->UnmarkAll();
113             bReturn = sal_True;
114         }
115     }
116 
117     bIsInDragMode = sal_False;
118 
119     return bReturn;
120 }
121 
122 /*************************************************************************
123 |*
124 |* MouseMove-event
125 |*
126 \************************************************************************/
127 
MouseMove(const MouseEvent & rMEvt)128 sal_Bool __EXPORT FuConstruct::MouseMove(const MouseEvent& rMEvt)
129 {
130     FuDraw::MouseMove(rMEvt);
131 
132     if (aDragTimer.IsActive() )
133     {
134         Point aOldPixel = pWindow->LogicToPixel( aMDPos );
135         Point aNewPixel = rMEvt.GetPosPixel();
136         if ( Abs( aOldPixel.X() - aNewPixel.X() ) > SC_MAXDRAGMOVE ||
137              Abs( aOldPixel.Y() - aNewPixel.Y() ) > SC_MAXDRAGMOVE )
138             aDragTimer.Stop();
139     }
140 
141     Point aPix(rMEvt.GetPosPixel());
142     Point aPnt( pWindow->PixelToLogic(aPix) );
143 
144     if ( pView->IsAction() )
145     {
146         ForceScroll(aPix);
147         pView->MovAction(aPnt);
148     }
149     else
150     {
151         SdrHdl* pHdl=pView->PickHandle(aPnt);
152 
153         if ( pHdl != NULL )
154         {
155             pViewShell->SetActivePointer(pHdl->GetPointer());
156         }
157         else if ( pView->IsMarkedHit(aPnt) )
158         {
159             pViewShell->SetActivePointer(Pointer(POINTER_MOVE));
160         }
161         else
162         {
163             pViewShell->SetActivePointer( aNewPointer );
164         }
165     }
166     return sal_True;
167 }
168 
169 /*************************************************************************
170 |*
171 |* MouseButtonUp-event
172 |*
173 \************************************************************************/
174 
MouseButtonUp(const MouseEvent & rMEvt)175 sal_Bool __EXPORT FuConstruct::MouseButtonUp(const MouseEvent& rMEvt)
176 {
177     // #95491# remember button state for creation of own MouseEvents
178     SetMouseButtonCode(rMEvt.GetButtons());
179 
180     sal_Bool bReturn = SimpleMouseButtonUp( rMEvt );
181 
182     //      Doppelklick auf Textobjekt? (->fusel)
183 
184     sal_uInt16 nClicks = rMEvt.GetClicks();
185     if ( nClicks == 2 && rMEvt.IsLeft() )
186     {
187         if ( pView->AreObjectsMarked() )
188         {
189             const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
190             if (rMarkList.GetMarkCount() == 1)
191             {
192                 SdrMark* pMark = rMarkList.GetMark(0);
193                 SdrObject* pObj = pMark->GetMarkedSdrObj();
194 
195                 //  #49458# bei Uno-Controls nicht in Textmodus
196                 if ( pObj->ISA(SdrTextObj) && !pObj->ISA(SdrUnoObj) )
197                 {
198                     OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
199                     sal_Bool bVertical = ( pOPO && pOPO->IsVertical() );
200                     sal_uInt16 nTextSlotId = bVertical ? SID_DRAW_TEXT_VERTICAL : SID_DRAW_TEXT;
201 
202                     pViewShell->GetViewData()->GetDispatcher().
203                         Execute(nTextSlotId, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
204 
205                     // jetzt den erzeugten FuText holen und in den EditModus setzen
206                     FuPoor* pPoor = pViewShell->GetViewData()->GetView()->GetDrawFuncPtr();
207                     if ( pPoor && pPoor->GetSlotID() == nTextSlotId )    // hat keine RTTI
208                     {
209                         FuText* pText = (FuText*)pPoor;
210                         Point aMousePixel = rMEvt.GetPosPixel();
211                         pText->SetInEditMode( pObj, &aMousePixel );
212                     }
213                     bReturn = sal_True;
214                 }
215             }
216         }
217     }
218 
219     FuDraw::MouseButtonUp(rMEvt);
220 
221     return bReturn;
222 }
223 
224 //      SimpleMouseButtonUp - ohne Test auf Doppelklick
225 
SimpleMouseButtonUp(const MouseEvent & rMEvt)226 sal_Bool FuConstruct::SimpleMouseButtonUp(const MouseEvent& rMEvt)
227 {
228     sal_Bool    bReturn = sal_True;
229 
230     if (aDragTimer.IsActive() )
231     {
232         aDragTimer.Stop();
233     }
234 
235     Point   aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
236 
237     if ( pView->IsDragObj() )
238          pView->EndDragObj( rMEvt.IsMod1() );
239 
240     else if ( pView->IsMarkObj() )
241         pView->EndMarkObj();
242 
243     else bReturn = sal_False;
244 
245     if ( !pView->IsAction() )
246     {
247         pWindow->ReleaseMouse();
248 
249         if ( !pView->AreObjectsMarked() && rMEvt.GetClicks() < 2 )
250         {
251             pView->MarkObj(aPnt, -2, sal_False, rMEvt.IsMod1());
252 
253             SfxDispatcher& rDisp = pViewShell->GetViewData()->GetDispatcher();
254             if ( pView->AreObjectsMarked() )
255                 rDisp.Execute(SID_OBJECT_SELECT, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
256             else
257                 rDisp.Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
258         }
259     }
260 
261     return bReturn;
262 }
263 
264 /*************************************************************************
265 |*
266 |* Tastaturereignisse bearbeiten
267 |*
268 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
269 |* FALSE.
270 |*
271 \************************************************************************/
272 
KeyInput(const KeyEvent & rKEvt)273 sal_Bool __EXPORT FuConstruct::KeyInput(const KeyEvent& rKEvt)
274 {
275     sal_Bool bReturn = sal_False;
276 
277     switch ( rKEvt.GetKeyCode().GetCode() )
278     {
279         case KEY_ESCAPE:
280             if ( pView->IsAction() )
281             {
282                 pView->BrkAction();
283                 pWindow->ReleaseMouse();
284                 bReturn = sal_True;
285             }
286             else                            // Zeichenmodus beenden
287             {
288                 pViewShell->GetViewData()->GetDispatcher().
289                     Execute(aSfxRequest.GetSlot(), SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD);
290             }
291             break;
292 
293         case KEY_DELETE:
294             pView->DeleteMarked();
295             bReturn = sal_True;
296             break;
297     }
298 
299     if ( !bReturn )
300     {
301         bReturn = FuDraw::KeyInput(rKEvt);
302     }
303 
304     return(bReturn);
305 }
306 
307 /*************************************************************************
308 |*
309 |* Function aktivieren
310 |*
311 \************************************************************************/
312 
Activate()313 void FuConstruct::Activate()
314 {
315     FuDraw::Activate();
316 }
317 
318 /*************************************************************************
319 |*
320 |* Function deaktivieren
321 |*
322 \************************************************************************/
323 
Deactivate()324 void FuConstruct::Deactivate()
325 {
326     FuDraw::Deactivate();
327 }
328 
329 
330 
331 
332