[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can I make entries in CW_PDMENU insensitive?




David Fanning wrote:

> Adding a menu item as a button, assigning an event
> handler for it, and writing the new event handler
> can be done in a matter of minutes, as opposed to
> re-ordering my index numbers in a large event 
> handler, making several mistakes that introduce
> other errors, etc. 

I agree, David, that this is easily done in a few minutes -
although the situation might require a bit more than just an
event handler. You might want to (de)sensitize the button(s)
based on a number of different criteria, not just based on
events from the buttons themselves... So you'll probably
need to store the ID(s) in the info structure anyway.

Anyway, the ID extraction from the array would come directly
after the cw_pdmenu call using the IDS= keyword, so it isn't
that difficult to remember the update when you're changing
the cw_pdmenu call...

Given that button IDs for several buttons need to be stored
for later use, the difference isn't all that big... But
personally I agree that the direct method using /MENU in
widget_button is aesthetically more pleasing.

> When it comes to programming, I need all the help I can
> get.

Ok - you asked for it :-) In the case that one needs to
manipulate the status of several buttons on a pulldown menu,
the sensible thing is to write a pulldown menu *object*.

When this is done once and for all, you can forget all about
IDs and widget_control calls. Something like this (off the
top of my head, the specific mode of operation is at the
programmers discretion, of course):

   menu = obj_new('mypdmenu',base,'Pull Down Menu')
   menu->add,'Level 1a','LEVEL1A'   ;; Second arg. is an optional 
   menu->add,'Level 1b','LEVEL1B'   ;; identifier, [UVALUE]
   menu->add,'Level 1c','LEVEL1C',/menu
   menu->add,'Level 2a','LEVEL2A'
   menu->add,'Level 2b','LEVEL2B'
   
We keep the object pointer in the info structure, and
later we use it like this:

   ;; No argument means desensitize whole menu
   menu->desensitize 

   ;; One argument means desensitize that button (or
   ;; submenu)
   menu->sensitize,'LEVEL1A'  ;;  Single button
   menu->desensitize,'LEVEL1C'  ;; Submenu.
  
The rationale behind using identifiers like 'LEVEL1A' etc is
to be independent of the actual button text (like, if
somebody translates the text to serbocroatian... :-)

You may of course specify event handlers etc. in the "add"
method..

Regards,

Stein Vidar