File: e_cback.cpp

package info (click to toggle)
libwx-perl 1%3A0.9932-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,300 kB
  • sloc: cpp: 11,064; perl: 8,603; ansic: 711; makefile: 53
file content (111 lines) | stat: -rw-r--r-- 2,922 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
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
/////////////////////////////////////////////////////////////////////////////
// Name:        cpp/e_cback.cpp
// Purpose:     implementation for e_cback.h
// Author:      Mattia Barbon
// Modified by:
// Created:     29/10/2000
// RCS-ID:      $Id: e_cback.cpp 3374 2012-09-26 11:37:03Z mdootson $
// Copyright:   (c) 2000-2002, 2004-2008 Mattia Barbon
// Licence:     This program is free software; you can redistribute it and/or
//              modify it under the same terms as Perl itself
/////////////////////////////////////////////////////////////////////////////

wxPliEventCallback::wxPliEventCallback( SV* method, SV* self ) 
{
    dTHX;
    m_method = method;
    SvREFCNT_inc( m_method );
    m_self = self;
    SvREFCNT_inc( m_self );
    m_is_method = !SvROK( m_method ) || !SvRV( m_method );
}

wxPliEventCallback::~wxPliEventCallback() 
{
    dTHX;
    SvREFCNT_dec( m_method );
    SvREFCNT_dec( m_self );
}

void wxPliEventCallback::Handler( wxEvent& event ) 
{
    wxPliEventCallback* This = (wxPliEventCallback*) event.m_callbackUserData;

    dTHX;
    dSP;

    ENTER;
    SAVETMPS;

    {
        // similar to wxPli_object_2_sv
        wxPliGuard guard;
        SV* e = 0;
        SV* rv = 0;
        wxClassInfo *ci = event.GetClassInfo();
        const wxChar* classname = ci->GetClassName();

#if wxUSE_UNICODE
        if( wcsncmp( classname, wxT("wxPl"), 4 ) == 0 ) 
#else
        if( strnEQ( classname, "wxPl", 4 ) ) 
#endif
        {
            wxPliClassInfo* cci = (wxPliClassInfo*)ci;
            wxPliSelfRef* sr = cci->m_func( &event );
        
            if( sr )
            {
                // this needs to have the refcount incremented, otherwise
                // the refcount will be decremented one time too much when
                // exiting from the handler
                e = sv_2mortal( newRV_inc( SvRV( sr->m_self ) ) );
            }
        }

        if( !e )
        {
            char buffer[WXPL_BUF_SIZE];
            const char* CLASS = wxPli_cpp_class_2_perl( classname, buffer );

            e = sv_newmortal();
            sv_setref_pv( e, CHAR_P CLASS, &event );
            rv = SvRV( e );
            // corner case: prevent destruction if referrer is
            // destroyed
            SvREFCNT_inc( rv );
            sv_2mortal( rv );
            guard.SetSV( rv );
            wxPli_thread_sv_register( aTHX_ CLASS, &event, e );
        }

        PUSHMARK( SP );
        XPUSHs( This->m_self );
        XPUSHs( e );
        PUTBACK;

        if( This->m_is_method )
        {
            call_method( SvPV_nolen( This->m_method ), G_EVAL|G_VOID|G_DISCARD );
        }
        else
        {
            call_sv( This->m_method, G_EVAL|G_VOID|G_DISCARD );
        }

        SPAGAIN;
    }

    if( SvTRUE( ERRSV ) )
    {
        croak( Nullch );
    }

    PUTBACK;
    FREETMPS;
    LEAVE;
}

// Local variables: //
// mode: c++ //
// End: //