From 2bfe7f833d4617ef881898298410b9d7c76ff049 Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Wed, 4 Apr 2001 21:45:18 +0000 Subject: [PATCH] new borderless wdef to bring in line with win32 windows. clean up mdef code to be in line with wdef code. r=saari/sr=sfraser bug# 61039 --- widget/src/mac/nsDynamicMDEF.cpp | 34 ++++++-------- widget/src/mac/nsMacWindow.h | 3 ++ widget/src/mac/nsMenu.cpp | 14 +----- widget/src/mac/nsMenuBar.cpp | 76 ++++++-------------------------- 4 files changed, 32 insertions(+), 95 deletions(-) diff --git a/widget/src/mac/nsDynamicMDEF.cpp b/widget/src/mac/nsDynamicMDEF.cpp index 11b8b1ef50eb..eda203e0a6e5 100644 --- a/widget/src/mac/nsDynamicMDEF.cpp +++ b/widget/src/mac/nsDynamicMDEF.cpp @@ -29,16 +29,17 @@ #include "nsIDOMNode.h" #include "nsMenuBar.h" #include "nsIMenuBar.h" +#include "DefProcFakery.h" #include #include extern nsWeakPtr gMacMenubar; -extern Handle gSystemMDEFHandle; + +// needed for CallMenuDefProc() to work correctly #pragma options align=mac68k -RoutineDescriptorPtr gOriginaldesc; -RoutineDescriptorPtr gmdefUPP; + // Caching the Mac menu nsVoidArray gPreviousMenuHandleStack; // hold MenuHandles @@ -259,11 +260,8 @@ pascal void nsDynamicMDEFMain( // Force a size message next time we draw this menu if(message == kMenuDrawMsg) { #if !TARGET_CARBON - SInt8 state = ::HGetState((Handle)theMenu); - HLock((Handle)theMenu); (**theMenu).menuWidth = -1; (**theMenu).menuHeight = -1; - HSetState((Handle)theMenu, state); #endif } } @@ -464,23 +462,17 @@ void nsCallSystemMDEF( Point hitPt, short * whichItem) { -#if !TARGET_CARBON - SInt8 state = ::HGetState(gSystemMDEFHandle); - ::HLock(gSystemMDEFHandle); + // extract the real system mdef out of the fake one we've stored in the menu + Handle fakedMDEF = (**theMenu).menuProc; + Handle systemDefProc = DefProcFakery::GetSystemDefProc ( fakedMDEF ); - gmdefUPP = ::NewRoutineDescriptor( (ProcPtr)*gSystemMDEFHandle, uppMenuDefProcInfo, kM68kISA); + SInt8 state = ::HGetState(systemDefProc); + ::HLock(systemDefProc); - CallMenuDefProc( - gmdefUPP, - message, - theMenu, - menuRect, - hitPt, - whichItem); - - ::DisposeRoutineDescriptor(gmdefUPP); - ::HSetState(gSystemMDEFHandle, state); -#endif + // can't use NewMenuDefProc() here because the routine descriptor has to use kM68kISA + CallMenuDefProc((RoutineDescriptorPtr)*systemDefProc, message, theMenu, menuRect, hitPt, whichItem); + + ::HSetState(systemDefProc, state); return; } diff --git a/widget/src/mac/nsMacWindow.h b/widget/src/mac/nsMacWindow.h index f07995e93ea1..6e1fe6988e30 100644 --- a/widget/src/mac/nsMacWindow.h +++ b/widget/src/mac/nsMacWindow.h @@ -112,6 +112,9 @@ public: void SetIsActive(PRBool aActive); protected: + void InstallBorderlessDefProc ( WindowPtr inWindow ) ; + void RemoveBorderlessDefProc ( WindowPtr inWindow ) ; + pascal static OSErr DragTrackingHandler ( DragTrackingMessage theMessage, WindowPtr theWindow, void *handlerRefCon, DragReference theDrag ); pascal static OSErr DragReceiveHandler (WindowPtr theWindow, diff --git a/widget/src/mac/nsMenu.cpp b/widget/src/mac/nsMenu.cpp index c97132a43986..1ce7aa9e3224 100644 --- a/widget/src/mac/nsMenu.cpp +++ b/widget/src/mac/nsMenu.cpp @@ -270,13 +270,8 @@ NS_METHOD nsMenu::SetLabel(const nsAReadableString &aText) mMacMenuIDCount++; // Replace standard MDEF with our stub MDEF - if(mMacMenuHandle) { - SInt8 state = ::HGetState((Handle)mMacMenuHandle); - ::HLock((Handle)mMacMenuHandle); - //gSystemMDEFHandle = (**mMacMenuHandle).menuProc; + if(mMacMenuHandle && gMDEF) (**mMacMenuHandle).menuProc = gMDEF; - ::HSetState((Handle)mMacMenuHandle, state); - } } return NS_OK; @@ -1412,13 +1407,8 @@ nsMenu::AttributeChanged(nsIDocument *aDocument, PRInt32 aNameSpaceID, nsIAtom * mMacMenuHandle = NSStringNewMenu(mMacMenuID, mLabel); // Replace standard MDEF with our stub MDEF - if(mMacMenuHandle) { - SInt8 state = ::HGetState((Handle)mMacMenuHandle); - ::HLock((Handle)mMacMenuHandle); - //gSystemMDEFHandle = (**mMacMenuHandle).menuProc; + if(mMacMenuHandle && gMDEF) (**mMacMenuHandle).menuProc = gMDEF; - ::HSetState((Handle)mMacMenuHandle, state); - } // Need to get the menuID of the next visible menu SInt16 nextMenuID = -1; // default to the submenu case diff --git a/widget/src/mac/nsMenuBar.cpp b/widget/src/mac/nsMenuBar.cpp index 655132de677b..2c97d8ee7978 100644 --- a/widget/src/mac/nsMenuBar.cpp +++ b/widget/src/mac/nsMenuBar.cpp @@ -52,15 +52,10 @@ #include #include "nsMacResources.h" -#pragma options align=mac68k -typedef struct { - short jmpInstr; - Ptr jmpAddr; -} JmpRecord, *JmpPtr, **JmpHandle; -#pragma options align=reset +#include "DefProcFakery.h" + Handle gMDEF = nsnull; -Handle gSystemMDEFHandle = nsnull; nsWeakPtr gMacMenubar; nsWeakPtr gOriginalMenuBar; bool gFirstMenuBar = true; @@ -106,10 +101,7 @@ nsMenuBar::nsMenuBar() mParent = nsnull; mIsMenuBarAdded = PR_FALSE; mUnicodeTextRunConverter = nsnull; - - MenuDefUPP mdef = NewMenuDefProc( nsDynamicMDEFMain ); - InstallDefProc((short)nsMacResources::GetLocalResourceFile(), (ResType)'MDEF', (short)128, (Ptr) mdef ); - + mOriginalMacMBarHandle = nsnull; mMacMBarHandle = nsnull; mDocument = nsnull; @@ -304,53 +296,48 @@ nsMenuBar::MenuConstruct( const nsMenuEvent & aMenuEvent, nsIWidget* aParentWind MenuHandle macMenuHandle = ::NewMenu(2, "\psubmenu"); if(macMenuHandle) { + + // get our fake MDEF ready to be stashed into every menu that comes our way. + // if we fail creating it, we're probably so doomed there's no point in going + // on. + if ( !gMDEF ) { + MenuDefUPP mdef = NewMenuDefProc( nsDynamicMDEFMain ); + Boolean success = DefProcFakery::CreateDefProc( mdef, (**macMenuHandle).menuProc, &gMDEF ); + if ( !success ) + ::ExitToShell(); + } + gLevel2HierMenu = macMenuHandle; - SInt8 state = ::HGetState((Handle)macMenuHandle); - ::HLock((Handle)macMenuHandle); - gSystemMDEFHandle = (**macMenuHandle).menuProc; (**macMenuHandle).menuProc = gMDEF; (**macMenuHandle).menuWidth = -1; (**macMenuHandle).menuHeight = -1; - ::HSetState((Handle)macMenuHandle, state); ::InsertMenu(macMenuHandle, hierMenu); } macMenuHandle = ::NewMenu(3, "\psubmenu"); if(macMenuHandle) { gLevel3HierMenu = macMenuHandle; - SInt8 state = ::HGetState((Handle)macMenuHandle); - ::HLock((Handle)macMenuHandle); - gSystemMDEFHandle = (**macMenuHandle).menuProc; (**macMenuHandle).menuProc = gMDEF; (**macMenuHandle).menuWidth = -1; (**macMenuHandle).menuHeight = -1; - ::HSetState((Handle)macMenuHandle, state); ::InsertMenu(macMenuHandle, hierMenu); } macMenuHandle = ::NewMenu(4, "\psubmenu"); if(macMenuHandle) { gLevel4HierMenu = macMenuHandle; - SInt8 state = ::HGetState((Handle)macMenuHandle); - ::HLock((Handle)macMenuHandle); - gSystemMDEFHandle = (**macMenuHandle).menuProc; (**macMenuHandle).menuProc = gMDEF; (**macMenuHandle).menuWidth = -1; (**macMenuHandle).menuHeight = -1; - ::HSetState((Handle)macMenuHandle, state); ::InsertMenu(macMenuHandle, hierMenu); } macMenuHandle = ::NewMenu(5, "\psubmenu"); if(macMenuHandle) { gLevel5HierMenu = macMenuHandle; - SInt8 state = ::HGetState((Handle)macMenuHandle); - ::HLock((Handle)macMenuHandle); - gSystemMDEFHandle = (**macMenuHandle).menuProc; (**macMenuHandle).menuProc = gMDEF; (**macMenuHandle).menuWidth = -1; (**macMenuHandle).menuHeight = -1; - ::HSetState((Handle)macMenuHandle, state); ::InsertMenu(macMenuHandle, hierMenu); } } else { @@ -609,41 +596,6 @@ NS_METHOD nsMenuBar::Paint() } -//------------------------------------------------------------------------- -void InstallDefProc( - short dpPath, - ResType dpType, - short dpID, - Ptr dpAddr) -{ - JmpHandle jH; - short savePath; - - savePath = CurResFile(); - UseResFile(dpPath); - - jH = (JmpHandle)GetResource(dpType, dpID); - DetachResource((Handle)jH); - gMDEF = (Handle) jH; - UseResFile(savePath); - - if (!jH) /* is there no defproc resource? */\ - { -#if DEBUG - DebugStr("\pStub Defproc Not Found!"); -#endif - ExitToShell(); // bail - } - - HNoPurge((Handle)jH); /* make this resource nonpurgeable */ - (**jH).jmpAddr = dpAddr; - (**jH).jmpInstr = 0x4EF9; - //FlushCache(); - - HLockHi((Handle)jH); -} - - #pragma mark - //