wxruby 1.9.1-i686-linux → 1.9.2-i686-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -0
- data/README +299 -0
- data/lib/wx/classes/app.rb +15 -1
- data/lib/wx/classes/bitmap.rb +2 -2
- data/lib/wx/classes/checklistbox.rb +30 -0
- data/lib/wx/classes/clientdc.rb +1 -1
- data/lib/wx/classes/commandevent.rb +7 -0
- data/lib/wx/classes/controlwithitems.rb +10 -0
- data/lib/wx/classes/evthandler.rb +63 -7
- data/lib/wx/classes/listctrl.rb +9 -0
- data/lib/wx/classes/menu.rb +62 -0
- data/lib/wx/classes/menuitem.rb +7 -0
- data/lib/wx/classes/paintdc.rb +1 -1
- data/lib/wx/classes/timer.rb +2 -2
- data/lib/wx/classes/treectrl.rb +18 -0
- data/lib/wx/classes/window.rb +11 -4
- data/lib/wx/keyword_ctors.rb +1 -15
- data/lib/wx/keyword_defs.rb +68 -58
- data/lib/wx/version.rb +1 -1
- data/lib/wxruby2.so +0 -0
- data/samples/bigdemo/wxScrolledWindow.rbw +8 -3
- data/samples/calendar/calendar.rb +1 -1
- data/samples/caret/caret.rb +29 -39
- data/samples/etc/threaded.rb +81 -0
- data/samples/etc/wizard.rb +22 -24
- data/samples/html/html.rb +25 -12
- data/samples/listbook/listbook.rb +65 -67
- data/samples/minimal/minimal.rb +38 -36
- data/samples/minimal/mondrian.ico +0 -0
- data/samples/minimal/nothing.rb +5 -30
- data/samples/treectrl/treectrl.rb +197 -226
- metadata +26 -16
- data/samples/minimal/text.rb +0 -35
data/samples/minimal/minimal.rb
CHANGED
@@ -13,35 +13,45 @@ rescue LoadError => no_wx_err
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
16
|
+
# This sample shows a fairly minimal Wx::App using a Frame, with a
|
17
|
+
# MenuBar and StatusBar but no controls. For the absolute minimum app,
|
18
|
+
# see nothing.rb
|
19
|
+
|
20
|
+
# A Wx::Frame is a self-contained, top-level Window that can contain
|
21
|
+
# controls, menubars, and statusbars
|
17
22
|
class MinimalFrame < Wx::Frame
|
18
23
|
def initialize(title)
|
19
|
-
|
20
|
-
# A main application frame has no parent (nil)
|
24
|
+
# The main application frame has no parent (nil)
|
21
25
|
super(nil, :title => title, :size => [ 400, 300 ])
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
icon_file = File.join( File.dirname(__FILE__), "mondrian.png")
|
28
|
+
# PNG can be used on all platforms, but icon type must be specified
|
29
|
+
# to work on Windows; OS X doesn't have "Frame" icons.
|
30
|
+
self.icon = Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_PNG)
|
26
31
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# in the correct platform-specific place
|
31
|
-
menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
32
|
+
menu_bar = Wx::MenuBar.new
|
33
|
+
# The "file" menu
|
34
|
+
menu_file = Wx::Menu.new
|
32
35
|
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit this program")
|
33
|
-
menu_bar = Wx::MenuBar.new()
|
34
36
|
menu_bar.append(menu_file, "&File")
|
37
|
+
|
38
|
+
# The "help" menu
|
39
|
+
menu_help = Wx::Menu.new
|
40
|
+
# Using Wx::ID_ABOUT default id means the menu item will be placed
|
41
|
+
# in the correct platform-specific place - eg on OS X
|
42
|
+
menu_help.append(Wx::ID_ABOUT, "&About...\tF1", "Show about dialog")
|
35
43
|
menu_bar.append(menu_help, "&Help")
|
36
|
-
# Assign the menus to this frame
|
37
|
-
set_menu_bar(menu_bar)
|
38
44
|
|
45
|
+
# Assign the menubar to this frame
|
46
|
+
self.menu_bar = menu_bar
|
47
|
+
|
48
|
+
# Create a status bar
|
39
49
|
create_status_bar(2)
|
40
|
-
|
50
|
+
self.status_text = "Welcome to wxRuby!"
|
41
51
|
|
42
|
-
# handle menu events
|
43
|
-
evt_menu
|
44
|
-
evt_menu
|
52
|
+
# Set it up to handle menu events using the relevant methods
|
53
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
54
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
45
55
|
end
|
46
56
|
|
47
57
|
# End the application; it should finish automatically when the last
|
@@ -58,26 +68,18 @@ class MinimalFrame < Wx::Frame
|
|
58
68
|
# create a simple message dialog with OK button
|
59
69
|
about_dlg = Wx::MessageDialog.new( self, msg, 'About Minimal',
|
60
70
|
Wx::OK|Wx::ICON_INFORMATION )
|
71
|
+
# Display the dialog on top of and blocking other windows, until
|
72
|
+
# dismissed by clicking the 'OK' button
|
61
73
|
about_dlg.show_modal
|
62
74
|
end
|
63
75
|
end
|
64
76
|
|
65
|
-
# Wx::App is the container class for any wxruby app
|
66
|
-
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
# This is required,
|
74
|
-
frame.show
|
75
|
-
# on_init must return a true value else the app will not start
|
76
|
-
true
|
77
|
-
end
|
77
|
+
# Wx::App is the container class for any wxruby app. To start an
|
78
|
+
# application, either define a subclass of Wx::App, create an instance,
|
79
|
+
# and call its main_loop method, OR, simply call the Wx::App.run class
|
80
|
+
# method, as shown here.
|
81
|
+
Wx::App.run do
|
82
|
+
self.app_name = 'Minimal'
|
83
|
+
frame = MinimalFrame.new("Minimal wxRuby App")
|
84
|
+
frame.show
|
78
85
|
end
|
79
|
-
|
80
|
-
# Create an instance ...
|
81
|
-
app = MinimalApp.new
|
82
|
-
# ... and run the application
|
83
|
-
app.main_loop()
|
Binary file
|
data/samples/minimal/nothing.rb
CHANGED
@@ -13,34 +13,9 @@ rescue LoadError => no_wx_err
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
# This is the minimum code to start a WxRuby app - create a Frame, and
|
17
|
+
# show it.
|
18
|
+
Wx::App.run do
|
19
|
+
frame = Wx::Frame.new(nil, :title => "Minimal wxRuby App")
|
20
|
+
frame.show
|
20
21
|
end
|
21
|
-
|
22
|
-
class NothingApp < Wx::App
|
23
|
-
def on_init
|
24
|
-
puts("in on_init")
|
25
|
-
$frame = MyFrame.new("Minimal wxRuby App")
|
26
|
-
puts("about to call show")
|
27
|
-
$frame.show
|
28
|
-
puts("returning from on_init")
|
29
|
-
return true
|
30
|
-
end
|
31
|
-
|
32
|
-
def on_fatal_exception
|
33
|
-
puts("on_fatal_exception")
|
34
|
-
end
|
35
|
-
|
36
|
-
def on_exit
|
37
|
-
puts("on_exit")
|
38
|
-
return super
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
a = NothingApp.new
|
43
|
-
a.main_loop()
|
44
|
-
puts("back from main_loop...")
|
45
|
-
GC.start
|
46
|
-
puts("survived gc")
|
@@ -59,7 +59,6 @@ TreeTest_DecSpacing,
|
|
59
59
|
TreeTest_ToggleIcon,
|
60
60
|
TreeTest_Select,
|
61
61
|
TreeTest_Unselect = (Wx::ID_HIGHEST..Wx::ID_HIGHEST+39).to_a
|
62
|
-
TreeTest_Ctrl = 1000
|
63
62
|
|
64
63
|
TreeCtrlIcon_File,
|
65
64
|
TreeCtrlIcon_FileSelected,
|
@@ -68,8 +67,8 @@ TreeCtrlIcon_FolderSelected,
|
|
68
67
|
TreeCtrlIcon_FolderOpened = 0,1,2,3,4
|
69
68
|
|
70
69
|
class MyTreeCtrl < Wx::TreeCtrl
|
71
|
-
def initialize(parent,
|
72
|
-
super
|
70
|
+
def initialize(parent, args)
|
71
|
+
super
|
73
72
|
|
74
73
|
@reverse_sort = false
|
75
74
|
|
@@ -79,26 +78,25 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
79
78
|
add_test_items_to_tree(5, 2)
|
80
79
|
|
81
80
|
# TreeCtrl supports a large number of different events...
|
82
|
-
evt_tree_begin_drag
|
83
|
-
evt_tree_begin_rdrag
|
84
|
-
evt_tree_end_drag
|
85
|
-
evt_tree_begin_label_edit
|
86
|
-
evt_tree_end_label_edit
|
87
|
-
evt_tree_delete_item
|
88
|
-
evt_tree_set_info
|
89
|
-
evt_tree_item_expanded
|
90
|
-
evt_tree_item_expanding
|
91
|
-
evt_tree_item_collapsed
|
92
|
-
evt_tree_item_collapsing
|
93
|
-
evt_tree_item_right_click
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
81
|
+
evt_tree_begin_drag self, :on_begin_drag
|
82
|
+
evt_tree_begin_rdrag self, :on_begin_rdrag
|
83
|
+
evt_tree_end_drag self, :on_end_drag
|
84
|
+
evt_tree_begin_label_edit self, :on_begin_label_edit
|
85
|
+
evt_tree_end_label_edit self, :on_end_label_edit
|
86
|
+
evt_tree_delete_item self, :on_delete_item
|
87
|
+
evt_tree_set_info self, :on_set_info
|
88
|
+
evt_tree_item_expanded self, :on_item_expanded
|
89
|
+
evt_tree_item_expanding self, :on_item_expanding
|
90
|
+
evt_tree_item_collapsed self, :on_item_collapsed
|
91
|
+
evt_tree_item_collapsing self, :on_item_collapsing
|
92
|
+
evt_tree_item_right_click self, :on_item_right_click
|
93
|
+
evt_tree_sel_changed self, :on_sel_changed
|
94
|
+
evt_tree_sel_changing self, :on_sel_changing
|
95
|
+
evt_tree_key_down self, :on_tree_key_down
|
96
|
+
evt_tree_item_activated self, :on_item_activated
|
97
|
+
|
98
|
+
evt_right_dclick :on_rmouse_dclick
|
99
|
+
evt_right_up :on_rmouse_up
|
102
100
|
end
|
103
101
|
|
104
102
|
def show_info(id)
|
@@ -131,7 +129,7 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
131
129
|
|
132
130
|
def is_test_item(item)
|
133
131
|
# the test item is the first child folder
|
134
|
-
return
|
132
|
+
return item_parent(item) == root_item && ! prev_sibling(item)
|
135
133
|
end
|
136
134
|
|
137
135
|
def create_image_list
|
@@ -143,16 +141,15 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
143
141
|
Wx::BusyCursor.busy do
|
144
142
|
icons = (1 .. 5).map do | i |
|
145
143
|
icon_file = File.join(File.dirname(__FILE__), "icon#{i}.xpm")
|
146
|
-
# Wx::Icon.new(icon_file, Wx::BITMAP_TYPE_XPM, 16, 16)
|
147
144
|
Wx::Bitmap.new(icon_file, Wx::BITMAP_TYPE_XPM)
|
148
145
|
end
|
149
146
|
icons.each { | ic | images.add(ic) }
|
150
|
-
|
147
|
+
self.image_list = images
|
151
148
|
end
|
152
149
|
end
|
153
150
|
|
154
151
|
def unset_image_list
|
155
|
-
|
152
|
+
self.image_list = nil
|
156
153
|
end
|
157
154
|
|
158
155
|
def create_buttons_image_list()
|
@@ -165,19 +162,19 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
165
162
|
Wx::Icon.new("icon3.xpm"), # closed
|
166
163
|
Wx::Icon.new("icon3.xpm"), # closed, selected
|
167
164
|
Wx::Icon.new("icon5.xpm"), # open
|
168
|
-
Wx::Icon.new("icon5.xpm")] # open, selected
|
165
|
+
Wx::Icon.new("icon5.xpm") ] # open, selected
|
169
166
|
|
170
167
|
icons.each do | ic |
|
171
168
|
orig_size = ic.get_width()
|
172
169
|
if size == orig_size
|
173
170
|
images.add(ic)
|
174
171
|
else
|
175
|
-
resized = ic.convert_to_image
|
172
|
+
resized = ic.convert_to_image.rescale(size, size)
|
176
173
|
images.add( Wx::Bitmap.new(resized) )
|
177
174
|
end
|
178
175
|
end
|
179
176
|
|
180
|
-
|
177
|
+
self.buttons_image_list = images
|
181
178
|
end
|
182
179
|
end
|
183
180
|
|
@@ -203,7 +200,7 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
203
200
|
end
|
204
201
|
# here we pass to append_item() normal and selected item images (we
|
205
202
|
# suppose that selected image follows the normal one in the enum)
|
206
|
-
if Wx::
|
203
|
+
if Wx::THE_APP.show_images
|
207
204
|
image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder
|
208
205
|
imageSel = image + 1
|
209
206
|
else
|
@@ -213,8 +210,8 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
213
210
|
|
214
211
|
# and now we also set the expanded one (only for the folders)
|
215
212
|
if has_children && Wx::get_app.show_images()
|
216
|
-
set_item_image(id, TreeCtrlIcon_FolderOpened,
|
217
|
-
|
213
|
+
set_item_image( id, TreeCtrlIcon_FolderOpened,
|
214
|
+
Wx::TREE_ITEM_ICON_EXPANDED)
|
218
215
|
end
|
219
216
|
|
220
217
|
# remember the last child for OnEnsureVisible()
|
@@ -228,10 +225,10 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
228
225
|
end
|
229
226
|
|
230
227
|
def add_test_items_to_tree(num_children,depth)
|
231
|
-
image = Wx::
|
228
|
+
image = Wx::THE_APP.show_images ? TreeCtrlIcon_Folder : -1
|
232
229
|
root_id = add_root("Root",image, image)
|
233
230
|
if image != -1
|
234
|
-
set_item_image(root_id, TreeCtrlIcon_FolderOpened,
|
231
|
+
set_item_image( root_id, TreeCtrlIcon_FolderOpened,
|
235
232
|
Wx::TREE_ITEM_ICON_EXPANDED)
|
236
233
|
end
|
237
234
|
|
@@ -242,17 +239,18 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
242
239
|
# that use the generic TreeCtrl - OS X and GTK, and only if
|
243
240
|
# Wx::TR_HAS_VARIABLE_ROW_HEIGHT style was used in the constructor
|
244
241
|
font = get_font
|
245
|
-
font.
|
242
|
+
font.style = Wx::FONTSTYLE_ITALIC
|
246
243
|
set_item_font(root_id, font)
|
247
244
|
|
248
|
-
|
249
|
-
|
245
|
+
ids = get_children(root_id)
|
246
|
+
|
247
|
+
# make the first item blue
|
248
|
+
set_item_text_colour(ids[0], Wx::BLUE)
|
250
249
|
|
251
|
-
|
252
|
-
id,cookie = get_next_child(root_id,cookie)
|
250
|
+
# make the third item red on grey
|
253
251
|
if Wx::PLATFORM == "WXMSW"
|
254
|
-
set_item_text_colour(
|
255
|
-
set_item_background_colour(
|
252
|
+
set_item_text_colour(ids[2], Wx::RED)
|
253
|
+
set_item_background_colour(ids[2], Wx::LIGHT_GREY)
|
256
254
|
end
|
257
255
|
end
|
258
256
|
|
@@ -266,7 +264,7 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
266
264
|
return nil
|
267
265
|
end
|
268
266
|
|
269
|
-
text =
|
267
|
+
text = item_text(id)
|
270
268
|
Wx::log_message(text)
|
271
269
|
|
272
270
|
if item_has_children(id)
|
@@ -288,51 +286,51 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
288
286
|
|
289
287
|
def on_begin_rdrag(event)
|
290
288
|
Wx::log_message("OnBeginRDrag")
|
291
|
-
event.skip
|
289
|
+
event.skip
|
292
290
|
end
|
293
291
|
|
294
292
|
def on_delete_item(event)
|
295
293
|
Wx::log_message("OnDeleteItem")
|
296
|
-
event.skip
|
294
|
+
event.skip
|
297
295
|
end
|
298
296
|
|
299
297
|
def on_get_info(event)
|
300
298
|
Wx::log_message("OnGetInfo")
|
301
|
-
event.skip
|
299
|
+
event.skip
|
302
300
|
end
|
303
301
|
|
304
302
|
def on_set_info(event)
|
305
303
|
Wx::log_message("OnSetInfo")
|
306
|
-
event.skip
|
304
|
+
event.skip
|
307
305
|
end
|
308
306
|
|
309
307
|
def on_item_expanded(event)
|
310
308
|
Wx::log_message("OnItemExpanded")
|
311
|
-
event.skip
|
309
|
+
event.skip
|
312
310
|
end
|
313
311
|
|
314
312
|
def on_item_expanding(event)
|
315
313
|
Wx::log_message("OnItemExpanding")
|
316
|
-
event.skip
|
314
|
+
event.skip
|
317
315
|
end
|
318
316
|
|
319
317
|
def on_item_collapsed(event)
|
320
318
|
Wx::log_message("OnItemCollapsed")
|
321
|
-
event.skip
|
319
|
+
event.skip
|
322
320
|
end
|
323
321
|
|
324
322
|
def on_sel_changed(event)
|
325
323
|
Wx::log_message("OnSelChanged")
|
326
|
-
event.skip
|
324
|
+
event.skip
|
327
325
|
end
|
328
326
|
|
329
327
|
def on_sel_changing(event)
|
330
328
|
Wx::log_message("OnSelChanging")
|
331
|
-
event.skip
|
329
|
+
event.skip
|
332
330
|
end
|
333
331
|
|
334
332
|
def log_key_event(name,event)
|
335
|
-
keycode = event.
|
333
|
+
keycode = event.key_code
|
336
334
|
|
337
335
|
case keycode
|
338
336
|
when Wx::K_BACK
|
@@ -548,26 +546,25 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
548
546
|
end
|
549
547
|
|
550
548
|
Wx::log_message( "%s event: %s (flags = %s%s%s%s)",
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
549
|
+
name, key,
|
550
|
+
event.control_down() ? 'C' : '-',
|
551
|
+
event.alt_down() ? 'A' : '-',
|
552
|
+
event.shift_down() ? 'S' : '-',
|
553
|
+
event.meta_down() ? 'M' : '-')
|
556
554
|
end
|
557
555
|
|
558
556
|
def on_tree_key_down(event)
|
559
|
-
log_key_event("Tree key down ", event.
|
560
|
-
|
561
|
-
event.skip()
|
557
|
+
log_key_event("Tree key down ", event.key_event )
|
558
|
+
event.skip
|
562
559
|
end
|
563
560
|
|
564
561
|
def on_begin_drag(event)
|
565
562
|
# need to explicitly allow drag
|
566
|
-
if event.
|
567
|
-
@dragged_item = event.
|
568
|
-
Wx::log_message("OnBeginDrag: started dragging %s",
|
569
|
-
|
570
|
-
event.allow
|
563
|
+
if event.item != root_item()
|
564
|
+
@dragged_item = event.item
|
565
|
+
Wx::log_message( "OnBeginDrag: started dragging %s",
|
566
|
+
item_text(@dragged_item))
|
567
|
+
event.allow
|
571
568
|
else
|
572
569
|
Wx::log_message("OnBeginDrag: selected item can't be dragged.")
|
573
570
|
end
|
@@ -575,12 +572,12 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
575
572
|
|
576
573
|
def on_end_drag(event)
|
577
574
|
src_item = @dragged_item
|
578
|
-
dest_item = event.
|
575
|
+
dest_item = event.item
|
579
576
|
@dragged_item = 0
|
580
577
|
|
581
578
|
if dest_item.nonzero? && ! item_has_children(dest_item)
|
582
579
|
# copy to the parent then
|
583
|
-
dest_item =
|
580
|
+
dest_item = item_parent(dest_item)
|
584
581
|
end
|
585
582
|
|
586
583
|
unless dest_item.nonzero?()
|
@@ -588,9 +585,9 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
588
585
|
return nil
|
589
586
|
end
|
590
587
|
|
591
|
-
text =
|
588
|
+
text = item_text(src_item)
|
592
589
|
Wx::log_message("OnEndDrag: '%s' copied to '%s'.",
|
593
|
-
|
590
|
+
text, item_text(dest_item))
|
594
591
|
|
595
592
|
# just do append here - we could also insert it just before/after the item
|
596
593
|
# on which it was dropped, but self requires slightly more work... we also
|
@@ -599,7 +596,7 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
599
596
|
#
|
600
597
|
# Finally, we only copy one item here but we might copy the entire tree if
|
601
598
|
# we were dragging a folder.
|
602
|
-
image = Wx::
|
599
|
+
image = Wx::THE_APP.show_images() ? TreeCtrlIcon_File : -1
|
603
600
|
append_item(dest_item, text, image)
|
604
601
|
end
|
605
602
|
|
@@ -607,26 +604,25 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
607
604
|
Wx::log_message("OnBeginLabelEdit")
|
608
605
|
|
609
606
|
# for testing, prevent self item's label editing
|
610
|
-
|
611
|
-
|
612
|
-
message_box("The demo prevents you editing this item.")
|
607
|
+
if is_test_item(event.item)
|
608
|
+
Wx::message_box("The demo prevents you editing this item.")
|
613
609
|
event.veto()
|
614
610
|
end
|
615
611
|
end
|
616
612
|
|
617
613
|
def on_end_label_edit(event)
|
618
614
|
Wx::log_message("OnEndLabelEdit")
|
619
|
-
if event.
|
615
|
+
if event.edit_cancelled?
|
620
616
|
Wx::log_message("Label edit was cancelled by user")
|
621
617
|
return
|
622
618
|
end
|
623
619
|
|
624
620
|
# For a demo, don't allow anything except letters in the labels
|
625
|
-
if event.
|
621
|
+
if event.label =~ /[^\w.]/
|
626
622
|
msg = "Only letters, numbers and full stops are allowed in the label."
|
627
|
-
message_box(msg)
|
623
|
+
Wx::message_box(msg)
|
628
624
|
Wx::log_message("Label edit was cancelled by demo")
|
629
|
-
event.veto
|
625
|
+
event.veto
|
630
626
|
end
|
631
627
|
end
|
632
628
|
|
@@ -634,28 +630,26 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
634
630
|
Wx::log_message("OnItemCollapsing")
|
635
631
|
|
636
632
|
# for testing, prevent the user from collapsing the first child folder
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
event.veto()
|
633
|
+
if is_test_item(event.item)
|
634
|
+
Wx::message_box("You can't collapse self item.")
|
635
|
+
event.veto
|
642
636
|
end
|
643
637
|
end
|
644
638
|
|
645
639
|
# show some info about activated item
|
646
640
|
def on_item_activated(event)
|
647
|
-
if item_id = event.
|
641
|
+
if item_id = event.item
|
648
642
|
show_info(item_id)
|
649
643
|
end
|
650
644
|
Wx::log_message("OnItemActivated")
|
651
645
|
end
|
652
646
|
|
653
647
|
def on_item_right_click(event)
|
654
|
-
show_popup_menu(event.
|
648
|
+
show_popup_menu(event.item, event.point)
|
655
649
|
end
|
656
650
|
|
657
651
|
def on_rmouse_up(event)
|
658
|
-
pos = event.
|
652
|
+
pos = event.position
|
659
653
|
item = hit_test(pos)
|
660
654
|
show_popup_menu(item, pos)
|
661
655
|
end
|
@@ -663,7 +657,7 @@ class MyTreeCtrl < Wx::TreeCtrl
|
|
663
657
|
def show_popup_menu(id, pos)
|
664
658
|
title = ""
|
665
659
|
if id.nonzero?
|
666
|
-
title << "Menu for " <<
|
660
|
+
title << "Menu for " << item_text(id)
|
667
661
|
else
|
668
662
|
title = "Menu for no particular item"
|
669
663
|
end
|
@@ -690,7 +684,7 @@ end
|
|
690
684
|
|
691
685
|
class MyFrame < Wx::Frame
|
692
686
|
def initialize(title, x, y, w, h)
|
693
|
-
super(nil,
|
687
|
+
super( nil, :title => title, :pos => [ x, y ], :size => [ w, h ] )
|
694
688
|
@treectrl = nil
|
695
689
|
@textctrl = nil
|
696
690
|
@s_num = 0
|
@@ -698,7 +692,7 @@ class MyFrame < Wx::Frame
|
|
698
692
|
# This reduces flicker effects - even better would be to define
|
699
693
|
# OnEraseBackground to do nothing. When the tree control's scrollbars are
|
700
694
|
# show or hidden, the frame is sent a background erase event.
|
701
|
-
|
695
|
+
self.background_colour = Wx::WHITE
|
702
696
|
|
703
697
|
# Make a menubar
|
704
698
|
file_menu = Wx::Menu.new
|
@@ -782,13 +776,13 @@ class MyFrame < Wx::Frame
|
|
782
776
|
menu_bar.append(style_menu, "&Style")
|
783
777
|
menu_bar.append(tree_menu, "&Tree")
|
784
778
|
menu_bar.append(item_menu, "&Item")
|
785
|
-
|
779
|
+
self.menu_bar = menu_bar
|
786
780
|
|
787
781
|
|
788
782
|
# create the controls
|
789
|
-
@textctrl = Wx::TextCtrl.new(self,
|
790
|
-
|
791
|
-
|
783
|
+
@textctrl = Wx::TextCtrl.new( self,
|
784
|
+
:text => '',
|
785
|
+
:style => Wx::TE_MULTILINE|Wx::SUNKEN_BORDER)
|
792
786
|
|
793
787
|
create_tree_with_default_style()
|
794
788
|
|
@@ -800,55 +794,54 @@ class MyFrame < Wx::Frame
|
|
800
794
|
|
801
795
|
# set our text control as the log target
|
802
796
|
logWindow = Wx::LogTextCtrl.new(@textctrl)
|
803
|
-
Wx::Log::
|
804
|
-
|
805
|
-
evt_size
|
806
|
-
|
807
|
-
|
808
|
-
evt_menu
|
809
|
-
|
810
|
-
|
811
|
-
evt_menu
|
812
|
-
evt_menu
|
813
|
-
evt_menu
|
814
|
-
evt_menu
|
815
|
-
evt_menu
|
816
|
-
evt_menu
|
817
|
-
evt_menu
|
818
|
-
evt_menu
|
819
|
-
evt_menu
|
820
|
-
evt_menu
|
821
|
-
|
822
|
-
|
823
|
-
evt_menu
|
824
|
-
evt_menu
|
825
|
-
evt_menu
|
826
|
-
evt_menu
|
827
|
-
evt_menu
|
828
|
-
evt_menu
|
829
|
-
evt_menu
|
830
|
-
evt_menu
|
831
|
-
evt_menu
|
832
|
-
evt_menu
|
833
|
-
evt_menu
|
834
|
-
evt_menu
|
835
|
-
evt_menu
|
836
|
-
evt_menu
|
837
|
-
evt_menu
|
838
|
-
evt_menu
|
839
|
-
evt_menu
|
840
|
-
evt_menu
|
841
|
-
evt_menu
|
842
|
-
evt_menu
|
843
|
-
evt_menu
|
844
|
-
evt_menu
|
845
|
-
evt_menu
|
846
|
-
evt_menu
|
847
|
-
evt_menu
|
848
|
-
evt_menu
|
849
|
-
evt_menu
|
850
|
-
|
851
|
-
evt_close {|event| on_close(event) }
|
797
|
+
Wx::Log::active_target = logWindow
|
798
|
+
|
799
|
+
evt_size :on_size
|
800
|
+
evt_close :on_close
|
801
|
+
|
802
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
803
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
804
|
+
|
805
|
+
evt_menu TreeTest_TogButtons, :on_tog_buttons
|
806
|
+
evt_menu TreeTest_TogTwist, :on_tog_twist
|
807
|
+
evt_menu TreeTest_TogLines, :on_tog_lines
|
808
|
+
evt_menu TreeTest_TogEdit, :on_tog_edit
|
809
|
+
evt_menu TreeTest_TogHideRoot, :on_tog_hide_root
|
810
|
+
evt_menu TreeTest_TogRootLines, :on_tog_root_lines
|
811
|
+
evt_menu TreeTest_TogBorder, :on_tog_border
|
812
|
+
evt_menu TreeTest_TogFullHighlight, :on_tog_full_highlight
|
813
|
+
evt_menu TreeTest_SetFgColour, :on_set_fg_colour
|
814
|
+
evt_menu TreeTest_SetBgColour, :on_set_bg_colour
|
815
|
+
evt_menu TreeTest_ResetStyle, :on_reset_style
|
816
|
+
|
817
|
+
evt_menu TreeTest_Dump, :on_dump
|
818
|
+
evt_menu TreeTest_DumpSelected, :on_dump_selected
|
819
|
+
evt_menu TreeTest_Select, :on_select
|
820
|
+
evt_menu TreeTest_Unselect, :on_unselect
|
821
|
+
evt_menu TreeTest_ToggleSel, :on_toggle_sel
|
822
|
+
evt_menu TreeTest_Rename, :on_rename
|
823
|
+
evt_menu TreeTest_Count, :on_count
|
824
|
+
evt_menu TreeTest_CountRec, :on_count_rec
|
825
|
+
evt_menu TreeTest_Sort, :on_sort
|
826
|
+
evt_menu TreeTest_SortRev, :on_sort_rev
|
827
|
+
evt_menu TreeTest_SetBold, :on_set_bold
|
828
|
+
evt_menu TreeTest_ClearBold, :on_clear_bold
|
829
|
+
evt_menu TreeTest_Delete, :on_delete
|
830
|
+
evt_menu TreeTest_DeleteChildren, :on_delete_children
|
831
|
+
evt_menu TreeTest_DeleteAll, :on_delete_all
|
832
|
+
evt_menu TreeTest_Recreate, :on_recreate
|
833
|
+
evt_menu TreeTest_ToggleImages, :on_toggle_images
|
834
|
+
evt_menu TreeTest_ToggleButtons, :on_toggle_buttons
|
835
|
+
evt_menu TreeTest_SetImageSize, :on_set_image_size
|
836
|
+
evt_menu TreeTest_CollapseAndReset, :on_collapse_and_reset
|
837
|
+
evt_menu TreeTest_EnsureVisible, :on_ensure_visible
|
838
|
+
evt_menu TreeTest_AddItem, :on_add_item
|
839
|
+
evt_menu TreeTest_InsertItem, :on_insert_item
|
840
|
+
evt_menu TreeTest_IncIndent, :on_inc_indent
|
841
|
+
evt_menu TreeTest_DecIndent, :on_dec_indent
|
842
|
+
evt_menu TreeTest_IncSpacing, :on_inc_spacing
|
843
|
+
evt_menu TreeTest_DecSpacing, :on_dec_spacing
|
844
|
+
evt_menu TreeTest_ToggleIcon, :on_toggle_icon
|
852
845
|
end
|
853
846
|
|
854
847
|
def create_tree_with_default_style()
|
@@ -860,7 +853,7 @@ class MyFrame < Wx::Frame
|
|
860
853
|
|
861
854
|
# as we don't know what Wx::TR_DEFAULT_STYLE could contain, test for
|
862
855
|
# everything
|
863
|
-
mbar =
|
856
|
+
mbar = menu_bar
|
864
857
|
mbar.check(TreeTest_TogButtons, (style & Wx::TR_HAS_BUTTONS) != 0)
|
865
858
|
mbar.check(TreeTest_TogButtons, (style & Wx::TR_TWIST_BUTTONS) != 0)
|
866
859
|
mbar.check(TreeTest_TogLines, (style & Wx::TR_NO_LINES) == 0)
|
@@ -872,53 +865,51 @@ class MyFrame < Wx::Frame
|
|
872
865
|
end
|
873
866
|
|
874
867
|
def create_tree(style)
|
875
|
-
@treectrl = MyTreeCtrl.new(self,
|
876
|
-
|
877
|
-
style)
|
878
|
-
resize()
|
868
|
+
@treectrl = MyTreeCtrl.new(self, :style => style)
|
869
|
+
resize
|
879
870
|
end
|
880
871
|
|
881
872
|
def tog_style(id,flag)
|
882
873
|
|
883
|
-
style = @treectrl.
|
874
|
+
style = @treectrl.window_style_flag ^ flag
|
884
875
|
|
885
876
|
# most treectrl styles can't be changed on the fly using the native
|
886
877
|
# control and the tree must be recreated
|
887
878
|
@treectrl.destroy
|
888
879
|
create_tree(style)
|
889
|
-
|
880
|
+
menu_bar.check(id, (style & flag) != 0)
|
890
881
|
end
|
891
882
|
|
892
883
|
def on_tog_buttons(event)
|
893
|
-
tog_style(event.
|
884
|
+
tog_style(event.id, Wx::TR_HAS_BUTTONS)
|
894
885
|
end
|
895
886
|
|
896
887
|
def on_tog_twist(event)
|
897
|
-
tog_style(event.
|
888
|
+
tog_style(event.id, Wx::TR_TWIST_BUTTONS)
|
898
889
|
end
|
899
890
|
|
900
891
|
def on_tog_lines(event)
|
901
|
-
tog_style(event.
|
892
|
+
tog_style(event.id, Wx::TR_NO_LINES)
|
902
893
|
end
|
903
894
|
|
904
895
|
def on_tog_edit(event)
|
905
|
-
tog_style(event.
|
896
|
+
tog_style(event.id, Wx::TR_EDIT_LABELS)
|
906
897
|
end
|
907
898
|
|
908
899
|
def on_tog_hide_root(event)
|
909
|
-
tog_style(event.
|
900
|
+
tog_style(event.id, Wx::TR_HIDE_ROOT)
|
910
901
|
end
|
911
902
|
|
912
903
|
def on_tog_root_lines(event)
|
913
|
-
tog_style(event.
|
904
|
+
tog_style(event.id, Wx::TR_LINES_AT_ROOT)
|
914
905
|
end
|
915
906
|
|
916
907
|
def on_tog_border(event)
|
917
|
-
tog_style(event.
|
908
|
+
tog_style(event.id, Wx::TR_ROW_LINES)
|
918
909
|
end
|
919
910
|
|
920
911
|
def on_tog_full_highlight(event)
|
921
|
-
tog_style(event.
|
912
|
+
tog_style(event.id, Wx::TR_FULL_ROW_HIGHLIGHT)
|
922
913
|
end
|
923
914
|
|
924
915
|
def on_reset_style(event)
|
@@ -934,7 +925,7 @@ class MyFrame < Wx::Frame
|
|
934
925
|
end
|
935
926
|
|
936
927
|
def on_sort(event)
|
937
|
-
do_sort
|
928
|
+
do_sort
|
938
929
|
end
|
939
930
|
|
940
931
|
def on_sort_rev(event)
|
@@ -943,22 +934,19 @@ class MyFrame < Wx::Frame
|
|
943
934
|
|
944
935
|
def on_size(event)
|
945
936
|
if @treectrl && @textctrl
|
946
|
-
resize
|
937
|
+
resize
|
947
938
|
end
|
948
|
-
|
949
|
-
event.skip()
|
939
|
+
event.skip
|
950
940
|
end
|
951
941
|
|
952
|
-
def resize
|
953
|
-
my_size =
|
954
|
-
|
955
|
-
@treectrl.set_size( tree_size )
|
956
|
-
@textctrl.set_dimensions(0, 2*my_size.y/3, my_size.x, my_size.y/3)
|
942
|
+
def resize
|
943
|
+
my_size = self.client_size
|
944
|
+
@treectrl.size = [ my_size.x, 2 * my_size.y / 3 ]
|
957
945
|
end
|
958
946
|
|
959
947
|
def on_close(event)
|
960
|
-
Wx::Log::
|
961
|
-
destroy
|
948
|
+
Wx::Log::active_target = nil
|
949
|
+
destroy
|
962
950
|
end
|
963
951
|
|
964
952
|
def on_quit(event)
|
@@ -966,15 +954,15 @@ class MyFrame < Wx::Frame
|
|
966
954
|
end
|
967
955
|
|
968
956
|
def on_about(event)
|
969
|
-
Wx::message_box("Tree test sample\n" +
|
970
|
-
|
971
|
-
|
972
|
-
|
957
|
+
Wx::message_box( "Tree test sample\n" +
|
958
|
+
"(c) Julian Smart 1997, Vadim Zeitlin 1998",
|
959
|
+
"About tree test",
|
960
|
+
Wx::OK|Wx::ICON_INFORMATION, self)
|
973
961
|
end
|
974
962
|
|
975
963
|
def check_item(item)
|
976
964
|
unless item.nonzero?
|
977
|
-
message_box("Please select some item first!",
|
965
|
+
Wx::message_box("Please select some item first!",
|
978
966
|
"Tree sample error",
|
979
967
|
Wx::OK|Wx::ICON_EXCLAMATION, self)
|
980
968
|
return false
|
@@ -983,51 +971,44 @@ class MyFrame < Wx::Frame
|
|
983
971
|
end
|
984
972
|
|
985
973
|
def on_rename(event)
|
986
|
-
item = @treectrl.
|
987
|
-
|
974
|
+
item = @treectrl.selection
|
988
975
|
return nil unless check_item( item )
|
989
|
-
|
990
976
|
# TODO demonstrate creating a custom edit control...
|
991
977
|
@treectrl.edit_label(item)
|
992
978
|
end
|
993
979
|
|
994
980
|
def on_count(event)
|
995
|
-
item = @treectrl.
|
996
|
-
|
981
|
+
item = @treectrl.selection
|
997
982
|
return nil unless check_item( item )
|
998
|
-
|
999
|
-
i = @treectrl.get_children_count( item, false )
|
1000
|
-
|
983
|
+
i = @treectrl.children_count( item, false )
|
1001
984
|
Wx::log_message("%d children", i)
|
1002
985
|
end
|
1003
986
|
|
1004
987
|
def on_count_rec(event)
|
1005
|
-
item = @treectrl.
|
988
|
+
item = @treectrl.selection
|
1006
989
|
return nil unless check_item( item )
|
1007
|
-
Wx::log_message("%d children", @treectrl.
|
990
|
+
Wx::log_message("%d children", @treectrl.children_count( item ))
|
1008
991
|
end
|
1009
992
|
|
1010
993
|
def do_sort(reverse = false)
|
1011
|
-
item = @treectrl.
|
994
|
+
item = @treectrl.selection
|
1012
995
|
return nil unless check_item( item )
|
1013
996
|
@treectrl.do_sort_children(item, reverse)
|
1014
997
|
end
|
1015
998
|
|
1016
999
|
def on_dump(event)
|
1017
|
-
root = @treectrl.
|
1018
|
-
|
1000
|
+
root = @treectrl.selection
|
1019
1001
|
return nil unless check_item( root )
|
1020
|
-
|
1021
1002
|
@treectrl.get_items_recursively(root, -1)
|
1022
1003
|
end
|
1023
1004
|
|
1024
1005
|
def on_toggle_sel(event)
|
1025
|
-
tog_style(event.
|
1006
|
+
tog_style(event.id, Wx::TR_MULTIPLE)
|
1026
1007
|
end
|
1027
1008
|
|
1028
1009
|
def on_dump_selected(event)
|
1029
|
-
if ( @treectrl.
|
1030
|
-
item_id = @treectrl.
|
1010
|
+
if ( @treectrl.window_style & Wx::TR_MULTIPLE ) == 0
|
1011
|
+
item_id = @treectrl.selection
|
1031
1012
|
if item_id.nonzero?
|
1032
1013
|
Wx::log_message("<TreeItem '%s'>",
|
1033
1014
|
@treectrl.get_item_text(item_id))
|
@@ -1046,7 +1027,7 @@ class MyFrame < Wx::Frame
|
|
1046
1027
|
end
|
1047
1028
|
|
1048
1029
|
def on_select(event)
|
1049
|
-
@treectrl.select_item(@treectrl.
|
1030
|
+
@treectrl.select_item(@treectrl.selection)
|
1050
1031
|
end
|
1051
1032
|
|
1052
1033
|
def on_unselect(event)
|
@@ -1054,26 +1035,20 @@ class MyFrame < Wx::Frame
|
|
1054
1035
|
end
|
1055
1036
|
|
1056
1037
|
def do_set_bold(bold = true)
|
1057
|
-
item = @treectrl.
|
1058
|
-
|
1038
|
+
item = @treectrl.selection
|
1059
1039
|
return nil unless check_item( item )
|
1060
|
-
|
1061
1040
|
@treectrl.set_item_bold(item, bold)
|
1062
1041
|
end
|
1063
1042
|
|
1064
1043
|
def on_delete(event)
|
1065
|
-
item = @treectrl.
|
1066
|
-
|
1044
|
+
item = @treectrl.selection
|
1067
1045
|
return nil unless check_item( item )
|
1068
|
-
|
1069
1046
|
@treectrl.delete(item)
|
1070
1047
|
end
|
1071
1048
|
|
1072
1049
|
def on_delete_children(event)
|
1073
|
-
item = @treectrl.
|
1074
|
-
|
1050
|
+
item = @treectrl.selection
|
1075
1051
|
return nil unless check_item( item )
|
1076
|
-
|
1077
1052
|
@treectrl.delete_children(item)
|
1078
1053
|
end
|
1079
1054
|
|
@@ -1096,7 +1071,7 @@ class MyFrame < Wx::Frame
|
|
1096
1071
|
end
|
1097
1072
|
|
1098
1073
|
@treectrl.create_image_list(size)
|
1099
|
-
Wx::
|
1074
|
+
Wx::THE_APP.show_images = true
|
1100
1075
|
end
|
1101
1076
|
|
1102
1077
|
def on_toggle_images(event)
|
@@ -1121,46 +1096,42 @@ class MyFrame < Wx::Frame
|
|
1121
1096
|
end
|
1122
1097
|
|
1123
1098
|
def on_insert_item(event)
|
1124
|
-
image = Wx::
|
1125
|
-
@treectrl.insert_item(@treectrl.
|
1099
|
+
image = Wx::THE_APP.show_images() ? TreeCtrlIcon_File : -1
|
1100
|
+
@treectrl.insert_item(@treectrl.root_item, -1, "2nd item", image)
|
1126
1101
|
end
|
1127
1102
|
|
1128
1103
|
def on_add_item(event)
|
1129
1104
|
@s_num += 1
|
1130
1105
|
text = sprintf("Item #%d", @s_num)
|
1131
|
-
@treectrl.append_item(@treectrl.
|
1106
|
+
@treectrl.append_item(@treectrl.root_item, text)
|
1132
1107
|
end
|
1133
1108
|
|
1134
1109
|
def on_inc_indent(event)
|
1135
|
-
|
1136
|
-
|
1137
|
-
@treectrl.set_indent( indent+5 )
|
1110
|
+
if @treectrl.indent < 100
|
1111
|
+
@treectrl.indent += 5
|
1138
1112
|
end
|
1139
1113
|
end
|
1140
1114
|
|
1141
1115
|
def on_dec_indent(event)
|
1142
|
-
|
1143
|
-
|
1144
|
-
@treectrl.set_indent( indent-5 )
|
1116
|
+
if @treectrl.indent > 10
|
1117
|
+
@treectrl.indent -= 5
|
1145
1118
|
end
|
1146
1119
|
end
|
1147
1120
|
|
1148
1121
|
def on_inc_spacing(event)
|
1149
|
-
|
1150
|
-
|
1151
|
-
@treectrl.set_spacing( indent+5 )
|
1122
|
+
if @treectrl.spacing < 100
|
1123
|
+
@treectrl.spacing += 5
|
1152
1124
|
end
|
1153
1125
|
end
|
1154
1126
|
|
1155
1127
|
def on_dec_spacing(event)
|
1156
|
-
|
1157
|
-
|
1158
|
-
@treectrl.set_spacing( indent-5 )
|
1128
|
+
if @treectrl.spacing > 10
|
1129
|
+
@treectrl.spacing -= 5
|
1159
1130
|
end
|
1160
1131
|
end
|
1161
1132
|
|
1162
1133
|
def on_toggle_icon(event)
|
1163
|
-
item = @treectrl.
|
1134
|
+
item = @treectrl.selection
|
1164
1135
|
return nil unless check_item( item )
|
1165
1136
|
@treectrl.do_toggle_icon(item)
|
1166
1137
|
end
|
@@ -1169,9 +1140,9 @@ class MyFrame < Wx::Frame
|
|
1169
1140
|
def on_set_fg_colour(event)
|
1170
1141
|
Wx::log_message('NOT IMPLEMENTED')
|
1171
1142
|
return
|
1172
|
-
col = Wx::get_colour_from_user(self, @treectrl.
|
1173
|
-
if col.
|
1174
|
-
@treectrl.
|
1143
|
+
col = Wx::get_colour_from_user(self, @treectrl.foreground_colour)
|
1144
|
+
if col.ok?
|
1145
|
+
@treectrl.foreground_colour = col
|
1175
1146
|
end
|
1176
1147
|
end
|
1177
1148
|
|
@@ -1179,9 +1150,9 @@ class MyFrame < Wx::Frame
|
|
1179
1150
|
def on_set_bg_colour(event)
|
1180
1151
|
Wx::log_message('NOT IMPLEMENTED')
|
1181
1152
|
return
|
1182
|
-
col = Wx::get_colour_from_user(self, @treectrl.
|
1183
|
-
if col.
|
1184
|
-
@treectrl.
|
1153
|
+
col = Wx::get_colour_from_user(self, @treectrl.background_colour)
|
1154
|
+
if col.ok?
|
1155
|
+
@treectrl.background_colour = col
|
1185
1156
|
end
|
1186
1157
|
end
|
1187
1158
|
|
@@ -1198,7 +1169,7 @@ class MyApp < Wx::App
|
|
1198
1169
|
def on_init
|
1199
1170
|
# Create the main frame window
|
1200
1171
|
frame = MyFrame.new("TreeCtrl Test", 50, 50, 450, 600)
|
1201
|
-
|
1172
|
+
gc_stress
|
1202
1173
|
# show the frame
|
1203
1174
|
frame.show(true)
|
1204
1175
|
# set_top_window(frame)
|
@@ -1206,5 +1177,5 @@ class MyApp < Wx::App
|
|
1206
1177
|
end
|
1207
1178
|
end
|
1208
1179
|
|
1209
|
-
|
1210
|
-
|
1180
|
+
app = MyApp.new
|
1181
|
+
app.main_loop
|