home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kyūkyoku!! X68000 Emulator
/
X68000Book.dat
/
mac
/
OLS
/
X68000
/
Ko-Window
/
kow142s.lzh
/
wsrv
/
manager.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-11-24
|
16KB
|
721 lines
/*
* âEâCâôâhâEâ}âlü[âWââÅêù¥è╓Éö
*
* Copyright T.Kobayashi
* 1990.1.1
*/
/*
1995 11/5 ö≈ÅCÉ│ COR.
1995 11/22 MAXPROCESSâVâôâ{âïé≡èOòöé╓
*/
#define COR 1
#include <stdio.h>
#include <mm_alloc.h>
#include <sys_doslib.h>
#include <iocslib.h>
#include <microstr.h>
#define MANAGER
#include "clip.h"
#include "window.h"
#include "manager.h"
#include "mouselib.h"
#include "error.h"
#include "vram.h"
#include "kanji.h"
#include "screen.h"
#include "sheet.h"
#include "process.h"
extern Sheet *BackPattern;
WindowClass RootWindow;
/*int CommonSize= 100;*/ /* Number of Entory */
int (*RootEventExec[MAXPROCESS])();
int Palet1= ( 20 << 11 ) + ( 20 << 6 ) + ( 20 << 1 );
int Palet3= ( 31 << 11 ) + ( 31 << 6 ) + ( 31 << 1 );
typedef struct _KeyBuf {
char function[20][32];
char spcial[12][6];
}
KeyBuf;
static KeyBuf KeySet = {
{
"\x1B[A", "\x1B[B", "\x1B[C", "\x1B[D", "\x1B[E",
"\x1B[F", "\x1B[G", "\x1B[H", "\x1B[I", "\x1B[J",
"\x1B[K", "\x1B[L", "\x1B[M", "\x1B[N", "\x1B[O",
"\x1B[P", "\x1B[Q", "\x1B[R", "\x1B[S", "\x1B[T"
},
{
"\x1B[U", "\x1B[V", "\x1B[W", "\x1B[X", "\x1B[Y",
"\x1B[Z", "\x1B[[", "\x1B[\\", "\x1B[]", "\x1B[^",
"\x1B[_", "\x1B[`"
}
};
static KeyBuf DefaultKeySet ;
#if COR
extern int ScreenH, ScreenV; /* 1991-94 COR. */
extern int MouseX, MouseY ;
extern int MouseCursor ;
extern int GraphicLock;
#else
static int ScreenH= 768, ScreenV= 512;
static int MouseX, MouseY ;
static int MouseCursor ;
#endif
static Sheet *BackSetPattern ;
static Common *CommonBuf= NULL;
static EventInfo Info;
static WindowClass *FocusWP;
/*
proto -s manager.c > temp
*/
static int RootEvent( WindowClass*, EventInfo* );
/*static int ChengeKeyCode( int );*/
/* Åëè·ë╗ */
WindowClass *ManagerInit( line, col )
int line ;
int col ;
{
int i ;
EventInfo info ;
if( line > 64 )
line= 64; /* 62 -> 64 COR. */
if( col > 128 )
col= 128;
FNCKEYGT( 0, (unsigned char*) &DefaultKeySet );
#if 0
if( !(CommonBuf= WindowMemoryAlloc( CommonSize*sizeof(Common*) )) ){
errput( "ïñùLù╠êµé¬é╞éΩé▄é╣é±\n" ); /* 1991 COR. */
EXIT2( 1 );
}
s_memclr_short( CommonSize*sizeof(Common), CommonBuf ); /* 24x100 */
#endif
for( i = 0 ; i < MAXPROCESS ; ++i )
RootEventExec[i] = NULL ;
MouseX = -1 ;
MouseY = -1 ;
MouseCursor = ON ;
Info.LeftStat = FALSE ;
Info.RightStat = FALSE ;
Info.Counter = 0 ;
info.option = EventOpen ;
info.x = 0 ;
info.y = 0 ;
info.h = col*8 ;
info.v = line*16 ;
WindowSet( &RootWindow, 0, 0, col*8, line*16, NULL, -1, RootEvent );
WindowSetEventAttr( &RootWindow, EventAttrDefault|EventMouseMoveON|EventNonON );
WindowSendEvent( &RootWindow, &info );
/* C_CLS_AL(); COR. */
ScreenInit();
return &RootWindow;
}
/* ëµû╩é╠Åëè·ë╗ */
void ScreenInit()
{
int h, v ;
/* int line ;*/
WindowClass *wp ;
WindowSetScreenMode( -1 );
#if 0
for( wp = RootWindow.window.childtop ; wp != NULL ; wp = wp->window.next )
{
if ( wp->window.attr & WindowAttrGraphicUse )
break ;
}
if ( wp == NULL )
{
SetGraphicMode( 0 );
}
else
{
SetGraphicMode( -1 );
/*G_CLR_ON();*/
}
#endif
KanjiInit();
C_FNKMOD( 3 );
WindowGetViewSize( &RootWindow, &h, &v );
#if 0
line = v / 16 ;
if ( line < 32 )
C_WINDOW( line, 32-line );
else
#endif
C_CUROFF();
FNCKEYST( 0, (unsigned char*)&KeySet );
TPALET( 0, 1 );
TPALET( 2, 0 );
TPALET( 1, Palet1 );
TPALET( 3, Palet3 );
WindowRootScroll( 0, 0 );
MouseInitialize();
MouseRegion( 0, 0, h-1, v-1 );
VramRegion( 0, 0, h-1, v-1 );
PutCVtInit();
WindowRedraw( & RootWindow );
for( wp= RootWindow.window.childtop ; wp ; wp= wp->window.next ){
WindowRedraw( wp );
}
if( GraphicLock ){
TGUSEMD( 0, 2 ); /* Lock */
}
}
/* ÅIù╣Åêù¥ */
void ManagerQuit()
{
WindowClass *p ;
Info.option = EventClose ;
for( p = RootWindow.window.childtop ; p != NULL ; p = p->window.next )
WindowSendEvent( p, &Info );
WindowClose( & RootWindow );
/* ManagerQuit() é╠îπé╔é═òKé╕ ServerQuit() é¬î─é╬éΩéΘéτé╡éóüB
ServerQuit() ôαé┼éα ScreenQuit() é≡Ä└ìsé╡é─é¿éΦéQôxô«ì∞é╖éΘé▒é╞é╔é╚éΘ
é╠é┼âRâüâôâgâAâEâg 1992 10/6 H.Ogasawara (COR.) */
/* ScreenQuit();*/
}
/* ëµû╩é╠ÅIù╣Åêù¥ */
void ScreenQuit()
{
PutCVtQuit();
KanjiQuit();
WindowRootScroll( 0, 0 );
C_WINDOW( 0, 31 );
C_FNKMOD( 0 );
C_CURON();
FNCKEYST( 0, (unsigned char*)&DefaultKeySet );
TPALET( 0, -2 ); /* âVâXâeâÇÆlé╔û▀é╖éµéñÅCÉ│ 1991 COR.*/
TPALET( 1, -2 );
TPALET( 2, -2 );
TPALET( 3, -2 );
/* if( GraphicMode & WindowAttrGraphicUse )
TGUSEMD( 0, 0 );*/
if( GraphicLock ){
TGUSEMD( 0, 0 ); /* UnLock */
}
C_WIDTH( 0 ); /* 1991 COR. */
MouseQuit();
}
/* âpâîâbâgé╠É▌ÆΦ */
void SetPalet( p1, p3 )
int p1, p3 ;
{
Palet1 = p1 ;
Palet3 = p3 ;
TPALET( 1, Palet1 );
TPALET( 3, Palet3 );
}
/* âïü[âgé╠âCâxâôâgÅêù¥É▌ÆΦ */
void SetRootEvent( id, exec )
int id ;
int (*exec)();
{
ErrorCheck( 0 <= id && id < MAXPROCESS, "SetRootEvent" );
RootEventExec[id] = exec ;
}
static int RootEvent( wp, info )
WindowClass *wp ;
EventInfo *info ;
{
int i ;
WindowClass *cwp ;
EventInfo info2 ;
static WindowClass *lastwp ;
static DrawBuf buf[1] ;
if ( info->option != EventNon )
{
for( i = 0 ; i < MAXPROCESS ; ++i )
{
if ( RootEventExec[i] != NULL )
{
if ( SendEvent( i, RootEventExec[i], wp, info ) )
return( TRUE );
}
}
}
/* 1991 COR. */
{
/* [XF5]+[CTRL]+[XF2]+[BS] */
if( (BITSNS(11) & 2) && (BITSNS(1) & 128) && (BITSNS(10) & 64) && (BITSNS(14) & 2 ) ){
WindowSendSignal( 0, 1, 0 ); /* SignalKill */
/*return TRUE; û▀é┴é─ùêé╚éó*/
}
}
/*************/
switch( info->option )
{
case EventOpen:
lastwp= NULL;
return TRUE;
case EventRedraw :
DrawSetPattern( buf, GetBackPattern() );
WindowDraw( wp, buf, 1 );
return TRUE;
case EventKey :
if ( FocusWP != NULL )
return WindowSendEvent( FocusWP, info );
case EventMouseSwitch :
case EventMouseMove :
case EventNon :
cwp = WindowGetChild( wp, info );
if( lastwp != cwp ){
/* info2= *info;*/
s_memcpy_simple( sizeof(EventInfo), &info2, info );
if( lastwp != NULL && lastwp->window.check != 0 &&
!( lastwp->window.attr & WindowAttrInvisible ) ){
info2.option = EventMouseOut ;
WindowSendEvent( lastwp, &info2 );
}
if( cwp != NULL ){
info2.option = EventMouseEnter ;
WindowSendEvent( cwp, &info2 );
}
lastwp = cwp ;
}
if( cwp != NULL && info->option != EventNon )
return WindowSendEvent( cwp, info );
else
return FALSE;
default :
ErrorCheck( FALSE, "RootEvent" );
}
return TRUE;
}
void RootZoomOperation( info )
EventInfo *info ;
{
int h, v ;
info->x = HomeX ;
info->y = HomeY ;
WindowGetViewSize( &RootWindow, &h, &v );
info->h = ScreenH < h ? ScreenH : h ;
info->v = ScreenV < v ? ScreenV : v ;
}
/* âtâHü[âJâXâEâCâôâhâEé╠É▌ÆΦ */
void SetFocus( wp )
WindowClass *wp ;
{
FocusWP = wp ;
}
/* âoâbâNé╠âpâ^ü[âôé╠âZâbâg */
void SetBackPattern( sp )
void *sp ;
{
BackSetPattern = sp ;
WindowRedraw( & RootWindow );
}
/* âoâbâNé╠âpâ^ü[âôé≡ô╛éΘ */
void *GetBackPattern()
{
if ( BackSetPattern == NULL )
return( BackPattern );
else
return( BackSetPattern );
}
/* â}âEâXâJü[â\âïé╠É▌ÆΦ */
void WindowMouseCursor( sw )
int sw ;
{
if ( sw )
{
MouseCursor = ON ;
MouseMove( MouseX, MouseY );
MouseCursorOn();
}
else
{
MouseCursor = OFF ;
MouseCursorOff();
}
}
/* ïñùLù╠êµé╠É▌ÆΦ */
/* 1992 H.Ogasawara */
/* 1995 11/22 mm_realloc é≡Ägùpé╖éΘéµéñëⁿù╟(Äßè▒é╠ìéæ¼ë╗é╠é═é╕) */
/* 1995 11/24 ïñùLù╠êµéαÄ⌐ô«ègÆúé╖éΘéµéñé╔é╡é╜ */
#define NameCmp(str1,str2) ( *(str1) == *(str2) && !n_strcmp( str1, str2 ) )
static Common *
SearchCommon( name )
char *name;
{
Common *cp= CommonBuf;
for(; cp ; cp= cp->next ){
if( cp->pointer && NameCmp( cp->name, name ) )
return cp;
}
return NULL;
}
void *
WindowGetCommon( name, len )
char *name;
int len;
{
Common *cp= SearchCommon( name );
{
/*v_format_put( "GetCommon '%s' %d\r\n", name, len );*/
}
if( !len )
return cp ? cp->pointer+sizeof(int) : NULL;
if( cp ){
if( cp->pointer= realloc( cp->pointer, len+ sizeof(int)*2 ) )
return cp->pointer+ sizeof(int);
}else{
for( cp= CommonBuf ; cp ; cp= cp->next ){
if( !cp->pointer )
goto _CommonSet;
}
if( cp= WindowMemoryAlloc( sizeof(Common) ) ){
cp->next= CommonBuf;
CommonBuf= cp;
_CommonSet:
s_strcpy( cp->name, name );
if( cp->pointer= WindowMemoryAlloc( len+ sizeof(int)*2 ) ){
*((int*)cp->pointer)= -1;
return cp->pointer+ sizeof(int);
}
}
}
ErrorCheck( FALSE, "ïñùLù╠êµé¬èmò█é┼é½é▄é╣é±" );
return NULL;
}
/* ïñùLù╠êµé╠èJò· */
int
WindowResetCommon( name )
char *name;
{
Common *cp= SearchCommon( name );
{
/*v_format_put( "ResetCommon '%s' %x\r\n", name, cp );*/
}
if( cp ){
WindowMemoryFree( cp->pointer );
cp->pointer= NULL;
return TRUE;
}
return FALSE;
}
/* âCâxâôâgæ╥é┐ */
/*void EventWait( sw )
int sw ;*/
void EventWait()
{
WindowClass *cwp ;
if ( GetEventInfo( &Info ) )
{
Info.Counter ++ ;
WindowSendEvent( &RootWindow, &Info );
}
else
{
/* âüâé 1991 COR.
(1) EventInterval é≡ Send é╡é╚éóÅΩìçé═üAÆPé╔âèâXâgé≡ÆHéΘé╛é»é┼âïü[âvôαé╠
Ä₧è╘æ╥é┐é═é┘é┌0é┼é╖üBé┬é▄éΦï≤âïü[âvé╔ôÖé╡éóé╠é┼üAé╗é╠ÅΩìçéαûêë± Event
é≡ Check é╖éΘé╠é═û│æ╩é╔é╚éΦé▄é╖üBé╗é▒é┼ Check é═ EventInterval é≡ Send
é╡é╜ÅΩìçé╔î└éΦüAé╗éñé┼é╚éóÅΩìçé═ 32 âEâBâôâhâEé╔éPë±é╠é╛é»â`âFâbâNé≡
ìsé╚éóé▄é╖üB( EventCheck é═îïì\ÅdéóÅêù¥é┼é╖üBô┴é╔ ASK é¬ægé▌ì₧é▄éΩé─
éóéΘé╞üEüE)
(2) é▄é╜ EventInterval é≡ Send é╡é╜ÅΩìçé┼éαüAâAâvâèâPü[âVâçâôé┼ë±Éöé≡âJâE
âôâgé╡ë╜éαé╣é╕é╔ return é╖éΘÅΩìçé¬é┘é╞é±é╟é┼é╖üBé╗éΩé≡ìlù╢é╡é─üAéαé╡
FALSE é¬ò╘é┴é─é½é╜éτ Check é≡Å╚ù¬é╖éΘéµéñé╔é╡é─é▌é▄é╡é╜üBé╜é╛é╡üAé▒é╠
ÅΩìçì┼Æßé┼éα 8 âEâBâôâhâEé╔éPë±é═ Check é≡ìsé╚éóé▄é╖üB
(1) é╔é┬éóé─é═ë╜é╠ûΓæΦéαé╚éóé═é╕é┼é╖üB(2) é╔é┬éóé─é═éáéΘÆ÷ôxâTü[âoü[
é╠Ädùlé╔è╓é╖éΘòöò¬é╚é╠é┼üAéáé▄éΦŃÄΦé╔Åæé½è╖éªéΘé▒é╞é═é┼é½é▄é╣é±üB
EventInterval é╔è╓é╖éΘâvâëâCâIâèâeâBé═âTü[âoü[é┼âJâEâôâgé╡é─éαéóéóé┼
é╡éσéñé¬üAâAâvâèæñé┼Ä₧è╘é≡ÄQÅ╞é╖éΘòKùvé¬Åoé─é½é╜ÅΩìçéΓìíé▄é┼é╠î▌è╖ɽ
éαìçé╣éΘé╞üA(2) é╠Ädùlé┼Å\ò¬é⌐éαé╡éΩé▄é╣é±üB
*/
#define EVENTMAX 32
int i= 0;
Info.option = EventInterval ;
cwp = RootWindow.window.childtop ;
while( cwp != NULL )
{
#define INTERVAL 1
if ( cwp->window.eventattr & EventIntervalON ){
#if !INTERVAL
WindowSendEvent( cwp, &Info );
if( CheckEventInfo( &Info ) ) /* 1991 COR. */
break;
i= 0;
#else
if( WindowSendEvent( cwp, &Info ) ){
if ( CheckEventInfo( &Info ) ) /* 1991 COR. */
break;
i= 0;
}else{
if( i< 16 )
i= 16;
}
#endif
}else if( ++i >= EVENTMAX ){ /* no count */
if ( CheckEventInfo( &Info ) ) /* 1991 COR. */
break;
i= 0;
}
cwp = cwp->window.next ;
}
if ( cwp == NULL )
{
unsigned int i;
extern int BGmode;
if( BGmode )
CHANGE_PR(); /* wsrv+7 */
Info.option = EventNon ;
Info.x= ( (i= MS_CURGT()) >>16 );
Info.y= ( i & 0xffff );
/* MouseGetPosition( &(Info.x), &(Info.y) );*/
WindowSendEvent( &RootWindow, &Info );
}
#if 0 /* 1991 12/16 NEWëµû╩É▌ÆΦâïü[â`âôé╠ì╠ùpé╔éµéΦòsùpé╔é╚éΘ */
if ( GraphicMode & WindowAttrGraphicUse )
{
/* 964.w 9dc.b */
if ( APAGE( -1 ) < 0 || TGUSEMD( 0, -1 ) != 2 )
{
WindowClass *wp ;
/* G_CLR_ON();*/
TGUSEMD( 0, 2 );
for( wp = RootWindow.window.childtop ; wp != NULL ; wp = wp->window.next )
{
if ( wp->window.attr & WindowAttrGraphicUse )
WindowRedraw( wp );
}
}
}
#endif
}
}
/* âCâxâôâgÅεò±é╠èmò█ */
/* 1991 COR. âCâxâôâgè╓ÿAé═ getevent.s é╔ê┌ìsé╡é▄é╡é╜ */
/*#if !COR*/
#if 0
int
GetEventInfo( info )
EventInfo *info;
{
int flag= FALSE;
int left,
right;
info->LeftON= info->LeftOFF= info->RightON= info->RightOFF= FALSE;
info->MoveFlag= FALSE;
info->KeyCode= 0;
info->option= EventNon;
if( MouseCursor ){
unsigned int i= MS_GETDT();
left= (i & 0x100) == 0x100;
right= i & 1;
info->x= ( (i= MS_CURGT()) >>16 );
info->y= ( i & 0xffff );
if( info->LeftStat != left ){
flag= TRUE;
info->option= EventMouseSwitch;
if( left )
info->LeftON= TRUE;
else
info->LeftOFF= TRUE;
info->LeftStat= left;
}
if( info->RightStat != right ){
flag= TRUE;
info->option= EventMouseSwitch;
if( right )
info->RightON= TRUE;
else
info->RightOFF= TRUE;
info->RightStat= right;
}
if( info->x != MouseX || info->y != MouseY ){
if( flag || right || left )
info->option= EventMouseSwitch;
else
info->option= EventMouseMove;
flag= TRUE;
info->MoveFlag= TRUE;
MouseX= info->x;
MouseY= info->y;
if( MouseX < HomeX )
HomeX= MouseX;
if( MouseX >= HomeX +ScreenH )
HomeX= MouseX - ScreenH +1;
if( MouseY < HomeY )
HomeY= MouseY;
if( MouseY >= HomeY +ScreenV )
HomeY= MouseY - ScreenV +1;
WindowRootScroll( HomeX, HomeY );
}
}else{
info->x= MouseX;
info->y= MouseY;
}
if( ! flag ){
if( K_KEYSNS() ){
info->KeyCode= K_KEYINP() & 0xff;
flag= TRUE;
info->option= EventKey;
info->KeyCode= ChengeKeyCode( info->KeyCode );
}
}
if( flag )
info->ShiftStat= B_SFTSNS();
return flag;
}
/* if( info->KeyCode= KeyGet() ) */
/* MouseGetSwitch( &left, &right );*/
/* MouseGetPosition( &(info->x), &(info->y) ); */
/* âLü[âRü[âhé╠ò╧è╖ */
static int ChengeKeyCode( code )
int code ;
{
if ( code == 0x1B && KeySense() == '[' )
{
KeyGet();
code = KeyGet();
if ( 'A' <= code && code <= '`' )
{
return( 0x8000 + code - '@' );
}
}
return( code );
}
/* âCâxâôâgâ`âFâbâN */ /* 1991 COR. */
int CheckEventInfo( info )
EventInfo *info;
{
int left;
unsigned int i= MS_GETDT();
left= (i & 0x100) == 0x100;
if( info->LeftStat != left || info->RightStat != (i&1) )
return TRUE;
info->x= ( (i= MS_CURGT()) >>16 );
info->y= ( i & 0xffff );
if( info->x != MouseX || info->y != MouseY )
return TRUE;
if( K_KEYSNS() & 0xff )
return TRUE;
return FALSE;
/* MouseGetSwitch( &left, &right );*/
/* MouseGetPosition( &(info->x), &(info->y) );*/
/* if ( KeySense() )*/
}
#endif
/* âüâéâèè╟ù¥ù╠êµ */
typedef struct {
short id;
short size; /* é▒éΩé┴é─ 64K(or32K) é▄é┼é⌐!? */
}
MMA ;
/* âüâéâèé╠èmò█ */
void *WindowMemoryAlloc( size )
int size ;
{ /* éαé╡é⌐é╡é─ëⁿê½üIüHé▓é▀é±é╚é│éó 1995 11/22 COR. */
void *p= malloc( size );
/*v_format_put( "malloc %d %x\r\n", size, p );*/
ErrorCheck( p, "âqü[âvù╠êµé¬æ½éΦé▄é╣é±" );
return p;
#if 0
MMA *h ;
h = (MMA*)malloc( size + sizeof( MMA ) );
ErrorCheck( h != NULL, "âqü[âvù╠êµé¬æ½éΦé▄é╣é±" );
h->id = 4321 ;
h->size = size ;
/* memset( (char*)( h + 1 ), 0, size );*/
/* 1992,8 â[âìâNâèâAìφÅ£ H.Ogasawara(COR.) */
return( (void*)( h + 1 ) );
#endif
}
/* âüâéâèé╠èJò· */
void WindowMemoryFree( p )
void *p ;
{
free( p );
/*v_format_put( "free %x\r\n", p );*/
#if 0
MMA *h ;
h = (MMA*)p - 1 ;
ErrorCheck( h->id == 4321, "âüâéâèè╟ù¥ù╠êµé¬öjë≤é│éΩé▄é╡é╜üIüI" );
h->id = 0 ;
free( (char*)h );
#endif
}
/* :vi:se ts=4 sw=4: */