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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24
25 #include <svx/fmglob.hxx>
26 #include <svx/svdview.hxx>
27 #include <svx/fmshell.hxx>
28
29 #include "view.hxx"
30 #include "edtwin.hxx"
31 #include "wrtsh.hxx"
32 #include "drawbase.hxx"
33 #include "conform.hxx"
34
35 extern sal_Bool bNoInterrupt; // in mainwn.cxx
36
37 /*************************************************************************
38 |* C'Tor
39 \************************************************************************/
40
ConstFormControl(SwWrtShell * pWrtShell,SwEditWin * pEditWin,SwView * pSwView)41 ConstFormControl::ConstFormControl(SwWrtShell* pWrtShell, SwEditWin* pEditWin, SwView* pSwView) :
42 SwDrawBase(pWrtShell, pEditWin, pSwView)
43 {
44 m_bInsForm = sal_True;
45 }
46
47 /*************************************************************************
48 |* MouseButtonDown-event
49 \************************************************************************/
50
MouseButtonDown(const MouseEvent & rMEvt)51 sal_Bool ConstFormControl::MouseButtonDown(const MouseEvent& rMEvt)
52 {
53 sal_Bool bReturn = sal_False;
54
55 SdrView *pSdrView = m_pSh->GetDrawView();
56
57 pSdrView->SetOrtho(rMEvt.IsShift());
58 pSdrView->SetAngleSnapEnabled(rMEvt.IsShift());
59
60 if (rMEvt.IsMod2())
61 {
62 pSdrView->SetCreate1stPointAsCenter(sal_True);
63 pSdrView->SetResizeAtCenter(sal_True);
64 }
65 else
66 {
67 pSdrView->SetCreate1stPointAsCenter(sal_False);
68 pSdrView->SetResizeAtCenter(sal_False);
69 }
70
71 SdrViewEvent aVEvt;
72 SdrHitKind eHit = pSdrView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
73
74 // Nur neues Objekt, wenn nicht im Basismode (bzw reinem Selektionsmode)
75 if (rMEvt.IsLeft() && !m_pWin->IsDrawAction() &&
76 (eHit == SDRHIT_UNMARKEDOBJECT || eHit == SDRHIT_NONE || m_pSh->IsDrawCreate()))
77 {
78 bNoInterrupt = sal_True;
79 m_pWin->CaptureMouse();
80
81 m_pWin->SetPointer(Pointer(POINTER_DRAW_RECT));
82
83 m_aStartPos = m_pWin->PixelToLogic(rMEvt.GetPosPixel());
84 bReturn = m_pSh->BeginCreate( static_cast< sal_uInt16 >(m_pWin->GetSdrDrawMode()), FmFormInventor, m_aStartPos);
85
86 if (bReturn)
87 m_pWin->SetDrawAction(sal_True);
88 }
89 else
90 bReturn = SwDrawBase::MouseButtonDown(rMEvt);
91
92 return (bReturn);
93 }
94
95 /*************************************************************************
96 |* activate function
97 \************************************************************************/
98
Activate(const sal_uInt16 nSlotId)99 void ConstFormControl::Activate(const sal_uInt16 nSlotId)
100 {
101 m_pWin->SetSdrDrawMode( static_cast<SdrObjKind>(nSlotId) );
102 SwDrawBase::Activate(nSlotId);
103 m_pSh->GetDrawView()->SetCurrentObj(nSlotId);
104
105 m_pWin->SetPointer(Pointer(POINTER_DRAW_RECT));
106 }
107
CreateDefaultObject()108 void ConstFormControl::CreateDefaultObject()
109 {
110 Point aStartPos(GetDefaultCenterPos());
111 Point aEndPos(aStartPos);
112 aStartPos.X() -= 2 * MM50;
113 aStartPos.Y() -= MM50;
114 aEndPos.X() += 2 * MM50;
115 aEndPos.Y() += MM50;
116
117 if(!m_pSh->HasDrawView())
118 m_pSh->MakeDrawView();
119
120 SdrView *pSdrView = m_pSh->GetDrawView();
121 pSdrView->SetDesignMode(sal_True);
122 m_pSh->BeginCreate( static_cast< sal_uInt16 >(m_pWin->GetSdrDrawMode()), FmFormInventor, aStartPos);
123 m_pSh->MoveCreate(aEndPos);
124 m_pSh->EndCreate(SDRCREATE_FORCEEND);
125 }
126
127 /* vim: set noet sw=4 ts=4: */
128