GUITools.h 9.5 KB

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