OSDN Git Service

DrawText modified
[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   ARect.Left := ARect.Left + 2;
43   ARect.Right := ARect.Right - 2;
44
45   Str := BottleChainRuleList[Index].StringExpression;
46   //
47   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
48   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
49     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
50   Height := ARect.Bottom - ARect.Top;
51   //
52
53   ARect.Left := ARect.Left + 5;
54   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
55   Str := BottleChainRuleList[Index].Title;
56   DrawText(lstRules.Canvas.Handle, PChar(Str), -1,
57     ARect, DT_NOPREFIX or DT_EDITCONTROL or DT_CALCRECT or DT_WORDBREAK);
58   Height := Height + ARect.Bottom - ARect.Top;
59   Height := Height + 4;
60 end;
61
62 procedure TfrmBottleChainList.lstRulesDrawItem(Control: TWinControl; Index: Integer;
63   Rect: TRect; State: TOwnerDrawState);
64 var Str: String;
65     y: integer;
66 begin
67   lstRules.Canvas.FillRect(Rect);
68
69   // \83e\83L\83X\83g\95`\89æ\97Ì\88æ\82Ì\83}\81[\83W\83\93\82ð\8eæ\82é
70   Rect.Left := Rect.Left + 2;
71   Rect.Top := Rect.Top + 2;
72   Rect.Right := Rect.Right - 2;
73   Rect.Bottom := Rect.Bottom - 2;
74
75   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style + [fsBold];
76   Str := BottleChainRuleList[Index].Title;
77   y := DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
78   lstRules.Canvas.Font.Style := lstRules.Canvas.Font.Style - [fsBold];
79   Str := BottleChainRuleList[Index].StringExpression;
80   Rect.Top := Rect.Top + y;
81   Rect.Left := Rect.Left + 5;
82   DrawText(lstRules.Canvas.Handle, PChar(Str), -1, Rect, DT_NOPREFIX or DT_WORDBREAK);
83 end;
84
85 procedure TfrmBottleChainList.Button1Click(Sender: TObject);
86 var instance: TBottleChainRuleList;
87     rule: TBottleChainRule;
88     condition: TBottleChainCondition;
89     str: String;
90 begin
91   instance := TBottleChainRuleList.Create(nil);
92   try
93     rule := TBottleChainRule.Create(instance);
94     rule.RuleList := instance;
95     condition := TBottleChainChannelCondition.Create(rule);
96     (condition as TBottleChainChannelCondition).Channels.Add('\8fd\97v');
97     (condition as TBottleChainChannelCondition).Channels.Add('Important');
98     Condition.Rule := rule;
99     str := ComponentToString(instance);
100     ShowMessage(str);
101   finally
102     instance.Free;
103   end;
104   instance := StringToComponent(str) as TBottleChainRuleList;
105   ShowMessage(ComponentToString(instance));
106 end;
107
108 procedure TfrmBottleChainList.UpdateDisplay;
109 var i: integer;
110 begin
111   lstRules.Items.Clear;
112   for i := 0 to BottleChainRuleList.Count-1 do begin
113     lstRules.Items.Add(BottleChainRuleList.Rules[i].StringExpression);
114     lstRules.Checked[i] := BottleChainRuleList[i].Enabled;
115   end;
116 end;
117
118 procedure TfrmBottleChainList.lstRulesClickCheck(Sender: TObject);
119 var i: integer;
120 begin
121   for i := 0 to BottleChainRuleList.Count-1 do begin
122     BottleChainRuleList[i].Enabled := lstRules.Checked[i];
123   end;
124 end;
125
126 procedure TfrmBottleChainList.EditRule(Sender: TObject);
127 begin
128   if lstRules.ItemIndex <> -1 then begin
129     frmBottleChainRuleEditor.Execute(BottleChainRuleList[lstRules.ItemIndex]);
130     UpdateDisplay;
131   end;
132 end;
133
134 procedure TfrmBottleChainList.btnAddClick(Sender: TObject);
135 var New: TBottleChainRule;
136 begin
137   New := TBottleChainRule.Create(BottleChainRuleList);
138   New.RuleList := BottleChainRuleList; // \8e©\95ª\82ð\83\8a\83X\83g\82É\92Ç\89Á\82·\82é
139   frmBottleChainRuleEditor.Execute(New);
140   UpdateDisplay;
141 end;
142
143 procedure TfrmBottleChainList.btnDeleteClick(Sender: TObject);
144 var Del: TBottleChainRule;
145 begin
146   if lstRules.ItemIndex < 0 then Exit;
147   Del := BottleChainRuleList[lstRules.ItemIndex];
148   Del.Free;
149   UpdateDisplay; 
150 end;
151
152 end.