Author Topic: Info About CAdUiDockControlBar Class ?  (Read 6251 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Re: Info About CAdUiDockControlBar Class ?
« Reply #15 on: July 08, 2006, 09:44:30 PM »
As always Mick;

Thanks!

Here are some code of what I am doing/playing... it has been a lot of fun.  :-)

In the custom palette class derivation I put:

File = Cpalette.h
Code: [Select]
public:

// tree control
CTreeCtrl *pTreeCtrl;

// tooltips control
CToolTipCtrl m_tooltip;

// for the tooltips
void RelayEvent(UINT message, WPARAM wParam, LPARAM lParam);
BOOL PreTranslateMessage(MSG* pMsg);

afx_msg void OnContextMenu(CWnd*, CPoint point);

File = Cpalette.cpp

Code: [Select]
// map to hold all the tooltips strings
typedef CMap< HTREEITEM,HTREEITEM&,CString,CString& > TipMap;
extern TipMap tooltipMap;

In one function to add the controls I place:
Code: [Select]
tooltipMap.RemoveAll(); // removing first the previous tooltips

// add the tree control
pTreeCtrl = new CTreeCtrl;
CRect rect;
GetClientRect(&rect);
rect.DeflateRect(2, 8, 2, 2);
// create the tree
if (!pTreeCtrl->Create(WS_CHILD | WS_VISIBLE |
TVS_HASLINES | TVS_HASBUTTONS |
TVS_LINESATROOT, rect,
this, ID_INSTANTBARTREECTRL))
{
acdbFail(_T("\nTree control fail!.\n"));
}
// tree style
pTreeCtrl->ModifyStyleEx(0, WS_EX_CLIENTEDGE);
// sample layers data
AcDbLayerTable* LayerTable = NULL;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(LayerTable, AcDb::kForRead);
AcDbLayerTableIterator* pLayerIterator;
LayerTable->newIterator(pLayerIterator);
AcDbLayerTableRecord* LayerTableRecord;
char *pLayerName;
CImageList pImageList;
CBitmap bitmap;
// tree images setup
pImageList.Create(16, 16, ILC_COLORDDB | ILC_MASK, 0, 0);
bitmap.LoadBitmap(IDB_TREECTRL);
pImageList.Add(&bitmap, RGB(255, 0, 255));
pTreeCtrl->SetImageList(&pImageList, TVSIL_STATE);
bitmap.DeleteObject();
pImageList.Detach();
// iterate all layers
for(pLayerIterator->start() ; !pLayerIterator->done() ; pLayerIterator->step())
{
pLayerIterator->getRecord(LayerTableRecord, AcDb::kForRead);
// layer name
LayerTableRecord->getName(pLayerName);
// insert the layer name as main node
HTREEITEM nodeLayer = pTreeCtrl->InsertItem(pLayerName);
tooltipMap[nodeLayer] = pLayerName; // Set the tool tip text of the item.

// setup the state and the image
pTreeCtrl->SetItemState(nodeLayer,INDEXTOSTATEIMAGEMASK(1), TVIS_STATEIMAGEMASK);
// returns an AcCmColor object
// that contains the color value of the layer.
//AcCmColor colour = LayerTableRecord->color();

// returns true if and only if the layer is frozen.
// If the layer is thawed, then false is returned.
if (LayerTableRecord->isFrozen())
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Frozen"), nodeLayer);
tooltipMap[nodeChild] = "Frozen";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(3), TVIS_STATEIMAGEMASK);
}
else
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Thawed"), nodeLayer);
tooltipMap[nodeChild] = "Thawed";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(2), TVIS_STATEIMAGEMASK);
}

// returns true if and only if the layer is locked.
// If the layer is unlocked, then false is returned.
if (LayerTableRecord->isLocked())
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Locked"), nodeLayer);
tooltipMap[nodeChild] = "Locked";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(6), TVIS_STATEIMAGEMASK);
}
else
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Unlocked"), nodeLayer);
tooltipMap[nodeChild] = "Unlocked";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(7), TVIS_STATEIMAGEMASK);
}

// returns true if the layer is plottable.
// If the layer is not plottable, then false is returned.
if (LayerTableRecord->isPlottable())
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Plottable"), nodeLayer);
tooltipMap[nodeChild] = "Plottable";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(8), TVIS_STATEIMAGEMASK);
}
else
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Unplottable"), nodeLayer);
tooltipMap[nodeChild] = "Unplottable";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(9), TVIS_STATEIMAGEMASK);
}

// returns true if the layer is off.
// If the layer is on, then false is returned.
if (LayerTableRecord->isOff())
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("Off"), nodeLayer);
tooltipMap[nodeChild] = "Off";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(5), TVIS_STATEIMAGEMASK);
}
else
{
HTREEITEM nodeChild = pTreeCtrl->InsertItem(_T("On"), nodeLayer);
tooltipMap[nodeChild] = "On";
pTreeCtrl->SetItemState(nodeChild, INDEXTOSTATEIMAGEMASK(4), TVIS_STATEIMAGEMASK);
}
LayerTableRecord->close();
acutDelString(pLayerName);
}
delete pLayerIterator;
LayerTable->close();

m_tooltip.Create(this);
m_tooltip.Activate(TRUE);
m_tooltip.AddTool(GetDlgItem(ID_INSTANTBARTREECTRL), "Layer Explorer"); // adding my tooltips!

Code: [Select]
BOOL CMyPalette::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message == WM_MOUSEMOVE && pMsg->hwnd == pTreeCtrl->m_hWnd)
{
CPoint point(LOWORD(pMsg->lParam), HIWORD(pMsg->lParam));
HTREEITEM hItem = pTreeCtrl->HitTest(point);
if(hItem != NULL)
{
CString text = tooltipMap[hItem];
m_tooltip.UpdateTipText(text, pTreeCtrl);
m_tooltip.RelayEvent(pMsg);
}
}
return FALSE;
}

Code: [Select]
void CMyPalette::OnContextMenu(CWnd* pWnd, CPoint point)
{
if (pWnd != pTreeCtrl)
{
CWnd::OnContextMenu(pWnd, point);
return;
}
CPoint CurPos;
UINT nFlags;
GetCursorPos(&CurPos);
ScreenToClient(&CurPos);
HTREEITEM hItemClk = pTreeCtrl->HitTest(CurPos, &nFlags);
pTreeCtrl->SelectItem(hItemClk);

CMenu menu;
CMenu* pContextMenu;
menu.LoadMenu(IDR_MENU1);
ASSERT(menu);
CString txt = "";

if ((hItemClk != NULL) && (TVHT_ONITEM & nFlags))
{
pTreeCtrl->Select(hItemClk, TVGN_CARET);
txt = pTreeCtrl->GetItemText(hItemClk);
}

pContextMenu = menu.GetSubMenu(0);
ASSERT(pContextMenu);

// delete previous items
// here I have to do the following since I did not found a better way
pContextMenu->DeleteMenu(0, MF_BYPOSITION);
pContextMenu->DeleteMenu(1, MF_BYPOSITION);
pContextMenu->DeleteMenu(0, MF_BYPOSITION);
pContextMenu->DeleteMenu(1, MF_BYPOSITION);
pContextMenu->DeleteMenu(0, MF_BYPOSITION);
// to here

pContextMenu->AppendMenu(MF_STRING, 0, (LPCTSTR)txt.GetString());
pContextMenu->AppendMenu(MF_SEPARATOR, 0, _T(""));

pContextMenu->AppendMenu(MF_STRING, 0, _T("Menu Property1"));
pContextMenu->AppendMenu(MF_STRING, 0, _T("Menu Property2"));
pContextMenu->AppendMenu(MF_STRING, 0, _T("Menu Property3"));
pContextMenu->AppendMenu(MF_STRING, 0, _T("Menu Property4"));
pContextMenu->AppendMenu(MF_STRING, 0, _T("Menu Property5"));

CMenu menuPopup;
menuPopup.CreatePopupMenu();
ASSERT(menuPopup);

menuPopup.AppendMenu(MF_STRING | MF_ENABLED, 0, _T("PopupMenu Item1"));
menuPopup.AppendMenu(MF_STRING | MF_ENABLED, 0, _T("PopupMenu Item2"));
menuPopup.AppendMenu(MF_STRING | MF_ENABLED, 0, _T("PopupMenu Item3"));
menuPopup.AppendMenu(MF_STRING | MF_ENABLED, 0, _T("PopupMenu Item4"));

pContextMenu->AppendMenu(MF_POPUP | MF_ENABLED, (UINT)menuPopup.Detach(), _T("&Open PopupMenu"));

pContextMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this, 0);
pContextMenu->Detach();

menu.Detach();
}
« Last Edit: July 08, 2006, 09:51:47 PM by LE »

LE

  • Guest
Re: Info About CAdUiDockControlBar Class ?
« Reply #16 on: July 09, 2006, 07:01:43 PM »
Mick;

And what approach do you use to update the data (controls) for your palette? [OnSetActive ?] - when switching documents.

le

MickD

  • Gator
  • Posts: 3286
  • (x-in)->[process]->(y-out)
Re: Info About CAdUiDockControlBar Class ?
« Reply #17 on: July 09, 2006, 07:14:13 PM »
I haven't gone that far with it yet Luis, at the moment I'm only interested in what's in my master model drg. The button I use to load the form only works in the current active document which is all I need at the moment. This way I can get objects from the master model and import them into a different document.
There are many document event handlers to override though so I imagine it wouldn't be too hard.
Debugging:
Being the detective in a crime movie where you're also the murderer.

“Someone's sitting in the shade today because someone planted a tree a long time ago.”
- Warren Buffet

LE

  • Guest
Re: Info About CAdUiDockControlBar Class ?
« Reply #18 on: July 09, 2006, 07:30:16 PM »
I am using a docmanager reactor . . .

Code: [Select]
class CDocReactor : public AcApDocManagerReactor
{
public:
virtual void  documentActivated(AcApDocument* pDoc);
};

Code: [Select]
template <class T> class AsdkDataManager : public AcApDocManagerReactor
{
public:
    AsdkDataManager()
    {
        acDocManager->addReactor(this);
    }
    ~AsdkDataManager()
    {
        acDocManager->removeReactor(this);
    }
    virtual void documentToBeDestroyed( AcApDocument *pDoc )
    {
        m_dataMap.erase(pDoc);
    }
   
    T& docData(AcApDocument* pDoc)
    {
        std::map<AcApDocument*, T>::iterator i;
        i = m_dataMap.find(pDoc);
        if (i==m_dataMap.end())
            return  m_dataMap[ pDoc ];
        else
            return (*i).second;
    }
    T& docData()
    {
        return docData(acDocManager->curDocument());
    }
   
private:
    std::map<AcApDocument*, T> m_dataMap;
};

Code: [Select]
static CDocReactor* gpDocReactor = NULL;

void CDocReactor::documentActivated(AcApDocument* pDoc)
{
// my update function for the tree control data
}

Code: [Select]
void InitApplication()
{
gpDocReactor = new CDocReactor();
acDocManager->addReactor(gpDocReactor);

. . .
}

Code: [Select]
void UnloadApplication()
{
if(gpDocReactor)
{
acDocManager->removeReactor(gpDocReactor);
delete gpDocReactor;
}

. . .
}

MickD

  • Gator
  • Posts: 3286
  • (x-in)->[process]->(y-out)
Re: Info About CAdUiDockControlBar Class ?
« Reply #19 on: July 09, 2006, 09:48:26 PM »
That'll do it :)
The .net equivalent for reference is Autodesk.AutoCAD.ApplicationServices.DocumentCollection events methods which wrap these reactors.
Debugging:
Being the detective in a crime movie where you're also the murderer.

“Someone's sitting in the shade today because someone planted a tree a long time ago.”
- Warren Buffet