wxruby 1.9.9-x86-linux → 1.9.10-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) 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.so +0 -0
  28. data/samples/bigdemo/About.rbw +1 -1
  29. data/samples/bigdemo/wxCheckListBox.rbw +40 -50
  30. data/samples/bigdemo/wxListCtrl_virtual.rbw +8 -3
  31. data/samples/bigdemo/wxSashWindow.rbw +2 -2
  32. data/samples/bigdemo/wxTreeCtrl.rbw +4 -3
  33. data/samples/calendar/calendar.rb +143 -158
  34. data/samples/dialogs/dialogs.rb +74 -0
  35. data/samples/etc/toolbar_sizer_additem.rb +55 -0
  36. data/samples/event/update_ui_event.rb +70 -0
  37. data/samples/grid/gridtablebase.rb +43 -29
  38. data/samples/mdi/mdi.rb +22 -14
  39. data/samples/minimal/minimal.rb +3 -3
  40. data/samples/text/format-text-bold.png +0 -0
  41. data/samples/text/format-text-italic.png +0 -0
  42. data/samples/text/format-text-underline.png +0 -0
  43. data/samples/text/rich_textctrl.rb +98 -0
  44. data/samples/text/textctrl.rb +0 -2
  45. data/samples/treectrl/treectrl.rb +10 -18
  46. data/samples/xrc/xrc_sample.rb +48 -68
  47. metadata +222 -210
@@ -11,12 +11,27 @@ class Wx::Sizer
11
11
  def add_item(item, *mixed_args)
12
12
  args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
13
13
 
14
- # Call add to append if default position
14
+ full_args = []
15
+
16
+ # extract the width and the height in the case of a spacer
17
+ # defined as an array
18
+ if item.kind_of?(Array)
19
+ Kernel.raise ArgumentError,
20
+ "Invalid Sizer specification : [width, height] expected" if item.size != 2
21
+ full_args << item[0] << item[1]
22
+ else
23
+ full_args << item
24
+ end
25
+
26
+ # update the full arguments list with the optional arguments (except index)
15
27
  idx = args.shift
28
+ full_args.concat(args)
29
+
30
+ # Call add to append if default position
16
31
  if idx == -1
17
- add(item, *args)
32
+ add(*full_args)
18
33
  else
19
- insert(idx, item, *args)
34
+ insert(idx, *full_args)
20
35
  end
21
36
  end
22
37
  end
@@ -5,21 +5,19 @@ class Wx::ToolBar
5
5
  ADD_ITEM_PARAMS = [ Wx::Parameter[ :position, -1 ],
6
6
  Wx::Parameter[ :id, -1 ],
7
7
  Wx::Parameter[ :label, "" ],
8
- Wx::Parameter[ :bitmap, Wx::NULL_BITMAP ],
9
8
  Wx::Parameter[ :bitmap2, Wx::NULL_BITMAP ],
10
9
  Wx::Parameter[ :kind, Wx::ITEM_NORMAL ],
11
10
  Wx::Parameter[ :short_help, "" ],
12
11
  Wx::Parameter[ :long_help, "" ],
13
12
  Wx::Parameter[ :client_data, nil ] ]
14
13
 
15
- def add_item(*mixed_args)
14
+ def add_item(bitmap, *mixed_args)
16
15
  args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
17
- if args[3] == Wx::NULL_BITMAP
18
- Kernel.raise ArgumentError, "Main button bitmap may not be NULL"
19
- end
20
16
 
21
- # Call add_tool to append if default position
22
17
  pos = args.shift
18
+ args.insert(2, bitmap)
19
+
20
+ # Call add_tool to append if default position
23
21
  if pos == -1
24
22
  add_tool(*args)
25
23
  else
@@ -0,0 +1,6 @@
1
+ # Just a shortcut version for creating a vertical box sizer
2
+ class Wx::VBoxSizer < Wx::BoxSizer
3
+ def initialize
4
+ super(Wx::VERTICAL)
5
+ end
6
+ end
@@ -11,6 +11,13 @@ class Wx::Window
11
11
  # In case a more explicit option is preferred.
12
12
  alias :wx_id :get_id
13
13
 
14
+ # The name of Wx::Window#raise conflicts with Ruby's core Kernel#raise
15
+ # method. This can cause unexpected errors when undecorated #raise is
16
+ # used inside a Window method. For wxRuby 2.0 it's too late to remove
17
+ # Window#raise completely, but for now, offer alternatives to
18
+ # raise/lower that could replace them in future versions.
19
+ alias :bring_to_front :raise
20
+ alias :send_to_back :lower
14
21
 
15
22
  # Recursively searches all windows below +self+ and returns the first
16
23
  # window which has the id +an_id+. This corresponds to the find_window
@@ -34,4 +34,21 @@ class Wx::XmlResource
34
34
  end
35
35
  fname
36
36
  end
37
+
38
+ # Returns a Wx::Wizard object from the element named +name+ in the
39
+ # loaded XRC file. The Wizard will have the parent +parent+.
40
+ #
41
+ # This method is not available in wxWidgets, but is here for
42
+ # completeness and also to document how to use load_object (see
43
+ # below).
44
+ def load_wizard(parent, name)
45
+ wiz = Wx::Wizard.new()
46
+ load_wizard_subclass(wiz, parent, name)
47
+ wiz
48
+ end
49
+
50
+ # Completes the loading of a incomplete instance of Wx::Wizard.
51
+ def load_wizard_subclass(wizard, parent, name)
52
+ load_object(wizard, parent, name, "wxWizard")
53
+ end
37
54
  end
@@ -8,7 +8,6 @@ module Wx
8
8
  # structs containing the keyword name and default value for each
9
9
  # possible argument. +mixed_args+ is an array which may optionally end
10
10
  # with a set of named arguments
11
-
12
11
  def self.args_as_list(param_spec, *mixed_args)
13
12
  # get keyword arguments from mixed args if supplied, else empty
14
13
  kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
@@ -27,4 +26,20 @@ module Wx
27
26
  Kernel.raise ArgumentError,
28
27
  "Bad arg composition of #{mixed_args.inspect}"
29
28
  end
29
+
30
+ # Given an integer constant +int_const+, returns an array Wx constant
31
+ # names which have this value. If a string +prefix+ is supplied, find
32
+ # only constants whose names begin with this prefix. For example,
33
+ # passing "EVT" would return only constants with a name like
34
+ # Wx::EVT_XXX
35
+ #
36
+ # This is primarily useful for debugging, when an unknown constant is
37
+ # returned, eg as an event type id.
38
+ def self.find_const(sought, prefix = "")
39
+ consts = constants.grep(/\A#{prefix}/)
40
+ consts.find_all do | c |
41
+ c_val = const_get(c)
42
+ c_val.instance_of?(Fixnum) and c_val == sought
43
+ end
44
+ end
30
45
  end
@@ -122,8 +122,9 @@ module Wx
122
122
  # API constructor
123
123
  def wx_ctor_params(*params)
124
124
  self.param_spec += params.map do | param |
125
- param.kind_of?(Hash) ? Parameter[*param.to_a.flatten] :
126
- Parameter[param, STANDARD_DEFAULTS[param] ]
125
+ param.kind_of?(Hash) ?
126
+ Parameter[ param.keys.first, param.values.first ] :
127
+ Parameter[ param, STANDARD_DEFAULTS[param] ]
127
128
  end
128
129
  end
129
130
 
@@ -156,19 +156,29 @@ Wx::define_keyword_ctors('ToolBarTool') do
156
156
  wx_ctor_params :long_help => ''
157
157
  end
158
158
 
159
+ # Similar to notebook but using choice control
160
+ Wx::define_keyword_ctors('Choicebook') do
161
+ wx_ctor_params :id, :pos, :size, :style, :name => 'choiceBook'
162
+ end
163
+
159
164
  # Notebook class
160
165
  Wx::define_keyword_ctors('Notebook') do
161
166
  wx_ctor_params :id, :pos, :size, :style, :name => 'noteBook'
162
167
  end
163
168
 
164
- # Similar to notebook but using list control - undocumented
169
+ # Similar to notebook but using list control
165
170
  Wx::define_keyword_ctors('Listbook') do
166
171
  wx_ctor_params :id, :pos, :size, :style, :name => 'listBook'
167
172
  end
168
173
 
169
- # Similar to notebook but using choice control
170
- Wx::define_keyword_ctors('Choicebook') do
171
- wx_ctor_params :id, :pos, :size, :style, :name => 'choiceBook'
174
+ # Similar to notebook but using toolbar
175
+ Wx::define_keyword_ctors('Toolbook') do
176
+ wx_ctor_params :id, :pos, :size, :style, :name => 'toolBook'
177
+ end
178
+
179
+ # Similar to notebook but using tree control
180
+ Wx::define_keyword_ctors('Treebook') do
181
+ wx_ctor_params :id, :pos, :size, :style, :name => 'treeBook'
172
182
  end
173
183
 
174
184
  # wxSashWindow: Window with four optional sashes that can be dragged
@@ -268,7 +278,6 @@ Wx::define_keyword_ctors('PrintDialog') do
268
278
  wx_ctor_params :data
269
279
  end
270
280
 
271
-
272
281
  # Simple message box dialog
273
282
  Wx::define_keyword_ctors('MessageDialog') do
274
283
  wx_ctor_params :message => ''
@@ -277,6 +286,13 @@ Wx::define_keyword_ctors('MessageDialog') do
277
286
  wx_ctor_params :pos
278
287
  end
279
288
 
289
+ # Property editing dialog
290
+ Wx::define_keyword_ctors('PropertySheetDialog') do
291
+ wx_ctor_params :id, :title
292
+ wx_ctor_params :pos, :size, :style => Wx::DEFAULT_DIALOG_STYLE
293
+ wx_ctor_params :name => 'propertySheetDialog'
294
+ end
295
+
280
296
  ### CONTROLS
281
297
 
282
298
  # Push button control, displaying text
@@ -517,6 +533,11 @@ Wx::define_keyword_ctors('HtmlListBox') do
517
533
  wx_ctor_params :id, :pos, :size, :style, :name => 'HtmlListBoxNameStr'
518
534
  end
519
535
 
536
+ Wx::define_keyword_ctors('DatePickerCtrl') do
537
+ wx_ctor_params :id, :dt => Time.now
538
+ wx_ctor_params :pos, :size, :style, :validator, :name => 'dateCtrl'
539
+ end
540
+
520
541
  Wx::define_keyword_ctors('RichTextCtrl') do
521
542
  wx_ctor_params :id, :value => ''
522
543
  wx_ctor_params :pos, :size, :style => Wx::TE_MULTILINE
@@ -531,6 +552,7 @@ Wx::define_keyword_ctors('RichTextStyleListCtrl') do
531
552
  wx_ctor_params :id, :pos, :size, :style
532
553
  end
533
554
 
555
+
534
556
  # FIXME - SymbolPickerDialog is hard to because the parent argument is
535
557
  # in a strange place.
536
558
 
@@ -1,3 +1,3 @@
1
1
  module Wx
2
- WXRUBY_VERSION = '1.9.9'
2
+ WXRUBY_VERSION = '1.9.10'
3
3
  end
Binary file
@@ -10,7 +10,7 @@ class MyAboutBox < Wx::Dialog
10
10
  title = Wx::StaticText.new(self, -1, "WxRuby Demo!", Wx::Point.new(20, 20))
11
11
  title.set_font(headerFont)
12
12
 
13
- rVersion = Wx::StaticText.new(self, -1, "Running on Ruby version " + VERSION + " on " + RUBY_PLATFORM, Wx::Point.new(20,100))
13
+ rVersion = Wx::StaticText.new(self, -1, "Running on Ruby version " + RUBY_VERSION + " on " + RUBY_PLATFORM, Wx::Point.new(20,100))
14
14
  rVersion.set_font(bodyFont)
15
15
  rVersion.set_foreground_colour(Wx::RED)
16
16
 
@@ -10,62 +10,52 @@ require 'wx'
10
10
 
11
11
 
12
12
  class TestPanel < Wx::Panel
13
- def initialize(parent, log)
14
- super(parent, -1)
15
- @log = log
16
-
17
- sampleList = %w(one two three four five six seven eight nine ten eleven twelve thirteen fourteen)
18
-
19
- Wx::StaticText.new(self, -1, "This example uses the wxCheckListBox control.", Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE)
20
-
21
- lb = Wx::CheckListBox.new(self, 60, Wx::Point.new(80,50), Wx::Size.new(80,120), sampleList)
22
- evt_listbox(60) {|event| on_evt_listbox(event)}
23
- evt_listbox_dclick(60) {|event| on_evt_listbox_dclick(event)}
24
- lb.set_selection(0)
25
- @lb = lb
26
-
27
- pos = lb.get_position().x + lb.get_size().get_width() + 25
28
- btn = Wx::Button.new(self, -1, "Test SetString", Wx::Point.new(pos,50))
29
- evt_button(btn.get_id()) {|event| on_test_button(event)}
30
-
31
- evt_right_up {|event| on_do_popup(event)}
32
- end
13
+ attr_reader :lb
14
+ def initialize(parent, log)
15
+ super parent
16
+ @log = log
33
17
 
34
- def on_evt_listbox(event)
35
- @log.write_text("evt_listbox: " + event.get_string())
36
- end
18
+ sample_list = %w|one two three four five six seven eight
19
+ nine ten eleven twelve thirteen fourteen|
37
20
 
38
- def on_evt_listbox_dclick(event)
39
- @log.write_text("evt_listbox_dclick:")
40
- end
21
+ self.sizer = Wx::VBoxSizer.new
22
+ tx = Wx::StaticText.new( self,
23
+ :label => "This example uses the wxCheckListBox control.")
24
+ sizer.add(tx, 0, Wx::ALL, 5)
25
+ @lb = Wx::CheckListBox.new(self, :choices => sample_list)
26
+ sizer.add(lb, 1, Wx::ALL|Wx::GROW, 5)
27
+ evt_listbox lb, :on_evt_listbox
28
+ evt_listbox_dclick lb, :on_evt_listbox_dclick
29
+ lb.set_selection(0)
41
30
 
42
- def on_test_button(event)
43
- @lb.set_string(4, "FUBAR")
44
- end
45
-
46
- def on_do_popup(event)
47
- menu = Wx::Menu.new()
48
- # Make this first item bold
49
- menu.append(50000, "Normal item &1")
50
- menu.append(50001, "Normal item &2")
51
- menu.append(50002, "Normal item &3")
52
- menu.append(50003, "Normal item &4")
53
-
54
- popup_menu(menu, event.get_position())
55
- menu.destroy()
56
- event.skip()
57
- end
31
+
32
+ btn = Wx::Button.new(self, :label => "Test SetString")
33
+ sizer.add(btn, 0, Wx::ALL, 5)
34
+ evt_button btn, :on_test_button
35
+ end
36
+
37
+ def on_evt_listbox(event)
38
+ @log.write_text("evt_listbox: " + event.get_string())
39
+ end
40
+
41
+ def on_evt_listbox_dclick(event)
42
+ @log.write_text("evt_listbox_dclick:")
43
+ end
44
+
45
+ def on_test_button(event)
46
+ @lb.set_string(4, "FUBAR")
47
+ end
58
48
  end
59
49
 
60
50
  module Demo
61
- def Demo.run(frame, nb, log)
62
- win = TestPanel.new(nb, log)
63
- return win
64
- end
65
-
66
- def Demo.overview
67
- return "A checklistbox is like a listbox, but allows items to be checked or unchecked."
68
- end
51
+ def Demo.run(frame, nb, log)
52
+ win = TestPanel.new(nb, log)
53
+ return win
54
+ end
55
+
56
+ def Demo.overview
57
+ return "A checklistbox is like a listbox, but allows items to be checked or unchecked."
58
+ end
69
59
  end
70
60
 
71
61
  if __FILE__ == $0
@@ -8,10 +8,14 @@ end
8
8
  require 'wx'
9
9
 
10
10
 
11
-
11
+ # A virtual ListCtrl loads its items as needed from a virtual store. So
12
+ # it's useful for linking to existing data sources, or for displaying
13
+ # very large lists. It's subclassed in ruby, and the item_count is set;
14
+ # the get_item_text methods should return how to display a given line.
12
15
  class TestVirtualList < Wx::ListCtrl
13
16
  def initialize(parent, log)
14
- super(parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE, Wx::LC_REPORT | Wx::LC_VIRTUAL | Wx::LC_HRULES | Wx::LC_VRULES)
17
+ super parent, :style => Wx::LC_REPORT|Wx::LC_VIRTUAL|
18
+ Wx::LC_HRULES| Wx::LC_VRULES
15
19
  @log = log
16
20
 
17
21
  @il = Wx::ImageList.new(16,16)
@@ -27,7 +31,8 @@ class TestVirtualList < Wx::ListCtrl
27
31
  set_column_width(1,175)
28
32
  set_column_width(2,175)
29
33
 
30
- set_item_count(1000000)
34
+ # Important - call this
35
+ self.item_count = 10_000
31
36
 
32
37
  @attr1 = Wx::ListItemAttr.new()
33
38
  @attr1.set_background_colour(Wx::Colour.new("YELLOW"))
@@ -81,8 +81,8 @@ class TestPanel < Wx::Panel
81
81
 
82
82
 
83
83
  def on_sash_drag(event)
84
- if event.get_drag_status == Wx::SASH_STATUS_OUT_OF_RANGE:
85
- @log.write_text('drag == out of range')
84
+ if event.get_drag_status == Wx::SASH_STATUS_OUT_OF_RANGE
85
+ @log.write_text('drag == out of range')
86
86
  return
87
87
  end
88
88
 
@@ -79,20 +79,21 @@ class TestTreeCtrlPanel < Wx::Panel
79
79
  @root = @tree.add_root("The Root Item")
80
80
  @tree.set_item_image(@root, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
81
81
  @tree.set_item_image(@root, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
82
-
83
82
  0.upto(15) do |x|
84
83
  child = @tree.append_item(@root, "Item " + x.to_s())
85
84
  @tree.set_item_image(child, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
86
85
  @tree.set_item_image(child, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
86
+ character = "a"
87
87
  0.upto(4) do |y|
88
- last = @tree.append_item(child, "item " + x.to_s() + "-" + (?a + y).chr)
88
+ last = @tree.append_item(child, "item " + x.to_s() + "-" + character)
89
89
  @tree.set_item_image(last, fldridx, Wx::TREE_ITEM_ICON_NORMAL)
90
90
  @tree.set_item_image(last, fldropenidx, Wx::TREE_ITEM_ICON_EXPANDED)
91
91
  0.upto(4) do |z|
92
- item = @tree.append_item(last, "item " + x.to_s() + "-" + (?a + y).chr + "-" + z.to_s())
92
+ item = @tree.append_item(last, "item " + x.to_s() + "-" + character + "-" + z.to_s())
93
93
  @tree.set_item_image(item, fileidx, Wx::TREE_ITEM_ICON_NORMAL)
94
94
  @tree.set_item_image(item, smileidx, Wx::TREE_ITEM_ICON_SELECTED)
95
95
  end
96
+ character.succ!
96
97
  end
97
98
  end
98
99
 
@@ -7,14 +7,8 @@ rescue LoadError
7
7
  end
8
8
  require 'wx'
9
9
 
10
-
11
10
  include Wx
12
11
 
13
- require 'date'
14
-
15
-
16
- Calendar_File_About = ID_ABOUT
17
- Calendar_File_Quit = ID_EXIT
18
12
  Calendar_Cal_Monday = 200
19
13
  Calendar_Cal_Holidays = 201
20
14
  Calendar_Cal_Special = 202
@@ -24,123 +18,114 @@ Calendar_Cal_SeqMonth = 205
24
18
  Calendar_Cal_SurroundWeeks = 206
25
19
 
26
20
 
27
- def format_date(d)
28
- return "#{d.year}-#{d.mon}-#{d.day}"
29
- end
30
-
31
21
  class MyCalendar < CalendarCtrl
32
- def initialize(parent, display_frame, initial_date, calendar_flags)
33
- super(parent, -1,
34
- initial_date,
35
- DEFAULT_POSITION,
36
- DEFAULT_SIZE,
37
- calendar_flags | RAISED_BORDER)
38
-
39
- @display = display_frame
40
- @date = initial_date
41
- @weekday_names = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
42
-
43
- id = get_id
44
- evt_calendar(id) {|event| on_calendar(event)}
45
- evt_calendar_month(id) {on_cal_month_change}
46
- evt_calendar_year(id) {on_cal_year_change}
47
- evt_calendar_sel_changed(id) {|event| on_calendar_change(event)}
48
- evt_calendar_weekday_clicked(id) {|event| on_calendar_weekday_click(event)}
49
- end
22
+ def initialize(parent, display_frame, initial_date, calendar_flags)
23
+ super( parent,
24
+ :date => initial_date,
25
+ :style => calendar_flags | RAISED_BORDER)
26
+
27
+ @display = display_frame
28
+ @date = initial_date
29
+ @weekday_names = %w|Sun Mon Tue Wed Thu Fri Sat|
30
+
31
+ evt_calendar self, :on_calendar
32
+ evt_calendar_month self, :on_cal_month_change
33
+ evt_calendar_year self, :on_cal_year_change
34
+ evt_calendar_sel_changed self, :on_calendar_change
35
+ evt_calendar_weekday_clicked self, :on_calendar_weekday_click
36
+ end
50
37
 
51
38
  def on_calendar(event)
52
- @date = event.get_date
53
- @display.set_date(@date)
54
- end
39
+ @display.date = event.date
40
+ end
55
41
 
56
42
  def on_calendar_change(event)
57
- @date = event.get_date
58
- log_status("Selected date: #{format_date(@date)}")
59
- end
43
+ @date = event.date
44
+ log_status("Selected date: #{@date.strftime('%Y-%M-%D')}")
45
+ end
60
46
 
61
47
  def on_cal_month_change
62
- log_status("Calendar month changed")
63
- end
48
+ log_status("Calendar month changed")
49
+ end
64
50
 
65
51
  def on_cal_year_change
66
- log_status("Calendar year changed")
67
- end
52
+ log_status("Calendar year changed")
53
+ end
68
54
 
69
55
  def on_calendar_weekday_click(event)
70
- wday = event.get_week_day
71
- log_status("Clicked on #{@weekday_names[wday]}")
72
- end
73
-
74
- attr_reader :date
56
+ wday = event.week_day
57
+ log_status("Clicked on #{@weekday_names[wday]}")
58
+ end
59
+
60
+ attr_reader :date
75
61
  end
76
62
 
77
63
  class MyFrame < Frame
78
- def initialize(title)
79
- super(nil, -1, title)
80
- @panel = Wx::Panel.new(self)
81
- add_menu_bar
82
- add_status_bar
64
+ def initialize(title)
65
+ super(nil, -1, title)
66
+ @panel = Wx::Panel.new(self)
67
+ add_menu_bar
68
+ add_status_bar
83
69
 
84
- @calendar_flags = CAL_MONDAY_FIRST | CAL_SHOW_HOLIDAYS
70
+ @calendar_flags = CAL_MONDAY_FIRST | CAL_SHOW_HOLIDAYS
85
71
 
86
- now = DateTime.now
87
- @calendar = MyCalendar.new(@panel, self, now, @calendar_flags)
72
+ @calendar = MyCalendar.new(@panel, self, Time.now, @calendar_flags)
88
73
 
89
- @sizer = BoxSizer.new(VERTICAL)
90
- configure_window
74
+ @sizer = BoxSizer.new(VERTICAL)
75
+ configure_window
91
76
 
92
- evt_menu(Calendar_File_Quit) {on_quit}
93
- evt_menu(Calendar_File_About) {on_about}
77
+ evt_menu Wx::ID_EXIT, :on_quit
78
+ evt_menu Wx::ID_ABOUT, :on_about
94
79
 
95
- evt_menu(Calendar_Cal_Monday) {|event| on_cal_monday(event)}
96
- evt_menu(Calendar_Cal_Holidays) {|event| on_cal_holidays(event)}
97
- evt_menu(Calendar_Cal_Special) {|event| on_cal_special(event)}
80
+ evt_menu Calendar_Cal_Monday, :on_cal_monday
81
+ evt_menu Calendar_Cal_Holidays, :on_cal_holidays
82
+ evt_menu Calendar_Cal_Special, :on_cal_special
98
83
 
99
- evt_menu(Calendar_Cal_Month) {|event| on_cal_allow_month(event)}
100
- evt_menu(Calendar_Cal_Year) {|event| on_cal_allow_year(event)}
84
+ evt_menu Calendar_Cal_Month, :on_cal_allow_month
85
+ evt_menu Calendar_Cal_Year, :on_cal_allow_year
101
86
 
102
- evt_menu(Calendar_Cal_SeqMonth) {|event| on_cal_seq_month(event)}
103
- evt_menu(Calendar_Cal_SurroundWeeks) {|event| on_cal_show_surrounding_weeks(event)}
87
+ evt_menu Calendar_Cal_SeqMonth, :on_cal_seq_month
88
+ evt_menu Calendar_Cal_SurroundWeeks, :on_cal_show_surrounding_weeks
104
89
 
105
- evt_update_ui(Calendar_Cal_Year) {|event| on_allow_year_update(event)}
106
- end
107
-
108
- def add_menu_bar
109
- # create a menu bar
90
+ evt_update_ui Calendar_Cal_Year, :on_allow_year_update
91
+ end
92
+
93
+ def add_menu_bar
94
+ # create a menu bar
110
95
  menu_file = Menu.new
111
96
 
112
- menu_file.append(Calendar_File_About, "&About...\tCtrl-A", "Show about dialog")
113
- menu_file.append_separator()
114
- menu_file.append(Calendar_File_Quit, "E&xit\tAlt-X", "Quit self program")
97
+ menu_file.append(Wx::ID_ABOUT, "&About...\tCtrl-A", "Show about dialog")
98
+ menu_file.append_separator
99
+ menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit self program")
115
100
 
116
101
  menu_cal = Menu.new
117
102
  menu_cal.append(Calendar_Cal_Monday,
118
- "Monday &first weekday\tCtrl-F",
119
- "Toggle between Mon and Sun as the first week day",
120
- ITEM_CHECK)
103
+ "Monday &first weekday\tCtrl-F",
104
+ "Toggle between Mon and Sun as the first week day",
105
+ ITEM_CHECK)
121
106
  menu_cal.append(Calendar_Cal_Holidays, "Show &holidays\tCtrl-H",
122
- "Toggle highlighting the holidays",
123
- ITEM_CHECK)
107
+ "Toggle highlighting the holidays",
108
+ ITEM_CHECK)
124
109
  menu_cal.append(Calendar_Cal_Special, "Highlight &special dates\tCtrl-S",
125
- "Test custom highlighting",
126
- ITEM_CHECK)
110
+ "Test custom highlighting",
111
+ ITEM_CHECK)
127
112
  menu_cal.append(Calendar_Cal_SurroundWeeks,
128
- "Show s&urrounding weeks\tCtrl-W",
129
- "Show the neighbouring weeks in the prev/next month",
130
- ITEM_CHECK)
131
- menu_cal.append_separator()
113
+ "Show s&urrounding weeks\tCtrl-W",
114
+ "Show the neighbouring weeks in the prev/next month",
115
+ ITEM_CHECK)
116
+ menu_cal.append_separator
132
117
  menu_cal.append(Calendar_Cal_SeqMonth,
133
- "To&ggle month selector style\tCtrl-G",
134
- "Use another style for the calendar controls",
135
- ITEM_CHECK)
118
+ "To&ggle month selector style\tCtrl-G",
119
+ "Use another style for the calendar controls",
120
+ ITEM_CHECK)
136
121
  menu_cal.append(Calendar_Cal_Month, "&Month can be changed\tCtrl-M",
137
- "Allow changing the month in the calendar",
138
- ITEM_CHECK)
122
+ "Allow changing the month in the calendar",
123
+ ITEM_CHECK)
139
124
  menu_cal.append(Calendar_Cal_Year, "&Year can be changed\tCtrl-Y",
140
- "Allow changing the year in the calendar",
141
- ITEM_CHECK)
125
+ "Allow changing the year in the calendar",
126
+ ITEM_CHECK)
142
127
 
143
- # now append the freshly created menu to the menu bar...
128
+ # now append the freshly created menu to the menu bar...
144
129
  menu_bar = MenuBar.new
145
130
  menu_bar.append(menu_file, "&File")
146
131
  menu_bar.append(menu_cal, "&Calendar")
@@ -150,89 +135,89 @@ class MyFrame < Frame
150
135
  menu_bar.check(Calendar_Cal_Month, TRUE)
151
136
  menu_bar.check(Calendar_Cal_Year, TRUE)
152
137
 
153
- # ... and attach self menu bar to the frame
154
- set_menu_bar(menu_bar)
155
- end
156
-
157
- def add_status_bar
158
- # create a status bar just for fun (by default with 1 pane only)
159
- create_status_bar
160
- set_status_text("Welcome to Windows!")
161
- end
162
-
163
- def configure_window
164
- @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
165
- @sizer.set_size_hints(@panel)
166
- layout
167
- @panel.set_sizer(@sizer)
168
- end
169
-
138
+ # ... and attach self menu bar to the frame
139
+ self.menu_bar = menu_bar
140
+ end
141
+
142
+ def add_status_bar
143
+ # create a status bar just for fun (by default with 1 pane only)
144
+ create_status_bar
145
+ set_status_text("Welcome to Windows!")
146
+ end
147
+
148
+ def configure_window
149
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
150
+ @sizer.size_hints = @panel
151
+ layout
152
+ @panel.sizer = @sizer
153
+ end
154
+
170
155
  def on_quit
171
156
  # true is to force the frame to close
172
157
  close(true)
173
- end
158
+ end
174
159
 
175
160
  def on_about
176
- message_box("wxRuby CalendarCtrl sample\nby Kevin Smith\n" +
161
+ message_box("wxRuby CalendarCtrl sample\nby Kevin Smith\n" +
177
162
  "based on the wxWidgets version by Vadim Zeitlin",
178
163
  "About Calendar", OK | ICON_INFORMATION, self)
179
- end
164
+ end
180
165
 
181
166
  def on_cal_monday(event)
182
- enable = get_menu_bar().is_checked(event.get_id())
183
- toggle_cal_style(enable, CAL_MONDAY_FIRST)
184
- end
167
+ enable = get_menu_bar().is_checked(event.get_id())
168
+ toggle_cal_style(enable, CAL_MONDAY_FIRST)
169
+ end
185
170
 
186
171
  def on_cal_holidays(event)
187
- enable = get_menu_bar().is_checked(event.get_id())
172
+ enable = get_menu_bar().is_checked(event.get_id())
188
173
  @calendar.enable_holiday_display(enable)
189
- end
174
+ end
190
175
 
191
- def on_cal_special(event)
192
- highlight_special(get_menu_bar().is_checked(event.get_id()))
193
- end
176
+ def on_cal_special(event)
177
+ highlight_special(get_menu_bar().is_checked(event.get_id()))
178
+ end
194
179
 
195
- def on_cal_allow_month(event)
196
- allow = get_menu_bar().is_checked(event.get_id())
180
+ def on_cal_allow_month(event)
181
+ allow = get_menu_bar().is_checked(event.get_id())
197
182
  @calendar.enable_month_change(allow)
198
- end
183
+ end
199
184
 
200
- def on_cal_allow_year(event)
201
- allow = get_menu_bar().is_checked(event.get_id())
185
+ def on_cal_allow_year(event)
186
+ allow = get_menu_bar().is_checked(event.get_id())
202
187
  @calendar.enable_year_change(allow)
203
- end
188
+ end
204
189
 
205
- def on_cal_seq_month(event)
206
- allow = get_menu_bar().is_checked(event.get_id())
207
- toggle_cal_style(allow, CAL_SEQUENTIAL_MONTH_SELECTION)
208
- end
190
+ def on_cal_seq_month(event)
191
+ allow = get_menu_bar().is_checked(event.get_id())
192
+ toggle_cal_style(allow, CAL_SEQUENTIAL_MONTH_SELECTION)
193
+ end
209
194
 
210
- def on_cal_show_surrounding_weeks(event)
211
- allow = get_menu_bar().is_checked(event.get_id())
212
- toggle_cal_style(allow, CAL_SHOW_SURROUNDING_WEEKS)
213
- end
195
+ def on_cal_show_surrounding_weeks(event)
196
+ allow = get_menu_bar().is_checked(event.get_id())
197
+ toggle_cal_style(allow, CAL_SHOW_SURROUNDING_WEEKS)
198
+ end
214
199
 
215
- def on_allow_year_update(event)
216
- event.enable( get_menu_bar().is_checked(Calendar_Cal_Month))
217
- end
200
+ def on_allow_year_update(event)
201
+ event.enable( get_menu_bar().is_checked(Calendar_Cal_Month))
202
+ end
218
203
 
219
- def toggle_cal_style(on,flag)
204
+ def toggle_cal_style(on,flag)
220
205
  style = @calendar.get_window_style_flag
221
206
  date = @calendar.date
222
207
  @sizer.detach(@calendar)
223
208
  @calendar.destroy
224
- if on
225
- style |= flag
226
- else
227
- style &= ~flag
228
- end
229
- @calendar = MyCalendar.new(@panel, self, date, style)
230
- @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
231
- @panel.layout
209
+ if on
210
+ style |= flag
211
+ else
212
+ style &= ~flag
232
213
  end
214
+ @calendar = MyCalendar.new(@panel, self, date, style)
215
+ @sizer.add(@calendar, 0, Wx::ALIGN_CENTRE|Wx::ALL, 5)
216
+ @panel.layout
217
+ end
233
218
 
234
- def highlight_special(on)
235
- if on
219
+ def highlight_special(on)
220
+ if on
236
221
  attr_red_circle = CalendarDateAttr.new(CAL_BORDER_ROUND, RED)
237
222
  attr_green_square = CalendarDateAttr.new(CAL_BORDER_SQUARE, GREEN)
238
223
  # This wraps correctly, but causes problems because the colour is freed
@@ -243,28 +228,28 @@ class MyFrame < Frame
243
228
  @calendar.set_attr(17, attr_red_circle)
244
229
  @calendar.set_attr(29, attr_green_square)
245
230
  # @calendar.set_attr(13, attr_header_like)
246
- else
231
+ else
247
232
  @calendar.reset_attr(17)
248
233
  @calendar.reset_attr(29)
249
234
  # @calendar.reset_attr(13)
250
- end
251
- @calendar.refresh()
252
235
  end
253
-
254
- def set_date(d)
255
- str = "%s-%s-%s" % [ d.year, d.mon, d.day ]
256
- Wx::MessageDialog.new( self, "The selected date is #{str}",
257
- "Date chosen" ).show_modal
258
- end
259
-
236
+ @calendar.refresh()
237
+ end
238
+
239
+ def set_date(d)
240
+ str = "%s-%s-%s" % [ d.year, d.mon, d.day ]
241
+ Wx::MessageDialog.new( self, "The selected date is #{str}",
242
+ "Date chosen" ).show_modal
243
+ end
244
+
260
245
  end
261
246
 
262
247
 
263
248
  class RbApp < App
264
- def on_init()
265
- frame = MyFrame.new("Calendar Windows sample")
249
+ def on_init()
250
+ frame = MyFrame.new("Calendar Windows sample")
266
251
  frame.show(true)
267
- end
252
+ end
268
253
  end
269
254
 
270
255
  a = RbApp.new