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

Commit 73d5768

Browse files
Refactor MCObjectHandle to allow MCButtonHandle, etc
Due to compiler limitations, classes like MCStackHandle won't convert to MCObjectHandle naturally: this can be done in a type-safe manner using some features in C++11 that are not available on all of our supported platforms at this time. Conflicts: engine/src/exec-interface2.cpp engine/src/object.cpp engine/src/object.h
1 parent 09d81e9 commit 73d5768

30 files changed

Lines changed: 236 additions & 122 deletions

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.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ class MCButtonMenuHandler
103103

104104
class ButtonMenuCallback;
105105

106-
class MCButton : public MCControl
106+
typedef MCObjectProxy<MCButton>::Handle MCButtonHandle;
107+
108+
class MCButton : public MCControl, public MCMixinObjectHandle<MCButton>
107109
{
108110
public:
109111

110112
enum { kObjectType = CT_BUTTON };
113+
using MCMixinObjectHandle<MCButton>::GetHandle;
111114

112115
private:
113116

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);

engine/src/cpalette.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2222

2323
#include "mccontrol.h"
2424

25-
class MCColors : public MCControl
25+
class MCColors;
26+
typedef MCObjectProxy<MCColors>::Handle MCColorsHandle;
27+
28+
class MCColors : public MCControl, public MCMixinObjectHandle<MCColors>
2629
{
2730
public:
2831

2932
enum { kObjectType = CT_COLOR_PALETTE };
33+
using MCMixinObjectHandle<MCColors>::GetHandle;
3034

3135
private:
3236

engine/src/desktop-menu.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ struct MCMainMenuInfo
535535
};
536536

537537
static MCPlatformMenuRef s_menubar = nil;
538-
static MCObjectHandle *s_menubar_targets = nil;
538+
static MCButtonHandle *s_menubar_targets = nil;
539539
static uindex_t s_menubar_target_count = 0;
540540
static uindex_t s_menubar_lock_count = 0;
541541

@@ -596,7 +596,7 @@ void MCScreenDC::updatemenubar(Boolean force)
596596
t_menu_index = 0;
597597

598598
// We construct the new menubar as we go along.
599-
MCObjectHandle *t_new_menubar_targets;
599+
MCButtonHandle *t_new_menubar_targets;
600600
uindex_t t_new_menubar_target_count;
601601
t_new_menubar_targets = nil;
602602
t_new_menubar_target_count = 0;
@@ -940,7 +940,7 @@ void MCPlatformHandleMenuUpdate(MCPlatformMenuRef p_menu)
940940
// menu button still exists!
941941
if (!t_update_menubar && s_menubar_targets[t_parent_menu_index].IsValid())
942942
{
943-
MCButton *t_button = s_menubar_targets[t_parent_menu_index].GetAs<MCButton>();
943+
MCButton *t_button = s_menubar_targets[t_parent_menu_index];
944944

945945
MCPlatformRemoveAllMenuItems(p_menu);
946946
MCstacks -> deleteaccelerator(t_button, t_button -> getstack());
@@ -994,8 +994,8 @@ void MCPlatformHandleMenuSelect(MCPlatformMenuRef p_menu, uindex_t p_item_index)
994994
{
995995
if (s_menubar_targets[t_current_menu_index].IsValid())
996996
{
997-
s_menubar_targets[t_current_menu_index].GetAs<MCButton>()->setmenuhistoryprop(t_last_menu_index + 1);
998-
s_menubar_targets[t_current_menu_index].GetAs<MCButton>()->handlemenupick(*t_result, nil);
997+
s_menubar_targets[t_current_menu_index]->setmenuhistoryprop(t_last_menu_index + 1);
998+
s_menubar_targets[t_current_menu_index]->handlemenupick(*t_result, nil);
999999
}
10001000
}
10011001
else

engine/src/eps.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2222

2323
#include "mccontrol.h"
2424

25-
class MCEPS : public MCControl
25+
class MCEPS;
26+
typedef MCObjectProxy<MCEPS>::Handle MCEPSHandle;
27+
28+
class MCEPS : public MCControl, public MCMixinObjectHandle<MCEPS>
2629
{
2730
public:
2831

2932
enum { kObjectType = CT_EPS };
33+
using MCMixinObjectHandle<MCEPS>::GetHandle;
3034

3135
private:
3236

engine/src/eventqueue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct MCEvent
101101
// This shouldn't really be a raw MCObjectProxy* but we can't embed
102102
// the MCObjectHandle RAII class here as it cannot be placed inside
103103
// a union.
104-
MCObjectProxy* target;
104+
MCObjectProxy<>* target;
105105
union
106106
{
107107
struct

engine/src/exec-engine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ void MCEngineExecDispatch(MCExecContext& ctxt, int p_handler_type, MCNameRef p_m
11911191
t_object = ctxt . GetObjectPtr();
11921192

11931193
// Fetch current default stack and target settings
1194-
MCObjectHandle t_old_stack(MCdefaultstackptr->GetHandle());
1194+
MCStackHandle t_old_stack(MCdefaultstackptr->GetHandle());
11951195
MCObjectPtr t_old_target;
11961196
t_old_target = MCtargetptr;
11971197

@@ -1265,7 +1265,7 @@ void MCEngineExecDispatch(MCExecContext& ctxt, int p_handler_type, MCNameRef p_m
12651265
// semantics here. i.e. If the default stack has been changed, the change sticks.
12661266
if (t_old_stack.IsValid() &&
12671267
MCdefaultstackptr == t_this_stack)
1268-
MCdefaultstackptr = t_old_stack.GetAs<MCStack>();
1268+
MCdefaultstackptr = t_old_stack;
12691269

12701270
// Reset target pointer
12711271
MCtargetptr = t_old_target;

engine/src/exec-interface.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,7 +2187,7 @@ void MCInterfaceProcessToContainer(MCExecContext& ctxt, MCObjectPtr *p_objects,
21872187
{
21882188
if (!p_cut)
21892189
{
2190-
MCObjectHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
2190+
MCStackHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
21912191
MCdefaultstackptr = static_cast<MCStack *>(p_dst . object);
21922192
MCdefaultstackptr -> stopedit();
21932193

@@ -2197,7 +2197,7 @@ void MCInterfaceProcessToContainer(MCExecContext& ctxt, MCObjectPtr *p_objects,
21972197
t_new_object = t_card -> clone(True, True);
21982198

21992199
if (t_old_defaultstack.IsValid())
2200-
MCdefaultstackptr = t_old_defaultstack.GetAs<MCStack>();
2200+
MCdefaultstackptr = t_old_defaultstack;
22012201

22022202
}
22032203
}
@@ -2966,7 +2966,7 @@ void MCInterfaceExecSubwindow(MCExecContext& ctxt, MCStack *p_target, MCStack *p
29662966

29672967
// MW-2007-05-01: Reverting this as it causes problems :o(
29682968
//stackptr -> setflag(True, F_VISIBLE);
2969-
MCObjectHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
2969+
MCStackHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
29702970
Boolean oldtrace = MCtrace;
29712971
MCtrace = False;
29722972
if (p_mode >= WM_MODELESS)
@@ -2995,7 +2995,7 @@ void MCInterfaceExecSubwindow(MCExecContext& ctxt, MCStack *p_target, MCStack *p
29952995
MCtrace = oldtrace;
29962996

29972997
if (p_mode > WM_TOP_LEVEL && t_old_defaultstack.IsValid())
2998-
MCdefaultstackptr = t_old_defaultstack.GetAs<MCStack>();
2998+
MCdefaultstackptr = t_old_defaultstack;
29992999
}
30003000

30013001
void MCInterfaceExecDrawerOrSheetStack(MCExecContext& ctxt, MCStack *p_target, MCNameRef p_parent_name, bool p_parent_is_thisstack, int p_at, int p_aligned, int p_mode)
@@ -3147,7 +3147,7 @@ void MCInterfaceExecPopupStackByName(MCExecContext& ctxt, MCNameRef p_name, MCPo
31473147

31483148
void MCInterfaceExecCreateStack(MCExecContext& ctxt, MCObject *p_object, MCStringRef p_new_name, bool p_force_invisible, bool p_with_group)
31493149
{
3150-
MCObjectHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
3150+
MCStackHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
31513151
Boolean wasvisible = MCtemplatestack->isvisible();
31523152

31533153
/* Check that a specified parent stack has a usable name before
@@ -3192,7 +3192,7 @@ void MCInterfaceExecCreateStack(MCExecContext& ctxt, MCObject *p_object, MCStrin
31923192
MCObject *t_object = MCdefaultstackptr;
31933193

31943194
if (t_old_defaultstack.IsValid())
3195-
MCdefaultstackptr = t_old_defaultstack.GetAs<MCStack>();
3195+
MCdefaultstackptr = t_old_defaultstack;
31963196

31973197
if (p_new_name != nil)
31983198
t_object->setstringprop(ctxt, 0, P_NAME, False, p_new_name);
@@ -3359,7 +3359,7 @@ void MCInterfaceExecCreateWidget(MCExecContext& ctxt, MCStringRef p_new_name, MC
33593359

33603360
void MCInterfaceExecClone(MCExecContext& ctxt, MCObject *p_target, MCStringRef p_new_name, bool p_force_invisible)
33613361
{
3362-
MCObjectHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
3362+
MCStackHandle t_old_defaultstack = MCdefaultstackptr->GetHandle();
33633363

33643364
MCObject *t_object = nil;
33653365
switch (p_target->gettype())
@@ -3457,7 +3457,7 @@ void MCInterfaceExecClone(MCExecContext& ctxt, MCObject *p_target, MCStringRef p
34573457
ctxt . SetItToValue(*t_id);
34583458

34593459
if (t_old_defaultstack.IsValid())
3460-
MCdefaultstackptr = t_old_defaultstack.GetAs<MCStack>();
3460+
MCdefaultstackptr = t_old_defaultstack;
34613461
}
34623462

34633463
////////////////////////////////////////////////////////////////////////////////

engine/src/exec-interface2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3773,7 +3773,7 @@ void MCInterfaceDoRelayer(MCExecContext& ctxt, int p_relation, MCObjectPtr p_sou
37733773
t_source_handle = p_source . object -> GetHandle();
37743774
t_new_owner_handle = t_new_owner -> GetHandle();
37753775
t_new_target_handle = t_new_target != nil ? t_new_target -> GetHandle() : nil;
3776-
3776+
37773777
// Make sure we remove focus from the control.
37783778
bool t_was_mfocused, t_was_kfocused;
37793779
t_was_mfocused = t_card -> getstate(CS_MFOCUSED) == True;

0 commit comments

Comments
 (0)