434 lines
10 KiB
C++
434 lines
10 KiB
C++
#include "stdafx.h"
|
|
#include "CoolTreeCtrl.h"
|
|
#include "DockDialog.h"
|
|
#include "dockpane.h"
|
|
#include "gs.h "
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCoolTreeCtrl
|
|
extern CDockPane *g_pDockPane;
|
|
CCoolTreeCtrl::CCoolTreeCtrl()
|
|
{
|
|
m_bTracking=FALSE;
|
|
}
|
|
|
|
CCoolTreeCtrl::~CCoolTreeCtrl()
|
|
{
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CCoolTreeCtrl, CTreeCtrl)
|
|
//{{AFX_MSG_MAP(CCoolTreeCtrl)
|
|
ON_WM_ERASEBKGND()
|
|
ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelchanging)
|
|
ON_WM_NCMOUSEMOVE()
|
|
ON_WM_MOUSEMOVE()
|
|
ON_WM_PAINT()
|
|
ON_WM_VSCROLL()
|
|
ON_COMMAND(ID_DELDIR, OnDeldir)
|
|
ON_WM_CONTEXTMENU()
|
|
ON_WM_LBUTTONUP()
|
|
ON_WM_NCLBUTTONUP()
|
|
ON_WM_RBUTTONUP()
|
|
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
|
|
ON_WM_RBUTTONDOWN()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCoolTreeCtrl message handlers
|
|
|
|
void CCoolTreeCtrl::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
|
HTREEITEM hItem = pNMTreeView->itemNew.hItem;
|
|
if(!hItem)
|
|
return;
|
|
m_hSelectItem=hItem;
|
|
CString strPathName;
|
|
CStringArray sRcdName;
|
|
CString sDwgPath;
|
|
CString sText;
|
|
CString sParentText;
|
|
BaseFuncs::GetPathName(strPathName);
|
|
CDockDialog *pDlg1=(CDockDialog*)GetParent()->GetParent()->GetParent()->GetParent();
|
|
if(acedGetAcadDwgView()==NULL)
|
|
{
|
|
return;
|
|
}
|
|
//modify by hrp;
|
|
CString sSubPath;
|
|
HTREEITEM hParentItem=GetParentItem(hItem);
|
|
HTREEITEM hChildItem=GetChildItem(hItem);
|
|
m_sCurParentText=sParentText=GetItemText(hParentItem);
|
|
m_sCurSltText=sText=GetItemText(hItem);
|
|
|
|
if(hChildItem!=NULL) //点击的是文件甲
|
|
{
|
|
CString sPath;
|
|
while(hItem!=NULL)
|
|
{
|
|
sPath=GetItemText(hItem);
|
|
pDlg1->m_sDirPath+=sPath+_T("\\");
|
|
hItem=GetParentItem(hItem);
|
|
}
|
|
pDlg1->m_nType=-1;
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if(hParentItem==NULL)
|
|
return;
|
|
while(hItem!=NULL)
|
|
{
|
|
sText=GetItemText(hItem);
|
|
sSubPath=_T("\\")+sText+sSubPath;
|
|
hItem=GetParentItem(hItem);
|
|
}
|
|
strPathName=strPathName+_T("\\TK\\Customer\\图库中心")+sSubPath;
|
|
|
|
//strPathName = _T("\\\\192.168.0.200\\大杂烩\\图库中心") + sSubPath;
|
|
strPathName.TrimRight(_T("\\"));
|
|
strPathName+=_T(".dwg");
|
|
pDlg1->m_strSubPath=sSubPath+_T(".dwg");
|
|
pDlg1->m_nType=1;
|
|
pDlg1->m_sDwgPath=strPathName;
|
|
pDlg1->getListCtrl().DeleteAllItems();
|
|
pDlg1->AddItemToListCtrl(strPathName);
|
|
|
|
pDlg1->getListCtrl().RedrawWindow();
|
|
// acedGetAcadDwgView()->SetFocus();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
BOOL CCoolTreeCtrl::SetBKImage(LPCTSTR LpszResource)
|
|
{
|
|
if( m_bitmap.m_hObject != NULL )
|
|
m_bitmap.DeleteObject();
|
|
|
|
CString sBmpPath = FilePath::GetRootDir() + _T("\\BMP\\") + LpszResource;
|
|
HBITMAP hBit = (HBITMAP) LoadImage(NULL, sBmpPath,
|
|
IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR | LR_LOADFROMFILE);
|
|
|
|
if( hBit != NULL )
|
|
m_bitmap.Attach(hBit);
|
|
else
|
|
return FALSE;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
BOOL CCoolTreeCtrl::OnEraseBkgnd(CDC* pDC)
|
|
{
|
|
return CTreeCtrl::OnEraseBkgnd(pDC);
|
|
|
|
CRect rect;
|
|
GetClientRect(&rect);
|
|
CBrush brush(RGB(255,255,255));
|
|
CBrush* pOldBrush=pDC->SelectObject(&brush);
|
|
pDC->PatBlt(rect.left,rect.top,rect.Width(),rect.Height(),PATCOPY);
|
|
pDC->SelectObject(pOldBrush);
|
|
brush.DeleteObject();
|
|
return TRUE;
|
|
/*
|
|
CRect rect;
|
|
this->GetClientRect(rect);
|
|
CBrush brush;
|
|
brush.CreateSolidBrush(RGB(112,23,255));
|
|
pDC->SetBkMode(TRANSPARENT);
|
|
pDC->FillRect(rect,&brush);
|
|
DeleteObject(brush);
|
|
// this->Invalidate();
|
|
// return CTreeCtrl::OnEraseBkgnd(pDC);
|
|
|
|
return TRUE;*/
|
|
}
|
|
|
|
|
|
BOOL CCoolTreeCtrl::PreCreateWindow(CREATESTRUCT& cs)
|
|
{
|
|
//TVS_TRACKSELECT
|
|
cs.style |= TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES |TVS_SHOWSELALWAYS;
|
|
return CTreeCtrl::PreCreateWindow(cs);
|
|
}
|
|
|
|
/*
|
|
|
|
void CCoolTreeCtrl::OnNcMouseMove(UINT nHitTest, CPoint point)
|
|
{
|
|
CTreeCtrl::OnNcMouseMove(nHitTest, point);
|
|
}
|
|
|
|
*/
|
|
void CCoolTreeCtrl::OnMouseMove(UINT nFlags, CPoint point)
|
|
{
|
|
if (!m_bTracking)
|
|
{
|
|
TRACKMOUSEEVENT tme;
|
|
tme.cbSize = sizeof(tme);
|
|
tme.hwndTrack = m_hWnd;
|
|
tme.dwFlags = TME_LEAVE | TME_HOVER;
|
|
tme.dwHoverTime = 1;
|
|
m_bTracking = _TrackMouseEvent(&tme);
|
|
}
|
|
CTreeCtrl::OnMouseMove(nFlags, point);
|
|
}
|
|
|
|
|
|
LRESULT CCoolTreeCtrl::OnMouseLeave(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
m_bTracking = FALSE;
|
|
if(acedGetAcadDwgView()!=NULL)
|
|
acedGetAcadDwgView()->SetFocus();
|
|
return 0;
|
|
}
|
|
|
|
|
|
HTREEITEM CCoolTreeCtrl::viewItemByText( HTREEITEM hRootItem,CString sText)
|
|
{
|
|
if(hRootItem!=NULL)
|
|
{
|
|
CString sItemText;
|
|
HTREEITEM hChldItem;
|
|
hChldItem =GetChildItem(hRootItem);
|
|
if(hChldItem==NULL)
|
|
return NULL;
|
|
sItemText=GetItemText(hChldItem);
|
|
if(sItemText==sText)
|
|
{
|
|
SelectItem(hChldItem);
|
|
return hChldItem;
|
|
}
|
|
while((hChldItem=GetNextItem(hChldItem,TVGN_NEXT))!=NULL)
|
|
{
|
|
sItemText=GetItemText(hChldItem);
|
|
if(sItemText==sText)
|
|
{
|
|
SelectItem(hChldItem);
|
|
return hChldItem;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void JxPathName(CString str,CStringArray &strArr)
|
|
{
|
|
CString strZj;
|
|
CString strFind=str;
|
|
str.TrimLeft();
|
|
str.TrimRight();
|
|
if(str==_T(""))
|
|
return;
|
|
int nIndex=strFind.Find(_T("\\"),0);
|
|
while(nIndex>=0)
|
|
{
|
|
int nLength=strFind.GetLength();
|
|
strZj=strFind.Left(nIndex);
|
|
strFind=strFind.Right(nLength-nIndex-1);
|
|
nIndex=strFind.Find(_T("\\"),0);
|
|
strArr.Add(strZj);
|
|
}
|
|
strArr.Add(strFind);
|
|
}
|
|
|
|
|
|
void CCoolTreeCtrl::SetSltDwgFile(LPCTSTR pszFolder, LPCTSTR pszDwg)
|
|
{
|
|
CString sFolder(_T("")), sDwg(_T(""));
|
|
if (pszFolder) sFolder = pszFolder;
|
|
if (pszDwg) sDwg = pszDwg;
|
|
|
|
int pos = sDwg.ReverseFind(_T('.'));
|
|
if (pos != -1) // 有后缀,去掉
|
|
{
|
|
sDwg = sDwg.Left(pos);
|
|
}
|
|
|
|
HTREEITEM hRootItem = GetRootItem(), hItem(NULL);
|
|
|
|
CString sItem(_T(""));
|
|
while (hRootItem)
|
|
{
|
|
sItem = GetItemText(hRootItem);
|
|
hItem = viewItemByText(hRootItem, sFolder);
|
|
if (hItem)
|
|
{
|
|
Expand(hItem, TVE_EXPAND);
|
|
Select(hItem, TVGN_FIRSTVISIBLE);
|
|
hItem = viewItemByText(hItem, sDwg);
|
|
if (hItem)
|
|
{
|
|
Expand(hItem, TVE_EXPAND);
|
|
Select(hItem, TVGN_FIRSTVISIBLE);
|
|
}
|
|
Invalidate();
|
|
SetRedraw(TRUE);
|
|
break;
|
|
}
|
|
hRootItem=GetNextItem(hRootItem,TVGN_NEXT);
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
void CCoolTreeCtrl::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
|
Invalidate();
|
|
SetRedraw(TRUE);
|
|
*pResult = 0;
|
|
}
|
|
|
|
|
|
void CCoolTreeCtrl::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
|
|
SetRedraw(FALSE);
|
|
*pResult = 0;
|
|
}
|
|
*/
|
|
|
|
void CCoolTreeCtrl::OnPaint()
|
|
{
|
|
CTreeCtrl::OnPaint();
|
|
return;
|
|
CPaintDC dc(this);
|
|
|
|
// dc.SetBkColor(RGB(255,255,255));
|
|
CRect rcclient;
|
|
GetClientRect(&rcclient);
|
|
|
|
CDC memdc;
|
|
memdc.CreateCompatibleDC(&dc);
|
|
CBitmap bitmap;
|
|
bitmap.CreateCompatibleBitmap(&dc, rcclient.Width(), rcclient.Height());
|
|
memdc.SelectObject( &bitmap );
|
|
|
|
CWnd::DefWindowProc(WM_PAINT, (WPARAM)memdc.m_hDC , 0);
|
|
|
|
CDC maskdc;
|
|
maskdc.CreateCompatibleDC(&dc);
|
|
CBitmap maskbitmap;
|
|
maskbitmap.CreateBitmap(rcclient.Width(), rcclient.Height(), 1, 1, NULL);
|
|
maskdc.SelectObject( &maskbitmap );
|
|
maskdc.BitBlt( 0, 0, rcclient.Width(), rcclient.Height(), &memdc,
|
|
rcclient.left, rcclient.top, SRCCOPY);
|
|
|
|
CBrush brush;
|
|
brush.CreatePatternBrush(&m_bitmap);
|
|
dc.FillRect(rcclient, &brush);
|
|
|
|
memdc.SetBkColor(RGB(0,0,0));
|
|
memdc.SetTextColor(RGB(255,255,255));
|
|
memdc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(),
|
|
&maskdc, rcclient.left, rcclient.top, SRCAND);
|
|
|
|
dc.SetBkColor(RGB(255,255,255));
|
|
dc.SetTextColor(RGB(0,0,0));
|
|
dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(),
|
|
&maskdc, rcclient.left, rcclient.top, SRCAND);
|
|
|
|
dc.BitBlt(rcclient.left, rcclient.top, rcclient.Width(), rcclient.Height(),
|
|
&memdc, rcclient.left, rcclient.top,SRCPAINT);
|
|
|
|
brush.DeleteObject();
|
|
|
|
}
|
|
|
|
void CCoolTreeCtrl::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
|
|
{
|
|
// 确保在移动滚动条时更新
|
|
//Invalidate();
|
|
CTreeCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCoolTreeCtrl::OnDeldir()
|
|
{
|
|
// TODO: Add your command handler code here
|
|
|
|
}
|
|
|
|
void CCoolTreeCtrl::OnRButtonDown(UINT nFlags, CPoint point)
|
|
{
|
|
// TODO: Add your message handler code here
|
|
/* UINT uFlags;
|
|
CString sSubPath;
|
|
HTREEITEM hOldItem;
|
|
acedGetAcadDwgView()->SetFocus(); //很奇怪一定要先让CAD视图获得焦点
|
|
CDockDialog *pDlg1=(CDockDialog*)GetParent()->GetParent()->GetParent()->GetParent();
|
|
HTREEITEM hTreeItem=(pDlg1->getTreeCtrl()).HitTest(point,&uFlags);
|
|
(pDlg1->getTreeCtrl()).ClientToScreen(&point);
|
|
HTREEITEM hParentItem;
|
|
hOldItem=hTreeItem;
|
|
TVITEM item;
|
|
TCHAR szText[1024];
|
|
item.hItem = hOldItem;
|
|
item.mask = TVIF_TEXT | TVIF_HANDLE;
|
|
item.pszText = szText;
|
|
item.cchTextMax = 1024;
|
|
(pDlg1->getTreeCtrl()).GetItem(&item);
|
|
int nImage;
|
|
int nSelectedImage;
|
|
if(hTreeItem!=NULL)
|
|
{
|
|
BOOL bRet=(pDlg1->getTreeCtrl()).SelectItem(hTreeItem);
|
|
hParentItem=(pDlg1->getTreeCtrl()).GetParentItem(hTreeItem);
|
|
(pDlg1->getTreeCtrl()).GetItemImage(hTreeItem, nImage, nSelectedImage);
|
|
CMenu menu;
|
|
menu.LoadMenu(IDR_MENU3);
|
|
if(nImage==0&&nSelectedImage==1) //文件佳
|
|
{
|
|
if(hParentItem==NULL)
|
|
{
|
|
(menu.GetSubMenu(0))->RemoveMenu(ID_DELDIR,MF_REMOVE|MF_BYCOMMAND);
|
|
}
|
|
|
|
//(menu.GetSubMenu(0))->RemoveMenu(ID_NEWFILE,MF_REMOVE|MF_BYCOMMAND);
|
|
(menu.GetSubMenu(0))->RemoveMenu(ID_DELFILE,MF_REMOVE|MF_BYCOMMAND);
|
|
}
|
|
else if(nImage==3&&nSelectedImage==4)
|
|
{
|
|
(menu.GetSubMenu(0))->RemoveMenu(ID_NEWDIR,MF_REMOVE|MF_BYCOMMAND);
|
|
(menu.GetSubMenu(0))->RemoveMenu(ID_DELDIR,MF_REMOVE|MF_BYCOMMAND);
|
|
(menu.GetSubMenu(0))->RemoveMenu(ID_NEWFILE,MF_REMOVE|MF_BYCOMMAND);
|
|
}
|
|
CString strItemText=(pDlg1->getTreeCtrl()).GetItemText(hTreeItem);
|
|
//if(strItemText=="用户图库")
|
|
// GetDlgItem(ID_DELDIR)->EnableWindow(FALSE);
|
|
while(hParentItem!=NULL&&strItemText!="用户图库")
|
|
{
|
|
hTreeItem=hParentItem;
|
|
sSubPath=strItemText+"\\"+sSubPath;
|
|
hParentItem=(pDlg1->getTreeCtrl()).GetParentItem(hTreeItem);
|
|
strItemText=(pDlg1->getTreeCtrl()).GetItemText(hTreeItem);
|
|
}
|
|
sSubPath=strItemText+"\\"+sSubPath;
|
|
g_pDockPane->m_sCurSltPath=g_pDockPane->m_sSoftPath+sSubPath;
|
|
if(strItemText=="用户图库")
|
|
{
|
|
BOOL bRet=(pDlg1->getTreeCtrl()).SelectItem(hOldItem);
|
|
g_pDockPane->m_hTreeItem=hOldItem;
|
|
|
|
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
|
|
}
|
|
} */
|
|
// CTreeCtrl::OnRButtonDown(nFlags, point);
|
|
}
|
|
|
|
|