OSDN Git Service

Editing routines implemented
[winbottle/winbottle.git] / bottleclient / BottleChainListFrame.pas
1 unit BottleChainListFrame;
2
3 interface
4
5 uses
6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
7   Dialogs, BottleChainEvent, BottleChainRule, StdCtrls, CheckLst,
8   BottleChainRuleEditor;
9
10 type
11   TfrmBottleChainList = class(TFrame)
12     lstRules: TCheckListBox;
13     Button1: TButton;
14     btnDelete: TButton;
15     btnAdd: TButton;
16     procedure lstRulesMeasureItem(Control: TWinControl; Index: Integer;
17       var Height: Integer);
18     procedure lstRulesDrawItem(Control: TWinControl; Index: Integer;
19       Rect: TRect; State: TOwnerDrawState);
20     procedure Button1Click(Sender: TObject);
21     procedure lstRulesClickCheck(Sender: TObject);
22     procedure EditRule(Sender: TObject);
23     procedure btnAddClick(Sender: TObject);
24     procedure btnDeleteClick(Sender: TObject);
25   private
26     { Private \90é\8c¾ }
27   public
28     { Public \90é\8c¾ }
29     procedure UpdateDisplay;
30   end;
31
32 implementation
33
34 {$R *.dfm}
35
36 procedure TfrmBottleChainList.lstRulesMeasureItem(Control: TWinControl; Index: Integer;
37   var Height: Integer);
38 var Str: String;
39     ARect: TRect;
40 begin
41   ARect := lstRules.ItemRect(Index);
42   Str := BottleChainRuleList[Index].StringExpression;
43   //
44   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
45   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
46     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
47   Height := ARect.Bottom - ARect.Top;
48   //
49   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
50   Str := BottleChainRuleList[Index].Title;
51   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
52     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
53   Height := Height + ARect.Bottom - ARect.Top;
54   Height := Height + 4;
55 end;
56
57 procedure TfrmBottleChainList.lstRulesDrawItem(Control: TWinControl; Index: Integer;
58   Rect: TRect; State: TOwnerDrawState);
59 var Str: String;
60     y: integer;
61 begin
62   lstRules.Canvas.FillRect(Rect);
63
64   // \83e\83L\83X\83g\95`\89æ\97Ì\88æ\82Ì\83}\81[\83W\83\93\82ð\8eæ\82é
65   Rect.Left := Rect.Left + 2;
66   Rect.Top := Rect.Top + 2;
67   Rect.Right := Rect.Right - 2;
68   Rect.Bottom := Rect.Bottom - 2;
69
70   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
71   Str := BottleChainRuleList[Index].Title;
72   y := DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_EDITCONTROL or DT_WORDBREAK);
73   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
74   Str := BottleChainRuleList[Index].StringExpression;
75   Rect.Top := Rect.Top + y;
76   DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_EDITCONTROL or DT_WORDBREAK);
77 end;
78
79 procedure TfrmBottleChainList.Button1Click(Sender: TObject);
80 var instance: TBottleChainRuleList;
81     rule: TBottleChainRule;
82     condition: TBottleChainCondition;
83     str: String;
84 begin
85   instance := TBottleChainRuleList.Create(nil);
86   try
87     rule := TBottleChainRule.Create(instance);
88     rule.RuleList := instance;
89     condition := TBottleChainChannelCondition.Create(rule);
90     (condition as TBottleChainChannelCondition).Channels.Add('\8fd\97v');
91     (condition as TBottleChainChannelCondition).Channels.Add('Important');
92     Condition.Rule := rule;
93     str := ComponentToString(instance);
94     ShowMessage(str);
95   finally
96     instance.Free;
97   end;
98   instance := StringToComponent(str) as TBottleChainRuleList;
99   ShowMessage(ComponentToString(instance));
100 end;
101
102 procedure TfrmBottleChainList.UpdateDisplay;
103 var i: integer;
104 begin
105   lstRules.Items.Clear;
106   for i := 0 to BottleChainRuleList.Count-1 do begin
107     lstRules.Items.Add(BottleChainRuleList.Rules[i].StringExpression);
108     lstRules.Checked[i] := BottleChainRuleList[i].Enabled;
109   end;
110 end;
111
112 procedure TfrmBottleChainList.lstRulesClickCheck(Sender: TObject);
113 var i: integer;
114 begin
115   for i := 0 to BottleChainRuleList.Count-1 do begin
116     BottleChainRuleList[i].Enabled := lstRules.Checked[i];
117   end;
118 end;
119
120 procedure TfrmBottleChainList.EditRule(Sender: TObject);
121 begin
122   if lstRules.ItemIndex <> -1 then begin
123     frmBottleChainRuleEditor.Execute(BottleChainRuleList[lstRules.ItemIndex]);
124     UpdateDisplay;
125   end;
126 end;
127
128 procedure TfrmBottleChainList.btnAddClick(Sender: TObject);
129 var New: TBottleChainRule;
130 begin
131   New := TBottleChainRule.Create(BottleChainRuleList);
132   New.RuleList := BottleChainRuleList; // \8e©\95ª\82ð\83\8a\83X\83g\82É\92Ç\89Á\82·\82é
133   frmBottleChainRuleEditor.Execute(New);
134   UpdateDisplay;
135 end;
136
137 procedure TfrmBottleChainList.btnDeleteClick(Sender: TObject);
138 var Del: TBottleChainRule;
139 begin
140   if lstRules.ItemIndex < 0 then Exit;
141   Del := BottleChainRuleList[lstRules.ItemIndex];
142   Del.Free;
143   UpdateDisplay; 
144 end;
145
146 end.