home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Delphi / eXpertDevelopmentKit / SOURCE / XDKSTEPS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-01-26  |  7.6 KB  |  260 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       eXpert Development Kit                          }
  4. {                                                       }
  5. {       Copyright (c) 1996,97 Sergey Orlik              }
  6. {       - product manager of Borland Russia             }
  7. {                                                       }
  8. {*******************************************************}
  9. unit XDKSteps;
  10. interface
  11. uses
  12.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  13.   StdCtrls, ExtCtrls, ComCtrls;
  14.  
  15. type
  16.   TxdkSteps = class;
  17.  
  18.   TxdkStepTab = class(TTabSheet)
  19.   private
  20.     FOnBack : TNotifyEvent;
  21.     FOnNext : TNotifyEvent;
  22.   public
  23.     constructor Create(AOwner: TComponent); override;
  24.     procedure Loaded; override;
  25.   published
  26.     property OnBack:TNotifyEvent read FOnBack write FOnBack;
  27.     property OnNext:TNotifyEvent read FOnNext write FOnNext;
  28.   end;
  29.  
  30.   TxdkSteps = class(TCustomPanel)
  31.   private
  32.     FStepPages   : TPageControl;
  33.     FBtnAbout    : TButton;
  34.     FBtnBack     : TButton;
  35.     FBtnNext     : TButton;
  36.     FBtnCancel   : TButton;
  37.     FOnAbout     : TNotifyEvent;
  38.     FOnFinish    : TNotifyEvent;
  39.     FOnCancel    : TNotifyEvent;
  40.     FFormCaption : string;
  41.     procedure ReboundChilds;
  42.   protected
  43.     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
  44.     procedure Resize; override;
  45.     procedure DoBack(Sender: TObject); virtual;
  46.     procedure DoNext(Sender: TObject); virtual;
  47.   public
  48.     constructor Create(AOwner: TComponent); override;
  49.     destructor Destroy; override;
  50.     procedure Loaded; override;
  51.     procedure DisableNext;
  52.     procedure EnableNext;
  53.     property StepPages:TPageControl read FStepPages;    
  54.   published
  55.     property BevelInner;
  56.     property BevelOuter;
  57.     property BevelWidth;
  58.     property BorderWidth;
  59.     property BorderStyle;
  60.     property Enabled;
  61.     property FullRepaint;
  62.     property Color;
  63.     property Ctl3D;
  64.     property Font;
  65.     property ParentColor;
  66.     property ParentCtl3D;
  67.     property ParentFont;
  68.     property ParentShowHint;
  69.     property PopupMenu;
  70.     property ShowHint;
  71.     property TabOrder;
  72.     property TabStop;
  73.     property Visible;
  74.     property OnAbout:TNotifyEvent read FOnAbout write FOnAbout;
  75.     property OnFinish:TNotifyEvent read FOnFinish write FOnFinish;
  76.     property OnCancel:TNotifyEvent read FOnCancel write FOnCancel;
  77.   end;
  78.  
  79. //================================================================================
  80. implementation
  81.  
  82. resourcestring
  83.   sNext = 'Next >';
  84.   sBack = '< Back';
  85.   sFinish = 'Finish';
  86.  
  87. //TxdkSteps
  88. constructor TxdkSteps.Create(AOwner: TComponent);
  89. begin
  90.   inherited Create(AOwner);
  91.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  92.     csOpaque, csDoubleClicks, csReplicatable];
  93.   Align:=alClient;
  94.   BevelOuter:=bvNone;
  95.   FullRepaint:=True;
  96.   FStepPages:=TPageControl.Create(Self);
  97.   FStepPages.Parent:=Self;
  98.   FStepPages.Align:=alTop;
  99.   FStepPages.TabPosition:=tpBottom;
  100.   FBtnAbout:=TButton.Create(Self);
  101.   FBtnAbout.Parent:=Self;
  102.   FBtnAbout.Caption:='About';
  103.   FBtnBack:=TButton.Create(Self);
  104.   FBtnBack.Parent:=Self;
  105.   FBtnBack.Caption:=sBack;
  106.   FBtnNext:=TButton.Create(Self);
  107.   FBtnNext.Parent:=Self;
  108.   FBtnNext.Caption:=sNext;
  109.   FBtnNext.Default:=true;
  110.   FBtnCancel:=TButton.Create(Self);
  111.   FBtnCancel.Parent:=Self;
  112.   FBtnCancel.Caption:='Cancel';
  113. end;
  114.  
  115. destructor TxdkSteps.Destroy;
  116. begin
  117.   FBtnNext.Caption:=sNext;
  118.   if not (csDesigning in ComponentState) then
  119.     GetParentForm(Self).Caption:=FFormCaption;
  120.   inherited Destroy;
  121. end;
  122.  
  123. procedure TxdkSteps.GetChildren(Proc: TGetChildProc; Root: TComponent);
  124. var
  125.   I: Integer;
  126. begin
  127.   for I := 0 to FStepPages.PageCount - 1 do Proc(TComponent(FStepPages.Pages[I]));
  128.   inherited GetChildren(Proc,Root);
  129. end;
  130.  
  131. procedure TxdkSteps.Loaded;
  132. begin
  133.   inherited Loaded;
  134.   ReboundChilds;
  135.   if not (csDesigning in ComponentState) then
  136.     FFormCaption:=GetParentForm(Self).Caption;
  137.   if (Assigned(FStepPages)) and (FStepPages.PageCount>0) then
  138.   begin
  139.     FStepPages.ActivePage:=FStepPages.Pages[0];
  140.     if not (csDesigning in ComponentState) then
  141.       GetParentForm(Self).Caption:=FFormCaption+Format(' : Step 1 of %d',[FStepPages.PageCount]);
  142.   end;
  143.   FBtnBack.Visible:=False;
  144.   if Assigned(FOnAbout) then
  145.     FBtnAbout.OnClick:=FOnAbout;
  146.   if Assigned(FOnCancel) then
  147.     FBtnCancel.OnClick:=FOnCancel;
  148.   FBtnBack.OnClick:=DoBack;
  149.   FBtnNext.OnClick:=DoNext;
  150.   if not (Assigned(FStepPages) and (FStepPages.PageCount>1)) then
  151.   begin
  152.     FBtnNext.Caption:=sFinish;
  153.     FBtnNext.Font.Style:=FBtnNext.Font.Style+[fsBold];
  154.   end;
  155. end;
  156.  
  157. procedure TxdkSteps.Resize;
  158. begin
  159.   if Parent.ClientHeight<160 then
  160.     Parent.ClientHeight:=160;
  161.   if Parent.ClientWidth<360 then
  162.     Parent.ClientWidth:=360;
  163.   inherited Resize;
  164.   ReboundChilds;
  165. end;
  166.  
  167. procedure TxdkSteps.ReboundChilds;
  168. begin
  169.   if Height<160 then
  170.     Height:=160;
  171.   if Width<360 then
  172.     Width:=360;
  173.   FStepPages.Height:=Height-33;
  174.   FBtnAbout.Top:=Height-29;
  175.   FBtnAbout.Left:=4;
  176.   FBtnBack.Top:=Height-29;
  177.   FBtnBack.Left:=Width-239;
  178.   FBtnNext.Top:=Height-29;
  179.   FBtnNext.Left:=Width-164;
  180.   FBtnCancel.Top:=Height-29;
  181.   FBtnCancel.Left:=Width-79;
  182. end;
  183.  
  184. procedure TxdkSteps.DoBack(Sender: TObject);
  185. begin
  186.   if FStepPages.ActivePage.PageIndex=0 then
  187.     Exit;
  188.   if Assigned(TxdkStepTab(FStepPages.ActivePage).OnBack) then
  189.     TxdkStepTab(FStepPages.ActivePage).OnBack(Sender);
  190.   if FStepPages.ActivePage.PageIndex=1 then
  191.     FBtnBack.Visible:=False;
  192.   if FStepPages.ActivePage.PageIndex=FStepPages.PageCount-1 then
  193.   begin
  194.     FBtnNext.Caption:=sNext;
  195.     FBtnNext.Font.Style:=FBtnNext.Font.Style-[fsBold];
  196.   end;
  197.   FStepPages.ActivePage:=FStepPages.Pages[FStepPages.ActivePage.PageIndex-1];
  198.   if not (csDesigning in ComponentState) then
  199.     GetParentForm(Self).Caption:=FFormCaption+
  200.     Format(' : Step %d of %d',[FStepPages.ActivePage.PageIndex+1,FStepPages.PageCount]);
  201. end;
  202.  
  203. procedure TxdkSteps.DoNext(Sender: TObject);
  204. begin
  205.   if ((FStepPages.PageCount>0)
  206.        and (FStepPages.ActivePage.PageIndex=FStepPages.PageCount-1))
  207.      or (FStepPages.PageCount=0)
  208.     then
  209.   begin
  210.     if Assigned(Self.OnFinish) then
  211.       OnFinish(Sender);
  212.     Exit;
  213.   end;
  214.   if Assigned(TxdkStepTab(FStepPages.ActivePage).OnNext) then
  215.     TxdkStepTab(FStepPages.ActivePage).OnNext(Sender);
  216.   if FStepPages.ActivePage.PageIndex=0 then
  217.     FBtnBack.Visible:=True;
  218.   FStepPages.ActivePage:=FStepPages.Pages[FStepPages.ActivePage.PageIndex+1];
  219.   if FStepPages.ActivePage.PageIndex=FStepPages.PageCount-1 then
  220.   begin
  221.     FBtnNext.Caption:=sFinish;
  222.     FBtnNext.Font.Style:=FBtnNext.Font.Style+[fsBold];
  223.   end;
  224.   if not (csDesigning in ComponentState) then
  225.     GetParentForm(Self).Caption:=FFormCaption+
  226.     Format(' : Step %d of %d',[FStepPages.ActivePage.PageIndex+1,FStepPages.PageCount]);
  227. end;
  228.  
  229. procedure TxdkSteps.DisableNext;
  230. begin
  231.   FBtnNext.Enabled:=false;
  232. end;
  233.  
  234. procedure TxdkSteps.EnableNext;
  235. begin
  236.   FBtnNext.Enabled:=true;
  237. end;
  238.  
  239. //================================================================================
  240. // TxdkStepTab
  241.  
  242. constructor TxdkStepTab.Create(AOwner: TComponent);
  243. begin
  244.   inherited Create(AOwner);
  245.   if not (csDesigning in ComponentState) then
  246.     TabVisible := False
  247.   else
  248.     TabVisible := True;
  249. end;
  250.  
  251. procedure TxdkStepTab.Loaded;
  252. begin
  253.   inherited Loaded;
  254.   PageControl := TxdkSteps(Parent).FStepPages;//FSteps.FStepPages;
  255. end;
  256.  
  257. //================================================================================
  258.  
  259. end.
  260.