home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
POLYEDIT.LZH
/
MODEL
/
DLOG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-03-21
|
15KB
|
740 lines
/*
* ダイヤログボックス制御
*
* Copyright T.Kobayashi 1994.7.24
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define iskanji( c ) ( ( (c) & 0x80 ) != 0 )
#include "graph.h"
#include "input.h"
#include "ml.h"
#include "dlog.h"
#include "model.h"
#define ESC 0x1B
#define RET 0x0D
#define TAB 9
#define BS 8
#define DEL 7
#define FUNC_DEL KEY_DEL /*(0x8000 + 24)*/
#define LEFT ('S'-'A'+1)
#define RIGHT ('D'-'A'+1)
#define FUNC_LEFT KEY_LEFT /*(0x8000 + 26)*/
#define FUNC_RIGHT KEY_RIGHT /*(0x8000 + 27)*/
#define UP ('E'-'A'+1)
#define DOWN ('X'-'A'+1)
#define FUNC_UP KEY_UP /*(0x8000 + 25)*/
#define FUNC_DOWN KEY_DOWN /*(0x8000 + 28)*/
#define EVENT_MOUSE 0
#define EVENT_KEY 1
#define DLOG_STEP FontV
#define DLOG_OFFSET (FontV*2)
#define MAX_FIELD 30
#define DLOG_MAX_BUTTON 5
extern int QuitFlag;
static int x1, y1, x2, y2 ;
static DlogData Dlog[MAX_FIELD];
static int KeyField ;
static void SliderDisplay( SliderData* );
static int SliderConv( SliderData* );
static int _DlogWait( void );
static int isSwitch( EventData* );
static void ChangeKeyField( void );
static void EventString( int, int );
static void EventToggle( int );
static void EventSelect( int );
static void EventSlider( int );
static int ConvertNumpadToChar(int);
EventData DlogSwitch[DLOG_MAX_BUTTON];
int DlogSwitches;
#if 0
EventData SwitchOK, SwitchCancel ;
/* ダイヤログウインドウのオープン */
void DlogOpen( title, fields, sw )
char *title ;
int fields ;
int sw ;
#endif
/* ダイヤログウインドウのオープン */
void DlogOpen( title, fields, button )
char *title ;
int fields ;
char *button[];
{
int i, x ;
ViewCursor( OFF );
#ifdef X68K
x1 = 80 ;
x2 = DISPLAY_X - 80 ;
y1 = 80 ;
#endif
#ifdef PC98
x1 = 24 ;
x2 = DISPLAY_X - 24 ;
y1 = 32 ;
#endif
#ifdef PC
x1 = 80 ;
x2 = DISPLAY_X - 80 ;
y1 = 80 ;
#endif
#ifdef WINDOWS
x1 = 80 ;
x2 = DISPLAY_X - 80 ;
y1 = 80 ;
#endif
y2 = y1 + DLOG_STEP * fields + FontV * 5 ;
graph_push(x1, y1, x2-x1+1, y2-y1+1);
#ifdef X68K
graph_fill( x1+1, y1+1, x2-1, y2-1, TMP_COLOR );
#endif
graph_fill( x1+1, y1+1, x2-1, y2-1, FRAME_COLOR );
graph_box( x1, y1, x2, y2, TRUE );
graph_puts( title, x1+16, y1+3, FRAME_COLOR << 4 );
graph_line( x1+1, y1+21, x2-1, y1+21, 0 );
graph_line( x1, y1+22, x2, y1+22, 7 );
x = x2 - 36;
for (i = 0; button[i] != NULL; i++) {
int len;
len = strlen(button[i]);
if (len == 0) {
DlogSwitch[i].x1 = DlogSwitch[i].y1 = DlogSwitch[i].x2 = DlogSwitch[i].y2 = 0;
} else {
DlogSwitch[i].x2 = x;
DlogSwitch[i].x1 = x - (len+2) * FontH;
DlogSwitch[i].y1 = y2 - 32 - 4;
DlogSwitch[i].y2 = DlogSwitch[i].y1 + FontV + 9;
graph_box( DlogSwitch[i].x1, DlogSwitch[i].y1, DlogSwitch[i].x2, DlogSwitch[i].y2, TRUE );
graph_puts( button[i], DlogSwitch[i].x1+FontH, DlogSwitch[i].y1+4, FRAME_COLOR << 4 );
x -= (len+3) * FontH;
}
}
DlogSwitches = i;
#if 0
if ( sw )
{
SwitchOK.x1 = x2 - 132 ;
SwitchOK.y1 = y2 - 32 - 4 ;
SwitchOK.x2 = x2 - 88 ;
SwitchOK.y2 = SwitchOK.y1 + FontV + 9 ;
graph_box( SwitchOK.x1, SwitchOK.y1, SwitchOK.x2, SwitchOK.y2, TRUE );
graph_puts( "決定", SwitchOK.x1+8, SwitchOK.y1+4, FRAME_COLOR << 4 );
SwitchCancel.x1 = x2 - 80 ;
SwitchCancel.y1 = y2 - 32 - 4 ;
SwitchCancel.x2 = x2 - 36 ;
SwitchCancel.y2 = SwitchCancel.y1 + FontV + 9 ;
graph_box( SwitchCancel.x1, SwitchCancel.y1, SwitchCancel.x2, SwitchCancel.y2, TRUE );
graph_puts( "中止", SwitchCancel.x1+8, SwitchCancel.y1+4, FRAME_COLOR << 4 );
}
else
{
SwitchOK.x1 = x2 - 80 ;
SwitchOK.y1 = y2 - 32 - 4 ;
SwitchOK.x2 = x2 - 36 ;
SwitchOK.y2 = SwitchOK.y1 + FontV + 9 ;
graph_box( SwitchOK.x1, SwitchOK.y1, SwitchOK.x2, SwitchOK.y2, TRUE );
graph_puts( "確認", SwitchOK.x1+8, SwitchOK.y1+4, FRAME_COLOR << 4 );
SwitchCancel.x1 = 0 ;
SwitchCancel.y1 = 0 ;
SwitchCancel.x2 = 0 ;
SwitchCancel.y2 = 0 ;
}
#endif
for( i = 0 ; i < MAX_FIELD ; i++ )
Dlog[i].type = 0 ;
KeyField = -1 ;
}
/* メッセージの表示 */
int DlogMessage( field, msg )
int field ;
char *msg ;
{
graph_puts( msg, x1+16, y1+DLOG_OFFSET+field*DLOG_STEP, FRAME_COLOR << 4 );
return x1 + 16 + 16 + strlen( msg ) * FontH ;
}
/* 文字列入力フィールド表示 */
void DlogString( field, msg, str, max, wild )
int field ;
char *msg ;
char *str ;
int max ;
char *wild;
{
StringData *sd ;
Dlog[field].type = DLOG_STRING ;
sd = &Dlog[field].str ;
sd->func = EventString ;
sd->max = max ;
strcpy( sd->str, str );
sd->x1 = DlogMessage( field, msg );
sd->y1 = y1 + DLOG_OFFSET + field * DLOG_STEP ;
sd->x2 = sd->x1 + max * FontH - 1 ;
sd->y2 = sd->y1 + FontV - 1 ;
graph_puts( str, sd->x1, sd->y1, FRAME_COLOR << 4 );
graph_box( sd->x1-2, sd->y1-2, sd->x2+2, sd->y2+2, FALSE );
if ( KeyField < 0 )
{
KeyField = field ;
Locate( sd->x1/FontH + strlen( str ), sd->y1/FontV );
}
CursorON();
}
/* トグルスイッチ表示 */
void DlogToggle( field, msg, str, sw )
int field ;
char *msg, *str ;
int sw ;
{
ToggleData *td ;
Dlog[field].type = DLOG_TOGGLE ;
td = &Dlog[field].toggle ;
td->func = EventToggle ;
td->x1 = DlogMessage( field, msg );
td->y1 = y1 + DLOG_OFFSET + field * DLOG_STEP ;
td->x2 = td->x1 + strlen( str ) * FontH ;
td->y2 = td->y1 + FontV - 1 ;
td->stat = sw ;
graph_puts( str, td->x1, td->y1, FRAME_COLOR << 4 );
graph_box( td->x1-4, td->y1-4, td->x2+4, td->y2+4, ! sw );
}
/* 選択スイッチ表示 */
void DlogSelect( field, msg, item, stat )
int field ;
char *msg ;
char **item ;
int stat ;
{
int i, len, n, max ;
int x ;
SelectData *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 ;
sd->func = EventSelect ;
sd->x1 = DlogMessage( field, msg );
sd->y1 = y1 + DLOG_OFFSET + field * DLOG_STEP ;
sd->x2 = sd->x1 + ( max + 1 ) * FontH * n ;
sd->y2 = sd->y1 + FontV - 1 ;
sd->step = ( max + 1 ) * FontH ;
sd->sels = n ;
sd->stat = stat ;
x = sd->x1 ;
for( i = 0 ; i < n ; i++ )
{
graph_puts( item[i], x, sd->y1, FRAME_COLOR << 4 );
graph_box( x-4, sd->y1-4, x+sd->step-5, sd->y2+4, ! ( stat == i ) );
x += sd->step ;
}
}
/* スライドスイッチ表示 */
void DlogSlider( field, msg, size, step, start, ident )
int field ;
char *msg ;
int size, step, start, ident ;
{
SliderData *sd ;
Dlog[field].type = DLOG_SLIDER ;
sd = &Dlog[field].slider ;
sd->func = EventSlider ;
sd->x1 = DlogMessage( field, msg );
sd->y1 = y1 + DLOG_OFFSET + field * DLOG_STEP + 3 ;
sd->x2 = sd->x1 + size + FontV ;
sd->y2 = sd->y1 + 10 - 1 ;
sd->size = size ;
sd->step = step;
sd->count = start ;
sd->ident = ident ;
graph_box( sd->x1-1, sd->y1-1, sd->x2+1, sd->y2+1, FALSE );
SliderDisplay( sd );
}
static void SliderDisplay( sd )
SliderData *sd ;
{
int slider ;
char str[10] ;
slider = sd->x1 + sd->count * sd->size / (sd->step-1);
graph_fill( sd->x1, sd->y1, sd->x2, sd->y2, FRAME_COLOR );
graph_box( slider, sd->y1, slider+FontV, sd->y2, TRUE );
sprintf( str, "%6d", SliderConv( sd ) );
graph_puts( str, sd->x2 + 16, sd->y1 - 2, FRAME_COLOR<<4 );
}
static int SliderConv( sd )
SliderData *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 ;
}
/* 入力待ち */
int DlogWait()
{
int ret ;
ret = _DlogWait();
CursorOFF();
if (graph_pop() == FALSE) {
ViewFrame();
ViewLineAll( x1, y1, x2, y2, TRUE );
DrawTitleBar();
DrawUserButtonAll();
DrawControlPanel();
}
ViewCursor( ON );
return ret ;
}
static int _DlogWait()
{
int i ;
for(;;)
{
WaitMouseOrKey();
if (QuitFlag) {
return 0;
}
switch( KeyCode )
{
case ESC:
return 0 ;
case RET:
case KEY_NUMPAD_ENTER:
return RET ;
case TAB:
if (ShiftStat & 1) {
for( i = KeyField - 1 ; i >= 0 ; i-- )
{
if ( Dlog[i].type == DLOG_STRING )
break ;
}
if (i < 0) {
for (i = MAX_FIELD-1; i >= KeyField; i--) {
if ( Dlog[i].type == DLOG_STRING )
break ;
}
}
if ( i >= 0 )
{
KeyField = i ;
ChangeKeyField();
}
} else {
for( i = KeyField + 1 ; i < MAX_FIELD ; i++ )
{
if ( Dlog[i].type == DLOG_STRING )
break ;
}
if (i >= MAX_FIELD) {
for (i = 0; i <= KeyField; i++) {
if ( Dlog[i].type == DLOG_STRING )
break ;
}
}
if ( i < MAX_FIELD )
{
KeyField = i ;
ChangeKeyField();
}
}
break;
case UP:
case FUNC_UP:
for( i = KeyField - 1 ; i >= 0 ; i-- )
{
if ( Dlog[i].type == DLOG_STRING )
break ;
}
if ( i >= 0 )
{
KeyField = i ;
ChangeKeyField();
}
break ;
case DOWN:
case FUNC_DOWN:
for( i = KeyField + 1 ; i < MAX_FIELD ; i++ )
{
if ( Dlog[i].type == DLOG_STRING )
break ;
}
if ( i < MAX_FIELD )
{
KeyField = i ;
ChangeKeyField();
}
break ;
default:
if ( KeyCode > 0 && KeyField >= 0 )
(*Dlog[KeyField].event.func)( KeyField, EVENT_KEY );
}
if ( MouseLeft || MouseRight )
{
for( i = 0 ; i < MAX_FIELD ; i++ )
{
if ( Dlog[i].type > 0 &&
Dlog[i].event.x1 < MouseX && MouseX < Dlog[i].event.x2 &&
Dlog[i].event.y1 < MouseY && MouseY < Dlog[i].event.y2 )
{
(*Dlog[i].event.func)( i, EVENT_MOUSE );
}
}
for (i = 0; i < DlogSwitches; i++) {
if (isSwitch( &(DlogSwitch[i]))) {
return i;
}
}
#if 0
if ( isSwitch( &SwitchOK ) )
return TRUE ;
if ( isSwitch( &SwitchCancel ) )
return FALSE ;
#endif
}
}
return 0 ;
}
static int isSwitch( sw )
EventData *sw ;
{
if ( sw->x1 <= MouseX && MouseX <= sw->x2 && sw->y1 <= MouseY && MouseY <= sw->y2 )
{
graph_box( sw->x1, sw->y1, sw->x2, sw->y2, FALSE );
WaitMouseOff();
return TRUE ;
}
return FALSE ;
}
static void ChangeKeyField()
{
int x, y ;
StringData *sd ;
GetCursorPosition( &x, &y );
sd = &Dlog[KeyField].str ;
y = sd->y1 / FontV ;
if ( x > sd->x1 / FontH + strlen( sd->str ) )
x = sd->x1 / FontH + strlen( sd->str );
Locate( x, y );
}
/* 文字列入力のイベント処理ルーチン */
static void EventString( n, event )
int n ;
int event ;
{
int keycode;
int x, y ;
int i, j, px, top, cur, len ;
char *p ;
static int kanji ;
StringData *sd ;
sd = &Dlog[n].str ;
switch( event )
{
case EVENT_MOUSE:
x = ( MouseX - sd->x1 ) / FontH ;
if ( x > strlen( sd->str ) )
x = strlen( sd->str );
Locate( x + sd->x1/FontH, MouseY/FontV );
KeyField = n ;
break ;
case EVENT_KEY:
GetCursorPosition( &cur, &y );
y = sd->y1 / FontV ;
top = sd->x1 / FontH ;
cur = cur - top ;
Locate( top+cur, y );
p = sd->str + cur ;
len = strlen( sd->str );
px = -1 ;
kanji = 0 ;
keycode = ConvertNumpadToChar(KeyCode);
switch( keycode )
{
case BS :
if ( cur > 1 && iskanji( *(p-2) ) )
{
cur -= 2 ;
p -= 2 ;
}
else if ( cur > 0 )
{
cur -- ;
p -- ;
}
else
break ;
case DEL :
case FUNC_DEL :
if ( cur < len )
{
if ( iskanji( *p ) )
{
memcpy( p, p+2, len - cur );
len -= 2 ;
}
else
{
memcpy( p, p+1, len - cur );
len -- ;
}
sd->str[len] = '\0' ;
px = cur ;
}
break ;
case LEFT :
case FUNC_LEFT :
i = 0 ;
do
{
j = i ;
if ( iskanji( sd->str[i] ) )
i += 2 ;
else
i ++ ;
}
while( i < cur );
cur = j ;
break ;
case RIGHT :
case FUNC_RIGHT :
if ( cur < len && cur < sd->max - 1 )
{
if ( iskanji( *p ) )
cur += 2 ;
else
cur ++ ;
}
break ;
default :
if ( ( keycode & 0xFF ) >= ' ' )
{
if ( len < sd->max )
memcpy( p+1, p, len-cur+1 );
*p = keycode ;
if ( kanji == 0 )
{
if ( iskanji( keycode ) )
{
px = -1 ;
kanji = keycode ;
}
else
px = cur ;
}
else
{
px = cur - 1 ;
p -- ;
kanji = 0 ;
}
if ( cur < sd->max - 1 )
cur ++ ;
}
break ;
}
if ( px >= 0 )
{
graph_puts( sd->str, sd->x1, sd->y1, FRAME_COLOR << 4 );
graph_puts( " ", sd->x1+strlen(sd->str)*FontH, sd->y1, FRAME_COLOR << 4 );
}
Locate( top+cur, y );
break ;
}
}
/* トグルスイッチのイベント処理ルーチン */
static void EventToggle( n )
int n ;
{
ToggleData *td ;
td = &Dlog[n].toggle ;
td->stat = ! td->stat ;
graph_box( td->x1-4, td->y1-4, td->x2+4, td->y2+4, ! td->stat );
WaitMouseOff();
}
/* 選択スイッチのイベント処理ルーチン */
static void EventSelect( n )
int n ;
{
int i, x ;
SelectData *sd ;
sd = &Dlog[n].select ;
n = ( MouseX + 4 - sd->x1 ) / sd->step ;
if ( 0 <= n && n < sd->sels )
{
for( i = 0 ; i < 2 ; i++ )
{
x = sd->x1 + sd->step * sd->stat ;
graph_box( x-4, sd->y1-4, x+sd->step-5, sd->y2+4, i == 0 );
sd->stat = n ;
}
}
WaitMouseOff();
}
/* スライドスイッチのイベント処理ルーチン */
static void EventSlider( n )
int n ;
{
SliderData *sd ;
sd = &Dlog[n].slider ;
sd->count = ((MouseX - 8 - sd->x1) * (sd->step-1) + sd->size/2) / sd->size;
if ( sd->count < 0 )
sd->count = 0 ;
if ( sd->count >= sd->step)
sd->count = sd->step - 1 ;
SliderDisplay( sd );
}
/* 答を得る */
int DlogAnswer( n, str, ip )
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 ;
}
}
static int ConvertNumpadToChar(int c)
{
switch (c) {
case KEY_NUMPAD_0:
return '0';
case KEY_NUMPAD_1:
return '1';
case KEY_NUMPAD_2:
return '2';
case KEY_NUMPAD_3:
return '3';
case KEY_NUMPAD_4:
return '4';
case KEY_NUMPAD_5:
return '5';
case KEY_NUMPAD_6:
return '6';
case KEY_NUMPAD_7:
return '7';
case KEY_NUMPAD_8:
return '8';
case KEY_NUMPAD_9:
return '9';
case KEY_NUMPAD_SLASH:
return '/';
case KEY_NUMPAD_ASTERISK:
return '*';
case KEY_NUMPAD_MINUS:
return '-';
case KEY_NUMPAD_PLUS:
return '+';
case KEY_NUMPAD_EQUAL:
return '=';
case KEY_NUMPAD_ENTER:
return 0x0d;
case KEY_NUMPAD_COMMA:
return ',';
case KEY_NUMPAD_PERIOD:
return '.';
default:
return c;
}
}