Exemplo n.º 1
0
void MCPickExecPickPhotoAndResize(MCExecContext& ctxt, intenum_t p_source, uinteger_t p_width, uinteger_t p_height)
{
    if (!MCSystemCanAcquirePhoto((MCPhotoSourceType)p_source))
    {
        ctxt . SetTheResultToStaticCString("source not available");
        return;
    }
    
    void *t_image_data = nil;
    size_t t_image_data_size;
    MCAutoStringRef t_result;
    if (!MCSystemAcquirePhoto((MCPhotoSourceType)p_source, p_width, p_height, t_image_data, t_image_data_size, &t_result))
    {
        ctxt . SetTheResultToStaticCString("error");
        return;
    }
    
    if (t_image_data == nil)
    {
        ctxt . SetTheResultToValue(*t_result);
        return;
    }
    
    ctxt . SetTheResultToEmpty();
    
    MCtemplateimage->setparent((MCObject *)MCdefaultstackptr -> getcurcard());
    MCImage *iptr = (MCImage *)MCtemplateimage->clone(False, OP_NONE, false);
    MCtemplateimage->setparent(NULL);
    iptr -> attach(OP_CENTER, false);
    
    MCAutoDataRef t_text;
    MCDataCreateWithBytes((const byte_t *)t_image_data, t_image_data_size, &t_text);
    iptr -> SetText(ctxt, *t_text);
}
Exemplo n.º 2
0
void MCArraysEvalArrayEncode(MCExecContext& ctxt, MCArrayRef p_array, MCStringRef p_version, MCDataRef& r_encoding)
{
	bool t_success;
	t_success = true;

	IO_handle t_stream_handle;
	t_stream_handle = nil;
	if (t_success)
	{
		t_stream_handle = MCS_fakeopenwrite();
		if (t_stream_handle == nil)
			t_success = false;
	}

    // AL-2014-05-15: [[ Bug 12203 ]] Add version parameter to arrayEncode, to allow
    //  version 7.0 variant to preserve unicode. 
    MCInterfaceStackFileVersion t_version;
    if (p_version != nil)
        MCInterfaceStackFileVersionParse(ctxt, p_version, t_version);
    
    // AL-2014-05-22: [[ Bug 12547 ]] Make arrayEncode encode in 7.0 format by default.
    bool t_legacy;
    t_legacy = p_version != nil && t_version . version < 7000;
    
    if (t_legacy)
    {
        MCObjectOutputStream *t_stream;
        t_stream = nil;
        if (t_success)
        {
            t_stream = new MCObjectOutputStream(t_stream_handle);
            if (t_stream == nil)
                t_success = false;
        }
        
        if (t_success)
        {
            if (t_stream -> WriteU8(kMCEncodedValueTypeLegacyArray) != IO_NORMAL)
                t_success = false;
        }
        
        if (t_success)
            if (MCArraySaveToStreamLegacy(p_array, false, *t_stream) != IO_NORMAL)
                t_success = false;
        
        if (t_success)
            t_stream -> Flush(true);
        
        delete t_stream;
    }
    else
    {
        if (t_success)
            if (IO_write_uint1(kMCEncodedValueTypeArray, t_stream_handle) != IO_NORMAL)
                t_success = false;
        
        if (t_success)
            if (IO_write_valueref_new(p_array, t_stream_handle) != IO_NORMAL)
                t_success = false;
    }
	
	//////////

	void *t_buffer;
	size_t t_length;
	t_buffer = nil;
	t_length = 0;
	if (MCS_closetakingbuffer(t_stream_handle, t_buffer, t_length) != IO_NORMAL)
		t_success = false;

	if (t_success)
		t_success = MCDataCreateWithBytes((const byte_t *)t_buffer, t_length, r_encoding);

	free(t_buffer);

	if (t_success)
		return;

	ctxt . Throw();
}
Exemplo n.º 3
0
void MCKeywordsExecRepeatFor(MCExecContext& ctxt, MCStatement *statements, MCExpression *endcond, MCVarref *loopvar, File_unit each, uint2 line, uint2 pos)
{
    MCAutoArrayRef t_array;
    MCAutoStringRef t_string;
    MCAutoDataRef t_data;
    MCRange t_chunk_range;
    t_chunk_range = MCRangeMake(0,0);
    uindex_t t_length = 0;
    MCAutoValueRef t_condition;
	MCNameRef t_key;
	MCValueRef t_value;
	uintptr_t t_iterator;
    // SN2015-06-15: [[ Bug 15457 ]] The index can be a negative index.
    index_t t_sequenced_iterator;
    const byte_t *t_data_ptr;
    
    MCAutoPointer<MCTextChunkIterator> tci;
    
    if (!ctxt . TryToEvaluateExpression(endcond, line, pos, EE_REPEAT_BADFORCOND, &t_condition))
        return;
    
    bool t_sequence_array;
    t_sequence_array = false;

    if (each == FU_ELEMENT || each == FU_KEY)
    {
        if (!ctxt . ConvertToArray(*t_condition, &t_array))
            return;
        
        // SN-2015-06-15: [[ Bug 15457 ]] If this is a numerical array, do
        //  it in order - even if it does not start at 1
        if (each == FU_ELEMENT && MCArrayIsNumericSequence(*t_array, t_sequenced_iterator))
        {
            t_sequence_array = true;
            if (!MCArrayFetchValueAtIndex(*t_array, t_sequenced_iterator, t_value))
                return;
        }
        else
        {
            t_iterator = 0;
            if (!MCArrayIterate(*t_array, t_iterator, t_key, t_value))
                return;
        }
    }
    else if (each == FU_BYTE)
    {
        if (!ctxt . ConvertToData(*t_condition, &t_data))
            return;
        
        t_length = MCDataGetLength(*t_data);
        t_data_ptr = MCDataGetBytePtr(*t_data);
    }
    else
    {
        if (!ctxt . ConvertToString(*t_condition, &t_string))
            return;
        
        switch (each)
        {
            case FU_LINE:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_LINE);
                break;
            case FU_PARAGRAPH:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_PARAGRAPH);
                break;
            case FU_SENTENCE:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_SENTENCE);
                break;
            case FU_ITEM:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_ITEM);
                break;
            case FU_WORD:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_WORD);
                break;
            case FU_TRUEWORD:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_TRUEWORD);
                break;
            case FU_TOKEN:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_TOKEN);
                break;
            case FU_CODEPOINT:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CODEPOINT);
                break;
            case FU_CODEUNIT:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CODEUNIT);
                break;
            case FU_CHARACTER:
            default:
                tci = MCStringsTextChunkIteratorCreate(ctxt, *t_string, CT_CHARACTER);
                break;
        } 
    }
    
    bool done;
    done = false;
    
    bool endnext;
    endnext = false;
    
    bool t_found;
    t_found = false;
    
    while (!done)
    {
        MCAutoStringRef t_unit;
        MCAutoDataRef t_byte;
        switch (each)
        {
            case FU_KEY:
            {
                loopvar -> set(ctxt, t_key);
                if (!MCArrayIterate(*t_array, t_iterator, t_key, t_value))
                    endnext = true;
            }
            break;
                
            case FU_ELEMENT:
            {
                loopvar -> set(ctxt, t_value);
                // SN-2015-06-15: [[ Bug 15457 ]] Sequenced, numeric arrays
                //  have their own iterator
                if (t_sequence_array)
                {
                    if (!MCArrayFetchValueAtIndex(*t_array, ++t_sequenced_iterator, t_value))
                        endnext = true;
                }
                else
                {
                    if (!MCArrayIterate(*t_array, t_iterator, t_key, t_value))
                        endnext = true;
                }
            }
            break;
            
            case FU_BYTE:
            {
                // SN-2014-04-14 [[ Bug 12184 ]] If we have no data at all, we don't want to start the loop
                if (t_length)
                {
                    MCDataCreateWithBytes(t_data_ptr++, 1, &t_byte);
                    
                    endnext = (--t_length) == 0;
                }
                else
                    done = true;
            }
            break;
                
            default:
            {
                t_found = MCStringsTextChunkIteratorNext(ctxt, *tci);
                endnext = tci -> IsExhausted();
                
                if (!t_found)
                {
                    t_unit = kMCEmptyString;
                    done = true;
                }
                else
                    tci -> CopyString(&t_unit);
            }
            break;
        }
        // MW-2010-12-15: [[ Bug 9218 ]] Added KEY to the type of repeat that already
        //   copies the value.
        // MW-2011-02-08: [[ Bug ]] Make sure we don't use 't_unit' if the repeat type is 'key' or
        //   'element'.
        // Set the loop variable to whatever the value was in the last iteration.
        if (each == FU_BYTE)
        {
            // SN-2014-04-14 [[ Bug 12184 ]] We don't need to set anything since we are not going in the loop
            if (!done)
                loopvar -> set(ctxt, *t_byte);
        }
        else if (each != FU_ELEMENT && each != FU_KEY)
            loopvar -> set(ctxt, *t_unit);
        
        if (!done)
            MCKeywordsExecuteRepeatStatements(ctxt, statements, line, pos, done);
        
        if (endnext)
        {
            // Reset the loop variable to whatever the value was in the last iteration.
            if (loopvar != nil)
            {
                if (each == FU_BYTE)
                    loopvar -> set(ctxt, *t_byte);
                else if (each != FU_ELEMENT && each != FU_KEY)
                    loopvar -> set(ctxt, *t_unit);
            }
        }
        
        done = done || endnext;
    }
}