//stop gap method
//if the material editor becomes visible and teh material in it is not
//already wrapped we better add it. 
void CMaxMaterialCollection::OnMeditVisible()
{
	if(!m_suspendCount)
	{
		MtlBase *m = GetMtlEditInterface()->GetCurMtl();
		if(m->SuperClassID()!=MATERIAL_CLASS_ID)
			return;
		CComPtr<IMaxMaterial> pWrapper;
		FindItemKey((DWORD_PTR)(m), &pWrapper.p);
		if(!pWrapper)
		{
			MakeWrapperObject((Mtl*)m);
			FindItemKey((DWORD_PTR)(m), &pWrapper.p);
			if(pWrapper)
				AddPersistence(pWrapper);
		}
	}
}
Example #2
0
BOOL plTextureSearch::DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_ACTIVATE:
        if (LOWORD(wParam) == WA_INACTIVE)
            plMaxAccelerators::Enable();
        else
            plMaxAccelerators::Disable();
        return TRUE;

    case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED)
        {
            int id = LOWORD(wParam);
            if (id == IDCANCEL)
            {
                Toggle();
                return TRUE;
            }
            else if (id == IDC_UPDATE_BUTTON)
            {
                IUpdateTextures(kUpdateLoadList);
                return TRUE;
            }
            else if (id == IDC_REPLACE_ALL_BUTTON)
            {
                if (hsMessageBox("Are you sure?", "Confirmation", hsMessageBoxYesNo) == hsMBoxYes)
                {
                    IUpdateTextures(kUpdateReplace);
                }
                return TRUE;
            }
            else if (id == IDC_SET_ALL_BUTTON)
            {
                if (hsMessageBox("Are you sure?", "Confirmation", hsMessageBoxYesNo) == hsMBoxYes)
                {
                    IUpdateTextures(kUpdateSetSize);
                }
                return TRUE;
            }
            else if (id == IDC_REPLACE_BUTTON)
            {
                IPickReplaceTexture();
                return TRUE;
            }
        }
        else if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_FIND_EDIT)
        {
            bool findText = (SendDlgItemMessage(hDlg, IDC_FIND_EDIT, EM_LINELENGTH, 0, 0) > 0);
            bool replace = (fFileName[0] != '\0');

            EnableWindow(GetDlgItem(hDlg, IDC_REPLACE_BUTTON), findText);
            EnableWindow(GetDlgItem(hDlg, IDC_REPLACE_ALL_BUTTON), findText && replace);

            return TRUE;
        }
        break;

    case WM_NOTIFY:
        {
            NMHDR* nmhdr = (NMHDR*)lParam;
            // User double-clicked a material in the texture list
            if (nmhdr->idFrom == IDC_TEXTURE_LIST && nmhdr->code == NM_DBLCLK)
            {
                NMITEMACTIVATE* itema = (NMITEMACTIVATE*)lParam;
                if (itema->iItem != -1)
                {
                    // Get the material the user clicked on
                    HWND hList = GetDlgItem(fDlg, IDC_TEXTURE_LIST);
                    LV_ITEM item;
                    item.iItem = itema->iItem;
                    item.mask = LVIF_PARAM;
                    ListView_GetItem(hList, &item);

                    Mtl* mtl = (Mtl*)item.lParam;

                    // Make sure the material is still in the scene (paranoid check)
                    MtlSet mtls;
                    plMtlCollector::GetMtls(&mtls, nil, plMtlCollector::kPlasmaOnly | plMtlCollector::kNoMultiMtl);
                    if (mtls.find(mtl) != mtls.end())
                    {
                        // Put the material in the current slot of the material editor
                        IMtlEditInterface* mtlInterface = GetMtlEditInterface();
                        int slot = mtlInterface->GetActiveMtlSlot();
                        mtlInterface->PutMtlToMtlEditor(mtl, slot);
                    }
                }

                return TRUE;
            }
        }
        break;
    }

    return FALSE;
}