Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How do I gray-out a menu item? (Read 4434 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How do I gray-out a menu item?

By making is_disabled() return [true] this item cannot be clicked anymore.
But it does NOT gray it out! How can I do this?

 

How do I gray-out a menu item?

Reply #1
You need to overwrite get_display_data() (or context_get_display, if you have a menu_item_context subclass), and include FLAG_GRAYED in displayflags. See the FLAG_* enum values in class menu_item for all available flags.

How do I gray-out a menu item?

Reply #2
the problem is i don't know
* what get_display_data() really does
* what all the params are good for

does it also replace is_checked() and get_enum()?

the sdk contains this code from you (foo_vis_vu_meter\main.cpp):

Code: [Select]
virtual bool get_display_data(unsigned n,const ptr_list_base<metadb_handle> & data,string_base & out,unsigned & displayflags) {
 assert(n>=0 && n<get_num_items());
 if (!is_available(n)) return false;
 string8 temp;
 enum_item(n,temp);
 const char * ptr = strrchr(temp,'/');
 if (ptr) ptr++;
 else ptr = temp;
 out.set_string(ptr);
 displayflags = (is_checked(n) ? FLAG_CHECKED : 0) | (is_disabled(n) ? FLAG_DISABLED_GRAYED : 0);
 return true;
    }


but i gotta confess i don't understand that code.

ps: kannst mir auch ne mail auf deutsch schreiben - ich komm aus berlin

How do I gray-out a menu item?

Reply #3
Quote
the problem is i don't know
* what get_display_data() really does
* what all the params are good for

does it also replace is_checked() and get_enum()?

See below for explanation.

Quote
the sdk contains this code from you (foo_vis_vu_meter\main.cpp):

What SDK are you talking about here? Nevertheless, if you use that code from foo_vis_vu_meter, you will get the same behaviour for your menu_item as with the default implementation, except that disabled commands will be grayed out as well.

Quote
ps: kannst mir auch ne mail auf deutsch schreiben - ich komm aus berlin

For the sake of the other forum users, I'll try to answer questions asked here by posting (in English) rather than sending an email.


Now for the details about get_display_data:
get_display_data() determines how a command should be displayed, that is the displayed name and whether the command is checked/disabled/grayed out. is_available/is_checked/is_disabled are helper methods used by get_display_data (to get a uniform implementation). get_display_data does not replace enum_item, as that is used to identify a command. However, the default implementation of get_display_data derives the display name of a from the identifier given by enum_item.

The parameters of get_display_data are:
  • n - index of the command for which information is retrieved
  • data - a list of metadb_handle pointers*
  • out - in case the command is available, get_display_data has to store the name of the command in out
  • displayflags - get_display_data can store a combination of the FLAG_* enum values in displayflags to change the appearance of a command in the menu (like adding a check mark, or making the command disabled or grayed out)
  • caller - (only in the overloaded version in menu_item) identifies how the command was called*
*: the data and caller parameters are mainly for use with context menu items. I don't know what their values are for main menu items, so unless Peter says otherwise, you should consider them to have an undefined value for main menu items (i.e. don't use them).

The return value of get_display_data indicates, whether the command is available. Commands that are not available are not shown in the menu.

The default implementation of get_display_data does the following:
  • assert that n is a valid command index
  • check whether the command indicated by n is available using is_available; if it is not, return false
  • derive the display name of the command from the identifier given by enum_item (either the whole identifier, or if the identifier contains a slash, the part of the identifier after the last slash)
  • determine displayflags using is_checked and is_disabled
  • return true
I hope that clears things up a bit.

How do I gray-out a menu item?

Reply #4
thanx, foosion! your description cleared up ALOT! i will vote for you on sdk-documention...

Quote
What SDK are you talking about here? Nevertheless, if you use that code from foo_vis_vu_meter, you will get the same behaviour for your menu_item as with the default implementation, except that disabled commands will be grayed out as well.

sdk-08final/08b7.
using ...
Code: [Select]
virtual bool get_display_data( unsigned n, const ptr_list_base<metadb_handle> & data,string_base & out, unsigned & displayflags, const GUID & caller )

...i get grayed items now.

btw thanx again for writing your tutorial, was a GREAT HELP!!!

How do I gray-out a menu item?

Reply #5
My question about which SDK you meant was refering to this sentence:
Quote
the sdk contains this code from you (foo_vis_vu_meter\main.cpp):

foo_vis_vu_meter isn't really included in the official fb2k SDK.


As for explanation and documentation, I'll try to help out as far as my time permits.

How do I gray-out a menu item?

Reply #6
i forgot i extracted the source of [foo_vis_vu_meter] to that directory, too. so to me it seemed to be part of the sdk...

How do I gray-out a menu item?

Reply #7
You could always override get_display_data yourself and set the display flags directly. In fact, you can also use menu_item as a base instead of menu_item_v2 if you're not associating GUIDs with your items and don't care where you're called from.

Of course, I'm not sure if that has any real benefit or not, since menu_item services may just be wrapped by one of the core's internal compatibility layers, or something.