Services.C 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2008 Emweb bvba
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include "StyleLayout.h"
  7. #include "EventDisplayer.h"
  8. #include <Wt/WApplication>
  9. #include <Wt/WText>
  10. #include <Wt/WComboBox>
  11. #include <Wt/WPushButton>
  12. #include <Wt/WDefaultLoadingIndicator>
  13. #include <Wt/WOverlayLoadingIndicator>
  14. #include "EmwebLoadingIndicator.h"
  15. #if defined(WT_THREADED) || defined(WT_TARGET_JAVA)
  16. #include <boost/thread.hpp>
  17. #else
  18. #if WT_WIN32
  19. #include <windows.h>
  20. #endif
  21. #endif
  22. StyleLayout::StyleLayout(EventDisplayer *ed)
  23. : ControlsWidget(ed, true)
  24. {
  25. addText(tr("style-layout-intro"), this);
  26. }
  27. void StyleLayout::populateSubMenu(WMenu *menu)
  28. {
  29. menu->addItem("CSS", css());
  30. menu->addItem("WLoadingIndicator", wLoadingIndicator());
  31. }
  32. WWidget *StyleLayout::css()
  33. {
  34. return addText(tr("style-and-layout-css"));
  35. }
  36. WWidget *StyleLayout::wLoadingIndicator()
  37. {
  38. WContainerWidget *result = new WContainerWidget();
  39. topic("WLoadingIndicator", result);
  40. addText(tr("style-WLoadingIndicator"), result);
  41. //fix for the WOverlayLoadingIndicator
  42. WApplication::instance()->styleSheet().addRule("body", "margin: 0px");
  43. addText("Select a loading indicator: ", result);
  44. WComboBox *cb = new WComboBox(result);
  45. cb->addItem("WDefaultLoadingIndicator");
  46. cb->addItem("WOverlayLoadingIndicator");
  47. cb->addItem("EmwebLoadingIndicator");
  48. cb->setCurrentIndex(0);
  49. cb->sactivated().connect(this, &StyleLayout::loadingIndicatorSelected);
  50. new WBreak(result);
  51. WPushButton *load = new WPushButton("Load!", result);
  52. load->clicked().connect(this, &StyleLayout::load);
  53. return result;
  54. }
  55. void StyleLayout::loadingIndicatorSelected(WString indicator)
  56. {
  57. if (indicator.toUTF8() == "WDefaultLoadingIndicator") {
  58. WApplication::instance()
  59. ->setLoadingIndicator(new WDefaultLoadingIndicator());
  60. } else if (indicator.toUTF8() == "WOverlayLoadingIndicator") {
  61. WApplication::instance()
  62. ->setLoadingIndicator(new WOverlayLoadingIndicator());
  63. } else if (indicator.toUTF8() == "EmwebLoadingIndicator") {
  64. WApplication::instance()
  65. ->setLoadingIndicator(new EmwebLoadingIndicator());
  66. }
  67. }
  68. void StyleLayout::load(Wt::WMouseEvent) {
  69. #if defined(WT_THREADED) || defined(WT_TARGET_JAVA)
  70. boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
  71. #else
  72. #ifdef WT_WIN32
  73. Sleep(2000);
  74. #else
  75. sleep(2);
  76. #endif //WIN32
  77. #endif // WT_THREADED
  78. }