?? chwlistd.cpp
字號:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
The contents of this file are subject to the Andromedia Public
License Version 1.0 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.andromedia.com/APL/
Software distributed under the License is distributed on an
"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Pueblo client code, released November 4, 1998.
The Initial Developer of the Original Code is Andromedia Incorporated.
Portions created by Andromedia are Copyright (C) 1998 Andromedia
Incorporated. All Rights Reserved.
Andromedia Incorporated 415.365.6700
818 Mission Street - 2nd Floor 415.365.6701 fax
San Francisco, CA 94103
Contributor(s):
--------------------------------------------------------------------------
Chaco team: Dan Greening, Glenn Crocker, Jim Doubek,
Coyote Lussier, Pritham Shetty.
Wrote and designed original codebase.
------------------------------------------------------------------------------
Implementation for the ChWorldListDlg class.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChWorld/ChWListD.cpp,v 2.27 1996/09/12 19:10:10 pritham Exp $
#include "headers.h"
#if !defined(CH_PUEBLO_PLUGIN)
#include "resource.h"
#else
#include "vwrres.h"
#endif
#include <ChCore.h>
#include <ChUtil.h>
#include "ChWListD.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/*----------------------------------------------------------------------------
ChWorldListDlg class
----------------------------------------------------------------------------*/
ChWorldListDlg::ChWorldListDlg( ChCore* pCore, bool boolConnected, CWnd* pParent ) :
ChDialog(
#if defined( CH_PUEBLO_PLUGIN )
(chparam)AfxGetInstanceHandle(),
#else
(chparam)ChWorldDLL.hModule,
#endif
ChWorldListDlg::IDD,
pParent ),
m_pCore( pCore ),
m_boolConnected( boolConnected )
{
//{{AFX_DATA_INIT(ChWorldListDlg)
//}}AFX_DATA_INIT
}
void ChWorldListDlg::DoDataExchange( CDataExchange* pDX )
{
CDialog::DoDataExchange( pDX );
//{{AFX_DATA_MAP(ChWorldListDlg)
DDX_Control(pDX, IDC_LIST_ADD, m_btnAdd);
DDX_Control(pDX, IDC_LIST_EDIT, m_btnEdit);
DDX_Control(pDX, IDC_LIST_DELETE, m_btnDelete);
DDX_Control(pDX, IDC_LIST_CONNECT, m_btnConnect);
DDX_Control(pDX, IDC_WORLD_LIST, m_listWorlds);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP( ChWorldListDlg, CDialog )
//{{AFX_MSG_MAP( ChWorldListDlg )
ON_BN_CLICKED(IDC_LIST_ADD, OnListAdd)
ON_LBN_SELCHANGE(IDC_WORLD_LIST, OnSelchangeWorldList)
ON_BN_CLICKED(IDC_LIST_DELETE, OnListDelete)
ON_BN_CLICKED(IDC_LIST_CONNECT, OnListConnect)
ON_BN_CLICKED(IDC_LIST_EDIT, OnListEdit)
ON_BN_CLICKED(IDC_LIST_CREATE_SHORTCUT, OnListCreateShortcut)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/*----------------------------------------------------------------------------
ChWorldListDlg protected methods
----------------------------------------------------------------------------*/
void ChWorldListDlg::Add( bool boolChange, const string& strName,
const string& strDesc, const string& strHost,
chint16 sPort, const ChWorldType& type,
ChLoginType login, const string& strUsername,
const string& strPassword,
const string& strHomePage )
{
if (!boolChange)
{ // Add name to list box
int iIndex;
iIndex = AddNameToList( strName, strUsername );
if (LB_ERR != iIndex)
{
m_listWorlds.SetCurSel( iIndex );
UpdateButtons();
}
}
/* Add or change the item in the
data structure */
m_worldList.Add( strName, strDesc, strHost, sPort, type, login,
strUsername, strPassword, strHomePage );
}
void ChWorldListDlg::UpdateButtons()
{
bool boolEnable;
if (m_listWorlds.GetCurSel() != LB_ERR)
{
boolEnable = true;
}
else
{
boolEnable = false;
}
m_btnDelete.EnableWindow( boolEnable );
m_btnEdit.EnableWindow( boolEnable );
/* Only enable the connect button
if we're not already
connected */
m_btnConnect.EnableWindow( boolEnable && !m_boolConnected );
}
void ChWorldListDlg::InstallWorldList()
{
ChPosition pos;
pos = m_worldList.GetHead();
while( pos )
{
ChWorldInfo* pInfo;
pInfo = m_worldList.GetData( pos );
AddNameToList( pInfo->GetName(), pInfo->GetUsername() );
m_worldList.GetNext( pos );
}
if (m_listWorlds.GetCount() > 0)
{
m_listWorlds.SetCurSel( 0 );
OnSelchangeWorldList();
}
UpdateButtons();
}
void ChWorldListDlg::CreateShortcut()
{
ChWorldInfo info( GetName(), GetDesc(), GetHost(), GetPort(),
GetType(), GetLoginType(), GetUsername(),
GetPassword(), GetHomePage() );
info.CreateShortcut( m_pCore );
}
int ChWorldListDlg::AddNameToList( const string& strName,
const string& strUsername )
{
string strEntry( strName );
if (!strUsername.IsEmpty())
{
strEntry += " ";
strEntry += WORLD_NAME_SEPARATOR;
strEntry += " " + strUsername;
}
return m_listWorlds.AddString( strEntry );
}
void ChWorldListDlg::ExtractName( const string& strListEntry, string& strName,
string& strUsername )
{
int iLoc;
if (-1 != (iLoc = strListEntry.Find( WORLD_NAME_SEPARATOR )))
{
strName = strListEntry.Left( iLoc - 1 );
strUsername = strListEntry.Mid( iLoc + 2 );
}
else
{
strName = strListEntry;
strUsername = "";
}
}
/*----------------------------------------------------------------------------
SyncDataFields
This method will take the data for the currently selected item in
the list and store this data in the dialog's data fields.
----------------------------------------------------------------------------*/
bool ChWorldListDlg::SyncDataFields()
{
ChWorldInfo* pInfo = GetCurrInfo();
bool boolSuccess;
if (0 != pInfo)
{
m_strName = pInfo->GetName();
m_strDesc = pInfo->GetDesc();
m_strHost = pInfo->GetHost();
m_strAddr = pInfo->GetAddr();
m_sPort = pInfo->GetPort();
m_type = pInfo->GetType();
m_loginType = pInfo->GetLoginType();
m_strUsername = pInfo->GetUsername();
m_strPassword = pInfo->GetPassword();
m_strHomePage = pInfo->GetHomePage();
boolSuccess = true;
}
else
{
boolSuccess = false;
}
return boolSuccess;
}
ChWorldInfo* ChWorldListDlg::GetCurrInfo()
{
ChWorldInfo *pInfo;
int iSel;
if (LB_ERR == (iSel = m_listWorlds.GetCurSel()))
{
pInfo = 0;
}
else
{
string strItem;
string strName;
string strUsername;
m_listWorlds.GetText( iSel, strItem );
ExtractName( strItem, strName, strUsername );
pInfo = m_worldList.FindName( strName, strUsername );
}
return pInfo;
}
void ChWorldListDlg::Delete( int iIndex )
{ /* Deletes an indexed item from
the list */
string strEntry;
string strName;
string strUsername;
int iCount;
m_listWorlds.GetText( iIndex, strEntry );
ExtractName( strEntry, strName, strUsername );
m_worldList.Remove( strName, strUsername );
m_listWorlds.DeleteString( iIndex );
iCount = m_listWorlds.GetCount();
if (iCount > 0)
{
if (iIndex >= iCount)
{
iIndex = iCount - 1;
}
m_listWorlds.SetCurSel( iIndex );
}
}
/*----------------------------------------------------------------------------
ChWorldListDlg message handlers
----------------------------------------------------------------------------*/
bool ChWorldListDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow();
InstallWorldList();
UpdateButtons();
if (m_listWorlds.GetCount() > 0 &&
LB_ERR != m_listWorlds.GetCurSel())
{
m_listWorlds.SetFocus();
m_listWorlds.SetCurSel( 0 );
}
else
{
m_btnAdd.SetFocus();
}
return false;
}
void ChWorldListDlg::OnOK()
{
CDialog::OnOK();
m_worldList.Store();
}
void ChWorldListDlg::OnListCreateShortcut()
{
SyncDataFields();
CreateShortcut();
}
void ChWorldListDlg::OnListConnect()
{
SyncDataFields();
m_worldList.Store();
EndDialog( IDC_LIST_CONNECT );
}
void ChWorldListDlg::OnListDelete()
{
int iSel;
if (LB_ERR != (iSel = m_listWorlds.GetCurSel()))
{
Delete( iSel );
}
UpdateButtons();
}
void ChWorldListDlg::OnListAdd()
{
ChWorldListEdit editDlg;
int iResult;
iResult = editDlg.DoModal();
if (IDOK == iResult)
{
ASSERT( variableLogin != editDlg.GetLoginType() );
Add( false, editDlg.GetName(), editDlg.GetDesc(), editDlg.GetHost(),
editDlg.GetPort(), editDlg.GetType(), editDlg.GetLoginType(),
editDlg.GetUsername(), editDlg.GetPassword(),
editDlg.GetHomePage() );
}
UpdateButtons();
}
void ChWorldListDlg::OnListEdit()
{
if (SyncDataFields())
{
string strOldName = GetName();
string strOldUsername = GetUsername();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -