-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathMap_Events.cpp
More file actions
1723 lines (1547 loc) · 46.8 KB
/
Map_Events.cpp
File metadata and controls
1723 lines (1547 loc) · 46.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "stdafx.h"
#include "Map.h"
#include "Measuring.h"
#include "ShapeEditor.h"
#include "Shapefile.h"
#include "ShapefileHelper.h"
#include "SelectionHelper.h"
#include "ShapeStyleHelper.h"
#include "VertexEditor.h"
#include "EditorHelper.h"
#include "Digitizer.h"
#include "Tiles.h"
#include "SelectionListHelper.h"
// ************************************************************
// ParseKeyboardEventFlags
// ************************************************************
long CMapView::ParseKeyboardEventFlags(UINT nFlags)
{
long vbflags = 0;
if (nFlags & MK_SHIFT)
vbflags |= 1;
if (nFlags & MK_CONTROL)
vbflags |= 2;
return vbflags;
}
// ************************************************************
// ParseMouseEventFlags
// ************************************************************
long CMapView::ParseMouseEventFlags(UINT nFlags)
{
long mbutton = 0;
if (nFlags & MK_LBUTTON)
mbutton = 1;
else if (nFlags & MK_RBUTTON)
mbutton = 2;
else if (nFlags & MK_MBUTTON)
mbutton = 3;
return mbutton;
}
#pragma region Keyboard events
// ***************************************************************
// OnKeyUp
// ***************************************************************
void CMapView::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_SPACE:
if (_spacePressed)
{
TurnOffPanning();
_spacePressed = false;
}
break;
}
}
// ***************************************************************
// TurnOffPanning
// ***************************************************************
void CMapView::TurnOffPanning()
{
if (m_cursorMode == cmPan && _lastCursorMode != cmNone)
{
UpdateCursor(_lastCursorMode, false);
_lastCursorMode = cmNone;
if (m_cursorMode == cmMeasure)
{
_measuring->put_Persistent(_measuringPersistent ? VARIANT_TRUE: VARIANT_FALSE);
}
if (!_panningAnimation)
{
// releasing capture for panning operation
ReleaseCapture();
//this is the only mode we care about for this event
_dragging.Start = CPoint(0,0);
_dragging.Move = CPoint(0,0);
this->SetExtentsCore(_extents, false);
}
}
}
// ***************************************************************
// UndoCore
// ***************************************************************
bool CMapView::UndoCore(bool shift)
{
if (EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode))
{
VARIANT_BOOL result = VARIANT_FALSE;
_shapeEditor->UndoPoint(&result);
if (result) {
Redraw2(RedrawSkipAllLayers);
return true;
}
}
if (m_cursorMode == cmMeasure)
{
tkUndoShortcut button;
_measuring->get_UndoButton(&button);
if (button == usCtrlZ)
{
UndoMeasuringPoint();
return true;
}
}
VARIANT_BOOL vb;
if (shift) {
_undoList->Redo(VARIANT_TRUE, &vb);
}
else {
_undoList->Undo(VARIANT_TRUE, &vb);
}
if (vb) {
Redraw2(RedrawSkipDataLayers);
}
return true;
}
// ***************************************************************
// OnKeyDown
// ***************************************************************
void CMapView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
double dx = (this->_extents.right - this->_extents.left)/4.0;
double dy = (this->_extents.top - this->_extents.bottom)/4.0;
CComPtr<IExtents> box = NULL;
bool arrows = nChar == VK_LEFT || nChar == VK_RIGHT || nChar == VK_UP || nChar == VK_DOWN;
if (arrows)
ComHelper::CreateExtents(&box);
bool ctrl = GetKeyState(VK_CONTROL) & 0x8000 ? true: false;
bool shift = GetKeyState(VK_SHIFT) & 0x8000 ? true : false;
switch(nChar)
{
case VK_ESCAPE:
VARIANT_BOOL isEmpty;
_shapeEditor->get_IsEmpty(&isEmpty);
if (!isEmpty)
{
_shapeEditor->ClearCore(false); // first it may be needed to stop overlay operation
Redraw2(tkRedrawType::RedrawAll);
}
break;
case VK_DELETE:
{
if (m_cursorMode == cmEditShape)
{
if (_shapeEditor->HandleDelete()) {
RedrawCore(RedrawSkipDataLayers, true);
}
}
}
break;
case VK_SPACE:
{
bool repetitive = (nFlags & (1 << 14)) ? true : false;
if (!repetitive)
{
if (m_cursorMode != cmPan)
{
// starting panning
if (m_cursorMode == cmMeasure)
{
VARIANT_BOOL vb;
_measuring->get_Persistent(&vb);
_measuringPersistent = vb ? true: false;
_measuring->put_Persistent(VARIANT_TRUE);
}
_lastCursorMode = (tkCursorMode)m_cursorMode;
UpdateCursor(cmPan, false);
}
else
{
TurnOffPanning();
}
}
else
{
_spacePressed = true;
}
}
break;
case 'P':
UpdateCursor(cmPan, false);
break;
case 'Z':
{
if (ctrl) {
if (UndoCore(shift))
return;
}
UpdateCursor(cmZoomIn, false);
}
break;
case 'M':
if (m_cursorMode == cmMeasure)
{
_measuring->Clear();
tkMeasuringType type;
_measuring->get_MeasuringType(&type);
tkMeasuringType newType = type == MeasureArea ? MeasureDistance : MeasureArea;
_measuring->put_MeasuringType(newType);
Redraw2(RedrawSkipDataLayers);
}
else
{
UpdateCursor(cmMeasure, false);
}
break;
case VK_BACK:
ZoomToPrev();
break;
case VK_ADD:
ZoomIn(0.3);
break;
case VK_SUBTRACT:
ZoomOut(0.3);
break;
case VK_MULTIPLY:
int zoom;
_tiles->get_CurrentZoom(&zoom);
ZoomToTileLevel(zoom);
break;
case VK_HOME:
ZoomToMaxExtents();
break;
case VK_LEFT:
if (ctrl) {
// moving to previous layer
_activeLayerPosition--;
if (_activeLayers.size() > 0)
{
if (_activeLayerPosition < 0) {
_activeLayerPosition = _activeLayers.size() - 1;
}
int handle = GetLayerHandle(_activeLayerPosition);
ZoomToLayer(handle);
}
}
else
{
box->SetBounds(_extents.left - dx, _extents.bottom, 0.0, _extents.right - dx, _extents.top, 0.0);
this->SetExtents(box);
}
break;
case VK_RIGHT:
if (ctrl) {
// moving to the next layer
_activeLayerPosition++;
if (_activeLayers.size() > 0)
{
if (_activeLayerPosition >= (int)_activeLayers.size()) {
_activeLayerPosition = 0;
}
int handle = GetLayerHandle(_activeLayerPosition);
ZoomToLayer(handle);
}
}
else
{
box->SetBounds(_extents.left + dx, _extents.bottom, 0.0, _extents.right + dx, _extents.top, 0.0);
this->SetExtents(box);
}
break;
case VK_UP:
box->SetBounds(_extents.left, _extents.bottom + dy, 0.0, _extents.right, _extents.top + dy, 0.0);
this->SetExtents(box);
break;
case VK_DOWN:
box->SetBounds(_extents.left, _extents.bottom - dy, 0.0, _extents.right, _extents.top - dy, 0.0);
this->SetExtents(box);
break;
default:
break;
}
}
#pragma endregion
#pragma region Mouse wheel
// ***************************************************************
// OnMouseWheel()
// ***************************************************************
// Processing mouse wheel event. Amount of zoom is determined by MouseWheelsSpeed parameter
BOOL CMapView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
if (_mouseWheelSpeed < 0.1 || _mouseWheelSpeed > 10) _mouseWheelSpeed = 1;
if (_mouseWheelSpeed == 1) return FALSE;
RECT rect;
double width, height;
double xCent, yCent;
double dx, dy;
// absolute cursor position
this->GetWindowRect(&rect);
if (pt.x < rect.left || pt.x > rect.right || pt.y < rect.top || pt.y > rect.bottom)
return false;
if ((rect.right - rect.left == 0) && (rect.bottom - rect.top == 0))
return false;
if (HasRotation())
{
CPoint curMousePt, origMousePt, rotCentre;
curMousePt.x = pt.x - rect.left;
curMousePt.y = pt.y - rect.top;
rotCentre.x = (rect.right - rect.left) / 2;
rotCentre.y = (rect.bottom - rect.top) / 2;
_rotate->getOriginalPixelPoint(curMousePt.x, curMousePt.y, &(origMousePt.x), &(origMousePt.y));
PixelToProj((double)(origMousePt.x), (double)(origMousePt.y), &xCent, &yCent);
dx = (double)(origMousePt.x) / (double)(rect.right - rect.left);
dy = (double)(origMousePt.y) / (double)(rect.bottom - rect.top);
}
else
{
PixelToProj((double)(pt.x - rect.left), (double)(pt.y - rect.top), &xCent, &yCent);
dx = (double)(pt.x - rect.left) / (rect.right - rect.left);
dy = (double)(pt.y - rect.top) / (rect.bottom - rect.top);
}
// make sure that we have enough momentum to reach the next tile level
double speed = _mouseWheelSpeed;
if (ForceDiscreteZoom()) {
speed = _mouseWheelSpeed > 1 ? 2.001 : 0.499; // add some margin for rounding error and account for reversed wheeling
int zoom = GetCurrentZoom();
int maxZoom, minZoom;
GetMinMaxZoom(minZoom, maxZoom);
if ((zDelta > 0 && zoom + 1 > maxZoom) || (zDelta < 0 && zoom -1 < minZoom)) {
return true;
}
}
// new extents
double ratio = zDelta > 0 ? speed : (1/speed);
height = (_extents.top - _extents.bottom) * ratio;
width = (_extents.right - _extents.left) * ratio;
Extent ext;
ext.left = xCent - width * dx;
ext.right = xCent + width * (1 - dx);
ext.bottom = yCent - height * (1 - dy);
ext.top = yCent + height * dy;
SetExtentsCore(ext);
return true;
}
#pragma endregion
#pragma region Zoombar
// ************************************************************
// HandleOnZoombarMouseDown
// ************************************************************
bool CMapView::HandleOnZoombarMouseDown( CPoint point )
{
if (_zoombarVisible && _transformationMode != tmNotDefined)
{
int minZoom, maxZoom;
GetMinMaxZoom(minZoom, maxZoom);
ZoombarPart part = ZoombarHitTest(point.x, point.y);
switch(part)
{
case ZoombarPart::ZoombarPlus:
{
// zoom in
int zoom = GetCurrentZoom();
if (zoom + 1 <= maxZoom)
{
ZoomToTileLevel(zoom + 1);
}
return true;
}
case ZoombarPart::ZoombarMinus:
{
// zoom out
int zoom = GetCurrentZoom();
if (zoom - 1 >= minZoom )
{
ZoomToTileLevel(zoom - 1);
}
return true;
}
case ZoombarPart::ZoombarHandle:
_dragging.Operation = DragZoombarHandle;
return true;
case ZoombarPart::ZoombarBar:
{
double ratio = _zoombarParts.GetRelativeZoomFromClick(point.y);
int zoom = (int)(minZoom + (maxZoom - minZoom) * ratio + 0.5);
ZoomToTileLevel(zoom);
return true;
}
case ZoombarNone:
default:
return false;
}
}
return false;
}
// ************************************************************
// HandleOnZoombarMouseMove
// ************************************************************
bool CMapView::HandleOnCopyrightMouseMove(CPoint point)
{
BOOL active = _copyrightRect.Contains((Gdiplus::REAL)point.x, (Gdiplus::REAL)point.y);
if (_copyrightLinkActive != active)
{
_copyrightLinkActive = active;
OnSetCursor(this, HTCLIENT, 0);
RedrawCore(tkRedrawType::RedrawSkipAllLayers, true);
return true;
}
return false;
}
// ************************************************************
// HandleCopyrighMouseDown
// ************************************************************
bool CMapView::HandleOnCopyrighMouseDown(CPoint point)
{
BOOL active = _copyrightRect.Contains((Gdiplus::REAL)point.x, (Gdiplus::REAL)point.y);
if (active) {
tkTileProvider provider = GetTileProvider();
if (provider != tkTileProvider::ProviderNone && _transformationMode != tmNotDefined)
{
CComPtr<ITileProviders> providers = NULL;
_tiles->get_Providers(&providers);
CString s = ((CTileProviders*)&(*providers))->get_LicenseUrl(provider);
_copyrightLinkActive = false;
RedrawCore(tkRedrawType::RedrawSkipDataLayers, true);
ShellExecute(0, NULL, s, NULL, NULL, SW_SHOWDEFAULT);
return true;
}
}
return false;
}
// ************************************************************
// HandleOnZoombarMouseMove
// ************************************************************
bool CMapView::HandleOnZoombarMouseMove( CPoint point )
{
if (_dragging.Operation == DragZoombarHandle)
{
RedrawCore(tkRedrawType::RedrawSkipDataLayers, true);
return true;
}
ZoombarPart part = ZoombarHitTest(point.x, point.y);
if (part != _lastZooombarPart)
{
_lastZooombarPart = part; // update before calling OnSetCursor
OnSetCursor(this,HTCLIENT,0);
RedrawCore(RedrawSkipDataLayers, true);
}
return part != ZoombarNone;
}
#pragma endregion
#pragma region Left button
// ************************************************************
// UpdateShapeEditor
// ************************************************************
void CMapView::UpdateShapeEditor()
{
if (_shapeEditor->GetRedrawNeeded(rtVolatileLayer))
RedrawCore(RedrawSkipDataLayers, true);
else if (_shapeEditor->GetRedrawNeeded(rtShapeEditor))
RedrawCore(RedrawSkipAllLayers, true);
}
// ************************************************************
// OnLButtonDown
// ************************************************************
void CMapView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (HasRotation()) {
_rotate->getOriginalPixelPoint(point.x, point.y, &(point.x), &(point.y));
}
_dragging.Start = point;
_dragging.Move = point;
_clickDownExtents = _extents;
_leftButtonDown = TRUE;
_shapeEditor->ClearRedrawFlag();
// process zoombar before everything else; if zoom bar was clicked,
// map must not receive the event at all
if (HandleOnZoombarMouseDown(point) || HandleOnCopyrighMouseDown(point))
return;
bool ctrl = (nFlags & MK_CONTROL) != 0;
bool shift = (nFlags & MK_SHIFT) != 0;
bool alt = GetKeyState(VK_MENU) < 0 ? true : false;
long vbflags = ParseKeyboardEventFlags(nFlags);
long x = point.x;
long y = point.y;
// --------------------------------------------
// Snapping
// --------------------------------------------
double projX;
double projY;
ClearHotTracking();
bool digitizingCursor = EditorHelper::IsDigitizingCursor((tkCursorMode)m_cursorMode);
VARIANT_BOOL snapped = VARIANT_FALSE;
bool snapping = SnappingIsOn(nFlags);
if (snapping)
{
snapped = FindSnapPointCore(point.x, point.y, &projX, &projY);
if (!snapped && shift){
return; // can't proceed in this mode without snapping
}
}
if (!snapped)
this->PixelToProjection(x, y, projX, projY);
// digitizing
if (digitizingCursor)
{
if (m_cursorMode == cmAddShape) {
if (StartNewBoundShape(projX, projY) != VARIANT_TRUE) return;
}
if (alt) { // user wants to intercept coordinates and possibly modify them
this->FireBeforeVertexDigitized(&projX, &projY);
}
if (Digitizer::OnMouseDown(_shapeEditor, projX, projY, ctrl)) {
UpdateShapeEditor();
}
return;
}
// other modes
switch(m_cursorMode)
{
case cmEditShape:
{
if (!VertexEditor::OnMouseDown(this, _shapeEditor, projX, projY, ctrl, shift))
{
long layerHandle, shapeIndex;
if (SelectShapeForEditing(x, y, layerHandle, shapeIndex))
{
VertexEditor::StartEdit(_shapeEditor, layerHandle, shapeIndex);
}
}
UpdateShapeEditor();
}
break;
case cmIdentify:
{
long layerHandle = -1;
long shapeIndex = -1;
bool needRedraw = SelectionListHelper::GetCount(_identifiedShapes) > 0;
if (!ctrl) {
_identifiedShapes->Clear();
}
tkIdentifierMode mode;
_identifier->get_IdentifierMode(&mode);
bool stopOnFirst = mode != tkIdentifierMode::imAllLayers;
if (DrillDownSelect(projX, projY, _identifiedShapes, stopOnFirst, ctrl))
{
long numShapes = SelectionListHelper::GetCount(_identifiedShapes);
if (numShapes == 1)
{
_identifiedShapes->get_LayerHandle(0, &layerHandle);
_identifiedShapes->get_ShapeIndex(0, &shapeIndex);
}
needRedraw = true;
}
if (needRedraw){
FireShapeIdentified(layerHandle, shapeIndex, projX, projY);
RedrawCore(RedrawSkipDataLayers, true);
}
}
break;
case cmRotateShapes:
case cmMoveShapes:
{
HandleOnLButtonMoveOrRotate(x, y);
break;
}
case cmZoomIn:
{
this->SetCapture();
_dragging.Operation = DragZoombox;
}
break;
case cmSelection:
{
this->SetCapture();
_dragging.Operation = DragSelectionBox;
}
break;
case cmZoomOut:
{
ZoomToCursorPosition(false);
break;
}
case cmPan:
{
this->SetCapture();
_dragging.Operation = DragPanning;
}
break;
case cmMeasure:
{
bool added = true;
if (snapping){
GetMeasuringBase()->HandleProjPointAdd(projX, projY);
}
else {
added = GetMeasuringBase()->HandlePointAdd(x, y, ctrl);
}
if (added)
{
FireMeasuringChanged(tkMeasuringAction::PointAdded);
if( m_sendMouseDown ) this->FireMouseDown( MK_LBUTTON, (short)vbflags, x, y );
RedrawCore(RedrawSkipDataLayers, true);
}
}
break;
default: //if( m_cursorMode == cmNone )
{
SetCapture();
if( m_sendMouseDown == TRUE )
this->FireMouseDown(MK_LBUTTON, (short)vbflags, x, y);
}
break;
}
}
// ************************************************************
// OnLButtonDblClick
// ************************************************************
void CMapView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
ZoombarPart part = ZoombarHitTest(point.x, point.y);
if (part != ZoombarPart::ZoombarNone)
return;
if (m_cursorMode == cmMeasure)
{
_measuring->FinishMeasuring();
FireMeasuringChanged(tkMeasuringAction::MeasuringStopped);
Redraw2(RedrawSkipDataLayers);
return;
}
// add a vertex
if (m_cursorMode == cmEditShape)
{
double projX, projY;
this->PixelToProjection(point.x, point.y, projX, projY);
bool alt = GetKeyState(VK_MENU) < 0 ? true : false;
if (alt) { // user wants to intercept coordinates and possibly modify them
this->FireBeforeVertexDigitized(&projX, &projY);
}
if (_shapeEditor->GetClosestPoint(projX, projY, projX, projY))
{
if (_shapeEditor->InsertVertex(projX, projY)) {
RedrawCore(tkRedrawType::RedrawSkipDataLayers, true);
return;
}
}
}
FireDblClick();
}
// ************************************************************
// OnLButtonUp
// ************************************************************
void CMapView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (HasRotation())
_rotate->getOriginalPixelPoint(point.x, point.y, &(point.x), &(point.y));
long vbflags = ParseKeyboardEventFlags(nFlags);
DraggingOperation operation = _dragging.Operation;
ReleaseCapture();
switch(operation)
{
case DragRotateShapes:
{
IShapefile* sf = _dragging.Shapefile;
if (sf)
{
double angle = GetDraggingRotationAngle();
ShapefileHelper::Rotate(sf, _dragging.RotateCenter.x, _dragging.RotateCenter.y, angle);
RegisterGroupOperation(operation);
Redraw();
}
}
break;
case DragMoveShapes:
{
IShapefile* sf = _dragging.Shapefile;
if (sf)
{
Point2D pnt = GetDraggingProjOffset();
VARIANT_BOOL vb;
sf->Move(pnt.x, pnt.y, &vb);
RegisterGroupOperation(operation);
Redraw();
}
}
break;
case DragMoveVertex:
case DragMovePart:
case DragMoveShape:
{
if (HandleLButtonUpDragVertexOrShape(nFlags))
Redraw2(tkRedrawType::RedrawSkipAllLayers);
}
break;
case DragPanning:
{
if (m_cursorMode != cmPan)
CallbackHelper::AssertionFailed("Wrong cursor mode when panning is expected.");
if (!_spacePressed)
DisplayPanningInertia(point);
SetExtentsCore(_extents, false);
LogPrevExtent();
ClearPanningList();
_dragging.Operation = DragNone; // don't clear dragging state until the end of animation; it won't offset the layers
Redraw2(tkRedrawType::RedrawAll);
}
break;
case DragZoombarHandle:
{
ZoomToTileLevel(_zoombarTargetZoom);
_dragging.Operation = DragNone;
}
break;
case DragZoombox:
case DragSelectionBox:
{
HandleLButtonUpZoomBox(vbflags, point.x, point.y);
}
break;
}
_dragging.Clear();
Utility::ClosePointer(&_moveBitmap);
// in case of selection mouse down event will be triggered in this function (to preserve backward compatibility);
// so mouse up should be further on to preserve at least some logic
if (m_sendMouseUp && _leftButtonDown)
FireMouseUp(MK_LBUTTON, (short)vbflags, point.x, point.y);
_leftButtonDown = FALSE;
}
// ************************************************************
// GetSelectionProjTolerance
// ************************************************************
Extent CMapView::GetPointSelectionBox(IShapefile* sf, double xProj, double yProj)
{
Extent box(xProj, xProj, yProj, yProj);
if (!sf) return box;
Extent tol;
ShpfileType shpType = ShapefileHelper::GetShapeType2D(sf);
if (shpType == SHP_POINT)
{
double minVal = 16; // TODO: make parameter
ShapeStyleHelper::GetPointBounds(sf, tol);
// make sure that symbol is large enough
if (minVal - tol.Width() / 2 < minVal)
{
double dx = (minVal - tol.Width() / 2) / 2.0;
tol.left -= dx;
tol.right += dx;
}
if (minVal - tol.Height() / 2 < minVal)
{
double dy = (minVal - tol.Height() / 2) / 2.0;
tol.bottom -= dy;
tol.top += dy;
}
double ratio = this->PixelsPerMapUnit();
tol.left /= ratio;
tol.right /= ratio;
tol.top /= ratio;
tol.bottom /= ratio;
}
else if (shpType == SHP_POLYGON)
{
// empty box
}
else {
double val = GetMouseTolerance(MouseTolerance::ToleranceSelect);
tol.right = tol.top = val;
tol.left = tol.bottom = -val;
}
box.left += tol.left;
box.right += tol.right;
box.top += tol.top;
box.bottom += tol.bottom;
return box;
}
// ************************************************************
// ZoomToCursorPosition
// ************************************************************
void CMapView::ZoomToCursorPosition(bool zoomIn)
{
POINT pt;
GetCursorPos(&pt);
RECT rect;
this->GetWindowRect(&rect);
// if pt is outside of map window, just return
if (pt.x < rect.left || pt.x > rect.right || pt.y < rect.top || pt.y > rect.bottom)
return;
if ((rect.right - rect.left == 0) && (rect.bottom - rect.top == 0))
return;
double xCent, yCent, dx, dy;
// pt is screen position, and we need the position within the map rectangle
PixelToProj((double)(pt.x - rect.left), (double)(pt.y - rect.top), &xCent, &yCent);
// if we are recentering the map...
if (GetRecenterMapOnZoom())
{
// dx and dy represent the mouse position as a percent of the screen;
// since we are centering, set both to 50%
dx = 0.5;
dy = 0.5;
}
else
{
// dx and dy represent the mouse position as a percent of the screen;
// maintain the current screen position as a percent
dx = (double)(pt.x - rect.left) / (rect.right - rect.left);
dy = (double)(pt.y - rect.top) / (rect.bottom - rect.top);
}
double ratio;
if (ForceDiscreteZoom())
{
int zoom = GetCurrentZoom();
int maxZoom, minZoom;
GetMinMaxZoom(minZoom, maxZoom);
if ((zoomIn && zoom + 1 > maxZoom) || (!zoomIn && zoom - 1 < minZoom))
return;
ratio = zoomIn ? 0.499 : 2.001; // add some margin for rounding error
}
else
{
// set zoom-in and zoom-out to be inverse of each other
double factor = 1 + m_zoomPercent;
ratio = zoomIn ? (1 / factor) : factor;
}
double height = (_extents.top - _extents.bottom) * ratio;
double width = (_extents.right - _extents.left) * ratio;
Extent ext;
ext.left = xCent - width * dx;
ext.right = xCent + width * (1 - dx);
ext.bottom = yCent - height * (1 - dy);
ext.top = yCent + height * dy;
SetExtentsCore(ext);
}
// ************************************************************
// HandleLButtonUpZoomBox
// ************************************************************
void CMapView::HandleLButtonUpZoomBox(long vbflags, long x, long y)
{
bool ctrl = vbflags & 2 ? true : false;
long layerHandle = -1;
bool selectingSelectable = false;
CComPtr<IShapefile> sf = NULL;
if (m_cursorMode == cmSelection)
{
tkMwBoolean cancel = blnFalse;
// see if single layer is specified to select
FireChooseLayer(x, y, &layerHandle);
// if none specified, consider all 'selectable' layers
if (layerHandle == -1)
{
// all selectable layers
selectingSelectable = true;
}
else
{
// single layer specified for selection
sf.Attach(GetShapefile(layerHandle));
}
}
_dragging.Operation = DragNone;
if (!_dragging.HasRectangle())
{
// no drag rectangle, mouse click only
switch (m_cursorMode)
{
case cmZoomIn:
ZoomToCursorPosition(true);
break;
case cmSelection:
if (sf || selectingSelectable)
{
double xProj, yProj;
PixelToProjection(x, y, xProj, yProj);
if (sf)
{
// how many are currently selected?
long numSelected;
sf->get_NumSelected(&numSelected);
// single layer select
Extent box = GetPointSelectionBox(sf, xProj, yProj);
if (SelectionHelper::SelectByPoint(sf, box, !ctrl))
{
FireSelectionChanged(layerHandle);
Redraw();
}
else
{
// watch for de-selection
long nowSelected;
sf->get_NumSelected(&nowSelected);
if (nowSelected != numSelected)
{
// we need an event
FireSelectionChanged(layerHandle);
Redraw();
}
}
}
else if (selectingSelectable)
{
// we need to know if at least one layer was marked 'selectable'
bool atLeastOneLayerWasSelectable = false;
// we want to know if at least one layer was selected/deselected
bool atLeastOneLayerAffected = false;
// iterate all layers
for (int layerPosition = 0; layerPosition < GetNumLayers(); layerPosition++)
{
layerHandle = GetLayerHandle(layerPosition);
sf.Attach(GetShapefile(layerHandle));
if (sf)
{