SelUserFrm.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:7k
- unit SelUserFrm;
- interface
- uses
- SysUtils, Windows, Messages, Classes, Graphics, Controls,
- StdCtrls, ExtCtrls, Forms, ComCtrls,ChatingFrm,RealMessengerUnit,RealMessengerImpl,Commctrl,
- ToolWin,Global, bsSkinCtrls, BusinessSkinForm;
- type
- TSelUserForm = class(TForm)
- TrevUserList: TbsSkinTreeView;
- bsSkinPanel1: TbsSkinPanel;
- bsSkinScrollBar1: TbsSkinScrollBar;
- bsSkinScrollBar2: TbsSkinScrollBar;
- bsBusinessSkinForm1: TbsBusinessSkinForm;
- bsSkinGroupBox1: TbsSkinGroupBox;
- bsSkinPanel2: TbsSkinPanel;
- bsSkinButton1: TbsSkinButton;
- bsSkinButton2: TbsSkinButton;
- procedure TrevUserListCustomDrawItem(Sender: TCustomTreeView;
- Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
- procedure TrevUserListGetImageIndex(Sender: TObject; Node: TTreeNode);
- procedure FormShow(Sender: TObject);
- procedure TrevUserListMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure TBBranchsClick(Sender: TObject);
- procedure TBGroupsClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure TBOrOrOffClick(Sender: TObject);
- private
- procedure SetAllFalse();
- end;
- function IsNodeChecked(Node :TTreeNode) :Boolean;
- var
- SelUserForm: TSelUserForm;
- implementation
- {$R *.DFM}
- procedure DOYNChecked(Node: TTreeNode; isChecked: Boolean);
- {操作节点是否被checkd}
- var
- item:TTVItem;
- begin
- item.mask:=TVIF_HANDLE;
- item.hItem:=SelUserForm.TrevUserList.Items[Node.AbsoluteIndex].ItemId;
- TreeView_GetItem(SelUserForm.TrevUserList.Handle,item);
- item.mask:=TVIF_HANDLE or TVIF_STATE;
- if not isChecked then
- item.state:= (item.state or $1000) and (not $2000)
- else
- item.state:= (item.state or $2000) and (not $1000);
- item.stateMask:=$ffffffff;
- TreeView_SetItem(SelUserForm.TrevUserList.Handle,item);
- end;
- procedure AllChildYNChecked(Node: TTreeNode; isChecked: Boolean);
- {操作所有的子节点是否被checkd}
- var
- CurChild: TTreeNode;
- begin
- if Node.HasChildren then
- begin
- CurChild:=Node.GetFirstChild;
- while CurChild <> nil do
- begin
- DOYNChecked(CurChild, isChecked);
- if CurChild.HasChildren then
- begin
- AllChildYNChecked(CurChild, isChecked);
- end;
- CurChild:=Node.getNextChild(CurChild);
- end;
- end;
- end;{FreeDeleteNode}
- function IsNodeChecked(Node :TTreeNode) :Boolean;
- {判断节点是否被checkd}
- var
- item:TTVItem;
- begin
- item.mask:=TVIF_HANDLE;
- item.hItem:=SelUserForm.TrevUserList.Items[Node.AbsoluteIndex].ItemId;
- TreeView_GetItem(SelUserForm.TrevUserList.Handle,item);
- if (item.state and $2000)=0 then
- Result := False
- else
- Result := True;
- end;
- function isBrotherAllChecked(Node: TTreeNode): Boolean;
- {判断所有的兄弟节点是否已全部被checkd}
- var
- CurChild: TTreeNode;
- tmpBool: Boolean;
- begin
- Node := Node.Parent;
- if Node.HasChildren then
- begin
- CurChild:=Node.GetFirstChild;
- while CurChild <> nil do
- begin
- tmpBool := IsNodeChecked(CurChild);
- if not tmpBool then
- begin
- Result := False;
- exit;
- end;
- CurChild:=Node.getNextChild(CurChild);
- end;
- end;
- Result := True;
- end;
- procedure SetParentChecked(Node: TTreeNode);
- {当子节点checked时,设置父节点应该设置的checked}
- begin
- if Node.Parent <> nil then
- begin
- if isBrotherAllChecked(Node) then
- DOYNChecked(Node.Parent, True);
- SetParentChecked(Node.Parent);
- end;
- end;
- procedure SetParentNOChecked(Node: TTreeNode);
- {当子节点not checked时,设置父节点应该设置的checked}
- begin
- if Node.Parent <> nil then
- begin
- DOYNChecked(Node.Parent, False);
- SetParentNOChecked(Node.Parent);
- end;
- end;
- procedure SetComCtlStyle(Ctl: TWinControl; Value: Integer; UseStyle: Boolean);
- var
- Style: Integer;
- begin
- if Ctl.HandleAllocated then
- begin
- Style := GetWindowLong(Ctl.Handle, GWL_STYLE);
- if not UseStyle then Style := Style and not Value
- else Style := Style or Value;
- SetWindowLong(Ctl.Handle, GWL_STYLE, Style);
- end;
- end;
- {自定义CustomDrawItem,根据用户不同的状态显示不同颜色}
- procedure TSelUserForm.TrevUserListCustomDrawItem(Sender: TCustomTreeView;
- Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
- begin
- DefaultDraw:=true;
- if Node.Selected then
- begin
- TrevUserList.Canvas.Font.Color:=clWhite;
- end
- else
- begin
- if Node.StateIndex = 2 then
- begin
- if (Node.ImageIndex = 6) or (Node.ImageIndex = 10) then
- TrevUserList.Canvas.Font.Color:=clRed
- else
- TrevUserList.Canvas.Font.Color:=clGreen;
- end
- else
- TrevUserList.Canvas.Font.Color:=clBlack;
- end;
- TrevUserList.Canvas.Textout(Node.DisplayRect(True).Left+2,Node.DisplayRect(True).Top+2,Node.Text);
- end;
- {设置TreeView的节点图片}
- procedure TSelUserForm.TrevUserListGetImageIndex(Sender: TObject;
- Node: TTreeNode);
- begin
- if Node.StateIndex = -1 then
- begin
- if Node.Expanded then
- Node.ImageIndex:=4
- else
- Node.ImageIndex:=5;
- end;
- if Node.StateIndex = 0 then
- begin
- if Node.Expanded then
- Node.ImageIndex:=1
- else
- Node.ImageIndex:=0;
- end;
- if Node.StateIndex = 1 then
- begin
- if Node.Expanded then
- Node.ImageIndex:=3
- else
- Node.ImageIndex:=2;
- end;
- Node.SelectedIndex:=Node.ImageIndex;
- end;
- procedure TSelUserForm.TrevUserListMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- HitTests: THitTests;
- tmpNode: TTreeNode;
- begin
- HitTests := TrevUserList.GetHitTestInfoAt(X, Y);
- if htOnStateIcon in HitTests then
- begin
- tmpNode := TrevUserList.GetNodeAt(x, y);
- tmpNode.Selected := True;
- if IsNodeChecked(TrevUserList.Selected) then
- begin
- SetParentChecked(TrevUserList.Selected);
- AllChildYNChecked(TrevUserList.Selected, true);
- end
- else
- begin
- SetParentNOChecked(TrevUserList.Selected);
- AllChildYNChecked(TrevUserList.Selected, False);
- end;
- end;
- end;
- procedure TSelUserForm.FormShow(Sender: TObject);
- begin
- SetComCtlStyle(TrevUserList,TVS_CHECKBOXES,True);
- TBBranchsClick(nil);
- end;
- procedure TSelUserForm.SetAllFalse();
- var
- iLoop:Integer;
- begin
- for iLoop:=0 to TrevUserList.Items.Count-1 do
- begin
- DOYNChecked(TrevUserList.Items[iLoop],False);
- end;
- end;
- procedure TSelUserForm.TBBranchsClick(Sender: TObject);
- begin
- RealMessengerX.GetListViewData(TrevUserList,vsTree,True);
- SetAllFalse;
- end;
- procedure TSelUserForm.TBGroupsClick(Sender: TObject);
- begin
- RealMessengerX.GetListViewData(TrevUserList,vsGroup,True);
- SetAllFalse;
- end;
- procedure TSelUserForm.TBOrOrOffClick(Sender: TObject);
- begin
- RealMessengerX.GetListViewData(TrevUserList,vsOnlineOffline,True);
- SetAllFalse;
- end;
- procedure TSelUserForm.FormDestroy(Sender: TObject);
- var
- i:Integer;
- begin
- for i:=0 to TrevUserList.Items.Count-1 do FreeMem(TrevUserList.Items[i].Data,SizeOf(Employee));
- end;
- end.