guistat.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 529 行 · 第 1/2 页
C
529 行
/****************************************************************************
*
* 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: Installer GUI status bar.
*
****************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "gui.h"
#include "guiutil.h"
#include "guikey.h"
#include "dlggen.h"
#include "setup.h"
#include "setupwpi.h"
#include "setupinf.h"
#include "guistr.h"
#include "guidlg.h"
#include "dlgbutn.h"
#include "genvbl.h"
extern gui_colour_set StatusColours[];
extern gui_colour_set StatusBackground;
gui_window *StatusWnd;
static gui_rect StatusBarRect;
static gui_coord CharSize;
static int Percent;
static long Parts_Injob;
static long Parts_Complete;
gui_colour_set ToolPlain = { GUI_BLACK, GUI_BLUE, };
gui_colour_set ToolStandout = { GUI_BRIGHT_WHITE, GUI_BLUE };
extern gui_window *MainWnd;
static char StatusLine1[_MAX_PATH];
static gui_ord StatusBarLen;
static gui_rect StatusRect;
static char StatusBarBuf[256];
int MsgLine0 = STAT_BLANK;
bool CancelSetup = FALSE;
#ifdef PATCH
extern int IsPatch;
#endif
#if defined( __UNIX__ )
#include "stdui.h"
#elif defined( _UI )
#include <stdui.h>
#endif
#define LINE0_ROW 1
#define LINE1_ROW 2
#define LINE0_COL 1
#define LINE1_COL 1
#define STATUS_WIDTH 70
#define STATUS_HEIGHT 10
#define CANNERY_SIZE 10
#define CANNERY_ROW 6
#define STATUS_ROW 4
#define BAR_INDENT 4
#undef pick
#define pick( x, y ) y,
char *Messages[] = {
#include "status.h"
};
#undef pick
extern void StatusShow( bool show )
/********************************/
{
if( StatusWnd == NULL && show ) {
StatusInit();
}
if( StatusWnd != NULL ) {
if( show ) {
GUIShowWindow( StatusWnd );
} else {
GUIHideWindow( StatusWnd );
}
GUIWndDirty( StatusWnd );
}
}
extern void StatusFini( void )
/***************************/
{
if( StatusWnd == NULL ){
return;
} else {
GUIDestroyWnd( StatusWnd );
StatusWnd = NULL;
}
}
extern void StatusLines( int msg0, char *message1 )
/*************************************************/
{
if( StatusWnd != NULL ) {
if( message1 != NULL ) {
if( strcmp( message1, StatusLine1 ) != 0 ) {
strcpy( StatusLine1, message1 );
GUIWndDirtyRow( StatusWnd, LINE1_ROW );
}
}
if( msg0 != STAT_SAME ) {
if( msg0 != MsgLine0 ) {
MsgLine0 = msg0;
GUIWndDirty( StatusWnd );
}
}
}
}
extern void BumpStatus( long by ) {
/*********************************/
#ifdef PATCH
if( !IsPatch ) {
#endif
// if a patch, don't change status because denominator of status
// fraction is the number of operations, not a number of bytes
StatusAmount( Parts_Complete + by, Parts_Injob );
#ifdef PATCH
}
#endif
}
extern void StatusAmount( long parts_complete, long parts_injob )
/*************************************************************/
// Display slider bar indicating percentage complete
{
int old_percent;
Parts_Injob = parts_injob;
Parts_Complete = parts_complete;
old_percent = Percent;
if( parts_injob == 0 ) {
if( parts_complete == 0 ) {
Percent = 0;
} else {
Percent = 100;
}
} else {
if( Parts_Complete > Parts_Injob ) {
Parts_Complete = Parts_Injob;
}
if( Parts_Injob > 100000 ) {
Percent = Parts_Complete / ( Parts_Injob / 100 );
} else {
Percent = ( 100 * Parts_Complete ) / Parts_Injob;
}
if( Percent > 100 ) Percent = 100;
}
if( old_percent == Percent ) return;
if( Percent != 0 && Percent < old_percent ) {
Percent = old_percent;
return;
}
if( StatusWnd == NULL ) return;
#ifdef _UI
GUIWndDirty( StatusWnd );
#else
{
gui_ord bar_width, old_divider, divider;
gui_rect rect;
sprintf( StatusBarBuf, "%d%%", Percent );
// calculate where divider splits rectangle
bar_width = StatusBarRect.width;
divider = ( bar_width * (long)Percent ) / 100;
if( divider < 0 ) {
divider = 0;
} else if( divider > bar_width ) {
divider = bar_width;
}
old_divider = ( bar_width * (long)old_percent ) / 100;
if( old_divider < 0 ) {
old_divider = 0;
} else if( old_divider > bar_width ) {
old_divider = bar_width;
}
if( divider <= old_divider ) {
GUIWndDirty( StatusWnd );
} else {
// dirty new bit of bar
divider += StatusBarRect.x;
old_divider += StatusBarRect.x;
rect = StatusBarRect;
rect.width = GUIGetExtentX( StatusWnd, StatusBarBuf, strlen( StatusBarBuf ) );
rect.x = StatusBarRect.x + ( StatusBarRect.width - rect.width ) / 2;
rect.x -= CharSize.x / 2;
rect.width += CharSize.x;
GUIWndDirtyRect( StatusWnd, &rect ); // dirty text
rect.x = old_divider - CharSize.x;
rect.width = divider - old_divider + 2*CharSize.x;
GUIWndDirtyRect( StatusWnd, &rect ); // dirty new bit of bar
}
}
#endif
}
extern bool StatusCancelled( void )
/*********************************/
{
// update windows and let other apps execute
GUIDrainEvents();
return( CancelSetup );
}
static GUICALLBACK StatusEventProc;
static bool StatusEventProc( gui_window *gui, gui_event gui_ev, void *parm )
/**************************************************************************/
{
static bool button_pressed = FALSE;
unsigned id;
gui_key key;
gui_keystate state;
char * msg;
parm = parm;
if( gui == NULL ) return( FALSE );
switch( gui_ev ) {
case GUI_INIT_WINDOW:
return( TRUE );
case GUI_PAINT:
{
if( StatusBarLen == 0 ) break;
msg = GetVariableStrVal( Messages[MsgLine0] );
GUIDrawTextExtent( gui, msg, strlen( msg ), LINE0_ROW,
LINE0_COL*CharSize.x, WND_STATUS_TEXT, GUI_NO_COLUMN );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?