📄 teeinspector.pas
字号:
end;
Procedure TTeeInspector.CreateEdit;
begin { create edit box }
IEditGrid:=TEditGrid.Create(Self);
with IEditGrid do
begin
Name:='IEditGrid';
Visible:=False;
OnChange:=Self.EditChange;
OnKeyDown:=Self.EditKeyDown;
end;
end;
Procedure TTeeInspector.SetComboIndex;
begin
with IComboGrid do
begin
if Items.Count=0 then
with Item(Row) do
if Assigned(FOnGetItems) then FOnGetItems(Item(Row),AddComboItem);
ItemIndex:=Items.IndexOfObject(Item(Row).Data);
end;
end;
Procedure TTeeInspector.CreateCombo;
begin { create combobox }
IComboGrid:=TComboFlatGrid.Create(Self);
with IComboGrid do
begin
Name:='IComboGrid';
Style:=csDropDownList;
DropDownCount:=8;
ItemHeight:=21;
Visible:=False;
OnChange:=Self.ComboChange;
end;
end;
Procedure TTeeInspector.Resize;
begin
inherited;
if ColCount>0 then
{$IFDEF CLX}
if (not Assigned(Owner)) or (not (csReading in Owner.ComponentState)) then
{$ENDIF}
ColWidths[1]:=ClientWidth-ColWidths[0];
{ resize combobox width (if visible) }
DoPositionCombos(True);
if (Row=0) and (RowCount>MinRow) then MoveColRow(1,MinRow,True,True);
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.EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case Key of
TeeKey_Escape: 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 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 Value:=StrToIntDef(IEditGrid.Text,0);
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
Value:=IComboGrid.Items[IComboGrid.ItemIndex];
Data:=IComboGrid.Items.Objects[IComboGrid.ItemIndex];
Changed;
end;
end;
Procedure TTeeInspector.Clear;
begin
Items.Clear;
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;
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}
and (Items[t].Enabled)
and (Items[t].HelpContext<>5) then { 5 means "dont put at inspector" }
begin
tmpSt:=StripHotkey(Items[t].Caption);
{ remove trailing ellipsi "..." }
While tmpSt[Length(tmpSt)]='.' do 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 Items[t].Count>0 then Style:=iiSelection;
end;
if Header.Visible then tmp2:=tmp
else tmp2:=tmp-1;
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;
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;
Function CellType(ARow:Integer):Integer;
var tmp : TInspectorItem;
begin { returns the type of the cell if it points to a menu item }
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;
Procedure DrawEllipsis;
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}
Pen.Handle:=TeeCreatePenSmallDots(clBlack);
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);
begin
if LeftPos=-1 then LeftPos:=ARect.Right+2;
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);
FillRect(TeeRect(ARect.Left,ARect.Top,ARect.Right-1,ARect.Bottom-1));
tmpSt:=ColorToString(Brush.Color);
if Copy(tmpSt,1,2)='cl' then
begin
Brush.Style:=bsClear;
DrawText(Copy(tmpSt,3,255));
end;
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 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
(Item(ARow).Style<>iiSelection) and
(Item(ARow).Style<>iiString) and
(Item(ARow).Style<>iiInteger) and
(Item(ARow).Style<>iiDouble) then
begin { button }
{$IFDEF CLX}
Pen.Style:=psSolid;
FillRect(ARect);
{$ELSE}
Dec(ARect.Bottom);
Dec(ARect.Right,2);
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
DrawEllipsis { button }
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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -