guixdlg.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 860 行 · 第 1/2 页
C
860 行
break;
case WM_COMMAND :
escape_pressed = FALSE;
param = _wpi_getid( wparam );
if( _wpi_ismenucommand( wparam, lparam ) ) { /* from menu */
if( wnd != NULL ) {
#ifndef __OS2_PM__
escape_pressed = ( !GET_WM_COMMAND_CMD( wparam, lparam ) &&
( param == IDCANCEL ) );
#endif
if( !escape_pressed ) {
GUIEVENTWND( wnd, GUI_CONTROL_CLICKED, ¶m );
}
}
} else {
#ifdef __OS2_PM__
escape_pressed = (((ULONG)lparam == 1) && (param == IDCANCEL));
#else
escape_pressed = ( !GET_WM_COMMAND_CMD( wparam, lparam ) &&
( param == IDCANCEL ) );
#endif
if( !escape_pressed ) {
GUIProcessControlMsg( wparam, lparam, wnd, &ret );
}
}
if( escape_pressed ) {
GUIEVENTWND( wnd, GUI_DIALOG_ESCAPE, NULL );
GUICloseDialog( wnd );
}
msg_processed = TRUE;
break;
case WM_CLOSE :
_wpi_enddialog( hwnd, TRUE );
msg_processed = TRUE;
break;
case WM_MOVE :
GUIInvalidatePaintHandles( wnd );
break;
case WM_DESTROY :
if( wnd != NULL ) {
GUIEVENTWND( wnd, GUI_DESTROY, NULL );
}
#ifndef __OS2_PM__
break;
case WM_NCDESTROY :
#endif
if( wnd != NULL ) {
GUIFreeWindowMemory( wnd, FALSE, TRUE );
}
break;
case WM_PAINT :
if( !_wpi_isiconic( hwnd ) ) {
GUIPaint( wnd, hwnd, TRUE );
msg_processed = TRUE;
}
break;
#ifndef __OS2_PM__
case WM_VKEYTOITEM :
msg_processed = TRUE;
ret = -1;
GUIGetKeyState( &key_state.state );
if( ( GUIWindowsMapKey( wparam, lparam, &key_state.key ) ) ) {
ret = GUIEVENTWND( wnd, GUI_KEYTOITEM, &key_state );
}
break;
#endif
// the following code allows GUI dialogs to receive key msgs
// this code must eventually be rationalized with the code in
// guixwind.c
#ifndef __OS2_PM__
case WM_SYSKEYDOWN :
case WM_SYSKEYUP :
case WM_KEYDOWN :
case WM_KEYUP :
gui_ev = GUI_KEYUP;
if( ( message == WM_KEYDOWN ) || ( message == WM_SYSKEYDOWN ) ) {
gui_ev = GUI_KEYDOWN;
}
GUIGetKeyState( &key_state.state );
if( ( GUIWindowsMapKey( wparam, lparam, &key_state.key ) ) ) {
if( GUIEVENTWND( wnd, gui_ev, &key_state ) ) {
return( FALSE );
}
}
break;
#else
case WM_CHAR :
key_flags = SHORT1FROMMP( wparam );
gui_ev = GUI_KEYDOWN;
if( key_flags & KC_KEYUP ) {
gui_ev = GUI_KEYUP;
}
GUIGetKeyState( &key_state.state );
if( GUIWindowsMapKey( wparam, lparam, &key_state.key ) ) {
if( GUIEVENTWND( wnd, gui_ev, &key_state ) ) {
return( FALSE );
}
}
break;
#endif
}
#ifdef __OS2_PM__
if( !msg_processed ) {
return( _wpi_defdlgproc( hwnd, message, wparam, lparam ) );
}
#endif
return( ret );
}
/*
* ToDialogUnits -- convert the given coordinate to dialog units
*/
static void ToDialogUnits( gui_coord *coord )
{
if( coord != NULL ) {
coord->x = GUIMulDiv( coord->x, SizeDialog.x, SizeScreen.x );
coord->y = GUIMulDiv( coord->y, SizeDialog.y, SizeScreen.y );
}
}
/*
* AdjustToDialogUnits -- convert the given coordinate to dialog units and
* adjust
*/
static void AdjustToDialogUnits( gui_coord *coord )
{
ToDialogUnits( coord );
}
static void AdjustForFrame( gui_coord *pos, gui_coord *size )
{
#ifndef __OS2_PM__
int xframe, yframe, ycaption;
if( ( pos != NULL ) || ( size != NULL ) ) {
xframe = _wpi_getsystemmetrics( SM_CXDLGFRAME );
yframe = _wpi_getsystemmetrics( SM_CYDLGFRAME );
ycaption = _wpi_getsystemmetrics( SM_CYCAPTION );
}
if( pos != NULL ) {
pos->x += xframe;
pos->y += ( yframe + ycaption );
}
if( size != NULL ) {
size->x -= ( 2 * xframe );
size->y -= ( 2 * yframe + ycaption );
}
#else
pos = pos;
size = size;
#endif
}
void GUIDlgCalcLocation( gui_rect *rect, gui_coord *pos, gui_coord *size )
{
pos->x = rect->x;
pos->y = rect->y;
size->x = rect->width;
size->y = rect->height;
GUIScaleToScreenR( pos );
GUIScaleToScreenR( size );
}
/*
* GUIXCreateDialog -- create a dialog with the specified controls
*/
bool GUIXCreateDialog( gui_create_info *dialog, gui_window *wnd,
int num_controls, gui_control_info *info_controls,
bool sys, long dlg_id )
{
gui_coord pos, size;
gui_coord parent_pos;
TEMPLATE_HANDLE data;
TEMPLATE_HANDLE new;
int i;
char *text;
long style;
HWND parent_hwnd;
gui_control_info *control;
bool got_first_focus;
bool in_group;
LONG dlg_style;
void *pctldata;
int pctldatalen;
#ifdef __OS2_PM__
ENTRYFDATA edata;
#endif
wnd->flags |= IS_DIALOG;
wnd->parent = dialog->parent;
wnd->root_pinfo.force_count = NUMBER_OF_FORCED_REPAINTS;
wnd->hwnd_pinfo.force_count = NUMBER_OF_FORCED_REPAINTS;
parent_hwnd = HWND_DESKTOP;
if( dialog->parent != NULL ) {
parent_hwnd = dialog->parent->hwnd;
}
if( !GUISetupStruct( wnd, dialog, &parent_pos, &size, parent_hwnd, NULL ) ) {
return( FALSE );
}
wnd->flags |= HAS_CAPTION;
if( dlg_id != -1 ) {
wnd->flags |= IS_RES_DIALOG;
return( GUIDoCreateResDialog( dlg_id, parent_hwnd, (void *)wnd ) );
}
AdjustForFrame( &parent_pos, &size );
AdjustToDialogUnits( &parent_pos );
AdjustToDialogUnits( &size );
if( sys ) {
dlg_style = SYSTEM_MODAL_STYLE;
} else {
dlg_style = MODAL_STYLE;
}
data = DialogTemplate( dlg_style | DS_SETFONT,
parent_pos.x, parent_pos.y, size.x, size.y,
LIT( Empty ), LIT( Empty ), dialog->text,
PointSize, Font );
if( data == NULL ) {
return( FALSE );
}
got_first_focus = FALSE;
in_group = FALSE;
for( i = 0; i < num_controls; i++ ) {
pctldata = NULL;
pctldatalen = 0;
control = &info_controls[i];
#ifdef __OS2_PM__
if( control->control_class == GUI_EDIT ) {
edata.cb = sizeof(ENTRYFDATA);
edata.cchEditLimit = 2048;
edata.ichMinSel = 0;
edata.ichMaxSel = 0;
pctldata = &edata;
pctldatalen = edata.cb;
}
#endif
GUIDlgCalcLocation( &control->rect, &pos, &size );
AdjustToDialogUnits( &pos );
AdjustToDialogUnits( &size );
if( control->text == NULL ) {
text = LIT( Empty );
} else {
text = control->text;
}
style = GUISetControlStyle( control );
if( !in_group ) {
style |= WS_GROUP;
}
if( style & GUI_GROUP ) {
in_group = !in_group;
}
new = AddControl( data, pos.x, pos.y, size.x, size.y, control->id,
style, GUIControls[control->control_class].classname,
text, pctldatalen, (char *)pctldata );
if( new == NULL ) {
GlobalFree( data );
return( FALSE );
}
if( GUIControlInsert( wnd, control->control_class, NULL, control,
NULL ) == NULL ) {
GlobalFree( data );
return( FALSE );
}
data = new;
}
data = DoneAddingControls( data );
DynamicDialogBox( (LPVOID) GUIDialogFunc, GUIMainHInst, parent_hwnd, data, (LONG)wnd );
return( TRUE );
}
/*
* GUICloseDialog -- close the given dialog, freeing all associated memory
*/
void GUICloseDialog( gui_window * wnd )
{
GUISendMessage( wnd->hwnd, WM_CLOSE, 0, 0 );
}
/****************************************************************************/
/* From here down is used to get sizing right, called by GUIWndInit */
/****************************************************************************/
static WPI_FONT DlgFont;
/*
* GUIInitDialogFunc - callback function the test dialog box used to get the
* dialog box font info and client size info
*
*/
#if defined( UNIX )
long GUIInitDialogFunc( HWND hwnd, WPI_MSG message, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
#else
WPI_DLGRESULT CALLBACK GUIInitDialogFunc( HWND hwnd, WPI_MSG message, WPI_PARAM1 wparam, WPI_PARAM2 lparam )
#endif
{
WPI_PRES hdc;
WPI_RECT rect;
WPI_FONT prev;
WPI_DLGRESULT ret;
lparam = lparam;
ret = FALSE;
switch( message ) {
#ifndef __OS2_PM__
case WM_SETFONT :
DlgFont = (WPI_FONT)wparam;
break;
#endif
case WM_INITDIALOG:
prev = prev;
hdc = _wpi_getpres( hwnd );
#ifndef __OS2_PM__
prev = _wpi_selectfont( hdc, DlgFont );
#else
DlgFont = (WPI_FONT)NULL;
#endif
_wpi_gettextmetrics( hdc, &GUIDialogtm );
_wpi_releasepres( hwnd, hdc );
_wpi_getclientrect( hwnd, &rect );
SizeScreen.x = _wpi_getwidthrect( rect );
SizeScreen.y = _wpi_getheightrect( rect );
_wpi_enddialog( hwnd, TRUE );
break;
#ifdef __OS2_PM__
default:
return( _wpi_defdlgproc( hwnd, message, wparam, lparam ) );
#endif
}
return( ret );
}
void GUIFiniDialog( void )
{
if( Font != NULL ) {
GUIMemFree( Font );
Font = NULL;
}
}
void GUIInitDialog( void )
{
TEMPLATE_HANDLE data;
char *cp;
bool font_set;
font_set = FALSE;
#ifdef __OS2_PM__
GUIStrDup( LIT( OS2_Dialog_Font ), &Font );
#else
GUIStrDup( LIT( Windows_Dialog_Font ), &Font );
#endif
if( Font ) {
cp = strrchr( Font, '.' );
if( cp ) {
*cp = '\0';
cp++;
PointSize = atoi( cp );
font_set = TRUE;
}
}
if( !font_set ) {
PointSize = 0;
if( Font != NULL ) {
GUIMemFree( Font );
}
GUIStrDup( "", &Font );
}
// create a dialog of known dialog units and use the resulting
// size of the client area to scale subsequent screen units
data = DialogTemplate( MODAL_STYLE | DS_SETFONT,
SizeDialog.x, SizeDialog.y,
SizeDialog.x, SizeDialog.y, LIT( Empty ),
LIT( Empty ), LIT( Empty ), PointSize, Font );
if( data != NULL ) {
data = DoneAddingControls( data );
DynamicDialogBox( (LPVOID) GUIInitDialogFunc, GUIMainHInst, NULL, data, 0 );
}
}
/*
* ScaleGrow -- adjust the estimate given to the user according to the
* known discrepency beween a dialog size asked for and
* what was created in this font.
*/
#ifdef THIS_CODE_IS_STUPID
static void ScaleGrow( gui_coord * coord )
{
if( coord != NULL ) {
coord->x = GUIMulDiv( coord->x, ActualSize.x, ExpectedSize.x );
coord->y = GUIMulDiv( coord->y, ActualSize.y, ExpectedSize.y );
}
}
#endif
/*
* GUIGetDlgTextMetrics -- get the metrics of the text used in dialog boxes
*/
void GUIGetDlgTextMetrics( gui_text_metrics * metrics )
{
if( metrics != NULL ) {
GUISetMetrics( metrics, &GUIDialogtm );
#ifdef THIS_CODE_IS_STUPID
ScaleGrow( &metrics->avg );
ScaleGrow( &metrics->max );
#endif
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?