OSDN Git Service

スレ一覧の絞込みでCTRL+DELで個別に削除できるように修正
[gikonavigoeson/gikonavi.git] / Giko.pas
index d65168e..dcb1a01 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -19,7 +19,7 @@ uses
        {HintWindow,} GikoCoolBar, GikoListView, Search, ExternalBoardManager,
        ExternalBoardPlugInMain, StdActns, Variants, ExtActns,IdTCPConnection,
        IdBaseComponent, IdTCPClient, AppEvnts, BrowserRecord, MoveHistoryItem,
-    ShellAPI,Preview, HistoryList, ResPopupBrowser;
+    ShellAPI,Preview, HistoryList, ResPopupBrowser, ExtPreviewDatamodule;
 
 const
        NGWORDNAME_PANEL = 3;
@@ -417,6 +417,8 @@ type
     IDNG1: TMenuItem;
     IDNG2: TMenuItem;
     ResPopupClearTimer: TTimer;
+    TaskTrayPopupMenu: TPopupMenu;
+    Exit1: TMenuItem;
                                procedure FormCreate(Sender: TObject);
                procedure FormDestroy(Sender: TObject);
                procedure BrowserStatusTextChange(Sender: TObject;
@@ -815,6 +817,8 @@ type
         procedure TaskTrayIconMessage(var Msg : TMsg); message WM_USER + 2010;
         //! \83^\83X\83N\83g\83\8c\83C\82É\83A\83C\83R\83\93\93o\98^\81\95\83t\83H\81[\83\80\89B\82µ
         procedure StoredTaskTray;
+        //! \93¯ID\83\8c\83X\83A\83\93\83J\81[\95\\8e¦
+        procedure ShowSameIDAncher(const AID: String);
        published
                property EnabledCloseButton: Boolean read FEnabledCloseButton write SetEnabledCloseButton;
        end;
@@ -903,7 +907,7 @@ begin
 {$ENDIF}
 //try
        Sort.SetSortDate(Now());
-       
+
        FTreeType := gttNone;
        // \8bN\93®\8e\9e\82É\95Û\91\82³\82ê\82Ä\82µ\82Ü\82¤\91Î\8dô
        FStartUp := true;
@@ -1545,7 +1549,13 @@ var
        i                               : Integer;
        wp                      : TWindowPlacement;
        tmpBool : Boolean;
+    WindowPlacement: TWindowPlacement;
 begin
+    // \83^\83X\83N\83g\83\8c\83C\82Ì\83A\83C\83R\83\93\8dí\8f\9c
+    if (FIconData.uID <> 0) then begin
+        Shell_NotifyIcon(NIM_DELETE, @FIconData);
+    end;
+
        // \83}\83E\83X\83W\83F\83X\83`\83\83\81[\8aJ\95ú
        try
         if GikoSys.Setting.GestureEnabled then begin
@@ -1563,6 +1573,9 @@ begin
        except
        end;
        try
+        WindowPlacement.length := SizeOf(TWindowPlacement);
+        GetWindowPlacement(Self.Handle, @WindowPlacement);
+
                //\8dÅ\91å\89»\81E\83E\83B\83\93\83h\83E\88Ê\92u\95Û\91
                wp.length := sizeof(wp);
                GetWindowPlacement(Handle, @wp);
@@ -1570,8 +1583,8 @@ begin
                GikoSys.Setting.WindowLeft := wp.rcNormalPosition.Left;
                GikoSys.Setting.WindowHeight := wp.rcNormalPosition.Bottom - wp.rcNormalPosition.Top;
                GikoSys.Setting.WindowWidth := wp.rcNormalPosition.Right - wp.rcNormalPosition.Left;
-               GikoSys.Setting.WindowMax := WindowState = wsMaximized;
-
+               GikoSys.Setting.WindowMax := (WindowState = wsMaximized) or
+                                        (WindowPlacement.flags = WPF_RESTORETOMAXIMIZED);
                GikoSys.Setting.ListStyle := ListView.ViewStyle;
                GikoSys.Setting.CabinetVisible := GikoDM.CabinetVisibleAction.Checked;
                GikoSys.Setting.CabinetWidth := CabinetPanel.Width;
@@ -1630,6 +1643,11 @@ begin
        end;
        try
                for i := FBrowsers.Count - 1 downto 0 do begin
+            GikoSys.ShowRefCount('browser' + IntToStr(i), TWebBrowser(FBrowsers[i]).ControlInterface);
+            GikoSys.ShowRefCount('document' + IntToStr(i), TWebBrowser(FBrowsers[i]).ControlInterface.Document);
+               end;
+
+               for i := FBrowsers.Count - 1 downto 0 do begin
                        TWebBrowser(FBrowsers[i]).Free;
                end;
                FBrowsers.Clear;
@@ -1909,31 +1927,41 @@ var
        e: IHTMLElement;
        Ext: string;
        PathRec: TPathRec;
-  Text2: string;
+    Text2: string;
     cResPopup: TResPopupBrowser;
+    senderBrowser :TWebBrowser;
+    doc: IHTMLDocument2;
 begin
-       // \83M\83R\83i\83r\82Í\83\8c\83X\83A\83\93\83J\81[\82ª about:blank.. \82Å\8en\82Ü\82é\82±\82Æ\82ð\8aú\91Ò\82µ\82Ä\82¢\82é\82ª
-  // IE 7 \82Å\82Í about:blank.. \82Å\82Í\82È\82­ about:.. \82É\82È\82é\82Ì\82Å\81A\92u\8a·\82·\82é(\93\8a\82°\82â\82è)
-       if Pos('about:..', Text) = 1 then
-       Text2 := 'about:blank..' + Copy( Text, Length('about:..')+1, Length(Text) )
-  else
-       Text2 := Text;
+    // \83M\83R\83i\83r\82Í\83\8c\83X\83A\83\93\83J\81[\82ª about:blank.. \82Å\8en\82Ü\82é\82±\82Æ\82ð\8aú\91Ò\82µ\82Ä\82¢\82é\82ª
+    // IE 7 \82Å\82Í about:blank.. \82Å\82Í\82È\82­ about:.. \82É\82È\82é\82Ì\82Å\81A\92u\8a·\82·\82é(\93\8a\82°\82â\82è)
+    if Pos('about:..', Text) = 1 then
+        Text2 := 'about:blank..' + Copy( Text, Length('about:..')+1, Length(Text) )
+    else
+        Text2 := Text;
+
        if not( TObject(Sender) is TWebBrowser )then
                Exit;
+
+    senderBrowser := TWebBrowser(Sender);
+    doc := senderBrowser.ControlInterface.Document as IHTMLDocument2;
+
        try
                try
-                       if (TWebBrowser(Sender) <> nil) and (not TWebBrowser(Sender).Busy) and (Assigned(TWebBrowser(Sender).Document)) then begin
-                               if LowerCase(OleVariant(IHTMLDocument2(TWebBrowser(Sender).Document)).charset) <> 'shift_jis' then begin
-                                       OleVariant(IHTMLDocument2(TWebBrowser(Sender).Document)).charset := 'shift_jis';
+                       if ((not senderBrowser.Busy) and Assigned(doc)) then begin
+                               if LowerCase(doc.charset) <> 'shift_jis' then begin
+                                       doc.charset := 'shift_jis';
                                end;
                        end;
                except
                end;
        finally
        end;
+
        if PreviewTimer.Enabled then
                PreviewTimer.Enabled := False;
+
        Application.CancelHint;
+
        try
                if GetActiveContent <> nil then
                        ActiveFileName := ChangeFileExt(ExtractFileName(GetActiveContent.FileName), '')
@@ -1943,6 +1971,7 @@ begin
                FActiveContent := nil;
                Exit;
        end;
+
     // \91O\89ñ\82Æ\93¯\82\8fê\8d\87\8fI\97¹
     if (StatusBar.Panels[1].Text = Text2) then begin
         if Text2 = '' then begin
@@ -1992,7 +2021,10 @@ begin
 
 //file:///C:/Borland/Projects/gikoNavi/test/read.cgi/qa/990576336/10
 //file:///C:/Borland/Projects/gikoNavi/test/read.cgi/qa/990576336/10-15
-
+    // \91¼\82Ì\83A\83v\83\8a\82Å\8f\88\97\9d\82·\82éURL\82©\8am\94F
+    if (ExtPreviewDM.PreviewURL(Text2)) then begin
+        Exit;
+    end;
        s := '';
        Ext := AnsiLowerCase(ExtractFileExt(Text2));
        if (Pos('http://', Text2) = 1) and (GikoSys.Setting.PreviewVisible) and
@@ -2011,9 +2043,9 @@ begin
                        s := StringReplace(Text2, 'mailto:', '', [rfIgnoreCase]);
                        //\83M\83R\83i\83r\83X\83\8c \83p\81[\83g3\82Ì466\8e\81\82É\8a´\8eÓ
                        GetCursorPos(p);
-                       p.x := p.x - TWebBrowser(Sender).ClientOrigin.x;
-                       p.y := p.y - TWebBrowser(Sender).ClientOrigin.y;
-                       e := IHTMLDocument2(TWebBrowser(Sender).Document).elementFromPoint(p.x, p.y);
+                       p.x := p.x - senderBrowser.ClientOrigin.x;
+                       p.y := p.y - senderBrowser.ClientOrigin.y;
+                       e := doc.elementFromPoint(p.x, p.y);
                        if (Assigned(e)) then begin
                 CreateResPopupBrowser;
 
@@ -2026,7 +2058,7 @@ begin
                 end;
 
                 cResPopup := FResPopupBrowser.CreateNewBrowser;
-                               tmp2 := ZenToHan(e.Get_outerText);
+                               tmp2 := Trim(ZenToHan(e.Get_outerText));
                                if (GikoSys.IsNumeric(tmp2)) then begin
                                        //\82\93\82Í\83\8c\83X\94Ô\8d\86\82Á\82Û\82¢\82Á\82·\81B
                                        wkIntSt := StrToInt64(tmp2);
@@ -2297,6 +2329,12 @@ begin
                KokoPopupMenu.Popup(p.x, p.y);
        end else if Pos('mailto', LowerCase(URL)) <> 0 then begin
                Cancel := not GikoSys.Setting.OpenMailer;
+
+        //@\82Æ.\82ð\8aÜ\82Ü\82È\82¢URL\82Í\83\81\81[\83\8b\83A\83h\83\8c\83X\82Æ\82Ý\82È\82³\82È\82¢
+        //\8eå\82Éage\81Asage\91Î\8dô
+        if (Pos('@', URL) = 0) or (Pos('.', URL) = 0) then begin
+            Cancel := True;
+        end;
        end;
 
 end;
@@ -2533,9 +2571,11 @@ begin
 
                                //\8f\84\89ñ\82 \82è\82Ì\8fê\8d\87\81\95\82P\82O\82O\82O\92´\82Í\8f\84\89ñ\8dí\8f\9c
                                if (Item.ThreadItem.Round) and (Item.ThreadItem.Count > 1000) then begin
-                                       Item.ThreadItem.Round := False;
-                                       //Item.ThreadItem.RoundName := '';
-                                       AddMessageList('\81\9a1000\94­\8c¾\82ð\92´\82¦\82½\82Ì\82Å\8f\84\89ñ\82ð\8dí\8f\9c\82µ\82Ü\82µ\82½ - [' + Item.ThreadItem.Title + ']', nil, gmiOK);
+                    // 2ch\88È\8aO\82Í\81A1000\82ª\8dÅ\8d\82\82©\95s\96¾\82È\82Ì\82Å\81A2ch\8cÀ\92è\82É\82·\82é
+                    if (Item.ThreadItem.ParentBoard.Is2ch) then begin
+                                       Item.ThreadItem.Round := False;
+                                       AddMessageList('\81\9a1000\94­\8c¾\82ð\92´\82¦\82½\82Ì\82Å\8f\84\89ñ\82ð\8dí\8f\9c\82µ\82Ü\82µ\82½ - [' + Item.ThreadItem.Title + ']', nil, gmiOK);
+                    end;
                                end;
                                TreeView.Refresh;
                                //ListView\82Å\82±\82Ì\83X\83\8c\82ª\8aÜ\82Ü\82ê\82é\94Â\82ð\95\\8e¦\82µ\82Ä\82¢\82é\82Æ\82«\82Ì\8dX\90V\8f\88\97\9d
@@ -2801,7 +2841,7 @@ var
        BBSID: string;
        FileName: string;
        sTitle: string;
-       doc: Variant;
+       doc: OleVariant;
        s: string;
        idx: Integer;
        ThreadItem: TThreadItem;
@@ -2815,14 +2855,14 @@ begin
         (FActiveContent <> nil) and
                (FActiveContent.Thread <> Thread.Thread) and
                (FActiveContent.Browser <> nil) and
-               (Assigned(FActiveContent.Browser.Document)) then begin
-               try
-               try
-                       FActiveContent.Thread.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document).Body).ScrollTop;
-               except
-                       on E: Exception do
-                               MsgBox(Handle, E.Message, 'SetContent[<-ScrollTop]', 0);
-               end;
+               (Assigned(FActiveContent.Browser.ControlInterface.Document)) then begin
+        try
+            try
+                FActiveContent.Thread.ScrollTop := FActiveContent.Browser.OleObject.Document.Body.ScrollTop;
+            except
+            on E: Exception do
+                MsgBox(Handle, E.Message, 'SetContent[<-ScrollTop]', 0);
+        end;
                finally
                end;
        end;
@@ -2874,7 +2914,7 @@ begin
                                ShowWindow(FActiveContent.Browser.Handle, SW_HIDE);
                end;
                ShowWindow(Thread.Browser.Handle, SW_SHOW);
-               if (not Assigned(Thread.Browser.Document)) then begin
+               if (not Assigned(Thread.Browser.ControlInterface.Document)) then begin
                        Thread.Browser.Navigate('about:blank');
                end;
                while (Thread.Browser.ReadyState <> READYSTATE_COMPLETE) and
@@ -2912,7 +2952,7 @@ begin
                        try
                                Thread.Browser.BringToFront;
                                s := '<HTML><BODY><CENTER>\82±\82Ì\83X\83\8c\83b\83h\82Í\8eæ\93¾\82µ\82Ä\82¢\82Ü\82¹\82ñ</CENTER></BODY></HTML>';
-                               doc := Idispatch( olevariant(Thread.Browser.ControlInterface).Document) as IHTMLDocument2;
+                               doc := Thread.Browser.OleObject.Document;
                                doc.open;
                                doc.charset := 'Shift_JIS';
                                doc.Write(s);
@@ -3643,29 +3683,32 @@ begin
 end;
 procedure TGikoForm.DeleteTab(index, selectIndex: Integer);
 var
-    doc: Variant;
+    browserRec : TBrowserRecord;
+    doc: OleVariant;
     j: Integer;
 begin
+    browserRec := TBrowserRecord(BrowserTab.Tabs.Objects[index]);
     try
-        if TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser <> nil then begin
-            doc := TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser.Document;
-            TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.ScrollTop := doc.Body.ScrollTop;
+        if browserRec.Browser <> nil then begin
+            doc := browserRec.Browser.OleObject.Document;
+            browserRec.Thread.ScrollTop := doc.Body.ScrollTop;
         end;
     except
-        TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.ScrollTop := 0;
+        browserRec.Thread.ScrollTop := 0;
     end;
-    if(FActiveContent = TBrowserRecord(BrowserTab.Tabs.Objects[index])) then
+
+    if(FActiveContent = browserRec) then
         FActiveContent := nil;
-    if TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser <> nil then begin
-        j := FBrowsers.IndexOf(TBrowserRecord(BrowserTab.Tabs.Objects[index]).Browser);
+    if browserRec.Browser <> nil then begin
+        j := FBrowsers.IndexOf(browserRec.Browser);
         if j <> -1 then
             FBrowsers.Move(j, BROWSER_COUNT - 1);
     end;
+
     BrowserTab.Tabs.BeginUpdate;
     try
-        GikoSys.Setting.LastCloseTabURL :=
-            TBrowserRecord(BrowserTab.Tabs.Objects[index]).Thread.URL;
-        TBrowserRecord(BrowserTab.Tabs.Objects[index]).Free;
+        GikoSys.Setting.LastCloseTabURL := browserRec.Thread.URL;
+        browserRec.Free;
         if ( BrowserTab.Tabs.Count - 1 = index ) and
             ( BrowserTab.TabRect(index).Left
                 <= BrowserTab.DisplayRect.Left ) then begin
@@ -3686,6 +3729,7 @@ begin
     if BrowserTab.Tabs.Count = 0 then begin
         BrowserNullTab.Thread := nil;
     end;
+
     if(BrowserTab.TabIndex <> -1) and
         ( TBrowserRecord(BrowserTab.Tabs.Objects[BrowserTab.TabIndex]).Browser = nil) then begin
         // \88ê\94Ô\8cÃ\82¢\83u\83\89\83E\83U\82ð\8aJ\95ú\82·\82é
@@ -3838,90 +3882,103 @@ var
     BNum, BRes: string;
     threadItem: TThreadItem;
     aElement : IHTMLElement;
+    senderBrowser : TWebBrowser;
+    doc : IHTMLDocument2;
 begin
 {$IFDEF DEBUG}
        Writeln(IntToStr(Integer(ppDisp)));
 {$ENDIF}
        Cancel := True;
-    aElement := IHTMLDocument2(TWebBrowser(Sender).Document).activeElement;
-       if ( aElement <> nil) then begin
-               Text := aElement.Get_outerText;
-               Html := aElement.Get_outerHTML;
-               if(AnsiPos('>>', Text) = 1) or (AnsiPos('>', Text) = 1)
-                       or (AnsiPos('\81\84\81\84', Text) = 1) or (AnsiPos('\81\84', Text) = 1) then begin
-                       if GikoSys.Setting.ResAnchorJamp then begin
-
-                               Text := ZenToHan(Trim(Text));
-
-                               if(AnsiPos('>>', Text) = 1) then begin
-                                       //Text := Copy(Text, 3, Length(Text) - 2);
-                                       Delete(Text, 1, 2);
-                               end else begin
-                                       //Text := Copy(Text, 2, Length(Text) - 1);
-                                       Delete(Text, 1, 1);
-                               end;
 
-                               if AnsiPos('-', Text) <> 0 then begin
-                                       wkIntSt := StrToIntDef(Copy(Text, 1, AnsiPos('-', Text) - 1), 0);
-                                       Text := Copy(Text, AnsiPos('-', Text) + 1, Length(Text));
-                                       wkIntTo := StrToIntDef(Text, 0);
-                                       if wkIntTo < wkIntSt then
-                                               wkIntSt := wkIntTo;
-                               end else begin
-                                       wkIntSt := StrToIntDef(Text, 0);
-                               end;
+       if not( TObject(Sender) is TWebBrowser )then
+               Exit;
 
-                               if wkIntSt <> 0 then begin
-                       FActiveContent.IDAnchorPopup('');
-                    MoveHisotryManager.pushItem(FActiveContent);
-                    if (Sender is TResPopupBrowser) then begin
-                        TResPopupBrowser(Sender).ChildClear;
-                        OpenThreadItem(
-                            GetActiveContent(true),
-                            GetActiveContent(true).URL + '&st=' +
-                                 IntToStr(wkIntSt) + '&to=' + IntToStr(wkIntSt));
-                    end else begin
-                                       BrowserMovement(IntToStr(wkIntSt));
-                    end;
-                end;
+    senderBrowser := TWebBrowser(Sender);
+    doc := senderBrowser.ControlInterface.Document as IHTMLDocument2;
+       if not Assigned(doc) then
+               Exit;
+
+       aElement := doc.activeElement;
+       if not Assigned(aElement) then
+               Exit;
+
+       Text := aElement.Get_outerText;
+       Html := aElement.Get_outerHTML;
+
+       if(AnsiPos('>>', Text) = 1) or (AnsiPos('>', Text) = 1)
+               or (AnsiPos('\81\84\81\84', Text) = 1) or (AnsiPos('\81\84', Text) = 1) then begin
+               if GikoSys.Setting.ResAnchorJamp then begin
+
+                       Text := ZenToHan(Trim(Text));
+
+                       if(AnsiPos('>>', Text) = 1) then begin
+                               //Text := Copy(Text, 3, Length(Text) - 2);
+                               Delete(Text, 1, 2);
+                       end else begin
+                               //Text := Copy(Text, 2, Length(Text) - 1);
+                               Delete(Text, 1, 1);
                        end;
-               end else begin
-            ////'http://be.2ch.net/test/p.php?i='+id+'&u=d:'+bas+num
-
-                       URL := GikoSys.GetHRefText(Html);
-                       URL := GikoSys.HTMLDecode(URL);
-            if AnsiPos('BE:', URL) = 1 then begin
-                               BNum := Copy(URL, 4, AnsiPos('/', URL) - 4);
-                               BRes := Copy(URL, AnsiPos('/', URL) + 1,  Length(URL));
-                threadItem := FActiveContent.Thread;
-                if threadItem = nil then Exit;
-                URL := BE_PHP_URL + BNum + '&u=d'
-                       + CustomStringReplace(threadItem.URL, 'l50', '') + BRes;
-            end;
 
-                       if( AnsiPos('http://', URL) = 1) or (AnsiPos('https://', URL) = 1) or
-                               ( AnsiPos('ftp://', URL) = 1) then begin
-                               //\83A\83h\83\8c\83X\83o\81[\82Ì\97\9a\97ð
-                               if GikoSys.Setting.LinkAddAddressBar then begin
-                                       idx := AddressComboBox.Items.IndexOf(URL);
-                                       if idx = -1 then begin
-                                               AddressComboBox.Items.Insert(0, URL);
-                                               if AddressComboBox.Items.Count > GikoSys.Setting.AddressHistoryCount then
-                                                       AddressComboBox.Items.Delete(AddressComboBox.Items.Count - 1);
-                                       end else begin
-                                               AddressComboBox.Items.Delete(idx);
-                                               AddressComboBox.Items.Insert(0, URL);
-                                       end;
-                               end;
+                       if AnsiPos('-', Text) <> 0 then begin
+                               wkIntSt := StrToIntDef(Copy(Text, 1, AnsiPos('-', Text) - 1), 0);
+                               Text := Copy(Text, AnsiPos('-', Text) + 1, Length(Text));
+                               wkIntTo := StrToIntDef(Text, 0);
+                               if wkIntTo < wkIntSt then
+                                       wkIntSt := wkIntTo;
+                       end else begin
+                               wkIntSt := StrToIntDef(Text, 0);
+                       end;
+
+                       if wkIntSt <> 0 then begin
+               FActiveContent.IDAnchorPopup('');
+                MoveHisotryManager.pushItem(FActiveContent);
                 if (Sender is TResPopupBrowser) then begin
-                    TResPopupBrowser(Sender).ChildClear
+                    TResPopupBrowser(Sender).ChildClear;
+                    OpenThreadItem(
+                        GetActiveContent(true),
+                        GetActiveContent(true).URL + '&st=' +
+                             IntToStr(wkIntSt) + '&to=' + IntToStr(wkIntSt));
+                end else begin
+                                       BrowserMovement(IntToStr(wkIntSt));
                 end;
+            end;
+               end;
+       end else begin
+        ////'http://be.2ch.net/test/p.php?i='+id+'&u=d:'+bas+num
+
+               URL := GikoSys.GetHRefText(Html);
+               URL := GikoSys.HTMLDecode(URL);
+        if AnsiPos('BE:', URL) = 1 then begin
+                       BNum := Copy(URL, 4, AnsiPos('/', URL) - 4);
+                       BRes := Copy(URL, AnsiPos('/', URL) + 1,  Length(URL));
+            threadItem := FActiveContent.Thread;
+            if threadItem = nil then Exit;
+            URL := BE_PHP_URL + BNum + '&u=d'
+               + CustomStringReplace(threadItem.URL, 'l50', '') + BRes;
+        end;
 
-                MoveHisotryManager.pushItem(FActiveContent);
-                               MoveToURL( URL );
+               if( AnsiPos('http://', URL) = 1) or (AnsiPos('https://', URL) = 1) or
+                       ( AnsiPos('ftp://', URL) = 1) then begin
+                       //\83A\83h\83\8c\83X\83o\81[\82Ì\97\9a\97ð
+                       if GikoSys.Setting.LinkAddAddressBar then begin
+                               idx := AddressComboBox.Items.IndexOf(URL);
+                               if idx = -1 then begin
+                                       AddressComboBox.Items.Insert(0, URL);
+                                       if AddressComboBox.Items.Count > GikoSys.Setting.AddressHistoryCount then
+                                               AddressComboBox.Items.Delete(AddressComboBox.Items.Count - 1);
+                               end else begin
+                                       AddressComboBox.Items.Delete(idx);
+                                       AddressComboBox.Items.Insert(0, URL);
+                               end;
                        end;
+            if (Sender is TResPopupBrowser) then begin
+                TResPopupBrowser(Sender).ChildClear
+            end;
+
+            MoveHisotryManager.pushItem(FActiveContent);
+                       MoveToURL( URL );
                end;
-    end;
+       end;
 
 end;
 
@@ -4156,10 +4213,9 @@ end;
 procedure TGikoForm.BrowserDocumentComplete(Sender: TObject;
        const pDisp: IDispatch; var URL: OleVariant);
 var
-       FDispHtmlDocument: DispHTMLDocument;
        BrowserRecord :TBrowserRecord;
        i :Integer;
-       doc                                     : Variant;
+       doc     : IHTMLDocument2;
        threadItem      : TThreadItem;
 begin
        if TObject(Sender) is TWebBrowser then begin
@@ -4174,17 +4230,15 @@ begin
                        if BrowserRecord <> nil then begin
                                if BrowserRecord.Event <> nil then
                                        BrowserRecord.Event.Free;
-                               FDispHtmlDocument := Idispatch(OleVariant(BrowserRecord.Browser.ControlInterface).Document) as DispHTMLDocument;
-                               BrowserRecord.Event := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+                               BrowserRecord.Event := THTMLDocumentEventSink.Create(Self, BrowserRecord.Browser.ControlInterface.Document, HTMLDocumentEvents2);
                                BrowserRecord.Event.OnContextMenu := OnDocumentContextMenu;
                                BrowserRecord.Event.OnClick := WebBrowserClick;  //\92Ç\89Á\82µ\82½OnClick\83C\83x\83\93\83g
                        end;
                end else begin
                        if GetActiveContent <> nil then begin
-                               FDispHtmlDocument := Idispatch(OleVariant(Browser.ControlInterface).Document) as DispHTMLDocument;
                                if FEvent <> nil then
                                        FEvent.Free;
-                               FEvent := THTMLDocumentEventSink.Create(Self, FDispHtmlDocument, HTMLDocumentEvents2);
+                               FEvent := THTMLDocumentEventSink.Create(Self, Browser.ControlInterface.Document, HTMLDocumentEvents2);
                                FEvent.OnContextMenu := OnDocumentContextMenu;
                                FEvent.OnClick := WebBrowserClick;  //\92Ç\89Á\82µ\82½OnClick\83C\83x\83\93\83g
                        end else begin
@@ -4222,8 +4276,8 @@ begin
                                RefreshListView(threadItem);
                        end else if threadItem.ScrollTop <> 0 then begin
                                try
-                                       doc := Idispatch( OleVariant( BrowserRecord.Browser.ControlInterface ).Document ) as IHTMLDocument2;
-                                       doc.Body.ScrollTop := threadItem.ScrollTop;
+                                       doc := BrowserRecord.Browser.ControlInterface.Document as IHTMLDocument2;
+                                       (doc.body as IHTMLElement2).ScrollTop := threadItem.ScrollTop;
                                except
                                        on E: Exception do
                                                MsgBox(Handle, E.Message, 'SetContent[ScrollTop<-]', 0);
@@ -4548,7 +4602,7 @@ var
        stRes, edRes : Int64;
        browserRec : TBrowserRecord;
        threadNumber : String;
-       doc : Variant;
+       doc : IHTMLDocument2;
 begin
        stRes := 0;
        edRes := 0;
@@ -4576,8 +4630,9 @@ begin
                        browserRec.Move(IntToStr(stRes));
                        Thread.JumpAddress := 0;
                        try
-                               doc := Idispatch( OleVariant( browserRec.Browser.ControlInterface ).Document ) as IHTMLDocument2;
-                               Thread.ScrollTop := doc.Body.ScrollTop;
+                doc := browserRec.Browser.ControlInterface.Document as IHTMLDocument2;
+                if Assigned(doc) then
+                               Thread.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
                        except
                        end;
                end;
@@ -4778,8 +4833,8 @@ end;
 
 procedure TGikoForm.WndProc(var Message: TMessage);
 var
-       senderBrowser   : TWebBrowser;
-       url                                             : OleVariant;
+       senderBrowser : TWebBrowser;
+       url : OleVariant;
 begin
        try
                case Message.Msg of
@@ -4910,9 +4965,13 @@ begin
        if PreviewTimer.Enabled then
                PreviewTimer.Enabled := False;
 
-       if (FResPopupBrowser <> nil) and (IsWindowVisible(FResPopupBrowser.Handle)) then begin
-        FResPopupBrowser.Clear;
-       end;
+    //Window\8aO\82É\88Ú\93®\82µ\82½\82Æ\82«\82Í\8fÁ\82¦\82é\82æ\82¤\82É\82·\82é\82½\82ß\95\9c\8a\88
+    if (FResPopupBrowser <> nil) and (IsWindowVisible(FResPopupBrowser.Handle)) then begin
+        // \89E\83N\83\8a\83b\83N\82Ì\8e\9e\82Í\8fÁ\82³\82È\82¢\82æ\82¤\82É\8fð\8c\8f\92Ç\89Á
+        if (Message.MouseMsg <> WM_RBUTTONUP) then begin
+            FResPopupBrowser.Clear;
+        end;
+    end;
 
        if (FPreviewBrowser <> nil)
                and (IsWindowVisible(FPreviewBrowser.Handle)) then begin
@@ -4939,7 +4998,7 @@ end;
 
 function TGikoForm.OnDocumentContextMenu(Sender: TObject): WordBool;
 var
-       Doc: IHtmlDocument2;
+       doc: IHtmlDocument2;
        Range: IHTMLTxtRange;
        s: string;
        Num: Integer;
@@ -4947,26 +5006,31 @@ var
 begin
        Result := False;
        FactiveContent.IDAnchorPopup('');
-       Doc := FactiveContent.Browser.Document as IHtmlDocument2;
-       if Assigned(Doc) then begin
-               Range := Doc.selection.createRange as IHTMLTxtRange;
-               s := CustomStringReplace(Range.text, '\81@', ' ');//\91S\8ap\8bó\94\92\82ð\94¼\8ap\8bó\94\92\82É
-               s := ZenToHan(Trim(s));
-               if GikoSys.IsNumeric(s) then begin
-                       Num := StrToInt64Def(s, -1);
-                       ThreadItem := GetActiveContent(true);
-                       if (ThreadItem <> nil) and (Num <= ThreadItem.Count)
-                and (Num > 0)then begin
-                CreateResPopupBrowser;
-                FResPopupBrowser.CreateNewBrowser.PopupType := gptThread;
-                               HTMLCreater.SetResPopupText(FResPopupBrowser.CreateNewBrowser, ThreadItem, Num, Num, False, False);
-                FResPopupBrowser.Popup;
-                               Result := False;
-                       end else
-                               Result := True;
-               end else begin
+
+       doc := FactiveContent.Browser.ControlInterface.Document as IHtmlDocument2;
+       if not Assigned(doc) then
+        Exit;
+
+       Range := doc.selection.createRange as IHTMLTxtRange;
+       if not Assigned(Range) then
+        Exit;
+
+       s := CustomStringReplace(Range.text, '\81@', ' ');//\91S\8ap\8bó\94\92\82ð\94¼\8ap\8bó\94\92\82É
+       s := ZenToHan(Trim(s));
+       if GikoSys.IsNumeric(s) then begin
+               Num := StrToInt64Def(s, -1);
+               ThreadItem := GetActiveContent(true);
+               if (ThreadItem <> nil) and (Num <= ThreadItem.Count)
+           and (Num > 0)then begin
+           CreateResPopupBrowser;
+           FResPopupBrowser.CreateNewBrowser.PopupType := gptThread;
+                       HTMLCreater.SetResPopupText(FResPopupBrowser.CreateNewBrowser, ThreadItem, Num, Num, False, False);
+            FResPopupBrowser.Popup;
+               Result := False;
+               end else
                        Result := True;
-               end;
+    end else begin
+               Result := True;
        end;
 end;
 
@@ -5663,7 +5727,7 @@ procedure TGikoForm.SelectComboBoxKeyDown(Sender: TObject; var Key: Word;
        Shift: TShiftState);
 var
   IMC: HIMC;
-  Len: integer;
+  Len, idx: integer;
   Str: string;
   tmp: string;
 begin
@@ -5689,6 +5753,20 @@ begin
                                SetSelectWord(Str);
                        end;
                end;
+    end else if (Key = Windows.VK_DELETE) and (ssCtrl in Shift) then begin
+        // Ctrl + DEL \82Å\8dí\8f\9c\82·\82é
+        Str := SelectComboBox.Text;
+        idx := GikoSys.Setting.SelectTextList.IndexOf( Str );
+        if idx <> -1 then begin
+            GikoSys.Setting.SelectTextList.Delete( idx );
+        end;
+        idx := SelectComboBox.Items.IndexOf( Str );
+               if idx <> -1 then begin
+            SelectComboBox.Items.Delete( idx );
+        end;
+        SelectComboBox.Text := '';
+        // \8di\8d\9e\82Ý\82ð\89ð\8f\9c\82·\82é\82½\82ß\82É\95Ï\8dX\83C\83x\83\93\83g\82ð\8cÄ\82Ñ\8fo\82·
+        SelectComboBox.OnChange(Sender);
        end else if Length( SelectComboBox.Text ) = 0 then
        begin
                {* SelectComboBox.Text\82ª\8bó\82Å\82à\81A\93ü\97Í\93r\92\86\82ÅEsc\82µ\82½\82Æ\82©
@@ -6473,10 +6551,15 @@ end;
 
 /// \8dÅ\8f¬\89»\82³\82ê\82é
 procedure TGikoForm.OnMinimize;
+var
+    doc: IHTMLDocument2;
 begin
        if FActiveContent <> nil then begin
                FIsMinimize := mtMinimizing;
-               FActiveContent.Thread.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+        doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+        if Assigned(doc) then begin
+               FActiveContent.Thread.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
+        end;
        end;
 end;
 
@@ -6672,9 +6755,8 @@ end;
 
 procedure TGikoForm.OnResized;
 var
-       doc                                             : Variant;
+       doc : IHTMLDocument2;
 begin
-
        FOldFormWidth := Width;
        FIsIgnoreResize := rtNone;
 
@@ -6689,8 +6771,8 @@ begin
                begin
                        // \8dÅ\8f¬\89»\82Í\8aù\82É\8a®\97¹\82µ\82Ä\82¢\82é (\82Â\82Ü\82è\83^\83X\83N\83o\81[\82©\82ç\83E\83B\83\93\83h\83E\82ð\95\9c\8c³\92\86)
                        if FActiveContent <> nil then begin
-                               doc := Idispatch( olevariant(FActiveContent.Browser.ControlInterface).Document) as IHTMLDocument2;
-                               doc.Body.ScrollTop := FActiveContent.Thread.ScrollTop;
+                               doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+                               (doc.body as IHTMLElement2).ScrollTop := FActiveContent.Thread.ScrollTop;
                        end;
                        FIsMinimize := mtNone;
                end;
@@ -6701,74 +6783,94 @@ end;
 //! \83X\83\8c\83b\83h\83u\83\89\83E\83U\83N\83\8a\83b\83N\83C\83x\83\93\83g
 // *************************************************************************
 function TGikoForm.WebBrowserClick(Sender: TObject): WordBool;
-const
-    LIMIT = 20;
 var
-       p : TPoint;
        e: IHTMLElement;
+    doc : IHTMLDocument2;
+    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
+       p : TPoint;
        AID: string;
        stlist : TStringList;
-       i, count: Integer;
-       body : String;
-    limited : Integer;
-    FOleInPlaceActiveObject: IOleInPlaceActiveObject;
+    i : Integer;
 begin
-  result := true;
-  try
-       if (FActiveContent <> nil) and (FActiveContent.Browser <> nil) then
-        FOleInPlaceActiveObject := FActiveContent.Browser.ControlInterface as IOleInPlaceActiveObject;
-        FOleInPlaceActiveObject.OnFrameWindowActivate(True);
-               try
-                       GetCursorPos(p);
-                       p.x := p.x - FActiveContent.Browser.ClientOrigin.x;
-                       p.y := p.y - FActiveContent.Browser.ClientOrigin.y;
-                       e := IHTMLDocument2(FActiveContent.Browser.Document).elementFromPoint(p.x, p.y);
-                       if (Assigned(e)) then begin
-                               if (e.className = 'date') or (e.id = 'date') then begin
-                                       AID := e.innerText;
-                                       if AnsiPos('id', AnsiLowerCase(AID)) > 0 then begin
-                                               AID := Copy(AID, AnsiPos('id', AnsiLowerCase(AID)) - 1, 11);
-                       if AnsiPos(' be:', AnsiLowerCase(AID)) > 0 then begin
-                               AID := Copy(AID, 1, AnsiPos(' BE:', AnsiLowerCase(AID)) - 1)
-                        end;
-                                       end else begin
-                                               stlist := TStringList.Create;
-                                               try
-                                                       stList.DelimitedText := AID;
-                                                       AID := '';
-                                                       for i := 0 to stList.Count - 1 do
-                                                               if Length(WideString(stList[i])) = 8 then begin
-                                                                       if GikoSys.NotDateorTimeString(stList[i]) then begin
-                                                                               AID := stList[i];
-                                                                               break;
-                                                                       end;
-                                                               end;
-                                               finally
-                                                       stList.Free;
+       result := true;
+    if not Assigned(FActiveContent) then
+        Exit;
+    if not Assigned(FActiveContent.Browser) then
+        Exit;
+
+       try
+               FOleInPlaceActiveObject := FActiveContent.Browser.ControlInterface as IOleInPlaceActiveObject;
+               FOleInPlaceActiveObject.OnFrameWindowActivate(True);
+               GetCursorPos(p);
+
+               p.x := p.x - FActiveContent.Browser.ClientOrigin.x;
+               p.y := p.y - FActiveContent.Browser.ClientOrigin.y;
+
+               doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+               if not Assigned(doc) then
+                       Exit;
+
+               e := doc.elementFromPoint(p.x, p.y);
+               if not Assigned(e) then
+                       Exit;
+
+               if (e.className = 'date') or (e.id = 'date') then begin
+                       AID := e.innerText;
+                       if AnsiPos('id', AnsiLowerCase(AID)) > 0 then begin
+                               AID := Copy(AID, AnsiPos('id', AnsiLowerCase(AID)) - 1, 11);
+                               if AnsiPos(' be:', AnsiLowerCase(AID)) > 0 then begin
+                                       AID := Copy(AID, 1, AnsiPos(' BE:', AnsiLowerCase(AID)) - 1)
+                               end;
+                       end else begin
+                               stlist := TStringList.Create;
+                               try
+                                       stList.DelimitedText := AID;
+                                       AID := '';
+                                       for i := 0 to stList.Count - 1 do begin
+                                               if Length(WideString(stList[i])) = 8 then begin
+                                                       if GikoSys.NotDateorTimeString(stList[i]) then begin
+                                                               AID := stList[i];
+                                                               break;
+                                                       end;
                                                end;
                                        end;
-                    count := GikoSys.GetSameIDResCount(AID, FActiveContent.Thread);
-                    limited := LIMIT;
-                    if not (GikoSys.Setting.LimitResCountMessage) then begin
-                        limited := -1;
-                    end else if (count > LIMIT) then begin
-                        if (GikoUtil.MsgBox(Handle,
-                                IntToStr(LIMIT) + '\8cÂ\88È\8fã\82 \82è\82Ü\82·\82ª\81A\82·\82×\82Ä\95\\8e¦\82µ\82Ü\82·\82©\81H',
-                                'ID\83|\83b\83v\83A\83b\83v\8cx\8d\90',
-                                                               MB_YESNO or MB_ICONQUESTION) = ID_YES) then begin
-                            limited := -1;
-                        end
-                    end;
-                                       body := GikoSys.GetSameIDResAnchor(AID, FActiveContent.Thread, limited);
-                                       FActiveContent.IDAnchorPopup(body);
+                               finally
+                                       stList.Free;
                                end;
                        end;
-               except
+            ShowSameIDAncher(AID);
                end;
-  except
-  end;
+       except
+       end;
 end;
+procedure TGikoForm.ShowSameIDAncher(const AID: String);
+const
+    LIMIT = 20;
+var
+       numbers : TStringList;
+    limited : Integer;
+begin
+    numbers := TStringList.Create;
+    try
 
+        GikoSys.GetSameIDRes(AID, FActiveContent.Thread, numbers);
+        limited := LIMIT;
+        if not (GikoSys.Setting.LimitResCountMessage) then begin
+            limited := -1;
+        end else if (numbers.Count > LIMIT) then begin
+            if (GikoUtil.MsgBox(Handle,
+                    IntToStr(LIMIT) + '\8cÂ\88È\8fã\82 \82è\82Ü\82·\82ª\81A\82·\82×\82Ä\95\\8e¦\82µ\82Ü\82·\82©\81H',
+                    'ID\83|\83b\83v\83A\83b\83v\8cx\8d\90',
+                    MB_YESNO or MB_ICONQUESTION) = ID_YES) then begin
+                limited := -1;
+            end
+        end;
+        FActiveContent.IDAnchorPopup(
+            GikoSys.CreateSameIDResAnchor(numbers, FActiveContent.Thread, limited));
+    finally
+        numbers.Free;
+    end;
+end;
 //\83X\83\8c\83b\83h\88ê\97\97\82ð\8dÅ\91å\89»\82µ\82Ä\83t\83H\81[\83J\83X\82ð\93\96\82Ä\82é
 procedure TGikoForm.SelectTimerTimer(Sender: TObject);
 begin
@@ -7155,15 +7257,22 @@ end;
 //\82±\82Ì\83\8c\83X\82 \82Ú\81`\82ñ
 procedure TGikoForm.IndividualAbon(Atag, Atype : Integer);
 var
-       ThreadItem      : TThreadItem;
-       ReadList                : TStringList;
-       wordCount               : TWordCount;
+    doc : IHTMLDocument2;
+       ThreadItem : TThreadItem;
+       ReadList : TStringList;
+       wordCount : TWordCount;
 begin
-       ThreadItem      := GetActiveContent(True);
-       ReadList                := TStringList.Create;
-       wordCount               := TWordCount.Create;
+    if not Assigned(FActiveContent) then
+        Exit;
+    doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+    if not Assigned(doc) then
+        Exit;
+
+       ThreadItem := GetActiveContent(True);
+       ReadList := TStringList.Create;
+       wordCount := TWordCount.Create;
        try
-               ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+               ThreadItem.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
 {$IFDEF SPAM_FILTER_ENABLED}
                // \83X\83p\83\80\82É\90Ý\92è
                ReadList.LoadFromFile( ThreadItem.GetThreadFileName );
@@ -7184,6 +7293,7 @@ end;
 //\93¯\88êID\82ðNG\83\8f\81[\83h\82É\93o\98^
 procedure TGikoForm.AddIDtoNGWord(invisible : boolean);
 var
+    doc : IHTMLDocument2;
        ThreadItem : TThreadItem;
        No : Integer;
 {$IFDEF SPAM_FILTER_ENABLED}
@@ -7233,7 +7343,11 @@ begin
     end;
 {$ENDIF}
     if (FActiveContent.Repaint) then begin
-        ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+        doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+
+        if not Assigned(doc) then
+            Exit;
+        ThreadItem.ScrollTop := (doc.body as IHTMLElement2).ScrollTop;
         if ThreadItem <> nil then
             InsertBrowserTab( ThreadItem, True );
     end;
@@ -7259,7 +7373,7 @@ begin
                ReadList                := TStringList.Create;
                wordCount               := TWordCount.Create;
                try
-                       ThreadItem.ScrollTop := OleVariant(IHTMLDocument2(FActiveContent.Browser.Document)).Body.ScrollTop;
+                       ThreadItem.ScrollTop := FActiveContent.Browser.OleObject.Document.Body.ScrollTop;
 {$IFDEF SPAM_FILTER_ENABLED}
                        // \83X\83p\83\80\82É\90Ý\92è
                        ReadList.LoadFromFile( ThreadItem.GetThreadFileName );
@@ -7289,14 +7403,17 @@ end;
 procedure TGikoForm.KokoPopupMenuPopup(Sender: TObject);
 var
        firstElement: IHTMLElement;
-       document: IHTMLDocument2;
+       doc: IHTMLDocument2;
 begin
-       document := FActiveContent.Browser.Document as IHTMLDocument2;
-       if Assigned(document) then
-               firstElement := document.all.item('idSearch', 0) as IHTMLElement;
-               if Assigned(firstElement) then
-                       if firstElement.style.visibility <> 'hidden' then
-                               firstElement.style.visibility := 'hidden';
+    try
+       doc := FActiveContent.Browser.ControlInterface.Document as IHTMLDocument2;
+           if Assigned(doc) then
+                   firstElement := doc.all.item('idSearch', 0) as IHTMLElement;
+               if Assigned(firstElement) then
+                       if firstElement.style.visibility <> 'hidden' then
+                               firstElement.style.visibility := 'hidden';
+    except
+    end;
 end;
 
 procedure TGikoForm.RepaintAllTabsBrowser();
@@ -7479,6 +7596,7 @@ begin
        BrowserNullTab.Browser.Navigate(BLANK_HTML);
 
        FBrowsers := TList.Create;
+
        for i := 0 to count -1 do begin
                FBrowsers.Add(TWebBrowser.Create(BrowserPanel));
                newBrowser := FBrowsers[FBrowsers.Count - 1];
@@ -7494,6 +7612,8 @@ begin
                newBrowser.OnStatusTextChange   := BrowserStatusTextChange;
                newBrowser.Navigate(BLANK_HTML);
                ShowWindow(newBrowser.Handle, SW_HIDE);
+        GikoSys.ShowRefCount('Browser' + IntToStr(i), newBrowser.ControlInterface);
+        GikoSys.ShowRefCount('Document' + IntToStr(i), newBrowser.ControlInterface.Document);
        end;
        BrowserNullTab.Browser.BringToFront;
        ShowWindow(BrowserNullTab.Browser.Handle, SW_SHOW);
@@ -7667,10 +7787,17 @@ begin
 end;
 
 procedure TGikoForm.TaskTrayIconMessage(var Msg: TMsg);
+var
+    p: TPoint;
 begin
     //  \8d\83N\83\8a\83b\83N\82È\82ç\95\9c\8c³\82·\82é
     if  (Msg.wParam = WM_LBUTTONUP) then  begin
         UnStoredTaskTray;
+    end else if (Msg.wParam=WM_RBUTTONUP) then begin
+        // \89E\83N\83\8a\83b\83N\82È\82ç\8fI\97¹\82·\82é
+        GetCursorPos ( p );
+        SetForegroundWindow ( Self.Handle );
+        TaskTrayPopupMenu.Popup ( p.X, p.Y );
     end;
 end;
 //! \83^\83X\83N\83g\83\8c\83C\82É\83A\83C\83R\83\93\93o\98^\81\95\83t\83H\81[\83\80\89B\82µ