📄 gtwin.cpp
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <limits.h>
#include "assure.h"
#include "browse.h"
#include "busyntc.h"
#include "dtview.h"
#include "gtrootpk.h"
#include "gtwin.h"
#include "icons.h"
#include "menuids.h"
#include "screendv.h"
#include "viewmgr.h"
#include "util.h"
#include "keysym.h"
#include "querycfg.h"
const sibSep = 10;
// FIXME --- has too many invalidates due to paranoia
TreeWindow::TreeWindow( char * title, WStyle stl )
: WBRWindow( title, stl )
, GlobalViewTree( menuManager() )
, _rootsLoaded( FALSE )
, _empty( FALSE )
, _xOffset( 0 )
, _yOffset( 0 )
, _currNode( NULL )
, _findRoot( -1 )
, _findNode( -1 )
, _hScrollFactor( 0 )
, _vScrollFactor( 0 )
//----------------------------------------------------------
{
GUIWantPartialRows( handle(), TRUE );
setIcon( GBTree );
_direction = optManager()->getTreeDirection();
_edgeType = optManager()->getEdgeType();
_autoArrange = optManager()->getTreeAutoArrange();
_queryConfig = new QueryConfig( this, "Find" );
_loadFilter = new KeySymbol( optManager()->getQueryFilt() );
_findFilter = new KeySymbol;
menuManager()->trackPopup( this, MMTree );
viewManager()->registerForEvents( this );
}
TreeWindow::~TreeWindow()
//-----------------------
{
for( int i = _roots.count(); i > 0; i -= 1 ) {
delete _roots[ i - 1 ];
}
delete _queryConfig;
delete _loadFilter;
delete _findFilter;
}
bool TreeWindow::reallyClose()
//----------------------------
{
viewManager()->viewDying( this );
return TRUE;
}
bool TreeWindow::gettingFocus( WWindow * )
//----------------------------------------
{
viewManager()->eventOccured( VEGettingFocus, this );
return FALSE;
}
bool TreeWindow::losingFocus( WWindow * )
//---------------------------------------
{
viewManager()->eventOccured( VELosingFocus, this );
return FALSE;
}
void TreeWindow::resized( WOrdinal w, WOrdinal h )
//------------------------------------------------
{
resetScrollRange();
WWindow::resized( w, h );
}
void TreeWindow::event( ViewEvent ve, View * )
//--------------------------------------------
{
switch( ve ) {
case VEOptionValChange:
if( _edgeType != optManager()->getEdgeType() ) {
toggleEdges();
}
if( _autoArrange != optManager()->getTreeAutoArrange() ) {
toggleAutoArrange();
}
if( _direction != optManager()->getTreeDirection() ) {
changeDirection();
}
invalidate();
break;
case VEQueryFiltChange:
query();
break;
case VEBrowseFileChange:
reLoad();
break;
default:
NODEFAULT;
}
}
ViewEvent TreeWindow::wantEvents()
//--------------------------------
{
return VEQueryFiltChange | VEBrowseFileChange | VEOptionValChange;
}
static MIMenuID TreeMenus[] = {
MIMenuID( MMLocate, LMFind ),
MIMenuID( MMLocate, LMFindNext ),
#ifdef DEBUGTREE
MIMenuID( MMTree, TMDebugInfo ),
MIMenuID( MMTree, TMSibWidth ),
#endif
};
#define NumTreeMenus (sizeof(TreeMenus) / sizeof(MIMenuID) )
void TreeWindow::setMenus( MenuManager * mgr )
//--------------------------------------------
{
int i;
for( i = 0; i < NumTreeMenus; i += 1 ) {
mgr->registerForMenu( this, TreeMenus[ i ] );
}
menuManager()->enableMenu( MIMenuID(MMLocate,LMFindNext), FALSE );
GlobalViewTree::setMenus( mgr );
// NYI changed( NULL ); // disable menus
}
void TreeWindow::unsetMenus( MenuManager * mgr )
//----------------------------------------------
{
int i;
for( i = 0; i < NumTreeMenus; i += 1 ) {
mgr->unRegister( TreeMenus[ i ] );
}
GlobalViewTree::unsetMenus( mgr );
}
void TreeWindow::menuSelected( const MIMenuID & id )
//--------------------------------------------------
{
switch( id.mainID() ) {
case MMLocate:
switch( id.subID() ) {
case LMFind:
findFirst();
break;
case LMFindNext:
findNext();
break;
case LMFindSelected:
treeViewEvent( ScrollToSelected );
break;
default:
NODEFAULT;
}
break;
#ifdef DEBUGTREE
case MMTree:
switch( id.subID() ) {
case TMDebugInfo:
showDebug();
break;
case TMSibWidth:
showSib();
break;
default:
GlobalViewTree::menuSelected( id );
}
break;
#endif
default:
GlobalViewTree::menuSelected( id );
}
}
void TreeWindow::treeViewEvent( TreeViewEvent tve )
//-------------------------------------------------
{
WRect rect;
int i;
switch( tve ) {
case ShowDetail:
showDetail();
break;
case ShowDefinition:
showDefinition();
break;
case ShowReferences:
showReferences();
break;
case ShowUsers:
showUsers();
break;
case ScrollToSelected:
if( _currNode ) {
getClientRect( rect );
scrollToNode( _currNode, rect );
invalidate();
}
break;
case Arrange:
arrangeAllSelectRoots();
break;
case SelectRoots:
selectRoots();
break;
case ExpandOne:
if( _currNode ) {
_currNode->setEnable( TreeNode::Visible );
for( i = _currNode->getCount( TreeNode::ChildList ); i > 0; i -= 1 ) {
TreeNode * node;
node = _currNode->getNode( TreeNode::ChildList, i - 1 );
node->setEnable( TreeNode::Visible );
}
arrangeAll();
}
break;
case ExpandBranch:
if( _currNode ) {
_currNode->enableKids( TRUE );
arrangeAll();
}
break;
case ExpandAll:
enableAll();
arrangeAll();
break;
case CollapseBranch:
if( _currNode ) {
_currNode->enableKids( FALSE );
// enableKids affects node itself so enable the current node
// _currNode->setEnable( TreeNode::Visible );
if( _autoArrange ) {
arrangeAll();
} else {
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->sortEdges();
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
}
}
break;
case CollapseAll:
enableAll( FALSE );
scrollTo( 0, 0 );
arrangeAll();
break;
}
}
TreeWindow::ExpandState TreeWindow::state()
//-----------------------------------------
{
if( _currNode ) {
int count = _currNode->getCount( TreeNode::ChildList );
if( count == 0 ) {
return Leaf;
} else {
for( int i = 0; i < count; i += 1 ) {
if( _currNode->getNode( TreeNode::ChildList, i )->getEnable() == TreeNode::Hidden ) {
return Collapsed;
}
}
return Expanded;
}
} else {
return NoSymbol;
}
}
void TreeWindow::selectRoots()
//----------------------------
// select which trees to display, which to hide
{
TreeRootSelect rootSel( this, &_roots );
if( rootSel.process() ) { // ie OK selected
scrollTo( 0, 0 );
arrangeAllSelectRoots();
}
}
void TreeWindow::showDetail()
//---------------------------
{
if( _currNode ) {
Symbol * sym = _currNode->makeSymbol();
popDetail( sym );
delete sym;
}
}
void TreeWindow::showDefinition()
//-------------------------------
{
if( _currNode ) {
Symbol * sym = _currNode->makeSymbol();
browseTop->showSource( sym );
delete sym;
}
}
void TreeWindow::showReferences()
//-------------------------------
{
if( _currNode ) {
Symbol * sym = _currNode->makeSymbol();
viewManager()->showDetailView( sym, DetailView::ViewSourceRefs );
delete sym;
}
}
void TreeWindow::showUsers()
//--------------------------
{
if( _currNode ) {
Symbol * sym = _currNode->makeSymbol();
viewManager()->showDetailView( sym, DetailView::ViewSymbolRefs );
delete sym;
}
}
#if 0 // dead expand / collapse stuff
/*
* show active node (called from main menu only)
*/
void TreeWindow::showNode()
//-------------------------
// DEAD
{
if( _currNode ) {
_currNode->setEnable( TreeNode::Visible );
arrangeAll();
}
}
/*
* hide this node
*/
void TreeWindow::hideNode()
//-------------------------
// DEAD
{
if( _currNode ) {
_currNode->setEnable( TreeNode::Hidden );
_currNode = NULL;
if( _autoArrange ) {
arrangeAll();
} else {
for( int i = _roots.count(); i > 0; i -= 1 ) {
_roots[ i - 1 ]->sortEdges();
_roots[ i - 1 ]->needsUpdating();
}
invalidate();
}
}
}
/*
* show all of a nodes parents
*/
void TreeWindow::showParents()
//----------------------------
// DEAD
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -