Clean up sequence widget class.

This commit is contained in:
Jonathan Moore Liles 2008-06-22 20:01:09 -05:00
parent 9335a97933
commit d4535ab52e
2 changed files with 114 additions and 99 deletions

View File

@ -48,6 +48,35 @@ Sequence_Widget::Sequence_Widget ( )
_color = FL_FOREGROUND_COLOR; _color = FL_FOREGROUND_COLOR;
} }
/* careful with this, it doesn't journal */
Sequence_Widget::Sequence_Widget ( const Sequence_Widget &rhs ) : Loggable( rhs )
{
_drag = NULL;
_sequence = rhs._sequence;
_range = rhs._range;
_r = &_range;
_color = rhs._color;
_box_color = rhs._box_color;
};
const Sequence_Widget &
Sequence_Widget::operator= ( const Sequence_Widget &rhs )
{
if ( this == &rhs )
return *this;
_r = &_range;
_range = rhs._range;
_sequence = rhs._sequence;
_box_color = rhs._box_color;
_color = rhs._color;
return *this;
}
Sequence_Widget::~Sequence_Widget ( ) Sequence_Widget::~Sequence_Widget ( )
{ {
redraw(); redraw();
@ -336,8 +365,7 @@ Sequence_Widget::handle ( int m )
/* deletion */ /* deletion */
if ( test_press( FL_BUTTON3 + FL_CTRL ) ) if ( test_press( FL_BUTTON3 + FL_CTRL ) )
{ {
redraw(); remove();
sequence()->queue_delete( this );
return 1; return 1;
} }
else if ( test_press( FL_BUTTON1 ) || test_press( FL_BUTTON1 + FL_CTRL ) ) else if ( test_press( FL_BUTTON1 ) || test_press( FL_BUTTON1 + FL_CTRL ) )
@ -450,3 +478,68 @@ Sequence_Widget::handle ( int m )
return 0; return 0;
} }
} }
/**********/
/* Public */
/**********/
/** add this widget to the selection */
void
Sequence_Widget::select ( void )
{
if ( selected() )
return;
_selection.push_back( this );
_selection.sort( sort_func );
redraw();
}
/** remove this widget from the selection */
void
Sequence_Widget::deselect ( void )
{
_selection.remove( this );
redraw();
}
bool
Sequence_Widget::selected ( void ) const
{
return std::find( _selection.begin(), _selection.end(), this ) != _selection.end();
}
/** remove this widget from its sequence */
void
Sequence_Widget::remove ( void )
{
redraw();
sequence()->queue_delete( this );
}
void
Sequence_Widget::delete_selected ( void )
{
Loggable::block_start();
while ( _selection.size() )
delete _selection.front();
Loggable::block_end();
}
void
Sequence_Widget::select_none ( void )
{
Loggable::block_start();
while ( _selection.size() )
{
_selection.front()->redraw();
_selection.pop_front();
}
Loggable::block_end();
}

View File

@ -110,6 +110,12 @@ struct position_info
BBT bbt; BBT bbt;
}; };
#define SEQUENCE_WIDGET_CLONE_FUNC(class) \
virtual Sequence_Widget *clone ( void ) const \
{ \
return new class ( *this ); \
}
/* Base class for virtual widget on a track */ /* Base class for virtual widget on a track */
class Sequence_Widget : public Loggable class Sequence_Widget : public Loggable
@ -144,114 +150,33 @@ protected:
virtual void get ( Log_Entry &e ) const; virtual void get ( Log_Entry &e ) const;
virtual void set ( Log_Entry &e ); virtual void set ( Log_Entry &e );
/* careful with this, it doesn't journal */ Sequence_Widget ( const Sequence_Widget &rhs );
Sequence_Widget ( const Sequence_Widget &rhs ) : Loggable( rhs )
{
_drag = NULL;
_sequence = rhs._sequence;
_range = rhs._range;
_r = &_range;
_color = rhs._color;
_box_color = rhs._box_color;
};
Sequence_Widget ( ); Sequence_Widget ( );
const Sequence_Widget &
operator= ( const Sequence_Widget &rhs );
public: public:
virtual ~Sequence_Widget ( ); virtual ~Sequence_Widget ( );
const Sequence_Widget &
operator= ( const Sequence_Widget &rhs )
{
if ( this == &rhs )
return *this;
_r = &_range;
_range = rhs._range;
_sequence = rhs._sequence;
_box_color = rhs._box_color;
_color = rhs._color;
return *this;
}
/* Sequence_Widget ( const Sequence_Widget &rhs ) */
/* { */
/* *this = rhs; */
/* } */
#define SEQUENCE_WIDGET_CLONE_FUNC(class) \
virtual Sequence_Widget *clone ( void ) const \
{ \
return new class ( *this ); \
} \
\
// virtual Sequence_Widget *clone ( const Sequence_Widget *r ) = 0;
virtual Sequence_Widget *clone ( void ) const = 0; virtual Sequence_Widget *clone ( void ) const = 0;
bool selected ( void ) const bool selected ( void ) const;
{ void select ( void );
return std::find( _selection.begin(), _selection.end(), this ) != _selection.end(); void deselect ( void );
} void remove ( void );
void select ( void ) static void delete_selected ( void );
{ static void select_none ( void );
if ( selected() )
return;
_selection.push_back( this );
_selection.sort( sort_func );
redraw();
}
void deselect ( void )
{
_selection.remove( this );
redraw();
}
static void
delete_selected ( void )
{
Loggable::block_start();
while ( _selection.size() )
delete _selection.front();
Loggable::block_end();
}
static void
select_none ( void )
{
Loggable::block_start();
while ( _selection.size() )
{
_selection.front()->redraw();
_selection.pop_front();
}
Loggable::block_end();
}
static Sequence_Widget *current ( void ) { return Sequence_Widget::_current; } static Sequence_Widget *current ( void ) { return Sequence_Widget::_current; }
static Sequence_Widget *pushed ( void ) { return Sequence_Widget::_pushed; } static Sequence_Widget *pushed ( void ) { return Sequence_Widget::_pushed; }
static Sequence_Widget *belowmouse ( void ) { return Sequence_Widget::_belowmouse; } static Sequence_Widget *belowmouse ( void ) { return Sequence_Widget::_belowmouse; }
static void pushed ( Sequence_Widget *w ) { Sequence_Widget::_pushed = w; } static void pushed ( Sequence_Widget *w ) { Sequence_Widget::_pushed = w; }
static void belowmouse ( Sequence_Widget *w ) { Sequence_Widget::_belowmouse = w; } static void belowmouse ( Sequence_Widget *w ) { Sequence_Widget::_belowmouse = w; }
// static void pushed ( Sequence_Widget *w ) { Sequence_Widget::_pushed = w; }
void begin_drag ( const Drag &d ); void begin_drag ( const Drag &d );
void end_drag ( void ); void end_drag ( void );
@ -322,9 +247,6 @@ public:
int active_r ( void ) const { return _sequence->active_r(); } int active_r ( void ) const { return _sequence->active_r(); }
/** returns true if widget /w/ begins and ends completely within the range of this widget */ /** returns true if widget /w/ begins and ends completely within the range of this widget */
bool contains ( const Sequence_Widget *w ) const bool contains ( const Sequence_Widget *w ) const
{ {