📄 rm_desgn.pas
字号:
min: Double;
p: TPoint;
function DoMin(a: array of TPoint): Boolean;
var
i: Integer;
d: Double;
begin
Result := False;
for i := Low(a) to High(a) do
begin
d := sqrt((x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y));
if d < min then
begin
min := d;
p := a[i];
Result := True;
end;
end;
end;
begin
Result := False;
min := FDesigner.GridSizeX;
p := Point(x, y);
for i := 0 to Objects.Count - 1 do
begin
t := Objects[i];
if DoMin([Point(t.x, t.y), Point(t.x + t.dx, t.y),
Point(t.x + t.dx, t.y + t.dy), Point(t.x, t.y + t.dy)]) then
Result := True;
end;
x := p.x; y := p.y;
end;
procedure TRMDesignerPage.RoundCoord(var x, y: Integer);
begin
with FDesigner do
begin
if GridAlign then
begin
if GridSizeX * GridSizeX <> 0 then
x := x div GridSizeX * GridSizeX;
if GridSizeY * GridSizeY <> 0 then
y := y div GridSizeY * GridSizeY;
end;
end;
end;
procedure TRMDesignerPage.GetMultipleSelected;
var
i, j, k: Integer;
t: TRMView;
begin
j := 0; k := 0;
FLeftTop := Point(10000, 10000);
FRightBottom := -1;
MRFlag := False;
if SelNum > 1 then {find right-bottom element}
begin
for i := 0 to Objects.Count - 1 do
begin
t := Objects[i];
if t.Selected then
begin
t.OriginalRect := Rect(t.x, t.y, t.dx, t.dy);
if (t.x + t.dx > j) or ((t.x + t.dx = j) and (t.y + t.dy > k)) then
begin
j := t.x + t.dx;
k := t.y + t.dy;
FRightBottom := i;
end;
if t.x < FLeftTop.x then
FLeftTop.x := t.x;
if t.y < FLeftTop.y then
FLeftTop.y := t.y;
end;
end;
t := Objects[FRightBottom];
OldRect := Rect(FLeftTop.x, FLeftTop.y, t.x + t.dx, t.y + t.dy);
OldRect1 := OldRect;
MRFlag := True;
end;
end;
procedure TRMDesignerPage.InplaceEdit(aView: TRMView);
procedure _DisableToolbar(aToolbar: TRMToolbar);
var
i: Integer;
begin
aToolbar.BeginUpdate;
{$IFDEF USE_TB2k}
for i := 0 to aToolbar.Items.Count - 1 do
{$ELSE}
for i := 0 to aToolbar.ControlCount - 1 do
{$ENDIF}
{$IFDEF USE_TB2k}
aToolbar.Items[i].Enabled := False;
{$ELSE}
aToolbar.Controls[i].Enabled := False;
{$ENDIF}
aToolbar.EndUpdate;
end;
procedure _DisableMenu(aMenu: TMenuItem);
var
i: Integer;
begin
for i := 0 to aMenu.Count - 1 do
aMenu.Items[i].Enabled := False;
end;
begin
if THackView(aView).AllowInplaceEdit then
begin
SaveInplaceEdit;
_DisableToolbar(FDesigner.ToolbarStandard);
_DisableToolbar(FDesigner.ToolbarEdit);
_DisableToolbar(FDesigner.ToolBarAddinTools);
_DisableToolbar(FDesigner.ToolbarBorder);
_DisableToolbar(FDesigner.ToolbarAlign);
_DisableToolbar(FDesigner.ToolbarSize);
_DisableToolbar(FDesigner.ToolbarModifyPrepared);
_DisableToolbar(FDesigner.ToolbarComponent);
_DisableMenu(FDesigner.barFile);
_DisableMenu(FDesigner.barEdit);
_DisableMenu(FDesigner.barTools);
_DisableMenu(FDesigner.barHelp);
FDesigner.FInspForm.Enabled := False;
if RMFieldsDialog <> nil then
RMFieldsDialog.Enabled := False;
FInplaceEditedView := aView;
THackView(aView).InplaceEdit(Self, FInplaceEditor);
end;
end;
procedure TRMDesignerPage.SaveInplaceEdit;
begin
if FInplaceEditedView <> nil then
begin
THackView(FInplaceEditedView).SaveInplaceEdit(FInplaceEditor);
EndInplaceEdit;
end;
end;
procedure TRMDesignerPage.EndInplaceEdit;
var
pt, pl: integer;
procedure _EnableToolbar(aToolbar: TRMToolbar);
var
i: Integer;
begin
aToolbar.BeginUpdate;
{$IFDEF USE_TB2k}
for i := 0 to aToolbar.Items.Count - 1 do
{$ELSE}
for i := 0 to aToolbar.ControlCount - 1 do
{$ENDIF}
{$IFDEF USE_TB2k}
aToolbar.Items[i].Enabled := True;
{$ELSE}
aToolbar.Controls[i].Enabled := True;
{$ENDIF}
aToolbar.EndUpdate;
end;
procedure _DisableMenu(aMenu: TMainMenu);
var
i: Integer;
begin
for i := 0 to aMenu.Items.Count - 1 do
aMenu.Items[i].Enabled := True;
end;
procedure _EnableMenu(aMenu: TMenuItem);
var
i: Integer;
begin
for i := 0 to aMenu.Count - 1 do
aMenu.Items[i].Enabled := True;
end;
begin
if FInplaceEditor <> nil then
begin
pl := TScrollBox(Parent).HorzScrollBar.Position;
pt := TScrollBox(Parent).VertScrollBar.Position;
SetFocus;
FInplaceEditor.Free;
FInplaceEditor := nil;
FInplaceEditedView := nil;
TScrollBox(Parent).HorzScrollBar.Position := pl;
TScrollBox(Parent).VertScrollBar.Position := pt;
_EnableToolbar(FDesigner.ToolbarStandard);
_EnableToolbar(FDesigner.ToolbarEdit);
_EnableToolbar(FDesigner.ToolBarAddinTools);
_EnableToolbar(FDesigner.ToolbarBorder);
_EnableToolbar(FDesigner.ToolbarAlign);
_EnableToolbar(FDesigner.ToolbarSize);
_EnableToolbar(FDesigner.ToolbarModifyPrepared);
_EnableToolbar(FDesigner.ToolbarComponent);
_EnableMenu(FDesigner.barFile);
_EnableMenu(FDesigner.barEdit);
_EnableMenu(FDesigner.barTools);
_EnableMenu(FDesigner.barHelp);
FDesigner.Tab1.Enabled := True;
FDesigner.FInspForm.Enabled := True;
if RMFieldsDialog <> nil then
RMFieldsDialog.Enabled := True;
end;
end;
procedure TRMDesignerPage.MDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i: Integer;
f, v: Boolean;
t: TRMView;
Rgn: HRGN;
p: TPoint;
procedure _SaveInplaceEdit;
begin
if (FInplaceEditor <> nil) and (Objects.Count > 0) then
begin
t := Objects[TopSelected];
if (SelNum = 0) or (t = nil) or (t <> FInplaceEditedView) then
begin
SaveInplaceEdit;
end;
end;
end;
begin
FWasCtrl := ssCtrl in Shift;
if FDFlag then
begin
FDFlag := False;
Exit;
end;
if (Button = mbRight) and FDown and FRFlag then
DrawFocusRect(OldRect);
FRFlag := False;
DrawPage(dmSelection);
FDown := True;
_SaveInplaceEdit;
if Button = mbLeft then
begin
if (ssCtrl in Shift) or (Cursor = crCross) then
begin
FRFlag := True;
if Cursor = crCross then
begin
if FDesigner.PageType = ptReport then
DrawFocusRect(OldRect);
RoundCoord(x, y);
OldRect1 := OldRect;
end;
OldRect := Rect(x, y, x, y);
FDesigner.Unselect;
SelNum := 0;
FRightBottom := -1;
MRFlag := False;
FirstSelected := nil;
Exit;
end
else if Cursor = crPencil then
begin
with FDesigner do
begin
if GridAlign then
begin
if not FindNearestEdge(x, y) then
begin
x := Round(x / GridSizeX) * GridSizeX;
y := Round(y / GridSizeY) * GridSizeY;
end;
end;
end;
OldRect := Rect(x, y, x, y);
FDesigner.Unselect;
SelNum := 0;
FRightBottom := -1;
MRFlag := False;
FirstSelected := nil;
FLastX := x;
FLastY := y;
Exit;
end;
end;
if Cursor = crDefault then
begin
f := False;
for i := Objects.Count - 1 downto 0 do
begin
t := Objects[i];
Rgn := t.GetClipRgn(rtNormal);
v := PtInRegion(Rgn, X, Y);
DeleteObject(Rgn);
if v then
begin
if ssShift in Shift then
begin
t.Selected := not t.Selected;
if t.Selected then
Inc(SelNum)
else
Dec(SelNum);
end
else if not t.Selected then
begin
FDesigner.Unselect;
SelNum := 1;
t.Selected := True;
end;
if SelNum = 0 then
FirstSelected := nil
else if SelNum = 1 then
FirstSelected := t
else if FirstSelected <> nil then
begin
if not FirstSelected.Selected then
FirstSelected := nil;
end;
f := True;
Break;
end;
end;
if not f then
begin
FDesigner.Unselect;
SelNum := 0;
FirstSelected := nil;
if Button = mbLeft then
begin
FRFlag := True;
OldRect := Rect(x, y, x, y);
_SaveInplaceEdit;
Exit;
end;
end;
GetMultipleSelected;
end;
if SelNum = 0 then
begin // reset multiple selection
FRightBottom := -1;
MRFlag := False;
end;
FLastX := x;
FLastY := y;
FMoved := False;
FirstChange := True;
FFirstBandMove := True;
if Button = mbRight then
begin
DrawPage(dmSelection);
FDown := False;
GetCursorPos(p);
FDesigner.SelectionChanged;
FDesigner.Popup1.Popup(p.X, p.Y);
end
else if FDesigner.FShapeMode = smFrame then
DrawPage(dmShape);
_SaveInplaceEdit;
end;
function IsSubreport(PageN: Integer): TRMView;
var
i, j: Integer;
t: TRMView;
begin
Result := nil;
with CurReport do
begin
for i := 0 to Pages.Count - 1 do
begin
for j := 0 to Pages[i].Objects.Count - 1 do
begin
t := Pages[i].Objects[j];
if t.Typ = gtSubReport then
begin
if TRMSubReportView(t).SubPage = PageN then
begin
Result := t;
Exit;
end;
end;
end;
end;
end;
end;
const
CON_RMBandNames: array[0..22] of string = (
'Report title', 'Report summary', 'Page header', 'Page footer',
'Master header', 'Master data', 'Master footer', 'Detail header',
'Detail data', 'Detail footer', 'Subdetail header', 'Subdetail data',
'Subdetail footer', 'Overlay', 'Column header', 'Column footer',
'Group header', 'Group footer', 'Cross header', 'Cross data',
'Cross footer', 'Child', 'None');
procedure TRMDesignerPage.MUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
i, k, dx, dy: Integer;
t: TRMView;
ObjectInserted: Boolean;
procedure AddObject(ot: Byte);
begin
Objects.Add(RMCreateObject(ot, ''));
t := Objects.Last;
end;
procedure CreateSection;
var
s: string;
FRMBandTypesForm: TRMBandTypesForm;
begin
FRMBandTypesForm := TRMBandTypesForm.Create(nil);
FRMBandTypesForm.IsSubreport := IsSubreport(FDesigner.CurPage) <> nil;
ObjectInserted := FRMBandTypesForm.ShowModal = mrOk;
if ObjectInserted then
begin
Objects.Add(TRMBandView.Create);
t := Objects.Last;
TRMBandView(t).BandType := FRMBandTypesForm.SelectedTyp;
s := CON_RMBandNames[Integer(FRMBandTypesForm.SelectedTyp)];
if Pos(' ', s) <> 0 then
begin
s[Pos(' ', s) + 1] := UpCase(s[Pos(' ', s) + 1]);
Delete(s, Pos(' ', s), 1);
end;
THackView(t).BaseName := s;
SendBandsToDown;
end;
FRMBandTypesForm.Free;
end;
procedure CreateSubReport;
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -