No longer aggregate nsIWidget in nsIXPFCCanvas. Use the CanvasManager

to maintain history.
This commit is contained in:
spider%netscape.com 1998-09-16 17:17:45 +00:00
Родитель 23dca980a8
Коммит 8443ed2432
6 изменённых файлов: 162 добавлений и 60 удалений

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

@ -540,16 +540,15 @@ nsEventStatus nsCalendarContainer::HandleEvent(nsGUIEvent *aEvent)
/*
* find the canvas this event is associated with!
*/
res = aEvent->widget->QueryInterface(kIXPFCCanvasIID,(void**)&canvas);
if (res == NS_OK)
canvas = gXPFCToolkit->GetCanvasManager()->CanvasFromWidget(aEvent->widget);
if (canvas != nsnull)
{
es = canvas->HandleEvent(aEvent);
//mViewManager->DispatchEvent(aEvent, es);
NS_RELEASE(canvas);
return es;
}

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

@ -275,24 +275,14 @@ private:
PRUint32 mTabID;
PRUint32 mTabGroup;
// nsIWidget Aggregation
protected:
// a Canvas CAN aggregate an nsIWidget
// mWidgetSupports is the pointer to the widget's real nsISupports. QueryInterace
// should be called on mWidgetSupports if any of the widget interface wants to
// be exposed,
// mWidget is a convenience pointer to the widget functionalities.
// mWidget is not AddRef'ed or Released otherwise we'll create a circulare
// refcount and the canvas will never go away
nsISupports *mWidgetSupports;
nsIWidget *mWidget;
nsISupports *mWidgetSupports;
nsIWidget *mWidget;
nsIRenderingContext *mRenderingContext;
nsIXPFCCanvas * mParent;
nsIImageRequest* mImageRequest;
nsIImageGroup* mImageGroup;
nsIXPFCCanvas *mParent;
nsIImageRequest *mImageRequest;
nsIImageGroup *mImageGroup;
public:
nsIView *mView;

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

@ -40,10 +40,21 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init() ;
NS_IMETHOD_(nsIXPFCCanvas *) CanvasFromView(nsIView * aView);
NS_IMETHOD_(nsIXPFCCanvas *) CanvasFromWidget(nsIWidget * aWidget);
NS_IMETHOD GetRootCanvas(nsIXPFCCanvas ** aCanvas);
NS_IMETHOD SetRootCanvas(nsIXPFCCanvas * aCanvas);
NS_IMETHOD Register(nsIXPFCCanvas * aCanvas, nsIView * aView);
NS_IMETHOD RegisterView(nsIXPFCCanvas * aCanvas,
nsIView * aView);
NS_IMETHOD RegisterWidget(nsIXPFCCanvas * aCanvas,
nsIWidget * aWidget);
NS_IMETHOD Unregister(nsIXPFCCanvas * aCanvas);
NS_IMETHOD_(nsIXPFCCanvas *) GetFocusedCanvas();
@ -73,7 +84,8 @@ public:
PRMonitor * monitor;
public:
nsIVector * mList ;
nsIVector * mViewList ;
nsIVector * mWidgetList ;
private:
nsIXPFCCanvas * mRootCanvas;

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

@ -23,6 +23,7 @@
class nsIXPFCCanvas;
class nsIView;
class nsIWidget;
// IID for the nsIXPFCCanvasManager interface
#define NS_IXPFC_CANVAS_MANAGER_IID \
@ -50,6 +51,7 @@ public:
* @result nsIXPFCCanvas pointer, The resultant canvas, nsnull if none found
*/
NS_IMETHOD_(nsIXPFCCanvas *) CanvasFromView(nsIView * aView) = 0;
NS_IMETHOD_(nsIXPFCCanvas *) CanvasFromWidget(nsIWidget * aWidget) = 0;
/**
* Get a reference to the root canvas
@ -71,8 +73,11 @@ public:
* @param aWidget the widget
* @result nsresult, NS_OK if successful
*/
NS_IMETHOD Register(nsIXPFCCanvas * aCanvas,
nsIView * aView) = 0;
NS_IMETHOD RegisterView(nsIXPFCCanvas * aCanvas,
nsIView * aView) = 0;
NS_IMETHOD RegisterWidget(nsIXPFCCanvas * aCanvas,
nsIWidget * aWidget) = 0;
/**
* UnRegister an association between a canvas and a widget

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

@ -61,6 +61,7 @@ static NS_DEFINE_IID(kXPFCCommandReceiverIID, NS_IXPFC_COMMANDRECEIVER_IID);
static NS_DEFINE_IID(kXPFCCommandCID, NS_XPFC_COMMAND_CID);
static NS_DEFINE_IID(kIImageObserverIID, NS_IIMAGEREQUESTOBSERVER_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
nsXPFCCanvas :: nsXPFCCanvas(nsISupports* outer) :
@ -74,7 +75,6 @@ nsXPFCCanvas :: nsXPFCCanvas(nsISupports* outer) :
{
NS_INIT_AGGREGATED(outer);
mWidgetSupports = nsnull;
mWidget = nsnull;
mLayout = nsnull;
mParent = nsnull;
@ -117,9 +117,7 @@ nsXPFCCanvas :: ~nsXPFCCanvas()
{
DeleteChildren();
if (nsnull != mWidgetSupports) {
NS_RELEASE(mWidgetSupports);
}
NS_IF_RELEASE(mWidget);
mParent = nsnull;
@ -191,8 +189,8 @@ nsresult nsXPFCCanvas::AggregatedQueryInterface(const nsIID &aIID,
return NS_OK;
}
if (nsnull != mWidgetSupports)
return mWidgetSupports->QueryInterface(aIID, aInstancePtr);
if (nsnull != mWidget)
return mWidget->QueryInterface(aIID, aInstancePtr);
return NS_NOINTERFACE;
}
@ -581,21 +579,19 @@ nsresult nsXPFCCanvas :: LoadWidget(const nsCID &aClassIID)
return rv;
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
rv = nsRepository::CreateInstance(aClassIID, supports, kISupportsIID, (void**)&mWidgetSupports);
if (NS_OK == rv) {
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
rv = mWidgetSupports->QueryInterface(kIWidgetIID, (void**)&mWidget);
if (NS_OK != rv) {
mWidgetSupports->Release();
mWidgetSupports = NULL;
}
else {
mWidget->Release();
}
rv = nsRepository::CreateInstance(aClassIID,
nsnull, //supports,
kIWidgetIID,
(void**)&mWidget);
NS_RELEASE(supports);
if (mWidget != nsnull)
{
gXPFCToolkit->GetCanvasManager()->RegisterWidget(this,mWidget);
}
return rv;
}
@ -754,7 +750,6 @@ PRBool nsXPFCCanvas::Create(char * lpszWindowName,
{
static NS_DEFINE_IID(kCChildCID, NS_CHILD_CID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
#ifdef XP_UNIX
nsRepository::RegisterFactory(kCChildCID, "libwidgetunix.so", PR_FALSE, PR_FALSE);

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

@ -27,17 +27,31 @@ static NS_DEFINE_IID(kXPFCCanvasManagerIID, NS_IXPFC_CANVAS_MANAGER_IID);
static NS_DEFINE_IID(kCXPFCCanvasIID, NS_IXPFC_CANVAS_IID);
static NS_DEFINE_IID(kIViewObserverIID, NS_IVIEWOBSERVER_IID);
class ListEntry {
class ViewListEntry {
public:
nsIView * view;
nsIXPFCCanvas * canvas;
ListEntry(nsIView * aView,
nsIXPFCCanvas * aCanvas) {
ViewListEntry(nsIView * aView,
nsIXPFCCanvas * aCanvas) {
view = aView;
canvas = aCanvas;
}
~ListEntry() {
~ViewListEntry() {
}
};
class WidgetListEntry {
public:
nsIWidget * widget;
nsIXPFCCanvas * canvas;
WidgetListEntry(nsIWidget * aWidget,
nsIXPFCCanvas * aCanvas) {
widget = aWidget;
canvas = aCanvas;
}
~WidgetListEntry() {
}
};
@ -45,7 +59,8 @@ public:
nsXPFCCanvasManager :: nsXPFCCanvasManager()
{
NS_INIT_REFCNT();
mList = nsnull;
mViewList = nsnull;
mWidgetList = nsnull;
monitor = nsnull;
mRootCanvas = nsnull;
mFocusedCanvas = nsnull;
@ -57,7 +72,8 @@ nsXPFCCanvasManager :: ~nsXPFCCanvasManager()
{
PR_DestroyMonitor(monitor);
NS_IF_RELEASE(mRootCanvas);
NS_IF_RELEASE(mList);
NS_IF_RELEASE(mViewList);
NS_IF_RELEASE(mWidgetList);
}
NS_IMPL_ADDREF(nsXPFCCanvasManager)
@ -92,7 +108,8 @@ nsresult nsXPFCCanvasManager::QueryInterface(REFNSIID aIID, void** aInstancePtr)
nsresult nsXPFCCanvasManager::Init()
{
if (mList == nsnull) {
if (mViewList == nsnull)
{
static NS_DEFINE_IID(kCVectorIteratorCID, NS_VECTOR_ITERATOR_CID);
static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID);
@ -100,12 +117,29 @@ nsresult nsXPFCCanvasManager::Init()
nsresult res = nsRepository::CreateInstance(kCVectorCID,
nsnull,
kCVectorCID,
(void **)&mList);
(void **)&mViewList);
if (NS_OK != res)
return res ;
mList->Init();
mViewList->Init();
}
if (mWidgetList == nsnull)
{
static NS_DEFINE_IID(kCVectorIteratorCID, NS_VECTOR_ITERATOR_CID);
static NS_DEFINE_IID(kCVectorCID, NS_VECTOR_CID);
nsresult res = nsRepository::CreateInstance(kCVectorCID,
nsnull,
kCVectorCID,
(void **)&mWidgetList);
if (NS_OK != res)
return res ;
mWidgetList->Init();
}
if (monitor == nsnull) {
@ -123,15 +157,15 @@ nsIXPFCCanvas * nsXPFCCanvasManager::CanvasFromView(nsIView * aView)
nsIIterator * iterator;
mList->CreateIterator(&iterator);
mViewList->CreateIterator(&iterator);
iterator->Init();
ListEntry * item ;
ViewListEntry * item ;
while(!(iterator->IsDone()))
{
item = (ListEntry *) iterator->CurrentItem();
item = (ViewListEntry *) iterator->CurrentItem();
if (item->view == aView)
{
@ -149,11 +183,56 @@ nsIXPFCCanvas * nsXPFCCanvasManager::CanvasFromView(nsIView * aView)
return (canvas);
}
nsresult nsXPFCCanvasManager::Register(nsIXPFCCanvas * aCanvas, nsIView * aView)
nsIXPFCCanvas * nsXPFCCanvasManager::CanvasFromWidget(nsIWidget * aWidget)
{
nsIXPFCCanvas * canvas = nsnull;
PR_EnterMonitor(monitor);
nsIIterator * iterator;
mWidgetList->CreateIterator(&iterator);
iterator->Init();
WidgetListEntry * item ;
while(!(iterator->IsDone()))
{
item = (WidgetListEntry *) iterator->CurrentItem();
if (item->widget == aWidget)
{
canvas = item->canvas;
break;
}
iterator->Next();
}
NS_RELEASE(iterator);
PR_ExitMonitor(monitor);
return (canvas);
}
nsresult nsXPFCCanvasManager::RegisterView(nsIXPFCCanvas * aCanvas, nsIView * aView)
{
PR_EnterMonitor(monitor);
mList->Append(new ListEntry(aView, aCanvas));
mViewList->Append(new ViewListEntry(aView, aCanvas));
PR_ExitMonitor(monitor);
return NS_OK;
}
nsresult nsXPFCCanvasManager::RegisterWidget(nsIXPFCCanvas * aCanvas, nsIWidget * aWidget)
{
PR_EnterMonitor(monitor);
mWidgetList->Append(new WidgetListEntry(aWidget, aCanvas));
PR_ExitMonitor(monitor);
@ -170,19 +249,41 @@ nsresult nsXPFCCanvasManager::Unregister(nsIXPFCCanvas * aCanvas)
*/
nsIIterator * iterator;
mList->CreateIterator(&iterator);
mViewList->CreateIterator(&iterator);
iterator->Init();
ListEntry * item ;
ViewListEntry * item ;
while(!(iterator->IsDone()))
{
item = (ListEntry *) iterator->CurrentItem();
item = (ViewListEntry *) iterator->CurrentItem();
if (item->canvas == aCanvas)
{
mList->Remove((nsComponent)item);
mViewList->Remove((nsComponent)item);
break;
}
iterator->Next();
}
NS_RELEASE(iterator);
mWidgetList->CreateIterator(&iterator);
iterator->Init();
WidgetListEntry * witem ;
while(!(iterator->IsDone()))
{
witem = (WidgetListEntry *) iterator->CurrentItem();
if (witem->canvas == aCanvas)
{
mWidgetList->Remove((nsComponent)witem);
break;
}