state.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 760 行 · 第 1/2 页
C
760 行
/****************************************************************************
*
* 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: Module to contain various pieces of state information.
*
****************************************************************************/
#include <string.h>
#include <dos.h>
#include <windows.h>
#include "fmedit.def"
#include "object.def"
#include "cursor.def"
#include "global.h"
#include "memory.def"
#include "state.h"
static HANDLE FMEditInst = NULL;
static STATE * State = NULL;
static STATE * StateList = NULL;
static STATE_HDL StateID = 1;
extern void SetInst( HANDLE inst )
/********************************/
/* save the DLL instance */
{
FMEditInst = inst;
}
extern void NewState( void )
/**************************/
/* initialize state info */
{
State = EdAlloc( sizeof( STATE ) );
State->currstate = DORMANT;
State->basestate = DORMANT;
State->currobj = NULL;
State->selecteatom = NULL;
State->prevobject = NULL;
State->mainobject = NULL;
State->gridvinc = DEF_V_GRID;
State->gridhinc = DEF_H_GRID;
State->vresizegrid = DEF_V_GRID;
State->hresizegrid = DEF_H_GRID;
State->offset.x = 0;
State->offset.y = 0;
State->hAccel[0] = LoadAccelerators( GetInst(), "EscAccelTable" );
State->hAccel[1] = NULL;
State->hAccel[2] = NULL;
State->hAccel[3] = NULL;
State->hAccel[4] = NULL;
State->showerror = TRUE;
State->error = NULL;
State->mouseaction = NULL;
State->show_eatoms = TRUE;
State->id = StateID;
++StateID;
State->next = StateList;
StateList = State;
}
extern void SetStateWnd( HWND wnd )
/*********************************/
{
RECT rect;
State->appwnd = wnd;
if( wnd != NULL ) {
GetClientRect( wnd, &rect );
} else {
memset( &rect, 0, sizeof( RECT ) );
}
State->scrollrect = rect;
}
extern void FreeState( void )
/***************************/
{
STATE * s;
STATE * last;
last = NULL;
for( s = StateList; s != NULL; s = s->next ) {
if( s == State ) {
break;
}
last = s;
}
if( last == NULL ) {
StateList = s->next;
} else {
last->next = s->next;
}
EdFree( s );
State = NULL;
}
extern HWND InheritState( HWND newwnd )
/*************************************/
/* replace the window of the current state with the passed window */
{
HWND old;
old = State->appwnd;
State->appwnd = newwnd;
return( old );
}
BOOL WINEXP InitState( HWND wnd )
/*******************************/
/* initialize the state from the window */
{
STATE * s;
for( s = StateList; s != NULL; s = s->next ) {
if( s->appwnd == wnd ) {
break;
}
}
State = s;
return( State != NULL );
}
extern void SetState( STATE_ID state )
/************************************/
/* set to the specified state */
{
State->currstate = state;
SetStateCursor( state );
}
extern STATE_ID GetState( void )
/******************************/
/* return the current state */
{
return( State->currstate );
}
extern void SetBaseState( STATE_ID st )
/*************************************/
/* set the state that the system goes to when nothing is actively happening */
{
State->basestate = st;
}
extern void SetDefState( void )
/*****************************/
/* reset to base state */
{
State->currstate = State->basestate;
SetStateCursor( State->basestate );
}
extern void SetSize( RESIZE_ID id )
/**********************************/
/* set the sizing state based on the passed sizing operation */
{
State->sizeinfo |= id;
}
extern void ResetSize( void )
/***************************/
/* reset the sizing state info */
{
State->sizeinfo = R_NONE;
}
extern char GetSizing( void )
/***************************/
/* return the sizing info */
{
return( State->sizeinfo );
}
extern BOOL Sizing( char op )
/***************************/
/* check to see if a sizing operation is valid */
{
return( (State->sizeinfo & op) != R_NONE );
}
extern void SetPrevMouse( POINT pt )
/**********************************/
/* save the mouse position */
{
State->prevmouse = pt;
}
extern POINT GetPrevMouse( void )
/*******************************/
/* Return the last significant the mouse position. */
{
return( State->prevmouse );
}
extern HANDLE GetAppWnd( void )
/*****************************/
/* save the application window handle */
{
return( State->appwnd );
}
extern HANDLE GetInst( void )
/***************************/
/* save the instance handle */
{
return( FMEditInst );
}
extern void CreateMainObject( void )
/**********************************/
/* create the main object */
{
State->mainobject = Create( USER_OBJ, NULL, NULL, NULL );
}
extern void DestroyMainObject( void )
/***********************************/
/* destroy the main object */
{
OBJPTR temp;
temp = State->mainobject;
Destroy( temp, FALSE );
State->mainobject = NULL;
}
extern void CreateCurrObject( void )
/**********************************/
/* Create the current object */
{
State->currobj = Create( O_CURROBJ, NULL, NULL, NULL );
}
extern void DestroyCurrObject( void )
/***********************************/
/* Destroy the current object */
{
Destroy( State->currobj, FALSE );
}
OBJPTR WINEXP GetMainObject( void )
/*********************************/
/* create the main object */
{
return( State->mainobject );
}
void WINEXP SetBaseObjType( OBJ_ID id )
/*************************************/
/* save the type of object to create */
{
State->objtype = id;
}
OBJ_ID WINEXP GetBaseObjType( void )
/**********************************/
/* return the type of object to build */
{
return( State->objtype );
}
unsigned WINEXP GetVerticalInc( void )
/************************************/
/* return the vertical grid increment value */
{
return( State->gridvinc );
}
void WINEXP SetVerticalInc( unsigned inc )
/****************************************/
/* set the vertical grid increment value */
{
State->gridvinc = inc;
}
unsigned WINEXP GetHorizontalInc( void )
/**************************************/
/* return the vertical grid increment value */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?