⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dyntbar.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

void wxDynamicToolBar::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
    // draw separators if any
    wxPaintDC dc(this);

    size_t i;
    for( i = 0; i != mTools.Count(); ++i )
    {
        if ( mTools[i]->mIsSeparator )
        {
            // check if separator doesn't have it's own window
            // if so, then draw it using built-in drawing method
            if ( !mTools[i]->mpToolWnd )
                DrawSeparator( *mTools[i], dc );
        }
    }
}

// FOR NOW:: quick fix
#include "wx/choice.h"

void wxDynamicToolBar::SizeToolWindows()
{
    bool bStateCheckDone = false;
    bool bHorzSeparator  = false;
    int maxWidth         = 0;
    int maxHeight        = 0;

    size_t i;
    for( i = 0; i != mTools.Count(); ++i )
    {
        wxDynToolInfo& info = *mTools[i];

        if ( !info.mIsSeparator )
        {
            // center real rectangle within the rectangle
            // provided by the layout manager

            int x = info.mRect.x;
            int y = info.mRect.y + (info.mRect.height - info.mRealSize.y)/2;

            // FOR NOW FOR NOW:: quick & dirty fix
            if ( info.mpToolWnd->IsKindOf( CLASSINFO( wxChoice ) ) )
            {
                info.mpToolWnd->SetSize( x, y,
                                         info.mRealSize.x - 3,
                                         info.mRealSize.y);
            }
            else
            {
                info.mpToolWnd->SetSize( x, y,
                                         info.mRealSize.x,
                                         info.mRealSize.y );
            }
        }
        else
        {
            // We performer this code here, so we only execute it when we have
            // separators and we do it only once (all to do with performance...)
            if (!bStateCheckDone)
            {
                bStateCheckDone = true;

                size_t j;
                wxDynToolInfo *pInfo;
                wxDynToolInfo *pPrevInfo = NULL;
                int nVertSeparators = 0;

                for( j = 0; j != mTools.Count(); ++j )
                {
                    pInfo = mTools[j];

                    // Count all Vert Separators.
                    if ( pInfo->mIsSeparator )
                        nVertSeparators++;

                    // Check if the new row starts with a Separator.
                    if ( pPrevInfo && pInfo->mIsSeparator &&
                         // pPrevInfo->mRect.x >= pInfo->mRect.x &&
                         pPrevInfo->mRect.y < pInfo->mRect.y)
                    {
                        // If the Separator is shown on the next row and it's
                        // the only object on the row it would mean that the
                        // Separator should be shown as Horizontal one.
                        if (j+1 != mTools.Count())
                        {
                            if (pInfo->mRect.y < mTools[j+1]->mRect.y)
                                nVertSeparators--;
                        }
                        else
                        {
                            nVertSeparators--;
                        }
                    }

                    pPrevInfo = pInfo;

                    maxWidth = wxMax(pInfo->mRect.width, maxWidth);
                    maxHeight = wxMax(pInfo->mRect.height, maxHeight);
                }

                bHorzSeparator = nVertSeparators == 0;
            }

            // Check if we should draw Horz or Vert...
            if ( !bHorzSeparator )
            {
                info.mRect.width = mSepartorSize;
                info.mRect.height = maxHeight;
            }
            else
            {
                info.mRect.width = maxWidth;
                info.mRect.height = mSepartorSize;
            }

            // Do we need to set a new size to a separator object?
            if ( info.mpToolWnd )
            {
                info.mpToolWnd->SetSize( info.mRect.x,
                                         info.mRect.y,
                                         info.mRect.width,
                                         info.mRect.height);
            }

        }
    }
}

bool wxDynamicToolBar::Layout()
{
    int x,y;
    GetSize( &x, &y );
    wxSize wndDim(x,y);
    wxSize result;
    size_t i;
    wxDynToolInfo *pInfo;

    // Reset the size of separators...
    for( i = 0; i != mTools.Count(); ++i )
    {
        pInfo = mTools[i];

        if ( pInfo->mIsSeparator )
        {
            pInfo->mRect.width  = mSepartorSize;
            pInfo->mRect.height = mSepartorSize;
        }
    }

    // Calc and set the best layout
    GetPreferredDim( wndDim, result );

    SizeToolWindows();
    return true;
}

void wxDynamicToolBar::GetPreferredDim( const wxSize& givenDim, wxSize& prefDim )
{
    if ( !mpLayoutMan )
        mpLayoutMan = CreateDefaultLayout();

    wxLayoutItemArrayT items;

    // safe conversion
    size_t i;
    for( i = 0; i != mTools.Count(); ++i )
        items.Add( mTools[i] );

    mpLayoutMan->Layout( givenDim, prefDim, items, mVertGap, mHorizGap );
}

void wxDynamicToolBar::SetLayout( LayoutManagerBase* pLayout )
{
    if ( mpLayoutMan )
        delete mpLayoutMan;

    mpLayoutMan = pLayout;

    Layout();
}

void wxDynamicToolBar::EnableTool(int toolIndex, bool enable )
{
    wxDynToolInfo* pInfo = GetToolInfo( toolIndex );

    if ( !pInfo )
        return;

    if ( pInfo->mIsSeparator || !pInfo->mpToolWnd )
        return;

    pInfo->mpToolWnd->Enable( enable );
}

/***** Implementation for class BagLayout *****/

void BagLayout::Layout(  const wxSize&       parentDim,
                         wxSize&             resultingDim,
                         wxLayoutItemArrayT& items,
                         int                 horizGap,
                         int                 vertGap
                      )
{
    int maxWidth = 0;
    int curY  = 0;
    int nRows = 0;

    size_t i = 0;

    while( i < items.Count() )
    {
        int curX   = 0;
        int height = 0;
        // int nItems = 0;

        // int firstItem  = i;
        int itemsInRow = 0;

        if ( nRows > 0 )
            curY += vertGap;

        // step #1 - arrange horizontal positions of items in the row

        do
        {
            if ( itemsInRow > 0 )
                curX += horizGap;

            wxRect& r = items[i]->mRect;

            if ( curX + r.width > parentDim.x )
            {
                if ( itemsInRow > 0 )
                    break;
            }
            r.x = curX;
            r.y = curY;

            curX += r.width;

            height = wxMax( height, r.height );

            ++itemsInRow;
            ++i;

        } while( i < items.Count() );

        curY += height;

        maxWidth = wxMax( maxWidth, curX );
    }

    resultingDim.x = maxWidth;
    resultingDim.y = curY;
}

//////// stuff from 2.1.15 ///////////

wxToolBarToolBase* wxDynamicToolBar::FindToolForPosition( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) const
{
    return NULL;
}

bool wxDynamicToolBar::DoInsertTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) )
{
    return true;
}

bool wxDynamicToolBar::DoDeleteTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) )
{
    return true;
}

void wxDynamicToolBar::DoEnableTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(enable) )
{
}

void wxDynamicToolBar::DoToggleTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) )
{
}

void wxDynamicToolBar::DoSetToggle( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) )
{
}

wxToolBarToolBase* wxDynamicToolBar::CreateTool( int WXUNUSED(id),
                                                 const wxString& WXUNUSED(label),
                                                 const wxBitmap& WXUNUSED(bmpNormal),
                                                 const wxBitmap& WXUNUSED(bmpDisabled),
                                                 wxItemKind WXUNUSED(kind),
                                                 wxObject *WXUNUSED(clientData),
                                                 const wxString& WXUNUSED(shortHelp),
                                                 const wxString& WXUNUSED(longHelp)
                                                )
{
    return NULL;
}

wxToolBarToolBase* wxDynamicToolBar::CreateTool( wxControl* WXUNUSED(control) )
{
    return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -