utils.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 807 行 · 第 1/2 页
C
807 行
{
delay( ms );
}
void MyBeep( void )
{
MessageBeep( -1 );
}
static char oldPath[FILENAME_MAX];
static char oldDrive;
/*
* PushDirectory - save the current drive/directory
*/
void PushDirectory( char *orig )
{
unsigned c;
oldPath[0] = 0;
_dos_getdrive( &c );
oldDrive = (char) c;
if( orig[1] == ':' ) {
ChangeDrive( orig[0] );
}
GetCWD2( oldPath, FILENAME_MAX );
} /* PushDirectory */
/*
* PopDirectory - restore the current drive/directory
*/
void PopDirectory( void )
{
unsigned total;
if( oldPath[0] != 0 ) {
ChangeDirectory( oldPath );
}
_dos_setdrive( oldDrive, &total );
ChangeDirectory( CurrentDirectory );
} /* PopDirectory */
/*
* DoAboutBox - do an about box
*/
int DoAboutBox( void )
{
about_info ai;
ai.owner = Root;
ai.inst = InstanceHandle;
ai.name = WATCOM_ABOUT_EDITOR;
ai.version = banner1p2( _VI_VERSION_ );
ai.first_cr_year = "1989";
ai.title = "About Open Watcom Editor";
DoAbout( &ai );
return( ERR_NO_ERR );
} /* DoAboutBox */
void CursorOp( CursorOps op )
{
static int lastop = COP_FINI;
static HCURSOR noDrop, dropFt, dropClr, dropSS, statMove;
// if( op == lastop )
// return;
// ShowCursor( FALSE );
switch( op ) {
case COP_INIT:
noDrop = LoadCursor( InstanceHandle, "NODROP" );
dropFt = LoadCursor( InstanceHandle, "DROPFT" );
dropClr = LoadCursor( InstanceHandle, "DROPCLR" );
dropSS = LoadCursor( InstanceHandle, "DROPSS" );
statMove = LoadCursor( InstanceHandle, "STATMOVE" );
break;
case COP_FINI:
DestroyCursor( noDrop );
DestroyCursor( dropClr );
DestroyCursor( dropFt );
DestroyCursor( dropSS );
DestroyCursor( statMove );
break;
case COP_ARROW:
SetCursor( LoadCursor( (HINSTANCE) NULL, IDC_ARROW ) );
break;
case COP_DROPFT:
SetCursor( dropFt );
break;
case COP_DROPSS:
SetCursor( dropSS );
break;
case COP_DROPCLR:
SetCursor( dropClr );
break;
case COP_NODROP:
SetCursor( noDrop );
break;
case COP_STATMOVE:
SetCursor( statMove );
break;
}
// ShowCursor( TRUE );
lastop = op;
}
char *windowName[] = {
"Buffer Window",
"MessageWindow",
"RepeatWindow",
"FileCompleteWindow",
"CommandWindow",
"StatusWnd",
"WTool",
#if 0
EditorName, // nothing to change
"Edit Container", // should use standard Windows colour for this
#endif
};
HWND GetOwnedWindow( POINT pt )
{
char textBuffer[ 80 ];
int i, nTypes;
HWND hwndElement, hwndChild;
POINT ptSave;
/* point expected to be in screen coordinates
*/
ptSave = pt;
hwndElement = WindowFromPoint( pt );
ScreenToClient( hwndElement, &pt );
hwndChild = ChildWindowFromPoint( hwndElement, pt );
if( hwndChild != NULL ) {
/* must go 2 generations down
(BufferWindows children of ContainerWindow, child of EditorName)
*/
ClientToScreen( hwndElement, &pt );
hwndElement = hwndChild;
ScreenToClient( hwndElement, &pt );
hwndChild = ChildWindowFromPoint( hwndElement, pt );
if( hwndChild != NULL) {
hwndElement = hwndChild;
}
}
GetClassName( hwndElement, textBuffer, sizeof( textBuffer ) - 1 );
nTypes = GetNumWindowTypes();
for( i = 0; i < nTypes; i++ ) {
if( !strcmp( textBuffer, windowName [ i ] ) ) {
/* a recognized window - return handle to it
*/
#ifdef __WINDOWS__
if( GetWindowWord( hwndElement, GWW_HINSTANCE ) ==
GetWindowWord( Root, GWW_HINSTANCE ) ) {
return( hwndElement );
}
#else
if( GetWindowLong( hwndElement, GWL_HINSTANCE ) ==
GetWindowLong( Root, GWL_HINSTANCE ) ) {
return( hwndElement );
}
#endif
return( NULL );
}
}
return( NULL );
}
int GetNumWindowTypes( void )
{
return( sizeof( windowName ) / sizeof( windowName[ 0 ] ) );
}
void MoveWindowTopRight( HWND hwnd )
{
/* move window to top-right corner of container
(a tool-bar-like position)
*/
RECT rcClient, rcUs;
RECT rcTB;
POINT pt;
int clientWidth, usWidth, usHeight;
int xshift, xshiftmax;
if( !BAD_ID(CurrentWindow) ){
GetClientRect( CurrentWindow, &rcClient );
GetWindowRect( hwnd, &rcUs );
clientWidth = rcClient.right - rcClient.left;
usWidth = rcUs.right - rcUs.left;
usHeight = rcUs.bottom - rcUs.top;
pt.x = rcClient.left;
pt.y = rcClient.top;
ClientToScreen( CurrentWindow, &pt );
xshift = FontAverageWidth( 1 ) * 80;
xshiftmax = clientWidth - usWidth - 35;
if( xshift > xshiftmax ) {
xshift = xshiftmax;
}
pt.x += xshift;
pt.y += 30;
if( GetToolbarWindow() ) {
GetWindowRect( GetToolbarWindow(), &rcTB );
pt.y += rcTB.bottom - rcTB.top;
}
ScreenToClient( GetParent( hwnd ), &pt );
MoveWindow( hwnd, pt.x, pt.y, usWidth, usHeight, TRUE );
}
}
/*
* SetEditInt - set an integer in an edit window
*/
void SetEditInt( HWND hwnd, UINT id, int value )
{
char buff[16];
itoa( value, buff, 10 );
SetDlgItemText( hwnd, id, buff );
} /* SetEditInt */
/*
* UpdateBoolSetting - update an boolean setting
*/
void UpdateBoolSetting( HWND hwnd, int token, int id, bool oldval )
{
char *str;
char *ptr;
char result[MAX_STR];
int val;
val = IsDlgButtonChecked( hwnd, id );
if( val == oldval ) {
return;
}
if( !val ) {
result[0] = 'n';
result[1] = 'o';
ptr = &result[2];
} else {
ptr = result;
}
str = GetTokenString( SetTokens2, token );
strcpy( ptr, str );
Set( result );
} /* UpdateBoolSetting */
/*
* DoStrSet - do a set for a specified string
*/
void DoStrSet( char *value, int token )
{
char result[MAX_STR];
char *str;
str = GetTokenString( SetTokens1, token );
strcpy( result, str );
strcat( result, " " );
strcat( result, value );
Set( result );
} /* DoStrSet */
/*
* UpdateStrSetting - update a string setting
*/
void UpdateStrSetting( HWND hwnd, int token, int id, char *oldval )
{
char value[MAX_STR];
GetDlgItemText( hwnd, id, value, sizeof( value ) );
if( !strcmp( oldval, value ) ) {
return;
}
DoStrSet( value, token );
} /* UpdateStrSetting */
/*
* UpdateIntSetting - update a string setting
*/
void UpdateIntSetting( HWND hwnd, int token, int id, long oldval )
{
char value[MAX_STR];
long lval;
GetDlgItemText( hwnd, id, value, sizeof( value ) );
lval = atol( value );
if( lval == oldval ) {
return;
}
DoStrSet( value, token );
} /* UpdateIntSetting */
/*
* CenterWindowInRoot - nicely center a child of Root
*/
void CenterWindowInRoot( HWND hwnd )
{
RECT rR, rH;
int x, y, w, h, d;
GetWindowRect( Root, &rR );
GetWindowRect( hwnd, &rH );
// center in root
w = rH.right - rH.left;
h = rH.bottom - rH.top;
x = ( ( rR.right - rR.left + 1 ) - ( w + 1 ) ) / 2 + rR.left;
y = ( ( rR.bottom - rR.top + 1 ) - ( h + 1 ) ) / 2 + rR.top;
// try to keep on-screen
if( x < 0 ) x = 0;
if( y < 0 ) y = 0;
d = GetSystemMetrics( SM_CXSCREEN ) - ( x + w );
if( d < 0 ) {
x += d;
}
d = GetSystemMetrics( SM_CYSCREEN ) - ( y + h );
if( d < 0 ) {
y += d;
}
SetWindowPos( hwnd, (HWND)NULL, x, y, 0, 0,
SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOZORDER );
}
void DrawRectangleUpDown( HWND hwnd, int which )
{
LONG l;
l = GetWindowLong( hwnd, GWL_STYLE );
l &= ~SS_WHITEFRAME;
l |= SS_BLACKFRAME;
if( which == DRAW_UP ) {
l &= ~SS_BLACKFRAME;
l |= SS_WHITEFRAME;
}
SetWindowLong( hwnd, GWL_STYLE, l );
InvalidateRect( hwnd, NULL, TRUE );
UpdateWindow( hwnd );
}
#if 0
// sanity check on list of ss blocks
static void dumpSSBlocks( ss_block *ss_start, dc dc_line ) {
ss_block *ss = ss_start;
FILE *f= fopen( "C:\\vi.out", "a+t" );
fprintf( f,"Bad SSBlock:: dumping current DC line\n" );
fprintf( f,"%s %d %d %d %d\n",
dc_line->text,
ss->type,
ss->end,
ss->len,
ss->offset );
ss++;
while( ss->end <= BEYOND_TEXT ) {
fprintf( f,"%d %d %d %d\n",
ss->type,
ss->end,
ss->len,
ss->offset );
if( (ss->end == BEYOND_TEXT) || (ss->offset == 10000) ) break;
ss++;
}
fprintf( f,"\n" );
fclose( f );
}
#endif
/*
* ChangeDrive - change the working drive
*/
int ChangeDrive( int drive )
{
char a;
unsigned b;
unsigned total,c;
a = (char) tolower(drive) - (char) 'a';
b = a+1;
_dos_setdrive( b, &total );
_dos_getdrive( &c );
if( b != c ) {
return( ERR_NO_SUCH_DRIVE );
}
return( ERR_NO_ERR );
}/* ChangeDrive */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?