wrb 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +28 -0
- data/Rakefile +66 -0
- data/bin/wrb +41 -0
- data/bin/wrb.bat +6 -0
- data/ext/rwin/aatree.c +192 -0
- data/ext/rwin/aatree.h +55 -0
- data/ext/rwin/extconf.rb +47 -0
- data/ext/rwin/rw_api.c +2058 -0
- data/ext/rwin/rw_devices.c +215 -0
- data/ext/rwin/rw_gdiplus.h +278 -0
- data/ext/rwin/rw_graphics.c +1583 -0
- data/ext/rwin/rw_resources.c +1988 -0
- data/ext/rwin/rw_ubfuncs.c +281 -0
- data/ext/rwin/rw_windows.c +1936 -0
- data/ext/rwin/rwin.c +451 -0
- data/ext/rwin/rwin.h +442 -0
- data/lib/rwin.rb +820 -0
- data/lib/wrb.rb +20 -0
- data/lib/wrb/applications/frmdesigner/angle.cur +0 -0
- data/lib/wrb/applications/frmdesigner/angle2.cur +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Button.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Button.rb +34 -0
- data/lib/wrb/applications/frmdesigner/controls/Checkbox.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Checkbox.rb +10 -0
- data/lib/wrb/applications/frmdesigner/controls/Combobox.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Combobox.rb +88 -0
- data/lib/wrb/applications/frmdesigner/controls/ComboboxEx.rb +97 -0
- data/lib/wrb/applications/frmdesigner/controls/Comboboxex.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/DateTimePicker.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/DateTimePicker.rb +11 -0
- data/lib/wrb/applications/frmdesigner/controls/Edit.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Edit.rb +8 -0
- data/lib/wrb/applications/frmdesigner/controls/Groupbox.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Groupbox.rb +9 -0
- data/lib/wrb/applications/frmdesigner/controls/Hotkeyctrl.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Hotkeyctrl.rb +9 -0
- data/lib/wrb/applications/frmdesigner/controls/Imagelist.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Imagelist.rb +115 -0
- data/lib/wrb/applications/frmdesigner/controls/Listbox.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Listbox.rb +77 -0
- data/lib/wrb/applications/frmdesigner/controls/Listview.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Listview.rb +157 -0
- data/lib/wrb/applications/frmdesigner/controls/Menu.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Menu.rb +198 -0
- data/lib/wrb/applications/frmdesigner/controls/Menubar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Menubar.rb +9 -0
- data/lib/wrb/applications/frmdesigner/controls/MonthCalender.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Monthcalender.rb +9 -0
- data/lib/wrb/applications/frmdesigner/controls/Panel.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Panel.rb +30 -0
- data/lib/wrb/applications/frmdesigner/controls/Progressbar.rb +10 -0
- data/lib/wrb/applications/frmdesigner/controls/Radiobutton.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Radiobutton.rb +13 -0
- data/lib/wrb/applications/frmdesigner/controls/Rebar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Rebar.rb +162 -0
- data/lib/wrb/applications/frmdesigner/controls/Splitter.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Splitter.rb +66 -0
- data/lib/wrb/applications/frmdesigner/controls/Static.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Static.rb +9 -0
- data/lib/wrb/applications/frmdesigner/controls/Statusbar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Statusbar.rb +103 -0
- data/lib/wrb/applications/frmdesigner/controls/Tabctrl.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Tabctrl.rb +136 -0
- data/lib/wrb/applications/frmdesigner/controls/Timer.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Timer.rb +36 -0
- data/lib/wrb/applications/frmdesigner/controls/Toolbar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Toolbar.rb +165 -0
- data/lib/wrb/applications/frmdesigner/controls/Trackbar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Trackbar.rb +34 -0
- data/lib/wrb/applications/frmdesigner/controls/Treeview.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Treeview.rb +107 -0
- data/lib/wrb/applications/frmdesigner/controls/Updown.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/Updown.rb +31 -0
- data/lib/wrb/applications/frmdesigner/controls/default.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/progressbar.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/controls/unselect.bmp +0 -0
- data/lib/wrb/applications/frmdesigner/fddialogs.rb +87 -0
- data/lib/wrb/applications/frmdesigner/fdesign.rb +1315 -0
- data/lib/wrb/applications/frmdesigner/fdmodules.rb +1394 -0
- data/lib/wrb/applications/frmdesigner/fdparseform.rb +197 -0
- data/lib/wrb/applications/frmdesigner/img13.bmp +0 -0
- data/lib/wrb/base.rb +1294 -0
- data/lib/wrb/combocommon.rb +77 -0
- data/lib/wrb/commctrlconst.rb +139 -0
- data/lib/wrb/commdlg.rb +77 -0
- data/lib/wrb/components/animate.rb +114 -0
- data/lib/wrb/components/bitmap.rb +116 -0
- data/lib/wrb/components/button.rb +134 -0
- data/lib/wrb/components/canvas.rb +266 -0
- data/lib/wrb/components/checkbox.rb +118 -0
- data/lib/wrb/components/choosecolordlg.rb +87 -0
- data/lib/wrb/components/choosefontdlg.rb +142 -0
- data/lib/wrb/components/clipboard.rb +174 -0
- data/lib/wrb/components/combobox.rb +282 -0
- data/lib/wrb/components/comboboxex.rb +574 -0
- data/lib/wrb/components/cursor.rb +91 -0
- data/lib/wrb/components/datetimepicker.rb +197 -0
- data/lib/wrb/components/ddeclient.rb +180 -0
- data/lib/wrb/components/ddeserver.rb +131 -0
- data/lib/wrb/components/dialog.rb +228 -0
- data/lib/wrb/components/edit.rb +412 -0
- data/lib/wrb/components/font.rb +35 -0
- data/lib/wrb/components/form.rb +65 -0
- data/lib/wrb/components/groupbox.rb +122 -0
- data/lib/wrb/components/header.rb +479 -0
- data/lib/wrb/components/hotkeyctrl.rb +72 -0
- data/lib/wrb/components/icon.rb +109 -0
- data/lib/wrb/components/imagelist.rb +396 -0
- data/lib/wrb/components/inifile.rb +97 -0
- data/lib/wrb/components/listbox.rb +149 -0
- data/lib/wrb/components/listview.rb +1467 -0
- data/lib/wrb/components/menu.rb +592 -0
- data/lib/wrb/components/menubar.rb +84 -0
- data/lib/wrb/components/monthcalender.rb +164 -0
- data/lib/wrb/components/openfilenamedlg.rb +147 -0
- data/lib/wrb/components/pager.rb +199 -0
- data/lib/wrb/components/panel.rb +103 -0
- data/lib/wrb/components/picture.rb +55 -0
- data/lib/wrb/components/printdlg.rb +148 -0
- data/lib/wrb/components/printdlgex.rb +117 -0
- data/lib/wrb/components/printer.rb +97 -0
- data/lib/wrb/components/progressbar.rb +140 -0
- data/lib/wrb/components/radiobutton.rb +49 -0
- data/lib/wrb/components/rebar.rb +830 -0
- data/lib/wrb/components/registry.rb +408 -0
- data/lib/wrb/components/richedit.rb +1181 -0
- data/lib/wrb/components/savefilenamedlg.rb +27 -0
- data/lib/wrb/components/scintilla.rb +1298 -0
- data/lib/wrb/components/scrollbar.rb +239 -0
- data/lib/wrb/components/splitter.rb +494 -0
- data/lib/wrb/components/static.rb +198 -0
- data/lib/wrb/components/statusbar.rb +490 -0
- data/lib/wrb/components/tabctrl.rb +686 -0
- data/lib/wrb/components/timer.rb +117 -0
- data/lib/wrb/components/toolbar.rb +1107 -0
- data/lib/wrb/components/tooltip.rb +651 -0
- data/lib/wrb/components/trackbar.rb +298 -0
- data/lib/wrb/components/treeview.rb +845 -0
- data/lib/wrb/components/updown.rb +198 -0
- data/lib/wrb/ddeml.rb +241 -0
- data/lib/wrb/documents/animate.html +46 -0
- data/lib/wrb/documents/bitmap.html +69 -0
- data/lib/wrb/documents/button.html +78 -0
- data/lib/wrb/documents/canvas.html +137 -0
- data/lib/wrb/documents/checkbox.html +77 -0
- data/lib/wrb/documents/choosecolordlg.html +29 -0
- data/lib/wrb/documents/choosefontdlg.html +31 -0
- data/lib/wrb/documents/clipboard.html +31 -0
- data/lib/wrb/documents/combobox.html +117 -0
- data/lib/wrb/documents/comboboxex.html +139 -0
- data/lib/wrb/documents/control.html +53 -0
- data/lib/wrb/documents/cursor.html +45 -0
- data/lib/wrb/documents/datetimepicker.html +70 -0
- data/lib/wrb/documents/ddeclient.html +33 -0
- data/lib/wrb/documents/ddeserver.html +26 -0
- data/lib/wrb/documents/dialog.html +78 -0
- data/lib/wrb/documents/edit.html +169 -0
- data/lib/wrb/documents/empty.html +11 -0
- data/lib/wrb/documents/favicon.png +0 -0
- data/lib/wrb/documents/font.html +38 -0
- data/lib/wrb/documents/form.html +63 -0
- data/lib/wrb/documents/groupbox.html +57 -0
- data/lib/wrb/documents/header.html +85 -0
- data/lib/wrb/documents/hotkeyctrl.html +42 -0
- data/lib/wrb/documents/icon.html +45 -0
- data/lib/wrb/documents/imagelist.html +101 -0
- data/lib/wrb/documents/images/button.png +0 -0
- data/lib/wrb/documents/images/checkbox.png +0 -0
- data/lib/wrb/documents/images/combobox.png +0 -0
- data/lib/wrb/documents/images/comboboxex.png +0 -0
- data/lib/wrb/documents/images/datetimepicker.png +0 -0
- data/lib/wrb/documents/images/edit.png +0 -0
- data/lib/wrb/documents/images/groupbox.png +0 -0
- data/lib/wrb/documents/images/hotkeyctrl.png +0 -0
- data/lib/wrb/documents/images/listbox.png +0 -0
- data/lib/wrb/documents/images/listview.png +0 -0
- data/lib/wrb/documents/images/menu.png +0 -0
- data/lib/wrb/documents/images/menubar.png +0 -0
- data/lib/wrb/documents/images/monthcalender.png +0 -0
- data/lib/wrb/documents/images/progressbar.png +0 -0
- data/lib/wrb/documents/images/radiobutton.png +0 -0
- data/lib/wrb/documents/images/rebar.png +0 -0
- data/lib/wrb/documents/images/richedit.png +0 -0
- data/lib/wrb/documents/images/splitter.png +0 -0
- data/lib/wrb/documents/images/static.png +0 -0
- data/lib/wrb/documents/images/statusbar.png +0 -0
- data/lib/wrb/documents/images/tabctrl.png +0 -0
- data/lib/wrb/documents/images/toolbar.png +0 -0
- data/lib/wrb/documents/images/tooltip.png +0 -0
- data/lib/wrb/documents/images/trackbar.png +0 -0
- data/lib/wrb/documents/images/treeview.png +0 -0
- data/lib/wrb/documents/images/updown.png +0 -0
- data/lib/wrb/documents/index.html +155 -0
- data/lib/wrb/documents/inifile.html +36 -0
- data/lib/wrb/documents/license.txt +22 -0
- data/lib/wrb/documents/listbox.html +96 -0
- data/lib/wrb/documents/listview.html +277 -0
- data/lib/wrb/documents/make_doc.rb +596 -0
- data/lib/wrb/documents/menu.html +144 -0
- data/lib/wrb/documents/menubar.html +54 -0
- data/lib/wrb/documents/monthcalender.html +48 -0
- data/lib/wrb/documents/openfilenamedlg.html +36 -0
- data/lib/wrb/documents/pager.html +63 -0
- data/lib/wrb/documents/panel.html +32 -0
- data/lib/wrb/documents/picture.html +48 -0
- data/lib/wrb/documents/printdlg.html +35 -0
- data/lib/wrb/documents/printdlgex.html +35 -0
- data/lib/wrb/documents/printer.html +40 -0
- data/lib/wrb/documents/progressbar.html +69 -0
- data/lib/wrb/documents/radiobutton.html +51 -0
- data/lib/wrb/documents/rebar.html +143 -0
- data/lib/wrb/documents/registry.html +36 -0
- data/lib/wrb/documents/richedit.html +232 -0
- data/lib/wrb/documents/samples/editimg.bmp +0 -0
- data/lib/wrb/documents/samples/editimg.iml +0 -0
- data/lib/wrb/documents/samples/fileimg.bmp +0 -0
- data/lib/wrb/documents/samples/fileimg.iml +0 -0
- data/lib/wrb/documents/samples/sample_button.rb +21 -0
- data/lib/wrb/documents/samples/sample_checkbox.rb +18 -0
- data/lib/wrb/documents/samples/sample_combobox.rb +18 -0
- data/lib/wrb/documents/samples/sample_comboboxex.rb +23 -0
- data/lib/wrb/documents/samples/sample_datetimepicker.rb +11 -0
- data/lib/wrb/documents/samples/sample_edit.rb +25 -0
- data/lib/wrb/documents/samples/sample_groupbox.rb +19 -0
- data/lib/wrb/documents/samples/sample_hotkeyctrl.rb +12 -0
- data/lib/wrb/documents/samples/sample_listbox.rb +12 -0
- data/lib/wrb/documents/samples/sample_listview.rb +32 -0
- data/lib/wrb/documents/samples/sample_menu.rb +21 -0
- data/lib/wrb/documents/samples/sample_menubar.rb +23 -0
- data/lib/wrb/documents/samples/sample_monthcalender.rb +11 -0
- data/lib/wrb/documents/samples/sample_progressbar.rb +14 -0
- data/lib/wrb/documents/samples/sample_radiobutton.rb +14 -0
- data/lib/wrb/documents/samples/sample_rebar.rb +25 -0
- data/lib/wrb/documents/samples/sample_richedit.rb +60 -0
- data/lib/wrb/documents/samples/sample_splitter.rb +33 -0
- data/lib/wrb/documents/samples/sample_static.rb +15 -0
- data/lib/wrb/documents/samples/sample_statusbar.rb +17 -0
- data/lib/wrb/documents/samples/sample_tabctrl.rb +19 -0
- data/lib/wrb/documents/samples/sample_toolbar.rb +29 -0
- data/lib/wrb/documents/samples/sample_tooltip.rb +50 -0
- data/lib/wrb/documents/samples/sample_trackbar.rb +30 -0
- data/lib/wrb/documents/samples/sample_treeview.rb +19 -0
- data/lib/wrb/documents/samples/sample_updown.rb +18 -0
- data/lib/wrb/documents/samples/sampleimg16.iml +0 -0
- data/lib/wrb/documents/samples/sampleimg32.iml +0 -0
- data/lib/wrb/documents/samples/samplemg16.png +0 -0
- data/lib/wrb/documents/samples/samplemg32.png +0 -0
- data/lib/wrb/documents/samples/wrb.ico +0 -0
- data/lib/wrb/documents/savefilenamedlg.html +19 -0
- data/lib/wrb/documents/scrollbar.html +60 -0
- data/lib/wrb/documents/splitter.html +96 -0
- data/lib/wrb/documents/static.html +84 -0
- data/lib/wrb/documents/statusbar.html +110 -0
- data/lib/wrb/documents/tabctrl.html +151 -0
- data/lib/wrb/documents/timer.html +43 -0
- data/lib/wrb/documents/toolbar.html +181 -0
- data/lib/wrb/documents/tooltip.html +131 -0
- data/lib/wrb/documents/trackbar.html +107 -0
- data/lib/wrb/documents/treeview.html +210 -0
- data/lib/wrb/documents/updown.html +85 -0
- data/lib/wrb/documents/wincontrol.html +258 -0
- data/lib/wrb/documents/window.html +499 -0
- data/lib/wrb/documents/wrb.css +228 -0
- data/lib/wrb/gmem.rb +26 -0
- data/lib/wrb/imecommon.rb +59 -0
- data/lib/wrb/listcommon.rb +185 -0
- data/lib/wrb/lzss.rb +126 -0
- data/lib/wrb/scrollinfo.rb +142 -0
- data/lib/wrb/toplevelcommon.rb +634 -0
- metadata +315 -0
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
require 'wrb'
|
3
|
+
|
4
|
+
module WR
|
5
|
+
class FDParseForm < Ripper::Filter
|
6
|
+
# Ripper::SCANNER_EVENTS -> [:CHAR, :__end__, :backref, :backtick, :comma, :comment, :const, :cvar, :embdoc, :embdoc_beg, :embdoc_end, :embexpr_beg, :embexpr_end, :embvar, :float, :gvar, :heredoc_beg, :heredoc_end, :ident, :ignored_nl, :imaginary, :int, :ivar, :kw, :label, :label_end, :lbrace, :lbracket, :lparen, :nl, :op, :period, :qsymbols_beg, :qwords_beg, :rational, :rbrace, :rbracket, :regexp_beg, :regexp_end, :rparen, :semicolon, :sp, :symbeg, :symbols_beg, :tlambda, :tlambeg, :tstring_beg, :tstring_content, :tstring_end, :words_beg, :words_sep]
|
7
|
+
|
8
|
+
|
9
|
+
# ParseData = Struct.new(:event, :text, :line, :column)
|
10
|
+
|
11
|
+
include RC
|
12
|
+
|
13
|
+
module ParseData
|
14
|
+
attr_accessor :attr, :line, :column
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :result
|
18
|
+
|
19
|
+
def initialize(src, fname=nil, lnno=1)
|
20
|
+
super(src, fname, lnno)
|
21
|
+
@result = []
|
22
|
+
@_depth = 0
|
23
|
+
@_lines = src.split(/\r?\n/)
|
24
|
+
@_can_modifier = nil
|
25
|
+
# dpp @_lines
|
26
|
+
end
|
27
|
+
|
28
|
+
############## event handers ##############
|
29
|
+
|
30
|
+
def on_default(event, token, pd)# ; dpp lineno, event, token, pd
|
31
|
+
case event
|
32
|
+
when :on_int, :on_rbrace, :on_rbracket, :on_rparen
|
33
|
+
@_can_modifier = true
|
34
|
+
when :on_comma, :on_lbrace, :on_lbracket, :on_lparen, :on_ignored_nl
|
35
|
+
@_can_modifier = nil
|
36
|
+
end
|
37
|
+
pd << token if pd
|
38
|
+
end
|
39
|
+
|
40
|
+
def on_kw(token, pd)
|
41
|
+
case token
|
42
|
+
when 'class', 'def'
|
43
|
+
@_can_modifier = nil
|
44
|
+
@current_column = column
|
45
|
+
@_depth += 1
|
46
|
+
return token
|
47
|
+
when 'begin', 'case', 'do', 'module', 'while'
|
48
|
+
@_can_modifier = nil
|
49
|
+
@_depth += 1
|
50
|
+
when 'if', 'unless' #; dpp lineno, token, pd, @_can_modifier
|
51
|
+
if @_can_modifier
|
52
|
+
@_can_modifier = nil
|
53
|
+
else
|
54
|
+
@_depth += 1
|
55
|
+
end
|
56
|
+
# @_can_modifier = nil
|
57
|
+
when 'end'
|
58
|
+
@_can_modifier = true
|
59
|
+
@_depth -= 1
|
60
|
+
if @_in_the_initialize && @_depth < @_in_the_initialize
|
61
|
+
@_in_the_initialize = -1
|
62
|
+
end
|
63
|
+
if @_depth==1 #; dpp @_depth, lineno, column
|
64
|
+
token.extend(ParseData)
|
65
|
+
token.line = lineno - 1
|
66
|
+
token.column = column
|
67
|
+
return token
|
68
|
+
end
|
69
|
+
when 'self' #; dpp lineno, pd, token
|
70
|
+
@_can_modifier = true
|
71
|
+
if !pd && @_in_the_initialize == @_depth
|
72
|
+
token.extend(ParseData)
|
73
|
+
token.line = lineno - 1
|
74
|
+
token.column = column
|
75
|
+
return token
|
76
|
+
else
|
77
|
+
return pd << token if pd # Argument of method.
|
78
|
+
end
|
79
|
+
else
|
80
|
+
@_can_modifier = true
|
81
|
+
return pd << token if pd
|
82
|
+
end
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def on_ident(token, pd) # dpp [token, pd]
|
87
|
+
@_can_modifier = true
|
88
|
+
case token
|
89
|
+
when 'initialize'
|
90
|
+
if pd =~ /^def\s+/
|
91
|
+
@_in_the_initialize = @_depth
|
92
|
+
end
|
93
|
+
nil
|
94
|
+
when 'controls', '_', /^\_\w+/ #; dpp lineno, pd, token
|
95
|
+
if @_in_the_initialize == @_depth
|
96
|
+
unless pd
|
97
|
+
token.extend(ParseData)
|
98
|
+
token.line = lineno - 1
|
99
|
+
token.column = column
|
100
|
+
token
|
101
|
+
else
|
102
|
+
pd << token
|
103
|
+
end
|
104
|
+
end
|
105
|
+
else
|
106
|
+
case pd
|
107
|
+
when /^\_.*/, /^\_\w+\.*/, /^controls\W.*/, /^self\./ #
|
108
|
+
pd << token if pd
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def on_op(token, pd)
|
114
|
+
@_can_modifier = nil
|
115
|
+
case token
|
116
|
+
when '<<'#; dpp pd
|
117
|
+
case pd
|
118
|
+
when /^\_.*/, /^controls\W.*/ #; dpp pd + token
|
119
|
+
pd << token
|
120
|
+
end
|
121
|
+
when '<' # inherited class
|
122
|
+
if pd =~ /^class\s+[A-Z][A-Za-z0-9_]*\s*/
|
123
|
+
pd << token
|
124
|
+
end
|
125
|
+
when '='
|
126
|
+
if pd =~ /^self\.\w+\s*/
|
127
|
+
pd << token
|
128
|
+
end
|
129
|
+
else #; dpp lineno, pd, token
|
130
|
+
pd << token if pd
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def on_const(token, pd)
|
135
|
+
@_can_modifier = true
|
136
|
+
if pd =~ /^class\s+[A-Z][A-Za-z0-9_]*\s*<\s*/
|
137
|
+
case token
|
138
|
+
when 'Form', 'Dialog'
|
139
|
+
s = pd + token
|
140
|
+
s.extend(ParseData)
|
141
|
+
s.line = lineno - 1
|
142
|
+
s.column = @current_column
|
143
|
+
@result << [s]
|
144
|
+
@_in_the_form = true
|
145
|
+
else #; dpp lineno, pd, token
|
146
|
+
nil
|
147
|
+
# return pd << token
|
148
|
+
end
|
149
|
+
nil
|
150
|
+
elsif pd =~ /^class\s+/#; dpp lineno, pd, token
|
151
|
+
pd << token
|
152
|
+
elsif pd =~ /^self.\w+\s*\=.*/
|
153
|
+
pd << token
|
154
|
+
elsif pd #; dpp lineno, pd, token
|
155
|
+
# if File.exist?(WR_INSTALLED_DIR + "/wrb/components/#{token.downcase}.rb")
|
156
|
+
# require "wrb/components/#{token.downcase}.rb"
|
157
|
+
# pd << token
|
158
|
+
# elsif val = (eval(token) rescue nil)
|
159
|
+
# pd << token
|
160
|
+
# end
|
161
|
+
pd << token if (WR.module_eval(token) rescue nil)
|
162
|
+
else
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def on_nl(token, pd)
|
167
|
+
@_can_modifier = nil
|
168
|
+
@result.last << pd if !@result.empty? && pd
|
169
|
+
nil
|
170
|
+
end
|
171
|
+
|
172
|
+
def on_semicolon(token, pd)
|
173
|
+
@_can_modifier = nil
|
174
|
+
@result.last << pd if !@result.empty? && pd
|
175
|
+
nil
|
176
|
+
end
|
177
|
+
|
178
|
+
def on_comment(token, pd)
|
179
|
+
@_can_modifier = nil
|
180
|
+
@result.last << pd if !@result.empty? && pd
|
181
|
+
nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
module WR
|
187
|
+
require 'pp'
|
188
|
+
fname = OpenFileNameDlg.show()
|
189
|
+
if fname
|
190
|
+
s = open(fname){|f| f.read}
|
191
|
+
src = FDParseForm.new(s, fname)
|
192
|
+
src.parse
|
193
|
+
# dpp src.result[0][0].line
|
194
|
+
p src.result
|
195
|
+
|
196
|
+
end
|
197
|
+
end if __FILE__ == $0
|
Binary file
|
data/lib/wrb/base.rb
ADDED
@@ -0,0 +1,1294 @@
|
|
1
|
+
# base.rb
|
2
|
+
# modules and classes for all windows components of wrb
|
3
|
+
|
4
|
+
module WR
|
5
|
+
require 'rwin' if __FILE__ == $0 # for self-testing
|
6
|
+
|
7
|
+
APP = RWin::Application
|
8
|
+
API = RWin::API
|
9
|
+
UNICODE = RWin::UNICODE
|
10
|
+
CancelDefWindowProc = APP::CancelDefWindowProc
|
11
|
+
NilID = nil.__id__
|
12
|
+
|
13
|
+
module ModAutoloading
|
14
|
+
def self.included(mod)
|
15
|
+
def mod.const_missing(id)
|
16
|
+
WR.const_missing(id)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.included(mod)
|
22
|
+
def mod.const_missing(id)
|
23
|
+
WR.const_missing(id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.const_missing(id)
|
28
|
+
libname = id.to_s.downcase + ".rb"
|
29
|
+
begin
|
30
|
+
require(libname)
|
31
|
+
if const_defined?(id)
|
32
|
+
const_get(id)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
super(id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module RC # Module for gathering constants of resources and APIs.
|
42
|
+
## window messages ##
|
43
|
+
WM_NULL = 0x0000
|
44
|
+
WM_CREATE = 0x0001
|
45
|
+
WM_DESTROY = 0x0002
|
46
|
+
WM_MOVE = 0x0003
|
47
|
+
WM_SIZE = 0x0005
|
48
|
+
WM_ACTIVATE = 0x0006
|
49
|
+
WM_SETFOCUS = 0x0007
|
50
|
+
WM_KILLFOCUS = 0x0008
|
51
|
+
WM_ENABLE = 0x000A
|
52
|
+
WM_SETREDRAW = 0x000B
|
53
|
+
WM_SETTEXT = 0x000C
|
54
|
+
WM_GETTEXT = 0x000D
|
55
|
+
WM_GETTEXTLENGTH = 0x000E
|
56
|
+
WM_PAINT = 0x000F
|
57
|
+
WM_CLOSE = 0x0010
|
58
|
+
WM_QUERYENDSESSION = 0x0011
|
59
|
+
WM_QUIT = 0x0012
|
60
|
+
WM_QUERYOPEN = 0x0013
|
61
|
+
WM_ERASEBKGND = 0x0014
|
62
|
+
WM_SYSCOLORCHANGE = 0x0015
|
63
|
+
WM_ENDSESSION = 0x0016
|
64
|
+
WM_SHOWWINDOW = 0x0018
|
65
|
+
WM_WININICHANGE = 0x001A
|
66
|
+
WM_SETTINGCHANGE = WM_WININICHANGE
|
67
|
+
WM_DEVMODECHANGE = 0x001B
|
68
|
+
WM_ACTIVATEAPP = 0x001C
|
69
|
+
WM_FONTCHANGE = 0x001D
|
70
|
+
WM_TIMECHANGE = 0x001E
|
71
|
+
WM_CANCELMODE = 0x001F
|
72
|
+
WM_SETCURSOR = 0x0020
|
73
|
+
WM_MOUSEACTIVATE = 0x0021
|
74
|
+
WM_CHILDACTIVATE = 0x0022
|
75
|
+
WM_QUEUESYNC = 0x0023
|
76
|
+
WM_GETMINMAXINFO = 0x0024
|
77
|
+
WM_PAINTICON = 0x0026
|
78
|
+
WM_ICONERASEBKGND = 0x0027
|
79
|
+
WM_NEXTDLGCTL = 0x0028
|
80
|
+
WM_SPOOLERSTATUS = 0x002A
|
81
|
+
WM_DRAWITEM = 0x002B
|
82
|
+
WM_MEASUREITEM = 0x002C
|
83
|
+
WM_DELETEITEM = 0x002D
|
84
|
+
WM_VKEYTOITEM = 0x002E
|
85
|
+
WM_CHARTOITEM = 0x002F
|
86
|
+
WM_SETFONT = 0x0030
|
87
|
+
WM_GETFONT = 0x0031
|
88
|
+
WM_NOTIFY = 0x004E
|
89
|
+
WM_CONTEXTMENU = 0x007B
|
90
|
+
WM_STYLECHANGING = 0x007C
|
91
|
+
WM_STYLECHANGED = 0x007D
|
92
|
+
WM_DISPLAYCHANGE = 0x007E
|
93
|
+
WM_GETICON = 0x007F
|
94
|
+
WM_SETICON = 0x0080
|
95
|
+
WM_KEYDOWN = 0x0100
|
96
|
+
WM_KEYUP = 0x0101
|
97
|
+
WM_CHAR = 0x0102
|
98
|
+
WM_DEADCHAR = 0x0103
|
99
|
+
WM_SYSKEYDOWN = 0x0104
|
100
|
+
WM_SYSKEYUP = 0x0105
|
101
|
+
WM_SYSCHAR = 0x0106
|
102
|
+
WM_SYSDEADCHAR = 0x0107
|
103
|
+
WM_UNICHAR = 0x0109
|
104
|
+
WM_INITDIALOG = 0x0110
|
105
|
+
WM_COMMAND = 0x0111
|
106
|
+
WM_SYSCOMMAND = 0x0112
|
107
|
+
WM_TIMER = 0x0113
|
108
|
+
WM_HSCROLL = 0x0114
|
109
|
+
WM_VSCROLL = 0x0115
|
110
|
+
|
111
|
+
WM_MOUSEMOVE = 0x0200
|
112
|
+
WM_LBUTTONDOWN = 0x0201
|
113
|
+
WM_LBUTTONUP = 0x0202
|
114
|
+
WM_LBUTTONDBLCLK = 0x0203
|
115
|
+
WM_RBUTTONDOWN = 0x0204
|
116
|
+
WM_RBUTTONUP = 0x0205
|
117
|
+
WM_RBUTTONDBLCLK = 0x0206
|
118
|
+
WM_MBUTTONDOWN = 0x0207
|
119
|
+
WM_MBUTTONUP = 0x0208
|
120
|
+
WM_MBUTTONDBLCLK = 0x0209
|
121
|
+
# WM_MOUSEWHEEL = 0x020A
|
122
|
+
# WM_MOUSELAST = 0x020A
|
123
|
+
WM_XBUTTONDOWN = 0x020B
|
124
|
+
WM_XBUTTONUP = 0x020C
|
125
|
+
WM_XBUTTONDBLCLK = 0x020D
|
126
|
+
WM_MOUSEWHEEL = 0x020E
|
127
|
+
WM_MOUSELAST = 0x020E
|
128
|
+
WM_PARENTNOTIFY = 0x0210
|
129
|
+
WM_ENTERMENULOOP = 0x0211
|
130
|
+
WM_EXITMENULOOP = 0x0212
|
131
|
+
WM_NEXTMENU = 0x0213
|
132
|
+
WM_SIZING = 0x0214
|
133
|
+
WM_CAPTURECHANGED = 0x0215
|
134
|
+
WM_MOVING = 0x0216
|
135
|
+
WM_POWERBROADCAST = 0x0218
|
136
|
+
|
137
|
+
WM_DROPFILES = 0x0233
|
138
|
+
WM_CUT = 0x0300
|
139
|
+
WM_COPY = 0x0301
|
140
|
+
WM_PASTE = 0x0302
|
141
|
+
WM_CLEAR = 0x0303
|
142
|
+
WM_UNDO = 0x0304
|
143
|
+
WM_HOTKEY = 0x0312
|
144
|
+
WM_USER = 0x0400
|
145
|
+
WM_APP = 0x8000
|
146
|
+
|
147
|
+
# Message of Non Client area
|
148
|
+
WM_NCCREATE = 0x0081
|
149
|
+
WM_NCDESTROY = 0x0082
|
150
|
+
WM_NCCALCSIZE = 0x0083
|
151
|
+
WM_NCHITTEST = 0x0084
|
152
|
+
WM_NCPAINT = 0x0085
|
153
|
+
WM_NCACTIVATE = 0x0086
|
154
|
+
WM_GETDLGCODE = 0x0087
|
155
|
+
WM_SYNCPAINT = 0x0088
|
156
|
+
WM_NCMOUSEMOVE = 0x00A0
|
157
|
+
WM_NCLBUTTONDOWN = 0x00A1
|
158
|
+
WM_NCLBUTTONUP = 0x00A2
|
159
|
+
WM_NCLBUTTONDBLCLK = 0x00A3
|
160
|
+
WM_NCRBUTTONDOWN = 0x00A4
|
161
|
+
WM_NCRBUTTONUP = 0x00A5
|
162
|
+
WM_NCRBUTTONDBLCLK = 0x00A6
|
163
|
+
WM_NCMBUTTONDOWN = 0x00A7
|
164
|
+
WM_NCMBUTTONUP = 0x00A8
|
165
|
+
WM_NCMBUTTONDBLCLK = 0x00A9
|
166
|
+
WM_NCXBUTTONDOWN = 0x00AB
|
167
|
+
WM_NCXBUTTONUP = 0x00AC
|
168
|
+
WM_NCXBUTTONDBLCLK = 0x00AD
|
169
|
+
|
170
|
+
## window styles ##
|
171
|
+
WS_OVERLAPPED = 0
|
172
|
+
WS_TABSTOP = 0x00010000
|
173
|
+
WS_GROUP = 0x00020000
|
174
|
+
WS_THICKFRAME = 0x00040000
|
175
|
+
WS_SYSMENU = 0x00080000
|
176
|
+
WS_HSCROLL = 0x00100000
|
177
|
+
WS_VSCROLL = 0x00200000
|
178
|
+
WS_DLGFRAME = 0x00400000
|
179
|
+
WS_BORDER = 0x00800000
|
180
|
+
WS_CAPTION = 0x00c00000
|
181
|
+
WS_MAXIMIZE = 0x01000000
|
182
|
+
WS_CLIPCHILDREN = 0x02000000
|
183
|
+
WS_CLIPSIBLINGS = 0x04000000
|
184
|
+
WS_DISABLED = 0x08000000
|
185
|
+
WS_VISIBLE = 0x10000000
|
186
|
+
WS_MINIMIZE = 0x20000000
|
187
|
+
WS_CHILD = 0x40000000
|
188
|
+
WS_POPUP = 0x80000000
|
189
|
+
WS_VISIBLECHILD = 0x50000000
|
190
|
+
WS_ICONIC = 0x20000000
|
191
|
+
WS_CHILDWINDOW = 0x40000000
|
192
|
+
WS_MAXIMIZEBOX = 0x00010000
|
193
|
+
WS_MINIMIZEBOX = 0x00020000
|
194
|
+
WS_OVERLAPPEDWINDOW = 0x00CF0000
|
195
|
+
WS_POPUPWINDOW = 0x80880000
|
196
|
+
WS_SIZEBOX = 0x00040000
|
197
|
+
WS_TILED = 0
|
198
|
+
WS_TILEDWINDOW = 0x00CF0000
|
199
|
+
|
200
|
+
WS_EX_TOPMOST = 0x00000008
|
201
|
+
WS_EX_TRANSPARENT = 0x00000020
|
202
|
+
WS_EX_MDICHILD = 0x00000040
|
203
|
+
WS_EX_TOOLWINDOW = 0x00000080
|
204
|
+
WS_EX_CLIENTEDGE = 0x00000200
|
205
|
+
WS_EX_CONTEXTHELP = 0x00000400
|
206
|
+
WS_EX_APPWINDOW = 0x00040000
|
207
|
+
WS_EX_LAYERED = 0x00080000
|
208
|
+
WS_EX_COMPOSITED = 0x02000000
|
209
|
+
|
210
|
+
## ShowWindow constants
|
211
|
+
SW_HIDE = 0
|
212
|
+
SW_SHOWNORMAL = 1
|
213
|
+
SW_NORMAL = 1
|
214
|
+
SW_SHOWMINIMIZED = 2
|
215
|
+
SW_SHOWMAXIMIZED = 3
|
216
|
+
SW_MAXIMIZE = 3
|
217
|
+
SW_SHOWNOACTIVATE = 4
|
218
|
+
SW_SHOW = 5
|
219
|
+
SW_MINIMIZE = 6
|
220
|
+
SW_SHOWMINNOACTIVE = 7
|
221
|
+
SW_SHOWNA = 8
|
222
|
+
SW_RESTORE = 9
|
223
|
+
SW_SHOWDEFAULT = 10
|
224
|
+
SW_FORCEMINIMIZE = 11
|
225
|
+
SW_MAX = 11
|
226
|
+
|
227
|
+
## GetWindowLong constants ##
|
228
|
+
GWL_WNDPROC = -4
|
229
|
+
GWL_HINSTANCE = -6
|
230
|
+
GWL_HWNDPARENT = -8
|
231
|
+
GWL_STYLE = -16
|
232
|
+
GWL_EXSTYLE = -20
|
233
|
+
GWL_USERDATA = -21
|
234
|
+
GWL_ID = -12
|
235
|
+
|
236
|
+
## mouse button and key states ##
|
237
|
+
MK_LBUTTON = 0x0001 # uses splitter.rb
|
238
|
+
MK_RBUTTON = 0x0002
|
239
|
+
MK_SHIFT = 0x0004
|
240
|
+
MK_CONTROL = 0x0008
|
241
|
+
MK_MBUTTON = 0x0010
|
242
|
+
MK_XBUTTON1 = 0x0020
|
243
|
+
MK_XBUTTON2 = 0x0040
|
244
|
+
|
245
|
+
## logfont size ##
|
246
|
+
LF_FACESIZE = 32 # uses richedit.rb
|
247
|
+
|
248
|
+
## icon sizes ##
|
249
|
+
ICON_SMALL = 0
|
250
|
+
ICON_BIG = 1
|
251
|
+
ICON_SMALL2 = 2
|
252
|
+
|
253
|
+
## use default window size and position ##
|
254
|
+
CW_USEDEFAULT = 0x80000000 - 0x100000000
|
255
|
+
|
256
|
+
## desktop window ##
|
257
|
+
HWND_DESKTOP = 0
|
258
|
+
|
259
|
+
## pre defined structures ##
|
260
|
+
TCHAR = API::TCHAR
|
261
|
+
CHAR = API::CHAR
|
262
|
+
WORD = API::WORD
|
263
|
+
POINT = API::POINT
|
264
|
+
RECT = API::RECT
|
265
|
+
|
266
|
+
## ownerdraw constants ##
|
267
|
+
ODT_MENU = 1
|
268
|
+
ODT_LISTBOX = 2
|
269
|
+
ODT_COMBOBOX = 3
|
270
|
+
ODT_BUTTON = 4
|
271
|
+
ODT_STATIC = 5
|
272
|
+
|
273
|
+
ODA_DRAWENTIRE = 0x0001
|
274
|
+
ODA_SELECT = 0x0002
|
275
|
+
ODA_FOCUS = 0x0004
|
276
|
+
|
277
|
+
ODS_SELECTED = 0x0001
|
278
|
+
ODS_GRAYED = 0x0002
|
279
|
+
ODS_DISABLED = 0x0004
|
280
|
+
ODS_CHECKED = 0x0008
|
281
|
+
ODS_FOCUS = 0x0010
|
282
|
+
ODS_DEFAULT = 0x0020
|
283
|
+
ODS_COMBOBOXEDIT = 0x1000
|
284
|
+
ODS_HOTLIGHT = 0x0040
|
285
|
+
ODS_INACTIVE = 0x0080
|
286
|
+
ODS_NOACCEL = 0x0100
|
287
|
+
ODS_NOFOCUSRECT = 0x0200
|
288
|
+
|
289
|
+
# code pages
|
290
|
+
CP_ACP = 0
|
291
|
+
CP_OEMCP = 1
|
292
|
+
CP_MACCP = 2
|
293
|
+
CP_THREAD_ACP = 3
|
294
|
+
CP_SYMBOL = 42
|
295
|
+
CP_UNICODE = 1200 # not defined in winnls.h but uses richedit.rb
|
296
|
+
CP_UTF7 = 65000
|
297
|
+
CP_UTF8 = 65001
|
298
|
+
|
299
|
+
# global memory
|
300
|
+
GMEM_FIXED = 0x0
|
301
|
+
GMEM_MOVEABLE = 0x2
|
302
|
+
GMEM_ZEROINIT = 0x40
|
303
|
+
GHND = (GMEM_MOVEABLE | GMEM_ZEROINIT)
|
304
|
+
GPTR = (GMEM_FIXED | GMEM_ZEROINIT)
|
305
|
+
|
306
|
+
HWND_TOP = 0
|
307
|
+
HWND_BOTTOM = 1
|
308
|
+
HWND_TOPMOST = -1
|
309
|
+
HWND_NOTOPMOST = -2
|
310
|
+
|
311
|
+
WA_INACTVE = 0
|
312
|
+
WA_ACTVE = 1
|
313
|
+
WA_CLICKACTIVE = 2
|
314
|
+
|
315
|
+
DRAWITEMSTRUCT = API.defstruct "
|
316
|
+
INT ctlType;
|
317
|
+
INT ctlID;
|
318
|
+
INT itemID;
|
319
|
+
INT itemAction;
|
320
|
+
INT itemState;
|
321
|
+
HWND hwndItem;
|
322
|
+
HDC hDC;
|
323
|
+
RECT rcItem;
|
324
|
+
INT itemData;"
|
325
|
+
|
326
|
+
MEASUREITEMSTRUCT = API.defstruct "
|
327
|
+
INT ctlType;
|
328
|
+
INT ctlID;
|
329
|
+
INT itemID;
|
330
|
+
INT itemWidth;
|
331
|
+
INT itemHeight;
|
332
|
+
INT itemData;"
|
333
|
+
|
334
|
+
SYSTEMTIME = API.defstruct "
|
335
|
+
WORD wYear;
|
336
|
+
WORD wMonth;
|
337
|
+
WORD wDayOfWeek;
|
338
|
+
WORD wDay;
|
339
|
+
WORD wHour;
|
340
|
+
WORD wMinute;
|
341
|
+
WORD wSecond;
|
342
|
+
WORD wMilliseconds;"
|
343
|
+
|
344
|
+
NMHDR = API.defstruct "
|
345
|
+
HWND hwndFrom;
|
346
|
+
ULONG_PTR idFrom;
|
347
|
+
ULONG code;"
|
348
|
+
|
349
|
+
WINDOWPOS = API.defstruct "
|
350
|
+
HWND hwnd;
|
351
|
+
HWND hwndInsertAfter;
|
352
|
+
int x;
|
353
|
+
int y;
|
354
|
+
int cx;
|
355
|
+
int cy;
|
356
|
+
UINT flags;"
|
357
|
+
|
358
|
+
end
|
359
|
+
|
360
|
+
##### Utility functions #####
|
361
|
+
module RC
|
362
|
+
module_function
|
363
|
+
def LOWORD(i)
|
364
|
+
i & 0xffff
|
365
|
+
end
|
366
|
+
def HIWORD(i)
|
367
|
+
(i>>16) & 0xffff
|
368
|
+
end
|
369
|
+
def SPLITPARAM(i)
|
370
|
+
[LOWORD(i), HIWORD(i)]
|
371
|
+
end
|
372
|
+
def MAKELPARAM(lo, hi)
|
373
|
+
((hi & 0xffff) << 16) | (lo & 0xffff)
|
374
|
+
end
|
375
|
+
def RGB(r, g, b)
|
376
|
+
(b << 16) + (g << 8) + r
|
377
|
+
end
|
378
|
+
def _T(s)
|
379
|
+
API.encode_output(s)
|
380
|
+
end
|
381
|
+
def _X(s)
|
382
|
+
API.encode_default(s)
|
383
|
+
end
|
384
|
+
def _I(s)
|
385
|
+
API.encode_internal(s)
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
##### Base classes #####
|
390
|
+
module ModAccessor
|
391
|
+
module ModArrayAccess
|
392
|
+
def index(obj)
|
393
|
+
if obj.is_a?(Integer) && !block_given?
|
394
|
+
self.each_with_index{|val, i| return i if (val.idcmd rescue nil)==obj}
|
395
|
+
nil
|
396
|
+
else
|
397
|
+
super
|
398
|
+
end
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
attr_reader :_accessors
|
403
|
+
def _check_name(name)
|
404
|
+
raise NameError, "Name must be Symbol (but got #{name.class})." unless name.is_a? Symbol
|
405
|
+
str = name.to_s
|
406
|
+
if !(str =~ /^[a-z][a-zA-Z0-9_]*$/)
|
407
|
+
raise NameError ,"`#{str}' is not allowed for name of accessor.", caller(2)
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
def _define_access_method(name, obj)
|
412
|
+
instance_eval "def #{name}() @_accessors[:#{name}]; end"
|
413
|
+
@parent.instance_eval "def _#{name}() controls.#{name}; end"
|
414
|
+
end
|
415
|
+
|
416
|
+
def _add_accessor(obj, name) #dpp self, obj, name#, caller[0, 2]
|
417
|
+
@_accessors ||= {}
|
418
|
+
raise "Need name for accessor" unless name
|
419
|
+
_check_name(name)
|
420
|
+
if obj1=@_accessors[name]
|
421
|
+
@_accessors[name] = [obj1].extend(ModArrayAccess) unless obj1.is_a? Array
|
422
|
+
@_accessors[name] << obj
|
423
|
+
else
|
424
|
+
@_accessors[name] = obj
|
425
|
+
_define_access_method(name, obj)
|
426
|
+
end
|
427
|
+
obj
|
428
|
+
end
|
429
|
+
|
430
|
+
def _delete_accessor(name, idx=nil)
|
431
|
+
if (obj1=@_accessors[name]).is_a?(Array) && obj1.size>1
|
432
|
+
raise ArgumentError, "Need index" unless idx
|
433
|
+
if idx.is_a?(Integer) && idx <= ModParent::ItemBaseID
|
434
|
+
obj1.delete_at(idx)
|
435
|
+
else
|
436
|
+
obj1.delete(idx)
|
437
|
+
end
|
438
|
+
@_accessors[name] = obj1[0] if obj1.size == 1
|
439
|
+
else
|
440
|
+
@_accessors.delete(name)
|
441
|
+
instance_eval "undef #{name} if defined?(#{name})"
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
def _delete_accessor_by_obj(obj)
|
446
|
+
@_accessors.each{|k, v|
|
447
|
+
if v.is_a?(Array)
|
448
|
+
if r=v.delete(obj)
|
449
|
+
@_accessors[k] = v[0] if v.size==1
|
450
|
+
break
|
451
|
+
else
|
452
|
+
next
|
453
|
+
end
|
454
|
+
elsif v==obj
|
455
|
+
@_accessors.delete_if{|k, v| v==obj}
|
456
|
+
instance_eval "undef #{k} if defined?(#{k})"
|
457
|
+
break
|
458
|
+
end
|
459
|
+
}
|
460
|
+
end
|
461
|
+
end # ModAccessor
|
462
|
+
|
463
|
+
class Collection < Array
|
464
|
+
undef +, -, *, &, |, assoc, at, clone, concat, push, shift, slice
|
465
|
+
alias _dup dup
|
466
|
+
alias _clear clear
|
467
|
+
alias _each each
|
468
|
+
alias _equal? equal?
|
469
|
+
alias _index index
|
470
|
+
alias _map map
|
471
|
+
alias _delete delete
|
472
|
+
alias _delete_at delete_at
|
473
|
+
alias _pop pop
|
474
|
+
alias _size size
|
475
|
+
end
|
476
|
+
|
477
|
+
class Controls < Collection
|
478
|
+
attr_reader :parent, :receiver
|
479
|
+
include ModAccessor
|
480
|
+
|
481
|
+
def initialize(parent, receiver=parent, sendto=nil) #; dpp self, parent, receiver, caller
|
482
|
+
raise "parent must be RWin::Window" if parent && !parent.is_a?(RWin::Window) &&
|
483
|
+
!parent.is_a?(RWin::Dialog)
|
484
|
+
@parent = parent
|
485
|
+
@receiver = receiver
|
486
|
+
@sendto = sendto
|
487
|
+
end
|
488
|
+
|
489
|
+
def <<(*args)
|
490
|
+
args = args[0] if args[0].is_a?(Array)
|
491
|
+
if args[0].respond_to?(:create)
|
492
|
+
ret = args[0]
|
493
|
+
ret.parent ||= @parent
|
494
|
+
elsif args[0].is_a?(Class)
|
495
|
+
klass = args.shift
|
496
|
+
ret = klass.new(@parent, *args)
|
497
|
+
elsif args[0].is_a?(Controls)
|
498
|
+
ret = args[0]
|
499
|
+
else
|
500
|
+
ret = args[0]
|
501
|
+
end
|
502
|
+
|
503
|
+
if @parent && @parent.controls.equal?(self) # is root?
|
504
|
+
_add_accessor(ret, ret.name)
|
505
|
+
# super(ret)
|
506
|
+
end
|
507
|
+
|
508
|
+
ret.idcmd = @receiver.new_control_id if ret.respond_to?(:idcmd=) && !ret.idcmd
|
509
|
+
ret.class::DefaultEvents.each{|i|
|
510
|
+
msg, submsg, template, klass = ret.acceptable_events[i]
|
511
|
+
handlername = "#{ret.name}_#{i.to_s}"
|
512
|
+
@receiver.set_msgtranslator(msg) unless @receiver.get_msgtranslator(msg)
|
513
|
+
@receiver.register_event(ret.idcmd, msg, submsg, handlername, template, klass, @sendto)
|
514
|
+
} if defined? ret.class::DefaultEvents
|
515
|
+
|
516
|
+
if ret.respond_to?(:create) && @parent.alive?
|
517
|
+
ret.create
|
518
|
+
if f=parent.inheritfont && ret.is_a?(RWin::Window)
|
519
|
+
if (hf=ret.SendMessage(RC::WM_GETFONT, 0, 0))==0 || hf==Font::SystemFontHandle
|
520
|
+
ret.font = @parent.SendMessage(RC::WM_GETFONT, 0, 0)
|
521
|
+
elsif f==:force
|
522
|
+
ret.font = @parent.SendMessage(RC::WM_GETFONT, 0, 0)
|
523
|
+
end
|
524
|
+
end
|
525
|
+
end
|
526
|
+
super(ret)
|
527
|
+
ret
|
528
|
+
end
|
529
|
+
|
530
|
+
def [](arg)
|
531
|
+
if arg.is_a?(Integer)
|
532
|
+
arg > ModParent::ItemBaseID ? self.find{|i| i.idcmd == arg} : super(arg)
|
533
|
+
elsif arg.is_a?(String) || arg.is_a?(Symbol)
|
534
|
+
sym = arg.intern
|
535
|
+
self.find{|i| i.name == sym}
|
536
|
+
elsif arg.is_a?(WinControl)
|
537
|
+
self._index(arg)
|
538
|
+
else
|
539
|
+
raise "Type #{arg.class} is not allowed"
|
540
|
+
end
|
541
|
+
end
|
542
|
+
|
543
|
+
def _delete(ctl)
|
544
|
+
if @_accessors && (ar=@_accessors[ctl.name]).is_a?(Array)
|
545
|
+
ar.delete(ctl)
|
546
|
+
@_accessors[ctl.name] = ar[0] if ar.size == 1
|
547
|
+
else
|
548
|
+
self._delete_accessor(ctl.name)
|
549
|
+
if @parent && ctl.respond_to?(:idcmd)
|
550
|
+
@parent.registered_messages.each{|msg| @parent.unregister_event(ctl.idcmd, msg)}
|
551
|
+
end
|
552
|
+
end
|
553
|
+
if ctl.respond_to?(:alive?) && ctl.alive?
|
554
|
+
if ctl.respond_to?(:close)
|
555
|
+
ctl.close
|
556
|
+
elsif ctl.respond_to?(:destroy) # for Menu
|
557
|
+
ctl.destroy
|
558
|
+
end
|
559
|
+
end
|
560
|
+
super
|
561
|
+
end
|
562
|
+
alias delete _delete
|
563
|
+
|
564
|
+
def _show()
|
565
|
+
self._each{|i| i.visible = true}
|
566
|
+
end
|
567
|
+
|
568
|
+
def _hide()
|
569
|
+
self._each{|i| i.visible = false}
|
570
|
+
end
|
571
|
+
|
572
|
+
def _create()
|
573
|
+
self._each{|i|
|
574
|
+
if i.is_a?(WinControl) && !i.alive? #; dp "@i=%p, parent=%p", i, i.parent
|
575
|
+
i.create
|
576
|
+
elsif i.is_a?(Controls)
|
577
|
+
i._create
|
578
|
+
elsif !i.is_a?(RWin::Window) && i.respond_to?(:create)
|
579
|
+
i.create
|
580
|
+
end
|
581
|
+
}
|
582
|
+
end
|
583
|
+
|
584
|
+
def __move(x, y, w, h)
|
585
|
+
self._each{|i| i.__move(x, y, w, h) if respond_to?(:__move)}
|
586
|
+
end
|
587
|
+
end # Controls
|
588
|
+
|
589
|
+
class Margin
|
590
|
+
attr_accessor :x, :y, :w, :h
|
591
|
+
attr_reader :target, :left, :top, :right, :bottom
|
592
|
+
|
593
|
+
def self.[](*args)
|
594
|
+
self.new(*args)
|
595
|
+
end
|
596
|
+
|
597
|
+
def initialize(*args)
|
598
|
+
raise ArgumentError, "No arguments" if args.empty?
|
599
|
+
self.target = args.shift if args[0].is_a? RWin::Window
|
600
|
+
@left, @top, @right, @bottom = args
|
601
|
+
end
|
602
|
+
|
603
|
+
def target=(target)
|
604
|
+
@target = target
|
605
|
+
@x, @y = target.clientpos
|
606
|
+
@w, @h = target.windowsize
|
607
|
+
end
|
608
|
+
|
609
|
+
def move(x, y, w, h) #; dpp x, y, w, h
|
610
|
+
@x, @y, @w, @h = x, y, w, h
|
611
|
+
end
|
612
|
+
|
613
|
+
def to_s()
|
614
|
+
[@left, @top, @right, @bottom].to_s
|
615
|
+
end
|
616
|
+
|
617
|
+
def set(l, t, r, b)
|
618
|
+
@left, @top, @right, @bottom = l, t, r, b
|
619
|
+
@target.__move(0,0,*target.parent.clientsize) if @target.parent
|
620
|
+
end
|
621
|
+
|
622
|
+
def left=(l)
|
623
|
+
@left = l
|
624
|
+
@target.__move(0,0,*target.parent.clientsize) if @target.parent
|
625
|
+
end
|
626
|
+
|
627
|
+
def top=(t)
|
628
|
+
@top = t
|
629
|
+
@target.__move(0,0,*target.parent.clientsize) if @target.parent
|
630
|
+
end
|
631
|
+
|
632
|
+
def right=(r)
|
633
|
+
@right = r
|
634
|
+
@target.__move(0,0,*target.parent.clientsize) if @target.parent
|
635
|
+
end
|
636
|
+
|
637
|
+
def bottom=(b) #; dpp @x, @y, @w, @h
|
638
|
+
@bottom = b
|
639
|
+
@target.__move(0,0,*target.parent.clientsize) if @target.parent
|
640
|
+
end
|
641
|
+
|
642
|
+
def to_a()
|
643
|
+
[@left, @top, @right, @bottom]
|
644
|
+
end
|
645
|
+
|
646
|
+
def origin()
|
647
|
+
[@x, @y, @w, @h]
|
648
|
+
end
|
649
|
+
|
650
|
+
alias l left
|
651
|
+
alias t top
|
652
|
+
alias r right
|
653
|
+
alias b bottom
|
654
|
+
end # Margin
|
655
|
+
|
656
|
+
##### Fonts #####
|
657
|
+
class Font < RWin::Font
|
658
|
+
include RC
|
659
|
+
def self.[](*args) self.new(*args); end
|
660
|
+
|
661
|
+
SystemFontHandle = API.GetStockObject(13) # SYSTEM_FONT
|
662
|
+
|
663
|
+
def initialize(*args)
|
664
|
+
if (str=args[2]).is_a?(String) || str.is_a?(Symbol)
|
665
|
+
b, i, u, s = nil
|
666
|
+
b = str.index('b') ? 700 : nil
|
667
|
+
i = !str.index('i').nil?
|
668
|
+
u = !str.index('u').nil?
|
669
|
+
s = !str.index('s').nil?
|
670
|
+
super(args[0], args[1], b, i, u, s)
|
671
|
+
else
|
672
|
+
super
|
673
|
+
end
|
674
|
+
end
|
675
|
+
|
676
|
+
def inspect()
|
677
|
+
sprintf("<%p:%#x %s, %d, %#x>", self.class, __id__, facename, height, _hfont)
|
678
|
+
end
|
679
|
+
|
680
|
+
def to_a()
|
681
|
+
attrstr.empty? ? [facename, height] : [facename, height, attrstr]
|
682
|
+
end
|
683
|
+
|
684
|
+
def weight()
|
685
|
+
logfont.lfWeight
|
686
|
+
end
|
687
|
+
def italic()
|
688
|
+
logfont.lfItalic==1 ? true : nil
|
689
|
+
end
|
690
|
+
def underline()
|
691
|
+
logfont.lfUnderline==1 ? true : nil
|
692
|
+
end
|
693
|
+
def strikeout()
|
694
|
+
logfont.lfStrikeOut==1 ? true : nil
|
695
|
+
end
|
696
|
+
|
697
|
+
def attrstr()
|
698
|
+
lf = self.logfont
|
699
|
+
atr = ""
|
700
|
+
atr << 'b' if lf.lfWeight==700
|
701
|
+
atr << 'i' if lf.lfItalic==1
|
702
|
+
atr << 'u' if lf.lfUnderline==1
|
703
|
+
atr << 's' if lf.lfStrikeOut==1
|
704
|
+
atr
|
705
|
+
end
|
706
|
+
end # Font
|
707
|
+
|
708
|
+
##### Base modules #####
|
709
|
+
module ModParent
|
710
|
+
include RC
|
711
|
+
ItemBaseID = 0xfff
|
712
|
+
|
713
|
+
def controls()
|
714
|
+
@controls ||= Controls.new(self)
|
715
|
+
end
|
716
|
+
alias _ controls
|
717
|
+
|
718
|
+
def new_control_id()
|
719
|
+
unless parent # toplevel window
|
720
|
+
@curret_id ||= ItemBaseID
|
721
|
+
@curret_id += 1
|
722
|
+
else # use toplevel window's
|
723
|
+
parent.new_control_id
|
724
|
+
end
|
725
|
+
end
|
726
|
+
|
727
|
+
def font=(arg)
|
728
|
+
if alive?
|
729
|
+
phf = SendMessage(WM_GETFONT, 0, 0)
|
730
|
+
super
|
731
|
+
hf = SendMessage(WM_GETFONT, 0, 0)
|
732
|
+
if hf!=0
|
733
|
+
controls.each{|i|
|
734
|
+
next unless i.is_a?(Window)
|
735
|
+
next unless i.alive?
|
736
|
+
if @_inheritfont==:force
|
737
|
+
i.font = hf
|
738
|
+
else
|
739
|
+
cfont = i.SendMessage(WM_GETFONT, 0, 0)
|
740
|
+
i.font = hf if cfont!=0 && cfont==phf
|
741
|
+
end
|
742
|
+
}
|
743
|
+
end
|
744
|
+
else
|
745
|
+
@_font = arg.is_a?(Array) ? Font.new(*arg) : arg
|
746
|
+
end
|
747
|
+
end
|
748
|
+
|
749
|
+
def inheritfont=(f)
|
750
|
+
if alive?
|
751
|
+
f = [f] unless f.is_a?(Array)
|
752
|
+
case f.last
|
753
|
+
when :force, true, false, nil
|
754
|
+
@_inheritfont = f.pop
|
755
|
+
@_inheritfont = nil if @_inheritfont==false
|
756
|
+
return unless @_inheritfont
|
757
|
+
end
|
758
|
+
@_inheritfont ||= true
|
759
|
+
unless f.empty?
|
760
|
+
self.font = f[0].is_a?(RWin::Font) ? f[0] : f
|
761
|
+
end
|
762
|
+
hfont = SendMessage(WM_GETFONT, 0, 0)
|
763
|
+
controls.each{|i| #; dpp i, i.font
|
764
|
+
next unless i.respond_to?(:font)
|
765
|
+
hf = i.SendMessage(WM_GETFONT, 0, 0)
|
766
|
+
if hf==0 || hf==Font::SystemFontHandle
|
767
|
+
i.font = hfont
|
768
|
+
i.inheritfont = @_inheritfont if i.respond_to?(:inheritfont)
|
769
|
+
elsif @_inheritfont==:force && hf==i.default_hfont
|
770
|
+
i.font = hfont
|
771
|
+
i.inheritfont=:force if i.respond_to?(:inheritfont)
|
772
|
+
end
|
773
|
+
} if self.font
|
774
|
+
else
|
775
|
+
@_inheritfont = f
|
776
|
+
end
|
777
|
+
end
|
778
|
+
def inheritfont(*args)
|
779
|
+
return @_inheritfont if args.empty?
|
780
|
+
self.inheritfont = *args
|
781
|
+
end
|
782
|
+
|
783
|
+
def create()
|
784
|
+
super
|
785
|
+
controls._create
|
786
|
+
self.inheritfont = @_inheritfont if @_inheritfont
|
787
|
+
register_event(WM_SIZE, "__resize__", "xh")# SetMenu sends WM_SIZE before children created
|
788
|
+
__send__(:created) if respond_to?(:created)
|
789
|
+
self
|
790
|
+
end
|
791
|
+
|
792
|
+
def idcmd2ref(id)
|
793
|
+
APP.hwnd2ref(API.GetDlgItem(self._hwnd, id))
|
794
|
+
end
|
795
|
+
|
796
|
+
def __resize__(w, h)
|
797
|
+
@controls.each{|i| i.__move(0, 0, w, h) if i.respond_to?(:__move)}
|
798
|
+
end
|
799
|
+
end # ModParent
|
800
|
+
|
801
|
+
module ModCreateWin
|
802
|
+
attr_reader :default_hfont
|
803
|
+
def create() #; dp "@%p, style=%#x", self, @_style
|
804
|
+
@_style &= ~RC::WS_VISIBLE if @_visible==false
|
805
|
+
__create__(@_classname, @_caption.to_s, @_x, @_y, @_w, @_h, @_parent, @_idcmd, @_style,
|
806
|
+
@_exstyle.to_i)
|
807
|
+
self.accept_events *@_events if @_events
|
808
|
+
@default_hfont = SendMessage(RC::WM_GETFONT, 0, 0)
|
809
|
+
self.font = @_font if @_font
|
810
|
+
self.visible = @_visible if @_visible
|
811
|
+
self.setorder(@_zorder) if @_zorder
|
812
|
+
self.margin = @_margin if @_margin
|
813
|
+
set_subclass(@_setsubclass) if @_setsubclass
|
814
|
+
self
|
815
|
+
end
|
816
|
+
# alias _create create
|
817
|
+
end # ModCreateWin
|
818
|
+
|
819
|
+
module ModBaseWin
|
820
|
+
include RC
|
821
|
+
PreDefinedEvents = {}
|
822
|
+
|
823
|
+
def CancelDefWindowProc(arg=nil)
|
824
|
+
APP.CancelDefWindowProc(arg)
|
825
|
+
end
|
826
|
+
|
827
|
+
attr_reader :_deny_font_inherit
|
828
|
+
def inspect()
|
829
|
+
sprintf("#<%p: 0x%x @name=%p, @_idcmd=%p>", self.class, self.__id__, @name, @_idcmd)
|
830
|
+
end
|
831
|
+
|
832
|
+
def classname()
|
833
|
+
if alive?
|
834
|
+
buff = TCHAR[128]
|
835
|
+
GetClassname(_hwnd, buff, buff.size)
|
836
|
+
buff.to_s
|
837
|
+
else
|
838
|
+
@_classname
|
839
|
+
end
|
840
|
+
end
|
841
|
+
|
842
|
+
def acceptable_events()
|
843
|
+
@_acceptable_events ||= {}.update(PreDefinedEvents)
|
844
|
+
end
|
845
|
+
|
846
|
+
def accept_events(*args)
|
847
|
+
return @_events = args[0].is_a?(Array) ? args[0] : args unless alive?
|
848
|
+
target = nil
|
849
|
+
args.each{|i|
|
850
|
+
if i.is_a?(Window)
|
851
|
+
target = i
|
852
|
+
next
|
853
|
+
elsif target
|
854
|
+
target.accept_events(i)
|
855
|
+
next
|
856
|
+
end
|
857
|
+
if i.is_a?(Symbol) #; dpp acceptable_events
|
858
|
+
a = acceptable_events[nm=i]
|
859
|
+
raise "#{i} is not defined in #{self.inspect}" unless a
|
860
|
+
else
|
861
|
+
raise "#{i.inspect} is not allowed."
|
862
|
+
end
|
863
|
+
case a[0]
|
864
|
+
when WM_COMMAND, WM_NOTIFY
|
865
|
+
msg, submsg, template, klass = a
|
866
|
+
handlername = "#{self.name}_#{nm}"
|
867
|
+
parent.set_msgtranslator(msg) unless @_parent.get_msgtranslator(msg)
|
868
|
+
parent.register_event(self.idcmd, msg, submsg, handlername, template, klass)
|
869
|
+
else
|
870
|
+
msg, template, klass = a
|
871
|
+
handlername = "self_#{nm}"
|
872
|
+
register_event(msg, handlername, template, klass)
|
873
|
+
end
|
874
|
+
}
|
875
|
+
end
|
876
|
+
alias events= accept_events
|
877
|
+
|
878
|
+
def move(*args)
|
879
|
+
if alive?
|
880
|
+
super
|
881
|
+
else
|
882
|
+
case args.size
|
883
|
+
when 2, 3
|
884
|
+
@_x, @_y = args
|
885
|
+
when 4, 5
|
886
|
+
@_x, @_y, @_w, @_h = args
|
887
|
+
else
|
888
|
+
raise ArgumentError, "illegal num of args:#{args.size}"
|
889
|
+
end
|
890
|
+
end
|
891
|
+
end
|
892
|
+
|
893
|
+
def resize(w, h)
|
894
|
+
return super if alive?
|
895
|
+
@_w = w
|
896
|
+
@_h = h
|
897
|
+
end
|
898
|
+
def size=(args)
|
899
|
+
resize(*args)
|
900
|
+
end
|
901
|
+
alias windowsize= size=
|
902
|
+
|
903
|
+
def x
|
904
|
+
alive? ? super : @_x
|
905
|
+
end
|
906
|
+
def x=(_x)
|
907
|
+
alive? ? super : @_x = _x
|
908
|
+
end
|
909
|
+
|
910
|
+
def y
|
911
|
+
alive? ? super : @_y
|
912
|
+
end
|
913
|
+
def y=(_y)
|
914
|
+
alive? ? super : @_y = _y
|
915
|
+
end
|
916
|
+
|
917
|
+
def w
|
918
|
+
alive? ? super : @_w
|
919
|
+
end
|
920
|
+
def w=(_w)
|
921
|
+
alive? ? super : @_w = _w
|
922
|
+
end
|
923
|
+
|
924
|
+
def h
|
925
|
+
alive? ? super : @_h
|
926
|
+
end
|
927
|
+
def h=(_h)
|
928
|
+
alive? ? super : @_h = _h
|
929
|
+
end
|
930
|
+
|
931
|
+
def focused?()
|
932
|
+
API.GetFocus == self._hwnd
|
933
|
+
end
|
934
|
+
|
935
|
+
def active?()
|
936
|
+
API.GetActiveWindow == self._hwnd
|
937
|
+
end
|
938
|
+
|
939
|
+
def setorder(wnd)
|
940
|
+
alive? ? super : @_zorder = wnd
|
941
|
+
end
|
942
|
+
|
943
|
+
def refresh(*args)
|
944
|
+
super
|
945
|
+
end
|
946
|
+
|
947
|
+
def caption()
|
948
|
+
alive? ? super : @_caption
|
949
|
+
end
|
950
|
+
def caption=(s)
|
951
|
+
alive? ? super : @_caption = s
|
952
|
+
end
|
953
|
+
|
954
|
+
def style()
|
955
|
+
alive? ? GetWindowLong(GWL_STYLE) : @_style || self.class::DefaultWindowStyle
|
956
|
+
end
|
957
|
+
def style=(st)
|
958
|
+
alive? ? SetWindowLong(GWL_STYLE, st) : @_style = st
|
959
|
+
end
|
960
|
+
|
961
|
+
def exstyle()
|
962
|
+
alive? ? GetWindowLong(GWL_EXSTYLE) : @_exstyle || 0
|
963
|
+
end
|
964
|
+
def exstyle=(st)
|
965
|
+
alive? ? SetWindowLong(GWL_EXSTYLE, st) : @_exstyle = st
|
966
|
+
end
|
967
|
+
|
968
|
+
def _sym2style(styles, args)
|
969
|
+
args = args[0] if args[0].is_a?(Array)
|
970
|
+
st = 0
|
971
|
+
while args.last.is_a?(Symbol)
|
972
|
+
i = self.class::styles[args.pop].to_i
|
973
|
+
i < 0 ? st &= i.abs : st |= i
|
974
|
+
end
|
975
|
+
st
|
976
|
+
end
|
977
|
+
private :_sym2style
|
978
|
+
|
979
|
+
def sym2style(styles, *args)
|
980
|
+
_sym2style(self.class::WinExStyles, args)
|
981
|
+
end
|
982
|
+
|
983
|
+
def sym2exstyle(styles, *args)
|
984
|
+
_sym2style(self.class::WinExStyles, args)
|
985
|
+
end
|
986
|
+
|
987
|
+
def clientpos()
|
988
|
+
alive? ? super : [@_x, @_y]
|
989
|
+
end
|
990
|
+
def windowsize()
|
991
|
+
alive? ? super : [@_w, @_h]
|
992
|
+
end
|
993
|
+
alias size windowsize
|
994
|
+
|
995
|
+
def font()
|
996
|
+
if alive?
|
997
|
+
return @_font if @_font
|
998
|
+
hfont = SendMessage(WM_GETFONT, 0, 0)
|
999
|
+
hfont==0 ? nil : WR::Font.wraphandle(hfont)
|
1000
|
+
else
|
1001
|
+
@_font
|
1002
|
+
end
|
1003
|
+
end
|
1004
|
+
|
1005
|
+
# font=[Font, Array, Window, HFONT, :parent, nil]
|
1006
|
+
# If given nil: Use default but allow if default is SYSTEM_FONT or nil, else deny.
|
1007
|
+
def font=(arg)
|
1008
|
+
if alive?
|
1009
|
+
@_font = nil
|
1010
|
+
if arg.nil? || arg==0
|
1011
|
+
r = SendMessage(WM_SETFONT, 0, 1)
|
1012
|
+
@default_hfont = SendMessage(WM_GETFONT, 0, 0)
|
1013
|
+
return r
|
1014
|
+
elsif arg==:parent || arg==:p
|
1015
|
+
hf = parent.SendMessage(WM_GETFONT, 0, 0)
|
1016
|
+
elsif arg.is_a?(Integer)
|
1017
|
+
hf = arg
|
1018
|
+
elsif arg.is_a?(Window)
|
1019
|
+
hf = arg.SendMessage(WM_GETFONT, 0, 0)
|
1020
|
+
elsif arg.is_a?(Array)
|
1021
|
+
if !arg[0].is_a?(String) || !arg[1].is_a?(Integer)
|
1022
|
+
raise ArgumentError, "Need facename and height", caller(1)
|
1023
|
+
end
|
1024
|
+
@_font = Font.new(*arg) # keep Font object in this window
|
1025
|
+
hf = @_font._hfont
|
1026
|
+
elsif arg.is_a?(RWin::Font)
|
1027
|
+
@_font = arg # keep Font object in this window
|
1028
|
+
hf = arg._hfont
|
1029
|
+
else
|
1030
|
+
raise ArgumentError, "Unrecognized argument: #{arg.inspect}", caller(1)
|
1031
|
+
end
|
1032
|
+
SendMessage(WM_SETFONT, hf, 1) #== 0 ? nil : true
|
1033
|
+
else # dpp arg
|
1034
|
+
@_font = arg
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
def parent() #; dpp [alive?, self]
|
1039
|
+
alive? ? super : @_parent
|
1040
|
+
end
|
1041
|
+
def parent=(arg)
|
1042
|
+
alive? ? super(arg) : @_parent = arg
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
def visible()
|
1046
|
+
alive? ? super : @_visible
|
1047
|
+
end
|
1048
|
+
def visible=(state)
|
1049
|
+
alive? ? super : @_visible = state
|
1050
|
+
end
|
1051
|
+
def show()
|
1052
|
+
self.visible = true
|
1053
|
+
self
|
1054
|
+
end
|
1055
|
+
def hide()
|
1056
|
+
self.visible = false
|
1057
|
+
self
|
1058
|
+
end
|
1059
|
+
def showna()
|
1060
|
+
self.visible = SW_SHOWNA
|
1061
|
+
self
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
SubclassedHandlers = {
|
1065
|
+
:activate => [WM_ACTIVATE, 'hi'],
|
1066
|
+
:paint => [WM_PAINT, 'c'],
|
1067
|
+
:keydown => [WM_KEYDOWN, 'ih'],
|
1068
|
+
:keyup => [WM_KEYUP, 'ih'],
|
1069
|
+
:char => [WM_CHAR, 'ih'],
|
1070
|
+
:syskeydown => [WM_SYSKEYDOWN, 'ih'],
|
1071
|
+
:syskeyup => [WM_SYSKEYUP, 'ih'],
|
1072
|
+
:syschar => [WM_SYSCHAR, 'ih'],
|
1073
|
+
:mousemove => [WM_MOUSEMOVE, 'ih'],
|
1074
|
+
:move => [WM_MOVE, 'ih'],
|
1075
|
+
:resize => [WM_SIZE, 'ih'],
|
1076
|
+
:lbuttondown => [WM_LBUTTONDOWN, 'ih'],
|
1077
|
+
:lbuttonup => [WM_LBUTTONUP, 'ih'],
|
1078
|
+
:lbuttondblclk => [WM_LBUTTONDBLCLK, 'ih'],
|
1079
|
+
:rbuttondown => [WM_RBUTTONDOWN, 'ih'],
|
1080
|
+
:rbuttonup => [WM_RBUTTONUP, 'ih'],
|
1081
|
+
:rbuttondblclk => [WM_RBUTTONDBLCLK, 'ih'],
|
1082
|
+
:mbuttondown => [WM_MBUTTONDOWN, 'ih'],
|
1083
|
+
:mbuttonup => [WM_MBUTTONUP, 'ih'],
|
1084
|
+
:mbuttondblclk => [WM_MBUTTONDBLCLK, 'ih'],
|
1085
|
+
:xbuttondown => [WM_XBUTTONDOWN, 'ih'],
|
1086
|
+
:xbuttonup => [WM_XBUTTONUP, 'ih'],
|
1087
|
+
:xbuttondblclk => [WM_XBUTTONDBLCLK, 'ih'],
|
1088
|
+
:close => [WM_CLOSE, 'ih'],
|
1089
|
+
:setcursor => [WM_SETCURSOR, 'ih'],
|
1090
|
+
:contextmenu => [WM_CONTEXTMENU, 'ih']
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
end # ModBaseWin
|
1094
|
+
|
1095
|
+
module ModStdCtrl
|
1096
|
+
include RC
|
1097
|
+
def create(*args)
|
1098
|
+
super
|
1099
|
+
unless parent.controls.receiver.get_msgtranslator(WM_COMMAND)
|
1100
|
+
parent.controls.receiver.set_msgtranslator(WM_COMMAND)
|
1101
|
+
end
|
1102
|
+
end
|
1103
|
+
end # ModStdCtrl
|
1104
|
+
|
1105
|
+
module ModCommCtrl
|
1106
|
+
include RC
|
1107
|
+
def self.included(mod)
|
1108
|
+
require 'wrb/commctrlconst.rb'
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
def create(*)
|
1112
|
+
unless parent.controls.receiver.get_msgtranslator(WM_NOTIFY)
|
1113
|
+
parent.controls.receiver.set_msgtranslator(WM_NOTIFY)
|
1114
|
+
end
|
1115
|
+
super
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
protected
|
1119
|
+
def _apply_options(arg)
|
1120
|
+
if st = CCStyles[arg]
|
1121
|
+
self.style |= st
|
1122
|
+
return nil
|
1123
|
+
end
|
1124
|
+
super
|
1125
|
+
end
|
1126
|
+
end # ModStdCtrl
|
1127
|
+
|
1128
|
+
##### winodw classes #####
|
1129
|
+
|
1130
|
+
class Window < RWin::Window # The root of all windows
|
1131
|
+
# PreDefinedEvents = {}
|
1132
|
+
alias __create__ create
|
1133
|
+
include RC
|
1134
|
+
include ModAutoloading
|
1135
|
+
include ModBaseWin, ModCreateWin
|
1136
|
+
|
1137
|
+
alias size windowsize
|
1138
|
+
def size=(arg)
|
1139
|
+
raise ArgumentError, "Argument must be [w, h]" unless arg.is_a?(Array)
|
1140
|
+
resize *arg
|
1141
|
+
end
|
1142
|
+
|
1143
|
+
def position()
|
1144
|
+
[self.x, self.y]
|
1145
|
+
end
|
1146
|
+
def position=(args)
|
1147
|
+
x, y = args
|
1148
|
+
move(x, y)
|
1149
|
+
end
|
1150
|
+
end # Window
|
1151
|
+
|
1152
|
+
class WinControl < Window # The root of child windows
|
1153
|
+
undef RegisterHotKey, UnregisterHotKey
|
1154
|
+
attr_reader :name
|
1155
|
+
alias :_name :name
|
1156
|
+
|
1157
|
+
DefaultWindowStyle = WS_VISIBLECHILD
|
1158
|
+
DefaultEvents = []
|
1159
|
+
|
1160
|
+
def self.[](*args)#; dpp args
|
1161
|
+
self.new(*args)
|
1162
|
+
end
|
1163
|
+
|
1164
|
+
def initialize(*args)
|
1165
|
+
if args[0].is_a? RWin::Window
|
1166
|
+
@_parent = args.shift
|
1167
|
+
end
|
1168
|
+
raise ArgumentError, "Control name must be Symbol." unless args[0].is_a? Symbol
|
1169
|
+
@_style = DefaultWindowStyle
|
1170
|
+
@name = args.shift
|
1171
|
+
optionfuncs = args.pop if args.last.is_a?(Hash)
|
1172
|
+
@__unplocessed = []
|
1173
|
+
while args.last.is_a? Symbol
|
1174
|
+
r = _apply_options(args.pop)
|
1175
|
+
@__unplocessed << r if r
|
1176
|
+
end
|
1177
|
+
@_caption = args.shift if args[0].is_a? String
|
1178
|
+
case args.size
|
1179
|
+
when 4
|
1180
|
+
rect = args
|
1181
|
+
when 5
|
1182
|
+
obj = args.pop
|
1183
|
+
obj.is_a?(Integer) ? self.style = WS_VISIBLECHILD | obj : @__remain_arg__ = obj
|
1184
|
+
rect = args
|
1185
|
+
else
|
1186
|
+
raise ArgumentError, "Illegal num of argument"
|
1187
|
+
end
|
1188
|
+
self.move(*rect)
|
1189
|
+
optionfuncs.each{|k, v| __send__(k.to_s + '=', v)} if optionfuncs
|
1190
|
+
end
|
1191
|
+
|
1192
|
+
def idcmd()
|
1193
|
+
alive? ? super : @_idcmd;
|
1194
|
+
end
|
1195
|
+
def idcmd=(id)
|
1196
|
+
alive? ? super : @_idcmd = id
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
def enabled()
|
1200
|
+
(self.style & WS_ENABLED) != 0
|
1201
|
+
end
|
1202
|
+
def enabled=(f)
|
1203
|
+
f ? self.style &= ~WS_DISABLED : self.style |= WS_DISABLED
|
1204
|
+
end
|
1205
|
+
|
1206
|
+
def delete()
|
1207
|
+
parent.controls._delete(self)
|
1208
|
+
parent
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
def name=(nm)
|
1212
|
+
parent.controls._delete_accessor(name)
|
1213
|
+
parent.controls._add_accessor(self, nm.intern)
|
1214
|
+
@name = nm.intern
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
def margin()
|
1218
|
+
@_margin
|
1219
|
+
end
|
1220
|
+
def margin=(arg)
|
1221
|
+
if arg.is_a? Array
|
1222
|
+
@_margin = Margin.new(self) unless @_margin
|
1223
|
+
@_margin.set(*arg)
|
1224
|
+
elsif arg.is_a?(Margin)
|
1225
|
+
@_margin = Margin.new(self) unless @_margin
|
1226
|
+
@_margin.set(arg.left, arg.top, arg.right, arg.bottom)
|
1227
|
+
elsif arg.nil?
|
1228
|
+
return unless @_margin
|
1229
|
+
self.move(@_margin.x, @_margin.y, @_margin.w, @_margin.h)
|
1230
|
+
@_margin = nil
|
1231
|
+
else
|
1232
|
+
raise ArgumentError, "argument: #{arg.inspect} is not allowed", caller(1)
|
1233
|
+
end
|
1234
|
+
parent.SendMessage(WM_SIZE, 0, MAKELPARAM(*parent.clientsize)) if alive?
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
def get_toplevel_win()
|
1238
|
+
parent.get_toplevel_win
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
def __move(x, y, w, h)
|
1242
|
+
return if !@_margin || !@_margin.target
|
1243
|
+
l, t, r, b = @_margin.left, @_margin.top, @_margin.right, @_margin.bottom
|
1244
|
+
_x = l ? x+l : (r ? x+w-r-@_margin.w : @_margin.x)
|
1245
|
+
_y = t ? y+t : (b ? y+h-b-@_margin.h : @_margin.y);
|
1246
|
+
_w = (r && l) ? (w - l - r) : @_margin.w
|
1247
|
+
_h = (b && t) ? (h - t - b) : @_margin.h
|
1248
|
+
self.move(_x, _y, _w, _h)
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
def set_subclass(f=true)
|
1252
|
+
raise "argument must be `true' or `false'" if f!=true && f!=false
|
1253
|
+
if alive?
|
1254
|
+
@_setsubclass = f
|
1255
|
+
if f
|
1256
|
+
PreDefinedEvents.update(SubclassedHandlers)
|
1257
|
+
SetWindowSubclass()
|
1258
|
+
else
|
1259
|
+
PreDefinedEvents.reject!{|k, v| SubclassedHandlers[k]}
|
1260
|
+
RemoveWindowSubclass()
|
1261
|
+
end
|
1262
|
+
else
|
1263
|
+
@_setsubclass = f
|
1264
|
+
end
|
1265
|
+
self
|
1266
|
+
end
|
1267
|
+
|
1268
|
+
def is_subclassing()
|
1269
|
+
@_setsubclass ? true : false
|
1270
|
+
end
|
1271
|
+
|
1272
|
+
WinStyles = {
|
1273
|
+
:tabstop => WS_TABSTOP,
|
1274
|
+
:group => WS_GROUP,
|
1275
|
+
:disabled => WS_DISABLED,
|
1276
|
+
:hscroll => WS_HSCROLL,
|
1277
|
+
:vscroll => WS_VSCROLL,
|
1278
|
+
:border => WS_BORDER
|
1279
|
+
}
|
1280
|
+
|
1281
|
+
protected
|
1282
|
+
def _apply_options(arg)
|
1283
|
+
if arg == :parentfont
|
1284
|
+
@parentfont = true
|
1285
|
+
return nil
|
1286
|
+
end
|
1287
|
+
if st=WinStyles[arg]
|
1288
|
+
self.style |= st
|
1289
|
+
return nil
|
1290
|
+
end
|
1291
|
+
arg
|
1292
|
+
end
|
1293
|
+
end # WinControl
|
1294
|
+
end
|