⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvglogicseditorform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvgLogicsEditor.PAS, released on 2003-01-15.

The Initial Developer of the Original Code is Andrey V. Chudin,  [chudin att yandex dott ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.

Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
Burov Dmitry, translation of russian text.

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvgLogicsEditorForm.pas,v 1.23 2004/12/25 13:20:43 marquardt Exp $

unit JvgLogicsEditorForm;

{$I jvcl.inc}

interface

uses
  Windows, Messages,
  SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, ComCtrls, ToolWin, ImgList, RichEdit, Tabs,
  {$IFDEF COMPILER6_UP}
  DesignIntf, DesignEditors, PropertyCategories,
  {$ELSE}
  DsgnIntf,
  {$ENDIF COMPILER6_UP}
  JvgLogics, JvgGroupBox;

type
  TJvgLogicsEditor = class(TComponentEditor)
    procedure ExecuteVerb(Index: Integer); override;
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
  private
    procedure ShowEditor(LogicProducer: TJvgLogicProducer);
  end;

  TJvgGroupBoxPlus = class(TJvgGroupBox)
  public
    Pt: TPoint;
    Selected: Boolean;
    LogicElement: TJvgLogicElement;
    //    fAsLogical: Boolean;
    //    constructor Create(AOwner: TComponent); override;
    //    destructor Destroy; override;
    procedure Paint; override;
  end;

  TJvgShapePlus = class(TShape)
  public
    Pt: TPoint;
    Selected: Boolean;
    CommentArea: TJvgCommentArea;
    procedure Paint; override;
  end;

  TJvgLogicsEditorMain = class(TForm)
    SB: TScrollBox;
    Panel1: TPanel;
    iPKey: TImage;
    iFKey: TImage;
    Label2: TLabel;
    cbMode: TComboBox;
    SBar: TStatusBar;
    iLink: TImage;
    cbNext: TComboBox;
    Label4: TLabel;
    eStepName: TEdit;
    Label1: TLabel;
    ImageList1: TImageList;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    tbNew: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    cbNextFalse: TComboBox;
    Label5: TLabel;
    Image3: TImage;
    Label7: TLabel;
    Label8: TLabel;
    Shape1: TShape;
    ImageList: TImageList;
    ToolButton2: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    cbIgnoreSpaces: TCheckBox;
    ToolButton8: TToolButton;
    pLeft: TPanel;
    pLog: TPanel;
    Splitter1: TSplitter;
    tbStop: TToolButton;
    Panel2: TPanel;
    Splitter2: TSplitter;
    reReslt: TRichEdit;
    PC: TPageControl;
    tsLog: TTabSheet;
    mLog: TMemo;
    tsDictionary: TTabSheet;
    mDictionary: TMemo;
    Shape2: TShape;
    Shape3: TShape;
    Shape4: TShape;
    Shape5: TShape;
    Shape6: TShape;
    Shape7: TShape;
    Shape8: TShape;
    Shape9: TShape;
    Shape10: TShape;
    Shape11: TShape;
    Shape12: TShape;
    Shape13: TShape;
    TabSet1: TTabSet;
    procedure SBEraseBkgndEvent(Sender: TObject; DC: HDC);
    procedure cbNextChange(Sender: TObject);
    procedure cbModeChange(Sender: TObject);
    procedure tbNewClick(Sender: TObject);
    procedure cbNextFalseChange(Sender: TObject);
    procedure eStepNameChange(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure cbIgnoreSpacesClick(Sender: TObject);
    procedure pLeftDockOver(Sender: TObject; Source: TDragDockObject;
      X, Y: Integer; State: TDragState; var Accept: Boolean);
    procedure pLeftUnDock(Sender: TObject; Client: TControl;
      NewTarget: TWinControl; var Allow: Boolean);
    procedure pLeftDockDrop(Sender: TObject; Source: TDragDockObject;
      X, Y: Integer);
    procedure ToolButton8Click(Sender: TObject);
    procedure tbStopClick(Sender: TObject);
    procedure TabSet1Change(Sender: TObject; NewTab: Integer;
      var AllowChange: Boolean);
  private
    FActiveBox: TJvgGroupBoxPlus;
    LogicProducer: TJvgLogicProducer;
    Logics: TJvgLogics;
    procedure MouseDown_(Sender: TObject; Button: TMouseButton; Shift:
      TShiftState; X, Y: Integer);
    procedure MouseMove_(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure MouseUp_(Sender: TObject; Button: TMouseButton; Shift:
      TShiftState; X, Y: Integer);
    procedure DblClick_(Sender: TObject);
    procedure SetActiveBox(const Value: TJvgGroupBoxPlus);
    procedure UpdateView;
    procedure AddBox(ALogicElement: TJvgLogicElement);
    procedure AddShape(CommentArea: TJvgCommentArea);
    procedure OnTraceMessage(Sender: TJvgLogics; AStepResult: Boolean;
      const StepResult, ParsedResult, Msg: string);
  public
    function Execute(ALogicProducer: TJvgLogicProducer): Boolean;
    property ActiveBox: TJvgGroupBoxPlus read FActiveBox write SetActiveBox;
  end;

implementation

uses
  Clipbrd,
  {$IFDEF USEJVCL}
  JvDsgnConsts,
  {$ENDIF USEJVCL}
  JvgTypes, JvgUtils, JvgLogicItemEditorForm;

{$R *.dfm}

var
  JvgLogicItemEditor: TJvgLogicItemEditor;

{$IFNDEF USEJVCL}
resourcestring
  RsCaption = 'Caption';
  RsComments = 'Comments';
  RsEditComponentEllipsis = 'Edit component...';
{$ENDIF !USEJVCL}

//=== { TJvgLogicsEditorMain } ===============================================

function TJvgLogicsEditorMain.Execute(ALogicProducer: TJvgLogicProducer): Boolean;
var
  I: Integer;
begin
  JvgLogicItemEditor := TJvgLogicItemEditor.Create(nil);

  mDictionary.Lines.Assign(ALogicProducer.Dictionary);
  try
    LogicProducer := ALogicProducer;
    Logics := ALogicProducer.Logics;

    Logics.OnTraceMessage := OnTraceMessage;

    cbNext.Items.Clear;
    cbNextFalse.Items.Clear;
    cbNext.Items.Add('');
    cbNextFalse.Items.Add('');

    for I := 0 to Logics.Count - 1 do
      AddBox(Logics[I]);

    for I := 0 to LogicProducer.CommentAreas.Count - 1 do
      AddShape(LogicProducer.CommentAreas[I]);

    Result := ShowModal = mrOk;
  finally
    JvgLogicItemEditor.Free;
  end;
  //  pLog.Dock(pLeft, Rect(1, 1, 10, 10));
  //  pLog.Dock(pLeft, Rect(1, 1, 10, 10));
  //  pLeft.Dock(pLog, Rect(1, 1, 1, 1));
end;

procedure TJvgLogicsEditorMain.AddBox(ALogicElement: TJvgLogicElement);
var
  Box: TJvgGroupBoxPlus;
begin
  Box := TJvgGroupBoxPlus.Create(Self);
  with Box do
  begin
    Parent := SB;
    Left := ALogicElement.Left;
    Top := ALogicElement.Top;
    Width := 100;
    Height := 50;
    Caption := ALogicElement.Caption;
    Options := Options - [fgoCanCollapse];
    CaptionAlignment := fcaWidth;
    CaptionBorder.Inner := bvRaised;
    CaptionBorder.Outer := bvLowered;
    Colors.Caption := clBtnShadow;
    Colors.TextActive := clBtnHighlight;
    OnMouseDown := MouseDown_;
    OnMouseMove := MouseMove_;
    OnMouseUp := MouseUp_;
    OnDblClick := DblClick_;
    //Border.Inner := bvRaised;
    //Border.Outer := bvNone;
    Colors.Client := clWhite;
    Colors.ClientActive := clWhite;
    Box.LogicElement := ALogicElement;

    cbNext.Items.AddObject(ALogicElement.Caption, LogicElement);
    cbNextFalse.Items.AddObject(ALogicElement.Caption, LogicElement);
  end;
end;

procedure TJvgLogicsEditorMain.AddShape(CommentArea: TJvgCommentArea);
var
  Shape: TJvgShapePlus;
begin
  Shape := TJvgShapePlus.Create(Self);
  Shape.CommentArea := CommentArea;
  with Shape do
  begin
    Parent := SB;
    Left := CommentArea.Left;
    Top := CommentArea.Top;
    Width := CommentArea.Width;
    Height := CommentArea.Height;
    Pen.Style := psDashDot;
    Brush.Style := bsClear;

    OnMouseDown := MouseDown_;
    OnMouseMove := MouseMove_;
    OnMouseUp := MouseUp_;
    OnDblClick := DblClick_;
  end;
end;

procedure TJvgLogicsEditorMain.MouseDown_(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  I: Integer;
begin
  if Sender is TJvgShapePlus then
    with Sender as TJvgShapePlus do
    begin
      Pt.X := X;
      Pt.Y := Y;
      Pt := ClientToScreen(Pt);
      Selected := True;
      Tag := 1;
      if (X >= Width - 5) and (X < Width) and (Y >= Height - 5) and (Y < Height) then
        Tag := 2;
      Exit;
    end;

  with TJvgGroupBoxPlus(Sender) do
  begin
    Pt.X := X;
    Pt.Y := Y;
    Pt := ClientToScreen(Pt);
    Pt.Y := Pt.Y; // + SB.VertScrollBar.ScrollPos;
    Tag := 1;
    Options := Options + [fgoDelineatedText];
    Colors.Caption := clBtnHighlight;
    Colors.TextActive := clBlack;
    Font.Style := [fsBold];
    Selected := True;
    ActiveBox := TJvgGroupBoxPlus(Sender);
  end;

  for I := 0 to SB.ControlCount - 1 do
    if SB.Controls[I] is TJvgGroupBoxPlus then
      with TJvgGroupBoxPlus(SB.Controls[I]) do
        if ActiveBox <> TJvgGroupBoxPlus(SB.Controls[I]) then
        begin
          Options := Options - [fgoDelineatedText];
          Colors.Caption := clBtnShadow;
          Colors.TextActive := clBtnHighlight;
          Font.Style := [];
          Selected := False;
          Repaint;
        end;
end;

procedure TJvgLogicsEditorMain.MouseMove_(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  NewPt: TPoint;
begin
  if Sender is TJvgShapePlus then
    with Sender as TJvgShapePlus do
    begin
      case Tag of
        1:
          begin
            NewPt.X := X;
            NewPt.Y := Y;
            NewPt := ClientToScreen(NewPt);
            Left := Left + NewPt.X - Pt.X;
            Top := Top + NewPt.Y - Pt.Y;
            CommentArea.Left := Left + SB.HorzScrollBar.ScrollPos;
            CommentArea.Top := Top + SB.VertScrollBar.ScrollPos;
          end;
        2:
          begin
            NewPt.X := X;
            NewPt.Y := Y;
            NewPt := ClientToScreen(NewPt);
            Width := Width + NewPt.X - Pt.X;
            Height := Height + NewPt.Y - Pt.Y;
            if Width < 50 then
              Width := 50;
            if Height < 50 then
              Height := 50;
            CommentArea.Width := Width;
            CommentArea.Height := Height;
          end;
      end;
      Pt.X := NewPt.X;
      Pt.Y := NewPt.Y;
      Exit;
    end;

  with TJvgGroupBoxPlus(Sender) do
  begin
    if Tag <> 0 then
    begin
      NewPt.X := X;
      NewPt.Y := Y;
      NewPt := ClientToScreen(NewPt);
      NewPt.Y := NewPt.Y; // + SB.VertScrollBar.ScrollPos;
      Left := Left + NewPt.X - Pt.X;
      Top := Top + NewPt.Y - Pt.Y;

      LogicElement.Left := Left + SB.HorzScrollBar.ScrollPos;
      LogicElement.Top := Top + SB.VertScrollBar.ScrollPos;

      SBar.SimpleText := IntToStr(Left) + ':' + IntToStr(Top);

      UpdateView;
    end;
    Pt.X := NewPt.X;
    Pt.Y := NewPt.Y;
  end;
end;

procedure TJvgLogicsEditorMain.UpdateView;
var
  DC: HDC;
begin
  DC := GetDC(SB.Handle);
  SendMessage(SB.Handle, WM_ERASEBKGND, WPARAM(DC), 0);
  ReleaseDC(SB.Handle, DC);
end;

procedure TJvgLogicsEditorMain.MouseUp_(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  I: Integer;
begin
  TControl(Sender).Tag := 0;
  for I := 0 to SB.ControlCount - 1 do
    if (SB.Controls[I] is TJvgShapePlus) then
      (SB.Controls[I] as TJvgShapePlus).Paint;
end;

procedure TJvgLogicsEditorMain.DblClick_(Sender: TObject);
var
  S: string;
begin
  TControl(Sender).Tag := 0;
  if Sender is TJvgShapePlus then
    with Sender as TJvgShapePlus do
    begin
      S := CommentArea.Text;
      if InputQuery(RsCaption, RsComments, S) then
        CommentArea.Text := S;
      PostMessage(TWinControl(Parent).Handle, WM_LBUTTONUP, 1, 1);
      Exit;
    end;

  JvgLogicItemEditor.Execute(Logics, TJvgGroupBoxPlus(Sender).LogicElement);
  PostMessage(TWinControl(Sender).Handle, WM_LBUTTONUP, 1, 1);
end;

procedure TJvgLogicsEditorMain.SetActiveBox(const Value: TJvgGroupBoxPlus);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -