예제 #1
0
MenuRef IGraphicsCarbon::CreateMenu(IPopupMenu* pMenu)
{
  MenuRef menuRef = 0;
  ResID menuID = UniqueID ('MENU');

  int numItems = pMenu->GetNItems();

  if (numItems && CreateNewMenu(menuID, kMenuAttrCondenseSeparators, &menuRef) == noErr)
  {
    for (int i = 0; i < numItems; ++i)
    {
      IPopupMenuItem* menuItem = pMenu->GetItem(i);

      if (menuItem->GetIsSeparator())
      {
        AppendMenuItemTextWithCFString(menuRef, CFSTR(""), kMenuItemAttrSeparator, 0, NULL);
      }
      else
      {
        CFStringRef itemString = CFStringCreateWithCString(NULL, menuItem->GetText(), kCFStringEncodingUTF8);

        if (pMenu->GetPrefix())
        {
          CFStringRef prefixString = 0;

          switch (pMenu->GetPrefix())
          {
            case 0:
              prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR(""),i+1); break;
            case 1:
              prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%1d: "),i+1); break;
            case 2:
              prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%02d: "),i+1); break;
            case 3:
              prefixString = CFStringCreateWithFormat(NULL, 0, CFSTR("%03d: "),i+1); break;
          }

          CFMutableStringRef newItemString = CFStringCreateMutable(0, 0);
          CFStringAppend (newItemString, prefixString);
          CFStringAppend (newItemString, itemString);
          CFRelease (itemString);
          CFRelease (prefixString);
          itemString = newItemString;
        }

        if (itemString == 0)
          continue;

        MenuItemAttributes itemAttribs = kMenuItemAttrIgnoreMeta;

        if (!menuItem->GetEnabled())
        {
          itemAttribs |= kMenuItemAttrDisabled;
        }

        if (menuItem->GetIsTitle())
        {
          itemAttribs |= kMenuItemAttrSectionHeader;
        }

        InsertMenuItemTextWithCFString(menuRef, itemString, i, itemAttribs, 0);

        if (menuItem->GetChecked())
        {
          CheckMenuItem(menuRef, i+1, true);
        }

        if (menuItem->GetSubmenu())
        {
          MenuRef submenu = CreateMenu(menuItem->GetSubmenu());

          if (submenu)
          {
            SetMenuItemHierarchicalMenu(menuRef, i+1, submenu);
            CFRelease (submenu);
          }
        }

        CFRelease (itemString);
      }
    }

    //  if (pMenu->getStyle() & kCheckStyle && !multipleCheck)
    //    CheckMenuItem (menuRef, pMenu->getCurrentIndex (true) + 1, true);
    SetMenuItemRefCon(menuRef, 0, (int32_t)pMenu);
    //swell collision
    #undef InsertMenu
    InsertMenu(menuRef, kInsertHierarchicalMenu);
    #define InsertMenu SWELL_InsertMenu
  }

  return menuRef;
}
예제 #2
0
IPopupMenu* IGraphicsWin::CreateIPopupMenu(IPopupMenu* pMenu, IRECT* pAreaRect)
{
  ReleaseMouseCapture();
  
  int numItems = pMenu->GetNItems();

  POINT cPos;
  
  cPos.x = pAreaRect->L;
  cPos.y = pAreaRect->B;

  ClientToScreen(mPlugWnd, &cPos);

  HMENU hMenu = CreatePopupMenu();

  int flags = 0;
  
  if(numItems && hMenu)
  {
    for(int i = 0; i< numItems;i++)
    {
      IPopupMenuItem* menuItem = pMenu->GetItem(i);

      if (menuItem->GetIsSeparator())
      {
        AppendMenu (hMenu, MF_SEPARATOR, 0, 0);
      }
      else
      {
        const char* str = menuItem->GetText();
        char* titleWithPrefixNumbers = 0;
        
        if (pMenu->GetPrefix())
        {
          titleWithPrefixNumbers = (char*)malloc(strlen(str) + 50);

          switch (pMenu->GetPrefix())
          {
            case 1:
            {
              sprintf(titleWithPrefixNumbers, "%1d: %s", i+1, str); break;
            }
            case 2:
            {
              sprintf(titleWithPrefixNumbers, "%02d: %s", i+1, str); break;
            }
            case 3:
            {
              sprintf(titleWithPrefixNumbers, "%03d: %s", i+1, str); break;
            }
          }
        }

        const char* entryText (titleWithPrefixNumbers ? titleWithPrefixNumbers : str);
        
        flags = MF_STRING;
        //if (nbEntries < 160 && _menu->getNbItemsPerColumn () > 0 && inc && !(inc % _menu->getNbItemsPerColumn ()))
        //  flags |= MF_MENUBARBREAK;

        if (menuItem->GetSubmenu())
        {
        //  HMENU submenu = createMenu (item->getSubmenu (), offsetIdx);
        //  if (submenu)
        //  {
         //   AppendMenu (menu, flags|MF_POPUP|MF_ENABLED, (UINT_PTR)submenu, (const TCHAR*)entryText);
         // }
        }
        else
        {
          if (menuItem->GetEnabled())
            flags |= MF_ENABLED;
          else
            flags |= MF_GRAYED;
          if (menuItem->GetIsTitle())
            flags |= MF_DISABLED;
          //if (multipleCheck && menuItem->GetChecked())
           // flags |= MF_CHECKED;
          if (menuItem->GetChecked())
            flags |= MF_CHECKED;
          else
            flags |= MF_UNCHECKED;
          //if (!(flags & MF_CHECKED))
          //  flags |= MF_UNCHECKED;
          
          AppendMenu(hMenu, flags, i+1, entryText);
          
        }

        if(titleWithPrefixNumbers)
          FREE_NULL(titleWithPrefixNumbers);
      }
    }
    
    int itemChosen = TrackPopupMenu(hMenu, TPM_LEFTALIGN/*|TPM_VCENTERALIGN*/|TPM_NONOTIFY|TPM_RETURNCMD, cPos.x, cPos.y, 0, mPlugWnd, 0);

//    IPopupMenu* chosenMenu;

 

    if (itemChosen > 0)
    {
      pMenu->SetChosenItemIdx(itemChosen - 1);
      DestroyMenu(hMenu);
      return pMenu;
    }
    else 
    {
      DestroyMenu(hMenu);
      return 0;
    }
  }
  else 
  return 0;
}