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            }

   cidBtShow           = 110;  { Tlacitko Show                          }
   cidBtHide           = 111;  { Tlacitko Hide                          }

   cidBtEnable         = 113;  { Tlacitko Enable                        }
   cidBtDisable        = 114;  { Tlacitko Disable                       }
   cidBtTlacitko       = 115;  { Tlacitko citajici pocet stisku         }

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


{-----------------------------------------------------------------------}
{ 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                       }
      Text    : PStaticText;  { Mizejici a zobrazujici se text          }
      Tlacitko: PButton;
    end;

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

  end;



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

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

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

{-------------------------
{ AfterPaintDisabled
{--
{ Skrtnuti komponenty = ukazuje, ze komponenta je disabled
{--
}

procedure AfterPaintDisabled( AControl: PControl; ACanvas: PCanvas ); far;
var
  R : TRect;
begin
  AControl^.GetExtent( R );
  ACanvas^.Pen.Color := clBlack;
  ACanvas^.Pen.Style := psDotted;
  ACanvas^.DrawLine( R.A.X + 3, R.A.Y + 3, R.B.X - 3, R.B.Y - 3 );
  ACanvas^.DrawLine( R.A.X - 3, R.B.Y - 3, R.B.X - 3, R.A.Y + 3 );
end;



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

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

procedure MainPageNotify( var N: TNotification ); far;
const
  pocet_stisku : word = 0;
var
  s : string;
begin
  case N.Control^.Id of
{ zobrazeni a skryti komponenty }
    cidBtShow:
      begin
        if N.Code = nmClick then
          Tree.MainPage.Text^.Show;
        ClearNotification( N );
      end;
    cidBtHide:
      begin
        if N.Code = nmClick then
          Tree.MainPage.Text^.Hide;
        ClearNotification( N );
      end;

{ povoleni a zakazani komponenty }
    cidBtTlacitko:
      begin
        case N.Code of
          nmClick:
            begin
              inc( pocet_stisku );
              str( pocet_stisku, s );
              PButton( N.Control )^.SetText('Tlacitko stisknuto ' + s + ' krat');
              ClearNotification( N );
            end;
          nmEnable:
            begin
              N.Control^.AfterPaint := nil;
              N.Control^.RePaint;
              ClearNotification( N );
            end;
          nmDisable:
            begin
              N.Control^.AfterPaint := AfterPaintDisabled;
              N.Control^.RePaint;
              ClearNotification( N );
            end;
        end;
      end;
    cidBtEnable:
      begin
        if N.Code = nmClick then
          Tree.MainPage.Tlacitko^.Enable;
        ClearNotification( N );
      end;
    cidBtDisable:
      begin
        if N.Code = nmClick then
          Tree.MainPage.Tlacitko^.Disable;
        ClearNotification( N );
      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;
  bt   : PButton;
begin
  Page := Tree.PageCtrl^.NewPage( cidMainPage );
  Page^.Customize( ccPage );
  Page^.AfterPaint := PagePaintFrame;
  Page^.AfterNotify := MainPageNotify;

  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, cidOtherPage,
      nil))
    ));
    Navig^.Customize( ccNavigator );
    Page^.Insert( Navig );

{ metody show a hide }
    R.Assign( 3, 23, 83, 43 );
    bt := new( PButton, init( R, 'Show', btmNotify, 0 ));
    bt^.Id := cidBtShow;
    bt^.customize( ccButton );
    Page^.Insert( bt );

    R.Move( 0, 25 );
    bt := new( PButton, init( R, 'Hide', btmNotify, 0 ));
    bt^.Id := cidBtHide;
    bt^.Customize( ccButton );
    Page^.Insert( bt );

    R.Assign( 90, 30, 300, 56 );
    Text := new( PStaticText, Init( R, 'Mizejici a objevujici se text' ));
    Text^.Customize( ccStaticText );
    Text^.SetFlags( stfBorder, 0 );
    Text^.SetFont( fidSS20 );
    Text^.TextFlags := Text^.TextFlags or tfCenterX;
    Page^.Insert( Text );

{ metody enable a disable }
    R.Assign( 3, 83, 83, 103 );
    bt := new( PButton, init( R, 'Enable', btmNotify, 0 ));
    bt^.Id := cidBtEnable;
    bt^.Customize( ccButton );
    Page^.Insert( bt );

    R.Move( 0, 25 );
    bt := new( PButton, init( R, 'Disable', btmNotify, 0 ));
    bt^.Id := cidBtDisable;
    bt^.Customize( ccButton );
    Page^.Insert( bt );

    R.Assign( 90, 83, 230, 128 );
    Tlacitko := new( PButton, init( R, 'Tlacitko stisknuto 0 krat', btmNotify, 0 ));
    Tlacitko^.Id := cidBtTlacitko;
    Tlacitko^.Customize( ccButton );
    Page^.Insert( Tlacitko );

  end;

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


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

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

procedure OtherPageNotify( var N: TNotification ); far;
begin
  if N.Control^.Id = cidOPst then
  begin
    case N.Code of
      nmEnter,nmExit:
        begin
          N.Control^.Repaint;
          ClearNotification( N );
        end;
    end;
  end;
end;

procedure OPstAfterPaint( AControl: PControl; ACanvas: PCanvas ); far;
var
  R : TRect;
begin
  if ((AControl^.State and sfFocused) <> 0) then
  begin
    AControl^.GetExtent( R );
    ACanvas^.Pen.Color := clBlack;
    ACanvas^.Pen.Style := psDotted;
    ACanvas^.DrawRect( R.A.X+2, R.A.Y+2, R.B.X-3, R.B.Y-3 );
  end;
end;

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

procedure CreateOtherPage;
var
  Page : PPage;
  R    : TRect;
  bt   : PButton;
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, 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,
      nil)
    ));
    Navig^.Customize( ccNavigator );
    Page^.Insert( Navig );

    R.Assign( 30, 50, 170, 70 );
    st1 := new( PStaticText, Init( R, 'AAAaaaAAA' ));
    st1^.Id := cidOPst;
    st1^.Customize( ccStaticText );
    st1^.SetFlags( stfBorder, 0 );
    st1^.TextFlags := tfCenterX or tfCenterY;
    st1^.SetOptions( ofSelectable or ofTopSelect or ofShowFocus, 0 );
    st1^.AfterPaint := OPstAfterPaint;
    Page^.Insert( st1 );

    R.Assign( 130, 30, 150, 170 );
    st2 := new( PStaticText, Init( R, 'B'#13'b'#13'B' ));
    st2^.Id := cidOPst;
    st2^.Customize( ccStaticText );
    st2^.SetFlags( stfBorder, 0 );
    st2^.TextFlags := tfCenterX or tfCenterY or tfMultiLine;
    st2^.SetOptions( ofSelectable or ofTopSelect, 0 );
    st2^.AfterPaint := OPstAfterPaint;
    Page^.Insert( st2 );

    R.Assign( 30, 130, 170, 150 );
    st3 := new( PStaticText, Init( R, 'CCCcccCCC' ));
    st3^.Id := cidOPst;
    st3^.Customize( ccStaticText );
    st3^.SetFlags( stfBorder, 0 );
    st3^.TextFlags := tfCenterX or tfCenterY;
    st3^.SetOptions( ofSelectable or ofTopSelect, 0 );
    st3^.AfterPaint := OPstAfterPaint;
    Page^.Insert( st3 );

    R.Assign( 50, 30, 70, 170 );
    st4 := new( PStaticText, Init( R, 'D'#13'd'#13'D' ));
    st4^.Id := cidOPst;
    st4^.Customize( ccStaticText );
    st4^.SetFlags( stfBorder, 0 );
    st4^.TextFlags := tfCenterX or tfCenterY or tfMultiLine;
    st4^.SetOptions( ofSelectable or ofTopSelect, 0 );
    st4^.AfterPaint := OPstAfterPaint;
    Page^.Insert( st4 );

    R.Assign( 200, 50, 300, 70 );
    bt := new( PButton, Init( R, '+ofShowFocus', 0, 0 ));
    bt^.Customize( ccButton );
    bt^.SetOptions( ofShowFocus or ofSelectable, 0 );
    page^.Insert( bt );

    R.Move( 0, 30 );
    bt := new( PButton, Init( R, '-ofShowFocus', 0, 0 ));
    bt^.Customize( ccButton );
    bt^.SetOptions( ofSelectable, ofShowFocus );
    page^.Insert( bt );

  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;

  { 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.