File: pluginsample.cpp

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (84 lines) | stat: -rw-r--r-- 2,881 bytes parent folder | download | duplicates (4)
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
///////////////////////////////////////////////////////////////////////////////
// Name:        tests/drawing/pluginsample.cpp
// Purpose:     Sample plugin for the wxGraphicsContext test
// Author:      Armel Asselin
// Created:     2014-02-21
// Copyright:   (c) 2014 ElliƩ Computing <opensource@elliecomputing.com>
///////////////////////////////////////////////////////////////////////////////

#include "wx/wxprec.h"


// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------

#include "plugin.h"

#if wxUSE_TEST_GC_DRAWING

// ----------------------------------------------------------------------------
// plugin implementation
// ----------------------------------------------------------------------------

class SampleDrawingTestGCFactory: public DrawingTestGCFactory {
public:
    SampleDrawingTestGCFactory() {
        wxImage::AddHandler (new wxBMPHandler());
    }

    virtual ~SampleDrawingTestGCFactory() {
    }
    virtual wxString GetIdForFileName () const wxOVERRIDE { return "sample-plg"; }
    virtual wxString GetExtensionForFileName () const wxOVERRIDE { return "bmp"; }

    // Bitmaps are handled by wx code they should be binarily equal
    virtual bool UseImageComparison() const wxOVERRIDE { return false; }

    // We use wxGraphicsContext, its implementation is not platform independent
    // and returns may slightly vary
    virtual bool PlatformIndependent() const wxOVERRIDE { return false; }

    virtual wxGraphicsContext *BuildNewContext (wxSize expectedSize,
        double WXUNUSED(pointsPerInch), const wxFileName &targetFileName) wxOVERRIDE {
        m_image = new wxImage (expectedSize);
        m_image->InitAlpha();

        m_targetFileName = targetFileName.GetFullPath();

        // we should probably pass the number of points per inches somewhere...
        //  but I don't see where yet...
        return wxGraphicsContext::Create(*m_image);
    }

    // Let's the opportunity to actually save the context and associated data
    // If saving requires deleting the wxGraphicsContext object the
    //  implementer is free to do it but @c gc must then be nulled
    virtual void SaveBuiltContext (wxGraphicsContext *&gc) wxOVERRIDE {
        wxDELETE(gc);

        m_image->SaveFile (m_targetFileName);
    }

    // Cleans @c gc and internal data if any
    virtual void CleanUp (wxGraphicsContext *gc) wxOVERRIDE {
        delete gc;
        m_targetFileName.Empty();
        wxDELETE(m_image);
    }

    wxImage *m_image;
    wxString m_targetFileName;
};

extern "C" WXEXPORT DrawingTestGCFactory * CreateDrawingTestLifeCycle()
{
    return new SampleDrawingTestGCFactory;
}

extern "C" WXEXPORT void DestroyDrawingTestLifeCycle (DrawingTestGCFactory* lc)
{
    delete lc;
}

#endif // wxUSE_TEST_GC_DRAWING