Added the ability to sort (in alphabetical order) by Name, Manufacturer

or Rarity columns in the game listview.  The currently selected sort column
is also saved, and then used when StellaX starts again.

The current width of columns is also saved, and reused when StellaX starts
again.

Still TODO is get the titlebar close button to 'hook' into the
MainDlg::Quit() method, so that it works the same way as pressing
the 'Exit' button or pressing 'Alt-F4'.  Right now, pressing the close
button in the titlebar bypasses the Quit() method, and AFAICT also
the freeing of any memory.  This bug seems to have been present in StellaX
since the beginning.


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@304 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2004-07-11 22:04:22 +00:00
parent eda901519b
commit 1a82add67b
5 changed files with 306 additions and 239 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: SettingsWin32.cxx,v 1.8 2004-07-05 00:53:48 stephena Exp $
// $Id: SettingsWin32.cxx,v 1.9 2004-07-11 22:04:21 stephena Exp $
//============================================================================
#include <sstream>
@ -62,6 +62,13 @@ SettingsWin32::SettingsWin32()
#ifdef SNAPSHOT_SUPPORT
set("ssdir", ".\\");
#endif
// These settings are for the StellaX frontend
// If you don't use StellaX, the following settings are ignored
set("sortcol", "0");
set("namecolwidth", "0");
set("manufacturercolwidth", "0");
set("raritycolwidth", "0");
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -2,199 +2,148 @@
// StellaX
// Jeff Miller 05/01/2000
//
#include "pch.hxx"
#include "HeaderCtrl.hxx"
CHeaderCtrl::CHeaderCtrl(
) : \
m_nSortCol(0),
m_fSortAsc(TRUE)
CHeaderCtrl::CHeaderCtrl()
: m_nSortCol(0),
m_fSortAsc(TRUE)
{
}
LRESULT CHeaderCtrl::WndProc(
HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam,
BOOL& rfHandled
)
LRESULT CHeaderCtrl::WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL& rfHandled )
{
switch ( msg )
{
case WM_DRAWITEM:
rfHandled = TRUE;
OnDrawItem(hWnd, (UINT)wParam, (LPDRAWITEMSTRUCT)lParam);
return TRUE;
}
switch ( msg )
{
case WM_DRAWITEM:
rfHandled = TRUE;
OnDrawItem(hWnd, (UINT)wParam, (LPDRAWITEMSTRUCT)lParam);
return TRUE;
}
return 0;
return 0;
}
void CHeaderCtrl::SetSortCol(
int nCol,
BOOL bAsc
)
void CHeaderCtrl::SetSortCol( int nCol, BOOL bAsc )
{
m_nSortCol = nCol;
m_fSortAsc = bAsc;
m_nSortCol = nCol;
m_fSortAsc = bAsc;
// change this item to owner draw
// change this item to owner draw
HWND hwndHeader = ::GetDlgItem( *this, 0 );
HDITEM hdi;
hdi.mask = HDI_FORMAT;
Header_GetItem(hwndHeader, nCol, &hdi);
hdi.fmt |= HDF_OWNERDRAW;
Header_SetItem(hwndHeader, nCol, &hdi);
HWND hwndHeader = ::GetDlgItem( *this, 0 );
HDITEM hdi;
hdi.mask = HDI_FORMAT;
Header_GetItem(hwndHeader, nCol, &hdi);
hdi.fmt |= HDF_OWNERDRAW;
Header_SetItem(hwndHeader, nCol, &hdi);
// repaint the header
::InvalidateRect(hwndHeader, NULL, TRUE);
// repaint the header
InvalidateRect(hwndHeader, NULL, TRUE);
}
void CHeaderCtrl::OnDrawItem(
HWND hwnd,
UINT idCtl,
LPDRAWITEMSTRUCT lpdis
)
void CHeaderCtrl::OnDrawItem( HWND hwnd, UINT idCtl, LPDRAWITEMSTRUCT lpdis )
{
UNUSED_ALWAYS( idCtl );
UNUSED_ALWAYS( idCtl );
HDC hdc = lpdis->hDC;
RECT rcLabel;
HDC hdc = lpdis->hDC;
CopyRect( &rcLabel, &(lpdis->rcItem) );
RECT rcLabel;
::CopyRect( &rcLabel, &(lpdis->rcItem) );
/* save the DC */
int nSavedDC = ::SaveDC( hdc );
/* save the DC */
/* set clip region to column */
HRGN hrgn = ::CreateRectRgnIndirect( &rcLabel );
SelectObject( hdc, hrgn );
DeleteObject( hrgn );
int nSavedDC = ::SaveDC( hdc );
/* draw the background */
FillRect( hdc, &rcLabel, ::GetSysColorBrush(COLOR_3DFACE) );
/* set clip region to column */
/* offset the label */
SIZE size;
GetTextExtentPoint32( hdc, _T(" "), 1, &size );
int nOffset = size.cx * 2;
HRGN hrgn = ::CreateRectRgnIndirect( &rcLabel );
SelectObject( hdc, hrgn );
DeleteObject( hrgn );
/* get the column text and format */
TCHAR tszText[255 + 1];
HDITEM hdi;
hdi.mask = HDI_TEXT | HDI_FORMAT;
hdi.pszText = tszText;
hdi.cchTextMax = 255;
Header_GetItem( GetDlgItem(hwnd, 0), lpdis->itemID, &hdi );
/* draw the background */
/* determine format for drawing label */
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS;
::FillRect( hdc, &rcLabel, ::GetSysColorBrush(COLOR_3DFACE) );
/* determine justification */
if (hdi.fmt & HDF_CENTER)
uFormat |= DT_CENTER;
else if (hdi.fmt & HDF_RIGHT)
uFormat |= DT_RIGHT;
else
uFormat |= DT_LEFT;
/* offset the label */
/* adjust the rect if selected */
if (lpdis->itemState & ODS_SELECTED)
{
rcLabel.left++;
rcLabel.top += 2;
rcLabel.right++;
}
SIZE size;
::GetTextExtentPoint32( hdc, _T(" "), 1, &size );
int nOffset = size.cx * 2;
/* adjust rect for sort arrow */
if ( lpdis->itemID == m_nSortCol )
rcLabel.right -= (3 * nOffset);
/* get the column text and format */
rcLabel.left += nOffset;
rcLabel.right -= nOffset;
TCHAR tszText[255 + 1];
HDITEM hdi;
hdi.mask = HDI_TEXT | HDI_FORMAT;
hdi.pszText = tszText;
hdi.cchTextMax = 255;
Header_GetItem( GetDlgItem(hwnd, 0), lpdis->itemID, &hdi );
/* draw label */
if ( rcLabel.left < rcLabel.right )
DrawText(hdc, tszText, -1, &rcLabel, uFormat );
/* determine format for drawing label */
/* draw the arrow */
if ( lpdis->itemID == m_nSortCol )
{
RECT rcIcon;
HPEN hpenLight, hpenShadow, hpenOld;
UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP |
DT_VCENTER | DT_END_ELLIPSIS;
CopyRect( &rcIcon, &(lpdis->rcItem) );
/* determine justification */
hpenLight = ::CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT) );
hpenShadow = ::CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW) );
hpenOld = (HPEN)::SelectObject( hdc, hpenLight );
if (hdi.fmt & HDF_CENTER)
if (m_fSortAsc)
{
uFormat |= DT_CENTER;
/* draw triangle pointing up */
MoveToEx( hdc, rcIcon.right - 2 * nOffset, nOffset - 1, NULL );
LineTo( hdc, rcIcon.right - 3 * nOffset / 2, rcIcon.bottom - nOffset );
LineTo( hdc, rcIcon.right - 5 * nOffset / 2 - 2, rcIcon.bottom - nOffset );
MoveToEx( hdc, rcIcon.right - 5 * nOffset / 2 - 1, rcIcon.bottom - nOffset, NULL );
SelectObject( hdc, hpenShadow );
LineTo( hdc, rcIcon.right - 2 * nOffset, nOffset - 2 );
}
else if (hdi.fmt & HDF_RIGHT)
else
{
uFormat |= DT_RIGHT;
}
else
{
uFormat |= DT_LEFT;
/* draw triangle pointing down */
MoveToEx( hdc, rcIcon.right - 3 * nOffset / 2, nOffset - 1, NULL );
LineTo( hdc, rcIcon.right - 2 * nOffset - 1, rcIcon.bottom - nOffset );
LineTo( hdc, rcIcon.right - 2 * nOffset - 1, rcIcon.bottom - nOffset );
MoveToEx( hdc, rcIcon.right - 2 * nOffset - 1, rcIcon.bottom - nOffset, NULL );
SelectObject( hdc, hpenShadow );
LineTo( hdc, rcIcon.right - 5 * nOffset / 2 - 1, nOffset - 1 );
LineTo( hdc, rcIcon.right - 3 * nOffset / 2, nOffset - 1 );
}
/* adjust the rect if selected */
SelectObject( hdc, hpenOld );
DeleteObject( hpenShadow );
DeleteObject( hpenLight );
}
if (lpdis->itemState & ODS_SELECTED)
{
rcLabel.left++;
rcLabel.top += 2;
rcLabel.right++;
}
/* adjust rect for sort arrow */
if ( lpdis->itemID == m_nSortCol )
{
rcLabel.right -= (3 * nOffset);
}
rcLabel.left += nOffset;
rcLabel.right -= nOffset;
/* draw label */
if ( rcLabel.left < rcLabel.right )
{
::DrawText(hdc, tszText, -1, &rcLabel, uFormat );
}
/* draw the arrow */
if ( lpdis->itemID == m_nSortCol )
{
RECT rcIcon;
HPEN hpenLight, hpenShadow, hpenOld;
::CopyRect( &rcIcon, &(lpdis->rcItem) );
hpenLight = ::CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT) );
hpenShadow = ::CreatePen( PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW) );
hpenOld = (HPEN)::SelectObject( hdc, hpenLight );
if (m_fSortAsc)
{
/* draw triangle pointing up */
::MoveToEx( hdc, rcIcon.right - 2 * nOffset, nOffset - 1, NULL );
::LineTo( hdc, rcIcon.right - 3 * nOffset / 2,
rcIcon.bottom - nOffset );
::LineTo( hdc, rcIcon.right - 5 * nOffset / 2 - 2,
rcIcon.bottom - nOffset );
::MoveToEx( hdc, rcIcon.right - 5 * nOffset / 2 - 1,
rcIcon.bottom - nOffset, NULL );
::SelectObject( hdc, hpenShadow );
::LineTo( hdc, rcIcon.right - 2 * nOffset, nOffset - 2 );
}
else
{
/* draw triangle pointing down */
::MoveToEx( hdc, rcIcon.right - 3 * nOffset / 2, nOffset - 1,
NULL );
::LineTo( hdc, rcIcon.right - 2 * nOffset - 1,
rcIcon.bottom - nOffset );
::LineTo( hdc, rcIcon.right - 2 * nOffset - 1,
rcIcon.bottom - nOffset );
::MoveToEx( hdc, rcIcon.right - 2 * nOffset - 1,
rcIcon.bottom - nOffset, NULL );
::SelectObject( hdc, hpenShadow );
::LineTo( hdc, rcIcon.right - 5 * nOffset / 2 - 1,
nOffset - 1 );
::LineTo( hdc, rcIcon.right - 3 * nOffset / 2,
nOffset - 1 );
}
::SelectObject( hdc, hpenOld );
::DeleteObject( hpenShadow );
::DeleteObject( hpenLight );
}
::RestoreDC( hdc, nSavedDC );
RestoreDC( hdc, nSavedDC );
}

View File

@ -4,51 +4,39 @@
//
#ifndef HDRCTL_H
#define HDRCTL_H
#pragma once
#include "Wnd.hxx"
class CHeaderCtrl : public CWnd
{
public:
public:
CHeaderCtrl();
CHeaderCtrl();
void SetSortCol(int col, BOOL fAscending);
int GetSortCol(void) const;
BOOL GetSortAsc(void) const;
void SetSortCol(int nCol, BOOL fAscending);
int GetSortCol(void) const;
BOOL GetSortAsc(void) const;
protected:
LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL& rfHandled);
protected:
private:
void OnDrawItem(HWND hwnd, UINT idCtl, LPDRAWITEMSTRUCT lpdis);
LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
BOOL& rfHandled);
private:
void OnDrawItem(HWND hwnd, UINT idCtl, LPDRAWITEMSTRUCT lpdis);
UINT m_nSortCol;
BOOL m_fSortAsc;
CHeaderCtrl( const CHeaderCtrl& ); // no implementation
void operator=( const CHeaderCtrl& ); // no implementation
UINT m_nSortCol;
BOOL m_fSortAsc;
CHeaderCtrl( const CHeaderCtrl& ); // no implementation
void operator=( const CHeaderCtrl& ); // no implementation
};
inline int CHeaderCtrl::GetSortCol
(
void
) const
inline int CHeaderCtrl::GetSortCol( void ) const
{
return m_nSortCol;
return m_nSortCol;
}
inline BOOL CHeaderCtrl::GetSortAsc
(
void
) const
inline BOOL CHeaderCtrl::GetSortAsc( void ) const
{
return m_fSortAsc;
return m_fSortAsc;
}
#endif

View File

@ -14,7 +14,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: MainDlg.cxx,v 1.4 2004-07-10 22:25:58 stephena Exp $
// $Id: MainDlg.cxx,v 1.5 2004-07-11 22:04:22 stephena Exp $
//============================================================================
#include "pch.hxx"
@ -35,14 +35,21 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MainDlg::MainDlg( CGlobalData& rGlobalData, HINSTANCE hInstance )
: myGlobalData(rGlobalData),
m_hInstance(hInstance)
myHInstance(hInstance)
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MainDlg::~MainDlg( void )
{
// Just to be safe, make sure we don't have a memory leak
ListView_Clear();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int MainDlg::DoModal( HWND hwndParent )
{
return DialogBoxParam( m_hInstance,
return DialogBoxParam( myHInstance,
MAKEINTRESOURCE(IDD),
hwndParent,
StaticDialogFunc,
@ -138,7 +145,7 @@ MainDlg::DialogFunc( UINT uMsg, WPARAM wParam, LPARAM lParam )
case WM_SYSCOMMAND:
// Allow Alt-F4 to close the window
if ( wParam == SC_CLOSE )
::EndDialog( myHwnd, IDCANCEL );
Quit(myHwnd);
break;
}
@ -154,7 +161,7 @@ BOOL MainDlg::OnInitDialog( void )
HWND hwnd = *this;
// Set dialog icon
HICON hicon = ::LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_APP));
HICON hicon = ::LoadIcon(myHInstance, MAKEINTRESOURCE(IDI_APP));
::SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)hicon );
::SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hicon );
@ -199,16 +206,24 @@ BOOL MainDlg::OnInitDialog( void )
int columnHeader[] = { IDS_NAME, IDS_MANUFACTURER, IDS_RARITY };
// Set the column widths
LONG lTotalWidth = rc.right-rc.left - GetSystemMetrics(SM_CXVSCROLL);
int columnWidth[3];
columnWidth[0] = (int) (0.58 * lTotalWidth);
columnWidth[1] = (int) (0.25 * lTotalWidth);
columnWidth[2] = lTotalWidth - columnWidth[0] - columnWidth[1];
columnWidth[0] = myGlobalData.settings().getInt("namecolwidth");
columnWidth[1] = myGlobalData.settings().getInt("manufacturercolwidth");
columnWidth[2] = myGlobalData.settings().getInt("raritycolwidth");
// Make sure there are sane values for the column widths
if (columnWidth[0] <= 0 || columnWidth[1] <= 0 || columnWidth[2] <= 0)
{
LONG lTotalWidth = rc.right-rc.left - GetSystemMetrics(SM_CXVSCROLL);
columnWidth[0] = (int) (0.58 * lTotalWidth);
columnWidth[1] = (int) (0.25 * lTotalWidth);
columnWidth[2] = lTotalWidth - columnWidth[0] - columnWidth[1];
}
// Set up the column headings
for (int i = 0; i < sizeof(columnHeader)/sizeof(int); ++i)
for (int i = 0; i < 3; ++i)
{
LoadString( m_hInstance, columnHeader[i], psz, nMaxString );
LoadString( myHInstance, columnHeader[i], psz, nMaxString );
LV_COLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
@ -222,7 +237,7 @@ BOOL MainDlg::OnInitDialog( void )
UpdateRomList();
// Set default button
::SendMessage( hwnd, DM_SETDEFID, IDC_PLAY, 0 );
SendMessage( hwnd, DM_SETDEFID, IDC_PLAY, 0 );
// return FALSE if SetFocus is called
return TRUE;
@ -247,7 +262,7 @@ BOOL MainDlg::OnCommand( int id, HWND hwndCtl, UINT codeNotify )
ASSERT( nItem != -1 );
if ( nItem == -1 )
{
MessageBox( m_hInstance, hwnd, IDS_NO_ITEM_SELECTED );
MessageBox( myHInstance, hwnd, IDS_NO_ITEM_SELECTED );
return TRUE;
}
@ -262,8 +277,7 @@ BOOL MainDlg::OnCommand( int id, HWND hwndCtl, UINT codeNotify )
break; // case IDC_PLAY
case IDC_EXIT:
ListView_Clear();
EndDialog( hwnd, IDCANCEL );
Quit(hwnd);
return TRUE;
break; // case IDC_EXIT
@ -295,7 +309,7 @@ BOOL MainDlg::OnCommand( int id, HWND hwndCtl, UINT codeNotify )
case IDC_RELOAD:
{
LoadRomListFromDisk();
ListView_SortByColumn( myHwndList, myGlobalData.settings().getInt("sortcol") );
return TRUE;
break; // case IDC_RELOAD
}
@ -315,13 +329,13 @@ BOOL MainDlg::OnNotify( int idCtrl, LPNMHDR pnmh )
OnItemChanged( (LPNMLISTVIEW)pnmh );
return TRUE;
// case LVN_COLUMNCLICK:
// OnColumnClick( (LPNMLISTVIEW)pnmh );
// return TRUE;
case LVN_COLUMNCLICK:
OnColumnClick( (LPNMLISTVIEW)pnmh );
return TRUE;
case NM_DBLCLK:
// send out an ok click to play
::SendDlgItemMessage( *this, IDC_PLAY, BM_CLICK, 0, 0 );
SendDlgItemMessage( *this, IDC_PLAY, BM_CLICK, 0, 0 );
return TRUE;
}
@ -356,6 +370,12 @@ void MainDlg::OnItemChanged( LPNMLISTVIEW pnmv )
EnableWindow( GetDlgItem( hwnd, IDC_PLAY ), TRUE );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MainDlg::OnColumnClick( LPNMLISTVIEW pnmv )
{
ListView_SortByColumn( pnmv->hdr.hwndFrom, pnmv->iSubItem );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
static void ScreenToClient( HWND hwnd, LPRECT lpRect )
{
@ -393,7 +413,7 @@ BOOL MainDlg::OnEraseBkgnd( HDC hdc )
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmpTile = LoadBitmap( m_hInstance, MAKEINTRESOURCE(IDB_TILE) );
HBITMAP hbmpTile = LoadBitmap( myHInstance, MAKEINTRESOURCE(IDB_TILE) );
BITMAP bm;
GetObject(hbmpTile, sizeof(bm), &bm);
@ -436,6 +456,31 @@ HBRUSH MainDlg::OnCtlColorStatic( HDC hdcStatic, HWND hwndStatic )
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MainDlg::Quit( HWND hwnd )
{
// OK, reload the settings to make sure we have the most current ones
myGlobalData.settings().loadConfig();
// Save the current sort column
int sortcol = myHeader.GetSortCol();
myGlobalData.settings().setInt("sortcol", sortcol);
// Save the column widths
myGlobalData.settings().setInt("namecolwidth",
ListView_GetColWidth( hwnd, 0 ));
myGlobalData.settings().setInt("manufacturercolwidth",
ListView_GetColWidth( hwnd, 1 ));
myGlobalData.settings().setInt("raritycolwidth",
ListView_GetColWidth( hwnd, 2 ));
// Now, save the settings
myGlobalData.settings().saveConfig();
ListView_Clear();
EndDialog( hwnd, IDCANCEL );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MainDlg::UpdateRomList( void )
{
@ -447,22 +492,13 @@ void MainDlg::UpdateRomList( void )
// if items added, select first item and enable play button
int nCount = ListView_GetItemCount( myHwndList );
if (nCount != 0)
{
myHeader.SetSortCol( 0, TRUE );
// ListView_SortItems( myHwndList, ListViewCompareFunc, (LPARAM)this );
ListView_SetItemState( myHwndList, 0, LVIS_SELECTED | LVIS_FOCUSED,
LVIS_SELECTED | LVIS_FOCUSED );
}
else
{
::EnableWindow(::GetDlgItem( *this, IDC_PLAY), FALSE );
}
if (nCount == 0)
EnableWindow(GetDlgItem( *this, IDC_PLAY), FALSE );
// Show status text
TCHAR psz[256 + 1];
TCHAR pszStatus[256 + 1];
LoadString(m_hInstance, IDS_STATUSTEXT, pszStatus, 256);
LoadString(myHInstance, IDS_STATUSTEXT, pszStatus, 256);
wsprintf( psz, pszStatus, nCount );
hwndText = GetDlgItem( *this, IDC_ROMCOUNT );
GetWindowRect(hwndText, &rc);
@ -492,6 +528,7 @@ bool MainDlg::PopulateRomList( void )
else
result = LoadRomListFromDisk();
ListView_SortByColumn( myHwndList, myGlobalData.settings().getInt("sortcol") );
return result;
}
@ -594,7 +631,10 @@ bool MainDlg::LoadRomListFromDisk()
strncpy(name, g->name().c_str(), 255);
// Update the current game
// To save memory, 'Note' is the only item that needs to be saved
g->setMd5( md5 );
g->setName( name );
g->setRarity( rarity );
g->setManufacturer( manufacturer );
g->setNote( props.get("Cartridge.Note") );
// Update the cachefile with this game
@ -648,9 +688,13 @@ bool MainDlg::LoadRomListFromCache()
in.getline(manufacturer, 255);
in.getline(note, 255);
// These are the only things we really need to save
// And save it to this game object
g->setAvailable( true );
g->setRom( rom );
g->setMd5( md5 );
g->setName( name );
g->setRarity( rarity );
g->setManufacturer( manufacturer );
g->setNote( note );
LV_ITEM lvi;
@ -725,6 +769,42 @@ LPARAM MainDlg::ListView_GetItemData( HWND hwndList, int iItem )
return lvi.lParam;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MainDlg::ListView_SortByColumn( HWND hwndList, int col )
{
HCURSOR hcur = SetCursor(LoadCursor(NULL, IDC_WAIT));
int nCount = ListView_GetItemCount( hwndList );
if (nCount != 0)
{
myHeader.SetSortCol( col, TRUE );
ListView_SortItems( hwndList, ListViewCompareFunc, (LPARAM)this );
ListView_SetItemState( hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED,
LVIS_SELECTED | LVIS_FOCUSED );
}
// ensure the selected item is visible
int nItem = ListView_GetNextItem( myHwndList, -1, LVNI_SELECTED );
if (nItem != -1)
ListView_EnsureVisible( myHwndList, nItem, TRUE );
SetCursor(hcur);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int MainDlg::ListView_GetColWidth( HWND hwndList, int col )
{
// Although there seems to be a similar function in the Win32 API
// to do this, I couldn't get it to work, so it's quicker to
// write this one and use it ...
LV_COLUMN lvc;
lvc.mask = LVCF_WIDTH;
if (ListView_GetColumn( myHwndList, col, &lvc ) == TRUE)
return lvc.cx;
else
return 0; // the next time StellaX starts, it will recreate a sane value
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MainDlg::ListView_Clear( void )
{
@ -735,3 +815,41 @@ void MainDlg::ListView_Clear( void )
ListView_DeleteAllItems( myHwndList );
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int CALLBACK
MainDlg::ListViewCompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort )
{
MainDlg* dlg = reinterpret_cast<MainDlg*>( lParamSort );
int sortCol = dlg->myHeader.GetSortCol();
Game* g1 = reinterpret_cast<Game*>( lParam1 );
Game* g2 = reinterpret_cast<Game*>( lParam2 );
string s1 = "", s2 = "";
switch (sortCol)
{
case 0:
s1 = g1->name();
s2 = g2->name();
break;
case 1:
s1 = g1->manufacturer();
s2 = g2->manufacturer();
break;
case 2:
s1 = g1->rarity();
s2 = g2->rarity();
break;
}
if (s1 > s2)
return 1;
else if (s1 < s2)
return -1;
else
return 0;
}

View File

@ -14,7 +14,7 @@
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: MainDlg.hxx,v 1.3 2004-07-10 22:25:58 stephena Exp $
// $Id: MainDlg.hxx,v 1.4 2004-07-11 22:04:22 stephena Exp $
//============================================================================
#ifndef __MAINDLG_H_
@ -37,6 +37,7 @@ class MainDlg
enum { IDD = IDD_MAIN };
MainDlg( CGlobalData& rGlobalData, HINSTANCE hInstance );
virtual ~MainDlg( void );
virtual int DoModal( HWND hwndParent );
@ -63,7 +64,7 @@ class MainDlg
// wm_notify handlers
void OnItemChanged( LPNMLISTVIEW pnmv );
// void OnColumnClick( LPNMLISTVIEW pnmv );
void OnColumnClick( LPNMLISTVIEW pnmv );
// cool caption handlers
void OnDestroy( void );
@ -74,6 +75,7 @@ class MainDlg
// callback methods
BOOL CALLBACK DialogFunc( UINT uMsg, WPARAM wParam, LPARAM lParam );
static BOOL CALLBACK StaticDialogFunc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
static int CALLBACK ListViewCompareFunc( LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort );
// internal data
void UpdateRomList();
@ -81,11 +83,14 @@ class MainDlg
bool LoadRomListFromDisk();
bool LoadRomListFromCache();
HINSTANCE m_hInstance;
void Quit( HWND hwnd );
HINSTANCE myHInstance;
// stuff in list
HWND myHwndList;
LPARAM ListView_GetItemData( HWND hwndList, int iItem );
void ListView_SortByColumn( HWND hwndList, int col );
int ListView_GetColWidth( HWND hwndList, int col );
void ListView_Clear();
HFONT m_hfontRomNote;