/*SUNIX??ì¨?′?? v1.4*/
// SelectVectorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sp_draw.h"
#include "SelectVectorDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVectorStatic
CVectorStatic::CVectorStatic()
{
}
CVectorStatic::~CVectorStatic()
{
}
BEGIN_MESSAGE_MAP(CVectorStatic, CStatic)
//{{AFX_MSG_MAP(CVectorStatic)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVectorStatic message handlers
void CVectorStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rt1;
GetClientRect(&rt1);
CBrush brush;
brush.CreateSolidBrush(RGB(255,255,255));
CBrush* pOldBrush=dc.SelectObject(&brush);
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(192,192,192));
CPen *poldpen=dc.SelectObject(&pen);
dc.Rectangle(&rt1);
dc.SelectObject(pOldBrush);
dc.SelectObject(poldpen);
CSize sz=m_vector.GetSize();
if ((sz.cx==0)||(sz.cy==0)) return;
float scaleX=1;
float scaleY=1;
if((rt1.Width()<sz.cx)||(rt1.Height()<sz.cy))
{
if (rt1.Width()<sz.cx)
scaleX=((float)rt1.Width())/(float)(sz.cx+1);
if (rt1.Height()<sz.cy)
scaleY=((float)rt1.Height())/(float)(sz.cy+1);
float scale=__max(scaleX,scaleY);
sz.cx=__min(rt1.Width()-10,(int)((float)(sz.cx-1)*scale));
sz.cy=__min(rt1.Height()-10,(int)((float)(sz.cy-1)*scale));
}
else
{
if (rt1.Width()>sz.cx)
scaleX=(int)((float)rt1.Width())/(float)(sz.cx+1);
if (rt1.Height()>sz.cy)
scaleY=(int)((float)rt1.Height())/(float)(sz.cy+1);
float scale=__min(scaleX,scaleY);
sz.cx=__min(rt1.Width()-10,(int)((float)(sz.cx-1)*scale));
sz.cy=__min(rt1.Height()-10,(int)((float)(sz.cy-1)*scale));
}
rt1.SetRect(5,5,sz.cx,sz.cy);
m_vector.Draw(&dc,rt1,rt1,0,FALSE);
// Do not call CStatic::OnPaint() for painting messages
}
void CVectorStatic::SetVectFile(LPCSTR filepath)
{
m_vector.Load(filepath);
Invalidate(TRUE);
}
/////////////////////////////////////////////////////////////////////////////
// CSelectVectorDlg property page
IMPLEMENT_DYNCREATE(CSelectVectorDlg, CPropertyPage)
CSelectVectorDlg::CSelectVectorDlg() : CPropertyPage(CSelectVectorDlg::IDD)
{
//{{AFX_DATA_INIT(CSelectVectorDlg)
m_bFill = FALSE;
m_vector = _T("");
//}}AFX_DATA_INIT
}
CSelectVectorDlg::~CSelectVectorDlg()
{
}
void CSelectVectorDlg::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelectVectorDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Check(pDX, IDC_FILL, m_bFill);
DDX_Text(pDX, IDC_EDIT1, m_vector);
DDV_MaxChars(pDX, m_vector, 32);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_TAB1, m_TabCtrl);
}
BEGIN_MESSAGE_MAP(CSelectVectorDlg, CPropertyPage)
//{{AFX_MSG_MAP(CSelectVectorDlg)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_BN_CLICKED(IDC_COLOR, OnColor)
//}}AFX_MSG_MAP
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CSelectVectorDlg::OnTcnSelchangeTab1)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelectVectorDlg message handlers
BOOL CSelectVectorDlg::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
m_ctrl_ToColor.SubclassDlgItem(IDC_COLOR,this);
m_ctrlStatic.SubclassDlgItem(IDC_VECTOR,this);
CString str;
CStdioFile file;
BOOL res = true;
if (file.Open("C://sunpac//par//global//vec//vec.ini",CFile::modeRead|CFile::typeText)==FALSE)
{
res = false;
}
if(res)
{
res = ReadVecType(&file);
}
if(!res)
{
FillBox();
}
else
{
int i = m_TabCtrl.GetCurSel();
TCITEM tcItem;
char buffer[64]={0};
tcItem.pszText= buffer;
tcItem.cchTextMax=32;
tcItem.mask= TCIF_TEXT;
m_TabCtrl.GetItem(i,&tcItem);
CString type = buffer;
FillBox(&file,type);
}
if(res)
{
file.Close();
}
if(!m_vector.IsEmpty())
m_list.SelectString(0,m_vector);
OnSelchangeList1();
m_ctrl_ToColor.m_Color=m_ToColor;
m_ctrl_ToColor.Invalidate();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CSelectVectorDlg::ReadVecType(CStdioFile *pfile)
{
CString str;
BOOL bl1,bl2;
DWORD dwflag = 0;
char strName[33];
int iret;
int index = 0;
//移动读指针到画面段落
if (SeekSection(pfile,"type")==FALSE)
return FALSE;
try
{
//读取下一行字符串
bl1=pfile->ReadString(str);
if (!bl1) return FALSE;
str.TrimLeft();
str.TrimRight();
//判断字符串是否是段落名
bl2=HitTestSectionID(str);
if (bl2) return FALSE;
while ((!bl2)&&(bl1))
{
//读入画面名称和画面标志
iret=sscanf(str,"%x=%[^;]33s",&dwflag,strName);//%[^=]s
if (iret==2)
{
m_TabCtrl.InsertItem(index, strName);
index++;
}
//读取下一行字符串
bl1=pfile->ReadString(str);
if (!bl1) break;
str.TrimLeft();
str.TrimRight();
//判断字符串是否是段落名
bl2=HitTestSectionID(str);
if (bl2) break;
}
return TRUE;
}
catch(CFileException* e)
{
e->Delete();
return FALSE;
}
}
BOOL CSelectVectorDlg::SeekSection(CStdioFile *pfile, LPCSTR strSection)
{
CString str;
BOOL bret;
assert(strSection!=NULL);
assert(pfile!=NULL);
try
{
pfile->SeekToBegin();
bret=pfile->ReadString(str);
while (bret)
{
if (HitTestSectionID(str)==TRUE)
{
if ((HitTestSectionName(str,strSection))==TRUE)
return TRUE;
}
bret=pfile->ReadString(str);
}
return FALSE;
}
catch(CFileException* e)
{
e->Delete();
return FALSE;
}
}
BOOL CSelectVectorDlg::HitTestSectionID(LPCSTR str)
{
CString s;
assert(str!=NULL);
s=str;
s.TrimLeft();
if (s.IsEmpty()) return FALSE;
if ((s[0]=='[')&&(s.FindOneOf("]")>0))
return TRUE;
return FALSE;
}
BOOL CSelectVectorDlg::HitTestSectionName(LPCSTR strSection, LPCSTR strName)
{
assert(strSection!=NULL);
assert(strName!=NULL);
CString str="[";
str=str+strName+"]";
if (_strnicmp(strSection,str,str.GetLength())==0)
return TRUE;
else return FALSE;
}
void CSelectVectorDlg::SetContent(LPCSTR vectorname, BOOL bFill, COLORREF color)
{
m_ToColor=color;
m_bFill=bFill;
m_vector=vectorname;
}
void CSelectVectorDlg::GetContent(CString &vectorname, BOOL &bFill, COLORREF &color)
{
color=m_ToColor;
bFill=m_bFill;
vectorname=m_vector;
}
void CSelectVectorDlg::FillBox()
{
CFileFind vectordir;
CString file=theApp.GetDirectory();
CString vectorname;
file+="global\\vec\\*.vec";
m_list.ResetContent();
if (vectordir.FindFile(file))
{
while (vectordir.FindNextFile())
{
vectorname=vectordir.GetFileTitle();
m_list.AddString(vectorname);
}
vectorname=vectordir.GetFileTitle();
m_list.AddString(vectorname);
vectordir.Close();
}
}
void CSelectVectorDlg::FillBox(CStdioFile *pfile,CString type)
{
m_list.ResetContent();
CString str;
BOOL bl1,bl2;
DWORD dwflag = 0;
char strName[33];
int iret;
//移动读指针到画面段落
if (SeekSection(pfile,type)==FALSE)
return;
try
{
//读取下一行字符串
bl1=pfile->ReadString(str);
if (!bl1) return;
str.TrimLeft();
str.TrimRight();
//判断字符串是否是段落名
bl2=HitTestSectionID(str);
if (bl2) return;
while ((!bl2)&&(bl1))
{
//读入画面名称和画面标志
iret=sscanf(str,"%x=%[^;]33s",&dwflag,strName);//%[^=]s
if (iret==2)
{
m_list.AddString(strName);
}
//读取下一行字符串
bl1=pfile->ReadString(str);
if (!bl1) break;
str.TrimLeft();
str.TrimRight();
//判断字符串是否是段落名
bl2=HitTestSectionID(str);
if (bl2) break;
}
return;
}
catch(CFileException* e)
{
e->Delete();
return;
}
}
void CSelectVectorDlg::OnSelchangeList1()
{
// TODO: Add your control notification handler code here
int pos=m_list.GetCurSel();
CString vectorname;
if (pos>=0)
{
m_list.GetText(pos,vectorname);
m_vector=vectorname;
CString file;
file.Format("%sglobal\\vec\\%s.vec",theApp.GetDirectory(),vectorname);
m_ctrlStatic.SetVectFile(file);
}
UpdateData(FALSE);
}
void CSelectVectorDlg::OnColor()
{
// TODO: Add your control notification handler code here
if (m_ToColor==m_ctrl_ToColor.m_Color) return;
m_ToColor=m_ctrl_ToColor.m_Color;
}
void CSelectVectorDlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
int i = m_TabCtrl.GetCurSel();
TCITEM tcItem;
char buffer[64]={0};
tcItem.pszText= buffer;
tcItem.cchTextMax=32;
tcItem.mask= TCIF_TEXT;
m_TabCtrl.GetItem(i,&tcItem);
CStdioFile file;
if (file.Open("C://sunpac//par//global//vec//vec.ini",CFile::modeRead|CFile::typeText)==TRUE)
{
FillBox(&file,buffer);
if(!m_vector.IsEmpty())
m_list.SelectString(0,m_vector);
OnSelchangeList1();
file.Close();
}
*pResult = 0;
}