OWL NExt - Knowledge Base

[ Home | Contents | Search | Next | Previous | Up ]

Disable toolbar buttons with Command Enablers

Date: 11/30/99
Time: 1:24:48 AM


Question:

Is it possible to use OWL command enabling to disable toolbar
buttons?

Answer:

You can use the same CommandEnabler function for menus and
buttongadgets. You are being passed both TButtonGadgetEnabler
references and TMenuItemEnabler references, and your call to
Enabler.Enable( false )will work on both. If for some reason
you have to distinguish between the two then you could use
dynamic_cast and conditionally disable only the tool bar button
or the menu item.
The following disables only the controlbar button, not the menu
item for a particular command:

void MyClient::CeFileNew(TCommandEnabler &tce )
{
  try{
    // from a toolbar button?
    dynamic_cast< TButtonGadgetEnabler& >( tce );
  }
  catch( Bad_cast& b ) {
    // not for a toolbar, do nothing
    return;
  }
  // disable if it is for a toolbar button
  tce.Enable( false );
}

Bad_cast is thrown when a cast of a reference type fails.

Last changed: July 14, 2001