📄 controlbar.cpp
字号:
cbDockPane::cbDockPane( int alignment, wxFrameLayout* pPanel )
: mLeftMargin ( 1 ),
mRightMargin ( 1 ),
mTopMargin ( 1 ),
mBottomMargin( 1 ),
mPaneWidth ( 32768 ), // fake-up very large pane dims,
// since the real dimensions of the pane may not
// be known, while inserting bars initially
mPaneHeight( 32768 ),
mAlignment ( alignment ),
mpLayout ( pPanel ),
mpStoredRow( NULL )
{}
cbDockPane::~cbDockPane()
{
size_t i;
for ( i = 0; i != mRows.Count(); ++i )
delete mRows[i];
WX_CLEAR_LIST(wxList,mRowShapeData)
// NOTE:: control bar infromation structures are cleaned-up
// in wxFrameLayout's destructor, using global control-bar list
}
void cbDockPane::SetMargins( int top, int bottom, int left, int right )
{
mTopMargin = top;
mBottomMargin = bottom;
mLeftMargin = left;
mRightMargin = right;
}
/*** helpers of cbDockPane ***/
void cbDockPane::PaintBarDecorations( cbBarInfo* pBar, wxDC& dc )
{
cbDrawBarDecorEvent evt( pBar, dc, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::PaintBarHandles( cbBarInfo* pBar, wxDC& dc )
{
cbDrawBarHandlesEvent evt( pBar, dc, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::PaintBar( cbBarInfo* pBar, wxDC& dc )
{
PaintBarDecorations( pBar, dc );
PaintBarHandles( pBar, dc );
}
void cbDockPane::PaintRowHandles( cbRowInfo* pRow, wxDC& dc )
{
cbDrawRowHandlesEvent evt( pRow, dc, this );
mpLayout->FirePluginEvent( evt );
cbDrawRowDecorEvent evt1( pRow, dc, this );
mpLayout->FirePluginEvent( evt1 );
}
void cbDockPane::PaintRowBackground ( cbRowInfo* pRow, wxDC& dc )
{
cbDrawRowBkGroundEvent evt( pRow, dc, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::PaintRowDecorations( cbRowInfo* pRow, wxDC& dc )
{
size_t i;
// decorations first
for ( i = 0; i != pRow->mBars.Count(); ++i )
PaintBarDecorations( pRow->mBars[i], dc );
// then handles if present
for ( i = 0; i != pRow->mBars.Count(); ++i )
PaintBarHandles( pRow->mBars[i], dc );
}
void cbDockPane::PaintRow( cbRowInfo* pRow, wxDC& dc )
{
PaintRowBackground ( pRow, dc );
PaintRowDecorations( pRow, dc );
PaintRowHandles ( pRow, dc );
}
void cbDockPane::PaintPaneBackground( wxDC& dc )
{
cbDrawPaneBkGroundEvent evt( dc, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::PaintPaneDecorations( wxDC& dc )
{
cbDrawPaneDecorEvent evt( dc, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::PaintPane( wxDC& dc )
{
size_t i;
PaintPaneBackground( dc );
// first decorations
for ( i = 0; i != mRows.Count(); ++i )
{
PaintRowBackground( mRows[i], dc );
PaintRowDecorations( mRows[i], dc );
}
// than handles
for ( i = 0; i != mRows.Count(); ++i )
PaintRowHandles( mRows[i], dc );
// and finally
PaintPaneDecorations( dc );
}
void cbDockPane::SizeBar( cbBarInfo* pBar )
{
cbSizeBarWndEvent evt( pBar, this );
mpLayout->FirePluginEvent( evt );
return;
}
void cbDockPane::SizeRowObjects( cbRowInfo* pRow )
{
size_t i;
for ( i = 0; i != pRow->mBars.Count(); ++i )
SizeBar( pRow->mBars[i] );
}
void cbDockPane::SizePaneObjects()
{
size_t i;
for ( i = 0; i != mRows.Count(); ++i )
SizeRowObjects( mRows[i] );
}
wxDC* cbDockPane::StartDrawInArea( const wxRect& area )
{
wxDC* pDc = 0;
cbStartDrawInAreaEvent evt( area, &pDc, this );
mpLayout->FirePluginEvent( evt );
return pDc;
}
void cbDockPane::FinishDrawInArea( const wxRect& area )
{
cbFinishDrawInAreaEvent evt( area, this );
mpLayout->FirePluginEvent( evt );
}
bool cbDockPane::IsFixedSize( cbBarInfo* pInfo )
{
return ( pInfo->mDimInfo.mIsFixed );
}
int cbDockPane::GetNotFixedBarsCount( cbRowInfo* pRow )
{
int cnt = 0;
size_t i;
for ( i = 0; i != pRow->mBars.Count(); ++i )
{
if ( !pRow->mBars[i]->IsFixed() )
++cnt;
}
return cnt;
}
void cbDockPane::RemoveBar( cbBarInfo* pBar )
{
bool needsRestoring = mProps.mNonDestructFrictionOn &&
mpStoredRow == pBar->mpRow;
cbRemoveBarEvent evt( pBar, this );
mpLayout->FirePluginEvent( evt );
if ( needsRestoring )
{
SetRowShapeData( mpStoredRow, &mRowShapeData );
mpStoredRow = NULL;
}
}
void cbDockPane::SyncRowFlags( cbRowInfo* pRow )
{
// setup mHasOnlyFixedBars flag for the row information
pRow->mHasOnlyFixedBars = true;
pRow->mNotFixedBarsCnt = 0;
size_t i;
for ( i = 0; i != pRow->mBars.Count(); ++i )
{
cbBarInfo& bar = *pRow->mBars[i];
bar.mpRow = pRow;
if ( !bar.IsFixed() )
{
pRow->mHasOnlyFixedBars = false;
++pRow->mNotFixedBarsCnt;
}
}
}
void cbDockPane::FrameToPane( int* x, int* y )
{
*x -= mLeftMargin;
*y -= mTopMargin;
if ( mAlignment == FL_ALIGN_TOP ||
mAlignment == FL_ALIGN_BOTTOM
)
{
*x -= mBoundsInParent.x;
*y -= mBoundsInParent.y;
}
else
{
int rx = *x, ry = *y;
*x = ry - mBoundsInParent.y;
*y = rx - mBoundsInParent.x;
}
}
void cbDockPane::PaneToFrame( int* x, int* y )
{
if ( mAlignment == FL_ALIGN_TOP ||
mAlignment == FL_ALIGN_BOTTOM
)
{
*x += mBoundsInParent.x;
*y += mBoundsInParent.y;
}
else
{
int rx = *x, ry = *y;
*x = ry + mBoundsInParent.x;
*y = mBoundsInParent.y + rx;
}
*x += mLeftMargin;
*y += mTopMargin;
}
void cbDockPane::FrameToPane( wxRect* pRect )
{
wxPoint upperLeft ( pRect->x, pRect->y );
wxPoint lowerRight( pRect->x + pRect->width,
pRect->y + pRect->height );
FrameToPane( &upperLeft.x, &upperLeft.y );
FrameToPane( &lowerRight.x, &lowerRight.y );
pRect->x = wxMin(upperLeft.x,lowerRight.x);
pRect->y = wxMin(upperLeft.y,lowerRight.y);
pRect->width = abs( lowerRight.x - upperLeft.x );
pRect->height = abs( lowerRight.y - upperLeft.y );
}
void cbDockPane::PaneToFrame( wxRect* pRect )
{
wxPoint upperLeft ( pRect->x, pRect->y );
wxPoint lowerRight( pRect->x + pRect->width,
pRect->y + pRect->height );
PaneToFrame( &upperLeft.x, &upperLeft.y );
PaneToFrame( &lowerRight.x, &lowerRight.y );
//wxRect newRect = wxRect( upperLeft, lowerRight );
pRect->x = wxMin(upperLeft.x,lowerRight.x);
pRect->y = wxMin(upperLeft.y,lowerRight.y);
pRect->width = abs( lowerRight.x - upperLeft.x );
pRect->height = abs( lowerRight.y - upperLeft.y );
}
int cbDockPane::GetRowAt( int paneY )
{
if ( paneY < 0 )
return -1;
int curY = 0;
size_t i = 0;
for ( ; i != mRows.Count(); ++i )
{
int rowHeight = mRows[i]->mRowHeight;
int third = rowHeight/3;
if ( paneY >= curY && paneY < curY + third )
return i-1;
if ( paneY >= curY + third && paneY < curY + rowHeight - third )
return i;
curY += rowHeight;
}
return i;
}
int cbDockPane::GetRowAt( int upperY, int lowerY )
{
/*
// OLD STUFF::
int range = lowerY - upperY;
int oneThird = range / 3;
wxNode* pRow = mRows.GetFirst();
int row = 0;
int curY = 0;
if ( lowerY <= 0 ) return -1;
while( pRow )
{
int rowHeight = GetRowHeight( (wxList*)pRow->GetData() );
if ( upperY >= curY &&
lowerY < curY ) return row;
if ( upperY <= curY &&
lowerY >= curY &&
curY - upperY >= oneThird ) return row-1;
if ( ( upperY < curY + rowHeight &&
lowerY >= curY + rowHeight &&
curY + rowHeight - lowerY >= oneThird )
)
return row+1;
if ( lowerY <= curY + rowHeight ) return row;
++row;
curY += rowHeight;
pRow = pRow->GetNext();
}
*/
int mid = upperY + (lowerY - upperY)/2;
if ( mid < 0 )
return -1;
int curY = 0;
size_t i = 0;
for ( ; i != mRows.Count(); ++i )
{
int rowHeight = mRows[i]->mRowHeight;
if ( mid >= curY && mid < curY + rowHeight ) return i;
curY += rowHeight;
}
return i;
}
int cbDockPane::GetRowY( cbRowInfo* pRow )
{
int curY = 0;
size_t i;
for ( i = 0; i != mRows.Count(); ++i )
{
if ( mRows[i] == pRow )
break;
curY += mRows[i]->mRowHeight;
}
return curY;
}
bool cbDockPane::HasNotFixedRowsAbove( cbRowInfo* pRow )
{
while ( pRow->mpPrev )
{
pRow = pRow->mpPrev;
if ( pRow->mHasOnlyFixedBars )
return true;
}
return false;
}
bool cbDockPane::HasNotFixedRowsBelow( cbRowInfo* pRow )
{
while( pRow->mpNext )
{
pRow = pRow->mpNext;
if ( pRow->mHasOnlyFixedBars )
return true;
}
return false;
}
bool cbDockPane::HasNotFixedBarsLeft( cbBarInfo* pBar )
{
while( pBar->mpPrev )
{
pBar = pBar->mpPrev;
if ( pBar->IsFixed() )
return true;
}
return false;
}
bool cbDockPane::HasNotFixedBarsRight( cbBarInfo* pBar )
{
while( pBar->mpNext )
{
pBar = pBar->mpNext;
if ( pBar->IsFixed() )
return true;
}
return false;
}
void cbDockPane::CalcLengthRatios( cbRowInfo* pInRow )
{
size_t i;
int totalWidth = 0;
// calc current-maximal-total-length of all maximized bars
for ( i = 0; i != pInRow->mBars.GetCount(); ++i )
{
cbBarInfo& bar = *pInRow->mBars[i];
if ( !bar.IsFixed() )
totalWidth += bar.mBounds.width;
}
// set up percentages of occupied space for each maximized bar
for ( i = 0; i != pInRow->mBars.Count(); ++i )
{
cbBarInfo& bar = *pInRow->mBars[i];
if ( !bar.IsFixed() )
bar.mLenRatio = double(bar.mBounds.width)/double(totalWidth);
}
}
void cbDockPane::RecalcRowLayout( cbRowInfo* pRow )
{
cbLayoutRowEvent evt( pRow, this );
mpLayout->FirePluginEvent( evt );
}
void cbDockPane::ExpandBar( cbBarInfo* pBar )
{
mpLayout->GetUpdatesManager().OnStartChanges();
if ( !pBar->mpRow->mpExpandedBar )
{
// save ratios only when there arent any bars expanded yet
cbArrayFloat& ratios = pBar->mpRow->mSavedRatios;
ratios.Clear();
ratios.Alloc( pBar->mpRow->mNotFixedBarsCnt );
cbBarInfo* pCur = pBar->mpRow->mBars[0];
while( pCur )
{
if ( !pCur->IsFixed() )
{
ratios.Add( 0.0 );
ratios[ ratios.GetCount() - 1 ] = pCur->mLenRatio;
}
pCur = pCur->mpNext;
}
}
cbBarInfo* pCur = pBar->mpRow->mBars[0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -