GUITools.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //---------------------------------------------------------------------------
  2. #ifndef GUIToolsH
  3. #define GUIToolsH
  4. //---------------------------------------------------------------------------
  5. #include <FileMasks.h>
  6. #include <TBX.hpp>
  7. #include <DirectoryMonitor.hpp>
  8. //---------------------------------------------------------------------------
  9. class TSessionData;
  10. //---------------------------------------------------------------------------
  11. typedef void __fastcall (__closure* TProcessMessagesEvent)();
  12. //---------------------------------------------------------------------------
  13. void GUIFinalize();
  14. bool __fastcall FindFile(UnicodeString & Path);
  15. UnicodeString FindPuttyPath();
  16. bool __fastcall FindTool(const UnicodeString & Name, UnicodeString & Path);
  17. void __fastcall ExecuteTool(const UnicodeString & Name);
  18. void __fastcall ExecuteShellChecked(const UnicodeString Path, const UnicodeString Params,
  19. bool ChangeWorkingDirectory = false);
  20. void __fastcall ExecuteShellChecked(const UnicodeString Command);
  21. bool __fastcall ExecuteShell(const UnicodeString Path, const UnicodeString Params,
  22. HANDLE & Handle);
  23. void __fastcall ExecuteShellCheckedAndWait(const UnicodeString Command, TProcessMessagesEvent ProcessMessages);
  24. TObjectList * StartCreationDirectoryMonitorsOnEachDrive(unsigned int Filter, TFileChangedEvent OnChanged);
  25. extern bool DontCopyCommandToClipboard;
  26. bool __fastcall CopyCommandToClipboard(const UnicodeString & Command);
  27. bool DoesSessionExistInPutty(const UnicodeString & StorageKey);
  28. bool __fastcall ExportSessionToPutty(TSessionData * SessionData, bool ReuseExisting, const UnicodeString & SessionName);
  29. void OpenSessionInPutty(TSessionData * SessionData);
  30. bool __fastcall SpecialFolderLocation(int PathID, UnicodeString & Path);
  31. UnicodeString __fastcall UniqTempDir(const UnicodeString BaseDir,
  32. const UnicodeString Identity, bool Mask = false);
  33. int __fastcall GetSessionColorImage(TCustomImageList * ImageList, TColor Color, int MaskIndex);
  34. void __fastcall RegenerateSessionColorsImageList(TCustomImageList * ImageList, int MaskIndex);
  35. void __fastcall SetSubmenu(TTBXCustomItem * Item, bool Enable);
  36. typedef int __fastcall (*TCalculateWidth)(UnicodeString Text, void * Arg);
  37. void __fastcall ApplyTabs(
  38. UnicodeString & Text, wchar_t Padding,
  39. TCalculateWidth CalculateWidth, void * CalculateWidthArg);
  40. TPanel * CreateBlankPanel(TComponent * Owner);
  41. TPanel * CreateLabelPanel(TPanel * Parent, const UnicodeString & Label);
  42. TLabel * CreateLabel(TComponent * AOwner);
  43. TCheckBox * CreateCheckBox(TComponent * AOwner);
  44. void SetExplorerTheme(TWinControl * Control);
  45. TButton * CreateButton(TComponent * AOwner);
  46. TEdit * CreateEdit(TComponent * AOwner);
  47. TMemo * CreateMemo(TComponent * AOwner);
  48. void __fastcall SelectScaledImageList(TImageList * ImageList);
  49. void __fastcall CopyImageList(TImageList * TargetList, TImageList * SourceList);
  50. void __fastcall LoadDialogImage(TImage * Image, const UnicodeString & ImageName);
  51. int __fastcall DialogImageSize(TForm * Form);
  52. int NormalizePixelsPerInch(int PixelsPerInch);
  53. int LargerPixelsPerInch(int PixelsPerInch, int Larger);
  54. void __fastcall HideComponentsPanel(TForm * Form);
  55. struct TIncrementalSearchState
  56. {
  57. TIncrementalSearchState();
  58. void Reset();
  59. bool Searching;
  60. UnicodeString Text;
  61. bool HaveNext;
  62. };
  63. UnicodeString FormatIncrementalSearchStatus(const TIncrementalSearchState & SearchState);
  64. namespace Webbrowserex
  65. {
  66. class TWebBrowserEx;
  67. }
  68. #pragma clang diagnostic push
  69. #pragma clang diagnostic ignored "-Wheader-hygiene"
  70. using namespace Webbrowserex;
  71. #pragma clang diagnostic pop
  72. TWebBrowserEx * __fastcall CreateBrowserViewer(TPanel * Parent, const UnicodeString & LoadingLabel);
  73. void __fastcall SetBrowserDesignModeOff(TWebBrowserEx * WebBrowser);
  74. void __fastcall AddBrowserLinkHandler(TWebBrowserEx * WebBrowser,
  75. const UnicodeString & Url, TNotifyEvent Handler);
  76. void __fastcall NavigateBrowserToUrl(TWebBrowserEx * WebBrowser, const UnicodeString & Url);
  77. void ReadyBrowserForStreaming(TWebBrowserEx * WebBrowser);
  78. void WaitBrowserToIdle(TWebBrowserEx * WebBrowser);
  79. void HideBrowserScrollbars(TWebBrowserEx * WebBrowser);
  80. bool CopyTextFromBrowser(TWebBrowserEx * WebBrowser, UnicodeString & Text);
  81. UnicodeString GenerateAppHtmlPage(TFont * Font, TPanel * Parent, const UnicodeString & Body, bool Seamless);
  82. void LoadBrowserDocument(TWebBrowserEx * WebBrowser, const UnicodeString & Document);
  83. TComponent * __fastcall FindComponentRecursively(TComponent * Root, const UnicodeString & Name);
  84. void __fastcall GetInstrutionsTheme(
  85. TColor & MainInstructionColor, HFONT & MainInstructionFont, HFONT & InstructionFont);
  86. bool CanShowTimeEstimate(TDateTime StartTime);
  87. void CheckOperationStatusWindow();
  88. //---------------------------------------------------------------------------
  89. class TLocalCustomCommand : public TFileCustomCommand
  90. {
  91. public:
  92. TLocalCustomCommand();
  93. TLocalCustomCommand(
  94. const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath);
  95. TLocalCustomCommand(
  96. const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath,
  97. const UnicodeString & FileName, const UnicodeString & LocalFileName,
  98. const UnicodeString & FileList);
  99. virtual bool __fastcall IsFileCommand(const UnicodeString & Command);
  100. bool __fastcall HasLocalFileName(const UnicodeString & Command);
  101. protected:
  102. virtual int __fastcall PatternLen(const UnicodeString & Command, int Index);
  103. virtual bool __fastcall PatternReplacement(int Index, const UnicodeString & Pattern,
  104. UnicodeString & Replacement, bool & Delimit);
  105. virtual void __fastcall DelimitReplacement(UnicodeString & Replacement, wchar_t Quote);
  106. private:
  107. UnicodeString FLocalPath;
  108. UnicodeString FLocalFileName;
  109. };
  110. //---------------------------------------------------------------------------
  111. namespace Pngimagelist
  112. {
  113. class TPngImageList;
  114. class TPngImageCollectionItem;
  115. }
  116. #pragma clang diagnostic push
  117. #pragma clang diagnostic ignored "-Wheader-hygiene"
  118. using namespace Pngimagelist;
  119. #pragma clang diagnostic pop
  120. //---------------------------------------------------------------------------
  121. TPngImageList * __fastcall GetAnimationsImages(TControl * Control);
  122. TImageList * __fastcall GetButtonImages(TControl * Control);
  123. TPngImageList * __fastcall GetDialogImages(TControl * Control);
  124. TCustomImageList * TreeViewImageList(TPngImageList * ImageList);
  125. void __fastcall ReleaseImagesModules();
  126. //---------------------------------------------------------------------------
  127. class TFrameAnimation
  128. {
  129. public:
  130. __fastcall TFrameAnimation();
  131. void __fastcall Init(TPaintBox * PaintBox, const UnicodeString & Name);
  132. void __fastcall Start();
  133. void __fastcall Stop();
  134. private:
  135. UnicodeString FName;
  136. TPaintBox * FPaintBox;
  137. TPngImageList * FImageList;
  138. int FFirstFrame;
  139. int FFirstLoopFrame;
  140. int FLastFrame;
  141. int FCurrentFrame;
  142. DWORD FNextFrameTick;
  143. TTimer * FTimer;
  144. bool FPainted;
  145. void __fastcall DoInit();
  146. void __fastcall PaintBoxPaint(TObject * Sender);
  147. void __fastcall CalculateNextFrameTick();
  148. TPngImageCollectionItem * __fastcall GetCurrentImage();
  149. void __fastcall Animate();
  150. void __fastcall Timer(TObject * Sender);
  151. void __fastcall Repaint();
  152. void __fastcall Rescale();
  153. static void __fastcall PaintBoxRescale(TComponent * Sender, TObject * Token);
  154. };
  155. //---------------------------------------------------------------------------
  156. class TScreenTipHintWindow : public THintWindow
  157. {
  158. public:
  159. __fastcall TScreenTipHintWindow(TComponent * Owner);
  160. virtual TRect __fastcall CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData);
  161. virtual void __fastcall ActivateHintData(const TRect & Rect, const UnicodeString AHint, void * AData);
  162. static void __fastcall CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint);
  163. protected:
  164. virtual void __fastcall Paint();
  165. virtual void __fastcall Dispatch(void * AMessage);
  166. private:
  167. bool FParentPainting;
  168. int FMargin;
  169. UnicodeString FShortHint;
  170. UnicodeString FLongHint;
  171. TControl * FHintControl;
  172. bool FHintPopup;
  173. std::unique_ptr<TFont> FScaledHintFont;
  174. UnicodeString __fastcall GetLongHintIfAny(const UnicodeString & AHint);
  175. static int __fastcall GetTextFlags(TControl * Control);
  176. bool __fastcall IsPathLabel(TControl * HintControl);
  177. bool __fastcall UseBoldShortHint(TControl * HintControl);
  178. int __fastcall GetMargin(TControl * HintControl, const UnicodeString & Hint);
  179. TFont * __fastcall GetFont(TControl * HintControl, const UnicodeString & Hint);
  180. TControl * __fastcall GetHintControl(void * Data);
  181. void __fastcall SplitHint(
  182. TControl * HintControl, const UnicodeString & Hint, UnicodeString & ShortHint, UnicodeString & LongHint);
  183. };
  184. //---------------------------------------------------------------------------
  185. // FindComponentClass takes parameter by reference and as such it cannot be implemented in
  186. // an inline method without a compiler warning, which we cannot suppress in a macro.
  187. // And having the implementation in a real code (not macro) also allows us to debug the code.
  188. void __fastcall FindComponentClass(
  189. void * Data, TReader * Reader, const UnicodeString ClassName, TComponentClass & ComponentClass);
  190. #define INTERFACE_HOOK_CUSTOM(PARENT) \
  191. protected: \
  192. virtual void __fastcall ReadState(TReader * Reader) \
  193. { \
  194. Reader->OnFindComponentClass = MakeMethod<TFindComponentClassEvent>(NULL, FindComponentClass); \
  195. PARENT::ReadState(Reader); \
  196. }
  197. #define INTERFACE_HOOK INTERFACE_HOOK_CUSTOM(TForm)
  198. //---------------------------------------------------------------------------
  199. extern const UnicodeString PageantTool;
  200. extern const UnicodeString PuttygenTool;
  201. //---------------------------------------------------------------------------
  202. #endif