VCLCommon.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //---------------------------------------------------------------------------
  2. #ifndef VCLCommonH
  3. #define VCLCommonH
  4. //---------------------------------------------------------------------------
  5. #include "Common.h"
  6. #include "Configuration.h"
  7. #include "Exceptions.h"
  8. #include <ComCtrls.hpp>
  9. //---------------------------------------------------------------------------
  10. void __fastcall AdjustListColumnsWidth(TListView* ListView, int RowCount = -1,
  11. int RightPad = 0);
  12. void __fastcall EnableControl(TControl* Control, bool Enable);
  13. void __fastcall ReadOnlyControl(TControl * Control, bool ReadOnly = true);
  14. void __fastcall InitializeSystemSettings();
  15. void __fastcall FinalizeSystemSettings();
  16. void __fastcall LocalSystemSettings(TCustomForm * Control);
  17. void __fastcall UseSystemSettingsPre(TCustomForm * Control, void ** Settings = NULL);
  18. void __fastcall UseSystemSettingsPost(TCustomForm * Control, void * Settings = NULL);
  19. void __fastcall UseSystemSettings(TCustomForm * Control, void ** Settings = NULL);
  20. void __fastcall ResetSystemSettings(TCustomForm * Control);
  21. void __fastcall RevokeSystemSettings(TCustomForm * Control, void * Settings);
  22. void __fastcall DeleteSystemSettings(TCustomForm * Control, void * Settings);
  23. void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url = L"",
  24. TNotifyEvent OnEnter = NULL);
  25. void __fastcall HintLabel(TStaticText * StaticText, UnicodeString Hint = L"");
  26. void __fastcall HintLabelRestore(TStaticText * StaticText);
  27. void __fastcall HotTrackLabel(TLabel * Label);
  28. void __fastcall FixComboBoxResizeBug(TCustomComboBox * ComboBox);
  29. void __fastcall ShowAsModal(TForm * Form, void *& Storage);
  30. void __fastcall HideAsModal(TForm * Form, void *& Storage);
  31. void __fastcall ReleaseAsModal(TForm * Form, void *& Storage);
  32. TImageList * __fastcall SharedSystemImageList(bool Large);
  33. bool __fastcall SelectDirectory(UnicodeString & Path, const UnicodeString Prompt,
  34. bool PreserveFileName);
  35. enum TListViewCheckAll { caCheck, caUncheck, caToggle };
  36. bool __fastcall ListViewAnyChecked(TListView * ListView, bool Checked = true);
  37. void __fastcall ListViewCheckAll(TListView * ListView,
  38. TListViewCheckAll CheckAll);
  39. void __fastcall ComboAutoSwitchInitialize(TComboBox * ComboBox);
  40. void __fastcall ComboAutoSwitchLoad(TComboBox * ComboBox, TAutoSwitch Value);
  41. TAutoSwitch __fastcall ComboAutoSwitchSave(TComboBox * ComboBox);
  42. void __fastcall CheckBoxAutoSwitchLoad(TCheckBox * CheckBox, TAutoSwitch Value);
  43. TAutoSwitch __fastcall CheckBoxAutoSwitchSave(TCheckBox * CheckBox);
  44. void __fastcall InstallPathWordBreakProc(TWinControl * Control);
  45. void __fastcall RepaintStatusBar(TCustomStatusBar * StatusBar);
  46. void __fastcall SetVerticalControlsOrder(TControl ** ControlsOrder, int Count);
  47. void __fastcall SetHorizontalControlsOrder(TControl ** ControlsOrder, int Count);
  48. TPoint __fastcall GetAveCharSize(TCanvas * Canvas);
  49. void __fastcall MakeNextInTabOrder(TWinControl * Control, TWinControl * After);
  50. void __fastcall CutFormToDesktop(TForm * Form);
  51. void __fastcall UpdateFormPosition(TCustomForm * Form, TPosition Position);
  52. void __fastcall ResizeForm(TCustomForm * Form, int Width, int Height);
  53. TComponent * __fastcall GetFormOwner();
  54. void __fastcall SetCorrectFormParent(TForm * Form);
  55. void __fastcall InvokeHelp(TWinControl * Control);
  56. Forms::TMonitor * __fastcall FormMonitor(TCustomForm * Form);
  57. int __fastcall GetLastMonitor();
  58. void __fastcall SetLastMonitor(int MonitorNum);
  59. TForm * __fastcall _SafeFormCreate(TMetaClass * FormClass, TComponent * Owner);
  60. template<class FormType>
  61. FormType * __fastcall SafeFormCreate(TComponent * Owner = NULL)
  62. {
  63. return dynamic_cast<FormType *>(_SafeFormCreate(__classid(FormType), Owner));
  64. }
  65. bool __fastcall SupportsSplitButton();
  66. //---------------------------------------------------------------------------
  67. // When exception is left to be handled by Application->OnException
  68. // memory error occurs when clearing the exception for unknown reason.
  69. // (possibly only when exception handling takes too long,
  70. // such as when reconnect is retried)
  71. // deferring call after the catch clause gets rid of the problem.
  72. // on the other hand, not sure if there's some code that actually
  73. // relies on exception leaving the method when we use APPLICATION_EXCEPTION_HACK*
  74. // (such as then timer is called from withing event loop run
  75. // by our code, which we want to break too with the exception).
  76. // Steps to reproduce the problem:
  77. // 1) Connect
  78. // 2) Terminate the server
  79. // 3) Let is try to reconnect once
  80. // 4) Start the server and let it reconnect
  81. // 5) Upon clearing the original terminattion exception from 2)
  82. // the EAccessViolation is thrown
  83. class TApplicationExceptionHackHelper
  84. {
  85. public:
  86. void __fastcall Catch(Exception & E)
  87. {
  88. FSavedException.reset(CloneException(&E));
  89. }
  90. void __fastcall Handle()
  91. {
  92. if (FSavedException.get() != NULL)
  93. {
  94. Application->OnException(Application, FSavedException.get());
  95. Abort();
  96. }
  97. }
  98. private:
  99. std::auto_ptr<Exception> FSavedException;
  100. };
  101. //---------------------------------------------------------------------------
  102. #define APPLICATION_EXCEPTION_HACK_BEGIN \
  103. TApplicationExceptionHackHelper _ExceptionHackHelper; \
  104. try
  105. #define APPLICATION_EXCEPTION_HACK_END \
  106. catch (Exception & E) \
  107. { \
  108. _ExceptionHackHelper.Catch(E); \
  109. } \
  110. _ExceptionHackHelper.Handle();
  111. //---------------------------------------------------------------------------
  112. #endif // VCLCommonH