// (C) Copyright 2002-2005 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
//-----------------------------------------------------------------------------
//----- MDB.h : Declaration of the Cad_DockControlBar
//-----------------------------------------------------------------------------
#pragma once
#include "..\..\resource1.h"
#include "..\..\Resource1.h"
#include "..\..\编程2013\cad2012+arx\函数库\function_for_cad\function_for_cad.h"
#include "..\..\编程2013\系统头文件\list_head.h"
#include "..\..\编程2013\vc控件\CTabCtrlEx\CTabCtrlEx.h"
#include "..\系统头文件\list_head.h"
#include "..\..\编程2013\cad捕获显示\AcEdInputPointMonitor_xtcow.h"
//-----------------------------------------------------------------------------
using namespace xtcow;
namespace xtcow
{
class Cad_DockControlBar_tab : public CAcUiDockControlBar
{
DECLARE_DYNAMIC (Cad_DockControlBar_tab)
public:
//用来记录已经加载过的数据库@记录是否已经生成过Cad_DockControlBar_tab实例
//可能是多余,但习惯这样做了
static std::vector<AcApDocument *> store_workingDatabase;
static Cad_DockControlBar_tab *pdb;
//AcEdInputPointMonitor类,用来显示鼠标指向的对象属性
class AcApDocManagerReactor_tab : public AcApDocManagerReactor
{
public:
AcApDocManagerReactor_tab()
{
acDocManager->addReactor(this);
}
~AcApDocManagerReactor_tab()
{
acDocManager->removeReactor(this);
}
void documentCreated(AcApDocument* pDocCreating)
{
Cad_DockControlBar_tab::add_Cad_DockControlBar_tab(pDocCreating);
m_dataMap.insert(std::make_pair(pDocCreating,1));
}
void documentToBeDestroyed( AcApDocument *pDoc )
{
Cad_DockControlBar_tab::delete_Cad_DockControlBar_tab(pDoc);
m_dataMap.erase(pDoc);
}
void documentBecameCurrent(AcApDocument*pActivatedDoc )
{
std::vector<AcApDocument * > ::iterator find=std::find(Cad_DockControlBar_tab::store_workingDatabase.begin(),Cad_DockControlBar_tab::store_workingDatabase.end(),pActivatedDoc);
if (Cad_DockControlBar_tab::m_TabCtrl!=0\
&&Cad_DockControlBar_tab::pdb!=0\
&&find!=store_workingDatabase.end())
{
Cad_DockControlBar_tab::active_spetial_Document_tab(pActivatedDoc);
}
}
void documentLockModeWillChange(AcApDocument*curDoc ,AcAp::DocLockMode myCurrentMode,AcAp::DocLockMode myNewMode,
AcAp::DocLockMode currentMode,const ACHAR* pGlobalCmdName)
{
if (CString(pGlobalCmdName)!=_T("#SAVEAS"))
{
return ;
}
std::vector<AcApDocument * > ::iterator find=std::find(Cad_DockControlBar_tab::store_workingDatabase.begin(),Cad_DockControlBar_tab::store_workingDatabase.end(),curDoc);
if (find!=store_workingDatabase.end())
{
TCITEM item;
item.mask=TCIF_TEXT;
CString linshi=get_database_tile_name(curDoc->database()).c_str();
item.pszText=linshi.GetBuffer(linshi.GetLength());
pdb->m_TabCtrl->SetItem(find-Cad_DockControlBar_tab::store_workingDatabase.begin(),&item);
}
}
private:
std::map<AcApDocument*,int> m_dataMap;
};
public:
Cad_DockControlBar_tab ();
virtual ~Cad_DockControlBar_tab ();
virtual BOOL Create (CWnd *pParent, LPCTSTR lpszTitle) ;
//重store_workingDatabase中删除对应文档记录
static void delete_Cad_DockControlBar_tab(AcApDocument*pActivatedDoc=curDoc());
static void add_Cad_DockControlBar_tab(AcApDocument*pActivatedDoc=curDoc());
static void show_Cad_DockControlBar_tab();
static void active_spetial_Document_tab(AcApDocument* pDoc);
protected:
static CTabCtrlEx *m_TabCtrl;
AcApDocManagerReactor_tab Mgr_for_tab_;
double fangda_beishu;
afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct) ;
virtual void SizeChanged (CRect *lpRect, BOOL bFloating, int flags) ;//控制子控件大小
LRESULT OnTab(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
} ;
}
// (C) Copyright 2002-2005 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//-----------------------------------------------------------------------------
//----- MDB.cpp : Implementation of Cad_DockControlBar
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "..\..\Resource1.h"
#include "..\..\resource1.h"
#include "Cad_DockControlBar_tab.h"
#include "..\..\编程2013\cad2012+arx\cad系统操作\Cad_Block\Cad_Block.h"
#include "..\..\编程2013\cad2012+arx\画图\Cad_Line_Gon\Cad_Line_Gon.h"
#include "..\..\编程2013\cad2012+arx\函数库\function_for_cad\function_for_cad.h"
using namespace xtcow;
namespace xtcow
{
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC (Cad_DockControlBar_tab, CAcUiDockControlBar)
BEGIN_MESSAGE_MAP(Cad_DockControlBar_tab, CAcUiDockControlBar)
ON_WM_CREATE()
ON_MESSAGE(WM_Tab_change,OnTab) // 映射添加到这里
ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
Cad_DockControlBar_tab * Cad_DockControlBar_tab::pdb = NULL;
CTabCtrlEx *Cad_DockControlBar_tab::m_TabCtrl = NULL;
std::vector<AcApDocument*> Cad_DockControlBar_tab::store_workingDatabase;
Cad_DockControlBar_tab::Cad_DockControlBar_tab (): CAcUiDockControlBar()
{
m_TabCtrl=new CTabCtrlEx;
};
Cad_DockControlBar_tab::~Cad_DockControlBar_tab ()
{
acedGetAcadFrame()->RemoveControlBar(this);
if(store_workingDatabase.size()!=0)
{
for (;;)
{
std::vector<AcApDocument * > ::iterator find=store_workingDatabase.begin();
if (find!=store_workingDatabase.end())
{
Cad_DockControlBar_tab::delete_Cad_DockControlBar_tab(*find);
}
else
{
break;
}
}
}
//用来记录已经加载过的数据库
store_workingDatabase.clear();
pdb=0;
delete m_TabCtrl;
m_TabCtrl=0;
};
//每当关闭一个cad文档调用一次,重store_workingDatabase中删除对应文档记录
void Cad_DockControlBar_tab::delete_Cad_DockControlBar_tab(AcApDocument*pActivatedDoc)
{
std::vector<AcApDocument * > ::iterator find=std::find(store_workingDatabase.begin(),store_workingDatabase.end(),pActivatedDoc);
if (find!=store_workingDatabase.end())
{
pdb->m_TabCtrl->DeleteItem(find-store_workingDatabase.begin());
AcEdInputPointMonitor_xtcow::delete_AcEdInputPointMonitor_xtcow_in_curDoc(pActivatedDoc);//或用来手动清除
store_workingDatabase.erase(find);
}
if (store_workingDatabase.size()==0)
{
if (pdb!=0)
{
pdb->ShowWindow(0);
}
}
}
void Cad_DockControlBar_tab::add_Cad_DockControlBar_tab(AcApDocument*pActivatedDoc)//
{
if (pdb==0)
{
pdb=new Cad_DockControlBar_tab;
if(pdb==0)
{
TRACE0(L"ControlBar_tab\n");
return ;
}
if(!pdb->Create (acedGetAcadFrame(),L"y"))
{
TRACE0(L"Failed to create DlgBar\n");
return ;
}
AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator();
AcApDocument* pDoc = NULL;
while(!iter->done()) //保护措施
{//记录还剩哪些AcDbDatabase
pDoc= iter->document();
std::vector<AcApDocument*> ::iterator find=std::find(store_workingDatabase.begin(),store_workingDatabase.end(),pDoc);
if(find==store_workingDatabase.end())//未加入store_workingDatabase//有点多余
{
store_workingDatabase.insert(store_workingDatabase.begin(),pDoc);
if (pDoc->isReadOnly())
{
pdb->m_TabCtrl->InsertItem(0,get_database_tile_name(pDoc->database()).append(_T(":只读")).c_str());
}
else
{
pdb->m_TabCtrl->InsertItem(0,get_database_tile_name(pDoc->database()).c_str());
}
AcEdInputPointMonitor_xtcow::build_AcEdInputPointMonitor_xtcow_in_curDoc(pDoc);
}
iter->step();
}
delete iter;
//
Cad_DockControlBar_tab::active_spetial_Document_tab(curDoc());
//
pdb->EnableDocking(CBRS_ALIGN_TOP );
CPoint pt(0,10);
acedGetAcadFrame()->FloatControlBar(pdb,pt);
acedGetAcadFrame()->DockControlBar (pdb, AFX_IDW_DOCKBAR_TOP);
acedGetAcadFrame()->ShowControlBar(pdb, TRUE, FALSE);
acedGetAcadFrame()->RecalcLayout();
}
else
{//
std::vector<AcApDocument*> ::iterator find=std::find(store_workingDatabase.begin(),store_workingDatabase.end(),pActivatedDoc);
if (find==store_workingDatabase.end())
{
store_workingDatabase.insert(store_workingDatabase.begin(),pActivatedDoc);
if (curDoc()->isReadOnly())
{
pdb->m_TabCtrl->InsertItem(0,get_database_tile_name(pActivatedDoc->database()).append(_T(":只读")).c_str());
}
else
{
pdb->m_TabCtrl->InsertItem(0,get_database_tile_name(pActivatedDoc->database()).c_str());
}
AcEdInputPointMonitor_xtcow::build_AcEdInputPointMonitor_xtcow_in_curDoc(pActivatedDoc);
Cad_DockControlBar_tab::active_spetial_Document_tab(pActivatedDoc);
}
show_Cad_DockControlBar_tab();
}
}
void Cad_DockControlBar_tab::show_Cad_DockControlBar_tab()//
{
if (pdb!=0)
{
pdb->EnableDocking(CBRS_ALIGN_TOP);
CPoint pt(0,10);
acedGetAcadFrame()->FloatControlBar(pdb,pt);
acedGetAcadFrame()->DockControlBar (pdb, AFX_IDW_DOCKBAR_TOP);
acedGetAcadFrame()->ShowControlBar(pdb, TRUE, FALSE);
acedGetAcadFrame()->RecalcLayout();
pdb->ShowWindow(1);
}
}
void Cad_DockControlBar_tab::active_spetial_Document_tab(AcApDocument* pDoc)
{
std::vector<AcApDocument * > ::iterator find=std::find(store_workingDatabase.begin(),store_workingDatabase.end(),pDoc);
if (find!=store_workingDatabase.end())
{
pdb->m_TabCtrl->SetCurSel(find-store_workingDatabase.begin());
}
}
LRESULT Cad_DockControlBar_tab::OnTab(WPARAM wParam, LPARAM lParam)
{
if (lParam==0)
{
int nCurSel = m_TabCtrl->GetCurSel();
acDocManager->activateDocument(store_workingDatabase[nCurSel]);
}
return true;
}
BOOL Cad_DockControlBar_tab::Create (CWnd *pParent, LPCTSTR lpszTitle)
{
double y=GetSystemMetrics(SM_CYSCREEN);
double X=GetSystemMetrics(SM_CXSCREEN);
fangda_beishu=y/768;
CRect Rect;
Rect.SetRect(0,0,0,fangda_beishu*26);
if ( !CAcUiDockControlBar::Create (pParent,lpszTitle,0,WS_VISIBLE |CBRS_SIZE_FIXED ,Rect))
return (FALSE) ;
return (TRUE) ;
}
//----- created by calling the Create or CreateEx member function
int Cad_DockControlBar_tab::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
if ( CAcUiDockControlBar::OnCreate (lpCreateStruct) == -1 )
return (-1) ;
//
//对话框设定标题
SetWindowText(_T("标签栏_xtcow"));
CRect Rect=GetInsideRect();
//
m_TabCtrl->Create(TCS_SINGLELINE|TCS_FIXEDWIDTH,Rect,this, IDC_TAB1_for_cad_tab);
//
m_TabCtrl->SetBkgndColor(::GetSysColor(COLOR_3DFACE));
CTabCtrlEx::EnableCustomLook(TRUE,ETC_FLAT| ETC_COLOR|ETC_SELECTION|ETC_BACKTABS|ETC_GRADIENT);
m_TabCtrl->EnableDraw(BTC_ALL);
m_TabCtrl->ShowWindow(1);
return (0) ;
}
void Cad_DockControlBar_tab::SizeChanged (CRect *lpRect, BOOL bFloating, int flags)
{//相应大小变化的
if(m_TabCtrl!=0)
{
lpRect->bottom=fangda_beishu*26;
m_TabCtrl->MoveWindow(lpRect,1);
}
}
}