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.
- data/lib/wx/classes/bitmap.rb +29 -1
- data/lib/wx/classes/clipboard.rb +19 -3
- data/lib/wx/classes/colour.rb +6 -4
- data/lib/wx/classes/data_object.rb +14 -0
- data/lib/wx/classes/data_object_simple.rb +6 -0
- data/lib/wx/classes/dataformat.rb +23 -0
- data/lib/wx/classes/evthandler.rb +31 -4
- data/lib/wx/classes/genericdirctrl.rb +36 -0
- data/lib/wx/classes/grid.rb +8 -0
- data/lib/wx/classes/hboxsizer.rb +6 -0
- data/lib/wx/classes/icon.rb +12 -1
- data/lib/wx/classes/image.rb +13 -1
- data/lib/wx/classes/listctrl.rb +12 -0
- data/lib/wx/classes/point.rb +8 -0
- data/lib/wx/classes/rect.rb +10 -1
- data/lib/wx/classes/richtextctrl.rb +22 -0
- data/lib/wx/classes/size.rb +9 -0
- data/lib/wx/classes/sizer.rb +18 -3
- data/lib/wx/classes/toolbar.rb +4 -6
- data/lib/wx/classes/vboxsizer.rb +6 -0
- data/lib/wx/classes/window.rb +7 -0
- data/lib/wx/classes/xmlresource.rb +17 -0
- data/lib/wx/helpers.rb +16 -1
- data/lib/wx/keyword_ctors.rb +3 -2
- data/lib/wx/keyword_defs.rb +27 -5
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.so +0 -0
- data/samples/bigdemo/About.rbw +1 -1
- data/samples/bigdemo/wxCheckListBox.rbw +40 -50
- data/samples/bigdemo/wxListCtrl_virtual.rbw +8 -3
- data/samples/bigdemo/wxSashWindow.rbw +2 -2
- data/samples/bigdemo/wxTreeCtrl.rbw +4 -3
- data/samples/calendar/calendar.rb +143 -158
- data/samples/dialogs/dialogs.rb +74 -0
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/gridtablebase.rb +43 -29
- data/samples/mdi/mdi.rb +22 -14
- data/samples/minimal/minimal.rb +3 -3
- data/samples/text/format-text-bold.png +0 -0
- data/samples/text/format-text-italic.png +0 -0
- data/samples/text/format-text-underline.png +0 -0
- data/samples/text/rich_textctrl.rb +98 -0
- data/samples/text/textctrl.rb +0 -2
- data/samples/treectrl/treectrl.rb +10 -18
- data/samples/xrc/xrc_sample.rb +48 -68
- metadata +222 -210
data/lib/wx/classes/sizer.rb
CHANGED
@@ -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
|
-
|
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(
|
32
|
+
add(*full_args)
|
18
33
|
else
|
19
|
-
insert(idx,
|
34
|
+
insert(idx, *full_args)
|
20
35
|
end
|
21
36
|
end
|
22
37
|
end
|
data/lib/wx/classes/toolbar.rb
CHANGED
@@ -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
|
data/lib/wx/classes/window.rb
CHANGED
@@ -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
|
data/lib/wx/helpers.rb
CHANGED
@@ -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
|
data/lib/wx/keyword_ctors.rb
CHANGED
@@ -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) ?
|
126
|
-
Parameter[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
|
|
data/lib/wx/keyword_defs.rb
CHANGED
@@ -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
|
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
|
170
|
-
Wx::define_keyword_ctors('
|
171
|
-
wx_ctor_params :id, :pos, :size, :style, :name => '
|
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
|
|
data/lib/wx/version.rb
CHANGED
data/lib/wxruby2.so
CHANGED
Binary file
|
data/samples/bigdemo/About.rbw
CHANGED
@@ -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 " +
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
35
|
-
|
36
|
-
end
|
18
|
+
sample_list = %w|one two three four five six seven eight
|
19
|
+
nine ten eleven twelve thirteen fourteen|
|
37
20
|
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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() + "-" +
|
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() + "-" +
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
53
|
-
|
54
|
-
end
|
39
|
+
@display.date = event.date
|
40
|
+
end
|
55
41
|
|
56
42
|
def on_calendar_change(event)
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
63
|
-
|
48
|
+
log_status("Calendar month changed")
|
49
|
+
end
|
64
50
|
|
65
51
|
def on_cal_year_change
|
66
|
-
|
67
|
-
|
52
|
+
log_status("Calendar year changed")
|
53
|
+
end
|
68
54
|
|
69
55
|
def on_calendar_weekday_click(event)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
70
|
+
@calendar_flags = CAL_MONDAY_FIRST | CAL_SHOW_HOLIDAYS
|
85
71
|
|
86
|
-
|
87
|
-
@calendar = MyCalendar.new(@panel, self, now, @calendar_flags)
|
72
|
+
@calendar = MyCalendar.new(@panel, self, Time.now, @calendar_flags)
|
88
73
|
|
89
|
-
|
90
|
-
|
74
|
+
@sizer = BoxSizer.new(VERTICAL)
|
75
|
+
configure_window
|
91
76
|
|
92
|
-
evt_menu
|
93
|
-
evt_menu
|
77
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
78
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
94
79
|
|
95
|
-
evt_menu
|
96
|
-
evt_menu
|
97
|
-
evt_menu
|
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
|
100
|
-
evt_menu
|
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
|
103
|
-
evt_menu
|
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
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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(
|
113
|
-
menu_file.append_separator
|
114
|
-
menu_file.append(
|
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
|
-
|
119
|
-
|
120
|
-
|
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
|
-
|
123
|
-
|
107
|
+
"Toggle highlighting the holidays",
|
108
|
+
ITEM_CHECK)
|
124
109
|
menu_cal.append(Calendar_Cal_Special, "Highlight &special dates\tCtrl-S",
|
125
|
-
|
126
|
-
|
110
|
+
"Test custom highlighting",
|
111
|
+
ITEM_CHECK)
|
127
112
|
menu_cal.append(Calendar_Cal_SurroundWeeks,
|
128
|
-
|
129
|
-
|
130
|
-
|
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
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
138
|
-
|
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
|
-
|
141
|
-
|
125
|
+
"Allow changing the year in the calendar",
|
126
|
+
ITEM_CHECK)
|
142
127
|
|
143
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
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
|
-
|
158
|
+
end
|
174
159
|
|
175
160
|
def on_about
|
176
|
-
|
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
|
-
|
164
|
+
end
|
180
165
|
|
181
166
|
def on_cal_monday(event)
|
182
|
-
|
183
|
-
|
184
|
-
|
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
|
-
|
172
|
+
enable = get_menu_bar().is_checked(event.get_id())
|
188
173
|
@calendar.enable_holiday_display(enable)
|
189
|
-
|
174
|
+
end
|
190
175
|
|
191
|
-
|
192
|
-
|
193
|
-
|
176
|
+
def on_cal_special(event)
|
177
|
+
highlight_special(get_menu_bar().is_checked(event.get_id()))
|
178
|
+
end
|
194
179
|
|
195
|
-
|
196
|
-
|
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
|
-
|
183
|
+
end
|
199
184
|
|
200
|
-
|
201
|
-
|
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
|
-
|
188
|
+
end
|
204
189
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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
|
-
|
216
|
-
|
217
|
-
|
200
|
+
def on_allow_year_update(event)
|
201
|
+
event.enable( get_menu_bar().is_checked(Calendar_Cal_Month))
|
202
|
+
end
|
218
203
|
|
219
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
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
|
-
|
235
|
-
|
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
|
-
|
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
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
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
|
-
|
265
|
-
|
249
|
+
def on_init()
|
250
|
+
frame = MyFrame.new("Calendar Windows sample")
|
266
251
|
frame.show(true)
|
267
|
-
|
252
|
+
end
|
268
253
|
end
|
269
254
|
|
270
255
|
a = RbApp.new
|