www.pudn.com > d4psp31.zip > fmPower.pas, change:1998-08-31,size:9526b


(*====================================================================* 
 | Unit fmPower - fmPower.pas                                       | 
 |                                                                    | 
 | Abstract base class for Power Sequencer Plus v3.0 active track     | 
 | forms.                                                             | 
 |                                                                    | 
 | The main form maintains a list of active forms and sends them      | 
 | notification messages.                                             | 
 |                                                                    | 
 | Active forms have an 'Animate' button, which turns on/off their    | 
 | 'Active' property.                                                 | 
 |                                                                    | 
 | The Notify method is abstract and must be overriden.               | 
 |                                                                    | 
 | Copyright (c) Colin Wilson 1996.  All rights reserved              | 
 |                                                                    | 
 | Version  Date      By    Description                               | 
 | -------  --------  ----  ------------------------------------------| 
 | 1.0       02/11/96 CPWW  Original                                  | 
 | 1.1       04/07/97 CPWW 
 *--------------------------------------------------------------------*) 
unit fmPower; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
  Buttons, ExtCtrls; 
 
type 
  TActiveFormNotify = (        // Notification message types received from parent. 
    ntFullUpdate,              // Redraw entire form. 
    ntPositionUpdate           // Update form based on new position. 
  ); 
 
  TPowerForm = class(TForm) 
    bvlTopMargin: TBevel;      // 'Top Margin' bevel. 
    btnAnimate: TSpeedButton;  // 'Animate' button 
 
    procedure FormClose(Sender: TObject; var Action: TCloseAction); 
    procedure FormShow(Sender: TObject); 
    procedure btnAnimateClick(Sender: TObject); 
    procedure FormResize(Sender: TObject); 
    procedure FormKeyDown(Sender: TObject; var Key: Word; 
      Shift: TShiftState); 
  private 
    fActive : boolean; 
    procedure SetActive (value : boolean); virtual; 
    procedure AdjustHeader; 
    { Private declarations } 
  protected 
  public 
    constructor Create (Owner : TComponent); override; 
    procedure CopyToClipboard; virtual; 
    procedure CutToClipboard; virtual; 
    procedure DeleteToClipboard; virtual; 
    procedure PasteFromClipboard; virtual; 
    procedure Notify (tp : TActiveFormNotify); virtual; abstract; 
    property Active : boolean read fActive write SetActive; 
    procedure SetCaption (formName : string; trackNo : Integer); 
    { Public declarations } 
  end; 
 
var 
  PowerForm: TPowerForm; 
 
implementation 
 
uses Globals, ClipBrd, fmMainForm; 
 
{$R *.DFM} 
 
(*--------------------------------------------------------------------* 
 | constructor TActiveForm.Create                                     | 
 |                                                                    | 
 | Create the form. Set the initial 'Active' value.                   | 
 |                                                                    | 
 | Parameters                                                         | 
 |   Owner : TComponent           The form's owner - the main form    | 
 *--------------------------------------------------------------------*) 
constructor TPowerForm.Create (Owner : TComponent); 
begin 
  inherited Create (Owner); 
  Active := AutoSynchronize; 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.SetCaption                                   | 
 |                                                                    | 
 | Sets the form's caption, displaying the current track info.        | 
 |                                                                    | 
 | Parameters                                                         | 
 |   formName : string         The form type name - eg. Note Editor   | 
 |   trackNo : Integer         The track number to display.           | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.SetCaption (formName : string; trackNo : Integer); 
var st : string; 
begin 
  if trackNo = 0 then 
    st := 'Control - ' 
  else 
    if trackNo < MainForm.MidiData.NoTracks then 
      st := MainForm.MidiData.Tracks [trackNo].TrackName + ' - '; 
 
  st := st + Format ('Track %d - %s', [trackNo, formName]); 
  Caption := st 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.AdjustHeader                                 | 
 |                                                                    | 
 | Adjust the form's heade to reposition the 'animate' button at the  | 
 | far right of the screen.                                           | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.AdjustHeader; 
begin 
  btnAnimate.Left := ClientWidth - btnAnimate.Width - 2; 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.FormClose                                    | 
 |                                                                    | 
 | OnClose method for active forms.  Remove the form from the Main    | 
 | Form's active form list, and set the (modeless) form to auto-free. | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
  MainForm.DeleteActiveForm (self); 
  Action := caFree 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.FormShow                                     | 
 |                                                                    | 
 | OnShow method for active form.  Add the form to the Main Form's    | 
 | active form list.                                                  | 
 |                                                                    | 
 | Parameters                                                         | 
 |   Sender : TObject         The main form.                          | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.FormShow(Sender: TObject); 
begin 
                                       // Set 'animate' button state 
  btnAnimate.Down := AutoSynchronize; 
  AdjustHeader;                        // Position the 'animate' button 
  MainForm.AddActiveForm (self)        // Add to main form's active list 
end; 
 
(*--------------------------------------------------------------------* 
 | TActiveForm.SetActive                                              | 
 |                                                                    | 
 | Helper function for 'Active' property.                             | 
 |                                                                    | 
 | Parameters                                                         | 
 |   value : boolean            The new value to set                  | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.SetActive (value : boolean); 
begin 
  if value <> fActive then 
  begin 
    fActive := value; 
    if fActive then              // Redraw the screen to relect the current 
      Notify (ntPositionUpdate); // position 
  end 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.btnAnimateClick                              | 
 |                                                                    | 
 | Update the 'active' property to relect the (new) state of the      | 
 | 'animate' button.                                                  | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.btnAnimateClick(Sender: TObject); 
begin 
  Active := btnAnimate.Down 
end; 
 
(*--------------------------------------------------------------------* 
 | procedure TActiveForm.FormResize                                   | 
 |                                                                    | 
 | Adjust the header to update the position of the 'animate' button   | 
 | when the form resizes                                              | 
 *--------------------------------------------------------------------*) 
procedure TPowerForm.FormResize(Sender: TObject); 
begin 
 AdjustHeader; 
end; 
 
procedure TPowerForm.FormKeyDown(Sender: TObject; var Key: Word; 
  Shift: TShiftState); 
begin 
  MainForm.FormKeyDown (sender, key, shift); 
end; 
 
procedure TPowerForm.CopyToClipboard; 
begin 
  with MainForm, MidiData.Tracks [CurrentTrackNo] do 
    CopyToClipboard (selStartPos, selEndPos); 
end; 
 
procedure TPowerForm.CutToClipboard; 
begin 
  with MainForm, MidiData.Tracks [CurrentTrackNo] do 
    CutToClipboard (selStartPos, selEndPos); 
end; 
 
procedure TPowerForm.PasteFromClipboard; 
begin 
  with MainForm, MidiData.Tracks [CurrentTrackNo] do 
    PasteFromClipboard (CurrentPosition); 
end; 
 
procedure TPowerForm.DeleteToClipboard; 
begin 
  with MainForm, MidiData.Tracks [CurrentTrackNo] do 
    DeleteToClipboard (selStartPos, selEndPos); 
end; 
 
end.