Пример #1
0
/*  This code is called when you finish resizing a view by dragging the
    corner tab, but I think this implementation is lousy and will surprise
    the user more often than it will do what they are trying to do.  What
    I really need to be doing here is do a rewrite such that *no* sashes
    move except the ones immediately to the bottom and right of this window,
    and handle the case where you resize a window larger than it's neighbors
    by destroying the neighbors.

    But this will do for now.  */
void wxDynamicSashWindowImpl::Resize(int x, int y)
{
    wxDynamicSashWindowImpl *h_parent = FindParent(DSR_BOTTOM_EDGE);
    wxDynamicSashWindowImpl *v_parent = FindParent(DSR_RIGHT_EDGE);
    int h_unify = -1;
    int v_unify = -1;
    wxWindow *frame = FindFrame();

    if (x < 0)
        x = 0;
    if (y < 0)
        y = 0;

    if (h_parent)
    {
        m_container->ClientToScreen(NULL, &y);
        h_parent->m_container->ScreenToClient(NULL, &y);

        int py = (int)((y * 100) / h_parent->m_container->GetSize().GetHeight() + 0.5);

        if (py < 10)
        {
            wxDynamicSashWindowImpl *ho_parent = FindParent(DSR_TOP_EDGE);

            if (ho_parent)
            {
                if (FindUpperParent(h_parent, ho_parent) == ho_parent)
                {
                    h_unify = 1;
                }
                else
                {
                    py = (int)((ho_parent->m_child[0]->m_container->GetSize().GetHeight() * 100)
                                / h_parent->m_container->GetSize().GetHeight() + 0.5);
                    h_parent->m_child[0]->m_container->GetConstraints()->height.PercentOf(
                            h_parent->m_container, wxHeight, py);

                    h_parent = ho_parent;
                    h_unify = 0;
                }
            }
            else
            {
                h_unify = 1;
            }
        }
        else if (py > 90)
        {
            h_unify = 0;
        }
        else
        {
            h_parent->m_child[0]->m_container->GetConstraints()->height.PercentOf(
                    h_parent->m_container, wxHeight, py);
            h_parent->m_container->Layout();
        }
    }
    else
    {
        int do_resize = 1;
        h_parent = FindParent(DSR_TOP_EDGE);

        if (h_parent)
        {
            int py = (int)((y * 100) /
                        (h_parent->m_container->GetSize().GetHeight() +
                                y - m_container->GetSize().GetHeight()) + 0.5);

            if (py < 10)
                h_unify = 0;
        }
        else if (y < 64)
        {
            do_resize = 0;
        }

        if (do_resize)
        {
            wxSize size = frame->GetSize();
            frame->SetSize(size.GetWidth(), size.GetHeight() + y - m_container->GetSize().GetHeight());
        }
    }

    if (v_parent)
    {
        m_container->ClientToScreen(&x, NULL);
        v_parent->m_container->ScreenToClient(&x, NULL);

        int px = (int)((x * 100) / v_parent->m_container->GetSize().GetWidth() + 0.5);

        if (px < 10)
        {
            wxDynamicSashWindowImpl *vo_parent = FindParent(DSR_LEFT_EDGE);

            if (vo_parent)
            {
                if (FindUpperParent(v_parent, vo_parent) == vo_parent)
                {
                    v_unify = 1;
                }
                else
                {
                    px = (int)((vo_parent->m_child[0]->m_container->GetSize().GetWidth() * 100)
                                / v_parent->m_container->GetSize().GetWidth() + 0.5);
                    v_parent->m_child[0]->m_container->GetConstraints()->width.PercentOf(
                            v_parent->m_container, wxWidth, px);

                    v_parent = vo_parent;
                    v_unify = 0;
                }
            }
            else
            {
                v_unify = 1;
            }
        }
        else if (px > 90)
        {
            v_unify = 0;
        }
        else
        {
            v_parent->m_child[0]->m_container->GetConstraints()->width.PercentOf(
                    v_parent->m_container, wxWidth, px);
            v_parent->m_container->Layout();
        }
    }
    else
    {
        int do_resize = 1;
        v_parent = FindParent(DSR_LEFT_EDGE);

        if (v_parent)
        {
            int px = (int)((x * 100) /
                        (v_parent->m_container->GetSize().GetWidth() +
                                x - m_container->GetSize().GetWidth()) + 0.5);

            if (px < 10)
                v_unify = 0;
        }
        else if (x < 64)
        {
            do_resize = 0;
        }

        if (do_resize)
        {
            wxSize size = frame->GetSize();
            frame->SetSize(size.GetWidth() + x - m_container->GetSize().GetWidth(), size.GetHeight());
        }
    }

    if (h_unify != -1 && v_unify != -1)
    {
        wxDynamicSashWindowImpl *parent = FindUpperParent(h_parent, v_parent);

        if (parent == h_parent)
        {
            h_parent->Unify(h_unify);
        }
        else
        {
            v_parent->Unify(v_unify);
        }
    }
    else if (h_unify != -1)
    {
        h_parent->Unify(h_unify);
    }
    else if (v_unify != -1)
    {
        v_parent->Unify(v_unify);
    }
}
Пример #2
0
void wxDynamicSashWindowImpl::DrawSash(int x, int y) const
{
    int i, j;

    wxScreenDC dc;
    dc.StartDrawingOnTop(m_container);

    wxBitmap bmp(8, 8);
    wxMemoryDC bdc;
    bdc.SelectObject(bmp);
    bdc.DrawRectangle(-1, -1, 10, 10);
    for (i = 0; i < 8; i++)
    {
        for (j = 0; j < 8; j++)
        {
            if ((i + j) & 1)
                bdc.DrawPoint(i, j);
        }
    }

    wxBrush brush(bmp);
    dc.SetBrush(brush);
    dc.SetLogicalFunction(wxXOR);

    if ((m_dragging == DSR_CORNER) &&
        (m_window->GetWindowStyle() & wxDS_DRAG_CORNER) != 0)
    {
        int cx = 0;
        int cy = 0;

        m_container->ClientToScreen(&cx, &cy);
        m_container->ClientToScreen(&x, &y);

        if (cx < x && cy < y)
        {
            dc.DrawRectangle(cx - 2, cy - 2, x - cx + 4, 4);
            dc.DrawRectangle(x - 2, cy + 2, 4, y - cy);
            dc.DrawRectangle(cx - 2, cy + 2, 4, y - cy);
            dc.DrawRectangle(cx + 2, y - 2, x - cx - 4, 4);
        }
    }
    else
    {
        int body_w, body_h;
        m_container->GetClientSize(&body_w, &body_h);

        if (y < 0)
            y = 0;
        if (y > body_h)
            y = body_h;
        if (x < 0)
            x = 0;
        if (x > body_w)
            x = body_w;

        if (m_dragging == DSR_HORIZONTAL_TAB)
            x = 0;
        else
            y = 0;

        m_container->ClientToScreen(&x, &y);

        int w, h;
        w = body_w;  h = body_h;

        if (m_dragging == DSR_HORIZONTAL_TAB)
            dc.DrawRectangle(x, y - 2, w, 4);
        else
            dc.DrawRectangle(x - 2, y, 4, h);
    }

    dc.EndDrawingOnTop();
}