GUITools.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. void __fastcall ReleaseImagesModules();
  111. //---------------------------------------------------------------------------
  112. class TFrameAnimation
  113. {
  114. public:
  115. __fastcall TFrameAnimation();
  116. void __fastcall Init(TPaintBox * PaintBox, const UnicodeString & Name);
  117. void __fastcall Start();
  118. void __fastcall Stop();
  119. private:
  120. UnicodeString FName;
  121. TPaintBox * FPaintBox;
  122. TPngImageList * FImageList;
  123. int FFirstFrame;
  124. int FFirstLoopFrame;
  125. int FLastFrame;
  126. int FCurrentFrame;
  127. DWORD FNextFrameTick;
  128. TTimer * FTimer;
  129. bool FPainted;
  130. void __fastcall DoInit();
  131. void __fastcall PaintBoxPaint(TObject * Sender);
  132. void __fastcall CalculateNextFrameTick();
  133. TPngImageCollectionItem * __fastcall GetCurrentImage();
  134. void __fastcall Animate();
  135. void __fastcall Timer(TObject * Sender);
  136. void __fastcall Repaint();
  137. void __fastcall Rescale();
  138. static void __fastcall PaintBoxRescale(TComponent * Sender, TObject * Token);
  139. };
  140. //---------------------------------------------------------------------------
  141. class TScreenTipHintWindow : public THintWindow
  142. {
  143. public:
  144. __fastcall TScreenTipHintWindow(TComponent * Owner);
  145. virtual TRect __fastcall CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData);
  146. virtual void __fastcall ActivateHintData(const TRect & Rect, const UnicodeString AHint, void * AData);
  147. static void __fastcall CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint);
  148. protected:
  149. virtual void __fastcall Paint();
  150. virtual void __fastcall Dispatch(void * AMessage);
  151. private:
  152. bool FParentPainting;
  153. int FMargin;
  154. UnicodeString FShortHint;
  155. UnicodeString FLongHint;
  156. TControl * FHintControl;
  157. bool FHintPopup;
  158. std::unique_ptr<TFont> FScaledHintFont;
  159. UnicodeString __fastcall GetLongHintIfAny(const UnicodeString & AHint);
  160. static int __fastcall GetTextFlags(TControl * Control);
  161. bool __fastcall IsPathLabel(TControl * HintControl);
  162. bool __fastcall UseBoldShortHint(TControl * HintControl);
  163. int __fastcall GetMargin(TControl * HintControl, const UnicodeString & Hint);
  164. TFont * __fastcall GetFont(TControl * HintControl, const UnicodeString & Hint);
  165. TControl * __fastcall GetHintControl(void * Data);
  166. void __fastcall SplitHint(
  167. TControl * HintControl, const UnicodeString & Hint, UnicodeString & ShortHint, UnicodeString & LongHint);
  168. };
  169. //---------------------------------------------------------------------------
  170. // Newer version rich edit that supports "Friendly name hyperlinks" and
  171. // allows wider range of Unicode characters: https://stackoverflow.com/q/47433656/850848
  172. class TNewRichEdit : public TRichEdit
  173. {
  174. public:
  175. virtual __fastcall TNewRichEdit(TComponent * AOwner);
  176. protected:
  177. virtual void __fastcall CreateParams(TCreateParams & Params);
  178. virtual void __fastcall CreateWnd();
  179. virtual void __fastcall DestroyWnd();
  180. private:
  181. HINSTANCE FLibrary;
  182. };
  183. //---------------------------------------------------------------------------
  184. // Based on:
  185. // https://stackoverflow.com/q/6912424/850848
  186. // https://stackoverflow.com/q/4685863/850848
  187. class TUIStateAwareLabel : public TLabel
  188. {
  189. public:
  190. __fastcall virtual TUIStateAwareLabel(TComponent * AOwner);
  191. protected:
  192. DYNAMIC void __fastcall DoDrawText(TRect & Rect, int Flags);
  193. virtual void __fastcall Dispatch(void * AMessage);
  194. };
  195. // FindComponentClass takes parameter by reference and as such it cannot be implemented in
  196. // an inline method without a compiler warning, which we cannot suppress in a macro.
  197. // And having the implementation in a real code (not macro) also allows us to debug the code.
  198. void __fastcall FindComponentClass(
  199. void * Data, TReader * Reader, const UnicodeString ClassName, TComponentClass & ComponentClass);
  200. #define INTERFACE_HOOK_CUSTOM(PARENT) \
  201. protected: \
  202. virtual void __fastcall ReadState(TReader * Reader) \
  203. { \
  204. Reader->OnFindComponentClass = MakeMethod<TFindComponentClassEvent>(NULL, FindComponentClass); \
  205. PARENT::ReadState(Reader); \
  206. }
  207. #define INTERFACE_HOOK INTERFACE_HOOK_CUSTOM(TForm)
  208. //---------------------------------------------------------------------------
  209. extern const UnicodeString PageantTool;
  210. extern const UnicodeString PuttygenTool;
  211. //---------------------------------------------------------------------------
  212. #endif