Cface__CairoMapping.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 08 Jan 2010 13:25:11 +0000
changeset 14 1f730d82496e
parent 5 c110eef5b9ef
child 19 1297bf936bfb
permissions -rw-r--r--
Added version_SVN methods

"{ Package: 'cvut:fel/cface' }"

"{ NameSpace: Cface }"

TypeMapping subclass:#CairoMapping
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Cface-Mappings'
!


!CairoMapping methodsFor:'accessing'!

smalltalkClassNameForDerivedType:cType 
    |cairoName|

    cairoName := cType cName.
    cairoName = '_cairo' ifTrue:[
        ^ #GraphicsContext
    ].
    (cairoName startsWith:'_cairo_') ifTrue:[
        cairoName := cairoName copyFrom:8
    ].
    (cairoName startsWith:'cairo_') ifTrue:[
        cairoName := cairoName copyFrom:7
    ].
    (cairoName endsWith:'_t') ifTrue:[
        cairoName := cairoName copyTo:(cairoName size - 2)
    ].
    ^ (self smalltalkize:cairoName) capitalized asSymbol

    "
        Cface::CairoMappings new
            classForType:(Cface::EnumNode new name:'_cairo_subpixel_order_t')

        Cface::CairoMappings new
            classForType:(Cface::EnumNode new name:'_cairo_status_t')"
    "Answers class which should contain function call"

    "Modified: / 17-02-2008 / 22:18:24 / janfrog"
    "Created: / 10-07-2008 / 08:05:42 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

smalltalkClassNameForFunction:cFunction 
    (cFunction cName = 'cairo_create') ifTrue:[
        ^ 'GraphicsContext'
    ].
    ((cFunction cName matches:'*create*') 
        and:[
            cFunction return isCPointerNode 
                and:[ cFunction return type isCStructNode ]
        ]) 
            ifTrue:[ ^ cFunction return type smalltalkClassName ].
    ^ super smalltalkClassNameForFunction:cFunction

    "Created: / 04-07-2008 / 09:43:37 / Jan Vrany <vranyj1@fel.cvut.cz>"
    "Modified: / 10-07-2008 / 08:01:16 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

smalltalkNameForEnumValue:cEnumFieldType 
    |cairoName|

    cairoName := cEnumFieldType cName.
    (cairoName startsWith:'CAIRO_') ifTrue:[
        cairoName := cairoName copyFrom:7
    ].
    ^ cairoName asSymbol

    "
        Cface::CairoMapping new
            smalltalkNameForEnumValue:(Cface::CEnumValueNode new cName:'CAIRO_FONT_TYPE_TOY')

    "

    "Created: / 04-07-2008 / 11:32:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

smalltalkNamespace

    ^#Cairo

    "Created: / 17-02-2008 / 20:51:26 / janfrog"
!

smalltalkPackage

    ^#'stx:goodies/libcairo'

    "Created: / 03-07-2008 / 21:14:47 / Jan Vrany <vranyj1@fel.cvut.cz>"
!

smalltalkSelectorForFunction: cFunction

    | selector |
    selector := cFunction cName.
    cFunction isFirstArgumentCPointerToCStructure ifTrue:
        [|firstArgTypeCname|
        firstArgTypeCname := cFunction arguments first type type cName.
        (firstArgTypeCname first = $_) ifTrue:
            [ firstArgTypeCname := firstArgTypeCname copyFrom:2].
        (selector startsWith:firstArgTypeCname) ifTrue:
            [selector := selector copyFrom: firstArgTypeCname size + 2]].

    (selector startsWith:'cairo_')
        ifTrue:[selector := (cFunction cName at: 7) asString , (selector copyFrom: 8)].
    ^self smalltalkizeSelector: selector forFunction: cFunction.

    "Created: / 17-02-2008 / 22:16:03 / janfrog"
    "Modified: / 18-02-2008 / 14:58:43 / janfrog"
    "Modified: / 04-07-2008 / 15:33:31 / Jan Vrany <vranyj1@fel.cvut.cz>"
! !

!CairoMapping class methodsFor:'documentation'!

version
    ^ '$Header: /opt/data/cvs/cvut-fel/cface/Cface__CairoMapping.st,v 1.1 2008/02/26 15:57:39 vranyj1 Exp $'
!

version_SVN
    ^ '$Id$'
! !