1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
|
/* browse.c: tape browser dialog box
Copyright (c) 2002-2008 Philip Kendall, Marek Januszewski
$Id: browse.c 3768 2008-09-07 01:33:19Z specu $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <libspectrum.h>
#include <tchar.h>
#include <windows.h>
#include "fuse.h"
#include "tape.h"
#include "ui/ui.h"
#include "win32internals.h"
#include "browse.h"
static INT_PTR CALLBACK dialog_proc( HWND hwndDlg, UINT uMsg,
WPARAM wParam, LPARAM lParam );
static void add_block_details( libspectrum_tape_block *block, void *user_data );
static void select_row( LPNMITEMACTIVATE lpnmitem );
static HWND dialog; /* The dialog box itself */
static int dialog_created; /* Have we created the dialog box yet? */
void
menu_media_tape_browse( int action )
{
/* Firstly, stop emulation */
fuse_emulation_pause();
if( !dialog_created ) {
dialog = CreateDialog( fuse_hInstance, MAKEINTRESOURCE( IDD_BROWSE ),
fuse_hWnd, dialog_proc );
if( dialog == NULL ) { fuse_emulation_unpause(); return; }
}
if( ui_tape_browser_update( UI_TAPE_BROWSER_NEW_TAPE, NULL ) ) {
fuse_emulation_unpause();
return;
}
ShowWindow( dialog, SW_SHOW );
/* Carry on with emulation */
fuse_emulation_unpause();
}
static void
dialog_init( HWND hwndDlg )
{
size_t i;
TCHAR *titles[3] = { "", "Block type", "Data" };
int titles_widths[3] = { 16, 115, 150 };
/* set extended listview style to select full row, when an item is selected */
DWORD lv_ext_style;
lv_ext_style = SendDlgItemMessage( hwndDlg, IDC_BROWSE_LV,
LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 );
lv_ext_style |= LVS_EX_FULLROWSELECT;
SendDlgItemMessage( hwndDlg, IDC_BROWSE_LV,
LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lv_ext_style );
/* Create columns in the listview */
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;
lvc.fmt = LVCFMT_LEFT;
for( i = 0; i < 3; i++ ) {
if( i != 0 )
lvc.mask |= LVCF_SUBITEM;
lvc.cx = titles_widths[i];
lvc.pszText = titles[i];
SendDlgItemMessage( hwndDlg, IDC_BROWSE_LV, LVM_INSERTCOLUMN, i,
( LPARAM ) &lvc );
}
/* create image list for the listview */
HBITMAP icon_tape_marker, icon_tape_marker_mask;
BITMAP bmp;
HIMAGELIST himl;
/* FIXME: need to destroy those objects later */
icon_tape_marker = LoadImage( fuse_hInstance, "win32bmp_tape_marker",
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
icon_tape_marker_mask = LoadImage( fuse_hInstance, "win32bmp_tape_marker_mask",
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
GetObject( icon_tape_marker, sizeof( bmp ), &bmp );
/* FIXME: destroy the list later */
himl = ImageList_Create( bmp.bmWidth, bmp.bmHeight,
ILC_COLOR | ILC_MASK, 1, 0 );
ImageList_Add( himl, icon_tape_marker, icon_tape_marker_mask );
SendDlgItemMessage( hwndDlg, IDC_BROWSE_LV, LVM_SETIMAGELIST,
LVSIL_SMALL, ( LPARAM ) himl );
dialog_created = 1;
}
static INT_PTR CALLBACK
dialog_proc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
/* FIXME: implement resizing the dialog */
switch( uMsg ) {
case WM_INITDIALOG:
dialog_init( hwndDlg );
return FALSE;
case WM_NOTIFY:
if( ( ( LPNMHDR ) lParam )->code == NM_DBLCLK ) {
if( ( ( LPNMHDR ) lParam )->idFrom == IDC_BROWSE_LV ) {
select_row( ( LPNMITEMACTIVATE ) lParam );
return 0;
}
}
break;
case WM_COMMAND:
if( LOWORD( wParam ) == IDCLOSE ) {
ShowWindow( dialog, SW_HIDE );
return 0;
}
break;
case WM_CLOSE:
/* Catch attempts to delete the window and just hide it instead */
ShowWindow( dialog, SW_HIDE );
return 0;
}
return FALSE;
}
int
ui_tape_browser_update( ui_tape_browser_update_type change GCC_UNUSED,
libspectrum_tape_block *block GCC_UNUSED )
{
int error, current_block;
if( !dialog_created ) return 0;
fuse_emulation_pause();
SendDlgItemMessage( dialog, IDC_BROWSE_LV, LVM_DELETEALLITEMS, 0, 0 );
error = tape_foreach( add_block_details, NULL );
if( error ) {
fuse_emulation_unpause();
return 1;
}
current_block = tape_get_current_block();
if( current_block != -1 ) {
LVITEM li;
li.mask = LVIF_IMAGE;
li.iItem = current_block;
li.iSubItem = 0;
li.iImage = 0;
SendDlgItemMessage( dialog, IDC_BROWSE_LV, LVM_SETITEM, 0, ( LPARAM ) &li );
}
if( tape_modified ) {
SendDlgItemMessage( dialog, IDC_BROWSE_MODIFIED, WM_SETTEXT,
0, ( LPARAM ) TEXT( "Tape modified" ) );
} else {
SendDlgItemMessage( dialog, IDC_BROWSE_MODIFIED, WM_SETTEXT,
0, ( LPARAM ) TEXT( "Tape not modified" ) );
}
fuse_emulation_unpause();
return 0;
}
static void
add_block_details( libspectrum_tape_block *block, void *user_data )
{
TCHAR buffer[256];
TCHAR *details[3] = { &buffer[0], &buffer[80], &buffer[160] };
LV_ITEM lvi;
size_t i;
_tcscpy( details[0], "" );
libspectrum_tape_block_description( details[1], 80, block );
/* FIXME: why does it give such a big number of bytes? */
tape_block_details( details[2], 80, block );
lvi.mask = LVIF_TEXT | LVIF_IMAGE;
lvi.iImage = -1;
lvi.iItem = SendDlgItemMessage( dialog, IDC_BROWSE_LV,
LVM_GETITEMCOUNT, 0, 0 );
for( i = 0; i < 3; i++ ) {
lvi.iSubItem = i;
lvi.pszText = details[i];
if( i == 0 )
SendDlgItemMessage( dialog, IDC_BROWSE_LV, LVM_INSERTITEM, 0,
( LPARAM ) &lvi );
else
SendDlgItemMessage( dialog, IDC_BROWSE_LV, LVM_SETITEM, 0,
( LPARAM ) &lvi );
}
}
/* Called when a row is selected */
static void
select_row( LPNMITEMACTIVATE lpnmitem )
{
int current_block, row;
row = lpnmitem->iItem;
/* Don't do anything if the current block was clicked on */
current_block = tape_get_current_block();
if( row == current_block ) return;
/* Otherwise, select the new block */
tape_select_block_no_update( row );
/* set the marker at the current item, clear others */
size_t i, count;
count = SendDlgItemMessage( dialog, IDC_BROWSE_LV,
LVM_GETITEMCOUNT, 0, 0 );
LVITEM li;
li.mask = LVIF_IMAGE;
li.iSubItem = 0;
for( i=0; i<count; i++ ) {
li.iImage = ( i==row ? 0 : -1 );
li.iItem = i;
SendDlgItemMessage( dialog, IDC_BROWSE_LV, LVM_SETITEM, 0, ( LPARAM ) &li );
}
}
|