📄 document.cpp
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/EnhPi3/Document.cpp,v $
* $Date: 2003/05/13 18:41:57 $
*
Description:
\*____________________________________________________________________________*/
/* $SourceTop:$ */
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <assert.h>
#include "DblList.h"
#include "PIString.h"
#include "resrc1.h"
#include "Dialogs.h"
#include "Config.h"
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
static HWND hWndList = 0;
static HWND hWndFileExt = 0;
static HWND hWndMime = 0;
static HWND hWndAdd = 0;
static HWND hWndReplace = 0;
static HWND hWndDelete = 0;
static DblList lExtensions;
static DblList lMIMEs;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_addLine( const char *pLine )
{
assert( pLine );
assert( lExtensions.Size()==lMIMEs.Size() );
int i;
for( i=0; pLine[i] && !isspace(pLine[i]); i++ );
/* --- scan to tab --- */
lExtensions.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
/* --- scan over whitespace to start of Media type/subtype --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
lMIMEs.Append( (DblList::type)PI_NEW( PIString( &(pLine[i]) ) ) );
assert( lExtensions.Size()==lMIMEs.Size() );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_updateButtons( WPARAM wParam, LPARAM lParam, HWND hWndEdit1,
HWND hWndEdit2, const char *pExtension )
{
if ( GET_WM_COMMAND_CMD(wParam, lParam)!=EN_CHANGE )
{ return; };
/*
** If the file extension changed then check if this is an existing
** file extension
*/
int iExistingIndex = -1;
assert( pExtension );
int iIndex = 0;
if ( *pExtension )
{
for( DblListIterator i( lExtensions ); !i.BadIndex(); i++, iIndex++ )
{
PIString *pString = (PIString *)i.Current();
assert( pString );
if ( (*pString)==pExtension )
{
iExistingIndex = iIndex;
break;
};
};
};
/*
** Remove listbox selection or scroll to correct line
** as appropriate
*/
SendMessage( hWndList, LB_SETCURSEL, iExistingIndex, 0 );
/*
** Set buttons
*/
if ( SendMessage( hWndEdit1, EM_LINELENGTH, 0, 0 )==0 )
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
}
else if ( SendMessage( hWndEdit2, EM_LINELENGTH, 0, 0 )!=0 )
{
if ( iExistingIndex>-1 ) /* --- disable add, enable replace --- */
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( !IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, TRUE );
}
else /* --- disable replace, enable add --- */
{
if ( !IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, TRUE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
};
};
/*
** If there is a selected item in the listbox then
** enable delete, otherwise disable delete
*/
if ( SendMessage( hWndList, LB_GETCURSEL, 0, 0 )==LB_ERR )
{ EnableWindow( hWndDelete, FALSE ); }
else
{ EnableWindow( hWndDelete, TRUE ); };
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static BOOL CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
enum { BUF_SIZE=1023 };
char szBuf[BUF_SIZE+1];
int aTabstop[2];
switch (uMsg)
{
case WM_INITDIALOG:
AD_hourglassOn();
{
const char *pTmp;
int iTmp;
hWndList = GetDlgItem( hDlg, IDC_LIST );
hWndFileExt = GetDlgItem( hDlg, IDC_VARIABLE );
hWndMime= GetDlgItem( hDlg, IDC_VALUE );
hWndAdd = GetDlgItem( hDlg, IDC_ADD );
hWndReplace = GetDlgItem( hDlg, IDC_REPLACE );
hWndDelete= GetDlgItem( hDlg, IDC_DELETE );
assert( hWndList && hWndFileExt && hWndMime );
assert( hWndAdd && hWndReplace && hWndDelete );
EnableWindow( hWndAdd, FALSE );
EnableWindow( hWndReplace, FALSE );
EnableWindow( hWndDelete, FALSE );
/*
** Limit edit field lengths, really just a sanity thing
*/
SendMessage( hWndFileExt, EM_SETLIMITTEXT, 256, 0 );
SendMessage( hWndMime, EM_SETLIMITTEXT, 256, 0 );
/*
** Setup tabstops
*/
aTabstop[0] = 0;
aTabstop[1] = 75;
SendMessage( hWndList, LB_SETTABSTOPS, 2, (LPARAM)&aTabstop );
/*
** Setup tabstops
*/
aTabstop[0] = 0;
aTabstop[1] = 75;
SendMessage( hWndList, LB_SETTABSTOPS, 2, (LPARAM)&aTabstop );
/*
** Load all mime types
*/
iTmp = 0;
for(;; iTmp++ )
{
pTmp = AD_lookupValueEx( __pConfig, "MIMETypes",
"Mapping", iTmp );
if ( !pTmp )
{ break; };
if ( SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)pTmp )>=0 )
{
Internal_addLine( pTmp );
}
else
{ break; /* error */; };
};
}
AD_hourglassOff();
break;
case WM_DESTROY:
{
int i;
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
/*
** Save all mime types
*/
DblListIterator x( lExtensions );
DblListIterator y( lMIMEs );
for( i=0; i<iCount; i++, x++, y++ )
{
/*
** Delete this entry in extensions and MIME lists
*/
assert( !x.BadIndex() && !y.BadIndex() );
PI_DELETE( (PIString *)x.Current() );
PI_DELETE( (PIString *)y.Current() );
};
lExtensions.Clear();
lMIMEs.Clear();
};
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDC_ADD:
{
int i;
*szBuf = '\0';
SendMessage( hWndFileExt, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
for( i=0; i<BUF_SIZE && szBuf[i] && !isspace( szBuf[i] ); i++ );
if ( szBuf[i] ) { szBuf[i] = '\0'; };
lExtensions.Append( (DblList::type)PI_NEW( PIString( szBuf ) ) );
szBuf[i++] = '\t';
SendMessage( hWndMime, WM_GETTEXT, BUF_SIZE-i, (LPARAM)&(szBuf[i]) );
lMIMEs.Append( (DblList::type)PI_NEW( PIString( &(szBuf[i]) ) ) );
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndFileExt, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndMime, WM_SETTEXT, 0, (LPARAM)"" );
SetFocus( hWndList );
};
break;
case IDC_REPLACE:
{
/*
** Get selected item index
*/
int iCurSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
/*
** Get text to add and add it to internal lists only
*/
int i;
*szBuf = '\0';
SendMessage( hWndFileExt, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
for( i=0; i<BUF_SIZE && szBuf[i] && !isspace( szBuf[i] ); i++ );
if ( szBuf[i] ) { szBuf[i] = '\0'; };
lExtensions.Append( (DblList::type)PI_NEW( PIString( szBuf ) ) );
szBuf[i++] = '\t';
SendMessage( hWndMime, WM_GETTEXT, BUF_SIZE-i, (LPARAM)&(szBuf[i]) );
lMIMEs.Append( (DblList::type)PI_NEW( PIString( &(szBuf[i]) ) ) );
/*
** Delete the item from the list and internal lists
*/
SendMessage( hWndList, LB_DELETESTRING, iCurSel, 0 );
PI_DELETE( (PIString *)lExtensions.Detach( iCurSel) );
PI_DELETE( (PIString *)lMIMEs.Detach( iCurSel) );
/*
** Add new item to listbox
*/
SendMessage( hWndList, LB_ADDSTRING, 0, (LPARAM)szBuf );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndFileExt, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndMime, WM_SETTEXT, 0, (LPARAM)"" );
SetFocus( hWndList );
};
break;
case IDC_DELETE:
{
int iCurSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
SendMessage( hWndList, LB_DELETESTRING, iCurSel, 0 );
PI_DELETE( (PIString *)lExtensions.Detach( iCurSel) );
PI_DELETE( (PIString *)lMIMEs.Detach( iCurSel) );
/*
** Clear edit fields, focus to list
*/
SendMessage( hWndFileExt, WM_SETTEXT, 0, (LPARAM)"" );
SendMessage( hWndMime, WM_SETTEXT, 0, (LPARAM)"" );
SetFocus( hWndList );
};
break;
case IDC_FILEEXT:
*szBuf = '\0';
SendMessage( hWndFileExt, WM_GETTEXT, BUF_SIZE, (LPARAM)szBuf );
Internal_updateButtons( wParam, lParam, hWndFileExt,
hWndMime, szBuf );
break;
case IDC_MIME:
*szBuf = '\0';
SendMessage( hWndFileExt, WM_GETTEXT, BUF_SIZE,(LPARAM)szBuf );
Internal_updateButtons( wParam, lParam, hWndMime,
hWndFileExt, szBuf );
break;
case IDC_LIST:
if ( GET_WM_COMMAND_CMD(wParam, lParam)==LBN_SELCHANGE )
{
int iSel = SendMessage( hWndList, LB_GETCURSEL, 0, 0 );
if ( iSel!=LB_ERR )
{
assert( iSel>=0 && iSel<lExtensions.Size() );
EnableWindow( hWndDelete, TRUE );
SendMessage( hWndFileExt, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lExtensions[iSel]) );
SendMessage( hWndMime, WM_SETTEXT, 0,
(LPARAM)(const char *)*((PIString *)lMIMEs[iSel]) );
};
};
break;
default:;
}
break;
case WM_NOTIFY:
{
switch( ((NMHDR *)lParam)->code )
{
case PSN_QUERYCANCEL:
return AD_cancel( hDlg );
case PSN_KILLACTIVE:
if ( AD_IsChanged() )
{
int i;
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
/*
** Save all mime types
*/
/* --- remove old ones first --- */
AD_deleteValue( __pConfig, "MIMETypes", "Mapping" );
for( i=0; i<iCount; i++ )
{
*szBuf = '\0';
szBuf[BUF_SIZE] = '\0';
/*
** safety only
*/
if ( SendMessage( hWndList, LB_GETTEXTLEN, 0, 0 ) >= BUF_SIZE )
{
MessageBox( hDlg, "MIMEType too long", "Internal Error", MB_OK );
break;
};
SendMessage( hWndList, LB_GETTEXT, i, (LPARAM)szBuf );
AD_addValue( __pConfig, "MIMETypes", "Mapping", szBuf );
};
SetWindowLong( hDlg, DWL_MSGRESULT, FALSE );
break;
}
default:
return FALSE;
};
};
break;
default:
return FALSE;
};
return TRUE;
return (FALSE);
}
/*____________________________________________________________________________*\
*
Description:
Definitions and global values
\*____________________________________________________________________________*/
DLGPROC fnDocuments = (DLGPROC)DialogProc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -