📄 mapping.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/Mapping.cpp,v $
* $Date: 2003/05/13 18:41:58 $
*
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 hWndType = 0;
static HWND hWndFrom = 0;
static HWND hWndTo = 0;
static HWND hWndRealm = 0;
static HWND hWndAdd = 0;
static HWND hWndReplace = 0;
static HWND hWndDelete = 0;
static DblList lTypes;
static DblList lFroms;
static DblList lTos;
static DblList lRealms;
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static int Internal_verifyFields( HWND hDlg, char *pszBuf, int iBufSize )
{
assert( pszBuf && iBufSize );
*pszBuf = '\0';
int i;
int iFromLen;
int iToLen;
SendMessage( hWndFrom, WM_GETTEXT, iBufSize, (LPARAM)pszBuf );
/*
** 'From' must begin and end with '/'
*/
assert( *pszBuf );
iFromLen = strlen(pszBuf);
if ( *pszBuf!='/' || pszBuf[iFromLen-1]!='/' )
{
MessageBox( hDlg, "'From' field must begin and end with a forward-slash ('/').",
"Error in 'From' Field", MB_OK | MB_ICONEXCLAMATION );
::SetFocus( hWndFrom );
::SendMessage( hWndFrom, EM_SETSEL, (WPARAM)(INT)0, (LPARAM)(INT)-1 );
goto verify_fail;
};
/*
** Scan for spaces
*/
for( i=0; i<iFromLen; i++)
{
if ( isspace( pszBuf[i] ) )
{
MessageBox( hDlg, "'From' field may not contain spaces or tabs.",
"Error in 'From' Field", MB_OK | MB_ICONEXCLAMATION );
goto verify_fail;
};
};
SendMessage( hWndTo, WM_GETTEXT, iBufSize, (LPARAM)pszBuf );
/*
** 'To' must end with '/'
*/
assert( *pszBuf );
iToLen = strlen(pszBuf);
if ( pszBuf[iToLen-1]!='/' && pszBuf[iToLen-1]!='\\' )
{
MessageBox( hDlg, "'To' field must end with a forward-slash ('/') \
or a backslash ('\\').",
"Error in 'To' Field", MB_OK | MB_ICONEXCLAMATION );
::SetFocus( hWndTo );
::SendMessage( hWndTo, EM_SETSEL, (WPARAM)(INT)0, (LPARAM)(INT)-1 );
goto verify_fail;
};
/*
** Some realm must be selected, even if it is '(none)'
*/
if ( ::SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )==CB_ERR )
{
::SendMessage( hWndRealm, CB_SETCURSEL, (WPARAM)::SendMessage(
hWndRealm,
CB_SETCURSEL,
::SendMessage( hWndRealm, CB_FINDSTRINGEXACT, 0, (LPARAM)"(none)" ),
0 ), 0 );
assert( ::SendMessage( hWndRealm, CB_GETCURSEL, 0, 0 )!=CB_ERR );
};
/*
** Good
*/
return 1;
verify_fail:
return 0;
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
Insert values from listbox into values array. Sort
the lines in reverse order of virtual path component length.
\*____________________________________________________________________________*/
static void Internal_saveValues( HWND hDlg )
{
enum { BUF_SIZE=1023 };
char pszBuf[BUF_SIZE+1];
for(;;)
{
int iCount = SendMessage( hWndList, LB_GETCOUNT, 0, 0 );
if ( !iCount )
{ return; };
int iBiggest = -1;
int iBiggestIndex = -1;
for( int j=0; j<iCount; j++ )
{
/*
** Get string
*/
if ( SendMessage( hWndList, LB_GETTEXTLEN, j, 0 ) >= BUF_SIZE )
{
MessageBox( hDlg, "Mapping line too long", "Internal Error", MB_OK );
return;
};
SendMessage( hWndList, LB_GETTEXT, j, (LPARAM)pszBuf );
/*
** Get number of components in path
*/
int iNumComponents = 0;
int i=0;
for( ; pszBuf[i] && pszBuf[i]!='\t'; i++ );
for( ; pszBuf[i] && isspace(pszBuf[i]); i++ );
for( ; pszBuf[i] && !isspace(pszBuf[i]); i++ )
{
if ( pszBuf[i]=='/' )
{
iNumComponents++;
i++;
if ( !pszBuf[i] || isspace(pszBuf[i]) )
{ break; };
};
};
if ( iNumComponents>iBiggest )
{
iBiggestIndex = j;
iBiggest = iNumComponents;
};
};
/*
** Add biggest line to list and remove it from
** listbox
*/
SendMessage( hWndList, LB_GETTEXT, iBiggestIndex, (LPARAM)pszBuf );
SendMessage( hWndList, LB_DELETESTRING, iBiggestIndex, 0 );
AD_addValue( __pConfig, "Mappings", "Mapping", pszBuf );
};
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_addLine( const char *pLine )
{
assert( pLine );
assert( lTypes.Size()==lFroms.Size() );
assert( lFroms.Size()==lTos.Size() );
int i = 0;
/* --- scan to tab --- */
for( ; pLine[i] && pLine[i]!='\t'; i++ );
lTypes.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
/* --- scan over whitespace to start of from --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
pLine = &( pLine[i] );
i=0;
/* --- scan to tab --- */
for( ; pLine[i] && pLine[i]!='\t'; i++ );
lFroms.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
/* --- scan over whitespace to start of to --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
pLine = &( pLine[i] );
i=0;
/* --- scan to tab --- */
for( ; pLine[i] && pLine[i]!='\t'; i++ );
lTos.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) );
/* --- scan over whitespace to start of realm --- */
for( ; pLine[i] && isspace(pLine[i]); i++ );
pLine = &( pLine[i] );
i=0;
/* --- scan to tab --- */
for( ; pLine[i] && pLine[i]!='\t'; i++ );
if ( i )
{ lRealms.Append( (DblList::type)PI_NEW( PIString( pLine, i ) ) ); }
else
{ lRealms.Append( (DblList::type)PI_NEW( PIString( "(none)" ) ) ); }
assert( lTypes.Size()==lFroms.Size() );
assert( lFroms.Size()==lTos.Size() );
}
/*____________________________________________________________________________*\
*
Function:
Synopsis:
Description:
\*____________________________________________________________________________*/
static void Internal_updateButtons( WPARAM wParam, LPARAM lParam,
const char *pFrom )
{
int iCBSel = SendMessage( hWndType, CB_GETCURSEL, 0, 0 );
const char *pType = 0;
if ( iCBSel>-1 )
{
pType = AD_lookupValueEx( __pConfig, "Internal",
"MappingTypes", iCBSel );
assert( pType );
};
/*
** If the 'from' changed check is it an existing one.
*/
int iExistingIndex = -1;
assert( pFrom );
int iIndex = 0;
if ( *pFrom )
{
for( DblListIterator i( lFroms ); !i.BadIndex(); i++, iIndex++ )
{
PIString *pString = (PIString *)i.Current();
assert( pString );
if ( (*pString)==pFrom )
{
iExistingIndex = iIndex;
break;
};
};
};
/*
** Remove listbox selection or scroll to correct line
** as appropriate
*/
SendMessage( hWndList, LB_SETCURSEL, iExistingIndex, 0 );
/*
** Set buttons
*/
if ( iCBSel<0 || SendMessage( hWndType, CB_GETLBTEXTLEN, iCBSel, 0 )==0 ||
SendMessage( hWndFrom, EM_LINELENGTH, 0, 0 )==0 ||
SendMessage( hWndTo, EM_LINELENGTH, 0, 0 )==0 )
{
if ( IsWindowEnabled( hWndAdd ) ) EnableWindow( hWndAdd, FALSE );
if ( IsWindowEnabled( hWndReplace ) ) EnableWindow( hWndReplace, FALSE );
}
else
{
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[4];
switch (uMsg)
{
case WM_INITDIALOG:
AD_hourglassOn();
{
const char *pTmp;
int iTmp;
hWndList = GetDlgItem( hDlg, IDC_LIST );
hWndType = GetDlgItem( hDlg, IDC_TYPE );
hWndFrom = GetDlgItem( hDlg, IDC_FROM );
hWndTo = GetDlgItem( hDlg, IDC_TO );
hWndRealm = GetDlgItem( hDlg, IDC_REALM );
hWndAdd = GetDlgItem( hDlg, IDC_ADD );
hWndReplace = GetDlgItem( hDlg, IDC_REPLACE );
hWndDelete= GetDlgItem( hDlg, IDC_DELETE );
assert( hWndList && hWndType && hWndFrom && hWndTo );
assert( hWndAdd && hWndReplace && hWndDelete && hWndRealm );
EnableWindow( hWndAdd, FALSE );
EnableWindow( hWndReplace, FALSE );
EnableWindow( hWndDelete, FALSE );
/*
** Add options to 'Types' combo-box
*/
iTmp = 0;
for(;; iTmp++ )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -