Added code to support getting the URL's for samples using the current working

directory under unix.
This commit is contained in:
kmcclusk 1998-06-11 20:57:27 +00:00
Родитель 3395527f32
Коммит 0345bf75cc
3 изменённых файлов: 52 добавлений и 4 удалений

Просмотреть файл

@ -19,9 +19,13 @@
#include "nsViewer.h"
#include "nsMotifMenu.h"
#include "nsIImageManager.h"
#include <stdlib.h>
#define FILE_BASE_URL "file:////home/kmcclusk/mozilla/dist/Linux2.0.31_x86_DBG.OBJ/bin/res/samples"
class nsMotifViewer : public nsViewer {
virtual void AddMenu(nsIWidget* aMainWindow);
virtual char* GetBaseURL();
};
//--------------------------------------------------------
@ -64,4 +68,29 @@ void nsMotifViewer::AddMenu(nsIWidget* aMainWindow)
CreateViewerMenus(XtParent(aMainWindow->GetNativeData(NS_NATIVE_WIDGET)), MenuProc);
}
char* nsMotifViewer::GetBaseURL()
{
static char* protocol = "file:///";
static char url[MAXPATHLEN + sizeof(protocol)];
FILE *pp;
char location[MAXPATHLEN];
if (!(pp = popen("pwd", "r"))) {
printf("Error in nsMotifViewer::GetBaseURL 1\n");
return(0);
}
else {
if (fgets(location, MAXPATHLEN, pp)) {
location[strlen(location)-1] = 0;
sprintf(url, "%s%s%s", protocol,location, "/res/samples");
return(url);
}
else
printf("Error in nsMotifViewer::GetBaseURL 2\n");
return(0);
}
}

Просмотреть файл

@ -81,8 +81,12 @@ static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID);
static NS_DEFINE_IID(kCWebWidgetCID, NS_WEBWIDGET_CID);
//#define SAMPLES_BASE_URL "file:////home/kmcclusk/mozilla/dist/Linux2.0.31_x86_DBG.OBJ/bin/res/samples"
//#define START_URL SAMPLES_BASE_URL "/test0.html"
#define SAMPLES_BASE_URL "resource:/res/samples"
#define START_URL SAMPLES_BASE_URL "/test0.html"
#define DEFAULT_DOC "/test0.html"
nsViewer* gTheViewer = nsnull;
WindowData * gMainWindowData = nsnull;
@ -654,7 +658,7 @@ void nsViewer::AddTestDocs(nsDocLoader* aDocLoader)
char url[500];
for (int docnum = 0; docnum < gNumSamples; docnum++)
{
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, docnum);
PR_snprintf(url, 500, "%s/test%d.html", GetBaseURL(), docnum);
aDocLoader->AddURL(url);
}
}
@ -950,7 +954,7 @@ nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd)
if ((nsnull != wd) && (nsnull != wd->ww)) {
PRIntn ix = aId - VIEWER_DEMO0;
char* url = new char[500];
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, ix);
PR_snprintf(url, 500, "%s/test%d.html", GetBaseURL(), ix);
wd->observer->LoadURL(url);
delete url;
}
@ -1117,7 +1121,7 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg
}
else {
// Load the starting url if we have one
wd->observer->LoadURL(startURL ? startURL : START_URL);
wd->observer->LoadURL(startURL ? startURL : GetDefaultStartURL());
if (gDoQuantify) {
// Synthesize 20 ResizeReflow commands (+/- 10 pixels) and then
// exit.
@ -1144,6 +1148,19 @@ void nsViewer::AfterDispatch()
NET_PollSockets();
}
char* nsViewer::GetBaseURL()
{
return(SAMPLES_BASE_URL);
}
char* nsViewer::GetDefaultStartURL()
{
static char defaultURL[MAXPATHLEN];
sprintf(defaultURL, "%s%s", GetBaseURL(), DEFAULT_DOC);
return(defaultURL);
}
void nsViewer::AddMenu(nsIWidget* aMainWindow)
{
printf("Menu not implemented\n");

Просмотреть файл

@ -133,6 +133,8 @@ struct WindowData {
class nsViewer : public nsDispatchListener {
public:
virtual char* GetBaseURL();
virtual char* GetDefaultStartURL();
virtual void AddMenu(nsIWidget* aMainWindow);
virtual void ShowConsole(WindowData* aWindata);
virtual void CloseConsole();