Wt::JSignal< A1, A2, A3, A4, A5, A6 > Class Template Reference
[Signal/slot system]

A signal to relay JavaScript to C++ calls. More...

#include <Wt/WJavaScript>

Inheritance diagram for Wt::JSignal< A1, A2, A3, A4, A5, A6 >:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 JSignal (WObject *object, const std::string &name, bool collectSlotJavaScript=false)
 Construct a signal for the given object, and name.
 ~JSignal ()
 Destructor.
const std::string & name () const
 Returns the signal name.
const std::string createCall (std::string arg1=std::string(), std::string arg2=std::string(), std::string arg3=std::string(), std::string arg4=std::string(), std::string arg5=std::string(), std::string arg6=std::string()) const
 Returns a JavaScript call that triggers the signal.
virtual bool isConnected () const
 Returns whether the signal is connected to at least one slot.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)())
 Connect a slot that takes no arguments.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1))
 Connect a slot that takes one argument.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1, A2))
 Connect a slot that takes two arguments.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1, A2, A3))
 Connect a slot that takes three arguments.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4))
 Connect a slot that takes four arguments.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4, A5))
 Connect a slot that takes five arguments.
template<class T, class V>
boost::signals::connection connect (T *target, void(V::*method)(A1, A2, A3, A4, A5, A6))
 Connect a slot that takes six arguments.
void connect (JSlot &slot)
 Connect a slot that is specified as JavaScript only.
void emit (A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none)
 Emit the signal.
void operator() (A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none)
 Emit the signal.


Detailed Description

template<typename A1 = NoClass, typename A2 = NoClass, typename A3 = NoClass, typename A4 = NoClass, typename A5 = NoClass, typename A6 = NoClass>
class Wt::JSignal< A1, A2, A3, A4, A5, A6 >

A signal to relay JavaScript to C++ calls.

A JSignal, like an EventSignal, provides communicates events from JavaScript to C++ code. However, it not tied to a built-in event. Instead, it can be emitted from within custom JavaScript code using the JavaScript Wt.emit() function.

The signal is identified by a unique name within the scope of a WObject, or a unique global name (when declaring the signal in your WApplication).

The signal supports up to 6 arguments. Values for these arguments may be specified in the JavaScript Wt.emit() (or the deprecated global function WtSignalEmit()).

To define a signal within a widget, consider the following example:

 class MyWidget : public WCompositeWidget
 {
 public:
   // ...
   JSignal<std::string, int> doSome;
   // ...
 };

 MyWidget::MyWidget()
   : doSome(this, "dosome")
 { 
   //...
 }

The following JavaScript code will then emit the signal for a DOM element element that corresponds to a widget of class MyWidget:

 Wt.emit(element, 'dosome', 'foo', 42);

The argument element is either a DOM element, or the object ID of a WObject. The conversion between the JavaScript argument (ax) and the C++ type Ax uses boost::lexical_cast<Ax>(ax).

By adding a signal to your WApplication object, you define a 'global' signal. In that case, the first argument to Wt.emit() may also be the constant 'Wt':

 Wt.emit(Wt, 'dosome', 'foo', 42);

See also:
WWidget::jsRef(), WObject::id()

Constructor & Destructor Documentation

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
Wt::JSignal< A1, A2, A3, A4, A5, A6 >::JSignal ( WObject object,
const std::string &  name,
bool  collectSlotJavaScript = false 
) [inline]

Construct a signal for the given object, and name.

The given name must be unique for all user signals specified for the object object. Ownership of the signal is not transferred to the object.

If collectSlotJavaScript is true, then javascript specified for connected slots (using JSlot) or learned by stateless slot learning, is collected to client-side JavaScript. Therefore the signal must be called from client-side JavaScript by using createCall().

Reimplemented in Wt::JSignal< void >.


Member Function Documentation

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
const std::string Wt::JSignal< A1, A2, A3, A4, A5, A6 >::createCall ( std::string  arg1 = std::string(),
std::string  arg2 = std::string(),
std::string  arg3 = std::string(),
std::string  arg4 = std::string(),
std::string  arg5 = std::string(),
std::string  arg6 = std::string() 
) const [inline]

Returns a JavaScript call that triggers the signal.

For a JSignal constructed with inlineJavaScript = false, this is simply Wt.emit([element], [name], arg1, ...) with the element corresponding to the owner object, and name corresponding to the signal name. Otherwise, the inline JavaScript from slots is included as well.

Reimplemented in Wt::JSignal< void >.

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)()  method 
) [inline]

Connect a slot that takes no arguments.

The slot is specified as a method of class V, which is equal to class V, or a base class of class V. In addition, to check for stateless implementations, class T must be also be a descendant of WObject. Thus, the following statement must return a non-null pointer:

 WObject *o = dynamic_cast<WObject *>(dynamic_cast<V *>(target));

If a stateless implementation is specified for the slot, then the visual behaviour will be learned in terms of JavaScript, and will be cached on the client side for instant feed-back, in addition running the slot on the server.

Reimplemented in Wt::JSignal< void >.

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1)  method 
) [inline]

Connect a slot that takes one argument.

This is only possible for signals that take at least one argument.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2)  method 
) [inline]

Connect a slot that takes two arguments.

This is only possible for signals that take at least two arguments.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3)  method 
) [inline]

Connect a slot that takes three arguments.

This is only possible for signals that take at least three arguments.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4)  method 
) [inline]

Connect a slot that takes four arguments.

This is only possible for signals that take at least four arguments.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4, A5)  method 
) [inline]

Connect a slot that takes five arguments.

This is only possible for signals that take at least five arguments.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
template<class T, class V>
boost::signals::connection Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( T *  target,
void(V::*)(A1, A2, A3, A4, A5, A6)  method 
) [inline]

Connect a slot that takes six arguments.

This is only possible for signals that take at least six arguments.

See also:
connect(T *target, void (V::*method)())

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void Wt::JSignal< A1, A2, A3, A4, A5, A6 >::connect ( JSlot slot  )  [inline]

Connect a slot that is specified as JavaScript only.

This will provide a client-side connection between the event and some JavaScript code as implemented by the slot. Unlike other connects, this does not cause the event to propagated to the application, and thus the state changes induced by the slot are invisible to the server-side.

Reimplemented in Wt::JSignal< void >.

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void Wt::JSignal< A1, A2, A3, A4, A5, A6 >::emit ( A1  a1 = NoClass::none,
A2  a2 = NoClass::none,
A3  a3 = NoClass::none,
A4  a4 = NoClass::none,
A5  a5 = NoClass::none,
A6  a6 = NoClass::none 
) [inline]

Emit the signal.

The arguments must exactly match the arguments of the target function.

This will cause all connected slots to be triggered, with the given arguments.

template<typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void Wt::JSignal< A1, A2, A3, A4, A5, A6 >::operator() ( A1  a1 = NoClass::none,
A2  a2 = NoClass::none,
A3  a3 = NoClass::none,
A4  a4 = NoClass::none,
A5  a5 = NoClass::none,
A6  a6 = NoClass::none 
) [inline]

Emit the signal.

This is equivalent to emit().

See also:
emit


Generated on Fri Jul 25 17:56:38 2008 for Wt by doxygen 1.5.3