//---------------------------------------------------------------------------------------
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()) );
}
Beispiel #2
0
//---------------------------------------------------------------------------------------
void Layouter::layout_item(ImoContentObj* pItem, GmoBox* pParentBox)
{
    LOMSE_LOG_DEBUG(Logger::k_layout, str(boost::format(
        "Laying out id %d %s") % pItem->get_id() % pItem->get_name() ));

    m_pCurLayouter = create_layouter(pItem);

    m_pCurLayouter->prepare_to_start_layout();
    while (!m_pCurLayouter->is_item_layouted())
    {
        m_pCurLayouter->create_main_box(pParentBox, m_pageCursor,
                                        m_availableWidth, m_availableHeight);
        m_pCurLayouter->layout_in_box();
        m_pCurLayouter->set_box_height();

        if (!m_pCurLayouter->is_item_layouted())
        {
            pParentBox = start_new_page();
        }
    }
    m_pCurLayouter->add_end_margins();

    //update cursor and available space
    GmoBox* pChildBox = m_pCurLayouter->get_item_main_box();
    if (pChildBox)  //AWARE: NullLayouter does not create a box
    {
        m_pageCursor.y = pChildBox->get_bottom();
        m_availableHeight -= pChildBox->get_height();
    }

    if (!pItem->is_score())
        delete m_pCurLayouter;
}