Sha256: 4ebf4a9c613f1752db22b8648963d9e82f622a32ccb1a46e713a5ebd9f7fc31d

Contents?: true

Size: 1.98 KB

Versions: 9

Compression:

Stored size: 1.98 KB

Contents

###
# wxRuby3 Common typemap definitions
# Copyright (c) M.J.N. Corino, The Netherlands
###

require_relative '../core/mapping'

module WXRuby3

  module Typemap

    # Shared features used by the RichText classes
    module RichText

      include Typemap::Module

      def self.on_include(including_mod)
        # Used by several classes to load and save rich text content to files
        # and streams.
        including_mod.include(Typemap::IOStreams)
      end

      define do

        # The wxWidgets RichText API in several places represents and returns
        # ranges of text selections with a special class. It doesn't add
        # anything much that Ruby's own range class doesn't, so deal with using
        # typemaps
        map 'wxRichTextRange&' => 'Range' do

          map_in code: <<~__CODE
            int start = NUM2INT( rb_funcall( $input, rb_intern("begin"), 0));
            int end   = NUM2INT( rb_funcall( $input, rb_intern("end"), 0));
            wxRichTextRange rng = wxRichTextRange(start, end);
            $1 = &rng;
            __CODE

          map_typecheck precedence: 1, code: '$1 = ( CLASS_OF($input) == rb_cRange );'

          map_out code: '$result = rb_range_new (LONG2NUM($1->GetStart()),LONG2NUM($1->GetEnd()),0);'

          map_directorin code: '$input = rb_range_new (LONG2NUM($1.GetStart()),LONG2NUM($1.GetEnd()),0);'

        end

        map 'wxRichTextRange' => 'Range' do

          map_out code: '$result = rb_range_new (LONG2NUM($1.GetStart()),LONG2NUM($1.GetEnd()),0);'

          map_directorout code: <<~__CODE
            int start = NUM2INT( rb_funcall( $input, rb_intern("begin"), 0));
            int end   = NUM2INT( rb_funcall( $input, rb_intern("end"), 0));
            $result = wxRichTextRange(start, end);
            __CODE

        end

        # Used as in/out parameters by some other selection-getting methods
        map_apply 'int *OUTPUT' => [ 'long * from' , 'long * to' ]

      end # define

    end # RichText

  end # Typemap

end # WXRuby3

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wxruby3-0.9.0.pre.rc.3 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.rc.2 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.rc.1 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.14 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.13 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.11 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.10 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.9 rakelib/lib/typemap/richtext.rb
wxruby3-0.9.0.pre.beta.8 rakelib/lib/typemap/richtext.rb