vsetup.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 753 行 · 第 1/2 页
CPP
753 行
/****************************************************************************
*
* 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 "vsetup.hpp"
#include "wpshbttn.hpp"
#include "wradbttn.hpp"
#include "wcheckbx.hpp"
#include "weditbox.hpp"
#include "wtext.hpp"
#include "wcombox.hpp"
#include "wgroupbx.hpp"
#include "mtool.hpp"
#include "mfamily.hpp"
#include "mswitch.hpp"
#include "mrswitch.hpp"
#include "mcswitch.hpp"
#include "mc2swtch.hpp"
#include "mvswitch.hpp"
#include "mstate.hpp"
#include "mrstate.hpp"
#include "mcstate.hpp"
#include "mvstate.hpp"
#include "wmetrics.hpp"
#define TEST
WCLASS SwitchMap : public WObject
{
public:
#ifdef TEST
SwitchMap( WControl* ctrl );
#endif
SwitchMap( MSwitch* sw, WBoolSwitch* ctl, MState* st, WEditBox* ctl2=NULL );
~SwitchMap() {}
MSwitch* sw() { return _switch; }
WBoolSwitch* ctl() { return _control; }
WEditBox* ctl2() { return _control2; }
#ifdef TEST
WControl* ctrl() { return _ctrl; }
#endif
private:
MSwitch* _switch;
WBoolSwitch* _control;
WEditBox* _control2;
#ifdef TEST
WControl* _ctrl;
#endif
};
#ifdef TEST
SwitchMap::SwitchMap( WControl* ctrl )
: _switch( NULL )
, _control( NULL )
, _control2( NULL )
, _ctrl( ctrl )
{
}
#endif
SwitchMap::SwitchMap( MSwitch* sw, WBoolSwitch* ctl, MState* /*st*/, WEditBox* ctl2 )
: _switch( sw )
, _control( ctl )
, _control2( ctl2 )
#ifdef TEST
, _ctrl( NULL )
#endif
{
}
VSetup::VSetup( WWindow* parent, MTool* tool, WString& tagMask, WVList* states, const char* text, SwMode mode )
: WDialog( parent, WRect( 20, 50, 600, 400 ) )
, _tool( tool )
, _tagMask( tagMask )
, _states( states )
, _mode( mode )
, _curIndex( -1 )
, _next( NULL )
, _prev( NULL )
, _text( text )
{
}
static unsigned calcControlHite( WVList *list, unsigned index,
unsigned editctl_hite, unsigned checkbox_hite,
unsigned radiobutton_hite, unsigned text_hite,
unsigned groupbox_hite ) {
MSwitch* sw;
unsigned ret;
unsigned cnt;
sw = (MSwitch*)(*list)[index];
if( streq( sw->className(), "MRSwitch" ) ) {
ret = groupbox_hite + radiobutton_hite;
WString& groupName = ((MRSwitch*)sw)->group();
index++;
cnt = list->count();
for( ; index < cnt ; index++ ) {
sw = (MSwitch*)(*list)[index];
if( !streq( sw->className(), "MRSwitch" ) ) break;
if( !(groupName == ((MRSwitch*)sw)->group()) ) break;
ret += radiobutton_hite;
}
} else if( streq( sw->className(), "MCSwitch" ) ) {
ret = checkbox_hite;
} else if( streq( sw->className(), "MC2Switch" ) ) {
ret = checkbox_hite;
} else if( streq( sw->className(), "MVSwitch" ) ) {
if( ((MVSwitch*)sw)->optional() ) {
ret = checkbox_hite;
} else {
ret = text_hite;
}
ret += editctl_hite;
} else {
ret = 0;
}
return( ret );
}
void VSetup::initialize()
{
static const char ok[] = { "OK" };
static const char cancel[] = { "Cancel" };
static const char resetcfg[] = { "Rese&t" };
static const char resetdev[] = { "Copy&Dev" };
static const char resetrel[] = { "Copy&Rel" };
unsigned editctl_hite;
unsigned checkbox_hite;
unsigned radiobutton_hite;
unsigned groupbox_hite;
WPoint avgCh;
WPoint maxCh;
WRect sc;
int frame_width;
int frame_hite;
int text_hite;
int button_width;
int button_hite;
int bxoff;
int byoff;
int yy;
WString n;
int thoff;
int maxw;
int maxh;
WVList famList;
int k;
int icount;
#ifndef TEST
show();
#endif
WSystemMetrics::screenCoordinates( sc );
size( (WOrdinal)((long)sc.w()*4/5), (WOrdinal)((long)sc.h()) );
textMetrics( avgCh, maxCh );
frame_width = WSystemMetrics::dialogFrameWidth();
frame_hite = WSystemMetrics::dialogFrameHeight();
text_hite = maxCh.y() * 5/4;
editctl_hite = text_hite + avgCh.y() / 2;
checkbox_hite = text_hite;
radiobutton_hite = text_hite;
groupbox_hite = frame_hite + text_hite + text_hite / 2;
button_width = getTextExtentX( resetdev ) + frame_width*2;
button_hite = getTextExtentY( resetdev ) * 3/2;
bxoff = button_width + frame_width;
byoff = button_hite * 5/4;
startWait();
_tagMask.concat( '*' ); //make this work for all switches
yy = frame_hite;
_tool->name( n );
n.concat( " Switches" );
setText( n );
//
// Create the text at the top of the dialog
//
WText* head = new WText( this, WRect(frame_width,yy,-frame_width,text_hite), _text );
head->show();
yy += text_hite;
//
// Create the drop down list box at the top of the dialog
//
_combo = new WComboBox( this, WRect( frame_width, yy, -frame_width, maxCh.y()*12 ), NULL, CStyleDefault | WStyleVScroll | WStyleHScroll );
_combo->onChanged( this, (cbw)&VSetup::pickFamily );
thoff = text_hite * 3/2;
yy += thoff;
maxw = getTextExtentX( _text );
maxh = 0;
_tool->addFamilies( famList );
k = 0;
icount = famList.count();
for( int i=0; i<icount; i++ ) {
MFamily *fam;
WVList myList;
int jcount;
fam = (MFamily*)famList[i];
fam->addSwitches( myList, _tagMask, TRUE );
jcount = myList.count();
if( jcount > 0 ) {
WVList *swList;
WString famName;
WString title;
WWindow *w;
int YBEG;
int XBEG;
int xoff;
int yoff;
WRect rr;
int wid;
swList = new WVList();
_families.add( swList );
fam->name( famName );
famName.concat( " Switches" );
title.printf( "%d. %s", k+1, (const char*)famName );
#ifdef TEST
w = this;
YBEG = yy;
#else
w = new WWindow( this, WRect(frame_width,yy,-frame_width,-button_hite*3/2), NULL, WStyleSimple );
YBEG = frame_hite;
#endif
XBEG = frame_width;
xoff = XBEG;
yoff = YBEG;
_screens.add( w );
w->getRectangle( rr );
rr.w( rr.w() - 2*XBEG );
rr.h( rr.h() - button_hite*3/2
- frame_hite*2
- WSystemMetrics::captionSize() );
wid = rr.w()/2;
for( int j=0; j<jcount; ) {
MSwitch *sw;
sw = (MSwitch*)myList[j];
if( sw->text().size() > 0 && sw->text()[0] != ' ' ) {
MState *st;
WString text;
st = findState( sw, _mode );
//
// decide if we should start putting controls in
// the second column
//
if( xoff == XBEG ) {
unsigned newypos;
newypos = yoff;
newypos += calcControlHite( &myList, j, editctl_hite,
checkbox_hite, radiobutton_hite, text_hite,
groupbox_hite );
if( sw->panel() == 1 || newypos > rr.h() ) {
yoff = YBEG;
xoff = XBEG + rr.w()/2 + frame_width;
}
}
sw->displayText( text );
//
// Create a radio button group
//
if( streq( sw->className(), "MRSwitch" ) ) {
WString& groupName = ((MRSwitch*)sw)->group();
WRect rg(xoff,yoff,wid,10);
WGroupBox* curGroup;
int XGBEG;
int YGBEG;
int ygoff;
int xgoff;
WStyle style;
curGroup = new WGroupBox( w, rg, groupName );
#ifdef TEST
swList->add( new SwitchMap( curGroup ) );
#endif
XGBEG = frame_width;
YGBEG = text_hite;
ygoff = YGBEG;
xgoff = XGBEG;
style = RStyleGroupFirst;
for( ; j<jcount; ) {
sw = (MSwitch*)myList[j];
st = findState( sw, _mode );
if( !streq( sw->className(), "MRSwitch" ) ) break;
if( !(groupName == ((MRSwitch*)sw)->group()) ) break;
if( j+1 < jcount ) {
MSwitch* nsw = (MSwitch*)myList[j+1];
if( !streq( nsw->className(), "MRSwitch" ) ||
!(groupName == ((MRSwitch*)nsw)->group()) ) {
style = RStyleGroupLast;
}
} else {
style = RStyleGroupLast;
}
sw->displayText( text );
WRect rbrect( xoff+xgoff, yoff+ygoff, wid-2*xgoff, radiobutton_hite );
WRadioButton* t = new WRadioButton( w, rbrect, text, style );
swList->add( new SwitchMap( sw, t, st ) );
#ifndef TEST
t->show();
#endif
ygoff += radiobutton_hite;
j++;
style = RStyleRadioButton;
}
rg.h( ygoff+frame_hite );
curGroup->move( rg );
#ifndef TEST
curGroup->show();
#endif
yoff += rg.h() + text_hite / 2;
//
// Create a check box
//
} else if( streq( sw->className(), "MCSwitch" )
|| streq( sw->className(), "MC2Switch" ) ) {
WCheckBox* t = new WCheckBox( w, WRect(xoff,yoff,wid,checkbox_hite), text );
swList->add( new SwitchMap( sw, t, st ) );
#ifndef TEST
t->show();
#endif
yoff += checkbox_hite;
j++;
//
// Create an edit control
//
} else if( streq( sw->className(), "MVSwitch" ) ) {
WBoolSwitch* tt = NULL;
if( ((MVSwitch*)sw)->optional() ) {
tt = new WCheckBox( w, WRect(xoff,yoff,wid, checkbox_hite), text );
#ifndef TEST
tt->show();
#endif
yoff += checkbox_hite;
} else {
WText* t = new WText( w, WRect(xoff,yoff,wid,text_hite), text );
#ifdef TEST
swList->add( new SwitchMap( t ) );
#else
t->show();
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?