void WindowTestCase::Mouse()
{
    wxCursor cursor(wxCURSOR_CHAR);
    m_window->SetCursor(cursor);

    CPPUNIT_ASSERT(m_window->GetCursor().IsOk());

    //A plain window doesn't have a caret
    CPPUNIT_ASSERT(!m_window->GetCaret());

    wxCaret* caret = new wxCaret(m_window, 16, 16);
    m_window->SetCaret(caret);

    CPPUNIT_ASSERT(m_window->GetCaret()->IsOk());

    m_window->CaptureMouse();

    CPPUNIT_ASSERT(m_window->HasCapture());

    m_window->ReleaseMouse();

    CPPUNIT_ASSERT(!m_window->HasCapture());
}
Beispiel #2
0
bool wxDynamicSashWindowImpl::Create()
{
    if (!m_container)
        m_container = m_window;

    wxCursor cursor(wxCURSOR_ARROW);
    m_container->SetCursor(cursor);

    m_leaf = new wxDynamicSashWindowLeaf(this);
    if (!m_leaf)
        return false;

    if (!m_leaf->Create())
    {
        delete m_leaf;
        m_leaf = NULL;
        return false;
    }

    m_container->SetEventHandler(this);

    Connect(wxEVT_SIZE, wxSizeEventHandler(wxDynamicSashWindowImpl::OnSize));
    Connect(wxEVT_PAINT, wxPaintEventHandler(wxDynamicSashWindowImpl::OnPaint));
    Connect(wxEVT_MOTION,
            wxMouseEventHandler(wxDynamicSashWindowImpl::OnMouseMove));
    Connect(wxEVT_ENTER_WINDOW,
            wxMouseEventHandler(wxDynamicSashWindowImpl::OnMouseMove));
    Connect(wxEVT_LEAVE_WINDOW,
            wxMouseEventHandler(wxDynamicSashWindowImpl::OnLeave));
    Connect(wxEVT_LEFT_DOWN,
            wxMouseEventHandler(wxDynamicSashWindowImpl::OnPress));
    Connect(wxEVT_LEFT_UP,
            wxMouseEventHandler(wxDynamicSashWindowImpl::OnRelease));

    return true;
}
Beispiel #3
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 #4
0
bool wxDynamicSashWindowLeaf::Create()
{
    m_hscroll = new wxScrollBar();
    m_vscroll = new wxScrollBar();
    m_viewport = new wxWindow();

    wxDynamicSashWindowImpl *add_child_target = m_impl->m_add_child_target;
    m_impl->m_add_child_target = NULL;

    bool success = m_hscroll->Create(m_impl->m_container, wxID_ANY,
                                     wxDefaultPosition, wxDefaultSize,
                                     wxSB_HORIZONTAL);
    if ( success )
        success = m_vscroll->Create(m_impl->m_container, wxID_ANY,
                                    wxDefaultPosition, wxDefaultSize,
                                    wxSB_VERTICAL);
    if ( success )
        success = m_viewport->Create(m_impl->m_container, wxID_ANY);
    if ( !success )
        return false;

    m_impl->m_add_child_target = add_child_target;

    wxCursor cursor(wxCURSOR_ARROW);
    m_hscroll->SetCursor(cursor);
    m_vscroll->SetCursor(cursor);
    m_viewport->SetCursor(cursor);

    // the viewport must resize its child when it is itself resized, but it's
    // more convenient to do it in our own method instead of deriving a new
    // class just for this: this is why we pass this as last Connect() argument
    m_viewport->Connect(wxEVT_SIZE,
                        wxSizeEventHandler(wxDynamicSashWindowLeaf::OnViewSize),
                        NULL, this);

    Connect(wxEVT_DYNAMIC_SASH_REPARENT,
            wxEventHandler(wxDynamicSashWindowLeaf::OnReparent));

    if (m_impl->m_window->GetWindowStyle() & wxDS_MANAGE_SCROLLBARS)
    {
        m_hscroll->SetEventHandler(this);
        m_vscroll->SetEventHandler(this);

        Connect(wxEVT_SET_FOCUS,
                wxFocusEventHandler(wxDynamicSashWindowLeaf::OnFocus));
        Connect(wxEVT_SCROLL_TOP,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_BOTTOM,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_LINEUP,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_LINEDOWN,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_PAGEUP,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_PAGEDOWN,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_THUMBTRACK,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
        Connect(wxEVT_SCROLL_THUMBRELEASE,
                wxScrollEventHandler(wxDynamicSashWindowLeaf::OnScroll));
    }

    wxLayoutConstraints *layout = new wxLayoutConstraints();
    if (!layout)
        return false;

    wxSize size = m_hscroll->GetBestSize();

    layout->left.SameAs(m_impl->m_container, wxLeft, 10);
    layout->right.LeftOf(m_vscroll);
    layout->bottom.SameAs(m_impl->m_container, wxBottom, 3);
    layout->height.Absolute(size.GetHeight());
    m_hscroll->SetConstraints(layout);

    layout = new wxLayoutConstraints();
    if (!layout)
        return false;

    size = m_vscroll->GetBestSize();

    layout->top.SameAs(m_impl->m_container, wxTop, 10);
    layout->bottom.Above(m_hscroll);
    layout->right.SameAs(m_impl->m_container, wxRight, 3);
    layout->width.Absolute(size.GetWidth());
    m_vscroll->SetConstraints(layout);

    layout = new wxLayoutConstraints();
    if (!layout)
        return false;
    layout->left.SameAs(m_impl->m_container, wxLeft, 3);
    layout->right.LeftOf(m_vscroll);
    layout->top.SameAs(m_impl->m_container, wxTop, 3);
    layout->bottom.Above(m_hscroll);
    m_viewport->SetConstraints(layout);

    m_impl->m_container->Layout();

    return true;
}