/home/koen/project/wt/cvs/wt/examples/dragdrop/DragExample.C

Go to the documentation of this file.
00001 #include <Wt/WApplication>
00002 #include <Wt/WEnvironment>
00003 #include <Wt/WContainerWidget>
00004 #include <Wt/WImage>
00005 
00006 #include "Character.h"
00007 
00008 using namespace Wt;
00009 
00014 
00020 WImage *createDragImage(const char *url, const char *smallurl,
00021                         const char *mimeType,
00022                         WContainerWidget *p)
00023 {
00024   WImage *result = new WImage(url, p);
00025   WImage *dragImage = new WImage(smallurl, p);
00026 
00027   /*
00028    * Set the image to be draggable, showing the other image (dragImage)
00029    * to be used as the widget that is visually dragged.
00030    */
00031   result->setDraggable(mimeType, dragImage, true);
00032 
00033   return result;
00034 }
00035 
00036 WApplication *createApplication(const WEnvironment& env)
00037 {
00038   WApplication *app = new WApplication(env);
00039   app->setTitle(L"Drag &amp; drop");
00040   new WText("<h1>Wt Drag &amp; drop example.</h1>", app->root());
00041 
00042   new WText("<p>Help these people with their decision by dragging one of "
00043             "the pills.</p>", app->root());
00044 
00045   if (!env.javaScript()) {
00046     new WText("<i>This examples requires that javascript support is "
00047               "enabled.</i>", app->root());
00048   }
00049 
00050   WContainerWidget *pills = new WContainerWidget(app->root());
00051   pills->setContentAlignment(WWidget::AlignCenter);
00052 
00053   createDragImage("icons/blue-pill.jpg",
00054                   "icons/blue-pill-small.png",
00055                   "blue-pill", pills);
00056   createDragImage("icons/red-pill.jpg",
00057                   "icons/red-pill-small.png",
00058                   "red-pill", pills);
00059 
00060   WContainerWidget *dropSites = new WContainerWidget(app->root());
00061 
00062   new Character(L"Neo", dropSites);
00063   new Character(L"Morpheus", dropSites);
00064   new Character(L"Trinity", dropSites);
00065 
00066   app->useStyleSheet("dragdrop.css");
00067 
00068   return app;
00069 }
00070 
00071 int main(int argc, char **argv)
00072 {
00073   return WRun(argc, argv, &createApplication);
00074 }
00075 

Generated on Fri Jul 25 17:05:59 2008 for Wt by doxygen 1.5.3