(*
*******************************************************************************
*         Copyright (C) SofCon 2003 All Rights Reserved                       *
*******************************************************************************
*
*    project:     Vizualizacni knihovny pro jednotku KIT
*
*
*    title:       T10Cus
*
*******************************************************************************
*
*    description: Konfiguracni procedura pro komponenty zobrazovane
*                 na terminalu Term10
*
*    version:     0.01
*
*     (vyse uvedena verze je pouze verze teto knihovny, ktera
*      je soucasti baliku LIBV, jehoz verze je uvedena v knihovne
*      Iodrv.pas)
*
*    language:    Borland Pascal
*
*    author:      Cernin
*    history:     date        sign   remark
*                 06/09/04    bin     prvni vydani
*
*****************************************************************************
*)

unit T10Cus;

interface

  function T10DefaultKeyMapper( KeyCode: Word ): Word;

implementation

{[ +default, -color, +showfocus, -flickSafe ]}

uses
  defCus,
  osfCus,

  Objects,
  IoDrv,
  Controls,
  GrCtrls,
  Bitmaps;


{-------------------------------
{ T10DefaultKeyMapper
{---
{ Implicitni mapovaci funkce kodu klaves kbXXX na vkXXX
{---
}

function T10DefaultKeyMapper( KeyCode: Word ): Word;
var
  Result : Word;
begin
  case KeyCode of
    kbEnter      : Result := vkEnter;
    kbEsc        : Result := vkEsc;
    kbShiftLeft  : Result := vkNext;
    kbShiftRight : Result := vkPrev;
    kbLeft       : Result := vkLeft;
    kbRight      : Result := vkRight;
    kbUp         : Result := vkUp;
    kbDown       : Result := vkDown;
    kbInsert     : Result := vkInsert;
    kbDelete     : Result := vkDelete;
    kbBackSpace  : Result := vkBackSpace;
    kbHome       : Result := vkHome;
    kbEnd        : Result := vkEnd;
    kbPageUp     : Result := vkPageUp;
    kbPageDown   : Result := vkPageDown;
    kbF1         : Result := vkHelp;
    kbShiftDown  : Result := vkNextWindow;
    kbShiftUp    : Result := vkPrevWindow;
  {$ifdef DOS}
    kbAltX       : Result := vkAppExit;
  {$endif}
  else
    Result := 0;
  end;

  T10DefaultKeyMapper := Result;
end;


function T10MessageBoxFunc( const ABounds: TRect;
  const ATitle, AText: string; AFlags: Word ): PCustomDialog; far;
var
  Dlg  : PDialog;
  Text : PStaticText;
  R    : TRect;
begin
  Dlg := New( PDialog, Init( ABounds, ATitle ) );
  Dlg^.Customize( ccDialog{MsgBox} );

  Dlg^.GetExtent( R );

  Inc( R.A.Y, 16 );
  Dec( R.B.Y, 4 );
  Inc( R.A.X, 4 );
  Dec( R.B.X, 4 );

  Text := New( PStaticText, Init( R, AText ) );
  Text^.Customize( ccStaticText{MsgBox} );
  Text^.TextFlags := tfLeft or tfTop or tfMultiline;

  Dlg^.Insert( Text );

  T10MessageBoxFunc := Dlg;
end;


{-------------------------------
{ T10CustomizeProc
{---
{ Konfiguracni procedura pro vsechny komponenty definovane
{ v jednotka VMenu a GrMenu. Procedura konfiguruje komponenty
{ tak, aby byly vhodne zobrazeny a reagovaly spravne na
{ vstupni udalosti terminalu Term10 }
{---
{ AControl   Odkaz na instanci komponenty
{ AClass     Kod tridy konfigurace
{---
{ AClass musi odpovidat tride komponenty, jinak
{ volani funkce muze zpusobit nepredvidatelne nasledky.
}

procedure T10CustomizeProc( AControl: PControl; AClass: Word ); far;
{const
  CStaticTextTitle : string[4]  = #$00#$0F#$0F#$0F;
}
begin
  case AClass and ccGeneralMask of

  {----------------- TWindow }
    ccWindow:
    begin
      with PWindow( AControl )^ do
      begin
        KeyMapper := FocusUDKeyMapper;
      end;
    end;

  {----------------- TFrame }
    ccFrame:
    begin
      with PFrame( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TDialog }
    ccDialog:
    begin
      with PDialog( AControl )^ do
      begin
        KeyMapper := FocusUDKeyMapper;
      end;
    end;

  {----------------- TPageControl }
    ccPageControl:
    begin
      with PPageControl( AControl )^ do
      begin
        KeyMapper := WindowLRKeyMapper;
      end;
    end;

  {----------------- TPage }
    ccPage:
    begin
      with PPage( AControl )^ do
      begin
        KeyMapper := FocusUDKeyMapper;
      end;
    end;

  {----------------- TApplication }
    ccApplication:
    begin
      with PApplication( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
        MessageBoxFunc := T10MessageBoxFunc;
      end;
    end;


  {----------------- TButton }
    ccButton:
    begin
      with PButton( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TEdit }
    ccEdit:
    begin
      with PEdit( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TListBox }
    ccListBox:
    begin
      with PListBox( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TListView }
    ccListView:
    begin
      with PListView( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;


  {----------------- TListEdit }
    ccListEdit:
    begin
      with PListEdit( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TNavigator }
    ccNavigator:
    begin
      with PNavigator( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TProgressBar }
    ccProgressBar:
    begin
      with PProgressBar( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TScrollBar }
    ccScrollBar:
    begin
      with PScrollBar( AControl )^ do
      begin
        SetFlags( 0, sbfButtons );
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TTrackBar }
    ccTrackBar:
    begin
      with PTrackBar( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TUpDown }
    ccUpDown:
    begin
      with PUpDown( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TStaticText }
    ccStaticText:
    begin
      with PStaticText( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TPaintBox }
    ccPaintBox:
    begin
      with PPaintBox( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TImage }
    ccImage:
    begin
      with PImage( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TMenuOverlay }
    ccMenuOverlay:
    begin
      with PMenuOverlay( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;

  {----------------- TMenuOverlay }
    ccMenuPopup:
    begin
      with PMenuPopup( AControl )^ do
      begin
        KeyMapper := T10DefaultKeyMapper;
      end;
    end;


  else
    { Invalid class }
  end;
end;



begin
  RegisterCustomizeProc( T10CustomizeProc, cplDefault );
  RegisterStdBitmaps1BPP;
end.
