// FeatureLibView.cpp : implementation file
//

#include "stdafx.h"
#include "imagegrinder.h"
#include "FeatureLibView.h"



/////////////////////////////////////////////////////////////////////////////
// CFeatureLibView

IMPLEMENT_DYNCREATE(CFeatureLibView, CView)

CFeatureLibView::CFeatureLibView()
{
	DiagPanel=NULL;
	MaxWid=-1;
}

CFeatureLibView::~CFeatureLibView()
{
	if(DiagPanel) delete DiagPanel;
	
}


BEGIN_MESSAGE_MAP(CFeatureLibView, CView)
//{{AFX_MSG_MAP(CFeatureLibView)
ON_WM_SIZE()
	ON_COMMAND(ID_FILE_EXPORT_FEATUREFILE, OnFileExportFeaturefile)
	ON_COMMAND(ID_FILE_IMPORT_FEATURES, OnFileImportFeatures)
	ON_COMMAND(ID_EDIT_SELECTUNUSEDFEATURES, OnEditSelectunusedfeatures)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFeatureLibView drawing

void CFeatureLibView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
}

/////////////////////////////////////////////////////////////////////////////
// CFeatureLibView diagnostics

#ifdef _DEBUG
void CFeatureLibView::AssertValid() const
{
	CView::AssertValid();
}

void CFeatureLibView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CFeatureLibView message handlers

BOOL CFeatureLibView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	
	//	CMDIChildWnd::Create(NULL,"Feature Library",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_CHILD,rectDefault,pParentWnd);
	BOOL res;
	res= CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
	
	CRect rct;
	DiagPanel=new CFeatureLibDiag;
	res=DiagPanel->Create(CFeatureLibDiag::IDD,this);
	ASSERT(res);
	DiagPanel->GetWindowRect(&rct);
	SetWindowPos(NULL,0,0,
		rct.Width()+GetSystemMetrics(SM_CXSIZEFRAME)*2,
		rct.Height()+GetSystemMetrics(SM_CXSIZEFRAME)+GetSystemMetrics(SM_CYCAPTION),
		SWP_NOZORDER|SWP_NOMOVE);
	DiagPanel->ShowWindow(SW_SHOW);
	DiagPanel->SetView(this);
	
	return res;
}

void CFeatureLibView::OnSize(UINT nType, int cx, int cy) 
{
	
	if(DiagPanel)
	{
		CRect sze;
		DiagPanel->ResizeVert(cy);
		DiagPanel->ResizeHor(cx);
		if(MaxWid==-1)
		{
			CRect rct;
			GetClientRect(rct);
			DiagPanel->GetWindowRect(&rct);
			MaxWid=rct.Width();
		}
		
	}
	
	CView::OnSize(nType, cx, cy);
	
	
	
}

int CFeatureLibView::GetMaxWidth()
{
	return MaxWid;
}

void CFeatureLibView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	ASSERT(DiagPanel);
	DiagPanel->SetView(this);
}

void CFeatureLibView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	DiagPanel->RefreshList();
	
}

void CFeatureLibView::OnFileExportFeaturefile() 
{
CFileDialog dlg(FALSE,"igf","List.igf",NULL,"Feature List (*.igf)|*.igf||",NULL);

if(dlg.DoModal()==IDOK)
{
DiagPanel->SaveSelectedFeatures(dlg.GetPathName());
}

}

void CFeatureLibView::OnFileImportFeatures() 
{
CFileDialog dlg(TRUE,NULL,NULL,NULL,"Feature List (*.igf)|*.igf||",NULL);

if(dlg.DoModal()==IDOK)
{
DiagPanel->LoadFeatures(dlg.GetPathName());
}
	
}

void CFeatureLibView::OnEditSelectunusedfeatures() 
{
	DiagPanel->SelectUnsed();

}
