// mode_complex.cpp : DLL アプリケーション用のエントリ ポイントを定義します。 // # include "stdafx.h" # include "..\fileseeker\interface\plugin.h" # include "..\fileseeker\interface\internal.h" # include # include # include # include # define BOOST_MEM_FN_ENABLE_STDCALL # include # include # include # include # include # include # include # include # include # include # include # include "resource.h" # define BEGIN_END( c ) c.begin(), c.end() // {F9A48F9E-5BE3-422d-A733-F023C7480EF0} # define GUID_COMPLEX { 0xf9a48f9e, 0x5be3, 0x422d, { 0xa7, 0x33, 0xf0, 0x23, 0xc7, 0x48, 0xe, 0xf0 } } static const GUID GUID_DEFAULT = { 0x36d32f49, 0x2d1, 0x45a5, { 0x9e, 0x52, 0x33, 0x25, 0x95, 0xe5, 0xc3, 0x71 } }; static const GUID GUID_WILDCARD = { 0xe24f336, 0x7ebb, 0x4372, { 0x84, 0xeb, 0xed, 0xc9, 0x53, 0xb6, 0x14, 0xc6 } }; #define PLUGIN_NAME _T("Complex") CAppModule _Module; fs::fsIPluginContainer* g_pCont = NULL; class CComplexKeywordMatcher* g_pComplexKwMatcher = NULL; class CComplexKeywordMatcher : public fs::fsIKeywordMatcher { public: typedef std::vector< fs::fsIKeywordMatcher* > List; List m_KeywordMatchers; List m_Actives; FS_IMPLEMENT_GUID( GUID_COMPLEX ); FS_IMPLEMENT( void, purge() ){ delete this; } FS_IMPLEMENT( LPCTSTR, pluginName() ){ return PLUGIN_NAME; } FS_IMPLEMENT( LPCTSTR, getMenuLabel() ){ return _T("複合(&C)"); } FS_IMPLEMENT( BOOL, match( fs::FileInfoPtr pFileInfo ) ){ List::iterator iter = std::find_if( m_Actives.begin(), m_Actives.end(), std::bind2nd( boost::mem_fn( &fs::fsIKeywordMatcher::match ), pFileInfo ) ); return iter != m_Actives.end(); } void Init(){ fs::EnumObject< fs::fsIKeywordMatcher > enumObj = g_pCont->enumObjects( FSIID_KEYWORD_MATCHER, FALSE ); // m_KeywordMatchers.clear(); m_KeywordMatchers.assign( enumObj.begin(), enumObj.end() ); int n = m_KeywordMatchers.size(); List::iterator iter = std::find( m_KeywordMatchers.begin(), m_KeywordMatchers.end(), static_cast< fs::fsIKeywordMatcher* >( this ) ); ATLASSERT( iter != m_KeywordMatchers.end() ); m_KeywordMatchers.erase( iter ); // m_Actives.clear(); Activate( GUID_DEFAULT ); Activate( GUID_WILDCARD ); } void Activate( const GUID& guid ){ List::iterator i = m_KeywordMatchers.begin(); while( i != m_KeywordMatchers.end() ){ if( *(*i)->guid() == guid ){ m_Actives.push_back( *i ); } i++; } } FS_IMPLEMENT( void, setKeyword( LPCTSTR pszKeyword ) ){ if( not m_KeywordMatchers.size() ){ Init(); } std::for_each( m_KeywordMatchers.begin(), m_KeywordMatchers.end(), boost::bind( &fs::fsIKeywordMatcher::setKeyword, _1, pszKeyword ) ); } FS_IMPLEMENT( LPCTSTR, modeName() ){ return _T("complex"); } }; class CConfigDlg : public CDialogImpl< CConfigDlg >, public CWinDataExchange< CConfigDlg > { protected: CListViewCtrl m_listMode; public: enum { IDD = IDD_CONFIG }; BEGIN_MSG_MAP( CConfigDlg ) MESSAGE_HANDLER( WM_INITDIALOG, OnInitDialog ) COMMAND_ID_HANDLER(IDOK, OnOK) COMMAND_ID_HANDLER(IDCANCEL, OnCancel) END_MSG_MAP() BEGIN_DDX_MAP( CConfigDlg ) DDX_CONTROL_HANDLE( IDC_LIST_MODE, m_listMode ) END_DDX_MAP() LRESULT OnInitDialog( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ){ DoDataExchange( FALSE ); m_listMode.SetExtendedListViewStyle( LVS_EX_CHECKBOXES ); m_listMode.InsertColumn( 0, _T("名前"), LVCFMT_LEFT, 300, -1 ); if( not g_pComplexKwMatcher->m_Actives.size() ){ g_pComplexKwMatcher->setKeyword( _T("") ); // バインドさせる } using CComplexKeywordMatcher::List; List& matchers = g_pComplexKwMatcher->m_KeywordMatchers; List& actives = g_pComplexKwMatcher->m_Actives; List::iterator i = matchers.begin(); int idx = 0; while( i != matchers.end() ){ LPCTSTR name = (*i)->pluginName(); idx = m_listMode.InsertItem( idx, name ); List::iterator i2 = std::find( BEGIN_END( actives ), *i ); m_listMode.SetCheckState( idx, i2 != actives.end() ); m_listMode.SetItemData( idx, reinterpret_cast< DWORD_PTR >( *i ) ); i++, idx++; } return 0; } void Apply(){ using CComplexKeywordMatcher::List; List& actives = g_pComplexKwMatcher->m_Actives; actives.clear(); for( int i = 0; i < m_listMode.GetItemCount(); i++ ){ if( m_listMode.GetCheckState( i ) ){ actives.push_back( reinterpret_cast< List::value_type >( m_listMode.GetItemData( i ) ) ); } } } LRESULT OnOK( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled ){ Apply(); EndDialog( wID ); return 0; } LRESULT OnCancel( WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled ){ EndDialog( wID ); return 0; } }; class CPluginMenu : public fs::fsIPluginMenu { FS_IMPLEMENT_GUID( GUID_COMPLEX ); FS_IMPLEMENT( void, purge() ){ delete this; } FS_IMPLEMENT( LPCTSTR, pluginName() ){ return PLUGIN_NAME; } FS_IMPLEMENT( LPCTSTR, getMenuLabel() ){ return _T("コンプレックス モード 設定(&C)"); } FS_IMPLEMENT( void, invoke( HWND hParent ) ){ CConfigDlg dlg; dlg.DoModal(); } }; class CAbout : public fs::fsIAbout { FS_IMPLEMENT_GUID( GUID_COMPLEX ); FS_IMPLEMENT( void, purge() ){ delete this; } FS_IMPLEMENT( LPCTSTR, pluginName() ){ return PLUGIN_NAME; } FS_IMPLEMENT( void, invoke( HWND hParent ) ){ ::MessageBox( hParent, _T("コンプレックス 複合検索モード") _T(" lpctstr"), _T("About"),0 ); } }; void InitInstance( HANDLE hModule ) { HRESULT hRes = ::CoInitialize(NULL); // If you are running on NT 4.0 or higher you can use the following call instead to // make the EXE free threaded. This means that calls come in on a random RPC thread. // HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED); ATLASSERT(SUCCEEDED(hRes)); // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used ::DefWindowProc(NULL, 0, 0, 0L); AtlInitCommonControls(ICC_COOL_CLASSES | ICC_BAR_CLASSES); // add flags to support other controls hRes = _Module.Init( NULL, static_cast< HINSTANCE >( hModule ) ); ATLASSERT(SUCCEEDED(hRes)); CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); } void ExitInstance( HANDLE hModule ) { _Module.RemoveMessageLoop(); _Module.Term(); ::CoUninitialize(); } BOOL APIENTRY DllMain( HANDLE hModule, DWORD dwReason, LPVOID lpReserved ) { switch( dwReason ){ case DLL_PROCESS_ATTACH: InitInstance( hModule ); break; case DLL_PROCESS_DETACH: ExitInstance( hModule ); break; } return TRUE; } DWORD WINAPI GetPluginObjects( fs::fsIPluginContainer* pCont ) { if( not IsSupported_PluginContainer_enumObjects( pCont->iid() ) ){ ::MessageBox( 0, _T("コンプレックスモードはこのバージョンでは使えません。\n") _T("mode_complex.dll を削除するか、本体をアップデートしてください"), 0, 0 ); return 0; } g_pCont = pCont; pCont->add( (g_pComplexKwMatcher = new CComplexKeywordMatcher) ); pCont->add( new CPluginMenu ); pCont->add( new CAbout ); return 0; }