LibreOffice Module sd (master) 1
smarttag.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 <utility>
21#include <vcl/commandevent.hxx>
22
23#include <ViewShell.hxx>
24#include <smarttag.hxx>
25#include <Window.hxx>
26#include <View.hxx>
27
28namespace sd
29{
30
32: mrView( rView )
33, mbSelected( false )
34{
35 SmartTagReference xThis( this );
36 mrView.getSmartTags().add( xThis );
37}
38
40{
41}
42
44{
45 return false;
46}
47
49bool SmartTag::KeyInput( const KeyEvent& /*rKEvt*/ )
50{
51 return false;
52}
53
55bool SmartTag::Command( const CommandEvent& /*rCEvt*/ )
56{
57 return false;
58}
59
60void SmartTag::addCustomHandles( SdrHdlList& /*rHandlerList*/ )
61{
62}
63
65{
66 mbSelected = true;
67}
68
70{
71 mbSelected = false;
72}
73
75{
76 SmartTagReference xThis( this );
77 mrView.getSmartTags().remove( xThis );
78}
79
81{
82 return false;
83}
84
86{
87 return 0;
88}
89
91{
92 return 0;
93}
94
95bool SmartTag::MarkPoint(SdrHdl& /*rHdl*/, bool /*bUnmark*/ )
96{
97 return false;
98}
99
100bool SmartTag::MarkPoints(const ::tools::Rectangle* /*pRect*/, bool /*bUnmark*/ )
101{
102 return false;
103}
104
106{
107}
108
110: mrView( rView )
111{
112}
113
115{
116}
117
119{
120 maSet.insert( xTag );
122
123 if( xTag == mxMouseOverTag )
124 mxMouseOverTag.clear();
125
126 if( xTag == mxSelectedTag )
127 mxSelectedTag.clear();
128}
129
131{
132 std::set< SmartTagReference >::iterator aIter( maSet.find( xTag ) );
133 if( aIter != maSet.end() )
134 maSet.erase( aIter );
136
137 if( xTag == mxMouseOverTag )
138 mxMouseOverTag.clear();
139
140 if( xTag == mxSelectedTag )
141 mxSelectedTag.clear();
142}
143
145{
146 std::set< SmartTagReference > aSet;
147 aSet.swap( maSet );
148 for( auto& rxItem : aSet )
149 rxItem->Dispose();
151 mxMouseOverTag.clear();
152 mxSelectedTag.clear();
153}
154
156{
157 if( mxSelectedTag == xTag )
158 return;
159
160 if( mxSelectedTag.is() )
161 mxSelectedTag->deselect();
162
163 mxSelectedTag = xTag;
164 mxSelectedTag->select();
166 if( mrView.GetMarkedObjectCount() > 0 )
168 else
170}
171
173{
174 if( mxSelectedTag.is() )
175 {
176 mxSelectedTag->deselect();
177 mxSelectedTag.clear();
180 }
181}
182
184{
186 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
187
188 // check if a smart tag is selected and no handle is hit
189 if( mxSelectedTag.is() && !pHdl )
190 {
191 // deselect smart tag
192 deselect();
193 return false;
194 }
195
196 // if a smart tag handle is hit, forward event to its smart tag
197 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
198 if(pSmartHdl && pSmartHdl->getTag().is() )
199 {
200 SmartTagReference xTag( pSmartHdl->getTag() );
201 return xTag->MouseButtonDown( rMEvt, *pSmartHdl );
202 }
203
204 return false;
205}
206
207bool SmartTagSet::KeyInput( const KeyEvent& rKEvt )
208{
209 if( mxSelectedTag.is() )
210 return mxSelectedTag->KeyInput( rKEvt );
211 else if( rKEvt.GetKeyCode().GetCode() == KEY_SPACE )
212 {
213 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( mrView.GetHdlList().GetFocusHdl() );
214 if( pSmartHdl )
215 {
216 const_cast< SdrHdlList& >( mrView.GetHdlList() ).ResetFocusHdl();
217 const SmartTagReference& xTag( pSmartHdl->getTag() );
218 select( xTag );
219 return true;
220 }
221 }
222
223 return false;
224}
225
228{
229 if( rCEvt.IsMouseEvent() )
230 {
232 SdrHdl* pHdl = mrView.PickHandle(aMDPos);
233
234 if( pHdl )
235 {
236 // if a smart tag handle is hit, forward event to its smart tag
237 SmartHdl* pSmartHdl = dynamic_cast< SmartHdl* >( pHdl );
238 if(pSmartHdl && pSmartHdl->getTag().is() )
239 {
240 const SmartTagReference& xTag( pSmartHdl->getTag() );
241 return xTag->Command( rCEvt );
242 }
243 }
244 }
245 else
246 {
247 if( mxSelectedTag.is() )
248 return mxSelectedTag->Command( rCEvt );
249
250 }
251
252 return false;
253}
254
256{
257 for( auto& rxItem : maSet )
258 rxItem->addCustomHandles( rHandlerList );
259}
260
264{
265 if( mxSelectedTag.is() )
266 return mxSelectedTag->getContext( rContext );
267 else
268 return false;
269}
270
271// support point editing
272
274{
275 return GetMarkablePointCount() != 0;
276}
277
279{
280 if( mxSelectedTag.is() )
281 return mxSelectedTag->GetMarkablePointCount();
282 return 0;
283}
284
286{
287 return GetMarkedPointCount() != 0;
288}
289
291{
292 if( mxSelectedTag.is() )
293 return mxSelectedTag->GetMarkedPointCount();
294 else
295 return 0;
296}
297
298bool SmartTagSet::MarkPoint(SdrHdl& rHdl, bool bUnmark )
299{
300 if( mxSelectedTag.is() )
301 return mxSelectedTag->MarkPoint( rHdl, bUnmark );
302
303 return false;
304}
305
306bool SmartTagSet::MarkPoints(const ::tools::Rectangle* pRect, bool bUnmark)
307{
308 if( mxSelectedTag.is() )
309 return mxSelectedTag->MarkPoints( pRect, bUnmark );
310 return false;
311}
312
314{
315 if( mxSelectedTag.is() )
316 mxSelectedTag->CheckPossibilities();
317}
318
319SmartHdl::SmartHdl( SmartTagReference xTag, SdrObject* pObject, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
320: SdrHdl( rPnt, eNewKind )
321, mxSmartTag(std::move( xTag ))
322{
323 SetObj( pObject );
324}
325
326SmartHdl::SmartHdl( SmartTagReference xTag, const Point& rPnt, SdrHdlKind eNewKind /*=SdrHdlKind::Move*/ )
327: SdrHdl( rPnt, eNewKind )
328, mxSmartTag(std::move( xTag ))
329{
330}
331
332} // end of namespace sd
333
334/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorterView & mrView
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
const vcl::KeyCode & GetKeyCode() const
const Point & GetPosPixel() const
SdrHdl * GetFocusHdl() const
void SetObj(SdrObject *pNewObj)
SdrHdl * PickHandle(const Point &rPnt) const
const SdrHdlList & GetHdlList() const
size_t GetMarkedObjectCount() const
void UnmarkAllObj(SdrPageView const *pPV=nullptr)
void InvalidateAllWin()
a derivation from this handle is the visual representation for a smart tag.
Definition: smarttag.hxx:157
SmartHdl(SmartTagReference xTag, SdrObject *pObject, const Point &rPnt, SdrHdlKind eNewKind)
Definition: smarttag.cxx:319
const SmartTagReference & getTag() const
Definition: smarttag.hxx:162
void Dispose()
disposes all smart tags and clears the set
Definition: smarttag.cxx:144
bool MouseButtonDown(const MouseEvent &)
returns true if a SmartTag consumes this event.
Definition: smarttag.cxx:183
bool KeyInput(const KeyEvent &rKEvt)
returns true if a SmartTag consumes this event.
Definition: smarttag.cxx:207
SmartTagReference mxMouseOverTag
Definition: smarttag.hxx:150
bool HasMarkedPoints() const
Definition: smarttag.cxx:285
sal_uLong GetMarkablePointCount() const
Definition: smarttag.cxx:278
bool MarkPoints(const ::tools::Rectangle *pRect, bool bUnmark)
Definition: smarttag.cxx:306
void remove(const SmartTagReference &xTag)
removes the given smart tag from this set
Definition: smarttag.cxx:130
::sd::View & mrView
Definition: smarttag.hxx:148
bool Command(const CommandEvent &rCEvt)
returns true if a SmartTag consumes this event.
Definition: smarttag.cxx:227
void select(const SmartTagReference &xTag)
selects the given smart tag and updates all handles
Definition: smarttag.cxx:155
void CheckPossibilities()
Definition: smarttag.cxx:313
bool HasMarkablePoints() const
Definition: smarttag.cxx:273
void deselect()
deselects the current selected smart tag and updates all handles
Definition: smarttag.cxx:172
bool getContext(SdrViewContext &rContext) const
returns true if the currently selected smart tag has a special context, returned in rContext.
Definition: smarttag.cxx:263
bool MarkPoint(SdrHdl &rHdl, bool bUnmark)
Definition: smarttag.cxx:298
sal_uLong GetMarkedPointCount() const
Definition: smarttag.cxx:290
std::set< SmartTagReference > maSet
Definition: smarttag.hxx:146
SmartTagReference mxSelectedTag
Definition: smarttag.hxx:149
SmartTagSet(::sd::View &rView)
void addCustomHandles(SdrHdlList &rHandlerList)
adds the handles from all smart tags to the given list
Definition: smarttag.cxx:255
void add(const SmartTagReference &xTag)
adds a new smart tag to this set
Definition: smarttag.cxx:118
::sd::View & mrView
Definition: smarttag.hxx:79
virtual void addCustomHandles(SdrHdlList &rHandlerList)
Definition: smarttag.cxx:60
virtual bool KeyInput(const KeyEvent &rKEvt)
returns true if the SmartTag consumes this event.
Definition: smarttag.cxx:49
virtual void select()
Definition: smarttag.cxx:64
bool mbSelected
Definition: smarttag.hxx:80
virtual void deselect()
Definition: smarttag.cxx:69
virtual bool getContext(SdrViewContext &rContext)
Definition: smarttag.cxx:80
virtual bool Command(const CommandEvent &rCEvt)
returns true if the SmartTag consumes this event.
Definition: smarttag.cxx:55
virtual void disposing() override
Definition: smarttag.cxx:74
virtual void CheckPossibilities()
Definition: smarttag.cxx:105
SmartTag(::sd::View &rView)
Definition: smarttag.cxx:31
virtual bool MouseButtonDown(const MouseEvent &, SmartHdl &)
returns true if the SmartTag consumes this event.
Definition: smarttag.cxx:43
virtual bool MarkPoint(SdrHdl &rHdl, bool bUnmark)
Definition: smarttag.cxx:95
virtual sal_Int32 GetMarkedPointCount() const
Definition: smarttag.cxx:90
virtual bool MarkPoints(const ::tools::Rectangle *pRect, bool bUnmark)
Definition: smarttag.cxx:100
virtual ~SmartTag() override
Definition: smarttag.cxx:39
virtual sal_Int32 GetMarkablePointCount() const
Definition: smarttag.cxx:85
::sd::Window * GetActiveWindow() const
The active window is usually the mpContentWindow.
Definition: ViewShell.hxx:155
void SetPossibilitiesDirty()
Definition: View.hxx:240
ViewShell * GetViewShell() const
Definition: View.hxx:144
SmartTagSet & getSmartTags()
Definition: View.hxx:207
void updateHandles()
Definition: sdview.cxx:1122
sal_uInt16 GetCode() const
Point PixelToLogic(const Point &rDevicePt) const
EmbeddedObjectRef * pObject
constexpr sal_uInt16 KEY_SPACE
sal_uIntPtr sal_uLong
SdrHdlKind
SdrViewContext