browserui/browser/FavouritesSrc/BrowserBookmarksContainer.cpp
changeset 1 57d5b8e231c4
parent 0 84ad3b177aa3
child 10 4530440261a8
--- a/browserui/browser/FavouritesSrc/BrowserBookmarksContainer.cpp	Mon Mar 30 12:49:49 2009 +0300
+++ b/browserui/browser/FavouritesSrc/BrowserBookmarksContainer.cpp	Fri May 08 08:18:43 2009 +0300
@@ -22,9 +22,11 @@
 
 #include <AknViewAppUi.h>
 #include <aknsfld.h>
+#include <avkon.mbg>
 #include <BrowserNG.rsg>
 #include <FavouritesItem.h>
 #include <FeatMgr.h>
+#include "BrowserBookmarksView.h"
 
 #include "CommonConstants.h"
 #include "BrowserFavouritesView.h"
@@ -41,6 +43,8 @@
 #endif // __SERIES60_HELP
 #include "Logger.h"
 #include "e32event.h"
+#include "BrowserUiSDKCRKeys.h"
+#include <StringLoader.h>
 
 // CONSTANTS
 
@@ -72,6 +76,8 @@
 CBrowserBookmarksContainer::~CBrowserBookmarksContainer()
     {
     delete iGotoPane;
+    delete iSearchPane;
+    delete iDefaultSearchText;
     }
 
 // ---------------------------------------------------------
@@ -85,15 +91,93 @@
        	iGotoPaneActive = ETrue;
 
     	Listbox()->UpdateFilterL();	
-    	
+    	if( iSearchPane )
+    	    {
+    	    iGotoPane->SetVKBFlag( EFalse );
+    	    // Check for Search Configuration Changes //
+    	    if( View().ApiProvider().Preferences().GetIntValue( KBrowserSearchIconId )
+    	            != iSearchIconId )
+                {   
+    	        ConstructSearchPaneL();
+                }
+    	    
+            iSearchPane->SetFocus( EFalse );
+        	// only one editor can be active at a time //
+        	iSearchPaneActive = EFalse;
+        	// we still need to display search, when showing for first time //
+        	iSearchPane->MakeVisible(ETrue);
+            iSearchPane->CancelEditingL();
+    	    }
+            
     	// redraw
     	SizeChanged();
     	
-    	iGotoPane->BeginEditingL();
-    	
+        // It is important to set the Text and Italic property after SizeChanged, because
+        // iInputFrame->SetRect() event on GoTo/Search Pane calls the scalable version 
+        // ( AknLayoutUtils::LayoutEdwinScalable ) which overwrites all the properties for
+        // Char and Para Formats.
+        if( iSearchPane )
+            {
+            iSearchPane->SetTextModeItalicL();
+            HBufC* text = iSearchPane->GetTextL();
+            CleanupStack::PushL( text );
+            if ( !text->Length() )
+                {
+                iSearchPane->SetTextL( *iDefaultSearchText );
+                }
+            CleanupStack::PopAndDestroy( text );
+            }
+        
+        iGotoPane->BeginEditingL();
        	DrawDeferred();      	
     	}
     }
+    	
+// ---------------------------------------------------------
+// CBrowserBookmarksContainer::SetSearchActiveL
+// ---------------------------------------------------------
+//
+void CBrowserBookmarksContainer::SetSearchActiveL()
+    {    
+    if( ! iSearchPaneActive )
+        {
+        // Check for Search Configuration Changes //
+        if( View().ApiProvider().Preferences().GetIntValue( KBrowserSearchIconId ) 
+                != iSearchIconId )
+            {
+            ConstructSearchPaneL();
+            }
+            
+        iSearchPane->SetVKBFlag( EFalse );
+        iSearchPane->SetFocus( ETrue );
+        iSearchPaneActive = ETrue;
+        
+        Listbox()->UpdateFilterL();
+        // only one editor can be active at a time
+        iGotoPaneActive = EFalse;
+        iGotoPane->MakeVisible(ETrue);
+        iGotoPane->SetFocus( EFalse );        
+        iGotoPane->CancelEditingL();
+        
+        // redraw
+        SizeChanged();
+        
+        // Not Focused, so set the current Text Mode to italics.
+        iGotoPane->SetTextModeItalicL();
+        // if gotopane is empty add default text
+        HBufC* text = iGotoPane->GetTextL();
+        CleanupStack::PushL( text );
+        if ( !text->Length() )
+            {
+            iGotoPane->SetTextL( KWWWString );
+            }
+        CleanupStack::PopAndDestroy( text );
+        
+        iSearchPane->BeginEditingL();
+        DrawDeferred();
+        }
+       
+    }
 
 
 // ---------------------------------------------------------
@@ -103,8 +187,18 @@
 
 void CBrowserBookmarksContainer::SetGotoInactiveL()
 	{
-	if(iGotoPaneActive)
+	if( iGotoPaneActive || iSearchPaneActive )
 		{
+		
+		  if( iSearchPane )
+            {
+            /* In Search Feature we have to move between the editors preserving the 
+             * text added, clear the text when cancel is pressed.
+             */
+            iGotoPane->SetTextL( KNullDesC , ETrue );
+            SetSearchInactiveL();
+            }
+		// Deactivate GoTo Pane
 		iGotoPaneActive = EFalse;
 			
 		// Deactivate GoTo Pane
@@ -119,13 +213,21 @@
 		}
 	}
 	
+void CBrowserBookmarksContainer::SetSearchInactiveL()
+    {
+    iSearchPaneActive = EFalse; 
+    iSearchPane->SetTextL( KNullDesC , ETrue);
+    iSearchPane->MakeVisible( EFalse );
+    iSearchPane->CancelEditingL();
+    }
+
 // ---------------------------------------------------------
 // CBrowserBookmarksContainer::CountComponentControls
 // ---------------------------------------------------------
 //
 TInt CBrowserBookmarksContainer::CountComponentControls() const
     {
-    return (Listbox() ? 1 : 0) + (iGotoPane ? 1 : 0);
+    return (Listbox() ? 1 : 0) + (iGotoPane ? 1 : 0) + (iSearchPane? 1 : 0) ;
     }
 
 // ---------------------------------------------------------
@@ -146,7 +248,10 @@
             {
             return iGotoPane;
             }
-
+        case 2:
+            {
+            return iSearchPane;
+            }
         default:
             {
             return NULL;
@@ -164,16 +269,53 @@
     TInt unfilteredNumberOfItems = Listbox()->UnfilteredNumberOfItems();
     
     // if goto pane is active
-    if( iGotoPaneActive )
+    if( iGotoPaneActive || iSearchPaneActive )
     	{
-        	// Enable / disable line in Goto Pane (hide if listbox is empty).
+    	if( iSearchPane )
+    	    {
+    	    TAknWindowLineLayout findPane = AknLayout::find_pane();
+        	
+    	    // Enable / disable line in Goto Pane (hide if listbox is empty).
         	iGotoPane->SetLineState( unfilteredNumberOfItems > 0 );
         	
+        	TAknWindowLineLayout listLayout = AknLayout::list_gen_pane( 1 );
+        	
+        	TRect listBoxRect = AknLayoutUtils::RectFromCoords( rect,listLayout.il, 
+        	        listLayout.it, listLayout.ir, listLayout.ib, listLayout.iW, listLayout.iH);
+        	
+        	/* Now we need to make room for both Goto and Search Pane.
+        	 * No layout specification was suitable for this case, so 
+        	 * substracting the height of pane.
+        	 */ 
+        	listBoxRect.iBr.iY -= findPane.iH;
+        	
         	// In Goto Mode, the listbox is laid out leaving space for Goto Pane.
-        	AknLayoutUtils::LayoutControl( Listbox(), rect, AknLayout::list_gen_pane( 1 ));
+        	Listbox()->SetRect( listBoxRect );
+        	
+        
+        	// Now Lay out Search Pane as if it was the old Find Pane.
+            AknLayoutUtils::LayoutControl( iSearchPane, rect, findPane );
         	
-        	// Lay out Goto Pane as if it was the old Find Pane.
-        	AknLayoutUtils::LayoutControl( iGotoPane, rect, AknLayout::find_pane() );
+        	TRect gotoRect = AknLayoutUtils::RectFromCoords( rect,findPane.il, findPane.it, 
+        	        findPane.ir, findPane.ib, findPane.iW, findPane.iH);
+        	
+        	// Calculate the new position for GoToPane.
+        	gotoRect.iTl.iY -= ( findPane.iH );
+        	gotoRect.iBr.iY -= ( findPane.iH );
+        	iGotoPane->SetRect( gotoRect );
+        	
+    	    }
+    	else
+    	    {
+    	    // Enable / disable line in Goto Pane (hide if listbox is empty).
+            iGotoPane->SetLineState( unfilteredNumberOfItems > 0 );
+             
+            // In Goto Mode, the listbox is laid out leaving space for Goto Pane.
+            AknLayoutUtils::LayoutControl( Listbox(), rect, AknLayout::list_gen_pane( 1 ));
+             
+            // Lay out Goto Pane as if it was the old Find Pane.
+            AknLayoutUtils::LayoutControl( iGotoPane, rect, AknLayout::find_pane() );
+    	    }
     	}
 	else
     	{
@@ -257,11 +399,11 @@
 	    }
 		// If the Goto Pane exists and we're not fetching, then decide
 		// if we should pass keystroke to it
-	if(iGotoPane)
+	if(iGotoPane && !CBrowserAppUi::Static()->Fetching())
 		{
 		// If the key so far hadn't been consumed or if the pane is already active,
 		// pass the keystroke on
-		if( (result == EKeyWasNotConsumed) || (iGotoPaneActive) )
+		if( (result == EKeyWasNotConsumed) || iGotoPaneActive || iSearchPaneActive )
 			{			
         	// Goto pane has highest priority; if it's active, arrow keys go there.
         	// If fetching is in progress, no key events are offered, to prevent it
@@ -269,7 +411,7 @@
         	
         	// Enter Key  now handled through HandleCommand in BrowserBookmarksView like MSK
 			// This change affects the enter key on the QWERTY keyboard when we run emulator
-        	if(EStdKeyEnter == aKeyEvent.iScanCode && EEventKeyUp == aType && AknLayoutUtils::MSKEnabled() && iGotoPaneActive )
+        	if(EStdKeyEnter == aKeyEvent.iScanCode && EEventKeyUp == aType && AknLayoutUtils::MSKEnabled() && (iGotoPaneActive || iSearchPaneActive ))
 				{
 				CEikButtonGroupContainer* myCba = CEikButtonGroupContainer::Current();
 				if(myCba != NULL)
@@ -280,13 +422,51 @@
 					}
 				}
 			else
-				{
-				result = iGotoPane->OfferKeyEventL( keyEvent, aType );	
+			    {
+			    if( iSearchPane )
+			        {
+			        // Process separately for Search Feature //
+			        if( iGotoPaneActive )
+			            {
+                        result = iGotoPane->OfferKeyEventL( keyEvent, aType );
+			            }
+                    else 
+                        {
+                        result = iSearchPane->OfferKeyEventL( keyEvent, aType );
+                        }
+ 			        }
+			    else
+			        result = iGotoPane->OfferKeyEventL( keyEvent, aType );
 				}
-        
+        	
+        	if( iSearchPane )
+        	    {
+            	if( ( iGotoPaneActive || iSearchPaneActive) && result == EKeyWasNotConsumed ) 
+                    {
+                    
+                    if(  aKeyEvent.iCode == EKeyUpArrow )
+                        {
+                        result = EKeyWasConsumed;
+                        if( iSearchPaneActive )
+                            {
+                            SetGotoActiveL();
+                            iGotoPane->SetVKBFlag( ETrue );
+                            }
+                        }
+                    if( aKeyEvent.iCode == EKeyDownArrow )
+                        {
+                        result = EKeyWasConsumed;
+                        if( iGotoPaneActive )
+                            {
+                            SetSearchActiveL();
+                            iSearchPane->SetVKBFlag( ETrue );
+                            }
+                        }
+                    }
+        	    }
+            
 			// if key is consumed, goto pane was not active, make it active now.
-        	if(result == EKeyWasConsumed &&
-        		!iGotoPaneActive)
+        	if(result == EKeyWasConsumed && (!iGotoPaneActive && !iSearchPaneActive))
         		{
         		SetGotoActiveL();	
         		}
@@ -373,6 +553,20 @@
     }
 
 // ---------------------------------------------------------
+// CBrowserBookmarksContainer::IsEditingSearch
+// ---------------------------------------------------------
+//
+TBool CBrowserBookmarksContainer::IsEditingSearch()
+    {
+    TBool editing = EFalse;
+    if( iSearchPane )
+        {
+        editing = iSearchPane->IsEditing();
+        }
+    return editing;
+    }
+
+// ---------------------------------------------------------
 // CBrowserBookmarksContainer::TabIndex
 // ---------------------------------------------------------
 //
@@ -404,7 +598,7 @@
 // ---------------------------------------------------------
 //
 CBrowserBookmarksContainer::CBrowserBookmarksContainer()
-: iGotoPaneActive( EFalse )
+: iGotoPaneActive( EFalse ),iSearchPaneActive(EFalse)
     {
     }
 
@@ -423,8 +617,17 @@
     // Construct Goto Pane.
     
     //pass view to bookmarks goto pane
-    iGotoPane = CBrowserBookmarksGotoPane::NewL( *this, &aView );
+    iGotoPane = CBrowserBookmarksGotoPane::NewL( *this, &aView, KAvkonBitmapFile,
+            EMbmAvkonQgn_indi_find_goto,
+            EMbmAvkonQgn_indi_find_goto_mask);
     iGotoPane->SetFocus( EFalse );
+    
+    if( View().ApiProvider().Preferences().SearchFeature() )
+        {
+        ConstructSearchPaneL();
+        iSearchPane->SetFocus( EFalse );
+        iDefaultSearchText = StringLoader::LoadL( R_IS_WEB_SEARCH );
+        }
     }
 
 // ---------------------------------------------------------
@@ -459,6 +662,10 @@
         {
         iGotoPane->SetFocus( IsFocused(), aDrawNow );
         }
+    else if( IsEditingSearch() )
+        {
+        iSearchPane->SetFocus( IsFocused(), aDrawNow );
+        }
     else if ( Listbox() && Listbox()->IsVisible() )
         {
         Listbox()->SetFocus( IsFocused(), aDrawNow );
@@ -478,10 +685,48 @@
 		//
 		// otherwise, if it falls within the listbox's rect
 		//
-        if (iGotoPaneActive && iGotoPane)
-			{		
-    		iGotoPane->HandlePointerEventL(aPointerEvent);
-			}
+        
+        // Now we have two different panes so we have to check explicitly before passing controls
+        // to any panes.
+        if( iGotoPane && ( iGotoPaneActive || iSearchPaneActive) )
+            {
+            if( iSearchPane )//implies presence of search feature.
+                {
+                 if( iGotoPane->Rect().Contains( aPointerEvent.iPosition) )
+                     {
+                     if( iGotoPaneActive )
+                         {
+                         iGotoPane->HandlePointerEventL(aPointerEvent);
+                         }
+                     else
+                         {
+                         SetGotoActiveL();                         
+                         }
+                     iGotoPane->SetVKBFlag( ETrue );                        
+                     }
+                 else if( iSearchPane->Rect().Contains( aPointerEvent.iPosition) )
+                     {
+                     if( iSearchPaneActive )
+                         {
+                         iSearchPane->HandlePointerEventL(aPointerEvent);
+                         }
+                     else
+                         {
+                         SetSearchActiveL();                         
+                         }
+                     iSearchPane->SetVKBFlag( ETrue );                     
+                     }
+                 else
+                     {
+                     CBrowserAppUi::Static()->ActiveView()->HandleCommandL(EWmlCmdGotoPaneCancel);
+                     SetGotoInactiveL();
+                     }
+                }
+             else
+                 {
+                 iGotoPane->HandlePointerEventL(aPointerEvent);
+                 }
+            }
         else
         	{
     		// normally, pass all pointer events down to the listbox
@@ -490,4 +735,92 @@
         }
     }
 
+// ----------------------------------------------------------------------------
+// CBrowserBookmarksContainer::ConstructSearchPaneL
+// ----------------------------------------------------------------------------
+//
+
+void CBrowserBookmarksContainer::ConstructSearchPaneL()
+    {
+    TFileName iconFile;
+    MPreferences& preferences = View().ApiProvider().Preferences();
+    
+    TInt iconId = preferences.GetIntValue( KBrowserSearchIconId );
+    // Get the Search Icon File Path.
+    preferences.GetStringValueL( KBrowserSearchIconPath, KMaxFileName, iconFile );
+      
+    // If Icon File Path Changed or Icon Id Changed, Refresh the Icon for Search Pane.
+    // Comparing Icon File path as well, because it may be possible that two different 
+    // Icon files have same icon id.
+    if( iconId != iSearchIconId  
+            || iSearchIconFilePath.Compare( iconFile ) != 0 )
+        {
+          
+        TInt iconMaskId = preferences.GetIntValue( KBrowserSearchIconMaskId );
+
+        // Save IconId 
+        iSearchIconId = iconId;
+        // Save Icon File
+        iSearchIconFilePath = iconFile;
+
+        
+        // No Icon file or IconId or IconMaskId set , then it means no search provider is still 
+        // selected and set by search application, in that case we use the default icon for Search.
+        if( ! iconFile.Length() 
+                || iconId == -1
+                || iconMaskId == -1 )
+            {
+            iconId = EMbmAvkonQgn_indi_find_glass;
+            iconMaskId = EMbmAvkonQgn_indi_find_glass_mask;
+            iconFile = KAvkonBitmapFile;
+            }
+                 
+        if( iSearchPane )
+            {
+            delete iSearchPane;
+            iSearchPane = NULL;
+            }
+       
+        
+        // iSearchPane != NULL, implies presence of search feature, hence it can be
+        // used to validate search feature avoiding repetative calls to utils and
+        // avoiding need of separate variable.
+        iSearchPane = CBrowserBookmarksGotoPane::NewL( *this, 
+                            &(View()), 
+                            iconFile, 
+                            iconId,
+                            iconMaskId,
+                            GOTOPANE_POPUPLIST_DISABLE,
+                            ETrue
+                            );
+       
+        CBrowserBookmarksView* bookmarkView = REINTERPRET_CAST( CBrowserBookmarksView* ,  &( View() ));
+        // Set Pane observer
+        iSearchPane->SetGPObserver( bookmarkView );
+        }
+    }
+
+// ----------------------------------------------------------------------------
+// CBrowserBookmarksContainer::HandleResourceChange
+// ----------------------------------------------------------------------------
+//
+void CBrowserBookmarksContainer::HandleResourceChange(TInt aType)
+    {
+    CBrowserFavouritesContainer::HandleResourceChange( aType);
+    if( aType == KEikDynamicLayoutVariantSwitch)
+        {
+        // If search feature exsist
+        if( iSearchPane  ) 
+            {
+            if( iSearchPaneActive )
+                {
+                iGotoPane->SetTextModeItalicL( );
+                }
+            else
+                {
+                iSearchPane->SetTextModeItalicL( );
+                }
+            }
+        }
+    }
 // End of File