OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb55'.
[gikonavigoeson/gikonavi.git] / MoveHistoryItem.pas
1 unit MoveHistoryItem;
2
3 interface
4  
5 uses
6     SysUtils, Classes, BoardGroup, BrowserRecord,
7 {$IF Defined(DELPRO) }
8         SHDocVw,
9         MSHTML,
10 {$ELSE}
11         SHDocVw_TLB,
12         MSHTML_TLB,
13 {$IFEND}
14     OleCtrls, ActiveX;
15 type
16
17     TMoveHistoryItem = class(TObject)
18     private
19         FThreadItem : TThreadItem;
20         FScrollTop  : Integer;
21     public
22         property ThreadItem : TThreadItem read FThreadItem write FThreadItem;
23         property ScrollTop : Integer read FScrollTop write FScrollTop;
24     end;
25
26     TMoveHistory = class(TList)
27     private
28         FHistoryMax : Integer;
29         FIndex : Integer;
30         {
31         \brief \83\8a\83\93\83N\88Ú\93®\97\9a\97ð\8dÅ\91å\95Û\8e\9d\90\94\82ð\90Ý\92è\82·\82é\81B
32         \param  AVal \95Û\8e\9d\90\94
33         }
34         procedure SetHistoryMax(AVal: Integer);
35         {
36         \brief \83\8a\83\93\83N\88Ú\93®\97\9a\97ð\8dÅ\91å\95Û\8e\9d\90\94\82ð\8eæ\93¾\82·\82é\81B
37         \return \95Û\8e\9d\90\94( > 0 )
38         }
39         function GetHistoryMax: Integer;
40     public
41         constructor Create( max : Integer ); overload;
42         function pushItem( item: TMoveHistoryItem): Integer; overload;
43         function pushItem( item: TBrowserRecord): Integer; overload;
44         function getPrevItem( item: TBrowserRecord): TMoveHistoryItem;
45         function getNextItem: TMoveHistoryItem;
46         procedure clear; override;
47         property HistoryMax : Integer read GetHistoryMax write SetHistoryMax;
48         property HisotryIndex: Integer read FIndex;
49     end;
50
51 var
52     MoveHisotryManager : TMoveHistory;
53
54 implementation
55
56 uses
57     GikoSystem;
58
59
60 //! \83R\83\93\83X\83g\83\89\83N\83^
61 constructor TMoveHistory.Create( max : Integer );
62 begin
63     inherited Create;
64
65     FIndex := 0;
66     
67     SetHistoryMax( GikoSys.Setting.MoveHistorySize );
68 end;
69 //! \88Ú\93®\97\9a\97ð\82Ì\83A\83C\83e\83\80\92Ç\89Á
70 function TMoveHistory.pushItem( item: TMoveHistoryItem): Integer;
71 var
72     i : Integer;
73     top: TMoveHistoryItem;
74 begin
75     Result := -1;
76     if (Self.Count > 0) then begin
77         top := TMoveHistoryItem( Self.Items[Self.Count - 1] );
78         if (top.FThreadItem = item.FThreadItem) and
79             (top.FScrollTop = item.FScrollTop) then begin
80             Exit;
81         end;
82     end;
83     // \95Û\8e\9d\90\94\82Ì\8dÅ\91å\92l\82ð\92´\82¦\82é\8fê\8d\87\90æ\93ª\82ð\8dí\8f\9c
84     if (FIndex + 1 > FHistoryMax) then begin
85         if ( Self.Items[0] <> nil ) then begin
86             TMoveHistoryItem( Self.Items[0] ).Free;
87         end;
88         Self.Delete(0);
89         Dec(Findex);
90     end;
91     // FIndex\82æ\82è\8cã\82ë\82Ì\83A\83C\83e\83\80\82ð\8dí\8f\9c\82·\82é
92     for i := Self.Count - 1 downto Findex do begin
93         if (Self.Items [i] <> nil) then begin
94             TMoveHistoryItem( Self.Items[i] ).Free;
95         end;
96         Self.Delete(i);
97     end;
98     Inc(FIndex);
99     Result := Self.Add( item );
100 end;
101 //! \88Ú\93®\97\9a\97ð\82Ì\83A\83C\83e\83\80\92Ç\89Á
102 function TMoveHistory.pushItem( item: TBrowserRecord): Integer;
103 var
104     history : TMoveHistoryItem;
105     doc : OleVariant;
106 begin
107     Result := -1;
108     if ( item <> nil ) and ( item.Thread <> nil )
109         and ( item.Browser <> nil) then begin
110         history := TMoveHistoryItem.Create;
111         history.FThreadItem := item.Thread;
112         doc := Idispatch( olevariant(item.Browser.ControlInterface).Document) as IHTMLDocument2;
113         history.ScrollTop := doc.Body.ScrollTop;
114
115         Result := pushItem( history );
116     end;
117 end;
118 //! \88ê\82Â\91O\82Ì\97\9a\97ð\83A\83C\83e\83\80\8eæ\93¾
119 function TMoveHistory.getPrevItem(item: TBrowserRecord): TMoveHistoryItem;
120 begin
121     Result := nil;
122     if (FIndex = Self.Count) and (item <> nil) then begin
123         pushItem( item );
124         Dec(FIndex);
125     end;
126     if ( FIndex > 0 ) then begin
127         Dec( FIndex );
128         Result := TMoveHistoryItem( Self.items[ FIndex  ] );
129     end;
130 end;
131 //! \88ê\82Â\8cã\82ë\82Ì\97\9a\97ð\83A\83C\83e\83\80\8eæ\93¾
132 function TMoveHistory.getNextItem: TMoveHistoryItem;
133 begin
134     Result := nil;
135     if ( FIndex < Self.Count - 1 ) then begin
136         Inc( FIndex );
137         Result := TMoveHistoryItem( Self.items[ FIndex ] );
138     end;
139 end;
140 //! \97\9a\97ð\82Ì\91S\8fÁ\8b\8e
141 procedure TMoveHistory.clear;
142 var
143     i : Integer;
144 begin
145     // \83A\83C\83e\83\80\82ð\8dí\8f\9c\82·\82é
146     for i := Self.Count - 1 downto 0 do begin
147         if (Self.Items [i] <> nil) then begin
148             TMoveHistoryItem( Self.Items[i] ).Free;
149         end;
150         Self.Delete(i);
151     end;
152     Self.Capacity := 0;
153     FIndex := 0;
154     inherited;
155 end;
156
157 procedure TMoveHistory.SetHistoryMax(AVal: Integer);
158 begin
159     // \97\9a\97ð\82Ì\83T\83C\83Y\82Í0\82æ\82è\91å\82«\82­\82È\82¢\82Æ\82¢\82¯\82È\82¢
160     if ( AVal > 0 ) then begin
161         if ((AVal + 1) <> FHistoryMax) then begin
162             Self.clear;
163             // \88Ú\93®\82µ\82½\8dÛ\82É\81A\96ß\82é\83\8a\83\93\83N\82ð1\82Â\91«\82·\82Ì\82Å
164             FHistoryMax := AVal + 1;
165         end;
166     end;
167 end;
168 function TMoveHistory.GetHistoryMax: Integer;
169 begin
170     // \88Ú\93®\82µ\82½\8dÛ\82É\81A\96ß\82é\83\8a\83\93\83N\82ð1\82Â\91«\82·\82Ì\82Å
171     Result := FHistoryMax - 1;
172 end;
173 initialization
174         MoveHisotryManager := TMoveHistory.Create( 20 );
175
176 finalization
177         if MoveHisotryManager <> nil then begin
178                 MoveHisotryManager.clear;
179         MoveHisotryManager.Free;
180                 MoveHisotryManager := nil;
181         end;
182 end.