vsetup.cpp

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

CPP
753
字号
                            yoff += text_hite;
                        }
                        int INDENT = frame_width * 2;
                        WEditBox* t = new WEditBox( w, WRect(xoff+INDENT,yoff,wid-INDENT,editctl_hite), "value" );
                        swList->add( new SwitchMap( sw, tt, st, t ) );
#ifndef TEST
                        t->show();
#endif
                        yoff += editctl_hite;
                        j++;
                    } else {
                        j++;    //this should not happen!
                    }
                    if( xoff+wid > maxw ) maxw = xoff+wid;
                    if( yoff > maxh ) maxh = yoff;
                } else {
                    j++;
                }
            }
            initControls( swList, _mode, TRUE );
            _combo->insertString( title, k );
            k += 1;
        }
    }
    if( k > 1 ) {
        _combo->show();
    }

    int xoff = frame_width;

    //
    // create the push buttons at the bottom of the dialog
    //
    WDefPushButton* bOk = new WDefPushButton( this, WRect( xoff, -byoff, button_width, button_hite), ok );
    xoff += bxoff;
    bOk->onClick( this, (cbw)&VSetup::okButton );
    bOk->show();

    WPushButton* bCancel = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), cancel );
    xoff += bxoff;
    bCancel->onClick( this, (cbw)&VSetup::cancelButton );
    bCancel->show();

    WPushButton* bResetCfg = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), resetcfg );
    xoff += bxoff;
    bResetCfg->onClick( this, (cbw)&VSetup::resetCfgButton );
    bResetCfg->show();

    WPushButton* bResetDev = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), resetdev );
    xoff += bxoff;
    bResetDev->onClick( this, (cbw)&VSetup::resetDevButton );
    bResetDev->enable( _mode != SWMODE_DEBUG );
    bResetDev->show();

    WPushButton* bResetRel = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), resetrel );
    xoff += bxoff;
    bResetRel->onClick( this, (cbw)&VSetup::resetRelButton );
    bResetRel->enable( _mode != SWMODE_RELEASE );
    bResetRel->show();

    //
    // create the next and previous push buttons if this dialog has
    // more than one panel
    //
    if( k > 1 ) {
        _prev = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), "&<<" );
        xoff += bxoff;
        _prev->onClick( this, (cbw)&VSetup::prevButton );
        _prev->show();

        _next = new WPushButton( this, WRect( xoff, -byoff, button_width, button_hite), "&>>" );
        xoff += bxoff;
        _next->onClick( this, (cbw)&VSetup::nextButton );
        _next->show();
    }

    if( maxw < xoff ) maxw = xoff;

    //
    // hide the drop down list box at the top of the dialog and move all
    // the controls up if this dialog has only one panel
    //
    if( k <= 1 ) {
        yy -= thoff;
        maxh -= thoff;
        for( int ii=0; ii<_families.count(); ii++ ) {
            shiftFamily( ii, 0, -thoff );
        }
    }

#ifdef TEST
    maxw += 2 * frame_width; //add wwindow offsets
    maxh += button_hite*3/2;
#else
    maxw += 3 * frame_width; //add wwindow offsets
    maxh += button_hite*3/2;
#endif

    maxw += 2 * frame_width; //add for frame thickness
    maxh += frame_hite*2 + WSystemMetrics::captionSize(); //add frame thickness and title bar

    size( (WOrdinal)maxw, (WOrdinal)maxh );
    sc.x( 0 );
    sc.y( 0 );
    sc.w( maxw );
    sc.h( maxh );
    move( sc );

    _combo->select( 0 );
    pickFamily( _combo );
    show();
    enableButtons();
    stopWait();
    _combo->setFocus();
}


VSetup::~VSetup()
{
    show( WWinStateHide );
    int icount = _families.count();
    for( int i=0; i<icount; i++ ) {
        WVList* swList = (WVList*)_families[i];
        swList->deleteContents();
    }
    _families.deleteContents();
}

MState* VSetup::findState( MSwitch* sw, SwMode mode )
{
    int kcount = _states->count();
    for( int k=0; k<kcount; k++ ) {
        MState* t = (MState*)(*_states)[k];
        if( mode == t->mode() && sw == t->sw() ) {
            return t;
        }
    }
    return NULL;
}

void VSetup::initControls( WVList* swList, SwMode mode, bool useStates )
{
    int icount = swList->count();
    for( int i=0; i<icount; i++ ) {
        SwitchMap* m = (SwitchMap*)(*swList)[i];
        MSwitch* sw = m->sw();
        MState* st = NULL;
        if( useStates ) {
            st = findState( sw, mode );
        }
        if( !sw ) {
        } else if( streq( sw->className(), "MRSwitch" ) ) {
            bool b = FALSE;
            if( st ) {
                b = ((MRState*)st)->state();
            } else {
                b = ((MRSwitch*)sw)->state( mode );
            }
            m->ctl()->setCheck( b );
        } else if( streq( sw->className(), "MCSwitch" ) ) {
            bool b = FALSE;
            if( st ) {
                b = ((MCState*)st)->state();
            } else {
                b = ((MCSwitch*)sw)->state( mode );
            }
            m->ctl()->setCheck( b );
        } else if( streq( sw->className(), "MC2Switch" ) ) {
            bool b = FALSE;
            if( st ) {
                b = ((MCState*)st)->state();
            } else {
                b = ((MC2Switch*)sw)->state( mode );
            }
            m->ctl()->setCheck( b );
        } else if( streq( sw->className(), "MVSwitch" ) ) {
            if( ((MVSwitch*)sw)->optional() ) {
                bool b = FALSE;
                if( st ) {
                    b = ((MVState*)st)->state();
                } else {
                    b = ((MVSwitch*)sw)->state( mode );
                }
                m->ctl()->setCheck( b );
            }
            WString* v;
            if( st ) {
                v = &((MVState*)st)->value();
            } else {
                v = &((MVSwitch*)sw)->value( mode );
            }
            m->ctl2()->setText( *v );
        }
    }
}

void VSetup::enableButtons()
{
    int index = _combo->selected();
    if( _prev ) _prev->enable( (index>0) ? TRUE : FALSE );
    if( _next ) _next->enable( (index+1<_screens.count()) ? TRUE : FALSE );
}

void VSetup::okButton( WWindow* )
{
    for( int k=_states->count(); k>0; ) {
        k--;
        MState* st = (MState*)(*_states)[k];
        if( st->mode() == _mode ) {
            delete _states->removeAt( k );
        }
    }
    int icount = _families.count();
    for( int i=0; i<icount; i++ ) {
        WVList* swList = (WVList*)_families[i];
        int jcount = swList->count();
        for( int j=0; j<jcount; j++ ) {
            SwitchMap* m = (SwitchMap*)(*swList)[j];
            MSwitch* sw = m->sw();
            if( !sw ) {
            } else if( streq( sw->className(), "MRSwitch" ) ) {
                bool b = m->ctl()->checked();
                if( b != ((MRSwitch*)sw)->state( _mode ) ) {
                    MRState* st = new MRState( _tool, _mode, (MRSwitch*)sw, b );
                    _states->add( st );
                }
            } else if( streq( sw->className(), "MCSwitch" ) ) {
                bool b = m->ctl()->checked();
                if( b != ((MCSwitch*)sw)->state( _mode ) ) {
                    MCState* st = new MCState( _tool, _mode, (MCSwitch*)sw, b );
                    _states->add( st );
                }
            } else if( streq( sw->className(), "MC2Switch" ) ) {
                bool b = m->ctl()->checked();
                if( b != ((MC2Switch*)sw)->state( _mode ) ) {
                    MCState* st = new MCState( _tool, _mode, (MCSwitch*)sw, b );
                    _states->add( st );
                }
            } else if( streq( sw->className(), "MVSwitch" ) ) {
                bool b = FALSE;
                if( ((MVSwitch*)sw)->optional() ) {
                    b = m->ctl()->checked();
                }
                WString v;
                m->ctl2()->getText( v );
                v.trim();
                if( b != ((MVSwitch*)sw)->state( _mode ) || !(((MVSwitch*)sw)->value( _mode ) == v) ) {
                    MVState* st = new MVState( _tool, _mode, (MVSwitch*)sw, b, &v );
                    _states->add( st );
                }
            }
        }
    }
    quit( TRUE );
}

void VSetup::cancelButton( WWindow* )
{
    quit( FALSE );
}

void VSetup::resetCfgButton( WWindow* )
{
    int i = _combo->selected();
    WVList* swList = (WVList*)_families[i];
    initControls( swList, _mode, FALSE );
}

void VSetup::resetDevButton( WWindow* )
{
    int i = _combo->selected();
    WVList* swList = (WVList*)_families[i];
    initControls( swList, SWMODE_DEBUG, TRUE );
}

void VSetup::resetRelButton( WWindow* )
{
    int i = _combo->selected();
    WVList* swList = (WVList*)_families[i];
    initControls( swList, SWMODE_RELEASE, TRUE );
}

void VSetup::prevButton( WWindow* )
{
    int index = _combo->selected();
    if( index > 0 ) {
        index -= 1;
        _combo->select( index );
    }
    enableButtons();
}

void VSetup::nextButton( WWindow* )
{
    int index = _combo->selected();
    if( index+1 < _screens.count() ) {
        index += 1;
        _combo->select( index );
    }
    enableButtons();
}

void VSetup::shift( WWindow* w, int xoff, int yoff )
{
    WRect r = w->getAutosize();
    w->move( (WOrdinal)(r.x() + xoff), (WOrdinal)(r.y() + yoff) );
}

void VSetup::shiftFamily( int index, int xoff, int yoff )
{
#ifdef TEST
    WVList* swList = (WVList*)_families[ index ];
    for( int i=0; i<swList->count(); i++ ) {
        SwitchMap* sm = (SwitchMap*)(*swList)[i];
        if( sm->ctl() ) shift( sm->ctl(), xoff, yoff );
        if( sm->ctl2() ) shift( sm->ctl2(), xoff, yoff );
        if( sm->ctrl() ) shift( sm->ctrl(), xoff, yoff );
    }
#else
    WWindow* w = (WWindow*)_screens[ index ];
    w->shift( xoff, yoff );
#endif
}

void VSetup::hideFamily( int index )
{
#ifdef TEST
    WVList* swList = (WVList*)_families[ index ];
    for( int i=0; i<swList->count(); i++ ) {
        SwitchMap* sm = (SwitchMap*)(*swList)[i];
        if( sm->ctl() ) sm->ctl()->show( WWinStateHide );
        if( sm->ctl2() ) sm->ctl2()->show( WWinStateHide );
        if( sm->ctrl() ) sm->ctrl()->show( WWinStateHide );
    }
#else
    WWindow* g = (WWindow*)_screens[ index ];
    g->show( WWinStateHide );
#endif
}

void VSetup::showFamily( int index )
{
#ifdef TEST
    WVList* swList = (WVList*)_families[ index ];
    for( int i=0; i<swList->count(); i++ ) {
        SwitchMap* sm = (SwitchMap*)(*swList)[i];
        if( sm->ctl() ) sm->ctl()->show();
        if( sm->ctl2() ) sm->ctl2()->show();
        if( sm->ctrl() ) sm->ctrl()->show();
    }
#else
    WWindow* g = (WWindow*)_screens[ index ];
    g->show();
#endif
}

void VSetup::pickFamily( WWindow* combo )
{
    int newIndex = ((WComboBox*)combo)->selected();
    if( _curIndex != newIndex ) {
        if( _curIndex >= 0 ) {
            hideFamily( _curIndex );
        }
        _curIndex = newIndex;
        if( _curIndex >= 0 ) {
            showFamily( _curIndex );
        }
        enableButtons();
    }
}

bool VSetup::process()
{
    return WDialog::process() == TRUE;
}

⌨️ 快捷键说明

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