wxruby3 0.9.0.pre.beta.10 → 0.9.0.pre.beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +85 -0
  3. data/README.md +2 -0
  4. data/assets/logo.png +0 -0
  5. data/assets/logo.svg +170 -0
  6. data/assets/logo.xcf +0 -0
  7. data/ext/wxruby3/include/wxruby-ScaledDC.h +549 -0
  8. data/ext/wxruby3/swig/wx.i +1 -1
  9. data/lib/wx/core/array_ext.rb +26 -0
  10. data/lib/wx/core/art_locator.rb +92 -0
  11. data/lib/wx/core/artprovider.rb +1 -1
  12. data/lib/wx/core/bitmap.rb +90 -53
  13. data/lib/wx/core/cursor.rb +12 -0
  14. data/lib/wx/core/data_object.rb +74 -6
  15. data/lib/wx/core/dataformat.rb +3 -1
  16. data/lib/wx/core/dc.rb +76 -52
  17. data/lib/wx/core/enum.rb +4 -0
  18. data/lib/wx/core/event.rb +38 -5
  19. data/lib/wx/core/evthandler.rb +64 -23
  20. data/lib/wx/core/icon.rb +50 -35
  21. data/lib/wx/core/id_helper.rb +32 -0
  22. data/lib/wx/core/image.rb +63 -53
  23. data/lib/wx/core/point.rb +35 -10
  24. data/lib/wx/core/real_point.rb +35 -10
  25. data/lib/wx/core/rect.rb +44 -9
  26. data/lib/wx/core/region_iterator.rb +37 -0
  27. data/lib/wx/core/size.rb +32 -5
  28. data/lib/wx/core/window.rb +8 -31
  29. data/lib/wx/doc/array_ext.rb +27 -0
  30. data/lib/wx/doc/art_locator.rb +57 -0
  31. data/lib/wx/doc/bitmap.rb +27 -0
  32. data/lib/wx/doc/clipboard.rb +12 -0
  33. data/lib/wx/doc/const.rb +77 -0
  34. data/lib/wx/doc/cursor.rb +16 -0
  35. data/lib/wx/doc/data_object.rb +103 -0
  36. data/lib/wx/doc/dc.rb +63 -46
  37. data/lib/wx/doc/event.rb +24 -0
  38. data/lib/wx/doc/events.rb +14 -0
  39. data/lib/wx/doc/evthandler.rb +24 -3
  40. data/lib/wx/doc/extra/00_starting.md +1 -1
  41. data/lib/wx/doc/extra/06_geometry.md +10 -4
  42. data/lib/wx/doc/extra/10_art.md +105 -0
  43. data/lib/wx/doc/gc_dc.rb +21 -0
  44. data/lib/wx/doc/gdi_common.rb +155 -6
  45. data/lib/wx/doc/graphics_context.rb +42 -0
  46. data/lib/wx/doc/icon.rb +18 -0
  47. data/lib/wx/doc/id_helper.rb +25 -0
  48. data/lib/wx/doc/image.rb +33 -0
  49. data/lib/wx/doc/region_iterator.rb +31 -0
  50. data/lib/wx/doc/scaled_dc.rb +17 -0
  51. data/lib/wx/doc/window.rb +18 -0
  52. data/lib/wx/global_const.rb +4 -3
  53. data/lib/wx/version.rb +1 -1
  54. data/lib/wx/wxruby/cmd/sampler.rb +3 -21
  55. data/rakelib/lib/config.rb +4 -4
  56. data/rakelib/lib/core/package.rb +6 -6
  57. data/rakelib/lib/core/spec.rb +2 -0
  58. data/rakelib/lib/director/art_provider.rb +2 -2
  59. data/rakelib/lib/director/busy_info.rb +9 -7
  60. data/rakelib/lib/director/clipboard.rb +1 -1
  61. data/rakelib/lib/director/colour_picker_ctrl.rb +1 -0
  62. data/rakelib/lib/director/data_object.rb +162 -0
  63. data/rakelib/lib/director/data_object_simple_base.rb +123 -0
  64. data/rakelib/lib/director/derived_dc.rb +134 -2
  65. data/rakelib/lib/director/dir_picker_ctrl.rb +1 -0
  66. data/rakelib/lib/director/event.rb +73 -8
  67. data/rakelib/lib/director/events.rb +19 -1
  68. data/rakelib/lib/director/file_picker_ctrl.rb +1 -0
  69. data/rakelib/lib/director/font_picker_ctrl.rb +1 -0
  70. data/rakelib/lib/director/gdicommon.rb +1 -3
  71. data/rakelib/lib/director/graphics_context.rb +89 -0
  72. data/rakelib/lib/director/help_controller.rb +2 -2
  73. data/rakelib/lib/director/html_data_object.rb +37 -0
  74. data/rakelib/lib/director/image.rb +55 -0
  75. data/rakelib/lib/director/region_iterator.rb +48 -0
  76. data/rakelib/lib/director/richtext_buffer.rb +1 -1
  77. data/rakelib/lib/director/richtext_buffer_data_object.rb +45 -0
  78. data/rakelib/lib/director/scroll_bar.rb +39 -0
  79. data/rakelib/lib/director/slider.rb +39 -0
  80. data/rakelib/lib/director/window.rb +36 -5
  81. data/rakelib/lib/director/window_disabler.rb +0 -7
  82. data/rakelib/lib/extractor/class.rb +1 -1
  83. data/rakelib/lib/extractor/function.rb +1 -1
  84. data/rakelib/lib/generate/doc.rb +26 -6
  85. data/rakelib/lib/specs/interfaces.rb +8 -1
  86. data/rakelib/lib/typemap/common.rb +1 -1
  87. data/rakelib/lib/typemap/data_object_data.rb +13 -4
  88. data/rakelib/lib/util/string.rb +29 -8
  89. data/samples/art/wxruby-128x128.png +0 -0
  90. data/samples/art/wxruby-256x256.png +0 -0
  91. data/samples/art/wxruby-64x64.png +0 -0
  92. data/samples/art/wxruby.ico +0 -0
  93. data/samples/art/wxruby.png +0 -0
  94. data/samples/drawing/graphics_drawing.rb +1 -2
  95. data/samples/propgrid/propgrid.rb +65 -65
  96. data/samples/sample.xpm +246 -470
  97. data/samples/treectrl/treectrl.rb +1 -1
  98. data/tests/art/my_art/sample.xpm +251 -0
  99. data/tests/art/sample3.xpm +251 -0
  100. data/tests/art/test_art/bitmap/sample.xpm +251 -0
  101. data/tests/art/test_art/bitmap/wxruby.bmp +0 -0
  102. data/tests/art/test_art/bitmap/wxruby.png +0 -0
  103. data/tests/art/test_art/bitmap/wxruby.xpm +251 -0
  104. data/tests/art/test_art/cursor/wxruby.bmp +0 -0
  105. data/tests/art/test_art/icon/sample.xpm +251 -0
  106. data/tests/art/test_art/icon/wxruby.ico +0 -0
  107. data/tests/art/test_art/icon/wxruby.png +0 -0
  108. data/tests/art/test_art/image/sample.xpm +251 -0
  109. data/tests/art/test_art/image/wxruby.jpg +0 -0
  110. data/tests/art/test_art/image/wxruby.png +0 -0
  111. data/tests/art/test_art/sample2.xpm +251 -0
  112. data/tests/lib/wxapp_runner.rb +64 -0
  113. data/tests/test_art.rb +91 -0
  114. data/tests/test_basic.rb +0 -5
  115. data/tests/test_clipboard.rb +149 -17
  116. data/tests/test_dc.rb +70 -0
  117. data/tests/test_dialog.rb +2 -13
  118. data/tests/test_event_handling.rb +2 -13
  119. data/tests/test_events.rb +14 -6
  120. data/tests/test_geometry.rb +67 -17
  121. data/tests/test_intl.rb +2 -15
  122. data/tests/test_item_data.rb +2 -15
  123. data/tests/test_variant.rb +1 -15
  124. data/tests/testapp.rb +0 -5
  125. data/tests/testapp_noframe.rb +0 -5
  126. metadata +56 -5
@@ -1,66 +1,103 @@
1
1
  # A platform-dependent image that can be drawn on the screen
2
- class Wx::Bitmap
3
- # Allow wxRuby to guess the type of an image file from its extension.
4
- BITMAP_TYPE_GUESS = {
5
- 'bmp' => Wx::BitmapType::BITMAP_TYPE_BMP,
6
- 'gif' => Wx::BitmapType::BITMAP_TYPE_GIF,
7
- 'ico' => Wx::BitmapType::BITMAP_TYPE_ICO,
8
- 'jpeg' => Wx::BitmapType::BITMAP_TYPE_JPEG,
9
- 'jpg' => Wx::BitmapType::BITMAP_TYPE_JPEG,
10
- 'pbm' => Wx::BitmapType::BITMAP_TYPE_PNM,
11
- 'pcx' => Wx::BitmapType::BITMAP_TYPE_PCX,
12
- 'pgm' => Wx::BitmapType::BITMAP_TYPE_PNM,
13
- 'png' => Wx::BitmapType::BITMAP_TYPE_PNG,
14
- 'pnm' => Wx::BitmapType::BITMAP_TYPE_PNM,
15
- 'ppm' => Wx::BitmapType::BITMAP_TYPE_PNM,
16
- 'tga' => Wx::BitmapType::BITMAP_TYPE_TGA,
17
- 'tif' => Wx::BitmapType::BITMAP_TYPE_TIF,
18
- 'tiff' => Wx::BitmapType::BITMAP_TYPE_TIF,
19
- 'xbm' => Wx::BitmapType::BITMAP_TYPE_XBM,
20
- 'xpm' => Wx::BitmapType::BITMAP_TYPE_XPM
21
- }
2
+ module Wx
22
3
 
23
- # Constructor copying data from an image
24
- def self.from_image(img, depth = -1)
25
- new(img, depth)
4
+ if Wx::PLATFORM == 'WXMSW'
5
+ ICON_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_ICO
6
+ elsif Wx::PLATFORM == 'WXGTK'
7
+ ICON_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_XPM
8
+ elsif Wx::PLATFORM == 'WXOSX'
9
+ ICON_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_ICO
10
+ else
11
+ ICON_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_XPM
26
12
  end
27
13
 
28
- # Create a new bitmap from an icon
29
- def self.from_icon(icon)
30
- bmp = self.new
31
- bmp.copy_from_icon(icon)
32
- bmp
14
+ if Wx::PLATFORM == 'WXMSW'
15
+ BITMAP_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_BMP
16
+ elsif Wx::PLATFORM == 'WXGTK'
17
+ BITMAP_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_XPM
18
+ elsif Wx::PLATFORM == 'WXOSX'
19
+ BITMAP_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_PICT
20
+ else
21
+ BITMAP_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_XPM
33
22
  end
34
23
 
35
- # Ruby methods that switch class are conventionally named to_foo
36
- alias :to_image :convert_to_image
24
+ if Wx::PLATFORM == 'WXMSW'
25
+ CURSOR_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_CUR
26
+ else
27
+ CURSOR_DEFAULT_TYPE = BitmapType::BITMAP_TYPE_INVALID # not supported
28
+ end
37
29
 
38
- # Redefine the initialize method so it raises an exception if a
39
- # non-existent file is given to the constructor; otherwise, wx Widgets
40
- # just carries on with an empty bitmap, which may cause faults
41
- # later. Also, be helpful and try to guess the bitmap type from the
42
- # filename if it's not specified
43
- wx_init = self.instance_method(:initialize)
44
- define_method(:initialize) do | *args |
45
- # If creating from a file, check it exists
46
- if args[0].kind_of? String
47
- if not File.exist?( File.expand_path(args[0]) )
48
- Kernel.raise(ArgumentError, "Bitmap file does not exist: #{args[0]}")
49
- end
50
- # If type not specified, try to guess it from the file extension
51
- if not args[1] and file_ext = args[0][/\w+$/]
52
- args[1] = BITMAP_TYPE_GUESS[file_ext.downcase]
30
+ class Bitmap
31
+ # Allow wxRuby to guess the type of an image file from its extension.
32
+ BITMAP_TYPE_GUESS = {
33
+ 'bmp' => Wx::BitmapType::BITMAP_TYPE_BMP,
34
+ 'gif' => Wx::BitmapType::BITMAP_TYPE_GIF,
35
+ 'ico' => Wx::BitmapType::BITMAP_TYPE_ICO,
36
+ 'jpeg' => Wx::BitmapType::BITMAP_TYPE_JPEG,
37
+ 'jpg' => Wx::BitmapType::BITMAP_TYPE_JPEG,
38
+ 'pbm' => Wx::BitmapType::BITMAP_TYPE_PNM,
39
+ 'pcx' => Wx::BitmapType::BITMAP_TYPE_PCX,
40
+ 'pgm' => Wx::BitmapType::BITMAP_TYPE_PNM,
41
+ 'png' => Wx::BitmapType::BITMAP_TYPE_PNG,
42
+ 'pnm' => Wx::BitmapType::BITMAP_TYPE_PNM,
43
+ 'ppm' => Wx::BitmapType::BITMAP_TYPE_PNM,
44
+ 'tga' => Wx::BitmapType::BITMAP_TYPE_TGA,
45
+ 'tif' => Wx::BitmapType::BITMAP_TYPE_TIF,
46
+ 'tiff' => Wx::BitmapType::BITMAP_TYPE_TIF,
47
+ 'xbm' => Wx::BitmapType::BITMAP_TYPE_XBM,
48
+ 'xpm' => Wx::BitmapType::BITMAP_TYPE_XPM
49
+ }
50
+
51
+ # Constructor copying data from an image
52
+ def self.from_image(img, depth = -1)
53
+ new(img, depth)
54
+ end
55
+
56
+ # Create a new bitmap from an icon
57
+ def self.from_icon(icon)
58
+ bmp = self.new
59
+ bmp.copy_from_icon(icon)
60
+ bmp
61
+ end
62
+
63
+ # Ruby methods that switch class are conventionally named to_foo
64
+ alias :to_image :convert_to_image
65
+
66
+ # Redefine the initialize method so it raises an exception if a
67
+ # non-existent file is given to the constructor; otherwise, wx Widgets
68
+ # just carries on with an empty bitmap, which may cause faults
69
+ # later. Also, be helpful and try to guess the bitmap type from the
70
+ # filename if it's not specified
71
+ wx_init = self.instance_method(:initialize)
72
+ define_method(:initialize) do | *args |
73
+ # If creating from a file, check it exists
74
+ if args[0].kind_of? String
75
+ if not File.exist?( File.expand_path(args[0]) )
76
+ Kernel.raise(ArgumentError, "Bitmap file does not exist: #{args[0]}")
77
+ end
78
+ # If type not specified, try to guess it from the file extension
79
+ if not args[1] and file_ext = args[0][/\w+$/]
80
+ args[1] = BITMAP_TYPE_GUESS[file_ext.downcase]
81
+ end
53
82
  end
83
+ wx_init.bind(self).call(*args)
84
+ end
85
+
86
+ # Accepts a block, which will be passed a device context which can be
87
+ # used to draw upon the Bitmap
88
+ def draw
89
+ dc = Wx::MemoryDC.new
90
+ dc.select_object(self)
91
+ yield dc
92
+ dc.select_object( Wx::NULL_BITMAP )
54
93
  end
55
- wx_init.bind(self).call(*args)
56
94
  end
57
95
 
58
- # Accepts a block, which will be passed a device context which can be
59
- # used to draw upon the Bitmap
60
- def draw
61
- dc = Wx::MemoryDC.new
62
- dc.select_object(self)
63
- yield dc
64
- dc.select_object( Wx::NULL_BITMAP )
96
+ def self.Bitmap(name, bmp_type = nil)
97
+ art_path = File.dirname(caller_path = caller_locations(1).first.absolute_path)
98
+ art_owner = File.basename(caller_path, '.*')
99
+ art_file = ArtLocator.find_art(name, art_type: :bitmap, art_path: art_path, art_section: art_owner, bmp_type: bmp_type)
100
+ ::Kernel.raise ArgumentError, "Cannot locate art file for #{name}:Bitmap" unless art_file
101
+ Bitmap.new(art_file, bmp_type)
65
102
  end
66
103
  end
@@ -0,0 +1,12 @@
1
+
2
+ module Wx
3
+
4
+ def self.Cursor(name, bmp_type = nil, *rest)
5
+ art_path = File.dirname(caller_path = caller_locations(1).first.absolute_path)
6
+ art_owner = File.basename(caller_path, '.*')
7
+ art_file = ArtLocator.find_art(name, art_type: :icon, art_path: art_path, art_section: art_owner, bmp_type: bmp_type)
8
+ ::Kernel.raise ArgumentError, "Cannot locate art file for #{name}:Cursor" unless art_file
9
+ Cursor.new(art_file, bmp_type || Wx::Bitmap::BITMAP_TYPE_GUESS[File.extname(art_file).sub(/\A\./,'')], *rest)
10
+ end
11
+
12
+ end
@@ -1,10 +1,78 @@
1
- # Provide some default implementations of these to make life easier
2
- class Wx::DataObject
3
- def get_preferred_format(direction)
4
- get_all_formats(direction).first
1
+
2
+ module Wx
3
+
4
+ # Provide some default implementations of these to make life easier
5
+ class DataObject
6
+ def get_preferred_format(direction)
7
+ get_all_formats(direction).first
8
+ end
9
+
10
+ def get_format_count(direction)
11
+ get_all_formats(direction).size
12
+ end
5
13
  end
6
14
 
7
- def get_format_count(direction)
8
- get_all_formats(direction).size
15
+ class DataObjectSimple
16
+
17
+ # implement the overloads which do not require the format arg
18
+ # using pure Ruby
19
+
20
+ wx_get_data_size = instance_method :get_data_size
21
+ define_method :get_data_size do |format = nil|
22
+ wx_get_data_size.bind(self).call(format || self.get_format)
23
+ end
24
+
25
+ wx_get_data_here = instance_method :get_data_here
26
+ define_method :get_data_here do |format = nil|
27
+ wx_get_data_here.bind(self).call(format || self.get_format)
28
+ end
29
+
30
+ wx_set_data = instance_method :set_data
31
+ define_method :set_data do |*args|
32
+ if args.size>1
33
+ format, buf = args
34
+ else
35
+ format = nil
36
+ buf = args.first
37
+ end
38
+ wx_set_data.bind(self).call(format || self.get_format, buf)
39
+ end
40
+
9
41
  end
42
+
43
+ class DataObjectSimpleBase
44
+
45
+ # implement these in pure Ruby for optimization
46
+ def get_data_size(*)
47
+ self._get_data_size
48
+ end
49
+ def get_data_here(*)
50
+ self._get_data
51
+ end
52
+
53
+ def set_data(*args)
54
+ if args.size>1
55
+ _, buf = args
56
+ else
57
+ buf = args.first
58
+ end
59
+ self._set_data(buf)
60
+ end
61
+
62
+ def _get_data_size
63
+ (_get_data || '').bytesize
64
+ end
65
+ protected :_get_data_size
66
+
67
+ end
68
+
69
+ class TextDataObject
70
+
71
+ # override this to loose the extra terminating 0 we otherwise get
72
+ def get_data_here(*)
73
+ self.get_text
74
+ end
75
+
76
+ end
77
+
10
78
  end
@@ -22,5 +22,7 @@ module Wx
22
22
  end
23
23
  DF_FILENAME = DataFormat.new( Wx::DataFormatId::DF_FILENAME )
24
24
  DF_UNICODETEXT = DataFormat.new( Wx::DataFormatId::DF_UNICODETEXT )
25
- # DF_HTML is only supported on Windows + MSVC, so don't offer it
25
+ if Wx.has_feature?(:USE_HTML) && Wx::WXWIDGETS_VERSION >= '3.3'
26
+ DF_HTML = DataFormat.new( Wx::DataFormatId::DF_HTML )
27
+ end
26
28
  end
data/lib/wx/core/dc.rb CHANGED
@@ -1,68 +1,92 @@
1
- # Class for drawing primitives and bitmaps on various outputs (screen, paper)
2
- class Wx::DC
3
- # provide Ruby-style convenience methods supporting wxDCxxxChanger-like functionality
4
1
 
5
- def with_brush(brush)
6
- begin
7
- old_brush = self.brush
8
- self.brush = brush
9
- yield(self) if block_given?
10
- ensure
11
- self.brush = old_brush
2
+ module Wx
3
+ # Class for drawing primitives and bitmaps on various outputs (screen, paper)
4
+ class DC
5
+ # provide Ruby-style convenience methods supporting wxDCxxxChanger-like functionality
6
+
7
+ def with_brush(brush)
8
+ begin
9
+ old_brush = self.brush
10
+ self.brush = brush
11
+ yield(self) if block_given?
12
+ ensure
13
+ self.brush = old_brush
14
+ end
12
15
  end
13
- end
14
16
 
15
- def with_pen(pen)
16
- begin
17
- old_pen = self.pen
18
- self.pen = pen
19
- yield(self) if block_given?
20
- ensure
21
- self.pen = old_pen
17
+ def with_pen(pen)
18
+ begin
19
+ old_pen = self.pen
20
+ self.pen = pen
21
+ yield(self) if block_given?
22
+ ensure
23
+ self.pen = old_pen
24
+ end
22
25
  end
23
- end
24
26
 
25
- def with_font(font)
26
- begin
27
- old_font = self.font
28
- self.font = font
29
- yield(self) if block_given?
30
- ensure
31
- self.font = old_font
27
+ def with_font(font)
28
+ begin
29
+ old_font = self.font
30
+ self.font = font
31
+ yield(self) if block_given?
32
+ ensure
33
+ self.font = old_font
34
+ end
32
35
  end
33
- end
34
36
 
35
- def with_text_foreground(clr)
36
- begin
37
- old = self.get_text_foreground
38
- self.text_foreground = clr
39
- yield(self) if block_given?
40
- ensure
41
- self.text_foreground = old
37
+ def with_text_foreground(clr)
38
+ begin
39
+ old = self.get_text_foreground
40
+ self.text_foreground = clr
41
+ yield(self) if block_given?
42
+ ensure
43
+ self.text_foreground = old
44
+ end
42
45
  end
43
- end
44
- alias :with_text_fg :with_text_foreground
46
+ alias :with_text_fg :with_text_foreground
45
47
 
46
- def with_text_background(clr)
47
- begin
48
- old = self.get_text_background
49
- self.text_background = clr
50
- yield(self) if block_given?
51
- ensure
52
- self.text_background = old
48
+ def with_text_background(clr)
49
+ begin
50
+ old = self.get_text_background
51
+ self.text_background = clr
52
+ yield(self) if block_given?
53
+ ensure
54
+ self.text_background = old
55
+ end
53
56
  end
57
+ alias :with_text_bg :with_text_background
58
+
59
+ def with_background_mode(mode)
60
+ begin
61
+ old = self.get_background_mode
62
+ self.background_mode = mode
63
+ yield(self) if block_given?
64
+ ensure
65
+ self.background_mode = old
66
+ end
67
+ end
68
+ alias :with_bg_mode :with_background_mode
69
+
54
70
  end
55
- alias :with_text_bg :with_text_background
56
71
 
57
- def with_background_mode(mode)
58
- begin
59
- old = self.get_background_mode
60
- self.background_mode = mode
61
- yield(self) if block_given?
62
- ensure
63
- self.background_mode = old
72
+ class MemoryDC
73
+
74
+ # convenience method for drawing on a temporary memory DC
75
+ def self.draw_on(arg)
76
+ dc = case arg
77
+ when Wx::Bitmap, Wx::DC
78
+ self.new(arg)
79
+ else
80
+ ::Kernel.raise ArgumentError, 'Expected Wx::Bitmap or Wx::DC'
81
+ end
82
+ begin
83
+ yield(dc) if block_given?
84
+ ensure
85
+ dc.select_object(Wx::NULL_BITMAP)
86
+ end
87
+ nil
64
88
  end
89
+
65
90
  end
66
- alias :with_bg_mode :with_background_mode
67
91
 
68
92
  end
data/lib/wx/core/enum.rb CHANGED
@@ -25,4 +25,8 @@ class Wx::Enum
25
25
  self.to_i == 0
26
26
  end
27
27
 
28
+ def hash
29
+ @value.hash
30
+ end
31
+
28
32
  end
data/lib/wx/core/event.rb CHANGED
@@ -1,10 +1,43 @@
1
- # Base class for all events
2
- class Wx::Event
3
- # Get the Wx id, not Ruby's deprecated Object#id
4
- alias :id :get_id
5
- end
1
+
2
+ require_relative './evthandler'
6
3
 
7
4
  module Wx
5
+
6
+ # Base class for all events
7
+ class Event
8
+
9
+ # overload the #initialize method to add a check on a
10
+ # correct match between EventType and event class
11
+ wx_init = self.instance_method(:initialize)
12
+ define_method :initialize do |evt_type = Wx::EVT_NULL, *rest|
13
+ evt_klass = Wx::EvtHandler.event_class_for_type(evt_type)
14
+ if evt_klass >= self.class
15
+ wx_init.bind(self).call(evt_type, *rest)
16
+ else
17
+ ::Kernel.raise ArgumentError, "Invalid event type #{Wx::EvtHandler.event_name_for_type(evt_type)}:#{evt_type} for class #{self.class}"
18
+ end
19
+ end
20
+
21
+ # Get the Wx id, not Ruby's deprecated Object#id
22
+ alias :id :get_id
23
+ end
24
+
25
+ class Wx::CommandEvent
26
+
27
+ # overload the #initialize method to add a check on a
28
+ # correct match between EventType and event class
29
+ wx_init = self.instance_method(:initialize)
30
+ define_method :initialize do |evt_type = Wx::EVT_NULL, *rest|
31
+ evt_klass = Wx::EvtHandler.event_class_for_type(evt_type)
32
+ if evt_klass >= self.class
33
+ wx_init.bind(self).call(evt_type, *rest)
34
+ else
35
+ ::Kernel.raise ArgumentError, "Invalid event type #{Wx::EvtHandler.event_name_for_type(evt_type)}:#{evt_type} for class #{self.class}"
36
+ end
37
+ end
38
+
39
+ end
40
+
8
41
  # reduce mapping warnings for this unpublished event class
9
42
  NcPaintEvent = Wx::Event
10
43
 
@@ -195,32 +195,73 @@ class Wx::EvtHandler
195
195
  end
196
196
 
197
197
  # Convenience evt_handler to listen to all mouse events.
198
- def evt_mouse_events(&block)
199
- evt_left_down(&block)
200
- evt_left_up(&block)
201
- evt_middle_down(&block)
202
- evt_middle_up(&block)
203
- evt_right_down(&block)
204
- evt_right_up(&block)
205
- evt_motion(&block)
206
- evt_left_dclick(&block)
207
- evt_middle_dclick(&block)
208
- evt_right_dclick(&block)
209
- evt_leave_window(&block)
210
- evt_enter_window(&block)
211
- evt_mousewheel(&block)
198
+ def evt_mouse_events(*args, &block)
199
+ evt_left_down(*args, &block)
200
+ evt_left_up(*args, &block)
201
+ evt_middle_down(*args, &block)
202
+ evt_middle_up(*args, &block)
203
+ evt_right_down(*args, &block)
204
+ evt_right_up(*args, &block)
205
+ evt_motion(*args, &block)
206
+ evt_left_dclick(*args, &block)
207
+ evt_middle_dclick(*args, &block)
208
+ evt_right_dclick(*args, &block)
209
+ evt_leave_window(*args, &block)
210
+ evt_enter_window(*args, &block)
211
+ evt_mousewheel(*args, &block)
212
212
  end
213
213
 
214
214
  # Convenience evt handler to listen to all scrollwin events.
215
- def evt_scrollwin(&block)
216
- evt_scrollwin_top(&block)
217
- evt_scrollwin_bottom(&block)
218
- evt_scrollwin_lineup(&block)
219
- evt_scrollwin_linedown(&block)
220
- evt_scrollwin_pageup(&block)
221
- evt_scrollwin_pagedown(&block)
222
- evt_scrollwin_thumbtrack(&block)
223
- evt_scrollwin_thumbrelease(&block)
215
+ def evt_scrollwin(meth = nil, &block)
216
+ evt_scrollwin_top(meth, &block)
217
+ evt_scrollwin_bottom(meth, &block)
218
+ evt_scrollwin_lineup(meth, &block)
219
+ evt_scrollwin_linedown(meth, &block)
220
+ evt_scrollwin_pageup(meth, &block)
221
+ evt_scrollwin_pagedown(meth, &block)
222
+ evt_scrollwin_thumbtrack(meth, &block)
223
+ evt_scrollwin_thumbrelease(meth, &block)
224
+ end
225
+
226
+ # Convenience evt handler to listen to all scroll events (Wx::Slider and Wx::ScrollBar)
227
+ def evt_scroll(meth = nil, &block)
228
+ evt_scroll_top(meth, &block)
229
+ evt_scroll_bottom(meth, &block)
230
+ evt_scroll_lineup(meth, &block)
231
+ evt_scroll_linedown(meth, &block)
232
+ evt_scroll_pageup(meth, &block)
233
+ evt_scroll_pagedown(meth, &block)
234
+ evt_scroll_thumbtrack(meth, &block)
235
+ evt_scroll_thumbrelease(meth, &block)
236
+ evt_scroll_changed(meth, &block)
237
+ end
238
+
239
+ # Convenience evt handler to listen to all scroll command events.
240
+ def evt_command_scroll(id, meth = nil, &block)
241
+ evt_command_scroll_top(id, meth, &block)
242
+ evt_command_scroll_bottom(id, meth, &block)
243
+ evt_command_scroll_lineup(id, meth, &block)
244
+ evt_command_scroll_linedown(id, meth, &block)
245
+ evt_command_scroll_pageup(id, meth, &block)
246
+ evt_command_scroll_pagedown(id, meth, &block)
247
+ evt_command_scroll_thumbtrack(id, meth, &block)
248
+ evt_command_scroll_thumbrelease(id, meth, &block)
249
+ evt_command_scroll_changed(id, meth, &block)
250
+ end
251
+
252
+ # add missing constants (these are redefinitions of other constants which are not documented themselves)
253
+ %i[EVT_COMMAND_SCROLL_TOP
254
+ EVT_COMMAND_SCROLL_BOTTOM
255
+ EVT_COMMAND_SCROLL_LINEUP
256
+ EVT_COMMAND_SCROLL_LINEDOWN
257
+ EVT_COMMAND_SCROLL_PAGEUP
258
+ EVT_COMMAND_SCROLL_PAGEDOWN
259
+ EVT_COMMAND_SCROLL_THUMBTRACK
260
+ EVT_COMMAND_SCROLL_THUMBRELEASE
261
+ EVT_COMMAND_SCROLL_CHANGED].each do |const|
262
+ unless Wx.const_defined?(const)
263
+ Wx.const_set(const, Wx.const_get(const.to_s.sub('EVT_COMMAND_', 'EVT_').to_sym))
264
+ end
224
265
  end
225
266
 
226
267
  if Wx.const_defined?(:EVT_DESTROY)
data/lib/wx/core/icon.rb CHANGED
@@ -1,46 +1,61 @@
1
1
  # Specific type of platform-dependent image used for frames on Windows and
2
2
  # Linux. Normally Bitmap is used
3
- class Wx::Icon
4
- # Load the type-guessing hash from Wx::Bitmap
5
- require 'wx/core/bitmap'
6
- BITMAP_TYPE_GUESS = Wx::Bitmap::BITMAP_TYPE_GUESS
7
-
8
- # Analogous to Image.from_bitmap
9
- def self.from_bitmap(bmp)
10
- ico = new
11
- ico.copy_from_bitmap(bmp)
12
- ico
13
- end
14
3
 
15
- def to_bitmap
16
- # for WXMSW platform Icon is not derived from Bitmap
17
- return self unless Wx::PLATFORM == 'WXMSW' || Wx::PLATFORM == 'WXOSX'
18
- bm = Wx::Bitmap.new
19
- bm.copy_from_icon(self)
20
- bm
21
- end
4
+ require_relative './art_locator'
5
+
6
+ module Wx
22
7
 
23
- if Wx::PLATFORM == 'WXMSW' || Wx::PLATFORM == 'WXOSX'
24
- def convert_to_image
25
- to_bitmap.convert_to_image
8
+ class Icon
9
+ # Load the type-guessing hash from Wx::Bitmap
10
+ require 'wx/core/bitmap'
11
+ BITMAP_TYPE_GUESS = Wx::Bitmap::BITMAP_TYPE_GUESS
12
+
13
+ # Analogous to Image.from_bitmap
14
+ def self.from_bitmap(bmp)
15
+ ico = new
16
+ ico.copy_from_bitmap(bmp)
17
+ ico
18
+ end
19
+
20
+ def to_bitmap
21
+ # for WXMSW platform Icon is not derived from Bitmap
22
+ return self unless Wx::PLATFORM == 'WXMSW' || Wx::PLATFORM == 'WXOSX'
23
+ bm = Wx::Bitmap.new
24
+ bm.copy_from_icon(self)
25
+ bm
26
26
  end
27
- end
28
27
 
29
- # Redefine the initialize method so it raises an exception if a
30
- # non-existent file is given to the constructor; otherwise, wx Widgets
31
- # just carries on with an empty icon, which may cause faults
32
- # later. Also guess icon type from filename, if not specified.
33
- wx_init = self.instance_method(:initialize)
34
- define_method(:initialize) do | *args |
35
- if args[0].kind_of? String
36
- if not File.exist?( File.expand_path(args[0]) )
37
- Kernel.raise(ArgumentError, "Icon file does not exist: #{args[0]}")
28
+ if Wx::PLATFORM == 'WXMSW' || Wx::PLATFORM == 'WXOSX'
29
+ def convert_to_image
30
+ to_bitmap.convert_to_image
38
31
  end
39
- # If type not specified, try to guess it from the file extension
40
- if not args[1] and ( file_ext = args[0][/\w+$/] )
41
- args[1] = BITMAP_TYPE_GUESS[file_ext.downcase]
32
+ end
33
+
34
+ # Redefine the initialize method so it raises an exception if a
35
+ # non-existent file is given to the constructor; otherwise, wx Widgets
36
+ # just carries on with an empty icon, which may cause faults
37
+ # later. Also guess icon type from filename, if not specified.
38
+ wx_init = self.instance_method(:initialize)
39
+ define_method(:initialize) do | *args |
40
+ if args[0].kind_of? String
41
+ if not File.exist?( File.expand_path(args[0]) )
42
+ Kernel.raise(ArgumentError, "Icon file does not exist: #{args[0]}")
43
+ end
44
+ # If type not specified, try to guess it from the file extension
45
+ if not args[1] and ( file_ext = args[0][/\w+$/] )
46
+ args[1] = BITMAP_TYPE_GUESS[file_ext.downcase]
47
+ end
42
48
  end
49
+ wx_init.bind(self).call(*args)
43
50
  end
44
- wx_init.bind(self).call(*args)
45
51
  end
52
+
53
+ def self.Icon(name, bmp_type = nil, *rest)
54
+ art_path = File.dirname(caller_path = caller_locations(1).first.absolute_path)
55
+ art_owner = File.basename(caller_path, '.*')
56
+ art_file = ArtLocator.find_art(name, art_type: :icon, art_path: art_path, art_section: art_owner, bmp_type: bmp_type)
57
+ ::Kernel.raise ArgumentError, "Cannot locate art file for #{name}:Icon" unless art_file
58
+ Icon.new(art_file, bmp_type, *rest)
59
+ end
60
+
46
61
  end