GUITools.h 9.7 KB

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