📄 wedit.c
字号:
/****************************************************************************
*
* 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: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include <windows.h>
#include <ctype.h>
#include <string.h>
#include "win1632.h"
#include "wglbl.h"
#include "wribbon.h"
#include "wmain.h"
#include "wmsg.h"
#include "wstat.h"
#include "wmem.h"
#include "wnewitem.h"
#include "wdel.h"
#include "wvk2str.h"
#include "wedit.h"
#include "wctl3d.h"
#include "wsetedit.h"
#include "wclip.h"
#include "sys_rc.h"
#include "wmsgfile.gh"
#include "jdlg.h"
/****************************************************************************/
/* macro definitions */
/****************************************************************************/
#define WEDIT_PAD 4
/****************************************************************************/
/* type definitions */
/****************************************************************************/
/****************************************************************************/
/* external function prototypes */
/****************************************************************************/
LRESULT WINEXPORT WAcccelEditProc ( HWND, UINT, WPARAM, LPARAM );
/****************************************************************************/
/* static function prototypes */
/****************************************************************************/
static Bool WInitEditWindow ( WAccelEditInfo * );
static void WExpandEditWindowItem ( HWND, int, RECT * );
static Bool WSetEditWindowKey ( HWND, uint_16, uint_16 );
static Bool WSetEditWindowID ( HWND, char *, uint_16 );
static Bool WSetEditWindowFlags ( HWND, uint_16 );
static Bool WGetEditWindowKey ( HWND, uint_16 *, uint_16 *, Bool * );
static Bool WGetEditWindowID ( HWND dlg, char **symbol, uint_16 *id,
WRHashTable *symbol_table,
Bool combo_change );
static Bool WGetEditWindowFlags ( HWND, uint_16 * );
/****************************************************************************/
/* external variables */
/****************************************************************************/
extern UINT WClipbdFormat;
extern UINT WItemClipbdFormat;
extern WAccelEntry DefaultEntry = { FALSE, { ACCEL_ASCII, 'A', 101 },
NULL, NULL, NULL };
/****************************************************************************/
/* static variables */
/****************************************************************************/
static DLGPROC WAccelEditWinProc = NULL;
static HBRUSH WEditWinBrush = NULL;
static COLORREF WEditWinColor = 0;
int appWidth = -1;
int appHeight = -1;
void WInitEditWindows ( HINSTANCE inst )
{
_wtouch(inst);
WEditWinColor = GetSysColor( COLOR_BTNFACE );
WEditWinBrush = CreateSolidBrush ( WEditWinColor );
WAccelEditWinProc = (DLGPROC)
MakeProcInstance ( (FARPROC) WAcccelEditProc, inst );
}
void WFiniEditWindows ( void )
{
if ( WEditWinBrush ) {
DeleteObject ( WEditWinBrush );
}
FreeProcInstance ( (FARPROC) WAccelEditWinProc );
}
Bool WCreateAccelEditWindow ( WAccelEditInfo *einfo, HINSTANCE inst )
{
int tabstop;
einfo->edit_dlg = JCreateDialogParam( inst, "WAccelEditDLG", einfo->win,
WAccelEditWinProc, (LPARAM) einfo );
if( einfo->edit_dlg == (HWND) NULL ) {
return( FALSE );
}
tabstop = 85;
SendDlgItemMessage( einfo->edit_dlg, IDM_ACCEDLIST, LB_SETTABSTOPS,
(WPARAM)1, (LPARAM) &tabstop );
SetWindowPos( einfo->edit_dlg, (HWND)NULL, 0, WGetRibbonHeight(), 0, 0,
SWP_NOSIZE | SWP_NOZORDER );
return( WInitEditWindow( einfo ) );
}
Bool WResizeAccelEditWindow ( WAccelEditInfo *einfo, RECT *prect )
{
int width, height, ribbon_depth;
HWND win;
RECT crect;
if ( !einfo || !einfo->edit_dlg || !prect ) {
return ( FALSE );
}
if ( einfo->show_ribbon ) {
ribbon_depth = WGetRibbonHeight();
} else {
ribbon_depth = 0;
}
width = prect->right - prect->left;
height = prect->bottom - prect->top - ribbon_depth - WGetStatusDepth();
/* change the size of the divider */
win = GetDlgItem ( einfo->edit_dlg, IDM_ACCEDBLACKLINE );
GetWindowRect ( win, &crect );
SetWindowPos ( win, (HWND) NULL, 0, 0, width,
crect.bottom - crect.top,
SWP_NOMOVE | SWP_NOZORDER );
/* change the size of the resource name edit field */
WExpandEditWindowItem ( einfo->edit_dlg, IDM_ACCEDRNAME, prect );
/* change the size of the listbox */
WExpandEditWindowItem ( einfo->edit_dlg, IDM_ACCEDLIST, prect );
SetWindowPos ( einfo->edit_dlg, (HWND)NULL, 0, ribbon_depth,
width, height, SWP_NOZORDER );
return ( TRUE );
}
void WExpandEditWindowItem ( HWND hDlg, int id, RECT *prect )
{
HWND win;
RECT crect, t;
/* expand the child window */
win = GetDlgItem ( hDlg, id );
GetWindowRect ( win, &crect );
MapWindowPoints ( (HWND)NULL, hDlg, (POINT *)&crect, 2 );
t.left = 0;
t.top = 0;
t.right = 0;
t.bottom = WEDIT_PAD;
MapDialogRect ( hDlg, &t );
SetWindowPos ( win, (HWND) NULL, 0, 0,
prect->right - crect.left - t.bottom,
crect.bottom - crect.top,
SWP_NOMOVE | SWP_NOZORDER );
InvalidateRect ( win, NULL, TRUE );
}
void WResetEditWindow( WAccelEditInfo *einfo )
{
if( einfo ) {
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_ACCEDKEY), "" );
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_ACCEDCMDID), "" );
WSetEditWithStr( GetDlgItem(einfo->edit_dlg, IDM_ACCEDCMDNUM), "" );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDVIRT, FALSE );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDASCII, TRUE );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDCNTL, FALSE );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDSHFT, FALSE );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDALT, FALSE );
CheckDlgButton ( einfo->edit_dlg, IDM_ACCEDFLASH, FALSE );
}
}
Bool WSetEditWindowKeyEntry ( WAccelEditInfo *einfo, WAccelEntry *entry )
{
Bool ok;
uint_16 key, flags, id;
ok = ( einfo && einfo->edit_dlg && entry );
if( ok ) {
if( entry->is32bit ) {
key = entry->entry32.Ascii;
flags = entry->entry32.Flags;
id = entry->entry32.Id;
} else {
key = entry->entry.Ascii;
flags = entry->entry.Flags;
id = (uint_16) entry->entry.Id;
}
ok = WSetEditWindowKey ( einfo->edit_dlg, key, flags );
if( !ok ) {
WSetStatusByID( einfo->wsb, -1, W_INVALIDACCEL );
memcpy( entry, &DefaultEntry, sizeof(WAccelEntry) );
key = entry->entry.Ascii;
flags = entry->entry.Flags;
id = (uint_16) entry->entry.Id;
ok = WSetEditWindowKey ( einfo->edit_dlg, key, flags );
}
}
if ( ok ) {
ok = WSetEditWindowID ( einfo->edit_dlg, entry->symbol, id );
}
if ( ok ) {
ok = WSetEditWindowFlags ( einfo->edit_dlg, flags );
}
return ( ok );
}
Bool WGetEditWindowKeyEntry( WAccelEditInfo *einfo, WAccelEntry *entry,
Bool check_mod )
{
Bool ok;
Bool force_ascii;
uint_16 key, flags, id;
char *symbol;
symbol = NULL;
flags = 0;
force_ascii = FALSE;
ok = ( einfo && einfo->edit_dlg && entry );
if( ok ) {
ok = WGetEditWindowFlags( einfo->edit_dlg, &flags );
}
if( ok ) {
ok = WGetEditWindowKey( einfo->edit_dlg, &key, &flags, &force_ascii );
if( !ok ) {
WSetStatusByID( einfo->wsb, -1, W_INVALIDACCELKEY );
}
}
if( ok ) {
ok = WGetEditWindowID( einfo->edit_dlg, &symbol, &id,
einfo->info->symbol_table,
einfo->combo_change );
}
if( ok ) {
if( force_ascii ) {
flags &= ~( ACCEL_VIRTKEY | ACCEL_SHIFT |
ACCEL_CONTROL | ACCEL_ALT );
}
}
/* check if anything was actually modified */
if( ok ) {
// make sure the symbol info did not change
ok = ( !entry->symbol && symbol ) || ( entry->symbol && !symbol );
if( !ok ) {
ok = symbol && stricmp( entry->symbol, symbol );
if( !ok ) {
if( entry->is32bit ) {
ok = ( ( entry->entry32.Ascii != key ) ||
( entry->entry32.Flags != flags ) ||
( entry->entry32.Id != id ) );
} else {
ok = ( ( entry->entry.Ascii != key ) ||
( entry->entry.Flags != (uint_8) flags ) ||
( entry->entry.Id != id ) );
}
}
}
if( check_mod ) {
return( ok );
}
}
if( ok ) {
if( entry->is32bit ) {
entry->entry32.Ascii = key;
entry->entry32.Flags = flags;
entry->entry32.Id = id;
} else {
entry->entry.Ascii = key;
entry->entry.Flags = (uint_8) flags;
entry->entry.Id = id;
}
if( entry->symbol ) {
WMemFree( entry->symbol );
}
entry->symbol = symbol;
} else {
if( symbol ) {
WMemFree( symbol );
}
}
return( ok );
}
Bool WSetEditWindowKey( HWND dlg, uint_16 key, uint_16 flags )
{
char *text;
HWND edit;
Bool ok;
ok = ( dlg != (HWND) NULL );
if( ok ) {
text = WGetKeyText( key, flags );
ok = ( text != NULL );
}
if( ok ) {
edit = GetDlgItem( dlg, IDM_ACCEDKEY );
ok = WSetEditWithStr( edit, text );
}
return( ok );
}
Bool WGetEditWindowKey( HWND dlg, uint_16 *key, uint_16 *flags, Bool *force_ascii )
{
Bool ok;
char *text;
text = NULL;
ok = ( dlg != (HWND) NULL && key && flags && force_ascii );
if( ok ) {
text = WGetStrFromEdit( GetDlgItem( dlg, IDM_ACCEDKEY ), NULL );
ok = ( text != NULL );
}
if( ok ) {
ok = WGetKeyFromText( text, key, flags, force_ascii );
}
if( text ) {
WMemFree( text );
}
return( ok );
}
Bool WSetEditWindowID( HWND dlg, char *symbol, uint_16 id )
{
Bool ok;
ok = ( dlg != (HWND) NULL );
if( ok ) {
if( symbol != NULL ) {
ok = WSetEditWithStr( GetDlgItem( dlg, IDM_ACCEDCMDID ), symbol );
} else {
ok = WSetEditWithSINT32( GetDlgItem( dlg, IDM_ACCEDCMDID ),
(int_32) id, 10 );
}
}
if( ok ) {
ok = WSetEditWithSINT32( GetDlgItem ( dlg, IDM_ACCEDCMDNUM ),
(int_32) id, 10 );
}
return( ok );
}
Bool WGetEditWindowID( HWND dlg, char **symbol, uint_16 *id,
WRHashTable *symbol_table, Bool combo_change )
{
int_32 val;
char *ep;
WRHashValue hv;
WRHashEntry *new_entry;
BOOL dup;
if( dlg == (HWND)NULL ) {
return( FALSE );
}
if( combo_change ) {
*symbol = WGetStrFromComboLBox( GetDlgItem( dlg, IDM_ACCEDCMDID ), -1 );
} else {
*symbol = WGetStrFromEdit( GetDlgItem( dlg, IDM_ACCEDCMDID ), NULL );
}
if( *symbol == NULL ) {
return( FALSE );
}
if( !**symbol ) {
*symbol = WGetStrFromEdit( GetDlgItem( dlg, IDM_ACCEDCMDNUM ), NULL );
}
if( *symbol == NULL ) {
return( FALSE );
}
strupr( *symbol );
// check if the string has a numeric representation
val = (int_32)strtol( *symbol, &ep, 0 );
if( *ep ) {
// the string did not have a numeric representation
// so lets look it up in the hash table
if( WRLookupName( symbol_table, *symbol, &hv ) ) {
*id = (uint_16)hv;
} else {
dup = FALSE;
new_entry = WRAddDefHashEntry( symbol_table, *symbol, &dup );
if( new_entry != NULL ) {
*id = (uint_16)new_entry->value;
if( !dup ) {
SendDlgItemMessage( dlg, IDM_ACCEDCMDID, CB_ADDSTRING,
0, (LPARAM)(LPCSTR)new_entry->name );
SendDlgItemMessage( dlg, IDM_ACCEDCMDID, CB_SETITEMDATA,
0, (LPARAM)new_entry );
}
} else {
*id = 0;
WMemFree( *symbol );
*symbol = NULL;
return( FALSE );
}
}
} else {
// the string did have a numeric representation
*id = (uint_16)val;
WMemFree( *symbol );
*symbol = NULL;
}
return( TRUE );
}
Bool WSetEditWindowFlags ( HWND dlg, uint_16 flags )
{
Bool ok, is_virt;
ok = ( dlg != (HWND) NULL );
if ( ok ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -