view include/dndfile.h @ 14:ac17a73e39b3

Zoom in / out in Preview Dialog.
author pyon@macmini
date Thu, 05 Jun 2014 04:19:03 +0900
parents bc2e2b304095
children 92188f60323d
line wrap: on
line source

// Filename   : dndfile.h
// Last Change: 12-Sep-2013.
//
#ifndef __DNDFILE_H__
#define __DNDFILE_H__

#include "db.h"

class DnDFile : public wxFileDropTarget
{
    public:
        DnDFile( wxGrid *grid )
        {
            m_grid = grid;
        }
        virtual bool OnDropFiles( wxCoord x, wxCoord y, const wxArrayString& filenames )
        {
            size_t nFiles = filenames.GetCount();
            if ( nFiles != 1 ) return false;

            m_grid->ClearGrid();

            // ファイルから被保番リストを生成
            wxTextFile csv;
            csv.Open( filenames[0] );

            wxRegEx reHhs( wxT("^0[1238][0-9]{8}$") );
            wxArrayString hhs;
            for ( int n = 0; n < csv.GetLineCount(); n++ ) {
                wxString hhsno = csv.GetLine( n ).BeforeFirst( ',', NULL );
                if ( ! reHhs.Matches( hhsno ) ) 
                    continue;
                hhs.Add( hhsno );
            }
            csv.Close();

            //
            int d = hhs.GetCount() - m_grid->GetNumberRows();
            if ( d > 0 )
                m_grid->AppendRows( d, true );

            // グリッドに情報を読込み
            wxArrayString res = GetHhsInfoAndPathByHhsNoList( hhs );
            for ( int r = 0; r < res.GetCount(); r++ ) {
                wxArrayString data = wxSplit( res[r], '_', '\\' );
                m_grid->SetCellValue( r, 0, data[0] );
                m_grid->SetCellValue( r, 1, data[1] );
                m_grid->SetCellValue( r, 2, data[2] );    
            }

            return true;
        }

    private:
        wxGrid* m_grid;
};
        
#endif  //__DNDFILE_H__