2008-02-03 12:05:55 +00:00
|
|
|
{*********************************************************}
|
|
|
|
{* VPRESEDITDLG.PAS 1.03 *}
|
|
|
|
{*********************************************************}
|
|
|
|
|
|
|
|
{* ***** BEGIN LICENSE BLOCK ***** *}
|
|
|
|
{* Version: MPL 1.1 *}
|
|
|
|
{* *}
|
|
|
|
{* 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 TurboPower Visual PlanIt *}
|
|
|
|
{* *}
|
|
|
|
{* The Initial Developer of the Original Code is TurboPower Software *}
|
|
|
|
{* *}
|
|
|
|
{* Portions created by TurboPower Software Inc. are Copyright (C) 2002 *}
|
|
|
|
{* TurboPower Software Inc. All Rights Reserved. *}
|
|
|
|
{* *}
|
|
|
|
{* Contributor(s): *}
|
|
|
|
{* *}
|
|
|
|
{* ***** END LICENSE BLOCK ***** *}
|
|
|
|
|
2016-06-07 15:09:01 +00:00
|
|
|
{$I vp.inc}
|
2008-02-03 12:05:55 +00:00
|
|
|
|
|
|
|
unit VpResEditDlg;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{$IFDEF LCL}
|
2016-07-12 18:00:32 +00:00
|
|
|
LCLProc, LCLType, LCLIntf, LResources,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ELSE}
|
2016-06-22 07:59:17 +00:00
|
|
|
Windows, Messages,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
2016-06-22 07:59:17 +00:00
|
|
|
SysUtils,
|
2008-02-03 12:05:55 +00:00
|
|
|
{$IFDEF VERSION6} Variants, {$ENDIF}
|
|
|
|
Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls,
|
|
|
|
VpDlg, VpBase, VpData, ComCtrls, VpConst;
|
|
|
|
|
|
|
|
type
|
|
|
|
{ forward declarations }
|
|
|
|
TVpResourceEditDialog = class;
|
|
|
|
|
|
|
|
TResEditForm = class(TForm)
|
|
|
|
pnlBottom: TPanel;
|
|
|
|
OKBtn: TButton;
|
|
|
|
CancelBtn: TButton;
|
|
|
|
pgResource: TPageControl;
|
|
|
|
tabResource: TTabSheet;
|
|
|
|
DescriptionEdit: TEdit;
|
|
|
|
lblDescription: TLabel;
|
|
|
|
lblNotes: TLabel;
|
|
|
|
NotesMemo: TMemo;
|
|
|
|
imgResources: TImage;
|
|
|
|
procedure OKBtnClick(Sender: TObject);
|
|
|
|
procedure FormCreate(Sender: TObject);
|
|
|
|
procedure CancelBtnClick(Sender: TObject);
|
|
|
|
procedure Change(Sender: TObject);
|
|
|
|
procedure FormShow(Sender: TObject);
|
|
|
|
private
|
2016-07-14 15:26:55 +00:00
|
|
|
procedure PositionControls;
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure SetControls;
|
|
|
|
public
|
|
|
|
ReturnCode: TVpEditorReturnCode;
|
|
|
|
ResourceChanged: Boolean;
|
|
|
|
Resource: TVpResource;
|
|
|
|
procedure PopulateSelf;
|
|
|
|
procedure DePopulateSelf;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TVpResourceEditDialog = class(TVpBaseDialog)
|
|
|
|
protected {private}
|
2016-06-28 09:36:30 +00:00
|
|
|
reEditDlg: TResEditForm;
|
|
|
|
reResource: TVpResource;
|
2008-02-03 12:05:55 +00:00
|
|
|
function Show: Boolean;
|
|
|
|
public
|
|
|
|
function Execute: Boolean; reintroduce;
|
|
|
|
function AddNewResource: Boolean;
|
|
|
|
published
|
|
|
|
{properties}
|
|
|
|
property DataStore;
|
|
|
|
property Options;
|
|
|
|
property Placement;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ExecuteResourceDlg(Resource: TVpResource): Boolean;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2016-06-07 16:34:18 +00:00
|
|
|
{$IFDEF LCL}
|
2016-06-07 15:09:01 +00:00
|
|
|
{$R *.lfm}
|
2016-06-07 16:34:18 +00:00
|
|
|
{$ELSE}
|
|
|
|
{$R *.dfm}
|
2008-02-03 12:05:55 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
2016-06-10 16:12:14 +00:00
|
|
|
uses
|
2016-07-14 15:26:55 +00:00
|
|
|
Math,
|
2016-06-10 16:12:14 +00:00
|
|
|
vpSR, vpMisc;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
function ExecuteResourceDlg(Resource: TVpResource): Boolean;
|
|
|
|
var
|
|
|
|
EditForm: TResEditForm;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
|
|
|
|
if Resource = nil then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
Application.CreateForm(TResEditForm, EditForm);
|
|
|
|
EditForm.Resource := Resource;
|
|
|
|
EditForm.PopulateSelf;
|
|
|
|
EditForm.ShowModal;
|
|
|
|
if EditForm.ReturnCode = rtCommit then begin
|
|
|
|
EditForm.DePopulateSelf;
|
|
|
|
result := true;
|
|
|
|
end;
|
|
|
|
EditForm.Release;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
{ TVpResourceEditDialog }
|
|
|
|
|
|
|
|
function TVpResourceEditDialog.AddNewResource: Boolean;
|
|
|
|
var
|
|
|
|
Res: TVpResource;
|
|
|
|
ResName: string;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
if DataStore <> nil then begin
|
|
|
|
Res := DataStore.Resources.AddResource(DataStore.GetNextID(ResourceTableName));
|
|
|
|
if Res <> nil then begin
|
|
|
|
Res.Changed := true;
|
|
|
|
reResource := Res;
|
|
|
|
result := Show;
|
|
|
|
|
|
|
|
if Result then begin
|
|
|
|
ResName := Res.Description;
|
|
|
|
DataStore.PostResources;
|
|
|
|
DataStore.Load;
|
|
|
|
DataStore.SetResourceByName(ResName);
|
|
|
|
end else
|
|
|
|
Res.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
function TVpResourceEditDialog.Show: Boolean;
|
|
|
|
var
|
|
|
|
EditForm: TResEditForm;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
Application.CreateForm(TResEditForm, EditForm);
|
|
|
|
try
|
|
|
|
DoFormPlacement(EditForm);
|
|
|
|
EditForm.Resource := reResource;
|
|
|
|
EditForm.PopulateSelf;
|
|
|
|
EditForm.ShowModal;
|
|
|
|
if EditForm.ReturnCode = rtCommit then begin
|
|
|
|
EditForm.DePopulateSelf;
|
2016-06-17 21:29:44 +00:00
|
|
|
DataStore.NotifyDependents;
|
2008-02-03 12:05:55 +00:00
|
|
|
result := true;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
EditForm.Release;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
function TVpResourceEditDialog.Execute: Boolean;
|
|
|
|
begin
|
|
|
|
result := false;
|
|
|
|
if (DataStore <> nil) and (DataStore.Resource <> nil) then begin
|
|
|
|
reResource := DataStore.Resource;
|
|
|
|
|
|
|
|
result := Show;
|
|
|
|
|
|
|
|
if result then begin
|
|
|
|
reResource.Changed := true;
|
|
|
|
DataStore.PostResources;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
{ TResEditForm }
|
|
|
|
|
|
|
|
procedure TResEditForm.DePopulateSelf;
|
|
|
|
begin
|
|
|
|
Resource.Description := DescriptionEdit.Text;
|
|
|
|
Resource.Notes := NotesMemo.Text;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.PopulateSelf;
|
|
|
|
begin
|
|
|
|
DescriptionEdit.Text := Resource.Description;
|
|
|
|
NotesMemo.Text := Resource.Notes;
|
2016-06-10 16:12:14 +00:00
|
|
|
|
|
|
|
Caption := RSDlgResEditCaption;
|
|
|
|
tabResource.Caption := RSResource;
|
|
|
|
lblDescription.Caption := RSDlgResEditDescription;
|
|
|
|
lblNotes.Caption := RSNotes;
|
|
|
|
OKBtn.Caption := RSOKBtn;
|
|
|
|
CancelBtn.Caption := RSCancelBtn;
|
|
|
|
|
2016-07-14 15:26:55 +00:00
|
|
|
PositionControls;
|
2008-02-03 12:05:55 +00:00
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
2016-07-14 15:26:55 +00:00
|
|
|
procedure TResEditForm.PositionControls;
|
|
|
|
var
|
2016-08-06 22:18:53 +00:00
|
|
|
HDelta: Integer = 8;
|
|
|
|
VDelta: Integer = 8;
|
2016-07-14 15:26:55 +00:00
|
|
|
begin
|
2016-08-06 22:18:53 +00:00
|
|
|
HDelta := ScaleX(HDelta, DesignTimeDPI);
|
|
|
|
VDelta := ScaleY(VDelta, DesignTimeDPI);
|
2016-07-14 15:26:55 +00:00
|
|
|
|
2016-08-06 22:18:53 +00:00
|
|
|
DescriptionEdit.Left := lblDescription.Left + GetLabelWidth(lblDescription) + HDelta;
|
|
|
|
DescriptionEdit.Width := imgResources.Left - 2*HDelta - DescriptionEdit.Left;
|
|
|
|
DescriptionEdit.Top := imgResources.Top; // + (imgResources.Height - DescriptionEdit.Height) div 2;
|
2016-07-14 15:26:55 +00:00
|
|
|
lblDescription.Top := DescriptionEdit.Top + (DescriptionEdit.Height - lblDescription.Height) div 2;
|
|
|
|
|
2016-08-06 22:18:53 +00:00
|
|
|
lblNotes.Top := BottomOf(DescriptionEdit) + VDelta;
|
|
|
|
NotesMemo.Top := BottomOf(lblNotes) + VDelta;
|
|
|
|
ClientHeight := ClientHeight + ScaleY(NotesMemo.Height, DesignTimeDPI) - NotesMemo.Height;
|
|
|
|
NotesMemo.Height := tabResource.ClientHeight - NotesMemo.Top - VDelta;
|
|
|
|
|
|
|
|
OKBtn.Height := ScaleY(OKBtn.Height, DesignTimeDPI);
|
|
|
|
CancelBtn.Height := OKBtn.Height;
|
|
|
|
pnlBottom.Height := VDelta + OKBtn.Height + VDelta;
|
|
|
|
OKBtn.Top := VDelta;
|
|
|
|
CancelBtn.Top := VDelta;
|
2016-07-14 15:26:55 +00:00
|
|
|
|
|
|
|
OKBtn.Width := Max(GetButtonWidth(OKBtn), GetButtonWidth(CancelBtn));
|
|
|
|
CancelBtn.Width := OKBtn.Width;
|
2016-08-13 12:24:22 +00:00
|
|
|
{$IFDEF MSWINDOWS}
|
2016-07-14 15:26:55 +00:00
|
|
|
CancelBtn.Left := pnlBottom.ClientWidth - lblDescription.Left - CancelBtn.Width;
|
2016-08-06 22:18:53 +00:00
|
|
|
OKBtn.Left := CancelBtn.Left - OKBtn.Width - HDelta; // - (ClientWidth - tabResource.ClientWidth);
|
2016-08-13 12:24:22 +00:00
|
|
|
OKBtn.TabOrder := 0;
|
|
|
|
CancelBtn.TabOrder := 1;
|
|
|
|
{$ELSE}
|
|
|
|
OKBtn.Left := pnlBottom.ClientWidth - lblDescription.Left - OKBtn.Width;
|
|
|
|
CancelBtn.Left := OKBtn.Left - CancelBtn.Width - HDelta; // - (ClientWidth - tabResource.ClientWidth);
|
|
|
|
CancelBtn.TabOrder := 0;
|
|
|
|
OKBtn.TabOrder := 1;
|
|
|
|
{$ENDIF}
|
2016-07-14 15:26:55 +00:00
|
|
|
end;
|
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
procedure TResEditForm.OKBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if ResourceChanged then
|
|
|
|
ReturnCode := rtCommit;
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.FormCreate(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ReturnCode := rtAbandon;
|
|
|
|
ResourceChanged := false;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.CancelBtnClick(Sender: TObject);
|
|
|
|
begin
|
|
|
|
Close;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.Change(Sender: TObject);
|
|
|
|
begin
|
|
|
|
ResourceChanged := true;
|
|
|
|
SetControls;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.FormShow(Sender: TObject);
|
|
|
|
begin
|
|
|
|
DescriptionEdit.SetFocus;
|
|
|
|
SetControls;
|
|
|
|
end;
|
|
|
|
{=====}
|
|
|
|
|
|
|
|
procedure TResEditForm.SetControls;
|
|
|
|
begin
|
|
|
|
OKBtn.Enabled := (DescriptionEdit.Text <> '');
|
|
|
|
end;
|
2008-02-08 15:07:26 +00:00
|
|
|
|
2008-02-03 12:05:55 +00:00
|
|
|
end.
|
|
|
|
|