cache the LookAndFeel object as long as we have any widgets

git-svn-id: svn://10.0.0.236/trunk@27993 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shaver%netscape.com
1999-04-17 15:55:21 +00:00
parent 849b23ba7d
commit 08eb88b70c
2 changed files with 19 additions and 5 deletions

View File

@@ -33,6 +33,8 @@
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
static nsILookAndFeel *nsWidget::sLookAndFeel = nsnull;
static PRUint32 nsWidget::sWidgetCount = 0;
//#define DBG 1
@@ -41,12 +43,17 @@ nsWidget::nsWidget()
// XXX Shouldn't this be done in nsBaseWidget?
NS_INIT_REFCNT();
// get the proper color from the look and feel code
nsILookAndFeel * lookAndFeel;
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
lookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, mBackground);
if (!sLookAndFeel) {
if (NS_OK != nsComponentManager::CreateInstance(kLookAndFeelCID,
nsnull, kILookAndFeelIID,
(void**)&sLookAndFeel))
sLookAndFeel = nsnull;
}
NS_RELEASE(lookAndFeel);
if (sLookAndFeel)
sLookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground,
mBackground);
mWidget = nsnull;
mParent = nsnull;
mPreferredWidth = 0;
@@ -60,6 +67,7 @@ nsWidget::nsWidget()
mOnDestroyCalled = PR_FALSE;
mIsToplevel = PR_FALSE;
mUpdateArea.SetRect(0, 0, 0, 0);
sWidgetCount++;
}
nsWidget::~nsWidget()
@@ -68,6 +76,9 @@ nsWidget::~nsWidget()
if (nsnull != mWidget) {
Destroy();
}
if (!sWidgetCount--) {
NS_RELEASE_IF(sLookAndFeel);
}
}
NS_METHOD nsWidget::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)

View File

@@ -221,6 +221,9 @@ protected:
PRBool mShown;
PRUint32 mPreferredWidth, mPreferredHeight;
private:
static nsILookAndFeel *sLookAndFeel;
static PRUint32 sWidgetCount;
};
#endif /* nsWidget_h__ */