File: cairoCFerBind_deleteWindow.c

package info (click to toggle)
pyferret 7.6.5-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 138,136 kB
  • sloc: fortran: 240,609; ansic: 25,235; python: 24,026; sh: 1,618; makefile: 1,123; pascal: 569; csh: 307; awk: 18
file content (64 lines) | stat: -rw-r--r-- 2,138 bytes parent folder | download | duplicates (5)
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
/* Python.h should always be first */
#include <Python.h>
#include <cairo/cairo.h>
#include <string.h>
#include "grdel.h"
#include "cferbind.h"
#include "cairoCFerBind.h"
#include "FerMem.h"

/*
 * Deletes (frees) any allocated resources associated with this
 * "Window" (bindings instance), and then deletes (frees) the
 * bindings instance.  After calling this function, this bindings
 * instance should no longer be used.
 *
 * Returns one if successful.   If an error occurs, grdelerrmsg
 * is assigned an appropriate error message and zero is returned.
 */
grdelBool cairoCFerBind_deleteWindow(CFerBind *self)
{
    CairoCFerBindData *instdata;
    CCFBPicture *delpic;

    /* Sanity check */
    if ( (self->enginename != CairoCFerBindName) &&
         (self->enginename != PyQtCairoCFerBindName) ) {
        strcpy(grdelerrmsg, "cairoCFerBind_deleteWindow: unexpected error, "
                            "self is not a valid CFerBind struct");
        return 0;
    }
    instdata = (CairoCFerBindData *) self->instancedata;

    /* Delete any existing context and surface */
    if ( instdata->context != NULL ) {
        /*
         * Explicitly call cairo_show_page before destroying the context.
         * Cairo 1.2 (but not 1.4 or later) requires this call.
         */
        cairo_show_page(instdata->context);
        cairo_destroy(instdata->context);
        instdata->context = NULL;
    }
    if ( instdata->surface != NULL ) {
        /* Explicitly finish the surface just to be safe */
        cairo_surface_finish(instdata->surface);
        cairo_surface_destroy(instdata->surface);
        instdata->surface = NULL;
    }
    /* Delete any stored pictures */
    while ( instdata->firstpic != NULL ) {
        delpic = instdata->firstpic;
        instdata->firstpic = delpic->next;
        cairo_surface_finish(delpic->surface);
        cairo_surface_destroy(delpic->surface);
        FerMem_Free(delpic, __FILE__, __LINE__);
    }
    instdata->lastpic = NULL;

    FerMem_Free(self->instancedata, __FILE__, __LINE__);
    self->instancedata = NULL;
    FerMem_Free(self, __FILE__, __LINE__);
    return 1;
}