added throbber.

This commit is contained in:
michaelp 1998-07-11 05:33:00 +00:00
parent 90b3de57ed
commit f12ab6ff1c
4 changed files with 345 additions and 6 deletions

View File

@ -146,6 +146,26 @@ install:: $(TARGETS)
$(INSTALL) samples/gear1.gif $(DIST)/bin/res/samples
$(INSTALL) samples/rock_gra.gif $(DIST)/bin/res/samples
$(INSTALL) samples/bg.jpg $(DIST)/bin/res/samples
$(INSTALL) throbber/anims00.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims01.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims02.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims03.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims04.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims05.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims06.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims07.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims08.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims09.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims1.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims11.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims12.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims13.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims14.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims15.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims16.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims17.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims18.gif $(DIST)/bin/res/throbber
$(INSTALL) throbber/anims19.gif $(DIST)/bin/res/throbber
clobber::
rm -f $(DIST)/bin/viewer.exe
@ -168,5 +188,25 @@ clobber::
rm -f $(DIST)/bin/res/samples/gear1.gif
rm -f $(DIST)/bin/res/samples/rock_gra.gif
rm -f $(DIST)/bin/res/samples/bg.jpg
rm -f $(DIST)/bin/res/throbber/anims00.gif
rm -f $(DIST)/bin/res/throbber/anims01.gif
rm -f $(DIST)/bin/res/throbber/anims02.gif
rm -f $(DIST)/bin/res/throbber/anims03.gif
rm -f $(DIST)/bin/res/throbber/anims04.gif
rm -f $(DIST)/bin/res/throbber/anims05.gif
rm -f $(DIST)/bin/res/throbber/anims06.gif
rm -f $(DIST)/bin/res/throbber/anims07.gif
rm -f $(DIST)/bin/res/throbber/anims08.gif
rm -f $(DIST)/bin/res/throbber/anims09.gif
rm -f $(DIST)/bin/res/throbber/anims10.gif
rm -f $(DIST)/bin/res/throbber/anims11.gif
rm -f $(DIST)/bin/res/throbber/anims12.gif
rm -f $(DIST)/bin/res/throbber/anims13.gif
rm -f $(DIST)/bin/res/throbber/anims14.gif
rm -f $(DIST)/bin/res/throbber/anims15.gif
rm -f $(DIST)/bin/res/throbber/anims16.gif
rm -f $(DIST)/bin/res/throbber/anims17.gif
rm -f $(DIST)/bin/res/throbber/anims18.gif
rm -f $(DIST)/bin/res/throbber/anims19.gif

View File

@ -88,6 +88,26 @@ install:: $(PROGRAM)
$(MAKE_INSTALL) samples\gear1.gif $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\rock_gra.gif $(DIST)\bin\res\samples
$(MAKE_INSTALL) samples\bg.jpg $(DIST)\bin\res\samples
$(MAKE_INSTALL) throbber\anims00.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims01.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims02.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims03.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims04.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims05.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims06.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims07.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims08.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims09.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims10.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims11.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims12.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims13.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims14.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims15.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims16.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims17.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims18.gif $(DIST)\bin\res\throbber
$(MAKE_INSTALL) throbber\anims19.gif $(DIST)\bin\res\throbber
clobber::
rm -f $(DIST)\bin\viewer.exe
@ -111,3 +131,23 @@ clobber::
rm -f $(DIST)\bin\res\samples\gear1.gif
rm -f $(DIST)\bin\res\samples\rock_gra.gif
rm -f $(DIST)\bin\res\samples\bg.jpg
rm -f $(DIST)\bin\res\throbber\anims00.gif
rm -f $(DIST)\bin\res\throbber\anims01.gif
rm -f $(DIST)\bin\res\throbber\anims02.gif
rm -f $(DIST)\bin\res\throbber\anims03.gif
rm -f $(DIST)\bin\res\throbber\anims04.gif
rm -f $(DIST)\bin\res\throbber\anims05.gif
rm -f $(DIST)\bin\res\throbber\anims06.gif
rm -f $(DIST)\bin\res\throbber\anims07.gif
rm -f $(DIST)\bin\res\throbber\anims08.gif
rm -f $(DIST)\bin\res\throbber\anims09.gif
rm -f $(DIST)\bin\res\throbber\anims10.gif
rm -f $(DIST)\bin\res\throbber\anims11.gif
rm -f $(DIST)\bin\res\throbber\anims12.gif
rm -f $(DIST)\bin\res\throbber\anims13.gif
rm -f $(DIST)\bin\res\throbber\anims14.gif
rm -f $(DIST)\bin\res\throbber\anims15.gif
rm -f $(DIST)\bin\res\throbber\anims16.gif
rm -f $(DIST)\bin\res\throbber\anims17.gif
rm -f $(DIST)\bin\res\throbber\anims18.gif
rm -f $(DIST)\bin\res\throbber\anims19.gif

View File

@ -68,6 +68,11 @@
#include "nsINetContainerApplication.h"
#include "nsIButton.h"
#include "nsITextWidget.h"
#include "nsIImageObserver.h"
#include "nsFont.h"
#include "nsIFontMetrics.h"
#include "nsIImageRequest.h"
#include "nsITimer.h"
// Class ID's
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
@ -103,19 +108,26 @@ static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kIDocumentLoaderIID, NS_IDOCUMENTLOADER_IID);
static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID);
static NS_DEFINE_IID(kIChildWidgetIID, NS_IWIDGET_IID);
#define VIEWER_UI
#define VIEWER_UI
#undef INSET_WEBWIDGET
#ifdef VIEWER_UI
#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 30
#define THROBBER_WIDTH 32
#define THROBBER_HEIGHT 32
#define BUTTON_WIDTH 90
#else
#define THROBBER_WIDTH 0
#define THROBBER_HEIGHT 0
#define BUTTON_WIDTH 0
#define BUTTON_HEIGHT 0
#endif
#define BUTTON_HEIGHT THROBBER_HEIGHT
#define THROB_NUM 20
#define THROBBER_AT "resource:/res/throbber/anims%02d.gif"
#ifdef INSET_WEBWIDGET
#define WEBWIDGET_LEFT_INSET 5
#define WEBWIDGET_RIGHT_INSET 5
@ -463,6 +475,11 @@ DocObserver::OnProgress(PRInt32 aProgress, PRInt32 aProgressMax,
NS_IMETHODIMP
DocObserver::OnStartBinding(const char *aContentType)
{
//start the throbber...
if (nsnull != mViewer)
mViewer->mUpdateThrobber = PR_TRUE;
fputs("Loading ", stdout);
fputs(mURL, stdout);
fputs("\n", stdout);
@ -475,6 +492,18 @@ DocObserver::OnStopBinding(PRInt32 status, const nsString& aMsg)
fputs("Done loading ", stdout);
fputs(mURL, stdout);
fputs("\n", stdout);
//stop the throbber...
if (nsnull != mViewer)
{
nsRect trect;
mViewer->mUpdateThrobber = PR_FALSE;
mViewer->mThrobberIdx = 0;
mViewer->mThrobber->GetBounds(trect);
mViewer->mThrobber->Invalidate(PR_FALSE);
}
return NS_OK;
}
@ -674,8 +703,17 @@ nsViewer::Layout(WindowData* aWindowData, int aWidth, int aHeight)
// position location bar (it's stretchy)
if (mLocation) {
mLocation->Resize(2*BUTTON_WIDTH, 0, rr.width - 2*BUTTON_WIDTH,
BUTTON_HEIGHT, PR_TRUE);
if (mThrobber)
mLocation->Resize(2*BUTTON_WIDTH, 0, rr.width - (2*BUTTON_WIDTH + THROBBER_WIDTH),
BUTTON_HEIGHT, PR_TRUE);
else
mLocation->Resize(2*BUTTON_WIDTH, 0, rr.width - 2*BUTTON_WIDTH,
BUTTON_HEIGHT, PR_TRUE);
}
if (mThrobber) {
mThrobber->Resize(rr.width - THROBBER_WIDTH, 0, THROBBER_WIDTH,
THROBBER_HEIGHT, PR_TRUE);
}
// inset the web widget
@ -805,6 +843,195 @@ void nsViewer::ProcessArguments(int argc, char **argv)
}
}
//----------------------------------------------------------------------
// Throbber Implementation
//----------------------------------------------------------------------
class ThrobObserver : public nsIImageRequestObserver {
public:
ThrobObserver();
~ThrobObserver();
NS_DECL_ISUPPORTS
virtual void Notify(nsIImageRequest *aImageRequest,
nsIImage *aImage,
nsImageNotification aNotificationType,
PRInt32 aParam1, PRInt32 aParam2,
void *aParam3);
virtual void NotifyError(nsIImageRequest *aImageRequest,
nsImageError aErrorType);
};
ThrobObserver::ThrobObserver()
{
}
ThrobObserver::~ThrobObserver()
{
}
static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID);
NS_IMPL_ISUPPORTS(ThrobObserver, kIImageObserverIID)
void
ThrobObserver::Notify(nsIImageRequest *aImageRequest,
nsIImage *aImage,
nsImageNotification aNotificationType,
PRInt32 aParam1, PRInt32 aParam2,
void *aParam3)
{
}
void
ThrobObserver::NotifyError(nsIImageRequest *aImageRequest,
nsImageError aErrorType)
{
}
static void throb_timer_callback(nsITimer *aTimer, void *aClosure)
{
nsViewer *viewer = (nsViewer *)aClosure;
if (viewer->mUpdateThrobber)
{
nsRect trect;
viewer->mThrobberIdx++;
if (viewer->mThrobberIdx >= THROB_NUM)
viewer->mThrobberIdx = 0;
viewer->mThrobber->GetBounds(trect);
viewer->mThrobber->Invalidate(PR_TRUE);
}
nsresult rv = NS_NewTimer(&viewer->mThrobTimer);
if (NS_OK == rv)
viewer->mThrobTimer->Init(throb_timer_callback, viewer, 33);
}
void nsViewer::LoadThrobberImages()
{
char url[2000];
mThrobberImages = new nsVoidArray(THROB_NUM);
if ((nsnull != mThrobberImages) &&
(NS_OK == NS_NewImageGroup(&mThrobberImageGroup)))
{
nsIRenderingContext *drawCtx = mThrobber->GetRenderingContext();
mThrobberImageGroup->Init(drawCtx);
NS_RELEASE(drawCtx);
}
nsresult rv = NS_NewTimer(&mThrobTimer);
if (NS_OK == rv)
mThrobTimer->Init(throb_timer_callback, this, 33);
for (PRInt32 cnt = 0; cnt < THROB_NUM; cnt++)
{
sprintf(url, THROBBER_AT, cnt);
ThrobObserver *observer = new ThrobObserver();
mThrobberImages->InsertElementAt(mThrobberImageGroup->GetImage(url,
observer,
NS_RGB(0, 0, 0),
THROBBER_WIDTH - 2,
THROBBER_HEIGHT - 2, 0), cnt);
}
}
void nsViewer::DestroyThrobberImages()
{
if (nsnull != mThrobberImageGroup)
{
if (nsnull != mThrobTimer)
{
mThrobTimer->Cancel(); //XXX this should not be necessary. MMP
NS_RELEASE(mThrobTimer);
}
mThrobberImageGroup->Interrupt();
for (PRInt32 cnt = 0; cnt < THROB_NUM; cnt++)
{
nsIImageRequest *imgreq;
imgreq = (nsIImageRequest *)mThrobberImages->ElementAt(cnt);
if (nsnull != imgreq)
{
NS_RELEASE(imgreq);
mThrobberImages->ReplaceElementAt(nsnull, cnt);
}
}
delete mThrobberImages;
}
}
nsEventStatus PR_CALLBACK HandleThrobberEvent(nsGUIEvent *aEvent)
{
switch (aEvent->message)
{
case NS_PAINT:
{
nsPaintEvent *pe = (nsPaintEvent *)aEvent;
nsIRenderingContext *cx = pe->renderingContext;
nsRect bounds;
nsIImageRequest *imgreq;
nsIImage *img;
pe->widget->GetBounds(bounds);
cx->SetClipRect(*pe->rect, nsClipCombine_kReplace);
cx->SetColor(NS_RGB(255, 255, 255));
cx->DrawLine(0, bounds.height - 1, 0, 0);
cx->DrawLine(0, 0, bounds.width, 0);
cx->SetColor(NS_RGB(128, 128, 128));
cx->DrawLine(bounds.width - 1, 1, bounds.width - 1, bounds.height - 1);
cx->DrawLine(bounds.width - 1, bounds.height - 1, 0, bounds.height - 1);
imgreq = (nsIImageRequest *)gTheViewer->mThrobberImages->ElementAt(gTheViewer->mThrobberIdx);
if ((nsnull == imgreq) || (nsnull == (img = imgreq->GetImage())))
{
char str[3];
nsFont tfont = nsFont("monospace", 0, 0, 0, 0, 10);
nsIFontMetrics *met;
nscoord w, h;
cx->SetColor(NS_RGB(0, 0, 0));
cx->FillRect(1, 1, bounds.width - 2, bounds.height - 2);
sprintf(str, "%02d", gTheViewer->mThrobberIdx);
cx->SetColor(NS_RGB(255, 255, 255));
cx->SetFont(tfont);
met = cx->GetFontMetrics();
w = met->GetWidth(str[0]) + met->GetWidth(str[1]);
h = met->GetHeight();
cx->DrawString(str, 2, (bounds.width - w) >> 1, (bounds.height - h) >> 1, 0);
}
else
{
cx->DrawImage(img, 1, 1);
NS_RELEASE(img);
}
break;
}
}
return nsEventStatus_eIgnore;
}
//----------------------------------------------------------------------
// nsViewer Implementation
//----------------------------------------------------------------------
@ -1472,7 +1699,7 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg
// Add a location box
rect.SetRect(2*BUTTON_WIDTH, 0,
bounds.width - 2*BUTTON_WIDTH, BUTTON_HEIGHT);
bounds.width - 2*BUTTON_WIDTH - THROBBER_WIDTH, BUTTON_HEIGHT);
NSRepository::CreateInstance(kCTextFieldCID, nsnull, kITextWidgetIID,
(void**)&mLocation);
mLocation->Create(wd->windowWidget, rect, HandleLocationEvent, NULL);
@ -1480,6 +1707,17 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg
mLocation->Show(PR_TRUE);
mLocation->SetForegroundColor(NS_RGB(255, 0, 0));
mLocation->SetBackgroundColor(NS_RGB(255, 255, 255));
// Add a throbber
rect.SetRect(bounds.width - THROBBER_WIDTH, 0,
THROBBER_WIDTH, THROBBER_HEIGHT);
NSRepository::CreateInstance(kCChildIID, nsnull, kIChildWidgetIID,
(void**)&mThrobber);
mThrobber->Create(wd->windowWidget, rect, HandleThrobberEvent, NULL);
mThrobber->Show(PR_TRUE);
LoadThrobberImages();
wd->windowWidget->SetBackgroundColor(NS_RGB(255, 0, 0));
#endif
wd->mViewer = this;

View File

@ -29,6 +29,7 @@
#include "nsINetContainerApplication.h"
#include "nsVoidArray.h"
#include "nsIScriptContextOwner.h"
#include "nsIImageGroup.h"
class nsITextWidget;
class nsIScriptContext;
@ -156,6 +157,17 @@ class nsViewer : public nsINetContainerApplication, public nsDispatchListener {
nsViewer() {
mLocation = nsnull;
mHistoryIndex = -1;
mThrobber = nsnull;
mThrobberImages = nsnull;
mThrobberIdx = 0;
mThrobberImageGroup = nsnull;
mThrobTimer = nsnull;
mUpdateThrobber = PR_FALSE;
}
~nsViewer() {
DestroyThrobberImages();
}
// nsISupports
@ -220,7 +232,16 @@ class nsViewer : public nsINetContainerApplication, public nsDispatchListener {
void GoingTo(const nsString& aURL);
void ShowHistory();
void LoadThrobberImages();
void DestroyThrobberImages();
nsITextWidget* mLocation;
nsIWidget* mThrobber;
nsVoidArray* mThrobberImages;
PRInt32 mThrobberIdx;
nsIImageGroup* mThrobberImageGroup;
nsITimer* mThrobTimer;
PRBool mUpdateThrobber;
// Cheesy history (just the urls are stored)
WindowData* mWD;