// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef WFLASHOBJECT_H_
#define WFLASHOBJECT_H_

#include <Wt/WContainerWidget>

namespace Wt {

/*! \class WFlashObject Wt/WFlashObject Wt/WFlashObject
 *  \brief A widget that renders a Flash object (also known as Flash movie).
 *
 * This class dynamically loads a .swf Flash file in the browser.
 *
 * This widget is a container, which means that you can instantiate
 * additional widgets inside it. These widgets can for example be the
 * content that is shown when a Flash player is not available on the
 * system or when JavaScript is disabled.
 *
 * \if cpp
 * Usage example:
 * \code
 * WFlash *player = new WFlash("dummy.swf", parent);
 * player->resize(300, 600);
 * player->setFlashParameter("allowScriptAccess", "always");
 * player->setFlashParameter("quality", "high");
 * player->setFlashParameter("bgcolor", "#aaaaaa");
 * player->setFlashVariable("someVar", "foo");
 * \endcode
 * \endif
 *
 * This class uses <i>resourcesURL</i>"/swfobject.js", a companion
 * JavaScript library, which is distributed with %Wt in the resources
 * folder, see also \ref deployment "deployment and resources".
 *
 * <h3>CSS</h3>
 *
 * Styling through CSS is not applicable.
 */
class WT_API WFlashObject : public WContainerWidget
{
public:
  /*! \brief Constructs a Flash widget.
   */
  WFlashObject(const std::string &url, WContainerWidget *parent = 0);

  /*! \brief Destructor
   *
   * The Flash object is removed.
   */
  ~WFlashObject();

  virtual void resize(const WLength &width, const WLength &height);

  /*! \brief Sets a Flash parameter.
   *
   * The Flash parameters are items such as quality, scale, menu, ...
   * Depending on the browser they are passed as attributes or PARAM
   * objects to the Flash movie. See the adobe website for more information
   * about these parameters:
   * http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_12701
   *
   * Setting the same Flash parameter a second time will overwrite the
   * previous value. Flash parameters can only be set before the widget
   * is rendered for the first time, so it is recommended to call this
   * method shortly after construction before returning to the idle loop.
   */
  void setFlashParameter(const std::string &name, const WString &value);

  /*! \brief Sets a Flash variable.
   *
   * This method is a helper function to set variable values in the
   * flashvars parameter.
   *
   * Setting the same Flash parameter a second time will overwrite the
   * previous value. Flash parameters can only be set before the widget
   * is rendered for the first time, so it is recommended to call this
   * method shortly after construction before returning to the idle loop.
   */
  void setFlashVariable(const std::string &name, const WString &value);

  /*! \brief A JavaScript expression that returns the DOM node of the Flash
   *         object.
   *
   * The Flash object is not stored in jsRef(), but in jsFlashRef(). Use this
   * method in conjuction with WApplication::doJavaScript() or JSlot in custom
   * JavaScript code to refer to the Flash content.
   */
  std::string jsFlashRef() const;

protected:
  void getDomChanges(std::vector<DomElement *>& result,
                     WApplication *app);
  virtual DomElement *createDomElement(WApplication *app);

private:
  std::string url_;
  bool isRendered_;
  bool sizeChanged_;
  std::map<std::string, WString> parameters_;
  std::map<std::string, WString> variables_;

};

}

#endif // WFLASHOBJECT_H_

