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

📄 controlbar.cpp

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

                  // bottom rect's y
    rect.height = rect.y - curY;
    rect.x = curX;
    rect.y = curY;
    rect.width  = wxMin( paneHeight, frmWidth );

    pPane->SetBoundsInParent( rect );

    curX += rect.width;

    // setup RIGHT pane

    pPane = mPanes[ FL_ALIGN_RIGHT ];

                         // left pane's height
    pPane->SetPaneWidth( rect.height );

    pPane->RecalcLayout();
    paneHeight = pPane->GetPaneHeight();

                  // left pane's height
    rect.height = rect.height;
    rect.x = wxMax( frmWidth - paneHeight, curX );
    rect.y = curY;
    rect.width  = frmWidth - rect.x;

    pPane->SetBoundsInParent( rect );

    // recalc bounds of the client-window

    mClntWndBounds.x = mPanes[FL_ALIGN_LEFT]->mBoundsInParent.x +
                       mPanes[FL_ALIGN_LEFT]->mBoundsInParent.width;
    mClntWndBounds.y = mPanes[FL_ALIGN_TOP ]->mBoundsInParent.y +
                       mPanes[FL_ALIGN_TOP ]->mBoundsInParent.height;

    mClntWndBounds.width  = mPanes[FL_ALIGN_RIGHT]->mBoundsInParent.x -
                            mClntWndBounds.x;
    mClntWndBounds.height = mPanes[FL_ALIGN_BOTTOM]->mBoundsInParent.y -
                            mClntWndBounds.y;

    if ( repositionBarsNow )

        PositionPanes();
}

int wxFrameLayout::GetClientHeight()
{
    // for better portablility wxWindow::GetSzie() is not used here

    return mClntWndBounds.height;
}

int wxFrameLayout::GetClientWidth()
{
    // for better portablility wxWindow::GetSzie() is not used here

    return mClntWndBounds.width;
}

void wxFrameLayout::PositionClientWindow()
{
    if ( mpFrameClient )
    {
        if ( mClntWndBounds.width >= 1 && mClntWndBounds.height >= 1 )
        {
            mpFrameClient->SetSize( mClntWndBounds.x,     mClntWndBounds.y,
                                    mClntWndBounds.width, mClntWndBounds.height, 0 );

            if ( !mpFrameClient->IsShown() )

                mpFrameClient->Show( true );
        }
        else
            mpFrameClient->Show( false );
    }
}

void wxFrameLayout::PositionPanes()
{
    PositionClientWindow();

    // FOR NOW:: excessive updates!
    // reposition bars within all panes

    int i;
    for ( i = 0; i != MAX_PANES; ++i )
        mPanes[i]->SizePaneObjects();
}

void wxFrameLayout::OnSize( wxSizeEvent& event )
{
    mpFrame->ProcessEvent( event );
    event.Skip( false ); // stop its progpagation

    if ( event.GetEventObject() == (wxObject*) mpFrame )
    {
        GetUpdatesManager().OnStartChanges();
        RecalcLayout(true);
        GetUpdatesManager().OnFinishChanges();
        GetUpdatesManager().UpdateNow();
    }

}

/*** protected members ***/

void wxFrameLayout::HideBarWindows()
{
    size_t i;
    for ( i = 0; i != mAllBars.Count(); ++i )
        if ( mAllBars[i]->mpBarWnd && mAllBars[i]->mState != wxCBAR_FLOATING )
            mAllBars[i]->mpBarWnd->Show( false );

    // then floated frames

    ShowFloatedWindows( false );

    if ( mpFrameClient )

        mpFrameClient->Show( false );
}

void wxFrameLayout::UnhookFromFrame()
{
    // NOTE:: the SetEvtHandlerEnabled() method is not used
    //        here, since it is assumed that unhooking layout
    //        from window may result destroying of the layout itself
    //
    //        BUG BUG BUG (wx):: this would not be a problem if
    //                           wxEvtHandler's destructor checked if
    //                           this handler is currently the top-most
    //                           handler of some window, and additionally
    //                           to the reconnecting itself from the chain.
    //                           It would also re-setup current event handler
    //                           of the window using wxWindow::SetEventHandler()

    // FOR NOW::

    if ( mpFrame->GetEventHandler() == this )
    {
        mpFrame->PopEventHandler();
        return;
    }

    if ( mpFrame )
    {
        if ( this == mpFrame->GetEventHandler() )
        {
            mpFrame->SetEventHandler( this->GetNextHandler() );
        }
        else
        {
            wxEvtHandler* pCur = mpFrame->GetEventHandler();

            while ( pCur )
            {
                if ( pCur == this )
                    break;

                pCur = pCur->GetNextHandler();
            }

            // do not try to unhook ourselves if we're not hooked yet
            if ( !pCur )
                return;
        }

        if ( GetPreviousHandler() )
            GetPreviousHandler()->SetNextHandler( GetNextHandler() );
        else
        {
            mpFrame->PopEventHandler();
            return;
        }

        if ( GetNextHandler() )
            GetNextHandler()->SetPreviousHandler( GetPreviousHandler() );

        SetNextHandler( NULL );
        SetPreviousHandler( NULL );
    }
}

void wxFrameLayout::HookUpToFrame()
{
    // unhook us first, we're already hooked up

    UnhookFromFrame();

    // put ourselves on top

    mpFrame->PushEventHandler( this );
}

cbDockPane* wxFrameLayout::GetBarPane( cbBarInfo* pBar )
{
    int i;
    for ( i = 0; i != MAX_PANES; ++i )
        if ( mPanes[i]->BarPresent( pBar ) )
            return mPanes[i];

    return NULL;
}

void wxFrameLayout::CreateCursors()
{
    /*
    // FIXME:: The below code somehow doesn't work - cursors remain unchanged
    char bits[64];

    set_cursor_bits( _gHorizCursorImg, bits, 32, 16 );

    mpHorizCursor = new wxCursor( bits, 32, 16 );

    set_cursor_bits( _gVertCursorImg, bits, 32, 16 );

    mpVertCursor  = new wxCursor( bits, 32, 16 );
    */

    // FOR NOW:: use standard ones

    mpHorizCursor  = new wxCursor(wxCURSOR_SIZEWE);
    mpVertCursor   = new wxCursor(wxCURSOR_SIZENS);
    mpNormalCursor = new wxCursor(wxCURSOR_ARROW );
    mpDragCursor   = new wxCursor(wxCURSOR_CROSS );
    mpNECursor     = new wxCursor(wxCURSOR_NO_ENTRY);

    mFloatingPosStep.x = 25;
    mFloatingPosStep.y = 25;

    mNextFloatedWndPos.x = mFloatingPosStep.x;
    mNextFloatedWndPos.y = mFloatingPosStep.y;
}

bool wxFrameLayout::HitTestPane( cbDockPane* pPane, int x, int y )
{
    return rect_contains_point( pPane->GetRealRect(), x, y );
}

cbDockPane* wxFrameLayout::HitTestPanes( const wxRect& rect,
                                         cbDockPane* pCurPane )
{
    // first, give the privilege to the current pane

    if ( pCurPane && rect_hits_rect( pCurPane->GetRealRect(), rect ) )

        return pCurPane;

    int i;
    for ( i = 0; i != MAX_PANES; ++i )
    {
        if ( pCurPane != mPanes[i] &&
             rect_hits_rect( mPanes[i]->GetRealRect(), rect ) )
        {
            return mPanes[i];
        }
    }
    return 0;
}

void wxFrameLayout::ForwardMouseEvent( wxMouseEvent& event,
                                           cbDockPane*   pToPane,
                                           int           eventType )
{
    wxPoint pos( event.m_x, event.m_y );
    pToPane->FrameToPane( &pos.x, &pos.y );

    if ( eventType == cbEVT_PL_LEFT_DOWN )
    {
        cbLeftDownEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
    else if ( eventType == cbEVT_PL_LEFT_DCLICK )
    {
        cbLeftDClickEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
    else if ( eventType == cbEVT_PL_LEFT_UP )
    {
        cbLeftUpEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
    else if ( eventType == cbEVT_PL_RIGHT_DOWN )
    {
        cbRightDownEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
    else if ( eventType == cbEVT_PL_RIGHT_UP )
    {
        cbRightUpEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
    else if ( eventType == cbEVT_PL_MOTION )
    {
        cbMotionEvent evt( pos, pToPane );
        FirePluginEvent( evt );
    }
}  // wxFrameLayout::ForwardMouseEvent()


void wxFrameLayout::RouteMouseEvent( wxMouseEvent& event, int pluginEvtType )
{
    if ( mpPaneInFocus )

        ForwardMouseEvent( event, mpPaneInFocus, pluginEvtType );
    else
    {
        int i;
        for ( i = 0; i != MAX_PANES; ++i )
        {
            if ( HitTestPane( mPanes[i], event.m_x, event.m_y ) )
            {
                ForwardMouseEvent( event, mPanes[i], pluginEvtType );
                return;
            }
        }
    }
}

/*** event handlers ***/

void wxFrameLayout::OnRButtonDown( wxMouseEvent& event )
{
    RouteMouseEvent( event, cbEVT_PL_RIGHT_DOWN );
}

void wxFrameLayout::OnRButtonUp( wxMouseEvent& event )
{
    RouteMouseEvent( event, cbEVT_PL_RIGHT_UP );
}

void wxFrameLayout::OnLButtonDown( wxMouseEvent& event )
{
    RouteMouseEvent( event, cbEVT_PL_LEFT_DOWN );
}

void wxFrameLayout::OnLDblClick( wxMouseEvent& event )
{
    RouteMouseEvent( event, cbEVT_PL_LEFT_DCLICK );
}

void wxFrameLayout::OnLButtonUp( wxMouseEvent& event )
{
    RouteMouseEvent( event, cbEVT_PL_LEFT_UP );
}

void wxFrameLayout::OnMouseMove( wxMouseEvent& event )
{
    if ( mpPaneInFocus )

        ForwardMouseEvent( event, mpPaneInFocus, cbEVT_PL_MOTION );
    else
    {
        int i;
        for ( i = 0; i != MAX_PANES; ++i )
        {
            if ( HitTestPane( mPanes[i], event.m_x, event.m_y ) )
            {
                if ( mpLRUPane && mpLRUPane != mPanes[i] )
                {
                    // simulate "mouse-leave" event
                    ForwardMouseEvent( event, mpLRUPane, cbEVT_PL_MOTION );
                }

                ForwardMouseEvent( event, mPanes[i], cbEVT_PL_MOTION );

                mpLRUPane = mPanes[i];

                return;
            }
        }
    }

    if ( mpLRUPane )
    {
        // simulate "mouse-leave" event
        ForwardMouseEvent( event, mpLRUPane, cbEVT_PL_MOTION );
        mpLRUPane = 0;
    }
}

void wxFrameLayout::OnPaint( wxPaintEvent& event )
{
    if ( mRecalcPending  )
        RecalcLayout( true );

    wxPaintDC dc(mpFrame);

    int i;
    for ( i = 0; i != MAX_PANES; ++i )
    {
        wxRect& rect = mPanes[i]->mBoundsInParent;

        dc.SetClippingRegion( rect.x, rect.y, rect.width, rect.height );

        mPanes[i]->PaintPane(dc);

        dc.DestroyClippingRegion();
    }

    event.Skip();
}

void wxFrameLayout::OnEraseBackground( wxEraseEvent& WXUNUSED(event) )
{
    // do nothing
}

void wxFrameLayout::OnIdle( wxIdleEvent& event )
{
    wxWindow* focus = wxWindow::FindFocus();

    if ( !focus && mCheckFocusWhenIdle )
    {
        wxMessageBox(wxT("Hi, no more focus in this app!"));

        mCheckFocusWhenIdle = false;
        //ShowFloatedWindows( false );
    }

    mCheckFocusWhenIdle = false;

    event.Skip();
}

void wxFrameLayout::GetPaneProperties( cbCommonPaneProperties& props, int alignment )
{
    props = mPanes[alignment]->mProps;
}

void wxFrameLayout::SetPaneProperties( const cbCommonPaneProperties& props, int paneMask )
{
    int i;
    for ( i = 0; i != MAX_PANES; ++i )
    {
        if ( mPanes[i]->MatchesMask( paneMask ) )
            mPanes[i]->mProps = props;
    }
}

void wxFrameLayout::SetMargins( int top, int bottom, int left, int right,
                                int paneMask )
{
    int i;
    for ( i = 0; i != MAX_PANES; ++i )
    {
        cbDockPane& pane = *mPanes[i];

        if ( pane.MatchesMask( paneMask ) )
        {
            pane.mTopMargin = top;
            pane.mBottomMargin = bottom;
            pane.mLeftMargin = left;
            pane.mRightMargin = right;
        }
    }
}

void wxFrameLayout::SetPaneBackground( const wxColour& colour )
{
    mBorderPen.SetColour( colour );
}

void wxFrameLayout::RefreshNow( bool recalcLayout )
{
    if ( recalcLayout )
        RecalcLayout( true );

    if ( mpFrame )
        mpFrame->Refresh();
}

/*** plugin-related methods ***/

void wxFrameLayout::FirePluginEvent( cbPluginEvent& event )
{
    // check state of input capture, before processing the event

    if ( mpCaputesInput )
    {
        bool isInputEvt = true;
#if wxCHECK_VERSION(2,3,0)
        if ( event.GetEventType() != cbEVT_PL_LEFT_DOWN &&
             event.GetEventType() != cbEVT_PL_LEFT_UP &&
             event.GetEventType() != cbEVT_PL_RIGHT_DOWN &&
             event.GetEventType() != cbEVT_PL_RIGHT_UP &&
             event.GetEventType() != cbEVT_PL_MOTION )
            isInputEvt = false;
#else
        switch ( event.m_eventType )
        {
            case cbEVT_PL_LEFT_DOWN  : break;
            case cbEVT_PL_LEFT_UP    : break;
            case cbEVT_PL_RIGHT_DOWN : break;
            case cbEVT_PL_RIGHT_UP   : break;
            case cbEVT_PL_MOTION     : break;

            default : isInputEvt = false; break;
        }
#endif  // #if wxCHECK_VERSION(2,3,0)

        if ( isInputEvt )
        {
            mpCaputesInput->ProcessEvent( event );
            return;
        }
    }

    GetTopPlugin().ProcessEvent( event );
}

void wxFrameLayout::CaptureEventsForPlugin ( cbPluginBase* pPlugin )
{
    // cannot capture events for more than one plugin at a time
    wxASSERT( mpCaputesInput == NULL );

    mpCaputesInput = pPlugin;

}

void wxFrameLayout::ReleaseEventsFromPlugin( cbPluginBase* WXUNUSED(pPlugin) )
{
    // events should be captured first
    wxASSERT( mpCaputesInput != NULL );

    mpCaputesInput = NULL;
}

⌨️ 快捷键说明

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