📄 wmain.c
字号:
return ( RegisterClass ( &wc ) );
}
char *WCreateEditTitle( WStringEditInfo *einfo )
{
char *title;
char *fname;
char *text;
int offset, len;
title = NULL;
fname = NULL;
if( !einfo ) {
return( NULL );
}
if( !einfo->file_name ) {
fname = einfo->info->file_name;
} else {
fname = einfo->file_name;
}
text = WAllocRCString( W_STRINGAPPTITLE );
if( !fname || !text ) {
return( NULL );
}
offset = WRFindFnOffset( fname );
fname = &fname[offset];
len = strlen( fname ) + strlen( text ) + 6;
title = (char *) WMemAlloc( len );
if( title ) {
strcpy( title, text );
strcat( title, " - [" );
strcat( title, fname );
strcat( title, "]" );
}
if( text ) {
WFreeRCString( text );
}
return( title );
}
void WSetEditTitle ( WStringEditInfo *einfo )
{
char *title;
Bool is_rc;
title = WCreateEditTitle( einfo );
is_rc = FALSE;
if( !title ) {
title = WAllocRCString( W_STRINGAPPTITLE );
is_rc = TRUE;
}
if( title ) {
SendMessage( einfo->win, WM_SETTEXT, 0, (LPARAM) title );
if( is_rc ) {
WFreeRCString( title );
} else {
WMemFree( title );
}
}
}
Bool WCreateEditWindow ( HINSTANCE inst, WStringEditInfo *einfo )
{
int x, y, width, height;
char *title;
HMENU hmenu;
HMENU menu;
Bool is_rc;
RECT rect;
if( !einfo ) {
return ( FALSE );
}
x = CW_USEDEFAULT;
y = CW_USEDEFAULT;
width = appWidth;
height = appHeight;
if( einfo->info->stand_alone ) {
WGetScreenPosOption( &rect );
if( !IsRectEmpty( &rect ) ) {
x = rect.left;
y = rect.top;
width = max( appWidth, rect.right - rect.left );
height = max( appHeight, rect.bottom - rect.top );
}
}
is_rc = FALSE;
title = WCreateEditTitle( einfo );
if( !title ) {
title = WAllocRCString( W_STRINGAPPTITLE );
is_rc = TRUE;
}
menu = (HMENU)NULL;
if( einfo->info->stand_alone ) {
menu = LoadMenu( inst, WMainSOMenuName );
}
einfo->win = CreateWindow( WMainClass, title, WS_OVERLAPPEDWINDOW,
x, y, width, height, einfo->info->parent,
menu, inst, einfo );
if( title ) {
if( is_rc ) {
WFreeRCString( title );
} else {
WMemFree( title );
}
}
if( einfo->win == (HWND)NULL ) {
return( FALSE );
}
if( !WCreateRibbon( einfo ) ) {
return( FALSE );
}
einfo->wsb = WCreateStatusLine( einfo->win, inst );
if( !einfo->wsb ) {
return( FALSE );
}
if( !WCreateStringEditWindow( einfo, inst ) ) {
return( FALSE );
}
hmenu = GetMenu( einfo->win );
if( hmenu != (HMENU)NULL ) {
EnableMenuItem( hmenu, IDM_STR_CUT, MF_GRAYED );
EnableMenuItem( hmenu, IDM_STR_COPY, MF_GRAYED );
}
if( WGetOption( WOptScreenMax ) ) {
ShowWindow( einfo->win, SW_SHOWMAXIMIZED );
} else {
ShowWindow( einfo->win, SW_SHOWNORMAL );
}
UpdateWindow( einfo->win );
WResizeWindows( einfo );
SetFocus( einfo->edit_dlg );
return( TRUE );
}
WStringEditInfo *WGetCurrentEditInfo ( void )
{
return ( WCurrEditInfo );
}
void WSetCurrentEditInfo ( WStringEditInfo *einfo )
{
WCurrEditInfo = einfo;
}
HMENU WGetMenuHandle ( WStringEditInfo *einfo )
{
if ( !einfo ) {
einfo = WGetCurrentEditInfo ();
}
if ( einfo && einfo->win ) {
return ( GetMenu ( einfo->win ) );
}
return ( NULL );
}
static void handleSymbols( WStringEditInfo *einfo )
{
if( !WEditSymbols( einfo->win, &einfo->info->symbol_table,
WGetEditInstance(), WStrHelpRoutine ) ) {
return;
}
WResolveStringTableSymIDs( einfo );
WHandleSelChange( einfo );
}
static void handleLoadSymbols( WStringEditInfo *einfo )
{
char *file;
int pos;
file = WLoadSymbols( &einfo->info->symbol_table,
einfo->info->symbol_file,
einfo->win, TRUE );
if( file == NULL ) {
return;
}
if( einfo->info->symbol_file ) {
WMemFree( einfo->info->symbol_file );
}
einfo->info->symbol_file = file;
pos = einfo->current_pos;
if( pos == -1 ) {
pos = 0;
}
// lookup the id associated with the symbol for all entries
WResolveStringTableSymIDs( einfo );
// look for the symbol matching the id for all entries
WResolveStringTable( einfo );
WInitEditWindowListBox( einfo );
WRAddSymbolsToComboBox( einfo->info->symbol_table, einfo->edit_dlg,
IDM_STREDCMDID, WR_HASHENTRY_ALL );
SendDlgItemMessage( einfo->edit_dlg, IDM_STREDLIST,
LB_SETCURSEL, pos, 0 );
einfo->info->modified = TRUE;
WDoHandleSelChange( einfo, FALSE, TRUE );
}
LRESULT WINEXPORT WMainWndProc ( HWND hWnd, UINT message,
WPARAM wParam, volatile LPARAM lParam )
{
HMENU menu;
#if 0
HWND win;
#endif
LRESULT ret;
Bool pass_to_def;
WStringEditInfo *einfo;
WORD wp;
MINMAXINFO *minmax;
pass_to_def = TRUE;
ret = FALSE;
einfo = (WStringEditInfo *) GetWindowLong ( hWnd, 0 );
WSetCurrentEditInfo ( einfo );
switch ( message ) {
case WM_ACTIVATE:
if( GET_WM_ACTIVATE_FACTIVE(wParam, lParam) &&
!GET_WM_ACTIVATE_FMINIMIZED(wParam, lParam) &&
einfo && einfo->edit_dlg != (HWND)NULL ) {
SetFocus( einfo->edit_dlg );
pass_to_def = FALSE;
}
break;
case WM_INITMENU:
if( wParam == (WPARAM) GetMenu(hWnd) ) {
// set the cut and copy menu items
ret = SendDlgItemMessage( einfo->edit_dlg, IDM_STREDLIST,
LB_GETCURSEL, 0, 0 );
if( ret != LB_ERR ) {
EnableMenuItem( (HMENU)wParam, IDM_STR_CUT, MF_ENABLED );
EnableMenuItem( (HMENU)wParam, IDM_STR_COPY, MF_ENABLED );
EnableMenuItem( (HMENU)wParam, IDM_STR_MEM_FLAGS, MF_ENABLED );
} else {
EnableMenuItem( (HMENU)wParam, IDM_STR_CUT, MF_GRAYED );
EnableMenuItem( (HMENU)wParam, IDM_STR_COPY, MF_GRAYED );
EnableMenuItem( (HMENU)wParam, IDM_STR_MEM_FLAGS, MF_GRAYED );
}
// set the paste menu item
if( OpenClipboard( hWnd ) ) {
if( //IsClipboardFormatAvailable( WClipbdFormat ) ||
IsClipboardFormatAvailable( CF_TEXT ) ) {
EnableMenuItem( (HMENU)wParam, IDM_STR_PASTE, MF_ENABLED );
} else {
EnableMenuItem( (HMENU)wParam, IDM_STR_PASTE, MF_GRAYED );
}
CloseClipboard();
}
ret = FALSE;
}
break;
case WM_CREATE:
einfo = ((CREATESTRUCT *)lParam)->lpCreateParams;
SetWindowLong ( hWnd, 0, (LONG)einfo );
break;
case WM_MENUSELECT:
if ( einfo ) {
menu = WGetMenuHandle ( einfo );
WHandleMenuSelect ( einfo->wsb, menu, wParam, lParam );
}
break;
case WM_GETMINMAXINFO:
minmax = (MINMAXINFO *) lParam;
minmax->ptMinTrackSize.x = appWidth;
minmax->ptMinTrackSize.y = appHeight;
break;
case WM_MOVE:
if ( einfo ) {
if ( IsZoomed ( hWnd ) ) {
WSetOption ( WOptScreenMax, TRUE );
} else if ( !IsIconic ( hWnd ) ) {
WUpdateScreenPosOpt ( hWnd );
WSetOption ( WOptScreenMax, FALSE );
}
}
break;
case WM_SIZE:
if ( einfo ) {
if ( wParam == SIZE_MAXIMIZED ) {
WSetOption ( WOptScreenMax, TRUE );
} else if ( wParam != SIZE_MINIMIZED ) {
WUpdateScreenPosOpt ( hWnd );
WSetOption ( WOptScreenMax, FALSE );
}
WResizeWindows ( einfo );
}
break;
case WM_COMMAND:
wp = LOWORD(wParam);
switch ( wp ) {
case IDM_STR_CLEAR:
WHandleClear( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_UPDATE:
SendMessage( einfo->info->parent, STRING_PLEASE_SAVEME, 0,
(LPARAM)einfo->hndl );
pass_to_def = FALSE;
break;
case IDM_STR_OPEN:
pass_to_def = FALSE;
if( einfo->info->modified ) {
ret = WQuerySave( einfo, FALSE );
if( !ret ) {
break;
}
}
ret = SendMessage( einfo->info->parent,
STRING_PLEASE_OPENME, 0,
(LPARAM)einfo->hndl );
ret = FALSE;
break;
case IDM_STR_SAVE:
WSaveObject( einfo, FALSE, FALSE );
pass_to_def = FALSE;
break;
case IDM_STR_SAVEAS:
WSaveObject( einfo, TRUE, FALSE );
pass_to_def = FALSE;
break;
case IDM_STR_SAVEINTO:
WSaveObject( einfo, TRUE, TRUE );
pass_to_def = FALSE;
break;
case IDM_STR_EXIT:
/* clean up before we exit */
PostMessage( einfo->win, WM_CLOSE, 0, 0 );
break;
case IDM_STR_PASTE:
WPasteStringItem( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_CUT:
case IDM_STR_COPY:
WClipStringItem( einfo, ( wp == IDM_STR_CUT ) );
pass_to_def = FALSE;
break;
case IDM_STR_DELETE:
WDeleteStringEntry ( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_NEWITEM:
WInsertStringEntry ( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_SYMBOLS:
handleSymbols( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_LOAD_SYMBOLS:
handleLoadSymbols( einfo );
pass_to_def = FALSE;
break;
case IDM_STR_SHOWRIBBON:
menu = WGetMenuHandle ( einfo );
WShowRibbon ( einfo, menu );
pass_to_def = FALSE;
break;
case IDM_STR_MEM_FLAGS:
WHandleMemFlags( einfo );
pass_to_def = FALSE;
break;
case IDM_HELP:
WStrHelpRoutine();
pass_to_def = FALSE;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -