2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 package winapi_fixup_statements
;
23 use vars
qw($VERSION @ISA @EXPORT @EXPORT_OK);
28 @EXPORT_OK = qw(fixup_statements);
30 use config
qw($wine_dir);
31 use options qw($options);
32 use output qw($output);
35 use winapi_module_user qw(
36 get_message_result_kind
37 get_message_wparam_kind
38 get_message_lparam_kind
41 ########################################################################
44 sub fixup_function_call
($$) {
46 my @arguments = @
{(shift)};;
48 return "$name(" . join(", ", @arguments) . ")";
51 ########################################################################
54 sub _parse_makelong
($) {
65 my $parser = new c_parser
;
69 if($parser->parse_c_function_call(\
$_, \
$line, \
$column, \
$name, \
@arguments, \
@argument_lines, \
@argument_columns) &&
70 $name =~ /^MAKE(?:LONG|LPARAM|LRESULT|WPARAM)$/)
73 $high = $arguments[1];
74 } elsif(/^(?:\(\w+\)\s*)?0L?$/) {
78 $low = "($_) & 0xffff";
82 $low =~ s/^\s*(.*?)\s*$/$1/;
83 $high =~ s/^\s*(.*?)\s*$/$1/;
88 ########################################################################
89 # fixup_function_call_2_windowsx
91 sub fixup_user_message_2_windowsx
($$) {
93 (my $hwnd, my $msg, my $wparam, my $lparam) = @
{(shift)};
97 } elsif($msg =~ /^(?
:WM_BEGINDRAG
|WM_ENTERMENULOOP
|WM_EXITMENULOOP
|WM_HELP
|
98 WM_ISACTIVEICON
|WM_LBTRACKPOINT
|WM_NEXTMENU
)$/x
)
101 } elsif($msg =~ /^WM_(?:GET|SET)TEXT$/) {
113 $wparam =~ s/^\(WPARAM\)\s*//;
114 $lparam =~ s/^\(LPARAM\)\s*//;
117 if($msg =~ /^WM_COMMAND$/) {
118 (my $id, my $code_notify) = _parse_makelong
($wparam);
119 my $hwndctl = $lparam;
120 @arguments = ($id, $hwndctl, $code_notify);
121 } elsif($msg =~ /^WM_(?:COPY|CUT|PASTE)$/) {
123 } elsif($msg =~ /^WM_(?:CHARTO|VKEYTO)ITEM$/) {
124 (my $key, my $caret) = _parse_makelong
($wparam);
125 my $hwndctl = $lparam;
126 @arguments = ($key, $hwndctl, $caret);
127 } elsif($msg =~ /^WM_(?:COMPARE|DELETE|DRAW|MEASURE)ITEM$/) {
128 @arguments = ($lparam);
129 } elsif($msg =~ s/^WM_GETTEXT$/$&$suffix/) {
130 @arguments = ($wparam, $lparam);
131 } elsif($msg =~ /^WM_INITMENU$/) {
133 @arguments = ($hmenu);
134 } elsif($msg =~ /^WM_INITMENUPOPUP$/) {
136 (my $item, my $system_menu) = _parse_makelong
($lparam);
137 @arguments = ($hmenu, $item, $system_menu);
138 } elsif($msg =~ /^WM_MENUCHAR$/) {
139 (my $ch, my $flags) = _parse_makelong
($wparam);
141 @arguments = ($ch, $flags, $hmenu);
142 } elsif($msg =~ /^WM_MENUSELECT$/) {
143 (my $item, my $flags) = _parse_makelong
($wparam);
145 my $hmenu_popup = "NULL"; # FIXME: Is this really correct?
146 @arguments = ($hmenu, $item, $hmenu_popup, $flags);
147 } elsif($msg =~ s/^WM_(NC)?LBUTTONDBLCLK$/WM_$1LBUTTONDOWN/) {
148 my $double_click = "TRUE";
149 my $key_flags = $wparam;
150 (my $x, my $y) = _parse_makelong
($lparam);
151 @arguments = ($double_click, $x, $y, $key_flags);
152 } elsif($msg =~ /^WM_(NC)?LBUTTONDOWN$/) {
153 my $double_click = "FALSE";
154 my $key_flags = $wparam;
155 (my $x, my $y) = _parse_makelong
($lparam);
156 @arguments = ($double_click, $x, $y, $key_flags);
157 } elsif($msg =~ /^WM_LBUTTONUP$/) {
158 my $key_flags = $wparam;
159 (my $x, my $y) = _parse_makelong
($lparam);
160 @arguments = ($x, $y, $key_flags);
161 } elsif($msg =~ /^WM_SETCURSOR$/) {
162 my $hwnd_cursor = $wparam;
163 (my $code_hit_test, my $msg2) = _parse_makelong
($lparam);
164 @arguments = ($hwnd_cursor, $code_hit_test, $msg2);
165 } elsif($msg =~ s/^WM_SETTEXT$/$&$suffix/) {
167 @arguments = ($text);
168 } elsif($msg =~ /^WM_(?:SYS)?KEYDOWN$/) {
170 (my $repeat, my $flags) = _parse_makelong
($lparam);
171 @arguments = ($vk, $repeat, $flags);
173 @arguments = ($wparam, $lparam);
175 unshift @arguments, $hwnd;
177 return "FORWARD_" . $msg . "(" . join(", ", @arguments) . ", $name)";
180 ########################################################################
183 sub _get_messages
($) {
186 if(/^(?:BM|CB|EM|LB|STM|WM)_\w+(.*?)$/) {
192 } elsif(/^(.*?)\s*\?\s*((?:BM|CB|EM|LB|STM|WM)_\w+)\s*:\s*((?:BM|CB|EM|LB|STM|WM)_\w+)$/) {
196 } elsif(/^RegisterWindowMessage[AW]\s*\(.*?\)$/) {
199 $output->write("warning: _get_messages: '$_'\n");
204 ########################################################################
205 # _fixup_user_message
207 sub _fixup_user_message
($$) {
209 (my $hwnd, my $msg, my $wparam, my $lparam) = @
{(shift)};
215 foreach my $msg (_get_messages
($msg)) {
216 my $new_wkind = get_message_wparam_kind
($msg);
217 if(defined($wkind) && $new_wkind ne $wkind) {
218 $output->write("messsages used together do not have the same type\n");
223 my $new_lkind = get_message_lparam_kind
($msg);
224 if(defined($lkind) && $new_lkind ne $lkind) {
225 $output->write("messsages used together do not have the same type\n");
232 [ \
$wparam, $wkind, "W", "w" ],
233 [ \
$lparam, $lkind, "L", "l" ]
235 foreach my $entry (@entries) {
236 (my $refparam, my $kind, my $upper, my $lower) = @
$entry;
238 if(!defined($kind)) {
240 $output->write("messsage $msg not properly defined\n");
244 } elsif($kind eq "ptr") {
245 if($$refparam =~ /^(\(${upper}PARAM\))?\s*($lower[pP]aram)$/) {
250 } elsif($$refparam =~ /^(\(${upper}PARAM\))?\s*0$/) {
251 $$refparam = "(${upper}PARAM) NULL";
253 } elsif($$refparam !~ /^\(${upper}PARAM\)\s*/) {
254 $$refparam = "(${upper}PARAM) $$refparam";
257 } elsif($kind eq "long") {
258 if($$refparam =~ s/^\(${upper}PARAM\)\s*//) {
265 my @arguments = ($hwnd, $msg, $wparam, $lparam);
266 return "$name(" . join(", ", @arguments) . ")";
272 ########################################################################
275 sub fixup_statements
($$) {
276 my $function = shift;
279 my $file = $function->file;
280 my $linkage = $function->linkage;
281 my $name = $function->name;
282 my $statements_line = $function->statements_line;
283 my $statements_column = $function->statements_column;
284 my $statements = $function->statements;
286 if(!defined($statements)) {
290 my $parser = new c_parser
($file);
292 my $found_function_call = sub {
293 my $begin_line = shift;
294 my $begin_column = shift;
295 my $end_line = shift;
296 my $end_column = shift;
298 my $arguments = shift;
300 foreach my $argument (@
$arguments) {
301 $argument =~ s/^\s*(.*?)\s*$/$1/;
304 my $fixup_function_call;
305 if($name =~ /^(?:DefWindowProc|SendMessage)[AW]$/)
307 if($options->statements_windowsx) {
308 $fixup_function_call = \
&fixup_user_message_2_windowsx
;
310 $fixup_function_call = \
&_fixup_user_message
;
314 if(defined($fixup_function_call)) {
315 my $replace = &$fixup_function_call($name, $arguments);
317 if(defined($replace)) {
318 $editor->replace($begin_line, $begin_column, $end_line, $end_column, $replace);
320 } elsif($options->debug) {
321 $output->write("$begin_line.$begin_column-$end_line.$end_column: " .
322 "$name(" . join(", ", @
$arguments) . ")\n");
328 $parser->set_found_function_call_callback($found_function_call);
330 my $line = $statements_line;
332 if(!$parser->parse_c_statements(\
$statements, \
$line, \
$column)) {
333 $output->write("error: can't parse statements\n");