GUITools.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. using namespace Webbrowserex;
  69. TWebBrowserEx * __fastcall CreateBrowserViewer(TPanel * Parent, const UnicodeString & LoadingLabel);
  70. void __fastcall SetBrowserDesignModeOff(TWebBrowserEx * WebBrowser);
  71. void __fastcall AddBrowserLinkHandler(TWebBrowserEx * WebBrowser,
  72. const UnicodeString & Url, TNotifyEvent Handler);
  73. void __fastcall NavigateBrowserToUrl(TWebBrowserEx * WebBrowser, const UnicodeString & Url);
  74. void ReadyBrowserForStreaming(TWebBrowserEx * WebBrowser);
  75. void WaitBrowserToIdle(TWebBrowserEx * WebBrowser);
  76. void HideBrowserScrollbars(TWebBrowserEx * WebBrowser);
  77. bool CopyTextFromBrowser(TWebBrowserEx * WebBrowser, UnicodeString & Text);
  78. UnicodeString GenerateAppHtmlPage(TFont * Font, TPanel * Parent, const UnicodeString & Body, bool Seamless);
  79. void LoadBrowserDocument(TWebBrowserEx * WebBrowser, const UnicodeString & Document);
  80. TComponent * __fastcall FindComponentRecursively(TComponent * Root, const UnicodeString & Name);
  81. void __fastcall GetInstrutionsTheme(
  82. TColor & MainInstructionColor, HFONT & MainInstructionFont, HFONT & InstructionFont);
  83. bool CanShowTimeEstimate(TDateTime StartTime);
  84. //---------------------------------------------------------------------------
  85. class TLocalCustomCommand : public TFileCustomCommand
  86. {
  87. public:
  88. TLocalCustomCommand();
  89. TLocalCustomCommand(
  90. const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath);
  91. TLocalCustomCommand(
  92. const TCustomCommandData & Data, const UnicodeString & RemotePath, const UnicodeString & LocalPath,
  93. const UnicodeString & FileName, const UnicodeString & LocalFileName,
  94. const UnicodeString & FileList);
  95. virtual bool __fastcall IsFileCommand(const UnicodeString & Command);
  96. bool __fastcall HasLocalFileName(const UnicodeString & Command);
  97. protected:
  98. virtual int __fastcall PatternLen(const UnicodeString & Command, int Index);
  99. virtual bool __fastcall PatternReplacement(int Index, const UnicodeString & Pattern,
  100. UnicodeString & Replacement, bool & Delimit);
  101. virtual void __fastcall DelimitReplacement(UnicodeString & Replacement, wchar_t Quote);
  102. private:
  103. UnicodeString FLocalPath;
  104. UnicodeString FLocalFileName;
  105. };
  106. //---------------------------------------------------------------------------
  107. namespace Pngimagelist
  108. {
  109. class TPngImageList;
  110. class TPngImageCollectionItem;
  111. }
  112. using namespace Pngimagelist;
  113. //---------------------------------------------------------------------------
  114. TPngImageList * __fastcall GetAnimationsImages(TControl * Control);
  115. TImageList * __fastcall GetButtonImages(TControl * Control);
  116. TPngImageList * __fastcall GetDialogImages(TControl * Control);
  117. TCustomImageList * TreeViewImageList(TPngImageList * ImageList);
  118. void __fastcall ReleaseImagesModules();
  119. //---------------------------------------------------------------------------
  120. class TFrameAnimation
  121. {
  122. public:
  123. __fastcall TFrameAnimation();
  124. void __fastcall Init(TPaintBox * PaintBox, const UnicodeString & Name);
  125. void __fastcall Start();
  126. void __fastcall Stop();
  127. private:
  128. UnicodeString FName;
  129. TPaintBox * FPaintBox;
  130. TPngImageList * FImageList;
  131. int FFirstFrame;
  132. int FFirstLoopFrame;
  133. int FLastFrame;
  134. int FCurrentFrame;
  135. DWORD FNextFrameTick;
  136. TTimer * FTimer;
  137. bool FPainted;
  138. void __fastcall DoInit();
  139. void __fastcall PaintBoxPaint(TObject * Sender);
  140. void __fastcall CalculateNextFrameTick();
  141. TPngImageCollectionItem * __fastcall GetCurrentImage();
  142. void __fastcall Animate();
  143. void __fastcall Timer(TObject * Sender);
  144. void __fastcall Repaint();
  145. void __fastcall Rescale();
  146. static void __fastcall PaintBoxRescale(TComponent * Sender, TObject * Token);
  147. };
  148. //---------------------------------------------------------------------------
  149. class TScreenTipHintWindow : public THintWindow
  150. {
  151. public:
  152. __fastcall TScreenTipHintWindow(TComponent * Owner);
  153. virtual TRect __fastcall CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData);
  154. virtual void __fastcall ActivateHintData(const TRect & Rect, const UnicodeString AHint, void * AData);
  155. static void __fastcall CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint);
  156. protected:
  157. virtual void __fastcall Paint();
  158. virtual void __fastcall Dispatch(void * AMessage);
  159. private:
  160. bool FParentPainting;
  161. int FMargin;
  162. UnicodeString FShortHint;
  163. UnicodeString FLongHint;
  164. TControl * FHintControl;
  165. bool FHintPopup;
  166. std::unique_ptr<TFont> FScaledHintFont;
  167. UnicodeString __fastcall GetLongHintIfAny(const UnicodeString & AHint);
  168. static int __fastcall GetTextFlags(TControl * Control);
  169. bool __fastcall IsPathLabel(TControl * HintControl);
  170. bool __fastcall UseBoldShortHint(TControl * HintControl);
  171. int __fastcall GetMargin(TControl * HintControl, const UnicodeString & Hint);
  172. TFont * __fastcall GetFont(TControl * HintControl, const UnicodeString & Hint);
  173. TControl * __fastcall GetHintControl(void * Data);
  174. void __fastcall SplitHint(
  175. TControl * HintControl, const UnicodeString & Hint, UnicodeString & ShortHint, UnicodeString & LongHint);
  176. };
  177. //---------------------------------------------------------------------------
  178. // FindComponentClass takes parameter by reference and as such it cannot be implemented in
  179. // an inline method without a compiler warning, which we cannot suppress in a macro.
  180. // And having the implementation in a real code (not macro) also allows us to debug the code.
  181. void __fastcall FindComponentClass(
  182. void * Data, TReader * Reader, const UnicodeString ClassName, TComponentClass & ComponentClass);
  183. #define INTERFACE_HOOK_CUSTOM(PARENT) \
  184. protected: \
  185. virtual void __fastcall ReadState(TReader * Reader) \
  186. { \
  187. Reader->OnFindComponentClass = MakeMethod<TFindComponentClassEvent>(NULL, FindComponentClass); \
  188. PARENT::ReadState(Reader); \
  189. }
  190. #define INTERFACE_HOOK INTERFACE_HOOK_CUSTOM(TForm)
  191. //---------------------------------------------------------------------------
  192. extern const UnicodeString PageantTool;
  193. extern const UnicodeString PuttygenTool;
  194. //---------------------------------------------------------------------------
  195. #endif