📄 gtwin.cpp
字号:
bool TreeWindow::getSmartEdges() const
//------------------------------------
{
return( _edgeType == EdgesSquare );
}
void TreeWindow::enableAll( bool enable, bool rePlace )
//-----------------------------------------------------
{
for( int i = _roots.count(); i > 0; i -= 1 ) {
if( _roots[ i - 1 ]->enabled() ) {
for( int j = _roots[ i - 1 ]->node()->getCount( TreeNode::FlatList ); j > 0; j -= 1 ) {
TreeNode * node;
node = _roots[ i - 1 ]->node()->getNode( TreeNode::FlatList, j - 1 );
if( enable ) {
node->setEnable( TreeNode::Visible );
} else {
if( node != _roots[ i - 1 ]->node() ) {
node->setEnable( TreeNode::Hidden );
}
}
if( rePlace ) {
node->rePlace();
}
}
}
}
}
void TreeWindow::rePlaceAll()
//---------------------------
{
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->rePlaceAll();
}
}
bool TreeWindow::scrollNotify( WScrollNotification sn, int diff )
//---------------------------------------------------------------
{
TreeCoord xDiff = 0;
TreeCoord yDiff = 0;
TreeCoord maxY;
TreeCoord maxX;
WRect r;
getClientRect( r );
maxY = _world.h() - r.h();
maxX = _world.w() - r.w();
switch( sn ) {
case WScrollUp:
yDiff = -_vScrollFactor;
break;
case WScrollPageUp:
yDiff = -r.h();
break;
case WScrollDown:
yDiff = _vScrollFactor;
break;
case WScrollPageDown:
yDiff = r.h();
break;
case WScrollBottom:
yDiff = _world.h() - r.h();
break;
case WScrollTop:
yDiff = -getYOff();
break;
case WScrollVertical:
yDiff = diff * _vScrollFactor;
break;
case WScrollLeft:
xDiff = -_hScrollFactor;
break;
case WScrollPageLeft:
xDiff = -r.w();
break;
case WScrollRight:
xDiff = _hScrollFactor;
break;
case WScrollPageRight:
xDiff = r.w();
break;
case WScrollFullRight:
xDiff = _world.w() - r.w();
break;
case WScrollFullLeft:
xDiff = -getXOff();
break;
case WScrollHorizontal:
xDiff = diff * _hScrollFactor;
break;
default:
return FALSE;
}
scrollTo( getXOff() + xDiff, getYOff() + yDiff );
return TRUE;
}
TreeCoord TreeWindow::getXOff() const
//-----------------------------------
{
return _xOffset * _hScrollFactor;
}
TreeCoord TreeWindow::getYOff() const
//-----------------------------------
{
return _yOffset * _vScrollFactor;
}
void TreeWindow::resetScrollRange()
//---------------------------------
// set the scroll range
{
WPoint avgChar;
WPoint maxChar;
WRect r;
int range;
TreeCoord newX;
TreeCoord newY;
getClientRect( r );
textMetrics( avgChar, maxChar );
_hScrollColMult = (int) (_world.w() / SHRT_MAX + 1);
_vScrollRowMult = (int) (_world.h() / SHRT_MAX + 1);
_vScrollFactor = _vScrollRowMult * maxChar.y();
_hScrollFactor = _hScrollColMult * avgChar.x();
if( _empty ) {
setScrollRange( WScrollBarVertical, 0 );
setScrollRange( WScrollBarHorizontal, 0 );
scrollTo( 0, 0 );
} else {
range = (int) (_world.h() / _vScrollFactor + 3);
range += (int) ((_vScrollRowMult - 1) * r.h() / _vScrollFactor);
if( range > r.h() / _vScrollFactor ) {
setScrollTextRange( WScrollBarVertical, range );
newY = minCoord( _yOffset, range );
newY = maxCoord( newY, 0 );
} else {
setScrollTextRange( WScrollBarVertical, 0 );
newY = 0;
}
range = (int) (_world.w() / _hScrollFactor + 3);
range += (int) ((_hScrollColMult - 1) * r.w() / _hScrollFactor);
if( range > r.w() / _hScrollFactor ) {
setScrollTextRange( WScrollBarHorizontal, range );
newX = minCoord( _xOffset, range );
newX = maxCoord( newX, 0 );
} else {
setScrollTextRange( WScrollBarHorizontal, 0 );
newX = 0;
}
if( _xOffset != newX || _yOffset != newY ) {
_xOffset = newX;
_yOffset = newY;
GUIInitHScrollCol( handle(), (int)_xOffset );
GUIInitVScrollRow( handle(), (int)_yOffset );
invalidate();
}
}
}
void TreeWindow::scrollTo( TreeCoord x, TreeCoord y )
//---------------------------------------------------
// scroll the physical screen so the top left corner
// is roughly at x,y on the virtual screen
{
TreeCoord nx;
TreeCoord ny;
int diff;
WRect r;
WPoint avgChar;
WPoint maxChar;
textMetrics( avgChar, maxChar );
getClientRect( r );
nx = x / _hScrollFactor;
nx = minCoord( nx, getScrollTextRange( WScrollBarHorizontal ) );
nx = maxCoord( nx, 0 );
diff = (int) (nx - _xOffset);
GUIInitHScrollCol( handle(), nx );
if( nx != _xOffset ) {
_xOffset = nx;
if( maxCoord( diff*_hScrollFactor, -diff*_hScrollFactor ) < r.w() ) {
scrollWindow( WScrollBarHorizontal, diff * _hScrollColMult );
} else {
invalidate();
}
}
ny = y / _vScrollFactor;
ny = minCoord( ny, getScrollTextRange( WScrollBarVertical ) );
ny = maxCoord( ny, 0 );
diff = (int) (ny - _yOffset);
GUIInitVScrollRow( handle(), ny );
if( ny != _yOffset ) {
_yOffset = ny;
if( maxCoord( diff*_vScrollFactor, -diff*_vScrollFactor ) < r.h() ) {
scrollWindow( WScrollBarVertical, diff * _vScrollRowMult );
} else {
invalidate();
}
}
invalidateRow( getRows() );
}
void TreeWindow::scrollToNode( TreeNode * node, WRect & rect )
//------------------------------------------------------------
// Scroll the window so that node is visible and roughly centred.
//
// node -- ptr to the node we want to scroll to
// rect -- the dimensions of the window; we're interested in width and
// height only
{
if( node == NULL ) return;
TreeRect rootRect;
TreeRect nodeRect;
TreeCoord nx;
TreeCoord ny;
node->myRect( nodeRect );
node->getRootPtr()->getBound( rootRect );
if( getDirection() == TreeVertical ) {
if( rootRect.h() < nodeRect.y() + rect.h() / 2 ) {
ny = ( rootRect.h() - rect.h() );
} else {
ny = ( nodeRect.y() - rect.h() / 2 );
}
nx = ( nodeRect.x() - rect.w() / 2 );
} else {
ny = ( nodeRect.y() - rect.h() / 2 );
if( rootRect.w() < nodeRect.x() + rect.w() / 2 ) {
nx = ( rootRect.w() - rect.w() );
} else {
nx = ( nodeRect.x() - rect.w() / 2 );
}
}
scrollTo( nx, ny );
}
TreeNode* TreeWindow::hitTest( int x, int y )
//-------------------------------------------
{
TreeCoord newx = x + getXOff();
TreeCoord newy = y + getYOff();
return TreeRoot::hitTest( _roots, newx, newy );
}
bool TreeWindow::leftBttnDn( int x, int y, WMouseKeyFlags )
//---------------------------------------------------------
{
TreeNode * node = hitTest( x, y );
if( node != NULL ) {
giveFocusToNode( node );
selChange();
}
return (node != NULL);
}
bool TreeWindow::leftBttnDbl( int x, int y, WMouseKeyFlags )
//----------------------------------------------------------
{
TreeNode * node = hitTest( x, y );
if( node != NULL ) {
if( _currNode != node ) {
giveFocusToNode( node );
} else {
showDetail();
}
return TRUE;
}
return FALSE;
}
bool TreeWindow::rightBttnDn( int x, int y, WMouseKeyFlags )
//----------------------------------------------------------
{
TreeNode * node = hitTest( x, y );
if( node != NULL ) {
giveFocusToNode( node );
selChange();
}
return FALSE;
}
void TreeWindow::giveFocusToNode( TreeNode * pNode )
//--------------------------------------------------
// Takes the focus away from the current node and gives it
// to the new node.
//
// pNode -- pointer to the tree node which is getting the focus
//
{
if( pNode == NULL ) {
return;
}
if( _currNode != NULL ) {
_currNode->losingFocus( this );
}
_currNode = pNode;
_currNode->gettingFocus( this );
selChange();
}
void TreeWindow::query()
//----------------------
{
delete _loadFilter;
_loadFilter = new KeySymbol( optManager()->getQueryFilt() );
reLoad();
}
void TreeWindow::findFirst()
//--------------------------
{
if( _queryConfig->editFilter( _findFilter ) ) {
_findRoot = 0;
_findNode = -1;
findNext();
}
}
void TreeWindow::findNext()
//-------------------------
{
ASSERTION( _findRoot >= 0 );
TreeNode * node;
int i = _findNode + 1;
bool found = FALSE;
WRect rect;
BusyNotice busy( "Searching..." );
for( ; _findRoot < _roots.count(); ++_findRoot ) {
TreeRoot * root = _roots[ _findRoot ];
for( ; i < root->node()->getCount( TreeNode::FlatList ); ++i ) {
if( matches( _findRoot, i, _findFilter ) ) {
_findNode = i;
found = TRUE;
break;
}
}
if( found ) {
break;
} else {
i = 0; // start at the top of the next tree
}
}
if( !found ) {
if( _findNode == -1 ) {
errMessage( "No matching symbols" ); // FIXME-- not an error
} else {
errMessage( "End of matching symbols" ); // FIXME-- not an error
}
_findRoot = -1;
_findNode = -1;
menuManager()->enableMenu( MIMenuID(MMLocate,LMFindNext), FALSE );
} else {
node = _roots[_findRoot]->node()->getNode( TreeNode::FlatList, _findNode );
node->enableParents( TRUE );
arrangeAll();
giveFocusToNode( node );
getClientRect( rect );
scrollToNode( node, rect );
menuManager()->enableMenu( MIMenuID(MMLocate,LMFindNext), TRUE );
}
}
bool TreeWindow::matches( int r, int n, KeySymbol * filt )
//--------------------------------------------------------
{
TreeRoot * root = _roots[ r ];
TreeNode * node;
node = root->node()->getNode( TreeNode::FlatList, n );
return filt->matches( node->getHandle(), node->name() );
}
void TreeWindow::reLoad()
//-----------------------
{
int i;
for( i = 0; i < _roots.count(); i += 1 ) {
delete _roots[ i ];
}
_roots.reset();
_currNode = NULL;
_findRoot = -1;
_findNode = -1;
_rootsLoaded = FALSE;
_xOffset = 0;
_yOffset = 0;
invalidate(); // causes a paint, re-loads using _loadFilter
resetScrollRange();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -