From 95fc0f6f14588de46edb6decf2f72694cd8b4efd Mon Sep 17 00:00:00 2001 From: "pinkerton%netscape.com" Date: Tue, 6 Oct 1998 20:55:43 +0000 Subject: [PATCH] url bar now works, redraw fixes, buttons actually do what they are supposed to do. git-svn-id: svn://10.0.0.236/trunk@12068 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/cmd/macfe/gui/CRDFToolbarItem.cp | 234 +++++++++++++++++++---- mozilla/cmd/macfe/gui/CRDFToolbarItem.h | 29 ++- 2 files changed, 222 insertions(+), 41 deletions(-) diff --git a/mozilla/cmd/macfe/gui/CRDFToolbarItem.cp b/mozilla/cmd/macfe/gui/CRDFToolbarItem.cp index e230290356e..f8656b98570 100644 --- a/mozilla/cmd/macfe/gui/CRDFToolbarItem.cp +++ b/mozilla/cmd/macfe/gui/CRDFToolbarItem.cp @@ -38,7 +38,9 @@ #include "UGAAppearance.h" #include "URDFUtilities.h" #include "CBrowserWindow.h" +#include "CTargetedUpdateMenuRegistry.h" #include "uapp.h" +#include "CPaneEnabler.h" extern RDF_NCVocab gNavCenter; // RDF vocab struct for NavCenter @@ -57,7 +59,6 @@ CRDFToolbarItem :: ~CRDFToolbarItem ( ) } - #pragma mark - @@ -75,6 +76,9 @@ CRDFPushButton :: CRDFPushButton ( HT_Resource inNode ) AttachTooltip(); AttachContextMenu(); + AttachPaneEnabler(); + + AssignCommand(); } @@ -84,6 +88,59 @@ CRDFPushButton :: ~CRDFPushButton ( ) } +// +// HookUpToListeners +// +// Find the top level browser window and register it as a listener for commands, but only +// if this button is a special command. Other kinds of buttons don't need to be registered as +// they just dispatch immediately and don't broadcast commands. +// +void +CRDFPushButton :: HookUpToListeners ( ) +{ + const char* url = HT_GetNodeURL(HTNode()); + if ( url && strncmp(url, "command:", 8) == 0 ) { + LView* top=GetSuperView(); + while ( top && top->GetSuperView() ) + top = top->GetSuperView(); + LListener* topListener = dynamic_cast(top); + if ( topListener ) + AddListener(topListener); + } + +} // HookUpToListeners + + +// +// AssignCommand +// +// Set LControl's value message for clicking and command enabling. The default is |cmd_ToolbarButton| +// which is a container or url (a la personal toolbar button). Explicit commands (anything with +// "command:" in their URL) have their own command ID's in the FE. +// +void +CRDFPushButton :: AssignCommand ( ) +{ + SetValueMessage ( cmd_ToolbarButton ); + + // check for one of our known commands. If it is one of those, change the command id. + const char* url = HT_GetNodeURL(HTNode()); + if ( url && strncmp(url, "command:", 8) == 0 ) { + if ( strcmp(url, "command:back") == 0 ) + SetValueMessage ( cmd_GoBack ); + else if ( strcmp(url, "command:forward") == 0 ) + SetValueMessage ( cmd_GoForward ); + else if ( strcmp(url, "command:stop") == 0 ) + SetValueMessage ( cmd_Stop ); + else if ( strcmp(url, "command:reload") == 0 ) + SetValueMessage ( cmd_Reload ); + else if ( strcmp(url, "command:search") == 0 ) + SetValueMessage ( cmd_NetSearch ); + } + +} // AssignCommand + + // // CalcDisplayMode // @@ -238,6 +295,23 @@ CRDFPushButton :: AttachContextMenu ( ) } // AttachContextMenu +// +// AttachPaneEnabler +// +// Creates a enabler policy attachment. We can use the default enabling policy (which is based off +// FindCommandStatus) because we are an LControl. +// +void +CRDFPushButton :: AttachPaneEnabler ( ) +{ + CPaneEnabler* enabler = new CPaneEnabler; + Assert_(enabler != NULL); + if ( enabler ) + AddAttachment(enabler); + +} // AttachPaneEnabler + + // // FindTooltipForMouseLocation // @@ -257,6 +331,48 @@ CRDFPushButton :: FindTooltipForMouseLocation ( const EventRecord& inMacEvent, S } // FindTooltipForMouseLocation +// +// NaturalSize +// +SDimension16 +CRDFPushButton::NaturalSize( SDimension16 inAvailable ) const + /* + ...returns the natural size of this item. The toolbar asks this of + each item during layout. If possible, the toolbar will resize the + item to its natural size, as returned by this routine. + + If you return exactly the value from |inAvailable| for width, the + toolbar may assume that you wish to consume all available width, e.g., + for a URL entry field, or a status message. This does not apply to + height (mainly because of the problem described below). Returning a + height greater than |inAvailable| may encourage the toolbar to grow + vertically. + + For a particular dimension: + * an item with a fixed size can ignore |inAvailable| and return its + size; + * an item with a percentage size can calculate it based on + |inAvailable|; + * an item with a space-filling size can simply return |inAvailable|. + + Problems: + this routine is essentially a hack. In particular, if |inAvailable| + happens to coincide with the natural size in either dimension, + hilarity ensues. Hopefully, |inAvailable| will always reflect a + toolbar wider than a normal button :-> + + Assumptions: + any toolbar item can be resized arbitrarilly small (to an + unspecified limit). + */ +{ + SDimension16 desiredSpace; + desiredSpace.width = 50; desiredSpace.height = 50; //еее for now + + return desiredSpace; +} + + // // PrepareDrawButton // @@ -500,10 +616,10 @@ CRDFPushButton :: ImageIsReady ( ) // // Called when the image we want to draw has not finished loading. We get // called to draw something in its place. Any good ideas? +// void CRDFPushButton :: DrawStandby ( const Point & inTopLeft, IconTransformType inTransform ) const { -// ::FrameRect ( &mCachedGraphicFrame ); //еее this is wrong! } // DrawStandby @@ -513,7 +629,7 @@ CRDFPushButton :: MouseEnter ( Point /*inPortPt*/, const EventRecord & /*inMacEv { mMouseInFrame = true; if (IsActive() && IsEnabled()) - Draw(NULL); + Refresh(); } @@ -531,20 +647,10 @@ CRDFPushButton :: MouseLeave( ) return; mMouseInFrame = false; - if (IsActive() && IsEnabled()) { - // since we can't simply draw the border w/ xor, we need to get the toolbar - // to redraw its bg and then redraw the normal button over it. To do this - // we create a rgn (in port coords), make it the clip rgn, and then draw - // the parent toolbar and this button again. - Rect portRect; - CalcPortFrameRect(portRect); - StRegion buttonRgnPort(portRect); -// StClipRgnState savedClip(buttonRgnPort); ///еее grrr, this doesn't work - - GetSuperView()->Draw(NULL); - Draw(NULL); - } -} + if (IsActive() && IsEnabled()) + Refresh(); + +} // MouseLeave // @@ -557,7 +663,7 @@ CRDFPushButton :: HotSpotAction(short /* inHotSpot */, Boolean inCurrInside, Boo { if (inCurrInside != inPrevInside) { SetTrackInside(inCurrInside); - Draw(NULL); + Draw(NULL); // draw immed. because mouse is down, can't wait for update event } } // HotSpotAction @@ -567,13 +673,11 @@ void CRDFPushButton :: HotSpotResult(Int16 inHotSpot) { const char* url = HT_GetNodeURL(HTNode()); - if ( strncmp(url, "command:", 8) == 0 ) + if ( url && strncmp(url, "command:", 8) == 0 ) { // We're a command, baby. Look up our FE command and execute it. - //UINT nCommand = theApp.m_pBrowserCommandMap->GetFEResource(url); - //WFE_GetOwnerFrame(this)->PostMessage(WM_COMMAND, MAKEWPARAM(nCommand, nCommand), 0); + HotSpotAction ( 0, false, true ); BroadcastValueMessage(); - DebugStr("\pExecuting command; g"); } else if ( !HT_IsContainer(HTNode()) && !HT_IsSeparator(HTNode()) ) { @@ -591,7 +695,7 @@ CRDFPushButton :: HotSpotResult(Int16 inHotSpot) // find the Browser window and tell it to show a popdown with // the give HT_Resource for this cell LView* top=GetSuperView(); - while ( top->GetSuperView() ) + while ( top && top->GetSuperView() ) top = top->GetSuperView(); // popdown the tree @@ -633,16 +737,38 @@ CRDFPushButton :: DoneTracking ( SInt16 inHotSpot, Boolean inGoodTrack ) { SetTrackInside(false); - if ( inGoodTrack ) { - // draw parent, then redraw us. - GetSuperView()->Draw(NULL); - Draw(NULL); - } + if ( inGoodTrack ) + Refresh(); else MouseLeave(); // mouse has left the building. Redraw the correct state now, not later } +// +// EnableSelf +// DisableSelf +// +// Override to redraw immediately when enabled or disabled. +// + +void +CRDFPushButton :: EnableSelf ( ) +{ + if (FocusExposed()) { + FocusDraw(); + Draw(NULL); + } +} + +void +CRDFPushButton :: DisableSelf ( ) +{ + if (FocusExposed()) { + FocusDraw(); + Draw(NULL); + } +} + #pragma mark - @@ -673,6 +799,24 @@ CRDFSeparator :: DrawSelf ( ) ::FrameRect ( &localRect ); } + +// +// NaturalSize +// (See comment on CRDFPushButton::NaturalSize() for tons of info.) +// +// Return the appropriate size for a separator. +// +SDimension16 +CRDFSeparator :: NaturalSize( SDimension16 inAvailable ) const +{ + SDimension16 desiredSpace; + desiredSpace.width = 15; desiredSpace.height = 50; //еее for now + + return desiredSpace; + +} // NaturalSize + + #pragma mark - @@ -680,7 +824,6 @@ CRDFURLBar :: CRDFURLBar ( HT_Resource inNode ) : CRDFToolbarItem(inNode) { - } @@ -691,13 +834,34 @@ CRDFURLBar :: ~CRDFURLBar ( ) } -// a strawman drawing routine for testing purposes only + +// +// FinishCreate +// +// Called after this item has been placed into the widget hierarchy. Reanimate the +// url bar from a PPob. This needs to be done here (and not in the constructor) +// because some of its components (proxy icon, etc) throw/assert if they are not +// part of a window at creation time. +// void -CRDFURLBar :: DrawSelf ( ) +CRDFURLBar :: FinishCreate ( ) { - Rect localRect; - CalcLocalFrameRect ( localRect ); + LWindow* window = LWindow::FetchWindowObject(GetMacPort()); + LView* view = UReanimator::CreateView(1104, this, window); // create the url bar - ::FrameRect ( &localRect ); -} +} // FinishCreate + + +// +// NaturalSize +// (See comment on CRDFPushButton::NaturalSize() for tons of info.) +// +// Since we want to take as much room as possible, return what is available. +// +SDimension16 +CRDFURLBar::NaturalSize( SDimension16 inAvailable ) const +{ + return inAvailable; + +} // NaturalSize diff --git a/mozilla/cmd/macfe/gui/CRDFToolbarItem.h b/mozilla/cmd/macfe/gui/CRDFToolbarItem.h index e35469712dd..28bbf462e99 100644 --- a/mozilla/cmd/macfe/gui/CRDFToolbarItem.h +++ b/mozilla/cmd/macfe/gui/CRDFToolbarItem.h @@ -50,7 +50,15 @@ public: virtual void PutInside ( LView *inView, Boolean inOrient = true) = 0; virtual void ResizeFrameTo ( SInt16 inWidth, SInt16 inHeight, Boolean inRefresh ) = 0; virtual void PlaceInSuperFrameAt ( SInt32 inHoriz, SInt32 inVert, Boolean inRefresh ) = 0; + virtual SDimension16 NaturalSize ( SDimension16 inAvail ) const = 0; + // Post-creation init routines + // These are called AFTER the item has been placed inside its parent + // toolbar. This is important because some items need to be part of + // a window or need to walk up the view hierarchy to register themselves. + virtual void HookUpToListeners ( ) { } ; + virtual void FinishCreate ( ) { } ; + protected: HT_Resource HTNode ( ) { return mNode; } @@ -84,9 +92,6 @@ public: CRDFPushButton ( HT_Resource inNode ) ; virtual ~CRDFPushButton ( ) ; - void SetTrackInside(bool inInside) { mTrackInside = inInside; } - bool IsTrackInside() const { return mTrackInside; } - // returns how the buttons wants to display: icon only, icon & text, text only // based on the properties in HT. UInt32 CalcDisplayMode ( ) const; @@ -100,6 +105,9 @@ public: virtual void PlaceInSuperFrameAt ( SInt32 inHoriz, SInt32 inVert, Boolean inRefresh ) { LPane::PlaceInSuperFrameAt(inHoriz, inVert, inRefresh); } + virtual SDimension16 NaturalSize ( SDimension16 inAvail ) const ; + + virtual void HookUpToListeners ( ) ; protected: @@ -117,7 +125,9 @@ protected: virtual void DrawSelfDisabled ( ) ; virtual void DrawButtonOutline ( ) ; virtual void DrawButtonHilited ( ) ; - + virtual void EnableSelf ( ) ; + virtual void DisableSelf ( ) ; + // handle drawing icon as an image virtual void ImageIsReady ( ) ; virtual void DrawStandby ( const Point & inTopLeft, IconTransformType inTransform ) const ; @@ -133,16 +143,21 @@ protected: virtual void HotSpotResult ( Int16 inHotSpot ); bool IsMouseInFrame ( ) const { return mMouseInFrame; } ; + void SetTrackInside(bool inInside) { mTrackInside = inInside; } + bool IsTrackInside() const { return mTrackInside; } // calculate tooltip to display title virtual void FindTooltipForMouseLocation ( const EventRecord& inMacEvent, StringPtr outTip ); + virtual void AssignCommand ( ) ; + private: UInt32 CalcAlignment ( UInt32 inTopAlignment, Uint32 inSideAlignment ) const; void AttachTooltip ( ) ; void AttachContextMenu ( ) ; + void AttachPaneEnabler ( ) ; StRegion mButtonMask; Rect mCachedButtonFrame; @@ -189,7 +204,8 @@ public: virtual void PlaceInSuperFrameAt ( SInt32 inHoriz, SInt32 inVert, Boolean inRefresh ) { LPane::PlaceInSuperFrameAt(inHoriz, inVert, inRefresh); } - + virtual SDimension16 NaturalSize ( SDimension16 inAvail ) const ; + virtual void DrawSelf ( ) ; private: @@ -222,8 +238,9 @@ public: virtual void PlaceInSuperFrameAt ( SInt32 inHoriz, SInt32 inVert, Boolean inRefresh ) { LPane::PlaceInSuperFrameAt(inHoriz, inVert, inRefresh); } + virtual SDimension16 NaturalSize ( SDimension16 inAvail ) const ; - virtual void DrawSelf ( ) ; + virtual void FinishCreate ( ) ; private: // items cannot be passed by value because they exist in 1-to-1 correspondance