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

📄 rm_insp.pas

📁 report machine 2.3 功能强大
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  FItemIndex := -1;
  FBusyFlag := True;
  FPanel1.Height := Items.Count * FRowHeight;
  FPanel1.Width := Box.ClientWidth;
  Fw := PaintBox1.Width;
  FBusyFlag := False;

  LastIndex := FItems.IndexOf(FLastProp);
  if LastIndex = -1 then
    LastIndex := 0;
  ItemIndex := LastIndex;
  if not HideProperties then
  begin
    if not ((CB1.ItemIndex <> -1) and (CB1.Items[CB1.ItemIndex] = ObjectName)) then
    begin
      CB1DropDown(nil);
      CB1.ItemIndex := CB1.Items.IndexOf(ObjectName);
    end;
  end
  else
    CB1.ItemIndex := -1;
end;

function TRMInspForm.GetPropName(Index: Integer): string;
var
  i: Integer;
begin
  i := FPropAliases.IndexOf(FItems[Index]);
  if (i >= 0) and RMLocale.LocalizedPropertyNames then
    Result := FPropAliases.Value[i]
  else if Index < FItems.Count then
    Result := FItems[Index]
  else
  	Result := '';
end;

procedure TRMInspForm.DrawOneLine(index: Integer; a: Boolean);
var
  R: TRect;

  procedure Line(x, y, dx, dy: Integer);
  begin
    Fb.Canvas.MoveTo(x, y);
    Fb.Canvas.LineTo(x + dx, y + dy);
  end;

  procedure DrawColorProp;
  var
    x, y: integer;
    SaveColor: TColor;
  begin
    x := Fw1 + 2; y := index * FRowHeight + 1;
    with Fb.Canvas do
    begin
      SaveColor := Brush.Color;
      if GetPropValue(index) = clNone then
        Brush.Color := clBtnFace
      else
        Brush.Color := GetPropValue(index);
      Rectangle(x, y, x + FRowHeight - 3, y + FRowHeight - 3);
      Brush.Color := SaveColor;
      Font.Color := clNavy;
      TextOut(x + FRowHeight, y, GetItemValue(index));
    end;
  end;

begin
  if Count > 0 then
  begin
    with Fb.Canvas do
    begin
      Brush.Color := clBtnFace;
      Pen.Color := clBtnShadow;
//      Font.Name := 'MS Sans Serif';
//      Font.Size := 8;
      Font.Assign(Self.Font);
      Font.Style := [];
      Font.Color := clBlack;
      R := Rect(5, index * FRowHeight + 1, Fw1 - 2 - 2, index * FRowHeight + FRowHeight - 1);
      if a then
      begin
        Pen.Color := clBtnShadow;
        Line(0, -2 + index * FRowHeight, Fw, 0);
        Line(Fw1 - 1, 0 + index * FRowHeight, 0, FRowHeight);
        Pen.Color := clBlack;
        Line(0, -1 + index * FRowHeight, Fw, 0);
        Line(0, -1 + index * FRowHeight, 0, FRowHeight + 1);
        Pen.Color := clBtnHighlight;
        Line(1, FRowHeight + -1 + index * FRowHeight, Fw - 1, 0);
        Line(Edit1.Left, 0 + index * FRowHeight, Edit1.Width, 0);
        Line(Fw1, 0 + index * FRowHeight, 0, FRowHeight);
        Line(Fw1 + 1, 0 + index * FRowHeight, 0, FRowHeight);
        TextRect(R, 5, 1 + index * FRowHeight, GetPropName(index));
      end
      else
      begin
        Line(0, FRowHeight - 1 + index * FRowHeight, Fw, 0);
        Line(Fw1 - 1, 0 + index * FRowHeight, 0, FRowHeight);
        Pen.Color := clBtnHighlight;
        Line(Fw1, 0 + index * FRowHeight, 0, FRowHeight);
        TextRect(R, 5, 1 + index * FRowHeight, GetPropName(index));
        if RMdtColor in GetItemType(index) then
        begin
          DrawColorProp;
        end
        else
        begin
          Font.Color := clNavy;
          TextOut(Fw1 + 2, 1 + index * FRowHeight, GetItemValue(index));
        end;
      end;
    end;
  end;
end;

procedure TRMInspForm.PaintBox1Paint(Sender: TObject);
var
  i: Integer;
  r: TRect;
begin
  if FBusyFlag then Exit;
  FLB1.Hide;
  r := PaintBox1.BoundsRect;
  Fb.Width := PaintBox1.Width;
  Fb.Height := PaintBox1.Height;
  Fb.Canvas.Brush.Color := clBtnFace;
  Fb.Canvas.FillRect(r);
  if not HideProperties then
  begin
    for i := 0 to Count - 1 do
    begin
      if i <> FItemIndex then
        DrawOneLine(i, False);
    end;
    if FItemIndex <> -1 then DrawOneLine(FItemIndex, True);
  end;
  PaintBox1.Canvas.Draw(0, 0, Fb);
end;

procedure TRMInspForm.FillPropAliases;
var
  i: Integer;
  s: string;
begin
  for i := rmRes + 5001 to 65535 do
  begin
    s := RMLoadStr(i);
    if s = '' then
      Break;
    if (Pos('=', s) = 0) or (Pos('=', s) = Length(s)) then Continue;
    FPropAliases[Copy(s, 1, Pos('=', s) - 1)] := Copy(s, Pos('=', s) + 1, 255);
  end;
end;

procedure TRMInspForm.FormCreate(Sender: TObject);
begin
  Localize;
  FPropAliases := TRMVariables.Create;
  FillPropAliases;

  FPanel1 := TInspPanel.Create(Self);
  FPanel1.Parent := Box;
  FPanel1.BevelInner := bvNone;
  FPanel1.BevelOuter := bvNone;
  PaintBox1.Parent := FPanel1;

  ComboPanel.Parent := FPanel1;
  EditPanel.Parent := FPanel1;
  Edit1.Parent := FPanel1;
  Fw := PaintBox1.Width;
  Fb := TBitmap.Create;

  FItemIndex := -1;
  FItems := TStringList.Create;
  FRowHeight := -Font.Height + 5;
  Box.VertScrollBar.Increment := FRowHeight;
  Box.VertScrollBar.Tracking := True;

  FLB1 := TRMPopupListBox.Create(Self);
  with FLB1 do
  begin
    Parent := Self;
    OnClick := LB1Click;
    IntegralHeight := True;
    ItemHeight := 11;
    FInspForm := Self;
    Style := lbOwnerDrawFixed;
    ItemHeight := 16;
  end;

  FDefHeight := Height;
  FormResize(nil);
end;

procedure TRMInspForm.FormDestroy(Sender: TObject);
begin
  FPropAliases.Free;
  Fb.Free;
  FLB1.Free;
  ClearProperties;
  FItems.Free;
end;

procedure TRMInspForm.FormActivate(Sender: TObject);
begin
  if Edit1.Enabled and Edit1.Visible then
    Edit1.SetFocus;
end;

procedure TRMInspForm.FormDeactivate(Sender: TObject);
begin
  CloseUp(FALSE);
  FLB1.Hide;
  if CurItem = nil then Exit;
  if [RMdtHasEditor, RMdtColor, RMdtBoolean, RMdtEnum] * CurItem.DataType = [] then
  begin
    if Edit1.Modified then
      SetItemValue(Edit1.Text);
  end;
end;

procedure TRMInspForm.FormShow(Sender: TObject);
begin
  if ClientHeight < 20 then
    CB1.Hide;
end;

procedure TRMInspForm.WMNCLButtonDblClk(var Message: TMessage);
begin
  if Height > 30 then
  begin
    ClientHeight := 0;
    CB1.Hide;
  end
  else
  begin
    Height := FDefHeight;
    CB1.Show;
    ItemsChanged;
    Edit1.SelText := Edit1.Text;
    Edit1.Modified := False;
  end;
  if Assigned(FOnHeightChanged) then
    FOnHeightChanged(Self);
end;

procedure TRMInspForm.FormResize(Sender: TObject);
begin
  Box.Width := ClientWidth;
  Box.Height := ClientHeight - CB1.Height - 7;
  CB1.Width := ClientWidth;

  FPanel1.Height := Items.Count * FRowHeight;
  FPanel1.Width := Box.ClientWidth;

  Fw := PaintBox1.Width;
  SetItemIndex(FItemIndex);
end;

procedure TRMInspForm.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if HideProperties then Exit;
  if PaintBox1.Cursor = crHSplit then
    FDown := True
  else
  begin
    CloseUp(FALSE);
    ItemIndex := y div FRowHeight;
    Edit1.SetFocus;
    FTickCount := GetTickCount;
  end;
end;

procedure TRMInspForm.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if HideProperties then Exit;
  if Key = vk_Escape then
  begin
    Edit1.Perform(EM_UNDO, 0, 0);
    Edit1.Modified := False;
  end
  else if Key = vk_Up then
  begin
    if ItemIndex > 0 then
      ItemIndex := ItemIndex - 1;
    Key := 0;
  end
  else if Key = vk_Down then
  begin
    if ItemIndex < Count - 1 then
      ItemIndex := ItemIndex + 1;
    Key := 0;
  end;
end;

procedure TRMInspForm.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if RMdtHasEditor in CurItem.DataType then
      EditBtnClick(nil)
    else
    begin
      if Edit1.Modified then
        SetItemValue(Edit1.Text);
      Edit1.Modified := False;
    end;
    Edit1.SelectAll;
    Key := #0;
  end;
end;

procedure TRMInspForm.EditBtnClick(Sender: TObject);
begin
  if HideProperties then Exit;
  CurItem.Editor(CurObject);
  Edit1.SelectAll;
end;

procedure TRMInspForm.Edit1DblClick(Sender: TObject);
var
  p: TProp;

  function IndexOf(arr: Variant; val: Variant): Integer;
  var
    i: Integer;
  begin
    Result := -1;
    for i := 0 to varArrayHighBound(arr, 1) do
    begin
      if arr[i] = val then
      begin
        Result := i;
        Break;
      end;
    end;
  end;

begin
  p := CurItem;
  if RMdtHasEditor in p.DataType then
    EditBtnClick(nil)
  else if RMdtColor in p.DataType then
  begin
    with TColorDialog.Create(nil) do
    begin
      Color := p.Value;
      if Execute then
      begin
        p.Value := Color;
        SetItemValue(p.Text);
        Edit1.Modified := False;
        Edit1.SelectAll;
      end;
      Free;
    end;
  end
  else if RMdtBoolean in p.DataType then
  begin
    p.Value := not p.Value;
    SetItemValue(p.Text);
    Edit1.Modified := False;
    Edit1.SelectAll;
  end
  else if RMdtEnum in p.DataType then
  begin
    if p.IsEnumNull then
    begin
      if p.Enum.Count > 0 then
      begin
        if p.Enum.IndexOf(p.Value) >= p.Enum.Count - 1 then
          p.Value := p.Enum[0]
        else
          p.Value := p.Enum[p.Enum.IndexOf(p.Value) + 1];
      end;
    end
    else if IndexOf(p.EnumValues, p.Value) > varArrayHighBound(p.EnumValues, 1) - 1 then
      p.Value := p.EnumValues[0]
    else
      p.Value := p.EnumValues[IndexOf(p.EnumValues, p.Value) + 1];
    SetItemValue(p.Text);
    Edit1.Modified := False;
    Edit1.SelectAll;
  end;
end;

procedure TRMInspForm.CB1DropDown(Sender: TObject);
var
  s: string;
begin
  if CB1.ItemIndex <> -1 then
    s := CB1.Items[CB1.ItemIndex]
  else
    s := '';
  if Assigned(FOnGetObjects) then
    FOnGetObjects(CB1.Items);
  CB1.ItemIndex := CB1.Items.IndexOf(s);
end;

procedure TRMInspForm.CB1Click(Sender: TObject);
begin
  if Assigned(FOnSelectionChanged) then
    FOnSelectionChanged(CB1.Items[CB1.ItemIndex]);
  Edit1.SetFocus;
end;

function TRMInspForm.GetClassName(ObjName: string): string;
begin
  if CurObject <> nil then
  begin
    try
      Result := CurObject.ClassName;
    except
      Result := '';
    end;
  end
  else
    Result := '';
end;

procedure TRMInspForm.CB1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with CB1.Canvas do
  begin
    FillRect(Rect);
    if CB1.DroppedDown then
      TextOut(Rect.Left + 2, Rect.Top + 1, CB1.Items[Index])
    else
      TextOut(Rect.Left + 2, Rect.Top + 1, CB1.Items[Index] + ': ' +
        GetClassName(CB1.Items[Index]));
  end;
end;

procedure TRMInspForm.ComboBtnClick(Sender: TObject);
var
  i, wItems, nItems: Integer;
  p: TPoint;
begin
  if FListVisible then
  begin
    CloseUp(FALSE);
    Edit1.SetFocus;
    FListVisible := FALSE;
  end
  else
  begin
    FLB1.OnDrawItem := nil;
    FLB1.Style := lbStandard;
    with FLB1 do
    begin
      Items.Clear;
      Sorted := False;
      if RMdtBoolean in CurItem.DataType then
      begin
        Items.Add('False');
        Items.Add('True');
      end
      else if RMdtColor in CurItem.DataType then
      begin
        for i := 0 to 41 do
          Items.Add(RMColorNames[i]);
      end
      else if RMdtEnum in CurItem.DataType then
      begin
        for i := 0 to CurItem.Enum.Count - 1 do
          Items.Add(CurItem.Enum[i]);
      end;

      if Items.Count > 0 then
      begin
        ItemIndex := Items.IndexOf(CurItem.Text);
        wItems := 0;
        for i := 0 to Items.Count - 1 do
        begin
          if Canvas.TextWidth(Items[i]) > wItems then
            wItems := Canvas.TextWidth(Items[i]);
        end;

        Inc(wItems, 8);
        nItems := Items.Count;
        if nItems > 8 then
        begin
          nItems := 8;
          Inc(wItems, 16);
        end;

        p := Edit1.ClientToScreen(Point(0, Edit1.Height));
        if wItems < Fw - Fw1 then
          SetBounds(Fw1 + 1, p.Y, Fw - Fw1 + 1, nItems * (ItemHeight + 1) + 2)
        else
          SetBounds(Fw - wItems + 2, p.Y, wItems, nItems * (ItemHeight + 1) + 2);

        if RMdtColor in CurItem.DataType then
        begin
          FLB1.Style := lbOwnerDrawFixed;
          //FLB1.ItemHeight := 16;
          FLB1.OnDrawItem := OnEventDrawItemColor;
        end;

        p := Self.ClientToScreen(Point(0, 0));
        Inc(p.X, Left);
        if p.X < 0 then p.X := 0;
        ItemIndex := Items.IndexOf(CurItem.Text);
        SetWindowPos(Handle, HWND_TOP, p.X, Top, 0, 0, SWP_NOSIZE or SWP_NOACTIVATE or SWP_SHOWWINDOW);
        FListVisible := TRUE;
      end;
    end;
  end;
end;

procedure TRMInspForm.LB1Click(Sender: TObject);
begin
  Edit1.Text := FLB1.Items[FLB1.ItemIndex];
  CloseUp(FALSE);
  FLB1.Hide;
  Edit1.SetFocus;
  SetItemValue(Edit1.Text);
end;

{$WARNINGS OFF}

procedure TRMInspForm.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if GetTickCount - FTickCount < GetDoubleClickTime then
    Edit1DblClick(nil);
end;
{$WARNINGS ON}

procedure TRMInspForm.Grow;
begin
  Show;
  if ClientHeight < 20 then
  begin
    Height := FDefHeight;
    CB1.Show;
    ItemsChanged;
    Edit1.SelText := Edit1.Text;
    Edit1.Modified := False;
    if Assigned(FOnHeightChanged) then
      FOnHeightChanged(Self);
  end;
end;

procedure TRMInspForm.PaintBox1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
  if not FDown then
  begin
    if (X > Fw1 - 2) and (X < Fw1 + 2) then
    begin
      PaintBox1.Cursor := crHSplit;
    end
    else if x > 2 then
    begin
      PaintBox1.Cursor := crDefault;
    end;
  end
  else
  begin
    if x > 5 then
      Fw1 := X;
    FormResize(nil);
  end;
end;

procedure TRMInspForm.PaintBox1MouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FDown := False;
end;

end.

⌨️ 快捷键说明

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