Files
lazarus-ccr/components/tvplanit/source/vpedelem.pas

473 lines
14 KiB
ObjectPascal
Raw Permalink Normal View History

{*********************************************************}
{* VPEDELEM.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 ***** *}
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined}
{$I vp.inc}
unit VpEdElem;
interface
uses
{$IFDEF LCL}
LCLProc, LCLType, LCLIntf,
{$ELSE}
Windows, Messages,
{$ENDIF}
SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls,
VpBase, VpSR, VpPrtFmt;
type
{ TfrmEditElement }
TfrmEditElement = class(TForm)
BevelHeightWidth: TBevel;
BevelTopLeft: TBevel;
BevelTopLeft1: TBevel;
btnCancel: TButton;
btnOk: TButton;
btnShape: TButton;
edName: TEdit;
gbDayOffset: TGroupBox;
gbPosition: TGroupBox;
lblName: TLabel;
Panel1: TPanel;
DayOffsetPanel: TPanel;
ButtonPanel: TPanel;
ItemTypePanel: TPanel;
HeightWidthPanel: TPanel;
Panel2: TPanel;
PositionPanel: TPanel;
rbPixels: TRadioButton;
rbPercent: TRadioButton;
rbInches: TRadioButton;
rbCentimeters: TRadioButton;
TopLeftPanel: TPanel;
rgDayOffsetUnit: TRadioGroup;
rgItemType: TRadioGroup;
LblTop: TLabel;
LblLeft: TLabel;
LblHeight: TLabel;
LblWidth: TLabel;
rgRotation: TRadioGroup;
edTop: TEdit;
edLeft: TEdit;
edHeight: TEdit;
edWidth: TEdit;
chkVisible: TCheckBox;
gbCaption: TGroupBox;
btnCaptionFont: TButton;
FontDialog1: TFontDialog;
edCaptionText: TEdit;
lblCaptionText: TLabel;
edOffset: TEdit;
udOffset: TUpDown;
udTop: TUpDown;
udLeft: TUpDown;
udHeight: TUpDown;
udWidth: TUpDown;
procedure btnCancelClick(Sender: TObject);
procedure btnOkClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure rgItemTypeClick(Sender: TObject);
procedure btnShapeClick(Sender: TObject);
procedure btnCaptionFontClick(Sender: TObject);
procedure edCaptionTextChange(Sender: TObject);
procedure PosEditExit(Sender: TObject);
procedure PosEditEnter(Sender: TObject);
procedure MeasurementUnitChange(Sender: TObject);
procedure UpDownClick(Sender: TObject; Button: TUDBtnType);
private
procedure PositionControls;
procedure SetCaptions;
procedure SetMaxSpin(Spin: Integer);
protected
TheShape: TVpPrintShape;
TheCaption: TVpPrintCaption;
CurEdit: TEdit;
MaxSpin: Integer;
function GetUnitIndex: Integer;
procedure SaveData(AnElement: TVpPrintFormatElementItem);
procedure SetData(AnElement: TVpPrintFormatElementItem);
procedure SetItemType(Index: Integer);
function Validate: Boolean;
{ Private declarations }
public
function Execute(AnElement : TVpPrintFormatElementItem) : Boolean;
{ Public declarations }
end;
implementation
uses
Math,
VpMisc, VpEdShape;
{$IFDEF LCL}
{$R *.lfm}
{$ELSE}
{$R *.dfm}
{$ENDIF}
function EvalFmt(Val : Extended) : string;
begin
Result := FormatFloat('0.00', Val);
end;
{******************************************************************************}
{* TfrmEditElement *}
{******************************************************************************}
procedure TfrmEditElement.FormCreate(Sender: TObject);
var
i: Integer;
begin
btnShape.Enabled := False;
gbCaption.Enabled := False;
edCaptionText.Enabled := False;
lblCaptionText.Enabled := False;
btnCaptionFont.Enabled := False;
for i:=0 to rgDayOffsetUnit.ControlCount-1 do
TRadioButton(rgDayOffsetUnit.Controls[i]).ParentFont := false;
rgDayOffsetUnit.Font.Style := [fsBold];
for i:=0 to rgItemType.ControlCount-1 do
TRadioButton(rgItemType.Controls[i]).ParentFont := false;
rgItemType.Font.Style := [fsBold];
for i:=0 to rgRotation.ControlCount-1 do
TRadioButton(rgRotation.Controls[i]).ParentFont := false;
rgItemType.Font.Style := [fsBold];
for i:= 0 to gbPosition.ControlCount-1 do
begin
if gbPosition.Controls[i] is TLabel then
TLabel(gbPosition.Controls[i]).ParentFont := false
else if gbPosition.Controls[i] is TEdit then
TEdit(gbPosition.Controls[i]).ParentFont := false
else if gbPosition.Controls[i] is TCheckbox then
TCheckbox(gbPosition.Controls[i]).ParentFont := false
else if gbPosition.Controls[i] is TPanel then
TPanel(gbPosition.Controls[i]).ParentFont := false;
end;
gbPosition.Font.Style := [fsBold];
SetCaptions;
FixLabels(Self);
end;
procedure TfrmEditElement.FormShow(Sender: TObject);
begin
PositionControls;
edName.SetFocus;
end;
procedure TfrmEditElement.btnCaptionFontClick(Sender: TObject);
begin
if FontDialog1.Execute then
TheCaption.Font := FontDialog1.Font;
end;
procedure TfrmEditElement.btnCancelClick(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TfrmEditElement.btnOkClick(Sender: TObject);
begin
if Validate then
ModalResult := mrOk
else begin
ShowMessage(RSNeedElementName);
edName.SetFocus;
Exit;
end;
end;
procedure TfrmEditElement.btnShapeClick(Sender: TObject);
var
frmEditShape: TfrmEditShape;
begin
Application.CreateForm(TfrmEditShape, frmEditShape);
frmEditShape.Execute(TheShape);
frmEditShape.Free;
end;
procedure TfrmEditElement.edCaptionTextChange(Sender: TObject);
begin
TheCaption.Caption := edCaptionText.Text;
end;
function TfrmEditElement.Execute(AnElement : TVpPrintFormatElementItem) : Boolean;
begin
SetData(AnElement);
Result := ShowModal = mrOk;
if Result then
SaveData(AnElement);
end;
function TfrmEditElement.GetUnitIndex: Integer;
begin
if rbPixels.Checked then
Result := 0
else if rbPercent.Checked then
Result := 1
else if rbInches.Checked then
Result := 2
else if rbCentimeters.Checked then
Result := 3
else
raise Exception.Create('GetUnitIndex: unknown control');
end;
procedure TfrmEditElement.PosEditEnter(Sender: TObject);
begin
CurEdit := (Sender as TEdit);
end;
procedure TfrmEditElement.MeasurementUnitChange(Sender: TObject);
begin
SetMaxSpin(GetUnitIndex);
end;
procedure TfrmEditElement.PosEditExit(Sender: TObject);
var
ed: TEdit;
Val: Extended;
begin
ed := (Sender as TEdit);
if TryStrToFloat(ed.Text, Val) then
begin
if Val > MaxSpin then begin
ed.Text := EvalFmt(MaxSpin);
end else
if Val < 0.0 then begin
ed.Text := EvalFmt(0);
end;
end else
begin
ed.SetFocus;
MessageDlg(RSPleaseEnterFloat, mtError, [mbOK], 0);
end;
end;
procedure TfrmEditElement.rgItemTypeClick(Sender: TObject);
begin
SetItemType(rgItemType.ItemIndex);
end;
procedure TfrmEditElement.SaveData(AnElement: TVpPrintFormatElementItem);
begin
AnElement.ElementName := edName.Text;
AnElement.DayOffset := udOffset.Position;
AnElement.Top := StrToFloat(edTop.Text);
AnElement.Left := StrToFloat(edLeft.Text);
AnElement.Height:= StrToFloat(edHeight.Text);
AnElement.Width := StrToFloat(edWidth.Text);
AnElement.ItemType := TVpItemType(rgItemType.ItemIndex);
AnElement.DayOffsetUnits := TVpDayUnits(rgDayOffsetUnit.ItemIndex);
AnElement.Rotation := TVpRotationAngle(rgRotation.ItemIndex);
AnElement.Measurement := TVpItemMeasurement(GetUnitIndex);
AnElement.Visible := chkVisible.Checked;
end;
procedure TfrmEditElement.SetCaptions;
begin
Caption := RSEditElementCaption;
lblName.Caption := RSNameLbl;
rgItemType.Caption := RSElementTypeLbl;
rgItemType.Items[0] := RSDayViewElement;
rgItemType.Items[1] := RSWeekViewElement;
rgItemType.Items[2] := RSMonthViewElement;
rgItemType.Items[3] := RSCalendarElement;
rgItemType.Items[4] := RSShapeElement;
rgItemType.Items[5] := RSCaptionElement;
rgItemType.Items[6] := RSTasksElement;
rgItemType.Items[7] := RSContactsElement;
gbDayOffset.Caption := RSDayOffsetCaption;
rgDayOffsetUnit.Caption := RSDayOffsetUnits;
rgDayOffsetUnit.Items[0] := RSDays;
rgDayOffsetUnit.Items[1] := RSWeeks;
rgDayOffsetUnit.Items[2] := RSMonths;
rgDayOffsetUnit.Items[3] := RSYears;
rgRotation.Caption := RSRotationCaption;
rbPixels.Caption := RSPixels;
rbPercent.Caption := RSPercent;
rbInches.Caption := RSInches;
lblLeft.Caption := RSLeft;
lblTop.Caption := RSTop;
lblWidth.Caption := RSWidth;
lblHeight.Caption := RSHeight;
chkVisible.Caption := RSVisible;
gbCaption.Caption := RSCaptionLbl;
lblCaptionText.Caption := RSTextCaption;
btnCaptionFont.Caption := RSFontBtn;
btnShape.Caption := RSShapeBtn;
btnOK.Caption := RSOKBtn;
btnCancel.Caption := RSCancelBtn;
end;
procedure TfrmEditElement.PositionControls;
begin
AlignOKCancel(btnOK, btnCancel, ButtonPanel);
udOffset.Width := udOffset.Height div 2 + 1;
udTop.Width := udTop.Height div 2 + 1;
udLeft.Width := udLeft.Height div 2 + 1;
udHeight.Width := udHeight.Height div 2 + 1;
udWidth.Width := udWidth.Height div 2 + 1;
BevelTopLeft.Shape := bsSpacer;
BevelHeightWidth.Shape := bsSpacer;
rgRotation.Constraints.MinWidth := gbDayOffset.Width;
btnShape.Constraints.MinWidth := MaxValue([btnShape.Width, btnOK.Width, btnCancel.Width]);
btnOK.Constraints.MinWidth := btnShape.Constraints.MinWidth;
btnCancel.Constraints.MinWidth := btnShape.Constraints.MinWidth;
end;
procedure TfrmEditElement.SetData(AnElement : TVpPrintFormatElementItem);
begin
edName.Text := AnElement.ElementName;
udOffset.Position := AnElement.DayOffset;
rgItemType.ItemIndex := Ord(AnElement.ItemType);
TheShape := AnElement.Shape;
TheCaption := AnElement.Caption;
rgDayOffsetUnit.ItemIndex := Ord(AnElement.DayOffsetUnits);
rgRotation.ItemIndex := Ord(AnElement.Rotation);
case AnElement.Measurement of
imAbsolutePixel: rbPixels.Checked := true;
imPercent: rbPercent.Checked := true;
imInches: rbInches.Checked := true;
imCentimeters: rbCentimeters.Checked := true;
end;
SetMaxSpin(Ord(AnElement.Measurement));
edTop.Text := EvalFmt(AnElement.Top);
udTop.Position := Trunc(AnElement.Top);
edLeft.Text := EvalFmt(AnElement.Left);
udLeft.Position := Trunc(AnElement.Left);
edHeight.Text := EvalFmt(AnElement.Height);
udHeight.Position := Trunc(AnElement.Height);
edWidth.Text := EvalFmt(AnElement.Width);
udWidth.Position := Trunc(AnElement.Width);
edCaptionText.Text := AnElement.Caption.Caption;
FontDialog1.Font := AnElement.Caption.Font;
chkVisible.Checked := AnElement.Visible;
end;
procedure TfrmEditElement.SetItemType(Index : Integer);
var
itemType: TVpItemType;
begin
rgItemType.ItemIndex := Index;
itemType := TVpItemType(Index);
btnShape.Enabled := itemType = itShape;
gbCaption.Enabled := itemType = itCaption;
edCaptionText.Enabled := gbCaption.Enabled;
lblCaptionText.Enabled := gbCaption.Enabled;
btnCaptionFont.Enabled := gbCaption.Enabled;
DayOffsetPanel.Enabled := itemType in [itDayView, itWeekView, itMonthView, itCalendar];
end;
procedure TfrmEditElement.SetMaxSpin(Spin : Integer);
begin
case Spin of
0: MaxSpin := 2000;
1: MaxSpin := 100;
2: MaxSpin := 50;
end;
udLeft.Max := MaxSpin;
udTop.Max := MaxSpin;
udHeight.Max := MaxSpin;
udWidth.Max := MaxSpin;
end;
procedure TfrmEditElement.UpDownClick(Sender: TObject; Button: TUDBtnType);
var
Val, Inc : Extended;
begin
if Sender = udLeft then CurEdit := edLeft;
if Sender = udTop then CurEdit := edTop;
if Sender = udHeight then CurEdit := edHeight;
if Sender = udWidth then CurEdit := edWidth;
Val := 0.0;
if not TryStrToFloat(CurEdit.Text, Val) then
begin
Val := 0.0;
CurEdit.SetFocus;
MessageDlg(RSPleaseEnterFloat, mtError, [mbOK], 0);
end;
Inc := udLeft.Increment / 100;
case Button of
btNext: begin
if Trunc(Val + Inc) > Trunc(Val) then
(Sender as TUpDown).Position := (Sender as TUpDown).Position + 1;
CurEdit.Text := FormatFloat('0.00 ', Val + Inc);
end;
btPrev: begin
if Trunc(Val - Inc) < Trunc(Val) then
(Sender as TUpDown).Position := (Sender as TUpDown).Position - 1;
CurEdit.Text := FormatFloat('0.00 ', Val - Inc);
end;
end;
end;
function TfrmEditElement.Validate: Boolean;
begin
Result := edName.Text <> '';
end;
end.