Changeset 386

Show
Ignore:
Timestamp:
01/05/08 17:39:25 (1 year ago)
Author:
Mike Wey
Message:

Make the wrapper generate correct code for signals in interfaces and templates

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/gtk/RecentChooserIF.d

    r380 r386  
    3131 * clss    = RecentChooserT 
    3232 * interf  = RecentChooserIF 
    33  * class Code: Yes 
    34  * interface Code: Yes 
     33 * class Code: No 
     34 * interface Code: No 
    3535 * template for: 
    3636 * extend  =  
     
    4343 * omit code: 
    4444 * omit signals: 
    45  *  - item-activated 
    46  *  - selection-changed 
    4745 * imports: 
    4846 *  - glib.Str 
     
    9492     
    9593    /** 
     94     */ 
     95     
     96    void delegate(RecentChooserIF)[] onItemActivatedListeners(); 
     97    /** 
    9698     * This signal is emitted when the user "activates" a recent item 
    9799     * in the recent chooser. This can happen by double-clicking on an item 
     
    100102     * Since 2.10 
    101103     */ 
    102     void addOnItemActivated(void delegate(RecentChooserIF), ConnectFlags); 
    103      
     104    void addOnItemActivated(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 
     105    void delegate(RecentChooserIF)[] onSelectionChangedListeners(); 
    104106    /** 
    105107     * This signal is emitted when there is a change in the set of 
     
    112114     * GtkRecentChooserMenu 
    113115     */ 
    114     void addOnSelectionChanged(void delegate(RecentChooserIF), ConnectFlags); 
    115      
    116     /** 
    117      */ 
     116    void addOnSelectionChanged(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0); 
    118117     
    119118    /** 
  • trunk/src/gtk/RecentChooserT.d

    r381 r386  
    3030 * ctorStrct= 
    3131 * clss    = RecentChooserT 
    32  * interf  =  
    33  * class Code: Yes 
    34  * interface Code: Yes 
     32 * interf  = RecentChooserIF 
     33 * class Code: No 
     34 * interface Code: No 
    3535 * template for: 
    3636 *  - TStruct 
     
    4444 * omit code: 
    4545 * omit signals: 
    46  *  - item-activated 
    47  *  - selection-changed 
    4846 * imports: 
    4947 *  - glib.Str 
     
    9795     
    9896     
    99     /** */ 
     97    /** 
     98     */ 
    10099    int[char[]] connectedSignals; 
    101100     
    102     public struct UserData 
    103     { 
    104         RecentChooserIF recentChooser; 
    105         void delegate(RecentChooserIF)[] listeners; 
    106     } 
    107      
    108     UserData* itemActivatedData; 
    109     void delegate(RecentChooserIF)[] onItemActivatedListeners; 
     101    void delegate(RecentChooserIF)[] _onItemActivatedListeners; 
     102    void delegate(RecentChooserIF)[] onItemActivatedListeners() 
     103    { 
     104        return  _onItemActivatedListeners; 
     105    } 
    110106    /** 
    111107     * This signal is emitted when the user "activates" a recent item 
     
    117113    void addOnItemActivated(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 
    118114    { 
    119         onItemActivatedListeners ~= dlg; 
    120          
    121         if(itemActivatedData is null) 
    122         { 
    123             itemActivatedData = new UserData; 
    124         } 
    125         itemActivatedData.recentChooser = this; 
    126         itemActivatedData.listeners = onItemActivatedListeners; 
    127          
    128115        if ( !("item-activated" in connectedSignals) ) 
    129116        { 
     
    132119            "item-activated", 
    133120            cast(GCallback)&callBackItemActivated, 
    134             cast(void*)itemActivatedData
     121            cast(void*)cast(RecentChooserIF)this
    135122            null, 
    136123            connectFlags); 
    137124            connectedSignals["item-activated"] = 1; 
    138125        } 
    139     } 
    140     extern(C) static void callBackItemActivated(GtkRecentChooser* chooserStruct, UserData* data) 
     126        _onItemActivatedListeners ~= dlg; 
     127    } 
     128    extern(C) static void callBackItemActivated(GtkRecentChooser* chooserStruct, RecentChooserIF recentChooserIF) 
    141129    { 
    142130        bool consumed = false; 
    143131         
    144         foreach ( void delegate(RecentChooserIF) dlg ; data.listeners ) 
     132        foreach ( void delegate(RecentChooserIF) dlg ; recentChooserIF.onItemActivatedListeners ) 
    145133        { 
    146             dlg(data.recentChooser); 
     134            dlg(recentChooserIF); 
    147135        } 
    148136         
     
    150138    } 
    151139     
    152     UserData* selectionChangedData; 
    153     void delegate(RecentChooserIF)[] onSelectionChangedListeners; 
     140    void delegate(RecentChooserIF)[] _onSelectionChangedListeners; 
     141    void delegate(RecentChooserIF)[] onSelectionChangedListeners() 
     142    { 
     143        return  _onSelectionChangedListeners; 
     144    } 
    154145    /** 
    155146     * This signal is emitted when there is a change in the set of 
     
    164155    void addOnSelectionChanged(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 
    165156    { 
    166         onSelectionChangedListeners ~= dlg; 
    167          
    168         if(selectionChangedData is null) 
    169         { 
    170             selectionChangedData = new UserData; 
    171         } 
    172          
    173         selectionChangedData.recentChooser = this; 
    174         selectionChangedData.listeners = onSelectionChangedListeners; 
    175          
    176157        if ( !("selection-changed" in connectedSignals) ) 
    177158        { 
     
    180161            "selection-changed", 
    181162            cast(GCallback)&callBackSelectionChanged, 
    182             cast(void*)selectionChangedData
     163            cast(void*)cast(RecentChooserIF)this
    183164            null, 
    184165            connectFlags); 
    185166            connectedSignals["selection-changed"] = 1; 
    186167        } 
    187     } 
    188     extern(C) static void callBackSelectionChanged(GtkRecentChooser* chooserStruct, UserData* data) 
     168        _onSelectionChangedListeners ~= dlg; 
     169    } 
     170    extern(C) static void callBackSelectionChanged(GtkRecentChooser* chooserStruct, RecentChooserIF recentChooserIF) 
    189171    { 
    190172        bool consumed = false; 
    191173         
    192         foreach ( void delegate(RecentChooserIF) dlg ; data.listeners ) 
     174        foreach ( void delegate(RecentChooserIF) dlg ; recentChooserIF.onSelectionChangedListeners ) 
    193175        { 
    194             dlg(data.recentChooser); 
     176            dlg(recentChooserIF); 
    195177        } 
    196178         
     
    198180    } 
    199181     
    200     /** 
    201      */ 
    202182     
    203183    /** 
  • trunk/wrap/APILookupGtk.txt

    r385 r386  
    60906090#import: glib.ErrorG 
    60916091#structWrap: GError** ErrorG* 
    6092  
    6093 interfaceCode: start 
    6094     /** 
    6095      * This signal is emitted when the user "activates" a recent item 
    6096      * in the recent chooser. This can happen by double-clicking on an item 
    6097      * in the recently used resources list, or by pressing 
    6098      * Enter. 
    6099      * Since 2.10 
    6100      */ 
    6101     void addOnItemActivated(void delegate(RecentChooserIF), ConnectFlags); 
    6102      
    6103     /** 
    6104      * This signal is emitted when there is a change in the set of 
    6105      * selected recently used resources. This can happen when a user 
    6106      * modifies the selection with the mouse or the keyboard, or when 
    6107      * explicitely calling functions to change the selection. 
    6108      * Since 2.10 
    6109      * See Also 
    6110      * GtkRecentManager, GtkRecentChooserDialog, GtkRecentChooserWidget, 
    6111      * GtkRecentChooserMenu 
    6112      */ 
    6113     void addOnSelectionChanged(void delegate(RecentChooserIF), ConnectFlags); 
    6114 interfaceCode: end 
    6115  
    6116 code: start 
    6117     /** */ 
    6118     int[char[]] connectedSignals; 
    6119  
    6120     public struct UserData 
    6121     { 
    6122         RecentChooserIF recentChooser; 
    6123         void delegate(RecentChooserIF)[] listeners; 
    6124     } 
    6125  
    6126     UserData* itemActivatedData; 
    6127     void delegate(RecentChooserIF)[] onItemActivatedListeners; 
    6128     /** 
    6129      * This signal is emitted when the user "activates" a recent item 
    6130      * in the recent chooser. This can happen by double-clicking on an item 
    6131      * in the recently used resources list, or by pressing 
    6132      * Enter. 
    6133      * Since 2.10 
    6134      */ 
    6135     void addOnItemActivated(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 
    6136     { 
    6137         onItemActivatedListeners ~= dlg; 
    6138  
    6139         if(itemActivatedData is null) 
    6140         { 
    6141             itemActivatedData = new UserData; 
    6142         } 
    6143         itemActivatedData.recentChooser = this; 
    6144         itemActivatedData.listeners = onItemActivatedListeners; 
    6145  
    6146         if ( !("item-activated" in connectedSignals) ) 
    6147         { 
    6148             Signals.connectData( 
    6149             getStruct(), 
    6150             "item-activated", 
    6151             cast(GCallback)&callBackItemActivated, 
    6152             cast(void*)itemActivatedData, 
    6153             null, 
    6154             connectFlags); 
    6155             connectedSignals["item-activated"] = 1; 
    6156         } 
    6157     } 
    6158     extern(C) static void callBackItemActivated(GtkRecentChooser* chooserStruct, UserData* data) 
    6159     { 
    6160         bool consumed = false; 
    6161  
    6162         foreach ( void delegate(RecentChooserIF) dlg ; data.listeners ) 
    6163         { 
    6164             dlg(data.recentChooser); 
    6165         } 
    6166          
    6167         return consumed; 
    6168     } 
    6169  
    6170     UserData* selectionChangedData; 
    6171     void delegate(RecentChooserIF)[] onSelectionChangedListeners; 
    6172     /** 
    6173      * This signal is emitted when there is a change in the set of 
    6174      * selected recently used resources. This can happen when a user 
    6175      * modifies the selection with the mouse or the keyboard, or when 
    6176      * explicitely calling functions to change the selection. 
    6177      * Since 2.10 
    6178      * See Also 
    6179      * GtkRecentManager, GtkRecentChooserDialog, GtkRecentChooserWidget, 
    6180      * GtkRecentChooserMenu 
    6181      */ 
    6182     void addOnSelectionChanged(void delegate(RecentChooserIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 
    6183     { 
    6184         onSelectionChangedListeners ~= dlg; 
    6185  
    6186         if(selectionChangedData is null) 
    6187         { 
    6188             selectionChangedData = new UserData; 
    6189         } 
    6190         selectionChangedData.recentChooser = this; 
    6191         selectionChangedData.listeners = onSelectionChangedListeners; 
    6192  
    6193         if ( !("selection-changed" in connectedSignals) ) 
    6194         { 
    6195             Signals.connectData( 
    6196             getStruct(), 
    6197             "selection-changed", 
    6198             cast(GCallback)&callBackSelectionChanged, 
    6199             cast(void*)selectionChangedData, 
    6200             null, 
    6201             connectFlags); 
    6202             connectedSignals["selection-changed"] = 1; 
    6203         } 
    6204     } 
    6205     extern(C) static void callBackSelectionChanged(GtkRecentChooser* chooserStruct, UserData* data) 
    6206     { 
    6207         bool consumed = false; 
    6208  
    6209         foreach ( void delegate(RecentChooserIF) dlg ; data.listeners ) 
    6210         { 
    6211             dlg(data.recentChooser); 
    6212         } 
    6213          
    6214         return consumed; 
    6215     } 
    6216 code: end 
    6217  
    62186092interface: RecentChooserIF 
    62196093outFile: RecentChooserT 
  • trunk/wrap/utils/GtkDClass.d

    r379 r386  
    7474    ConvParms* convParms; 
    7575 
    76     bool isInterface; 
    7776    char[] iFaceChar = ""; 
    7877 
     
    187186        //writefln("collectStructs %s", std.string.strip(inLines[currLine])); 
    188187        this.inAPI = inAPI; 
    189         isInterface = convParms.interf.length > 0; 
    190         if ( isInterface ) iFaceChar = ";"; 
     188        if ( convParms.isInterface ) iFaceChar = ";"; 
    191189        else iFaceChar = ""; 
    192190        HtmlStrip stripper = new HtmlStrip(); 
     
    467465    { 
    468466        char[] h; 
    469         if ( convParms.interf.length > 0
     467        if ( convParms.isInterface
    470468        { 
    471469            h = "public interface "~convParms.interf; 
     
    562560            char[] var = toVar(gtkStruct.dup); 
    563561            text ~= ""; 
    564             if ( !isInterface ) 
     562            if ( !convParms.isInterface ) 
    565563            { 
    566564                text ~= "/** the main Gtk struct */"; 
     
    576574                { 
    577575                    text ~= "public "~gtkStruct~"* get"~convParms.clss~"Struct()"~iFaceChar; 
    578                     if ( !isInterface ) 
     576                    if ( !convParms.isInterface ) 
    579577                    { 
    580578                        text ~= "{"; 
     
    587585                { 
    588586                    text ~= "public "~gtkStruct~"* get"~convParms.clss~"Struct()"~iFaceChar; 
    589                     if ( !isInterface ) 
     587                    if ( !convParms.isInterface ) 
    590588                    { 
    591589                        text ~= "{"; 
     
    597595                    text ~= "/** the main Gtk struct as a void* */"; 
    598596                    text ~= "protected void* getStruct()"~iFaceChar; 
    599                     if ( !isInterface ) 
     597                    if ( !convParms.isInterface ) 
    600598                    { 
    601599                        text ~= "{"; 
     
    607605                    { 
    608606                        // GObject has a specific constructor for the struct 
    609                         if ( !isInterface ) 
     607                        if ( !convParms.isInterface ) 
    610608                        { 
    611609                            text ~= "/**"; 
     
    690688        char[] code; 
    691689 
    692         if ( isInterface ) code = convParms.interfaceCode; 
     690        if ( convParms.isInterface ) code = convParms.interfaceCode; 
    693691        else code = convParms.classCode; 
    694692 
     
    970968                if ( needSignalImports ) 
    971969                { 
    972                     if ( !isInterface ) 
     970                    if ( !convParms.isInterface ) 
    973971                    { 
    974972                        text ~= "int[char[]] connectedSignals;"; 
     
    979977                } 
    980978 
    981                 text ~= delegateDeclaration ~ "[] on" ~ gtkDSignal~"Listeners;" ; 
    982                 text ~= comments; 
    983                 addAddListener(text, signalName, gtkDSignal, delegateDeclaration); 
    984                 addExternCallback(text, fun, gtkDSignal, delegateDeclaration); 
     979                if(convParms.isInterface) 
     980                { 
     981                    text ~= delegateDeclaration ~ "[] on" ~ gtkDSignal~"Listeners();" ; 
     982                    text ~= comments; 
     983                } 
     984                else if(!convParms.isInterface && convParms.templ.length > 0) 
     985                { 
     986                    text ~= delegateDeclaration ~ "[] _on" ~ gtkDSignal~"Listeners;"; 
     987                    text ~= delegateDeclaration ~ "[] on" ~ gtkDSignal~"Listeners()"; 
     988                    text ~= "{"; 
     989                    text ~= "   return  _on" ~ gtkDSignal~"Listeners;"; 
     990                    text ~= "}"; 
     991                    text ~= comments; 
     992                } 
     993                else 
     994                { 
     995                    text ~= delegateDeclaration ~ "[] on" ~ gtkDSignal~"Listeners;" ; 
     996                    text ~= comments; 
     997                } 
     998 
     999                    addAddListener(text, signalName, gtkDSignal, delegateDeclaration); 
     1000                    addExternCallback(text, fun, gtkDSignal, delegateDeclaration); 
    9851001            } 
    9861002        } 
     
    9881004    } 
    9891005 
    990  
     1006    /* 
     1007     * Params: 
     1008     * text = the char[][] to append the function to. 
     1009     * funct = the signal function 
     1010     * gtkDSignal = the GtkD name for the signal 
     1011     * dlg = the delegale for this signal 
     1012     */ 
    9911013    void addExternCallback(inout char[][] text, Funct fun, char[] gtkDSignal, char[] dlg) 
    9921014    { 
    993         if ( !isInterface ) 
     1015        if ( !convParms.isInterface ) 
    9941016        { 
    9951017            text ~= "extern(C) static void callBack"~gtkDSignal~"(" 
     
    10191041    { 
    10201042        text ~= "void addOn"~gtkDSignalName~"("~dlg~" dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)"~iFaceChar; 
    1021         if ( !isInterface ) 
     1043        if ( !convParms.isInterface ) 
    10221044        { 
    10231045            text ~= "{"; 
     
    10391061            text ~= "           \""~signalName~"\", "; 
    10401062            text ~= "           cast(GCallback)&callBack"~gtkDSignalName~", "; 
    1041             text ~= "           cast(void*)this, "; 
     1063 
     1064            if(convParms.templ.length > 0) 
     1065                text ~= "           cast(void*)cast("~ convParms.interf ~")this, "; 
     1066            else 
     1067                text ~= "           cast(void*)this, "; 
     1068 
    10421069            text ~= "           null, "; 
    1043             //text ~= "         ConnectFlags.AFTER);"; 
    10441070            text ~= "           connectFlags);"; 
    1045             //text ~= "         cast(ConnectFlags)0);"; 
    1046             //text ~= "         0);"; 
    10471071            text ~= "   connectedSignals[\""~signalName~"\"] = 1;"; 
    10481072            text ~= "}"; 
    1049             text ~= "on"~gtkDSignalName~"Listeners ~= dlg;"; 
     1073 
     1074            if(convParms.templ.length > 0) 
     1075                text ~= "_on"~gtkDSignalName~"Listeners ~= dlg;"; 
     1076            else 
     1077                text ~= "on"~gtkDSignalName~"Listeners ~= dlg;"; 
     1078 
    10501079            text ~= "}"; 
    10511080        } 
    10521081    } 
    10531082 
    1054  
    10551083    public static char[] getClassVar(ConvParms* convParms) 
    10561084    { 
    10571085        char[] cv; 
    10581086 
    1059         if ( convParms.clss.length > 0 ) 
     1087        if ( convParms.interf.length > 0) 
     1088        { 
     1089            cv = convParms.interf.dup; 
     1090            cv[0] = std.ctype.tolower(cv[0]); 
     1091        } 
     1092        else if ( convParms.clss.length > 0 ) 
    10601093        { 
    10611094            cv = convParms.clss.dup; 
     
    11921225        { 
    11931226            if ( !convParms.strictPrefix 
    1194                 && !isInterface 
     1227                && !convParms.isInterface 
    11951228                ) 
    11961229            { 
     
    12031236        { 
    12041237            if ( !convParms.strictPrefix 
    1205                 && !isInterface 
     1238                && !convParms.isInterface 
    12061239                ) 
    12071240            { 
     
    12121245        { 
    12131246            if ( !convParms.strictPrefix 
    1214                 && !isInterface 
     1247                && !convParms.isInterface 
    12151248                ) 
    12161249            { 
     
    12211254        { 
    12221255            if ( !convParms.strictPrefix 
    1223                 && !isInterface 
     1256                && !convParms.isInterface 
    12241257                ) 
    12251258            { 
     
    12291262        else if ( startsWith(lines[0], "GTK_STOCK_") ) 
    12301263        { 
    1231             if ( !isInterface ) 
     1264            if ( !convParms.isInterface ) 
    12321265            { 
    12331266                collectStockItems(lines, convParms); 
     
    12381271                ) 
    12391272        { 
    1240             if ( !isInterface ) 
     1273            if ( !convParms.isInterface ) 
    12411274            { 
    12421275                collectGTypes(lines, convParms); 
     
    20222055                if ( fun.name.length==0 || fun.name[0] == '(' ) 
    20232056                { 
    2024                     if ( !isInterface ) 
     2057                    if ( !convParms.isInterface ) 
    20252058                    { 
    20262059                        if ( !convParms.strictPrefix ) 
     
    21622195                    else 
    21632196                    { 
    2164                         if ( !isInterface ) 
     2197                        if ( !convParms.isInterface ) 
    21652198                        { 
    21662199                            char[] externalDeclaration = fun.getExternal(convParms, wrapper.getAliases()); 
     
    21842217                            addComments(); 
    21852218                            member ~= gtkDDeclaration~iFaceChar; 
    2186                             if ( !isInterface ) 
     2219                            if ( !convParms.isInterface ) 
    21872220                            { 
    21882221                                member ~= "{"; 
  • trunk/wrap/utils/GtkWrapper.d

    r363 r386  
    589589                    convParms.templ.length = 0; 
    590590                    convParms.outFile = convParms.interf; 
     591                    convParms.isInterface = true; 
    591592                    buildText ~= "\nprivate import " 
    592593                            ~convParms.outPack~"." 
     
    596597                    convParms.templ = saveTempl; 
    597598                    // mark not interface (anymore) 
    598                     convParms.interf = ""
     599                    convParms.isInterface = false
    599600                    // as outFile is always the last definition 
    600601                    // there is no need to restore it 
     
    667668            convParms.outFile,convParms.bindDir); 
    668669        GtkDClass gtkDClass = new GtkDClass(this); 
    669     convParms.bindDir = bindingsDir; 
     670       convParms.bindDir = bindingsDir; 
    670671        gtkDClass.openGtkDClass(text, convParms); 
    671672 
     
    688689        } 
    689690        writefln("gtk Wrapped %s", gtkDClass.getOutFile(outputRoot, srcDir)); 
    690         if ( convParms.interf.length == 0
     691        if ( !convParms.isInterface
    691692        { 
    692693            convParms.clearAll(); 
  • trunk/wrap/utils/convparms.d

    r363 r386  
    3737    public char[] clss; 
    3838    public char[] interf; 
     39    public bool isInterface;  ///Are we generating an interface. 
    3940    public char[][] templ; 
    4041    public char[] extend; 
     
    6768        clss.length = 0; 
    6869        interf.length = 0; 
     70        isInterface = false; 
    6971        extend.length = 0; 
    7072        prefixes.length = 0; 
  • trunk/wrap/utils/funct.d

    r360 r386  
    261261            if ( i == parms.length-1 ) 
    262262            { 
    263                 parameters ~= convParms.clss~" "~GtkDClass.getClassVar(convParms); 
     263                if(convParms.templ.length > 0) 
     264                    parameters ~= convParms.interf~" "~GtkDClass.getClassVar(convParms); 
     265                else 
     266                    parameters ~= convParms.clss~" "~GtkDClass.getClassVar(convParms); 
    264267            } 
    265268            else if ( i>=firstParameter 
     
    346349                if ( count == parmsWrap.length-1 ) 
    347350                { 
    348                     decl ~= convParms.clss; 
     351                    //If we are generating an interface or template 
     352                    //use the interface name in the delegate. 
     353                    if(convParms.isInterface || convParms.templ.length > 0) 
     354                    { 
     355                        decl ~= convParms.interf; 
     356                    } 
     357                    else 
     358                    { 
     359                        decl ~= convParms.clss; 
     360                    } 
    349361                } 
    350362                else