/src/libreoffice/sw/source/uibase/ribbar/drawbase.cxx
Line | Count | Source |
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 <hintids.hxx> |
21 | | #include <comphelper/lok.hxx> |
22 | | #include <svx/svdview.hxx> |
23 | | #include <svx/svdobj.hxx> |
24 | | #include <svl/ptitem.hxx> |
25 | | #include <editeng/sizeitem.hxx> |
26 | | #include <sfx2/request.hxx> |
27 | | #include <sfx2/bindings.hxx> |
28 | | #include <sfx2/viewfrm.hxx> |
29 | | #include <fmtclds.hxx> |
30 | | #include <frmfmt.hxx> |
31 | | #include <cmdid.h> |
32 | | #include <view.hxx> |
33 | | #include <wrtsh.hxx> |
34 | | #include <drawbase.hxx> |
35 | | #include <edtwin.hxx> |
36 | | #include <swmodule.hxx> |
37 | | #include <swundo.hxx> |
38 | | #include <SwCapObjType.hxx> |
39 | | #include <SwRewriter.hxx> |
40 | | #include <strings.hrc> |
41 | | |
42 | | using namespace ::com::sun::star; |
43 | | |
44 | | SwDrawBase::SwDrawBase(SwWrtShell* pSwWrtShell, SwEditWin* pWindow, SwView& rSwView) : |
45 | 0 | m_rView(rSwView), |
46 | 0 | m_pSh(pSwWrtShell), |
47 | 0 | m_pWin(pWindow), |
48 | 0 | m_nSlotId(USHRT_MAX), |
49 | 0 | m_bCreateObj(true), |
50 | 0 | m_bInsForm(false) |
51 | 0 | { |
52 | 0 | if ( !m_pSh->HasDrawView() ) |
53 | 0 | m_pSh->MakeDrawView(); |
54 | 0 | } |
55 | | |
56 | | SwDrawBase::~SwDrawBase() |
57 | 0 | { |
58 | 0 | if (m_rView.GetWrtShellPtr()) // In the view-dtor could the wrtsh already been deleted... |
59 | 0 | m_pSh->GetDrawView()->SetEditMode(); |
60 | 0 | } |
61 | | |
62 | | bool SwDrawBase::MouseButtonDown(const MouseEvent& rMEvt) |
63 | 0 | { |
64 | 0 | bool bReturn = false; |
65 | |
|
66 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
67 | | |
68 | | // #i33136# |
69 | 0 | pSdrView->SetOrtho(doConstructOrthogonal() ? !rMEvt.IsShift() : rMEvt.IsShift()); |
70 | 0 | pSdrView->SetAngleSnapEnabled(rMEvt.IsShift()); |
71 | |
|
72 | 0 | if (rMEvt.IsMod2()) |
73 | 0 | { |
74 | 0 | pSdrView->SetCreate1stPointAsCenter(true); |
75 | 0 | pSdrView->SetResizeAtCenter(true); |
76 | 0 | } |
77 | 0 | else |
78 | 0 | { |
79 | 0 | pSdrView->SetCreate1stPointAsCenter(false); |
80 | 0 | pSdrView->SetResizeAtCenter(false); |
81 | 0 | } |
82 | |
|
83 | 0 | SdrViewEvent aVEvt; |
84 | 0 | SdrHitKind eHit = pSdrView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt); |
85 | | |
86 | | // Only new object, if not in the basic mode (or pure selection mode). |
87 | 0 | if (rMEvt.IsLeft() && !m_pWin->IsDrawAction()) |
88 | 0 | { |
89 | 0 | if (IsCreateObj() && (eHit == SdrHitKind::UnmarkedObject || eHit == SdrHitKind::NONE || m_pSh->IsDrawCreate())) |
90 | 0 | { |
91 | 0 | g_bNoInterrupt = true; |
92 | 0 | m_pWin->CaptureMouse(); |
93 | |
|
94 | 0 | m_aStartPos = m_pWin->PixelToLogic(rMEvt.GetPosPixel()); |
95 | |
|
96 | 0 | bReturn = m_pSh->BeginCreate(m_pWin->GetSdrDrawMode(), m_aStartPos); |
97 | |
|
98 | 0 | SetDrawPointer(); |
99 | |
|
100 | 0 | if ( bReturn ) |
101 | 0 | m_pWin->SetDrawAction(true); |
102 | 0 | } |
103 | 0 | else if (!pSdrView->IsAction()) |
104 | 0 | { |
105 | | // BEZIER-EDITOR |
106 | 0 | m_pWin->CaptureMouse(); |
107 | 0 | m_aStartPos = m_pWin->PixelToLogic(rMEvt.GetPosPixel()); |
108 | 0 | sal_uInt16 nEditMode = m_pWin->GetBezierMode(); |
109 | |
|
110 | 0 | if (eHit == SdrHitKind::Handle && aVEvt.mpHdl->GetKind() == SdrHdlKind::BezierWeight) |
111 | 0 | { |
112 | | // Drag handle |
113 | 0 | g_bNoInterrupt = true; |
114 | 0 | bReturn = pSdrView->BegDragObj(m_aStartPos, nullptr, aVEvt.mpHdl); |
115 | 0 | m_pWin->SetDrawAction(true); |
116 | 0 | } |
117 | 0 | else if (eHit == SdrHitKind::MarkedObject && nEditMode == SID_BEZIER_INSERT) |
118 | 0 | { |
119 | | // Insert gluepoint |
120 | 0 | g_bNoInterrupt = true; |
121 | 0 | bReturn = pSdrView->BegInsObjPoint(m_aStartPos, rMEvt.IsMod1()); |
122 | 0 | m_pWin->SetDrawAction(true); |
123 | 0 | } |
124 | 0 | else if (eHit == SdrHitKind::MarkedObject && rMEvt.IsMod1()) |
125 | 0 | { |
126 | | // Select gluepoint |
127 | 0 | if (!rMEvt.IsShift()) |
128 | 0 | pSdrView->UnmarkAllPoints(); |
129 | |
|
130 | 0 | bReturn = pSdrView->BegMarkPoints(m_aStartPos); |
131 | 0 | m_pWin->SetDrawAction(true); |
132 | 0 | } |
133 | 0 | else if (eHit == SdrHitKind::MarkedObject && !rMEvt.IsShift() && !rMEvt.IsMod2()) |
134 | 0 | { |
135 | | // Move object |
136 | 0 | return false; |
137 | 0 | } |
138 | 0 | else if (eHit == SdrHitKind::Handle) |
139 | 0 | { |
140 | | // Select gluepoint |
141 | 0 | if (pSdrView->HasMarkablePoints() && (!pSdrView->IsPointMarked(*aVEvt.mpHdl) || rMEvt.IsShift())) |
142 | 0 | { |
143 | 0 | SdrHdl* pHdl = nullptr; |
144 | |
|
145 | 0 | if (!rMEvt.IsShift()) |
146 | 0 | { |
147 | 0 | pSdrView->UnmarkAllPoints(); |
148 | 0 | pHdl = pSdrView->PickHandle(m_aStartPos); |
149 | 0 | } |
150 | 0 | else |
151 | 0 | { |
152 | 0 | if (pSdrView->IsPointMarked(*aVEvt.mpHdl)) |
153 | 0 | { |
154 | 0 | bReturn = pSdrView->UnmarkPoint(*aVEvt.mpHdl); |
155 | 0 | pHdl = nullptr; |
156 | 0 | } |
157 | 0 | else |
158 | 0 | { |
159 | 0 | pHdl = pSdrView->PickHandle(m_aStartPos); |
160 | 0 | } |
161 | 0 | } |
162 | |
|
163 | 0 | if (pHdl) |
164 | 0 | { |
165 | 0 | g_bNoInterrupt = true; |
166 | 0 | pSdrView->MarkPoint(*pHdl); |
167 | 0 | } |
168 | 0 | } |
169 | 0 | } |
170 | 0 | else |
171 | 0 | { |
172 | | // Select or drag object |
173 | 0 | if (m_pSh->IsObjSelectable(m_aStartPos) && eHit == SdrHitKind::UnmarkedObject) |
174 | 0 | { |
175 | 0 | if (pSdrView->HasMarkablePoints()) |
176 | 0 | pSdrView->UnmarkAllPoints(); |
177 | |
|
178 | 0 | g_bNoInterrupt = false; |
179 | | // Use drag in edtwin |
180 | 0 | return false; |
181 | 0 | } |
182 | | |
183 | 0 | g_bNoInterrupt = true; |
184 | |
|
185 | 0 | if (m_pSh->GetSelectedObjCount()) |
186 | 0 | { |
187 | 0 | if (!rMEvt.IsShift()) |
188 | 0 | { |
189 | 0 | if (!pSdrView->HasMarkablePoints()) |
190 | 0 | { |
191 | 0 | bool bUnlockView = !m_pSh->IsViewLocked(); |
192 | 0 | m_pSh->LockView( true ); //lock visible section |
193 | 0 | m_pSh->SelectObj(Point(LONG_MAX, LONG_MAX)); // deselect all |
194 | 0 | if( bUnlockView ) |
195 | 0 | m_pSh->LockView( false ); |
196 | 0 | } |
197 | 0 | else |
198 | 0 | pSdrView->UnmarkAllPoints(); |
199 | 0 | } |
200 | 0 | } |
201 | 0 | if (!m_pSh->IsSelFrameMode()) |
202 | 0 | m_pSh->EnterSelFrameMode(); |
203 | |
|
204 | 0 | bReturn = m_pSh->BeginMark(m_aStartPos); |
205 | 0 | if( bReturn ) |
206 | 0 | m_pWin->SetDrawAction(true); |
207 | |
|
208 | 0 | SetDrawPointer(); |
209 | 0 | } |
210 | 0 | } |
211 | 0 | } |
212 | 0 | return bReturn; |
213 | 0 | } |
214 | | |
215 | | bool SwDrawBase::MouseMove(const MouseEvent& rMEvt) |
216 | 0 | { |
217 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
218 | 0 | Point aPnt(m_pWin->PixelToLogic(rMEvt.GetPosPixel())); |
219 | 0 | bool bRet = false; |
220 | |
|
221 | 0 | if (IsCreateObj() && !m_pWin->IsDrawSelMode() && pSdrView->IsCreateObj()) |
222 | 0 | { |
223 | | // #i33136# |
224 | 0 | pSdrView->SetOrtho(doConstructOrthogonal() ? !rMEvt.IsShift() : rMEvt.IsShift()); |
225 | 0 | pSdrView->SetAngleSnapEnabled(rMEvt.IsShift()); |
226 | |
|
227 | 0 | m_pSh->MoveCreate(aPnt); |
228 | 0 | bRet = true; |
229 | 0 | } |
230 | 0 | else if (pSdrView->IsAction() || pSdrView->IsInsObjPoint() || pSdrView->IsMarkPoints()) |
231 | 0 | { |
232 | 0 | m_pSh->MoveMark(aPnt); |
233 | 0 | bRet = true; |
234 | 0 | } |
235 | |
|
236 | 0 | return bRet; |
237 | 0 | } |
238 | | |
239 | | bool SwDrawBase::MouseButtonUp(const MouseEvent& rMEvt) |
240 | 0 | { |
241 | 0 | bool bReturn = false; |
242 | 0 | bool bCheckShell = false; |
243 | 0 | bool bAutoCap = false; |
244 | |
|
245 | 0 | Point aPnt(m_pWin->PixelToLogic(rMEvt.GetPosPixel())); |
246 | |
|
247 | 0 | if (IsCreateObj() && m_pSh->IsDrawCreate() && !m_pWin->IsDrawSelMode()) |
248 | 0 | { |
249 | 0 | const SdrObjKind nDrawMode = m_pWin->GetSdrDrawMode(); |
250 | | //objects with multiple point may end at the start position |
251 | 0 | bool bMultiPoint = SdrObjKind::PolyLine == nDrawMode || |
252 | 0 | SdrObjKind::Polygon == nDrawMode || |
253 | 0 | SdrObjKind::PathLine == nDrawMode || |
254 | 0 | SdrObjKind::PathFill == nDrawMode || |
255 | 0 | SdrObjKind::FreehandLine == nDrawMode || |
256 | 0 | SdrObjKind::FreehandFill == nDrawMode; |
257 | 0 | if(rMEvt.IsRight()) |
258 | 0 | { |
259 | 0 | m_pSh->BreakCreate(); |
260 | 0 | m_rView.LeaveDrawCreate(); |
261 | 0 | } |
262 | 0 | else |
263 | 0 | { |
264 | 0 | if (SdrObjKind::NewFrame == nDrawMode) |
265 | 0 | { |
266 | 0 | SwRewriter aRewriter; |
267 | |
|
268 | 0 | aRewriter.AddRule(UndoArg1, SwResId(STR_FRAME)); |
269 | 0 | m_pSh->StartUndo(SwUndoId::INSERT, &aRewriter); |
270 | 0 | } |
271 | |
|
272 | 0 | bool didCreate = m_pSh->EndCreate(SdrCreateCmd::ForceEnd); |
273 | 0 | if(!didCreate && !bMultiPoint) |
274 | 0 | { |
275 | 0 | CreateDefaultObjectAtPosWithSize(aPnt, Size(1000, 1000)); |
276 | 0 | } |
277 | |
|
278 | 0 | if (SdrObjKind::NewFrame == nDrawMode) // Text border inserted |
279 | 0 | { |
280 | 0 | uno::Reference< frame::XDispatchRecorder > xRecorder = |
281 | 0 | m_pSh->GetView().GetViewFrame().GetBindings().GetRecorder(); |
282 | 0 | if ( xRecorder.is() ) |
283 | 0 | { |
284 | 0 | SfxRequest aReq(m_pSh->GetView().GetViewFrame(), FN_INSERT_FRAME); |
285 | 0 | aReq .AppendItem(SfxUInt16Item( FN_INSERT_FRAME, |
286 | 0 | static_cast<sal_uInt16>(RndStdIds::FLY_AT_PARA) )); |
287 | 0 | aReq.AppendItem(SfxPointItem( FN_PARAM_1, m_pSh->GetAnchorObjDiff())); |
288 | 0 | aReq.AppendItem(SvxSizeItem( FN_PARAM_2, m_pSh->GetObjSize())); |
289 | 0 | aReq.Done(); |
290 | 0 | } |
291 | 0 | bAutoCap = true; |
292 | 0 | if(m_pWin->GetFrameColCount() > 1) |
293 | 0 | { |
294 | 0 | SfxItemSetFixed<RES_COL,RES_COL> aSet(m_rView.GetPool()); |
295 | 0 | SwFormatCol aCol(aSet.Get(RES_COL)); |
296 | 0 | aCol.Init(m_pWin->GetFrameColCount(), aCol.GetGutterWidth(), aCol.GetWishWidth()); |
297 | 0 | aSet.Put(aCol); |
298 | | // Template AutoUpdate |
299 | 0 | SwFrameFormat* pFormat = m_pSh->GetSelectedFrameFormat(); |
300 | 0 | if(pFormat && pFormat->IsAutoUpdateOnDirectFormat()) |
301 | 0 | m_pSh->AutoUpdateFrame(pFormat, aSet); |
302 | 0 | else |
303 | 0 | m_pSh->SetFlyFrameAttr( aSet ); |
304 | 0 | } |
305 | 0 | } |
306 | 0 | if (m_pWin->GetSdrDrawMode() == SdrObjKind::NewFrame) |
307 | 0 | { |
308 | 0 | m_pSh->EndUndo(); |
309 | 0 | } |
310 | 0 | } |
311 | |
|
312 | 0 | bReturn = true; |
313 | |
|
314 | 0 | EnterSelectMode(rMEvt); |
315 | 0 | } |
316 | 0 | else |
317 | 0 | { |
318 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
319 | |
|
320 | 0 | if (!pSdrView->HasMarkablePoints()) |
321 | 0 | { |
322 | | // NO BEZIER_EDITOR |
323 | 0 | if ((m_pSh->GetDrawView()->IsMarkObj() || m_pSh->GetDrawView()->IsMarkPoints()) |
324 | 0 | && rMEvt.IsLeft()) |
325 | 0 | { |
326 | 0 | bReturn = m_pSh->EndMark(); |
327 | |
|
328 | 0 | m_pWin->SetDrawAction(false); |
329 | |
|
330 | 0 | if (aPnt == m_aStartPos && m_pSh->IsObjSelectable(aPnt)) |
331 | 0 | { |
332 | 0 | m_pSh->SelectObj(aPnt, ( rMEvt.IsShift() && |
333 | 0 | m_pSh->IsSelFrameMode()) ? SW_ADD_SELECT : 0); |
334 | |
|
335 | 0 | if (!m_pSh->GetSelectedObjCount()) |
336 | 0 | { |
337 | 0 | m_rView.LeaveDrawCreate(); // Switch to selection mode |
338 | |
|
339 | 0 | m_pSh->GetView().GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW); |
340 | |
|
341 | 0 | if (m_pSh->IsSelFrameMode()) |
342 | 0 | m_pSh->LeaveSelFrameMode(); |
343 | 0 | } |
344 | 0 | m_rView.NoRotate(); |
345 | |
|
346 | 0 | bCheckShell = true; // if necessary turn on BezierShell |
347 | 0 | } |
348 | 0 | else if (!m_pSh->GetSelectedObjCount() && !m_pWin->IsDrawAction()) |
349 | 0 | { |
350 | 0 | if (m_pSh->IsObjSelectable(aPnt)) |
351 | 0 | m_pSh->SelectObj(aPnt, ( rMEvt.IsShift() && |
352 | 0 | m_pSh->IsSelFrameMode() ) ? SW_ADD_SELECT : 0 ); |
353 | 0 | else |
354 | 0 | { |
355 | 0 | m_rView.LeaveDrawCreate(); |
356 | 0 | if (m_pSh->IsSelFrameMode()) |
357 | 0 | m_pSh->LeaveSelFrameMode(); |
358 | 0 | } |
359 | 0 | m_rView.NoRotate(); |
360 | |
|
361 | 0 | bReturn = true; |
362 | 0 | } |
363 | 0 | } |
364 | 0 | } |
365 | 0 | else |
366 | 0 | { |
367 | | // BEZIER_EDITOR |
368 | 0 | if ( pSdrView->IsAction() ) |
369 | 0 | { |
370 | 0 | if ( pSdrView->IsInsObjPoint() ) |
371 | 0 | bReturn = pSdrView->EndInsObjPoint(SdrCreateCmd::ForceEnd); |
372 | 0 | else if (pSdrView->IsMarkPoints() ) |
373 | 0 | bReturn = pSdrView->EndMarkPoints(); |
374 | 0 | else |
375 | 0 | { |
376 | 0 | pSdrView->EndAction(); |
377 | 0 | bReturn = true; |
378 | 0 | } |
379 | 0 | m_pWin->SetDrawAction(false); |
380 | |
|
381 | 0 | if (aPnt == m_aStartPos) |
382 | 0 | { |
383 | 0 | if (!m_pSh->IsObjSelectable(aPnt)) |
384 | 0 | m_pSh->SelectObj(Point(LONG_MAX, LONG_MAX)); |
385 | 0 | else if (!bReturn) |
386 | 0 | { |
387 | 0 | if (!rMEvt.IsShift()) |
388 | 0 | pSdrView->UnmarkAllPoints(); |
389 | 0 | m_pSh->SelectObj(aPnt, (rMEvt.IsShift() && |
390 | 0 | m_pSh->IsSelFrameMode()) ? SW_ADD_SELECT :0); |
391 | 0 | } |
392 | |
|
393 | 0 | if (!m_pSh->GetSelectedObjCount()) |
394 | 0 | { |
395 | 0 | m_rView.LeaveDrawCreate(); // Switch to selection mode |
396 | |
|
397 | 0 | m_pSh->GetView().GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW); |
398 | |
|
399 | 0 | if (m_pSh->IsSelFrameMode()) |
400 | 0 | m_pSh->LeaveSelFrameMode(); |
401 | 0 | } |
402 | 0 | m_rView.NoRotate(); |
403 | |
|
404 | 0 | bCheckShell = true; // if necessary turn on BezierShell |
405 | 0 | } |
406 | 0 | } |
407 | |
|
408 | 0 | SetDrawPointer(); |
409 | |
|
410 | 0 | if (!m_pSh->GetSelectedObjCount() && !m_pWin->IsDrawAction()) |
411 | 0 | { |
412 | 0 | m_rView.LeaveDrawCreate(); |
413 | 0 | if (m_pSh->IsSelFrameMode()) |
414 | 0 | m_pSh->LeaveSelFrameMode(); |
415 | |
|
416 | 0 | m_rView.NoRotate(); |
417 | 0 | bReturn = true; |
418 | 0 | } |
419 | 0 | } |
420 | 0 | } |
421 | |
|
422 | 0 | if (bCheckShell) |
423 | 0 | m_rView.AttrChangedNotify(nullptr); // if necessary turn on BezierShell |
424 | | |
425 | | //!!!!!!!!!! Attention suicide !!!!!!!!!!! Everything should be renewed once |
426 | 0 | if ( bAutoCap ) |
427 | 0 | m_rView.AutoCaption(FRAME_CAP); //Can currently only be FRAME, otherwise convert |
428 | | // to enums |
429 | 0 | return bReturn; |
430 | 0 | } |
431 | | |
432 | | void SwDrawBase::Activate(const sal_uInt16 nSlot) |
433 | 0 | { |
434 | 0 | SetSlotId(nSlot); |
435 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
436 | |
|
437 | 0 | pSdrView->SetCurrentObj(m_pWin->GetSdrDrawMode()); |
438 | 0 | pSdrView->SetEditMode(false); |
439 | |
|
440 | 0 | SetDrawPointer(); |
441 | 0 | m_pSh->NoEdit(); |
442 | 0 | } |
443 | | |
444 | | void SwDrawBase::Deactivate() |
445 | 0 | { |
446 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
447 | 0 | pSdrView->SetOrtho(false); |
448 | 0 | pSdrView->SetAngleSnapEnabled(false); |
449 | |
|
450 | 0 | if (m_pWin->IsDrawAction() && m_pSh->IsDrawCreate()) |
451 | 0 | m_pSh->BreakCreate(); |
452 | |
|
453 | 0 | m_pWin->SetDrawAction(false); |
454 | |
|
455 | 0 | if (m_pWin->IsMouseCaptured()) |
456 | 0 | m_pWin->ReleaseMouse(); |
457 | 0 | g_bNoInterrupt = false; |
458 | |
|
459 | 0 | if (m_pWin->GetApplyTemplate()) |
460 | 0 | m_pWin->SetApplyTemplate(SwApplyTemplate()); |
461 | 0 | m_pSh->GetView().GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW); |
462 | 0 | } |
463 | | |
464 | | // Process keyboard events |
465 | | |
466 | | // If a KeyEvent is processed then the return value is true, otherwise |
467 | | // false. |
468 | | |
469 | | void SwDrawBase::BreakCreate() |
470 | 0 | { |
471 | 0 | m_pSh->BreakCreate(); |
472 | 0 | m_pWin->SetDrawAction(false); |
473 | 0 | m_pWin->ReleaseMouse(); |
474 | |
|
475 | 0 | Deactivate(); |
476 | 0 | } |
477 | | |
478 | | void SwDrawBase::SetDrawPointer() |
479 | 0 | { |
480 | 0 | SdrView *pSdrView = m_pSh->GetDrawView(); |
481 | 0 | Point aPnt(m_pWin->OutputToScreenPixel(m_pWin->GetPointerPosPixel())); |
482 | 0 | aPnt = m_pWin->PixelToLogic(m_pWin->ScreenToOutputPixel(aPnt)); |
483 | 0 | PointerStyle aPointTyp = pSdrView->GetPreferredPointer(aPnt, m_pSh->GetOut()); |
484 | 0 | m_pWin->SetPointer(aPointTyp); |
485 | 0 | } |
486 | | |
487 | | // If necessary switch into selection mode |
488 | | |
489 | | void SwDrawBase::EnterSelectMode(const MouseEvent& rMEvt) |
490 | 0 | { |
491 | 0 | m_pWin->SetDrawAction(false); |
492 | |
|
493 | 0 | if (m_pSh->GetSelectedObjCount() || m_pWin->IsDrawAction()) |
494 | 0 | return; |
495 | | |
496 | 0 | Point aPnt(m_pWin->PixelToLogic(rMEvt.GetPosPixel())); |
497 | |
|
498 | 0 | if (m_pSh->IsObjSelectable(aPnt)) |
499 | 0 | { |
500 | 0 | m_pSh->SelectObj(aPnt); |
501 | 0 | if (rMEvt.GetModifier() == KEY_SHIFT || !m_pSh->GetSelectedObjCount()) |
502 | 0 | { |
503 | 0 | m_rView.LeaveDrawCreate(); // Switch to selection mode |
504 | |
|
505 | 0 | m_pSh->GetView().GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW); |
506 | 0 | } |
507 | 0 | } |
508 | 0 | else |
509 | 0 | { |
510 | 0 | m_rView.LeaveDrawCreate(); |
511 | 0 | if (m_pSh->IsSelFrameMode()) |
512 | 0 | m_pSh->LeaveSelFrameMode(); |
513 | 0 | } |
514 | 0 | m_rView.NoRotate(); |
515 | 0 | } |
516 | | |
517 | | void SwDrawBase::CreateDefaultObject() |
518 | 0 | { |
519 | 0 | constexpr tools::Long constTwips_3cm = o3tl::toTwips(3, o3tl::Length::cm); |
520 | |
|
521 | 0 | Point aStartPos = GetDefaultCenterPos(); |
522 | 0 | Point aEndPos(aStartPos); |
523 | 0 | aStartPos.AdjustX(-constTwips_3cm); |
524 | 0 | aStartPos.AdjustY(-constTwips_3cm); |
525 | 0 | aEndPos.AdjustX(constTwips_3cm); |
526 | 0 | aEndPos.AdjustY(constTwips_3cm); |
527 | 0 | tools::Rectangle aRect(aStartPos, aEndPos); |
528 | 0 | m_pSh->CreateDefaultShape(m_pWin->GetSdrDrawMode(), aRect, m_nSlotId); |
529 | 0 | } |
530 | | |
531 | | void SwDrawBase::CreateDefaultObjectAtPosWithSize(Point aPos, Size aSize) |
532 | 0 | { |
533 | 0 | aPos.AdjustX(-sal_Int32(aSize.getWidth() / 2)); |
534 | 0 | aPos.AdjustY(-sal_Int32(aSize.getHeight() / 2)); |
535 | |
|
536 | 0 | SdrView* sdrView = m_rView.GetDrawView(); |
537 | 0 | SdrPageView *pPV = sdrView->GetSdrPageView(); |
538 | |
|
539 | 0 | if(sdrView->IsSnapEnabled()) |
540 | 0 | aPos = sdrView->GetSnapPos(aPos, pPV); |
541 | |
|
542 | 0 | ::tools::Rectangle aNewObjectRectangle(aPos, aSize); |
543 | 0 | m_pSh->CreateDefaultShape(m_pWin->GetSdrDrawMode(), aNewObjectRectangle, m_nSlotId); |
544 | 0 | } |
545 | | |
546 | | Point SwDrawBase::GetDefaultCenterPos() const |
547 | 0 | { |
548 | 0 | Size aDocSz(m_pSh->GetDocSize()); |
549 | |
|
550 | 0 | SwRect aVisArea(m_pSh->VisArea()); |
551 | 0 | if (comphelper::LibreOfficeKit::isActive()) |
552 | 0 | { |
553 | 0 | aVisArea = SwRect(m_pSh->getLOKVisibleArea()); |
554 | 0 | aVisArea.Intersection(SwRect(Point(), aDocSz)); |
555 | 0 | } |
556 | |
|
557 | 0 | Point aCenter = aVisArea.Center(); |
558 | | // To increase the chance that aCenter actually falls somewhere on a page (rather than on the |
559 | | // background between pages), keep it centered horizontally for the "Single-page view" |
560 | | // (GetViewLayoutColumns() == 1) and "Book view" (GetViewLayoutColumns() == 2) cases that |
561 | | // display the pages centered on the background: |
562 | 0 | if (aVisArea.Width() > aDocSz.Width() && m_pSh->GetViewOptions()->GetViewLayoutColumns() == 0) |
563 | 0 | aCenter.setX(aDocSz.Width() / 2 + aVisArea.Left()); |
564 | 0 | if (aVisArea.Height() > aDocSz.Height()) |
565 | 0 | aCenter.setY(aDocSz.Height() / 2 + aVisArea.Top()); |
566 | |
|
567 | 0 | return aCenter; |
568 | 0 | } |
569 | | |
570 | | // #i33136# |
571 | | bool SwDrawBase::doConstructOrthogonal() const |
572 | 0 | { |
573 | 0 | return ( m_nSlotId == SID_DRAW_XPOLYGON || m_nSlotId == SID_DRAW_XPOLYGON_NOFILL || m_nSlotId == SID_DRAW_XLINE ); |
574 | 0 | } |
575 | | |
576 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |