bool wxSplitWindow::DoSetSashPosition(int sashPos)
{
    int newSashPosition = AdjustSashPosition (sashPos);
    if (newSashPosition == m_sashPosition) return false; // do nothing if equal

    m_sashPosition = newSashPosition;
    return true;
}
示例#2
0
bool wxSplitterWindow::DoSetSashPosition(int sashPos)
{
    int newSashPosition = AdjustSashPosition(sashPos);

    if ( newSashPosition == m_sashPosition )
        return false;

    m_sashPosition = newSashPosition;

    return true;
}
int wxSplitWindow::OnSashPositionChanging (int newSashPosition) {
    // If within UNSPLIT_THRESHOLD from edge, set to edge to cause closure.
    //? TODO fix constant value
    const int UNSPLIT_THRESHOLD = 4;

    // first of all, check if OnSashPositionChange() doesn't forbid this change
    if (!OnSashPositionChange (newSashPosition)) return -1; // it does

    // Obtain relevant window dimension for bottom / right threshold check
    int size = GetWindowSize();

    bool unsplit_scenario = false;
    if (m_permitUnsplitAlways || m_minimumPaneSize == 0) {

        // Do edge detection if unsplit premitted
        if (newSashPosition <= UNSPLIT_THRESHOLD) {
            // threshold top / left check
            newSashPosition = 0;
            unsplit_scenario = true;
        }
        if (newSashPosition >= size - UNSPLIT_THRESHOLD) {
            // threshold bottom/right check
            newSashPosition = size;
            unsplit_scenario = true;
        }
    }

    if (!unsplit_scenario) {
        // If resultant pane would be too small, enlarge it
        newSashPosition = AdjustSashPosition (newSashPosition);
    }

    // If the result is out of bounds it means minimum size is too big,
    // so split window in half as best compromise.
    if (newSashPosition < 0 || newSashPosition > size) newSashPosition = size / 2;

    // now let the event handler have it
    // TODO: shouldn't we do it before the adjustments above so as to ensure
    //       that the sash position is always reasonable?
    wxSplitWindowEvent event(wxEVT_COMMAND_SPLITWINDOW_SASH_POS_CHANGING, this);
    event.m_data.pos = newSashPosition;

    if (!DoSendEvent(event)) {
        // the event handler vetoed the change
        newSashPosition = -1;
    }else{
        // it could have been changed by it
        newSashPosition = event.GetSashPosition();
    }

    return newSashPosition;
}
示例#4
0
void wxSplitterWindow::OnSize(wxSizeEvent& event)
{
    // only process this message if we're not iconized - otherwise iconizing
    // and restoring a window containing the splitter has a funny side effect
    // of changing the splitter position!
    wxWindow *parent = wxGetTopLevelParent(this);
    bool iconized;

    wxTopLevelWindow *winTop = wxDynamicCast(parent, wxTopLevelWindow);
    if ( winTop )
    {
        iconized = winTop->IsIconized();
    }
    else
    {
        wxFAIL_MSG(wxT("should have a top level parent!"));

        iconized = false;
    }

    if ( iconized )
    {
        m_lastSize = wxSize(0,0);

        event.Skip();

        return;
    }

    const wxSize curSize = event.GetSize();

    // Update the sash position if needed.
    //
    // Notice that we shouldn't do this if the sash position requested by user
    // couldn't be set yet as it would never be taken into account at all if we
    // modified it before this happens.
    if ( m_windowTwo && m_requestedSashPosition == INT_MAX )
    {
        int size = m_splitMode == wxSPLIT_VERTICAL ? curSize.x : curSize.y;

        int old_size = m_splitMode == wxSPLIT_VERTICAL ? m_lastSize.x : m_lastSize.y;

        // Don't do anything if the size didn't really change.
        if ( size != old_size )
        {
            int newPosition = -1;

            // Apply gravity if we use it.
            int delta = (int) ( (size - old_size)*m_sashGravity );
            if ( delta != 0 )
            {
                newPosition = m_sashPosition + delta;
                if( newPosition < m_minimumPaneSize )
                    newPosition = m_minimumPaneSize;
            }

            // Also check if the second window became too small.
            newPosition = AdjustSashPosition(newPosition == -1
                                                 ? m_sashPosition
                                                 : newPosition);
            if ( newPosition != m_sashPosition )
                SetSashPositionAndNotify(newPosition);
        }
    }

    m_lastSize = curSize;

    SizeWindows();
}