Thanks, this function worked perfect, it was what I was looking for, and
the problem I am having has nothing to do with it, 
I have tried several different ways to do the same thing, and it fails
every time, I am running the code on:
http://wittywizard.org/
You can see that the first time it works fine, but if you try to change
the combobox, it fails, if I do not bind the tags it works fine,
the WidgetFunction does not really matter, I have tired many other ways
to bind it, all fail.
Here is the source code, I made it minimal
http://wittywizard.org/resources/Audio.zip
I made lots of comments to try to explain the problems,
in the function AudioManImpl::CreateAudio
I have a matrix that describes the problem

* useTemplate | useTemplateData | useWidgetFun | useWraper | Pass | Description
*     T       |        0        |    0         |    F      |  F   | Template - 
tag      - registerType & addFunction external
*     T       |        0        |    0         |    T      |  F   | Template - 
tag      - Wraper - registerType & addFunction external - Note: theme for Flash 
is not working
*     T       |        0        |    1         |    F      |  F   | Template - 
tag      - setTemplate (no type registered: audio)
*     T       |        0        |    2         |    F      |  T   | Template - 
tag      - WText (${widget:audio id='audio0' class='wtaudio' type='audio/mpeg' 
width='580' height='33' src='/resources/LaSera-NeverComeAround.mp3' 
altsrc='/resources/LaSera-NeverComeAround.mp3' title='La Sera - Never Come 
Around'})
*     T       |        1        |    2         |    F      |  T   | Template - 
HTML5    - WText
*     T       |        2        |    0         |    F      |  F   | Template - 
Full tag - registerType & addFunction external
*     T       |        2        |    0         |    T      |  F   | Template - 
Full tag - Wraper - registerType & addFunction external  - Note: theme for 
Flash is not working
*     F       |       NA        |    NA        |    NA     |  T   | Use Audio 
player directly


and some variables to setup all the conditions to try to show how
different solutions fail or pass, 
My problem is simple, I have a menu and comboboxs, 
I want to chose different audios (this are all the same for simplicity)
but the function works the first time, and will not allow me to use the
combobox to navigate.
This problem is some fundamental issue with programming I did not
understand or its a bug.
I have been stuck on this issue for months now, I have tried everything
I can think of.
My original program uses Video, but displays pages that contain audio
tags, it fails for the audio tags, did not matter how they got there,
bind them, or just add them in as xhtml,
<audio controls='controls' id='audio' class='wtaudio' width='580'
height='33'> <source
src='/resources/LaSera-NeverComeAround.mp3'</source></audio>.
Minor issues with Widget function are setTemplate (simple fix, but I did
not find it yet), and Wraper losing theme for alternative content, flash
fall back.
Once I get passed this problem, I would like to add all control tags I
can to make this class work for any controls.

Thanks
Jeffrey Flesher

On Fri, 2014-08-01 at 13:12 +0200, Koen Deforche wrote:
> Hey Jeffrey,
> 
> 
> 
> 2014-07-27 22:54 GMT+02:00 Jeffrey Scott Flesher Gmail
> <jeffrey.scott.fles...@gmail.com>:
> 
>         I have a temple like this:
>         
>         <?xml version="1.0" encoding="UTF-8" ?>
>         <messages>
>             <message id="x-template">
>                 <wt id='audio1' class='audio' type='audio/mpeg'
>         width='640' height='360' src='/resources/audio.mp3'></wt>
>                 ${audio1}
>                 <wt id='audio2' class='audio' type='audio/mpeg'
>         width='640' height='360' src='/resources/audio.mp3'></wt>
>                 ${audio2}
>             </message>
>         </messages>
>         
> 
> 
> You can do this if you change your template like this:
> 
> 
>         ${widget:audio id='audio1' type='audio/mpeg' width='640'
> height='360' src='/resources/audio.mp3'}
>         ${widget:audio id='audio2' type='audio/mpeg' width='640'
> height='360' src='/resources/audio.mp3'}
> 
> 
> 
> This would then use a 'widget' function that you add to the template,
> and which is implemented below:
> 
> 
> class WidgetFunction
> {
> public:
>   typedef boost::function<Wt::WWidget *(const
> std::vector<Wt::WString>&)>
>     InstatiateWidget;
> 
> 
>   bool operator()(Wt::WTemplate *t, const std::vector<Wt::WString>&
> args,
>  std::ostream& result);
> 
> 
>   void registerType(const std::string& name, InstatiateWidget
> instatiate);
> 
> 
> private:
>   typedef std::map<std::string, InstatiateWidget> RegistryMap;
>   RegistryMap registeredTypes_;
> 
> 
>   static std::string getArg(const std::string& name,
>    const std::vector<Wt::WString>& args);
> };
> 
> 
> bool WidgetFunction::operator()(Wt::WTemplate *t,
> const std::vector<Wt::WString>& args,
> std::ostream& result)
> {
>   std::string name = args[0].toUTF8();
> 
> 
>   RegistryMap::const_iterator i = registeredTypes_.find(name);
>   if (i == registeredTypes_.end()) {
>     result << "?? WidgetFunction: no type registered: " << name <<
> "??";
>   } else {
>     std::string id = getArg("id", args);
> 
> 
>     Wt::WWidget *w = 0;
>     if (!id.empty())
>       w = t->resolveWidget(id);
> 
> 
>     if (!w) {
>       w = i->second(args);
> 
> 
>       std::string cl = getArg("class", args);
>       if (!cl.empty())
> w->addStyleClass(cl);
>     }
> 
> 
>     if (!w) {
>       result << "?? WidgetFunction: could not create instance of type
> "
>     << name << "??";
>     } else {
>       if (id.empty())
> id = w->id();
>     }
> 
> 
>     t->bindWidget(id, w);
> 
> 
>     Wt::WString text = Wt::WString::fromUTF8("${" + id + "}");
>     t->renderTemplateText(result, text);
>   }
> 
> 
>   return true;
> }
> 
> 
> void WidgetFunction::registerType(const std::string& name,
>  InstatiateWidget instantiate)
> {
>   registeredTypes_[name] = instantiate;
> }
> 
> 
> std::string WidgetFunction::getArg(const std::string& name,
>   const std::vector<Wt::WString>& args)
> {
>   for (unsigned i = 0; i < args.size(); ++i) {
>     std::string s = args[i].toUTF8();
>     if (boost::starts_with(s, name + "="))
>       return s.substr(name.length()+1);
>   }
> 
> 
>   return std::string();
> }
> 
> 
> To register a new 'type', for example 'line-edit' you can then use:
> 
> 
> Wt::WWidget *createLineEdit(const std::vector<Wt::WString>& args)
> {
>   return new Wt::WLineEdit(); // could also process the arguments...
> }
> 
> 
> WidgetFunction widgetFunction; 
> widgetFunction.registerType("line-edit", createLineEdit);
> 
> 
> Using it, for example:
> 
> 
>   Wt::WTemplate *t = new Wt::WTemplate("${widget:line-edit}");
> 
>   t->addFunction("widget", widgetFunction);
> 
> 
> Regards,
> koen


> _______________________________________________ witty-interest mailing list 
> witty-interest@lists.sourceforge.net 
> https://lists.sourceforge.net/lists/listinfo/witty-interest
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to