VCLCommon.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "VCLCommon.h"
  5. #include <Common.h>
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. //---------------------------------------------------------------------------
  9. void __fastcall AdjustListColumnsWidth(TListView* ListView)
  10. {
  11. int OriginalWidth, NewWidth, i, CWidth;
  12. OriginalWidth = 0;
  13. for (i = 0; i < ListView->Columns->Count; i++)
  14. {
  15. OriginalWidth += ListView->Columns->Items[i]->Width;
  16. }
  17. NewWidth = 0;
  18. CWidth = ListView->ClientWidth;
  19. if ((ListView->VisibleRowCount < ListView->Items->Count) &&
  20. (ListView->Width - ListView->ClientWidth < GetSystemMetrics(SM_CXVSCROLL)))
  21. {
  22. CWidth -= GetSystemMetrics(SM_CXVSCROLL);
  23. }
  24. for (i = 0; i < ListView->Columns->Count-1;i++)
  25. {
  26. if (ListView->Columns->Items[i]->Tag == 0)
  27. {
  28. ListView->Columns->Items[i]->Width =
  29. (CWidth * ListView->Columns->Items[i]->Width) / OriginalWidth;
  30. }
  31. NewWidth += ListView->Columns->Items[i]->Width;
  32. }
  33. ListView->Columns->Items[ListView->Columns->Count-1]->Width = CWidth-NewWidth;
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall EnableControl(TControl * Control, bool Enable)
  37. {
  38. if (Control->Enabled != Enable)
  39. {
  40. if (Control->InheritsFrom(__classid(TWinControl)) &&
  41. (((TWinControl*)Control)->ControlCount > 0))
  42. {
  43. for (Integer Index = 0; Index < ((TWinControl*)Control)->ControlCount; Index++)
  44. EnableControl(((TWinControl*)Control)->Controls[Index], Enable);
  45. }
  46. Control->Enabled = Enable;
  47. }
  48. if (Control->InheritsFrom(__classid(TCustomEdit)) ||
  49. Control->InheritsFrom(__classid(TCustomComboBox)))
  50. {
  51. if (Enable) ((TEdit*)Control)->Color = clWindow;
  52. else ((TEdit*)Control)->Color = clBtnFace;
  53. }
  54. };
  55. //---------------------------------------------------------------------------
  56. void __fastcall UseSystemFont(TCustomForm * Control)
  57. {
  58. assert(Control && Control->Font);
  59. Control->Font->Name = "MS Shell Dlg";
  60. };
  61. //---------------------------------------------------------------------------
  62. void __fastcall LinkLabel(TLabel * Label)
  63. {
  64. Label->ParentFont = true;
  65. Label->Font->Style = Label->Font->Style << fsUnderline;
  66. Label->Font->Color = clBlue;
  67. }
  68. //---------------------------------------------------------------------------
  69. /*void __fastcall ShowAsModal(TCustomForm * Form)
  70. {
  71. CancelDrag();
  72. if (GetCapture() != 0) SendMessage(GetCapture(), WM_CANCELMODE, 0, 0);
  73. ReleaseCapture();
  74. FFormState << fsModal;
  75. FFocusActiveWindow = GetActiveWindow();
  76. FFocusWindowList = DisableTaskWindows(0);
  77. Show();
  78. SendMessage(Handle, CM_ACTIVATE, 0, 0);
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TProgressForm::HideAsModal()
  82. {
  83. SendMessage(Handle, CM_DEACTIVATE, 0, 0);
  84. if (GetActiveWindow() != Handle)
  85. {
  86. FFocusActiveWindow = 0;
  87. }
  88. Hide();
  89. EnableTaskWindows(FFocusWindowList);
  90. if (FFocusActiveWindow != 0)
  91. {
  92. SetActiveWindow(FFocusActiveWindow);
  93. }
  94. FFormState >> fsModal;
  95. } */