SelLangForm.pas 3.3 KB

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