GUITools.h 9.5 KB

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