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

📄 teeinspector.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 3 页
字号:

            if Assigned(tmpData) then
            begin
              tmpBrush:=TChartBrush(tmpData);

              if Assigned(tmpBrush.Image.Graphic) then
                 Brush.Bitmap:=tmpBrush.Image.Bitmap
              else
                 Brush.Assign(tmpBrush);
            end;

            {$IFNDEF CLX}
            if (CurrentItem<>nil) then
               SetBkColor(Handle,ColorToRGB(StrToInt(CurrentItem.Hint)));  // 6.01
            {$ENDIF}

            FillRect(RectangleItem);
            Brush.Style:=bsSolid;

            {$IFNDEF CLX}
            if (CurrentItem<>nil) then
               SetBkColor(Handle,ColorToRGB(Self.Color));  // 6.01
            {$ENDIF}
          end;
      end;
    end;

  end
  else
  if (ACol=0) and ValidRow(ARow) then { draw caption cells }
  begin
    Inc(ARect.Left,ItemOffset(ARow));
    Canvas.TextOut(ARect.Left+16,ARect.Top+2,Cells[ACol,ARow]);

    if ItemExpandable(ARow) then
       DrawCross(ItemCrossRect(ARect),not Item(ARow).Expanded);
  end
  else inherited;

  {$IFDEF CLX}
  Canvas.Stop;
  {$ENDIF}
end;

function TTeeInspector.ItemExpandable(ARow:Integer):Boolean;
var tmp : TInspectorItem;
begin
  tmp:=Item(ARow);

  result:=Assigned(tmp) and
          ((tmp.Style=iiBrush) or (tmp.Style=iiPen) or
           (tmp.Style=iiGradient) or (tmp.Style=iiImage) or (tmp.Style=iiFont));
end;

function TTeeInspector.ItemCrossRect(const R:TRect):TRect;
var tmp : Integer;
begin
  tmp:=R.Left+16;
  result:=TeeRect(tmp-13,R.Top+3,tmp-2,R.Top+14);
end;

procedure TTeeInspector.DrawCross(const R:TRect; Plus:Boolean);
var tmp : Integer;
begin
  with Canvas do
  begin
    Brush.Style:=bsSolid;
    Brush.Color:=clWhite;
    Pen.Color:=clDkGray;
    Pen.Width:=1;
    Pen.Style:=psSolid;

    {$IFDEF D5}
    Rectangle(R);
    {$ELSE}
    Rectangle(R.Left,R.Top,R.Right,R.Bottom);
    {$ENDIF}

    tmp:=R.Top+5;
    MoveTo(R.Left+3,tmp);
    LineTo(R.Left+8,tmp);

    if Plus then
    begin
      tmp:=R.Left+5;
      MoveTo(tmp,R.Top+3);
      LineTo(tmp,R.Top+8);
    end;

  end;
end;

procedure TTeeInspector.AddComboItem(Const S:String; AObject:TObject);
begin
  IComboGrid.Items.AddObject(S,AObject);
end;

{$IFNDEF CLX}
procedure TTeeInspector.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
  Invalidate;
end;
{$ENDIF}

Procedure TTeeInspector.HideCombos;
begin
  { remove previous combobox, if any }
  if Assigned(IComboGrid) then IComboGrid.Hide;

  { remove previous edit box, if any }
  if Assigned(IEditGrid) then IEditGrid.Hide;
end;

function TTeeInspector.RecalcRowCount:Integer;
var t : Integer;
begin
  result:=0;

  for t:=0 to Items.Count-1 do
      if Items[t].Visible then Inc(result);
  RowCount:=Math.Max(1,result);

  if Header.Visible then
  begin
    result:=1;
    if Items.Count>0 then
       RowCount:=RowCount+1;
  end
  else
    result:=0;

  if Header.Visible and (RowCount>1) then
     FixedRows:=1;
end;

// Reload grid cells with Visible Items
procedure TTeeInspector.Rebuild;
var t   : Integer;
    tmp : Integer;
begin
  tmp:=RecalcRowCount;

  for t:=0 to Items.Count-1 do
  if Items[t].Visible then
  begin
    Cells[0,tmp]:=Items[t].Caption;
    Objects[0,tmp]:=Items[t];
    Inc(tmp);
  end;
end;

procedure TTeeInspector.Loaded;
begin
  inherited;
  Rebuild;

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

Function TTeeInspector.MinRow:Integer;
begin
  if Assigned(FHeader) and Header.Visible then result:=1
                                          else result:=0;
end;

procedure TTeeInspector.ExpandCollapse(ARow:Integer);
begin
  if Assigned(FOnExpandCollapse) then
     FOnExpandCollapse(Item(ARow));
end;

function TTeeInspector.ClickedCross(X,Y:Integer):Integer;
var tmpR : TRect;
    t    : Integer;
begin
  result:=-1;

  for t:=0 to RowCount do
  if ItemExpandable(t) then
  begin
    tmpR:=CellRect(0,t);
    Inc(tmpR.Left,ItemOffset(t));
    tmpR:=ItemCrossRect(tmpR);

    if PointInRect(tmpR,X,Y) then
    begin
      result:=t;
      break;
    end;
  end;
end;

procedure TTeeInspector.MouseDown(Button: TMouseButton; Shift: TShiftState;
                                          X, Y: Integer);
var tmp     : TObject;
    tmpR    : TRect;
    t       : Integer;
    tmpItem : TInspectorItem;
    tmpChanged : Boolean;
    tmpColor   : TColor;
begin { execute the inspector property (menu item associated) }

  inherited;

  t:=ClickedCross(X,Y);

  if t<>-1 then
     ExpandCollapse(t)
  else
  if Enabled and (Col=1) and ValidRow(Row) then { clicked at column 1? }
  begin
    HideCombos;

    { calculate rectangle for button or checkbox }
    tmpR:=CellRect(Col,Row);

    { cell contains selection of items? }

    tmpItem:=Item(Row);

    if Assigned(tmpItem) and Enabled then
    begin

      if (tmpItem.Style=iiString) or (tmpItem.Style=iiInteger) or
         (tmpItem.Style=iiDouble) then
      begin
        with IEditGrid do
        begin
          { set Edit box position and size }
          DoPositionCombos(False);
          Text:={$IFDEF LCL}VarToStr({$ENDIF}Self.Item(Row).Value{$IFDEF LCL}){$ENDIF};
          Show;
          SetFocus;
        end;
      end
      else

      if tmpItem.Style=iiSelection then
      begin
        { create combobox }
        with IComboGrid do
        begin
          tmp:=tmpItem.IData;

          Tag:={$IFDEF CLR}Variant{$ELSE}Integer{$ENDIF}(tmp); { menu item }

          { set ComboBox position and size }
          DoPositionCombos(False);

          { fill combobox and select item }
          Items.Clear;

          if Assigned(tmp) and (tmp is TMenuItem) then
          begin
            with TMenuItem(tmp) do
            for t:=0 to Count-1 do
            if Items[t].RadioItem then
            begin
              IComboGrid.Items.Add(StripHotKey(Items[t].Caption));
              if Items[t].Checked then
                 ItemIndex:=t;
            end;
          end
          else
          begin
            with Self.Item(Row) do
            if Assigned(FOnGetItems) then
            begin
              FOnGetItems(tmpItem,AddComboItem);
              SetComboIndex;
            end
            else ItemIndex:=-1;
          end;

          Show;
          SetFocus;
        end;
      end;

      tmpR.Right:=tmpR.Left+TeeInspectorButtonSize;

      { clicked on ellipsis rectangle? }
      if PointInRect(tmpR,X,Y) then
      begin
        if tmpItem.Enabled then
        begin
          tmpChanged:=False;

          Case tmpItem.Style of
          iiBoolean: begin
                       if tmpItem.Value{$IFDEF CLR}=True{$ENDIF}{$IFDEF LCL}=True{$ENDIF} then
                          tmpItem.Value:=False
                       else
                          tmpItem.Value:=True;

                       tmpChanged:=True;
                     end;

            iiColor: begin
                       tmpColor:={$IFDEF CLR}TColor{$ENDIF}(tmpItem.Value);

                       tmpChanged:=EditColorDialog(Self,tmpColor);

                       if tmpChanged then
                          tmpItem.Value:=tmpColor;
                     end;

             iiFont: if tmpItem.Data is TTeeFont then
                        tmpChanged:=EditTeeFontEx(Self,TTeeFont(tmpItem.Data))
                     else
                        tmpChanged:=EditTeeFont(Self,TTeeFont(tmpItem.Data));

              iiPen: tmpChanged:=EditChartPen(Self,TChartPen(tmpItem.Data));
            iiBrush: tmpChanged:=EditChartBrush(Self,TChartBrush(tmpItem.Data));
         iiGradient: tmpChanged:=EditTeeGradient(Self,TCustomTeeGradient(tmpItem.Data));
            iiImage: tmpChanged:=EditTeePicture(Self,TTeePicture(tmpItem.Data));

          end;

          { repaing grid cell }
          if tmpItem.StyleToInt=0 then
             InvalidateCell(Col,Row);

          if tmpChanged then
             tmpItem.Changed;

          if Assigned(tmpItem.IData) and (tmpItem.IData is TMenuItem) then
             TMenuItem(tmpItem.IData).Click;

          { repaint clicked grid cell }
          InvalidateCell(Col,Row);
        end;
      end;
    end;
  end;
end;

procedure TTeeInspector.KeyDown(var Key: Word; Shift: TShiftState);
begin { emulate mouse clicking when pressing the SPACE key }
  if Key=TeeKey_Space then
  begin
    with CellRect(1,Row) do
         MouseDown(mbLeft,[],Left+4,Top+4);

    Key:=0;
  end
  else
  if (Key=TeeKey_Right) and ItemExpandable(Row) then
     ExpandCollapse(Row)
  else
     inherited;
end;

Procedure TTeeInspector.DoPositionCombos(WhenVisible:Boolean);
var R : TRect;
begin { set inspector combobox position and size }
  R:=CellRect(Col,Row);

  if Assigned(IComboGrid) and ((not WhenVisible) or IComboGrid.Visible) then
  with IComboGrid do
  begin
    Left:=Self.Left+R.Left+1;
    Width:=R.Right-R.Left+1;
    Top:=Self.Top+R.Top;  // -1 7.02
  end;

  if Assigned(IEditGrid) and ((not WhenVisible) or IEditGrid.Visible) then
  with IEditGrid do
  begin
    Left:=Self.Left+R.Left+1+2;
    Width:=R.Right-R.Left+1-2;
    Height:=R.Bottom-R.Top+1;
    Top:=Self.Top+R.Top+1;
  end;
end;

procedure TTeeInspector.TopLeftChanged;
begin { reposition the inspector ComboBox (if visible) when scrolling }
  DoPositionCombos(True);
end;

Function TTeeInspector.ValidRow(ARow:Integer):Boolean;
begin
  if Assigned(FHeader) and Header.Visible then
     result:=ARow>0
  else
     result:=Assigned(Items) and (Items.Count>0);
end;

Function TTeeInspector.SelectCell(ACol, ARow: Integer): Boolean;
begin { Avoid selecting the first grid column (when clicking) }
  result:= (ACol>0) and
           ValidRow(ARow) and
           inherited SelectCell(ACol,ARow);
end;

procedure TTeeInspector.MouseUp(Button: TMouseButton; Shift: TShiftState;
  X, Y: Integer);
var tmp:TGridState;
begin
  tmp:=FGridState;

  inherited;

  if tmp=gsColSizing then
     DoPositionCombos(True);
end;

procedure TTeeInspector.MouseMove(Shift: TShiftState; X, Y: Integer);
var tmpR      : TRect;
    tmp       : TGridCoord;
    tmpCursor : TCursor;
    tmpItem   : TInspectorItem;
begin
  inherited;

  {$IFNDEF LCL} // MouseCoord not supported

  tmpCursor:=crDefault;

  tmp:=MouseCoord(x,y); { mouse to grid Row,Col }

  if (tmp.X=0) and ValidRow(tmp.Y) and (ClickedCross(X,Y)<>-1) then
     tmpCursor:=crHandPoint
  else
  if (tmp.X=1) and ValidRow(tmp.Y) then { at column 1? }
  begin
    if CanDrawEllipsi(tmp.Y) then
    begin
      tmpItem:=Item(tmp.Y);

      if Assigned(tmpItem) and (tmpItem.Style<>iiSelection) then
      begin
        tmpR:=CellRect(tmp.X,tmp.Y); { Row,Col to screen pixel Rect }
        tmpR.Right:=tmpR.Left+TeeInspectorButtonSize;

        { clicked on rectangle? }
        if PointInRect(tmpR,X,Y) and tmpItem.Enabled then
           tmpCursor:=crHandPoint;
      end;
    end;
  end;

  Cursor:=tmpCursor;

  {$ENDIF}
end;

{ TComboFlatGrid }

{$IFNDEF CLX}
{$IFNDEF CLR}
{$IFNDEF LCL}
procedure TComboFlatGrid.CMFocusChanged(var Message: TCMFocusChanged);
begin
  if Visible then
     if GetFocus<>Handle then Hide;
end;
{$ENDIF}
{$ENDIF}
{$ELSE}
function TComboFlatGrid.EventFilter(Sender: QObjectH;
  Event: QEventH): Boolean;
begin
  Result := inherited EventFilter(Sender, Event);
  if QEvent_type(Event)=QEventType_FocusOut then
     if Visible then Hide;
end;
{$ENDIF}

{ TEditGrid }

{$IFNDEF CLX}
{$IFNDEF CLR}
{$IFNDEF LCL}
procedure TEditGrid.CMFocusChanged(var Message: TCMFocusChanged);
begin
  if Visible then
     if GetFocus<>Handle then Hide;
end;
{$ENDIF}
{$ENDIF}
{$ELSE}
function TEditGrid.EventFilter(Sender: QObjectH;
  Event: QEventH): Boolean;
begin
  Result := inherited EventFilter(Sender, Event);
  if QEvent_type(Event)=QEventType_FocusOut then
     if Visible then Hide;
end;
{$ENDIF}

{ TInspectorHeader }

constructor TInspectorHeader.Create;
begin
  inherited;
  FFont:=TTeeFont.Create(CanvasChanged);
  FVisible:=True;
end;

procedure TInspectorHeader.SetFont(const Value: TFont);
begin
  FFont.Assign(Value);
end;

Procedure TInspectorHeader.CanvasChanged(Sender:TObject);
begin
  Inspector.Invalidate;
end;

procedure TInspectorHeader.SetVisible(const Value: Boolean);
begin
  if FVisible<>Value then
  begin
    FVisible:=Value;
    Inspector.InternalSetHeader;
    Inspector.Rebuild;
  end;
end;

procedure TInspectorHeader.Update;
begin
  Inspector.InternalSetHeader;
  CanvasChanged(nil);
end;

destructor TInspectorHeader.Destroy;
begin
  FFont.Free;
  inherited;
end;

procedure TInspectorItem.SetStyle(const Value: TInspectorItemStyle);
begin
  if FStyle<>Value then
  begin
    FStyle:=Value;
    Inspector.Invalidate;
  end;
end;

function TInspectorItem.GetSelectedIndex(Items:TStrings): Integer;
begin
  result:=-1;

  if Assigned(FOnGetItemIndex) then
     FOnGetItemIndex(Self,result)
  else
  if Assigned(Data) then
     result:=Items.IndexOfObject(Data)
  else
  if not VarIsEmpty(Value) then
     result:=Items.IndexOf(Value)
end;

procedure TInspectorItem.FillItems(Items: TStrings);
begin
  if (Items.Count=0) and Assigned(FOnGetItems) then
     FOnGetItems(Self,Inspector.AddComboItem);
end;

end.

⌨️ 快捷键说明

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