Designer.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882
  1. using FastReport.Design.PageDesigners.Code;
  2. using FastReport.Design.ToolWindows;
  3. using FastReport.Forms;
  4. using FastReport.Preview;
  5. using FastReport.Utils;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.IO;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace FastReport.Design
  14. {
  15. /// <summary>
  16. /// Represents the report's designer control.
  17. /// </summary>
  18. /// <remarks>
  19. /// Usually you don't need to create an instance of this class. The designer can be called
  20. /// using the <see cref="FastReport.Report.Design()"/> method of
  21. /// the <see cref="FastReport.Report"/> instance.
  22. /// <para/>This control represents pure designer surface + Objects toolbar. If you need
  23. /// standard menu, statusbar, toolbars and tool windows, use the
  24. /// <see cref="FastReport.Design.StandardDesigner.DesignerControl"/> control instead. Also you may
  25. /// decide to use a designer's form (<see cref="FastReport.Design.StandardDesigner.DesignerForm"/>)
  26. /// instead of a control.
  27. /// <para/>To run a designer, you need to attach a Report instance to it. This can be done via
  28. /// the <see cref="Report"/> property.
  29. /// <para/>To call the designer in MDI (Multi-Document Interface) mode, use the
  30. /// <see cref="MdiMode"/> property.
  31. /// <para/>To set up some global properties, use the <see cref="Config"/> static class
  32. /// or <see cref="EnvironmentSettings"/> component that you can use in the Visual Studio IDE.
  33. /// </remarks>
  34. [ToolboxItem(false)]
  35. [Designer("FastReport.VSDesign.DesignerControlLayoutDesigner, FastReport.VSDesign, Version=1.0.0.0, Culture=neutral, PublicKeyToken=db7e5ce63278458c, processorArchitecture=MSIL")]
  36. public partial class Designer : UserControl, ISupportInitialize
  37. {
  38. #region Fields
  39. private Report report;
  40. private ReportTab activeReportTab;
  41. private PluginCollection plugins;
  42. private List<string> recentFiles;
  43. private DesignerClipboard clipboard;
  44. private bool mdiMode;
  45. private List<DocumentWindow> documents;
  46. private StartPageTab startPage;
  47. private ObjectCollection objects;
  48. private SelectedObjectCollection selectedObjects;
  49. private SelectedObjectCollection previouslySelectedObjects;
  50. private SelectedComponents selectedComponents;
  51. private SelectedReportComponents selectedReportComponents;
  52. private SelectedTextObjects selectedTextObjects;
  53. private LastFormatting lastFormatting;
  54. private bool modified;
  55. private bool formatPainter;
  56. private ReportComponentBase formatPainterPattern;
  57. private DesignerRestrictions restrictions;
  58. private bool isPreviewPageDesigner;
  59. private bool askSave;
  60. private string layoutState;
  61. private bool initFlag;
  62. private bool layoutNeeded;
  63. private UIStyle uIStyle;
  64. private StorageService designerStorage;
  65. private StorageService autoSaveStorage;
  66. private Timer autoSaveTimer;
  67. private TaskCompletionSource<bool> embeddedPreviewCompletion;
  68. private PreviewControl embeddedPreview;
  69. // tools
  70. private ObjectsToolbar objectsToolbar;
  71. private DictionaryWindow dataWindow;
  72. private PropertiesWindow propertiesWindow;
  73. private ReportTreeWindow reportTreeWindow;
  74. private MessagesWindow messagesWindow;
  75. // commands
  76. private NewCommand fcmdNew;
  77. private NewPageCommand fcmdNewPage;
  78. private NewDialogCommand fcmdNewDialog;
  79. private OpenCommand fcmdOpen;
  80. private OpenPageCommand fcmdOpenPage;
  81. private OpenViaCloudCommand fcmdOpenViaCloud;
  82. private SaveCommand fcmdSave;
  83. private SaveToCloudCommand fcmdSaveToCloud;
  84. private SaveAsCommand fcmdSaveAs;
  85. private SaveWithRandomDataCommand fcmdSaveWithRandomData;
  86. private SaveAllCommand fcmdSaveAll;
  87. private CloseCommand fcmdClose;
  88. private CloseAllCommand fcmdCloseAll;
  89. private PreviewCommand fcmdPreview;
  90. private PreviewCloudCommand fcmdPreviewCloud;
  91. private PrinterSettingsCommand fcmdPrinterSetup;
  92. private PageSettingsCommand fcmdPageSetup;
  93. private AddDataCommand fcmdAddData;
  94. private SortDataSourcesCommand fcmdSortDataSources;
  95. private ChooseDataCommand fcmdChooseData;
  96. private UndoCommand fcmdUndo;
  97. private RedoCommand fcmdRedo;
  98. private CutCommand fcmdCut;
  99. private CopyCommand fcmdCopy;
  100. private PasteCommand fcmdPaste;
  101. private FormatPainterCommand fcmdFormatPainter;
  102. private DeleteCommand fcmdDelete;
  103. private CopyPageCommand copyPageCommand;
  104. private DeletePageCommand fcmdDeletePage;
  105. private SelectAllCommand fcmdSelectAll;
  106. private GroupCommand fcmdGroup;
  107. private UngroupCommand fcmdUngroup;
  108. private EditCommand fcmdEdit;
  109. private FindCommand fcmdFind;
  110. private ReplaceCommand fcmdReplace;
  111. private BringToFrontCommand fcmdBringToFront;
  112. private SendToBackCommand fcmdSendToBack;
  113. private InsertCommand fcmdInsert;
  114. private InsertBandCommand fcmdInsertBand;
  115. private RecentFilesCommand fcmdRecentFiles;
  116. private SelectLanguageCommand fcmdSelectLanguage;
  117. private ViewStartPageCommand fcmdViewStartPage;
  118. private ReportSettingsCommand fcmdReportSettings;
  119. private OptionsCommand fcmdOptions;
  120. private ReportStylesCommand fcmdReportStyles;
  121. private ReportValidationCommand fcmdReportValidation;
  122. private HelpContentsCommand fcmdHelpContents;
  123. private AccountCommand fcmdAccount;
  124. private AboutCommand fcmdAbout;
  125. private WelcomeCommand fcmdWelcome;
  126. // polygon
  127. private PolygonSelectModeCommand fcmdPolySelectMove;
  128. private PolygonSelectModeCommand fcmdPolySelectPointer;
  129. private PolygonSelectModeCommand fcmdPolySelectAddPoint;
  130. private PolygonSelectModeCommand fcmdPolySelectBezier;
  131. private PolygonSelectModeCommand fcmdPolySelectRemovePoint;
  132. #endregion
  133. #region Properties
  134. /// <summary>
  135. /// Occurs when designer's UI state changed.
  136. /// </summary>
  137. public event EventHandler UIStateChanged;
  138. /// <summary>
  139. /// Gets or sets the edited report.
  140. /// </summary>
  141. /// <remarks>
  142. /// To initialize the designer, you need to pass a Report instance to this property.
  143. /// This will create the designer's surface associated with the report.
  144. /// <code>
  145. /// Designer designer = new Designer();
  146. /// designer.Parent = form1;
  147. /// designer.Report = report1;
  148. /// </code>
  149. /// </remarks>
  150. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  151. public Report Report
  152. {
  153. get { return report; }
  154. set
  155. {
  156. report = value;
  157. if (report != null)
  158. report.Designer = this;
  159. InitTabs();
  160. }
  161. }
  162. /// <summary>
  163. /// Gets active report object.
  164. /// </summary>
  165. /// <remarks>
  166. /// May be <b>null</b> if Start Page selected, or no reports opened.
  167. /// </remarks>
  168. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  169. public Report ActiveReport
  170. {
  171. get { return activeReportTab == null ? null : activeReportTab.Report; }
  172. set
  173. {
  174. foreach (DocumentWindow c in Documents)
  175. {
  176. if (c is ReportTab && (c as ReportTab).Report == value)
  177. {
  178. c.Activate();
  179. return;
  180. }
  181. }
  182. }
  183. }
  184. /// <summary>
  185. /// Gets a collection of global plugins such as menu, properties window, etc.
  186. /// </summary>
  187. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  188. public PluginCollection Plugins
  189. {
  190. get { return plugins; }
  191. }
  192. /// <summary>
  193. /// Gets a collection of objects on the active page of the active report.
  194. /// </summary>
  195. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  196. public ObjectCollection Objects
  197. {
  198. get { return objects; }
  199. }
  200. /// <summary>
  201. /// Gets a collection of selected objects on the active page of the active report.
  202. /// </summary>
  203. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  204. public SelectedObjectCollection SelectedObjects
  205. {
  206. get { return selectedObjects; }
  207. }
  208. /// <summary>
  209. /// Gets a collection of selected objects of the <b>ComponentBase</b> type.
  210. /// </summary>
  211. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  212. public SelectedComponents SelectedComponents
  213. {
  214. get { return selectedComponents; }
  215. }
  216. /// <summary>
  217. /// Gets a collection of selected objects of the <b>ReportComponentBase</b> type.
  218. /// </summary>
  219. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  220. public SelectedReportComponents SelectedReportComponents
  221. {
  222. get { return selectedReportComponents; }
  223. }
  224. /// <summary>
  225. /// Gets a collection of selected objects of the <b>TextObject</b> type.
  226. /// </summary>
  227. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  228. public SelectedTextObjects SelectedTextObjects
  229. {
  230. get { return selectedTextObjects; }
  231. }
  232. /// <summary>
  233. /// Gets or sets a value indicating that the report was modified.
  234. /// </summary>
  235. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  236. public bool Modified
  237. {
  238. get { return modified; }
  239. set { modified = value; }
  240. }
  241. /// <summary>
  242. /// Gets or sets a value that determines whether to ask user to save changes when closing the designer.
  243. /// </summary>
  244. public bool AskSave
  245. {
  246. get { return askSave; }
  247. set { askSave = value; }
  248. }
  249. /// <summary>
  250. /// Gets the designer restrictions.
  251. /// </summary>
  252. public DesignerRestrictions Restrictions
  253. {
  254. get { return restrictions; }
  255. }
  256. /// <summary>
  257. /// Gets or sets a value indicating that designer is run in MDI mode.
  258. /// </summary>
  259. /// <remarks>
  260. /// <para/>To call the designer in MDI (Multi-Document Interface) mode, use the following code:
  261. /// <code>
  262. /// DesignerControl designer = new DesignerControl();
  263. /// designer.MdiMode = true;
  264. /// designer.ShowDialog();
  265. /// </code>
  266. /// </remarks>
  267. [DefaultValue(false)]
  268. public bool MdiMode
  269. {
  270. get { return mdiMode; }
  271. set
  272. {
  273. mdiMode = value;
  274. UpdateMdiMode();
  275. }
  276. }
  277. /// <summary>
  278. /// Gets or sets the visual style.
  279. /// </summary>
  280. public UIStyle UIStyle
  281. {
  282. get { return uIStyle; }
  283. set
  284. {
  285. uIStyle = value;
  286. UpdateUIStyle();
  287. UIStyleChanged?.Invoke(this, EventArgs.Empty);
  288. }
  289. }
  290. /// <summary>
  291. /// Occurs when the UIStyle property is changed.
  292. /// </summary>
  293. public event EventHandler UIStyleChanged;
  294. /// <summary>
  295. /// Gets a value indicating that designer is used to edit a preview page.
  296. /// </summary>
  297. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  298. public bool IsPreviewPageDesigner
  299. {
  300. get { return isPreviewPageDesigner; }
  301. set { isPreviewPageDesigner = value; }
  302. }
  303. /// <summary>
  304. /// Gets or sets the zoom factor.
  305. /// </summary>
  306. public float Zoom
  307. {
  308. get
  309. {
  310. if (ActiveReportTab != null)
  311. return ActiveReportTab.Zoom;
  312. return 1;
  313. }
  314. set
  315. {
  316. if (ActiveReportTab != null)
  317. ActiveReportTab.Zoom = value;
  318. }
  319. }
  320. /// <summary>
  321. /// Gets the zoom factor with respect of designer's dpi value.
  322. /// </summary>
  323. public float ZoomDpi
  324. {
  325. get { return Zoom * this.DpiMultiplier(); }
  326. }
  327. /// <summary>
  328. /// The "File|New" command.
  329. /// </summary>
  330. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  331. public NewCommand cmdNew
  332. {
  333. get { return fcmdNew; }
  334. }
  335. /// <summary>
  336. /// The "New Page" toolbar command.
  337. /// </summary>
  338. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  339. public NewPageCommand cmdNewPage
  340. {
  341. get { return fcmdNewPage; }
  342. }
  343. /// <summary>
  344. /// The "New Dialog" toolbar command.
  345. /// </summary>
  346. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  347. public NewDialogCommand cmdNewDialog
  348. {
  349. get { return fcmdNewDialog; }
  350. }
  351. /// <summary>
  352. /// The "File|Open|Open locally." command.
  353. /// </summary>
  354. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  355. public OpenCommand cmdOpen
  356. {
  357. get { return fcmdOpen; }
  358. }
  359. /// <summary>
  360. /// The "File|Open|Open page." command.
  361. /// </summary>
  362. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  363. public OpenPageCommand cmdOpenPage
  364. {
  365. get { return fcmdOpenPage; }
  366. }
  367. /// <summary>
  368. /// The "File|Open|Open via Cloud." command.
  369. /// </summary>
  370. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  371. public OpenViaCloudCommand cmdOpenViaCloud
  372. {
  373. get { return fcmdOpenViaCloud; }
  374. }
  375. /// <summary>
  376. /// The "File|Save" command.
  377. /// </summary>
  378. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  379. public SaveCommand cmdSave
  380. {
  381. get { return fcmdSave; }
  382. }
  383. /// <summary>
  384. /// The "File|Save to Cloud" command.
  385. /// </summary>
  386. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  387. public SaveToCloudCommand cmdSaveToCloudCommand
  388. {
  389. get { return fcmdSaveToCloud; }
  390. }
  391. /// <summary>
  392. /// The "File|Save As..." command.
  393. /// </summary>
  394. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  395. public SaveAsCommand cmdSaveAs
  396. {
  397. get { return fcmdSaveAs; }
  398. }
  399. /// <summary>
  400. /// The "File|Save With Random Data..." command.
  401. /// </summary>
  402. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  403. public SaveWithRandomDataCommand cmdSaveWithRandomData
  404. {
  405. get { return fcmdSaveWithRandomData; }
  406. }
  407. /// <summary>
  408. /// The "File|Save All" command.
  409. /// </summary>
  410. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  411. public SaveAllCommand cmdSaveAll
  412. {
  413. get { return fcmdSaveAll; }
  414. }
  415. /// <summary>
  416. /// The "File|Close" command.
  417. /// </summary>
  418. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  419. public CloseCommand cmdClose
  420. {
  421. get { return fcmdClose; }
  422. }
  423. /// <summary>
  424. /// The "Window|Close All" command.
  425. /// </summary>
  426. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  427. public CloseAllCommand cmdCloseAll
  428. {
  429. get { return fcmdCloseAll; }
  430. }
  431. /// <summary>
  432. /// The "File|Preview..." command.
  433. /// </summary>
  434. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  435. public PreviewCommand cmdPreview
  436. {
  437. get { return fcmdPreview; }
  438. }
  439. /// <summary>
  440. /// The "File|Preview on Cloud..." command.
  441. /// </summary>
  442. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  443. public PreviewCloudCommand cmdPreviewCloud
  444. {
  445. get { return fcmdPreviewCloud; }
  446. }
  447. /// <summary>
  448. /// The "File|Printer Setup..." command.
  449. /// </summary>
  450. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  451. public PrinterSettingsCommand cmdPrinterSetup
  452. {
  453. get { return fcmdPrinterSetup; }
  454. }
  455. /// <summary>
  456. /// The "File|Page Setup..." command.
  457. /// </summary>
  458. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  459. public PageSettingsCommand cmdPageSetup
  460. {
  461. get { return fcmdPageSetup; }
  462. }
  463. /// <summary>
  464. /// The "Data|Add New Data Source..." command.
  465. /// </summary>
  466. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  467. public AddDataCommand cmdAddData
  468. {
  469. get { return fcmdAddData; }
  470. }
  471. /// <summary>
  472. /// The "Data|Sort Data Sources" command.
  473. /// </summary>
  474. public SortDataSourcesCommand cmdSortDataSources
  475. {
  476. get { return fcmdSortDataSources; }
  477. }
  478. /// <summary>
  479. /// The "Data|Choose Report Data..." command.
  480. /// </summary>
  481. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  482. public ChooseDataCommand cmdChooseData
  483. {
  484. get { return fcmdChooseData; }
  485. }
  486. /// <summary>
  487. /// The "Edit|Undo" command.
  488. /// </summary>
  489. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  490. public UndoCommand cmdUndo
  491. {
  492. get { return fcmdUndo; }
  493. }
  494. /// <summary>
  495. /// The "Edit|Redo" command.
  496. /// </summary>
  497. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  498. public RedoCommand cmdRedo
  499. {
  500. get { return fcmdRedo; }
  501. }
  502. /// <summary>
  503. /// The "Edit|Cut" command.
  504. /// </summary>
  505. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  506. public CutCommand cmdCut
  507. {
  508. get { return fcmdCut; }
  509. }
  510. /// <summary>
  511. /// The "Edit|Copy" command.
  512. /// </summary>
  513. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  514. public CopyCommand cmdCopy
  515. {
  516. get { return fcmdCopy; }
  517. }
  518. /// <summary>
  519. /// The "Edit|Paste" command.
  520. /// </summary>
  521. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  522. public PasteCommand cmdPaste
  523. {
  524. get { return fcmdPaste; }
  525. }
  526. /// <summary>
  527. /// The "Format Painter" toolbar command.
  528. /// </summary>
  529. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  530. public FormatPainterCommand cmdFormatPainter
  531. {
  532. get { return fcmdFormatPainter; }
  533. }
  534. /// <summary>
  535. /// The "Edit|Delete" command.
  536. /// </summary>
  537. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  538. public DeleteCommand cmdDelete
  539. {
  540. get { return fcmdDelete; }
  541. }
  542. /// <summary>
  543. /// The "Edit|Copy Page" command.
  544. /// </summary>
  545. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  546. public CopyPageCommand cmdCopyPage
  547. {
  548. get { return copyPageCommand; }
  549. }
  550. /// <summary>
  551. /// The "Edit|Delete Page" command.
  552. /// </summary>
  553. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  554. public DeletePageCommand cmdDeletePage
  555. {
  556. get { return fcmdDeletePage; }
  557. }
  558. /// <summary>
  559. /// The "Edit|Select All" command.
  560. /// </summary>
  561. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  562. public SelectAllCommand cmdSelectAll
  563. {
  564. get { return fcmdSelectAll; }
  565. }
  566. /// <summary>
  567. /// The "Edit|Group" command.
  568. /// </summary>
  569. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  570. public GroupCommand cmdGroup
  571. {
  572. get { return fcmdGroup; }
  573. }
  574. /// <summary>
  575. /// The "Edit|Ungroup" command.
  576. /// </summary>
  577. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  578. public UngroupCommand cmdUngroup
  579. {
  580. get { return fcmdUngroup; }
  581. }
  582. /// <summary>
  583. /// The "Edit" command.
  584. /// </summary>
  585. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  586. public EditCommand cmdEdit
  587. {
  588. get { return fcmdEdit; }
  589. }
  590. /// <summary>
  591. /// The "Edit|Find..." command.
  592. /// </summary>
  593. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  594. public FindCommand cmdFind
  595. {
  596. get { return fcmdFind; }
  597. }
  598. /// <summary>
  599. /// The "Polygon move command" command.
  600. /// </summary>
  601. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  602. public PolygonSelectModeCommand CmdPolySelectMove
  603. {
  604. get { return fcmdPolySelectMove; }
  605. }
  606. /// <summary>
  607. /// The "Polygon point move" command.
  608. /// </summary>
  609. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  610. public PolygonSelectModeCommand CmdPolySelectPointer
  611. {
  612. get { return fcmdPolySelectPointer; }
  613. }
  614. /// <summary>
  615. /// The "Polygon add new point" command.
  616. /// </summary>
  617. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  618. public PolygonSelectModeCommand CmdPolySelectAddPoint
  619. {
  620. get { return fcmdPolySelectAddPoint; }
  621. }
  622. /// <summary>
  623. /// The "Polygon berier" command.
  624. /// </summary>
  625. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  626. public PolygonSelectModeCommand CmdPolySelectBezier
  627. {
  628. get { return fcmdPolySelectBezier; }
  629. }
  630. /// <summary>
  631. /// The "Polygon remove point" command.
  632. /// </summary>
  633. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  634. public PolygonSelectModeCommand CmdPolySelectRemovePoint
  635. {
  636. get { return fcmdPolySelectRemovePoint; }
  637. }
  638. /// <summary>
  639. /// The "Edit|Replace..." command.
  640. /// </summary>
  641. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  642. public ReplaceCommand cmdReplace
  643. {
  644. get { return fcmdReplace; }
  645. }
  646. /// <summary>
  647. /// The "Bring To Front" command.
  648. /// </summary>
  649. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  650. public BringToFrontCommand cmdBringToFront
  651. {
  652. get { return fcmdBringToFront; }
  653. }
  654. /// <summary>
  655. /// The "Send To Back" command.
  656. /// </summary>
  657. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  658. public SendToBackCommand cmdSendToBack
  659. {
  660. get { return fcmdSendToBack; }
  661. }
  662. /// <summary>
  663. /// The "Insert" command.
  664. /// </summary>
  665. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  666. public InsertCommand cmdInsert
  667. {
  668. get { return fcmdInsert; }
  669. }
  670. /// <summary>
  671. /// The "Insert Band" command.
  672. /// </summary>
  673. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  674. public InsertBandCommand cmdInsertBand
  675. {
  676. get { return fcmdInsertBand; }
  677. }
  678. /// <summary>
  679. /// The "Recent Files" command.
  680. /// </summary>
  681. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  682. public RecentFilesCommand cmdRecentFiles
  683. {
  684. get { return fcmdRecentFiles; }
  685. }
  686. /// <summary>
  687. /// The "File|Select Language..." command.
  688. /// </summary>
  689. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  690. public SelectLanguageCommand cmdSelectLanguage
  691. {
  692. get { return fcmdSelectLanguage; }
  693. }
  694. /// <summary>
  695. /// The "View|Start Page" command.
  696. /// </summary>
  697. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  698. public ViewStartPageCommand cmdViewStartPage
  699. {
  700. get { return fcmdViewStartPage; }
  701. }
  702. /// <summary>
  703. /// The "Report|Options..." command.
  704. /// </summary>
  705. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  706. public ReportSettingsCommand cmdReportSettings
  707. {
  708. get { return fcmdReportSettings; }
  709. }
  710. /// <summary>
  711. /// The "View|Options..." command.
  712. /// </summary>
  713. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  714. public OptionsCommand cmdOptions
  715. {
  716. get { return fcmdOptions; }
  717. }
  718. /// <summary>
  719. /// The "Report|Styles..." command.
  720. /// </summary>
  721. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  722. public ReportStylesCommand cmdReportStyles
  723. {
  724. get { return fcmdReportStyles; }
  725. }
  726. /// <summary>
  727. /// The "Report|Validation" command.
  728. /// </summary>
  729. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  730. public ReportValidationCommand cmdReportValidation
  731. {
  732. get { return fcmdReportValidation; }
  733. }
  734. /// <summary>
  735. /// The "Help|Help Contents..." command.
  736. /// </summary>
  737. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  738. public HelpContentsCommand cmdHelpContents
  739. {
  740. get { return fcmdHelpContents; }
  741. }
  742. /// <summary>
  743. /// The "Help|Account" command.
  744. /// </summary>
  745. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  746. public AccountCommand cmdAccount
  747. {
  748. get { return fcmdAccount; }
  749. }
  750. /// <summary>
  751. /// The "Help|About..." command.
  752. /// </summary>
  753. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  754. public AboutCommand cmdAbout
  755. {
  756. get { return fcmdAbout; }
  757. }
  758. /// <summary>
  759. /// The "Show welcome window..." command.
  760. /// </summary>
  761. [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  762. public WelcomeCommand cmdWelcome
  763. {
  764. get { return fcmdWelcome; }
  765. }
  766. /// <summary>
  767. /// Gets or sets the layout state of the designer.
  768. /// </summary>
  769. /// <remarks>
  770. /// This property is used to store layout in Visual Studio design time. You may also use
  771. /// it to save and restore the designer's layout in your code. However, consider using the
  772. /// <see cref="SaveConfig()"/> and <see cref="RestoreConfig()"/> methods that use FastReport
  773. /// configuration file.
  774. /// </remarks>
  775. [Browsable(false)]
  776. public string LayoutState
  777. {
  778. get
  779. {
  780. XmlDocument doc = new XmlDocument();
  781. doc.Root.Name = "Config";
  782. SaveDockState(doc.Root);
  783. using (MemoryStream stream = new MemoryStream())
  784. {
  785. doc.Save(stream);
  786. return Encoding.UTF8.GetString(stream.ToArray());
  787. }
  788. }
  789. set
  790. {
  791. layoutState = value;
  792. if (initFlag)
  793. layoutNeeded = true;
  794. else
  795. RestoreLayout(value);
  796. }
  797. }
  798. /// <summary>
  799. /// Fires when the layout is changed.
  800. /// </summary>
  801. /// <remarks>
  802. /// This event is for internal use only.
  803. /// </remarks>
  804. public event EventHandler LayoutChangedEvent;
  805. internal StartPageTab StartPage
  806. {
  807. get { return startPage; }
  808. }
  809. // active report tab. May be null if Start Page selected, or no reports opened
  810. internal ReportTab ActiveReportTab
  811. {
  812. get { return activeReportTab; }
  813. set
  814. {
  815. if (activeReportTab != value)
  816. {
  817. if (activeReportTab != null)
  818. activeReportTab.ReportDeactivated();
  819. activeReportTab = value;
  820. if (value != null)
  821. value.ReportActivated();
  822. else
  823. ClearSelection();
  824. UpdatePlugins(null);
  825. }
  826. }
  827. }
  828. // list of recent opened files
  829. internal List<string> RecentFiles
  830. {
  831. get { return recentFiles; }
  832. }
  833. internal List<DocumentWindow> Documents
  834. {
  835. get { return documents; }
  836. }
  837. internal DesignerClipboard Clipboard
  838. {
  839. get { return clipboard; }
  840. }
  841. internal DictionaryWindow DataWindow
  842. {
  843. get { return dataWindow; }
  844. }
  845. internal PropertiesWindow PropertiesWindow
  846. {
  847. get { return propertiesWindow; }
  848. }
  849. internal ReportTreeWindow ReportTreeWindow
  850. {
  851. get { return reportTreeWindow; }
  852. }
  853. internal MessagesWindow MessagesWindow
  854. {
  855. get { return messagesWindow; }
  856. }
  857. internal CodePageDesigner Editor
  858. {
  859. get { return ActiveReportTab.Editor; }
  860. }
  861. internal LastFormatting LastFormatting
  862. {
  863. get { return lastFormatting; }
  864. }
  865. internal bool FormatPainter
  866. {
  867. get { return formatPainter; }
  868. set
  869. {
  870. if (formatPainter != value)
  871. {
  872. formatPainter = value;
  873. formatPainterPattern = value ? SelectedReportComponents.First : null;
  874. UpdatePlugins(null);
  875. }
  876. }
  877. }
  878. internal bool IsVSDesignMode
  879. {
  880. get { return DesignMode; }
  881. }
  882. internal Timer AutoSaveTimer
  883. {
  884. get { return autoSaveTimer; }
  885. }
  886. internal Dictionary<string, string> CloudReportDictionary { get; set; } = new Dictionary<string, string>();
  887. #endregion
  888. #region Private Methods
  889. private void SetupAutoSave()
  890. {
  891. autoSaveStorage = new StorageService("Designer,Saving");
  892. autoSaveTimer = new Timer();
  893. autoSaveTimer.Interval = autoSaveStorage.GetInt("AutoSaveMinutes", 5) * 60000;
  894. autoSaveTimer.Tick += delegate (object s1, EventArgs e1)
  895. {
  896. if (this != null && !IsPreviewPageDesigner)
  897. {
  898. if (cmdSave.Enabled)
  899. {
  900. ActiveReportTab.AutoSaveFile();
  901. }
  902. else
  903. {
  904. if (File.Exists(Config.AutoSaveFileName))
  905. File.Delete(Config.AutoSaveFileName);
  906. if (File.Exists(Config.AutoSaveFile))
  907. File.Delete(Config.AutoSaveFile);
  908. }
  909. }
  910. };
  911. }
  912. /// <summary>
  913. /// Updates UI style of the designer.
  914. /// </summary>
  915. public virtual void UpdateUIStyle()
  916. {
  917. UpdateUIStyleInternal();
  918. foreach (DocumentWindow document in Documents)
  919. {
  920. document.UpdateUIStyle();
  921. }
  922. plugins.UpdateUIStyle();
  923. }
  924. // create initial pages (Start Page, default report)
  925. private void InitTabs()
  926. {
  927. if (mdiMode)
  928. AddStartPageTab();
  929. if (report != null)
  930. AddReportTab(CreateReportTab(report));
  931. }
  932. private void AddDocument(DocumentWindow doc)
  933. {
  934. Documents.Add(doc);
  935. doc.AddToTabControl(tabs);
  936. doc.Activate();
  937. }
  938. private void RemoveDocument(DocumentWindow doc)
  939. {
  940. if (doc is StartPageTab)
  941. startPage = null;
  942. Documents.Remove(doc);
  943. doc.Close();
  944. }
  945. internal bool CloseDocument(DocumentWindow doc)
  946. {
  947. if (doc is ReportTab)
  948. {
  949. if (!(doc as ReportTab).CanClose())
  950. return false;
  951. }
  952. RemoveDocument(doc);
  953. return true;
  954. }
  955. private void ClearSelection()
  956. {
  957. activeReportTab = null;
  958. Objects.Clear();
  959. SelectedObjects.Clear();
  960. SelectionChanged(null);
  961. UpdatePlugins(null);
  962. }
  963. #endregion
  964. #region Protected Methods
  965. /// <summary>
  966. /// Initializes designer plugins such as toolbars and toolwindows.
  967. /// </summary>
  968. protected virtual void InitPlugins()
  969. {
  970. InitTools();
  971. plugins.AddRange(new IDesignerPlugin[] {
  972. objectsToolbar, dataWindow, propertiesWindow,
  973. reportTreeWindow, messagesWindow });
  974. // add export plugins
  975. plugins.Add(typeof(ExportPlugins.FR3.FR3ExportPlugin));
  976. #if MSCHART
  977. plugins.Add(typeof(ExportPlugins.RDL.RDLExportPlugin));
  978. #endif
  979. // add import plugins
  980. #if MSCHART
  981. plugins.Add(typeof(ImportPlugins.RDL.RDLImportPlugin));
  982. #endif
  983. plugins.Add(typeof(ImportPlugins.ListAndLabel.ListAndLabelImportPlugin));
  984. plugins.Add(typeof(ImportPlugins.DevExpress.DevExpressImportPlugin));
  985. plugins.Add(typeof(ImportPlugins.RTF.RTFImportPlugin));
  986. plugins.Add(typeof(ImportPlugins.StimulSoft.StimulSoftImportPlugin));
  987. plugins.Add(typeof(ImportPlugins.JasperReports.JasperReportsImportPlugin));
  988. }
  989. #endregion
  990. #region Public Methods
  991. /// <summary>
  992. /// Zooms the report to page width.
  993. /// </summary>
  994. public void ZoomPageWidth()
  995. {
  996. if (ActiveReportTab != null)
  997. ActiveReportTab.ZoomPageWidth();
  998. }
  999. /// <summary>
  1000. /// Zooms the report to whole page.
  1001. /// </summary>
  1002. public void ZoomWholePage()
  1003. {
  1004. if (ActiveReportTab != null)
  1005. ActiveReportTab.ZoomWholePage();
  1006. }
  1007. /// <summary>
  1008. /// Cancels paste mode.
  1009. /// </summary>
  1010. public void CancelPaste()
  1011. {
  1012. ActiveReportTab.ActivePageDesigner.CancelPaste();
  1013. }
  1014. /// <summary>
  1015. /// AutoSave system initialization.
  1016. /// </summary>
  1017. public void StartAutoSave()
  1018. {
  1019. if (IsPreviewPageDesigner)
  1020. return;
  1021. if (File.Exists(Config.AutoSaveFile) &&
  1022. File.Exists(Config.AutoSaveFileName) &&
  1023. autoSaveStorage.GetBool("EnableAutoSave", true) == true)
  1024. {
  1025. string filepath = File.ReadAllText(Config.AutoSaveFileName);
  1026. using (LoadAutoSaveForm f = new LoadAutoSaveForm(filepath))
  1027. {
  1028. if (f.ShowDialog() == DialogResult.OK)
  1029. {
  1030. ActiveReportTab.LoadAutoSaveFile(filepath);
  1031. SetModified();
  1032. }
  1033. }
  1034. }
  1035. if (File.Exists(Config.AutoSaveFileName))
  1036. File.Delete(Config.AutoSaveFileName);
  1037. if (File.Exists(Config.AutoSaveFile))
  1038. File.Delete(Config.AutoSaveFile);
  1039. autoSaveTimer.Enabled = autoSaveStorage.GetBool("EnableAutoSave", true);
  1040. }
  1041. /// <summary>
  1042. /// Stops the AutoSave system.
  1043. /// </summary>
  1044. public void StopAutoSave()
  1045. {
  1046. if (IsPreviewPageDesigner)
  1047. return;
  1048. autoSaveTimer.Stop();
  1049. if (File.Exists(Config.AutoSaveFileName))
  1050. File.Delete(Config.AutoSaveFileName);
  1051. if (File.Exists(Config.AutoSaveFile))
  1052. File.Delete(Config.AutoSaveFile);
  1053. }
  1054. /// <summary>
  1055. /// Call this method if you change something in the report.
  1056. /// </summary>
  1057. /// <remarks>
  1058. /// This method adds the current report state to the undo buffer and updates all plugins.
  1059. /// </remarks>
  1060. public void SetModified()
  1061. {
  1062. SetModified(null, "Change");
  1063. }
  1064. /// <summary>
  1065. /// Call this method if you change something in the report.
  1066. /// </summary>
  1067. /// <param name="sender">The object that was modified.</param>
  1068. /// <param name="action">The undo action name.</param>
  1069. /// <remarks>
  1070. /// This method adds the current report state to the undo buffer and updates all plugins.
  1071. /// </remarks>
  1072. public void SetModified(object sender, string action)
  1073. {
  1074. SetModified(sender, action, null);
  1075. }
  1076. /// <summary>
  1077. /// Call this method if you change something in the report.
  1078. /// </summary>
  1079. /// <param name="sender">The object that was modified.</param>
  1080. /// <param name="action">The undo action name.</param>
  1081. /// <param name="objName">The name of modified object.</param>
  1082. public void SetModified(object sender, string action, string objName)
  1083. {
  1084. modified = true;
  1085. if (ActiveReportTab != null)
  1086. ActiveReportTab.SetModified(sender, action, objName);
  1087. UpdatePlugins(sender);
  1088. }
  1089. /// <summary>
  1090. /// Call this method to tell the designer that current selection is changed.
  1091. /// </summary>
  1092. /// <param name="sender">The plugin that changes the selection (may be <b>null</b>).</param>
  1093. public void SelectionChanged(object sender)
  1094. {
  1095. // check groups
  1096. ObjectCollection selectedObjects = new ObjectCollection();
  1097. SelectedObjects.CopyTo(selectedObjects);
  1098. foreach (Base c in selectedObjects)
  1099. {
  1100. if (c is ComponentBase && (c as ComponentBase).GroupIndex != 0)
  1101. {
  1102. int groupIndex = (c as ComponentBase).GroupIndex;
  1103. foreach (Base c1 in Objects)
  1104. {
  1105. if (c1 is ComponentBase && (c1 as ComponentBase).GroupIndex == groupIndex)
  1106. {
  1107. if (SelectedObjects.IndexOf(c1) == -1)
  1108. SelectedObjects.Add(c1);
  1109. }
  1110. }
  1111. }
  1112. }
  1113. foreach (Base c in previouslySelectedObjects)
  1114. {
  1115. c.SelectionChanged();
  1116. }
  1117. foreach (Base c in selectedObjects)
  1118. {
  1119. c.SelectionChanged();
  1120. if (formatPainter && formatPainterPattern != null && c is ReportComponentBase)
  1121. (c as ReportComponentBase).AssignFormat(formatPainterPattern);
  1122. }
  1123. SelectedComponents.Update();
  1124. SelectedReportComponents.Update();
  1125. SelectedTextObjects.Update();
  1126. if (ActiveReportTab != null)
  1127. ActiveReportTab.Plugins.SelectionChanged(sender);
  1128. plugins.SelectionChanged(sender);
  1129. SelectedObjects.CopyTo(previouslySelectedObjects);
  1130. if (formatPainter && formatPainterPattern != null)
  1131. {
  1132. if (sender != null)
  1133. SetModified();
  1134. else
  1135. {
  1136. SetModified(null, "no-undo");
  1137. FormatPainter = false;
  1138. }
  1139. }
  1140. OnUIStateChanged();
  1141. }
  1142. /// <summary>
  1143. /// Locks all plugins.
  1144. /// </summary>
  1145. /// <remarks>
  1146. /// This method is usually called when we destroy the report to prevent unexpected
  1147. /// errors - such as trying to draw destroyed objects.
  1148. /// </remarks>
  1149. public void Lock()
  1150. {
  1151. if (ActiveReportTab != null)
  1152. ActiveReportTab.Plugins.Lock();
  1153. plugins.Lock();
  1154. }
  1155. /// <summary>
  1156. /// Unlocks all plugins.
  1157. /// </summary>
  1158. /// <remarks>
  1159. /// Call this method after the <b>Lock</b>.
  1160. /// </remarks>
  1161. public void Unlock()
  1162. {
  1163. if (ActiveReportTab != null)
  1164. ActiveReportTab.Plugins.Unlock();
  1165. plugins.Unlock();
  1166. }
  1167. /// <summary>
  1168. /// Call this method to refresh all plugins' content.
  1169. /// </summary>
  1170. /// <param name="sender">The plugin that we don't need to refresh.</param>
  1171. public void UpdatePlugins(object sender)
  1172. {
  1173. if (ActiveReportTab != null)
  1174. ActiveReportTab.Plugins.Update(sender);
  1175. plugins.Update(sender);
  1176. OnUIStateChanged();
  1177. }
  1178. /// <summary>
  1179. /// Updates localization of the designer.
  1180. /// </summary>
  1181. public void Localize()
  1182. {
  1183. Plugins.Localize();
  1184. if (ActiveReportTab != null)
  1185. ActiveReportTab.Localize();
  1186. // Mono: update toolwindows captions & tabs
  1187. LocalizeInternal();
  1188. }
  1189. /// <summary>
  1190. /// Updates layout and images on dpi change.
  1191. /// </summary>
  1192. /// <param name="sender">The sender object.</param>
  1193. public virtual void UpdateDpiDependencies(object sender)
  1194. {
  1195. Plugins.UpdateDpiDependencies(sender);
  1196. if (ActiveReportTab != null)
  1197. ActiveReportTab.UpdateDpiDependencies();
  1198. // Mono: this should be after all plugins (TabStrip images related)
  1199. UpdateDpiDependenciesInternal();
  1200. embeddedPreview?.UpdateDpiDependencies();
  1201. }
  1202. /// <summary>
  1203. /// Checks if parent window can be closed.
  1204. /// </summary>
  1205. /// <param name="e">The cancel event args.</param>
  1206. /// <remarks>
  1207. /// Use this method in the window's FormClosing event handler if you use this control.
  1208. /// This method checks if the embedded preview is running and cancels it. Also if there is unsaved changes, the user will be asked to save changes.
  1209. /// </remarks>
  1210. public void ParentFormClosing(FormClosingEventArgs e)
  1211. {
  1212. if (embeddedPreview != null)
  1213. {
  1214. if (embeddedPreview.IsAsyncReportRunning)
  1215. embeddedPreview.Report.Abort();
  1216. else
  1217. embeddedPreviewCompletion.SetResult(true);
  1218. e.Cancel = true;
  1219. return;
  1220. }
  1221. if (!CloseAll())
  1222. {
  1223. e.Cancel = true;
  1224. }
  1225. }
  1226. internal async Task ShowEmbeddedPreview(Report report)
  1227. {
  1228. PreviewControl savePreview = report.Preview;
  1229. report.Preview = null;
  1230. Config.ReportSettings.ShowProgress = false;
  1231. bool finished = false;
  1232. try
  1233. {
  1234. if (await report.AsyncPrepareStart()) // startup, compile, run dialogs. May throw a compiler exception
  1235. {
  1236. var preview = new PreviewControl();
  1237. preview.Buttons = Config.PreviewSettings.Buttons | PreviewButtons.Close;
  1238. preview.Dock = DockStyle.Fill;
  1239. #if !MONO
  1240. preview.Size = Parent.ClientSize; // winforms, less flickering; Avalonia - wrong size on pmV2
  1241. #endif
  1242. preview.Visible = false;
  1243. // setup preview control
  1244. preview.SetAsyncReportRunning();
  1245. report.Preview = preview;
  1246. report.SetupPreviewControl();
  1247. preview.Parent = Parent;
  1248. #if WPF
  1249. // fix WPF rendering issues (pmV2)
  1250. Application.DoEvents();
  1251. #endif
  1252. #if !MONO
  1253. preview.Scale(new System.Drawing.SizeF(this.FontDpiMultiplier(), this.FontDpiMultiplier()));
  1254. #endif
  1255. UIUtils.CheckRTL(preview);
  1256. preview.UpdateDpiDependencies();
  1257. // swap designer and preview
  1258. Parent.SuspendLayout();
  1259. foreach (Control c in Parent.Controls)
  1260. c.Visible = false;
  1261. preview.Visible = true;
  1262. #if (WPF || AVALONIA)
  1263. var form = FindForm().window as IForm;
  1264. form.ExtendedAppArea = false;
  1265. form.ExtendedAppAreaSize = 0;
  1266. preview.control.AnimateOpacity(0, 1, 200);
  1267. #endif
  1268. Parent.ResumeLayout();
  1269. preview.AsyncReportStart();
  1270. #if WPF
  1271. _ = System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(
  1272. #elif AVALONIA
  1273. _ = Avalonia.Threading.Dispatcher.UIThread.InvokeAsync(
  1274. #else
  1275. this.BeginInvoke(
  1276. #endif
  1277. new Action(() =>
  1278. {
  1279. try
  1280. {
  1281. report.AsyncPrepareRun(); // run report pages (pseudo async way). May throw runtime exception
  1282. }
  1283. catch (Exception ex)
  1284. {
  1285. FRMessageBox.Error(ex.Message);
  1286. }
  1287. finally
  1288. {
  1289. report.AsyncPrepareFinish(); // cleanup
  1290. preview.AsyncReportFinish();
  1291. finished = true;
  1292. }
  1293. }));
  1294. // wait for form is about to close (handled in the DesignerForm.cs code)
  1295. embeddedPreview = preview;
  1296. embeddedPreviewCompletion = new TaskCompletionSource<bool>();
  1297. await embeddedPreviewCompletion.Task;
  1298. embeddedPreview = null;
  1299. embeddedPreviewCompletion = null;
  1300. preview.Dispose();
  1301. // show the designer control again
  1302. Parent.SuspendLayout();
  1303. foreach (Control c in Parent.Controls)
  1304. {
  1305. if (!c.GetType().Name.Contains("RibbonControl") || Config.UseRibbon)
  1306. c.Visible = true;
  1307. }
  1308. #if (WPF || AVALONIA)
  1309. form.ExtendedAppArea = true;
  1310. #endif
  1311. Parent.ResumeLayout();
  1312. }
  1313. }
  1314. finally
  1315. {
  1316. if (!finished)
  1317. report.AsyncPrepareFinish(); // cleanup
  1318. report.Preview = savePreview;
  1319. }
  1320. }
  1321. // adds the Start Page tab
  1322. internal void AddStartPageTab()
  1323. {
  1324. if (StartPage != null)
  1325. return;
  1326. startPage = new StartPageTab(this);
  1327. AddDocument(startPage);
  1328. UpdatePlugins(null);
  1329. }
  1330. // adds the report tab
  1331. internal ReportTab CreateReportTab(Report report)
  1332. {
  1333. return new ReportTab(this, report);
  1334. }
  1335. internal void AddReportTab(ReportTab tab)
  1336. {
  1337. AddDocument(tab);
  1338. tab.UpdateUIStyle();
  1339. tab.UpdateDpiDependencies();
  1340. ActiveReportTab = tab;
  1341. }
  1342. private void OnUIStateChanged()
  1343. {
  1344. if (UIStateChanged != null)
  1345. UIStateChanged(this, EventArgs.Empty);
  1346. }
  1347. #endregion
  1348. #region Layout
  1349. private void SaveRecentFiles()
  1350. {
  1351. string files = "";
  1352. foreach (string s in RecentFiles)
  1353. {
  1354. files += s + '\r';
  1355. }
  1356. designerStorage.SetStr("RecentFiles", files);
  1357. }
  1358. private void SaveCloudReports()
  1359. {
  1360. string files = "";
  1361. foreach (var pair in CloudReportDictionary)
  1362. {
  1363. files += pair.Key + '\n' + pair.Value + '\r';
  1364. }
  1365. designerStorage.SetStr("CloudReports", files);
  1366. }
  1367. private void RestoreRecentFiles()
  1368. {
  1369. string[] files = designerStorage.GetStr("RecentFiles").Split(new char[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);
  1370. RecentFiles.Clear();
  1371. RecentFiles.AddRange(files);
  1372. }
  1373. private void RestoreCloudReports()
  1374. {
  1375. var files = designerStorage.GetStr("CloudReports").Split('\r');
  1376. CloudReportDictionary.Clear();
  1377. if (files.Length < 1 || files[0] == string.Empty)
  1378. return;
  1379. foreach (var line in files)
  1380. {
  1381. if (line != string.Empty)
  1382. {
  1383. var pair = line.Split('\n');
  1384. // filename should not be rooted
  1385. if (pair.Length == 2 && !Path.IsPathRooted(pair[0]))
  1386. CloudReportDictionary.Add(pair[0], pair[1]);
  1387. }
  1388. }
  1389. }
  1390. /// <summary>
  1391. /// Saves config to a FastReport configuration file.
  1392. /// </summary>
  1393. public void SaveConfig()
  1394. {
  1395. SaveRecentFiles();
  1396. SaveCloudReports();
  1397. plugins.SaveState();
  1398. SaveDockState(Config.Root);
  1399. }
  1400. /// <summary>
  1401. /// Restores config from a FastReport configuration file.
  1402. /// </summary>
  1403. /// <remarks>
  1404. /// Call this method to restore the designer's layout. You need to do this after the
  1405. /// designer's control is placed on a form.
  1406. /// </remarks>
  1407. public void RestoreConfig()
  1408. {
  1409. BeforeRestoreState();
  1410. RestoreRecentFiles();
  1411. RestoreCloudReports();
  1412. RestoreDockState(Config.Root);
  1413. plugins.RestoreState();
  1414. AfterRestoreState();
  1415. }
  1416. /// <summary>
  1417. /// Refresh the designer's toolbars and toolwindows layout.
  1418. /// </summary>
  1419. /// <remarks>
  1420. /// Call this method if you use
  1421. /// <see cref="FastReport.Design.StandardDesigner.DesignerControl">DesignerControl</see>. To restore
  1422. /// the layout that you've created in VS design time, you need to call this method in the form's
  1423. /// <b>Load</b> event handler. If you don't do this, tool windows like Properties, Data, Report Tree
  1424. /// will not be available.
  1425. /// </remarks>
  1426. public void RefreshLayout()
  1427. {
  1428. RestoreLayout(layoutState);
  1429. }
  1430. internal virtual void BeforeRestoreState()
  1431. {
  1432. SuspendLayout();
  1433. }
  1434. internal virtual void AfterRestoreState()
  1435. {
  1436. ResumeLayout();
  1437. }
  1438. private void RestoreLayout(string value)
  1439. {
  1440. XmlDocument doc = new XmlDocument();
  1441. if (value == null)
  1442. value = "";
  1443. int startIndex = value.IndexOf("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  1444. if (startIndex != -1)
  1445. {
  1446. using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(value.Substring(startIndex))))
  1447. {
  1448. doc.Load(stream);
  1449. }
  1450. }
  1451. SuspendLayout();
  1452. RestoreDockState(doc.Root);
  1453. ResumeLayout();
  1454. }
  1455. /// <inheritdoc/>
  1456. public void BeginInit()
  1457. {
  1458. initFlag = true;
  1459. }
  1460. /// <inheritdoc/>
  1461. public void EndInit()
  1462. {
  1463. if (initFlag)
  1464. {
  1465. if (layoutNeeded)
  1466. RestoreLayout(layoutState);
  1467. initFlag = false;
  1468. layoutNeeded = false;
  1469. if (DesignMode)
  1470. DisableFloatingBars();
  1471. }
  1472. }
  1473. #endregion
  1474. #region Commands
  1475. private void InitCommands()
  1476. {
  1477. fcmdNew = new NewCommand(this);
  1478. fcmdNewPage = new NewPageCommand(this);
  1479. fcmdNewDialog = new NewDialogCommand(this);
  1480. fcmdOpen = new OpenCommand(this);
  1481. fcmdOpenPage = new OpenPageCommand(this);
  1482. fcmdOpenViaCloud = new OpenViaCloudCommand(this);
  1483. fcmdSave = new SaveCommand(this);
  1484. fcmdSaveToCloud = new SaveToCloudCommand(this);
  1485. fcmdSaveAs = new SaveAsCommand(this);
  1486. fcmdSaveWithRandomData = new SaveWithRandomDataCommand(this);
  1487. fcmdSaveAll = new SaveAllCommand(this);
  1488. fcmdClose = new CloseCommand(this);
  1489. fcmdCloseAll = new CloseAllCommand(this);
  1490. fcmdPreview = new PreviewCommand(this);
  1491. fcmdPreviewCloud = new PreviewCloudCommand(this);
  1492. fcmdPrinterSetup = new PrinterSettingsCommand(this);
  1493. fcmdPageSetup = new PageSettingsCommand(this);
  1494. fcmdAddData = new AddDataCommand(this);
  1495. fcmdSortDataSources = new SortDataSourcesCommand(this);
  1496. fcmdChooseData = new ChooseDataCommand(this);
  1497. fcmdUndo = new UndoCommand(this);
  1498. fcmdRedo = new RedoCommand(this);
  1499. fcmdCut = new CutCommand(this);
  1500. fcmdCopy = new CopyCommand(this);
  1501. fcmdPaste = new PasteCommand(this);
  1502. fcmdFormatPainter = new FormatPainterCommand(this);
  1503. fcmdDelete = new DeleteCommand(this);
  1504. copyPageCommand = new CopyPageCommand(this);
  1505. fcmdDeletePage = new DeletePageCommand(this);
  1506. fcmdSelectAll = new SelectAllCommand(this);
  1507. fcmdGroup = new GroupCommand(this);
  1508. fcmdUngroup = new UngroupCommand(this);
  1509. fcmdEdit = new EditCommand(this);
  1510. fcmdFind = new FindCommand(this);
  1511. fcmdReplace = new ReplaceCommand(this);
  1512. fcmdBringToFront = new BringToFrontCommand(this);
  1513. fcmdSendToBack = new SendToBackCommand(this);
  1514. fcmdInsert = new InsertCommand(this);
  1515. fcmdInsertBand = new InsertBandCommand(this);
  1516. fcmdRecentFiles = new RecentFilesCommand(this);
  1517. fcmdSelectLanguage = new SelectLanguageCommand(this);
  1518. fcmdViewStartPage = new ViewStartPageCommand(this);
  1519. fcmdReportSettings = new ReportSettingsCommand(this);
  1520. fcmdOptions = new OptionsCommand(this);
  1521. fcmdReportStyles = new ReportStylesCommand(this);
  1522. fcmdReportValidation = new ReportValidationCommand(this);
  1523. fcmdHelpContents = new HelpContentsCommand(this);
  1524. fcmdAccount = new AccountCommand(this);
  1525. fcmdAbout = new AboutCommand(this);
  1526. fcmdWelcome = new WelcomeCommand(this);
  1527. fcmdPolySelectAddPoint = new PolygonSelectModeCommand(this, PolyLineObject.PolygonSelectionMode.AddToLine);
  1528. fcmdPolySelectBezier = new PolygonSelectModeCommand(this, PolyLineObject.PolygonSelectionMode.AddBezier);
  1529. fcmdPolySelectMove = new PolygonSelectModeCommand(this, PolyLineObject.PolygonSelectionMode.MoveAndScale);
  1530. fcmdPolySelectPointer = new PolygonSelectModeCommand(this, PolyLineObject.PolygonSelectionMode.Normal);
  1531. fcmdPolySelectRemovePoint = new PolygonSelectModeCommand(this, PolyLineObject.PolygonSelectionMode.Delete);
  1532. }
  1533. internal void InitPages(int pageNo)
  1534. {
  1535. ActiveReportTab.InitPages(pageNo);
  1536. }
  1537. /// <summary>
  1538. /// Initializes the workspace after the new report is loaded.
  1539. /// </summary>
  1540. public void InitReport()
  1541. {
  1542. ActiveReportTab.InitReport();
  1543. ActiveReportTab.SetModified();
  1544. }
  1545. internal void InsertObject(ObjectInfo[] infos, InsertFrom source)
  1546. {
  1547. ObjectCollection list = new ObjectCollection();
  1548. CancelPaste();
  1549. foreach (ObjectInfo info in infos)
  1550. {
  1551. Base c = Activator.CreateInstance(info.Object) as Base;
  1552. LastFormatting.SetFormatting(c as ReportComponentBase);
  1553. c.OnBeforeInsert(info.Flags);
  1554. list.Add(c);
  1555. //c.Parent = ActiveReportTab.ActivePageDesigner.GetParentForPastedObjects();
  1556. Config.DesignerSettings.OnObjectInserted(this, new ObjectInsertedEventArgs(c, source));
  1557. }
  1558. ActiveReportTab.ActivePageDesigner.Paste(list, source);
  1559. }
  1560. internal void InsertObject(ObjectInfo info, InsertFrom source)
  1561. {
  1562. InsertObject(new ObjectInfo[] { info }, source);
  1563. }
  1564. internal void ResetObjectsToolbar(bool ignoreMultiInsert)
  1565. {
  1566. objectsToolbar.ClickSelectButton(ignoreMultiInsert);
  1567. FormatPainter = false;
  1568. }
  1569. internal void Exit(object sender, EventArgs e)
  1570. {
  1571. Form form = FindForm();
  1572. if (form != null)
  1573. form.Close();
  1574. }
  1575. /// <summary>
  1576. /// Tries to create a new empty report.
  1577. /// </summary>
  1578. /// <returns><b>true</b> if report was created successfully; <b>false</b> if user cancels the action.</returns>
  1579. public bool CreateEmptyReport()
  1580. {
  1581. bool result = false;
  1582. if (MdiMode)
  1583. {
  1584. Report report = new Report();
  1585. report.Designer = this;
  1586. Config.DesignerSettings.OnReportLoaded(this, new ReportLoadedEventArgs(report));
  1587. AddReportTab(CreateReportTab(report));
  1588. result = true;
  1589. }
  1590. else
  1591. result = ActiveReportTab.EmptyReport(true);
  1592. if (result)
  1593. {
  1594. ActiveReportTab.SetModified();
  1595. UpdatePlugins(null);
  1596. }
  1597. return result;
  1598. }
  1599. internal void ErrorMsg(string msg, string objName)
  1600. {
  1601. MessagesWindow.AddMessage(msg, objName);
  1602. }
  1603. internal void ErrorMsg(string msg, int line, int column)
  1604. {
  1605. MessagesWindow.AddMessage(msg, line, column);
  1606. }
  1607. /// <summary>
  1608. /// Displays a message in the "Messages" window.
  1609. /// </summary>
  1610. /// <param name="msg">Message text.</param>
  1611. public void ShowMessage(string msg)
  1612. {
  1613. MessagesWindow.AddMessage(msg, 1, 1);
  1614. }
  1615. /// <summary>
  1616. /// Clears the "Messages" window.
  1617. /// </summary>
  1618. public void ClearMessages()
  1619. {
  1620. MessagesWindow.ClearMessages();
  1621. }
  1622. /// <summary>
  1623. /// Shows the selected object's information in the designer's statusbar.
  1624. /// </summary>
  1625. /// <param name="location">Object's location.</param>
  1626. /// <param name="size">Object's size.</param>
  1627. /// <param name="text">Textual information about the selected object.</param>
  1628. /// <param name="locationRightBot">The location of the lower-right corner of the object's.</param>
  1629. public virtual void ShowStatus(string location, string size, string text, string locationRightBot)
  1630. {
  1631. }
  1632. /// <summary>
  1633. /// Close all opened reports, ask to save changes.
  1634. /// </summary>
  1635. /// <returns><b>true</b> if all tabs closed succesfully.</returns>
  1636. /// <remarks>
  1637. /// Use this method to close all opened documents and save changes when you closing the main form
  1638. /// that contains the designer control. To do this, create an event handler for your form's FormClosing
  1639. /// event and call this method inside the handler. If it returns false, set e.Cancel to <b>true</b>.
  1640. /// </remarks>
  1641. public bool CloseAll()
  1642. {
  1643. // close all tabs from the last tab to first.
  1644. while (Documents.Count > 0)
  1645. {
  1646. DocumentWindow c = Documents[Documents.Count - 1];
  1647. if (!CloseDocument(c))
  1648. {
  1649. // tab cannot be closed. Activate it and exit. Do not allow to close the designer.
  1650. c.Activate();
  1651. return false;
  1652. }
  1653. }
  1654. return true;
  1655. }
  1656. #endregion
  1657. /// <summary>
  1658. /// Initializes a new instance of the <see cref="Designer"/> class with default settings.
  1659. /// </summary>
  1660. public Designer()
  1661. {
  1662. Report.EnsureInit();
  1663. plugins = new PluginCollection(this);
  1664. recentFiles = new List<string>();
  1665. clipboard = new DesignerClipboard(this);
  1666. documents = new List<DocumentWindow>();
  1667. objects = new ObjectCollection();
  1668. selectedObjects = new SelectedObjectCollection();
  1669. previouslySelectedObjects = new SelectedObjectCollection();
  1670. selectedComponents = new SelectedComponents(this);
  1671. selectedReportComponents = new SelectedReportComponents(this);
  1672. selectedTextObjects = new SelectedTextObjects(this);
  1673. restrictions = Config.DesignerSettings.Restrictions.Clone();
  1674. askSave = true;
  1675. lastFormatting = new LastFormatting();
  1676. designerStorage = new StorageService("Designer");
  1677. InitCommands();
  1678. InitPluginsInternal();
  1679. UpdatePlugins(null);
  1680. UpdateMdiMode();
  1681. UIStyle = Config.UIStyle;
  1682. SetupAutoSave();
  1683. InitRightToLeft();
  1684. UpdateDpiDependencies(null);
  1685. }
  1686. }
  1687. }