@@ -41,6 +41,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4141#include " globals.h"
4242#include " mode.h"
4343#include " exec.h"
44+ #include " system.h"
4445
4546// //////////////////////////////////////////////////////////////////////////////
4647
@@ -129,58 +130,61 @@ void MCB_setvalue(MCExecContext &ctxt, MCExecValue p_value, MCNameRef name)
129130
130131void MCB_setmsg (MCExecContext &ctxt, MCStringRef p_string)
131132{
132- if (!MCmessageboxredirect.IsValid ())
133- {
134- MCAutoStringRefAsCString t_output;
135- /* UNCHECKED */ t_output . Lock (p_string);
136- MCS_write (*t_output, sizeof (char ), strlen (*t_output), IO_stdout);
137- uint4 length = MCStringGetLength (p_string);
138- if (length && MCStringGetCharAtIndex (p_string, length - 1 ) != ' \n ' )
139- MCS_write (" \n " , sizeof (char ), 1 , IO_stdout);
140- return ;
141- }
142- else
143- {
144- MCObject *t_src_object = nil;
145- if (ctxt.GetObject () != nil)
146- t_src_object = ctxt.GetObject ();
147-
148- bool t_in_msg_box = false ;
149-
150- MCObject *t_obj_ptr = t_src_object;
151- while (t_obj_ptr != nil)
152- {
153- if (t_obj_ptr == MCmessageboxredirect)
154- {
155- t_in_msg_box = true ;
156- break ;
157- }
158- t_obj_ptr = t_obj_ptr->getparent ();
159- }
160-
161- if (!t_in_msg_box)
162- {
163- MCmessageboxlastobject = t_src_object->GetHandle ();
164-
165- MCNameDelete (MCmessageboxlasthandler);
166- MCmessageboxlasthandler = nil;
167- MCNameClone (ctxt.GetHandler ()->getname (), MCmessageboxlasthandler);
168-
169- MCmessageboxlastline = ctxt . GetLine ();
170- }
171-
172- bool t_added = false ;
173- if (MCnexecutioncontexts < MAX_CONTEXTS && ctxt.GetObject () != nil)
174- {
175- MCexecutioncontexts[MCnexecutioncontexts++] = &ctxt;
176- t_added = true ;
177- }
178-
179- MCmessageboxredirect -> message (MCM_msgchanged);
180-
181- if (t_added)
182- MCnexecutioncontexts--;
183- }
133+ Exec_stat t_stat = ES_NOT_HANDLED;
134+
135+ MCObject *t_target = nil;
136+ if (ctxt.GetObject () != nil)
137+ t_target = ctxt.GetObject ();
138+ else if (MCdefaultstackptr . IsValid ())
139+ t_target = MCdefaultstackptr;
140+
141+ if (t_target != nil)
142+ {
143+ MCAutoStringRef t_handler;
144+ t_handler = MCNameGetString (ctxt.GetHandler ()->getname ());
145+ MCParameter *t_handler_parameter = new (nothrow) MCParameter;
146+ t_handler_parameter -> setvalueref_argument (*t_handler);
147+
148+ MCAutoNumberRef t_line;
149+ MCParameter *t_line_parameter;
150+ if (MCNumberCreateWithUnsignedInteger (ctxt.GetLine (), &t_line))
151+ {
152+ t_line_parameter = new (nothrow) MCParameter;
153+ t_line_parameter -> setvalueref_argument (*t_line);
154+ t_handler_parameter -> setnext (t_line_parameter);
155+ }
156+
157+ bool t_added = false ;
158+ if (MCnexecutioncontexts < MAX_CONTEXTS && ctxt.GetObject () != nil)
159+ {
160+ MCexecutioncontexts[MCnexecutioncontexts++] = &ctxt;
161+ t_added = true ;
162+ }
163+
164+ t_stat = t_target -> message (MCM_msgchanged, t_handler_parameter, True, True, False);
165+
166+ if (t_added)
167+ MCnexecutioncontexts--;
168+ }
169+
170+ if (t_stat == ES_NOT_HANDLED || t_stat == ES_PASS)
171+ {
172+ if (MCnoui)
173+ {
174+ MCAutoStringRefAsCString t_output;
175+ /* UNCHECKED */ t_output . Lock (p_string);
176+ MCS_write (*t_output, sizeof (char ), strlen (*t_output), IO_stdout);
177+ uint4 length = MCStringGetLength (p_string);
178+ if (length && MCStringGetCharAtIndex (p_string, length - 1 ) != ' \n ' )
179+ MCS_write (" \n " , sizeof (char ), 1 , IO_stdout);
180+ return ;
181+ }
182+ else
183+ {
184+ MCsystem -> Debug (p_string);
185+ }
186+ }
187+
184188}
185189
186190void MCB_message (MCExecContext &ctxt, MCNameRef mess, MCParameter *p)
0 commit comments