Beispiel #1
0
void SetSizeTestCase::SetSizeLessThanMinSize()
{
    m_win->SetMinSize(wxSize(100, 100));

    const wxSize size(200, 50);
    m_win->SetSize(size);
    CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
}
Beispiel #2
0
    void Restore()
    {
        int x, y;

        m_w->GetSize( &x, &y );
        if( x != m_x || y != m_y )
            m_w->SetSize( -1, -1, m_x, m_y );
    }
Beispiel #3
0
void wxDynamicSashWindowLeaf::OnReparent(wxEvent &WXUNUSED(event))
{
    if (m_child)
    {
        m_child->Reparent(m_viewport);
    }

    ResizeChild(m_viewport->GetSize());
}
Beispiel #4
0
// Returns FALSE if the window position is considered invalid, which means that it's title
// bar is most likely not easily grabble.  Such a window should be moved to a valid or
// default position.
bool pxIsValidWindowPosition( const wxWindow& window, const wxPoint& windowPos )
{
	// The height of the window is only revlevant to the height of a title bar, which is
	// all we need visible for the user to be able to drag the window into view.  But
	// there's no way to get that info from wx, so we'll just have to guesstimate...

	wxSize sizeMatters( window.GetSize().GetWidth(), 32 );		// if some gui has 32 pixels of undraggable title bar, the user deserves to suffer.
	return wxGetDisplayArea().Contains( wxRect( windowPos, sizeMatters ) );
}
Beispiel #5
0
void SwitchView::OnSize(wxSizeEvent& WXUNUSED(event)) {
    Layout();

    wxScrollBar *hscroll = m_dyn_sash->GetHScrollBar(this);
    wxScrollBar *vscroll = m_dyn_sash->GetVScrollBar(this);

    if (hscroll && vscroll) {
        int hpos = hscroll->GetThumbPosition();
        int vpos = vscroll->GetThumbPosition();

        wxSize size = m_view->GetSize();
        if (hpos + size.GetWidth() > 300)
            hpos = 300 - size.GetWidth();
        if (vpos + size.GetHeight() > 300)
            vpos = 300 - size.GetHeight();

        hscroll->SetScrollbar(hpos, size.GetWidth(), 300, size.GetWidth());
        vscroll->SetScrollbar(vpos, size.GetHeight(), 300, size.GetHeight());
    }
}
Beispiel #6
0
void wxDynamicSashWindowImpl::OnRelease(wxMouseEvent &event)
{
    if ((m_dragging == DSR_CORNER) &&
        (m_window->GetWindowStyle() & wxDS_DRAG_CORNER) != 0)
    {
        DrawSash(m_drag_x, m_drag_y);
        m_container->ReleaseMouse();

        Resize(event.m_x, event.m_y);

        m_dragging = DSR_NONE;
    }
    else if (m_dragging)
    {
        DrawSash(m_drag_x, m_drag_y);
        m_container->ReleaseMouse();

        wxSize size = m_container->GetSize();
        int px = (int)((event.m_x * 100) / size.GetWidth() + 0.5);
        int py = (int)((event.m_y * 100) / size.GetHeight() + 0.5);

        if ((m_dragging == DSR_HORIZONTAL_TAB && py >= 10 && py <= 90)
                    || (m_dragging == DSR_VERTICAL_TAB && px >= 10 && px <= 90))
        {
            if (m_child[0] == NULL)
            {
                Split(px, py);
            }
            else
            {
                /*  It would be nice if moving *this* sash didn't implicitly move
                    the sashes of our children (if any).  But this will do.  */
                wxLayoutConstraints *layout = m_child[0]->m_container->GetConstraints();
                if (m_split == DSR_HORIZONTAL_TAB)
                {
                    layout->height.PercentOf(m_container, wxHeight, py);
                }
                else
                {
                    layout->width.PercentOf(m_container, wxWidth, px);
                }
                m_container->Layout();
            }
        }
        else
        {
            if (m_child[0] != NULL)
            {
                if ((m_dragging == DSR_HORIZONTAL_TAB && py <= 10)
                        || (m_dragging == DSR_VERTICAL_TAB && px <= 10))
                {
                    Unify(1);
                }
                else
                {
                    Unify(0);
                }
            }
        }

        wxCursor cursor;
        if (m_split == DSR_HORIZONTAL_TAB)
            cursor = wxCursor(wxCURSOR_SIZENS);
        else if (m_split == DSR_VERTICAL_TAB)
            cursor = wxCursor(wxCURSOR_SIZEWE);
        else
            cursor = wxCursor(wxCURSOR_ARROW);

        m_container->SetCursor(cursor);

        m_dragging = DSR_NONE;
    }
    else if (m_leaf)
    {
        m_leaf->OnRelease(event);
    }
}
Beispiel #7
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);
    }
}
Beispiel #8
0
void wxDynamicSashWindowImpl::Unify(int panel)
{
    int other = panel == 0 ? 1 : 0;

    if (m_child[panel]->m_leaf)
    {
        wxDynamicSashWindowImpl *child[2];

        child[0] = m_child[0];
        child[1] = m_child[1];

        m_child[0] = m_child[1] = NULL;

        m_leaf = new wxDynamicSashWindowLeaf(this);
        m_leaf->Create();
        m_leaf->m_child = child[panel]->m_leaf->m_child;

        m_leaf->m_vscroll->SetScrollbar(child[panel]->m_leaf->m_vscroll->GetThumbPosition(),
                                        child[panel]->m_leaf->m_vscroll->GetThumbSize(),
                                        child[panel]->m_leaf->m_vscroll->GetRange(),
                                        child[panel]->m_leaf->m_vscroll->GetPageSize());
        m_leaf->m_hscroll->SetScrollbar(child[panel]->m_leaf->m_hscroll->GetThumbPosition(),
                                        child[panel]->m_leaf->m_hscroll->GetThumbSize(),
                                        child[panel]->m_leaf->m_hscroll->GetRange(),
                                        child[panel]->m_leaf->m_hscroll->GetPageSize());
        m_add_child_target = NULL;
        wxDynamicSashReparentEvent event(m_leaf);
        m_leaf->ProcessEvent(event);

        delete child[0];
        delete child[1];

        m_split = DSR_NONE;

        wxDynamicSashUnifyEvent unify(m_leaf->m_child);
        m_leaf->m_child->ProcessEvent(unify);
    }
    else
    {
        m_split = m_child[panel]->m_split;

        delete m_child[other];

        wxDynamicSashWindowImpl *child_panel = m_child[panel];
        m_child[0] = child_panel->m_child[0];
        m_child[1] = child_panel->m_child[1];

        m_child[0]->m_parent = this;
        m_child[1]->m_parent = this;

        m_add_child_target = NULL;
        m_child[0]->m_container->Reparent(m_container);
        m_child[1]->m_container->Reparent(m_container);

        child_panel->m_child[0] = child_panel->m_child[1] = NULL;
        delete child_panel;

        wxSize size = m_container->GetSize();
        wxSize child_size = m_child[0]->m_container->GetSize();

        ConstrainChildren(child_size.GetWidth() * 100 / size.GetWidth(),
                            child_size.GetHeight() * 100 / size.GetHeight());

        m_container->Layout();
    }
}
Beispiel #9
0
void wxDynamicSashWindowLeaf::OnViewSize(wxSizeEvent &WXUNUSED(event))
{
    if ( m_viewport )
        ResizeChild(m_viewport->GetSize());
}
Beispiel #10
0
void SetSizeTestCase::SetSize()
{
    const wxSize size(127, 35);
    m_win->SetSize(size);
    CPPUNIT_ASSERT_EQUAL( size, m_win->GetSize() );
}
Beispiel #11
0
 wxSizeKeeper( wxWindow* w )
     : m_w( w )
 {
     m_w->GetSize( &m_x, &m_y );
 }