}
-void CtrlButton::onUpdate( Subject<AnimBitmap> &rBitmap )
+void CtrlButton::onUpdate( Subject<AnimBitmap, void*> &rBitmap, void *arg )
{
notifyLayout();
}
/// Base class for button controls
-class CtrlButton: public CtrlGeneric, public Observer<AnimBitmap>
+class CtrlButton: public CtrlGeneric, public Observer<AnimBitmap, void*>
{
public:
/// Create a button with 3 images
void setImage( AnimBitmap *pImg );
/// Method called when an animated bitmap changes
- virtual void onUpdate( Subject<AnimBitmap> &rBitmap );
+ virtual void onUpdate( Subject<AnimBitmap, void*> &rBitmap, void* );
};
}
-void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable )
+void CtrlGeneric::onUpdate( Subject<VarBool, void*> &rVariable, void *arg )
{
// Is it the visibility variable ?
if( &rVariable == m_pVisible )
/// Base class for controls
-class CtrlGeneric: public SkinObject, public Observer<VarBool>
+class CtrlGeneric: public SkinObject, public Observer<VarBool, void*>
{
public:
virtual ~CtrlGeneric();
VarBool *m_pVisible;
/// Method called when an observed bool variable is changed
- virtual void onUpdate( Subject<VarBool> &rVariable );
+ virtual void onUpdate( Subject<VarBool, void*> &rVariable , void* );
};
typedef CountedPtr<CtrlGeneric> CtrlGenericPtr;
}
-void CtrlList::onUpdate( Subject<VarList> &rList )
+void CtrlList::onUpdate( Subject<VarList, void*> &rList, void *arg )
{
autoScroll();
m_pLastSelected = NULL;
}
-void CtrlList::onUpdate( Subject<VarPercent> &rPercent )
+void CtrlList::onUpdate( Subject<VarPercent, void*> &rPercent, void *arg )
{
// Get the size of the control
const Position *pPos = getPosition();
/// Class for control list
-class CtrlList: public CtrlGeneric, public Observer<VarList>,
- public Observer<VarPercent>
+class CtrlList: public CtrlGeneric, public Observer<VarList, void*>,
+ public Observer<VarPercent, void *>
{
public:
CtrlList( intf_thread_t *pIntf, VarList &rList,
int m_lastPos;
/// Method called when the list variable is modified
- virtual void onUpdate( Subject<VarList> &rList );
+ virtual void onUpdate( Subject<VarList, void*> &rList, void* );
/// Method called when the position variable of the list is modified
- virtual void onUpdate( Subject<VarPercent> &rPercent );
+ virtual void onUpdate( Subject<VarPercent, void*> &rPercent, void* );
/// Called when the position is set
virtual void onPositionChange();
}
-void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable )
+void CtrlRadialSlider::onUpdate( Subject<VarPercent,void*> &rVariable,
+ void *arg )
{
m_position = (int)( m_rVariable.get() * m_numImg );
notifyLayout( m_width, m_height );
/// Radial slider
-class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent>
+class CtrlRadialSlider: public CtrlGeneric, public Observer<VarPercent, void*>
{
public:
/// Create a radial slider with the given image, which must be
DEFINE_CALLBACK( CtrlRadialSlider, Move )
/// Method called when the observed variable is modified
- virtual void onUpdate( Subject<VarPercent> &rVariable );
+ virtual void onUpdate( Subject<VarPercent,void*> &rVariable, void* );
/// Change the position of the cursor, with the given position of
/// the mouse (relative to the layout). Is blocking is true, the
}
-void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable )
+void CtrlSliderCursor::onUpdate( Subject<VarPercent,void*> &rVariable,
+ void *arg )
{
// The position has changed
refreshLayout();
}
-void CtrlSliderBg::onUpdate( Subject<VarPercent> &rVariable )
+void CtrlSliderBg::onUpdate( Subject<VarPercent, void*> &rVariable, void*arg )
{
m_position = (int)( m_rVariable.get() * (m_nbHoriz * m_nbVert - 1) );
notifyLayout( m_bgWidth, m_bgHeight );
/// Cursor of a slider
-class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent>
+class CtrlSliderCursor: public CtrlGeneric, public Observer<VarPercent, void*>
{
public:
/// Create a cursor with 3 images (which are NOT copied, be careful)
const Bezier &m_rCurve;
/// Method called when the position variable is modified
- virtual void onUpdate( Subject<VarPercent> &rVariable );
+ virtual void onUpdate( Subject<VarPercent,void*> &rVariable, void * );
/// Method to compute the resize factors
void getResizeFactors( float &rFactorX, float &rFactorY ) const;
/// Slider background
-class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent>
+class CtrlSliderBg: public CtrlGeneric, public Observer<VarPercent, void*>
{
public:
CtrlSliderBg( intf_thread_t *pIntf,
int m_position;
/// Method called when the observed variable is modified
- virtual void onUpdate( Subject<VarPercent> &rVariable );
+ virtual void onUpdate( Subject<VarPercent,void*> &rVariable, void* );
/// Method to compute the resize factors
void getResizeFactors( float &rFactorX, float &rFactorY ) const;
}
-void CtrlText::onUpdate( Subject<VarText> &rVariable )
+void CtrlText::onUpdate( Subject<VarText, void*> &rVariable, void* arg )
{
displayText( m_rVariable.get() );
}
/// Class for control text
-class CtrlText: public CtrlGeneric, public Observer<VarText>
+class CtrlText: public CtrlGeneric, public Observer<VarText, void*>
{
public:
enum Align_t
DEFINE_CALLBACK( CtrlText, UpdateText );
/// Method called when the observed variable is modified
- virtual void onUpdate( Subject<VarText> &rVariable );
+ virtual void onUpdate( Subject<VarText,void*> &rVariable, void* );
/// Display the text on the control
void displayText( const UString &rText );
}
-void CtrlTree::onUpdate( Subject<VarTree> &rTree )
+void CtrlTree::onUpdate( Subject<VarTree, int> &rTree, int arg )
{
+ fprintf( stderr, "Doing update type %i\n", arg );
autoScroll();
m_pLastSelected = NULL;
}
-void CtrlTree::onUpdate( Subject<VarPercent> &rPercent )
+void CtrlTree::onUpdate( Subject<VarPercent, void*> &rPercent, void* arg)
{
// Determine what is the first item to display
VarTree::Iterator it = m_rTree.begin();
class GenericBitmap;
/// Class for control tree
-class CtrlTree: public CtrlGeneric, public Observer<VarTree>,
- public Observer<VarPercent>
+class CtrlTree: public CtrlGeneric, public Observer<VarTree, int>,
+ public Observer<VarPercent, void*>
{
public:
CtrlTree( intf_thread_t *pIntf,
VarTree::Iterator m_lastPos;
/// Method called when the tree variable is modified
- virtual void onUpdate( Subject<VarTree> &rTree );
+ virtual void onUpdate( Subject<VarTree, int> &rTree , int);
// Method called when the position variable of the tree is modified
- virtual void onUpdate( Subject<VarPercent> &rPercent );
+ virtual void onUpdate( Subject<VarPercent, void *> &rPercent , void *);
/// Called when the position is set
virtual void onPositionChange();
}
-void CtrlVideo::onUpdate( Subject<VarBox> &rVoutSize )
+void CtrlVideo::onUpdate( Subject<VarBox, void *> &rVoutSize, void *arg )
{
int newWidth = ((VarBox&)rVoutSize).getWidth() + m_xShift;
int newHeight = ((VarBox&)rVoutSize).getHeight() + m_yShift;
class VoutWindow;
/// Control video
-class CtrlVideo: public CtrlGeneric, public Observer<VarBox>
+class CtrlVideo: public CtrlGeneric, public Observer<VarBox, void*>
{
public:
CtrlVideo( intf_thread_t *pIntf, GenericLayout &rLayout,
virtual string getType() const { return "video"; }
/// Method called when the vout size is updated
- virtual void onUpdate( Subject<VarBox> &rVoutSize );
+ virtual void onUpdate( Subject<VarBox,void*> &rVoutSize, void* );
private:
/// Vout window
/// Animated bitmap
-class AnimBitmap: public SkinObject, public Box, public Subject<AnimBitmap>
+class AnimBitmap: public SkinObject, public Box,
+ public Subject<AnimBitmap, void*>
{
public:
AnimBitmap( intf_thread_t *pIntf, const GenericBitmap &rBitmap );
}
-void GenericWindow::onUpdate( Subject<VarBool> &rVariable )
+void GenericWindow::onUpdate( Subject<VarBool, void*> &rVariable, void*arg )
{
if( m_varVisible.get() )
{
/// Generic window class
-class GenericWindow: public SkinObject, public Observer<VarBool>
+class GenericWindow: public SkinObject, public Observer<VarBool, void*>
{
private:
friend class WindowManager;
mutable VarBoolImpl m_varVisible;
/// Method called when the observed variable is modified
- virtual void onUpdate( Subject<VarBool> &rVariable );
+ virtual void onUpdate( Subject<VarBool, void*> &rVariable , void*);
};
}
-void Tooltip::onUpdate( Subject<VarText> &rVariable )
+void Tooltip::onUpdate( Subject<VarText, void*> &rVariable , void *arg)
{
// Redisplay the tooltip
displayText( ((VarText&)rVariable).get() );
class UString;
-class Tooltip: public SkinObject, public Observer<VarText>
+class Tooltip: public SkinObject, public Observer<VarText, void*>
{
public:
/// Create a tooltip with the given font and delay (in milliseconds)
int m_xPos, m_yPos;
/// Method called when the observed variable is modified
- virtual void onUpdate( Subject<VarText> &rVariable );
+ virtual void onUpdate( Subject<VarText,void*> &rVariable, void * );
/// Display text of the tooltip
void displayText( const UString &rText );
#include <set>
// Forward declaration
-template <class S> class Observer;
+template <class S, class ARG> class Observer;
/// Template for subjects in the Observer design pattern
-template <class S> class Subject
+template <class S, class ARG> class Subject
{
public:
virtual ~Subject() {}
/// Add an observer to this subject
/// Note: adding twice the same observer is not harmful
- virtual void addObserver( Observer<S>* pObserver )
+ virtual void addObserver( Observer<S, ARG>* pObserver )
{
m_observers.insert( pObserver );
}
/// Remove an observer from this subject
/// Note: removing twice the same observer is not harmful
- virtual void delObserver( Observer<S>* pObserver )
+ virtual void delObserver( Observer<S, ARG>* pObserver )
{
m_observers.erase( pObserver );
}
/// Notify the observers when the status has changed
- virtual void notify()
+ virtual void notify( ARG arg )
{
// This stupid gcc 3.2 needs "typename"
- typename set<Observer<S>*>::const_iterator iter;
+ typename set<Observer<S, ARG>*>::const_iterator iter;
for( iter = m_observers.begin(); iter != m_observers.end();
iter++ )
{
fprintf( stderr, "iter NULL !\n" );
return;
}
- (*iter)->onUpdate( *this );
+ (*iter)->onUpdate( *this , arg );
}
}
+ /// Notify without any argument
+ virtual void notify() { notify( NULL ); }
+
protected:
Subject() {}
private:
/// Set of observers for this subject
- set<Observer<S>*> m_observers;
+ set<Observer<S, ARG>*> m_observers;
};
/// Template for observers in the Observer design pattern
-template <class S> class Observer
+template <class S, class ARG> class Observer
{
public:
virtual ~Observer() {}
/// Method called when the subject is modified
- virtual void onUpdate( Subject<S> &rSubject ) = 0;
+ virtual void onUpdate( Subject<S,ARG> &rSubject , ARG arg) = 0;
protected:
Observer() {}
/// Variable implementing the Box interface
-class VarBox: public Variable, public Box, public Subject<VarBox>
+class VarBox: public Variable, public Box, public Subject<VarBox, void*>
{
public:
VarBox( intf_thread_t *pIntf, int width = 0, int height = 0 );
}
-void VarBoolAndBool::onUpdate( Subject<VarBool> &rVariable )
+void VarBoolAndBool::onUpdate( Subject<VarBool,void *> &rVariable, void *arg )
{
notify();
}
}
-void VarBoolOrBool::onUpdate( Subject<VarBool> &rVariable )
+void VarBoolOrBool::onUpdate( Subject<VarBool,void*> &rVariable , void*arg)
{
notify();
}
}
-void VarNotBool::onUpdate( Subject<VarBool> &rVariable )
+void VarNotBool::onUpdate( Subject<VarBool, void*> &rVariable, void*arg )
{
notify();
}
/// Interface for read-only boolean variable
-class VarBool: public Variable, public Subject<VarBool>
+class VarBool: public Variable, public Subject<VarBool, void *>
{
public:
/// Get the variable type
/// Conjunction of two boolean variables (AND)
-class VarBoolAndBool: public VarBool, public Observer<VarBool>
+class VarBoolAndBool: public VarBool, public Observer<VarBool, void*>
{
public:
VarBoolAndBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
virtual bool get() const { return m_rVar1.get() && m_rVar2.get(); }
// Called when one of the observed variables is changed
- void onUpdate( Subject<VarBool> &rVariable );
+ void onUpdate( Subject<VarBool, void*> &rVariable, void* );
private:
/// Boolean variables
/// Disjunction of two boolean variables (OR)
-class VarBoolOrBool: public VarBool, public Observer<VarBool>
+class VarBoolOrBool: public VarBool, public Observer<VarBool, void*>
{
public:
VarBoolOrBool( intf_thread_t *pIntf, VarBool &rVar1, VarBool &rVar2 );
virtual bool get() const { return m_rVar1.get() || m_rVar2.get(); }
// Called when one of the observed variables is changed
- void onUpdate( Subject<VarBool> &rVariable );
+ void onUpdate( Subject<VarBool, void*> &rVariable, void* );
private:
/// Boolean variables
/// Negation of a boolean variable (NOT)
-class VarNotBool: public VarBool, public Observer<VarBool>
+class VarNotBool: public VarBool, public Observer<VarBool, void*>
{
public:
VarNotBool( intf_thread_t *pIntf, VarBool &rVar );
virtual bool get() const { return !m_rVar.get(); }
// Called when the observed variable is changed
- void onUpdate( Subject<VarBool> &rVariable );
+ void onUpdate( Subject<VarBool, void*> &rVariable, void* );
private:
/// Boolean variable
/// List variable
-class VarList: public Variable, public Subject<VarList>
+class VarList: public Variable, public Subject<VarList, void* >
{
public:
VarList( intf_thread_t *pIntf );
if( m_value != percentage )
{
m_value = percentage;
- notify();
+ notify( NULL );
}
}
/// Percentage variable
-class VarPercent: public Variable, public Subject<VarPercent>
+class VarPercent: public Variable, public Subject<VarPercent, void*>
{
public:
VarPercent( intf_thread_t *pIntf ): Variable( pIntf ), m_value( 0 ) {}
}
-void VarText::onUpdate( Subject<VarPercent> &rVariable )
+void VarText::onUpdate( Subject<VarPercent, void*> &rVariable, void *arg )
{
UString newText = get();
// If the text has changed, notify the observers
}
-void VarText::onUpdate( Subject<VarText> &rVariable )
+void VarText::onUpdate( Subject<VarText,void*> &rVariable, void *arg )
{
UString newText = get();
// If the text has changed, notify the observers
/// String variable
-class VarText: public Variable, public Subject<VarText>,
- public Observer<VarPercent>, public Observer< VarText >
+class VarText: public Variable, public Subject<VarText, void*>,
+ public Observer<VarPercent, void*>,
+ public Observer< VarText,void*>
{
public:
// Set substVars to true to replace "$X" variables in the text
virtual const UString get() const;
/// Methods called when an observed variable is modified
- virtual void onUpdate( Subject<VarPercent> &rVariable );
- virtual void onUpdate( Subject<VarText> &rVariable );
+ virtual void onUpdate( Subject<VarPercent, void*> &rVariable, void* );
+ virtual void onUpdate( Subject<VarText, void*> &rVariable, void* );
private:
/// Variable type
* var_tree.hpp
*****************************************************************************
* Copyright (C) 2005 VideoLAN
- * $Id: var_bool.hpp 9934 2005-02-15 13:55:08Z courmisch $
+ * $Id$
*
* Authors: Antoine Cellerier <dionoea@videolan.org>
*
#include "var_percent.hpp"
/// Tree variable
-class VarTree: public Variable, public Subject<VarTree>
+class VarTree: public Variable, public Subject<VarTree, int>
{
public:
VarTree( intf_thread_t *pIntf );
}
-void EqualizerBands::onUpdate( Subject<VarPercent> &rBand )
+void EqualizerBands::onUpdate( Subject<VarPercent,void*> &rBand, void *arg )
{
// Make sure we are not called from set()
if (!m_isUpdating)
/// Variable for graphical equalizer
-class EqualizerBands: public SkinObject, public Observer<VarPercent>
+class EqualizerBands: public SkinObject, public Observer<VarPercent, void*>
{
public:
/// Number of bands
bool m_isUpdating;
/// Callback for band updates
- virtual void onUpdate( Subject<VarPercent> &rBand );
+ virtual void onUpdate( Subject<VarPercent, void*> &rBand , void *);
};
}
}
buildTree();
- notify();
+ notify( 1 );
}
void Playtree::action( VarTree *pItem )
void Playtree::onChange()
{
buildTree();
- notify();
+ notify( 1 );
}
void Playtree::onUpdate( int id )
msg_Warn(getIntf(), "Cannot find node with id %d", id );
}
// TODO update only the right node
- notify();
+ notify( 0 );
}
void Playtree::buildNode( playlist_item_t *pNode, VarTree &rTree )