Пример #1
0
//---------------------------------------------------------------------------------------
DocCursorState CaretPositioner::click_point_to_cursor_state(GraphicModel* pGModel,
                                int iPage, LUnits x, LUnits y, ImoObj* pImo, GmoObj* pGmo)
{
    ImoObj* pTopImo = pImo->find_block_level_parent();

    if (pTopImo->is_score())
    {
        InnerLevelCaretPositioner* p = new_positioner(pTopImo, pGModel);
        SpElementCursorState innerState =
                        p->click_point_to_cursor_state(iPage, x, y, pImo, pGmo);
        int topId = (innerState.get() == NULL ? k_no_imoid : pTopImo->get_id());
        return DocCursorState(topId, innerState);
    }
	else
        return DocCursorState(pTopImo->get_id(), SharedPtr<ElementCursorState>());
}
Пример #2
0
//=======================================================================================
// SelectionValidator implementation
//=======================================================================================
bool SelectionValidator::is_valid_to_add_tie(SelectionSet* pSelection,
                                           ImoNote** ppStartNote,
                                           ImoNote** ppEndNote)
{
    //Returns TRUE if current selection is valid for adding a tie.
    //If valid, returns pointers to start and end notes, if not NULL parameters received


    //Conditions to be valid:
    //   1. The first note found can be tied to next one
    //   2. If condition 1 is true, the next note must also be in the selection

    bool fValid = false;
    ImoNote* pStart = NULL;
    ImoNote* pEnd = NULL;

    ColStaffObjs* pCollection = pSelection->get_staffobjs_collection();
    if (pCollection == NULL)
        return false;

    ColStaffObjsIterator it;
    for (it = pCollection->begin(); it != pCollection->end(); ++it)
    {
        ImoObj* pImo = (*it)->imo_object();
        if (pImo->is_note())
        {
            if (!pStart)
            {
                //first note found. Verify if it can be tied to next
                pStart = static_cast<ImoNote*>(pImo);
                if (!pStart->is_tied_next())
                {
                    ImoScore* pScore = pStart->get_score();
                    ColStaffObjs* pCol = pScore->get_staffobjs_table();
                    pEnd = ScoreAlgorithms::find_possible_end_of_tie(pCol, pStart);
                }
            }
            else
            {
                //Start note processed. verify if end note is also in the selection
                if (pEnd && pEnd->get_id() == pImo->get_id())
                {
                    fValid = true;      //ok. End note is in the selection
                    break;
                }
            }
        }
    }

    if (fValid)
    {
        if (ppStartNote)
            *ppStartNote = pStart;
        if (ppEndNote)
            *ppEndNote = pEnd;
        return true;
    }
    else
        return false;
}
Пример #3
0
//=======================================================================================
// EventControlPointMoved implementation
//=======================================================================================
EventControlPointMoved::EventControlPointMoved(EEventType type, WpInteractor wpInteractor,
                    GmoObj* pGmo, int iHandler, UPoint uShift, WpDocument wpDoc)
    : EventCommand(type, wpInteractor, 0, wpDoc)
    , m_iHandler(iHandler)
    , m_uShift(uShift)
{
    ImoObj* pImo = pGmo->get_creator_imo();
    m_imoId = pImo->get_id();
    m_gmoType = pGmo->get_gmobj_type();
    m_idx = (pGmo->is_shape() ? static_cast<GmoShape*>(pGmo)->get_shape_id() : -1);
}
Пример #4
0
//---------------------------------------------------------------------------------------
list<ImoId> SelectionSet::filter(int type)
{
    ensure_set_is_valid();

    list<ImoId> objects;
    list<ImoObj*>::iterator it;
    for (it = m_imos.begin(); it != m_imos.end(); ++it)
    {
        ImoObj* pImo = (*it);
        if (pImo->get_obj_type() == type)
            objects.push_back(pImo->get_id());
    }
    return objects;
}
Пример #5
0
//---------------------------------------------------------------------------------------
void SelectionSet::add_gmo(GmoObj* pGmo, bool fSaveImoId)
{
    ensure_set_is_valid();

    m_gmos.push_back(pGmo);

    ImoObj* pImo = pGmo->get_creator_imo();
    if (pImo)
    {
        m_imos.push_back(pImo);
        if (fSaveImoId)
            m_ids.push_back( pImo->get_id() );

        if (pImo->is_staffobj())
            add_staffobj_to_collection( static_cast<ImoStaffObj*>(pImo) );
    }
}
Пример #6
0
//---------------------------------------------------------------------------------------
void SelectionSet::ensure_set_is_valid()
{
    if (!m_fValid)
    {
        if (m_pDoc)
        {
            m_gmos.clear();
            m_imos.clear();
            delete m_pCollection;
            m_pCollection = NULL;
            m_pMasterCollection = NULL;
            m_fValid = true;

            list<ImoId>::iterator it = m_ids.begin();
            while (it != m_ids.end())
            {
                ImoObj* pImo = m_pDoc->get_pointer_to_imo(*it);
                if (pImo)
                {
                    m_imos.push_back(pImo);
                    if (pImo->is_staffobj())
                        add_staffobj_to_collection( static_cast<ImoStaffObj*>(pImo) );

                    if (m_pGModel)      //In some unit tests, there is no GModel
                    {
                        GmoObj* pGmo = m_pGModel->get_main_shape_for_imo( pImo->get_id() );
                        //TODO: When adding a GmoObj, its Shape Id should be saved so that
                        //      following method can be used:
                        // GmoShape* get_shape_for_imo(ImoId imoId, ShapeId shapeId);

                        m_gmos.push_back(pGmo);
                    }
                    ++it;
                }
                else
                    it = m_ids.erase(it);
            }
        }
        else
            clear();
    }
}
Пример #7
0
//---------------------------------------------------------------------------------------
string SelectionSet::dump_selection()
{
    if (this->empty())
        return "No objects selected.";

    ensure_set_is_valid();

    if (m_pDoc)
    {
        stringstream msg;
        list<ImoId>::iterator it;
        for (it = m_ids.begin(); it != m_ids.end(); ++it)
        {
            ImoObj* pImo = m_pDoc->get_pointer_to_imo(*it);
            msg << pImo->get_id() << ": " << pImo->get_name() << endl;
        }
        return msg.str();
    }
    return "Error: can't access to Document!";
}
Пример #8
0
//---------------------------------------------------------------------------------------
list<ImoId> SelectionSet::filter_notes_rests()
{
    //note/rests are returned in order

    ensure_set_is_valid();

    list<ImoId> notes;
    ColStaffObjs* pCollection = get_staffobjs_collection();
    if (pCollection != NULL)
    {
        ColStaffObjsIterator it;
        for (it = pCollection->begin(); it != pCollection->end(); ++it)
        {
            ImoObj* pImo = (*it)->imo_object();
            if (pImo->is_note_rest())
                notes.push_back(pImo->get_id());
        }
    }
    return notes;
}
Пример #9
0
//---------------------------------------------------------------------------------------
GmoRef GmoObj::get_ref()
{
    if (this->is_box())
    {
        ImoObj* pImo = get_creator_imo();
        if (pImo)
        {
            if (this->is_box_control() || pImo->is_mouse_over_generator())
            {
                ImoId id = pImo->get_id();
                ImoId idg = 0;
                if (is_box_control())
                {
                    Control* pControl =
                        static_cast<GmoBoxControl*>(this)->get_creator_control();
                    idg = pControl->get_control_id();
                }

                return make_pair(id, idg);
            }
        }
    }
    return k_no_gmo_ref;
}