OSDN Git Service

MaxValue changed
[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     btnDelete: TButton;
14     btnAdd: TButton;
15     btnDown: TButton;
16     btnUp: TButton;
17     btnEdit: TButton;
18     procedure lstRulesMeasureItem(Control: TWinControl; Index: Integer;
19       var Height: Integer);
20     procedure lstRulesDrawItem(Control: TWinControl; Index: Integer;
21       Rect: TRect; State: TOwnerDrawState);
22     procedure lstRulesClickCheck(Sender: TObject);
23     procedure EditRule(Sender: TObject);
24     procedure btnAddClick(Sender: TObject);
25     procedure btnDeleteClick(Sender: TObject);
26     procedure btnUpClick(Sender: TObject);
27     procedure btnDownClick(Sender: TObject);
28   private
29     { Private \90é\8c¾ }
30     procedure ExecuteEditRule(Rule: TBottleChainRule);
31   public
32     { Public \90é\8c¾ }
33     procedure UpdateDisplay;
34   end;
35
36 implementation
37
38 {$R *.dfm}
39
40 procedure TfrmBottleChainList.lstRulesMeasureItem(Control: TWinControl; Index: Integer;
41   var Height: Integer);
42 var Str: String;
43     ARect: TRect;
44 begin
45   ARect := lstRules.ItemRect(Index);
46   ARect.Left := ARect.Left + 2;
47   ARect.Right := ARect.Right - 2;
48
49   Str := BottleChainRuleList[Index].StringExpression;
50   //
51   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
52   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
53     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
54   Height := ARect.Bottom - ARect.Top;
55   //
56
57   ARect.Left := ARect.Left + 5;
58   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
59   Str := BottleChainRuleList[Index].Title;
60   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
61     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
62   Height := Height + ARect.Bottom - ARect.Top;
63   Height := Height + 4;
64 end;
65
66 procedure TfrmBottleChainList.lstRulesDrawItem(Control: TWinControl; Index: Integer;
67   Rect: TRect; State: TOwnerDrawState);
68 var Str: String;
69     y: integer;
70 begin
71   lstRules.Canvas.FillRect(Rect);
72
73   // \83e\83L\83X\83g\95`\89æ\97Ì\88æ\82Ì\83}\81[\83W\83\93\82ð\8eæ\82é
74   Rect.Left := Rect.Left + 2;
75   Rect.Top := Rect.Top + 2;
76   Rect.Right := Rect.Right - 2;
77   Rect.Bottom := Rect.Bottom - 2;
78
79   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
80   Str := BottleChainRuleList[Index].Title;
81   y := DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
82   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
83   Str := BottleChainRuleList[Index].StringExpression;
84   Rect.Top := Rect.Top + y;
85   Rect.Left := Rect.Left + 5;
86   DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
87 end;
88
89 procedure TfrmBottleChainList.UpdateDisplay;
90 var i: integer;
91     sel: TBottleChainRule;
92 begin
93   i := lstRules.ItemIndex;
94   if i >= 0 then begin
95     if i <= BottleChainRuleList.Count-1 then
96       sel := BottleChainRuleList[i]
97     else if BottleChainRuleList.Count > 0 then
98       sel := BottleChainRuleList[BottleChainRuleList.Count-1]
99     else
100       sel := nil;
101   end else sel := nil;
102
103   lstRules.Items.BeginUpdate;
104   lstRules.Items.Clear;
105   for i := 0 to BottleChainRuleList.Count-1 do begin
106     lstRules.Items.Add(BottleChainRuleList.Rules[i].StringExpression);
107     lstRules.Checked[i] := BottleChainRuleList[i].Enabled;
108   end;
109   lstRules.Items.EndUpdate;
110   lstRules.ItemIndex := BottleChainRuleList.List.IndexOf(sel);
111 end;
112
113 procedure TfrmBottleChainList.lstRulesClickCheck(Sender: TObject);
114 var i: integer;
115 begin
116   for i := 0 to BottleChainRuleList.Count-1 do begin
117     BottleChainRuleList[i].Enabled := lstRules.Checked[i];
118   end;
119 end;
120
121 procedure TfrmBottleChainList.EditRule(Sender: TObject);
122 begin
123   if lstRules.ItemIndex <> -1 then begin
124     ExecuteEditRule(BottleChainRuleList[lstRules.ItemIndex]);
125     UpdateDisplay;
126   end;
127 end;
128
129 procedure TfrmBottleChainList.btnAddClick(Sender: TObject);
130 var New: TBottleChainRule;
131 begin
132   New := TBottleChainRule.Create(BottleChainRuleList);
133   New.RuleList := BottleChainRuleList; // \8e©\95ª\82ð\83\8a\83X\83g\82É\92Ç\89Á\82·\82é
134   New.Enabled := true;
135   ExecuteEditRule(New);
136   UpdateDisplay;
137 end;
138
139 procedure TfrmBottleChainList.btnDeleteClick(Sender: TObject);
140 var Del: TBottleChainRule;
141 begin
142   if lstRules.ItemIndex < 0 then Exit;
143   Del := BottleChainRuleList[lstRules.ItemIndex];
144   Del.Free;
145   UpdateDisplay; 
146 end;
147
148 procedure TfrmBottleChainList.btnUpClick(Sender: TObject);
149 var i: integer;
150 begin
151   i := lstRules.ItemIndex;
152   if i > 0 then begin
153     BottleChainRuleList.List.Move(i, i - 1);
154     lstRules.ItemIndex := i - 1;
155     UpdateDisplay;
156   end;
157 end;
158
159 procedure TfrmBottleChainList.btnDownClick(Sender: TObject);
160 var i: integer;
161 begin
162   i := lstRules.ItemIndex;
163   if (i >= 0) and (i < lstRules.Items.Count-1) then begin
164     BottleChainRuleList.List.Move(i, i + 1);
165     lstRules.ItemIndex := i + 1;
166     UpdateDisplay;
167   end;
168 end;
169
170 procedure TfrmBottleChainList.ExecuteEditRule(Rule: TBottleChainRule);
171 var MyfrmBottleChainRuleEditor: TfrmBottleChainRuleEditor;
172 begin
173   Application.CreateForm(TfrmBottleChainRuleEditor, MyfrmBottleChainRuleEditor);
174   with MyfrmBottleChainRuleEditor do begin
175     try
176       Execute(Rule);
177     finally
178       Release;
179     end;
180   end;
181 end;
182
183 end.