IPopupMenu* IGraphicsCarbon::CreateIPopupMenu(IPopupMenu* pMenu, IRECT* pAreaRect) { // Get the plugin gui frame rect within the host's window HIRect rct; HIViewGetFrame(this->mView, &rct); // Get the host's window rect within the screen Rect wrct; GetWindowBounds(this->mWindow, kWindowContentRgn, &wrct); #ifdef RTAS_API int xpos = wrct.left + this->GetLeftOffset() + pAreaRect->L; int ypos = wrct.top + this->GetTopOffset() + pAreaRect->B + 5; #else HIViewRef contentView; HIViewFindByID(HIViewGetRoot(this->mWindow), kHIViewWindowContentID, &contentView); HIViewConvertRect(&rct, HIViewGetSuperview((HIViewRef)this->mView), contentView); int xpos = wrct.left + rct.origin.x + pAreaRect->L; int ypos = wrct.top + rct.origin.y + pAreaRect->B + 5; #endif MenuRef menuRef = CreateMenu(pMenu); if (menuRef) { int32_t popUpItem = 1; int32_t PopUpMenuItem = PopUpMenuSelect(menuRef, ypos, xpos, popUpItem); short result = LoWord(PopUpMenuItem) - 1; short menuIDResult = HiWord(PopUpMenuItem); IPopupMenu* resultMenu = 0; if (menuIDResult != 0) { MenuRef usedMenuRef = GetMenuHandle(menuIDResult); if (usedMenuRef) { if (GetMenuItemRefCon(usedMenuRef, 0, (URefCon*)&resultMenu) == noErr) { resultMenu->SetChosenItemIdx(result); } } } CFRelease(menuRef); return resultMenu; } else { return 0; } }
void IGraphics::PromptUserInput(IControl* pControl, IParam* pParam, IRECT* pTextRect) { if (!pControl || !pParam || !pTextRect) return; IParam::EParamType type = pParam->Type(); int n = pParam->GetNDisplayTexts(); char currentText[MAX_PARAM_LEN]; if ( type == IParam::kTypeEnum || (type == IParam::kTypeBool && n)) { pParam->GetDisplayForHost(currentText); IPopupMenu menu; // Fill the menu for (int i = 0; i < n; ++i) { const char* str = pParam->GetDisplayText(i); // TODO: what if two parameters have the same text? if (!strcmp(str, currentText)) // strings are equal menu.AddItem( new IPopupMenuItem(str, IPopupMenuItem::kChecked), -1 ); else // not equal menu.AddItem( new IPopupMenuItem(str), -1 ); } if(CreateIPopupMenu(&menu, pTextRect)) { pControl->SetValueFromUserInput(pParam->GetNormalized( (double) menu.GetChosenItemIdx() )); } } // TODO: what if there are Int/Double Params with a display text e.g. -96db = "mute" else // type == IParam::kTypeInt || type == IParam::kTypeDouble { pParam->GetDisplayForHostNoDisplayText(currentText); CreateTextEntry(pControl, pControl->GetText(), pTextRect, currentText, pParam ); } }
void doPopupMenu() { IPopupMenu menu; IGraphics* gui = mPlug->GetGUI(); menu.AddItem("Save Program..."); menu.AddItem("Save Bank..."); menu.AddSeparator(); menu.AddItem("Load Program..."); menu.AddItem("Load Bank..."); if(gui->CreateIPopupMenu(&menu, &mRECT)) { int itemChosen = menu.GetChosenItemIdx(); //printf("chosen %i /n", itemChosen); switch (itemChosen) { case 0: //Save Program char disp[MAX_PRESET_NAME_LEN]; strcpy(disp, mPlug->GetPresetName(mPlug->GetCurrentPresetIdx())); mPlug->SaveProgramAsFXP(disp); break; case 1: //Save Bank mPlug->SaveBankAsFXB("IPlugChunks Bank"); break; case 3: //Load Preset mPlug->LoadProgramFromFXP(); break; case 4: // Load Bank mPlug->LoadBankFromFXB(); break; default: break; } } }