home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
DLOGWIN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-15
|
16KB
|
660 lines
//
// ダイアログ処理関数
//
// 1996.1.16 M.Takatsu
//
#include <owl\owlpch.h>
#pragma hdrstop
#include <owl\button.h>
#include <owl\edit.h>
#include <owl\slider.h>
#include <owl\static.h>
#include <owl\checkbox.h>
#include <owl\radiobut.h>
#include <owl\groupbox.h>
#include <owl\opensave.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "model.rh"
#include "message.h"
extern "C" {
#include "ml.h"
#include "dlog.h"
#include "model.h"
}
#define OFFSET 1000
#define DLOG_STEP (FontV+2)
//#define DLOG_OFFSET (FontV+DLOG_STEP)
#define DLOG_OFFSET FontV
#define MAX_FIELD 30
#define MAX_SELECT 10
#define DLOG_ID_SLIDER (DIALOG_FRAME+1)
#define DLOG_ID_BUTTON (DLOG_ID_SLIDER+32)
#define DLOG_ID_END (DLOG_ID_BUTTON+32)
#define BORDER 4
#define RIGHTBORDER (FontH*3)
#define MAXSTRING 512
#define MAXBUTTONTEXT 16
#define SLIDERSTEP 10
#define SLIDEROFFSET 30
typedef struct {
int type ;
TEdit *control;
int max ;
char str[MAXSTRING] ;
char wild[MAXSTRING] ;
}
cStringData ;
typedef struct {
int type ;
TCheckBox *control;
int stat ;
}
cToggleData ;
typedef struct {
int type ;
TRadioButton *control[MAX_SELECT];
int sels;
int stat;
}
cSelectData ;
typedef struct {
int type ;
TSlider *control;
TStatic *text;
int size;
int step;
int count ;
int ident ;
}
cSliderData ;
typedef union {
int type ;
cStringData str ;
cToggleData toggle ;
cSelectData select ;
cSliderData slider ;
}
cDlogData ;
class TDlog : public TDialog {
public:
TDlog (TWindow* parent);
virtual ~TDlog ();
virtual void SetupWindow ();
protected:
void CmEnd();
void CmOK ();
void CmCancel ();
void CmDlogButton0();
void CmDlogButton1();
void CmDlogButton2();
void CmDlogButton3();
void CmDlogButton4();
void CmDlogButton5();
void CmDlogButton6();
void CmDlogButton7();
void EvSlider(UINT code);
void CmButton(int pos);
#define E(n) void CmButton##n () {CmButton(n);}
E(0) E(1) E(2) E(3) E(4) E(5) E(6) E(7)
E(8) E(9) E(10) E(11) E(12) E(13) E(14) E(15)
E(16) E(17) E(18) E(19) E(20) E(21) E(22) E(23)
E(24) E(25) E(26) E(27) E(28) E(29) E(30) E(31)
#undef E
DECLARE_RESPONSE_TABLE(TDlog);
};
#define EV_CHILD_NOTIFY_ALL_CODES_2(id,func) \
EV_CHILD_NOTIFY_ALL_CODES((id)+0,func),\
EV_CHILD_NOTIFY_ALL_CODES((id)+1,func)
#define EV_CHILD_NOTIFY_ALL_CODES_4(id,func) \
EV_CHILD_NOTIFY_ALL_CODES_2((id)+0,func),\
EV_CHILD_NOTIFY_ALL_CODES_2((id)+2,func)
#define EV_CHILD_NOTIFY_ALL_CODES_8(id,func) \
EV_CHILD_NOTIFY_ALL_CODES_4((id)+0,func),\
EV_CHILD_NOTIFY_ALL_CODES_4((id)+4,func)
#define EV_CHILD_NOTIFY_ALL_CODES_16(id,func) \
EV_CHILD_NOTIFY_ALL_CODES_8((id)+0,func),\
EV_CHILD_NOTIFY_ALL_CODES_8((id)+8,func)
#define EV_CHILD_NOTIFY_ALL_CODES_32(id,func) \
EV_CHILD_NOTIFY_ALL_CODES_16((id)+0,func),\
EV_CHILD_NOTIFY_ALL_CODES_16((id)+16,func)
#define EV_BN_CLICKED_AND_CODE(id,func) EV_CHILD_NOTIFY_AND_CODE(id,BN_CLICKED,func)
#define EV_BN_CLICKED_AND_CODE_4(id, func) \
EV_BN_CLICKED_AND_CODE((id)+0, func),\
EV_BN_CLICKED_AND_CODE((id)+1, func),\
EV_BN_CLICKED_AND_CODE((id)+2, func),\
EV_BN_CLICKED_AND_CODE((id)+3, func)
#define EV_BN_CLICKED_AND_CODE_16(id, func) \
EV_BN_CLICKED_AND_CODE_4((id)+ 0, func),\
EV_BN_CLICKED_AND_CODE_4((id)+ 4, func),\
EV_BN_CLICKED_AND_CODE_4((id)+ 8, func),\
EV_BN_CLICKED_AND_CODE_4((id)+12, func)
#define EV_BN_CLICKED_AND_CODE_32(id,func) \
EV_BN_CLICKED_AND_CODE_16((id)+ 0, func),\
EV_BN_CLICKED_AND_CODE_16((id)+16, func)
DEFINE_RESPONSE_TABLE1(TDlog, TDialog)
EV_CHILD_NOTIFY_ALL_CODES_32(DLOG_ID_SLIDER, EvSlider),
#define E(n) EV_BN_CLICKED(DLOG_ID_BUTTON+n, CmButton##n),
E(0) E(1) E(2) E(3) E(4) E(5) E(6) E(7)
E(8) E(9) E(10) E(11) E(12) E(13) E(14) E(15)
E(16) E(17) E(18) E(19) E(20) E(21) E(22) E(23)
E(24) E(25) E(26) E(27) E(28) E(29) E(30) E(31)
#undef E
EV_BN_CLICKED(IDOK, CmOK),
EV_BN_CLICKED(DLOG_ID_END+0, CmDlogButton0),
EV_BN_CLICKED(DLOG_ID_END+1, CmDlogButton1),
EV_BN_CLICKED(DLOG_ID_END+2, CmDlogButton2),
EV_BN_CLICKED(DLOG_ID_END+3, CmDlogButton3),
EV_BN_CLICKED(DLOG_ID_END+4, CmDlogButton4),
EV_BN_CLICKED(DLOG_ID_END+5, CmDlogButton5),
EV_BN_CLICKED(DLOG_ID_END+6, CmDlogButton6),
EV_BN_CLICKED(DLOG_ID_END+7, CmDlogButton7),
END_RESPONSE_TABLE;
extern int QuitFlag;
extern int FontH, FontV ;
static TDlog *DlogWindow = NULL;
static cDlogData Dlog[MAX_FIELD];
static int maxwidth;
static int dx, dy, dw, dh;
#if 0
static int buttontype;
TButton *b_ok, *b_cancel;
#endif
TButton *dlogbutton[DLOG_MAX_BUTTON];
int dlogbuttonwidth[DLOG_MAX_BUTTON];
char buttontext[DLOG_MAX_BUTTON][MAXBUTTONTEXT];
static void SliderDisplay( cSliderData* );
static int SliderConv( cSliderData* );
extern TWindow *GetModelWindow(void);
extern TApplication *Application ;
TDlog::TDlog (TWindow* parent) :
TDialog(parent, DIALOG_FRAME, NULL)
{
for (int i = 0; i < DLOG_MAX_BUTTON; ++i) {
dlogbutton[i] = NULL;
}
}
void TDlog::SetupWindow ()
{
TDialog::SetupWindow();
// INSERT>> 追加のコードはここに
int ox = GetSystemMetrics(SM_CXBORDER)*2;
int oy = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYBORDER);
if (dw < maxwidth) {
dw = maxwidth;
}
MoveWindow(dx-(dw/2), dy-(dh/2), dw+ox, dh+oy);
int bx, by;
bx = dw - FontH * 3;
by = dh - (FontV+BORDER*5);
for (int i = 0; i < DLOG_MAX_BUTTON; ++i) {
if (dlogbutton[i] != NULL) {
bx -= FontH * (dlogbuttonwidth[i]+ 2);
dlogbutton[i]->MoveWindow(bx, by, FontH * (dlogbuttonwidth[i]+2), FontV+BORDER*2);
bx -= FontH * 2;
}
}
for (i = 0; i < MAX_FIELD; ++i) {
cToggleData *td;
cSelectData *sd;
cSliderData *hd;
switch (Dlog[i].type) {
case DLOG_STRING:
break;
case DLOG_TOGGLE:
td = &(Dlog[i].toggle);
if (td->stat) {
td->control->Check();
}
break;
case DLOG_SELECT:
sd = &(Dlog[i].select);
sd->control[sd->stat]->Check();
break;
case DLOG_SLIDER:
hd = &(Dlog[i].slider);
hd->control->SetPosition((hd->count+1) * SLIDERSTEP);
hd->control->PageMagnitude = SLIDERSTEP;
hd->control->LineMagnitude = SLIDERSTEP;
hd->control->DeltaPos(SLIDERSTEP);
hd->control->SetRange(SLIDERSTEP, SLIDERSTEP * hd->step);
hd->control->SetRuler(SLIDERSTEP, TRUE);
hd->control->SetPosition(0);
hd->control->SetPosition((hd->count+1) * SLIDERSTEP);
SliderDisplay(hd);
break;
}
}
}
TDlog::~TDlog()
{
}
void TDlog::EvSlider(UINT /*code*/)
{
int i;
for (i = 0; i < MAX_FIELD; ++i) {
cSliderData *sd = &(Dlog[i].slider);
if (Dlog[i].type == DLOG_SLIDER
&& sd->count != (sd->control->GetPosition()/SLIDERSTEP)-1) {
sd->count = (sd->control->GetPosition()/SLIDERSTEP)-1;
if (sd->count < 0) {
sd->count = 0;
} else if (sd->count >= sd->step) {
sd->count = sd->step-1;
}
SliderDisplay(sd);
}
}
}
void TDlog::CmEnd()
{
int i, j;
for (i = 0; i < MAX_FIELD; ++i) {
cStringData *str;
cToggleData *tgl;
cSelectData *sel;
switch (Dlog[i].type) {
case DLOG_STRING:
str = &(Dlog[i].str);
str->control->GetText(str->str, MAXSTRING);
break;
case DLOG_TOGGLE:
tgl = &(Dlog[i].toggle);
tgl->stat = (tgl->control->GetCheck() == BF_CHECKED);
break;
case DLOG_SELECT:
sel = &(Dlog[i].select);
for (j = 0; j < sel->sels; ++j) {
if (sel->control[j]->GetCheck() == BF_CHECKED) {
sel->stat = j;
break;
}
}
break;
case DLOG_SLIDER:
break;
}
}
}
void TDlog::CmOK() {CmEnd();CloseWindow(OFFSET + 0x0d);}
void TDlog::CmCancel() {CmEnd();CloseWindow(OFFSET + 0);}
void TDlog::CmDlogButton0() {CmEnd();CloseWindow(OFFSET + 0);}
void TDlog::CmDlogButton1() {CmEnd();CloseWindow(OFFSET + 1);}
void TDlog::CmDlogButton2() {CmEnd();CloseWindow(OFFSET + 2);}
void TDlog::CmDlogButton3() {CmEnd();CloseWindow(OFFSET + 3);}
void TDlog::CmDlogButton4() {CmEnd();CloseWindow(OFFSET + 4);}
void TDlog::CmDlogButton5() {CmEnd();CloseWindow(OFFSET + 5);}
void TDlog::CmDlogButton6() {CmEnd();CloseWindow(OFFSET + 6);}
void TDlog::CmDlogButton7() {CmEnd();CloseWindow(OFFSET + 7);}
void TDlog::CmButton(int pos)
{
cStringData *sd ;
if (0 <= pos && pos < MAX_FIELD && Dlog[pos].type == DLOG_STRING) {
sd = &Dlog[pos].str ;
TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
sd->wild + 4, 0, NULL, sd->wild);
if (TFileOpenDialog(this, FileData).Execute() == IDOK) {
sd->control->SetText(FileData.FileName);
}
}
}
void DlogOpen(char *title, int fields, char *button[] )
{
TWindow *parent;
int i ;
dw = FontH * 20;
// dh = DLOG_STEP * fields + FontV * 5;
dh = DLOG_STEP * fields + FontV * 4;
maxwidth = FontH * 20;
dx = GetSystemMetrics(SM_CXSCREEN)/2;
dy = GetSystemMetrics(SM_CYSCREEN)/2;
if (DlogWindow == NULL) {
delete DlogWindow;
}
parent = GetModelWindow();
DlogWindow = new TDlog(parent);
// new TStatic(DlogWindow, 0, title, FontH*2, BORDER, FontH*60, FontV, strlen(title));
DlogWindow->SetCaption(title);
for (i = 0; button[i] != NULL; i++) {
strcpy(buttontext[i], button[i]);
}
for (; i < DLOG_MAX_BUTTON; i++) {
buttontext[i][0] = '\0';
}
#if 0
int bx, by;
bx = dw- FontH * 5;
by = dh - (FontV+BORDER*5);
new TButton(DlogWindow, IDOK, "決定", -100, -100, 0, 0);
new TButton(DlogWindow, IDCANCEL, "中止", -100, -100, 0, 0);
for (i = 0; button[i] != NULL; i++) {
int len;
len = dlogbuttonwidth[i] = strlen(button[i]);
dlogbutton[i] = new TButton(DlogWindow, DLOG_ID_END+ i, button[i], bx - FontH * (len+2), by, FontH * (len+2), FontV + BORDER*2);
bx -= FontH * (len + 4);
}
#endif
for( i = 0 ; i < MAX_FIELD ; i++ ) {
Dlog[i].type = 0 ;
}
}
/* メッセージの表示 */
int DlogMessage(int field, char *msg )
{
int x = FontH * 2;
int y = DLOG_OFFSET + field * DLOG_STEP;
int len = strlen(msg);
new TStatic(DlogWindow, 0, msg, x, y,
FontH * len, FontV, len);
if (maxwidth < x + FontH * len + RIGHTBORDER) {
maxwidth = x + FontH * len + RIGHTBORDER;
}
return FontH * (4 + len);
}
/* 文字列入力フィールド表示 */
void DlogString( int field, char *msg, char *str, int max, char *wild )
{
cStringData *sd ;
Dlog[field].type = DLOG_STRING ;
sd = &Dlog[field].str ;
sd->max = max ;
strcpy( sd->str, str );
int x = DlogMessage(field, msg);
int y = DLOG_OFFSET + field * DLOG_STEP;
sd->control = new TEdit(DlogWindow, 0, sd->str,
x, y-BORDER, max*FontH, FontV+BORDER*2, MAXSTRING);
x += max * FontH ;
if (wild != NULL && wild[0]) {
strcpy(sd->wild, wild);
sd->wild[3] = '\0';
new TButton(DlogWindow, DLOG_ID_BUTTON + field, "参照",
x + FontH, y-BORDER, 6 * FontH, FontV + BORDER*2);
//printf("field = %d, Create ID=%08x\n", field, DLOG_ID_BUTTON+ field);
x += FontH + 6 * FontH;
}
if (maxwidth < x + RIGHTBORDER) {
maxwidth = x + RIGHTBORDER;
}
}
/* トグルスイッチ表示 */
void DlogToggle( int field, char *msg, char *str, int sw )
{
cToggleData *td ;
Dlog[field].type = DLOG_TOGGLE ;
td = &Dlog[field].toggle ;
int x = DlogMessage(field, msg);
int y = DLOG_OFFSET + field * DLOG_STEP;
int len = strlen(str);
td->control = new TCheckBox(DlogWindow, DLOG_ID_BUTTON + field,
str,
x, y-BORDER, (len+4)*FontH, FontV+BORDER*2);
td->stat = sw ;
if (maxwidth < x + (len+4) * FontH + RIGHTBORDER) {
maxwidth = x + (len+4) * FontH + RIGHTBORDER;
}
}
/* 選択スイッチ表示 */
void DlogSelect( int field, char *msg, char **item, int stat )
{
int i, len, n, max ;
cSelectData *sd ;
max = 0 ;
for( n = 0 ; item[n] != NULL ; n++ )
{
len = strlen( item[n] ) ;
if ( max < len )
max = len ;
}
Dlog[field].type = DLOG_SELECT ;
sd = &Dlog[field].select ;
int x = DlogMessage(field, msg);
int y = DLOG_OFFSET + field * DLOG_STEP;
TGroupBox *tbox = new TGroupBox(DlogWindow, 0, "", x, y-BORDER*3,
((max+5) * n +1) * FontH, FontV+BORDER*4);
sd->sels = n ;
if (stat < 0 || stat >= n) {
stat = 0;
}
sd->stat = stat ;
x += FontH;
for (i = 0; i < n; ++i) {
sd->control[i] = new TRadioButton(DlogWindow, 0, item[i],
x, y, FontH * (max+4), FontV, tbox);
x += FontH * (max+5);
}
if (maxwidth < x + ((max+5)*n+1) * FontH + RIGHTBORDER) {
maxwidth = x + RIGHTBORDER;
}
}
/* スライドスイッチ表示 */
void DlogSlider( int field, char *msg, int size, int step, int start, int ident )
{
cSliderData *sd ;
Dlog[field].type = DLOG_SLIDER ;
sd = &Dlog[field].slider ;
int x = DlogMessage(field, msg);
int y = DLOG_OFFSET + field * DLOG_STEP;
sd->control = new THSlider(DlogWindow, DLOG_ID_SLIDER + field,
x, y-BORDER, size, FontV+BORDER*2);
sd->text = new TStatic(DlogWindow, 0, "hoge", x + size + 2 * FontH, y,
FontH * 6, FontV, 6);
sd->size = size ;
sd->step = step;
sd->count = start ;
sd->ident = ident ;
if (maxwidth < x + size + 8 * FontH + RIGHTBORDER) {
maxwidth = x + size + 8 * FontH + RIGHTBORDER;
}
}
static int SliderConv( cSliderData *sd )
{
int slider ;
DataStruct *mark ;
if ( sd->ident >= 0 )
{
mark = StackTop();
StackPushInt( sd->count );
CallFunction( sd->ident, 1, mark+1 );
slider = mark[1].id.i ;
StackRelease( mark );
}
else
{
slider = sd->count ;
}
return slider ;
}
static void SliderDisplay( cSliderData *sd )
{
char str[10] ;
sprintf( str, "%6d", SliderConv( sd ) );
sd->text->SetText(str);
}
/* 入力待ち */
int DlogWait()
{
// new TButton(DlogWindow, IDOK, "決定", -100, -100, 0, 0);
// new TButton(DlogWindow, IDCANCEL, "中止", -100, -100, 0, 0);
int w;
w = 0;
for (int i = 0; i < DLOG_MAX_BUTTON; i++) {
if (buttontext[i][0] != '\0') {
int len;
len = dlogbuttonwidth[i] = strlen(buttontext[i]);
dlogbutton[i] = new TButton(DlogWindow, DLOG_ID_END+i, buttontext[i], 0,0,0,0);
w += (len+2) * FontH;
}
}
if (maxwidth < w) maxwidth = w;
int ret;
ret = DlogWindow->Execute();
delete DlogWindow;
DlogWindow = NULL;
Application->PumpWaitingMessages();
if (ret >= OFFSET) {
ret -= OFFSET;
} else if (ret == IDCANCEL) {
ret = 0;
} else if (ret == IDOK) {
ret = 1;
}
return ret;
}
/* 答を得る */
int DlogAnswer( int n, char *str, int *ip )
{
switch( Dlog[n].type )
{
case DLOG_STRING:
strcpy( str, Dlog[n].str.str );
return DLOG_STRING ;
case DLOG_TOGGLE:
*ip = Dlog[n].toggle.stat ;
return DLOG_TOGGLE ;
case DLOG_SELECT:
*ip = Dlog[n].select.stat ;
return DLOG_SELECT ;
case DLOG_SLIDER:
*ip = Dlog[n].slider.count ;
return DLOG_SLIDER ;
default:
return 0 ;
}
}
/*
* ファイル名入力
*/
int DlogFileOpen(char *str, int n, char *title, char *def, char *defext, char *selext)
{
//printf("title=%s\ndefault=%s\ndefext=%s\nselext=%s\n",
// title, def, defext, selext);
#if 0
TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
selext, 0, def, defext);
if (TFileOpenDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
strncpy(str, FileData.FileName, n-1);
str[n-1] = '\0';
return TRUE;
}
#else
if (def && *def) {
char *name, *p, initialdir[F_NAME_LEN];
strcpy(initialdir, def);
if ((p = strrchr(initialdir, '\\')) == NULL) {
p = initialdir;
}
if ((name = strrchr(p, '/')) == NULL) {
name = p;
}
if (*name == '/' || *name == '\\') {
*name = '\0';
name++;
p = initialdir;
} else {
p = NULL;
}
TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
selext, 0, p, defext);
strcpy(FileData.FileName, name);
if (TFileSaveDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
strncpy(str, FileData.FileName, n-1);
str[n-1] = '\0';
return TRUE;
}
} else {
TOpenSaveDialog::TData FileData(OFN_HIDEREADONLY,
selext, 0, "", defext);
if (TFileOpenDialog(GetModelWindow(), FileData,0,title).Execute() == IDOK) {
strncpy(str, FileData.FileName, n-1);
str[n-1] = '\0';
return TRUE;
}
}
#endif
return FALSE;
}