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

Commit 26f5953

Browse files
committed
[[ Bug 17690 ]] Add MCObject::getminimumstackfileversion method to return minimum stack file version required to fully encode object
1 parent f2eb99a commit 26f5953

File tree

8 files changed

+77
-0
lines changed

8 files changed

+77
-0
lines changed

engine/src/MCBlock.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class MCBlock : public MCDLlist
8585
// MCBlock functions
8686
void copy(MCBlock *bptr);
8787

88+
uint32_t getminimumstackfileversion(void);
89+
8890
// MW-2012-03-04: [[ StackFile5500 ]] If 'is_ext' is true then this block has
8991
// an extension style attribute section.
9092
IO_stat load(IO_handle stream, uint32_t version, bool is_ext);

engine/src/block.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ bool MCBlock::visit(MCObjectVisitorOptions p_options, uint32_t p_part, MCObjectV
145145
return p_visitor -> OnBlock(this);
146146
}
147147

148+
uint32_t MCBlock::getminimumstackfileversion(void)
149+
{
150+
return kMCStackFileFormatMinimumExportVersion;
151+
}
152+
148153
// MW-2012-03-04: [[ StackFile5500 ]] If 'is_ext' is true then the record is an extended
149154
// record.
150155
IO_stat MCBlock::load(IO_handle stream, uint32_t version, bool is_ext)

engine/src/object.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
6464
#include "stacksecurity.h"
6565
#include "stackfileformat.h"
6666

67+
#include "paragraf.h"
68+
#include "MCBlock.h"
69+
6770
#include "exec.h"
6871
#include "graphicscontext.h"
6972

@@ -5133,6 +5136,50 @@ bool MCObject::haswidgets(void)
51335136
return t_visitor . found_widget;
51345137
}
51355138

5139+
struct MCRequiredStackFileVersionVisitor : public MCObjectVisitor
5140+
{
5141+
uint32_t required_version;
5142+
5143+
bool OnObject(MCObject *p_object)
5144+
{
5145+
required_version = MCMax(required_version, p_object->getminimumstackfileversion());
5146+
5147+
// keep looking if current required version is less than the maximum
5148+
return required_version < kMCStackFileFormatCurrentVersion;
5149+
}
5150+
5151+
// make sure blocks and paragraphs are checked
5152+
bool OnParagraph(MCParagraph *p_paragraph)
5153+
{
5154+
required_version = MCMax(required_version, p_paragraph->getminimumstackfileversion());
5155+
5156+
// keep looking if current required version is less than the maximum
5157+
return required_version < kMCStackFileFormatCurrentVersion;
5158+
}
5159+
5160+
bool OnBlock(MCBlock *p_block)
5161+
{
5162+
required_version = MCMax(required_version, p_block->getminimumstackfileversion());
5163+
5164+
// keep looking if current required version is less than the maximum
5165+
return required_version < kMCStackFileFormatCurrentVersion;
5166+
}
5167+
};
5168+
5169+
uint32_t MCObject::geteffectiveminimumstackfileversion(void)
5170+
{
5171+
MCRequiredStackFileVersionVisitor t_visitor;
5172+
t_visitor.required_version = kMCStackFileFormatMinimumExportVersion;
5173+
visit(kMCObjectVisitorRecursive, 0, &t_visitor);
5174+
return t_visitor.required_version;
5175+
}
5176+
5177+
uint32_t MCObject::getminimumstackfileversion(void)
5178+
{
5179+
// Default minimum stack file version
5180+
return kMCStackFileFormatMinimumExportVersion;
5181+
}
5182+
51365183
// AL-2015-06-30: [[ Bug 15556 ]] Refactored function to sync mouse focus
51375184
void MCObject::sync_mfocus(void)
51385185
{

engine/src/object.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,14 @@ class MCObject : public MCDLlist
922922
// a widget.
923923
virtual bool haswidgets(void);
924924

925+
// IM-2016-07-06: [[ Bug 17690 ]] Return the minimum stack file version that can fully
926+
// encode this object and its properties.
927+
virtual uint32_t getminimumstackfileversion(void);
928+
929+
// IM-2016-07-06: [[ Bug 17690 ]] Returns the minimum stack file version of this object
930+
// and any child objects.
931+
uint32_t geteffectiveminimumstackfileversion(void);
932+
925933
// Currently non-functional: always returns false
926934
bool is_rtl() const { return false; }
927935

engine/src/paragraf.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ bool MCParagraph::visit(MCObjectVisitorOptions p_options, uint32_t p_part, MCObj
464464
return t_continue;
465465
}
466466

467+
uint32_t MCParagraph::getminimumstackfileversion(void)
468+
{
469+
return kMCStackFileFormatMinimumExportVersion;
470+
}
471+
467472
// **** mutate blocks
468473
IO_stat MCParagraph::load(IO_handle stream, uint32_t version, bool is_ext)
469474
{

engine/src/paragraf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class MCParagraph : public MCDLlist
279279

280280
bool visit(MCObjectVisitorOptions p_options, uint32_t p_part, MCObjectVisitor* p_visitor);
281281

282+
uint32_t getminimumstackfileversion(void);
283+
282284
// MW-2012-03-04: [[ StackFile5500 ]] If 'is_ext' is true then this paragraph
283285
// has an attribute extension.
284286
IO_stat load(IO_handle stream, uint32_t version, bool is_ext);

engine/src/widget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ Exec_stat MCWidget::handle(Handler_type p_type, MCNameRef p_method, MCParameter
753753
return MCControl::handle(p_type, p_method, p_parameters, p_passing_object);
754754
}
755755

756+
uint32_t MCWidget::getminimumstackfileversion(void)
757+
{
758+
return kMCStackFileFormatVersion_8_0;
759+
}
760+
756761
IO_stat MCWidget::load(IO_handle p_stream, uint32_t p_version)
757762
{
758763
IO_stat t_stat;

engine/src/widget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class MCWidget: public MCControl
162162

163163
virtual Exec_stat handle(Handler_type, MCNameRef, MCParameter *, MCObject *pass_from);
164164

165+
// IM-2016-07-07: [[ Bug 17690 ]] Override - widgets not available before v8.0
166+
virtual uint32_t getminimumstackfileversion(void);
167+
165168
virtual IO_stat save(IO_handle stream, uint4 p_part, bool p_force_ext, uint32_t p_version);
166169
virtual IO_stat load(IO_handle stream, uint32_t p_version);
167170

0 commit comments

Comments
 (0)