wxruby 1.9.9-x86-mswin32-60 → 1.9.10-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/wx/classes/bitmap.rb +29 -1
  2. data/lib/wx/classes/clipboard.rb +19 -3
  3. data/lib/wx/classes/colour.rb +6 -4
  4. data/lib/wx/classes/data_object.rb +14 -0
  5. data/lib/wx/classes/data_object_simple.rb +6 -0
  6. data/lib/wx/classes/dataformat.rb +23 -0
  7. data/lib/wx/classes/evthandler.rb +31 -4
  8. data/lib/wx/classes/genericdirctrl.rb +36 -0
  9. data/lib/wx/classes/grid.rb +8 -0
  10. data/lib/wx/classes/hboxsizer.rb +6 -0
  11. data/lib/wx/classes/icon.rb +12 -1
  12. data/lib/wx/classes/image.rb +13 -1
  13. data/lib/wx/classes/listctrl.rb +12 -0
  14. data/lib/wx/classes/point.rb +8 -0
  15. data/lib/wx/classes/rect.rb +10 -1
  16. data/lib/wx/classes/richtextctrl.rb +22 -0
  17. data/lib/wx/classes/size.rb +9 -0
  18. data/lib/wx/classes/sizer.rb +18 -3
  19. data/lib/wx/classes/toolbar.rb +4 -6
  20. data/lib/wx/classes/vboxsizer.rb +6 -0
  21. data/lib/wx/classes/window.rb +7 -0
  22. data/lib/wx/classes/xmlresource.rb +17 -0
  23. data/lib/wx/helpers.rb +16 -1
  24. data/lib/wx/keyword_ctors.rb +3 -2
  25. data/lib/wx/keyword_defs.rb +27 -5
  26. data/lib/wx/version.rb +1 -1
  27. data/lib/wxruby2.exp +0 -0
  28. data/lib/wxruby2.lib +0 -0
  29. data/lib/wxruby2.so +0 -0
  30. data/samples/bigdemo/About.rbw +1 -1
  31. data/samples/bigdemo/wxCheckListBox.rbw +40 -50
  32. data/samples/bigdemo/wxListCtrl_virtual.rbw +8 -3
  33. data/samples/bigdemo/wxSashWindow.rbw +2 -2
  34. data/samples/bigdemo/wxTreeCtrl.rbw +4 -3
  35. data/samples/calendar/calendar.rb +143 -158
  36. data/samples/dialogs/dialogs.rb +74 -0
  37. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  38. data/samples/event/update_ui_event.rb +70 -0
  39. data/samples/grid/gridtablebase.rb +43 -29
  40. data/samples/mdi/mdi.rb +22 -14
  41. data/samples/minimal/minimal.rb +3 -3
  42. data/samples/text/format-text-bold.png +0 -0
  43. data/samples/text/format-text-italic.png +0 -0
  44. data/samples/text/format-text-underline.png +0 -0
  45. data/samples/text/rich_textctrl.rb +98 -0
  46. data/samples/text/textctrl.rb +0 -2
  47. data/samples/treectrl/treectrl.rb +10 -18
  48. data/samples/xrc/xrc_sample.rb +48 -68
  49. metadata +14 -2
@@ -38,6 +38,7 @@ DIALOGS_PROGRESS = 22
38
38
  DIALOGS_BUSYINFO = 23
39
39
  DIALOGS_FIND = 24
40
40
  DIALOGS_REPLACE = 25
41
+ DIALOGS_PREFS = 26
41
42
 
42
43
  $my_canvas = nil
43
44
 
@@ -125,6 +126,71 @@ class MyModelessDialog < Dialog
125
126
  end
126
127
  end
127
128
 
129
+ # PropertySheetDialog is specialised for doing preferences dialogs; it
130
+ # contains a BookCtrl of some sort
131
+ class MyPrefsDialog < Wx::PropertySheetDialog
132
+ def initialize(parent)
133
+ # Using Book type other than Notebook needs two-step construction
134
+ super()
135
+ self.sheet_style = Wx::PROPSHEET_BUTTONTOOLBOOK
136
+ self.sheet_outer_border = 1
137
+ self.sheet_inner_border = 2
138
+ img_list = Wx::ImageList.new(32, 32)
139
+ img_list << std_bitmap(Wx::ART_NORMAL_FILE)
140
+ img_list << std_bitmap(Wx::ART_CDROM)
141
+ img_list << std_bitmap(Wx::ART_REPORT_VIEW)
142
+
143
+ create(parent, -1, "Preferences")
144
+ create_buttons(Wx::ID_OK|Wx::ID_CANCEL)
145
+ book_ctrl.image_list = img_list
146
+ book_ctrl.add_page(file_panel(book_ctrl), "File", false, 0)
147
+ book_ctrl.add_page(cdrom_panel(book_ctrl), "CD ROM", false, 1)
148
+
149
+ layout_dialog
150
+ end
151
+
152
+ # Gets one of the rather ugly standard bitmaps from ArtProvider
153
+ def std_bitmap(art_id)
154
+ Wx::ArtProvider.bitmap(art_id, Wx::ART_TOOLBAR, [32, 32])
155
+ end
156
+
157
+ def file_panel(book)
158
+ panel = Wx::Panel.new(book)
159
+ panel.sizer = Wx::VBoxSizer.new
160
+
161
+ cb1 = Wx::CheckBox.new(panel, :label => 'Show hidden files')
162
+ panel.sizer.add(cb1, 0, Wx::ALL, 5)
163
+
164
+ cb2 = Wx::CheckBox.new(panel, :label => 'Always show extensions')
165
+ panel.sizer.add(cb2, 0, Wx::ALL, 5)
166
+
167
+ cb3 = Wx::CheckBox.new(panel, :label => 'Show icons')
168
+ panel.sizer.add(cb3, 0, Wx::ALL, 5)
169
+
170
+ cb4 = Wx::CheckBox.new(panel, :label => 'Show owner')
171
+ panel.sizer.add(cb4, 0, Wx::ALL, 5)
172
+
173
+ st = Wx::StaticText.new(panel, :label => "Sort by:")
174
+ panel.sizer.add(st, 0, Wx::ALL, 5)
175
+
176
+ cb1 = Wx::Choice.new(panel, :choices => %w|Name Created Modified Size|)
177
+ panel.sizer.add(cb1, 0, Wx::ALL, 5)
178
+ panel
179
+ end
180
+
181
+ def cdrom_panel(book)
182
+ panel = Wx::Panel.new(book)
183
+ panel.sizer = Wx::VBoxSizer.new
184
+
185
+ choices = [ 'Show files', 'Play media', 'Run CD', 'Do nothing' ]
186
+ rb = Wx::RadioBox.new( panel,
187
+ :label => 'When opening CD',
188
+ :choices => choices,
189
+ :major_dimension => 1)
190
+ panel.sizer.add(rb, 0, Wx::GROW|Wx::ALL, 5)
191
+ panel
192
+ end
193
+ end
128
194
 
129
195
  class MyCanvas < ScrolledWindow
130
196
  def initialize(parent)
@@ -185,6 +251,7 @@ class MyFrame < Frame
185
251
  evt_menu(DIALOGS_TIP) {|event| on_show_tip(event) }
186
252
  evt_menu(DIALOGS_PROGRESS) {|event| on_show_progress(event) }
187
253
  evt_menu(DIALOGS_BUSYINFO) {|event| on_show_busy_info(event) }
254
+ evt_menu(DIALOGS_PREFS) {|event| on_show_prefs(event) }
188
255
  evt_menu(DIALOGS_FIND) {|event| on_show_find_dialog(event) }
189
256
  evt_menu(DIALOGS_REPLACE) {|event| on_show_replace_dialog(event) }
190
257
  evt_find(-1) {|event| on_find_dialog(event) }
@@ -521,6 +588,11 @@ class MyFrame < Frame
521
588
  end
522
589
 
523
590
 
591
+ def on_show_prefs(event)
592
+ dialog = MyPrefsDialog.new(self)
593
+ dialog.show_modal
594
+ end
595
+
524
596
  def on_show_progress(event)
525
597
 
526
598
  dialog = ProgressDialog.new("Progress dialog example",
@@ -697,8 +769,10 @@ class MyApp < App
697
769
  file_menu.append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D")
698
770
  file_menu.append(DIALOGS_PROGRESS, "Pro&gress dialog\tCtrl-G")
699
771
  file_menu.append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B")
772
+ file_menu.append(DIALOGS_PREFS, "Propert&y sheet dialog\tCtrl-Y")
700
773
  file_menu.append(DIALOGS_FIND, "&Find dialog\tCtrl-F", "", ITEM_CHECK)
701
774
  file_menu.append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F", "", ITEM_CHECK)
775
+
702
776
  file_menu.append_separator()
703
777
  file_menu.append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-W")
704
778
  file_menu.append(DIALOGS_MODELESS, "Modeless &dialog\tCtrl-Z", "", ITEM_CHECK)
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ require 'rubygems' rescue LoadError
6
+
7
+ require 'wx'
8
+
9
+ # Simple test application for keyword arguments to Sizer#add_item and
10
+ # ToolBar#add_item. Originally contributed by Chauk-Mean P
11
+
12
+ Wx::App.run do
13
+ frame = Wx::Frame.new( nil,
14
+ :title => 'ToolBar and Sizer API enhancements') do
15
+
16
+ sizer = Wx::BoxSizer.new(Wx::VERTICAL)
17
+
18
+ button1 = Wx::Button.new(self, :label => 'Button 1')
19
+ button2 = Wx::Button.new(self, :label => 'Button 2')
20
+ button3 = Wx::Button.new(self, :label => 'Button 3')
21
+
22
+ # Sizer#add_item usage
23
+ # use of positional arguments
24
+ sizer.add_item(button1, -1, 1, Wx::EXPAND)
25
+ # use of a spacer
26
+ sizer.add_item([20, 15])
27
+ # use of keyword arguments without index
28
+ sizer.add_item(button3, :proportion => 1, :flag => Wx::EXPAND)
29
+ # use of keyword arguments with index specified
30
+ sizer.add_item(button2, :index => 1, :proportion => 1, :flag => Wx::EXPAND)
31
+ self.sizer = sizer
32
+
33
+ # ToolBar#add_item usage
34
+ toolbar = create_tool_bar( Wx::TB_HORIZONTAL|Wx::TB_FLAT )
35
+ # provide only a bitmap
36
+ new_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_NEW) )
37
+ # use of keyword arguments without pos
38
+ save_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_FILE_SAVE),
39
+ :short_help => "Save")
40
+ # use of keyword arguments with pos
41
+ open_item_id = toolbar.add_item( Wx::ArtProvider.bitmap(Wx::ART_FILE_OPEN),
42
+ :position => 1,
43
+ :short_help => "Open")
44
+ toolbar.realize
45
+
46
+ # tool item event handling
47
+ evt_tool new_item_id do
48
+ Wx::message_box "New clicked"
49
+ end
50
+
51
+ end
52
+
53
+ frame.show
54
+ end
55
+
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require 'rubygems'
4
+ rescue LoadError
5
+ end
6
+ require 'wx'
7
+
8
+ # Demonstrating the use of evt_update_ui to keep menu items and controls
9
+ # in sync in being enabled/disabled, checked/unchecked.
10
+ #
11
+ # evt_update_ui is called repeatedly whenever the item is (or is about
12
+ # to become) visible; by calling methods on the passed event object, the
13
+ # state of the control is updated. For complex applications, this can be
14
+ # a lot simpler (less code, more reliable) than having to remember to
15
+ # update all the relevant controls and items whenever the state changes.
16
+ #
17
+ # In the example below, the application is globally in edit mode. This
18
+ # mode can be changed either from a menu item, or via a
19
+ # checkbox. Whichever is used to change, the state of the other should
20
+ # be kept in sync
21
+ class UpdateUIFrame < Wx::Frame
22
+ def initialize
23
+ super(nil, :title => 'Update UI example', :size => [ 400, 300 ])
24
+ @edit_mode = false
25
+
26
+ # First, set up the menus
27
+ self.menu_bar = Wx::MenuBar.new
28
+ menu_edit = Wx::Menu.new
29
+
30
+ # Toggle case-change menu item
31
+ menu_edit.append_check_item(Wx::ID_EDIT, 'Allow case change')
32
+ # When the item is called, toggle edit mode
33
+ evt_menu(Wx::ID_EDIT) { @edit_mode = ! @edit_mode }
34
+ # Give the menu item a check or not, depending on mode
35
+ evt_update_ui(Wx::ID_EDIT) { | evt | evt.check(@edit_mode) }
36
+
37
+ # Upcase menu item
38
+ up_case = menu_edit.append('Upper case')
39
+ evt_menu(up_case) { @txt.value = @txt.value.upcase }
40
+ evt_update_ui(up_case) { | evt | evt.enable(@edit_mode) }
41
+
42
+ # Lowercase menu item
43
+ up_case = menu_edit.append('Lower case')
44
+ evt_menu(up_case) { @txt.value = @txt.value.downcase }
45
+ evt_update_ui(up_case) { | evt | evt.enable(@edit_mode) }
46
+
47
+ menu_bar.append(menu_edit, "&Edit")
48
+
49
+ # Second, the frame contents
50
+ self.sizer = Wx::BoxSizer.new(Wx::VERTICAL)
51
+
52
+ # A text control
53
+ @txt = Wx::TextCtrl.new( self,
54
+ :value => 'Welcome to wxRuby',
55
+ :style => Wx::TE_MULTILINE )
56
+ sizer.add(@txt, 1, Wx::GROW|Wx::ALL, 5)
57
+
58
+ # A checkbox, use the Wx::ID_EDIT id to share evt code with the
59
+ # corresponding menu item
60
+ @cbx = Wx::CheckBox.new( self,
61
+ :id => Wx::ID_EDIT,
62
+ :label => 'Allow case change')
63
+ evt_checkbox(@cbx) { @edit_mode = ! @edit_mode }
64
+
65
+ sizer.add(@cbx, 0, Wx::RIGHT|Wx::ALL, 5)
66
+ sizer.layout
67
+ end
68
+ end
69
+
70
+ Wx::App.run { UpdateUIFrame.new.show }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2009 wxRuby development team
3
3
  # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
4
  begin
5
5
  require 'rubygems'
@@ -24,9 +24,12 @@ class MyGridTable < Wx::GridTableBase
24
24
  super()
25
25
  @rows = rows
26
26
  @cols = cols
27
- @val = 'a'
27
+ @number_col = 1
28
28
  end
29
29
 
30
+ # Letter labels for columns
31
+ COLS = ('AA' .. 'ZZ').to_a
32
+
30
33
  # Firstly, a GridTableBase must indicate the size of the grid in
31
34
  # terms of rows ...
32
35
  def get_number_rows
@@ -41,9 +44,25 @@ class MyGridTable < Wx::GridTableBase
41
44
  # Most importantly, it should be able to return any given cell's
42
45
  # contents, given its row and column reference
43
46
  def get_value(row, col)
44
- "#{@val} - #{row}"
47
+ if col == @number_col
48
+ (row * 5).to_s
49
+ else
50
+ "#{row}:#{COLS[col]}"
51
+ end
45
52
  end
46
53
 
54
+ # This is not needed if the cell contents are simply strings. However,
55
+ # if you wish to use custom GridCellRenderers and/or GridCellEditors,
56
+ # this should return a type name which has the correct renderer /
57
+ # editor defined for it in the Grid, using register_
58
+ def get_type_name(row, col)
59
+ if col == @number_col
60
+ "NUMBER"
61
+ else
62
+ "STRING"
63
+ end
64
+ end
65
+
47
66
  # It should also return the attributes that should apply to any given
48
67
  # cell; this example give alternate rows red text letters
49
68
  def get_attr(row, col, attr_kind)
@@ -61,7 +80,7 @@ class MyGridTable < Wx::GridTableBase
61
80
 
62
81
  # It may also provide labels for the columns and rows
63
82
  def get_col_label_value(col)
64
- "Col: #{col}"
83
+ COLS[col]
65
84
  end
66
85
 
67
86
  # If the Grid is to support write as well as read operations,
@@ -73,23 +92,27 @@ class MyGridTable < Wx::GridTableBase
73
92
  end
74
93
  end
75
94
 
76
- # A derivative class illustrating that it is possible to change
77
- # parameters of the GridTable and have the main control update.
78
- class MyMutableGridTable < MyGridTable
79
- def increment_value
80
- @val = @val.succ
81
- end
82
- end
83
-
84
-
85
95
  class GridFrame < Wx::Frame
86
96
  def initialize()
87
- super(nil, :title => 'GridTableBase demo')
88
- main_sizer = Wx::BoxSizer.new(Wx::VERTICAL)
97
+ super(nil, :title => 'GridTableBase demo', :size => [600, 300])
98
+ main_sizer = Wx::VBoxSizer.new
89
99
  # Create a grid and associate an instance of the GridTable as the
90
100
  # data provider for the grid
91
101
  @grid = Wx::Grid.new(self)
92
- @grid.table = MyMutableGridTable.new(10, 10)
102
+
103
+ # Define the renderers and editors used by the different data types
104
+ # displayed in this Grid. The type of a given cell is determined by
105
+ # calling the source's get_type_name method; see above.
106
+ @grid.register_data_type( "STRING",
107
+ Wx::GridCellStringRenderer.new,
108
+ Wx::GridCellTextEditor.new )
109
+ @grid.register_data_type( "NUMBER",
110
+ Wx::GridCellNumberRenderer.new,
111
+ Wx::GridCellNumberEditor.new(0, 500) )
112
+
113
+ # Set the data source
114
+ @grid.table = MyGridTable.new(10, 10)
115
+
93
116
 
94
117
  main_sizer.add(@grid, 1, Wx::EXPAND|Wx::ALL, 5)
95
118
 
@@ -100,29 +123,20 @@ class GridFrame < Wx::Frame
100
123
  # When resizing the grid to have a new number of rows or columns,
101
124
  # need to allocate a new grid table source
102
125
  evt_button(butt_1) do
103
- @grid.table = MyMutableGridTable.new( @grid.table.rows + 1,
104
- @grid.table.cols)
126
+ @grid.table = MyGridTable.new( @grid.table.rows + 1,
127
+ @grid.table.cols)
105
128
  @grid.refresh
106
129
  end
107
130
  butt_sizer.add(butt_1)
108
131
 
109
132
  butt_2 = Wx::Button.new(self, :label => "Add column")
110
133
  evt_button(butt_2) do
111
- @grid.table = MyMutableGridTable.new( @grid.table.rows,
112
- @grid.table.cols + 1)
134
+ @grid.table = MyGridTable.new( @grid.table.rows,
135
+ @grid.table.cols + 1)
113
136
  @grid.refresh
114
137
  end
115
138
  butt_sizer.add(butt_2)
116
139
 
117
- # For other changes, can just change a value in the existing
118
- # GridTable
119
- butt_3 = Wx::Button.new(self, :label => "Increment letter")
120
- evt_button(butt_3) do
121
- @grid.table.increment_value
122
- @grid.refresh
123
- end
124
- butt_sizer.add(butt_3)
125
-
126
140
  main_sizer.add(butt_sizer, 0, Wx::EXPAND|Wx::ALL, 5)
127
141
  self.sizer = main_sizer
128
142
  end
data/samples/mdi/mdi.rb CHANGED
@@ -7,14 +7,22 @@ rescue LoadError
7
7
  end
8
8
  require 'wx'
9
9
 
10
- # Simple MDI-based parent frame with menus to create, cycle through and
11
- # close child frames within in.
10
+ # Demonstrates a simple MDI (Multiple Document Interface) parent frame
11
+ # with menus to create, cycle through and close child frames within in.
12
12
  #
13
- # NB: MDI is only properly implemented on Windows, and is simulated by
14
- # using a Notebook on Linux and OS X. Therefore its use is not
15
- # recommended for cross-platform applications. An alternative interface
16
- # strategy may be to use separate frames, or possibly the AUI classes.
17
- class MyFrame < Wx::MDIParentFrame
13
+ # Note that MDI is only properly natively implemented on Windows, and
14
+ # even there it is deprecated by Microsoft as an application interface
15
+ # style.
16
+ #
17
+ # On Linux/GTK, Wx simulates an MDI by using a Notebook. On OS X, MDI is
18
+ # simulated simply by ordinary separate frames, and Next/Preview and
19
+ # Tile/Cascade are unimplemented.
20
+ #
21
+ # For these reasons, MDI is not recommended for cross-platform
22
+ # development. Alternative interface strategies include using separate
23
+ # frames, or the AUI classes.
24
+
25
+ class MDIFrame < Wx::MDIParentFrame
18
26
  def initialize(title)
19
27
  super(nil, :title => title, :size => [ 500, 400 ] )
20
28
 
@@ -63,15 +71,15 @@ class MyFrame < Wx::MDIParentFrame
63
71
  def create_child
64
72
  @child_number += 1
65
73
  name = "Child #{@child_number.to_s}"
66
- Wx::MDIChildFrame.new(self, -1, name)
74
+ child = Wx::MDIChildFrame.new(self, :title => name)
75
+ # Note that this is required on OS X; if no child frames are shown,
76
+ # then nothing is shown at all.
77
+ child.show
67
78
  end
68
79
  end
69
80
 
70
- class MDIApp < Wx::App
71
- def on_init
72
- frame = MyFrame.new("MDI App")
73
- frame.show
74
- end
81
+ Wx::App.run do
82
+ MDIFrame.new("MDI Application").show # may return false on OS X
83
+ true
75
84
  end
76
85
 
77
- MDIApp.new.main_loop
@@ -18,10 +18,10 @@ class MinimalFrame < Wx::Frame
18
18
  # The main application frame has no parent (nil)
19
19
  super(nil, :title => title, :size => [ 400, 300 ])
20
20
 
21
- # PNG can be used on all platforms, but icon type must be specified
22
- # to work on Windows. Note that OS X doesn't have "Frame" icons.
21
+ # Give the frame an icon. PNG is a good choice of format for
22
+ # cross-platform images. Note that OS X doesn't have "Frame" icons.
23
23
  icon_file = File.join( File.dirname(__FILE__), "mondrian.png")
24
- self.icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_PNG)
24
+ self.icon = Wx::Icon.new(icon_file)
25
25
 
26
26
  menu_bar = Wx::MenuBar.new
27
27
  # The "file" menu
Binary file
Binary file
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
3
+ # Freely reusable code: see SAMPLES-LICENSE.TXT for details
4
+
5
+ # RichTextCtrl sample by Chauk-Mean P
6
+ #
7
+ # RichTextCtrl is a sophisticated styled text editing component. This
8
+ # short sample shows the basics, but RichTextCtrl supports numerous
9
+ # other text characteristics (font, size, colour, super/subscript), as
10
+ # well as paragraph alignment and spacing, and bullets. It permits named
11
+ # text styles to be created and organised in stylesheets. It can output
12
+ # to HTML and XML, and facilities are provided for printing.
13
+ #
14
+ # Icons are taken from the Tango Icon Theme.
15
+
16
+ begin
17
+ require 'rubygems'
18
+ rescue LoadError
19
+ end
20
+ require 'wx'
21
+
22
+ class RichTextFrame < Wx::Frame
23
+
24
+ def initialize
25
+ super( nil, :title => "RichTextCtrl sample", :size => [800, 600] )
26
+
27
+ toolbar = create_tool_bar( Wx::TB_HORIZONTAL|Wx::NO_BORDER|
28
+ Wx::TB_FLAT|Wx::TB_TEXT )
29
+ toolbar.tool_bitmap_size = [ 32, 32 ]
30
+
31
+ bold_bmp = bmp_from_png("format-text-bold.png")
32
+ toolbar.add_check_tool( Wx::ID_BOLD, "Bold",
33
+ bold_bmp, bold_bmp, "Apply bold")
34
+
35
+ italic_bmp = bmp_from_png("format-text-italic.png")
36
+ toolbar.add_check_tool( Wx::ID_ITALIC, "Italic",
37
+ italic_bmp, italic_bmp, "Apply italic")
38
+
39
+ underline_bmp = bmp_from_png("format-text-underline.png")
40
+ toolbar.add_check_tool( Wx::ID_UNDERLINE, "Underline",
41
+ underline_bmp, underline_bmp, "Apply underline")
42
+ toolbar.realize
43
+
44
+ editor = Wx::RichTextCtrl.new(self, :style => Wx::WANTS_CHARS)
45
+ editor.begin_font_size(18)
46
+
47
+ editor.begin_bold
48
+ editor.write_text "Simple RichTextCtrl sample"
49
+ editor.end_bold
50
+ editor.newline
51
+ editor.begin_italic
52
+ editor.write_text "Use the formatting buttons then type some text or "
53
+ editor.write_text "select some text and use the buttons to apply the formatting.\n"
54
+ editor.end_italic
55
+
56
+ # Apply / unapply bold to selection
57
+ evt_tool(Wx::ID_BOLD) do
58
+ editor.apply_bold_to_selection
59
+ end
60
+
61
+ # Keep the pressed / unpressed state of the button in sync with the
62
+ # current selection in the text ctrl
63
+ evt_update_ui(Wx::ID_BOLD) do |evt|
64
+ evt.check(editor.selection_bold?)
65
+ end
66
+
67
+ evt_tool(Wx::ID_ITALIC) do
68
+ editor.apply_italic_to_selection
69
+ end
70
+
71
+ evt_update_ui(Wx::ID_ITALIC) do |evt|
72
+ evt.check(editor.selection_italics?)
73
+ end
74
+
75
+ evt_tool(Wx::ID_UNDERLINE) do
76
+ editor.apply_underline_to_selection
77
+ end
78
+
79
+ evt_update_ui(Wx::ID_UNDERLINE) do |evt|
80
+ evt.check(editor.selection_underlined?)
81
+ end
82
+ end
83
+
84
+ # Return a new bitmap corresponding to the specified PNG filename
85
+ def bmp_from_png(filename)
86
+ img_file = File.join( File.dirname(__FILE__), filename)
87
+ Wx::Bitmap.new(img_file, Wx::BITMAP_TYPE_PNG)
88
+ end
89
+ end
90
+
91
+
92
+ # The Application
93
+ Wx::App.run do
94
+ self.app_name = 'RichTextCtrl sample'
95
+ frame = RichTextFrame.new
96
+ frame.centre
97
+ frame.show
98
+ end