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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 ########################################################################
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*//;
119 } elsif($msg =~ /^WM_COMMAND$/) {
120 (my $id, my $code_notify) = _parse_makelong($wparam);
121 my $hwndctl = $lparam;
122 @arguments = ($id, $hwndctl, $code_notify);
123 } elsif($msg =~ /^WM_(?:COPY|CUT|PASTE)$/) {
125 } elsif($msg =~ /^WM_(?:CHARTO|VKEYTO)ITEM$/) {
126 (my $key, my $caret) = _parse_makelong($wparam);
127 my $hwndctl = $lparam;
128 @arguments = ($key, $hwndctl, $caret);
129 } elsif($msg =~ /^WM_(?:COMPARE|DELETE|DRAW|MEASURE)ITEM$/) {
130 @arguments = ($lparam);
131 } elsif($msg =~ s/^WM_GETTEXT$/$&$suffix/) {
132 @arguments = ($wparam, $lparam);
133 } elsif($msg =~ /^WM_INITMENU$/) {
135 @arguments = ($hmenu);
136 } elsif($msg =~ /^WM_INITMENUPOPUP$/) {
138 (my $item, my $system_menu) = _parse_makelong($lparam);
139 @arguments = ($hmenu, $item, $system_menu);
140 } elsif($msg =~ /^WM_MENUCHAR$/) {
141 (my $ch, my $flags) = _parse_makelong($wparam);
143 @arguments = ($ch, $flags, $hmenu);
144 } elsif($msg =~ /^WM_MENUSELECT$/) {
145 (my $item, my $flags) = _parse_makelong($wparam);
147 my $hmenu_popup = "NULL"; # FIXME: Is this really correct?
148 @arguments = ($hmenu, $item, $hmenu_popup, $flags);
149 } elsif($msg =~ s/^WM_(NC)?LBUTTONDBLCLK$/WM_$1LBUTTONDOWN/) {
150 my $double_click = "TRUE";
151 my $key_flags = $wparam;
152 (my $x, my $y) = _parse_makelong($lparam);
153 @arguments = ($double_click, $x, $y, $key_flags);
154 } elsif($msg =~ /^WM_(NC)?LBUTTONDOWN$/) {
155 my $double_click = "FALSE";
156 my $key_flags = $wparam;
157 (my $x, my $y) = _parse_makelong($lparam);
158 @arguments = ($double_click, $x, $y, $key_flags);
159 } elsif($msg =~ /^WM_LBUTTONUP$/) {
160 my $key_flags = $wparam;
161 (my $x, my $y) = _parse_makelong($lparam);
162 @arguments = ($x, $y, $key_flags);
163 } elsif($msg =~ /^WM_SETCURSOR$/) {
164 my $hwnd_cursor = $wparam;
165 (my $code_hit_test, my $msg2) = _parse_makelong($lparam);
166 @arguments = ($hwnd_cursor, $code_hit_test, $msg2);
167 } elsif($msg =~ s/^WM_SETTEXT$/$&$suffix/) {
169 @arguments = ($text);
170 } elsif($msg =~ /^WM_(?:SYS)?KEYDOWN$/) {
172 (my $repeat, my $flags) = _parse_makelong($lparam);
173 @arguments = ($vk, $repeat, $flags);
175 @arguments = ($wparam, $lparam);
177 unshift @arguments, $hwnd;
179 return "FORWARD_" . $msg . "(" . join(", ", @arguments) . ", $name)";
182 ########################################################################
188 if(/^(?:BM|CB|EM|LB|STM|WM)_\w+(.*?)$/) {
194 } elsif(/^(.*?)\s*\?\s*((?:BM|CB|EM|LB|STM|WM)_\w+)\s*:\s*((?:BM|CB|EM|LB|STM|WM)_\w+)$/) {
198 } elsif(/^RegisterWindowMessage[AW]\s*\(.*?\)$/) {
201 $output->write("warning: _get_messages: '$_'\n");
206 ########################################################################
207 # _fixup_user_message
209 sub _fixup_user_message {
211 (my $hwnd, my $msg, my $wparam, my $lparam) = @{(shift)};
217 foreach my $msg (_get_messages($msg)) {
218 my $new_wkind = &get_message_wparam_kind($msg);
219 if(defined($wkind) && $new_wkind ne $wkind) {
220 $output->write("messsages used together do not have the same type\n");
225 my $new_lkind = &get_message_lparam_kind($msg);
226 if(defined($lkind) && $new_lkind ne $lkind) {
227 $output->write("messsages used together do not have the same type\n");
234 [ \$wparam, $wkind, "W", "w" ],
235 [ \$lparam, $lkind, "L", "l" ]
237 foreach my $entry (@entries) {
238 (my $refparam, my $kind, my $upper, my $lower) = @$entry;
240 if(!defined($kind)) {
242 $output->write("messsage $msg not properly defined\n");
246 } elsif($kind eq "ptr") {
247 if($$refparam =~ /^(\(${upper}PARAM\))?\s*($lower[pP]aram)$/) {
252 } elsif($$refparam =~ /^(\(${upper}PARAM\))?\s*0$/) {
253 $$refparam = "(${upper}PARAM) NULL";
255 } elsif($$refparam !~ /^\(${upper}PARAM\)\s*/) {
256 $$refparam = "(${upper}PARAM) $$refparam";
259 } elsif($kind eq "long") {
260 if($$refparam =~ s/^\(${upper}PARAM\)\s*//) {
267 my @arguments = ($hwnd, $msg, $wparam, $lparam);
268 return "$name(" . join(", ", @arguments) . ")";
274 ########################################################################
277 sub fixup_statements {
278 my $function = shift;
281 my $file = $function->file;
282 my $linkage = $function->linkage;
283 my $name = $function->name;
284 my $statements_line = $function->statements_line;
285 my $statements_column = $function->statements_column;
286 my $statements = $function->statements;
288 if(!defined($statements)) {
292 my $parser = new c_parser($file);
294 my $found_function_call = sub {
295 my $begin_line = shift;
296 my $begin_column = shift;
297 my $end_line = shift;
298 my $end_column = shift;
300 my $arguments = shift;
302 foreach my $argument (@$arguments) {
303 $argument =~ s/^\s*(.*?)\s*$/$1/;
306 my $fixup_function_call;
307 if($name =~ /^(?:DefWindowProc|SendMessage)[AW]$/)
309 if($options->statements_windowsx) {
310 $fixup_function_call = \&fixup_user_message_2_windowsx;
312 $fixup_function_call = \&_fixup_user_message;
316 if(defined($fixup_function_call)) {
317 my $replace = &$fixup_function_call($name, $arguments);
319 if(defined($replace)) {
320 $editor->replace($begin_line, $begin_column, $end_line, $end_column, $replace);
322 } elsif($options->debug) {
323 $output->write("$begin_line.$begin_column-$end_line.$end_column: " .
324 "$name(" . join(", ", @$arguments) . ")\n");
330 $parser->set_found_function_call_callback($found_function_call);
332 my $line = $statements_line;
334 if(!$parser->parse_c_statements(\$statements, \$line, \$column)) {
335 $output->write("error: can't parse statements\n");