strcview.cpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 642 行 · 第 1/2 页

CPP
642
字号
/****************************************************************************
*
*                            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 <wtext.hpp>
#include <wstring.hpp>
#include <wpshbttn.hpp>
#include <drsrchdf.h>
#include "mem.h"
#include "verblist.h"
#include "strcview.h"
#include "assure.h"
#include "descrip.h"
#include "methfilt.h"
#include "classtyp.h"
#include "varsym.h"
#include "classlat.h"
#include "projmodl.h"

const short StrucWidth = 200;
const short StrucHeight = 208;

StrucView::StrucView()
    : WBRWindow( WRect(0,0,0,0), "" )
    , _listbox(NULL)
    , _listobjs(NULL)
    , _type(NULL)
    , _lattice(NULL)
//--------------------
{
}

StrucView::StrucView( int x, int y, Symbol * info )
    :WBRWindow( WRect(x,y,StrucWidth,StrucHeight), "" )
    ,_listbox( new VerboseListBox( WRect( 5, 30, -5, -25 ), this ))
    ,_listobjs( new WVList )
    ,_type( new WText( this, WRect( 5, -20, -5, -2 ), NULL,
                       TextStyleLeftNoWrap | TextStyleAmpersands ))
    ,_treeRoot(NULL)
    ,_nodesSeen( new WVList )
    ,_lattice( new ClassLattice( info ) )
    ,_filter( activeProject->getFiltFlags( Filt_Members ))
//-------------------------------------------------------------------
{
    WString title = info->name();
    Symbol * sym;

    title.concat( " Structure" );
    setText( title );

    _listbox->setCallbacks( this, (cbw)&StrucView::itemSelected,
                        (bcbwi)&StrucView::keyPressed,
                        (cbw)&StrucView::itemDblClicked );
//  _listbox->setFont(stdFont);
    _listbox->select( 0 );
    _listbox->show();
//  _type->setFont(stdFont);
    _type->show();

    WPushButton * bttn;
    bttn = new WPushButton( this, WRect( 5, 2, 25, 25 ), "+" );
    bttn->onClick( this, (cbw) plusSelected );
    bttn->show();

    bttn = new WPushButton( this, WRect( 40, 2, 25, 25 ), "-" );
    bttn->onClick( this, (cbw) minusSelected );
    bttn->show();

    bttn = new WPushButton( this, WRect( 75, 2, 25, 25 ), "*" );
    bttn->onClick( this, (cbw) starSelected );
    bttn->show();

    bttn = new WPushButton( this, WRect( -70, 2, 65, 25 ), "&Filters..." );
    bttn->onClick( this, (cbw) filterSelected );
    bttn->show();

    sym = Symbol::defineSymbol( info );
    _treeRoot = new StrucViewItem( this, sym );
    reset();

    _listbox->setFocus();
    show();
}

StrucView::~StrucView()
//---------------------
{
    //NYI -- DetailView ViewCreator::viewDying( CreateStructView, this );
    delete _treeRoot;
    delete _listobjs;
    delete _nodesSeen;
    _lattice->deleteLattice();
}

static WBRWindow * StrucView::createView( int x, int y, Symbol * info )
//----------------------------------------------------------------------
{
    return new StrucView( x, y, info );
}

bool StrucView::isEqual( WObject * sym ) {
    return _treeRoot->isEqual( sym );
}

void StrucView::reset()
//---------------------
{
    _listbox->reset();
    _listobjs->reset();
    _nodesSeen->reset();
    _treeRoot->reset();

    char * tmpstr = _treeRoot->name();
    _listbox->insertString( tmpstr, 0 );
    delete tmpstr;

    _listobjs->insertAt( 0, _treeRoot );

    int tmp = 0;
    _treeRoot->collapseNode( tmp );
    tmp = 0;
    _treeRoot->expandNode( tmp );

    _type->setText( _treeRoot->typeStr() );

    _listbox->select(0);
}

void StrucView::filterSelected( WWindow * )
//-----------------------------------------
{
    MethodFilter filt( 150, 150, FALSE);

    if( filt.process() ) {
        _filter = filt.getCurrentFlags();
        reset();
    }
}

void StrucView::addSeen( StrucViewItem * item )
//---------------------------------------------
{
    _nodesSeen->add( item );
}

bool StrucView::isSeen( Symbol * sym )
//------------------------------------
{
    bool ret = FALSE;
    if( _nodesSeen->find( sym ) ) {
        ret = TRUE;
    }
    return ret;
}

bool StrucView::setMinimumSize( short *w, short *h )
//--------------------------------------------------
{
    *w = StrucWidth;
    *h = StrucHeight;
    return TRUE;
}

void StrucView::itemSelected( WWindow *)
//--------------------------------------
{
    int index = _listbox->selected();
    StrucViewItem * item = (StrucViewItem *)(*_listobjs)[ index ];
    if (item) {
        _type->setText( item->typeStr() );
    }
}

int StrucView::keyPressed( WWindow *, int key )
//---------------------------------------------
{
    if( key == WKeyPlus || key == WKeyMinus || key == WKeyAsterisk ){
        switch( (WKeyCode) key ) {
        case WKeyPlus:
            plusSelected( this );
            break;
        case WKeyAsterisk:
            starSelected( this );
            break;
        case WKeyMinus:
            minusSelected( this );
            break;
        default:
            REQUIRE( 0, "strcview -- keypressed with bad key!" );
        }
        return TRUE;
    } else {
        return FALSE;
    }
}

void StrucView::plusSelected( WWindow * )
//---------------------------------------
{
    int index = _listbox->selected();
    int curr = index;
    StrucViewItem * item = (StrucViewItem *) (*_listobjs)[ index ];
    REQUIRE( item != NULL, "plusSelected -- no object selected!" );

    _type->setText( item->typeStr() );

    item->expandNode( index );
}

void StrucView::minusSelected( WWindow * )
//----------------------------------------
{
    int index = _listbox->selected();
    int curr = index;
    StrucViewItem * item = (StrucViewItem *) (*_listobjs)[ index ];
    REQUIRE( item != NULL, "plusSelected -- no object selected!" );

    _type->setText( item->typeStr() );

    if( item->state() == Expanded ) {
        item->collapseNode( index );
        char * tmp = item->name();
        _listobjs->insertAt( index, item );
        _listbox->insertString( tmp, index );
        delete tmp;
        _listbox->select( curr );
    }
}

void StrucView::starSelected( WWindow * )
//---------------------------------------
{
    int index = _listbox->selected();
    int curr = index;
    StrucViewItem * item = (StrucViewItem *) (*_listobjs)[ index ];
    REQUIRE( item != NULL, "starSelected -- no object selected!" );

    _type->setText( item->typeStr() );

    if( item->state() != LeafNode ){
        item->expandAllNode( index );
        _listbox->select( curr );
    }
}

void StrucView::itemDblClicked( WWindow * )
//-----------------------------------------
{
    int index = _listbox->selected();
    if (_treeRoot) {
        StrucViewItem * item = (StrucViewItem *) (*_listobjs)[ index ];
        if( item ) {
            popDetail( item->info() );
        }
    }
}

//////////////////////////StrucViewItem////////////////////////////////

StrucViewItem::StrucViewItem( StrucView * parent, Symbol * strucInfo,
                              uchar indent )
    :_initialized(FALSE)
    ,_expandState(LeafNode)
    ,_info(strucInfo)
    ,_indentLevel(indent)
    ,_parent(parent)
    ,_classNode(NULL)
{
}

StrucViewItem::StrucViewItem( StrucView * parent, ClassLattice * node,
                              uchar indent )
    :_initialized(FALSE)
    ,_expandState(LeafNode)
    ,_info(node->makeSymbol())
    ,_indentLevel(indent)
    ,_parent(parent)
    ,_classNode(node)
{
}

bool StrucViewItem::isEqual( WObject * sym ) {
    return _info->isEqual( sym );
}

StrucViewItem::~StrucViewItem()
{
    delete _info;
    _kids.deleteContents();
}

char * StrucViewItem::name( void )
//--------------------------------

⌨️ 快捷键说明

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