Changes between Version 1 and Version 2 of WxWidgetsPort
- Timestamp:
- 10/29/09 11:12:15 (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WxWidgetsPort
v1 v2 7 7 see [wiki:C#Diffs Cobra differences fm C#] 8 8 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 9 Heres 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 11 1 Take .cs file, rename to .cobra file. 12 12 13 13 14 2. Change multiline comments from multiple // or /* */ bounded to be /# #/ bounded.[[br]] … … 15 16 16 17 Remove extraneous separator line comments between method calls 17 // ------------------------------18 {{{ // ------------------------------ }}} 18 19 19 20 3. Remove trailing ';' from each line they occur on … … 31 32 Remove any lines for 32 33 {{{ 33 34 35 36 34 using System 35 using System.Collections.Generic 36 using System.IO 37 using System.Text 37 38 }}} 38 39 as cobra includes these automagically … … 42 43 You also need to specify to use the C# wrapper library/namespace for wxWidgets (''''wx''''). 43 44 44 Before ''''use System.Drawing'''' add a ''''use .. from line'''' for wx.NET45 {{{ 46 47 48 }}} 49 50 {{{ 51 52 53 54 45 Before ''''use System.Drawing'''' add a ''''use .. from line'''' for wx.NET 46 {{{ 47 use wx from "wx.NET" 48 use System.Drawing 49 }}} 50 or add an explicit compiler directive ref line and a 'use wx' line 51 {{{ 52 @ref "wx.NET" 53 ... 54 use wx 55 use System.Drawing 55 56 }}} 56 57 … … 61 62 62 63 63 5a. Correct any Enum definitions 64 5a. Correct any Enum definitions. [[br]] 64 65 After applying the above its basically removing trailing ',' and ensuring indentation 65 66 of enum items is the same 66 67 e.g. 67 68 {{{ 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 69 enum Cmd { About, Quit, Dialog } 70 }}} 71 -> 72 {{{ 73 enum Cmd 74 About 75 Quit 76 Dialog 77 78 79 enum ID_CONTROLS { 80 ID_RADIO_ORIENT = 5999, 81 ID_CHK_SHOWIMAGES, 82 ID_BTN_NEXT_PAGE, 83 ID_NOTEBOOK 84 } 85 }}} 86 -> 87 {{{ 88 enum ID_CONTROLS 89 ID_RADIO_ORIENT = 5999 90 ID_CHK_SHOWIMAGES 91 ID_BTN_NEXT_PAGE 92 ID_NOTEBOOK 86 93 }}} 87 94 … … 101 108 8. Fixup class constructor definitions 102 109 For initializer/constructor change lines like 103 ''''public !ClassName(params,...) : base(baseParams,...)''''110 {{{ public ClassName(params,...) : base(baseParams,...) }}} 104 111 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, 110 120 -> 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 114 125 e.g. 115 126 {{{ … … 121 132 122 133 9. 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]] 124 135 e.g. 125 136 {{{ … … 129 140 }}} 130 141 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''', 133 143 methodNames must start with a lowercase letter and are prefixed by ''''this.'''' or just ''''.'''' 134 144 so change the methodName accordingly … … 137 147 138 148 10. 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''' 144 154 you can just delete those words. 155 145 156 Also, if a method has no parameters then the empty trailing () can be left off. 146 157 147 158 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 150 162 that if you just declare something of Type Object theres a resolution ambiguity 151 163 message is 'Ambiguous reference "Object" found in namespaces "System" and "wx"' … … 166 178 }}} 167 179 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 180 11. 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]] 171 183 must be modified accordingly. 184 172 185 e.g. 173 186 {{{ … … 181 194 Log.SetActiveTarget( textCtrl ) -> Log.setActiveTarget(.textCtrl) # static class 182 195 }}} 196 183 197 If a method takes no args then any empty trailing () on a method call can/should be left off. 184 198 185 12. Property definition depending on the property use, prefix properties with186 get - readable property only187 set - setable property only188 pro - getable and setable199 12. 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 189 203 190 204 Change property names to start with a lowercase letter … … 192 206 193 207 13. Local variables declared and assigned on first use can usually be changed to remove 194 195 196 {{{ 197 208 the type definition (type inferred from the assignment) or can continue to be explicitly typed 209 (if that compiles). 210 {{{ 211 ListItem info = new ListItem() 198 212 -> 199 213 info = ListItem # or info as ListItem = ListItem() 200 214 }}} 201 215 202 Heres a composite example 203 {{{ 204 // C# 216 Heres a composite example 217 218 {{{ 219 // C# 205 220 ListItem itemCol = new ListItem(); 206 221 itemCol.Text = "Second Column"; … … 208 223 itemCol.Width = 300; 209 224 InsertColumn( 1, itemCol ); 210 211 225 --> 226 # Cobra 212 227 itemCol = ListItem() 213 228 itemCol.text = "Second Column" … … 220 235 12. Fixup 'For' loops 221 236 {{{ 222 223 224 225 226 227 228 237 for ( <Type> name = start ; name < stop; ++name ) 238 -> 239 for name as Type in start : stop : 1 # explicit or equally use shortcuts: 240 for name in start : stop : 1 241 for name in start : stop # if step is one (1) 242 for name in stop # if start is zero (0) and step is one (1) 243 # same as for name in 0 : stop : 1 229 244 }}} 230 245 231 232 {{{ 233 246 e.g 247 {{{ 248 for ( int i = 0; i < 200; ++i ) -> for i in 0 : 200 234 249 }}} 250 235 251 236 252 13. Casting … … 238 254 e.g. 239 255 {{{ 240 256 mf.AppendWL( (int)Cmd.About,... 241 257 -> 242 258 mf.appendWL(Cmd.About to int,... 243 259 }}} 244 260 … … 261 277 262 278 15. 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]] 270 287 Upcased methodnames are referenced with the first '''word''' lowercased 271 288 so 272 {{{289 {{{ 273 290 EVENT += EventListener( MethodName ) in C# becomes 274 291 listen .EVENT, EventListener( ref .methodName ) … … 276 293 EVENT += EventListener( EH_METHOD_NAME ) in C# becomes 277 294 listen .EVENT, EventListener( ref .eh_METHOD_NAME ) 278 }}}295 }}} 279 296 e.g. 280 {{{297 {{{ 281 298 ColumnClick += EventListener( OnColumnClick ) 282 299 ItemSelect += EventListener( OnItemSelect ) … … 286 303 listen .itemSelect, EventListener(ref .onItemSelect ) 287 304 listen .columnRightClick, EventListener(ref .onColumnRightClick) 288 }}}289 290 !WxWid ets 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. 291 308 {{{EVT_MENU((int)MENU_ENUM_VALUE, new EventListener(MethodName)); }}} 292 309 the equivalent in cobra becomes … … 294 311 295 312 e.g. 296 {{{313 {{{ 297 314 EVT_MENU((int)Cmd.Quit, new EventListener(OnQuit)); 298 315 EVT_MENU((int)Cmd.Dialog, new EventListener(OnDialog)); 299 316 EVT_MENU((int)Cmd.About, new EventListener(OnAbout)); 300 }}}301 302 {{{317 }}} 318 -> 319 {{{ 303 320 .evt_MENU(Cmd.Quit to int, EventListener(ref .onQuit)) 304 321 .evt_MENU(Cmd.Dialog to int, EventListener(ref .onDialog)) 305 322 .evt_MENU(Cmd.About to int, EventListener(ref .onAbout)) 306 }}}323 }}} 307 324 308 325 16. Main method 309 public void is default, static is an accessmodifierbecomes ''''shared'''' in cobra,326 'public void' is default, static is an accessmodifier which becomes ''''shared'''' in cobra, 310 327 C# attributes (!MetaInformation) are denoted with ''''has'''' 311 328 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] 331 static public void main() 332 }}} 333 -> 334 {{{ 335 def main is shared has STAThread 336 }}} 337 338 17. 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]] 325 344 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 {{{ 346 use wx from "wx.NET" 347 namespace SampleMinimal 348 class MyFrame inherits wx.Frame 349 # file.cobra(3): error: Cannot find type for "wx.Frame". 350 }}} 351 change to 352 {{{ 353 use wx from "wx.NET" 354 namespace SampleMinimal 355 class MyFrame inherits Frame 356 }}} 336 357 337 {{{ def onAbout(sender as System.Object, e as wx.Event ) }}} 338 # Change to339 {{{ def onAbout(sender as System.Object, e as Event ) }}} 340 341 {{{ 342 fileMenu as wx.Menu = wx.Menu()343 # Change to344 fileMenu = Menu()345 }}} 346 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 370 Other weirdnesses: 350 371 As of this doc date (Oct 2009) the wx.NET version and cobra seem to not be able to find 351 372 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]]