Click here to Skip to main content
15,884,298 members
Articles / Operating Systems / Windows

WPF Chart Control With Pan, Zoom and More

Rate me:
Please Sign up or sign in to vote.
4.92/5 (42 votes)
10 Dec 2012Public Domain10 min read 386.5K   10.9K   174  
Chart Control for Microsoft .NET 3.0/WPF with pan, zoom, and offline rendering to the clipboard for custom sizes.
// Copyright (c) Microsoft Corporation.  All rights reserved.

namespace  Microsoft { namespace WindowsAPICodePack { namespace DirectX {

#pragma once

/// <summary>
/// An auto pointer style class supporting a simple void pointer
/// Reserved for internal use only.
/// </summary>
template <typename T>
private ref struct AutoPointer
{
internal:
    AutoPointer() : target(0), isDeletable(true), isArray(false)  { }

    void Set(T* ptr)
    {
        Set(ptr, true, false);
    }

    void Set(T* ptr, bool deletable)
    {
        Set(ptr, deletable, false);
    }

    void SetArray(T* ptr, bool deletable)
    {
        Set(ptr, deletable, true);
    }

    T* operator->()
    {
        return target;
    }

    T* Get()
    {
        return target;
    }

protected:
    void Set(T* ptr, bool deletable, bool is_array)
    {
        target = ptr;
        isDeletable = deletable;
        isArray = is_array;

// To debug pointer allc/dealloc, define _DEBUG_AUTO_PTR
#ifdef _DEBUG_AUTO_PTR
        System::Diagnostics::Debug::WriteLine(
            System::String::Format("0x{0:X}\t{1}\t0\t{2}\tDeletable=\t{3}\tArray=\t{4}\tsetting target",
                (int)target,
                System::DateTime::Now.ToString("HH:mm:ss.fff"),
                T::typeid,
                isDeletable?"T":"F",
                isArray?"T":"F"));
#endif    
    }

    virtual void DisposeTarget()
    {

        if (isDeletable && target != 0)
        {
            if (isArray)
                delete [] target;
            else
                delete target;

            target = 0;
        }
    }

    virtual ~AutoPointer()
    {
        AutoPointer::!AutoPointer();
    }
    
    !AutoPointer()
    {
#ifdef _DEBUG_AUTO_PTR
        int targetWas = (int)target;
        System::Diagnostics::Debug::WriteLine(
            System::String::Format("0x{0:X}\t{1}\t1\t{2}\tDeletable=\t{3}\tArray=\t{4}\tdisposing",
                targetWas,
                System::DateTime::Now.ToString("HH:mm:ss.fff"),
                T::typeid,
                isDeletable?"T":"F",
                isArray?"T":"F"));
#endif

        DisposeTarget();

#ifdef _DEBUG_AUTO_PTR
        System::Diagnostics::Debug::WriteLine(
            System::String::Format("0x{0:X}\t{1}\t1\t{2}\tDeletable=\t{3}\tArray=\t{4}\tdone disposing",
                targetWas,
                System::DateTime::Now.ToString("HH:mm:ss.fff"),
                T::typeid,
                isDeletable?"T":"F",
                isArray?"T":"F"));
#endif
    }

protected:
    T* target;
    bool isDeletable;
    bool isArray;

};
} } }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Founder Cheesy Design
Taiwan Taiwan
John graduated from the University of South Australia in 1997 with a Bachelor of Electronic Engineering Degree, and since then he has worked on hardware and software in many fields including Aerospace, Defence, and Medical giving him over 10 of years experience in C++ and C# programming. In 2009 John Started his own contracting company doing business between Taiwan and Australia.

Comments and Discussions