Exemplo n.º 1
0
//---------------------------------------------------------------------------------------
void CaretPositioner::layout_caret(Caret* pCaret, DocCursor* pCursor,
                                   GraphicModel* pGModel)
{
    m_pCursor = pCursor;
    if (m_pCursor->is_inside_terminal_node())
    {
        ImoObj* pTopLevel = m_pCursor->get_parent_object();
        GmoBox* pBox = pGModel->get_box_for_imo(pCursor->get_parent_id());
        if (!pBox)
        {
            LOMSE_LOG_ERROR("No box for cursor pointed object");
        }
        else
        {
            pCaret->set_top_level_box( pBox->get_bounds() );
            InnerLevelCaretPositioner* p = new_positioner(pTopLevel, pGModel);
            p->layout_caret(pCaret, m_pCursor);
        }
    }
    else
    {
        TopLevelCaretPositioner p(pGModel);
        p.layout_caret(pCaret, m_pCursor);
    }
}
Exemplo n.º 2
0
//---------------------------------------------------------------------------------------
void TopLevelCaretPositioner::layout_caret(Caret* pCaret, DocCursor* pCursor)
{
    m_pCursor = pCursor;
    m_state = m_pCursor->get_state();

    ImoId id = m_state.get_parent_level_id();
    GmoBox* pBox = m_pGModel->get_box_for_imo(id);

    URect pos;
    if (pBox)
        pos = pBox->get_bounds();
    else
    {
        //at end of document
        pBox = get_box_for_last_element();
        if (pBox)
        {
            pos.set_top_left( UPoint(pBox->get_left(), pBox->get_bottom()) );
            pos.set_height(1000.0f);
            pos.set_width(1000.0f);
        }
        else
        {
            //empty document
            pos = URect(0.0f, 0.0f, 1000.0f, 1000.0f);
        }
    }

    pCaret->set_type(Caret::k_top_level);
    pCaret->set_top_level_box(pos);
    pCaret->set_position( pos.get_top_left() );
    pCaret->set_size( USize(pos.get_width(), pos.get_height()) );
}