Files
envi-code/SourceCode/Code2026/tg_shs/shs_TwtKernal/SlideStatic.cpp
T
2026-09-28 15:28:50 +08:00

435 lines
12 KiB
C++

// SlideStatic.cpp : implementation file
//
#include "stdafx.h"
//#include <arxtools.h>
#include "SlideStatic.h"
//#include "tapi.h"
#include "teldef.h"
//#include "twtdef.h"
#include "TGAs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSlideStatic
CSlideStatic::CSlideStatic(const TCHAR* szTKName, const TCHAR* szType)
{
m_csTKName = szTKName;
m_csTKType = szType;
m_iRowNum= 4;
m_iColNum = 6;
m_iIndex = 0;
m_iPage = 0;
m_iCurPos = 0;
EndOfFile = TRUE;
m_bOnlyCurType = FALSE;
m_csTKAllName = g_sDwbPath + m_csTKName + _T(".tk");
m_csCurDwbName = g_sDwbPath + m_csTKName + _T(".dwb");
m_lstSlide.RemoveAll();
if(GetTypeAllRecord(m_csTKName, m_csTKType, m_lstSlide) == FALSE) {
AfxMessageBox(_T("查询图库管理系统时出错!"));
return;
}
UpdateRecord();
}
CSlideStatic::CSlideStatic()
{
m_csTKName = _T("");
m_csTKType = _T("");
m_iRowNum= 4;
m_iColNum = 6;
m_iIndex = 0;
m_iPage = 0;
m_iCurPos = 0;
EndOfFile = TRUE;
m_bOnlyCurType = FALSE;
}
void CSlideStatic::ResetSource(const TCHAR* szTKName, const TCHAR* szType, int iIndex, int iPage, int iCurPos)
{
EnableToolTips(TRUE);
m_csTKName = szTKName;
m_csTKType = szType;
m_iIndex = iIndex;
m_iPage = iPage;
m_iCurPos = iCurPos;
EndOfFile = TRUE;
m_csTKAllName = g_sDwbPath + m_csTKName + _T(".tk");
m_csCurDwbName = g_sDwbPath + m_csTKName + _T(".dwb");
m_lstSlide.RemoveAll();
if(m_csTKType == _T("用户自定义")){ //2008-5-11 sr 根据邓工浩城建议增加用户自定义
CodeBase db;
db.read_only = 1;
CString sType, sName;
CString csUserName = g_csSysPath + _T("CustomBlkLib.dbf");
if(FindFile(csUserName)){
XDbfTable *pTable2 = db.Open(csUserName);
if(!pTable2) return;
pTable2->MoveFirst();
while(!pTable2->IsEOF()) {
GET_FIELD(pTable2, _T("type"), sType);
GET_FIELD(pTable2, _T("name"), sName);
if((sType == szTKName)) {
if(!IsTgBlkExist((const TCHAR*)sName)){
pTable2->MoveNext();
continue;
}
CString csTk, csRecord;
SplitBlkStr((const TCHAR*)sName, csTk, csRecord);
CString csTmpTKName = g_sDwbPath + csTk + _T(".tk");
if((csTk != _T("")) && (csRecord != _T(""))) {
CBlockStruct Blk;
Blk.m_csTKName = csTmpTKName;
Blk.m_csDesName = GetBlkDesName(csRecord, csTmpTKName);
Blk.m_csRecord = csRecord;
m_lstSlide.InsertAfter(m_lstSlide.GetTailPosition(), Blk); //在链表尾插入 块 结构
}
}
pTable2->MoveNext();
}
}
}
else if(GetTypeAllRecord(m_csTKName, m_csTKType, m_lstSlide, m_bOnlyCurType) == FALSE) {
AfxMessageBox(_T("查询图库管理系统时出错!"));
return;
}
if(m_iIndex == -1 && m_csCurRecord != _T("")){
int i=-1;
XString xsTKFile, xsDefaultItem;
SplitSlbName(m_csCurRecord, xsTKFile, xsDefaultItem);
CString csTmp;
csTmp = xsDefaultItem;
POSITION pos = m_lstSlide.GetHeadPosition();
while(pos != NULL)
{
i++;
CBlockStruct bsBlk = m_lstSlide.GetNext(pos);
if(csTmp == bsBlk.m_csRecord){
m_iIndex = i;
m_iPage = m_iIndex / (m_iColNum * m_iRowNum);
m_iCurPos = m_iIndex - (m_iColNum * m_iRowNum)*m_iPage;
break;
}
}
}
UpdateRecord();
Invalidate(TRUE);
UpdateWindow();
}
CSlideStatic::~CSlideStatic()
{
}
BEGIN_MESSAGE_MAP(CSlideStatic, CStatic)
//{{AFX_MSG_MAP(CSlideStatic)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSlideStatic message handlers
void CSlideStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
GetWindowRect(m_rectStatic);
ScreenToClient(m_rectStatic);
HBRUSH hSysBru = GetSysColorBrush(COLOR_3DFACE);
CBrush *pSysBru = CBrush::FromHandle(hSysBru);
dc.FillRect(&m_rectStatic, pSysBru);
dc.FrameRect(&m_rectStatic, pSysBru);
//计算容器左上单个幻灯片的坐标
m_rectLeftUpSlide.SetRect(m_rectStatic.left,m_rectStatic.top,
m_rectStatic.left + (int)((double)(m_rectStatic.Width() - (m_iColNum-1) * 3) /
(double)m_iColNum),
m_rectStatic.top + (int)((double)(m_rectStatic.Height() - (m_iRowNum-1) * 3) /
(double)m_iRowNum));
m_iIndex = 0; //每次从头开始搜索幻灯片
EndOfFile = 1;
CBlockStruct bsBlk; //代表链表中的一个元素
//幻灯片全路径名 幻灯片名与描述名
CString strPathSlideName,strSlideName;
POSITION pos = m_lstSlide.GetHeadPosition();
while(pos != NULL)
{
bsBlk = m_lstSlide.GetNext(pos);
strSlideName = bsBlk.m_csRecord;
strPathSlideName = bsBlk.m_csTKName;
strPathSlideName = strPathSlideName.Left(strPathSlideName.GetLength() - 3)
+ _T('(') + strSlideName + _T(')') ;
DisplayStatic(&dc, strPathSlideName);
}
//绘制边框
if(m_iCurPos < (m_iColNum * m_iRowNum) && !m_lstSlide.IsEmpty())
{
CRect recCur;
recCur.left = (m_iCurPos % m_iColNum) *
(m_rectLeftUpSlide.Width() + 3);
recCur.top = m_rectStatic.top + (m_iCurPos / m_iColNum) *
(m_rectLeftUpSlide.Height() + 3);
recCur.right = recCur.left + m_rectLeftUpSlide.Width();
recCur.bottom = recCur.top + m_rectLeftUpSlide.Height();
DrawFrame(recCur);
UpdateRecord();
}
}
void CSlideStatic::DisplayStatic(CDC *pDC, CString& strPathSlideName)
{
m_iIndex++;
EndOfFile=!(m_iIndex > ((m_iPage+1) * m_iColNum * m_iRowNum));
if(m_iIndex <= (m_iPage * (m_iColNum * m_iRowNum))
|| (m_iIndex > ((m_iPage+1) * (m_iColNum * m_iRowNum))))//仅显示范围内的幻灯片
return;
int pos = (m_iIndex-1) % (m_iColNum * m_iRowNum);
CRect rec;
//计算幻灯显示区域
rec.left = m_rectStatic.left + (pos % m_iColNum) *
(m_rectLeftUpSlide.Width() + 3);
rec.top = m_rectStatic.top + (pos / m_iColNum) *
(m_rectLeftUpSlide.Height() + 3);
rec.right = rec.left + m_rectLeftUpSlide.Width();
rec.bottom = rec.top + m_rectLeftUpSlide.Height();
m_img.InitDC(pDC, rec, GetAcadBackColor());
m_img.PaintSlide(strPathSlideName);
m_img.SetDC(NULL);
}
void CSlideStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rec;
int pos = ((point.y - m_rectStatic.top) / (m_rectLeftUpSlide.Height() + 3)) * m_iColNum
+ ((point.x- m_rectStatic.left) / (m_rectLeftUpSlide.Width() + 3));
if(pos < (m_iIndex-m_iPage*m_iRowNum*m_iColNum)){
m_iCurPos = pos;
rec.left = m_rectStatic.left + (m_iCurPos % m_iColNum) *
(m_rectLeftUpSlide.Width() + 3);
rec.top = m_rectStatic.top + (m_iCurPos / m_iColNum) *
(m_rectLeftUpSlide.Height() + 3);
rec.right = rec.left + m_rectLeftUpSlide.Width();
rec.bottom = rec.top + m_rectLeftUpSlide.Height();
if(rec.PtInRect(point)) {
EraseFrame();
DrawFrame(rec);
}
}
}
void CSlideStatic::DrawFrame(CRect& cr)
{
CDC* pDC=GetDC();
m_rectSel = cr;
pDC->Draw3dRect(cr,RGB(128,128,128),RGB(240,240,240)); //3D
cr.DeflateRect(1, 1);
pDC->Draw3dRect(cr,RGB(128,128,128),RGB(240,240,240)); //3D
cr.DeflateRect(1,1);
CBrush brush(RGB(255,0,0));
pDC->FrameRect(&cr, &brush);
cr.DeflateRect(1,1);
pDC->FrameRect(&cr, &brush);
UpdateRecord();
}
void CSlideStatic::EraseFrame()
{
CDC* pDC=GetDC();
CBrush brush(GetAcadBackColor());
pDC->FrameRect(&m_rectSel, &brush);
m_rectSel.DeflateRect(1,1);
pDC->FrameRect(&m_rectSel, &brush);
m_rectSel.DeflateRect(1,1);
pDC->FrameRect(&m_rectSel, &brush);
m_rectSel.DeflateRect(1,1);
pDC->FrameRect(&m_rectSel, &brush);
}
void CSlideStatic::UpdateRecord()
{
CBlockStruct blk;
if(!m_lstSlide.IsEmpty()){
POSITION pos = m_lstSlide.FindIndex(m_iCurPos + m_iColNum*m_iRowNum*m_iPage);
if(!pos){
m_iCurPos = 0;
pos = m_lstSlide.FindIndex(0);
}
blk = m_lstSlide.GetAt(pos);
CString csCurTKName = blk.m_csTKName;
m_csCurDesName = blk.m_csDesName;
m_csCurRecord = csCurTKName.Left(csCurTKName.GetLength() - 3)
+ _T('(') + blk.m_csRecord + _T(')') ;
}
}
//翻页
void CSlideStatic::GoPage(int iPage)
{
if(iPage>-1)
{
m_iPage = iPage;
m_iCurPos = 0;
CRect m_rect;
GetClientRect(&m_rect);
InvalidateRect(&m_rect);
UpdateRecord();
}
}
//向后翻页
void CSlideStatic::OnPgup()
{
if(m_iPage>0)
{
m_iPage--;
m_iCurPos=0;
CRect m_rect;
GetClientRect(&m_rect);
InvalidateRect(&m_rect);
UpdateRecord();
}
}
//向前翻页
void CSlideStatic::OnPgdown()
{
if(!EndOfFile)
{
m_iPage++;
m_iCurPos=0;
CRect m_rect;
GetClientRect(&m_rect);
InvalidateRect(&m_rect);
UpdateRecord();
}
}
void CSlideStatic::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rec;
int pos;
pos=((point.y - m_rectStatic.top) / (m_rectLeftUpSlide.Height() + 3)) * m_iColNum
+ ((point.x- m_rectStatic.left) / (m_rectLeftUpSlide.Width() + 3));
if(pos < (m_iIndex - m_iPage*m_iRowNum*m_iColNum)){
rec.left = m_rectStatic.left + (pos % m_iColNum) *
(m_rectLeftUpSlide.Width() + 3);
rec.top = m_rectStatic.top + (pos / m_iColNum) *
(m_rectLeftUpSlide.Height() + 3);
rec.right = rec.left + m_rectLeftUpSlide.Width();
rec.bottom = rec.top + m_rectLeftUpSlide.Height();
if( rec.PtInRect(point) && !m_lstSlide.IsEmpty() && pos < m_iColNum*m_iRowNum){
CBlockStruct blk;
blk = m_lstSlide.GetAt(m_lstSlide.FindIndex(pos + m_iColNum*m_iRowNum*m_iPage));
m_csMoveDesName = blk.m_csDesName;
CString csCurTKName = blk.m_csTKName;
m_csMoveRecord = csCurTKName.Left(csCurTKName.GetLength() - 3)
+ _T('(') + blk.m_csRecord + _T(')') ;
}
}
CStatic::OnMouseMove(nFlags, point);
}
BOOL CSlideStatic::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_MOUSEMOVE)
GetParent()->SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
else if(pMsg->message == WM_LBUTTONDOWN){
DWORD lParam = -1;
GetParent()->SendMessage(WM_LBUTTONDOWN, pMsg->wParam, lParam);
}
else if(pMsg->message == WM_LBUTTONUP){
DWORD lParam = -1;
GetParent()->SendMessage(WM_LBUTTONUP, pMsg->wParam, lParam);
}
else if(pMsg->message == WM_LBUTTONDBLCLK){
DWORD lParam = -1;
GetParent()->SendMessage(WM_LBUTTONDBLCLK, pMsg->wParam, lParam);
}
else if(pMsg->message == WM_RBUTTONDOWN){
DWORD lParam = -1;
GetParent()->SendMessage(WM_RBUTTONDOWN, pMsg->wParam, lParam);
}
return CStatic::PreTranslateMessage(pMsg);
}
INT_PTR CSlideStatic::OnToolHitTest(CPoint point,TOOLINFO*pTI)const
{
CRect rec;
int pos;
pos=((point.y - m_rectStatic.top) / (m_rectLeftUpSlide.Height() + 3)) * m_iColNum
+ ((point.x- m_rectStatic.left) / (m_rectLeftUpSlide.Width() + 3));
if(pos < (m_iIndex - m_iPage*m_iRowNum*m_iColNum)){
rec.left = m_rectStatic.left + (pos % m_iColNum) *
(m_rectLeftUpSlide.Width() + 3);
rec.top = m_rectStatic.top + (pos / m_iColNum) *
(m_rectLeftUpSlide.Height() + 3);
rec.right = rec.left + m_rectLeftUpSlide.Width();
rec.bottom = rec.top + m_rectLeftUpSlide.Height();
CPoint pt(10, 10);
rec -= pt;
if( rec.PtInRect(point) && !m_lstSlide.IsEmpty() && pos < m_iColNum*m_iRowNum){
CBlockStruct blk;
int idx = pos + m_iColNum*m_iRowNum*m_iPage;
blk = m_lstSlide.GetAt(m_lstSlide.FindIndex(idx));
CString sTip = blk.m_csDesName;
int idx1 = sTip.Find(_T("-"));
if(idx1 > 0){
sTip = sTip.Left(idx1);
}
int idx2 = sTip.Find(_T("("));
if(idx2 > 0){
sTip = sTip.Left(idx2);
}
pTI->hwnd = m_hWnd;
CRect rect;
rect.top=0;
rect.bottom=100;
pTI->rect = rec;
pTI->uId = (UINT_PTR)m_hWnd;
pTI->uFlags |=TTF_IDISHWND|TTF_NOTBUTTON|TTF_ALWAYSTIP;
pTI->lpszText=new TCHAR[256];
wsprintf(pTI->lpszText,_T("%s"),sTip);
return idx;
}
}
return -1;
}