ToolbarSettings.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. using FastReport.Web.Toolbar;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Drawing;
  5. using System.Linq;
  6. namespace FastReport.Web
  7. {
  8. public class ToolbarSettings
  9. {
  10. public static ToolbarSettings Default => new ToolbarSettings();
  11. public bool Show { get; set; } = true;
  12. #if DIALOGS
  13. public bool ShowOnDialogPage { get; set; } = true;
  14. #endif
  15. [Obsolete("Please, use Position")]
  16. public bool ShowBottomToolbar
  17. {
  18. get => Position == Positions.Bottom;
  19. set
  20. {
  21. if (value)
  22. {
  23. Position = Positions.Bottom;
  24. }
  25. else
  26. Position = default;
  27. }
  28. }
  29. /// <summary>
  30. /// ExportMenu settings
  31. /// </summary>
  32. public ExportMenuSettings Exports { get; set; } = ExportMenuSettings.Default;
  33. public bool ShowPrevButton { get; set; } = true;
  34. public bool ShowNextButton { get; set; } = true;
  35. public bool ShowFirstButton { get; set; } = true;
  36. public bool ShowLastButton { get; set; } = true;
  37. public bool ShowRefreshButton { get; set; } = true;
  38. public bool ShowZoomButton { get; set; } = true;
  39. /// <summary>
  40. /// Show Print menu
  41. /// </summary>
  42. public bool ShowPrint { get; set; } = true;
  43. public bool PrintInHtml { get; set; } = true;
  44. /// <summary>
  45. /// If enabled, the toolbar will follow the scrolling of the report.
  46. /// </summary>
  47. /// <remarks>
  48. /// Default value: false
  49. /// </remarks>
  50. public bool Sticky { get; set; } = false;
  51. #if !OPENSOURCE
  52. public bool PrintInPdf { get; set; } = true;
  53. #endif
  54. /// <summary>
  55. /// Use to change ToolbarColor,
  56. /// Default value Color.WhiteSmoke
  57. /// </summary>
  58. public Color Color { get; set; } = Color.WhiteSmoke;
  59. /// <summary>
  60. /// Use to change Toolbar DropDownMenuColor,
  61. /// Default value Color.White
  62. /// </summary>
  63. public Color DropDownMenuColor { get; set; } = Color.White;
  64. /// <summary>
  65. /// Use to change Toolbar DropDownMenuText Color,
  66. /// Default value Color.Black
  67. /// </summary>
  68. public Color DropDownMenuTextColor { get; set; } = Color.Black;
  69. /// <summary>
  70. /// Use to change Toolbar Position in report,
  71. /// Default value Position.Top
  72. /// </summary>
  73. public Positions Position { get; set; } = Positions.Top;
  74. /// <summary>
  75. /// Use to add Roundness to Toolbar,
  76. /// Default value RoundnessEnum.High
  77. /// </summary>
  78. public RoundnessEnum Roundness { get; set; } = RoundnessEnum.High;
  79. /// <summary>
  80. /// Use to change content position in Toolbar,
  81. /// Default value ContentPositions.Center
  82. /// </summary>
  83. public ContentPositions ContentPosition { get; set; } = ContentPositions.Center;
  84. /// <summary>
  85. /// Use to change Icons color in Toolbar,
  86. /// Default value IconColors.Black
  87. /// </summary>
  88. public IconColors IconColor { get; set; } = IconColors.Black;
  89. /// <summary>
  90. /// Use to add Transparency in icon Toolbar,
  91. /// Default value IconTransparencyEnum.None
  92. /// </summary>
  93. public IconTransparencyEnum IconTransperency { get; set; } = IconTransparencyEnum.None;
  94. /// <summary>
  95. /// Use to change Font in Toolbar,
  96. /// Default value null
  97. /// <para>Example syntax : new Font("Arial", 14 , FontStyle.Bold)</para>
  98. /// </summary>
  99. public Font FontSettings { get; set; } = null;
  100. public int Height { get; set; } = 40;
  101. internal List<ToolbarElement> Elements { get; set; } = new List<ToolbarElement>();
  102. /// <summary>
  103. /// Adds an item to the toolbar
  104. /// </summary>
  105. /// <param name="element">Any inheritor of ToolbarElement. Can be a TolbarButton, ToolbarSelect, or ToolbarInput</param>
  106. public void InsertToolbarElement(ToolbarElement element)
  107. {
  108. if (Elements.Any(x => x.Name == element.Name)) return;
  109. var index = Elements.FindIndex(x => x.Position > element.Position);
  110. if (index < 0 || element.Position == -1)
  111. {
  112. if (Elements.Count != 0)
  113. element.Position = Elements.Max(x => x.Position) + 1;
  114. else
  115. element.Position = 0;
  116. Elements.Add(element);
  117. }
  118. else
  119. {
  120. Elements.Insert(index, element);
  121. }
  122. }
  123. internal int ToolbarSlash
  124. {
  125. get
  126. {
  127. switch (Position)
  128. {
  129. case Positions.Left:
  130. case Positions.Right:
  131. return 90;
  132. default:
  133. return 20;
  134. }
  135. }
  136. }
  137. internal string StickyToolbarTags
  138. {
  139. get
  140. {
  141. if (Sticky)
  142. {
  143. string tags = "position: sticky; position: -webkit-sticky; ";
  144. if(TopOrBottom == -1)
  145. {
  146. if (Position == Positions.Left || Position == Positions.Right)
  147. {
  148. if (ContentPosition == ContentPositions.Right)
  149. tags += "bottom: 10px; left: 10px; right: 10px;";
  150. else if (ContentPosition == ContentPositions.Center)
  151. tags += "top: 10px; bottom: 10px; left: 10px; right: 10px;";
  152. }
  153. else
  154. tags += "top: 10px; left: 10px; right: 10px;";
  155. }
  156. else
  157. tags += "bottom: 10px; left: 10px; right: 10px;";
  158. return tags;
  159. }
  160. else
  161. return "";
  162. }
  163. }
  164. internal string StickyToolbarTabsTags
  165. {
  166. get
  167. {
  168. if (Sticky)
  169. {
  170. int paddingVertical = Height + 10;
  171. float paddingHorizontal = Height * 1.55f + 10;
  172. string tags = "position: sticky; position: -webkit-sticky; ";
  173. if (TopOrBottom == -1)
  174. {
  175. if (Position == Positions.Left || Position == Positions.Right)
  176. {
  177. if (ContentPosition == ContentPositions.Right)
  178. tags += $@"bottom: {paddingVertical}px; left: {paddingHorizontal}px; right: {paddingHorizontal}px;";
  179. else if (ContentPosition == ContentPositions.Center)
  180. tags += $@"top: {paddingVertical}px; bottom: {paddingVertical}px; left: {paddingHorizontal}px; right: {paddingHorizontal}px;";
  181. }
  182. else
  183. tags += $@"top: {paddingVertical}px; left: 10px; right: 10px;";
  184. }
  185. else
  186. tags += $@"bottom: {paddingVertical}px; left: 10px; right: 10px;";
  187. return tags;
  188. }
  189. else
  190. return "";
  191. }
  192. }
  193. internal string ModalContainerPosition => Sticky ? "position: fixed;" : "";
  194. internal string DropDownListPosition => Position == Positions.Bottom ? "bottom: 100%" : "";
  195. internal string DropDownListBorder => Position == Positions.Bottom ? "12px 12px 0px 0px" : "0px 0px 12px 12px";
  196. internal int ToolbarNarrow
  197. {
  198. get
  199. {
  200. switch (Position)
  201. {
  202. case Positions.Left:
  203. case Positions.Right:
  204. return 90;
  205. default:
  206. return 0;
  207. }
  208. }
  209. }
  210. internal string UserFontSettings
  211. {
  212. get
  213. {
  214. if (FontSettings != null)
  215. {
  216. return FontSettings.Size + "em " + FontSettings.OriginalFontName + " " + FontSettings.Style;
  217. }
  218. else
  219. return "15em Verdana,Arial sans-serif Regular";
  220. }
  221. }
  222. internal string VerticalToolbarHeight
  223. {
  224. get
  225. {
  226. switch (Position)
  227. {
  228. case Positions.Left:
  229. case Positions.Right:
  230. return "fit-content";
  231. default:
  232. return Height.ToString() + "px";
  233. }
  234. }
  235. }
  236. internal int TopOrBottom
  237. {
  238. get
  239. {
  240. switch (Position)
  241. {
  242. case Positions.Bottom:
  243. return 1;
  244. default:
  245. return -1;
  246. }
  247. }
  248. }
  249. internal string Vertical
  250. {
  251. get
  252. {
  253. switch (Position)
  254. {
  255. case Positions.Right:
  256. return "row-reverse";
  257. case Positions.Left:
  258. return "row";
  259. default:
  260. return "column";
  261. }
  262. }
  263. }
  264. internal int DropDownMenuPositionLeft
  265. {
  266. get
  267. {
  268. switch (Position)
  269. {
  270. case Positions.Left:
  271. case Positions.Right:
  272. return Height + 10;
  273. default:
  274. return 0;
  275. }
  276. }
  277. }
  278. internal int DropDownMenuPositionTops
  279. {
  280. get
  281. {
  282. switch (Position)
  283. {
  284. case Positions.Right:
  285. case Positions.Left:
  286. return 7;
  287. default:
  288. return 0;
  289. }
  290. }
  291. }
  292. internal string RowOrColumn
  293. {
  294. get
  295. {
  296. switch (Position)
  297. {
  298. case Positions.Left:
  299. case Positions.Right:
  300. return "column";
  301. default:
  302. return "row";
  303. }
  304. }
  305. }
  306. internal string Content
  307. {
  308. get
  309. {
  310. switch (ContentPosition)
  311. {
  312. case ContentPositions.Center:
  313. return "center";
  314. case ContentPositions.Right:
  315. return "flex-end";
  316. case ContentPositions.Left:
  317. return "flex-start";
  318. default:
  319. return "flex-start";
  320. }
  321. }
  322. }
  323. internal string DropDownMenuPosition
  324. {
  325. get
  326. {
  327. switch (Position)
  328. {
  329. case Positions.Left:
  330. return "left:" + Height + "px;" + "text-align:left;" + "top:8px;";
  331. case Positions.Right:
  332. return "right:" + Height + "px;" + "text-align:right;" + "top:8px;";
  333. case Positions.Bottom:
  334. return "bottom:" + Height + "px;";
  335. default:
  336. return "top:" + Height + "px;";
  337. }
  338. }
  339. }
  340. internal string TabsPositionSettings
  341. {
  342. get
  343. {
  344. switch (Position)
  345. {
  346. case Positions.Left:
  347. return "179px";
  348. case Positions.Right:
  349. return "179px";
  350. case Positions.Bottom:
  351. return "order:1;";
  352. default:
  353. return "auto";
  354. }
  355. }
  356. }
  357. internal int ToolbarRoundness
  358. {
  359. get
  360. {
  361. switch (Roundness)
  362. {
  363. case RoundnessEnum.High:
  364. return 10;
  365. case RoundnessEnum.Medium:
  366. return 5;
  367. case RoundnessEnum.Low:
  368. return 3;
  369. case RoundnessEnum.None:
  370. default:
  371. return 0;
  372. }
  373. }
  374. }
  375. internal int ColorIcon
  376. {
  377. get
  378. {
  379. switch (IconColor)
  380. {
  381. case IconColors.White:
  382. return 1;
  383. default:
  384. return 0;
  385. }
  386. }
  387. }
  388. internal string TransparencyIcon
  389. {
  390. get
  391. {
  392. switch (IconTransperency)
  393. {
  394. case IconTransparencyEnum.None:
  395. return "1";
  396. case IconTransparencyEnum.Low:
  397. return "0.9";
  398. case IconTransparencyEnum.Medium:
  399. return "0.7";
  400. case IconTransparencyEnum.Default:
  401. return "0.5";
  402. default:
  403. return "0.5";
  404. }
  405. }
  406. }
  407. }
  408. public enum IconColors
  409. {
  410. White, Black
  411. }
  412. public enum IconTransparencyEnum
  413. {
  414. Low, Medium, High, Default, None
  415. }
  416. public enum Positions
  417. {
  418. Top = 0,
  419. Bottom,
  420. Right,
  421. Left,
  422. }
  423. public enum ContentPositions
  424. {
  425. Left,
  426. Right,
  427. Center,
  428. }
  429. public enum RoundnessEnum
  430. {
  431. Low, Medium, High, None
  432. }
  433. }