hotlist.cpp

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

CPP
561
字号
/****************************************************************************
*
*                            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>     // NYI -- only for scroll bandage
#include <whotspot.hpp>
#include <wkeydefs.hpp>

#include "hotspots.h"
#include "hotlist.h"
#include "wbrdefs.h"

HotControlList::HotControlList( WWindow * prt, const WRect & r, WStyle stl )
                : WWindow( prt, r, NULL, stl )
                , HotSpotList( this, FALSE )
//--------------------------------------------------------------------------
{
}

bool HotControlList::losingFocus( WWindow * )
//-------------------------------------------
{
    if( _selectedAttr != WPaintAttrMenuActive ) {
        _selectedAttr = WPaintAttrMenuActive;
        _win->invalidateRow( _selected - _topIndex );
    }
    return( FALSE );
}

bool HotControlList::gettingFocus( WWindow * )
//--------------------------------------------
{
    if( _selectedAttr != WPaintAttrIcon ) {
        _selectedAttr = WPaintAttrIcon;
        _win->invalidateRow( _selected - _topIndex );
    }
    return( FALSE );
}

HotWindowList::HotWindowList( const char * text, bool inf, WStyle stl )
                : WBRWindow( text, stl )
                , HotSpotList( this, inf )
//---------------------------------------------------------------------------
{
}

void HotWindowList::resized( WOrdinal w, WOrdinal h )
//---------------------------------------------------
{
    reset();
    WWindow::resized( w, h );
}

// HotSpotList has semantics for derived classes which are infinite
// or non-infinite.
//
// Non-infinite derived classes have a count() member
// function which is always valid, and they never return NULL from
// getString.
//
// Infinite lists have a member full() which returns true only when
// the list has been filled completely -- at this point, count() is
// valid.  If a string outside the range is requested, NULL is returned
//

HotSpotList::HotSpotList( WWindow * win, bool infinite )
                : _win( win )
                , _topIndex( 0 )
                , _selected( 0 )
                , _selectedAttr( WPaintAttrIcon )
                , _leftDown( FALSE )
                , _hotPressIdx( -1 )
                , _inHotZone( FALSE )
                , _infinite( infinite )
                , _width( 0 )
                , _changedClient( NULL )
                , _changed( NULL )
                , _dblClickClient( NULL )
                , _dblClick( NULL )
                , _hotPressClient( NULL )
                , _hotPress( NULL )
//--------------------------------------------------------------
{
}

HotSpotList::~HotSpotList()
//-------------------------
{
}

bool HotSpotList::HLPaint()
//-------------------------
{
    int             maxRows = _win->numDirtyRows() + _topIndex + _win->firstDirtyRow();
    int             numElem = _infinite ? 0 : count();
    int             offset;
    int             hotSpot;
    WPoint          hotSize;
    int             maxExtent( _width );

    for( long i = _topIndex + _win->firstDirtyRow(); i < maxRows; i += 1 ) {
        const char * str;
        int          extent;

        if( !_infinite && i >= numElem ) break;
        str = getString( i );
        if( str == NULL ) break;

        if( i == _hotPressIdx && _inHotZone ) {
            hotSpot = getHotSpot( i, TRUE );
        } else {
            hotSpot = getHotSpot( i, FALSE );
        }

        GlobalHotSpots->hotSpotSize( hotSpot, hotSize );
        offset = getHotOffset( i ) + hotSize.x();

        _win->drawHotSpot( hotSpot, i - _topIndex, getHotOffset( i ) );

        extent = _win->getTextExtentX( str ) + offset;

        maxExtent = maxInt( maxExtent, extent );

        if( i == _selected ) {
            _win->drawTextExtent( i - _topIndex, offset, str, _selectedAttr, maxExtent );
        } else {
            _win->drawTextExtent( i - _topIndex, offset, str, WPaintAttrBackground, maxExtent );
        }
    }

    if( maxExtent != _width ) {
        _width = maxExtent;
        _win->setScrollRange( WScrollBarHorizontal, _width );
    }

    return TRUE;
}

bool HotSpotList::HLMouseMove( int x, int y )
//-------------------------------------------
{
    if( _leftDown ) {
        int         row = _win->getRow( WPoint( x, y ) );
        int         oldSel = _selected;
        WPoint      hotSize;
        int         hotOffset;

        if( row < 0 ) row = 0;
        if( row > _win->getRows() - 1 ) {
            row = _win->getRows() - 1;
        }

        row += _topIndex;

        if( _hotPressIdx >= 0 ) {

            GlobalHotSpots->hotSpotSize( getHotSpot( _hotPressIdx, FALSE ), hotSize );
            hotOffset = getHotOffset( _hotPressIdx );

            if( row == _hotPressIdx
                && x >= hotOffset
                && x <= hotOffset + hotSize.x() ) {

                if( !_inHotZone ) {
                    _inHotZone = TRUE;
                    _win->invalidateRow( _hotPressIdx - _topIndex );
                }
            } else {
                if( _inHotZone ) {
                    _inHotZone = FALSE;
                    _win->invalidateRow( _hotPressIdx - _topIndex );
                }
            }
        } else {
            if( full() && row >= count() ) {
                row = count() - 1;
            }

            if( _selected != row ) {
                _selected = row;

                _win->invalidateRow( oldSel - _topIndex );
                _win->invalidateRow( _selected - _topIndex );
                scrollToSelected();
            }
        }

        return TRUE;
    } else {
        return FALSE;
    }
}

bool HotSpotList::HLLeftBttnDn( int x, int y )
//--------------------------------------------
{
    int     hotOffset;
    WPoint  hotSize;
    int     row;

    row = _win->getRow( WPoint( x, y ) ) + _topIndex;

    if( row < 0 )
        row = 0;

    if( full() && row >= count() )
        row = count() - 1;

    if( row < 0 ) {     // count == 0
        return FALSE;
    }

    GlobalHotSpots->hotSpotSize( getHotSpot( row, FALSE ), hotSize );
    hotOffset = getHotOffset( row );

    if( x > hotOffset && x < hotOffset + hotSize.x() ) {
        _hotPressIdx = row;
    }

    _leftDown = TRUE;

    HLMouseMove( x, y );

    return TRUE;
}

bool HotSpotList::HLLeftBttnUp( int x, int y )
//--------------------------------------------
{
    int oldSel;

    HLMouseMove( x, y );
    _leftDown = FALSE;

    if( _inHotZone && _win->getRow( WPoint( x, y ) ) + _topIndex == _hotPressIdx ) {
        // have to set false before calling invalidateRow().
        _inHotZone = FALSE;

        if( _selected != _hotPressIdx ) {
            oldSel = _selected;
            _selected = _hotPressIdx;
            _win->invalidateRow( oldSel - _topIndex );
        }

        if( _hotPressClient && _hotPress )
            (_hotPressClient->*_hotPress)( _win );

        _win->invalidateRow( _selected - _topIndex );
    }

    _inHotZone = FALSE;
    _hotPressIdx = -1;

⌨️ 快捷键说明

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