Skip to content

Commit 56b76dc

Browse files
committed
[[ Bug 18948 ]] Make handling of 'objchunk of me' consistent for widgets
For other non-group controls that aren't behaviors, the 'me' resolves to 'this card of me' in this context.
1 parent 22b98a7 commit 56b76dc

File tree

5 files changed

+35
-53
lines changed

5 files changed

+35
-53
lines changed

docs/notes/bugfix-18948.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Make 'obj of me' consistent across all control types

engine/src/chunk.cpp

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
5555

5656
////////////////////////////////////////////////////////////////////////////////
5757

58+
static bool MCChunkTermIsNestable(Chunk_term p_chunk_term)
59+
{
60+
switch (p_chunk_term)
61+
{
62+
case CT_STACK:
63+
case CT_GROUP:
64+
case CT_LAYER:
65+
case CT_ELEMENT:
66+
return true;
67+
default:
68+
return false;
69+
}
70+
}
71+
72+
static bool MCChunkTermHasRange(Chunk_term p_chunk_term)
73+
{
74+
return p_chunk_term >= CT_LINE && p_chunk_term < CT_ELEMENT;
75+
}
76+
77+
////////////////////////////////////////////////////////////////////////////////
78+
5879
#ifdef COLLECTING_CHUNKS
5980
#include "newchunk.h"
6081
class MCSyntaxCollector
@@ -991,30 +1012,10 @@ void MCChunk::getoptionalobj(MCExecContext& ctxt, MCObjectPtr &r_object, Boolean
9911012
ctxt . LegacyThrow(EE_CHUNK_NOTARGET);
9921013
return;
9931014
}
994-
// SN-2015-01-13: [[ Bug 14376 ]] Remove this if statement added during the refactoring process
995-
// (commit 15a49a27e387f3e49e5bcce8f8316348578bf810)
996-
// which leads to a part_id of 0 instead of the card part id.
997-
// if (background == nil && card == nil && group == nil && object == nil)
998-
// {
999-
// r_object . object = t_object . object;
1000-
// r_object . part_id = t_object . part_id;
1001-
// return;
1002-
// }
1003-
switch (t_object . object -> gettype())
1004-
{
1005-
case CT_AUDIO_CLIP:
1006-
case CT_VIDEO_CLIP:
1007-
case CT_LAYER:
1008-
case CT_MENU:
1009-
case CT_BUTTON:
1010-
case CT_IMAGE:
1011-
case CT_FIELD:
1012-
case CT_GRAPHIC:
1013-
case CT_EPS:
1014-
case CT_SCROLLBAR:
1015-
case CT_PLAYER:
1016-
case CT_MAGNIFY:
1017-
case CT_COLOR_PALETTE:
1015+
1016+
Chunk_term t_type = t_object . object -> gettype();
1017+
if (MCChunkTermIsControl(t_type) && t_type != CT_GROUP)
1018+
{
10181019
MCCard *t_card;
10191020
t_card = t_object . object -> getcard(t_object . part_id);
10201021
if (t_card == nil)
@@ -1028,9 +1029,7 @@ void MCChunk::getoptionalobj(MCExecContext& ctxt, MCObjectPtr &r_object, Boolean
10281029
r_object . object = t_object . object;
10291030
r_object . part_id = t_object . part_id;
10301031
return;
1031-
default:
1032-
break;
1033-
}
1032+
}
10341033
}
10351034
else if (noobjectchunks())
10361035
{
@@ -3453,22 +3452,3 @@ MCChunkType MCChunkTypeFromChunkTerm(Chunk_term p_chunk_term)
34533452
MCUnreachableReturn(kMCChunkTypeLine);
34543453
}
34553454
}
3456-
3457-
bool MCChunkTermIsNestable(Chunk_term p_chunk_term)
3458-
{
3459-
switch (p_chunk_term)
3460-
{
3461-
case CT_STACK:
3462-
case CT_GROUP:
3463-
case CT_LAYER:
3464-
case CT_ELEMENT:
3465-
return true;
3466-
default:
3467-
return false;
3468-
}
3469-
}
3470-
3471-
bool MCChunkTermHasRange(Chunk_term p_chunk_term)
3472-
{
3473-
return p_chunk_term >= CT_LINE && p_chunk_term < CT_ELEMENT;
3474-
}

engine/src/chunk.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ class MCChunk : public MCExpression
190190
};
191191

192192
MCChunkType MCChunkTypeFromChunkTerm(Chunk_term p_chunk_term);
193-
bool MCChunkTermIsNestable(Chunk_term p_chunk_term);
194-
bool MCChunkTermHasRange(Chunk_term p_chunk_term);
195-
193+
inline bool MCChunkTermIsControl(Chunk_term p_chunk_term)
194+
{
195+
return p_chunk_term >= CT_FIRST_CONTROL && p_chunk_term <= CT_LAST_CONTROL;
196+
}
196197
#endif

engine/src/cmdsc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,8 @@ void MCMakeGroup::exec_ctxt(MCExecContext& ctxt)
17361736
for(MCChunk *t_chunk = targets; t_chunk != nil; t_chunk = t_chunk -> next)
17371737
{
17381738
MCObjectPtr t_object;
1739-
if (!t_chunk -> getobj(ctxt, t_object, True) || t_object . object -> gettype() < CT_FIRST_CONTROL || t_object . object -> gettype() > CT_LAST_CONTROL)
1739+
if (!t_chunk -> getobj(ctxt, t_object, True) ||
1740+
!MCChunkTermIsControl(t_object . object -> gettype()))
17401741
{
17411742
ctxt .Throw();
17421743
return;

engine/src/cmdse.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,8 @@ void MCFocus::exec_ctxt(MCExecContext &ctxt)
425425
{
426426
MCObject *optr;
427427
uint4 parid;
428-
if (!object->getobj(ctxt, optr, parid, True)
429-
|| optr->gettype() < CT_FIRST_CONTROL
430-
|| optr->gettype() > CT_LAST_CONTROL)
428+
if (!object->getobj(ctxt, optr, parid, True) ||
429+
!MCChunkTermIsControl(optr -> gettype()))
431430
{
432431
ctxt . LegacyThrow(EE_FOCUS_BADOBJECT);
433432
return;

0 commit comments

Comments
 (0)