home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kolekce / d6 / FRCLX.ZIP / SOURCE / FR_Desgn.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-29  |  161KB  |  5,959 lines

  1.  
  2. {******************************************}
  3. {                                          }
  4. {           FastReport CLX v2.4            }
  5. {             Report Designer              }
  6. {                                          }
  7. { Copyright (c) 1998-2001 by Tzyganenko A. }
  8. {                                          }
  9. {******************************************}
  10.  
  11. unit FR_Desgn;
  12.  
  13. interface
  14.  
  15. {$I FR.inc}
  16.  
  17. uses
  18.   SysUtils, Types, Classes, QGraphics, QControls,
  19.   QForms, QDialogs, QStdCtrls, QButtons, QExtCtrls, QPrinters, QComCtrls,
  20.   QMenus, QImgList, FR_Class, FR_Color,
  21.   FR_Ctrls, FR_Dock, FR_Insp, FR_Flds1, FR_API, QTypes;
  22.  
  23. const
  24.   crPencil = 11;
  25.  
  26. type
  27.   TLoadReportEvent = procedure(Report: TfrReport; var ReportName: String;
  28.     var Opened: Boolean) of object;
  29.   TSaveReportEvent = procedure(Report: TfrReport; var ReportName: String;
  30.     SaveAs: Boolean; var Saved: Boolean) of object;
  31.  
  32.   TfrDesignerForm = class;
  33.  
  34.   TfrDesigner = class(TComponent)  // fake component
  35.   private
  36.     FCloseQuery: Boolean;
  37.     FHideDisabledButtons: Boolean;
  38.     FTemplDir: String;
  39.     FOnLoadReport: TLoadReportEvent;
  40.     FOnSaveReport: TSaveReportEvent;
  41.     FOnShow: TNotifyEvent;
  42.   public
  43.     constructor Create(AOwner: TComponent); override;
  44.     destructor Destroy; override;
  45.   published
  46.     property CloseQuery: Boolean read FCloseQuery write FCloseQuery default True;
  47.     property HideDisabledButtons: Boolean read FHideDisabledButtons write FHideDisabledButtons default True;
  48.     property TemplateDir: String read FTemplDir write FTemplDir;
  49.     property OnLoadReport: TLoadReportEvent read FOnLoadReport write FOnLoadReport;
  50.     property OnSaveReport: TSaveReportEvent read FOnSaveReport write FOnSaveReport;
  51.     property OnShow: TNotifyEvent read FOnShow write FOnShow;
  52.   end;
  53.  
  54.   TfrSelectionType = (ssBand, ssMemo, ssOther, ssMultiple, ssClipboardFull);
  55.   TfrSelectionStatus = set of TfrSelectionType;
  56.   TfrReportUnits = (ruPixels, ruMM, ruInches);
  57.   TfrShapeMode = (smFrame, smAll);
  58.   TfrDesignerDrawMode = (dmAll, dmSelection, dmShape);
  59.   TfrDesignerRestriction =
  60.     (frdrDontEditObj, frdrDontModifyObj, frdrDontSizeObj, frdrDontMoveObj,
  61.      frdrDontDeleteObj, frdrDontCreateObj,
  62.      frdrDontDeletePage, frdrDontCreatePage, frdrDontEditPage,
  63.      frdrDontCreateReport, frdrDontLoadReport, frdrDontSaveReport,
  64.      frdrDontPreviewReport, frdrDontEditVariables, frdrDontChangeReportOptions);
  65.   TfrDesignerRestrictions = set of TfrDesignerRestriction;
  66.  
  67.   TfrSplitInfo = record
  68.     SplRect: TRect;
  69.     SplX: Integer;
  70.     View1, View2: TfrView;
  71.   end;
  72.  
  73.   TfrDesignerPage = class(TPanel)
  74.   private
  75.     Down,                          // mouse button was pressed
  76.     Moved,                         // mouse was moved (with pressed btn)
  77.     DFlag,                         // was double click
  78.     RFlag: Boolean;                // selecting objects by framing
  79.     Mode: (mdInsert, mdSelect);    // current mode
  80.     CT: (ctNone, ct1, ct2, ct3, ct4, ct5, ct6, ct7, ct8);  // cursor type
  81.     LastX, LastY: Integer;         // here stored last mouse coords
  82.     SplitInfo: TfrSplitInfo;
  83.     RightBottom: Integer;
  84.     LeftTop: TPoint;
  85.     FirstBandMove: Boolean;
  86.     WasCtrl: Boolean;
  87.     FDesigner: TfrDesignerForm;
  88.     FDrag: Boolean;
  89.     DisableDraw: Boolean;
  90.     procedure NormalizeRect(var r: TRect);
  91.     procedure NormalizeCoord(t: TfrView);
  92.     function FindNearestEdge(var x, y: Integer): Boolean;
  93.     procedure RoundCoord(var x, y: Integer);
  94.     procedure Draw(N: Integer);
  95.     procedure DrawPage(DrawMode: TfrDesignerDrawMode);
  96.     procedure DrawRectLine(Rect: TRect);
  97.     procedure DrawFocusRect(Rect: TRect);
  98.     procedure DrawHSplitter(Rect: TRect);
  99.     procedure DrawSelection(t: TfrView);
  100.     procedure DrawShape(t: TfrView);
  101.     procedure MDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  102.     procedure MUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  103.     procedure MMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  104.     procedure DClick(Sender: TObject);
  105.     procedure DoDragOver(Sender, Source: TObject; X, Y: Integer;
  106.       State: TDragState; var Accept: Boolean);
  107.     procedure DoDragDrop(Sender, Source: TObject; X, Y: Integer);
  108.   protected
  109.     procedure Paint; override;
  110.     procedure MouseLeave(AControl: TControl); override;
  111.   public
  112.     constructor Create(AOwner: TComponent); override;
  113.     procedure Init;
  114.     procedure SetPage;
  115.     procedure GetMultipleSelected;
  116.   end;
  117.  
  118.   TfrUndoBuffer = class(TObject)
  119.   private
  120.     FUndo, FRedo: TList;
  121.   public
  122.     constructor Create;
  123.     destructor Destroy; override;
  124.     procedure AddUndo(Report: TfrReport);
  125.     procedure AddRedo(Report: TfrReport);
  126.     procedure GetUndo(Report: TfrReport);
  127.     procedure GetRedo(Report: TfrReport);
  128.     procedure ClearUndo;
  129.     procedure ClearRedo;
  130.   end;
  131.  
  132.   TfrDesignerForm = class(TfrReportDesigner)
  133.     StatusBar1: TStatusBar;
  134.     frDock2: TfrDock;
  135.     frDock3: TfrDock;
  136.     Popup1: TPopupMenu;
  137.     N1: TMenuItem;
  138.     N2: TMenuItem;
  139.     N3: TMenuItem;
  140.     N5: TMenuItem;
  141.     N6: TMenuItem;
  142.     MainMenu1: TMainMenu;
  143.     FileMenu: TMenuItem;
  144.     EditMenu: TMenuItem;
  145.     ToolMenu: TMenuItem;
  146.     N10: TMenuItem;
  147.     N11: TMenuItem;
  148.     N12: TMenuItem;
  149.     N13: TMenuItem;
  150.     N19: TMenuItem;
  151.     N20: TMenuItem;
  152.     N21: TMenuItem;
  153.     N23: TMenuItem;
  154.     N24: TMenuItem;
  155.     N25: TMenuItem;
  156.     N27: TMenuItem;
  157.     N28: TMenuItem;
  158.     N26: TMenuItem;
  159.     N29: TMenuItem;
  160.     N30: TMenuItem;
  161.     N31: TMenuItem;
  162.     N32: TMenuItem;
  163.     N33: TMenuItem;
  164.     N36: TMenuItem;
  165.     OpenDialog1: TOpenDialog;
  166.     SaveDialog1: TSaveDialog;
  167.     ImageList1: TImageList;
  168.     Pan5: TMenuItem;
  169.     N8: TMenuItem;
  170.     N38: TMenuItem;
  171.     Pan6: TMenuItem;
  172.     N39: TMenuItem;
  173.     N40: TMenuItem;
  174.     N42: TMenuItem;
  175.     MastMenu: TMenuItem;
  176.     N16: TMenuItem;
  177.     N37: TMenuItem;
  178.     Pan2: TMenuItem;
  179.     Pan3: TMenuItem;
  180.     Pan1: TMenuItem;
  181.     Pan4: TMenuItem;
  182.     Panel4: TfrToolBar;
  183.     OB1: TToolButton;
  184.     OB2: TToolButton;
  185.     OB3: TToolButton;
  186.     OB4: TToolButton;
  187.     OB5: TToolButton;
  188.     Panel5: TfrToolBar;
  189.     Align1: TToolButton;
  190.     Align2: TToolButton;
  191.     Align3: TToolButton;
  192.     Align4: TToolButton;
  193.     Align5: TToolButton;
  194.     Align6: TToolButton;
  195.     Align7: TToolButton;
  196.     Align8: TToolButton;
  197.     Align9: TToolButton;
  198.     Align10: TToolButton;
  199.     Tab1: TTabControl;
  200.     ScrollBox1: TScrollBox;
  201.     frDock4: TfrDock;
  202.     HelpMenu: TMenuItem;
  203.     N34: TMenuItem;
  204.     N46: TMenuItem;
  205.     N47: TMenuItem;
  206.     N48: TMenuItem;
  207.     OB6: TToolButton;
  208.     Pan7: TMenuItem;
  209.     Image2: TImage;
  210.     N14: TMenuItem;
  211.     Panel7: TPanel;
  212.     PBox1: TPaintBox;
  213.     N17: TMenuItem;
  214.     N18: TMenuItem;
  215.     N22: TMenuItem;
  216.     N35: TMenuItem;
  217.     Popup2: TPopupMenu;
  218.     N41: TMenuItem;
  219.     N43: TMenuItem;
  220.     N44: TMenuItem;
  221.     Pan8: TMenuItem;
  222.     N45: TMenuItem;
  223.     N15: TMenuItem;
  224.     Bevel1: TBevel;
  225.     frDock1: TfrDock;
  226.     Panel2: TfrToolBar;
  227.     FileBtn1: TToolButton;
  228.     FileBtn2: TToolButton;
  229.     FileBtn3: TToolButton;
  230.     FileBtn4: TToolButton;
  231.     frTBSeparator1: TToolButton;
  232.     CutB: TToolButton;
  233.     CopyB: TToolButton;
  234.     PstB: TToolButton;
  235.     frTBSeparator2: TToolButton;
  236.     UndoB: TToolButton;
  237.     RedoB: TToolButton;
  238.     frTBSeparator3: TToolButton;
  239.     ZB1: TToolButton;
  240.     ZB2: TToolButton;
  241.     SelAllB: TToolButton;
  242.     frTBSeparator4: TToolButton;
  243.     PgB1: TToolButton;
  244.     PgB4: TToolButton;
  245.     PgB2: TToolButton;
  246.     PgB3: TToolButton;
  247.     frTBSeparator5: TToolButton;
  248.     GB1: TToolButton;
  249.     GB2: TToolButton;
  250.     GB3: TToolButton;
  251.     frTBSeparator11: TToolButton;
  252.     HelpBtn: TToolButton;
  253.     Panel3: TfrToolBar;
  254.     FnB1: TToolButton;
  255.     FnB2: TToolButton;
  256.     FnB3: TToolButton;
  257.     frTBSeparator6: TToolButton;
  258.     ClB2: TToolButton;
  259.     HlB1: TToolButton;
  260.     frTBSeparator7: TToolButton;
  261.     AlB1: TToolButton;
  262.     AlB3: TToolButton;
  263.     AlB2: TToolButton;
  264.     AlB8: TToolButton;
  265.     frTBSeparator8: TToolButton;
  266.     AlB6: TToolButton;
  267.     AlB5: TToolButton;
  268.     AlB7: TToolButton;
  269.     frTBSeparator9: TToolButton;
  270.     AlB4: TToolButton;
  271.     Panel1: TfrToolBar;
  272.     FrB1: TToolButton;
  273.     FrB2: TToolButton;
  274.     FrB3: TToolButton;
  275.     FrB4: TToolButton;
  276.     frTBSeparator10: TToolButton;
  277.     FrB5: TToolButton;
  278.     FrB6: TToolButton;
  279.     frTBSeparator15: TToolButton;
  280.     ClB1: TToolButton;
  281.     ClB3: TToolButton;
  282.     StB1: TToolButton;
  283.     MainImages: TImageList;
  284.     ToolBar1: TToolBar;
  285.     ToolBar2: TToolBar;
  286.     ToolBar3: TToolBar;
  287.     Panel6: TfrToolBar;
  288.     ToolBar4: TToolBar;
  289.     ToolBar5: TToolBar;
  290.     ToolButton1: TToolButton;
  291.     LinePanel: TPanel;
  292.     ToolBar6: TToolBar;
  293.     frSpeedButton7: TToolButton;
  294.     frSpeedButton8: TToolButton;
  295.     frSpeedButton9: TToolButton;
  296.     frSpeedButton10: TToolButton;
  297.     frSpeedButton11: TToolButton;
  298.     frSpeedButton12: TToolButton;
  299.     ImageList2: TImageList;
  300.     frTBPanel2: TfrTBPanel;
  301.     C4: TfrComboBox;
  302.     frTBPanel1: TfrTBPanel;
  303.     C3: TfrComboBox;
  304.     C2: TfrFontComboBox;
  305.     ExitB: TfrTBButton;
  306.     DisabledImages: TImageList;
  307.     Image1: TImage;
  308.     procedure FormCreate(Sender: TObject);
  309.     procedure FormDestroy(Sender: TObject);
  310.     procedure FormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
  311.     procedure DoClick(Sender: TObject);
  312.     procedure ClB1Click(Sender: TObject);
  313.     procedure GB1Click(Sender: TObject);
  314.     procedure ZB1Click(Sender: TObject);
  315.     procedure ZB2Click(Sender: TObject);
  316.     procedure PgB1Click(Sender: TObject);
  317.     procedure PgB2Click(Sender: TObject);
  318.     procedure OB2MouseDown(Sender: TObject; Button: TMouseButton;
  319.       Shift: TShiftState; X, Y: Integer);
  320.     procedure OB1Click(Sender: TObject);
  321.     procedure CutBClick(Sender: TObject);
  322.     procedure CopyBClick(Sender: TObject);
  323.     procedure PstBClick(Sender: TObject);
  324.     procedure SelAllBClick(Sender: TObject);
  325.     procedure ExitBClick(Sender: TObject);
  326.     procedure PgB3Click(Sender: TObject);
  327.     procedure FormResize(Sender: TObject);
  328.     procedure N5Click(Sender: TObject);
  329.     procedure N6Click(Sender: TObject);
  330.     procedure GB2Click(Sender: TObject);
  331.     procedure FileBtn1Click(Sender: TObject);
  332.     procedure FileBtn2Click(Sender: TObject);
  333.     procedure FileBtn3Click(Sender: TObject);
  334.     procedure FormShow(Sender: TObject);
  335.     procedure N8Click(Sender: TObject);
  336.     procedure HlB1Click(Sender: TObject);
  337.     procedure FileBtn4Click(Sender: TObject);
  338.     procedure N42Click(Sender: TObject);
  339.     procedure Popup1Popup(Sender: TObject);
  340.     procedure N23Click(Sender: TObject);
  341.     procedure N37Click(Sender: TObject);
  342.     procedure Pan2Click(Sender: TObject);
  343.     procedure N14Click(Sender: TObject);
  344.     procedure Align1Click(Sender: TObject);
  345.     procedure Align2Click(Sender: TObject);
  346.     procedure Align3Click(Sender: TObject);
  347.     procedure Align4Click(Sender: TObject);
  348.     procedure Align5Click(Sender: TObject);
  349.     procedure Align6Click(Sender: TObject);
  350.     procedure Align7Click(Sender: TObject);
  351.     procedure Align8Click(Sender: TObject);
  352.     procedure Align9Click(Sender: TObject);
  353.     procedure Align10Click(Sender: TObject);
  354.     procedure Tab1Change(Sender: TObject);
  355.     procedure N34Click(Sender: TObject);
  356.     procedure GB3Click(Sender: TObject);
  357.     procedure UndoBClick(Sender: TObject);
  358.     procedure RedoBClick(Sender: TObject);
  359.     procedure N20Click(Sender: TObject);
  360.     procedure PBox1Paint(Sender: TObject);
  361.     procedure HelpBtnClick(Sender: TObject);
  362.     procedure N22Click(Sender: TObject);
  363.     procedure Tab1MouseDown(Sender: TObject; Button: TMouseButton;
  364.       Shift: TShiftState; X, Y: Integer);
  365.     procedure frSpeedButton1Click(Sender: TObject);
  366.     procedure StB1Click(Sender: TObject);
  367.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  368.     procedure ScrollBox1Resize(Sender: TObject);
  369.     procedure Tab1DragOver(Sender, Source: TObject; X, Y: Integer;
  370.       State: TDragState; var Accept: Boolean);
  371.     procedure Tab1MouseUp(Sender: TObject; Button: TMouseButton;
  372.       Shift: TShiftState; X, Y: Integer);
  373.     procedure Tab1MouseMove(Sender: TObject; Shift: TShiftState; X,
  374.       Y: Integer);
  375.     procedure Tab1DragDrop(Sender, Source: TObject; X, Y: Integer);
  376.     procedure PgB4Click(Sender: TObject);
  377.     procedure StatusBar1MouseDown(Sender: TObject; Button: TMouseButton;
  378.       Shift: TShiftState; X, Y: Integer);
  379.     procedure StatusBar1DblClick(Sender: TObject);
  380.     procedure C2DblClick(Sender: TObject);
  381.     procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
  382.       Shift: TShiftState; X, Y: Integer);
  383.   private
  384.     { Private declarations }
  385.     PageForm: TForm;
  386.     PageView: TfrDesignerPage;
  387.     InspForm: TfrInspForm;
  388.     ColorSelector: TColorSelector;
  389.     FCurPage: Integer;
  390.     FGridSizeX, FGridSizeY: Integer;
  391.     FGridShow, FGridAlign: Boolean;
  392.     FUnits: TfrReportUnits;
  393.     UndoBuffer: TfrUndoBuffer;
  394.     FirstTime: Boolean;
  395.     fld: Array[0..63] of String;
  396.     EditAfterInsert: Boolean;
  397.     FCurDocName, FCaption: String;
  398.     ShapeMode: TfrShapeMode;
  399.     PagePosition: TAlign;
  400.     FPageType: TfrPageType;
  401.     MDown, ChangeUnits: Boolean;
  402.     UnlimitedHeight: Boolean;
  403.     LastPt: TPoint;
  404.     procedure SetMenuBitmaps;
  405.     procedure SetCurPage(Value: Integer);
  406.     procedure SetGridSize(Value: Integer);
  407.     procedure SetGridShow(Value: Boolean);
  408.     procedure SetGridAlign(Value: Boolean);
  409.     procedure SetUnits(Value: TfrReportUnits);
  410.     procedure SetCurDocName(Value: String);
  411.     procedure SelectionChanged;
  412.     procedure ShowPosition;
  413.     procedure ShowContent;
  414.     procedure EnableControls;
  415.     procedure ResetSelection;
  416.     procedure DeleteObjects;
  417.     procedure AddPage;
  418.     procedure RemovePage(n: Integer);
  419.     procedure SetPageTitles;
  420.     procedure DefMemoEditor(Sender: TObject);
  421.     procedure DefPictureEditor(Sender: TObject);
  422.     procedure DefTagEditor(Sender: TObject);
  423.     procedure DefRestrEditor(Sender: TObject);
  424.     procedure DefHighlightEditor(Sender: TObject);
  425.     procedure DefFieldEditor(Sender: TObject);
  426.     procedure DefDataSourceEditor(Sender: TObject);
  427.     procedure DefCrossDataSourceEditor(Sender: TObject);
  428.     procedure DefGroupEditor(Sender: TObject);
  429.     procedure DefFontEditor(Sender: TObject);
  430.     procedure FillInspFields;
  431.     function RectTypEnabled: Boolean;
  432.     function FontTypEnabled: Boolean;
  433.     function ZEnabled: Boolean;
  434.     function CutEnabled: Boolean;
  435.     function CopyEnabled: Boolean;
  436.     function PasteEnabled: Boolean;
  437.     function DelEnabled: Boolean;
  438.     function EditEnabled: Boolean;
  439.     procedure ColorSelected(Sender: TObject);
  440.     procedure MoveObjects(dx, dy: Integer; Resize: Boolean);
  441.     procedure SelectAll;
  442.     procedure Unselect;
  443.     procedure NumberOfSelected;
  444.     procedure CutToClipboard;
  445.     procedure CopyToClipboard;
  446.     procedure SaveState;
  447.     procedure RestoreState;
  448.     procedure Undo;
  449.     procedure Redo;
  450.     procedure AddUndo;
  451.     procedure AddRedo;
  452.     procedure ClearUndo;
  453.     procedure ClearRedo;
  454.     procedure InsFieldsClick(Sender: TObject);
  455.     procedure SetMenuItemBitmap(AMenuItem: TMenuItem; ABtn: TToolButton);
  456.     function SelStatus: TfrSelectionStatus;
  457.     procedure OnModify(Item: Integer);
  458.     procedure PageFormCloseQuery(Sender: TObject; var CanClose: Boolean);
  459.     procedure PageFormResize(Sender: TObject);
  460.     procedure PageFormKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);
  461.     function BeforeEdit: Boolean;
  462.     procedure AfterEdit;
  463.     procedure DoEdit(ClassRef: TClass);
  464.     procedure ShowFieldsDialog(Show: Boolean);
  465.     procedure HeightChanged(Sender: TObject);
  466.     procedure NotifyParentBands(OldName, NewName: String);
  467.     procedure NotifySubReports(OldIndex, NewIndex: Integer);
  468.     procedure InspSelectionChanged(ObjName: String);
  469.     procedure InspGetObjects(List: TStrings);
  470.     procedure AssignDefEditors;
  471.     procedure Localize;
  472.     procedure GetDefaultSize(var dx, dy: Integer);
  473.     procedure FormMouseWheelUp(Sender: TObject; Shift: TShiftState;
  474.       MousePos: TPoint; var Handled: Boolean);
  475.     procedure FormMouseWheelDown(Sender: TObject; Shift: TShiftState;
  476.       MousePos: TPoint; var Handled: Boolean);
  477.   public
  478.     { Public declarations }
  479.     function GetModified: Boolean; override;
  480.     procedure SetModified(Value: Boolean); override;
  481.     procedure RegisterObject(ButtonBmp: TBitmap; ButtonHint: String;
  482.       ButtonTag: Integer; IsControl: Boolean);
  483.     procedure RegisterTool(MenuCaption: String; ButtonBmp: TBitmap;
  484.       OnClick: TNotifyEvent);
  485.     procedure BeforeChange; override;
  486.     procedure AfterChange; override;
  487.     procedure SelectObject(ObjName: String); override;
  488.     function InsertDBField: String; override;
  489.     function InsertExpression: String; override;
  490.     procedure ShowMemoEditor(Sender: TObject);
  491.     procedure ShowEditor;
  492.     procedure RedrawPage; override;
  493.     function PointsToUnits(x: Double): Double;
  494.     function UnitsToPoints(x: Double): Double;
  495.     property CurDocName: String read FCurDocName write SetCurDocName;
  496.     property CurPage: Integer read FCurPage write SetCurPage;
  497.     property GridSizeX: Integer read FGridSizeX write SetGridSize;
  498.     property GridSizeY: Integer read FGridSizeY write SetGridSize;
  499.     property ShowGrid: Boolean read FGridShow write SetGridShow;
  500.     property GridAlign: Boolean read FGridAlign write SetGridAlign;
  501.     property Units: TfrReportUnits read FUnits write SetUnits;
  502.     property PageType: TfrPageType read FPageType;
  503.   end;
  504.  
  505.  
  506. function frCheckBand(b: TfrBandType): Boolean;
  507.  
  508. var
  509.   frTemplateDir: String;
  510.   DesignerRestrictions: TfrDesignerRestrictions;
  511.  
  512.  
  513. implementation
  514.  
  515. {$R *.xfm}
  516. {$R *.res}
  517.  
  518. uses
  519.   FR_Pgopt, FR_GEdit, FR_Edit, FR_Templ, FR_Newrp, FR_DsOpt, FR_Const,
  520.   FR_AttrE, FR_Prntr, FR_Hilit, FR_Dopt, FR_Dict, FR_BndEd, FR_VBnd, FR_Flds,
  521.   FR_BTyp, FR_Utils, FR_GrpEd, FR_About, FR_IFlds, FR_Pars, FR_DBRel,
  522.   FR_Restr, FR_DBSet, FR_PageF, FR_Expr, FR_Funcs, Variants, Qt;
  523.  
  524. type
  525.   THackView = class(TfrView)
  526.   end;
  527.  
  528. var
  529.   FirstSelected: TfrView;
  530.   SelNum: Integer;               // number of objects currently selected
  531.   MRFlag,                        // several objects was selected
  532.   ObjRepeat,                     // was pressed Shift + Insert Object
  533.   WasOk: Boolean;                // was Ok pressed in dialog
  534.   OldRect, OldRect1: TRect;      // object rect after mouse was clicked
  535.   Busy: Boolean;                 // busy flag. need!
  536.   ShowSizes: Boolean;
  537.   LastFontName: String;
  538.   LastFontSize, LastAlignment: Integer;
  539.   LastFrameWidth, LastLineWidth: Single;
  540.   LastFrameTyp, LastFontStyle: Word;
  541.   LastCharset: TFontCharset;
  542.   LastFrameColor, LastFillColor, LastFontColor: TColor;
  543.   ClrButton: TToolButton;
  544.   FirstChange: Boolean;
  545.   DesignerComp: TfrDesigner;
  546.   InspBusy: Boolean;
  547.  
  548. // globals
  549.   ClipBd: TList;                 // clipboard
  550.   GridBitmap: TBitmap;           // for drawing grid in design time
  551.  
  552.  
  553. {----------------------------------------------------------------------------}
  554. // miscellaneous routines
  555. function Objects: TList;
  556. begin
  557.   Result := frDesigner.Page.Objects;
  558. end;
  559.  
  560. function TopSelected: Integer;
  561. var
  562.   i: Integer;
  563. begin
  564.   Result := Objects.Count - 1;
  565.   for i := Objects.Count - 1 downto 0 do
  566.     if TfrView(Objects[i]).Selected then
  567.     begin
  568.       Result := i;
  569.       break;
  570.     end;
  571. end;
  572.  
  573. function frCheckBand(b: TfrBandType): Boolean;
  574. var
  575.   i: Integer;
  576.   t: TfrView;
  577. begin
  578.   Result := False;
  579.   for i := 0 to Objects.Count - 1 do
  580.   begin
  581.     t := Objects[i];
  582.     if t.Typ = gtBand then
  583.       if b = TfrBandType(t.FrameTyp) then
  584.       begin
  585.         Result := True;
  586.         break;
  587.       end;
  588.   end;
  589. end;
  590.  
  591. function GetUnusedBand: TfrBandType;
  592. var
  593.   b: TfrBandType;
  594. begin
  595.   Result := btNone;
  596.   for b := btReportTitle to btNone do
  597.     if not frCheckBand(b) then
  598.     begin
  599.       Result := b;
  600.       break;
  601.     end;
  602.   if Result = btNone then Result := btMasterData;
  603. end;
  604.  
  605. procedure SendBandsToDown;
  606. var
  607.   i, j, n, k: Integer;
  608.   t: TfrView;
  609. begin
  610.   n := Objects.Count; j := 0; i := n - 1;
  611.   k := 0;
  612.   while j < n do
  613.   begin
  614.     t := Objects[i];
  615.     if t.Typ = gtBand then
  616.     begin
  617.       Objects.Delete(i);
  618.       Objects.Insert(0, t);
  619.       Inc(k);
  620.     end
  621.     else
  622.       Dec(i);
  623.     Inc(j);
  624.   end;
  625.   for i := 0 to n - 1 do // sends btOverlay to back
  626.   begin
  627.     t := Objects[i];
  628.     if (t.Typ = gtBand) and (t.FrameTyp = Integer(btOverlay)) then
  629.     begin
  630.       Objects.Delete(i);
  631.       Objects.Insert(0, t);
  632.       break;
  633.     end;
  634.   end;
  635.   i := 0; j := 0;
  636.   while j < n do // sends btCrossXXX to front
  637.   begin
  638.     t := Objects[i];
  639.     if (t.Typ = gtBand) and
  640.        (TfrBandType(t.FrameTyp) in [btCrossHeader..btCrossFooter]) then
  641.     begin
  642.       Objects.Delete(i);
  643.       Objects.Insert(k - 1, t);
  644.     end
  645.     else Inc(i);
  646.     Inc(j);
  647.   end;
  648. end;
  649.  
  650. procedure ClearClipBoard;
  651. var
  652.   m: TMemoryStream;
  653. begin
  654.   if Assigned(ClipBd) then
  655.     with ClipBd do
  656.     while Count > 0 do
  657.     begin
  658.       m := Items[0];
  659.       m.Free;
  660.       Delete(0);
  661.     end;
  662. end;
  663.  
  664. function IsBandsSelect(var Value: TfrView): Boolean;
  665. var
  666.   i: Integer;
  667. begin
  668.   Result := False;
  669.   Value := nil;
  670.   for i := 0 to Objects.Count - 1 do
  671.   begin
  672.     Value := Objects[i];
  673.     if Value.Selected and (Value.Typ = gtBand) then
  674.     begin
  675.       Result := True;
  676.       break;
  677.     end;
  678.   end;
  679. end;
  680.  
  681.  
  682. {----------------------------------------------------------------------------}
  683. constructor TfrDesigner.Create(AOwner: TComponent);
  684. begin
  685.   if Assigned(DesignerComp) then
  686.     raise Exception.Create('You already have one TfrDesigner component');
  687.   inherited Create(AOwner);
  688.   FCloseQuery := True;
  689.   DesignerComp := Self;
  690.   HideDisabledButtons := True;
  691. end;
  692.  
  693. destructor TfrDesigner.Destroy;
  694. begin
  695.   DesignerComp := nil;
  696.   inherited Destroy;
  697. end;
  698.  
  699.  
  700. {--------------------------------------------------}
  701. constructor TfrDesignerPage.Create(AOwner: TComponent);
  702. begin
  703.   inherited Create(AOwner);
  704.   Parent := AOwner as TWinControl;
  705.   BevelInner := bvNone;
  706.   BevelOuter := bvNone;
  707.   Color  := clWhite;
  708.   BorderStyle := bsNone;
  709.   OnMouseDown := MDown;
  710.   OnMouseUp := MUp;
  711.   OnMouseMove := MMove;
  712.   OnDblClick := DClick;
  713.   OnDragOver := DoDragOver;
  714.   OnDragDrop := DoDragDrop;
  715. end;
  716.  
  717. procedure TfrDesignerPage.Init;
  718. begin
  719.   Down := False; DFlag := False; RFlag := False;
  720.   Cursor := crDefault; CT := ctNone;
  721. end;
  722.  
  723. procedure TfrDesignerPage.SetPage;
  724. var
  725.   Pgw, Pgh, Pgl, Pgt: Integer;
  726. begin
  727.   Pgw := FDesigner.Page.PrnInfo.Pgw;
  728.   Pgh := FDesigner.Page.PrnInfo.Pgh;
  729.   if FDesigner.UnlimitedHeight then
  730.     Pgh := Pgh * 3;
  731.   Pgt := 10;
  732.   if (Pgw > Parent.Width) or (FDesigner.PagePosition = alLeft) then
  733.     Pgl := 10
  734.   else if FDesigner.PagePosition = alClient then
  735.     Pgl := (Parent.ClientWidth - Pgw) div 2
  736.   else
  737.     Pgl := Parent.ClientWidth - Pgw - 16;
  738.  
  739.  
  740.   Align := alNone;
  741.   if (FDesigner.PageType = ptDialog) and (FDesigner.PageForm <> nil) then
  742.     SetBounds(0, 0, FDesigner.PageForm.ClientWidth, FDesigner.PageForm.ClientHeight)
  743.   else
  744.   begin
  745.     SetBounds(Pgl, Pgt, Pgw, Pgh);
  746.     TScrollBox(Parent).VertScrollBar.Range := Top + Height + 10;
  747.     TScrollBox(Parent).HorzScrollBar.Range := Left + Width + 10;
  748.   end;
  749. end;
  750.  
  751. procedure TfrDesignerPage.Paint;
  752. begin
  753.   Draw(10000);
  754. end;
  755.  
  756. procedure TfrDesignerPage.NormalizeCoord(t: TfrView);
  757. begin
  758.   if t.dx < 0 then
  759.   begin
  760.     t.dx := -t.dx;
  761.     t.x := t.x - t.dx;
  762.   end;
  763.   if t.dy < 0 then
  764.   begin
  765.     t.dy := -t.dy;
  766.     t.y := t.y - t.dy;
  767.   end;
  768. end;
  769.  
  770. procedure TfrDesignerPage.NormalizeRect(var r: TRect);
  771. var
  772.   i: Integer;
  773. begin
  774.   with r do
  775.   begin
  776.     if Left > Right then begin i := Left; Left := Right; Right := i end;
  777.     if Top > Bottom then begin i := Top; Top := Bottom; Bottom := i end;
  778.   end;
  779. end;
  780.  
  781. procedure TfrDesignerPage.DrawHSplitter(Rect: TRect);
  782. begin
  783.   with Canvas do
  784.   begin
  785.     Pen.Mode := pmXor;
  786.     Pen.Color := clSilver;
  787.     Pen.Width := 1;
  788.     MoveTo(Rect.Left, Rect.Top);
  789.     LineTo(Rect.Right, Rect.Bottom);
  790.     Pen.Mode := pmCopy;
  791.   end;
  792. end;
  793.  
  794. procedure TfrDesignerPage.DrawRectLine(Rect: TRect);
  795. begin
  796.   with Canvas do
  797.   begin
  798.     Pen.Mode := pmNot;
  799.     Pen.Style := psSolid;
  800.     Pen.Width := Round(LastLineWidth);
  801.     with Rect do
  802.       if Abs(Right - Left) > Abs(Bottom - Top) then
  803.       begin
  804.         MoveTo(Left, Top);
  805.         LineTo(Right, Top);
  806.       end
  807.       else
  808.       begin
  809.         MoveTo(Left, Top);
  810.         LineTo(Left, Bottom);
  811.       end;
  812.     Pen.Mode := pmCopy;
  813.   end;
  814. end;
  815.  
  816. procedure TfrDesignerPage.DrawFocusRect(Rect: TRect);
  817. begin
  818.   with Canvas do
  819.   begin
  820.     Pen.Mode := pmXor;
  821.     Pen.Color := clSilver;
  822.     Pen.Width := 1;
  823.     Pen.Style := psSolid;
  824.     Brush.Style := bsClear;
  825.     if (Rect.Right = Rect.Left + 1) or (Rect.Bottom = Rect.Top + 1) then
  826.     begin
  827.       if Rect.Right = Rect.Left + 1 then
  828.         Dec(Rect.Right, 1) else
  829.         Dec(Rect.Bottom, 1);
  830.       MoveTo(Rect.Left, Rect.Top);
  831.       LineTo(Rect.Right, Rect.Bottom);
  832.     end
  833.     else
  834.       Rectangle(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
  835.     Pen.Mode := pmCopy;
  836.     Brush.Style := bsSolid;
  837.   end;
  838. end;
  839.  
  840. procedure TfrDesignerPage.DrawSelection(t: TfrView);
  841. var
  842.   px, py: Word;
  843.  
  844.   procedure Draw_Point(x, y: Word);
  845.   var
  846.     i: Integer;
  847.   begin
  848.     for i := 0 to 4 do
  849.     begin
  850.       Canvas.MoveTo(x - 2, y - 2 + i);
  851.       Canvas.LineTo(x + 2, y - 2 + i);
  852.     end;
  853.   end;
  854.  
  855. begin
  856.   if t.Selected then
  857.   with t, Canvas do
  858.   begin
  859.     Pen.Width := 1;
  860.     Pen.Mode := pmXor;
  861.     Pen.Color := clWhite;
  862.     px := x + dx div 2;
  863.     py := y + dy div 2;
  864.     Draw_Point(x, y);
  865.     if (dx <> 0) and (dy <> 0) then
  866.     begin
  867.       Draw_Point(x + dx, y);
  868.       Draw_Point(x, y + dy);
  869.     end;
  870.     if Objects.IndexOf(t) = RightBottom then
  871.       Pen.Color := clTeal;
  872.     Draw_Point(x + dx, y + dy);
  873.     Pen.Color := clWhite;
  874.     if (SelNum = 1) and (dx <> 0) and (dy <> 0) then
  875.     begin
  876.       Draw_Point(px, y); Draw_Point(px, y + dy);
  877.       Draw_Point(x, py); Draw_Point(x + dx, py);
  878.     end;
  879.     Pen.Mode := pmCopy;
  880.   end;
  881. end;
  882.  
  883. procedure TfrDesignerPage.DrawShape(t: TfrView);
  884. begin
  885.   with t do
  886.     if Selected then
  887.       DrawFocusRect(Rect(x, y, x + dx + 1, y + dy + 1))
  888. end;
  889.  
  890. procedure TfrDesignerPage.Draw(N: Integer{; ClipRgn: frHRGN});
  891. var
  892.   i: Integer;
  893.   t: TfrView;
  894.   Objects: TList;
  895.   c: TColor;
  896.   Bmp, Bmp1: TBitmap;
  897.   r1, r2, r3: frHRGN;
  898.  
  899.   procedure DrawBackground;
  900.   var
  901.     i, j: Integer;
  902.   begin
  903.     with Canvas do
  904.     begin
  905.       c := clBlack;
  906.       if FDesigner.ShowGrid and (FDesigner.GridSizeX <> 18) then
  907.       begin
  908.         with GridBitmap.Canvas do
  909.         begin
  910.           if FDesigner.PageType = ptDialog then
  911.             Brush.Color := FDesigner.Page.Color else
  912.             Brush.Color := clWhite;
  913.           FillRect(Rect(0, 0, 8, 8));
  914.           Pen.Color := c;
  915.           DrawPoint(0, 0);
  916.           if FDesigner.GridSizeX = 4 then
  917.           begin
  918.             DrawPoint(4, 0);
  919.             DrawPoint(0, 4);
  920.             DrawPoint(4, 4);
  921.           end;
  922.         end;
  923.         Brush.Bitmap := GridBitmap;
  924.       end
  925.       else
  926.       begin
  927.         if FDesigner.PageType = ptDialog then
  928.           Brush.Color := FDesigner.Page.Color else
  929.           Brush.Color := clWhite;
  930.         Brush.Style := bsSolid;
  931.       end;
  932.       FillRect(Rect(0, 0, Width, Height));
  933.       Pen.Color := c;
  934.       if FDesigner.ShowGrid and (FDesigner.GridSizeX = 18) then
  935.       begin
  936.         i := 0;
  937.         while i < Width do
  938.         begin
  939.           j := 0;
  940.           while j < Height do
  941.           begin
  942.             if frRectVisible(Handle, Rect(i, j, i + 1, j + 1)) then
  943.               DrawPoint(i, j);
  944.             Inc(j, FDesigner.GridSizeY);
  945.           end;
  946.           Inc(i, FDesigner.GridSizeX);
  947.         end;
  948.       end;
  949.     end;
  950.   end;
  951.  
  952.   procedure DrawMargins;
  953.   var
  954.     i, j: Integer;
  955.   begin
  956.     with Canvas do
  957.     begin
  958.       Brush.Style := bsClear;
  959.       Pen.Width := 1;
  960.       Pen.Color := clGray;
  961.       Pen.Style := psSolid;
  962.       Pen.Mode := pmCopy;
  963.       if FDesigner.PageType = ptReport then
  964.         with FDesigner.Page do
  965.         begin
  966.           if UseMargins then
  967.             Rectangle(LeftMargin, TopMargin, RightMargin, BottomMargin);
  968.           if ColCount > 1 then
  969.           begin
  970.             ColWidth := (RightMargin - LeftMargin -
  971.               ((ColCount - 1) * ColGap)) div ColCount;
  972.             Pen.Style := psDot;
  973.             j := LeftMargin;
  974.             for i := 1 to ColCount do
  975.             begin
  976.               Rectangle(j, -1, j + ColWidth + 1,  PrnInfo.Pgh + 1);
  977.               Inc(j, ColWidth + ColGap);
  978.             end;
  979.             Pen.Style := psSolid;
  980.           end;
  981.         end;
  982.       Brush.Style := bsSolid;
  983.     end;
  984.   end;
  985.  
  986.   procedure DrawObject(t: TfrView; Canvas: TCanvas);
  987.   begin
  988.     t.Draw(Canvas);
  989.     if t.Script.Count > 0 then
  990.       Canvas.Draw(t.x + 1, t.y + 1, Bmp);
  991.     if (t is TfrMemoView) and (TfrMemoView(t).HighlightStr <> '') then
  992.       Canvas.Draw(t.x + 1, t.y + 10, Bmp1);
  993.   end;
  994.  
  995. begin
  996.   if (FDesigner.Page = nil) or DisableDraw then Exit;
  997.   Bmp := TBitmap.Create;
  998.   Bmp.LoadFromResourceName(hInstance, 'FR_SCRIPT');
  999.   Bmp1 := TBitmap.Create;
  1000.   Bmp1.LoadFromResourceName(hInstance, 'FR_HIGHLIGHT');
  1001.   DocMode := dmDesigning;
  1002.   Objects := FDesigner.Page.Objects;
  1003.  
  1004.   Canvas.Start;
  1005.   r1 := frCreateRectRgn(0, 0, Width, Height);
  1006.   frSetClipRgn(Canvas.Handle, r1);
  1007.   r3 := frCreateRectRgn(0, 0, Width, Height);
  1008.  
  1009.   for i := Objects.Count - 1 downto 0 do
  1010.   begin
  1011.     t := Objects[i];
  1012.     DrawObject(t, Canvas);
  1013.     r2 := t.GetClipRgn(rtNormal);
  1014.     frExcludeClipRgn(Canvas.Handle, r2);
  1015.     frDeleteRgn(r2);
  1016.   end;
  1017.  
  1018.   DrawBackground;
  1019.   Canvas.Stop;
  1020.   frDeleteRgn(r1);
  1021.   frDeleteRgn(r3);
  1022.   DrawMargins;
  1023.  
  1024. {  DrawBackground;
  1025.   for i := 0 to Objects.Count - 1 do
  1026.   begin
  1027.     frSetTextCharacterExtra(Canvas.Handle, 0);
  1028.     t := Objects[i];
  1029.     DrawObject(t, Canvas);
  1030.     frSetTextCharacterExtra(Canvas.Handle, 0);
  1031.   end;
  1032.   DrawMargins;}
  1033.  
  1034.  
  1035.  
  1036.  
  1037.   if not Down then
  1038.     DrawPage(dmSelection);
  1039.   Bmp.Free;
  1040.   Bmp1.Free;
  1041. end;
  1042.  
  1043. procedure TfrDesignerPage.DrawPage(DrawMode: TfrDesignerDrawMode);
  1044. var
  1045.   i: Integer;
  1046.   t: TfrView;
  1047. begin
  1048.   if DocMode <> dmDesigning then Exit;
  1049.   for i := 0 to Objects.Count - 1 do
  1050.   begin
  1051.     t := Objects[i];
  1052.     case DrawMode of
  1053.       dmAll: t.Draw(Canvas);
  1054.       dmSelection: DrawSelection(t);
  1055.       dmShape: DrawShape(t);
  1056.     end;
  1057.   end;
  1058. end;
  1059.  
  1060. function TfrDesignerPage.FindNearestEdge(var x, y: Integer): Boolean;
  1061. var
  1062.   i: Integer;
  1063.   t: TfrView;
  1064.   min: Double;
  1065.   p: TPoint;
  1066.   function DoMin(a: Array of TPoint): Boolean;
  1067.   var
  1068.     i: Integer;
  1069.     d: Double;
  1070.   begin
  1071.     Result := False;
  1072.     for i := Low(a) to High(a) do
  1073.     begin
  1074.       d := sqrt((x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y));
  1075.       if d < min then
  1076.       begin
  1077.         min := d;
  1078.         p := a[i];
  1079.         Result := True;
  1080.       end;
  1081.     end;
  1082.   end;
  1083. begin
  1084.   Result := False;
  1085.   min := FDesigner.GridSizeX;
  1086.   p := Point(x, y);
  1087.   for i := 0 to Objects.Count - 1 do
  1088.   begin
  1089.     t := Objects[i];
  1090.     if DoMin([Point(t.x, t.y), Point(t.x + t.dx, t.y),
  1091.          Point(t.x + t.dx, t.y + t.dy),  Point(t.x, t.y + t.dy)]) then
  1092.       Result := True;
  1093.   end;
  1094.   x := p.x; y := p.y;
  1095. end;
  1096.  
  1097. procedure TfrDesignerPage.RoundCoord(var x, y: Integer);
  1098. begin
  1099.   with FDesigner do
  1100.     if GridAlign then
  1101.     begin
  1102.       x := x div GridSizeX * GridSizeX;
  1103.       y := y div GridSizeY * GridSizeY;
  1104.     end;
  1105. end;
  1106.  
  1107. procedure TfrDesignerPage.GetMultipleSelected;
  1108. var
  1109.   i, j, k: Integer;
  1110.   t: TfrView;
  1111. begin
  1112.   j := 0; k := 0;
  1113.   LeftTop := Point(10000, 10000);
  1114.   RightBottom := -1;
  1115.   MRFlag := False;
  1116.   if SelNum > 1 then                  {find right-bottom element}
  1117.   begin
  1118.     for i := 0 to Objects.Count-1 do
  1119.     begin
  1120.       t := Objects[i];
  1121.       if t.Selected then
  1122.       begin
  1123.         t.OriginalRect := Rect(t.x, t.y, t.dx, t.dy);
  1124.         if (t.x + t.dx > j) or ((t.x + t.dx = j) and (t.y + t.dy > k)) then
  1125.         begin
  1126.           j := t.x + t.dx;
  1127.           k := t.y + t.dy;
  1128.           RightBottom := i;
  1129.         end;
  1130.         if t.x < LeftTop.x then LeftTop.x := t.x;
  1131.         if t.y < LeftTop.y then LeftTop.y := t.y;
  1132.       end;
  1133.     end;
  1134.     t := Objects[RightBottom];
  1135.     OldRect := Rect(LeftTop.x, LeftTop.y, t.x + t.dx, t.y + t.dy);
  1136.     OldRect1 := OldRect;
  1137.     MRFlag := True;
  1138.   end;
  1139. end;
  1140.  
  1141. procedure TfrDesignerPage.MDown(Sender: TObject; Button: TMouseButton;
  1142.   Shift: TShiftState; X, Y: Integer);
  1143. var
  1144.   i: Integer;
  1145.   f, v: Boolean;
  1146.   t: TfrView;
  1147.   p: TPoint;
  1148.   Rgn: frHRGN;
  1149. begin
  1150.   WasCtrl := ssCtrl in Shift;
  1151.   if DFlag then
  1152.   begin
  1153.     DFlag := False;
  1154.     Exit;
  1155.   end;
  1156.   if (Button = mbRight) and Down and RFlag then
  1157.     DrawFocusRect(OldRect);
  1158.   RFlag := False;
  1159.   DrawPage(dmSelection);
  1160.   Down := True;
  1161.   if Button = mbLeft then
  1162.     if (ssCtrl in Shift) or (Cursor = crCross) then
  1163.     begin
  1164.       RFlag := True;
  1165.       if Cursor = crCross then
  1166.       begin
  1167.         if FDesigner.PageType = ptReport then
  1168.           DrawFocusRect(OldRect);
  1169.         RoundCoord(x, y);
  1170.         OldRect1 := OldRect;
  1171.       end;
  1172.       OldRect := Rect(x, y, x, y);
  1173.       FDesigner.Unselect;
  1174.       SelNum := 0;
  1175.       RightBottom := -1;
  1176.       MRFlag := False;
  1177.       FirstSelected := nil;
  1178.       Exit;
  1179.     end
  1180.     else if Cursor = crPencil then
  1181.     begin
  1182.       with FDesigner do
  1183.       if GridAlign then
  1184.         if not FindNearestEdge(x, y) then
  1185.         begin
  1186.           x := Round(x / GridSizeX) * GridSizeX;
  1187.           y := Round(y / GridSizeY) * GridSizeY;
  1188.         end;
  1189.       OldRect := Rect(x, y, x, y);
  1190.       FDesigner.Unselect;
  1191.       SelNum := 0;
  1192.       RightBottom := -1;
  1193.       MRFlag := False;
  1194.       FirstSelected := nil;
  1195.       LastX := x;
  1196.       LastY := y;
  1197.       Exit;
  1198.     end;
  1199.   if Cursor = crDefault then
  1200.   begin
  1201.     f := False;
  1202.     for i := Objects.Count - 1 downto 0 do
  1203.     begin
  1204.       t := Objects[i];
  1205.       Rgn := t.GetClipRgn(rtNormal);
  1206.       v := frPtInRegion(Rgn, X, Y);
  1207.       frDeleteRgn(Rgn);
  1208. //      v := (x >= t.x) and (x < t.x + t.dx) and (y >= t.y) and (y < t.y + t.dy);
  1209.  
  1210.       if v then
  1211.       begin
  1212.         if ssShift in Shift then
  1213.         begin
  1214.           t.Selected := not t.Selected;
  1215.           if t.Selected then Inc(SelNum) else Dec(SelNum);
  1216.         end
  1217.         else if not t.Selected then
  1218.         begin
  1219.           FDesigner.Unselect;
  1220.           SelNum := 1;
  1221.           t.Selected := True;
  1222.         end;
  1223.         if SelNum = 0 then FirstSelected := nil
  1224.         else if SelNum = 1 then FirstSelected := t
  1225.         else if FirstSelected <> nil then
  1226.           if not FirstSelected.Selected then FirstSelected := nil;
  1227.         f := True;
  1228.         break;
  1229.       end;
  1230.     end;
  1231.     if not f then
  1232.     begin
  1233.       FDesigner.Unselect;
  1234.       SelNum := 0;
  1235.       FirstSelected := nil;
  1236.       if Button = mbLeft then
  1237.       begin
  1238.         RFlag := True;
  1239.         OldRect := Rect(x, y, x, y);
  1240.         Exit;
  1241.       end;
  1242.     end;
  1243.     GetMultipleSelected;
  1244.   end;
  1245.   if SelNum = 0 then
  1246.   begin // reset multiple selection
  1247.     RightBottom := -1;
  1248.     MRFlag := False;
  1249.   end;
  1250.   LastX := x;
  1251.   LastY := y;
  1252.   Moved := False;
  1253.   FirstChange := True;
  1254.   FirstBandMove := True;
  1255.   if Button = mbRight then
  1256.   begin
  1257.     DrawPage(dmSelection);
  1258.     Down := False;
  1259.     GetCursorPos(p);
  1260.     FDesigner.SelectionChanged;
  1261.     FDesigner.Popup1Popup(nil);
  1262.     FDesigner.Popup1.Popup(p.X, p.Y);
  1263.   end
  1264.   else if FDesigner.ShapeMode = smFrame then
  1265.     DrawPage(dmShape);
  1266. end;
  1267.  
  1268. procedure TfrDesignerPage.MUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState;
  1269.   X, Y: Integer);
  1270. var
  1271.   i, k, dx, dy: Integer;
  1272.   t: TfrView;
  1273.   ObjectInserted: Boolean;
  1274.  
  1275.   procedure AddObject(ot: Byte);
  1276.   begin
  1277.     Objects.Add(frCreateObject(ot, ''));
  1278.     t := Objects.Last;
  1279.   end;
  1280.  
  1281.   procedure CreateSection;
  1282.   var
  1283.     s: String;
  1284.     frBandTypesForm: TfrBandTypesForm;
  1285.  
  1286.     function IsSubreport(PageN: Integer): Boolean;
  1287.     var
  1288.       i, j: Integer;
  1289.       t: TfrView;
  1290.     begin
  1291.       Result := False;
  1292.       with CurReport do
  1293.         for i := 0 to Pages.Count - 1 do
  1294.           for j := 0 to Pages[i].Objects.Count - 1 do
  1295.           begin
  1296.             t := Pages[i].Objects[j];
  1297.             if t.Typ = gtSubReport then
  1298.               if TfrSubReportView(t).SubPage = PageN then
  1299.               begin
  1300.                 Result := True;
  1301.                 Exit;
  1302.               end;
  1303.           end;
  1304.     end;
  1305.  
  1306.   begin
  1307.     frBandTypesForm := TfrBandTypesForm.Create(nil);
  1308.     frBandTypesForm.IsSubreport := IsSubreport(FDesigner.CurPage);
  1309.     ObjectInserted := frBandTypesForm.ShowModal = mrOk;
  1310.     if ObjectInserted then
  1311.     begin
  1312.       Objects.Add(TfrBandView.Create);
  1313.       t := Objects.Last;
  1314.       (t as TfrBandView).BandType := frBandTypesForm.SelectedTyp;
  1315.       s := frBandNames[Integer(frBandTypesForm.SelectedTyp)];
  1316.       if Pos(' ', s) <> 0 then
  1317.       begin
  1318.         s[Pos(' ', s) + 1] := UpCase(s[Pos(' ', s) + 1]);
  1319.         Delete(s, Pos(' ', s), 1);
  1320.       end;
  1321.       THackView(t).BaseName := s;
  1322.       SendBandsToDown;
  1323.     end;
  1324.     frBandTypesForm.Free;
  1325.   end;
  1326.  
  1327.   procedure CreateSubReport;
  1328.   begin
  1329.     Objects.Add(TfrSubReportView.Create);
  1330.     t := Objects.Last;
  1331.     (t as TfrSubReportView).SubPage := CurReport.Pages.Count;
  1332.     CurReport.Pages.Add;
  1333.   end;
  1334.  
  1335. begin
  1336.   if Button <> mbLeft then Exit;
  1337.   Down := False;
  1338.   if FDesigner.ShapeMode = smFrame then
  1339.     DrawPage(dmShape);
  1340. // inserting a new object
  1341.   if Cursor = crCross then
  1342.   begin
  1343.     Mode := mdSelect;
  1344.     if FDesigner.PageType = ptReport then
  1345.     begin
  1346.       DrawFocusRect(OldRect);
  1347.       if (OldRect.Left = OldRect.Right) and (OldRect.Top = OldRect.Bottom) then
  1348.         OldRect := OldRect1;
  1349.     end;
  1350.     NormalizeRect(OldRect);
  1351.     RFlag := False;
  1352.     if DesignerRestrictions * [frdrDontCreateObj] = [] then
  1353.     begin
  1354.       ObjectInserted := True;
  1355.       FDesigner.AddUndo;
  1356.       with FDesigner.ToolBar4 do
  1357.       for i := 0 to ControlCount - 1 do
  1358.         if Controls[i] is TToolButton then
  1359.         with Controls[i] as TToolButton do
  1360.           if Down then
  1361.           begin
  1362.             if Tag = gtBand then
  1363.               if GetUnusedBand <> btNone then
  1364.                 CreateSection else
  1365.                 Exit
  1366.             else if Tag = gtSubReport then
  1367.               CreateSubReport
  1368.             else if Tag >= gtAddIn then
  1369.             begin
  1370.               k := Tag - gtAddIn;
  1371.               Objects.Add(frCreateObject(gtAddIn, frAddIns[k].ClassRef.ClassName));
  1372.               t := Objects.Last;
  1373.             end
  1374.             else
  1375.               AddObject(Tag);
  1376.             break;
  1377.           end;
  1378.     end
  1379.     else
  1380.       ObjectInserted := False;
  1381.     if ObjectInserted then
  1382.     begin
  1383.       t.CreateUniqueName;
  1384.       if t is TfrSubReportView then
  1385.         FDesigner.SetPageTitles;
  1386.       with OldRect do
  1387.         if (Left = Right) or (Top = Bottom) then
  1388.         begin
  1389.           dx := 36; dy := 36;
  1390.           if t is TfrMemoView then
  1391.             FDesigner.GetDefaultSize(dx, dy)
  1392.           else if FDesigner.PageType = ptDialog then
  1393.           begin
  1394.             dx := t.dx;
  1395.             dy := t.dy;
  1396.           end;
  1397.           OldRect := Rect(Left, Top, Left + dx, Top + dy);
  1398.         end;
  1399.       FDesigner.Unselect;
  1400.       t.x := OldRect.Left; t.y := OldRect.Top;
  1401.       t.dx := OldRect.Right - OldRect.Left; t.dy := OldRect.Bottom - OldRect.Top;
  1402.       if (t is TfrBandView) and
  1403.          (TfrBandType(t.FrameTyp) in [btCrossHeader..btCrossFooter]) and
  1404.          (t.dx > Width - 10) then
  1405.          t.dx := 40;
  1406.       if t.Typ <> gtAddIn then
  1407.         t.FrameWidth := LastFrameWidth;
  1408.       t.FrameColor := LastFrameColor;
  1409.       t.FillColor := LastFillColor;
  1410.       t.Selected := True;
  1411.       if t is TfrMemoView then
  1412.         with t as TfrMemoView do
  1413.         begin
  1414.           FrameTyp := LastFrameTyp;
  1415.           Font.Name := LastFontName;
  1416.           Font.Size := LastFontSize;
  1417.           Font.Color := LastFontColor;
  1418.           Font.Style := frSetFontStyle(LastFontStyle);
  1419.           Font.Charset := LastCharset;
  1420.           Alignment := LastAlignment;
  1421.         end;
  1422.       SelNum := 1;
  1423.       if t.Typ = gtBand then
  1424.         Draw(10000{, t.GetClipRgn(rtExtended)})
  1425.       else
  1426.       begin
  1427.         t.Draw(Canvas);
  1428.         DrawSelection(t);
  1429.       end;
  1430.       with FDesigner do
  1431.       begin
  1432.         SelectionChanged;
  1433.         if EditAfterInsert and not FDrag and not (t is TfrControl) then
  1434.           ShowEditor;
  1435.       end;
  1436.     end;
  1437.     if not ObjRepeat then
  1438.       FDesigner.OB1.Down := True else
  1439.       DrawFocusRect(OldRect);
  1440.     Exit;
  1441.   end;
  1442. // line drawing
  1443.   if Cursor = crPencil then
  1444.   begin
  1445.     with OldRect do
  1446.       if (Left = Right) and (Top = Bottom) then
  1447.         Exit;
  1448.     if DesignerRestrictions * [frdrDontCreateObj] <> [] then Exit;
  1449.     DrawRectLine(OldRect);
  1450.     FDesigner.AddUndo;
  1451.     AddObject(gtLine);
  1452.     t.CreateUniqueName;
  1453.     t.x := OldRect.Left; t.y := OldRect.Top;
  1454.     t.dx := OldRect.Right - OldRect.Left; t.dy := OldRect.Bottom - OldRect.Top;
  1455.     if t.dx < 0 then
  1456.     begin
  1457.       t.dx := -t.dx; if Abs(t.dx) > Abs(t.dy) then t.x := OldRect.Right;
  1458.     end;
  1459.     if t.dy < 0 then
  1460.     begin
  1461.       t.dy := -t.dy; if Abs(t.dy) > Abs(t.dx) then t.y := OldRect.Bottom;
  1462.     end;
  1463.     t.Selected := True;
  1464.     t.FrameWidth := LastLineWidth;
  1465.     t.FrameColor := LastFrameColor;
  1466.     SelNum := 1;
  1467.     t.Draw(Canvas);
  1468.     DrawSelection(t);
  1469.     FDesigner.SelectionChanged;
  1470.     Exit;
  1471.   end;
  1472.  
  1473. // calculating which objects contains in frame (if user select it with mouse+Ctrl key)
  1474.   if RFlag then
  1475.   begin
  1476.     DrawFocusRect(OldRect);
  1477.     RFlag := False;
  1478.     NormalizeRect(OldRect);
  1479.     SelNum := 0;
  1480.     for i := 0 to Objects.Count - 1 do
  1481.     begin
  1482.       t := Objects[i];
  1483.       with OldRect do
  1484.       if t.Typ <> gtBand then
  1485.         if not ((t.x > Right) or (t.x + t.dx < Left) or
  1486.                 (t.y > Bottom) or (t.y + t.dy < Top)) then
  1487.         begin
  1488.           t.Selected := True;
  1489.           Inc(SelNum);
  1490.         end;
  1491.     end;
  1492.  
  1493.     if SelNum = 0 then
  1494.       for i := 0 to Objects.Count - 1 do
  1495.       begin
  1496.         t := Objects[i];
  1497.         with OldRect do
  1498.           if not ((t.x > Right) or (t.x + t.dx < Left) or
  1499.                   (t.y > Bottom) or (t.y + t.dy < Top)) then
  1500.           begin
  1501.             t.Selected := True;
  1502.             Inc(SelNum);
  1503.           end;
  1504.       end;
  1505.  
  1506.     GetMultipleSelected;
  1507.     FDesigner.SelectionChanged;
  1508.     DrawPage(dmSelection);
  1509.     Exit;
  1510.   end;
  1511. // splitting
  1512.   if Moved and MRFlag and (Cursor = crHSplit) then
  1513.   begin
  1514.     with SplitInfo do
  1515.     begin
  1516.       dx := SplRect.Left - SplX;
  1517.       if DesignerRestrictions * [frdrDontMoveObj, frdrDontSizeObj] = [] then
  1518.         if ((View1.Restrictions and frrfDontSize) = 0) and
  1519.           ((View2.Restrictions and (frrfDontMove + frrfDontSize)) = 0) then
  1520.           if (View1.dx + dx > 0) and (View2.dx - dx > 0) then
  1521.           begin
  1522.             Inc(View1.dx, dx);
  1523.             Inc(View2.x, dx);
  1524.             Dec(View2.dx, dx);
  1525.           end;
  1526.     end;
  1527.     GetMultipleSelected;
  1528.     Draw(TopSelected{, ClipRgn});
  1529.     Exit;
  1530.   end;
  1531. // resizing several objects
  1532.   if Moved and MRFlag and (Cursor <> crDefault) then
  1533.   begin
  1534.     Draw(TopSelected{, ClipRgn});
  1535.     Exit;
  1536.   end;
  1537. // redrawing all moved or resized objects
  1538.   if not Moved then
  1539.   begin
  1540.     FDesigner.SelectionChanged;
  1541.     DrawPage(dmSelection);
  1542.   end;
  1543.   if (SelNum >= 1) and Moved then
  1544.     if SelNum > 1 then
  1545.     begin
  1546.       Draw(TopSelected{, ClipRgn});
  1547.       GetMultipleSelected;
  1548.       FDesigner.ShowPosition;
  1549.     end
  1550.     else
  1551.     begin
  1552.       t := Objects[TopSelected];
  1553.       NormalizeCoord(t);
  1554.       if Cursor <> crDefault then t.Resized;
  1555.       Draw(TopSelected{, ClipRgn});
  1556.       FDesigner.SelectionChanged;
  1557.       FDesigner.ShowPosition;
  1558.     end;
  1559.   Moved := False;
  1560.   CT := ctNone;
  1561. end;
  1562.  
  1563. procedure TfrDesignerPage.MMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  1564. var
  1565.   i, j, kx, ky, w, dx, dy: Integer;
  1566.   t, t1, Bnd: TfrView;
  1567.   nx, ny, x1, x2, y1, y2: Double;
  1568.   FAlign: Boolean;
  1569.   ii: Integer;
  1570.  
  1571.   function Cont(px, py, x, y: Integer): Boolean;
  1572.   begin
  1573.     Result := (x >= px - w) and (x <= px + w + 1) and
  1574.       (y >= py - w) and (y <= py + w + 1);
  1575.   end;
  1576.  
  1577.   function GridCheck: Boolean;
  1578.   begin
  1579.     with FDesigner do
  1580.     begin
  1581.       Result := (kx >= GridSizeX) or (kx <= -GridSizeX) or
  1582.                 (ky >= GridSizeY) or (ky <= -GridSizeY);
  1583.       if Result then
  1584.       begin
  1585.         kx := kx - kx mod GridSizeX;
  1586.         ky := ky - ky mod GridSizeY;
  1587.       end;
  1588.     end;
  1589.   end;
  1590.  
  1591.   function CheckNegative(t: TfrView): Boolean;
  1592.   begin
  1593.     if (t.dx < 0) or (t.dy < 0) then
  1594.     begin
  1595.       NormalizeCoord(t);
  1596.       Result := True;
  1597.     end
  1598.     else
  1599.       Result := False;
  1600.   end;
  1601.  
  1602. begin
  1603.   Moved := True;
  1604.   FDrag := False;
  1605.   FAlign := FDesigner.GridAlign;
  1606.   if ssAlt in Shift then
  1607.     FAlign := not FAlign;
  1608.  
  1609.   w := 2;
  1610.   if FirstChange and Down and not RFlag then
  1611.   begin
  1612.     kx := x - LastX;
  1613.     ky := y - LastY;
  1614.     if not FAlign or GridCheck then
  1615.     begin
  1616.       FirstChange := False;
  1617.       FDesigner.AddUndo;
  1618.     end;
  1619.   end;
  1620.  
  1621.   if not Down then
  1622.     if FDesigner.OB6.Down then
  1623.     begin
  1624.       Mode := mdSelect;
  1625.       Cursor := crPencil;
  1626.     end
  1627.     else if FDesigner.OB1.Down then
  1628.     begin
  1629.       Mode := mdSelect;
  1630.       Cursor := crDefault;
  1631.       if SelNum = 0 then
  1632.       begin
  1633.         ShowSizes := False;
  1634.         OldRect := Rect(x, y, x, y);
  1635.         FDesigner.PBox1Paint(nil);
  1636.       end;
  1637.     end
  1638.     else
  1639.     begin
  1640.       Mode := mdInsert;
  1641.       if Cursor <> crCross then
  1642.       begin
  1643.         RoundCoord(x, y);
  1644.         FDesigner.GetDefaultSize(kx, ky);
  1645.         if FDesigner.OB3.Down then
  1646.           kx := Width;
  1647.         OldRect := Rect(x, y, x + kx, y + ky);
  1648.         if FDesigner.PageType = ptReport then
  1649.           DrawFocusRect(OldRect);
  1650.       end;
  1651.       Cursor := crCross;
  1652.     end;
  1653.  
  1654.   if (Mode = mdInsert) and not Down then
  1655.   begin
  1656.     if FDesigner.PageType = ptReport then
  1657.       DrawFocusRect(OldRect);
  1658.     RoundCoord(x, y);
  1659.     OffsetRect(OldRect, x - OldRect.Left, y - OldRect.Top);
  1660.     if FDesigner.PageType = ptReport then
  1661.       DrawFocusRect(OldRect);
  1662.     ShowSizes := True;
  1663.     FDesigner.PBox1Paint(nil);
  1664.     ShowSizes := False;
  1665.     Exit;
  1666.   end;
  1667.  
  1668.  // cursor shapes
  1669.   if not Down and (SelNum = 1) and (Mode = mdSelect) and
  1670.     not FDesigner.OB6.Down then
  1671.   begin
  1672.     t := Objects[TopSelected];
  1673.     if Cont(t.x, t.y, x, y) or Cont(t.x + t.dx, t.y + t.dy, x, y) then
  1674.       Cursor := crSizeNWSE
  1675.     else if Cont(t.x + t.dx, t.y, x, y) or Cont(t.x, t.y + t.dy, x, y)then
  1676.       Cursor := crSizeNESW
  1677.     else if Cont(t.x + t.dx div 2, t.y, x, y) or Cont(t.x + t.dx div 2, t.y + t.dy, x, y) then
  1678.       Cursor := crSizeNS
  1679.     else if Cont(t.x, t.y + t.dy div 2, x, y) or Cont(t.x + t.dx, t.y + t.dy div 2, x, y) then
  1680.       Cursor := crSizeWE
  1681.     else
  1682.       Cursor := crDefault;
  1683.   end;
  1684.   // selecting a lot of objects
  1685.   if Down and RFlag then
  1686.   begin
  1687.     DrawFocusRect(OldRect);
  1688.     if Cursor = crCross then
  1689.       RoundCoord(x, y);
  1690.     OldRect := Rect(OldRect.Left, OldRect.Top, x, y);
  1691.     DrawFocusRect(OldRect);
  1692.     ShowSizes := True;
  1693.     if Cursor = crCross then
  1694.       FDesigner.PBox1Paint(nil);
  1695.     ShowSizes := False;
  1696.     Exit;
  1697.   end;
  1698.   // line drawing
  1699.   if Down and (Cursor = crPencil) then
  1700.   begin
  1701.     kx := x - LastX;
  1702.     ky := y - LastY;
  1703.     if FAlign and not GridCheck then Exit;
  1704.     DrawRectLine(OldRect);
  1705.     OldRect := Rect(OldRect.Left, OldRect.Top, OldRect.Right + kx, OldRect.Bottom + ky);
  1706.     DrawRectLine(OldRect);
  1707.     Inc(LastX, kx);
  1708.     Inc(LastY, ky);
  1709.     Exit;
  1710.   end;
  1711.   // check for multiple selected objects - right-bottom corner
  1712.   if not Down and (SelNum > 1) and (Mode = mdSelect) then
  1713.   begin
  1714.     t := Objects[RightBottom];
  1715.     if Cont(t.x + t.dx, t.y + t.dy, x, y) then
  1716.       Cursor := crSizeNWSE
  1717.   end;
  1718.   // split checking
  1719.   if not Down and (SelNum > 1) and (Mode = mdSelect) then
  1720.   begin
  1721.     for i := 0 to Objects.Count - 1 do
  1722.     begin
  1723.       t := Objects[i];
  1724.       if (t.Typ <> gtBand) and (t.Typ <> gtLine) and t.Selected then
  1725.         if (x >= t.x) and (x <= t.x + t.dx) and (y >= t.y) and (y <= t.y + t.dy) then
  1726.         begin
  1727.           for j := 0 to Objects.Count - 1 do
  1728.           begin
  1729.             t1 := Objects[j];
  1730.             if (t1.Typ <> gtBand) and (t1 <> t) and t1.Selected then
  1731.               if ((t.x = t1.x + t1.dx) and ((x >= t.x) and (x <= t.x + 2))) or
  1732.                 ((t1.x = t.x + t.dx) and ((x >= t1.x - 2) and (x <= t.x))) then
  1733.               begin
  1734.                 Cursor := crHSplit;
  1735.                 with SplitInfo do
  1736.                 begin
  1737.                   SplRect := Rect(x, t.y, x, t.y + t.dy);
  1738.                   if t.x = t1.x + t1.dx then
  1739.                   begin
  1740.                     SplX := t.x;
  1741.                     View1 := t1;
  1742.                     View2 := t;
  1743.                   end
  1744.                   else
  1745.                   begin
  1746.                     SplX := t1.x;
  1747.                     View1 := t;
  1748.                     View2 := t1;
  1749.                   end;
  1750.                   SplRect.Left := SplX;
  1751.                   SplRect.Right := SplX;
  1752.                 end;
  1753.               end;
  1754.           end;
  1755.         end;
  1756.     end;
  1757.   end;
  1758.   // splitting
  1759.   if Down and MRFlag and (Mode = mdSelect) and (Cursor = crHSplit) then
  1760.   begin
  1761.     kx := x - LastX;
  1762.     ky := 0;
  1763.     if FAlign and not GridCheck then Exit;
  1764.     with SplitInfo do
  1765.     begin
  1766.       DrawHSplitter(SplRect);
  1767.       SplRect := Rect(SplRect.Left + kx, SplRect.Top, SplRect.Right + kx, SplRect.Bottom);
  1768.       DrawHSplitter(SplRect);
  1769.     end;
  1770.     Inc(LastX, kx);
  1771.     Exit;
  1772.   end;
  1773.   // sizing several objects
  1774.   if Down and MRFlag and (Mode = mdSelect) and (Cursor <> crDefault) then
  1775.   begin
  1776.     kx := x - LastX;
  1777.     ky := y - LastY;
  1778.     if FAlign and not GridCheck then Exit;
  1779.  
  1780.     if FDesigner.ShapeMode = smFrame then
  1781.       DrawPage(dmShape);
  1782.     if not ((OldRect.Right + kx < OldRect.Left) or (OldRect.Bottom + ky < OldRect.Top)) then
  1783.       OldRect := Rect(OldRect.Left, OldRect.Top, OldRect.Right + kx, OldRect.Bottom + ky);
  1784.     nx := (OldRect.Right - OldRect.Left) / (OldRect1.Right - OldRect1.Left);
  1785.     ny := (OldRect.Bottom - OldRect.Top) / (OldRect1.Bottom - OldRect1.Top);
  1786.     for i := 0 to Objects.Count - 1 do
  1787.     begin
  1788.       t := Objects[i];
  1789.       if t.Selected then
  1790.       begin
  1791.         x1 := (t.OriginalRect.Left - LeftTop.x) * nx;
  1792.         x2 := t.OriginalRect.Right * nx;
  1793.         dx := Round(x1 + x2) - (Round(x1) + Round(x2));
  1794.         if DesignerRestrictions * [frdrDontSizeObj] = [] then
  1795.           if (t.Restrictions and frrfDontSize) = 0 then
  1796.           begin
  1797.             t.x := LeftTop.x + Round(x1); t.dx := Round(x2) + dx;
  1798.           end;
  1799.  
  1800.         y1 := (t.OriginalRect.Top - LeftTop.y) * ny;
  1801.         y2 := t.OriginalRect.Bottom * ny;
  1802.         dy := Round(y1 + y2) - (Round(y1) + Round(y2));
  1803.         if DesignerRestrictions * [frdrDontSizeObj] = [] then
  1804.           if (t.Restrictions and frrfDontSize) = 0 then
  1805.           begin
  1806.             t.y := LeftTop.y + Round(y1); t.dy := Round(y2) + dy;
  1807.           end;
  1808.       end;
  1809.     end;
  1810.     if FDesigner.ShapeMode = smFrame then
  1811.       DrawPage(dmShape)
  1812.     else
  1813.       Draw(10000);
  1814.     Inc(LastX, kx);
  1815.     Inc(LastY, ky);
  1816.     FDesigner.PBox1Paint(nil);
  1817.     Exit;
  1818.   end;
  1819.   // moving
  1820.   if Down and (Mode = mdSelect) and (SelNum >= 1) and (Cursor = crDefault) then
  1821.   begin
  1822.     kx := x - LastX;
  1823.     ky := y - LastY;
  1824.     if FAlign and not GridCheck then Exit;
  1825.     if FirstBandMove and (SelNum = 1) and ((kx <> 0) or (ky <> 0)) and
  1826.       not (ssAlt in Shift) then
  1827.       if TfrView(Objects[TopSelected]).Typ = gtBand then
  1828.       begin
  1829.         Bnd := Objects[TopSelected];
  1830.         if (Bnd.Restrictions and frrfDontMove) = 0 then
  1831.         begin
  1832.           for i := 0 to Objects.Count - 1 do
  1833.           begin
  1834.             t := Objects[i];
  1835.             if t.Typ <> gtBand then
  1836.               if (t.x >= Bnd.x) and (t.x + t.dx <= Bnd.x + Bnd.dx) and
  1837.                  (t.y >= Bnd.y) and (t.y + t.dy <= Bnd.y + Bnd.dy) then
  1838.               begin
  1839.                 t.Selected := True;
  1840.                 Inc(SelNum);
  1841.               end;
  1842.           end;
  1843.           FDesigner.SelectionChanged;
  1844.           GetMultipleSelected;
  1845.         end;
  1846.       end;
  1847.     FirstBandMove := False;
  1848.     if FDesigner.ShapeMode = smFrame then
  1849.       DrawPage(dmShape);
  1850.     for i := 0 to Objects.Count - 1 do
  1851.     begin
  1852.       t := Objects[i];
  1853.       if not t.Selected then continue;
  1854.       if DesignerRestrictions * [frdrDontMoveObj] = [] then
  1855.         if (t.Restrictions and frrfDontMove) = 0 then
  1856.         begin
  1857.           t.x := t.x + kx;
  1858.           t.y := t.y + ky;
  1859.         end;
  1860.     end;
  1861.     if FDesigner.ShapeMode = smFrame then
  1862.       DrawPage(dmShape)
  1863.     else
  1864.       Draw(10000);
  1865.     Inc(LastX, kx);
  1866.     Inc(LastY, ky);
  1867.     FDesigner.PBox1Paint(nil);
  1868.   end;
  1869.  // resizing
  1870.   if Down and (Mode = mdSelect) and (SelNum = 1) and (Cursor <> crDefault) then
  1871.   begin
  1872.     kx := x - LastX;
  1873.     ky := y - LastY;
  1874.     if FAlign and not GridCheck then Exit;
  1875.     t := Objects[TopSelected];
  1876.     if FDesigner.ShapeMode = smFrame then
  1877.       DrawPage(dmShape);
  1878.     w := 3;
  1879.     if (DesignerRestrictions * [frdrDontSizeObj] = []) and
  1880.        ((t.Restrictions and frrfDontSize) = 0) then
  1881.     begin
  1882.       if Cursor = crSizeNWSE then
  1883.         if (CT <> ct2) and ((CT = ct1) or Cont(t.x, t.y, LastX, LastY)) then
  1884.         begin
  1885.           t.x := t.x + kx;
  1886.           t.dx := t.dx - kx;
  1887.           t.y := t.y + ky;
  1888.           t.dy := t.dy - ky;
  1889.           if CheckNegative(t) then
  1890.             CT := ct2 else
  1891.             CT := ct1;
  1892.         end
  1893.         else
  1894.         begin
  1895.           t.dx := t.dx + kx;
  1896.           t.dy := t.dy + ky;
  1897.           if CheckNegative(t) then
  1898.             CT := ct1 else
  1899.             CT := ct2;
  1900.         end;
  1901.       if Cursor = crSizeNESW then
  1902.         if (CT <> ct4) and ((CT = ct3) or Cont(t.x + t.dx, t.y, LastX, LastY)) then
  1903.         begin
  1904.           t.y := t.y + ky;
  1905.           t.dx := t.dx + kx;
  1906.           t.dy := t.dy - ky;
  1907.           if CheckNegative(t) then
  1908.             CT := ct4 else
  1909.             CT := ct3;
  1910.         end
  1911.         else
  1912.         begin
  1913.           t.x := t.x + kx;
  1914.           t.dx := t.dx - kx;
  1915.           t.dy := t.dy + ky;
  1916.           if CheckNegative(t) then
  1917.             CT := ct3 else
  1918.             CT := ct4;
  1919.         end;
  1920.       if Cursor = crSizeWE then
  1921.         if (CT <> ct6) and ((CT = ct5) or Cont(t.x, t.y + t.dy div 2, LastX, LastY)) then
  1922.         begin
  1923.           t.x := t.x + kx;
  1924.           t.dx := t.dx - kx;
  1925.           if CheckNegative(t) then
  1926.             CT := ct6 else
  1927.             CT := ct5;
  1928.         end
  1929.         else
  1930.         begin
  1931.           t.dx := t.dx + kx;
  1932.           if CheckNegative(t) then
  1933.             CT := ct5 else
  1934.             CT := ct6;
  1935.         end;
  1936.       if Cursor = crSizeNS then
  1937.         if (CT <> ct8) and ((CT = ct7) or Cont(t.x + t.dx div 2, t.y, LastX, LastY)) then
  1938.         begin
  1939.           t.y := t.y + ky;
  1940.           t.dy := t.dy - ky;
  1941.           if CheckNegative(t) then
  1942.             CT := ct8 else
  1943.             CT := ct7;
  1944.         end
  1945.         else
  1946.         begin
  1947.           t.dy := t.dy + ky;
  1948.           if CheckNegative(t) then
  1949.             CT := ct7 else
  1950.             CT := ct8;
  1951.         end;
  1952.     end;
  1953.     if FDesigner.ShapeMode = smFrame then
  1954.       DrawPage(dmShape)
  1955.     else
  1956.       Draw(10000);
  1957.     Inc(LastX, kx);
  1958.     Inc(LastY, ky);
  1959.     FDesigner.PBox1Paint(nil);
  1960.   end;
  1961.  
  1962.   if shift = [ssLeft] then
  1963.   begin
  1964.     ii := 0;
  1965.     with TScrollBox(Parent) do
  1966.     begin
  1967.       if x > (ClientRect.Right + HorzScrollBar.Position) then
  1968.       begin
  1969.         ii := x - (ClientRect.Right + HorzScrollBar.Position);
  1970.         HorzScrollBar.Position := HorzScrollBar.Position + ii;
  1971.       end;
  1972.       if x < HorzScrollBar.Position then
  1973.       begin
  1974.         ii := HorzScrollBar.Position - x;
  1975.         HorzScrollBar.Position := HorzScrollBar.Position - ii;
  1976.       end;
  1977.       if y > (ClientRect.Bottom + VertScrollBar.Position) then
  1978.       begin
  1979.         ii := y - (ClientRect.Bottom + VertScrollBar.Position);
  1980.         VertScrollBar.Position := VertScrollBar.Position + ii;
  1981.       end;
  1982.       if y < VertScrollBar.Position then
  1983.       begin
  1984.         ii := VertScrollBar.Position - y;
  1985.         VertScrollBar.Position := VertScrollBar.Position - ii;
  1986.       end;
  1987.     end;
  1988.     if ii <> 0 then
  1989.     begin
  1990.       self.Refresh;
  1991.       DrawFocusRect(OldRect);
  1992.     end;
  1993.   end;
  1994. end;
  1995.  
  1996. procedure TfrDesignerPage.DClick(Sender: TObject);
  1997. begin
  1998.   Down := False;
  1999.   if SelNum = 0 then
  2000.     if FDesigner.PageType = ptReport then
  2001.     begin
  2002.       FDesigner.PgB3Click(nil);
  2003.       DFlag := True;
  2004.     end
  2005.     else
  2006.     begin
  2007.       DFlag := True;
  2008.       FDesigner.Page.ScriptEditor(nil);
  2009.     end
  2010.   else if SelNum = 1 then
  2011.   begin
  2012.     DFlag := True;
  2013.     if WasCtrl then
  2014.       FDesigner.ShowMemoEditor(nil) else
  2015.       FDesigner.ShowEditor;
  2016.   end
  2017.   else Exit;
  2018. end;
  2019.  
  2020. procedure TfrDesignerPage.MouseLeave(AControl: TControl);
  2021. begin
  2022.   if ((Mode = mdInsert) and not Down) or FDrag then
  2023.   begin
  2024.     if FDesigner.PageType = ptReport then
  2025.       DrawFocusRect(OldRect);
  2026.     OffsetRect(OldRect, -10000, -10000);
  2027.   end;
  2028. end;
  2029.  
  2030. procedure TfrDesignerPage.DoDragOver(Sender, Source: TObject; X, Y: Integer;
  2031.   State: TDragState; var Accept: Boolean);
  2032. var
  2033.   kx, ky: Integer;
  2034. begin
  2035.   Accept := (Source is TListBox) and
  2036.             (DesignerRestrictions * [frdrDontCreateObj] = []) and
  2037.             (FDesigner.PageType = ptReport);
  2038.   if not Accept then Exit;
  2039.   if not FDrag then
  2040.   begin
  2041.     FDrag := True;
  2042.     FDesigner.GetDefaultSize(kx, ky);
  2043.     OldRect := Rect(x - 4, y - 4, x + kx - 4, y + ky - 4);
  2044.   end
  2045.   else
  2046.     DrawFocusRect(OldRect);
  2047.   RoundCoord(x, y);
  2048.   OffsetRect(OldRect, x - OldRect.Left - 4, y - OldRect.Top - 4);
  2049.   DrawFocusRect(OldRect);
  2050. end;
  2051.  
  2052. procedure TfrDesignerPage.DoDragDrop(Sender, Source: TObject; X, Y: Integer);
  2053. var
  2054.   t: TfrView;
  2055. begin
  2056.   DrawPage(dmSelection);
  2057. // emulating object insertion
  2058.   FDesigner.OB2.Down := True;
  2059.   Cursor := crCross;
  2060.   MUp(nil, mbLeft, [], 0, 0);
  2061.   t := Objects[TopSelected];
  2062.   t.Memo.Text := '[' + frFieldsDialog.DBField + ']';
  2063.   DrawSelection(t);
  2064.   t.Draw(Canvas);
  2065.   DrawSelection(t);
  2066. end;
  2067.  
  2068. { TfrUndoBuffer }
  2069.  
  2070. constructor TfrUndoBuffer.Create;
  2071. begin
  2072.   FUndo := TList.Create;
  2073.   FRedo := TList.Create;
  2074. end;
  2075.  
  2076. destructor TfrUndoBuffer.Destroy;
  2077. begin
  2078.   ClearUndo;
  2079.   ClearRedo;
  2080.   FUndo.Free;
  2081.   FRedo.Free;
  2082.   inherited;
  2083. end;
  2084.  
  2085. procedure TfrUndoBuffer.AddUndo(Report: TfrReport);
  2086. var
  2087.   m: TMemoryStream;
  2088. begin
  2089.   m := TMemoryStream.Create;
  2090.   FUndo.Add(m);
  2091.   Report.SaveToStream(m);
  2092. end;
  2093.  
  2094. procedure TfrUndoBuffer.AddRedo(Report: TfrReport);
  2095. var
  2096.   m: TMemoryStream;
  2097. begin
  2098.   m := TMemoryStream.Create;
  2099.   FRedo.Add(m);
  2100.   Report.SaveToStream(m);
  2101. end;
  2102.  
  2103. procedure TfrUndoBuffer.GetUndo(Report: TfrReport);
  2104. var
  2105.   m: TMemoryStream;
  2106. begin
  2107.   m := FUndo[FUndo.Count - 1];
  2108.   m.Position := 0;
  2109.   Report.LoadFromStream(m);
  2110.   m.Free;
  2111.   FUndo.Delete(FUndo.Count - 1);
  2112. end;
  2113.  
  2114. procedure TfrUndoBuffer.GetRedo(Report: TfrReport);
  2115. var
  2116.   m: TMemoryStream;
  2117. begin
  2118.   m := FRedo[FRedo.Count - 1];
  2119.   m.Position := 0;
  2120.   Report.LoadFromStream(m);
  2121.   m.Free;
  2122.   FRedo.Delete(FRedo.Count - 1);
  2123. end;
  2124.  
  2125. procedure TfrUndoBuffer.ClearUndo;
  2126. begin
  2127.   while FUndo.Count > 0 do
  2128.   begin
  2129.     TMemoryStream(FUndo[0]).Free;
  2130.     FUndo.Delete(0);
  2131.   end;
  2132. end;
  2133.  
  2134. procedure TfrUndoBuffer.ClearRedo;
  2135. begin
  2136.   while FRedo.Count > 0 do
  2137.   begin
  2138.     TMemoryStream(FRedo[0]).Free;
  2139.     FRedo.Delete(0);
  2140.   end;
  2141. end;
  2142.  
  2143.  
  2144. {-----------------------------------------------------------------------------}
  2145. procedure BDown(SB: TToolButton);
  2146. begin
  2147.   SB.Down := True;
  2148. end;
  2149.  
  2150. procedure BUp(SB: TToolButton);
  2151. begin
  2152.   SB.Down := False;
  2153. end;
  2154.  
  2155. procedure TfrDesignerForm.Localize;
  2156. var
  2157.   b: TBitmap;
  2158. begin
  2159.   FCaption :=         (S53080);
  2160.   Panel1.Caption :=   (S53081);
  2161.   Panel2.Caption :=   (S53082);
  2162.   Panel3.Caption :=   (S53083);
  2163.   Panel4.Caption :=   (S53084);
  2164.   Panel5.Caption :=   (S53085);
  2165.   Panel6.Caption :=   (S53086);
  2166.   FileBtn1.Hint :=    (S53087);
  2167.   FileBtn2.Hint :=    (S53088);
  2168.   FileBtn3.Hint :=    (S53089);
  2169.   FileBtn4.Hint :=    (S53090);
  2170.   CutB.Hint :=        (S53091);
  2171.   CopyB.Hint :=       (S53092);
  2172.   PstB.Hint :=        (S53093);
  2173.   UndoB.Hint :=       (S53094);
  2174.   RedoB.Hint :=       (S53095);
  2175.   ZB1.Hint :=         (S53096);
  2176.   ZB2.Hint :=         (S53097);
  2177.   SelAllB.Hint :=     (S53098);
  2178.   PgB1.Hint :=        (S53099);
  2179.   PgB2.Hint :=        (S53100);
  2180.   PgB3.Hint :=        (S53101);
  2181.   PgB4.Hint :=        (S53193);
  2182.   GB1.Hint :=         (S53102);
  2183.   GB2.Hint :=         (S53103);
  2184.   GB3.Hint :=         (S53104);
  2185.   HelpBtn.Hint :=     (S53032);
  2186.   ExitB.Caption :=    (S53105);
  2187.   ExitB.Hint :=       (S53106);
  2188.   AlB1.Hint :=        (S53107);
  2189.   AlB2.Hint :=        (S53108);
  2190.   AlB3.Hint :=        (S53109);
  2191.   AlB4.Hint :=        (S53110);
  2192.   AlB5.Hint :=        (S53111);
  2193.   AlB6.Hint :=        (S53112);
  2194.   AlB7.Hint :=        (S53113);
  2195.   AlB8.Hint :=        (S53114);
  2196.   FnB1.Hint :=        (S53115);
  2197.   FnB2.Hint :=        (S53116);
  2198.   FnB3.Hint :=        (S53117);
  2199.   ClB2.Hint :=        (S53118);
  2200.   HlB1.Hint :=        (S53119);
  2201.   C3.Hint :=          (S53120);
  2202.   C2.Hint :=          (S53121);
  2203.   FrB1.Hint :=        (S53122);
  2204.   FrB2.Hint :=        (S53123);
  2205.   FrB3.Hint :=        (S53124);
  2206.   FrB4.Hint :=        (S53125);
  2207.   FrB5.Hint :=        (S53126);
  2208.   FrB6.Hint :=        (S53127);
  2209.   ClB1.Hint :=        (S53128);
  2210.   ClB3.Hint :=        (S53129);
  2211.   C4.Hint :=          (S53130);
  2212.   OB1.Hint :=         (S53132);
  2213.   OB2.Hint :=         (S53133);
  2214.   OB3.Hint :=         (S53134);
  2215.   OB4.Hint :=         (S53135);
  2216.   OB5.Hint :=         (S53136);
  2217.   OB6.Hint :=         (S53137);
  2218.   Align1.Hint :=      (S53138);
  2219.   Align2.Hint :=      (S53139);
  2220.   Align3.Hint :=      (S53140);
  2221.   Align4.Hint :=      (S53141);
  2222.   Align5.Hint :=      (S53142);
  2223.   Align6.Hint :=      (S53143);
  2224.   Align7.Hint :=      (S53144);
  2225.   Align8.Hint :=      (S53145);
  2226.   Align9.Hint :=      (S53146);
  2227.   Align10.Hint :=     (S53147);
  2228.   N2.Caption :=       (S53148);
  2229.   N1.Caption :=       (S53149);
  2230.   N3.Caption :=       (S53150);
  2231.   N5.Caption :=       (S53151);
  2232.   N16.Caption :=      (S53152);
  2233.   N6.Caption :=       (S53153);
  2234.   FileMenu.Caption := (S53154);
  2235.   N23.Caption :=      (S53155);
  2236.   N19.Caption :=      (S53156);
  2237.   N20.Caption :=      (S53157);
  2238.   N42.Caption :=      (S53158);
  2239.   N8.Caption :=       (S53159);
  2240.   N25.Caption :=      (S53160);
  2241.   N39.Caption :=      (S53161);
  2242.   N10.Caption :=      (S53162);
  2243.   EditMenu.Caption := (S53163);
  2244.   N46.Caption :=      (S53164);
  2245.   N48.Caption :=      (S53165);
  2246.   N11.Caption :=      (S53166);
  2247.   N12.Caption :=      (S53167);
  2248.   N13.Caption :=      (S53168);
  2249.   N27.Caption :=      (S53169);
  2250.   N28.Caption :=      (S53170);
  2251.   N36.Caption :=      (S53171);
  2252.   N29.Caption :=      (S53172);
  2253.   N30.Caption :=      (S53173);
  2254.   N32.Caption :=      (S53174);
  2255.   N33.Caption :=      (S53175);
  2256.   ToolMenu.Caption := (S53176);
  2257.   N37.Caption :=      (S53177);
  2258.   MastMenu.Caption := (S53178);
  2259.   N14.Caption :=      (S53179);
  2260.   Pan1.Caption :=     (S53180);
  2261.   Pan2.Caption :=     (S53181);
  2262.   Pan3.Caption :=     (S53182);
  2263.   Pan4.Caption :=     (S53183);
  2264.   Pan5.Caption :=     (S53184);
  2265.   Pan6.Caption :=     (S53185);
  2266.   Pan7.Caption :=     (S53186);
  2267.   Pan8.Caption :=     (S53450);
  2268.   N34.Caption :=      (S53187);
  2269.   N17.Caption :=      (S53188);
  2270.   N22.Caption :=      (S53189);
  2271.   N35.Caption :=      (S53190);
  2272.   N15.Caption :=      (S53192);
  2273.   StB1.Hint   :=      (S53191);
  2274.   N41.Caption :=      N29.Caption;
  2275.   N41.OnClick :=      N29.OnClick;
  2276.   N43.Caption :=      N30.Caption;
  2277.   N43.OnClick :=      N30.OnClick;
  2278.   N44.Caption :=      N25.Caption;
  2279.   N44.OnClick :=      N25.OnClick;
  2280.   N45.Caption :=      N15.Caption;
  2281.   N45.OnClick :=      N15.OnClick;
  2282.  
  2283.   b := TBitmap.Create;
  2284.   b.Width := 16; b.Height := 16;
  2285.   b.LoadFromResourceName(HInstance, 'FR_BOLD');
  2286.   MainImages.ReplaceMasked(28, b, clSilver);
  2287.   b.LoadFromResourceName(HInstance, 'FR_ITALIC');
  2288.   MainImages.ReplaceMasked(29, b, clSilver);
  2289.   b.LoadFromResourceName(HInstance, 'FR_UNDRLINE');
  2290.   MainImages.ReplaceMasked(30, b, clSilver);
  2291.   b.Free;
  2292. end;
  2293.  
  2294. procedure TfrDesignerForm.FormCreate(Sender: TObject);
  2295. var
  2296.   i: Integer;
  2297. begin
  2298.   Localize;
  2299.   Busy := True;
  2300.   FirstTime := True;
  2301.   UndoBuffer := TfrUndoBuffer.Create;
  2302.  
  2303.   PageView := TfrDesignerPage.Create(ScrollBox1);
  2304.   PageView.FDesigner := Self;
  2305.   PageView.PopupMenu := Popup1;
  2306.   PageView.ShowHint := True;
  2307.  
  2308.   ColorSelector := TColorSelector.Create(Self);
  2309.   ColorSelector.OnColorSelected := ColorSelected;
  2310.   ColorSelector.Hide;
  2311.  
  2312.   for i := 0 to frAddInsCount - 1 do
  2313.   with frAddIns[i] do
  2314.     if not IsControl then
  2315.       RegisterObject(ButtonBmp, ButtonHint, Integer(gtAddIn) + i, IsControl);
  2316.  
  2317.   for i := 0 to frAddInsCount - 1 do
  2318.   with frAddIns[i] do
  2319.     if IsControl then
  2320.       RegisterObject(ButtonBmp, ButtonHint, Integer(gtAddIn) + i, IsControl);
  2321.  
  2322.   if FirstInstance then
  2323.   begin
  2324.     RegisterTool((SInsertFields), Image2.Picture.Bitmap, InsFieldsClick);
  2325.     for i := 0 to frToolsCount - 1 do
  2326.     with frTools[i] do
  2327.       RegisterTool(Caption, ButtonBmp, OnClick);
  2328.   end;
  2329.  
  2330.   InspForm := TfrInspForm.Create(Self);
  2331.   with InspForm do
  2332.   begin
  2333.     ClearProperties;
  2334.     AddProperty('', 0, [frdtString], nil, Null, nil);
  2335.     OnModify := Self.OnModify;
  2336.     OnHeightChanged := HeightChanged;
  2337.     OnSelectionChanged := InspSelectionChanged;
  2338.     OnGetObjects := InspGetObjects;
  2339.   end;
  2340.   CurPage := 0;
  2341.   RestoreState;
  2342.  
  2343.   OnMouseWheelUp := FormMouseWheelUp;
  2344.   OnMouseWheelDown := FormMouseWheelDown;
  2345. end;
  2346.  
  2347. procedure TfrDesignerForm.FormShow(Sender: TObject);
  2348.  
  2349.   procedure DoHide(Obj: TObject; Enabled: Boolean);
  2350.   begin
  2351.     if Obj is TMenuItem then
  2352.       TMenuItem(Obj).Enabled := Enabled
  2353.     else
  2354.     begin
  2355.       if (DesignerComp <> nil) and DesignerComp.HideDisabledButtons then
  2356.         TControl(Obj).Visible := Enabled else
  2357.         TControl(Obj).Enabled := Enabled
  2358.     end
  2359.   end;
  2360.  
  2361. begin
  2362. //  Screen.Cursors[crPencil].LoadFromResourceName(hInstance, 'FR_PENCIL');
  2363.   Panel7.Hide;
  2364.  
  2365.   if not FirstInstance then
  2366.   begin
  2367.     DoHide(PgB1, False);
  2368.     DoHide(PgB2, False);
  2369.     DoHide(N41, False);
  2370.     DoHide(N43, False);
  2371.     DoHide(N29, False);
  2372.     DoHide(N30, False);
  2373.   end;
  2374.  
  2375.   DoHide(FileBtn1, FirstInstance and (DesignerRestrictions * [frdrDontCreateReport] = []));
  2376.   DoHide(N23, FirstInstance and (DesignerRestrictions * [frdrDontCreateReport] = []));
  2377.  
  2378.   DoHide(FileBtn4, FirstInstance and not (CurReport is TfrCompositeReport) and
  2379.     (DesignerRestrictions * [frdrDontPreviewReport] = []));
  2380.   DoHide(N39, FirstInstance and not (CurReport is TfrCompositeReport) and
  2381.     (DesignerRestrictions * [frdrDontPreviewReport] = []));
  2382.  
  2383.   DoHide(OB3, FirstInstance);
  2384.   DoHide(OB5, FirstInstance);
  2385.  
  2386.   DoHide(FileBtn2, DesignerRestrictions * [frdrDontLoadReport] = []);
  2387.   DoHide(N19, DesignerRestrictions * [frdrDontLoadReport] = []);
  2388.  
  2389.   DoHide(FileBtn3, DesignerRestrictions * [frdrDontSaveReport] = []);
  2390.   DoHide(N17, DesignerRestrictions * [frdrDontSaveReport] = []);
  2391.   DoHide(N20, DesignerRestrictions * [frdrDontSaveReport] = []);
  2392.  
  2393.   DoHide(PgB1, DesignerRestrictions * [frdrDontCreatePage] = []);
  2394.   DoHide(N29, DesignerRestrictions * [frdrDontCreatePage] = []);
  2395.   DoHide(N41, DesignerRestrictions * [frdrDontCreatePage] = []);
  2396.  
  2397.   DoHide(PgB2, DesignerRestrictions * [frdrDontDeletePage] = []);
  2398.   DoHide(N30, DesignerRestrictions * [frdrDontDeletePage] = []);
  2399.   DoHide(N43, DesignerRestrictions * [frdrDontDeletePage] = []);
  2400.  
  2401.   DoHide(PgB3, DesignerRestrictions * [frdrDontEditPage] = []);
  2402.   DoHide(N25, DesignerRestrictions * [frdrDontEditPage] = []);
  2403.   DoHide(N44, DesignerRestrictions * [frdrDontEditPage] = []);
  2404.  
  2405.   DoHide(PgB4, DesignerRestrictions * [frdrDontCreatePage] = []);
  2406.   DoHide(N15, DesignerRestrictions * [frdrDontCreatePage] = []);
  2407.   DoHide(N45, DesignerRestrictions * [frdrDontCreatePage] = []);
  2408.  
  2409.   DoHide(N42, DesignerRestrictions * [frdrDontEditVariables] = []);
  2410.   DoHide(N8, DesignerRestrictions * [frdrDontChangeReportOptions] = []);
  2411.  
  2412.   if FirstTime then
  2413.     SetMenuBitmaps;
  2414.   FirstTime := False;
  2415.  
  2416.   ClearUndo;
  2417.   ClearRedo;
  2418.   Modified := False;
  2419.   CurReport.ComponentModified := False;
  2420.   Busy := True;
  2421.   DocMode := dmDesigning;
  2422.  
  2423.   LastFontName := C2.Items[0];
  2424.   if C2.Items.IndexOf('Arial') <> -1 then
  2425.     LastFontName := 'Arial';
  2426.   LastFontSize := 10;
  2427.  
  2428. //  CurPage := 0; // this cause page sizing
  2429.   if PageForm <> nil then
  2430.     PageForm.Show;
  2431.  
  2432.   if FirstInstance then
  2433.     CurDocName := CurReport.FileName else
  2434.     CurDocName := (SUntitled);
  2435.   Unselect;
  2436.   PageView.Init;
  2437.   EnableControls;
  2438.   OB1.Down := True;
  2439.   ColorSelector.Hide;
  2440.   LinePanel.Hide;
  2441.   ShowPosition;
  2442. //  RestoreState;
  2443. //  FormResize(nil);
  2444.   ScrollBox1.OnResize := ScrollBox1Resize;
  2445.   AssignDefEditors;
  2446.   if (DesignerComp <> nil) and Assigned(DesignerComp.OnShow) then
  2447.     DesignerComp.OnShow(Self);
  2448. end;
  2449.  
  2450. procedure TfrDesignerForm.FormDestroy(Sender: TObject);
  2451. begin
  2452. // workaround
  2453.   MainImages.Clear;
  2454.   DisabledImages.Clear;
  2455.   ImageList1.Clear;
  2456.   ImageList2.Clear;
  2457.   MainImages.Free;
  2458.   DisabledImages.Free;
  2459.  
  2460.   SaveState;
  2461.   CurReport.FileName := CurDocName;
  2462.   UndoBuffer.Free;
  2463.   InspForm.Free;
  2464.   if PageForm <> nil then
  2465.     PageForm.Hide;
  2466.   ScrollBox1.OnResize := nil;
  2467.  
  2468.   PageView.Free;
  2469.   if PageForm <> nil then
  2470.   begin
  2471.     PageForm.Free;
  2472.     PageForm := nil;
  2473.   end;
  2474.   if FirstInstance then
  2475.     ShowFieldsDialog(False);
  2476.   ColorSelector.Free;
  2477. end;
  2478.  
  2479. procedure TfrDesignerForm.FormResize(Sender: TObject);
  2480. begin
  2481.   if (csDestroying in ComponentState) or (csLoading in ComponentState) then Exit;
  2482.   with ScrollBox1 do
  2483.   begin
  2484.     HorzScrollBar.Position := 0;
  2485.     VertScrollBar.Position := 0;
  2486.   end;
  2487.   PageView.SetPage;
  2488.   Panel7.Top := StatusBar1.Top + 3;
  2489.   Panel7.Show;
  2490. end;
  2491.  
  2492. procedure TfrDesignerForm.AssignDefEditors;
  2493. begin
  2494.   frMemoEditor := DefMemoEditor;
  2495.   frPictureEditor := DefPictureEditor;
  2496.   frTagEditor := DefTagEditor;
  2497.   frRestrEditor := DefRestrEditor;
  2498.   frHighlightEditor := DefHighlightEditor;
  2499.   frFieldEditor := DefFieldEditor;
  2500.   frDataSourceEditor := DefDataSourceEditor;
  2501.   frCrossDataSourceEditor := DefCrossDataSourceEditor;
  2502.   frGroupEditor := DefGroupEditor;
  2503.   frFontEditor := DefFontEditor;
  2504. end;
  2505.  
  2506. procedure TfrDesignerForm.ScrollBox1Resize(Sender: TObject);
  2507. begin
  2508.   PageView.SetPage;
  2509. end;
  2510.  
  2511. procedure TfrDesignerForm.SetCurPage(Value: Integer);
  2512.  
  2513.   procedure SwitchObjectsToolbar;
  2514.   var
  2515.     i: Integer;
  2516.     c: TControl;
  2517.   begin
  2518.     for i := 0 to Toolbar4.ControlCount - 1 do
  2519.     begin
  2520.       c := Toolbar4.Controls[i];
  2521.       if (c is TToolButton) and (c <> OB1) then
  2522.         c.Enabled := not c.Enabled;
  2523.     end;
  2524.     Panel4.AdjustBounds;
  2525.     if Panel4.IsFloat then
  2526.     begin
  2527.       Panel4.FloatWindow.ClientWidth := Panel4.Width;
  2528.       Panel4.FloatWindow.ClientHeight := Panel4.Height;
  2529.     end;
  2530.   end;
  2531.  
  2532.   procedure PrepareObjects;
  2533.   var
  2534.     i: Integer;
  2535.     t: TfrView;
  2536.   begin
  2537.     DocMode := dmDesigning;
  2538.     for i := 0 to Objects.Count - 1 do
  2539.     begin
  2540.       t := Objects[i];
  2541.       t.Draw(GridBitmap.Canvas);
  2542.     end;
  2543.   end;
  2544.  
  2545. begin
  2546.   FCurPage := Value;
  2547.   Page := CurReport.Pages[FCurPage];
  2548.   FPageType := Page.PageType;
  2549.   FR_Class.CurPage := Page;
  2550.  
  2551.   if (FPageType = ptDialog) and (PageForm = nil) then
  2552.   begin
  2553.     if OB2.Enabled then
  2554.       SwitchObjectsToolbar;
  2555.     PageForm := TfrPageForm.Create(Self);
  2556.     PageForm.SetBounds(Page.Left, Page.Top, Page.Width, Page.Height);
  2557.     PageForm.OnCloseQuery := PageFormCloseQuery;
  2558.     PageForm.OnKeyDown := PageFormKeyDown;
  2559.     PageView.Color := clBtnFace;
  2560.     PageView.Parent := PageForm;
  2561.     PageForm.Icon := Icon;
  2562.     PageForm.Show;
  2563.   end
  2564.   else if (FPageType = ptReport) and (PageForm <> nil) then
  2565.   begin
  2566.     PageForm.OnResize := nil;
  2567.     if not OB2.Enabled then
  2568.       SwitchObjectsToolbar;
  2569.     PageView.Parent := ScrollBox1;
  2570.     PageView.Color := clWhite;
  2571.     PageForm.Free;
  2572.     PageForm := nil;
  2573.   end;
  2574.  
  2575.   if PageForm <> nil then
  2576.   begin
  2577.     PageForm.OnResize := nil;
  2578.     PageForm.SetBounds(Page.Left, Page.Top, Page.Width, Page.Height);
  2579.     PageForm.OnResize := PageFormResize;
  2580.     PageForm.Caption := Page.Caption;
  2581.     PageForm.Color := Page.Color;
  2582.   end;
  2583.   PageView.SetPage;
  2584.   ScrollBox1.VertScrollBar.Position := 0;
  2585.   ScrollBox1.HorzScrollBar.Position := 0;
  2586.   SetPageTitles;
  2587.   Tab1.OnChange := nil;
  2588.   Tab1.TabIndex := Value;
  2589.   Application.HandleMessage;
  2590.   Tab1.OnChange := Tab1Change;
  2591.   ResetSelection;
  2592.   SendBandsToDown;
  2593.   PrepareObjects;
  2594.   PageView.Repaint;
  2595. end;
  2596.  
  2597. procedure TfrDesignerForm.SetGridSize(Value: Integer);
  2598. begin
  2599.   if FGridSizeX = Value then Exit;
  2600.   FGridSizeX := Value;
  2601.   FGridSizeY := Value;
  2602.   RedrawPage;
  2603. end;
  2604.  
  2605. procedure TfrDesignerForm.SetGridShow(Value: Boolean);
  2606. begin
  2607.   if FGridShow = Value then Exit;
  2608.   FGridShow := Value;
  2609.   GB1.Down := Value;
  2610.   RedrawPage;
  2611. end;
  2612.  
  2613. procedure TfrDesignerForm.SetGridAlign(Value: Boolean);
  2614. begin
  2615.   if FGridAlign = Value then Exit;
  2616.   GB2.Down := Value;
  2617.   FGridAlign := Value;
  2618. end;
  2619.  
  2620. procedure TfrDesignerForm.SetUnits(Value: TfrReportUnits);
  2621. var
  2622.   s: String;
  2623. begin
  2624.   FUnits := Value;
  2625.   case Value of
  2626.     ruPixels: s := (SPixels);
  2627.     ruMM:     s := (SMM);
  2628.     ruInches: s := (SInches);
  2629.   end;
  2630.   StatusBar1.Panels[0].Text := s;
  2631.   ShowPosition;
  2632. end;
  2633.  
  2634. procedure TfrDesignerForm.SetCurDocName(Value: String);
  2635. begin
  2636.   FCurDocName := Value;
  2637.   Caption := FCaption + ' - ' + ExtractFileName(Value);
  2638. end;
  2639.  
  2640. procedure TfrDesignerForm.SetModified(Value: Boolean);
  2641. begin
  2642.   CurReport.Modified := Value;
  2643.   if Value and FirstInstance then
  2644.     CurReport.ComponentModified := True;
  2645.   FileBtn3.Enabled := Value and (DesignerRestrictions * [frdrDontSaveReport] = []);
  2646.   N20.Enabled := FileBtn3.Enabled;
  2647. end;
  2648.  
  2649. function TfrDesignerForm.GetModified: Boolean;
  2650. begin
  2651.   Result := CurReport.Modified;
  2652. end;
  2653.  
  2654. procedure TfrDesignerForm.SelectObject(ObjName: String);
  2655. var
  2656.   t: TfrView;
  2657. begin
  2658.   t := Page.FindObject(ObjName);
  2659.   if t <> nil then // it's object name
  2660.   begin
  2661.     Unselect;
  2662.     SelNum := 1;
  2663.     t.Selected := True;
  2664.     SelectionChanged;
  2665.     RedrawPage;
  2666.     PageView.GetMultipleSelected;
  2667.     ShowPosition;
  2668.   end
  2669.   else if Pos('Page', ObjName) = 1 then // it's page name
  2670.     CurPage := StrToInt(Copy(ObjName, 5, 255)) - 1;
  2671. end;
  2672.  
  2673. function TfrDesignerForm.InsertDBField: String;
  2674. begin
  2675.   Result := '';
  2676.   with TfrFieldsForm.Create(nil) do
  2677.   begin
  2678.     if ShowModal = mrOk then
  2679.       if DBField <> '' then
  2680.         Result := '[' + DBField + ']';
  2681.     Free;
  2682.   end;
  2683. end;
  2684.  
  2685. function TfrDesignerForm.InsertExpression: String;
  2686. begin
  2687.   Result := '';
  2688.   with TfrExprForm.Create(nil) do
  2689.   begin
  2690.     if ShowModal = mrOk then
  2691.     begin
  2692.       Result := ExprMemo.Text;
  2693.       if Result <> '' then
  2694.         if not ((Result[1] = '[') and (Result[Length(Result)] = ']') and
  2695.           (Pos('[', Copy(Result, 2, 255)) = 0)) then
  2696.           Result := '[' + Result + ']';
  2697.     end;
  2698.     Free;
  2699.   end;
  2700. end;
  2701.  
  2702. procedure TfrDesignerForm.RegisterObject(ButtonBmp: TBitmap;
  2703.   ButtonHint: String; ButtonTag: Integer; IsControl: Boolean);
  2704. var
  2705.   b: TToolButton;
  2706. begin
  2707.   MainImages.AddMasked(ButtonBMP, ButtonBMP.TransparentColor);
  2708.   DisabledImages.AddMasked(Image1.Picture.Bitmap, clSilver);
  2709.   b := TToolButton.Create(Self);
  2710.   with b do
  2711.   begin
  2712.     ImageIndex := MainImages.Count - 1;
  2713.  
  2714.     Hint := ButtonHint;
  2715.     Grouped := True;
  2716.     Style := tbsCheck;
  2717.     SetBounds(1000, 1000, 23, 23);
  2718.     Tag := ButtonTag;
  2719.     OnMouseDown := OB2MouseDown;
  2720.     Parent := ToolBar4;
  2721.     Enabled := not IsControl;
  2722.   end;
  2723. end;
  2724.  
  2725. procedure TfrDesignerForm.RegisterTool(MenuCaption: String; ButtonBmp: TBitmap;
  2726.   OnClick: TNotifyEvent);
  2727. var
  2728.   m: TMenuItem;
  2729.   b: TfrTBButton;
  2730. begin
  2731.   m := TMenuItem.Create(MastMenu);
  2732.  
  2733.   m.Caption := MenuCaption;
  2734.   m.OnClick := OnClick;
  2735.   MastMenu.Enabled := True;
  2736.   MastMenu.Add(m);
  2737.   Panel6.Height := 27; Panel6.Width := 27;
  2738.   b := TfrTBButton.Create(Self);
  2739.   with b do
  2740.   begin
  2741.     Parent := Panel6;
  2742.     Glyph := ButtonBmp;
  2743.     Hint := MenuCaption;
  2744.     Flat := True;
  2745.     SetBounds(1000, 1000, 23, 23);
  2746.     Tag := 36;
  2747.   end;
  2748.   b.OnClick := OnClick;
  2749.   Panel6.AdjustBounds;
  2750. end;
  2751.  
  2752. procedure TfrDesignerForm.AddPage;
  2753. begin
  2754.   if DesignerRestrictions * [frdrDontCreatePage] <> [] then Exit;
  2755.   AddUndo;
  2756.   CurReport.Pages.Add;
  2757.   Page := CurReport.Pages[CurReport.Pages.Count - 1];
  2758.   Page.CreateUniqueName;
  2759.   PgB3Click(nil);
  2760.   if WasOk then
  2761.   begin
  2762.     Modified := True;
  2763.     CurPage := CurReport.Pages.Count - 1
  2764.   end
  2765.   else
  2766.   begin
  2767.     CurReport.Pages.Delete(CurReport.Pages.Count - 1);
  2768.     CurPage := CurPage;
  2769.   end;
  2770. end;
  2771.  
  2772. procedure TfrDesignerForm.RemovePage(n: Integer);
  2773.   procedure AdjustSubReports;
  2774.   var
  2775.     i, j: Integer;
  2776.     t: TfrView;
  2777.   begin
  2778.     with CurReport do
  2779.       for i := 0 to Pages.Count - 1 do
  2780.       begin
  2781.         j := 0;
  2782.         while j < Pages[i].Objects.Count do
  2783.         begin
  2784.           t := Pages[i].Objects[j];
  2785.           if t.Typ = gtSubReport then
  2786.             if TfrSubReportView(t).SubPage = n then
  2787.             begin
  2788.               Pages[i].Delete(j);
  2789.               Dec(j);
  2790.             end
  2791.             else if TfrSubReportView(t).SubPage > n then
  2792.               Dec(TfrSubReportView(t).SubPage);
  2793.           Inc(j);
  2794.         end;
  2795.       end;
  2796.   end;
  2797. begin
  2798.   if DesignerRestrictions * [frdrDontDeletePage] <> [] then Exit;
  2799.   AddUndo;
  2800.   Modified := True;
  2801.   with CurReport do
  2802.     if (n >= 0) and (n < Pages.Count) then
  2803.       if Pages.Count = 1 then
  2804.         Pages[n].Clear else
  2805.       begin
  2806.         CurReport.Pages.Delete(n);
  2807.         Tab1.Tabs.Delete(n);
  2808.         Tab1.TabIndex := 0;
  2809.         AdjustSubReports;
  2810.         CurPage := 0;
  2811.       end;
  2812. end;
  2813.  
  2814. procedure TfrDesignerForm.SetPageTitles;
  2815. var
  2816.   i: Integer;
  2817.   s: String;
  2818.  
  2819.   function IsSubreport(PageN: Integer): Boolean;
  2820.   var
  2821.     i, j: Integer;
  2822.     t: TfrView;
  2823.   begin
  2824.     Result := False;
  2825.     with CurReport do
  2826.       for i := 0 to Pages.Count - 1 do
  2827.         for j := 0 to Pages[i].Objects.Count - 1 do
  2828.         begin
  2829.           t := Pages[i].Objects[j];
  2830.           if t.Typ = gtSubReport then
  2831.             if TfrSubReportView(t).SubPage = PageN then
  2832.             begin
  2833.               s := t.Name;
  2834.               Result := True;
  2835.               Exit;
  2836.             end;
  2837.         end;
  2838.   end;
  2839.  
  2840. begin
  2841.   if Tab1.Tabs.Count = CurReport.Pages.Count then
  2842.     for i := 0 to Tab1.Tabs.Count - 1 do
  2843.     begin
  2844.       if not IsSubreport(i) then
  2845.         s := (SPg) + IntToStr(i + 1);// CurReport.Pages[i].Name;
  2846.       if Tab1.Tabs[i].Caption <> s then
  2847.         Tab1.Tabs[i].Caption := s;
  2848.     end
  2849.   else
  2850.   begin
  2851.     Tab1.Tabs.Clear;
  2852.     for i := 0 to CurReport.Pages.Count - 1 do
  2853.     begin
  2854.       if not IsSubreport(i) then
  2855.         s := (SPg) + IntToStr(i + 1); //CurReport.Pages[i].Name;
  2856.       Tab1.Tabs.Add(s);
  2857.     end;
  2858.   end;
  2859. end;
  2860.  
  2861. procedure TfrDesignerForm.CutToClipboard;
  2862. var
  2863.   i: Integer;
  2864.   t: TfrView;
  2865.   m: TMemoryStream;
  2866. begin
  2867.   ClearClipBoard;
  2868.   for i := 0 to Objects.Count - 1 do
  2869.   begin
  2870.     t := Objects[i];
  2871.     if t.Selected then
  2872.     begin
  2873.       m := TMemoryStream.Create;
  2874.       frWriteByte(m, t.Typ);
  2875.       frWriteString(m, t.ClassName);
  2876.       t.SaveToStream(m);
  2877.       ClipBd.Add(m);
  2878.     end;
  2879.   end;
  2880.   DeleteObjects;
  2881. end;
  2882.  
  2883. procedure TfrDesignerForm.CopyToClipboard;
  2884. var
  2885.   i: Integer;
  2886.   t: TfrView;
  2887.   m: TMemoryStream;
  2888. begin
  2889.   ClearClipBoard;
  2890.   for i := 0 to Objects.Count - 1 do
  2891.   begin
  2892.     t := Objects[i];
  2893.     if t.Selected then
  2894.     begin
  2895.       m := TMemoryStream.Create;
  2896.       frWriteByte(m, t.Typ);
  2897.       frWriteString(m, t.ClassName);
  2898.       t.SaveToStream(m);
  2899.       ClipBd.Add(m);
  2900.     end;
  2901.   end;
  2902. end;
  2903.  
  2904. procedure TfrDesignerForm.SelectAll;
  2905. var
  2906.   i: Integer;
  2907. begin
  2908.   SelNum := 0;
  2909.   for i := 0 to Objects.Count - 1 do
  2910.   begin
  2911.     TfrView(Objects[i]).Selected := True;
  2912.     Inc(SelNum);
  2913.   end;
  2914. end;
  2915.  
  2916. procedure TfrDesignerForm.Unselect;
  2917. var
  2918.   i: Integer;
  2919. begin
  2920.   SelNum := 0;
  2921.   for i := 0 to Objects.Count - 1 do
  2922.     TfrView(Objects[i]).Selected := False;
  2923. end;
  2924.  
  2925. procedure TfrDesignerForm.NumberOfSelected;
  2926. var
  2927.   i: Integer;
  2928. begin
  2929.   SelNum := 0;
  2930.   for i := 0 to Objects.Count - 1 do
  2931.     if TfrView(Objects[i]).Selected then
  2932.       Inc(SelNum);
  2933. end;
  2934.  
  2935. procedure TfrDesignerForm.ResetSelection;
  2936. begin
  2937.   Unselect;
  2938.   EnableControls;
  2939.   ShowPosition;
  2940. end;
  2941.  
  2942. function TfrDesignerForm.PointsToUnits(x: Double): Double;
  2943. begin
  2944.   Result := x;
  2945.   case FUnits of
  2946.     ruMM: Result := x / 18 * 5;
  2947.     ruInches: Result := x / 18 * 5 / 25.4;
  2948.   end;
  2949. end;
  2950.  
  2951. function TfrDesignerForm.UnitsToPoints(x: Double): Double;
  2952. begin
  2953.   Result := x;
  2954.   case FUnits of
  2955.     ruMM: Result := x / 5 * 18;
  2956.     ruInches: Result := x * 25.4 / 5 * 18;
  2957.   end;
  2958. end;
  2959.  
  2960. procedure TfrDesignerForm.RedrawPage;
  2961. begin
  2962.   PageView.Draw(10000);
  2963. end;
  2964.  
  2965. procedure TfrDesignerForm.FormKeyDown(Sender: TObject; var Key: Word;
  2966.   Shift: TShiftState);
  2967. var
  2968.   StepX, StepY: Integer;
  2969.   i, tx, ty, tx1, ty1, d, d1: Integer;
  2970.   t, t1: TfrView;
  2971. begin
  2972. // thank you for buggy CLX, Borland!
  2973.   if InspForm.Edit1.Focused then Exit;
  2974. //
  2975.   StepX := 0; StepY := 0;
  2976.   if Key = key_F11 then
  2977.     InspForm.Grow;
  2978.   if (Key = key_Return) and (ActiveControl = C3) then
  2979.   begin
  2980.     Key := 0;
  2981.     DoClick(C3);
  2982.   end;
  2983.   if (Key = key_Return) and (ActiveControl = C4) then
  2984.   begin
  2985.     Key := 0;
  2986.     DoClick(C4);
  2987.   end;
  2988.   if (Key = key_Insert) and (Shift = []) and (PageType = ptReport) then
  2989.   begin
  2990.     ShowFieldsDialog(True);
  2991.     Key := 0;
  2992.   end;
  2993.   if (Key = key_Delete) and DelEnabled and (ActiveControl <> C3) then
  2994.   begin
  2995.     DeleteObjects;
  2996.     Key := 0;
  2997.   end;
  2998.   if (Key = key_Return) and EditEnabled then
  2999.   begin
  3000.     if ssCtrl in Shift then
  3001.       ShowMemoEditor(nil) else
  3002.       ShowEditor;
  3003.   end;
  3004.   if (Chr(Key) in ['1'..'9']) and (ssCtrl in Shift) and DelEnabled then
  3005.   begin
  3006.     C4.Text := Chr(Key);
  3007.     DoClick(C4);
  3008.     Key := 0;
  3009.   end;
  3010.   if (Chr(Key) = 'F') and (ssCtrl in Shift) and DelEnabled then
  3011.   begin
  3012.     FrB5.Click;
  3013.     Key := 0;
  3014.   end;
  3015.   if (Chr(Key) = 'D') and (ssCtrl in Shift) and DelEnabled then
  3016.   begin
  3017.     FrB6.Click;
  3018.     Key := 0;
  3019.   end;
  3020.   if (Chr(Key) = 'G') and (ssCtrl in Shift) then
  3021.   begin
  3022.     ShowGrid := not ShowGrid;
  3023.     Key := 0;
  3024.   end;
  3025.   if (ssCtrl in Shift) and EditEnabled then
  3026.   begin
  3027.     if Chr(Key) = 'B' then
  3028.     begin
  3029.       FnB1.Down := not FnB1.Down;
  3030.       DoClick(FnB1);
  3031.     end;
  3032.     if Chr(Key) = 'I' then
  3033.     begin
  3034.       FnB2.Down := not FnB2.Down;
  3035.       DoClick(FnB2);
  3036.     end;
  3037.     if Chr(Key) = 'U' then
  3038.     begin
  3039.       FnB3.Down := not FnB3.Down;
  3040.       DoClick(FnB3);
  3041.     end;
  3042.   end;
  3043.   if CutEnabled then
  3044.     if (Key = key_Delete) and (ssShift in Shift) then CutBClick(Self);
  3045.   if CopyEnabled then
  3046.     if (Key = key_Insert) and (ssCtrl in Shift) then CopyBClick(Self);
  3047.   if PasteEnabled then
  3048.     if (Key = key_Insert) and (ssShift in Shift) then PstBClick(Self);
  3049.   if Key = key_Prior then
  3050.     with ScrollBox1.VertScrollBar do
  3051.     begin
  3052.       Position := Position - 200;
  3053.       Key := 0;
  3054.     end;
  3055.   if Key = key_Next then
  3056.     with ScrollBox1.VertScrollBar do
  3057.     begin
  3058.       Position := Position + 200;
  3059.       Key := 0;
  3060.     end;
  3061.   if SelNum > 0 then
  3062.   begin
  3063.     if Key = key_Up then StepY := -1
  3064.     else if Key = key_Down then StepY := 1
  3065.     else if Key = key_Left then StepX := -1
  3066.     else if Key = key_Right then StepX := 1;
  3067.     if (StepX <> 0) or (StepY <> 0) then
  3068.     begin
  3069.       if ssCtrl in Shift then
  3070.         MoveObjects(StepX, StepY, False)
  3071.       else if ssShift in Shift then
  3072.         MoveObjects(StepX, StepY, True)
  3073.       else if SelNum = 1 then
  3074.       begin
  3075.         t := Objects[TopSelected];
  3076.         tx := t.x; ty := t.y; tx1 := t.x + t.dx; ty1 := t.y + t.dy;
  3077.         d := 10000; t1 := nil;
  3078.         for i := 0 to Objects.Count-1 do
  3079.         begin
  3080.           t := Objects[i];
  3081.           if not t.Selected and (t.Typ <> gtBand) then
  3082.           begin
  3083.             d1 := 10000;
  3084.             if StepX <> 0 then
  3085.             begin
  3086.               if t.y + t.dy < ty then
  3087.                 d1 := ty - (t.y + t.dy)
  3088.               else if t.y > ty1 then
  3089.                 d1 := t.y - ty1
  3090.               else if (t.y <= ty) and (t.y + t.dy >= ty1) then
  3091.                 d1 := 0
  3092.               else
  3093.                 d1 := t.y - ty;
  3094.               if ((t.x <= tx) and (StepX = 1)) or
  3095.                  ((t.x + t.dx >= tx1) and (StepX = -1)) then
  3096.                 d1 := 10000;
  3097.               if StepX = 1 then
  3098.                 if t.x >= tx1 then
  3099.                   d1 := d1 + t.x - tx1 else
  3100.                   d1 := d1 + t.x - tx
  3101.               else if t.x + t.dx <= tx then
  3102.                   d1 := d1 + tx - (t.x + t.dx) else
  3103.                   d1 := d1 + tx1 - (t.x + t.dx);
  3104.             end
  3105.             else if StepY <> 0 then
  3106.             begin
  3107.               if t.x + t.dx < tx then
  3108.                 d1 := tx - (t.x + t.dx)
  3109.               else if t.x > tx1 then
  3110.                 d1 := t.x - tx1
  3111.               else if (t.x <= tx) and (t.x + t.dx >= tx1) then
  3112.                 d1 := 0
  3113.               else
  3114.                 d1 := t.x - tx;
  3115.               if ((t.y <= ty) and (StepY = 1)) or
  3116.                  ((t.y + t.dy >= ty1) and (StepY = -1)) then
  3117.                 d1 := 10000;
  3118.               if StepY = 1 then
  3119.                 if t.y >= ty1 then
  3120.                   d1 := d1 + t.y - ty1 else
  3121.                   d1 := d1 + t.y - ty
  3122.               else if t.y + t.dy <= ty then
  3123.                   d1 := d1 + ty - (t.y + t.dy) else
  3124.                   d1 := d1 + ty1 - (t.y + t.dy);
  3125.             end;
  3126.             if d1 < d then
  3127.             begin
  3128.               d := d1;
  3129.               t1 := t;
  3130.             end;
  3131.           end;
  3132.         end;
  3133.         if t1 <> nil then
  3134.         begin
  3135.           t := Objects[TopSelected];
  3136.           if not (ssAlt in Shift) then
  3137.           begin
  3138.             PageView.DrawPage(dmSelection);
  3139.             Unselect;
  3140.             SelNum := 1;
  3141.             t1.Selected := True;
  3142.             PageView.DrawPage(dmSelection);
  3143.           end
  3144.           else if (DesignerRestrictions * [frdrDontMoveObj] = []) and
  3145.             ((t.Restrictions and frrfDontMove) = 0) then
  3146.           begin
  3147.             if (t1.x >= t.x + t.dx) and (Key = key_Right) then
  3148.               t.x := t1.x - t.dx
  3149.             else if (t1.y > t.y + t.dy) and (Key = key_Down) then
  3150.               t.y := t1.y - t.dy
  3151.             else if (t1.x + t1.dx <= t.x) and (Key = key_Left) then
  3152.               t.x := t1.x + t1.dx
  3153.             else if (t1.y + t1.dy <= t.y) and (Key = key_Up) then
  3154.               t.y := t1.y + t1.dy;
  3155.             RedrawPage;
  3156.           end;
  3157.           SelectionChanged;
  3158.         end;
  3159.       end;
  3160.     end;
  3161.   end;
  3162. end;
  3163.  
  3164. procedure TfrDesignerForm.MoveObjects(dx, dy: Integer; Resize: Boolean);
  3165. var
  3166.   i: Integer;
  3167.   t: TfrView;
  3168. begin
  3169.   AddUndo;
  3170.   FirstChange := False;
  3171.   PageView.DrawPage(dmSelection);
  3172.   for i := 0 to Objects.Count - 1 do
  3173.   begin
  3174.     t := Objects[i];
  3175.     if t.Selected then
  3176.       if Resize and (DesignerRestrictions * [frdrDontSizeObj] = []) and
  3177.         ((t.Restrictions and frrfDontSize) = 0) then
  3178.       begin
  3179.         Inc(t.dx, dx); Inc(t.dy, dy);
  3180.       end
  3181.       else if (DesignerRestrictions * [frdrDontMoveObj] = []) and
  3182.         ((t.Restrictions and frrfDontMove) = 0) then
  3183.       begin
  3184.         Inc(t.x, dx); Inc(t.y, dy);
  3185.       end;
  3186.   end;
  3187.   ShowPosition;
  3188.   PageView.GetMultipleSelected;
  3189.   PageView.Draw(TopSelected);
  3190. end;
  3191.  
  3192. procedure TfrDesignerForm.DeleteObjects;
  3193. var
  3194.   i: Integer;
  3195.   t: TfrView;
  3196. begin
  3197.   AddUndo;
  3198.   FirstChange := False;
  3199.   PageView.DrawPage(dmSelection);
  3200.   for i := Objects.Count - 1 downto 0 do
  3201.   begin
  3202.     t := Objects[i];
  3203.     if t.Selected and (DesignerRestrictions * [frdrDontDeleteObj] = []) and
  3204.       ((t.Restrictions and frrfDontDelete) = 0) then
  3205.     begin
  3206.       if (t is TfrBandView) and (TfrBandView(t).BandType = btChild) then
  3207.         NotifyParentBands(t.Name, '');
  3208.       Page.Delete(i);
  3209.     end;
  3210.   end;
  3211.   SetPageTitles;
  3212.   ResetSelection;
  3213.   FirstSelected := nil;
  3214.   PageView.Draw(10000);
  3215. end;
  3216.  
  3217. procedure TfrDesignerForm.NotifyParentBands(OldName, NewName: String);
  3218. var
  3219.   i: Integer;
  3220.   t: TfrView;
  3221. begin
  3222.   for i := 0 to Objects.Count - 1 do
  3223.   begin
  3224.     t := Objects[i];
  3225.     if (t is TfrBandView) and (TfrBandView(t).ChildBand = OldName) then
  3226.       TfrBandView(t).ChildBand := NewName;
  3227.   end;
  3228. end;
  3229.  
  3230. procedure TfrDesignerForm.NotifySubReports(OldIndex, NewIndex: Integer);
  3231. var
  3232.   i, j: Integer;
  3233.   t: TfrView;
  3234. begin
  3235.   with CurReport do
  3236.     for i := 0 to Pages.Count - 1 do
  3237.       for j := 0 to Pages[i].Objects.Count - 1 do
  3238.       begin
  3239.         t := Pages[i].Objects[j];
  3240.         if (t is TfrSubReportView) and (TfrSubReportView(t).SubPage = OldIndex) then
  3241.           TfrSubReportView(t).SubPage := NewIndex;
  3242.       end;
  3243. end;
  3244.  
  3245. function TfrDesignerForm.SelStatus: TfrSelectionStatus;
  3246. var
  3247.   t: TfrView;
  3248. begin
  3249.   Result := [];
  3250.   if SelNum = 1 then
  3251.   begin
  3252.     t := Objects[TopSelected];
  3253.     if t.Typ = gtBand then
  3254.       Result := [ssBand]
  3255.     else if t is TfrMemoView then
  3256.       Result := [ssMemo] else
  3257.       Result := [ssOther];
  3258.   end
  3259.   else if SelNum > 1 then
  3260.     Result := [ssMultiple];
  3261.   if ClipBd.Count > 0 then
  3262.     Result := Result + [ssClipboardFull];
  3263. end;
  3264.  
  3265. function TfrDesignerForm.RectTypEnabled: Boolean;
  3266. begin
  3267.   Result := [ssMemo, ssOther, ssMultiple] * SelStatus <> [];
  3268. end;
  3269.  
  3270. function TfrDesignerForm.FontTypEnabled: Boolean;
  3271. begin
  3272.   Result := [ssMemo, ssMultiple] * SelStatus <> [];
  3273. end;
  3274.  
  3275. function TfrDesignerForm.ZEnabled: Boolean;
  3276. begin
  3277.   Result := [ssBand, ssMemo, ssOther, ssMultiple] * SelStatus <> [];
  3278. end;
  3279.  
  3280. function TfrDesignerForm.CutEnabled: Boolean;
  3281. begin
  3282.   Result := [ssBand, ssMemo, ssOther, ssMultiple] * SelStatus <> [];
  3283. end;
  3284.  
  3285. function TfrDesignerForm.CopyEnabled: Boolean;
  3286. begin
  3287.   Result := [ssBand, ssMemo, ssOther, ssMultiple] * SelStatus <> [];
  3288. end;
  3289.  
  3290. function TfrDesignerForm.PasteEnabled: Boolean;
  3291. begin
  3292.   Result := ssClipboardFull in SelStatus;
  3293. end;
  3294.  
  3295. function TfrDesignerForm.DelEnabled: Boolean;
  3296. begin
  3297.   Result := [ssBand, ssMemo, ssOther, ssMultiple] * SelStatus <> [];
  3298. end;
  3299.  
  3300. function TfrDesignerForm.EditEnabled: Boolean;
  3301. begin
  3302.   Result := [ssBand, ssMemo, ssOther] * SelStatus <> [];
  3303. end;
  3304.  
  3305. procedure TfrDesignerForm.EnableControls;
  3306.   procedure SetEnabled(const Ar: Array of TObject; en: Boolean);
  3307.   var
  3308.     i: Integer;
  3309.   begin
  3310.     for i := Low(Ar) to High(Ar) do
  3311.       if Ar[i] is TToolButton then
  3312.       begin
  3313.         (Ar[i] as TToolButton).Enabled := en;
  3314.         if not en then
  3315.           (Ar[i] as TToolButton).Down := False;
  3316.       end
  3317.       else if Ar[i] is TControl then
  3318.         (Ar[i] as TControl).Enabled := en
  3319.       else if Ar[i] is TMenuItem then
  3320.         (Ar[i] as TMenuItem).Enabled := en
  3321.   end;
  3322. begin
  3323.   SetEnabled([FrB1, FrB2, FrB3, FrB4, FrB5, FrB6, ClB1, ClB3, C4, StB1],
  3324.     RectTypEnabled and (PageType = ptReport));
  3325.   SetEnabled([ClB2, C2, C3, FnB1, FnB2, FnB3, AlB1, AlB2, AlB3, AlB5, AlB6, AlB7, HlB1],
  3326.     FontTypEnabled);
  3327.   SetEnabled([ZB1, ZB2, N32, N33, GB3], ZEnabled);
  3328.   SetEnabled([CutB, N11, N2], CutEnabled);
  3329.   SetEnabled([CopyB, N12, N1], CopyEnabled);
  3330.   SetEnabled([PstB, N13, N3], PasteEnabled);
  3331.   SetEnabled([N27, N5], DelEnabled);
  3332.   SetEnabled([N36, N6], EditEnabled);
  3333.   StatusBar1.Repaint;
  3334.   PBox1Paint(nil);
  3335. end;
  3336.  
  3337. procedure TfrDesignerForm.SelectionChanged;
  3338. var
  3339.   t: TfrView;
  3340. begin
  3341.   Busy := True;
  3342.   ColorSelector.Hide;
  3343.   LinePanel.Hide;
  3344.   EnableControls;
  3345.   if SelNum = 1 then
  3346.   begin
  3347.     t := Objects[TopSelected];
  3348.     if t.Typ <> gtBand then
  3349.     with t do
  3350.     begin
  3351.       FrB1.Down := (FrameTyp and $8) <> 0;
  3352.       FrB2.Down := (FrameTyp and $4) <> 0;
  3353.       FrB3.Down := (FrameTyp and $2) <> 0;
  3354.       FrB4.Down := (FrameTyp and $1) <> 0;
  3355.       C4.Text := FloatToStrF(FrameWidth, ffGeneral, 2, 2);
  3356.       if t is TfrMemoView then
  3357.       with t as TfrMemoView do
  3358.       begin
  3359.         if C2.Text <> Font.Name then
  3360.           C2.ItemIndex := C2.Items.IndexOf(Font.Name);
  3361.         if C3.Text <> IntToStr(Font.Size) then
  3362.           C3.Text := IntToStr(Font.Size);
  3363.         FnB1.Down := fsBold in Font.Style;
  3364.         FnB2.Down := fsItalic in Font.Style;
  3365.         FnB3.Down := fsUnderline in Font.Style;
  3366. //        AlB4.Down := (Alignment and $4) <> 0;
  3367.         AlB5.Down := (Alignment and $18) = $8;
  3368.         AlB6.Down := (Alignment and $18) = 0;
  3369.         AlB7.Down := (Alignment and $18) = $10;
  3370.  
  3371.         AlB1.Down := (Alignment and $3) = 0;
  3372.         AlB2.Down := (Alignment and $3) = 1;
  3373.         AlB3.Down := (Alignment and $3) = 2;
  3374. //        AlB8.Down := (Alignment and $3) = 3;
  3375.       end;
  3376.     end;
  3377.   end
  3378.   else if SelNum > 1 then
  3379.   begin
  3380.     BUp(FrB1); BUp(FrB2); BUp(FrB3); BUp(FrB4);
  3381.     C4.Text := '1'; C2.Text := ''; C3.Text := '';
  3382.     BUp(FnB1); BUp(FnB2); BUp(FnB3);
  3383.     BDown(AlB1); BUp(AlB4); BUp(AlB5);
  3384.   end;
  3385.   ShowPosition;
  3386.   ShowContent;
  3387.   ActiveControl := nil;
  3388.   Busy := False;
  3389. end;
  3390.  
  3391. procedure TfrDesignerForm.ShowPosition;
  3392. begin
  3393.   FillInspFields;
  3394.   if not InspBusy then
  3395.     InspForm.ItemsChanged;
  3396.   StatusBar1.Repaint;
  3397.   PBox1Paint(nil);
  3398. end;
  3399.  
  3400. procedure TfrDesignerForm.ShowContent;
  3401. var
  3402.   t: TfrView;
  3403.   s: String;
  3404. begin
  3405.   s := '';
  3406.   if SelNum = 1 then
  3407.   begin
  3408.     t := Objects[TopSelected];
  3409.     s := t.Name;
  3410.     if t is TfrBandView then
  3411.       s := s + ': ' + frBandNames[Integer(TfrBandView(t).BandType)]
  3412.     else if t.Memo.Count > 0 then
  3413.       s := s + ': ' + t.Memo[0];
  3414.   end;
  3415.   StatusBar1.Panels[2].Text := s;
  3416. end;
  3417.  
  3418. procedure SetBit(var w: Word; e: Boolean; m: Integer);
  3419. begin
  3420.   if e then
  3421.     w := w or m else
  3422.     w := w and not m;
  3423. end;
  3424.  
  3425. procedure TfrDesignerForm.DoClick(Sender: TObject);
  3426. var
  3427.   i, b: Integer;
  3428.   DRect: TRect;
  3429.   t: TfrView;
  3430. begin
  3431.   if Busy then Exit;
  3432.   AddUndo;
  3433.   PageView.DrawPage(dmSelection);
  3434.   FirstChange := False;
  3435.   b := (Sender as TControl).Tag;
  3436.   for i := 0 to Objects.Count - 1 do
  3437.   begin
  3438.     t := Objects[i];
  3439.     if (DesignerRestrictions * [frdrDontModifyObj] = []) then
  3440.       if t.Selected and ((t.Restrictions and frrfDontModify) = 0) and
  3441.         ((t.Typ <> gtBand) or (b = 16)) then
  3442.       with t do
  3443.       begin
  3444.         if t is TfrMemoView then
  3445.         with t as TfrMemoView do
  3446.           case b of
  3447.             7: begin
  3448.                  LastFontName := C2.Text;
  3449.                  Font.Name := LastFontName;
  3450.                end;
  3451.             8: begin
  3452.                  Font.Size := StrToInt(C3.Text);
  3453.                  LastFontSize := Font.Size;
  3454.                end;
  3455.             9: begin
  3456.                  LastFontStyle := frGetFontStyle(Font.Style);
  3457.                  SetBit(LastFontStyle, FnB1.Down, 2);
  3458.                  Font.Style := frSetFontStyle(LastFontStyle);
  3459.                end;
  3460.            10: begin
  3461.                  LastFontStyle := frGetFontStyle(Font.Style);
  3462.                  SetBit(LastFontStyle, FnB2.Down, 1);
  3463.                  Font.Style := frSetFontStyle(LastFontStyle);
  3464.                end;
  3465.            11..13:
  3466.                begin
  3467.                  Alignment := (Alignment and $FC) + (b - 11);
  3468.                  LastAlignment := Alignment;
  3469.                end;
  3470.            14: begin
  3471.                  Alignment := (Alignment and $FB) + Word(AlB4.Down) * 4;
  3472.                  LastAlignment := Alignment;
  3473.                end;
  3474.            15: begin
  3475.                  Alignment := (Alignment and $E7) + Word(AlB5.Down) * 8 + Word(AlB7.Down) * $10;
  3476.                  LastAlignment := Alignment;
  3477.                end;
  3478.            17: begin
  3479.                  Font.Color := ColorSelector.Color;
  3480.                  LastFontColor := Font.Color;
  3481.                end;
  3482.            18: begin
  3483.                  LastFontStyle := frGetFontStyle(Font.Style);
  3484.                  SetBit(LastFontStyle, FnB3.Down, 4);
  3485.                  Font.Style := frSetFontStyle(LastFontStyle);
  3486.                end;
  3487.            22: begin
  3488.                  Alignment := (Alignment and $FC) + 3;
  3489.                  LastAlignment := Alignment;
  3490.                end;
  3491.           end;
  3492.         case b of
  3493.           1:
  3494.             begin
  3495.               SetBit(FrameTyp, FrB1.Down, 8);
  3496.               DRect := Rect(t.x - 10, t.y - 10, t.x + t.dx + 10, t.y + 10)
  3497.             end;
  3498.           2:
  3499.             begin
  3500.               SetBit(FrameTyp, FrB2.Down, 4);
  3501.               DRect := Rect(t.x - 10, t.y - 10, t.x + 10, t.y + t.dy + 10)
  3502.             end;
  3503.           3:
  3504.             begin
  3505.               SetBit(FrameTyp, FrB3.Down, 2);
  3506.               DRect := Rect(t.x - 10, t.y + t.dy - 10, t.x + t.dx + 10, t.y + t.dy + 10)
  3507.             end;
  3508.           4:
  3509.             begin
  3510.               SetBit(FrameTyp, FrB4.Down, 1);
  3511.               DRect := Rect(t.x + t.dx - 10, t.y - 10, t.x + t.dx + 10, t.y + t.dy + 10)
  3512.             end;
  3513.           20:
  3514.             begin
  3515.               FrameTyp := FrameTyp or $F;
  3516.               LastFrameTyp := $F;
  3517.             end;
  3518.           21:
  3519.             begin
  3520.               FrameTyp := FrameTyp and not $F;
  3521.               LastFrameTyp := 0;
  3522.             end;
  3523.           5:
  3524.             begin
  3525.               FillColor := ColorSelector.Color;
  3526.               LastFillColor := FillColor;
  3527.             end;
  3528.           6:
  3529.             begin
  3530.               FrameWidth := frStrToFloat(C4.Text);
  3531.               if t is TfrLineView then
  3532.                 LastLineWidth := FrameWidth else
  3533.                 LastFrameWidth := FrameWidth;
  3534.             end;
  3535.           19:
  3536.             begin
  3537.               FrameColor := ColorSelector.Color;
  3538.               LastFrameColor := FrameColor;
  3539.             end;
  3540.           25..30:
  3541.             FrameStyle := b - 25;
  3542.         end;
  3543.       end;
  3544.   end;
  3545.   PageView.Draw(TopSelected);
  3546.   FillInspFields;
  3547.   InspForm.ItemsChanged;
  3548.   ActiveControl := nil;
  3549.   if b in [20, 21] then SelectionChanged;
  3550. end;
  3551.  
  3552. procedure TfrDesignerForm.frSpeedButton1Click(Sender: TObject);
  3553. begin
  3554.   LinePanel.Hide;
  3555.   DoClick(Sender);
  3556. end;
  3557.  
  3558. procedure TfrDesignerForm.HlB1Click(Sender: TObject);
  3559. var
  3560.   i: Integer;
  3561.   t: TfrMemoView;
  3562. begin
  3563.   t := Objects[TopSelected];
  3564.   with TfrHilightForm.Create(nil) do
  3565.   begin
  3566.     FontColor := t.Highlight.FontColor;
  3567.     FillColor := t.Highlight.FillColor;
  3568.     CB1.Checked := (t.Highlight.FontStyle and $2) <> 0;
  3569.     CB2.Checked := (t.Highlight.FontStyle and $1) <> 0;
  3570.     CB3.Checked := (t.Highlight.FontStyle and $4) <> 0;
  3571.     Edit1.Text := t.HighlightStr;
  3572.     if ShowModal = mrOk then
  3573.     begin
  3574.       AddUndo;
  3575.       for i := 0 to Objects.Count - 1 do
  3576.       begin
  3577.         t := Objects[i];
  3578.         if t.Selected and (t is TfrMemoView) then
  3579.         begin
  3580.           t.HighlightStr := Edit1.Text;
  3581.           t.Highlight.FontColor := FontColor;
  3582.           t.Highlight.FillColor := FillColor;
  3583.           SetBit(t.Highlight.FontStyle, CB1.Checked, 2);
  3584.           SetBit(t.Highlight.FontStyle, CB2.Checked, 1);
  3585.           SetBit(t.Highlight.FontStyle, CB3.Checked, 4);
  3586.           SetBit(t.Highlight.FontStyle, False, 8);
  3587.         end;
  3588.       end;
  3589.     end;
  3590.     Free;
  3591.   end;
  3592.   RedrawPage;
  3593. end;
  3594.  
  3595. function TfrDesignerForm.BeforeEdit: Boolean;
  3596. begin
  3597.   Result := (DesignerRestrictions * [frdrDontEditObj] = []) and
  3598.     ((TfrView(Objects[TopSelected]).Restrictions and frrfDontEditContents) = 0);
  3599.   if Result then
  3600.     PageView.DrawPage(dmSelection);
  3601. end;
  3602.  
  3603. procedure TfrDesignerForm.AfterEdit;
  3604. begin
  3605.   PageView.Draw(TopSelected);
  3606. end;
  3607.  
  3608. procedure TfrDesignerForm.DoEdit(ClassRef: TClass);
  3609. var
  3610.   f: TfrObjEditorForm;
  3611. begin
  3612.   if BeforeEdit then
  3613.   begin
  3614.     f := TfrObjEditorForm(ClassRef.NewInstance);
  3615.     f.Create(nil);
  3616.     f.ShowEditor(Objects[TopSelected]);
  3617.     f.Free;
  3618.     AfterEdit;
  3619.   end;
  3620. end;
  3621.  
  3622. procedure TfrDesignerForm.DefMemoEditor(Sender: TObject);
  3623. begin
  3624.   ShowMemoEditor(Sender);
  3625. end;
  3626.  
  3627. procedure TfrDesignerForm.DefPictureEditor(Sender: TObject);
  3628. begin
  3629.   DoEdit(TfrGEditorForm);
  3630. end;
  3631.  
  3632. procedure TfrDesignerForm.DefTagEditor(Sender: TObject);
  3633. var
  3634.   t: TfrView;
  3635. begin
  3636.   if Sender = nil then
  3637.     t := Objects[TopSelected] else
  3638.     t := TfrView(Sender);
  3639.   if BeforeEdit then
  3640.   begin
  3641.     with TfrAttrEditorForm.Create(nil) do
  3642.     begin
  3643.       ShowEditor(t);
  3644.       Free;
  3645.     end;
  3646.     AfterEdit;
  3647.   end;
  3648. end;
  3649.  
  3650. procedure TfrDesignerForm.DefRestrEditor(Sender: TObject);
  3651. var
  3652.   i: Integer;
  3653.   t: TfrView;
  3654. begin
  3655.   if Sender = nil then
  3656.     t := Objects[TopSelected] else
  3657.     t := TfrView(Sender);
  3658.   with TfrRestrictionsForm.Create(nil) do
  3659.   begin
  3660.     with t do
  3661.     begin
  3662.       CB1.Checked := (Restrictions and frrfDontEditMemo) <> 0;
  3663.       CB2.Checked := (Restrictions and frrfDontEditScript) <> 0;
  3664.       CB3.Checked := (Restrictions and frrfDontEditContents) <> 0;
  3665.       CB4.Checked := (Restrictions and frrfDontModify) <> 0;
  3666.       CB5.Checked := (Restrictions and frrfDontSize) <> 0;
  3667.       CB6.Checked := (Restrictions and frrfDontMove) <> 0;
  3668.       CB7.Checked := (Restrictions and frrfDontDelete) <> 0;
  3669.     end;
  3670.     if ShowModal = mrOk then
  3671.     begin
  3672.       BeforeEdit;
  3673.       for i := 0 to frDesigner.Page.Objects.Count - 1 do
  3674.       begin
  3675.         t := frDesigner.Page.Objects[i];
  3676.         if t.Selected then
  3677.           t.Restrictions :=
  3678.             Word(CB1.Checked) * frrfDontEditMemo +
  3679.             Word(CB2.Checked) * frrfDontEditScript +
  3680.             Word(CB3.Checked) * frrfDontEditContents +
  3681.             Word(CB4.Checked) * frrfDontModify +
  3682.             Word(CB5.Checked) * frrfDontSize +
  3683.             Word(CB6.Checked) * frrfDontMove +
  3684.             Word(CB7.Checked) * frrfDontDelete;
  3685.       end;
  3686.       AfterEdit;
  3687.     end;
  3688.     Free;
  3689.   end;
  3690. end;
  3691.  
  3692. procedure TfrDesignerForm.DefHighlightEditor(Sender: TObject);
  3693. begin
  3694.   HlB1Click(nil);
  3695. end;
  3696.  
  3697. procedure TfrDesignerForm.DefFieldEditor(Sender: TObject);
  3698. var
  3699.   t: TfrView;
  3700.   s: String;
  3701. begin
  3702.   if BeforeEdit then
  3703.   begin
  3704.     t := Objects[TopSelected];
  3705.     s := InsertDBField;
  3706.     if s <> '' then
  3707.     begin
  3708.       BeforeChange;
  3709.       t.Prop['DataField'] := s;
  3710.     end;
  3711.     FillInspFields;
  3712.     InspForm.ItemsChanged;
  3713.     AfterEdit;
  3714.   end;
  3715. end;
  3716.  
  3717. procedure TfrDesignerForm.DefDataSourceEditor(Sender: TObject);
  3718. begin
  3719.   DoEdit(TfrBandEditorForm);
  3720. end;
  3721.  
  3722. procedure TfrDesignerForm.DefCrossDataSourceEditor(Sender: TObject);
  3723. begin
  3724.   DoEdit(TfrVBandEditorForm);
  3725. end;
  3726.  
  3727. procedure TfrDesignerForm.DefGroupEditor(Sender: TObject);
  3728. begin
  3729.   DoEdit(TfrGroupEditorForm);
  3730. end;
  3731.  
  3732. procedure TfrDesignerForm.DefFontEditor(Sender: TObject);
  3733. var
  3734.   t: TfrView;
  3735.   t1: TfrMemoView;
  3736.   i: Integer;
  3737.   fd: TFontDialog;
  3738. begin
  3739.   if BeforeEdit then
  3740.   begin
  3741.     t1 := TfrMemoView(Objects[TopSelected]);
  3742.     fd := TFontDialog.Create(nil);
  3743.     with fd do
  3744.     begin
  3745.       Font.Assign(t1.Font);
  3746.       if Execute then
  3747.       begin
  3748.         BeforeChange;
  3749.         for i := 0 to Objects.Count - 1 do
  3750.         begin
  3751.           t := Objects[i];
  3752.           if t.Selected and ((t.Restrictions and frrfDontModify) = 0) then
  3753.           begin
  3754.             if Font.Name <> t1.Font.Name then
  3755.               TfrMemoView(t).Font.Name := Font.Name;
  3756.             if Font.Size <> t1.Font.Size then
  3757.               TfrMemoView(t).Font.Size := Font.Size;
  3758.             if Font.Color <> t1.Font.Color then
  3759.               TfrMemoView(t).Font.Color := Font.Color;
  3760.             if Font.Style <> t1.Font.Style then
  3761.               TfrMemoView(t).Font.Style := Font.Style;
  3762. {$IFNDEF Delphi2}
  3763.             if Font.Charset <> t1.Font.Charset then
  3764.             begin
  3765.               TfrMemoView(t).Font.Charset := Font.Charset;
  3766.               LastCharset := Font.Charset;
  3767.             end;
  3768. {$ENDIF}
  3769.           end;
  3770.         end;
  3771.         AfterChange;
  3772.       end;
  3773.     end;
  3774.     fd.Free;
  3775.     AfterEdit;
  3776.   end;
  3777. end;
  3778.  
  3779.  
  3780. // ---------------------------------------------------- inspector section begin
  3781. type
  3782.   THackObject = class(TfrObject)
  3783.   end;
  3784.  
  3785. procedure TfrDesignerForm.InspSelectionChanged(ObjName: String);
  3786. begin
  3787.   SelectObject(ObjName);
  3788. end;
  3789.  
  3790. procedure TfrDesignerForm.InspGetObjects(List: TStrings);
  3791. var
  3792.   i: Integer;
  3793. begin
  3794.   List.Clear;
  3795.   for i := 0 to Objects.Count - 1 do
  3796.     List.Add(TfrView(Objects[i]).Name);
  3797.   for i := 0 to CurReport.Pages.Count - 1 do
  3798.     List.Add('Page' + IntToStr(i + 1));
  3799. end;
  3800.  
  3801. procedure TfrDesignerForm.FillInspFields;
  3802. var
  3803.   t: TfrObject;
  3804.   s, s1: TStringList;
  3805.   i: Integer;
  3806.  
  3807.   procedure GetObjectProperties(t: TfrObject; s: TStrings);
  3808.   var
  3809.     i: Integer;
  3810.     p: PfrPropRec;
  3811.   begin
  3812.     s.Clear;
  3813.     for i := 0 to THackObject(t).PropList.Count - 1 do
  3814.     begin
  3815.       p := THackObject(t).PropList[i];
  3816.       if p^.PropType <> [] then
  3817.         s.Add(p^.PropName);
  3818.     end;
  3819.   end;
  3820.  
  3821.   procedure ExcludeStrings(t: TfrObject);
  3822.   var
  3823.     i: Integer;
  3824.     p: PfrPropRec;
  3825.   begin
  3826.     i := 0;
  3827.     while i < s.Count do
  3828.     begin
  3829.       p := t.PropRec[s[i]];
  3830.       if (s1.IndexOf(s[i]) = -1) or
  3831.         ((frdtOneObject in p^.PropType) and (SelNum > 1)) then
  3832.         s.Delete(i) else
  3833.         Inc(i);
  3834.     end;
  3835.   end;
  3836.  
  3837.   procedure FillProperties(t: TfrObject);
  3838.   var
  3839.     i: Integer;
  3840.     p: PfrPropRec;
  3841.     st: String;
  3842.   begin
  3843.     for i := 0 to s.Count - 1 do
  3844.     begin
  3845.       p := t.PropRec[s[i]];
  3846.       if (frdtHasEditor in p^.PropType) and not (frdtString in p^.PropType) then
  3847.         fld[i] := '(' + p^.PropName + ')'
  3848.       else
  3849.       begin
  3850.         st := t.Prop[p^.PropName];
  3851.         if (st <> fld[i]) and (fld[i] <> '-') then
  3852.           st := '';
  3853.         fld[i] := st;
  3854.       end;
  3855.     end;
  3856.   end;
  3857.  
  3858.   function ConvertToSize(s: String): String;
  3859.   var
  3860.     v: Double;
  3861.   begin
  3862.     v := frStrToFloat(s);
  3863.     if (FUnits = ruPixels) or (PageType = ptDialog) then
  3864.       Result := FloatToStrF(v, ffGeneral, 4, 2) else
  3865.       Result := FloatToStrF(PointsToUnits(v), ffFixed, 4, 2);
  3866.   end;
  3867.  
  3868.   procedure CreateProperties(t: TfrObject);
  3869.   var
  3870.     p: PfrPropRec;
  3871.     i: Integer;
  3872.     dt: TfrDataTypes;
  3873.   begin
  3874.     for i := 0 to s.Count - 1 do
  3875.     begin
  3876.       p := t.PropRec[s[i]];
  3877.       dt := p^.PropType;
  3878.       if frdtSize in p^.PropType then
  3879.       begin
  3880.         if fld[i] <> '' then
  3881.           fld[i] := ConvertToSize(fld[i]);
  3882.         if p^.PropType = [frdtSize] then
  3883.           if (Units = ruPixels) or (PageType = ptDialog) then
  3884.             dt := dt + [frdtInteger] else
  3885.             dt := dt + [frdtFloat];
  3886.       end;
  3887.  
  3888.       if not (frdtHasEditor in p^.PropType) then
  3889.         InspForm.AddProperty(s[i], fld[i], dt, p^.Enum, p^.EnumValues, p^.PropEditor) else
  3890.         InspForm.AddProperty(s[i], fld[i], p^.PropType, p^.Enum, p^.EnumValues, p^.PropEditor);
  3891.     end;
  3892.   end;
  3893.  
  3894. begin
  3895.   if InspBusy then Exit;
  3896.   InspForm.ClearProperties;
  3897.   InspForm.ObjectName := '';
  3898.   InspForm.CurObject := nil;
  3899.  
  3900.   s := TStringList.Create;
  3901.   s1 := TStringList.Create;
  3902.  
  3903.   if SelNum > 0 then
  3904.   begin
  3905.     for i := 0 to Objects.Count - 1 do
  3906.     begin
  3907.       t := Objects[i];
  3908.       if TfrView(t).Selected then
  3909.       begin
  3910.         t.DefineProperties;
  3911.         GetObjectProperties(t, s1);
  3912.         if s.Count = 0 then
  3913.           s.Assign(s1) else
  3914.           ExcludeStrings(t);
  3915.       end;
  3916.     end;
  3917.  
  3918.     t := Objects[TopSelected];
  3919.     if SelNum = 1 then
  3920.     begin
  3921.       InspForm.ObjectName := TfrView(t).Name;
  3922.       InspForm.CurObject := t;
  3923.     end;
  3924.     s.Sort;
  3925.  
  3926.     for i := 0 to s.Count - 1 do
  3927.       fld[i] := '-';
  3928.  
  3929.     for i := 0 to Objects.Count - 1 do
  3930.     begin
  3931.       t := Objects[i];
  3932.       if TfrView(t).Selected then
  3933.         FillProperties(t);
  3934.     end;
  3935.  
  3936.     t := Objects[TopSelected];
  3937.     CreateProperties(t);
  3938.   end
  3939.   else
  3940.   begin
  3941.     t := Page;
  3942.     t.DefineProperties;
  3943.     GetObjectProperties(t, s);
  3944.     s.Sort;
  3945.     InspForm.CurObject := Page;
  3946.     InspForm.ObjectName := 'Page' + IntToStr(CurPage + 1);
  3947.     for i := 0 to s.Count - 1 do
  3948.       fld[i] := '-';
  3949.     FillProperties(t);
  3950.     CreateProperties(t);
  3951.   end;
  3952.  
  3953.   s.Free;
  3954.   s1.Free;
  3955. end;
  3956.  
  3957. procedure TfrDesignerForm.OnModify(Item: Integer);
  3958. var
  3959.   t: TfrView;
  3960.   t1: TfrObject;
  3961.   PropName: String;
  3962.   i: Integer;
  3963.   v: Variant;
  3964.   CantAssign: Boolean;
  3965.  
  3966.   function CheckUnique(Obj: TfrView; Name: String): Boolean;
  3967.   begin
  3968.     Result := (CurReport.FindObject(Name) = nil) and
  3969.        (not (Obj is TfrControl) or (frDialogForm.FindComponent(Name) = nil));
  3970.   end;
  3971.  
  3972. begin
  3973.   try
  3974.     PropName := InspForm.Items[Item];
  3975.     v := InspForm.PropValue[Item];
  3976.     if SelNum > 0 then
  3977.     begin
  3978.       if DesignerRestrictions * [frdrDontModifyObj] = [] then
  3979.       begin
  3980.         AddUndo;
  3981.         for i := 0 to Objects.Count - 1 do
  3982.         begin
  3983.           t := Objects[i];
  3984.           if t.Selected then
  3985.           begin
  3986.             if PropName = 'Name' then
  3987.             begin
  3988.               if CheckUnique(t, v) then
  3989.               begin
  3990.                 if (DesignerRestrictions * [frdrDontModifyObj] = []) and
  3991.                   ((t.Restrictions and frrfDontModify) = 0) then
  3992.                 begin
  3993.                   NotifyParentBands(t.Name, v);
  3994.                   t.Prop[PropName] := v;
  3995.                 end;
  3996.               end
  3997.             end
  3998.             else
  3999.             begin
  4000.               CantAssign := ((PropName = 'Left') or (PropName = 'Top')) and
  4001.                  (((t.Restrictions and frrfDontMove) <> 0) or
  4002.                  (DesignerRestrictions * [frdrDontMoveObj] <> []));
  4003.               CantAssign := CantAssign or
  4004.                  ((PropName = 'Width') or (PropName = 'Height')) and
  4005.                  (((t.Restrictions and frrfDontSize) <> 0) or
  4006.                  (DesignerRestrictions * [frdrDontSizeObj] <> []));
  4007.               if not CantAssign then
  4008.                 if (frdtSize in t.PropRec[PropName].PropType) and (PageType = ptReport) then
  4009.                   t.Prop[PropName] := UnitsToPoints(v) else
  4010.                   t.Prop[PropName] := v;
  4011.             end;
  4012.           end;
  4013.         end;
  4014.       end
  4015.     end
  4016.     else if DesignerRestrictions * [frdrDontEditPage] = [] then
  4017.     begin
  4018.       CantAssign := False;
  4019.       t1 := Page;
  4020.       if frdtSize in t1.PropRec[PropName].PropType then
  4021.         v := UnitsToPoints(v);
  4022.       if (PropName = 'Type') and (Page.Objects.Count > 0) then
  4023.       begin
  4024.         CantAssign := Application.MessageBox((SDeleteObjects),
  4025.           (SWarning), [smbYes, smbNo], smsWarning) <> smbYes;
  4026.         if not CantAssign then
  4027.           Page.Clear;
  4028.       end;
  4029.  
  4030.       if not CantAssign then
  4031.       begin
  4032.         t1.Prop[PropName] := v;
  4033.         Modified := True;
  4034.         with Page do
  4035.           ChangePaper(pgSize, pgWidth, pgHeight, pgBin, pgOr);
  4036.         if PropName <> 'Type' then
  4037.           InspBusy := True;
  4038.         CurPage := CurPage;
  4039.         InspBusy := False;
  4040.       end;
  4041.     end;
  4042.  
  4043.   finally
  4044.     FillInspFields;
  4045.     InspForm.ItemsChanged;
  4046.     RedrawPage;
  4047.     SetPageTitles;
  4048.     if frFieldsDialog <> nil then
  4049.       frFieldsDialog.RefreshData;
  4050.     StatusBar1.Repaint;
  4051.     PBox1Paint(nil);
  4052.   end;
  4053. end;
  4054. // ---------------------------------------------------- inspector section end
  4055.  
  4056. procedure TfrDesignerForm.StB1Click(Sender: TObject);
  4057. var
  4058.   p: TPoint;
  4059. begin
  4060.   ColorSelector.Hide;
  4061.   if not LinePanel.Visible then
  4062.   begin
  4063.     LinePanel.Parent := Self;
  4064.     with (Sender as TControl) do
  4065.       p := Self.ScreenToClient(Parent.ClientToScreen(Point(Left, Top)));
  4066.     LinePanel.Left := p.X;
  4067.     LinePanel.Top := p.Y + 26;
  4068.   end;
  4069.   LinePanel.Visible := not LinePanel.Visible;
  4070. end;
  4071.  
  4072. procedure TfrDesignerForm.ClB1Click(Sender: TObject);
  4073. var
  4074.   p: TPoint;
  4075.   t: TfrView;
  4076. begin
  4077.   LinePanel.Hide;
  4078.   with (Sender as TControl) do
  4079.     p := Self.ScreenToClient(Parent.ClientToScreen(Point(Left, Top)));
  4080.   if ColorSelector.Left = p.X then
  4081.     ColorSelector.Visible := not ColorSelector.Visible
  4082.   else
  4083.   begin
  4084.     ColorSelector.Left := p.X;
  4085.     ColorSelector.Top := p.Y + 26;
  4086.     ColorSelector.Visible := True;
  4087.   end;
  4088.   ColorSelector.Color := clNone;
  4089.   ClrButton := Sender as TToolButton;
  4090.   t := Objects[TopSelected];
  4091.   if ClrButton = ClB1 then
  4092.     ColorSelector.Color := t.FillColor
  4093.   else if (ClrButton = ClB2) and (t is TfrMemoView) then
  4094.     ColorSelector.Color := TfrMemoView(t).Font.Color
  4095.   else if ClrButton = ClB3 then
  4096.     ColorSelector.Color := t.FrameColor
  4097. end;
  4098.  
  4099. procedure TfrDesignerForm.ColorSelected(Sender: TObject);
  4100. begin
  4101.   DoClick(ClrButton);
  4102. end;
  4103.  
  4104. procedure TfrDesignerForm.PBox1Paint(Sender: TObject);
  4105. var
  4106.   t: TfrView;
  4107.   p: TPoint;
  4108.   s: String;
  4109.   nx, ny: Double;
  4110.   x, y, dx, dy: Integer;
  4111.  
  4112.   function TopLeft: TPoint;
  4113.   var
  4114.     i: Integer;
  4115.     t: TfrView;
  4116.   begin
  4117.     Result.x := 10000; Result.y := 10000;
  4118.     for i := 0 to Objects.Count - 1 do
  4119.     begin
  4120.       t := Objects[i];
  4121.       if t.Selected then
  4122.       begin
  4123.         if t.x < Result.x then
  4124.           Result.x := t.x;
  4125.         if t.y < Result.y then
  4126.           Result.y := t.y;
  4127.       end;
  4128.     end;
  4129.   end;
  4130.  
  4131. begin
  4132.   with PBox1.Canvas do
  4133.   begin
  4134.     FillRect(Rect(0, 0, PBox1.Width, PBox1.Height));
  4135.     ImageList1.Draw(PBox1.Canvas, 2, 0, 0);
  4136.     if not ((SelNum = 0) and (PageView.Mode = mdSelect)) then
  4137.       ImageList1.Draw(PBox1.Canvas, 92, 0, 1);
  4138.     if (SelNum = 1) or ShowSizes then
  4139.     begin
  4140.       t := nil;
  4141.       if ShowSizes then
  4142.       begin
  4143.         x := OldRect.Left; y := OldRect.Top;
  4144.         dx := OldRect.Right - x; dy := OldRect.Bottom - y;
  4145.       end
  4146.       else
  4147.       begin
  4148.         t := Objects[TopSelected];
  4149.         x := t.x; y := t.y; dx := t.dx; dy := t.dy;
  4150.       end;
  4151.       if FUnits = ruPixels then
  4152.         s := IntToStr(x) + ';' + IntToStr(y) else
  4153.         s := FloatToStrF(PointsToUnits(x), ffFixed, 4, 2) + '; ' +
  4154.           FloatToStrF(PointsToUnits(y), ffFixed, 4, 2);
  4155.       TextOut(20, 1, s);
  4156.       if FUnits = ruPixels then
  4157.         s := IntToStr(dx) + ';' + IntToStr(dy) else
  4158.         s := FloatToStrF(PointsToUnits(dx), ffFixed, 4, 2) + '; ' +
  4159.           FloatToStrF(PointsToUnits(dy), ffFixed, 4, 2);
  4160.       TextOut(110, 1, s);
  4161.       if not ShowSizes and (t.Typ = gtPicture) then
  4162.         with t as TfrPictureView do
  4163.         if (Picture.Graphic <> nil) and not Picture.Graphic.Empty then
  4164.         begin
  4165.           s := IntToStr(dx * 100 div Picture.Width) + ',' +
  4166.                IntToStr(dy * 100 div Picture.Height);
  4167.           TextOut(170, 1, '% ' + s);
  4168.         end;
  4169.     end
  4170.     else if (SelNum > 0) and MRFlag then
  4171.     begin
  4172.       p := TopLeft;
  4173.       if FUnits = ruPixels then
  4174.         s := IntToStr(p.x) + ';' + IntToStr(p.y) else
  4175.         s := FloatToStrF(PointsToUnits(p.x), ffFixed, 4, 2) + '; ' +
  4176.           FloatToStrF(PointsToUnits(p.y), ffFixed, 4, 2);
  4177.       TextOut(20, 1, s);
  4178.  
  4179.       nx := 0; ny := 0;
  4180.       if OldRect1.Right - OldRect1.Left <> 0 then
  4181.         nx := (OldRect.Right - OldRect.Left) / (OldRect1.Right - OldRect1.Left);
  4182.       if OldRect1.Bottom - OldRect1.Top <> 0 then
  4183.         ny := (OldRect.Bottom - OldRect.Top) / (OldRect1.Bottom - OldRect1.Top);
  4184.       s := IntToStr(Round(nx * 100)) + ',' + IntToStr(Round(ny * 100));
  4185.       TextOut(170, 1, '% ' + s);
  4186.     end
  4187.     else if (SelNum = 0) and (PageView.Mode = mdSelect) then
  4188.     begin
  4189.       x := OldRect.Left; y := OldRect.Top;
  4190.       if FUnits = ruPixels then
  4191.         s := IntToStr(x) + ';' + IntToStr(y) else
  4192.         s := FloatToStrF(PointsToUnits(x), ffFixed, 4, 2) + '; ' +
  4193.           FloatToStrF(PointsToUnits(y), ffFixed, 4, 2);
  4194.       TextOut(20, 1, s);
  4195.     end
  4196.   end;
  4197. end;
  4198.  
  4199. procedure TfrDesignerForm.ShowMemoEditor(Sender: TObject);
  4200. var
  4201.   t: TfrView;
  4202. begin
  4203.   if Sender = nil then
  4204.     t := Objects[TopSelected] else
  4205.     t := TfrView(Sender);
  4206.   with TfrEditorForm.Create(Self) do
  4207.   begin
  4208.     if ShowEditor(t) = mrOk then
  4209.     begin
  4210.       PageView.DrawPage(dmSelection);
  4211.       PageView.Draw(TopSelected);
  4212.     end;
  4213.     Free;
  4214.   end;
  4215.   ActiveControl := nil;
  4216. end;
  4217.  
  4218. procedure TfrDesignerForm.ShowEditor;
  4219. var
  4220.   t: TfrView;
  4221.   bt: TfrBandType;
  4222. begin
  4223.   t := Objects[TopSelected];
  4224.   if (DesignerRestrictions * [frdrDontEditObj] <> []) or
  4225.     ((t.Restrictions and frrfDontEditContents) <> 0) then Exit;
  4226.   if t.Typ = gtSubReport then
  4227.     CurPage := (t as TfrSubReportView).SubPage
  4228.   else if t.Typ <> gtBand then
  4229.   begin
  4230.     PageView.DrawPage(dmSelection);
  4231.     t.ShowEditor;
  4232.     PageView.Draw(TopSelected);
  4233.   end
  4234.   else
  4235.   begin
  4236.     PageView.DrawPage(dmSelection);
  4237.     bt := (t as TfrBandView).BandType;
  4238.     if bt in [btMasterData, btDetailData, btSubDetailData] then
  4239.       with TfrBandEditorForm.Create(nil) do
  4240.       begin
  4241.         ShowEditor(t);
  4242.         Free;
  4243.       end
  4244.     else if bt = btGroupHeader then
  4245.       with TfrGroupEditorForm.Create(nil) do
  4246.       begin
  4247.         ShowEditor(t);
  4248.         Free;
  4249.       end
  4250.     else if bt = btCrossData then
  4251.       with TfrVBandEditorForm.Create(nil) do
  4252.       begin
  4253.         ShowEditor(t);
  4254.         Free;
  4255.       end
  4256.     else
  4257.       PageView.DFlag := False;
  4258.     PageView.Draw(TopSelected);
  4259.   end;
  4260.   ShowContent;
  4261.   ShowPosition;
  4262.   ActiveControl := nil;
  4263. end;
  4264.  
  4265. //-------------------------------------------------------------- undo/redo -----
  4266.  
  4267. procedure TfrDesignerForm.Undo;
  4268. var
  4269.   n: Integer;
  4270. begin
  4271.   n := CurPage;
  4272.   AddRedo;
  4273.   PageView.DisableDraw := True;
  4274.   UndoBuffer.GetUndo(CurReport);
  4275.   if n < CurReport.Pages.Count then
  4276.     CurPage := n else
  4277.     CurPage := 0;
  4278.   ResetSelection;
  4279.   PageView.DisableDraw := False;
  4280.   RedrawPage;
  4281.   N46.Enabled := UndoBuffer.FUndo.Count > 0;
  4282.   UndoB.Enabled := N46.Enabled;
  4283. end;
  4284.  
  4285. procedure TfrDesignerForm.Redo;
  4286. var
  4287.   n: Integer;
  4288. begin
  4289.   n := CurPage;
  4290.   UndoBuffer.AddUndo(CurReport);
  4291.   PageView.DisableDraw := True;
  4292.   UndoBuffer.GetRedo(CurReport);
  4293.   if n < CurReport.Pages.Count then
  4294.     CurPage := n else
  4295.     CurPage := 0;
  4296.   ResetSelection;
  4297.   PageView.DisableDraw := False;
  4298.   RedrawPage;
  4299.   N46.Enabled := True;
  4300.   UndoB.Enabled := True;
  4301.   N48.Enabled := UndoBuffer.FRedo.Count > 0;
  4302.   RedoB.Enabled := N48.Enabled;
  4303. end;
  4304.  
  4305. procedure TfrDesignerForm.AddUndo;
  4306. begin
  4307.   UndoBuffer.AddUndo(CurReport);
  4308.   UndoBuffer.ClearRedo;
  4309.   N46.Enabled := True;
  4310.   UndoB.Enabled := True;
  4311.   N48.Enabled := False;
  4312.   RedoB.Enabled := False;
  4313.   Modified := True;
  4314. end;
  4315.  
  4316. procedure TfrDesignerForm.AddRedo;
  4317. begin
  4318.   UndoBuffer.AddRedo(CurReport);
  4319.   N48.Enabled := True;
  4320.   RedoB.Enabled := True;
  4321.   Modified := True;
  4322. end;
  4323.  
  4324. procedure TfrDesignerForm.ClearUndo;
  4325. begin
  4326.   UndoBuffer.ClearUndo;
  4327.   N46.Enabled := False;
  4328.   UndoB.Enabled := False;
  4329. end;
  4330.  
  4331. procedure TfrDesignerForm.ClearRedo;
  4332. begin
  4333.   UndoBuffer.ClearRedo;
  4334.   N48.Enabled := False;
  4335.   RedoB.Enabled := False;
  4336. end;
  4337.  
  4338. //------------------------------------------------------------------------------
  4339.  
  4340. procedure TfrDesignerForm.BeforeChange;
  4341. begin
  4342.   AddUndo;
  4343. end;
  4344.  
  4345. procedure TfrDesignerForm.AfterChange;
  4346. begin
  4347.   PageView.DrawPage(dmSelection);
  4348.   PageView.Draw(TopSelected);
  4349.   FillInspFields;
  4350.   InspForm.ItemsChanged;
  4351. end;
  4352.  
  4353. procedure TfrDesignerForm.ZB1Click(Sender: TObject);   // go up
  4354. var
  4355.   i, j, n: Integer;
  4356.   t: TfrView;
  4357. begin
  4358.   AddUndo;
  4359.   n := Objects.Count; i := 0; j := 0;
  4360.   while j < n do
  4361.   begin
  4362.     t := Objects[i];
  4363.     if t.Selected and (DesignerRestrictions * [frdrDontMoveObj] = []) and
  4364.       ((t.Restrictions and frrfDontMove) = 0) then
  4365.     begin
  4366.       Objects.Delete(i);
  4367.       Objects.Add(t);
  4368.     end
  4369.     else
  4370.       Inc(i);
  4371.     Inc(j);
  4372.   end;
  4373.   SendBandsToDown;
  4374.   RedrawPage;
  4375. end;
  4376.  
  4377. procedure TfrDesignerForm.ZB2Click(Sender: TObject);    // go down
  4378. var
  4379.   t: TfrView;
  4380.   i, j, n: Integer;
  4381. begin
  4382.   AddUndo;
  4383.   n := Objects.Count; j := 0; i := n - 1;
  4384.   while j < n do
  4385.   begin
  4386.     t := Objects[i];
  4387.     if t.Selected and (DesignerRestrictions * [frdrDontMoveObj] = []) and
  4388.       ((t.Restrictions and frrfDontMove) = 0) then
  4389.     begin
  4390.       Objects.Delete(i);
  4391.       Objects.Insert(0, t);
  4392.     end
  4393.     else
  4394.       Dec(i);
  4395.     Inc(j);
  4396.   end;
  4397.   SendBandsToDown;
  4398.   RedrawPage;
  4399. end;
  4400.  
  4401. procedure TfrDesignerForm.PgB1Click(Sender: TObject); // add page
  4402. begin
  4403.   ResetSelection;
  4404.   AddPage;
  4405. end;
  4406.  
  4407. procedure TfrDesignerForm.PgB2Click(Sender: TObject); // remove page
  4408. begin
  4409.   if CurReport.Pages.Count > 1 then
  4410.     if Application.MessageBox((SRemovePg),
  4411.       (SConfirm), [smbYes, smbNo], smsWarning) = smbYes then
  4412.       RemovePage(CurPage);
  4413. end;
  4414.  
  4415. procedure TfrDesignerForm.PgB4Click(Sender: TObject); // add dialog page
  4416. begin
  4417.   if DesignerRestrictions * [frdrDontCreatePage] <> [] then Exit;
  4418.   AddUndo;
  4419.   CurReport.Pages.Add;
  4420.   Page := CurReport.Pages[CurReport.Pages.Count - 1];
  4421.   Page.CreateUniqueName;
  4422.   Page.PageType := ptDialog;
  4423.   Modified := True;
  4424.   CurPage := CurReport.Pages.Count - 1;
  4425. end;
  4426.  
  4427. procedure TfrDesignerForm.OB1Click(Sender: TObject);
  4428. begin
  4429.   ObjRepeat := False;
  4430. end;
  4431.  
  4432. procedure TfrDesignerForm.OB2MouseDown(Sender: TObject; Button: TMouseButton;
  4433.   Shift: TShiftState; X, Y: Integer);
  4434. begin
  4435.   ObjRepeat := ssShift in Shift;
  4436.   PageView.Cursor := crDefault;
  4437. end;
  4438.  
  4439. procedure TfrDesignerForm.CutBClick(Sender: TObject); //cut
  4440. begin
  4441.   AddUndo;
  4442.   CutToClipboard;
  4443.   FirstSelected := nil;
  4444.   EnableControls;
  4445.   ShowPosition;
  4446.   RedrawPage;
  4447. end;
  4448.  
  4449. procedure TfrDesignerForm.CopyBClick(Sender: TObject); //copy
  4450. begin
  4451.   CopyToClipboard;
  4452.   EnableControls;
  4453. end;
  4454.  
  4455. procedure TfrDesignerForm.PstBClick(Sender: TObject); //paste
  4456. var
  4457.   i, minx, miny: Integer;
  4458.   t: TfrView;
  4459.   b: Byte;
  4460.   m: TMemoryStream;
  4461.   Band: TfrView;
  4462.  
  4463.   procedure UnselectLeaveBand;
  4464.   var
  4465.     i: Integer;
  4466.   begin
  4467.     SelNum := 0;
  4468.     for i := 0 to Objects.Count - 1 do
  4469.       if TfrView(Objects[i]).Typ <> gtBand then
  4470.           TfrView(Objects[i]).Selected := False;
  4471.   end;
  4472.  
  4473.   procedure CreateName(t: TfrView);
  4474.   begin
  4475.     if CurReport.FindObject(t.Name) <> nil then
  4476.       t.CreateUniqueName;
  4477.     t.Prop['Name'] := t.Name;
  4478.   end;
  4479.  
  4480. begin
  4481.   if DesignerRestrictions * [frdrDontCreateObj] <> [] then Exit;
  4482.   AddUndo;
  4483.   UnselectLeaveBand;
  4484.   if not IsBandsSelect(Band) then
  4485.     Band := nil else
  4486.     Band.Selected := False;
  4487.   SelNum := 0;
  4488.   minx := 32767; miny := 32767;
  4489.   with ClipBd do
  4490.     for i := 0 to Count - 1 do
  4491.     begin
  4492.       m := Items[i];
  4493.       m.Position := 0;
  4494.       b := frReadByte(m);
  4495.       t := frCreateObject(b, frReadString(m));
  4496.       frVersion := frCurrentVersion;
  4497.       t.LoadFromStream(m);
  4498.       if t.x < minx then minx := t.x;
  4499.       if t.y < miny then miny := t.y;
  4500.       t.Free;
  4501.     end;
  4502.  
  4503.   for i := 0 to ClipBd.Count - 1 do
  4504.   begin
  4505.     m := ClipBd.Items[i];
  4506.     m.Position := 0;
  4507.     b := frReadByte(m);
  4508.     t := frCreateObject(b, frReadString(m));
  4509.     frVersion := frCurrentVersion;
  4510.     t.LoadFromStream(m);
  4511.     CreateName(t);
  4512.     if t.Typ = gtBand then
  4513.       if not (TfrBandType(t.FrameTyp) in [btMasterHeader..btSubDetailFooter,
  4514.                                           btGroupHeader, btGroupFooter]) and
  4515.         frCheckBand(TfrBandType(t.FrameTyp)) then
  4516.       begin
  4517.         t.Free;
  4518.         continue;
  4519.       end;
  4520.     if PageView.Left < 0 then
  4521.       t.x := t.x - minx + ((-PageView.Left) div GridSizeX * GridSizeX) else
  4522.       t.x := t.x - minx;
  4523.  
  4524.     if PageView.Top < 0 then
  4525.       t.y := t.y - miny + ((-PageView.Top) div GridSizeY * GridSizeY) else
  4526.       t.y := t.y - miny;
  4527.     if Band <> nil then
  4528.       t.y := band.y;
  4529.     t.Selected := True;
  4530.     Inc(SelNum);
  4531.     Objects.Add(t);
  4532.   end;
  4533.   SelectionChanged;
  4534.   SendBandsToDown;
  4535.   PageView.GetMultipleSelected;
  4536.   RedrawPage;
  4537. end;
  4538.  
  4539. procedure TfrDesignerForm.UndoBClick(Sender: TObject); // undo
  4540. begin
  4541.   Undo;
  4542. end;
  4543.  
  4544. procedure TfrDesignerForm.RedoBClick(Sender: TObject); // redo
  4545. begin
  4546.   Redo;
  4547. end;
  4548.  
  4549. procedure TfrDesignerForm.SelAllBClick(Sender: TObject); // select all
  4550. begin
  4551.   PageView.DrawPage(dmSelection);
  4552.   SelectAll;
  4553.   PageView.GetMultipleSelected;
  4554.   PageView.DrawPage(dmSelection);
  4555.   SelectionChanged;
  4556. end;
  4557.  
  4558. procedure TfrDesignerForm.ExitBClick(Sender: TObject);
  4559. begin
  4560.   ModalResult := mrOk;
  4561.   Close;
  4562. end;
  4563.  
  4564.  
  4565. procedure TfrDesignerForm.N5Click(Sender: TObject); // popup delete command
  4566. begin
  4567.   DeleteObjects;
  4568. end;
  4569.  
  4570. procedure TfrDesignerForm.N6Click(Sender: TObject); // popup edit command
  4571. begin
  4572.   ShowEditor;
  4573. end;
  4574.  
  4575. procedure TfrDesignerForm.FileBtn1Click(Sender: TObject); // create new
  4576. var
  4577.   w: TMessageButton;
  4578. begin
  4579.   if DesignerRestrictions * [frdrDontCreateReport] <> [] then Exit;
  4580.   if Modified then
  4581.   begin
  4582.     w := Application.MessageBox((SSaveChanges) + ' ' + (STo) + ' ' +
  4583.       ExtractFileName(CurDocName) + '?',
  4584.       (SConfirm), [smbYes, smbNo, smbCancel], smsWarning);
  4585.     if w = smbCancel then Exit;
  4586.     if w = smbYes then
  4587.     begin
  4588.       FileBtn3Click(nil);
  4589.       if not WasOk then Exit;
  4590.     end;
  4591.   end;
  4592.   ClearUndo;
  4593.   ClearRedo;
  4594.   CurReport.Clear;
  4595.   CurReport.Pages.Add;
  4596.   CurReport.Pages[CurReport.Pages.Count - 1].CreateUniqueName;
  4597.   CurPage := 0;
  4598.   CurDocName := (SUntitled);
  4599.   Modified := False;
  4600.   CurReport.ComponentModified := True;
  4601.   if frFieldsDialog <> nil then
  4602.     frFieldsDialog.RefreshData;
  4603. end;
  4604.  
  4605. procedure TfrDesignerForm.N23Click(Sender: TObject); // create new from template
  4606. begin
  4607.   if DesignerComp <> nil then
  4608.     frTemplateDir := DesignerComp.TemplateDir;
  4609.   if DesignerRestrictions * [frdrDontCreateReport] <> [] then Exit;
  4610.   with TfrTemplForm.Create(nil) do
  4611.   begin
  4612.     if ShowModal = mrOk then
  4613.     begin
  4614.       ClearUndo;
  4615.       ClearRedo;
  4616.       CurReport.LoadTemplate(TemplName, nil, nil, True);
  4617.       CurDocName := (SUntitled);
  4618.       CurPage := 0; // do all
  4619.     end;
  4620.     Free;
  4621.   end;
  4622. end;
  4623.  
  4624. procedure TfrDesignerForm.FileBtn2Click(Sender: TObject); // open
  4625. var
  4626.   w: TMessageButton;
  4627.   rName: String;
  4628.   Opened: Boolean;
  4629. begin
  4630.   if DesignerRestrictions * [frdrDontLoadReport] <> [] then Exit;
  4631.   w := smbNo;
  4632.   if Modified then
  4633.     w := Application.MessageBox((SSaveChanges) + ' ' + (STo) + ' ' +
  4634.       ExtractFileName(CurDocName) + '?',
  4635.       (SConfirm), [smbYes, smbNo, smbCancel], smsWarning);
  4636.   if w = smbCancel then Exit;
  4637.   if w = smbYes then
  4638.   begin
  4639.     FileBtn3Click(nil);
  4640.     if not WasOk then Exit;
  4641.   end;
  4642.  
  4643.   PageView.DisableDraw := True;
  4644.   Opened := True;
  4645.   if (DesignerComp <> nil) and Assigned(DesignerComp.OnLoadReport) then
  4646.   begin
  4647.     rName := '';
  4648.     DesignerComp.OnLoadReport(CurReport, rName, Opened);
  4649.   end
  4650.   else
  4651.   begin
  4652.     OpenDialog1.Filter :=
  4653.       (SFormFile) + ' (*.frf)|*.frf|' +
  4654.       (SDictFile) + ' (*.frd)|*.frd';
  4655.  
  4656.     Opened := OpenDialog1.Execute;
  4657.     rName := OpenDialog1.FileName;
  4658.     if Opened then
  4659.       if OpenDialog1.FilterIndex = 1 then
  4660.         CurReport.LoadFromFile(rName)
  4661.       else
  4662.       begin
  4663.         CurReport.Dictionary.LoadFromFile(rName);
  4664.         Opened := False;
  4665.       end;
  4666.   end;
  4667.  
  4668.   PageView.DisableDraw := False;
  4669.   if Opened then
  4670.   begin
  4671.     ClearUndo;
  4672.     ClearRedo;
  4673.     CurDocName := rName;
  4674.     Modified := False;
  4675.     CurReport.ComponentModified := True;
  4676.     CurPage := 0; // do all
  4677.     if frFieldsDialog <> nil then
  4678.       frFieldsDialog.RefreshData;
  4679.   end;
  4680. end;
  4681.  
  4682. procedure TfrDesignerForm.N20Click(Sender: TObject); // save as
  4683. var
  4684.   rName: String;
  4685.   Saved: Boolean;
  4686. begin
  4687.   if DesignerRestrictions * [frdrDontSaveReport] <> [] then Exit;
  4688.   WasOk := False;
  4689.  
  4690.   if (DesignerComp <> nil) and Assigned(DesignerComp.OnSaveReport) then
  4691.   begin
  4692.     Saved := True;
  4693.     rName := CurDocName;
  4694.     DesignerComp.OnSaveReport(CurReport, rName, True, Saved);
  4695.     if Saved then
  4696.     begin
  4697.       CurDocName := rName;
  4698.       WasOk := True;
  4699.     end;
  4700.   end
  4701.   else
  4702.   begin
  4703.     with SaveDialog1 do
  4704.     begin
  4705.       Filter := (SFormFile) + ' (*.frf)|*.frf|' +
  4706.                 (STemplFile) + ' (*.frt)|*.frt|' +
  4707.                 (SDictFile) + ' (*.frd)|*.frd';
  4708.       FileName := CurDocName;
  4709.       FilterIndex := 1;
  4710.       if Execute then
  4711.         if FilterIndex = 1 then
  4712.         begin
  4713.           rName := ChangeFileExt(FileName, '.frf');
  4714.           CurReport.SaveToFile(rName);
  4715.           CurDocName := rName;
  4716.           WasOk := True;
  4717.         end
  4718.         else if FilterIndex = 2 then
  4719.         begin
  4720.           rName := ChangeFileExt(FileName, '.frt');
  4721.           if DesignerComp <> nil then
  4722.             frTemplateDir := DesignerComp.TemplateDir;
  4723.           if frTemplateDir <> '' then
  4724.             rName := frTemplateDir + '\' + ExtractFileName(rName);
  4725.           with TfrTemplNewForm.Create(nil) do
  4726.           begin
  4727.             if ShowModal = mrOk then
  4728.             begin
  4729.               CurReport.SaveTemplate(rName, Memo1.Lines, Image1.Picture.Bitmap);
  4730.               WasOk := True;
  4731.             end;
  4732.             Free;
  4733.           end;
  4734.         end
  4735.         else
  4736.         begin
  4737.           rName := ChangeFileExt(FileName, '.frd');
  4738.           CurReport.Dictionary.SaveToFile(rName);
  4739.         end;
  4740.     end;
  4741.   end;
  4742.   if WasOk then
  4743.     Modified := False;
  4744. end;
  4745.  
  4746. procedure TfrDesignerForm.FileBtn3Click(Sender: TObject); // save
  4747. var
  4748.   rName: String;
  4749.   Saved: Boolean;
  4750. begin
  4751.   if DesignerRestrictions * [frdrDontSaveReport] <> [] then Exit;
  4752.   if CurDocName <> (SUntitled) then
  4753.   begin
  4754.     WasOk := True;
  4755.     if (DesignerComp <> nil) and Assigned(DesignerComp.OnSaveReport) then
  4756.     begin
  4757.       Saved := True;
  4758.       rName := CurDocName;
  4759.       DesignerComp.OnSaveReport(CurReport, rName, False, Saved);
  4760.       if Saved then
  4761.         Modified := False;
  4762.     end
  4763.     else
  4764.     begin
  4765.       CurReport.SaveToFile(CurDocName);
  4766.       Modified := False;
  4767.     end;
  4768.   end
  4769.   else
  4770.     N20Click(nil);
  4771. end;
  4772.  
  4773. procedure TfrDesignerForm.FormCloseQuery(Sender: TObject;
  4774.   var CanClose: Boolean);
  4775. var
  4776.   w: TMessageButton;
  4777. begin
  4778.   if (CurReport = nil) or
  4779.     ((csDesigning in CurReport.ComponentState) and CurReport.StoreInDFM) or
  4780.     not Modified or not FirstInstance or
  4781.     (DesignerRestrictions * [frdrDontSaveReport] <> []) or
  4782.     ((DesignerComp <> nil) and not DesignerComp.CloseQuery) then
  4783.     CanClose := True
  4784.   else
  4785.   begin
  4786.     w := Application.MessageBox(PChar((SSaveChanges) + ' ' + (STo) + ' ' +
  4787.       ExtractFileName(CurDocName) + '?'),
  4788.       PChar((SConfirm)), [smbYes, smbNo, smbCancel], smsWarning);
  4789.     CanClose := False;
  4790.     if w = smbNo then
  4791.     begin
  4792.       CanClose := True;
  4793.       ModalResult := mrCancel;
  4794.     end
  4795.     else if w = smbYes then
  4796.     begin
  4797.       FileBtn3Click(nil);
  4798.       CanClose := WasOk;
  4799.     end;
  4800.   end;
  4801.   if CanClose = True then
  4802.     if FirstInstance then
  4803.       frDesignerDoneModal := True else
  4804.       frDesigner1DoneModal := True;
  4805. end;
  4806.  
  4807. procedure TfrDesignerForm.PageFormCloseQuery(Sender: TObject;
  4808.   var CanClose: Boolean);
  4809. begin
  4810.   CanClose := False;
  4811. end;
  4812.  
  4813. procedure TfrDesignerForm.PageFormResize(Sender: TObject);
  4814. begin
  4815.   Page.Left := PageForm.Left;
  4816.   Page.Top := PageForm.Top;
  4817.   Page.Width := PageForm.Width;
  4818.   Page.Height := PageForm.Height;
  4819.   PageView.SetBounds(0, 0, PageForm.ClientWidth, PageForm.ClientHeight);
  4820.   Modified := True;
  4821. end;
  4822.  
  4823. procedure TfrDesignerForm.PageFormKeyDown(Sender: TObject; var Key: Word;
  4824.   Shift: TShiftState);
  4825. begin
  4826.   if (Chr(Key) = 'C') and (ssCtrl in Shift) then
  4827.     Key := key_Insert;
  4828.   if (Chr(Key) = 'X') and (ssCtrl in Shift) then
  4829.   begin
  4830.     Key := key_Delete;
  4831.     Shift := [ssShift];
  4832.   end;
  4833.   if (Chr(Key) = 'V') and (ssCtrl in Shift) then
  4834.   begin
  4835.     Key := key_Insert;
  4836.     Shift := [ssShift];
  4837.   end;
  4838.   if (Chr(Key) = 'A') and (ssCtrl in Shift) then
  4839.     SelAllBClick(nil);
  4840.   FormKeyDown(Sender, Key, Shift);
  4841. end;
  4842.  
  4843. procedure TfrDesignerForm.FileBtn4Click(Sender: TObject); // preview
  4844. var
  4845.   v: Boolean;
  4846. begin
  4847.   if CurReport is TfrCompositeReport then Exit;
  4848.   v := CurReport.ModalPreview;
  4849.   Application.ProcessMessages;
  4850.   CurReport.ModalPreview := True;
  4851.   Unselect;
  4852.   RedrawPage;
  4853.   Page := nil;
  4854.   try
  4855.     PageView.DisableDraw := True;
  4856.     InspForm.HideProperties := True;
  4857.     InspForm.ItemsChanged;
  4858.     CurReport.PrepareReport;
  4859.     CurReport.ShowPreparedReport;
  4860.   finally
  4861.     CurReport.ModalPreview := v;
  4862.     SetFocus;
  4863.     PageView.DisableDraw := False;
  4864.     InspForm.HideProperties := False;
  4865.     CurPage := CurPage;
  4866.     SelectionChanged;
  4867.     AssignDefEditors;
  4868.     if (DesignerComp <> nil) and Assigned(DesignerComp.OnShow) then
  4869.       DesignerComp.OnShow(Self);
  4870.     Screen.Cursor := crDefault;
  4871.   end;
  4872. end;
  4873.  
  4874. procedure TfrDesignerForm.N42Click(Sender: TObject); // data dictionary editor
  4875. begin
  4876.   with TfrDictForm.Create(nil) do
  4877.   begin
  4878.     Doc := CurReport;
  4879.     if ShowModal = mrOk then
  4880.     begin
  4881.       if frFieldsDialog <> nil then
  4882.         frFieldsDialog.RefreshData;
  4883.       Modified := True;
  4884.     end;
  4885.     Free;
  4886.   end;
  4887. end;
  4888.  
  4889. procedure TfrDesignerForm.PgB3Click(Sender: TObject); // page options
  4890. var
  4891.   w, h, p: Integer;
  4892.   frPgoptForm: TfrPgoptForm;
  4893. begin
  4894.   frPgoptForm := TfrPgoptForm.Create(nil);
  4895.   with frPgoptForm, Page do
  4896.   begin
  4897.     CB1.Checked := PrintToPrevPage;
  4898.     CB5.Checked := not UseMargins;
  4899.     CB2.Checked := UnlimitedHeight;
  4900.     if pgOr = poPortrait then
  4901.       RB1.Checked := True else
  4902.       RB2.Checked := True;
  4903.     ComB1.Items := Prn.PaperNames;
  4904.     ComB1.ItemIndex := Prn.GetSizeIndex(pgSize);
  4905.     E3.Text := FloatToStrF(pgMargins.Left * 5 / 18, ffGeneral, 4, 2);
  4906.     E4.Text := FloatToStrF(pgMargins.Top * 5 / 18, ffGeneral, 4, 2);
  4907.     E5.Text := FloatToStrF(pgMargins.Right * 5 / 18, ffGeneral, 4, 2);
  4908.     E6.Text := FloatToStrF(pgMargins.Bottom * 5 / 18, ffGeneral, 4, 2);
  4909.     E7.Text := FloatToStrF(ColGap * 5 / 18, ffGeneral, 4, 2);
  4910.     Edit1.Text := IntToStr(ColCount);
  4911.     WasOk := False;
  4912.     if (ShowModal = mrOk) and (DesignerRestrictions * [frdrDontEditPage] = []) then
  4913.     begin
  4914.       Modified := True;
  4915.       WasOk := True;
  4916.       PrintToPrevPage := CB1.Checked;
  4917.       UseMargins := not CB5.Checked;
  4918.       UnlimitedHeight := CB2.Checked;
  4919.       if RB1.Checked then
  4920.         pgOr := poPortrait else
  4921.         pgOr := poLandscape;
  4922.       p := Prn.PaperSizes[ComB1.ItemIndex];
  4923.       w := 0; h := 0;
  4924.       try
  4925.         pgMargins := Rect(Round(frStrToFloat(E3.Text) * 18 / 5),
  4926.                           Round(frStrToFloat(E4.Text) * 18 / 5),
  4927.                           Round(frStrToFloat(E5.Text) * 18 / 5),
  4928.                           Round(frStrToFloat(E6.Text) * 18 / 5));
  4929.         ColGap := Round(frStrToFloat(E7.Text) * 18 / 5);
  4930.       except
  4931.         on exception do
  4932.         begin
  4933.           pgMargins := Rect(0, 0, 0, 0);
  4934.           ColGap := 0;
  4935.         end;
  4936.       end;
  4937.       ColCount := StrToInt(Edit1.Text);
  4938.       ChangePaper(p, w, h, 0, pgOr);
  4939.       CurPage := CurPage; // for repaint and other
  4940.     end;
  4941.   end;
  4942.   frPgoptForm.Free;
  4943. end;
  4944.  
  4945. procedure TfrDesignerForm.N8Click(Sender: TObject); // report options
  4946. begin
  4947.   with TfrDocOptForm.Create(nil) do
  4948.   begin
  4949.     CB1.Checked := not CurReport.PrintToDefault;
  4950.     CB2.Checked := CurReport.DoublePass;
  4951.     if ShowModal = mrOk then
  4952.     begin
  4953.       CurReport.PrintToDefault := not CB1.Checked;
  4954.       CurReport.DoublePass := CB2.Checked;
  4955.       CurReport.ChangePrinter(Prn.PrinterIndex, LB1.ItemIndex);
  4956.       Modified := True;
  4957.     end;
  4958.     CurPage := CurPage;
  4959.     Free;
  4960.   end;
  4961. end;
  4962.  
  4963. procedure TfrDesignerForm.N14Click(Sender: TObject); // designer options
  4964. var
  4965.   DesOptionsForm: TfrDesOptionsForm;
  4966. begin
  4967.   DesOptionsForm := TfrDesOptionsForm.Create(nil);
  4968.   with DesOptionsForm do
  4969.   begin
  4970.     CB1.Checked := ShowGrid;
  4971.     CB2.Checked := GridAlign;
  4972.     case GridSizeX of
  4973.       4: RB1.Checked := True;
  4974.       8: RB2.Checked := True;
  4975.       18: RB3.Checked := True;
  4976.     end;
  4977.     case Units of
  4978.       ruPixels: RB6.Checked := True;
  4979.       ruMM:     RB7.Checked := True;
  4980.       ruInches: RB8.Checked := True;
  4981.     end;
  4982.     CB4.Checked := EditAfterInsert;
  4983.     CB5.Checked := ShowBandTitles;
  4984.     case PagePosition of
  4985.       alClient: RB9.Checked := True;
  4986.       alLeft:   RB10.Checked := True;
  4987.       alRight:  RB11.Checked := True;
  4988.     end;
  4989.     if ShowModal = mrOk then
  4990.     begin
  4991.       ShowGrid := CB1.Checked;
  4992.       GridAlign := CB2.Checked;
  4993.       if RB1.Checked then
  4994.         GridSizeX := 4
  4995.       else if RB2.Checked then
  4996.         GridSizeX := 8
  4997.       else
  4998.         GridSizeX := 18;
  4999.       ShapeMode := smFrame;
  5000.       if RB6.Checked then
  5001.         Units := ruPixels
  5002.       else if RB7.Checked then
  5003.         Units := ruMM
  5004.       else
  5005.         Units := ruInches;
  5006.       if RB9.Checked then
  5007.         PagePosition := alClient
  5008.       else if RB10.Checked then
  5009.         PagePosition := alLeft
  5010.       else
  5011.         PagePosition := alRight;
  5012.       EditAfterInsert := CB4.Checked;
  5013.       ShowBandTitles := CB5.Checked;
  5014.       CurPage := CurPage;
  5015.     end;
  5016.     Free;
  5017.   end;
  5018. end;
  5019.  
  5020. procedure TfrDesignerForm.GB1Click(Sender: TObject);
  5021. begin
  5022.   ShowGrid := GB1.Down;
  5023. end;
  5024.  
  5025. procedure TfrDesignerForm.GB2Click(Sender: TObject);
  5026. begin
  5027.   GridAlign := GB2.Down;
  5028. end;
  5029.  
  5030. procedure TfrDesignerForm.GB3Click(Sender: TObject);
  5031. var
  5032.   i: Integer;
  5033.   t: TfrView;
  5034. begin
  5035.   AddUndo;
  5036.   for i := 0 to Objects.Count - 1 do
  5037.   begin
  5038.     t := Objects[i];
  5039.     if t.Selected then
  5040.     begin
  5041.       t.x := Round(t.x / GridSizeX) * GridSizeX;
  5042.       t.y := Round(t.y / GridSizeY) * GridSizeY;
  5043.       t.dx := Round(t.dx / GridSizeX) * GridSizeX;
  5044.       t.dy := Round(t.dy / GridSizeY) * GridSizeY;
  5045.       if t.dx = 0 then t.dx := GridSizeX;
  5046.       if t.dy = 0 then t.dy := GridSizeY;
  5047.     end;
  5048.   end;
  5049.   RedrawPage;
  5050.   ShowPosition;
  5051.   PageView.GetMultipleSelected;
  5052. end;
  5053.  
  5054. procedure TfrDesignerForm.Tab1Change(Sender: TObject);
  5055. begin
  5056.   CurPage := Tab1.TabIndex;
  5057. end;
  5058.  
  5059. procedure TfrDesignerForm.Popup1Popup(Sender: TObject);
  5060. var
  5061.   i: Integer;
  5062.   t, t1: TfrView;
  5063.   fl: Boolean;
  5064. begin
  5065.   EnableControls;
  5066.   while Popup1.Items.Count > 7 do
  5067.     Popup1.Items.Delete(7);
  5068.  
  5069.   if SelNum = 1 then
  5070.   begin
  5071.     t := Objects[TopSelected];
  5072.     t.DefinePopupMenu(Popup1);
  5073.   end
  5074.   else if SelNum > 1 then
  5075.   begin
  5076.     t := Objects[TopSelected];
  5077.     fl := True;
  5078.     for i := 0 to Objects.Count - 1 do
  5079.     begin
  5080.       t1 := Objects[i];
  5081.       if t1.Selected then
  5082.         if not (((t is TfrMemoView) and (t1 is TfrMemoView)) or
  5083.            ((t.Typ <> gtAddIn) and (t.Typ = t1.Typ)) or
  5084.            ((t.Typ = gtAddIn) and (t.ClassName = t1.ClassName))) then
  5085.         begin
  5086.           fl := False;
  5087.           break;
  5088.         end;
  5089.     end;
  5090.     if fl and not (t.Typ = gtBand) then t.DefinePopupMenu(Popup1);
  5091.   end;
  5092.  
  5093.   SetMenuItemBitmap(N2, CutB);
  5094.   SetMenuItemBitmap(N1, CopyB);
  5095.   SetMenuItemBitmap(N3, PstB);
  5096.   SetMenuItemBitmap(N16, SelAllB);
  5097. end;
  5098.  
  5099. procedure TfrDesignerForm.N37Click(Sender: TObject);
  5100. begin // toolbars
  5101.   Pan1.Checked := Panel1.IsVisible;
  5102.   Pan2.Checked := Panel2.IsVisible;
  5103.   Pan3.Checked := Panel3.IsVisible;
  5104.   Pan4.Checked := Panel4.IsVisible;
  5105.   Pan5.Checked := InspForm.Visible;
  5106.   Pan6.Checked := Panel5.IsVisible;
  5107.   Pan7.Checked := Panel6.IsVisible;
  5108.   Pan8.Checked := frFieldsDialog <> nil;
  5109. end;
  5110.  
  5111. procedure TfrDesignerForm.Pan2Click(Sender: TObject);
  5112.   procedure SetShow(c: Array of TWinControl; i: Integer; b: Boolean);
  5113.   begin
  5114.     if c[i] is TfrToolBar then
  5115.     with c[i] as TfrToolBar do
  5116.     begin
  5117.       if IsFloat then
  5118.         FloatWindow.Visible := b
  5119.       else
  5120.       begin
  5121.         if b then
  5122.           AddToDock(Parent as TfrDock);
  5123.         Visible := b;
  5124.         (Parent as TfrDock).AdjustBounds;
  5125.       end;
  5126.     end
  5127.     else
  5128.       (c[i] as TForm).Visible := b;
  5129.   end;
  5130. begin // each toolbar
  5131.   with Sender as TMenuItem do
  5132.   begin
  5133.     Checked := not Checked;
  5134.     if Tag = 7 then // insert fields
  5135.       ShowFieldsDialog(Checked)
  5136.     else
  5137.       SetShow([Panel1, Panel2, Panel3, Panel4, Panel5, InspForm, Panel6], Tag, Checked);
  5138.   end;
  5139. end;
  5140.  
  5141. procedure TfrDesignerForm.N34Click(Sender: TObject);
  5142. begin // about box
  5143.   with TfrAboutForm.Create(nil) do
  5144.   begin
  5145.     ShowModal;
  5146.     Free;
  5147.   end;
  5148. end;
  5149.  
  5150. procedure TfrDesignerForm.Tab1MouseDown(Sender: TObject;
  5151.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  5152. begin
  5153.   GetCursorPos(LastPt);
  5154.   if Button = mbRight then
  5155.     Popup2.Popup(LastPt.X, LastPt.Y) else
  5156.     MDown := True;
  5157. end;
  5158.  
  5159. procedure TfrDesignerForm.Tab1DragOver(Sender, Source: TObject; X,
  5160.   Y: Integer; State: TDragState; var Accept: Boolean);
  5161. begin
  5162.   Accept := Source is TTabControl;
  5163. end;
  5164.  
  5165. procedure TfrDesignerForm.Tab1MouseUp(Sender: TObject;
  5166.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  5167. begin
  5168.   MDown := False;
  5169. end;
  5170.  
  5171. procedure TfrDesignerForm.Tab1MouseMove(Sender: TObject;
  5172.   Shift: TShiftState; X, Y: Integer);
  5173. begin
  5174. {  if MDown and (Abs(x - LastPt.X) > 8) then
  5175.     Tab1.BeginDrag(False);}
  5176. end;
  5177.  
  5178. procedure TfrDesignerForm.Tab1DragDrop(Sender, Source: TObject; X,
  5179.   Y: Integer);
  5180. var
  5181.   i, HitIndex: Integer;
  5182. begin
  5183.   HitIndex := Tab1.IndexOfTabAt(X, Y);
  5184.  
  5185.   if CurPage > HitIndex then
  5186.   begin
  5187.     NotifySubReports(CurPage, -1);
  5188.     for i := CurPage - 1 downto HitIndex do
  5189.       NotifySubReports(i, i + 1);
  5190.     NotifySubReports(-1, HitIndex);
  5191.   end
  5192.   else
  5193.   begin
  5194.     NotifySubReports(CurPage, -1);
  5195.     for i := CurPage + 1 to HitIndex do
  5196.       NotifySubReports(i, i - 1);
  5197.     NotifySubReports(-1, HitIndex);
  5198.   end;
  5199.  
  5200.   Tab1.Tabs.Delete(CurPage);
  5201.   if HitIndex < Tab1.Tabs.Count then
  5202.     Tab1.Tabs.Insert(HitIndex) else
  5203.     Tab1.Tabs.Add('');
  5204.  
  5205.   CurReport.Pages.Move(CurPage, HitIndex);
  5206.   SetPageTitles;
  5207.   Modified := True;
  5208.   RedrawPage;
  5209.   Tab1.TabIndex := HitIndex;
  5210. end;
  5211.  
  5212. procedure TfrDesignerForm.ShowFieldsDialog(Show: Boolean);
  5213. begin
  5214.   if Show then
  5215.   begin
  5216.     if frFieldsDialog = nil then
  5217.     begin
  5218.       frFieldsDialog := TfrInsFieldsForm.Create(Self);
  5219.       frFieldsDialog.OnHeightChanged := HeightChanged;
  5220.       frFieldsDialog.Show;
  5221.     end
  5222.     else
  5223.       frFieldsDialog.Grow;
  5224.     frFieldsDialog.SetFocus;
  5225.   end
  5226.   else
  5227.   begin
  5228.     if frFieldsDialog <> nil then
  5229.     begin
  5230.       frFieldsDialog.Free;
  5231.       frFieldsDialog := nil;
  5232.     end;
  5233.   end;
  5234. end;
  5235.  
  5236. procedure TfrDesignerForm.HeightChanged(Sender: TObject);
  5237. var
  5238.   r1, r2: TRect;
  5239.   p: TPoint;
  5240.   Panel, Pan1, Pan2: TPanel;
  5241.   h: Integer;
  5242. begin
  5243.   if (frFieldsDialog = nil) or not InspForm.Visible then Exit;
  5244.   r1 := InspForm.BoundsRect;
  5245.   r2 := frFieldsDialog.BoundsRect;
  5246.  
  5247.   if ((r1.Left >= r2.Left) and (r1.Left <= r2.Right)) or
  5248.      ((r1.Right >= r2.Left) and (r1.Right <= r2.Right)) then
  5249.   begin
  5250.     Panel := TPanel.Create(Panel7);
  5251.     Panel.Parent := Panel7;
  5252.     Panel.SetBounds(2000, 0, 10, ScrollBox1.Height - 2);
  5253.  
  5254.     Pan1 := TPanel.Create(Panel);
  5255.     Pan1.Parent := Panel;
  5256.  
  5257.     Pan2 := TPanel.Create(Panel);
  5258.     Pan2.Parent := Panel;
  5259.     Pan2.SetBounds(r2.Left, r2.Top, r2.Right - r2.Left, r2.Bottom - r2.Top);
  5260.  
  5261.     if r1.Top < r2.Top then
  5262.       Pan2.Align := alBottom else
  5263.       Pan2.Align := alTop;
  5264.     Pan1.Align := alClient;
  5265.  
  5266.     p := ScrollBox1.ClientToScreen(Point(0, -1));
  5267.     if InspForm.ClientHeight < 20 then
  5268.       h := 0 else
  5269.       h := Pan1.Height;
  5270.     InspForm.SetBounds(InspForm.Left, Pan1.Top + p.Y,
  5271.       InspForm.Width, h);
  5272.     frFieldsDialog.SetBounds(frFieldsDialog.Left, Pan2.Top + p.Y,
  5273.       frFieldsDialog.Width, Pan2.Height);
  5274.     Pan1.Free;
  5275.     Pan2.Free;
  5276.     Panel.Free;
  5277.   end;
  5278. end;
  5279.  
  5280.  
  5281. {----------------------------------------------------------------------------}
  5282. // state storing/retrieving
  5283. const
  5284.   rsGridShow = 'GridShow';
  5285.   rsGridAlign = 'GridAlign';
  5286.   rsGridSize = 'GridSize';
  5287.   rsUnits = 'Units';
  5288.   rsButtons = 'GrayButtons';
  5289.   rsEdit = 'EditAfterInsert';
  5290.   rsSelection = 'Selection';
  5291.   rsPagePos = 'PagePosition';
  5292.   rsBandTitles = 'BandTitles';
  5293.   rsProps = 'LocalizedPropNames';
  5294.   rsPgHeight = 'UnlimitedHeight';
  5295.  
  5296.  
  5297. procedure TfrDesignerForm.SaveState;
  5298. var
  5299.   Nm: String;
  5300.  
  5301.   procedure DoSaveToolbars(t: Array of TfrToolBar);
  5302.   var
  5303.     i: Integer;
  5304.   begin
  5305.     for i := Low(t) to High(t) do
  5306.     begin
  5307.       if FirstInstance or (t[i] <> Panel6) then
  5308.         SaveToolbarPosition(frIni, t[i]);
  5309.       t[i].IsVisible := False;
  5310.     end;
  5311.   end;
  5312.  
  5313. begin
  5314.   Nm := rsForm + ClassName;
  5315.   frIni.WriteBool(Nm, rsGridShow, ShowGrid);
  5316.   frIni.WriteBool(Nm, rsGridAlign, GridAlign);
  5317.   frIni.WriteInteger(Nm, rsGridSize, GridSizeX);
  5318.   frIni.WriteInteger(Nm, rsUnits, Word(Units));
  5319.   frIni.WriteBool(Nm, rsEdit, EditAfterInsert);
  5320.   frIni.WriteInteger(Nm, rsSelection, Integer(ShapeMode));
  5321.   frIni.WriteInteger(Nm, rsPagePos, Integer(PagePosition));
  5322.   frIni.WriteBool(Nm, rsBandTitles, ShowBandTitles);
  5323.   frIni.WriteBool(rsForm + InspForm.ClassName, rsVisible, InspForm.Visible);
  5324.   frIni.WriteInteger(rsForm + InspForm.ClassName, 'SplitPos', InspForm.SplitterPos);
  5325.   frIni.WriteBool(rsForm + TfrInsFieldsForm.ClassName, rsVisible,
  5326.     (frFieldsDialog <> nil) and frFieldsDialog.Visible);
  5327.   frIni.WriteBool(Nm, rsPgHeight, UnlimitedHeight);
  5328.  
  5329.   DoSaveToolbars([Panel1, Panel2, Panel3, Panel4, Panel5, Panel6]);
  5330.   SaveFormPosition(frIni, InspForm);
  5331.   SaveFormPosition(frIni, Self);
  5332. end;
  5333.  
  5334. procedure TfrDesignerForm.RestoreState;
  5335. var
  5336.   Nm: String;
  5337.  
  5338.   procedure DoRestoreToolbars(t: Array of TfrToolBar);
  5339.   var
  5340.     i: Integer;
  5341.   begin
  5342.     for i := Low(t) to High(t) do
  5343.       RestoreToolbarPosition(frIni, t[i]);
  5344.   end;
  5345.  
  5346. begin
  5347.   Nm := rsForm + ClassName;
  5348.   GridSizeX := frIni.ReadInteger(Nm, rsGridSize, 4);
  5349.   if GridSizeX = 0 then
  5350.     GridSizeX := 4;
  5351.   GridAlign := frIni.ReadBool(Nm, rsGridAlign, True);
  5352.   ShowGrid := frIni.ReadBool(Nm, rsGridShow, True);
  5353.   Units := TfrReportUnits(frIni.ReadInteger(Nm, rsUnits, 0));
  5354.   EditAfterInsert := frIni.ReadBool(Nm, rsEdit, True);
  5355.   ShapeMode := smFrame;//TfrShapeMode(frIni.ReadInteger(Nm, rsSelection, 1));
  5356.   PagePosition := TAlign(frIni.ReadInteger(Nm, rsPagePos, 5));
  5357.   ShowBandTitles := frIni.ReadBool(Nm, rsBandTitles, True);
  5358.   UnlimitedHeight := frIni.ReadBool(Nm, rsPgHeight, False);
  5359.   RestoreFormPosition(frIni, InspForm);
  5360.   InspForm.SplitterPos := frIni.ReadInteger(rsForm + InspForm.ClassName, 'SplitPos', 75);
  5361.   if InspForm.SplitterPos < 20 then
  5362.     InspForm.SplitterPos := 20;
  5363.   InspForm.Visible := frIni.ReadBool(rsForm + InspForm.ClassName, rsVisible, True);
  5364.  
  5365.   if FirstInstance then
  5366.     if frIni.ReadBool(rsForm + TfrInsFieldsForm.ClassName, rsVisible, True) then
  5367.       ShowFieldsDialog(True);
  5368.  
  5369.   DoRestoreToolbars([Panel1, Panel2, Panel3, Panel4, Panel5, Panel6]);
  5370.   if Panel6.Height < 26 then
  5371.     Panel6.Height := 26;
  5372.   if Panel6.Width < 26 then
  5373.     Panel6.Width := 26;
  5374.   if Panel6.ControlCount < 2 then
  5375.     Panel6.Hide;
  5376.   frDock1.AdjustBounds;
  5377.   frDock2.AdjustBounds;
  5378.   frDock3.AdjustBounds;
  5379.   frDock4.AdjustBounds;
  5380.   RestoreFormPosition(frIni, Self);
  5381. end;
  5382.  
  5383.  
  5384. {----------------------------------------------------------------------------}
  5385. // menu bitmaps
  5386. procedure TfrDesignerForm.SetMenuItemBitmap(AMenuItem: TMenuItem; ABtn: TToolButton);
  5387. begin
  5388.   AMenuItem.ImageIndex := ABtn.ImageIndex;
  5389. end;
  5390.  
  5391. procedure TfrDesignerForm.SetMenuBitmaps;
  5392. var
  5393.   i: Integer;
  5394. begin
  5395.   MainMenu1.Images := MainImages;
  5396.   Popup1.Images := MainImages;
  5397.   Popup2.Images := MainImages;
  5398.  
  5399.   SetMenuItemBitmap(N23, FileBtn1);
  5400.   SetMenuItemBitmap(N19, FileBtn2);
  5401.   SetMenuItemBitmap(N20, FileBtn3);
  5402.   SetMenuItemBitmap(N39, FileBtn4);
  5403.  
  5404.   SetMenuItemBitmap(N46, UndoB);
  5405.   SetMenuItemBitmap(N48, RedoB);
  5406.   SetMenuItemBitmap(N11, CutB);
  5407.   SetMenuItemBitmap(N12, CopyB);
  5408.   SetMenuItemBitmap(N13, PstB);
  5409.   SetMenuItemBitmap(N28, SelAllB);
  5410.   SetMenuItemBitmap(N29, PgB1);
  5411.   SetMenuItemBitmap(N30, PgB2);
  5412.   SetMenuItemBitmap(N32, ZB1);
  5413.   SetMenuItemBitmap(N33, ZB2);
  5414.   SetMenuItemBitmap(N35, HelpBtn);
  5415.   SetMenuItemBitmap(N15, PgB4);
  5416.   for i := 0 to MastMenu.Count - 1 do
  5417.     MastMenu.Items[i].Bitmap := TfrTBButton(Panel6.Controls[i + 1]).Glyph;
  5418.  
  5419.   SetMenuItemBitmap(N41, PgB1);
  5420.   SetMenuItemBitmap(N43, PgB2);
  5421.   SetMenuItemBitmap(N44, PgB3);
  5422.   SetMenuItemBitmap(N45, PgB4);
  5423. end;
  5424.  
  5425. {----------------------------------------------------------------------------}
  5426. // alignment palette
  5427. function GetFirstSelected: TfrView;
  5428. begin
  5429.   if FirstSelected <> nil then
  5430.     Result := FirstSelected else
  5431.     Result := Objects[TopSelected];
  5432. end;
  5433.  
  5434. function GetLeftObject: Integer;
  5435. var
  5436.   i: Integer;
  5437.   t: TfrView;
  5438.   x: Integer;
  5439. begin
  5440.   t := Objects[TopSelected];
  5441.   x := t.x;
  5442.   Result := TopSelected;
  5443.   for i := 0 to Objects.Count - 1 do
  5444.   begin
  5445.     t := Objects[i];
  5446.     if t.Selected then
  5447.       if t.x < x then
  5448.       begin
  5449.         x := t.x;
  5450.         Result := i;
  5451.       end;
  5452.   end;
  5453. end;
  5454.  
  5455. function GetRightObject: Integer;
  5456. var
  5457.   i: Integer;
  5458.   t: TfrView;
  5459.   x: Integer;
  5460. begin
  5461.   t := Objects[TopSelected];
  5462.   x := t.x + t.dx;
  5463.   Result := TopSelected;
  5464.   for i := 0 to Objects.Count - 1 do
  5465.   begin
  5466.     t := Objects[i];
  5467.     if t.Selected then
  5468.       if t.x + t.dx > x then
  5469.       begin
  5470.         x := t.x + t.dx;
  5471.         Result := i;
  5472.       end;
  5473.   end;
  5474. end;
  5475.  
  5476. function GetTopObject: Integer;
  5477. var
  5478.   i: Integer;
  5479.   t: TfrView;
  5480.   y: Integer;
  5481. begin
  5482.   t := Objects[TopSelected];
  5483.   y := t.y;
  5484.   Result := TopSelected;
  5485.   for i := 0 to Objects.Count - 1 do
  5486.   begin
  5487.     t := Objects[i];
  5488.     if t.Selected then
  5489.       if t.y < y then
  5490.       begin
  5491.         y := t.y;
  5492.         Result := i;
  5493.       end;
  5494.   end;
  5495. end;
  5496.  
  5497. function GetBottomObject: Integer;
  5498. var
  5499.   i: Integer;
  5500.   t: TfrView;
  5501.   y: Integer;
  5502. begin
  5503.   t := Objects[TopSelected];
  5504.   y := t.y + t.dy;
  5505.   Result := TopSelected;
  5506.   for i := 0 to Objects.Count - 1 do
  5507.   begin
  5508.     t := Objects[i];
  5509.     if t.Selected then
  5510.       if t.y + t.dy > y then
  5511.       begin
  5512.         y := t.y + t.dy;
  5513.         Result := i;
  5514.       end;
  5515.   end;
  5516. end;
  5517.  
  5518. procedure TfrDesignerForm.Align1Click(Sender: TObject);
  5519. var
  5520.   i: Integer;
  5521.   t: TfrView;
  5522.   x: Integer;
  5523.   band: TfrView;
  5524.   s: TStringList;
  5525.   y: Integer;
  5526. begin
  5527.   if DesignerRestrictions * [frdrDontMoveObj] <> [] then Exit;
  5528.   if IsBandsSelect(band) then
  5529.   begin
  5530.     BeforeChange;
  5531.     s := TStringList.Create;
  5532.     s.Sorted := True;
  5533.     s.Duplicates := dupAccept;
  5534.     t := Objects[GetLeftObject];
  5535.     x := Page.LeftMargin;
  5536.     y := t.y;
  5537.     for i := 0 to Objects.Count - 1 do
  5538.     begin
  5539.       t := Objects[i];
  5540.       if (t.y >= band.y) and (t.y + t.dy <= band.y + band.dy) and
  5541.          (t.Typ <> gtBand) then
  5542.         s.AddObject(Format('%4.4d', [t.x]), t);
  5543.     end;
  5544.     for i := 0 to s.Count - 1 do
  5545.     begin
  5546.       t := TfrView(s.Objects[i]);
  5547.       if (t.Restrictions and frrfDontMove) = 0 then
  5548.       begin
  5549.         t.x := x;
  5550.         t.y := y;
  5551.       end;
  5552.       x := x + t.dx;
  5553.     end;
  5554.     s.Free;
  5555.     PageView.GetMultipleSelected;
  5556.     RedrawPage;
  5557.     Exit;
  5558.   end;
  5559.  
  5560.   if SelNum < 2 then Exit;
  5561.   BeforeChange;
  5562.   t := GetFirstSelected;
  5563.   x := t.x;
  5564.   for i := 0 to Objects.Count - 1 do
  5565.   begin
  5566.     t := Objects[i];
  5567.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5568.       t.x := x;
  5569.   end;
  5570.   PageView.GetMultipleSelected;
  5571.   FillInspFields;
  5572.   InspForm.ItemsChanged;
  5573.   RedrawPage;
  5574. end;
  5575.  
  5576. procedure TfrDesignerForm.Align6Click(Sender: TObject);
  5577. var
  5578.   i: Integer;
  5579.   t: TfrView;
  5580.   y: Integer;
  5581. begin
  5582.   if (SelNum < 2) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5583.   BeforeChange;
  5584.   t := GetFirstSelected;
  5585.   y := t.y;
  5586.   for i := 0 to Objects.Count - 1 do
  5587.   begin
  5588.     t := Objects[i];
  5589.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5590.       t.y := y;
  5591.   end;
  5592.   PageView.GetMultipleSelected;
  5593.   FillInspFields;
  5594.   InspForm.ItemsChanged;
  5595.   RedrawPage;
  5596. end;
  5597.  
  5598. procedure TfrDesignerForm.Align5Click(Sender: TObject);
  5599. var
  5600.   i: Integer;
  5601.   t: TfrView;
  5602.   x: Integer;
  5603.   band: TfrView;
  5604.   s: TStringList;
  5605.   y: Integer;
  5606. begin
  5607.   if DesignerRestrictions * [frdrDontMoveObj] <> [] then Exit;
  5608.   if IsBandsSelect(band) then
  5609.   begin
  5610.     BeforeChange;
  5611.     s := TStringList.Create;
  5612.     s.Sorted := True;
  5613.     s.Duplicates := dupAccept;
  5614.     t := Objects[GetRightObject];
  5615.     x := Page.RightMargin;
  5616.     y := t.y;
  5617.     for i := 0 to Objects.Count - 1 do
  5618.     begin
  5619.       t := Objects[i];
  5620.       if (t.y >= band.y) and (t.y + t.dy <= band.y + band.dy) and
  5621.          (t.Typ <> gtBand) then
  5622.         s.AddObject(Format('%4.4d', [t.x]), t);
  5623.     end;
  5624.     for i := s.Count - 1 downto 0 do
  5625.     begin
  5626.       t := TfrView(s.Objects[i]);
  5627.       if (t.Restrictions and frrfDontMove) = 0 then
  5628.       begin
  5629.         t.x := x - t.dx;
  5630.         t.y := y;
  5631.       end;
  5632.       x := x - t.dx;
  5633.     end;
  5634.     s.Free;
  5635.     PageView.GetMultipleSelected;
  5636.     RedrawPage;
  5637.     Exit;
  5638.   end;
  5639.  
  5640.   if SelNum < 2 then Exit;
  5641.   BeforeChange;
  5642.   t := GetFirstSelected;
  5643.   x := t.x + t.dx;
  5644.   for i := 0 to Objects.Count - 1 do
  5645.   begin
  5646.     t := Objects[i];
  5647.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5648.       t.x := x - t.dx;
  5649.   end;
  5650.   PageView.GetMultipleSelected;
  5651.   FillInspFields;
  5652.   InspForm.ItemsChanged;
  5653.   RedrawPage;
  5654. end;
  5655.  
  5656. procedure TfrDesignerForm.Align10Click(Sender: TObject);
  5657. var
  5658.   i: Integer;
  5659.   t: TfrView;
  5660.   y: Integer;
  5661. begin
  5662.   if (SelNum < 2) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5663.   BeforeChange;
  5664.   t := GetFirstSelected;
  5665.   y := t.y + t.dy;
  5666.   for i := 0 to Objects.Count - 1 do
  5667.   begin
  5668.     t := Objects[i];
  5669.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5670.       t.y := y - t.dy;
  5671.   end;
  5672.   PageView.GetMultipleSelected;
  5673.   FillInspFields;
  5674.   InspForm.ItemsChanged;
  5675.   RedrawPage;
  5676. end;
  5677.  
  5678. procedure TfrDesignerForm.Align2Click(Sender: TObject);
  5679. var
  5680.   i: Integer;
  5681.   t: TfrView;
  5682.   x: Integer;
  5683. begin
  5684.   if (SelNum < 2) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5685.   BeforeChange;
  5686.   t := GetFirstSelected;
  5687.   x := t.x + t.dx div 2;
  5688.   for i := 0 to Objects.Count - 1 do
  5689.   begin
  5690.     t := Objects[i];
  5691.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5692.       t.x := x - t.dx div 2;
  5693.   end;
  5694.   PageView.GetMultipleSelected;
  5695.   FillInspFields;
  5696.   InspForm.ItemsChanged;
  5697.   RedrawPage;
  5698. end;
  5699.  
  5700. procedure TfrDesignerForm.Align7Click(Sender: TObject);
  5701. var
  5702.   i: Integer;
  5703.   t: TfrView;
  5704.   y: Integer;
  5705. begin
  5706.   if (SelNum < 2) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5707.   BeforeChange;
  5708.   t := GetFirstSelected;
  5709.   y := t.y + t.dy div 2;
  5710.   for i := 0 to Objects.Count - 1 do
  5711.   begin
  5712.     t := Objects[i];
  5713.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5714.       t.y := y - t.dy div 2;
  5715.   end;
  5716.   PageView.GetMultipleSelected;
  5717.   FillInspFields;
  5718.   InspForm.ItemsChanged;
  5719.   RedrawPage;
  5720. end;
  5721.  
  5722. procedure TfrDesignerForm.Align3Click(Sender: TObject);
  5723. var
  5724.   i: Integer;
  5725.   t: TfrView;
  5726.   x: Integer;
  5727. begin
  5728.   if (SelNum = 0) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5729.   BeforeChange;
  5730.   t := Objects[GetLeftObject];
  5731.   x := t.x;
  5732.   t := Objects[GetRightObject];
  5733.   x := x + (t.x + t.dx - x - PageView.Width) div 2;
  5734.   for i := 0 to Objects.Count - 1 do
  5735.   begin
  5736.     t := Objects[i];
  5737.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5738.       Dec(t.x, x);
  5739.   end;
  5740.   PageView.GetMultipleSelected;
  5741.   FillInspFields;
  5742.   InspForm.ItemsChanged;
  5743.   RedrawPage;
  5744. end;
  5745.  
  5746. procedure TfrDesignerForm.Align8Click(Sender: TObject);
  5747. var
  5748.   i: Integer;
  5749.   t: TfrView;
  5750.   y: Integer;
  5751. begin
  5752.   if (SelNum = 0) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5753.   BeforeChange;
  5754.   t := Objects[GetTopObject];
  5755.   y := t.y;
  5756.   t := Objects[GetBottomObject];
  5757.   y := y + (t.y + t.dy - y - PageView.Height) div 2;
  5758.   for i := 0 to Objects.Count - 1 do
  5759.   begin
  5760.     t := Objects[i];
  5761.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5762.       Dec(t.y, y);
  5763.   end;
  5764.   PageView.GetMultipleSelected;
  5765.   FillInspFields;
  5766.   InspForm.ItemsChanged;
  5767.   RedrawPage;
  5768. end;
  5769.  
  5770. procedure TfrDesignerForm.Align4Click(Sender: TObject);
  5771. var
  5772.   s: TStringList;
  5773.   i, dx: Integer;
  5774.   t: TfrView;
  5775. begin
  5776.   if (SelNum < 3) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5777.   BeforeChange;
  5778.   s := TStringList.Create;
  5779.   s.Sorted := True;
  5780.   s.Duplicates := dupAccept;
  5781.   for i := 0 to Objects.Count - 1 do
  5782.   begin
  5783.     t := Objects[i];
  5784.     if t.Selected then s.AddObject(Format('%4.4d', [t.x]), t);
  5785.   end;
  5786.   dx := (TfrView(s.Objects[s.Count - 1]).x - TfrView(s.Objects[0]).x) div (s.Count - 1);
  5787.   for i := 1 to s.Count - 2 do
  5788.   begin
  5789.     t := TfrView(s.Objects[i]);
  5790.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5791.       t.x := TfrView(s.Objects[i - 1]).x + dx;
  5792.   end;
  5793.   s.Free;
  5794.   PageView.GetMultipleSelected;
  5795.   FillInspFields;
  5796.   InspForm.ItemsChanged;
  5797.   RedrawPage;
  5798. end;
  5799.  
  5800. procedure TfrDesignerForm.Align9Click(Sender: TObject);
  5801. var
  5802.   s: TStringList;
  5803.   i, dy: Integer;
  5804.   t: TfrView;
  5805. begin
  5806.   if (SelNum < 3) or (DesignerRestrictions * [frdrDontMoveObj] <> []) then Exit;
  5807.   BeforeChange;
  5808.   s := TStringList.Create;
  5809.   s.Sorted := True;
  5810.   s.Duplicates := dupAccept;
  5811.   for i := 0 to Objects.Count - 1 do
  5812.   begin
  5813.     t := Objects[i];
  5814.     if t.Selected then s.AddObject(Format('%4.4d', [t.y]), t);
  5815.   end;
  5816.   dy := (TfrView(s.Objects[s.Count - 1]).y - TfrView(s.Objects[0]).y) div (s.Count - 1);
  5817.   for i := 1 to s.Count - 2 do
  5818.   begin
  5819.     t := TfrView(s.Objects[i]);
  5820.     if t.Selected and ((t.Restrictions and frrfDontMove) = 0) then
  5821.       t.y := TfrView(s.Objects[i - 1]).y + dy;
  5822.   end;
  5823.   s.Free;
  5824.   PageView.GetMultipleSelected;
  5825.   FillInspFields;
  5826.   InspForm.ItemsChanged;
  5827.   RedrawPage;
  5828. end;
  5829.  
  5830.  
  5831. procedure TfrDesignerForm.GetDefaultSize(var dx, dy: Integer);
  5832. begin
  5833.   dx := 96;
  5834.   if GridSizeX = 18 then dx := 18 * 6;
  5835.   dy := 18;
  5836.   if GridSizeY = 18 then dy := 18;
  5837.   if LastFontSize in [12, 13] then dy := 20;
  5838.   if LastFontSize in [14..16] then dy := 24;
  5839. end;
  5840.  
  5841.  
  5842. procedure TfrDesignerForm.InsFieldsClick(Sender: TObject);
  5843. begin
  5844.   if PageType = ptDialog then Exit;
  5845.   with TfrInsertFieldsForm.Create(nil) do
  5846.   begin
  5847.     Unselect;
  5848.     if ShowModal = mrOk then
  5849.     begin
  5850.       NumberOfSelected;
  5851.       SelectionChanged;
  5852.       SendBandsToDown;
  5853.       PageView.GetMultipleSelected;
  5854.       RedrawPage;
  5855.     end;
  5856.     Free;
  5857.   end;
  5858. end;
  5859.  
  5860. procedure TfrDesignerForm.HelpBtnClick(Sender: TObject);
  5861. begin
  5862.   HelpBtn.Down := True;
  5863.   Screen.Cursor := crHelp;
  5864. //  SetCapture(Handle);
  5865.   HelpBtn.Invalidate;
  5866. end;
  5867.  
  5868. procedure TfrDesignerForm.FormMouseUp(Sender: TObject;
  5869.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  5870. var
  5871.   c: TControl;
  5872.   t: Integer;
  5873. begin
  5874.   HelpBtn.Down := False;
  5875.   Screen.Cursor := crDefault;
  5876.   c := frControlAtPos(Self, Point(X, Y));
  5877.   if (c <> nil) and (c <> HelpBtn) then
  5878.   begin
  5879.     t := c.Tag;
  5880.     if (c.Parent = Panel4) and (t > 4) then
  5881.       t := 5;
  5882.     if c.Parent = Panel4 then
  5883.       Inc(t, 430) else
  5884.       Inc(t, 400);
  5885.     Application.ContextHelp(t);
  5886.   end;
  5887. end;
  5888.  
  5889. procedure TfrDesignerForm.N22Click(Sender: TObject);
  5890. begin
  5891. //  Application.HelpCommand(HELP_FINDER, 0);
  5892. end;
  5893.  
  5894. procedure TfrDesignerForm.FormMouseWheelUp(Sender: TObject;
  5895.   Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
  5896. begin
  5897.   ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position - 8;
  5898. end;
  5899.  
  5900. procedure TfrDesignerForm.FormMouseWheelDown(Sender: TObject;
  5901.   Shift: TShiftState; MousePos: TPoint; var Handled: Boolean);
  5902. begin
  5903.   ScrollBox1.VertScrollBar.Position := ScrollBox1.VertScrollBar.Position + 8;
  5904. end;
  5905.  
  5906.  
  5907. procedure TfrDesignerForm.StatusBar1MouseDown(Sender: TObject;
  5908.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  5909. begin
  5910.   ChangeUnits := X < 75;
  5911. end;
  5912.  
  5913. procedure TfrDesignerForm.StatusBar1DblClick(Sender: TObject);
  5914. begin
  5915.   if ChangeUnits then
  5916.     if Units = ruInches then
  5917.       Units := ruPixels else
  5918.       Units := Succ(Units)
  5919. end;
  5920.  
  5921. procedure TfrDesignerForm.C2DblClick(Sender: TObject);
  5922. begin
  5923.   frFontEditor(nil);
  5924. end;
  5925.  
  5926. procedure DoInit;
  5927. begin
  5928.   frDesignerClass := TfrDesignerForm;
  5929.   ClipBd := TList.Create;
  5930.   GridBitmap := TBitmap.Create;
  5931.   with GridBitmap do
  5932.   begin
  5933.     Width := 8; Height := 8;
  5934.   end;
  5935.   LastFrameTyp := 0;
  5936.   LastFrameWidth := 1;
  5937.   LastLineWidth := 2;
  5938.   LastFillColor := clNone;
  5939.   LastFrameColor := clBlack;
  5940.   LastFontColor := clBlack;
  5941.   LastFontStyle := 0;
  5942.   LastAlignment := 0;
  5943.   LastCharset := TFontCharset(frCharset);
  5944. end;
  5945.  
  5946.  
  5947.  
  5948.  
  5949. initialization
  5950.   DoInit;
  5951.  
  5952. finalization
  5953.   ClearClipBoard;
  5954.   ClipBd.Free;
  5955.   GridBitmap.Free;
  5956.  
  5957. end.
  5958.  
  5959.