fcTreeView_ItemsEditor.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:22k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit fcTreeView_ItemsEditor;
  2. interface
  3. {$i fcIfDef.pas}
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   StdCtrls, ComCtrls, fcTreeView, ExtCtrls, checklst, fcCommon,   {$ifdef fcdelphi6up}
  7.   designintf,
  8.   {$else}
  9.   dsgnintf,
  10.   {$endif}
  11.   Buttons;
  12. type
  13.   TfcTreeViewItemsEditor = class(TForm)
  14.     GroupBox1: TGroupBox;
  15.     Label1: TLabel;
  16.     TextEdit: TEdit;
  17.     GroupBox2: TGroupBox;
  18.     Label2: TLabel;
  19.     Label3: TLabel;
  20.     Label4: TLabel;
  21.     ImageIndexEdit: TEdit;
  22.     SelectedIndexEdit: TEdit;
  23.     StateIndexEdit: TEdit;
  24.     ShowCheckBox: TCheckBox;
  25.     CheckListBox: TCheckListBox;
  26.     TreeView: TfcTreeView;
  27.     StringData1Edit: TEdit;
  28.     Label5: TLabel;
  29.     SaveDialog1: TSaveDialog;
  30.     OpenDialog1: TOpenDialog;
  31.     Label6: TLabel;
  32.     StringData2Edit: TEdit;
  33.     Panel1: TPanel;
  34.     Button1: TButton;
  35.     Button2: TButton;
  36.     Button4: TButton;
  37.     Panel2: TPanel;
  38.     NewItemButton: TSpeedButton;
  39.     NewSubitemButton: TSpeedButton;
  40.     DeleteButton: TSpeedButton;
  41.     MoveUpButton: TSpeedButton;
  42.     MoveDownButton: TSpeedButton;
  43.     LoadButton: TSpeedButton;
  44.     SpeedButton1: TSpeedButton;
  45.     CheckboxRadioGroup: TGroupBox;
  46.     CheckboxButton: TRadioButton;
  47.     RadioButton: TRadioButton;
  48.     GrayedCheckbox: TCheckBox;
  49.     procedure NewItemButtonClick(Sender: TObject);
  50.     procedure NewSubitemButtonClick(Sender: TObject);
  51.     procedure DeleteButtonClick(Sender: TObject);
  52.     procedure FormShow(Sender: TObject);
  53.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  54.     procedure Button3Click(Sender: TObject);
  55.     procedure TextEditChange(Sender: TObject);
  56.     procedure ShowCheckBoxClick(Sender: TObject);
  57.     procedure StateIndexEditExit(Sender: TObject);
  58.     procedure SelectedIndexEditExit(Sender: TObject);
  59.     procedure ImageIndexEditExit(Sender: TObject);
  60.     procedure CheckListBoxClickCheck(Sender: TObject);
  61.     procedure CheckListBoxDrawItem(Control: TWinControl; Index: Integer;
  62.       Rect: TRect; State: TOwnerDrawState);
  63.     procedure CheckListBoxClick(Sender: TObject);
  64.     procedure TreeViewDragDrop(Sender, Source: TObject; X, Y: Integer);
  65.     procedure MoveButtonClick(Sender: TObject);
  66.     procedure TreeViewMouseDown(TreeView: TfcCustomTreeView; Node: TfcTreeNode; Button: TMouseButton;
  67.       Shift: TShiftState; X, Y: Integer);
  68.     procedure TreeViewDragOver(Sender, Source: TObject; X, Y: Integer;
  69.       State: TDragState; var Accept: Boolean);
  70.     procedure StateIndexEditKeyDown(Sender: TObject; var Key: Word;
  71.       Shift: TShiftState);
  72.     procedure StringData1EditExit(Sender: TObject);
  73.     procedure LoadButtonClick(Sender: TObject);
  74.     procedure SpeedButton1Click(Sender: TObject);
  75.     procedure StringData2EditExit(Sender: TObject);
  76.     procedure FormResize(Sender: TObject);
  77.     procedure CheckboxButtonClick(Sender: TObject);
  78.     procedure RadioButtonClick(Sender: TObject);
  79.     procedure GrayedCheckboxClick(Sender: TObject);
  80.     procedure TreeViewToggleCheckbox(TreeView: TfcCustomTreeView;
  81.       Node: TfcTreeNode);
  82.     procedure TreeViewChanging(TreeView: TfcCustomTreeView;
  83.       Node: TfcTreeNode; var AllowChange: Boolean);
  84.     procedure TreeViewChange(TreeView: TfcCustomTreeView;
  85.       Node: TfcTreeNode);
  86.     procedure TreeViewCalcNodeAttributes(TreeView: TfcCustomTreeView;
  87.       Node: TfcTreeNode; State: TfcItemStates);
  88.     procedure Button4Click(Sender: TObject);
  89.     procedure FormKeyDown(Sender: TObject; var Key: Word;
  90.       Shift: TShiftState);
  91.   private
  92.     SuspendCheckboxList: Boolean;
  93.     InRefreshControls: boolean;
  94.     DataModified: boolean;
  95.     OrigTreeView: TfcCustomTreeView;
  96. //    DragFlag: Boolean;
  97.     procedure RefreshControls;
  98.     procedure UpdateNode(UpdateAll: boolean);
  99.     procedure RefreshChecklistBox(Node: TfcTreeNode);
  100.     procedure FillChecklistBox;
  101.     procedure SetCheckboxEnabled(val: boolean);
  102.     { Private declarations }
  103.   public
  104.     { Public declarations }
  105.   end;
  106.   {$ifdef fcDelphi6Up}
  107.   TFormDesigner = IDesigner;
  108.   {$else}
  109.   TFormDesigner = IFormDesigner;
  110.   {$endif}
  111.   procedure ExecuteTreeNodesEditor(ADesigner: TFormDesigner; ATreeView: TfcTreeView);
  112. var
  113.   fcTreeViewItemsEditor: TfcTreeViewItemsEditor;
  114. implementation
  115. {$R *.DFM}
  116. type TEditorTreeView = class(TfcTreeView);
  117. procedure ExecuteTreeNodesEditor(ADesigner: TFormDesigner; ATreeView: TfcTreeView);
  118. begin
  119.   with TfcTreeViewItemsEditor.Create(Application) do
  120.   begin
  121.     TEditorTreeView(TreeView).NodeClass := TEditorTreeView(ATreeView).NodeClass;
  122.     OrigTreeView:= ATreeView;
  123.     TreeView.Items.Assign(ATreeView.Items);
  124.     TreeView.MultiSelectAttributes.Assign(ATreeView.MultiSelectAttributes);
  125.     TreeView.Font.Assign(ATreeView.Font);
  126.     TreeView.Font.Color:= clWindowText; { 3/9/00 - Use window text for design - time }
  127.     if ATreeView.Images <> nil then
  128.       TreeView.Images:= ATreeView.Images;
  129.     if ATreeView.StateImages <> nil then
  130.       TreeView.StateImages := ATreeView.StateImages;
  131.     TreeView.Options:= ATreeView.Options - [tvoAutoURL, tvoHideSelection];
  132.     TreeView.Indent:= ATreeView.Indent;
  133.     if ShowModal = mrOK then
  134.     begin
  135.       ATreeView.Items.Assign(TreeView.Items);
  136.       if ADesigner <> nil then ADesigner.Modified else ShowMessage('nil');
  137.     end;
  138.     Free;
  139.   end;
  140. end;
  141. procedure TfcTreeViewItemsEditor.NewItemButtonClick(Sender: TObject);
  142. var ParentOfSelected: TfcTreeNode;
  143.     Node: TfcTreeNode;
  144. begin
  145. //   UpdateNode(False);
  146.    if TreeView.Selected=Nil then ParentOfSelected:= Nil
  147.    else ParentOfSelected:= TreeView.Selected.parent;
  148.    TreeView.selected := TreeView.Items.AddChild(ParentOfSelected, '');
  149.    if parentOfSelected=nil then
  150.       Node := TfcTreeNode(TreeView.Items.GetFirstNode)
  151.    else
  152.       Node := TfcTreeNode(parentOfSelected.GetFirstChild);
  153.    if (Node<>Nil) and (Node.CheckboxType=tvctRadioGroup) then
  154.    begin
  155.       TfcTreeNode(TreeView.selected).CheckboxType:= tvctRadioGroup;
  156.       TfcTreeNode(TreeView.selected).StateIndex:= 1;
  157.    end;
  158.    RefreshControls;
  159.    UpdateNode(False);
  160.    TextEdit.setFocus;
  161. end;
  162. procedure TfcTreeViewItemsEditor.NewSubitemButtonClick(Sender: TObject);
  163. begin
  164. //   UpdateNode;
  165.    if TreeView.selected<>Nil then
  166.    begin
  167.       TreeView.selected:= TreeView.Items.AddChild(TreeView.Selected, '');
  168.       UpdateNode(False);
  169.       TextEdit.setFocus;
  170.    end;
  171. end;
  172. procedure TfcTreeViewItemsEditor.DeleteButtonClick(Sender: TObject);
  173. begin
  174.   if TreeView.selected <> nil then
  175.   begin
  176.     TreeView.Items.Delete(TreeView.Selected);
  177.     RefreshControls;
  178.   end
  179. end;
  180. type TTempTree = class(TfcTreeView);
  181. procedure TfcTreeViewItemsEditor.FillChecklistBox;
  182. var BooleanProps: TStringList;
  183.     i: Integer;
  184.     Node: TfcTreeNode;
  185. begin
  186.   Node := TTempTree(TreeView).NodeClass.Create(TreeView.Items);
  187.   ChecklistBox.Items.Clear;
  188.   BooleanProps := TStringList.Create;
  189.   try
  190.     fcGetBooleanProps(Node, BooleanProps);
  191.     if BooleanProps.count>0 then
  192.     begin
  193.        CheckListbox.enabled:= True;
  194.        TabStop:= True;
  195.     end;
  196.     for i := 0 to BooleanProps.Count - 1 do
  197.       ChecklistBox.Items.Add(BooleanProps[i]);
  198.   finally
  199.     BooleanProps.Free;
  200.     Node.Free;
  201.   end;
  202. end;
  203. procedure TfcTreeViewItemsEditor.RefreshChecklistBox(Node: TfcTreeNode);
  204. var i: Integer;
  205. begin
  206.   SuspendCheckboxList := True;
  207.   for i := 0 to CheckListBox.Items.Count - 1 do
  208.     ChecklistBox.Checked[ChecklistBox.Items.Count - 1] :=
  209.       Boolean(fcGetOrdProp(Node, ChecklistBox.Items[i]));
  210.   SuspendCheckboxList := False;
  211. end;
  212. procedure TfcTreeViewItemsEditor.RefreshControls;
  213. var haveSelection: boolean;
  214. begin
  215.    haveSelection:= TreeView.selected<>Nil;
  216.    InRefreshControls:= True;
  217.    DeleteButton.enabled:= haveSelection;
  218.    NewSubItemButton.enabled:= haveSelection;
  219.    TextEdit.enabled:= haveSelection;
  220.    ImageIndexEdit.enabled:= haveSelection;
  221.    StringData1Edit.enabled:= haveSelection;
  222.    StringData2Edit.enabled:= haveSelection;
  223.    SelectedIndexEdit.enabled:= haveSelection;
  224.    StateIndexEdit.enabled:= haveSelection;
  225.    ShowCheckbox.enabled:= haveSelection;
  226.    CheckListBox.Enabled := haveSelection;
  227.    if ShowCheckBox.enabled then
  228.    begin
  229.        ShowCheckbox.enabled:= haveSelection and
  230.           not TreeView.MultiSelectCheckboxNeeded(TreeView.Selected);
  231.        if not ShowCheckbox.enabled then begin
  232.           ShowCheckbox.checked:= false;
  233.        end
  234.    end;
  235.    if TreeView.selected <> nil then
  236.    begin
  237.       RefreshChecklistBox(TreeView.Selected);
  238.       TextEdit.text:= TreeView.Selected.Text;
  239.       ImageIndexEdit.text:= inttostr(TreeView.Selected.ImageIndex);
  240.       StringData1Edit.text:= TreeView.Selected.StringData;
  241.       StringData2Edit.text:= TreeView.Selected.StringData2;
  242.       SelectedIndexEdit.text:= inttostr(TreeView.Selected.SelectedIndex);
  243.       StateIndexEdit.text:= inttostr(TreeView.Selected.StateIndex);
  244.       ShowCheckbox.checked:= (TreeView.Selected as TfcTreeNode).CheckboxType<>tvctNone;
  245.       If ShowCheckbox.checked then begin
  246.          StateIndexEdit.enabled:= False;
  247.          if (TreeView.Selected as TfcTreeNode).CheckboxType=tvctRadioGroup then
  248.          begin
  249.             CheckboxButton.checked:= False;
  250.             RadioButton.checked:= True;
  251.          end
  252.          else begin
  253.             CheckboxButton.checked:= True;
  254.             RadioButton.checked:= False;
  255.          end;
  256.          GrayedCheckbox.checked:= TreeView.Selected.Grayed;
  257.       end
  258.       else begin
  259.          CheckboxButton.checked:= True;
  260.          RadioButton.checked:= False;
  261.       end;
  262.       SetCheckboxEnabled(ShowCheckbox.checked);
  263.    end;
  264.    InRefreshControls:= False;
  265. end;
  266. procedure TfcTreeViewItemsEditor.SetCheckboxEnabled(val: boolean);
  267. begin
  268.     CheckboxButton.enabled:= val;
  269.     RadioButton.enabled:= val;
  270.     GrayedCheckbox.enabled:= val;
  271. end;
  272. procedure TfcTreeViewItemsEditor.UpdateNode(UpdateAll: boolean);
  273.     procedure SetSiblingsToRadio(Node: TfcTreeNode; RadioGroupFlag: boolean);
  274.     begin
  275.        Node:=  TreeView.GetFirstSibling(Node);
  276. {       parentNode:= TwwTreeNode(TreeView.selected.parent);
  277.        if parentNode=nil then
  278.           Node := TreeView.Items.GetFirstNode as TwwTreeNode
  279.        else
  280.           Node := TwwTreeNode(parentNode.GetFirstChild);
  281. }
  282.        while Node <> nil do
  283.        begin
  284.           if RadioGroupFlag then begin
  285.              Node.CheckboxType:= tvctRadioGroup;
  286.              Node.StateIndex:=strtoint(StateIndexEdit.text);
  287.           end
  288.           else if Node.CheckboxType=tvctRadioGroup then begin
  289.              Node.CheckboxType:= tvctNone;
  290.              Node.StateIndex:=-1;
  291.           end;
  292.           Node := TfcTreeNode(Node.GetNextSibling);
  293.        end;
  294.        TreeView.Invalidate;
  295.     end;
  296. begin
  297.     if TreeView.selected<>nil then begin
  298.        DataModified:= True;
  299.        TreeView.Selected.Text := TextEdit.text;
  300.        if ImageIndexEdit.text<>'' then
  301.           TreeView.Selected.ImageIndex:= strtoint(ImageIndexEdit.text);
  302.        if StringData1Edit.text<>'' then
  303.           TreeView.Selected.StringData:= StringData1Edit.text;
  304.        if StringData2Edit.text<>'' then
  305.           TreeView.Selected.StringData2:= StringData2Edit.text;
  306.        if SelectedIndexEdit.text<>'' then
  307.           TreeView.Selected.SelectedIndex:= strtoint(SelectedIndexEdit.text);
  308.        if StateIndexEdit.text<>'' then
  309.           TreeView.Selected.StateIndex:= strtoint(stateindexedit.text);
  310.        if not UpdateAll then exit;
  311.        if ShowCheckbox.checked then
  312.        begin
  313.           if RadioButton.checked then { Radio group }
  314.              SetSiblingsToRadio(TfcTreeNode(TreeView.selected), True)
  315.           else begin
  316.              SetSiblingsToRadio(TfcTreeNode(TreeView.selected), False);
  317.              if CheckboxButton.checked then
  318.                 (TreeView.selected as TfcTreeNode).CheckboxType:= tvctCheckbox
  319.              else
  320.                 (TreeView.selected as TfcTreeNode).CheckboxType:= tvctRadioGroup;
  321.              (TreeView.selected as TfcTreeNode).StateIndex:=strtoint(StateIndexEdit.text);
  322.           end;
  323.           TreeView.selected.grayed:=GrayedCheckbox.checked;
  324.        end
  325.        else begin
  326.           if RadioButton.checked then { Radio group }
  327.              SetSiblingsToRadio(TfcTreeNode(TreeView.selected), False)
  328.           else (TreeView.selected as TfcTreeNode).CheckboxType:= tvctNone;
  329.        end
  330.     end;
  331. end;
  332. procedure TfcTreeViewItemsEditor.FormShow(Sender: TObject);
  333. begin
  334.    FillChecklistBox;  { 4/22/99 - Put before refresh controls }
  335.    RefreshControls;
  336.    TreeView.Options:= TreeView.Options - [tvo3StateCheckbox];
  337. //   TreeView.ReadOnly:= True;
  338. end;
  339. procedure TfcTreeViewItemsEditor.FormClose(Sender: TObject;
  340.   var Action: TCloseAction);
  341. var answer: integer;
  342. begin
  343.    if ModalResult = mrOK then UpdateNode(True)
  344.    else if (ModalResult = mrCancel) and DataModified then begin
  345.       answer:= MessageDlg('Changes have been made!  Do you wish to save them?',
  346.            mtConfirmation, [mbYes, mbNo, mbCancel], 0);
  347.       if (answer = mrYes) then ModalResult:= mrOK
  348.       else if (answer = mrNo) then ModalResult:= mrCancel
  349.       else Action:= caNone;
  350.    end
  351. end;
  352. procedure TfcTreeViewItemsEditor.Button3Click(Sender: TObject);
  353. begin
  354.    UpdateNode(True);
  355. end;
  356. procedure TfcTreeViewItemsEditor.TextEditChange(Sender: TObject);
  357. begin
  358.    if TextEdit.modified then
  359.    begin
  360.       TreeView.Selected.Text:= TextEdit.Text;
  361.       DataModified:= True;
  362.    end
  363. //   if (Sender as TEdit).Focused then UpdateNode;
  364. //   if TreeView.Selected<>Nil then
  365. //      TreeView.Selected.Text:= (Sender as TEdit).text;
  366. end;
  367. procedure TfcTreeViewItemsEditor.ShowCheckBoxClick(Sender: TObject);
  368. begin
  369.    if InRefreshControls then exit;
  370.    if ShowCheckbox.checked then
  371.    begin
  372.       StateIndexEdit.text:= '1';
  373.       StateIndexEdit.enabled:= False;
  374.       SetCheckboxEnabled(true);
  375.    end
  376.    else begin
  377.       StateIndexEdit.text:= '-1';
  378.       StateIndexEdit.enabled:= True;
  379.       SetCheckboxEnabled(false);
  380.    end;
  381.    UpdateNode(True);
  382. end;
  383. procedure TfcTreeViewItemsEditor.StateIndexEditExit(Sender: TObject);
  384. begin
  385.    if StateIndexEdit.modified then
  386.    begin
  387.       TreeView.Selected.StateIndex:= strtoint(StateIndexEdit.Text);
  388.       TreeView.InvalidateNode(TreeView.Selected);
  389.       DataModified:= True;
  390.    end
  391. end;
  392. procedure TfcTreeViewItemsEditor.SelectedIndexEditExit(Sender: TObject);
  393. begin
  394.    if SelectedIndexEdit.modified then
  395.    begin
  396.       TreeView.Selected.SelectedIndex:= strtoint(SelectedIndexEdit.Text);
  397.       DataModified:= True;
  398.    end
  399. end;
  400. procedure TfcTreeViewItemsEditor.ImageIndexEditExit(Sender: TObject);
  401. begin
  402.    if ImageIndexEdit.modified then
  403.    begin
  404.       TreeView.Selected.ImageIndex:= strtoint(ImageIndexEdit.Text);
  405.       TreeView.InvalidateNode(TreeView.Selected);
  406.       DataModified:= True;
  407.    end
  408. end;
  409. procedure TfcTreeViewItemsEditor.CheckListBoxClickCheck(Sender: TObject);
  410. begin
  411.   if SuspendCheckboxList then Exit;
  412.   if TreeView.Selected <> nil then
  413.     fcSetOrdProp(TreeView.Selected, CheckListBox.Items[CheckListBox.ItemIndex],
  414.       ord(CheckListBox.Checked[CheckListBox.ItemIndex]));
  415. end;
  416. procedure TfcTreeViewItemsEditor.CheckListBoxDrawItem(Control: TWinControl;
  417.   Index: Integer; Rect: TRect; State: TOwnerDrawState);
  418.   function ExtrapolateText: string;
  419.   var i: Integer;
  420.   begin
  421.     result := ChecklistBox.Items[Index];
  422.     i := 2;
  423.     while i <= Length(result) do
  424.     begin
  425.       if result[i] in ['A'..'Z'] then
  426.       begin
  427.         Insert(' ', result, i);
  428.         inc(i);
  429.       end;
  430.       inc(i);
  431.     end;
  432.   end;
  433. begin
  434.   Inc(Rect.Left, 2);
  435.   SetBkMode(ChecklistBox.Canvas.Handle, TRANSPARENT);
  436.   SetBkColor(ChecklistBox.Canvas.Handle, 0);
  437.   SetTextColor(ChecklistBox.Canvas.Handle, ColorToRGB(Font.Color));
  438.   DrawText(ChecklistBox.Canvas.Handle, PChar(ExtrapolateText),
  439.     Length(ExtrapolateText), Rect, DT_VCENTER or DT_SINGLELINE);
  440. end;
  441. procedure TfcTreeViewItemsEditor.CheckListBoxClick(Sender: TObject);
  442. begin
  443. //  CheckListBox.Checked[CheckListBox.ItemIndex] := not CheckListBox.Checked[CheckListBox.ItemIndex];
  444. end;
  445. procedure TfcTreeViewItemsEditor.TreeViewDragDrop(Sender, Source: TObject;
  446.   X, Y: Integer);
  447. var HitTest : TfcHitTests;
  448.     KeyState: TKeyboardState;
  449. begin
  450.   with (Sender as TfcTreeView) do begin
  451.     HitTest := GetHitTestInfoAt(X,Y);
  452.     if (Selected <> nil) and
  453.        ([fchtOnItem, fchtOnButton, fchtOnIndent, fchtOnLabel, fchtOnRight] * HitTest <> []) then
  454.     begin
  455.        if ([fchtOnItem, fchtOnButton, fchtOnIndent, fchtOnLabel, fchtOnRight] * HitTest <> []) then
  456.        begin
  457.           Items.BeginUpdate;
  458.           DataModified:= True;
  459.           GetKeyboardState(KeyState);
  460.           if KeyState[vk_Shift]>=128 then
  461.              Selected.MoveTo(GetNodeAt(X,Y), fcnaAddChild)
  462.           else begin
  463.              if (GetNodeAt(X,Y)=nil) then
  464.                 Selected.MoveTo(GetNodeAt(X,Y), fcnaInsertAfter)
  465.              else
  466.                 Selected.MoveTo(GetNodeAt(X,Y), fcnaInsert);
  467.           end;
  468.           Items.EndUpdate;
  469.        end
  470.     end
  471.     else if fchtNowhere in HitTest then
  472.     begin
  473.        Selected.MoveTo(DropTarget, fcnaAdd)
  474.     end;
  475.     DropTarget := nil;
  476.     Screen.Cursor := crDefault;
  477.   end
  478. end;
  479. procedure TfcTreeViewItemsEditor.MoveButtonClick(Sender: TObject);
  480. var NextSibling: TfcTreeNode;
  481.     Mode: TfcNodeAttachMode;
  482. begin
  483.   Mode := fcnaInsert;
  484.   if (TreeView.Selected = nil) then Exit;
  485.   if (Sender as TSpeedButton).Tag < 0 then
  486.   begin
  487.     NextSibling := TreeView.Selected.GetNextSibling;
  488.     if NextSibling = nil then Exit;
  489.     NextSibling := NextSibling.GetNextSibling;
  490.     if NextSibling = nil then
  491.     begin
  492.       NextSibling := TreeView.Selected;
  493.       Mode := fcnaAdd;
  494.     end;
  495.   end else NextSibling := TreeView.Selected.GetPrevSibling;
  496.   if NextSibling = nil then Exit;
  497.   TreeView.Items.BeginUpdate;
  498.   TreeView.Selected.MoveTo(NextSibling, Mode);
  499.   TreeView.Items.EndUpdate;
  500.   DataModified := True;
  501. end;
  502. procedure TfcTreeViewItemsEditor.TreeViewMouseDown(TreeView: TfcCustomTreeView;
  503.   Node: TfcTreeNode; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  504. begin
  505.   if fchtOnLabel in TreeView.GetHitTestInfoAt(X,Y) then
  506.      TreeView.BeginDrag(False);
  507. end;
  508. procedure TfcTreeViewItemsEditor.TreeViewDragOver(Sender, Source: TObject;
  509.   X, Y: Integer; State: TDragState; var Accept: Boolean);
  510. begin
  511.   Accept:= True;
  512. end;
  513. procedure TfcTreeViewItemsEditor.StateIndexEditKeyDown(Sender: TObject;
  514.   var Key: Word; Shift: TShiftState);
  515. begin
  516.   if key=vk_return then begin
  517.     if ActiveControl = TextEdit then
  518.     begin
  519.        NewItemButton.Click;
  520.     end
  521.     else if (ActiveControl = ImageIndexEdit) or
  522.             (ActiveControl = StringData1Edit) or
  523.             (ActiveControl = StringData2Edit) or
  524.             (ActiveControl = SelectedIndexEdit) or
  525.             (ActiveControl = StateIndexEdit) then
  526.     begin
  527.        TEdit(ActiveControl).OnExit(ActiveControl);
  528.        TEdit(ActiveControl).SelectAll;
  529.     end
  530.   end
  531. end;
  532. procedure TfcTreeViewItemsEditor.StringData1EditExit(Sender: TObject);
  533. begin
  534.    if (Sender as TEdit).modified then
  535.    begin
  536.       TreeView.Selected.StringData:= (Sender as TEdit).Text;
  537.       DataModified:= True;
  538.    end
  539. end;
  540. procedure TfcTreeViewItemsEditor.LoadButtonClick(Sender: TObject);
  541. begin
  542.   if OpenDialog1.Execute then
  543.   begin
  544.      TreeView.LoadFromFile(OpenDialog1.FileName);
  545.   end;
  546. end;
  547. procedure TfcTreeViewItemsEditor.SpeedButton1Click(Sender: TObject);
  548. begin
  549.   if SaveDialog1.Execute then
  550.   begin
  551.     if FileExists(SaveDialog1.FileName) then
  552.       if MessageDlg(Format('OK to overwrite %s', [SaveDialog1.FileName]),
  553.         mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
  554.     TreeView.SaveToFile(SaveDialog1.FileName);
  555.   end;
  556. end;
  557. procedure TfcTreeViewItemsEditor.StringData2EditExit(Sender: TObject);
  558. begin
  559.    if (Sender as TEdit).modified then
  560.    begin
  561.       TreeView.Selected.StringData2:= (Sender as TEdit).Text;
  562.       DataModified:= True;
  563.    end
  564. end;
  565. procedure TfcTreeViewItemsEditor.FormResize(Sender: TObject);
  566. begin
  567.   if Width<500 then Width:= 500;
  568.   if Height<325 then Height:= 325;
  569. end;
  570. procedure TfcTreeViewItemsEditor.CheckboxButtonClick(Sender: TObject);
  571. begin
  572.    RadioButton.checked:= False;
  573.    if InRefreshControls then exit;
  574.    UpdateNode(True);
  575. end;
  576. procedure TfcTreeViewItemsEditor.RadioButtonClick(Sender: TObject);
  577. begin
  578.    CheckboxButton.checked:= False;
  579.    if InRefreshControls then exit;
  580.    UpdateNode(True);
  581. end;
  582. procedure TfcTreeViewItemsEditor.GrayedCheckboxClick(Sender: TObject);
  583. begin
  584.    if InRefreshControls then exit;
  585.    UpdateNode(True);
  586. end;
  587. procedure TfcTreeViewItemsEditor.TreeViewToggleCheckbox(
  588.   TreeView: TfcCustomTreeView; Node: TfcTreeNode);
  589. begin
  590.    RefreshControls;
  591. end;
  592. procedure TfcTreeViewItemsEditor.TreeViewChanging(
  593.   TreeView: TfcCustomTreeView; Node: TfcTreeNode;
  594.   var AllowChange: Boolean);
  595. begin
  596.    try
  597.       if ImageIndexEdit.modified or StateIndexEdit.modified or
  598.          SelectedIndexEdit.modified or StringData1Edit.modified or
  599.          StringData2Edit.modified then
  600.          UpdateNode(False);
  601.    except
  602.       AllowChange:= False;
  603.       raise;
  604.    end;
  605. end;
  606. procedure TfcTreeViewItemsEditor.TreeViewChange(
  607.   TreeView: TfcCustomTreeView; Node: TfcTreeNode);
  608. begin
  609.    RefreshControls;
  610. end;
  611. procedure TfcTreeViewItemsEditor.TreeViewCalcNodeAttributes(
  612.   TreeView: TfcCustomTreeView; Node: TfcTreeNode; State: TfcItemStates);
  613. begin
  614.   if (Node.StringData<>'') and (tvoAutoURL in OrigTreeView.Options) then
  615.   begin
  616.       if not (fcisSelected in State) or not TreeView.Focused then
  617.          Treeview.Canvas.Font.Color:= clBlue;
  618.       Treeview.Canvas.Font.Style:=
  619.               Canvas.Font.Style + [fsUnderline];
  620.   end
  621. end;
  622. procedure TfcTreeViewItemsEditor.Button4Click(Sender: TObject);
  623. begin
  624.   fcHelp(Handle, 'TfcTreeView Nodes Editor');
  625. end;
  626. procedure TfcTreeViewItemsEditor.FormKeyDown(Sender: TObject;
  627.   var Key: Word; Shift: TShiftState);
  628. begin
  629.   if Key = VK_F1 then Button4Click(Button4);
  630. end;
  631. end.