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 :
21 : #include "fuconuno.hxx"
22 : #include "tabvwsh.hxx"
23 : #include "sc.hrc"
24 : #include "drawview.hxx"
25 :
26 : /*************************************************************************
27 : |*
28 : |* Konstruktor
29 : |*
30 : \************************************************************************/
31 :
32 0 : FuConstUnoControl::FuConstUnoControl(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
33 : SdrModel* pDoc, SfxRequest& rReq)
34 0 : : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
35 : {
36 0 : SFX_REQUEST_ARG( rReq, pInventorItem, SfxUInt32Item, SID_FM_CONTROL_INVENTOR, false );
37 0 : SFX_REQUEST_ARG( rReq, pIdentifierItem, SfxUInt16Item, SID_FM_CONTROL_IDENTIFIER, false );
38 0 : if( pInventorItem )
39 0 : nInventor = pInventorItem->GetValue();
40 0 : if( pIdentifierItem )
41 0 : nIdentifier = pIdentifierItem->GetValue();
42 0 : }
43 :
44 : /*************************************************************************
45 : |*
46 : |* Destruktor
47 : |*
48 : \************************************************************************/
49 :
50 0 : FuConstUnoControl::~FuConstUnoControl()
51 : {
52 0 : }
53 :
54 : /*************************************************************************
55 : |*
56 : |* MouseButtonDown-event
57 : |*
58 : \************************************************************************/
59 :
60 0 : bool FuConstUnoControl::MouseButtonDown(const MouseEvent& rMEvt)
61 : {
62 : // remember button state for creation of own MouseEvents
63 0 : SetMouseButtonCode(rMEvt.GetButtons());
64 :
65 0 : bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
66 :
67 0 : if ( rMEvt.IsLeft() && !pView->IsAction() )
68 : {
69 0 : Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
70 : // Hack to align object to nearest grid position where object
71 : // would be anchored ( if it were cell anchored )
72 : // Get grid offset for current position ( note: aPnt is
73 : // also adjusted )
74 0 : Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
75 :
76 0 : pWindow->CaptureMouse();
77 0 : pView->BegCreateObj(aPnt);
78 0 : pView->GetCreateObj()->SetGridOffset( aGridOff );
79 0 : bReturn = true;
80 : }
81 0 : return bReturn;
82 : }
83 :
84 : /*************************************************************************
85 : |*
86 : |* MouseMove-event
87 : |*
88 : \************************************************************************/
89 :
90 0 : bool FuConstUnoControl::MouseMove(const MouseEvent& rMEvt)
91 : {
92 0 : return FuConstruct::MouseMove(rMEvt);
93 : }
94 :
95 : /*************************************************************************
96 : |*
97 : |* MouseButtonUp-event
98 : |*
99 : \************************************************************************/
100 :
101 0 : bool FuConstUnoControl::MouseButtonUp(const MouseEvent& rMEvt)
102 : {
103 : // remember button state for creation of own MouseEvents
104 0 : SetMouseButtonCode(rMEvt.GetButtons());
105 :
106 0 : bool bReturn = false;
107 :
108 0 : if ( pView->IsCreateObj() && rMEvt.IsLeft() )
109 : {
110 0 : pView->EndCreateObj(SDRCREATE_FORCEEND);
111 0 : bReturn = true;
112 : }
113 0 : return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
114 : }
115 :
116 : /*************************************************************************
117 : |*
118 : |* Tastaturereignisse bearbeiten
119 : |*
120 : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
121 : |* FALSE.
122 : |*
123 : \************************************************************************/
124 :
125 0 : bool FuConstUnoControl::KeyInput(const KeyEvent& rKEvt)
126 : {
127 0 : return FuConstruct::KeyInput(rKEvt);
128 : }
129 :
130 : /*************************************************************************
131 : |*
132 : |* Function aktivieren
133 : |*
134 : \************************************************************************/
135 :
136 0 : void FuConstUnoControl::Activate()
137 : {
138 0 : pView->SetCurrentObj( nIdentifier, nInventor );
139 :
140 0 : aNewPointer = Pointer( POINTER_DRAW_RECT );
141 0 : aOldPointer = pWindow->GetPointer();
142 0 : pViewShell->SetActivePointer( aNewPointer );
143 :
144 0 : SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_CONTROLS);
145 0 : if (pLayer)
146 0 : pView->SetActiveLayer( pLayer->GetName() );
147 :
148 0 : FuConstruct::Activate();
149 0 : }
150 :
151 : /*************************************************************************
152 : |*
153 : |* Function deaktivieren
154 : |*
155 : \************************************************************************/
156 :
157 0 : void FuConstUnoControl::Deactivate()
158 : {
159 0 : FuConstruct::Deactivate();
160 :
161 0 : SdrLayer* pLayer = pView->GetModel()->GetLayerAdmin().GetLayerPerID(SC_LAYER_FRONT);
162 0 : if (pLayer)
163 0 : pView->SetActiveLayer( pLayer->GetName() );
164 :
165 0 : pViewShell->SetActivePointer( aOldPointer );
166 0 : }
167 :
168 : // Create default drawing objects via keyboard
169 0 : SdrObject* FuConstUnoControl::CreateDefaultObject(const sal_uInt16 /* nID */, const Rectangle& rRectangle)
170 : {
171 : // case SID_FM_CREATE_CONTROL:
172 :
173 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
174 0 : pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
175 0 : 0L, pDrDoc);
176 :
177 0 : if(pObj)
178 : {
179 0 : pObj->SetLogicRect(rRectangle);
180 : }
181 :
182 0 : return pObj;
183 0 : }
184 :
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|