Swig''s bad interface generation strikes again. get_text_extent called with 1 argument maps to WindowDC''s _wrap_wxWindowDC_GetTextExtent__SWIG_0 Since this generates a wxFont that''s not initialized to nil it fails when calling into wxWindows. Anyone have a suggestion?
Kevin Smith
2005-Sep-11 00:13 UTC
[Wxruby-users] Swig generates bad interface to GetTextExtent
Roy Sutton wrote:> Swig''s bad interface generation strikes again. get_text_extent called > with 1 argument maps to WindowDC''s _wrap_wxWindowDC_GetTextExtent__SWIG_0 > > Since this generates a wxFont that''s not initialized to nil it fails > when calling into wxWindows. Anyone have a suggestion?Ugh. I need to report this to the swig list to see if they have any plans to fix it. For this case, I think the solution is to do what wxPerl did, which is to define a get_text_extent(string, font=nil) that returns four values (width, height, descent, externalLeading). To do that, I think we would get rid of those icky typemaps in WindowDC.i, and %ignore GetTextExtent. Then %extend the class to implement our own get_text_extent. Much like we did for App#main_loop. The actual body of our get_text_extent should be fairly straightforward: Validate the parameters, call GetTextExtent with some locals to hold the results, create a ruby array, copy the results to it, and return it. We''ll need to do the same thing for DC.i, so it would probably be best to put the %extend stuff in a .i file that is %include''d from both. Maybe "../dcextensions.i"? I''m not sure if there will be issues trying to make it work for two different classes. If so, we could have duplicated code to start with, and later figure out how to merge them. Kevin
Roy Sutton
2005-Sep-11 01:01 UTC
[Wxruby-users] Swig generates bad interface to GetTextExtent
Well, I fixed it. Font isn''t an in/out parameter. Given the discussion earlier on moving typemaps into the typemap.i, attached is a patch to the three affected files. Given that wxWindowDC doesn''t actually seem to declare all the methods defined in the wxWindowDC.h file, should we clean that out? Roy Roy Sutton wrote:> Swig''s bad interface generation strikes again. get_text_extent called > with 1 argument maps to WindowDC''s _wrap_wxWindowDC_GetTextExtent__SWIG_0 > > Since this generates a wxFont that''s not initialized to nil it fails > when calling into wxWindows. Anyone have a suggestion?-------------- next part -------------- --- wxruby2_old/swig/typemap.i 2005-09-03 17:33:46.000000000 -0400 +++ wxruby2/swig/typemap.i 2005-09-11 00:17:57.043641600 -0400 @@ -334,3 +334,33 @@ ############################################################## + +%typemap(in,numinputs=0) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading) (wxCoord a, wxCoord b, wxCoord c, wxCoord d) { + $1=&a; + $2=&b; + $3=&c; + $4=&d; +} + +%typemap(argout) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading) { + $result = rb_ary_new(); + rb_ary_push($result, INT2NUM(*$1)); + rb_ary_push($result, INT2NUM(*$2)); + rb_ary_push($result, INT2NUM(*$3)); + rb_ary_push($result, INT2NUM(*$4)); +} + +%typemap(in,numinputs=0) (wxCoord * width , wxCoord * height , wxCoord * heightLine) (wxCoord a, wxCoord b, wxCoord c) { + $1=&a; + $2=&b; + $3=&c; +} + +%typemap(argout) (wxCoord * width , wxCoord * height , wxCoord * heightLine) { + $result = rb_ary_new(); + rb_ary_push($result, INT2NUM(*$1)); + rb_ary_push($result, INT2NUM(*$2)); + rb_ary_push($result, INT2NUM(*$3)); +} + +############################################################## -------------- next part -------------- --- wxruby2_old/swig/classes/DC.i 2005-09-09 23:31:22.000000000 -0400 +++ wxruby2/swig/classes/DC.i 2005-09-11 00:17:37.205115200 -0400 @@ -15,37 +15,6 @@ %ignore wxDC::EnableCache; %ignore wxDC::StartPage; -%typemap(in,numinputs=0) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading, wxFont *font) (wxCoord a, wxCoord b, wxCoord c, wxCoord d, wxFont f) { - $1=&a; - $2=&b; - $3=&c; - $4=&d; - $5=&f; -} - -%typemap(argout) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading, wxFont *font) { - $result = rb_ary_new(); - rb_ary_push($result, INT2NUM(*$1)); - rb_ary_push($result, INT2NUM(*$2)); - rb_ary_push($result, INT2NUM(*$3)); - rb_ary_push($result, INT2NUM(*$4)); - rb_ary_push($result, SWIG_NewPointerObj((void *) $5, SWIGTYPE_p_wxFont,0)); -} - -%typemap(in,numinputs=0) (wxCoord * width , wxCoord * height , wxCoord * heightLine, wxFont *font) (wxCoord a, wxCoord b, wxCoord c, wxFont f) { - $1=&a; - $2=&b; - $3=&c; - $4=&f; -} - -%typemap(argout) (wxCoord * width , wxCoord * height , wxCoord * heightLine, wxFont *font) { - $result = rb_ary_new(); - rb_ary_push($result, INT2NUM(*$1)); - rb_ary_push($result, INT2NUM(*$2)); - rb_ary_push($result, INT2NUM(*$3)); - rb_ary_push($result, SWIG_NewPointerObj((void *) $4, SWIGTYPE_p_wxFont,0)); -} %import "include/wxObject.h" %include "include/wxDC.h" -------------- next part -------------- --- wxruby2_old/swig/classes/WindowDC.i 2005-09-03 17:33:46.000000000 -0400 +++ wxruby2/swig/classes/WindowDC.i 2005-09-11 00:19:09.868358400 -0400 @@ -5,38 +5,6 @@ %module(directors="1") wxWindowDC -%typemap(in,numinputs=0) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading, wxFont *font) (wxCoord a, wxCoord b, wxCoord c, wxCoord d, wxFont f) { - $1=&a; - $2=&b; - $3=&c; - $4=&d; - $5=&f; -} - -%typemap(argout) (wxCoord * w , wxCoord * h , wxCoord * descent, wxCoord * externalLeading, wxFont *font) { - $result = rb_ary_new(); - rb_ary_push($result, INT2NUM(*$1)); - rb_ary_push($result, INT2NUM(*$2)); - rb_ary_push($result, INT2NUM(*$3)); - rb_ary_push($result, INT2NUM(*$4)); - rb_ary_push($result, SWIG_NewPointerObj((void *) $5, SWIGTYPE_p_wxFont,0)); -} - -%typemap(in,numinputs=0) (wxCoord * width , wxCoord * height , wxCoord * heightLine, wxFont *font) (wxCoord a, wxCoord b, wxCoord c, wxFont f) { - $1=&a; - $2=&b; - $3=&c; - $4=&f; -} - -%typemap(argout) (wxCoord * width , wxCoord * height , wxCoord * heightLine, wxFont *font) { - $result = rb_ary_new(); - rb_ary_push($result, INT2NUM(*$1)); - rb_ary_push($result, INT2NUM(*$2)); - rb_ary_push($result, INT2NUM(*$3)); - rb_ary_push($result, SWIG_NewPointerObj((void *) $4, SWIGTYPE_p_wxFont,0)); -} - %import "include/wxObject.h" %import "include/wxDC.h"
Seemingly Similar Threads
- Grid.GetTextExtent
- Wx::Window#get_text_extent patch
- [929] branches/wxruby2/wxwidgets_282/swig/classes: Fix virtual methods that shouldn''t be (Bug 9682); Add missing methods and
- Bug in new_work_item
- [756] trunk/wxruby2/swig: Moved one-shot typemaps for ListBox.get_selections into ListBox.i