/// Called from Message() for MSG_GETCUSTOMICON. void OnGetCustomIcon(BaseObject* op, GetCustomIconData* data) { IconData* dIcon = data->dat; BaseBitmap* bmp; LONG xoff, yoff, xdim, ydim; if (m_customIcon) { if (dIcon->bmp) { // We can not free the previous bitmap, because it leads to a // crash. We copy the custom icon bitmap to the already // present bitmap. bmp = dIcon->bmp; m_customIcon->CopyTo(bmp); } else { bmp = m_customIcon->GetClone(); } xoff = 0; yoff = 0; xdim = bmp->GetBw(); ydim = bmp->GetBh(); } else { bmp = dIcon->bmp; if (!bmp) { bmp = BaseBitmap::Alloc(); bmp->Init(64, 64); } if (GetIcon(Ocontainer, dIcon)) { dIcon->bmp->CopyTo(bmp); } xoff = dIcon->x; yoff = dIcon->y; xdim = dIcon->w; ydim = dIcon->h; } if (bmp) { // Adjust the IconData. dIcon->x = xoff; dIcon->y = yoff; dIcon->w = xdim; dIcon->h = ydim; dIcon->bmp = bmp; data->filled = true; } else { data->filled = false; } }
/// Called from Message() for MSG_DESCRIPTION_COMMAND. void OnDescriptionCommand(BaseObject* op, DescriptionCommand* cmdData) { BaseDocument* doc = op->GetDocument(); const AutoUndo au(doc); const LONG id = cmdData->id[0].id; switch (id) { case NRCONTAINER_PACKUP: ToggleProtect(op); break; case NRCONTAINER_ICON_LOAD: { if (m_protected) break; // Ask the user for an image-file. Filename flname; flname.SetDirectory(GeGetC4DPath(C4D_PATH_DESKTOP)); Bool ok = flname.FileSelect(FILESELECTTYPE_IMAGES, FILESELECT_LOAD, GeLoadString(IDS_SELECTICON)); if (ok) { // Ensure the destination bitmap is allocated. if (!m_customIcon) m_customIcon = BaseBitmap::Alloc(); else m_customIcon->FlushAll(); // If it is still null here, allocation failed. if (!m_customIcon) MessageDialog(GeLoadString(IDS_INFO_OUTOFMEMORY)); else { IMAGERESULT res = m_customIcon->Init(flname); if (res != IMAGERESULT_OK) { MessageDialog(IDS_INFO_INVALIDIMAGE); BaseBitmap::Free(m_customIcon); } else { // Scale the bitmap down to 64x64 pixels. BaseBitmap* dest = BaseBitmap::Alloc(); const LONG size = CONTAINEROBJECT_ICONSIZE; dest->Init(size, size); m_customIcon->ScaleIt(dest, 256, true, true); BaseBitmap::Free(m_customIcon); m_customIcon = dest; } } } break; } case NRCONTAINER_ICON_CLEAR: { if (m_protected) break; if (m_customIcon) { // TODO: We possibly require a flag for removing the icon // on the next MSG_GETCUSTOMICON message, because Cinema // still references this bitmap. BaseBitmap::Free(m_customIcon); } break; } } }