Wiki

Changes between Version 1 and Version 2 of WxWidgetsPort

Show
Ignore:
Timestamp:
10/29/09 11:12:15 (15 years ago)
Author:
hopscc
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • WxWidgetsPort

    v1 v2  
    77see [wiki:C#Diffs Cobra differences fm C#] 
    88 
    9 Heres a process for C# generally with some notes re wx.NET generated from converting wx.NET sample file ListView.cs to ListView.cobra 
    10  
    11 1 Take .cs file, rename to .cobra file 
     9Heres a process for C# generally with some notes re wx.NET generated from converting wx.NET sample file [wiki:ListViewCode ListView.cs to ListView.cobra] 
     10 
     111 Take .cs file, rename to .cobra file. 
     12 
    1213 
    13142. Change multiline comments from multiple // or /* */ bounded to be /# #/ bounded.[[br]] 
     
    1516 
    1617Remove extraneous separator line comments between method calls    
    17         // ------------------------------ 
     18        {{{ // ------------------------------ }}} 
    1819         
    19203. Remove trailing ';' from each line they occur on 
     
    3132Remove any lines for  
    3233{{{ 
    33     using System 
    34     using System.Collections.Generic 
    35     using System.IO 
    36     using System.Text 
     34using System 
     35using System.Collections.Generic 
     36using System.IO 
     37using System.Text 
    3738}}} 
    3839  as cobra includes these automagically 
     
    4243You also need to specify to use the C# wrapper library/namespace for wxWidgets (''''wx''''). 
    4344 
    44 Before ''''use System.Drawing'''' add a ''''use .. from line''''  for wx.NET 
    45 {{{ 
    46     use wx from "wx.NET" 
    47     use System.Drawing 
    48 }}} 
    49         or  add an explicit compiler directive ref line and a 'use wx' line 
    50 {{{ 
    51     @ref "wx.NET" 
    52             ... 
    53     use wx 
    54     use System.Drawing 
     45  Before ''''use System.Drawing'''' add a ''''use .. from line''''  for wx.NET 
     46{{{ 
     47use wx from "wx.NET" 
     48use System.Drawing 
     49}}} 
     50  or  add an explicit compiler directive ref line and a 'use wx' line 
     51{{{ 
     52@ref "wx.NET" 
     53        ... 
     54use wx 
     55use System.Drawing 
    5556}}} 
    5657 
     
    6162 
    6263 
    63 5a. Correct any Enum definitions 
     645a. Correct any Enum definitions. [[br]] 
    6465    After applying the above its basically removing trailing ',' and ensuring indentation 
    6566    of enum items is the same 
    6667    e.g.  
    6768{{{ 
    68     enum Cmd { About, Quit, Dialog } -> 
    69     enum Cmd 
    70         About 
    71         Quit 
    72         Dialog 
    73  
    74     enum ID_CONTROLS  { 
    75         ID_RADIO_ORIENT = 5999, 
    76         ID_CHK_SHOWIMAGES, 
    77         ID_BTN_NEXT_PAGE, 
    78         ID_NOTEBOOK 
    79    } 
    80          -> 
    81    enum ID_CONTROLS 
    82         ID_RADIO_ORIENT = 5999 
    83         ID_CHK_SHOWIMAGES 
    84         ID_BTN_NEXT_PAGE 
    85         ID_NOTEBOOK 
     69enum Cmd { About, Quit, Dialog } 
     70}}}  
     71    -> 
     72{{{ 
     73enum Cmd 
     74    About 
     75    Quit 
     76    Dialog 
     77 
     78 
     79enum ID_CONTROLS  { 
     80    ID_RADIO_ORIENT = 5999, 
     81    ID_CHK_SHOWIMAGES, 
     82    ID_BTN_NEXT_PAGE, 
     83    ID_NOTEBOOK 
     84} 
     85}}} 
     86    -> 
     87{{{ 
     88enum ID_CONTROLS 
     89    ID_RADIO_ORIENT = 5999 
     90    ID_CHK_SHOWIMAGES 
     91    ID_BTN_NEXT_PAGE 
     92    ID_NOTEBOOK 
    8693}}} 
    8794 
     
    1011088. Fixup class constructor definitions 
    102109      For initializer/constructor change lines like 
    103         ''''public !ClassName(params,...) : base(baseParams,...)'''' 
     110        {{{ public ClassName(params,...) : base(baseParams,...) }}} 
    104111      to 
    105         ''''cue init(params, ...) is public''' 
    106              '''base.init(baseParams,...)''''         
    107  
    108      within the params list correct type declaration syntax from C# to cobra 
    109         ''''[<accessModifier> ...] <Type> name,'  
     112{{{ 
     113    cue init(params, ...) is public 
     114        base.init(baseParams,...)  
     115}}}         
     116 
     117     Within the params list correct type declaration syntax from C# to cobra 
     118{{{ 
     119        [<accessModifier> ...] <Type> name,  
    110120            ->  
    111         ''''name as <Type> [is <accessModifier>, ...],'''' 
    112  
    113         public is default accessmodifier so can leave that off   
     121        name as <Type> [is <accessModifier>, ...], 
     122}}} 
     123 
     124        public is default accessModifier so can leave that off   
    114125     e.g. 
    115126{{{ 
     
    121132                
    1221339. Remove any uses of ''''new'''' to construct a class instance,  
    123     instead just make a call to the class type passing any initializer args, i.e just remove 'new' 
     134    instead just make a call to the class type passing any initializer args, i.e just remove 'new'[[br]] 
    124135    e.g. 
    125136{{{ 
     
    129140}}} 
    130141 
    131        For classes that construct delegates (take method names) prefix the methodname with 
    132         '''ref''',  
     142       For classes that construct delegates (take method names) prefix the methodname with '''ref''',  
    133143        methodNames must start with a lowercase letter and are prefixed by ''''this.'''' or just ''''.'''' 
    134144        so change the methodName accordingly 
     
    137147 
    13814810. Methods: 
    139     Prefix methods with '''def''' 
    140     Change methodnames to start with a lowercase letter,  
    141     Change param definitions to cobra form. 
    142         ''''[<accessModifier> ...] <Type> name,'''' -> ''''name as <Type> [is <accessModifier>, ...],'''' 
    143     Cobra methods by default return void and are public so if the C# code specifies ''''public void'''  
     149    Prefix methods with '''def'''.[[br]] 
     150    Change methodnames to start with a lowercase letter, [[br]] 
     151    Change param definitions to cobra form.[[br]] 
     152        {{{[<accessModifier> ...] <Type> name,}}} -> {{{name as <Type> [is <accessModifier>, ...],}}} 
     153    Cobra methods by default return void and are public so if the C# code specifies '''public void'''  
    144154    you can just delete those words. 
     155 
    145156    Also, if a method has no parameters then the empty trailing () can be left off. 
    146157             
    147158    Note builtin types: 
    148         C# string -> String 
    149         C# object -> Object - Theres a twist though; wx.NET also defines an Object (wx.Object) so 
     159        C# string -> String[[br]] 
     160        C# object -> Object [[br]] 
     161            Theres a twist though; wx.NET also defines an Object (wx.Object) so 
    150162            that if you just declare something of Type Object theres a resolution ambiguity 
    151163                message is 'Ambiguous reference "Object" found in namespaces "System" and "wx"' 
     
    166178}}} 
    167179             
    168 11. Calls to methods, properties and attributes/fields 
    169      Instance method names, properties and fields are called with a prefix of ''''this.'''' or just ''''.''''  
    170      and they all must be named starting with a lowercase letter so these calls and settings 
     18011. Calls to methods, properties and attributes/fields. 
     181     Instance method names, properties and fields are called with a prefix of ''''this.'''' or just ''''.'''' [[br]] 
     182     and they all must be named starting with a lowercase letter so these calls and settings[[br]] 
    171183     must be modified accordingly. 
     184 
    172185     e.g. 
    173186{{{ 
     
    181194    Log.SetActiveTarget( textCtrl ) ->  Log.setActiveTarget(.textCtrl) # static class 
    182195}}} 
     196 
    183197    If a method takes no args then any empty trailing () on a method call can/should be left off. 
    184198 
    185 12.  Property definition depending on the property use, prefix properties with  
    186         get - readable property only 
    187         set - setable property only 
    188         pro - getable and setable 
     19912.  Property definition. Depending on the property use, prefix properties with :[[br]]  
     200        * get - readable property only  
     201        * set - settable property only 
     202        * pro - gettable and settable 
    189203 
    190204    Change property names to start with a lowercase letter 
     
    192206 
    19320713. Local variables declared and assigned on first use can usually be changed to remove  
    194     the type definition (type inferred from the assignment) or can continue to be explicitly typed 
    195     (if that compiles). 
    196 {{{ 
    197      ListItem info = new ListItem()  
     208the type definition (type inferred from the assignment) or can continue to be explicitly typed 
     209(if that compiles). 
     210{{{ 
     211    ListItem info = new ListItem()  
    198212      -> 
    199      info = ListItem     # or    info as ListItem = ListItem() 
     213    info = ListItem     # or    info as ListItem = ListItem() 
    200214}}} 
    201215     
    202  Heres a composite example  
    203 {{{ 
    204     //  C# 
     216Heres a composite example 
     217  
     218{{{ 
     219//  C# 
    205220    ListItem itemCol = new ListItem(); 
    206221    itemCol.Text = "Second Column"; 
     
    208223    itemCol.Width = 300; 
    209224    InsertColumn( 1, itemCol ); 
    210             -> 
    211     # Cobra 
     225        --> 
     226# Cobra 
    212227    itemCol = ListItem() 
    213228    itemCol.text = "Second Column" 
     
    22023512. Fixup 'For' loops 
    221236{{{ 
    222     for ( <Type> name = start ; name < stop; ++name )  
    223             -> 
    224     for name as Type in start : stop : 1 # explicit or equally use shortcuts: 
    225     for name in start : stop : 1  
    226     for name  in start : stop  # if step is one (1) 
    227     for name in stop           # if start is zero (0) and step is one (1) 
    228         # same as for name in 0 : stop : 1 
     237for ( <Type> name = start ; name < stop; ++name )  
     238        -> 
     239for name as Type in start : stop : 1 # explicit or equally use shortcuts: 
     240for name in start : stop : 1  
     241for name  in start : stop  # if step is one (1) 
     242for name in stop           # if start is zero (0) and step is one (1) 
     243    # same as for name in 0 : stop : 1 
    229244}}} 
    230245     
    231   e.g 
    232 {{{ 
    233     for ( int i = 0; i < 200; ++i ) -> for i in 0 : 200 
     246e.g 
     247{{{ 
     248for ( int i = 0; i < 200; ++i ) -> for i in 0 : 200 
    234249}}}     
     250 
    235251 
    23625213. Casting 
     
    238254    e.g.   
    239255{{{ 
    240     mf.AppendWL( (int)Cmd.About,...  
     256mf.AppendWL( (int)Cmd.About,...  
    241257        ->   
    242     mf.appendWL(Cmd.About to int,... 
     258mf.appendWL(Cmd.About to int,... 
    243259}}} 
    244260 
     
    261277              
    26227815. Adding eventHandlers 
    263     Cobra uses the *listen* statement to register eventhandlers where C# uses an override on  
    264     the += operator.  WxWidgets wraps method calls in an EventHandler class instance. 
    265     Otherwise normal cobra mapping for method names and reference to methods (vs method calls) 
    266     apply; Methodnames in Cobra must start with lower case and calls to this instance names  
    267         are prefixed with ''''this.'''' or (easier) ''''.''''     
    268     When translating from a 'use'd library namespace,  calls to  
    269         Capcased methodnames are referenced in cobra with the first '''char''' lowercased,  
     279    Cobra uses the '''listen''' statement to register event handlers where C# uses an override on  
     280    the += operator.  !WxWidgets wraps method calls in an !EventHandler class instance.[[br]] 
     281    Otherwise normal cobra mapping for method names and reference to methods (vs method calls)apply;[[br]] 
     282    Methodnames in Cobra must start with a lower case letter and calls to this instance names  
     283        are prefixed with ''''this.'''' or (easier) ''''.'''' 
     284     
     285    When translating from a 'use'd library namespace,  calls to[[br]]  
     286        Capcased methodnames are referenced in cobra with the first '''char''' lowercased,[[br]]  
    270287        Upcased methodnames  are referenced with the first '''word''' lowercased 
    271288    so  
    272 {{{ 
     289    {{{ 
    273290    EVENT += EventListener( MethodName ) in C# becomes 
    274291    listen .EVENT,      EventListener( ref .methodName )  
     
    276293    EVENT += EventListener( EH_METHOD_NAME ) in C# becomes 
    277294    listen .EVENT,      EventListener( ref .eh_METHOD_NAME )  
    278 }}} 
     295    }}} 
    279296    e.g. 
    280 {{{ 
     297    {{{ 
    281298    ColumnClick += EventListener( OnColumnClick ) 
    282299    ItemSelect  +=  EventListener( OnItemSelect ) 
     
    286303    listen .itemSelect,     EventListener(ref .onItemSelect ) 
    287304    listen .columnRightClick, EventListener(ref .onColumnRightClick) 
    288 }}} 
    289  
    290     !WxWidets menu action handlers can be done in C# using call to EVT_MENU. 
     305    }}} 
     306 
     307    !WxWidgets menu action handlers can be done in C# using call to EVT_MENU. 
    291308        {{{EVT_MENU((int)MENU_ENUM_VALUE, new EventListener(MethodName)); }}} 
    292309    the equivalent in cobra becomes 
     
    294311                 
    295312    e.g.     
    296 {{{ 
     313    {{{ 
    297314    EVT_MENU((int)Cmd.Quit,    new EventListener(OnQuit)); 
    298315    EVT_MENU((int)Cmd.Dialog,  new EventListener(OnDialog)); 
    299316    EVT_MENU((int)Cmd.About,   new EventListener(OnAbout)); 
    300 }}} 
    301             -> 
    302 {{{ 
     317    }}} 
     318    -> 
     319    {{{ 
    303320    .evt_MENU(Cmd.Quit to int,    EventListener(ref .onQuit)) 
    304321    .evt_MENU(Cmd.Dialog to int,  EventListener(ref .onDialog)) 
    305322    .evt_MENU(Cmd.About to int,   EventListener(ref .onAbout)) 
    306 }}} 
     323    }}} 
    307324 
    30832516. Main method 
    309     public void is default, static is an accessmodifier becomes ''''shared'''' in cobra, 
     326    'public void' is default, static is an accessmodifier which becomes ''''shared'''' in cobra, 
    310327    C# attributes (!MetaInformation) are denoted with ''''has'''' 
    311328    e.g. 
    312 {{{ 
    313     [STAThread] 
    314     static public void main() 
    315             ->   
    316     def main is shared has STAThread 
    317 }}}     
    318  
    319 17. Lowercased namespace names (as in wx.NET) used to disambiguate or otherwise explicitly  
    320     specify the namespace  on types (inherits ..., as ....) as opposed to methods or constants  
    321     can (may/will) generate compile errors of the form  
    322         ''''error: Cannot find type for "wx.TYPE".''''[[br]] 
    323         e.g. error: Cannot find type for "wx.Frame".         
    324     If such occurs the only recourse is to remove the explicit typing and rely on default handling 
     329    {{{ 
     330[STAThread] 
     331static public void main() 
     332    }}} 
     333    -> 
     334    {{{ 
     335def main is shared has STAThread  
     336    }}}     
     337 
     33817. Lowercased namespace names (as in wx.NET) used to disambiguate or otherwise explicitly [[br]] 
     339    specify the namespace on types (inherits ..., as ....) as opposed to methods or constants [[br]] 
     340    can (may/will) generate compile errors of the form: [[br]] 
     341        '''error: Cannot find type for "wx.TYPE".'''[[br]] 
     342        e.g. error: Cannot find type for "wx.Frame".[[br]]         
     343    If such occurs the only recourse is to remove the explicit typing and rely on default handling. [[br]] 
    325344    e.g. 
    326 {{{ 
    327     use wx from "wx.NET" 
    328     namespace SampleMinimal 
    329         class MyFrame inherits wx.Frame 
    330                 # file.cobra(3): error: Cannot find type for "wx.Frame".    
    331     #Change to          
    332     use wx from "wx.NET" 
    333     namespace SampleMinimal 
    334         class MyFrame inherits Frame 
    335 }}} 
     345  {{{ 
     346use wx from "wx.NET" 
     347namespace SampleMinimal 
     348    class MyFrame inherits wx.Frame 
     349        # file.cobra(3): error: Cannot find type for "wx.Frame". 
     350}}}    
     351  change to          
     352{{{ 
     353use wx from "wx.NET" 
     354namespace SampleMinimal 
     355    class MyFrame inherits Frame 
     356  }}} 
    336357         
    337 {{{     def onAbout(sender as System.Object, e as wx.Event ) }}} 
    338     #    Change to  
    339 {{{     def onAbout(sender as System.Object, e as Event ) }}} 
    340          
    341 {{{      
    342     fileMenu as wx.Menu = wx.Menu()  
    343     #    Change to  
    344     fileMenu = Menu()  
    345 }}} 
    346     Eventually it would be preferable if cobra became a little more flexible in these cases..  
    347  
    348  
    349 Other weirdnesses 
     358  {{{ def onAbout(sender as System.Object, e as wx.Event ) }}} [[br]] 
     359  change to [[br]] 
     360  {{{ def onAbout(sender as System.Object, e as Event ) }}} [[br]] 
     361 
     362     
     363  {{{fileMenu as wx.Menu = wx.Menu() }}} [[br]] 
     364  change to [[br]] 
     365  {{{fileMenu = Menu() }}} [[br]] 
     366 
     367  Eventually it would be preferable if cobra became a little more flexible in these cases..  
     368 
     369 
     370Other weirdnesses: 
    350371    As of this doc date (Oct 2009) the wx.NET version and cobra seem to not be able to find 
    351372    some properties, specifically[[br]] 
    352         Frame.Icon, .icon property -> no workaround [[br]] 
    353         Frame.!StatusBar, .statusBar text property -> use method .setStatusBar(text) instead[[br]] 
     373        Frame.Icon, .icon property -> no workaround. [[br]] 
     374        Frame.!StatusBar, .statusBar text property -> use method .setStatusBar(text) instead.[[br]]