📄 tabfileview.cpp
字号:
// TabFileView.cpp : implementation of the CTabFileView class
//
#include "stdafx.h"
#include "C02IDE.h"
#include "MainFrm.h"
#include "TabFileDoc.h"
#include "TabFileView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabFileView
IMPLEMENT_DYNCREATE(CTabFileView, CTreeView)
BEGIN_MESSAGE_MAP(CTabFileView, CTreeView)
//{{AFX_MSG_MAP(CTabFileView)
// ON_COMMAND(ID_ADDNODE,AddNewFunc)
ON_COMMAND(ID_NEWFILE, NewFile)
ON_NOTIFY_REFLECT(NM_RCLICK, OnRclick)
ON_COMMAND(ID_FUNC_TOSHEGMING, OnFuncToshengming)
ON_WM_RBUTTONDOWN()
ON_NOTIFY_REFLECT(NM_CLICK, OnClick)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
ON_COMMAND(ID_FUNC_TOTI, OnFuncToti)
ON_COMMAND(ID_ADDKEYTOTREE, updatefiletree)
// ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabFileView construction/destruction
CTabFileView::CTabFileView()
{
// TODO: add construction code here
m_pTreeCtrlFile = NULL;
a_filelist.RemoveAll();
m_psavepro=new ProjectList;
m_psavepro=NULL;
n_fileno=0;
}
CTabFileView::~CTabFileView()
{
}
BOOL CTabFileView::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CTreeView::PreCreateWindow( cs ))
return FALSE;
// set the style for the tree control.
cs.style |= TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTabFileView drawing
void CTabFileView::OnDraw(CDC* pDC)
{
CTabFileDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CTabFileView::OnInitialUpdate()
{
//默认初始化
CTreeView::OnInitialUpdate();
//如果树控件变量没有初始化
if(!m_pTreeCtrlFile)
{
//树控件变量没有初始化
m_pTreeCtrlFile = &GetTreeCtrl();
//创建图像列表
m_ImageList.Create (IDB_IL_FILE, 16, 1, RGB(0,255,0));
//为树控件设置图像列表
m_pTreeCtrlFile->SetImageList (&m_ImageList, TVSIL_NORMAL);
}
}
/////////////////////////////////////////////////////////////////////////////
// CTabFileView printing
BOOL CTabFileView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTabFileView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTabFileView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTabFileView diagnostics
#ifdef _DEBUG
void CTabFileView::AssertValid() const
{
CTreeView::AssertValid();
}
void CTabFileView::Dump(CDumpContext& dc) const
{
CTreeView::Dump(dc);
}
CTabFileDoc* CTabFileView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTabFileDoc)));
return (CTabFileDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTabFileView message handlers
void CTabFileView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
}
void CTabFileView::UpdateView()
{
//如果树控件变量没有初始化
if(!m_pTreeCtrlFile)
//树控件变量没有初始化
OnInitialUpdate();
//文件节点信息结构的变量
struct fileitem m_pfinode;
//树形控件存在,取得控件指针
if( m_pTreeCtrlFile && m_pTreeCtrlFile->GetSafeHwnd( ))
{
//禁止在一个窗口中的绘图功能
m_pTreeCtrlFile->LockWindowUpdate();
//项目数目
int npro=projectinfo.GetSize();
//当前项目指针
struct ProjectList * curpro=NULL;
curpro=new ProjectList;
curpro=(ProjectList *)projectinfo.GetAt(0);
//项目名称
CString proname=_T("");
proname=curpro->str_projectname;
//初始化树形项变量
HTREEITEM hticurpro=NULL;
//树形节点数目为 0
if(m_pTreeCtrlFile->GetCount()==0)
{
//插入节点
hticurpro = m_pTreeCtrlFile->InsertItem (proname);
}
else
{
//获得根节点
hticurpro=m_pTreeCtrlFile->GetRootItem();
}
//项目中的文件数目
int nfile=curpro->proinfstru.GetSize();
if(nfile>0)
{
int fileno=nfile-1;
//文件信息结构的指针变量
FileList * m_pcurfile;
m_pcurfile=new FileList;
CString str_curfilename=_T("");
//获得项目中最后一个文件信息
m_pcurfile=(FileList *)curpro->proinfstru.GetAt(nfile-1);
//获得文件名
str_curfilename=m_pcurfile->str_filename;
//初始化树形项变量
HTREEITEM hticurfile; // child item
//插入节点
hticurfile= m_pTreeCtrlFile->InsertItem (str_curfilename, 1, 1, hticurpro, TVI_LAST);
//将节点存入项目信息
m_pcurfile->t_fileitem=hticurfile;
//获得文件对应的字窗口指针
CMDIFrameWnd *nowframe = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
CMDIChildWnd *nowchild = nowframe->MDIGetActive();
//将文件的节点,指针,序号信息存入文件节点变量
m_pfinode.titem=hticurfile;
m_pfinode.m_pchildf=nowchild;
m_pfinode.n_nodenumber=nfile-1;
//将文件节点变量加入文件节点数组
fileitemarray[fileno]=m_pfinode;
// projectinfo.InsertAt(0,(CObject*)curpro);
//在当前节点展开
m_pTreeCtrlFile->Expand (hticurfile , TVE_EXPAND);
// int nfunc=m_pcurfile->funcinfstru.GetSize();
m_psavepro=curpro;
//激活在一个窗口中的绘图功能
m_pTreeCtrlFile->UnlockWindowUpdate();
}
}
}
void CTabFileView::updatefiletree()
{
//树控件不存在
if(!m_pTreeCtrlFile)
//初始化树控件
OnInitialUpdate();
//树形控件存在,取得控件指针
if( m_pTreeCtrlFile && m_pTreeCtrlFile->GetSafeHwnd( ))
{
//删除树控件的所有项
m_pTreeCtrlFile->DeleteAllItems();
//禁止对树控件的重画
m_pTreeCtrlFile->LockWindowUpdate();
// int npro=projectinfo.GetSize();
// for(int i=0;i<=npro-1;i++)
// {
//当前项目指针
struct ProjectList * curpro=NULL;
curpro=new ProjectList;
curpro=(ProjectList *)projectinfo.GetAt(0);
CString proname=_T("");
proname=curpro->str_projectname;
//将项目名作为根节点
HTREEITEM hticurpro = m_pTreeCtrlFile->InsertItem (proname);//GetRootItem();//
//项目中的文件数目
int nfile=curpro->proinfstru.GetSize();
//文件信息结构指针
struct FileList * m_pcurfile=NULL;
m_pcurfile=new FileList;
FileList *m_pfile;
m_pfile=new FileList;
CMDIChildWnd *nowchild = NULL;
CString str_curfilename=_T("");
//对每一个文件展开
for (int j=0;j<=nfile-1;j++)
{
//取项目中的第j个文件信息
m_pcurfile=(FileList *)curpro->proinfstru.GetAt(j);
//文件名
str_curfilename=m_pcurfile->str_filename;
nowchild=m_pcurfile->m_pChildWnd;
m_mappro.Lookup(nowchild->GetSafeHwnd(),(void *&)m_pfile);
//添加文件节点
HTREEITEM hticurfile; // child item
hticurfile= m_pTreeCtrlFile->InsertItem( str_curfilename,1,1,hticurpro,TVI_LAST);
//在新加节点处展开
m_pTreeCtrlFile->Expand (hticurpro , TVE_EXPAND);
//当前文件中的函数个数
int nfunc=m_pfile->oa_funcinfstru.GetSize();
// CString str_filenm;
// str_filenm=m_pcurfile->str_filename;
//函数信息结构的指针变量
struct FuncStruct * m_pcurfunc;
m_pcurfunc=new FuncStruct;
CString str_curfunc=_T("");
for(int k=0;k<=nfunc-1;k++)
{
//获得第i个函数
m_pcurfunc=(FuncStruct *)m_pfile->oa_funcinfstru.GetAt(k);
//函数名称
str_curfunc=m_pcurfunc->str_funcname;
//插入节点
HTREEITEM hticurfunc; // child item
hticurfunc= m_pTreeCtrlFile->InsertItem (str_curfunc, 2, 3, hticurfile, TVI_LAST);
// m_pTreeCtrlFile->Expand (hticurfile , TVE_EXPAND);
}
}
// }
//激活在一个窗口中的绘图功能
m_pTreeCtrlFile->UnlockWindowUpdate();
}
}
void CTabFileView::OnLButtonDown(UINT nFlags, CPoint point)
{
//默认的左键处理函数
CTreeView::OnLButtonDown(nFlags, point);
//定义树形项变量
HTREEITEM hti,hParent;//,fti;
//根节点
hParent=m_pTreeCtrlFile->GetRootItem();
//当前选择节点
hti=m_pTreeCtrlFile->GetSelectedItem();
/* //根节点的第一个子节点
fti=m_pTreeCtrlFile->GetChildItem(hParent);
//子窗口指针
CMDIChildWnd * m_ptestwnd=NULL;
m_ptestwnd=new CMDIChildWnd ;
//文件信息结构指针
FileList * m_ptopfile=NULL;
m_ptopfile=new FileList;
// m_psavepro=(ProjectList *)projectinfo.GetAt(0);
//项目不存在
if(m_psavepro==NULL)
return;
//项目中的文件数目
int n_filenum=m_psavepro->proinfstru.GetSize();
//如果当前选择节点是文件节点
if(m_pTreeCtrlFile->GetParentItem(hti)==hParent)
{
for(int i=0;i<=n_filenum-1;i++)
{
if(fti==hti)
{
m_pgotochildf=fileitemarray[i].m_pchildf;
n_fileno=fileitemarray[i].n_nodenumber;
break;
}
fti=m_pTreeCtrlFile->GetNextSiblingItem(fti);
}
// m_ptestwnd->MDIActivate();
// m_ptestwnd->BringWindowToTop();
}
else
{
*/
//如果当前选择节点是根节点
if(hti==hParent)
{
//主窗口指针
CMainFrame* m_Wnd =(CMainFrame*) AfxGetMainWnd();
//展开所有节点
m_Wnd->ExpandAllFile();
}
else
{
if(m_pTreeCtrlFile->GetParentItem(hti)!=hParent)
OnFuncToti();
}
}
/*
void CTabFileView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CTreeView::OnRButtonDblClk(nFlags, point);
}
*/
void CTabFileView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//工作区坐标转换为屏幕坐标
ClientToScreen(&point);
myflags=nFlags;
mypoint=point;
//同时模拟左键点击
OnLButtonDown(myflags, mypoint);
//定义树形项变量
HTREEITEM hti,hParent;
//获得根节点
hParent=m_pTreeCtrlFile->GetRootItem();
//获得选择节点
hti=m_pTreeCtrlFile->GetSelectedItem();
// CRect r_item=(0,0,0,0);
// m_pTreeCtrlFile->GetItemRect(hti,r_item,TRUE);
//如果选择的节点是函数节点
if(m_pTreeCtrlFile->GetParentItem(hti)!=hParent)//&&r_item.PtInRect(mypoint)!=0)
{
//主窗口
CWnd* Wnd = AfxGetMainWnd();
//加载菜单
CMenu menu;
VERIFY(menu.LoadMenu(IDR_FUNCMENU));
//选择第一个子菜单
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
//加载子菜单到该窗口
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -