wxruby3 0.9.0.pre.beta.10 → 0.9.0.pre.beta.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,7 @@
1
1
  class Wx::RealPoint
2
+
3
+ include Comparable
4
+
2
5
  # More informative output when converted to string
3
6
  def to_s
4
7
  "#<Wx::RealPoint: (#{x}, #{y})>"
@@ -16,23 +19,26 @@ class Wx::RealPoint
16
19
  alias :get_x :x
17
20
  alias :get_y :y
18
21
 
19
- # Compare point values
20
- def ==(other)
21
- if Wx::RealPoint === other
22
+ # Correct comparison for RealPoints - same if same x and y
23
+ def eql?(other)
24
+ if other.instance_of?(self.class)
22
25
  x == other.x and y == other.y
23
- elsif Array === other && other.size == 2
24
- to_ary == other
25
26
  else
26
- Kernel.raise TypeError, "Cannot compare RealPoint to #{other}"
27
+ false
27
28
  end
28
29
  end
29
30
 
30
- # Correct comparison for RealPoints - same if same x and y
31
- def eql?(other)
31
+ def hash
32
+ to_ary.hash
33
+ end
34
+
35
+ def <=>(other)
32
36
  if Wx::RealPoint === other
33
- x == other.x and y == other.y
37
+ (x*y) <=> (other.x*other.y)
38
+ elsif Array === other && other.size == 2
39
+ (x*y) <=> (other.first.to_f*other.last.to_f)
34
40
  else
35
- false
41
+ nil
36
42
  end
37
43
  end
38
44
 
@@ -89,4 +95,9 @@ class Wx::RealPoint
89
95
  end
90
96
  end
91
97
  end
98
+
99
+
100
+ def to_point
101
+ Wx::Point.new(self.x.to_i, self.y.to_i)
102
+ end
92
103
  end
data/lib/wx/core/rect.rb CHANGED
@@ -23,12 +23,12 @@ class Wx::Rect
23
23
  elsif Array === other && other.size == 4
24
24
  to_ary == other
25
25
  else
26
- Kernel.raise TypeError, "Cannot compare Rect to #{other}"
26
+ false
27
27
  end
28
28
  end
29
29
 
30
30
  def eql?(other)
31
- if Wx::Rect === other
31
+ if other.instance_of?(self.class)
32
32
  left == other.left and top == other.top and
33
33
  width == other.width and height == other.height
34
34
  else
data/lib/wx/core/size.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  class Wx::Size
2
+
3
+ include Comparable
4
+
2
5
  # More informative output for inspect etc
3
6
  def to_s
4
7
  "#<Wx::Size: #{width}x#{height}>"
@@ -14,24 +17,28 @@ class Wx::Size
14
17
  end
15
18
 
16
19
  # Compare with another size value
17
- def ==(other)
20
+ def <=>(other)
18
21
  if Wx::Size === other
19
- width == other.width and height == other.height
22
+ (width*height) <=> (other.width*other.height)
20
23
  elsif Array === other and other.size == 2
21
- to_ary == other
24
+ (width*height) <=> (other.first*other.last)
22
25
  else
23
- Kernel.raise TypeError, "Cannot compare Size to #{other}"
26
+ nil
24
27
  end
25
28
  end
26
29
 
27
30
  def eql?(other)
28
- if Wx::Size === other
31
+ if other.instance_of?(self.class)
29
32
  width == other.width and height == other.height
30
33
  else
31
34
  false
32
35
  end
33
36
  end
34
37
 
38
+ def hash
39
+ to_ary.hash
40
+ end
41
+
35
42
  # Return a new Wx::Size with the width and height values both divided
36
43
  # by parameter +num+, which should be a Numeric
37
44
  def /(num)
@@ -0,0 +1,104 @@
1
+
2
+ module Wx
3
+
4
+ class DataObject
5
+
6
+ # Returns the data size of the given format.
7
+ # Should be overridden in derived classes.
8
+ # @note **IMPORTANT** Please note that it is necessary to return the **size in bytes** of the data string
9
+ # returned by #get_data_here (not the size in characters).
10
+ # @param format [Wx::DataFormat]
11
+ # @return [Integer]
12
+ def get_data_size(format) end
13
+ alias_method :data_size, :get_data_size
14
+
15
+ end
16
+
17
+ # This is an (abstract in Ruby) base class for the simplest possible custom data objects.
18
+ # Unlike in C++ in Ruby this class cannot be used to derive custom data objects from but
19
+ # instead {Wx::DataObjectSimpleBase} (derived from Wx::DataObjectSimple) should be used.
20
+ # The data object of (a class derived from) this class only supports <b>one format</b>,
21
+ # so the number of virtual functions to be implemented is reduced.
22
+ # This class is the base class for {Wx::TextDataObject}, {Wx::FileDataObject}, {Wx::BitmapDataObject},
23
+ # {Wx::wxCustomDataObject} and others.
24
+ # ===
25
+ #
26
+ # Category: Clipboard and Drag & Drop
27
+ # @see Drag and Drop Overview
28
+ # @see Drag & Drop Sample
29
+ class DataObjectSimple < DataObject
30
+
31
+ # @overload get_data_size(format)
32
+ # Returns the data size of the format for this object.
33
+ # @param [Wx::DataFormat] format ignored for this class
34
+ # @return [Integer] default always returns 0
35
+ # @overload get_data_size()
36
+ # Returns the data size of the format for this object.
37
+ # @return [Integer] default always returns 0
38
+ def get_data_size(*) end
39
+
40
+ # @overload get_data_here(format)
41
+ # Returns the data of this object.
42
+ # @param [Wx::DataFormat] format ignored for this class
43
+ # @return [String,nil] data of this object
44
+ # @overload get_data_here()
45
+ # Returns the data of this object.
46
+ # @return [String,nil] data of this object
47
+ def get_data_here(*) end
48
+
49
+ # @overload set_data(format, buf)
50
+ # Sets the data for this object and returns true if successful, false otherwise.
51
+ # @param [Wx::DataFormat] format ignored for this class
52
+ # @param [String] buf non-nil data
53
+ # @return [Boolean] default always returns false.
54
+ # @overload set_data(buf)
55
+ # Sets the data for this object and returns true if successful, false otherwise.
56
+ # @param [String] buf non-nil data
57
+ # @return [Boolean] default always returns false.
58
+ def set_data(*) end
59
+
60
+ end
61
+
62
+ # This is the base class for the simplest possible custom data objects.
63
+ # The data object of (a class derived from) this class only supports <b>one format</b>,
64
+ # so the number of methods to be implemented is reduced.
65
+ # To be useful it must be derived. Derived objects supporting rendering the data must
66
+ # override {Wx::DataObjectSimpleBase#_get_data_size} and {Wx::DataObjectSimpleBase#_get_data}.
67
+ # By default these methods respectively return <code>0</code> and <code>nil</code>.
68
+ # The objects which may be set must override {Wx::DataObjectSimpleBase#_set_data} (which
69
+ # returns <code>false</code>).
70
+ # Of course, the objects supporting both operations must override all three methods.
71
+ # ===
72
+ #
73
+ # Category: Clipboard and Drag & Drop
74
+ # @see Drag and Drop Overview
75
+ # @see Drag & Drop Sample
76
+ # @see Wx::DataObjectSimple
77
+ class DataObjectSimpleBase < DataObjectSimple
78
+
79
+ # Returns this object's data size.
80
+ # The default implementation calls #_get_data and determines the size of the returned data string (if any).
81
+ # As this is not very optimal for more complex (and larger data objects) very often this method will be
82
+ # overridden in derived classes.
83
+ # @note **IMPORTANT** Please note that it is necessary to return the **size in bytes** of the data string
84
+ # returned by #_get_data (not the size in characters).
85
+ # @return [Integer]
86
+ def _get_data_size; end
87
+ protected :_get_data_size
88
+
89
+ # Returns this object's data (default implementation returns nil).
90
+ # Should be overridden in derived classes.
91
+ # @return [String,nil]
92
+ def _get_data; end
93
+ protected :_get_data
94
+
95
+ # Sets this object's data (default implementation does nothing and returns false).
96
+ # Should be overridden in derived classes.
97
+ # @param [String] buf non-nil data
98
+ # @return [Boolean]
99
+ def _set_data(buf); end
100
+ protected :_set_data
101
+
102
+ end
103
+
104
+ end
@@ -56,20 +56,27 @@ module Wx
56
56
 
57
57
  class Point
58
58
 
59
+ include Comparable
60
+
59
61
  # Returns point array (`[x, y]`)
60
62
  # @return [Array(Integer,Integer)] point as array
61
63
  def to_ary; end
62
64
 
63
- # Compare point values (Wx::Point or point array). Throws exception if incompatible.
65
+ # Compare point values (Wx::Point or point array). Returns -1,0 or 1 to indicate if this point
66
+ # is smaller, equal or greater than other (comparing <code>x*y</code> with <code>other.x*other.y</code>).
67
+ # Returns nil if incompatible.
64
68
  # @param [Wx::Point,Array(Integer,Integer)] other
65
- # @return [Boolean]
66
- def ==(other)end
69
+ # @return [Boolean,nil]
70
+ def <=>(other)end
67
71
 
68
72
  # Compare points.
69
73
  # @param [Wx::Point] other
70
74
  # @return [Boolean]
71
75
  def eql?(other)end
72
76
 
77
+ # Returns hash for point
78
+ def hash; end
79
+
73
80
  # Return a new Wx::Point with the x and y parameters both divided by
74
81
  # parameter +num+, which should be a Numeric
75
82
  # @param [Numeric] num
@@ -97,11 +104,18 @@ module Wx
97
104
  # @param [Wx::Point,Wx::Size,Array(Integer,Integer),Numeric] arg
98
105
  # @return [Wx::Point]
99
106
  def +(arg) end
100
-
107
+
108
+ # Converts point to Wx::RealPoint
109
+ # @return [Wx::RealPoint] Wx::RealPoint instance from point coordinates
110
+ def to_real_point; end
111
+ alias :to_real :to_real_point
112
+
101
113
  end
102
114
 
103
115
  class RealPoint
104
116
 
117
+ include Comparable
118
+
105
119
  # Returns point array (`[x, y]`)
106
120
  # @return [Array(Float,Float)] point as array
107
121
  def to_ary; end
@@ -111,11 +125,21 @@ module Wx
111
125
  # @return [Boolean]
112
126
  def ==(other)end
113
127
 
128
+ # Compare point values (Wx::RealPoint or point array). Returns -1,0 or 1 to indicate if this point
129
+ # is smaller, equal or greater than other (comparing <code>x*y</code> with <code>other.x*other.y</code>).
130
+ # Returns nil if incompatible.
131
+ # @param [Wx::RealPoint,Array(Float,Float)] other
132
+ # @return [Boolean,nil]
133
+ def <=>(other)end
134
+
114
135
  # Compare points.
115
136
  # @param [Wx::RealPoint] other
116
137
  # @return [Boolean]
117
138
  def eql?(other)end
118
139
 
140
+ # Returns hash for point
141
+ def hash; end
142
+
119
143
  # Return a new Wx::RealPoint with the x and y parameters both divided by
120
144
  # parameter +num+, which should be a Numeric
121
145
  # @param [Numeric] num
@@ -144,6 +168,10 @@ module Wx
144
168
  # @return [Wx::RealPoint]
145
169
  def +(arg) end
146
170
 
171
+ # Converts real point to Wx::Point
172
+ # @return [Wx::Point] Wx::Point instance from real point coordinates
173
+ def to_point; end
174
+
147
175
  end
148
176
 
149
177
  class Rect
@@ -152,7 +180,7 @@ module Wx
152
180
  # @return [Array(Integer,Integer,Integer,Integer)] rect as array
153
181
  def to_ary; end
154
182
 
155
- # Compare area values (Wx::Rect or 4-element array). Throws exception if incompatible.
183
+ # Compare area values (Wx::Rect or 4-element array). Returns false if incompatible.
156
184
  # @param [Wx::Rect,Array(Integer,Integer,Integer,Integer)] other
157
185
  # @return [Boolean]
158
186
  def ==(other)end
@@ -0,0 +1,16 @@
1
+
2
+ class Wx
3
+
4
+ class ScaledDC < Wx::DC
5
+
6
+ private :initialize
7
+
8
+ # Creates a Wx::ScaledDC instance for target and scale and
9
+ # passes the instance to the given block to draw on.
10
+ # @param [Wx::DC] target DC to draw on (scaled)
11
+ # @param [Float] scale scale factor
12
+ # @yieldparam [Wx::ScaledDC] dc scaled dc to draw on
13
+ def self.draw_on(target, scale) end
14
+ end
15
+
16
+ end
@@ -4,7 +4,7 @@
4
4
  module WxGlobalConstants
5
5
 
6
6
  class << self
7
- def search_nested(mod, sym)
7
+ def search_nested(mod, sym, path = [])
8
8
  # check any nested modules and/or (enum) classes
9
9
  const_val = nil
10
10
  mod.constants.each do |c|
@@ -16,11 +16,12 @@ module WxGlobalConstants
16
16
  elsif cv.name.start_with?('Wx::') # only search Wx namespace
17
17
  # prevent const_missing being triggered here since that may lead to unexpected results
18
18
  const_val = cv.const_get(sym) if cv.constants.include?(sym)
19
- const_val = search_nested(cv, sym) unless const_val
19
+ const_val = search_nested(cv, sym, path+[mod]) unless const_val || path.include?(cv)
20
20
  end
21
21
  when ::Module
22
22
  if cv.name.start_with?('Wx::') # only search Wx namespace
23
- const_val = cv.const_get(sym) rescue nil
23
+ const_val = cv.const_get(sym) if cv.constants.include?(sym)
24
+ const_val = search_nested(cv, sym, path+[mod]) unless const_val || path.include?(cv)
24
25
  end
25
26
  end unless mod == cv # watch out for infinite recursion
26
27
  break if const_val
data/lib/wx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wx
2
- WXRUBY_VERSION = '0.9.0-beta.10'
2
+ WXRUBY_VERSION = '0.9.0-beta.11'
3
3
  end
@@ -208,7 +208,7 @@ module WXRuby3
208
208
  # next initialize all modules without classes (keeping only those with classes)
209
209
  inc_dirs.select! do |dir|
210
210
  modreg = Spec.module_registry[dir.spec.module_name]
211
- if modreg.nil? || modreg.empty?
211
+ if !dir.spec.initialize_at_end && (modreg.nil? || modreg.empty?)
212
212
  init = "Init_#{dir.spec.module_name}()"
213
213
  decls << "extern \"C\" void #{init};"
214
214
  init_fn << " #{init};"
@@ -222,7 +222,7 @@ module WXRuby3
222
222
  cls_set = ::Set.new
223
223
  inc_dirs.select! do |dir|
224
224
  modreg = Spec.module_registry[dir.spec.module_name]
225
- if modreg && !modreg.empty? && modreg.values.all? {|base| base.nil? || modreg.has_key?(base) }
225
+ if !dir.spec.initialize_at_end && modreg && !modreg.empty? && modreg.values.all? {|base| base.nil? || modreg.has_key?(base) }
226
226
  cls_set.merge modreg.keys # remember classes
227
227
  init = "Init_#{dir.spec.module_name}()"
228
228
  decls << "extern \"C\" void #{init};"
@@ -235,7 +235,7 @@ module WXRuby3
235
235
 
236
236
  # next initialize all modules with classes depending (bases AND mixins) on classes in any modules already
237
237
  # selected until there are no more modules left or none that are left depend on any selected ones
238
- while dir_inx = inc_dirs.find_index { |dir| is_dir_with_fulfilled_deps?(dir, cls_set) }
238
+ while dir_inx = inc_dirs.find_index { |dir| !dir.spec.initialize_at_end && is_dir_with_fulfilled_deps?(dir, cls_set) }
239
239
  dir = inc_dirs[dir_inx]
240
240
  modreg = Spec.module_registry[dir.spec.module_name]
241
241
  cls_set.merge modreg.keys # remember classes
@@ -77,6 +77,7 @@ module WXRuby3
77
77
  @post_processors = processors || [:rename, :fixmodule, :fix_protected_access]
78
78
  @requirements = [requirements].flatten
79
79
  @type_maps = Typemap::Collection.new
80
+ @initialize_at_end = false
80
81
  end
81
82
 
82
83
  attr_reader :director, :package, :module_name, :name, :items, :folded_bases, :ignores, :regards, :readonly, :contracts, :event_overrides,
@@ -85,6 +86,7 @@ module WXRuby3
85
86
  :runtime_code, :header_code, :wrapper_code, :extend_code, :init_code, :interface_code,
86
87
  :nogen_sections, :post_processors, :requirements, :type_maps
87
88
  attr_writer :interface_file
89
+ attr_accessor :initialize_at_end
88
90
 
89
91
  def interface_file
90
92
  @interface_file || File.join(Config.instance.classes_path, @name + '.i')
@@ -56,9 +56,103 @@ module WXRuby3
56
56
  # Once a DataObject has been added, it belongs to the wxDataObjectComposite object,
57
57
  # and will be freed by it on destruction.
58
58
  spec.disown 'wxDataObjectSimple* dataObject'
59
+
60
+ # Add GC management for the DataObjectSimple instances added to a DataObjectComposite instance.
61
+ spec.add_header_code <<~__HEREDOC
62
+ #include <vector>
63
+ #include <map>
64
+
65
+ typedef std::vector<VALUE> data_object_list_t;
66
+ typedef std::map<wxDataObjectComposite*, data_object_list_t> composite_data_object_map_t;
67
+ static composite_data_object_map_t CompositeDataObject_Map;
68
+
69
+ static void wxRuby_markCompositeDataObjects()
70
+ {
71
+ composite_data_object_map_t::iterator it;
72
+ for( it = CompositeDataObject_Map.begin(); it != CompositeDataObject_Map.end(); ++it )
73
+ {
74
+ data_object_list_t &do_list = it->second;
75
+ for (VALUE data_obj : do_list)
76
+ {
77
+ #ifdef __WXRB_DEBUG__
78
+ if (wxRuby_TraceLevel()>1)
79
+ {
80
+ void *c_ptr = (TYPE(data_obj) == T_DATA ? DATA_PTR(data_obj) : 0);
81
+ std::wcout << "**** wxRuby_markCompositeDataObjects : " << it->first << "|" << (void*)c_ptr << std::endl;
82
+ }
83
+ #endif
84
+ rb_gc_mark(data_obj);
85
+ }
86
+ }
87
+ }
88
+
89
+ // custom implementation for wxRuby so we can handle de-registering composites
90
+ class WxRuby_DataObjectComposite : public wxDataObjectComposite
91
+ {
92
+ public:
93
+ WxRuby_DataObjectComposite() : wxDataObjectComposite() {}
94
+ virtual ~WxRuby_DataObjectComposite()
95
+ {
96
+ CompositeDataObject_Map.erase(this);
97
+ }
98
+ };
99
+ __HEREDOC
100
+ # install GC marker
101
+ spec.add_init_code 'wxRuby_AppendMarker(wxRuby_markCompositeDataObjects);'
102
+ # use custom implementation class
103
+ spec.use_class_implementation 'wxDataObjectComposite', 'WxRuby_DataObjectComposite'
104
+
105
+ # disable generating the default Add method (keep docs)
106
+ spec.ignore 'wxDataObjectComposite::Add', ignore_doc: false
107
+ # Add custom Add implementation
108
+ spec.add_extend_code 'wxDataObjectComposite', <<~__HEREDOC
109
+ void add(VALUE rb_dataObject, bool preferred=false)
110
+ {
111
+ // convert simple object
112
+ wxDataObjectSimple *simple_do;
113
+ int res = SWIG_ConvertPtr(rb_dataObject, SWIG_as_voidptrptr(&simple_do), SWIGTYPE_p_wxDataObjectSimple, SWIG_POINTER_DISOWN);
114
+ if (!SWIG_IsOK(res))
115
+ {
116
+ rb_raise(rb_eArgError, "Expected Wx::DataObjectSimple for 1");
117
+ }
118
+
119
+ // add new simple instance to registration for this composite
120
+ CompositeDataObject_Map[$self].push_back(rb_dataObject);
121
+
122
+ // add to composite
123
+ $self->Add(simple_do);
124
+ }
125
+ __HEREDOC
126
+
59
127
  end
60
128
  end # class DataObject
61
129
 
130
+ def doc_generator
131
+ DataObjectDocGenerator.new(self)
132
+ end
133
+
62
134
  end # class Director
63
135
 
136
+ class DataObjectDocGenerator < DocGenerator
137
+
138
+ def get_class_doc(clsdef)
139
+ if clsdef.name == 'wxDataObjectSimple'
140
+ []
141
+ else
142
+ super
143
+ end
144
+ end
145
+ protected :get_class_doc
146
+
147
+ def get_method_doc(mtd)
148
+ if Extractor::MethodDef === mtd && mtd.class_name == 'wxDataObject' && mtd.name == 'GetDataSize'
149
+ {}
150
+ else
151
+ super
152
+ end
153
+ end
154
+ protected :get_method_doc
155
+
156
+ end
157
+
64
158
  end # module WXRuby3
@@ -0,0 +1,123 @@
1
+ ###
2
+ # wxRuby3 wxWidgets interface director
3
+ # Copyright (c) M.J.N. Corino, The Netherlands
4
+ ###
5
+
6
+ module WXRuby3
7
+
8
+ class Director
9
+
10
+ class DataObjectSimpleBase < Director
11
+
12
+ include Typemap::DataFormat
13
+ include Typemap::DataObjectData
14
+
15
+ def setup
16
+ super
17
+ spec.items.clear
18
+ # insert literal code as #gc_as_xx does not work without parsed class items
19
+ spec.add_swig_code 'GC_MANAGE_AS_OBJECT(wxDataObjectSimpleBase);'
20
+ spec.initialize_at_end = true
21
+
22
+ spec.swig_import 'ext/wxruby3/swig/classes/include/wxDataObject.h'
23
+
24
+ spec.add_header_code <<~__HEREDOC
25
+ class wxDataObjectSimpleBase : public wxDataObjectSimple
26
+ {
27
+ public:
28
+ wxDataObjectSimpleBase(const wxDataFormat &format=wxFormatInvalid)
29
+ : wxDataObjectSimple(format) {}
30
+ virtual ~wxDataObjectSimpleBase() { }
31
+
32
+ virtual size_t GetDataSize() const { return _GetDataSize(); }
33
+ virtual size_t GetDataSize(const wxDataFormat &) const { return _GetDataSize(); }
34
+ virtual bool GetDataHere(const wxDataFormat &, void *buf) const { return _GetData(buf); }
35
+ virtual bool GetDataHere(void *data_buffer) const { return _GetData(data_buffer); }
36
+ virtual bool SetData(const wxDataFormat &, size_t len, const void *buf) { return _SetData(len, buf); }
37
+ virtual bool SetData(size_t len, const void *buf) { return _SetData(len, buf); }
38
+
39
+ protected:
40
+ virtual size_t _GetDataSize() const { return 0; }
41
+ virtual bool _GetData(void *data_buffer) const { return false; }
42
+ virtual bool _SetData(size_t len, const void *buf) { return false; }
43
+ };
44
+ __HEREDOC
45
+
46
+ spec.add_interface_code <<~__HEREDOC
47
+ class wxDataObjectSimpleBase : public wxDataObjectSimple
48
+ {
49
+ public:
50
+ wxDataObjectSimpleBase(const wxDataFormat &format=wxFormatInvalid);
51
+
52
+ virtual void GetAllFormats(wxDataFormat *formats, Direction dir=Get) const;
53
+ virtual size_t GetFormatCount(Direction dir=Get) const;
54
+ virtual wxDataFormat GetPreferredFormat(Direction dir=Get) const;
55
+
56
+ protected:
57
+ virtual size_t _GetDataSize() const;
58
+ %feature("numoutputs", "0") _GetData;
59
+ virtual VOID_BOOL _GetData(void *data_buffer) const;
60
+ virtual bool _SetData(size_t len, const void *buf);
61
+ };
62
+ __HEREDOC
63
+
64
+ # For wxDataObjectSimpleBase::GetDataHere/_GetData : the ruby method should
65
+ # return either a string containing the
66
+ # data, or nil if the data cannot be provided for some reason.
67
+ spec.map 'void *data_buffer' do
68
+
69
+ map_in ignore: true, code: ''
70
+
71
+ # "misuse" the 'check' typemap to initialize the ignored argument
72
+ # since this is inserted after any non-ignored arguments have been converted we can use these
73
+ # here
74
+ map_check temp: 'std::unique_ptr<char[]> data_buf, size_t data_size', code: <<~__CODE
75
+ data_size = arg1->GetDataSize();
76
+ data_buf = std::make_unique<char[]>(data_size);
77
+ $1 = data_buf.get ();
78
+ __CODE
79
+
80
+ # ignore C defined return value entirely (also affects directorout)
81
+ map_out ignore: 'bool'
82
+
83
+ map_argout as: {type: 'String', index: 1}, code: <<~__CODE
84
+ if (result)
85
+ {
86
+ $result = rb_utf8_str_new( (const char*)data_buf$argnum.get(), data_size$argnum);
87
+ }
88
+ else
89
+ $result = Qnil;
90
+ __CODE
91
+
92
+ # ignore the buffer pointer for now
93
+ map_directorin code: ''
94
+
95
+ map_directorargout code: <<~__CODE
96
+ if (RTEST(result))
97
+ {
98
+ if (TYPE(result) == T_STRING)
99
+ {
100
+ memcpy(data_buffer, StringValuePtr(result), RSTRING_LEN(result) );
101
+ c_result = true;
102
+ }
103
+ else
104
+ {
105
+ Swig::DirectorTypeMismatchException::raise(rb_eTypeError,
106
+ "get_data_here should return a string, or nil on failure");
107
+ }
108
+ }
109
+ else
110
+ c_result = false;
111
+ __CODE
112
+
113
+ end
114
+
115
+ # Once a DataObject has been added, it belongs to the wxDataObjectComposite object,
116
+ # and will be freed by it on destruction.
117
+ # spec.disown 'wxDataObjectSimple* dataObject'
118
+ end
119
+ end # class DataObject
120
+
121
+ end # class Director
122
+
123
+ end # module WXRuby3
@@ -52,6 +52,44 @@ module WXRuby3
52
52
  'wxSVGFileDC::EndPage'
53
53
  elsif spec.module_name == 'wxGCDC'
54
54
  spec.ignore 'wxGCDC::wxGCDC(const wxEnhMetaFileDC &)'
55
+ elsif spec.module_name == 'wxScaledDC'
56
+ spec.items.clear # wxRuby extension; no XML docs
57
+ spec.override_inheritance_chain('wxScaledDC', %w[wxDC wxObject])
58
+ # as there are no dependencies parsed from XML make sure we're initialized after Wx::DC
59
+ spec.initialize_at_end = true
60
+ spec.gc_as_temporary 'wxScaledDC'
61
+ spec.no_proxy 'wxScaledDC'
62
+ spec.include 'wxruby-ScaledDC.h'
63
+ # wxScaledDc should ever only be used in a restricted scope
64
+ # to be destructed directly after use therefor we make it abstract
65
+ # and provide a class factory method #draw_on with accepts a block.
66
+ # (as we there no classes defined in XML we cannot use add_extend_code
67
+ # so we use a workaround here)
68
+ spec.add_swig_code <<~__HEREDOC
69
+ %extend wxScaledDC {
70
+ static void draw_on(wxDC& target, double scale)
71
+ {
72
+ if (rb_block_given_p())
73
+ {
74
+ wxScaledDC scaled_dc(target, scale);
75
+ wxScaledDC* p_scaled_dc = &scaled_dc;
76
+ VALUE rb_scaled_dc = SWIG_NewPointerObj(SWIG_as_voidptr(p_scaled_dc), SWIGTYPE_p_wxScaledDC, 0);
77
+ rb_yield(rb_scaled_dc);
78
+ }
79
+ return ;
80
+ }
81
+ };
82
+ __HEREDOC
83
+ spec.swig_import %w[ext/wxruby3/swig/classes/include/wxObject.h
84
+ ext/wxruby3/swig/classes/include/wxDC.h]
85
+ spec.add_interface_code <<~__HEREDOC
86
+ class wxScaledDC : public wxDC
87
+ {
88
+ public:
89
+ wxScaledDC(wxDC& target, double scale);
90
+ virtual ~wxScaledDC() = 0;
91
+ };
92
+ __HEREDOC
55
93
  else
56
94
  # ctors of all other derived DC require a running App
57
95
  spec.require_app spec.module_name