Пример #1
0
///
/// Add a menu item to the current menu.  When the user selects it, the
/// given functor will be called
void CommandManager::AddItem(wxString name, wxString label_in,
                             CommandFunctor *callback, int checkmark)
{
   wxString label = label_in;
   if( ItemShouldBeHidden( label ) )
      return;

   int ID = NewIdentifier(name, label, CurrentMenu(), callback, false, 0, 0);

   // Replace the accel key with the one from the preferences
   label = label.BeforeFirst(wxT('\t'));

   // This is a very weird hack.  Under GTK, menu labels are totally
   // linked to accelerators the first time you create a menu item
   // with that label and can't be changed.  This causes all sorts of
   // problems.  As a workaround, we create each menu item with a
   // made-up name (just an ID number string) but with the accelerator
   // we want, then immediately change the label to the correct string.
   // -DMM
   mHiddenID++;
   wxString dummy, newLabel;
   dummy.Printf(wxT("%s%08d"), label.c_str(), mHiddenID);
   newLabel = label;

   bool shortcut = false;

   if (mCommandIDHash[ID]->key.Length() > 0)
      shortcut = true;
   
   // Mac OS X fixes
  #ifdef __WXMAC__
   if (newLabel.Length() > 0 && newLabel[0] == wxT('&'))
      newLabel = newLabel.Right(newLabel.Length()-1);

   if (shortcut == true &&
       (mCommandIDHash[ID]->key.Length() < 5 ||
        mCommandIDHash[ID]->key.Left(5) != wxT("Ctrl+")))
      shortcut = false;
  #endif
   
   if (shortcut) {
      dummy = dummy + wxT("\t") + mCommandIDHash[ID]->key;
   }

   if (checkmark >= 0) {
      CurrentMenu()->AppendCheckItem(ID, dummy);
      CurrentMenu()->Check(ID, checkmark !=0);
   }
   else {
      CurrentMenu()->Append(ID, dummy);
   }
   CurrentMenu()->SetLabel(ID, newLabel);
   mbSeparatorAllowed = true;
}
Пример #2
0
///
/// This makes a new menu and adds it to the 'CurrentMenuBar'
///
/// If the menu already exists, all of the items in it are
/// cleared instead.
///
void CommandManager::BeginMenu(wxString tNameIn)
{
   
   wxString tName = tNameIn;
   if( ItemShouldBeHidden( tName ) )
   {
      mHidingLevel++;
      return;
   }

   wxMenu *tmpMenu = new wxMenu();

   mCurrentMenu = tmpMenu;

   CurrentMenuBar()->Append(mCurrentMenu, tName);
}
Пример #3
0
void CommandManager::AddItem(const wxChar *name,
                             const wxChar *label_in,
                             CommandFunctor *callback,
                             const wxChar *accel,
                             unsigned int flags,
                             unsigned int mask,
                             int checkmark)
{
   wxString label(label_in);
   label += wxT("\t");
   label += accel ? accel : wxEmptyString;

   if (ItemShouldBeHidden(label)) {
      delete callback;
      return;
   }

   int ID = NewIdentifier(name, label, CurrentMenu(), callback, false, 0, 0);

   if (flags != NoFlagsSpecifed || mask != NoFlagsSpecifed) {
      SetCommandFlags(name, flags, mask);
   }

   // Replace the accel key with the one from the preferences
   label = label.BeforeFirst(wxT('\t'));

   // This is a very weird hack.  Under GTK, menu labels are totally
   // linked to accelerators the first time you create a menu item
   // with that label and can't be changed.  This causes all sorts of
   // problems.  As a workaround, we create each menu item with a
   // made-up name (just an ID number string) but with the accelerator
   // we want, then immediately change the label to the correct string.
   // -DMM
   wxString newLabel;
   newLabel.Printf(wxT("%s%08d"), label.c_str(), ++mHiddenID);

   if (checkmark >= 0) {
      CurrentMenu()->AppendCheckItem(ID, newLabel);
      CurrentMenu()->Check(ID, checkmark != 0);
   }
   else {
      CurrentMenu()->Append(ID, newLabel);
   }

   CurrentMenu()->SetLabel(ID, label);
   mbSeparatorAllowed = true;
}
Пример #4
0
///
/// This starts a new submenu, and names it according to
/// the function's argument.
wxMenu* CommandManager::BeginSubMenu(wxString tNameIn)
{
   wxString tName = tNameIn;
   if( ItemShouldBeHidden( tName ) )
   {
      mHidingLevel++;
      return NULL;
   }

   SubMenuListEntry *tmpEntry = new SubMenuListEntry;

   tmpEntry->menu = new wxMenu();
   tmpEntry->name = tName;

   mSubMenuList.Add(tmpEntry);
   mbSeparatorAllowed = false;

   return(tmpEntry->menu);
}
Пример #5
0
///
/// Add a menu item to the current menu.  When the user selects it, the
/// given functor will be called
void CommandManager::InsertItem(wxString name, wxString label_in,
                                CommandFunctor *callback, wxString after,
                                int checkmark)
{
   wxString label = label_in;

   if (ItemShouldBeHidden(label)) {
      delete callback;
      return;
   }

   wxMenuBar *bar = GetActiveProject()->GetMenuBar();
   wxArrayString names = ::wxStringTokenize(after, wxT(":"));
   size_t cnt = names.GetCount();

   if (cnt < 2) {
      return;
   }

   int pos = bar->FindMenu(names[0]);
   if (pos == wxNOT_FOUND) {
      return;
   }

   wxMenu *menu = bar->GetMenu(pos);
   wxMenuItem *item = NULL;
   pos = 0;

   for (size_t ndx = 1; ndx < cnt; ndx++) {
      wxMenuItemList list = menu->GetMenuItems();
      size_t lcnt = list.GetCount();
      wxString label = wxMenuItem::GetLabelText(names[ndx]);

      for (size_t lndx = 0; lndx < lcnt; lndx++) {
         item = list.Item(lndx)->GetData();
         if (item->GetLabel() == label) {
            break;
         }
         pos++;
         item = NULL;
      }

      if (item == NULL) {
         return;
      }

      if (item->IsSubMenu()) {
         menu = item->GetSubMenu();
         item = NULL;
         continue;
      }

      if (ndx + 1 != cnt) {
         return;
      }
   }

   int ID = NewIdentifier(name, label, menu, callback, false, 0, 0);

   // Replace the accel key with the one from the preferences
   label = label.BeforeFirst(wxT('\t'));

   // This is a very weird hack.  Under GTK, menu labels are totally
   // linked to accelerators the first time you create a menu item
   // with that label and can't be changed.  This causes all sorts of
   // problems.  As a workaround, we create each menu item with a
   // made-up name (just an ID number string) but with the accelerator
   // we want, then immediately change the label to the correct string.
   // -DMM
   mHiddenID++;
   wxString dummy, newLabel;
   dummy.Printf(wxT("%s%08d"), label.c_str(), mHiddenID);
   newLabel = label;

   if (checkmark >= 0) {
      menu->InsertCheckItem(pos, ID, dummy);
      menu->Check(ID, checkmark != 0);
   }
   else {
      menu->Insert(pos, ID, dummy);
   }
   menu->SetLabel(ID, newLabel);

   mbSeparatorAllowed = true;
}
Пример #6
0
///
/// Add a list of menu items to the current menu.  When the user selects any
/// one of these, the given functor will be called
/// with its position in the list as the index number.
/// When you call Enable on this command name, it will enable or disable
/// all of the items at once.
void CommandManager::AddItemList(wxString name, wxArrayString labels,
                                 CommandFunctor *callback,
                                 bool plugins /*= false*/)
{
   unsigned int i;

   #ifndef __WXGTK__
   plugins = false;
   #endif

   if( mHidingLevel  > 0 )
      return;

   unsigned int effLen = labels.GetCount();
   unsigned int nVisibleEffects=0;

   wxString label;
   int tmpmax;

   // Count the visible effects.
   for(i=0; i<effLen; i++) {
      // ItemShouldBeHidden removes the ! so do it to a temporary.
      label = labels[i];
      if (!ItemShouldBeHidden(label)) {
         nVisibleEffects++;
      }
   }

   if (CurrentMenu()->GetMenuItemCount() + nVisibleEffects < MAX_MENU_LEN)
      plugins = false;

   // j counts the visible menu items, i counts the actual menu items.
   // These numbers are the same unless we are using a simplified interface
   // by hiding effects with a ! before them when translated.
   int j=0;
   for(i=0; i<effLen; i++) {
      if (!ItemShouldBeHidden(labels[i])) {

         // ---- Start of code for Plugin sub-menus.  Only relevant on wxGTK.
         // If plugins, and at start of a sublist....
         if( plugins && ((j % MAX_SUBMENU_LEN) == 0 )) {
            // End previous sub-menu, if there was one.
            if( j>0 )
               EndSubMenu();

            // Start new sub-menu
            // tmpmax is number of last plugin for this sub-menu
            tmpmax = wxMin(j + MAX_SUBMENU_LEN, (int)nVisibleEffects);
            // Submenu titles are 1 to 15, 15 to 30, etc.
            BeginSubMenu(wxString::Format(_("Plug-ins %i to %i"),j+1,tmpmax));
         }
         // ---- End of code for Plugin sub-menus.

         j++;
         int ID = NewIdentifier(name, labels[i], CurrentMenu(), callback,
                                true, i, effLen);
         CurrentMenu()->Append(ID, labels[i]);
         mbSeparatorAllowed = true;
      }
   }
   if( plugins && (nVisibleEffects>0 ))
      EndSubMenu();
}