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

📄 teeinspector.pas

📁 TeeChart7Source 控件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
            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
              Font.Color:=Color;
              Font.Name:=Name;
              Font.Style:=Style;
            end;

            DrawText(Font.Name);
          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;

            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 inherited;

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

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

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;

// Reload grid cells with Visible Items
procedure TTeeInspector.Rebuild;
var t   : Integer;
    tmp : Integer;
begin
  tmp:=0;
  for t:=0 to Items.Count-1 do if Items[t].Visible then Inc(tmp);
  RowCount:=Math.Max(1,tmp);

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

  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;

  if RowCount>MinRow then MoveColRow(1,MinRow,True,True);
end;

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

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

  inherited;

  if (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) 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:=Self.Item(Row).Value;
          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;
        end;
      end;

      tmpR.Right:=tmpR.Left+TeeInspectorButtonSize;

      { clicked on rectangle? }
      if PointInRect(tmpR,X,Y) then
      begin
        if tmpItem.Enabled then
        begin
          Case tmpItem.Style of
          iiBoolean: begin
                       if tmpItem.Value{$IFDEF CLR}=True{$ENDIF} then
                          tmpItem.Value:=False
                       else
                          tmpItem.Value:=True;
                     end;
            iiColor: tmpItem.Value:=EditColor(Self,{$IFDEF CLR}TColor{$ENDIF}(tmpItem.Value));
             iiFont: if tmpItem.Data is TTeeFont then
                        EditTeeFontEx(Self,TTeeFont(tmpItem.Data))
                     else
                        EditTeeFont(Self,TTeeFont(tmpItem.Data));
              iiPen: EditChartPen(Self,TChartPen(tmpItem.Data));
            iiBrush: EditChartBrush(Self,TChartBrush(tmpItem.Data));
         iiGradient: EditTeeGradient(Self,TCustomTeeGradient(tmpItem.Data));
          end;

          { repaing grid cell }
          if tmpItem.StyleToInt=0 then InvalidateCell(Col,Row);
  
          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
     With CellRect(1,Row) do MouseDown(mbLeft,[],Left+4,Top+4)
  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;
  end;

  if Assigned(IEditGrid) and ((not WhenVisible) or IEditGrid.Visible) then
  with IEditGrid do
  begin
    Left:=Self.Left+R.Left+1;
    Width:=R.Right-R.Left+1;
    Height:=R.Bottom-R.Top+1;
    Top:=Self.Top+R.Top;
  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.MouseMove(Shift: TShiftState; X, Y: Integer);
var tmpR      : TRect;
    tmp       : TGridCoord;
    tmpCursor : TCursor;
    tmpItem   : TInspectorItem;
begin
  tmpCursor:=crDefault;

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

  if (tmp.X=1) and ValidRow(tmp.Y) then { at column 1? }
  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;

  Cursor:=tmpCursor;
end;

{ TComboFlatGrid }

{$IFNDEF CLX}
{$IFNDEF CLR}
procedure TComboFlatGrid.CMFocusChanged(var Message: TCMFocusChanged);
begin
  if Visible then
     if GetFocus<>Handle then Hide;
end;
{$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}
procedure TEditGrid.CMFocusChanged(var Message: TCMFocusChanged);
begin
  if Visible then
     if GetFocus<>Handle then Hide;
end;
{$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;

end.

⌨️ 快捷键说明

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