From 69da4c453c47491acd3a5586f99a598ab027dac4 Mon Sep 17 00:00:00 2001 From: "pierre%netscape.com" Date: Fri, 14 May 1999 10:09:14 +0000 Subject: [PATCH] fix list boxes with a temporary hack to access the 'ldes' resource from the Finder --- widget/src/mac/nsListBox.cpp | 76 ++++++++++++++++++++++++++++-------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/widget/src/mac/nsListBox.cpp b/widget/src/mac/nsListBox.cpp index 6c40ce48e5ff..511d30e49778 100644 --- a/widget/src/mac/nsListBox.cpp +++ b/widget/src/mac/nsListBox.cpp @@ -19,6 +19,8 @@ #include "nsListBox.h" #include #include +#include +#include #if TARGET_CARBON #include #endif @@ -92,26 +94,68 @@ NS_IMETHODIMP nsListBox::Create(nsIWidget *aParent, nsIToolkit *aToolkit, nsWidgetInitData *aInitData) { - Handle resH = ::NewHandleClear(sizeof(ldesRsrc)); - if (resH) - { - ldesRsrc** ldesH = (ldesRsrc**)resH; - (*ldesH)->cols = 1; - (*ldesH)->vertScroll = 1; - short resID = mValue = 2222; - ::AddResource(resH, 'ldes', resID, "\p"); + short sysVRefNum; + long sysDirID; + short fRefNum; + short saveResFile; + Handle resH; + + #define kFinderLDESRsrcID 128 + + { //--- + // Hack: the list control needs a 'ldes' resource to initialize properly but + // we don't have any global resource file that we could use to store one as a + // resource template so we temporarily borrow the resource that exists in the Finder. + // + //¥REVISIT: this hack is probably a big performance hit because the Finder rsrc fork + // is accessed each time a list box is created. Amongst possible solutions: + // - Switch to GFX widgets. Problem: maybe we'll still want to keep the native widgets. + // - Define a Mozilla resource file that all the applications (internal + embedding) + // will have to include. Problem: risk of rsrc ID conflicts with embedding apps. + // - Keep this hack but have a global refNum for the Finder. Problem: well... + // - Stop using the Appearance Manager control for list boxes: use LNew directly. + saveResFile = ::CurResFile(); + ::FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &sysVRefNum, &sysDirID); + fRefNum = HOpenResFile(sysVRefNum, sysDirID, ::LMGetFinderName(), fsRdPerm); + if (fRefNum != -1) + { + ::UseResFile(fRefNum); + + resH = ::GetResource(kControlListDescResType, kFinderLDESRsrcID); + if (resH) + { + ldesRsrc** ldesH = (ldesRsrc**)resH; + (*ldesH)->version = 0; + (*ldesH)->rows = 0; + (*ldesH)->cols = 1; + (*ldesH)->cellHeight = 0; + (*ldesH)->cellWidth = 0; + (*ldesH)->vertScroll = 1; + (*ldesH)->horizScroll = 0; + (*ldesH)->ldefID = 0; + (*ldesH)->hasGrow = 0; + } + } } + mValue = kFinderLDESRsrcID; nsresult res = Inherited::Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); - if (resH) - { - ::RemoveResource(resH); - ::DisposeHandle(resH); + + { //--- + // Hack: part 2 - see above + if (fRefNum != -1) + { + if (resH) + ::ReleaseResource(resH); + + ::CloseResFile(fRefNum); + ::UseResFile(saveResFile); + } } - if (res == NS_OK) - { + if (res == NS_OK) + { Size actualSize; ::GetControlData(mControl, kControlNoPart, kControlListBoxListHandleTag, sizeof(ListHandle), (Ptr)&mListHandle, &actualSize); if (mListHandle) @@ -123,8 +167,8 @@ NS_IMETHODIMP nsListBox::Create(nsIWidget *aParent, ::LSetDrawingMode(mVisible, mListHandle); } else - res = NS_ERROR_FAILURE; - } + res = NS_ERROR_FAILURE; + } return res; }