Clean up menu code. Assure valid callbacks.
This commit is contained in:
parent
f0cfdd01c8
commit
d248786085
|
@ -19,8 +19,9 @@
|
||||||
|
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Menu_.H>
|
#include <FL/Fl_Menu_.H>
|
||||||
|
#include <FL/Fl_Menu_Item.H>
|
||||||
|
|
||||||
/* popup menu and execute callback */
|
/** popup menu and execute callback */
|
||||||
bool
|
bool
|
||||||
menu_popup ( Fl_Menu_ *m )
|
menu_popup ( Fl_Menu_ *m )
|
||||||
{
|
{
|
||||||
|
@ -30,5 +31,20 @@ menu_popup ( Fl_Menu_ *m )
|
||||||
{
|
{
|
||||||
m->value( r );
|
m->value( r );
|
||||||
r->do_callback( static_cast<Fl_Widget*>(m) );
|
r->do_callback( static_cast<Fl_Widget*>(m) );
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** set a single callback for all items in menu. */
|
||||||
|
void
|
||||||
|
menu_set_callback( Fl_Menu_Item *menu, void (*callback)( Fl_Widget *, void * ), void *user_data )
|
||||||
|
{
|
||||||
|
for ( int i = menu->size(); i--; )
|
||||||
|
if ( menu[i].label() && ! menu[i].submenu() )
|
||||||
|
{
|
||||||
|
menu[i].callback( callback );
|
||||||
|
menu[i].user_data( user_data );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,4 +18,8 @@
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
|
||||||
class Fl_Menu_;
|
class Fl_Menu_;
|
||||||
|
class Fl_Menu_Item;
|
||||||
|
class Fl_Widget;
|
||||||
|
|
||||||
bool menu_popup ( Fl_Menu_ *m );
|
bool menu_popup ( Fl_Menu_ *m );
|
||||||
|
void menu_set_callback ( Fl_Menu_Item *menu, void (*callback)( Fl_Widget *, void * ), void *user_data );
|
||||||
|
|
|
@ -248,6 +248,7 @@ Audio_Region::menu_cb ( const Fl_Menu_ *m )
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "FL/test_press.H"
|
#include "FL/test_press.H"
|
||||||
|
#include "FL/menu_popup.H"
|
||||||
|
|
||||||
/** build the context menu for this region */
|
/** build the context menu for this region */
|
||||||
Fl_Menu_Button &
|
Fl_Menu_Button &
|
||||||
|
@ -260,33 +261,33 @@ Audio_Region::menu ( void )
|
||||||
|
|
||||||
Fl_Menu_Item items[] =
|
Fl_Menu_Item items[] =
|
||||||
{
|
{
|
||||||
{ "Fade", 0, &Audio_Region::menu_cb, 0, FL_SUBMENU },
|
{ "Fade", 0, 0, 0, FL_SUBMENU },
|
||||||
{ "In", 0, &Audio_Region::menu_cb, 0, FL_SUBMENU },
|
{ "In", 0, 0, 0, FL_SUBMENU },
|
||||||
{ "Linear", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( it == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
{ "Linear", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Sigmoid", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( it == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
{ "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Logarithmic", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( it == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
{ "Logarithmic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Parabolic", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( it == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
{ "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( it == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
{ "Out", 0, &Audio_Region::menu_cb, 0, FL_SUBMENU },
|
{ "Out", 0, 0, 0, FL_SUBMENU },
|
||||||
{ "Linear", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( ot == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
{ "Linear", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Linear ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Sigmoid", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( ot == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
{ "Sigmoid", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Sigmoid ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Logarothmic", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
{ "Logarothmic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Logarithmic ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Parabolic", 0, &Audio_Region::menu_cb, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
{ "Parabolic", 0, 0, 0, FL_MENU_RADIO | ( ot == Fade::Parabolic ? FL_MENU_VALUE : 0 ) },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
{ "Color", 0, &Audio_Region::menu_cb, 0, inherit_track_color ? FL_MENU_INACTIVE : 0 },
|
{ "Color", 0, 0, 0, inherit_track_color ? FL_MENU_INACTIVE : 0 },
|
||||||
{ "Fade in to mouse", FL_F + 3, &Audio_Region::menu_cb, 0 },
|
{ "Fade in to mouse", FL_F + 3, 0, 0 },
|
||||||
{ "Fade out to mouse", FL_F + 4, &Audio_Region::menu_cb, 0 },
|
{ "Fade out to mouse", FL_F + 4, 0, 0 },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu_set_callback( items, &Audio_Region::menu_cb, (void*)this );
|
||||||
|
|
||||||
m.copy( items, (void*)this );
|
m.copy( items, (void*)this );
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "FL/menu_popup.H"
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Audio_Region::handle ( int m )
|
Audio_Region::handle ( int m )
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,6 +41,9 @@
|
||||||
|
|
||||||
#include "Engine/Engine.H" // for lock()
|
#include "Engine/Engine.H" // for lock()
|
||||||
|
|
||||||
|
|
||||||
|
#include "FL/menu_popup.H"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool Timeline::draw_with_measure_lines = true;
|
bool Timeline::draw_with_measure_lines = true;
|
||||||
|
@ -318,19 +321,21 @@ Timeline::Timeline ( int X, int Y, int W, int H, const char* L ) : Fl_Overlay_Wi
|
||||||
|
|
||||||
/* menu->add( "Add Track", 0, 0, 0 ); */
|
/* menu->add( "Add Track", 0, 0, 0 ); */
|
||||||
|
|
||||||
menu->add( "Add Audio Track", 'a', &Timeline::menu_cb, this );
|
menu->add( "Add Audio Track", 'a', 0, 0 );
|
||||||
menu->add( "Tempo from range", 't', &Timeline::menu_cb, this );
|
menu->add( "Tempo from range", 't', 0, 0 );
|
||||||
menu->add( "Playhead to mouse", 'p', &Timeline::menu_cb, this );
|
menu->add( "Playhead to mouse", 'p', 0, 0 );
|
||||||
menu->add( "P1 to mouse", '[', &Timeline::menu_cb, this );
|
menu->add( "P1 to mouse", '[', 0, 0 );
|
||||||
menu->add( "P2 to mouse", ']', &Timeline::menu_cb, this );
|
menu->add( "P2 to mouse", ']', 0, 0 );
|
||||||
menu->add( "Playhead left beat", FL_SHIFT + FL_Left, &Timeline::menu_cb, this );
|
menu->add( "Playhead left beat", FL_SHIFT + FL_Left, 0, 0 );
|
||||||
menu->add( "Playhead right beat", FL_SHIFT + FL_Right, &Timeline::menu_cb, this );
|
menu->add( "Playhead right beat", FL_SHIFT + FL_Right, 0, 0 );
|
||||||
menu->add( "Playhead left bar", FL_CTRL + FL_SHIFT + FL_Left, &Timeline::menu_cb, this );
|
menu->add( "Playhead left bar", FL_CTRL + FL_SHIFT + FL_Left, 0, 0 );
|
||||||
menu->add( "Playhead right bar", FL_CTRL + FL_SHIFT + FL_Right, &Timeline::menu_cb, this );
|
menu->add( "Playhead right bar", FL_CTRL + FL_SHIFT + FL_Right, 0, 0 );
|
||||||
menu->add( "Swap P1 and playhead", FL_CTRL + FL_SHIFT + '[', &Timeline::menu_cb, this );
|
menu->add( "Swap P1 and playhead", FL_CTRL + FL_SHIFT + '[', 0, 0 );
|
||||||
menu->add( "Swap P2 and playhead", FL_CTRL + FL_SHIFT + ']', &Timeline::menu_cb, this );
|
menu->add( "Swap P2 and playhead", FL_CTRL + FL_SHIFT + ']', 0, 0 );
|
||||||
menu->add( "P1 to playhead", FL_CTRL + '[', &Timeline::menu_cb, this );
|
menu->add( "P1 to playhead", FL_CTRL + '[', 0, 0 );
|
||||||
menu->add( "P2 to playhead", FL_CTRL + ']', &Timeline::menu_cb, this );
|
menu->add( "P2 to playhead", FL_CTRL + ']', 0, 0 );
|
||||||
|
|
||||||
|
menu_set_callback( const_cast<Fl_Menu_Item*>(menu->menu()), &Timeline::menu_cb, (void*)this );
|
||||||
|
|
||||||
{
|
{
|
||||||
Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 );
|
Scalebar *o = new Scalebar( X, Y + H - 18, W - 18, 18 );
|
||||||
|
@ -1203,12 +1208,7 @@ Timeline::handle ( int m )
|
||||||
}
|
}
|
||||||
else if ( test_press( FL_BUTTON3 ) )
|
else if ( test_press( FL_BUTTON3 ) )
|
||||||
{
|
{
|
||||||
const Fl_Menu_Item *r = menu->menu()->popup( X, Y, "Timeline" );
|
menu_popup( menu );
|
||||||
if ( r )
|
|
||||||
{
|
|
||||||
menu->value( r );
|
|
||||||
r->do_callback( static_cast<Fl_Widget*>(menu) );
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -556,6 +556,8 @@ Track::menu_cb ( const Fl_Menu_ *m )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "FL/menu_popup.H"
|
||||||
|
|
||||||
/** build the context menu */
|
/** build the context menu */
|
||||||
Fl_Menu_Button &
|
Fl_Menu_Button &
|
||||||
Track::menu ( void ) const
|
Track::menu ( void ) const
|
||||||
|
@ -566,19 +568,21 @@ Track::menu ( void ) const
|
||||||
|
|
||||||
Fl_Menu_Item menu[] =
|
Fl_Menu_Item menu[] =
|
||||||
{
|
{
|
||||||
{ "Type", 0, &Track::menu_cb, 0, FL_SUBMENU },
|
{ "Type", 0, 0, 0, FL_SUBMENU },
|
||||||
{ "Mono", 0, &Track::menu_cb, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) },
|
{ "Mono", 0, 0, 0, FL_MENU_RADIO | ( c == 1 ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Stereo", 0, &Track::menu_cb, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ) },
|
{ "Stereo", 0, 0, 0, FL_MENU_RADIO | ( c == 2 ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "Quad", 0, &Track::menu_cb, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) },
|
{ "Quad", 0, 0, 0, FL_MENU_RADIO | ( c == 4 ? FL_MENU_VALUE : 0 ) },
|
||||||
{ "...", 0, &Track::menu_cb, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) },
|
{ "...", 0, 0, 0, FL_MENU_RADIO | ( c == 3 || c > 4 ? FL_MENU_VALUE : 0 ) },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
{ "Add Control" },
|
{ "Add Control", 0, 0, 0 },
|
||||||
{ "Add Annotation" },
|
{ "Add Annotation", 0, 0, 0 },
|
||||||
{ "Color" },
|
{ "Color", 0, 0, 0 },
|
||||||
{ "Remove", 0, &Track::menu_cb, 0 }, // transport->rolling ? FL_MENU_INACTIVE : 0 },
|
{ "Remove", 0, 0, 0 }, // transport->rolling ? FL_MENU_INACTIVE : 0 },
|
||||||
{ 0 },
|
{ 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
menu_set_callback( menu, &Track::menu_cb, (void*)this );
|
||||||
|
|
||||||
m.copy( menu, (void*)this );
|
m.copy( menu, (void*)this );
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
@ -586,7 +590,6 @@ Track::menu ( void ) const
|
||||||
|
|
||||||
#include "FL/event_name.H"
|
#include "FL/event_name.H"
|
||||||
#include "FL/test_press.H"
|
#include "FL/test_press.H"
|
||||||
#include "FL/menu_popup.H"
|
|
||||||
|
|
||||||
int
|
int
|
||||||
Track::handle ( int m )
|
Track::handle ( int m )
|
||||||
|
@ -619,14 +622,10 @@ Track::handle ( int m )
|
||||||
{
|
{
|
||||||
Logger log( this );
|
Logger log( this );
|
||||||
|
|
||||||
int X = Fl::event_x();
|
|
||||||
int Y = Fl::event_y();
|
|
||||||
|
|
||||||
if ( Fl_Group::handle( m ) )
|
if ( Fl_Group::handle( m ) )
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
if ( test_press( FL_BUTTON3 ) && Fl::event_x() < Track::width() )
|
||||||
if ( test_press( FL_BUTTON3 ) && X < Track::width() )
|
|
||||||
{
|
{
|
||||||
menu_popup( &menu() );
|
menu_popup( &menu() );
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue