OSDN Git Service

1.57.2.749
[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 //! \83R\83\93\83X\83g\83\89\83N\83^
60 constructor TMoveHistory.Create( max : Integer );
61 begin
62     inherited Create;
63
64     FIndex := 0;
65     // \82È\82º\82ª\83f\83o\83b\83O\92\86\82ÉGikoSys\82ªnil\82Ì\8e\9e\82ª\82 \82Á\82½???
66     if (GikoSys = nil) then begin
67         SetHistoryMax( max );
68     end else begin
69         SetHistoryMax( GikoSys.Setting.MoveHistorySize );
70     end;
71 end;
72 //! \88Ú\93®\97\9a\97ð\82Ì\83A\83C\83e\83\80\92Ç\89Á
73 function TMoveHistory.pushItem( item: TMoveHistoryItem): Integer;
74 var
75     i : Integer;
76     top: TMoveHistoryItem;
77 begin
78     Result := -1;
79     if (Self.Count > 0) then begin
80         top := TMoveHistoryItem( Self.Items[Self.Count - 1] );
81         if (top.FThreadItem = item.FThreadItem) and
82             (top.FScrollTop = item.FScrollTop) then begin
83             Exit;
84         end;
85     end;
86     // \95Û\8e\9d\90\94\82Ì\8dÅ\91å\92l\82ð\92´\82¦\82é\8fê\8d\87\90æ\93ª\82ð\8dí\8f\9c
87     if (FIndex + 1 > FHistoryMax) then begin
88         if ( Self.Items[0] <> nil ) then begin
89             TMoveHistoryItem( Self.Items[0] ).Free;
90         end;
91         Self.Delete(0);
92         Dec(Findex);
93     end;
94     // FIndex\82æ\82è\8cã\82ë\82Ì\83A\83C\83e\83\80\82ð\8dí\8f\9c\82·\82é
95     for i := Self.Count - 1 downto Findex do begin
96         if (Self.Items [i] <> nil) then begin
97             TMoveHistoryItem( Self.Items[i] ).Free;
98         end;
99         Self.Delete(i);
100     end;
101     Inc(FIndex);
102     Result := Self.Add( item );
103 end;
104 //! \88Ú\93®\97\9a\97ð\82Ì\83A\83C\83e\83\80\92Ç\89Á
105 function TMoveHistory.pushItem( item: TBrowserRecord): Integer;
106 var
107     history : TMoveHistoryItem;
108     doc : OleVariant;
109 begin
110     Result := -1;
111     if ( item <> nil ) and ( item.Thread <> nil )
112         and ( item.Browser <> nil) then begin
113         history := TMoveHistoryItem.Create;
114         history.FThreadItem := item.Thread;
115         doc := Idispatch( olevariant(item.Browser.ControlInterface).Document) as IHTMLDocument2;
116         history.ScrollTop := doc.Body.ScrollTop;
117
118         Result := pushItem( history );
119     end;
120 end;
121 //! \88ê\82Â\91O\82Ì\97\9a\97ð\83A\83C\83e\83\80\8eæ\93¾
122 function TMoveHistory.getPrevItem(item: TBrowserRecord): TMoveHistoryItem;
123 begin
124     Result := nil;
125     if (FIndex = Self.Count) and (item <> nil) then begin
126         pushItem( item );
127         Dec(FIndex);
128     end;
129     if ( FIndex > 0 ) then begin
130         Dec( FIndex );
131         Result := TMoveHistoryItem( Self.items[ FIndex  ] );
132     end;
133 end;
134 //! \88ê\82Â\8cã\82ë\82Ì\97\9a\97ð\83A\83C\83e\83\80\8eæ\93¾
135 function TMoveHistory.getNextItem: TMoveHistoryItem;
136 begin
137     Result := nil;
138     if ( FIndex < Self.Count - 1 ) then begin
139         Inc( FIndex );
140         Result := TMoveHistoryItem( Self.items[ FIndex ] );
141     end;
142 end;
143 //! \97\9a\97ð\82Ì\91S\8fÁ\8b\8e
144 procedure TMoveHistory.clear;
145 var
146     i : Integer;
147 begin
148     // \83A\83C\83e\83\80\82ð\8dí\8f\9c\82·\82é
149     for i := Self.Count - 1 downto 0 do begin
150         if (Self.Items [i] <> nil) then begin
151             TMoveHistoryItem( Self.Items[i] ).Free;
152         end;
153         Self.Delete(i);
154     end;
155     Self.Capacity := 0;
156     FIndex := 0;
157     inherited;
158 end;
159
160 procedure TMoveHistory.SetHistoryMax(AVal: Integer);
161 begin
162     // \97\9a\97ð\82Ì\83T\83C\83Y\82Í0\82æ\82è\91å\82«\82­\82È\82¢\82Æ\82¢\82¯\82È\82¢
163     if ( AVal > 0 ) then begin
164         if ((AVal + 1) <> FHistoryMax) then begin
165             Self.clear;
166             // \88Ú\93®\82µ\82½\8dÛ\82É\81A\96ß\82é\83\8a\83\93\83N\82ð1\82Â\91«\82·\82Ì\82Å
167             FHistoryMax := AVal + 1;
168         end;
169     end;
170 end;
171 function TMoveHistory.GetHistoryMax: Integer;
172 begin
173     // \88Ú\93®\82µ\82½\8dÛ\82É\81A\96ß\82é\83\8a\83\93\83N\82ð1\82Â\91«\82·\82Ì\82Å
174     Result := FHistoryMax - 1;
175 end;
176 initialization
177         MoveHisotryManager := TMoveHistory.Create( 20 );
178
179 finalization
180         if MoveHisotryManager <> nil then begin
181                 MoveHisotryManager.clear;
182         FreeAndNil(MoveHisotryManager);
183         end;
184 end.