unit global_resources;
{
[global_resources] [1.0]
Delphi 2005
December 2005

LICENSE

The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
"http://www.mozilla.org/MPL/"

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is "[global_resources.pas]".

The Initial Developer of the Original Code is Martin Holmes (Victoria,
BC, Canada, "http://www.mholmes.com/"). Copyright (C) 2005 Martin Holmes
and the University of Victoria Computing and Media Centre. The code was
co-developed for university and personal projects, and rights are shared
by Martin Holmes and the University of Victoria. All Rights Reserved.
}
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TntForms, ImgList, ActnList, TntActnList, TntStdCtrls, AppEvnts,
  Clipbrd;

type
  TufrmResources = class(TTntForm)
    ilGlobal16Enabled: TImageList;
    ualGlobals: TTntActionList;
    aeGloibals: TApplicationEvents;
    aSelectAll: TTntAction;
    aDelete: TTntAction;
    aPaste: TTntAction;
    aCopy: TTntAction;
    aCut: TTntAction;
    aUndo: TTntAction;
    procedure aeGloibalsIdle(Sender: TObject; var Done: Boolean);
    procedure aSelectAllExecute(Sender: TObject);
    procedure aDeleteExecute(Sender: TObject);
    procedure aPasteExecute(Sender: TObject);
    procedure aCopyExecute(Sender: TObject);
    procedure aCutExecute(Sender: TObject);
    procedure aUndoExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ufrmResources: TufrmResources;

implementation

{$R *.dfm}

procedure TufrmResources.aUndoExecute(Sender: TObject);
begin
  if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).Perform(EM_UNDO, 0, 0);
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).Perform(EM_UNDO, 0, 0);
end;

procedure TufrmResources.aCutExecute(Sender: TObject);
begin
  if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).CutToClipboard;
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).CutToClipboard;
end;

procedure TufrmResources.aCopyExecute(Sender: TObject);
begin
   if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).CopyToClipboard;
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).CopyToClipboard;
end;

procedure TufrmResources.aPasteExecute(Sender: TObject);
begin
   if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).PasteFromClipboard;
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).PasteFromClipboard;
end;

procedure TufrmResources.aDeleteExecute(Sender: TObject);
begin
  if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).SelText := '';
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).SelText := '';
end;

procedure TufrmResources.aSelectAllExecute(Sender: TObject);
begin
  if Screen.ActiveForm.ActiveControl is TTntEdit then
    (Screen.ActiveForm.ActiveControl as TTntEdit).SelectAll;
  if Screen.ActiveForm.ActiveControl is TTntMemo then
    (Screen.ActiveForm.ActiveControl as TTntMemo).SelectAll;
end;

procedure TufrmResources.aeGloibalsIdle(Sender: TObject; var Done: Boolean);
var
IsEdit: Boolean;
HasSelection: Boolean;
HasText: Boolean;
boolCanUndo: Boolean;

begin
  IsEdit := ((Screen.ActiveForm.ActiveControl is TTntEdit) or
            (Screen.ActiveForm.ActiveControl is TTntMemo));
  if IsEdit then
    begin
      if (Screen.ActiveForm.ActiveControl is TTntEdit) then
        with (Screen.ActiveForm.ActiveControl as TTntEdit) do
          begin
            HasSelection := (SelLength > 0);
            boolCanUndo := CanUndo;
            HasText := (Length(Text) > 0);
          end;
      if (Screen.ActiveForm.ActiveControl is TTntMemo) then
        with (Screen.ActiveForm.ActiveControl as TTntMemo) do
          begin
            HasSelection := (SelLength > 0);
            boolCanUndo := CanUndo;
            HasText := (Length(Text) > 0);
          end;
      aUndo.Enabled := boolCanUndo;
      aCut.Enabled := HasSelection;
      aCopy.Enabled := HasSelection;
      aPaste.Enabled := Clipboard.HasFormat(CF_TEXT);
      aDelete.Enabled := HasSelection;
      aSelectAll.Enabled := HasText;
    end
  else
    begin
      aUndo.Enabled := False;
      aCut.Enabled := False;
      aCopy.Enabled := False;
      aPaste.Enabled := False;
      aDelete.Enabled := False;
      aSelectAll.Enabled := False; 
    end;
end;

end.
