Adding sources for the new Listcontrol and removing now obsolete stuff for the old one

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@80 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
gunfight 2002-04-25 13:53:06 +00:00
parent efcb6fa969
commit f4b9aca1d7
7 changed files with 447 additions and 490 deletions

View File

@ -1,153 +0,0 @@
//////////////////////////////////////////////////////////////////////
//
// ShellBrowser.cpp: implementation of the CShellBrowser class.
//
#include "pch.hxx"
#include "BrowseForFolder.hxx"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CBrowseForFolder::CBrowseForFolder(const HWND hParent, const LPITEMIDLIST pidl,
LPCTSTR strTitle)
{
m_hwnd = NULL;
SetOwner(hParent);
SetRoot(pidl);
m_bi.lpfn = BrowseCallbackProc;
m_bi.lParam = reinterpret_cast<LPARAM>( this );
m_bi.pszDisplayName = m_szSelected;
m_bi.lpszTitle = strTitle;
}
CBrowseForFolder::~CBrowseForFolder()
{
}
void CBrowseForFolder::SetOwner(const HWND hwndOwner)
{
if (m_hwnd != NULL)
return;
m_bi.hwndOwner = hwndOwner;
}
void CBrowseForFolder::SetRoot(const LPITEMIDLIST pidl)
{
if (m_hwnd != NULL)
return;
m_bi.pidlRoot = pidl;
}
LPCTSTR CBrowseForFolder::GetTitle() const
{
return m_bi.lpszTitle;
}
void CBrowseForFolder::SetFlags(const UINT ulFlags)
{
if (m_hwnd != NULL)
return;
m_bi.ulFlags = ulFlags;
}
LPCTSTR CBrowseForFolder::GetSelectedFolder(
void
) const
{
return m_szSelected;
}
bool CBrowseForFolder::SelectFolder()
{
bool bRet = false;
LPITEMIDLIST pidl;
if ((pidl = ::SHBrowseForFolder(&m_bi)) != NULL)
{
m_strPath.Set( _T("") );
if (SUCCEEDED(::SHGetPathFromIDList(pidl, m_szSelected)))
{
bRet = true;
m_strPath.Set( m_szSelected );
}
LPMALLOC pMalloc;
//Retrieve a pointer to the shell's IMalloc interface
if (SUCCEEDED(SHGetMalloc(&pMalloc)))
{
// free the PIDL that SHBrowseForFolder returned to us.
pMalloc->Free(pidl);
// release the shell's IMalloc interface
(void)pMalloc->Release();
}
}
m_hwnd = NULL;
return bRet;
}
void CBrowseForFolder::OnInit() const
{
}
void CBrowseForFolder::OnSelChanged(const LPITEMIDLIST pidl) const
{
(void)pidl;
}
void CBrowseForFolder::EnableOK(const bool bEnable) const
{
if (m_hwnd == NULL)
return;
// (void)SendMessage(m_hwnd, BFFM_ENABLEOK, static_cast(bEnable), NULL);
(void)SendMessage( m_hwnd, BFFM_ENABLEOK, NULL, static_cast<LPARAM>(bEnable) );
}
void CBrowseForFolder::SetSelection(const LPITEMIDLIST pidl) const
{
if (m_hwnd == NULL)
return;
(void)SendMessage(m_hwnd, BFFM_SETSELECTION, FALSE, reinterpret_cast<LPARAM>(pidl));
}
void CBrowseForFolder::SetSelection(
LPCTSTR strPath
) const
{
if (m_hwnd == NULL)
return;
(void)SendMessage(m_hwnd, BFFM_SETSELECTION, TRUE, reinterpret_cast<LPARAM>(strPath));
}
void CBrowseForFolder::SetStatusText(
LPCTSTR strText
) const
{
if (m_hwnd == NULL)
return;
(void)SendMessage(m_hwnd, BFFM_SETSTATUSTEXT, NULL, reinterpret_cast<LPARAM>(strText));
}
int __stdcall CBrowseForFolder::BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
CBrowseForFolder* pbff = reinterpret_cast<CBrowseForFolder*>( lpData );
pbff->m_hwnd = hwnd;
if (uMsg == BFFM_INITIALIZED)
pbff->OnInit();
else if (uMsg == BFFM_SELCHANGED)
pbff->OnSelChanged( reinterpret_cast<LPITEMIDLIST>( lParam ));
return 0;
}

View File

@ -1,175 +0,0 @@
//////////////////////////////////////////////////////////////////////
//
// ShellBrowser.h: interface for the CShellBrowser class.
//
// Copyright 1998 Scott D. Killen
//
//////////////////////////////////////////////////////////////////////
#ifndef __SHELLBROWSER_H__
#define __SHELLBROWSER_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include <shlobj.h>
/////////////////////////////////////////////////////////////////////
//
// CShellBrowser
//
class CBrowseForFolder
{
public:
#ifdef MFC
CBrowseForFolder(const HWND hParent = NULL,
const LPITEMIDLIST pidl = NULL,
const int nTitleID = 0);
#endif
CBrowseForFolder(const HWND hParent = NULL,
const LPITEMIDLIST pidl = NULL,
LPCTSTR strTitle = NULL );
virtual ~CBrowseForFolder();
//
// Set the handle of the owner window for the dialog box.
//
void SetOwner(const HWND hwndOwner);
//
// Set the root of the heirarchy that will be browsed. Get pidl from
// SHGetSpecialFolderLocation. This can be set to NULL to use the Virtual Folder
// that represents the Windows Desktop.
//
void SetRoot(const LPITEMIDLIST pidl);
//
// Access a string that is displayed above the tree view control in the dialog box.
// This string can be used to specify instructions to the user. strTitle is a
// CString containing the text to be displayed. nTitle is the index of a string
// resource to be loaded. The return value is false if the resource could not be
// loaded.
//
LPCTSTR GetTitle() const;
bool SetTitle(LPCTSTR strTitle);
#ifdef MFC
bool SetTitle(const int nTitle);
#endif
//
// ulFlags = Value specifying the types of folders to be listed in the dialog box
// as well as other options. This member can include zero or more of the following
// values:
//
// BIF_BROWSEFORCOMPUTER Only returns computers. If the user selects
// anything other than a computer, the OK button
// is grayed.
//
// BIF_BROWSEFORPRINTER Only returns printers. If the user selects
// anything other than a printer, the OK button
// is grayed.
//
// BIF_DONTGOBELOWDOMAIN Does not include network folders below the
// domain level in the tree view control.
//
// BIF_RETURNFSANCESTORS Only returns file system ancestors. If the user
// selects anything other than a file system
// ancestor, the OK button is grayed.
//
// BIF_RETURNONLYFSDIRS Only returns file system directories. If the
// user selects folders that are not part of the
// file system, the OK button is grayed.
//
// BIF_STATUSTEXT Includes a status area in the dialog box. The
// callback function can set the status text by
// sending messages to the dialog box.
//
UINT GetFlags() const;
void SetFlags(const UINT ulFlags);
//
// Call GetSelectedFolder to retrieve the folder selected by the user.
//
LPCTSTR GetSelectedFolder() const;
//
// Function to retreive the image associated with the selected folder. The image is
// specified as an index to the system image list.
//
int GetImage() const;
//
// Call SelectFolder to display the dialog and get a selection from the user. Use
// GetSelectedFolder and GetImage to get the results of the dialog.
//
bool SelectFolder();
protected:
//
// OnInit is called before the dialog is displayed on the screen.
//
virtual void OnInit() const;
//
// OnSelChanged is called whenever the user selects a different directory. pidl is
// the LPITEMIDLIST of the new selection. Use SHGetPathFromIDList to retrieve the
// path of the selection.
//
virtual void OnSelChanged(const LPITEMIDLIST pidl) const;
//
// Call EnableOK to enable the OK button on the active dialog. If bEnable is true
// then the button is enabled, otherwise it is disabled.
// NOTE -- This function should only be called within overrides of OnInit and
// OnSelChanged.
//
void EnableOK(const bool bEnable) const;
//
// Call SetSelection to set the selection in the active dialog. pidl is the
// LPITEMIDLIST
// of the path to be selected. strPath is a CString containing the path to be
// selected.
// NOTE -- This function should only be called within overrides of OnInit and
// OnSelChanged.
//
void SetSelection(const LPITEMIDLIST pidl) const;
void SetSelection(LPCTSTR strPath) const;
//
// Call SetStatusText to set the text in the Status area in the active dialog.
// strText is the text to be displayed.
// NOTE -- This function should only be called within overrides of OnInit and
// OnSelChanged.
//
void SetStatusText(LPCTSTR strText) const;
private:
static int __stdcall BrowseCallbackProc(HWND hwnd,
UINT uMsg,
LPARAM lParam,
LPARAM lpData);
CSimpleString m_pchTitle;
BROWSEINFO m_bi;
char m_szSelected[MAX_PATH];
CSimpleString m_strPath;
HWND m_hwnd;
};
inline UINT CBrowseForFolder::GetFlags() const
{
return m_bi.ulFlags;
}
inline int CBrowseForFolder::GetImage() const
{
return m_bi.iImage;
}
#endif // __SHELLBROWSER_H__

View File

@ -0,0 +1,378 @@
// GameList.cpp : implementation file
//
#include "pch.hxx"
#include "Cyberstella.h"
#include "GameList.h"
#include "MD5.hxx"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// GameList
GameList::GameList()
: rs("GameList")
{
rs.Bind(path, "ROM Path", "");
}
GameList::~GameList()
{
}
BEGIN_MESSAGE_MAP(GameList, CListCtrl)
//{{AFX_MSG_MAP(GameList)
ON_NOTIFY_REFLECT(LVN_COLUMNCLICK, OnColumnclick)
ON_NOTIFY_REFLECT(LVN_ITEMACTIVATE, OnItemActivate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GameList message handlers
// Sort the item in reverse alphabetical order.
static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
Properties* props1 = (Properties*) lParam1;
Properties* props2 = (Properties*) lParam2;
// Dots on top
if(strcmpi(props1->get("Cartridge.Type").c_str(), "Dots") == 0)
return 0;
if(strcmpi(props2->get("Cartridge.Type").c_str(), "Dots") == 0)
return 1;
// Directories on top
if((strcmpi(props1->get("Cartridge.Type").c_str(), "Directory") == 0)
&&(strcmpi(props2->get("Cartridge.Type").c_str(), "Directory") != 0))
return 0;
if((strcmpi(props1->get("Cartridge.Type").c_str(), "Directory") != 0)
&&(strcmpi(props2->get("Cartridge.Type").c_str(), "Directory") == 0))
return 1;
// Else compare by name
return strcmpi(props1->get("Cartridge.Name").c_str(),
props2->get("Cartridge.Name").c_str());
}
void GameList::deleteItemsAndProperties()
{
// First delete all Properties
for(int i = 0; i < GetItemCount(); i++)
{
Properties* props = (Properties*)GetItemData(i);
if(props) delete props;
}
// Second delete all items
DeleteAllItems();
}
void GameList::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void GameList::insertColumns()
{
CRect rect;
int width;
CString str;
GetClientRect(&rect);
width = (rect.Width()-20)/4;
// Insert Columns
str.LoadString(IDS_FILE);
InsertColumn (0, str, LVCFMT_LEFT, width);
str.LoadString(IDS_NAME);
InsertColumn (1, str, LVCFMT_LEFT, width);
str.LoadString(IDS_MANUFACTURER);
InsertColumn (2, str, LVCFMT_LEFT, width);
str.LoadString(IDS_RARITY);
InsertColumn (3, str, LVCFMT_LEFT, width);
}
void GameList::populateRomList()
{
CWaitCursor c;
// Remove previous content
deleteItemsAndProperties();
// Add new content
if(path.GetLength() > 0)
{
displayPath();
}
else
{
displayDrives();
}
// Sort content
SortItems(MyCompareProc, (LPARAM)(CListCtrl*)this);
// Select first item
SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
}
void GameList::displayPath()
{
CFileFind find;
CString name, searchpath;
BOOL bFind;
LVITEM lvi;
int itemCounter = 0;
BOOL first = true;
// Do pathname
if (path.GetAt(path.GetLength()-1) == '\\')
searchpath = path + "*.*";
else
searchpath = path + "\\*.*";
bFind = find.FindFile(searchpath);
while (bFind)
{
bFind = find.FindNextFile();
if (find.IsDirectory())
{
if (!find.IsDots())
{
name = find.GetFileName();
lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
lvi.iItem = itemCounter++;
lvi.iSubItem = 0;
lvi.pszText = name.GetBuffer(name.GetLength());
// set fake properties
Properties* props = new Properties();
props->set("Cartridge.Type", "Directory");
props->set("Cartridge.Name", name.GetBuffer(name.GetLength()));
lvi.lParam = (LPARAM)props;
//Set folder icon
lvi.iImage = 0;
InsertItem(&lvi);
}
}
else
{
name = find.GetFileName();
// Bail out if if this is not a *.BIN file
CString right = name.Right(4);
if (strcmpi(right, ".bin") != 0) continue;
// Bail out if we don't get properties
Properties* props = readRomData(find.GetFilePath());
if(props == NULL) continue;
lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
lvi.iItem = itemCounter++;
lvi.iSubItem = 0;
lvi.pszText = name.GetBuffer(name.GetLength());
lvi.lParam = (LPARAM)props;
// Set atari icon
lvi.iImage = 1;
InsertItem(&lvi);
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 1;
name = props->get("Cartridge.Name").c_str();
lvi.pszText = name.GetBuffer(name.GetLength());
SetItem(&lvi);
lvi.iSubItem = 2;
name = props->get("Cartridge.Manufacturer").c_str();
lvi.pszText = name.GetBuffer(name.GetLength());
SetItem(&lvi);
lvi.iSubItem = 3;
name = props->get("Cartridge.Rarity").c_str();
lvi.pszText = name.GetBuffer(name.GetLength());
SetItem(&lvi);
}
}
lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
lvi.iItem = itemCounter++;
lvi.iSubItem = 0;
lvi.pszText = "..";
// set fake properties
Properties* props = new Properties();
props->set("Cartridge.Type", "Dots");
lvi.lParam = (LPARAM)props;
//Set folder icon
lvi.iImage = 0;
InsertItem(&lvi);
}
void GameList::displayDrives()
{
DWORD dwDrives, dwMask;
LVITEM lvi;
bool first;
int itemCounter;
// Clear path
path = "";
//Enumerate drive letters and add them to list
dwDrives = GetLogicalDrives();
dwMask = 1;
first = true;
itemCounter = 0;
for (int i=0; i<32; i++)
{
if (dwDrives & dwMask)
{
CString sDrive;
sDrive.Format(_T("%c:\\"), i + _T('A'));
lvi.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
lvi.iItem = itemCounter++;
lvi.iSubItem = 0;
lvi.pszText = sDrive.GetBuffer(sDrive.GetLength());
// set fake properties
Properties* props = new Properties();
props->set("Cartridge.Type", "Directory");
props->set("Cartridge.Name", sDrive.GetBuffer(sDrive.GetLength()));
lvi.lParam = (LPARAM)props;
//Set folder icon
lvi.iImage = 0;
InsertItem(&lvi);
}
dwMask <<= 1;
}
}
void GameList::OnItemActivate(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int iItem = pNMListView->iItem;
if(iItem >= 0)
{
Properties* props = (Properties*)GetItemData(iItem);
CString dir = GetItemText(iItem,0);
if(strcmpi(props->get("Cartridge.Type").c_str(), "Dots") == 0)
{
int cutPos = path.ReverseFind('\\');
path = path.Left(cutPos);
populateRomList();
}
else if(strcmpi(props->get("Cartridge.Type").c_str(), "Directory") == 0)
{
// Do pathname
if (path.GetLength() <= 0)
{
path = dir;
}
else if (path.GetAt(path.GetLength()-1) != '\\')
{
path += "\\";
path += dir;
}
else
{
path += dir;
}
populateRomList();
}
}
*pResult = 0;
}
Properties* GameList::readRomData(CString binFile)
{
HANDLE hFile;
hFile = CreateFile(binFile, GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return NULL;
}
DWORD dwFileSize = ::GetFileSize(hFile, NULL);
BYTE* pImage = new BYTE[dwFileSize];
if (pImage == NULL)
{
return NULL;
}
DWORD dwRead;
if (::ReadFile(hFile, pImage, dwFileSize, &dwRead, NULL))
{
// Read the file, now check the md5
std::string md5 = MD5(pImage, dwFileSize);
// search through the properties set for this MD5
Properties* props = new Properties();
m_pPropertiesSet->getMD5(md5, *props);
// Return properties
delete[] pImage;
VERIFY(::CloseHandle(hFile));
return props;
}
delete[] pImage;
VERIFY(::CloseHandle(hFile));
return NULL;
}
CString GameList::getCurrentFile()
{
CString filename = "";
int curSel = GetSelectionMark();
if(curSel >= 0)
{
if (path.GetAt(path.GetLength()-1) != '\\')
path += "\\";
filename = path + GetItemText(curSel,0);
}
return filename;
}
CString GameList::getCurrentName()
{
int curSel = GetSelectionMark();
if(curSel >= 0)
{
return GetItemText(curSel,1);
}
return "";
}

View File

@ -0,0 +1,69 @@
#if !defined(AFX_GAMELIST_H__1EF8C3E1_4D6A_11D6_ACFC_0048546D2F04__INCLUDED_)
#define AFX_GAMELIST_H__1EF8C3E1_4D6A_11D6_ACFC_0048546D2F04__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// GameList.h : header file
//
#include "CRegBinding.h"
#include "PropsSet.hxx"
/////////////////////////////////////////////////////////////////////////////
// GameList window
class GameList : public CListCtrl
{
private:
// memebers saved in registry
CString path;
PropertiesSet* m_pPropertiesSet;
// Regbinding
CRegBinding rs;
// methods
void displayDrives();
void displayPath();
Properties* readRomData(CString binFile);
// Construction
public:
GameList();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(GameList)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~GameList();
void insertColumns();
void populateRomList();
void setPropertiesSet(PropertiesSet* newPropertiesSet)
{m_pPropertiesSet = newPropertiesSet;}
void deleteItemsAndProperties();
CString getCurrentFile();
CString getCurrentName();
// Generated message map functions
protected:
//{{AFX_MSG(GameList)
afx_msg void OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnItemActivate(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GAMELIST_H__1EF8C3E1_4D6A_11D6_ACFC_0048546D2F04__INCLUDED_)

View File

@ -1,6 +0,0 @@
//
// StellaX
// Jeff Miller 05/12/2000
//
#include "ListData.hxx"

View File

@ -1,156 +0,0 @@
//
// StellaX
// Jeff Miller 05/10/2000
//
#ifndef MAINDLG_H
#define MAINDLG_H
#pragma once
#include "resource.h"
#include "pch.hxx"
class CMainDlg;
class CListData
{
friend CMainDlg;
public:
CListData() :
m_fPopulated( FALSE )
{
}
DWORD Initialize()
{
//
// ListView control doesn't like NULLs returned, so initialize all
//
if ( ! m_strName.Set( _T("") ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! m_strManufacturer.Set( _T("") ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! m_strRarity.Set( _T("") ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! m_strFileName.Set( _T("") ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
if ( ! m_strNote.Set( _T("") ) )
{
return ERROR_NOT_ENOUGH_MEMORY;
}
return ERROR_SUCCESS;
}
static int GetColumnCount( void )
{
return 4;
}
enum ColumnIndex
{
FILENAME_COLUMN,
NAME_COLUMN,
MANUFACTURER_COLUMN,
RARITY_COLUMN,
};
static UINT GetColumnNameIdForColumn( int nCol )
{
UINT uID = 0;
switch ( nCol )
{
case NAME_COLUMN:
uID = IDS_NAME;
break;
case MANUFACTURER_COLUMN:
uID = IDS_MANUFACTURER;
break;
case RARITY_COLUMN:
uID = IDS_RARITY;
break;
case FILENAME_COLUMN:
uID = IDS_FILENAME;
break;
default:
ASSERT(FALSE);
break;
}
return uID;
}
LPCTSTR GetTextForColumn( int nCol ) const
{
LPCTSTR pszText = NULL;
switch (nCol)
{
case NAME_COLUMN:
pszText = m_strName.Get();
break;
case MANUFACTURER_COLUMN:
pszText = m_strManufacturer.Get();
break;
case RARITY_COLUMN:
pszText = m_strRarity.Get();
break;
case FILENAME_COLUMN:
pszText = m_strFileName.Get();
break;
default:
ASSERT( FALSE );
break;
}
return pszText;
}
LPCTSTR GetNote( void ) const
{
return m_strNote.Get();
}
BOOL IsPopulated( void ) const
{
return m_fPopulated;
}
CSimpleString m_strName;
CSimpleString m_strManufacturer;
CSimpleString m_strRarity;
CSimpleString m_strFileName;
CSimpleString m_strNote;
BOOL m_fPopulated;
private:
CListData( const CListData& ); // no implementation
void operator=( const CListData& ); // no implementation
};
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB