Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 7803e66

Browse files
authored
Merge pull request #4804 from livecodefraser/global-object-handles-8.1
[Bug 18646] Use object handles instead of global object pointers (8.1)
2 parents 40fa98c + f9b3687 commit 7803e66

File tree

156 files changed

+1382
-1083
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1382
-1083
lines changed

engine/src/aclip.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
4141
#include "platform.h"
4242
static MCPlatformSoundRef s_current_sound = nil;
4343
#elif defined _WINDOWS_DESKTOP
44-
#include "w32prefix.h"
4544
// SN-2014-06-26 [[ PlatformPlayer ]]
4645
// These 2 definitions must be accessible from exec-interface-aclip
4746
HWAVEOUT hwaveout; //handle to audio device opened
@@ -152,7 +151,7 @@ MCAudioClip::~MCAudioClip()
152151
if (MCacptr == this)
153152
{
154153
stop(True);
155-
MCacptr = NULL;
154+
MCacptr = nil;
156155
}
157156
delete[] samples; /* Allocated with new[] */
158157
delete osamples;
@@ -187,7 +186,7 @@ void MCAudioClip::timer(MCNameRef mptr, MCParameter *params)
187186
}
188187
else
189188
{
190-
MCacptr = NULL;
189+
MCacptr = nil;
191190
if (mstack != NULL)
192191
{
193192
if (mstack->getopened())

engine/src/aclip.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ enum Audio_format {
3737
#define LOOP_RATE 250
3838
#endif
3939

40-
class MCAudioClip : public MCObject
40+
typedef MCObjectProxy<MCAudioClip>::Handle MCAudioClipHandle;
41+
42+
class MCAudioClip : public MCObject, public MCMixinObjectHandle<MCAudioClip>
4143
{
4244
public:
4345

4446
enum { kObjectType = CT_AUDIO_CLIP };
47+
using MCMixinObjectHandle<MCAudioClip>::GetHandle;
4548

4649
private:
4750

engine/src/button.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void MCButton::open()
499499
default:
500500
findmenu(true);
501501
if (!MCNameIsEmpty(menuname) && menu.IsValid())
502-
menu.GetAs<MCStack>()->installaccels(getstack());
502+
menu->installaccels(getstack());
503503
break;
504504
}
505505
}
@@ -716,15 +716,15 @@ Boolean MCButton::kdown(MCStringRef p_string, KeySym key)
716716
case XK_WheelUp:
717717
case XK_WheelLeft:
718718
case XK_WheelRight:
719-
if (menu.GetAs<MCStack>() -> getcontrols() -> gettype() == CT_FIELD)
720-
if (menu.GetAs<MCStack>() -> getcontrols() -> kdown(p_string, key))
719+
if (menu->getcontrols()->gettype() == CT_FIELD)
720+
if (menu->getcontrols()->kdown(p_string, key))
721721
return True;
722722
break;
723723
case XK_space:
724724
case XK_Return:
725725
case XK_KP_Enter:
726726
closemenu(False, True);
727-
menu.GetAs<MCStack>()->menukdown(p_string, key, &t_pick, menuhistory);
727+
menu->menukdown(p_string, key, &t_pick, menuhistory);
728728

729729
// This check must be for null (not empty) because an empty pick
730730
// indicates that the function succeeded while a null pick means
@@ -755,10 +755,10 @@ Boolean MCButton::kdown(MCStringRef p_string, KeySym key)
755755
message_with_args(MCM_mouse_release, menubutton);
756756
state &= ~CS_IGNORE_MENU;
757757
if (MCmenuobjectptr == this)
758-
MCmenuobjectptr = NULL;
758+
MCmenuobjectptr = nil;
759759
return True;
760760
default:
761-
MCButton *mbptr = menu.GetAs<MCStack>()->findmnemonic(t_char);
761+
MCButton *mbptr = menu->findmnemonic(t_char);
762762
if (mbptr != NULL)
763763
{
764764
closemenu(False, True);
@@ -772,13 +772,13 @@ Boolean MCButton::kdown(MCStringRef p_string, KeySym key)
772772
else
773773
t_label = mbptr->getlabeltext();
774774

775-
menu.GetAs<MCStack>()->menukdown(p_string, key, &t_pick, menuhistory);
775+
menu->menukdown(p_string, key, &t_pick, menuhistory);
776776
Exec_stat es = handlemenupick(t_label, nil);
777777
if (es == ES_NOT_HANDLED || es == ES_PASS)
778778
message_with_args(MCM_mouse_up, menubutton);
779779
}
780780
if (MCmenuobjectptr == this)
781-
MCmenuobjectptr = NULL;
781+
MCmenuobjectptr = nil;
782782
return True;
783783
}
784784
else
@@ -860,7 +860,7 @@ Boolean MCButton::mfocus(int2 x, int2 y)
860860
if (!(menu.IsValid()))
861861
return False;
862862

863-
sptr->translatecoords(menu.GetAs<MCStack>(), tx, ty);
863+
sptr->translatecoords(menu, tx, ty);
864864
MCRectangle trect = sptr->getrect();
865865
Boolean handled = menu->mfocus(tx, ty);
866866
tx = x + trect.x;
@@ -940,7 +940,7 @@ Boolean MCButton::mfocus(int2 x, int2 y)
940940
{
941941
uint2 fheight;
942942
fheight = gettextheight();
943-
MCField *fptr = (MCField *)menu.GetAs<MCStack>()->getcontrols();
943+
MCField *fptr = (MCField *)menu->getcontrols();
944944
fptr->vscroll(my < rect.y + rect.height ? -fheight : fheight, True);
945945
fptr->resetscrollbars(True);
946946
}
@@ -1354,7 +1354,7 @@ Boolean MCButton::mup(uint2 which, bool p_release)
13541354
// MW-2008-03-27; [[ Bug 6225 ]] Make sure we send a mouseUp in this case
13551355
// by setting the menupoppedup global.
13561356
MCmenupoppedup = true;
1357-
menu.GetAs<MCStack>()->menumup(which, &t_pick, menuhistory);
1357+
menu->menumup(which, &t_pick, menuhistory);
13581358
MCmenupoppedup = false;
13591359
if (state & CS_IGNORE_MENU)
13601360
closemenu(True, True);
@@ -1416,7 +1416,7 @@ Boolean MCButton::mup(uint2 which, bool p_release)
14161416
}
14171417
state &= ~CS_IGNORE_MENU;
14181418
if (MCmenuobjectptr == this)
1419-
MCmenuobjectptr = NULL;
1419+
MCmenuobjectptr = nil;
14201420
// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
14211421
layer_redrawall();
14221422
if (!opened)
@@ -1759,12 +1759,12 @@ void MCButton::closemenu(Boolean kfocus, Boolean disarm)
17591759
menu->kunfocus();
17601760
}
17611761

1762-
MCButton *focused = (MCButton *)menu.GetAs<MCStack>()->getcurcard()->getmfocused();
1762+
MCButton *focused = (MCButton *)menu->getcurcard()->getmfocused();
17631763
if (focused != NULL && focused->gettype() == CT_BUTTON
17641764
&& focused->getmenumode() == WM_CASCADE)
17651765
focused->closemenu(kfocus, disarm);
17661766

1767-
menu.GetAs<MCStack>() -> mode_closeasmenu();
1767+
menu->mode_closeasmenu();
17681768
menu->close();
17691769
}
17701770
state &= ~(CS_SUBMENU | CS_MOUSE_UP_MENU);
@@ -1957,7 +1957,7 @@ void MCButton::activate(Boolean notify, KeySym p_key)
19571957
MCAutoStringRef t_pick;
19581958

19591959
if (menu.IsValid())
1960-
menu.GetAs<MCStack>()->findaccel(p_key, &t_pick, t_disabled);
1960+
menu->findaccel(p_key, &t_pick, t_disabled);
19611961
#ifdef _MAC_DESKTOP
19621962
else if (m_system_menu != nil)
19631963
getmacmenuitemtextfromaccelerator(m_system_menu, p_key, MCmodifierstate, &t_pick, false);
@@ -1987,7 +1987,7 @@ void MCButton::activate(Boolean notify, KeySym p_key)
19871987
// MH-2007-03-20: [[ Bug 2581 ]] If a radio button is hilited using the keyboard, others in the group are not unhilited (when radioBehavior is set).
19881988
if (parent->gettype() == CT_GROUP)
19891989
{
1990-
MCGroup *gptr = (MCGroup *)parent;
1990+
MCGroup *gptr = parent.GetAs<MCGroup>();
19911991
gptr->radio(0, this);
19921992
}
19931993
reseticon();
@@ -2705,7 +2705,7 @@ bool MCSystemPick(MCStringRef p_options, bool p_use_checkmark, uint32_t p_initia
27052705

27062706
void MCButton::openmenu(Boolean grab)
27072707
{
2708-
if (!opened || MCmousestackptr == NULL)
2708+
if (!opened || !MCmousestackptr)
27092709
return;
27102710
if (!MCNameIsEmpty(menuname) && !MCModeMakeLocalWindows())
27112711
return;
@@ -2775,7 +2775,7 @@ void MCButton::openmenu(Boolean grab)
27752775
{
27762776
state |= CS_SUBMENU | CS_ARMED;
27772777
reseticon();
2778-
if (MCmenuobjectptr == NULL)
2778+
if (!MCmenuobjectptr)
27792779
MCmenuobjectptr = this;
27802780
mymenudepth = ++menudepth;
27812781
MCStack *sptr = menumode == WM_POPUP ? MCmousestackptr : getstack();
@@ -2811,17 +2811,17 @@ void MCButton::openmenu(Boolean grab)
28112811
}
28122812
rel.x += labelwidth;
28132813
rel.width -= labelwidth;
2814-
menu.GetAs<MCStack>()->menuset(menuhistory, rect.height >> 1);
2814+
menu->menuset(menuhistory, rect.height >> 1);
28152815
}
28162816

2817-
menu.GetAs<MCStack>()->openrect(rel, (Window_mode)menumode, NULL, WP_DEFAULT, OP_NONE);
2818-
menu.GetAs<MCStack>() -> mode_openasmenu(t_did_grab ? sptr : NULL);
2817+
menu->openrect(rel, (Window_mode)menumode, NULL, WP_DEFAULT, OP_NONE);
2818+
menu->mode_openasmenu(t_did_grab ? sptr : NULL);
28192819

28202820
// MW-2014-03-11: [[ Bug 11893 ]] Make sure we don't do anything to a stack panel.
28212821
if (menumode == WM_OPTION && MCNameIsEmpty(menuname))
28222822
{
28232823
MCField *t_field = NULL;
2824-
MCObjptr *t_obj = menu.GetAs<MCStack>()->getcurcard()->getrefs();
2824+
MCObjptr *t_obj = menu->getcurcard()->getrefs();
28252825
MCObjptr *t_iter = t_obj;
28262826
do
28272827
{
@@ -2842,9 +2842,9 @@ void MCButton::openmenu(Boolean grab)
28422842
}
28432843
int2 tx = mx;
28442844
int2 ty = my;
2845-
sptr->translatecoords(menu.GetAs<MCStack>(), tx, ty);
2845+
sptr->translatecoords(menu, tx, ty);
28462846
menu->mfocus(tx, ty);
2847-
menu.GetAs<MCStack>()->resetcursor(True);
2847+
menu->resetcursor(True);
28482848
if (!(state & CS_MFOCUSED))
28492849
menu->kfocusnext(True);
28502850
// MW-2011-08-18: [[ Layers ]] Invalidate the whole object.
@@ -2863,18 +2863,18 @@ void MCButton::freemenu(Boolean force)
28632863
{
28642864
if (!MCNameIsEmpty(menuname))
28652865
{
2866-
menu.GetAs<MCStack>()->removeaccels(getstack());
2867-
menu.GetAs<MCStack>()->removeneed(this);
2866+
menu->removeaccels(getstack());
2867+
menu->removeneed(this);
28682868
menu = nil;
28692869
}
28702870
else
28712871
{
28722872
if (!MCStringIsEmpty(menustring) || force)
28732873
{
28742874
closemenu(False, True);
2875-
MCdispatcher->removepanel(menu.GetAs<MCStack>());
2875+
MCdispatcher->removepanel(menu);
28762876
MCstacks->deleteaccelerator(this, NULL);
2877-
menu.GetAs<MCStack>()->removeneed(this);
2877+
menu->removeneed(this);
28782878
menu = nil;
28792879
}
28802880
}
@@ -3892,7 +3892,7 @@ IO_stat MCButton::load(IO_handle stream, uint32_t version)
38923892

38933893
MCStack * MCButton::getmenu()
38943894
{
3895-
return menu.GetAs<MCStack>();
3895+
return menu;
38963896
}
38973897

38983898
////////////////////////////////////////////////////////////////////////////////

engine/src/button.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1818
#define BUTTON_H
1919

2020
#include "mccontrol.h"
21+
#include "stack.h"
2122

2223

2324
#define AQUA_FUDGE 8
@@ -103,11 +104,14 @@ class MCButtonMenuHandler
103104

104105
class ButtonMenuCallback;
105106

106-
class MCButton : public MCControl
107+
typedef MCObjectProxy<MCButton>::Handle MCButtonHandle;
108+
109+
class MCButton : public MCControl, public MCMixinObjectHandle<MCButton>
107110
{
108111
public:
109112

110113
enum { kObjectType = CT_BUTTON };
114+
using MCMixinObjectHandle<MCButton>::GetHandle;
111115

112116
private:
113117

@@ -118,7 +122,7 @@ class MCButton : public MCControl
118122
MCNameRef menuname;
119123
MCStringRef menustring;
120124
MCField *entry;
121-
MCObjectHandle menu;
125+
MCStackHandle menu;
122126
MCStringRef acceltext;
123127
MCArrayRef tabs;
124128
MCPlatformMenuRef m_system_menu;

engine/src/card.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ Boolean MCCard::mdown(uint2 which)
749749
MCtooltip->closetip();
750750
MCControl *cptr = NULL;
751751

752-
MCclickfield = NULL;
752+
MCclickfield = nil;
753753
mgrabbed = True;
754754
if (mfocused != NULL)
755755
{
@@ -1092,7 +1092,7 @@ void MCCard::timer(MCNameRef mptr, MCParameter *params)
10921092

10931093
bool MCCard::isdeletable(bool p_check_flag)
10941094
{
1095-
if (parent == NULL || scriptdepth != 0 ||
1095+
if (!parent || scriptdepth != 0 ||
10961096
(p_check_flag && getflag(F_C_CANT_DELETE)) ||
10971097
getstack() -> isediting())
10981098
{
@@ -1280,7 +1280,7 @@ Exec_stat MCCard::handle(Handler_type htype, MCNameRef mess, MCParameter *params
12801280
stat = ES_PASS;
12811281
}
12821282

1283-
if (parent != NULL && (stat == ES_PASS || stat == ES_NOT_HANDLED))
1283+
if (parent && (stat == ES_PASS || stat == ES_NOT_HANDLED))
12841284
{
12851285
Exec_stat oldstat = stat;
12861286
stat = parent->handle(htype, mess, params, this);
@@ -1289,7 +1289,7 @@ Exec_stat MCCard::handle(Handler_type htype, MCNameRef mess, MCParameter *params
12891289
}
12901290
}
12911291

1292-
if (stat == ES_ERROR && MCerrorptr == NULL)
1292+
if (stat == ES_ERROR && !MCerrorptr)
12931293
MCerrorptr = this;
12941294

12951295
return stat;
@@ -2819,7 +2819,7 @@ void MCCard::updateselection(MCControl *cptr, const MCRectangle &oldrect,
28192819
if (!cptr -> isselectable()
28202820
&& (!MCselectgrouped || cptr->gettype() != CT_GROUP))
28212821
return;
2822-
MCGroup *gptr = (MCGroup *)cptr;
2822+
MCGroup *gptr = MCObjectCast<MCGroup>(cptr);
28232823

28242824
// MW-2008-12-04: [[ Bug ]] Make sure we honour group-local selectGrouped for
28252825
// select-tool drags
@@ -3455,8 +3455,8 @@ Exec_stat MCCard::closecontrols(void)
34553455
// is a property of the mouseControl. Will return NULL if no mouseControl exists.
34563456
MCControl *MCCard::getmousecontrol(void)
34573457
{
3458-
if (MCmousestackptr == NULL)
3459-
return NULL;
3458+
if (!MCmousestackptr)
3459+
return nil;
34603460

34613461
MCControl *t_focused;
34623462
t_focused = MCmousestackptr -> getcard() -> getmfocused();

engine/src/card.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
1919

2020
#include "object.h"
2121

22-
class MCCard : public MCObject
22+
typedef MCObjectProxy<MCCard>::Handle MCCardHandle;
23+
24+
class MCCard : public MCObject, public MCMixinObjectHandle<MCCard>
2325
{
24-
friend class MCHccard;
2526
public:
2627

2728
enum { kObjectType = CT_CARD };
29+
using MCMixinObjectHandle<MCCard>::GetHandle;
2830

2931
protected:
3032

@@ -289,7 +291,6 @@ class MCCard : public MCObject
289291
return (MCCard *)MCDLlist::remove((MCDLlist *&)list);
290292
}
291293

292-
293294
////////// PROPERTY SUPPORT METHODS
294295

295296
void GetPropList(MCExecContext& ctxt, Properties which, uint32_t part_id, MCStringRef& r_props);

0 commit comments

Comments
 (0)