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

📄 bardragpl.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        cbDrawHintRectEvent evt( actualRect, mpCurPane == NULL, false, false );

        mpLayout->FirePluginEvent( evt );

        mPrevHintRect = actualRect;
    }
    else
    {
        // otherwise, if real-time updates option is ON

        if ( mpDraggedBar->mState != wxCBAR_FLOATING && !mpCurPane )
        {
            mpLayout->SetBarState( mpDraggedBar, wxCBAR_FLOATING, true );
        }
        else
            if ( mpDraggedBar->mState == wxCBAR_FLOATING && mpCurPane )
            {
                mpLayout->SetBarState( mpDraggedBar, wxCBAR_DOCKED_HORIZONTALLY, false );

                wasDocked = true;
            }

        if ( mpCurPane )
        {
            mpLayout->GetUpdatesManager().OnStartChanges();

            if ( wasDocked )

            mpDraggedBar->mUMgrData.SetDirty( true );

#ifdef  __WXDEBUG__
            bool success =
#endif
                           mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane, false );

            wxASSERT( success ); // DBG ::

            mpLayout->GetUpdatesManager().OnFinishChanges();
            mpLayout->GetUpdatesManager().UpdateNow();
        }
        else
        {
            if ( mpLayout->mFloatingOn )
            {
                // move the top-most floated bar around as user drags the hint

                mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mHintRect;

                mpLayout->ApplyBarProperties( mpDraggedBar );
            }
        }
    }
}

/*** event handlers ***/

void cbBarDragPlugin::OnMouseMove( cbMotionEvent& event )
{
    // calculate postion in frame's coordiantes

    if ( !mBarDragStarted )
    {
        event.Skip(); // pass event to the next plugin
        return;
    }

    wxPoint mousePos = event.mPos;

    event.mpPane->PaneToFrame( &mousePos.x, &mousePos.y );

    bool   prevIsInClient = ( mpCurPane == 0 );

    AdjustHintRect( mousePos );

    // if the hint-rect is not "tempted" to any pane yet

    if ( mpCurPane == NULL )
    {
        cbDockPane* pPane = HitTestPanes( mHintRect );

        // enable sticking again, if we've left the pane completely
        if ( !pPane )
            mCanStick = true;

        if ( mCanStick && pPane &&
             GetDistanceToPane( pPane, mousePos ) < GetBarHeightInPane( pPane ) )
            StickToPane( pPane, mousePos );
        else
            if ( pPane && HitTestPanes( mousePos ) == pPane && 0 ) // FOR NOW:: disabled

        StickToPane( pPane, mousePos );
    }
    else
    {
        // otherwise, when rect is now sticked to some of the panes
        // check if it should still remain in this pane

        mCanStick = true;

        bool mouseInOther = IsInOtherPane( mousePos );

        if ( mouseInOther )
        {
            cbDockPane* pPane = HitTestPanes( mousePos );

            StickToPane( pPane, mousePos );
        }
        else
        {
            if ( IsInClientArea( mousePos ) )
            {
                cbDockPane* pPane = HitTestPanes( mHintRect );

                if ( pPane &&
                     pPane != mpCurPane &&
                     GetDistanceToPane( pPane, mousePos ) < GetBarHeightInPane( pPane ) )
                    StickToPane( pPane, mousePos );
                else
                    if ( !pPane )
                    {
                        UnstickFromPane( mpCurPane, mousePos );

                        // FOR NOW:: disabled, would cause some mess
                        // mCanStick = false; // prevents from sticking to this
                        // pane again, flag is reset when hint-rect
                        // leaves the pane completely
                    }
                    else
                        if ( GetDistanceToPane( pPane, mousePos ) > GetBarHeightInPane( pPane ) )
                        {
                            if ( !HitsPane( mpCurPane, mHintRect ) )
                            {
                                UnstickFromPane( mpCurPane, mousePos );

                                // FOR NOW:: disabled, would cause some mess
                                // mCanStick = false; // prevents from sticking to this
                                // pane again, flag is reset when hint-rect
                                // leaves the pane completely
                            }
                        }

            }
        }
    }

    ShowHint( prevIsInClient );

    wxCursor* pPrevCurs = mpCurCursor;

    if ( mpCurPane )
    {
        mpCurCursor = mpLayout->mpNormalCursor;
    }
    else
    {
        // if floating is off, and we are in the client
        // area, the cursor will be invalid, otherwise
        // it will be the normal cursor

        if (mpLayout->mFloatingOn)
        {
            mpCurCursor = mpLayout->mpNormalCursor;
        }
        else
        {
            mpCurCursor = mpLayout->mpNECursor;
        }

    }
    if ( pPrevCurs != mpCurCursor )
        mpLayout->GetParentFrame().SetCursor( *mpCurCursor );
}

void cbBarDragPlugin::OnLButtonDown( cbLeftDownEvent& event )
{
    if ( mBarDragStarted  )
    {
        wxMessageBox(wxT("DblClick!"));
    }

    event.Skip();
}

void cbBarDragPlugin::OnLButtonUp( cbLeftUpEvent& event )
{
    if ( mBarDragStarted  )
    {
        if ( mpSrcPane->mProps.mRealTimeUpdatesOn == false )
        {
            // erase current rectangle, and finsih on-screen drawing session

            cbDrawHintRectEvent evt( mPrevHintRect, mpCurPane == NULL, true, true );

            mpLayout->FirePluginEvent( evt );

            if ( mpCurPane != NULL )
            {
                if ( mpSrcPane->mProps.mExactDockPredictionOn )
                {
                    mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane, false );

                    mpLayout->GetUpdatesManager().OnFinishChanges();
                    mpLayout->GetUpdatesManager().UpdateNow();
                }
                else
                {
                    if (mpDraggedBar->mState == wxCBAR_FLOATING)
                    {
                        mpLayout->SetBarState( mpDraggedBar, wxCBAR_DOCKED_HORIZONTALLY, true);
                    }

                    mpLayout->RedockBar( mpDraggedBar, mHintRect, mpCurPane );
                }
            }
            else
            {
                if (mpDraggedBar->mState != wxCBAR_FLOATING)
                {
                    mpLayout->SetBarState(mpDraggedBar, wxCBAR_FLOATING, true);
                }

                mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mHintRect;
                mpLayout->ApplyBarProperties( mpDraggedBar );
            }
        }

        mHintRect.width = -1;

        // In Windows, at least, the frame needs to have a null cursor
        // else child windows (such as text windows) inherit the cursor
#if 1
        mpLayout->GetParentFrame().SetCursor( wxNullCursor );
#else
        mpLayout->GetParentFrame().SetCursor( *mpLayout->mpNormalCursor );
#endif

        mpLayout->ReleaseEventsFromPane( event.mpPane );
        mpLayout->ReleaseEventsFromPlugin( this );

        mBarDragStarted = false;

        if ( mBarWasFloating && mpDraggedBar->mState != wxCBAR_FLOATING )
        {
            // save bar's floating position before it was docked

            mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ] = mFloatedBarBounds;
        }
    }
    else
        event.Skip(); // pass event to the next plugin
}

void cbBarDragPlugin::OnLDblClick( cbLeftDClickEvent& event )
{
    int avoidCompilerWarning = 1;
    if ( avoidCompilerWarning )
    {
        cbBarInfo* pHittedBar;
        cbRowInfo* pRow;

        if ( event.mpPane->HitTestPaneItems( event.mPos,   // in pane's coordiantes
                                             &pRow,
                                             &pHittedBar ) == CB_BAR_CONTENT_HITTED
           )
        {
            mpLayout->SetBarState( pHittedBar, wxCBAR_FLOATING, true );

            mpLayout->RepositionFloatedBar( pHittedBar );

            return; // event is "eaten" by this plugin
        }

        mBarDragStarted = false;

        event.Skip();
    }

    //wxMessageBox("Hi, dblclick arrived!");
}

void cbBarDragPlugin::OnStartBarDragging( cbStartBarDraggingEvent& event )
{
    mpDraggedBar = event.mpBar;
    mpSrcPane    = event.mpPane;

    mpLayout->CaptureEventsForPane( event.mpPane );
    mpLayout->CaptureEventsForPlugin( this );

    mpLayout->GetParentFrame().SetCursor( *mpLayout->mpNormalCursor );

    mBarDragStarted = true;

    wxRect inParent = mpDraggedBar->mBounds;

    mBarWasFloating = mpDraggedBar->mState == wxCBAR_FLOATING;

    if ( mBarWasFloating )
    {
        inParent = mpDraggedBar->mDimInfo.mBounds[ wxCBAR_FLOATING ];
        mFloatedBarBounds = inParent;
    }
    else
        event.mpPane->PaneToFrame( &inParent );

    mHintRect.x = POS_UNDEFINED;

    mHintRect.width  = inParent.width;
    mHintRect.height = inParent.height;

    mMouseInRectX = event.mPos.x - inParent.x;
    mMouseInRectY = event.mPos.y - inParent.y;

    mpSrcPane = event.mpPane;

    if ( mpDraggedBar->mState == wxCBAR_FLOATING )

        mpCurPane = NULL;
    else
        mpCurPane = event.mpPane;

    mPrevHintRect.x = POS_UNDEFINED;

    mCanStick = false; // we're not stuck into any pane now -
                       // there's nowhere to "stick-twice"

    mBarWidthInSrcPane = mpDraggedBar->mDimInfo.mSizes[ mpDraggedBar->mState ].x;

    if ( mpSrcPane->mProps.mRealTimeUpdatesOn == false &&
         mpSrcPane->mProps.mExactDockPredictionOn  )
        mpLayout->GetUpdatesManager().OnStartChanges(); // capture initial state of layout

    // simulate the first mouse movement

    int x = event.mPos.x, y = event.mPos.y;
    mpSrcPane->FrameToPane( &x, &y );

    wxPoint pt(x,y);
    cbMotionEvent motionEvt( pt, event.mpPane );
    this->OnMouseMove( motionEvt );

    return; // event is "eaten" by this plugin
}

/*** on-screen hint-tracking related methods ***/

void cbBarDragPlugin::OnDrawHintRect( cbDrawHintRectEvent& event )
{
    if ( !mpScrDc ) StartTracking();

    DoDrawHintRect( event.mRect, event.mIsInClient );

    if ( event.mLastTime )
        FinishTracking();
}

#define _IMG_A  0xAA    // Note: modified from _A to _IMG_A, _A was already defined (cygwin)
#define _IMG_B  0x00    // Note: modified from _B to _IMG_A, _B was already defined (cygwin)
#define _IMG_C  0x55    // Note: modified from _C to _IMG_C, for consistency reasons.
#define _IMG_D  0x00    // Note: modified from _D to _IMG_D, for consistency reasons.

// FOR NOW:: static

static const unsigned char _gCheckerImg[16] = { _IMG_A,_IMG_B,_IMG_C,_IMG_D,
                                                _IMG_A,_IMG_B,_IMG_C,_IMG_D,
                                                _IMG_A,_IMG_B,_IMG_C,_IMG_D,
                                                _IMG_A,_IMG_B,_IMG_C,_IMG_D
                                              };

void cbBarDragPlugin::StartTracking()
{
    mpScrDc = new wxScreenDC;

    wxScreenDC::StartDrawingOnTop(&mpLayout->GetParentFrame());
}

void cbBarDragPlugin::DoDrawHintRect( wxRect& rect, bool isInClientRect)
{
    wxRect scrRect;

    RectToScr( rect, scrRect );

    int prevLF = mpScrDc->GetLogicalFunction();

    mpScrDc->SetLogicalFunction( wxINVERT );

    if ( isInClientRect )
    {
        // BUG BUG BUG (wx):: somehow stippled brush works only
        // when the bitmap created on stack, not
        // as a member of the class

        wxBitmap checker( (const char*)_gCheckerImg, 8,8 );

        wxBrush checkerBrush( checker );

        mpScrDc->SetPen( mpLayout->mNullPen );
        mpScrDc->SetBrush( checkerBrush );

        int half = mInClientHintBorder / 2;

        mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y - half,
                                scrRect.width + 2*half, mInClientHintBorder );

        mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + scrRect.height - half,
                                scrRect.width + 2*half, mInClientHintBorder );

        mpScrDc->DrawRectangle( scrRect.x - half, scrRect.y + half - 1,
                                mInClientHintBorder, scrRect.height - 2*half + 2);

        mpScrDc->DrawRectangle( scrRect.x + scrRect.width - half,
                                scrRect.y + half - 1,
                                mInClientHintBorder, scrRect.height - 2*half + 2);

        mpScrDc->SetBrush( wxNullBrush );
    }
    else
    {
        mpScrDc->SetPen( mpLayout->mBlackPen );

        mpScrDc->DrawLine( scrRect.x, scrRect.y,
                           scrRect.x + scrRect.width, scrRect.y );

        mpScrDc->DrawLine( scrRect.x, scrRect.y + 1,
                           scrRect.x, scrRect.y + scrRect.height );

        mpScrDc->DrawLine( scrRect.x+1, scrRect.y + scrRect.height,
                           scrRect.x + scrRect.width, scrRect.y + scrRect.height );

        mpScrDc->DrawLine( scrRect.x + scrRect.width , scrRect.y,
                           scrRect.x + scrRect.width, scrRect.y + scrRect.height + 1);
    }

    mpScrDc->SetLogicalFunction( prevLF );
}

void cbBarDragPlugin::DrawHintRect ( wxRect& rect, bool isInClientRect)
{
    DoDrawHintRect( rect, isInClientRect );
}

void cbBarDragPlugin::EraseHintRect( wxRect& rect, bool isInClientRect)
{
    DoDrawHintRect( rect, isInClientRect );
}

void cbBarDragPlugin::FinishTracking()
{
    wxScreenDC::EndDrawingOnTop();

    delete mpScrDc;

    mpScrDc = NULL;
}

void cbBarDragPlugin::RectToScr( wxRect& frameRect, wxRect& scrRect )
{
    scrRect = frameRect;

    int x = frameRect.x, y = frameRect.y;

    mpLayout->GetParentFrame().ClientToScreen( &x, &y );

    scrRect.x = x;
    scrRect.y = y;
}

⌨️ 快捷键说明

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