1998-09-23 19:19:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-09-23 19:19:23 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-09-23 19:19:23 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-09-23 19:19:23 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-09-23 19:19:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsBaseWidget.h"
|
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
1999-01-25 19:18:43 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-02-05 02:19:46 +00:00
|
|
|
#include "nsIMenuListener.h"
|
1999-02-23 08:10:24 +00:00
|
|
|
#include "nsIEnumerator.h"
|
1998-09-23 19:19:23 +00:00
|
|
|
#include "nsGfxCIID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPref.h"
|
1999-12-03 07:23:22 +00:00
|
|
|
#include "prefapi.h"
|
|
|
|
|
|
|
|
static void debug_RegisterPrefCallbacks();
|
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
#endif
|
|
|
|
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
static PRInt32 gNumWidgets;
|
|
|
|
#endif
|
|
|
|
|
1999-09-04 08:13:41 +00:00
|
|
|
// nsBaseWidget
|
|
|
|
NS_IMPL_ISUPPORTS1(nsBaseWidget, nsIWidget)
|
1999-02-23 08:10:24 +00:00
|
|
|
|
1999-09-04 08:13:41 +00:00
|
|
|
// nsBaseWidget::Enumerator
|
|
|
|
NS_IMPL_ISUPPORTS2(nsBaseWidget::Enumerator, nsIBidirectionalEnumerator, nsIEnumerator)
|
1999-02-23 08:10:24 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1999-10-05 14:53:40 +00:00
|
|
|
|
1999-08-24 01:00:01 +00:00
|
|
|
nsBaseWidget::nsBaseWidget()
|
|
|
|
: mClientData(nsnull)
|
|
|
|
, mEventCallback(nsnull)
|
|
|
|
, mContext(nsnull)
|
|
|
|
, mAppShell(nsnull)
|
|
|
|
, mToolkit(nsnull)
|
|
|
|
, mMouseListener(nsnull)
|
|
|
|
, mEventListener(nsnull)
|
|
|
|
, mMenuListener(nsnull)
|
|
|
|
, mCursor(eCursor_standard)
|
|
|
|
, mBorderStyle(eBorderStyle_none)
|
|
|
|
, mIsShiftDown(PR_FALSE)
|
|
|
|
, mIsControlDown(PR_FALSE)
|
|
|
|
, mIsAltDown(PR_FALSE)
|
|
|
|
, mIsDestroying(PR_FALSE)
|
|
|
|
, mOnDestroyCalled(PR_FALSE)
|
|
|
|
, mBounds(0,0,0,0)
|
1999-09-28 01:31:41 +00:00
|
|
|
#ifdef LOSER
|
1999-08-24 01:00:01 +00:00
|
|
|
, mVScrollbar(nsnull)
|
1999-09-28 01:31:41 +00:00
|
|
|
#endif
|
1999-09-23 23:26:25 +00:00
|
|
|
, mZIndex(0)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets++;
|
|
|
|
printf("WIDGETS+ = %d\n", gNumWidgets);
|
|
|
|
#endif
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
debug_RegisterPrefCallbacks();
|
|
|
|
#endif
|
|
|
|
|
1999-05-26 21:12:54 +00:00
|
|
|
NS_NewISupportsArray(getter_AddRefs(mChildren));
|
|
|
|
|
1999-02-03 04:25:40 +00:00
|
|
|
NS_INIT_REFCNT();
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsBaseWidget destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsBaseWidget::~nsBaseWidget()
|
|
|
|
{
|
1999-10-05 14:53:40 +00:00
|
|
|
#ifdef NOISY_WIDGET_LEAKS
|
|
|
|
gNumWidgets--;
|
|
|
|
printf("WIDGETS- = %d\n", gNumWidgets);
|
|
|
|
#endif
|
|
|
|
|
1999-02-05 02:19:46 +00:00
|
|
|
NS_IF_RELEASE(mMenuListener);
|
1999-09-28 01:31:41 +00:00
|
|
|
#ifdef LOSER
|
1999-03-05 15:50:04 +00:00
|
|
|
NS_IF_RELEASE(mVScrollbar);
|
1999-09-28 01:31:41 +00:00
|
|
|
#endif
|
1999-09-29 01:25:19 +00:00
|
|
|
NS_IF_RELEASE(mToolkit);
|
|
|
|
NS_IF_RELEASE(mContext);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-10-15 00:49:11 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Basic create.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::BaseCreate(nsIWidget *aParent,
|
1999-09-28 01:31:41 +00:00
|
|
|
const nsRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsIDeviceContext *aContext,
|
|
|
|
nsIAppShell *aAppShell,
|
|
|
|
nsIToolkit *aToolkit,
|
|
|
|
nsWidgetInitData *aInitData)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull == mToolkit) {
|
|
|
|
if (nsnull != aToolkit) {
|
|
|
|
mToolkit = (nsIToolkit*)aToolkit;
|
|
|
|
NS_ADDREF(mToolkit);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull != aParent) {
|
|
|
|
mToolkit = (nsIToolkit*)(aParent->GetToolkit()); // the call AddRef's, we don't have to
|
|
|
|
}
|
|
|
|
// it's some top level window with no toolkit passed in.
|
|
|
|
// Create a default toolkit with the current thread
|
1999-10-15 00:49:11 +00:00
|
|
|
#if !defined(USE_TLS_FOR_TOOLKIT)
|
1999-09-28 01:31:41 +00:00
|
|
|
else {
|
|
|
|
static NS_DEFINE_CID(kToolkitCID, NS_TOOLKIT_CID);
|
|
|
|
|
|
|
|
nsresult res;
|
|
|
|
res = nsComponentManager::CreateInstance(kToolkitCID, nsnull,
|
|
|
|
NS_GET_IID(nsIToolkit), (void **)&mToolkit);
|
|
|
|
if (NS_OK != res)
|
|
|
|
NS_ASSERTION(PR_FALSE, "Can not create a toolkit in nsBaseWidget::Create");
|
|
|
|
if (mToolkit)
|
|
|
|
mToolkit->Init(PR_GetCurrentThread());
|
|
|
|
}
|
1999-10-15 00:49:11 +00:00
|
|
|
#else /* USE_TLS_FOR_TOOLKIT */
|
|
|
|
else {
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = NS_GetCurrentToolkit(&mToolkit);
|
|
|
|
}
|
|
|
|
#endif /* USE_TLS_FOR_TOOLKIT */
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
1999-09-28 01:31:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
mAppShell = aAppShell;
|
|
|
|
NS_IF_ADDREF(mAppShell);
|
|
|
|
|
|
|
|
// save the event callback function
|
|
|
|
mEventCallback = aHandleEventFunction;
|
|
|
|
|
|
|
|
// keep a reference to the device context
|
|
|
|
if (aContext) {
|
|
|
|
mContext = aContext;
|
|
|
|
NS_ADDREF(mContext);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsresult res;
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID);
|
|
|
|
|
|
|
|
res = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull,
|
|
|
|
NS_GET_IID(nsIDeviceContext), (void **)&mContext);
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
if (NS_OK == res)
|
|
|
|
mContext->Init(nsnull);
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
if (nsnull != aInitData) {
|
|
|
|
PreCreateWidget(aInitData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aParent) {
|
|
|
|
aParent->AddChild(this);
|
|
|
|
}
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-06-21 20:37:50 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::CaptureMouse(PRBool aCapture)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Accessor functions to get/set the client data
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetClientData(void*& aClientData)
|
|
|
|
{
|
|
|
|
aClientData = mClientData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetClientData(void* aClientData)
|
|
|
|
{
|
|
|
|
mClientData = aClientData;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Close this nsBaseWidget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::Destroy()
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
|
|
|
// disconnect from the parent
|
|
|
|
nsIWidget *parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
1999-09-28 01:31:41 +00:00
|
|
|
#ifdef LOSER
|
1999-04-19 23:24:40 +00:00
|
|
|
NS_IF_RELEASE(mVScrollbar);
|
1999-09-28 01:31:41 +00:00
|
|
|
#endif
|
1999-03-12 04:29:48 +00:00
|
|
|
// disconnect listeners.
|
|
|
|
NS_IF_RELEASE(mMouseListener);
|
|
|
|
NS_IF_RELEASE(mEventListener);
|
|
|
|
NS_IF_RELEASE(mMenuListener);
|
1999-04-19 23:24:40 +00:00
|
|
|
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget parent
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIWidget* nsBaseWidget::GetParent(void)
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this nsBaseWidget's list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIEnumerator* nsBaseWidget::GetChildren()
|
|
|
|
{
|
1999-05-26 21:12:54 +00:00
|
|
|
nsIEnumerator* children = nsnull;
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1999-06-22 19:07:03 +00:00
|
|
|
PRUint32 itemCount = 0;
|
1999-05-26 21:12:54 +00:00
|
|
|
mChildren->Count(&itemCount);
|
|
|
|
if ( itemCount ) {
|
|
|
|
children = new Enumerator(*this);
|
|
|
|
NS_IF_ADDREF(children);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
1999-05-26 21:12:54 +00:00
|
|
|
return children;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Add a child to the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::AddChild(nsIWidget* aChild)
|
|
|
|
{
|
1999-05-26 21:12:54 +00:00
|
|
|
mChildren->AppendElement(aChild);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Remove a child from the list of children
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::RemoveChild(nsIWidget* aChild)
|
|
|
|
{
|
1999-05-26 21:12:54 +00:00
|
|
|
mChildren->RemoveElement(aChild);
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
1999-09-23 23:26:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Sets widget's position within its parent's child list.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::SetZIndex(PRInt32 aZIndex)
|
|
|
|
{
|
|
|
|
mZIndex = aZIndex;
|
|
|
|
|
|
|
|
// reorder this child in its parent's list.
|
|
|
|
nsBaseWidget* parent = NS_STATIC_CAST(nsBaseWidget*, GetParent());
|
|
|
|
if (nsnull != parent) {
|
|
|
|
parent->mChildren->RemoveElement(this);
|
|
|
|
PRUint32 childCount, index;
|
|
|
|
if (NS_SUCCEEDED(parent->mChildren->Count(&childCount))) {
|
|
|
|
for (index = 0; index < childCount; index++) {
|
|
|
|
nsCOMPtr<nsIWidget> childWidget;
|
|
|
|
if (NS_SUCCEEDED(parent->mChildren->QueryElementAt(index, NS_GET_IID(nsIWidget), (void**)getter_AddRefs(childWidget)))) {
|
|
|
|
PRInt32 childZIndex;
|
|
|
|
if (NS_SUCCEEDED(childWidget->GetZIndex(&childZIndex))) {
|
|
|
|
if (aZIndex < childZIndex) {
|
|
|
|
parent->mChildren->InsertElementAt(this, index);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// were we added to the list?
|
|
|
|
if (index == childCount) {
|
|
|
|
parent->mChildren->AppendElement(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Gets widget's position within its parent's child list.
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP nsBaseWidget::GetZIndex(PRInt32* aZIndex)
|
|
|
|
{
|
|
|
|
*aZIndex = mZIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the foreground color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nscolor nsBaseWidget::GetForegroundColor(void)
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mForeground;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set the foreground color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetForegroundColor(const nscolor &aColor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
mForeground = aColor;
|
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get the background color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nscolor nsBaseWidget::GetBackgroundColor(void)
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mBackground;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Set the background color
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetBackgroundColor(const nscolor &aColor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
mBackground = aColor;
|
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Get this component cursor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsCursor nsBaseWidget::GetCursor()
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
return mCursor;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetCursor(nsCursor aCursor)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
|
|
|
mCursor = aCursor;
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Create a rendering context from this nsBaseWidget
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIRenderingContext* nsBaseWidget::GetRenderingContext()
|
|
|
|
{
|
|
|
|
nsIRenderingContext *renderingCtx = NULL;
|
|
|
|
nsresult res;
|
|
|
|
|
1999-09-04 08:13:41 +00:00
|
|
|
static NS_DEFINE_CID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1999-04-03 18:38:47 +00:00
|
|
|
res = nsComponentManager::CreateInstance(kRenderingContextCID, nsnull,
|
1999-09-04 08:13:41 +00:00
|
|
|
NS_GET_IID(nsIRenderingContext),
|
1999-04-03 18:38:47 +00:00
|
|
|
(void **)&renderingCtx);
|
1998-09-23 19:19:23 +00:00
|
|
|
|
|
|
|
if (NS_OK == res)
|
|
|
|
renderingCtx->Init(mContext, this);
|
|
|
|
|
|
|
|
NS_ASSERTION(NULL != renderingCtx, "Null rendering context");
|
|
|
|
|
|
|
|
return renderingCtx;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the toolkit this widget was created on
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIToolkit* nsBaseWidget::GetToolkit()
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mToolkit);
|
|
|
|
return mToolkit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the used device context
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsIDeviceContext* nsBaseWidget::GetDeviceContext()
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mContext);
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Return the App Shell
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsIAppShell *nsBaseWidget::GetAppShell()
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
NS_IF_ADDREF(mAppShell);
|
|
|
|
return mAppShell;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destroy the window
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
void nsBaseWidget::OnDestroy()
|
|
|
|
{
|
1999-09-28 01:31:41 +00:00
|
|
|
// release references to device context, toolkit, and app shell
|
|
|
|
NS_IF_RELEASE(mContext);
|
|
|
|
NS_IF_RELEASE(mToolkit);
|
|
|
|
NS_IF_RELEASE(mAppShell);
|
1998-12-01 17:58:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-27 04:27:17 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetWindowType(nsWindowType aWindowType)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
1999-07-27 04:27:17 +00:00
|
|
|
mWindowType = aWindowType;
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1999-07-27 04:27:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD nsBaseWidget::SetBorderStyle(nsBorderStyle aBorderStyle)
|
|
|
|
{
|
|
|
|
mBorderStyle = aBorderStyle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Processes a mouse pressed event
|
|
|
|
*
|
|
|
|
**/
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::AddMouseListener(nsIMouseListener * aListener)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mMouseListener == nsnull, "Null mouse listener");
|
1999-03-12 04:29:48 +00:00
|
|
|
NS_IF_RELEASE(mMouseListener);
|
|
|
|
NS_ADDREF(aListener);
|
1998-09-23 19:19:23 +00:00
|
|
|
mMouseListener = aListener;
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Processes a mouse pressed event
|
|
|
|
*
|
|
|
|
**/
|
1998-09-28 22:32:48 +00:00
|
|
|
NS_METHOD nsBaseWidget::AddEventListener(nsIEventListener * aListener)
|
1998-09-23 19:19:23 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mEventListener == nsnull, "Null mouse listener");
|
1999-03-12 04:29:48 +00:00
|
|
|
NS_IF_RELEASE(mEventListener);
|
|
|
|
NS_ADDREF(aListener);
|
1998-09-23 19:19:23 +00:00
|
|
|
mEventListener = aListener;
|
1998-09-28 22:32:48 +00:00
|
|
|
return NS_OK;
|
1998-09-23 19:19:23 +00:00
|
|
|
}
|
|
|
|
|
1999-01-22 23:23:00 +00:00
|
|
|
/**
|
1999-02-05 02:19:46 +00:00
|
|
|
* Add a menu listener
|
|
|
|
* This interface should only be called by the menu services manager
|
|
|
|
* This will AddRef() the menu listener
|
|
|
|
* This will Release() a previously set menu listener
|
1999-01-22 23:23:00 +00:00
|
|
|
*
|
|
|
|
**/
|
1999-01-27 04:20:20 +00:00
|
|
|
|
1999-01-22 23:23:00 +00:00
|
|
|
NS_METHOD nsBaseWidget::AddMenuListener(nsIMenuListener * aListener)
|
|
|
|
{
|
1999-02-05 02:19:46 +00:00
|
|
|
NS_IF_RELEASE(mMenuListener);
|
|
|
|
NS_IF_ADDREF(aListener);
|
1999-01-22 23:23:00 +00:00
|
|
|
mMenuListener = aListener;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-27 04:20:20 +00:00
|
|
|
|
1998-09-23 19:19:23 +00:00
|
|
|
|
1998-11-04 21:43:47 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
1998-11-04 21:43:47 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetClientBounds(nsRect &aRect)
|
|
|
|
{
|
|
|
|
return GetBounds(aRect);
|
|
|
|
}
|
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetBounds(nsRect &aRect)
|
|
|
|
{
|
|
|
|
aRect = mBounds;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
fixed bugs #6303, #6753, #6756, #6759
Re-wrote nsComboboxFrame.
removed the obsolete nsHTMLAtoms: comboText,comoTextSelected,comTextSelectedFocus,dropDownVisible,
dropdownHidden, dropDownBtnOut, dropDownBtnPressed,
Added nsHTMLAtoms::combobox, nsLayoutAtoms::popupList
Renamed dropDownList to dropDownListPseudo
Added "arrow.gif" as to be used the background-image for the combobox button
ua.css - added rules for select to differentiate between comboboxes and listboxes.
Added style rules to more closely match the XPTOOLKIT XPWidgets look.
removed the following :-moz-combobox-text, -moz-combobox-textselected
nsIFormControlFrame.h - Added SetSuggestedSize method.
nsButtonControlFrame - Implemented SetSuggestedSize.
nsCSSFrameConstructor.cpp - Rewrote ConstructSelectFrame.
nsIWidget.h -Added GetAbsoluteBounds method.
nsWindow.cpp - Implemented GetAbsoluteBounds.
1999-07-14 22:00:24 +00:00
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* If the implementation of nsWindow supports borders this method MUST be overridden
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetBoundsAppUnits(nsRect &aRect, float aAppUnits)
|
|
|
|
{
|
|
|
|
aRect = mBounds;
|
|
|
|
// Convert to twips
|
|
|
|
aRect.x = nscoord((PRFloat64)aRect.x * aAppUnits);
|
|
|
|
aRect.y = nscoord((PRFloat64)aRect.y * aAppUnits);
|
|
|
|
aRect.width = nscoord((PRFloat64)aRect.width * aAppUnits);
|
|
|
|
aRect.height = nscoord((PRFloat64)aRect.height * aAppUnits);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetBounds(const nsRect &aRect)
|
|
|
|
{
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-28 01:31:41 +00:00
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
|
1998-11-04 21:43:47 +00:00
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Calculates the border width and height
|
|
|
|
*
|
|
|
|
**/
|
1998-11-04 21:43:47 +00:00
|
|
|
NS_METHOD nsBaseWidget::GetBorderSize(PRInt32 &aWidth, PRInt32 &aHeight)
|
|
|
|
{
|
|
|
|
nsRect rectWin;
|
1998-11-24 14:57:09 +00:00
|
|
|
nsRect rect;
|
1998-11-04 21:43:47 +00:00
|
|
|
GetBounds(rectWin);
|
1998-11-24 14:57:09 +00:00
|
|
|
GetClientBounds(rect);
|
1998-11-04 21:43:47 +00:00
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
aWidth = (rectWin.width - rect.width) / 2;
|
|
|
|
aHeight = (rectWin.height - rect.height) / 2;
|
1998-11-04 21:43:47 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-24 14:57:09 +00:00
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Calculates the border width and height
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
void nsBaseWidget::DrawScaledRect(nsIRenderingContext& aRenderingContext, const nsRect & aRect, float aScale, float aAppUnits)
|
|
|
|
{
|
|
|
|
nsRect rect = aRect;
|
|
|
|
|
|
|
|
float x = (float)rect.x;
|
|
|
|
float y = (float)rect.y;
|
|
|
|
float w = (float)rect.width;
|
|
|
|
float h = (float)rect.height;
|
|
|
|
float twoAppUnits = aAppUnits * 2.0f;
|
|
|
|
|
|
|
|
for (int i=0;i<int(aScale);i++) {
|
|
|
|
rect.x = nscoord(x);
|
|
|
|
rect.y = nscoord(y);
|
|
|
|
rect.width = nscoord(w);
|
|
|
|
rect.height = nscoord(h);
|
|
|
|
aRenderingContext.DrawRect(rect);
|
|
|
|
x += aAppUnits;
|
|
|
|
y += aAppUnits;
|
|
|
|
w -= twoAppUnits;
|
|
|
|
h -= twoAppUnits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Calculates the border width and height
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
void nsBaseWidget::DrawScaledLine(nsIRenderingContext& aRenderingContext,
|
|
|
|
nscoord aSX,
|
|
|
|
nscoord aSY,
|
|
|
|
nscoord aEX,
|
|
|
|
nscoord aEY,
|
|
|
|
float aScale,
|
|
|
|
float aAppUnits,
|
|
|
|
PRBool aIsHorz)
|
|
|
|
{
|
|
|
|
float sx = (float)aSX;
|
|
|
|
float sy = (float)aSY;
|
|
|
|
float ex = (float)aEX;
|
|
|
|
float ey = (float)aEY;
|
|
|
|
|
|
|
|
for (int i=0;i<int(aScale);i++) {
|
|
|
|
aSX = nscoord(sx);
|
|
|
|
aSY = nscoord(sy);
|
|
|
|
aEX = nscoord(ex);
|
|
|
|
aEY = nscoord(ey);
|
|
|
|
aRenderingContext.DrawLine(aSX, aSY, aEX, aEY);
|
|
|
|
if (aIsHorz) {
|
|
|
|
sy += aAppUnits;
|
|
|
|
ey += aAppUnits;
|
|
|
|
} else {
|
|
|
|
sx += aAppUnits;
|
|
|
|
ex += aAppUnits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
1998-12-03 21:46:27 +00:00
|
|
|
* Paints default border (XXX - this should be done by CSS)
|
|
|
|
*
|
|
|
|
**/
|
1998-11-24 14:57:09 +00:00
|
|
|
NS_METHOD nsBaseWidget::Paint(nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
float appUnits;
|
|
|
|
float scale;
|
|
|
|
nsIDeviceContext * context;
|
|
|
|
aRenderingContext.GetDeviceContext(context);
|
|
|
|
|
|
|
|
context->GetCanonicalPixelScale(scale);
|
|
|
|
context->GetDevUnitsToAppUnits(appUnits);
|
|
|
|
|
|
|
|
GetBoundsAppUnits(rect, appUnits);
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
|
|
|
|
|
|
|
DrawScaledRect(aRenderingContext, rect, scale, appUnits);
|
|
|
|
|
|
|
|
NS_RELEASE(context);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-23 01:17:20 +00:00
|
|
|
NS_IMETHODIMP nsBaseWidget::ScrollRect(nsRect &aRect, PRInt32 aDx, PRInt32 aDy)
|
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
#ifdef LOSER
|
1999-03-05 15:25:24 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetVerticalScrollbar(nsIWidget * aWidget)
|
|
|
|
{
|
1999-04-19 23:24:40 +00:00
|
|
|
NS_IF_RELEASE(mVScrollbar);
|
1999-03-05 15:25:24 +00:00
|
|
|
mVScrollbar = aWidget;
|
1999-04-19 23:24:40 +00:00
|
|
|
NS_IF_ADDREF(mVScrollbar);
|
1999-03-05 15:25:24 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-28 01:31:41 +00:00
|
|
|
#endif
|
1999-03-05 15:25:24 +00:00
|
|
|
|
1999-08-26 14:41:17 +00:00
|
|
|
NS_METHOD nsBaseWidget::EnableDragDrop(PRBool aEnable)
|
1999-03-09 23:47:47 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-12 23:46:30 +00:00
|
|
|
NS_METHOD nsBaseWidget::SetModal(PRBool aModal)
|
1999-06-13 20:56:08 +00:00
|
|
|
{
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-07-09 12:11:12 +00:00
|
|
|
|
1999-11-12 23:46:30 +00:00
|
|
|
// generic xp assumption is that events should be processed
|
|
|
|
NS_METHOD nsBaseWidget::ModalEventFilter(PRBool aRealEvent, void *aEvent,
|
|
|
|
PRBool *aForWindow)
|
|
|
|
{
|
|
|
|
*aForWindow = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-12-10 07:20:51 +00:00
|
|
|
NS_IMETHODIMP
|
1999-12-17 06:11:45 +00:00
|
|
|
nsBaseWidget::GetAttention() {
|
1999-12-10 07:20:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
//////////////////////////////////////////////////////////////
|
1999-07-09 12:11:12 +00:00
|
|
|
//
|
|
|
|
// Convert a GUI event message code to a string.
|
|
|
|
// Makes it a lot easier to debug events.
|
|
|
|
//
|
|
|
|
// See gtk/nsWidget.cpp and windows/nsWindow.cpp
|
|
|
|
// for a DebugPrintEvent() function that uses
|
|
|
|
// this.
|
|
|
|
//
|
1999-09-09 02:32:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ nsAutoString
|
|
|
|
nsBaseWidget::debug_GuiEventToString(nsGUIEvent * aGuiEvent)
|
1999-07-09 12:11:12 +00:00
|
|
|
{
|
1999-09-09 02:32:54 +00:00
|
|
|
NS_ASSERTION(nsnull != aGuiEvent,"cmon, null gui event.");
|
|
|
|
|
|
|
|
nsAutoString eventName = "UNKNOWN";
|
1999-07-09 12:11:12 +00:00
|
|
|
|
|
|
|
#define _ASSIGN_eventName(_value,_name)\
|
1999-07-09 12:15:12 +00:00
|
|
|
case _value: eventName = _name ; break
|
1999-07-09 12:11:12 +00:00
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
switch(aGuiEvent->message)
|
1999-07-09 12:11:12 +00:00
|
|
|
{
|
|
|
|
_ASSIGN_eventName(NS_BLUR_CONTENT,"NS_BLUR_CONTENT");
|
|
|
|
_ASSIGN_eventName(NS_CONTROL_CHANGE,"NS_CONTROL_CHANGE");
|
|
|
|
_ASSIGN_eventName(NS_CREATE,"NS_CREATE");
|
|
|
|
_ASSIGN_eventName(NS_DESTROY,"NS_DESTROY");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_GESTURE,"NS_DND_GESTURE");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_DROP,"NS_DND_DROP");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_ENTER,"NS_DND_ENTER");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_EXIT,"NS_DND_EXIT");
|
|
|
|
_ASSIGN_eventName(NS_DRAGDROP_OVER,"NS_DND_OVER");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FOCUS_CONTENT,"NS_FOCUS_CONTENT");
|
1999-08-07 23:18:35 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_SELECTED,"NS_FORM_SELECTED");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_CHANGE,"NS_FORM_CHANGE");
|
1999-09-21 23:02:35 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_INPUT,"NS_FORM_INPUT");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_FORM_RESET,"NS_FORM_RESET");
|
|
|
|
_ASSIGN_eventName(NS_FORM_SUBMIT,"NS_FORM_SUBMIT");
|
|
|
|
_ASSIGN_eventName(NS_GOTFOCUS,"NS_GOTFOCUS");
|
|
|
|
_ASSIGN_eventName(NS_IMAGE_ABORT,"NS_IMAGE_ABORT");
|
|
|
|
_ASSIGN_eventName(NS_IMAGE_ERROR,"NS_IMAGE_ERROR");
|
|
|
|
_ASSIGN_eventName(NS_IMAGE_LOAD,"NS_IMAGE_LOAD");
|
|
|
|
_ASSIGN_eventName(NS_KEY_DOWN,"NS_KEY_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_KEY_PRESS,"NS_KEY_PRESS");
|
|
|
|
_ASSIGN_eventName(NS_KEY_UP,"NS_KEY_UP");
|
|
|
|
_ASSIGN_eventName(NS_LOSTFOCUS,"NS_LOSTFOCUS");
|
|
|
|
_ASSIGN_eventName(NS_MENU_SELECTED,"NS_MENU_SELECTED");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_ENTER,"NS_MOUSE_ENTER");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_EXIT,"NS_MOUSE_EXIT");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_LEFT_BUTTON_DOWN,"NS_MOUSE_LEFT_BTN_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_LEFT_BUTTON_UP,"NS_MOUSE_LEFT_BTN_UP");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_LEFT_CLICK,"NS_MOUSE_LEFT_CLICK");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_LEFT_DOUBLECLICK,"NS_MOUSE_LEFT_DBLCLICK");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_MIDDLE_BUTTON_DOWN,"NS_MOUSE_MIDDLE_BTN_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_MIDDLE_BUTTON_UP,"NS_MOUSE_MIDDLE_BTN_UP");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_MIDDLE_CLICK,"NS_MOUSE_MIDDLE_CLICK");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_MIDDLE_DOUBLECLICK,"NS_MOUSE_MIDDLE_DBLCLICK");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_MOVE,"NS_MOUSE_MOVE");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_RIGHT_BUTTON_DOWN,"NS_MOUSE_RIGHT_BTN_DOWN");
|
|
|
|
_ASSIGN_eventName(NS_MOUSE_RIGHT_BUTTON_UP,"NS_MOUSE_RIGHT_BTN_UP");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_RIGHT_CLICK,"NS_MOUSE_RIGHT_CLICK");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_MOUSE_RIGHT_DOUBLECLICK,"NS_MOUSE_RIGHT_DBLCLICK");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_MOVE,"NS_MOVE");
|
|
|
|
_ASSIGN_eventName(NS_PAGE_LOAD,"NS_PAGE_LOAD");
|
|
|
|
_ASSIGN_eventName(NS_PAGE_UNLOAD,"NS_PAGE_UNLOAD");
|
|
|
|
_ASSIGN_eventName(NS_PAINT,"NS_PAINT");
|
1999-07-26 09:19:18 +00:00
|
|
|
_ASSIGN_eventName(NS_MENU_CREATE,"NS_MENU_CREATE");
|
|
|
|
_ASSIGN_eventName(NS_MENU_DESTROY,"NS_MENU_DESTROY");
|
|
|
|
_ASSIGN_eventName(NS_MENU_ACTION, "NS_MENU_ACTION");
|
1999-09-21 23:02:35 +00:00
|
|
|
_ASSIGN_eventName(NS_XUL_BROADCAST, "NS_XUL_BROADCAST");
|
|
|
|
_ASSIGN_eventName(NS_XUL_COMMAND_UPDATE, "NS_XUL_COMMAND_UPDATE");
|
1999-09-09 02:32:54 +00:00
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_LINE_NEXT,"NS_SB_LINE_NEXT");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_LINE_PREV,"NS_SB_LINE_PREV");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_PAGE_NEXT,"NS_SB_PAGE_NEXT");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_PAGE_PREV,"NS_SB_PAGE_PREV");
|
|
|
|
_ASSIGN_eventName(NS_SCROLLBAR_POS,"NS_SB_POS");
|
1999-07-09 12:11:12 +00:00
|
|
|
_ASSIGN_eventName(NS_SIZE,"NS_SIZE");
|
|
|
|
|
|
|
|
#undef _ASSIGN_eventName
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
1999-09-09 02:32:54 +00:00
|
|
|
sprintf(buf,"UNKNOWN: %d",aGuiEvent->message);
|
1999-07-09 12:11:12 +00:00
|
|
|
|
|
|
|
eventName = buf;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-07-09 12:11:12 +00:00
|
|
|
return nsAutoString(eventName);
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
//
|
1999-12-03 07:23:22 +00:00
|
|
|
// Code to deal with paint and event debug prefs.
|
1999-09-09 02:32:54 +00:00
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
1999-12-03 07:23:22 +00:00
|
|
|
struct PrefPair
|
|
|
|
{
|
|
|
|
char * name;
|
|
|
|
PRBool value;
|
|
|
|
};
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
static PrefPair debug_PrefValues[] =
|
|
|
|
{
|
|
|
|
{ "nglayout.debug.crossing_event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.invalidate_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.motion_event_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.paint_dumping", PR_FALSE },
|
|
|
|
{ "nglayout.debug.paint_flashing", PR_FALSE }
|
|
|
|
};
|
|
|
|
|
|
|
|
static PRUint32 debug_NumPrefValues =
|
|
|
|
(sizeof(debug_PrefValues) / sizeof(debug_PrefValues[0]));
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
static PRBool debug_GetBoolPref(nsIPref * aPrefs,const char * aPrefName)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
|
|
|
NS_ASSERTION(nsnull != aPrefs,"cmon, prefs are null.");
|
|
|
|
|
|
|
|
PRBool value = PR_FALSE;
|
|
|
|
|
|
|
|
if (aPrefs)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
aPrefs->GetBoolPref(aPrefName,&value);
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
return value;
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
1999-12-03 07:23:22 +00:00
|
|
|
static PRBool debug_GetCachedBoolPref(const char * aPrefName)
|
1999-09-09 02:32:54 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
|
|
|
if (nsAutoString(debug_PrefValues[i].name) == aPrefName)
|
|
|
|
{
|
|
|
|
return debug_PrefValues[i].value;
|
|
|
|
}
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
static void debug_SetCachedBoolPref(const char * aPrefName,PRBool aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aPrefName,"cmon, pref name is null.");
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
|
|
|
if (nsAutoString(debug_PrefValues[i].name) == aPrefName)
|
|
|
|
{
|
|
|
|
debug_PrefValues[i].value = aValue;
|
1999-09-09 02:32:54 +00:00
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(PR_FALSE, "cmon, this code is not reached dude.");
|
|
|
|
}
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ int
|
|
|
|
debug_PrefChangedCallback(const char * name,void * closure)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsIPref * prefs = nsnull;
|
|
|
|
|
|
|
|
nsresult rv = nsServiceManager::GetService(kPrefCID,
|
|
|
|
NS_GET_IID(nsIPref),
|
|
|
|
(nsISupports**) &prefs);
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service.");
|
|
|
|
NS_ASSERTION(nsnull != prefs,"Prefs services is null.");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
PRBool value = PR_FALSE;
|
|
|
|
|
|
|
|
prefs->GetBoolPref(name,&value);
|
|
|
|
|
|
|
|
debug_SetCachedBoolPref(name,value);
|
|
|
|
|
|
|
|
NS_RELEASE(prefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PREF_NOERROR;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
debug_RegisterPrefCallbacks()
|
|
|
|
{
|
|
|
|
static PRBool once = PR_TRUE;
|
|
|
|
|
|
|
|
if (once)
|
|
|
|
{
|
|
|
|
once = PR_FALSE;
|
|
|
|
|
|
|
|
nsIPref * prefs = nsnull;
|
|
|
|
|
|
|
|
nsresult rv = nsServiceManager::GetService(kPrefCID,
|
|
|
|
NS_GET_IID(nsIPref),
|
|
|
|
(nsISupports**) &prefs);
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv),"Could not get prefs service.");
|
|
|
|
NS_ASSERTION(nsnull != prefs,"Prefs services is null.");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < debug_NumPrefValues; i++)
|
|
|
|
{
|
|
|
|
// Initialize the pref values
|
|
|
|
debug_PrefValues[i].value =
|
|
|
|
debug_GetBoolPref(prefs,debug_PrefValues[i].name);
|
|
|
|
|
|
|
|
// Register callbacks for when these change
|
|
|
|
prefs->RegisterCallback(debug_PrefValues[i].name,
|
|
|
|
debug_PrefChangedCallback,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(prefs);
|
|
|
|
}
|
|
|
|
}
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
static PRInt32
|
|
|
|
_GetPrintCount()
|
|
|
|
{
|
|
|
|
static PRInt32 sCount = 0;
|
|
|
|
|
|
|
|
return ++sCount;
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ PRBool
|
|
|
|
nsBaseWidget::debug_WantPaintFlashing()
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
return debug_GetCachedBoolPref("nglayout.debug.paint_flashing");
|
1999-09-09 02:32:54 +00:00
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
|
|
|
nsGUIEvent * aGuiEvent,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
|
|
|
// NS_PAINT is handled by debug_DumpPaintEvent()
|
|
|
|
if (aGuiEvent->message == NS_PAINT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_MOVE)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.motion_event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aGuiEvent->message == NS_MOUSE_ENTER ||
|
|
|
|
aGuiEvent->message == NS_MOUSE_EXIT)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.crossing_event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.event_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%4d %-26s widget=%-8p name=%-12s id=%-8p pos=%d,%d\n",
|
|
|
|
_GetPrintCount(),
|
|
|
|
(const char *) nsCAutoString(debug_GuiEventToString(aGuiEvent)),
|
|
|
|
(void *) aWidget,
|
|
|
|
(const char *) aWidgetName,
|
|
|
|
(void *) (aWindowID ? aWindowID : 0x0),
|
|
|
|
aGuiEvent->point.x,
|
|
|
|
aGuiEvent->point.y);
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpPaintEvent(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
|
|
|
nsPaintEvent * aPaintEvent,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(nsnull != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nsnull != aWidget,"cmon, the widget is null");
|
|
|
|
NS_ASSERTION(nsnull != aPaintEvent,"cmon, the paint event is null");
|
|
|
|
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.paint_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%4d PAINT widget=%p name=%-12s id=%-8p rect=",
|
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
|
|
|
(const char *) aWidgetName,
|
|
|
|
(void *) aWindowID);
|
|
|
|
|
|
|
|
if (aPaintEvent->rect)
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%3d,%-3d %3d,%-3d",
|
|
|
|
aPaintEvent->rect->x,
|
|
|
|
aPaintEvent->rect->y,
|
|
|
|
aPaintEvent->rect->width,
|
|
|
|
aPaintEvent->rect->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,"none");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* static */ void
|
|
|
|
nsBaseWidget::debug_DumpInvalidate(FILE * aFileOut,
|
|
|
|
nsIWidget * aWidget,
|
|
|
|
const nsRect * aRect,
|
|
|
|
PRBool aIsSynchronous,
|
|
|
|
const nsCAutoString & aWidgetName,
|
|
|
|
PRInt32 aWindowID)
|
|
|
|
{
|
1999-12-03 07:23:22 +00:00
|
|
|
if (!debug_GetCachedBoolPref("nglayout.debug.invalidate_dumping"))
|
1999-09-09 02:32:54 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
NS_ASSERTION(nsnull != aFileOut,"cmon, null output FILE");
|
|
|
|
NS_ASSERTION(nsnull != aWidget,"cmon, the widget is null");
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
"%4d Invalidate widget=%p name=%-12s id=%-8p",
|
|
|
|
_GetPrintCount(),
|
|
|
|
(void *) aWidget,
|
|
|
|
(const char *) aWidgetName,
|
|
|
|
(void *) aWindowID);
|
|
|
|
|
|
|
|
if (aRect)
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%3d,%-3d %3d,%-3d",
|
|
|
|
aRect->x,
|
|
|
|
aRect->y,
|
|
|
|
aRect->width,
|
|
|
|
aRect->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" rect=%-15s",
|
|
|
|
"none");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(aFileOut,
|
|
|
|
" sync=%s",
|
|
|
|
(const char *) (aIsSynchronous ? "yes" : "no "));
|
|
|
|
|
|
|
|
fprintf(aFileOut,"\n");
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#endif // NS_DEBUG
|
|
|
|
|
1999-09-28 01:31:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Constructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsBaseWidget::Enumerator::Enumerator(nsBaseWidget & inParent)
|
|
|
|
: mCurrentPosition(0), mParent(inParent)
|
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destructor
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
nsBaseWidget::Enumerator::~Enumerator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//enumerator interfaces
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::Next()
|
|
|
|
{
|
|
|
|
PRUint32 itemCount = 0;
|
|
|
|
mParent.mChildren->Count(&itemCount);
|
|
|
|
if (mCurrentPosition < itemCount - 1 )
|
|
|
|
mCurrentPosition ++;
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::Prev()
|
|
|
|
{
|
|
|
|
if (mCurrentPosition > 0 )
|
|
|
|
mCurrentPosition --;
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::CurrentItem(nsISupports **aItem)
|
|
|
|
{
|
|
|
|
if (!aItem)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
PRUint32 itemCount = 0;
|
|
|
|
mParent.mChildren->Count(&itemCount);
|
|
|
|
if ( mCurrentPosition < itemCount ) {
|
|
|
|
nsISupports* widget = mParent.mChildren->ElementAt(mCurrentPosition);
|
|
|
|
// NS_IF_ADDREF(widget); already addref'd in nsSupportsArray::ElementAt()
|
|
|
|
*aItem = widget;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::First()
|
|
|
|
{
|
|
|
|
PRUint32 itemCount = 0;
|
|
|
|
mParent.mChildren->Count(&itemCount);
|
|
|
|
if ( itemCount ) {
|
|
|
|
mCurrentPosition = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::Last()
|
|
|
|
{
|
|
|
|
PRUint32 itemCount = 0;
|
|
|
|
mParent.mChildren->Count(&itemCount);
|
|
|
|
if ( itemCount ) {
|
|
|
|
mCurrentPosition = itemCount - 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseWidget::Enumerator::IsDone()
|
|
|
|
{
|
|
|
|
PRUint32 itemCount = 0;
|
|
|
|
mParent.mChildren->Count(&itemCount);
|
|
|
|
|
|
|
|
if ((mCurrentPosition == itemCount-1) || (itemCount == 0) ){ //empty lists always return done
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else {
|
1999-10-28 03:16:48 +00:00
|
|
|
return NS_ENUMERATOR_FALSE;
|
1999-09-28 01:31:41 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|