wxruby 1.9.9-x86-mingw32 → 1.9.10-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -53
- data/README +297 -297
- data/lib/wx.rb +53 -53
- 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/SAMPLES-LICENSE.TXT +17 -17
- data/samples/bigdemo/About.rbw +39 -39
- data/samples/bigdemo/ColorPanel.rbw +23 -23
- data/samples/bigdemo/GridSimple.rbw +78 -78
- data/samples/bigdemo/MDIDemo.rbw +57 -57
- data/samples/bigdemo/PopupMenu.rbw +149 -149
- data/samples/bigdemo/Sizers.rbw +543 -543
- data/samples/bigdemo/bigdemo.rb +823 -823
- data/samples/bigdemo/demoTemplate.rbw +33 -33
- data/samples/bigdemo/icons/choice.xpm +27 -27
- data/samples/bigdemo/icons/combo.xpm +27 -27
- data/samples/bigdemo/icons/copy.xpm +25 -25
- data/samples/bigdemo/icons/cut.xpm +24 -24
- data/samples/bigdemo/icons/gauge.xpm +27 -27
- data/samples/bigdemo/icons/help.xpm +25 -25
- data/samples/bigdemo/icons/list.xpm +27 -27
- data/samples/bigdemo/icons/mondrian.xpm +44 -44
- data/samples/bigdemo/icons/new.xpm +24 -24
- data/samples/bigdemo/icons/ogl.ico +0 -0
- data/samples/bigdemo/icons/ogl.xpm +45 -45
- data/samples/bigdemo/icons/open.xpm +26 -26
- data/samples/bigdemo/icons/paste.xpm +38 -38
- data/samples/bigdemo/icons/preview.xpm +26 -26
- data/samples/bigdemo/icons/print.xpm +26 -26
- data/samples/bigdemo/icons/radio.xpm +27 -27
- data/samples/bigdemo/icons/robert.xpm +415 -415
- data/samples/bigdemo/icons/save.xpm +25 -25
- data/samples/bigdemo/icons/smiles.xpm +39 -39
- data/samples/bigdemo/icons/smiley.xpm +42 -42
- data/samples/bigdemo/icons/stattext.xpm +24 -24
- data/samples/bigdemo/icons/test2.bmp +0 -0
- data/samples/bigdemo/icons/test2.xpm +79 -79
- data/samples/bigdemo/icons/text.xpm +27 -27
- data/samples/bigdemo/icons/tog1.xpm +38 -38
- data/samples/bigdemo/icons/tog2.xpm +38 -38
- data/samples/bigdemo/icons/wxwin16x16.xpm +25 -25
- data/samples/bigdemo/tips.txt +7 -7
- data/samples/bigdemo/utils.rb +11 -11
- data/samples/bigdemo/wxButton.rbw +64 -64
- data/samples/bigdemo/wxCalendarCtrl.rbw +60 -60
- data/samples/bigdemo/wxCheckBox.rbw +50 -50
- data/samples/bigdemo/wxCheckListBox.rbw +65 -75
- data/samples/bigdemo/wxChoice.rbw +47 -47
- data/samples/bigdemo/wxColourDialog.rbw +31 -31
- data/samples/bigdemo/wxComboBox.rbw +77 -77
- data/samples/bigdemo/wxDialog.rbw +74 -74
- data/samples/bigdemo/wxDirDialog.rbw +29 -29
- data/samples/bigdemo/wxFileDialog.rbw +37 -37
- data/samples/bigdemo/wxFileDialog_Save.rbw +35 -35
- data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -82
- data/samples/bigdemo/wxFontDialog.rbw +173 -173
- data/samples/bigdemo/wxFrame.rbw +53 -53
- data/samples/bigdemo/wxGauge.rbw +71 -71
- data/samples/bigdemo/wxGrid.rbw +66 -66
- data/samples/bigdemo/wxListBox.rbw +140 -140
- data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -107
- data/samples/bigdemo/wxMDIWindows.rbw +50 -50
- data/samples/bigdemo/wxMenu.rbw +236 -236
- data/samples/bigdemo/wxMessageDialog.rbw +27 -27
- data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -32
- data/samples/bigdemo/wxNotebook.rbw +136 -136
- data/samples/bigdemo/wxProgressDialog.rbw +43 -43
- data/samples/bigdemo/wxRadioBox.rbw +72 -72
- data/samples/bigdemo/wxRadioButton.rbw +125 -125
- data/samples/bigdemo/wxSashWindow.rbw +2 -2
- data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -57
- data/samples/bigdemo/wxScrolledWindow.rbw +199 -199
- data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -33
- data/samples/bigdemo/wxSlider.rbw +42 -42
- data/samples/bigdemo/wxSpinButton.rbw +50 -50
- data/samples/bigdemo/wxSpinCtrl.rbw +51 -51
- data/samples/bigdemo/wxSplitterWindow.rbw +63 -63
- data/samples/bigdemo/wxStaticBitmap.rbw +51 -51
- data/samples/bigdemo/wxStaticText.rbw +55 -55
- data/samples/bigdemo/wxStatusBar.rbw +126 -126
- data/samples/bigdemo/wxTextCtrl.rbw +149 -149
- data/samples/bigdemo/wxTextEntryDialog.rbw +31 -31
- data/samples/bigdemo/wxToggleButton.rbw +49 -49
- data/samples/bigdemo/wxToolBar.rbw +131 -131
- data/samples/bigdemo/wxTreeCtrl.rbw +191 -190
- data/samples/calendar/calendar.rb +256 -271
- data/samples/caret/caret.rb +282 -282
- data/samples/caret/mondrian.xpm +44 -44
- data/samples/controls/controls.rb +1136 -1136
- data/samples/controls/get_item_sample.rb +87 -87
- data/samples/controls/icons/choice.xpm +27 -27
- data/samples/controls/icons/combo.xpm +27 -27
- data/samples/controls/icons/gauge.xpm +27 -27
- data/samples/controls/icons/list.xpm +27 -27
- data/samples/controls/icons/radio.xpm +27 -27
- data/samples/controls/icons/stattext.xpm +24 -24
- data/samples/controls/icons/text.xpm +27 -27
- data/samples/controls/mondrian.xpm +44 -44
- data/samples/dialogs/dialogs.rb +797 -723
- data/samples/dialogs/tips.txt +18 -18
- data/samples/drawing/images.rb +37 -37
- data/samples/etc/activation.rb +102 -102
- data/samples/etc/choice.rb +67 -67
- data/samples/etc/miniframe.rb +79 -79
- data/samples/etc/sash.rb +130 -130
- data/samples/etc/scrollwin.rb +110 -110
- data/samples/etc/system_settings.rb +252 -252
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/etc/wizard.rb +74 -74
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/gridtablebase.rb +43 -29
- data/samples/listbook/listbook.rb +174 -174
- data/samples/listbook/listbook.xrc +370 -370
- data/samples/mdi/mdi.rb +85 -77
- data/samples/minimal/minimal.rb +77 -77
- data/samples/minimal/nothing.rb +16 -16
- 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 +111 -113
- data/samples/text/unicode.rb +242 -242
- data/samples/text/utf8.txt +14 -14
- data/samples/treectrl/treectrl.rb +1166 -1174
- data/samples/xrc/samples.xrc +46 -46
- data/samples/xrc/xrc_sample.rb +76 -96
- metadata +15 -3
data/samples/caret/caret.rb
CHANGED
@@ -1,282 +1,282 @@
|
|
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
|
-
begin
|
5
|
-
require 'rubygems'
|
6
|
-
rescue LoadError
|
7
|
-
end
|
8
|
-
require 'wx'
|
9
|
-
|
10
|
-
|
11
|
-
include Wx
|
12
|
-
|
13
|
-
# menu items
|
14
|
-
Caret_set_blink_time = 3
|
15
|
-
Caret_Move = 4
|
16
|
-
|
17
|
-
# controls start here (the numbers are, of course, arbitrary)
|
18
|
-
Caret_Text = 1000
|
19
|
-
|
20
|
-
|
21
|
-
# MyCanvas is a canvas on which you can type
|
22
|
-
class MyCanvas < ScrolledWindow
|
23
|
-
def initialize(parent)
|
24
|
-
super(parent, :style => SUNKEN_BORDER)
|
25
|
-
|
26
|
-
self.background_colour = WHITE
|
27
|
-
|
28
|
-
@font = Font.new(12, FONTFAMILY_TELETYPE,
|
29
|
-
FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)
|
30
|
-
|
31
|
-
@x_caret = @y_caret = @x_chars = @y_chars = 0
|
32
|
-
@x_margin = @y_margin = 5
|
33
|
-
@text = nil
|
34
|
-
|
35
|
-
create_caret
|
36
|
-
|
37
|
-
evt_paint :on_paint
|
38
|
-
evt_size :on_size
|
39
|
-
evt_char :on_char
|
40
|
-
end
|
41
|
-
|
42
|
-
def [](x,y)
|
43
|
-
@text[x + @x_chars * y,1]
|
44
|
-
end
|
45
|
-
|
46
|
-
def []=(x,y,z)
|
47
|
-
@text[x + @x_chars * y,1] = z
|
48
|
-
end
|
49
|
-
|
50
|
-
# caret movement
|
51
|
-
def home_pos
|
52
|
-
@x_caret = 0
|
53
|
-
end
|
54
|
-
|
55
|
-
def end_pos
|
56
|
-
@x_caret = @x_chars - 1
|
57
|
-
end
|
58
|
-
|
59
|
-
def first_line
|
60
|
-
@y_caret = 0
|
61
|
-
end
|
62
|
-
|
63
|
-
def last_line
|
64
|
-
@y_caret = @y_chars - 1
|
65
|
-
end
|
66
|
-
|
67
|
-
def prev_char
|
68
|
-
if @x_caret == 0
|
69
|
-
end_pos
|
70
|
-
prev_line
|
71
|
-
else
|
72
|
-
@x_caret -= 1
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def next_char
|
77
|
-
@x_caret += 1
|
78
|
-
if @x_caret == @x_chars
|
79
|
-
home_pos
|
80
|
-
next_line
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def prev_line
|
85
|
-
if @y_caret == 0
|
86
|
-
last_line
|
87
|
-
else
|
88
|
-
@y_caret -= 1
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def next_line
|
93
|
-
@y_caret += 1
|
94
|
-
if @y_caret == @y_chars
|
95
|
-
first_line
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def create_caret
|
100
|
-
paint do | dc |
|
101
|
-
dc.font = @font
|
102
|
-
@height_char = dc.char_height
|
103
|
-
@width_char = dc.char_width
|
104
|
-
|
105
|
-
my_caret = Caret.new(self, Size.new(@width_char, @height_char))
|
106
|
-
self.caret = my_caret
|
107
|
-
|
108
|
-
caret.move [ @x_margin, @y_margin ]
|
109
|
-
caret.show
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
def move_caret(x,y)
|
114
|
-
@x_caret = x
|
115
|
-
@y_caret = y
|
116
|
-
|
117
|
-
do_move_caret
|
118
|
-
end
|
119
|
-
|
120
|
-
def do_move_caret
|
121
|
-
log_status("Caret is at (%d, %d)", @x_caret, @y_caret)
|
122
|
-
|
123
|
-
caret.move_xy( @x_margin + @x_caret * @width_char,
|
124
|
-
@y_margin + @y_caret * @height_char)
|
125
|
-
end
|
126
|
-
|
127
|
-
def on_size(event)
|
128
|
-
@x_chars = (event.size.x - 2 * @x_margin) / @width_char
|
129
|
-
@y_chars = (event.size.y - 2 * @y_margin) / @height_char
|
130
|
-
if @x_chars <= 0
|
131
|
-
@x_chars = 1
|
132
|
-
end
|
133
|
-
if @y_chars <= 0
|
134
|
-
@y_chars = 1
|
135
|
-
end
|
136
|
-
if @x_caret >= @x_chars
|
137
|
-
@x_caret = @x_chars-1
|
138
|
-
end
|
139
|
-
if @y_caret >= @y_chars
|
140
|
-
@y_caret = @y_chars-1
|
141
|
-
end
|
142
|
-
|
143
|
-
@text = " " * @x_chars * @y_chars
|
144
|
-
|
145
|
-
if parent && parent.status_bar
|
146
|
-
msg = sprintf("Panel size is (%d, %d)", @x_chars, @y_chars)
|
147
|
-
parent.set_status_text(msg, 1)
|
148
|
-
parent.refresh
|
149
|
-
end
|
150
|
-
event.skip
|
151
|
-
end
|
152
|
-
|
153
|
-
def on_paint
|
154
|
-
if caret
|
155
|
-
caret.hide
|
156
|
-
end
|
157
|
-
|
158
|
-
paint do | dc |
|
159
|
-
dc.clear
|
160
|
-
dc.set_font(@font)
|
161
|
-
|
162
|
-
for y in 0 ... @y_chars
|
163
|
-
line = @text[@x_chars * y,@x_chars]
|
164
|
-
dc.draw_text( line, @x_margin, @y_margin + y * @height_char )
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
if caret
|
169
|
-
caret.show
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def on_char(event)
|
174
|
-
case event.key_code
|
175
|
-
when K_LEFT, K_BACK
|
176
|
-
prev_char
|
177
|
-
when K_RIGHT
|
178
|
-
next_char
|
179
|
-
when K_UP
|
180
|
-
prev_line
|
181
|
-
when K_DOWN
|
182
|
-
next_line
|
183
|
-
when K_HOME
|
184
|
-
home_pos
|
185
|
-
when K_END
|
186
|
-
end_pos
|
187
|
-
when K_RETURN
|
188
|
-
home_pos
|
189
|
-
next_line
|
190
|
-
else
|
191
|
-
ch = event.key_code
|
192
|
-
if !event.alt_down and (ch >= K_SPACE) and (ch < K_DELETE)
|
193
|
-
self[@x_caret, @y_caret] = ch.chr
|
194
|
-
refresh
|
195
|
-
next_char
|
196
|
-
else
|
197
|
-
event.skip
|
198
|
-
end
|
199
|
-
end
|
200
|
-
do_move_caret
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
class MyFrame < Frame
|
205
|
-
def initialize(title, pos, size)
|
206
|
-
super(nil, -1, title, pos, size)
|
207
|
-
# set the frame icon
|
208
|
-
icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
|
209
|
-
self.icon = Icon.new(icon_file, BITMAP_TYPE_XPM)
|
210
|
-
|
211
|
-
# create a menu bar
|
212
|
-
menu_file = Menu.new
|
213
|
-
|
214
|
-
menu_file.append(Caret_set_blink_time, "&Blink time...\tCtrl-B")
|
215
|
-
menu_file.append(Caret_Move, "&Move caret\tCtrl-C")
|
216
|
-
menu_file.append_separator
|
217
|
-
menu_file.append(Wx::ID_ABOUT, "&About...\tCtrl-A", "Show about dialog")
|
218
|
-
menu_file.append_separator
|
219
|
-
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit self program")
|
220
|
-
|
221
|
-
# now append the freshly created menu to the menu bar...
|
222
|
-
menu_bar = MenuBar.new
|
223
|
-
menu_bar.append(menu_file, "&File")
|
224
|
-
|
225
|
-
# ... and attach self menu bar to the frame
|
226
|
-
self.menu_bar = menu_bar
|
227
|
-
|
228
|
-
@canvas = MyCanvas.new(self)
|
229
|
-
|
230
|
-
# This is required to set focus so that key events are directed to
|
231
|
-
# this Window, on Linux/GTK in particular
|
232
|
-
@canvas.set_focus
|
233
|
-
|
234
|
-
# create a status bar just for fun (by default with 1 pane only)
|
235
|
-
create_status_bar(2)
|
236
|
-
self.status_text = "Welcome to Windows!"
|
237
|
-
|
238
|
-
evt_menu Wx::ID_EXIT, :on_quit
|
239
|
-
evt_menu Wx::ID_ABOUT, :on_about
|
240
|
-
evt_menu Caret_set_blink_time, :on_set_blink_time
|
241
|
-
evt_menu Caret_Move, :on_caret_move
|
242
|
-
end
|
243
|
-
|
244
|
-
def on_quit
|
245
|
-
# true is to force the frame to close
|
246
|
-
close(true)
|
247
|
-
end
|
248
|
-
|
249
|
-
def on_about
|
250
|
-
message_box("The caret Windows sample, adapted for WxRuby",
|
251
|
-
"About Caret", OK | ICON_INFORMATION, self)
|
252
|
-
end
|
253
|
-
|
254
|
-
def on_caret_move
|
255
|
-
@canvas.move_caret(10, 10)
|
256
|
-
end
|
257
|
-
|
258
|
-
def on_set_blink_time
|
259
|
-
blink_time = get_number_from_user(
|
260
|
-
"The caret blink time is the time between two blinks",
|
261
|
-
"Time in milliseconds:",
|
262
|
-
"Caret sample",
|
263
|
-
Caret::get_blink_time, 0, 10000,
|
264
|
-
self)
|
265
|
-
if blink_time != -1
|
266
|
-
Caret::set_blink_time(blink_time)
|
267
|
-
@canvas.create_caret
|
268
|
-
log_status(self,"Blink time set to %d milliseconds.", blink_time)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
class CaretApp < App
|
274
|
-
def on_init
|
275
|
-
frame = MyFrame.new("Caret Windows sample",
|
276
|
-
Point.new(50, 50), Size.new(450, 340))
|
277
|
-
frame.show(true)
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
a = CaretApp.new
|
282
|
-
a.main_loop
|
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
|
+
begin
|
5
|
+
require 'rubygems'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
require 'wx'
|
9
|
+
|
10
|
+
|
11
|
+
include Wx
|
12
|
+
|
13
|
+
# menu items
|
14
|
+
Caret_set_blink_time = 3
|
15
|
+
Caret_Move = 4
|
16
|
+
|
17
|
+
# controls start here (the numbers are, of course, arbitrary)
|
18
|
+
Caret_Text = 1000
|
19
|
+
|
20
|
+
|
21
|
+
# MyCanvas is a canvas on which you can type
|
22
|
+
class MyCanvas < ScrolledWindow
|
23
|
+
def initialize(parent)
|
24
|
+
super(parent, :style => SUNKEN_BORDER)
|
25
|
+
|
26
|
+
self.background_colour = WHITE
|
27
|
+
|
28
|
+
@font = Font.new(12, FONTFAMILY_TELETYPE,
|
29
|
+
FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)
|
30
|
+
|
31
|
+
@x_caret = @y_caret = @x_chars = @y_chars = 0
|
32
|
+
@x_margin = @y_margin = 5
|
33
|
+
@text = nil
|
34
|
+
|
35
|
+
create_caret
|
36
|
+
|
37
|
+
evt_paint :on_paint
|
38
|
+
evt_size :on_size
|
39
|
+
evt_char :on_char
|
40
|
+
end
|
41
|
+
|
42
|
+
def [](x,y)
|
43
|
+
@text[x + @x_chars * y,1]
|
44
|
+
end
|
45
|
+
|
46
|
+
def []=(x,y,z)
|
47
|
+
@text[x + @x_chars * y,1] = z
|
48
|
+
end
|
49
|
+
|
50
|
+
# caret movement
|
51
|
+
def home_pos
|
52
|
+
@x_caret = 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def end_pos
|
56
|
+
@x_caret = @x_chars - 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def first_line
|
60
|
+
@y_caret = 0
|
61
|
+
end
|
62
|
+
|
63
|
+
def last_line
|
64
|
+
@y_caret = @y_chars - 1
|
65
|
+
end
|
66
|
+
|
67
|
+
def prev_char
|
68
|
+
if @x_caret == 0
|
69
|
+
end_pos
|
70
|
+
prev_line
|
71
|
+
else
|
72
|
+
@x_caret -= 1
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def next_char
|
77
|
+
@x_caret += 1
|
78
|
+
if @x_caret == @x_chars
|
79
|
+
home_pos
|
80
|
+
next_line
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def prev_line
|
85
|
+
if @y_caret == 0
|
86
|
+
last_line
|
87
|
+
else
|
88
|
+
@y_caret -= 1
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def next_line
|
93
|
+
@y_caret += 1
|
94
|
+
if @y_caret == @y_chars
|
95
|
+
first_line
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def create_caret
|
100
|
+
paint do | dc |
|
101
|
+
dc.font = @font
|
102
|
+
@height_char = dc.char_height
|
103
|
+
@width_char = dc.char_width
|
104
|
+
|
105
|
+
my_caret = Caret.new(self, Size.new(@width_char, @height_char))
|
106
|
+
self.caret = my_caret
|
107
|
+
|
108
|
+
caret.move [ @x_margin, @y_margin ]
|
109
|
+
caret.show
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def move_caret(x,y)
|
114
|
+
@x_caret = x
|
115
|
+
@y_caret = y
|
116
|
+
|
117
|
+
do_move_caret
|
118
|
+
end
|
119
|
+
|
120
|
+
def do_move_caret
|
121
|
+
log_status("Caret is at (%d, %d)", @x_caret, @y_caret)
|
122
|
+
|
123
|
+
caret.move_xy( @x_margin + @x_caret * @width_char,
|
124
|
+
@y_margin + @y_caret * @height_char)
|
125
|
+
end
|
126
|
+
|
127
|
+
def on_size(event)
|
128
|
+
@x_chars = (event.size.x - 2 * @x_margin) / @width_char
|
129
|
+
@y_chars = (event.size.y - 2 * @y_margin) / @height_char
|
130
|
+
if @x_chars <= 0
|
131
|
+
@x_chars = 1
|
132
|
+
end
|
133
|
+
if @y_chars <= 0
|
134
|
+
@y_chars = 1
|
135
|
+
end
|
136
|
+
if @x_caret >= @x_chars
|
137
|
+
@x_caret = @x_chars-1
|
138
|
+
end
|
139
|
+
if @y_caret >= @y_chars
|
140
|
+
@y_caret = @y_chars-1
|
141
|
+
end
|
142
|
+
|
143
|
+
@text = " " * @x_chars * @y_chars
|
144
|
+
|
145
|
+
if parent && parent.status_bar
|
146
|
+
msg = sprintf("Panel size is (%d, %d)", @x_chars, @y_chars)
|
147
|
+
parent.set_status_text(msg, 1)
|
148
|
+
parent.refresh
|
149
|
+
end
|
150
|
+
event.skip
|
151
|
+
end
|
152
|
+
|
153
|
+
def on_paint
|
154
|
+
if caret
|
155
|
+
caret.hide
|
156
|
+
end
|
157
|
+
|
158
|
+
paint do | dc |
|
159
|
+
dc.clear
|
160
|
+
dc.set_font(@font)
|
161
|
+
|
162
|
+
for y in 0 ... @y_chars
|
163
|
+
line = @text[@x_chars * y,@x_chars]
|
164
|
+
dc.draw_text( line, @x_margin, @y_margin + y * @height_char )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if caret
|
169
|
+
caret.show
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def on_char(event)
|
174
|
+
case event.key_code
|
175
|
+
when K_LEFT, K_BACK
|
176
|
+
prev_char
|
177
|
+
when K_RIGHT
|
178
|
+
next_char
|
179
|
+
when K_UP
|
180
|
+
prev_line
|
181
|
+
when K_DOWN
|
182
|
+
next_line
|
183
|
+
when K_HOME
|
184
|
+
home_pos
|
185
|
+
when K_END
|
186
|
+
end_pos
|
187
|
+
when K_RETURN
|
188
|
+
home_pos
|
189
|
+
next_line
|
190
|
+
else
|
191
|
+
ch = event.key_code
|
192
|
+
if !event.alt_down and (ch >= K_SPACE) and (ch < K_DELETE)
|
193
|
+
self[@x_caret, @y_caret] = ch.chr
|
194
|
+
refresh
|
195
|
+
next_char
|
196
|
+
else
|
197
|
+
event.skip
|
198
|
+
end
|
199
|
+
end
|
200
|
+
do_move_caret
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
class MyFrame < Frame
|
205
|
+
def initialize(title, pos, size)
|
206
|
+
super(nil, -1, title, pos, size)
|
207
|
+
# set the frame icon
|
208
|
+
icon_file = File.join(File.dirname(__FILE__), 'mondrian.xpm')
|
209
|
+
self.icon = Icon.new(icon_file, BITMAP_TYPE_XPM)
|
210
|
+
|
211
|
+
# create a menu bar
|
212
|
+
menu_file = Menu.new
|
213
|
+
|
214
|
+
menu_file.append(Caret_set_blink_time, "&Blink time...\tCtrl-B")
|
215
|
+
menu_file.append(Caret_Move, "&Move caret\tCtrl-C")
|
216
|
+
menu_file.append_separator
|
217
|
+
menu_file.append(Wx::ID_ABOUT, "&About...\tCtrl-A", "Show about dialog")
|
218
|
+
menu_file.append_separator
|
219
|
+
menu_file.append(Wx::ID_EXIT, "E&xit\tAlt-X", "Quit self program")
|
220
|
+
|
221
|
+
# now append the freshly created menu to the menu bar...
|
222
|
+
menu_bar = MenuBar.new
|
223
|
+
menu_bar.append(menu_file, "&File")
|
224
|
+
|
225
|
+
# ... and attach self menu bar to the frame
|
226
|
+
self.menu_bar = menu_bar
|
227
|
+
|
228
|
+
@canvas = MyCanvas.new(self)
|
229
|
+
|
230
|
+
# This is required to set focus so that key events are directed to
|
231
|
+
# this Window, on Linux/GTK in particular
|
232
|
+
@canvas.set_focus
|
233
|
+
|
234
|
+
# create a status bar just for fun (by default with 1 pane only)
|
235
|
+
create_status_bar(2)
|
236
|
+
self.status_text = "Welcome to Windows!"
|
237
|
+
|
238
|
+
evt_menu Wx::ID_EXIT, :on_quit
|
239
|
+
evt_menu Wx::ID_ABOUT, :on_about
|
240
|
+
evt_menu Caret_set_blink_time, :on_set_blink_time
|
241
|
+
evt_menu Caret_Move, :on_caret_move
|
242
|
+
end
|
243
|
+
|
244
|
+
def on_quit
|
245
|
+
# true is to force the frame to close
|
246
|
+
close(true)
|
247
|
+
end
|
248
|
+
|
249
|
+
def on_about
|
250
|
+
message_box("The caret Windows sample, adapted for WxRuby",
|
251
|
+
"About Caret", OK | ICON_INFORMATION, self)
|
252
|
+
end
|
253
|
+
|
254
|
+
def on_caret_move
|
255
|
+
@canvas.move_caret(10, 10)
|
256
|
+
end
|
257
|
+
|
258
|
+
def on_set_blink_time
|
259
|
+
blink_time = get_number_from_user(
|
260
|
+
"The caret blink time is the time between two blinks",
|
261
|
+
"Time in milliseconds:",
|
262
|
+
"Caret sample",
|
263
|
+
Caret::get_blink_time, 0, 10000,
|
264
|
+
self)
|
265
|
+
if blink_time != -1
|
266
|
+
Caret::set_blink_time(blink_time)
|
267
|
+
@canvas.create_caret
|
268
|
+
log_status(self,"Blink time set to %d milliseconds.", blink_time)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
class CaretApp < App
|
274
|
+
def on_init
|
275
|
+
frame = MyFrame.new("Caret Windows sample",
|
276
|
+
Point.new(50, 50), Size.new(450, 340))
|
277
|
+
frame.show(true)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
a = CaretApp.new
|
282
|
+
a.main_loop
|