Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes
nsThrobber Class Reference

#include <nsThrobber.h>

Inheritance diagram for nsThrobber:
Inheritance graph
[legend]
Collaboration diagram for nsThrobber:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS nsresult 
Init (nsIWidget *aParent, const nsRect &aBounds, const nsString &aFileNameMask, PRInt32 aNumImages)
void Destroy ()
nsresult MoveTo (PRInt32 aX, PRInt32 aY)
nsresult Show ()
nsresult Hide ()
nsresult Start ()
nsresult Stop ()

Static Public Member Functions

static nsThrobberNewThrobber ()

Protected Member Functions

 nsThrobber ()
virtual ~nsThrobber ()
void Tick ()
nsresult LoadThrobberImages (const nsString &aFileNameMask, PRInt32 aNumImages)
void DestroyThrobberImages ()

Static Protected Member Functions

static nsThrobberFindThrobberFor (nsIWidget *aWidget)
static void AddThrobber (nsThrobber *aThrobber)
static void RemoveThrobber (nsThrobber *aThrobber)
static nsEventStatus PR_CALLBACK HandleThrobberEvent (nsGUIEvent *aEvent)
static void ThrobTimerCallback (nsITimer *aTimer, void *aClosure)

Protected Attributes

PRInt32 mWidth
PRInt32 mHeight
nsIWidgetmWidget
nsVoidArraymImages
PRInt32 mNumImages
PRInt32 mIndex
nsCOMPtr< nsITimermTimer
PRBool mRunning
PRUint32 mCompletedImages
PRInt32 mPreferredWidth
PRInt32 mPreferredHeight

Static Protected Attributes

static nsVoidArraygThrobbers
static PRInt32 gNumThrobbers

Detailed Description

Definition at line 49 of file nsThrobber.h.


Constructor & Destructor Documentation

nsThrobber::nsThrobber ( ) [protected]

Definition at line 199 of file nsThrobber.cpp.

{
  if (0 == gNumThrobbers++) {
    gThrobbers = new nsVoidArray;
  }
  AddThrobber(this);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsThrobber::~nsThrobber ( ) [protected, virtual]

Definition at line 207 of file nsThrobber.cpp.

{
  Destroy();
}

Here is the call graph for this function:


Member Function Documentation

void nsThrobber::AddThrobber ( nsThrobber aThrobber) [static, protected]

Definition at line 94 of file nsThrobber.cpp.

{
  if (gThrobbers) {
    gThrobbers->AppendElement(aThrobber);
  }
}

Here is the caller graph for this function:

Definition at line 213 of file nsThrobber.cpp.

{
  if (mWidget) {
    mWidget->Destroy();
    NS_RELEASE(mWidget);
  }
  RemoveThrobber(this);
  DestroyThrobberImages();

  if (0 == --gNumThrobbers) {
    delete gThrobbers;
    // Do this in case an event shows up later for the throbber...
    gThrobbers = nsnull;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 383 of file nsThrobber.cpp.

{
  if (mTimer) {
    mTimer->Cancel();
  }

#if 0
  if (mImageGroup) {
    mImageGroup->Interrupt();
    for (PRInt32 cnt = 0; cnt < mNumImages; cnt++) {
      nsIImageRequest *imgreq = (nsIImageRequest*) mImages->ElementAt(cnt);
      NS_IF_RELEASE(imgreq);
    }
    NS_RELEASE(mImageGroup);
  }

  if (mImages) {
    delete mImages;
    mImages = nsnull;
  }
#endif
}

Here is the caller graph for this function:

nsThrobber * nsThrobber::FindThrobberFor ( nsIWidget aWidget) [static, protected]

Definition at line 77 of file nsThrobber.cpp.

{
  if (gThrobbers) {
    PRInt32 i, n = gThrobbers->Count();
    for (i = 0; i < n; i++) {
      nsThrobber* th = (nsThrobber*) gThrobbers->ElementAt(i);
      if (nsnull != th) {
        if (th->mWidget == aWidget) {
          return th;
        }
      }
    }
  }
  return nsnull;
}

Here is the caller graph for this function:

Definition at line 110 of file nsThrobber.cpp.

{
  nsThrobber* throbber = FindThrobberFor(aEvent->widget);
  if (nsnull == throbber) {
    return nsEventStatus_eIgnore;
  }

  switch (aEvent->message)
  {
    case NS_PAINT:
    {
#if 0

      nsPaintEvent *pe = (nsPaintEvent *)aEvent;
      nsIRenderingContext *cx = pe->renderingContext;
      nsRect bounds;
      nsIImageRequest *imgreq;
      nsIImage *img;
      PRBool clipState;
   
      pe->widget->GetClientBounds(bounds);

      cx->SetClipRect(*pe->rect, nsClipCombine_kReplace, clipState);

      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 *)
        throbber->mImages->ElementAt(throbber->mIndex);

      if ((nsnull == imgreq) || (nsnull == (img = imgreq->GetImage())))
      {
        char str[10];
        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);

        PR_snprintf(str, sizeof(str), "%02d", throbber->mIndex);

        cx->SetColor(NS_RGB(255, 255, 255));
        cx->SetFont(tfont);
        cx->GetFontMetrics(met);
        if (nsnull != met)
        {
          cx->GetWidth(str, w);
          met->GetHeight(h);
          cx->DrawString(str, PRUint32(2), (bounds.width - w) >> 1, (bounds.height - h) >> 1);
          NS_RELEASE(met);
        }
      }
      else
      {
        cx->DrawImage(img, 1, 1);
        NS_RELEASE(img);
      }
#endif
      break;
    }

    case NS_MOUSE_LEFT_BUTTON_UP:
      // XXX wire up to API
      //gTheViewer->GoTo(nsString("http://www.mozilla.org"));
      break;

    case NS_MOUSE_ENTER:
      aEvent->widget->SetCursor(eCursor_hyperlink);
      break;

    case NS_MOUSE_EXIT:
      aEvent->widget->SetCursor(eCursor_standard);
      break;
  }

  return nsEventStatus_eIgnore;
}

Here is the call graph for this function:

Definition at line 263 of file nsThrobber.cpp.

{
  mWidget->Show(PR_FALSE);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsThrobber::Init ( nsIWidget aParent,
const nsRect aBounds,
const nsString aFileNameMask,
PRInt32  aNumImages 
)

Definition at line 232 of file nsThrobber.cpp.

{
  mWidth     = aBounds.width;
  mHeight    = aBounds.height;
  mNumImages = aNumImages;

  // Create widget
  nsresult rv = CallCreateInstance(kChildCID, &mWidget);
  if (NS_OK != rv) {
    return rv;
  }
  mWidget->Create(aParent, aBounds, HandleThrobberEvent, NULL);
  return LoadThrobberImages(aFileNameMask, aNumImages);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsThrobber::LoadThrobberImages ( const nsString aFileNameMask,
PRInt32  aNumImages 
) [protected]

Definition at line 333 of file nsThrobber.cpp.

{
#if 0
  nsresult rv;
  char url[2000];

  mImages = new nsVoidArray(mNumImages);
  if (nsnull == mImages) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  rv = NS_NewImageGroup(&mImageGroup);
  if (NS_OK != rv) {
    return rv;
  }

  nsIDeviceContext *deviceCtx = mWidget->GetDeviceContext();
  mImageGroup->Init(deviceCtx, nsnull);
  NS_RELEASE(deviceCtx);

  mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
  if (NS_OK != rv) {
    return rv;
  }
  mTimer->InitWithFuncCallback(ThrobTimerCallback, this, 33, nsITimer::TYPE_REPEATING_SLACK);
  
  char * mask = ToNewCString(aFileNameMask);
  for (PRInt32 cnt = 0; cnt < mNumImages; cnt++)
  {
    PR_snprintf(url, sizeof(url), mask, cnt);
    nscolor bgcolor = NS_RGB(0, 0, 0);
    mImages->InsertElementAt(mImageGroup->GetImage(url,
                                                   (nsIImageRequestObserver *)this,
                                                   &bgcolor,
                                                   mWidth - 2,
                                                   mHeight - 2, 0),
                                                   cnt);
  }

  if (nsnull != mask)
    nsMemory::Free(mask);

  mWidget->Invalidate(PR_TRUE);

  return rv;
#endif

return NS_OK;
}

Here is the call graph for this function:

Definition at line 248 of file nsThrobber.cpp.

{
  NS_PRECONDITION(nsnull != mWidget, "no widget");
  mWidget->Resize(aX, aY, mWidth, mHeight, PR_TRUE);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 63 of file nsThrobber.cpp.

{
  nsThrobber* t = new nsThrobber();
  if (t) {
    NS_ADDREF(t);
  }
  return t;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsThrobber::RemoveThrobber ( nsThrobber aThrobber) [static, protected]

Definition at line 102 of file nsThrobber.cpp.

{
  if (gThrobbers) {
    gThrobbers->RemoveElement(aThrobber);
  }
}

Here is the caller graph for this function:

Definition at line 256 of file nsThrobber.cpp.

{
  mWidget->Show(PR_TRUE);
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 270 of file nsThrobber.cpp.

{
  mRunning = PR_TRUE;
  return NS_OK;
}

Here is the caller graph for this function:

Definition at line 277 of file nsThrobber.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsThrobber::ThrobTimerCallback ( nsITimer aTimer,
void aClosure 
) [static, protected]

Definition at line 312 of file nsThrobber.cpp.

{
  nsThrobber* throbber = (nsThrobber*)aClosure;
  throbber->Tick();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsThrobber::Tick ( ) [protected]

Definition at line 319 of file nsThrobber.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

PRInt32 nsThrobber::gNumThrobbers [static, protected]

Definition at line 112 of file nsThrobber.h.

nsVoidArray * nsThrobber::gThrobbers [static, protected]

Definition at line 111 of file nsThrobber.h.

Definition at line 100 of file nsThrobber.h.

Definition at line 92 of file nsThrobber.h.

Definition at line 94 of file nsThrobber.h.

Definition at line 96 of file nsThrobber.h.

Definition at line 95 of file nsThrobber.h.

Definition at line 103 of file nsThrobber.h.

Definition at line 102 of file nsThrobber.h.

Definition at line 99 of file nsThrobber.h.

Definition at line 98 of file nsThrobber.h.

Definition at line 93 of file nsThrobber.h.

Definition at line 91 of file nsThrobber.h.


The documentation for this class was generated from the following files: