WinHelp.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <Tools.h>
  6. #include <TextsWin.h>
  7. #include <CoreMain.h>
  8. #include <HelpIntfs.hpp>
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. //---------------------------------------------------------------------------
  12. class TWebHelpSystem : public TInterfacedObject, public ICustomHelpViewer
  13. {
  14. public:
  15. __fastcall TWebHelpSystem(const UnicodeString & Version, const UnicodeString & Language);
  16. virtual int __fastcall UnderstandsKeyword(const UnicodeString HelpString);
  17. virtual TStringList * __fastcall GetHelpStrings(const UnicodeString HelpString);
  18. virtual void __fastcall NotifyID(const int ViewerID);
  19. virtual void __fastcall SoftShutDown();
  20. virtual void __fastcall ShutDown();
  21. virtual UnicodeString __fastcall GetViewerName();
  22. virtual bool __fastcall CanShowTableOfContents();
  23. virtual void __fastcall ShowTableOfContents();
  24. virtual void __fastcall ShowHelp(const UnicodeString HelpString);
  25. IUNKNOWN
  26. private:
  27. UnicodeString FVersion;
  28. UnicodeString FLanguage;
  29. };
  30. //---------------------------------------------------------------------------
  31. void __fastcall SearchHelp(const UnicodeString & Message)
  32. {
  33. // Message goes last, as it may exceed URL parameters limit (2048) and get truncated.
  34. // And we need to preserve the other parameters.
  35. OpenBrowser(FMTLOAD(DOCUMENTATION_SEARCH_URL3,
  36. (Configuration->ProductVersion, GUIConfiguration->LocaleHex,
  37. EncodeUrlString(Message))));
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall InitializeWinHelp()
  41. {
  42. InitializeCustomHelp(new TWebHelpSystem(
  43. Configuration->ProductVersion, GUIConfiguration->LocaleHex));
  44. }
  45. //---------------------------------------------------------------------------
  46. void __fastcall FinalizeWinHelp()
  47. {
  48. FinalizeCustomHelp();
  49. }
  50. //---------------------------------------------------------------------------
  51. __fastcall TWebHelpSystem::TWebHelpSystem(
  52. const UnicodeString & Version, const UnicodeString & Language) :
  53. FVersion(Version), FLanguage(Language)
  54. {
  55. }
  56. //---------------------------------------------------------------------------
  57. int __fastcall TWebHelpSystem::UnderstandsKeyword(const UnicodeString HelpString)
  58. {
  59. // pretend that we know everything
  60. return 1;
  61. }
  62. //---------------------------------------------------------------------------
  63. TStringList * __fastcall TWebHelpSystem::GetHelpStrings(const UnicodeString HelpString)
  64. {
  65. TStringList * Result = new TStringList();
  66. Result->Add(GetViewerName() + L" : " + HelpString);
  67. return Result;
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TWebHelpSystem::NotifyID(const int /*ViewerID*/)
  71. {
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TWebHelpSystem::SoftShutDown()
  75. {
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TWebHelpSystem::ShutDown()
  79. {
  80. }
  81. //---------------------------------------------------------------------------
  82. UnicodeString __fastcall TWebHelpSystem::GetViewerName()
  83. {
  84. return L"Web";
  85. }
  86. //---------------------------------------------------------------------------
  87. bool __fastcall TWebHelpSystem::CanShowTableOfContents()
  88. {
  89. return true;
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TWebHelpSystem::ShowTableOfContents()
  93. {
  94. OpenBrowser(FMTLOAD(DOCUMENTATION_URL2, (FVersion, FLanguage)));
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TWebHelpSystem::ShowHelp(const UnicodeString AHelpString)
  98. {
  99. if (IsHttpOrHttpsUrl(AHelpString))
  100. {
  101. OpenBrowser(AHelpString);
  102. }
  103. else
  104. {
  105. ::ShowHelp(AHelpString);
  106. }
  107. }