Setup.SelectLanguageForm.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. unit Setup.SelectLanguageForm;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. "Select Language" form
  8. }
  9. interface
  10. uses
  11. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12. Setup.SetupForm, StdCtrls, ExtCtrls, NewStaticText, BitmapImage, BidiCtrls;
  13. type
  14. TSelectLanguageForm = class(TSetupForm)
  15. SelectLabel: TNewStaticText;
  16. LangCombo: TNewComboBox;
  17. OKButton: TNewButton;
  18. CancelButton: TNewButton;
  19. IconBitmapImage: TBitmapImage;
  20. MainPanel: TPanel;
  21. Bevel: TBevel;
  22. public
  23. constructor Create(AOwner: TComponent); override;
  24. end;
  25. function AskForLanguage: Boolean;
  26. implementation
  27. uses
  28. Shared.Struct, SetupLdrAndSetup.Messages, Shared.SetupMessageIDs,
  29. Setup.MainFunc, Shared.CommonFunc.Vcl;
  30. {$R *.DFM}
  31. function AskForLanguage: Boolean;
  32. { Creates and shows the "Select Language" dialog. Returns True and activates
  33. the selected language if the user clicks OK, or False otherwise. }
  34. var
  35. LangForm: TSelectLanguageForm;
  36. I, J: Integer;
  37. LangEntry: PSetupLanguageEntry;
  38. begin
  39. LangForm := AppCreateForm(TSelectLanguageForm) as TSelectLanguageForm;
  40. try
  41. for I := 0 to Entries[seLanguage].Count-1 do begin
  42. LangEntry := Entries[seLanguage][I];
  43. J := LangForm.LangCombo.Items.Add(LangEntry.LanguageName);
  44. LangForm.LangCombo.Items.Objects[J] := TObject(I);
  45. end;
  46. { If there's multiple languages, select the previous language, if available }
  47. if (shUsePreviousLanguage in SetupHeader.Options) and
  48. (LangForm.LangCombo.Items.Count > 1) then begin
  49. { Note: if UsePreviousLanguage is set to "yes" then the compiler does not
  50. allow AppId to include constants but we should still call ExpandConst
  51. to handle any '{{'. }
  52. I := GetPreviousLanguage(ExpandConst(SetupHeader.AppId));
  53. if I <> -1 then
  54. LangForm.LangCombo.ItemIndex := LangForm.LangCombo.Items.IndexOfObject(TObject(I));
  55. end;
  56. { Select the active language if no previous language was selected }
  57. if LangForm.LangCombo.ItemIndex = -1 then
  58. LangForm.LangCombo.ItemIndex := LangForm.LangCombo.Items.IndexOfObject(TObject(ActiveLanguage));
  59. if LangForm.LangCombo.Items.Count > 1 then begin
  60. Result := (LangForm.ShowModal = mrOK);
  61. if Result then begin
  62. I := LangForm.LangCombo.ItemIndex;
  63. if I >= 0 then
  64. SetActiveLanguage(Integer(LangForm.LangCombo.Items.Objects[I]));
  65. end;
  66. end
  67. else begin
  68. { Don't show language dialog if there aren't multiple languages to choose
  69. from, which can happen if only one language matches the user's code
  70. page. }
  71. Result := True;
  72. end;
  73. finally
  74. LangForm.Free;
  75. end;
  76. end;
  77. { TSelectLanguageForm }
  78. constructor TSelectLanguageForm.Create(AOwner: TComponent);
  79. begin
  80. inherited;
  81. MainPanel.ParentBackground := False;
  82. InitializeFont;
  83. Caption := SetupMessages[msgSelectLanguageTitle];
  84. SelectLabel.Caption := SetupMessages[msgSelectLanguageLabel];
  85. OKButton.Caption := SetupMessages[msgButtonOK];
  86. CancelButton.Caption := SetupMessages[msgButtonCancel];
  87. IconBitmapImage.InitializeFromIcon(HInstance, 'MAINICON', MainPanel.Color, [32, 48, 64]);
  88. KeepSizeY := True;
  89. end;
  90. end.