fix list boxes with a temporary hack to access the 'ldes' resource from the Finder

This commit is contained in:
pierre%netscape.com 1999-05-14 10:09:14 +00:00
Родитель d5e28b33bd
Коммит 69da4c453c
1 изменённых файлов: 60 добавлений и 16 удалений

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

@ -19,6 +19,8 @@
#include "nsListBox.h"
#include <StringCompare.h>
#include <Resources.h>
#include <Folders.h>
#include <LowMem.h>
#if TARGET_CARBON
#include <ControlDefinitions.h>
#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;
}