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

📄 teeinspector.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  DoPositionCombos(True);

  {$IFNDEF LCL} // Same method in LCL does a different thing
  if (Row=0) and (RowCount>MinRow) then MoveColRow(1,MinRow,True,True);
  {$ENDIF}
end;

{$IFDEF CLX}
Procedure TTeeInspector.SetParent(const Value: TWinControl);
{$ELSE}
Procedure TTeeInspector.SetParent(AParent: TWinControl);
{$ENDIF}
begin
  inherited;
  if (not (csDestroying in ComponentState)) and
     (not (csDesigning in ComponentState)) then
  begin
    IComboGrid.Parent:=Parent;
    IEditGrid.Parent:=Parent;
  end;
end;

procedure TTeeInspector.ComboKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  case Key of
 TeeKey_Escape: begin
                  HideCombos;
                  SetFocus;
                end;
  end;
end;

procedure TTeeInspector.EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  case Key of
 TeeKey_Escape,
 TeeKey_Return: begin
                  HideCombos;
                  SetFocus;
                end;
     TeeKey_Up: begin
                  HideCombos;
                  SetFocus;
                  if Row>=MinRow then Row:=Row-1;
                end;
   TeeKey_Down: begin
                  HideCombos;
                  SetFocus;
                  if Row<RowCount-1 then Row:=Row+1;
                end;
  end;
end;

Function TTeeInspector.Item(ARow:Integer):TInspectorItem;
begin
  result:=TInspectorItem(Objects[0,ARow]);
end;

procedure TTeeInspector.EditChange(Sender: TObject);
begin { the inspector edit box has changed }
  with Item(Row) do
  begin
    if Style=iiString then
       Value:=IEditGrid.Text
    else
    if Style=iiInteger then
       Value:=StrToIntDef(IEditGrid.Text,Value)
    else
    if Style=iiDouble then
       Value:=StrToFloatDef(IEditGrid.Text,Value); // 8.01 TV52012259

    Changed;
  end;
end;

procedure TTeeInspector.ComboChange(Sender: TObject);
var tmpItem : TMenuItem;
begin { the inspector combobox has changed, select subitem }
  if IComboGrid.Tag {$IFDEF CLR}<>nil{$ELSE}<>0{$ENDIF} then
  begin
    tmpItem:=TMenuItem(IComboGrid.Tag).Items[IComboGrid.ItemIndex];
    tmpItem.Checked:=True;

    if Assigned(tmpItem.OnClick) then
       tmpItem.OnClick(tmpItem);
  end
  else
  with Item(Row) do
  begin
    if Assigned(FOnSetItemIndex) then
       FOnSetItemIndex(Item(Row),IComboGrid.ItemIndex)
    else
    begin
      Value:=IComboGrid.CurrentItem;
      Data:=IComboGrid.SelectedObject;
    end;

    Changed;
  end;
end;

Procedure TTeeInspector.Clear;
begin
  Items.Clear;
  HideCombos;
end;

// A Menu can be used to fill the Inspector.

Procedure TTeeInspector.SetProperties(const AMenu:TPopupMenu);
var t     : Integer;
    tmpSt : String;
    tmp   : Integer;
    tmp2  : Integer;
    tmpInspectorItem : TInspectorItem;
    tmpEllipsi : Boolean;
begin { set properties at inspector, if any }

  HideCombos;

  Items.Clear;

  tmp:=0;

  if Assigned(AMenu) then
  with AMenu do
  begin
    { call OnPopup to prepare items }
    if Assigned(OnPopup) then OnPopup(AMenu);

    RowCount:=Items.Count;

    { fill properties... }
    for t:=0 to Items.Count-1 do
    begin
      if {$IFDEF D5}(not Items[t].IsLine){$ELSE}(Items[t].Caption<>'-'){$ENDIF} // Do not localize
         and (Items[t].Enabled)
         and (Items[t].HelpContext<>5) then { 5 means "dont put at inspector" }
      begin
        tmpSt:=StripHotkey(Items[t].Caption);

        tmpEllipsi:=Copy(tmpSt,Length(tmpSt)-2,3)='...'; // Do not localize

        { remove trailing ellipsi "..." }
        if tmpEllipsi then
           While tmpSt[Length(tmpSt)]='.' do // Do not localize
                 Delete(tmpSt,Length(tmpSt),1);

        Inc(tmp);

        tmpInspectorItem:=TInspectorItem(Self.Items.Add);

        with tmpInspectorItem do
        begin
          Caption:=tmpSt;
          Data:=TObject(AMenu.Items[t].Tag);
          IData:=AMenu.Items[t];

          if Header.Visible then tmp2:=tmp
                            else tmp2:=tmp-1;

          if Items[t].Count>0 then
             Style:=iiSelection
          else
          (*
          // Problem here: Cannot set automatic style due to TeeChartOffice
          // duplication of click event (menuitem and inspector ellipsi)
          case CellType(tmp2) of
            3: Style:=iiPen;
            4: Style:=iiGradient;
            7: Style:=iiFont;
            9: Style:=iiBrush;
          else
          *)
            if tmpEllipsi then
               Style:=iiButton;
          //end;
        end;

        Cells[0,tmp2]:=tmpSt;
        Objects[1,tmp2]:=tmpInspectorItem;
      end;
    end;
  end;

  if Header.Visible then RowCount:=tmp+1
                    else RowCount:=tmp;

  { enable / disable inspector }
  Enabled:=Assigned(AMenu);

  { resize grid column }
  ColWidths[1]:=ClientWidth-ColWidths[0];
end;

function TTeeInspector.ItemOffset(ARow:Integer):Integer;
var tmp : TInspectorItem;
begin
  result:=0;

  tmp:=Item(ARow).Parent;

  while Assigned(tmp) do
  begin
    Inc(result,16);
    tmp:=tmp.Parent;
  end;
end;

function TTeeInspector.CanDrawEllipsi(ARow:Integer):Boolean;
begin
  with Item(ARow) do
    result:=((Style=iiColor) or (Style=iiGradient) or (Style=iiImage) or
             (Style=iiPen) or (Style=iiBrush) or (Style=iiFont))
            or
            (
            (Style<>iiSelection) and
            (Style<>iiString) and
            (Style<>iiInteger) and
            (Style<>iiDouble) and
            ((Style=iiButton) and (Assigned(FOnChange)))
            );
end;

{ returns the type of the cell if it points to a menu item }
Function TTeeInspector.CellType(ARow:Integer):Integer;
var tmp : TInspectorItem;
begin
  result:= -1;

  tmp:=Item(ARow);

  if Assigned(tmp) then
    if Assigned(tmp.IData) then
    begin
      if tmp.IData is TMenuItem then
         result:=(tmp.IData as TMenuItem).HelpContext
    end
    else
      result:=tmp.StyleToInt;
end;

const
  TeeInspectorButtonSize=16;

procedure TTeeInspector.DrawCell(ACol, ARow: Integer; ARect: TRect;
                                       AState: TGridDrawState);

  Function BooleanCell(ARow:Integer):Boolean;
  var tmp : TObject;
  begin { returns True if the inspector cell (menu item) is True }
    result:=False;
    tmp:=Item(ARow).IData;

    if Assigned(tmp) then
    begin
      if tmp is TMenuItem then
         result:=(tmp as TMenuItem).Checked;
    end
    else result:=Item(ARow).Value;
  end;

  Procedure DrawEllipsis;
  var tmpColor : TColor;
  begin { draw small "ellipsis" buttons }
    with Canvas do
    begin
      {$IFDEF CLX}
      Pen.Color:=clBlack;
      Pen.Style:=psSolid;
      DrawPoint(ARect.Left+4,ARect.Bottom-6);
      DrawPoint(ARect.Left+6,ARect.Bottom-6);
      DrawPoint(ARect.Left+8,ARect.Bottom-6);
      {$ELSE}

      if Self.Enabled and Item(ARow).Enabled then
         tmpColor:=clBlack
      else
         tmpColor:=clDkGray;

      Pen.Handle:=TeeCreatePenSmallDots(tmpColor);

      MoveTo(ARect.Left+4,ARect.Bottom-6);
      LineTo(ARect.Left+10,ARect.Bottom-6);
      {$ENDIF}
    end;
  end;

  Function CurrentItem:TMenuItem;
  begin { returns the Menu Item associated to current grid cell }
    result:=TMenuItem(Item(ARow).IData);
  end;

  Function CurrentItemCount:Integer;
  var tmp : TMenuItem;
  begin
    tmp:=CurrentItem;
    if Assigned(tmp) then result:=tmp.Count
                     else result:=0;
  end;

  Function RectangleItem:TRect;
  begin
    result:=TeeRect(ARect.Right+2,ARect.Top+2,ARect.Right+40,ARect.Bottom-2);
  end;

  Procedure DrawText(Const S:String; LeftPos:Integer=-1; EnableColor:Boolean=True);
  begin
    if LeftPos=-1 then
       LeftPos:=ARect.Right+2;

    if EnableColor then
       if Enabled and Item(ARow).Enabled then
          Canvas.Font.Color:=Font.Color
       else
          Canvas.Font.Color:=clDkGray;

    Canvas.TextOut(LeftPos,ARect.Top,S);
  end;

var tmp       : Integer;
    tmpSt     : String;
    tmpMiddle : Integer;
    tmpCanvas : TTeeCanvas3D;
    tmpGrad   : TCustomTeeGradient;
    tmpFont   : TTeeFont;
    tmpImage  : TPicture;
    tmpItem   : TMenuItem;
    tmpPen    : TChartPen;
    tmpColor  : TColor;
    tmpData   : TObject;
    {$IFDEF CLX}
    QC        : QColorH;
    {$ENDIF}
    tmpBrush  : TChartBrush;
begin { draw checkboxes and buttons at Property Inspector }

  { draw thin dotted grid lines }
  with Canvas do
  begin
    {$IFDEF CLX}
    Start;
    {$ENDIF}

    if goHorzLine in Options then
    begin
      {$IFNDEF CLX}
      Pen.Handle:=TeeCreatePenSmallDots(clDkGray);
      {$ENDIF}

      MoveTo(ARect.Left,ARect.Bottom-1);
      LineTo(ARect.Right-1,ARect.Bottom-1);
    end;
  end;

  if (ARow=0) and Header.Visible then
  begin
    { draw top row text }
    with Canvas do
    begin
      tmpColor:=Font.Color;

      Font.Assign(Header.Font);

      if gdSelected in AState then
         Font.Color:=tmpColor;

      TextOut(ARect.Left+2,ARect.Top+{$IFDEF CLX}2{$ELSE}1{$ENDIF},Cells[ACol,0]);
    end;
  end
  else

  if (ACol=1) and ValidRow(ARow) then { draw value cells }
  with Canvas do
  begin
    { resize rectangle to button / checkbox size }
    Inc(ARect.Left,2);
    Inc(ARect.Top,2);
    Dec(ARect.Bottom,1);
    ARect.Right:=ARect.Left+TeeInspectorButtonSize;

    if CellType(ARow)=2 then { color property }
    begin
      tmpItem:=CurrentItem;

      if Assigned(tmpItem) {$IFDEF CLR}and Assigned(tmpItem.Tag){$ENDIF} then
         Brush.Color:={$IFDEF CLR}Integer{$ELSE}TColor{$ENDIF}(tmpItem.Tag)
      else
         Brush.Color:={$IFDEF CLR}Integer{$ELSE}TColor{$ENDIF}(Item(ARow).Value);

      Pen.Style:=psSolid;
      Pen.Width:=1;

      if Self.Enabled and
         ( (Brush.Color=clBlack) or (Brush.Color=clDkGray) ) then
         Pen.Color:=clWhite
      else
         Pen.Color:=clDkGray;

      Rectangle(ARect.Left,ARect.Top+1,ARect.Right-3,ARect.Bottom-2);

      tmpSt:=ColorToString(Brush.Color);

      if Copy(tmpSt,1,2)='cl' then // Do not localize
         tmpSt:=Copy(tmpSt,3,255);

      Brush.Style:=bsClear;
      DrawText(tmpSt);
    end
    else
    if CellType(ARow)=10 then // String
       DrawText(Item(ARow).Value,ARect.Left)
    else
    begin
      { draw button or check-box }
      if CellType(ARow)=1 then { boolean ? }
      begin
        if Self.Enabled and Item(ARow).Enabled then
           tmpColor:=Color
        else
           tmpColor:=clSilver;

        TeeDrawCheckBox(ARect.Left,ARect.Top,Canvas,BooleanCell(ARow),tmpColor);
      end
      else

      if (CellType(ARow)<>-1) and (CurrentItemCount=0) and
         CanDrawEllipsi(ARow) then
      begin { button }
        {$IFDEF CLX}
        Pen.Style:=psSolid;
        FillRect(ARect);
        {$ELSE}
        Dec(ARect.Bottom);
        Dec(ARect.Right,3);
        tmp:=DFCS_BUTTONPUSH or DFCS_FLAT;
        DrawFrameControl(Handle,ARect,DFC_BUTTON,tmp);
        {$ENDIF}
      end;

      tmpMiddle:=(ARect.Top+ARect.Bottom) div 2;

      case CellType(ARow) of
        0: if (CurrentItemCount=0) and
              (Item(ARow).Style<>iiSelection) then
           begin
             if CanDrawEllipsi(ARow) then
                DrawEllipsis; { button }

              if VarIsStr(Item(ARow).Value) then // TVC52010347
                 DrawText(Item(ARow).Value);
           end
           else
           begin { combobox (submenu items) }

             tmpSt:='';

             if CurrentItem<>nil then
             begin
               for tmp:=0 to CurrentItem.Count-1 do
               begin
                 tmpItem:=CurrentItem.Items[tmp];
                 if tmpItem.RadioItem and tmpItem.Checked then
                 begin
                   tmpSt:=StripHotKey(tmpItem.Caption);
                   break;
                 end;
               end;
             end
             else tmpSt:=Item(ARow).Value;

             if tmpSt<>'' then
                DrawText(tmpSt,ARect.Left);
           end;

        1: { boolean }
           begin
             { draw Yes/No }
             if BooleanCell(ARow) then tmpSt:=TeeMsg_Yes
                                  else tmpSt:=TeeMsg_No;
             DrawText(StripHotKey(tmpSt));
           end;

        3: begin { pen }
             DrawEllipsis;
             tmpPen:=TChartPen(Item(ARow).Data);

             if Assigned(tmpPen) then
             begin
               TeeSetTeePen(Pen,tmpPen,tmpPen.Color,Handle);

               MoveTo(ARect.Right+tmpPen.Width+1,tmpMiddle);
               LineTo(ARect.Right+30,tmpMiddle);
             end;
           end;

       4: begin { gradient }
            DrawEllipsis;
            tmpGrad:=TCustomTeeGradient(Item(ARow).Data);

            if Assigned(tmpGrad) then
            if tmpGrad.Visible then
            begin
              tmpCanvas:=TTeeCanvas3D.Create;
              try
                tmpCanvas.ReferenceCanvas:=Canvas;
                tmpGrad.Draw(tmpCanvas,RectangleItem);
              finally
                tmpCanvas.Free;
                {$IFDEF CLX}
                with Canvas.Brush do
                begin
                  QC:=QColor(clBtnFace);
                  try
                    QBrush_setColor(Handle, QC);
                  finally
                    QColor_destroy(QC);
                  end;
                end;
                {$ENDIF}
              end;
            end
            else DrawText(TeeMsg_None);
          end;

       6: begin { integer }
            // IntToStr(CurrentItem.HelpContext)

            DrawText(Item(ARow).Value);
          end;

       7: begin { font }
            DrawEllipsis;
            tmpFont:=TTeeFont(Item(ARow).Data);

            if Assigned(tmpFont) then
            with tmpFont do
            begin
              if Self.Enabled and Item(ARow).Enabled then
                 Font.Color:=Color
              else
                 Font.Color:=clDkGray;

              Font.Name:=Name;
              Font.Style:=Style;
            end
            else
              Font.Color:=clDkGray;

            DrawText(Font.Name,-1,False);
          end;

       8: begin { image }
            DrawEllipsis;

            tmpImage:=TPicture(Item(ARow).Data);

            if Assigned(tmpImage) and Assigned(tmpImage.Graphic) then
               tmpSt:=TeeMsg_Image
            else
               tmpSt:=TeeMsg_None;

            DrawText(tmpSt);
          end;

       9: begin { pattern brush }
            DrawEllipsis;

            tmpData:=Item(ARow).Data;

⌨️ 快捷键说明

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