Hooked up the related links code to the demo. Getting duplicated now,

hopefully get that fixed soon.
This commit is contained in:
jevering 1998-07-15 18:45:16 +00:00
parent 8bc7ad7f2a
commit 7554b89a54
5 changed files with 110 additions and 1 deletions

View File

@ -151,6 +151,9 @@ nsViewer* gTheViewer = nsnull;
WindowData * gMainWindowData = nsnull;
nsIAppShell *gAppShell= nsnull;
nsIPref *gPrefs;
#define MAX_RL 15
static char* gRLList[MAX_RL];
static int gRLPos = 0;
static char* startURL;
static nsVoidArray* gWindows;
static PRBool gDoPurify; // run in Purify auto mode
@ -378,6 +381,21 @@ DocObserver::LoadURL(const nsString& aURLSpec,
nsIStreamObserver* anObserver)
{
mURL = aURLSpec;
for (int i = 0; i < MAX_RL; i++) {
if (gRLList[i])
PL_strfree(gRLList[i]);
}
gRLPos = 0;
mViewer->ResetRelatedLinks();
if (mViewer->mRelatedLinks) {
char * pStr = aURLSpec.ToNewCString();
mViewer->mRelatedLinks->SetRLWindowURL(mViewer->mRLWindow, pStr);
if (pStr)
free(pStr);
mViewer->mRelatedLinks->WindowItems(mViewer->mRLWindow);
}
return mDocLoader->LoadURL(aURLSpec, aCommand, aContainer,
aPostData, aExtraInfo, anObserver);
}
@ -1475,6 +1493,22 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd)
DoDebugSave(wd);
break;
case VIEWER_RL_BASE:
case VIEWER_RL_BASE+1:
case VIEWER_RL_BASE+2:
case VIEWER_RL_BASE+3:
case VIEWER_RL_BASE+4:
case VIEWER_RL_BASE+5:
case VIEWER_RL_BASE+6:
case VIEWER_RL_BASE+7:
case VIEWER_RL_BASE+8:
case VIEWER_RL_BASE+9:
case VIEWER_RL_BASE+10:
if (wd) {
wd->mViewer->GoTo(gRLList[aId-VIEWER_RL_BASE]);
}
break;
}
return(result);
@ -1586,7 +1620,8 @@ nsViewer::GoTo(const nsString& aURLSpec,
printf("goto: ");
fputs(aURLSpec, stdout);
printf("\n");
mLocation->RemoveText();
mLocation->SetText(aURLSpec);
rv = mWD->observer->LoadURL(aURLSpec, // URL string
aCommand, // Command
aContainer, // Container
@ -1620,6 +1655,25 @@ nsViewer::GoingTo(const nsString& aURL)
#endif
}
static nsIRelatedLinks * gRelatedLinks = 0;
static void DumpRLValues(void* pdata, RL_Window win)
{
nsViewer * pIViewer = (nsViewer *)pdata;
if (pIViewer) {
RL_Item nextItem = gRelatedLinks->WindowItems(win);
do {
char * pname = gRelatedLinks->ItemName(nextItem);
char * purl = gRelatedLinks->ItemUrl(nextItem);
if (pname) {
if (gRLPos < MAX_RL)
gRLList[gRLPos++] = PL_strdup(purl);
pIViewer->AddRelatedLink(pname, purl);
}
} while ((nextItem = gRelatedLinks->NextItem(nextItem))!=0);
}
}
nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **argv)
{
#ifdef XP_PC
@ -1662,6 +1716,14 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg
NS_InitINetService(this);
for (int i=0; i<MAX_RL; i++)
gRLList[i] = nsnull;
mRelatedLinks = NS_NewRelatedLinks();
gRelatedLinks = mRelatedLinks;
if (mRelatedLinks) {
mRLWindow = mRelatedLinks->MakeRLWindowWithCallback(DumpRLValues, this);
}
// Create an application shell
res=NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&gAppShell);
if (NS_OK==res)
@ -1827,6 +1889,16 @@ void nsViewer::ShowConsole(WindowData* aWindata)
printf("ShowConsole not implemented\n");
}
void nsViewer::AddRelatedLink(char * name, char * url)
{
printf("AddRelatedLink not implemented\n");
}
void nsViewer::ResetRelatedLinks()
{
printf("ResetRelatedLinks not implemented\n");
}
void nsViewer::CloseConsole()
{
printf("CloseConsole not implemented\n");

View File

@ -20,6 +20,7 @@
#include "nsIWebWidget.h"
#include "nsIDocumentObserver.h"
#include "nsIRelatedLinks.h"
#include "nsIStreamListener.h"
#include "nsILinkHandler.h"
#include "nsIDocumentLoader.h"
@ -190,6 +191,8 @@ class nsViewer : public nsINetContainerApplication, public nsDispatchListener {
virtual void DoDebugSave(WindowData* aWindata);
virtual void DoSiteWalker(WindowData* aWindata);
virtual void CopySelection(WindowData* aWindata);
virtual void AddRelatedLink(char * name, char * url);
virtual void ResetRelatedLinks();
virtual nsresult Run();
virtual void Destroy(WindowData* wd);
virtual void Stop();
@ -256,6 +259,8 @@ class nsViewer : public nsINetContainerApplication, public nsDispatchListener {
WindowData* mWD;
nsVoidArray mHistory;
PRInt32 mHistoryIndex;
nsIRelatedLinks * mRelatedLinks;
RL_Window mRLWindow;
};
// Set the single viewer.

View File

@ -66,6 +66,8 @@
#define VIEWER_EDIT_SELECTALL 40204
#define VIEWER_EDIT_FINDINPAGE 40205
#define VIEWER_RL_BASE 41000
#define VIEWER_TOP100 40300
/* Debug Robot dialog setup */

View File

@ -85,6 +85,10 @@ VIEWER MENU DISCARDABLE
MENUITEM "&JavaScript Console", JS_CONSOLE
MENUITEM "&Editor Mode", EDITOR_MODE
}
POPUP "&Related Links"
{
MENUITEM SEPARATOR
}
}
PRINTPREVIEW MENU DISCARDABLE

View File

@ -20,6 +20,7 @@
#include <windows.h>
#include <crtdbg.h>
#include <stdio.h>
#include "resources.h"
#include "jsconsres.h"
#include "JSConsole.h"
@ -74,6 +75,9 @@ class nsWin32Viewer : public nsViewer {
virtual void CloseConsole();
virtual void Stop();
virtual void CrtSetDebug(PRUint32 aNewFlags);
virtual void AddRelatedLink(char * name, char * url);
virtual void ResetRelatedLinks();
// Utilities
virtual void CopyTextContent(WindowData* wd, HWND aHWnd);
};
@ -99,6 +103,27 @@ void DestroyConsole()
}
}
HWND ghWnd = 0;
#define RL_MENU_POS 4
void nsWin32Viewer::AddRelatedLink(char * name, char * url)
{
if (name) {
HMENU hMenu = GetMenu(ghWnd);
HMENU hDropDown = GetSubMenu(hMenu,RL_MENU_POS);
int i = GetMenuItemCount(hDropDown);
AppendMenu(hDropDown, MF_STRING, VIEWER_RL_BASE+i, (LPCSTR)name);
}
}
void nsWin32Viewer::ResetRelatedLinks()
{
HMENU hMenu = GetMenu(ghWnd);
HMENU hDropDown = GetSubMenu(hMenu,RL_MENU_POS);
while (DeleteMenu(hDropDown,0,MF_BYPOSITION))
;
}
//-----------------------------------------------------------------
// CRT Debug
//-----------------------------------------------------------------
@ -187,6 +212,7 @@ void AddViewerMenu(HINSTANCE hInstance, nsIWidget* aWidget, LPCTSTR lpMenuName)
{
HMENU menu = ::LoadMenu(hInstance,lpMenuName);
HWND hwnd = aWidget->GetNativeData(NS_NATIVE_WIDGET);
ghWnd = hwnd;
::SetMenu(hwnd, menu);
}