(************************************************************************
*    This File is Part of the AHM Triton Tools                          *
*    for Borland Delphi and C++ Builder.                                *
*************************************************************************
* Copyright © 1995-1999 Alexander H. Mehlhorn (AHM) and Tritontools.com *
* All Rights reserved.                                                  *
*                                                                       *
*    For more Information contact us at                                 *
*    E-Mail : support@tritontools.com                                   *
*    URL : http://www.tritontools.com                                   *
*                                                                       *
*    AHM is copyright by Alexander H. Mehlhorn                          *
*    All Parts of this Collection were developed,                       *
*    designed and implemented by AHM                                    *
*                                                                       *
*    Under no Circumstances may you distribute this file                *
*    in this or any other format. This File is supplied                 *
*    as Evaluation of Source only. No Delphi Components may be developed*
*    using extracts or subsets of this code without expressed permission*
*    by AHM.                                                            *
*                                                                       *
*************************************************************************)
unit AHMTLanguageCombo;

interface
{$I AHM.INC}
uses Windows, SysUtils, Classes, StdCtrls,AHMStdClass;

type
  TAHMLanguageCombo = class(TCustomComboBox)
  private
    FAboutStr : TAHMAboutSControlStr;
    function GetLangID: Word;
    function GetLangIdAsString: string;
    procedure SetLangID(Value: Word);
  protected
    procedure CreateWnd; override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Loaded; override;
    property LangID: Word read GetLangID write SetLangID;
    property LangIdAsString: string read GetLangIdAsString;
  published
    property About : TAHMAboutSControlStr read FAboutStr write FAboutStr;
    property Color;
    property Ctl3D;
   {$IFDEF AHMONLY4}
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragKind;
    property ParentBiDiMode;
    {$ENDIF}
    property DragMode;
    property DragCursor;
    property DropDownCount;
    property Enabled;
    property Font;
    {$IFDEF AHMINPRISE3}
    property ImeMode;
    property ImeName;
    {$ENDIF}
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Text;
    property Visible;
    property Width default 200;
    property OnChange;
    property OnClick;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnStartDrag;
  end;
implementation
const
  LangCodes: array[0..107] of Word = (
	LANG_SYSTEM_DEFAULT,
	LANG_USER_DEFAULT,
	LANG_AFRIKAANS or SUBLANG_DEFAULT shl 10,
	LANG_ALBANIAN or SUBLANG_DEFAULT shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_SAUDI_ARABIA shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_IRAQ shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_EGYPT shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_LIBYA shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_ALGERIA shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_MOROCCO shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_TUNISIA shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_OMAN shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_YEMEN shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_SYRIA shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_JORDAN shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_LEBANON shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_KUWAIT shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_UAE shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_BAHRAIN shl 10,
	LANG_ARABIC or SUBLANG_ARABIC_QATAR shl 10,
	LANG_BASQUE or SUBLANG_DEFAULT shl 10,
	LANG_BELARUSIAN or SUBLANG_DEFAULT shl 10,
	LANG_BULGARIAN or SUBLANG_DEFAULT shl 10,
	LANG_CATALAN or SUBLANG_DEFAULT shl 10,
	LANG_CHINESE or SUBLANG_DEFAULT shl 10,
	LANG_CHINESE or SUBLANG_CHINESE_TRADITIONAL shl 10,
	LANG_CHINESE or SUBLANG_CHINESE_SIMPLIFIED shl 10,
	LANG_CHINESE or SUBLANG_CHINESE_HONGKONG shl 10,
	LANG_CHINESE or SUBLANG_CHINESE_SINGAPORE shl 10,
	LANG_CROATIAN or SUBLANG_DEFAULT shl 10,
	LANG_CZECH or SUBLANG_DEFAULT shl 10,
	LANG_DANISH or SUBLANG_DEFAULT shl 10,
	LANG_DUTCH or SUBLANG_DUTCH shl 10,
	LANG_DUTCH or SUBLANG_DUTCH_BELGIAN shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_US shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_UK shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_AUS shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_CAN shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_NZ shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_EIRE shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_SOUTH_AFRICA shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_JAMAICA shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_CARIBBEAN shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_BELIZE shl 10,
	LANG_ENGLISH or SUBLANG_ENGLISH_TRINIDAD shl 10,
	LANG_ESTONIAN or SUBLANG_DEFAULT shl 10,
	LANG_FAEROESE or SUBLANG_DEFAULT shl 10,
	LANG_FARSI or SUBLANG_DEFAULT shl 10,
	LANG_FINNISH or SUBLANG_DEFAULT shl 10,
	LANG_FRENCH or SUBLANG_FRENCH shl 10,
	LANG_FRENCH or SUBLANG_FRENCH_BELGIAN shl 10,
	LANG_FRENCH or SUBLANG_FRENCH_CANADIAN shl 10,
	LANG_FRENCH or SUBLANG_FRENCH_SWISS shl 10,
	LANG_FRENCH or SUBLANG_FRENCH_LUXEMBOURG shl 10,
	LANG_GERMAN or SUBLANG_GERMAN shl 10,
	LANG_GERMAN or SUBLANG_GERMAN_SWISS shl 10,
	LANG_GERMAN or SUBLANG_GERMAN_AUSTRIAN shl 10,
	LANG_GERMAN or SUBLANG_GERMAN_LUXEMBOURG shl 10,
	LANG_GERMAN or SUBLANG_GERMAN_LIECHTENSTEIN shl 10,
	LANG_GREEK or SUBLANG_DEFAULT shl 10,
	LANG_HEBREW or SUBLANG_DEFAULT shl 10,
	LANG_HUNGARIAN or SUBLANG_DEFAULT shl 10,
	LANG_ICELANDIC or SUBLANG_DEFAULT shl 10,
	LANG_INDONESIAN or SUBLANG_DEFAULT shl 10,
	LANG_ITALIAN or SUBLANG_ITALIAN shl 10,
	LANG_ITALIAN or SUBLANG_ITALIAN_SWISS shl 10,
	LANG_JAPANESE or SUBLANG_DEFAULT shl 10,
	LANG_KOREAN or SUBLANG_KOREAN shl 10,
	LANG_KOREAN or SUBLANG_KOREAN_JOHAB shl 10,
	LANG_LATVIAN or SUBLANG_DEFAULT shl 10,
	LANG_NORWEGIAN or SUBLANG_NORWEGIAN_BOKMAL shl 10,
	LANG_NORWEGIAN or SUBLANG_NORWEGIAN_NYNORSK shl 10,
	LANG_POLISH or SUBLANG_DEFAULT shl 10,
	LANG_PORTUGUESE or SUBLANG_PORTUGUESE shl 10,
	LANG_PORTUGUESE or SUBLANG_PORTUGUESE_BRAZILIAN shl 10,
	LANG_ROMANIAN or SUBLANG_DEFAULT shl 10,
	LANG_RUSSIAN or SUBLANG_DEFAULT shl 10,
	LANG_SERBIAN or SUBLANG_DEFAULT shl 10,
	LANG_SERBIAN or SUBLANG_SERBIAN_LATIN shl 10,
	LANG_SERBIAN or SUBLANG_SERBIAN_CYRILLIC shl 10,
	LANG_SLOVAK or SUBLANG_DEFAULT shl 10,
	LANG_SLOVENIAN or SUBLANG_DEFAULT shl 10,
	LANG_SPANISH or SUBLANG_SPANISH shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_MEXICAN shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_MODERN shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_GUATEMALA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_COSTA_RICA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_PANAMA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_DOMINICAN_REPUBLIC shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_VENEZUELA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_COLOMBIA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_PERU shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_ARGENTINA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_ECUADOR shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_CHILE shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_URUGUAY shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_PARAGUAY shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_BOLIVIA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_EL_SALVADOR shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_HONDURAS shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_NICARAGUA shl 10,
	LANG_SPANISH or SUBLANG_SPANISH_PUERTO_RICO shl 10,
	LANG_SWEDISH or SUBLANG_SWEDISH shl 10,
	LANG_SWEDISH or SUBLANG_SWEDISH_FINLAND shl 10,
	LANG_THAI or SUBLANG_DEFAULT shl 10,
	LANG_TURKISH or SUBLANG_DEFAULT shl 10,
	LANG_UKRAINIAN or SUBLANG_DEFAULT shl 10,
	LANG_VIETNAMESE or SUBLANG_DEFAULT shl 10);

function GetLanguageName(LangID: Word): string;
var Buf: array[0..79] of Char;
begin
  VerLanguageName(LangID, @Buf, SizeOf(Buf)-1);
  Result := Buf;
end;

constructor TAHMLanguageCombo.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  Style := csDropDownList;
  Width := 200;
end;

destructor TAHMLanguageCombo.Destroy;
begin
  inherited Destroy;
end;

procedure TAHMLanguageCombo.Loaded;
begin
  inherited Loaded;
end;

procedure TAHMLanguageCombo.CreateWnd;
var i: Integer;
begin
  inherited CreateWnd;
  for i := Low(LangCodes) to High(LangCodes) do  Items.Add(GetLanguageName(LangCodes[i]));
  LangID := GetUserDefaultLangID;
end;

function TAHMLanguageCombo.GetLangID: Word;
begin
  Result := LangCodes[ItemIndex];
end;

procedure TAHMLanguageCombo.SetLangID(Value: Word);
var i: Integer;
begin
  for i := Low(LangCodes) to High(LangCodes) do
  if Value = LangCodes[i] then
  begin
    ItemIndex := i;
    Exit;
  end;
  raise Exception.Create('Unknown language specifier');
end;

function TAHMLanguageCombo.GetLangIdAsString: string;
begin
  Result := IntToHex(LangID, 4);
end;

end.
