unit uMenuDef;

{==========================================================}
{                                                          }
{  unit uMenuDef                       22/04/2004          }
{                                      Verze 1.0           }
{                                                          }
{  Skelet aplikace s terminalem PC                         }
{                                                          }
{  Definice stromu komponent aplikace                      }
{                                                          }
{                                                          }
{  (C)2004, 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             }

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

procedure CreateAppPages;

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

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


implementation

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

const

  cidPageCtrl          = 1;    { Hlavni komponenta TPageControl         }

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

  cidOtherPage         = 200;  { Dalsi stranka                          }
  cidOtherPageTitle    = 201;  { Titulek na dalsi strance               }
  cidOtherPageNavig    = 202;  { Navigator na dalsi strance             }


{-----------------------------------------------------------------------}
{ 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;

  end;

{-----------------------------------------------------------------------}
{ Vlastni tridy nastaveni komponent                                     }
{-----------------------------------------------------------------------}

const

  ccStaticTextXXX  = ccStaticText + 16;
  ccEditXXX        = ccEdit       + 16;


{-----------------------------------------------------------------------}
{ Vlastni konfiguracni procedura pro vytvarene komponenty               }
{-----------------------------------------------------------------------}

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

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

  { Vyber podle tridy }
  case AClass and ccGeneralMask of

    ccStaticText: { Komponenta TStaticText }
    begin
      { Vyber podle podtridy }
      case AClass of

        ccStaticTextXXX:
        begin
          { ... }
        end;

      end;
    end;

    ccEdit: { Komponenta TEdit }
    begin
      { Vyber podle podtridy }
      case AClass of

        ccEditXXX:
        begin
          { ... }
        end;

      end;
    end;

    { ... }

  end;
end;


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

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

procedure MainPageNotify( var N: TNotification ); far;
begin
{ case N.Control^.Id of

    cidXXX:
    begin
      case N.Code of
        nmXXX:
        begin
          ClearNotification( N );
        end;

        nmYYY:
        begin
          ClearNotification( N );
        end;
      end;
    end;

    cidYYY:
    begin
      case N.Code of
        nmXXX:
        begin
          ClearNotification( N );
        end;

        nmYYY:
        begin
          ClearNotification( N );
        end;
      end;
    end;

  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;
begin
  Page := Tree.PageCtrl^.NewPage( cidMainPage );
  Page^.Customize( ccPage );
  Page^.AfterNotify := MainPageNotify;
  Page^.AfterPaint := PagePaintFrame;

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

    { Navigator }
    R.Assign( 1, 460, 639, 479 );
    Navig := New( PNavigator, Init( R, Tree.PageCtrl,
{      PC zatim nema setup, proto je nasledujici radka zakomentovana }
{      NewTextPanel( 'Setup', Ord('S'), -4, npfDivider or npfCall, cidTermSetupPage,}
      NewTextPanel( 'Other', Ord('O'), -4, npfDivider or npfGoto, cidOtherPage,
      nil)
    ));
    Navig^.Customize( ccNavigator );
    Page^.Insert( Navig );

    { Zde bude incializace dalsich komponent na strance }

    { ... }

  end;

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


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

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

procedure OtherPageNotify( var N: TNotification ); far;
begin
{ case N.Control^.Id of

    cidXXX:
    begin
      case N.Code of
        nmXXX:
        begin
          ClearNotification( N );
        end;

        nmYYY:
        begin
          ClearNotification( N );
        end;
      end;
    end;

    cidYYY:
    begin
      case N.Code of
        nmXXX:
        begin
          ClearNotification( N );
        end;

        nmYYY:
        begin
          ClearNotification( N );
        end;
      end;
    end;

  end;}
end;


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

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

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

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

    { Zde bude incializace dalsich komponent na strance }

    { ... }
  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, 640, 480 );
  Tree.PageCtrl := New( PPageControl, Init( R ) );
  Tree.PageCtrl^.Customize( ccPageControl );
  Tree.PageCtrl^.Id := cidPageCtrl;

  { Vytvoreni jednotlivych stranek aplikace }
  CreateMainPage;
  CreateOtherPage;

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

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


end.