Advertisement
sbaldovi

fuse_memorybrowser.diff

Feb 12th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 13.51 KB | None | 0 0
  1. Index: ui/gtk/memory.c
  2. ===================================================================
  3. --- ui/gtk/memory.c (revision 4664)
  4. +++ ui/gtk/memory.c (working copy)
  5. @@ -32,10 +32,13 @@
  6.  #include <gtk/gtk.h>
  7.  
  8.  #include "compat.h"
  9. +#include "fuse.h"
  10.  #include "gtkinternals.h"
  11.  #include "memory.h"
  12.  #include "menu.h"
  13.  
  14. +static libspectrum_word memaddr = 0x0000;
  15. +
  16.  static void
  17.  update_display( GtkCList *clist, libspectrum_word base )
  18.  {
  19. @@ -45,6 +48,7 @@
  20.    gchar *text[] = { &buffer[0], &buffer[ 8 ], &buffer[ 8 + 64 ] };
  21.    char buffer2[ 8 ];
  22.  
  23. +  memaddr = base;
  24.    gtk_clist_freeze( clist );
  25.    gtk_clist_clear( clist );
  26.  
  27. @@ -91,6 +95,7 @@
  28.    int error;
  29.    gtkui_font font;
  30.  
  31. +  fuse_emulation_pause();
  32.    gchar *titles[] = { "Address", "Hex", "Data" };
  33.  
  34.    error = gtkui_get_monospaced_font( &font ); if( error ) return;
  35. @@ -107,10 +112,10 @@
  36.    for( i = 0; i < 3; i++ )
  37.      gtk_clist_set_column_auto_resize( GTK_CLIST( clist ), i, TRUE );
  38.    gtkui_set_font( clist, font );
  39. -  update_display( GTK_CLIST( clist ), 0x0000 );
  40. +  update_display( GTK_CLIST( clist ), memaddr );
  41.    gtk_box_pack_start_defaults( GTK_BOX( box ), clist );
  42.  
  43. -  adjustment = gtk_adjustment_new( 0, 0x0000, 0xffff, 0x10, 0xa0, 0x13f );
  44. +  adjustment = gtk_adjustment_new( memaddr, 0x0000, 0xffff, 0x10, 0xa0, 0x13f );
  45.    gtk_signal_connect( adjustment, "value-changed", GTK_SIGNAL_FUNC( scroller ),
  46.               clist );
  47.  
  48. @@ -123,6 +128,7 @@
  49.    gtk_main();
  50.  
  51.    gtkui_free_font( font );
  52. +  fuse_emulation_unpause();
  53.  
  54.    return;
  55.  }
  56. Index: ui/win32/memorybrowser.c
  57. ===================================================================
  58. --- ui/win32/memorybrowser.c    (revision 4664)
  59. +++ ui/win32/memorybrowser.c    (working copy)
  60. @@ -27,7 +27,10 @@
  61.  
  62.  #include <libspectrum.h>
  63.  #include <tchar.h>
  64. +#include <windows.h>
  65.  
  66. +#include "compat.h"
  67. +#include "fuse.h"
  68.  #include "memory.h"
  69.  #include "win32internals.h"
  70.  
  71. @@ -36,35 +39,49 @@
  72.  static INT_PTR CALLBACK
  73.  memorybrowser_proc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  74.  
  75. +static LRESULT CALLBACK
  76. +memory_listview_proc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
  77. +
  78.  static void
  79.  memorybrowser_init( HWND hwndDlg );
  80.  
  81. +void
  82. +menu_machine_memorybrowser( int action );
  83. +
  84.  /* helper constants for memory listview's scrollbar */
  85.  static const int memorysb_min = 0x0000;
  86. -static const int memorysb_max = 0xffff;
  87. +static const int memorysb_max = 0x10000;
  88.  static const int memorysb_step = 0x10;
  89. -static const int memorysb_page_inc = 0xa0;
  90. -static const int memorysb_page_size = 0x13f;
  91.  
  92. +/* Visual styles could change visible rows */
  93. +static int memorysb_page_inc = 0xa0;
  94. +static int memorysb_page_size = 0x140;
  95. +static int memorysb_page_rows = 20;
  96. +
  97. +/* Address of first visible row */
  98. +static libspectrum_word memaddr = 0x0000;
  99. +
  100.  static void
  101.  update_display( HWND hwndDlg, libspectrum_word base )
  102.  {
  103. -  size_t i, j;
  104. +  int i, j;
  105.  
  106.    TCHAR buffer[ 8 + 64 + 20 ];
  107.    TCHAR *text[] = { &buffer[0], &buffer[ 8 ], &buffer[ 8 + 64 ] };
  108.    TCHAR buffer2[ 8 ];
  109.  
  110. +  memaddr = base;
  111. +
  112.    SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_DELETEALLITEMS, 0, 0 );
  113.  
  114.    LV_ITEM lvi;
  115.    lvi.mask = LVIF_TEXT;
  116.  
  117. -  for( i = 0; i < 20; i++ ) {
  118. +  for( i = 0; i < memorysb_page_rows; i++ ) {
  119.      _sntprintf( text[0], 8, TEXT( "%04X" ), base );
  120.  
  121.      text[1][0] = '\0';
  122. -    for( j = 0; j < 0x10; j++, base++ ) {
  123. +    for( j = 0; j < memorysb_step; j++, base++ ) {
  124.  
  125.        libspectrum_byte b = readbyte_internal( base );
  126.  
  127. @@ -99,22 +116,26 @@
  128.    libspectrum_word base;
  129.    SCROLLINFO si;
  130.  
  131. +  memset( &si, 0, sizeof( si ) );
  132.    si.cbSize = sizeof(si);
  133.    si.fMask = SIF_POS;
  134.    GetScrollInfo( GetDlgItem( hwndDlg, IDC_MEM_SB ), SB_CTL, &si );
  135.  
  136.    int value = si.nPos;
  137. +  int selected = 0;
  138.    
  139.    /* in Windows we have to read the command and scroll the scrollbar manually */
  140.    switch( LOWORD( scroll_command ) ) {
  141.      case SB_BOTTOM:
  142.        value = memorysb_max;
  143. +      selected = memorysb_page_rows - 1;
  144.        break;
  145.      case SB_TOP:
  146.        value = memorysb_min;
  147.        break;
  148.      case SB_LINEDOWN:
  149.        value += memorysb_step;
  150. +      selected = 1;
  151.        break;
  152.      case SB_LINEUP:
  153.        value -= memorysb_step;
  154. @@ -124,6 +145,7 @@
  155.        break;
  156.      case SB_PAGEDOWN:
  157.        value += memorysb_page_inc;
  158. +      selected = memorysb_page_rows - 1;
  159.        break;
  160.      case SB_THUMBPOSITION:
  161.      case SB_THUMBTRACK:
  162. @@ -132,34 +154,47 @@
  163.      default:
  164.        return 1;
  165.    }
  166. -  if( value > memorysb_max ) value = memorysb_max;
  167. +
  168. +  if( value > memorysb_max - memorysb_page_size )
  169. +    value = memorysb_max - memorysb_page_size;
  170.    if( value < memorysb_min ) value = memorysb_min;
  171.  
  172.    /* Drop the low bits before displaying anything */
  173.    base = value; base &= 0xfff0;
  174.  
  175. -  /* set the new scrollbar position */
  176. -  memset( &si, 0, sizeof(si) );
  177. -  si.cbSize = sizeof(si);
  178. -  si.fMask = SIF_POS;
  179. -  si.nPos = base;
  180. -  SetScrollInfo( GetDlgItem( hwndDlg, IDC_MEM_SB ), SB_CTL, &si, TRUE );
  181. -  
  182. -  update_display( hwndDlg, base );
  183. -  
  184. +  if( base != memaddr ) {
  185. +    /* set the new scrollbar position */
  186. +    memset( &si, 0, sizeof(si) );
  187. +    si.cbSize = sizeof(si);
  188. +    si.fMask = SIF_POS;
  189. +    si.nPos = base;
  190. +    SetScrollInfo( GetDlgItem( hwndDlg, IDC_MEM_SB ), SB_CTL, &si, TRUE );
  191. +
  192. +    update_display( hwndDlg, base );
  193. +  }
  194. +
  195. +  /* Select row according to last scroll command */
  196. +  ListView_SetItemState( GetDlgItem( hwndDlg, IDC_MEM_LV ), selected,
  197. +                         LVIS_SELECTED, LVIS_SELECTED );
  198. +
  199.    return 0;
  200.  }
  201.  
  202.  void
  203. -menu_machine_memorybrowser()
  204. +menu_machine_memorybrowser( int action GCC_UNUSED )
  205.  {
  206. +  fuse_emulation_pause();
  207. +
  208.    DialogBox( fuse_hInstance, MAKEINTRESOURCE( IDD_MEM ),
  209.               fuse_hWnd, (DLGPROC) memorybrowser_proc );
  210. +
  211. +  fuse_emulation_unpause();
  212.    return;
  213.  }
  214.  
  215.  static INT_PTR CALLBACK
  216. -memorybrowser_proc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  217. +memorybrowser_proc( HWND hwndDlg, UINT uMsg, WPARAM wParam,
  218. +                    LPARAM lParam GCC_UNUSED )
  219.  {
  220.    switch( uMsg )
  221.    {
  222. @@ -168,33 +203,113 @@
  223.        return TRUE;
  224.  
  225.      case WM_COMMAND:
  226. -      if( LOWORD( wParam ) == IDCLOSE ) {
  227. +      if( LOWORD( wParam ) == IDCLOSE ||
  228. +          LOWORD( wParam ) == IDCANCEL ) {
  229.          EndDialog( hwndDlg, 0 );
  230. -        return 0;
  231. +        return TRUE;
  232.        }
  233.        break;
  234.  
  235.      case WM_CLOSE: {
  236.        EndDialog( hwndDlg, 0 );
  237. -      return 0;
  238. +      return TRUE;
  239.      }
  240.  
  241.      case WM_VSCROLL:
  242. -      if( ( HWND ) lParam != NULL ) {
  243. -        if( ! scroller( hwndDlg, wParam ) )
  244. -          return 0;
  245. +      /* Accept vertical scroll from listview too */
  246. +      scroller( hwndDlg, wParam );
  247. +      return TRUE;
  248. +  
  249. +    case WM_MOUSEWHEEL:
  250. +    {
  251. +      /* get current position */
  252. +      SCROLLINFO si;
  253. +      memset( &si, 0, sizeof(si) );
  254. +      si.cbSize = sizeof(si);
  255. +      si.fMask = SIF_POS;
  256. +      GetScrollInfo( GetDlgItem( hwndDlg, IDC_MEM_SB ), SB_CTL, &si );
  257. +
  258. +      /* convert delta displacement to memory displacement */
  259. +      short delta = (short) HIWORD( wParam ) / WHEEL_DELTA;
  260. +      int value = si.nPos - delta * memorysb_step;
  261. +      if( value > memorysb_max - memorysb_page_size )
  262. +        value = memorysb_max - memorysb_page_size;
  263. +      if( value < memorysb_min ) value = memorysb_min;
  264. +
  265. +      /* scroll to new position */
  266. +      scroller( hwndDlg, MAKEWPARAM( SB_THUMBPOSITION, value ) );
  267. +      return TRUE;
  268. +    }
  269. +  }
  270. +
  271. +  return FALSE;
  272. +}
  273. +
  274. +static LRESULT CALLBACK
  275. +memory_listview_proc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
  276. +{
  277. +  switch( msg ) {
  278. +
  279. +    case WM_DESTROY:
  280. +    {
  281. +      WNDPROC orig_proc = (WNDPROC) GetProp( hWnd, "original_proc" );
  282. +      SetWindowLongPtr( hWnd, GWL_WNDPROC, (LONG) orig_proc );
  283. +      RemoveProp( hWnd, "original_proc" );
  284. +      break;
  285. +    }
  286. +
  287. +    case WM_KEYDOWN:
  288. +    {    
  289. +      WORD scroll_notify = 0xffff;
  290. +
  291. +      switch( wParam )
  292. +      {
  293. +        case VK_UP:
  294. +            scroll_notify = SB_LINEUP;
  295. +            break;
  296. +
  297. +        case VK_PRIOR:
  298. +            scroll_notify = SB_PAGEUP;
  299. +            break;
  300. +
  301. +        case VK_NEXT:
  302. +            scroll_notify = SB_PAGEDOWN;
  303. +            break;
  304. +
  305. +        case VK_DOWN:
  306. +            scroll_notify = SB_LINEDOWN;
  307. +            break;
  308. +
  309. +        case VK_HOME:
  310. +            scroll_notify = SB_TOP;
  311. +            break;
  312. +
  313. +        case VK_END:
  314. +            scroll_notify = SB_BOTTOM;
  315. +            break;
  316.        }
  317. +
  318. +      /* Inform parent window about key scrolling */
  319. +      if( scroll_notify != 0xffff ) {
  320. +        SendMessage( GetParent( hWnd ), WM_VSCROLL,
  321. +                     MAKEWPARAM( scroll_notify, 0 ), (LPARAM) NULL );
  322. +        return 0;
  323. +      }
  324. +
  325.        break;
  326. -      
  327. +    }
  328. +
  329.      case WM_MOUSEWHEEL:
  330. -/* FIXME: when one of the lines in the listview is selected,
  331. -          mouse wheel doesn't work */      
  332. -      scroller( hwndDlg, MAKEWPARAM(
  333. -                ( ( short ) HIWORD( wParam ) < 0 ) ? SB_LINEDOWN : SB_LINEUP,
  334. -                0 ) );
  335. +    {
  336. +      /* Inform parent window about mouse scrolling */
  337. +      SendMessage( GetParent( hWnd ), WM_MOUSEWHEEL, wParam, lParam );
  338.        return 0;
  339. +    }
  340. +
  341.    }
  342. -  return FALSE;
  343. +
  344. +  WNDPROC orig_proc = (WNDPROC) GetProp( hWnd, "original_proc" );
  345. +  return CallWindowProc( orig_proc, hWnd, msg, wParam, lParam );
  346.  }
  347.  
  348.  static void
  349. @@ -204,16 +319,24 @@
  350.    int error;
  351.    HFONT font;
  352.  
  353. -  TCHAR *titles[] = { "Address", "Hex", "Data" };
  354. +  const TCHAR *titles[] = { "Address", "Hex", "Data" };
  355.    int column_widths[] = { 62, 348, 124 };
  356.  
  357.    error = win32ui_get_monospaced_font( &font ); if( error ) return;
  358.  
  359. +  /* subclass listview to catch keydown and mousewheel messages */
  360. +  HWND hwnd_list = GetDlgItem( hwndDlg, IDC_MEM_LV );
  361. +  WNDPROC orig_proc = (WNDPROC) GetWindowLongPtr( hwnd_list, GWL_WNDPROC );
  362. +  SetProp( hwnd_list, "original_proc", (HANDLE) orig_proc );
  363. +  SetWindowLongPtr( hwnd_list, GWL_WNDPROC,
  364. +                    (LONG) (WNDPROC) memory_listview_proc );
  365. +
  366.    /* set extended listview style to select full row, when an item is selected */
  367.    DWORD lv_ext_style;
  368.    lv_ext_style = SendDlgItemMessage( hwndDlg, IDC_MEM_LV,
  369.                                       LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0 );
  370.    lv_ext_style |= LVS_EX_FULLROWSELECT;
  371. +  lv_ext_style |= LVS_EX_DOUBLEBUFFER;
  372.    SendDlgItemMessage( hwndDlg, IDC_MEM_LV,
  373.                        LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lv_ext_style );
  374.  
  375. @@ -230,22 +353,31 @@
  376.      SendDlgItemMessage( hwndDlg, IDC_MEM_LV, LVM_INSERTCOLUMN, i,
  377.                          ( LPARAM ) &lvc );
  378.    }
  379. +  
  380. +  /* set font of the listview to monospaced one */
  381. +  SendDlgItemMessage( hwndDlg, IDC_MEM_LV , WM_SETFONT,
  382. +                      (WPARAM) font, FALSE );
  383.  
  384. +  /* Recalculate visible rows, Visual Styles could change rows height */
  385. +  memorysb_page_rows = SendDlgItemMessage( hwndDlg, IDC_MEM_LV,
  386. +                                           LVM_GETCOUNTPERPAGE, 0, 0 );
  387. +  memorysb_page_size = memorysb_page_rows * memorysb_step;
  388. +  memorysb_page_inc = memorysb_page_size / 2;
  389. +
  390.    /* set the scrollbar parameters */
  391.    SCROLLINFO si;
  392.    si.cbSize = sizeof(si);
  393.    si.fMask = SIF_POS | SIF_RANGE | SIF_PAGE;
  394. -  si.nPos = 0;
  395. +  si.nPos = memaddr;
  396.    si.nMin = memorysb_min;
  397.    si.nMax = memorysb_max;
  398.    si.nPage = memorysb_page_size;
  399.    SetScrollInfo( GetDlgItem( hwndDlg, IDC_MEM_SB ), SB_CTL, &si, TRUE );
  400. -/* FIXME: if the scrollbar is position on the bottom, clicking on the down arrow
  401. -          reveals address 0x0000 */
  402. -  
  403. -  /* set font of the listview to monospaced one */
  404. -  SendDlgItemMessage( hwndDlg, IDC_MEM_LV , WM_SETFONT,
  405. -                      (WPARAM) font, FALSE );
  406.  
  407. -  update_display( hwndDlg, 0x0000 );
  408. +  update_display( hwndDlg, memaddr );
  409. +
  410. +  /* Recalculate columns width, high DPI resolutions have larger sizes */
  411. +  ListView_SetColumnWidth( hwnd_list, 0, LVSCW_AUTOSIZE_USEHEADER );
  412. +  ListView_SetColumnWidth( hwnd_list, 1, LVSCW_AUTOSIZE );
  413. +  ListView_SetColumnWidth( hwnd_list, 2, LVSCW_AUTOSIZE_USEHEADER );
  414.  }
  415. Index: ui/win32/win32internals.h
  416. ===================================================================
  417. --- ui/win32/win32internals.h   (revision 4664)
  418. +++ ui/win32/win32internals.h   (working copy)
  419. @@ -39,6 +39,11 @@
  420.  
  421.  #define ID_STATUSBAR 900
  422.  
  423. +/* Reduce listview flickering. Defined from WINVER >= 6.00 */
  424. +#ifndef LVS_EX_DOUBLEBUFFER
  425. +#define LVS_EX_DOUBLEBUFFER 0x00010000
  426. +#endif
  427. +
  428.  /* window handler */
  429.  HWND fuse_hWnd;
  430.  
  431. Index: ui/win32/memorybrowser.rc
  432. ===================================================================
  433. --- ui/win32/memorybrowser.rc   (revision 4664)
  434. +++ ui/win32/memorybrowser.rc   (working copy)
  435. @@ -27,16 +27,16 @@
  436.  
  437.  #include "memorybrowser.h"
  438.  
  439. -IDD_MEM DIALOGEX DISCARDABLE 0,0,371,224
  440. +IDD_MEM DIALOGEX DISCARDABLE 0,0,371,264
  441.  CAPTION "Fuse - Memory Browser"
  442.  FONT 8,"MS Sans Serif"
  443.  STYLE WS_POPUP | WS_CAPTION | WS_VISIBLE | WS_SYSMENU
  444.  EXSTYLE WS_EX_APPWINDOW
  445.  BEGIN
  446.    CONTROL  "", IDC_MEM_LV, "SysListView32", \
  447. -                WS_CHILD | WS_VISIBLE | LVS_REPORT | \
  448. +                WS_CHILD | WS_TABSTOP | WS_VISIBLE | LVS_REPORT | \
  449.                  LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSCROLL, \
  450. -                0,0,360,200, WS_EX_CLIENTEDGE
  451. -  SCROLLBAR     IDC_MEM_SB, 360,0,11,195, WS_CHILD | SBS_VERT
  452. -  PUSHBUTTON   "&Close", IDCLOSE, 315,205,51,14
  453. +                0,0,360,240, WS_EX_CLIENTEDGE
  454. +  SCROLLBAR     IDC_MEM_SB, 360,0,11,240, WS_CHILD | SBS_VERT
  455. +  PUSHBUTTON   "&Close", IDCLOSE, 315,245,51,14
  456.  END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement