InputDlg.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinInterface.h"
  5. #include <VCLCommon.h>
  6. #include <Windows.hpp>
  7. #include <Consts.hpp>
  8. #include <HistoryComboBox.hpp>
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. //---------------------------------------------------------------------------
  12. void __fastcall InputDialogHelp(void * /*Data*/, TObject * Sender)
  13. {
  14. TControl * Control = dynamic_cast<TControl *>(Sender);
  15. Application->HelpKeyword(Control->Parent->HelpKeyword);
  16. }
  17. //---------------------------------------------------------------------------
  18. bool __fastcall InputDialog(const AnsiString ACaption,
  19. const AnsiString APrompt, AnsiString & Value, AnsiString HelpKeyword,
  20. TStrings * History, bool PathInput)
  21. {
  22. TForm * Form;
  23. TLabel * Prompt;
  24. TEdit * Edit;
  25. THistoryComboBox * HistoryCombo;
  26. TPoint DialogUnits;
  27. int ButtonTop, ButtonWidth, ButtonHeight;
  28. bool Result = False;
  29. Form = new TForm(Application, 0); // bypass the VCL streaming (for Salamander)
  30. try
  31. {
  32. SetCorrectFormParent(Form);
  33. UseSystemSettingsPre(Form);
  34. Form->Canvas->Font = Form->Font;
  35. DialogUnits = GetAveCharSize(Form->Canvas);
  36. Form->BorderStyle = bsDialog;
  37. Form->Caption = ACaption;
  38. Form->ClientWidth = MulDiv(220, DialogUnits.x, 4);
  39. Form->ClientHeight = MulDiv(63, DialogUnits.y, 8);
  40. Form->Position = poMainFormCenter;
  41. if (!HelpKeyword.IsEmpty())
  42. {
  43. Form->HelpKeyword = HelpKeyword;
  44. Form->BorderIcons = TBorderIcons(Form->BorderIcons) << biHelp;
  45. }
  46. Prompt = new TLabel(Form);
  47. Prompt->Parent = Form;
  48. Prompt->AutoSize = True;
  49. Prompt->Left = MulDiv(8, DialogUnits.x, 4);
  50. Prompt->Top = MulDiv(8, DialogUnits.y, 8);
  51. Prompt->Caption = APrompt;
  52. TWinControl * EditControl;
  53. if (History == NULL)
  54. {
  55. Edit = new TEdit(Form);
  56. Edit->Parent = Form;
  57. Edit->Text = Value;
  58. Edit->SelectAll();
  59. Edit->MaxLength = 255;
  60. EditControl = Edit;
  61. }
  62. else
  63. {
  64. HistoryCombo = new THistoryComboBox(Form);
  65. HistoryCombo->Parent = Form;
  66. HistoryCombo->Text = Value;
  67. HistoryCombo->SelectAll();
  68. HistoryCombo->Items = History;
  69. HistoryCombo->MaxLength = 255;
  70. EditControl = HistoryCombo;
  71. }
  72. EditControl->Left = Prompt->Left;
  73. EditControl->Top = MulDiv(19, DialogUnits.y, 8);
  74. EditControl->Width = MulDiv(204, DialogUnits.x, 4);
  75. if (PathInput)
  76. {
  77. InstallPathWordBreakProc(EditControl);
  78. }
  79. Prompt->FocusControl = EditControl;
  80. ButtonTop = MulDiv(41, DialogUnits.y, 8);
  81. ButtonWidth = MulDiv(50, DialogUnits.x, 4);
  82. ButtonHeight = MulDiv(14, DialogUnits.y, 8);
  83. int ButtonSpace = MulDiv(5, DialogUnits.x, 4);
  84. int ButtonsStart;
  85. if (HelpKeyword.IsEmpty())
  86. {
  87. ButtonsStart = (Form->ClientWidth / 2) - ButtonWidth - (ButtonSpace / 2);
  88. }
  89. else
  90. {
  91. ButtonsStart = (Form->ClientWidth / 2) - (3 * ButtonWidth / 2) - ButtonSpace;
  92. }
  93. TButton * Button;
  94. Button = new TButton(Form);
  95. Button->Parent = Form;
  96. Button->Caption = Consts_SMsgDlgOK;
  97. Button->ModalResult = mrOk;
  98. Button->Default = True;
  99. Button->SetBounds(ButtonsStart, ButtonTop, ButtonWidth, ButtonHeight);
  100. Button = new TButton(Form);
  101. Button->Parent = Form;
  102. Button->Caption = Consts_SMsgDlgCancel;
  103. Button->ModalResult = mrCancel;
  104. Button->Cancel = True;
  105. Button->SetBounds(ButtonsStart + ButtonWidth + ButtonSpace, ButtonTop,
  106. ButtonWidth, ButtonHeight);
  107. if (!HelpKeyword.IsEmpty())
  108. {
  109. Button = new TButton(Form);
  110. Button->Parent = Form;
  111. Button->Caption = Consts_SMsgDlgHelp;
  112. Button->ModalResult = mrNone;
  113. Button->SetBounds(ButtonsStart + 2 * (ButtonWidth + ButtonSpace), ButtonTop,
  114. ButtonWidth, ButtonHeight);
  115. TNotifyEvent OnClick;
  116. ((TMethod*)&OnClick)->Code = InputDialogHelp;
  117. Button->OnClick = OnClick;
  118. }
  119. UseSystemSettingsPost(Form);
  120. if (Form->ShowModal() == mrOk)
  121. {
  122. if (History != NULL)
  123. {
  124. HistoryCombo->SaveToHistory();
  125. History->Assign(HistoryCombo->Items);
  126. Value = HistoryCombo->Text;
  127. }
  128. else
  129. {
  130. Value = Edit->Text;
  131. }
  132. Result = true;
  133. }
  134. }
  135. __finally
  136. {
  137. delete Form;
  138. }
  139. return Result;
  140. }
  141. //---------------------------------------------------------------------------