HtmlImage.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Text;
  3. namespace ClearSlideLibrary.HtmlController
  4. {
  5. internal class HtmlImage : HtmlPresentationElement
  6. {
  7. public string HyperLink { get; set; }
  8. public string FileExtension { get; set; }
  9. public HtmlImage(string id, int width, int height,
  10. int top, int left, bool invisible,
  11. bool animatable, string extension)
  12. {
  13. base.id = id;
  14. base.top = top;
  15. base.left = left;
  16. base.width = width;
  17. base.height = height;
  18. base.invisible = invisible;
  19. base.animatable = animatable;
  20. this.FileExtension = extension;
  21. }
  22. public override string DrawElement()
  23. {
  24. StringBuilder imageBuilder = new StringBuilder();
  25. //add hyperlink into output html tag as style element.
  26. string hyperlinkString="";
  27. bool cursorPointer = false;
  28. if (HyperLink != null)
  29. {
  30. cursorPointer = true;
  31. hyperlinkString = "onclick=\"openHyperLink(this,1,'" + HyperLink + "')\" onmouseout=\"OutListener()\" onmouseover=\"OverListener()\"";
  32. }
  33. string style = invisible ? "DC0" : "DC1";
  34. String idForHtml = id;
  35. if ("gif".Equals(FileExtension))
  36. idForHtml += ".gif";
  37. else if ("jpg".Equals(FileExtension) || "jpeg".Equals(FileExtension))
  38. idForHtml += ".jpg";
  39. else if ("bmp".Equals(FileExtension))
  40. idForHtml += ".bmp";
  41. else
  42. idForHtml += ".png";
  43. if (animatable)
  44. {
  45. imageBuilder.Append("<div id=\"" + id + "\" style=\"top:" + top.ToString() + "px;left:" + left.ToString() +
  46. "px;height:" + height.ToString() + "px;width:" + width.ToString() + "px;" + (cursorPointer ? "cursor:pointer" : "") + "\"" + hyperlinkString + ">");
  47. imageBuilder.Append("<div class=\"" + style + "\" id=\"" + idForHtml + "\">");
  48. imageBuilder.Append("<img />");
  49. imageBuilder.Append("</div>");
  50. imageBuilder.Append("</div>");
  51. }
  52. else
  53. {
  54. imageBuilder.Append("<div id=\"" + id + "\" style=\"top:" + top.ToString() + "px;left:" + left.ToString() +
  55. "px;height:" + height.ToString() + "px;width:" + width.ToString() + "px;" + (cursorPointer ? "cursor:pointer" : "") + "\"" + hyperlinkString + ">");
  56. imageBuilder.Append("<div class=\"" + style + "\" id=\"" + idForHtml + "\">");
  57. imageBuilder.Append("<img />");
  58. imageBuilder.Append("</div>");
  59. imageBuilder.Append("</div>");
  60. }
  61. return imageBuilder.ToString();
  62. }
  63. public override string ToString()
  64. {
  65. Console.WriteLine("The top is:" + top);
  66. Console.WriteLine("The left is:" + left);
  67. Console.WriteLine("The width is:" + width);
  68. Console.WriteLine("The height is:" + height);
  69. return string.Format("[{0}, {1}, {2}, {3}]", top, left, width, height);
  70. }
  71. }
  72. }