From 2a94df8c398e3985b6843c2a069683ff3ebe7035 Mon Sep 17 00:00:00 2001 From: pinkerton Date: Fri, 29 May 1998 20:23:14 +0000 Subject: [PATCH] Back/forward button popups actually do the right thing now. --- cmd/macfe/gui/CBrowserWindow.cp | 38 +++++++------ cmd/macfe/gui/CNavigationButtonPopup.cp | 73 ++++++++++++++++--------- cmd/macfe/gui/CNavigationButtonPopup.h | 9 ++- 3 files changed, 75 insertions(+), 45 deletions(-) diff --git a/cmd/macfe/gui/CBrowserWindow.cp b/cmd/macfe/gui/CBrowserWindow.cp index 57c13d85de65..ef7d4943f166 100644 --- a/cmd/macfe/gui/CBrowserWindow.cp +++ b/cmd/macfe/gui/CBrowserWindow.cp @@ -706,20 +706,30 @@ Boolean CBrowserWindow::ObeyCommand( GetHTMLView()->ObeyCommand(inCommand, ioParam); } break; - + +#if 0 + // The forward and back buttons are LBevelButtons, which means they will + // broadcast when the user clicks in them. |ioParam| will be the value of + // the popup menu, or 0 if the user clicked the button. case cmd_GoForward: - if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey)) - { - if (mContext) + if ( ioParam > 0 ) { + + + } + else { + if (CApplicationEventAttachment::CurrentEventHasModifiers(optionKey)) { - mContext->GoForwardOneHost(); + if (mContext) + { + mContext->GoForwardOneHost(); + } } + else + { + SendAEGo(kAENext); + } + cmdHandled = true; } - else - { - SendAEGo(kAENext); - } - cmdHandled = true; break; case cmd_GoBack: @@ -736,6 +746,7 @@ Boolean CBrowserWindow::ObeyCommand( } cmdHandled = true; break; +#endif case cmd_Home: SendAEGo(AE_www_go_home); @@ -874,18 +885,11 @@ void CBrowserWindow::ListenToMessage(MessageT inMessage, void* ioParam) CStr255* urlString = (CStr255*)ioParam; if (urlString && mContext) { - /* old way - URL_Struct* theURL = - NET_CreateURLStruct(*urlString, NET_DONT_RELOAD); - mContext->SwitchLoadURL(theURL, FO_CACHE_AND_PRESENT); - */ if (!urlString->IsEmpty()) SendAEGetURL(*urlString); } break; - case cmd_GoForward: - case cmd_GoBack: case cmd_Home: case cmd_Reload: case cmd_Stop: diff --git a/cmd/macfe/gui/CNavigationButtonPopup.cp b/cmd/macfe/gui/CNavigationButtonPopup.cp index f9c274cca731..c14b067ed75a 100644 --- a/cmd/macfe/gui/CNavigationButtonPopup.cp +++ b/cmd/macfe/gui/CNavigationButtonPopup.cp @@ -45,6 +45,7 @@ CNavigationButtonPopup::CNavigationButtonPopup( LStream* inStream) : mBrowserContext(nil), + mBrowserWindow(nil), mHistory(nil), mCurrentEntry(nil), mCurrentEntryIndex(0), @@ -61,7 +62,23 @@ CNavigationButtonPopup::CNavigationButtonPopup( CNavigationButtonPopup::~CNavigationButtonPopup() { } + + +// +// FinishCreateSelf +// +void +CNavigationButtonPopup :: FinishCreateSelf ( ) +{ + CToolbarBevelButton::FinishCreateSelf(); + // LBevelButton will broadcast when an item in the popup menu is picked or when + // the button is pressed. We want to handle that here instead of elsewhere + AddListener(this); + +} // FinishCreateSelf + + #pragma mark - // --------------------------------------------------------------------------- @@ -138,28 +155,36 @@ CNavigationButtonPopup::InsertHistoryItemIntoMenu( #pragma mark - -// --------------------------------------------------------------------------- -// ¥ HandleNewValue -// --------------------------------------------------------------------------- -Boolean -CNavigationButtonPopup::HandleNewValue( - Int32 inNewValue) +// +// ListenToMessage +// +// The message sent will have +// +void +CNavigationButtonPopup :: ListenToMessage ( MessageT inMessage, void* ioParam ) { - if (AssertPreconditions() && inNewValue) - { - Int32 historyIndex = 0; - - if (GetCommandNumber() == cmd_GoBack) - historyIndex = SHIST_GetIndex(mHistory, mCurrentEntry) - inNewValue; - else if (GetCommandNumber() == cmd_GoForward) - historyIndex = SHIST_GetIndex(mHistory, mCurrentEntry) + inNewValue; - - if (historyIndex) - mBrowserContext->LoadHistoryEntry(historyIndex); - } + Uint32 menuValue = *reinterpret_cast(ioParam); - return true; + if ( AssertPreconditions() ) { + if ( menuValue ) { + Int32 historyIndex = 0; + + if (inMessage == cmd_GoBack) + historyIndex = SHIST_GetIndex(mHistory, mCurrentEntry) - menuValue; + else if (inMessage == cmd_GoForward) + historyIndex = SHIST_GetIndex(mHistory, mCurrentEntry) + menuValue; + + if (historyIndex) + mBrowserContext->LoadHistoryEntry(historyIndex); + } + else { + if (inMessage == cmd_GoBack) + mBrowserWindow->SendAEGo(kAEPrevious); + else if (inMessage == cmd_GoForward) + mBrowserWindow->SendAEGo(kAENext); + } + } } // --------------------------------------------------------------------------- @@ -170,17 +195,15 @@ CNavigationButtonPopup::HandleNewValue( Boolean CNavigationButtonPopup::AssertPreconditions() { - CMediatedWindow* topWindow = CWindowMediator::GetWindowMediator()->FetchTopWindow(WindowType_Any, regularLayerType); - + CMediatedWindow* topWindow = CWindowMediator::GetWindowMediator()->FetchTopWindow(WindowType_Any, regularLayerType); if (!topWindow || topWindow->GetWindowType() != WindowType_Browser) return false; - CBrowserWindow* browserWindow = dynamic_cast(topWindow); - - if (!browserWindow) + mBrowserWindow = dynamic_cast(topWindow); + if (!mBrowserWindow) return false; - if (!(mBrowserContext = (CBrowserContext*)browserWindow->GetWindowContext())) + if (!(mBrowserContext = (CBrowserContext*)mBrowserWindow->GetWindowContext())) return false; if (!(mHistory = &((MWContext*)(*mBrowserContext))->hist)) diff --git a/cmd/macfe/gui/CNavigationButtonPopup.h b/cmd/macfe/gui/CNavigationButtonPopup.h index 7342cf28a6e1..7814ee878032 100644 --- a/cmd/macfe/gui/CNavigationButtonPopup.h +++ b/cmd/macfe/gui/CNavigationButtonPopup.h @@ -33,10 +33,11 @@ // Forward declarations class CBrowserContext; +class CBrowserWindow; // Class declaration -class CNavigationButtonPopup : public CToolbarBevelButton +class CNavigationButtonPopup : public CToolbarBevelButton, public LListener { public: enum { class_ID = 'TbNv' }; @@ -48,17 +49,19 @@ public: protected: virtual void ClickSelf ( const SMouseDownEvent & inEvent ); - + virtual void FinishCreateSelf ( ) ; + virtual void AdjustMenuContents(); virtual void InsertHistoryItemIntoMenu( Int32 inHistoryItemIndex, Int16 inAfterItem); - virtual Boolean HandleNewValue(Int32 inNewValue); + virtual void ListenToMessage ( MessageT inMessage, void* ioParam ) ; Boolean AssertPreconditions(); + CBrowserWindow* mBrowserWindow; CBrowserContext* mBrowserContext; History* mHistory; History_entry* mCurrentEntry;