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 <vcl/scrbar.hxx>
21 : #include <svx/svdview.hxx>
22 : #include "dlgedfunc.hxx"
23 : #include "dlged.hxx"
24 : #include "dlgedview.hxx"
25 : #include <vcl/seleng.hxx>
26 :
27 : namespace basctl
28 : {
29 :
30 : //----------------------------------------------------------------------------
31 :
32 0 : IMPL_LINK_INLINE_START( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
33 : {
34 : (void)pTimer;
35 0 : Window& rWindow = rParent.GetWindow();
36 0 : Point aPos = rWindow.ScreenToOutputPixel( rWindow.GetPointerPosPixel() );
37 0 : aPos = rWindow.PixelToLogic( aPos );
38 0 : ForceScroll( aPos );
39 0 : return 0;
40 : }
41 0 : IMPL_LINK_INLINE_END( DlgEdFunc, ScrollTimeout, Timer *, pTimer )
42 :
43 : //----------------------------------------------------------------------------
44 :
45 0 : void DlgEdFunc::ForceScroll( const Point& rPos )
46 : {
47 0 : aScrollTimer.Stop();
48 :
49 0 : Window& rWindow = rParent.GetWindow();
50 :
51 0 : static Point aDefPoint;
52 0 : Rectangle aOutRect( aDefPoint, rWindow.GetOutputSizePixel() );
53 0 : aOutRect = rWindow.PixelToLogic( aOutRect );
54 :
55 0 : ScrollBar* pHScroll = rParent.GetHScroll();
56 0 : ScrollBar* pVScroll = rParent.GetVScroll();
57 0 : long nDeltaX = pHScroll->GetLineSize();
58 0 : long nDeltaY = pVScroll->GetLineSize();
59 :
60 0 : if( !aOutRect.IsInside( rPos ) )
61 : {
62 0 : if( rPos.X() < aOutRect.Left() )
63 0 : nDeltaX = -nDeltaX;
64 0 : else if( rPos.X() <= aOutRect.Right() )
65 0 : nDeltaX = 0;
66 :
67 0 : if( rPos.Y() < aOutRect.Top() )
68 0 : nDeltaY = -nDeltaY;
69 0 : else if( rPos.Y() <= aOutRect.Bottom() )
70 0 : nDeltaY = 0;
71 :
72 0 : if( nDeltaX )
73 0 : pHScroll->SetThumbPos( pHScroll->GetThumbPos() + nDeltaX );
74 0 : if( nDeltaY )
75 0 : pVScroll->SetThumbPos( pVScroll->GetThumbPos() + nDeltaY );
76 :
77 0 : if( nDeltaX )
78 0 : rParent.DoScroll( pHScroll );
79 0 : if( nDeltaY )
80 0 : rParent.DoScroll( pVScroll );
81 : }
82 :
83 0 : aScrollTimer.Start();
84 0 : }
85 :
86 : //----------------------------------------------------------------------------
87 :
88 0 : DlgEdFunc::DlgEdFunc (DlgEditor& rParent_) :
89 0 : rParent(rParent_)
90 : {
91 0 : aScrollTimer.SetTimeoutHdl( LINK( this, DlgEdFunc, ScrollTimeout ) );
92 0 : aScrollTimer.SetTimeout( SELENG_AUTOREPEAT_INTERVAL );
93 0 : }
94 :
95 : //----------------------------------------------------------------------------
96 :
97 0 : DlgEdFunc::~DlgEdFunc()
98 : {
99 0 : }
100 :
101 : //----------------------------------------------------------------------------
102 :
103 0 : bool DlgEdFunc::MouseButtonDown( const MouseEvent& )
104 : {
105 0 : return true;
106 : }
107 :
108 : //----------------------------------------------------------------------------
109 :
110 0 : bool DlgEdFunc::MouseButtonUp( const MouseEvent& )
111 : {
112 0 : aScrollTimer.Stop();
113 0 : return true;
114 : }
115 :
116 : //----------------------------------------------------------------------------
117 :
118 0 : bool DlgEdFunc::MouseMove( const MouseEvent& )
119 : {
120 0 : return true;
121 : }
122 :
123 : //----------------------------------------------------------------------------
124 :
125 0 : bool DlgEdFunc::KeyInput( const KeyEvent& rKEvt )
126 : {
127 0 : bool bReturn = false;
128 :
129 0 : SdrView& rView = rParent.GetView();
130 0 : Window& rWindow = rParent.GetWindow();
131 :
132 0 : KeyCode aCode = rKEvt.GetKeyCode();
133 0 : sal_uInt16 nCode = aCode.GetCode();
134 :
135 0 : switch ( nCode )
136 : {
137 : case KEY_ESCAPE:
138 : {
139 0 : if ( rView.IsAction() )
140 : {
141 0 : rView.BrkAction();
142 0 : bReturn = true;
143 : }
144 0 : else if ( rView.AreObjectsMarked() )
145 : {
146 0 : const SdrHdlList& rHdlList = rView.GetHdlList();
147 0 : SdrHdl* pHdl = rHdlList.GetFocusHdl();
148 0 : if ( pHdl )
149 0 : const_cast<SdrHdlList&>(rHdlList).ResetFocusHdl();
150 : else
151 0 : rView.UnmarkAll();
152 :
153 0 : bReturn = true;
154 : }
155 : }
156 0 : break;
157 : case KEY_TAB:
158 : {
159 0 : if ( !aCode.IsMod1() && !aCode.IsMod2() )
160 : {
161 : // mark next object
162 0 : if ( !rView.MarkNextObj( !aCode.IsShift() ) )
163 : {
164 : // if no next object, mark first/last
165 0 : rView.UnmarkAllObj();
166 0 : rView.MarkNextObj( !aCode.IsShift() );
167 : }
168 :
169 0 : if ( rView.AreObjectsMarked() )
170 0 : rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
171 :
172 0 : bReturn = true;
173 : }
174 0 : else if ( aCode.IsMod1() )
175 : {
176 : // selected handle
177 0 : const SdrHdlList& rHdlList = rView.GetHdlList();
178 0 : const_cast<SdrHdlList&>(rHdlList).TravelFocusHdl( !aCode.IsShift() );
179 :
180 : // guarantee visibility of focused handle
181 0 : if (SdrHdl* pHdl = rHdlList.GetFocusHdl())
182 : {
183 0 : Point aHdlPosition( pHdl->GetPos() );
184 0 : Rectangle aVisRect( aHdlPosition - Point( 100, 100 ), Size( 200, 200 ) );
185 0 : rView.MakeVisible( aVisRect, rWindow );
186 : }
187 :
188 0 : bReturn = true;
189 : }
190 : }
191 0 : break;
192 : case KEY_UP:
193 : case KEY_DOWN:
194 : case KEY_LEFT:
195 : case KEY_RIGHT:
196 : {
197 0 : long nX = 0;
198 0 : long nY = 0;
199 :
200 0 : if ( nCode == KEY_UP )
201 : {
202 : // scroll up
203 0 : nX = 0;
204 0 : nY = -1;
205 : }
206 0 : else if ( nCode == KEY_DOWN )
207 : {
208 : // scroll down
209 0 : nX = 0;
210 0 : nY = 1;
211 : }
212 0 : else if ( nCode == KEY_LEFT )
213 : {
214 : // scroll left
215 0 : nX = -1;
216 0 : nY = 0;
217 : }
218 0 : else if ( nCode == KEY_RIGHT )
219 : {
220 : // scroll right
221 0 : nX = 1;
222 0 : nY = 0;
223 : }
224 :
225 0 : if ( rView.AreObjectsMarked() && !aCode.IsMod1() )
226 : {
227 0 : if ( aCode.IsMod2() )
228 : {
229 : // move in 1 pixel distance
230 0 : Size aPixelSize = rWindow.PixelToLogic(Size(1, 1));
231 0 : nX *= aPixelSize.Width();
232 0 : nY *= aPixelSize.Height();
233 : }
234 : else
235 : {
236 : // move in 1 mm distance
237 0 : nX *= 100;
238 0 : nY *= 100;
239 : }
240 :
241 0 : const SdrHdlList& rHdlList = rView.GetHdlList();
242 0 : SdrHdl* pHdl = rHdlList.GetFocusHdl();
243 :
244 0 : if ( pHdl == 0 )
245 : {
246 : // no handle selected
247 0 : if ( rView.IsMoveAllowed() )
248 : {
249 : // restrict movement to work area
250 0 : const Rectangle& rWorkArea = rView.GetWorkArea();
251 :
252 0 : if ( !rWorkArea.IsEmpty() )
253 : {
254 0 : Rectangle aMarkRect( rView.GetMarkedObjRect() );
255 0 : aMarkRect.Move( nX, nY );
256 :
257 0 : if ( !rWorkArea.IsInside( aMarkRect ) )
258 : {
259 0 : if ( aMarkRect.Left() < rWorkArea.Left() )
260 0 : nX += rWorkArea.Left() - aMarkRect.Left();
261 :
262 0 : if ( aMarkRect.Right() > rWorkArea.Right() )
263 0 : nX -= aMarkRect.Right() - rWorkArea.Right();
264 :
265 0 : if ( aMarkRect.Top() < rWorkArea.Top() )
266 0 : nY += rWorkArea.Top() - aMarkRect.Top();
267 :
268 0 : if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
269 0 : nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
270 : }
271 : }
272 :
273 0 : if ( nX != 0 || nY != 0 )
274 : {
275 0 : rView.MoveAllMarked( Size( nX, nY ) );
276 0 : rView.MakeVisible( rView.GetAllMarkedRect(), rWindow );
277 : }
278 : }
279 : }
280 : else
281 : {
282 : // move the handle
283 0 : if ( pHdl && ( nX || nY ) )
284 : {
285 0 : Point aStartPoint( pHdl->GetPos() );
286 0 : Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
287 0 : const SdrDragStat& rDragStat = rView.GetDragStat();
288 :
289 : // start dragging
290 0 : rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
291 :
292 0 : if ( rView.IsDragObj() )
293 : {
294 0 : bool const bWasNoSnap = rDragStat.IsNoSnap();
295 0 : bool const bWasSnapEnabled = rView.IsSnapEnabled();
296 :
297 : // switch snapping off
298 0 : if ( !bWasNoSnap )
299 0 : const_cast<SdrDragStat&>(rDragStat).SetNoSnap(true);
300 0 : if ( bWasSnapEnabled )
301 0 : rView.SetSnapEnabled(false);
302 :
303 0 : rView.MovAction( aEndPoint );
304 0 : rView.EndDragObj();
305 :
306 : // restore snap
307 0 : if ( !bWasNoSnap )
308 0 : const_cast<SdrDragStat&>(rDragStat).SetNoSnap( bWasNoSnap );
309 0 : if ( bWasSnapEnabled )
310 0 : rView.SetSnapEnabled( bWasSnapEnabled );
311 : }
312 :
313 : // make moved handle visible
314 0 : Rectangle aVisRect( aEndPoint - Point( 100, 100 ), Size( 200, 200 ) );
315 0 : rView.MakeVisible( aVisRect, rWindow );
316 : }
317 : }
318 : }
319 : else
320 : {
321 : // scroll page
322 0 : ScrollBar* pScrollBar = ( nX != 0 ) ? rParent.GetHScroll() : rParent.GetVScroll();
323 0 : if ( pScrollBar )
324 : {
325 0 : long nRangeMin = pScrollBar->GetRangeMin();
326 0 : long nRangeMax = pScrollBar->GetRangeMax();
327 0 : long nThumbPos = pScrollBar->GetThumbPos() + ( ( nX != 0 ) ? nX : nY ) * pScrollBar->GetLineSize();
328 0 : if ( nThumbPos < nRangeMin )
329 0 : nThumbPos = nRangeMin;
330 0 : if ( nThumbPos > nRangeMax )
331 0 : nThumbPos = nRangeMax;
332 0 : pScrollBar->SetThumbPos( nThumbPos );
333 0 : rParent.DoScroll( pScrollBar );
334 : }
335 : }
336 :
337 0 : bReturn = true;
338 : }
339 0 : break;
340 : default:
341 : {
342 : }
343 0 : break;
344 : }
345 :
346 0 : if ( bReturn )
347 0 : rWindow.ReleaseMouse();
348 :
349 0 : return bReturn;
350 : }
351 :
352 : //----------------------------------------------------------------------------
353 :
354 0 : DlgEdFuncInsert::DlgEdFuncInsert (DlgEditor& rParent_) :
355 0 : DlgEdFunc(rParent_)
356 : {
357 0 : rParent.GetView().SetCreateMode(true);
358 0 : }
359 :
360 : //----------------------------------------------------------------------------
361 :
362 0 : DlgEdFuncInsert::~DlgEdFuncInsert()
363 : {
364 0 : rParent.GetView().SetEditMode( true );
365 0 : }
366 :
367 : //----------------------------------------------------------------------------
368 :
369 0 : bool DlgEdFuncInsert::MouseButtonDown( const MouseEvent& rMEvt )
370 : {
371 0 : if( !rMEvt.IsLeft() )
372 0 : return true;
373 :
374 0 : SdrView& rView = rParent.GetView();
375 0 : Window& rWindow = rParent.GetWindow();
376 0 : rView.SetActualWin(&rWindow);
377 :
378 0 : Point aPos = rWindow.PixelToLogic( rMEvt.GetPosPixel() );
379 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
380 0 : sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
381 :
382 0 : rWindow.CaptureMouse();
383 :
384 0 : if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
385 : {
386 0 : SdrHdl* pHdl = rView.PickHandle(aPos);
387 :
388 : // if selected object was hit, drag object
389 0 : if ( pHdl!=NULL || rView.IsMarkedHit(aPos, nHitLog) )
390 0 : rView.BegDragObj(aPos, (OutputDevice*) NULL, pHdl, nDrgLog);
391 0 : else if ( rView.AreObjectsMarked() )
392 0 : rView.UnmarkAll();
393 :
394 : // if no action, create object
395 0 : if ( !rView.IsAction() )
396 0 : rView.BegCreateObj(aPos);
397 : }
398 0 : else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
399 : {
400 : // if object was hit, show property browser
401 0 : if ( rView.IsMarkedHit(aPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
402 0 : rParent.ShowProperties();
403 : }
404 :
405 0 : return true;
406 : }
407 :
408 : //----------------------------------------------------------------------------
409 :
410 0 : bool DlgEdFuncInsert::MouseButtonUp( const MouseEvent& rMEvt )
411 : {
412 0 : DlgEdFunc::MouseButtonUp( rMEvt );
413 :
414 0 : SdrView& rView = rParent.GetView();
415 0 : Window& rWindow = rParent.GetWindow();
416 0 : rView.SetActualWin(&rWindow);
417 :
418 0 : rWindow.ReleaseMouse();
419 :
420 : // object creation active?
421 0 : if ( rView.IsCreateObj() )
422 : {
423 0 : rView.EndCreateObj(SDRCREATE_FORCEEND);
424 :
425 0 : if ( !rView.AreObjectsMarked() )
426 : {
427 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
428 0 : Point aPos( rWindow.PixelToLogic( rMEvt.GetPosPixel() ) );
429 0 : rView.MarkObj(aPos, nHitLog);
430 : }
431 :
432 0 : return rView.AreObjectsMarked();
433 : }
434 : else
435 : {
436 0 : if ( rView.IsDragObj() )
437 0 : rView.EndDragObj( rMEvt.IsMod1() );
438 0 : return true;
439 : }
440 : }
441 :
442 : //----------------------------------------------------------------------------
443 :
444 0 : bool DlgEdFuncInsert::MouseMove( const MouseEvent& rMEvt )
445 : {
446 0 : SdrView& rView = rParent.GetView();
447 0 : Window& rWindow = rParent.GetWindow();
448 0 : rView.SetActualWin(&rWindow);
449 :
450 0 : Point aPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
451 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
452 :
453 0 : if (rView.IsAction())
454 : {
455 0 : ForceScroll(aPos);
456 0 : rView.MovAction(aPos);
457 : }
458 :
459 0 : rWindow.SetPointer( rView.GetPreferedPointer( aPos, &rWindow, nHitLog ) );
460 :
461 0 : return true;
462 : }
463 :
464 : //----------------------------------------------------------------------------
465 :
466 0 : DlgEdFuncSelect::DlgEdFuncSelect (DlgEditor& rParent_) :
467 : DlgEdFunc(rParent_),
468 0 : bMarkAction(false)
469 : {
470 0 : }
471 :
472 : //----------------------------------------------------------------------------
473 :
474 0 : DlgEdFuncSelect::~DlgEdFuncSelect()
475 : {
476 0 : }
477 :
478 : //----------------------------------------------------------------------------
479 :
480 0 : bool DlgEdFuncSelect::MouseButtonDown( const MouseEvent& rMEvt )
481 : {
482 : // get view from parent
483 0 : SdrView& rView = rParent.GetView();
484 0 : Window& rWindow = rParent.GetWindow();
485 0 : rView.SetActualWin(&rWindow);
486 :
487 0 : sal_uInt16 nDrgLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
488 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
489 0 : Point aMDPos = rWindow.PixelToLogic(rMEvt.GetPosPixel());
490 :
491 0 : if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 1 )
492 : {
493 0 : SdrHdl* pHdl = rView.PickHandle(aMDPos);
494 : SdrObject* pObj;
495 : SdrPageView* pPV;
496 :
497 : // hit selected object?
498 0 : if ( pHdl!=NULL || rView.IsMarkedHit(aMDPos, nHitLog) )
499 : {
500 0 : rView.BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
501 : }
502 : else
503 : {
504 : // if not multi selection, unmark all
505 0 : if ( !rMEvt.IsShift() )
506 0 : rView.UnmarkAll();
507 : else
508 : {
509 0 : if( rView.PickObj( aMDPos, nHitLog, pObj, pPV ) )
510 : {
511 : //if (dynamic_cast<DlgEdForm*>(pObj))
512 : // rView.UnmarkAll();
513 : //else
514 : // rParent.UnmarkDialog();
515 : }
516 : }
517 :
518 0 : if ( rView.MarkObj(aMDPos, nHitLog) )
519 : {
520 : // drag object
521 0 : pHdl = rView.PickHandle(aMDPos);
522 0 : rView.BegDragObj(aMDPos, (OutputDevice*) NULL, pHdl, nDrgLog);
523 : }
524 : else
525 : {
526 : // select object
527 0 : rView.BegMarkObj(aMDPos);
528 0 : bMarkAction = true;
529 : }
530 : }
531 : }
532 0 : else if ( rMEvt.IsLeft() && rMEvt.GetClicks() == 2 )
533 : {
534 : // if object was hit, show property browser
535 0 : if ( rView.IsMarkedHit(aMDPos, nHitLog) && rParent.GetMode() != DlgEditor::READONLY )
536 0 : rParent.ShowProperties();
537 : }
538 :
539 0 : return true;
540 : }
541 :
542 : //----------------------------------------------------------------------------
543 :
544 0 : bool DlgEdFuncSelect::MouseButtonUp( const MouseEvent& rMEvt )
545 : {
546 0 : DlgEdFunc::MouseButtonUp( rMEvt );
547 :
548 : // get view from parent
549 0 : SdrView& rView = rParent.GetView();
550 0 : Window& rWindow = rParent.GetWindow();
551 0 : rView.SetActualWin(&rWindow);
552 :
553 0 : Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
554 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
555 :
556 0 : if ( rMEvt.IsLeft() )
557 : {
558 0 : if (rView.IsDragObj())
559 : {
560 : // object was dragged
561 0 : rView.EndDragObj( rMEvt.IsMod1() );
562 0 : rView.ForceMarkedToAnotherPage();
563 : }
564 0 : else if (rView.IsAction())
565 : {
566 0 : rView.EndAction();
567 : }
568 : }
569 :
570 0 : bMarkAction = false;
571 :
572 0 : rWindow.SetPointer( rView.GetPreferedPointer( aPnt, &rWindow, nHitLog ) );
573 0 : rWindow.ReleaseMouse();
574 :
575 0 : return true;
576 : }
577 :
578 : //----------------------------------------------------------------------------
579 :
580 0 : bool DlgEdFuncSelect::MouseMove( const MouseEvent& rMEvt )
581 : {
582 0 : SdrView& rView = rParent.GetView();
583 0 : Window& rWindow = rParent.GetWindow();
584 0 : rView.SetActualWin(&rWindow);
585 :
586 0 : Point aPnt = rWindow.PixelToLogic(rMEvt.GetPosPixel());
587 0 : sal_uInt16 nHitLog = static_cast<sal_uInt16>(rWindow.PixelToLogic(Size(3, 0)).Width());
588 :
589 0 : if ( rView.IsAction() )
590 : {
591 0 : Point aPix = rMEvt.GetPosPixel();
592 0 : Point aPnt_ = rWindow.PixelToLogic(aPix);
593 :
594 0 : ForceScroll(aPnt_);
595 0 : rView.MovAction(aPnt_);
596 : }
597 :
598 0 : rWindow.SetPointer( rView.GetPreferedPointer( aPnt, &rWindow, nHitLog ) );
599 :
600 0 : return true;
601 : }
602 :
603 : //----------------------------------------------------------------------------
604 :
605 0 : } // namespace basctl
606 :
607 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|