LibreOffice Module sw (master) 1
conform.cxx
Go to the documentation of this file.
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 <svx/svdview.hxx>
21#include <vcl/ptrstyle.hxx>
22
23#include <swmodule.hxx>
24#include <view.hxx>
25#include <edtwin.hxx>
26#include <wrtsh.hxx>
27#include <drawbase.hxx>
28#include <conform.hxx>
29
31 : SwDrawBase(pWrtShell, pEditWin, pSwView)
32 , m_eObjKind(eObjKind)
33{
34 m_bInsForm = true;
35}
36
38{
39 bool bReturn = false;
40
41 SdrView *pSdrView = m_pSh->GetDrawView();
42
43 pSdrView->SetOrtho(rMEvt.IsShift());
44 pSdrView->SetAngleSnapEnabled(rMEvt.IsShift());
45
46 if (rMEvt.IsMod2())
47 {
48 pSdrView->SetCreate1stPointAsCenter(true);
49 pSdrView->SetResizeAtCenter(true);
50 }
51 else
52 {
53 pSdrView->SetCreate1stPointAsCenter(false);
54 pSdrView->SetResizeAtCenter(false);
55 }
56
57 SdrViewEvent aVEvt;
58 SdrHitKind eHit = pSdrView->PickAnything(rMEvt, SdrMouseEventKind::BUTTONDOWN, aVEvt);
59
60 // Only new object; if not in base mode (or pure selection mode)
61 if (rMEvt.IsLeft() && !m_pWin->IsDrawAction() &&
62 (eHit == SdrHitKind::UnmarkedObject || eHit == SdrHitKind::NONE || m_pSh->IsDrawCreate()))
63 {
64 g_bNoInterrupt = true;
65 m_pWin->CaptureMouse();
66
67 m_pWin->SetPointer(PointerStyle::DrawRect);
68
69 m_aStartPos = m_pWin->PixelToLogic(rMEvt.GetPosPixel());
70 bReturn = m_pSh->BeginCreate(m_pWin->GetSdrDrawMode(), SdrInventor::FmForm, m_aStartPos);
71
72 if (bReturn)
73 m_pWin->SetDrawAction(true);
74 }
75 else
76 bReturn = SwDrawBase::MouseButtonDown(rMEvt);
77
78 return bReturn;
79}
80
81void ConstFormControl::Activate(const sal_uInt16 nSlotId)
82{
83 m_pWin->SetSdrDrawMode(m_eObjKind);
84 SwDrawBase::Activate(nSlotId);
86
87 m_pWin->SetPointer(PointerStyle::DrawRect);
88}
89
91{
93 constexpr tools::Long constTwips_10mm = o3tl::toTwips(10, o3tl::Length::mm);
94
95 Point aStartPos(GetDefaultCenterPos());
96 Point aEndPos(aStartPos);
97 aStartPos.AdjustX(-constTwips_10mm);
98 aStartPos.AdjustY(-constTwips_5mm);
99 aEndPos.AdjustX(constTwips_10mm);
100 aEndPos.AdjustY(constTwips_5mm);
101
102 if(!m_pSh->HasDrawView())
104
105 SdrView *pSdrView = m_pSh->GetDrawView();
106 pSdrView->SetDesignMode();
107 m_pSh->BeginCreate(m_pWin->GetSdrDrawMode(), SdrInventor::FmForm, aStartPos);
108 m_pSh->MoveCreate(aEndPos);
109 m_pSh->EndCreate(SdrCreateCmd::ForceEnd);
110}
111
112/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: conform.cxx:37
virtual void Activate(const sal_uInt16 nSlotId) override
Definition: conform.cxx:81
ConstFormControl(SwWrtShell *pSh, SwEditWin *pWin, SwView *pView, SdrObjKind eObjKind)
Definition: conform.cxx:30
SdrObjKind m_eObjKind
Definition: conform.hxx:27
virtual void CreateDefaultObject() override
Definition: conform.cxx:90
bool IsMod2() const
const Point & GetPosPixel() const
bool IsLeft() const
bool IsShift() const
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
void SetCreate1stPointAsCenter(bool bOn)
void SetCurrentObj(SdrObjKind nIdent, SdrInventor nInvent=SdrInventor::Default)
void SetResizeAtCenter(bool bOn)
void SetDesignMode(bool bOn=true)
void SetOrtho(bool bOn)
void SetAngleSnapEnabled(bool bOn)
SdrHitKind PickAnything(const MouseEvent &rMEvt, SdrMouseEventKind nMouseDownOrMoveOrUp, SdrViewEvent &rVEvt) const
virtual void Activate(const sal_uInt16 nSlotId)
Definition: drawbase.cxx:432
SwWrtShell * m_pSh
Definition: drawbase.hxx:36
VclPtr< SwEditWin > m_pWin
Definition: drawbase.hxx:37
virtual bool MouseButtonDown(const MouseEvent &rMEvt)
Definition: drawbase.cxx:62
Point m_aStartPos
Definition: drawbase.hxx:38
bool m_bInsForm
Definition: drawbase.hxx:41
Point GetDefaultCenterPos() const
Definition: drawbase.cxx:546
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
bool BeginCreate(SdrObjKind eSdrObjectKind, const Point &rPos)
Process of creating draw objects.
Definition: feshview.cxx:1666
bool EndCreate(SdrCreateCmd eSdrCreateCmd)
Definition: feshview.cxx:1719
bool IsDrawCreate() const
Definition: feshview.cxx:2108
void MoveCreate(const Point &rPos)
Definition: feshview.cxx:1708
bool HasDrawView() const
Definition: vnew.cxx:371
void MakeDrawView()
Definition: vnew.cxx:376
SdrView * GetDrawView()
Definition: vnew.cxx:386
Definition: view.hxx:146
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
constexpr auto toTwips(N number, Length from)
long Long
constexpr tools::Long constTwips_5mm
Definition: pggrid.cxx:38
SdrHitKind
SdrObjKind
bool g_bNoInterrupt
Definition: swmodule.cxx:115