hotlist.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 561 行 · 第 1/2 页
CPP
561 行
changed();
return TRUE;
}
bool HotSpotList::HLLeftBttnDbl( int x, int y )
//---------------------------------------------
{
long row = _win->getRow( WPoint( x, y ) ) + _topIndex;
if( _selected == row ) {
if( _dblClickClient && _dblClick ) {
(_dblClickClient->*_dblClick)( _win );
}
}
_win->invalidateRow( _selected - _topIndex );
return TRUE;
}
void HotSpotList::onChanged( WObject* obj, cbw changed )
//------------------------------------------------------
{
_changedClient = obj;
_changed = changed;
}
void HotSpotList::onDblClick( WObject* obj, cbw dblClick )
//--------------------------------------------------------
{
_dblClickClient = obj;
_dblClick = dblClick;
}
void HotSpotList::onHotPress( WObject* obj, cbw hotPress )
//--------------------------------------------------------
{
_hotPressClient = obj;
_hotPress = hotPress;
}
int HotSpotList::selected()
//-------------------------
{
return _selected;
}
void HotSpotList::select( int index )
//-----------------------------------
{
int curr_selected = _selected;
_selected = index;
_win->invalidateRow( curr_selected - _topIndex );
_win->invalidateRow( _selected - _topIndex );
scrollToSelected();
changed();
}
void HotSpotList::resetScrollRange()
//----------------------------------
{
// NYI -- fix scrolling gear!
int scrollr;
WPoint avg;
WPoint max;
int nRows;
if( _infinite ) {
nRows = _win->getRows();
_win->setScrollTextRange( WScrollBarVertical, nRows * 2 );
_win->setScrollTextPos( WScrollBarVertical, nRows / 2 );
} else {
_win->textMetrics( avg, max );
if( (max.y() == 0) || (count() <= INT_MAX / max.y()) ) {
scrollr = count();
} else {
scrollr = INT_MAX / max.y();
}
if( scrollr <= _win->getRows() ) {
_topIndex = 0;
}
_win->setScrollTextPos( WScrollBarVertical, _topIndex );
_win->setScrollTextRange( WScrollBarVertical, scrollr );
}
}
void HotSpotList::reset()
//-----------------------
{
resetScrollRange();
_win->invalidate();
}
void HotSpotList::scrollToSelected()
//----------------------------------
{
int nRows = _win->getRows();
// make sure that _selected is within the range of
// acceptable rows
if( _selected < 0 || (full() && _selected >= count()) ) {
_selected = 0;
}
if( _selected < _topIndex ) {
performScroll( _selected, TRUE );
}
if( _selected > _topIndex + nRows - 1 ) {
performScroll( _selected - nRows + 1, TRUE );
}
}
void HotSpotList::changed()
//-------------------------
{
if( _changedClient && _changed ) {
(_changedClient->*_changed)( _win );
}
}
void HotSpotList::performScroll( long pos, bool absolute )
//--------------------------------------------------------
{
long diff;
int nRows = _win->getRows();
if( absolute ) {
diff = pos - _topIndex;
} else {
diff = pos;
}
if( _topIndex + diff < 0 ) { // it's important this appears twice
diff = -1 * _topIndex;
}
if( _infinite ) {
if( getString( _topIndex + diff ) == NULL ) {
diff = count() - nRows - _topIndex;
}
if( full() && _topIndex + diff > count() - nRows ) {
diff = count() - nRows - _topIndex;
}
} else {
if( _topIndex + diff >= count() ) {
diff = count() - nRows - _topIndex;
}
if( _topIndex + diff > count() - nRows ) {
diff = count() - nRows - _topIndex;
}
}
if( _topIndex + diff < 0 ) { // it's important this appears twice
diff = -1 * _topIndex;
}
_topIndex += diff;
if( _infinite ) {
_win->scrollWindow( WScrollBarVertical, diff );
} else {
_win->setScrollTextPos( WScrollBarVertical, _topIndex );
}
}
bool HotSpotList::HLScrollNotify( WScrollNotification sn, int diff )
//------------------------------------------------------------------
{
switch( sn ) {
case WScrollUp:
performScroll( -1 );
return TRUE;
case WScrollPageUp:
performScroll( -1 * _win->getRows() + 1 );
return TRUE;
case WScrollDown:
performScroll( 1 );
return TRUE;
case WScrollPageDown:
performScroll( _win->getRows() - 1 );
return TRUE;
case WScrollVertical:
performScroll( diff );
return TRUE;
}
return FALSE;
}
bool HotSpotList::HLKeyDown( WKeyCode key, WKeyState state )
//-----------------------------------------------------------
{
int nRows = _win->getRows();
long int oldSel = _selected;
if( state == WKeyStateNone ) {
switch( key ) {
case WKeyPageup:
_selected -= nRows - 1;
if( _selected < 0 ) _selected = 0;
if( oldSel != _selected ) {
_win->invalidateRow( oldSel - _topIndex );
_win->invalidateRow( _selected - _topIndex );
}
scrollToSelected();
changed();
return TRUE;
case WKeyPagedown:
_selected += nRows - 1;
if( full() && _selected >= count() ) {
_selected = count() - 1;
}
if( oldSel != _selected ) {
_win->invalidateRow( oldSel - _topIndex );
_win->invalidateRow( _selected - _topIndex );
}
scrollToSelected();
changed();
return TRUE;
case WKeyUp:
_selected -= 1;
if( _selected < 0 ) _selected = 0;
scrollToSelected();
changed();
if( oldSel != _selected ) {
_win->invalidateRow( oldSel - _topIndex );
_win->invalidateRow( _selected - _topIndex );
}
return TRUE;
case WKeyDown:
_selected += 1;
if( full() && _selected >= count() ) {
_selected = count() - 1;
}
scrollToSelected();
changed();
if( oldSel != _selected ) {
_win->invalidateRow( oldSel - _topIndex );
_win->invalidateRow( _selected - _topIndex );
}
return TRUE;
case WKeyEnter:
if( _dblClickClient && _dblClick ) {
(_dblClickClient->*_dblClick)( _win );
return TRUE;
}
break;
case WKeySpace:
if( _hotPressClient && _hotPress ) {
(_hotPressClient->*_hotPress)( _win );
return TRUE;
}
break;
default:
return FALSE;
}
}
return FALSE;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?