MG: added actnlist.pp

git-svn-id: trunk@1826 -
This commit is contained in:
lazarus 2002-08-06 20:05:19 +00:00
parent 3ee9c1fab9
commit 76d88bf210
3 changed files with 244 additions and 1 deletions

1
.gitattributes vendored
View File

@ -460,6 +460,7 @@ lcl/include/control.inc svneol=native#text/pascal
lcl/include/controlcanvas.inc svneol=native#text/pascal
lcl/include/controlsproc.inc svneol=native#text/pascal
lcl/include/customaction.inc svneol=native#text/pascal
lcl/include/customactionlist.inc svneol=native#text/pascal
lcl/include/customcheckbox.inc svneol=native#text/pascal
lcl/include/customcombobox.inc svneol=native#text/pascal
lcl/include/customcontrol.inc svneol=native#text/pascal

View File

@ -0,0 +1,196 @@
// included by actnlist.pas
{
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.LCL, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
{ TCustomActionList }
constructor TCustomActionList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FActions := TList.Create;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @ImageListChange;
FState := asNormal;
end;
destructor TCustomActionList.Destroy;
begin
FImageChangeLink.Free;
while FActions.Count > 0 do TContainedAction(FActions.Last).Free;
FActions.Free;
inherited Destroy;
end;
procedure TCustomActionList.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
I: Integer;
Action: TAction;
begin
for I := 0 to FActions.Count - 1 do
begin
Action := TAction(FActions.List^[I]);
if Action.Owner = Root then Proc(Action);
end;
end;
procedure TCustomActionList.SetChildOrder(Component: TComponent; Order: Integer);
begin
if FActions.IndexOf(Component) >= 0 then
(Component as TContainedAction).Index := Order;
end;
function TCustomActionList.GetAction(Index: Integer): TContainedAction;
begin
Result := TContainedAction(FActions[Index]);
end;
function TCustomActionList.GetActionCount: Integer;
begin
Result := FActions.Count;
end;
procedure TCustomActionList.SetAction(Index: Integer; Value: TContainedAction);
begin
TContainedAction(FActions[Index]).Assign(Value);
end;
procedure TCustomActionList.SetImages(Value: TCustomImageList);
begin
if Images <> nil then Images.UnRegisterChanges(FImageChangeLink);
FImages := Value;
if Images <> nil then
begin
Images.RegisterChanges(FImageChangeLink);
Images.FreeNotification(Self);
end;
end;
procedure TCustomActionList.ImageListChange(Sender: TObject);
begin
if Sender = Images then Change;
end;
procedure TCustomActionList.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if Operation = opRemove then
if AComponent = Images then
Images := nil
else if (AComponent is TContainedAction) then
RemoveAction(TContainedAction(AComponent));
end;
procedure TCustomActionList.AddAction(Action: TContainedAction);
begin
FActions.Add(Action);
Action.FActionList := Self;
Action.FreeNotification(Self);
end;
procedure TCustomActionList.RemoveAction(Action: TContainedAction);
begin
if FActions.Remove(Action) >= 0 then
Action.FActionList := nil;
end;
procedure TCustomActionList.Change;
var
I: Integer;
begin
if Assigned(FOnChange) then FOnChange(Self);
for I := 0 to FActions.Count - 1 do
TContainedAction(FActions.List^[I]).Change;
if csDesigning in ComponentState then
begin
if (Owner is TForm) and (TForm(Owner).Designer <> nil) then
TForm(Owner).Designer.Modified;
end;
end;
{ ToDo:
function TCustomActionList.IsShortCut(var Message: TWMKey): Boolean;
var
I: Integer;
ShortCut: TShortCut;
ShiftState: TShiftState;
Action: TCustomAction;
begin
ShiftState := KeyDataToShiftState(Message.KeyData);
ShortCut := Menus.ShortCut(Message.CharCode, ShiftState);
if ShortCut <> scNone then
for I := 0 to FActions.Count - 1 do
begin
Action := FActions.List[I];
if (TObject(Action) is TCustomAction) then
if (Action.ShortCut = ShortCut) or (Assigned(Action.FSecondaryShortCuts) and
(Action.SecondaryShortCuts.IndexOfShortCut(ShortCut) <> -1)) then
begin
Result := Action.HandleShortCut;
Exit;
end;
end;
Result := False;
end; }
function TCustomActionList.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := False;
if Assigned(FOnExecute) then FOnExecute(Action, Result);
end;
function TCustomActionList.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := False;
if Assigned(FOnUpdate) then FOnUpdate(Action, Result);
end;
procedure TCustomActionList.SetState(const Value: TActionListState);
var
I: Integer;
Action: TCustomAction;
begin
if FState <> Value then
begin
FState := Value;
if State = asSuspended then exit;
for I := 0 to FActions.Count - 1 do
begin
Action := TAction(FActions.List^[I]);
case Value of
asNormal:
begin
if Action is TCustomAction then
if State = asSuspendedEnabled then
with Action as TCustomAction do
Enabled := SavedEnabledState;
Action.Update;
end;
asSuspendedEnabled:
if Action is TCustomAction then
if Value = asSuspendedEnabled then
with Action as TCustomAction do
begin
SavedEnabledState := Enabled;
Enabled := True;
end;
end;
end;
end;
end;
// included by actnlist.pas

View File

@ -211,13 +211,53 @@ end;
{------------------------------------------------------------------------------
function TMenuItem.IsCaptionStored: boolean;
Checks if Caption needs to be saved to stream
Checks if 'Caption' needs to be saved to stream
------------------------------------------------------------------------------}
function TMenuItem.IsCaptionStored: boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsCaptionLinked;
end;
{------------------------------------------------------------------------------
function TMenuItem.IsCheckedStored: boolean;
Checks if 'Checked' needs to be saved to stream
------------------------------------------------------------------------------}
function TMenuItem.IsCheckedStored: boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsCheckedLinked;
end;
{------------------------------------------------------------------------------
function TMenuItem.IsEnabledStored: boolean;
Checks if 'Checked' needs to be saved to stream
------------------------------------------------------------------------------}
function TMenuItem.IsEnabledStored: boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsEnabledLinked;
end;
{------------------------------------------------------------------------------
function TMenuItem.IsShortCutStored: boolean;
Checks if 'Checked' needs to be saved to stream
------------------------------------------------------------------------------}
function TMenuItem.IsShortCutStored: boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsShortCutLinked;
end;
{------------------------------------------------------------------------------
function TMenuItem.IsVisibleStored: boolean;
Checks if 'Checked' needs to be saved to stream
------------------------------------------------------------------------------}
function TMenuItem.IsVisibleStored: boolean;
begin
Result := (ActionLink = nil) or not FActionLink.IsVisibleLinked;
end;
{------------------------------------------------------------------------------
Function: TMenuItem.GetParentMenu
Params: none
@ -587,6 +627,9 @@ end;
{ =============================================================================
$Log$
Revision 1.18 2002/08/06 20:05:19 lazarus
MG: added actnlist.pp
Revision 1.17 2002/08/06 19:57:40 lazarus
MG: added actnlist.pp
@ -666,6 +709,9 @@ end;
$Log$
Revision 1.18 2002/08/06 20:05:19 lazarus
MG: added actnlist.pp
Revision 1.17 2002/08/06 19:57:40 lazarus
MG: added actnlist.pp