| 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 ???潟??Щ??絮ユ???紊т????違??荐???????? |
| 32 |
\param AVal 篆?????/span> |
| 33 |
} |
| 34 |
procedure SetHistoryMax(AVal: Integer); |
| 35 |
{ |
| 36 |
\brief ???潟??Щ??絮ユ???紊т????違????緇??????? |
| 37 |
\return 篆????? > 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 |
//! ?潟?潟?鴻????????/span> |
| 60 |
constructor TMoveHistory.Create( max : Integer ); |
| 61 |
begin |
| 62 |
inherited Create; |
| 63 |
|
| 64 |
FIndex := 0; |
| 65 |
// ?????????????遺賢??ikoSys??nil?????????c????? |
| 66 |
if (GikoSys = nil) then begin |
| 67 |
SetHistoryMax( max ); |
| 68 |
end else begin |
| 69 |
SetHistoryMax( GikoSys.Setting.MoveHistorySize ); |
| 70 |
end; |
| 71 |
end; |
| 72 |
//! 腱糸??絮ユ????≪?ゃ????菴遵?? |
| 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 |
// 篆????違????紊у?ゃ??莇??????翫????????????/span> |
| 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????緇??????≪?ゃ?????????ゃ???? |
| 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 |
//! 腱糸??絮ユ????≪?ゃ????菴遵?? |
| 105 |
function TMoveHistory.pushItem( item: TBrowserRecord): Integer; |
| 106 |
var |
| 107 |
history : TMoveHistoryItem; |
| 108 |
doc : IHTMLDocument2; |
| 109 |
begin |
| 110 |
Result := -1; |
| 111 |
if not Assigned(item) then |
| 112 |
Exit; |
| 113 |
if not Assigned(item.Thread) then |
| 114 |
Exit; |
| 115 |
if not Assigned(item.Browser) then |
| 116 |
Exit; |
| 117 |
|
| 118 |
doc := item.Browser.ControlInterface.Document as IHTMLDocument2; |
| 119 |
if not Assigned(doc) then |
| 120 |
Exit; |
| 121 |
|
| 122 |
history := TMoveHistoryItem.Create; |
| 123 |
history.FThreadItem := item.Thread; |
| 124 |
|
| 125 |
history.ScrollTop := (doc.body as IHTMLElement2).ScrollTop; |
| 126 |
|
| 127 |
Result := pushItem( history ); |
| 128 |
end; |
| 129 |
//! 筝??ゅ????吋罩眼?≪?ゃ??????緇? |
| 130 |
function TMoveHistory.getPrevItem(item: TBrowserRecord): TMoveHistoryItem; |
| 131 |
begin |
| 132 |
Result := nil; |
| 133 |
if (FIndex = Self.Count) and (item <> nil) then begin |
| 134 |
pushItem( item ); |
| 135 |
Dec(FIndex); |
| 136 |
end; |
| 137 |
if ( FIndex > 0 ) then begin |
| 138 |
Dec( FIndex ); |
| 139 |
Result := TMoveHistoryItem( Self.items[ FIndex ] ); |
| 140 |
end; |
| 141 |
end; |
| 142 |
//! 筝??ゅ?????吋罩眼?≪?ゃ??????緇? |
| 143 |
function TMoveHistory.getNextItem: TMoveHistoryItem; |
| 144 |
begin |
| 145 |
Result := nil; |
| 146 |
if ( FIndex < Self.Count - 1 ) then begin |
| 147 |
Inc( FIndex ); |
| 148 |
Result := TMoveHistoryItem( Self.items[ FIndex ] ); |
| 149 |
end; |
| 150 |
end; |
| 151 |
//! 絮ユ????????/span> |
| 152 |
procedure TMoveHistory.clear; |
| 153 |
var |
| 154 |
i : Integer; |
| 155 |
begin |
| 156 |
// ?≪?ゃ?????????ゃ???? |
| 157 |
for i := Self.Count - 1 downto 0 do begin |
| 158 |
if (Self.Items [i] <> nil) then begin |
| 159 |
TMoveHistoryItem( Self.Items[i] ).Free; |
| 160 |
end; |
| 161 |
Self.Delete(i); |
| 162 |
end; |
| 163 |
Self.Capacity := 0; |
| 164 |
FIndex := 0; |
| 165 |
inherited; |
| 166 |
end; |
| 167 |
|
| 168 |
procedure TMoveHistory.SetHistoryMax(AVal: Integer); |
| 169 |
begin |
| 170 |
// 絮ユ????泣?ゃ?冴??????紊с????????????????? |
| 171 |
if ( AVal > 0 ) then begin |
| 172 |
if ((AVal + 1) <> FHistoryMax) then begin |
| 173 |
Self.clear; |
| 174 |
// 腱糸?????????????祉?????潟????1?よ恭??????/span> |
| 175 |
FHistoryMax := AVal + 1; |
| 176 |
end; |
| 177 |
end; |
| 178 |
end; |
| 179 |
function TMoveHistory.GetHistoryMax: Integer; |
| 180 |
begin |
| 181 |
// 腱糸?????????????祉?????潟????1?よ恭??????/span> |
| 182 |
Result := FHistoryMax - 1; |
| 183 |
end; |
| 184 |
initialization |
| 185 |
MoveHisotryManager := TMoveHistory.Create( 20 ); |
| 186 |
|
| 187 |
finalization |
| 188 |
if MoveHisotryManager <> nil then begin |
| 189 |
MoveHisotryManager.clear; |
| 190 |
FreeAndNil(MoveHisotryManager); |
| 191 |
end; |
| 192 |
end. |