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

📄 rowdragpl.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        rowdragpl.cpp// Purpose:     cbRowDragPlugin implementation.// Author:      Aleksandras Gluchovas// Modified by:// Created:     06/10/98// RCS-ID:      $Id: rowdragpl.cpp,v 1.9 2006/04/26 16:27:18 PC Exp $// Copyright:   (c) Aleksandras Gluchovas// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__#pragma hdrstop#endif#ifndef WX_PRECOMP#include "wx/wx.h"#endif#include "wx/fl/rowdragpl.h"#define MINIMAL_ROW_DRAG_OFS  5// parameters for row-hints of NC-look#define TRIANGLE_OFFSET       2#define TRIANGLE_TO_PAT_GAP   2#define PAT_OFFSET            2#define COLLAPSED_ICON_WIDTH  45#define COLLAPSED_ICON_HEIGHT 9#define ROW_DRAG_HINT_WIDTH   10#define ICON_TRIAN_WIDTH      6#define ICON_TRIAN_HEIGHT     3/***** Implementation for class cbHiddenBarInfo *****/IMPLEMENT_DYNAMIC_CLASS( cbHiddenBarInfo, wxObject )/***** Implementation for class cbRowDragPlugin *****/IMPLEMENT_DYNAMIC_CLASS( cbRowDragPlugin, cbPluginBase )BEGIN_EVENT_TABLE( cbRowDragPlugin, cbPluginBase )    EVT_PL_LEFT_DOWN          ( cbRowDragPlugin::OnLButtonDown        )    EVT_PL_LEFT_UP              ( cbRowDragPlugin::OnLButtonUp          )    EVT_PL_MOTION              ( cbRowDragPlugin::OnMouseMove          )    EVT_PL_DRAW_PANE_DECOR    ( cbRowDragPlugin::OnDrawPaneBackground )END_EVENT_TABLE()// FIXME:: how to eliminated these cut and pasted constructors?cbRowDragPlugin::cbRowDragPlugin(void)    : mHightColor          ( 192, 192, 255 ),      mLowColor            ( 192, 192, 192 ),      mTrianInnerColor     ( 0,0,255 ),      mTrianInnerPen       ( mTrianInnerColor, 1, wxSOLID ),       mDragStarted         ( false ),      mDecisionMode        ( false ),      mCurDragOfs          ( 0 ),      mCaptureIsOn         ( false ),      mSvTopMargin         ( -1 ),      mSvBottomMargin      ( -1 ),      mSvLeftMargin        ( -1 ),      mSvRightMargin       ( -1 ),         mpPaneImage          ( NULL ),      mpRowImage           ( NULL ),      mpCombinedImage        ( NULL ),      mpRowInFocus         ( NULL ),      mCollapsedIconInFocus( -1 ),            mpPane               ( NULL ){}cbRowDragPlugin::cbRowDragPlugin( wxFrameLayout* pLayout, int paneMask )    : cbPluginBase( pLayout, paneMask ),               mHightColor          ( 192, 192, 255 ),      mLowColor            ( 192, 192, 192 ),      mTrianInnerColor     ( 0,0,255 ),      mTrianInnerPen       ( mTrianInnerColor, 1, wxSOLID ),         mDragStarted         ( false ),      mDecisionMode        ( false ),      mCurDragOfs          ( 0 ),      mCaptureIsOn         ( false ),      mSvTopMargin         ( -1 ),      mSvBottomMargin      ( -1 ),      mSvLeftMargin        ( -1 ),      mSvRightMargin       ( -1 ),            mpPaneImage          ( NULL ),      mpRowImage           ( NULL ),      mpCombinedImage        ( NULL ),      mpRowInFocus         ( NULL ),      mCollapsedIconInFocus( -1 ),            mpPane               ( NULL ){}cbRowDragPlugin::~cbRowDragPlugin(){}// handlers for plugin eventsvoid cbRowDragPlugin::OnMouseMove( cbMotionEvent& event ){    // short-cuts    wxPoint pos = event.mPos;    mpPane      = event.mpPane;    mpPane->PaneToFrame( &pos.x, &pos.y );    if ( !mDragStarted )    {        if ( mDecisionMode && mpRowInFocus )        {            int ofs;            if ( mpPane->IsHorizontal() )                ofs = pos.y - mDragOrigin.y;            else                ofs = pos.x - mDragOrigin.x;            // check if the item was dragged sufficeintly            // far, enough to consider that user really intends             // to drag it            if ( ofs >= MINIMAL_ROW_DRAG_OFS ||                 ofs <= -MINIMAL_ROW_DRAG_OFS )            {                // DBG::                //.wxPoint pos = event.mPos;                //wxPoint drg = mDragOrigin;                //int dif = event.mPos.x - mDragOrigin.x;                mDragStarted  = true;                mDecisionMode = false;                mDragOrigin   = pos;                PrepareForRowDrag();                return;            }            // this plugin "eats" all mouse input while item is dragged,            return;        }        cbRowInfo* pRow = GetFirstRow();        bool focusFound = false;        while( pRow )        {            if ( HitTestRowDragHint( pRow, pos ) )            {                CheckPrevItemInFocus( pRow, -1 );                SetMouseCapture( true );                focusFound = true;                mpRowInFocus          = pRow;                mCollapsedIconInFocus = -1;                break;            }            pRow = pRow->mpNext;        }        if ( !focusFound )        {            int hrCnt = GetHRowsCountForPane( event.mpPane );            for( int i = 0; i != hrCnt; ++i )            {                if ( HitTestCollapsedRowIcon( i, pos ) )                {                    CheckPrevItemInFocus( NULL, i );                    SetMouseCapture( true );                    focusFound = true;                    mCollapsedIconInFocus = i;                    mpRowInFocus          = NULL;                    break;                }            }        }        if ( !focusFound && ItemIsInFocus() )        {            // kill focus from item previously been in focus            UnhighlightItemInFocus();            mpRowInFocus          = NULL;            mCollapsedIconInFocus = -1;            SetMouseCapture( false );        }        if ( !ItemIsInFocus() )                 // delegate it to other plugins                event.Skip();    }    else    {        // otherwise mouse pointer moves, when dragging is started        if ( mpPane->IsHorizontal() )        {            // row is dragged up or down;            ShowDraggedRow( pos.y - mDragOrigin.y );        }        else        {            // row is dragged left or right            ShowDraggedRow( pos.x - mDragOrigin.x );        }        // this plugin "eats" all mouse input while item is dragged,    }}void cbRowDragPlugin::OnLButtonDown( cbLeftDownEvent& event ){    mpPane = event.mpPane;    // DBG::    wxASSERT( !mDragStarted && !mDecisionMode );    if ( ItemIsInFocus() )    {        mDecisionMode = true;        wxPoint pos = event.mPos;        mpPane->PaneToFrame( &pos.x, &pos.y );        mDragOrigin = pos;        SetMouseCapture( true );    }    else        // propagate event to other plugins        event.Skip();}void cbRowDragPlugin::OnLButtonUp  ( cbLeftUpEvent& event ){    if ( !mDragStarted && !mDecisionMode )     {        event.Skip();        return;    }    mpPane = event.mpPane;    if ( mDecisionMode )    {        cbDockPane* pPane = mpPane;        SetMouseCapture( false );        mDecisionMode = false;        mDragStarted  = false;        wxPoint frmPos = event.mPos;        pPane->PaneToFrame( &frmPos.x, &frmPos.y );        if ( mpRowInFocus )         {            CollapseRow( mpRowInFocus );            mpRowInFocus = 0;        }        else        {            ExpandRow( mCollapsedIconInFocus );            mCollapsedIconInFocus = -1;        }        mpRowInFocus  = NULL;        mpPane = pPane;        pPane->FrameToPane( &frmPos.x, &frmPos.y );        // give it another try after relayouting bars        cbMotionEvent moveEvt( frmPos, pPane );        this->OnMouseMove( moveEvt );        // this plugin has "eaten" the mouse-up event        return;    }    else    {        // otherwise, the dragged row was dropped, determine        // where to insert it        // restore initial pane appearence        ShowPaneImage();        FinishOnScreenDraw();        cbRowInfo* pRow = GetFirstRow();        mpLayout->GetUpdatesManager().OnStartChanges();        pRow->mUMgrData.SetDirty(true);        cbBarInfo* pBar = mpRowInFocus->mBars[0];        while ( pBar )        {            pBar->mUMgrData.SetDirty(true);            if ( pBar->mpBarWnd )            {                // do complete refresh                pBar->mpBarWnd->Show(false);                pBar->mpBarWnd->Show(true);            }            pBar = pBar->mpNext;        }        while( pRow )        {            if ( mCurDragOfs < pRow->mRowY )            {                InsertDraggedRowBefore( pRow );                break;            }            pRow = pRow->mpNext;        }        if ( pRow == NULL ) InsertDraggedRowBefore( NULL );        mpRowInFocus = NULL;        mpLayout->RecalcLayout(false);        // finish change "transaction"        mpLayout->GetUpdatesManager().OnFinishChanges();        mpLayout->GetUpdatesManager().UpdateNow();        // finish drag action        SetMouseCapture( false );        mDragStarted = false;    }}void cbRowDragPlugin::OnDrawPaneBackground ( cbDrawPaneDecorEvent& event ){    mpPane = event.mpPane;    // FIXME:: this may harm operation of other plugins    if ( GetNextHandler() && mpPane->GetRowList().GetCount() )    {        // first, let other plugins add their decorations now            GetNextHandler()->ProcessEvent( event );        event.Skip(false);    }    wxClientDC dc( &mpLayout->GetParentFrame() );    dc.SetClippingRegion( mpPane->mBoundsInParent.x,                          mpPane->mBoundsInParent.y,                          mpPane->mBoundsInParent.width,                          mpPane->mBoundsInParent.height );    int cnt = GetHRowsCountForPane( event.mpPane );    if ( cnt > 0 )         DrawCollapsedRowsBorder( dc );    if ( mpPane->GetRowList().GetCount() )            DrawRowsDragHintsBorder( dc );    cbRowInfo* pRow = GetFirstRow();    while( pRow )    {        DrawRowDragHint( pRow, dc, false );        pRow = pRow->mpNext;    }    for( int i = 0; i != cnt; ++i )        DrawCollapsedRowIcon(i, dc, false );}int cbRowDragPlugin::GetHRowsCountForPane( cbDockPane* pPane ){    wxNode* pNode = mHiddenBars.GetFirst();    int maxIconNo = -1;    while( pNode )    {        cbHiddenBarInfo* pHBInfo = (cbHiddenBarInfo*)pNode->GetData();        if ( pHBInfo->mAlignment == pPane->mAlignment )            maxIconNo = wxMax( maxIconNo, pHBInfo->mIconNo );        pNode = pNode->GetNext();    }    return ( maxIconNo + 1 );}int cbRowDragPlugin::GetCollapsedRowIconHeight(){    return COLLAPSED_ICON_HEIGHT;}int cbRowDragPlugin::GetRowDragHintWidth(){    return ROW_DRAG_HINT_WIDTH;}void cbRowDragPlugin::SetPaneMargins(){    int hiddenRowsCnt = GetHRowsCountForPane( mpPane );    if ( mSvTopMargin == -1 )    {        mSvTopMargin    = mpPane->mTopMargin;        mSvBottomMargin    = mpPane->mBottomMargin;        mSvLeftMargin   = mpPane->mLeftMargin;        mSvRightMargin  = mpPane->mRightMargin;    }    if ( mpPane->IsHorizontal() )    {        mpPane->mTopMargin    = mSvTopMargin;        mpPane->mBottomMargin = ( hiddenRowsCnt == 0 )                                 ?  mSvBottomMargin                                 :  mSvBottomMargin + GetCollapsedRowIconHeight();        mpPane->mLeftMargin   = mSvLeftMargin + GetRowDragHintWidth();        mpPane->mRightMargin  = mSvRightMargin;    }    else    {        mpPane->mTopMargin    = mSvTopMargin;        mpPane->mBottomMargin = mSvBottomMargin + GetRowDragHintWidth();        mpPane->mLeftMargin   = mSvLeftMargin;        mpPane->mRightMargin  = ( hiddenRowsCnt == 0 ) ?                                mSvRightMargin : mSvRightMargin + GetCollapsedRowIconHeight();    }}void cbRowDragPlugin::OnInitPlugin(){    cbDockPane** panes = mpLayout->GetPanesArray();    for( int i = 0; i != MAX_PANES; ++i )        if ( panes[i]->MatchesMask( mPaneMask ) )        {            mpPane = panes[i];            SetPaneMargins();        }

⌨️ 快捷键说明

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