File: ZoomView.cpp

package info (click to toggle)
paintlib 2.6.2-14
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,920 kB
  • ctags: 3,874
  • sloc: cpp: 25,209; sh: 10,605; ansic: 1,891; makefile: 120
file content (728 lines) | stat: -rw-r--r-- 23,130 bytes parent folder | download | duplicates (3)
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
// zoomview.cpp : Implements Zooming functions in a CScrollView window
//
// Written by Brad Pirtle, CS:72450,1156, Internet:pirtle@qlogic.com
// Copyright 1994, QuickLogic Corp., all rights reserved.
// Version 1.0

#include "stdafx.h"
#include "zoomview.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CZoomView, CScrollView)
    //{{AFX_MSG_MAP(CZoomView)
    ON_WM_LBUTTONDOWN()
    ON_WM_LBUTTONUP()
    ON_WM_MOUSEMOVE()
    ON_WM_RBUTTONDOWN()
    ON_WM_SETCURSOR()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

#define MAXZOOMIN    4        // Maximum zoom-in factor
#define PICKMARGIN  10        // Screen pixels apart for region zoom

/////////////////////////////////////////////////////////////////////////////
// CZoomView
IMPLEMENT_DYNCREATE(CZoomView, CScrollView)

/*---------------------------------------------------------------------------
   FUNCTION: CZoomView
   PURPOSE : Constructor for the CZoomView class
---------------------------------------------------------------------------*/
CZoomView::CZoomView()
        : CScrollView()
{
    // Init zoom mode to nothing
    m_zoomMode    = MODE_ZOOMOFF;
    m_bCaptured   = false;
    m_zoomScale   = 1.0;
    m_ptDragRect.SetRectEmpty();

    // Load the zoom cursor
    m_hZoomCursor = ::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDC_ZOOMCURSOR));

    // Default to centering on full fit
    m_bCenter = true;
} // CZoomView

/*---------------------------------------------------------------------------
   FUNCTION: ~CZoomView
   PURPOSE : Destructor for the CZoomView class
---------------------------------------------------------------------------*/
CZoomView::~CZoomView()
{
    // Clean up the cursors if they were loaded properly
    if (m_hZoomCursor) DestroyCursor(m_hZoomCursor);
} // ~CZoomView

/////////////////////////////////////////////////////////////////////////////
// CZoomView overridden default CScrollView members
/////////////////////////////////////////////////////////////////////////////

/*---------------------------------------------------------------------------
   FUNCTION: SetZoomSizes
   PURPOSE : Set up the CZoomView class with the logical page size, and
         scrolling page/line units.
         This replaces CScrollView::SetScrollSizes.
---------------------------------------------------------------------------*/
void CZoomView::SetZoomSizes (
    SIZE sizeTotal,
    const SIZE& sizePage, // in logical units
    const SIZE& sizeLine) // in logical units
{
    // Set up the defaults
    ASSERT(sizeTotal.cx >= 0 && sizeTotal.cy >= 0);
    m_nMapMode    = MM_ANISOTROPIC; // Need for arbitrary scaling
    m_totalLog    = sizeTotal;
    // Setup default Viewport extent to be conversion of Window extent
    // into device units.
    //BLOCK for DC
    {
        CWindowDC dc(NULL);
        dc.SetMapMode(m_nMapMode);

        // total size
        m_totalDev = m_totalLog;
        dc.LPtoDP((LPPOINT)&m_totalDev);
    } // Release DC here

    // Save the original Viewport Extent
    m_origTotalDev = m_totalDev;
    // Save the original scrollbar info - for CalcBars
    m_origPageDev = sizePage;
    m_origLineDev = sizeLine;
    // Fugure out scroll bar info
    CalcBars();
    // Notify the class that the zoom scale was set
    NotifyZoom();
} // SetZoomSizes

/*---------------------------------------------------------------------------
   FUNCTION: OnPrepareDC
   PURPOSE : Override of CScrollView for MM_ANISOTROPIC zoom mode
---------------------------------------------------------------------------*/
void CZoomView::OnPrepareDC (
    CDC* pDC,
    CPrintInfo* pInfo)
{
#ifdef _DEBUG
    if (m_nMapMode != MM_ANISOTROPIC) {
        TRACE0("Error: must call SetZoomSizes() before painting zoom view\n");
        // ASSERT(false);
        return;
    }
#endif //_DEBUG

    ASSERT_VALID(pDC);
    ASSERT(m_totalLog.cx >= 0 && m_totalLog.cy >= 0);
    ASSERT(m_totalDev.cx >= 0 && m_totalDev.cx >= 0);
    // Set the Mapping mode, and the window and viewport extents
    pDC->SetMapMode(m_nMapMode);
    pDC->SetWindowExt(m_totalLog);   // in logical coordinates
    CPoint ptVpOrg;

    if (!pDC->IsPrinting()) {
        pDC->SetViewportExt(m_totalDev); // in device coordinates

        // by default shift viewport origin in negative direction of scroll
        ASSERT(pDC->GetWindowOrg() == CPoint(0,0));
        ptVpOrg = -GetDeviceScrollPosition();

        // Center full fit
        if (m_bCenter) {
            CRect rect;
            GetClientRect(&rect);

            // if client area is larger than total device size,
            // override scroll positions to place origin such that
            // output is centered in the window
            if (m_totalDev.cx < rect.Width())
                ptVpOrg.x = (rect.Width() - m_totalDev.cx) / 2;
            if (m_totalDev.cy < rect.Height())
                ptVpOrg.y = (rect.Height() - m_totalDev.cy) / 2;
        }
    } else {
        // Special case for printing
        CSize  printSize;
        printSize.cx = pDC->GetDeviceCaps(HORZRES);
        printSize.cy = pDC->GetDeviceCaps(VERTRES);
        // Maintain the original ratio, setup origin shift
        PersistRatio(m_totalLog, printSize, ptVpOrg);
        // Zoom completely out
        pDC->SetViewportExt(printSize);
    }
    // Set the new origin
    pDC->SetViewportOrg(ptVpOrg);
    // For default Printing behavior
    CView::OnPrepareDC(pDC, pInfo);
} // OnPrepareDC

/*---------------------------------------------------------------------------
   FUNCTION: CalcBars
   PURPOSE : Update the scrollbars - uses logical units
         Call when the Viewport changes size.
---------------------------------------------------------------------------*/
void CZoomView::CalcBars (void)
{
    { // BLOCK for DC
        CWindowDC dc(NULL);
        dc.SetMapMode(m_nMapMode);

        // Calculate new device units for scrollbar
        // Start with original logical units from SetScrollPos
        m_pageDev = m_origPageDev;
        dc.LPtoDP((LPPOINT)&m_pageDev);
        m_lineDev = m_origLineDev;
        dc.LPtoDP((LPPOINT)&m_lineDev);
    } // Free DC

    // Make sure of the range
    if (m_pageDev.cy < 0)  m_pageDev.cy = -m_pageDev.cy;
    if (m_lineDev.cy < 0)  m_lineDev.cy = -m_lineDev.cy;

    // If none specified - use one tenth
    ASSERT(m_totalDev.cx >= 0 && m_totalDev.cy >= 0);
    if (m_pageDev.cx == 0) m_pageDev.cx = m_totalDev.cx / 10;
    if (m_pageDev.cy == 0) m_pageDev.cy = m_totalDev.cy / 10;
    if (m_lineDev.cx == 0) m_lineDev.cx = m_pageDev.cx  / 10;
    if (m_lineDev.cy == 0) m_lineDev.cy = m_pageDev.cy  / 10;

    // Now update the scrollbars
    if (m_hWnd != NULL) {
        UpdateBars();
        Invalidate(true); // Zoom scale changed, redraw all
    }
} // CalcBars

/*---------------------------------------------------------------------------
   FUNCTION: AssertValid
   PURPOSE : Make sure valid class
---------------------------------------------------------------------------*/
#ifdef _DEBUG
void CZoomView::AssertValid() const
{
    // Bypass CScrollView because of MM_ANISOTROPIC map mode
    CView::AssertValid();
} // AssertValid
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CZoomView custom members to implement zooming functionality
/////////////////////////////////////////////////////////////////////////////

/*---------------------------------------------------------------------------
   FUNCTION: DoZoomIn
   PURPOSE : Zoom the view in on a rect
---------------------------------------------------------------------------*/
int  CZoomView::DoZoomIn (
    CRect &rect)   // rect in logical coordinates
{
    ASSERT(m_nMapMode == MM_ANISOTROPIC);

    // Make sure that the rect is normalized
    CRect zoomRect = rect;
    NormalizeRect(zoomRect);

    // Get the center of rect
    CPoint ptCenter;
    ptCenter.x = ((zoomRect.left + zoomRect.right)  / 2);
    ptCenter.y = ((zoomRect.top  + zoomRect.bottom) / 2);

    // See if the rect is small enough for a point zoom (Device coordinates)
    CRect rectDP = zoomRect;
    ViewLPtoDP((LPPOINT)&rectDP, 2);
    bool bPointZoom = (max(rectDP.Width(), rectDP.Height()) < PICKMARGIN);
    if (bPointZoom) {
        // Just do normal point zoom
        return DoZoomIn(&ptCenter);
    }

    CRect clientRect;
    GetClientRect(&clientRect);

    // Calculate the new zoom scale.
    double scaleH = (double) (clientRect.right  + 1) / (double) zoomRect.Width();
    double scaleV = (double) (clientRect.bottom + 1) / (double) zoomRect.Height();

    double zoomBackup = m_zoomScale;

    // Keep the scale Isotropic
    m_zoomScale = min(scaleH, scaleV);

    // Maximum size reached?
    if(m_zoomScale > 80)
    {
      m_zoomScale = zoomBackup;
      return true;
    }

    // Modify the Viewport extent
    m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
    m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
    CalcBars();

    // Set the current center point.
    CenterOnLogicalPoint(ptCenter);
    // Notify the class that a new zoom scale was done
    NotifyZoom();
    return true;
} // DoZoomIn (Rect)

/*---------------------------------------------------------------------------
   FUNCTION: DoZoomIn
   PURPOSE : Zoom the view in on a point by the specified scale factor
---------------------------------------------------------------------------*/
int  CZoomView::DoZoomIn (
    CPoint *point,   // point in logical coordinates
    double  delta)    // scale factor
{
    CPoint ptCenter;

    ASSERT(m_nMapMode == MM_ANISOTROPIC);
    // Save the current center point.
    if (!point) {
        ptCenter = GetLogicalCenterPoint();
    } else {
        ptCenter = *point;
    }

    // Increase the zoom scale.
    m_zoomScale *= delta;

    // Maximum size reached?
    if(m_zoomScale > 80)
     {
      m_zoomScale /= delta;
      return true;
     }

    // Modify the Viewport extent
    m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
    m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
    CalcBars();
    // Set the current center point.
    CenterOnLogicalPoint(ptCenter);
    // Notify the class that a new zoom scale was done
    NotifyZoom();
    return true;
} // DoZoomIn (Pt)

/*---------------------------------------------------------------------------
   FUNCTION: DoZoomOut
   PURPOSE : Zoom the view out on a point by one scale factor
---------------------------------------------------------------------------*/
int  CZoomView::DoZoomOut (
    CPoint *point,   // point in logical coordinates
    double  delta)    // scale factor
{
    CPoint ptCenter;

    ASSERT(m_nMapMode == MM_ANISOTROPIC);
    // Save the current center point.
    if (!point) {
        ptCenter = GetLogicalCenterPoint();
    } else {
        ptCenter = *point;
    }

    // Decrease the zoom scale.
    m_zoomScale /= delta;

    // Modify the Viewport extent
    m_totalDev.cx = (int) ((double) m_origTotalDev.cx * m_zoomScale);
    m_totalDev.cy = (int) ((double) m_origTotalDev.cy * m_zoomScale);
    CalcBars();
    // Set the current center point (logical coordinates.
    CenterOnLogicalPoint(ptCenter);
    // Notify the class that a new zoom scale was done
    NotifyZoom();
    return true;
} // DoZoomOut

/*---------------------------------------------------------------------------
   FUNCTION: DoZoomFull
   PURPOSE : Zoom the view to full state
---------------------------------------------------------------------------*/
int  CZoomView::DoZoomFull (void)
{
    ASSERT(m_nMapMode == MM_ANISOTROPIC);
    CRect  rc;
    CPoint pt;
    CSize  sizeSb;
    // Just set Viewport Extent to Client size for full fit
    GetTrueClientSize(m_totalDev, sizeSb);
    // Maintain original ratio
    PersistRatio(m_totalLog, m_totalDev, pt);
    // Set the new zoom scale (could use cx or cy)
    m_zoomScale = (double) m_totalDev.cx / m_origTotalDev.cx;
    // Remove the scrollbars
    UpdateBars();
    // Complete redraw
    Invalidate(true);
    // Notify the class that a new zoom scale was done
    NotifyZoom();
    return true;
} // DoZoomInFull

/*---------------------------------------------------------------------------
   FUNCTION: SetZoomMode
   PURPOSE : Put the view into the specified zoom mode
---------------------------------------------------------------------------*/
void CZoomView::SetZoomMode (
    ZoomMode_ zoomMode)
{
    ASSERT(m_nMapMode == MM_ANISOTROPIC);
    if (zoomMode != m_zoomMode) {
        m_zoomMode = zoomMode;
        // Force cursor change now
        OnSetCursor(NULL, HTCLIENT, 0);
    }
} // SetZoomMode


/*---------------------------------------------------------------------------
   FUNCTION: CenterOnLogicalPoint
   PURPOSE : Same as CScrollView::CenterOnPoint, but for logical coordinates
---------------------------------------------------------------------------*/
void CZoomView::CenterOnLogicalPoint(CPoint pt)
{
    // Convert the point to device coordinates
    ViewLPtoDP(&pt);
    // Account for scroll bar position
    ClientToDevice(pt);
    // Use CScrollView's function for device coordinates
    CScrollView::CenterOnPoint(pt);
} // CenterOnLogicalPoint

/*---------------------------------------------------------------------------
   FUNCTION: GetLogicalCenterPoint
   PURPOSE : Get the center of screen in logical coordinates
---------------------------------------------------------------------------*/
CPoint CZoomView::GetLogicalCenterPoint (void)  // Point in logical units
{
    CPoint pt;
    CRect rect;
    // Get the center of screen
    GetClientRect(&rect);
    pt.x = (rect.Width()  / 2);
    pt.y = (rect.Height() / 2);

    // Convert the point to logical coordinates
    ViewDPtoLP(&pt);
    return pt;
} // GetLogicalCenterPoint

/*---------------------------------------------------------------------------
   FUNCTION: DrawBox
   PURPOSE : Draw a box - XOR if want to erase
---------------------------------------------------------------------------*/
void CZoomView::DrawBox (
    CDC   &dc,
    CRect &rect,
    bool  xor)
{
    CPen pen;
    // Save the device context
    dc.SaveDC();
    if (xor) {
        dc.SetROP2(R2_NOTXORPEN);
        pen.CreatePen(PS_DASH,  0, RGB(0, 0, 0)); // 0 width = 1 device unit
    } else {
        pen.CreatePen(PS_SOLID, 0, RGB(0, 0, 0)); // 0 width = 1 device unit
    }
    dc.SelectObject(&pen);
    // Draw the rect with lines (eliminate rect middle fill)
    dc.MoveTo(rect.left,  rect.top);
    dc.LineTo(rect.right, rect.top);
    dc.LineTo(rect.right, rect.bottom);
    dc.LineTo(rect.left,  rect.bottom);
    dc.LineTo(rect.left,  rect.top);
    // Clean up
    dc.RestoreDC(-1);
} // DrawBox

/*---------------------------------------------------------------------------
   FUNCTION: DrawLine
   PURPOSE : Draw a line - XOR to erase
---------------------------------------------------------------------------*/
void CZoomView::DrawLine (
    CDC &dc,
    const int &x1, // Logical units
    const int &y1,
    const int &x2,
    const int &y2,
    bool      xor)
{
    CPen pen;
    // Save the device context
    dc.SaveDC();
    if (xor) {
        dc.SetROP2(R2_NOTXORPEN);
        pen.CreatePen(PS_DASH,  0, RGB(0, 0, 0)); // 0 width = 1 device unit
    } else {
        pen.CreatePen(PS_SOLID, 0, RGB(0, 0, 0)); // 0 width = 1 device unit
    }
    dc.SelectObject(&pen);

    // Draw the line
    dc.MoveTo(x1, y1);
    dc.LineTo(x2, y2);
    // Clean up
    dc.RestoreDC(-1);
} // DrawLine

/*---------------------------------------------------------------------------
   FUNCTION: OnLButtonDown
   PURPOSE : Handle the left mouse click
---------------------------------------------------------------------------*/
void CZoomView::OnLButtonDown(
    UINT nFlags,
    CPoint point)
{
    // Pass the message along
    CScrollView::OnLButtonDown(nFlags, point);

    switch (m_zoomMode) {
    case MODE_ZOOMIN:
        // Capture the mouse for zooming in
        m_bCaptured = true;
        SetCapture();
        // Save the mouse down point for XOR rect
        ViewDPtoLP(&point);
        m_ptDragRect.SetRect(point.x, point.y, point.x, point.y);
        // Set the cursor to the cross hair
        ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_CROSS)));
        break;

    default:
        // Do nothing.
        break;
    }
} // OnLButtonDown

/*---------------------------------------------------------------------------
   FUNCTION: OnMouseMove
   PURPOSE : Handle the mouse movement
---------------------------------------------------------------------------*/
void CZoomView::OnMouseMove(UINT nFlags, CPoint point)
{
    // Pass the message along
    CScrollView::OnMouseMove(nFlags, point);

    if (m_bCaptured) {
        // Get the Device Context
        CClientDC dc(this);
        OnPrepareDC(&dc);

        switch (m_zoomMode) {
        case MODE_ZOOMIN:
            // Draw the drag-rect
            // Erase last rect
            DrawBox(dc, m_ptDragRect);
            // Draw new rect
            dc.DPtoLP(&point);
            m_ptDragRect.BottomRight() = point;
            DrawBox(dc, m_ptDragRect);
            break;

        default:
            // Do nothing.
            break;
        }
    }
} // OnMouseMove

/*---------------------------------------------------------------------------
   FUNCTION: OnLButtonUp
   PURPOSE : Handle the left mouse release
---------------------------------------------------------------------------*/
void CZoomView::OnLButtonUp (
    UINT nFlags,
    CPoint point)
{
    // Pass the message along
    CScrollView::OnLButtonUp(nFlags, point);

    switch (m_zoomMode) {
    case MODE_ZOOMIN:
        // Uncapture the mouse?
        if (m_bCaptured) {
            m_bCaptured = false;
            ReleaseCapture();
            // Set back the cross cursor to the Z
            ::SetCursor(m_hZoomCursor);
            // Get the Device Context
            CClientDC dc(this);
            OnPrepareDC(&dc);
            // Erase the bounding box
            DrawBox(dc, m_ptDragRect);
            // Now Zoom in on logical rectangle
            DoZoomIn(m_ptDragRect);
        }
        break;

    case MODE_ZOOMOUT:
        ViewDPtoLP(&point);
        DoZoomOut(&point);
        break;

    default:
        // Do nothing.
        break;
    }
} // OnLButtonUp

/*---------------------------------------------------------------------------
   FUNCTION: OnRButtonDown
   PURPOSE : Handle the right mouse click - CANCELS CURRENT ZOOM MODE OR DRAG
---------------------------------------------------------------------------*/
void CZoomView::OnRButtonDown(UINT nFlags, CPoint point)
{
    CScrollView::OnRButtonDown(nFlags, point);

    // See if currently captured
    if (m_bCaptured) {
        // Maintain current mode, just stop current drag
        m_bCaptured = false;
        ReleaseCapture();
        // Get the Device Context
        CClientDC dc(this);
        OnPrepareDC(&dc);

        switch (m_zoomMode) {
        case MODE_ZOOMIN:
            // Erase last rect
            DrawBox(dc, m_ptDragRect);
            break;

        default:
            // Do nothing.
            break;
        }
    } else {
        // Cancel current mode
        m_zoomMode = MODE_ZOOMOFF;
    }
} // OnRButtonDown

/*---------------------------------------------------------------------------
   FUNCTION: OnSetCursor
   PURPOSE : Set the cursor depending on the zoom mode
---------------------------------------------------------------------------*/
BOOL CZoomView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    if (nHitTest != HTCLIENT)
        return CScrollView::OnSetCursor(pWnd, nHitTest, message);

    switch (m_zoomMode) {
    case MODE_ZOOMOFF:
        ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
        break;

    default:
        // All other zoom modes
        ::SetCursor(m_hZoomCursor);
        break;
    } // Zoom mode select

    return true;
} // OnSetCursor

/*---------------------------------------------------------------------------
   FUNCTION: ViewDPtoLP
   PURPOSE : Same as DPtoLP, but gets the Client DC for the view
---------------------------------------------------------------------------*/
void CZoomView::ViewDPtoLP (
    LPPOINT lpPoints,
    int     nCount)
{
    // Convert to logical units
    // Called from View when no DC is available
    ASSERT(m_nMapMode > 0); // must be set
    CWindowDC dc(this);
    OnPrepareDC(&dc);
    dc.DPtoLP(lpPoints, nCount);
} // ViewDPtoLP

/*---------------------------------------------------------------------------
   FUNCTION: ViewLPtoDP
   PURPOSE : Same as LPtoDP, but gets the Client DC for the view
---------------------------------------------------------------------------*/
void CZoomView::ViewLPtoDP (
    LPPOINT lpPoints,
    int     nCount)
{
    // Convert to logical units
    // Called from View when no DC is available
    ASSERT(m_nMapMode > 0); // must be set
    CWindowDC dc(this);
    OnPrepareDC(&dc);
    dc.LPtoDP(lpPoints, nCount);
} // ViewLPtoDP

/*---------------------------------------------------------------------------
   FUNCTION: ClientToDevice
   PURPOSE : Convert from Client coordinates to relative Device coordinates
---------------------------------------------------------------------------*/
void CZoomView::ClientToDevice (
    CPoint &point)
{
    // Need to account for scrollbar position
    CPoint scrollPt = GetDeviceScrollPosition();
    point.x += scrollPt.x;
    point.y += scrollPt.y;
} // ClientToDevice

/*---------------------------------------------------------------------------
   FUNCTION: NormalizeRect
   PURPOSE : Normalize the rectangle
---------------------------------------------------------------------------*/
void CZoomView::NormalizeRect (
    CRect &rect)
{
    if (rect.left > rect.right) {
        int r = rect.right;
        rect.right = rect.left;
        rect.left = r;
    }
    if (rect.top > rect.bottom) {
        int b = rect.bottom;
        rect.bottom = rect.top;
        rect.top = b;
    }
} // NormalizeRect

/*---------------------------------------------------------------------------
   FUNCTION: PersistRatio
   PURPOSE : Make a CSize maintain the given ratio (by shrinking if nescessary)
---------------------------------------------------------------------------*/
void CZoomView::PersistRatio (
    const CSize &orig,
    CSize       &dest,
    CPoint      &remainder)
{
    double ratio1 = (double) orig.cx / orig.cy;
    double ratio2 = (double) dest.cx / dest.cy;
    int   newSize;

    // Do nothing if they are the same
    if (ratio1 > ratio2) {
        // Shrink hieght
        newSize = (int)(dest.cx / ratio1);
        remainder.x = 0;
        remainder.y = dest.cy - newSize;
        dest.cy = newSize;
    } else if (ratio2 > ratio1) {
        // Shrink width
        newSize = (int)(dest.cy * ratio1);
        remainder.x = dest.cx - newSize;
        remainder.y = 0;
        dest.cx = newSize;
    }
} // PersistRatio