unit uMenuDef;

{==========================================================}
{                                                          }
{  unit uMenuDef                       11/12/2003          }
{                                      Verze 1.2           }
{                                                          }
{  Dokumentovany priklad				   }
{                                                          }
{                                                          }
{                                                          }
{                                                          }
{  (C)2003, SofCon, Stresovicka 49, 160 00 Praha 6         }
{                                                          }
{                                                          }
{==========================================================}

interface

{$I SETS.INC}

uses
  Objects,    { Standardni knihovna             }
  IoDrv,      { Obecne I/O ovladace terminalu   }
  Bitmaps,    { Spravce bitmap                  }
  Fonts,      { Spravce fontu                   }
  Controls,   { Zakladni komponenty             }
  GrCtrls,    { Graficke komponenty             }
  T11Setup;   { Setup pro terminal T11          }

{-------------------------
{ CreateAppPages
{--
{ Procedura pro vytvoreni vsech stranek aplikace
{--
}

procedure CreateAppPages;

{-------------------------
{ AppCustomizeProc
{--
{ Aplikacni konfiguracni procedura komponent
{--
}

procedure AppCustomizeProc( AControl: PControl; AClass: Word );


implementation

uses
  NumToStr;

{-----------------------------------------------------------------------}
{ Identifikatory komponent                                              }
{-----------------------------------------------------------------------}

const

  cidPageCtrl          = 1;    { Hlavni komponenta TPageControl         }

  cidMainPage          = 100;  { Hlavni stranka                         }
   cidMainPageTitle    = 101;  { Titulek hlavni stranky                 }
   cidMainPageNavig    = 102;  { Navigator na hlavni strance            }

  cidSecondPage         = 200;  { Dalsi stranka                          }
   cidSecondPageTitle   = 201;  { Titulek na dalsi strance               }
   cidSecondPageNavig   = 202;  { Navigator na dalsi strance             }

  cidThirdPage          = 300;
   cidTPlb              = 301;  { list-box }


{-----------------------------------------------------------------------}
{ Odkazy na instance komponent ve stromu aplikace                       }
{-----------------------------------------------------------------------}

var

  Tree :
  record
    PageCtrl : PPageControl;  { Instance hlavni komponenty TPageControl }

    MainPage : record         { Hlavni stranka                          }
      Title   : PStaticText;  { Titulek stranky                         }
      Navig   : PNavigator;   { Navigator stranky                       }
    end;

    OtherPage : record        { Dalsi stranka                           }
      Title   : PStaticText;  { Titulek stranky                         }
      Navig   : PNavigator;   { Navigator stranky                       }
    end;

    ThirdPage : record
      st1     : PStaticText;
      st2     : PStaticText;
    end;

  end;



{-------------------------
{ AppCustomizeProc
{--
{ Aplikacni konfiguracni procedura komponent
{--
}

procedure AppCustomizeProc( AControl: PControl; AClass: Word );
begin
end;

{-----------------------------------------------------------------------}
{ Pomocne procedury                                                        }
{-----------------------------------------------------------------------}



{-----------------------------------------------------------------------}
{ Hlavni stranka                                                        }
{-----------------------------------------------------------------------}

{-------------------------
{ MainPageNotify
{--
{ Obsluha oznameni komponent v hlavni strance
{--
}

procedure MainPageNotify( var N: TNotification ); far;
begin
end;

const
  pocitadlo :word = 0;

procedure PocitadloNotify( var N: TNotification ); far;
var s : string;
begin
  if N.Code = nmClick then
  begin
    inc( pocitadlo );
    str( pocitadlo, s );
    PStaticText( N.Control )^.SetText( 'Pocitadlo: '+s );
  end;
end;

{-------------------------
{ MainPagePaint
{--
{
{--
}

procedure PagePaintFrame( AControl: PControl; ACanvas: PCanvas ); far;
var
  R : TRect;
begin
  { Vykresleni okraje ve vnitrni casti stranky }
  AControl^.GetExtent( R );
  ACanvas^.Pen.Color := clBlack;
  ACanvas^.DrawRect( R.A.X + 1, R.A.Y + 21, R.B.X - 2, R.B.Y - 22 );
end;

{-------------------------
{ CreateMainPage
{--
{ Vytvoreni a inicializace hlavni stranky
{--
}

procedure CreateMainPage;
var
  Page : PPage;
  R    : TRect;
  st   : PStaticText;
  bt   : PButton;
begin
  Page := Tree.PageCtrl^.NewPage( cidMainPage );
  Page^.Customize( ccPage );
  Page^.AfterPaint := PagePaintFrame;

  with Tree.MainPage do
  begin
    { Titulek }
    R.Assign( 1, 1, 319, 20 );
    Title := New( PStaticText, Init( R, 'Main page' ) );
    Title^.Customize( ccStaticTextTitle );
    Page^.Insert( Title );

    { Navigator }
    R.Assign( 1, 220, 319, 239 );
    Navig := New( PNavigator, Init( R, Tree.PageCtrl,
      NewTextPanel( 'Setup', Ord('S'), -4, npfDivider or npfCall, cidTermSetupPage,
      NewTextPanel( 'Other', Ord('O'), -4, npfDivider or npfGoto, cidSecondPage,
      NewTextPanel( 'Third', Ord('T'), -4, npfDivider or npfGoto, cidThirdPage,
      nil)))
    ));
    Navig^.Customize( ccNavigator );
    Page^.Insert( Navig );

    R.Assign( 20, 30, 120, 50 );
    st := new( PStaticText, init( r, 'Pocitadlo: 0' ));
    st^.Customize( ccStaticText );
    st^.SetFlags( stfBorder, 0 );
    st^.AfterNotify := PocitadloNotify;
    Page^.Insert( st );

    R.Assign( 20, 190, 80, 210 );
    bt := new( PButton, init( r, 'Alt-X Exit', btmKeyDown, kbAltX ));
    bt^.Customize( ccButton );
    Page^.Insert( bt );

  end;

  Tree.PageCtrl^.Insert( Page );
end;


{-----------------------------------------------------------------------}
{ Dalsi stranka                                                         }
{-----------------------------------------------------------------------}

{-------------------------
{ OtherPageNotify
{--
{ Obsluha oznameni komponent v dalsi strance
{--
}

procedure OtherPageNotify( var N: TNotification ); far;
begin
end;


{-------------------------
{ CreateOtherPage
{--
{ Vytvoreni a inicializace dalsi stranky
{--
}

procedure CreateOtherPage;
var
  Page : PPage;
  R    : TRect;
  ed   : PEdit;
begin
  Page := Tree.PageCtrl^.NewPage( cidSecondPage );
  Page^.Customize( ccPage );
  Page^.AfterNotify := OtherPageNotify;
  Page^.AfterPaint := PagePaintFrame;

  with Tree.OtherPage do
  begin
    { Titulek }
    R.Assign( 1, 1, 319, 20 );
    Title := New( PStaticText, Init( R, 'Other page' ));
    Title^.Customize( ccStaticTextTitle );
    Page^.Insert( Title );

    { Navigator }
    R.Assign( 1, 220, 319, 239 );
    Navig := New( PNavigator, Init( R, Tree.PageCtrl,
      NewTextPanel( 'Main', Ord('M'), -4, npfDivider or npfGoto, cidMainPage,
      NewTextPanel( 'Third', Ord('T'), -4, npfDivider or npfGoto, cidThirdPage,
      nil))
    ));
    Navig^.Customize( ccNavigator );
    Page^.Insert( Navig );

    R.Assign( 20, 40, 120, 60 );
    ed := new( PEdit, Init( r, 30 ));
    ed^.Customize( ccEdit );
    Page^.Insert( ed );

    R.Move( 0, 30 );
    ed := new( PEdit, Init( r, 30 ));
    ed^.Customize( ccEdit );
    ed^.SetFlags( edfMarks or edfAlignRight, 0 );
    Page^.Insert( ed );

    R.Move( 0, 30 );
    ed := new( PEdit, Init( R, 30 ));
    ed^.Customize( ccEdit );
    ed^.SetFlags( edfMarks, 0 );
    ed^.SetPasswordChar( '*' );
    Page^.Insert( ed );


  end;

  Tree.PageCtrl^.Insert( Page );
end;


{-----------------------------------------------------------------------}
{ Dalsi stranka                                                         }
{-----------------------------------------------------------------------}

{-------------------------
{ ThirdPageNotify
{--
{ Obsluha oznameni komponent v dalsi strance
{--
}

const
  s : string = '';

procedure ThirdPageNotify( var N: TNotification ); far;
begin
  case N.Control^.Id of
    cidTPlb:
      begin
        case N.Code of
          nmGetData:
            begin
              case N.Index of
                 0: s := 'Destiny';
                 1: s := 'Trident';
                 2: s := 'Spear';
                 3: s := 'Sword';
                 4: s := 'Lance';
                 5: s := 'Cemetery';
                 6: s := 'Ghoul';
                 7: s := 'Undead';
                 8: s := 'Skeleton';
                 9: s := 'Vampire';
                10: s := 'Garlic';
                11: s := 'Axe';
                12: s := 'Cleric';
                13: s := 'Monk';
                14: s := 'Creatrix';
                15: s := 'Witch';
                16: s := 'Temple';
                17: s := 'Gate';
                18: s := 'Particle';
                19: s := 'Generation';
                20: s := 'Apostate';
                21: s := 'Neophyte';
                22: s := 'Sanctuary';
                23: s := 'Tomb';
                24: s := 'Statue';
              else
                s := 'Undefined';
              end;
              n.text := addr(S);
              ClearNotification( N );
            end;

          nmSelect:
            begin
              Tree.ThirdPage.st2^.SetText( 'Confirmed:  '+
                PListBox( N.Control )^.GetData(
                  PListBox( N.Control )^.Selected
                )^
              );
              ClearNotification( N );
            end; {varianty nmSelect}

          nmChange:
            begin
              Tree.ThirdPage.st1^.SetText( 'Selected:  '+
                PListBox( N.Control )^.GetData(
                  PListBox( N.Control )^.Selected
                )^
              );
              ClearNotification( N );
            end;
        end;
      end;
  end;
end;


{-------------------------
{ CreateThirdPage
{--
{ Vytvoreni a inicializace dalsi stranky
{--
}

procedure CreateThirdPage;
var
  Page : PPage;
  R    : TRect;
  ed   : PEdit;
  st   : PStaticText;
  nav  : PNavigator;
  lb   : PListBox;
  sb   : PScrollBar;
begin
  Page := Tree.PageCtrl^.NewPage( cidThirdPage );
  Page^.Customize( ccPage );
  Page^.AfterNotify := ThirdPageNotify;
  Page^.AfterPaint := PagePaintFrame;

  { Titulek }
  R.Assign( 1, 1, 319, 20 );
  st := New( PStaticText, Init( R, 'Third page' ));
  st^.Customize( ccStaticTextTitle );
  Page^.Insert( st );

  { Navigator }
  R.Assign( 1, 220, 319, 239 );
  Nav := New( PNavigator, Init( R, Tree.PageCtrl,
    NewTextPanel( 'Main', Ord('M'), -4, npfDivider or npfGoto, cidMainPage,
    NewTextPanel( 'Second', Ord('S'), -4, npfDivider or npfGoto, cidSecondPage,
    nil)
  )));
  Nav^.Customize( ccNavigator );
  Page^.Insert( Nav );

{  R.Assign( 20, 131, 220, 146 );}
  R.Assign( 221, 30, 236, 130 );
  sb := new( PScrollBar, init( R ));
  sb^.Customize( ccScrollBar );
  page^.insert(sb);

  R.Assign( 20, 30, 220, 130 );
  lb := new( PListBox, init( R, sb ));
  lb^.Id := cidTPlb;
  lb^.Customize( ccListBox );
  lb^.font := fidss13;
  lb^.SetColCount( 2 ); {2 sloupce }
  lb^.SetItemCount( 25 ); {5 polozek}
  lb^.SelectItem( 3 );
  lb^.SetFlags( lbfBorder or lbfHorzDiv or lbfVertDiv or lbfUseEnter, 0 );


  page^.Insert( lb );

  with Tree.ThirdPage do
  begin
    R.Assign( 20, 140, 180, 160 );
    st1 := new( PStaticText, init( R, '' ));
    st1^.Customize( ccStaticText );
    st1^.SetFlags( stfBorder, 0 );
    page^.Insert( st1 );

    R.Move( 0, 25 );
    st2 := new( PStaticText, init( R, '' ));
    st2^.Customize( ccStaticText );
    st2^.SetFlags( stfBorder, 0 );
    page^.Insert( st2 );

  end;

  Tree.PageCtrl^.Insert( Page );
end;






{-----------------------------------------------------------------------}
{ Pomocne rutiny                                                        }
{-----------------------------------------------------------------------}


{-------------------------
{ CreateAppPages
{--
{ Vytvoreni vsech stranek aplikace
{--
}

procedure CreateAppPages;
var
  R : TRect;
begin
  { Inicializace hlavni komponenty TPageControl }

  R.Assign( 0, 0, 320, 240 );
  Tree.PageCtrl := New( PPageControl, Init( R ) );
  Tree.PageCtrl^.Customize( ccPageControl );
  Tree.PageCtrl^.Id := cidPageCtrl;

  { Vytvoreni jednotlivych stranek aplikace }
  CreateMainPage;
  CreateOtherPage;
  CreateThirdPage;

  { Vytvoreni stranek setupu terminalu T11, knihovna T11Setup }
  CreateT11SetupPages( Tree.PageCtrl );

  { Nastaveni prvni zobrazene stranky po startu aplikace }
  Tree.PageCtrl^.GotoPage( cidMainPage );

  { Vlozeni komponenty TPageControl do aplikace }
  Application^.Insert( Tree.PageCtrl );
end;


end.