1998-04-13 20:24:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file arhandlee subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsView.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIButton.h"
|
|
|
|
#include "nsIScrollbar.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsRepository.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsTransform2D.h"
|
1998-04-23 21:51:43 +00:00
|
|
|
#include "nsIScrollableView.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIViewIID, NS_IVIEW_IID);
|
1998-07-26 04:24:42 +00:00
|
|
|
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-11 06:17:09 +00:00
|
|
|
//#define SHOW_VIEW_BORDERS
|
1998-06-16 17:05:42 +00:00
|
|
|
//#define HIDE_ALL_WIDGETS
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//
|
|
|
|
// Main events handler
|
|
|
|
//
|
|
|
|
nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent)
|
|
|
|
{
|
1998-05-29 22:44:13 +00:00
|
|
|
//printf(" %d %d %d (%d,%d) \n", aEvent->widget, aEvent->widgetSupports,
|
|
|
|
// aEvent->message, aEvent->point.x, aEvent->point.y);
|
1998-08-08 04:23:33 +00:00
|
|
|
nsIView* view = nsView::GetViewFor(aEvent->widget);
|
|
|
|
nsEventStatus result = nsEventStatus_eIgnore;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-08 04:23:33 +00:00
|
|
|
if (nsnull != view)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
switch(aEvent->message)
|
|
|
|
{
|
|
|
|
case NS_SIZE:
|
|
|
|
{
|
|
|
|
nscoord width = ((nsSizeEvent*)aEvent)->windowSize->width;
|
|
|
|
nscoord height = ((nsSizeEvent*)aEvent)->windowSize->height;
|
|
|
|
|
|
|
|
// Inform the view manager that the root window has been resized
|
|
|
|
nsIViewManager* vm = view->GetViewManager();
|
|
|
|
nsIPresContext* presContext = vm->GetPresContext();
|
|
|
|
|
|
|
|
// The root view may not be set if this is the resize associated with
|
|
|
|
// window creation
|
|
|
|
|
|
|
|
nsIView* rootView = vm->GetRootView();
|
|
|
|
|
|
|
|
if (view == rootView)
|
|
|
|
{
|
|
|
|
// Convert from pixels to twips
|
|
|
|
float p2t = presContext->GetPixelsToTwips();
|
1998-07-26 04:24:42 +00:00
|
|
|
nsIScrollableView *scrollView;
|
|
|
|
|
|
|
|
//XXX hey look, a hack! :) i'm not proud of it, but it does
|
|
|
|
//work. the purpose is to prevent resizes of the view if the
|
|
|
|
//clip size (assumed to be the size of this window) is the same
|
|
|
|
//as the new size we get here. MMP
|
|
|
|
|
|
|
|
if (NS_OK == rootView->QueryInterface(kIScrollableViewIID, (void **)&scrollView))
|
|
|
|
{
|
|
|
|
nscoord sizex, sizey;
|
|
|
|
float t2p = presContext->GetTwipsToPixels();
|
|
|
|
|
|
|
|
scrollView->GetClipSize(&sizex, &sizey);
|
|
|
|
|
1998-07-31 23:34:45 +00:00
|
|
|
if ((width == NSTwipsToIntPixels(sizex, t2p)) &&
|
|
|
|
(height == NSTwipsToIntPixels(sizey, t2p)))
|
1998-07-26 04:24:42 +00:00
|
|
|
{
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-07-31 23:34:45 +00:00
|
|
|
vm->SetWindowDimensions(NSIntPixelsToTwips(width, p2t),
|
|
|
|
NSIntPixelsToTwips(height, p2t));
|
1998-04-13 20:24:54 +00:00
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(presContext);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_PAINT:
|
|
|
|
{
|
|
|
|
nsIViewManager *vm = view->GetViewManager();
|
|
|
|
nsIPresContext *px = vm->GetPresContext();
|
|
|
|
float convert = px->GetPixelsToTwips();
|
1998-07-24 21:49:02 +00:00
|
|
|
nsRect trect = *((nsPaintEvent*)aEvent)->rect;
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIDeviceContext *dx = px->GetDeviceContext();
|
|
|
|
|
1998-06-03 03:12:52 +00:00
|
|
|
trect *= convert;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-19 17:44:03 +00:00
|
|
|
//printf("damage repair...\n");
|
|
|
|
|
1998-06-19 02:46:25 +00:00
|
|
|
vm->UpdateView(view, trect,
|
1998-07-24 21:05:50 +00:00
|
|
|
NS_VMREFRESH_SCREEN_RECT |
|
|
|
|
NS_VMREFRESH_IMMEDIATE |
|
1998-07-24 21:49:02 +00:00
|
|
|
NS_VMREFRESH_AUTO_DOUBLE_BUFFER);
|
1998-06-19 17:44:03 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_RELEASE(dx);
|
|
|
|
NS_RELEASE(px);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_DESTROY:
|
|
|
|
result = nsEventStatus_eConsumeNoDefault;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
nsIViewManager *vm = view->GetViewManager();
|
|
|
|
nsIPresContext *cx = vm->GetPresContext();
|
|
|
|
|
|
|
|
// pass on to view somewhere else to deal with
|
|
|
|
|
1998-07-31 23:34:45 +00:00
|
|
|
aEvent->point.x = NSIntPixelsToTwips(aEvent->point.x, cx->GetPixelsToTwips());
|
|
|
|
aEvent->point.y = NSIntPixelsToTwips(aEvent->point.y, cx->GetPixelsToTwips());
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-29 22:44:13 +00:00
|
|
|
result = view->HandleEvent(aEvent, NS_VIEW_FLAG_CHECK_CHILDREN |
|
|
|
|
NS_VIEW_FLAG_CHECK_PARENT |
|
|
|
|
NS_VIEW_FLAG_CHECK_SIBLINGS);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-07-31 23:34:45 +00:00
|
|
|
aEvent->point.x = NSTwipsToIntPixels(aEvent->point.x, cx->GetTwipsToPixels());
|
|
|
|
aEvent->point.y = NSTwipsToIntPixels(aEvent->point.y, cx->GetTwipsToPixels());
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsView :: nsView()
|
|
|
|
{
|
|
|
|
mVis = nsViewVisibility_kShow;
|
1998-04-28 19:16:24 +00:00
|
|
|
mXForm = nsnull;
|
1998-06-03 22:49:45 +00:00
|
|
|
mVFlags = ~ALL_VIEW_FLAGS;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsView :: ~nsView()
|
|
|
|
{
|
1998-06-03 22:49:45 +00:00
|
|
|
mVFlags |= VIEW_FLAG_DYING;
|
1998-06-01 22:02:02 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
if (GetChildCount() > 0)
|
|
|
|
{
|
|
|
|
nsIView *kid;
|
|
|
|
|
|
|
|
//nuke the kids
|
|
|
|
|
|
|
|
while (kid = GetChild(0))
|
|
|
|
kid->Destroy();
|
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
if (mXForm != nsnull)
|
|
|
|
{
|
|
|
|
delete mXForm;
|
|
|
|
mXForm = nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
if (nsnull != mViewManager)
|
|
|
|
{
|
|
|
|
nsIView *rootView = mViewManager->GetRootView();
|
1998-05-01 03:13:34 +00:00
|
|
|
|
|
|
|
if (nsnull != rootView)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-01 03:13:34 +00:00
|
|
|
if (rootView == this)
|
|
|
|
{
|
1998-08-08 04:23:33 +00:00
|
|
|
// Inform the view manager that the root view has gone away...
|
|
|
|
mViewManager->SetRootView(nsnull);
|
1998-05-01 03:13:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (nsnull != mParent)
|
1998-08-08 04:23:33 +00:00
|
|
|
{
|
1998-05-01 03:13:34 +00:00
|
|
|
mViewManager->RemoveChild(mParent, this);
|
1998-08-08 04:23:33 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-08 04:23:33 +00:00
|
|
|
}
|
1998-05-01 03:13:34 +00:00
|
|
|
else if (nsnull != mParent)
|
1998-08-08 04:23:33 +00:00
|
|
|
{
|
1998-05-01 03:13:34 +00:00
|
|
|
mParent->RemoveChild(this);
|
1998-08-08 04:23:33 +00:00
|
|
|
}
|
1998-05-01 03:13:34 +00:00
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
mViewManager = nsnull;
|
|
|
|
}
|
1998-05-01 03:13:34 +00:00
|
|
|
else if (nsnull != mParent)
|
1998-08-08 04:23:33 +00:00
|
|
|
{
|
1998-05-01 03:13:34 +00:00
|
|
|
mParent->RemoveChild(this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-08-08 04:23:33 +00:00
|
|
|
|
|
|
|
// Destroy and release the widget
|
|
|
|
if (nsnull != mWindow) {
|
|
|
|
mWindow->SetClientData(nsnull);
|
|
|
|
mWindow->Destroy();
|
|
|
|
NS_RELEASE(mWindow);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsView :: QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (nsnull == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
static NS_DEFINE_IID(kClassIID, kIViewIID);
|
|
|
|
|
|
|
|
if (aIID.Equals(kClassIID) || (aIID.Equals(kISupportsIID))) {
|
|
|
|
*aInstancePtr = (void*)(nsIView*)this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsView::AddRef()
|
|
|
|
{
|
1998-08-08 04:23:33 +00:00
|
|
|
NS_WARNING("not supported for views");
|
|
|
|
return 1;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt nsView::Release()
|
|
|
|
{
|
1998-08-08 04:23:33 +00:00
|
|
|
NS_WARNING("not supported for views");
|
|
|
|
return 1;
|
|
|
|
}
|
1998-05-01 03:13:34 +00:00
|
|
|
|
1998-08-08 04:23:33 +00:00
|
|
|
nsIView* nsView::GetViewFor(nsIWidget* aWidget)
|
|
|
|
{
|
|
|
|
nsIView* view = nsnull;
|
|
|
|
void* clientData;
|
1998-06-01 22:02:02 +00:00
|
|
|
|
1998-08-08 04:23:33 +00:00
|
|
|
// The widget's client data points back to the owning view
|
|
|
|
if (NS_SUCCEEDED(aWidget->GetClientData(clientData))) {
|
|
|
|
view = (nsIView*)clientData;
|
1998-05-01 03:13:34 +00:00
|
|
|
|
1998-08-13 00:03:41 +00:00
|
|
|
if (nsnull != view) {
|
1998-08-08 04:23:33 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-08-13 00:03:41 +00:00
|
|
|
// Verify the pointer is really a view
|
|
|
|
nsView* widgetView;
|
|
|
|
NS_ASSERTION((NS_SUCCEEDED(view->QueryInterface(kIViewIID, (void **)&widgetView))) &&
|
|
|
|
(widgetView == view), "bad client data");
|
1998-08-08 04:23:33 +00:00
|
|
|
#endif
|
1998-08-13 00:03:41 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-01 22:02:02 +00:00
|
|
|
|
1998-08-08 04:23:33 +00:00
|
|
|
return view;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsView :: Init(nsIViewManager* aManager,
|
|
|
|
const nsRect &aBounds,
|
|
|
|
nsIView *aParent,
|
|
|
|
const nsCID *aWindowCIID,
|
1998-05-14 21:34:08 +00:00
|
|
|
nsWidgetInitData *aWidgetInitData,
|
1998-06-25 04:24:45 +00:00
|
|
|
nsNativeWidget aNative,
|
1998-04-13 20:24:54 +00:00
|
|
|
PRInt32 aZIndex,
|
1998-04-29 02:24:07 +00:00
|
|
|
const nsViewClip *aClip,
|
1998-04-13 20:24:54 +00:00
|
|
|
float aOpacity,
|
|
|
|
nsViewVisibility aVisibilityFlag)
|
|
|
|
{
|
1998-04-24 21:37:30 +00:00
|
|
|
//printf(" \n callback=%d data=%d", aWidgetCreateCallback, aCallbackData);
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_PRECONDITION(nsnull != aManager, "null ptr");
|
|
|
|
if (nsnull == aManager) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (nsnull != mViewManager) {
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
1998-08-08 04:23:33 +00:00
|
|
|
// we don't hold a reference to the view manager
|
1998-04-13 20:24:54 +00:00
|
|
|
mViewManager = aManager;
|
|
|
|
|
1998-04-29 02:24:07 +00:00
|
|
|
if (aClip != nsnull)
|
|
|
|
mClip = *aClip;
|
1998-04-28 19:16:24 +00:00
|
|
|
else
|
1998-04-29 02:24:07 +00:00
|
|
|
{
|
|
|
|
mClip.mLeft = 0;
|
|
|
|
mClip.mRight = 0;
|
|
|
|
mClip.mTop = 0;
|
|
|
|
mClip.mBottom = 0;
|
|
|
|
}
|
1998-04-28 19:16:24 +00:00
|
|
|
|
|
|
|
mOpacity = aOpacity;
|
|
|
|
mZindex = aZIndex;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
// assign the parent view
|
|
|
|
SetParent(aParent);
|
|
|
|
|
1998-07-07 21:51:57 +00:00
|
|
|
SetBounds(aBounds);
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
// check if a real window has to be created
|
|
|
|
if (aWindowCIID)
|
|
|
|
{
|
|
|
|
nsIPresContext *cx = mViewManager->GetPresContext();
|
|
|
|
nsIDeviceContext *dx = cx->GetDeviceContext();
|
|
|
|
nsRect trect = aBounds;
|
|
|
|
|
|
|
|
trect *= cx->GetTwipsToPixels();
|
|
|
|
|
|
|
|
if (NS_OK == LoadWidget(*aWindowCIID))
|
|
|
|
{
|
|
|
|
if (aNative)
|
1998-07-29 18:47:50 +00:00
|
|
|
mWindow->Create(aNative, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
|
1998-04-13 20:24:54 +00:00
|
|
|
else
|
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
nsIWidget *parent = GetOffsetFromWidget(nsnull, nsnull);
|
1998-07-29 18:47:50 +00:00
|
|
|
mWindow->Create(parent, trect, ::HandleEvent, dx, nsnull, nsnull, aWidgetInitData);
|
1998-04-13 20:24:54 +00:00
|
|
|
NS_IF_RELEASE(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(dx);
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetVisibility(aVisibilityFlag);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: Destroy()
|
|
|
|
{
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIViewManager * nsView :: GetViewManager()
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mViewManager);
|
|
|
|
return mViewManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget * nsView :: GetWidget()
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mWindow);
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
PRBool nsView :: Paint(nsIRenderingContext& rc, const nsRect& rect,
|
|
|
|
PRUint32 aPaintFlags, nsIView *aBackstop)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-27 02:13:28 +00:00
|
|
|
nsIView *pRoot = mViewManager->GetRootView();
|
1998-06-03 21:30:51 +00:00
|
|
|
PRBool clipres = PR_FALSE;
|
1998-06-16 17:05:42 +00:00
|
|
|
PRBool clipwasset = PR_FALSE;
|
1998-05-27 02:13:28 +00:00
|
|
|
|
1998-04-27 23:51:57 +00:00
|
|
|
rc.PushState();
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
if (aPaintFlags & NS_VIEW_FLAG_CLIP_SET)
|
|
|
|
{
|
|
|
|
clipwasset = PR_TRUE;
|
|
|
|
aPaintFlags &= ~NS_VIEW_FLAG_CLIP_SET;
|
|
|
|
}
|
|
|
|
else if (mVis == nsViewVisibility_kShow)
|
1998-04-27 23:51:57 +00:00
|
|
|
{
|
1998-07-07 21:51:57 +00:00
|
|
|
nsRect brect;
|
|
|
|
|
|
|
|
GetBounds(brect);
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
if ((mClip.mLeft != mClip.mRight) && (mClip.mTop != mClip.mBottom))
|
|
|
|
{
|
|
|
|
nsRect crect;
|
|
|
|
|
1998-07-07 21:51:57 +00:00
|
|
|
crect.x = mClip.mLeft + brect.x;
|
|
|
|
crect.y = mClip.mTop + brect.y;
|
1998-06-16 17:05:42 +00:00
|
|
|
crect.width = mClip.mRight - mClip.mLeft;
|
|
|
|
crect.height = mClip.mBottom - mClip.mTop;
|
1998-04-29 02:24:07 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
clipres = rc.SetClipRect(crect, nsClipCombine_kIntersect);
|
|
|
|
}
|
|
|
|
else if (this != pRoot)
|
1998-07-07 21:51:57 +00:00
|
|
|
clipres = rc.SetClipRect(brect, nsClipCombine_kIntersect);
|
1998-06-16 17:05:42 +00:00
|
|
|
}
|
1998-04-29 02:24:07 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
if (nsnull != mXForm)
|
|
|
|
{
|
|
|
|
nsTransform2D *pXForm = rc.GetCurrentTransform();
|
|
|
|
pXForm->Concatenate(mXForm);
|
1998-04-27 23:51:57 +00:00
|
|
|
}
|
1998-04-28 02:05:46 +00:00
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
if (clipres == PR_FALSE)
|
1998-04-28 19:16:24 +00:00
|
|
|
{
|
1998-07-07 21:51:57 +00:00
|
|
|
nscoord posx, posy;
|
|
|
|
|
|
|
|
GetPosition(&posx, &posy);
|
|
|
|
|
|
|
|
rc.Translate(posx, posy);
|
1998-04-28 19:16:24 +00:00
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
PRInt32 numkids = GetChildCount();
|
1998-04-27 23:51:57 +00:00
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
for (PRInt32 cnt = 0; cnt < numkids; cnt++)
|
1998-04-27 23:51:57 +00:00
|
|
|
{
|
1998-06-03 21:30:51 +00:00
|
|
|
nsIView *kid = GetChild(cnt);
|
1998-04-27 23:51:57 +00:00
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
if (nsnull != kid)
|
1998-04-27 23:51:57 +00:00
|
|
|
{
|
1998-06-03 21:30:51 +00:00
|
|
|
nsRect kidRect;
|
|
|
|
kid->GetBounds(kidRect);
|
|
|
|
nsRect damageArea;
|
|
|
|
PRBool overlap = damageArea.IntersectRect(rect, kidRect);
|
|
|
|
|
|
|
|
if (overlap == PR_TRUE)
|
|
|
|
{
|
|
|
|
// Translate damage area into kid's coordinate system
|
|
|
|
nsRect kidDamageArea(damageArea.x - kidRect.x, damageArea.y - kidRect.y,
|
|
|
|
damageArea.width, damageArea.height);
|
|
|
|
clipres = kid->Paint(rc, kidDamageArea, aPaintFlags);
|
|
|
|
|
|
|
|
if (clipres == PR_TRUE)
|
|
|
|
break;
|
|
|
|
}
|
1998-04-27 23:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
if ((clipres == PR_FALSE) && (mVis == nsViewVisibility_kShow))
|
1998-06-03 21:30:51 +00:00
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
float opacity = GetOpacity();
|
|
|
|
|
|
|
|
if (opacity > 0.0f)
|
|
|
|
{
|
|
|
|
rc.PushState();
|
|
|
|
|
|
|
|
if (HasTransparency() || (opacity < 1.0f))
|
|
|
|
{
|
1998-06-25 04:24:45 +00:00
|
|
|
//overview of algorithm:
|
|
|
|
//1. clip is set to intersection of this view and whatever is
|
|
|
|
// left of the damage region in the rc.
|
|
|
|
//2. walk tree from this point down through the view list,
|
|
|
|
// rendering and clipping out opaque views encountered until
|
|
|
|
// there is nothing left in the clip area or the bottommost
|
|
|
|
// view is reached.
|
|
|
|
//3. walk back up through view list restoring clips and painting
|
|
|
|
// or blending any non-opaque views encountered until we reach the
|
|
|
|
// view that started the whole process
|
1998-06-16 17:05:42 +00:00
|
|
|
|
|
|
|
//walk down rendering only views within this clip
|
|
|
|
|
1998-06-25 04:24:45 +00:00
|
|
|
nsIView *child = GetNextSibling(), *prevchild = this;
|
|
|
|
|
|
|
|
while (nsnull != child)
|
|
|
|
{
|
|
|
|
nsRect kidRect;
|
|
|
|
child->GetBounds(kidRect);
|
|
|
|
nsRect damageArea;
|
|
|
|
PRBool overlap = damageArea.IntersectRect(rect, kidRect);
|
|
|
|
|
|
|
|
//as we tell each kid to paint, we need to mark the kid as one that was hit
|
|
|
|
//in the front to back rendering so that when we do the back to front pass,
|
|
|
|
//we can re-add the child's rect back into the clip.
|
|
|
|
|
|
|
|
if (overlap == PR_TRUE)
|
|
|
|
{
|
|
|
|
// Translate damage area into kid's coordinate system
|
|
|
|
nsRect kidDamageArea(damageArea.x - kidRect.x, damageArea.y - kidRect.y,
|
|
|
|
damageArea.width, damageArea.height);
|
|
|
|
clipres = child->Paint(rc, kidDamageArea, aPaintFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
prevchild = child;
|
|
|
|
|
|
|
|
child = child->GetNextSibling();
|
|
|
|
|
|
|
|
if (nsnull == child)
|
|
|
|
child = child->GetParent();
|
|
|
|
|
|
|
|
if (clipres == PR_TRUE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != prevchild) && (this != prevchild))
|
|
|
|
{
|
|
|
|
//walk backwards, rendering views
|
|
|
|
}
|
1998-06-16 17:05:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != mFrame)
|
|
|
|
{
|
|
|
|
nsIPresContext *cx = mViewManager->GetPresContext();
|
|
|
|
mFrame->Paint(*cx, rc, rect);
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SHOW_VIEW_BORDERS
|
|
|
|
{
|
|
|
|
nscoord x, y, w, h;
|
|
|
|
|
|
|
|
if ((mClip.mLeft != mClip.mRight) && (mClip.mTop != mClip.mBottom))
|
|
|
|
{
|
|
|
|
x = mClip.mLeft;
|
|
|
|
y = mClip.mTop;
|
|
|
|
w = mClip.mRight - mClip.mLeft;
|
|
|
|
h = mClip.mBottom - mClip.mTop;
|
|
|
|
|
|
|
|
rc.SetColor(NS_RGB(255, 255, 0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x = y = 0;
|
1998-07-07 21:51:57 +00:00
|
|
|
|
|
|
|
GetDimensions(&w, &h);
|
1998-06-16 17:05:42 +00:00
|
|
|
|
|
|
|
if (nsnull != mWindow)
|
|
|
|
rc.SetColor(NS_RGB(0, 255, 0));
|
|
|
|
else
|
|
|
|
rc.SetColor(NS_RGB(0, 0, 255));
|
|
|
|
}
|
|
|
|
|
|
|
|
rc.DrawRect(x, y, w, h);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rc.PopState();
|
|
|
|
}
|
1998-06-03 21:30:51 +00:00
|
|
|
}
|
1998-05-27 02:13:28 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
//XXX would be nice if we could have a version of pop that just removes the
|
|
|
|
//state from the stack but doesn't change the state of the underlying graphics
|
|
|
|
//context. MMP
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
clipres = rc.PopState();
|
1998-05-27 02:13:28 +00:00
|
|
|
|
|
|
|
//now we need to exclude this view from the rest of the
|
|
|
|
//paint process. only do this if this view is actually
|
|
|
|
//visible and if there is no widget (like a scrollbar) here.
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
// if ((clipres == PR_FALSE) && (mVis == nsViewVisibility_kShow))
|
|
|
|
if (!clipwasset && (clipres == PR_FALSE) && (mVis == nsViewVisibility_kShow) && (nsnull == mWindow))
|
1998-05-27 02:13:28 +00:00
|
|
|
{
|
1998-07-07 21:51:57 +00:00
|
|
|
nsRect brect;
|
|
|
|
|
|
|
|
GetBounds(brect);
|
|
|
|
|
1998-05-27 02:13:28 +00:00
|
|
|
if ((mClip.mLeft != mClip.mRight) && (mClip.mTop != mClip.mBottom))
|
|
|
|
{
|
|
|
|
nsRect crect;
|
|
|
|
|
1998-07-07 21:51:57 +00:00
|
|
|
crect.x = mClip.mLeft + brect.x;
|
|
|
|
crect.y = mClip.mTop + brect.y;
|
1998-05-27 02:13:28 +00:00
|
|
|
crect.width = mClip.mRight - mClip.mLeft;
|
|
|
|
crect.height = mClip.mBottom - mClip.mTop;
|
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
clipres = rc.SetClipRect(crect, nsClipCombine_kSubtract);
|
1998-05-27 02:13:28 +00:00
|
|
|
}
|
|
|
|
else if (this != pRoot)
|
1998-07-07 21:51:57 +00:00
|
|
|
clipres = rc.SetClipRect(brect, nsClipCombine_kSubtract);
|
1998-05-27 02:13:28 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
return clipres;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-03 21:30:51 +00:00
|
|
|
PRBool nsView :: Paint(nsIRenderingContext& rc, const nsIRegion& region, PRUint32 aPaintFlags)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
// XXX apply region to rc
|
|
|
|
// XXX get bounding rect from region
|
|
|
|
//if (nsnull != mFrame)
|
1998-04-28 19:16:24 +00:00
|
|
|
// mFrame->Paint(rc, rect, aPaintFlags);
|
1998-06-03 21:30:51 +00:00
|
|
|
return PR_FALSE;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
nsEventStatus nsView :: HandleEvent(nsGUIEvent *event, PRUint32 aEventFlags)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-29 22:44:13 +00:00
|
|
|
//printf(" %d %d %d %d (%d,%d) \n", this, event->widget, event->widgetSupports,
|
|
|
|
// event->message, event->point.x, event->point.y);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsEventStatus retval = nsEventStatus_eIgnore;
|
|
|
|
|
|
|
|
//see if any of this view's children can process the event
|
1998-04-28 19:16:24 +00:00
|
|
|
if ((aEventFlags & NS_VIEW_FLAG_CHECK_CHILDREN) &&
|
|
|
|
(retval == nsEventStatus_eIgnore))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
PRInt32 numkids = GetChildCount();
|
|
|
|
nsRect trect;
|
|
|
|
nscoord x, y;
|
|
|
|
|
|
|
|
x = event->point.x;
|
|
|
|
y = event->point.y;
|
|
|
|
|
|
|
|
for (PRInt32 cnt = 0; cnt < numkids; cnt++)
|
|
|
|
{
|
|
|
|
nsIView *pKid = GetChild(cnt);
|
|
|
|
nscoord lx, ly;
|
|
|
|
|
|
|
|
pKid->GetBounds(trect);
|
|
|
|
|
|
|
|
lx = x - trect.x;
|
|
|
|
ly = y - trect.y;
|
|
|
|
|
|
|
|
if (trect.Contains(lx, ly))
|
|
|
|
{
|
|
|
|
//the x, y position of the event in question
|
|
|
|
//is inside this child view, so give it the
|
|
|
|
//opportunity to handle the event
|
|
|
|
|
|
|
|
event->point.x -= trect.x;
|
|
|
|
event->point.y -= trect.y;
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
retval = pKid->HandleEvent(event, NS_VIEW_FLAG_CHECK_CHILDREN);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
event->point.x += trect.x;
|
|
|
|
event->point.y += trect.y;
|
|
|
|
|
|
|
|
if (retval != nsEventStatus_eIgnore)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-23 21:50:30 +00:00
|
|
|
//if the view's children didn't take the event, check the view itself.
|
|
|
|
if ((retval == nsEventStatus_eIgnore) && (nsnull != mFrame))
|
|
|
|
{
|
|
|
|
nsIPresContext *cx = mViewManager->GetPresContext();
|
|
|
|
nscoord xoff, yoff;
|
|
|
|
|
|
|
|
GetScrollOffset(&xoff, &yoff);
|
|
|
|
|
|
|
|
event->point.x += xoff;
|
|
|
|
event->point.y += yoff;
|
|
|
|
|
|
|
|
mFrame->HandleEvent(*cx, event, retval);
|
|
|
|
|
|
|
|
event->point.x -= xoff;
|
|
|
|
event->point.y -= yoff;
|
|
|
|
|
|
|
|
NS_RELEASE(cx);
|
|
|
|
}
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
//see if any of this views siblings can process this event
|
|
|
|
//we only go from the next sibling since this is a z-ordered
|
|
|
|
//list
|
|
|
|
|
1998-05-29 22:44:13 +00:00
|
|
|
if ((aEventFlags & NS_VIEW_FLAG_CHECK_SIBLINGS) &&
|
|
|
|
(retval == nsEventStatus_eIgnore))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
nsIView *pNext = GetNextSibling();
|
|
|
|
|
|
|
|
while (pNext)
|
|
|
|
{
|
1998-04-28 19:16:24 +00:00
|
|
|
retval = pNext->HandleEvent(event, NS_VIEW_FLAG_CHECK_CHILDREN);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
if (retval != PR_FALSE)
|
|
|
|
break;
|
|
|
|
|
|
|
|
pNext = pNext->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//no-one has a clue what to do with this... so ask the
|
|
|
|
//parents. kind of mimics life, huh?
|
|
|
|
|
1998-05-29 22:44:13 +00:00
|
|
|
if ((aEventFlags & NS_VIEW_FLAG_CHECK_PARENT) && (retval == nsEventStatus_eIgnore))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
|
|
|
nsIView *pParent = GetParent();
|
|
|
|
|
|
|
|
while (pParent)
|
|
|
|
{
|
1998-05-29 22:44:13 +00:00
|
|
|
retval = pParent->HandleEvent(event, NS_VIEW_FLAG_CHECK_SIBLINGS);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-29 22:44:13 +00:00
|
|
|
if (retval == nsEventStatus_eIgnore)
|
1998-04-13 20:24:54 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
pParent = pParent->GetParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetPosition(nscoord x, nscoord y)
|
|
|
|
{
|
|
|
|
mBounds.MoveTo(x, y);
|
|
|
|
|
|
|
|
if (nsnull != mWindow)
|
|
|
|
{
|
|
|
|
nsIPresContext *px = mViewManager->GetPresContext();
|
1998-06-04 02:02:08 +00:00
|
|
|
nscoord offx, offy, parx = 0, pary = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
float scale = px->GetTwipsToPixels();
|
1998-06-16 17:05:42 +00:00
|
|
|
nsIWidget *pwidget = nsnull;
|
1998-06-04 02:02:08 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
GetScrollOffset(&offx, &offy);
|
1998-06-04 02:02:08 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
pwidget = GetOffsetFromWidget(&parx, &pary);
|
|
|
|
NS_IF_RELEASE(pwidget);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-08-08 19:21:40 +00:00
|
|
|
mWindow->Move(NSTwipsToIntPixels((x + parx - offx), scale),
|
|
|
|
NSTwipsToIntPixels((y + pary - offy), scale));
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
NS_RELEASE(px);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: GetPosition(nscoord *x, nscoord *y)
|
|
|
|
{
|
1998-07-07 21:51:57 +00:00
|
|
|
nsIView *rootView = mViewManager->GetRootView();
|
|
|
|
|
|
|
|
if (this == rootView)
|
|
|
|
*x = *y = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = mBounds.x;
|
|
|
|
*y = mBounds.y;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetDimensions(nscoord width, nscoord height)
|
|
|
|
{
|
|
|
|
mBounds.SizeTo(width, height);
|
|
|
|
|
|
|
|
if (nsnull != mParent)
|
|
|
|
{
|
1998-04-23 21:51:43 +00:00
|
|
|
nsIScrollableView *scroller;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-23 21:51:43 +00:00
|
|
|
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-23 21:51:43 +00:00
|
|
|
if (NS_OK == mParent->QueryInterface(kscroller, (void **)&scroller))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-23 23:21:37 +00:00
|
|
|
scroller->ComputeContainerSize();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-04-23 21:51:43 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-23 21:51:43 +00:00
|
|
|
if (nsnull != mWindow)
|
|
|
|
{
|
|
|
|
nsIPresContext *px = mViewManager->GetPresContext();
|
|
|
|
float t2p = px->GetTwipsToPixels();
|
|
|
|
|
1998-07-31 23:34:45 +00:00
|
|
|
mWindow->Resize(NSTwipsToIntPixels(width, t2p), NSTwipsToIntPixels(height, t2p),
|
1998-06-01 20:26:50 +00:00
|
|
|
PR_TRUE);
|
1998-04-23 21:51:43 +00:00
|
|
|
|
|
|
|
NS_RELEASE(px);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: GetDimensions(nscoord *width, nscoord *height)
|
|
|
|
{
|
|
|
|
*width = mBounds.width;
|
|
|
|
*height = mBounds.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetBounds(const nsRect &aBounds)
|
|
|
|
{
|
|
|
|
SetPosition(aBounds.x, aBounds.y);
|
|
|
|
SetDimensions(aBounds.width, aBounds.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetBounds(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
|
|
|
|
{
|
|
|
|
SetPosition(aX, aY);
|
|
|
|
SetDimensions(aWidth, aHeight);
|
|
|
|
}
|
|
|
|
|
1998-07-07 21:51:57 +00:00
|
|
|
void nsView :: GetBounds(nsRect &aBounds) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-07-07 21:51:57 +00:00
|
|
|
nsIView *rootView = mViewManager->GetRootView();
|
|
|
|
|
1998-04-13 20:24:54 +00:00
|
|
|
aBounds = mBounds;
|
1998-07-07 21:51:57 +00:00
|
|
|
|
|
|
|
if ((nsIView *)this == rootView)
|
|
|
|
aBounds.x = aBounds.y = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
void nsView :: SetClip(nscoord aLeft, nscoord aTop, nscoord aRight, nscoord aBottom)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-29 02:24:07 +00:00
|
|
|
mClip.mLeft = aLeft;
|
|
|
|
mClip.mTop = aTop;
|
|
|
|
mClip.mRight = aRight;
|
|
|
|
mClip.mBottom = aBottom;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
PRBool nsView :: GetClip(nscoord *aLeft, nscoord *aTop, nscoord *aRight, nscoord *aBottom)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-29 02:24:07 +00:00
|
|
|
if ((mClip.mLeft == mClip.mRight) || (mClip.mTop == mClip.mBottom))
|
1998-04-27 23:51:57 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
else
|
|
|
|
{
|
1998-04-29 02:24:07 +00:00
|
|
|
*aLeft = mClip.mLeft;
|
|
|
|
*aTop = mClip.mTop;
|
|
|
|
*aRight = mClip.mRight;
|
|
|
|
*aBottom = mClip.mBottom;
|
1998-04-27 23:51:57 +00:00
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetVisibility(nsViewVisibility aVisibility)
|
|
|
|
{
|
|
|
|
mVis = aVisibility;
|
|
|
|
|
|
|
|
if (nsnull != mWindow)
|
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
#ifndef HIDE_ALL_WIDGETS
|
1998-04-13 20:24:54 +00:00
|
|
|
if (mVis == nsViewVisibility_kShow)
|
|
|
|
mWindow->Show(PR_TRUE);
|
|
|
|
else
|
1998-06-16 17:05:42 +00:00
|
|
|
#endif
|
1998-04-13 20:24:54 +00:00
|
|
|
mWindow->Show(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsViewVisibility nsView :: GetVisibility()
|
|
|
|
{
|
|
|
|
return mVis;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetZIndex(PRInt32 zindex)
|
|
|
|
{
|
|
|
|
mZindex = zindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsView :: GetZIndex()
|
|
|
|
{
|
|
|
|
return mZindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetParent(nsIView *aParent)
|
|
|
|
{
|
|
|
|
mParent = aParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView * nsView :: GetParent()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView * nsView :: GetNextSibling() const
|
|
|
|
{
|
|
|
|
return mNextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView::SetNextSibling(nsIView* aView)
|
|
|
|
{
|
|
|
|
mNextSibling = aView;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: InsertChild(nsIView *child, nsIView *sibling)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != child, "null ptr");
|
|
|
|
if (nsnull != child)
|
|
|
|
{
|
|
|
|
if (nsnull != sibling)
|
|
|
|
{
|
1998-05-01 03:13:34 +00:00
|
|
|
NS_ASSERTION(!(sibling->GetParent() != this), "tried to insert view with invalid sibling");
|
1998-04-13 20:24:54 +00:00
|
|
|
//insert after sibling
|
|
|
|
child->SetNextSibling(sibling->GetNextSibling());
|
|
|
|
sibling->SetNextSibling(child);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = child;
|
|
|
|
}
|
|
|
|
child->SetParent(this);
|
|
|
|
mNumKids++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: RemoveChild(nsIView *child)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != child, "null ptr");
|
|
|
|
|
|
|
|
if (nsnull != child)
|
|
|
|
{
|
|
|
|
nsIView* prevKid = nsnull;
|
|
|
|
nsIView* kid = mFirstChild;
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
while (nsnull != kid) {
|
|
|
|
if (kid == child) {
|
|
|
|
if (nsnull != prevKid) {
|
|
|
|
prevKid->SetNextSibling(kid->GetNextSibling());
|
|
|
|
} else {
|
|
|
|
mFirstChild = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
child->SetParent(nsnull);
|
|
|
|
mNumKids--;
|
|
|
|
found = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1998-05-01 03:13:34 +00:00
|
|
|
prevKid = kid;
|
1998-04-13 20:24:54 +00:00
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
NS_ASSERTION(found, "tried to remove non child");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 nsView :: GetChildCount()
|
|
|
|
{
|
|
|
|
return mNumKids;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIView * nsView :: GetChild(PRInt32 index)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!(index > mNumKids), "bad index");
|
|
|
|
|
|
|
|
if (index < mNumKids)
|
|
|
|
{
|
|
|
|
nsIView *kid = mFirstChild;
|
|
|
|
for (PRInt32 cnt = 0; (cnt < index) && (nsnull != kid); cnt++) {
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
return kid;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
void nsView :: SetTransform(nsTransform2D &aXForm)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-28 19:16:24 +00:00
|
|
|
if (nsnull == mXForm)
|
|
|
|
mXForm = new nsTransform2D(&aXForm);
|
|
|
|
else
|
|
|
|
*mXForm = aXForm;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-04-28 19:16:24 +00:00
|
|
|
void nsView :: GetTransform(nsTransform2D &aXForm)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-04-28 19:16:24 +00:00
|
|
|
if (nsnull != mXForm)
|
|
|
|
aXForm = *mXForm;
|
|
|
|
else
|
|
|
|
aXForm.SetToIdentity();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetOpacity(float opacity)
|
|
|
|
{
|
1998-04-28 19:16:24 +00:00
|
|
|
mOpacity = opacity;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float nsView :: GetOpacity()
|
|
|
|
{
|
1998-04-28 19:16:24 +00:00
|
|
|
return mOpacity;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nsView :: HasTransparency()
|
|
|
|
{
|
1998-06-03 22:49:45 +00:00
|
|
|
return (mVFlags & VIEW_FLAG_TRANSPARENT) ? PR_TRUE : PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: SetContentTransparency(PRBool aTransparent)
|
|
|
|
{
|
|
|
|
if (aTransparent == PR_TRUE)
|
|
|
|
mVFlags |= VIEW_FLAG_TRANSPARENT;
|
|
|
|
else
|
|
|
|
mVFlags &= ~VIEW_FLAG_TRANSPARENT;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Frames have a pointer to the view, so don't AddRef the frame.
|
|
|
|
void nsView :: SetFrame(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
mFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame * nsView :: GetFrame()
|
|
|
|
{
|
|
|
|
return mFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// internal window creation functions
|
|
|
|
//
|
|
|
|
nsresult nsView :: LoadWidget(const nsCID &aClassIID)
|
|
|
|
{
|
1998-08-08 04:23:33 +00:00
|
|
|
nsISupports* window;
|
|
|
|
nsresult rv;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
1998-08-08 04:23:33 +00:00
|
|
|
rv = NSRepository::CreateInstance(aClassIID, nsnull, kISupportsIID, (void**)&window);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
|
|
|
if (NS_OK == rv) {
|
1998-08-08 04:23:33 +00:00
|
|
|
// get a pointer to the nsIWidget* interface
|
1998-04-13 20:24:54 +00:00
|
|
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
1998-08-08 04:23:33 +00:00
|
|
|
rv = window->QueryInterface(kIWidgetIID, (void**)&mWindow);
|
|
|
|
window->Release();
|
|
|
|
|
|
|
|
// Set the widget's client data
|
|
|
|
mWindow->SetClientData((void*)this);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
1998-08-05 09:02:52 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
1998-06-04 20:02:30 +00:00
|
|
|
fprintf(out, "%p ", this);
|
|
|
|
if (nsnull != mWindow) {
|
|
|
|
nsRect windowBounds;
|
|
|
|
mWindow->GetBounds(windowBounds);
|
|
|
|
fprintf(out, "(widget=%p pos={%d,%d,%d,%d}) ",
|
|
|
|
mWindow,
|
|
|
|
windowBounds.x, windowBounds.y,
|
|
|
|
windowBounds.width, windowBounds.height);
|
|
|
|
}
|
1998-07-07 21:51:57 +00:00
|
|
|
nsRect brect;
|
|
|
|
GetBounds(brect);
|
|
|
|
out << brect;
|
1998-05-27 02:13:28 +00:00
|
|
|
fprintf(out, " z=%d vis=%d opc=%1.3f <\n", mZindex, mVis, mOpacity);
|
1998-04-13 20:24:54 +00:00
|
|
|
nsIView* kid = mFirstChild;
|
|
|
|
while (nsnull != kid) {
|
|
|
|
kid->List(out, aIndent + 1);
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
1998-08-05 09:02:52 +00:00
|
|
|
for (i = aIndent; --i >= 0; ) fputs(" ", out);
|
1998-04-13 20:24:54 +00:00
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
nsIWidget * nsView :: GetOffsetFromWidget(nscoord *aDx, nscoord *aDy)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
nsIView *ancestor = GetParent();
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
while (nsnull != ancestor)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
if (nsnull != (window = ancestor->GetWidget()))
|
|
|
|
return window;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
if ((nsnull != aDx) && (nsnull != aDy))
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
nscoord offx, offy;
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
ancestor->GetPosition(&offx, &offy);
|
|
|
|
|
|
|
|
*aDx += offx;
|
|
|
|
*aDy += offy;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
ancestor = ancestor->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsView :: GetScrollOffset(nscoord *aDx, nscoord *aDy)
|
|
|
|
{
|
|
|
|
nsIWidget *window = nsnull;
|
|
|
|
nsIView *ancestor = GetParent();
|
1998-05-13 03:39:08 +00:00
|
|
|
|
1998-06-16 17:05:42 +00:00
|
|
|
while (nsnull != ancestor)
|
|
|
|
{
|
|
|
|
nsIScrollableView *sview;
|
|
|
|
|
|
|
|
static NS_DEFINE_IID(kscroller, NS_ISCROLLABLEVIEW_IID);
|
|
|
|
|
|
|
|
if (NS_OK == ancestor->QueryInterface(kscroller, (void **)&sview))
|
1998-05-13 03:39:08 +00:00
|
|
|
{
|
1998-06-16 17:05:42 +00:00
|
|
|
sview->GetVisibleOffset(aDx, aDy);
|
|
|
|
return;
|
1998-05-13 03:39:08 +00:00
|
|
|
}
|
1998-06-16 17:05:42 +00:00
|
|
|
|
|
|
|
ancestor = ancestor->GetParent();
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
1998-06-16 17:05:42 +00:00
|
|
|
|
|
|
|
*aDx = *aDy = 0;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|